{"version":3,"sources":["viewer.js","../Client/viewer/models/type-extensions.ts","../node_modules/tslib/tslib.es6.js","../Client/viewer/models/classes/token.ts","../Client/viewer/models/classes/decorators/model-utils.ts","../Client/viewer/models/interfaces/tracked-class.ts","../Client/viewer/models/services/sync-service.ts","../node_modules/rxjs/node_modules/tslib/tslib.es6.js","../node_modules/rxjs/src/internal/util/isFunction.ts","../node_modules/rxjs/src/internal/config.ts","../node_modules/rxjs/src/internal/util/hostReportError.ts","../node_modules/rxjs/src/internal/Observer.ts","../node_modules/rxjs/src/internal/util/isObject.ts","../node_modules/rxjs/src/internal/util/UnsubscriptionError.ts","../node_modules/rxjs/src/internal/Subscription.ts","../node_modules/rxjs/src/internal/symbol/rxSubscriber.ts","../node_modules/rxjs/src/internal/Subscriber.ts","../node_modules/rxjs/src/internal/util/identity.ts","../node_modules/rxjs/src/internal/util/pipe.ts","../node_modules/rxjs/src/internal/Observable.ts","../node_modules/rxjs/src/internal/util/toSubscriber.ts","../node_modules/rxjs/src/internal/util/canReportError.ts","../node_modules/rxjs/src/internal/util/ObjectUnsubscribedError.ts","../node_modules/rxjs/src/internal/SubjectSubscription.ts","../node_modules/rxjs/src/internal/Subject.ts","../node_modules/rxjs/src/internal/operators/refCount.ts","../node_modules/rxjs/src/internal/observable/ConnectableObservable.ts","../node_modules/rxjs/src/internal/BehaviorSubject.ts","../node_modules/rxjs/src/internal/scheduler/AsyncAction.ts","../node_modules/rxjs/src/internal/scheduler/Action.ts","../node_modules/rxjs/src/internal/scheduler/QueueAction.ts","../node_modules/rxjs/src/internal/Scheduler.ts","../node_modules/rxjs/src/internal/scheduler/AsyncScheduler.ts","../node_modules/rxjs/src/internal/scheduler/QueueScheduler.ts","../node_modules/rxjs/src/internal/scheduler/queue.ts","../node_modules/rxjs/src/internal/observable/empty.ts","../node_modules/rxjs/src/internal/util/isScheduler.ts","../node_modules/rxjs/src/internal/util/subscribeToArray.ts","../node_modules/rxjs/src/internal/scheduled/scheduleArray.ts","../node_modules/rxjs/src/internal/observable/fromArray.ts","../node_modules/rxjs/src/internal/observable/of.ts","../node_modules/rxjs/src/internal/observable/throwError.ts","../node_modules/rxjs/src/internal/Notification.ts","../node_modules/rxjs/src/internal/operators/observeOn.ts","../node_modules/rxjs/src/internal/ReplaySubject.ts","../node_modules/rxjs/src/internal/scheduler/async.ts","../node_modules/rxjs/src/internal/util/ArgumentOutOfRangeError.ts","../node_modules/rxjs/src/internal/util/EmptyError.ts","../node_modules/rxjs/src/internal/operators/map.ts","../node_modules/rxjs/src/internal/OuterSubscriber.ts","../node_modules/rxjs/src/internal/InnerSubscriber.ts","../node_modules/rxjs/src/internal/symbol/iterator.ts","../node_modules/rxjs/src/internal/util/isPromise.ts","../node_modules/rxjs/src/internal/util/subscribeTo.ts","../node_modules/rxjs/src/internal/util/subscribeToObservable.ts","../node_modules/rxjs/src/internal/util/subscribeToPromise.ts","../node_modules/rxjs/src/internal/util/subscribeToIterable.ts","../node_modules/rxjs/src/internal/util/subscribeToResult.ts","../node_modules/rxjs/src/internal/observable/combineLatest.ts","../node_modules/rxjs/src/internal/scheduled/scheduled.ts","../node_modules/rxjs/src/internal/util/isInteropObservable.ts","../node_modules/rxjs/src/internal/scheduled/scheduleObservable.ts","../node_modules/rxjs/src/internal/scheduled/schedulePromise.ts","../node_modules/rxjs/src/internal/util/isIterable.ts","../node_modules/rxjs/src/internal/scheduled/scheduleIterable.ts","../node_modules/rxjs/src/internal/observable/from.ts","../node_modules/rxjs/src/internal/innerSubscribe.ts","../node_modules/rxjs/src/internal/operators/mergeMap.ts","../node_modules/rxjs/src/internal/operators/mergeAll.ts","../node_modules/rxjs/src/internal/operators/concatAll.ts","../node_modules/rxjs/src/internal/observable/concat.ts","../node_modules/rxjs/src/internal/observable/merge.ts","../node_modules/rxjs/src/internal/operators/filter.ts","../node_modules/rxjs/src/internal/operators/debounceTime.ts","../node_modules/rxjs/src/internal/operators/defaultIfEmpty.ts","../node_modules/rxjs/src/internal/operators/distinctUntilChanged.ts","../node_modules/rxjs/src/internal/operators/throwIfEmpty.ts","../node_modules/rxjs/src/internal/operators/take.ts","../node_modules/rxjs/src/internal/operators/finalize.ts","../node_modules/rxjs/src/internal/operators/multicast.ts","../node_modules/rxjs/src/internal/operators/share.ts","../node_modules/rxjs/src/internal/operators/shareReplay.ts","../node_modules/rxjs/src/internal/operators/switchMap.ts","../node_modules/rxjs/src/internal/operators/takeUntil.ts","../node_modules/rxjs/src/internal/operators/takeWhile.ts","../node_modules/rxjs/src/internal/operators/throttle.ts","../node_modules/rxjs/src/internal/operators/throttleTime.ts","../Client/viewer/models/classes/utilities.ts","../Client/viewer/models/classes/history.ts","../Client/viewer/models/classes/decorators/change-tracker.ts","../Client/viewer/models/classes/decorators/change-tracker-node.ts","../Client/viewer/models/classes/primitives/primitive-utilities.ts","../Client/viewer/models/classes/decorators/kb3d-decorator.ts","../Client/viewer/models/classes/decorators/enumerable.ts","../Client/viewer/models/classes/decorators/inject-decorator.ts","../Client/viewer/models/classes/decorators/service-decorator.ts","../Client/viewer/models/interfaces/settings.ts","../Client/viewer/models/classes/kb3d-object.ts","../Client/viewer/models/classes/features/feature.ts","../Client/viewer/models/classes/features/base-connector.ts","../Client/viewer/models/classes/default-values.ts","../Client/viewer/models/classes/materials/material-mapping.ts","../Client/viewer/models/classes/materials/material-node.ts","../node_modules/@babylonjs/core/tslib.es6.js","../dev/core/src/Misc/andOrNotEvaluator.ts","../dev/core/src/Misc/tags.ts","../dev/core/src/Maths/math.scalar.ts","../dev/core/src/Maths/math.constants.ts","../dev/core/src/Misc/arrayTools.ts","../dev/core/src/Misc/typeStore.ts","../dev/core/src/Engines/performanceConfigurator.ts","../dev/core/src/Misc/observable.ts","../dev/core/src/Engines/engineStore.ts","../dev/core/src/Maths/math.vector.ts","../dev/core/src/Misc/devTools.ts","../dev/core/src/Maths/math.color.ts","../dev/core/src/Misc/decorators.ts","../dev/core/src/node.ts","../dev/core/src/Misc/domManagement.ts","../dev/core/src/Misc/logger.ts","../dev/core/src/Misc/deepCopier.ts","../dev/core/src/Misc/precisionDate.ts","../dev/core/src/Misc/webRequest.ts","../dev/core/src/Misc/filesInputStore.ts","../dev/core/src/Misc/error.ts","../dev/core/src/Misc/stringTools.ts","../dev/core/src/Engines/Processors/shaderCodeNode.ts","../dev/core/src/Engines/Processors/shaderCodeCursor.ts","../dev/core/src/Engines/Processors/shaderCodeConditionNode.ts","../dev/core/src/Engines/Processors/shaderCodeTestNode.ts","../dev/core/src/Engines/Processors/Expressions/shaderDefineExpression.ts","../dev/core/src/Engines/Processors/Expressions/Operators/shaderDefineIsDefinedOperator.ts","../dev/core/src/Engines/Processors/Expressions/Operators/shaderDefineOrOperator.ts","../dev/core/src/Engines/Processors/Expressions/Operators/shaderDefineAndOperator.ts","../dev/core/src/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.ts","../dev/core/src/Materials/shaderLanguage.ts","../dev/core/src/Engines/Processors/shaderProcessor.ts","../dev/core/src/Engines/shaderStore.ts","../dev/core/src/Materials/effect.ts","../dev/core/src/States/depthCullingState.ts","../dev/core/src/States/stencilState.ts","../dev/core/src/States/alphaCullingState.ts","../dev/core/src/Materials/Textures/internalTexture.ts","../dev/core/src/Materials/Textures/textureSampler.ts","../dev/core/src/Engines/WebGL/webGLShaderProcessors.ts","../dev/core/src/Engines/WebGL/webGL2ShaderProcessors.ts","../dev/core/src/Buffers/dataBuffer.ts","../dev/core/src/Meshes/WebGL/webGLDataBuffer.ts","../dev/core/src/Engines/WebGL/webGLPipelineContext.ts","../dev/core/src/Engines/WebGL/webGLHardwareTexture.ts","../dev/core/src/Materials/drawWrapper.ts","../dev/core/src/States/stencilStateComposer.ts","../dev/core/src/Engines/thinEngine.ts","../dev/core/src/Misc/timingTools.ts","../dev/core/src/Misc/fileTools.ts","../dev/core/src/Misc/retryStrategy.ts","../dev/core/src/Misc/instantiationTools.ts","../dev/core/src/Misc/guid.ts","../dev/core/src/Misc/tools.ts","../dev/core/src/Misc/coroutine.ts","../dev/core/src/Misc/smartArray.ts","../dev/core/src/Maths/math.viewport.ts","../dev/core/src/Maths/math.plane.ts","../dev/core/src/Maths/math.frustum.ts","../dev/core/src/Cameras/camera.ts","../dev/core/src/Misc/stringDictionary.ts","../dev/core/src/abstractScene.ts","../dev/core/src/Materials/materialDefines.ts","../dev/core/src/Materials/colorCurves.ts","../dev/core/src/Materials/imageProcessingConfiguration.ts","../dev/core/src/DeviceInput/InputDevices/deviceEnums.ts","../dev/core/src/Events/deviceInputEvents.ts","../dev/core/src/Engines/Extensions/engine.uniformBuffer.ts","../dev/core/src/Materials/uniformBuffer.ts","../dev/core/src/Buffers/buffer.ts","../dev/core/src/Collisions/pickingInfo.ts","../dev/core/src/Actions/actionEvent.ts","../dev/core/src/PostProcesses/postProcessManager.ts","../dev/core/src/Rendering/renderingGroup.ts","../dev/core/src/Rendering/renderingManager.ts","../dev/core/src/sceneComponent.ts","../dev/core/src/Events/pointerEvents.ts","../dev/core/src/Actions/abstractActionManager.ts","../dev/core/src/Events/keyboardEvents.ts","../dev/core/src/DeviceInput/eventFactory.ts","../dev/core/src/DeviceInput/nativeDeviceInputSystem.ts","../dev/core/src/DeviceInput/webDeviceInputSystem.ts","../dev/core/src/DeviceInput/InputDevices/deviceSource.ts","../dev/core/src/DeviceInput/internalDeviceSourceManager.ts","../dev/core/src/DeviceInput/InputDevices/deviceSourceManager.ts","../dev/core/src/Inputs/scene.inputManager.ts","../dev/core/src/Misc/perfCounter.ts","../dev/core/src/Misc/uniqueIdGenerator.ts","../dev/core/src/Lights/lightConstants.ts","../dev/core/src/Inputs/pointerPickingConfiguration.ts","../dev/core/src/scene.ts","../dev/core/src/Collisions/intersectionInfo.ts","../dev/core/src/Culling/boundingBox.ts","../dev/core/src/Culling/boundingSphere.ts","../dev/core/src/Culling/boundingInfo.ts","../dev/core/src/Maths/math.functions.ts","../dev/core/src/Meshes/subMesh.ts","../dev/core/src/Meshes/mesh.vertexData.ts","../dev/core/src/Loading/sceneLoaderFlags.ts","../dev/core/src/Compat/compatibilityOptions.ts","../dev/core/src/Meshes/geometry.ts","../dev/core/src/Misc/performanceMonitor.ts","../dev/core/src/Engines/Extensions/engine.alpha.ts","../dev/core/src/Engines/Extensions/engine.readTexture.ts","../dev/core/src/Engines/Extensions/engine.dynamicBuffer.ts","../dev/core/src/Engines/engine.ts","../dev/core/src/Maths/math.axis.ts","../dev/core/src/Meshes/transformNode.ts","../dev/core/src/Collisions/meshCollisionData.ts","../dev/core/src/Meshes/abstractMesh.ts","../dev/core/src/Materials/clipPlaneMaterialHelper.ts","../dev/core/src/Materials/materialHelper.ts","../dev/core/src/Materials/materialStencilState.ts","../dev/core/src/Materials/materialPluginEvent.ts","../dev/core/src/Maths/math.path.ts","../dev/core/src/Animations/animationKey.ts","../dev/core/src/Materials/material.ts","../dev/core/src/Materials/multiMaterial.ts","../dev/core/src/Meshes/meshLODLevel.ts","../dev/core/src/Meshes/mesh.ts","../dev/core/src/Behaviors/Cameras/autoRotationBehavior.ts","../dev/core/src/Animations/easing.ts","../dev/core/src/Animations/animationRange.ts","../dev/core/src/Maths/math.size.ts","../dev/core/src/Animations/animation.ts","../dev/core/src/Behaviors/Cameras/bouncingBehavior.ts","../dev/core/src/Behaviors/Cameras/framingBehavior.ts","../dev/core/src/Cameras/targetCamera.ts","../dev/core/src/Cameras/cameraInputsManager.ts","../dev/core/src/Cameras/Inputs/BaseCameraPointersInput.ts","../dev/core/src/Cameras/Inputs/arcRotateCameraPointersInput.ts","../dev/core/src/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.ts","../dev/core/src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts","../dev/core/src/Cameras/arcRotateCameraInputsManager.ts","../dev/core/src/Cameras/arcRotateCamera.ts","../dev/core/src/Culling/ray.ts","../dev/core/src/Maths/sphericalPolynomial.ts","../Client/viewer/view/helpers/math-helper.ts","../Client/viewer/models/classes/primitives/kb-quaternion.ts","../Client/viewer/models/classes/meshes/box-node.ts","../Client/viewer/models/classes/meshes/cone-node.ts","../Client/viewer/models/classes/meshes/cylinder-node.ts","../Client/viewer/models/classes/meshes/disc-node.ts","../Client/viewer/models/classes/meshes/mesh-utilities.ts","../Client/viewer/models/classes/meshes/plane-node.ts","../Client/viewer/models/classes/primitives/kb-vector.ts","../Client/viewer/models/classes/meshes/space-node.ts","../Client/viewer/models/classes/meshes/mesh-node.ts","../Client/viewer/models/classes/meshes/primitive-mesh-node.ts","../Client/viewer/models/classes/meshes/custom-mesh-node.ts","../Client/viewer/models/classes/meshes/mesh-group-node.ts","../Client/viewer/models/classes/primitives/kb-color.ts","../Client/viewer/models/classes/primitives/kb-geometry.ts","../Client/viewer/models/classes/enums.ts","../Client/viewer/models/classes/meshes/sphere-node.ts","../Client/viewer/models/classes/meshes/torus-node.ts","../Client/viewer/models/classes/meshes/sketch-node.ts","../Client/viewer/models/classes/meshes/sketch-node-path.ts","../Client/viewer/models/classes/meshes/text-node.ts","../Client/viewer/models/classes/features/pattern-feature.ts","../Client/viewer/models/classes/features/connector.ts","../Client/viewer/models/classes/features/circular-pattern-feature.ts","../Client/viewer/models/classes/features/delete-faces-feature.ts","../Client/viewer/models/classes/features/displacement-map-feature.ts","../Client/viewer/models/classes/features/extrude-feature.ts","../Client/viewer/models/classes/features/join-geometry-feature.ts","../Client/viewer/models/classes/features/linear-pattern-feature.ts","../Client/viewer/models/classes/features/slice-feature.ts","../Client/viewer/models/classes/features/mirror-feature.ts","../Client/viewer/models/classes/features/move-vertices-feature.ts","../Client/viewer/models/classes/features/normal-smoothing-feature.ts","../Client/viewer/models/classes/handlers.ts","../Client/viewer/models/classes/features/sketch-control-point.ts","../Client/viewer/models/classes/features/uv-map-feature.ts","../Client/viewer/models/classes/features/submesh-feature.ts","../Client/viewer/models/classes/features/sweep-feature.ts","../Client/viewer/models/classes/features/transform-feature.ts","../Client/viewer/models/classes/features/weld-vertices-feature.ts","../Client/viewer/models/classes/annotations/annotation-node.ts","../Client/viewer/models/classes/annotations/dimension-node.ts","../Client/viewer/models/classes/import-job.ts","../Client/viewer/models/services/font-service.ts","../Client/viewer/models/services/http-service.ts","../Client/viewer/common-util/texture-util.ts","../Client/viewer/models/constants.ts","../Client/viewer/models/services/loading-timer-helper.ts","../Client/viewer/models/services/material-service.ts","../Client/viewer/common-util/device-helper.ts","../Client/viewer/models/services/mesh-service.ts","../Client/viewer/models/classes/lights/light-node.ts","../Client/viewer/models/classes/scene-node.ts","../Client/viewer/models/classes/kb3d-manager.ts","../Client/viewer/models/classes/lights/shadow-light-node.ts","../Client/viewer/models/classes/materials/texture-layer.ts","../Client/viewer/models/classes/lights/directional-light-node.ts","../Client/viewer/models/classes/lights/hemispheric-light-node.ts","../Client/viewer/models/classes/lights/point-light-node.ts","../Client/viewer/models/classes/lights/spot-light-node.ts","../Client/viewer/models/classes/materials/advanced-material-node.ts","../Client/viewer/models/classes/materials/color-fill-texture-layer.ts","../Client/viewer/models/classes/materials/file-texture-layer.ts","../Client/viewer/models/classes/materials/svg-texture-layer.ts","../Client/viewer/models/classes/materials/text-texture-layer.ts","../Client/viewer/models/classes/mates/mate-node.ts","../Client/viewer/view/helpers/graph-helper.ts","../Client/viewer/models/classes/viewpoints/viewpoint-node.ts","../dev/core/src/Materials/Textures/thinTexture.ts","../dev/core/src/Materials/Textures/baseTexture.ts","../dev/core/src/Misc/copyTools.ts","../dev/core/src/Materials/Textures/texture.ts","../dev/core/src/Materials/prePassConfiguration.ts","../dev/core/src/Materials/pushMaterial.ts","../dev/core/src/Materials/materialFlags.ts","../dev/core/src/Shaders/ShadersInclude/decalFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/defaultFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/sceneUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/meshUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/defaultUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/prePassDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/oitDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/mainUVVaryingDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/helperFunctions.ts","../dev/core/src/Shaders/ShadersInclude/lightFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/lightUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/lightsFragmentFunctions.ts","../dev/core/src/Shaders/ShadersInclude/shadowsFragmentFunctions.ts","../dev/core/src/Shaders/ShadersInclude/samplerFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/fresnelFunction.ts","../dev/core/src/Shaders/ShadersInclude/reflectionFunction.ts","../dev/core/src/Shaders/ShadersInclude/imageProcessingDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/imageProcessingFunctions.ts","../dev/core/src/Shaders/ShadersInclude/bumpFragmentMainFunctions.ts","../dev/core/src/Shaders/ShadersInclude/bumpFragmentFunctions.ts","../dev/core/src/Shaders/ShadersInclude/clipPlaneFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/logDepthDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/fogFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/clipPlaneFragment.ts","../dev/core/src/Shaders/ShadersInclude/bumpFragment.ts","../dev/core/src/Shaders/ShadersInclude/decalFragment.ts","../dev/core/src/Shaders/ShadersInclude/depthPrePass.ts","../dev/core/src/Shaders/ShadersInclude/lightFragment.ts","../dev/core/src/Shaders/ShadersInclude/logDepthFragment.ts","../dev/core/src/Shaders/ShadersInclude/fogFragment.ts","../dev/core/src/Shaders/ShadersInclude/oitFragment.ts","../dev/core/src/Shaders/default.fragment.ts","../dev/core/src/Shaders/ShadersInclude/decalVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/defaultVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/uvAttributeDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/bonesDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/bakedVertexAnimationDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/instancesDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/prePassVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/samplerVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/bumpVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/clipPlaneVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/fogVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/lightVxFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/lightVxUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/morphTargetsVertexGlobalDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/morphTargetsVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/morphTargetsVertexGlobal.ts","../dev/core/src/Shaders/ShadersInclude/morphTargetsVertex.ts","../dev/core/src/Shaders/ShadersInclude/instancesVertex.ts","../dev/core/src/Shaders/ShadersInclude/bonesVertex.ts","../dev/core/src/Shaders/ShadersInclude/bakedVertexAnimation.ts","../dev/core/src/Shaders/ShadersInclude/prePassVertex.ts","../dev/core/src/Shaders/ShadersInclude/uvVariableDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/samplerVertexImplementation.ts","../dev/core/src/Shaders/ShadersInclude/bumpVertex.ts","../dev/core/src/Shaders/ShadersInclude/clipPlaneVertex.ts","../dev/core/src/Shaders/ShadersInclude/fogVertex.ts","../dev/core/src/Shaders/ShadersInclude/shadowsVertex.ts","../dev/core/src/Shaders/ShadersInclude/vertexColorMixing.ts","../dev/core/src/Shaders/ShadersInclude/pointCloudVertex.ts","../dev/core/src/Shaders/ShadersInclude/logDepthVertex.ts","../dev/core/src/Shaders/default.vertex.ts","../dev/core/src/Materials/effectFallbacks.ts","../dev/core/src/Materials/materialPluginManager.ts","../dev/core/src/Materials/materialPluginBase.ts","../dev/core/src/Materials/material.detailMapConfiguration.ts","../dev/core/src/Materials/standardMaterial.ts","../dev/core/src/Shaders/postprocess.vertex.ts","../dev/core/src/Engines/WebGL/webGLRenderTargetWrapper.ts","../dev/core/src/Engines/renderTargetWrapper.ts","../dev/core/src/Engines/Extensions/engine.renderTarget.ts","../dev/core/src/PostProcesses/postProcess.ts","../dev/core/src/Shaders/rgbdDecode.fragment.ts","../dev/core/src/Engines/Extensions/engine.renderTargetCube.ts","../dev/core/src/Materials/effectRenderer.ts","../dev/core/src/Shaders/pass.fragment.ts","../dev/core/src/Misc/dumpTools.ts","../dev/core/src/Materials/Textures/renderTargetTexture.ts","../dev/core/src/Shaders/passCube.fragment.ts","../dev/core/src/PostProcesses/passPostProcess.ts","../dev/core/src/Misc/textureTools.ts","../dev/core/src/Misc/rgbdTextureTools.ts","../dev/core/src/Misc/brdfTextureTools.ts","../dev/core/src/Materials/PBR/pbrBRDFConfiguration.ts","../dev/core/src/Misc/HighDynamicRange/cubemapToSphericalPolynomial.ts","../dev/core/src/Materials/Textures/baseTexture.polynomial.ts","../dev/core/src/Shaders/ShadersInclude/pbrFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/pbrUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/pbrFragmentExtraDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/samplerFragmentAlternateDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/subSurfaceScatteringFunctions.ts","../dev/core/src/Shaders/ShadersInclude/importanceSampling.ts","../dev/core/src/Shaders/ShadersInclude/pbrHelperFunctions.ts","../dev/core/src/Shaders/ShadersInclude/harmonicsFunctions.ts","../dev/core/src/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.ts","../dev/core/src/Shaders/ShadersInclude/pbrDirectLightingFalloffFunctions.ts","../dev/core/src/Shaders/ShadersInclude/pbrBRDFFunctions.ts","../dev/core/src/Shaders/ShadersInclude/hdrFilteringFunctions.ts","../dev/core/src/Shaders/ShadersInclude/pbrDirectLightingFunctions.ts","../dev/core/src/Shaders/ShadersInclude/pbrIBLFunctions.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockReflectivity.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockAmbientOcclusion.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockAlphaFresnel.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockAnisotropic.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockReflection.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockSheen.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockClearcoat.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockIridescence.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockSubSurface.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockNormalGeometric.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockNormalFinal.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockLightmapInit.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockGeometryInfo.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockReflectance0.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockReflectance.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockDirectLighting.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockFinalLitComponents.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockFinalUnlitComponents.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockFinalColorComposition.ts","../dev/core/src/Shaders/ShadersInclude/pbrBlockImageProcessing.ts","../dev/core/src/Shaders/ShadersInclude/pbrDebug.ts","../dev/core/src/Shaders/pbr.fragment.ts","../dev/core/src/Shaders/ShadersInclude/pbrVertexDeclaration.ts","../dev/core/src/Shaders/pbr.vertex.ts","../dev/core/src/Materials/PBR/pbrClearCoatConfiguration.ts","../dev/core/src/Materials/PBR/pbrIridescenceConfiguration.ts","../dev/core/src/Materials/PBR/pbrAnisotropicConfiguration.ts","../dev/core/src/Materials/PBR/pbrSheenConfiguration.ts","../dev/core/src/Materials/PBR/pbrSubSurfaceConfiguration.ts","../dev/core/src/Materials/PBR/pbrBaseMaterial.ts","../dev/core/src/Materials/PBR/pbrMaterial.ts","../dev/core/src/Lights/light.ts","../dev/core/src/Lights/hemisphericLight.ts","../dev/core/src/Shaders/ShadersInclude/kernelBlurVaryingDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/packingFunctions.ts","../dev/core/src/Shaders/ShadersInclude/kernelBlurFragment.ts","../dev/core/src/Shaders/ShadersInclude/kernelBlurFragment2.ts","../dev/core/src/Shaders/kernelBlur.fragment.ts","../dev/core/src/Shaders/ShadersInclude/kernelBlurVertex.ts","../dev/core/src/Shaders/kernelBlur.vertex.ts","../dev/core/src/PostProcesses/blurPostProcess.ts","../dev/core/src/Materials/Textures/mirrorTexture.ts","../dev/core/src/Engines/Extensions/engine.cubeTexture.ts","../dev/core/src/Materials/Textures/cubeTexture.ts","../dev/core/src/Shaders/ShadersInclude/backgroundFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/backgroundUboDeclaration.ts","../dev/core/src/Shaders/background.fragment.ts","../dev/core/src/Shaders/ShadersInclude/backgroundVertexDeclaration.ts","../dev/core/src/Shaders/background.vertex.ts","../dev/core/src/Materials/Background/backgroundMaterial.ts","../dev/core/src/Meshes/Builders/planeBuilder.ts","../dev/core/src/Meshes/groundMesh.ts","../dev/core/src/Meshes/Builders/groundBuilder.ts","../dev/core/src/Meshes/Builders/boxBuilder.ts","../dev/core/src/Helpers/environmentHelper.ts","../dev/core/src/Cameras/Inputs/freeCameraKeyboardMoveInput.ts","../dev/core/src/Cameras/Inputs/freeCameraMouseInput.ts","../dev/core/src/Cameras/Inputs/BaseCameraMouseWheelInput.ts","../dev/core/src/Cameras/Inputs/freeCameraMouseWheelInput.ts","../dev/core/src/Cameras/Inputs/freeCameraTouchInput.ts","../dev/core/src/Cameras/freeCameraInputsManager.ts","../dev/core/src/Cameras/freeCamera.ts","../dev/core/src/Cameras/Inputs/freeCameraDeviceOrientationInput.ts","../dev/core/src/Cameras/deviceOrientationCamera.ts","../dev/core/src/Cameras/VR/vrCameraMetrics.ts","../dev/core/src/Shaders/vrDistortionCorrection.fragment.ts","../dev/core/src/PostProcesses/vrDistortionCorrectionPostProcess.ts","../dev/core/src/Shaders/vrMultiviewToSingleview.fragment.ts","../dev/core/src/Materials/Textures/MultiviewRenderTarget.ts","../dev/core/src/Engines/Extensions/engine.multiview.ts","../dev/core/src/PostProcesses/vrMultiviewToSingleviewPostProcess.ts","../dev/core/src/Cameras/RigModes/vrRigMode.ts","../dev/core/src/Cameras/VR/vrDeviceOrientationFreeCamera.ts","../dev/core/src/Gamepads/gamepad.ts","../dev/core/src/Gamepads/Controllers/poseEnabledController.ts","../dev/core/src/Gamepads/xboxGamepad.ts","../dev/core/src/Cameras/RigModes/webVRRigMode.ts","../dev/core/src/Engines/Extensions/engine.webVR.ts","../dev/core/src/Cameras/VR/webVRCamera.ts","../dev/core/src/Gamepads/Controllers/webVRController.ts","../dev/core/src/Engines/Extensions/engine.dynamicTexture.ts","../dev/core/src/Materials/Textures/dynamicTexture.ts","../dev/core/src/Shaders/imageProcessing.fragment.ts","../dev/core/src/PostProcesses/imageProcessingPostProcess.ts","../dev/core/src/Gamepads/dualShockGamepad.ts","../dev/core/src/Gamepads/gamepadManager.ts","../dev/core/src/Cameras/Inputs/freeCameraGamepadInput.ts","../dev/core/src/Cameras/Inputs/arcRotateCameraGamepadInput.ts","../dev/core/src/Gamepads/gamepadSceneComponent.ts","../dev/core/src/Animations/runtimeAnimation.ts","../dev/core/src/Bones/bone.ts","../dev/core/src/Animations/animatable.ts","../dev/core/src/XR/webXRLayerWrapper.ts","../dev/core/src/XR/webXRRenderTargetTextureProvider.ts","../dev/core/src/XR/webXRWebGLLayer.ts","../dev/core/src/XR/webXRManagedOutputCanvas.ts","../dev/core/src/XR/native/nativeXRRenderTarget.ts","../dev/core/src/XR/webXRSessionManager.ts","../dev/core/src/XR/webXRTypes.ts","../dev/core/src/Meshes/Builders/cylinderBuilder.ts","../dev/core/src/Meshes/Builders/torusBuilder.ts","../dev/core/src/Cameras/VR/vrExperienceHelper.ts","../dev/core/src/Misc/dds.ts","../dev/core/src/Materials/Textures/Loaders/ddsTextureLoader.ts","../dev/core/src/Shaders/rgbdEncode.fragment.ts","../dev/core/src/Misc/environmentTextureTools.ts","../dev/core/src/Materials/Textures/Loaders/envTextureLoader.ts","../dev/core/src/Misc/khronosTextureContainer.ts","../dev/core/src/Misc/workerPool.ts","../dev/core/src/Materials/Textures/ktx2decoderTypes.ts","../dev/core/src/Loading/sceneLoader.ts","../dev/core/src/Misc/khronosTextureContainer2.ts","../dev/core/src/Materials/Textures/Loaders/ktxTextureLoader.ts","../dev/core/src/XR/webXRCamera.ts","../dev/core/src/XR/webXRFeaturesManager.ts","../dev/core/src/Cameras/touchCamera.ts","../dev/core/src/Cameras/universalCamera.ts","../dev/core/src/XR/webXRExperienceHelper.ts","../dev/core/src/XR/motionController/webXRControllerComponent.ts","../dev/core/src/XR/motionController/webXRAbstractMotionController.ts","../dev/core/src/XR/motionController/webXRGenericMotionController.ts","../dev/core/src/Meshes/Builders/sphereBuilder.ts","../dev/core/src/XR/motionController/webXRProfiledMotionController.ts","../dev/core/src/XR/motionController/webXRMotionControllerManager.ts","../dev/core/src/XR/webXRInputSource.ts","../dev/core/src/XR/webXRInput.ts","../dev/core/src/XR/features/WebXRAbstractFeature.ts","../dev/core/src/Rendering/utilityLayerRenderer.ts","../dev/core/src/XR/features/WebXRControllerPointerSelection.ts","../dev/core/src/Materials/Node/Enums/nodeMaterialBlockConnectionPointTypes.ts","../dev/core/src/Materials/Node/Enums/nodeMaterialBlockTargets.ts","../dev/core/src/Materials/Node/nodeMaterialBlockConnectionPoint.ts","../dev/core/src/Decorators/nodeDecorator.ts","../dev/core/src/Materials/Node/Enums/nodeMaterialBlockConnectionPointMode.ts","../dev/core/src/Materials/Node/Enums/nodeMaterialSystemValues.ts","../dev/core/src/Materials/Node/Blocks/Input/animatedInputBlockTypes.ts","../dev/core/src/Materials/Node/nodeMaterialBuildState.ts","../dev/core/src/Materials/Node/nodeMaterialBuildStateSharedData.ts","../dev/core/src/Materials/Node/nodeMaterialBlock.ts","../dev/core/src/Materials/Node/Blocks/transformBlock.ts","../dev/core/src/Materials/Node/Blocks/Vertex/vertexOutputBlock.ts","../dev/core/src/Materials/Node/Blocks/Fragment/fragmentOutputBlock.ts","../dev/core/src/Materials/Node/Blocks/Input/inputBlock.ts","../dev/core/src/Materials/Node/Blocks/Dual/currentScreenBlock.ts","../dev/core/src/Materials/Node/Blocks/Particle/particleTextureBlock.ts","../dev/core/src/Materials/Node/Blocks/Particle/particleRampGradientBlock.ts","../dev/core/src/Materials/Node/Blocks/Particle/particleBlendMultiplyBlock.ts","../dev/core/src/Materials/Node/Blocks/vectorMergerBlock.ts","../dev/core/src/Materials/Node/Blocks/remapBlock.ts","../dev/core/src/Materials/Node/Blocks/multiplyBlock.ts","../dev/core/src/Materials/Node/Enums/nodeMaterialModes.ts","../dev/core/src/Particles/EmitterTypes/boxParticleEmitter.ts","../dev/core/src/Particles/EmitterTypes/coneParticleEmitter.ts","../dev/core/src/Particles/EmitterTypes/cylinderParticleEmitter.ts","../dev/core/src/Particles/EmitterTypes/hemisphericParticleEmitter.ts","../dev/core/src/Particles/EmitterTypes/pointParticleEmitter.ts","../dev/core/src/Particles/EmitterTypes/sphereParticleEmitter.ts","../dev/core/src/Particles/EmitterTypes/meshParticleEmitter.ts","../dev/core/src/Particles/baseParticleSystem.ts","../dev/core/src/Materials/Node/Blocks/colorSplitterBlock.ts","../dev/core/src/Materials/Textures/Procedurals/proceduralTextureSceneComponent.ts","../dev/core/src/Shaders/procedural.vertex.ts","../dev/core/src/Materials/Textures/Procedurals/proceduralTexture.ts","../dev/core/src/Materials/Node/Blocks/trigonometryBlock.ts","../dev/core/src/Materials/Node/nodeMaterial.ts","../dev/core/src/XR/features/WebXRNearInteraction.ts","../dev/core/src/Meshes/subMesh.project.ts","../dev/core/src/XR/webXREnterExitUI.ts","../dev/core/src/Meshes/instancedMesh.ts","../dev/core/src/Materials/shaderMaterial.ts","../dev/core/src/Shaders/color.fragment.ts","../dev/core/src/Shaders/color.vertex.ts","../dev/core/src/Meshes/linesMesh.ts","../dev/core/src/Meshes/Builders/linesBuilder.ts","../dev/core/src/Misc/timer.ts","../dev/core/src/XR/features/WebXRControllerTeleportation.ts","../dev/core/src/XR/webXRDefaultExperience.ts","../dev/core/src/Helpers/sceneHelpers.ts","../dev/core/src/Shaders/glowMapGeneration.fragment.ts","../dev/core/src/Shaders/glowMapGeneration.vertex.ts","../dev/core/src/Layers/effectLayer.ts","../dev/core/src/Layers/effectLayerSceneComponent.ts","../dev/core/src/Lights/shadowLight.ts","../dev/core/src/Shaders/ShadersInclude/bayerDitherFunctions.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapFragmentExtraDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapFragment.ts","../dev/core/src/Shaders/shadowMap.fragment.ts","../dev/core/src/Shaders/ShadersInclude/sceneVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/meshVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapUboDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapVertexExtraDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapVertexNormalBias.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapVertexMetric.ts","../dev/core/src/Shaders/shadowMap.vertex.ts","../dev/core/src/Shaders/depthBoxBlur.fragment.ts","../dev/core/src/Shaders/ShadersInclude/shadowMapFragmentSoftTransparentShadow.ts","../dev/core/src/Lights/Shadows/shadowGenerator.ts","../dev/core/src/Shaders/depth.fragment.ts","../dev/core/src/Shaders/depth.vertex.ts","../dev/core/src/Rendering/depthRenderer.ts","../dev/core/src/Shaders/minmaxRedux.fragment.ts","../dev/core/src/Misc/depthReducer.ts","../dev/core/src/Misc/minMaxReducer.ts","../dev/core/src/Lights/Shadows/cascadedShadowGenerator.ts","../dev/core/src/Lights/Shadows/shadowGeneratorSceneComponent.ts","../dev/core/src/Lights/directionalLight.ts","../dev/core/src/Lights/pointLight.ts","../dev/core/src/Lights/spotLight.ts","../dev/core/src/Misc/sceneOptimizer.ts","../dev/core/src/Misc/sceneSerializer.ts","../dev/core/src/Rendering/depthRendererSceneComponent.ts","../dev/core/src/Shaders/line.fragment.ts","../dev/core/src/Shaders/line.vertex.ts","../dev/core/src/Rendering/edgesRenderer.ts","../dev/core/src/Engines/Extensions/engine.multiRender.ts","../dev/core/src/Materials/Textures/multiRenderTarget.ts","../dev/core/src/Shaders/ShadersInclude/mrtFragmentDeclaration.ts","../dev/core/src/Shaders/geometry.fragment.ts","../dev/core/src/Shaders/ShadersInclude/geometryVertexDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/geometryUboDeclaration.ts","../dev/core/src/Shaders/geometry.vertex.ts","../dev/core/src/Rendering/geometryBufferRenderer.ts","../dev/core/src/Rendering/geometryBufferRendererSceneComponent.ts","../dev/core/src/Shaders/outline.fragment.ts","../dev/core/src/Shaders/outline.vertex.ts","../dev/core/src/Rendering/outlineRenderer.ts","../dev/core/src/Materials/Textures/prePassRenderTarget.ts","../dev/core/src/Rendering/prePassRenderer.ts","../dev/core/src/Rendering/prePassRendererSceneComponent.ts","../Client/viewer/models/services/settings-manager-service.ts","../dev/core/src/Meshes/Builders/ribbonBuilder.ts","../dev/core/src/Meshes/Builders/discBuilder.ts","../dev/core/src/Meshes/Builders/tiledPlaneBuilder.ts","../dev/core/src/Meshes/Builders/tiledBoxBuilder.ts","../dev/core/src/Meshes/Builders/torusKnotBuilder.ts","../dev/core/src/Meshes/polygonMesh.ts","../dev/core/src/Meshes/Builders/polygonBuilder.ts","../dev/core/src/Meshes/Builders/shapeBuilder.ts","../dev/core/src/Meshes/Builders/latheBuilder.ts","../dev/core/src/Meshes/Builders/tubeBuilder.ts","../dev/core/src/Meshes/Builders/polyhedronBuilder.ts","../dev/core/src/Meshes/Builders/icoSphereBuilder.ts","../dev/core/src/Meshes/Builders/decalBuilder.ts","../dev/core/src/Meshes/Builders/capsuleBuilder.ts","../dev/core/src/Maths/math.isovector.ts","../dev/core/src/Meshes/geodesicMesh.ts","../dev/core/src/Meshes/goldbergMesh.ts","../dev/core/src/Meshes/Builders/textBuilder.ts","../dev/core/src/Meshes/meshBuilder.ts","../dev/core/src/Meshes/Builders/geodesicBuilder.ts","../dev/core/src/Meshes/Builders/goldbergBuilder.ts","../Client/viewer/view/helpers/gui-helper.ts","../Client/viewer/view/helpers/scene-helper.ts","../Client/viewer/view/kb-worker.ts","../Client/viewer/view/helpers/imagedata-polyfill.ts","../node_modules/@tweenjs/tween.js/dist/tween.esm.js","../Client/viewer/view/modules/animation.ts","../dev/core/src/XR/features/WebXRAnchorSystem.ts","../dev/core/src/XR/features/WebXRHitTest.ts","../dev/core/src/XR/features/WebXRPlaneDetector.ts","../dev/core/src/Morph/morphTarget.ts","../dev/serializers/src/glTF/2.0/glTFUtilities.ts","../dev/serializers/src/glTF/2.0/glTFAnimation.ts","../dev/serializers/src/glTF/2.0/glTFData.ts","../dev/core/src/Engines/Extensions/engine.rawTexture.ts","../dev/core/src/Materials/Textures/rawTexture.ts","../dev/core/src/Engines/constants.ts","../dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts","../dev/serializers/src/glTF/2.0/glTFExporter.ts","../dev/serializers/src/glTF/2.0/glTFSerializer.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_texture_transform.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_iridescence.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_sheen.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_unlit.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_ior.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_specular.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_volume.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.ts","../dev/core/src/Meshes/thinInstanceMesh.ts","../dev/serializers/src/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts","../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_emissive_strength.ts","../Client/viewer/view/modules/exporter-gltf.ts","../dev/core/src/Materials/Textures/colorGradingTexture.ts","../dev/core/src/Misc/HighDynamicRange/panoramaToCubemap.ts","../dev/core/src/Shaders/hdrFiltering.vertex.ts","../dev/core/src/Shaders/hdrFiltering.fragment.ts","../dev/core/src/Materials/Textures/Filtering/hdrFiltering.ts","../dev/core/src/Misc/HighDynamicRange/hdr.ts","../dev/core/src/Materials/Textures/hdrCubeTexture.ts","../dev/core/src/Engines/Extensions/engine.videoTexture.ts","../dev/core/src/Engines/Extensions/engine.externalTexture.ts","../dev/core/src/Misc/tga.ts","../dev/core/src/Materials/Textures/Loaders/tgaTextureLoader.ts","../dev/core/src/Misc/basis.ts","../dev/core/src/Materials/Textures/Loaders/hdrTextureLoader.ts","../dev/core/src/Materials/Textures/Loaders/basisTextureLoader.ts","../dev/core/src/Shaders/noise.fragment.ts","../dev/core/src/Materials/Textures/Procedurals/noiseProceduralTexture.ts","../dev/core/src/Materials/Textures/refractionTexture.ts","../node_modules/fflate/esm/browser.js","../Client/viewer/view/modules/usdz/usdz-converter.ts","../Client/viewer/view/modules/usdz/usdz-babylon-converter.ts","../Client/viewer/view/modules/xr/xr-hit-tester.ts","../Client/viewer/view/render/shadow-manager.ts","../Client/viewer/view/modules/xr/xr-light.ts","../Client/viewer/view/modules/xr/xr-marker.ts","../dev/core/src/Shaders/ShadersInclude/imageProcessingCompatibility.ts","../dev/materials/src/shadowOnly/shadowOnly.fragment.ts","../dev/materials/src/shadowOnly/shadowOnly.vertex.ts","../dev/materials/src/shadowOnly/shadowOnlyMaterial.ts","../Client/viewer/view/modules/xr/xr-shadow-plane.ts","../Client/viewer/view/modules/xr/xr-transient-hit-tester.ts","../Client/viewer/view/modules/xr/xr.ts","../Client/viewer/view/modules/ar.ts","../node_modules/rxjs/src/internal/operators/first.ts","../Client/viewer/view/modules/bounding-box-cache.ts","../Client/viewer/view/helpers/view-extensions.ts","../Client/viewer/view/helpers/bounding-box-relative-helper.ts","../Client/viewer/view/helpers/enum-maps.ts","../Client/viewer/view/helpers/light-helper.ts","../Client/viewer/view/helpers/quadtree.ts","../Client/viewer/view/helpers/earcut.ts","../Client/viewer/view/helpers/geometry-helper.ts","../Client/viewer/view/helpers/text-mesh-helper.ts","../dev/core/src/Materials/greasedLinePluginMaterial.ts","../dev/core/src/Meshes/Builders/greasedLineBuilder.ts","../dev/core/src/Meshes/Builders/hemisphereBuilder.ts","../dev/core/src/Misc/greasedLineTools.ts","../dev/core/src/Meshes/greasedLineMesh.ts","../Client/viewer/view/helpers/uvmap-helper.ts","../Client/viewer/view/helpers/vertex-group-helper.ts","../Client/viewer/view/helpers/viewpoint-helper.ts","../Client/viewer/view/render/renderer.ts","../Client/viewer/view/render/annotation.ts","../Client/viewer/view/render/dimension.ts","../Client/viewer/view/render/features/connector.ts","../Client/viewer/view/render/features/feature.ts","../Client/viewer/view/render/features/move-vertices.ts","../Client/viewer/view/render/features/normal-smoothing.ts","../dev/core/src/Particles/solidParticle.ts","../dev/core/src/Particles/solidParticleSystem.ts","../Client/viewer/view/render/features/utils.ts","../Client/viewer/view/render/features/pattern.ts","../Client/viewer/view/render/features/submesh.ts","../Client/viewer/view/render/features/uvmap.ts","../Client/viewer/view/render/light.ts","../Client/viewer/view/render/mate.ts","../dev/core/src/Probes/reflectionProbe.ts","../Client/viewer/view/render/material.ts","../Client/viewer/view/modules/sketching/util.ts","../node_modules/opentype.js/node_modules/string.prototype.codepointat/codepointat.js","../node_modules/opentype.js/node_modules/tiny-inflate/index.js","../node_modules/opentype.js/src/bbox.js","../node_modules/opentype.js/src/path.js","../node_modules/opentype.js/src/check.js","../node_modules/opentype.js/src/types.js","../node_modules/opentype.js/src/table.js","../node_modules/opentype.js/src/parse.js","../node_modules/opentype.js/src/tables/cmap.js","../node_modules/opentype.js/src/encoding.js","../node_modules/opentype.js/src/draw.js","../node_modules/opentype.js/src/glyph.js","../node_modules/opentype.js/src/glyphset.js","../node_modules/opentype.js/src/tables/cff.js","../node_modules/opentype.js/src/tables/head.js","../node_modules/opentype.js/src/tables/hhea.js","../node_modules/opentype.js/src/tables/hmtx.js","../node_modules/opentype.js/src/tables/ltag.js","../node_modules/opentype.js/src/tables/maxp.js","../node_modules/opentype.js/src/tables/name.js","../node_modules/opentype.js/src/tables/os2.js","../node_modules/opentype.js/src/tables/post.js","../node_modules/opentype.js/src/tables/gsub.js","../node_modules/opentype.js/src/tables/meta.js","../node_modules/opentype.js/src/tables/sfnt.js","../node_modules/opentype.js/src/layout.js","../node_modules/opentype.js/src/position.js","../node_modules/opentype.js/src/substitution.js","../node_modules/opentype.js/src/util.js","../node_modules/opentype.js/src/tables/glyf.js","../node_modules/opentype.js/src/hintingtt.js","../node_modules/opentype.js/src/tokenizer.js","../node_modules/opentype.js/src/char.js","../node_modules/opentype.js/src/features/featureQuery.js","../node_modules/opentype.js/src/features/arab/contextCheck/arabicWord.js","../node_modules/opentype.js/src/features/arab/contextCheck/arabicSentence.js","../node_modules/opentype.js/src/features/applySubstitution.js","../node_modules/opentype.js/src/features/arab/arabicPresentationForms.js","../node_modules/opentype.js/src/features/arab/arabicRequiredLigatures.js","../node_modules/opentype.js/src/features/latn/contextCheck/latinWord.js","../node_modules/opentype.js/src/features/latn/latinLigatures.js","../node_modules/opentype.js/src/bidi.js","../node_modules/opentype.js/src/font.js","../node_modules/opentype.js/src/tables/fvar.js","../node_modules/opentype.js/src/tables/gdef.js","../node_modules/opentype.js/src/tables/gpos.js","../node_modules/opentype.js/src/tables/kern.js","../node_modules/opentype.js/src/tables/loca.js","../node_modules/opentype.js/src/opentype.js","../Client/viewer/view/render/mesh.ts","../Client/viewer/view/helpers/mesh-builders/sphere-builder.ts","../Client/viewer/view/helpers/mesh-builders/cylinder-builder.ts","../Client/viewer/view/helpers/mesh-builders/torus-builder.ts","../Client/viewer/view/helpers/mesh-builders/plane-builder.ts","../Client/viewer/view/helpers/mesh-builders/disc-builder.ts","../Client/viewer/view/render/path.ts","../Client/viewer/view/helpers/mate-helper.ts","../Client/viewer/view/render/processors/mate-sorter.ts","../Client/viewer/view/render/processors/processor.ts","../Client/viewer/view/render/processors/mate-processor.ts","../Client/viewer/view/render/features/circular-pattern.ts","../Client/viewer/view/render/features/delete-faces.ts","../Client/viewer/view/render/features/displacement-map.ts","../Client/viewer/view/render/features/extrude.ts","../dev/core/src/Meshes/csg.ts","../Client/viewer/view/helpers/join-geometry-helper.ts","../Client/viewer/view/render/features/join-geometry.ts","../Client/viewer/view/render/features/linear-pattern.ts","../Client/viewer/view/render/features/slice.ts","../Client/viewer/view/helpers/mirror-helper.ts","../Client/viewer/view/render/features/mirror.ts","../node_modules/svg-pathdata/node_modules/tslib/tslib.es6.js","../node_modules/svg-pathdata/src/SVGPathDataEncoder.ts","../node_modules/svg-pathdata/src/mathUtils.ts","../node_modules/svg-pathdata/src/SVGPathDataTransformer.ts","../node_modules/svg-pathdata/src/TransformableSVG.ts","../node_modules/svg-pathdata/src/SVGPathDataParser.ts","../node_modules/svg-pathdata/src/SVGPathData.ts","../Client/viewer/view/modules/sketching/path-parser.ts","../Client/viewer/view/modules/sketching/path-handler.ts","../node_modules/imagetracer/dist/index.mjs","../node_modules/svg-parser/src/index.js","../node_modules/svg-parser/node_modules/locate-character/dist/locate-character.es.js","../Client/viewer/view/modules/sketching/svg-converter.ts","../Client/viewer/view/modules/miteredRibbonBuilder.ts","../Client/viewer/view/render/features/sweep.ts","../Client/viewer/view/render/features/transform.ts","../Client/viewer/view/render/features/weld-vertices.ts","../Client/viewer/view/render/feature-stack.ts","../Client/viewer/view/render/features/sketch-control-point.ts","../Client/viewer/view/render/processors/reference-processor.ts","../Client/viewer/view/render/processors/sketch-processor.ts","../dev/core/src/PostProcesses/RenderPipeline/postProcessRenderPipeline.ts","../dev/core/src/PostProcesses/RenderPipeline/postProcessRenderEffect.ts","../dev/core/src/PostProcesses/RenderPipeline/postProcessRenderPipelineManager.ts","../dev/core/src/PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent.ts","../dev/core/src/Shaders/chromaticAberration.fragment.ts","../dev/core/src/Shaders/lensHighlights.fragment.ts","../dev/core/src/Shaders/depthOfField.fragment.ts","../dev/core/src/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline.ts","../dev/core/src/Rendering/ssao2Configuration.ts","../dev/core/src/Shaders/ssao2.fragment.ts","../dev/core/src/Shaders/ssaoCombine.fragment.ts","../dev/core/src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts","../dev/core/src/Shaders/fxaa.fragment.ts","../dev/core/src/Shaders/fxaa.vertex.ts","../dev/core/src/PostProcesses/fxaaPostProcess.ts","../Client/viewer/view/render/scene.ts","../Client/viewer/view/render/textures/texture.ts","../Client/viewer/view/render/textures/color-fill-texture.ts","../Client/viewer/view/render/textures/file-texture.ts","../Client/viewer/common-util/buffer-util.ts","../Client/viewer/view/render/textures/svg-texture.ts","../Client/viewer/view/render/texture-stack.ts","../Client/viewer/view/render/viewpoint.ts","../Client/viewer/view/render/renderer-manager.ts","../Client/viewer/view/modules/cameras/kb-arc-rotate-camera-wheel-input.ts","../Client/viewer/view/modules/cameras/kb-arc-rotate-camera.ts","../Client/viewer/view/modules/camera-tools.ts","../node_modules/rxjs/src/internal/operators/startWith.ts","../dev/core/src/Culling/Octrees/octreeBlock.ts","../dev/core/src/Culling/Octrees/octree.ts","../Client/viewer/view/modules/dragger.ts","../Client/viewer/view/modules/exporter-obj.ts","../dev/serializers/src/OBJ/objSerializer.ts","../dev/core/src/Shaders/ShadersInclude/boundingBoxRendererFragmentDeclaration.ts","../dev/core/src/Shaders/ShadersInclude/boundingBoxRendererUboDeclaration.ts","../dev/core/src/Shaders/boundingBoxRenderer.fragment.ts","../dev/core/src/Shaders/ShadersInclude/boundingBoxRendererVertexDeclaration.ts","../dev/core/src/Shaders/boundingBoxRenderer.vertex.ts","../dev/core/src/Rendering/boundingBoxRenderer.ts","../dev/core/src/Misc/pivotTools.ts","../dev/core/src/Behaviors/Meshes/pointerDragBehavior.ts","../Client/viewer/view/modules/gizmos/axis-morph-gizmo.ts","../dev/core/src/Gizmos/gizmo.ts","../Client/viewer/view/modules/gizmos/gizmo.ts","../Client/viewer/view/modules/gizmos/plane-rotation-gizmo.ts","../Client/viewer/view/modules/gizmos/axis-angle-gizmo.ts","../Client/viewer/view/modules/face-engine.ts","../Client/viewer/view/modules/interaction.ts","../Client/viewer/view/modules/gizmos/facet-select-gizmo.ts","../Client/viewer/view/modules/gizmos/light-gizmo.ts","../Client/viewer/view/modules/gizmos/axis-drag-gizmo.ts","../Client/viewer/view/modules/gizmos/position-gizmo.ts","../Client/viewer/view/modules/gizmos/rotation-gizmo.ts","../Client/viewer/view/modules/gizmos/axis-scale-gizmo.ts","../Client/viewer/view/modules/gizmos/scale-gizmo.ts","../dev/core/src/Misc/gradients.ts","../dev/core/src/Particles/particle.ts","../dev/core/src/Particles/subEmitter.ts","../dev/core/src/Shaders/particles.fragment.ts","../dev/core/src/Shaders/particles.vertex.ts","../dev/core/src/Particles/particleSystem.ts","../Client/viewer/view/modules/gizmos/vertex-select-gizmo.ts","../Client/viewer/view/modules/gizmos/viewpoint-gizmo.ts","../Client/viewer/view/modules/gizmo-tools.ts","../Client/viewer/view/modules/sketch-editor.ts","../Client/viewer/view/modules/snapshot.ts","../Client/viewer/view/helpers/blob-helper.ts","../Client/viewer/view/modules/highlighter.ts","../Client/viewer/view/modules/right-click-menu.ts","../Client/viewer/view/kb-viewer.ts","../Client/viewer/index.ts","../Client/viewer/models/classes/validator.ts","../Client/viewer/view/modules/mesh-utils.ts","../Client/viewer/view/helpers/environment-helper.ts","../Client/viewer/tests/kb3d-test.ts"],"names":["kb3d","exports","String","prototype","capitalize","this","charAt","toUpperCase","slice","splitWordsRegex","__decorate","decorators","target","key","desc","d","c","arguments","length","r","Object","getOwnPropertyDescriptor","Reflect","decorate","i","defineProperty","__param","paramIndex","decorator","splitWords","match","isEqual","str","undefined","equalsAny","strings","some","s","toSentence","replace","trim","Array","enumerable","writable","value","predicate","sort","a","b","item","indexOf","splice","removed","push","selector","reduce","out","v","vres","isArray","valueDelegate","arr","every","keySelector","m","Map","set","fromIndex","toIndex","undo","itemToMove","Set","keys","k","has","SuppressedError","Token","constructor","static","token","Error","tokens","map","t","isPrimitive","PrimitiveTokenMap","isPrimitiveMesh","PrimitiveMeshTokenMap","isMesh","MeshTokenMap","isMeshOrGroup","MeshAndGroupTokenMap","isMaterial","MaterialTokenMap","isFeature","FeatureTokenMap","isTexture","TextureLayerTokenMap","isLight","LightTokenMap","isViewpoint","ViewpointNode","isMate","MateNode","isConnector","Connector","SketchControlPoint","isAnnotation","AnnotationTokenMap","isNode","NodeTokenMap","isSceneNode","SceneNode","isSketchPath","SketchPath","HttpService","MaterialService","MeshService","JobService","SceneService","FontService","Ignore","Kb3dObject","ImportInfo","LightNode","DirectionalLightNode","HemisphericLightNode","PointLightNode","SpotLightNode","BoxNode","CustomMeshNode","CylinderNode","ConeNode","DiscNode","PlaneNode","SphereNode","TorusNode","MeshNode","PrimitiveMeshNode","MeshGroupNode","SpaceNode","TextNode","SketchNode","AnnotationNode","DimensionNode","KbColor","KbGeometry","KbQuaternion","KbVector","MaterialNode","AdvancedMaterialNode","MaterialMapping","TextureLayer","FileTextureLayer","SvgTextureLayer","TextTextureLayer","ColorFillTextureLayer","Feature","BaseConnector","SubmeshFeature","MoveVerticesFeature","WeldVerticesFeature","DisplacementMapFeature","UvMapFeature","LinearPatternFeature","CircularPatternFeature","JoinGeometryFeature","DeleteFacesFeature","NormalSmoothingFeature","SliceFeature","MirrorFeature","TransformFeature","ExtrudeFeature","SweepFeature","PrimitiveTokens","MapFrom","PrimitiveMeshTokens","MeshTokens","concat","MeshAndGroupTokens","SpaceTokens","SpaceTokenMap","MaterialTokens","AnnotationTokens","PositionalLightTokens","GlobalLightTokens","LightTokens","FeatureTokens","ConnectorTokens","TextureLayerTokens","NodeTokens","BaseNodeTokens","AllTokens","AllTokenMap","Kb3dModels","instanceOf","instance","model","get","classConstructor","instanceOfAny","EChangeOperation","isTrackedClass","object","isTrackedInstance","isTrackedInstanceOfAny","changedItems","deletedItems","SyncService","tracker","modified","changes","add","delete","hasChanges","size","values","extendStatics","setPrototypeOf","__proto__","p","hasOwnProperty","__extends","__","create","isFunction","x","_enable_super_gross_mode_that_will_cause_bad_things","config","Promise","useDeprecatedSynchronousErrorHandling","stack","hostReportError","err","setTimeout","empty","closed","next","error","complete","isObject","UnsubscriptionErrorImpl","errors","call","message","toString","join","name","UnsubscriptionError","Subscription","unsubscribe","_parentOrParents","_subscriptions","_ctorUnsubscribe","_unsubscribe","_a","remove","index","e","flattenUnsubscriptionErrors","len","sub","teardown","subscription","EMPTY","tmp","subscriptions","subscriptionIndex","errs","rxSubscriber","Symbol","Math","random","Subscriber","_super","destinationOrNext","_this","syncErrorValue","syncErrorThrown","syncErrorThrowable","isStopped","destination","SafeSubscriber","tslib_1.__extends","subscriber","_next","_error","_complete","_unsubscribeAndRecycle","_parentSubscriber","observerOrNext","context","bind","_context","__tryOrSetError","__tryOrUnsub","wrappedComplete","fn","parent","observable","identity","pipeFromArray","fns","input","prev","Observable","subscribe","_isScalar","_subscribe","lift","operator","source","sink","nextOrObserver","toSubscriber","_trySubscribe","observer","closed_1","canReportError","console","warn","forEach","promiseCtor","getPromiseCtor","resolve","reject","pipe","operations","_i","toPromise","ObjectUnsubscribedError","ObjectUnsubscribedErrorImpl","SubjectSubscription","subject","observers","subscriberIndex","SubjectSubscriber","Subject","hasError","thrownError","AnonymousSubject","copy","asObservable","refCount","RefCountOperator","connectable","_refCount","refCounter","RefCountSubscriber","connection","connect","sharedConnection","_connection","ConnectableObservable","subjectFactory","_isComplete","getSubject","_subject","ConnectableSubscriber","connectableObservableDescriptor","connectableProto","BehaviorSubject","_value","getValue","configurable","AsyncAction","scheduler","work","pending","schedule","state","delay","id","recycleAsyncId","requestAsyncId","setInterval","flush","clearInterval","execute","_execute","errored","errorValue","actions","Action","QueueAction","Scheduler","SchedulerAction","now","Date","AsyncScheduler","delegate","active","scheduled","action","shift","QueueScheduler","apply","queue","empty$1","emptyScheduled","isScheduler","subscribeToArray","array","scheduleArray","fromArray","of","args","pop","dispatch","Notification","kind","hasValue","observe","do","accept","toObservable","createNext","undefinedValueNotification","createError","createComplete","completeNotification","ObserveOnSubscriber","arg","notification","scheduleMessage","ObserveOnMessage","ReplaySubject","bufferSize","windowTime","Number","POSITIVE_INFINITY","_events","_infiniteTimeWindow","_bufferSize","_windowTime","nextInfiniteTimeWindow","nextTimeWindow","ReplayEvent","_getNow","_trimBufferThenGetEvents","eventsCount","spliceCount","time","max","async","ArgumentOutOfRangeError","ArgumentOutOfRangeErrorImpl","EmptyError","EmptyErrorImpl","project","thisArg","TypeError","MapOperator","MapSubscriber","count","result","OuterSubscriber","notifyNext","outerValue","innerValue","outerIndex","innerIndex","innerSub","notifyError","notifyComplete","InnerSubscriber","getSymbolIterator","iterator","isArrayLike","isPromise","then","subscribeTo","obj","obs","promise","iterable","iterator$1","done","return","subscribeToResult","outerSubscriber","innerSubscriber","NONE","CombineLatestOperator","resultSelector","CombineLatestSubscriber","observables","toRespond","unused","_outerValue","oldVal","_tryResultSelector","isInteropObservable","scheduleObservable","schedulePromise","isIterable","Symbol_iterator","scheduleIterable","from","SimpleInnerSubscriber","SimpleOuterSubscriber","innerSubscribe","mergeMap","concurrent","ii","MergeMapOperator","MergeMapSubscriber","hasCompleted","buffer","_tryNext","_innerSub","ish","innerSubscription","mergeAll","concatAll","merge","last","filter","FilterOperator","FilterSubscriber","DebounceTimeOperator","dueTime","DebounceTimeSubscriber","debouncedSubscription","lastValue","clearDebounce","dispatchNext","debouncedNext","defaultIfEmpty","defaultValue","DefaultIfEmptyOperator","DefaultIfEmptySubscriber","isEmpty","DistinctUntilChangedOperator","compare","DistinctUntilChangedSubscriber","hasKey","y","throwIfEmpty","errorFactory","defaultErrorFactory","ThrowIfEmptyOperator","ThrowIfEmptySubscriber","take","TakeOperator","total","TakeSubscriber","FinallyOperator","callback","FinallySubscriber","MulticastOperator","shareSubjectFactory","share","subjectOrSubjectFactory","shareReplay","configOrBufferSize","_b","_c","useRefCount","isComplete","shareReplayOperator","switchMap","SwitchMapOperator","SwitchMapSubscriber","takeUntil","notifier","TakeUntilOperator","takeUntilSubscriber","TakeUntilSubscriber","notifierSubscription","seenValue","TakeWhileOperator","inclusive","TakeWhileSubscriber","nextOrComplete","predicateResult","Boolean","defaultThrottleConfig","leading","trailing","throttleTime","duration","ThrottleTimeOperator","ThrottleTimeSubscriber","_hasTrailingValue","_trailingValue","throttled","dispatchNext$1","clearThrottle","isDefined","o","changesProcessed","guidRegex","isGuid","test","absoluteUrlRegex","isAbsoluteUrl","url","appendOrIncrementNumber","lastNumber","parseInt","UUID","hexBytes","substr","n","buf","bufIdx","crypto","getRandomValues","Uint8Array","randomBytesBuffered","uuidBin","initialize","history","SceneHistory","undoneChanges","ignoreChangesFromObjects","undoneState","updateState","getMergedChanges","updateUndoneState","changePart","change","description","nodes","node","properties","flatMap","property","ignoreUntilStable","clear","start","stop","addChange","processFunction","undoFunction","newChange","openChange","redoFunction","lastChangeSet","processChangeSet","reverse","restore","previousValue","operation","CreateAndPush","Push","Unshift","Shift","unshift","isModified","Pop","Remove","Splice","newValue","restoreItem","redo","lastUndoneChangeSet","createAndPush","undoTo","redoTo","changeEvent","originalValue","lastChangeOnObject","lastChangeOnObjectProperty","find","changeEvents","removeLastChange","changeSet","process","nextTick","__arrayProtoFunctions","arrayFunc","TrackedArray","parentObj","propertyName","changesIgnored","historyIgnored","super","$isTracked","items","setPropertyIsModified","res","addedToChildArray","destroy","deleteCount","insert","resultItem","removedFromChildArray","reorder","TrackChanges","options","onCreateCallback","onCreate","isPropertyEqualOverride","isPropertyEqual","onDestroy","targetClass","TrackedClass","$changesTracked","trackingState","baseObject","originalValues","defineProperties","_trackChanges","commitChanges","inherited","originalValuesMap","oldValue","proxy","changedValuesMap","updateIsModified","nodeChangesProcessed","registerDeleted","inheritedDestroyFunc","getPrototypeOf","trackChanges","rawNode","Proxy","currentValue","isPropertyModified","isEqualToOriginal","registerNewObject","trackedNewProperty","_changesIgnoredProperties","arrayHistoryIgnored","_historyIgnoredProperties","registerChangedState","prop","NodeReference","classRef","propertyKey","parameterIndex","nodeReferences","limitKeys","IgnoreChanges","IgnoreHistory","TrackChangesNode","origAddedToChildArray","arrayPropName","_parent","calculateParents","origDestroy","children","getChildren","child","_manager","unregister","z","isKbVector","g","isKbColor","w","isKbQuaternion","equal","Kb3dModel","$type","combinedConstructor","trackChangesFactory","BaseKb3dModel","Enumerable","descriptor","injectParameters","Inject","ignore","getConstructorParamsForModel","modelDef","paramsForType","sortBy","Kb3dService","eParentChangeBehavior","eNodeError","eMeshChangeTypes","_level","_errors","_selected","_expanded","generate","_dynamicId","_token","withKey","_rootScene","__rootScene","setRootScene","scene","metadata","_metadata","val","clone","serialize","serializeToJson","prettyPrint","deletion","_parentScene","register","getChildArrayForType","getChildArray","addChildren","removeChildren","insertChildAfter","afterChild","newChild","arr1","arr2","getAncestors","ancestors","getNamePath","path","self","includeSelf","alwaysIncludeChildren","included","filterByType","filterNodes","_sketchControlPoints","getSpaceParent","ALL_GEOMETRY","VertexIndices","VertexPositions","VertexNormals","VertexUvs","Submeshes","ALL_CHANGES","Transform","isFeatureNode","dependsOn","_dependsOn","affects","_affects","affectedBy","_affectedBy","_suppressed","defaults","enabled","label","fontFamily","fontSize","lineSpacing","preloadFontStylesheet","color","targetId","billboard","isPickable","keepOnTop","lineStyle","horizontalTextAlign","verticalBoxAlign","horizontalBoxAlign","offset","target2Id","lineCapStyle","axis","lineThickness","dimensionGap","dimensionUnitPrecision","labelOffset","scaleWithCamera","positionMode","position","direction","angle","positionZeroToOne","interpolateDirection","arc","pivot","meshId","distance","addEndMesh","minDisplacement","maxDisplacement","capEnd","capStart","joinType","translation","cloneGeometry","intersect","normal","removeGeometry","rotationAxis","rotationAngle","scale","center","smooth","PatternFeature","uvMapping","materialId","projectionAxis","uTile","vTile","uOffset","vOffset","mode","end","mitredExtrusion","generatesShadows","shadowQuality","shadowResolution","shadowFilter","processTransparency","intensity","visible","useEuler","eulerRotation","scaling","fixed","groundColor","ShadowLightNode","coneAngle","workflowMode","backFaceCulling","directIntensity","emissiveIntensity","environmentIntensity","specularIntensity","metallic","roughness","microSurface","useSpecularOverAlpha","useRadianceOverAlpha","ambientColor","albedoColor","specularColor","reflectionColor","anisotropyEnabled","anisotropicDirection","anisotropicIntensity","subsurfaceThickness","subsurfaceRefractionEnabled","subsurfaceReflectionEnabled","reflectionType","probePositionTargetId","subsurfaceRefractionIndex","subsurfaceRefractionIntensity","subsurfaceRefractionLinkTransparency","subsurfaceTranslucencyEnabled","subsurfaceTranslucencyIntensity","subsurfaceUseAlbedoForTintColor","subsurfaceTintColor","clearcoatEnabled","clearcoatIntensity","clearcoatTintEnabled","clearcoatTintColor","clearcoatTintIntensity","archived","location","alpha","zOffset","doubleSided","legacyTextureStacking","viewMode","emissiveColor","hasTransparency","uScale","vScale","uAngle","vAngle","wAngle","uPivot","vPivot","wPivot","width","height","strength","tile","maintainAspect","useClippingMask","blendMode","horizontalAlign","verticalAlign","horizontalFit","verticalFit","flipNormalsRg","text","connector1","connector2","mateType","flip","offsetX","offsetY","offsetZ","offsetAngle","depth","tessellation","sideOrientation","flipSurfaceOrientation","receiveShadows","castShadows","checkCollisions","opacity","radiusTop","radiusBottom","radius","subdivisions","capMode","GroundNode","segments","direction2","addFace","closePath","tracePath","pathColor","flipPath","clonePath","boundingXOverride","boundingYOverride","boundingZOverride","pathGroupKey","holeForPathGroup","type","latitudeStart","latitudeSlice","curveRadius","charSpacing","fontFile","thickness","background","environment","environmentBlur","backgroundColor","renderMode","edgeColor","edgeWidth","edgeDisplayTolerance","viewpointId","frameViewpoint","progressiveTextureLoad","enableDeferredSceneUpdates","enableGrid","enableGridAxes","gridSize","gridStepSize","gridMajorInterval","gridNormal","environmentRotation","connectorSize","enableFxaaPostProcess","enableLensEffectsPostProcess","enableSSAOPostProcess","textureSamplingMode","fullscreenEnabled","arEnabled","xrAllowScaling","unitsPerMeter","xrAddShadow","xrLightingEstimation","enableHoverEffects","enableSceneOptimization","loadingExperience","loadingImagePath","dimensionUnitScalar","dimensionUnitSymbol","conversionMap","targetMode","projection","targetPoint","targetMeshId","rotation","fov","allowOrbit","allowPan","allowZoom","limitMinimumTargetDistance","minTargetDistance","maxTargetDistance","orbitAxis","limitLatOrbit","limitMinLatitude","limitMaxLatitude","limitLngOrbit","limitMinLongitude","limitMaxLongitude","NEVER_INHERIT","isMaterialNode","_materialService","_overriddenPropertiesSet","_initialized","materials","_materials","overriddenProperties","_overriddenProperties","textures","_textures","init","refreshParentMaterial","texture","overrideProperty","parentMaterialId","inheritProperty","_parentMaterial","getTextureByName","f","inheritFromMaterial","parentMat","manager","_key","currentTextures","tex","indexOnParent","texDef","channel","findIndex","currentTexture","textureNode","deserialize","_external","getMaterialById","parentMaterial","data","getMediaReferences","refs","AndOrNotEvaluator","query","evaluateCallback","_HandleParenthesisContent","Eval","parenthesisContent","or","split","ori","_SimplifyNegation","and","j","andj","substring","booleanString","Tags","_tags","hasTags","HasTags","addTags","tagsString","AddTagsTo","removeTags","RemoveTagsFrom","matchesTagsQuery","tagsQuery","MatchesQuery","tags","asString","tagsArray","tag","_AddTagTo","EnableFor","_RemoveTagFrom","Scalar","epsilon","abs","isNaN","min","log","LOG2E","log2","floor","NaN","Infinity","normalized","current","num","Repeat","tx","to","Clamp","maxDelta","Sign","DeltaAngle","MoveTowards","amount","value1","tangent1","value2","tangent2","squared","cubed","t2","number","percent","TwoPi","PI","HCF","ToGammaSpace","ToLinearSpace","PHI","sqrt","Epsilon","ArrayTools","itemBuilder","BuildArray","observedArrayFunctions","_ObserveArray","unObserveFunctions","functionName","oldFunction","newFunction","previousLength","returnValue","previous","_observeArrayfunction","unObserveFunction","_RegisteredTypes","RegisterClass","className","GetClass","fqdn","PerformanceConfigurator","use64bits","MatrixTrackPrecisionChange","MatrixUse64Bits","MatrixTrackedMatrices","matrix","_m","MatrixCurrentType","Float32Array","EventState","mask","skipNextObservers","currentTarget","Observer","scope","_willBeUnregistered","unregisterOnNextCall","_remove","onErrorObservable","ret","notifyObservers","catch","_observers","onObserverAdded","notifyIfTriggered","_numObserversMarkedAsDeleted","_hasNotified","_eventState","_onObserverAdded","insertFirst","unregisterOnFirstCall","_lastNotifiedValue","notifyObserver","addOnce","_deferUnregister","removeCallback","updateCounter","makeObserverTopPriority","makeObserverBottomPriority","eventData","userInfo","lastReturnValue","hasObservers","cleanLastNotifiedState","hasSpecificMask","EngineStore","LastCreatedEngine","Instances","LastCreatedScene","_LastCreatedScene","OnEnginesDisposedObservable","UseFallbackTexture","FallbackTexture","_ExtractAsInt","Vector2","getClassName","getHashCode","hash","toArray","FromArrayToRef","asArray","copyFrom","copyFromFloats","otherVector","addToRef","addInPlace","addVector3","subtract","subtractToRef","subtractInPlace","multiplyInPlace","multiply","multiplyToRef","multiplyByFloats","divide","divideToRef","divideInPlace","negate","negateInPlace","negateToRef","scaleInPlace","scaleToRef","scaleAndAddToRef","equals","equalsWithEpsilon","WithinEpsilon","fract","rotateToRef","cos","sin","lengthSquared","normalize","NormalizeToRef","RandomRange","ZeroReadOnly","_ZeroReadOnly","value3","value4","part1","part2","part3","part4","Hermite1stDerivativeToRef","left","right","vector","newVector","transformation","TransformToRef","p0","p1","p2","sign","DistanceSquared","CenterToRef","ref","segA","segB","l2","Distance","Dot","proj","Zero","Vector3","_x","_isDirty","_y","_z","toQuaternion","Quaternion","RotationYawPitchRoll","addInPlaceFromFloats","subtractFromFloatsToRef","subtractFromFloats","getNormalToRef","theta","acos","phi","atan2","applyRotationQuaternionToRef","q","vx","vy","vz","qx","qy","qz","qw","_w","ty","tz","applyRotationQuaternionInPlace","applyRotationQuaternion","projectOnPlane","plane","origin","projectOnPlaneToRef","V","MathTmp","denom","pow","setAll","scaledV","equalsToFloats","minimizeInPlace","other","minimizeInPlaceFromFloats","maximizeInPlace","maximizeInPlaceFromFloats","isNonUniformWithinEpsilon","absX","absY","absZ","isNonUniform","hasAZeroComponent","normalizeFromLength","reorderInPlace","order","toLowerCase","rotateByQuaternionToRef","quaternion","toRotationMatrix","Matrix","TransformCoordinatesToRef","rotateByQuaternionAroundPointToRef","point","cross","CrossToRef","normalizeToNew","normalizeToRef","reference","vector0","vector1","d0","v0","v1","dot","vNormal","forward","NormalizeRadians","diff","TmpVectors","PitchYawRollToMoveBetweenPointsToRef","slerp","vector0Dir","vector1Dir","vector0Length","vector1Length","scale0","scale1","omega","invSin","Lerp","goal","deltaTime","lerpTime","SlerpToRef","FromArray","UpReadOnly","_UpReadOnly","DownReadOnly","_DownReadOnly","RightReadOnly","_RightReadOnly","LeftReadOnly","_LeftReadOnly","LeftHandedForwardReadOnly","_LeftHandedForwardReadOnly","RightHandedForwardReadOnly","_RightHandedForwardReadOnly","LeftHandedBackwardReadOnly","_LeftHandedBackwardReadOnly","RightHandedBackwardReadOnly","_RightHandedBackwardReadOnly","OneReadOnly","_OneReadOnly","rightHandedSystem","TransformCoordinatesFromFloatsToRef","rx","ry","rz","rw","TransformNormalToRef","TransformNormalFromFloatsToRef","ClampToRef","LerpToRef","world","transform","viewport","ProjectToRef","cw","ch","cx","cy","viewportMatrix","FromValuesToRef","inDirection","ReflectToRef","viewportWidth","viewportHeight","Unproject","IdentityReadOnly","view","UnprojectToRef","UnprojectFloatsToRef","sourceX","sourceY","sourceZ","invert","screenSource","isNDCHalfZRange","_UnprojectFromInvertedMatrixToRef","p1p0","p2p0","p2p1","vectorp0","p1p0L","p2p0L","p2p1L","nl","l","cosA","projVector","v2","projP","s0","s1","s2","edge","e0","e1","tmp2","tmp3","e0proj","e0projL","cosG","triProj","axis1","axis2","axis3","RotationFromAxisToRef","quat","RotationQuaternionFromAxisToRef","toEulerAnglesToRef","Up","Down","Forward","Backward","Right","Left","One","Vector4","toVector3","otherQuaternion","q1","conjugateToRef","conjugateInPlace","conjugate","invertInPlace","inv","toEulerAngles","zAxisY","limit","sqw","sqz","sqx","sqy","asin","FromQuaternionToRef","fromRotationMatrix","FromRotationMatrixToRef","m11","m12","m13","m21","m22","m23","m31","m32","m33","trace","quat0","quat1","RotationAxisToRef","RotationYawPitchRollToRef","vec","vecFrom","vecTo","yaw","pitch","roll","halfRoll","halfPitch","halfYaw","sinRoll","cosRoll","sinPitch","cosPitch","sinYaw","cosYaw","beta","gamma","RotationAlphaBetaGammaToRef","halfGammaPlusAlpha","halfGammaMinusAlpha","halfBeta","rotMat","FromXYZAxesToRef","up","FromLookDirectionLHToRef","LookDirectionLHToRef","FromLookDirectionRHToRef","LookDirectionRHToRef","Identity","num2","num3","num4","flag","num5","num6","Use64Bits","markAsUpdated","updateFlag","_UpdateFlagSeed","_isIdentity","_isIdentity3x2","_isIdentityDirty","_isIdentity3x2Dirty","_updateIdentityStatus","isIdentity","isIdentityDirty","isIdentity3x2","isIdentity3x2Dirty","isIdentityAs3x2","determinant","m00","m01","m02","m03","m10","m20","m30","det_22_33","det_21_33","det_21_32","det_20_33","det_20_32","det_20_31","invertToRef","reset","resultM","otherM","addToSelf","IdentityToRef","cofact_00","cofact_01","cofact_02","cofact_03","det","detInv","det_12_33","det_11_33","det_11_32","det_10_33","det_10_32","det_10_31","det_12_23","det_11_23","det_11_22","det_10_23","det_10_22","det_10_21","cofact_10","cofact_11","cofact_12","cofact_13","cofact_20","cofact_21","cofact_22","cofact_23","cofact_30","cofact_31","cofact_32","cofact_33","addAtIndex","multiplyAtIndex","setTranslationFromFloats","addTranslationFromFloats","setTranslation","vector3","getTranslation","getTranslationToRef","removeRotationAndScaling","copyToArray","multiplyToArray","tm0","tm1","tm2","tm3","tm4","tm5","tm6","tm7","tm8","tm9","tm10","tm11","tm12","tm13","tm14","tm15","om0","om1","om2","om3","om4","om5","om6","om7","om8","om9","om10","om11","om12","om13","om14","om15","om","decomposeToTransformNode","rotationQuaternion","decompose","preserveScalingNode","signX","signY","signZ","sx","sy","sz","getRow","getRowToRef","rowVector","setRow","row","setRowFromFloats","transpose","TransposeToRef","transposeToRef","toNormalMatrix","getRotationMatrix","getRotationMatrixToRef","toggleModelMatrixHandInPlace","toggleProjectionMatrixHandInPlace","_IdentityReadOnly","initialM11","initialM12","initialM13","initialM14","initialM21","initialM22","initialM23","initialM24","initialM31","initialM32","initialM33","initialM34","initialM41","initialM42","initialM43","initialM44","ComposeToRef","x2","y2","z2","xx","xy","xz","yy","yz","zz","wx","wy","wz","FromValues","zero","RotationXToRef","RotationYToRef","RotationZToRef","c1","Cross","ScalingToRef","TranslationToRef","startValue","endValue","gradient","startM","endM","DecomposeLerpToRef","startScale","startRotation","startTranslation","endScale","endRotation","endTranslation","resultScale","resultRotation","resultTranslation","eye","LookAtLHToRef","xAxis","yAxis","zAxis","xSquareLength","ex","ey","ez","LookAtRHToRef","back","znear","zfar","halfZRange","OrthoLHToRef","mtxConvertNDCToHalfZRange","bottom","top","OrthoOffCenterLHToRef","i0","i1","OrthoOffCenterRHToRef","projectionPlaneTilt","rot","tan","aspect","reverseDepthBufferMode","PerspectiveFovLHToRef","isVerticalFovFixed","PerspectiveFovRHToRef","rightHanded","rightHandedFactor","upTan","upDegrees","downTan","downDegrees","leftTan","leftDegrees","rightTan","rightDegrees","xScale","yScale","zmin","zmax","rm","mm","ReflectionToRef","temp","temp2","temp3","xaxis","yaxis","zaxis","zw","zx","yw","xw","BuildTuple","_WarnImport","colorChannelToLinearSpace","colorChannelToLinearSpaceExact","colorChannelToGammaSpace","colorChannelToGammaSpaceExact","Color3","toColor4","Color4","toLuminance","otherColor","equalsFloats","clampToRef","toHexString","intR","round","intG","intB","ToHex","toHSV","toHSVToRef","h","dm","toLinearSpace","exact","convertedColor","toLinearSpaceToRef","toGammaSpace","toGammaSpaceToRef","hue","saturation","chroma","HSVtoRGBToRef","hex","FromInts","Black","BlackReadOnly","_BlackReadOnly","returnAsColor3","intA","color3","colors","colors4","newIndex","TmpColors","__decoratorInitialStore","__mergedStore","_copySource","creationFunction","instanciate","GetTags","classStore","getMergedStore","textureMap","propertyDescriptor","sourceProperty","propertyType","SerializationHelper","AllowLoadingUniqueId","cloneTexturesOnlyOnce","uniqueId","isRenderTarget","classKey","store","currentKey","initialStore","generateSerializableMember","sourceName","getDirectStore","expandToProperty","targetKey","setCallback","generateExpandMember","serializeAsTexture","serializeAsColor3","serializeAsFresnelParameters","serializeAsVector2","serializeAsVector3","serializeAsMeshReference","serializeAsColor4","serializeAsImageProcessingConfiguration","serializeAsMatrix","animations","animationIndex","animation","entity","serializationObject","serializedProperties","targetPropertyName","rootUrl","dest","_TextureParser","_FresnelParametersParser","getLastMeshById","_ColorCurvesParser","_ImageProcessingConfigurationParser","getCameraById","ParseProperties","nativeOverride","jsFunc","params","func","_native","nativeFunc","_InternalNodeDataInfo","_doNotSerialize","_isDisposed","_sceneRootNodesIndex","_isEnabled","_isParentEnabled","_isReady","_onEnabledStateChangedObservable","_onClonedObservable","Node","constructorFunc","_NodeConstructors","accessibilityTag","_accessibilityTag","onAccessibilityTagChangedObservable","doNotSerialize","_nodeDataStorage","_parentNode","isDisposed","previousParentNode","_children","_addToSceneRootNodes","_removeFromSceneRootNodes","_syncParentEnabledState","_serializeAsParent","parentId","_scene","rootNodes","lastIdx","animationPropertiesOverride","_animationPropertiesOverride","onDispose","_onDisposeObserver","onDisposeObservable","onEnabledStateChangedObservable","onClonedObservable","reservedDataStore","_parentContainer","_ranges","onReady","_currentRenderId","_parentUpdateId","_childUpdateId","_waitingParentId","_waitingParentInstanceIndex","_waitingParsedUniqueId","_cache","_worldMatrix","_worldMatrixDeterminant","_worldMatrixDeterminantIsDirty","_isNode","_behaviors","getUniqueId","_initCache","getScene","getEngine","addBehavior","behavior","attachImmediately","isLoading","onDataLoadedObservable","attach","removeBehavior","detach","behaviors","getBehaviorByName","getWorldMatrix","getRenderId","computeWorldMatrix","_getWorldMatrixDeterminant","worldMatrixFromCache","updateCache","force","isSynchronized","_updateCache","_getActionManagerForTrigger","trigger","_initialCall","_ignoreParentClass","_isSynchronized","_markSyncedWithParent","isSynchronizedWithParent","isReady","_completeCheck","markAsDirty","_property","MAX_VALUE","isEnabled","checkAncestors","setEnabled","isDescendantOf","ancestor","_getDescendants","results","directDescendantsOnly","getDescendants","getChildMeshes","cullingStrategy","_setReady","getAnimationByName","createAnimationRange","_AnimationRangeFactory","nAnimations","createRange","deleteAnimationRange","deleteFrames","deleteRange","getAnimationRange","newParent","doNotCloneChildren","Clone","directDescendants","getAnimationRanges","animationRanges","beginAnimation","loop","speedRatio","onAnimationEnd","range","serializeAnimationRanges","serializationRanges","localRange","_force","dispose","doNotRecurse","disposeMaterialAndTextures","parsedNode","ranges","getHierarchyBoundingVectors","includeDescendants","incrementRenderId","thisAbstractMesh","getBoundingInfo","subMeshes","boundingInfo","boundingBox","minimumWorld","maximumWorld","descendants","descendant","childMesh","getTotalVertices","minBox","maxBox","CheckExtends","IsWindowObjectExist","window","IsNavigatorAvailable","navigator","IsDocumentAvailable","document","GetDOMTextContent","element","firstChild","nodeType","textContent","nextSibling","_name","_from","_to","Logger","entry","_LogLimitOutputs","level","MessageLimitReached","_Levels","_LogCache","OnNewCacheEntry","padStr","date","getHours","getMinutes","getSeconds","_CheckLimit","formattedMessage","_FormatMessage","logFunc","_AddLogEntry","_GenerateLimitMessage","LogCache","errorsCount","LogLevels","Log","_LogDisabled","Warn","MessageLogLevel","WarningLogLevel","ErrorLogLevel","_LogEnabled","NoneLogLevel","AllLogLevel","CloneValue","destinationObject","DeepCopier","doNotCopyList","mustCopyList","props","getOwnPropertyNames","GetAllPropertyNames","endsWith","sourceValue","typeOfSourceValue","clonedValue","PrecisionDate","Now","performance","WebRequest","_xhr","XMLHttpRequest","_requestURL","_injectCustomRequestHeaders","_shouldSkipRequestModifications","CustomRequestHeaders","setRequestHeader","SkipRequestModificationForBabylonCDN","includes","onprogress","readyState","status","statusText","response","responseURL","responseText","responseType","timeout","addEventListener","listener","removeEventListener","abort","send","body","open","method","update","CustomRequestModifiers","getResponseHeader","FilesInputStore","FilesToLoad","BaseError","_setPrototypeOf","proto","ErrorCodes","RuntimeError","errorCode","innerError","EncodeArrayBufferToBase64","keyStr","chr1","chr2","chr3","enc1","enc2","enc3","enc4","output","bytes","ArrayBuffer","isView","byteOffset","byteLength","DecodeBase64ToString","base64Data","atob","ShaderCodeNode","isValid","preprocessors","_d","_e","_f","_g","line","processor","lineProcessor","isFragment","processingContext","attributeKeyword","attributeKeywordName","varyingKeyword","varyingFragmentKeywordName","varyingVertexKeywordName","attributeProcessor","startsWith","varyingProcessor","varyingCheck","uniformProcessor","uniformRegexp","lookForClosingBracketForUniformBuffer","uniformBufferProcessor","uniformBufferRegexp","textureProcessor","textureRegexp","endOfUniformBufferProcessor","additionalDefineKey","additionalDefineValue","ShaderCodeCursor","_lines","currentLine","lineIndex","canRead","lines","trimmedLine","semicolonIndex","subLine","ShaderCodeConditionNode","ShaderCodeTestNode","testExpression","isTrue","ShaderDefineExpression","postfix","_OperatorPriority","infix","cacheItem","_InfixToPostfixCache","accessTime","stackIdx","pushOperand","operand","_Stack","peek","idx","InfixToPostfixCacheLimitSize","ClearCache","sortedCache","entries","InfixToPostfixCacheCleanupSize","ShaderDefineIsDefinedOperator","define","not","condition","ShaderDefineOrOperator","leftOperand","rightOperand","ShaderDefineAndOperator","ShaderDefineArithmeticOperator","testValue","ShaderLanguage","regexSE","regexSERevert","regexShaderInclude","regexShaderDecl","regexLightX","regexX","reusableMatches","ShaderProcessor","initializeShaders","sourceCode","engine","preProcessShaderCode","_ProcessIncludes","codeWithIncludes","processCodeAfterIncludes","migratedCode","_ProcessShaderConversion","_ApplyPreProcessing","vertexCode","fragmentCode","finalizeShaders","noPrecision","shouldUseHighPrecisionShader","expression","exec","operators","indexOperator","infixToPostfix","_ExtractOperation","command","_BuildSubExpression","cursor","rootNode","ifNode","_MoveCursor","first5","elseNode","elifNode","_BuildExpression","matches","_MoveCursorRegex","newRootNode","_MoveCursorWithinIf","newNode","defines","shaderLanguage","GLSL","version","platformName","_getGlobalDefines","preparedSourceCode","_ProcessPrecision","parseGLES3","_PreparePreProcessors","preProcessor","_EvaluatePreProcessors","postProcessor","_features","needShaderCodeInlining","inlineShaderCode","parts","keepProcessing","includeFile","supportsUniformBuffers","includesShadersStore","includeShaderUrl","shadersRepository","_FileToolsLoadFile","fileContent","includeContent","splits","RegExp","indexString","indexSplits","minIndex","maxIndex","sourceIncludeContent","indexParameters","newParts","part","splitPart","onSuccess","onProgress","offlineProvider","useArrayBuffer","onError","ShaderStore","ShadersRepository","ShadersRepositoryWGSL","ShadersStore","ShadersStoreWGSL","IncludesShadersStore","IncludesShadersStoreWGSL","Effect","EngineShaderStore","repo","onBindObservable","_onBindObservable","baseName","attributesNamesOrOptions","uniformsNamesOrEngine","samplers","fallbacks","onCompiled","onBind","onCompileObservable","_wasPreviouslyReady","_forceRebindOnNextCall","_wasPreviouslyUsingInstances","_bonesComputationForcedToCPU","_uniformBuffersNames","_multiTarget","_samplers","_compilationError","_allFallbacksProcessed","_uniforms","_fallbacks","_vertexSourceCodeOverride","_fragmentSourceCodeOverride","_transformFeedbackVaryings","_pipelineContext","_vertexSourceCode","_fragmentSourceCode","_vertexSourceCodeBeforeMigration","_fragmentSourceCodeBeforeMigration","_rawVertexSourceCode","_rawFragmentSourceCode","vertexSource","fragmentSource","processFinalCode","attributes","_engine","_attributesNames","_uniformsNames","uniformsNames","_samplerList","_indexParameters","transformFeedbackVaryings","multiTarget","_shaderLanguage","uniformBuffersNames","_uniformBuffersNamesList","_attributeLocationByName","_UniqueIdSeed","hostDocument","getHostDocument","vertexElement","getElementById","vertex","fragmentElement","fragment","_processingContext","_getShaderProcessingContext","processorOptions","_shouldUseHighPrecisionShader","_getShaderProcessor","GetShadersRepository","GetIncludesShadersStore","shaderPlatformName","useReverseDepthBuffer","shaderCodes","shadersLoaded","migratedVertexCode","Process","migratedFragmentCode","codeBeforeMigration","finalShaders","Finalize","_useFinalCode","_loadShader","Initialize","spectorName","WGSL","_prepareEffect","_isReadyInternal","getPipelineContext","getAttributesNames","getAttributeLocation","_attributes","getAttributeLocationByName","getAttributesCount","getUniformIndex","uniformName","getUniform","getSamplers","getUniformNames","getUniformBuffersNames","getIndexParameters","getCompilationError","allFallbacksProcessed","executeWhenCompiled","effect","isAsync","_checkIsReady","previousPipelineContext","_processCompilationErrors","shader","optionalKey","HTMLElement","shaderStore","GetShadersStore","shaderUrl","_loadFile","vertexSourceCode","_getVertexShaderCode","fragmentSourceCode","_getFragmentShaderCode","vertexSourceCodeBeforeMigration","fragmentSourceCodeBeforeMigration","rawVertexSourceCode","rawFragmentSourceCode","_rebuildProgram","scenes","markAllMaterialsAsDirty","_handlesSpectorRebuildCallback","attributesNames","createPipelineContext","rebuildRebind","_preparePipelineContext","_executeWhenRenderingStateIsCompiled","_fillEffectInformation","bindSamplers","unBindMesh","_deletePipelineContext","_getShaderCodeAndErrorLine","code","regexp","errorLine","lineNumber","uniform","attribute","LogShaderCodeOnCompilationError","lineErrorVertex","lineErrorFragment","notifyErrors","hasMoreFallbacks","isSupported","_bindTexture","setTexture","setDepthStencilTexture","setTextureArray","exName","initialPos","currentExName","channelIndex","setTextureFromPostProcess","postProcess","setTextureFromPostProcessOutput","bindUniformBuffer","bufferName","_BaseCache","useUBOBindingCache","bindUniformBufferBase","bindUniformBlock","blockName","setInt","setInt2","setInt3","setInt4","setIntArray","setIntArray2","setIntArray3","setIntArray4","setUInt","setUInt2","setUInt3","setUInt4","setUIntArray","setUIntArray2","setUIntArray3","setUIntArray4","setFloatArray","setArray","setFloatArray2","setArray2","setFloatArray3","setArray3","setFloatArray4","setArray4","setMatrices","matrices","setMatrix","setMatrix3x3","setMatrix2x2","setFloat","setBool","bool","setVector2","vector2","setFloat2","setVector3","setFloat3","setVector4","vector4","setQuaternion","setFloat4","setColor3","setColor4","setDirectColor4","color4","_releaseEffect","pixelShader","vertexShader","DepthCullingState","_isDepthTestDirty","_isDepthMaskDirty","_isDepthFuncDirty","_isCullFaceDirty","_isCullDirty","_isZOffsetDirty","_isFrontFaceDirty","isDirty","_zOffset","zOffsetUnits","_zOffsetUnits","cullFace","_cullFace","cull","_cull","depthFunc","_depthFunc","depthMask","_depthMask","depthTest","_depthTest","frontFace","_frontFace","gl","enable","CULL_FACE","disable","DEPTH_TEST","POLYGON_OFFSET_FILL","polygonOffset","StencilState","ALWAYS","funcRef","funcMask","opStencilFail","KEEP","opDepthFail","opStencilDepthPass","REPLACE","stencilFunc","stencilFuncRef","stencilFuncMask","stencilOpStencilFail","stencilOpDepthFail","stencilOpStencilDepthPass","stencilMask","stencilTest","AlphaState","_blendFunctionParameters","_blendEquationParameters","_blendConstants","_isBlendConstantsDirty","_alphaBlend","_isAlphaBlendDirty","_isBlendFunctionParametersDirty","_isBlendEquationParametersDirty","alphaBlend","setAlphaBlendConstants","setAlphaBlendFunctionParameters","value0","setAlphaEquationParameters","rgb","BLEND","blendFuncSeparate","blendEquationSeparate","blendColor","InternalTextureSource","InternalTexture","TextureSampler","wrapU","_cachedWrapU","wrapV","_cachedWrapV","wrapR","_cachedWrapR","anisotropicFilteringLevel","_cachedAnisotropicFilteringLevel","comparisonFunction","_comparisonFunction","useMipMaps","_useMipMaps","samplingMode","setParameters","compareSampler","generateMipMaps","_uniqueId","_setUniqueId","_source","delayAllocation","isCube","is3D","is2DArray","isMultiview","samples","format","onLoadedObservable","onRebuildCallback","baseWidth","baseHeight","baseDepth","invertY","_invertVScale","_associatedChannel","Unknown","_buffer","_bufferView","_bufferViewArray","_bufferViewArrayArray","_size","_extension","_files","_workingCanvas","_workingContext","_cachedCoordinatesMode","_isDisabled","_compression","_sphericalPolynomial","_sphericalPolynomialPromise","_sphericalPolynomialComputed","_lodGenerationScale","_lodGenerationOffset","_useSRGBBuffer","_lodTextureHigh","_lodTextureMid","_lodTextureLow","_isRGBD","_linearSpecularLOD","_irradianceTexture","_hardwareTexture","_maxLodLevel","_references","_gammaSpace","_Counter","_createHardwareTexture","incrementReferences","updateSize","updateTextureDimensions","_rebuild","swapAndSetIsReady","proxyInternalTexture","_swapAndDie","Temp","Url","createTexture","_originalUrl","Raw","createRawTexture","Raw3D","createRawTexture3D","Raw2DArray","createRawTexture2DArray","Dynamic","createDynamicTexture","updateDynamicTexture","getRenderingCanvas","Cube","createCubeTexture","CubeRaw","createRawCubeTexture","CubeRawRGBD","CubePrefiltered","createPrefilteredCubeTexture","swapAll","setUsage","cache","getLoadedTexturesCache","_releaseTexture","WebGLShaderProcessor","getCaps","drawBuffersExtension","regex","varyingRegex","WebGL2ShaderProcessor","varying","_isFragment","hasDrawBuffersExtension","search","hasOutput","DataBuffer","underlyingResource","references","capacity","is32Bits","WebGLDataBuffer","resource","WebGLPipelineContext","_valueCache","vertexCompilationError","fragmentCompilationError","programLinkError","programValidationError","isParallelCompiled","program","_isRenderingStateCompiled","uniforms","samplerList","getUniforms","attr","getAttributes","_cacheMatrix","_cacheFloat2","changed","_cacheFloat3","_cacheFloat4","_getShaderSource","fragmentShader","WebGLHardwareTexture","_webGLTexture","existingTexture","_MSAARenderBuffers","hardwareTexture","addMSAARenderBuffer","releaseMSAARenderBuffers","deleteRenderbuffer","release","deleteTexture","DrawWrapper","createMaterialContext","drawContext","createDrawContext","materialContext","setEffect","resetContext","StencilStateComposer","_isStencilTestDirty","_isStencilMaskDirty","_isStencilFuncDirty","_isStencilOpDirty","_func","_funcRef","_funcMask","_opStencilFail","_opDepthFail","_opStencilDepthPass","_mask","_enabled","useStencilGlobalOnly","stencilMaterial","stencilGlobal","stencilMaterialEnabled","STENCIL_TEST","stencilOp","BufferPointer","ThinEngine","NpmPackage","Version","webGLVersion","_caps","parallelShaderCompile","_webGLVersion","_shaderProcessor","_useReverseDepthBuffer","useReverse","_depthCullingState","frameId","_frameId","disableUniformBuffers","getCreationOptions","_creationOptions","highPrecisionShaderSupported","_highPrecisionShadersAllowed","needPOTTextures","forcePOTTextures","activeRenderLoops","_activeRenderLoops","doNotHandleContextLost","_doNotHandleContextLost","_supportsHardwareTextureRescaling","framebufferDimensionsObject","dimensions","_framebufferDimensionsObject","currentViewport","_cachedViewport","emptyTexture","_emptyTexture","emptyTexture3D","_emptyTexture3D","emptyTexture2DArray","_emptyTexture2DArray","emptyCubeTexture","_emptyCubeTexture","faceData","cubeData","isWebGPU","_isWebGPU","_shaderPlatformName","snapshotRendering","activate","snapshotRenderingMode","_snapshotRenderingMode","snapshotRenderingReset","OffscreenCanvas","canvas","createElement","createCanvas","_CreateCanvas","createCanvasImage","canvasOrContext","antialias","adaptToDeviceRatio","_h","_j","_k","_l","isFullscreen","cullBackFaces","renderEvenInBackground","preventCacheWipeBetweenFrames","validateShaderPrograms","hasOriginBottomLeft","_uniformBuffers","_storageBuffers","_windowIsBackground","_badOS","_badDesktopOS","_renderingQueueLaunched","onContextLostObservable","onContextRestoredObservable","_contextWasLost","disableVertexArrayObjects","_colorWrite","_colorWriteChanged","_stencilStateComposer","_stencilState","_alphaState","_alphaMode","_alphaEquation","_internalTexturesCache","_renderTargetWrapperCache","_activeChannel","_currentTextureChannel","_boundTexturesCache","_compiledEffects","_vertexAttribArraysEnabled","_uintIndicesCurrentlySet","_currentBoundBuffer","_currentFramebuffer","_dummyFramebuffer","_currentBufferPointers","_currentInstanceLocations","_currentInstanceBuffers","_vaoRecordInProgress","_mustWipeVertexAttributes","_nextFreeTextureSlots","_maxSimultaneousTextures","_maxMSAASamplesOverride","_activeRequests","_lastDevicePixelRatio","_transformTextureUrl","hostInformation","isMobile","premultipliedAlpha","onBeforeTextureInitObservable","_viewportCached","_unpackFlipYCached","enableUnpackFlipYCached","_boundUniforms","startTime","SetMatrixPrecision","useHighPrecisionMatrix","deterministicLockstep","lockstepMaxSteps","timeStep","audioEngine","stencil","_audioContext","audioEngineOptions","audioContext","_audioDestination","audioDestination","useExactSrgbConversions","_isStencilEnable","devicePixelRatio","limitDeviceRatio","_hardwareScalingLevel","getContext","_renderingCanvas","preserveDrawingBuffer","xrCompatible","userAgent","_setupMobileChecks","ua","exception","ExceptionList","targets","capture","captureConstraint","constraint","_onContextLost","evt","preventDefault","_onContextRestored","_restoreEngineAfterContextLost","_initGLContext","powerPreference","disableWebGL2Support","_gl","deleteQuery","renderbufferStorageMultisample","getContextAttributes","pixelStorei","UNPACK_COLORSPACE_CONVERSION_WEBGL","useHighPrecisionFloats","resize","_initFeatures","maxVertexAttribs","versionToLog","setAttribute","_checkForMobile","currentUA","initEngine","wipeCaches","_rebuildEffects","_rebuildComputeEffects","_rebuildBuffers","_rebuildInternalTextures","_rebuildRenderTargetWrappers","_sharedInit","currentState","internalTexture","renderTargetWrapper","ResetCache","areAllEffectsReady","uniformBuffer","storageBuffer","maxTexturesImageUnits","getParameter","MAX_TEXTURE_IMAGE_UNITS","maxCombinedTexturesImageUnits","MAX_COMBINED_TEXTURE_IMAGE_UNITS","maxVertexTextureImageUnits","MAX_VERTEX_TEXTURE_IMAGE_UNITS","maxTextureSize","MAX_TEXTURE_SIZE","maxSamples","MAX_SAMPLES","maxCubemapTextureSize","MAX_CUBE_MAP_TEXTURE_SIZE","maxRenderTextureSize","MAX_RENDERBUFFER_SIZE","MAX_VERTEX_ATTRIBS","maxVaryingVectors","MAX_VARYING_VECTORS","maxFragmentUniformVectors","MAX_FRAGMENT_UNIFORM_VECTORS","maxVertexUniformVectors","MAX_VERTEX_UNIFORM_VECTORS","getExtension","standardDerivatives","maxAnisotropy","astc","bptc","s3tc","s3tc_srgb","pvrtc","etc1","etc2","textureAnisotropicFilterExtension","uintIndices","fragmentDepthSupported","timerQuery","supportOcclusionQuery","canUseTimestampForTimerQuery","maxMSAASamples","colorBufferFloat","colorBufferHalfFloat","textureFloat","textureHalfFloat","textureHalfFloatRender","textureFloatLinearFiltering","textureFloatRender","textureHalfFloatLinearFiltering","vertexArrayObject","instancedArrays","textureLOD","texelFetch","blendMinMax","multiview","oculusMultiview","depthTextureExtension","canUseGLInstanceID","canUseGLVertexID","supportComputeShaders","supportSRGBBuffers","supportTransformFeedbacks","textureMaxLevel","texture2DArrayMaxLayerCount","MAX_ARRAY_TEXTURE_LAYERS","disableMorphTargetTexture","_glVersion","VERSION","rendererInfo","_glRenderer","UNMASKED_RENDERER_WEBGL","_glVendor","UNMASKED_VENDOR_WEBGL","VENDOR","RENDERER","HALF_FLOAT_OES","RGBA16F","RGBA32F","DEPTH24_STENCIL8","getQuery","getQueryEXT","TIMESTAMP_EXT","QUERY_COUNTER_BITS_EXT","MAX_TEXTURE_MAX_ANISOTROPY_EXT","_canRenderToFloatFramebuffer","COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR","COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT","COMPRESSED_SRGB_S3TC_DXT1_EXT","COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT","COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT","COMPRESSED_SRGB8_ETC2","COMPRESSED_SRGB8_ALPHA8_ETC2_EAC","_canRenderToHalfFloatFramebuffer","drawBuffers","drawBuffersWEBGL","DRAW_FRAMEBUFFER","FRAMEBUFFER","UNSIGNED_INT_24_8","UNSIGNED_INT_24_8_WEBGL","vertexArrayObjectExtension","createVertexArray","createVertexArrayOES","bindVertexArray","bindVertexArrayOES","deleteVertexArray","deleteVertexArrayOES","instanceExtension","drawArraysInstanced","drawArraysInstancedANGLE","drawElementsInstanced","drawElementsInstancedANGLE","vertexAttribDivisor","vertexAttribDivisorANGLE","getShaderPrecisionFormat","vertexhighp","VERTEX_SHADER","HIGH_FLOAT","fragmenthighp","FRAGMENT_SHADER","precision","blendMinMaxExtension","MAX","MAX_EXT","MIN","MIN_EXT","_glSRGBExtensionValues","SRGB","WebGL2RenderingContext","SRGB8","SRGB8_ALPHA8","sRGBExtension","SRGB_EXT","SRGB_ALPHA_EXT","forceSRGBBufferSupportState","LEQUAL","slot","forceBitmapOverHTMLImageElement","supportRenderAndCopyToLodForFloatTextures","supportDepthStencilTexture","supportShadowSamplers","uniformBufferHardCheckMatrix","allowTexturePrefiltering","trackUbosInFrame","checkUbosContentBeforeUpload","supportCSM","basisNeedsPOT","support3DTextures","needTypeSuffixInShaderConstants","supportMSAA","supportSSAO2","supportExtendedTextureFormats","supportSwitchCaseInShader","supportSyncTextureRead","needsInvertingBitmap","needToAlwaysBindUniformBuffers","supportRenderPasses","supportSpriteInstancing","_collectUbosUpdatedInFrame","isStencilEnable","_prepareWorkingCanvas","resetTextureCache","getInfo","getGlInfo","vendor","renderer","setHardwareScalingLevel","getHardwareScalingLevel","stopRenderLoop","renderFunction","_cancelFrame","_frameHandler","cancelAnimationFrame","getHostWindow","clearTimeout","_renderLoop","shouldRender","beginFrame","endFrame","_queueNewFrame","_boundRenderFunction","getAudioContext","getAudioDestination","ownerDocument","defaultView","getRenderWidth","useScreen","_currentRenderTarget","framebufferWidth","drawingBufferWidth","getRenderHeight","framebufferHeight","drawingBufferHeight","bindedRenderFunction","requester","QueueNewFrame","runRenderLoop","backBuffer","stencilStateComposer","applyStates","setBackBufferColor","textureFormat","textureType","_TempClearColorUint32","clearBufferuiv","COLOR","_TempClearColorInt32","clearBufferiv","clearColor","COLOR_BUFFER_BIT","GEQUAL","clearDepth","DEPTH_BUFFER_BIT","clearStencil","STENCIL_BUFFER_BIT","_viewport","setViewport","requiredWidth","requiredHeight","flushFramebuffer","forceSetSize","changeRatio","boundingRect","getBoundingClientRect","clientWidth","clientHeight","innerWidth","innerHeight","setSize","bindFramebuffer","rtWrapper","faceIndex","forceFullscreenViewport","lodLevel","layer","webglRTWrapper","unBindFramebuffer","_bindUnboundFramebuffer","_MSAAFramebuffer","_framebuffer","isMulti","framebufferTextureLayer","COLOR_ATTACHMENT0","framebufferTexture2D","TEXTURE_CUBE_MAP_POSITIVE_X","depthStencilTexture","_depthStencilTexture","attachment","_depthStencilTextureWithStencil","DEPTH_STENCIL_ATTACHMENT","DEPTH_ATTACHMENT","TEXTURE_2D","setState","culling","reverseSide","BACK","FRONT","setZOffset","setZOffsetUnits","CW","CCW","getDepthBuffer","setDepthBuffer","getZOffset","getZOffsetUnits","framebuffer","_currentFrameBufferIsDefaultFrameBuffer","generateMipmaps","_bindTextureDirectly","generateMipmap","disableGenerateMipMaps","onBeforeUnbind","unBindMultiColorAttachmentFramebuffer","READ_FRAMEBUFFER","blitFramebuffer","NEAREST","restoreDefaultFramebuffer","_resetVertexBufferBinding","bindArrayBuffer","_cachedVertexBuffers","createVertexBuffer","_createVertexBuffer","STATIC_DRAW","usage","vbo","createBuffer","dataBuffer","bufferData","ARRAY_BUFFER","createDynamicVertexBuffer","DYNAMIC_DRAW","_resetIndexBufferBinding","bindIndexBuffer","_cachedIndexBuffer","createIndexBuffer","indices","updatable","_normalizeIndexData","ELEMENT_ARRAY_BUFFER","BYTES_PER_ELEMENT","Uint32Array","Uint16Array","_unbindVertexArrayObject","_bindBuffer","pipelineContext","uniformLocation","getUniformBlockIndex","uniformBlockBinding","bindBuffer","updateArrayBuffer","bufferSubData","_vertexAttribPointer","indx","stride","pointer","UNSIGNED_INT","INT","vertexAttribIPointer","vertexAttribPointer","_bindIndexBufferWithCache","indexBuffer","_bindVertexBuffersAttributes","vertexBuffers","overrideVertexBuffers","unbindAllAttributes","ai","vertexBuffer","enableVertexAttribArray","getBuffer","getSize","byteStride","getIsInstanced","getInstanceDivisor","recordVertexArrayObject","vao","bindVertexArrayObject","_cachedVertexArrayObject","bindBuffersDirectly","vertexDeclaration","vertexStrideSize","_cachedEffectForVertexBuffers","attributesCount","FLOAT","bindBuffers","unbindInstanceAttributes","boundBuffer","ul","instancesBuffer","offsetLocation","releaseVertexArrayObject","_releaseBuffer","_deleteBuffer","deleteBuffer","updateAndBindInstancesBuffer","offsetLocations","bindInstancesBuffer","attributesInfo","computeStride","attributeSize","_currentEffect","attributeName","attributeType","divisor","disableInstanceAttributeByName","attributeLocation","disableInstanceAttribute","shouldClean","disableAttributeByIndex","disableVertexAttribArray","draw","useTriangles","indexStart","indexCount","instancesCount","drawElementsType","drawPointClouds","verticesStart","verticesCount","drawArraysType","drawUnIndexed","fillMode","_reportDrawCall","drawMode","_drawMode","indexFormat","UNSIGNED_SHORT","mult","drawElements","drawArrays","TRIANGLES","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","webGLPipelineContext","__SPECTOR_rebuildProgram","deleteProgram","createEffect","vertexToken","fragmentToken","globalDefines","fullDefines","compiledEffect","shaderVersion","_compileShader","_compileRawShader","_ConcatenateShader","createShader","NO_ERROR","tempError","getError","isContextLost","shaderSource","compileShader","getShaderSource","createRawShaderProgram","_createShaderProgram","createShaderProgram","shaderProcessingContext","shaderProgram","createProgram","attachShader","linkProgram","_finalizePipelineContext","getProgramParameter","LINK_STATUS","getShaderParameter","COMPILE_STATUS","getShaderInfoLog","getProgramInfoLog","validateProgram","VALIDATE_STATUS","deleteShader","createAsRaw","webGLRenderingState","COMPLETION_STATUS_KHR","oldHandler","getUniformLocation","getAttribLocation","enableEffect","IsWrapper","uniform1i","uniform2i","uniform3i","uniform4i","uniform1iv","uniform2iv","uniform3iv","uniform4iv","uniform1ui","uniform2ui","uniform3ui","uniform4ui","uniform1uiv","uniform2uiv","uniform3uiv","uniform4uiv","uniform1fv","uniform2fv","uniform3fv","uniform4fv","uniformMatrix4fv","uniformMatrix3fv","uniformMatrix2fv","uniform1f","uniform2f","uniform3f","uniform4f","colorMask","setColorWrite","getColorWrite","depthCullingState","alphaState","stencilState","clearInternalTexturesCache","bruteForce","_currentProgram","UNPACK_PREMULTIPLY_ALPHA_WEBGL","_getSamplingParameters","magFilter","minFilter","LINEAR","LINEAR_MIPMAP_NEAREST","LINEAR_MIPMAP_LINEAR","NEAREST_MIPMAP_LINEAR","NEAREST_MIPMAP_NEAREST","mag","_createTexture","_createInternalTexture","delayGPUTextureCreation","useSRGBBuffer","layers","filters","TEXTURE_2D_ARRAY","sizedFormat","_getRGBABufferInternalSizedFormat","internalFormat","_getInternalFormat","_getWebGLTextureType","texImage3D","texImage2D","texParameteri","TEXTURE_MAG_FILTER","TEXTURE_MIN_FILTER","TEXTURE_WRAP_S","CLAMP_TO_EDGE","TEXTURE_WRAP_T","_getUseSRGBBuffer","noMipmap","_createTextureBase","onLoad","prepareTexture","prepareTextureProcessFunction","fallback","forcedExtension","mimeType","loaderOptions","fromData","fromBlob","isBase64","originalUrl","lastDot","lastIndexOf","extension","loader","availableLoader","_TextureLoaders","canLoad","addPendingData","onLoadObserver","onInternalError","removePendingData","loadData","loadMipmap","isCompressed","loadFailed","request","onload","img","decoding","close","_FileToolsLoadImage","imageOrientation","Blob","creationFlags","_prepareWebGLTexture","potWidth","potHeight","continuationCallback","isPot","RGBA","RGB","texelFormat","UNSIGNED_BYTE","drawImage","_rescaleTexture","imageBitmapOptions","onComplete","compression","_unpackFlipY","UNPACK_FLIP_Y_WEBGL","_getUnpackAlignement","UNPACK_ALIGNMENT","_getTextureTarget","TEXTURE_CUBE_MAP","TEXTURE_3D","updateTextureSamplingMode","_setTextureParameterInteger","updateTextureWrappingMode","_getTextureWrapMode","TEXTURE_WRAP_R","_setupDepthStencilTexture","generateStencil","bilinearFiltering","samplingParameters","TEXTURE_COMPARE_FUNC","TEXTURE_COMPARE_MODE","COMPARE_REF_TO_TEXTURE","_uploadCompressedDataToTextureDirectly","lod","compressedTexImage2D","_uploadDataToTextureDirectly","imageData","babylonInternalFormat","useTextureWidthAndHeight","lodMaxWidth","lodMaxHeight","updateTextureData","xOffset","yOffset","targetForBinding","texSubImage2D","_uploadArrayBufferViewToTexture","bindTarget","_prepareWebGLTextureContinuation","GetExponentOfTwo","_setupFramebufferDepthAttachments","generateStencilBuffer","generateDepthBuffer","_createRenderBuffer","DEPTH_STENCIL","depthFormat","DEPTH_COMPONENT16","DEPTH_COMPONENT32F","STENCIL_INDEX8","STENCIL_ATTACHMENT","msInternalFormat","unbindBuffer","renderBuffer","createRenderbuffer","_updateRenderBuffer","bindRenderbuffer","RENDERBUFFER","renderbufferStorage","framebufferRenderbuffer","_deleteTexture","unbindAllTextures","_releaseRenderTargetWrapper","_setProgram","useProgram","_activateCurrentTexture","activeTexture","TEXTURE0","forTextureDataUpdate","wasPreviouslyBound","isTextureForRendering","bindTexture","_bindSamplerUniformToChannel","_setTexture","sourceSlot","_currentState","REPEAT","MIRRORED_REPEAT","isPartOfTextureArray","video","videoInternalTexture","getInternalTexture","delayLoadState","delayLoad","needToBind","coordinatesMode","textureWrapMode","_setAnisotropicLevel","_textureUnits","Int32Array","anisotropicFilterExtension","_setTextureParameterFloat","TEXTURE_MAX_ANISOTROPY_EXT","parameter","texParameterf","releaseEffects","deleteFramebuffer","releaseComputeEffects","attachContextLostEvent","attachContextRestoredEvent","_canRenderToFramebuffer","successful","fb","createFramebuffer","checkFramebufferStatus","FRAMEBUFFER_COMPLETE","readFormat","readType","readPixels","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","UNSIGNED_SHORT_5_6_5","BYTE","SHORT","HALF_FLOAT","UNSIGNED_INT_2_10_10_10_REV","UNSIGNED_INT_10F_11F_11F_REV","UNSIGNED_INT_5_9_9_9_REV","FLOAT_32_UNSIGNED_INT_24_8_REV","ALPHA","LUMINANCE","LUMINANCE_ALPHA","RED","RG","RED_INTEGER","RG_INTEGER","RGB_INTEGER","RGBA_INTEGER","R8_SNORM","RG8_SNORM","RGB8_SNORM","R8I","RG8I","RGB8I","RGBA8I","RGBA8_SNORM","R8","RG8","RGB8","RGBA8","R8UI","RG8UI","RGB8UI","RGBA8UI","R16I","RG16I","RGB16I","RGBA16I","R16UI","RG16UI","RGB16UI","RGBA16UI","R32I","RG32I","RGB32I","RGBA32I","R32UI","RG32UI","RGB32UI","RGBA32UI","R32F","RG32F","RGB32F","R16F","RG16F","RGB16F","RGB565","R11F_G11F_B10F","RGB9_E5","RGBA4","RGB5_A1","RGB10_A2","RGB10_A2UI","_getRGBAMultiSampleBufferFormat","onCompleteObservable","hasAlpha","flushRenderer","numChannels","IsSupportedAsync","IsSupported","_HasMajorPerformanceCaveat","_IsSupported","tempcanvas","WebGLRenderingContext","HasMajorPerformanceCaveat","failIfMajorPerformanceCaveat","CeilingPOT","FloorPOT","pot","NearestPOT","requestAnimationFrame","CollisionsEpsilon","TimingTools","setImmediate","Base64DataUrlRegEx","LoadFileError","file","RequestFileError","ReadFileError","FileToolsOptions","DefaultRetryStrategy","RetryStrategy","maxRetries","baseInterval","retryIndex","ExponentialBackoff","BaseUrl","CorsBehavior","PreprocessUrl","_CleanUrl","SetCorsBehavior","crossOrigin","LoadImage","usingObjectURL","URL","createObjectURL","onErrorHandler","inputText","Image","LoadFile","createImageBitmap","assign","premultiplyAlpha","imgBmp","revokeObjectURL","reason","handlersList","unloadHandlersList","handler","src","blockedURI","cspException","effectiveDirective","originalPolicy","noOfflineSupport","_","contentType","blob","loadFromOfflineSupport","loadImage","enableTexturesOffline","textureName","decodeURIComponent","blobURL","ReadFile","reader","FileReader","fileRequest","onloadend","onerror","readAsArrayBuffer","readAsText","fileOrUrl","onOpened","fileName","TestBase64DataUrl","DecodeBase64UrlToBinary","DecodeBase64UrlToString","SetImmediate","RequestFile","loadUrl","aborted","requestFile","onReadyStateChange","retryHandle","unbindEvents","onLoadEnd","DONE","handleError","retryLoop","IsFileURL","retryStrategy","waitTime","enableSceneOffline","loadFile","event","protocol","IsBase64DataUrl","uri","decodedString","bufferLength","bufferView","charCodeAt","DecodeBase64ToBinary","FileTools","_injectLTSFileTools","InstantiationTools","RegisteredExternalClasses","internalClass","RandomGUID","Tools","strategy","classes","fallbackTexture","u","pixels","Instantiate","fround","_TmpFloatArray","returnUnchangedIfNoSlash","previousAngle","newAngle","smoothFactor","previousAngleRad","ToRadians","newAngleRad","ToDegrees","allowsNullUndefined","eventPrefix","PointerEvent","referrerPolicy","FileToolLoadImage","FileToolsLoadFile","scriptUrl","scriptId","importScripts","head","getElementsByTagName","script","appendChild","LoadScript","fileToLoad","progressCallback","readAsDataURL","FileToolsReadFile","content","fileBlob","decimals","toFixed","DeepCopy","windowElement","events","successCallback","quality","toArrayBuffer","convertToBlob","_IsOffScreenCanvas","toBlob","binStr","toDataURL","getFullYear","getMonth","getDate","Download","newWindow","base64data","base64Image","ToBlob","DownloadBlob","style","display","href","download","parentElement","removeChild","click","camera","forceDownload","antialiasing","renderSprites","enableStencilBuffer","useLayerMask","ClearLogCache","PerformanceLogLevel","PerformanceUserMarkLogLevel","StartPerformanceCounter","_StartUserMark","EndPerformanceCounter","_EndUserMark","PerformanceConsoleLogLevel","_StartPerformanceConsole","_EndPerformanceConsole","_StartPerformanceCounterDisabled","_EndPerformanceCounterDisabled","counterName","_Performance","mark","measure","timeEnd","isType","el","moduleName","classObj","UseCustomRequestHeaders","GetAbsoluteUrl","PerformanceNoneLogLevel","AsyncLoop","iterations","_done","_fn","_successCallback","executeNext","breakLoop","syncedIterations","breakFunction","Run","ceil","iteration","inlineScheduler","coroutine","onStep","step","runCoroutine","abortSignal","resume","reschedule","stepResult","runCoroutineSync","SmartArray","_id","_GlobalId","compareFn","contains","SmartArrayNoDuplicate","_duplicateId","__smartArrayFlags","pushNoDuplicate","concatWithNoDuplicate","Viewport","toGlobal","renderWidth","renderHeight","toGlobalToRef","Plane","norm","magnitude","invertedMatrix","_TmpMatrix","normalX","normalY","normalZ","finalD","dotCoordinate","copyFromPoints","point1","point2","point3","x1","y1","z1","pyth","invPyth","isFrontFacingTo","signedDistanceTo","Frustum","frustumPlanes","GetPlanesToRef","frustumPlane","GetNearPlaneToRef","GetFarPlaneToRef","GetLeftPlaneToRef","GetRightPlaneToRef","GetTopPlaneToRef","GetBottomPlaneToRef","Camera","_position","newPosition","upVector","_upVector","screenArea","PERSPECTIVE_CAMERA","fovMode","FOVMODE_VERTICAL_FIXED","minZ","getAspectRatio","halfWidth","halfHeight","orthoRight","orthoLeft","orthoTop","orthoBottom","_orthoLeft","rigCamera","_rigCameras","_orthoRight","_orthoBottom","_orthoTop","_mode","setActiveOnSceneIfNoneActive","maxZ","inertia","isIntermediate","layerMask","cameraRigMode","RIG_MODE_NONE","customRenderTargets","outputRenderTarget","onViewMatrixChangedObservable","onProjectionMatrixChangedObservable","onAfterCheckInputsObservable","onRestoreStateObservable","isRigCamera","_webvrViewMatrix","_skipRendering","_projectionMatrix","_postProcesses","_activeMeshes","_globalPosition","_computedViewMatrix","_doNotComputeProjectionMatrix","_transformMatrix","_refreshFrustumPlanes","_absoluteRotation","_isCamera","_isLeftCamera","_isRightCamera","addCamera","activeCamera","renderPassId","createRenderPassId","storeState","_stateStored","_storedFov","_restoreStateValues","restoreState","fullDetails","applyVerticalCorrection","absoluteRotation","useRightHandedSystem","globalPosition","getActiveMeshes","isActiveMesh","mesh","completeCheck","pp","aspectRatio","ignoreParentClass","_isSynchronizedViewMatrix","_isSynchronizedProjectionMatrix","check","attachControl","_ignored","_noPreventDefault","detachControl","_checkInputs","_updateRigCameras","getViewMatrix","getProjectionMatrix","rigCameras","rigPostProcess","_rigPostProcess","_getFirstPostProcess","ppIndex","_cascadePostProcessesToRigCams","firstPostProcess","markTextureDirty","cam","getEffectName","attachPostProcess","insertAt","isReusable","prePassRenderer","detachPostProcess","_getViewMatrix","_cameraRigParams","vrPreViewMatrix","freezeProjectionMatrix","unfreezeProjectionMatrix","reverseDepth","getTransformationMatrix","_updateFrustumPlanes","_frustumPlanes","GetPlanes","isInFrustum","checkRigCameras","isCompletelyInFrustum","getForwardRay","getForwardRayToRef","refRay","inputs","stopAnimation","removeCamera","cameras","releaseRenderPassId","isLeftCamera","isRightCamera","leftCamera","rightCamera","getLeftTarget","getTarget","getRightTarget","setCameraRigMode","rigParams","interaxialDistance","stereoHalfAngle","createRigCamera","_setRigMode","_getVRProjectionMatrix","vrMetrics","aspectRatioFov","vrWorkMatrix","vrHMatrix","_updateCameraRotationMatrix","_updateWebVRCameraRotationMatrix","_getWebVRProjectionMatrix","_getWebVRViewMatrix","setCameraRigParameter","cameraIndex","RIG_MODE_STEREOSCOPIC_ANAGLYPH","_setupInputs","Serialize","AppendSerializedAnimations","GetConstructorFromName","isStereoscopicSideBySide","getDirection","localAxis","getDirectionToRef","interaxial_distance","Construct","_CreateDefaultParsedCamera","parsedCamera","construct","Parse","parentInstanceIndex","parse","setPosition","setTarget","parsedAnimation","ParseAnimationRanges","autoAnimate","autoAnimateFrom","autoAnimateTo","autoAnimateLoop","autoAnimateSpeed","ORTHOGRAPHIC_CAMERA","FOVMODE_HORIZONTAL_FIXED","RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL","RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED","RIG_MODE_STEREOSCOPIC_OVERUNDER","RIG_MODE_STEREOSCOPIC_INTERLACED","RIG_MODE_VR","RIG_MODE_WEBVR","RIG_MODE_CUSTOM","ForceAttachControlToAlwaysPreventDefault","StringDictionary","_count","_data","getOrAddWithFactory","factory","getOrAdd","curVal","getAndRemove","cur","first","AbstractScene","lights","meshes","skeletons","particleSystems","animationGroups","multiMaterials","morphTargetManagers","geometries","transformNodes","actionManagers","_environmentTexture","postProcesses","parser","_BabylonFileParsers","_IndividualBabylonFileParsers","jsonData","container","parserName","environmentTexture","getNodes","skeleton","bones","MaterialDefines","externalProperties","_keys","_areLightsDirty","_areLightsDisposed","_areAttributesDirty","_areTexturesDirty","_areFresnelDirty","_areMiscDirty","_arePrePassDirty","_areImageProcessingDirty","_normals","_uvs","_needNormals","_needUVs","_externalProperties","_setDefaultValue","markAsProcessed","markAsUnprocessed","markAllAsDirty","markAsImageProcessingDirty","markAsLightDirty","disposed","markAsAttributesDirty","markAsTexturesDirty","markAsFresnelDirty","markAsMiscDirty","markAsPrePassDirty","rebuild","cloneTo","defValue","default","ColorCurves","_dirty","_tempColor","_globalCurve","_highlightsCurve","_midtonesCurve","_shadowsCurve","_positiveCurve","_negativeCurve","_globalHue","_globalDensity","_globalSaturation","_globalExposure","_highlightsHue","_highlightsDensity","_highlightsSaturation","_highlightsExposure","_midtonesHue","_midtonesDensity","_midtonesSaturation","_midtonesExposure","_shadowsHue","_shadowsDensity","_shadowsSaturation","_shadowsExposure","globalHue","globalDensity","globalSaturation","globalExposure","highlightsHue","highlightsDensity","highlightsSaturation","highlightsExposure","midtonesHue","midtonesDensity","midtonesSaturation","midtonesExposure","shadowsHue","shadowsDensity","shadowsSaturation","shadowsExposure","colorCurves","positiveUniform","neutralUniform","negativeUniform","_getColorGradingDataToRef","uniformsList","density","exposure","_Clamp","_ApplyColorGradingSliderNonlinear","_FromHSBToRef","brightness","ImageProcessingConfigurationDefines","IMAGEPROCESSING","VIGNETTE","VIGNETTEBLENDMODEMULTIPLY","VIGNETTEBLENDMODEOPAQUE","TONEMAPPING","TONEMAPPING_ACES","CONTRAST","COLORCURVES","COLORGRADING","COLORGRADING3D","SAMPLER3DGREENDEPTH","SAMPLER3DBGRMAP","DITHER","IMAGEPROCESSINGPOSTPROCESS","EXPOSURE","SKIPFINALCOLORCLAMP","ImageProcessingConfiguration","_colorCurvesEnabled","_colorGradingEnabled","_colorGradingWithGreenDepth","_colorGradingBGR","_exposure","_toneMappingEnabled","_toneMappingType","TONEMAPPING_STANDARD","_contrast","vignetteStretch","vignetteCenterX","vignetteCenterY","vignetteWeight","vignetteColor","vignetteCameraFov","_vignetteBlendMode","VIGNETTEMODE_MULTIPLY","_vignetteEnabled","_ditheringEnabled","_ditheringIntensity","_skipFinalColorClamp","_applyByPostProcess","onUpdateParameters","colorCurvesEnabled","_updateParameters","colorGradingTexture","_colorGradingTexture","colorGradingEnabled","colorGradingWithGreenDepth","colorGradingBGR","toneMappingEnabled","toneMappingType","contrast","vignetteCentreY","vignetteCentreX","vignetteBlendMode","vignetteEnabled","ditheringEnabled","ditheringIntensity","skipFinalColorClamp","applyByPostProcess","PrepareUniforms","samplersList","prepareDefines","forPostProcess","_VIGNETTEMODE_MULTIPLY","overrideAspectRatio","Bind","inverseWidth","inverseHeight","vignetteScaleY","vignetteScaleX","vignetteScaleGeometricMean","Mix","vignettePower","textureSize","parsed","VIGNETTEMODE_OPAQUE","_VIGNETTEMODE_OPAQUE","DeviceType","PointerInput","NativePointerInput","DualShockInput","DualSenseInput","XboxInput","SwitchInput","DeviceInputEventType","createUniformBuffer","elements","ubo","UNIFORM_BUFFER","createDynamicUniformBuffer","updateUniformBuffer","subarray","bindBufferBase","UniformBuffer","dynamic","forceNoUniformBuffer","_noUBO","_dynamic","_uniformLocations","_uniformSizes","_uniformArraySizes","_uniformLocationPointer","_needSync","_buffers","_bufferIndex","_createBufferOnWrite","_currentFrameId","updateMatrix3x3","_updateMatrix3x3ForEffect","updateMatrix2x2","_updateMatrix2x2ForEffect","updateFloat","_updateFloatForEffect","updateFloat2","_updateFloat2ForEffect","updateFloat3","_updateFloat3ForEffect","updateFloat4","_updateFloat4ForEffect","updateFloatArray","_updateFloatArrayForEffect","updateArray","_updateArrayForEffect","updateIntArray","_updateIntArrayForEffect","updateUIntArray","_updateUIntArrayForEffect","updateMatrix","_updateMatrixForEffect","updateMatrices","_updateMatricesForEffect","updateVector3","_updateVector3ForEffect","updateVector4","_updateVector4ForEffect","updateColor3","_updateColor3ForEffect","updateColor4","_updateColor4ForEffect","updateDirectColor4","_updateDirectColor4ForEffect","updateInt","_updateIntForEffect","updateInt2","_updateInt2ForEffect","updateInt3","_updateInt3ForEffect","updateInt4","_updateInt4ForEffect","updateUInt","_updateUIntForEffect","updateUInt2","_updateUInt2ForEffect","updateUInt3","_updateUInt3ForEffect","updateUInt4","_updateUInt4ForEffect","_updateMatrix3x3ForUniform","_updateMatrix2x2ForUniform","_updateFloatForUniform","_updateFloat2ForUniform","_updateFloat3ForUniform","_updateFloat4ForUniform","_updateFloatArrayForUniform","_updateArrayForUniform","_updateIntArrayForUniform","_updateUIntArrayForUniform","_updateMatrixForUniform","_updateMatricesForUniform","_updateVector3ForUniform","_updateVector4ForUniform","_updateColor3ForUniform","_updateColor4ForUniform","_updateDirectColor4ForUniform","_updateIntForUniform","_updateInt2ForUniform","_updateInt3ForUniform","_updateInt4ForUniform","_updateUIntForUniform","_updateUInt2ForUniform","_updateUInt3ForUniform","_updateUInt4ForUniform","useUbo","isSync","isDynamic","getData","_bufferData","_fillAlignment","alignment","oldPointer","addUniform","arraySize","strideSize","addMatrix","mat","addFloat2","addFloat3","addColor3","addColor4","addMatrix3x3","addMatrix2x2","_numBuffers","_indexBuffer","currentEffect","_buffersEqual","buf1","buf2","_copyBuffer","dst","_UpdatedUbosInFrame","_createNewBuffer","_checkNewFrame","updateUniform","FloatRound","updateUniformArray","arraySizes","countToFour","baseStride","_TempBuffer","suffix","_TempBufferInt32View","_TempBufferUInt32View","updateUniformDirectly","bindToEffect","_currentEffectName","unbindEffect","setDataBuffer","uniformBuffers","_MAX_UNIFORM_SIZE","Buffer","postponeInternalCreation","instanced","useBytes","_isAlreadyOwned","_updatable","_instanced","_divisor","VertexBuffer","isUpdatable","getStrideSize","updateDynamicVertexBuffer","updateDirectly","vertexCount","_increaseReferences","instanceDivisor","_instanceDivisor","isInstanced","_computeHashCode","takeBufferOwnership","_ownsBuffer","_kind","vertexData","Int8Array","Int16Array","typeByteLength","GetTypeByteLength","DeduceStride","hashCode","getKind","getFloatData","totalVertices","forceCopy","tightlyPackedByteStride","remainder","getOffset","sizeInBytes","ForEach","UVKind","UV2Kind","UV3Kind","UV4Kind","UV5Kind","UV6Kind","NormalKind","PositionKind","ColorKind","MatricesIndicesKind","MatricesIndicesExtraKind","MatricesWeightsKind","MatricesWeightsExtraKind","TangentKind","componentCount","componentType","componentIndex","dataView","DataView","componentByteLength","componentByteOffset","_GetFloatValue","getInt8","getUint8","getInt16","getUint16","getInt32","getUint32","getFloat32","ColorInstanceKind","PickingInfo","hit","pickedPoint","pickedMesh","bu","bv","faceId","subMeshFaceId","subMeshId","pickedSprite","thinInstanceIndex","ray","originMesh","aimTransform","gripTransform","getNormal","useWorldCoordinates","useVerticesNormals","isVerticesDataPresent","getIndices","tmp0","tmp1","normals","getVerticesData","normal0","normal1","normal2","positions","vertex1","vertex2","vertex3","p1p2","p3p2","transformNormalToWorld","wm","nonUniformScaling","normalForDirectionChecking","getTextureCoordinates","uvSet","uvs","uv0","uv1","uv2","ActionEvent","pointerX","pointerY","meshUnderPointer","sourceEvent","additionalData","prim","pointerPos","PostProcessManager","_vertexBuffers","_prepareBuffers","vertices","_buildIndexBuffer","vb","_prepareFrame","sourceTexture","postProcessesEnabled","directRender","targetTexture","doNotBindFrambuffer","_debugInsertMarker","onBeforeRenderObservable","onAfterRenderObservable","setDepthWrite","_finalizeFrame","doNotPresent","_outputTexture","setAlphaMode","RenderingGroup","opaqueSortCompareFn","_opaqueSortCompareFn","PainterSortCompare","_renderOpaque","_renderOpaqueSorted","alphaTestSortCompareFn","_alphaTestSortCompareFn","_renderAlphaTest","_renderAlphaTestSorted","transparentSortCompareFn","_transparentSortCompareFn","defaultTransparentSortCompare","_renderTransparent","_renderTransparentSorted","_opaqueSubMeshes","_transparentSubMeshes","_alphaTestSubMeshes","_depthOnlySubMeshes","_particleSystems","_spriteManagers","_empty","_edgesRenderers","render","customRenderFunction","renderParticles","activeMeshes","getStencilBuffer","setStencilBuffer","_renderSprites","_renderParticles","onBeforeTransparentRendering","useOrderIndependentTransparency","excludedMeshes","depthPeelingRenderer","edgesRendererIndex","_RenderSorted","sortCompareFn","transparent","subMesh","subIndex","cameraPosition","_ZeroVector","_alphaIndex","getMesh","alphaIndex","_distanceToCamera","boundingSphere","centerWorld","sortedArray","_activeMeshesFrozenButKeepClipping","material","getMaterial","needDepthPrePass","backToFrontSortCompare","meshA","meshB","prepare","prepareSprites","needAlphaBlendingForMesh","needAlphaTesting","_renderingGroup","_edgesRenderer","dispatchSprites","spriteManager","dispatchParticles","particleSystem","onBeforeParticlesRenderingObservable","particleIndex","emitter","_activeParticles","addCount","onAfterParticlesRenderingObservable","spritesEnabled","onBeforeSpritesRenderingObservable","onAfterSpritesRenderingObservable","RenderingGroupInfo","RenderingManager","maintainStateBetweenFrames","_maintainStateBetweenFrames","_wasDispatched","spriteManagers","_useSceneAutoClearSetup","_renderingGroups","_autoClearDepthStencil","_customOpaqueSortCompareFn","_customAlphaTestSortCompareFn","_customTransparentSortCompareFn","_renderingGroupInfo","MIN_RENDERINGGROUPS","MAX_RENDERINGGROUPS","autoClear","getRenderingGroup","renderingGroupId","_prepareRenderingGroup","_clearDepthStencilBuffer","_depthStencilBufferAlreadyCleaned","info","renderingGroup","renderingGroupMask","onBeforeRenderingGroupObservable","AUTOCLEAR","getAutoClearDepthStencilSetup","_beforeRenderingGroupDrawStage","_afterRenderingGroupDrawStage","onAfterRenderingGroupObservable","resetSprites","freeRenderingGroups","setRenderingOrder","group","setRenderingAutoClearDepthStencil","autoClearDepthStencil","SceneComponentConstants","NAME_EFFECTLAYER","NAME_LAYER","NAME_LENSFLARESYSTEM","NAME_BOUNDINGBOXRENDERER","NAME_PARTICLESYSTEM","NAME_GAMEPAD","NAME_SIMPLIFICATIONQUEUE","NAME_GEOMETRYBUFFERRENDERER","NAME_PREPASSRENDERER","NAME_DEPTHRENDERER","NAME_DEPTHPEELINGRENDERER","NAME_POSTPROCESSRENDERPIPELINEMANAGER","NAME_SPRITE","NAME_SUBSURFACE","NAME_OUTLINERENDERER","NAME_PROCEDURALTEXTURE","NAME_SHADOWGENERATOR","NAME_OCTREE","NAME_PHYSICSENGINE","NAME_AUDIO","NAME_FLUIDRENDERER","STEP_ISREADYFORMESH_EFFECTLAYER","STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER","STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER","STEP_PREACTIVEMESH_BOUNDINGBOXRENDERER","STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER","STEP_BEFORECAMERADRAW_PREPASS","STEP_BEFORECAMERADRAW_EFFECTLAYER","STEP_BEFORECAMERADRAW_LAYER","STEP_BEFORERENDERTARGETDRAW_PREPASS","STEP_BEFORERENDERTARGETDRAW_LAYER","STEP_BEFORERENDERINGMESH_PREPASS","STEP_BEFORERENDERINGMESH_OUTLINE","STEP_AFTERRENDERINGMESH_PREPASS","STEP_AFTERRENDERINGMESH_OUTLINE","STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW","STEP_AFTERRENDERINGGROUPDRAW_BOUNDINGBOXRENDERER","STEP_BEFORECAMERAUPDATE_SIMPLIFICATIONQUEUE","STEP_BEFORECAMERAUPDATE_GAMEPAD","STEP_BEFORECLEAR_PROCEDURALTEXTURE","STEP_BEFORECLEAR_PREPASS","STEP_BEFORERENDERTARGETCLEAR_PREPASS","STEP_AFTERRENDERTARGETDRAW_PREPASS","STEP_AFTERRENDERTARGETDRAW_LAYER","STEP_AFTERCAMERADRAW_PREPASS","STEP_AFTERCAMERADRAW_EFFECTLAYER","STEP_AFTERCAMERADRAW_LENSFLARESYSTEM","STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW","STEP_AFTERCAMERADRAW_LAYER","STEP_AFTERCAMERADRAW_FLUIDRENDERER","STEP_AFTERCAMERAPOSTPROCESS_LAYER","STEP_AFTERRENDERTARGETPOSTPROCESS_LAYER","STEP_AFTERRENDER_AUDIO","STEP_GATHERRENDERTARGETS_DEPTHRENDERER","STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER","STEP_GATHERRENDERTARGETS_SHADOWGENERATOR","STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER","STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER","STEP_GATHERACTIVECAMERARENDERTARGETS_FLUIDRENDERER","STEP_POINTERMOVE_SPRITE","STEP_POINTERDOWN_SPRITE","STEP_POINTERUP_SPRITE","Stage","registerStep","component","PointerEventTypes","POINTERDOWN","POINTERUP","POINTERMOVE","POINTERWHEEL","POINTERPICK","POINTERTAP","POINTERDOUBLETAP","PointerInfoBase","PointerInfoPre","localX","localY","originalPickingInfo","skipOnPointerObservable","localPosition","PointerInfo","pickInfo","_pickInfo","_generatePickInfo","inputManager","_inputManager","_pickMove","_setRayOnPointerInfo","AbstractActionManager","hoverCursor","isRecursive","HasTriggers","Triggers","HasPickTriggers","tAsInt","KeyboardEventTypes","KEYDOWN","KEYUP","KeyboardInfo","KeyboardInfoPre","skipOnKeyboardObservable","EventConstants","DOM_DELTA_PIXEL","DOM_DELTA_LINE","DOM_DELTA_PAGE","DeviceEventFactory","deviceType","deviceSlot","inputIndex","deviceInputSystem","elementToAttachTo","pointerId","Keyboard","_CreateKeyboardEvent","Mouse","MouseWheelX","MouseWheelY","MouseWheelZ","_CreateWheelEvent","Touch","_CreatePointerEvent","_CreateMouseEvent","pointerType","buttons","pollInput","LeftClick","RightClick","MiddleClick","Move","button","deltaMode","deltaX","deltaY","deltaZ","_CreateEvent","Horizontal","Vertical","movementX","movementY","DeltaHorizontal","DeltaVertical","_CheckNonCharacterKeys","clientX","clientY","fromCharCode","keyCode","isKeyboardActive","isDeviceAvailable","altKey","ctrlKey","metaKey","shiftKey","NativeDeviceInputSystem","onDeviceConnected","onDeviceDisconnected","onInputChanged","_nativeInput","DeviceInputSystem","CreateDeviceEvent","_createDummyNativeInput","MAX_POINTER_INPUTS","WebDeviceInputSystem","_inputs","_keyboardActive","_pointerActive","_usingSafari","IsSafari","_usingMacOS","platform","_keyboardDownEvent","_keyboardUpEvent","_keyboardBlurEvent","_pointerMoveEvent","_pointerDownEvent","_pointerUpEvent","_pointerCancelEvent","_pointerWheelEvent","_pointerBlurEvent","_eventsAttached","_mouseId","_isUsingFirefox","_maxTouchPoints","_pointerInputClearObserver","_gamepadConnectedEvent","_gamepadDisconnectedEvent","_eventPrefix","GetPointerPrefix","_onDeviceConnected","_onDeviceDisconnected","_onInputChanged","_enableEvents","_metaKeys","_onEngineViewChanged","device","DualShock","DualSense","_updateDevice","_elementToAttachTo","_disableEvents","inputElement","getInputElement","deviceSlotKey","tabIndex","canvasTabIndex","_handleKeyActions","_handlePointerActions","_handleGamepadActions","_checkForConnectedDevices","_wheelEventName","onEndFrameObservable","getGamepads","gamepads","gamepad","_addGamePad","matchMedia","_addPointerDevice","_getGamepadDeviceType","_gamepads","_registerDevice","axes","currentX","currentY","numberOfInputs","fill","_unregisterDevice","kbKey","deviceEvent","maxTouchPoints","_activeTouchIds","_getPointerType","previousHorizontal","previousVertical","pointerLockElement","setPointerCapture","hasPointerCapture","releasePointerCapture","BrowserForward","onmousewheel","passiveSupported","noop","wheelDelta","passive","gp","valueOf","deviceName","Xbox","Switch","Generic","touches","DeviceSource","onInputChangedObservable","_deviceInputSystem","getInput","InternalDeviceSourceManager","_registeredManagers","registerManager","_devices","_addDevice","unregisterManager","numberOfDeviceTypes","deviceSource","_removeDevice","DeviceSourceManager","getDeviceSource","_firstDevice","getDeviceSources","_deviceSourceManager","onDeviceConnectedObservable","devices","onDeviceDisconnectedObservable","_updateFirstDevices","_ClickInfo","_singleClick","_doubleClick","_hasSwiped","_ignore","singleClick","doubleClick","hasSwiped","InputManager","_alreadyAttached","_meshPickProceed","_currentPickResult","_previousPickResult","_totalPointersPressed","_doubleClickOccured","_isSwiping","_swipeButtonPressed","_skipPointerTap","_isMultiTouchGesture","_pointerX","_pointerY","_startingPointerPosition","_previousStartingPointerPosition","_startingPointerTime","_previousStartingPointerTime","_pointerCaptures","_meshUnderPointerId","_movePointerInfo","_cameraObserverCount","_delayedClicks","_pointerOverMesh","getMeshUnderPointerByPointerId","unTranslatedPointer","_unTranslatedPointerX","_unTranslatedPointerY","_updatePointerPosition","canvasRect","getInputElementClientRect","_processPointerMove","pickResult","doNotHandleCursors","defaultCursor","_setCursorAndPointerOverMesh","_pointerMoveStage","isMeshPicked","pointerInfo","onPointerMove","onPointerObservable","_pickingAvailable","createPickingRay","_addCameraPointerObserver","_removeCameraPointerObserver","_checkForPicking","onPointerPick","_checkPrePointerObservable","pi","nearInteractionPickingInfo","onPrePointerObservable","pick","pointerMovePredicate","pointerMoveFastCheck","cameraToUseForPointers","pointerMoveTrianglePredicate","setPointerOverMesh","actionManager","hasPointerTriggers","simulatePointerMove","pointerEventInit","simulatePointerDown","_processPointerDown","_pickedDownMesh","hasPickTriggers","processTrigger","CreateNew","hasSpecificTrigger","isVisible","LongPressDelay","_isPointerSwiping","_pointerDownStage","onPointerDown","simulatePointerUp","doubleTap","clickInfo","_processPointerUp","_pickedUpMesh","doubleClickActionManager","_pointerUpStage","pickedDownActionManager","onPointerUp","isPointerCaptured","attachUp","attachDown","attachMove","_alreadyAttachedTo","_initActionManager","act","skipPointerUpPicking","_registeredActions","pointerUpPredicate","pointerUpFastCheck","_delayedSimpleClick","btn","cb","DoubleClickDelay","_previousButtonPressed","_initClickEvent","obs1","obs2","checkPicking","needToIgnoreNext","checkSingleClickImmediately","ExclusiveDoubleClickMode","HasSpecificTrigger","delayedClick","timeoutId","checkDoubleClick","_onPointerMove","DragMovementThreshold","isPointerLock","_verifyPointerLock","skipPointerMovePicking","enablePointerMoveEvents","constantlyUpdateMeshUnderPointer","_onPointerDown","prevEvt","preventDefaultOnPointerDown","focus","pointerDownPredicate","skipPointerDownPicking","pointerDownFastCheck","_onPointerUp","preventDefaultOnPointerUp","_onKeyDown","onPreKeyboardObservable","onKeyboardObservable","CreateNewFromScene","_onKeyUp","BrowserBack","_internalAbstractMeshDataInfo","_pointerOverDisableMeshTesting","underPointerMesh","getPointerOverMesh","_invalidateMesh","PerfCounter","_min","_max","average","_average","lastSecAverage","_lastSecAverage","_current","_totalAccumulated","_totalValueCount","_startMonitoringTime","_lastSecAccumulated","_lastSecTime","_lastSecValueCount","fetchNewFrame","newCount","fetchResult","Enabled","_fetchResult","beginMonitoring","endMonitoring","newFrame","currentTime","UniqueIdGenerator","UniqueId","_UniqueIdCounter","LightConstants","shadowEnabled","renderPriority","FALLOFF_DEFAULT","FALLOFF_PHYSICAL","FALLOFF_GLTF","FALLOFF_STANDARD","LIGHTMAP_DEFAULT","LIGHTMAP_SPECULAR","LIGHTMAP_SHADOWSONLY","INTENSITYMODE_AUTOMATIC","INTENSITYMODE_LUMINOUSPOWER","INTENSITYMODE_LUMINOUSINTENSITY","INTENSITYMODE_ILLUMINANCE","INTENSITYMODE_LUMINANCE","LIGHTTYPEID_POINTLIGHT","LIGHTTYPEID_DIRECTIONALLIGHT","LIGHTTYPEID_SPOTLIGHT","LIGHTTYPEID_HEMISPHERICLIGHT","PointerPickingConfiguration","ScenePerformancePriority","Scene","imageProcessingConfiguration","_imageProcessingConfiguration","performancePriority","_performancePriority","BackwardCompatible","skipFrustumClipping","_renderingManager","Intermediate","Aggressive","onScenePerformancePriorityChangedObservable","forceWireframe","_forceWireframe","_skipFrustumClipping","forcePointsCloud","_forcePointsCloud","beforeRender","_onBeforeRenderObserver","afterRender","_onAfterRenderObserver","beforeCameraRender","_onBeforeCameraRenderObserver","onBeforeCameraRenderObservable","afterCameraRender","_onAfterCameraRenderObserver","onAfterCameraRenderObservable","_pointerPickingConfiguration","bindEyePosition","variableName","isVector3","eyePosition","_forcedViewPosition","_mirroredCameraPosition","devicePosition","invertNormal","finalizeSceneUbo","getSceneUniformBuffer","_useRightHandedSystem","setStepId","newStepId","_currentStepId","getStepId","getInternalStep","_currentInternalStep","fogEnabled","_fogEnabled","fogMode","_fogMode","prePass","defaultRT","shadowsEnabled","_shadowsEnabled","lightsEnabled","_lightsEnabled","activeCameras","_activeCameras","_unObserveActiveCameras","onActiveCamerasChanged","_activeCamera","onActiveCameraChanged","defaultMaterial","_defaultMaterial","DefaultMaterialFactory","texturesEnabled","_texturesEnabled","skeletonsEnabled","_skeletonsEnabled","collisionCoordinator","_collisionCoordinator","CollisionCoordinatorFactory","renderingManager","_registerTransientComponents","_transientComponents","_addComponent","_components","serializableComponent","addFromContainer","_serializableComponents","_getComponent","_isScene","_blockEntityCollection","autoClearDepthAndStencil","animationsEnabled","useConstantAnimationDeltaTime","disableOfflineSupportExceptionRules","onAfterRenderCameraObservable","onBeforeAnimationsObservable","onAfterAnimationsObservable","onBeforeDrawPhaseObservable","onAfterDrawPhaseObservable","onReadyObservable","onBeforeActiveMeshesEvaluationObservable","onAfterActiveMeshesEvaluationObservable","onNewCameraAddedObservable","onCameraRemovedObservable","onNewLightAddedObservable","onLightRemovedObservable","onNewGeometryAddedObservable","onGeometryRemovedObservable","onNewTransformNodeAddedObservable","onTransformNodeRemovedObservable","onNewMeshAddedObservable","onMeshRemovedObservable","onNewSkeletonAddedObservable","onSkeletonRemovedObservable","onNewMaterialAddedObservable","onNewMultiMaterialAddedObservable","onMaterialRemovedObservable","onMultiMaterialRemovedObservable","onNewTextureAddedObservable","onTextureRemovedObservable","onBeforeRenderTargetsRenderObservable","onAfterRenderTargetsRenderObservable","onBeforeStepObservable","onAfterStepObservable","onMeshImportedObservable","onAnimationFileImportedObservable","_registeredForLateAnimationBindings","_timeAccumulator","FOGMODE_NONE","fogColor","fogDensity","fogStart","fogEnd","needsPreviousWorldMatrices","physicsEnabled","particlesEnabled","lensFlaresEnabled","collisionsEnabled","gravity","renderTargetsEnabled","dumpNextRenderTargets","importedMeshesFiles","probesEnabled","_meshesForIntersections","proceduralTexturesEnabled","_totalVertices","_activeIndices","_activeBones","_animationTime","animationTimeScale","_renderId","_executeWhenReadyTimeoutId","_intermediateRendering","_defaultFrameBufferCleared","_viewUpdateFlag","_projectionUpdateFlag","_toBeDisposed","_pendingData","dispatchAllSubMeshesOfActiveMeshes","_processedMaterials","_renderTargets","_materialsRenderTargets","_activeParticleSystems","_activeSkeletons","_softwareSkinnedMeshes","_activeAnimatables","requireLightSorting","_beforeCameraUpdateStage","Create","_beforeClearStage","_beforeRenderTargetClearStage","_gatherRenderTargetsStage","_gatherActiveCameraRenderTargetsStage","_isReadyForMeshStage","_beforeEvaluateActiveMeshStage","_evaluateSubMeshStage","_preActiveMeshStage","_cameraDrawRenderTargetStage","_beforeCameraDrawStage","_beforeRenderTargetDrawStage","_beforeRenderingMeshStage","_afterRenderingMeshStage","_afterCameraDrawStage","_afterCameraPostProcessStage","_afterRenderTargetDrawStage","_afterRenderTargetPostProcessStage","_afterRenderStage","_geometriesByUniqueId","_defaultMeshCandidates","_defaultSubMeshCandidates","_preventFreeActiveMeshesAndRenderingGroups","_activeMeshesFrozen","_skipEvaluateActiveMeshesCompletely","_allowPostProcessClearColor","getDeterministicFrameTime","getTimeStep","_blockMaterialDirtyMechanism","_perfCollector","fullOptions","useGeometryUniqueIdsMap","useMaterialMeshMap","useClonedMeshMap","virtual","_virtualScenes","_uid","postProcessManager","_createUbo","setDefaultCandidateProviders","onNewSceneAddedObservable","_getDefaultMeshCandidates","_getDefaultSubMeshCandidates","getActiveMeshCandidates","getActiveSubMeshCandidates","getIntersectingSubMeshCandidates","getCollidingSubMeshCandidates","getCachedMaterial","_cachedMaterial","getCachedEffect","_cachedEffect","getCachedVisibility","_cachedVisibility","isCachedMaterialInvalid","visibility","totalVerticesPerfCounter","getActiveIndices","totalActiveIndicesPerfCounter","getActiveParticles","activeParticlesPerfCounter","getActiveBones","activeBonesPerfCounter","getAnimationRatio","_animationRatio","getFrameId","setSceneUniformBuffer","createSceneUniformBuffer","checkRenderTargets","currentRenderPassId","hardwareInstancedRendering","hasThinInstances","instances","_storeEffectOnSubMeshes","hasRenderTargetTextures","getRenderTargetTextures","isReadyForRendering","resetCachedMaterial","registerBeforeRender","unregisterBeforeRender","registerAfterRender","unregisterAfterRender","_executeOnceBeforeRender","execFunc","executeOnceBeforeRender","wasLoading","getWaitingItemsCount","executeWhenReady","whenReadyAsync","animatables","resetLastAnimationTimeFrame","_animationTimeLast","_viewMatrix","getTransformMatrix","setTransformMatrix","viewL","projectionL","viewR","projectionR","_multiviewSceneUbo","_updateMultiviewUbo","_sceneUbo","sceneUbo","addMesh","newMesh","recursive","_resyncLightSources","removeMesh","toRemove","addTransformNode","newTransformNode","_indexInSceneTransformNodesArray","removeTransformNode","lastNode","removeSkeleton","_executeActiveContainerCleanup","removeMorphTargetManager","removeLight","_removeLightSource","sortLightsByPriority","index2","removeParticleSystem","removeAnimation","animationName","targetMask","removeAnimationGroup","removeMultiMaterial","removeMaterial","_indexInSceneMaterialArray","lastMaterial","removeActionManager","removeTexture","addLight","newLight","lightSources","CompareLightsPriority","newCamera","addSkeleton","newSkeleton","addParticleSystem","newParticleSystem","addAnimation","newAnimation","addAnimationGroup","newAnimationGroup","addMultiMaterial","newMultiMaterial","addMaterial","newMaterial","addMorphTargetManager","newMorphTargetManager","addGeometry","newGeometry","addActionManager","newActionManager","addTexture","newTexture","switchActiveCamera","setActiveCameraById","setActiveCameraByName","getCameraByName","getAnimationGroupByName","_getMaterial","allowMultiMaterials","getMaterialByUniqueID","getMaterialByName","getLastMaterialById","getTextureByUniqueId","getCameraByUniqueId","getBoneById","skeletonIndex","boneIndex","getBoneByName","getLightByName","getLightById","getLightByUniqueId","getParticleSystemById","getGeometryById","_getGeometryByUniqueId","pushGeometry","geometry","lastGeometry","getGeometries","getMeshById","getMeshesById","getTransformNodeById","getTransformNodeByUniqueId","getTransformNodesById","getMeshByUniqueId","getLastTransformNodeById","getLastEntryById","getNodeById","transformNode","light","bone","getNodeByName","getMeshByName","getTransformNodeByName","getLastSkeletonById","getSkeletonByUniqueId","getSkeletonById","getSkeletonByName","getMorphTargetManagerById","getMorphTargetById","managerIndex","morphTargetManager","numTargets","getMorphTargetByName","getPostProcessByName","postProcessIndex","uid","RandomId","addExternalData","_externalData","getExternalData","getOrAddExternalDataWithFactory","removeExternalData","_evaluateSubMesh","initialMesh","forcePush","freeProcessedMaterials","blockfreeActiveMeshesAndRenderingGroups","freeActiveMeshes","renderList","_isInIntermediateRendering","freezeActiveMeshes","skipEvaluateActiveMeshes","freezeMeshes","keepFrustumCulling","updateTransformMatrix","_evaluateActiveMeshes","_freeze","unfreezeActiveMeshes","_isActive","_unFreeze","psLength","animate","_currentLODIsUpToDate","isBlocked","hasSpecificTriggers2","meshToRender","customLODSelector","getLOD","_currentLOD","billboardMode","_preActivate","alwaysSelectAsActiveMesh","_activate","isAnInstance","_actAsRegularMesh","_onlyForInstances","_activeMesh","_postActivate","isStarted","sourceMesh","computeBonesUsingShaders","hasInstances","_renderingMultiview","_bindFrameBuffer","_multiviewTexture","_clearFrameBuffer","rtt","onClearObservable","skipInitialClear","_cleared","_clear","_renderForCamera","rigParent","bindFrameBuffer","softwareSkinnedMeshIndex","applySkeleton","needRebind","renderIndex","renderTarget","_shouldRender","hasSpecialRenderTargetCamera","_processSubCameras","_createMultiviewUbo","_useMultiviewToSingleView","_renderMultiviewToSingleView","_checkIntersections","actionIndex","parameters","getTriggerParameter","otherMesh","areIntersecting","intersectsMesh","usePreciseIntersection","currentIntersectionInProgress","_intersectionsInProgress","_executeCurrent","parameterMesh","_advancePhysicsEngineStep","_animate","isDeterministicLockStep","MinDeltaTime","getDeltaTime","MaxDeltaTime","defaultFrameTime","defaultFPS","stepsTaken","maxSubSteps","getLockstepMaxSteps","internalSteps","_checkCameraRenderTarget","resetDrawCache","passId","updateCameras","ignoreAnimations","currentActiveCamera","customIndex","freezeMaterials","freeze","unfreezeMaterials","unfreeze","stopAllAnimations","animatable","onAnimationEndObservable","activeRequests","_disposeList","itemsCopy","clearCachedVertexData","meshIndex","clearCachedData","cleanCachedTextureBuffer","baseTexture","getWorldExtends","filterPredicate","infiniteDistance","cameraViewSpace","createPickingRayToRef","enableDistantPicking","createPickingRayInCameraSpace","createPickingRayInCameraSpaceToRef","fastCheck","trianglePredicate","pickWithBoundingInfo","pickWithRay","multiPick","multiPickWithRay","_rebuildGeometries","system","spriteMgr","_rebuildTextures","_getByTags","list","listByTags","getMeshesByTags","getCamerasByTags","getLightsByTags","getMaterialByTags","getTransformNodesByTags","blockMaterialDirtyMechanism","useOfflineSupport","_loadFileAsync","_requestFile","_requestFileAsync","_readFile","_readFileAsync","getPerfCollector","setActiveCameraByID","getMaterialByID","getLastMaterialByID","getTextureByUniqueID","getCameraByID","getCameraByUniqueID","getBoneByID","getLightByID","getLightByUniqueID","getParticleSystemByID","getGeometryByID","getMeshByID","getMeshByUniqueID","getLastMeshByID","getMeshesByID","getTransformNodeByID","getTransformNodeByUniqueID","getTransformNodesByID","getNodeByID","getLastEntryByID","getLastSkeletonByID","FOGMODE_EXP","FOGMODE_EXP2","FOGMODE_LINEAR","IntersectionInfo","BoundingBox","worldMatrix","vectors","extendSize","extendSizeWorld","directions","vectorsWorld","minimum","maximum","_drawWrapperFront","_drawWrapperBack","reConstruct","minX","minY","maxX","maxY","_update","factor","tmpVectors","_TmpVector3","newRadius","minWorld","maxWorld","IsInFrustum","IsCompletelyInFrustum","intersectsPoint","pointX","pointY","pointZ","delta","intersectsSphere","sphere","IntersectsSphere","radiusWorld","intersectsMinMax","myMin","myMax","myMinX","myMinY","myMinZ","myMaxX","myMaxY","myMaxZ","box0","box1","minPoint","maxPoint","sphereCenter","sphereRadius","boundingVectors","canReturnFalse","BoundingSphere","tempRadiusVector","tempVector","isCenterInFrustum","squareDistance","sphere0","sphere1","radiusSum","_result0","_result1","computeBoxExtents","box","axisOverlap","BoundingInfo","_isLocked","isLocked","centerOn","extend","encapsulate","Minimize","Maximize","encapsulateBoundingInfo","toEncapsulate","invw","diagonalLength","_checkCollision","collider","_canDoCollision","intersects","precise","Intersects","MathHelpers","extractMinAndMax","bias","SubMesh","materialDefines","_mainDrawWrapperOverride","_getDrawWrapper","createIfNotExisting","drawWrapper","_drawWrappers","_mesh","_removeDrawWrapper","disposeWrapper","_drawWrapper","_drawWrapperOverride","_setMainDrawWrapperOverride","wrapper","materialIndex","renderingMesh","createBoundingBox","addToMesh","_linesIndexCount","_linesIndexBuffer","_lastColliderWorldVertices","_lastColliderTransformMatrix","_currentMaterial","_renderingMesh","_trianglePlanes","refreshBoundingInfo","IsGlobal","getTotalIndices","_boundingInfo","setBoundingInfo","getRenderingMesh","getReplacementMesh","getEffectiveMesh","replacementMesh","getDefaultMaterial","rootMaterial","getMaterialForRenderPass","_isMultiMaterial","effectiveMaterial","getSubMaterial","extractMinAndMaxIndexed","boundingBias","updateBoundingInfo","enableAlphaMode","_getLinesIndexBuffer","linesIndices","canIntersects","intersectsBox","checkStopper","_intersectLines","intersectionThreshold","_intersectUnIndexedLines","_unIndexed","_intersectUnIndexedTriangles","_intersectTriangles","intersectInfo","intersectionSegment","indexA","indexB","indexC","currentIntersectInfo","intersectsTriangle","newRenderingMesh","startIndex","minVertexIndex","maxVertexIndex","vertexIndex","VertexDataMaterialInfo","VertexData","coroutineFactory","_applyTo","_applyToCoroutine","tangents","uvs2","uvs3","uvs4","uvs5","uvs6","matricesIndices","matricesWeights","matricesIndicesExtra","matricesWeightsExtra","applyToMesh","applyToGeometry","updateMesh","updateGeometry","meshOrGeometry","setVerticesData","setIndices","materialInfos","matInfo","updateExtends","makeItUnique","updateVerticesData","coordinates","coordinate","transformedCoordinate","transformedNormal","_TransformVector3Coordinates","_TransformVector3Normals","_TransformVector4Normals","_FlipFaces","splitBasedOnMaterialID","materialInfo","newMaterialInfo","others","use32BitsIndices","forceCloneIndices","mergeMaterialIds","enableCompletion","vertexDatas","_mergeCoroutine","_validate","root","indexOffset","vertexOffset","currentMaterialInfo","vertexDataList","matInfoA","matInfoB","vertexDataSource","totalIndices","indexSum","indicesOffset","positionsOffset","_MergeElement","nonNullOthers","sumLen","transformRange","ret32","getElementCount","positionsElementCount","validateElementCount","elementCount","_isExpanded","materialInfoSerializationObject","copyWhenShared","_ExtractFrom","polygon","fUV","fColors","frontUVs","backUVs","wrap","orientation","capSubdivisions","p1p2x","p1p2y","p1p2z","p3p2x","p3p2y","p3p2z","faceNormalx","faceNormaly","faceNormalz","v1x","v1y","v1z","v2x","v2y","v2z","v3x","v3y","v3z","computeFacetNormals","computeFacetPositions","computeFacetPartitioning","computeDepthSort","faceNormalSign","ratio","distanceTo","facetNormals","facetPositions","facetPartitioning","depthSort","xSubRatio","ySubRatio","zSubRatio","subSq","bbSize","subDiv","X","Y","Z","nbFaces","ox","bInfo","oy","oz","b1x","b1y","b1z","b2x","b2y","b2z","b3x","b3y","b3z","block_idx_v1","block_idx_v2","block_idx_v3","block_idx_o","dsf","depthSortedFacets","ind","sqDistance","li","ln","DEFAULTSIDE","FRONTSIDE","BACKSIDE","DOUBLESIDE","lp","lu","parsedVertexData","CheckColors4","materialInfoFromJSON","setAllVerticesData","SceneLoaderFlags","ForceFullSceneLoadingForIncremental","_ForceFullSceneLoadingForIncremental","ShowLoadingScreen","_ShowLoadingScreen","loggingLevel","_LoggingLevel","CleanBoneMatrixWeights","_CleanBoneMatrixWeights","CompatibilityOptions","UseOpenGLOrientationForUV","Geometry","_boundingBias","_updateBoundingInfo","_meshes","_indexBufferIsUpdatable","_positionsCache","useBoundingInfoFromGeometry","_indices","_vertexArrayObjects","_extend","_notifyUpdate","setVerticesBuffer","removeVerticesData","_disposeVertexArrayObjects","disposeExistingBuffer","numOfMeshes","_updateExtend","_resetPointsArrayCache","buildBoundingInfo","_createGlobalSubMesh","isUnIndexed","synchronizeInstances","updateVerticesDataDirectly","getVertexBuffer","hasBoundingInfo","_bind","indexToBind","overrideVertexArrayObjects","vbs","getVertexBuffers","vaos","isVertexBufferUpdatable","_delayInfo","getVerticesDataKinds","updateIndices","gpuMemoryOnly","needToUpdateSubMeshes","updateDynamicIndexBuffer","orig","getIndexBuffer","_releaseVertexArrayObject","releaseForMesh","shouldDispose","_invalidateInstanceVertexArrayObject","_geometry","previousGeometry","_positions","_applyToMesh","_syncGeometryWithMorphTargetManager","onGeometryUpdated","_markSubMeshesAsAttributesDirty","load","onLoaded","_queueLoad","delayLoadingFile","_delayLoadingFunction","JSON","toLeftHanded","tIndices","tTemp","tPositions","tNormals","_generatePointsArray","arrayIdx","stopChecking","_toNumberArray","vbName","serializeVerticeData","uv2s","uv3s","uv4s","uv5s","uv6s","_loadedUniqueId","parsedGeometry","geometryUniqueId","geometryId","_GetGeometryByLoadedUniqueId","binaryInfo","_binaryInfo","positionsAttrDesc","positionsData","normalsAttrDesc","normalsData","tangetsAttrDesc","tangentsData","uvsAttrDesc","uvsData","uvs2AttrDesc","uvs2Data","uvs3AttrDesc","uvs3Data","uvs4AttrDesc","uvs4Data","uvs5AttrDesc","uvs5Data","uvs6AttrDesc","uvs6Data","colorsAttrDesc","colorsData","matricesIndicesAttrDesc","matricesIndicesData","floatIndices","matricesIndicesExtraAttrDesc","matricesWeightsAttrDesc","matricesWeightsData","indicesAttrDesc","indicesData","subMeshesAttrDesc","subMeshesData","AddToMesh","matricesIndex","_CleanMatricesWeights","parsedSubMesh","_shouldGenerateFlatShading","convertToFlatShadedMesh","noInfluenceBoneIndex","skeletonId","influencers","numBoneInfluencer","weight","firstZeroWeight","mweight","boundingBoxMinimum","boundingBoxMaximum","hasUVs","hasUVs2","hasUVs3","hasUVs4","hasUVs5","hasUVs6","hasColors","hasMatricesIndices","hasMatricesWeights","ImportVertexData","PerformanceMonitor","frameSampleSize","_rollingFrameTime","RollingAverage","sampleFrame","timeMs","_lastFrameTimeMs","dt","averageFrameTime","averageFrameTimeVariance","variance","instantaneousFrameTime","averageFPS","instantaneousFPS","isSaturated","_samples","bottomValue","_pos","_sampleCount","_m2","_wrapPosition","setAlphaConstants","noDepthWriteChange","ONE","ONE_MINUS_SRC_ALPHA","SRC_ALPHA","ZERO","ONE_MINUS_SRC_COLOR","DST_COLOR","CONSTANT_COLOR","ONE_MINUS_CONSTANT_COLOR","CONSTANT_ALPHA","ONE_MINUS_CONSTANT_ALPHA","DST_ALPHA","ONE_MINUS_DST_COLOR","ONE_MINUS_DST_ALPHA","getAlphaMode","setAlphaEquation","equation","getAlphaEquation","_readTexturePixelsSync","noDataConversion","dummy","sizeOrDstBuffer","copyBuffer","allocateAndCopyTypedBuffer","_readTexturePixels","dataLength","Engine","_createImageBitmapFromSource","imageSource","image","decode","imageBitmap","resizeImageBitmap","bufferWidth","bufferHeight","getImageData","engineIndex","sceneIndex","_RescalePostProcessFactory","performanceMonitor","_performanceMonitor","compatibilityMode","_compatibilityMode","enableOfflineSupport","disableManifestCheck","disableContextMenu","onResizeObservable","onCanvasBlurObservable","onCanvasFocusObservable","onCanvasPointerOutObservable","onBeginFrameObservable","customAnimationFrameRequester","onBeforeShaderCompilationObservable","onAfterShaderCompilationObservable","_deterministicLockstep","_lockstepMaxSteps","_timeStep","_fps","_deltaTime","_drawCalls","disablePerformanceMonitorInBackground","_renderPassNames","_connectVREvents","_prepareVRComponent","autoEnableWebVR","initWebVR","_rescalePostProcess","_onCanvasFocus","_onCanvasBlur","_onCanvasContextMenu","_onBlur","_onFocus","_onCanvasPointerOut","ev","elementFromPoint","hostWindow","doNotHandleTouchAction","_disableTouchAction","AudioEngineFactory","_onFullscreenChange","fullscreenElement","_pointerLockRequested","_RequestPointerlock","_onPointerLockChange","OfflineProviderFactory","viewportOwner","getScreenAspectRatio","getRenderingCanvasClientRect","generateMipMapsForCubemap","unbind","getDepthWrite","getStencilMask","setStencilMask","getStencilFunction","getStencilFunctionReference","getStencilFunctionMask","setStencilFunction","setStencilFunctionReference","setStencilFunctionMask","getStencilOperationFail","getStencilOperationDepthFail","getStencilOperationPass","setStencilOperationFail","setStencilOperationDepthFail","setStencilOperationPass","setDitheringState","setRasterizerState","RASTERIZER_DISCARD","getDepthFunction","setDepthFunction","setDepthFunctionToGreater","setDepthFunctionToGreaterOrEqual","setDepthFunctionToLess","setDepthFunctionToLessOrEqual","cacheStencilState","_cachedStencilBuffer","_cachedStencilFunction","_cachedStencilMask","_cachedStencilOperationPass","_cachedStencilOperationFail","_cachedStencilOperationDepthFail","_cachedStencilReference","restoreStencilState","setDirectViewport","scissorClear","enableScissor","disableScissor","SCISSOR_TEST","scissor","numDrawCalls","_submitVRFrame","disableVR","isVRPresenting","_requestVRFrame","getVertexShaderSource","shaders","getAttachedShaders","getFragmentShaderSource","postProcessInput","_forcedOutputTexture","_currentRenderTextureInd","_renderFrame","requestID","_renderViews","switchFullscreen","requestPointerLock","exitFullscreen","enterFullscreen","_RequestFullscreen","_ExitFullscreen","enterPointerlock","exitPointerlock","_ExitPointerlock","_measureFps","camIndex","transformFeedback","deleteTransformFeedback","createTransformFeedback","bindTransformFeedback","setTranformFeedbackVaryings","getRenderPassNames","getCurrentRenderPassName","_RenderPassIdCounter","createRenderTargetTexture","externalTextureSamplerBinding","getEffect","onApply","hostingScene","copyTexImage2D","getFps","wrapWebGLTexture","hasMipMaps","_uploadImageToTexture","updateTextureComparisonFunction","createInstancesBuffer","deleteInstancesBuffer","_clientWaitAsync","sync","flags","intervalms","clientWaitSync","WAIT_FAILED","TIMEOUT_EXPIRED","_readPixelsAsync","outputBuffer","PIXEL_PACK_BUFFER","STREAM_READ","fenceSync","SYNC_GPU_COMMANDS_COMPLETE","deleteSync","getBufferSubData","hideLoadingUI","touchAction","webkitTapHighlightColor","displayLoadingUI","loadingScreen","_loadingScreen","DefaultLoadingScreenFactory","loadingUIText","loadingUIBackgroundColor","createVideoElement","constraints","exitPointerLock","requestFunction","requestFullscreen","webkitRequestFullscreen","anyDoc","webkitCancelFullScreen","getFontOffset","font","innerHTML","block","div","whiteSpace","fontAscent","fontHeight","ascent","descent","Space","Coordinate","ALPHA_DISABLE","ALPHA_ADD","ALPHA_COMBINE","ALPHA_SUBTRACT","ALPHA_MULTIPLY","ALPHA_MAXIMIZED","ALPHA_ONEONE","ALPHA_PREMULTIPLIED","ALPHA_PREMULTIPLIED_PORTERDUFF","ALPHA_INTERPOLATE","ALPHA_SCREENMODE","DELAYLOADSTATE_NONE","DELAYLOADSTATE_LOADED","DELAYLOADSTATE_LOADING","DELAYLOADSTATE_NOTLOADED","NEVER","LESS","EQUAL","GREATER","NOTEQUAL","INCR","DECR","INVERT","INCR_WRAP","DECR_WRAP","TEXTURE_CLAMP_ADDRESSMODE","TEXTURE_WRAP_ADDRESSMODE","TEXTURE_MIRROR_ADDRESSMODE","TEXTUREFORMAT_ALPHA","TEXTUREFORMAT_LUMINANCE","TEXTUREFORMAT_LUMINANCE_ALPHA","TEXTUREFORMAT_RGB","TEXTUREFORMAT_RGBA","TEXTUREFORMAT_RED","TEXTUREFORMAT_R","TEXTUREFORMAT_RG","TEXTUREFORMAT_RED_INTEGER","TEXTUREFORMAT_R_INTEGER","TEXTUREFORMAT_RG_INTEGER","TEXTUREFORMAT_RGB_INTEGER","TEXTUREFORMAT_RGBA_INTEGER","TEXTURETYPE_UNSIGNED_BYTE","TEXTURETYPE_UNSIGNED_INT","TEXTURETYPE_FLOAT","TEXTURETYPE_HALF_FLOAT","TEXTURETYPE_BYTE","TEXTURETYPE_SHORT","TEXTURETYPE_UNSIGNED_SHORT","TEXTURETYPE_INT","TEXTURETYPE_UNSIGNED_INTEGER","TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4","TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1","TEXTURETYPE_UNSIGNED_SHORT_5_6_5","TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV","TEXTURETYPE_UNSIGNED_INT_24_8","TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV","TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV","TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV","TEXTURE_NEAREST_SAMPLINGMODE","TEXTURE_BILINEAR_SAMPLINGMODE","TEXTURE_TRILINEAR_SAMPLINGMODE","TEXTURE_NEAREST_NEAREST_MIPLINEAR","TEXTURE_LINEAR_LINEAR_MIPNEAREST","TEXTURE_LINEAR_LINEAR_MIPLINEAR","TEXTURE_NEAREST_NEAREST_MIPNEAREST","TEXTURE_NEAREST_LINEAR_MIPNEAREST","TEXTURE_NEAREST_LINEAR_MIPLINEAR","TEXTURE_NEAREST_LINEAR","TEXTURE_NEAREST_NEAREST","TEXTURE_LINEAR_NEAREST_MIPNEAREST","TEXTURE_LINEAR_NEAREST_MIPLINEAR","TEXTURE_LINEAR_LINEAR","TEXTURE_LINEAR_NEAREST","TEXTURE_EXPLICIT_MODE","TEXTURE_SPHERICAL_MODE","TEXTURE_PLANAR_MODE","TEXTURE_CUBIC_MODE","TEXTURE_PROJECTION_MODE","TEXTURE_SKYBOX_MODE","TEXTURE_INVCUBIC_MODE","TEXTURE_EQUIRECTANGULAR_MODE","TEXTURE_FIXED_EQUIRECTANGULAR_MODE","TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE","SCALEMODE_FLOOR","SCALEMODE_NEAREST","SCALEMODE_CEILING","Axis","convertRHSToLHS","Compose","FromEulerAngles","TransformNode","_billboardMode","useBillboardPosition","BILLBOARDMODE_USE_POSITION","_computeUseBillboardPath","preserveParentRotationForBillboard","_preserveParentRotationForBillboard","useBillboardPath","BILLBOARDMODE_NONE","_infiniteDistance","isPure","_forward","_up","_right","_rotation","_rotationQuaternion","_scaling","_transformToBoneReferal","_isAbsoluteSynced","scalingDeterminant","ignoreNonUniformScaling","reIntegrateRotationIntoRotationQuaternion","_poseMatrix","_localMatrix","_usePivotMatrix","_absolutePosition","_absoluteScaling","_absoluteRotationQuaternion","_pivotMatrix","_postMultiplyPivotMatrix","_isWorldMatrixFrozen","onAfterWorldMatrixUpdateObservable","_nonUniformScaling","isUsingPivotMatrix","newRotation","newScaling","updatePoseMatrix","getPoseMatrix","pivotMatrixUpdated","localMatrixUpdated","absolutePosition","getAbsolutePosition","absoluteScaling","_syncAbsoluteScalingAndRotation","absoluteRotationQuaternion","setPreTransformMatrix","setPivotMatrix","postMultiplyPivotMatrix","_pivotMatrixInverse","Invert","getPivotMatrix","instantiateHierarchy","onNewNodeCreated","getChildTransformNodes","freezeWorldMatrix","newWorldMatrix","_afterComputeWorldMatrix","unfreezeWorldMatrix","isWorldMatrixFrozen","setAbsolutePosition","absolutePositionX","absolutePositionY","absolutePositionZ","invertParentWorldMatrix","setPositionWithLocalVector","TransformNormal","getPositionExpressedInLocalSpace","invLocalWorldMatrix","locallyTranslate","TransformCoordinates","lookAt","yawCor","pitchCor","rollCor","space","LOCAL","dv","_LookAtVectorCache","pos","setDirection","WORLD","rotationMatrix","parentRotationMatrix","quaternionRotation","FromEulerVectorToRef","setPivotPoint","tmat","Translation","getPivotPoint","getPivotPointToRef","getAbsolutePivotPoint","getAbsolutePivotPointToRef","setParent","preserveScalingSign","updatePivot","quatRotation","invParentMatrix","composedMatrix","currentRotation","_TmpRotation","_updateNonUniformScalingState","attachToBone","affectedTransformNode","_currentParentWhenAttachingToBone","getSkeleton","getFinalMatrix","detachFromBone","resetToPreviousParent","rotate","_RotationAxisCache","rotateAround","tmpVector","finalScale","finalTranslation","finalRotation","translationMatrix","translationMatrixInv","finalMatrix","translate","displacementVector","tempV3","addRotation","accumulation","_getEffectiveParent","isWorldMatrixCameraDependent","currentRenderId","_TmpScaling","cameraWorldMatrix","cameraGlobalPosition","_TmpTranslation","scaleMatrix","BillboardUseParentOrientation","storedTranslation","BILLBOARDMODE_ALL","eulerAngles","BILLBOARDMODE_X","BILLBOARDMODE_Y","BILLBOARDMODE_Z","camInObjSpace","resetLocalMatrix","independentOfChildren","bakedMatrix","tmpRotationQuaternion","registerAfterWorldMatrixUpdate","unregisterAfterWorldMatrixUpdate","getPositionInCameraSpace","getDistanceToCamera","currentSerializationObject","localMatrix","parsedTransformNode","pivotMatrix","normalizeToUnitCube","ignoreRotation","storedRotation","storedRotationQuaternion","sizeVec","maxDimension","serializeAsQuaternion","_MeshCollisionData","_checkCollisions","_collisionMask","_collisionGroup","_surroundingMeshes","_collider","_oldPositionForCollisions","_diffPositionForCollisions","_collisionResponse","_FacetDataStorage","facetNb","partitioningSubdivisions","partitioningBBoxRatio","facetDataEnabled","facetParameters","facetDepthSort","facetDepthSortEnabled","_InternalAbstractMeshDataInfo","_hasVertexAlpha","_useVertexColors","_numBoneInfluencers","_applyFog","_receiveShadows","_facetData","_visibility","_skeleton","_layerMask","_computeBonesUsingShaders","_isActiveIntermediate","_onlyForInstancesIntermediate","_collisionRetryCount","_morphTargetManager","_renderingGroupId","_bakedVertexAnimationManager","_material","_meshCollisionData","_enableDistantPicking","_rawBoundingInfo","AbstractMesh","nb","mustDepthSortFacets","facetDepthSortFrom","collisionRetryCount","retryCount","isFacetDataEnabled","bakedVertexAnimationManager","_markSubMeshesAsMiscDirty","rawBoundingInfo","onCollide","_onCollideObserver","onCollideObservable","onCollisionPositionChange","_onCollisionPositionChangeObserver","onCollisionPositionChangeObservable","_markSubMeshesAsDirty","pointerOverDisableMeshTesting","meshMap","onMaterialChangedObservable","_unBindEffect","_materialForRenderPass","setMaterialForRenderPass","_markSubMeshesAsLightDirty","hasVertexAlpha","useVertexColors","numBoneInfluencers","applyFog","collisionMask","collisionResponse","collisionGroup","surroundingMeshes","_lightSources","needInitialSkinMatrix","_unregisterMeshWithPoseMatrix","_registerMeshWithPoseMatrix","_bonesTransformMatrices","_waitingMaterialId","CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY","definedFacingForward","_occlusionQuery","isNearPickable","isNearGrabbable","showSubMeshesBoundingBox","isBlocker","outlineColor","Red","outlineWidth","overlayColor","overlayAlpha","useOctreeForRenderingSelection","useOctreeForPicking","useOctreeForCollisions","doNotSyncBoundingInfo","ellipsoid","ellipsoidOffset","edgesWidth","edgesColor","_masterMesh","_boundingInfoIsDirty","_waitingData","lods","_transformMatrixTexture","onRebuildObservable","_onCollisionPositionChange","collisionId","collidedMesh","_uniformBuffer","_buildUniformLayout","transferToEffect","getMeshUniformBuffer","initialCall","canAffectMesh","_resyncLightSource","isIn","getRawBoundingInfo","useBones","_preActivateForIntermediateRendering","renderId","intermediateRendering","movePOV","amountRight","amountUp","amountForward","calcMovePOV","rotMatrix","translationDelta","defForwardMult","rotatePOV","flipBack","twirlClockwise","tiltRight","calcRotatePOV","applyMorph","_refreshBoundingInfo","_getPositionData","_getData","faceIndexCount","positionIndex","targetCount","targetMorph","influence","morphTargetPositions","getPositions","needExtras","matricesIndicesExtraData","matricesWeightsExtraData","skeletonMatrices","getTransformMatrices","tempMatrix","matWeightIdx","inf","FromFloat32ArrayToRefScaled","getNormalsData","getPositionData","_updateSubMeshesBoundingInfo","otherBoundingInfo","collisionEnabled","moveWithCollisions","displacement","coordinator","createCollider","_radius","getNewPosition","_collideForSubMesh","transformMatrix","_collide","_shouldConvertRHS","_processCollisionsForSubMeshes","collisionsScalingMatrix","collisionsTransformMatrix","onlyBoundingInfo","worldToUse","skipBoundingInfo","pickingInfo","anySubmeshSupportIntersect","worldOrigin","releaseSubMeshes","includedOnlyMeshes","generators","getShadowGenerators","shadowMap","getShadowMap","isOcclusionQueryInProgress","disableFacetData","addChild","_initFacetData","updateFacetData","depthSortedIndices","needs32bits","facetDepthSortFunction","f1","f2","depthSortedFacet","facetDepthSortOrigin","bbSizeMax","getFacetLocalNormals","getFacetLocalPositions","getFacetLocalPartitioning","ComputeNormals","sind","facetData","getFacetPosition","getFacetPositionToRef","localPos","getFacetNormal","getFacetNormalToRef","localNorm","getFacetsAtLocalCoordinates","getClosestFacetAtCoordinates","projected","checkFace","facing","invMat","invVect","closest","getClosestFacetAtLocalCoordinates","tmpx","tmpy","tmpz","t0","projx","projy","projz","facetsInBlock","fib","shortest","tmpDistance","getFacetDataParameters","createNormals","alignWithNormal","upDirection","axisX","axisZ","_checkOcclusionQuery","disableEdgesRendering","enableEdgesRendering","checkVerticesInsteadOfIndices","getConnectedParticleSystems","addClipPlaneUniforms","prepareStringDefinesForClipPlanes","primaryHolder","secondaryHolder","clipPlane","clipPlane2","clipPlane3","clipPlane4","clipPlane5","clipPlane6","bindClipPlane","setClipPlane","OCCLUSION_TYPE_NONE","OCCLUSION_TYPE_OPTIMISTIC","OCCLUSION_TYPE_STRICT","OCCLUSION_ALGORITHM_TYPE_ACCURATE","OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE","CULLINGSTRATEGY_STANDARD","CULLINGSTRATEGY_OPTIMISTIC_INCLUSION","CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY","MaterialHelper","optimizeUVAllocation","getTextureMatrix","coordinatesIndex","useLogarithmicDepth","pointsCloud","alphaTest","applyDecalAfterDetail","GetFogState","wasOrtho","wasPersp","isOrtho","isPersp","useInstances","useClipPlane","useThinInstances","PrepareDefinesForCamera","prepareDefinesForClipPlanes","materialSupportsBoneTexture","isUsingTextureForMatrices","nonExcluded","excludedSkinnedMesh","supportsUVs","supportsTangents","supportsNormals","numInfluencers","isUsingTextureForTargets","useVertexColor","useMorphTargets","useVertexAlpha","useBakedVertexAnimation","hasVertexColors","PrepareDefinesForBones","PrepareDefinesForMorphTargets","PrepareDefinesForBakedVertexAnimation","previousMultiview","MULTIVIEW","getViewCount","needAlphaBlending","previousDefine","ORDER_INDEPENDENT_TRANSPARENCY","previousDefine16Bits","ORDER_INDEPENDENT_TRANSPARENCY_16BITS","canRenderToMRT","previousPrePass","PREPASS","texturesList","SCENE_MRT_COUNT","mrtCount","getIndex","lightIndex","specularSupported","needNormals","needRebuild","prepareLightSpecificDefines","falloffType","specular","specularEnabled","shadowGenerator","getShadowGenerator","lightmapMode","maxSimultaneousLights","disableLighting","PrepareDefinesForLight","caps","projectedLightTexture","uniformBuffersList","updateOnlyBuffersList","uniformsListOrOptions","PrepareUniformsAndSamplersForLight","rank","lightFallbackRank","addFallback","attribs","_TmpMorphInfluencers","NUM_MORPH_INFLUENCERS","PrepareAttributesForMorphTargets","maxAttributesCount","tangent","uv","addCPUSkinningFallback","PushAttributesForInstances","INSTANCESCOLOR","needsPreviousMatrices","useSpecular","_bindLight","BindLight","linearSpace","_TempFogColor","prePassConfiguration","boneTexture","getTransformMatrixTexture","previousBones","_CopyBonesTransformationMatrices","abstractMesh","influences","LN2","MaterialStencilState","copyTo","MaterialPluginEvent","Orientation","AnimationKeyInterpolation","Material","_alpha","MiscDirtyFlag","PrePassDirtyFlag","_backFaceCulling","TextureDirtyFlag","_cullBackFaces","blockDirtyMechanism","_blockDirtyMechanism","markDirty","atomicMaterialsUpdate","_eventInfo","_callbackPluginEventHasRenderTargetTextures","_onBindObserver","onUnBindObservable","_onUnBindObservable","onEffectCreatedObservable","_onEffectCreatedObservable","alphaMode","_needDepthPrePass","checkReadyOnEveryCall","isPrePassCapable","wireframe","_fillMode","WireFrameFillMode","LineListDrawMode","LineLoopDrawMode","LineStripDrawMode","TriangleFillMode","PointFillMode","PointListDrawMode","_setDrawWrapper","doNotAdd","shadowDepthWrapper","allowShaderHotSwapping","checkReadyOnlyOnce","disableDepthWrite","disableColorWrite","forceDepthWrite","depthFunction","separateCullingPass","pointSize","_useUBO","_cachedDepthWriteState","_cachedColorWriteState","_cachedDepthFunctionState","_uniformBufferLayoutBuilt","_callbackPluginEventGeneric","_callbackPluginEventIsReadyForSubMesh","_callbackPluginEventPrepareDefines","_callbackPluginEventPrepareDefinesBeforeAttributes","_callbackPluginEventHardBindForSubMesh","_callbackPluginEventBindForSubMesh","_callbackPluginEventFillRenderTargetTextures","_forceAlphaTest","_transparencyMode","setScene","_dirtyCallbacks","_markAllSubMeshesAsTexturesDirty","_markAllSubMeshesAsLightsDirty","_markAllSubMeshesAsFresnelDirty","_markAllSubMeshesAsAttributesDirty","_markAllSubMeshesAsMiscDirty","_markAllSubMeshesAsPrePassDirty","_markAllSubMeshesAsAllDirty","_materialContext","ClockWiseSideOrientation","CounterClockWiseSideOrientation","OnEventObservable","Created","_isMaterial","isFrozen","isReadyForSubMesh","transparencyMode","MATERIAL_ALPHATESTANDBLEND","_markAllSubMeshesAsTexturesAndMiscDirty","_disableAlphaBlending","MATERIAL_OPAQUE","MATERIAL_ALPHATEST","_shouldTurnAlphaTestOn","getAlphaTestTexture","forceMaterialDirty","AllDirtyFlag","_preBind","overrideOrientation","buildUniformLayout","PrepareUniformBuffer","bindForSubMesh","bindOnlyWorldMatrix","bindView","_needToBindSceneUbo","bindViewProjection","_afterBind","BindSceneUniformBuffer","getAnimatables","GetAnimatables","getActiveTextures","activeTextures","GetActiveTextures","hasTexture","HasTexture","_clonePlugins","targetMaterial","_serializePlugins","_parsePlugins","pluginManager","plugin","_plugins","targetPlugin","getPlugin","getBindedMeshes","forceCompilation","localOptions","currentHotSwapingState","checkReady","clipPlaneState","allDone","lastError","tempSubMesh","forceCompilationAsync","_DirtyCallbackArray","_TextureDirtyCallBack","LightDirtyFlag","_LightsDirtyCallBack","FresnelDirtyFlag","_FresnelDirtyCallBack","AttributesDirtyFlag","_AttributeDirtyCallBack","_MiscDirtyCallBack","_PrePassDirtyCallBack","_markAllSubMeshesAsDirty","_RunDirtyCallBacks","_markScenePrePassDirty","enablePrePassRenderer","_AllDirtyCallBack","_markAllSubMeshesAsImageProcessingDirty","_ImageProcessingDirtyCallBack","_markAllSubMeshesAsFresnelAndMiscDirty","_FresnelAndMiscDirtyCallBack","_TextureAndMiscDirtyCallBack","_checkScenePerformancePriority","setPrePassRenderer","forceDisposeEffect","forceDisposeTextures","notBoundToMesh","Disposed","plugins","parsedMaterial","customType","overloadedAlbedo","BABYLON","LegacyPBRMaterial","pluginClassName","pluginData","pluginClassType","TriangleStripDrawMode","TriangleFanDrawMode","MATERIAL_ALPHABLEND","MATERIAL_NORMALBLENDMETHOD_WHITEOUT","MATERIAL_NORMALBLENDMETHOD_RNM","MultiMaterial","subMaterials","_subMaterials","_hookArray","_waitingSubMaterialsUniqueIds","oldPush","oldSplice","deleted","subMaterial","cloneChildren","materialsUniqueIds","matIndex","subMat","forceDisposeChildren","parsedMultiMaterial","multiMaterial","subMatId","MeshLODLevel","distanceOrScreenCoverage","_CreationDataStorage","_InstanceDataStorage","visibleInstances","batchCache","_InstancesBatch","batchCacheReplacementModeInFrozenMode","instancesBufferSize","mustReturn","renderSelf","_ThinInstanceDataStorage","matrixBuffer","previousMatrixBuffer","matrixBufferSize","matrixData","worldMatrices","_InternalMeshDataInfo","_areNormalsFrozen","_preActivateId","_LODLevels","_useLODScreenCoverage","_effectiveMaterial","_forcedInstanceCount","_overrideRenderingFillMode","Mesh","useLODScreenCoverage","_internalMeshDataInfo","_sortLODLevels","_sourcePositions","_sourceNormals","_onBeforeRenderObservable","onBeforeBindObservable","_onBeforeBindObservable","_onAfterRenderObservable","onBetweenPassObservable","_onBetweenPassObservable","onBeforeDrawObservable","_onBeforeDrawObservable","onBeforeDraw","_onBeforeDrawObserver","_thinInstanceDataStorage","forcedInstanceCount","overrideRenderingFillMode","cloneMeshMap","worldMatrixInstancedBuffer","_instanceDataStorage","instancesData","previousWorldMatrixInstancedBuffer","instancesPreviousData","manualUpdateOfWorldMatrixInstancedBuffer","manualUpdate","manualUpdateOfPreviousWorldMatrixInstancedBuffer","previousManualUpdate","forceWorldMatrixInstancedBufferUpdate","forceMatrixUpdates","clonePhysicsImpostor","_creationDataStorage","_originalBuilderSideOrientation","overrideMaterialSideOrientation","ignoreCameraMaxZ","_onBeforeDraw","isInstance","_internalMetadata","getPhysicsEngine","physicsEngine","getPluginVersion","impostor","getImpostorForPhysicsObject","physicsImpostor","physicsBody","_onMeshReadyObserverAdded","onMeshReadyObservable","_checkReadinessObserver","doNotInstantiate","createInstance","newSourcedMesh","_isMesh","ib","hasLODLevels","getLODLevels","sortingOrderFactor","addLODLevel","getLODLevelAtDistance","internalDataInfo","removeLODLevel","bSphere","distanceToCamera","compareValue","compareSign","meshArea","onLODLevelSelection","_checkDelayState","bypassInstanceData","_userInstancedBuffersStorage","kinds","forceInstanceSupport","generator","renderPassIds","areNormalsFrozen","freezeNormals","unfreezeNormals","overridenInstanceCount","sceneRenderId","intermediateDefaultRenderId","_registerInstanceForRenderId","defaultRenderId","selfDefaultRenderId","previousRenderId","thinInstanceRefreshBoundingInfo","edgesShareWithInstances","edgesRenderer","customInstances","needToRecreate","submesh","subdivide","subdivisionSize","CreateFromIndices","markVerticesDataAsUpdatable","CreateGeometryForMesh","makeGeometryUnique","updateMeshPositions","positionFunction","computeNormals","oldGeometry","allowInstancedRendering","_getRenderingFillMode","vertexArrayObjects","_draw","_getInstancesRenderList","isReplacementMode","previousBatch","isInIntermediateRendering","onlyForInstances","_renderWithInstances","batch","visibleInstanceCount","instanceStorage","currentInstancesBufferSize","instancesPreviousBuffer","needUpdateBuffer","masterMeshPreviousWorldMatrix","INSTANCEDMESH_SORT_TRANSPARENT","instanceIndex","instanceMesh","m1","m2","_previousWorldMatrix","strides","sizes","_processInstancedBuffers","_currentDrawContext","useInstancing","_renderWithThinInstances","previousMatrixData","_thinInstanceCreateMatrixBuffer","_processRendering","instanceCount","visibleInstancesForSubMesh","effectiveMeshReplacement","_occlusionDataStorage","forceRenderingWhenOccluded","oldCameraMaxZ","oldCamera","instanceDataStorage","effectiveMesh","mainDeterminant","cleanMatrixWeights","_normalizeSkinWeightsAndExtra","_normalizeSkinFourWeights","numWeights","recip","validateSkinning","skinned","valid","report","numberNotSorted","missingWeights","maxUsedWeights","numberNotNormalized","numInfluences","usedWeightCounts","lastWeight","usedWeights","tolerance","numBones","numBadBoneIndices","getBinaryData","_syncSubMeshes","setMaterialById","bakeTransformIntoVertices","submeshes","flipFaces","bakeCurrentTransformIntoVertices","bakeIndependentlyOfChildren","_disposeInstanceSpecificData","_disposeThinInstanceSpecificData","applyDisplacementMap","minHeight","maxHeight","uvOffset","uvScale","forceUpdate","heightMapWidth","heightMapHeight","applyDisplacementMapFromBuffer","_getFlattenedNormals","normalsCount","flipNormalGeneration","p3","Normalize","localIndex","_convertToUnIndexedMesh","flattenNormals","separateVertices","newData","previousSubmeshes","targetIndex","setPositions","getNormals","setNormals","getTangents","setTangents","getUVs","setUVs","synchronize","previousOne","convertToUnIndexedMesh","flipNormals","vertex_data","ExtractFromMesh","increaseVertices","numberPerEdge","currentIndices","tempIndices","deltaPosition","deltaNormal","deltaUV","side","uvPtr","normalsPtr","positionPtr","forceSharedVertices","currentUVs","currentPositions","currentColors","currentMatrixIndices","currentMatrixWeights","currentMatrixIndicesExtra","currentMatrixWeightsExtra","matrixIndices","matrixWeights","matrixIndicesExtra","matrixWeightsExtra","pstring","indexPtr","uniquePositions","ptr","facet","physicObject","jsonObject","_instancedMeshFactory","optimizeIndices","vectorPositions","dupes","SyncAsyncForLoop","realPos","testedPosition","againstPosition","originalSubMeshes","pickable","materialUniqueId","morphTargetManagerId","getPhysicsImpostor","physicsMass","getParam","physicsFriction","physicsRestitution","serializationInstance","thinInstances","enablePicking","thinInstanceEnablePicking","_userThinInstanceBuffersStorage","userThinInstance","renderOverlay","morphTarget","getActiveTarget","parsedMesh","_LinesMeshParser","_GroundMeshParser","_GoldbergMeshParser","_GreasedLineMeshParser","_TrailMeshParser","showBoundingBox","useFlatShading","_ImportGeometry","_PhysicsImpostorParser","lodMeshIds","ids","distances","lodDistances","coverages","lodCoverages","parsedInstance","thinInstanceSetBuffer","setPositionsForCPUSkinning","setNormalsForCPUSkinning","_softwareSkinningFrameId","hasNormals","tempVector3","minVector","maxVector","meshesOrMinMaxVector","minMaxVector","MinMax","Center","disposeSource","allow32BitsIndices","meshSubclass","subdivideWithSubMeshes","multiMultiMaterials","_MergeMeshesCoroutine","yieldAfterMS","createYieldingScheduler","materialArray","materialIndexArray","indiceArray","currentOverrideMaterialSideOrientation","getVertexDataFromMesh","sourceVertexData","sourceTransform","meshVertexDatas","mergeCoroutine","mergeCoroutineStep","applyToCoroutine","applyToCoroutineStep","addInstance","_indexInSourceMeshInstanceArray","removeInstance","setMaterialByID","pathArray","closeArray","diameter","diameterTop","diameterBottom","tube","radialSegments","tubularSegments","points","dashSize","gapSize","dashNb","shape","holes","earcutInjection","cap","scaleFunction","rotationFunction","ribbonCloseArray","ribbonClosePath","xmin","xmax","alphaFilter","radiusFunction","NO_CAP","CAP_START","CAP_END","CAP_ALL","NO_FLIP","FLIP_TILE","ROTATE_TILE","FLIP_ROW","ROTATE_ROW","FLIP_N_ROTATE_TILE","FLIP_N_ROTATE_ROW","CENTER","LEFT","RIGHT","TOP","BOTTOM","AutoRotationBehavior","_zoomStopsAnimation","_idleRotationSpeed","_idleRotationWaitTime","_idleRotationSpinupTime","targetAlpha","_isPointerDown","_lastFrameTime","_lastInteractionTime","_cameraRotationSpeed","_lastFrameRadius","zoomStopsAnimation","idleRotationSpeed","speed","idleRotationWaitTime","idleRotationSpinupTime","rotationInProgress","_attachedCamera","_onPrePointerObservableObserver","pointerInfoPre","_onAfterCheckInputsObserver","_reachTargetAlpha","_applyUserInteraction","timeToRotation","resetLastInteractionTime","customTime","_userIsZooming","inertialRadiusOffset","_shouldAnimationStopForInteraction","zoomHasHitLimit","_userIsMoving","inertialAlphaOffset","inertialBetaOffset","inertialPanningX","inertialPanningY","Angle","radians","_radians","degrees","Arc2","startPoint","midPoint","endPoint","startToMid","midToEnd","centerPoint","startAngle","BetweenTwoPoints","a1","a2","a3","FromDegrees","Path2","_points","_length","addLineTo","newPoint","previousPoint","addArcTo","midX","midY","endX","endY","numberOfSegments","increment","currentAngle","addQuadraticCurveTo","controlX","controlY","val0","val1","val2","addBezierCurveTo","originTangentX","originTangentY","destinationTangentX","destinationTangentY","val3","isPointInside","isInside","edgeLow","edgeHigh","edgeDx","edgeDy","EPSILON","perpEdge","lastPoint","area","getPoints","getPointAtLengthPosition","normalizedLengthPosition","lengthPosition","previousOffset","bToA","nextOffset","dir","localOffset","Path3D","firstNormal","raw","alignTangentsWithPath","_curve","_distances","_tangents","_binormals","_pointAtData","previousPointArrayIndex","subPosition","interpolateReady","interpolationMatrix","_raw","_alignTangentsWithPath","_compute","getCurve","getBinormals","getDistances","getPointAt","_updatePointAtData","getTangentAt","interpolated","getNormalAt","getBinormalAt","getDistanceAt","getPreviousPointIndexAt","getSubPositionAt","getClosestPositionTo","smallestDistance","closestPosition","subLength","_start","curvePoints","endIndex","slicePoints","_getFirstNonNullVector","tg0","pp0","_normalVector","curTang","prevNor","prevBinor","_getLastNonNullVector","nNVector","nLVector","vt","va","tgl","interpolateTNB","_updateInterpolationMatrix","_setPointAtData","currentPoint","currentLength","targetLength","parentIndex","tangentFrom","normalFrom","binormalFrom","tangentTo","normalTo","binormalTo","quatFrom","RotationQuaternionFromAxis","quatTo","Slerp","Curve3","nbPoints","bez","v3","t1","nSeg","hermite","Hermite","catmullRom","pointsCount","CatmullRom","totalPoints","second","third","steps","fullCircle","vec1","vec2","vec3","len4","len1_sq","len2_sq","len3_sq","len4_sq","dStep","_computeLength","continue","curve","continuedPoints","EasingFunction","_easingMode","EASINGMODE_EASEIN","setEasingMode","easingMode","getEasingMode","easeInCore","ease","EASINGMODE_EASEOUT","EASINGMODE_EASEINOUT","CircleEase","QuadraticEase","SineEase","AnimationRange","Size","surface","otherSize","Animation","targetProperty","framePerSecond","totalFrame","loopMode","easingFunction","dataType","parseFloat","isFinite","ANIMATIONTYPE_FLOAT","ANIMATIONTYPE_QUATERNION","ANIMATIONTYPE_VECTOR3","ANIMATIONTYPE_VECTOR2","ANIMATIONTYPE_COLOR3","ANIMATIONTYPE_COLOR4","ANIMATIONTYPE_SIZE","frame","setKeys","setEasingFunction","animationType","ANIMATIONLOOPMODE_CONSTANT","_PrepareAnimation","beginDirectAnimation","beginDirectHierarchyAnimation","sourceAnimation","referenceFrame","cloneOriginal","clonedName","firstKey","lastKey","valueStore","referenceValue","referencePosition","referenceQuaternion","referenceScaling","keyPosition","keyQuaternion","keyScaling","referenceFound","rangeValue","getRange","fromKeyFound","toKeyFound","_getKeyValue","nextKey","animationState","repeatCount","_interpolate","ANIMATIONTYPE_MATRIX","targetValue","host","frameRate","transition","runtimeAnimations","_runtimeAnimations","hasRunningRuntimeAnimations","runtimeAnimation","enableBlending","_easingFunction","blendingSpeed","targetPropertyPath","ANIMATIONLOOPMODE_CYCLE","_UniqueIdGenerator","addEvent","removeEvents","getEvents","getKeys","getHighestFrame","nKeys","getEasingFunction","floatInterpolateFunction","floatInterpolateFunctionWithTangents","outTangent","inTangent","quaternionInterpolateFunction","quaternionInterpolateFunctionWithTangents","vector3InterpolateFunction","vector3InterpolateFunctionWithTangents","vector2InterpolateFunction","vector2InterpolateFunctionWithTangents","sizeInterpolateFunction","color3InterpolateFunction","color3InterpolateFunctionWithTangents","color4InterpolateFunction","color4InterpolateFunctionWithTangents","evaluate","currentFrame","highLimitValue","keysLength","startKey","endKey","interpolation","STEP","useTangent","frameDelta","floatValue","ANIMATIONLOOPMODE_YOYO","ANIMATIONLOOPMODE_RELATIVE","offsetValue","quatValue","vec3Value","vec2Value","color3Value","color4Value","AllowMatricesInterpolation","matrixInterpolateFunction","workValue","AllowMatrixDecomposeForInterpolation","DecomposeLerp","loopBehavior","animationKey","_inTangent","_outTangent","keyData","serializedAnimation","snippetId","snippet","jsonPayload","outputs","SnippetUrl","CreateFromSnippetAsync","ParseFromSnippetAsync","BouncingBehavior","transitionDuration","lowerRadiusTransitionRange","upperRadiusTransitionRange","_autoTransitionRange","_radiusIsAnimating","_radiusBounceTransition","_animatables","autoTransitionRange","_onMeshTargetChangedObserver","onMeshTargetChangedObservable","diagonal","_isRadiusAtLimit","lowerRadiusLimit","_applyBoundRadiusAnimation","upperRadiusLimit","radiusLimit","radiusDelta","EasingMode","CreateAnimation","_cachedWheelPrecision","wheelPrecision","TransitionTo","_clearAnimationLocks","BackEase","amplitude","FramingBehavior","onTargetFramingAnimationEndObservable","FitFrustumSidesMode","_radiusScale","_positionScale","_defaultElevation","_elevationReturnTime","_elevationReturnWaitTime","_framingTime","autoCorrectCameraLimitsAndSensibility","_betaIsAnimating","radiusScale","positionScale","defaultElevation","elevation","elevationReturnTime","elevationReturnWaitTime","framingTime","zoomOnMesh","_maintainCameraAboveGround","focusOnOriginXZ","zoomOnBoundingInfo","zoomOnMeshHierarchy","zoomOnMeshesHierarchy","zoomTarget","zoomTargetY","_vectorTransition","_calculateLowerRadiusFromModelBoundingSphere","IgnoreBoundsSizeMode","panningSensibility","_radiusTransition","useInputToRestoreState","boxVectorGlobalDiagonal","frustumSlope","_getFrustumSlope","distanceForHorizontalFrustum","distanceForVerticalFrustum","timeSinceInteraction","defaultBeta","limitBeta","_betaTransition","animatabe","frustumSlopeY","isUserIsMoving","ExponentialEase","exponent","exp","TargetCamera","_tmpUpVector","_tmpTargetVector","cameraDirection","cameraRotation","ignoreParentScaling","updateUpVectorFromRotation","_tmpQuaternion","noRotationConstraint","invertRotation","inverseRotationSpeed","lockedTarget","_currentTarget","_initialFocalDistance","_camMatrix","_cameraTransformMatrix","_cameraRotationMatrix","_referencePoint","_transformedReferencePoint","_deferredPositionUpdate","_deferredRotationQuaternionUpdate","_deferredRotationUpdate","_deferredUpdated","_deferOnly","_defaultUp","_cachedRotationZ","_cachedQuaternionRotationZ","getFrontPosition","_getLockedTargetPosition","_storedPosition","_storedRotation","_storedRotationQuaternion","lockedTargetPosition","_computeLocalCameraSpeed","atan","vDir","_decideIfNeedsToMove","_updatePosition","directionMultiplier","needToMove","needToRotate","_rotateUpVectorWithCameraRotationMatrix","_computeViewMatrix","parentWorldMatrix","camLeft","camRight","leftSign","rightSign","_getRigCamPositionAndTarget","halfSpace","_TargetFocalPoint","newFocalTarget","_TargetTransformMatrix","RotationAxis","_RigCamTransformMatrix","CameraInputTypes","CameraInputsManager","attachedToElement","attached","checkInputs","getSimpleName","_addCheckInputs","noPreventDefault","inputToRemove","rebuildInputCheck","removeByType","inputType","attachInput","attachElement","detachElement","disconnect","serializedCamera","inputsmgr","parsedInputs","parsedinput","BaseCameraPointersInput","_currentActiveButton","BackCompatCameraNoPreventDefault","previousPinchSquaredDistance","previousMultiTouchPanPosition","_pointA","_pointB","_altKey","_ctrlKey","_metaKey","_shiftKey","_buttonsPressed","_pointerInput","isTouch","isInVRExclusivePointerMode","srcElement","onTouch","onDoubleTap","ed","distX","distY","pinchSquaredDistance","multiTouchPanPosition","onMultiTouch","onButtonUp","onButtonDown","_observer","_onLostFocus","onLostFocus","_contextMenuBind","onContextMenu","RegisterTopRootEvents","UnregisterTopRootEvents","ArcRotateCameraPointersInput","angularSensibilityX","angularSensibilityY","pinchPrecision","pinchDeltaPercentage","useNaturalPinchZoom","pinchZoom","multiTouchPanning","multiTouchPanAndZoom","pinchInwards","_isPanClick","_twoFingerActivityCount","_isPinching","_computeMultiTouchPanning","moveDeltaX","moveDeltaY","_computePinchZoom","MinimumRadiusForPinch","_useCtrlForPanning","pointA","pointB","pinchToPanMaxDistance","_panningMouseButton","ArcRotateCameraKeyboardMoveInput","keysUp","keysDown","keysLeft","keysRight","keysReset","zoomingSensibility","useAltToZoom","angularSpeed","_onCanvasBlurObserver","_onKeyboardObserver","_ctrlPressed","_altPressed","ArcRotateCameraMouseWheelInput","zoomToMouseLocation","wheelDeltaPercentage","customComputeDeltaFromMouseWheel","_inertialPanning","_computeDeltaFromMouseWheelLegacyEvent","mouseWheelDelta","_wheel","platformScale","estimatedTargetRadius","targetInertia","_hitPlane","_updateHitPlane","_zoomToMouse","_zeroIfClose","FromPositionAndNormal","_getPosition","targetScreenOffset","intersectsPlane","inertiaComp","lowerLimit","upperLimit","directionToZoomLocation","ArcRotateCameraInputsManager","addMouseWheel","addPointers","addKeyboard","AddNodeConstructor","ArcRotateCamera","_target","targetHost","_targetHost","_upToYMatrix","_yToUpMatrix","setMatUp","RotationAlignToRef","pointers","keyboard","mousewheel","bouncingBehavior","_bouncingBehavior","useBouncingBehavior","framingBehavior","_framingBehavior","useFramingBehavior","autoRotationBehavior","_autoRotationBehavior","useAutoRotationBehavior","lowerAlphaLimit","upperAlphaLimit","lowerBetaLimit","upperBetaLimit","panningDistanceLimit","panningOriginTarget","panningInertia","zoomOnFactor","allowUpsideDown","panningAxis","_transformedDirection","mapPanning","collisionRadius","_previousPosition","_collisionVelocity","_newPosition","_computationVector","cosa","sina","cosb","sinb","_getTargetPosition","_collisionTriggered","_targetBoundingCenter","_storedAlpha","_storedBeta","_storedRadius","_storedTarget","_storedTargetScreenOffset","ignored","useCtrlForPanning","panningMouseButton","_reset","directionModifier","localDirection","_checkLimits","rebuildAnglesAndRadius","previousAlpha","alphaCorrectionTurns","toBoundingCenter","allowSamePosition","cloneAlphaBetaRadius","overrideCloneAlphaBetaRadius","newTarget","zoomOn","doNotUpdateMaxZ","focusOn","meshesOrMinMaxVectorAndDistance","alphaShift","rigCam","Ray","intersectsBoxMinMax","intersectionTreshold","newMinimum","newMaximum","maxValue","rr","vertex0","edge1","edge2","pvec","tvec","qvec","invdet","bw","result1","result2","intersectsAxis","tm","_tmpRay","intersectsMeshes","_comparePickingInfo","pickingInfoA","pickingInfoB","sega","segb","threshold","rsegb","_Rayl","D","sN","tN","sD","tD","_Smallnum","sc","tc","qtc","qsc","dP","_RayDistant","unprojectRayToRef","nearScreenSource","farScreenSource","nearVec3","farVec3","_internalPickForMesh","rayFunction","_internalPick","computeWorldMatrixForCamera","currentCamera","forceCompute","tmpMatrix","thinMatrices","thinInstanceGetWorldMatrices","_internalMultiPick","pickingInfos","_tempPickingRay","_pickWithRayInverseMatrix","_cachedRayForTransform","SH3ylmBasisConstants","SH3ylmBasisTrigonometricTerms","applySH3","lm","SHCosKernelConvolution","SphericalHarmonics","preScaled","l00","l1_1","l10","l11","l2_2","l2_1","l20","l21","l22","deltaSolidAngle","colorVector","convertIncidentRadianceToIrradiance","convertIrradianceToLambertianRadiance","preScaleForRendering","updateFromArray","updateFromFloatsArray","FromFloatsToRef","polynomial","SphericalPolynomial","preScaledHarmonics","_harmonics","FromPolynomial","addAmbient","updateFromHarmonics","harmonics","sp","ray1","getCameraPositionWithOffset","toRadians","roundVectorToPlaces","significance","roundToPlaces","rotationToVector","toVector","fromVector","rotationToVectorToRef","transformVectorWithQuat","applyTransformToSpace","worldTransform","inSpace","inSpaceInv","spaceTransform","FromQuat","computeLocalTransform","toVec3","pivotTransform","scalingTransform","Scaling","rotationTransform","translationTransform","_toVector","_fromVector","rotAxis","multiplyScalar","scalar","computeNormal","applyMatrix4","thisVect","getRotationBtwVectors","addArrays","arrayA","arrayB","AxisType","KbVector_1","KbQuaternion_1","MeshNode_1","PrimitiveMeshNode_1","CustomMeshNode_1","KbColor_1","KbGeometry_1","basicallyEqual","isBoxMesh","isConeMesh","isCylinderMesh","isDiscMesh","isMeshGroupNode","isCustomMeshNode","isSketchNode","isTextNode","isSketchControlPoint","isMeshNode","isPrimitiveMeshNode","isSpaceNode","isPlaneMesh","newX","newY","newZ","crossProduct","dotProduct","shiftClone","toObject","toEuler","getAngle","_getRadAngle","getAxis","rad","nAxis","dV","_showPivot","getRotationQuaternion","FromYawPitchRoll","FromRotationAxis","setRotationQuaternion","features","connectors","_connectors","copyPropertiesTo","_primeMover","preTransform","getFeatureByName","_polygonCount","_verticesCount","getSpaceChildren","uvOverrides","_loading","hasGeometry","geometryLoaded","cssString","toIntObject","MAX_INT16","floatToIntStore","float","maxInt","maxVal","trunc","SketchNode_1","eContainerItemLayout","eContainerChildAlignment","eContainerItemAlignment","eContainerItemJustify","eScroll","eRelativeSize","ePadding","eColorShade","eBackgroundColor","eElevation","eRuleType","eToolbarPosition","eValidationTiming","eViewerMode","ePosition","eIconStyle","eExportType","eHotspotSource","eHotspotAttach","eHotspotPosition","eHotspotShape","eAnimationEasing","eQueryMode","eOptionFilterSource","eOutputType","eOutputFieldType","eSingleOptionBehavior","eConfiguratorImageSource","eTextColor","eConfiguratorEntityType","eBackground","eSideOrientation","eUvMode","eMaterialViewMode","eMaterialLocation","eAlphaMode","eViewpointType","eViewpointProjection","eViewpointTargetMode","eConnectorPositionMode","eDragMode","eConnectionMode","eEasing","eCylinderCap","eJoinType","eShadowQuality","eShadowResolution","eShadowFilter","eMaterialWorkflow","eFeatureCenter","eJobStatus","eJobType","eEnvironment","eImportType","eQueueMessageType","eMateType","eValidationType","eValidationSource","eTextureChannel","eTextureHorizontalAlign","eTextureVerticalAlign","eTextureFit","eTextureBlendMode","eTextureWrapAddressMode","eAnnotationLineStyle","eDimensionLineCapStyle","eDimensionAxis","eLoadingExperience","eReflectionType","eRenderMode","eTextureSamplingMode","eAxis","eSketchPathType","eFilterControl","eFilterSource","eFilterType","eFieldType","isSphereMesh","isTorusMesh","shared","extractFromBinary","fileData","meshNode","curPos","indicesDataSize","indices16","posOffset","posDataSize","posRatio","norOffset","norDataSize","norRatio","normalsInt","uvsOffset","uvsDataSize","uvsRatio","uvsInt","toBinary","fileLen","indicesBits","indicesLength","posBits","posLength","normalsOffset","normalsBits","normalsLength","uvsBits","uvsLength","inArray","canFitInUInt16Bit","setInt32","setUint16","setUint32","setFloat32","setInt16","_boundingBoxMin","_boundingBoxMax","_boundingBoxChanges","_controlPoints","_lineSegmentStartingPoints","_sketchPoints","paths","getBoundingBox","centerBB","getSketchLength","sketchLength","lastPosition","currentPos","controlPoints","vertexGroups","_previewParticleSize","vertexIndices","_vertexIndices","eHandler","_kb3dEnums","absolute","getSketch","worldPosition","TagArrayMap","_db","deleteByKeyValue","removeWhere","deleteEntryIfEmpty","getByKey","all","ArrayMap","deleteByTag","nodeResult","handlers","deleteByKey","removeValue","flat","SetMap","HandlerMap","idNameOrNode","getNodesByIdOrName","fontFilesLoading","stylesheetsLoading","fontFamilySrcs","httpService","assetRoot","readyFonts","loadFont","stylesheetUrl","fontFamilies","fontFaceSet","fonts","loadStylesheet","loadFontFamily","loadFontByFile","absPath","getAbsoluteFontPath","loadPromise","getPublicStatic","loadFontData","getFontData","relativePath","stylesheetLoad","fontFaces","matchAll","face","fontFamilyMatch","fontFamilyName","srcMatch","fontSrc","loadFaces","loadPromises","resMap","buffers","resultData","resultFonts","newFontFace","FontFace","eContentType","ABORTED","trackedAssetCalls","deferredAssetCalls","httpCallsToAbort","deferredExecuted","addCacheParams","getUrlWithParams","getEnvironmentCacheParams","trackAssetCall","addParams","fetchWrapper","fetch","credentials","arrayBuffer","json","post","put","getBinary","appendCacheParameters","abortSubject","xhr","abortSub","oEvent","getAllResponseHeaders","onabort","defer","priority","executeDeferredCalls","trackedPromise","finally","lastDeploy","cacheBuster","urlParams","URLSearchParams","prefix","headers","Headers","requestInit","append","stringify","formData","ok","getRotatedDimensions","rAngle","scaleImagePreserveAspect","targetWidth","targetHeight","naturalWidth","naturalHeight","drawWidth","drawHeight","imageWidth","imageHeight","getBinClampedSize","rounding","KBMAXPREFIX","LOCAL_ENVIRONMENT_DOMAIN","slowWarningThrown","attachLoadingTimer","fileSize","endTime","LIBRARY_PATH","textureCache","materialCache","TEXTURE_SIZES","LIBRARY_TEXTURE_SIZES","LIBRARY_ENV_SIZES","LIBRARY_MOBILE_ENV_SIZES","forceFullSizeTextures","materialUpdateChannel","abortSubjects","textureDetailLevel","screen","getMaterialLibraryCategories","materialDefinitionSet","getMaterialLibraryOptions","category","LibraryMaterialsByCategory","guid","LibraryMaterials","updateChannel","combineLatest","updatedMaterial","getTexturePath","detailLevel","getLibraryTexturePath","getAbsoluteTexturePath","getTextureImage","initialUrl","bitmapObs","processImageBlob","opts","resizeWidth","resizeHeight","resizeQuality","bitmap","activeLinkAbort","abortTextureLoad","cacheParamUrl","blobResult","initialCacheParamUrl","loadStartTime","initialBlobResult","loadTime","blobToConvert","imageElement","blobUrl","scaled","getAbsoluteEnvironmentPath","searchMaterialByName","loadArchivedMaterials","archivedFilter","searchArgs","sortField","descending","getMaterialNameList","fields","setMaterialCache","LibraryEnvironments","LibraryEnvironmentsMap","makeLibraryMaterial","indexStr","iname","baseUrl","library","ambientOcclusion","albedo","asphalt","omit","bark","bricks","chipboard","concrete","corrugatedsteel","diamondplate","fabric","gravel","ground","ice","leather","marble","metal","metalplates","paint","paintedmetal","paintedplaster","pavingstones","planks","plastic","rock","rocks","roofingtiles","rust","scratches","terrazzo","tiles","wood","woodfloor","woodsiding","matData","categoryList","fillLibraryMaterialsMap","env","previewUrl","geometryCache","hydrateGeometry","isLightNode","_forceGrid","_lights","viewpoints","_viewpoints","_scenes","mates","_mates","annotations","_annotations","importHistory","_importHistory","exportHistory","_exportHistory","isNested","runOnAllScenes","nested","getNestedPathTo","isPath","nestedId","getAllConnectors","getByToken","getAllSketchControlPoints","SET_TYPE","dynamicDb","getByDynamicId","dynamicId","throwOnNotFound","ImportOperation","Kb3dManager","isDevEnvironment","_tokenDb","_nodeDb","_nameSearchCache","_nestedSceneDb","clickHandlers","doubleClickHandlers","draggables","hotspotClickHandlers","boundingboxChangeHandlers","services","getService","serviceToken","runOnNodes","idOrName","useCache","getById","getNodesByName","nestedScene","subId","getNodeByIdOrName","getAll","getAllNodes","getFirstNodeByName","re","getWildcardRegex","getNodesContainingName","getByTokens","escapeRegex","rule","includeChildNodes","constructorParameters","hydratedParameters","service","initializeModel","afterCreate","isRoot","omitDefaultValues","defaultValues","shallowEquals","sourceArray","sourceItem","targetItem","onSerializing","deserializeJson","objectToClone","issueNewIds","nestScene","serializedNested","nestedMan","getNodeNamePathMap","matMap","lightMap","allNodes","previewImport","imported","nMap","processNode","parentNamePath","namePath","matchingNode","childProp","childArr","cNode","pathToImportParent","import","previews","parentNode","thisNode","originalId","matchingMeshNode","originalMaterialId","parentPath","setModelDefaultValues","copyingToDifferentNode","sourceProp","aProp","bProp","isTextureLayer","_init","local","_needsImageUpdate","svgXml","getC1","getC2","isActive","validate","hasAny","assert","topologicalSort","nameSelector","visited","sorted","cycles","recurse","edges","orbit","perspective","_type","newType","firstPerson","ThinTexture","_wrapU","_wrapV","_texture","_shareDepth","_cachedSize","_cachedBaseSize","_initialSamplingMode","_IsRenderTargetWrapper","getBaseSize","updateSamplingMode","releaseInternalTexture","BaseTexture","_hasAlpha","getAlphaFromRGB","_getAlphaFromRGB","_coordinatesIndex","_coordinatesMode","_isCube","gammaSpace","isRGBD","lodGenerationOffset","lodGenerationScale","linearSpecularLOD","irradianceTexture","isBlocking","loadingError","_loadingError","errorObject","_errorObject","sceneOrEngine","DEFAULT_ANISOTROPIC_FILTERING_LEVEL","invertZ","lodLevelInAlpha","_prefiltered","_forceSerialize","_IsScene","_getEngine","checkTransformsAreIdentical","getReflectionTextureMatrix","getRefractionTextureMatrix","isReadyOrNotBlocking","canRescale","_getFromCache","sampling","correctedUseSRGBBuffer","texturesCache","texturesCacheEntry","maxWidth","_readPixelsSync","allowEmptyName","numRemaining","onLoadObservable","GenerateBase64StringFromPixelData","npixels","ctx","createImageData","putImageData","canvas2","ctx2","Texture","_noMipmap","_mimeType","_isBlocking","_invertY","noMipmapOrOptions","TRILINEAR_SAMPLINGMODE","uAng","vAng","wAng","uRotationCenter","vRotationCenter","wRotationCenter","homogeneousRotationInUVTransform","inspectableCustomProperties","_rowGenerationMatrix","_cachedTextureMatrix","_projectionModeMatrix","_t0","_t1","_t2","_cachedUOffset","_cachedVOffset","_cachedUScale","_cachedVScale","_cachedUAng","_cachedVAng","_cachedWAng","_cachedReflectionProjectionMatrixId","_cachedURotationCenter","_cachedVRotationCenter","_cachedWRotationCenter","_cachedHomogeneousRotationInUVTransform","_cachedReflectionTextureMatrix","_cachedReflectionUOffset","_cachedReflectionVOffset","_cachedReflectionUScale","_cachedReflectionVScale","_cachedReflectionCoordinatesMode","_format","_delayedOnLoad","_delayedOnError","_loaderOptions","_creationFlags","_forcedExtension","errorHandler","OnTextureLoadErrorObservable","loadObserver","useDelayedTextureLoading","updateURL","_prepareRowForTextureGeneration","uBase","PROJECTION_MODE","flagMaterialsAsTextureDirty","PLANAR_MODE","projectionMatrix","savedName","SerializeBuffers","_SerializeInternalTextureUniqueId","ForceSerializeBuffers","base64String","GenerateBase64StringFromTexture","GenerateBase64StringFromTextureAsync","internalTextureUniqueId","parsedTexture","parsedCustomTexture","_samplingMode","_CubeTextureParser","hasInternalTextureUniqueId","mirrorPlane","mirrorTexture","_CreateMirror","renderTargetSize","_waitingRenderList","renderTargetTexture","reflectionProbes","probe","cubeTexture","_CreateRenderTargetTexture","CreateFromBase64String","UseSerializedUrlIfAny","jsonTexture","NEAREST_SAMPLINGMODE","NEAREST_NEAREST_MIPLINEAR","BILINEAR_SAMPLINGMODE","LINEAR_LINEAR_MIPNEAREST","LINEAR_LINEAR_MIPLINEAR","NEAREST_NEAREST_MIPNEAREST","NEAREST_LINEAR_MIPNEAREST","NEAREST_LINEAR_MIPLINEAR","NEAREST_LINEAR","NEAREST_NEAREST","LINEAR_NEAREST_MIPNEAREST","LINEAR_NEAREST_MIPLINEAR","LINEAR_LINEAR","LINEAR_NEAREST","EXPLICIT_MODE","SPHERICAL_MODE","CUBIC_MODE","SKYBOX_MODE","INVCUBIC_MODE","EQUIRECTANGULAR_MODE","FIXED_EQUIRECTANGULAR_MODE","FIXED_EQUIRECTANGULAR_MIRRORED_MODE","CLAMP_ADDRESSMODE","WRAP_ADDRESSMODE","MIRROR_ADDRESSMODE","PrePassConfiguration","previousWorldMatrices","currentRTisSceneRT","previousViewProjection","currentViewProjection","_lastUpdateFrameId","PushMaterial","storeEffectOnSubMeshes","_normalMatrix","_activeEffect","_isReadyForSubMesh","bindOnlyNormalMatrix","normalMatrix","_mustRebind","MaterialFlags","DiffuseTextureEnabled","_DiffuseTextureEnabled","MarkAllMaterialsAsDirty","DetailTextureEnabled","_DetailTextureEnabled","DecalMapEnabled","_DecalMapEnabled","AmbientTextureEnabled","_AmbientTextureEnabled","OpacityTextureEnabled","_OpacityTextureEnabled","ReflectionTextureEnabled","_ReflectionTextureEnabled","EmissiveTextureEnabled","_EmissiveTextureEnabled","SpecularTextureEnabled","_SpecularTextureEnabled","BumpTextureEnabled","_BumpTextureEnabled","LightmapTextureEnabled","_LightmapTextureEnabled","RefractionTextureEnabled","_RefractionTextureEnabled","ColorGradingTextureEnabled","_ColorGradingTextureEnabled","FresnelEnabled","_FresnelEnabled","ClearCoatTextureEnabled","_ClearCoatTextureEnabled","ClearCoatBumpTextureEnabled","_ClearCoatBumpTextureEnabled","ClearCoatTintTextureEnabled","_ClearCoatTintTextureEnabled","SheenTextureEnabled","_SheenTextureEnabled","AnisotropicTextureEnabled","_AnisotropicTextureEnabled","ThicknessTextureEnabled","_ThicknessTextureEnabled","RefractionIntensityTextureEnabled","_RefractionIntensityTextureEnabled","TranslucencyIntensityTextureEnabled","_TranslucencyIntensityTextureEnabled","IridescenceTextureEnabled","_IridescenceTextureEnabled","EffectFallbacks","_defines","_currentRank","_maxRank","currentDefines","currentFallbacks","rxOption","MaterialPluginManager","_activePlugins","_activePluginsForExtraEvents","_addPlugin","_MaterialPluginClassToMainDefine","_MaterialPluginCounter","_handlePluginEvent","_codeInjectionPoints","defineNamesFromPlugins","collectDefines","_collectPointNames","getCustomCode","_defineNamesFromPlugins","_activatePlugin","_handlePluginEventIsReadyForSubMesh","_handlePluginEventPrepareDefinesBeforeAttributes","_handlePluginEventPrepareDefines","_handlePluginEventBindForSubMesh","registerForExtraEvents","_handlePluginEventHasRenderTargetTextures","_handlePluginEventFillRenderTargetTextures","_handlePluginEventHardBindForSubMesh","prepareDefinesBeforeAttributes","hardBindForSubMesh","fillRenderTargetTextures","renderTargets","GetDefineNames","defineNames","PrepareEffect","fallbackRank","addFallbacks","_uniformList","_uboList","customCode","_injectCustomCode","_uboDeclaration","_vertexDeclaration","_fragmentDeclaration","shaderType","pointName","existingCallback","injectedCode","resolveIncludes","regexFlags","matchOption","newCode","fullPointName","MaterialPluginBase","_enable","_pluginManager","addToPluginList","_pluginDefineNames","markAllDefinesAsDirty","currentRank","ubos","MaterialDetailMapDefines","DETAIL","DETAILDIRECTUV","DETAIL_NORMALBLENDMETHOD","DetailMapConfiguration","_internalMarkAllSubMeshesAsTexturesDirty","diffuseBlendLevel","roughnessBlendLevel","bumpLevel","_normalBlendMethod","PrepareDefinesForMergedUV","BindTextureMatrix","onCreatedEffectParameters","StandardMaterialDefines","MAINUV1","MAINUV2","MAINUV3","MAINUV4","MAINUV5","MAINUV6","DIFFUSE","DIFFUSEDIRECTUV","BAKED_VERTEX_ANIMATION_TEXTURE","AMBIENT","AMBIENTDIRECTUV","OPACITY","OPACITYDIRECTUV","OPACITYRGB","REFLECTION","EMISSIVE","EMISSIVEDIRECTUV","SPECULAR","SPECULARDIRECTUV","BUMP","BUMPDIRECTUV","PARALLAX","PARALLAXOCCLUSION","SPECULAROVERALPHA","CLIPPLANE","CLIPPLANE2","CLIPPLANE3","CLIPPLANE4","CLIPPLANE5","CLIPPLANE6","ALPHATEST","DEPTHPREPASS","ALPHAFROMDIFFUSE","POINTSIZE","FOG","SPECULARTERM","DIFFUSEFRESNEL","OPACITYFRESNEL","REFLECTIONFRESNEL","REFRACTIONFRESNEL","EMISSIVEFRESNEL","FRESNEL","NORMAL","TANGENT","UV1","UV2","UV3","UV4","UV5","UV6","VERTEXCOLOR","VERTEXALPHA","NUM_BONE_INFLUENCERS","BonesPerMesh","BONETEXTURE","BONES_VELOCITY_ENABLED","INSTANCES","THIN_INSTANCES","GLOSSINESS","ROUGHNESS","EMISSIVEASILLUMINATION","LINKEMISSIVEWITHDIFFUSE","REFLECTIONFRESNELFROMSPECULAR","LIGHTMAP","LIGHTMAPDIRECTUV","OBJECTSPACE_NORMALMAP","USELIGHTMAPASSHADOWMAP","REFLECTIONMAP_3D","REFLECTIONMAP_SPHERICAL","REFLECTIONMAP_PLANAR","REFLECTIONMAP_CUBIC","USE_LOCAL_REFLECTIONMAP_CUBIC","USE_LOCAL_REFRACTIONMAP_CUBIC","REFLECTIONMAP_PROJECTION","REFLECTIONMAP_SKYBOX","REFLECTIONMAP_EXPLICIT","REFLECTIONMAP_EQUIRECTANGULAR","REFLECTIONMAP_EQUIRECTANGULAR_FIXED","REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED","REFLECTIONMAP_OPPOSITEZ","INVERTCUBICMAP","LOGARITHMICDEPTH","REFRACTION","REFRACTIONMAP_3D","REFLECTIONOVERALPHA","TWOSIDEDLIGHTING","SHADOWFLOAT","MORPHTARGETS","MORPHTARGETS_NORMAL","MORPHTARGETS_TANGENT","MORPHTARGETS_UV","MORPHTARGETS_TEXTURE","NONUNIFORMSCALING","PREMULTIPLYALPHA","ALPHATEST_AFTERALLALPHACOMPUTATIONS","ALPHABLEND","PREPASS_IRRADIANCE","PREPASS_IRRADIANCE_INDEX","PREPASS_ALBEDO_SQRT","PREPASS_ALBEDO_SQRT_INDEX","PREPASS_DEPTH","PREPASS_DEPTH_INDEX","PREPASS_NORMAL","PREPASS_NORMAL_INDEX","PREPASS_POSITION","PREPASS_POSITION_INDEX","PREPASS_VELOCITY","PREPASS_VELOCITY_INDEX","PREPASS_REFLECTIVITY","PREPASS_REFLECTIVITY_INDEX","RGBDLIGHTMAP","RGBDREFLECTION","RGBDREFRACTION","CAMERA_ORTHOGRAPHIC","CAMERA_PERSPECTIVE","IS_REFLECTION_LINEAR","IS_REFRACTION_LINEAR","DECAL_AFTER_DETAIL","setReflectionMode","modeToEnable","modes","StandardMaterial","_attachImageProcessingConfiguration","configuration","_imageProcessingObserver","cameraColorCurvesEnabled","cameraColorGradingEnabled","cameraToneMappingEnabled","cameraExposure","cameraContrast","cameraColorGradingTexture","cameraColorCurves","_diffuseTexture","_ambientTexture","_opacityTexture","_reflectionTexture","_emissiveTexture","_specularTexture","_bumpTexture","_lightmapTexture","_refractionTexture","diffuseColor","specularPower","_useAlphaFromDiffuseTexture","_useEmissiveAsIllumination","_linkEmissiveWithDiffuse","_useSpecularOverAlpha","_useReflectionOverAlpha","_disableLighting","_useObjectSpaceNormalMap","_useParallax","_useParallaxOcclusion","parallaxScaleBias","_roughness","indexOfRefraction","invertRefractionY","alphaCutOff","_useLightmapAsShadowmap","_useReflectionFresnelFromSpecular","_useGlossinessFromSpecularMapAlpha","_maxSimultaneousLights","_invertNormalMapX","_invertNormalMapY","_twoSidedLighting","_applyDecalMapAfterDetailMap","_worldViewProjectionMatrix","_globalAmbientColor","_cacheHasRenderTargetTextures","detailMap","_useLogarithmicDepth","_shouldUseAlphaFromDiffuseTexture","_opacityFresnelParameters","_hasAlphaChannel","PrepareDefinesForLights","PrepareDefinesForMultiview","oit","PrepareDefinesForPrePass","PrepareDefinesForOIT","boundingBoxSize","reflectionTexture","refractionTexture","_diffuseFresnelParameters","_emissiveFresnelParameters","_refractionFresnelParameters","_reflectionFresnelParameters","PrepareDefinesForMisc","PrepareDefinesForFrameBoundValues","PrepareDefinesForAttributes","forceWasNotReadyPreviously","lightDisposed","HandleFallbacksForShadows","PrepareAttributesForBones","PrepareAttributesForInstances","PrepareAttributesForBakedVertexAnimation","shaderName","maxSimultaneousMorphTargets","AddUniforms","AddSamplers","PrepareSamplers","PrepareUniformsAndSamplersList","csnrOptions","customShaderNameResolve","previousEffect","mustRebind","BindBonesParameters","diffuseFresnelParameters","leftColor","power","rightColor","opacityFresnelParameters","reflectionFresnelParameters","refractionFresnelParameters","emissiveFresnelParameters","boundingBoxPosition","BindLights","BindFogParameters","BindMorphTargetParameters","BindLogDepth","WebGLRenderTargetWrapper","RenderTargetWrapper","depthStencilTextureWithStencil","_isMulti","faceIndices","_faceIndices","layerIndices","_layerIndices","setSamples","initializeBuffers","updateMultipleRenderTargetTextureSampleCount","updateRenderTargetTextureSampleCount","_attachments","_generateStencilBuffer","_generateDepthBuffer","setTextures","disposePrevious","setLayerAndFaceIndices","faces","setLayerAndFaceIndex","createDepthStencilTexture","depthTextureFormat","_cloneRenderTargetWrapper","rtw","textureArray","generateDepthTexture","textureCount","lastTextureSource","Depth","DepthStencil","samplingModes","types","formats","targetTypes","layerIndex","layerCounts","internalTexture2Index","optionsMRT","createMultipleRenderTarget","createRenderTargetCubeTexture","_swapRenderTargetWrapper","bilinear","releaseTextures","disposeOnlyFramebuffers","_depthStencilBuffer","_colorTextureArray","_depthStencilTextureArray","_disposeOnlyFramebuffers","createMultiviewRenderTargetTexture","depthbuffer","_bindTextureRenderTarget","attachmentIndex","faceIndexOrLayer","currentFB","_createHardwareRenderTargetWrapper","colorAttachment","noColorAttachment","RenderTarget","currentFrameBuffer","_createDepthStencilCubeTexture","_createDepthStencilTexture","internalOptions","hasStencil","DEPTH_COMPONENT","DEPTH_COMPONENT24","DEPTH32F_STENCIL8","glRtWrapper","colorRenderbuffer","PostProcess","postProcessName","customShaderCodeProcessing","_CustomShaderCodeProcessing","_fragmentUrl","onActivate","_onActivateObserver","onActivateObservable","onSizeChanged","_onSizeChangedObserver","onSizeChangedObservable","_onApplyObserver","onApplyObservable","onBeforeRender","onAfterRender","inputTexture","restoreDefaultInputTexture","getCamera","_camera","texelSize","_shareOutputWithPostProcess","_texelSize","fragmentUrl","reusable","vertexUrl","blockCompilation","nodeMaterialSource","forceAutoClearInAlphaMode","enablePixelPerfectMode","scaleMode","alwaysForcePOT","adaptScaleToCurrentViewport","_reusable","_textureCache","_scaleRatio","_options","renderTargetSamplingMode","_textureType","_textureFormat","_vertexUrl","_parameters","updateEffect","shareOutputWith","_disposeTextures","useOwnOutput","_GetShaderCodeProcessing","defineCustomBindings","newUniforms","newSamplers","_postProcessDefines","_createRenderTargetTexture","textureOptions","postProcessChannel","lastUsedRenderId","_flushTextureCache","currentlyUsed","_resize","needMipMaps","forceDepthStencil","firstPP","maxSize","webVRCamera","desiredWidth","desiredHeight","alphaConstants","bindCustomBindings","_disposeTextureCache","_prePassEffectConfiguration","addEffectConfiguration","cameraId","parsedPostProcess","postProcessType","_Parse","targetCamera","defaultOptions","EffectRenderer","_fullscreenViewport","_onContextRestoredObserver","applyEffectWrapper","effectWrapper","saveStates","_savedStateDepthTest","_savedStateStencilTest","restoreStates","_isRenderTargetTexture","outputTexture","EffectWrapper","creationOptions","effectCreationOptions","uniformNames","useShaderStore","attributeNames","samplerNames","passPixelShader","DumpTools","_DumpToolsEngine","DumpData","_CreateDumpRenderer","data2","fileReader","EncodeScreenshotCanvasData","DumpDataAsync","DumpFramebuffer","RenderTargetTexture","_renderList","_unObserveRenderList","_renderListHasChanged","_prePassEnabled","_prePassRenderTarget","onAfterUnbind","_onAfterUnbindObserver","onAfterUnbindObservable","onClear","_onClearObserver","_renderPassIds","currentRefreshId","_currentRefreshId","setMaterialForRendering","_renderTarget","renderTargetOptions","_renderTargetOptions","_onRatioRescale","_sizeRatio","_initialSizeParameter","_boundingBoxSize","doNotChangeAspectRatio","_functionName","newLength","forceLayerMaskCheck","ignoreCameraViewport","_refreshRate","_canRescale","_isCubeData","_processSizeParameter","_resizeObserver","_generateMipMaps","_doNotChangeAspectRatio","getRenderSize","_textureMatrix","_releaseRenderPassId","_createRenderPassId","numPasses","getRenderLayers","createRenderPassIds","_bestReflectionRenderTargetDimension","resetRefreshCounter","refreshRate","addPostProcess","_postProcessManager","clearPostProcesses","removePostProcess","disableRescaling","newSize","wasCube","useCameraPostProcess","dumpForDebug","_render","checkReadiness","useCameraPostProcesses","renderListPredicate","sceneMeshes","sceneCamera","_defaultRenderListPrepared","numLayers","currentRenderList","defaultRenderList","defaultRenderListLength","getCustomRenderList","customIsReadyFunction","_renderToTarget","renderDimension","curved","_prepareRenderingManager","currentRenderListLength","checkLayerMask","isMasked","_unbindFrameBuffer","_debugPushGroup","saveGenerateMipMaps","_debugPopGroup","disposeFramebufferObjects","REFRESHRATE_RENDER_ONCE","REFRESHRATE_RENDER_ONEVERYFRAME","REFRESHRATE_RENDER_ONEVERYTWOFRAMES","PassPostProcess","ApplyPostProcess","encodedTexture","floatView","int32View","ToHalfFloat","bits","FromHalfFloat","TextureTools","CreateResizedCopy","useBilinearMode","passPostProcess","RGBDTextureTools","expandTexture","expandRGBDTexture","rgbdPostProcess","expandedTexture","outputTextureType","_instanceNumber","GetEnvironmentBRDFTexture","environmentBRDFTexture","previousState","ExpandRGBDTexture","MaterialBRDFDefines","BRDF_V_HEIGHT_CORRELATED","MS_BRDF_ENERGY_CONSERVATION","SPHERICAL_HARMONICS","SPECULAR_GLOSSINESS_ENERGY_CONSERVATION","PBRBRDFConfiguration","_internalMarkAllSubMeshesAsMiscDirty","_useEnergyConservation","DEFAULT_USE_ENERGY_CONSERVATION","useEnergyConservation","_useSmithVisibilityHeightCorrelated","DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED","useSmithVisibilityHeightCorrelated","_useSphericalHarmonics","DEFAULT_USE_SPHERICAL_HARMONICS","useSphericalHarmonics","_useSpecularGlossinessInputEnergyConservation","DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION","useSpecularGlossinessInputEnergyConservation","FileFaceOrientation","worldAxisForNormal","worldAxisForFileX","worldAxisForFileY","CubeMapToSphericalPolynomialTools","rightPromise","leftPromise","upPromise","downPromise","frontPromise","backPromise","down","front","cubeInfo","ConvertCubeMapToSphericalPolynomial","sphericalHarmonics","totalSolidAngle","du","halfTexel","minUV","fileFace","_FileFaces","dataArray","worldDirection","_AreaElement","MAX_HDRI_VALUE","PRESERVE_CLAMPED_COLORS","currentMax","correctionFactor","FromHarmonics","forceSphericalPolynomialsRecompute","ConvertCubeMapTextureToSphericalPolynomial","sphericalPolynomial","MaterialClearCoatDefines","CLEARCOAT","CLEARCOAT_DEFAULTIOR","CLEARCOAT_TEXTURE","CLEARCOAT_TEXTURE_ROUGHNESS","CLEARCOAT_TEXTUREDIRECTUV","CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV","CLEARCOAT_BUMP","CLEARCOAT_BUMPDIRECTUV","CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE","CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL","CLEARCOAT_REMAP_F0","CLEARCOAT_TINT","CLEARCOAT_TINT_TEXTURE","CLEARCOAT_TINT_TEXTUREDIRECTUV","CLEARCOAT_TINT_GAMMATEXTURE","PBRClearCoatConfiguration","_indexOfRefraction","_DefaultIndexOfRefraction","_useRoughnessFromMainTexture","useRoughnessFromMainTexture","_textureRoughness","textureRoughness","_remapF0OnInterfaceChange","remapF0OnInterfaceChange","bumpTexture","_isTintEnabled","isTintEnabled","tintColor","White","tintColorAtDistance","tintThickness","_tintTexture","tintTexture","disableBumpMap","_disableBumpMap","invertNormalMapX","invertNormalMapY","identicalTextures","f0","eta","MaterialIridescenceDefines","IRIDESCENCE","IRIDESCENCE_TEXTURE","IRIDESCENCE_TEXTUREDIRECTUV","IRIDESCENCE_THICKNESS_TEXTURE","IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV","IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE","PBRIridescenceConfiguration","minimumThickness","_DefaultMinimumThickness","maximumThickness","_DefaultMaximumThickness","_thicknessTexture","thicknessTexture","MaterialAnisotropicDefines","ANISOTROPIC","ANISOTROPIC_TEXTURE","ANISOTROPIC_TEXTUREDIRECTUV","ANISOTROPIC_LEGACY","PBRAnisotropicConfiguration","_legacy","legacy","MaterialSheenDefines","SHEEN","SHEEN_TEXTURE","SHEEN_GAMMATEXTURE","SHEEN_TEXTURE_ROUGHNESS","SHEEN_TEXTUREDIRECTUV","SHEEN_TEXTURE_ROUGHNESSDIRECTUV","SHEEN_LINKWITHALBEDO","SHEEN_ROUGHNESS","SHEEN_ALBEDOSCALING","SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE","SHEEN_TEXTURE_ROUGHNESS_IDENTICAL","PBRSheenConfiguration","_linkSheenWithAlbedo","linkSheenWithAlbedo","_albedoScaling","albedoScaling","MaterialSubSurfaceDefines","SUBSURFACE","SS_REFRACTION","SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE","SS_TRANSLUCENCY","SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE","SS_SCATTERING","SS_THICKNESSANDMASK_TEXTURE","SS_THICKNESSANDMASK_TEXTUREDIRECTUV","SS_HAS_THICKNESS","SS_REFRACTIONINTENSITY_TEXTURE","SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV","SS_TRANSLUCENCYINTENSITY_TEXTURE","SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV","SS_REFRACTIONMAP_3D","SS_REFRACTIONMAP_OPPOSITEZ","SS_LODINREFRACTIONALPHA","SS_GAMMAREFRACTION","SS_RGBDREFRACTION","SS_LINEARSPECULARREFRACTION","SS_LINKREFRACTIONTOTRANSPARENCY","SS_ALBEDOFORREFRACTIONTINT","SS_ALBEDOFORTRANSLUCENCYTINT","SS_USE_LOCAL_REFRACTIONMAP_CUBIC","SS_USE_THICKNESS_AS_DEPTH","SS_MASK_FROM_THICKNESS_TEXTURE","SS_USE_GLTF_TEXTURES","PBRSubSurfaceConfiguration","scatteringDiffusionProfile","subSurfaceConfiguration","ssDiffusionProfileColors","_scatteringDiffusionProfileIndex","enableSubSurfaceForPrePass","addDiffusionProfile","volumeIndexOfRefraction","_volumeIndexOfRefraction","_isRefractionEnabled","_isTranslucencyEnabled","_isScatteringEnabled","_internalMarkScenePrePassDirty","isRefractionEnabled","isTranslucencyEnabled","isScatteringEnabled","refractionIntensity","translucencyIntensity","useAlbedoToTintRefraction","useAlbedoToTintTranslucency","_invertRefractionY","_linkRefractionWithTransparency","linkRefractionWithTransparency","useThicknessAsDepth","diffusionDistance","_useMaskFromThicknessTexture","useMaskFromThicknessTexture","_refractionIntensityTexture","refractionIntensityTexture","_translucencyIntensityTexture","translucencyIntensityTexture","_useGltfStyleTextures","useGltfStyleTextures","_getRefractionTexture","refractionIntensityTextureIsThicknessTexture","translucencyIntensityTextureIsThicknessTexture","useOnlyThicknessTexture","thicknessScale","realTimeFiltering","lodBasedMicrosurface","LODBASEDMICROSFURACE","refractionIor","Log2","disableAlphaBlending","PBRMaterialDefines","PBR","NUM_SAMPLES","REALTIME_FILTERING","ALBEDO","GAMMAALBEDO","ALBEDODIRECTUV","AMBIENTINGRAYSCALE","ALPHAFROMALBEDO","ALPHATESTVALUE","RADIANCEOVERALPHA","ALPHAFRESNEL","LINEARALPHAFRESNEL","GAMMAEMISSIVE","REFLECTIVITY","REFLECTIVITY_GAMMA","REFLECTIVITYDIRECTUV","MICROSURFACEFROMREFLECTIVITYMAP","MICROSURFACEAUTOMATIC","MICROSURFACEMAP","MICROSURFACEMAPDIRECTUV","METALLICWORKFLOW","ROUGHNESSSTOREINMETALMAPALPHA","ROUGHNESSSTOREINMETALMAPGREEN","METALLNESSSTOREINMETALMAPBLUE","AOSTOREINMETALMAPRED","METALLIC_REFLECTANCE","METALLIC_REFLECTANCE_GAMMA","METALLIC_REFLECTANCEDIRECTUV","METALLIC_REFLECTANCE_USE_ALPHA_ONLY","REFLECTANCE","REFLECTANCE_GAMMA","REFLECTANCEDIRECTUV","ENVIRONMENTBRDF","ENVIRONMENTBRDF_RGBD","NORMALXYSCALE","GAMMALIGHTMAP","USESPHERICALFROMREFLECTIONMAP","USEIRRADIANCEMAP","USESPHERICALINVERTEX","LODINREFLECTIONALPHA","GAMMAREFLECTION","LINEARSPECULARREFLECTION","RADIANCEOCCLUSION","HORIZONOCCLUSION","USEPHYSICALLIGHTFALLOFF","USEGLTFLIGHTFALLOFF","FORCENORMALFORWARD","SPECULARAA","UNLIT","DEBUGMODE","PBRBaseMaterial","_realTimeFiltering","realTimeFilteringQuality","_realTimeFilteringQuality","_directIntensity","_emissiveIntensity","_environmentIntensity","_specularIntensity","_lightingInfos","_albedoTexture","_ambientTextureStrength","_ambientTextureImpactOnAnalyticalLights","DEFAULT_AO_ON_ANALYTICAL_LIGHTS","_reflectivityTexture","_metallicTexture","_metallic","_metallicF0Factor","_metallicReflectanceColor","_useOnlyMetallicFromMetallicReflectanceTexture","_metallicReflectanceTexture","_reflectanceTexture","_microSurfaceTexture","_ambientColor","_albedoColor","_reflectivityColor","_reflectionColor","_emissiveColor","_microSurface","_useHorizonOcclusion","_useRadianceOcclusion","_useAlphaFromAlbedoTexture","_useMicroSurfaceFromReflectivityMapAlpha","_useRoughnessFromMetallicTextureAlpha","_useRoughnessFromMetallicTextureGreen","_useMetallnessFromMetallicTextureBlue","_useAmbientOcclusionFromMetallicTextureRed","_useAmbientInGrayScale","_useAutoMicroSurfaceFromReflectivityMap","_lightFalloff","LIGHTFALLOFF_PHYSICAL","_useRadianceOverAlpha","_parallaxScaleBias","_alphaCutOff","_useAlphaFresnel","_useLinearAlphaFresnel","_environmentBRDFTexture","_forceIrradianceInFragment","_forceNormalForward","_enableSpecularAntiAliasing","_unlit","_debugMode","debugMode","debugLimit","debugFactor","brdf","clearCoat","iridescence","anisotropy","sheen","subSurface","PBRMATERIAL_OPAQUE","PBRMATERIAL_ALPHATEST","_shouldUseAlphaFromAlbedoTexture","_getReflectionTexture","isMetallicWorkflow","_prepareDefines","LIGHTFALLOFF_STANDARD","LIGHTFALLOFF_GLTF","polynomials","ior","outsideIOR","metallicF90","PBRMATERIAL_ALPHABLEND","PBRMATERIAL_ALPHATESTANDBLEND","PBRMaterial","usePhysicalLightFalloff","useGLTFLightFalloff","ambientTextureStrength","ambientTextureImpactOnAnalyticalLights","metallicF0Factor","metallicReflectanceColor","useOnlyMetallicFromMetallicReflectanceTexture","reflectivityColor","useLightmapAsShadowmap","useAlphaFromAlbedoTexture","forceAlphaTest","useMicroSurfaceFromReflectivityMapAlpha","useRoughnessFromMetallicTextureAlpha","useRoughnessFromMetallicTextureGreen","useMetallnessFromMetallicTextureBlue","useAmbientOcclusionFromMetallicTextureRed","useAmbientInGrayScale","useAutoMicroSurfaceFromReflectivityMap","useObjectSpaceNormalMap","useParallax","useParallaxOcclusion","forceIrradianceInFragment","twoSidedLighting","useAlphaFresnel","useLinearAlphaFresnel","forceNormalForward","enableSpecularAntiAliasing","useHorizonOcclusion","useRadianceOcclusion","unlit","applyDecalMapAfterDetailMap","Light","_range","_inverseSquaredRange","intensityMode","_intensityMode","_computePhotometricScale","_shadowEnabled","_markMeshesAsLightDirty","_includedOnlyMeshes","_hookArrayForIncludedOnly","_excludedMeshes","_hookArrayForExcluded","excludeWithLayerMask","_excludeWithLayerMask","_resyncMeshes","includeOnlyWithLayerMask","_includeOnlyWithLayerMask","_lightmapMode","diffuse","_photometricScale","_shadowGenerators","_excludedMeshesIds","_includedOnlyMeshesIds","_isLight","transferTexturesToEffect","iAsString","needUpdate","_lastUseSpecular","scaledIntensity","getScaledIntensity","bindShadowLight","getTypeID","clonedLight","excludedMeshesIds","includedOnlyMeshesIds","parsedLight","_getPhotometricScale","photometricScale","lightTypeID","photometricMode","apexAngleRadians","_reorderLightsInScene","_renderPriority","HemisphericLight","setDirectionToTarget","_effect","normalizeDirection","transferToNodeMaterialEffect","lightDataUniformName","BlurPostProcess","kernel","_idealKernel","_kernel","_nearestBestKernel","_blockCompilation","packedFloat","_packedFloat","varyingCount","depCount","_staticDefines","N","centerIndex","offsets","weights","totalWeight","_gaussianWeight","linearSamplingWeights","linearSamplingOffsets","linearSamplingMap","sharedCell","weightLinear","offsetLinear","maxVaryingRows","freeVaryingVec2","_glslFloat","idealKernel","sigma","decimalFigures","MirrorTexture","blurRatio","_blurRatio","_preparePostProcesses","adaptiveBlurKernel","_adaptiveBlurKernel","_autoComputeBlurKernel","blurKernel","blurKernelX","blurKernelY","_blurKernelX","_blurKernelY","dw","dh","_updateGammaSpace","_mirrorMatrix","_imageProcessingConfigChangeObserver","saveClipPlane","_sceneUBO","_currentSceneUBO","_blurX","_blurY","_partialLoadFile","loadedFiles","onfinish","onErrorCallBack","_internalCount","_cascadeLoadFiles","files","_cascadeLoadImgs","loadedImages","_partialLoadImg","tokenPendingData","_setCubeMapTextureParams","maxLevel","TEXTURE_MAX_LEVEL","createCubeTextureBase","createPolynomials","lodScale","lodOffset","beforeLoadCubeDataCallback","imageHandler","originalRootUrl","rootUrlWithoutUriParams","onloaddata","loadCubeData","supportCascades","images","imgs","TEXTURE_CUBE_MAP_POSITIVE_Y","TEXTURE_CUBE_MAP_POSITIVE_Z","TEXTURE_CUBE_MAP_NEGATIVE_X","TEXTURE_CUBE_MAP_NEGATIVE_Y","TEXTURE_CUBE_MAP_NEGATIVE_Z","CubeTexture","rotationY","_rotationY","setReflectionTextureMatrix","RotationY","rootUrlKey","extensions","prefiltered","_lodScale","_lodOffset","_extensions","_textureMatrixRefraction","_createPolynomials","isDDS","isEnv","isBasis","_loadTexture","trans","oldTexture","onLoadProcessing","newCubeTexture","BackgroundMaterialDefines","GAMMADIFFUSE","DIFFUSEHASALPHA","REFLECTIONBLUR","REFLECTIONFALLOFF","TEXTURELODSUPPORT","USERGBCOLOR","USEHIGHLIGHTANDSHADOWCOLORS","BACKMAT_SHADOWONLY","NOISE","REFLECTIONBGR","EQUIRECTANGULAR_RELFECTION_FOV","BackgroundMaterial","_perceptualColor","__perceptualColor","_computePrimaryColorFromPerceptualColor","primaryColorShadowLevel","_primaryColorShadowLevel","_computePrimaryColors","primaryColorHighlightLevel","_primaryColorHighlightLevel","reflectionStandardFresnelWeight","reflectionWeight","reflectionReflectance0","StandardReflectance0","reflectionReflectance90","StandardReflectance90","fovMultiplier","_fovMultiplier","primaryColor","reflectionBlur","diffuseTexture","_shadowLights","shadowLights","shadowLevel","sceneCenter","opacityFresnel","reflectionFresnel","reflectionFalloffDistance","reflectionAmount","useRGBColor","enableNoise","useEquirectangularFOV","_shadowOnly","shadowOnly","switchToBGR","_reflectionControls","_white","_primaryShadowColor","_primaryHighlightColor","_opacityFresnel","_reflectionBlur","_useRGBColor","_enableNoise","_primaryColor","CreatePlaneVertexData","_ComputeSides","CreatePlane","_GetDefaultSideOrientation","sourcePlane","PlaneBuilder","GroundMesh","generateOctree","_subdivisionsX","_subdivisionsY","subdivisionsX","subdivisionsY","optimize","chunksCount","octreeBlocksSize","thisAsAny","createOrUpdateSubmeshesOctree","getHeightAtCoordinates","tmpVect","_minX","_maxX","_minZ","_maxZ","_heightQuads","_initHeightQuads","_computeHeightQuads","_getFacetAt","getNormalAtCoordinates","getNormalAtCoordinatesToRef","tmpMat","updateCoordinateHeights","col","_width","_height","quad","slope","facet1","facet2","v4","v1v2","v1v3","v1v4","norm1","norm2","cd","d1","d2","CreateGroundVertexData","CreateTiledGroundVertexData","tileRow","tileCol","tileSize","applyTile","xTileMin","zTileMin","xTileMax","zTileMax","base","rowLength","square","CreateGroundFromHeightMapVertexData","colorFilter","idx1","idx2","idx3","idx4","isVisibleIdx1","isVisibleIdx2","isVisibleIdx3","CreateGround","CreateTiledGround","tiledGround","CreateGroundFromHeightMap","GroundBuilder","CreateBoxVertexData","topBaseAt","bottomBaseAt","topIndex","bottomIndex","basePositions","topFaceBase","bottomFaceBase","topFaceOrder","bottomFaceOrder","scaleArray","accumulator","currentIndex","faceUV","faceColors","totalColors","CreateBox","BoxBuilder","EnvironmentHelper","createGround","groundSize","groundTexture","_GroundTextureCDNUrl","groundOpacity","enableGroundShadow","groundShadowLevel","enableGroundMirror","groundMirrorSizeRatio","groundMirrorBlurKernel","groundMirrorAmount","groundMirrorFresnelWeight","groundMirrorFallOffDistance","groundMirrorTextureType","groundYBias","createSkybox","skyboxSize","skyboxTexture","_SkyboxTextureCDNUrl","skyboxColor","backgroundYRotation","sizeAuto","rootPosition","setupImageProcessing","_EnvironmentTextureCDNUrl","rootMesh","_rootMesh","skybox","_skybox","_skyboxTexture","skyboxMaterial","_skyboxMaterial","_ground","_groundTexture","groundMirror","_groundMirror","groundMirrorRenderList","groundMaterial","_groundMaterial","_errorHandler","_GetDefaultOptions","_setupBackground","_setupImageProcessing","updateOptions","newOptions","setMainColor","_setupEnvironmentTexture","CreateFromPrefilteredData","sceneSize","_getSceneSize","_setupGround","_setupGroundMaterial","_setupGroundDiffuseTexture","_setupGroundMirrorTexture","_setupMirrorInGroundMaterial","_setupSkybox","_setupSkyboxMaterial","_setupSkyboxReflectionTexture","sceneExtends","sceneDiagonal","sceneDiagonalLenght","wrapping","gammaGround","FreeCameraKeyboardMoveInput","keysUpward","keysDownward","rotationSpeed","keysRotateLeft","keysRotateRight","keysRotateUp","keysRotateDown","_localDirection","_getLocalRotation","FreeCameraMouseInput","touchEnabled","angularSensibility","onPointerMovedObservable","_allowCameraRotation","_activePointerId","_onMouseMove","BaseCameraMouseWheelInput","wheelPrecisionX","wheelPrecisionY","wheelPrecisionZ","onChangedObservable","_wheelDeltaX","_wheelDeltaY","_wheelDeltaZ","_ffMultiplier","_normalize","wheelDeltaX","wheelDeltaY","wheelDeltaZ","_CameraProperty","FreeCameraMouseWheelInput","_moveRelative","_rotateRelative","_moveScene","_wheelXAction","MoveRelative","_wheelXActionCoordinate","_wheelYAction","_wheelYActionCoordinate","_wheelZAction","_wheelZActionCoordinate","wheelXMoveRelative","wheelYMoveRelative","wheelZMoveRelative","wheelXRotateRelative","RotateRelative","wheelYRotateRelative","wheelZRotateRelative","wheelXMoveScene","MoveScene","wheelYMoveScene","wheelZMoveScene","_updateCamera","cameraTransformMatrix","transformedDirection","_updateCameraProperty","cameraProperty","FreeCameraTouchInput","allowMouse","touchAngularSensibility","touchMoveSensibility","singleFingerRotate","_offsetX","_offsetY","_pointerPressed","_isSafari","previousPosition","isMouseEvent","FreeCameraInputsManager","_mouseInput","_mouseWheelInput","addMouse","removeMouse","removeMouseWheel","addTouch","FreeCamera","mouse","applyGravity","_needMoveForGravity","_oldPosition","_diffPosition","_collideWithWorld","actualDisplacement","needMoveForGravity","addDeviceOrientation","_deviceOrientationInput","FreeCameraDeviceOrientationInput","rej","gotValue","eventHandler","DeviceOrientationEvent","requestPermission","_screenOrientationAngle","_screenQuaternion","_beta","_gamma","_onDeviceOrientationChangedObservable","_orientationChanged","_deviceOrientation","SmoothAngleChange","_constantTranform","DeviceOrientationCamera","_tmpDragQuaternion","_disablePointerInputWhenUsingDeviceOrientation","_dragFactor","_quaternionCache","_initialQuaternion","FromEulerAnglesToRef","disablePointerInputWhenUsingDeviceOrientation","enableHorizontalDragging","dragFactor","resetToCurrentRotation","axisName","VRCameraMetrics","compensateDistortion","multiviewEnabled","hResolution","vResolution","postProcessScaleFactor","vScreenSize","eyeToScreenDistance","leftHMatrix","hScreenSize","lensSeparationDistance","rightHMatrix","leftPreViewMatrix","interpupillaryDistance","rightPreViewMatrix","vScreenCenter","distortionK","chromaAbCorrection","lensCenterOffset","VRDistortionCorrectionPostProcess","isRightEye","_isRightEye","_distortionFactors","_postProcessScaleFactor","_lensCenterOffset","_scaleIn","_scaleFactor","_lensCenter","MultiviewRenderTarget","bindMultiviewFramebuffer","createMultiviewUbo","colorTexture","texStorage3D","multiviewTexture","ext","framebufferTextureMultisampleMultiviewOVR","framebufferTextureMultiviewOVR","bindSpaceWarpFramebuffer","_spaceWarpTexture","spaceWarpTexture","_resizeOrCreateMultiviewTexture","currentCreateSceneUniformBuffer","_transformMatrixR","VRMultiviewToSingleviewPostProcess","scaleFactor","setVRRigMode","metrics","vrCameraMetrics","GetDefault","VRDeviceOrientationFreeCamera","Gamepad","isConnected","_isConnected","browserGamepad","leftStickX","leftStickY","rightStickX","rightStickY","_leftStick","_rightStick","_invertLeftStickY","GAMEPAD","_leftStickAxisX","_leftStickAxisY","_rightStickAxisX","_rightStickAxisY","onleftstickchanged","_onleftstickchanged","onrightstickchanged","_onrightstickchanged","leftStick","newValues","rightStick","GENERIC","XBOX","POSE_ENABLED","DUALSHOCK","GenericPad","onbuttondown","_onbuttondown","onbuttonup","_onbuttonup","onButtonDownObservable","onButtonUpObservable","_buttons","_setButtonValue","buttonIndex","PoseEnabledControllerType","Xbox360Button","Xbox360Dpad","PoseEnabledControllerHelper","vrGamepad","_ControllerFactories","canCreate","_DefaultControllerFactory","PoseEnabledController","_disableTrackPosition","fixedPosition","_trackPosition","_calculatedPosition","isXR","_deviceRoomPosition","_deviceRoomRotationQuaternion","deviceRotationQuaternion","deviceScaleFactor","_maxRotationDistFromHeadset","_draggedRoomRotation","_leftHandSystemQuaternion","_deviceToWorld","_pointingPoseNode","_workingMatrix","_meshAttachedObservable","controllerType","_calculatedRotation","_updatePoseAndMesh","pose","updateFromDevice","_computeDevicePosition","distanceAway","rotationAmount","poseData","rawPose","attachToMesh","_poseControlledCamera","parents","attachToPoseControlledCamera","forwardWorld","setWebVRRigMode","vrDisplay","leftEye","getEyeParameters","rightEye","specs","frameData","parentCamera","POINTING_POSE","_vrExclusivePointerMode","_vrSupported","onVRDisplayChangedObservable","onVRRequestPresentComplete","onVRRequestPresentStart","isVRDevicePresent","_vrDisplay","getVRDevice","initWebVRAsync","eventArgs","vrSupported","_webVRInitPromise","_onVrDisplayConnect","_onVrDisplayDisconnect","_onVrDisplayPresentChange","isPresenting","_getVRDisplaysAsync","getVRDisplays","enableVR","onResolved","_onVRFullScreenTriggered","onRejected","presentationAttributes","highRefreshRate","vrPresentationAttributes","foveationLevel","useMultiview","requestPresent","_oldSize","_oldHardwareScaleFactor","exitPresent","_onVRDisplayPointerRestricted","_onVRDisplayPointerUnrestricted","submitFrame","WebVRFreeCamera","_webVROptions","_vrDevice","_specsVersion","_attached","_descendants","_standingMatrix","_worldToDevice","controllers","onControllersAttachedObservable","onControllerMeshLoadedObservable","onPoseUpdatedFromDeviceObservable","_poseSet","rigParenting","_defaultHeight","_detachIfAttached","_workingVector","_oneVector","_tmpMatrix","defaultHeight","trackPosition","controllerMeshes","defaultLightingOnControllers","_onVREnabled","success","initControllers","_frameData","VRFrameData","isController","controller","deviceDistanceToRoomGround","useStandingMatrix","stageParameters","sittingToStandingTransform","useStandingMatrixAsync","supported","_updateCacheWhenTrackingDisabledObserver","getControllerByName","hand","leftController","_leftController","rightController","_rightController","getFrameData","gamepadManager","onGamepadConnectedObservable","_onGamepadConnectedObserver","onGamepadDisconnectedObservable","_onGamepadDisconnectedObserver","resetPose","_correctPositionIfNotTrackPosition","isViewMatrix","_updateCacheCalled","viewArray","leftViewMatrix","rightViewMatrix","depthNear","depthFar","projectionArray","leftProjectionMatrix","rightProjectionMatrix","webVrController","defaultModel","controllerIndex","initControllerMesh","loadedMesh","_lightOnControllers","activateLightOnSubMeshes","firstViveWandDetected","VIVE","WebVRController","onButtonStateChange","_onButtonStateChange","_defaultModel","onTriggerStateChangedObservable","onMainButtonStateChangedObservable","onSecondaryButtonStateChangedObservable","onPadStateChangedObservable","onPadValuesChangedObservable","pad","_changes","pressChanged","touchChanged","valueChanged","newState","pressed","touched","_checkChanges","_handleButtonChange","Xbox360Pad","xboxOne","_leftTrigger","_rightTrigger","onPadDownObservable","onPadUpObservable","_buttonA","_buttonB","_buttonX","_buttonY","_buttonBack","_buttonStart","_buttonLB","_buttonRB","_buttonLeftStick","_buttonRightStick","_dPadUp","_dPadDown","_dPadLeft","_dPadRight","_isXboxOnePad","onlefttriggerchanged","_onlefttriggerchanged","onrighttriggerchanged","_onrighttriggerchanged","leftTrigger","rightTrigger","ondpaddown","_ondpaddown","ondpadup","_ondpadup","buttonType","_setDPadValue","buttonA","A","buttonB","B","buttonX","buttonY","buttonStart","Start","buttonBack","Back","buttonLB","LB","buttonRB","RB","buttonLeftStick","LeftStick","buttonRightStick","RightStick","dPadUp","dPadDown","dPadLeft","dPadRight","premulAlpha","forceBindTexture","allowGPUOptimization","glformat","DynamicTexture","_canvas","_recreate","scaleTo","fillRect","drawText","fillStyle","textSize","measureText","fillText","_IsCanvasElement","ImageProcessingPostProcess","doNotBuild","fromLinearSpace","_fromLinearSpace","FROMLINEARSPACE","DualShockButton","DualShockDpad","DualShockPad","_buttonCross","_buttonCircle","_buttonSquare","_buttonTriangle","_buttonShare","_buttonOptions","_buttonL1","_buttonR1","buttonCross","buttonCircle","Circle","buttonSquare","Square","buttonTriangle","Triangle","buttonOptions","Options","buttonShare","Share","buttonL1","L1","buttonR1","R1","GamepadManager","_babylonGamepads","_oneGamepadConnected","_isMonitoring","_gamepadEventSupported","_gamepadSupport","_onGamepadConnectedEvent","newGamepad","_addNewGamepad","_startMonitoringGamepads","_onGamepadDisconnectedEvent","disconnectedGamepad","_updateGamepadObjects","getGamepadByType","_stopMonitoringGamepads","dualShock","InitiateController","_checkGamepadsStatus","_loggedErrors","FreeCameraGamepadInput","gamepadAngularSensibility","gamepadMoveSensibility","deadzoneDelta","_yAxisScale","_cameraTransform","_deltaTransform","_vector3","_vector2","invertYAxis","lsValues","rsValues","ArcRotateCameraGamepadInput","gamepadRotationSensibility","normalizedRX","normalizedRY","normalizedLY","_gamepadManager","GamepadSystemSceneComponent","addGamepad","_beforeCameraUpdate","_staticOffsetValueQuaternion","_staticOffsetValueVector3","_staticOffsetValueVector2","_staticOffsetValueSize","_staticOffsetValueColor3","RuntimeAnimation","_currentFrame","_weight","_currentValue","targetPath","_targetPath","_currentActiveTarget","isAdditive","_host","_originalValue","_originalBlendValue","_offsetsCache","_highLimitsCache","_stopped","_blendingFactor","_directTarget","_absoluteFrameOffset","_previousElapsedTime","_previousAbsoluteFrame","_targetIsArray","_animation","_activeTargets","_animationState","_getCorrectLoopMode","_minFrame","_maxFrame","_minValue","_maxValue","newKey","_preparePath","_getOriginalValues","_clone","_enableBlending","restoreOriginal","_setValue","isDone","setValue","getRestPose","_UniversalLerp","_registerTargetForLateAnimationBinding","goToFrame","onlyOnce","_prepareForSpeedRatioChange","newSpeedRatio","newAbsoluteFrame","elapsedTimeSinceAnimationStart","frameRange","absoluteFrame","keyOffset","fromValue","toValue","syncRoot","masterFrame","fromFrame","toFrame","_onLoop","Bone","_matrix","_compose","_needToCompose","_markAsDirtyAndDecompose","parentBone","restMatrix","bindMatrix","_index","_scalingDeterminant","_needToDecompose","_linkedTransformNode","_waitingTransformNodeId","_restMatrix","_bindMatrix","_absoluteMatrix","_absoluteBindMatrix","_absoluteInverseBindMatrix","_finalMatrix","_updateAbsoluteBindMatrices","getParent","updateAbsoluteBindMatrices","getLocalMatrix","getBindMatrix","getBaseMatrix","getRestMatrix","setRestMatrix","setRestPose","getBindPose","setBindMatrix","setBindPose","returnToRest","localScaling","localRotation","getAbsoluteInverseBindMatrix","getInvertedAbsoluteTransform","getAbsoluteMatrix","getAbsoluteTransform","linkTransformNode","_numBonesWithLinkedTransformNode","getTransformNode","_decompose","_localPosition","_markAsDirtyAndCompose","getRotation","setRotation","_localRotation","getScale","setScale","_localScaling","updateLocalMatrix","updateChildren","_markAsDirty","tNode","translationMode","computeAbsoluteMatrices","_TmpMats","_TmpVecs","scaleChildren","locMat","scaleMat","cm","getScaleToRef","setYawPitchRoll","_TmpQuat","rotMatInv","_getAbsoluteInverseMatrixUnscaledToRef","_rotateWithMatrix","rmat","setAxisAngle","setRotationMatrix","rotMat2","lmat","lx","ly","lz","parentScale","parentScaleInv","getPosition","getPositionToRef","getAbsolutePositionToRef","poseMatrix","computeAbsoluteTransforms","getRotationToRef","getRotationQuaternionToRef","amat","getAbsolutePositionFromLocal","getAbsolutePositionFromLocalToRef","getLocalPositionFromAbsolute","getLocalPositionFromAbsoluteToRef","setCurrentPoseAsRest","Animatable","_syncRoot","_speedRatio","_goToFrame","loopAnimation","onAnimationLoop","playOrder","_localDelayOffset","_pausedDelay","_manualJumpDelay","_paused","_frameToSyncFromJump","disposeOnEnd","animationStarted","onAnimationLoopObservable","appendAnimations","syncWith","getAnimations","newRuntimeAnimation","getAnimationByTargetProperty","getRuntimeAnimationByTargetProperty","disableBlending","fps","pause","restart","_raiseOnAnimationEnd","useGlobalSplice","waitAsync","running","isRunning","animationTime","_processLateAnimationBindings","sortActiveAnimatables","beginWeightedAnimation","returnedAnimatable","stopCurrent","shouldRunTargetAnimations","beginHierarchyAnimation","getAnimatableByTarget","getAllAnimatablesByTarget","_lateAnimationHolders","totalAdditiveWeight","additiveAnimations","_processLateAnimationBindingsForMatrices","holder","normalizer","finalPosition","finalScaling","finalQuaternion","originalAnimation","skipOverride","animIndex","currentPosition","currentScaling","currentQuaternion","_processLateAnimationBindingsForQuaternions","refQuaternion","cumulativeQuaternion","quaternions","cumulativeAmount","matrixDecomposeMode","finalValue","copyAnimationRange","rangeName","frameOffset","rescaleAsRequired","skelDimensionsRatio","sourceRange","sourceKeys","sourceBoneLength","sourceParent","parentScalingReqd","parentRatio","dimensionsScalingReqd","destKeys","origTranslation","WebXRLayerWrapper","isFixedFoveationSupported","layerType","fixedFoveation","getWidth","getHeight","createRenderTargetTextureProvider","WebXRLayerRenderTargetTextureProvider","layerWrapper","_renderTargetTextures","XRWebGLBinding","_destroyRenderTargetTexture","getFramebufferDimensions","_framebufferDimensions","WebXRWebGLLayerWrapper","sessionManager","WebXRWebGLLayerRenderTargetTextureProvider","_layer","trySetViewportForView","xrViewport","getViewport","getRenderTargetTextureForEye","layerWidth","layerHeight","_rtt","getRenderTargetTextureForView","WebXRManagedOutputCanvasOptions","canvasOptions","framebufferScaleFactor","newCanvasCssStyle","WebXRManagedOutputCanvas","_xrSessionManager","GetDefaults","xrLayer","_xrLayerWrapper","onXRLayerInitObservable","canvasElement","_setManagedOutputCanvas","cssText","onXRSessionInit","_addCanvas","onXRSessionEnded","_removeCanvas","xrSession","createLayer","XRWebGLLayer","canvasContext","makeXRCompatible","_setCanvasSize","_originalCanvasSize","offsetWidth","offsetHeight","NativeXRLayerWrapper","NativeXRLayerRenderTargetTextureProvider","_nativeRTTProvider","xr","getNativeRenderTargetProvider","session","_nativeLayer","getRenderTargetForEye","NativeXRRenderTarget","_nativeRenderTarget","getWebXRRenderTarget","initializeXRLayerAsync","WebXRSessionManager","currentTimestamp","defaultHeightCompensation","onXRFrameObservable","onXRReferenceSpaceChanged","inXRFrameLoop","inXRSession","_onEngineDisposedObserver","referenceSpace","_referenceSpace","newReferenceSpace","sessionMode","_sessionMode","exitXRAsync","_baseLayerRTTProvider","_xrNavigator","native","initializeAsync","initializeSessionAsync","xrSessionMode","xrSessionInit","requestSession","isNative","_baseLayerWrapper","once","isSessionSupportedAsync","IsSessionSupportedAsync","resetReferenceSpace","baseReferenceSpace","runXRRenderLoop","timestamp","xrFrame","setReferenceSpaceTypeAsync","referenceSpaceType","requestReferenceSpace","rejectionReason","heightCompensation","XRRigidTransform","getOffsetReferenceSpace","viewerReferenceSpace","updateRenderStateAsync","updateRenderState","_setBaseLayerWrapper","baseLayerWrapper","_getBaseLayerWrapper","baseLayer","functionToUse","isSessionSupported","supportsSession","currentFrameRate","supportedFrameRates","updateTargetFrameRate","rate","runInXRFrame","ignoreIfNotInSession","enabledFeatures","WebXRState","WebXRTrackingState","CreateCylinderVertexData","hasRings","enclose","surfaceNb","angleStep","ringVertex","ringNormal","ringFirstVertex","ringFirstNormal","quadNormal","ringIdx","cs","i2","i3","createCylinderCap","isTop","circleVector","vbase","textureScale","textureCoordinate","CreateCylinder","cylinder","CylinderBuilder","CreateTorusVertexData","outerAngle","innerAngle","dx","dy","nextI","nextJ","CreateTorus","torus","VRExperienceHelperGazer","gazeTrackerToClone","_pointerDownOnMeshAsked","_isActionableMesh","_teleportationRequestInitiated","_teleportationBackRequestInitiated","_rotationRightAsked","_rotationLeftAsked","_dpadPressed","_activePointer","_IdCounter","_gazeTracker","targetMat","_getForwardRay","_selectionPointerDown","_currentHit","_selectionPointerUp","_activatePointer","_deactivatePointer","_updatePointerDistance","_interactionsEnabled","_teleportationEnabled","VRExperienceHelperControllerGazer","webVRController","_laserPointer","laserPointerMaterial","preloadMesh","preloadPointerPose","_setLaserPointerParent","_meshAttachedObserver","_setLaserPointerColor","_setLaserPointerLightingDisabled","disabled","makeNotPick","meshChildren","laserParent","VRExperienceHelperCameraGazer","_getCamera","VRExperienceHelper","onEnteringVR","onEnteringVRObservable","onExitingVR","onExitingVRObservable","onControllerMeshLoaded","teleportationTarget","_teleportationTarget","_isDefaultTeleportationTarget","gazeTrackerMesh","_cameraGazer","leftControllerGazeTrackerMesh","rightControllerGazeTrackerMesh","displayGaze","_displayGaze","displayLaserPointer","_displayLaserPointer","deviceOrientationCamera","_deviceOrientationCamera","currentVRCamera","_webVRready","_webVRCamera","vrDeviceOrientationCamera","_vrDeviceOrientationCamera","vrButton","_btnVR","webVROptions","_webVRsupported","_webVRrequesting","_webVRpresenting","_fullscreenVRpresenting","enableGazeEvenWhenNoPointerLock","exitVROnDoubleTap","onAfterEnteringVRObservable","_useCustomVRButton","_teleportationRequested","_teleportActive","_floorMeshesCollection","_teleportationMode","TELEPORTATIONMODE_CONSTANTTIME","_teleportationTime","_teleportationSpeed","_rotationAllowed","_teleportBackwardsVector","_teleportationFillColor","_teleportationBorderColor","_rotationAngle","_haloCenter","_padSensibilityUp","_padSensibilityDown","_gazeColor","_laserColor","_pickedLaserColor","_pickedGazeColor","onNewMeshSelected","onMeshSelectedWithController","onNewMeshPicked","onBeforeCameraTeleport","onAfterCameraTeleport","onSelectedMeshUnselected","teleportationEnabled","_teleportationInitialized","_interactionsRequested","updateGazeTrackerScale","updateGazeTrackerColor","updateControllerLaserColor","requestPointerLockOnFullScreen","xrTestDone","_onResize","_moveButtonToBottomRight","exitVR","_inputElement","offsetTop","offsetLeft","_updateButtonVisibility","_cachedAngularSensibility","_beforeRender","_castRayAndSelectObject","_noControllerIsActive","_onNewGamepadConnected","stickValues","_checkTeleportWithRay","_checkTeleportBackwards","_checkRotate","buttonPressed","_tryEnableInteractionOnController","_enableInteractionOnController","_enableTeleportationOnController","_onNewGamepadDisconnected","_workingQuaternion","useXR","createFallbackVRDeviceOrientationFreeCamera","createDeviceOrientationCamera","laserToggle","useCustomVRButton","customVRButton","rayLength","_rayLength","_hasEnteredVR","_existingCamera","createDefaultXRExperienceAsync","floorMeshes","baseExperience","onStateChangedObservable","ENTERING_XR","pointerSelection","EXITING_XR","IN_XR","NOT_IN_XR","_completeVRInit","vrDeviceOrientationCameraMetrics","title","css","SVGSVGElement","createTextNode","isInVRMode","enterVR","_displayVRButton","_onVRDisplayChangedBind","_onVRDisplayChanged","_onVrDisplayPresentChangeBind","_onVRRequestPresentStart","_onVRRequestPresentComplete","_onDefaultMeshLoaded","_circleEase","_teleportationEasing","enableTeleportation","wasPresenting","rect","_btnVRDisplayed","enterXRAsync","FromRotationMatrix","currentYRotation","currentGlobalRotation","enableInteractions","raySelectionPredicate","_floorMeshName","meshSelectionPredicate","_raySelectionPredicate","_isTeleportationFloor","addFloorMesh","floorMesh","removeFloorMesh","vrTeleportationOptions","floorMeshName","teleportation","waitForXr","teleportationMode","teleportationTime","teleportationSpeed","_postProcessMove","_createTeleportationCircles","stateObject","gazer","teleportCamera","_rotateCamera","dynamicTexture","beginPath","lineWidth","strokeStyle","stroke","teleportationCircleMaterial","animationInnerCircle","_hideTeleportationTarget","_displayTeleportationTarget","animationRotation","animationRotationKeys","animationPP","vignetteWeightKeys","animationPP2","vignetteStretchKeys","_moveTeleportationSelectorTo","pickNormal","_convertNormalToDirectionOfRay","lastFrame","TELEPORTATIONMODE_CONSTANTSPEED","dist","animationCameraTeleportation","animationCameraTeleportationKeys","midFrame","multiplier","deltaFighting","_currentMeshSelected","_notifySelectedMeshUnselected","changeGazeColor","changeLaserColor","gazerAsControllerGazer","setLaserColor","pickedColor","setLaserLightingState","setGazeColor","DDSD_MIPMAPCOUNT","DDPF_LUMINANCE","FourCCToInt32","FOURCC_DXT1","FOURCC_DXT3","FOURCC_DXT5","FOURCC_DX10","DDSTools","header","extendedHeader","headerLengthInt","mipmapCount","fourCC","dxgiFormat","isFourCC","isRGB","isLuminance","dataOffset","destArray","srcData","srcPos","StoreLODInAlphaChannel","rOffset","gOffset","bOffset","aOffset","byteArray","_ExtractLongWordOrder","loadMipmaps","lodIndex","currentFace","destTypeMustBeFilterable","sphericalPolynomialFaces","mip","internalCompressedFormat","blockBytes","bpp","computeFormats","startFace","floatArray","_GetFloatAsUIntRGBAArrayBuffer","_GetFloatRGBAArrayBuffer","_GetHalfFloatAsUIntRGBAArrayBuffer","_GetHalfFloatAsFloatRGBAArrayBuffer","floatAvailable","halfFloatAvailable","destType","dataGetter","dataGetterPolynomial","_GetFloatAsHalfFloatRGBAArrayBuffer","_GetHalfFloatRGBAArrayBuffer","_GetRGBArrayBuffer","_GetRGBAArrayBuffer","unpackAlignment","unpaddedRowSize","_GetLuminanceArrayBuffer","minLODIndex","maxLODIndex","mipmapIndex","glTextureFromLod","UploadDDSLevels","lodTexture","_DDSTextureLoader","GetDDSInfo","DefaultEnvironmentTextureImageType","MagicBytes","GetEnvInfo","manifestString","charCode","manifest","normalizeEnvInfo","specularDataPosition","imageType","_CreateEnvTextureIrradiance","polynmials","CreateImageDataArrayBufferViews","specularInfo","mipmapsCount","mipmaps","imageInfo","UploadEnvLevelsAsync","UploadLevelsAsync","_OnImageReadyAsync","generateNonLODTextures","lodTextures","cubeRtt","tempTexture","ImageBitmap","IsExponentOfTwo","ILog2","mipSlices","promises","UploadEnvSpherical","irradianceInfo","irradiance","EnvironmentTextureTools","CreateEnvTextureAsync","sphericalPolynomialPromise","cubeWidth","specularTextures","faceWidth","faceDataFloat","floatData","EncodeTextureToRGBD","rgbdEncodedData","imageEncodedData","imageQuality","infoString","infoBuffer","infoView","strLen","totalSize","finalBuffer","finalBufferView","setUint8","_ENVTextureLoader","KhronosTextureContainer","facesExpected","isInvalid","IsValid","dataSize","headerDataView","littleEndian","glType","glTypeSize","glFormat","glInternalFormat","glBaseInternalFormat","pixelWidth","pixelHeight","pixelDepth","numberOfArrayElements","numberOfFaces","numberOfMipmapLevels","bytesOfKeyValueData","loadType","COMPRESSED_2D","uploadLevels","_upload2DCompressedLevels","HEADER_LEN","imageSize","identifier","COMPRESSED_3D","TEX_2D","TEX_3D","AutoReleaseWorkerPool","WorkerPool","workers","_pendingActions","_workerInfos","worker","workerPromise","idle","workerInfo","terminate","_executeOnIdleWorker","nextAction","maxWorkers","createWorkerAsync","DefaultOptions","_maxWorkers","_createWorkerAsync","idleTimeElapsedBeforeRelease","SourceTextureFormat","TranscodeTarget","EngineFormat","SceneLoaderAnimationGroupLoadingMode","getAbsoluteUrlOrNull","applyConfig","urls","wasmUASTCToASTC","KTX2DECODER","LiteTranscoder_UASTC_ASTC","WasmModuleURL","wasmUASTCToBC7","LiteTranscoder_UASTC_BC7","wasmUASTCToRGBA_UNORM","LiteTranscoder_UASTC_RGBA_UNORM","wasmUASTCToRGBA_SRGB","LiteTranscoder_UASTC_RGBA_SRGB","wasmUASTCToR8_UNORM","LiteTranscoder_UASTC_R8_UNORM","wasmUASTCToRG8_UNORM","LiteTranscoder_UASTC_RG8_UNORM","jsMSCTranscoder","MSCTranscoder","JSModuleURL","wasmMSCTranscoder","wasmZSTDDecoder","ZSTDDecoder","KhronosTextureContainer2","hardwareConcurrency","numWorkers","_WorkerPoolPromise","_DecoderModulePromise","jsDecoderModule","URLConfig","Worker","workerContent","workerFunc","workerBlobUrl","onMessage","postMessage","LoadScriptAsync","UseFromWorkerThread","WASMMemoryManager","LoadBinariesFromCurrentThread","KTX2Decoder","DefaultNumWorkers","_Initialize","uploadAsync","compressedTexturesCaps","workerPool","decodedData","msg","DefaultDecoderOptions","_getKTX2DecoderOptions","dataCopy","decoder","transcodedFormat","isInGammaSpace","transcoderName","isUncompressedFormat","mipmap","ktx2Decoder","onmessage","GetDefaultNumWorkers","DefaultKTX2DecoderOptions","_useRGBAIfOnlyBC1BC3AvailableWhenUASTC","_ktx2DecoderOptions","useRGBAIfASTCBC7NotAvailableWhenUASTC","_useRGBAIfASTCBC7NotAvailableWhenUASTC","useRGBAIfOnlyBC1BC3AvailableWhenUASTC","forceRGBA","_forceRGBA","forceR8","_forceR8","forceRG8","_forceRG8","bypassTranscoders","_bypassTranscoders","transcodeFormatDecisionTree","UASTC","transcodeFormat","BC1_RGB","BC3_RGBA","yes","RGBA32","engineFormat","RGBA8Format","roundToMultiple4","_KTXTextureLoader","ktx","mappedFormat","mapSRGBToLinear","WebXRCamera","_firstFrame","_referenceQuaternion","_referencedPosition","_trackingState","NOT_TRACKING","onTrackingStateChanged","compensateOnFirstFrame","_rotate180","_updateNumberOfRigCameras","_updateFromXRSession","_updateReferenceSpace","_setTrackingState","realWorldHeight","basePose","getViewerPose","_updateForDualEyeDebugging","setTransformationFromNonVRCamera","otherCamera","resetToBaseReferenceSpace","yRotation","_lastXRViewerPose","emulatedPosition","TRACKING_LOST","TRACKING","xrRenderState","views","currentRig","viewCount","removedCamera","referencedMat","poseMat","transformMat","_ScaleReadOnly","WebXRFeatureName","ANCHOR_SYSTEM","BACKGROUND_REMOVER","HIT_TEST","MESH_DETECTION","PHYSICS_CONTROLLERS","PLANE_DETECTION","POINTER_SELECTION","TELEPORTATION","FEATURE_POINTS","HAND_TRACKING","IMAGE_TRACKING","NEAR_INTERACTION","DOM_OVERLAY","MOVEMENT","LIGHT_ESTIMATION","EYE_TRACKING","WALKING_LOCOMOTION","LAYERS","DEPTH_SENSING","SPACE_WARP","WebXRFeaturesManager","getEnabledFeatures","featureName","feature","featureImplementation","disableAutoAttach","attachFeature","detachFeature","constructorFunction","stable","_AvailableFeatures","latest","xrSessionManager","disableFeature","Name","enableFeature","moduleOptions","attachIfPossible","required","versionToLoad","GetStableVersionOfFeature","GetLatestVersionOfFeature","conflictingFeature","_ConflictingFeatures","constructFunction","ConstructFeature","constructed","dependentsFound","isCompatible","getEnabledFeature","nativeName","xrNativeFeatureName","requiredFeatures","optionalFeatures","getXRSessionInitExtension","extended","TouchCamera","touch","UniversalCamera","WebXRExperienceHelper","_nonVRCamera","_attachedToElement","_spectatorCamera","_originalSceneAutoClear","_supported","_spectatorMode","_lastTimestamp","onInitialXRPoseSetObservable","featuresManager","helper","_setState","sessionCreationOptions","_extendXRSessionInitObject","_nonXRToXRCamera","enableSpectatorMode","_switchSpectatorMode","disableSpecatatorMode","preferredCameraIndex","updateSpectatorCamera","onStateChanged","WebXRControllerComponent","_buttonIndex","_axesIndices","_axes","_hasChanges","_pressed","_touched","onAxisValueChangedObservable","onButtonStateChangedObservable","isAxes","isButton","nativeController","buttonUpdated","axesUpdate","BUTTON_TYPE","SQUEEZE_TYPE","THUMBSTICK_TYPE","TOUCHPAD_TYPE","TRIGGER_TYPE","SceneLoader","_RegisteredPlugins","registeredPlugin","GetDefaultPlugin","canDirectLoad","sceneFilename","queryStringPosition","dotPosition","_GetPluginForExtension","fileInfo","errorMessage","rawData","pluginExtension","directLoad","_GetDirectLoad","_GetPluginForDirectLoad","_GetPluginForFilename","isBinary","createPlugin","OnPluginActivatedObservable","dataCallback","pluginDisposed","manifestChecked","errorCallback","canUseOfflineSupport","exceptionFound","sceneFile","filename","GetFilename","GetFolderPath","meshNames","_GetFileInfo","loadingToken","disposeHandler","_FormatErrorMessage","progressHandler","successHandler","_LoadData","rewriteRootURL","importMesh","syncedPlugin","loadingPluginName","importMeshAsync","ImportMesh","Append","Load","_ShowingLoadingScreen","loadAsync","assets","loadAssetContainer","assetContainer","populateRootNodes","loadAssetContainerAsync","LoadAssetContainer","overwriteAnimations","animationGroupLoadingMode","Clean","targetConverter","animationGroup","Stop","Sync","NoSync","startingIndexForNewAnimatables","mergeAnimationsTo","ImportAnimations","NO_LOGGING","MINIMAL_LOGGING","SUMMARY_LOGGING","DETAILED_LOGGING","WebXRAbstractMotionController","layout","gamepadObject","handedness","_doNotLoadControllerMesh","_controllerCache","_initComponent","componentDef","components","gamepadIndices","_modelReady","disableAnimation","onModelLoadedObservable","getComponentIds","getComponent","getAllComponentsOfType","getComponentOfType","getMainComponent","selectComponentId","useGeneric","_getModelLoadingConstraints","loadingParams","_getGenericFilenameAndPath","_getFilenameAndPath","meshesLoaded","_getGenericParentMesh","_setRootMesh","_processLoadedModel","found","profileId","updateFromXRFrame","updateModel","handness","pulse","hapticActuatorIndex","hapticActuators","_getChildByName","_getImmediateChildByName","_lerpTransform","axisMap","axisValue","fixValueCoordinates","minMesh","maxMesh","valueMesh","lerpValue","_updateModel","WebXRGenericTriggerMotionController","GenericTriggerLayout","ProfileId","rootNodeName","visualResponses","gamepadMapping","assetPath","none","CreateSphereVertexData","diameterX","diameterY","diameterZ","dedupTopBottomIndices","totalZRotationSteps","totalYRotationSteps","zRotationStep","normalizedZ","angleZ","yRotationStep","normalizedY","angleY","rotationZ","RotationZ","afterRotZ","firstIndex","CreateSphere","SphereBuilder","WebXRProfiledMotionController","xrInput","_profile","_repositoryUrl","controllerCache","layouts","_buttonMeshMapping","_touchDots","visResKey","glbLoaded","IsPluginForExtensionAvailable","componentInLayout","mainMesh","states","visualResponseKey","visResponse","valueNodeProperty","valueNodeName","minNodeName","maxNodeName","nameOfMesh","touchPointNodeName","_xrFrame","componentProperty","WebXRMotionControllerManager","_ProfilesList","_ProfileLoadingPromises","RegisterFallbacksForProfileId","returnArray","_Fallbacks","forceProfile","profileArray","profiles","windowsMRIdx","UseOnlineRepository","firstFunction","PrioritizeOnlineRepository","_LoadProfileFromRepository","_LoadProfilesFromAvailableControllers","secondFunction","_AvailableControllers","LoadFileAsync","BaseRepositoryUrl","UpdateProfilesList","profilesList","profileToLoad","profile","DisableControllerCache","FindFallbackWithProfileId","constructionFunction","RegisterController","DefaultFallbacks","idCount","WebXRInputSource","inputSource","_tmpVector","_disposed","onMeshLoadedObservable","onMotionControllerInitObservable","targetRayMode","gripSpace","grip","GetMotionControllerWithXRInput","forceControllerProfile","motionController","doNotLoadControllerMesh","loadModel","disableMotionControllerAnimation","getWorldPointerRayToRef","gripIfAvailable","xrCamera","getPose","targetRaySpace","_lastXRPose","WebXRInput","onControllerAddedObservable","onControllerRemovedObservable","_onInputSourcesChange","_addAndRemoveControllers","added","_sessionEndedObserver","_sessionInitObserver","_frameObserver","customControllersRepositoryURL","disableOnlineControllerRepository","addInputs","removeInputs","sources","controllerOptions","forceInputProfile","doNotLoadControllerMeshes","disableControllerAnimation","keepControllers","removedControllers","ClearControllerCache","WebXRAbstractFeature","_removeOnDetach","_addNewAttachObserver","_onXRFrame","UtilityLayerRenderer","getRenderCamera","getRigParentIfPossible","_renderCamera","activeCam","originalScene","setRenderCamera","_getSharedGizmoLight","_sharedGizmoLight","utilityLayerScene","Gray","DefaultUtilityLayer","_DefaultUtilityLayer","_CreateDefaultUtilityLayerFromScene","DefaultKeepDepthUtilityLayer","_DefaultKeepDepthUtilityLayer","handleEvents","_lastPointerEvents","pickUtilitySceneFirst","onlyCheckPointerDownEvents","processAllEvents","pickingEnabled","onPointerOutObservable","_originalPointerObserver","prePointerInfo","pointerEvent","getNearPickDataForScene","scenePick","previousActiveCamera","utilityScenePick","originalScenePick","mainSceneTrackerPredicate","_notifyObservers","_afterRenderObserver","_sceneDisposeObserver","oldScene","WebXRControllerPointerSelection","_attachController","xrController","_controllers","laserPointer","selectionMesh","_generateNewMeshPair","tmpRay","disabledByNearInteraction","_attachedController","enablePointerSelectionOnAllControllers","preferredHandedness","_attachTrackedPointerRayMode","_attachGazeMode","_attachScreenRayMode","_tmpVectorForPickCompare","disablePointerLighting","disableSelectionMeshLighting","displaySelectionMesh","laserPointerPickedColor","laserPointerDefaultColor","selectionMeshDefaultColor","selectionMeshPickedColor","_identityMatrix","_screenCoordinatesRef","_viewportRef","_detachController","gazeCamera","webXRCamera","controllerId","getMeshUnderPointer","getXRControllerByPointerId","_getPointerSelectionDisabledByPointerId","_setPointerSelectionDisabledByPointerId","controllerData","controllerGlobalPosition","maxPointerDistance","disableScenePointerVectorUpdate","screenCoordinates","_utilityLayerScene","customUtilityLayerScene","timeToSelect","sceneToRenderTo","useUtilityLayer","oldPick","discMesh","timer","downTriggered","onFrameObserver","_augmentPointerInit","_pickingMoved","disablePointerUpOnTouchOut","finalPointerUpTriggered","pointerDownTriggered","forceGazeMode","overrideButtonId","selectionComponent","onButtonChangedObserver","disableSwitchOnClick","selectStartListener","selectEndListener","eventListeners","selectend","selectstart","xrControllerUniqueId","eventName","meshParent","customLasterPointerMeshGenerator","customSelectionMeshGenerator","newPick","gazeModePointerMovedFactor","screenX","screenY","lasterPointerDefaultColor","NodeMaterialBlockConnectionPointTypes","NodeMaterialBlockTargets","NodeMaterialConnectionPointCompatibilityStates","NodeMaterialConnectionPointDirection","PropertyTypeForEdition","NodeMaterialBlockConnectionPointMode","NodeMaterialSystemValues","AnimatedInputBlockTypes","AddWebXRFeature","NodeMaterialBuildState","supportUniformBuffers","constants","functions","counters","_attributeDeclaration","_uniformDeclaration","_constantDeclaration","_samplerDeclaration","_varyingTransfer","_injectAtEnd","_repeatableContentAnchorIndex","_builtCompilationString","compilationString","finalize","emitComments","sharedData","isFragmentMode","Fragment","functionCode","varyingDeclaration","extensionName","_repeatableContentAnchor","_getFreeVariableName","variableNames","_getFreeDefineName","_excludeVariableName","_emit2DSampler","_emit2DArraySampler","_getGLType","Float","Int","_emitExtension","_emitFunction","comments","_emitCodeFromInclude","includeName","repeatKey","substitutionVars","replaceStrings","replaceString","_emitFunctionFromInclude","storeKey","removeAttributes","removeUniforms","removeVaryings","removeIfDef","_registerTempVariable","temps","_emitVaryingFromString","notDefine","varyings","_emitUniformFromString","_emitFloat","NodeMaterialBuildStateSharedData","inputBlocks","textureBlocks","bindableBlocks","forcedBindableBlocks","blocksWithFallbacks","blocksWithDefines","repeatableContentBlocks","dynamicUniformBlocks","blockingBlocks","animatedInputs","hints","needWorldViewMatrix","needWorldViewProjectionMatrix","checks","emitVertex","emitFragment","notConnectedNonOptionalInputs","allowEmptyVertexProgram","emitErrors","notConnectedInput","ownerBlock","NodeMaterialConnectionPoint","type1","type2","_direction","associatedVariableName","_ownerBlock","isInput","_enforceAssociatedVariableName","_associatedVariableName","_connectedPoint","innerType","_linkedConnectionSource","AutoDetect","BasedOnInput","_typeConnectionSource","_defaultConnectionPointType","_prioritizeVertex","VertexAndFragment","Vertex","connectedPoint","hasEndpoints","isConnectedToInputBlock","connectInputBlock","sourceBlock","connectedBlocks","_endpoints","endpoints","isDirectlyConnectedToVertexOutput","endpoint","Neutral","isConnectedInVertexShader","isConnectedInFragmentShader","createCustomInputBlock","_acceptedConnectionPointType","needDualDirectionValidation","acceptedConnectionPointTypes","excludedConnectionPointTypes","onConnectionObservable","isExposedOnFrame","exposedPortPosition","canConnectTo","connectionPoint","checkCompatibilityState","Compatible","otherBlock","TargetIncompatible","AreEquivalentTypes","TypeIncompatible","targetBlock","Input","isAnAncestorOf","HierarchyIssue","connectTo","ignoreConstraints","disconnectFrom","addExcludedConnectionPointFromAllowedTypes","bitmask","All","displayName","inputName","targetBlockId","targetConnectionName","NodeMaterialBlock","newName","validateBlockName","isUnique","_isUnique","isFinalMerger","_isFinalMerger","_isInput","isTeleportOut","_isTeleportOut","isTeleportIn","_isTeleportIn","buildId","_buildId","_outputs","getInputByName","getOutputByName","inputsAreExclusive","_codeVariableName","visibleInInspector","visibleOnFrame","_originalTargetIsNeutral","_setInitialTarget","nodeMaterial","_declareOutput","_writeVariable","_writeFloat","stringVersion","registerInput","isOptional","registerOutput","Output","getFirstAvailableInput","forOutput","getFirstAvailableOutput","forBlock","getSiblingOutput","notFound","_buildBlock","updateUniformsAndSamples","provideFallbacks","initializeDefines","autoConfigure","replaceRepeatableContent","vertexShaderState","fragmentShaderState","willBeGeneratedIntoVertexShaderFromFragmentShader","_linkConnectionTypes","inputIndex0","inputIndex1","looseCoupling","_processBuild","activeBlocks","build","localBlockIsFragment","_vertexState","otherBlockWasGeneratedInVertexShader","_buildTarget","isAttribute","_noContextSwitch","reservedNames","reservedName","_customBuildStep","verbose","_inputRename","_outputRename","_dumpPropertiesCode","_dumpCode","uniqueNames","alreadyDumped","nameAsVariableName","codeString","connectedBlock","_dumpCodeForOutputConnections","connectedOutput","blockType","_deserialize","_deserializePortDisplayNamesAndExposedOnFrame","serializedInputs","serializedOutputs","port","TransformBlock","complementW","complementZ","otherAsInput","xyz","transformName","VertexOutputBlock","_isLogarithmicDepthEnabled","nodeList","fragmentOutputNodes","editableInPropertyPage","groupName","propStore","_propStore","FragmentOutputBlock","convertToGammaSpace","convertToLinearSpace","rgba","_linearDefineName","_gammaDefineName","aValue","notifiers","remapAttributeName","position2d","particle_uv","particle_color","particle_texturemask","particle_positionw","attributeInFragmentOnly","attributeAsUniform","InputBlock","isUniform","isSystemValue","_systemValue","World","WorldView","WorldViewProjection","View","ViewProjection","Projection","CameraPosition","FogColor","DeltaTime","MaterialAlpha","CameraParameters","Undefined","_animationType","None","isBoolean","matrixMode","isConstant","groupInInspector","onValueChangedObservable","setDefaultValue","setAsAttribute","Attribute","setAsSystemValue","systemValue","_storedValue","Uniform","valueCallback","_valueCallback","isUndefined","isVarying","Varying","Time","RealTime","_emitDefine","_emitConstant","_emit","_transmitWorld","worldView","worldViewProjection","_transmit","codes","valueString","valueType","wellKnownValue","CurrentScreenBlock","_samplerName","_injectVertexCode","uvInput","_mainUVName","_writeTextureRead","_writeOutput","vertexMode","_tempTextureRead","swizzle","ParticleTextureBlock","getInputBlockByPredicate","ParticleRampGradientBlock","rampColor","ParticleBlendMultiplyBlock","alphaTexture","alphaColor","VectorMergerBlock","xSwizzle","ySwizzle","zSwizzle","wSwizzle","xyzwIn","xyzIn","xyIn","zwIn","xyzw","xyzOut","xyOut","zwOut","_buildSwizzle","xInput","yInput","zInput","wInput","xyInput","zwInput","xyzInput","xyzwInput","v4Output","v3Output","v2Output","v2CompOutput","RemapBlock","targetRange","sourceMin","sourceMax","targetMin","targetMax","MultiplyBlock","NodeMaterialModes","BoxParticleEmitter","direction1","minEmitBox","maxEmitBox","startDirectionFunction","directionToUpdate","particle","isLocal","randX","randY","randZ","startPositionFunction","positionToUpdate","newOne","applyToShader","uboOrEffect","getEffectDefines","ConeParticleEmitter","_buildHeight","_angle","directionRandomizer","radiusRange","heightRange","emitFromSpawnPointOnly","CylinderParticleEmitter","_tempVector","inverseWorldMatrix","yPos","radiusDistribution","positionRadius","xPos","zPos","CylinderDirectedParticleEmitter","HemisphericParticleEmitter","randRadius","PointParticleEmitter","SphereParticleEmitter","SphereDirectedParticleEmitter","MeshParticleEmitter","_storedNormal","useMeshNormalsForDirection","randomFaceIndex","faceIndexA","faceIndexB","faceIndexC","vertexA","vertexB","vertexC","randomVertex","BaseParticleSystem","noiseTexture","_noiseTexture","isAnimationSheetEnabled","_isAnimationSheetEnabled","_hasTargetStopDurationDependantGradient","_startSizeGradients","_emitRateGradients","_lifeTimeGradients","getDragGradients","_dragGradients","getLimitVelocityGradients","_limitVelocityGradients","getColorGradients","_colorGradients","getSizeGradients","_sizeGradients","getColorRemapGradients","_colorRemapGradients","getAlphaRemapGradients","_alphaRemapGradients","getLifeTimeGradients","getAngularSpeedGradients","_angularSpeedGradients","getVelocityGradients","_velocityGradients","getStartSizeGradients","getEmitRateGradients","particleEmitterType","isBillboardBased","_isBillboardBased","_removeGradientAndTexture","gradients","valueGradient","emitRate","manualEmitCount","updateSpeed","targetStopDuration","disposeOnStop","minEmitPower","maxEmitPower","minLifeTime","maxLifeTime","minSize","minScaleX","maxScaleX","minScaleY","maxScaleY","minInitialRotation","maxInitialRotation","minAngularSpeed","maxAngularSpeed","customShader","preventAutoStart","_rootUrl","noiseStrength","BLENDMODE_ONEONE","preWarmCycles","preWarmStepOffset","spriteCellChangeSpeed","startSpriteCellID","endSpriteCellID","spriteCellWidth","spriteCellHeight","spriteCellLoop","spriteRandomStartCell","translationPivot","beginAnimationOnStart","beginAnimationFrom","beginAnimationTo","beginAnimationLoop","worldOffset","_rampGradients","startDelay","limitVelocityDamping","color1","color2","colorDead","textureMask","_isSubEmitter","_imageProcessingConfigurationDefines","createPointEmitter","particleEmitter","createHemisphericEmitter","createSphereEmitter","createDirectedSphereEmitter","createCylinderEmitter","createDirectedCylinderEmitter","createConeEmitter","createBoxEmitter","BLENDMODE_STANDARD","BLENDMODE_ADD","BLENDMODE_MULTIPLY","BLENDMODE_MULTIPLYADD","ColorSplitterBlock","rgbIn","rgbOut","rgbOutput","rOutput","gOutput","bOutput","aOutput","ProceduralTextureSceneComponent","proceduralTextures","_beforeClear","proceduralIndex","proceduralTexture","ProceduralTexture","onGeneratedObservable","onBeforeGenerationObservable","_floats","_ints","_floatsArrays","_colors3","_colors4","_vectors2","_vectors3","_matrices","_fallbackTextureUsed","_cachedDefines","_contentUpdateId","_rtWrapper","_fullEngine","setFragment","_fallbackTexture","_createRtWrapper","_createIndexBuffer","_setEffect","getContent","_contentData","_getDefines","_fragment","_checkUniform","setFloats","viewPort","onGenerated","TrigonometryBlockOperations","TrigonometryBlock","Cos","Sin","Abs","Exp","Exp2","Round","Floor","Ceiling","Sqrt","Tan","ArcTan","ArcCos","ArcSin","Fract","Radians","Degrees","NodeMaterialDefines","VERTEXCOLOR_NME","markAsUnprocessedIfDirty","NodeMaterial","_getGlobalNodeMaterialEditor","NODEEDITOR","NodeEditor","_BuildIdGenerator","_buildWasSuccessful","_cachedWorldViewMatrix","_cachedWorldViewProjectionMatrix","_optimizers","_animationFrame","BJSNODEMATERIALEDITOR","editorData","ignoreAlpha","onBuildObservable","_vertexOutputNodes","_fragmentOutputNodes","attachedBlocks","forceAlphaBlending","getBlockByName","getBlockByPredicate","getInputBlocks","blocks","registerOptimizer","optimizer","unregisterOptimizer","addOutputNode","_addVertexOutputNode","_addFragmentOutputNode","removeOutputNode","_removeVertexOutputNode","_removeFragmentOutputNode","_sharedData","_processInitializeOnLink","nodesToProcessForOtherBuildState","_preparationId","_initializeBlock","teleport","entryPoint","_resetDualBlocks","teleportOut","removeBlock","attachedBlockIndex","updateBuildId","Particle","_vertexCompilationState","_fragmentCompilationState","vertexNodes","fragmentNodes","vertexOutputNode","fragmentOutputNode","_prepareDefinesForAttributes","oldNormal","oldTangent","oldColor","uvChanged","oldUV","createPostProcess","_createEffectForPostProcess","createEffectForPostProcess","tempName","dummyMesh","_processDefines","RegisterShader","_checkInternals","createProceduralTexture","hidden","_createEffectForParticles","particleSystemDefinesJoined","particleSystemDefines","fillDefines","createEffectForParticles","setCustomEffect","particleSystemDefinesJoinedCurrent","inputBlock","createAsShadowDepthWrapper","ShadowDepthWrapper","mergedUniforms","mergedSamplers","compiledShaders","tb","getTextureBlocks","getAllTextureBlocks","_BlockIsTextureBlock","_createNodeEditor","additionalConfig","nodeEditorConfig","Show","edit","editorUrl","editorURL","EditorURL","setToDefault","positionInput","worldInput","worldPos","viewProjectionInput","worldPosdMultipliedByViewProjection","vertexOutput","pixelColor","fragmentOutput","setToDefaultPostProcess","const1","vmerger","currentScreen","setToDefaultProceduralTexture","vectorMerger","setToDefaultParticle","rampGradient","cSplitter","blendMultiply","ParseFromFileAsync","_gatherBlocks","generateCode","vertexBlocks","outputNode","fragmentBlocks","selectedBlocks","outputNodes","_restoreConnections","outputPoint","candidate","inputPoint","parseSerializedObject","parsedBlock","_tempEntryPointUniqueId","attachToEndpoint","blockIndex","outputNodeId","locations","blockId","blockMap","comment","loadFromSerialization","shareEffect","skipBuild","CreateDefault","ControllerOrbAnimationState","WebXRNearControllerMode","IgnoreTexturesAtLoadTime","_projectOnTrianglesToRef","tmpDist","ProjectOnTriangleToRef","_projectOnUnIndexedTrianglesToRef","projectToRef","WebXRNearInteraction","touchCollisionMesh","touchCollisionMeshFunction","hydrateCollisionMeshFunction","_generateNewTouchPointMesh","_generateVisualCue","nearInteractionTargetMesh","stalePick","currentAnimationState","DEHYDRATED","grabRay","hoverInteraction","nearInteraction","grabInteraction","pickedPointVisualCue","enableNearInteractionOnAllControllers","_attachNearInteractionMode","_farInteractionFeature","_hoverRadius","_pickRadius","_controllerPickRadius","_nearGrabLengthScale","nearInteractionControllerMode","CENTERED_IN_FRONT","farInteractionFeature","setFarInteractionFeature","_nearPickPredicate","_nearGrabPredicate","_nearInteractionPredicate","_controllerAvailablePredicate","excludedControllerId","_handleTransitionAnimation","HOVER","TOUCH","_processTouchPoint","handData","xrIndexTip","indexTipPose","getJointPose","axisRHSMultiplier","DISABLED","controllerPose","CENTERED_ON_CONTROLLER","accuratePickInfo","populateNearInteractionInfo","nearInteractionInfo","nearInteractionAtOrigin","utilitySceneHoverPick","_pickWithSphere","hoverPickInfo","utilitySceneNearPick","nearPick","_isControllerReadyForNearInteraction","grabCheck","squeezeComponent","onSqueezeButtonChangedObserver","meshCreationScene","motionControllerOrbMaterial","hoverSizeVec","touchSize","touchSizeVec","hydrateTransitionSize","hydrateTransitionSizeVec","touchHoverTransitionSize","touchHoverTransitionSizeVec","hoverTouchTransitionSize","touchKeys","releaseKeys","hydrateKeys","dehydrateKeys","releaseAction","hydrateAction","dehydrateAction","isHydration","sceneToUse","CreateFromCenterAndRadius","PickMeshWithSphere","tmpVec","tmpDistanceSphereToCenter","tmpDistanceSurfaceToCenter","worldToMesh","WebXREnterExitUIButton","activeButton","WebXREnterExitUI","_activeButton","activeButtonChangedObservable","_onSessionGranted","_helper","_enterXRWithButtonIndex","overlay","classList","ignoreSessionGrantedEvent","hostname","customButtons","hmdBtn","_updateButtons","renderCanvas","supportedPromises","onclick","ui","setHelperAsync","prevTitle","InstancedMesh","instancedBuffers","_sourceMesh","_billboardWorldMatrix","tempMaster","sourceMeshLODLevels","newSourceMesh","registerInstancedBuffer","expectedSize","ShaderMaterial","shaderPath","_textureArrays","_externalTextures","_uints","_colors3Arrays","_colors4Arrays","_vectors4","_quaternions","_quaternionsArrays","_matrixArrays","_matrices3x3","_matrices2x2","_vectors2Arrays","_vectors3Arrays","_vectors4Arrays","_textureSamplers","_multiview","_materialHelperNeedsPreviousMatrices","_shaderPath","externalTextures","samplerObjects","storageBuffers","setExternalTexture","setColor3Array","setColor4Array","setQuaternionArray","float32Array","setUniformBuffer","setTextureSampler","sampler","setStorageBuffer","setDefine","defineName","trimEnd","existingDefineIdx","defineToAdd","bvaManager","previousDefines","effectOverride","useSceneUBO","propName","propValue","textureArrays","ints","uints","floats","FloatArrays","colors3","colors3Arrays","colors4Arrays","vectors2","vectors3","vectors4","matrixArray","matrices3x3","matrices2x2","vectors2Arrays","vectors3Arrays","vectors4Arrays","quaternionsArrays","floatsArrays","shaderMaterial","LinesMesh","_isShaderMaterial","_color4","_lineMaterial","_subMesh","colorEffect","doNotDisposeMaterial","InstancedLinesMesh","CreateLineSystemVertexData","vertexColors","CreateDashedLinesVertexData","curvect","lg","shft","dashshft","curshft","CreateLineSystem","vertexColor","lineColors","lineSystem","CreateLines","CreateDashedLines","nbSeg","dashedLines","TimerState","setAndStartTimer","observableParameters","contextObservable","payload","completeRate","onTick","breakCondition","onAborted","onEnded","WebXRMotionControllerTeleportation","rotationEnabled","_rotationEnabled","teleportationTargetMesh","_snappedToPoint","_cachedColor4White","skipNextTeleportation","backwardsMovementEnabled","backwardsTeleportationDistance","parabolicCheckRadius","parabolicRayEnabled","straightRayEnabled","onTargetMeshPositionUpdatedObservable","forceHandedness","teleportationState","backwards","rotating","baseRotation","blocked","initMotionController","movementController","useMainComponentOnly","mainComponent","teleportationComponent","_currentTeleportationControllerId","timeToTeleport","_teleportForward","onAxisChangedObserver","axesData","snapPointsOnly","_floorMeshes","_setTargetMeshVisibility","_createDefaultTargetMesh","_snapToPositions","snapPositions","_blockedRayColor","blockedRayColor","snapToPoints","addBlockerMesh","pickBlockerMeshes","addSnapPoint","newSnapPoint","removeBlockerMesh","removeFloorMeshByName","removeSnapPoint","snapPointToRemove","setSelectionFeature","selectionFeature","_selectionFeature","targetMesh","hitPossible","_showParabolicPath","_setTargetMeshPosition","xRotation","compensation","_disposeBezierCurve","defaultTargetMeshOptions","centerX","centerY","teleportationFillColor","teleportationBorderColor","cone","torusArrowMaterial","torusConeMaterial","_teleportationRingMaterial","_findClosestSnapPointWithRadius","realPosition","snapToPositionRadius","closestPoint","closestDistance","radiusSquared","snapPosition","_quadraticBezierCurve","quadraticBezierVectors","CreateQuadraticBezier","colorsArray","generateRayPathMesh","WebXRDefaultExperience","disableDefaultUI","uiOptions","enterExitUI","CreateAsync","xrHelper","ignoreNativeCameraTransformation","inputOptions","disablePointerSelection","pointerSelectionOptions","useStablePlugins","disableTeleportation","teleportationOptions","disableNearInteraction","nearInteractionOptions","outputCanvasOptions","createDefaultLight","createDefaultCamera","createArcRotateCamera","attachCameraControls","worldExtends","worldSize","worldCenter","arcRotateCamera","freeCamera","createDefaultCameraOrLight","createDefaultSkybox","pbr","blur","setGlobalEnvTexture","hdrSkybox","hdrSkyboxMaterial","createDefaultEnvironment","createDefaultVRExperience","EffectLayer","_effectLayerOptions","mainTexture","_mainTexture","currentMesh","_materialForRendering","getEffectIntensity","_effectIntensity","setEffectIntensity","_maxSize","_mainTextureDesiredSize","_emissiveTextureAndColor","neutralColor","disableBoundingBoxesFromEffectLayer","onBeforeRenderMainTextureObservable","onBeforeComposeObservable","onBeforeRenderMeshToEffect","onAfterRenderMeshToEffect","onAfterComposeObservable","_SceneComponentInitialization","effectLayers","_mergeDrawWrapper","_generateIndexBuffer","_generateVertexBuffer","_numInternalDraws","mainTextureRatio","alphaBlendingMode","mainTextureType","_setMainTextureSize","_createMainTexture","_createTextureAndPostProcesses","mainTextureFixedSize","preWarm","_setEmissiveTextureAndColor","opaqueSubMeshes","alphaTestSubMeshes","transparentSubMeshes","depthOnlySubMeshes","_renderSubMesh","previousAlphaMode","getBoundingBoxRenderer","boundingBoxRendererEnabled","_addCustomEffectDefines","emissiveTexture","renderingMaterial","_useMeshMaterial","needAlphaTest","needAlphaBlendFromDiffuse","useAlphaFromDiffuseTexture","opacityTexture","morphInfluencers","PrepareAttributesForMorphTargetsInfluencers","cachedDefines","numDraws","_createMergeEffect","_internalRender","_disposeTextureAndPostProcesses","hasMesh","_shouldRenderMesh","_canRenderMesh","_shouldRenderEmissiveTextureForMesh","ownerMesh","textureMatrix","parsedEffectLayer","serializeAsCameraReference","AddParser","parsedData","effectLayer","removeEffectLayer","addEffectLayer","newEffectLayer","EffectLayerSceneComponent","_renderEffects","_needStencil","_previousStencilState","_isReadyForMesh","_renderMainTexture","_setStencil","_drawRenderingGroup","_setStencilBack","_drawCamera","removeFromContainer","needStencil","ShadowLight","_needProjectionMatrixCompute","_setPosition","_setDirection","shadowMinZ","_shadowMinZ","forceProjectionMatrixCompute","shadowMaxZ","_shadowMaxZ","computeTransformedInformation","transformedPosition","getDepthScale","getShadowDirection","RotationFromAxis","needCube","needProjectionMatrixCompute","getDepthMinZ","getDepthMaxZ","setShadowProjectionMatrix","viewMatrix","customProjectionMatrixBuilder","_setDefaultShadowProjectionMatrix","ShadowGenerator","_bias","normalBias","_normalBias","blurBoxOffset","_blurBoxOffset","_disposeBlurPostProcesses","blurScale","_blurScale","_blurKernel","useKernelBlur","_useKernelBlur","depthScale","_depthScale","_light","_validateFilter","_filter","FILTER_BLUREXPONENTIALSHADOWMAP","useExponentialShadowMap","FILTER_BLURCLOSEEXPONENTIALSHADOWMAP","useCloseExponentialShadowMap","FILTER_PCF","FILTER_PCSS","usePoissonSampling","_applyFilterValues","FILTER_POISSONSAMPLING","FILTER_NONE","FILTER_EXPONENTIALSHADOWMAP","useBlurExponentialShadowMap","FILTER_CLOSEEXPONENTIALSHADOWMAP","useBlurCloseExponentialShadowMap","usePercentageCloserFiltering","filteringQuality","_filteringQuality","useContactHardeningShadow","contactHardeningLightSizeUVRatio","_contactHardeningLightSizeUVRatio","darkness","_darkness","setDarkness","getDarkness","transparencyShadow","_transparencyShadow","setTransparencyShadow","_shadowMap","getShadowMapForRendering","_shadowMap2","CLASSNAME","addShadowCaster","removeShadowCaster","getLight","mapSize","_mapSize","recreateShadowMap","usefullFloatFirst","useRedTextureType","onBeforeShadowMapRenderObservable","onAfterShadowMapRenderObservable","onBeforeShadowMapRenderMeshObservable","onAfterShadowMapRenderMeshObservable","QUALITY_HIGH","enableSoftTransparentShadow","useOpacityTextureForTransparentShadow","frustumEdgeFalloff","forceBackFacesOnly","_lightDirection","_cachedPosition","_cachedDirection","_currentFaceIndex","_currentFaceIndexCache","_defaultTextureMatrix","_useRedTextureType","shadowGenerators","_sceneUBOs","_initializeGenerator","_initializeShadowMap","_createTargetRenderTexture","noPrePassRenderer","_storedUniqueId","_renderForShadowMap","_blurPostProcesses","clearZero","clearOne","_initializeBlurRTTAndPostProcesses","targetSize","_kernelBlurXPostprocess","_kernelBlurYPostprocess","_boxBlurPostprocess","_renderSubMeshForShadowMap","_bindCustomEffectForRenderSubMeshForShadowMap","isTransparent","detNeg","reverseSideOrientation","customAllowRendering","GetEffect","standalone","baseMaterial","worldOverride","_isReadyCustomDefines","_prepareShadowDefines","subMeshEffect","DEFAULT_ALPHA_CUTOFF","customShaderOptions","attrib","QUALITY_LOW","QUALITY_MEDIUM","lightPosition","_disposeRTTandPostProcesses","_disposeSceneUBOs","lightId","parsedShadowGenerator","constr","useVarianceShadowMap","useBlurVarianceShadowMap","DepthRenderer","_depthMap","storeNonLinearDepth","storeCameraSpaceZ","forceDepthWriteTransparentMeshes","useOnlyInActiveCamera","reverseCulling","_storeNonLinearDepth","_storeCameraSpaceZ","isPacked","renderSubMesh","cameraIsOrtho","numMorphInfluencers","getDepthMap","keysToDelete","_depthRenderer","DepthReducer","MinMaxReducer","onAfterReductionPerformed","_forceFullscreenViewport","_activated","_sourceTexture","setSourceTexture","depthRedux","_reductionSteps","reductionInitial","reduction","minmax","activated","deactivate","disposeAll","depthRenderer","setDepthRenderer","_depthRendererId","UpDir","ZeroVec","tmpv1","tmpv2","CascadedShadowGenerator","numCascades","_numCascades","MIN_CASCADES_COUNT","MAX_CASCADES_COUNT","_recreateSceneUBOs","freezeShadowCastersBoundingInfo","_freezeShadowCastersBoundingInfo","_freezeShadowCastersBoundingInfoObservable","_computeShadowCastersBoundingInfo","_scbiMin","_scbiMax","MIN_VALUE","_shadowCastersBoundingInfo","shadowCastersBoundingInfo","setMinMaxDistance","_minDistance","_maxDistance","_breaksAreDirty","minDistance","maxDistance","getCascadeMinExtents","cascadeIndex","_cascadeMinExtents","getCascadeMaxExtents","_cascadeMaxExtents","debug","_debug","dbg","depthClamp","_depthClamp","cascadeBlendPercentage","_cascadeBlendPercentage","lambda","_lambda","getCascadeViewMatrix","cascadeNum","_viewMatrices","getCascadeProjectionMatrix","_projectionMatrices","getCascadeTransformMatrix","_transformMatrices","_depthReducer","autoCalcDepthBounds","_autoCalcDepthBounds","autoCalcDepthBoundsRefreshRate","splitFrustum","_splitFrustum","near","far","cameraRange","_cascades","prevBreakDistance","breakDistance","_viewSpaceFrustumsZ","_frustumLengths","_computeMatrices","_computeFrustumInWorldSpace","_computeCascadeFrustum","_frustumCenter","_shadowCameraPos","_transformMatricesAsArray","prevSplitDist","splitDist","cameraInfiniteFarPlane","saveCameraMaxZ","invViewProj","cornerIndexOffset","cornerIndex","_FrustumCornersNDCSpace","_frustumCornersWorldSpace","stabilizeCascades","lightCameraPos","usefulFloatFirst","_o","_p","_q","_r","_s","_t","_u","_v","penumbraDarkness","DEFAULT_CASCADES_COUNT","_currentLayer","_lightSizeUVCorrection","_depthCorrection","ShadowGeneratorSceneComponent","_gatherRenderTargets","DirectionalLight","shadowFrustumSize","_shadowFrustumSize","shadowOrthoScale","_shadowOrthoScale","autoUpdateExtends","autoCalcShadowZBounds","_setDefaultFixedFrustumShadowProjectionMatrix","_setDefaultAutoExtendShadowProjectionMatrix","PointLight","shadowAngle","_shadowAngle","previousNeedCube","SpotLight","_cosHalfAngle","_projectionTextureProjectionLightDirty","_computeAngleValues","_innerAngle","shadowAngleScale","_shadowAngleScale","projectionTextureMatrix","_projectionTextureMatrix","projectionTextureLightNear","_projectionTextureLightNear","projectionTextureLightFar","_projectionTextureLightFar","projectionTextureUpDirection","_projectionTextureUpDirection","projectionTexture","_projectionTexture","_projectionTextureDirty","_IsProceduralTexture","_IsTexture","projectionTextureProjectionLightMatrix","_projectionTextureProjectionLightMatrix","_projectionTextureViewLightDirty","_projectionTextureViewTargetVector","_projectionTextureViewLightMatrix","_projectionTextureScalingMatrix","_computeProjectionTextureViewLightMatrix","_computeProjectionTextureProjectionLightMatrix","lightFar","lightNear","P","Q","S","_computeProjectionTextureMatrix","_lightAngleScale","_lightAngleOffset","SceneOptimization","getDescription","TextureOptimization","maximumSize","currentSize","HardwareScalingOptimization","_currentScale","maximumScale","_directionOffset","ShadowsOptimization","isInImprovementMode","PostProcessesOptimization","LensFlaresOptimization","CustomOptimization","onGetDescription","ParticlesOptimization","RenderTargetsOptimization","MergeMeshesOptimization","_canBeMerged","UpdateSelectionTree","_UpdateSelectionTree","updateSelectionTree","globalPool","globalLength","currentPool","MergeMeshes","sceneAsAny","createOrUpdateSelectionOctree","SceneOptimizerOptions","targetFrameRate","trackerDuration","optimizations","addOptimization","optimization","addCustomOptimization","SceneOptimizer","_improvementMode","currentPriorityLevel","_currentPriorityLevel","_currentFrameRate","_targetFrameRate","_trackerDuration","autoGeneratePriorities","improvementMode","_isRunning","onSuccessObservable","onNewOptimizationAppliedObservable","onFailureObservable","optim","_checkCurrentState","noOptimizationApplied","onFailure","ModerateDegradationAllowed","serializedGeometries","SerializeGeometry","serializationGeometries","SerializeMesh","serializationScene","SceneSerializer","_Serialize","checkSyncReadSupported","isPhysicsEnabled","physicEngine","physicsGravity","getPhysicsPluginName","activeCameraID","animationGroupIndex","reflectionProbe","environmentTextureRotationY","boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","_CollectPromises","toSerialize","withParents","withChildren","serializeMaterial","submaterial","FinalizeSingleNode","enableDepthRenderer","force32bitsFloat","supportFullfloat","disableDepthRenderer","DepthRendererSceneComponent","_gatherActiveCameraRenderTargets","EdgesRenderer","LineEdgesRenderer","FaceAdjacencies","edgesConnectedCount","linesPositions","_linesPositions","linesNormals","_linesNormals","_linesIndices","lineShader","_lineShader","_edgeRenderLineShader","generateEdgesLines","edgesWidthScalerForOrthographic","edgesWidthScalerForPerspective","_buffersForInstances","_checkVerticesInsteadOfIndices","_epsilon","_prepareRessources","useAlternateEdgeFinder","_generateEdgesLinesAlternate","_generateEdgesLines","_meshRebuildObserver","_meshDisposeObserver","_GetShader","_ib","_processEdgeForAdjacencies","pa","pb","_processEdgeForAdjacenciesWithVertices","eps","_checkEdge","faceNormals","needToCreateLine","createLine","_tessellateTriangle","edgePoints","indexTriangle","remapVertexIndices","makePointList","pointIndices","startEdge","mainPointIndices","otherPointIndices","numMainPoints","numOtherPoints","bucketIsMain","bucketStep","bucketLimit","bucketIdxLimit","winding","numTris","bucketIdx","nbucketIdx","bucketPoints","nbucketPoints","bucket","useFastVertexMerger","epsVertexMerge","epsilonVertexMerge","mapVertices","applyTessellation","epsVertexAligned","epsilonVertexAligned","mustTesselate","triangleToTessellate","p0Index","p1Index","p2Index","p0x","p0y","p0z","p1x","p1y","p1z","p0p1","vIndex","p0p","pp1","edgesPoints","triangle","faceNormal","removeDegeneratedTriangles","ei","_indicesCount","adjacencies","faceAdjacencies","otherIndex","otherFaceAdjacencies","otherP0","otherP1","otherP2","edgeIndex","otherEdgeIndex","currentDrawWrapper","useBuffersWithInstances","thinInstanceCount","restoreSingleAttachment","bindAttachments","restoreSingleAttachmentForRenderTarget","buildTextureLayout","textureStatus","attachments","readBuffer","useSRGBBuffers","useStencilTexture","depthStencilBuffer","layerCount","isWebGL2","MultiRenderTarget","internalSizedFormat","webGLTextureType","depthTexture","depthTextureType","glDepthTextureInternalFormat","glDepthTextureFormat","glDepthTextureType","glDepthTextureAttachment","useDepthStencil","textureNames","drawOnlyOnFirstAttachmentByDefault","_textureNames","_initTypes","_multiRenderTargetOptions","_drawOnlyOnFirstAttachmentByDefault","_createInternalTextures","_createTextures","defaultType","_createInternaTextureIndexMapping","mapMainInternalTexture2Index","mapInternalTexture2MainIndex","internalTextures","mainIndex","forceFullRebuild","releaseInternalTextures","_releaseTextures","setInternalTexture","updateCount","doNotDisposeInternalTextures","GeometryBufferRenderer","_linkPrePassRenderer","_linkedWithPrePass","_prePassRenderer","_multiRenderTarget","_unlinkPrePassRenderer","_createRenderTargets","_resetLayout","_enablePosition","_enableReflectivity","_enableVelocity","_attachmentsFromPrePass","_forceTextureType","geometryBufferType","POSITION_TEXTURE_TYPE","_positionIndex","VELOCITY_TEXTURE_TYPE","_velocityIndex","REFLECTIVITY_TEXTURE_TYPE","_reflectivityIndex","DEPTH_TEXTURE_TYPE","_depthIndex","NORMAL_TEXTURE_TYPE","_normalIndex","_setAttachments","_linkInternalTexture","getTextureIndex","enablePosition","enableVelocity","_previousTransformationMatrices","enableReflectivity","_ratio","_previousBonesTransformationMatrices","excludedSkinnedMeshesFromVelocity","renderTransparentMeshes","_clearColor","_clearDepthColor","useSpecificClearForDepthTexture","_useUbo","_depthFormat","needUv","metallicWorkflow","metallicRoughnessTexture","baseColor","specularGlossinessTexture","glossiness","metallicTexture","albedoTexture","reflectivityTexture","specularTexture","buffersCount","getGBuffer","_assignRenderTargetIndices","layoutAttachmentsAll","layoutAttachmentsAllButDepth","layoutAttachmentsDepthOnly","attachmentsAll","attachmentsAllButDepth","attachmentsDepthOnly","viewProjection","bonesTransformations","_copyBonesTransformationMatrices","_geometryBufferRenderer","enableGeometryBufferRenderer","disableGeometryBufferRenderer","GeometryBufferRendererSceneComponent","getOutlineRenderer","_outlineRenderer","OutlineRenderer","_renderOutline","_renderOverlay","_passIdForDrawWrapper","_beforeRenderingMesh","_afterRenderingMesh","useOverlay","_savedDepthWrite","renderOutline","_StencilReference","currentMode","alphaBlendState","PrePassRenderTarget","_beforeCompositionPostProcesses","_internalTextureDirty","_createCompositionEffect","imageProcessingPostProcess","_checkSize","_resetPostProcessChain","_outputPostProcess","PrePassRenderer","_textureIndices","_useSpecificClearForDepthTexture","getRenderTarget","_setRenderTarget","prePassRenderTarget","_refreshGeometryBufferRendererLink","doNotUseGeometryRendererFallback","_geometryBuffer","excludedMaterials","_mrtTypes","_mrtFormats","_mrtLayout","_mrtNames","_effectConfigurations","_needsCompositionForThisPass","disableGammaTransform","TextureFormats","_createRenderTarget","rt","bindAttachmentsForEffect","excluded","_multiRenderAttachments","_defaultAttachments","_reinitializeAttachments","multiRenderLayout","clearLayout","clearDepthLayout","defaultLayout","_clearAttachments","_clearDepthAttachments","purpose","_updateGeometryBufferLayout","texturesActivated","prePassConstant","geometryBufferConstant","restoreAttachments","_beforeDraw","_setupOutputForThisPass","_postProcessesSourceForThisPass","setCustomOutput","_renderPostProcesses","postProcessChain","_afterDraw","_setEnabled","_setRenderTargetEnabled","_unlinkInternalTexture","cfg","previousMrtCount","_enableTextures","texturesRequired","_disable","_getPostProcessesSource","secondaryCamera","cameraHasImageProcessing","_hasImageProcessing","_needsImageProcessing","firstCameraPP","firstPrePassPP","needsImageProcessing","isIPPAlreadyPresent","enablePrePass","_depthPeelingRenderer","_markAllMaterialsAsPrePassDirty","disablePrePassRenderer","PrePassRendererSceneComponent","_beforeCameraDraw","_afterCameraDraw","_beforeRenderTargetDraw","_afterRenderTargetDraw","settingDefaults","parentChangeBehavior","PRESERVE_POSITION","settingsKey","savedSettings","localStorage","getItem","settings","SettingsManagerService","setItem","CreateRibbonVertexData","invertUV","defaultOffset","customUV","customColors","us","vs","uTotalDistance","vTotalDistance","minlg","ar1","ar2","idc","closePathCorr","vectlg","path1","path2","l1","path1nb","indexFirst","indexLast","positions32","normals32","uvs32","_idx","CreateRibbon","ns","si","pathPoint","colorIndex","ribbon","CreateDiscVertexData","vertexNb","CreateDisc","disc","CreateTiledPlaneVertexData","flipTile","pattern","tileWidth","tileHeight","alignH","alignHorizontal","alignV","alignVertical","tilesX","tilesY","adjustX","adjustY","startX","startY","uvBase","partialBottomRow","partialTopRow","partialLeftCol","partialRightCol","uvPart","uvBaseBR","uvBaseTR","uvBaseLC","uvBaseRC","CreateTiledBoxVertexData","halfDepth","faceVertexData","baseAlignV","facePositions","newFaceUV","vec0","mtrx0","mtrx2","mtrx3","vec4","mtrx4","RotationX","mtrx5","CreateTorusKnotVertexData","getPos","cu","su","quOverP","tang","bitan","jNext","CreateTorusKnot","torusKnot","CreateTiledPlane","CreateTiledBox","IndexedVector2","original","PolygonPoints","originalPoints","computeBounds","lmin","lmax","PolygonMeshBuilder","_addToepoint","_epoints","contours","earcut","_outlinepoints","_holes","_eholes","bjsEarcut","addHole","hole","holepoints","smoothingThreshold","buildVertexData","bounds","positionscount","totalCount","_addSide","ulength","vc","vp","vn","vc_norm","vp_norm","vn_norm","dotp","dotn","CreatePolygonVertexData","wrp","disp","distZ","totalLen","cumulate","CreatePolygon","polygonTriangulation","hNb","hPoint","ExtrudePolygon","ExtrudeShape","closeShape","_ExtrudeShapeGeneric","adjustFrame","ExtrudeShapeCustom","rotateFunction","rbCA","rbCP","custom","updtbl","extrusionPathArray","path3D","shapePaths","binormals","scl","shapePath","scaleRatio","planed","rotated","capPath","pointCap","barycenter","storage","extrudedGeneric","CreateLathe","clip","pi2","CreateTube","tubePathArray","circlePaths","radiusFunctionFinal","circlePath","pathIndex","CreatePolyhedronVertexData","polyhedra","sizeX","sizeY","sizeZ","nbfaces","faceIdx","indexes","ang","fl","CreatePolyhedron","polyhedron","PolyhedronBuilder","CreateIcoSphereVertexData","radiusX","radiusY","radiusZ","icoVertices","ico_indices","vertices_unalias_id","ico_vertexuv","island","current_indice","face_vertex_pos","face_vertex_uv","v012","v_id","interp_vertex","c2","pos_x0","pos_x1","pos_interp","vertex_normal","centroid_x0","centroid_x1","uv_x0","uv_x1","uv_interp","CreateIcoSphere","xpAxis","xnAxis","ypAxis","ynAxis","zpAxis","znAxis","DecalVertex","vertexIdx","vertexIdxForBones","localPositionOverride","localNormalOverride","matrixIndicesOverride","matrixWeightsOverride","CreateDecal","hasSkeleton","useLocalComputation","localMode","meshHasOverridenMaterial","localPositions","localNormals","matIndices","matWeights","matIndicesExtra","matWeightsExtra","cameraWorldTarget","currentVertexDataIndex","extractDecalVector3","indexId","vertexId","captureUVS","emptyArray","clipSize","clipVertices","clipFactor","GetClipFactor","mat0Index","v0Indices","v0Weights","mat1Index","v1Indices","v1Weights","sumw","v0LocalPositionX","v0LocalPositionY","v0LocalPositionZ","v1LocalPositionX","v1LocalPositionY","v1LocalPositionZ","v0LocalNormalX","v0LocalNormalY","v0LocalNormalZ","interpNormalX","interpNormalY","interpNormalZ","clipResult","nV1","nV2","nV3","nV4","v1Out","v2Out","v3Out","sourceMeshAsMesh","numMatrices","thinInstanceMatrix","ofst","decalWorldMatrix","inverseDecalWorldMatrix","meshWorldMatrix","oneFaceVertices","faceVertices","decal","CreateCapsuleVertexData","capDetail","heightSegments","heightMinusCaps","thetaLength","capsTopSegments","topCapSubdivisions","capsBottomSegments","bottomCapSubdivisions","indexArray","cosAlpha","sinAlpha","coneLength","vl","indexRow","sinA","sinTheta","cosTheta","coneHeight","i4","vDat","CreateCapsule","capsule","_IsoVector","rotate60About","rotateNeg60About","rotate120","rotateNeg120","toCartesianOrigin","isoGridSize","_PrimaryIsoTriangle","cartesian","closestTo","innerFacets","isoVecsABOB","isoVecsOBOA","isoVecsBAOA","vertexTypes","IDATA","PolyhedronData","vecToidx","fr","O","n1","oVec","aVec","bVec","oaVec","abVec","obVec","idxR","isoId","isoIdR","verts","vDist","vertByDist","matchIdx","edgematch","calcCoeffs","thirdR3","LSQD","coau","cobu","coav","cobv","createInnerFacets","edgeVecsABOB","pointR","prevR","nextR","maxPrev","maxLeftPrev","mapABOBtoOBOA","mapABOBtoBAOA","MapToFace","faceNb","geodesicData","F","oidx","aidx","bidx","OA","OB","mapped","tempVec","distFrom","vert","primVert","distFromO","distFromA","distFromB","vertData","GeodesicData","innerToData","primTri","mapABOBtoDATA","mapOBOAtoDATA","mapBAOAtoDATA","orderData","nearTo","nearIndex","sharedNodes","poleNodes","setOrder","adjVerts","dualFaces","adjacentFaces","toGoldbergPolyhedronData","goldbergPolyhedronData","verticesNb","cz","GoldbergMesh","goldbergData","faceCenters","faceZaxis","faceXaxis","faceYaxis","nbSharedFaces","nbUnsharedFaces","nbFacesAtPole","relatedGoldbergFace","poleOrShared","fromPole","_changeGoldbergFaceColors","colorRange","newCols","setGoldbergFaceColors","updateGoldbergFaceColors","_changeGoldbergFaceUVs","uvRange","points5","points6","setGoldbergFaceUVs","newUVs","updateGoldbergFaceUVs","placeOnGoldbergFaceAt","goldberg","ShapePath","resolution","_paths","_tempPaths","_resolution","moveTo","_currentPath","lineTo","quadraticCurveTo","cpx","cpy","bezierCurveTo","cpx1","cpy1","cpx2","cpy2","extractHoles","CreateShapePath","char","fontData","glyph","glyphs","outline","ha","CreateTextShapePaths","chars","line_height","yMax","yMin","underlineThickness","MeshBuilder","CreateGeodesic","BuildGeodesicData","CreateGoldberg","ba","ca","pdata","vCoord","CreateGoldbergVertexData","CreateText","holeVectors","shapeVectors","localHolesCopy","holePoints","bbox","GuiHelper","highlighter","textLabelMap","gridSettings","sceneNode","skipOrigin","gridMesh","bgColor","bgColor3","strongLineColor","FromColor3","lightLineColor","calculateGridPoints","pointColors","linesPerSide","disableGrid","gridAxesMesh","Green","Blue","pointsAxes","gridMeshAxes","createTextLabels","disableGridAxes","planeHeight","textureHeight","tmpctx","textureWidth","planeWidth","stepSize","gridCount","gridFullSize","wV1","wV2","vStep","uVec","vVec","nodeToScreen","bNode","toScreen","toNDC","Project","getScreenBoundingBox","boundingVectorsToScreen","xs","ys","minx","maxx","miny","canvasWidth","canvasHeight","updateMatrixOfAncestorChain","eWorkerTasks","eKB3DMessageType","global","idealSize","numerator","denominator","dataURL","tagName","videoWidth","videoHeight","ImageData","Kb3dWorker","toggle","requestsInFlight","workerPath","workerReturnMessage","taskId","taskComplete","taskError","newWorker","startTask","task","taskPayload","transfer","messagePayload","taskStart","_Group","_tweens","_tweensAddedDuringUpdate","tweenId","removeAll","tween","getId","preserve","tweenIds","TWEEN","_isPlaying","Group","_nextId","nextId","hrtime","getTime","Tween","_isPaused","_pauseStart","_object","_valuesStart","_valuesEnd","_valuesStartRepeat","_duration","_repeat","_repeatDelayTime","_yoyo","_reversed","_delayTime","_startTime","Easing","Linear","_interpolationFunction","Interpolation","_chainedTweens","_onStartCallback","_onStartCallbackFired","_onUpdateCallback","_onRepeatCallback","_onCompleteCallback","_onStopCallback","_group","isPlaying","isPaused","stopChainedTweens","numChainedTweens","repeat","times","repeatDelay","yoyo","easing","interpolationFunction","chain","onStart","onUpdate","onRepeat","onStop","elapsed","Quadratic","In","Out","InOut","Cubic","Quartic","Quintic","Sinusoidal","Exponential","Circular","Elastic","Bounce","Utils","Bezier","pw","bn","Bernstein","fc","Factorial","AnimationModule","kbViewer","activeAnimations","animationsAreRunning","applyDefaults","origValue","origValueType","valueIn","toVal","getTweenEasingFn","valueOut","activeAnim","animationWarningsNeedsUpdate","anims","stopAll","linear","From","inOut","anchorIdProvider","WebXRAnchorSystem","referenceSpaceForFrameAnchors","_referenceSpaceForFrameAnchors","_lastFrameDetected","_trackedAnchors","_futureAnchors","onAnchorAddedObservable","onAnchorRemovedObservable","onAnchorUpdatedObservable","_populateTmpTransformation","hitTestResult","xrHitResult","createAnchor","nativeAnchor","resolved","submitted","xrTransformation","forceCreateInCurrentFrame","xrAnchor","_createAnchorAtTransformation","anchors","doNotRemoveAnchorsOnSessionEnded","trackedAnchors","anchor","idxTracker","_findIndexInAnchorArray","_updateAnchorWithXRFrame","attachedNode","transformationMatrix","newAnchor","futureAnchor","anchorSpace","worldParentNode","WebXRHitTest","_tmpMat","_tmpPos","_tmpQuat","_initHitTestSource","offsetRay","XRRay","hitTestOptions","useReferenceSpace","entityTypes","requestHitTestSource","hitTestSource","_xrHitTestSource","cancel","autoCloneTransformation","onHitTestResultObservable","paused","disablePermanentHitTest","enableTransientHitTest","transientOffsetRay","requestHitTestSourceForTransientInput","transientHitTestProfile","hitSource","_transientXrHitTestSource","getHitTestResults","_processWebXRHitTestResult","getHitTestResultsForTransientInput","resultsPerInputSource","hitTestResults","isTransient","planeIdProvider","WebXRPlaneDetector","_detectedPlanes","onPlaneAddedObservable","onPlaneRemovedObservable","onPlaneUpdatedObservable","doNotRemovePlanesOnSessionEnded","XRPlane","detectedPlanes","worldInformation","planeIdx","xrPlane","lastChangedTime","_findIndexInPlaneArray","_updatePlaneWithXRPlane","newPlane","polygonDefinition","internalInit","preferredDetectorOptions","trySetPreferredPlaneDetectorOptions","updateWorldTrackingState","planeDetectionState","xrPoint","planeSpace","MorphTarget","_influence","onInfluenceChanged","_onDataLayoutChanged","hasPositions","hasTangents","hadPositions","hadNormals","hadTangents","hadUVs","_GLTFUtilities","bufferIndex","bufferview","bufferviewIndex","accessor","vertexStart","accessorType","_TangentType","_GLTFAnimation","babylonNode","babylonTransformNode","animationChannelTargetPath","useQuaternion","animationSampleRate","_IsTransformable","keyFrames","minMaxKeyFrames","_CalculateMinMaxKeyFrames","interpolationOrBake","_DeduceInterpolation","interpolationType","shouldBakeAnimation","_CreateBakedAnimation","_CreateLinearOrStepAnimation","_CreateCubicSplineAnimation","samplerInterpolation","inputsMin","inputsMax","dataAccessorType","runtimeGLTFAnimation","idleGLTFAnimations","nodeMap","binaryWriter","bufferViews","accessors","shouldExportAnimation","glTFAnimation","animationInfo","_DeduceAnimationInfo","channels","_AddAnimation","combinedAnimation","combinedAnimationKeys","animationKeys","babylonScene","glTFAnimations","morphAnimations","sampleAnimations","morphAnimationMeshes","animationGroupFrameDiff","targetedAnimations","targetAnimation","babylonMorphTarget","babylonMorphTargetManager","babylonMesh","combinedAnimationGroup","sampleAnimationKeys","numAnimationKeys","animationsByMorphTarget","morphTargetAnimation","morphAnimationChannels","animationData","_CreateNodeAnimation","keyframeAccessorIndex","dataAccessorIndex","outputLength","animationSampler","animationChannel","currentInput","newInputs","nodeIndex","_CreateBufferView","getByteOffset","_CreateAccessor","_GetDataAccessorElementCount","minFrame","maxFrame","sampleRate","minMaxFrames","quaternionCache","previousTime","maxUsedFrame","currKeyFrame","nextKeyFrame","prevKeyFrame","_SetInterpolatedValue","basePositionRotationOrScale","_GetBasePositionRotationOrScale","componentName","cacheValue","_ConvertFactorToVector3OrQuaternion","keyFrame","_AddKeyframeValue","_AddSplineTangent","INTANGENT","OUTTANGENT","newPositionRotationOrScale","posRotScale","tangentType","tangentValue","GLTFData","glTFFiles","downloadFiles","link","_convertRGBtoRGBATextureData","rgbData","rgbaData","_makeCreateRawTextureFunction","updateRawTexture3D","updateRawTexture2DArray","_makeUpdateRawTextureFunction","internalType","internalSizedFomat","compressedTexImage3D","updateRawTexture","updateRawCubeTexture","needConversion","createRawCubeTextureFromUrl","mipmapGenerator","internalCallback","faceDataArrays","mipData","mipSize","mipFaceData","RawTexture","Constants","ALPHA_ONEONE_ONEONE","ALPHA_ALPHATOCOLOR","ALPHA_REVERSEONEMINUS","ALPHA_SRC_DSTONEMINUSSRCALPHA","ALPHA_ONEONE_ONEZERO","ALPHA_EXCLUSION","ALPHA_LAYER_ACCUMULATE","ALPHA_EQUATION_ADD","ALPHA_EQUATION_SUBSTRACT","ALPHA_EQUATION_REVERSE_SUBTRACT","ALPHA_EQUATION_MAX","ALPHA_EQUATION_MIN","ALPHA_EQUATION_DARKEN","TEXTURE_CREATIONFLAG_STORAGE","TEXTUREFORMAT_BGRA","TEXTUREFORMAT_DEPTH24_STENCIL8","TEXTUREFORMAT_DEPTH32_FLOAT","TEXTUREFORMAT_DEPTH16","TEXTUREFORMAT_DEPTH24","TEXTUREFORMAT_DEPTH24UNORM_STENCIL8","TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8","TEXTUREFORMAT_STENCIL8","TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM","TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM","TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT","TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT","TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5","TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT","TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3","TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT","TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1","TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1","TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT","TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT","TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4","TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR","TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL","TEXTUREFORMAT_COMPRESSED_RGB8_ETC2","TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2","TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2","TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2","TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC","TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC","TEXTURETYPE_UNDEFINED","TEXTURE_CUBE_MAP_ARRAY","TEXTURE_FILTERING_QUALITY_OFFLINE","TEXTURE_FILTERING_QUALITY_HIGH","TEXTURE_FILTERING_QUALITY_MEDIUM","TEXTURE_FILTERING_QUALITY_LOW","MATERIAL_TextureDirtyFlag","MATERIAL_LightDirtyFlag","MATERIAL_FresnelDirtyFlag","MATERIAL_AttributesDirtyFlag","MATERIAL_MiscDirtyFlag","MATERIAL_PrePassDirtyFlag","MATERIAL_AllDirtyFlag","MATERIAL_TriangleFillMode","MATERIAL_WireFrameFillMode","MATERIAL_PointFillMode","MATERIAL_PointListDrawMode","MATERIAL_LineListDrawMode","MATERIAL_LineLoopDrawMode","MATERIAL_LineStripDrawMode","MATERIAL_TriangleStripDrawMode","MATERIAL_TriangleFanDrawMode","MATERIAL_ClockWiseSideOrientation","MATERIAL_CounterClockWiseSideOrientation","ACTION_NothingTrigger","ACTION_OnPickTrigger","ACTION_OnLeftPickTrigger","ACTION_OnRightPickTrigger","ACTION_OnCenterPickTrigger","ACTION_OnPickDownTrigger","ACTION_OnDoublePickTrigger","ACTION_OnPickUpTrigger","ACTION_OnPickOutTrigger","ACTION_OnLongPressTrigger","ACTION_OnPointerOverTrigger","ACTION_OnPointerOutTrigger","ACTION_OnEveryFrameTrigger","ACTION_OnIntersectionEnterTrigger","ACTION_OnIntersectionExitTrigger","ACTION_OnKeyDownTrigger","ACTION_OnKeyUpTrigger","PARTICLES_BILLBOARDMODE_Y","PARTICLES_BILLBOARDMODE_ALL","PARTICLES_BILLBOARDMODE_STRETCHED","PARTICLES_BILLBOARDMODE_STRETCHED_LOCAL","MESHES_CULLINGSTRATEGY_STANDARD","MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY","MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION","MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY","SCENELOADER_NO_LOGGING","SCENELOADER_MINIMAL_LOGGING","SCENELOADER_SUMMARY_LOGGING","SCENELOADER_DETAILED_LOGGING","PREPASS_IRRADIANCE_TEXTURE_TYPE","PREPASS_POSITION_TEXTURE_TYPE","PREPASS_VELOCITY_TEXTURE_TYPE","PREPASS_REFLECTIVITY_TEXTURE_TYPE","PREPASS_COLOR_TEXTURE_TYPE","PREPASS_DEPTH_TEXTURE_TYPE","PREPASS_NORMAL_TEXTURE_TYPE","PREPASS_ALBEDO_SQRT_TEXTURE_TYPE","BUFFER_CREATIONFLAG_READ","BUFFER_CREATIONFLAG_WRITE","BUFFER_CREATIONFLAG_READWRITE","BUFFER_CREATIONFLAG_UNIFORM","BUFFER_CREATIONFLAG_VERTEX","BUFFER_CREATIONFLAG_INDEX","BUFFER_CREATIONFLAG_STORAGE","RENDERPASS_MAIN","INPUT_ALT_KEY","INPUT_CTRL_KEY","INPUT_META_KEY1","INPUT_META_KEY2","INPUT_META_KEY3","INPUT_SHIFT_KEY","SNAPSHOTRENDERING_STANDARD","SNAPSHOTRENDERING_FAST","MAX_SUPPORTED_UV_SETS","GL_ALPHA_EQUATION_ADD","GL_ALPHA_EQUATION_MIN","GL_ALPHA_EQUATION_MAX","GL_ALPHA_EQUATION_SUBTRACT","GL_ALPHA_EQUATION_REVERSE_SUBTRACT","GL_ALPHA_FUNCTION_SRC","GL_ALPHA_FUNCTION_ONE_MINUS_SRC_COLOR","GL_ALPHA_FUNCTION_SRC_ALPHA","GL_ALPHA_FUNCTION_ONE_MINUS_SRC_ALPHA","GL_ALPHA_FUNCTION_DST_ALPHA","GL_ALPHA_FUNCTION_ONE_MINUS_DST_ALPHA","GL_ALPHA_FUNCTION_DST_COLOR","GL_ALPHA_FUNCTION_ONE_MINUS_DST_COLOR","GL_ALPHA_FUNCTION_SRC_ALPHA_SATURATED","GL_ALPHA_FUNCTION_CONSTANT_COLOR","GL_ALPHA_FUNCTION_ONE_MINUS_CONSTANT_COLOR","GL_ALPHA_FUNCTION_CONSTANT_ALPHA","GL_ALPHA_FUNCTION_ONE_MINUS_CONSTANT_ALPHA","_GLTFMaterialExporter","exporter","_textureMap","_internalTextureToImage","_exporter","_convertMaterialsToGLTFAsync","exportMaterials","hasTextureCoords","_convertStandardMaterialAsync","_convertPBRMaterialAsync","_stripTexturesFromMaterial","originalMaterial","alphaCutoff","emissiveFactor","originalPBRMetallicRoughness","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","_hasTexturesPresent","normalTexture","occlusionTexture","pbrMat","baseColorTexture","extensionObject","hasTextures","_getTextureInfo","babylonTexture","textureUid","_convertToGLTFPBRMetallicRoughness","babylonStandardMaterial","P0","P1","P2","P3","cubicBezierCurve","solveForRoughness","_MaxSpecularPower","oneMinusSpecularStrength","_DielectricSpecular","glTFMaterial","babylonMaterial","materialMap","_materialMap","_exportTextureAsync","textureInfo","ambientTexture","_FuzzyEquals","_Epsilon","_SetAlphaMode","_finishMaterial","_extensionsPostExportMaterialAdditionalTextures","tasks","extensionWork","_extensionsPostExportMaterialAsync","_babylonScene","_createWhiteTexture","CreateRGBATexture","_resizeTexturesToSameDimensions","texture1","texture2","texture1Size","texture2Size","resizedTexture1","resizedTexture2","_convertPixelArrayToFloat32","factors","resizedTextures","diffuseSize","diffuseBuffer","specularGlossinessBuffer","diffusePixels","specularPixels","metallicRoughnessBuffer","baseColorBuffer","maxBaseColor","maxMetallic","maxRoughness","specularGlossiness","metallicRoughness","_convertSpecularGlossinessToMetallicRoughness","metallicRoughnessFactors","writeOutMetallicRoughnessTexture","writeOutBaseColorTexture","destinationOffset","sRGBBaseColorPixel","metallicRoughnessPixel","_getImageDataAsync","metallicRoughnessTextureData","baseColorTextureData","diffusePerceivedBrightness","_getPerceivedBrightness","specularPerceivedBrightness","_getMaxComponent","_SolveMetallic","baseColorFromDiffuse","baseColorFromSpecular","_convertMetalRoughFactorsToMetallicRoughnessAsync","babylonPBRMaterial","glTFPbrMetallicRoughness","glTFTexture","_getTextureSampler","wrapS","_getGLTFTextureWrapMode","wrapT","wrapMode","_convertSpecGlossFactorsToMetallicRoughnessAsync","specGloss","useMicrosurfaceFromReflectivityMapAlpha","samplerIndex","_exportTextureSampler","_convertSpecularGlossinessTexturesToMetallicRoughnessAsync","imageIndex","_exportImage","_exportTextureInfo","_setMetallicRoughnessPbrMaterial","texCoord","_getPixelsFromTexture","extensionPromise","_extensionsPreExportTextureAsync","_exportTextureInfoAsync","textureMimeType","internalTextureToImage","imageIndexPromise","_extensionsPostExportTextures","_imageData","getFileExtensionFromMimeType","_images","textureIndex","convertHandednessMatrix","isNoopNode","convertNodeHandedness","IsIdentity","_Exporter","_applyExtension","actionAsync","currentPromise","_applyExtensions","_ExtensionNames","preExportTextureAsync","_extensionsPostExportMeshPrimitiveAsync","meshPrimitive","babylonSubMesh","postExportMeshPrimitiveAsync","_extensionsPostExportNodeAsync","postExportNodeAsync","postExportMaterialAsync","postExportMaterialAdditionalTextures","postExportTexture","_forEachExtensions","_extensionsOnExporting","wasUsed","_glTF","extensionsUsed","extensionsRequired","onExporting","_loadExtensions","_ExtensionFactories","asset","_bufferViews","_accessors","_cameras","_nodes","_skins","_animations","_orderedImageData","_animationSampleRate","_glTFMaterialExporter","extensionKey","UnregisterExtension","_reorderIndicesBasedOnPrimitiveMode","primitiveMode","babylonIndices","secondIndex","getUInt32","thirdIndex","setUInt32","_reorderVertexAttributeDataBasedOnPrimitiveMode","vertexBufferKind","meshAttributeArray","_reorderTriangleFillMode","_reorderTriangleStripDrawMode","_reorderTriangleFanMode","_getVertexBufferFromMesh","_writeVertexAttributeData","vertexAttributeKind","_NormalizeTangentFromRef","_writeAttributeData","attributeComponentKind","writeBinaryFunc","vertexAttributes","meshMaterial","convertToLinear","setUInt8","setUInt16","vertexAttribute","writeMorphTargetAttributeData","morphTargetAttributeArray","minMax","difference","difference4","morphData","_generateJSON","shouldUseGlb","glTFPrefix","_totalByteLength","imageName","skins","_generateGLTFAsync","_generateBinaryAsync","binaryBuffer","jsonText","bin","glTFFileName","glTFBinFile","_BinaryWriter","_createSceneAsync","_localEngine","getArrayBuffer","_getPadding","_generateGLBAsync","glbFileName","encodedJsonText","jsonLength","imageByteLength","TextEncoder","encode","jsonPadding","binPadding","imagePadding","headerLength","headerBuffer","headerBufferView","jsonChunkBuffer","jsonChunkBufferView","blankCharCode","codePointAt","jsonPaddingView","binaryChunkBuffer","binaryChunkBufferView","binPaddingBuffer","binPaddingView","imagePaddingBuffer","imagePaddingView","glbData","glbFile","_setNodeTransformation","_setCameraTransformation","babylonCamera","attributeKind","bufferMesh","_createBufferViewKind","_setMorphTargetAttributes","vertexNormals","morphNormals","bufferViewIndex","vertexPositions","morphPositions","POSITION","vertexTangents","morphTangents","_getMeshPrimitiveMode","baseMesh","_setPrimitiveMode","_setAttributeKind","COLOR_0","TEXCOORD_0","TEXCOORD_1","JOINTS_0","JOINTS_1","WEIGHTS_0","WEIGHTS_1","_setPrimitiveAttributesAsync","attributeData","accessorComponentType","indexBufferViewIndex","vertexAttributeBufferViews","exportUnusedUVs","_CalculateMinMaxPositions","primitives","glTFNodeIndex","glTFNode","directDescendents","removedRootNodes","metadataSelector","extras","gltf","removeNoopRootNodes","includeCoordinateSystemConversionNodes","cameraMap","shouldExportNode","glTFCamera","yfov","orthographic","xmag","ymag","exportNodes","_getExportNodes","_createNodeMapAndAnimationsAsync","_createSkinsAsync","skinMap","_nodeMap","skin","descendent","promiseChain","_createNodeAsync","_CreateMorphTargetAnimationFromMorphTargetAnimations","_CreateNodeAnimationFromNodeAnimations","idleGLTFAnimation","_CreateNodeAndMorphAnimationFromAnimationGroups","joints","inverseBindMatrices","boneIndexMap","maxBoneIndex","bufferViewOffset","bindMatrixAccessor","inverseBindAccessorIndex","cell","_arrayBuffer","_dataView","_byteOffset","_resizeBuffer","newBuffer","copyOldBufferSize","oldUint8Array","getVector3Float32FromRef","setVector3Float32FromRef","getVector4Float32FromRef","setVector4Float32FromRef","setByte","setInt8","GLTF2Export","filePrefix","exportWithoutWaitingForScene","glTFData","_PreExportAsync","_PostExportAsync","NAME","KHR_texture_transform","_wasUsed","textureTransform","transformIsRequired","RegisterExtension","KHR_lights_punctual","lightType","lightRotationQuaternion","babylonSpotLight","spot","outerConeAngle","innerConeAngle","lightReference","parentBabylonNode","parentTranslation","parentRotation","parentMatrix","KHR_materials_clearcoat","additionalTextures","clearCoatTextureInfo","clearCoatTextureRoughnessInfo","clearCoatNormalTextureInfo","clearCoatInfo","clearcoatFactor","clearcoatTexture","clearcoatRoughnessFactor","clearcoatRoughnessTexture","clearcoatNormalTexture","KHR_materials_iridescence","iridescenceTextureInfo","iridescenceThicknessTextureInfo","iridescenceInfo","iridescenceFactor","iridescenceIor","iridescenceThicknessMinimum","iridescenceThicknessMaximum","iridescenceTexture","iridescenceThicknessTexture","KHR_materials_anisotropy","anisotropyTextureInfo","anisotropyInfo","anisotropyStrength","anisotropyRotation","anisotropyTexture","KHR_materials_sheen","sheenInfo","sheenColorFactor","sheenRoughnessFactor","sheenColorTexture","sheenRoughnessTexture","KHR_materials_unlit","unlitMaterial","KHR_materials_ior","_isExtensionEnabled","iorInfo","KHR_materials_specular","metallicReflectanceTexture","reflectanceTexture","_hasTexturesExtension","specularFactor","specularColorFactor","specularColorTexture","KHR_materials_volume","subs","volumeInfo","thicknessFactor","attenuationDistance","attenuationColor","KHR_materials_transmission","transmissionFactor","transmissionTexture","thinInstanceAdd","refresh","_thinInstanceUpdateBufferSize","thinInstanceSetMatrixAt","thinInstanceAddSelf","thinInstanceRegisterAttribute","_thinInstanceInitializeUserStorage","thinInstanceBufferUpdated","thinInstanceSetAttributeAt","staticBuffer","thinInstancePartialBufferUpdate","forceRefreshParentInfo","NEGATIVE_INFINITY","numInstances","kindIsMatrix","EXT_mesh_gpu_instancing","noTranslation","noRotation","noScale","iwt","iwr","iws","hasAnyInstanceWorldTranslation","hasAnyInstanceWorldRotation","hasAnyInstanceWorldScale","translationBuffer","rotationBuffer","scaleBuffer","_buildAccessor","bufferOffset","accessorIndex","KHR_materials_emissive_strength","tempEmissiveStrength","emissiveStrengthInfo","emissiveStrength","newEmissiveFactor","GLTFKb3dExporter","_glbExportOptions","generateGlb","GLBAsync","createGlbBlob","exportGlb","downloadBlob","exportGltf","GLTFAsync","disposeFuncs","kb3dNode","ColorGradingTexture","_onLoad","_triggerOnLoad","_load3dlTexture","tempData","pixelIndexW","pixelIndexH","pixelIndexSlice","maxColor","_NoneEmptyLineRegex","words","pixelStorageIndex","toLocaleLowerCase","PanoramaToCubeMapTools","inputWidth","inputHeight","supersample","CreateCubemapTexture","FACE_FRONT","FACE_BACK","FACE_LEFT","FACE_RIGHT","FACE_UP","FACE_DOWN","texSize","sampleFactor","sampleFactorSqr","rotDX1","rotDX2","fy","xv1","xv2","CalcProjectionSpherical","px","py","inputY","HDRFiltering","hdrScale","createMipMaps","_prefilterInternal","_effectWrapper","_effectRenderer","intTexture","_createEffect","prefilter","onFinished","HDRTools","mantissa","float32array","red","green","blue","_Ldexp","uint8array","character","_ReadStringLine","endOfHeader","findFormat","dataPosition","hdrInfo","RGBE_ReadHeader","RGBE_ReadPixels","ConvertPanoramaToCubemap","_RGBEReadPixelsRLE","num_scanlines","scanline_width","dataIndex","scanLineArrayBuffer","scanLineArray","resultBuffer","resultArray","_RGBEReadPixelsNOTRLE","_Rgbe2float","HDRCubeTexture","generateHarmonics","prefilterOnLoad","_generateHarmonics","_onError","_prefilterOnLoad","_supersample","previousOnLoad","hdrFiltering","GetCubeMapTextureData","shortArray","dataFace","_FacesMapping","useInGammaSpace","updateVideoTexture","_videoTextureSupported","clearRect","createExternalTexture","GetTGAHeader","id_length","colormap_type","image_type","colormap_index","colormap_length","colormap_size","pixel_size","UploadContent","pixel_data","use_rle","use_pal","use_grey","pixel_total","palettes","x_start","y_start","x_step","y_step","y_end","x_end","TGATools","_getImageData8bits","colormap","_getImageData16bits","_getImageData24bits","_getImageData32bits","_getImageDataGrey8bits","_getImageDataGrey16bits","_TGATextureLoader","BASIS_FORMATS","_HDRTextureLoader","pixelsDataRGB32","pixelsDataRGBA32","BasisToolsOptions","_WorkerPromise","_Worker","_actionId","TranscodeAsync","wasmBinary","initHandler","actionId","messageHandler","dataViewCopy","ignoreSupportedFormats","BindTexture","LoadTextureFromTranscodeResult","transcodeResult","rootImage","levels","cTFRGB565","transcodedPixels","BasisTools","GetInternalFormatFromBasisFormat","basisFormat","cTFETC1","cTFBC1","cTFBC4","cTFASTC_4x4","cTFETC2","cTFBC7","_BASIS_FORMAT","transcoderModulePromise","TranscodeLevel","loadedFile","levelIndex","convertToRgb565","dstSize","getImageTranscodedSizeInBytes","transcodeImage","srcByteOffset","blockWidth","blockHeight","blockY","blockX","dstI","ConvertDxtToRgb565","getImageWidth","getImageHeight","BASIS","initializeBasis","imgData","BasisFile","basisFile","getHasAlpha","imageCount","getNumImages","levelCount","getNumLevels","levelInfo","GetFileInfo","supportedCompressionFormats","bc7","GetSupportedTranscodeFormat","needsConversion","startTranscoding","loadSingleImage","mipCount","loadMipmapLevels","_BasisTextureLoader","transcodeConfig","hasMipmap","NoiseProceduralTexture","octaves","persistence","animationSpeedFactor","_updateShaderUniforms","RefractionTexture","refractionPlane","ch2","u8","u16","u32","fleb","fdeb","clim","freb","eb","revfl","revfd","rev","hMap","mb","co","le","rvb","sv","r_1","flt","fdt","flm","fdm","slc","ec","nt","captureStackTrace","wbits","wbits16","hTree","et","maxSym","tr","mbt","lft","cst","i2_1","i2_2","i2_3","lc","cl","cli","cln","cls","clen","cf","wfblk","dat","wblk","final","syms","lf","df","bs","bl","dlt","mlb","ddt","mdb","lclt","nlc","lcdt","ndc","lcfreq","lct","mlcb","nlcc","ll","dl","flen","ftlen","dtlen","llm","lcts","it","clct","deo","dflt","lvl","plvl","pre","lst","opt","msk_1","bs1_1","bs2_1","hsh","lc_1","wi","hv","imod","pimod","rem","ch_1","dif","maxn","maxd","ml","mmd","md","ti","lin","din","crct","dopt","st","mem","mrg","wcln","fnStr","td","ks","st_1","spInd","wrkr","td_1","$e$","wk","tl","cbfs","bDflt","deflateSync","pbf","wbytes","deflate","consume","cbify","fltn","te","TextDecoder","stream","strToU8","latin1","ar_1","ar","exfl","wzh","ce","extra","exl","os","mtime","crc","attrs","exf","zip","tot","slft","term","tAll","cbd","mt","cbf","oe","cdl","badd","loc","wzf","_loop_1","cr","com","ms","cbl","queueMicrotask","USDZConverter","useWorker","convertGeometry","meshObject","buildGeometryFromBuffers","buildUSDAFile","zipUSDZFiles","buildGeometryFromData","buildGeometryFromObject","buildHeader","dataToInsert","buildXform","appendFileName","escapeGUID","buildMatrixRow","buildMatrix","stringifyIntArray","buildVector3Array","stringifyFloatArray","buildVector2Array","perStruc","toPrecision","canvasResize","USDZBabylonConverter","toCleanup","modelFileName","conversionWorker","asyncGenerators","meshMaterials","baseGeometry","splitGeometryByMaterialId","baseVertexData","ExtractFromGeometry","subMeshMaterial","newIdx","oldIdx","newVertexData","geometryFileName","geometryData","buildGeometryTransferrable","usdConvertGeometry","uuid","buildMaterial","buildMaterials","textureGenerators","FromHexString","isRGBA","processImageData","processSequentially","offsetMod64","padding","usdPackage","cbs","targetTexureSize","resizeContext","HTMLCanvasElement","imagedata","canvasToBlob","dataPromise","Float64Array","pxLength","resizedData","Uint8ClampedArray","widthRatio","heightRatio","destIndex","lastLineOffset","yOffsetTarget","offsetTarget","newV","tMatrix","t2Matrix","t3Matrix","buildTexture","mapType","parsedTextureId","angleDeg","buildColor","microSurfaceTexture","geometryBuffers","XrHitTester","sessionMgr","getHitResult","hits","FromXRHitTestResult","refSpace","xrpos","xrquat","xrResult","ShadowManager","_bbCache","generatorMap","casters","receivers","projectionMatrixCache","rootBoundingBoxChanged","bbInfo","sg","convertShadowResultion","addAllCastersToGenerator","addCaster","removeCaster","toggleCaster","addReceiver","removeReceiver","toggleReceiver","clearProjectMatrixCache","allMeshes","low","medium","high","simple","advanced","XrLight","_originalLightEnabledMap","_shadowManager","bbCache","_sg","rendererManager","sceneRenderer","get3d","DELTA_PHI","XrMarker","naturalScale","MarkerMaterial","place","_placed","hide","bb","resizeToBoundingBox","getWorld","show","animateVisibility","_lineWidth","getVertexData","xSize","zSize","addCorner","numVertices","vdata","cornerX","cornerZ","ShadowOnlyMaterialDefines","ShadowOnlyMaterial","_needAlphaBlending","shadowColor","activeLight","_activeLight","_getFirstShadowLightForMesh","csg","XrShadowPlane","shadowMaterial","newBb","XrTransientHitTester","getFingers","fingers","convertedFingers","convertedHit","eXrState","SCALE_SNAP","Xr","onSessionEnd","_state","searchingForHit","_goalScale","_goalYaw","_lastScalar","_scaleSnapHigh","_scaleSnapLow","_naturalScale","_wasJustPlaced","_lightingEstimationCount","onSelectStart","initialPlacement","placeModel","placed","_initialHitTester","_transientHitTester","_sessionMgr","_lastFrame","_selectStartScreenPos","screenNdcToPixels","_isTranslating","_dragNodeStartPos","_rootNode","dragHitTester","_dragHitTester","_isRotating","interaction","getKb3dPointerArgs","handlePointerDown","_marker","_isScaling","getFingerSeparation","onSelectEnd","_fingerStartPos","screenCoord","handlePointerUp","handleClick","startSession","refSpaceType","overlayElem","xrInitOptions","domOverlay","sessionEnded","_xrCamera","_session","_refSpace","onXRFrame","_originalSceneCamera","_originalBackground","endSession","sessionEndingPromise","_shadow","_viewerPose","placeInitialMarker","processInput","setSceneTransform","runLightingEstimation","_lightProbe","estimate","getLightEstimate","primaryLightDirection","primaryLightIntensity","dragX","dragFingers","dragFingerResult","deltaPos","_goalPosition","requestLightProbe","hardwareScale","getRigCamera","firstFinger","secondFinger","invalidateRootBoundingBox","invalidate","screenPixelsToNdc","IS_IOS","IS_ANDROID","AR","isDebug","xrActive","xrLoading","gltfExporter","onEnterFunc","_onEnterFunc","startWebXR","usdz","whenAssetsLoaded","forceAndWaitForNextRender","relList","supports","currentObjectUrl","rel","endWebXr","_xr","hasDefaultValue","startIosQuickLook","usdzSrc","canScale","modelUrl","toBoundingBoxInfo","binfo","FromVec3","BoundingBoxCache","boundingBoxInvalidated","_digestCount","_watchedNodes","_changedNodes","watchForChanges","refreshAndGet","bnode","childNodes","cbb","parentMin","parentMax","childBNode","boundingBoxesStable","userIsInteracting","watchersToUpdateAndClear","externalWatchers","hasRootWatchers","hasWatchers","oldBoundingBox","boundingBoxChanged","boundingBoxesMatch","bbWatchersSubject","watcher","BoundingBoxRelativeHelper","eSideOrientationBabylonMap","eUvMapAxisBabylonMap","eUvModeBabylonMap","eAlphaModeBabylonMap","createLightVisualization","lightPositionGizmo","Yellow","coloredMaterial","gizmoOffset","Boundary","ymin","ymax","boundaryContains","halfPoint","QuadTree","duplicatesMap","_divided","xSelector","ySelector","divided","quads","nw","ne","sw","se","findByBoundary","proximity","boundary","itemPoint","getWithProximity","searchPoint","positionKey","createDivision","holeIndices","dim","invSize","hasHoles","outerLen","outerNode","linkedList","triangles","steiner","getLeftmost","compareX","eliminateHole","eliminateHoles","earcutLinked","clockwise","signedArea","insertNode","removeNode","filterPoints","again","ear","pass","zOrder","prevZ","nextZ","tail","numMerges","pSize","qSize","inSize","sortLinked","indexCurve","isEarHashed","isEar","cureLocalIntersections","splitEarcut","ax","bx","ay","by","x0","y0","pointInTriangle","locallyInside","isValidDiagonal","splitPolygon","bridge","hx","hy","mx","my","tanMin","sectorContainsSector","findHoleBridge","bridgeReverse","leftmost","intersectsPolygon","inside","middleInside","q2","o1","o2","o3","o4","onSegment","b2","an","bp","sum","deviation","polygonArea","trianglesArea","flatten","holeIndex","SubmeshVertexData","submeshData","kbGeometry","CopyToRef","extractSubmeshData","deepClone","shallowClone","pathIdxOffset","segmentIdxOffset","vertexIdxOffset","newPaths","newHoles","newArr","writeSubmeshes","verifyGeometry","outputError","indicesCount","maxVertex","GLYPH_COORDS_SCALE","IDENTITY_Q","TextMeshPolygon","lerp","conicTo","cubicTo","TextMeshFont","glyphsParent","createGlyph","charToGlyph","advanceWidth","glyphDef","commands","polys","pathSegmentCount","holePaths","poly","coords","parentSegmentIdx","meshdata","flipIndices","TextMeshVertexData","textMeshFont","getText","generatedVertices","ch1","advance","kern","getKerningValue","centerTransform","generatedVertexData","curveTransform","GreasedLineMeshMaterialType","GreasedLineMeshColorMode","GreasedLineMeshColorDistributionType","GreasedLineMeshColorDistribution","GreasedLineMeshWidthDistribution","CreateHemisphere","halfSphere","merged","MaterialGreasedLineDefines","GREASED_LINE_HAS_COLOR","GREASED_LINE_SIZE_ATTENUATION","GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE","GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM","GreasedLinePluginMaterial","DEFAULT_COLOR","sizeAttenuation","colorDistributionType","COLOR_DISTRIBUTION_TYPE_LINE","GREASED_LINE_MATERIAL_NAME","useDash","dashRatio","dashOffset","DEFAULT_WIDTH_ATTENUATED","DEFAULT_WIDTH","_sizeAttenuation","colorMode","COLOR_MODE_SET","_color","useColors","_colorsDistributionType","COLOR_DISTRIBUTION_TYPE_SEGMENT","colorsSampling","_colors","dashCount","_createColorsTexture","_PrepareEmptyColorsTexture","_colorsTexture","resolutionLineWidth","_aspect","dashOptions","_BooleanToNumber","_dashArray","colorModeVisibilityColorsWidthUseColors","_EmptyColorsTexture","CUSTOM_VERTEX_DEFINITIONS","CUSTOM_VERTEX_UPDATE_POSITION","CUSTOM_VERTEX_MAIN_END","CUSTOM_FRAGMENT_DEFINITIONS","CUSTOM_FRAGMENT_MAIN_END","COLOR_MODE_ADD","COLOR_MODE_MULTIPLY","colorTable","_Color3toRGBAUint8","setColors","lazy","origColorsCount","colorArray","updateLazy","_dashCount","setColor","doNotMarkDirty","colorsDistributionType","greasedLineMaterialOptions","GreasedLineTools","vi1","vi2","vi3","pointsFromPredicate","counts","ToVector3Array","segmentCount","dividedLinePoints","segmentVector","nextPoint","what","segmentLength","subLines","GetLineSegments","SegmentizeSegmentByCount","seg","GetLineLength","SegmentizeLineBySegmentLength","lineSegments","lineLength","visbility","localSpace","lengthVisibilityRatio","sumSegmentLengths","segmentIndex","lineSegmentsLength","segmentAngle","widthUp","widthDown","widthStartUp","widthStartDown","widths","includeInner","allPoints","points2d","p2d","GreasedLineMesh","_lazy","_vertexPositions","_colorPointers","colorPointers","_widths","_previousAndSide","_nextAndCounters","addPoints","ConvertPoints","setPoints","_updateColorPointers","_createVertexBuffers","greasedLineMaterial","isLazy","_offsets","_offsetsBuffer","_createOffsetsBuffer","_widthsBuffer","_colorPointersBuffer","pointsCopy","colorPointer","jj","_initGreasedLine","indiceOffset","totalLength","partialLine","_preprocess","_createLineOptions","lineOptions","deepCopiedLineOptions","cloned","intersections","findAllIntersections","intersection","_fastCheck","_trianglePredicate","_worldToUse","firstOnly","_boundingSphere","_V_START","_V_END","_V_OFFSET_START","_V_OFFSET_END","iFloored","positionIdx1","positionIdx2","arrayIdx1","arrayIdx2","positionIdx","_CompareV3","_CopyV3","previousAndSideBuffer","nextAndCountersBuffer","widthBuffer","colorPointersBuffer","offsetBuffer","pWorking","uv3","workingUv","workingUv2","working1","UVMapHelper","generateUVMapInPlace","indexList","newControlPointMap","transformMatrixInv","geometryPositions","geometryIndices","controlPointCount","newUvs","appendVertexData","touchedControlPoints","outputUvs","useExisting","uvIdx","newU","start2","start3","updateFaceUVMapToRef","expandControlPoints","newPositions","newNormals","newUvsTyped","newUv","newVertexIndex","computeAutoFitSize","feat","planar","planarUVMap","boxUVMap","cylindrical","cylindricalUVMap","spherical","sphericalUVMap","lon","nx","ny","nz","newVertex","lonlat","lo","la","lat","xyzToLongitudeLatitude","createUvMapVisualization","uvMap","uvMapVisualization","excludeVertices","vertexGroup","vertexGroupsIntersect","createViewpointVisualization","viewpoint","targetPositionMarker","viewpointPositionGizmo","lightPositionGizmoBox","Renderer","viewer","babylonMap","handlesNode","modelToken","update3d","update3dInternal","validator","validateNode","delete3d","nodeDeletionProcessed","set3d","babylonObject","getChanges","isNew","TEXT_RESOLUTION","AnnotationRenderer","annotationStore","billboards","utilityLayer","meshInfo","parentRotationQuat","annotationInfo","positionNeedsUpdate","textNeedsUpdate","lineNeedsUpdate","createAnnotationTextModels","parentSceneMesh","getRendererNode","needsFont","fontService","targetNode","updatePositionFromAnnotation","textContainer","textRotation","lineOffset","basePoint","drawLine","updateAnnotationText","textMesh","textMaterial","keepInStore","annotationModels","newDirection","getPositionFromConnnector","newOffset","newPivot","calculateTransform","containerMesh","planeContainer","webgl1Context","labelSize","labelText","mathExp","numberVal","mathEval","evalHandlebarString","textGap","textColor","toColor3","labelStats","fullStringTextSize","substrings","lineWidths","maximumWidth","maximumHeight","maximumDescent","string","actualBoundingBoxLeft","actualBoundingBoxRight","textWidth","actualBoundingBoxAscent","actualBoundingBoxDescent","labelArray","getMultiLineStats","textHeight","totalCanvasHeight","heightRatioChange","drawFont","textBaseline","CanvasRenderingContext2D","setTransform","relativeToScene","connector","sceneMesh","offsetWithTransform","lineOffsetWithTransform","lineInfo","linesMesh","solid","dashed","loopCount","DimensionRenderer","watchPosition","dimensionStore","dimensionInfo","maintainNodeScreenSize","updateLineFromCamera","clearMaintainedNodeScreenSize","editorMode","lineCap","updateDimensionControlPoints","updateDimensionLineColor","lineCapsMesh","distanceDefaultVal","precisionMultiplier","dimensionModels","deleteLine","updateLine","dimensionModel","annotationMesh","target1","target2","targetNode2","position1","position2","angleAdjustment","startConnector","endConnector","dimensionLine","startPostion","endPosition","free","rectifiedDimensionLine","lineDirectionCross","capSize","lineToStartConnector","endOffset","lineToEndConnector","arrow","capArrowOffset","lineCapOptions","lineColor","CONNECTOR_DIAM","ConnectorRenderer","subscriptionMap","controlPointScaleRatio","template","withArrows","forceScreenScale","realLayer","utilityMesh","realParts","utilityParts","scaledSize","handleContainer","directionHandle1","directionHandle2","_isPickable","moveAlongSketch","updatePosition","updateDirection","addSubscription","removeSubscription","_visible","getSelectedMaterial","getConnectorMaterial","updateScale","updatePositionMoveAlongSketch","convertRelativeToAbsolute","referenceProcessor","triggerChangesOnReferencers","updateDirectionMoveAlongSketch","normalVector","connectorDirection","angleRot","angleRotMatrix","parentDirection","newQuaternion","deltaBtwXaxisAndDirection","worldScale","posZeroToOne","trackedLength","targetNotFound","lastLength","percentageBetween2Points","vectorBetween2Points","calculatedPosition","controlPoint","lastPathVector","nextPathVector","nextPosition","nextNextPosition","calculatedDirection","createMeshTemplate","parent3d","ball","arrowHead","arrowShaft","twoTone","connectorMaterial","KbmaxOrange","highlightColor","selectedMaterial","FeatureRenderer","vertexDataCache","updateMeshGeometryCache","vertexDataChanges","cachedData","clearVertexDataCache","updateVertexDataCache","cachedSubmeshes","updateMeshGeometry","preserveCache","clearCache","MoveVerticesRenderer","parentMesh","newMeshVertexPositions","scaleVector","meshPivotPoint","currentMeshVertexPositions","vertexPosition","NormalSmoothingRenderer","vertexNeighbors","planeNormals","vectorA","vectorB","vectorC","totalSelectedIndices","groupA","groupB","planeNormal","submeshDataArray","planeCoordinates","planePositions","calculateNormalToRef","neighbor","newNormal","calculateSmoothedUnitVector","planeNormalArray","calculateUnitVector","visitedVertices","currentNormal","currentUv","resultPositions","resultNormals","resultUvs","updateNormalSmoothingWarnings","divider","SolidParticle","particleId","indiceIndex","shapeId","idxInShape","sps","modelBoundingInfo","velocity","translateFromPivot","alive","_ind","_stillInvisible","_rotationMatrix","_model","_sps","_modelBoundingInfo","copyToRef","_bSphereOnly","ModelShape","shapeID","shapeUV","posFunction","vtxFunction","_indicesLength","_shape","_shapeUV","_shapeColors","_positionFunction","_vertexFunction","DepthSortedParticle","indLength","SolidParticleVertex","SolidParticleSystem","particles","nbParticles","recomputeNormals","counter","vars","_bSphereRadiusFactor","_pickable","_isVisibilityBoxLocked","_alwaysVisible","_depthSort","_expandable","_shapeCounter","_copy","_computeParticleColor","_computeParticleTexture","_computeParticleRotation","_computeParticleVertex","_computeBoundingBox","_autoFixFaceOrientation","_depthSortParticles","_mustUnrotateFixedNormals","_particlesIntersect","_needs32Bits","_isNotBuilt","_lastParticleId","_idxOfId","_multimaterialEnabled","_useModelMaterial","_depthSortFunction","_materialSortFunction","_autoUpdateSubMeshes","_recomputeInvisibles","enableDepthSort","enableMultiMaterial","useModelMaterial","expandable","particleIntersection","boundingSphereOnly","bSphereRadiusFactor","computeBoundingBox","autoFixFaceOrientation","pickedBySubMesh","pickedParticles","depthSortedParticles","_multimaterial","_materialIndexesById","_tmpVertex","buildMesh","addShape","_indices32","_positions32","_uvs32","_colors32","_sortParticlesByMaterial","_normals32","_fixedNormal32","_unrotateFixedNormals","lind","pickedData","setMultiMaterial","digest","meshPos","meshInd","meshUV","meshCol","meshNor","totalFacets","facetPos","facetNor","facetInd","facetUV","facetCol","sizeO","fi","_posToShape","_uvsToShapeUV","shapeInd","shapeCol","shapeNor","_setDefaultMaterial","modelShape","currentInd","_meshBuilder","_addParticle","tmpNormal","invertedRotMatrix","pt","_resetCopy","storeApart","materialIndexesById","matIdx","tmpVertex","tmpColor","tmpUV","tmpRotated","pivotBackTranslation","scaledPivot","someVertexFunction","vertexFunction","copyUvs","current_ind","idxpos","idxind","shapeNormals","shapeColors","posfunc","vtxfunc","_insertNewParticle","_rebuildParticle","rebuildMesh","removeParticles","currentNb","firstRemaining","shiftPos","shifInd","particlesLength","modelIndices","modelNormals","modelColors","modelUVs","insertParticlesFromArray","solidParticleArray","currentShapeId","noNor","newPart","currentCopy","setParticles","beforeUpdateParticles","colors32","indices32","fixedNormal32","depthSortParticles","tempVectors","camAxisX","camAxisY","camAxisZ","camInvertedPosition","tmpVector0","colidx","uvidx","uvIndex","vpos","updateParticle","particleRotationMatrix","particlePosition","particleRotation","particleScaling","particleGlobalPosition","dsp","getParticleById","parentGlobalPosition","rotatedY","rotatedX","rotatedZ","rotMatrixValues","iu","iv","updateParticleVertex","vertexX","vertexY","vertexZ","pz","normalx","normaly","normalz","rotatedx","rotatedy","rotatedz","bBox","modelBoundingInfoVectors","tempMin","tempMax","scaledX","scaledY","scaledZ","minBbox","maxBbox","bSphereCenter","halfDiag","bSphereMinBbox","bSphereMaxBbox","vbp","dspl","sid","sortedParticle","particleInd","particleIdx","faceInd","computeSubMeshes","afterUpdateParticles","_materialIndexes","_indicesByMaterial","pickedParticle","picked","getParticlesByShapeId","getParticlesByShapeIdToRef","sortedPart","indicesByMaterial","materialIndexes","vcount","subMeshIndex","lastMatIndex","_setMaterialIndexesById","_filterUniqueMaterialId","refreshVisibleSize","setVisibilityBox","vis","isAlwaysVisible","isVisibilityBoxLocked","computeParticleRotation","computeParticleColor","computeParticleTexture","computeParticleVertex","multimaterialEnabled","multimaterial","autoUpdateSubMeshes","initParticles","recycleParticle","ensureNormalsExist","patternStore","identityRotation","PatternRenderer","setParticlePositionFunc","_pattern","meshUpdated","tempVertexData","sketchNode","getNode","positionArray","getPositionArray","sketchPosition","newPattern","featureUpdaters","sourceNode","needsUpdate","needsRebuild","needsSubmeshRebuild","updates","featureItemIndex","nextUpdateFunction","featureId","processParticleSystem","resultVertexData","resultMesh","totalIndicesSourceCount","totalVerticesSourceCount","submeshesToClone","totalIndicesResultCount","totalVerticesResultCount","baseMaterialIndex","spsPatternSize","numberOfMeshes","percentagePoints","getIntervalPosition","lastPath","lastPointVec3","uvHelper","multiMaterialUseCount","featureMappings","SubmeshRenderer","submeshFeatureMapping","multiMaterialIndex","newSubmesh","existingIndex","existingSubmesh","uvMapVertexes","existingUvs","_submeshFeatureMapping","fetchMaterialNode","materialNode","existingSubmaterialIndex","UvMapRenderer","babylonUvPreviewsMap","previewLayer","updatePreviewMesh","visualizationMesh","deletePreview3d","meshPosition","_previewMaterialVisible","previewMesh","LightRenderer","showPreviews","showAllLightPreviews","shadowManager","babylonLightPreviewsMap","gizmoLayer","pLight","lightRotation","rotationChanged","rotateDirection","shadowLightNode","shadowLight","justCreated","convertShadowFilter","selected","updateLightWarnings","getLightPosition","MateRenderer","removeReflectionProbe","addReflectionProbe","newReflectionProbe","ReflectionProbe","useFloat","_add","_invertYAxis","_renderTargetTexture","currentApplyByPostProcess","_attachedMesh","lookAtFunction","perspectiveFunction","PerspectiveFovRH","PerspectiveFovLH","isReflectionProbe","parsedReflectionProbe","rp","MaterialRenderer","textureRenderer","_globalMaterialCache","orphanedMeshes","reflectionProbeMap","reflectedMeshes","meshesUsingReflectionMaterial","_renderMode","setRenderModeOnMaterial","getAllDefinedMaterials","getGlobalMaterial","_globalMaterialManager","materialDeleted","materialWarningsNeedsUpdate","loadGlobalMaterial","managerServices","matService","imaterial","matNode","newMatNode","pbrAdvMaterial","meshesToBind","_pbrAdvMaterial","updateReflectionProbes","exceptions","sceneBackground","connectorMesh","noPlane","reflector","setTransparency","tangentTexture","anisotropyTangent","clearCoatNormal","refractionProbe","subsurfaceThicknessTexture","hiddenEdges","getNumberOfMaterialRef","nrefs","exceptionList","keyValuePair","connectorId","parseSketchGeometry","currentHole","segmentPoints","currentHolePoints","createSketchPointForEditor","insertIndex","sketch","previousControlPoint","currentPathIndex","previousPath","sketchNormal","getSketchNormalVector3","rawDirection","projectedDirection","eC","projectOnNodeAxis","axisToVector3","fillSketchPolygon","positionVectors","sketchNativeNormal","holePositions","getPolygonNormal","segmentPositions","segmentIndices","flatPositions","working","calculateFaceNormalFromFloats","calculateFaceNormal","segmentNormals","geometryNormal","totalVectorCount","segmentUvs","pathHandedness","iP","$defineProperty","Tree","table","Data","sourceIndex","bitcount","destLen","ltree","dtree","sltree","sdtree","length_bits","length_base","dist_bits","dist_base","clcidx","code_tree","lengths","tinf_build_bits_base","offs","tinf_build_tree","off","tinf_getbit","bit","tinf_read_bits","tinf_decode_symbol","tinf_decode_trees","lt","hlit","hdist","hclen","sym","tinf_inflate_block_data","tinf_inflate_uncompressed_block","tinf_build_fixed_trees","tinyInflate","bfinal","derive","Path","strokeWidth","fail","argument","addPoint","addX","addY","addBezier","const","let","b2ac","addQuad","cp1x","cp1y","cp2x","cp2y","curveTo","quadTo","pathOrCommands","prevX","prevY","cmd","toPathData","decimalPlaces","floatToString","packValues","arguments$1","toSVG","svg","toDOMElement","temporaryPath","newPath","createElementNS","LIMIT32","sizeOf","constant","CHAR","CHARARRAY","USHORT","UINT24","ULONG","LONG","FIXED","FWORD","UFWORD","LONGDATETIME","TAG","Card8","Card16","OffSize","SID","NUMBER","NUMBER16","NUMBER32","REAL","nibbles","STRING","UTF8","numBytes","codePoints","numChars","UTF16","codepoint","eightBitMacEncodings","macintosh","MACSTRING","encoding","macEncodingCacheKeys","macEncodingTableCache","WeakMap","isByteEncodable","encodeVarDeltaRunAsZeroes","deltas","runLength","numDeltas","encodeVarDeltaRunAsBytes","encodeVarDeltaRunAsWords","cacheKey","cachedTable","decodingTable","encodingTable","getMacEncodingTable","VARDELTAS","INDEX","OBJECT","encodedOffsets","offSize","offsetEncoder","encodedOffset","DICT","OPERAND","OPERATOR","OP","wmm","Table","tableName","field","optionKeys","ushortList","itemName","tableList","records","itemCallback","recordList","Coverage","coverageTable","RangeRecord","ScriptList","scriptListTable","scriptRecord","defaultLangSys","reqFeatureIndex","featureIndexes","langSysRecords","langSysRecord","langSys","FeatureList","featureListTable","featureRecord","featureParams","lookupListIndexes","LookupList","lookupListTable","subtableMakers","lookupTable","subtableCallback","lookupType","lookupFlag","subtables","CHARSTRING","ops","cachedValue","op","encodingFunction","sizeOfFunction","TABLE","subtableOffsets","RECORD","LITERAL","Record","getByte","getUShort","getULong","getFixed","typeOffsets","byte","uShort","short","uLong","longDateTime","Parser","relativeOffset","parseByte","parseChar","parseCard8","parseUShort","parseCard16","parseSID","parseOffset16","parseShort","parseF2Dot14","parseULong","parseOffset32","parseFixed","parseString","parseTag","parseLongDateTime","parseVersion","minorBase","major","minor","skip","parseULongList","parseOffset16List","parseUShortList","parseShortList","parseByteList","parseList","parseList32","parseRecordList","recordDescription","rec","fieldName","fieldType","parseRecordList32","parseStruct","struct","parseValueRecord","valueFormat","valueRecord","xPlacement","yPlacement","xAdvance","yAdvance","xPlaDevice","yPlaDevice","xAdvDevice","yAdvDevice","parseValueRecordList","valueCount","parsePointer","structOffset","parsePointer32","parseListOfLists","subOffsets","subList","parseCoverage","startOffset","parseClassDef","startGlyph","classId","list32","recordList32","pointer32","offset16","uShortList","offset32","uLongList","coverage","classDef","langSysTable","reserved","parseScriptList","parseFeatureList","parseLookupList","lookupTableParsers","useMarkFilteringSet","markFilteringSet","parseFeatureVariationsList","majorVersion","minorVersion","conditionSetOffset","featureTableSubstitutionOffset","getCard8","getCard16","getShort","getTag","getBytes","bytesToString","addSegment","glyphIndex","cmap","numTables","platformId","encodingId","groupCount","language","glyphIndexMap","startCharCode","endCharCode","startGlyphId","parseCmapTableFormat12","segCount","endCountParser","startCountParser","idDeltaParser","idRangeOffsetParser","glyphIndexOffset","endCount","startCount","idDelta","idRangeOffset","parseCmapTableFormat4","make","isPlan0Only","unicode","cmapTable","unicodes","addTerminatorSegment","segCountToRemove","endCounts","startCounts","idDeltas","idRangeOffsets","glyphIds","cmap12Groups","segment","glyphId","segCountX2","searchRange","entrySelector","rangeShift","cmap4Length","cmap12Length","cmap12Offset","cffStandardStrings","cffStandardEncoding","cffExpertEncoding","standardNames","DefaultEncoding","CmapEncoding","CffEncoding","charset","GlyphNames","names","numberOfGlyphs","glyphNameIndex","addGlyphNames","lowMemory","_IndexToUnicodeMap","tables","charCodes","addGlyphNamesToUnicodeMap","addUnicode","cffEncoding","isCIDFont","glyphNames","glyphIndexToName","addGlyphNamesAll","charToGlyphIndex","charName","nameToGlyphIndex","gid","Glyph","bindConstructorValues","defineDependentProperty","externalName","internalName","GlyphSet","unitsPerEm","_path","xMin","xMax","getPath","hPoints","hinting","getCommands","getContours","currentContour","lastPointOfContour","getMetrics","xCoords","yCoords","leftSideBearing","rightSideBearing","drawPoints","drawCircles","blueCircles","redCircles","drawMetrics","_push","unicodeObj","_hmtxTableData","glyphset","glyphLoader","ttfGlyphLoader","parseGlyph","buildPath","cffGlyphLoader","parseCFFCharstring","charstring","calcCFFSubroutineBias","subrs","parseCFFIndex","conversionFn","objectOffset","objects","offsetSize","parseOperand","b0","lookup","n2","parseFloatOperand","parseCFFDict","operands","entriesToObject","getCFFString","interpretDict","dict","meta","newDict","TOP_DICT_META","PRIVATE_DICT_META","parseCFFTopDict","parseCFFPrivateDict","gatherCFFTopDicts","cffIndex","topDictArray","iTopDict","topDict","_subrs","_subrsBias","_defaultWidthX","_nominalWidthX","privateSize","private","privateOffset","privateDict","defaultWidthX","nominalWidthX","subrIndex","_privateDict","c1x","c1y","c2x","c2y","subrsBias","nStems","haveWidth","fdIndex","cff","_fdSelect","fdDict","_fdArray","newContour","parseStems","b1","b3","b4","codeIndex","subrCode","jpx","jpy","c3x","c3y","c4x","c4y","gsubrsBias","gsubrs","encodeString","makeDict","makeTopDict","makeTopDictIndex","topDicts","glyphToOps","_13","_23","dx1","dy1","dx2","dy2","formatMajor","formatMinor","parseCFFHeader","nameIndex","topDictIndex","stringIndex","globalSubrIndex","ros","fdArrayOffset","fdArray","fdSelectOffset","fdSelect","fdArrayIndex","nGlyphs","fdArrayCount","iGid","nRanges","iRange","parseCFFFDSelect","numGlyphs","charStringsIndex","privateDictOffset","subrOffset","parseCFFIndexLowMemory","charStrings","parseCFFCharset","enc","nCodes","nLeft","parseCFFEncoding","charString","getCffIndexObject","fontScale","fullName","familyName","weightName","fontBBox","fontMatrix","fontNames","makeNameIndex","postScriptName","charsets","glyphSID","makeCharsets","makeCharStringsIndex","makePrivateDict","makeStringIndex","fontRevision","checkSumAdjustment","magicNumber","created","macStyle","lowestRecPPEM","fontDirectionHint","indexToLocFormat","glyphDataFormat","createdTimestamp","hhea","ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","metricDataFormat","numberOfHMetrics","hmtx","numMetrics","parseHmtxTableOnLowMemory","parseHmtxTableAll","ltag","stringPool","stringPoolOffset","tableVersion","numTags","maxp","maxPoints","maxContours","maxCompositePoints","maxCompositeContours","maxZones","maxTwilightPoints","maxStorage","maxFunctionDefs","maxInstructionDefs","maxStackElements","maxSizeOfInstructions","maxComponentElements","maxComponentDepth","nameTableNames","macLanguages","macLanguageToScript","windowsLanguages","getLanguageCode","platformID","languageID","utf16","macScriptEncodings","macLanguageEncodings","getEncoding","encodingID","reverseDict","makeNameRecord","nameID","addStringToPool","pool","needle","haystack","needleLength","findSubArray","stringOffset","translations","nameIDs","namesWithNumericKeys","nameTableIds","macLanguageIds","windowsLanguageIds","nameRecords","lang","macPlatform","macLanguage","macScript","macEncoding","macName","macNameOffset","winLanguage","winName","winNameOffset","unicodeRanges","begin","os2","xAvgCharWidth","usWeightClass","usWidthClass","fsType","ySubscriptXSize","ySubscriptYSize","ySubscriptXOffset","ySubscriptYOffset","ySuperscriptXSize","ySuperscriptYSize","ySuperscriptXOffset","ySuperscriptYOffset","yStrikeoutSize","yStrikeoutPosition","sFamilyClass","panose","ulUnicodeRange1","ulUnicodeRange2","ulUnicodeRange3","ulUnicodeRange4","achVendID","fsSelection","usFirstCharIndex","usLastCharIndex","sTypoAscender","sTypoDescender","sTypoLineGap","usWinAscent","usWinDescent","ulCodePageRange1","ulCodePageRange2","sxHeight","sCapHeight","usDefaultChar","usBreakChar","usMaxContent","getUnicodeRange","italicAngle","underlinePosition","isFixedPitch","minMemType42","maxMemType42","minMemType1","maxMemType1","nameLength","subtableParsers","substFormat","deltaGlyphId","substitute","sequences","alternateSets","ligatureSets","ligGlyph","lookupRecordDesc","sequenceIndex","lookupListIndex","ruleSets","glyphCount","substCount","lookupRecords","classSets","chainRuleSets","backtrack","lookahead","backtrackClassDef","inputClassDef","lookaheadClassDef","chainClassSet","backtrackCoverage","inputCoverage","lookaheadCoverage","extensionLookupType","extensionParser","substitutes","subtable","sequenceSet","alternateSet","ligatureSet","ligature","returnTable","chainRuleSet","chainRule","tableData","record","gsub","scripts","lookups","variations","numDataMaps","computeCheckSum","makeTableRecord","checkSum","makeSfntTable","sfnt","highestPowerOf2","recordFields","tableFields","tableLength","tableRecord","r1","r2","metricsForChar","notFoundMetrics","fontToTable","firstCharIndex","xMins","yMins","xMaxs","yMaxs","advanceWidths","leftSideBearings","rightSideBearings","lastCharIndex","globals","advanceWidthAvg","maxLeftSideBearing","headTable","hheaTable","maxpTable","os2Table","hasChar","hmtxTable","englishFamilyName","getEnglishName","englishStyleName","englishFullName","uniqueID","en","preferredFamily","preferredSubfamily","fontSubfamily","languageTags","nameTable","ltagTable","postTable","cffTable","metaTable","metas","sfntTable","checkSumAdjusted","searchTag","imin","imax","imid","binSearch","Layout","Position","Substitution","arraysEqual","getSubstFormat","defaultSubtable","checkArgument","parseGlyphCoordinate","shortVectorBitMask","sameBitMask","numberOfContours","_xMin","_yMin","_xMax","_yMax","endPointIndices","instructionLength","instructions","numberOfCoordinates","onCurve","isComposite","moreComponents","scale01","scale10","matchedPoints","transformPoints","newPoints","newPt","contourIndex","contour","curr","next2","componentGlyph","transformedPoints","firstPt","secondPt","getTable","createDefaultTable","getScriptNames","getDefaultScriptName","hasLatn","getScriptTable","scr","getLangSysTable","scriptTable","getFeatureTable","featIndexes","allFeatures","getLookupTables","featureTable","allLookups","getGlyphClass","classDefTable","getCoverageIndex","expandCoverage","defaultKerningTables","getKerningTables","kerningLookups","leftIndex","rightIndex","covIndex","posFormat","pairSet","pairSets","pair","secondGlyph","class1","classDef1","class2","classDef2","classRecords","gpos","getSingle","substitutions","lookupTables","getMultiple","replacements","getAlternates","alternates","getLigatures","ligatures","ligSet","lig","addSingle","substitution","coverageGlyph","addMultiple","addAlternate","addLigature","ligComponents","ligatureTable","getFeature","instructionTable","execGlyph","execComponent","glyf","loca","parseGlyfTableOnLowMemory","parseGlyfTableAll","Hinting","_fpgmState","_prepState","_errorState","roundOff","roundToGrid","roundToDoubleGrid","roundToHalfGrid","roundUpToGrid","roundDownToGrid","roundSuper","period","srPeriod","phase","srPhase","srThreshold","xUnitVector","xo","interpolate","rp1","rp2","pv","do1","do2","doa1","doa2","dm1","dm2","setRelative","normalSlope","org","rpx","rpy","yo","rpdx","rpdy","xTouched","untouch","yUnitVector","yTouched","UnitVector","getUnitVector","HPoint","prevPointOnContour","nextPointOnContour","preventExtensions","pvns","fvs","nextTouched","prevTouched","HPZero","defaultState","cvCutIn","deltaBase","deltaShift","minDis","autoFlip","State","prog","zp0","zp1","zp2","rp0","fv","dpv","initTZone","tZone","gZone","handleElse","ins","ip","nesting","SVTCA","DEBUG","SPVTCA","SFVTCA","SPVTL","p2i","p1i","SFVTL","POP","MDAP","z0","IUP","cp","np","pLen","SHP","rpi","SHC","ci","SHZ","MSIRP","MIAP","cv","cvt","GC","MD","pi1","DELTAP123","ppem","ds","ROUND","DELTAC123","SDPVTL","PUSHB","PUSHW","MDRP_MIRP","indirect","setRp0","keepD","ro","od","cvte","rp0i","activeState","ContextRange","contextName","ContextChecker","checkStart","checkEnd","openRange","ContextParams","Event","eventId","subscribers","initializeCoreEvents","this$1","coreEvents","updateContextsRanges","Tokenizer","registeredContexts","contextCheckers","registeredModifiers","isArabicChar","isIsolatedArabicChar","isTashkeelArabicChar","isLatinChar","FeatureQuery","SubstitutionAction","lookupCoverage","singleSubstitutionFormat1","singleSubstitutionFormat2","substituteIndex","lookupCoverageList","coverageList","contextParams","lookupList","lookupIndex","chainingSubstitutionFormat3","lookupsCount","inputLookups","lookaheadOffset","lookaheadContext","lookaheadParams","lookaheadLookups","backtrackContext","backtrackParams","backtrackLookups","getLookupByIndex","getLookupMethod","getSubstitutionType","ligatureSubstitutionFormat1","ligSetIndex","decompositionSubstitutionFormat1","prepState","fpgmState","fpgm","funcs","prep","oCvt","cg","gz","cc","gLen","inhibitGridFit","pa0i","pa1i","pb0i","pb1i","pa0","pa1","pb0","pb1","x3","y3","x4","y4","cip","cprog","ipBegin","rp1i","rp2i","e2","sel","ignoreCvt","getState","stateId","inboundIndex","composeRUD","RUDs","RUD","hasFAILObject","FAIL","replaceRange","silent","isTokenType","replaced","replaceToken","removeRange","removeToken","insertToken","registerModifier","modifierId","modifier","newToken","conditionParams","modifierParams","newStateValue","subsId","setCurrentIndex","rangeToText","getRangeTokens","on","registerContextChecker","contextStartCheck","contextEndCheck","getContextRanges","resetContextsRanges","runContextCheck","setEndOffset","rangeId","contextChecker","tokenize","getDefaultScriptFeaturesIndexes","getScriptFeaturesIndexes","scriptTag","mapTagsToFeatures","getScriptFeatures","featuresIndexes","lookupFeature","getFeatureLookups","getLookupSubtables","substType","supportedScript","supportedFeature","scriptFeatures","arabicWordCheck","startCheck","prevChar","endCheck","nextChar","arabicSentenceCheck","nextIsWhitespace","isWhiteSpace","arabicCharAhead","SUBSTITUTIONS","subst","compsCount","applySubstitution","arabicPresentationForms","featuresTags","tokenizer","charContextParams","CONNECT","isolated","tashkeel","willConnectPrev","willConnectNext","getContextParams","arabicRequiredLigatures","latinWordCheck","latinLigature","Bidi","baseDir","checkId","contextChecks","tokenizeText","reverseArabicSentences","rangeTokens","checkGlyphIndexStatus","applyArabicPresentationForms","applyArabicRequireLigatures","applyLatinLigatures","Font","styleName","designer","designerURL","manufacturer","manufacturerURL","license","licenseURL","copyright","trademark","weightClass","usWeightClasses","MEDIUM","widthClass","usWidthClasses","fsSelectionValues","REGULAR","_hinting","outlinesFormat","HintingTrueType","addName","nameString","nameKey","makeFvarAxis","minValue","parseFvarAxis","makeFvarInstance","inst","axisTag","parseFvarInstance","setText","registerFeatures","supportedTags","applyFeatures","checkContextReady","contextId","applyFeaturesToContexts","processText","getBidiText","getTextGlyphs","updateFeatures","defaultRenderOptions","stringToGlyphs","bidi","notdef","nameToGlyph","leftGlyph","rightGlyph","gposKerning","kerningPairs","kerning","forEachGlyph","letterSpacing","tracking","fullPath","gX","gY","gFontSize","glyphPath","getPaths","glyphPaths","getAdvanceWidth","assertNamePresent","englishName","toTables","toBuffer","intArray","webkitURL","createEvent","initEvent","dispatchEvent","fs","require","ab","arrayBufferToNodeBuffer","writeFileSync","ITALIC","UNDERSCORE","NEGATIVE","OUTLINED","STRIKEOUT","BOLD","USER_TYPO_METRICS","WWS","OBLIQUE","ULTRA_CONDENSED","EXTRA_CONDENSED","CONDENSED","SEMI_CONDENSED","SEMI_EXPANDED","EXPANDED","EXTRA_EXPANDED","ULTRA_EXPANDED","THIN","EXTRA_LIGHT","LIGHT","SEMI_BOLD","EXTRA_BOLD","BLACK","fvar","offsetToData","axisCount","axisSize","instanceSize","instanceStart","attachList","attachPoints","caretValue","pointindex","ligCaretList","ligGlyphs","markGlyphSets","gdef","markAttachClassDef","posformat","valueFormat1","valueFormat2","class1Count","class2Count","pairs","subtableVersion","nPairs","parseWindowsKernTable","parseMacKernTable","shortVersion","parseFn","glyphOffsets","glyphOffset","parseOpenTypeTableEntries","tableEntries","checksum","uncompressTable","tableEntry","inBuffer","compressedLength","outBuffer","inflate","parseBuffer","cffTableEntry","fvarTableEntry","glyfTableEntry","gdefTableEntry","gposTableEntry","gsubTableEntry","hmtxTableEntry","kernTableEntry","locaTableEntry","nameTableEntry","metaTableEntry","signature","flavor","compLength","origLength","parseWOFFTableEntries","locaTable","locaOffsets","glyfTable","kernTable","gdefTable","gposTable","gsubTable","fvarTable","primitiveShapeProperties","capModeMap","both","textMeshFonts","MeshRenderer","pivotGizmos","sketchPreviews","sketchTracings","sketchPlanePreviews","gizmo","setRenderMode","setRenderModeOnMesh","loadNewGeometry","invalidateBoundingBox","parentsVisible","isNewMesh","createOrUpdateMesh","pivotGizmo","oldPreview","createSketchPlaneVisualization","SketchPlancePreviewMesh","updateParentMeshFromNode","rebuildBaseGeometry","preTransformChanged","meshVertexData","createPrimitiveMesh","setBabylonUvData","preTransformVertices","getMeshVertexData","buildSketchGeometry","buildTextGeometry","pathSegmentIndices","pathGroupKeys","holePathsReferencingKeys","currentPath","thisPoint","primaryNormal","holesByPathsWithIndices","parentPathIndex","reorderedPathSegmentIndices","positionPointer","holesPositions","hi","holeData","newMeshVertices","indexMapToGrouped","indexOfPath","startingPoints","calculatedBoundingBox","calculateSketchBoundingBox","updateSketchPreview","segmentColors","newPreviewMesh","updateSketchTracing","sketchColor","linePoints","vertexDataBuilder","openTypeFont","fontParse","getMeshGeometry","localMaterial","globalLibMaterial","FromGeometry","cachedGeometry","existingTransform","_hasTransform","PRESERVE_PROPERTY","updateMeshTransform","recursiveLoadChildMeshGeometry","allChanges","meshVerticesNeedReset","setBabylonVertexData","updateConnectorScaling","polygonTracker","warningTracker","allParentsVisible","polygonNumber","featureNumber","MeshWarningTracker","globalMaterial","setMaterialOnMesh","updateSketchDrawing","resetMeshGeometry","_previewVisible","meshWarningsNeedsUpdate","originOffset","scalingMatrix","transformChanged","BabylonSphereBuilder","worldPivot","sliceStart","totalYRotationSegments","nextYStep","createSphere","Cylinder","angle_step","sI","createCylinder","TorusBuilder","outerSegments","innerSegments","closedRing","closedTube","lastOuterRing","lastTubeSection","createTorus","colorSet","normalSet","DiscBuilder","createDisc","kbMesh","preserveSubmeshes","invalid","uvData","squareSize","calculatedSize","boundingBoxCenter","sketchPlaneVisualization","sketchMesh","rotationVector","resultQuaternion","FromUnitVectorsToRef","controlPointRenderer","firstPoint","PathRenderer","flipMatrix","mateConnectors","mate","followerMesh","c1Mesh","c2Mesh","mateOffset","worldDelta","angleOffsetQ","targetWorldTransformMatrix","currentWorldTransformMatrix","c2LocalTransform","grandParentContainerWorldMatrix","grandParentContainerWorldMatrixInv","calculatedTargetWorldTransform","revolute","targetQ","currentQ","targetDirection","currentDirection","targetST","decomposeSwingTwist","currentST","targetRotationNew","swing","twist","fastened","slider","followerMeshTransformMatrix","resultFollowerRotMatrix","c1PlaneNormal","c1Plane","c2Direction","c1Pos","c2Pos","c2PlaneNormal","c2Plane","c1Direction","parallel","_swap","totalOffset","newAbsPos","ConstraintType","sortMates","validMates","primes","getNodeMap","Fixed","visitedNodes","visitedMates","nodePath","matePath","overConstrained","recurseMateChain","getNodeChain","c1Parent","c2Parent","sourceEdge","isOverconstrained","cycle","Processor","afterCleanupTasks","beforeDeletions","deletions","afterDeletions","beforeUpdates","afterUpdates","afterCleanup","doAfterCleanup","MateProcessor","connectorRenderer","rebuildDependencies","mateDeletions","connectorDeletions","mateChanges","connectorChanges","meshChanges","buildDependencies","sortedMates","processMate","getConnectorMesh","followerNode","pauseRenderWhile","nodeWithTransform","controlPointMesh","targetTransformMatrix","mateControlPointToConnector","originalFollowerMeshAbsPos","originalFollowerMeshAbsQuat","originalFollowerMeshLocalPos","originalFollowerMeshLocalQuat","sortResult","getValidMates","addError","rootScene","sceneMates","clearProp","CircularPatternRenderer","featurePivot","featureAxis","featureArc","workingQuaternion","DeleteFacesRenderer","newIndices","currReadIndex","DisplacementMapRenderer","textureCanvas","willReadFrequently","textureLayers","getActiveLayers","getRenderer","textureHasContent","baseImageSize","getNativeSize","clampedSize","paintedImage","paintTextureOnCanvas","displace","uInt8Array","xztoxy","ExtrudeRenderer","extrudedMeshes","shapeHoles","rotToZ","pathTransformToZ","pathTransformToZInv","shape2d","builder","hole2d","extruded","extrudedAll","applyExtrusion","getSketchShape","maxIdx","usedVertexLength","normalizeGeometry","concatArr","pushAmount","currentCSGMeshId","vertColor","coplanarFront","coplanarBack","polygonType","tj","vi","vj","Polygon","FromPoints","polygons","_plane","_front","_back","_polygons","clipPolygons","clipTo","bsp","allPolygons","CSG","meshRotation","meshScaling","meshRotationQuaternion","invertWinding","vertColors","sm","sml","il","indexIndices","sourceNormal","sourcePosition","_FromPolygons","copyTransformAttributes","union","unionInPlace","intersectInPlace","inverse","inverseInPlace","buildMeshGeometry","keepSubMeshes","polygonIndices","vertice_dict","vertex_idx","subMeshDict","subMeshObj","indexEnd","jl","localVertex","localNormal","areUvsDifferent","areColorsDifferent","materialMaxIndex","materialIndexOffset","toMesh","createJoinGeometryVisualization","visualization","joinedMeshes","JoinGeometryRenderer","bbSubscriptions","targetMeshVisualizationMap","parentMeshVisualizationMap","thisMesh","workingVertexData","tempMesh","targetTransform","newMeshInstance","featureParentMesh","resultCsg","FromMesh","targetMeshMatchTransform","targetMeshTransform","opCsg","cut","resultMeshCsg","existingMaterials","featureInstance","deleteTargetMeshVisualization","existingSubscription","targetMeshNode","originalMesh","targetMeshCopy","LinearPatternRenderer","featureTranslation","workingVector","SliceFeatureRenderer","babylonMirrorPreviewsMap","triCount","positionsCount","planePoint","preSliceSubmeshes","newSubmeshes","edgeSplits","edgeStart","edgeDir","iA","iB","vA","vB","lnDot","preSliceSubmesh","aSplit","bSplit","baseGeometryVertexLength","newPositionIndex","originalSubmeshes","originalSubmesh","visualizationPlane","mirror","mirrorVisualization","createMirrorVisualization","parentBoundingBox","getMeshBoundingBox","MirrorFeatureRenderer","planeIntersect","combinedIndices","combinedPositions","combinedNormals","combinedUvs","combinedSubmeshes","assertNumbers","numbers","annotateArcCommand","lArcFlag","sweepFlag","rX","rY","xRot","x1_","y1_","c_ScaleTemp","c_Scale","cx_","cy_","cRot","cX","cY","phi1","phi2","intersectionUnitCircleLine","termSqr","SVGPathDataTransformer","DEG","arcAt","phiDeg","bezierRoot","EPS","x01","x12","PRECISION","discriminantX4","bezierAt","TO_ABS","INFO","relative","NORMALIZE_ST","prevCurveC2X","prevCurveC2Y","prevQuadCX","prevQuadCY","SVGPathData","SMOOTH_CURVE_TO","CURVE_TO","SMOOTH_QUAD_TO","QUAD_TO","QT_TO_C","prevQuadX1","prevQuadY1","prevXAbs","prevYAbs","pathStartXAbs","pathStartYAbs","MOVE_TO","CLOSE_PATH","MATRIX","pathStartX","origX1","origX2","comRel","sqr","HORIZ_LINE_TO","LINE_TO","VERT_LINE_TO","sinRot","cosRot","xCurve","yCurve","C","A1","B1","C1","newXRot","newSinRot","newCosRot","roundVal","rf","normalizeZ","normalizeH","normalizeV","pathStartY","ARC","x1Rel","y1Rel","LINE_COMMANDS","xRel","yRel","x2Rel","y2Rel","dX","dY","phiMin","deltaPhi","partCount","phiStart","phiEnd","deltaPhi_1","xTemp","yTemp","toAbs","qtToC","normST","fixX","fixY","DRAWING_COMMANDS","T","xDerivRoots_1","derivRoot","yDerivRoots_1","xRotRad","x90","y90","phiMin_1","phiMax","normalizeXiEta","xi","xDerivRoots_2","H","yDerivRoots_2","TransformableSVG","TO_REL","NORMALIZE_HVZ","A_TO_C","SANITIZE","TRANSLATE","SCALE","ROTATE","SKEW_X","SKEW_Y","X_AXIS_SYMMETRY","Y_AXIS_SYMMETRY","ANNOTATE_ARCS","isDigit","SVGPathDataParser","curArgs","canParseCommandOrComma","SyntaxError","finishCommand","isAArcFlag","curCommandType","curNumber","isEndingDigit","curNumberHasExp","curNumberHasExpDigits","curNumberHasDecimal","COMMAND_ARG_COUNTS","curCommandRelative","chunk","parsedCommands_1","cT","boundsTransform","CALCULATE_BOUNDS","transformFunction","newCommands","transformedCommand","encodeSVGPath","finish","PathParser","control","previousCommand","angles","isEnd","getPoint","xProp","yProp","makeAbsolute","getAsControlPoint","getAsCurrentPoint","getReflectedControlPoint","addMarker","priorTo","angleBetweenPoints","addMarkerAngle","getMarkerPoints","getMarkerAngles","PathHandler","_currentPosition","initialPosition","scaleDivider","nodeManager","stubPath","parseTrace","pathM","commonPathCommand","pathCommand","pathL","pathQ","pathZ","reprojectPaths","parsePath","pathParser","pathC","pathS","pathT","pathA","checkIfNewPathNeeded","desiredPathType","activePath","addNewPath","newControlPoint","lastControlPoint","cubicBezier","quadraticBezier","secondLastControlPoint","calculateReflection","pathType","controlPoint2","VERSION_NUMBER","PATHSCAN_COMBINED_LOOKUP","SPECPALETTE","GKS","OPTION_PRESETS","corsenabled","ltres","qtres","pathomit","rightangleenhance","colorsampling","numberofcolors","mincolorratio","colorquantcycles","layering","strokewidth","linefilter","roundcoords","viewbox","lcpr","qcpr","blurradius","blurdelta","posterized1","posterized2","curvy","sharp","detailed","smoothed","grayscale","fixedpalette","randomsampling1","randomsampling2","artistic1","artistic2","artistic3","artistic4","posterized3","pal","roundToDec","places","colorQuantization","paletteacc","pixelnum","cnt","palette","imageDataCache","newImageData","pxcnt","numberOfColors","rcnt","gcnt","bcnt","graystep","colorqnum","colorstep","rndnum","generatePalette","samplePalette","ni","nj","samplePaletteByGrid","racc","gacc","bacc","aacc","wacc","imageData2","thisgk","himageData","toRgbaStr","svgPathString","tracedata","lnum","pathnum","smp","pcnt","toSvgColorStr","hcnt","holechildren","hsmp","fitSeq","seqstart","seqend","dist2","errorpoint","errorval","curvepass","pl","fitpoint","t3","splitpoint","boundingBoxIncludes","parentbbox","childbbox","pointInPoly","isin","pathScan","pacnt","lookuprow","pathfinished","holepath","boundingbox","isholepath","parentidx","parentcnt","segtype1","segtype2","linesegment","batchTracePaths","internodepaths","btracedpaths","interNodes","palen","nextidx","nextidx2","previdx","previdx2","idx5","batchTraceLayers","binternodes","btbis","layeringStep","cnum","ah","aw","imageTracer","ImageTracer","versionnumber","optionpresets","checkOptions","presetName","preset","imageDataToSVG","getImgdata","imgd","svgstr","lcnt","getSvgString","imageDataToTracedata","colornum","tracedlayer","ls","n3","n4","n5","n6","n7","n8","layercontainerid","parentid","drawLayers","bis","bpaths","batchInterNodes","batchPathScan","appendSVGString","validNameCharacters","whitespace","quotemark","currentElement","offsetLine","offsetColumn","originalLines","lineRanges","rangeContains","getLocation","column","getLocator","locate","before","beforeLine","after","neutral","cdata","closingTag","getName","getAttribute","selfClosing","allowSpaces","escaped","getQuotedAttributeValue","getUnquotedAttributeValue","SvgConverter","decover","headerText","dataUrl","imageToTracedata","calculateScaleDivider","paletteStrengths","getPaletteColorStrength","bgIdx","primaryLayers","pathsCreated","holeLayerIdx","pathSet","svgText","parsedSVG","parseSvgRecursively","getViewBoxFromSvgElement","elem","viewBox","int","findSvgViewBox","createRectangle","createCircle","createPolyLine","nameGeneratedPaths","newChildren","resultChildren","newControlPoint2","newControlPoint3","newControlPoint4","newControlPoint5","newControlPoint6","newControlPoint7","newControlPoint8","newControlPoint9","newControlPoint10","newControlPoint11","newControlPoint12","newControlPoint13","newControlPoint14","newControlPoint15","newControlPoint16","centerRadiusCircle","closeArrayCorr","useOpenGLOrientationForUV","CreateMiteredRibbon","startCap","endCap","startCapVectors","endCapVectors","resultVectors","resultCaps","firstPath","reverseHandednessOfPositions","secondLastPoint","startCapIndices","endCapIndices","combineVertexDataWithCaps","createLineCaps","capMeshIndices","capMeshPositions","totalBasePositions","totalBaseNormals","totalBaseUvs","totalBaseIndices","startCapPositions","endCapPositions","meshIndices","generatedUvs","generateUvsForCaps","combinedPositionsArray","combinedNormalsArray","combinedUvsArray","combinedIndicesArray","positionsArray","reversedArray","operationVectors","isZeroVector","findDistinctVectors","xp1","xp2","normalizedXp3","normalizedXp2","SweepRenderer","targetPathNode","pathMesh","pathPoints","pathVertexData","pathTransform","sketchTransform","pathPrimaryVector","extrudeOptions","mitredExtrude","nextLine","axisY","nextAxisX","nextAxisY","nextAxisZ","nextStartPoint","bisector","allPaths","ribbonPath","planeParallel","closedPlaneParallel","closedPlaneNormal","closedPlane","TransformRenderer","WeldVerticesRenderer","positionAverage","normalsAverage","uvAverage","selectedIndices","selectedVertices","selectedIndicesArray","vertexVisited","indicesResult","FeatureStackRenderer","queuedGeometryToReset","queuedFeaturesToProcess","processedFeatures","featureOrder","renderers","moveVertices","weldVertices","displacementMap","uvMaps","linearPatterns","circularPatterns","joinGeometry","deleteFaces","normalSmoothing","extrude","sweep","forceRebuildGeometry","applyNewVertexData","movedIndex","getMovedFeatureIndex","updateFeatureOrder","recursivelyUpdateFeatureVisibility","update3dGeometry","dataTypes","hasFeatureToUpdate","hasChange","featureIsAffected","queueGeometryUpdate","existingVertexData","currentChanges","getFeatureIndexOnParent","renderStartTime","queuedFeatureToProcess","startFeatureIndex","vertexDataCurrent","vertexDataNew","renderTime","maxRenderTime","processThisFeature","baseSubmeshes","lastSubmesh","remainingIndexCount","calculateBaseSubmeshes","oldArray","newArrayId","affectedFeatures","disabledFeatures","newAffectedFeatures","affectedFeature","featureIndex","getFeatureIndex","affector","_disableFeatureStackChange","ExtendToRef","affected","changeType","getMeshName","SketchControlPointRenderer","updateHandles","enableHandle1","enableHandle2","arcThrough3Points","handleBar","sketchPath","getRelativeDirection","invTransform","getControlPointAbsPosition","convertRelativeDirectionToAbsolute","_handleBar","handleBall","handle1","handle2","ReferenceProcessor","referencesTo","orphanedReferences","rootManager","nodeId","referenceTo","referencedById","referencedBy","referencePropertyName","referenceId","getReferencesTo","orphanedReference","changedNodeManager","targettingProperties","_prop","referenceSettings","originalReferencedNodeId","originalReferencedNodeKey","originalReferencedNode","nestedPathIdSource","nestedPathIdTarget","isNestedSource","nestedTargetNode","changeMap","triggerChangesOnReferencersSync","transformationPropagation","SketchProcessor","updatePath","sketchPathChanges","sketchControlPointChanges","sketchesToUpdate","calculateSketchBounds","getControlPoints","buildSketchPoints","getPointPosition","CreateCatmullRomSpline","getPointDirection","CreateHermiteSpline","getPointDirection2","CreateCubicBezier","ArcThru3Points","PostProcessRenderPipeline","_renderEffectsForIsolatedPass","renderEffectName","addEffect","renderEffect","_enableEffect","renderEffects","MakeArray","_disableEffect","_attachCameras","unique","cams","indicesToDelete","_detachCameras","cameraName","_enableMSAAOnFirstPostProcess","sampleCount","effectKeys","getPostProcesses","PostProcessRenderEffect","singleInstance","_singleInstance","_getPostProcesses","_indicesForCamera","pps","cameraKey","PostProcessRenderPipelineManager","_renderPipelines","supportedPipelines","renderPipelineName","pipeline","addPipeline","renderPipeline","removePipeline","attachCamerasToRenderPipeline","detachCamerasFromRenderPipeline","enableEffectInPipeline","disableEffectInPipeline","_postProcessRenderPipelineManager","PostProcessRenderPipelineManagerSceneComponent","LensRenderingPipeline","LensChromaticAberrationEffect","HighlightsEnhancingEffect","LensDepthOfFieldEffect","_pentagonBokehIsEnabled","_depthTexture","grain_texture","_grainTexture","_createGrainTexture","_edgeBlur","edge_blur","_grainAmount","grain_amount","_chromaticAberration","chromatic_aberration","_distortion","distortion","_highlightsGain","dof_gain","_highlightsThreshold","dof_threshold","_dofDistance","dof_focus_distance","_dofAperture","dof_aperture","_dofDarken","dof_darken","_dofPentagon","dof_pentagon","_blurNoise","blur_noise","_createChromaticAberrationPostProcess","_createHighlightsPostProcess","_createDepthOfFieldPostProcess","_chromaticAberrationPostProcess","_highlightsPostProcess","_depthOfFieldPostProcess","postProcessRenderPipelineManager","edgeBlur","setEdgeBlur","grainAmount","setGrainAmount","chromaticAberration","setChromaticAberration","dofAperture","setAperture","edgeDistortion","setEdgeDistortion","dofDistortion","setFocusDistance","darkenOutOfFocus","setDarkenOutOfFocus","blurNoise","pentagonBokeh","enablePentagonBokeh","disablePentagonBokeh","highlightsGain","setHighlightsGain","highlightsThreshold","setHighlightsThreshold","disableEdgeBlur","disableGrain","disableChromaticAberration","disableEdgeDistortion","disableDepthOfField","enableNoiseBlur","disableNoiseBlur","disableHighlights","disableDepthRender","SSAO2Configuration","SSAO2RenderingPipeline","_ssaoPostProcess","_getDefinesForSSAO","_sampleSphere","_generateHemisphere","textureSamples","_textureSamples","_originalColorPostProcess","_forceGeometryBuffer","geometryBufferRenderer","bypassBlur","_getDefinesForBlur","expensiveBlur","_getSamplersForBlur","_blurHPostProcess","_blurVPostProcess","_bypassBlur","_expensiveBlur","forceGeometryBuffer","SSAOOriginalSceneColorEffect","SSAORenderEffect","SSAOBlurHRenderEffect","SSAOBlurVRenderEffect","SSAOCombineRenderEffect","totalStrength","minZAspect","bilateralSamples","bilateralSoften","bilateralTolerance","_bits","ssaoRatio","_createRandomTexture","_createSSAOPostProcess","_createBlurPostProcess","_createSSAOCombinePostProcess","_ssaoCombinePostProcess","_randomTexture","bilateral","_createBlurFilter","horizontal","blurFilter","ssaoCombineSize","originalColorSize","_radicalInverse_VdC","_hammersley","_hemisphereSample_uniform","numSamples","rand","PERSPECTIVE_DEPTH_PROJECTION","ORTHO_DEPTH_PROJECTION","randVector","FxaaPostProcess","glInfo","SKYBOX_SIZE","SamplingModeMap","nearest","trilinear","SceneRenderer","gui","renderManager","yVector","processEnvironment","tnode","forceDisablePostProcess","fxaaPostProcess","lensEffectPostProcess","ssaoPostProcess","annotationNode","gridNeedsRebuild","eventPayload","fromEntries","CustomEvent","detail","bubbles","_envTexturePath","_envTexture","skyMat","getSkyBox","blendModeMap","darken","lighten","luminosity","workingCanvases","getWorkingCanvas","disposeWorkingCanvas","TextureLayerRenderer","paintTexture","updateTextureWarnings","calculateOffsetAndDimensions","ctxWidth","ctxHeight","sourceWidth","sourceHeight","contain","stretch","minRatio","middle","drawInBlendedContext","maskingCtx","getTransform","globalCompositeOperation","tempCanvas","filterImageInPlace","globalAlpha","tempContext","dstImageData","dstData","alphaScale","colorize","tmpCtx","normalRotate","rotateAngle","drawSourceToCanvas","firstTextureLayer","drawAt","pivotX","pivotY","patternCanvas","patternAttempt","createPattern","scaleOffsetU","scaleOffsetV","rotateOffsetU","rotateOffsetV","innerContext","_visualize","strokeRect","ColorFillTextureLayerRenderer","FileTextureLayerRenderer","loadTextureBuffer","resp","_bufferSource","base64ArrayBuffer","base64","encodings","byteRemainder","mainLength","SvgTextureLayerRenderer","svgHelpers","_raster","renderedWidth","renderedHeight","fontLoadPromise","fontFacesFound","fontsToLoad","generateSvg","embedFonts","imgElement","svgString","fontStyles","generateImagePromise","loadedImageElement","deferSceneReady","textureChannelMap","emissive","ambient","reflection","maskingCanvas","TextureStackRenderer","queuedTexturesToProcess","queueSize","noMipMapFallback","updateTextureStackRequest","deferCalled","fileTexture","svgTexture","updateTextureStacksExec","textureId","getTexture3dId","disposeTexture","forceRebuildTexture","resetTextureStack","updateTextureStacksInternal","texturedNode","hasTextureInChannel","channelsToProcess","channelStrength","textureLayer","existingProcess","propName3d","getObjectPropertyAtPath","getTexture","updateTextureStacks","updateTextureProps","fileTextureLayer","applyUvProperties","clippingTexture","clippingTextureRenderer","includeSupressed","canUseSimpleTexture","activeLayers","originalTexture","_obj","propPath","ViewpointRenderer","unprocessedChangesCount","ChangeMap","RendererManager","getRenderMode","forcedRenderingMode","deferredChanges","processors","annotation","dimension","mateProcessor","sketchProcessor","isStable","getChangeMap","getDeletedNodes","runChanges","newChanges","getChangedNodes","allChangesByDid","allChangeCount","processedChangeMap","processedChanges","unchangedNodes","renderStart","changeList","includeOrphaned","isGlobalMaterialOrTexture","KbArcRotateCameraMouseWheelInput","computeDeltaFromMouseWheelLegacyEvent","mouseWheelLegacyEvent","KbArcRotateCamera","inertialOffsetPanningX","inertialOffsetPanningY","inertialOrthoZoom","clientInfo","mouseX","mouseY","screenLeft","screenTop","screenWidth","screenHeight","lockRotation","lockPanning","lockZoom","_orthoWidth","updateClient","orthoWidth","clampOrthoWidth","updateOrthographicPosition","orthoFit","startZoomLevel","zoomChange","shiftX","shiftY","clientRect","focalLength","disposeListeners","updateMousePosition","updateClientWrap","ANIMATION_FPS","eCameraType","eCameraOrientation","CameraTools","cameraMoving","_activeAnimation","_lastOrientation","objectsToScaleWithDistance","_cameraSettingsChange","copyCameraStateIntoViewpoint","viewChanged","param","allow","enableFreeLook","enableFreeMove","setPipeline","activePipeline","applyScenePostProcesses","frameCamera","pan","zoom","bounding","childrenBounding","nodeInfo","minBoundingBox","maxBoundingBox","bbCenter","bbCorners","cameraRay","cameraProjectionTargetPlane","cameraDistance","cameraPositionWorldOffset","planeProjectionX","planeProjectionY","bbCenterOffset","cameraTruePosition","cameraTrueTarget","xPlane","yPlane","bbCorner","xO","yO","desiredDistance","fovH","thV","thH","xP","xA","xR","yP","yA","yR","fireViewChangedOnNextRender","getScreenPositionOfNode","getScreenBoundingBoxOfNode","moveCameraToViewpoint","createCameraFromViewpoint","_activateCamera","animateToViewpoint","circEaseOut","newCameraTarget","ArcRotate","frameTarget","frameOptions","orbitRotation","targetRotation","targetPosition","activeAlpha","normalizeRotation","translateRotation","translatePosition","translateFov","translateTarget","translateA","crossesZero","shortestArc","translateB","translateR","translateOffset","translateOrthoWidth","storeCameraSettings","_storedViewpoint","restoreCameraSettings","watch","renderedNode","relativeSize","convertToCameraType","disposePreviousCamera","overhead","Universal","universalCamera","applyViewpointProperties","startWith","orient","_lastPerspectivePosition","newPos","normalizedPosition","rotDegrees","oneRotation","rotations","OctreeBlock","maxDepth","creationFunc","_boundingVectors","_capacity","_depth","_maxDepth","_creationFunc","_minPoint","_maxPoint","addEntry","createInnerBlocks","removeEntry","entryIndex","addEntries","select","selection","allowDuplicate","intersectsRay","_CreateBlocks","worldMin","worldMax","maxBlockCapacity","currentDepth","blockSize","localMin","localMax","Octree","dynamicContent","_maxBlockCapacity","_selectionContent","CreationFuncForMeshes","CreationFuncForSubMeshes","Dragger","_externalConnectors","_dragConnectors","_dragConnectorsByDynamicId","_dropPreviewConnectors","_dragFriends","_dragFriendMeshes","_dragFriendConnectors","_matedConnectors","startDrag","pointerArgs","draggable","lastX","lastY","totalMoved","_pointerObserver","movX","movY","startDragCommit","dragging","dropped","_draggable","_connectorRenderer","_dragNode","_dragNodeStartPosition","_dragMesh","_dragNodeInverseTransform","connectionMode","connectionType","connectRadius","dragOpacity","_onComplete","setupDragSurface","dragStart","getDragArgs","setupDragFriends","setupConnectors","setOpacity","newConnection","findConnection","_activeConnection","showDropPreview","hideDropPreview","processDragPosition","applyDragResultToNode","dragArgs","applyEuler","newRotationEuler","newKbQuat","newRotationAngle","newRotationAxis","otherConnector","withMates","dragConnector","previousEuler","toggleAllConnectors","resetOpacity","disposeDropPreview","_dragPlane","_dragSurfaces","_oct","_quadTree","_dropPreview","newMouseIntersect","intersectPointerToDragSurface","disableOffset","_startMouseIntersect","surfaceIds","surfaceNodes","sn","intersectDragSurface","surfacePick","newKbRotation","dragNode","startPos","potentialConnectors","dragConnectorMesh","dragConPos","intersectOctree","otherNode","otherConnectorMesh","canConnect","connectionsAreEqual","externalConnectorMeshes","parentsEnabled","dragConnectors","selectMany","extConnectorPositions","activeMates","getActiveMates","friend","friendNode","friendMesh","showConnectors","potentials","screenPos","dragMeshTransform","createDragPreview","clonedMeshGroup","kbnode","getConnectorLocalPoint","shouldSetOpacity","getAllMeshes","originalVisibility","ObjKb3dExporter","generateObj","shouldExportMesh","OBJExport","matlibname","globalposition","textureV","inverseTransform","trunkVerts","trunkNormals","trunkUV","trunkFaces","currentV","currentTextureV","textureIndices","blanks","faceUVs","OBJ","exportObj","objData","createObjBlob","_forceShowBoundingBoxes","_boundingBoxRenderer","BoundingBoxRenderer","_showBoundingBox","frontColor","backColor","showBackLines","onBeforeBoxRenderingObservable","onAfterBoxRenderingObservable","onResourcesReadyObservable","_fillIndexBuffer","_fillIndexData","_uniformBufferFront","_uniformBufferBack","_preActiveMesh","_tag","forceShowBoundingBoxes","_prepareResources","_colorShader","_colorShaderForOcclusionQuery","boxdata","boundingBoxIndex","_createWrappersForBoundingBox","median","drawWrapperBack","drawWrapperFront","renderOcclusionBoundingBox","_renderPassIdForOcclusionQuery","PivotTools","_PivotCached","_OldPivotPoint","_PivotPostMultiplyPivotMatrix","_PivotTranslation","_PivotTmpVector","PointerDragBehavior","currentDraggingPointerID","currentDraggingPointerId","onEnabledObservable","_useAlternatePickedPointAboveMaxDragAngleDragSpeed","_activeDragButton","maxDragAngle","dragButtons","_useAlternatePickedPointAboveMaxDragAngle","dragDeltaRatio","updateDragPlane","_moving","onDragObservable","onDragStartObservable","onDragEndObservable","moveAttached","startAndReleaseDragOnPointerEvents","detachCameraControls","useObjectOrientationForDragging","validateDrag","_alternatePickedPoint","_worldDragAxis","_targetPosition","_startDragRay","_lastPointerRay","_dragDelta","_pointC","_localAxis","_lookAt","optionCount","dragAxis","dragPlaneNormal","ownerNode","_PlaneScene","lastDragPosition","pickPredicate","_activePointerInfo","_startDrag","releaseDrag","_AnyMouseId","MouseEvent","_moveDrag","_beforeRenderObserver","needMatrixUpdate","_RemoveAndStorePivotPoint","_RestorePivotPoint","dragPlanePoint","fromRay","startPickedPoint","lastRay","_updateDragPlanePosition","_pickWithRayOnDragPlane","dragLength","dragDistance","dragPlanePosition","KbAxisMorphGizmo","gizmoPosition","dragActive","_updateQuat","snapDistance","updateObservable","wireframeMaterial","hoverMaterial","axisMesh","line2","sphereMesh","dragBehavior","isHovered","GizmoAnchorPoint","GizmoCoordinatesMode","Gizmo","_isHovered","attachedMesh","_attachedNode","_attachedNodeChanged","setCustomMesh","_customMeshSet","updateGizmoRotationToMatchAttachedMesh","_updateGizmoRotationToMatchAttachedMesh","updateGizmoPositionToMatchAttachedMesh","_updateGizmoPositionToMatchAttachedMesh","anchorPoint","_anchorPoint","Local","_updateScale","_customRotationQuaternion","Origin","_rightHandtoLeftHandMatrix","customRotationQuaternion","effectiveNode","Pivot","PreserveScaling","camForward","_handlePivot","attachedNodeTransform","_matrixChanged","worldMatrixUC","parentInv","localMat","invParent","boneLocalMatrix","nodeLocalMatrix","_setGizmoMeshMaterial","gizmoMeshes","gizmoAxisCache","pointerObserver","colliderMeshes","disableMaterial","AUTO_MESH_NAME","KbGizmo","updateGizmoPosition","attachTo","attachMeshAtNodeSpace","positionSpaceTransform","KbPlaneRotationGizmo","onSnapObservable","drag","rotationMesh","planeNormalTowardsCamera","localPlaneNormalTowardsCamera","tmpSnapEvent","currentSnapDragDistance","amountToRotate","attachedMeshParent","attachedMeshPosition","originalVector","camVec","snapped","dragSteps","quaternionCoefficient","deltaAngle","_attachedMeshChanged","KbAxisAngleGizmo","positionSpace","placementOffset","_positionSpace","_updateGizmoPosition","changeTarget","onNextFrame","targetAxis","targetAxisTransformed","axisGizmo","angleMesh","angleGizmo","disableAngle","zeroVector","tempVector2","axisChange","angleChange","deltaAxis","meshFaceInfo","MeshFaceEngine","updateNodeGeometry","getMeshFaces","expandSelection","limitAngle","faceInfo","selectedFaceIds","newSelection","recursiveExpandSelection","iterCount","neighbors","faceNeighbors","adjacentFaceId","facesByEdges","trianglesCount","triId","triOffset","edgeId","faceCount","eMarqueeSelectMode","Interaction","onClick$","onFacetClick$","onDoubleClick$","onPointerMove$","onPointerDown$","onPointerUp$","onKeyboard$","onMarqueeSelect","pointerIsDown","dragInProgress","selectionTolerance","cameraFacingDirection","meshFaceEngine","onClick","onFacetClick","onDoubleClick","onKeyboard","attachScene","handleMove","handleDoubleClick","getKeyboardArgs","handleKeyboard","setSelectionTolerance","setSelectionCulling","marqueeSelectOptions","cullSelection","enableMarqueeSelect","onlyOnShiftPress","selectedFaces","vertexList","disableMarqueeSelect","fillKb3dPickInfo","handleClickTypeEvent","handlerType","getNextNodeHandlers","propagate","getHandlerMap","selectedTriangle","facetArgs","clicks","getNextClickHandlers","getNextDraggables","hover","clearHover","stopPropagation","handleMarquee","unlockCamera","canvasX","canvasY","startRay","uiOverlay","selectBox","border","Facets","dragger","topOrigin","leftOrigin","rightOrigin","bottomOrigin","topNormal","leftNormal","rightNormal","bottomNormal","boxL","boxR","boxT","boxB","forwardDirection","sideDirection","topLeft","topRight","botLeft","botRight","fP","fN","pointPlaneSizeToRef","Vertices","meshPoint","getNextDoubleClickHandlers","dbSubmeshes","KbFacetSelectGizmo","__attachedMesh","onSelectionChange","currentSelection","selectionsEnabled","highlightOpacity","utilLayer","__attachedNode","aMesh","disposeSubject","getVertexGroups","visualizeSubmesh","selectedFacets","selectFacetGroups","startFacet","endFacet","enableSelectionChange","disableSelectionChange","submeshInfo","setBackfaceCulling","setTolerance","setVisualization","highlightMaterial","faceIds","geometryNeedsUpdate","transparantMaterial","vMesh","indexGroup","KbLightGizmo","lightNode","_attachedLight","posGizmo","rotGizmo","_helperMesh","lightVisual","KbAxisDragGizmo","_CreateArrow","localDelta","KbPositionGizmo","orientGizmo","xGizmo","yGizmo","zGizmo","_attachedSpaceNode","axisVisibility","positionChange","activeGizmos","KbRotationGizmo","corr","rotationChange","KbAxisScaleGizmo","uniformScaling","_coloredMaterial","arrowMesh","arrowTail","dragStrength","useGizmoMaterial","KbScaleGizmo","uniformScaleGizmo","scaleChange","uniformScalingMesh","octahedron","ColorGradient","getColorToRef","Color3Gradient","FactorGradient","factor1","factor2","getFactor","GradientHelper","updateFunc","gradientIndex","currentGradient","nextGradient","lastIndex","colorStep","lifeTime","age","cellIndex","_attachedSubEmitters","_currentColor1","_currentColor2","_currentSize1","_currentSize2","_currentAngularSpeed1","_currentAngularSpeed2","_currentVelocity1","_currentVelocity2","_currentLimitVelocity1","_currentLimitVelocity2","_currentDrag1","_currentDrag2","_Count","_updateCellInfoFromSystem","updateCellIndex","offsetAge","changeSpeed","_randomCellOffset","_initialEndSpriteCellID","_initialStartSpriteCellID","_initialSpriteCellLoop","_inheritParticleInfoToSubEmitter","subEmitter","emitterMesh","inheritDirection","inheritedVelocityAmount","_inheritedVelocityOffset","_inheritParticleInfoToSubEmitters","_currentColorGradient","_currentSizeGradient","_currentAngularSpeedGradient","_currentVelocityGradient","_currentLimitVelocityGradient","_currentDragGradient","_initialDirection","useRampGradients","remapData","_randomNoiseCoordinates1","_randomNoiseCoordinates2","SubEmitterType","SubEmitter","END","_disposeEmitterOnDispose","serializeTexture","doNotStart","_ParseParticleSystem","ParticleSystem","_useRampGradients","_resetEffect","_particles","getActiveCount","isStopping","isAlive","getCustomEffect","_customWrappers","_getCustomDrawWrapper","_useInstancing","onBeforeDrawParticlesObservable","_onBeforeDrawParticlesObservable","vertexShaderName","customEffect","_emitterInverseWorldMatrix","onStoppedObservable","_stockParticles","_newPartsExcess","_scaledColorStep","_colorDiff","_scaledDirection","_scaledGravity","_started","_actualFrame","_currentEmitRate1","_currentEmitRate2","_currentStartSize1","_currentStartSize2","updateInAnimate","_rawTextureWidth","isGPU","lastParticle","_createParticle","_subEmitters","subEmitters","ATTACHED","newEmitter","_emitFromParticle","templateIndex","subSystem","_rootParticleSystem","activeSubSystems","defaultProjectionMatrix","_vertexArrayObject","noiseTextureData","updateFunction","noiseTextureSize","sameParticleArray","scaledUpdateSpeed","_scaledUpdateSpeed","previousAge","GetCurrentGradient","directionScale","limitVelocity","_emitterWorldMatrix","fetchedColorR","_fetchR","fetchedColorG","fetchedColorB","scaledForce","_addFactorGradient","factorGradients","newGradient","_removeFactorGradient","factorGradient","addLifeTimeGradient","removeLifeTimeGradient","addSizeGradient","removeSizeGradient","addColorRemapGradient","removeColorRemapGradient","addAlphaRemapGradient","removeAlphaRemapGradient","addAngularSpeedGradient","removeAngularSpeedGradient","addVelocityGradient","removeVelocityGradient","addLimitVelocityGradient","removeLimitVelocityGradient","addDragGradient","removeDragGradient","addEmitRateGradient","removeEmitRateGradient","addStartSizeGradient","removeStartSizeGradient","_createRampGradientTexture","_rampGradientsTexture","getRampGradients","forceRefreshGradients","_syncRampGradientTexture","addRampGradient","removeRampGradient","addColorGradient","colorGradient","removeColorGradient","drawWrappers","_vertexBuffer","_spriteBuffer","_vertexBufferSize","BILLBOARDMODE_STRETCHED","BILLBOARDMODE_STRETCHED_LOCAL","vertexSize","_vertexData","cellIndexBuffer","directionBuffer","rampDataBuffer","spriteData","getCapacity","_alive","_prepareSubEmitterInternalArray","_currentEmitRateGradient","_currentStartSizeGradient","noiseTextureAsProcedural","stopSubEmitters","_stopSubEmitters","_appendParticleVertex","initialDirection","_removeFromRoot","newParticles","emitterPosition","factorGradient1","factorGradient2","lifeTime1","lifeTime2","emitPower","attributeNamesOrOptions","effectCreationOption","fillUniformsAttributesAndSamplerNames","_GetAttributeNamesOrOptions","_GetEffectCreationOptions","_getWrapper","customWrapper","preWarmOnly","_appendParticleVertices","particleTexture","defaultViewMatrix","baseSize","outparticles","cloneTexture","shaderOptions","serialization","emitterId","colorGradients","serializedGradient","rampGradients","colorRemapGradients","colorRemapGradient","alphaRemapGradients","alphaRemapGradient","sizeGradients","sizeGradient","angularSpeedGradients","angularSpeedGradient","velocityGradients","velocityGradient","dragGradients","dragGradient","emitRateGradients","emitRateGradient","startSizeGradients","startSizeGradient","lifeTimeGradients","lifeTimeGradient","limitVelocityGradients","limitVelocityGradient","parsedParticleSystem","emitterType","cellArray","KbVertexSelectGizmo","drawVertices","vertexTracker","particleScale","redrawVertices","vertexSelectedColor","vertexUnSelectedColor","vertexTransparentColor","verticesUtilLayer","disposeMarquee","selectionMode","redraw","emitSelectionChange","updateParticleScale","selectVertices","getBarycenter","saveAnimate","particlesToProcess","CreateRGBTexture","KbViewpointGizmo","targetGizmo","_visualMesh","previousTargetMode","_gizmoMesh","_targetVisualMesh","updateHelperMeshes","updateHelperMeshDirectionToRotation","_attachedViewpoint","targetChange","deltaTargetPos","deltaRotation","viewpointNode","eulerRot","FromEulerVector","recreate","PREVIEW_NAME","GizmoTools","activeGizmoSettings","uvMapStoredMaterials","selectLight","lightGizmo","totalDeltaPosition","subjects","updateLightGizmo","selectViewpoint","viewpointGizmo","updateTargetPosition","updateRotation","totalDeltaTargetPosition","totalDeltaRotation","totalDeltaPositionQueue","totalDeltaTargetPositionQueue","totalDeltaRotationQueue","updateViewpointGizmo","positionGizmo","totalDelta","totalDeltaQueue","clearGizmo","rotateAxisAngle","updateAxisAngle","axisAngleGizmo","updateAxis","positionTransform","rotationGizmo","axisTranslate","gizmoRotation","worldTransformMatrix","positionTransformInv","positionDelta","axisDelta","worldNodePivot","nodeTransform","scaleGizmo","vertexSelectionGizmo","updateGizmoPositions","selectFacets","facetSelectionGizmo","gizmoSettings","showUvMapMaterial","_showMaterial","previousMaterial","previewMaterial","previewTexture","storedMaterial","filterToChangedValues","DefaultSketchOptions","faceCamera","snapSize","activeHitPoint","sketchPlaneIntersect","SketchEditor","defaultHighlightColor","mouseUp","sketchPoints","updateActiveOptions","currentOptions","startOnPlane","userOptions","useSketchNormal","activeSketch","currentCanvas","previewVisibleOriginal","sketchPlane","originalCamera","sketchCamera","dragObjects","lastMousePosition","sketchParent","getPointOnPlane","deletedPoints","collisionSphere","pointRendered","cpCenter","cpHandle1","cpHandle2","handle","transformInv","dragObject","movement","rightClickMenu","showContextMenu","getRightClickButtonsForLines","getRightClickButtons","isOpen","hideContextMenu","rendererNode","deleteSketchPoint","deleteSketchPath","separateSketchNode","sketchpathType","cpIndex","pointOnePosition","pointTwoPosition","selectedControlPoints","selectedPath","nextPath","nextPathPoints","addSketchNodeOnPath","spliceIndex","sketchControlPoint","eSnapshotType","SnapshotModule","takeAsBlob","takeAsDataUrl","viewpointSet","framePadding","snapshotCanvas","renderContext","newWidth","newHeight","renderingCanvas","dataurl","mime","bstr","u8arr","dataURLtoBlob","clickHandler","Highlighter","cameraManager","colorMap","nodeColors","highlighterDb","highlightPipeline","enableHighlightDebug","highlightEffect","startPostProcess","renderNode","addHighlightToRendered","activeHover","removeHighlightFromRendered","forceRenderOnNextFrame","clearAll","colorMapKey","colorToString","addNodeToColorMap","colorKey","removeNodeFromColorMap","colorMapEntry","newShader","RightClickMenu","contextMenuOpen","xPosition","yPosition","createContextMenu","contextmenu","contextMenu","zIndex","stopImmediatePropagation","newButton","innerText","FADE_TIME","KbViewer","pauseRender","normalSmoothingWarnings","fpsTracker","forceRunRenderer","positionTrackedNodes","nextFrameCallbacks","_renderLoopRunning","allAssetsLoaded","additionalLoadBlockers","enableScreenshots","webworkerPath","iOS","createScene","gizmos","sketchEditor","snapshot","objExporter","loadScene","createLoadingExperience","startRender","deferLoadingPromise","http","hideLoadingExperience","forceDisableGraphicsOptimization","waitForNextKb3dRender","optimizeScene","updateMeshWarnings","updateMaterialWarnings","updateAnimationWarnings","getFPS","getWarnings","warningMessages","totalSpotLights","totalPointLights","shadowCastingLights","tempWarning","lightsWarningMessages","updateWarnings","bigTextures2048","bigTextures4096","textureWarningMessages","subMaterialTextures","totalPolygons","recursiveGetPolygons","meshCastAndReceiveShadows","meshWarningMessages","polygonCount","warning","localMaterialCount","getLocalMaterialsRecursive","materialWarningMessages","tempArray","extractMeshGeometry","applySvgToSketch","overwriteSketchWithSvg","draggingEvent","mousePosition","lastPickedMesh","dragOver","resizeObserver","getBabylonJson","childData","preRender","frameCount","skipped","stopRender","createOverlay","ResizeObserver","pointerEvents","loadingOverlay","backgroundSize","backgroundRepeat","backgroundPosition","backgroundImage","fade","spinner","alignItems","justifyContent","sceneOptimizerOptions","sceneOptimizer","startSceneRenderAutoStop","createDefaultEnv","waitForMaterials","materialService","somePromise","nodesIntersect","node1","node2","bb1","bb2","getReferenceNodes","getTransformSpaceDifference","originNode","destinationNode","destinationMesh","originMatrix","destinationMatrix","centerMeshToOrigin","kb3dEnums","BoundingBoxRelativeHelperKbVector","convertAbsoluteToRelative","convertAbsoluteDirectionToRelative","NEW_GEOMETRY","Quad","Validator","vmap","nodeIsValid","getErrors","clearPropError","clearPropErrorWhere","clearNode","sprop","existingErrors","applyTransformToVector","bakeMeshTransform","newTransform","convertHdrToEnv","hdrFile","hdrSize","dataUri","dummyEngine","degreeToRadian","vectorDegree","optionalResult","getDimensionLinePoints","lineStart","lineEnd","getToken","tryWithKey","isCircularPattern","isInstanceOf","isLinearPattern","isObject$1","isPattern","isSubmesh","isTrackedArray","isTrackedMeshNode","isViewpointNode","kb3dTest","btnAnimate","quadraticIn","quadraticOut","btnStop","txtJson","txtCounter","btnToJson","updateJsonLength","btnToFullJson","btnFromJson","btnBabylonJson","btnWidth","btnMaterialColor","btnSaveMesh","myArray","longInt8View","btnGetSavedMesh","oReq","makeRotationAxis","mathClamp","mergeVertices","newVertexGroup","mergeVerticesIntoAll","nextVertexGroup","mergedVertexGroup","ofToken","omitUndefinedElements","removeVerticesFromAll","toPixels","viewportUnits"],"mappings":"AAAA,IAAIA,KAAQ,SAAUC,GAClB,aC2CJC,OAAOC,UAAUC,WAAa,WAC1B,OAAOC,KAAKC,OAAO,GAAGC,cAAgBF,KAAKG,MAAM,IAGrD,MAAMC,EAAkB,qECMjB,SAASC,EAAWC,EAAYC,EAAQC,EAAKC,GAChD,IAA2HC,EAAvHC,EAAIC,UAAUC,OAAQC,EAAIH,EAAI,EAAIJ,EAAkB,OAATE,EAAgBA,EAAOM,OAAOC,yBAAyBT,EAAQC,GAAOC,EACrH,GAAuB,iBAAZQ,SAAoD,mBAArBA,QAAQC,SAAyBJ,EAAIG,QAAQC,SAASZ,EAAYC,EAAQC,EAAKC,QACpH,IAAK,IAAIU,EAAIb,EAAWO,OAAS,EAAGM,GAAK,EAAGA,KAAST,EAAIJ,EAAWa,MAAIL,GAAKH,EAAI,EAAID,EAAEI,GAAKH,EAAI,EAAID,EAAEH,EAAQC,EAAKM,GAAKJ,EAAEH,EAAQC,KAASM,GAChJ,OAAOH,EAAI,GAAKG,GAAKC,OAAOK,eAAeb,EAAQC,EAAKM,GAAIA,EAGzD,SAASO,EAAQC,EAAYC,GAChC,OAAO,SAAUhB,EAAQC,GAAOe,EAAUhB,EAAQC,EAAKc,IDb3DzB,OAAOC,UAAU0B,WAAa,WAC1B,OAAOxB,KAAKyB,MAAMrB,IAAoB,IAG1CP,OAAOC,UAAU4B,QAAU,SAAUC,GACjC,OAAQ3B,KAAOA,KAAKE,mBAAgB0B,MAAgBD,EAAMA,EAAIzB,mBAAgB0B,IAGlF/B,OAAOC,UAAU+B,UAAY,YAAaC,GACtC,OAAOA,GAAWA,EAAQC,MAAK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YuB5lpB,GACvB,OAAQqH,GAAiCD,EAAWC,EAAUrH,IJ+o1M9D9E,EAAQ2qpB,sBA32uMR,SuFp0GqC3npB,GACrC,OAAOA,MAAAA,GvF+q1MPhD,EAAQ23hB,oBAAsBA,GAC9B33hB,EAAQ04hB,kBAAoBA,GAC5B14hB,EAAQ4qpB,sBAzg5CR,SmvBjr8JA5wY,EACAnnF,EACA8yD,GAEA,IAAK,IAAIpkP,EAAI,EAAGA,EAAIy4Q,EAAa/4Q,OAAQM,IAAK,CAC1C,MAAMyugB,EAAch2P,EAAaz4Q,GACjC,GAAI0ugB,GAAsBD,EAAan9U,EAAY8yD,GAAW,CAC1D,MAAMrpO,EAASyzf,GAAgBC,EAAan9U,EAAY8yD,GACxDq0B,EAAa92Q,OAAO3B,EAAG,KAAM+a,MnvBmr1MrCtc,EAAQisQ,iBAAmBA,GAC3BjsQ,EAAQosQ,sBAAwBA,GAChCpsQ,EAAQgsQ,cAAgBA,GACxBhsQ,EAAQ8rQ,oBAAsBA,GAC9B9rQ,EAAQm1kB,UAAYA,GACpBn1kB,EAAQs3f,kBAAoBA,GAC5Bt3f,EAAQ60c,MAAQA,GAChB70c,EAAQ6qpB,SA/z7DR,SkqBx25IqBC,EAAgC92hB,GAErD,MAAMgqC,GADNhqC,EAASwiL,GAAUxiL,IACOh4D,YAAYuwI,+BACtC,MAAO,CACHt+L,EAAG68oB,EAAc78oB,EAAI+vJ,EAAWjiI,MAChCva,EAAGspoB,EAActpoB,EAAIw8I,EAAWhiI,SlqBmq1MpCh8B,EAAQ6rQ,UAAYA,GACpB7rQ,EAAQ40c,SAAWA,GACnB50c,EAAQqsQ,wBAA0BA,GAClCrsQ,EAAQ6ygB,qBAAuBA,GAC/B7ygB,EAAQw1c,4BAA8BA,GAE/Bx1c,EA5s1MA,CA8s1MT","file":"viewer.min.js","sourcesContent":["var kb3d = (function (exports) {\n 'use strict';\n\n String.prototype.capitalize = function () {\n return this.charAt(0).toUpperCase() + this.slice(1);\n };\n const splitWordsRegex = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;\n String.prototype.splitWords = function () {\n return this.match(splitWordsRegex) || [];\n };\n String.prototype.isEqual = function (str) {\n return (this ? this.toUpperCase() : undefined) === (str ? str.toUpperCase() : undefined);\n };\n String.prototype.equalsAny = function (...strings) {\n return strings && strings.some(s => s.isEqual(this));\n };\n String.prototype.toSentence = function () {\n return this.replace(/([A-Z])/g, ' $1') // insert a space before all caps\n .replace(/^./, function (str) {\n return str.toUpperCase();\n }) // uppercase the first character\n .trim(); //trip leading and trainling whitespace\n };\n Object.defineProperty(Array.prototype, 'sortBy', {\n enumerable: false,\n writable: true,\n value: function (predicate) {\n return this.sort((a, b) => {\n if (predicate(a) < predicate(b)) {\n return -1;\n }\n else if (predicate(a) > predicate(b)) {\n return 1;\n }\n else {\n return 0;\n }\n });\n },\n });\n Object.defineProperty(Array.prototype, 'remove', {\n enumerable: false,\n writable: true,\n value: function (item) {\n const index = this.indexOf(item);\n if (index != -1) {\n return this.splice(this.indexOf(item), 1);\n }\n },\n });\n Object.defineProperty(Array.prototype, 'removeWhere', {\n enumerable: false,\n writable: true,\n value: function (predicate) {\n const removed = new Array();\n for (let i = this.length - 1; i >= 0; i--) {\n const item = this[i];\n if (predicate(item)) {\n removed.push(...this.splice(i, 1));\n }\n }\n return removed;\n },\n });\n Object.defineProperty(Array.prototype, 'contains', {\n enumerable: false,\n writable: true,\n value: function (item) {\n const index = this.indexOf(item);\n return index != -1;\n },\n });\n Object.defineProperty(Array.prototype, 'selectMany', {\n enumerable: false,\n writable: true,\n value: function (selector) {\n return this.reduce((out, v) => {\n let vres = selector(v);\n if (vres != null) {\n if (!Array.isArray(vres))\n vres = [vres];\n out.push(...vres);\n }\n return out;\n }, []);\n },\n });\n Object.defineProperty(Array.prototype, 'first', {\n enumerable: false,\n writable: true,\n value: function () {\n let item;\n if (this.length) {\n item = this[0];\n }\n return item;\n },\n });\n Object.defineProperty(Array.prototype, 'last', {\n enumerable: false,\n writable: true,\n value: function () {\n if (this.length) {\n return this[this.length - 1];\n }\n return undefined;\n },\n });\n Object.defineProperty(Array.prototype, 'getCommonOrNull', {\n enumerable: false,\n writable: true,\n value: function (valueDelegate) {\n const arr = this;\n if (this.length && arr.every(i => valueDelegate(i) == valueDelegate(arr[0]))) {\n return valueDelegate(arr[0]);\n }\n return null;\n },\n });\n Object.defineProperty(Array.prototype, 'toMap', {\n enumerable: false,\n writable: true,\n value: function (keySelector) {\n const m = new Map();\n for (const i of this) {\n m.set(keySelector(i), i);\n }\n return m;\n },\n });\n Object.defineProperty(Array.prototype, 'clear', {\n enumerable: false,\n writable: true,\n value: function () {\n if (this.length > 0) {\n this.splice(0, this.length);\n }\n },\n });\n Object.defineProperty(Array.prototype, 'reorder', {\n enumerable: false,\n writable: true,\n value: function (fromIndex, toIndex, undo) {\n if (undo) {\n if (fromIndex > toIndex) {\n fromIndex--;\n }\n else {\n toIndex++;\n }\n }\n const itemToMove = this[fromIndex];\n for (let i = fromIndex; i < this.length - 1; i++) {\n this[i] = this[i + 1];\n }\n if (toIndex > fromIndex) {\n toIndex--;\n }\n for (let i = this.length - 1; i > toIndex; i--) {\n this[i] = this[i - 1];\n }\n this[toIndex] = itemToMove;\n },\n });\n Object.defineProperty(Set.prototype, 'find', {\n enumerable: false,\n writable: true,\n value: function (predicate) {\n for (const i of this) {\n if (predicate(i))\n return i;\n }\n return undefined;\n },\n });\n Object.defineProperty(Map.prototype, 'hasAny', {\n enumerable: false,\n writable: true,\n value: function (...keys) {\n return keys.some(k => this.has(k));\n },\n });\n\n /******************************************************************************\r\n Copyright (c) Microsoft Corporation.\r\n\r\n Permission to use, copy, modify, and/or distribute this software for any\r\n purpose with or without fee is hereby granted.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\n PERFORMANCE OF THIS SOFTWARE.\r\n ***************************************************************************** */\r\n\r\n function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n }\r\n\r\n function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n }\r\n\r\n var _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n class Token {\n constructor(key) {\n this.key = key;\n }\n static withKey(key) {\n const token = this[key];\n if (!token)\n throw new Error(`Could not find token for key '${key}'`);\n return token;\n }\n static tryWithKey(key) {\n const token = this[key];\n return token;\n }\n static MapFrom(...tokens) {\n return new Map(tokens.map(t => [t, null]));\n }\n isPrimitive() {\n return Token.PrimitiveTokenMap.has(this);\n }\n isPrimitiveMesh() {\n return Token.PrimitiveMeshTokenMap.has(this);\n }\n isMesh() {\n return Token.MeshTokenMap.has(this);\n }\n isMeshOrGroup() {\n return Token.MeshAndGroupTokenMap.has(this);\n }\n isMaterial() {\n return Token.MaterialTokenMap.has(this);\n }\n isFeature() {\n return Token.FeatureTokenMap.has(this);\n }\n isTexture() {\n return Token.TextureLayerTokenMap.has(this);\n }\n isLight() {\n return Token.LightTokenMap.has(this);\n }\n isViewpoint() {\n return Token.ViewpointNode === this;\n }\n isMate() {\n return Token.MateNode === this;\n }\n isConnector() {\n return Token.Connector === this || Token.SketchControlPoint === this;\n }\n isAnnotation() {\n return Token.AnnotationTokenMap.has(this);\n }\n isNode() {\n return Token.NodeTokenMap.has(this);\n }\n isSceneNode() {\n return Token.SceneNode === this;\n }\n isSketchPath() {\n return Token.SketchPath === this;\n }\n }\n /** Services */\n Token.HttpService = new Token('HttpService');\n Token.MaterialService = new Token('MaterialService');\n Token.MeshService = new Token('MeshService');\n Token.JobService = new Token('JobService');\n Token.SceneService = new Token('SceneService');\n Token.FontService = new Token('FontService');\n Token.Ignore = new Token('Ignore');\n /** Roots */\n Token.SceneNode = new Token('SceneNode');\n Token.Kb3dObject = new Token('Kb3dObject');\n Token.ImportInfo = new Token('ImportInfo');\n /** Lights */\n Token.LightNode = new Token('LightNode');\n Token.DirectionalLightNode = new Token('DirectionalLightNode');\n Token.HemisphericLightNode = new Token('HemisphericLightNode');\n Token.PointLightNode = new Token('PointLightNode');\n Token.SpotLightNode = new Token('SpotLightNode');\n /** Meshes */\n Token.BoxNode = new Token('BoxNode');\n Token.CustomMeshNode = new Token('CustomMeshNode');\n Token.CylinderNode = new Token('CylinderNode');\n Token.ConeNode = new Token('ConeNode');\n Token.DiscNode = new Token('DiscNode');\n Token.PlaneNode = new Token('PlaneNode');\n Token.SphereNode = new Token('SphereNode');\n Token.TorusNode = new Token('TorusNode');\n Token.MeshNode = new Token('MeshNode');\n Token.PrimitiveMeshNode = new Token('PrimitiveMeshNode');\n Token.MeshGroupNode = new Token('MeshGroupNode');\n Token.SpaceNode = new Token('SpaceNode');\n Token.TextNode = new Token('TextNode');\n Token.SketchNode = new Token('SketchNode');\n Token.SketchPath = new Token('SketchPath');\n /** Dimensions */\n Token.AnnotationNode = new Token('AnnotationNode');\n Token.DimensionNode = new Token('DimensionNode');\n /** Primitives */\n Token.KbColor = new Token('KbColor');\n // public static KbColor4 = new Token(\"KbColor4\");\n Token.KbGeometry = new Token('KbGeometry');\n Token.KbQuaternion = new Token('KbQuaternion');\n Token.KbVector = new Token('KbVector');\n /** Materials */\n Token.MaterialNode = new Token('MaterialNode');\n Token.AdvancedMaterialNode = new Token('AdvancedMaterialNode');\n Token.MaterialMapping = new Token('MaterialMapping');\n /** Textures */\n Token.TextureLayer = new Token('TextureLayer');\n Token.FileTextureLayer = new Token('FileTextureLayer');\n Token.SvgTextureLayer = new Token('SvgTextureLayer');\n Token.TextTextureLayer = new Token('TextTextureLayer');\n Token.ColorFillTextureLayer = new Token('ColorFillTextureLayer');\n /** Viewpoints */\n Token.ViewpointNode = new Token('ViewpointNode');\n /** Features */\n Token.Feature = new Token('Feature');\n Token.BaseConnector = new Token('BaseConnector');\n Token.Connector = new Token('Connector');\n Token.SketchControlPoint = new Token('SketchControlPoint');\n Token.SubmeshFeature = new Token('SubmeshFeature');\n Token.MoveVerticesFeature = new Token('MoveVerticesFeature');\n Token.WeldVerticesFeature = new Token('WeldVerticesFeature');\n Token.DisplacementMapFeature = new Token('DisplacementMapFeature');\n Token.UvMapFeature = new Token('UvMapFeature');\n Token.LinearPatternFeature = new Token('LinearPatternFeature');\n Token.CircularPatternFeature = new Token('CircularPatternFeature');\n Token.JoinGeometryFeature = new Token('JoinGeometryFeature');\n Token.DeleteFacesFeature = new Token('DeleteFacesFeature');\n Token.NormalSmoothingFeature = new Token('NormalSmoothingFeature');\n Token.SliceFeature = new Token('SliceFeature');\n Token.MirrorFeature = new Token('MirrorFeature');\n Token.TransformFeature = new Token('TransformFeature');\n Token.ExtrudeFeature = new Token('ExtrudeFeature');\n Token.SweepFeature = new Token('SweepFeature');\n Token.MateNode = new Token('MateNode');\n Token.PrimitiveTokens = [Token.KbVector, Token.KbQuaternion, Token.KbColor];\n Token.PrimitiveTokenMap = Token.MapFrom(...Token.PrimitiveTokens);\n Token.PrimitiveMeshTokens = [\n Token.BoxNode,\n Token.CylinderNode,\n Token.ConeNode,\n Token.DiscNode,\n Token.PlaneNode,\n Token.SphereNode,\n Token.TorusNode,\n ];\n Token.PrimitiveMeshTokenMap = Token.MapFrom(...Token.PrimitiveMeshTokens);\n Token.MeshTokens = Token.PrimitiveMeshTokens.concat(Token.CustomMeshNode, Token.SketchNode, Token.TextNode);\n Token.MeshTokenMap = Token.MapFrom(...Token.MeshTokens);\n Token.MeshAndGroupTokens = Token.MeshTokens.concat(Token.MeshGroupNode);\n Token.MeshAndGroupTokenMap = Token.MapFrom(...Token.MeshAndGroupTokens);\n Token.SpaceTokens = Token.MeshAndGroupTokens.concat(Token.SceneNode);\n Token.SpaceTokenMap = Token.MapFrom(...Token.SpaceTokens);\n Token.MaterialTokens = [Token.AdvancedMaterialNode];\n Token.MaterialTokenMap = Token.MapFrom(...Token.MaterialTokens);\n Token.AnnotationTokens = [Token.AnnotationNode, Token.DimensionNode];\n Token.AnnotationTokenMap = Token.MapFrom(...Token.AnnotationTokens);\n Token.PositionalLightTokens = [Token.PointLightNode, Token.SpotLightNode];\n Token.GlobalLightTokens = [Token.DirectionalLightNode, Token.HemisphericLightNode];\n Token.LightTokens = [...Token.GlobalLightTokens, ...Token.PositionalLightTokens];\n Token.LightTokenMap = Token.MapFrom(...Token.LightTokens);\n Token.FeatureTokens = [\n Token.MoveVerticesFeature,\n Token.WeldVerticesFeature,\n Token.DisplacementMapFeature,\n Token.UvMapFeature,\n Token.SubmeshFeature,\n Token.LinearPatternFeature,\n Token.CircularPatternFeature,\n Token.JoinGeometryFeature,\n Token.DeleteFacesFeature,\n Token.NormalSmoothingFeature,\n Token.SliceFeature,\n Token.MirrorFeature,\n Token.TransformFeature,\n Token.ExtrudeFeature,\n Token.SweepFeature,\n ];\n Token.FeatureTokenMap = Token.MapFrom(...Token.FeatureTokens);\n Token.ConnectorTokens = [Token.Connector, Token.SketchControlPoint];\n Token.TextureLayerTokens = [\n Token.TextureLayer,\n Token.FileTextureLayer,\n Token.SvgTextureLayer,\n Token.TextTextureLayer,\n Token.ColorFillTextureLayer,\n ];\n Token.TextureLayerTokenMap = Token.MapFrom(...Token.TextureLayerTokens);\n Token.NodeTokens = [\n ...Token.SpaceTokens,\n ...Token.MaterialTokens,\n ...Token.LightTokens,\n ...Token.AnnotationTokens,\n Token.ViewpointNode,\n Token.MateNode,\n ];\n Token.NodeTokenMap = Token.MapFrom(...Token.NodeTokens);\n Token.BaseNodeTokens = [\n Token.SpaceNode,\n Token.MaterialNode,\n Token.LightNode,\n Token.ViewpointNode,\n Token.MateNode,\n Token.AnnotationNode,\n ];\n Token.AllTokens = Token.NodeTokens.concat(...Token.PrimitiveTokens, Token.FeatureTokens, Token.TextureLayerTokens, Token.ConnectorTokens, [Token.SketchPath]);\n Token.AllTokenMap = Token.MapFrom(...Token.AllTokens);\n\n const Kb3dModels = new Map();\n /**\n * Curry function to filter items in an array to items of a token type\n * @param classKey String key of the class you want to see if the instance is an instance of\n */\n function ofToken(token) {\n return (instance) => instanceOf(instance, token);\n }\n /**\n * Checks if the instance of a class given is an instance of the class represented by it's\n * injectable class key. If the instance is an instance of a class that was not\n * decorated, or if the class represented by the key was not decorated, then this will\n * return false!\n * @param instance An instance of a class that was decorated\n * @param classKey String key of the class you want to see if the instance is an instance of\n */\n function instanceOf(instance, token) {\n if (!instance)\n return false;\n const model = Kb3dModels.get(token);\n return model ? instance instanceof model.classConstructor : false;\n }\n /** Curry-able version of instanceOf */\n function isInstanceOf(token) {\n return (instance) => instanceOf(instance, token);\n }\n function getToken(object) {\n const node = object;\n if (node.$type) {\n return Token.tryWithKey(node.$type);\n }\n }\n /**\n * Checks if the instance of a class given is an instance of the class represented by it's\n * injectable class key. If the instance is an instance of a class that was not\n * decorated, or if the class represented by the key was not decorated, then this will\n * return false!\n * @param instance An instance of a class that was decorated\n * @param classKey String key of the class you want to see if the instance is an instance of\n */\n function instanceOfAny(instance, ...tokens) {\n if (!instance)\n return false;\n return tokens.some(t => instanceOf(instance, t));\n }\n\n (function (EChangeOperation) {\n // CreateAndPush and Remove correspond to functions in the custom KBArray class.\n // They use Push and Splice internally but also signify we need a\n // changeTracker destroy on undo and redo respectively and create on redo and undo respectively.\n EChangeOperation[EChangeOperation[\"Push\"] = 0] = \"Push\";\n EChangeOperation[EChangeOperation[\"Pop\"] = 1] = \"Pop\";\n EChangeOperation[EChangeOperation[\"Shift\"] = 2] = \"Shift\";\n EChangeOperation[EChangeOperation[\"Unshift\"] = 3] = \"Unshift\";\n EChangeOperation[EChangeOperation[\"Splice\"] = 4] = \"Splice\";\n EChangeOperation[EChangeOperation[\"CreateAndPush\"] = 5] = \"CreateAndPush\";\n EChangeOperation[EChangeOperation[\"Remove\"] = 6] = \"Remove\";\n })(exports.EChangeOperation || (exports.EChangeOperation = {}));\n function isTrackedClass(object) {\n return object && typeof object === 'object' && '$changesTracked' in object;\n }\n function isTrackedArray(object) {\n return !!object.$isTracked;\n }\n function isTrackedInstance(instance, token) {\n if (!instance)\n return false;\n const model = Kb3dModels.get(token);\n return model ? instance instanceof model.classConstructor && isTrackedClass(instance) : false;\n }\n function isTrackedInstanceOfAny(instance, ...tokens) {\n if (!instance)\n return false;\n return tokens.some(t => isTrackedInstance(instance, t));\n }\n\n const changedItems = new Set();\n const deletedItems = new Set();\n /** This class syncs changes to the renderer to update the scene view */\n class SyncService {\n static registerChangedState(tracker, modified) {\n if (modified) {\n // If node was deleted, ignore further changes, unless the item was moved to a different parent\n if (!deletedItems.has(tracker) || tracker.changes.has('_parent')) {\n changedItems.add(tracker);\n }\n }\n else {\n changedItems.delete(tracker);\n }\n }\n // When a new object is being created, the proxy being used to set the values will be the proxy of the parent of the class being created.\n // So, we need to make sure the changed items map is always pointing to the correct proxy (the proxy with the highest specificity)\n static registerNewObject(tracker) {\n changedItems.add(tracker);\n }\n static registerDeleted(tracker) {\n deletedItems.add(tracker);\n }\n static get hasChanges() {\n return changedItems.size > 0 || deletedItems.size > 0;\n }\n static getChangedNodes() {\n return [...changedItems.values()];\n }\n static getDeletedNodes() {\n return [...deletedItems.values()];\n }\n static nodeDeletionProcessed(tracker) {\n //when a node is deleted, we remove it from all the maps\n changedItems.delete(tracker);\n deletedItems.delete(tracker);\n }\n static nodeChangesProcessed(tracker) {\n //when node changes have been processed, we only remove it from the changedItems map\n changedItems.delete(tracker);\n }\n }\n\n /*! *****************************************************************************\r\n Copyright (c) Microsoft Corporation.\r\n\r\n Permission to use, copy, modify, and/or distribute this software for any\r\n purpose with or without fee is hereby granted.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\n PERFORMANCE OF THIS SOFTWARE.\r\n ***************************************************************************** */\r\n /* global Reflect, Promise */\r\n\r\n var extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n };\r\n\r\n function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function isFunction(x) {\n return typeof x === 'function';\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var _enable_super_gross_mode_that_will_cause_bad_things = false;\n var config = {\n Promise: undefined,\n set useDeprecatedSynchronousErrorHandling(value) {\n if (value) {\n var error = /*@__PURE__*/ new Error();\n /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \\n' + error.stack);\n }\n _enable_super_gross_mode_that_will_cause_bad_things = value;\n },\n get useDeprecatedSynchronousErrorHandling() {\n return _enable_super_gross_mode_that_will_cause_bad_things;\n },\n };\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function hostReportError(err) {\n setTimeout(function () { throw err; }, 0);\n }\n\n /** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */\n var empty = {\n closed: true,\n next: function (value) { },\n error: function (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n },\n complete: function () { }\n };\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function isObject(x) {\n return x !== null && typeof x === 'object';\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {\n function UnsubscriptionErrorImpl(errors) {\n Error.call(this);\n this.message = errors ?\n errors.length + \" errors occurred during unsubscription:\\n\" + errors.map(function (err, i) { return i + 1 + \") \" + err.toString(); }).join('\\n ') : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n return this;\n }\n UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return UnsubscriptionErrorImpl;\n })();\n var UnsubscriptionError = UnsubscriptionErrorImpl;\n\n /** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */\n var Subscription = /*@__PURE__*/ (function () {\n function Subscription(unsubscribe) {\n this.closed = false;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (unsubscribe) {\n this._ctorUnsubscribe = true;\n this._unsubscribe = unsubscribe;\n }\n }\n Subscription.prototype.unsubscribe = function () {\n var errors;\n if (this.closed) {\n return;\n }\n var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;\n this.closed = true;\n this._parentOrParents = null;\n this._subscriptions = null;\n if (_parentOrParents instanceof Subscription) {\n _parentOrParents.remove(this);\n }\n else if (_parentOrParents !== null) {\n for (var index = 0; index < _parentOrParents.length; ++index) {\n var parent_1 = _parentOrParents[index];\n parent_1.remove(this);\n }\n }\n if (isFunction(_unsubscribe)) {\n if (_ctorUnsubscribe) {\n this._unsubscribe = undefined;\n }\n try {\n _unsubscribe.call(this);\n }\n catch (e) {\n errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];\n }\n }\n if (isArray(_subscriptions)) {\n var index = -1;\n var len = _subscriptions.length;\n while (++index < len) {\n var sub = _subscriptions[index];\n if (isObject(sub)) {\n try {\n sub.unsubscribe();\n }\n catch (e) {\n errors = errors || [];\n if (e instanceof UnsubscriptionError) {\n errors = errors.concat(flattenUnsubscriptionErrors(e.errors));\n }\n else {\n errors.push(e);\n }\n }\n }\n }\n }\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n };\n Subscription.prototype.add = function (teardown) {\n var subscription = teardown;\n if (!teardown) {\n return Subscription.EMPTY;\n }\n switch (typeof teardown) {\n case 'function':\n subscription = new Subscription(teardown);\n case 'object':\n if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {\n return subscription;\n }\n else if (this.closed) {\n subscription.unsubscribe();\n return subscription;\n }\n else if (!(subscription instanceof Subscription)) {\n var tmp = subscription;\n subscription = new Subscription();\n subscription._subscriptions = [tmp];\n }\n break;\n default: {\n throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');\n }\n }\n var _parentOrParents = subscription._parentOrParents;\n if (_parentOrParents === null) {\n subscription._parentOrParents = this;\n }\n else if (_parentOrParents instanceof Subscription) {\n if (_parentOrParents === this) {\n return subscription;\n }\n subscription._parentOrParents = [_parentOrParents, this];\n }\n else if (_parentOrParents.indexOf(this) === -1) {\n _parentOrParents.push(this);\n }\n else {\n return subscription;\n }\n var subscriptions = this._subscriptions;\n if (subscriptions === null) {\n this._subscriptions = [subscription];\n }\n else {\n subscriptions.push(subscription);\n }\n return subscription;\n };\n Subscription.prototype.remove = function (subscription) {\n var subscriptions = this._subscriptions;\n if (subscriptions) {\n var subscriptionIndex = subscriptions.indexOf(subscription);\n if (subscriptionIndex !== -1) {\n subscriptions.splice(subscriptionIndex, 1);\n }\n }\n };\n Subscription.EMPTY = (function (empty) {\n empty.closed = true;\n return empty;\n }(new Subscription()));\n return Subscription;\n }());\n function flattenUnsubscriptionErrors(errors) {\n return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var rxSubscriber = /*@__PURE__*/ (function () {\n return typeof Symbol === 'function'\n ? /*@__PURE__*/ Symbol('rxSubscriber')\n : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();\n })();\n\n /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */\n var Subscriber = /*@__PURE__*/ (function (_super) {\n __extends(Subscriber, _super);\n function Subscriber(destinationOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this.syncErrorValue = null;\n _this.syncErrorThrown = false;\n _this.syncErrorThrowable = false;\n _this.isStopped = false;\n switch (arguments.length) {\n case 0:\n _this.destination = empty;\n break;\n case 1:\n if (!destinationOrNext) {\n _this.destination = empty;\n break;\n }\n if (typeof destinationOrNext === 'object') {\n if (destinationOrNext instanceof Subscriber) {\n _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;\n _this.destination = destinationOrNext;\n destinationOrNext.add(_this);\n }\n else {\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext);\n }\n break;\n }\n default:\n _this.syncErrorThrowable = true;\n _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);\n break;\n }\n return _this;\n }\n Subscriber.prototype[rxSubscriber] = function () { return this; };\n Subscriber.create = function (next, error, complete) {\n var subscriber = new Subscriber(next, error, complete);\n subscriber.syncErrorThrowable = false;\n return subscriber;\n };\n Subscriber.prototype.next = function (value) {\n if (!this.isStopped) {\n this._next(value);\n }\n };\n Subscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n this.isStopped = true;\n this._error(err);\n }\n };\n Subscriber.prototype.complete = function () {\n if (!this.isStopped) {\n this.isStopped = true;\n this._complete();\n }\n };\n Subscriber.prototype.unsubscribe = function () {\n if (this.closed) {\n return;\n }\n this.isStopped = true;\n _super.prototype.unsubscribe.call(this);\n };\n Subscriber.prototype._next = function (value) {\n this.destination.next(value);\n };\n Subscriber.prototype._error = function (err) {\n this.destination.error(err);\n this.unsubscribe();\n };\n Subscriber.prototype._complete = function () {\n this.destination.complete();\n this.unsubscribe();\n };\n Subscriber.prototype._unsubscribeAndRecycle = function () {\n var _parentOrParents = this._parentOrParents;\n this._parentOrParents = null;\n this.unsubscribe();\n this.closed = false;\n this.isStopped = false;\n this._parentOrParents = _parentOrParents;\n return this;\n };\n return Subscriber;\n }(Subscription));\n var SafeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SafeSubscriber, _super);\n function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {\n var _this = _super.call(this) || this;\n _this._parentSubscriber = _parentSubscriber;\n var next;\n var context = _this;\n if (isFunction(observerOrNext)) {\n next = observerOrNext;\n }\n else if (observerOrNext) {\n next = observerOrNext.next;\n error = observerOrNext.error;\n complete = observerOrNext.complete;\n if (observerOrNext !== empty) {\n context = Object.create(observerOrNext);\n if (isFunction(context.unsubscribe)) {\n _this.add(context.unsubscribe.bind(context));\n }\n context.unsubscribe = _this.unsubscribe.bind(_this);\n }\n }\n _this._context = context;\n _this._next = next;\n _this._error = error;\n _this._complete = complete;\n return _this;\n }\n SafeSubscriber.prototype.next = function (value) {\n if (!this.isStopped && this._next) {\n var _parentSubscriber = this._parentSubscriber;\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._next, value);\n }\n else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.error = function (err) {\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;\n if (this._error) {\n if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._error, err);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, this._error, err);\n this.unsubscribe();\n }\n }\n else if (!_parentSubscriber.syncErrorThrowable) {\n this.unsubscribe();\n if (useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n hostReportError(err);\n }\n else {\n if (useDeprecatedSynchronousErrorHandling) {\n _parentSubscriber.syncErrorValue = err;\n _parentSubscriber.syncErrorThrown = true;\n }\n else {\n hostReportError(err);\n }\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.complete = function () {\n var _this = this;\n if (!this.isStopped) {\n var _parentSubscriber = this._parentSubscriber;\n if (this._complete) {\n var wrappedComplete = function () { return _this._complete.call(_this._context); };\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(wrappedComplete);\n this.unsubscribe();\n }\n else {\n this.__tryOrSetError(_parentSubscriber, wrappedComplete);\n this.unsubscribe();\n }\n }\n else {\n this.unsubscribe();\n }\n }\n };\n SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n this.unsubscribe();\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n else {\n hostReportError(err);\n }\n }\n };\n SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {\n if (!config.useDeprecatedSynchronousErrorHandling) {\n throw new Error('bad call');\n }\n try {\n fn.call(this._context, value);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n parent.syncErrorValue = err;\n parent.syncErrorThrown = true;\n return true;\n }\n else {\n hostReportError(err);\n return true;\n }\n }\n return false;\n };\n SafeSubscriber.prototype._unsubscribe = function () {\n var _parentSubscriber = this._parentSubscriber;\n this._context = null;\n this._parentSubscriber = null;\n _parentSubscriber.unsubscribe();\n };\n return SafeSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */\n function canReportError(observer) {\n while (observer) {\n var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;\n if (closed_1 || isStopped) {\n return false;\n }\n else if (destination && destination instanceof Subscriber) {\n observer = destination;\n }\n else {\n observer = null;\n }\n }\n return true;\n }\n\n /** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */\n function toSubscriber(nextOrObserver, error, complete) {\n if (nextOrObserver) {\n if (nextOrObserver instanceof Subscriber) {\n return nextOrObserver;\n }\n if (nextOrObserver[rxSubscriber]) {\n return nextOrObserver[rxSubscriber]();\n }\n }\n if (!nextOrObserver && !error && !complete) {\n return new Subscriber(empty);\n }\n return new Subscriber(nextOrObserver, error, complete);\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function identity(x) {\n return x;\n }\n\n /** PURE_IMPORTS_START _identity PURE_IMPORTS_END */\n function pipeFromArray(fns) {\n if (fns.length === 0) {\n return identity;\n }\n if (fns.length === 1) {\n return fns[0];\n }\n return function piped(input) {\n return fns.reduce(function (prev, fn) { return fn(prev); }, input);\n };\n }\n\n /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */\n var Observable = /*@__PURE__*/ (function () {\n function Observable(subscribe) {\n this._isScalar = false;\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n Observable.prototype.lift = function (operator) {\n var observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n };\n Observable.prototype.subscribe = function (observerOrNext, error, complete) {\n var operator = this.operator;\n var sink = toSubscriber(observerOrNext, error, complete);\n if (operator) {\n sink.add(operator.call(sink, this.source));\n }\n else {\n sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?\n this._subscribe(sink) :\n this._trySubscribe(sink));\n }\n if (config.useDeprecatedSynchronousErrorHandling) {\n if (sink.syncErrorThrowable) {\n sink.syncErrorThrowable = false;\n if (sink.syncErrorThrown) {\n throw sink.syncErrorValue;\n }\n }\n }\n return sink;\n };\n Observable.prototype._trySubscribe = function (sink) {\n try {\n return this._subscribe(sink);\n }\n catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n sink.syncErrorThrown = true;\n sink.syncErrorValue = err;\n }\n if (canReportError(sink)) {\n sink.error(err);\n }\n else {\n console.warn(err);\n }\n }\n };\n Observable.prototype.forEach = function (next, promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var subscription;\n subscription = _this.subscribe(function (value) {\n try {\n next(value);\n }\n catch (err) {\n reject(err);\n if (subscription) {\n subscription.unsubscribe();\n }\n }\n }, reject, resolve);\n });\n };\n Observable.prototype._subscribe = function (subscriber) {\n var source = this.source;\n return source && source.subscribe(subscriber);\n };\n Observable.prototype[observable] = function () {\n return this;\n };\n Observable.prototype.pipe = function () {\n var operations = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n operations[_i] = arguments[_i];\n }\n if (operations.length === 0) {\n return this;\n }\n return pipeFromArray(operations)(this);\n };\n Observable.prototype.toPromise = function (promiseCtor) {\n var _this = this;\n promiseCtor = getPromiseCtor(promiseCtor);\n return new promiseCtor(function (resolve, reject) {\n var value;\n _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });\n });\n };\n Observable.create = function (subscribe) {\n return new Observable(subscribe);\n };\n return Observable;\n }());\n function getPromiseCtor(promiseCtor) {\n if (!promiseCtor) {\n promiseCtor = Promise;\n }\n if (!promiseCtor) {\n throw new Error('no Promise impl found');\n }\n return promiseCtor;\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var ObjectUnsubscribedErrorImpl = /*@__PURE__*/ (function () {\n function ObjectUnsubscribedErrorImpl() {\n Error.call(this);\n this.message = 'object unsubscribed';\n this.name = 'ObjectUnsubscribedError';\n return this;\n }\n ObjectUnsubscribedErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return ObjectUnsubscribedErrorImpl;\n })();\n var ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;\n\n /** PURE_IMPORTS_START tslib,_Subscription PURE_IMPORTS_END */\n var SubjectSubscription = /*@__PURE__*/ (function (_super) {\n __extends(SubjectSubscription, _super);\n function SubjectSubscription(subject, subscriber) {\n var _this = _super.call(this) || this;\n _this.subject = subject;\n _this.subscriber = subscriber;\n _this.closed = false;\n return _this;\n }\n SubjectSubscription.prototype.unsubscribe = function () {\n if (this.closed) {\n return;\n }\n this.closed = true;\n var subject = this.subject;\n var observers = subject.observers;\n this.subject = null;\n if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {\n return;\n }\n var subscriberIndex = observers.indexOf(this.subscriber);\n if (subscriberIndex !== -1) {\n observers.splice(subscriberIndex, 1);\n }\n };\n return SubjectSubscription;\n }(Subscription));\n\n /** PURE_IMPORTS_START tslib,_Observable,_Subscriber,_Subscription,_util_ObjectUnsubscribedError,_SubjectSubscription,_internal_symbol_rxSubscriber PURE_IMPORTS_END */\n var SubjectSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SubjectSubscriber, _super);\n function SubjectSubscriber(destination) {\n var _this = _super.call(this, destination) || this;\n _this.destination = destination;\n return _this;\n }\n return SubjectSubscriber;\n }(Subscriber));\n var Subject = /*@__PURE__*/ (function (_super) {\n __extends(Subject, _super);\n function Subject() {\n var _this = _super.call(this) || this;\n _this.observers = [];\n _this.closed = false;\n _this.isStopped = false;\n _this.hasError = false;\n _this.thrownError = null;\n return _this;\n }\n Subject.prototype[rxSubscriber] = function () {\n return new SubjectSubscriber(this);\n };\n Subject.prototype.lift = function (operator) {\n var subject = new AnonymousSubject(this, this);\n subject.operator = operator;\n return subject;\n };\n Subject.prototype.next = function (value) {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n if (!this.isStopped) {\n var observers = this.observers;\n var len = observers.length;\n var copy = observers.slice();\n for (var i = 0; i < len; i++) {\n copy[i].next(value);\n }\n }\n };\n Subject.prototype.error = function (err) {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n this.hasError = true;\n this.thrownError = err;\n this.isStopped = true;\n var observers = this.observers;\n var len = observers.length;\n var copy = observers.slice();\n for (var i = 0; i < len; i++) {\n copy[i].error(err);\n }\n this.observers.length = 0;\n };\n Subject.prototype.complete = function () {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n this.isStopped = true;\n var observers = this.observers;\n var len = observers.length;\n var copy = observers.slice();\n for (var i = 0; i < len; i++) {\n copy[i].complete();\n }\n this.observers.length = 0;\n };\n Subject.prototype.unsubscribe = function () {\n this.isStopped = true;\n this.closed = true;\n this.observers = null;\n };\n Subject.prototype._trySubscribe = function (subscriber) {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n else {\n return _super.prototype._trySubscribe.call(this, subscriber);\n }\n };\n Subject.prototype._subscribe = function (subscriber) {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n else if (this.hasError) {\n subscriber.error(this.thrownError);\n return Subscription.EMPTY;\n }\n else if (this.isStopped) {\n subscriber.complete();\n return Subscription.EMPTY;\n }\n else {\n this.observers.push(subscriber);\n return new SubjectSubscription(this, subscriber);\n }\n };\n Subject.prototype.asObservable = function () {\n var observable = new Observable();\n observable.source = this;\n return observable;\n };\n Subject.create = function (destination, source) {\n return new AnonymousSubject(destination, source);\n };\n return Subject;\n }(Observable));\n var AnonymousSubject = /*@__PURE__*/ (function (_super) {\n __extends(AnonymousSubject, _super);\n function AnonymousSubject(destination, source) {\n var _this = _super.call(this) || this;\n _this.destination = destination;\n _this.source = source;\n return _this;\n }\n AnonymousSubject.prototype.next = function (value) {\n var destination = this.destination;\n if (destination && destination.next) {\n destination.next(value);\n }\n };\n AnonymousSubject.prototype.error = function (err) {\n var destination = this.destination;\n if (destination && destination.error) {\n this.destination.error(err);\n }\n };\n AnonymousSubject.prototype.complete = function () {\n var destination = this.destination;\n if (destination && destination.complete) {\n this.destination.complete();\n }\n };\n AnonymousSubject.prototype._subscribe = function (subscriber) {\n var source = this.source;\n if (source) {\n return this.source.subscribe(subscriber);\n }\n else {\n return Subscription.EMPTY;\n }\n };\n return AnonymousSubject;\n }(Subject));\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n function refCount() {\n return function refCountOperatorFunction(source) {\n return source.lift(new RefCountOperator(source));\n };\n }\n var RefCountOperator = /*@__PURE__*/ (function () {\n function RefCountOperator(connectable) {\n this.connectable = connectable;\n }\n RefCountOperator.prototype.call = function (subscriber, source) {\n var connectable = this.connectable;\n connectable._refCount++;\n var refCounter = new RefCountSubscriber(subscriber, connectable);\n var subscription = source.subscribe(refCounter);\n if (!refCounter.closed) {\n refCounter.connection = connectable.connect();\n }\n return subscription;\n };\n return RefCountOperator;\n }());\n var RefCountSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(RefCountSubscriber, _super);\n function RefCountSubscriber(destination, connectable) {\n var _this = _super.call(this, destination) || this;\n _this.connectable = connectable;\n return _this;\n }\n RefCountSubscriber.prototype._unsubscribe = function () {\n var connectable = this.connectable;\n if (!connectable) {\n this.connection = null;\n return;\n }\n this.connectable = null;\n var refCount = connectable._refCount;\n if (refCount <= 0) {\n this.connection = null;\n return;\n }\n connectable._refCount = refCount - 1;\n if (refCount > 1) {\n this.connection = null;\n return;\n }\n var connection = this.connection;\n var sharedConnection = connectable._connection;\n this.connection = null;\n if (sharedConnection && (!connection || sharedConnection === connection)) {\n sharedConnection.unsubscribe();\n }\n };\n return RefCountSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_Subject,_Observable,_Subscriber,_Subscription,_operators_refCount PURE_IMPORTS_END */\n var ConnectableObservable = /*@__PURE__*/ (function (_super) {\n __extends(ConnectableObservable, _super);\n function ConnectableObservable(source, subjectFactory) {\n var _this = _super.call(this) || this;\n _this.source = source;\n _this.subjectFactory = subjectFactory;\n _this._refCount = 0;\n _this._isComplete = false;\n return _this;\n }\n ConnectableObservable.prototype._subscribe = function (subscriber) {\n return this.getSubject().subscribe(subscriber);\n };\n ConnectableObservable.prototype.getSubject = function () {\n var subject = this._subject;\n if (!subject || subject.isStopped) {\n this._subject = this.subjectFactory();\n }\n return this._subject;\n };\n ConnectableObservable.prototype.connect = function () {\n var connection = this._connection;\n if (!connection) {\n this._isComplete = false;\n connection = this._connection = new Subscription();\n connection.add(this.source\n .subscribe(new ConnectableSubscriber(this.getSubject(), this)));\n if (connection.closed) {\n this._connection = null;\n connection = Subscription.EMPTY;\n }\n }\n return connection;\n };\n ConnectableObservable.prototype.refCount = function () {\n return refCount()(this);\n };\n return ConnectableObservable;\n }(Observable));\n var connectableObservableDescriptor = /*@__PURE__*/ (function () {\n var connectableProto = ConnectableObservable.prototype;\n return {\n operator: { value: null },\n _refCount: { value: 0, writable: true },\n _subject: { value: null, writable: true },\n _connection: { value: null, writable: true },\n _subscribe: { value: connectableProto._subscribe },\n _isComplete: { value: connectableProto._isComplete, writable: true },\n getSubject: { value: connectableProto.getSubject },\n connect: { value: connectableProto.connect },\n refCount: { value: connectableProto.refCount }\n };\n })();\n var ConnectableSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(ConnectableSubscriber, _super);\n function ConnectableSubscriber(destination, connectable) {\n var _this = _super.call(this, destination) || this;\n _this.connectable = connectable;\n return _this;\n }\n ConnectableSubscriber.prototype._error = function (err) {\n this._unsubscribe();\n _super.prototype._error.call(this, err);\n };\n ConnectableSubscriber.prototype._complete = function () {\n this.connectable._isComplete = true;\n this._unsubscribe();\n _super.prototype._complete.call(this);\n };\n ConnectableSubscriber.prototype._unsubscribe = function () {\n var connectable = this.connectable;\n if (connectable) {\n this.connectable = null;\n var connection = connectable._connection;\n connectable._refCount = 0;\n connectable._subject = null;\n connectable._connection = null;\n if (connection) {\n connection.unsubscribe();\n }\n }\n };\n return ConnectableSubscriber;\n }(SubjectSubscriber));\n\n /** PURE_IMPORTS_START tslib,_Subject,_util_ObjectUnsubscribedError PURE_IMPORTS_END */\n var BehaviorSubject = /*@__PURE__*/ (function (_super) {\n __extends(BehaviorSubject, _super);\n function BehaviorSubject(_value) {\n var _this = _super.call(this) || this;\n _this._value = _value;\n return _this;\n }\n Object.defineProperty(BehaviorSubject.prototype, \"value\", {\n get: function () {\n return this.getValue();\n },\n enumerable: true,\n configurable: true\n });\n BehaviorSubject.prototype._subscribe = function (subscriber) {\n var subscription = _super.prototype._subscribe.call(this, subscriber);\n if (subscription && !subscription.closed) {\n subscriber.next(this._value);\n }\n return subscription;\n };\n BehaviorSubject.prototype.getValue = function () {\n if (this.hasError) {\n throw this.thrownError;\n }\n else if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n else {\n return this._value;\n }\n };\n BehaviorSubject.prototype.next = function (value) {\n _super.prototype.next.call(this, this._value = value);\n };\n return BehaviorSubject;\n }(Subject));\n\n /** PURE_IMPORTS_START tslib,_Subscription PURE_IMPORTS_END */\n var Action = /*@__PURE__*/ (function (_super) {\n __extends(Action, _super);\n function Action(scheduler, work) {\n return _super.call(this) || this;\n }\n Action.prototype.schedule = function (state, delay) {\n return this;\n };\n return Action;\n }(Subscription));\n\n /** PURE_IMPORTS_START tslib,_Action PURE_IMPORTS_END */\n var AsyncAction = /*@__PURE__*/ (function (_super) {\n __extends(AsyncAction, _super);\n function AsyncAction(scheduler, work) {\n var _this = _super.call(this, scheduler, work) || this;\n _this.scheduler = scheduler;\n _this.work = work;\n _this.pending = false;\n return _this;\n }\n AsyncAction.prototype.schedule = function (state, delay) {\n if (delay === void 0) {\n delay = 0;\n }\n if (this.closed) {\n return this;\n }\n this.state = state;\n var id = this.id;\n var scheduler = this.scheduler;\n if (id != null) {\n this.id = this.recycleAsyncId(scheduler, id, delay);\n }\n this.pending = true;\n this.delay = delay;\n this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);\n return this;\n };\n AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {\n if (delay === void 0) {\n delay = 0;\n }\n return setInterval(scheduler.flush.bind(scheduler, this), delay);\n };\n AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {\n if (delay === void 0) {\n delay = 0;\n }\n if (delay !== null && this.delay === delay && this.pending === false) {\n return id;\n }\n clearInterval(id);\n return undefined;\n };\n AsyncAction.prototype.execute = function (state, delay) {\n if (this.closed) {\n return new Error('executing a cancelled action');\n }\n this.pending = false;\n var error = this._execute(state, delay);\n if (error) {\n return error;\n }\n else if (this.pending === false && this.id != null) {\n this.id = this.recycleAsyncId(this.scheduler, this.id, null);\n }\n };\n AsyncAction.prototype._execute = function (state, delay) {\n var errored = false;\n var errorValue = undefined;\n try {\n this.work(state);\n }\n catch (e) {\n errored = true;\n errorValue = !!e && e || new Error(e);\n }\n if (errored) {\n this.unsubscribe();\n return errorValue;\n }\n };\n AsyncAction.prototype._unsubscribe = function () {\n var id = this.id;\n var scheduler = this.scheduler;\n var actions = scheduler.actions;\n var index = actions.indexOf(this);\n this.work = null;\n this.state = null;\n this.pending = false;\n this.scheduler = null;\n if (index !== -1) {\n actions.splice(index, 1);\n }\n if (id != null) {\n this.id = this.recycleAsyncId(scheduler, id, null);\n }\n this.delay = null;\n };\n return AsyncAction;\n }(Action));\n\n /** PURE_IMPORTS_START tslib,_AsyncAction PURE_IMPORTS_END */\n var QueueAction = /*@__PURE__*/ (function (_super) {\n __extends(QueueAction, _super);\n function QueueAction(scheduler, work) {\n var _this = _super.call(this, scheduler, work) || this;\n _this.scheduler = scheduler;\n _this.work = work;\n return _this;\n }\n QueueAction.prototype.schedule = function (state, delay) {\n if (delay === void 0) {\n delay = 0;\n }\n if (delay > 0) {\n return _super.prototype.schedule.call(this, state, delay);\n }\n this.delay = delay;\n this.state = state;\n this.scheduler.flush(this);\n return this;\n };\n QueueAction.prototype.execute = function (state, delay) {\n return (delay > 0 || this.closed) ?\n _super.prototype.execute.call(this, state, delay) :\n this._execute(state, delay);\n };\n QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {\n if (delay === void 0) {\n delay = 0;\n }\n if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {\n return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);\n }\n return scheduler.flush(this);\n };\n return QueueAction;\n }(AsyncAction));\n\n var Scheduler = /*@__PURE__*/ (function () {\n function Scheduler(SchedulerAction, now) {\n if (now === void 0) {\n now = Scheduler.now;\n }\n this.SchedulerAction = SchedulerAction;\n this.now = now;\n }\n Scheduler.prototype.schedule = function (work, delay, state) {\n if (delay === void 0) {\n delay = 0;\n }\n return new this.SchedulerAction(this, work).schedule(state, delay);\n };\n Scheduler.now = function () { return Date.now(); };\n return Scheduler;\n }());\n\n /** PURE_IMPORTS_START tslib,_Scheduler PURE_IMPORTS_END */\n var AsyncScheduler = /*@__PURE__*/ (function (_super) {\n __extends(AsyncScheduler, _super);\n function AsyncScheduler(SchedulerAction, now) {\n if (now === void 0) {\n now = Scheduler.now;\n }\n var _this = _super.call(this, SchedulerAction, function () {\n if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {\n return AsyncScheduler.delegate.now();\n }\n else {\n return now();\n }\n }) || this;\n _this.actions = [];\n _this.active = false;\n _this.scheduled = undefined;\n return _this;\n }\n AsyncScheduler.prototype.schedule = function (work, delay, state) {\n if (delay === void 0) {\n delay = 0;\n }\n if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {\n return AsyncScheduler.delegate.schedule(work, delay, state);\n }\n else {\n return _super.prototype.schedule.call(this, work, delay, state);\n }\n };\n AsyncScheduler.prototype.flush = function (action) {\n var actions = this.actions;\n if (this.active) {\n actions.push(action);\n return;\n }\n var error;\n this.active = true;\n do {\n if (error = action.execute(action.state, action.delay)) {\n break;\n }\n } while (action = actions.shift());\n this.active = false;\n if (error) {\n while (action = actions.shift()) {\n action.unsubscribe();\n }\n throw error;\n }\n };\n return AsyncScheduler;\n }(Scheduler));\n\n /** PURE_IMPORTS_START tslib,_AsyncScheduler PURE_IMPORTS_END */\n var QueueScheduler = /*@__PURE__*/ (function (_super) {\n __extends(QueueScheduler, _super);\n function QueueScheduler() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n return QueueScheduler;\n }(AsyncScheduler));\n\n /** PURE_IMPORTS_START _QueueAction,_QueueScheduler PURE_IMPORTS_END */\n var queueScheduler = /*@__PURE__*/ new QueueScheduler(QueueAction);\n var queue = queueScheduler;\n\n /** PURE_IMPORTS_START _Observable PURE_IMPORTS_END */\n var EMPTY = /*@__PURE__*/ new Observable(function (subscriber) { return subscriber.complete(); });\n function empty$1(scheduler) {\n return scheduler ? emptyScheduled(scheduler) : EMPTY;\n }\n function emptyScheduled(scheduler) {\n return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function isScheduler(value) {\n return value && typeof value.schedule === 'function';\n }\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var subscribeToArray = function (array) {\n return function (subscriber) {\n for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) {\n subscriber.next(array[i]);\n }\n subscriber.complete();\n };\n };\n\n /** PURE_IMPORTS_START _Observable,_Subscription PURE_IMPORTS_END */\n function scheduleArray(input, scheduler) {\n return new Observable(function (subscriber) {\n var sub = new Subscription();\n var i = 0;\n sub.add(scheduler.schedule(function () {\n if (i === input.length) {\n subscriber.complete();\n return;\n }\n subscriber.next(input[i++]);\n if (!subscriber.closed) {\n sub.add(this.schedule());\n }\n }));\n return sub;\n });\n }\n\n /** PURE_IMPORTS_START _Observable,_util_subscribeToArray,_scheduled_scheduleArray PURE_IMPORTS_END */\n function fromArray(input, scheduler) {\n if (!scheduler) {\n return new Observable(subscribeToArray(input));\n }\n else {\n return scheduleArray(input, scheduler);\n }\n }\n\n /** PURE_IMPORTS_START _util_isScheduler,_fromArray,_scheduled_scheduleArray PURE_IMPORTS_END */\n function of() {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n var scheduler = args[args.length - 1];\n if (isScheduler(scheduler)) {\n args.pop();\n return scheduleArray(args, scheduler);\n }\n else {\n return fromArray(args);\n }\n }\n\n /** PURE_IMPORTS_START _Observable PURE_IMPORTS_END */\n function throwError(error, scheduler) {\n if (!scheduler) {\n return new Observable(function (subscriber) { return subscriber.error(error); });\n }\n else {\n return new Observable(function (subscriber) { return scheduler.schedule(dispatch, 0, { error: error, subscriber: subscriber }); });\n }\n }\n function dispatch(_a) {\n var error = _a.error, subscriber = _a.subscriber;\n subscriber.error(error);\n }\n\n /** PURE_IMPORTS_START _observable_empty,_observable_of,_observable_throwError PURE_IMPORTS_END */\n var Notification = /*@__PURE__*/ (function () {\n function Notification(kind, value, error) {\n this.kind = kind;\n this.value = value;\n this.error = error;\n this.hasValue = kind === 'N';\n }\n Notification.prototype.observe = function (observer) {\n switch (this.kind) {\n case 'N':\n return observer.next && observer.next(this.value);\n case 'E':\n return observer.error && observer.error(this.error);\n case 'C':\n return observer.complete && observer.complete();\n }\n };\n Notification.prototype.do = function (next, error, complete) {\n var kind = this.kind;\n switch (kind) {\n case 'N':\n return next && next(this.value);\n case 'E':\n return error && error(this.error);\n case 'C':\n return complete && complete();\n }\n };\n Notification.prototype.accept = function (nextOrObserver, error, complete) {\n if (nextOrObserver && typeof nextOrObserver.next === 'function') {\n return this.observe(nextOrObserver);\n }\n else {\n return this.do(nextOrObserver, error, complete);\n }\n };\n Notification.prototype.toObservable = function () {\n var kind = this.kind;\n switch (kind) {\n case 'N':\n return of(this.value);\n case 'E':\n return throwError(this.error);\n case 'C':\n return empty$1();\n }\n throw new Error('unexpected notification kind value');\n };\n Notification.createNext = function (value) {\n if (typeof value !== 'undefined') {\n return new Notification('N', value);\n }\n return Notification.undefinedValueNotification;\n };\n Notification.createError = function (err) {\n return new Notification('E', undefined, err);\n };\n Notification.createComplete = function () {\n return Notification.completeNotification;\n };\n Notification.completeNotification = new Notification('C');\n Notification.undefinedValueNotification = new Notification('N', undefined);\n return Notification;\n }());\n\n /** PURE_IMPORTS_START tslib,_Subscriber,_Notification PURE_IMPORTS_END */\n var ObserveOnSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(ObserveOnSubscriber, _super);\n function ObserveOnSubscriber(destination, scheduler, delay) {\n if (delay === void 0) {\n delay = 0;\n }\n var _this = _super.call(this, destination) || this;\n _this.scheduler = scheduler;\n _this.delay = delay;\n return _this;\n }\n ObserveOnSubscriber.dispatch = function (arg) {\n var notification = arg.notification, destination = arg.destination;\n notification.observe(destination);\n this.unsubscribe();\n };\n ObserveOnSubscriber.prototype.scheduleMessage = function (notification) {\n var destination = this.destination;\n destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));\n };\n ObserveOnSubscriber.prototype._next = function (value) {\n this.scheduleMessage(Notification.createNext(value));\n };\n ObserveOnSubscriber.prototype._error = function (err) {\n this.scheduleMessage(Notification.createError(err));\n this.unsubscribe();\n };\n ObserveOnSubscriber.prototype._complete = function () {\n this.scheduleMessage(Notification.createComplete());\n this.unsubscribe();\n };\n return ObserveOnSubscriber;\n }(Subscriber));\n var ObserveOnMessage = /*@__PURE__*/ (function () {\n function ObserveOnMessage(notification, destination) {\n this.notification = notification;\n this.destination = destination;\n }\n return ObserveOnMessage;\n }());\n\n /** PURE_IMPORTS_START tslib,_Subject,_scheduler_queue,_Subscription,_operators_observeOn,_util_ObjectUnsubscribedError,_SubjectSubscription PURE_IMPORTS_END */\n var ReplaySubject = /*@__PURE__*/ (function (_super) {\n __extends(ReplaySubject, _super);\n function ReplaySubject(bufferSize, windowTime, scheduler) {\n if (bufferSize === void 0) {\n bufferSize = Number.POSITIVE_INFINITY;\n }\n if (windowTime === void 0) {\n windowTime = Number.POSITIVE_INFINITY;\n }\n var _this = _super.call(this) || this;\n _this.scheduler = scheduler;\n _this._events = [];\n _this._infiniteTimeWindow = false;\n _this._bufferSize = bufferSize < 1 ? 1 : bufferSize;\n _this._windowTime = windowTime < 1 ? 1 : windowTime;\n if (windowTime === Number.POSITIVE_INFINITY) {\n _this._infiniteTimeWindow = true;\n _this.next = _this.nextInfiniteTimeWindow;\n }\n else {\n _this.next = _this.nextTimeWindow;\n }\n return _this;\n }\n ReplaySubject.prototype.nextInfiniteTimeWindow = function (value) {\n if (!this.isStopped) {\n var _events = this._events;\n _events.push(value);\n if (_events.length > this._bufferSize) {\n _events.shift();\n }\n }\n _super.prototype.next.call(this, value);\n };\n ReplaySubject.prototype.nextTimeWindow = function (value) {\n if (!this.isStopped) {\n this._events.push(new ReplayEvent(this._getNow(), value));\n this._trimBufferThenGetEvents();\n }\n _super.prototype.next.call(this, value);\n };\n ReplaySubject.prototype._subscribe = function (subscriber) {\n var _infiniteTimeWindow = this._infiniteTimeWindow;\n var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();\n var scheduler = this.scheduler;\n var len = _events.length;\n var subscription;\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n else if (this.isStopped || this.hasError) {\n subscription = Subscription.EMPTY;\n }\n else {\n this.observers.push(subscriber);\n subscription = new SubjectSubscription(this, subscriber);\n }\n if (scheduler) {\n subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));\n }\n if (_infiniteTimeWindow) {\n for (var i = 0; i < len && !subscriber.closed; i++) {\n subscriber.next(_events[i]);\n }\n }\n else {\n for (var i = 0; i < len && !subscriber.closed; i++) {\n subscriber.next(_events[i].value);\n }\n }\n if (this.hasError) {\n subscriber.error(this.thrownError);\n }\n else if (this.isStopped) {\n subscriber.complete();\n }\n return subscription;\n };\n ReplaySubject.prototype._getNow = function () {\n return (this.scheduler || queue).now();\n };\n ReplaySubject.prototype._trimBufferThenGetEvents = function () {\n var now = this._getNow();\n var _bufferSize = this._bufferSize;\n var _windowTime = this._windowTime;\n var _events = this._events;\n var eventsCount = _events.length;\n var spliceCount = 0;\n while (spliceCount < eventsCount) {\n if ((now - _events[spliceCount].time) < _windowTime) {\n break;\n }\n spliceCount++;\n }\n if (eventsCount > _bufferSize) {\n spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);\n }\n if (spliceCount > 0) {\n _events.splice(0, spliceCount);\n }\n return _events;\n };\n return ReplaySubject;\n }(Subject));\n var ReplayEvent = /*@__PURE__*/ (function () {\n function ReplayEvent(time, value) {\n this.time = time;\n this.value = value;\n }\n return ReplayEvent;\n }());\n\n /** PURE_IMPORTS_START _AsyncAction,_AsyncScheduler PURE_IMPORTS_END */\n var asyncScheduler = /*@__PURE__*/ new AsyncScheduler(AsyncAction);\n var async = asyncScheduler;\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var ArgumentOutOfRangeErrorImpl = /*@__PURE__*/ (function () {\n function ArgumentOutOfRangeErrorImpl() {\n Error.call(this);\n this.message = 'argument out of range';\n this.name = 'ArgumentOutOfRangeError';\n return this;\n }\n ArgumentOutOfRangeErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return ArgumentOutOfRangeErrorImpl;\n })();\n var ArgumentOutOfRangeError = ArgumentOutOfRangeErrorImpl;\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var EmptyErrorImpl = /*@__PURE__*/ (function () {\n function EmptyErrorImpl() {\n Error.call(this);\n this.message = 'no elements in sequence';\n this.name = 'EmptyError';\n return this;\n }\n EmptyErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);\n return EmptyErrorImpl;\n })();\n var EmptyError = EmptyErrorImpl;\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n function map(project, thisArg) {\n return function mapOperation(source) {\n if (typeof project !== 'function') {\n throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');\n }\n return source.lift(new MapOperator(project, thisArg));\n };\n }\n var MapOperator = /*@__PURE__*/ (function () {\n function MapOperator(project, thisArg) {\n this.project = project;\n this.thisArg = thisArg;\n }\n MapOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));\n };\n return MapOperator;\n }());\n var MapSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(MapSubscriber, _super);\n function MapSubscriber(destination, project, thisArg) {\n var _this = _super.call(this, destination) || this;\n _this.project = project;\n _this.count = 0;\n _this.thisArg = thisArg || _this;\n return _this;\n }\n MapSubscriber.prototype._next = function (value) {\n var result;\n try {\n result = this.project.call(this.thisArg, value, this.count++);\n }\n catch (err) {\n this.destination.error(err);\n return;\n }\n this.destination.next(result);\n };\n return MapSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n var OuterSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(OuterSubscriber, _super);\n function OuterSubscriber() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {\n this.destination.next(innerValue);\n };\n OuterSubscriber.prototype.notifyError = function (error, innerSub) {\n this.destination.error(error);\n };\n OuterSubscriber.prototype.notifyComplete = function (innerSub) {\n this.destination.complete();\n };\n return OuterSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n var InnerSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(InnerSubscriber, _super);\n function InnerSubscriber(parent, outerValue, outerIndex) {\n var _this = _super.call(this) || this;\n _this.parent = parent;\n _this.outerValue = outerValue;\n _this.outerIndex = outerIndex;\n _this.index = 0;\n return _this;\n }\n InnerSubscriber.prototype._next = function (value) {\n this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this);\n };\n InnerSubscriber.prototype._error = function (error) {\n this.parent.notifyError(error, this);\n this.unsubscribe();\n };\n InnerSubscriber.prototype._complete = function () {\n this.parent.notifyComplete(this);\n this.unsubscribe();\n };\n return InnerSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START _hostReportError PURE_IMPORTS_END */\n var subscribeToPromise = function (promise) {\n return function (subscriber) {\n promise.then(function (value) {\n if (!subscriber.closed) {\n subscriber.next(value);\n subscriber.complete();\n }\n }, function (err) { return subscriber.error(err); })\n .then(null, hostReportError);\n return subscriber;\n };\n };\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function getSymbolIterator() {\n if (typeof Symbol !== 'function' || !Symbol.iterator) {\n return '@@iterator';\n }\n return Symbol.iterator;\n }\n var iterator = /*@__PURE__*/ getSymbolIterator();\n\n /** PURE_IMPORTS_START _symbol_iterator PURE_IMPORTS_END */\n var subscribeToIterable = function (iterable) {\n return function (subscriber) {\n var iterator$1 = iterable[iterator]();\n do {\n var item = void 0;\n try {\n item = iterator$1.next();\n }\n catch (err) {\n subscriber.error(err);\n return subscriber;\n }\n if (item.done) {\n subscriber.complete();\n break;\n }\n subscriber.next(item.value);\n if (subscriber.closed) {\n break;\n }\n } while (true);\n if (typeof iterator$1.return === 'function') {\n subscriber.add(function () {\n if (iterator$1.return) {\n iterator$1.return();\n }\n });\n }\n return subscriber;\n };\n };\n\n /** PURE_IMPORTS_START _symbol_observable PURE_IMPORTS_END */\n var subscribeToObservable = function (obj) {\n return function (subscriber) {\n var obs = obj[observable]();\n if (typeof obs.subscribe !== 'function') {\n throw new TypeError('Provided object does not correctly implement Symbol.observable');\n }\n else {\n return obs.subscribe(subscriber);\n }\n };\n };\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });\n\n /** PURE_IMPORTS_START PURE_IMPORTS_END */\n function isPromise(value) {\n return !!value && typeof value.subscribe !== 'function' && typeof value.then === 'function';\n }\n\n /** PURE_IMPORTS_START _subscribeToArray,_subscribeToPromise,_subscribeToIterable,_subscribeToObservable,_isArrayLike,_isPromise,_isObject,_symbol_iterator,_symbol_observable PURE_IMPORTS_END */\n var subscribeTo = function (result) {\n if (!!result && typeof result[observable] === 'function') {\n return subscribeToObservable(result);\n }\n else if (isArrayLike(result)) {\n return subscribeToArray(result);\n }\n else if (isPromise(result)) {\n return subscribeToPromise(result);\n }\n else if (!!result && typeof result[iterator] === 'function') {\n return subscribeToIterable(result);\n }\n else {\n var value = isObject(result) ? 'an invalid object' : \"'\" + result + \"'\";\n var msg = \"You provided \" + value + \" where a stream was expected.\"\n + ' You can provide an Observable, Promise, Array, or Iterable.';\n throw new TypeError(msg);\n }\n };\n\n /** PURE_IMPORTS_START _InnerSubscriber,_subscribeTo,_Observable PURE_IMPORTS_END */\n function subscribeToResult(outerSubscriber, result, outerValue, outerIndex, innerSubscriber) {\n if (innerSubscriber === void 0) {\n innerSubscriber = new InnerSubscriber(outerSubscriber, outerValue, outerIndex);\n }\n if (innerSubscriber.closed) {\n return undefined;\n }\n if (result instanceof Observable) {\n return result.subscribe(innerSubscriber);\n }\n return subscribeTo(result)(innerSubscriber);\n }\n\n /** PURE_IMPORTS_START tslib,_util_isScheduler,_util_isArray,_OuterSubscriber,_util_subscribeToResult,_fromArray PURE_IMPORTS_END */\n var NONE = {};\n function combineLatest() {\n var observables = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n observables[_i] = arguments[_i];\n }\n var resultSelector = undefined;\n var scheduler = undefined;\n if (isScheduler(observables[observables.length - 1])) {\n scheduler = observables.pop();\n }\n if (typeof observables[observables.length - 1] === 'function') {\n resultSelector = observables.pop();\n }\n if (observables.length === 1 && isArray(observables[0])) {\n observables = observables[0];\n }\n return fromArray(observables, scheduler).lift(new CombineLatestOperator(resultSelector));\n }\n var CombineLatestOperator = /*@__PURE__*/ (function () {\n function CombineLatestOperator(resultSelector) {\n this.resultSelector = resultSelector;\n }\n CombineLatestOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new CombineLatestSubscriber(subscriber, this.resultSelector));\n };\n return CombineLatestOperator;\n }());\n var CombineLatestSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(CombineLatestSubscriber, _super);\n function CombineLatestSubscriber(destination, resultSelector) {\n var _this = _super.call(this, destination) || this;\n _this.resultSelector = resultSelector;\n _this.active = 0;\n _this.values = [];\n _this.observables = [];\n return _this;\n }\n CombineLatestSubscriber.prototype._next = function (observable) {\n this.values.push(NONE);\n this.observables.push(observable);\n };\n CombineLatestSubscriber.prototype._complete = function () {\n var observables = this.observables;\n var len = observables.length;\n if (len === 0) {\n this.destination.complete();\n }\n else {\n this.active = len;\n this.toRespond = len;\n for (var i = 0; i < len; i++) {\n var observable = observables[i];\n this.add(subscribeToResult(this, observable, undefined, i));\n }\n }\n };\n CombineLatestSubscriber.prototype.notifyComplete = function (unused) {\n if ((this.active -= 1) === 0) {\n this.destination.complete();\n }\n };\n CombineLatestSubscriber.prototype.notifyNext = function (_outerValue, innerValue, outerIndex) {\n var values = this.values;\n var oldVal = values[outerIndex];\n var toRespond = !this.toRespond\n ? 0\n : oldVal === NONE ? --this.toRespond : this.toRespond;\n values[outerIndex] = innerValue;\n if (toRespond === 0) {\n if (this.resultSelector) {\n this._tryResultSelector(values);\n }\n else {\n this.destination.next(values.slice());\n }\n }\n };\n CombineLatestSubscriber.prototype._tryResultSelector = function (values) {\n var result;\n try {\n result = this.resultSelector.apply(this, values);\n }\n catch (err) {\n this.destination.error(err);\n return;\n }\n this.destination.next(result);\n };\n return CombineLatestSubscriber;\n }(OuterSubscriber));\n\n /** PURE_IMPORTS_START _Observable,_Subscription,_symbol_observable PURE_IMPORTS_END */\n function scheduleObservable(input, scheduler) {\n return new Observable(function (subscriber) {\n var sub = new Subscription();\n sub.add(scheduler.schedule(function () {\n var observable$1 = input[observable]();\n sub.add(observable$1.subscribe({\n next: function (value) { sub.add(scheduler.schedule(function () { return subscriber.next(value); })); },\n error: function (err) { sub.add(scheduler.schedule(function () { return subscriber.error(err); })); },\n complete: function () { sub.add(scheduler.schedule(function () { return subscriber.complete(); })); },\n }));\n }));\n return sub;\n });\n }\n\n /** PURE_IMPORTS_START _Observable,_Subscription PURE_IMPORTS_END */\n function schedulePromise(input, scheduler) {\n return new Observable(function (subscriber) {\n var sub = new Subscription();\n sub.add(scheduler.schedule(function () {\n return input.then(function (value) {\n sub.add(scheduler.schedule(function () {\n subscriber.next(value);\n sub.add(scheduler.schedule(function () { return subscriber.complete(); }));\n }));\n }, function (err) {\n sub.add(scheduler.schedule(function () { return subscriber.error(err); }));\n });\n }));\n return sub;\n });\n }\n\n /** PURE_IMPORTS_START _Observable,_Subscription,_symbol_iterator PURE_IMPORTS_END */\n function scheduleIterable(input, scheduler) {\n if (!input) {\n throw new Error('Iterable cannot be null');\n }\n return new Observable(function (subscriber) {\n var sub = new Subscription();\n var iterator$1;\n sub.add(function () {\n if (iterator$1 && typeof iterator$1.return === 'function') {\n iterator$1.return();\n }\n });\n sub.add(scheduler.schedule(function () {\n iterator$1 = input[iterator]();\n sub.add(scheduler.schedule(function () {\n if (subscriber.closed) {\n return;\n }\n var value;\n var done;\n try {\n var result = iterator$1.next();\n value = result.value;\n done = result.done;\n }\n catch (err) {\n subscriber.error(err);\n return;\n }\n if (done) {\n subscriber.complete();\n }\n else {\n subscriber.next(value);\n this.schedule();\n }\n }));\n }));\n return sub;\n });\n }\n\n /** PURE_IMPORTS_START _symbol_observable PURE_IMPORTS_END */\n function isInteropObservable(input) {\n return input && typeof input[observable] === 'function';\n }\n\n /** PURE_IMPORTS_START _symbol_iterator PURE_IMPORTS_END */\n function isIterable(input) {\n return input && typeof input[iterator] === 'function';\n }\n\n /** PURE_IMPORTS_START _scheduleObservable,_schedulePromise,_scheduleArray,_scheduleIterable,_util_isInteropObservable,_util_isPromise,_util_isArrayLike,_util_isIterable PURE_IMPORTS_END */\n function scheduled(input, scheduler) {\n if (input != null) {\n if (isInteropObservable(input)) {\n return scheduleObservable(input, scheduler);\n }\n else if (isPromise(input)) {\n return schedulePromise(input, scheduler);\n }\n else if (isArrayLike(input)) {\n return scheduleArray(input, scheduler);\n }\n else if (isIterable(input) || typeof input === 'string') {\n return scheduleIterable(input, scheduler);\n }\n }\n throw new TypeError((input !== null && typeof input || input) + ' is not observable');\n }\n\n /** PURE_IMPORTS_START _Observable,_util_subscribeTo,_scheduled_scheduled PURE_IMPORTS_END */\n function from(input, scheduler) {\n if (!scheduler) {\n if (input instanceof Observable) {\n return input;\n }\n return new Observable(subscribeTo(input));\n }\n else {\n return scheduled(input, scheduler);\n }\n }\n\n /** PURE_IMPORTS_START tslib,_Subscriber,_Observable,_util_subscribeTo PURE_IMPORTS_END */\n var SimpleInnerSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SimpleInnerSubscriber, _super);\n function SimpleInnerSubscriber(parent) {\n var _this = _super.call(this) || this;\n _this.parent = parent;\n return _this;\n }\n SimpleInnerSubscriber.prototype._next = function (value) {\n this.parent.notifyNext(value);\n };\n SimpleInnerSubscriber.prototype._error = function (error) {\n this.parent.notifyError(error);\n this.unsubscribe();\n };\n SimpleInnerSubscriber.prototype._complete = function () {\n this.parent.notifyComplete();\n this.unsubscribe();\n };\n return SimpleInnerSubscriber;\n }(Subscriber));\n var SimpleOuterSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SimpleOuterSubscriber, _super);\n function SimpleOuterSubscriber() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n SimpleOuterSubscriber.prototype.notifyNext = function (innerValue) {\n this.destination.next(innerValue);\n };\n SimpleOuterSubscriber.prototype.notifyError = function (err) {\n this.destination.error(err);\n };\n SimpleOuterSubscriber.prototype.notifyComplete = function () {\n this.destination.complete();\n };\n return SimpleOuterSubscriber;\n }(Subscriber));\n function innerSubscribe(result, innerSubscriber) {\n if (innerSubscriber.closed) {\n return undefined;\n }\n if (result instanceof Observable) {\n return result.subscribe(innerSubscriber);\n }\n var subscription;\n try {\n subscription = subscribeTo(result)(innerSubscriber);\n }\n catch (error) {\n innerSubscriber.error(error);\n }\n return subscription;\n }\n\n /** PURE_IMPORTS_START tslib,_map,_observable_from,_innerSubscribe PURE_IMPORTS_END */\n function mergeMap(project, resultSelector, concurrent) {\n if (concurrent === void 0) {\n concurrent = Number.POSITIVE_INFINITY;\n }\n if (typeof resultSelector === 'function') {\n return function (source) { return source.pipe(mergeMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); }, concurrent)); };\n }\n else if (typeof resultSelector === 'number') {\n concurrent = resultSelector;\n }\n return function (source) { return source.lift(new MergeMapOperator(project, concurrent)); };\n }\n var MergeMapOperator = /*@__PURE__*/ (function () {\n function MergeMapOperator(project, concurrent) {\n if (concurrent === void 0) {\n concurrent = Number.POSITIVE_INFINITY;\n }\n this.project = project;\n this.concurrent = concurrent;\n }\n MergeMapOperator.prototype.call = function (observer, source) {\n return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent));\n };\n return MergeMapOperator;\n }());\n var MergeMapSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(MergeMapSubscriber, _super);\n function MergeMapSubscriber(destination, project, concurrent) {\n if (concurrent === void 0) {\n concurrent = Number.POSITIVE_INFINITY;\n }\n var _this = _super.call(this, destination) || this;\n _this.project = project;\n _this.concurrent = concurrent;\n _this.hasCompleted = false;\n _this.buffer = [];\n _this.active = 0;\n _this.index = 0;\n return _this;\n }\n MergeMapSubscriber.prototype._next = function (value) {\n if (this.active < this.concurrent) {\n this._tryNext(value);\n }\n else {\n this.buffer.push(value);\n }\n };\n MergeMapSubscriber.prototype._tryNext = function (value) {\n var result;\n var index = this.index++;\n try {\n result = this.project(value, index);\n }\n catch (err) {\n this.destination.error(err);\n return;\n }\n this.active++;\n this._innerSub(result);\n };\n MergeMapSubscriber.prototype._innerSub = function (ish) {\n var innerSubscriber = new SimpleInnerSubscriber(this);\n var destination = this.destination;\n destination.add(innerSubscriber);\n var innerSubscription = innerSubscribe(ish, innerSubscriber);\n if (innerSubscription !== innerSubscriber) {\n destination.add(innerSubscription);\n }\n };\n MergeMapSubscriber.prototype._complete = function () {\n this.hasCompleted = true;\n if (this.active === 0 && this.buffer.length === 0) {\n this.destination.complete();\n }\n this.unsubscribe();\n };\n MergeMapSubscriber.prototype.notifyNext = function (innerValue) {\n this.destination.next(innerValue);\n };\n MergeMapSubscriber.prototype.notifyComplete = function () {\n var buffer = this.buffer;\n this.active--;\n if (buffer.length > 0) {\n this._next(buffer.shift());\n }\n else if (this.active === 0 && this.hasCompleted) {\n this.destination.complete();\n }\n };\n return MergeMapSubscriber;\n }(SimpleOuterSubscriber));\n\n /** PURE_IMPORTS_START _mergeMap,_util_identity PURE_IMPORTS_END */\n function mergeAll(concurrent) {\n if (concurrent === void 0) {\n concurrent = Number.POSITIVE_INFINITY;\n }\n return mergeMap(identity, concurrent);\n }\n\n /** PURE_IMPORTS_START _mergeAll PURE_IMPORTS_END */\n function concatAll() {\n return mergeAll(1);\n }\n\n /** PURE_IMPORTS_START _of,_operators_concatAll PURE_IMPORTS_END */\n function concat() {\n var observables = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n observables[_i] = arguments[_i];\n }\n return concatAll()(of.apply(void 0, observables));\n }\n\n /** PURE_IMPORTS_START _Observable,_util_isScheduler,_operators_mergeAll,_fromArray PURE_IMPORTS_END */\n function merge() {\n var observables = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n observables[_i] = arguments[_i];\n }\n var concurrent = Number.POSITIVE_INFINITY;\n var scheduler = null;\n var last = observables[observables.length - 1];\n if (isScheduler(last)) {\n scheduler = observables.pop();\n if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {\n concurrent = observables.pop();\n }\n }\n else if (typeof last === 'number') {\n concurrent = observables.pop();\n }\n if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {\n return observables[0];\n }\n return mergeAll(concurrent)(fromArray(observables, scheduler));\n }\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n function filter(predicate, thisArg) {\n return function filterOperatorFunction(source) {\n return source.lift(new FilterOperator(predicate, thisArg));\n };\n }\n var FilterOperator = /*@__PURE__*/ (function () {\n function FilterOperator(predicate, thisArg) {\n this.predicate = predicate;\n this.thisArg = thisArg;\n }\n FilterOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));\n };\n return FilterOperator;\n }());\n var FilterSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(FilterSubscriber, _super);\n function FilterSubscriber(destination, predicate, thisArg) {\n var _this = _super.call(this, destination) || this;\n _this.predicate = predicate;\n _this.thisArg = thisArg;\n _this.count = 0;\n return _this;\n }\n FilterSubscriber.prototype._next = function (value) {\n var result;\n try {\n result = this.predicate.call(this.thisArg, value, this.count++);\n }\n catch (err) {\n this.destination.error(err);\n return;\n }\n if (result) {\n this.destination.next(value);\n }\n };\n return FilterSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_Subscriber,_scheduler_async PURE_IMPORTS_END */\n function debounceTime(dueTime, scheduler) {\n if (scheduler === void 0) {\n scheduler = async;\n }\n return function (source) { return source.lift(new DebounceTimeOperator(dueTime, scheduler)); };\n }\n var DebounceTimeOperator = /*@__PURE__*/ (function () {\n function DebounceTimeOperator(dueTime, scheduler) {\n this.dueTime = dueTime;\n this.scheduler = scheduler;\n }\n DebounceTimeOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));\n };\n return DebounceTimeOperator;\n }());\n var DebounceTimeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(DebounceTimeSubscriber, _super);\n function DebounceTimeSubscriber(destination, dueTime, scheduler) {\n var _this = _super.call(this, destination) || this;\n _this.dueTime = dueTime;\n _this.scheduler = scheduler;\n _this.debouncedSubscription = null;\n _this.lastValue = null;\n _this.hasValue = false;\n return _this;\n }\n DebounceTimeSubscriber.prototype._next = function (value) {\n this.clearDebounce();\n this.lastValue = value;\n this.hasValue = true;\n this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));\n };\n DebounceTimeSubscriber.prototype._complete = function () {\n this.debouncedNext();\n this.destination.complete();\n };\n DebounceTimeSubscriber.prototype.debouncedNext = function () {\n this.clearDebounce();\n if (this.hasValue) {\n var lastValue = this.lastValue;\n this.lastValue = null;\n this.hasValue = false;\n this.destination.next(lastValue);\n }\n };\n DebounceTimeSubscriber.prototype.clearDebounce = function () {\n var debouncedSubscription = this.debouncedSubscription;\n if (debouncedSubscription !== null) {\n this.remove(debouncedSubscription);\n debouncedSubscription.unsubscribe();\n this.debouncedSubscription = null;\n }\n };\n return DebounceTimeSubscriber;\n }(Subscriber));\n function dispatchNext(subscriber) {\n subscriber.debouncedNext();\n }\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n function defaultIfEmpty(defaultValue) {\n if (defaultValue === void 0) {\n defaultValue = null;\n }\n return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };\n }\n var DefaultIfEmptyOperator = /*@__PURE__*/ (function () {\n function DefaultIfEmptyOperator(defaultValue) {\n this.defaultValue = defaultValue;\n }\n DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));\n };\n return DefaultIfEmptyOperator;\n }());\n var DefaultIfEmptySubscriber = /*@__PURE__*/ (function (_super) {\n __extends(DefaultIfEmptySubscriber, _super);\n function DefaultIfEmptySubscriber(destination, defaultValue) {\n var _this = _super.call(this, destination) || this;\n _this.defaultValue = defaultValue;\n _this.isEmpty = true;\n return _this;\n }\n DefaultIfEmptySubscriber.prototype._next = function (value) {\n this.isEmpty = false;\n this.destination.next(value);\n };\n DefaultIfEmptySubscriber.prototype._complete = function () {\n if (this.isEmpty) {\n this.destination.next(this.defaultValue);\n }\n this.destination.complete();\n };\n return DefaultIfEmptySubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n function distinctUntilChanged(compare, keySelector) {\n return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };\n }\n var DistinctUntilChangedOperator = /*@__PURE__*/ (function () {\n function DistinctUntilChangedOperator(compare, keySelector) {\n this.compare = compare;\n this.keySelector = keySelector;\n }\n DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));\n };\n return DistinctUntilChangedOperator;\n }());\n var DistinctUntilChangedSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(DistinctUntilChangedSubscriber, _super);\n function DistinctUntilChangedSubscriber(destination, compare, keySelector) {\n var _this = _super.call(this, destination) || this;\n _this.keySelector = keySelector;\n _this.hasKey = false;\n if (typeof compare === 'function') {\n _this.compare = compare;\n }\n return _this;\n }\n DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {\n return x === y;\n };\n DistinctUntilChangedSubscriber.prototype._next = function (value) {\n var key;\n try {\n var keySelector = this.keySelector;\n key = keySelector ? keySelector(value) : value;\n }\n catch (err) {\n return this.destination.error(err);\n }\n var result = false;\n if (this.hasKey) {\n try {\n var compare = this.compare;\n result = compare(this.key, key);\n }\n catch (err) {\n return this.destination.error(err);\n }\n }\n else {\n this.hasKey = true;\n }\n if (!result) {\n this.key = key;\n this.destination.next(value);\n }\n };\n return DistinctUntilChangedSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_util_EmptyError,_Subscriber PURE_IMPORTS_END */\n function throwIfEmpty(errorFactory) {\n if (errorFactory === void 0) {\n errorFactory = defaultErrorFactory;\n }\n return function (source) {\n return source.lift(new ThrowIfEmptyOperator(errorFactory));\n };\n }\n var ThrowIfEmptyOperator = /*@__PURE__*/ (function () {\n function ThrowIfEmptyOperator(errorFactory) {\n this.errorFactory = errorFactory;\n }\n ThrowIfEmptyOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));\n };\n return ThrowIfEmptyOperator;\n }());\n var ThrowIfEmptySubscriber = /*@__PURE__*/ (function (_super) {\n __extends(ThrowIfEmptySubscriber, _super);\n function ThrowIfEmptySubscriber(destination, errorFactory) {\n var _this = _super.call(this, destination) || this;\n _this.errorFactory = errorFactory;\n _this.hasValue = false;\n return _this;\n }\n ThrowIfEmptySubscriber.prototype._next = function (value) {\n this.hasValue = true;\n this.destination.next(value);\n };\n ThrowIfEmptySubscriber.prototype._complete = function () {\n if (!this.hasValue) {\n var err = void 0;\n try {\n err = this.errorFactory();\n }\n catch (e) {\n err = e;\n }\n this.destination.error(err);\n }\n else {\n return this.destination.complete();\n }\n };\n return ThrowIfEmptySubscriber;\n }(Subscriber));\n function defaultErrorFactory() {\n return new EmptyError();\n }\n\n /** PURE_IMPORTS_START tslib,_Subscriber,_util_ArgumentOutOfRangeError,_observable_empty PURE_IMPORTS_END */\n function take(count) {\n return function (source) {\n if (count === 0) {\n return empty$1();\n }\n else {\n return source.lift(new TakeOperator(count));\n }\n };\n }\n var TakeOperator = /*@__PURE__*/ (function () {\n function TakeOperator(total) {\n this.total = total;\n if (this.total < 0) {\n throw new ArgumentOutOfRangeError;\n }\n }\n TakeOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new TakeSubscriber(subscriber, this.total));\n };\n return TakeOperator;\n }());\n var TakeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(TakeSubscriber, _super);\n function TakeSubscriber(destination, total) {\n var _this = _super.call(this, destination) || this;\n _this.total = total;\n _this.count = 0;\n return _this;\n }\n TakeSubscriber.prototype._next = function (value) {\n var total = this.total;\n var count = ++this.count;\n if (count <= total) {\n this.destination.next(value);\n if (count === total) {\n this.destination.complete();\n this.unsubscribe();\n }\n }\n };\n return TakeSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_Subscriber,_Subscription PURE_IMPORTS_END */\n function finalize(callback) {\n return function (source) { return source.lift(new FinallyOperator(callback)); };\n }\n var FinallyOperator = /*@__PURE__*/ (function () {\n function FinallyOperator(callback) {\n this.callback = callback;\n }\n FinallyOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new FinallySubscriber(subscriber, this.callback));\n };\n return FinallyOperator;\n }());\n var FinallySubscriber = /*@__PURE__*/ (function (_super) {\n __extends(FinallySubscriber, _super);\n function FinallySubscriber(destination, callback) {\n var _this = _super.call(this, destination) || this;\n _this.add(new Subscription(callback));\n return _this;\n }\n return FinallySubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START _util_EmptyError,_filter,_take,_defaultIfEmpty,_throwIfEmpty,_util_identity PURE_IMPORTS_END */\n function first(predicate, defaultValue) {\n var hasDefaultValue = arguments.length >= 2;\n return function (source) { return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); })); };\n }\n\n /** PURE_IMPORTS_START _observable_ConnectableObservable PURE_IMPORTS_END */\n function multicast(subjectOrSubjectFactory, selector) {\n return function multicastOperatorFunction(source) {\n var subjectFactory;\n if (typeof subjectOrSubjectFactory === 'function') {\n subjectFactory = subjectOrSubjectFactory;\n }\n else {\n subjectFactory = function subjectFactory() {\n return subjectOrSubjectFactory;\n };\n }\n if (typeof selector === 'function') {\n return source.lift(new MulticastOperator(subjectFactory, selector));\n }\n var connectable = Object.create(source, connectableObservableDescriptor);\n connectable.source = source;\n connectable.subjectFactory = subjectFactory;\n return connectable;\n };\n }\n var MulticastOperator = /*@__PURE__*/ (function () {\n function MulticastOperator(subjectFactory, selector) {\n this.subjectFactory = subjectFactory;\n this.selector = selector;\n }\n MulticastOperator.prototype.call = function (subscriber, source) {\n var selector = this.selector;\n var subject = this.subjectFactory();\n var subscription = selector(subject).subscribe(subscriber);\n subscription.add(source.subscribe(subject));\n return subscription;\n };\n return MulticastOperator;\n }());\n\n /** PURE_IMPORTS_START _multicast,_refCount,_Subject PURE_IMPORTS_END */\n function shareSubjectFactory() {\n return new Subject();\n }\n function share() {\n return function (source) { return refCount()(multicast(shareSubjectFactory)(source)); };\n }\n\n /** PURE_IMPORTS_START _ReplaySubject PURE_IMPORTS_END */\n function shareReplay(configOrBufferSize, windowTime, scheduler) {\n var config;\n if (configOrBufferSize && typeof configOrBufferSize === 'object') {\n config = configOrBufferSize;\n }\n else {\n config = {\n bufferSize: configOrBufferSize,\n windowTime: windowTime,\n refCount: false,\n scheduler: scheduler,\n };\n }\n return function (source) { return source.lift(shareReplayOperator(config)); };\n }\n function shareReplayOperator(_a) {\n var _b = _a.bufferSize, bufferSize = _b === void 0 ? Number.POSITIVE_INFINITY : _b, _c = _a.windowTime, windowTime = _c === void 0 ? Number.POSITIVE_INFINITY : _c, useRefCount = _a.refCount, scheduler = _a.scheduler;\n var subject;\n var refCount = 0;\n var subscription;\n var hasError = false;\n var isComplete = false;\n return function shareReplayOperation(source) {\n refCount++;\n var innerSub;\n if (!subject || hasError) {\n hasError = false;\n subject = new ReplaySubject(bufferSize, windowTime, scheduler);\n innerSub = subject.subscribe(this);\n subscription = source.subscribe({\n next: function (value) {\n subject.next(value);\n },\n error: function (err) {\n hasError = true;\n subject.error(err);\n },\n complete: function () {\n isComplete = true;\n subscription = undefined;\n subject.complete();\n },\n });\n if (isComplete) {\n subscription = undefined;\n }\n }\n else {\n innerSub = subject.subscribe(this);\n }\n this.add(function () {\n refCount--;\n innerSub.unsubscribe();\n innerSub = undefined;\n if (subscription && !isComplete && useRefCount && refCount === 0) {\n subscription.unsubscribe();\n subscription = undefined;\n subject = undefined;\n }\n });\n };\n }\n\n /** PURE_IMPORTS_START _observable_concat,_util_isScheduler PURE_IMPORTS_END */\n function startWith() {\n var array = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n array[_i] = arguments[_i];\n }\n var scheduler = array[array.length - 1];\n if (isScheduler(scheduler)) {\n array.pop();\n return function (source) { return concat(array, source, scheduler); };\n }\n else {\n return function (source) { return concat(array, source); };\n }\n }\n\n /** PURE_IMPORTS_START tslib,_map,_observable_from,_innerSubscribe PURE_IMPORTS_END */\n function switchMap(project, resultSelector) {\n if (typeof resultSelector === 'function') {\n return function (source) { return source.pipe(switchMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };\n }\n return function (source) { return source.lift(new SwitchMapOperator(project)); };\n }\n var SwitchMapOperator = /*@__PURE__*/ (function () {\n function SwitchMapOperator(project) {\n this.project = project;\n }\n SwitchMapOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));\n };\n return SwitchMapOperator;\n }());\n var SwitchMapSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(SwitchMapSubscriber, _super);\n function SwitchMapSubscriber(destination, project) {\n var _this = _super.call(this, destination) || this;\n _this.project = project;\n _this.index = 0;\n return _this;\n }\n SwitchMapSubscriber.prototype._next = function (value) {\n var result;\n var index = this.index++;\n try {\n result = this.project(value, index);\n }\n catch (error) {\n this.destination.error(error);\n return;\n }\n this._innerSub(result);\n };\n SwitchMapSubscriber.prototype._innerSub = function (result) {\n var innerSubscription = this.innerSubscription;\n if (innerSubscription) {\n innerSubscription.unsubscribe();\n }\n var innerSubscriber = new SimpleInnerSubscriber(this);\n var destination = this.destination;\n destination.add(innerSubscriber);\n this.innerSubscription = innerSubscribe(result, innerSubscriber);\n if (this.innerSubscription !== innerSubscriber) {\n destination.add(this.innerSubscription);\n }\n };\n SwitchMapSubscriber.prototype._complete = function () {\n var innerSubscription = this.innerSubscription;\n if (!innerSubscription || innerSubscription.closed) {\n _super.prototype._complete.call(this);\n }\n this.unsubscribe();\n };\n SwitchMapSubscriber.prototype._unsubscribe = function () {\n this.innerSubscription = undefined;\n };\n SwitchMapSubscriber.prototype.notifyComplete = function () {\n this.innerSubscription = undefined;\n if (this.isStopped) {\n _super.prototype._complete.call(this);\n }\n };\n SwitchMapSubscriber.prototype.notifyNext = function (innerValue) {\n this.destination.next(innerValue);\n };\n return SwitchMapSubscriber;\n }(SimpleOuterSubscriber));\n\n /** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */\n function takeUntil(notifier) {\n return function (source) { return source.lift(new TakeUntilOperator(notifier)); };\n }\n var TakeUntilOperator = /*@__PURE__*/ (function () {\n function TakeUntilOperator(notifier) {\n this.notifier = notifier;\n }\n TakeUntilOperator.prototype.call = function (subscriber, source) {\n var takeUntilSubscriber = new TakeUntilSubscriber(subscriber);\n var notifierSubscription = innerSubscribe(this.notifier, new SimpleInnerSubscriber(takeUntilSubscriber));\n if (notifierSubscription && !takeUntilSubscriber.seenValue) {\n takeUntilSubscriber.add(notifierSubscription);\n return source.subscribe(takeUntilSubscriber);\n }\n return takeUntilSubscriber;\n };\n return TakeUntilOperator;\n }());\n var TakeUntilSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(TakeUntilSubscriber, _super);\n function TakeUntilSubscriber(destination) {\n var _this = _super.call(this, destination) || this;\n _this.seenValue = false;\n return _this;\n }\n TakeUntilSubscriber.prototype.notifyNext = function () {\n this.seenValue = true;\n this.complete();\n };\n TakeUntilSubscriber.prototype.notifyComplete = function () {\n };\n return TakeUntilSubscriber;\n }(SimpleOuterSubscriber));\n\n /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */\n function takeWhile(predicate, inclusive) {\n if (inclusive === void 0) {\n inclusive = false;\n }\n return function (source) {\n return source.lift(new TakeWhileOperator(predicate, inclusive));\n };\n }\n var TakeWhileOperator = /*@__PURE__*/ (function () {\n function TakeWhileOperator(predicate, inclusive) {\n this.predicate = predicate;\n this.inclusive = inclusive;\n }\n TakeWhileOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));\n };\n return TakeWhileOperator;\n }());\n var TakeWhileSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(TakeWhileSubscriber, _super);\n function TakeWhileSubscriber(destination, predicate, inclusive) {\n var _this = _super.call(this, destination) || this;\n _this.predicate = predicate;\n _this.inclusive = inclusive;\n _this.index = 0;\n return _this;\n }\n TakeWhileSubscriber.prototype._next = function (value) {\n var destination = this.destination;\n var result;\n try {\n result = this.predicate(value, this.index++);\n }\n catch (err) {\n destination.error(err);\n return;\n }\n this.nextOrComplete(value, result);\n };\n TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {\n var destination = this.destination;\n if (Boolean(predicateResult)) {\n destination.next(value);\n }\n else {\n if (this.inclusive) {\n destination.next(value);\n }\n destination.complete();\n }\n };\n return TakeWhileSubscriber;\n }(Subscriber));\n\n /** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */\n var defaultThrottleConfig = {\n leading: true,\n trailing: false\n };\n\n /** PURE_IMPORTS_START tslib,_Subscriber,_scheduler_async,_throttle PURE_IMPORTS_END */\n function throttleTime(duration, scheduler, config) {\n if (scheduler === void 0) {\n scheduler = async;\n }\n if (config === void 0) {\n config = defaultThrottleConfig;\n }\n return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };\n }\n var ThrottleTimeOperator = /*@__PURE__*/ (function () {\n function ThrottleTimeOperator(duration, scheduler, leading, trailing) {\n this.duration = duration;\n this.scheduler = scheduler;\n this.leading = leading;\n this.trailing = trailing;\n }\n ThrottleTimeOperator.prototype.call = function (subscriber, source) {\n return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));\n };\n return ThrottleTimeOperator;\n }());\n var ThrottleTimeSubscriber = /*@__PURE__*/ (function (_super) {\n __extends(ThrottleTimeSubscriber, _super);\n function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {\n var _this = _super.call(this, destination) || this;\n _this.duration = duration;\n _this.scheduler = scheduler;\n _this.leading = leading;\n _this.trailing = trailing;\n _this._hasTrailingValue = false;\n _this._trailingValue = null;\n return _this;\n }\n ThrottleTimeSubscriber.prototype._next = function (value) {\n if (this.throttled) {\n if (this.trailing) {\n this._trailingValue = value;\n this._hasTrailingValue = true;\n }\n }\n else {\n this.add(this.throttled = this.scheduler.schedule(dispatchNext$1, this.duration, { subscriber: this }));\n if (this.leading) {\n this.destination.next(value);\n }\n else if (this.trailing) {\n this._trailingValue = value;\n this._hasTrailingValue = true;\n }\n }\n };\n ThrottleTimeSubscriber.prototype._complete = function () {\n if (this._hasTrailingValue) {\n this.destination.next(this._trailingValue);\n this.destination.complete();\n }\n else {\n this.destination.complete();\n }\n };\n ThrottleTimeSubscriber.prototype.clearThrottle = function () {\n var throttled = this.throttled;\n if (throttled) {\n if (this.trailing && this._hasTrailingValue) {\n this.destination.next(this._trailingValue);\n this._trailingValue = null;\n this._hasTrailingValue = false;\n }\n throttled.unsubscribe();\n this.remove(throttled);\n this.throttled = null;\n }\n };\n return ThrottleTimeSubscriber;\n }(Subscriber));\n function dispatchNext$1(arg) {\n var subscriber = arg.subscriber;\n subscriber.clearThrottle();\n }\n\n function isDefined(item) {\n return typeof item !== 'undefined' && item !== null;\n }\n function isObject$1(o) {\n return typeof o === 'object' && o != null;\n }\n /** Type guard for filtering out undefined */\n function omitUndefinedElements(item) {\n return item !== null && typeof item !== 'undefined';\n }\n const changesProcessed = new Subject();\n const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n function isGuid(str) {\n return guidRegex.test(str);\n }\n const absoluteUrlRegex = /^(?:[a-z]+:)?\\/\\//i;\n function isAbsoluteUrl(url) {\n return absoluteUrlRegex.test(url);\n }\n function appendOrIncrementNumber(name) {\n const lastNumber = name.replace(/\\D*(\\d*)\\s*$/, '$1');\n if (lastNumber === '') {\n return name + ' 2';\n }\n else {\n return name.replace(/\\d*\\s*$/, (parseInt(lastNumber, 10) + 1).toString());\n }\n }\n /** UUID generation based on: https://github.com/jchook/uuid-random/blob/master/index.js */\n class UUID {\n static initialize() {\n // Pre-calculate toString(16) for speed\n for (UUID.i = 0; UUID.i < 256; UUID.i++) {\n UUID.hexBytes[UUID.i] = (UUID.i + 0x100).toString(16).substr(1);\n }\n }\n // Buffer some random bytes for speed\n static randomBytesBuffered(n) {\n if (!UUID.buf || UUID.bufIdx + n > UUID.bufferSize) {\n UUID.bufIdx = 0;\n UUID.buf = crypto.getRandomValues(new Uint8Array(UUID.bufferSize));\n }\n return UUID.buf.slice(UUID.bufIdx, (UUID.bufIdx += n));\n }\n // uuid.bin\n static uuidBin() {\n const b = UUID.randomBytesBuffered(16);\n b[6] = (b[6] & 0x0f) | 0x40;\n b[8] = (b[8] & 0x3f) | 0x80;\n return b;\n }\n static generate() {\n const b = UUID.uuidBin();\n return (UUID.hexBytes[b[0]] +\n UUID.hexBytes[b[1]] +\n UUID.hexBytes[b[2]] +\n UUID.hexBytes[b[3]] +\n '-' +\n UUID.hexBytes[b[4]] +\n UUID.hexBytes[b[5]] +\n '-' +\n UUID.hexBytes[b[6]] +\n UUID.hexBytes[b[7]] +\n '-' +\n UUID.hexBytes[b[8]] +\n UUID.hexBytes[b[9]] +\n '-' +\n UUID.hexBytes[b[10]] +\n UUID.hexBytes[b[11]] +\n UUID.hexBytes[b[12]] +\n UUID.hexBytes[b[13]] +\n UUID.hexBytes[b[14]] +\n UUID.hexBytes[b[15]]);\n }\n }\n UUID.bufIdx = 0;\n UUID.hexBytes = new Array();\n UUID.bufferSize = 4096;\n UUID.initialize();\n\n class SceneHistory {\n constructor() {\n this.active = false;\n this.changes = [];\n this.undoneChanges = [];\n this.ignoreChangesFromObjects = new Set();\n this.state = new BehaviorSubject([]);\n this.undoneState = new BehaviorSubject([]);\n }\n updateState() {\n return this.state.next(this.getMergedChanges(this.changes));\n }\n updateUndoneState() {\n return this.undoneState.next(this.getMergedChanges(this.undoneChanges));\n }\n getMergedChanges(changes) {\n return changes.map((c, index) => {\n const changePart = Array.from(c.change.values());\n return {\n description: c.description,\n index,\n nodes: changePart.map(node => node.node),\n // Return a set of properties to drop duplicate array elements\n properties: new Set(changePart.flatMap(node => node.properties.flatMap(property => property.name))).values(),\n };\n });\n }\n ignoreUntilStable(object) {\n if (this.ignoreChangesFromObjects.size === 0) {\n changesProcessed.pipe(take(1)).subscribe(() => {\n this.ignoreChangesFromObjects.clear();\n });\n }\n this.ignoreChangesFromObjects.add(object);\n }\n start() {\n this.active = true;\n }\n stop() {\n this.active = false;\n }\n /**\n * Adds a change to the history. If you added an open-ended change\n * @param description\n * @param processFunction\n * @param undoFunction\n */\n addChange(description, processFunction, undoFunction) {\n // if (this.openChange) {\n // console.warn(\n // 'Starting a new history change with a previous change still open. You may get a strange history state.',\n // `Change still open: ${this.openChange.description}`,\n // `New change: ${description}`\n // );\n // }\n let newChange;\n if (!this.openChange) {\n newChange = this.openChange = {\n change: new Map(),\n description,\n undoFunction,\n };\n }\n processFunction(false);\n const done = (description) => {\n if (this.openChange) {\n if (this.openChange.change.size > 0 || this.openChange.undoFunction !== undefined) {\n if (description) {\n this.openChange.description = description;\n }\n this.changes.push(this.openChange);\n }\n delete this.openChange;\n this.updateState();\n if (this.undoneChanges.length > 0) {\n this.undoneChanges.clear();\n this.updateUndoneState();\n }\n }\n };\n if (undoFunction) {\n this.openChange.redoFunction = () => processFunction(true);\n done();\n }\n else if (newChange) {\n changesProcessed.pipe(take(1)).subscribe(done);\n }\n }\n undo() {\n if (this.openChange) {\n throw Error(\"Can't undo while there are open changes\");\n }\n if (this.changes.length < 1) {\n return;\n }\n const lastChangeSet = this.changes.pop();\n if (lastChangeSet) {\n this.undoneChanges.push(lastChangeSet);\n if (lastChangeSet.undoFunction) {\n lastChangeSet.undoFunction();\n }\n else {\n this.processChangeSet(lastChangeSet, change => {\n // Undo changes in reverse so they are consistent with how they were added.\n change.properties\n .slice()\n .reverse()\n .forEach(property => {\n const restore = property.previousValue;\n switch (property.operation) {\n case exports.EChangeOperation.CreateAndPush:\n change.node.pop(true);\n break;\n case exports.EChangeOperation.Push:\n change.node.pop();\n break;\n case exports.EChangeOperation.Unshift:\n change.node.shift();\n break;\n case exports.EChangeOperation.Shift:\n change.node.unshift(property.previousValue);\n if (isTrackedClass(restore)) {\n restore.isModified = true;\n }\n break;\n case exports.EChangeOperation.Pop:\n change.node.push(property.previousValue);\n if (isTrackedClass(restore)) {\n restore.isModified = true;\n }\n break;\n case exports.EChangeOperation.Remove:\n case exports.EChangeOperation.Splice:\n // Property name is the index of the splice\n // Remove all the added values, add back in the old ones\n change.node.splice(property.name, property.newValue.length, ...restore);\n if (Array.isArray(restore) && restore.length > 0) {\n restore.forEach(restoreItem => {\n if (isTrackedClass(restoreItem)) {\n restoreItem.isModified = true;\n }\n });\n }\n break;\n default:\n change.node[property.name] = property.previousValue;\n }\n });\n });\n }\n this.updateState();\n this.updateUndoneState();\n }\n }\n redo() {\n if (this.openChange) {\n throw Error(\"Can't redo while there are open changes\");\n }\n if (this.undoneChanges.length < 1) {\n return;\n }\n const lastUndoneChangeSet = this.undoneChanges.pop();\n if (lastUndoneChangeSet) {\n this.changes.push(lastUndoneChangeSet);\n if (lastUndoneChangeSet.redoFunction) {\n lastUndoneChangeSet.redoFunction();\n }\n else {\n this.processChangeSet(lastUndoneChangeSet, change => {\n // Redo changes in the initial order\n change.properties.forEach(property => {\n const restore = property.newValue;\n switch (property.operation) {\n case exports.EChangeOperation.CreateAndPush:\n change.node.createAndPush(property.newValue);\n if (isTrackedClass(restore)) {\n restore.isModified = true;\n }\n break;\n case exports.EChangeOperation.Push:\n change.node.push(property.newValue);\n break;\n case exports.EChangeOperation.Unshift:\n change.node.unshift(property.newValue);\n if (isTrackedClass(restore)) {\n restore.isModified = true;\n }\n break;\n case exports.EChangeOperation.Shift:\n change.node.shift();\n break;\n case exports.EChangeOperation.Pop:\n change.node.pop();\n break;\n case exports.EChangeOperation.Remove:\n property.previousValue.length === 1 && change.node.remove(property.previousValue[0]);\n break;\n case exports.EChangeOperation.Splice:\n change.node.splice(property.name, property.previousValue.length, ...restore);\n if (Array.isArray(restore) && restore.length > 0) {\n restore.forEach(restoreItem => {\n if (isTrackedClass(restoreItem)) {\n restoreItem.isModified = true;\n }\n });\n }\n break;\n default:\n change.node[property.name] = property.newValue;\n }\n });\n });\n }\n this.updateState();\n this.updateUndoneState();\n }\n }\n undoTo(index) {\n while (this.changes.length > index + 1) {\n this.undo();\n }\n }\n redoTo(index) {\n while (this.undoneChanges.length > index) {\n this.redo();\n }\n }\n // startGroupingAllChanges() {\n // this.groupAllIncomingChanges = true;\n // this.changes.push(new Map());\n // }\n // stopGroupingAllChanges() {\n // this.groupAllIncomingChanges = false;\n // this.removeLastChangeIfEmpty();\n // this.updateState();\n // }\n // startGroupingObjectsChanges(objects: Array) {\n // this.groupChangesInObjects = new Set(objects.filter(isTrackedClass));\n // this.changes.push(new Map());\n // }\n // stopGroupingObjectsChanges() {\n // this.groupChangesInObjects = undefined;\n // this.removeLastChangeIfEmpty();\n // }\n changeEvent(object, property, value, originalValue, operation) {\n if (this.active &&\n (isTrackedClass(object) || Array.isArray(object)) &&\n value !== originalValue &&\n !this.ignoreChangesFromObjects.has(object)) {\n if (!this.openChange) {\n return;\n }\n const openChange = this.openChange;\n let lastChangeOnObject = openChange.change.get(object);\n if (!lastChangeOnObject) {\n lastChangeOnObject = { node: object, properties: [] };\n openChange.change.set(object, lastChangeOnObject);\n }\n const lastChangeOnObjectProperty = lastChangeOnObject.properties.find(openChange => openChange.name === property);\n if (!lastChangeOnObjectProperty) {\n lastChangeOnObject.properties.push({\n name: property,\n previousValue: originalValue,\n newValue: value,\n operation,\n });\n }\n else {\n lastChangeOnObjectProperty.newValue = value;\n }\n }\n }\n changeEvents(object, changes) {\n if (this.active &&\n (isTrackedClass(object) || Array.isArray(object)) &&\n !this.ignoreChangesFromObjects.has(object)) {\n changes.forEach(change => {\n this.changeEvent(object, change.property, change.value, change.originalValue, change.operation);\n });\n }\n }\n removeLastChange(object, property) {\n // todo\n }\n processChangeSet(changeSet, process) {\n changeSet.change.forEach(change => process(change));\n }\n }\n const history = new SceneHistory();\n\n function nextTick() {\n changesProcessed.next();\n }\n const __arrayProtoFunctions = {};\n ['push', 'unshift', 'shift', 'pop', 'splice', 'reorder', 'clear'].forEach((arrayFunc) => {\n __arrayProtoFunctions[arrayFunc] = Array.prototype[arrayFunc];\n // We shouldn't need this code after the Vue update to 3.2. Was needed to fix reactivity on arrays for Vue\n // Delete this when no confirmed that there are no issues with reactivity in creator\n // Array.prototype[arrayFunc] = function(...args: any) {\n // if(isTrackedArray(this)) {\n // return TrackedArray.prototype[arrayFunc].apply(this, args);\n // } else {\n // return __arrayProtoFunctions[arrayFunc].apply(this, args);\n // }\n // }\n });\n class TrackedArray extends Array {\n constructor(parentObj, propertyName, changesIgnored, historyIgnored, source) {\n super();\n this.parentObj = parentObj;\n this.propertyName = propertyName;\n this.changesIgnored = changesIgnored;\n this.historyIgnored = historyIgnored;\n this.$isTracked = true;\n if (source) {\n for (let i = 0; i < source.length; i++) {\n __arrayProtoFunctions.push.call(this, source[i]);\n }\n }\n }\n push(...items) {\n if (!this.changesIgnored) {\n this.parentObj.setPropertyIsModified(this.propertyName, true);\n if (!this.historyIgnored) {\n history.changeEvents(this, items.map(item => ({\n property: this.length,\n operation: exports.EChangeOperation.Push,\n value: item,\n originalValue: undefined,\n })));\n }\n }\n const res = __arrayProtoFunctions.push.apply(this, items); // super.push(...items);\n for (const item of items) {\n this.parentObj.addedToChildArray(this.parentObj, item, this.propertyName);\n }\n return res;\n }\n unshift(...items) {\n if (!this.changesIgnored) {\n this.parentObj.setPropertyIsModified(this.propertyName, true);\n if (!this.historyIgnored) {\n history.changeEvents(this, items.map(item => ({\n property: 0,\n operation: exports.EChangeOperation.Push,\n value: item,\n originalValue: undefined,\n })));\n }\n }\n const res = __arrayProtoFunctions.unshift.apply(this, items); // super.unshift(...items);\n for (const item of items) {\n this.parentObj.addedToChildArray(this.parentObj, item, this.propertyName);\n }\n return res;\n }\n shift(destroy) {\n const result = __arrayProtoFunctions.shift.apply(this); // super.shift();\n if (!this.changesIgnored) {\n this.parentObj.setPropertyIsModified(this.propertyName, true);\n if (!this.historyIgnored) {\n history.changeEvent(this, 0, undefined, result, exports.EChangeOperation.Shift);\n }\n }\n if (destroy && isTrackedClass(result)) {\n result.destroy();\n }\n this.parentObj.addedToChildArray(this.parentObj, result, this.propertyName);\n return result;\n }\n pop(destroy) {\n const result = __arrayProtoFunctions.pop.apply(this); // super.pop();\n if (!this.changesIgnored) {\n this.parentObj.setPropertyIsModified(this.propertyName, true);\n if (!this.historyIgnored) {\n history.changeEvent(this, this.length, undefined, result, exports.EChangeOperation.Pop);\n }\n }\n if (destroy && isTrackedClass(result)) {\n result.destroy();\n }\n this.parentObj.addedToChildArray(this.parentObj, result, this.propertyName);\n return result;\n }\n splice(start, deleteCount, ...insert) {\n // const result = Array.prototype.splice.call(array, start, deleteCount || 0, ...insert);\n let result;\n if (insert.length === 0) {\n result = __arrayProtoFunctions.splice.apply(this, [start, deleteCount]); // super.splice(start, deleteCount);\n }\n else {\n result = __arrayProtoFunctions.splice.apply(this, [start, deleteCount || 0, ...insert]); // super.splice(start, deleteCount || 0, ...insert);\n }\n result.forEach(resultItem => {\n if (isTrackedClass(resultItem)) {\n resultItem.destroy();\n }\n });\n for (const item of result) {\n this.parentObj.removedFromChildArray(this.parentObj, item, this.propertyName);\n }\n for (const item of insert) {\n this.parentObj.addedToChildArray(this.parentObj, item, this.propertyName);\n }\n if (!this.changesIgnored) {\n this.parentObj.setPropertyIsModified(this.propertyName, true);\n if (!this.historyIgnored) {\n history.changeEvent(this, start, insert, result, exports.EChangeOperation.Splice);\n }\n }\n return result;\n }\n remove(item) {\n const index = this.indexOf(item);\n if (index > -1) {\n return this.splice(index, 1);\n }\n return [];\n }\n reorder(fromIndex, toIndex, undo) {\n __arrayProtoFunctions.reorder.apply(this, [fromIndex, toIndex, undo]);\n if (!this.changesIgnored) {\n this.parentObj.setPropertyIsModified(this.propertyName, true);\n }\n }\n }\n /** Decorator to track the properties of a class. Used in conjunction with the change tracker class.\n * Properties with this decorator will be watched by the change tracker\n * @param {Object} options decorator options object\n * @param {Function} options.onCreate function that is called when a new class instance is created. Called with the proxy object that was created.\n */\n function TrackChanges(options) {\n const onCreateCallback = options ? options.onCreate : undefined;\n const isPropertyEqualOverride = options ? options.isPropertyEqual : undefined;\n const onDestroy = options ? options.onDestroy : undefined;\n const addedToChildArray = options ? options.addedToChildArray : undefined;\n const removedFromChildArray = options ? options.removedFromChildArray : undefined;\n return (targetClass) => {\n const TrackedClass = class extends targetClass {\n get $changesTracked() {\n return true;\n }\n setPropertyIsModified() { }\n destroy() { }\n constructor(...args) {\n super(...args);\n const trackingState = {\n baseObject: this,\n isModified: false,\n };\n if (typeof this.originalValues === 'undefined') {\n Object.defineProperties(this, {\n changes: {\n value: new Map(),\n enumerable: false,\n writable: false,\n configurable: false,\n },\n originalValues: {\n value: new Map(),\n enumerable: false,\n writable: false,\n configurable: false,\n },\n _trackChanges: {\n value: false,\n enumerable: false,\n writable: true,\n configurable: false,\n },\n isModified: {\n configurable: false,\n enumerable: false,\n set: () => { },\n get: () => trackingState.isModified,\n },\n commitChanges: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: (inherited = false) => commitChanges(this, inherited),\n },\n setPropertyIsModified: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: setPropertyIsModified,\n },\n destroy: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: () => destroy(this),\n },\n trackChanges: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: (active) => (this._trackChanges = active),\n },\n rawNode: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: trackingState.baseObject,\n },\n });\n }\n const changedValuesMap = this.changes;\n const originalValuesMap = this.originalValues;\n const proxy = new Proxy(this, {\n // get: (target, property) => {\n // if (property === 'isModified') {\n // return trackingState.isModified;\n // } else if (property === 'commitChanges') {\n // return (inherited: boolean = false) => commitChanges(target, inherited);\n // } else if (property === 'setPropertyIsModified') {\n // return setPropertyIsModified;\n // } else if (property === 'addedToChildArray') {\n // return addedToChildArray ? addedToChildArray : () => { }\n // } else if (property === 'removedFromChildArray') {\n // return removedFromChildArray ? removedFromChildArray : () => { }\n // } else if (property === 'destroy') {\n // return () => destroy(target);\n // } else if (property === 'trackChanges') {\n // return (active: boolean) => this._trackChanges = active;\n // } else if (property === 'rawNode') {\n // return trackingState.baseObject;\n // }\n // return target[property as string];\n // },\n set: (target, property, newValue) => {\n // Allow clearing changes by setting is modified to false.\n if (property === 'isModified') {\n if (newValue === false && newValue !== trackingState.isModified) {\n originalValuesMap.clear();\n changedValuesMap.clear();\n updateIsModified();\n }\n else if (newValue === true) {\n for (const key in target) {\n setPropertyIsModified(key, true);\n }\n }\n return true;\n // Throw type error on trying to redefine decorator functions\n }\n else if (property === 'setPropertyIsModified') {\n return false;\n }\n else {\n // If object is not being tracked, just set the value without tracking the changes\n if (!this._trackChanges) {\n return Reflect.set(trackingState.baseObject, property, newValue);\n }\n const changesIgnored = Reflect.has(target, '_changesIgnoredProperties') &&\n Reflect.get(target, '_changesIgnoredProperties').has(property);\n const historyIgnored = Reflect.has(target, '_historyIgnoredProperties') &&\n Reflect.get(target, '_historyIgnoredProperties').has(property);\n // If the value is an array, then we have to proxy the array to pick up new array elements\n // Important that this occurs even if the object is not being tracked because\n // parent node management will break without the array proxy\n if (Array.isArray(newValue)) {\n newValue = new TrackedArray(proxy, property.toString(), changesIgnored, historyIgnored, newValue);\n }\n if (!changesIgnored) {\n const originalValue = originalValuesMap.get(property.toString());\n const currentValue = Reflect.get(target, property);\n // If the new value is the same as previous, do nothing.\n if (isPropertyEqualOverride &&\n isPropertyEqualOverride(currentValue, newValue, property)) {\n return true;\n }\n else if (currentValue === newValue) {\n return true;\n }\n // Skip checks if originalValue is null. It means isModified is forced to be true until node is processed.\n if (originalValue !== null) {\n if (!originalValue) {\n // If the value is changed and was never changed before, register the change\n originalValuesMap.set(property.toString(), currentValue);\n }\n else {\n let isPropertyModified;\n // If the value was changed before, see if it's the same as the original value.\n let isEqualToOriginal;\n if (isPropertyEqualOverride) {\n isEqualToOriginal = isPropertyEqualOverride(originalValue, newValue, property);\n }\n if (typeof isEqualToOriginal !== 'undefined') {\n isPropertyModified = !isEqualToOriginal;\n }\n else {\n isPropertyModified = originalValue !== newValue;\n }\n // If the value is the same as the original, de-register the change\n if (!isPropertyModified) {\n originalValuesMap.delete(property.toString());\n }\n }\n updateIsModified();\n }\n }\n if (originalValuesMap.has(property.toString())) {\n changedValuesMap.set(property.toString(), newValue);\n }\n else {\n changedValuesMap.delete(property.toString());\n }\n return Reflect.set(trackingState.baseObject, property, newValue);\n }\n },\n });\n // Don't register changes in the history when creating new objects as they have to be registered as new objects instead.\n history.ignoreUntilStable(proxy);\n // The sync service won't have the right proxy object when a new object is created\n SyncService.registerNewObject(proxy);\n // The properties set on the object in the constructor won't be tracked because the original constructor runs before\n // the object is proxied.\n let trackedNewProperty = false;\n for (const property in this) {\n if (!this._changesIgnoredProperties || !this._changesIgnoredProperties.has(property)) {\n if (Array.isArray(this[property])) {\n const arrayHistoryIgnored = this._historyIgnoredProperties && this._historyIgnoredProperties.has(property);\n // We've already filtered out change ignored properties above\n this[property] = new TrackedArray(proxy, property.toString(), false, arrayHistoryIgnored, this[property]);\n }\n originalValuesMap.set(property, this[property]);\n changedValuesMap.set(property, this[property]);\n trackedNewProperty = true;\n }\n }\n if (trackedNewProperty) {\n updateIsModified();\n }\n if (onCreateCallback) {\n onCreateCallback(proxy);\n }\n return proxy;\n function updateIsModified() {\n // If the original value map is not empty, we have some pending changes so this object is considered modified\n if (trackingState.isModified !== originalValuesMap.size > 0) {\n trackingState.isModified = originalValuesMap.size > 0;\n SyncService.registerChangedState(proxy, trackingState.isModified);\n }\n }\n function commitChanges(target, inherited) {\n if (trackingState.isModified) {\n if (!inherited) {\n // Register the change on the history\n originalValuesMap.forEach((oldValue, property) => {\n const historyIgnored = Reflect.has(target, '_historyIgnoredProperties') &&\n Reflect.get(target, '_historyIgnoredProperties').has(property);\n if (!historyIgnored) {\n history.changeEvent(proxy, property, trackingState.baseObject[property], oldValue);\n }\n });\n originalValuesMap.clear();\n changedValuesMap.clear();\n }\n updateIsModified();\n }\n SyncService.nodeChangesProcessed(target);\n }\n function setPropertyIsModified(prop, modified) {\n if (modified) {\n // When forcing a property as modified, set the original value to null so it stays modified until processed (never matches)\n originalValuesMap.set(prop, null);\n changedValuesMap.set(prop, proxy[prop]);\n }\n else {\n originalValuesMap.delete(prop);\n changedValuesMap.delete(prop);\n }\n updateIsModified();\n }\n function destroy(target) {\n if (onDestroy) {\n onDestroy(proxy);\n }\n SyncService.registerDeleted(proxy);\n const inheritedDestroyFunc = Object.getPrototypeOf(target).destroy;\n if (typeof inheritedDestroyFunc === 'function') {\n inheritedDestroyFunc();\n }\n }\n }\n };\n Object.defineProperties(TrackedClass.prototype, {\n addedToChildArray: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: addedToChildArray ? addedToChildArray : () => { },\n },\n removedFromChildArray: {\n configurable: false,\n enumerable: false,\n writable: false,\n value: removedFromChildArray ? removedFromChildArray : () => { },\n },\n });\n return TrackedClass;\n };\n }\n // eslint-disable-next-line @typescript-eslint/ban-types\n function NodeReference(classRef, ...keys) {\n return (target, propertyKey, parameterIndex) => {\n if (typeof target.nodeReferences === 'undefined') {\n Object.defineProperty(target, 'nodeReferences', {\n value: new Map(),\n enumerable: false,\n writable: false,\n configurable: false,\n });\n }\n target.nodeReferences.set(propertyKey, {\n classRef,\n limitKeys: keys.length > 0 ? new Set(keys) : undefined,\n });\n };\n }\n /** Property decorator to ignore changes on some properties. The node will not be processed if only ignored properties change. */\n function IgnoreChanges(target, propertyKey, parameterIndex) {\n if (typeof target._changesIgnoredProperties === 'undefined') {\n Object.defineProperty(target, '_changesIgnoredProperties', {\n value: new Map(),\n enumerable: false,\n writable: false,\n configurable: false,\n });\n }\n target._changesIgnoredProperties.set(propertyKey, true);\n }\n /** Property decorator to ignore history on some properties. The property changing will not trigger history additions. */\n function IgnoreHistory(target, propertyKey, parameterIndex) {\n if (typeof target._historyIgnoredProperties === 'undefined') {\n Object.defineProperty(target, '_historyIgnoredProperties', {\n value: new Map(),\n enumerable: false,\n writable: false,\n configurable: false,\n });\n }\n target._historyIgnoredProperties.set(propertyKey, true);\n }\n\n function isKbVector(object) {\n return object && object.x !== undefined && object.y !== undefined && object.z !== undefined;\n }\n function isKbColor(object) {\n return (object && object.r !== undefined && object.g !== undefined && object.b !== undefined && object.a !== undefined);\n }\n function isKbQuaternion(object) {\n return (object && object.x !== undefined && object.y !== undefined && object.z !== undefined && object.w !== undefined);\n }\n function isPrimitive(object) {\n return isKbVector(object) || isKbColor(object) || isKbQuaternion(object);\n }\n\n /** Convenience decorator that sets up default options for Kb3dObjects with the change tracker */\n function TrackChangesNode(options = {}) {\n const origAddedToChildArray = options.addedToChildArray;\n options.addedToChildArray = (parent, item, arrayPropName) => {\n if (origAddedToChildArray)\n origAddedToChildArray(parent, item, arrayPropName);\n if (instanceOf(parent, Token.Kb3dObject) && instanceOf(item, Token.Kb3dObject)) {\n item._parent = parent;\n if (isTrackedClass(parent) && parent._trackChanges) {\n item.calculateParents();\n }\n }\n };\n const origDestroy = options.onDestroy;\n options.onDestroy = (item) => {\n if (origDestroy)\n origDestroy(item);\n const children = item.getChildren();\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (isTrackedClass(child)) {\n child.destroy();\n }\n }\n if (item._parent && instanceOf(item._parent, Token.Kb3dObject) && instanceOf(item, Token.Kb3dObject)) {\n if (item._parent._manager) {\n item._parent._manager.unregister(item);\n }\n }\n item._parent = undefined;\n item.isModified = false;\n };\n if (!options.isPropertyEqual) {\n options.isPropertyEqual = (oldValue, newValue, propertyKey) => {\n let result;\n // Check equality on node properties by handling arrays and KB primitives. Fall back to strict equality checks for other values.\n if (Array.isArray(oldValue) && Array.isArray(newValue)) {\n if (oldValue.length === newValue.length) {\n let isEqual = true;\n for (let i = 0; i < newValue.length; i++) {\n if (newValue[i] !== oldValue[i]) {\n isEqual = false;\n break;\n }\n }\n result = isEqual;\n }\n else {\n result = false;\n }\n }\n else if (isPrimitive(newValue)) {\n result = typeof oldValue !== 'undefined' && newValue.equal(oldValue);\n }\n // console.log('checking equality', oldValue, newValue, result);\n return result;\n };\n }\n return TrackChanges(options);\n }\n\n function Kb3dModel(options) {\n if (!('trackChanges' in options))\n options.trackChanges = true; //if trackChanges was not provided, default to true\n const $type = options.token.key;\n return (constructor) => {\n //set the $type on the prototype so we can always retrieve it from an instance\n Object.defineProperty(constructor.prototype, '$type', {\n enumerable: false,\n writable: true,\n value: $type,\n });\n /** we bundle up the track changes decorator here as well, as we want our map storing the constructors of\n * our models to actually be storing the constructor of the track changes proxy... so that when a class\n * is constructed using \"create\" that it will actually create the proxy class.\n */\n if (options.trackChanges) {\n const trackChangesFactory = TrackChangesNode(options);\n const combinedConstructor = trackChangesFactory(constructor);\n options.classConstructor = combinedConstructor;\n }\n else {\n options.classConstructor = constructor;\n }\n Kb3dModels.set(options.token, options);\n };\n }\n function BaseKb3dModel(options) {\n return (constructor) => {\n options.classConstructor = constructor;\n Kb3dModels.set(options.token, options);\n };\n }\n\n /**\n * Applied to a getter or setter property, will make it enumerable\n */\n function Enumerable() {\n return function (target, propertyKey, descriptor) {\n descriptor.enumerable = true;\n };\n }\n\n const injectParameters = [];\n function Inject(token) {\n return (target, propertyKey, parameterIndex) => {\n injectParameters.push({\n token: token,\n classConstructor: target,\n parameterIndex,\n ignore: false,\n });\n };\n }\n function Ignore() {\n return (target, propertyKey, parameterIndex) => {\n injectParameters.push({\n token: Token.Ignore,\n classConstructor: target,\n parameterIndex,\n ignore: true,\n });\n };\n }\n function getConstructorParamsForModel(modelDef) {\n let constructor;\n if (modelDef.trackChanges) {\n constructor = Object.getPrototypeOf(modelDef.classConstructor);\n }\n else {\n constructor = modelDef.classConstructor;\n }\n const paramsForType = injectParameters.filter(i => i.classConstructor == constructor);\n paramsForType.sortBy(p => p.index);\n if (modelDef.classConstructor && paramsForType.length < modelDef.classConstructor.length) {\n throw new Error('You must decorate every constructor parameter with an @Inject or @Ignore decorator for type ' +\n modelDef.token.key);\n }\n return paramsForType;\n }\n\n function Kb3dService(options) {\n const $type = options.token.key;\n return (constructor) => {\n constructor.prototype.$type = $type;\n options.classConstructor = constructor;\n Kb3dModels.set(options.token, options);\n };\n }\n\n (function (eParentChangeBehavior) {\n eParentChangeBehavior[eParentChangeBehavior[\"PRESERVE_POSITION\"] = 0] = \"PRESERVE_POSITION\";\n eParentChangeBehavior[eParentChangeBehavior[\"PRESERVE_PROPERTY\"] = 1] = \"PRESERVE_PROPERTY\";\n })(exports.eParentChangeBehavior || (exports.eParentChangeBehavior = {}));\n\n (function (eNodeError) {\n eNodeError[eNodeError[\"FEATURE_REFERENCE\"] = 0] = \"FEATURE_REFERENCE\";\n eNodeError[eNodeError[\"GEOMETRY_SAVE\"] = 1] = \"GEOMETRY_SAVE\";\n })(exports.eNodeError || (exports.eNodeError = {}));\n /**\n * Base class for kb3d models. Any model that has an id and $type should derive from this class\n */\n exports.Kb3dObject = class Kb3dObject {\n constructor() {\n this._level = -1;\n this._errors = [];\n this._selected = false;\n this._expanded = false;\n this.id = UUID.generate();\n this._dynamicId = UUID.generate();\n }\n get _token() {\n return Token.withKey(this.$type);\n }\n get _rootScene() {\n return this.__rootScene;\n }\n setRootScene(scene) {\n if (this.__rootScene !== scene) {\n this.__rootScene = scene;\n if (isTrackedClass(this)) {\n this.trackChanges(!!scene);\n }\n }\n }\n get metadata() {\n if (!this._metadata)\n this._metadata = {};\n return this._metadata;\n }\n set metadata(val) {\n this._metadata = val;\n }\n clone() {\n if (this._manager) {\n return this._manager.clone(this);\n }\n }\n serialize() {\n if (this._manager) {\n return this._manager.serialize(this);\n }\n }\n serializeToJson(prettyPrint = false) {\n if (this._manager) {\n return this._manager.serializeToJson(this, { prettyPrint });\n }\n return '';\n }\n calculateParents(deletion = false, parent) {\n var _a, _b;\n // When a node is deleted and recreated, the children won't have parents because they were not re-added to the parent's arrays.\n // This solves that case by making sure the hierarchy is consistent from the top down\n if (parent && this._parent !== parent) {\n this._parent = parent;\n }\n if (this._parent) {\n this._level = this._parent._level == -1 ? -1 : this._parent._level + 1;\n this._parentScene = this._parent._parentScene;\n this.setRootScene(this._parent._rootScene);\n if (instanceOf(this, Token.SceneNode)) {\n //it's a nested scene\n this._parentScene = this;\n }\n else {\n this._manager = this._parent._manager; // a nested scene uses it's own manager, but everything else should have the same as it's parent\n }\n if (this._parentScene && !deletion) {\n (_a = this._manager) === null || _a === void 0 ? void 0 : _a.register(this);\n }\n }\n else if (instanceOf(this, Token.SceneNode) && !deletion) {\n this._level = 0;\n this._parentScene = this;\n this.setRootScene(this);\n (_b = this._manager) === null || _b === void 0 ? void 0 : _b.register(this);\n }\n else {\n this._level = -1; // -1 means this is not part of a scene node hierarchy\n // TODO add this change after release on Jan 13 2023, test to ensure it works\n // if(isTrackedClass(this)) {\n // this.trackChanges(false);\n // }\n }\n for (const c of this.getChildren()) {\n c.calculateParents(deletion, this);\n }\n }\n /**\n * Derived classes that have children should override this\n */\n getChildren() {\n return [];\n }\n /**\n * Derived classes with children should override this\n */\n getChildArrayForType(token) {\n return undefined;\n }\n getChildArray(child) {\n return this.getChildArrayForType(Token.withKey(child.$type));\n }\n addChildren(...children) {\n var _a;\n for (const c of children) {\n (_a = this.getChildArray(c)) === null || _a === void 0 ? void 0 : _a.push(c);\n }\n }\n removeChildren(...children) {\n var _a;\n for (const c of children) {\n (_a = this.getChildArray(c)) === null || _a === void 0 ? void 0 : _a.remove(c);\n }\n }\n insertChildAfter(afterChild, newChild) {\n const arr1 = this.getChildArray(afterChild);\n const arr2 = this.getChildArray(newChild);\n if (!arr1 || !arr2)\n throw 'incompatible child';\n if (arr1 !== arr2)\n throw 'children mismatch';\n const index = arr1.indexOf(afterChild);\n if (index === -1)\n throw 'could not find given child';\n arr1.splice(index + 1, 0, newChild);\n }\n getAncestors() {\n const ancestors = new Array();\n let parent = this._parent;\n while (parent != null) {\n ancestors.push(parent);\n parent = parent._parent;\n }\n return ancestors;\n }\n getNamePath() {\n let path = '';\n let self = this;\n while (self && !instanceOf(self, Token.SceneNode)) {\n path = self.name + (path ? '/' + path : '');\n self = self._parent;\n }\n return path;\n }\n /**\n * Filters children recursively based on a condition. This is an O(n) operation, so only use when performance is not paramount\n * @param predicate expression to test whether the object should be included\n * @param includeSelf whether to include this kb3dObject in the search\n * @param alwaysIncludeChildren if true, will always search children even if the parent resolves to false\n */\n filter(predicate, includeSelf = false, alwaysIncludeChildren = true) {\n const res = [];\n let included = true;\n if (includeSelf && predicate(this)) {\n res.push(this);\n }\n else {\n included = false;\n }\n if (included || alwaysIncludeChildren) {\n const children = this.getChildren();\n for (const child of children) {\n res.push(...child.filter(predicate, true, alwaysIncludeChildren));\n }\n }\n return res;\n }\n /**\n * filters children by type given a list of type tokens\n * @param tokens\n */\n filterByType(...tokens) {\n return this.filter(node => instanceOfAny(node, ...tokens));\n }\n /**\n * filters children, but only those that qualify as nodes\n * @param predicate\n * @param includeSelf\n * @param alwaysIncludeChildren\n */\n filterNodes(predicate, includeSelf = false, alwaysIncludeChildren = true) {\n const nodePredicate = (node) => node.isNode() && predicate(node);\n return this.filter(nodePredicate, includeSelf, alwaysIncludeChildren);\n }\n isNode() {\n return this._token.isNode();\n }\n };\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"name\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"$type\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"_manager\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"_parentScene\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"__rootScene\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"_level\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"_errors\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.Kb3dObject.prototype, \"_expanded\", void 0);\n __decorate([\n Enumerable()\n ], exports.Kb3dObject.prototype, \"metadata\", null);\n exports.Kb3dObject = __decorate([\n BaseKb3dModel({\n token: Token.Kb3dObject,\n })\n ], exports.Kb3dObject);\n\n exports.BaseConnector = class BaseConnector extends exports.Kb3dObject {\n constructor() {\n super(...arguments);\n this._sketchControlPoints = [];\n }\n /** Extended by child classes to return the space node parent of this connector */\n getSpaceParent() {\n return undefined;\n }\n };\n exports.BaseConnector = __decorate([\n BaseKb3dModel({\n token: Token.BaseConnector,\n })\n ], exports.BaseConnector);\n\n var Feature_1;\n (function (eMeshChangeTypes) {\n eMeshChangeTypes[eMeshChangeTypes[\"VertexIndices\"] = 0] = \"VertexIndices\";\n eMeshChangeTypes[eMeshChangeTypes[\"VertexPositions\"] = 1] = \"VertexPositions\";\n eMeshChangeTypes[eMeshChangeTypes[\"VertexNormals\"] = 2] = \"VertexNormals\";\n eMeshChangeTypes[eMeshChangeTypes[\"VertexUvs\"] = 3] = \"VertexUvs\";\n eMeshChangeTypes[eMeshChangeTypes[\"Submeshes\"] = 4] = \"Submeshes\";\n eMeshChangeTypes[eMeshChangeTypes[\"Transform\"] = 5] = \"Transform\";\n })(exports.eMeshChangeTypes || (exports.eMeshChangeTypes = {}));\n const ALL_GEOMETRY = [\n exports.eMeshChangeTypes.VertexIndices,\n exports.eMeshChangeTypes.VertexPositions,\n exports.eMeshChangeTypes.VertexNormals,\n exports.eMeshChangeTypes.VertexUvs,\n exports.eMeshChangeTypes.Submeshes,\n ];\n const ALL_CHANGES = [...ALL_GEOMETRY, exports.eMeshChangeTypes.Transform];\n exports.Feature = Feature_1 = class Feature extends exports.Kb3dObject {\n get dependsOn() {\n return this.constructor._dependsOn;\n }\n get affects() {\n return this.constructor._affects;\n }\n get affectedBy() {\n return this.constructor._affectedBy;\n }\n constructor() {\n super();\n this._suppressed = false;\n }\n getAncestors() {\n return super.getAncestors();\n }\n };\n exports.Feature = Feature_1 = __decorate([\n BaseKb3dModel({\n token: Token.Feature,\n })\n ], exports.Feature);\n function isFeatureNode(node) {\n return instanceOf(node, Token.Feature);\n }\n\n let defaults = {\n AnnotationNode: {\n enabled: true,\n label: null,\n fontFamily: null,\n fontSize: 0.1,\n lineSpacing: 0,\n preloadFontStylesheet: \"\",\n color: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n targetId: null,\n billboard: false,\n isPickable: false,\n keepOnTop: false,\n lineStyle: \"solid\",\n horizontalTextAlign: \"left\",\n verticalBoxAlign: \"middle\",\n horizontalBoxAlign: \"center\",\n offset: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n name: null,\n metadata: {},\n },\n DimensionNode: {\n target2Id: null,\n lineCapStyle: \"line\",\n axis: \"free\",\n lineThickness: 0.05,\n dimensionGap: 0.1,\n dimensionUnitPrecision: 2,\n labelOffset: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n scaleWithCamera: false,\n enabled: true,\n label: null,\n fontFamily: null,\n fontSize: 0.1,\n lineSpacing: 0,\n preloadFontStylesheet: \"\",\n color: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n targetId: null,\n billboard: false,\n isPickable: false,\n keepOnTop: false,\n lineStyle: \"solid\",\n horizontalTextAlign: \"left\",\n verticalBoxAlign: \"middle\",\n horizontalBoxAlign: \"center\",\n offset: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n name: null,\n metadata: {},\n },\n BaseConnector: {\n positionMode: \"boundingBox\",\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n direction: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n angle: 0,\n positionZeroToOne: 0,\n interpolateDirection: true,\n name: null,\n metadata: {},\n },\n Connector: {\n enabled: true,\n positionMode: \"boundingBox\",\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n direction: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n angle: 0,\n positionZeroToOne: 0,\n interpolateDirection: true,\n name: null,\n metadata: {},\n },\n CircularPatternFeature: {\n arc: 360,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n axis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n count: 1,\n meshId: null,\n distance: 1,\n addEndMesh: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n DeleteFacesFeature: {\n enabled: true,\n name: null,\n metadata: {},\n },\n DisplacementMapFeature: {\n minDisplacement: 0,\n maxDisplacement: 1,\n enabled: true,\n name: null,\n metadata: {},\n },\n ExtrudeFeature: {\n size: 0,\n capEnd: false,\n capStart: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n Feature: {\n enabled: true,\n name: null,\n metadata: {},\n },\n JoinGeometryFeature: {\n joinType: \"cut\",\n meshId: null,\n enabled: true,\n name: null,\n metadata: {},\n },\n LinearPatternFeature: {\n translation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n count: 1,\n meshId: null,\n distance: 1,\n addEndMesh: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n MirrorFeature: {\n cloneGeometry: false,\n intersect: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n normal: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n removeGeometry: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n MoveVerticesFeature: {\n translation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scale: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n center: \"barycenter\",\n enabled: true,\n name: null,\n metadata: {},\n },\n NormalSmoothingFeature: {\n smooth: true,\n enabled: true,\n name: null,\n metadata: {},\n },\n PatternFeature: {\n count: 1,\n meshId: null,\n distance: 1,\n addEndMesh: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n SliceFeature: {\n intersect: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n normal: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n removeGeometry: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n SubmeshFeature: {\n uvMapping: false,\n materialId: null,\n center: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n projectionAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n angle: 0,\n scale: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n uTile: 1,\n vTile: 1,\n uOffset: 0,\n vOffset: 0,\n mode: \"planar\",\n enabled: true,\n name: null,\n metadata: {},\n },\n SweepFeature: {\n start: null,\n end: null,\n path: null,\n mitredExtrusion: false,\n size: 0,\n capEnd: false,\n capStart: false,\n enabled: true,\n name: null,\n metadata: {},\n },\n TransformFeature: {\n scale: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n enabled: true,\n name: null,\n metadata: {},\n },\n UvMapFeature: {\n center: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n projectionAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n angle: 0,\n scale: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n uTile: 1,\n vTile: 1,\n uOffset: 0,\n vOffset: 0,\n mode: \"planar\",\n enabled: true,\n name: null,\n metadata: {},\n },\n WeldVerticesFeature: {\n enabled: true,\n name: null,\n metadata: {},\n },\n Kb3dObject: {\n name: null,\n metadata: {},\n },\n DirectionalLightNode: {\n direction: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n generatesShadows: false,\n shadowQuality: \"medium\",\n shadowResolution: \"low\",\n shadowFilter: \"simple\",\n processTransparency: false,\n intensity: 1,\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n HemisphericLightNode: {\n direction: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n groundColor: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n intensity: 1,\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n LightNode: {\n intensity: 1,\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n PointLightNode: {\n generatesShadows: false,\n shadowQuality: \"medium\",\n shadowResolution: \"low\",\n shadowFilter: \"simple\",\n processTransparency: false,\n intensity: 1,\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n ShadowLightNode: {\n generatesShadows: false,\n shadowQuality: \"medium\",\n shadowResolution: \"low\",\n shadowFilter: \"simple\",\n processTransparency: false,\n intensity: 1,\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n SpotLightNode: {\n coneAngle: 60,\n direction: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n generatesShadows: false,\n shadowQuality: \"medium\",\n shadowResolution: \"low\",\n shadowFilter: \"simple\",\n processTransparency: false,\n intensity: 1,\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n AdvancedMaterialNode: {\n workflowMode: \"metallicRoughness\",\n backFaceCulling: false,\n directIntensity: 1,\n emissiveIntensity: 1,\n environmentIntensity: 1,\n specularIntensity: 1,\n metallic: 0,\n roughness: 1,\n microSurface: 1,\n useSpecularOverAlpha: true,\n useRadianceOverAlpha: true,\n ambientColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n albedoColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n specularColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n reflectionColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n anisotropyEnabled: false,\n anisotropicDirection: { \"$type\": \"KbVector\", \"x\": 1.0, \"y\": 1.0, \"z\": 1.0 },\n anisotropicIntensity: 1,\n subsurfaceThickness: 1,\n subsurfaceRefractionEnabled: false,\n subsurfaceReflectionEnabled: false,\n reflectionType: \"plane\",\n probePositionTargetId: null,\n subsurfaceRefractionIndex: 1,\n subsurfaceRefractionIntensity: 1,\n subsurfaceRefractionLinkTransparency: false,\n subsurfaceTranslucencyEnabled: false,\n subsurfaceTranslucencyIntensity: 1,\n subsurfaceUseAlbedoForTintColor: true,\n subsurfaceTintColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n clearcoatEnabled: false,\n clearcoatIntensity: 1,\n clearcoatTintEnabled: false,\n clearcoatTintColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n clearcoatTintIntensity: 0.1,\n archived: false,\n location: \"local\",\n alpha: 1,\n zOffset: 0,\n doubleSided: false,\n legacyTextureStacking: true,\n viewMode: \"shaded\",\n emissiveColor: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n hasTransparency: false,\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n ColorFillTextureLayer: {\n color: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n width: 256,\n height: 256,\n enabled: true,\n strength: 1,\n tile: false,\n maintainAspect: false,\n useClippingMask: false,\n blendMode: \"normal\",\n horizontalAlign: \"center\",\n verticalAlign: \"middle\",\n horizontalFit: \"none\",\n verticalFit: \"none\",\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n FileTextureLayer: {\n width: 256,\n height: 256,\n flipNormalsRg: false,\n enabled: true,\n strength: 1,\n tile: false,\n maintainAspect: false,\n useClippingMask: false,\n blendMode: \"normal\",\n horizontalAlign: \"center\",\n verticalAlign: \"middle\",\n horizontalFit: \"none\",\n verticalFit: \"none\",\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n MaterialMapping: {\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n MaterialNode: {\n location: \"local\",\n alpha: 1,\n zOffset: 0,\n reflectionType: \"plane\",\n doubleSided: false,\n legacyTextureStacking: true,\n viewMode: \"shaded\",\n emissiveColor: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n hasTransparency: false,\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n SvgTextureLayer: {\n width: 256,\n height: 256,\n preloadFontStylesheet: \"\",\n enabled: true,\n strength: 1,\n tile: false,\n maintainAspect: false,\n useClippingMask: false,\n blendMode: \"normal\",\n horizontalAlign: \"center\",\n verticalAlign: \"middle\",\n horizontalFit: \"none\",\n verticalFit: \"none\",\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n TextTextureLayer: {\n text: \"\",\n color: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n enabled: true,\n strength: 1,\n tile: false,\n maintainAspect: false,\n useClippingMask: false,\n blendMode: \"normal\",\n horizontalAlign: \"center\",\n verticalAlign: \"middle\",\n horizontalFit: \"none\",\n verticalFit: \"none\",\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n TextureLayer: {\n enabled: true,\n strength: 1,\n tile: false,\n maintainAspect: false,\n useClippingMask: false,\n blendMode: \"normal\",\n horizontalAlign: \"center\",\n verticalAlign: \"middle\",\n horizontalFit: \"none\",\n verticalFit: \"none\",\n uOffset: 0,\n vOffset: 0,\n uScale: 1,\n vScale: 1,\n uAngle: 0,\n vAngle: 0,\n wAngle: 0,\n uPivot: 0.5,\n vPivot: 0.5,\n wPivot: 0.5,\n name: null,\n metadata: {},\n },\n MateNode: {\n enabled: true,\n connector1: null,\n connector2: null,\n mateType: \"fastened\",\n flip: false,\n offsetX: 0,\n offsetY: 0,\n offsetZ: 0,\n offsetAngle: 0,\n name: null,\n metadata: {},\n },\n BoxNode: {\n height: 1,\n width: 1,\n depth: 1,\n tessellation: 1,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n ConeNode: {\n height: 1,\n radiusTop: 0,\n radiusBottom: 0.5,\n tessellation: 24,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n CustomMeshNode: {\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n CylinderNode: {\n height: 1,\n radius: 0.5,\n arc: 360,\n tessellation: 24,\n subdivisions: 1,\n capMode: \"both\",\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n DiscNode: {\n radius: 0.5,\n tessellation: 64,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n GroundNode: {\n height: 1,\n width: 1,\n subdivisions: 1,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n MeshGroupNode: {\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n MeshNode: {\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n PlaneNode: {\n depth: 4,\n width: 4,\n segments: 1,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n PrimitiveMeshNode: {\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n SketchControlPoint: {\n positionMode: \"absolute\",\n direction2: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": -1.0, \"z\": 0.0 },\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n direction: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n angle: 0,\n positionZeroToOne: 0,\n interpolateDirection: true,\n name: null,\n metadata: {},\n },\n SketchNode: {\n normal: \"y\",\n addFace: false,\n closePath: false,\n tracePath: false,\n lineThickness: 1,\n pathColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n flipPath: false,\n clonePath: null,\n boundingXOverride: null,\n boundingYOverride: null,\n boundingZOverride: null,\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n SketchPath: {\n pathGroupKey: \"default\",\n holeForPathGroup: null,\n type: \"points\",\n tessellation: 16,\n name: null,\n metadata: {},\n },\n SpaceNode: {\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n SphereNode: {\n tessellation: 32,\n radius: 0.5,\n latitudeStart: 0,\n latitudeSlice: 180,\n arc: 360,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n TextNode: {\n curveRadius: 0,\n charSpacing: 1,\n text: \"\",\n fontFile: \"\",\n fontSize: 1,\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n TorusNode: {\n radius: 0.5,\n thickness: 0.25,\n arc: 360,\n latitudeStart: 0,\n latitudeSlice: 360,\n tessellation: 16,\n sideOrientation: \"frontSide\",\n materialId: null,\n flipSurfaceOrientation: false,\n receiveShadows: false,\n castShadows: false,\n isPickable: true,\n checkCollisions: false,\n opacity: 1,\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n SceneNode: {\n background: \"transparent\",\n environment: \"library://adams_place_bridge\",\n environmentBlur: 0.27,\n environmentIntensity: 1,\n backgroundColor: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 0.0 },\n ambientColor: { \"$type\": \"KbColor\", \"r\": 0.0, \"g\": 0.0, \"b\": 0.0, \"a\": 1.0 },\n renderMode: \"shaded\",\n edgeColor: { \"$type\": \"KbColor\", \"r\": 1.0, \"g\": 1.0, \"b\": 1.0, \"a\": 1.0 },\n edgeWidth: 1,\n edgeDisplayTolerance: 0.95,\n viewpointId: null,\n frameViewpoint: false,\n progressiveTextureLoad: true,\n enableDeferredSceneUpdates: true,\n enableGrid: false,\n enableGridAxes: false,\n gridSize: 10,\n gridStepSize: 1,\n gridMajorInterval: 1,\n gridNormal: \"y\",\n environmentRotation: 0,\n connectorSize: 0.1,\n enableFxaaPostProcess: false,\n enableLensEffectsPostProcess: false,\n enableSSAOPostProcess: false,\n textureSamplingMode: \"trilinear\",\n fullscreenEnabled: true,\n arEnabled: true,\n xrAllowScaling: false,\n unitsPerMeter: 1,\n xrAddShadow: true,\n xrLightingEstimation: false,\n enableHoverEffects: false,\n enableSceneOptimization: true,\n loadingExperience: \"spinner\",\n loadingImagePath: null,\n dimensionUnitScalar: 1,\n dimensionUnitSymbol: \"m\",\n conversionMap: {},\n visible: true,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n useEuler: false,\n eulerRotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n rotationAngle: 0,\n scaling: 1,\n pivot: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fixed: false,\n name: null,\n metadata: {},\n },\n ViewpointNode: {\n type: \"orbit\",\n targetMode: \"point\",\n projection: \"perspective\",\n offsetX: 0,\n offsetY: 0,\n position: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n targetPoint: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n targetMeshId: null,\n rotation: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 0.0, \"z\": 0.0 },\n fov: 50,\n allowOrbit: true,\n allowPan: true,\n allowZoom: true,\n limitMinimumTargetDistance: false,\n minTargetDistance: 0.001,\n maxTargetDistance: 10000,\n orbitAxis: { \"$type\": \"KbVector\", \"x\": 0.0, \"y\": 1.0, \"z\": 0.0 },\n limitLatOrbit: false,\n limitMinLatitude: 0,\n limitMaxLatitude: 180,\n limitLngOrbit: false,\n limitMinLongitude: -180,\n limitMaxLongitude: 180,\n name: null,\n metadata: {},\n },\n };\n\n exports.MaterialMapping = class MaterialMapping extends exports.Kb3dObject {\n constructor() {\n super(...arguments);\n this.uOffset = 0; // Define an offset on the texture to offset the u coordinates of the UVs\n this.vOffset = 0; // Define an offset on the texture to offset the v coordinates of the UVs\n this.uScale = 1; // Define an offset on the texture to scale the u coordinates of the UVs\n this.vScale = 1; // Define an offset on the texture to scale the v coordinates of the UVs\n this.uAngle = 0; // Define an offset on the texture to rotate around the u coordinates of the UVs\n this.vAngle = 0; // Define an offset on the texture to rotate around the v coordinates of the UVs\n this.wAngle = 0; // Define an offset on the texture to rotate around the w coordinates of the UVs\n this.uPivot = 0.5; // Defines the center of rotation (U)\n this.vPivot = 0.5; // Defines the center of rotation (V)\n this.wPivot = 0.5; // Defines the center of rotation (W)\n }\n };\n exports.MaterialMapping = __decorate([\n BaseKb3dModel({\n token: Token.MaterialMapping,\n })\n ], exports.MaterialMapping);\n\n const NEVER_INHERIT = new Set([\n '$type',\n 'overriddenProperties',\n '_parentMaterial',\n 'parentMaterialId',\n 'location',\n 'children',\n '_selected',\n '_expanded',\n 'id',\n 'name',\n 'visible',\n '_parent',\n '_parentScene',\n '_rootScene',\n '_level',\n ]);\n exports.MaterialNode = class MaterialNode extends exports.MaterialMapping {\n constructor(_materialService) {\n super();\n this._materialService = _materialService;\n this._overriddenPropertiesSet = new Set();\n this._initialized = false;\n }\n get materials() {\n if (!this._materials)\n this._materials = [];\n return this._materials;\n }\n set materials(val) {\n this._materials = val;\n }\n get overriddenProperties() {\n if (!this._overriddenProperties)\n this._overriddenProperties = [];\n return this._overriddenProperties;\n }\n set overriddenProperties(val) {\n this._overriddenProperties = val;\n }\n get textures() {\n if (!this._textures)\n this._textures = [];\n return this._textures;\n }\n set textures(val) {\n this._textures = val;\n }\n init() {\n this.refreshParentMaterial();\n if (!this._initialized) {\n if (isTrackedClass(this)) {\n // Always track changes on initialized materials because they may be global materials\n this.trackChanges(true);\n this.isModified = true;\n }\n this._initialized = true;\n this.textures.forEach(texture => {\n texture.init(this);\n });\n }\n }\n getChildren() {\n return [...this.textures, ...this.materials];\n }\n getChildArrayForType(token) {\n if (token.isMaterial()) {\n return this.materials;\n }\n else if (token.isTexture()) {\n return this.textures;\n }\n else {\n throw 'unexpected token';\n }\n }\n overrideProperty(property) {\n if (this.parentMaterialId) {\n this._overriddenPropertiesSet.add(property);\n }\n }\n inheritProperty(property) {\n if (this.parentMaterialId) {\n this._overriddenPropertiesSet.delete(property);\n if (this._parentMaterial) {\n this[property] =\n this._parentMaterial[property] == null\n ? defaults[this.$type][property]\n : this._parentMaterial[property];\n }\n }\n }\n getTextureByName(name) {\n return [...this.textures].find(f => f.name.isEqual(name));\n }\n inheritFromMaterial(parentMat) {\n this.parentMaterialId = parentMat.id;\n this._parentMaterial = parentMat;\n if (!this._manager) {\n return;\n }\n const manager = this._manager;\n NEVER_INHERIT.forEach(prop => {\n this._overriddenPropertiesSet.add(prop);\n });\n for (const _key in parentMat) {\n const key = _key;\n if (!this._overriddenPropertiesSet.has(key)) {\n //if this is a serialization of a texture node, then we need to deserialize it\n if (Array.isArray(parentMat[key])) {\n const currentTextures = this[key];\n parentMat[key].forEach((tex, indexOnParent) => {\n const texDef = { ...tex, name: `Base ${tex.name || tex.channel}` };\n if (!texDef.id) {\n texDef.id = `${parentMat.id}_${tex.channel}`;\n }\n const currentIndex = currentTextures.findIndex(currentTexture => currentTexture.id === texDef.id);\n if (currentIndex < 0) {\n const textureNode = manager.deserialize(texDef);\n textureNode._external = true;\n // If this material is already initialized, make sure the new texture is also initialized.\n if (this._initialized) {\n textureNode.init(this);\n }\n currentTextures.splice(indexOnParent, 0, textureNode);\n }\n });\n }\n else {\n this[key] =\n parentMat[key] instanceof exports.Kb3dObject ? parentMat[key] : manager.deserialize(parentMat[key]);\n }\n }\n }\n }\n refreshParentMaterial() {\n if (this.parentMaterialId) {\n this._materialService.getMaterialById(this.parentMaterialId).subscribe(parentMaterial => {\n if (parentMaterial && parentMaterial.data) {\n this.inheritFromMaterial(parentMaterial.data);\n }\n });\n }\n }\n getMediaReferences() {\n const refs = new Array();\n for (const texture of this.textures) {\n if (instanceOf(texture, Token.FileTextureLayer) && texture.path && !isAbsoluteUrl(texture.path)) {\n refs.push({\n type: 'Media',\n id: 'media/' + texture.path,\n });\n }\n }\n return refs;\n }\n };\n __decorate([\n Enumerable()\n ], exports.MaterialNode.prototype, \"materials\", null);\n __decorate([\n IgnoreChanges\n ], exports.MaterialNode.prototype, \"_initialized\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.MaterialNode.prototype, \"location\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.MaterialNode.prototype, \"parentMaterialId\", void 0);\n __decorate([\n Enumerable()\n ], exports.MaterialNode.prototype, \"overriddenProperties\", null);\n __decorate([\n Enumerable()\n ], exports.MaterialNode.prototype, \"textures\", null);\n __decorate([\n IgnoreChanges\n ], exports.MaterialNode.prototype, \"legacyTextureStacking\", void 0);\n exports.MaterialNode = __decorate([\n BaseKb3dModel({\n token: Token.MaterialNode,\n })\n ], exports.MaterialNode);\n function isMaterialNode(node) {\n return instanceOfAny(node, ...Token.MaterialTokens);\n }\n\n function __decorate$1(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n }\n\n /**\n * Class used to evaluate queries containing `and` and `or` operators\n */\n class AndOrNotEvaluator {\n /**\n * Evaluate a query\n * @param query defines the query to evaluate\n * @param evaluateCallback defines the callback used to filter result\n * @returns true if the query matches\n */\n static Eval(query, evaluateCallback) {\n if (!query.match(/\\([^()]*\\)/g)) {\n query = AndOrNotEvaluator._HandleParenthesisContent(query, evaluateCallback);\n }\n else {\n query = query.replace(/\\([^()]*\\)/g, (r) => {\n // remove parenthesis\n r = r.slice(1, r.length - 1);\n return AndOrNotEvaluator._HandleParenthesisContent(r, evaluateCallback);\n });\n }\n if (query === \"true\") {\n return true;\n }\n if (query === \"false\") {\n return false;\n }\n return AndOrNotEvaluator.Eval(query, evaluateCallback);\n }\n static _HandleParenthesisContent(parenthesisContent, evaluateCallback) {\n evaluateCallback =\n evaluateCallback ||\n ((r) => {\n return r === \"true\" ? true : false;\n });\n let result;\n const or = parenthesisContent.split(\"||\");\n for (const i in or) {\n if (Object.prototype.hasOwnProperty.call(or, i)) {\n let ori = AndOrNotEvaluator._SimplifyNegation(or[i].trim());\n const and = ori.split(\"&&\");\n if (and.length > 1) {\n for (let j = 0; j < and.length; ++j) {\n const andj = AndOrNotEvaluator._SimplifyNegation(and[j].trim());\n if (andj !== \"true\" && andj !== \"false\") {\n if (andj[0] === \"!\") {\n result = !evaluateCallback(andj.substring(1));\n }\n else {\n result = evaluateCallback(andj);\n }\n }\n else {\n result = andj === \"true\" ? true : false;\n }\n if (!result) {\n // no need to continue since 'false && ... && ...' will always return false\n ori = \"false\";\n break;\n }\n }\n }\n if (result || ori === \"true\") {\n // no need to continue since 'true || ... || ...' will always return true\n result = true;\n break;\n }\n // result equals false (or undefined)\n if (ori !== \"true\" && ori !== \"false\") {\n if (ori[0] === \"!\") {\n result = !evaluateCallback(ori.substring(1));\n }\n else {\n result = evaluateCallback(ori);\n }\n }\n else {\n result = ori === \"true\" ? true : false;\n }\n }\n }\n // the whole parenthesis scope is replaced by 'true' or 'false'\n return result ? \"true\" : \"false\";\n }\n static _SimplifyNegation(booleanString) {\n booleanString = booleanString.replace(/^[\\s!]+/, (r) => {\n // remove whitespaces\n r = r.replace(/[\\s]/g, () => \"\");\n return r.length % 2 ? \"!\" : \"\";\n });\n booleanString = booleanString.trim();\n if (booleanString === \"!true\") {\n booleanString = \"false\";\n }\n else if (booleanString === \"!false\") {\n booleanString = \"true\";\n }\n return booleanString;\n }\n }\n\n /**\n * Class used to store custom tags\n */\n class Tags {\n /**\n * Adds support for tags on the given object\n * @param obj defines the object to use\n */\n static EnableFor(obj) {\n obj._tags = obj._tags || {};\n obj.hasTags = () => {\n return Tags.HasTags(obj);\n };\n obj.addTags = (tagsString) => {\n return Tags.AddTagsTo(obj, tagsString);\n };\n obj.removeTags = (tagsString) => {\n return Tags.RemoveTagsFrom(obj, tagsString);\n };\n obj.matchesTagsQuery = (tagsQuery) => {\n return Tags.MatchesQuery(obj, tagsQuery);\n };\n }\n /**\n * Removes tags support\n * @param obj defines the object to use\n */\n static DisableFor(obj) {\n delete obj._tags;\n delete obj.hasTags;\n delete obj.addTags;\n delete obj.removeTags;\n delete obj.matchesTagsQuery;\n }\n /**\n * Gets a boolean indicating if the given object has tags\n * @param obj defines the object to use\n * @returns a boolean\n */\n static HasTags(obj) {\n if (!obj._tags) {\n return false;\n }\n const tags = obj._tags;\n for (const i in tags) {\n if (Object.prototype.hasOwnProperty.call(tags, i)) {\n return true;\n }\n }\n return false;\n }\n /**\n * Gets the tags available on a given object\n * @param obj defines the object to use\n * @param asString defines if the tags must be returned as a string instead of an array of strings\n * @returns the tags\n */\n static GetTags(obj, asString = true) {\n if (!obj._tags) {\n return null;\n }\n if (asString) {\n const tagsArray = [];\n for (const tag in obj._tags) {\n if (Object.prototype.hasOwnProperty.call(obj._tags, tag) && obj._tags[tag] === true) {\n tagsArray.push(tag);\n }\n }\n return tagsArray.join(\" \");\n }\n else {\n return obj._tags;\n }\n }\n /**\n * Adds tags to an object\n * @param obj defines the object to use\n * @param tagsString defines the tag string. The tags 'true' and 'false' are reserved and cannot be used as tags.\n * A tag cannot start with '||', '&&', and '!'. It cannot contain whitespaces\n */\n static AddTagsTo(obj, tagsString) {\n if (!tagsString) {\n return;\n }\n if (typeof tagsString !== \"string\") {\n return;\n }\n const tags = tagsString.split(\" \");\n tags.forEach(function (tag) {\n Tags._AddTagTo(obj, tag);\n });\n }\n /**\n * @internal\n */\n static _AddTagTo(obj, tag) {\n tag = tag.trim();\n if (tag === \"\" || tag === \"true\" || tag === \"false\") {\n return;\n }\n if (tag.match(/[\\s]/) || tag.match(/^([!]|([|]|[&]){2})/)) {\n return;\n }\n Tags.EnableFor(obj);\n obj._tags[tag] = true;\n }\n /**\n * Removes specific tags from a specific object\n * @param obj defines the object to use\n * @param tagsString defines the tags to remove\n */\n static RemoveTagsFrom(obj, tagsString) {\n if (!Tags.HasTags(obj)) {\n return;\n }\n const tags = tagsString.split(\" \");\n for (const t in tags) {\n Tags._RemoveTagFrom(obj, tags[t]);\n }\n }\n /**\n * @internal\n */\n static _RemoveTagFrom(obj, tag) {\n delete obj._tags[tag];\n }\n /**\n * Defines if tags hosted on an object match a given query\n * @param obj defines the object to use\n * @param tagsQuery defines the tag query\n * @returns a boolean\n */\n static MatchesQuery(obj, tagsQuery) {\n if (tagsQuery === undefined) {\n return true;\n }\n if (tagsQuery === \"\") {\n return Tags.HasTags(obj);\n }\n return AndOrNotEvaluator.Eval(tagsQuery, (r) => Tags.HasTags(obj) && obj._tags[r]);\n }\n }\n\n /**\n * Scalar computation library\n */\n class Scalar {\n /**\n * Boolean : true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)\n * @param a number\n * @param b number\n * @param epsilon (default = 1.401298E-45)\n * @returns true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)\n */\n static WithinEpsilon(a, b, epsilon = 1.401298e-45) {\n return Math.abs(a - b) <= epsilon;\n }\n /**\n * Returns a string : the upper case translation of the number i to hexadecimal.\n * @param i number\n * @returns the upper case translation of the number i to hexadecimal.\n */\n static ToHex(i) {\n const str = i.toString(16);\n if (i <= 15) {\n return (\"0\" + str).toUpperCase();\n }\n return str.toUpperCase();\n }\n /**\n * Returns -1 if value is negative and +1 is value is positive.\n * @param value the value\n * @returns the value itself if it's equal to zero.\n */\n static Sign(value) {\n value = +value; // convert to a number\n if (value === 0 || isNaN(value)) {\n return value;\n }\n return value > 0 ? 1 : -1;\n }\n /**\n * Returns the value itself if it's between min and max.\n * Returns min if the value is lower than min.\n * Returns max if the value is greater than max.\n * @param value the value to clmap\n * @param min the min value to clamp to (default: 0)\n * @param max the max value to clamp to (default: 1)\n * @returns the clamped value\n */\n static Clamp(value, min = 0, max = 1) {\n return Math.min(max, Math.max(min, value));\n }\n /**\n * the log2 of value.\n * @param value the value to compute log2 of\n * @returns the log2 of value.\n */\n static Log2(value) {\n return Math.log(value) * Math.LOG2E;\n }\n /**\n * the floor part of a log2 value.\n * @param value the value to compute log2 of\n * @returns the log2 of value.\n */\n static ILog2(value) {\n if (Math.log2) {\n return Math.floor(Math.log2(value));\n }\n if (value < 0) {\n return NaN;\n }\n else if (value === 0) {\n return -Infinity;\n }\n let n = 0;\n if (value < 1) {\n while (value < 1) {\n n++;\n value = value * 2;\n }\n n = -n;\n }\n else if (value > 1) {\n while (value > 1) {\n n++;\n value = Math.floor(value / 2);\n }\n }\n return n;\n }\n /**\n * Loops the value, so that it is never larger than length and never smaller than 0.\n *\n * This is similar to the modulo operator but it works with floating point numbers.\n * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.\n * With t = 5 and length = 2.5, the result would be 0.0.\n * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator\n * @param value the value\n * @param length the length\n * @returns the looped value\n */\n static Repeat(value, length) {\n return value - Math.floor(value / length) * length;\n }\n /**\n * Normalize the value between 0.0 and 1.0 using min and max values\n * @param value value to normalize\n * @param min max to normalize between\n * @param max min to normalize between\n * @returns the normalized value\n */\n static Normalize(value, min, max) {\n return (value - min) / (max - min);\n }\n /**\n * Denormalize the value from 0.0 and 1.0 using min and max values\n * @param normalized value to denormalize\n * @param min max to denormalize between\n * @param max min to denormalize between\n * @returns the denormalized value\n */\n static Denormalize(normalized, min, max) {\n return normalized * (max - min) + min;\n }\n /**\n * Calculates the shortest difference between two given angles given in degrees.\n * @param current current angle in degrees\n * @param target target angle in degrees\n * @returns the delta\n */\n static DeltaAngle(current, target) {\n let num = Scalar.Repeat(target - current, 360.0);\n if (num > 180.0) {\n num -= 360.0;\n }\n return num;\n }\n /**\n * PingPongs the value t, so that it is never larger than length and never smaller than 0.\n * @param tx value\n * @param length length\n * @returns The returned value will move back and forth between 0 and length\n */\n static PingPong(tx, length) {\n const t = Scalar.Repeat(tx, length * 2.0);\n return length - Math.abs(t - length);\n }\n /**\n * Interpolates between min and max with smoothing at the limits.\n *\n * This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up\n * from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.\n * @param from from\n * @param to to\n * @param tx value\n * @returns the smooth stepped value\n */\n static SmoothStep(from, to, tx) {\n let t = Scalar.Clamp(tx);\n t = -2.0 * t * t * t + 3.0 * t * t;\n return to * t + from * (1.0 - t);\n }\n /**\n * Moves a value current towards target.\n *\n * This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.\n * Negative values of maxDelta pushes the value away from target.\n * @param current current value\n * @param target target value\n * @param maxDelta max distance to move\n * @returns resulting value\n */\n static MoveTowards(current, target, maxDelta) {\n let result = 0;\n if (Math.abs(target - current) <= maxDelta) {\n result = target;\n }\n else {\n result = current + Scalar.Sign(target - current) * maxDelta;\n }\n return result;\n }\n /**\n * Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.\n *\n * Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta\n * are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.\n * @param current current value\n * @param target target value\n * @param maxDelta max distance to move\n * @returns resulting angle\n */\n static MoveTowardsAngle(current, target, maxDelta) {\n const num = Scalar.DeltaAngle(current, target);\n let result = 0;\n if (-maxDelta < num && num < maxDelta) {\n result = target;\n }\n else {\n target = current + num;\n result = Scalar.MoveTowards(current, target, maxDelta);\n }\n return result;\n }\n /**\n * Creates a new scalar with values linearly interpolated of \"amount\" between the start scalar and the end scalar.\n * @param start start value\n * @param end target value\n * @param amount amount to lerp between\n * @returns the lerped value\n */\n static Lerp(start, end, amount) {\n return start + (end - start) * amount;\n }\n /**\n * Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.\n * The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.\n * @param start start value\n * @param end target value\n * @param amount amount to lerp between\n * @returns the lerped value\n */\n static LerpAngle(start, end, amount) {\n let num = Scalar.Repeat(end - start, 360.0);\n if (num > 180.0) {\n num -= 360.0;\n }\n return start + num * Scalar.Clamp(amount);\n }\n /**\n * Calculates the linear parameter t that produces the interpolant value within the range [a, b].\n * @param a start value\n * @param b target value\n * @param value value between a and b\n * @returns the inverseLerp value\n */\n static InverseLerp(a, b, value) {\n let result = 0;\n if (a != b) {\n result = Scalar.Clamp((value - a) / (b - a));\n }\n else {\n result = 0.0;\n }\n return result;\n }\n /**\n * Returns a new scalar located for \"amount\" (float) on the Hermite spline defined by the scalars \"value1\", \"value3\", \"tangent1\", \"tangent2\".\n * @see http://mathworld.wolfram.com/HermitePolynomial.html\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param amount defines the amount on the interpolation spline (between 0 and 1)\n * @returns hermite result\n */\n static Hermite(value1, tangent1, value2, tangent2, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\n const part2 = -2.0 * cubed + 3.0 * squared;\n const part3 = cubed - 2.0 * squared + amount;\n const part4 = cubed - squared;\n return value1 * part1 + value2 * part2 + tangent1 * part3 + tangent2 * part4;\n }\n /**\n * Returns a new scalar which is the 1st derivative of the Hermite spline defined by the scalars \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @returns 1st derivative\n */\n static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {\n const t2 = time * time;\n return (t2 - time) * 6 * value1 + (3 * t2 - 4 * time + 1) * tangent1 + (-t2 + time) * 6 * value2 + (3 * t2 - 2 * time) * tangent2;\n }\n /**\n * Returns a random float number between and min and max values\n * @param min min value of random\n * @param max max value of random\n * @returns random value\n */\n static RandomRange(min, max) {\n if (min === max) {\n return min;\n }\n return Math.random() * (max - min) + min;\n }\n /**\n * This function returns percentage of a number in a given range.\n *\n * RangeToPercent(40,20,60) will return 0.5 (50%)\n * RangeToPercent(34,0,100) will return 0.34 (34%)\n * @param number to convert to percentage\n * @param min min range\n * @param max max range\n * @returns the percentage\n */\n static RangeToPercent(number, min, max) {\n return (number - min) / (max - min);\n }\n /**\n * This function returns number that corresponds to the percentage in a given range.\n *\n * PercentToRange(0.34,0,100) will return 34.\n * @param percent to convert to number\n * @param min min range\n * @param max max range\n * @returns the number\n */\n static PercentToRange(percent, min, max) {\n return (max - min) * percent + min;\n }\n /**\n * Returns the angle converted to equivalent value between -Math.PI and Math.PI radians.\n * @param angle The angle to normalize in radian.\n * @returns The converted angle.\n */\n static NormalizeRadians(angle) {\n // More precise but slower version kept for reference.\n // angle = angle % Tools.TwoPi;\n // angle = (angle + Tools.TwoPi) % Tools.TwoPi;\n //if (angle > Math.PI) {\n //\tangle -= Tools.TwoPi;\n //}\n angle -= Scalar.TwoPi * Math.floor((angle + Math.PI) / Scalar.TwoPi);\n return angle;\n }\n /**\n * Returns the highest common factor of two integers.\n * @param a first parameter\n * @param b second parameter\n * @returns HCF of a and b\n */\n static HCF(a, b) {\n const r = a % b;\n if (r === 0) {\n return b;\n }\n return Scalar.HCF(b, r);\n }\n }\n /**\n * Two pi constants convenient for computation.\n */\n Scalar.TwoPi = Math.PI * 2;\n\n /**\n * Constant used to convert a value to gamma space\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const ToGammaSpace = 1 / 2.2;\n /**\n * Constant used to convert a value to linear space\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const ToLinearSpace = 2.2;\n /**\n * Constant Golden Ratio value in Babylon.js\n * @ignorenaming\n */\n const PHI = (1 + Math.sqrt(5)) / 2;\n /**\n * Constant used to define the minimal number value in Babylon.js\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const Epsilon = 0.001;\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * Class containing a set of static utilities functions for arrays.\n */\n class ArrayTools {\n /**\n * Returns an array of the given size filled with elements built from the given constructor and the parameters.\n * @param size the number of element to construct and put in the array.\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.\n * @returns a new array filled with new objects.\n */\n static BuildArray(size, itemBuilder) {\n const a = [];\n for (let i = 0; i < size; ++i) {\n a.push(itemBuilder());\n }\n return a;\n }\n /**\n * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.\n * @param size he number of element to construct and put in the tuple.\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.\n * @returns a new tuple filled with new objects.\n */\n static BuildTuple(size, itemBuilder) {\n return ArrayTools.BuildArray(size, itemBuilder);\n }\n }\n /**\n * Observes a function and calls the given callback when it is called.\n * @param object Defines the object the function to observe belongs to.\n * @param functionName Defines the name of the function to observe.\n * @param callback Defines the callback to call when the function is called.\n * @returns A function to call to stop observing\n */\n function _observeArrayfunction(object, functionName, callback) {\n // Finds the function to observe\n const oldFunction = object[functionName];\n if (typeof oldFunction !== \"function\") {\n return null;\n }\n // Creates a new function that calls the callback and the old function\n const newFunction = function () {\n const previousLength = object.length;\n const returnValue = newFunction.previous.apply(object, arguments);\n callback(functionName, previousLength);\n return returnValue;\n };\n // Doublishly links the new function and the old function\n oldFunction.next = newFunction;\n newFunction.previous = oldFunction;\n // Replaces the old function with the new function\n object[functionName] = newFunction;\n // Returns a function to disable the hook\n return () => {\n // Only unhook if the function is still hooked\n const previous = newFunction.previous;\n if (!previous) {\n return;\n }\n // Finds the ref to the next function in the chain\n const next = newFunction.next;\n // If in the middle of the chain, link the previous and next functions\n if (next) {\n previous.next = next;\n next.previous = previous;\n }\n // If at the end of the chain, remove the reference to the previous function\n // and restore the previous function\n else {\n previous.next = undefined;\n object[functionName] = previous;\n }\n // Lose reference to the previous and next functions\n newFunction.next = undefined;\n newFunction.previous = undefined;\n };\n }\n /**\n * Defines the list of functions to proxy when observing an array.\n * The scope is currently reduced to the common functions used in the render target render list and the scene cameras.\n */\n const observedArrayFunctions = [\"push\", \"splice\", \"pop\", \"shift\", \"unshift\"];\n /**\n * Observes an array and notifies the given observer when the array is modified.\n * @param array Defines the array to observe\n * @param callback Defines the function to call when the array is modified (in the limit of the observed array functions)\n * @returns A function to call to stop observing the array\n * @internal\n */\n function _ObserveArray(array, callback) {\n // Observes all the required array functions and stores the unhook functions\n const unObserveFunctions = observedArrayFunctions.map((name) => {\n return _observeArrayfunction(array, name, callback);\n });\n // Returns a function that unhook all the observed functions\n return () => {\n unObserveFunctions.forEach((unObserveFunction) => {\n unObserveFunction === null || unObserveFunction === void 0 ? void 0 : unObserveFunction();\n });\n };\n }\n\n /** @internal */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const _RegisteredTypes = {};\n /**\n * @internal\n */\n function RegisterClass(className, type) {\n _RegisteredTypes[className] = type;\n }\n /**\n * @internal\n */\n function GetClass(fqdn) {\n return _RegisteredTypes[fqdn];\n }\n\n /** @internal */\n class PerformanceConfigurator {\n /**\n * @internal\n */\n static SetMatrixPrecision(use64bits) {\n PerformanceConfigurator.MatrixTrackPrecisionChange = false;\n if (use64bits && !PerformanceConfigurator.MatrixUse64Bits) {\n if (PerformanceConfigurator.MatrixTrackedMatrices) {\n for (let m = 0; m < PerformanceConfigurator.MatrixTrackedMatrices.length; ++m) {\n const matrix = PerformanceConfigurator.MatrixTrackedMatrices[m];\n const values = matrix._m;\n matrix._m = new Array(16);\n for (let i = 0; i < 16; ++i) {\n matrix._m[i] = values[i];\n }\n }\n }\n }\n PerformanceConfigurator.MatrixUse64Bits = use64bits;\n PerformanceConfigurator.MatrixCurrentType = PerformanceConfigurator.MatrixUse64Bits ? Array : Float32Array;\n PerformanceConfigurator.MatrixTrackedMatrices = null; // reclaim some memory, as we don't need _TrackedMatrices anymore\n }\n }\n /** @internal */\n PerformanceConfigurator.MatrixUse64Bits = false;\n /** @internal */\n PerformanceConfigurator.MatrixTrackPrecisionChange = true;\n /** @internal */\n PerformanceConfigurator.MatrixCurrentType = Float32Array;\n /** @internal */\n PerformanceConfigurator.MatrixTrackedMatrices = [];\n\n /**\n * A class serves as a medium between the observable and its observers\n */\n class EventState {\n /**\n * Create a new EventState\n * @param mask defines the mask associated with this state\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\n * @param target defines the original target of the state\n * @param currentTarget defines the current target of the state\n */\n constructor(mask, skipNextObservers = false, target, currentTarget) {\n this.initialize(mask, skipNextObservers, target, currentTarget);\n }\n /**\n * Initialize the current event state\n * @param mask defines the mask associated with this state\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\n * @param target defines the original target of the state\n * @param currentTarget defines the current target of the state\n * @returns the current event state\n */\n initialize(mask, skipNextObservers = false, target, currentTarget) {\n this.mask = mask;\n this.skipNextObservers = skipNextObservers;\n this.target = target;\n this.currentTarget = currentTarget;\n return this;\n }\n }\n /**\n * Represent an Observer registered to a given Observable object.\n */\n class Observer {\n /**\n * Creates a new observer\n * @param callback defines the callback to call when the observer is notified\n * @param mask defines the mask of the observer (used to filter notifications)\n * @param scope defines the current scope used to restore the JS context\n */\n constructor(\n /**\n * Defines the callback to call when the observer is notified\n */\n callback, \n /**\n * Defines the mask of the observer (used to filter notifications)\n */\n mask, \n /**\n * Defines the current scope used to restore the JS context\n */\n scope = null) {\n this.callback = callback;\n this.mask = mask;\n this.scope = scope;\n /** @internal */\n this._willBeUnregistered = false;\n /**\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\n */\n this.unregisterOnNextCall = false;\n /**\n * this function can be used to remove the observer from the observable.\n * It will be set by the observable that the observer belongs to.\n * @internal\n */\n this._remove = null;\n }\n /**\n * Remove the observer from its observable\n * This can be used instead of using the observable's remove function.\n */\n remove() {\n if (this._remove) {\n this._remove();\n }\n }\n }\n /**\n * The Observable class is a simple implementation of the Observable pattern.\n *\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\n * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.\n */\n class Observable$1 {\n /**\n * Create an observable from a Promise.\n * @param promise a promise to observe for fulfillment.\n * @param onErrorObservable an observable to notify if a promise was rejected.\n * @returns the new Observable\n */\n static FromPromise(promise, onErrorObservable) {\n const observable = new Observable$1();\n promise\n .then((ret) => {\n observable.notifyObservers(ret);\n })\n .catch((err) => {\n if (onErrorObservable) {\n onErrorObservable.notifyObservers(err);\n }\n else {\n throw err;\n }\n });\n return observable;\n }\n /**\n * Gets the list of observers\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\n */\n get observers() {\n return this._observers;\n }\n /**\n * Creates a new observable\n * @param onObserverAdded defines a callback to call when a new observer is added\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\n */\n constructor(onObserverAdded, \n /**\n * If set to true the observable will notify when an observer was added if the observable was already triggered.\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\n */\n notifyIfTriggered = false) {\n this.notifyIfTriggered = notifyIfTriggered;\n this._observers = new Array();\n this._numObserversMarkedAsDeleted = 0;\n this._hasNotified = false;\n this._eventState = new EventState(0);\n if (onObserverAdded) {\n this._onObserverAdded = onObserverAdded;\n }\n }\n /**\n * Create a new Observer with the specified callback\n * @param callback the callback that will be executed for that Observer\n * @param mask the mask used to filter observers\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\n * @param scope optional scope for the callback to be called from\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\n * @returns the new observer created for the callback\n */\n add(callback, mask = -1, insertFirst = false, scope = null, unregisterOnFirstCall = false) {\n if (!callback) {\n return null;\n }\n const observer = new Observer(callback, mask, scope);\n observer.unregisterOnNextCall = unregisterOnFirstCall;\n if (insertFirst) {\n this._observers.unshift(observer);\n }\n else {\n this._observers.push(observer);\n }\n if (this._onObserverAdded) {\n this._onObserverAdded(observer);\n }\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\n if (this._hasNotified && this.notifyIfTriggered) {\n if (this._lastNotifiedValue !== undefined) {\n this.notifyObserver(observer, this._lastNotifiedValue);\n }\n }\n // attach the remove function to the observer\n observer._remove = () => {\n this.remove(observer);\n };\n return observer;\n }\n /**\n * Create a new Observer with the specified callback and unregisters after the next notification\n * @param callback the callback that will be executed for that Observer\n * @returns the new observer created for the callback\n */\n addOnce(callback) {\n return this.add(callback, undefined, undefined, undefined, true);\n }\n /**\n * Remove an Observer from the Observable object\n * @param observer the instance of the Observer to remove\n * @returns false if it doesn't belong to this Observable\n */\n remove(observer) {\n if (!observer) {\n return false;\n }\n observer._remove = null;\n const index = this._observers.indexOf(observer);\n if (index !== -1) {\n this._deferUnregister(observer);\n return true;\n }\n return false;\n }\n /**\n * Remove a callback from the Observable object\n * @param callback the callback to remove\n * @param scope optional scope. If used only the callbacks with this scope will be removed\n * @returns false if it doesn't belong to this Observable\n */\n removeCallback(callback, scope) {\n for (let index = 0; index < this._observers.length; index++) {\n const observer = this._observers[index];\n if (observer._willBeUnregistered) {\n continue;\n }\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\n this._deferUnregister(observer);\n return true;\n }\n }\n return false;\n }\n /**\n * @internal\n */\n _deferUnregister(observer) {\n if (observer._willBeUnregistered) {\n return;\n }\n this._numObserversMarkedAsDeleted++;\n observer.unregisterOnNextCall = false;\n observer._willBeUnregistered = true;\n setTimeout(() => {\n this._remove(observer);\n }, 0);\n }\n // This should only be called when not iterating over _observers to avoid callback skipping.\n // Removes an observer from the _observer Array.\n _remove(observer, updateCounter = true) {\n if (!observer) {\n return false;\n }\n const index = this._observers.indexOf(observer);\n if (index !== -1) {\n if (updateCounter) {\n this._numObserversMarkedAsDeleted--;\n }\n this._observers.splice(index, 1);\n return true;\n }\n return false;\n }\n /**\n * Moves the observable to the top of the observer list making it get called first when notified\n * @param observer the observer to move\n */\n makeObserverTopPriority(observer) {\n this._remove(observer, false);\n this._observers.unshift(observer);\n }\n /**\n * Moves the observable to the bottom of the observer list making it get called last when notified\n * @param observer the observer to move\n */\n makeObserverBottomPriority(observer) {\n this._remove(observer, false);\n this._observers.push(observer);\n }\n /**\n * Notify all Observers by calling their respective callback with the given data\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\n * @param eventData defines the data to send to all observers\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\n * @param target defines the original target of the state\n * @param currentTarget defines the current target of the state\n * @param userInfo defines any user info to send to observers\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\n */\n notifyObservers(eventData, mask = -1, target, currentTarget, userInfo) {\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\n if (this.notifyIfTriggered) {\n this._hasNotified = true;\n this._lastNotifiedValue = eventData;\n }\n if (!this._observers.length) {\n return true;\n }\n const state = this._eventState;\n state.mask = mask;\n state.target = target;\n state.currentTarget = currentTarget;\n state.skipNextObservers = false;\n state.lastReturnValue = eventData;\n state.userInfo = userInfo;\n for (const obs of this._observers) {\n if (obs._willBeUnregistered) {\n continue;\n }\n if (obs.mask & mask) {\n if (obs.unregisterOnNextCall) {\n this._deferUnregister(obs);\n }\n if (obs.scope) {\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\n }\n else {\n state.lastReturnValue = obs.callback(eventData, state);\n }\n }\n if (state.skipNextObservers) {\n return false;\n }\n }\n return true;\n }\n /**\n * Notify a specific observer\n * @param observer defines the observer to notify\n * @param eventData defines the data to be sent to each callback\n * @param mask is used to filter observers defaults to -1\n */\n notifyObserver(observer, eventData, mask = -1) {\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\n if (this.notifyIfTriggered) {\n this._hasNotified = true;\n this._lastNotifiedValue = eventData;\n }\n if (observer._willBeUnregistered) {\n return;\n }\n const state = this._eventState;\n state.mask = mask;\n state.skipNextObservers = false;\n if (observer.unregisterOnNextCall) {\n this._deferUnregister(observer);\n }\n observer.callback(eventData, state);\n }\n /**\n * Gets a boolean indicating if the observable has at least one observer\n * @returns true is the Observable has at least one Observer registered\n */\n hasObservers() {\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\n }\n /**\n * Clear the list of observers\n */\n clear() {\n while (this._observers.length) {\n const o = this._observers.pop();\n if (o) {\n o._remove = null;\n }\n }\n this._onObserverAdded = null;\n this._numObserversMarkedAsDeleted = 0;\n this.cleanLastNotifiedState();\n }\n /**\n * Clean the last notified state - both the internal last value and the has-notified flag\n */\n cleanLastNotifiedState() {\n this._hasNotified = false;\n this._lastNotifiedValue = undefined;\n }\n /**\n * Clone the current observable\n * @returns a new observable\n */\n clone() {\n const result = new Observable$1();\n result._observers = this._observers.slice(0);\n return result;\n }\n /**\n * Does this observable handles observer registered with a given mask\n * @param mask defines the mask to be tested\n * @returns whether or not one observer registered with the given mask is handled\n **/\n hasSpecificMask(mask = -1) {\n for (const obs of this._observers) {\n if (obs.mask & mask || obs.mask === mask) {\n return true;\n }\n }\n return false;\n }\n }\n\n /**\n * The engine store class is responsible to hold all the instances of Engine and Scene created\n * during the life time of the application.\n */\n class EngineStore {\n /**\n * Gets the latest created engine\n */\n static get LastCreatedEngine() {\n if (this.Instances.length === 0) {\n return null;\n }\n return this.Instances[this.Instances.length - 1];\n }\n /**\n * Gets the latest created scene\n */\n static get LastCreatedScene() {\n return this._LastCreatedScene;\n }\n }\n /** Gets the list of created engines */\n EngineStore.Instances = new Array();\n /**\n * Notifies when an engine was disposed.\n * Mainly used for static/cache cleanup\n */\n EngineStore.OnEnginesDisposedObservable = new Observable$1();\n /** @internal */\n EngineStore._LastCreatedScene = null;\n /**\n * Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded\n * @ignorenaming\n */\n EngineStore.UseFallbackTexture = true;\n /**\n * Texture content used if a texture cannot loaded\n * @ignorenaming\n */\n EngineStore.FallbackTexture = \"\";\n\n /* eslint-disable @typescript-eslint/naming-convention */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const _ExtractAsInt = (value) => {\n return parseInt(value.toString().replace(/\\W/g, \"\"));\n };\n /**\n * Class representing a vector containing 2 coordinates\n * Example Playground - Overview - https://playground.babylonjs.com/#QYBWV4#9\n */\n class Vector2 {\n /**\n * Creates a new Vector2 from the given x and y coordinates\n * @param x defines the first coordinate\n * @param y defines the second coordinate\n */\n constructor(\n /** defines the first coordinate */\n x = 0, \n /** defines the second coordinate */\n y = 0) {\n this.x = x;\n this.y = y;\n }\n /**\n * Gets a string with the Vector2 coordinates\n * @returns a string with the Vector2 coordinates\n */\n toString() {\n return `{X: ${this.x} Y: ${this.y}}`;\n }\n /**\n * Gets class name\n * @returns the string \"Vector2\"\n */\n getClassName() {\n return \"Vector2\";\n }\n /**\n * Gets current vector hash code\n * @returns the Vector2 hash code as a number\n */\n getHashCode() {\n const x = _ExtractAsInt(this.x);\n const y = _ExtractAsInt(this.y);\n let hash = x;\n hash = (hash * 397) ^ y;\n return hash;\n }\n // Operators\n /**\n * Sets the Vector2 coordinates in the given array or Float32Array from the given index.\n * Example Playground https://playground.babylonjs.com/#QYBWV4#15\n * @param array defines the source array\n * @param index defines the offset in source array\n * @returns the current Vector2\n */\n toArray(array, index = 0) {\n array[index] = this.x;\n array[index + 1] = this.y;\n return this;\n }\n /**\n * Update the current vector from an array\n * Example Playground https://playground.babylonjs.com/#QYBWV4#39\n * @param array defines the destination array\n * @param index defines the offset in the destination array\n * @returns the current Vector2\n */\n fromArray(array, index = 0) {\n Vector2.FromArrayToRef(array, index, this);\n return this;\n }\n /**\n * Copy the current vector to an array\n * Example Playground https://playground.babylonjs.com/#QYBWV4#40\n * @returns a new array with 2 elements: the Vector2 coordinates.\n */\n asArray() {\n const result = new Array();\n this.toArray(result, 0);\n return result;\n }\n /**\n * Sets the Vector2 coordinates with the given Vector2 coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#24\n * @param source defines the source Vector2\n * @returns the current updated Vector2\n */\n copyFrom(source) {\n this.x = source.x;\n this.y = source.y;\n return this;\n }\n /**\n * Sets the Vector2 coordinates with the given floats\n * Example Playground https://playground.babylonjs.com/#QYBWV4#25\n * @param x defines the first coordinate\n * @param y defines the second coordinate\n * @returns the current updated Vector2\n */\n copyFromFloats(x, y) {\n this.x = x;\n this.y = y;\n return this;\n }\n /**\n * Sets the Vector2 coordinates with the given floats\n * Example Playground https://playground.babylonjs.com/#QYBWV4#62\n * @param x defines the first coordinate\n * @param y defines the second coordinate\n * @returns the current updated Vector2\n */\n set(x, y) {\n return this.copyFromFloats(x, y);\n }\n /**\n * Add another vector with the current one\n * Example Playground https://playground.babylonjs.com/#QYBWV4#11\n * @param otherVector defines the other vector\n * @returns a new Vector2 set with the addition of the current Vector2 and the given one coordinates\n */\n add(otherVector) {\n return new this.constructor(this.x + otherVector.x, this.y + otherVector.y);\n }\n /**\n * Sets the \"result\" coordinates with the addition of the current Vector2 and the given one coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#12\n * @param otherVector defines the other vector\n * @param result defines the target vector\n * @returns result input\n */\n addToRef(otherVector, result) {\n result.x = this.x + otherVector.x;\n result.y = this.y + otherVector.y;\n return result;\n }\n /**\n * Set the Vector2 coordinates by adding the given Vector2 coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#13\n * @param otherVector defines the other vector\n * @returns the current updated Vector2\n */\n addInPlace(otherVector) {\n this.x += otherVector.x;\n this.y += otherVector.y;\n return this;\n }\n /**\n * Gets a new Vector2 by adding the current Vector2 coordinates to the given Vector3 x, y coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#14\n * @param otherVector defines the other vector\n * @returns a new Vector2\n */\n addVector3(otherVector) {\n return new this.constructor(this.x + otherVector.x, this.y + otherVector.y);\n }\n /**\n * Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2\n * Example Playground https://playground.babylonjs.com/#QYBWV4#61\n * @param otherVector defines the other vector\n * @returns a new Vector2\n */\n subtract(otherVector) {\n return new this.constructor(this.x - otherVector.x, this.y - otherVector.y);\n }\n /**\n * Sets the \"result\" coordinates with the subtraction of the given one from the current Vector2 coordinates.\n * Example Playground https://playground.babylonjs.com/#QYBWV4#63\n * @param otherVector defines the other vector\n * @param result defines the target vector\n * @returns result input\n */\n subtractToRef(otherVector, result) {\n result.x = this.x - otherVector.x;\n result.y = this.y - otherVector.y;\n return result;\n }\n /**\n * Sets the current Vector2 coordinates by subtracting from it the given one coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#88\n * @param otherVector defines the other vector\n * @returns the current updated Vector2\n */\n subtractInPlace(otherVector) {\n this.x -= otherVector.x;\n this.y -= otherVector.y;\n return this;\n }\n /**\n * Multiplies in place the current Vector2 coordinates by the given ones\n * Example Playground https://playground.babylonjs.com/#QYBWV4#43\n * @param otherVector defines the other vector\n * @returns the current updated Vector2\n */\n multiplyInPlace(otherVector) {\n this.x *= otherVector.x;\n this.y *= otherVector.y;\n return this;\n }\n /**\n * Returns a new Vector2 set with the multiplication of the current Vector2 and the given one coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#42\n * @param otherVector defines the other vector\n * @returns a new Vector2\n */\n multiply(otherVector) {\n return new this.constructor(this.x * otherVector.x, this.y * otherVector.y);\n }\n /**\n * Sets \"result\" coordinates with the multiplication of the current Vector2 and the given one coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#44\n * @param otherVector defines the other vector\n * @param result defines the target vector\n * @returns result input\n */\n multiplyToRef(otherVector, result) {\n result.x = this.x * otherVector.x;\n result.y = this.y * otherVector.y;\n return result;\n }\n /**\n * Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats\n * Example Playground https://playground.babylonjs.com/#QYBWV4#89\n * @param x defines the first coordinate\n * @param y defines the second coordinate\n * @returns a new Vector2\n */\n multiplyByFloats(x, y) {\n return new this.constructor(this.x * x, this.y * y);\n }\n /**\n * Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#27\n * @param otherVector defines the other vector\n * @returns a new Vector2\n */\n divide(otherVector) {\n return new this.constructor(this.x / otherVector.x, this.y / otherVector.y);\n }\n /**\n * Sets the \"result\" coordinates with the Vector2 divided by the given one coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#30\n * @param otherVector defines the other vector\n * @param result defines the target vector\n * @returns result input\n */\n divideToRef(otherVector, result) {\n result.x = this.x / otherVector.x;\n result.y = this.y / otherVector.y;\n return result;\n }\n /**\n * Divides the current Vector2 coordinates by the given ones\n * Example Playground https://playground.babylonjs.com/#QYBWV4#28\n * @param otherVector defines the other vector\n * @returns the current updated Vector2\n */\n divideInPlace(otherVector) {\n return this.divideToRef(otherVector, this);\n }\n /**\n * Gets a new Vector2 with current Vector2 negated coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#22\n * @returns a new Vector2\n */\n negate() {\n return new this.constructor(-this.x, -this.y);\n }\n /**\n * Negate this vector in place\n * Example Playground https://playground.babylonjs.com/#QYBWV4#23\n * @returns this\n */\n negateInPlace() {\n this.x *= -1;\n this.y *= -1;\n return this;\n }\n /**\n * Negate the current Vector2 and stores the result in the given vector \"result\" coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#41\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n negateToRef(result) {\n return result.copyFromFloats(this.x * -1, this.y * -1);\n }\n /**\n * Multiply the Vector2 coordinates by\n * Example Playground https://playground.babylonjs.com/#QYBWV4#59\n * @param scale defines the scaling factor\n * @returns the current updated Vector2\n */\n scaleInPlace(scale) {\n this.x *= scale;\n this.y *= scale;\n return this;\n }\n /**\n * Returns a new Vector2 scaled by \"scale\" from the current Vector2\n * Example Playground https://playground.babylonjs.com/#QYBWV4#52\n * @param scale defines the scaling factor\n * @returns a new Vector2\n */\n scale(scale) {\n const result = new this.constructor(0, 0);\n this.scaleToRef(scale, result);\n return result;\n }\n /**\n * Scale the current Vector2 values by a factor to a given Vector2\n * Example Playground https://playground.babylonjs.com/#QYBWV4#57\n * @param scale defines the scale factor\n * @param result defines the Vector2 object where to store the result\n * @returns result input\n */\n scaleToRef(scale, result) {\n result.x = this.x * scale;\n result.y = this.y * scale;\n return result;\n }\n /**\n * Scale the current Vector2 values by a factor and add the result to a given Vector2\n * Example Playground https://playground.babylonjs.com/#QYBWV4#58\n * @param scale defines the scale factor\n * @param result defines the Vector2 object where to store the result\n * @returns result input\n */\n scaleAndAddToRef(scale, result) {\n result.x += this.x * scale;\n result.y += this.y * scale;\n return result;\n }\n /**\n * Gets a boolean if two vectors are equals\n * Example Playground https://playground.babylonjs.com/#QYBWV4#31\n * @param otherVector defines the other vector\n * @returns true if the given vector coordinates strictly equal the current Vector2 ones\n */\n equals(otherVector) {\n return otherVector && this.x === otherVector.x && this.y === otherVector.y;\n }\n /**\n * Gets a boolean if two vectors are equals (using an epsilon value)\n * Example Playground https://playground.babylonjs.com/#QYBWV4#32\n * @param otherVector defines the other vector\n * @param epsilon defines the minimal distance to consider equality\n * @returns true if the given vector coordinates are close to the current ones by a distance of epsilon.\n */\n equalsWithEpsilon(otherVector, epsilon = Epsilon) {\n return otherVector && Scalar.WithinEpsilon(this.x, otherVector.x, epsilon) && Scalar.WithinEpsilon(this.y, otherVector.y, epsilon);\n }\n /**\n * Gets a new Vector2 from current Vector2 floored values\n * Example Playground https://playground.babylonjs.com/#QYBWV4#35\n * eg (1.2, 2.31) returns (1, 2)\n * @returns a new Vector2\n */\n floor() {\n return new this.constructor(Math.floor(this.x), Math.floor(this.y));\n }\n /**\n * Gets a new Vector2 from current Vector2 fractional values\n * Example Playground https://playground.babylonjs.com/#QYBWV4#34\n * eg (1.2, 2.31) returns (0.2, 0.31)\n * @returns a new Vector2\n */\n fract() {\n return new this.constructor(this.x - Math.floor(this.x), this.y - Math.floor(this.y));\n }\n /**\n * Rotate the current vector into a given result vector\n * Example Playground https://playground.babylonjs.com/#QYBWV4#49\n * @param angle defines the rotation angle\n * @param result defines the result vector where to store the rotated vector\n * @returns result input\n */\n rotateToRef(angle, result) {\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n const x = cos * this.x - sin * this.y;\n const y = sin * this.x + cos * this.y;\n result.x = x;\n result.y = y;\n return result;\n }\n // Properties\n /**\n * Gets the length of the vector\n * @returns the vector length (float)\n */\n length() {\n return Math.sqrt(this.x * this.x + this.y * this.y);\n }\n /**\n * Gets the vector squared length\n * @returns the vector squared length (float)\n */\n lengthSquared() {\n return this.x * this.x + this.y * this.y;\n }\n // Methods\n /**\n * Normalize the vector\n * Example Playground https://playground.babylonjs.com/#QYBWV4#48\n * @returns the current updated Vector2\n */\n normalize() {\n Vector2.NormalizeToRef(this, this);\n return this;\n }\n /**\n * Gets a new Vector2 copied from the Vector2\n * Example Playground https://playground.babylonjs.com/#QYBWV4#20\n * @returns a new Vector2\n */\n clone() {\n return new this.constructor(this.x, this.y);\n }\n // Statics\n /**\n * Gets a new Vector2(0, 0)\n * @returns a new Vector2\n */\n static Zero() {\n return new Vector2(0, 0);\n }\n /**\n * Gets a new Vector2(1, 1)\n * @returns a new Vector2\n */\n static One() {\n return new Vector2(1, 1);\n }\n /**\n * Returns a new Vector2 with random values between min and max\n * @param min the minimum random value\n * @param max the maximum random value\n * @returns a Vector2 with random values between min and max\n */\n static Random(min = 0, max = 1) {\n return new Vector2(Scalar.RandomRange(min, max), Scalar.RandomRange(min, max));\n }\n /**\n * Gets a zero Vector2 that must not be updated\n */\n static get ZeroReadOnly() {\n return Vector2._ZeroReadOnly;\n }\n /**\n * Gets a new Vector2 set from the given index element of the given array\n * Example Playground https://playground.babylonjs.com/#QYBWV4#79\n * @param array defines the data source\n * @param offset defines the offset in the data source\n * @returns a new Vector2\n */\n static FromArray(array, offset = 0) {\n return new Vector2(array[offset], array[offset + 1]);\n }\n /**\n * Sets \"result\" from the given index element of the given array\n * Example Playground https://playground.babylonjs.com/#QYBWV4#80\n * @param array defines the data source\n * @param offset defines the offset in the data source\n * @param result defines the target vector\n * @returns result input\n */\n static FromArrayToRef(array, offset, result) {\n result.x = array[offset];\n result.y = array[offset + 1];\n return result;\n }\n /**\n * Gets a new Vector2 located for \"amount\" (float) on the CatmullRom spline defined by the given four Vector2\n * Example Playground https://playground.babylonjs.com/#QYBWV4#65\n * @param value1 defines 1st point of control\n * @param value2 defines 2nd point of control\n * @param value3 defines 3rd point of control\n * @param value4 defines 4th point of control\n * @param amount defines the interpolation factor\n * @returns a new Vector2\n */\n static CatmullRom(value1, value2, value3, value4, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const x = 0.5 *\n (2.0 * value2.x +\n (-value1.x + value3.x) * amount +\n (2.0 * value1.x - 5.0 * value2.x + 4.0 * value3.x - value4.x) * squared +\n (-value1.x + 3.0 * value2.x - 3.0 * value3.x + value4.x) * cubed);\n const y = 0.5 *\n (2.0 * value2.y +\n (-value1.y + value3.y) * amount +\n (2.0 * value1.y - 5.0 * value2.y + 4.0 * value3.y - value4.y) * squared +\n (-value1.y + 3.0 * value2.y - 3.0 * value3.y + value4.y) * cubed);\n return new value1.constructor(x, y);\n }\n /**\n * Returns a new Vector2 set with same the coordinates than \"value\" ones if the vector \"value\" is in the square defined by \"min\" and \"max\".\n * If a coordinate of \"value\" is lower than \"min\" coordinates, the returned Vector2 is given this \"min\" coordinate.\n * If a coordinate of \"value\" is greater than \"max\" coordinates, the returned Vector2 is given this \"max\" coordinate\n * Example Playground https://playground.babylonjs.com/#QYBWV4#76\n * @param value defines the value to clamp\n * @param min defines the lower limit\n * @param max defines the upper limit\n * @returns a new Vector2\n */\n static Clamp(value, min, max) {\n let x = value.x;\n x = x > max.x ? max.x : x;\n x = x < min.x ? min.x : x;\n let y = value.y;\n y = y > max.y ? max.y : y;\n y = y < min.y ? min.y : y;\n return new value.constructor(x, y);\n }\n /**\n * Returns a new Vector2 located for \"amount\" (float) on the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\"\n * Example Playground https://playground.babylonjs.com/#QYBWV4#81\n * @param value1 defines the 1st control point\n * @param tangent1 defines the outgoing tangent\n * @param value2 defines the 2nd control point\n * @param tangent2 defines the incoming tangent\n * @param amount defines the interpolation factor\n * @returns a new Vector2\n */\n static Hermite(value1, tangent1, value2, tangent2, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\n const part2 = -2.0 * cubed + 3.0 * squared;\n const part3 = cubed - 2.0 * squared + amount;\n const part4 = cubed - squared;\n const x = value1.x * part1 + value2.x * part2 + tangent1.x * part3 + tangent2.x * part4;\n const y = value1.y * part1 + value2.y * part2 + tangent1.y * part3 + tangent2.y * part4;\n return new value1.constructor(x, y);\n }\n /**\n * Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * Example Playground https://playground.babylonjs.com/#QYBWV4#82\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @returns 1st derivative\n */\n static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {\n const result = new value1.constructor();\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\n return result;\n }\n /**\n * Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * Example Playground https://playground.babylonjs.com/#QYBWV4#83\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @param result define where the derivative will be stored\n * @returns result input\n */\n static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {\n const t2 = time * time;\n result.x = (t2 - time) * 6 * value1.x + (3 * t2 - 4 * time + 1) * tangent1.x + (-t2 + time) * 6 * value2.x + (3 * t2 - 2 * time) * tangent2.x;\n result.y = (t2 - time) * 6 * value1.y + (3 * t2 - 4 * time + 1) * tangent1.y + (-t2 + time) * 6 * value2.y + (3 * t2 - 2 * time) * tangent2.y;\n return result;\n }\n /**\n * Returns a new Vector2 located for \"amount\" (float) on the linear interpolation between the vector \"start\" adn the vector \"end\".\n * Example Playground https://playground.babylonjs.com/#QYBWV4#84\n * @param start defines the start vector\n * @param end defines the end vector\n * @param amount defines the interpolation factor\n * @returns a new Vector2\n */\n static Lerp(start, end, amount) {\n const x = start.x + (end.x - start.x) * amount;\n const y = start.y + (end.y - start.y) * amount;\n return new start.constructor(x, y);\n }\n /**\n * Gets the dot product of the vector \"left\" and the vector \"right\"\n * Example Playground https://playground.babylonjs.com/#QYBWV4#90\n * @param left defines first vector\n * @param right defines second vector\n * @returns the dot product (float)\n */\n static Dot(left, right) {\n return left.x * right.x + left.y * right.y;\n }\n /**\n * Returns a new Vector2 equal to the normalized given vector\n * Example Playground https://playground.babylonjs.com/#QYBWV4#46\n * @param vector defines the vector to normalize\n * @returns a new Vector2\n */\n static Normalize(vector) {\n const newVector = new vector.constructor();\n this.NormalizeToRef(vector, newVector);\n return newVector;\n }\n /**\n * Normalize a given vector into a second one\n * Example Playground https://playground.babylonjs.com/#QYBWV4#50\n * @param vector defines the vector to normalize\n * @param result defines the vector where to store the result\n * @returns result input\n */\n static NormalizeToRef(vector, result) {\n const len = vector.length();\n if (len === 0) {\n return result;\n }\n result.x = vector.x / len;\n result.y = vector.y / len;\n return result;\n }\n /**\n * Gets a new Vector2 set with the minimal coordinate values from the \"left\" and \"right\" vectors\n * Example Playground https://playground.babylonjs.com/#QYBWV4#86\n * @param left defines 1st vector\n * @param right defines 2nd vector\n * @returns a new Vector2\n */\n static Minimize(left, right) {\n const x = left.x < right.x ? left.x : right.x;\n const y = left.y < right.y ? left.y : right.y;\n return new left.constructor(x, y);\n }\n /**\n * Gets a new Vector2 set with the maximal coordinate values from the \"left\" and \"right\" vectors\n * Example Playground https://playground.babylonjs.com/#QYBWV4#86\n * @param left defines 1st vector\n * @param right defines 2nd vector\n * @returns a new Vector2\n */\n static Maximize(left, right) {\n const x = left.x > right.x ? left.x : right.x;\n const y = left.y > right.y ? left.y : right.y;\n return new left.constructor(x, y);\n }\n /**\n * Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix\n * Example Playground https://playground.babylonjs.com/#QYBWV4#17\n * @param vector defines the vector to transform\n * @param transformation defines the matrix to apply\n * @returns a new Vector2\n */\n static Transform(vector, transformation) {\n const result = new vector.constructor();\n Vector2.TransformToRef(vector, transformation, result);\n return result;\n }\n /**\n * Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector \"result\" coordinates\n * Example Playground https://playground.babylonjs.com/#QYBWV4#19\n * @param vector defines the vector to transform\n * @param transformation defines the matrix to apply\n * @param result defines the target vector\n * @returns result input\n */\n static TransformToRef(vector, transformation, result) {\n const m = transformation.m;\n const x = vector.x * m[0] + vector.y * m[4] + m[12];\n const y = vector.x * m[1] + vector.y * m[5] + m[13];\n result.x = x;\n result.y = y;\n return result;\n }\n /**\n * Determines if a given vector is included in a triangle\n * Example Playground https://playground.babylonjs.com/#QYBWV4#87\n * @param p defines the vector to test\n * @param p0 defines 1st triangle point\n * @param p1 defines 2nd triangle point\n * @param p2 defines 3rd triangle point\n * @returns true if the point \"p\" is in the triangle defined by the vectors \"p0\", \"p1\", \"p2\"\n */\n static PointInTriangle(p, p0, p1, p2) {\n const a = (1 / 2) * (-p1.y * p2.x + p0.y * (-p1.x + p2.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y);\n const sign = a < 0 ? -1 : 1;\n const s = (p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y) * sign;\n const t = (p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y) * sign;\n return s > 0 && t > 0 && s + t < 2 * a * sign;\n }\n /**\n * Gets the distance between the vectors \"value1\" and \"value2\"\n * Example Playground https://playground.babylonjs.com/#QYBWV4#71\n * @param value1 defines first vector\n * @param value2 defines second vector\n * @returns the distance between vectors\n */\n static Distance(value1, value2) {\n return Math.sqrt(Vector2.DistanceSquared(value1, value2));\n }\n /**\n * Returns the squared distance between the vectors \"value1\" and \"value2\"\n * Example Playground https://playground.babylonjs.com/#QYBWV4#72\n * @param value1 defines first vector\n * @param value2 defines second vector\n * @returns the squared distance between vectors\n */\n static DistanceSquared(value1, value2) {\n const x = value1.x - value2.x;\n const y = value1.y - value2.y;\n return x * x + y * y;\n }\n /**\n * Gets a new Vector2 located at the center of the vectors \"value1\" and \"value2\"\n * Example Playground https://playground.babylonjs.com/#QYBWV4#86\n * Example Playground https://playground.babylonjs.com/#QYBWV4#66\n * @param value1 defines first vector\n * @param value2 defines second vector\n * @returns a new Vector2\n */\n static Center(value1, value2) {\n const result = new value1.constructor();\n return Vector2.CenterToRef(value1, value2, result);\n }\n /**\n * Gets the center of the vectors \"value1\" and \"value2\" and stores the result in the vector \"ref\"\n * Example Playground https://playground.babylonjs.com/#QYBWV4#66\n * @param value1 defines first vector\n * @param value2 defines second vector\n * @param ref defines third vector\n * @returns ref\n */\n static CenterToRef(value1, value2, ref) {\n return ref.copyFromFloats((value1.x + value2.x) / 2, (value1.y + value2.y) / 2);\n }\n /**\n * Gets the shortest distance (float) between the point \"p\" and the segment defined by the two points \"segA\" and \"segB\".\n * Example Playground https://playground.babylonjs.com/#QYBWV4#77\n * @param p defines the middle point\n * @param segA defines one point of the segment\n * @param segB defines the other point of the segment\n * @returns the shortest distance\n */\n static DistanceOfPointFromSegment(p, segA, segB) {\n const l2 = Vector2.DistanceSquared(segA, segB);\n if (l2 === 0.0) {\n return Vector2.Distance(p, segA);\n }\n const v = segB.subtract(segA);\n const t = Math.max(0, Math.min(1, Vector2.Dot(p.subtract(segA), v) / l2));\n const proj = segA.add(v.multiplyByFloats(t, t));\n return Vector2.Distance(p, proj);\n }\n }\n Vector2._ZeroReadOnly = Vector2.Zero();\n /**\n * Class used to store (x,y,z) vector representation\n * A Vector3 is the main object used in 3D geometry\n * It can represent either the coordinates of a point the space, either a direction\n * Reminder: js uses a left handed forward facing system\n * Example Playground - Overview - https://playground.babylonjs.com/#R1F8YU\n */\n class Vector3 {\n /** Gets or sets the x coordinate */\n get x() {\n return this._x;\n }\n set x(value) {\n this._x = value;\n this._isDirty = true;\n }\n /** Gets or sets the y coordinate */\n get y() {\n return this._y;\n }\n set y(value) {\n this._y = value;\n this._isDirty = true;\n }\n /** Gets or sets the z coordinate */\n get z() {\n return this._z;\n }\n set z(value) {\n this._z = value;\n this._isDirty = true;\n }\n /**\n * Creates a new Vector3 object from the given x, y, z (floats) coordinates.\n * @param x defines the first coordinates (on X axis)\n * @param y defines the second coordinates (on Y axis)\n * @param z defines the third coordinates (on Z axis)\n */\n constructor(x = 0, y = 0, z = 0) {\n /** @internal */\n this._isDirty = true;\n this._x = x;\n this._y = y;\n this._z = z;\n }\n /**\n * Creates a string representation of the Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#67\n * @returns a string with the Vector3 coordinates.\n */\n toString() {\n return `{X: ${this._x} Y: ${this._y} Z: ${this._z}}`;\n }\n /**\n * Gets the class name\n * @returns the string \"Vector3\"\n */\n getClassName() {\n return \"Vector3\";\n }\n /**\n * Creates the Vector3 hash code\n * @returns a number which tends to be unique between Vector3 instances\n */\n getHashCode() {\n const x = _ExtractAsInt(this._x);\n const y = _ExtractAsInt(this._y);\n const z = _ExtractAsInt(this._z);\n let hash = x;\n hash = (hash * 397) ^ y;\n hash = (hash * 397) ^ z;\n return hash;\n }\n // Operators\n /**\n * Creates an array containing three elements : the coordinates of the Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#10\n * @returns a new array of numbers\n */\n asArray() {\n const result = [];\n this.toArray(result, 0);\n return result;\n }\n /**\n * Populates the given array or Float32Array from the given index with the successive coordinates of the Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#65\n * @param array defines the destination array\n * @param index defines the offset in the destination array\n * @returns the current Vector3\n */\n toArray(array, index = 0) {\n array[index] = this._x;\n array[index + 1] = this._y;\n array[index + 2] = this._z;\n return this;\n }\n /**\n * Update the current vector from an array\n * Example Playground https://playground.babylonjs.com/#R1F8YU#24\n * @param array defines the destination array\n * @param index defines the offset in the destination array\n * @returns the current Vector3\n */\n fromArray(array, index = 0) {\n Vector3.FromArrayToRef(array, index, this);\n return this;\n }\n /**\n * Converts the current Vector3 into a quaternion (considering that the Vector3 contains Euler angles representation of a rotation)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#66\n * @returns a new Quaternion object, computed from the Vector3 coordinates\n */\n toQuaternion() {\n return Quaternion.RotationYawPitchRoll(this._y, this._x, this._z);\n }\n /**\n * Adds the given vector to the current Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#4\n * @param otherVector defines the second operand\n * @returns the current updated Vector3\n */\n addInPlace(otherVector) {\n return this.addInPlaceFromFloats(otherVector._x, otherVector._y, otherVector._z);\n }\n /**\n * Adds the given coordinates to the current Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#5\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the current updated Vector3\n */\n addInPlaceFromFloats(x, y, z) {\n this._x += x;\n this._y += y;\n this._z += z;\n this._isDirty = true;\n return this;\n }\n /**\n * Gets a new Vector3, result of the addition the current Vector3 and the given vector\n * Example Playground https://playground.babylonjs.com/#R1F8YU#3\n * @param otherVector defines the second operand\n * @returns the resulting Vector3\n */\n add(otherVector) {\n return new this.constructor(this._x + otherVector._x, this._y + otherVector._y, this._z + otherVector._z);\n }\n /**\n * Adds the current Vector3 to the given one and stores the result in the vector \"result\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#6\n * @param otherVector defines the second operand\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n addToRef(otherVector, result) {\n return result.copyFromFloats(this._x + otherVector._x, this._y + otherVector._y, this._z + otherVector._z);\n }\n /**\n * Subtract the given vector from the current Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#61\n * @param otherVector defines the second operand\n * @returns the current updated Vector3\n */\n subtractInPlace(otherVector) {\n this._x -= otherVector._x;\n this._y -= otherVector._y;\n this._z -= otherVector._z;\n this._isDirty = true;\n return this;\n }\n /**\n * Returns a new Vector3, result of the subtraction of the given vector from the current Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#60\n * @param otherVector defines the second operand\n * @returns the resulting Vector3\n */\n subtract(otherVector) {\n return new this.constructor(this._x - otherVector._x, this._y - otherVector._y, this._z - otherVector._z);\n }\n /**\n * Subtracts the given vector from the current Vector3 and stores the result in the vector \"result\".\n * Example Playground https://playground.babylonjs.com/#R1F8YU#63\n * @param otherVector defines the second operand\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n subtractToRef(otherVector, result) {\n return this.subtractFromFloatsToRef(otherVector._x, otherVector._y, otherVector._z, result);\n }\n /**\n * Returns a new Vector3 set with the subtraction of the given floats from the current Vector3 coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#62\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the resulting Vector3\n */\n subtractFromFloats(x, y, z) {\n return new this.constructor(this._x - x, this._y - y, this._z - z);\n }\n /**\n * Subtracts the given floats from the current Vector3 coordinates and set the given vector \"result\" with this result\n * Example Playground https://playground.babylonjs.com/#R1F8YU#64\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n subtractFromFloatsToRef(x, y, z, result) {\n return result.copyFromFloats(this._x - x, this._y - y, this._z - z);\n }\n /**\n * Gets a new Vector3 set with the current Vector3 negated coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#35\n * @returns a new Vector3\n */\n negate() {\n return new this.constructor(-this._x, -this._y, -this._z);\n }\n /**\n * Negate this vector in place\n * Example Playground https://playground.babylonjs.com/#R1F8YU#36\n * @returns this\n */\n negateInPlace() {\n this._x *= -1;\n this._y *= -1;\n this._z *= -1;\n this._isDirty = true;\n return this;\n }\n /**\n * Negate the current Vector3 and stores the result in the given vector \"result\" coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#37\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n negateToRef(result) {\n return result.copyFromFloats(this._x * -1, this._y * -1, this._z * -1);\n }\n /**\n * Multiplies the Vector3 coordinates by the float \"scale\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#56\n * @param scale defines the multiplier factor\n * @returns the current updated Vector3\n */\n scaleInPlace(scale) {\n this._x *= scale;\n this._y *= scale;\n this._z *= scale;\n this._isDirty = true;\n return this;\n }\n /**\n * Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float \"scale\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#53\n * @param scale defines the multiplier factor\n * @returns a new Vector3\n */\n scale(scale) {\n return new this.constructor(this._x * scale, this._y * scale, this._z * scale);\n }\n /**\n * Multiplies the current Vector3 coordinates by the float \"scale\" and stores the result in the given vector \"result\" coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#57\n * @param scale defines the multiplier factor\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n scaleToRef(scale, result) {\n return result.copyFromFloats(this._x * scale, this._y * scale, this._z * scale);\n }\n /**\n * Creates a vector normal (perpendicular) to the current Vector3 and stores the result in the given vector\n * Out of the infinite possibilities the normal chosen is the one formed by rotating the current vector\n * 90 degrees about an axis which lies perpendicular to the current vector\n * and its projection on the xz plane. In the case of a current vector in the xz plane\n * the normal is calculated to be along the y axis.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#230\n * Example Playground https://playground.babylonjs.com/#R1F8YU#231\n * @param result defines the Vector3 object where to store the resultant normal\n * returns the result\n */\n getNormalToRef(result) {\n /**\n * Calculates the spherical coordinates of the current vector\n * so saves on memory rather than importing whole Spherical Class\n */\n const radius = this.length();\n let theta = Math.acos(this.y / radius);\n const phi = Math.atan2(this.z, this.x);\n //makes angle 90 degs to current vector\n if (theta > Math.PI / 2) {\n theta -= Math.PI / 2;\n }\n else {\n theta += Math.PI / 2;\n }\n //Calculates resutant normal vector from spherical coordinate of perpendicular vector\n const x = radius * Math.sin(theta) * Math.cos(phi);\n const y = radius * Math.cos(theta);\n const z = radius * Math.sin(theta) * Math.sin(phi);\n result.set(x, y, z);\n return result;\n }\n /**\n * Rotates the vector using the given unit quaternion and stores the new vector in result\n * Example Playground https://playground.babylonjs.com/#R1F8YU#9\n * @param q the unit quaternion representing the rotation\n * @param result the output vector\n * @returns the result\n */\n applyRotationQuaternionToRef(q, result) {\n // Derived from https://raw.org/proof/vector-rotation-using-quaternions/\n const vx = this._x, vy = this._y, vz = this._z;\n const qx = q._x, qy = q._y, qz = q._z, qw = q._w;\n // t = 2q x v\n const tx = 2 * (qy * vz - qz * vy);\n const ty = 2 * (qz * vx - qx * vz);\n const tz = 2 * (qx * vy - qy * vx);\n // v + w t + q x t\n result._x = vx + qw * tx + qy * tz - qz * ty;\n result._y = vy + qw * ty + qz * tx - qx * tz;\n result._z = vz + qw * tz + qx * ty - qy * tx;\n result._isDirty = true;\n return result;\n }\n /**\n * Rotates the vector in place using the given unit quaternion\n * Example Playground https://playground.babylonjs.com/#R1F8YU#8\n * @param q the unit quaternion representing the rotation\n * @returns the current updated Vector3\n */\n applyRotationQuaternionInPlace(q) {\n return this.applyRotationQuaternionToRef(q, this);\n }\n /**\n * Rotates the vector using the given unit quaternion and returns the new vector\n * Example Playground https://playground.babylonjs.com/#R1F8YU#7\n * @param q the unit quaternion representing the rotation\n * @returns a new Vector3\n */\n applyRotationQuaternion(q) {\n return this.applyRotationQuaternionToRef(q, new this.constructor());\n }\n /**\n * Scale the current Vector3 values by a factor and add the result to a given Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#55\n * @param scale defines the scale factor\n * @param result defines the Vector3 object where to store the result\n * @returns result input\n */\n scaleAndAddToRef(scale, result) {\n return result.addInPlaceFromFloats(this._x * scale, this._y * scale, this._z * scale);\n }\n /**\n * Projects the current point Vector3 to a plane along a ray starting from a specified origin and passing through the current point Vector3.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#48\n * @param plane defines the plane to project to\n * @param origin defines the origin of the projection ray\n * @returns the projected vector3\n */\n projectOnPlane(plane, origin) {\n const result = new this.constructor();\n this.projectOnPlaneToRef(plane, origin, result);\n return result;\n }\n /**\n * Projects the current point Vector3 to a plane along a ray starting from a specified origin and passing through the current point Vector3.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#49\n * @param plane defines the plane to project to\n * @param origin defines the origin of the projection ray\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n projectOnPlaneToRef(plane, origin, result) {\n const n = plane.normal;\n const d = plane.d;\n const V = MathTmp.Vector3[0];\n // ray direction\n this.subtractToRef(origin, V);\n V.normalize();\n const denom = Vector3.Dot(V, n);\n //When the ray is close to parallel to the plane return infinity vector\n if (Math.abs(denom) < Math.pow(10, -10)) {\n result.setAll(Infinity);\n }\n else {\n const t = -(Vector3.Dot(origin, n) + d) / denom;\n // P = P0 + t*V\n const scaledV = V.scaleInPlace(t);\n origin.addToRef(scaledV, result);\n }\n return result;\n }\n /**\n * Returns true if the current Vector3 and the given vector coordinates are strictly equal\n * Example Playground https://playground.babylonjs.com/#R1F8YU#19\n * @param otherVector defines the second operand\n * @returns true if both vectors are equals\n */\n equals(otherVector) {\n return otherVector && this._x === otherVector._x && this._y === otherVector._y && this._z === otherVector._z;\n }\n /**\n * Returns true if the current Vector3 and the given vector coordinates are distant less than epsilon\n * Example Playground https://playground.babylonjs.com/#R1F8YU#21\n * @param otherVector defines the second operand\n * @param epsilon defines the minimal distance to define values as equals\n * @returns true if both vectors are distant less than epsilon\n */\n equalsWithEpsilon(otherVector, epsilon = Epsilon) {\n return (otherVector &&\n Scalar.WithinEpsilon(this._x, otherVector._x, epsilon) &&\n Scalar.WithinEpsilon(this._y, otherVector._y, epsilon) &&\n Scalar.WithinEpsilon(this._z, otherVector._z, epsilon));\n }\n /**\n * Returns true if the current Vector3 coordinates equals the given floats\n * Example Playground https://playground.babylonjs.com/#R1F8YU#20\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns true if both vectors are equal\n */\n equalsToFloats(x, y, z) {\n return this._x === x && this._y === y && this._z === z;\n }\n /**\n * Multiplies the current Vector3 coordinates by the given ones\n * Example Playground https://playground.babylonjs.com/#R1F8YU#32\n * @param otherVector defines the second operand\n * @returns the current updated Vector3\n */\n multiplyInPlace(otherVector) {\n this._x *= otherVector._x;\n this._y *= otherVector._y;\n this._z *= otherVector._z;\n this._isDirty = true;\n return this;\n }\n /**\n * Returns a new Vector3, result of the multiplication of the current Vector3 by the given vector\n * Example Playground https://playground.babylonjs.com/#R1F8YU#31\n * @param otherVector defines the second operand\n * @returns the new Vector3\n */\n multiply(otherVector) {\n return this.multiplyByFloats(otherVector._x, otherVector._y, otherVector._z);\n }\n /**\n * Multiplies the current Vector3 by the given one and stores the result in the given vector \"result\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#33\n * @param otherVector defines the second operand\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n multiplyToRef(otherVector, result) {\n return result.copyFromFloats(this._x * otherVector._x, this._y * otherVector._y, this._z * otherVector._z);\n }\n /**\n * Returns a new Vector3 set with the result of the multiplication of the current Vector3 coordinates by the given floats\n * Example Playground https://playground.babylonjs.com/#R1F8YU#34\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the new Vector3\n */\n multiplyByFloats(x, y, z) {\n return new this.constructor(this._x * x, this._y * y, this._z * z);\n }\n /**\n * Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones\n * Example Playground https://playground.babylonjs.com/#R1F8YU#16\n * @param otherVector defines the second operand\n * @returns the new Vector3\n */\n divide(otherVector) {\n return new this.constructor(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);\n }\n /**\n * Divides the current Vector3 coordinates by the given ones and stores the result in the given vector \"result\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#18\n * @param otherVector defines the second operand\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n divideToRef(otherVector, result) {\n return result.copyFromFloats(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);\n }\n /**\n * Divides the current Vector3 coordinates by the given ones.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#17\n * @param otherVector defines the second operand\n * @returns the current updated Vector3\n */\n divideInPlace(otherVector) {\n return this.divideToRef(otherVector, this);\n }\n /**\n * Updates the current Vector3 with the minimal coordinate values between its and the given vector ones\n * Example Playground https://playground.babylonjs.com/#R1F8YU#29\n * @param other defines the second operand\n * @returns the current updated Vector3\n */\n minimizeInPlace(other) {\n return this.minimizeInPlaceFromFloats(other._x, other._y, other._z);\n }\n /**\n * Updates the current Vector3 with the maximal coordinate values between its and the given vector ones.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#27\n * @param other defines the second operand\n * @returns the current updated Vector3\n */\n maximizeInPlace(other) {\n return this.maximizeInPlaceFromFloats(other._x, other._y, other._z);\n }\n /**\n * Updates the current Vector3 with the minimal coordinate values between its and the given coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#30\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the current updated Vector3\n */\n minimizeInPlaceFromFloats(x, y, z) {\n if (x < this._x) {\n this.x = x;\n }\n if (y < this._y) {\n this.y = y;\n }\n if (z < this._z) {\n this.z = z;\n }\n return this;\n }\n /**\n * Updates the current Vector3 with the maximal coordinate values between its and the given coordinates.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#28\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the current updated Vector3\n */\n maximizeInPlaceFromFloats(x, y, z) {\n if (x > this._x) {\n this.x = x;\n }\n if (y > this._y) {\n this.y = y;\n }\n if (z > this._z) {\n this.z = z;\n }\n return this;\n }\n /**\n * Due to float precision, scale of a mesh could be uniform but float values are off by a small fraction\n * Check if is non uniform within a certain amount of decimal places to account for this\n * @param epsilon the amount the values can differ\n * @returns if the the vector is non uniform to a certain number of decimal places\n */\n isNonUniformWithinEpsilon(epsilon) {\n const absX = Math.abs(this._x);\n const absY = Math.abs(this._y);\n if (!Scalar.WithinEpsilon(absX, absY, epsilon)) {\n return true;\n }\n const absZ = Math.abs(this._z);\n if (!Scalar.WithinEpsilon(absX, absZ, epsilon)) {\n return true;\n }\n if (!Scalar.WithinEpsilon(absY, absZ, epsilon)) {\n return true;\n }\n return false;\n }\n /**\n * Gets a boolean indicating that the vector is non uniform meaning x, y or z are not all the same\n */\n get isNonUniform() {\n const absX = Math.abs(this._x);\n const absY = Math.abs(this._y);\n if (absX !== absY) {\n return true;\n }\n const absZ = Math.abs(this._z);\n if (absX !== absZ) {\n return true;\n }\n return false;\n }\n /**\n * Gets a new Vector3 from current Vector3 floored values\n * Example Playground https://playground.babylonjs.com/#R1F8YU#22\n * @returns a new Vector3\n */\n floor() {\n return new this.constructor(Math.floor(this._x), Math.floor(this._y), Math.floor(this._z));\n }\n /**\n * Gets a new Vector3 from current Vector3 fractional values\n * Example Playground https://playground.babylonjs.com/#R1F8YU#23\n * @returns a new Vector3\n */\n fract() {\n return new this.constructor(this._x - Math.floor(this._x), this._y - Math.floor(this._y), this._z - Math.floor(this._z));\n }\n // Properties\n /**\n * Gets the length of the Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#25\n * @returns the length of the Vector3\n */\n length() {\n return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z);\n }\n /**\n * Gets the squared length of the Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#26\n * @returns squared length of the Vector3\n */\n lengthSquared() {\n return this._x * this._x + this._y * this._y + this._z * this._z;\n }\n /**\n * Gets a boolean indicating if the vector contains a zero in one of its components\n * Example Playground https://playground.babylonjs.com/#R1F8YU#1\n */\n get hasAZeroComponent() {\n return this._x * this._y * this._z === 0;\n }\n /**\n * Normalize the current Vector3.\n * Please note that this is an in place operation.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#122\n * @returns the current updated Vector3\n */\n normalize() {\n return this.normalizeFromLength(this.length());\n }\n /**\n * Reorders the x y z properties of the vector in place\n * Example Playground https://playground.babylonjs.com/#R1F8YU#44\n * @param order new ordering of the properties (eg. for vector 1,2,3 with \"ZYX\" will produce 3,2,1)\n * @returns the current updated vector\n */\n reorderInPlace(order) {\n order = order.toLowerCase();\n if (order === \"xyz\") {\n return this;\n }\n MathTmp.Vector3[0].copyFrom(this);\n [\"x\", \"y\", \"z\"].forEach((val, i) => {\n this[val] = MathTmp.Vector3[0][order[i]];\n });\n return this;\n }\n /**\n * Rotates the vector around 0,0,0 by a quaternion\n * Example Playground https://playground.babylonjs.com/#R1F8YU#47\n * @param quaternion the rotation quaternion\n * @param result vector to store the result\n * @returns the resulting vector\n */\n rotateByQuaternionToRef(quaternion, result) {\n quaternion.toRotationMatrix(MathTmp.Matrix[0]);\n Vector3.TransformCoordinatesToRef(this, MathTmp.Matrix[0], result);\n return result;\n }\n /**\n * Rotates a vector around a given point\n * Example Playground https://playground.babylonjs.com/#R1F8YU#46\n * @param quaternion the rotation quaternion\n * @param point the point to rotate around\n * @param result vector to store the result\n * @returns the resulting vector\n */\n rotateByQuaternionAroundPointToRef(quaternion, point, result) {\n this.subtractToRef(point, MathTmp.Vector3[0]);\n MathTmp.Vector3[0].rotateByQuaternionToRef(quaternion, MathTmp.Vector3[0]);\n point.addToRef(MathTmp.Vector3[0], result);\n return result;\n }\n /**\n * Returns a new Vector3 as the cross product of the current vector and the \"other\" one\n * The cross product is then orthogonal to both current and \"other\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#14\n * @param other defines the right operand\n * @returns the cross product\n */\n cross(other) {\n const result = new this.constructor();\n return Vector3.CrossToRef(this, other, result);\n }\n /**\n * Normalize the current Vector3 with the given input length.\n * Please note that this is an in place operation.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#123\n * @param len the length of the vector\n * @returns the current updated Vector3\n */\n normalizeFromLength(len) {\n if (len === 0 || len === 1.0) {\n return this;\n }\n return this.scaleInPlace(1.0 / len);\n }\n /**\n * Normalize the current Vector3 to a new vector\n * Example Playground https://playground.babylonjs.com/#R1F8YU#124\n * @returns the new Vector3\n */\n normalizeToNew() {\n const normalized = new this.constructor(0, 0, 0);\n this.normalizeToRef(normalized);\n return normalized;\n }\n /**\n * Normalize the current Vector3 to the reference\n * Example Playground https://playground.babylonjs.com/#R1F8YU#125\n * @param reference define the Vector3 to update\n * @returns the updated Vector3\n */\n normalizeToRef(reference) {\n const len = this.length();\n if (len === 0 || len === 1.0) {\n return reference.copyFromFloats(this._x, this._y, this._z);\n }\n return this.scaleToRef(1.0 / len, reference);\n }\n /**\n * Creates a new Vector3 copied from the current Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#11\n * @returns the new Vector3\n */\n clone() {\n return new this.constructor(this._x, this._y, this._z);\n }\n /**\n * Copies the given vector coordinates to the current Vector3 ones\n * Example Playground https://playground.babylonjs.com/#R1F8YU#12\n * @param source defines the source Vector3\n * @returns the current updated Vector3\n */\n copyFrom(source) {\n return this.copyFromFloats(source._x, source._y, source._z);\n }\n /**\n * Copies the given floats to the current Vector3 coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#13\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the current updated Vector3\n */\n copyFromFloats(x, y, z) {\n this._x = x;\n this._y = y;\n this._z = z;\n this._isDirty = true;\n return this;\n }\n /**\n * Copies the given floats to the current Vector3 coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#58\n * @param x defines the x coordinate of the operand\n * @param y defines the y coordinate of the operand\n * @param z defines the z coordinate of the operand\n * @returns the current updated Vector3\n */\n set(x, y, z) {\n return this.copyFromFloats(x, y, z);\n }\n /**\n * Copies the given float to the current Vector3 coordinates\n * Example Playground https://playground.babylonjs.com/#R1F8YU#59\n * @param v defines the x, y and z coordinates of the operand\n * @returns the current updated Vector3\n */\n setAll(v) {\n this._x = this._y = this._z = v;\n this._isDirty = true;\n return this;\n }\n // Statics\n /**\n * Get the clip factor between two vectors\n * Example Playground https://playground.babylonjs.com/#R1F8YU#126\n * @param vector0 defines the first operand\n * @param vector1 defines the second operand\n * @param axis defines the axis to use\n * @param size defines the size along the axis\n * @returns the clip factor\n */\n static GetClipFactor(vector0, vector1, axis, size) {\n const d0 = Vector3.Dot(vector0, axis) - size;\n const d1 = Vector3.Dot(vector1, axis) - size;\n const s = d0 / (d0 - d1);\n return s;\n }\n /**\n * Get angle between two vectors\n * Example Playground https://playground.babylonjs.com/#R1F8YU#86\n * @param vector0 the starting point\n * @param vector1 the ending point\n * @param normal direction of the normal\n * @returns the angle between vector0 and vector1\n */\n static GetAngleBetweenVectors(vector0, vector1, normal) {\n const v0 = vector0.normalizeToRef(MathTmp.Vector3[1]);\n const v1 = vector1.normalizeToRef(MathTmp.Vector3[2]);\n let dot = Vector3.Dot(v0, v1);\n // Vectors are normalized so dot will be in [-1, 1] (aside precision issues enough to break the result which explains the below clamp)\n dot = Scalar.Clamp(dot, -1, 1);\n const angle = Math.acos(dot);\n const n = MathTmp.Vector3[3];\n Vector3.CrossToRef(v0, v1, n);\n if (Vector3.Dot(n, normal) > 0) {\n return isNaN(angle) ? 0 : angle;\n }\n return isNaN(angle) ? -Math.PI : -Math.acos(dot);\n }\n /**\n * Get angle between two vectors projected on a plane\n * Example Playground https://playground.babylonjs.com/#R1F8YU#87\n * Expectation compute time: 0.01 ms (median) and 0.02 ms (percentile 95%)\n * @param vector0 angle between vector0 and vector1\n * @param vector1 angle between vector0 and vector1\n * @param normal Normal of the projection plane\n * @returns the angle in radians (float) between vector0 and vector1 projected on the plane with the specified normal\n */\n static GetAngleBetweenVectorsOnPlane(vector0, vector1, normal) {\n MathTmp.Vector3[0].copyFrom(vector0);\n const v0 = MathTmp.Vector3[0];\n MathTmp.Vector3[1].copyFrom(vector1);\n const v1 = MathTmp.Vector3[1];\n MathTmp.Vector3[2].copyFrom(normal);\n const vNormal = MathTmp.Vector3[2];\n const right = MathTmp.Vector3[3];\n const forward = MathTmp.Vector3[4];\n v0.normalize();\n v1.normalize();\n vNormal.normalize();\n Vector3.CrossToRef(vNormal, v0, right);\n Vector3.CrossToRef(right, vNormal, forward);\n const angle = Math.atan2(Vector3.Dot(v1, right), Vector3.Dot(v1, forward));\n return Scalar.NormalizeRadians(angle);\n }\n /**\n * Gets the rotation that aligns the roll axis (Y) to the line joining the start point to the target point and stores it in the ref Vector3\n * Example PG https://playground.babylonjs.com/#R1F8YU#189\n * @param start the starting point\n * @param target the target point\n * @param ref the vector3 to store the result\n * @returns ref in the form (pitch, yaw, 0)\n */\n static PitchYawRollToMoveBetweenPointsToRef(start, target, ref) {\n const diff = TmpVectors.Vector3[0];\n target.subtractToRef(start, diff);\n ref._y = Math.atan2(diff.x, diff.z) || 0;\n ref._x = Math.atan2(Math.sqrt(diff.x ** 2 + diff.z ** 2), diff.y) || 0;\n ref._z = 0;\n ref._isDirty = true;\n return ref;\n }\n /**\n * Gets the rotation that aligns the roll axis (Y) to the line joining the start point to the target point\n * Example PG https://playground.babylonjs.com/#R1F8YU#188\n * @param start the starting point\n * @param target the target point\n * @returns the rotation in the form (pitch, yaw, 0)\n */\n static PitchYawRollToMoveBetweenPoints(start, target) {\n const ref = Vector3.Zero();\n return Vector3.PitchYawRollToMoveBetweenPointsToRef(start, target, ref);\n }\n /**\n * Slerp between two vectors. See also `SmoothToRef`\n * Slerp is a spherical linear interpolation\n * giving a slow in and out effect\n * Example Playground 1 https://playground.babylonjs.com/#R1F8YU#108\n * Example Playground 2 https://playground.babylonjs.com/#R1F8YU#109\n * @param vector0 Start vector\n * @param vector1 End vector\n * @param slerp amount (will be clamped between 0 and 1)\n * @param result The slerped vector\n */\n static SlerpToRef(vector0, vector1, slerp, result) {\n slerp = Scalar.Clamp(slerp, 0, 1);\n const vector0Dir = MathTmp.Vector3[0];\n const vector1Dir = MathTmp.Vector3[1];\n vector0Dir.copyFrom(vector0);\n const vector0Length = vector0Dir.length();\n vector0Dir.normalizeFromLength(vector0Length);\n vector1Dir.copyFrom(vector1);\n const vector1Length = vector1Dir.length();\n vector1Dir.normalizeFromLength(vector1Length);\n const dot = Vector3.Dot(vector0Dir, vector1Dir);\n let scale0;\n let scale1;\n if (dot < 1 - Epsilon) {\n const omega = Math.acos(dot);\n const invSin = 1 / Math.sin(omega);\n scale0 = Math.sin((1 - slerp) * omega) * invSin;\n scale1 = Math.sin(slerp * omega) * invSin;\n }\n else {\n // Use linear interpolation\n scale0 = 1 - slerp;\n scale1 = slerp;\n }\n vector0Dir.scaleInPlace(scale0);\n vector1Dir.scaleInPlace(scale1);\n result.copyFrom(vector0Dir).addInPlace(vector1Dir);\n result.scaleInPlace(Scalar.Lerp(vector0Length, vector1Length, slerp));\n return result;\n }\n /**\n * Smooth interpolation between two vectors using Slerp\n * Example Playground https://playground.babylonjs.com/#R1F8YU#110\n * @param source source vector\n * @param goal goal vector\n * @param deltaTime current interpolation frame\n * @param lerpTime total interpolation time\n * @param result the smoothed vector\n */\n static SmoothToRef(source, goal, deltaTime, lerpTime, result) {\n Vector3.SlerpToRef(source, goal, lerpTime === 0 ? 1 : deltaTime / lerpTime, result);\n return result;\n }\n /**\n * Returns a new Vector3 set from the index \"offset\" of the given array\n * Example Playground https://playground.babylonjs.com/#R1F8YU#83\n * @param array defines the source array\n * @param offset defines the offset in the source array\n * @returns the new Vector3\n */\n static FromArray(array, offset = 0) {\n return new Vector3(array[offset], array[offset + 1], array[offset + 2]);\n }\n /**\n * Returns a new Vector3 set from the index \"offset\" of the given Float32Array\n * @param array defines the source array\n * @param offset defines the offset in the source array\n * @returns the new Vector3\n * @deprecated Please use FromArray instead.\n */\n static FromFloatArray(array, offset) {\n return Vector3.FromArray(array, offset);\n }\n /**\n * Sets the given vector \"result\" with the element values from the index \"offset\" of the given array\n * Example Playground https://playground.babylonjs.com/#R1F8YU#84\n * @param array defines the source array\n * @param offset defines the offset in the source array\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static FromArrayToRef(array, offset, result) {\n result._x = array[offset];\n result._y = array[offset + 1];\n result._z = array[offset + 2];\n result._isDirty = true;\n return result;\n }\n /**\n * Sets the given vector \"result\" with the element values from the index \"offset\" of the given Float32Array\n * @param array defines the source array\n * @param offset defines the offset in the source array\n * @param result defines the Vector3 where to store the result\n * @deprecated Please use FromArrayToRef instead.\n */\n static FromFloatArrayToRef(array, offset, result) {\n return Vector3.FromArrayToRef(array, offset, result);\n }\n /**\n * Sets the given vector \"result\" with the given floats.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#85\n * @param x defines the x coordinate of the source\n * @param y defines the y coordinate of the source\n * @param z defines the z coordinate of the source\n * @param result defines the Vector3 where to store the result\n */\n static FromFloatsToRef(x, y, z, result) {\n result.copyFromFloats(x, y, z);\n return result;\n }\n /**\n * Returns a new Vector3 set to (0.0, 0.0, 0.0)\n * @returns a new empty Vector3\n */\n static Zero() {\n return new Vector3(0.0, 0.0, 0.0);\n }\n /**\n * Returns a new Vector3 set to (1.0, 1.0, 1.0)\n * @returns a new Vector3\n */\n static One() {\n return new Vector3(1.0, 1.0, 1.0);\n }\n /**\n * Returns a new Vector3 set to (0.0, 1.0, 0.0)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\n * @returns a new up Vector3\n */\n static Up() {\n return new Vector3(0.0, 1.0, 0.0);\n }\n /**\n * Gets an up Vector3 that must not be updated\n */\n static get UpReadOnly() {\n return Vector3._UpReadOnly;\n }\n /**\n * Gets a down Vector3 that must not be updated\n */\n static get DownReadOnly() {\n return Vector3._DownReadOnly;\n }\n /**\n * Gets a right Vector3 that must not be updated\n */\n static get RightReadOnly() {\n return Vector3._RightReadOnly;\n }\n /**\n * Gets a left Vector3 that must not be updated\n */\n static get LeftReadOnly() {\n return Vector3._LeftReadOnly;\n }\n /**\n * Gets a forward Vector3 that must not be updated\n */\n static get LeftHandedForwardReadOnly() {\n return Vector3._LeftHandedForwardReadOnly;\n }\n /**\n * Gets a forward Vector3 that must not be updated\n */\n static get RightHandedForwardReadOnly() {\n return Vector3._RightHandedForwardReadOnly;\n }\n /**\n * Gets a backward Vector3 that must not be updated\n */\n static get LeftHandedBackwardReadOnly() {\n return Vector3._LeftHandedBackwardReadOnly;\n }\n /**\n * Gets a backward Vector3 that must not be updated\n */\n static get RightHandedBackwardReadOnly() {\n return Vector3._RightHandedBackwardReadOnly;\n }\n /**\n * Gets a zero Vector3 that must not be updated\n */\n static get ZeroReadOnly() {\n return Vector3._ZeroReadOnly;\n }\n /**\n * Gets a one Vector3 that must not be updated\n */\n static get OneReadOnly() {\n return Vector3._OneReadOnly;\n }\n /**\n * Returns a new Vector3 set to (0.0, -1.0, 0.0)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\n * @returns a new down Vector3\n */\n static Down() {\n return new Vector3(0.0, -1.0, 0.0);\n }\n /**\n * Returns a new Vector3 set to (0.0, 0.0, 1.0)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\n * @param rightHandedSystem is the scene right-handed (negative z)\n * @returns a new forward Vector3\n */\n static Forward(rightHandedSystem = false) {\n return new Vector3(0.0, 0.0, rightHandedSystem ? -1.0 : 1.0);\n }\n /**\n * Returns a new Vector3 set to (0.0, 0.0, -1.0)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\n * @param rightHandedSystem is the scene right-handed (negative-z)\n * @returns a new Backward Vector3\n */\n static Backward(rightHandedSystem = false) {\n return new Vector3(0.0, 0.0, rightHandedSystem ? 1.0 : -1.0);\n }\n /**\n * Returns a new Vector3 set to (1.0, 0.0, 0.0)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\n * @returns a new right Vector3\n */\n static Right() {\n return new Vector3(1.0, 0.0, 0.0);\n }\n /**\n * Returns a new Vector3 set to (-1.0, 0.0, 0.0)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\n * @returns a new left Vector3\n */\n static Left() {\n return new Vector3(-1.0, 0.0, 0.0);\n }\n /**\n * Returns a new Vector3 with random values between min and max\n * @param min the minimum random value\n * @param max the maximum random value\n * @returns a Vector3 with random values between min and max\n */\n static Random(min = 0, max = 1) {\n return new Vector3(Scalar.RandomRange(min, max), Scalar.RandomRange(min, max), Scalar.RandomRange(min, max));\n }\n /**\n * Returns a new Vector3 set with the result of the transformation by the given matrix of the given vector.\n * This method computes transformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#111\n * @param vector defines the Vector3 to transform\n * @param transformation defines the transformation matrix\n * @returns the transformed Vector3\n */\n static TransformCoordinates(vector, transformation) {\n const result = Vector3.Zero();\n Vector3.TransformCoordinatesToRef(vector, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given vector\n * This method computes transformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#113\n * @param vector defines the Vector3 to transform\n * @param transformation defines the transformation matrix\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static TransformCoordinatesToRef(vector, transformation, result) {\n Vector3.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)\n * This method computes transformed coordinates only, not transformed direction vectors\n * Example Playground https://playground.babylonjs.com/#R1F8YU#115\n * @param x define the x coordinate of the source vector\n * @param y define the y coordinate of the source vector\n * @param z define the z coordinate of the source vector\n * @param transformation defines the transformation matrix\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) {\n const m = transformation.m;\n const rx = x * m[0] + y * m[4] + z * m[8] + m[12];\n const ry = x * m[1] + y * m[5] + z * m[9] + m[13];\n const rz = x * m[2] + y * m[6] + z * m[10] + m[14];\n const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);\n result._x = rx * rw;\n result._y = ry * rw;\n result._z = rz * rw;\n result._isDirty = true;\n return result;\n }\n /**\n * Returns a new Vector3 set with the result of the normal transformation by the given matrix of the given vector\n * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#112\n * @param vector defines the Vector3 to transform\n * @param transformation defines the transformation matrix\n * @returns the new Vector3\n */\n static TransformNormal(vector, transformation) {\n const result = Vector3.Zero();\n Vector3.TransformNormalToRef(vector, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given vector\n * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#114\n * @param vector defines the Vector3 to transform\n * @param transformation defines the transformation matrix\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static TransformNormalToRef(vector, transformation, result) {\n this.TransformNormalFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given floats (x, y, z)\n * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)\n * Example Playground https://playground.babylonjs.com/#R1F8YU#116\n * @param x define the x coordinate of the source vector\n * @param y define the y coordinate of the source vector\n * @param z define the z coordinate of the source vector\n * @param transformation defines the transformation matrix\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static TransformNormalFromFloatsToRef(x, y, z, transformation, result) {\n const m = transformation.m;\n result._x = x * m[0] + y * m[4] + z * m[8];\n result._y = x * m[1] + y * m[5] + z * m[9];\n result._z = x * m[2] + y * m[6] + z * m[10];\n result._isDirty = true;\n return result;\n }\n /**\n * Returns a new Vector3 located for \"amount\" on the CatmullRom interpolation spline defined by the vectors \"value1\", \"value2\", \"value3\", \"value4\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#69\n * @param value1 defines the first control point\n * @param value2 defines the second control point\n * @param value3 defines the third control point\n * @param value4 defines the fourth control point\n * @param amount defines the amount on the spline to use\n * @returns the new Vector3\n */\n static CatmullRom(value1, value2, value3, value4, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const x = 0.5 *\n (2.0 * value2._x +\n (-value1._x + value3._x) * amount +\n (2.0 * value1._x - 5.0 * value2._x + 4.0 * value3._x - value4._x) * squared +\n (-value1._x + 3.0 * value2._x - 3.0 * value3._x + value4._x) * cubed);\n const y = 0.5 *\n (2.0 * value2._y +\n (-value1._y + value3._y) * amount +\n (2.0 * value1._y - 5.0 * value2._y + 4.0 * value3._y - value4._y) * squared +\n (-value1._y + 3.0 * value2._y - 3.0 * value3._y + value4._y) * cubed);\n const z = 0.5 *\n (2.0 * value2._z +\n (-value1._z + value3._z) * amount +\n (2.0 * value1._z - 5.0 * value2._z + 4.0 * value3._z - value4._z) * squared +\n (-value1._z + 3.0 * value2._z - 3.0 * value3._z + value4._z) * cubed);\n return new value1.constructor(x, y, z);\n }\n /**\n * Returns a new Vector3 set with the coordinates of \"value\", if the vector \"value\" is in the cube defined by the vectors \"min\" and \"max\"\n * If a coordinate value of \"value\" is lower than one of the \"min\" coordinate, then this \"value\" coordinate is set with the \"min\" one\n * If a coordinate value of \"value\" is greater than one of the \"max\" coordinate, then this \"value\" coordinate is set with the \"max\" one\n * Example Playground https://playground.babylonjs.com/#R1F8YU#76\n * @param value defines the current value\n * @param min defines the lower range value\n * @param max defines the upper range value\n * @returns the new Vector3\n */\n static Clamp(value, min, max) {\n const result = new value.constructor();\n Vector3.ClampToRef(value, min, max, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the coordinates of \"value\", if the vector \"value\" is in the cube defined by the vectors \"min\" and \"max\"\n * If a coordinate value of \"value\" is lower than one of the \"min\" coordinate, then this \"value\" coordinate is set with the \"min\" one\n * If a coordinate value of \"value\" is greater than one of the \"max\" coordinate, then this \"value\" coordinate is set with the \"max\" one\n * Example Playground https://playground.babylonjs.com/#R1F8YU#77\n * @param value defines the current value\n * @param min defines the lower range value\n * @param max defines the upper range value\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static ClampToRef(value, min, max, result) {\n let x = value._x;\n x = x > max._x ? max._x : x;\n x = x < min._x ? min._x : x;\n let y = value._y;\n y = y > max._y ? max._y : y;\n y = y < min._y ? min._y : y;\n let z = value._z;\n z = z > max._z ? max._z : z;\n z = z < min._z ? min._z : z;\n result.copyFromFloats(x, y, z);\n return result;\n }\n /**\n * Checks if a given vector is inside a specific range\n * Example Playground https://playground.babylonjs.com/#R1F8YU#75\n * @param v defines the vector to test\n * @param min defines the minimum range\n * @param max defines the maximum range\n */\n static CheckExtends(v, min, max) {\n min.minimizeInPlace(v);\n max.maximizeInPlace(v);\n }\n /**\n * Returns a new Vector3 located for \"amount\" (float) on the Hermite interpolation spline defined by the vectors \"value1\", \"tangent1\", \"value2\", \"tangent2\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#89\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent vector\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent vector\n * @param amount defines the amount on the interpolation spline (between 0 and 1)\n * @returns the new Vector3\n */\n static Hermite(value1, tangent1, value2, tangent2, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\n const part2 = -2.0 * cubed + 3.0 * squared;\n const part3 = cubed - 2.0 * squared + amount;\n const part4 = cubed - squared;\n const x = value1._x * part1 + value2._x * part2 + tangent1._x * part3 + tangent2._x * part4;\n const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;\n const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;\n return new value1.constructor(x, y, z);\n }\n /**\n * Returns a new Vector3 which is the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * Example Playground https://playground.babylonjs.com/#R1F8YU#90\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @returns 1st derivative\n */\n static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {\n const result = new value1.constructor();\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\n return result;\n }\n /**\n * Update a Vector3 with the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * Example Playground https://playground.babylonjs.com/#R1F8YU#91\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @param result define where to store the derivative\n * @returns result input\n */\n static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {\n const t2 = time * time;\n result._x = (t2 - time) * 6 * value1._x + (3 * t2 - 4 * time + 1) * tangent1._x + (-t2 + time) * 6 * value2._x + (3 * t2 - 2 * time) * tangent2._x;\n result._y = (t2 - time) * 6 * value1._y + (3 * t2 - 4 * time + 1) * tangent1._y + (-t2 + time) * 6 * value2._y + (3 * t2 - 2 * time) * tangent2._y;\n result._z = (t2 - time) * 6 * value1._z + (3 * t2 - 4 * time + 1) * tangent1._z + (-t2 + time) * 6 * value2._z + (3 * t2 - 2 * time) * tangent2._z;\n result._isDirty = true;\n return result;\n }\n /**\n * Returns a new Vector3 located for \"amount\" (float) on the linear interpolation between the vectors \"start\" and \"end\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#95\n * @param start defines the start value\n * @param end defines the end value\n * @param amount max defines amount between both (between 0 and 1)\n * @returns the new Vector3\n */\n static Lerp(start, end, amount) {\n const result = new start.constructor(0, 0, 0);\n Vector3.LerpToRef(start, end, amount, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the result of the linear interpolation from the vector \"start\" for \"amount\" to the vector \"end\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#93\n * @param start defines the start value\n * @param end defines the end value\n * @param amount max defines amount between both (between 0 and 1)\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static LerpToRef(start, end, amount, result) {\n result._x = start._x + (end._x - start._x) * amount;\n result._y = start._y + (end._y - start._y) * amount;\n result._z = start._z + (end._z - start._z) * amount;\n result._isDirty = true;\n return result;\n }\n /**\n * Returns the dot product (float) between the vectors \"left\" and \"right\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#82\n * @param left defines the left operand\n * @param right defines the right operand\n * @returns the dot product\n */\n static Dot(left, right) {\n return left._x * right._x + left._y * right._y + left._z * right._z;\n }\n /**\n * Returns a new Vector3 as the cross product of the vectors \"left\" and \"right\"\n * The cross product is then orthogonal to both \"left\" and \"right\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#15\n * @param left defines the left operand\n * @param right defines the right operand\n * @returns the cross product\n */\n static Cross(left, right) {\n const result = new left.constructor();\n Vector3.CrossToRef(left, right, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the cross product of \"left\" and \"right\"\n * The cross product is then orthogonal to both \"left\" and \"right\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#78\n * @param left defines the left operand\n * @param right defines the right operand\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static CrossToRef(left, right, result) {\n const x = left._y * right._z - left._z * right._y;\n const y = left._z * right._x - left._x * right._z;\n const z = left._x * right._y - left._y * right._x;\n result.copyFromFloats(x, y, z);\n return result;\n }\n /**\n * Returns a new Vector3 as the normalization of the given vector\n * Example Playground https://playground.babylonjs.com/#R1F8YU#98\n * @param vector defines the Vector3 to normalize\n * @returns the new Vector3\n */\n static Normalize(vector) {\n const result = Vector3.Zero();\n Vector3.NormalizeToRef(vector, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the normalization of the given first vector\n * Example Playground https://playground.babylonjs.com/#R1F8YU#98\n * @param vector defines the Vector3 to normalize\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static NormalizeToRef(vector, result) {\n vector.normalizeToRef(result);\n return result;\n }\n /**\n * Project a Vector3 onto screen space\n * Example Playground https://playground.babylonjs.com/#R1F8YU#101\n * @param vector defines the Vector3 to project\n * @param world defines the world matrix to use\n * @param transform defines the transform (view x projection) matrix to use\n * @param viewport defines the screen viewport to use\n * @returns the new Vector3\n */\n static Project(vector, world, transform, viewport) {\n const result = new vector.constructor();\n Vector3.ProjectToRef(vector, world, transform, viewport, result);\n return result;\n }\n /**\n * Project a Vector3 onto screen space to reference\n * Example Playground https://playground.babylonjs.com/#R1F8YU#102\n * @param vector defines the Vector3 to project\n * @param world defines the world matrix to use\n * @param transform defines the transform (view x projection) matrix to use\n * @param viewport defines the screen viewport to use\n * @param result the vector in which the screen space will be stored\n * @returns result input\n */\n static ProjectToRef(vector, world, transform, viewport, result) {\n const cw = viewport.width;\n const ch = viewport.height;\n const cx = viewport.x;\n const cy = viewport.y;\n const viewportMatrix = MathTmp.Matrix[1];\n Matrix.FromValuesToRef(cw / 2.0, 0, 0, 0, 0, -ch / 2.0, 0, 0, 0, 0, 0.5, 0, cx + cw / 2.0, ch / 2.0 + cy, 0.5, 1, viewportMatrix);\n const matrix = MathTmp.Matrix[0];\n world.multiplyToRef(transform, matrix);\n matrix.multiplyToRef(viewportMatrix, matrix);\n Vector3.TransformCoordinatesToRef(vector, matrix, result);\n return result;\n }\n /**\n * Reflects a vector off the plane defined by a normalized normal\n * @param inDirection defines the vector direction\n * @param normal defines the normal - Must be normalized\n * @returns the resulting vector\n */\n static Reflect(inDirection, normal) {\n return this.ReflectToRef(inDirection, normal, new Vector3());\n }\n /**\n * Reflects a vector off the plane defined by a normalized normal to reference\n * @param inDirection defines the vector direction\n * @param normal defines the normal - Must be normalized\n * @param result defines the Vector3 where to store the result\n * @returns the resulting vector\n */\n static ReflectToRef(inDirection, normal, ref) {\n const tmp = TmpVectors.Vector3[0];\n tmp.copyFrom(normal).scaleInPlace(2 * Vector3.Dot(inDirection, normal));\n return ref.copyFrom(inDirection).subtractInPlace(tmp);\n }\n /**\n * @internal\n */\n static _UnprojectFromInvertedMatrixToRef(source, matrix, result) {\n Vector3.TransformCoordinatesToRef(source, matrix, result);\n const m = matrix.m;\n const num = source._x * m[3] + source._y * m[7] + source._z * m[11] + m[15];\n if (Scalar.WithinEpsilon(num, 1.0)) {\n result.scaleInPlace(1.0 / num);\n }\n return result;\n }\n /**\n * Unproject from screen space to object space\n * Example Playground https://playground.babylonjs.com/#R1F8YU#121\n * @param source defines the screen space Vector3 to use\n * @param viewportWidth defines the current width of the viewport\n * @param viewportHeight defines the current height of the viewport\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\n * @param transform defines the transform (view x projection) matrix to use\n * @returns the new Vector3\n */\n static UnprojectFromTransform(source, viewportWidth, viewportHeight, world, transform) {\n return this.Unproject(source, viewportWidth, viewportHeight, world, transform, Matrix.IdentityReadOnly);\n }\n /**\n * Unproject from screen space to object space\n * Example Playground https://playground.babylonjs.com/#R1F8YU#117\n * @param source defines the screen space Vector3 to use\n * @param viewportWidth defines the current width of the viewport\n * @param viewportHeight defines the current height of the viewport\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\n * @param view defines the view matrix to use\n * @param projection defines the projection matrix to use\n * @returns the new Vector3\n */\n static Unproject(source, viewportWidth, viewportHeight, world, view, projection) {\n const result = new source.constructor();\n Vector3.UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result);\n return result;\n }\n /**\n * Unproject from screen space to object space\n * Example Playground https://playground.babylonjs.com/#R1F8YU#119\n * @param source defines the screen space Vector3 to use\n * @param viewportWidth defines the current width of the viewport\n * @param viewportHeight defines the current height of the viewport\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\n * @param view defines the view matrix to use\n * @param projection defines the projection matrix to use\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result) {\n Vector3.UnprojectFloatsToRef(source._x, source._y, source._z, viewportWidth, viewportHeight, world, view, projection, result);\n return result;\n }\n /**\n * Unproject from screen space to object space\n * Example Playground https://playground.babylonjs.com/#R1F8YU#120\n * @param sourceX defines the screen space x coordinate to use\n * @param sourceY defines the screen space y coordinate to use\n * @param sourceZ defines the screen space z coordinate to use\n * @param viewportWidth defines the current width of the viewport\n * @param viewportHeight defines the current height of the viewport\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\n * @param view defines the view matrix to use\n * @param projection defines the projection matrix to use\n * @param result defines the Vector3 where to store the result\n * @returns result input\n */\n static UnprojectFloatsToRef(sourceX, sourceY, sourceZ, viewportWidth, viewportHeight, world, view, projection, result) {\n var _a;\n const matrix = MathTmp.Matrix[0];\n world.multiplyToRef(view, matrix);\n matrix.multiplyToRef(projection, matrix);\n matrix.invert();\n const screenSource = MathTmp.Vector3[0];\n screenSource.x = (sourceX / viewportWidth) * 2 - 1;\n screenSource.y = -((sourceY / viewportHeight) * 2 - 1);\n if ((_a = EngineStore.LastCreatedEngine) === null || _a === void 0 ? void 0 : _a.isNDCHalfZRange) {\n screenSource.z = sourceZ;\n }\n else {\n screenSource.z = 2 * sourceZ - 1.0;\n }\n Vector3._UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);\n return result;\n }\n /**\n * Gets the minimal coordinate values between two Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#97\n * @param left defines the first operand\n * @param right defines the second operand\n * @returns the new Vector3\n */\n static Minimize(left, right) {\n const min = new left.constructor();\n min.copyFrom(left);\n min.minimizeInPlace(right);\n return min;\n }\n /**\n * Gets the maximal coordinate values between two Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#96\n * @param left defines the first operand\n * @param right defines the second operand\n * @returns the new Vector3\n */\n static Maximize(left, right) {\n const max = new left.constructor();\n max.copyFrom(left);\n max.maximizeInPlace(right);\n return max;\n }\n /**\n * Returns the distance between the vectors \"value1\" and \"value2\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#81\n * @param value1 defines the first operand\n * @param value2 defines the second operand\n * @returns the distance\n */\n static Distance(value1, value2) {\n return Math.sqrt(Vector3.DistanceSquared(value1, value2));\n }\n /**\n * Returns the squared distance between the vectors \"value1\" and \"value2\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#80\n * @param value1 defines the first operand\n * @param value2 defines the second operand\n * @returns the squared distance\n */\n static DistanceSquared(value1, value2) {\n const x = value1._x - value2._x;\n const y = value1._y - value2._y;\n const z = value1._z - value2._z;\n return x * x + y * y + z * z;\n }\n /**\n * Projects \"vector\" on the triangle determined by its extremities \"p0\", \"p1\" and \"p2\", stores the result in \"ref\"\n * and returns the distance to the projected point.\n * Example Playground https://playground.babylonjs.com/#R1F8YU#104\n * From http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.4264&rep=rep1&type=pdf\n *\n * @param vector the vector to get distance from\n * @param p0 extremity of the triangle\n * @param p1 extremity of the triangle\n * @param p2 extremity of the triangle\n * @param ref variable to store the result to\n * @returns The distance between \"ref\" and \"vector\"\n */\n static ProjectOnTriangleToRef(vector, p0, p1, p2, ref) {\n const p1p0 = MathTmp.Vector3[0];\n const p2p0 = MathTmp.Vector3[1];\n const p2p1 = MathTmp.Vector3[2];\n const normal = MathTmp.Vector3[3];\n const vectorp0 = MathTmp.Vector3[4];\n // Triangle vectors\n p1.subtractToRef(p0, p1p0);\n p2.subtractToRef(p0, p2p0);\n p2.subtractToRef(p1, p2p1);\n const p1p0L = p1p0.length();\n const p2p0L = p2p0.length();\n const p2p1L = p2p1.length();\n if (p1p0L < Epsilon || p2p0L < Epsilon || p2p1L < Epsilon) {\n // This is a degenerate triangle. As we assume this is part of a non-degenerate mesh,\n // we will find a better intersection later.\n // Let's just return one of the extremities\n ref.copyFrom(p0);\n return Vector3.Distance(vector, p0);\n }\n // Compute normal and vector to p0\n vector.subtractToRef(p0, vectorp0);\n Vector3.CrossToRef(p1p0, p2p0, normal);\n const nl = normal.length();\n if (nl < Epsilon) {\n // Extremities are aligned, we are back on the case of a degenerate triangle\n ref.copyFrom(p0);\n return Vector3.Distance(vector, p0);\n }\n normal.normalizeFromLength(nl);\n let l = vectorp0.length();\n if (l < Epsilon) {\n // Vector is p0\n ref.copyFrom(p0);\n return 0;\n }\n vectorp0.normalizeFromLength(l);\n // Project to \"proj\" that lies on the triangle plane\n const cosA = Vector3.Dot(normal, vectorp0);\n const projVector = MathTmp.Vector3[5];\n const proj = MathTmp.Vector3[6];\n projVector.copyFrom(normal).scaleInPlace(-l * cosA);\n proj.copyFrom(vector).addInPlace(projVector);\n // Compute barycentric coordinates (v0, v1 and v2 are axis from barycenter to extremities)\n const v0 = MathTmp.Vector3[4];\n const v1 = MathTmp.Vector3[5];\n const v2 = MathTmp.Vector3[7];\n const tmp = MathTmp.Vector3[8];\n v0.copyFrom(p1p0).scaleInPlace(1 / p1p0L);\n tmp.copyFrom(p2p0).scaleInPlace(1 / p2p0L);\n v0.addInPlace(tmp).scaleInPlace(-1);\n v1.copyFrom(p1p0).scaleInPlace(-1 / p1p0L);\n tmp.copyFrom(p2p1).scaleInPlace(1 / p2p1L);\n v1.addInPlace(tmp).scaleInPlace(-1);\n v2.copyFrom(p2p1).scaleInPlace(-1 / p2p1L);\n tmp.copyFrom(p2p0).scaleInPlace(-1 / p2p0L);\n v2.addInPlace(tmp).scaleInPlace(-1);\n // Determines which edge of the triangle is closest to \"proj\"\n const projP = MathTmp.Vector3[9];\n let dot;\n projP.copyFrom(proj).subtractInPlace(p0);\n Vector3.CrossToRef(v0, projP, tmp);\n dot = Vector3.Dot(tmp, normal);\n const s0 = dot;\n projP.copyFrom(proj).subtractInPlace(p1);\n Vector3.CrossToRef(v1, projP, tmp);\n dot = Vector3.Dot(tmp, normal);\n const s1 = dot;\n projP.copyFrom(proj).subtractInPlace(p2);\n Vector3.CrossToRef(v2, projP, tmp);\n dot = Vector3.Dot(tmp, normal);\n const s2 = dot;\n const edge = MathTmp.Vector3[10];\n let e0, e1;\n if (s0 > 0 && s1 < 0) {\n edge.copyFrom(p1p0);\n e0 = p0;\n e1 = p1;\n }\n else if (s1 > 0 && s2 < 0) {\n edge.copyFrom(p2p1);\n e0 = p1;\n e1 = p2;\n }\n else {\n edge.copyFrom(p2p0).scaleInPlace(-1);\n e0 = p2;\n e1 = p0;\n }\n // Determines if \"proj\" lies inside the triangle\n const tmp2 = MathTmp.Vector3[9];\n const tmp3 = MathTmp.Vector3[4];\n e0.subtractToRef(proj, tmp);\n e1.subtractToRef(proj, tmp2);\n Vector3.CrossToRef(tmp, tmp2, tmp3);\n const isOutside = Vector3.Dot(tmp3, normal) < 0;\n // If inside, we already found the projected point, \"proj\"\n if (!isOutside) {\n ref.copyFrom(proj);\n return Math.abs(l * cosA);\n }\n // If outside, we find \"triProj\", the closest point from \"proj\" on the closest edge\n const r = MathTmp.Vector3[5];\n Vector3.CrossToRef(edge, tmp3, r);\n r.normalize();\n const e0proj = MathTmp.Vector3[9];\n e0proj.copyFrom(e0).subtractInPlace(proj);\n const e0projL = e0proj.length();\n if (e0projL < Epsilon) {\n // Proj is e0\n ref.copyFrom(e0);\n return Vector3.Distance(vector, e0);\n }\n e0proj.normalizeFromLength(e0projL);\n const cosG = Vector3.Dot(r, e0proj);\n const triProj = MathTmp.Vector3[7];\n triProj.copyFrom(proj).addInPlace(r.scaleInPlace(e0projL * cosG));\n // Now we clamp \"triProj\" so it lies between e0 and e1\n tmp.copyFrom(triProj).subtractInPlace(e0);\n l = edge.length();\n edge.normalizeFromLength(l);\n let t = Vector3.Dot(tmp, edge) / Math.max(l, Epsilon);\n t = Scalar.Clamp(t, 0, 1);\n triProj.copyFrom(e0).addInPlace(edge.scaleInPlace(t * l));\n ref.copyFrom(triProj);\n return Vector3.Distance(vector, triProj);\n }\n /**\n * Returns a new Vector3 located at the center between \"value1\" and \"value2\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#72\n * @param value1 defines the first operand\n * @param value2 defines the second operand\n * @returns the new Vector3\n */\n static Center(value1, value2) {\n return Vector3.CenterToRef(value1, value2, Vector3.Zero());\n }\n /**\n * Gets the center of the vectors \"value1\" and \"value2\" and stores the result in the vector \"ref\"\n * Example Playground https://playground.babylonjs.com/#R1F8YU#73\n * @param value1 defines first vector\n * @param value2 defines second vector\n * @param ref defines third vector\n * @returns ref\n */\n static CenterToRef(value1, value2, ref) {\n return ref.copyFromFloats((value1._x + value2._x) / 2, (value1._y + value2._y) / 2, (value1._z + value2._z) / 2);\n }\n /**\n * Given three orthogonal normalized left-handed oriented Vector3 axis in space (target system),\n * RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply\n * to something in order to rotate it from its local system to the given target system\n * Note: axis1, axis2 and axis3 are normalized during this operation\n * Example Playground https://playground.babylonjs.com/#R1F8YU#106\n * @param axis1 defines the first axis\n * @param axis2 defines the second axis\n * @param axis3 defines the third axis\n * @returns a new Vector3\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/target_align\n */\n static RotationFromAxis(axis1, axis2, axis3) {\n const rotation = new axis1.constructor();\n Vector3.RotationFromAxisToRef(axis1, axis2, axis3, rotation);\n return rotation;\n }\n /**\n * The same than RotationFromAxis but updates the given ref Vector3 parameter instead of returning a new Vector3\n * Example Playground https://playground.babylonjs.com/#R1F8YU#107\n * @param axis1 defines the first axis\n * @param axis2 defines the second axis\n * @param axis3 defines the third axis\n * @param ref defines the Vector3 where to store the result\n * @returns result input\n */\n static RotationFromAxisToRef(axis1, axis2, axis3, ref) {\n const quat = MathTmp.Quaternion[0];\n Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);\n quat.toEulerAnglesToRef(ref);\n return ref;\n }\n }\n Vector3._UpReadOnly = Vector3.Up();\n Vector3._DownReadOnly = Vector3.Down();\n Vector3._LeftHandedForwardReadOnly = Vector3.Forward(false);\n Vector3._RightHandedForwardReadOnly = Vector3.Forward(true);\n Vector3._LeftHandedBackwardReadOnly = Vector3.Backward(false);\n Vector3._RightHandedBackwardReadOnly = Vector3.Backward(true);\n Vector3._RightReadOnly = Vector3.Right();\n Vector3._LeftReadOnly = Vector3.Left();\n Vector3._ZeroReadOnly = Vector3.Zero();\n Vector3._OneReadOnly = Vector3.One();\n /**\n * Vector4 class created for EulerAngle class conversion to Quaternion\n */\n class Vector4 {\n /**\n * Creates a Vector4 object from the given floats.\n * @param x x value of the vector\n * @param y y value of the vector\n * @param z z value of the vector\n * @param w w value of the vector\n */\n constructor(\n /** x value of the vector */\n x = 0, \n /** y value of the vector */\n y = 0, \n /** z value of the vector */\n z = 0, \n /** w value of the vector */\n w = 0) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n }\n /**\n * Returns the string with the Vector4 coordinates.\n * @returns a string containing all the vector values\n */\n toString() {\n return `{X: ${this.x} Y: ${this.y} Z: ${this.z} W: ${this.w}}`;\n }\n /**\n * Returns the string \"Vector4\".\n * @returns \"Vector4\"\n */\n getClassName() {\n return \"Vector4\";\n }\n /**\n * Returns the Vector4 hash code.\n * @returns a unique hash code\n */\n getHashCode() {\n const x = _ExtractAsInt(this.x);\n const y = _ExtractAsInt(this.y);\n const z = _ExtractAsInt(this.z);\n const w = _ExtractAsInt(this.w);\n let hash = x;\n hash = (hash * 397) ^ y;\n hash = (hash * 397) ^ z;\n hash = (hash * 397) ^ w;\n return hash;\n }\n // Operators\n /**\n * Returns a new array populated with 4 elements : the Vector4 coordinates.\n * @returns the resulting array\n */\n asArray() {\n const result = new Array();\n this.toArray(result, 0);\n return result;\n }\n /**\n * Populates the given array from the given index with the Vector4 coordinates.\n * @param array array to populate\n * @param index index of the array to start at (default: 0)\n * @returns the Vector4.\n */\n toArray(array, index) {\n if (index === undefined) {\n index = 0;\n }\n array[index] = this.x;\n array[index + 1] = this.y;\n array[index + 2] = this.z;\n array[index + 3] = this.w;\n return this;\n }\n /**\n * Update the current vector from an array\n * @param array defines the destination array\n * @param index defines the offset in the destination array\n * @returns the current Vector3\n */\n fromArray(array, index = 0) {\n Vector4.FromArrayToRef(array, index, this);\n return this;\n }\n /**\n * Adds the given vector to the current Vector4.\n * @param otherVector the vector to add\n * @returns the updated Vector4.\n */\n addInPlace(otherVector) {\n this.x += otherVector.x;\n this.y += otherVector.y;\n this.z += otherVector.z;\n this.w += otherVector.w;\n return this;\n }\n /**\n * Returns a new Vector4 as the result of the addition of the current Vector4 and the given one.\n * @param otherVector the vector to add\n * @returns the resulting vector\n */\n add(otherVector) {\n return new this.constructor(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z, this.w + otherVector.w);\n }\n /**\n * Updates the given vector \"result\" with the result of the addition of the current Vector4 and the given one.\n * @param otherVector the vector to add\n * @param result the vector to store the result\n * @returns result input\n */\n addToRef(otherVector, result) {\n result.x = this.x + otherVector.x;\n result.y = this.y + otherVector.y;\n result.z = this.z + otherVector.z;\n result.w = this.w + otherVector.w;\n return result;\n }\n /**\n * Subtract in place the given vector from the current Vector4.\n * @param otherVector the vector to subtract\n * @returns the updated Vector4.\n */\n subtractInPlace(otherVector) {\n this.x -= otherVector.x;\n this.y -= otherVector.y;\n this.z -= otherVector.z;\n this.w -= otherVector.w;\n return this;\n }\n /**\n * Returns a new Vector4 with the result of the subtraction of the given vector from the current Vector4.\n * @param otherVector the vector to add\n * @returns the new vector with the result\n */\n subtract(otherVector) {\n return new this.constructor(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z, this.w - otherVector.w);\n }\n /**\n * Sets the given vector \"result\" with the result of the subtraction of the given vector from the current Vector4.\n * @param otherVector the vector to subtract\n * @param result the vector to store the result\n * @returns result input\n */\n subtractToRef(otherVector, result) {\n result.x = this.x - otherVector.x;\n result.y = this.y - otherVector.y;\n result.z = this.z - otherVector.z;\n result.w = this.w - otherVector.w;\n return result;\n }\n /**\n * Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.\n */\n /**\n * Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.\n * @param x value to subtract\n * @param y value to subtract\n * @param z value to subtract\n * @param w value to subtract\n * @returns new vector containing the result\n */\n subtractFromFloats(x, y, z, w) {\n return new this.constructor(this.x - x, this.y - y, this.z - z, this.w - w);\n }\n /**\n * Sets the given vector \"result\" set with the result of the subtraction of the given floats from the current Vector4 coordinates.\n * @param x value to subtract\n * @param y value to subtract\n * @param z value to subtract\n * @param w value to subtract\n * @param result the vector to store the result in\n * @returns result input\n */\n subtractFromFloatsToRef(x, y, z, w, result) {\n result.x = this.x - x;\n result.y = this.y - y;\n result.z = this.z - z;\n result.w = this.w - w;\n return result;\n }\n /**\n * Returns a new Vector4 set with the current Vector4 negated coordinates.\n * @returns a new vector with the negated values\n */\n negate() {\n return new this.constructor(-this.x, -this.y, -this.z, -this.w);\n }\n /**\n * Negate this vector in place\n * @returns this\n */\n negateInPlace() {\n this.x *= -1;\n this.y *= -1;\n this.z *= -1;\n this.w *= -1;\n return this;\n }\n /**\n * Negate the current Vector4 and stores the result in the given vector \"result\" coordinates\n * @param result defines the Vector3 object where to store the result\n * @returns the result\n */\n negateToRef(result) {\n return result.copyFromFloats(this.x * -1, this.y * -1, this.z * -1, this.w * -1);\n }\n /**\n * Multiplies the current Vector4 coordinates by scale (float).\n * @param scale the number to scale with\n * @returns the updated Vector4.\n */\n scaleInPlace(scale) {\n this.x *= scale;\n this.y *= scale;\n this.z *= scale;\n this.w *= scale;\n return this;\n }\n /**\n * Returns a new Vector4 set with the current Vector4 coordinates multiplied by scale (float).\n * @param scale the number to scale with\n * @returns a new vector with the result\n */\n scale(scale) {\n return new this.constructor(this.x * scale, this.y * scale, this.z * scale, this.w * scale);\n }\n /**\n * Sets the given vector \"result\" with the current Vector4 coordinates multiplied by scale (float).\n * @param scale the number to scale with\n * @param result a vector to store the result in\n * @returns result input\n */\n scaleToRef(scale, result) {\n result.x = this.x * scale;\n result.y = this.y * scale;\n result.z = this.z * scale;\n result.w = this.w * scale;\n return result;\n }\n /**\n * Scale the current Vector4 values by a factor and add the result to a given Vector4\n * @param scale defines the scale factor\n * @param result defines the Vector4 object where to store the result\n * @returns result input\n */\n scaleAndAddToRef(scale, result) {\n result.x += this.x * scale;\n result.y += this.y * scale;\n result.z += this.z * scale;\n result.w += this.w * scale;\n return result;\n }\n /**\n * Boolean : True if the current Vector4 coordinates are stricly equal to the given ones.\n * @param otherVector the vector to compare against\n * @returns true if they are equal\n */\n equals(otherVector) {\n return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z && this.w === otherVector.w;\n }\n /**\n * Boolean : True if the current Vector4 coordinates are each beneath the distance \"epsilon\" from the given vector ones.\n * @param otherVector vector to compare against\n * @param epsilon (Default: very small number)\n * @returns true if they are equal\n */\n equalsWithEpsilon(otherVector, epsilon = Epsilon) {\n return (otherVector &&\n Scalar.WithinEpsilon(this.x, otherVector.x, epsilon) &&\n Scalar.WithinEpsilon(this.y, otherVector.y, epsilon) &&\n Scalar.WithinEpsilon(this.z, otherVector.z, epsilon) &&\n Scalar.WithinEpsilon(this.w, otherVector.w, epsilon));\n }\n /**\n * Boolean : True if the given floats are strictly equal to the current Vector4 coordinates.\n * @param x x value to compare against\n * @param y y value to compare against\n * @param z z value to compare against\n * @param w w value to compare against\n * @returns true if equal\n */\n equalsToFloats(x, y, z, w) {\n return this.x === x && this.y === y && this.z === z && this.w === w;\n }\n /**\n * Multiplies in place the current Vector4 by the given one.\n * @param otherVector vector to multiple with\n * @returns the updated Vector4.\n */\n multiplyInPlace(otherVector) {\n this.x *= otherVector.x;\n this.y *= otherVector.y;\n this.z *= otherVector.z;\n this.w *= otherVector.w;\n return this;\n }\n /**\n * Returns a new Vector4 set with the multiplication result of the current Vector4 and the given one.\n * @param otherVector vector to multiple with\n * @returns resulting new vector\n */\n multiply(otherVector) {\n return new this.constructor(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z, this.w * otherVector.w);\n }\n /**\n * Updates the given vector \"result\" with the multiplication result of the current Vector4 and the given one.\n * @param otherVector vector to multiple with\n * @param result vector to store the result\n * @returns result input\n */\n multiplyToRef(otherVector, result) {\n result.x = this.x * otherVector.x;\n result.y = this.y * otherVector.y;\n result.z = this.z * otherVector.z;\n result.w = this.w * otherVector.w;\n return result;\n }\n /**\n * Returns a new Vector4 set with the multiplication result of the given floats and the current Vector4 coordinates.\n * @param x x value multiply with\n * @param y y value multiply with\n * @param z z value multiply with\n * @param w w value multiply with\n * @returns resulting new vector\n */\n multiplyByFloats(x, y, z, w) {\n return new this.constructor(this.x * x, this.y * y, this.z * z, this.w * w);\n }\n /**\n * Returns a new Vector4 set with the division result of the current Vector4 by the given one.\n * @param otherVector vector to devide with\n * @returns resulting new vector\n */\n divide(otherVector) {\n return new this.constructor(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z, this.w / otherVector.w);\n }\n /**\n * Updates the given vector \"result\" with the division result of the current Vector4 by the given one.\n * @param otherVector vector to devide with\n * @param result vector to store the result\n * @returns result input\n */\n divideToRef(otherVector, result) {\n result.x = this.x / otherVector.x;\n result.y = this.y / otherVector.y;\n result.z = this.z / otherVector.z;\n result.w = this.w / otherVector.w;\n return result;\n }\n /**\n * Divides the current Vector3 coordinates by the given ones.\n * @param otherVector vector to devide with\n * @returns the updated Vector3.\n */\n divideInPlace(otherVector) {\n return this.divideToRef(otherVector, this);\n }\n /**\n * Updates the Vector4 coordinates with the minimum values between its own and the given vector ones\n * @param other defines the second operand\n * @returns the current updated Vector4\n */\n minimizeInPlace(other) {\n if (other.x < this.x) {\n this.x = other.x;\n }\n if (other.y < this.y) {\n this.y = other.y;\n }\n if (other.z < this.z) {\n this.z = other.z;\n }\n if (other.w < this.w) {\n this.w = other.w;\n }\n return this;\n }\n /**\n * Updates the Vector4 coordinates with the maximum values between its own and the given vector ones\n * @param other defines the second operand\n * @returns the current updated Vector4\n */\n maximizeInPlace(other) {\n if (other.x > this.x) {\n this.x = other.x;\n }\n if (other.y > this.y) {\n this.y = other.y;\n }\n if (other.z > this.z) {\n this.z = other.z;\n }\n if (other.w > this.w) {\n this.w = other.w;\n }\n return this;\n }\n /**\n * Gets a new Vector4 from current Vector4 floored values\n * @returns a new Vector4\n */\n floor() {\n return new this.constructor(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z), Math.floor(this.w));\n }\n /**\n * Gets a new Vector4 from current Vector4 fractional values\n * @returns a new Vector4\n */\n fract() {\n return new this.constructor(this.x - Math.floor(this.x), this.y - Math.floor(this.y), this.z - Math.floor(this.z), this.w - Math.floor(this.w));\n }\n // Properties\n /**\n * Returns the Vector4 length (float).\n * @returns the length\n */\n length() {\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);\n }\n /**\n * Returns the Vector4 squared length (float).\n * @returns the length squared\n */\n lengthSquared() {\n return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;\n }\n // Methods\n /**\n * Normalizes in place the Vector4.\n * @returns the updated Vector4.\n */\n normalize() {\n const len = this.length();\n if (len === 0) {\n return this;\n }\n return this.scaleInPlace(1.0 / len);\n }\n /**\n * Returns a new Vector3 from the Vector4 (x, y, z) coordinates.\n * @returns this converted to a new vector3\n */\n toVector3() {\n return new Vector3(this.x, this.y, this.z);\n }\n /**\n * Returns a new Vector4 copied from the current one.\n * @returns the new cloned vector\n */\n clone() {\n return new this.constructor(this.x, this.y, this.z, this.w);\n }\n /**\n * Updates the current Vector4 with the given one coordinates.\n * @param source the source vector to copy from\n * @returns the updated Vector4.\n */\n copyFrom(source) {\n this.x = source.x;\n this.y = source.y;\n this.z = source.z;\n this.w = source.w;\n return this;\n }\n /**\n * Updates the current Vector4 coordinates with the given floats.\n * @param x float to copy from\n * @param y float to copy from\n * @param z float to copy from\n * @param w float to copy from\n * @returns the updated Vector4.\n */\n copyFromFloats(x, y, z, w) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n return this;\n }\n /**\n * Updates the current Vector4 coordinates with the given floats.\n * @param x float to set from\n * @param y float to set from\n * @param z float to set from\n * @param w float to set from\n * @returns the updated Vector4.\n */\n set(x, y, z, w) {\n return this.copyFromFloats(x, y, z, w);\n }\n /**\n * Copies the given float to the current Vector3 coordinates\n * @param v defines the x, y, z and w coordinates of the operand\n * @returns the current updated Vector3\n */\n setAll(v) {\n this.x = this.y = this.z = this.w = v;\n return this;\n }\n // Statics\n /**\n * Returns a new Vector4 set from the starting index of the given array.\n * @param array the array to pull values from\n * @param offset the offset into the array to start at\n * @returns the new vector\n */\n static FromArray(array, offset) {\n if (!offset) {\n offset = 0;\n }\n return new Vector4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\n }\n /**\n * Updates the given vector \"result\" from the starting index of the given array.\n * @param array the array to pull values from\n * @param offset the offset into the array to start at\n * @param result the vector to store the result in\n * @returns result input\n */\n static FromArrayToRef(array, offset, result) {\n result.x = array[offset];\n result.y = array[offset + 1];\n result.z = array[offset + 2];\n result.w = array[offset + 3];\n return result;\n }\n /**\n * Updates the given vector \"result\" from the starting index of the given Float32Array.\n * @param array the array to pull values from\n * @param offset the offset into the array to start at\n * @param result the vector to store the result in\n * @returns result input\n */\n static FromFloatArrayToRef(array, offset, result) {\n Vector4.FromArrayToRef(array, offset, result);\n return result;\n }\n /**\n * Updates the given vector \"result\" coordinates from the given floats.\n * @param x float to set from\n * @param y float to set from\n * @param z float to set from\n * @param w float to set from\n * @param result the vector to the floats in\n * @returns result input\n */\n static FromFloatsToRef(x, y, z, w, result) {\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n }\n /**\n * Returns a new Vector4 set to (0.0, 0.0, 0.0, 0.0)\n * @returns the new vector\n */\n static Zero() {\n return new Vector4(0.0, 0.0, 0.0, 0.0);\n }\n /**\n * Returns a new Vector4 set to (1.0, 1.0, 1.0, 1.0)\n * @returns the new vector\n */\n static One() {\n return new Vector4(1.0, 1.0, 1.0, 1.0);\n }\n /**\n * Returns a new Vector4 with random values between min and max\n * @param min the minimum random value\n * @param max the maximum random value\n * @returns a Vector4 with random values between min and max\n */\n static Random(min = 0, max = 1) {\n return new Vector4(Scalar.RandomRange(min, max), Scalar.RandomRange(min, max), Scalar.RandomRange(min, max), Scalar.RandomRange(min, max));\n }\n /**\n * Gets a zero Vector4 that must not be updated\n */\n static get ZeroReadOnly() {\n return Vector4._ZeroReadOnly;\n }\n /**\n * Returns a new normalized Vector4 from the given one.\n * @param vector the vector to normalize\n * @returns the vector\n */\n static Normalize(vector) {\n const result = Vector4.Zero();\n Vector4.NormalizeToRef(vector, result);\n return result;\n }\n /**\n * Updates the given vector \"result\" from the normalization of the given one.\n * @param vector the vector to normalize\n * @param result the vector to store the result in\n * @returns result input\n */\n static NormalizeToRef(vector, result) {\n result.copyFrom(vector);\n result.normalize();\n return result;\n }\n /**\n * Returns a vector with the minimum values from the left and right vectors\n * @param left left vector to minimize\n * @param right right vector to minimize\n * @returns a new vector with the minimum of the left and right vector values\n */\n static Minimize(left, right) {\n const min = new left.constructor();\n min.copyFrom(left);\n min.minimizeInPlace(right);\n return min;\n }\n /**\n * Returns a vector with the maximum values from the left and right vectors\n * @param left left vector to maximize\n * @param right right vector to maximize\n * @returns a new vector with the maximum of the left and right vector values\n */\n static Maximize(left, right) {\n const max = new left.constructor();\n max.copyFrom(left);\n max.maximizeInPlace(right);\n return max;\n }\n /**\n * Returns the distance (float) between the vectors \"value1\" and \"value2\".\n * @param value1 value to calulate the distance between\n * @param value2 value to calulate the distance between\n * @returns the distance between the two vectors\n */\n static Distance(value1, value2) {\n return Math.sqrt(Vector4.DistanceSquared(value1, value2));\n }\n /**\n * Returns the squared distance (float) between the vectors \"value1\" and \"value2\".\n * @param value1 value to calulate the distance between\n * @param value2 value to calulate the distance between\n * @returns the distance between the two vectors squared\n */\n static DistanceSquared(value1, value2) {\n const x = value1.x - value2.x;\n const y = value1.y - value2.y;\n const z = value1.z - value2.z;\n const w = value1.w - value2.w;\n return x * x + y * y + z * z + w * w;\n }\n /**\n * Returns a new Vector4 located at the center between the vectors \"value1\" and \"value2\".\n * @param value1 value to calulate the center between\n * @param value2 value to calulate the center between\n * @returns the center between the two vectors\n */\n static Center(value1, value2) {\n return Vector4.CenterToRef(value1, value2, Vector4.Zero());\n }\n /**\n * Gets the center of the vectors \"value1\" and \"value2\" and stores the result in the vector \"ref\"\n * @param value1 defines first vector\n * @param value2 defines second vector\n * @param ref defines third vector\n * @returns ref\n */\n static CenterToRef(value1, value2, ref) {\n return ref.copyFromFloats((value1.x + value2.x) / 2, (value1.y + value2.y) / 2, (value1.z + value2.z) / 2, (value1.w + value2.w) / 2);\n }\n /**\n * Returns a new Vector4 set with the result of the transformation by the given matrix of the given vector.\n * This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\n * The difference with Vector3.TransformCoordinates is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead\n * @param vector defines the Vector3 to transform\n * @param transformation defines the transformation matrix\n * @returns the transformed Vector4\n */\n static TransformCoordinates(vector, transformation) {\n const result = Vector4.Zero();\n Vector4.TransformCoordinatesToRef(vector, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given vector\n * This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\n * The difference with Vector3.TransformCoordinatesToRef is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead\n * @param vector defines the Vector3 to transform\n * @param transformation defines the transformation matrix\n * @param result defines the Vector4 where to store the result\n * @returns result input\n */\n static TransformCoordinatesToRef(vector, transformation, result) {\n Vector4.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)\n * This method computes tranformed coordinates only, not transformed direction vectors\n * The difference with Vector3.TransformCoordinatesFromFloatsToRef is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead\n * @param x define the x coordinate of the source vector\n * @param y define the y coordinate of the source vector\n * @param z define the z coordinate of the source vector\n * @param transformation defines the transformation matrix\n * @param result defines the Vector4 where to store the result\n * @returns result input\n */\n static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) {\n const m = transformation.m;\n const rx = x * m[0] + y * m[4] + z * m[8] + m[12];\n const ry = x * m[1] + y * m[5] + z * m[9] + m[13];\n const rz = x * m[2] + y * m[6] + z * m[10] + m[14];\n const rw = x * m[3] + y * m[7] + z * m[11] + m[15];\n result.x = rx;\n result.y = ry;\n result.z = rz;\n result.w = rw;\n return result;\n }\n /**\n * Returns a new Vector4 set with the result of the normal transformation by the given matrix of the given vector.\n * This methods computes transformed normalized direction vectors only.\n * @param vector the vector to transform\n * @param transformation the transformation matrix to apply\n * @returns the new vector\n */\n static TransformNormal(vector, transformation) {\n const result = new vector.constructor();\n Vector4.TransformNormalToRef(vector, transformation, result);\n return result;\n }\n /**\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given vector.\n * This methods computes transformed normalized direction vectors only.\n * @param vector the vector to transform\n * @param transformation the transformation matrix to apply\n * @param result the vector to store the result in\n * @returns result input\n */\n static TransformNormalToRef(vector, transformation, result) {\n const m = transformation.m;\n const x = vector.x * m[0] + vector.y * m[4] + vector.z * m[8];\n const y = vector.x * m[1] + vector.y * m[5] + vector.z * m[9];\n const z = vector.x * m[2] + vector.y * m[6] + vector.z * m[10];\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = vector.w;\n return result;\n }\n /**\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given floats (x, y, z, w).\n * This methods computes transformed normalized direction vectors only.\n * @param x value to transform\n * @param y value to transform\n * @param z value to transform\n * @param w value to transform\n * @param transformation the transformation matrix to apply\n * @param result the vector to store the results in\n * @returns result input\n */\n static TransformNormalFromFloatsToRef(x, y, z, w, transformation, result) {\n const m = transformation.m;\n result.x = x * m[0] + y * m[4] + z * m[8];\n result.y = x * m[1] + y * m[5] + z * m[9];\n result.z = x * m[2] + y * m[6] + z * m[10];\n result.w = w;\n return result;\n }\n /**\n * Creates a new Vector4 from a Vector3\n * @param source defines the source data\n * @param w defines the 4th component (default is 0)\n * @returns a new Vector4\n */\n static FromVector3(source, w = 0) {\n return new Vector4(source._x, source._y, source._z, w);\n }\n }\n Vector4._ZeroReadOnly = Vector4.Zero();\n /**\n * Class used to store quaternion data\n * Example Playground - Overview - https://playground.babylonjs.com/#L49EJ7#100\n * @see https://en.wikipedia.org/wiki/Quaternion\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms\n */\n class Quaternion {\n /** Gets or sets the x coordinate */\n get x() {\n return this._x;\n }\n set x(value) {\n this._x = value;\n this._isDirty = true;\n }\n /** Gets or sets the y coordinate */\n get y() {\n return this._y;\n }\n set y(value) {\n this._y = value;\n this._isDirty = true;\n }\n /** Gets or sets the z coordinate */\n get z() {\n return this._z;\n }\n set z(value) {\n this._z = value;\n this._isDirty = true;\n }\n /** Gets or sets the w coordinate */\n get w() {\n return this._w;\n }\n set w(value) {\n this._w = value;\n this._isDirty = true;\n }\n /**\n * Creates a new Quaternion from the given floats\n * @param x defines the first component (0 by default)\n * @param y defines the second component (0 by default)\n * @param z defines the third component (0 by default)\n * @param w defines the fourth component (1.0 by default)\n */\n constructor(x = 0.0, y = 0.0, z = 0.0, w = 1.0) {\n /** @internal */\n this._isDirty = true;\n this._x = x;\n this._y = y;\n this._z = z;\n this._w = w;\n }\n /**\n * Gets a string representation for the current quaternion\n * @returns a string with the Quaternion coordinates\n */\n toString() {\n return `{X: ${this._x} Y: ${this._y} Z: ${this._z} W: ${this._w}}`;\n }\n /**\n * Gets the class name of the quaternion\n * @returns the string \"Quaternion\"\n */\n getClassName() {\n return \"Quaternion\";\n }\n /**\n * Gets a hash code for this quaternion\n * @returns the quaternion hash code\n */\n getHashCode() {\n const x = _ExtractAsInt(this._x);\n const y = _ExtractAsInt(this._y);\n const z = _ExtractAsInt(this._z);\n const w = _ExtractAsInt(this._w);\n let hash = x;\n hash = (hash * 397) ^ y;\n hash = (hash * 397) ^ z;\n hash = (hash * 397) ^ w;\n return hash;\n }\n /**\n * Copy the quaternion to an array\n * Example Playground https://playground.babylonjs.com/#L49EJ7#13\n * @returns a new array populated with 4 elements from the quaternion coordinates\n */\n asArray() {\n return [this._x, this._y, this._z, this._w];\n }\n /**\n * Stores from the starting index in the given array the Quaternion successive values\n * Example Playground https://playground.babylonjs.com/#L49EJ7#59\n * @param array defines the array where to store the x,y,z,w components\n * @param index defines an optional index in the target array to define where to start storing values\n * @returns the current Quaternion object\n */\n toArray(array, index = 0) {\n array[index] = this._x;\n array[index + 1] = this._y;\n array[index + 2] = this._z;\n array[index + 3] = this._w;\n return this;\n }\n /**\n * Check if two quaternions are equals\n * Example Playground https://playground.babylonjs.com/#L49EJ7#38\n * @param otherQuaternion defines the second operand\n * @returns true if the current quaternion and the given one coordinates are strictly equals\n */\n equals(otherQuaternion) {\n return otherQuaternion && this._x === otherQuaternion._x && this._y === otherQuaternion._y && this._z === otherQuaternion._z && this._w === otherQuaternion._w;\n }\n /**\n * Gets a boolean if two quaternions are equals (using an epsilon value)\n * Example Playground https://playground.babylonjs.com/#L49EJ7#37\n * @param otherQuaternion defines the other quaternion\n * @param epsilon defines the minimal distance to consider equality\n * @returns true if the given quaternion coordinates are close to the current ones by a distance of epsilon.\n */\n equalsWithEpsilon(otherQuaternion, epsilon = Epsilon) {\n return (otherQuaternion &&\n Scalar.WithinEpsilon(this._x, otherQuaternion._x, epsilon) &&\n Scalar.WithinEpsilon(this._y, otherQuaternion._y, epsilon) &&\n Scalar.WithinEpsilon(this._z, otherQuaternion._z, epsilon) &&\n Scalar.WithinEpsilon(this._w, otherQuaternion._w, epsilon));\n }\n /**\n * Clone the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#12\n * @returns a new quaternion copied from the current one\n */\n clone() {\n return new this.constructor(this._x, this._y, this._z, this._w);\n }\n /**\n * Copy a quaternion to the current one\n * Example Playground https://playground.babylonjs.com/#L49EJ7#86\n * @param other defines the other quaternion\n * @returns the updated current quaternion\n */\n copyFrom(other) {\n this._x = other._x;\n this._y = other._y;\n this._z = other._z;\n this._w = other._w;\n this._isDirty = true;\n return this;\n }\n /**\n * Updates the current quaternion with the given float coordinates\n * Example Playground https://playground.babylonjs.com/#L49EJ7#87\n * @param x defines the x coordinate\n * @param y defines the y coordinate\n * @param z defines the z coordinate\n * @param w defines the w coordinate\n * @returns the updated current quaternion\n */\n copyFromFloats(x, y, z, w) {\n this._x = x;\n this._y = y;\n this._z = z;\n this._w = w;\n this._isDirty = true;\n return this;\n }\n /**\n * Updates the current quaternion from the given float coordinates\n * Example Playground https://playground.babylonjs.com/#L49EJ7#56\n * @param x defines the x coordinate\n * @param y defines the y coordinate\n * @param z defines the z coordinate\n * @param w defines the w coordinate\n * @returns the updated current quaternion\n */\n set(x, y, z, w) {\n return this.copyFromFloats(x, y, z, w);\n }\n /**\n * Adds two quaternions\n * Example Playground https://playground.babylonjs.com/#L49EJ7#10\n * @param other defines the second operand\n * @returns a new quaternion as the addition result of the given one and the current quaternion\n */\n add(other) {\n return new this.constructor(this._x + other._x, this._y + other._y, this._z + other._z, this._w + other._w);\n }\n /**\n * Add a quaternion to the current one\n * Example Playground https://playground.babylonjs.com/#L49EJ7#11\n * @param other defines the quaternion to add\n * @returns the current quaternion\n */\n addInPlace(other) {\n this._x += other._x;\n this._y += other._y;\n this._z += other._z;\n this._w += other._w;\n this._isDirty = true;\n return this;\n }\n /**\n * Subtract two quaternions\n * Example Playground https://playground.babylonjs.com/#L49EJ7#57\n * @param other defines the second operand\n * @returns a new quaternion as the subtraction result of the given one from the current one\n */\n subtract(other) {\n return new this.constructor(this._x - other._x, this._y - other._y, this._z - other._z, this._w - other._w);\n }\n /**\n * Subtract a quaternion to the current one\n * Example Playground https://playground.babylonjs.com/#L49EJ7#58\n * @param other defines the quaternion to subtract\n * @returns the current quaternion\n */\n subtractInPlace(other) {\n this._x -= other._x;\n this._y -= other._y;\n this._z -= other._z;\n this._w -= other._w;\n this._isDirty = true;\n return this;\n }\n /**\n * Multiplies the current quaternion by a scale factor\n * Example Playground https://playground.babylonjs.com/#L49EJ7#88\n * @param value defines the scale factor\n * @returns a new quaternion set by multiplying the current quaternion coordinates by the float \"scale\"\n */\n scale(value) {\n return new this.constructor(this._x * value, this._y * value, this._z * value, this._w * value);\n }\n /**\n * Scale the current quaternion values by a factor and stores the result to a given quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#89\n * @param scale defines the scale factor\n * @param result defines the Quaternion object where to store the result\n * @returns result input\n */\n scaleToRef(scale, result) {\n result._x = this._x * scale;\n result._y = this._y * scale;\n result._z = this._z * scale;\n result._w = this._w * scale;\n result._isDirty = true;\n return result;\n }\n /**\n * Multiplies in place the current quaternion by a scale factor\n * Example Playground https://playground.babylonjs.com/#L49EJ7#90\n * @param value defines the scale factor\n * @returns the current modified quaternion\n */\n scaleInPlace(value) {\n this._x *= value;\n this._y *= value;\n this._z *= value;\n this._w *= value;\n this._isDirty = true;\n return this;\n }\n /**\n * Scale the current quaternion values by a factor and add the result to a given quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#91\n * @param scale defines the scale factor\n * @param result defines the Quaternion object where to store the result\n * @returns result input\n */\n scaleAndAddToRef(scale, result) {\n result._x += this._x * scale;\n result._y += this._y * scale;\n result._z += this._z * scale;\n result._w += this._w * scale;\n result._isDirty = true;\n return result;\n }\n /**\n * Multiplies two quaternions\n * Example Playground https://playground.babylonjs.com/#L49EJ7#43\n * @param q1 defines the second operand\n * @returns a new quaternion set as the multiplication result of the current one with the given one \"q1\"\n */\n multiply(q1) {\n const result = new this.constructor(0, 0, 0, 1.0);\n this.multiplyToRef(q1, result);\n return result;\n }\n /**\n * Sets the given \"result\" as the the multiplication result of the current one with the given one \"q1\"\n * Example Playground https://playground.babylonjs.com/#L49EJ7#45\n * @param q1 defines the second operand\n * @param result defines the target quaternion\n * @returns the current quaternion\n */\n multiplyToRef(q1, result) {\n const x = this._x * q1._w + this._y * q1._z - this._z * q1._y + this._w * q1._x;\n const y = -this._x * q1._z + this._y * q1._w + this._z * q1._x + this._w * q1._y;\n const z = this._x * q1._y - this._y * q1._x + this._z * q1._w + this._w * q1._z;\n const w = -this._x * q1._x - this._y * q1._y - this._z * q1._z + this._w * q1._w;\n result.copyFromFloats(x, y, z, w);\n return result;\n }\n /**\n * Updates the current quaternion with the multiplication of itself with the given one \"q1\"\n * Example Playground https://playground.babylonjs.com/#L49EJ7#46\n * @param q1 defines the second operand\n * @returns the currentupdated quaternion\n */\n multiplyInPlace(q1) {\n this.multiplyToRef(q1, this);\n return this;\n }\n /**\n * Conjugates the current quaternion and stores the result in the given quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#81\n * @param ref defines the target quaternion\n * @returns result input\n */\n conjugateToRef(ref) {\n ref.copyFromFloats(-this._x, -this._y, -this._z, this._w);\n return ref;\n }\n /**\n * Conjugates in place the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#82\n * @returns the current updated quaternion\n */\n conjugateInPlace() {\n this._x *= -1;\n this._y *= -1;\n this._z *= -1;\n this._isDirty = true;\n return this;\n }\n /**\n * Conjugates (1-q) the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#83\n * @returns a new quaternion\n */\n conjugate() {\n return new this.constructor(-this._x, -this._y, -this._z, this._w);\n }\n /**\n * Returns the inverse of the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#84\n * @returns a new quaternion\n */\n invert() {\n const conjugate = this.conjugate();\n const lengthSquared = this.lengthSquared();\n if (lengthSquared == 0 || lengthSquared == 1) {\n return conjugate;\n }\n conjugate.scaleInPlace(1 / lengthSquared);\n return conjugate;\n }\n /**\n * Invert in place the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#85\n * @returns this quaternion\n */\n invertInPlace() {\n this.conjugateInPlace();\n const lengthSquared = this.lengthSquared();\n if (lengthSquared == 0 || lengthSquared == 1) {\n return this;\n }\n this.scaleInPlace(1 / lengthSquared);\n return this;\n }\n /**\n * Gets squared length of current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#29\n * @returns the quaternion length (float)\n */\n lengthSquared() {\n return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;\n }\n /**\n * Gets length of current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#28\n * @returns the quaternion length (float)\n */\n length() {\n return Math.sqrt(this.lengthSquared());\n }\n /**\n * Normalize in place the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#54\n * @returns the current updated quaternion\n */\n normalize() {\n const len = this.length();\n if (len === 0) {\n return this;\n }\n const inv = 1.0 / len;\n this.scaleInPlace(inv);\n return this;\n }\n /**\n * Normalize a copy of the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#55\n * @returns the normalized quaternion\n */\n normalizeToNew() {\n const len = this.length();\n if (len === 0) {\n return this.clone();\n }\n const inv = 1.0 / len;\n return this.scale(inv);\n }\n /**\n * Returns a new Vector3 set with the Euler angles translated from the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#32\n * @returns a new Vector3 containing the Euler angles\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/rotation_conventions\n */\n toEulerAngles() {\n const result = Vector3.Zero();\n this.toEulerAnglesToRef(result);\n return result;\n }\n /**\n * Sets the given vector3 \"result\" with the Euler angles translated from the current quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#31\n * @param result defines the vector which will be filled with the Euler angles\n * @returns result input\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/rotation_conventions\n */\n toEulerAnglesToRef(result) {\n const qz = this._z;\n const qx = this._x;\n const qy = this._y;\n const qw = this._w;\n const zAxisY = qy * qz - qx * qw;\n const limit = 0.4999999;\n if (zAxisY < -limit) {\n result._y = 2 * Math.atan2(qy, qw);\n result._x = Math.PI / 2;\n result._z = 0;\n result._isDirty = true;\n }\n else if (zAxisY > limit) {\n result._y = 2 * Math.atan2(qy, qw);\n result._x = -Math.PI / 2;\n result._z = 0;\n result._isDirty = true;\n }\n else {\n const sqw = qw * qw;\n const sqz = qz * qz;\n const sqx = qx * qx;\n const sqy = qy * qy;\n result._z = Math.atan2(2.0 * (qx * qy + qz * qw), -sqz - sqx + sqy + sqw);\n result._x = Math.asin(-2.0 * zAxisY);\n result._y = Math.atan2(2.0 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);\n result._isDirty = true;\n }\n return result;\n }\n /**\n * Updates the given rotation matrix with the current quaternion values\n * Example Playground https://playground.babylonjs.com/#L49EJ7#67\n * @param result defines the target matrix\n * @returns the current unchanged quaternion\n */\n toRotationMatrix(result) {\n Matrix.FromQuaternionToRef(this, result);\n return result;\n }\n /**\n * Updates the current quaternion from the given rotation matrix values\n * Example Playground https://playground.babylonjs.com/#L49EJ7#41\n * @param matrix defines the source matrix\n * @returns the current updated quaternion\n */\n fromRotationMatrix(matrix) {\n Quaternion.FromRotationMatrixToRef(matrix, this);\n return this;\n }\n // Statics\n /**\n * Creates a new quaternion from a rotation matrix\n * Example Playground https://playground.babylonjs.com/#L49EJ7#101\n * @param matrix defines the source matrix\n * @returns a new quaternion created from the given rotation matrix values\n */\n static FromRotationMatrix(matrix) {\n const result = new Quaternion();\n Quaternion.FromRotationMatrixToRef(matrix, result);\n return result;\n }\n /**\n * Updates the given quaternion with the given rotation matrix values\n * Example Playground https://playground.babylonjs.com/#L49EJ7#102\n * @param matrix defines the source matrix\n * @param result defines the target quaternion\n * @returns result input\n */\n static FromRotationMatrixToRef(matrix, result) {\n const data = matrix.m;\n const m11 = data[0], m12 = data[4], m13 = data[8];\n const m21 = data[1], m22 = data[5], m23 = data[9];\n const m31 = data[2], m32 = data[6], m33 = data[10];\n const trace = m11 + m22 + m33;\n let s;\n if (trace > 0) {\n s = 0.5 / Math.sqrt(trace + 1.0);\n result._w = 0.25 / s;\n result._x = (m32 - m23) * s;\n result._y = (m13 - m31) * s;\n result._z = (m21 - m12) * s;\n result._isDirty = true;\n }\n else if (m11 > m22 && m11 > m33) {\n s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);\n result._w = (m32 - m23) / s;\n result._x = 0.25 * s;\n result._y = (m12 + m21) / s;\n result._z = (m13 + m31) / s;\n result._isDirty = true;\n }\n else if (m22 > m33) {\n s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);\n result._w = (m13 - m31) / s;\n result._x = (m12 + m21) / s;\n result._y = 0.25 * s;\n result._z = (m23 + m32) / s;\n result._isDirty = true;\n }\n else {\n s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);\n result._w = (m21 - m12) / s;\n result._x = (m13 + m31) / s;\n result._y = (m23 + m32) / s;\n result._z = 0.25 * s;\n result._isDirty = true;\n }\n return result;\n }\n /**\n * Returns the dot product (float) between the quaternions \"left\" and \"right\"\n * Example Playground https://playground.babylonjs.com/#L49EJ7#61\n * @param left defines the left operand\n * @param right defines the right operand\n * @returns the dot product\n */\n static Dot(left, right) {\n return left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;\n }\n /**\n * Checks if the orientations of two rotation quaternions are close to each other\n * Example Playground https://playground.babylonjs.com/#L49EJ7#60\n * @param quat0 defines the first quaternion to check\n * @param quat1 defines the second quaternion to check\n * @param epsilon defines closeness, 0 same orientation, 1 PI apart, default 0.1\n * @returns true if the two quaternions are close to each other within epsilon\n */\n static AreClose(quat0, quat1, epsilon = 0.1) {\n const dot = Quaternion.Dot(quat0, quat1);\n return 1 - dot * dot <= epsilon;\n }\n /**\n * Smooth interpolation between two quaternions using Slerp\n * Example Playground https://playground.babylonjs.com/#L49EJ7#93\n * @param source source quaternion\n * @param goal goal quaternion\n * @param deltaTime current interpolation frame\n * @param lerpTime total interpolation time\n * @param result the smoothed quaternion\n */\n static SmoothToRef(source, goal, deltaTime, lerpTime, result) {\n let slerp = lerpTime === 0 ? 1 : deltaTime / lerpTime;\n slerp = Scalar.Clamp(slerp, 0, 1);\n Quaternion.SlerpToRef(source, goal, slerp, result);\n return result;\n }\n /**\n * Creates an empty quaternion\n * @returns a new quaternion set to (0.0, 0.0, 0.0)\n */\n static Zero() {\n return new Quaternion(0.0, 0.0, 0.0, 0.0);\n }\n /**\n * Inverse a given quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#103\n * @param q defines the source quaternion\n * @returns a new quaternion as the inverted current quaternion\n */\n static Inverse(q) {\n return new q.constructor(-q._x, -q._y, -q._z, q._w);\n }\n /**\n * Inverse a given quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#104\n * @param q defines the source quaternion\n * @param result the quaternion the result will be stored in\n * @returns the result quaternion\n */\n static InverseToRef(q, result) {\n result.set(-q._x, -q._y, -q._z, q._w);\n return result;\n }\n /**\n * Creates an identity quaternion\n * @returns the identity quaternion\n */\n static Identity() {\n return new Quaternion(0.0, 0.0, 0.0, 1.0);\n }\n /**\n * Gets a boolean indicating if the given quaternion is identity\n * @param quaternion defines the quaternion to check\n * @returns true if the quaternion is identity\n */\n static IsIdentity(quaternion) {\n return quaternion && quaternion._x === 0 && quaternion._y === 0 && quaternion._z === 0 && quaternion._w === 1;\n }\n /**\n * Creates a quaternion from a rotation around an axis\n * Example Playground https://playground.babylonjs.com/#L49EJ7#72\n * @param axis defines the axis to use\n * @param angle defines the angle to use\n * @returns a new quaternion created from the given axis (Vector3) and angle in radians (float)\n */\n static RotationAxis(axis, angle) {\n return Quaternion.RotationAxisToRef(axis, angle, new Quaternion());\n }\n /**\n * Creates a rotation around an axis and stores it into the given quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#73\n * @param axis defines the axis to use\n * @param angle defines the angle to use\n * @param result defines the target quaternion\n * @returns the target quaternion\n */\n static RotationAxisToRef(axis, angle, result) {\n const sin = Math.sin(angle / 2);\n axis.normalize();\n result._w = Math.cos(angle / 2);\n result._x = axis._x * sin;\n result._y = axis._y * sin;\n result._z = axis._z * sin;\n result._isDirty = true;\n return result;\n }\n /**\n * Creates a new quaternion from data stored into an array\n * Example Playground https://playground.babylonjs.com/#L49EJ7#63\n * @param array defines the data source\n * @param offset defines the offset in the source array where the data starts\n * @returns a new quaternion\n */\n static FromArray(array, offset) {\n if (!offset) {\n offset = 0;\n }\n return new Quaternion(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\n }\n /**\n * Updates the given quaternion \"result\" from the starting index of the given array.\n * Example Playground https://playground.babylonjs.com/#L49EJ7#64\n * @param array the array to pull values from\n * @param offset the offset into the array to start at\n * @param result the quaternion to store the result in\n * @returns result input\n */\n static FromArrayToRef(array, offset, result) {\n result._x = array[offset];\n result._y = array[offset + 1];\n result._z = array[offset + 2];\n result._w = array[offset + 3];\n result._isDirty = true;\n return result;\n }\n /**\n * Create a quaternion from Euler rotation angles\n * Example Playground https://playground.babylonjs.com/#L49EJ7#33\n * @param x Pitch\n * @param y Yaw\n * @param z Roll\n * @returns the new Quaternion\n */\n static FromEulerAngles(x, y, z) {\n const q = new Quaternion();\n Quaternion.RotationYawPitchRollToRef(y, x, z, q);\n return q;\n }\n /**\n * Updates a quaternion from Euler rotation angles\n * Example Playground https://playground.babylonjs.com/#L49EJ7#34\n * @param x Pitch\n * @param y Yaw\n * @param z Roll\n * @param result the quaternion to store the result\n * @returns the updated quaternion\n */\n static FromEulerAnglesToRef(x, y, z, result) {\n Quaternion.RotationYawPitchRollToRef(y, x, z, result);\n return result;\n }\n /**\n * Create a quaternion from Euler rotation vector\n * Example Playground https://playground.babylonjs.com/#L49EJ7#35\n * @param vec the Euler vector (x Pitch, y Yaw, z Roll)\n * @returns the new Quaternion\n */\n static FromEulerVector(vec) {\n const q = new Quaternion();\n Quaternion.RotationYawPitchRollToRef(vec._y, vec._x, vec._z, q);\n return q;\n }\n /**\n * Updates a quaternion from Euler rotation vector\n * Example Playground https://playground.babylonjs.com/#L49EJ7#36\n * @param vec the Euler vector (x Pitch, y Yaw, z Roll)\n * @param result the quaternion to store the result\n * @returns the updated quaternion\n */\n static FromEulerVectorToRef(vec, result) {\n Quaternion.RotationYawPitchRollToRef(vec._y, vec._x, vec._z, result);\n return result;\n }\n /**\n * Updates a quaternion so that it rotates vector vecFrom to vector vecTo\n * Example Playground - https://playground.babylonjs.com/#L49EJ7#70\n * @param vecFrom defines the direction vector from which to rotate\n * @param vecTo defines the direction vector to which to rotate\n * @param result the quaternion to store the result\n * @param epsilon defines the minimal dot value to define vecs as opposite. Default: `BABYLON.Epsilon`\n * @returns the updated quaternion\n */\n static FromUnitVectorsToRef(vecFrom, vecTo, result, epsilon = Epsilon) {\n const r = Vector3.Dot(vecFrom, vecTo) + 1;\n if (r < epsilon) {\n if (Math.abs(vecFrom.x) > Math.abs(vecFrom.z)) {\n result.set(-vecFrom.y, vecFrom.x, 0, 0);\n }\n else {\n result.set(0, -vecFrom.z, vecFrom.y, 0);\n }\n }\n else {\n Vector3.CrossToRef(vecFrom, vecTo, TmpVectors.Vector3[0]);\n result.set(TmpVectors.Vector3[0].x, TmpVectors.Vector3[0].y, TmpVectors.Vector3[0].z, r);\n }\n return result.normalize();\n }\n /**\n * Creates a new quaternion from the given Euler float angles (y, x, z)\n * Example Playground https://playground.babylonjs.com/#L49EJ7#77\n * @param yaw defines the rotation around Y axis\n * @param pitch defines the rotation around X axis\n * @param roll defines the rotation around Z axis\n * @returns the new quaternion\n */\n static RotationYawPitchRoll(yaw, pitch, roll) {\n const q = new Quaternion();\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, q);\n return q;\n }\n /**\n * Creates a new rotation from the given Euler float angles (y, x, z) and stores it in the target quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#78\n * @param yaw defines the rotation around Y axis\n * @param pitch defines the rotation around X axis\n * @param roll defines the rotation around Z axis\n * @param result defines the target quaternion\n * @returns result input\n */\n static RotationYawPitchRollToRef(yaw, pitch, roll, result) {\n // Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)\n const halfRoll = roll * 0.5;\n const halfPitch = pitch * 0.5;\n const halfYaw = yaw * 0.5;\n const sinRoll = Math.sin(halfRoll);\n const cosRoll = Math.cos(halfRoll);\n const sinPitch = Math.sin(halfPitch);\n const cosPitch = Math.cos(halfPitch);\n const sinYaw = Math.sin(halfYaw);\n const cosYaw = Math.cos(halfYaw);\n result._x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;\n result._y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;\n result._z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;\n result._w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;\n result._isDirty = true;\n return result;\n }\n /**\n * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation\n * Example Playground https://playground.babylonjs.com/#L49EJ7#68\n * @param alpha defines the rotation around first axis\n * @param beta defines the rotation around second axis\n * @param gamma defines the rotation around third axis\n * @returns the new quaternion\n */\n static RotationAlphaBetaGamma(alpha, beta, gamma) {\n const result = new Quaternion();\n Quaternion.RotationAlphaBetaGammaToRef(alpha, beta, gamma, result);\n return result;\n }\n /**\n * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation and stores it in the target quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#69\n * @param alpha defines the rotation around first axis\n * @param beta defines the rotation around second axis\n * @param gamma defines the rotation around third axis\n * @param result defines the target quaternion\n * @returns result input\n */\n static RotationAlphaBetaGammaToRef(alpha, beta, gamma, result) {\n // Produces a quaternion from Euler angles in the z-x-z orientation\n const halfGammaPlusAlpha = (gamma + alpha) * 0.5;\n const halfGammaMinusAlpha = (gamma - alpha) * 0.5;\n const halfBeta = beta * 0.5;\n result._x = Math.cos(halfGammaMinusAlpha) * Math.sin(halfBeta);\n result._y = Math.sin(halfGammaMinusAlpha) * Math.sin(halfBeta);\n result._z = Math.sin(halfGammaPlusAlpha) * Math.cos(halfBeta);\n result._w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);\n result._isDirty = true;\n return result;\n }\n /**\n * Creates a new quaternion containing the rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation)\n * Example Playground https://playground.babylonjs.com/#L49EJ7#75\n * @param axis1 defines the first axis\n * @param axis2 defines the second axis\n * @param axis3 defines the third axis\n * @returns the new quaternion\n */\n static RotationQuaternionFromAxis(axis1, axis2, axis3) {\n const quat = new Quaternion(0.0, 0.0, 0.0, 0.0);\n Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);\n return quat;\n }\n /**\n * Creates a rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation) and stores it in the target quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#76\n * @param axis1 defines the first axis\n * @param axis2 defines the second axis\n * @param axis3 defines the third axis\n * @param ref defines the target quaternion\n * @returns result input\n */\n static RotationQuaternionFromAxisToRef(axis1, axis2, axis3, ref) {\n const rotMat = MathTmp.Matrix[0];\n Matrix.FromXYZAxesToRef(axis1.normalize(), axis2.normalize(), axis3.normalize(), rotMat);\n Quaternion.FromRotationMatrixToRef(rotMat, ref);\n return ref;\n }\n /**\n * Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like \"up\".\n * This function works in left handed mode\n * Example Playground https://playground.babylonjs.com/#L49EJ7#96\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @returns A new quaternion oriented toward the specified forward and up.\n */\n static FromLookDirectionLH(forward, up) {\n const quat = new Quaternion();\n Quaternion.FromLookDirectionLHToRef(forward, up, quat);\n return quat;\n }\n /**\n * Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like \"up\", and stores it in the target quaternion.\n * This function works in left handed mode\n * Example Playground https://playground.babylonjs.com/#L49EJ7#97\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @param ref defines the target quaternion.\n * @returns result input\n */\n static FromLookDirectionLHToRef(forward, up, ref) {\n const rotMat = MathTmp.Matrix[0];\n Matrix.LookDirectionLHToRef(forward, up, rotMat);\n Quaternion.FromRotationMatrixToRef(rotMat, ref);\n return ref;\n }\n /**\n * Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like \"up\".\n * This function works in right handed mode\n * Example Playground https://playground.babylonjs.com/#L49EJ7#98\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @returns A new quaternion oriented toward the specified forward and up.\n */\n static FromLookDirectionRH(forward, up) {\n const quat = new Quaternion();\n Quaternion.FromLookDirectionRHToRef(forward, up, quat);\n return quat;\n }\n /**\n * Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like \"up\", and stores it in the target quaternion.\n * This function works in right handed mode\n * Example Playground https://playground.babylonjs.com/#L49EJ7#105\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @param ref defines the target quaternion.\n * @returns result input\n */\n static FromLookDirectionRHToRef(forward, up, ref) {\n const rotMat = MathTmp.Matrix[0];\n Matrix.LookDirectionRHToRef(forward, up, rotMat);\n return Quaternion.FromRotationMatrixToRef(rotMat, ref);\n }\n /**\n * Interpolates between two quaternions\n * Example Playground https://playground.babylonjs.com/#L49EJ7#79\n * @param left defines first quaternion\n * @param right defines second quaternion\n * @param amount defines the gradient to use\n * @returns the new interpolated quaternion\n */\n static Slerp(left, right, amount) {\n const result = Quaternion.Identity();\n Quaternion.SlerpToRef(left, right, amount, result);\n return result;\n }\n /**\n * Interpolates between two quaternions and stores it into a target quaternion\n * Example Playground https://playground.babylonjs.com/#L49EJ7#92\n * @param left defines first quaternion\n * @param right defines second quaternion\n * @param amount defines the gradient to use\n * @param result defines the target quaternion\n * @returns result input\n */\n static SlerpToRef(left, right, amount, result) {\n let num2;\n let num3;\n let num4 = left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;\n let flag = false;\n if (num4 < 0) {\n flag = true;\n num4 = -num4;\n }\n if (num4 > 0.999999) {\n num3 = 1 - amount;\n num2 = flag ? -amount : amount;\n }\n else {\n const num5 = Math.acos(num4);\n const num6 = 1.0 / Math.sin(num5);\n num3 = Math.sin((1.0 - amount) * num5) * num6;\n num2 = flag ? -Math.sin(amount * num5) * num6 : Math.sin(amount * num5) * num6;\n }\n result._x = num3 * left._x + num2 * right._x;\n result._y = num3 * left._y + num2 * right._y;\n result._z = num3 * left._z + num2 * right._z;\n result._w = num3 * left._w + num2 * right._w;\n result._isDirty = true;\n return result;\n }\n /**\n * Interpolate between two quaternions using Hermite interpolation\n * Example Playground https://playground.babylonjs.com/#L49EJ7#47\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-quaternion-spline\n * @param value1 defines first quaternion\n * @param tangent1 defines the incoming tangent\n * @param value2 defines second quaternion\n * @param tangent2 defines the outgoing tangent\n * @param amount defines the target quaternion\n * @returns the new interpolated quaternion\n */\n static Hermite(value1, tangent1, value2, tangent2, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\n const part2 = -2.0 * cubed + 3.0 * squared;\n const part3 = cubed - 2.0 * squared + amount;\n const part4 = cubed - squared;\n const x = value1._x * part1 + value2._x * part2 + tangent1._x * part3 + tangent2._x * part4;\n const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;\n const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;\n const w = value1._w * part1 + value2._w * part2 + tangent1._w * part3 + tangent2._w * part4;\n return new value1.constructor(x, y, z, w);\n }\n /**\n * Returns a new Quaternion which is the 1st derivative of the Hermite spline defined by the quaternions \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * Example Playground https://playground.babylonjs.com/#L49EJ7#48\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @returns 1st derivative\n */\n static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {\n const result = new value1.constructor();\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\n return result;\n }\n /**\n * Update a Quaternion with the 1st derivative of the Hermite spline defined by the quaternions \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * Example Playground https://playground.babylonjs.com/#L49EJ7#49\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @param result define where to store the derivative\n * @returns result input\n */\n static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {\n const t2 = time * time;\n result._x = (t2 - time) * 6 * value1._x + (3 * t2 - 4 * time + 1) * tangent1._x + (-t2 + time) * 6 * value2._x + (3 * t2 - 2 * time) * tangent2._x;\n result._y = (t2 - time) * 6 * value1._y + (3 * t2 - 4 * time + 1) * tangent1._y + (-t2 + time) * 6 * value2._y + (3 * t2 - 2 * time) * tangent2._y;\n result._z = (t2 - time) * 6 * value1._z + (3 * t2 - 4 * time + 1) * tangent1._z + (-t2 + time) * 6 * value2._z + (3 * t2 - 2 * time) * tangent2._z;\n result._w = (t2 - time) * 6 * value1._w + (3 * t2 - 4 * time + 1) * tangent1._w + (-t2 + time) * 6 * value2._w + (3 * t2 - 2 * time) * tangent2._w;\n result._isDirty = true;\n return result;\n }\n }\n /**\n * Class used to store matrix data (4x4)\n * Note on matrix definitions in Babylon.js for setting values directly\n * rather than using one of the methods available.\n * Matrix size is given by rows x columns.\n * A Vector3 is a 1 X 3 matrix [x, y, z].\n *\n * In Babylon.js multiplying a 1 x 3 matrix by a 4 x 4 matrix\n * is done using BABYLON.Vector4.TransformCoordinates(Vector3, Matrix).\n * and extending the passed Vector3 to a Vector4, V = [x, y, z, 1].\n * Let M be a matrix with elements m(row, column), so that\n * m(2, 3) is the element in row 2 column 3 of M.\n *\n * Multiplication is of the form VM and has the resulting Vector4\n * VM = [xm(0, 0) + ym(1, 0) + zm(2, 0) + m(3, 0), xm(0, 1) + ym(1, 1) + zm(2, 1) + m(3, 1), xm(0, 2) + ym(1, 2) + zm(2, 2) + m(3, 2), xm(0, 3) + ym(1, 3) + zm(2, 3) + m(3, 3)].\n * On the web you will find many examples that use the opposite convention of MV,\n * in which case to make use of the examples you will need to transpose the matrix.\n *\n * Example Playground - Overview Linear Algebra - https://playground.babylonjs.com/#AV9X17\n * Example Playground - Overview Transformation - https://playground.babylonjs.com/#AV9X17#1\n * Example Playground - Overview Projection - https://playground.babylonjs.com/#AV9X17#2\n */\n class Matrix {\n /**\n * Gets the precision of matrix computations\n */\n static get Use64Bits() {\n return PerformanceConfigurator.MatrixUse64Bits;\n }\n /**\n * Gets the internal data of the matrix\n */\n get m() {\n return this._m;\n }\n /**\n * Update the updateFlag to indicate that the matrix has been updated\n */\n markAsUpdated() {\n this.updateFlag = Matrix._UpdateFlagSeed++;\n this._isIdentity = false;\n this._isIdentity3x2 = false;\n this._isIdentityDirty = true;\n this._isIdentity3x2Dirty = true;\n }\n _updateIdentityStatus(isIdentity, isIdentityDirty = false, isIdentity3x2 = false, isIdentity3x2Dirty = true) {\n this._isIdentity = isIdentity;\n this._isIdentity3x2 = isIdentity || isIdentity3x2;\n this._isIdentityDirty = this._isIdentity ? false : isIdentityDirty;\n this._isIdentity3x2Dirty = this._isIdentity3x2 ? false : isIdentity3x2Dirty;\n }\n /**\n * Creates an empty matrix (filled with zeros)\n */\n constructor() {\n this._isIdentity = false;\n this._isIdentityDirty = true;\n this._isIdentity3x2 = true;\n this._isIdentity3x2Dirty = true;\n /**\n * Gets the update flag of the matrix which is an unique number for the matrix.\n * It will be incremented every time the matrix data change.\n * You can use it to speed the comparison between two versions of the same matrix.\n */\n this.updateFlag = -1;\n if (PerformanceConfigurator.MatrixTrackPrecisionChange) {\n PerformanceConfigurator.MatrixTrackedMatrices.push(this);\n }\n this._m = new PerformanceConfigurator.MatrixCurrentType(16);\n this.markAsUpdated();\n }\n // Properties\n /**\n * Check if the current matrix is identity\n * @returns true is the matrix is the identity matrix\n */\n isIdentity() {\n if (this._isIdentityDirty) {\n this._isIdentityDirty = false;\n const m = this._m;\n this._isIdentity =\n m[0] === 1.0 &&\n m[1] === 0.0 &&\n m[2] === 0.0 &&\n m[3] === 0.0 &&\n m[4] === 0.0 &&\n m[5] === 1.0 &&\n m[6] === 0.0 &&\n m[7] === 0.0 &&\n m[8] === 0.0 &&\n m[9] === 0.0 &&\n m[10] === 1.0 &&\n m[11] === 0.0 &&\n m[12] === 0.0 &&\n m[13] === 0.0 &&\n m[14] === 0.0 &&\n m[15] === 1.0;\n }\n return this._isIdentity;\n }\n /**\n * Check if the current matrix is identity as a texture matrix (3x2 store in 4x4)\n * @returns true is the matrix is the identity matrix\n */\n isIdentityAs3x2() {\n if (this._isIdentity3x2Dirty) {\n this._isIdentity3x2Dirty = false;\n if (this._m[0] !== 1.0 || this._m[5] !== 1.0 || this._m[15] !== 1.0) {\n this._isIdentity3x2 = false;\n }\n else if (this._m[1] !== 0.0 ||\n this._m[2] !== 0.0 ||\n this._m[3] !== 0.0 ||\n this._m[4] !== 0.0 ||\n this._m[6] !== 0.0 ||\n this._m[7] !== 0.0 ||\n this._m[8] !== 0.0 ||\n this._m[9] !== 0.0 ||\n this._m[10] !== 0.0 ||\n this._m[11] !== 0.0 ||\n this._m[12] !== 0.0 ||\n this._m[13] !== 0.0 ||\n this._m[14] !== 0.0) {\n this._isIdentity3x2 = false;\n }\n else {\n this._isIdentity3x2 = true;\n }\n }\n return this._isIdentity3x2;\n }\n /**\n * Gets the determinant of the matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#34\n * @returns the matrix determinant\n */\n determinant() {\n if (this._isIdentity === true) {\n return 1;\n }\n const m = this._m;\n const m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3];\n const m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7];\n const m20 = m[8], m21 = m[9], m22 = m[10], m23 = m[11];\n const m30 = m[12], m31 = m[13], m32 = m[14], m33 = m[15];\n // https://en.wikipedia.org/wiki/Laplace_expansion\n // to compute the deterrminant of a 4x4 Matrix we compute the cofactors of any row or column,\n // then we multiply each Cofactor by its corresponding matrix value and sum them all to get the determinant\n // Cofactor(i, j) = sign(i,j) * det(Minor(i, j))\n // where\n // - sign(i,j) = (i+j) % 2 === 0 ? 1 : -1\n // - Minor(i, j) is the 3x3 matrix we get by removing row i and column j from current Matrix\n //\n // Here we do that for the 1st row.\n const det_22_33 = m22 * m33 - m32 * m23;\n const det_21_33 = m21 * m33 - m31 * m23;\n const det_21_32 = m21 * m32 - m31 * m22;\n const det_20_33 = m20 * m33 - m30 * m23;\n const det_20_32 = m20 * m32 - m22 * m30;\n const det_20_31 = m20 * m31 - m30 * m21;\n const cofact_00 = +(m11 * det_22_33 - m12 * det_21_33 + m13 * det_21_32);\n const cofact_01 = -(m10 * det_22_33 - m12 * det_20_33 + m13 * det_20_32);\n const cofact_02 = +(m10 * det_21_33 - m11 * det_20_33 + m13 * det_20_31);\n const cofact_03 = -(m10 * det_21_32 - m11 * det_20_32 + m12 * det_20_31);\n return m00 * cofact_00 + m01 * cofact_01 + m02 * cofact_02 + m03 * cofact_03;\n }\n // Methods\n /**\n * Returns the matrix as a Float32Array or Array\n * Example Playground - https://playground.babylonjs.com/#AV9X17#49\n * @returns the matrix underlying array\n */\n toArray() {\n return this._m;\n }\n /**\n * Returns the matrix as a Float32Array or Array\n * Example Playground - https://playground.babylonjs.com/#AV9X17#114\n * @returns the matrix underlying array.\n */\n asArray() {\n return this._m;\n }\n /**\n * Inverts the current matrix in place\n * Example Playground - https://playground.babylonjs.com/#AV9X17#118\n * @returns the current inverted matrix\n */\n invert() {\n this.invertToRef(this);\n return this;\n }\n /**\n * Sets all the matrix elements to zero\n * @returns the current matrix\n */\n reset() {\n Matrix.FromValuesToRef(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, this);\n this._updateIdentityStatus(false);\n return this;\n }\n /**\n * Adds the current matrix with a second one\n * Example Playground - https://playground.babylonjs.com/#AV9X17#44\n * @param other defines the matrix to add\n * @returns a new matrix as the addition of the current matrix and the given one\n */\n add(other) {\n const result = new this.constructor();\n this.addToRef(other, result);\n return result;\n }\n /**\n * Sets the given matrix \"result\" to the addition of the current matrix and the given one\n * Example Playground - https://playground.babylonjs.com/#AV9X17#45\n * @param other defines the matrix to add\n * @param result defines the target matrix\n * @returns result input\n */\n addToRef(other, result) {\n const m = this._m;\n const resultM = result._m;\n const otherM = other.m;\n for (let index = 0; index < 16; index++) {\n resultM[index] = m[index] + otherM[index];\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Adds in place the given matrix to the current matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#46\n * @param other defines the second operand\n * @returns the current updated matrix\n */\n addToSelf(other) {\n const m = this._m;\n const otherM = other.m;\n for (let index = 0; index < 16; index++) {\n m[index] += otherM[index];\n }\n this.markAsUpdated();\n return this;\n }\n /**\n * Sets the given matrix to the current inverted Matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#119\n * @param other defines the target matrix\n * @returns result input\n */\n invertToRef(other) {\n if (this._isIdentity === true) {\n Matrix.IdentityToRef(other);\n return other;\n }\n // the inverse of a Matrix is the transpose of cofactor matrix divided by the determinant\n const m = this._m;\n const m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3];\n const m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7];\n const m20 = m[8], m21 = m[9], m22 = m[10], m23 = m[11];\n const m30 = m[12], m31 = m[13], m32 = m[14], m33 = m[15];\n const det_22_33 = m22 * m33 - m32 * m23;\n const det_21_33 = m21 * m33 - m31 * m23;\n const det_21_32 = m21 * m32 - m31 * m22;\n const det_20_33 = m20 * m33 - m30 * m23;\n const det_20_32 = m20 * m32 - m22 * m30;\n const det_20_31 = m20 * m31 - m30 * m21;\n const cofact_00 = +(m11 * det_22_33 - m12 * det_21_33 + m13 * det_21_32);\n const cofact_01 = -(m10 * det_22_33 - m12 * det_20_33 + m13 * det_20_32);\n const cofact_02 = +(m10 * det_21_33 - m11 * det_20_33 + m13 * det_20_31);\n const cofact_03 = -(m10 * det_21_32 - m11 * det_20_32 + m12 * det_20_31);\n const det = m00 * cofact_00 + m01 * cofact_01 + m02 * cofact_02 + m03 * cofact_03;\n if (det === 0) {\n // not invertible\n other.copyFrom(this);\n return other;\n }\n const detInv = 1 / det;\n const det_12_33 = m12 * m33 - m32 * m13;\n const det_11_33 = m11 * m33 - m31 * m13;\n const det_11_32 = m11 * m32 - m31 * m12;\n const det_10_33 = m10 * m33 - m30 * m13;\n const det_10_32 = m10 * m32 - m30 * m12;\n const det_10_31 = m10 * m31 - m30 * m11;\n const det_12_23 = m12 * m23 - m22 * m13;\n const det_11_23 = m11 * m23 - m21 * m13;\n const det_11_22 = m11 * m22 - m21 * m12;\n const det_10_23 = m10 * m23 - m20 * m13;\n const det_10_22 = m10 * m22 - m20 * m12;\n const det_10_21 = m10 * m21 - m20 * m11;\n const cofact_10 = -(m01 * det_22_33 - m02 * det_21_33 + m03 * det_21_32);\n const cofact_11 = +(m00 * det_22_33 - m02 * det_20_33 + m03 * det_20_32);\n const cofact_12 = -(m00 * det_21_33 - m01 * det_20_33 + m03 * det_20_31);\n const cofact_13 = +(m00 * det_21_32 - m01 * det_20_32 + m02 * det_20_31);\n const cofact_20 = +(m01 * det_12_33 - m02 * det_11_33 + m03 * det_11_32);\n const cofact_21 = -(m00 * det_12_33 - m02 * det_10_33 + m03 * det_10_32);\n const cofact_22 = +(m00 * det_11_33 - m01 * det_10_33 + m03 * det_10_31);\n const cofact_23 = -(m00 * det_11_32 - m01 * det_10_32 + m02 * det_10_31);\n const cofact_30 = -(m01 * det_12_23 - m02 * det_11_23 + m03 * det_11_22);\n const cofact_31 = +(m00 * det_12_23 - m02 * det_10_23 + m03 * det_10_22);\n const cofact_32 = -(m00 * det_11_23 - m01 * det_10_23 + m03 * det_10_21);\n const cofact_33 = +(m00 * det_11_22 - m01 * det_10_22 + m02 * det_10_21);\n Matrix.FromValuesToRef(cofact_00 * detInv, cofact_10 * detInv, cofact_20 * detInv, cofact_30 * detInv, cofact_01 * detInv, cofact_11 * detInv, cofact_21 * detInv, cofact_31 * detInv, cofact_02 * detInv, cofact_12 * detInv, cofact_22 * detInv, cofact_32 * detInv, cofact_03 * detInv, cofact_13 * detInv, cofact_23 * detInv, cofact_33 * detInv, other);\n return other;\n }\n /**\n * add a value at the specified position in the current Matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#47\n * @param index the index of the value within the matrix. between 0 and 15.\n * @param value the value to be added\n * @returns the current updated matrix\n */\n addAtIndex(index, value) {\n this._m[index] += value;\n this.markAsUpdated();\n return this;\n }\n /**\n * mutiply the specified position in the current Matrix by a value\n * @param index the index of the value within the matrix. between 0 and 15.\n * @param value the value to be added\n * @returns the current updated matrix\n */\n multiplyAtIndex(index, value) {\n this._m[index] *= value;\n this.markAsUpdated();\n return this;\n }\n /**\n * Inserts the translation vector (using 3 floats) in the current matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#120\n * @param x defines the 1st component of the translation\n * @param y defines the 2nd component of the translation\n * @param z defines the 3rd component of the translation\n * @returns the current updated matrix\n */\n setTranslationFromFloats(x, y, z) {\n this._m[12] = x;\n this._m[13] = y;\n this._m[14] = z;\n this.markAsUpdated();\n return this;\n }\n /**\n * Adds the translation vector (using 3 floats) in the current matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#20\n * Example Playground - https://playground.babylonjs.com/#AV9X17#48\n * @param x defines the 1st component of the translation\n * @param y defines the 2nd component of the translation\n * @param z defines the 3rd component of the translation\n * @returns the current updated matrix\n */\n addTranslationFromFloats(x, y, z) {\n this._m[12] += x;\n this._m[13] += y;\n this._m[14] += z;\n this.markAsUpdated();\n return this;\n }\n /**\n * Inserts the translation vector in the current matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#121\n * @param vector3 defines the translation to insert\n * @returns the current updated matrix\n */\n setTranslation(vector3) {\n return this.setTranslationFromFloats(vector3._x, vector3._y, vector3._z);\n }\n /**\n * Gets the translation value of the current matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#122\n * @returns a new Vector3 as the extracted translation from the matrix\n */\n getTranslation() {\n return new Vector3(this._m[12], this._m[13], this._m[14]);\n }\n /**\n * Fill a Vector3 with the extracted translation from the matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#123\n * @param result defines the Vector3 where to store the translation\n * @returns the current matrix\n */\n getTranslationToRef(result) {\n result.x = this._m[12];\n result.y = this._m[13];\n result.z = this._m[14];\n return result;\n }\n /**\n * Remove rotation and scaling part from the matrix\n * @returns the updated matrix\n */\n removeRotationAndScaling() {\n const m = this.m;\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, m[12], m[13], m[14], m[15], this);\n this._updateIdentityStatus(m[12] === 0 && m[13] === 0 && m[14] === 0 && m[15] === 1);\n return this;\n }\n /**\n * Multiply two matrices\n * Example Playground - https://playground.babylonjs.com/#AV9X17#15\n * A.multiply(B) means apply B to A so result is B x A\n * @param other defines the second operand\n * @returns a new matrix set with the multiplication result of the current Matrix and the given one\n */\n multiply(other) {\n const result = new this.constructor();\n this.multiplyToRef(other, result);\n return result;\n }\n /**\n * Copy the current matrix from the given one\n * Example Playground - https://playground.babylonjs.com/#AV9X17#21\n * @param other defines the source matrix\n * @returns the current updated matrix\n */\n copyFrom(other) {\n other.copyToArray(this._m);\n const o = other;\n this.updateFlag = o.updateFlag;\n this._updateIdentityStatus(o._isIdentity, o._isIdentityDirty, o._isIdentity3x2, o._isIdentity3x2Dirty);\n return this;\n }\n /**\n * Populates the given array from the starting index with the current matrix values\n * @param array defines the target array\n * @param offset defines the offset in the target array where to start storing values\n * @returns the current matrix\n */\n copyToArray(array, offset = 0) {\n const source = this._m;\n array[offset] = source[0];\n array[offset + 1] = source[1];\n array[offset + 2] = source[2];\n array[offset + 3] = source[3];\n array[offset + 4] = source[4];\n array[offset + 5] = source[5];\n array[offset + 6] = source[6];\n array[offset + 7] = source[7];\n array[offset + 8] = source[8];\n array[offset + 9] = source[9];\n array[offset + 10] = source[10];\n array[offset + 11] = source[11];\n array[offset + 12] = source[12];\n array[offset + 13] = source[13];\n array[offset + 14] = source[14];\n array[offset + 15] = source[15];\n return this;\n }\n /**\n * Sets the given matrix \"result\" with the multiplication result of the current Matrix and the given one\n * A.multiplyToRef(B, R) means apply B to A and store in R and R = B x A\n * Example Playground - https://playground.babylonjs.com/#AV9X17#16\n * @param other defines the second operand\n * @param result defines the matrix where to store the multiplication\n * @returns result input\n */\n multiplyToRef(other, result) {\n if (this._isIdentity) {\n result.copyFrom(other);\n return result;\n }\n if (other._isIdentity) {\n result.copyFrom(this);\n return result;\n }\n this.multiplyToArray(other, result._m, 0);\n result.markAsUpdated();\n return result;\n }\n /**\n * Sets the Float32Array \"result\" from the given index \"offset\" with the multiplication of the current matrix and the given one\n * @param other defines the second operand\n * @param result defines the array where to store the multiplication\n * @param offset defines the offset in the target array where to start storing values\n * @returns the current matrix\n */\n multiplyToArray(other, result, offset) {\n const m = this._m;\n const otherM = other.m;\n const tm0 = m[0], tm1 = m[1], tm2 = m[2], tm3 = m[3];\n const tm4 = m[4], tm5 = m[5], tm6 = m[6], tm7 = m[7];\n const tm8 = m[8], tm9 = m[9], tm10 = m[10], tm11 = m[11];\n const tm12 = m[12], tm13 = m[13], tm14 = m[14], tm15 = m[15];\n const om0 = otherM[0], om1 = otherM[1], om2 = otherM[2], om3 = otherM[3];\n const om4 = otherM[4], om5 = otherM[5], om6 = otherM[6], om7 = otherM[7];\n const om8 = otherM[8], om9 = otherM[9], om10 = otherM[10], om11 = otherM[11];\n const om12 = otherM[12], om13 = otherM[13], om14 = otherM[14], om15 = otherM[15];\n result[offset] = tm0 * om0 + tm1 * om4 + tm2 * om8 + tm3 * om12;\n result[offset + 1] = tm0 * om1 + tm1 * om5 + tm2 * om9 + tm3 * om13;\n result[offset + 2] = tm0 * om2 + tm1 * om6 + tm2 * om10 + tm3 * om14;\n result[offset + 3] = tm0 * om3 + tm1 * om7 + tm2 * om11 + tm3 * om15;\n result[offset + 4] = tm4 * om0 + tm5 * om4 + tm6 * om8 + tm7 * om12;\n result[offset + 5] = tm4 * om1 + tm5 * om5 + tm6 * om9 + tm7 * om13;\n result[offset + 6] = tm4 * om2 + tm5 * om6 + tm6 * om10 + tm7 * om14;\n result[offset + 7] = tm4 * om3 + tm5 * om7 + tm6 * om11 + tm7 * om15;\n result[offset + 8] = tm8 * om0 + tm9 * om4 + tm10 * om8 + tm11 * om12;\n result[offset + 9] = tm8 * om1 + tm9 * om5 + tm10 * om9 + tm11 * om13;\n result[offset + 10] = tm8 * om2 + tm9 * om6 + tm10 * om10 + tm11 * om14;\n result[offset + 11] = tm8 * om3 + tm9 * om7 + tm10 * om11 + tm11 * om15;\n result[offset + 12] = tm12 * om0 + tm13 * om4 + tm14 * om8 + tm15 * om12;\n result[offset + 13] = tm12 * om1 + tm13 * om5 + tm14 * om9 + tm15 * om13;\n result[offset + 14] = tm12 * om2 + tm13 * om6 + tm14 * om10 + tm15 * om14;\n result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;\n return this;\n }\n /**\n * Check equality between this matrix and a second one\n * @param value defines the second matrix to compare\n * @returns true is the current matrix and the given one values are strictly equal\n */\n equals(value) {\n const other = value;\n if (!other) {\n return false;\n }\n if (this._isIdentity || other._isIdentity) {\n if (!this._isIdentityDirty && !other._isIdentityDirty) {\n return this._isIdentity && other._isIdentity;\n }\n }\n const m = this.m;\n const om = other.m;\n return (m[0] === om[0] &&\n m[1] === om[1] &&\n m[2] === om[2] &&\n m[3] === om[3] &&\n m[4] === om[4] &&\n m[5] === om[5] &&\n m[6] === om[6] &&\n m[7] === om[7] &&\n m[8] === om[8] &&\n m[9] === om[9] &&\n m[10] === om[10] &&\n m[11] === om[11] &&\n m[12] === om[12] &&\n m[13] === om[13] &&\n m[14] === om[14] &&\n m[15] === om[15]);\n }\n /**\n * Clone the current matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#18\n * @returns a new matrix from the current matrix\n */\n clone() {\n const matrix = new this.constructor();\n matrix.copyFrom(this);\n return matrix;\n }\n /**\n * Returns the name of the current matrix class\n * @returns the string \"Matrix\"\n */\n getClassName() {\n return \"Matrix\";\n }\n /**\n * Gets the hash code of the current matrix\n * @returns the hash code\n */\n getHashCode() {\n let hash = _ExtractAsInt(this._m[0]);\n for (let i = 1; i < 16; i++) {\n hash = (hash * 397) ^ _ExtractAsInt(this._m[i]);\n }\n return hash;\n }\n /**\n * Decomposes the current Matrix into a translation, rotation and scaling components of the provided node\n * Example Playground - https://playground.babylonjs.com/#AV9X17#13\n * @param node the node to decompose the matrix to\n * @returns true if operation was successful\n */\n decomposeToTransformNode(node) {\n node.rotationQuaternion = node.rotationQuaternion || new Quaternion();\n return this.decompose(node.scaling, node.rotationQuaternion, node.position);\n }\n /**\n * Decomposes the current Matrix into a translation, rotation and scaling components\n * Example Playground - https://playground.babylonjs.com/#AV9X17#12\n * @param scale defines the scale vector3 given as a reference to update\n * @param rotation defines the rotation quaternion given as a reference to update\n * @param translation defines the translation vector3 given as a reference to update\n * @param preserveScalingNode Use scaling sign coming from this node. Otherwise scaling sign might change.\n * @returns true if operation was successful\n */\n decompose(scale, rotation, translation, preserveScalingNode) {\n if (this._isIdentity) {\n if (translation) {\n translation.setAll(0);\n }\n if (scale) {\n scale.setAll(1);\n }\n if (rotation) {\n rotation.copyFromFloats(0, 0, 0, 1);\n }\n return true;\n }\n const m = this._m;\n if (translation) {\n translation.copyFromFloats(m[12], m[13], m[14]);\n }\n scale = scale || MathTmp.Vector3[0];\n scale.x = Math.sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]);\n scale.y = Math.sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]);\n scale.z = Math.sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]);\n if (preserveScalingNode) {\n const signX = preserveScalingNode.scaling.x < 0 ? -1 : 1;\n const signY = preserveScalingNode.scaling.y < 0 ? -1 : 1;\n const signZ = preserveScalingNode.scaling.z < 0 ? -1 : 1;\n scale.x *= signX;\n scale.y *= signY;\n scale.z *= signZ;\n }\n else {\n if (this.determinant() <= 0) {\n scale.y *= -1;\n }\n }\n if (scale._x === 0 || scale._y === 0 || scale._z === 0) {\n if (rotation) {\n rotation.copyFromFloats(0.0, 0.0, 0.0, 1.0);\n }\n return false;\n }\n if (rotation) {\n const sx = 1 / scale._x, sy = 1 / scale._y, sz = 1 / scale._z;\n Matrix.FromValuesToRef(m[0] * sx, m[1] * sx, m[2] * sx, 0.0, m[4] * sy, m[5] * sy, m[6] * sy, 0.0, m[8] * sz, m[9] * sz, m[10] * sz, 0.0, 0.0, 0.0, 0.0, 1.0, MathTmp.Matrix[0]);\n Quaternion.FromRotationMatrixToRef(MathTmp.Matrix[0], rotation);\n }\n return true;\n }\n /**\n * Gets specific row of the matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\n * @param index defines the number of the row to get\n * @returns the index-th row of the current matrix as a new Vector4\n */\n getRow(index) {\n if (index < 0 || index > 3) {\n return null;\n }\n const i = index * 4;\n return new Vector4(this._m[i + 0], this._m[i + 1], this._m[i + 2], this._m[i + 3]);\n }\n /**\n * Gets specific row of the matrix to ref\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\n * @param index defines the number of the row to get\n * @param rowVector vector to store the index-th row of the current matrix\n * @returns result input\n */\n getRowToRef(index, rowVector) {\n if (index >= 0 && index < 3) {\n const i = index * 4;\n rowVector.x = this._m[i + 0];\n rowVector.y = this._m[i + 1];\n rowVector.z = this._m[i + 2];\n rowVector.w = this._m[i + 3];\n }\n return rowVector;\n }\n /**\n * Sets the index-th row of the current matrix to the vector4 values\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\n * @param index defines the number of the row to set\n * @param row defines the target vector4\n * @returns the updated current matrix\n */\n setRow(index, row) {\n return this.setRowFromFloats(index, row.x, row.y, row.z, row.w);\n }\n /**\n * Compute the transpose of the matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#40\n * @returns the new transposed matrix\n */\n transpose() {\n const result = new this.constructor();\n Matrix.TransposeToRef(this, result);\n return result;\n }\n /**\n * Compute the transpose of the matrix and store it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#41\n * @param result defines the target matrix\n * @returns result input\n */\n transposeToRef(result) {\n Matrix.TransposeToRef(this, result);\n return result;\n }\n /**\n * Sets the index-th row of the current matrix with the given 4 x float values\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\n * @param index defines the row index\n * @param x defines the x component to set\n * @param y defines the y component to set\n * @param z defines the z component to set\n * @param w defines the w component to set\n * @returns the updated current matrix\n */\n setRowFromFloats(index, x, y, z, w) {\n if (index < 0 || index > 3) {\n return this;\n }\n const i = index * 4;\n this._m[i + 0] = x;\n this._m[i + 1] = y;\n this._m[i + 2] = z;\n this._m[i + 3] = w;\n this.markAsUpdated();\n return this;\n }\n /**\n * Compute a new matrix set with the current matrix values multiplied by scale (float)\n * @param scale defines the scale factor\n * @returns a new matrix\n */\n scale(scale) {\n const result = new this.constructor();\n this.scaleToRef(scale, result);\n return result;\n }\n /**\n * Scale the current matrix values by a factor to a given result matrix\n * @param scale defines the scale factor\n * @param result defines the matrix to store the result\n * @returns result input\n */\n scaleToRef(scale, result) {\n for (let index = 0; index < 16; index++) {\n result._m[index] = this._m[index] * scale;\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Scale the current matrix values by a factor and add the result to a given matrix\n * @param scale defines the scale factor\n * @param result defines the Matrix to store the result\n * @returns result input\n */\n scaleAndAddToRef(scale, result) {\n for (let index = 0; index < 16; index++) {\n result._m[index] += this._m[index] * scale;\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Writes to the given matrix a normal matrix, computed from this one (using values from identity matrix for fourth row and column).\n * Example Playground - https://playground.babylonjs.com/#AV9X17#17\n * @param ref matrix to store the result\n */\n toNormalMatrix(ref) {\n const tmp = MathTmp.Matrix[0];\n this.invertToRef(tmp);\n tmp.transposeToRef(ref);\n const m = ref._m;\n Matrix.FromValuesToRef(m[0], m[1], m[2], 0.0, m[4], m[5], m[6], 0.0, m[8], m[9], m[10], 0.0, 0.0, 0.0, 0.0, 1.0, ref);\n return ref;\n }\n /**\n * Gets only rotation part of the current matrix\n * @returns a new matrix sets to the extracted rotation matrix from the current one\n */\n getRotationMatrix() {\n const result = new this.constructor();\n this.getRotationMatrixToRef(result);\n return result;\n }\n /**\n * Extracts the rotation matrix from the current one and sets it as the given \"result\"\n * @param result defines the target matrix to store data to\n * @returns result input\n */\n getRotationMatrixToRef(result) {\n const scale = MathTmp.Vector3[0];\n if (!this.decompose(scale)) {\n Matrix.IdentityToRef(result);\n return result;\n }\n const m = this._m;\n const sx = 1 / scale._x, sy = 1 / scale._y, sz = 1 / scale._z;\n Matrix.FromValuesToRef(m[0] * sx, m[1] * sx, m[2] * sx, 0.0, m[4] * sy, m[5] * sy, m[6] * sy, 0.0, m[8] * sz, m[9] * sz, m[10] * sz, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n return result;\n }\n /**\n * Toggles model matrix from being right handed to left handed in place and vice versa\n */\n toggleModelMatrixHandInPlace() {\n const m = this._m;\n m[2] *= -1;\n m[6] *= -1;\n m[8] *= -1;\n m[9] *= -1;\n m[14] *= -1;\n this.markAsUpdated();\n return this;\n }\n /**\n * Toggles projection matrix from being right handed to left handed in place and vice versa\n */\n toggleProjectionMatrixHandInPlace() {\n const m = this._m;\n m[8] *= -1;\n m[9] *= -1;\n m[10] *= -1;\n m[11] *= -1;\n this.markAsUpdated();\n return this;\n }\n // Statics\n /**\n * Creates a matrix from an array\n * Example Playground - https://playground.babylonjs.com/#AV9X17#42\n * @param array defines the source array\n * @param offset defines an offset in the source array\n * @returns a new Matrix set from the starting index of the given array\n */\n static FromArray(array, offset = 0) {\n const result = new Matrix();\n Matrix.FromArrayToRef(array, offset, result);\n return result;\n }\n /**\n * Copy the content of an array into a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#43\n * @param array defines the source array\n * @param offset defines an offset in the source array\n * @param result defines the target matrix\n * @returns result input\n */\n static FromArrayToRef(array, offset, result) {\n for (let index = 0; index < 16; index++) {\n result._m[index] = array[index + offset];\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Stores an array into a matrix after having multiplied each component by a given factor\n * Example Playground - https://playground.babylonjs.com/#AV9X17#50\n * @param array defines the source array\n * @param offset defines the offset in the source array\n * @param scale defines the scaling factor\n * @param result defines the target matrix\n * @returns result input\n */\n static FromFloat32ArrayToRefScaled(array, offset, scale, result) {\n for (let index = 0; index < 16; index++) {\n result._m[index] = array[index + offset] * scale;\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Gets an identity matrix that must not be updated\n */\n static get IdentityReadOnly() {\n return Matrix._IdentityReadOnly;\n }\n /**\n * Stores a list of values (16) inside a given matrix\n * @param initialM11 defines 1st value of 1st row\n * @param initialM12 defines 2nd value of 1st row\n * @param initialM13 defines 3rd value of 1st row\n * @param initialM14 defines 4th value of 1st row\n * @param initialM21 defines 1st value of 2nd row\n * @param initialM22 defines 2nd value of 2nd row\n * @param initialM23 defines 3rd value of 2nd row\n * @param initialM24 defines 4th value of 2nd row\n * @param initialM31 defines 1st value of 3rd row\n * @param initialM32 defines 2nd value of 3rd row\n * @param initialM33 defines 3rd value of 3rd row\n * @param initialM34 defines 4th value of 3rd row\n * @param initialM41 defines 1st value of 4th row\n * @param initialM42 defines 2nd value of 4th row\n * @param initialM43 defines 3rd value of 4th row\n * @param initialM44 defines 4th value of 4th row\n * @param result defines the target matrix\n * @returns result input\n */\n static FromValuesToRef(initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44, result) {\n const m = result._m;\n m[0] = initialM11;\n m[1] = initialM12;\n m[2] = initialM13;\n m[3] = initialM14;\n m[4] = initialM21;\n m[5] = initialM22;\n m[6] = initialM23;\n m[7] = initialM24;\n m[8] = initialM31;\n m[9] = initialM32;\n m[10] = initialM33;\n m[11] = initialM34;\n m[12] = initialM41;\n m[13] = initialM42;\n m[14] = initialM43;\n m[15] = initialM44;\n result.markAsUpdated();\n }\n /**\n * Creates new matrix from a list of values (16)\n * @param initialM11 defines 1st value of 1st row\n * @param initialM12 defines 2nd value of 1st row\n * @param initialM13 defines 3rd value of 1st row\n * @param initialM14 defines 4th value of 1st row\n * @param initialM21 defines 1st value of 2nd row\n * @param initialM22 defines 2nd value of 2nd row\n * @param initialM23 defines 3rd value of 2nd row\n * @param initialM24 defines 4th value of 2nd row\n * @param initialM31 defines 1st value of 3rd row\n * @param initialM32 defines 2nd value of 3rd row\n * @param initialM33 defines 3rd value of 3rd row\n * @param initialM34 defines 4th value of 3rd row\n * @param initialM41 defines 1st value of 4th row\n * @param initialM42 defines 2nd value of 4th row\n * @param initialM43 defines 3rd value of 4th row\n * @param initialM44 defines 4th value of 4th row\n * @returns the new matrix\n */\n static FromValues(initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44) {\n const result = new Matrix();\n const m = result._m;\n m[0] = initialM11;\n m[1] = initialM12;\n m[2] = initialM13;\n m[3] = initialM14;\n m[4] = initialM21;\n m[5] = initialM22;\n m[6] = initialM23;\n m[7] = initialM24;\n m[8] = initialM31;\n m[9] = initialM32;\n m[10] = initialM33;\n m[11] = initialM34;\n m[12] = initialM41;\n m[13] = initialM42;\n m[14] = initialM43;\n m[15] = initialM44;\n result.markAsUpdated();\n return result;\n }\n /**\n * Creates a new matrix composed by merging scale (vector3), rotation (quaternion) and translation (vector3)\n * Example Playground - https://playground.babylonjs.com/#AV9X17#24\n * @param scale defines the scale vector3\n * @param rotation defines the rotation quaternion\n * @param translation defines the translation vector3\n * @returns a new matrix\n */\n static Compose(scale, rotation, translation) {\n const result = new Matrix();\n Matrix.ComposeToRef(scale, rotation, translation, result);\n return result;\n }\n /**\n * Sets a matrix to a value composed by merging scale (vector3), rotation (quaternion) and translation (vector3)\n * Example Playground - https://playground.babylonjs.com/#AV9X17#25\n * @param scale defines the scale vector3\n * @param rotation defines the rotation quaternion\n * @param translation defines the translation vector3\n * @param result defines the target matrix\n * @returns result input\n */\n static ComposeToRef(scale, rotation, translation, result) {\n const m = result._m;\n const x = rotation._x, y = rotation._y, z = rotation._z, w = rotation._w;\n const x2 = x + x, y2 = y + y, z2 = z + z;\n const xx = x * x2, xy = x * y2, xz = x * z2;\n const yy = y * y2, yz = y * z2, zz = z * z2;\n const wx = w * x2, wy = w * y2, wz = w * z2;\n const sx = scale._x, sy = scale._y, sz = scale._z;\n m[0] = (1 - (yy + zz)) * sx;\n m[1] = (xy + wz) * sx;\n m[2] = (xz - wy) * sx;\n m[3] = 0;\n m[4] = (xy - wz) * sy;\n m[5] = (1 - (xx + zz)) * sy;\n m[6] = (yz + wx) * sy;\n m[7] = 0;\n m[8] = (xz + wy) * sz;\n m[9] = (yz - wx) * sz;\n m[10] = (1 - (xx + yy)) * sz;\n m[11] = 0;\n m[12] = translation._x;\n m[13] = translation._y;\n m[14] = translation._z;\n m[15] = 1;\n result.markAsUpdated();\n return result;\n }\n /**\n * Creates a new identity matrix\n * @returns a new identity matrix\n */\n static Identity() {\n const identity = Matrix.FromValues(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);\n identity._updateIdentityStatus(true);\n return identity;\n }\n /**\n * Creates a new identity matrix and stores the result in a given matrix\n * @param result defines the target matrix\n * @returns result input\n */\n static IdentityToRef(result) {\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n result._updateIdentityStatus(true);\n return result;\n }\n /**\n * Creates a new zero matrix\n * @returns a new zero matrix\n */\n static Zero() {\n const zero = Matrix.FromValues(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);\n zero._updateIdentityStatus(false);\n return zero;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the X axis\n * Example Playground - https://playground.babylonjs.com/#AV9X17#97\n * @param angle defines the angle (in radians) to use\n * @returns the new matrix\n */\n static RotationX(angle) {\n const result = new Matrix();\n Matrix.RotationXToRef(angle, result);\n return result;\n }\n /**\n * Creates a new matrix as the invert of a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#124\n * @param source defines the source matrix\n * @returns the new matrix\n */\n static Invert(source) {\n const result = new source.constructor();\n source.invertToRef(result);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the X axis and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#98\n * @param angle defines the angle (in radians) to use\n * @param result defines the target matrix\n * @returns result input\n */\n static RotationXToRef(angle, result) {\n const s = Math.sin(angle);\n const c = Math.cos(angle);\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n result._updateIdentityStatus(c === 1 && s === 0);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the Y axis\n * Example Playground - https://playground.babylonjs.com/#AV9X17#99\n * @param angle defines the angle (in radians) to use\n * @returns the new matrix\n */\n static RotationY(angle) {\n const result = new Matrix();\n Matrix.RotationYToRef(angle, result);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the Y axis and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#100\n * @param angle defines the angle (in radians) to use\n * @param result defines the target matrix\n * @returns result input\n */\n static RotationYToRef(angle, result) {\n const s = Math.sin(angle);\n const c = Math.cos(angle);\n Matrix.FromValuesToRef(c, 0.0, -s, 0.0, 0.0, 1.0, 0.0, 0.0, s, 0.0, c, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n result._updateIdentityStatus(c === 1 && s === 0);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the Z axis\n * Example Playground - https://playground.babylonjs.com/#AV9X17#101\n * @param angle defines the angle (in radians) to use\n * @returns the new matrix\n */\n static RotationZ(angle) {\n const result = new Matrix();\n Matrix.RotationZToRef(angle, result);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the Z axis and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#102\n * @param angle defines the angle (in radians) to use\n * @param result defines the target matrix\n * @returns result input\n */\n static RotationZToRef(angle, result) {\n const s = Math.sin(angle);\n const c = Math.cos(angle);\n Matrix.FromValuesToRef(c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n result._updateIdentityStatus(c === 1 && s === 0);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the given axis\n * Example Playground - https://playground.babylonjs.com/#AV9X17#96\n * @param axis defines the axis to use\n * @param angle defines the angle (in radians) to use\n * @returns the new matrix\n */\n static RotationAxis(axis, angle) {\n const result = new Matrix();\n Matrix.RotationAxisToRef(axis, angle, result);\n return result;\n }\n /**\n * Creates a new rotation matrix for \"angle\" radians around the given axis and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#94\n * @param axis defines the axis to use\n * @param angle defines the angle (in radians) to use\n * @param result defines the target matrix\n * @returns result input\n */\n static RotationAxisToRef(axis, angle, result) {\n const s = Math.sin(-angle);\n const c = Math.cos(-angle);\n const c1 = 1 - c;\n axis.normalize();\n const m = result._m;\n m[0] = axis._x * axis._x * c1 + c;\n m[1] = axis._x * axis._y * c1 - axis._z * s;\n m[2] = axis._x * axis._z * c1 + axis._y * s;\n m[3] = 0.0;\n m[4] = axis._y * axis._x * c1 + axis._z * s;\n m[5] = axis._y * axis._y * c1 + c;\n m[6] = axis._y * axis._z * c1 - axis._x * s;\n m[7] = 0.0;\n m[8] = axis._z * axis._x * c1 - axis._y * s;\n m[9] = axis._z * axis._y * c1 + axis._x * s;\n m[10] = axis._z * axis._z * c1 + c;\n m[11] = 0.0;\n m[12] = 0.0;\n m[13] = 0.0;\n m[14] = 0.0;\n m[15] = 1.0;\n result.markAsUpdated();\n return result;\n }\n /**\n * Takes normalised vectors and returns a rotation matrix to align \"from\" with \"to\".\n * Taken from http://www.iquilezles.org/www/articles/noacos/noacos.htm\n * Example Playground - https://playground.babylonjs.com/#AV9X17#93\n * @param from defines the vector to align\n * @param to defines the vector to align to\n * @param result defines the target matrix\n * @returns result input\n */\n static RotationAlignToRef(from, to, result) {\n const c = Vector3.Dot(to, from);\n const m = result._m;\n if (c < -1 + Epsilon) {\n // from and to are colinear and opposite direction.\n // compute a PI rotation on Z axis\n m[0] = -1;\n m[1] = 0;\n m[2] = 0;\n m[3] = 0;\n m[4] = 0;\n m[5] = -1;\n m[6] = 0;\n m[7] = 0;\n m[8] = 0;\n m[9] = 0;\n m[10] = 1;\n m[11] = 0;\n }\n else {\n const v = Vector3.Cross(to, from);\n const k = 1 / (1 + c);\n m[0] = v._x * v._x * k + c;\n m[1] = v._y * v._x * k - v._z;\n m[2] = v._z * v._x * k + v._y;\n m[3] = 0;\n m[4] = v._x * v._y * k + v._z;\n m[5] = v._y * v._y * k + c;\n m[6] = v._z * v._y * k - v._x;\n m[7] = 0;\n m[8] = v._x * v._z * k - v._y;\n m[9] = v._y * v._z * k + v._x;\n m[10] = v._z * v._z * k + c;\n m[11] = 0;\n }\n m[12] = 0;\n m[13] = 0;\n m[14] = 0;\n m[15] = 1;\n result.markAsUpdated();\n return result;\n }\n /**\n * Creates a rotation matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#103\n * Example Playground - https://playground.babylonjs.com/#AV9X17#105\n * @param yaw defines the yaw angle in radians (Y axis)\n * @param pitch defines the pitch angle in radians (X axis)\n * @param roll defines the roll angle in radians (Z axis)\n * @returns the new rotation matrix\n */\n static RotationYawPitchRoll(yaw, pitch, roll) {\n const result = new Matrix();\n Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, result);\n return result;\n }\n /**\n * Creates a rotation matrix and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#104\n * @param yaw defines the yaw angle in radians (Y axis)\n * @param pitch defines the pitch angle in radians (X axis)\n * @param roll defines the roll angle in radians (Z axis)\n * @param result defines the target matrix\n * @returns result input\n */\n static RotationYawPitchRollToRef(yaw, pitch, roll, result) {\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, MathTmp.Quaternion[0]);\n MathTmp.Quaternion[0].toRotationMatrix(result);\n return result;\n }\n /**\n * Creates a scaling matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#107\n * @param x defines the scale factor on X axis\n * @param y defines the scale factor on Y axis\n * @param z defines the scale factor on Z axis\n * @returns the new matrix\n */\n static Scaling(x, y, z) {\n const result = new Matrix();\n Matrix.ScalingToRef(x, y, z, result);\n return result;\n }\n /**\n * Creates a scaling matrix and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#108\n * @param x defines the scale factor on X axis\n * @param y defines the scale factor on Y axis\n * @param z defines the scale factor on Z axis\n * @param result defines the target matrix\n * @returns result input\n */\n static ScalingToRef(x, y, z, result) {\n Matrix.FromValuesToRef(x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n result._updateIdentityStatus(x === 1 && y === 1 && z === 1);\n return result;\n }\n /**\n * Creates a translation matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#109\n * @param x defines the translation on X axis\n * @param y defines the translation on Y axis\n * @param z defines the translationon Z axis\n * @returns the new matrix\n */\n static Translation(x, y, z) {\n const result = new Matrix();\n Matrix.TranslationToRef(x, y, z, result);\n return result;\n }\n /**\n * Creates a translation matrix and stores it in a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#110\n * @param x defines the translation on X axis\n * @param y defines the translation on Y axis\n * @param z defines the translationon Z axis\n * @param result defines the target matrix\n * @returns result input\n */\n static TranslationToRef(x, y, z, result) {\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, x, y, z, 1.0, result);\n result._updateIdentityStatus(x === 0 && y === 0 && z === 0);\n return result;\n }\n /**\n * Returns a new Matrix whose values are the interpolated values for \"gradient\" (float) between the ones of the matrices \"startValue\" and \"endValue\".\n * Example Playground - https://playground.babylonjs.com/#AV9X17#55\n * @param startValue defines the start value\n * @param endValue defines the end value\n * @param gradient defines the gradient factor\n * @returns the new matrix\n */\n static Lerp(startValue, endValue, gradient) {\n const result = new startValue.constructor();\n Matrix.LerpToRef(startValue, endValue, gradient, result);\n return result;\n }\n /**\n * Set the given matrix \"result\" as the interpolated values for \"gradient\" (float) between the ones of the matrices \"startValue\" and \"endValue\".\n * Example Playground - https://playground.babylonjs.com/#AV9X17#54\n * @param startValue defines the start value\n * @param endValue defines the end value\n * @param gradient defines the gradient factor\n * @param result defines the Matrix object where to store data\n * @returns result input\n */\n static LerpToRef(startValue, endValue, gradient, result) {\n const resultM = result._m;\n const startM = startValue.m;\n const endM = endValue.m;\n for (let index = 0; index < 16; index++) {\n resultM[index] = startM[index] * (1.0 - gradient) + endM[index] * gradient;\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Builds a new matrix whose values are computed by:\n * * decomposing the the \"startValue\" and \"endValue\" matrices into their respective scale, rotation and translation matrices\n * * interpolating for \"gradient\" (float) the values between each of these decomposed matrices between the start and the end\n * * recomposing a new matrix from these 3 interpolated scale, rotation and translation matrices\n * Example Playground - https://playground.babylonjs.com/#AV9X17#22\n * Example Playground - https://playground.babylonjs.com/#AV9X17#51\n * @param startValue defines the first matrix\n * @param endValue defines the second matrix\n * @param gradient defines the gradient between the two matrices\n * @returns the new matrix\n */\n static DecomposeLerp(startValue, endValue, gradient) {\n const result = new startValue.constructor();\n Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);\n return result;\n }\n /**\n * Update a matrix to values which are computed by:\n * * decomposing the the \"startValue\" and \"endValue\" matrices into their respective scale, rotation and translation matrices\n * * interpolating for \"gradient\" (float) the values between each of these decomposed matrices between the start and the end\n * * recomposing a new matrix from these 3 interpolated scale, rotation and translation matrices\n * Example Playground - https://playground.babylonjs.com/#AV9X17#23\n * Example Playground - https://playground.babylonjs.com/#AV9X17#53\n * @param startValue defines the first matrix\n * @param endValue defines the second matrix\n * @param gradient defines the gradient between the two matrices\n * @param result defines the target matrix\n * @returns result input\n */\n static DecomposeLerpToRef(startValue, endValue, gradient, result) {\n const startScale = MathTmp.Vector3[0];\n const startRotation = MathTmp.Quaternion[0];\n const startTranslation = MathTmp.Vector3[1];\n startValue.decompose(startScale, startRotation, startTranslation);\n const endScale = MathTmp.Vector3[2];\n const endRotation = MathTmp.Quaternion[1];\n const endTranslation = MathTmp.Vector3[3];\n endValue.decompose(endScale, endRotation, endTranslation);\n const resultScale = MathTmp.Vector3[4];\n Vector3.LerpToRef(startScale, endScale, gradient, resultScale);\n const resultRotation = MathTmp.Quaternion[2];\n Quaternion.SlerpToRef(startRotation, endRotation, gradient, resultRotation);\n const resultTranslation = MathTmp.Vector3[5];\n Vector3.LerpToRef(startTranslation, endTranslation, gradient, resultTranslation);\n Matrix.ComposeToRef(resultScale, resultRotation, resultTranslation, result);\n return result;\n }\n /**\n * Creates a new matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\n * This function generates a matrix suitable for a left handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#58\n * Example Playground - https://playground.babylonjs.com/#AV9X17#59\n * @param eye defines the final position of the entity\n * @param target defines where the entity should look at\n * @param up defines the up vector for the entity\n * @returns the new matrix\n */\n static LookAtLH(eye, target, up) {\n const result = new Matrix();\n Matrix.LookAtLHToRef(eye, target, up, result);\n return result;\n }\n /**\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\n * This function generates a matrix suitable for a left handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#60\n * Example Playground - https://playground.babylonjs.com/#AV9X17#61\n * @param eye defines the final position of the entity\n * @param target defines where the entity should look at\n * @param up defines the up vector for the entity\n * @param result defines the target matrix\n * @returns result input\n */\n static LookAtLHToRef(eye, target, up, result) {\n const xAxis = MathTmp.Vector3[0];\n const yAxis = MathTmp.Vector3[1];\n const zAxis = MathTmp.Vector3[2];\n // Z axis\n target.subtractToRef(eye, zAxis);\n zAxis.normalize();\n // X axis\n Vector3.CrossToRef(up, zAxis, xAxis);\n const xSquareLength = xAxis.lengthSquared();\n if (xSquareLength === 0) {\n xAxis.x = 1.0;\n }\n else {\n xAxis.normalizeFromLength(Math.sqrt(xSquareLength));\n }\n // Y axis\n Vector3.CrossToRef(zAxis, xAxis, yAxis);\n yAxis.normalize();\n // Eye angles\n const ex = -Vector3.Dot(xAxis, eye);\n const ey = -Vector3.Dot(yAxis, eye);\n const ez = -Vector3.Dot(zAxis, eye);\n Matrix.FromValuesToRef(xAxis._x, yAxis._x, zAxis._x, 0.0, xAxis._y, yAxis._y, zAxis._y, 0.0, xAxis._z, yAxis._z, zAxis._z, 0.0, ex, ey, ez, 1.0, result);\n }\n /**\n * Creates a new matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\n * This function generates a matrix suitable for a right handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#62\n * Example Playground - https://playground.babylonjs.com/#AV9X17#63\n * @param eye defines the final position of the entity\n * @param target defines where the entity should look at\n * @param up defines the up vector for the entity\n * @returns the new matrix\n */\n static LookAtRH(eye, target, up) {\n const result = new Matrix();\n Matrix.LookAtRHToRef(eye, target, up, result);\n return result;\n }\n /**\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\n * This function generates a matrix suitable for a right handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#64\n * Example Playground - https://playground.babylonjs.com/#AV9X17#65\n * @param eye defines the final position of the entity\n * @param target defines where the entity should look at\n * @param up defines the up vector for the entity\n * @param result defines the target matrix\n * @returns result input\n */\n static LookAtRHToRef(eye, target, up, result) {\n const xAxis = MathTmp.Vector3[0];\n const yAxis = MathTmp.Vector3[1];\n const zAxis = MathTmp.Vector3[2];\n // Z axis\n eye.subtractToRef(target, zAxis);\n zAxis.normalize();\n // X axis\n Vector3.CrossToRef(up, zAxis, xAxis);\n const xSquareLength = xAxis.lengthSquared();\n if (xSquareLength === 0) {\n xAxis.x = 1.0;\n }\n else {\n xAxis.normalizeFromLength(Math.sqrt(xSquareLength));\n }\n // Y axis\n Vector3.CrossToRef(zAxis, xAxis, yAxis);\n yAxis.normalize();\n // Eye angles\n const ex = -Vector3.Dot(xAxis, eye);\n const ey = -Vector3.Dot(yAxis, eye);\n const ez = -Vector3.Dot(zAxis, eye);\n Matrix.FromValuesToRef(xAxis._x, yAxis._x, zAxis._x, 0.0, xAxis._y, yAxis._y, zAxis._y, 0.0, xAxis._z, yAxis._z, zAxis._z, 0.0, ex, ey, ez, 1.0, result);\n return result;\n }\n /**\n * Creates a new matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\n * This function generates a matrix suitable for a left handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#66\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @returns the new matrix\n */\n static LookDirectionLH(forward, up) {\n const result = new Matrix();\n Matrix.LookDirectionLHToRef(forward, up, result);\n return result;\n }\n /**\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\n * This function generates a matrix suitable for a left handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#67\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @param result defines the target matrix\n * @returns result input\n */\n static LookDirectionLHToRef(forward, up, result) {\n const back = MathTmp.Vector3[0];\n back.copyFrom(forward);\n back.scaleInPlace(-1);\n const left = MathTmp.Vector3[1];\n Vector3.CrossToRef(up, back, left);\n // Generate the rotation matrix.\n Matrix.FromValuesToRef(left._x, left._y, left._z, 0.0, up._x, up._y, up._z, 0.0, back._x, back._y, back._z, 0.0, 0, 0, 0, 1.0, result);\n return result;\n }\n /**\n * Creates a new matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\n * This function generates a matrix suitable for a right handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#68\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @returns the new matrix\n */\n static LookDirectionRH(forward, up) {\n const result = new Matrix();\n Matrix.LookDirectionRHToRef(forward, up, result);\n return result;\n }\n /**\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\n * This function generates a matrix suitable for a right handed coordinate system\n * Example Playground - https://playground.babylonjs.com/#AV9X17#69\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\n * @param result defines the target matrix\n * @returns result input\n */\n static LookDirectionRHToRef(forward, up, result) {\n const right = MathTmp.Vector3[2];\n Vector3.CrossToRef(up, forward, right);\n // Generate the rotation matrix.\n Matrix.FromValuesToRef(right._x, right._y, right._z, 0.0, up._x, up._y, up._z, 0.0, forward._x, forward._y, forward._z, 0.0, 0, 0, 0, 1.0, result);\n return result;\n }\n /**\n * Create a left-handed orthographic projection matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#70\n * @param width defines the viewport width\n * @param height defines the viewport height\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @returns a new matrix as a left-handed orthographic projection matrix\n */\n static OrthoLH(width, height, znear, zfar, halfZRange) {\n const matrix = new Matrix();\n Matrix.OrthoLHToRef(width, height, znear, zfar, matrix, halfZRange);\n return matrix;\n }\n /**\n * Store a left-handed orthographic projection to a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#71\n * @param width defines the viewport width\n * @param height defines the viewport height\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param result defines the target matrix\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @returns result input\n */\n static OrthoLHToRef(width, height, znear, zfar, result, halfZRange) {\n const n = znear;\n const f = zfar;\n const a = 2.0 / width;\n const b = 2.0 / height;\n const c = 2.0 / (f - n);\n const d = -(f + n) / (f - n);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, 0.0, 0.0, d, 1.0, result);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result._updateIdentityStatus(a === 1 && b === 1 && c === 1 && d === 0);\n return result;\n }\n /**\n * Create a left-handed orthographic projection matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#72\n * @param left defines the viewport left coordinate\n * @param right defines the viewport right coordinate\n * @param bottom defines the viewport bottom coordinate\n * @param top defines the viewport top coordinate\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @returns a new matrix as a left-handed orthographic projection matrix\n */\n static OrthoOffCenterLH(left, right, bottom, top, znear, zfar, halfZRange) {\n const matrix = new Matrix();\n Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, matrix, halfZRange);\n return matrix;\n }\n /**\n * Stores a left-handed orthographic projection into a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#73\n * @param left defines the viewport left coordinate\n * @param right defines the viewport right coordinate\n * @param bottom defines the viewport bottom coordinate\n * @param top defines the viewport top coordinate\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param result defines the target matrix\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @returns result input\n */\n static OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange) {\n const n = znear;\n const f = zfar;\n const a = 2.0 / (right - left);\n const b = 2.0 / (top - bottom);\n const c = 2.0 / (f - n);\n const d = -(f + n) / (f - n);\n const i0 = (left + right) / (left - right);\n const i1 = (top + bottom) / (bottom - top);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, i0, i1, d, 1.0, result);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Creates a right-handed orthographic projection matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#76\n * @param left defines the viewport left coordinate\n * @param right defines the viewport right coordinate\n * @param bottom defines the viewport bottom coordinate\n * @param top defines the viewport top coordinate\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @returns a new matrix as a right-handed orthographic projection matrix\n */\n static OrthoOffCenterRH(left, right, bottom, top, znear, zfar, halfZRange) {\n const matrix = new Matrix();\n Matrix.OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, matrix, halfZRange);\n return matrix;\n }\n /**\n * Stores a right-handed orthographic projection into a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#77\n * @param left defines the viewport left coordinate\n * @param right defines the viewport right coordinate\n * @param bottom defines the viewport bottom coordinate\n * @param top defines the viewport top coordinate\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param result defines the target matrix\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @returns result input\n */\n static OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, result, halfZRange) {\n Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange);\n result._m[10] *= -1; // No need to call markAsUpdated as previous function already called it and let _isIdentityDirty to true\n return result;\n }\n /**\n * Creates a left-handed perspective projection matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#85\n * @param width defines the viewport width\n * @param height defines the viewport height\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @returns a new matrix as a left-handed perspective projection matrix\n */\n static PerspectiveLH(width, height, znear, zfar, halfZRange, projectionPlaneTilt = 0) {\n const matrix = new Matrix();\n const n = znear;\n const f = zfar;\n const a = (2.0 * n) / width;\n const b = (2.0 * n) / height;\n const c = (f + n) / (f - n);\n const d = (-2.0 * f * n) / (f - n);\n const rot = Math.tan(projectionPlaneTilt);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, c, 1.0, 0.0, 0.0, d, 0.0, matrix);\n if (halfZRange) {\n matrix.multiplyToRef(mtxConvertNDCToHalfZRange, matrix);\n }\n matrix._updateIdentityStatus(false);\n return matrix;\n }\n /**\n * Creates a left-handed perspective projection matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#78\n * @param fov defines the horizontal field of view\n * @param aspect defines the aspect ratio\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\n * @returns a new matrix as a left-handed perspective projection matrix\n */\n static PerspectiveFovLH(fov, aspect, znear, zfar, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {\n const matrix = new Matrix();\n Matrix.PerspectiveFovLHToRef(fov, aspect, znear, zfar, matrix, true, halfZRange, projectionPlaneTilt, reverseDepthBufferMode);\n return matrix;\n }\n /**\n * Stores a left-handed perspective projection into a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#81\n * @param fov defines the horizontal field of view\n * @param aspect defines the aspect ratio\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\n * @param result defines the target matrix\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\n * @returns result input\n */\n static PerspectiveFovLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {\n const n = znear;\n const f = zfar;\n const t = 1.0 / Math.tan(fov * 0.5);\n const a = isVerticalFovFixed ? t / aspect : t;\n const b = isVerticalFovFixed ? t : t * aspect;\n const c = reverseDepthBufferMode && n === 0 ? -1 : f !== 0 ? (f + n) / (f - n) : 1;\n const d = reverseDepthBufferMode && n === 0 ? 2 * f : f !== 0 ? (-2.0 * f * n) / (f - n) : -2 * n;\n const rot = Math.tan(projectionPlaneTilt);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, c, 1.0, 0.0, 0.0, d, 0.0, result);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result._updateIdentityStatus(false);\n return result;\n }\n /**\n * Stores a left-handed perspective projection into a given matrix with depth reversed\n * Example Playground - https://playground.babylonjs.com/#AV9X17#89\n * @param fov defines the horizontal field of view\n * @param aspect defines the aspect ratio\n * @param znear defines the near clip plane\n * @param zfar not used as infinity is used as far clip\n * @param result defines the target matrix\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @returns result input\n */\n static PerspectiveFovReverseLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0) {\n const t = 1.0 / Math.tan(fov * 0.5);\n const a = isVerticalFovFixed ? t / aspect : t;\n const b = isVerticalFovFixed ? t : t * aspect;\n const rot = Math.tan(projectionPlaneTilt);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, -znear, 1.0, 0.0, 0.0, 1.0, 0.0, result);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result._updateIdentityStatus(false);\n return result;\n }\n /**\n * Creates a right-handed perspective projection matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#83\n * @param fov defines the horizontal field of view\n * @param aspect defines the aspect ratio\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\n * @returns a new matrix as a right-handed perspective projection matrix\n */\n static PerspectiveFovRH(fov, aspect, znear, zfar, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {\n const matrix = new Matrix();\n Matrix.PerspectiveFovRHToRef(fov, aspect, znear, zfar, matrix, true, halfZRange, projectionPlaneTilt, reverseDepthBufferMode);\n return matrix;\n }\n /**\n * Stores a right-handed perspective projection into a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#84\n * @param fov defines the horizontal field of view\n * @param aspect defines the aspect ratio\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\n * @param result defines the target matrix\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\n * @returns result input\n */\n static PerspectiveFovRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {\n //alternatively this could be expressed as:\n // m = PerspectiveFovLHToRef\n // m[10] *= -1.0;\n // m[11] *= -1.0;\n const n = znear;\n const f = zfar;\n const t = 1.0 / Math.tan(fov * 0.5);\n const a = isVerticalFovFixed ? t / aspect : t;\n const b = isVerticalFovFixed ? t : t * aspect;\n const c = reverseDepthBufferMode && n === 0 ? 1 : f !== 0 ? -(f + n) / (f - n) : -1;\n const d = reverseDepthBufferMode && n === 0 ? 2 * f : f !== 0 ? (-2 * f * n) / (f - n) : -2 * n;\n const rot = Math.tan(projectionPlaneTilt);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, c, -1.0, 0.0, 0.0, d, 0.0, result);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result._updateIdentityStatus(false);\n return result;\n }\n /**\n * Stores a right-handed perspective projection into a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#90\n * @param fov defines the horizontal field of view\n * @param aspect defines the aspect ratio\n * @param znear defines the near clip plane\n * @param zfar not used as infinity is used as far clip\n * @param result defines the target matrix\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @returns result input\n */\n static PerspectiveFovReverseRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0) {\n const t = 1.0 / Math.tan(fov * 0.5);\n const a = isVerticalFovFixed ? t / aspect : t;\n const b = isVerticalFovFixed ? t : t * aspect;\n const rot = Math.tan(projectionPlaneTilt);\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, -znear, -1.0, 0.0, 0.0, -1.0, 0.0, result);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result._updateIdentityStatus(false);\n return result;\n }\n /**\n * Stores a perspective projection for WebVR info a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#92\n * @param fov defines the field of view\n * @param fov.upDegrees\n * @param fov.downDegrees\n * @param fov.leftDegrees\n * @param fov.rightDegrees\n * @param znear defines the near clip plane\n * @param zfar defines the far clip plane\n * @param result defines the target matrix\n * @param rightHanded defines if the matrix must be in right-handed mode (false by default)\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\n * @returns result input\n */\n static PerspectiveFovWebVRToRef(fov, znear, zfar, result, rightHanded = false, halfZRange, projectionPlaneTilt = 0) {\n const rightHandedFactor = rightHanded ? -1 : 1;\n const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);\n const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);\n const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);\n const rightTan = Math.tan((fov.rightDegrees * Math.PI) / 180.0);\n const xScale = 2.0 / (leftTan + rightTan);\n const yScale = 2.0 / (upTan + downTan);\n const rot = Math.tan(projectionPlaneTilt);\n const m = result._m;\n m[0] = xScale;\n m[1] = m[2] = m[3] = m[4] = 0.0;\n m[5] = yScale;\n m[6] = 0.0;\n m[7] = rot;\n m[8] = (leftTan - rightTan) * xScale * 0.5;\n m[9] = -((upTan - downTan) * yScale * 0.5);\n m[10] = -zfar / (znear - zfar);\n m[11] = 1.0 * rightHandedFactor;\n m[12] = m[13] = m[15] = 0.0;\n m[14] = -(2.0 * zfar * znear) / (zfar - znear);\n if (halfZRange) {\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\n }\n result.markAsUpdated();\n return result;\n }\n /**\n * Computes a complete transformation matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#113\n * @param viewport defines the viewport to use\n * @param world defines the world matrix\n * @param view defines the view matrix\n * @param projection defines the projection matrix\n * @param zmin defines the near clip plane\n * @param zmax defines the far clip plane\n * @returns the transformation matrix\n */\n static GetFinalMatrix(viewport, world, view, projection, zmin, zmax) {\n const cw = viewport.width;\n const ch = viewport.height;\n const cx = viewport.x;\n const cy = viewport.y;\n const viewportMatrix = Matrix.FromValues(cw / 2.0, 0.0, 0.0, 0.0, 0.0, -ch / 2.0, 0.0, 0.0, 0.0, 0.0, zmax - zmin, 0.0, cx + cw / 2.0, ch / 2.0 + cy, zmin, 1.0);\n const matrix = new world.constructor();\n world.multiplyToRef(view, matrix);\n matrix.multiplyToRef(projection, matrix);\n return matrix.multiplyToRef(viewportMatrix, matrix);\n }\n /**\n * Extracts a 2x2 matrix from a given matrix and store the result in a Float32Array\n * @param matrix defines the matrix to use\n * @returns a new Float32Array array with 4 elements : the 2x2 matrix extracted from the given matrix\n */\n static GetAsMatrix2x2(matrix) {\n const m = matrix.m;\n const arr = [m[0], m[1], m[4], m[5]];\n return PerformanceConfigurator.MatrixUse64Bits ? arr : new Float32Array(arr);\n }\n /**\n * Extracts a 3x3 matrix from a given matrix and store the result in a Float32Array\n * @param matrix defines the matrix to use\n * @returns a new Float32Array array with 9 elements : the 3x3 matrix extracted from the given matrix\n */\n static GetAsMatrix3x3(matrix) {\n const m = matrix.m;\n const arr = [m[0], m[1], m[2], m[4], m[5], m[6], m[8], m[9], m[10]];\n return PerformanceConfigurator.MatrixUse64Bits ? arr : new Float32Array(arr);\n }\n /**\n * Compute the transpose of a given matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#111\n * @param matrix defines the matrix to transpose\n * @returns the new matrix\n */\n static Transpose(matrix) {\n const result = new matrix.constructor();\n Matrix.TransposeToRef(matrix, result);\n return result;\n }\n /**\n * Compute the transpose of a matrix and store it in a target matrix\n * Example Playground - https://playground.babylonjs.com/#AV9X17#112\n * @param matrix defines the matrix to transpose\n * @param result defines the target matrix\n * @returns result input\n */\n static TransposeToRef(matrix, result) {\n const rm = result._m;\n const mm = matrix.m;\n rm[0] = mm[0];\n rm[1] = mm[4];\n rm[2] = mm[8];\n rm[3] = mm[12];\n rm[4] = mm[1];\n rm[5] = mm[5];\n rm[6] = mm[9];\n rm[7] = mm[13];\n rm[8] = mm[2];\n rm[9] = mm[6];\n rm[10] = mm[10];\n rm[11] = mm[14];\n rm[12] = mm[3];\n rm[13] = mm[7];\n rm[14] = mm[11];\n rm[15] = mm[15];\n result.markAsUpdated();\n // identity-ness does not change when transposing\n result._updateIdentityStatus(matrix._isIdentity, matrix._isIdentityDirty);\n return result;\n }\n /**\n * Computes a reflection matrix from a plane\n * Example Playground - https://playground.babylonjs.com/#AV9X17#87\n * @param plane defines the reflection plane\n * @returns a new matrix\n */\n static Reflection(plane) {\n const matrix = new Matrix();\n Matrix.ReflectionToRef(plane, matrix);\n return matrix;\n }\n /**\n * Computes a reflection matrix from a plane\n * Example Playground - https://playground.babylonjs.com/#AV9X17#88\n * @param plane defines the reflection plane\n * @param result defines the target matrix\n * @returns result input\n */\n static ReflectionToRef(plane, result) {\n plane.normalize();\n const x = plane.normal.x;\n const y = plane.normal.y;\n const z = plane.normal.z;\n const temp = -2 * x;\n const temp2 = -2 * y;\n const temp3 = -2 * z;\n Matrix.FromValuesToRef(temp * x + 1, temp2 * x, temp3 * x, 0.0, temp * y, temp2 * y + 1, temp3 * y, 0.0, temp * z, temp2 * z, temp3 * z + 1, 0.0, temp * plane.d, temp2 * plane.d, temp3 * plane.d, 1.0, result);\n return result;\n }\n /**\n * Sets the given matrix as a rotation matrix composed from the 3 left handed axes\n * @param xaxis defines the value of the 1st axis\n * @param yaxis defines the value of the 2nd axis\n * @param zaxis defines the value of the 3rd axis\n * @param result defines the target matrix\n * @returns result input\n */\n static FromXYZAxesToRef(xaxis, yaxis, zaxis, result) {\n Matrix.FromValuesToRef(xaxis._x, xaxis._y, xaxis._z, 0.0, yaxis._x, yaxis._y, yaxis._z, 0.0, zaxis._x, zaxis._y, zaxis._z, 0.0, 0.0, 0.0, 0.0, 1.0, result);\n return result;\n }\n /**\n * Creates a rotation matrix from a quaternion and stores it in a target matrix\n * @param quat defines the quaternion to use\n * @param result defines the target matrix\n * @returns result input\n */\n static FromQuaternionToRef(quat, result) {\n const xx = quat._x * quat._x;\n const yy = quat._y * quat._y;\n const zz = quat._z * quat._z;\n const xy = quat._x * quat._y;\n const zw = quat._z * quat._w;\n const zx = quat._z * quat._x;\n const yw = quat._y * quat._w;\n const yz = quat._y * quat._z;\n const xw = quat._x * quat._w;\n result._m[0] = 1.0 - 2.0 * (yy + zz);\n result._m[1] = 2.0 * (xy + zw);\n result._m[2] = 2.0 * (zx - yw);\n result._m[3] = 0.0;\n result._m[4] = 2.0 * (xy - zw);\n result._m[5] = 1.0 - 2.0 * (zz + xx);\n result._m[6] = 2.0 * (yz + xw);\n result._m[7] = 0.0;\n result._m[8] = 2.0 * (zx + yw);\n result._m[9] = 2.0 * (yz - xw);\n result._m[10] = 1.0 - 2.0 * (yy + xx);\n result._m[11] = 0.0;\n result._m[12] = 0.0;\n result._m[13] = 0.0;\n result._m[14] = 0.0;\n result._m[15] = 1.0;\n result.markAsUpdated();\n return result;\n }\n }\n Matrix._UpdateFlagSeed = 0;\n Matrix._IdentityReadOnly = Matrix.Identity();\n /**\n * @internal\n * Same as Tmp but not exported to keep it only for math functions to avoid conflicts\n */\n class MathTmp {\n }\n MathTmp.Vector3 = ArrayTools.BuildTuple(11, Vector3.Zero);\n MathTmp.Matrix = ArrayTools.BuildTuple(2, Matrix.Identity);\n MathTmp.Quaternion = ArrayTools.BuildTuple(3, Quaternion.Zero);\n /**\n * @internal\n */\n class TmpVectors {\n }\n TmpVectors.Vector2 = ArrayTools.BuildTuple(3, Vector2.Zero); // 3 temp Vector2 at once should be enough\n TmpVectors.Vector3 = ArrayTools.BuildTuple(13, Vector3.Zero); // 13 temp Vector3 at once should be enough\n TmpVectors.Vector4 = ArrayTools.BuildTuple(3, Vector4.Zero); // 3 temp Vector4 at once should be enough\n TmpVectors.Quaternion = ArrayTools.BuildTuple(2, Quaternion.Zero); // 2 temp Quaternion at once should be enough\n TmpVectors.Matrix = ArrayTools.BuildTuple(8, Matrix.Identity); // 8 temp Matrices at once should be enough\n RegisterClass(\"BABYLON.Vector2\", Vector2);\n RegisterClass(\"BABYLON.Vector3\", Vector3);\n RegisterClass(\"BABYLON.Vector4\", Vector4);\n RegisterClass(\"BABYLON.Matrix\", Matrix);\n const mtxConvertNDCToHalfZRange = Matrix.FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1);\n\n /**\n * @internal\n */\n function _WarnImport(name) {\n return `${name} needs to be imported before as it contains a side-effect required by your code.`;\n }\n\n function colorChannelToLinearSpace(color) {\n return Math.pow(color, ToLinearSpace);\n }\n function colorChannelToLinearSpaceExact(color) {\n if (color <= 0.04045) {\n return 0.0773993808 * color;\n }\n return Math.pow(0.947867299 * (color + 0.055), 2.4);\n }\n function colorChannelToGammaSpace(color) {\n return Math.pow(color, ToGammaSpace);\n }\n function colorChannelToGammaSpaceExact(color) {\n if (color <= 0.0031308) {\n return 12.92 * color;\n }\n return 1.055 * Math.pow(color, 0.41666) - 0.055;\n }\n /**\n * Class used to hold a RGB color\n */\n class Color3 {\n /**\n * Creates a new Color3 object from red, green, blue values, all between 0 and 1\n * @param r defines the red component (between 0 and 1, default is 0)\n * @param g defines the green component (between 0 and 1, default is 0)\n * @param b defines the blue component (between 0 and 1, default is 0)\n */\n constructor(\n /**\n * Defines the red component (between 0 and 1, default is 0)\n */\n r = 0, \n /**\n * Defines the green component (between 0 and 1, default is 0)\n */\n g = 0, \n /**\n * Defines the blue component (between 0 and 1, default is 0)\n */\n b = 0) {\n this.r = r;\n this.g = g;\n this.b = b;\n }\n /**\n * Creates a string with the Color3 current values\n * @returns the string representation of the Color3 object\n */\n toString() {\n return \"{R: \" + this.r + \" G:\" + this.g + \" B:\" + this.b + \"}\";\n }\n /**\n * Returns the string \"Color3\"\n * @returns \"Color3\"\n */\n getClassName() {\n return \"Color3\";\n }\n /**\n * Compute the Color3 hash code\n * @returns an unique number that can be used to hash Color3 objects\n */\n getHashCode() {\n let hash = (this.r * 255) | 0;\n hash = (hash * 397) ^ ((this.g * 255) | 0);\n hash = (hash * 397) ^ ((this.b * 255) | 0);\n return hash;\n }\n // Operators\n /**\n * Stores in the given array from the given starting index the red, green, blue values as successive elements\n * @param array defines the array where to store the r,g,b components\n * @param index defines an optional index in the target array to define where to start storing values\n * @returns the current Color3 object\n */\n toArray(array, index = 0) {\n array[index] = this.r;\n array[index + 1] = this.g;\n array[index + 2] = this.b;\n return this;\n }\n /**\n * Update the current color with values stored in an array from the starting index of the given array\n * @param array defines the source array\n * @param offset defines an offset in the source array\n * @returns the current Color3 object\n */\n fromArray(array, offset = 0) {\n Color3.FromArrayToRef(array, offset, this);\n return this;\n }\n /**\n * Returns a new Color4 object from the current Color3 and the given alpha\n * @param alpha defines the alpha component on the new Color4 object (default is 1)\n * @returns a new Color4 object\n */\n toColor4(alpha = 1) {\n return new Color4(this.r, this.g, this.b, alpha);\n }\n /**\n * Returns a new array populated with 3 numeric elements : red, green and blue values\n * @returns the new array\n */\n asArray() {\n return [this.r, this.g, this.b];\n }\n /**\n * Returns the luminance value\n * @returns a float value\n */\n toLuminance() {\n return this.r * 0.3 + this.g * 0.59 + this.b * 0.11;\n }\n /**\n * Multiply each Color3 rgb values by the given Color3 rgb values in a new Color3 object\n * @param otherColor defines the second operand\n * @returns the new Color3 object\n */\n multiply(otherColor) {\n return new Color3(this.r * otherColor.r, this.g * otherColor.g, this.b * otherColor.b);\n }\n /**\n * Multiply the rgb values of the Color3 and the given Color3 and stores the result in the object \"result\"\n * @param otherColor defines the second operand\n * @param result defines the Color3 object where to store the result\n * @returns the current Color3\n */\n multiplyToRef(otherColor, result) {\n result.r = this.r * otherColor.r;\n result.g = this.g * otherColor.g;\n result.b = this.b * otherColor.b;\n return this;\n }\n /**\n * Determines equality between Color3 objects\n * @param otherColor defines the second operand\n * @returns true if the rgb values are equal to the given ones\n */\n equals(otherColor) {\n return otherColor && this.r === otherColor.r && this.g === otherColor.g && this.b === otherColor.b;\n }\n /**\n * Determines equality between the current Color3 object and a set of r,b,g values\n * @param r defines the red component to check\n * @param g defines the green component to check\n * @param b defines the blue component to check\n * @returns true if the rgb values are equal to the given ones\n */\n equalsFloats(r, g, b) {\n return this.r === r && this.g === g && this.b === b;\n }\n /**\n * Creates a new Color3 with the current Color3 values multiplied by scale\n * @param scale defines the scaling factor to apply\n * @returns a new Color3 object\n */\n scale(scale) {\n return new Color3(this.r * scale, this.g * scale, this.b * scale);\n }\n /**\n * Multiplies the Color3 values by the float \"scale\"\n * @param scale defines the scaling factor to apply\n * @returns the current updated Color3\n */\n scaleInPlace(scale) {\n this.r *= scale;\n this.g *= scale;\n this.b *= scale;\n return this;\n }\n /**\n * Multiplies the rgb values by scale and stores the result into \"result\"\n * @param scale defines the scaling factor\n * @param result defines the Color3 object where to store the result\n * @returns the unmodified current Color3\n */\n scaleToRef(scale, result) {\n result.r = this.r * scale;\n result.g = this.g * scale;\n result.b = this.b * scale;\n return this;\n }\n /**\n * Scale the current Color3 values by a factor and add the result to a given Color3\n * @param scale defines the scale factor\n * @param result defines color to store the result into\n * @returns the unmodified current Color3\n */\n scaleAndAddToRef(scale, result) {\n result.r += this.r * scale;\n result.g += this.g * scale;\n result.b += this.b * scale;\n return this;\n }\n /**\n * Clamps the rgb values by the min and max values and stores the result into \"result\"\n * @param min defines minimum clamping value (default is 0)\n * @param max defines maximum clamping value (default is 1)\n * @param result defines color to store the result into\n * @returns the original Color3\n */\n clampToRef(min = 0, max = 1, result) {\n result.r = Scalar.Clamp(this.r, min, max);\n result.g = Scalar.Clamp(this.g, min, max);\n result.b = Scalar.Clamp(this.b, min, max);\n return this;\n }\n /**\n * Creates a new Color3 set with the added values of the current Color3 and of the given one\n * @param otherColor defines the second operand\n * @returns the new Color3\n */\n add(otherColor) {\n return new Color3(this.r + otherColor.r, this.g + otherColor.g, this.b + otherColor.b);\n }\n /**\n * Stores the result of the addition of the current Color3 and given one rgb values into \"result\"\n * @param otherColor defines the second operand\n * @param result defines Color3 object to store the result into\n * @returns the unmodified current Color3\n */\n addToRef(otherColor, result) {\n result.r = this.r + otherColor.r;\n result.g = this.g + otherColor.g;\n result.b = this.b + otherColor.b;\n return this;\n }\n /**\n * Returns a new Color3 set with the subtracted values of the given one from the current Color3\n * @param otherColor defines the second operand\n * @returns the new Color3\n */\n subtract(otherColor) {\n return new Color3(this.r - otherColor.r, this.g - otherColor.g, this.b - otherColor.b);\n }\n /**\n * Stores the result of the subtraction of given one from the current Color3 rgb values into \"result\"\n * @param otherColor defines the second operand\n * @param result defines Color3 object to store the result into\n * @returns the unmodified current Color3\n */\n subtractToRef(otherColor, result) {\n result.r = this.r - otherColor.r;\n result.g = this.g - otherColor.g;\n result.b = this.b - otherColor.b;\n return this;\n }\n /**\n * Copy the current object\n * @returns a new Color3 copied the current one\n */\n clone() {\n return new Color3(this.r, this.g, this.b);\n }\n /**\n * Copies the rgb values from the source in the current Color3\n * @param source defines the source Color3 object\n * @returns the updated Color3 object\n */\n copyFrom(source) {\n this.r = source.r;\n this.g = source.g;\n this.b = source.b;\n return this;\n }\n /**\n * Updates the Color3 rgb values from the given floats\n * @param r defines the red component to read from\n * @param g defines the green component to read from\n * @param b defines the blue component to read from\n * @returns the current Color3 object\n */\n copyFromFloats(r, g, b) {\n this.r = r;\n this.g = g;\n this.b = b;\n return this;\n }\n /**\n * Updates the Color3 rgb values from the given floats\n * @param r defines the red component to read from\n * @param g defines the green component to read from\n * @param b defines the blue component to read from\n * @returns the current Color3 object\n */\n set(r, g, b) {\n return this.copyFromFloats(r, g, b);\n }\n /**\n * Compute the Color3 hexadecimal code as a string\n * @returns a string containing the hexadecimal representation of the Color3 object\n */\n toHexString() {\n const intR = Math.round(this.r * 255);\n const intG = Math.round(this.g * 255);\n const intB = Math.round(this.b * 255);\n return \"#\" + Scalar.ToHex(intR) + Scalar.ToHex(intG) + Scalar.ToHex(intB);\n }\n /**\n * Converts current color in rgb space to HSV values\n * @returns a new color3 representing the HSV values\n */\n toHSV() {\n const result = new Color3();\n this.toHSVToRef(result);\n return result;\n }\n /**\n * Converts current color in rgb space to HSV values\n * @param result defines the Color3 where to store the HSV values\n */\n toHSVToRef(result) {\n const r = this.r;\n const g = this.g;\n const b = this.b;\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n let h = 0;\n let s = 0;\n const v = max;\n const dm = max - min;\n if (max !== 0) {\n s = dm / max;\n }\n if (max != min) {\n if (max == r) {\n h = (g - b) / dm;\n if (g < b) {\n h += 6;\n }\n }\n else if (max == g) {\n h = (b - r) / dm + 2;\n }\n else if (max == b) {\n h = (r - g) / dm + 4;\n }\n h *= 60;\n }\n result.r = h;\n result.g = s;\n result.b = v;\n }\n /**\n * Computes a new Color3 converted from the current one to linear space\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns a new Color3 object\n */\n toLinearSpace(exact = false) {\n const convertedColor = new Color3();\n this.toLinearSpaceToRef(convertedColor, exact);\n return convertedColor;\n }\n /**\n * Converts the Color3 values to linear space and stores the result in \"convertedColor\"\n * @param convertedColor defines the Color3 object where to store the linear space version\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns the unmodified Color3\n */\n toLinearSpaceToRef(convertedColor, exact = false) {\n if (exact) {\n convertedColor.r = colorChannelToLinearSpaceExact(this.r);\n convertedColor.g = colorChannelToLinearSpaceExact(this.g);\n convertedColor.b = colorChannelToLinearSpaceExact(this.b);\n }\n else {\n convertedColor.r = colorChannelToLinearSpace(this.r);\n convertedColor.g = colorChannelToLinearSpace(this.g);\n convertedColor.b = colorChannelToLinearSpace(this.b);\n }\n return this;\n }\n /**\n * Computes a new Color3 converted from the current one to gamma space\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns a new Color3 object\n */\n toGammaSpace(exact = false) {\n const convertedColor = new Color3();\n this.toGammaSpaceToRef(convertedColor, exact);\n return convertedColor;\n }\n /**\n * Converts the Color3 values to gamma space and stores the result in \"convertedColor\"\n * @param convertedColor defines the Color3 object where to store the gamma space version\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns the unmodified Color3\n */\n toGammaSpaceToRef(convertedColor, exact = false) {\n if (exact) {\n convertedColor.r = colorChannelToGammaSpaceExact(this.r);\n convertedColor.g = colorChannelToGammaSpaceExact(this.g);\n convertedColor.b = colorChannelToGammaSpaceExact(this.b);\n }\n else {\n convertedColor.r = colorChannelToGammaSpace(this.r);\n convertedColor.g = colorChannelToGammaSpace(this.g);\n convertedColor.b = colorChannelToGammaSpace(this.b);\n }\n return this;\n }\n /**\n * Converts Hue, saturation and value to a Color3 (RGB)\n * @param hue defines the hue (value between 0 and 360)\n * @param saturation defines the saturation (value between 0 and 1)\n * @param value defines the value (value between 0 and 1)\n * @param result defines the Color3 where to store the RGB values\n */\n static HSVtoRGBToRef(hue, saturation, value, result) {\n const chroma = value * saturation;\n const h = hue / 60;\n const x = chroma * (1 - Math.abs((h % 2) - 1));\n let r = 0;\n let g = 0;\n let b = 0;\n if (h >= 0 && h <= 1) {\n r = chroma;\n g = x;\n }\n else if (h >= 1 && h <= 2) {\n r = x;\n g = chroma;\n }\n else if (h >= 2 && h <= 3) {\n g = chroma;\n b = x;\n }\n else if (h >= 3 && h <= 4) {\n g = x;\n b = chroma;\n }\n else if (h >= 4 && h <= 5) {\n r = x;\n b = chroma;\n }\n else if (h >= 5 && h <= 6) {\n r = chroma;\n b = x;\n }\n const m = value - chroma;\n result.set(r + m, g + m, b + m);\n }\n /**\n * Converts Hue, saturation and value to a new Color3 (RGB)\n * @param hue defines the hue (value between 0 and 360)\n * @param saturation defines the saturation (value between 0 and 1)\n * @param value defines the value (value between 0 and 1)\n * @returns a new Color3 object\n */\n static FromHSV(hue, saturation, value) {\n const result = new Color3(0, 0, 0);\n Color3.HSVtoRGBToRef(hue, saturation, value, result);\n return result;\n }\n /**\n * Creates a new Color3 from the string containing valid hexadecimal values\n * @param hex defines a string containing valid hexadecimal values\n * @returns a new Color3 object\n */\n static FromHexString(hex) {\n if (hex.substring(0, 1) !== \"#\" || hex.length !== 7) {\n return new Color3(0, 0, 0);\n }\n const r = parseInt(hex.substring(1, 3), 16);\n const g = parseInt(hex.substring(3, 5), 16);\n const b = parseInt(hex.substring(5, 7), 16);\n return Color3.FromInts(r, g, b);\n }\n /**\n * Creates a new Color3 from the starting index of the given array\n * @param array defines the source array\n * @param offset defines an offset in the source array\n * @returns a new Color3 object\n */\n static FromArray(array, offset = 0) {\n return new Color3(array[offset], array[offset + 1], array[offset + 2]);\n }\n /**\n * Creates a new Color3 from the starting index element of the given array\n * @param array defines the source array to read from\n * @param offset defines the offset in the source array\n * @param result defines the target Color3 object\n */\n static FromArrayToRef(array, offset = 0, result) {\n result.r = array[offset];\n result.g = array[offset + 1];\n result.b = array[offset + 2];\n }\n /**\n * Creates a new Color3 from integer values (< 256)\n * @param r defines the red component to read from (value between 0 and 255)\n * @param g defines the green component to read from (value between 0 and 255)\n * @param b defines the blue component to read from (value between 0 and 255)\n * @returns a new Color3 object\n */\n static FromInts(r, g, b) {\n return new Color3(r / 255.0, g / 255.0, b / 255.0);\n }\n /**\n * Creates a new Color3 with values linearly interpolated of \"amount\" between the start Color3 and the end Color3\n * @param start defines the start Color3 value\n * @param end defines the end Color3 value\n * @param amount defines the gradient value between start and end\n * @returns a new Color3 object\n */\n static Lerp(start, end, amount) {\n const result = new Color3(0.0, 0.0, 0.0);\n Color3.LerpToRef(start, end, amount, result);\n return result;\n }\n /**\n * Creates a new Color3 with values linearly interpolated of \"amount\" between the start Color3 and the end Color3\n * @param left defines the start value\n * @param right defines the end value\n * @param amount defines the gradient factor\n * @param result defines the Color3 object where to store the result\n */\n static LerpToRef(left, right, amount, result) {\n result.r = left.r + (right.r - left.r) * amount;\n result.g = left.g + (right.g - left.g) * amount;\n result.b = left.b + (right.b - left.b) * amount;\n }\n /**\n * Returns a new Color3 located for \"amount\" (float) on the Hermite interpolation spline defined by the vectors \"value1\", \"tangent1\", \"value2\", \"tangent2\"\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent Color3\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent Color3\n * @param amount defines the amount on the interpolation spline (between 0 and 1)\n * @returns the new Color3\n */\n static Hermite(value1, tangent1, value2, tangent2, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\n const part2 = -2.0 * cubed + 3.0 * squared;\n const part3 = cubed - 2.0 * squared + amount;\n const part4 = cubed - squared;\n const r = value1.r * part1 + value2.r * part2 + tangent1.r * part3 + tangent2.r * part4;\n const g = value1.g * part1 + value2.g * part2 + tangent1.g * part3 + tangent2.g * part4;\n const b = value1.b * part1 + value2.b * part2 + tangent1.b * part3 + tangent2.b * part4;\n return new Color3(r, g, b);\n }\n /**\n * Returns a new Color3 which is the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @returns 1st derivative\n */\n static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {\n const result = Color3.Black();\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\n return result;\n }\n /**\n * Returns a new Color3 which is the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @param result define where to store the derivative\n */\n static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {\n const t2 = time * time;\n result.r = (t2 - time) * 6 * value1.r + (3 * t2 - 4 * time + 1) * tangent1.r + (-t2 + time) * 6 * value2.r + (3 * t2 - 2 * time) * tangent2.r;\n result.g = (t2 - time) * 6 * value1.g + (3 * t2 - 4 * time + 1) * tangent1.g + (-t2 + time) * 6 * value2.g + (3 * t2 - 2 * time) * tangent2.g;\n result.b = (t2 - time) * 6 * value1.b + (3 * t2 - 4 * time + 1) * tangent1.b + (-t2 + time) * 6 * value2.b + (3 * t2 - 2 * time) * tangent2.b;\n }\n /**\n * Returns a Color3 value containing a red color\n * @returns a new Color3 object\n */\n static Red() {\n return new Color3(1, 0, 0);\n }\n /**\n * Returns a Color3 value containing a green color\n * @returns a new Color3 object\n */\n static Green() {\n return new Color3(0, 1, 0);\n }\n /**\n * Returns a Color3 value containing a blue color\n * @returns a new Color3 object\n */\n static Blue() {\n return new Color3(0, 0, 1);\n }\n /**\n * Returns a Color3 value containing a black color\n * @returns a new Color3 object\n */\n static Black() {\n return new Color3(0, 0, 0);\n }\n /**\n * Gets a Color3 value containing a black color that must not be updated\n */\n static get BlackReadOnly() {\n return Color3._BlackReadOnly;\n }\n /**\n * Returns a Color3 value containing a white color\n * @returns a new Color3 object\n */\n static White() {\n return new Color3(1, 1, 1);\n }\n /**\n * Returns a Color3 value containing a purple color\n * @returns a new Color3 object\n */\n static Purple() {\n return new Color3(0.5, 0, 0.5);\n }\n /**\n * Returns a Color3 value containing a magenta color\n * @returns a new Color3 object\n */\n static Magenta() {\n return new Color3(1, 0, 1);\n }\n /**\n * Returns a Color3 value containing a yellow color\n * @returns a new Color3 object\n */\n static Yellow() {\n return new Color3(1, 1, 0);\n }\n /**\n * Returns a Color3 value containing a gray color\n * @returns a new Color3 object\n */\n static Gray() {\n return new Color3(0.5, 0.5, 0.5);\n }\n /**\n * Returns a Color3 value containing a teal color\n * @returns a new Color3 object\n */\n static Teal() {\n return new Color3(0, 1.0, 1.0);\n }\n /**\n * Returns a Color3 value containing a random color\n * @returns a new Color3 object\n */\n static Random() {\n return new Color3(Math.random(), Math.random(), Math.random());\n }\n }\n // Statics\n Color3._BlackReadOnly = Color3.Black();\n /**\n * Class used to hold a RBGA color\n */\n class Color4 {\n /**\n * Creates a new Color4 object from red, green, blue values, all between 0 and 1\n * @param r defines the red component (between 0 and 1, default is 0)\n * @param g defines the green component (between 0 and 1, default is 0)\n * @param b defines the blue component (between 0 and 1, default is 0)\n * @param a defines the alpha component (between 0 and 1, default is 1)\n */\n constructor(\n /**\n * Defines the red component (between 0 and 1, default is 0)\n */\n r = 0, \n /**\n * Defines the green component (between 0 and 1, default is 0)\n */\n g = 0, \n /**\n * Defines the blue component (between 0 and 1, default is 0)\n */\n b = 0, \n /**\n * Defines the alpha component (between 0 and 1, default is 1)\n */\n a = 1) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n }\n // Operators\n /**\n * Adds in place the given Color4 values to the current Color4 object\n * @param right defines the second operand\n * @returns the current updated Color4 object\n */\n addInPlace(right) {\n this.r += right.r;\n this.g += right.g;\n this.b += right.b;\n this.a += right.a;\n return this;\n }\n /**\n * Creates a new array populated with 4 numeric elements : red, green, blue, alpha values\n * @returns the new array\n */\n asArray() {\n return [this.r, this.g, this.b, this.a];\n }\n /**\n * Stores from the starting index in the given array the Color4 successive values\n * @param array defines the array where to store the r,g,b components\n * @param index defines an optional index in the target array to define where to start storing values\n * @returns the current Color4 object\n */\n toArray(array, index = 0) {\n array[index] = this.r;\n array[index + 1] = this.g;\n array[index + 2] = this.b;\n array[index + 3] = this.a;\n return this;\n }\n /**\n * Update the current color with values stored in an array from the starting index of the given array\n * @param array defines the source array\n * @param offset defines an offset in the source array\n * @returns the current Color4 object\n */\n fromArray(array, offset = 0) {\n Color4.FromArrayToRef(array, offset, this);\n return this;\n }\n /**\n * Determines equality between Color4 objects\n * @param otherColor defines the second operand\n * @returns true if the rgba values are equal to the given ones\n */\n equals(otherColor) {\n return otherColor && this.r === otherColor.r && this.g === otherColor.g && this.b === otherColor.b && this.a === otherColor.a;\n }\n /**\n * Creates a new Color4 set with the added values of the current Color4 and of the given one\n * @param right defines the second operand\n * @returns a new Color4 object\n */\n add(right) {\n return new Color4(this.r + right.r, this.g + right.g, this.b + right.b, this.a + right.a);\n }\n /**\n * Creates a new Color4 set with the subtracted values of the given one from the current Color4\n * @param right defines the second operand\n * @returns a new Color4 object\n */\n subtract(right) {\n return new Color4(this.r - right.r, this.g - right.g, this.b - right.b, this.a - right.a);\n }\n /**\n * Subtracts the given ones from the current Color4 values and stores the results in \"result\"\n * @param right defines the second operand\n * @param result defines the Color4 object where to store the result\n * @returns the current Color4 object\n */\n subtractToRef(right, result) {\n result.r = this.r - right.r;\n result.g = this.g - right.g;\n result.b = this.b - right.b;\n result.a = this.a - right.a;\n return this;\n }\n /**\n * Creates a new Color4 with the current Color4 values multiplied by scale\n * @param scale defines the scaling factor to apply\n * @returns a new Color4 object\n */\n scale(scale) {\n return new Color4(this.r * scale, this.g * scale, this.b * scale, this.a * scale);\n }\n /**\n * Multiplies the Color4 values by the float \"scale\"\n * @param scale defines the scaling factor to apply\n * @returns the current updated Color4\n */\n scaleInPlace(scale) {\n this.r *= scale;\n this.g *= scale;\n this.b *= scale;\n this.a *= scale;\n return this;\n }\n /**\n * Multiplies the current Color4 values by scale and stores the result in \"result\"\n * @param scale defines the scaling factor to apply\n * @param result defines the Color4 object where to store the result\n * @returns the current unmodified Color4\n */\n scaleToRef(scale, result) {\n result.r = this.r * scale;\n result.g = this.g * scale;\n result.b = this.b * scale;\n result.a = this.a * scale;\n return this;\n }\n /**\n * Scale the current Color4 values by a factor and add the result to a given Color4\n * @param scale defines the scale factor\n * @param result defines the Color4 object where to store the result\n * @returns the unmodified current Color4\n */\n scaleAndAddToRef(scale, result) {\n result.r += this.r * scale;\n result.g += this.g * scale;\n result.b += this.b * scale;\n result.a += this.a * scale;\n return this;\n }\n /**\n * Clamps the rgb values by the min and max values and stores the result into \"result\"\n * @param min defines minimum clamping value (default is 0)\n * @param max defines maximum clamping value (default is 1)\n * @param result defines color to store the result into.\n * @returns the current Color4\n */\n clampToRef(min = 0, max = 1, result) {\n result.r = Scalar.Clamp(this.r, min, max);\n result.g = Scalar.Clamp(this.g, min, max);\n result.b = Scalar.Clamp(this.b, min, max);\n result.a = Scalar.Clamp(this.a, min, max);\n return this;\n }\n /**\n * Multiply an Color4 value by another and return a new Color4 object\n * @param color defines the Color4 value to multiply by\n * @returns a new Color4 object\n */\n multiply(color) {\n return new Color4(this.r * color.r, this.g * color.g, this.b * color.b, this.a * color.a);\n }\n /**\n * Multiply a Color4 value by another and push the result in a reference value\n * @param color defines the Color4 value to multiply by\n * @param result defines the Color4 to fill the result in\n * @returns the result Color4\n */\n multiplyToRef(color, result) {\n result.r = this.r * color.r;\n result.g = this.g * color.g;\n result.b = this.b * color.b;\n result.a = this.a * color.a;\n return result;\n }\n /**\n * Creates a string with the Color4 current values\n * @returns the string representation of the Color4 object\n */\n toString() {\n return \"{R: \" + this.r + \" G:\" + this.g + \" B:\" + this.b + \" A:\" + this.a + \"}\";\n }\n /**\n * Returns the string \"Color4\"\n * @returns \"Color4\"\n */\n getClassName() {\n return \"Color4\";\n }\n /**\n * Compute the Color4 hash code\n * @returns an unique number that can be used to hash Color4 objects\n */\n getHashCode() {\n let hash = (this.r * 255) | 0;\n hash = (hash * 397) ^ ((this.g * 255) | 0);\n hash = (hash * 397) ^ ((this.b * 255) | 0);\n hash = (hash * 397) ^ ((this.a * 255) | 0);\n return hash;\n }\n /**\n * Creates a new Color4 copied from the current one\n * @returns a new Color4 object\n */\n clone() {\n return new Color4(this.r, this.g, this.b, this.a);\n }\n /**\n * Copies the given Color4 values into the current one\n * @param source defines the source Color4 object\n * @returns the current updated Color4 object\n */\n copyFrom(source) {\n this.r = source.r;\n this.g = source.g;\n this.b = source.b;\n this.a = source.a;\n return this;\n }\n /**\n * Copies the given float values into the current one\n * @param r defines the red component to read from\n * @param g defines the green component to read from\n * @param b defines the blue component to read from\n * @param a defines the alpha component to read from\n * @returns the current updated Color4 object\n */\n copyFromFloats(r, g, b, a) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n return this;\n }\n /**\n * Copies the given float values into the current one\n * @param r defines the red component to read from\n * @param g defines the green component to read from\n * @param b defines the blue component to read from\n * @param a defines the alpha component to read from\n * @returns the current updated Color4 object\n */\n set(r, g, b, a) {\n return this.copyFromFloats(r, g, b, a);\n }\n /**\n * Compute the Color4 hexadecimal code as a string\n * @param returnAsColor3 defines if the string should only contains RGB values (off by default)\n * @returns a string containing the hexadecimal representation of the Color4 object\n */\n toHexString(returnAsColor3 = false) {\n const intR = Math.round(this.r * 255);\n const intG = Math.round(this.g * 255);\n const intB = Math.round(this.b * 255);\n if (returnAsColor3) {\n return \"#\" + Scalar.ToHex(intR) + Scalar.ToHex(intG) + Scalar.ToHex(intB);\n }\n const intA = Math.round(this.a * 255);\n return \"#\" + Scalar.ToHex(intR) + Scalar.ToHex(intG) + Scalar.ToHex(intB) + Scalar.ToHex(intA);\n }\n /**\n * Computes a new Color4 converted from the current one to linear space\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns a new Color4 object\n */\n toLinearSpace(exact = false) {\n const convertedColor = new Color4();\n this.toLinearSpaceToRef(convertedColor, exact);\n return convertedColor;\n }\n /**\n * Converts the Color4 values to linear space and stores the result in \"convertedColor\"\n * @param convertedColor defines the Color4 object where to store the linear space version\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns the unmodified Color4\n */\n toLinearSpaceToRef(convertedColor, exact = false) {\n if (exact) {\n convertedColor.r = colorChannelToLinearSpaceExact(this.r);\n convertedColor.g = colorChannelToLinearSpaceExact(this.g);\n convertedColor.b = colorChannelToLinearSpaceExact(this.b);\n }\n else {\n convertedColor.r = colorChannelToLinearSpace(this.r);\n convertedColor.g = colorChannelToLinearSpace(this.g);\n convertedColor.b = colorChannelToLinearSpace(this.b);\n }\n convertedColor.a = this.a;\n return this;\n }\n /**\n * Computes a new Color4 converted from the current one to gamma space\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns a new Color4 object\n */\n toGammaSpace(exact = false) {\n const convertedColor = new Color4();\n this.toGammaSpaceToRef(convertedColor, exact);\n return convertedColor;\n }\n /**\n * Converts the Color4 values to gamma space and stores the result in \"convertedColor\"\n * @param convertedColor defines the Color4 object where to store the gamma space version\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\n * @returns the unmodified Color4\n */\n toGammaSpaceToRef(convertedColor, exact = false) {\n if (exact) {\n convertedColor.r = colorChannelToGammaSpaceExact(this.r);\n convertedColor.g = colorChannelToGammaSpaceExact(this.g);\n convertedColor.b = colorChannelToGammaSpaceExact(this.b);\n }\n else {\n convertedColor.r = colorChannelToGammaSpace(this.r);\n convertedColor.g = colorChannelToGammaSpace(this.g);\n convertedColor.b = colorChannelToGammaSpace(this.b);\n }\n convertedColor.a = this.a;\n return this;\n }\n // Statics\n /**\n * Creates a new Color4 from the string containing valid hexadecimal values.\n *\n * A valid hex string is either in the format #RRGGBB or #RRGGBBAA.\n *\n * When a hex string without alpha is passed, the resulting Color4 has\n * its alpha value set to 1.0.\n *\n * An invalid string results in a Color with all its channels set to 0.0,\n * i.e. \"transparent black\".\n *\n * @param hex defines a string containing valid hexadecimal values\n * @returns a new Color4 object\n */\n static FromHexString(hex) {\n if (hex.substring(0, 1) !== \"#\" || (hex.length !== 9 && hex.length !== 7)) {\n return new Color4(0.0, 0.0, 0.0, 0.0);\n }\n const r = parseInt(hex.substring(1, 3), 16);\n const g = parseInt(hex.substring(3, 5), 16);\n const b = parseInt(hex.substring(5, 7), 16);\n const a = hex.length === 9 ? parseInt(hex.substring(7, 9), 16) : 255;\n return Color4.FromInts(r, g, b, a);\n }\n /**\n * Creates a new Color4 object set with the linearly interpolated values of \"amount\" between the left Color4 object and the right Color4 object\n * @param left defines the start value\n * @param right defines the end value\n * @param amount defines the gradient factor\n * @returns a new Color4 object\n */\n static Lerp(left, right, amount) {\n const result = new Color4(0.0, 0.0, 0.0, 0.0);\n Color4.LerpToRef(left, right, amount, result);\n return result;\n }\n /**\n * Set the given \"result\" with the linearly interpolated values of \"amount\" between the left Color4 object and the right Color4 object\n * @param left defines the start value\n * @param right defines the end value\n * @param amount defines the gradient factor\n * @param result defines the Color4 object where to store data\n */\n static LerpToRef(left, right, amount, result) {\n result.r = left.r + (right.r - left.r) * amount;\n result.g = left.g + (right.g - left.g) * amount;\n result.b = left.b + (right.b - left.b) * amount;\n result.a = left.a + (right.a - left.a) * amount;\n }\n /**\n * Interpolate between two Color4 using Hermite interpolation\n * @param value1 defines first Color4\n * @param tangent1 defines the incoming tangent\n * @param value2 defines second Color4\n * @param tangent2 defines the outgoing tangent\n * @param amount defines the target Color4\n * @returns the new interpolated Color4\n */\n static Hermite(value1, tangent1, value2, tangent2, amount) {\n const squared = amount * amount;\n const cubed = amount * squared;\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\n const part2 = -2.0 * cubed + 3.0 * squared;\n const part3 = cubed - 2.0 * squared + amount;\n const part4 = cubed - squared;\n const r = value1.r * part1 + value2.r * part2 + tangent1.r * part3 + tangent2.r * part4;\n const g = value1.g * part1 + value2.g * part2 + tangent1.g * part3 + tangent2.g * part4;\n const b = value1.b * part1 + value2.b * part2 + tangent1.b * part3 + tangent2.b * part4;\n const a = value1.a * part1 + value2.a * part2 + tangent1.a * part3 + tangent2.a * part4;\n return new Color4(r, g, b, a);\n }\n /**\n * Returns a new Color4 which is the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @returns 1st derivative\n */\n static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {\n const result = new Color4();\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\n return result;\n }\n /**\n * Update a Color4 with the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\n * @param value1 defines the first control point\n * @param tangent1 defines the first tangent\n * @param value2 defines the second control point\n * @param tangent2 defines the second tangent\n * @param time define where the derivative must be done\n * @param result define where to store the derivative\n */\n static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {\n const t2 = time * time;\n result.r = (t2 - time) * 6 * value1.r + (3 * t2 - 4 * time + 1) * tangent1.r + (-t2 + time) * 6 * value2.r + (3 * t2 - 2 * time) * tangent2.r;\n result.g = (t2 - time) * 6 * value1.g + (3 * t2 - 4 * time + 1) * tangent1.g + (-t2 + time) * 6 * value2.g + (3 * t2 - 2 * time) * tangent2.g;\n result.b = (t2 - time) * 6 * value1.b + (3 * t2 - 4 * time + 1) * tangent1.b + (-t2 + time) * 6 * value2.b + (3 * t2 - 2 * time) * tangent2.b;\n result.a = (t2 - time) * 6 * value1.a + (3 * t2 - 4 * time + 1) * tangent1.a + (-t2 + time) * 6 * value2.a + (3 * t2 - 2 * time) * tangent2.a;\n }\n /**\n * Creates a new Color4 from a Color3 and an alpha value\n * @param color3 defines the source Color3 to read from\n * @param alpha defines the alpha component (1.0 by default)\n * @returns a new Color4 object\n */\n static FromColor3(color3, alpha = 1.0) {\n return new Color4(color3.r, color3.g, color3.b, alpha);\n }\n /**\n * Creates a new Color4 from the starting index element of the given array\n * @param array defines the source array to read from\n * @param offset defines the offset in the source array\n * @returns a new Color4 object\n */\n static FromArray(array, offset = 0) {\n return new Color4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\n }\n /**\n * Creates a new Color4 from the starting index element of the given array\n * @param array defines the source array to read from\n * @param offset defines the offset in the source array\n * @param result defines the target Color4 object\n */\n static FromArrayToRef(array, offset = 0, result) {\n result.r = array[offset];\n result.g = array[offset + 1];\n result.b = array[offset + 2];\n result.a = array[offset + 3];\n }\n /**\n * Creates a new Color3 from integer values (< 256)\n * @param r defines the red component to read from (value between 0 and 255)\n * @param g defines the green component to read from (value between 0 and 255)\n * @param b defines the blue component to read from (value between 0 and 255)\n * @param a defines the alpha component to read from (value between 0 and 255)\n * @returns a new Color3 object\n */\n static FromInts(r, g, b, a) {\n return new Color4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);\n }\n /**\n * Check the content of a given array and convert it to an array containing RGBA data\n * If the original array was already containing count * 4 values then it is returned directly\n * @param colors defines the array to check\n * @param count defines the number of RGBA data to expect\n * @returns an array containing count * 4 values (RGBA)\n */\n static CheckColors4(colors, count) {\n // Check if color3 was used\n if (colors.length === count * 3) {\n const colors4 = [];\n for (let index = 0; index < colors.length; index += 3) {\n const newIndex = (index / 3) * 4;\n colors4[newIndex] = colors[index];\n colors4[newIndex + 1] = colors[index + 1];\n colors4[newIndex + 2] = colors[index + 2];\n colors4[newIndex + 3] = 1.0;\n }\n return colors4;\n }\n return colors;\n }\n }\n /**\n * @internal\n */\n class TmpColors {\n }\n TmpColors.Color3 = ArrayTools.BuildArray(3, Color3.Black);\n TmpColors.Color4 = ArrayTools.BuildArray(3, () => new Color4(0, 0, 0, 0));\n RegisterClass(\"BABYLON.Color3\", Color3);\n RegisterClass(\"BABYLON.Color4\", Color4);\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const __decoratorInitialStore = {};\n const __mergedStore = {};\n const _copySource = function (creationFunction, source, instanciate, options = {}) {\n const destination = creationFunction();\n // Tags\n if (Tags && Tags.HasTags(source)) {\n Tags.AddTagsTo(destination, Tags.GetTags(source, true));\n }\n const classStore = getMergedStore(destination);\n // Map from source texture uniqueId to destination texture\n const textureMap = {};\n // Properties\n for (const property in classStore) {\n const propertyDescriptor = classStore[property];\n const sourceProperty = source[property];\n const propertyType = propertyDescriptor.type;\n if (sourceProperty !== undefined && sourceProperty !== null && (property !== \"uniqueId\" || SerializationHelper.AllowLoadingUniqueId)) {\n switch (propertyType) {\n case 0: // Value\n case 6: // Mesh reference\n case 11: // Camera reference\n destination[property] = sourceProperty;\n break;\n case 1: // Texture\n if (options.cloneTexturesOnlyOnce && textureMap[sourceProperty.uniqueId]) {\n destination[property] = textureMap[sourceProperty.uniqueId];\n }\n else {\n destination[property] = instanciate || sourceProperty.isRenderTarget ? sourceProperty : sourceProperty.clone();\n textureMap[sourceProperty.uniqueId] = destination[property];\n }\n break;\n case 2: // Color3\n case 3: // FresnelParameters\n case 4: // Vector2\n case 5: // Vector3\n case 7: // Color Curves\n case 10: // Quaternion\n case 12: // Matrix\n destination[property] = instanciate ? sourceProperty : sourceProperty.clone();\n break;\n }\n }\n }\n return destination;\n };\n function getDirectStore(target) {\n const classKey = target.getClassName();\n if (!__decoratorInitialStore[classKey]) {\n __decoratorInitialStore[classKey] = {};\n }\n return __decoratorInitialStore[classKey];\n }\n /**\n * Return the list of properties flagged as serializable\n * @param target host object\n */\n function getMergedStore(target) {\n const classKey = target.getClassName();\n if (__mergedStore[classKey]) {\n return __mergedStore[classKey];\n }\n __mergedStore[classKey] = {};\n const store = __mergedStore[classKey];\n let currentTarget = target;\n let currentKey = classKey;\n while (currentKey) {\n const initialStore = __decoratorInitialStore[currentKey];\n for (const property in initialStore) {\n store[property] = initialStore[property];\n }\n let parent;\n let done = false;\n do {\n parent = Object.getPrototypeOf(currentTarget);\n if (!parent.getClassName) {\n done = true;\n break;\n }\n if (parent.getClassName() !== currentKey) {\n break;\n }\n currentTarget = parent;\n } while (parent);\n if (done) {\n break;\n }\n currentKey = parent.getClassName();\n currentTarget = parent;\n }\n return store;\n }\n function generateSerializableMember(type, sourceName) {\n return (target, propertyKey) => {\n const classStore = getDirectStore(target);\n if (!classStore[propertyKey]) {\n classStore[propertyKey] = { type: type, sourceName: sourceName };\n }\n };\n }\n function generateExpandMember(setCallback, targetKey = null) {\n return (target, propertyKey) => {\n const key = targetKey || \"_\" + propertyKey;\n Object.defineProperty(target, propertyKey, {\n get: function () {\n return this[key];\n },\n set: function (value) {\n // does this object (i.e. vector3) has an equals function? use it!\n // Note - not using \"with epsilon\" here, it is expected te behave like the internal cache does.\n if (typeof this.equals === \"function\") {\n if (this.equals(value)) {\n return;\n }\n }\n if (this[key] === value) {\n return;\n }\n this[key] = value;\n target[setCallback].apply(this);\n },\n enumerable: true,\n configurable: true,\n });\n };\n }\n function expandToProperty(callback, targetKey = null) {\n return generateExpandMember(callback, targetKey);\n }\n function serialize(sourceName) {\n return generateSerializableMember(0, sourceName); // value member\n }\n function serializeAsTexture(sourceName) {\n return generateSerializableMember(1, sourceName); // texture member\n }\n function serializeAsColor3(sourceName) {\n return generateSerializableMember(2, sourceName); // color3 member\n }\n function serializeAsFresnelParameters(sourceName) {\n return generateSerializableMember(3, sourceName); // fresnel parameters member\n }\n function serializeAsVector2(sourceName) {\n return generateSerializableMember(4, sourceName); // vector2 member\n }\n function serializeAsVector3(sourceName) {\n return generateSerializableMember(5, sourceName); // vector3 member\n }\n function serializeAsMeshReference(sourceName) {\n return generateSerializableMember(6, sourceName); // mesh reference member\n }\n function serializeAsColorCurves(sourceName) {\n return generateSerializableMember(7, sourceName); // color curves\n }\n function serializeAsColor4(sourceName) {\n return generateSerializableMember(8, sourceName); // color 4\n }\n function serializeAsImageProcessingConfiguration(sourceName) {\n return generateSerializableMember(9, sourceName); // image processing\n }\n function serializeAsQuaternion(sourceName) {\n return generateSerializableMember(10, sourceName); // quaternion member\n }\n function serializeAsMatrix(sourceName) {\n return generateSerializableMember(12, sourceName); // matrix member\n }\n /**\n * Decorator used to define property that can be serialized as reference to a camera\n * @param sourceName defines the name of the property to decorate\n */\n function serializeAsCameraReference(sourceName) {\n return generateSerializableMember(11, sourceName); // camera reference member\n }\n /**\n * Class used to help serialization objects\n */\n class SerializationHelper {\n /**\n * Appends the serialized animations from the source animations\n * @param source Source containing the animations\n * @param destination Target to store the animations\n */\n static AppendSerializedAnimations(source, destination) {\n if (source.animations) {\n destination.animations = [];\n for (let animationIndex = 0; animationIndex < source.animations.length; animationIndex++) {\n const animation = source.animations[animationIndex];\n destination.animations.push(animation.serialize());\n }\n }\n }\n /**\n * Static function used to serialized a specific entity\n * @param entity defines the entity to serialize\n * @param serializationObject defines the optional target object where serialization data will be stored\n * @returns a JSON compatible object representing the serialization of the entity\n */\n static Serialize(entity, serializationObject) {\n if (!serializationObject) {\n serializationObject = {};\n }\n // Tags\n if (Tags) {\n serializationObject.tags = Tags.GetTags(entity);\n }\n const serializedProperties = getMergedStore(entity);\n // Properties\n for (const property in serializedProperties) {\n const propertyDescriptor = serializedProperties[property];\n const targetPropertyName = propertyDescriptor.sourceName || property;\n const propertyType = propertyDescriptor.type;\n const sourceProperty = entity[property];\n if (sourceProperty !== undefined && sourceProperty !== null && (property !== \"uniqueId\" || SerializationHelper.AllowLoadingUniqueId)) {\n switch (propertyType) {\n case 0: // Value\n serializationObject[targetPropertyName] = sourceProperty;\n break;\n case 1: // Texture\n serializationObject[targetPropertyName] = sourceProperty.serialize();\n break;\n case 2: // Color3\n serializationObject[targetPropertyName] = sourceProperty.asArray();\n break;\n case 3: // FresnelParameters\n serializationObject[targetPropertyName] = sourceProperty.serialize();\n break;\n case 4: // Vector2\n serializationObject[targetPropertyName] = sourceProperty.asArray();\n break;\n case 5: // Vector3\n serializationObject[targetPropertyName] = sourceProperty.asArray();\n break;\n case 6: // Mesh reference\n serializationObject[targetPropertyName] = sourceProperty.id;\n break;\n case 7: // Color Curves\n serializationObject[targetPropertyName] = sourceProperty.serialize();\n break;\n case 8: // Color 4\n serializationObject[targetPropertyName] = sourceProperty.asArray();\n break;\n case 9: // Image Processing\n serializationObject[targetPropertyName] = sourceProperty.serialize();\n break;\n case 10: // Quaternion\n serializationObject[targetPropertyName] = sourceProperty.asArray();\n break;\n case 11: // Camera reference\n serializationObject[targetPropertyName] = sourceProperty.id;\n break;\n case 12: // Matrix\n serializationObject[targetPropertyName] = sourceProperty.asArray();\n break;\n }\n }\n }\n return serializationObject;\n }\n /**\n * Given a source json and a destination object in a scene, this function will parse the source and will try to apply its content to the destination object\n * @param source the source json data\n * @param destination the destination object\n * @param scene the scene where the object is\n * @param rootUrl root url to use to load assets\n */\n static ParseProperties(source, destination, scene, rootUrl) {\n if (!rootUrl) {\n rootUrl = \"\";\n }\n const classStore = getMergedStore(destination);\n // Properties\n for (const property in classStore) {\n const propertyDescriptor = classStore[property];\n const sourceProperty = source[propertyDescriptor.sourceName || property];\n const propertyType = propertyDescriptor.type;\n if (sourceProperty !== undefined && sourceProperty !== null && (property !== \"uniqueId\" || SerializationHelper.AllowLoadingUniqueId)) {\n const dest = destination;\n switch (propertyType) {\n case 0: // Value\n dest[property] = sourceProperty;\n break;\n case 1: // Texture\n if (scene) {\n dest[property] = SerializationHelper._TextureParser(sourceProperty, scene, rootUrl);\n }\n break;\n case 2: // Color3\n dest[property] = Color3.FromArray(sourceProperty);\n break;\n case 3: // FresnelParameters\n dest[property] = SerializationHelper._FresnelParametersParser(sourceProperty);\n break;\n case 4: // Vector2\n dest[property] = Vector2.FromArray(sourceProperty);\n break;\n case 5: // Vector3\n dest[property] = Vector3.FromArray(sourceProperty);\n break;\n case 6: // Mesh reference\n if (scene) {\n dest[property] = scene.getLastMeshById(sourceProperty);\n }\n break;\n case 7: // Color Curves\n dest[property] = SerializationHelper._ColorCurvesParser(sourceProperty);\n break;\n case 8: // Color 4\n dest[property] = Color4.FromArray(sourceProperty);\n break;\n case 9: // Image Processing\n dest[property] = SerializationHelper._ImageProcessingConfigurationParser(sourceProperty);\n break;\n case 10: // Quaternion\n dest[property] = Quaternion.FromArray(sourceProperty);\n break;\n case 11: // Camera reference\n if (scene) {\n dest[property] = scene.getCameraById(sourceProperty);\n }\n break;\n case 12: // Matrix\n dest[property] = Matrix.FromArray(sourceProperty);\n break;\n }\n }\n }\n }\n /**\n * Creates a new entity from a serialization data object\n * @param creationFunction defines a function used to instanciated the new entity\n * @param source defines the source serialization data\n * @param scene defines the hosting scene\n * @param rootUrl defines the root url for resources\n * @returns a new entity\n */\n static Parse(creationFunction, source, scene, rootUrl = null) {\n const destination = creationFunction();\n // Tags\n if (Tags) {\n Tags.AddTagsTo(destination, source.tags);\n }\n SerializationHelper.ParseProperties(source, destination, scene, rootUrl);\n return destination;\n }\n /**\n * Clones an object\n * @param creationFunction defines the function used to instanciate the new object\n * @param source defines the source object\n * @returns the cloned object\n */\n static Clone(creationFunction, source, options = {}) {\n return _copySource(creationFunction, source, false, options);\n }\n /**\n * Instanciates a new object based on a source one (some data will be shared between both object)\n * @param creationFunction defines the function used to instanciate the new object\n * @param source defines the source object\n * @returns the new object\n */\n static Instanciate(creationFunction, source) {\n return _copySource(creationFunction, source, true);\n }\n }\n /**\n * Gets or sets a boolean to indicate if the UniqueId property should be serialized\n */\n SerializationHelper.AllowLoadingUniqueId = false;\n /**\n * @internal\n */\n SerializationHelper._ImageProcessingConfigurationParser = (sourceProperty) => {\n throw _WarnImport(\"ImageProcessingConfiguration\");\n };\n /**\n * @internal\n */\n SerializationHelper._FresnelParametersParser = (sourceProperty) => {\n throw _WarnImport(\"FresnelParameters\");\n };\n /**\n * @internal\n */\n SerializationHelper._ColorCurvesParser = (sourceProperty) => {\n throw _WarnImport(\"ColorCurves\");\n };\n /**\n * @internal\n */\n SerializationHelper._TextureParser = (sourceProperty, scene, rootUrl) => {\n throw _WarnImport(\"Texture\");\n };\n /**\n * Decorator used to redirect a function to a native implementation if available.\n * @internal\n */\n function nativeOverride(target, propertyKey, descriptor, predicate) {\n // Cache the original JS function for later.\n const jsFunc = descriptor.value;\n // Override the JS function to check for a native override on first invocation. Setting descriptor.value overrides the function at the early stage of code being loaded/imported.\n descriptor.value = (...params) => {\n // Assume the resolved function will be the original JS function, then we will check for the Babylon Native context.\n let func = jsFunc;\n // Check if we are executing in a Babylon Native context (e.g. check the presence of the _native global property) and if so also check if a function override is available.\n if (typeof _native !== \"undefined\" && _native[propertyKey]) {\n const nativeFunc = _native[propertyKey];\n // If a predicate was provided, then we'll need to invoke the predicate on each invocation of the underlying function to determine whether to call the native function or the JS function.\n if (predicate) {\n // The resolved function will execute the predicate and then either execute the native function or the JS function.\n func = (...params) => (predicate(...params) ? nativeFunc(...params) : jsFunc(...params));\n }\n else {\n // The resolved function will directly execute the native function.\n func = nativeFunc;\n }\n }\n // Override the JS function again with the final resolved target function.\n target[propertyKey] = func;\n // The JS function has now been overridden based on whether we're executing in the context of Babylon Native, but we still need to invoke that function.\n // Future invocations of the function will just directly invoke the final overridden function, not any of the decorator setup logic above.\n return func(...params);\n };\n }\n /**\n * Decorator factory that applies the nativeOverride decorator, but determines whether to redirect to the native implementation based on a filter function that evaluates the function arguments.\n * @param predicate\n * @example @nativeOverride.filter((...[arg1]: Parameters) => arg1.length > 20)\n * public someMethod(arg1: string, arg2: number): string {\n * @internal\n */\n nativeOverride.filter = function (predicate) {\n return (target, propertyKey, descriptor) => nativeOverride(target, propertyKey, descriptor, predicate);\n };\n\n /** @internal */\n class _InternalNodeDataInfo {\n constructor() {\n this._doNotSerialize = false;\n this._isDisposed = false;\n this._sceneRootNodesIndex = -1;\n this._isEnabled = true;\n this._isParentEnabled = true;\n this._isReady = true;\n this._onEnabledStateChangedObservable = new Observable$1();\n this._onClonedObservable = new Observable$1();\n }\n }\n /**\n * Node is the basic class for all scene objects (Mesh, Light, Camera.)\n */\n class Node {\n /**\n * Add a new node constructor\n * @param type defines the type name of the node to construct\n * @param constructorFunc defines the constructor function\n */\n static AddNodeConstructor(type, constructorFunc) {\n this._NodeConstructors[type] = constructorFunc;\n }\n /**\n * Returns a node constructor based on type name\n * @param type defines the type name\n * @param name defines the new node name\n * @param scene defines the hosting scene\n * @param options defines optional options to transmit to constructors\n * @returns the new constructor or null\n */\n static Construct(type, name, scene, options) {\n const constructorFunc = this._NodeConstructors[type];\n if (!constructorFunc) {\n return null;\n }\n return constructorFunc(name, scene, options);\n }\n /**\n * Gets or sets the accessibility tag to describe the node for accessibility purpose.\n */\n set accessibilityTag(value) {\n this._accessibilityTag = value;\n this.onAccessibilityTagChangedObservable.notifyObservers(value);\n }\n get accessibilityTag() {\n return this._accessibilityTag;\n }\n /**\n * Gets or sets a boolean used to define if the node must be serialized\n */\n get doNotSerialize() {\n if (this._nodeDataStorage._doNotSerialize) {\n return true;\n }\n if (this._parentNode) {\n return this._parentNode.doNotSerialize;\n }\n return false;\n }\n set doNotSerialize(value) {\n this._nodeDataStorage._doNotSerialize = value;\n }\n /**\n * Gets a boolean indicating if the node has been disposed\n * @returns true if the node was disposed\n */\n isDisposed() {\n return this._nodeDataStorage._isDisposed;\n }\n /**\n * Gets or sets the parent of the node (without keeping the current position in the scene)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/parent\n */\n set parent(parent) {\n if (this._parentNode === parent) {\n return;\n }\n const previousParentNode = this._parentNode;\n // Remove self from list of children of parent\n if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {\n const index = this._parentNode._children.indexOf(this);\n if (index !== -1) {\n this._parentNode._children.splice(index, 1);\n }\n if (!parent && !this._nodeDataStorage._isDisposed) {\n this._addToSceneRootNodes();\n }\n }\n // Store new parent\n this._parentNode = parent;\n // Add as child to new parent\n if (this._parentNode) {\n if (this._parentNode._children === undefined || this._parentNode._children === null) {\n this._parentNode._children = new Array();\n }\n this._parentNode._children.push(this);\n if (!previousParentNode) {\n this._removeFromSceneRootNodes();\n }\n }\n // Enabled state\n this._syncParentEnabledState();\n }\n get parent() {\n return this._parentNode;\n }\n /**\n * @internal\n */\n _serializeAsParent(serializationObject) {\n serializationObject.parentId = this.uniqueId;\n }\n /** @internal */\n _addToSceneRootNodes() {\n if (this._nodeDataStorage._sceneRootNodesIndex === -1) {\n this._nodeDataStorage._sceneRootNodesIndex = this._scene.rootNodes.length;\n this._scene.rootNodes.push(this);\n }\n }\n /** @internal */\n _removeFromSceneRootNodes() {\n if (this._nodeDataStorage._sceneRootNodesIndex !== -1) {\n const rootNodes = this._scene.rootNodes;\n const lastIdx = rootNodes.length - 1;\n rootNodes[this._nodeDataStorage._sceneRootNodesIndex] = rootNodes[lastIdx];\n rootNodes[this._nodeDataStorage._sceneRootNodesIndex]._nodeDataStorage._sceneRootNodesIndex = this._nodeDataStorage._sceneRootNodesIndex;\n this._scene.rootNodes.pop();\n this._nodeDataStorage._sceneRootNodesIndex = -1;\n }\n }\n /**\n * Gets or sets the animation properties override\n */\n get animationPropertiesOverride() {\n if (!this._animationPropertiesOverride) {\n return this._scene.animationPropertiesOverride;\n }\n return this._animationPropertiesOverride;\n }\n set animationPropertiesOverride(value) {\n this._animationPropertiesOverride = value;\n }\n /**\n * Gets a string identifying the name of the class\n * @returns \"Node\" string\n */\n getClassName() {\n return \"Node\";\n }\n /**\n * Sets a callback that will be raised when the node will be disposed\n */\n set onDispose(callback) {\n if (this._onDisposeObserver) {\n this.onDisposeObservable.remove(this._onDisposeObserver);\n }\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\n }\n /**\n * An event triggered when the enabled state of the node changes\n */\n get onEnabledStateChangedObservable() {\n return this._nodeDataStorage._onEnabledStateChangedObservable;\n }\n /**\n * An event triggered when the node is cloned\n */\n get onClonedObservable() {\n return this._nodeDataStorage._onClonedObservable;\n }\n /**\n * Creates a new Node\n * @param name the name and id to be given to this node\n * @param scene the scene this node will be added to\n */\n constructor(name, scene = null) {\n this._isDirty = false;\n this._nodeDataStorage = new _InternalNodeDataInfo();\n /**\n * Gets or sets a string used to store user defined state for the node\n */\n this.state = \"\";\n /**\n * Gets or sets an object used to store user defined information for the node\n */\n this.metadata = null;\n /**\n * For internal use only. Please do not use.\n */\n this.reservedDataStore = null;\n this._accessibilityTag = null;\n this.onAccessibilityTagChangedObservable = new Observable$1();\n /** @internal */\n this._parentContainer = null;\n /**\n * Gets a list of Animations associated with the node\n */\n this.animations = new Array();\n this._ranges = {};\n /**\n * Callback raised when the node is ready to be used\n */\n this.onReady = null;\n /** @internal */\n this._currentRenderId = -1;\n this._parentUpdateId = -1;\n /** @internal */\n this._childUpdateId = -1;\n /** @internal */\n this._waitingParentId = null;\n /** @internal */\n this._waitingParentInstanceIndex = null;\n /** @internal */\n this._waitingParsedUniqueId = null;\n /** @internal */\n this._cache = {};\n this._parentNode = null;\n /** @internal */\n this._children = null;\n /** @internal */\n this._worldMatrix = Matrix.Identity();\n /** @internal */\n this._worldMatrixDeterminant = 0;\n /** @internal */\n this._worldMatrixDeterminantIsDirty = true;\n this._animationPropertiesOverride = null;\n /** @internal */\n this._isNode = true;\n /**\n * An event triggered when the mesh is disposed\n */\n this.onDisposeObservable = new Observable$1();\n this._onDisposeObserver = null;\n // Behaviors\n this._behaviors = new Array();\n this.name = name;\n this.id = name;\n this._scene = (scene || EngineStore.LastCreatedScene);\n this.uniqueId = this._scene.getUniqueId();\n this._initCache();\n }\n /**\n * Gets the scene of the node\n * @returns a scene\n */\n getScene() {\n return this._scene;\n }\n /**\n * Gets the engine of the node\n * @returns a Engine\n */\n getEngine() {\n return this._scene.getEngine();\n }\n /**\n * Attach a behavior to the node\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\n * @param behavior defines the behavior to attach\n * @param attachImmediately defines that the behavior must be attached even if the scene is still loading\n * @returns the current Node\n */\n addBehavior(behavior, attachImmediately = false) {\n const index = this._behaviors.indexOf(behavior);\n if (index !== -1) {\n return this;\n }\n behavior.init();\n if (this._scene.isLoading && !attachImmediately) {\n // We defer the attach when the scene will be loaded\n this._scene.onDataLoadedObservable.addOnce(() => {\n behavior.attach(this);\n });\n }\n else {\n behavior.attach(this);\n }\n this._behaviors.push(behavior);\n return this;\n }\n /**\n * Remove an attached behavior\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\n * @param behavior defines the behavior to attach\n * @returns the current Node\n */\n removeBehavior(behavior) {\n const index = this._behaviors.indexOf(behavior);\n if (index === -1) {\n return this;\n }\n this._behaviors[index].detach();\n this._behaviors.splice(index, 1);\n return this;\n }\n /**\n * Gets the list of attached behaviors\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\n */\n get behaviors() {\n return this._behaviors;\n }\n /**\n * Gets an attached behavior by name\n * @param name defines the name of the behavior to look for\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\n * @returns null if behavior was not found else the requested behavior\n */\n getBehaviorByName(name) {\n for (const behavior of this._behaviors) {\n if (behavior.name === name) {\n return behavior;\n }\n }\n return null;\n }\n /**\n * Returns the latest update of the World matrix\n * @returns a Matrix\n */\n getWorldMatrix() {\n if (this._currentRenderId !== this._scene.getRenderId()) {\n this.computeWorldMatrix();\n }\n return this._worldMatrix;\n }\n /** @internal */\n _getWorldMatrixDeterminant() {\n if (this._worldMatrixDeterminantIsDirty) {\n this._worldMatrixDeterminantIsDirty = false;\n this._worldMatrixDeterminant = this._worldMatrix.determinant();\n }\n return this._worldMatrixDeterminant;\n }\n /**\n * Returns directly the latest state of the mesh World matrix.\n * A Matrix is returned.\n */\n get worldMatrixFromCache() {\n return this._worldMatrix;\n }\n // override it in derived class if you add new variables to the cache\n // and call the parent class method\n /** @internal */\n _initCache() {\n this._cache = {};\n this._cache.parent = undefined;\n }\n /**\n * @internal\n */\n updateCache(force) {\n if (!force && this.isSynchronized()) {\n return;\n }\n this._cache.parent = this.parent;\n this._updateCache();\n }\n /**\n * @internal\n */\n _getActionManagerForTrigger(trigger, _initialCall = true) {\n if (!this.parent) {\n return null;\n }\n return this.parent._getActionManagerForTrigger(trigger, false);\n }\n // override it in derived class if you add new variables to the cache\n // and call the parent class method if !ignoreParentClass\n /**\n * @internal\n */\n _updateCache(_ignoreParentClass) { }\n // override it in derived class if you add new variables to the cache\n /** @internal */\n _isSynchronized() {\n return true;\n }\n /** @internal */\n _markSyncedWithParent() {\n if (this._parentNode) {\n this._parentUpdateId = this._parentNode._childUpdateId;\n }\n }\n /** @internal */\n isSynchronizedWithParent() {\n if (!this._parentNode) {\n return true;\n }\n if (this._parentNode._isDirty || this._parentUpdateId !== this._parentNode._childUpdateId) {\n return false;\n }\n return this._parentNode.isSynchronized();\n }\n /** @internal */\n isSynchronized() {\n if (this._cache.parent !== this._parentNode) {\n this._cache.parent = this._parentNode;\n return false;\n }\n if (this._parentNode && !this.isSynchronizedWithParent()) {\n return false;\n }\n return this._isSynchronized();\n }\n /**\n * Is this node ready to be used/rendered\n * @param _completeCheck defines if a complete check (including materials and lights) has to be done (false by default)\n * @returns true if the node is ready\n */\n isReady(_completeCheck = false) {\n return this._nodeDataStorage._isReady;\n }\n /**\n * Flag the node as dirty (Forcing it to update everything)\n * @param _property helps children apply precise \"dirtyfication\"\n * @returns this node\n */\n markAsDirty(_property) {\n this._currentRenderId = Number.MAX_VALUE;\n this._isDirty = true;\n return this;\n }\n /**\n * Is this node enabled?\n * If the node has a parent, all ancestors will be checked and false will be returned if any are false (not enabled), otherwise will return true\n * @param checkAncestors indicates if this method should check the ancestors. The default is to check the ancestors. If set to false, the method will return the value of this node without checking ancestors\n * @returns whether this node (and its parent) is enabled\n */\n isEnabled(checkAncestors = true) {\n if (checkAncestors === false) {\n return this._nodeDataStorage._isEnabled;\n }\n if (!this._nodeDataStorage._isEnabled) {\n return false;\n }\n return this._nodeDataStorage._isParentEnabled;\n }\n /** @internal */\n _syncParentEnabledState() {\n this._nodeDataStorage._isParentEnabled = this._parentNode ? this._parentNode.isEnabled() : true;\n if (this._children) {\n this._children.forEach((c) => {\n c._syncParentEnabledState(); // Force children to update accordingly\n });\n }\n }\n /**\n * Set the enabled state of this node\n * @param value defines the new enabled state\n */\n setEnabled(value) {\n if (this._nodeDataStorage._isEnabled === value) {\n return;\n }\n this._nodeDataStorage._isEnabled = value;\n this._syncParentEnabledState();\n this._nodeDataStorage._onEnabledStateChangedObservable.notifyObservers(value);\n }\n /**\n * Is this node a descendant of the given node?\n * The function will iterate up the hierarchy until the ancestor was found or no more parents defined\n * @param ancestor defines the parent node to inspect\n * @returns a boolean indicating if this node is a descendant of the given node\n */\n isDescendantOf(ancestor) {\n if (this.parent) {\n if (this.parent === ancestor) {\n return true;\n }\n return this.parent.isDescendantOf(ancestor);\n }\n return false;\n }\n /**\n * @internal\n */\n _getDescendants(results, directDescendantsOnly = false, predicate) {\n if (!this._children) {\n return;\n }\n for (let index = 0; index < this._children.length; index++) {\n const item = this._children[index];\n if (!predicate || predicate(item)) {\n results.push(item);\n }\n if (!directDescendantsOnly) {\n item._getDescendants(results, false, predicate);\n }\n }\n }\n /**\n * Will return all nodes that have this node as ascendant\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\n * @returns all children nodes of all types\n */\n getDescendants(directDescendantsOnly, predicate) {\n const results = new Array();\n this._getDescendants(results, directDescendantsOnly, predicate);\n return results;\n }\n /**\n * Get all child-meshes of this node\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: false)\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\n * @returns an array of AbstractMesh\n */\n getChildMeshes(directDescendantsOnly, predicate) {\n const results = [];\n this._getDescendants(results, directDescendantsOnly, (node) => {\n return (!predicate || predicate(node)) && node.cullingStrategy !== undefined;\n });\n return results;\n }\n /**\n * Get all direct children of this node\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)\n * @returns an array of Node\n */\n getChildren(predicate, directDescendantsOnly = true) {\n return this.getDescendants(directDescendantsOnly, predicate);\n }\n /**\n * @internal\n */\n _setReady(state) {\n if (state === this._nodeDataStorage._isReady) {\n return;\n }\n if (!state) {\n this._nodeDataStorage._isReady = false;\n return;\n }\n if (this.onReady) {\n this.onReady(this);\n }\n this._nodeDataStorage._isReady = true;\n }\n /**\n * Get an animation by name\n * @param name defines the name of the animation to look for\n * @returns null if not found else the requested animation\n */\n getAnimationByName(name) {\n for (let i = 0; i < this.animations.length; i++) {\n const animation = this.animations[i];\n if (animation.name === name) {\n return animation;\n }\n }\n return null;\n }\n /**\n * Creates an animation range for this node\n * @param name defines the name of the range\n * @param from defines the starting key\n * @param to defines the end key\n */\n createAnimationRange(name, from, to) {\n // check name not already in use\n if (!this._ranges[name]) {\n this._ranges[name] = Node._AnimationRangeFactory(name, from, to);\n for (let i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {\n if (this.animations[i]) {\n this.animations[i].createRange(name, from, to);\n }\n }\n }\n }\n /**\n * Delete a specific animation range\n * @param name defines the name of the range to delete\n * @param deleteFrames defines if animation frames from the range must be deleted as well\n */\n deleteAnimationRange(name, deleteFrames = true) {\n for (let i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {\n if (this.animations[i]) {\n this.animations[i].deleteRange(name, deleteFrames);\n }\n }\n this._ranges[name] = null; // said much faster than 'delete this._range[name]'\n }\n /**\n * Get an animation range by name\n * @param name defines the name of the animation range to look for\n * @returns null if not found else the requested animation range\n */\n getAnimationRange(name) {\n return this._ranges[name] || null;\n }\n /**\n * Clone the current node\n * @param name Name of the new clone\n * @param newParent New parent for the clone\n * @param doNotCloneChildren Do not clone children hierarchy\n * @returns the new transform node\n */\n clone(name, newParent, doNotCloneChildren) {\n const result = SerializationHelper.Clone(() => new Node(name, this.getScene()), this);\n if (newParent) {\n result.parent = newParent;\n }\n if (!doNotCloneChildren) {\n // Children\n const directDescendants = this.getDescendants(true);\n for (let index = 0; index < directDescendants.length; index++) {\n const child = directDescendants[index];\n child.clone(name + \".\" + child.name, result);\n }\n }\n return result;\n }\n /**\n * Gets the list of all animation ranges defined on this node\n * @returns an array\n */\n getAnimationRanges() {\n const animationRanges = [];\n let name;\n for (name in this._ranges) {\n animationRanges.push(this._ranges[name]);\n }\n return animationRanges;\n }\n /**\n * Will start the animation sequence\n * @param name defines the range frames for animation sequence\n * @param loop defines if the animation should loop (false by default)\n * @param speedRatio defines the speed factor in which to run the animation (1 by default)\n * @param onAnimationEnd defines a function to be executed when the animation ended (undefined by default)\n * @returns the object created for this animation. If range does not exist, it will return null\n */\n beginAnimation(name, loop, speedRatio, onAnimationEnd) {\n const range = this.getAnimationRange(name);\n if (!range) {\n return null;\n }\n return this._scene.beginAnimation(this, range.from, range.to, loop, speedRatio, onAnimationEnd);\n }\n /**\n * Serialize animation ranges into a JSON compatible object\n * @returns serialization object\n */\n serializeAnimationRanges() {\n const serializationRanges = [];\n for (const name in this._ranges) {\n const localRange = this._ranges[name];\n if (!localRange) {\n continue;\n }\n const range = {};\n range.name = name;\n range.from = localRange.from;\n range.to = localRange.to;\n serializationRanges.push(range);\n }\n return serializationRanges;\n }\n /**\n * Computes the world matrix of the node\n * @param _force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\n * @returns the world matrix\n */\n computeWorldMatrix(_force) {\n if (!this._worldMatrix) {\n this._worldMatrix = Matrix.Identity();\n }\n return this._worldMatrix;\n }\n /**\n * Releases resources associated with this node.\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n this._nodeDataStorage._isDisposed = true;\n if (!doNotRecurse) {\n const nodes = this.getDescendants(true);\n for (const node of nodes) {\n node.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n }\n if (!this.parent) {\n this._removeFromSceneRootNodes();\n }\n else {\n this.parent = null;\n }\n // Callback\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n this.onEnabledStateChangedObservable.clear();\n this.onClonedObservable.clear();\n // Behaviors\n for (const behavior of this._behaviors) {\n behavior.detach();\n }\n this._behaviors.length = 0;\n this.metadata = null;\n }\n /**\n * Parse animation range data from a serialization object and store them into a given node\n * @param node defines where to store the animation ranges\n * @param parsedNode defines the serialization object to read data from\n * @param _scene defines the hosting scene\n */\n static ParseAnimationRanges(node, parsedNode, _scene) {\n if (parsedNode.ranges) {\n for (let index = 0; index < parsedNode.ranges.length; index++) {\n const data = parsedNode.ranges[index];\n node.createAnimationRange(data.name, data.from, data.to);\n }\n }\n }\n /**\n * Return the minimum and maximum world vectors of the entire hierarchy under current node\n * @param includeDescendants Include bounding info from descendants as well (true by default)\n * @param predicate defines a callback function that can be customize to filter what meshes should be included in the list used to compute the bounding vectors\n * @returns the new bounding vectors\n */\n getHierarchyBoundingVectors(includeDescendants = true, predicate = null) {\n // Ensures that all world matrix will be recomputed.\n this.getScene().incrementRenderId();\n this.computeWorldMatrix(true);\n let min;\n let max;\n const thisAbstractMesh = this;\n if (thisAbstractMesh.getBoundingInfo && thisAbstractMesh.subMeshes) {\n // If this is an abstract mesh get its bounding info\n const boundingInfo = thisAbstractMesh.getBoundingInfo();\n min = boundingInfo.boundingBox.minimumWorld.clone();\n max = boundingInfo.boundingBox.maximumWorld.clone();\n }\n else {\n min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n }\n if (includeDescendants) {\n const descendants = this.getDescendants(false);\n for (const descendant of descendants) {\n const childMesh = descendant;\n childMesh.computeWorldMatrix(true);\n // Filters meshes based on custom predicate function.\n if (predicate && !predicate(childMesh)) {\n continue;\n }\n //make sure we have the needed params to get mix and max\n if (!childMesh.getBoundingInfo || childMesh.getTotalVertices() === 0) {\n continue;\n }\n const childBoundingInfo = childMesh.getBoundingInfo();\n const boundingBox = childBoundingInfo.boundingBox;\n const minBox = boundingBox.minimumWorld;\n const maxBox = boundingBox.maximumWorld;\n Vector3.CheckExtends(minBox, min, max);\n Vector3.CheckExtends(maxBox, min, max);\n }\n }\n return {\n min: min,\n max: max,\n };\n }\n }\n /**\n * @internal\n */\n Node._AnimationRangeFactory = (_name, _from, _to) => {\n throw _WarnImport(\"AnimationRange\");\n };\n Node._NodeConstructors = {};\n __decorate$1([\n serialize()\n ], Node.prototype, \"name\", void 0);\n __decorate$1([\n serialize()\n ], Node.prototype, \"id\", void 0);\n __decorate$1([\n serialize()\n ], Node.prototype, \"uniqueId\", void 0);\n __decorate$1([\n serialize()\n ], Node.prototype, \"state\", void 0);\n __decorate$1([\n serialize()\n ], Node.prototype, \"metadata\", void 0);\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * Checks if the window object exists\n * @returns true if the window object exists\n */\n function IsWindowObjectExist() {\n return typeof window !== \"undefined\";\n }\n /**\n * Checks if the navigator object exists\n * @returns true if the navigator object exists\n */\n function IsNavigatorAvailable() {\n return typeof navigator !== \"undefined\";\n }\n /**\n * Check if the document object exists\n * @returns true if the document object exists\n */\n function IsDocumentAvailable() {\n return typeof document !== \"undefined\";\n }\n /**\n * Extracts text content from a DOM element hierarchy\n * @param element defines the root element\n * @returns a string\n */\n function GetDOMTextContent(element) {\n let result = \"\";\n let child = element.firstChild;\n while (child) {\n if (child.nodeType === 3) {\n result += child.textContent;\n }\n child = child.nextSibling;\n }\n return result;\n }\n\n /**\n * Logger used throughout the application to allow configuration of\n * the log level required for the messages.\n */\n class Logger {\n static _CheckLimit(message, limit) {\n let entry = Logger._LogLimitOutputs[message];\n if (!entry) {\n entry = { limit, current: 1 };\n Logger._LogLimitOutputs[message] = entry;\n }\n else {\n entry.current++;\n }\n return entry.current <= entry.limit;\n }\n static _GenerateLimitMessage(message, level = 1) {\n var _a;\n const entry = Logger._LogLimitOutputs[message];\n if (!entry || !Logger.MessageLimitReached) {\n return;\n }\n const type = this._Levels[level];\n if (entry.current === entry.limit) {\n Logger[type.name](Logger.MessageLimitReached.replace(/%LIMIT%/g, \"\" + entry.limit).replace(/%TYPE%/g, (_a = type.name) !== null && _a !== void 0 ? _a : \"\"));\n }\n }\n static _AddLogEntry(entry) {\n Logger._LogCache = entry + Logger._LogCache;\n if (Logger.OnNewCacheEntry) {\n Logger.OnNewCacheEntry(entry);\n }\n }\n static _FormatMessage(message) {\n const padStr = (i) => (i < 10 ? \"0\" + i : \"\" + i);\n const date = new Date();\n return \"[\" + padStr(date.getHours()) + \":\" + padStr(date.getMinutes()) + \":\" + padStr(date.getSeconds()) + \"]: \" + message;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static _LogDisabled(message, limit) {\n // nothing to do\n }\n static _LogEnabled(level = 1, message, limit) {\n if (limit !== undefined && !Logger._CheckLimit(message, limit)) {\n return;\n }\n const formattedMessage = Logger._FormatMessage(message);\n const type = this._Levels[level];\n type.logFunc && type.logFunc(\"BJS - \" + formattedMessage);\n const entry = `
${formattedMessage}

`;\n Logger._AddLogEntry(entry);\n Logger._GenerateLimitMessage(message, level);\n }\n /**\n * Gets current log cache (list of logs)\n */\n static get LogCache() {\n return Logger._LogCache;\n }\n /**\n * Clears the log cache\n */\n static ClearLogCache() {\n Logger._LogCache = \"\";\n Logger._LogLimitOutputs = {};\n Logger.errorsCount = 0;\n }\n /**\n * Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)\n */\n static set LogLevels(level) {\n Logger.Log = Logger._LogDisabled;\n Logger.Warn = Logger._LogDisabled;\n Logger.Error = Logger._LogDisabled;\n [Logger.MessageLogLevel, Logger.WarningLogLevel, Logger.ErrorLogLevel].forEach((l) => {\n if ((level & l) === l) {\n const type = this._Levels[l];\n Logger[type.name] = Logger._LogEnabled.bind(Logger, l);\n }\n });\n }\n }\n /**\n * No log\n */\n Logger.NoneLogLevel = 0;\n /**\n * Only message logs\n */\n Logger.MessageLogLevel = 1;\n /**\n * Only warning logs\n */\n Logger.WarningLogLevel = 2;\n /**\n * Only error logs\n */\n Logger.ErrorLogLevel = 4;\n /**\n * All logs\n */\n Logger.AllLogLevel = 7;\n /**\n * Message to display when a message has been logged too many times\n */\n Logger.MessageLimitReached = \"Too many %TYPE%s (%LIMIT%), no more %TYPE%s will be reported for this message.\";\n Logger._LogCache = \"\";\n Logger._LogLimitOutputs = {};\n // levels according to the (binary) numbering.\n Logger._Levels = [\n {},\n { color: \"white\", logFunc: console.log, name: \"Log\" },\n { color: \"orange\", logFunc: console.warn, name: \"Warn\" },\n {},\n { color: \"red\", logFunc: console.error, name: \"Error\" },\n ];\n /**\n * Gets a value indicating the number of loading errors\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Logger.errorsCount = 0;\n /**\n * Log a message to the console\n */\n Logger.Log = Logger._LogEnabled.bind(Logger, Logger.MessageLogLevel);\n /**\n * Write a warning message to the console\n */\n Logger.Warn = Logger._LogEnabled.bind(Logger, Logger.WarningLogLevel);\n /**\n * Write an error message to the console\n */\n Logger.Error = Logger._LogEnabled.bind(Logger, Logger.ErrorLogLevel);\n\n const CloneValue = (source, destinationObject) => {\n if (!source) {\n return null;\n }\n if (source.getClassName && source.getClassName() === \"Mesh\") {\n return null;\n }\n if (source.getClassName && (source.getClassName() === \"SubMesh\" || source.getClassName() === \"PhysicsBody\")) {\n return source.clone(destinationObject);\n }\n else if (source.clone) {\n return source.clone();\n }\n else if (Array.isArray(source)) {\n return source.slice();\n }\n return null;\n };\n function GetAllPropertyNames(obj) {\n const props = [];\n do {\n Object.getOwnPropertyNames(obj).forEach(function (prop) {\n if (props.indexOf(prop) === -1) {\n props.push(prop);\n }\n });\n } while ((obj = Object.getPrototypeOf(obj)));\n return props;\n }\n /**\n * Class containing a set of static utilities functions for deep copy.\n */\n class DeepCopier {\n /**\n * Tries to copy an object by duplicating every property\n * @param source defines the source object\n * @param destination defines the target object\n * @param doNotCopyList defines a list of properties to avoid\n * @param mustCopyList defines a list of properties to copy (even if they start with _)\n */\n static DeepCopy(source, destination, doNotCopyList, mustCopyList) {\n const properties = GetAllPropertyNames(source);\n for (const prop of properties) {\n if (prop[0] === \"_\" && (!mustCopyList || mustCopyList.indexOf(prop) === -1)) {\n continue;\n }\n if (prop.endsWith(\"Observable\")) {\n continue;\n }\n if (doNotCopyList && doNotCopyList.indexOf(prop) !== -1) {\n continue;\n }\n const sourceValue = source[prop];\n const typeOfSourceValue = typeof sourceValue;\n if (typeOfSourceValue === \"function\") {\n continue;\n }\n try {\n if (typeOfSourceValue === \"object\") {\n if (sourceValue instanceof Uint8Array) {\n destination[prop] = Uint8Array.from(sourceValue);\n }\n else if (sourceValue instanceof Array) {\n destination[prop] = [];\n if (sourceValue.length > 0) {\n if (typeof sourceValue[0] == \"object\") {\n for (let index = 0; index < sourceValue.length; index++) {\n const clonedValue = CloneValue(sourceValue[index], destination);\n if (destination[prop].indexOf(clonedValue) === -1) {\n // Test if auto inject was not done\n destination[prop].push(clonedValue);\n }\n }\n }\n else {\n destination[prop] = sourceValue.slice(0);\n }\n }\n }\n else {\n destination[prop] = CloneValue(sourceValue, destination);\n }\n }\n else {\n destination[prop] = sourceValue;\n }\n }\n catch (e) {\n // Log a warning (it could be because of a read-only property)\n Logger.Warn(e.message);\n }\n }\n }\n }\n\n /**\n * Class containing a set of static utilities functions for precision date\n */\n class PrecisionDate {\n /**\n * Gets either window.performance.now() if supported or Date.now() else\n */\n static get Now() {\n if (IsWindowObjectExist() && window.performance && window.performance.now) {\n return window.performance.now();\n }\n return Date.now();\n }\n }\n\n /** @internal */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function createXMLHttpRequest() {\n // If running in Babylon Native, then defer to the native XMLHttpRequest, which has the same public contract\n if (typeof _native !== \"undefined\" && _native.XMLHttpRequest) {\n return new _native.XMLHttpRequest();\n }\n else {\n return new XMLHttpRequest();\n }\n }\n /**\n * Extended version of XMLHttpRequest with support for customizations (headers, ...)\n */\n class WebRequest {\n constructor() {\n this._xhr = createXMLHttpRequest();\n this._requestURL = \"\";\n }\n _injectCustomRequestHeaders() {\n if (this._shouldSkipRequestModifications(this._requestURL)) {\n return;\n }\n for (const key in WebRequest.CustomRequestHeaders) {\n const val = WebRequest.CustomRequestHeaders[key];\n if (val) {\n this._xhr.setRequestHeader(key, val);\n }\n }\n }\n _shouldSkipRequestModifications(url) {\n return WebRequest.SkipRequestModificationForBabylonCDN && (url.includes(\"preview.babylonjs.com\") || url.includes(\"cdn.babylonjs.com\"));\n }\n /**\n * Gets or sets a function to be called when loading progress changes\n */\n get onprogress() {\n return this._xhr.onprogress;\n }\n set onprogress(value) {\n this._xhr.onprogress = value;\n }\n /**\n * Returns client's state\n */\n get readyState() {\n return this._xhr.readyState;\n }\n /**\n * Returns client's status\n */\n get status() {\n return this._xhr.status;\n }\n /**\n * Returns client's status as a text\n */\n get statusText() {\n return this._xhr.statusText;\n }\n /**\n * Returns client's response\n */\n get response() {\n return this._xhr.response;\n }\n /**\n * Returns client's response url\n */\n get responseURL() {\n return this._xhr.responseURL;\n }\n /**\n * Returns client's response as text\n */\n get responseText() {\n return this._xhr.responseText;\n }\n /**\n * Gets or sets the expected response type\n */\n get responseType() {\n return this._xhr.responseType;\n }\n set responseType(value) {\n this._xhr.responseType = value;\n }\n /**\n * Gets or sets the timeout value in milliseconds\n */\n get timeout() {\n return this._xhr.timeout;\n }\n set timeout(value) {\n this._xhr.timeout = value;\n }\n addEventListener(type, listener, options) {\n this._xhr.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener, options) {\n this._xhr.removeEventListener(type, listener, options);\n }\n /**\n * Cancels any network activity\n */\n abort() {\n this._xhr.abort();\n }\n /**\n * Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD\n * @param body defines an optional request body\n */\n send(body) {\n if (WebRequest.CustomRequestHeaders) {\n this._injectCustomRequestHeaders();\n }\n this._xhr.send(body);\n }\n /**\n * Sets the request method, request URL\n * @param method defines the method to use (GET, POST, etc..)\n * @param url defines the url to connect with\n */\n open(method, url) {\n for (const update of WebRequest.CustomRequestModifiers) {\n if (this._shouldSkipRequestModifications(url)) {\n return;\n }\n update(this._xhr, url);\n }\n // Clean url\n url = url.replace(\"file:http:\", \"http:\");\n url = url.replace(\"file:https:\", \"https:\");\n this._requestURL = url;\n return this._xhr.open(method, url, true);\n }\n /**\n * Sets the value of a request header.\n * @param name The name of the header whose value is to be set\n * @param value The value to set as the body of the header\n */\n setRequestHeader(name, value) {\n this._xhr.setRequestHeader(name, value);\n }\n /**\n * Get the string containing the text of a particular header's value.\n * @param name The name of the header\n * @returns The string containing the text of the given header name\n */\n getResponseHeader(name) {\n return this._xhr.getResponseHeader(name);\n }\n }\n /**\n * Custom HTTP Request Headers to be sent with XMLHttpRequests\n * i.e. when loading files, where the server/service expects an Authorization header\n */\n WebRequest.CustomRequestHeaders = {};\n /**\n * Add callback functions in this array to update all the requests before they get sent to the network\n */\n WebRequest.CustomRequestModifiers = new Array();\n WebRequest.SkipRequestModificationForBabylonCDN = true;\n\n /**\n * Class used to help managing file picking and drag'n'drop\n * File Storage\n */\n class FilesInputStore {\n }\n /**\n * List of files ready to be loaded\n */\n FilesInputStore.FilesToLoad = {};\n\n /**\n * Class used to define a retry strategy when error happens while loading assets\n */\n class RetryStrategy {\n /**\n * Function used to defines an exponential back off strategy\n * @param maxRetries defines the maximum number of retries (3 by default)\n * @param baseInterval defines the interval between retries\n * @returns the strategy function to use\n */\n static ExponentialBackoff(maxRetries = 3, baseInterval = 500) {\n return (url, request, retryIndex) => {\n if (request.status !== 0 || retryIndex >= maxRetries || url.indexOf(\"file:\") !== -1) {\n return -1;\n }\n return Math.pow(2, retryIndex) * baseInterval;\n };\n }\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * Base error. Due to limitations of typedoc-check and missing documentation\n * in lib.es5.d.ts, cannot extend Error directly for RuntimeError.\n * @ignore\n */\n class BaseError extends Error {\n }\n // See https://stackoverflow.com/questions/12915412/how-do-i-extend-a-host-object-e-g-error-in-typescript\n // and https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work\n // Polyfill for Object.setPrototypeOf if necessary.\n BaseError._setPrototypeOf = Object.setPrototypeOf ||\n ((o, proto) => {\n o.__proto__ = proto;\n return o;\n });\n /* IMP! DO NOT CHANGE THE NUMBERING OF EXISTING ERROR CODES */\n /**\n * Error codes for BaseError\n */\n const ErrorCodes = {\n // Mesh errors 0-999\n /** Invalid or empty mesh vertex positions. */\n MeshInvalidPositionsError: 0,\n // Texture errors 1000-1999\n /** Unsupported texture found. */\n UnsupportedTextureError: 1000,\n // GLTFLoader errors 2000-2999\n /** Unexpected magic number found in GLTF file header. */\n GLTFLoaderUnexpectedMagicError: 2000,\n // SceneLoader errors 3000-3999\n /** SceneLoader generic error code. Ideally wraps the inner exception. */\n SceneLoaderError: 3000,\n // File related errors 4000-4999\n /** Load file error */\n LoadFileError: 4000,\n /** Request file error */\n RequestFileError: 4001,\n /** Read file error */\n ReadFileError: 4002,\n };\n /**\n * Application runtime error\n */\n class RuntimeError extends BaseError {\n /**\n * Creates a new RuntimeError\n * @param message defines the message of the error\n * @param errorCode the error code\n * @param innerError the error that caused the outer error\n */\n constructor(message, errorCode, innerError) {\n super(message);\n this.errorCode = errorCode;\n this.innerError = innerError;\n this.name = \"RuntimeError\";\n BaseError._setPrototypeOf(this, RuntimeError.prototype);\n }\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * Encode a buffer to a base64 string\n * @param buffer defines the buffer to encode\n * @returns the encoded string\n */\n const EncodeArrayBufferToBase64 = (buffer) => {\n const keyStr = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\n let output = \"\";\n let chr1, chr2, chr3, enc1, enc2, enc3, enc4;\n let i = 0;\n const bytes = ArrayBuffer.isView(buffer) ? new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength) : new Uint8Array(buffer);\n while (i < bytes.length) {\n chr1 = bytes[i++];\n chr2 = i < bytes.length ? bytes[i++] : Number.NaN;\n chr3 = i < bytes.length ? bytes[i++] : Number.NaN;\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n }\n else if (isNaN(chr3)) {\n enc4 = 64;\n }\n output += keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);\n }\n return output;\n };\n /**\n * Converts a given base64 string as an ASCII encoded stream of data\n * @param base64Data The base64 encoded string to decode\n * @returns Decoded ASCII string\n */\n const DecodeBase64ToString = (base64Data) => {\n return atob(base64Data);\n };\n /**\n * Converts a given base64 string into an ArrayBuffer of raw byte data\n * @param base64Data The base64 encoded string to decode\n * @returns ArrayBuffer of byte data\n */\n const DecodeBase64ToBinary = (base64Data) => {\n const decodedString = DecodeBase64ToString(base64Data);\n const bufferLength = decodedString.length;\n const bufferView = new Uint8Array(new ArrayBuffer(bufferLength));\n for (let i = 0; i < bufferLength; i++) {\n bufferView[i] = decodedString.charCodeAt(i);\n }\n return bufferView.buffer;\n };\n\n const defaultAttributeKeywordName = \"attribute\";\n const defaultVaryingKeywordName = \"varying\";\n /** @internal */\n class ShaderCodeNode {\n constructor() {\n this.children = [];\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isValid(preprocessors) {\n return true;\n }\n process(preprocessors, options) {\n var _a, _b, _c, _d, _e, _f, _g;\n let result = \"\";\n if (this.line) {\n let value = this.line;\n const processor = options.processor;\n if (processor) {\n // This must be done before other replacements to avoid mistakenly changing something that was already changed.\n if (processor.lineProcessor) {\n value = processor.lineProcessor(value, options.isFragment, options.processingContext);\n }\n const attributeKeyword = (_b = (_a = options.processor) === null || _a === void 0 ? void 0 : _a.attributeKeywordName) !== null && _b !== void 0 ? _b : defaultAttributeKeywordName;\n const varyingKeyword = options.isFragment && ((_c = options.processor) === null || _c === void 0 ? void 0 : _c.varyingFragmentKeywordName)\n ? (_d = options.processor) === null || _d === void 0 ? void 0 : _d.varyingFragmentKeywordName\n : !options.isFragment && ((_e = options.processor) === null || _e === void 0 ? void 0 : _e.varyingVertexKeywordName)\n ? (_f = options.processor) === null || _f === void 0 ? void 0 : _f.varyingVertexKeywordName\n : defaultVaryingKeywordName;\n if (!options.isFragment && processor.attributeProcessor && this.line.startsWith(attributeKeyword)) {\n value = processor.attributeProcessor(this.line, preprocessors, options.processingContext);\n }\n else if (processor.varyingProcessor &&\n (((_g = processor.varyingCheck) === null || _g === void 0 ? void 0 : _g.call(processor, this.line, options.isFragment)) || (!processor.varyingCheck && this.line.startsWith(varyingKeyword)))) {\n value = processor.varyingProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\n }\n else if (processor.uniformProcessor && processor.uniformRegexp && processor.uniformRegexp.test(this.line)) {\n if (!options.lookForClosingBracketForUniformBuffer) {\n value = processor.uniformProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\n }\n }\n else if (processor.uniformBufferProcessor && processor.uniformBufferRegexp && processor.uniformBufferRegexp.test(this.line)) {\n if (!options.lookForClosingBracketForUniformBuffer) {\n value = processor.uniformBufferProcessor(this.line, options.isFragment, options.processingContext);\n options.lookForClosingBracketForUniformBuffer = true;\n }\n }\n else if (processor.textureProcessor && processor.textureRegexp && processor.textureRegexp.test(this.line)) {\n value = processor.textureProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\n }\n else if ((processor.uniformProcessor || processor.uniformBufferProcessor) && this.line.startsWith(\"uniform\") && !options.lookForClosingBracketForUniformBuffer) {\n const regex = /uniform\\s+(?:(?:highp)?|(?:lowp)?)\\s*(\\S+)\\s+(\\S+)\\s*;/;\n if (regex.test(this.line)) {\n // uniform\n if (processor.uniformProcessor) {\n value = processor.uniformProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\n }\n }\n else {\n // Uniform buffer\n if (processor.uniformBufferProcessor) {\n value = processor.uniformBufferProcessor(this.line, options.isFragment, options.processingContext);\n options.lookForClosingBracketForUniformBuffer = true;\n }\n }\n }\n if (options.lookForClosingBracketForUniformBuffer && this.line.indexOf(\"}\") !== -1) {\n options.lookForClosingBracketForUniformBuffer = false;\n if (processor.endOfUniformBufferProcessor) {\n value = processor.endOfUniformBufferProcessor(this.line, options.isFragment, options.processingContext);\n }\n }\n }\n result += value + \"\\n\";\n }\n this.children.forEach((child) => {\n result += child.process(preprocessors, options);\n });\n if (this.additionalDefineKey) {\n preprocessors[this.additionalDefineKey] = this.additionalDefineValue || \"true\";\n }\n return result;\n }\n }\n\n /** @internal */\n class ShaderCodeCursor {\n constructor() {\n this._lines = [];\n }\n get currentLine() {\n return this._lines[this.lineIndex];\n }\n get canRead() {\n return this.lineIndex < this._lines.length - 1;\n }\n set lines(value) {\n this._lines.length = 0;\n for (const line of value) {\n // Skip empty lines\n if (!line || line === \"\\r\") {\n continue;\n }\n // Prevent removing line break in macros.\n if (line[0] === \"#\") {\n this._lines.push(line);\n continue;\n }\n // Do not split single line comments\n const trimmedLine = line.trim();\n if (!trimmedLine) {\n continue;\n }\n if (trimmedLine.startsWith(\"//\")) {\n this._lines.push(line);\n continue;\n }\n // Work with semicolon in the line\n const semicolonIndex = trimmedLine.indexOf(\";\");\n if (semicolonIndex === -1) {\n // No semicolon in the line\n this._lines.push(trimmedLine);\n }\n else if (semicolonIndex === trimmedLine.length - 1) {\n // Single semicolon at the end of the line\n // If trimmedLine == \";\", we must not push, to be backward compatible with the old code!\n if (trimmedLine.length > 1) {\n this._lines.push(trimmedLine);\n }\n }\n else {\n // Semicolon in the middle of the line\n const split = line.split(\";\");\n for (let index = 0; index < split.length; index++) {\n let subLine = split[index];\n if (!subLine) {\n continue;\n }\n subLine = subLine.trim();\n if (!subLine) {\n continue;\n }\n this._lines.push(subLine + (index !== split.length - 1 ? \";\" : \"\"));\n }\n }\n }\n }\n }\n\n /** @internal */\n class ShaderCodeConditionNode extends ShaderCodeNode {\n process(preprocessors, options) {\n for (let index = 0; index < this.children.length; index++) {\n const node = this.children[index];\n if (node.isValid(preprocessors)) {\n return node.process(preprocessors, options);\n }\n }\n return \"\";\n }\n }\n\n /** @internal */\n class ShaderCodeTestNode extends ShaderCodeNode {\n isValid(preprocessors) {\n return this.testExpression.isTrue(preprocessors);\n }\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /** @internal */\n class ShaderDefineExpression {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isTrue(preprocessors) {\n return true;\n }\n static postfixToInfix(postfix) {\n const stack = [];\n for (const c of postfix) {\n if (ShaderDefineExpression._OperatorPriority[c] === undefined) {\n stack.push(c);\n }\n else {\n const v1 = stack[stack.length - 1], v2 = stack[stack.length - 2];\n stack.length -= 2;\n stack.push(`(${v2}${c}${v1})`);\n }\n }\n return stack[stack.length - 1];\n }\n /**\n * Converts an infix expression to a postfix expression.\n *\n * This method is used to transform infix expressions, which are more human-readable,\n * into postfix expressions, also known as Reverse Polish Notation (RPN), that can be\n * evaluated more efficiently by a computer. The conversion is based on the operator\n * priority defined in _OperatorPriority.\n *\n * The function employs a stack-based algorithm for the conversion and caches the result\n * to improve performance. The cache keeps track of each converted expression's access time\n * to manage the cache size and optimize memory usage. When the cache size exceeds a specified\n * limit, the least recently accessed items in the cache are deleted.\n *\n * The cache mechanism is particularly helpful for shader compilation, where the same infix\n * expressions might be encountered repeatedly, hence the caching can speed up the process.\n *\n * @param infix - The infix expression to be converted.\n * @returns The postfix expression as an array of strings.\n */\n static infixToPostfix(infix) {\n // Is infix already in cache\n const cacheItem = ShaderDefineExpression._InfixToPostfixCache.get(infix);\n if (cacheItem) {\n cacheItem.accessTime = Date.now();\n return cacheItem.result;\n }\n // Is infix contain any operator\n if (!infix.includes(\"&&\") && !infix.includes(\"||\") && !infix.includes(\")\") && !infix.includes(\"(\")) {\n return [infix];\n }\n const result = [];\n let stackIdx = -1;\n const pushOperand = () => {\n operand = operand.trim();\n if (operand !== \"\") {\n result.push(operand);\n operand = \"\";\n }\n };\n const push = (s) => {\n if (stackIdx < ShaderDefineExpression._Stack.length - 1) {\n ShaderDefineExpression._Stack[++stackIdx] = s;\n }\n };\n const peek = () => ShaderDefineExpression._Stack[stackIdx];\n const pop = () => (stackIdx === -1 ? \"!!INVALID EXPRESSION!!\" : ShaderDefineExpression._Stack[stackIdx--]);\n let idx = 0, operand = \"\";\n while (idx < infix.length) {\n const c = infix.charAt(idx), token = idx < infix.length - 1 ? infix.substr(idx, 2) : \"\";\n if (c === \"(\") {\n operand = \"\";\n push(c);\n }\n else if (c === \")\") {\n pushOperand();\n while (stackIdx !== -1 && peek() !== \"(\") {\n result.push(pop());\n }\n pop();\n }\n else if (ShaderDefineExpression._OperatorPriority[token] > 1) {\n pushOperand();\n while (stackIdx !== -1 && ShaderDefineExpression._OperatorPriority[peek()] >= ShaderDefineExpression._OperatorPriority[token]) {\n result.push(pop());\n }\n push(token);\n idx++;\n }\n else {\n operand += c;\n }\n idx++;\n }\n pushOperand();\n while (stackIdx !== -1) {\n if (peek() === \"(\") {\n pop();\n }\n else {\n result.push(pop());\n }\n }\n // If the cache is at capacity, clear it before adding a new item\n if (ShaderDefineExpression._InfixToPostfixCache.size >= ShaderDefineExpression.InfixToPostfixCacheLimitSize) {\n ShaderDefineExpression.ClearCache();\n }\n // Add the new item to the cache, including the current time as the last access time\n ShaderDefineExpression._InfixToPostfixCache.set(infix, { result, accessTime: Date.now() });\n return result;\n }\n static ClearCache() {\n // Convert the cache to an array and sort by last access time\n const sortedCache = Array.from(ShaderDefineExpression._InfixToPostfixCache.entries()).sort((a, b) => a[1].accessTime - b[1].accessTime);\n // Remove the least recently accessed half of the cache\n for (let i = 0; i < ShaderDefineExpression.InfixToPostfixCacheCleanupSize; i++) {\n ShaderDefineExpression._InfixToPostfixCache.delete(sortedCache[i][0]);\n }\n }\n }\n /**\n * Cache items count limit for the InfixToPostfix cache.\n * It uses to improve the performance of the shader compilation.\n * For details see PR: https://github.com/BabylonJS/Babylon.js/pull/13936\n */\n ShaderDefineExpression.InfixToPostfixCacheLimitSize = 50000;\n /**\n * When the cache size is exceeded, a cache cleanup will be triggered\n * and the cache will be reduced by the size specified\n * in the InfixToPostfixCacheCleanupSize variable, removing entries\n * that have not been accessed the longest.\n */\n ShaderDefineExpression.InfixToPostfixCacheCleanupSize = 25000;\n ShaderDefineExpression._InfixToPostfixCache = new Map();\n ShaderDefineExpression._OperatorPriority = {\n \")\": 0,\n \"(\": 1,\n \"||\": 2,\n \"&&\": 3,\n };\n ShaderDefineExpression._Stack = [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"];\n\n /** @internal */\n class ShaderDefineIsDefinedOperator extends ShaderDefineExpression {\n constructor(define, not = false) {\n super();\n this.define = define;\n this.not = not;\n }\n isTrue(preprocessors) {\n let condition = preprocessors[this.define] !== undefined;\n if (this.not) {\n condition = !condition;\n }\n return condition;\n }\n }\n\n /** @internal */\n class ShaderDefineOrOperator extends ShaderDefineExpression {\n isTrue(preprocessors) {\n return this.leftOperand.isTrue(preprocessors) || this.rightOperand.isTrue(preprocessors);\n }\n }\n\n /** @internal */\n class ShaderDefineAndOperator extends ShaderDefineExpression {\n isTrue(preprocessors) {\n return this.leftOperand.isTrue(preprocessors) && this.rightOperand.isTrue(preprocessors);\n }\n }\n\n /** @internal */\n class ShaderDefineArithmeticOperator extends ShaderDefineExpression {\n constructor(define, operand, testValue) {\n super();\n this.define = define;\n this.operand = operand;\n this.testValue = testValue;\n }\n isTrue(preprocessors) {\n let value = preprocessors[this.define];\n if (value === undefined) {\n value = this.define;\n }\n let condition = false;\n const left = parseInt(value);\n const right = parseInt(this.testValue);\n switch (this.operand) {\n case \">\":\n condition = left > right;\n break;\n case \"<\":\n condition = left < right;\n break;\n case \"<=\":\n condition = left <= right;\n break;\n case \">=\":\n condition = left >= right;\n break;\n case \"==\":\n condition = left === right;\n break;\n case \"!=\":\n condition = left !== right;\n break;\n }\n return condition;\n }\n }\n\n /**\n * Language of the shader code\n */\n var ShaderLanguage;\n (function (ShaderLanguage) {\n /** language is GLSL (used by WebGL) */\n ShaderLanguage[ShaderLanguage[\"GLSL\"] = 0] = \"GLSL\";\n /** language is WGSL (used by WebGPU) */\n ShaderLanguage[ShaderLanguage[\"WGSL\"] = 1] = \"WGSL\";\n })(ShaderLanguage || (ShaderLanguage = {}));\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const regexSE = /defined\\s*?\\((.+?)\\)/g;\n const regexSERevert = /defined\\s*?\\[(.+?)\\]/g;\n const regexShaderInclude = /#include\\s?<(.+)>(\\((.*)\\))*(\\[(.*)\\])*/g;\n const regexShaderDecl = /__decl__/;\n const regexLightX = /light\\{X\\}.(\\w*)/g;\n const regexX = /\\{X\\}/g;\n const reusableMatches = [];\n /** @internal */\n class ShaderProcessor {\n static Initialize(options) {\n if (options.processor && options.processor.initializeShaders) {\n options.processor.initializeShaders(options.processingContext);\n }\n }\n static Process(sourceCode, options, callback, engine) {\n var _a;\n if ((_a = options.processor) === null || _a === void 0 ? void 0 : _a.preProcessShaderCode) {\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\n }\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\n if (options.processCodeAfterIncludes) {\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\n }\n const migratedCode = this._ProcessShaderConversion(codeWithIncludes, options, engine);\n callback(migratedCode, codeWithIncludes);\n });\n }\n static PreProcess(sourceCode, options, callback, engine) {\n var _a;\n if ((_a = options.processor) === null || _a === void 0 ? void 0 : _a.preProcessShaderCode) {\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\n }\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\n if (options.processCodeAfterIncludes) {\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\n }\n const migratedCode = this._ApplyPreProcessing(codeWithIncludes, options, engine);\n callback(migratedCode, codeWithIncludes);\n });\n }\n static Finalize(vertexCode, fragmentCode, options) {\n if (!options.processor || !options.processor.finalizeShaders) {\n return { vertexCode, fragmentCode };\n }\n return options.processor.finalizeShaders(vertexCode, fragmentCode, options.processingContext);\n }\n static _ProcessPrecision(source, options) {\n var _a;\n if ((_a = options.processor) === null || _a === void 0 ? void 0 : _a.noPrecision) {\n return source;\n }\n const shouldUseHighPrecisionShader = options.shouldUseHighPrecisionShader;\n if (source.indexOf(\"precision highp float\") === -1) {\n if (!shouldUseHighPrecisionShader) {\n source = \"precision mediump float;\\n\" + source;\n }\n else {\n source = \"precision highp float;\\n\" + source;\n }\n }\n else {\n if (!shouldUseHighPrecisionShader) {\n // Moving highp to mediump\n source = source.replace(\"precision highp float\", \"precision mediump float\");\n }\n }\n return source;\n }\n static _ExtractOperation(expression) {\n const regex = /defined\\((.+)\\)/;\n const match = regex.exec(expression);\n if (match && match.length) {\n return new ShaderDefineIsDefinedOperator(match[1].trim(), expression[0] === \"!\");\n }\n const operators = [\"==\", \"!=\", \">=\", \"<=\", \"<\", \">\"];\n let operator = \"\";\n let indexOperator = 0;\n for (operator of operators) {\n indexOperator = expression.indexOf(operator);\n if (indexOperator > -1) {\n break;\n }\n }\n if (indexOperator === -1) {\n return new ShaderDefineIsDefinedOperator(expression);\n }\n const define = expression.substring(0, indexOperator).trim();\n const value = expression.substring(indexOperator + operator.length).trim();\n return new ShaderDefineArithmeticOperator(define, operator, value);\n }\n static _BuildSubExpression(expression) {\n expression = expression.replace(regexSE, \"defined[$1]\");\n const postfix = ShaderDefineExpression.infixToPostfix(expression);\n const stack = [];\n for (const c of postfix) {\n if (c !== \"||\" && c !== \"&&\") {\n stack.push(c);\n }\n else if (stack.length >= 2) {\n let v1 = stack[stack.length - 1], v2 = stack[stack.length - 2];\n stack.length -= 2;\n const operator = c == \"&&\" ? new ShaderDefineAndOperator() : new ShaderDefineOrOperator();\n if (typeof v1 === \"string\") {\n v1 = v1.replace(regexSERevert, \"defined($1)\");\n }\n if (typeof v2 === \"string\") {\n v2 = v2.replace(regexSERevert, \"defined($1)\");\n }\n operator.leftOperand = typeof v2 === \"string\" ? this._ExtractOperation(v2) : v2;\n operator.rightOperand = typeof v1 === \"string\" ? this._ExtractOperation(v1) : v1;\n stack.push(operator);\n }\n }\n let result = stack[stack.length - 1];\n if (typeof result === \"string\") {\n result = result.replace(regexSERevert, \"defined($1)\");\n }\n // note: stack.length !== 1 if there was an error in the parsing\n return typeof result === \"string\" ? this._ExtractOperation(result) : result;\n }\n static _BuildExpression(line, start) {\n const node = new ShaderCodeTestNode();\n const command = line.substring(0, start);\n let expression = line.substring(start);\n expression = expression.substring(0, (expression.indexOf(\"//\") + 1 || expression.length + 1) - 1).trim();\n if (command === \"#ifdef\") {\n node.testExpression = new ShaderDefineIsDefinedOperator(expression);\n }\n else if (command === \"#ifndef\") {\n node.testExpression = new ShaderDefineIsDefinedOperator(expression, true);\n }\n else {\n node.testExpression = this._BuildSubExpression(expression);\n }\n return node;\n }\n static _MoveCursorWithinIf(cursor, rootNode, ifNode) {\n let line = cursor.currentLine;\n while (this._MoveCursor(cursor, ifNode)) {\n line = cursor.currentLine;\n const first5 = line.substring(0, 5).toLowerCase();\n if (first5 === \"#else\") {\n const elseNode = new ShaderCodeNode();\n rootNode.children.push(elseNode);\n this._MoveCursor(cursor, elseNode);\n return;\n }\n else if (first5 === \"#elif\") {\n const elifNode = this._BuildExpression(line, 5);\n rootNode.children.push(elifNode);\n ifNode = elifNode;\n }\n }\n }\n static _MoveCursor(cursor, rootNode) {\n while (cursor.canRead) {\n cursor.lineIndex++;\n const line = cursor.currentLine;\n if (line.indexOf(\"#\") >= 0) {\n const matches = ShaderProcessor._MoveCursorRegex.exec(line);\n if (matches && matches.length) {\n const keyword = matches[0];\n switch (keyword) {\n case \"#ifdef\": {\n const newRootNode = new ShaderCodeConditionNode();\n rootNode.children.push(newRootNode);\n const ifNode = this._BuildExpression(line, 6);\n newRootNode.children.push(ifNode);\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\n break;\n }\n case \"#else\":\n case \"#elif\":\n return true;\n case \"#endif\":\n return false;\n case \"#ifndef\": {\n const newRootNode = new ShaderCodeConditionNode();\n rootNode.children.push(newRootNode);\n const ifNode = this._BuildExpression(line, 7);\n newRootNode.children.push(ifNode);\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\n break;\n }\n case \"#if\": {\n const newRootNode = new ShaderCodeConditionNode();\n const ifNode = this._BuildExpression(line, 3);\n rootNode.children.push(newRootNode);\n newRootNode.children.push(ifNode);\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\n break;\n }\n }\n continue;\n }\n }\n const newNode = new ShaderCodeNode();\n newNode.line = line;\n rootNode.children.push(newNode);\n // Detect additional defines\n if (line[0] === \"#\" && line[1] === \"d\") {\n const split = line.replace(\";\", \"\").split(\" \");\n newNode.additionalDefineKey = split[1];\n if (split.length === 3) {\n newNode.additionalDefineValue = split[2];\n }\n }\n }\n return false;\n }\n static _EvaluatePreProcessors(sourceCode, preprocessors, options) {\n const rootNode = new ShaderCodeNode();\n const cursor = new ShaderCodeCursor();\n cursor.lineIndex = -1;\n cursor.lines = sourceCode.split(\"\\n\");\n // Decompose (We keep it in 2 steps so it is easier to maintain and perf hit is insignificant)\n this._MoveCursor(cursor, rootNode);\n // Recompose\n return rootNode.process(preprocessors, options);\n }\n static _PreparePreProcessors(options, engine) {\n var _a;\n const defines = options.defines;\n const preprocessors = {};\n for (const define of defines) {\n const keyValue = define.replace(\"#define\", \"\").replace(\";\", \"\").trim();\n const split = keyValue.split(\" \");\n preprocessors[split[0]] = split.length > 1 ? split[1] : \"\";\n }\n if (((_a = options.processor) === null || _a === void 0 ? void 0 : _a.shaderLanguage) === ShaderLanguage.GLSL) {\n preprocessors[\"GL_ES\"] = \"true\";\n }\n preprocessors[\"__VERSION__\"] = options.version;\n preprocessors[options.platformName] = \"true\";\n engine._getGlobalDefines(preprocessors);\n return preprocessors;\n }\n static _ProcessShaderConversion(sourceCode, options, engine) {\n let preparedSourceCode = this._ProcessPrecision(sourceCode, options);\n if (!options.processor) {\n return preparedSourceCode;\n }\n // Already converted\n if (options.processor.shaderLanguage === ShaderLanguage.GLSL && preparedSourceCode.indexOf(\"#version 3\") !== -1) {\n preparedSourceCode = preparedSourceCode.replace(\"#version 300 es\", \"\");\n if (!options.processor.parseGLES3) {\n return preparedSourceCode;\n }\n }\n const defines = options.defines;\n const preprocessors = this._PreparePreProcessors(options, engine);\n // General pre processing\n if (options.processor.preProcessor) {\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\n }\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\n // Post processing\n if (options.processor.postProcessor) {\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\n }\n // Inline functions tagged with #define inline\n if (engine._features.needShaderCodeInlining) {\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\n }\n return preparedSourceCode;\n }\n static _ApplyPreProcessing(sourceCode, options, engine) {\n var _a, _b;\n let preparedSourceCode = sourceCode;\n const defines = options.defines;\n const preprocessors = this._PreparePreProcessors(options, engine);\n // General pre processing\n if ((_a = options.processor) === null || _a === void 0 ? void 0 : _a.preProcessor) {\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\n }\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\n // Post processing\n if ((_b = options.processor) === null || _b === void 0 ? void 0 : _b.postProcessor) {\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\n }\n // Inline functions tagged with #define inline\n if (engine._features.needShaderCodeInlining) {\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\n }\n return preparedSourceCode;\n }\n /** @internal */\n static _ProcessIncludes(sourceCode, options, callback) {\n reusableMatches.length = 0;\n let match;\n // stay back-compat to the old matchAll syntax\n while ((match = regexShaderInclude.exec(sourceCode)) !== null) {\n reusableMatches.push(match);\n }\n let returnValue = String(sourceCode);\n let parts = [sourceCode];\n let keepProcessing = false;\n for (const match of reusableMatches) {\n let includeFile = match[1];\n // Uniform declaration\n if (includeFile.indexOf(\"__decl__\") !== -1) {\n includeFile = includeFile.replace(regexShaderDecl, \"\");\n if (options.supportsUniformBuffers) {\n includeFile = includeFile.replace(\"Vertex\", \"Ubo\").replace(\"Fragment\", \"Ubo\");\n }\n includeFile = includeFile + \"Declaration\";\n }\n if (options.includesShadersStore[includeFile]) {\n // Substitution\n let includeContent = options.includesShadersStore[includeFile];\n if (match[2]) {\n const splits = match[3].split(\",\");\n for (let index = 0; index < splits.length; index += 2) {\n const source = new RegExp(splits[index], \"g\");\n const dest = splits[index + 1];\n includeContent = includeContent.replace(source, dest);\n }\n }\n if (match[4]) {\n const indexString = match[5];\n if (indexString.indexOf(\"..\") !== -1) {\n const indexSplits = indexString.split(\"..\");\n const minIndex = parseInt(indexSplits[0]);\n let maxIndex = parseInt(indexSplits[1]);\n let sourceIncludeContent = includeContent.slice(0);\n includeContent = \"\";\n if (isNaN(maxIndex)) {\n maxIndex = options.indexParameters[indexSplits[1]];\n }\n for (let i = minIndex; i < maxIndex; i++) {\n if (!options.supportsUniformBuffers) {\n // Ubo replacement\n sourceIncludeContent = sourceIncludeContent.replace(regexLightX, (str, p1) => {\n return p1 + \"{X}\";\n });\n }\n includeContent += sourceIncludeContent.replace(regexX, i.toString()) + \"\\n\";\n }\n }\n else {\n if (!options.supportsUniformBuffers) {\n // Ubo replacement\n includeContent = includeContent.replace(regexLightX, (str, p1) => {\n return p1 + \"{X}\";\n });\n }\n includeContent = includeContent.replace(regexX, indexString);\n }\n }\n // Replace\n // Split all parts on match[0] and intersperse the parts with the include content\n const newParts = [];\n for (const part of parts) {\n const splitPart = part.split(match[0]);\n for (let i = 0; i < splitPart.length - 1; i++) {\n newParts.push(splitPart[i]);\n newParts.push(includeContent);\n }\n newParts.push(splitPart[splitPart.length - 1]);\n }\n parts = newParts;\n keepProcessing = keepProcessing || includeContent.indexOf(\"#include<\") >= 0 || includeContent.indexOf(\"#include <\") >= 0;\n }\n else {\n const includeShaderUrl = options.shadersRepository + \"ShadersInclude/\" + includeFile + \".fx\";\n ShaderProcessor._FileToolsLoadFile(includeShaderUrl, (fileContent) => {\n options.includesShadersStore[includeFile] = fileContent;\n this._ProcessIncludes(parts.join(\"\"), options, callback);\n });\n return;\n }\n }\n reusableMatches.length = 0;\n returnValue = parts.join(\"\");\n if (keepProcessing) {\n this._ProcessIncludes(returnValue.toString(), options, callback);\n }\n else {\n callback(returnValue);\n }\n }\n /**\n * Loads a file from a url\n * @param url url to load\n * @param onSuccess callback called when the file successfully loads\n * @param onProgress callback called while file is loading (if the server supports this mode)\n * @param offlineProvider defines the offline provider for caching\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\n * @param onError callback called when the file fails to load\n * @returns a file request object\n * @internal\n */\n static _FileToolsLoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError) {\n throw _WarnImport(\"FileTools\");\n }\n }\n ShaderProcessor._MoveCursorRegex = /(#ifdef)|(#else)|(#elif)|(#endif)|(#ifndef)|(#if)/;\n\n /**\n * Defines the shader related stores and directory\n */\n class ShaderStore {\n /**\n * Gets the shaders repository path for a given shader language\n * @param shaderLanguage the shader language\n * @returns the path to the shaders repository\n */\n static GetShadersRepository(shaderLanguage = ShaderLanguage.GLSL) {\n return shaderLanguage === ShaderLanguage.GLSL ? ShaderStore.ShadersRepository : ShaderStore.ShadersRepositoryWGSL;\n }\n /**\n * Gets the shaders store of a given shader language\n * @param shaderLanguage the shader language\n * @returns the shaders store\n */\n static GetShadersStore(shaderLanguage = ShaderLanguage.GLSL) {\n return shaderLanguage === ShaderLanguage.GLSL ? ShaderStore.ShadersStore : ShaderStore.ShadersStoreWGSL;\n }\n /**\n * Gets the include shaders store of a given shader language\n * @param shaderLanguage the shader language\n * @returns the include shaders store\n */\n static GetIncludesShadersStore(shaderLanguage = ShaderLanguage.GLSL) {\n return shaderLanguage === ShaderLanguage.GLSL ? ShaderStore.IncludesShadersStore : ShaderStore.IncludesShadersStoreWGSL;\n }\n }\n /**\n * Gets or sets the relative url used to load shaders if using the engine in non-minified mode\n */\n ShaderStore.ShadersRepository = \"src/Shaders/\";\n /**\n * Store of each shader (The can be looked up using effect.key)\n */\n ShaderStore.ShadersStore = {};\n /**\n * Store of each included file for a shader (The can be looked up using effect.key)\n */\n ShaderStore.IncludesShadersStore = {};\n /**\n * Gets or sets the relative url used to load shaders (WGSL) if using the engine in non-minified mode\n */\n ShaderStore.ShadersRepositoryWGSL = \"src/ShadersWGSL/\";\n /**\n * Store of each shader (WGSL)\n */\n ShaderStore.ShadersStoreWGSL = {};\n /**\n * Store of each included file for a shader (WGSL)\n */\n ShaderStore.IncludesShadersStoreWGSL = {};\n\n /**\n * Effect containing vertex and fragment shader that can be executed on an object.\n */\n class Effect {\n /**\n * Gets or sets the relative url used to load shaders if using the engine in non-minified mode\n */\n static get ShadersRepository() {\n return ShaderStore.ShadersRepository;\n }\n static set ShadersRepository(repo) {\n ShaderStore.ShadersRepository = repo;\n }\n /**\n * Observable that will be called when effect is bound.\n */\n get onBindObservable() {\n if (!this._onBindObservable) {\n this._onBindObservable = new Observable$1();\n }\n return this._onBindObservable;\n }\n /**\n * Instantiates an effect.\n * An effect can be used to create/manage/execute vertex and fragment shaders.\n * @param baseName Name of the effect.\n * @param attributesNamesOrOptions List of attribute names that will be passed to the shader or set of all options to create the effect.\n * @param uniformsNamesOrEngine List of uniform variable names that will be passed to the shader or the engine that will be used to render effect.\n * @param samplers List of sampler variables that will be passed to the shader.\n * @param engine Engine to be used to render the effect\n * @param defines Define statements to be added to the shader.\n * @param fallbacks Possible fallbacks for this effect to improve performance when needed.\n * @param onCompiled Callback that will be called when the shader is compiled.\n * @param onError Callback that will be called if an error occurs during shader compilation.\n * @param indexParameters Parameters to be used with Babylons include syntax to iterate over an array (eg. {lights: 10})\n * @param key Effect Key identifying uniquely compiled shader variants\n * @param shaderLanguage the language the shader is written in (default: GLSL)\n */\n constructor(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers = null, engine, defines = null, fallbacks = null, onCompiled = null, onError = null, indexParameters, key = \"\", shaderLanguage = ShaderLanguage.GLSL) {\n var _a, _b, _c;\n /**\n * Name of the effect.\n */\n this.name = null;\n /**\n * String container all the define statements that should be set on the shader.\n */\n this.defines = \"\";\n /**\n * Callback that will be called when the shader is compiled.\n */\n this.onCompiled = null;\n /**\n * Callback that will be called if an error occurs during shader compilation.\n */\n this.onError = null;\n /**\n * Callback that will be called when effect is bound.\n */\n this.onBind = null;\n /**\n * Unique ID of the effect.\n */\n this.uniqueId = 0;\n /**\n * Observable that will be called when the shader is compiled.\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\n */\n this.onCompileObservable = new Observable$1();\n /**\n * Observable that will be called if an error occurs during shader compilation.\n */\n this.onErrorObservable = new Observable$1();\n /** @internal */\n this._onBindObservable = null;\n /**\n * @internal\n * Specifies if the effect was previously ready\n */\n this._wasPreviouslyReady = false;\n /**\n * @internal\n * Forces the code from bindForSubMesh to be fully run the next time it is called\n * It is used in frozen mode to make sure the effect is properly rebound when a new effect is created\n */\n this._forceRebindOnNextCall = false;\n /**\n * @internal\n * Specifies if the effect was previously using instances\n */\n this._wasPreviouslyUsingInstances = null;\n this._isDisposed = false;\n /** @internal */\n this._bonesComputationForcedToCPU = false;\n /** @internal */\n this._uniformBuffersNames = {};\n /** @internal */\n this._multiTarget = false;\n this._samplers = {};\n this._isReady = false;\n this._compilationError = \"\";\n this._allFallbacksProcessed = false;\n this._uniforms = {};\n /**\n * Key for the effect.\n * @internal\n */\n this._key = \"\";\n this._fallbacks = null;\n this._vertexSourceCodeOverride = \"\";\n this._fragmentSourceCodeOverride = \"\";\n this._transformFeedbackVaryings = null;\n /**\n * Compiled shader to webGL program.\n * @internal\n */\n this._pipelineContext = null;\n /** @internal */\n this._vertexSourceCode = \"\";\n /** @internal */\n this._fragmentSourceCode = \"\";\n /** @internal */\n this._vertexSourceCodeBeforeMigration = \"\";\n /** @internal */\n this._fragmentSourceCodeBeforeMigration = \"\";\n /** @internal */\n this._rawVertexSourceCode = \"\";\n /** @internal */\n this._rawFragmentSourceCode = \"\";\n this.name = baseName;\n this._key = key;\n let processCodeAfterIncludes = undefined;\n let processFinalCode = null;\n if (attributesNamesOrOptions.attributes) {\n const options = attributesNamesOrOptions;\n this._engine = uniformsNamesOrEngine;\n this._attributesNames = options.attributes;\n this._uniformsNames = options.uniformsNames.concat(options.samplers);\n this._samplerList = options.samplers.slice();\n this.defines = options.defines;\n this.onError = options.onError;\n this.onCompiled = options.onCompiled;\n this._fallbacks = options.fallbacks;\n this._indexParameters = options.indexParameters;\n this._transformFeedbackVaryings = options.transformFeedbackVaryings || null;\n this._multiTarget = !!options.multiTarget;\n this._shaderLanguage = (_a = options.shaderLanguage) !== null && _a !== void 0 ? _a : ShaderLanguage.GLSL;\n if (options.uniformBuffersNames) {\n this._uniformBuffersNamesList = options.uniformBuffersNames.slice();\n for (let i = 0; i < options.uniformBuffersNames.length; i++) {\n this._uniformBuffersNames[options.uniformBuffersNames[i]] = i;\n }\n }\n processFinalCode = (_b = options.processFinalCode) !== null && _b !== void 0 ? _b : null;\n processCodeAfterIncludes = (_c = options.processCodeAfterIncludes) !== null && _c !== void 0 ? _c : undefined;\n }\n else {\n this._engine = engine;\n this.defines = defines == null ? \"\" : defines;\n this._uniformsNames = uniformsNamesOrEngine.concat(samplers);\n this._samplerList = samplers ? samplers.slice() : [];\n this._attributesNames = attributesNamesOrOptions;\n this._uniformBuffersNamesList = [];\n this._shaderLanguage = shaderLanguage;\n this.onError = onError;\n this.onCompiled = onCompiled;\n this._indexParameters = indexParameters;\n this._fallbacks = fallbacks;\n }\n this._attributeLocationByName = {};\n this.uniqueId = Effect._UniqueIdSeed++;\n let vertexSource;\n let fragmentSource;\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\n if (baseName.vertexSource) {\n vertexSource = \"source:\" + baseName.vertexSource;\n }\n else if (baseName.vertexElement) {\n vertexSource = hostDocument ? hostDocument.getElementById(baseName.vertexElement) : null;\n if (!vertexSource) {\n vertexSource = baseName.vertexElement;\n }\n }\n else {\n vertexSource = baseName.vertex || baseName;\n }\n if (baseName.fragmentSource) {\n fragmentSource = \"source:\" + baseName.fragmentSource;\n }\n else if (baseName.fragmentElement) {\n fragmentSource = hostDocument ? hostDocument.getElementById(baseName.fragmentElement) : null;\n if (!fragmentSource) {\n fragmentSource = baseName.fragmentElement;\n }\n }\n else {\n fragmentSource = baseName.fragment || baseName;\n }\n this._processingContext = this._engine._getShaderProcessingContext(this._shaderLanguage);\n let processorOptions = {\n defines: this.defines.split(\"\\n\"),\n indexParameters: this._indexParameters,\n isFragment: false,\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\n processor: this._engine._getShaderProcessor(this._shaderLanguage),\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\n shadersRepository: ShaderStore.GetShadersRepository(this._shaderLanguage),\n includesShadersStore: ShaderStore.GetIncludesShadersStore(this._shaderLanguage),\n version: (this._engine.version * 100).toString(),\n platformName: this._engine.shaderPlatformName,\n processingContext: this._processingContext,\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\n processCodeAfterIncludes,\n };\n const shaderCodes = [undefined, undefined];\n const shadersLoaded = () => {\n if (shaderCodes[0] && shaderCodes[1]) {\n processorOptions.isFragment = true;\n const [migratedVertexCode, fragmentCode] = shaderCodes;\n ShaderProcessor.Process(fragmentCode, processorOptions, (migratedFragmentCode, codeBeforeMigration) => {\n this._fragmentSourceCodeBeforeMigration = codeBeforeMigration;\n if (processFinalCode) {\n migratedFragmentCode = processFinalCode(\"fragment\", migratedFragmentCode);\n }\n const finalShaders = ShaderProcessor.Finalize(migratedVertexCode, migratedFragmentCode, processorOptions);\n processorOptions = null;\n this._useFinalCode(finalShaders.vertexCode, finalShaders.fragmentCode, baseName);\n }, this._engine);\n }\n };\n this._loadShader(vertexSource, \"Vertex\", \"\", (vertexCode) => {\n ShaderProcessor.Initialize(processorOptions);\n ShaderProcessor.Process(vertexCode, processorOptions, (migratedVertexCode, codeBeforeMigration) => {\n this._rawVertexSourceCode = vertexCode;\n this._vertexSourceCodeBeforeMigration = codeBeforeMigration;\n if (processFinalCode) {\n migratedVertexCode = processFinalCode(\"vertex\", migratedVertexCode);\n }\n shaderCodes[0] = migratedVertexCode;\n shadersLoaded();\n }, this._engine);\n });\n this._loadShader(fragmentSource, \"Fragment\", \"Pixel\", (fragmentCode) => {\n this._rawFragmentSourceCode = fragmentCode;\n shaderCodes[1] = fragmentCode;\n shadersLoaded();\n });\n }\n _useFinalCode(migratedVertexCode, migratedFragmentCode, baseName) {\n if (baseName) {\n const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;\n this._vertexSourceCode = (this._shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME vertex:\" + vertex + \"\\n\" + migratedVertexCode;\n this._fragmentSourceCode = (this._shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME fragment:\" + fragment + \"\\n\" + migratedFragmentCode;\n }\n else {\n this._vertexSourceCode = migratedVertexCode;\n this._fragmentSourceCode = migratedFragmentCode;\n }\n this._prepareEffect();\n }\n /**\n * Unique key for this effect\n */\n get key() {\n return this._key;\n }\n /**\n * If the effect has been compiled and prepared.\n * @returns if the effect is compiled and prepared.\n */\n isReady() {\n try {\n return this._isReadyInternal();\n }\n catch (_a) {\n return false;\n }\n }\n _isReadyInternal() {\n if (this._isReady) {\n return true;\n }\n if (this._pipelineContext) {\n return this._pipelineContext.isReady;\n }\n return false;\n }\n /**\n * The engine the effect was initialized with.\n * @returns the engine.\n */\n getEngine() {\n return this._engine;\n }\n /**\n * The pipeline context for this effect\n * @returns the associated pipeline context\n */\n getPipelineContext() {\n return this._pipelineContext;\n }\n /**\n * The set of names of attribute variables for the shader.\n * @returns An array of attribute names.\n */\n getAttributesNames() {\n return this._attributesNames;\n }\n /**\n * Returns the attribute at the given index.\n * @param index The index of the attribute.\n * @returns The location of the attribute.\n */\n getAttributeLocation(index) {\n return this._attributes[index];\n }\n /**\n * Returns the attribute based on the name of the variable.\n * @param name of the attribute to look up.\n * @returns the attribute location.\n */\n getAttributeLocationByName(name) {\n return this._attributeLocationByName[name];\n }\n /**\n * The number of attributes.\n * @returns the number of attributes.\n */\n getAttributesCount() {\n return this._attributes.length;\n }\n /**\n * Gets the index of a uniform variable.\n * @param uniformName of the uniform to look up.\n * @returns the index.\n */\n getUniformIndex(uniformName) {\n return this._uniformsNames.indexOf(uniformName);\n }\n /**\n * Returns the attribute based on the name of the variable.\n * @param uniformName of the uniform to look up.\n * @returns the location of the uniform.\n */\n getUniform(uniformName) {\n return this._uniforms[uniformName];\n }\n /**\n * Returns an array of sampler variable names\n * @returns The array of sampler variable names.\n */\n getSamplers() {\n return this._samplerList;\n }\n /**\n * Returns an array of uniform variable names\n * @returns The array of uniform variable names.\n */\n getUniformNames() {\n return this._uniformsNames;\n }\n /**\n * Returns an array of uniform buffer variable names\n * @returns The array of uniform buffer variable names.\n */\n getUniformBuffersNames() {\n return this._uniformBuffersNamesList;\n }\n /**\n * Returns the index parameters used to create the effect\n * @returns The index parameters object\n */\n getIndexParameters() {\n return this._indexParameters;\n }\n /**\n * The error from the last compilation.\n * @returns the error string.\n */\n getCompilationError() {\n return this._compilationError;\n }\n /**\n * Gets a boolean indicating that all fallbacks were used during compilation\n * @returns true if all fallbacks were used\n */\n allFallbacksProcessed() {\n return this._allFallbacksProcessed;\n }\n /**\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\n * @param func The callback to be used.\n */\n executeWhenCompiled(func) {\n if (this.isReady()) {\n func(this);\n return;\n }\n this.onCompileObservable.add((effect) => {\n func(effect);\n });\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\n setTimeout(() => {\n this._checkIsReady(null);\n }, 16);\n }\n }\n _checkIsReady(previousPipelineContext) {\n try {\n if (this._isReadyInternal()) {\n return;\n }\n }\n catch (e) {\n this._processCompilationErrors(e, previousPipelineContext);\n return;\n }\n if (this._isDisposed) {\n return;\n }\n setTimeout(() => {\n this._checkIsReady(previousPipelineContext);\n }, 16);\n }\n _loadShader(shader, key, optionalKey, callback) {\n if (typeof HTMLElement !== \"undefined\") {\n // DOM element ?\n if (shader instanceof HTMLElement) {\n const shaderCode = GetDOMTextContent(shader);\n callback(shaderCode);\n return;\n }\n }\n // Direct source ?\n if (shader.substr(0, 7) === \"source:\") {\n callback(shader.substr(7));\n return;\n }\n // Base64 encoded ?\n if (shader.substr(0, 7) === \"base64:\") {\n const shaderBinary = window.atob(shader.substr(7));\n callback(shaderBinary);\n return;\n }\n const shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\n // Is in local store ?\n if (shaderStore[shader + key + \"Shader\"]) {\n callback(shaderStore[shader + key + \"Shader\"]);\n return;\n }\n if (optionalKey && shaderStore[shader + optionalKey + \"Shader\"]) {\n callback(shaderStore[shader + optionalKey + \"Shader\"]);\n return;\n }\n let shaderUrl;\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\n shaderUrl = shader;\n }\n else {\n shaderUrl = ShaderStore.GetShadersRepository(this._shaderLanguage) + shader;\n }\n // Vertex shader\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\n }\n /**\n * Gets the vertex shader source code of this effect\n * This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)\n */\n get vertexSourceCode() {\n var _a, _b;\n return this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride\n ? this._vertexSourceCodeOverride\n : (_b = (_a = this._pipelineContext) === null || _a === void 0 ? void 0 : _a._getVertexShaderCode()) !== null && _b !== void 0 ? _b : this._vertexSourceCode;\n }\n /**\n * Gets the fragment shader source code of this effect\n * This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)\n */\n get fragmentSourceCode() {\n var _a, _b;\n return this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride\n ? this._fragmentSourceCodeOverride\n : (_b = (_a = this._pipelineContext) === null || _a === void 0 ? void 0 : _a._getFragmentShaderCode()) !== null && _b !== void 0 ? _b : this._fragmentSourceCode;\n }\n /**\n * Gets the vertex shader source code before migration.\n * This is the source code after the include directives have been replaced by their contents but before the code is migrated, i.e. before ShaderProcess._ProcessShaderConversion is executed.\n * This method is, among other things, responsible for parsing #if/#define directives as well as converting GLES2 syntax to GLES3 (in the case of WebGL).\n */\n get vertexSourceCodeBeforeMigration() {\n return this._vertexSourceCodeBeforeMigration;\n }\n /**\n * Gets the fragment shader source code before migration.\n * This is the source code after the include directives have been replaced by their contents but before the code is migrated, i.e. before ShaderProcess._ProcessShaderConversion is executed.\n * This method is, among other things, responsible for parsing #if/#define directives as well as converting GLES2 syntax to GLES3 (in the case of WebGL).\n */\n get fragmentSourceCodeBeforeMigration() {\n return this._fragmentSourceCodeBeforeMigration;\n }\n /**\n * Gets the vertex shader source code before it has been modified by any processing\n */\n get rawVertexSourceCode() {\n return this._rawVertexSourceCode;\n }\n /**\n * Gets the fragment shader source code before it has been modified by any processing\n */\n get rawFragmentSourceCode() {\n return this._rawFragmentSourceCode;\n }\n /**\n * Recompiles the webGL program\n * @param vertexSourceCode The source code for the vertex shader.\n * @param fragmentSourceCode The source code for the fragment shader.\n * @param onCompiled Callback called when completed.\n * @param onError Callback called on error.\n * @internal\n */\n _rebuildProgram(vertexSourceCode, fragmentSourceCode, onCompiled, onError) {\n this._isReady = false;\n this._vertexSourceCodeOverride = vertexSourceCode;\n this._fragmentSourceCodeOverride = fragmentSourceCode;\n this.onError = (effect, error) => {\n if (onError) {\n onError(error);\n }\n };\n this.onCompiled = () => {\n const scenes = this.getEngine().scenes;\n if (scenes) {\n for (let i = 0; i < scenes.length; i++) {\n scenes[i].markAllMaterialsAsDirty(63);\n }\n }\n this._pipelineContext._handlesSpectorRebuildCallback(onCompiled);\n };\n this._fallbacks = null;\n this._prepareEffect();\n }\n /**\n * Prepares the effect\n * @internal\n */\n _prepareEffect() {\n const attributesNames = this._attributesNames;\n const defines = this.defines;\n const previousPipelineContext = this._pipelineContext;\n this._isReady = false;\n try {\n const engine = this._engine;\n this._pipelineContext = engine.createPipelineContext(this._processingContext);\n this._pipelineContext._name = this._key;\n const rebuildRebind = this._rebuildProgram.bind(this);\n if (this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride) {\n engine._preparePipelineContext(this._pipelineContext, this._vertexSourceCodeOverride, this._fragmentSourceCodeOverride, true, this._rawVertexSourceCode, this._rawFragmentSourceCode, rebuildRebind, null, this._transformFeedbackVaryings, this._key);\n }\n else {\n engine._preparePipelineContext(this._pipelineContext, this._vertexSourceCode, this._fragmentSourceCode, false, this._rawVertexSourceCode, this._rawFragmentSourceCode, rebuildRebind, defines, this._transformFeedbackVaryings, this._key);\n }\n engine._executeWhenRenderingStateIsCompiled(this._pipelineContext, () => {\n this._attributes = [];\n this._pipelineContext._fillEffectInformation(this, this._uniformBuffersNames, this._uniformsNames, this._uniforms, this._samplerList, this._samplers, attributesNames, this._attributes);\n // Caches attribute locations.\n if (attributesNames) {\n for (let i = 0; i < attributesNames.length; i++) {\n const name = attributesNames[i];\n this._attributeLocationByName[name] = this._attributes[i];\n }\n }\n engine.bindSamplers(this);\n this._compilationError = \"\";\n this._isReady = true;\n if (this.onCompiled) {\n this.onCompiled(this);\n }\n this.onCompileObservable.notifyObservers(this);\n this.onCompileObservable.clear();\n // Unbind mesh reference in fallbacks\n if (this._fallbacks) {\n this._fallbacks.unBindMesh();\n }\n if (previousPipelineContext) {\n this.getEngine()._deletePipelineContext(previousPipelineContext);\n }\n });\n if (this._pipelineContext.isAsync) {\n this._checkIsReady(previousPipelineContext);\n }\n }\n catch (e) {\n this._processCompilationErrors(e, previousPipelineContext);\n }\n }\n _getShaderCodeAndErrorLine(code, error, isFragment) {\n const regexp = isFragment ? /FRAGMENT SHADER ERROR: 0:(\\d+?):/ : /VERTEX SHADER ERROR: 0:(\\d+?):/;\n let errorLine = null;\n if (error && code) {\n const res = error.match(regexp);\n if (res && res.length === 2) {\n const lineNumber = parseInt(res[1]);\n const lines = code.split(\"\\n\", -1);\n if (lines.length >= lineNumber) {\n errorLine = `Offending line [${lineNumber}] in ${isFragment ? \"fragment\" : \"vertex\"} code: ${lines[lineNumber - 1]}`;\n }\n }\n }\n return [code, errorLine];\n }\n _processCompilationErrors(e, previousPipelineContext = null) {\n var _a, _b, _c;\n this._compilationError = e.message;\n const attributesNames = this._attributesNames;\n const fallbacks = this._fallbacks;\n // Let's go through fallbacks then\n Logger.Error(\"Unable to compile effect:\");\n Logger.Error(\"Uniforms: \" +\n this._uniformsNames.map(function (uniform) {\n return \" \" + uniform;\n }));\n Logger.Error(\"Attributes: \" +\n attributesNames.map(function (attribute) {\n return \" \" + attribute;\n }));\n Logger.Error(\"Defines:\\n\" + this.defines);\n if (Effect.LogShaderCodeOnCompilationError) {\n let lineErrorVertex = null, lineErrorFragment = null, code = null;\n if ((_a = this._pipelineContext) === null || _a === void 0 ? void 0 : _a._getVertexShaderCode()) {\n [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(this._pipelineContext._getVertexShaderCode(), this._compilationError, false);\n if (code) {\n Logger.Error(\"Vertex code:\");\n Logger.Error(code);\n }\n }\n if ((_b = this._pipelineContext) === null || _b === void 0 ? void 0 : _b._getFragmentShaderCode()) {\n [code, lineErrorFragment] = this._getShaderCodeAndErrorLine((_c = this._pipelineContext) === null || _c === void 0 ? void 0 : _c._getFragmentShaderCode(), this._compilationError, true);\n if (code) {\n Logger.Error(\"Fragment code:\");\n Logger.Error(code);\n }\n }\n if (lineErrorVertex) {\n Logger.Error(lineErrorVertex);\n }\n if (lineErrorFragment) {\n Logger.Error(lineErrorFragment);\n }\n }\n Logger.Error(\"Error: \" + this._compilationError);\n const notifyErrors = () => {\n if (this.onError) {\n this.onError(this, this._compilationError);\n }\n this.onErrorObservable.notifyObservers(this);\n };\n // In case a previous compilation was successful, we need to restore the previous pipeline context\n if (previousPipelineContext) {\n this._pipelineContext = previousPipelineContext;\n this._isReady = true;\n notifyErrors();\n }\n // Lets try to compile fallbacks as long as we have some.\n if (fallbacks) {\n this._pipelineContext = null;\n if (fallbacks.hasMoreFallbacks) {\n this._allFallbacksProcessed = false;\n Logger.Error(\"Trying next fallback.\");\n this.defines = fallbacks.reduce(this.defines, this);\n this._prepareEffect();\n }\n else {\n // Sorry we did everything we can\n this._allFallbacksProcessed = true;\n notifyErrors();\n this.onErrorObservable.clear();\n // Unbind mesh reference in fallbacks\n if (this._fallbacks) {\n this._fallbacks.unBindMesh();\n }\n }\n }\n else {\n this._allFallbacksProcessed = true;\n // In case of error, without any prior successful compilation, let s notify observers\n if (!previousPipelineContext) {\n notifyErrors();\n }\n }\n }\n /**\n * Checks if the effect is supported. (Must be called after compilation)\n */\n get isSupported() {\n return this._compilationError === \"\";\n }\n /**\n * Binds a texture to the engine to be used as output of the shader.\n * @param channel Name of the output variable.\n * @param texture Texture to bind.\n * @internal\n */\n _bindTexture(channel, texture) {\n this._engine._bindTexture(this._samplers[channel], texture, channel);\n }\n /**\n * Sets a texture on the engine to be used in the shader.\n * @param channel Name of the sampler variable.\n * @param texture Texture to set.\n */\n setTexture(channel, texture) {\n this._engine.setTexture(this._samplers[channel], this._uniforms[channel], texture, channel);\n }\n /**\n * Sets a depth stencil texture from a render target on the engine to be used in the shader.\n * @param channel Name of the sampler variable.\n * @param texture Texture to set.\n */\n setDepthStencilTexture(channel, texture) {\n this._engine.setDepthStencilTexture(this._samplers[channel], this._uniforms[channel], texture, channel);\n }\n /**\n * Sets an array of textures on the engine to be used in the shader.\n * @param channel Name of the variable.\n * @param textures Textures to set.\n */\n setTextureArray(channel, textures) {\n const exName = channel + \"Ex\";\n if (this._samplerList.indexOf(exName + \"0\") === -1) {\n const initialPos = this._samplerList.indexOf(channel);\n for (let index = 1; index < textures.length; index++) {\n const currentExName = exName + (index - 1).toString();\n this._samplerList.splice(initialPos + index, 0, currentExName);\n }\n // Reset every channels\n let channelIndex = 0;\n for (const key of this._samplerList) {\n this._samplers[key] = channelIndex;\n channelIndex += 1;\n }\n }\n this._engine.setTextureArray(this._samplers[channel], this._uniforms[channel], textures, channel);\n }\n /**\n * Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)\n * @param channel Name of the sampler variable.\n * @param postProcess Post process to get the input texture from.\n */\n setTextureFromPostProcess(channel, postProcess) {\n this._engine.setTextureFromPostProcess(this._samplers[channel], postProcess, channel);\n }\n /**\n * (Warning! setTextureFromPostProcessOutput may be desired instead)\n * Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)\n * @param channel Name of the sampler variable.\n * @param postProcess Post process to get the output texture from.\n */\n setTextureFromPostProcessOutput(channel, postProcess) {\n this._engine.setTextureFromPostProcessOutput(this._samplers[channel], postProcess, channel);\n }\n /**\n * Binds a buffer to a uniform.\n * @param buffer Buffer to bind.\n * @param name Name of the uniform variable to bind to.\n */\n bindUniformBuffer(buffer, name) {\n const bufferName = this._uniformBuffersNames[name];\n if (bufferName === undefined || (Effect._BaseCache[bufferName] === buffer && this._engine._features.useUBOBindingCache)) {\n return;\n }\n Effect._BaseCache[bufferName] = buffer;\n this._engine.bindUniformBufferBase(buffer, bufferName, name);\n }\n /**\n * Binds block to a uniform.\n * @param blockName Name of the block to bind.\n * @param index Index to bind.\n */\n bindUniformBlock(blockName, index) {\n this._engine.bindUniformBlock(this._pipelineContext, blockName, index);\n }\n /**\n * Sets an integer value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param value Value to be set.\n * @returns this effect.\n */\n setInt(uniformName, value) {\n this._pipelineContext.setInt(uniformName, value);\n return this;\n }\n /**\n * Sets an int2 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First int in int2.\n * @param y Second int in int2.\n * @returns this effect.\n */\n setInt2(uniformName, x, y) {\n this._pipelineContext.setInt2(uniformName, x, y);\n return this;\n }\n /**\n * Sets an int3 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First int in int3.\n * @param y Second int in int3.\n * @param z Third int in int3.\n * @returns this effect.\n */\n setInt3(uniformName, x, y, z) {\n this._pipelineContext.setInt3(uniformName, x, y, z);\n return this;\n }\n /**\n * Sets an int4 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First int in int4.\n * @param y Second int in int4.\n * @param z Third int in int4.\n * @param w Fourth int in int4.\n * @returns this effect.\n */\n setInt4(uniformName, x, y, z, w) {\n this._pipelineContext.setInt4(uniformName, x, y, z, w);\n return this;\n }\n /**\n * Sets an int array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setIntArray(uniformName, array) {\n this._pipelineContext.setIntArray(uniformName, array);\n return this;\n }\n /**\n * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setIntArray2(uniformName, array) {\n this._pipelineContext.setIntArray2(uniformName, array);\n return this;\n }\n /**\n * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setIntArray3(uniformName, array) {\n this._pipelineContext.setIntArray3(uniformName, array);\n return this;\n }\n /**\n * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setIntArray4(uniformName, array) {\n this._pipelineContext.setIntArray4(uniformName, array);\n return this;\n }\n /**\n * Sets an unsigned integer value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param value Value to be set.\n * @returns this effect.\n */\n setUInt(uniformName, value) {\n this._pipelineContext.setInt(uniformName, value);\n return this;\n }\n /**\n * Sets an unsigned int2 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First unsigned int in uint2.\n * @param y Second unsigned int in uint2.\n * @returns this effect.\n */\n setUInt2(uniformName, x, y) {\n this._pipelineContext.setInt2(uniformName, x, y);\n return this;\n }\n /**\n * Sets an unsigned int3 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First unsigned int in uint3.\n * @param y Second unsigned int in uint3.\n * @param z Third unsigned int in uint3.\n * @returns this effect.\n */\n setUInt3(uniformName, x, y, z) {\n this._pipelineContext.setInt3(uniformName, x, y, z);\n return this;\n }\n /**\n * Sets an unsigned int4 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First unsigned int in uint4.\n * @param y Second unsigned int in uint4.\n * @param z Third unsigned int in uint4.\n * @param w Fourth unsigned int in uint4.\n * @returns this effect.\n */\n setUInt4(uniformName, x, y, z, w) {\n this._pipelineContext.setInt4(uniformName, x, y, z, w);\n return this;\n }\n /**\n * Sets an unsigned int array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setUIntArray(uniformName, array) {\n this._pipelineContext.setUIntArray(uniformName, array);\n return this;\n }\n /**\n * Sets an unsigned int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setUIntArray2(uniformName, array) {\n this._pipelineContext.setUIntArray2(uniformName, array);\n return this;\n }\n /**\n * Sets an unsigned int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setUIntArray3(uniformName, array) {\n this._pipelineContext.setUIntArray3(uniformName, array);\n return this;\n }\n /**\n * Sets an unsigned int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setUIntArray4(uniformName, array) {\n this._pipelineContext.setUIntArray4(uniformName, array);\n return this;\n }\n /**\n * Sets an float array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setFloatArray(uniformName, array) {\n this._pipelineContext.setArray(uniformName, array);\n return this;\n }\n /**\n * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setFloatArray2(uniformName, array) {\n this._pipelineContext.setArray2(uniformName, array);\n return this;\n }\n /**\n * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setFloatArray3(uniformName, array) {\n this._pipelineContext.setArray3(uniformName, array);\n return this;\n }\n /**\n * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setFloatArray4(uniformName, array) {\n this._pipelineContext.setArray4(uniformName, array);\n return this;\n }\n /**\n * Sets an array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setArray(uniformName, array) {\n this._pipelineContext.setArray(uniformName, array);\n return this;\n }\n /**\n * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setArray2(uniformName, array) {\n this._pipelineContext.setArray2(uniformName, array);\n return this;\n }\n /**\n * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setArray3(uniformName, array) {\n this._pipelineContext.setArray3(uniformName, array);\n return this;\n }\n /**\n * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setArray4(uniformName, array) {\n this._pipelineContext.setArray4(uniformName, array);\n return this;\n }\n /**\n * Sets matrices on a uniform variable.\n * @param uniformName Name of the variable.\n * @param matrices matrices to be set.\n * @returns this effect.\n */\n setMatrices(uniformName, matrices) {\n this._pipelineContext.setMatrices(uniformName, matrices);\n return this;\n }\n /**\n * Sets matrix on a uniform variable.\n * @param uniformName Name of the variable.\n * @param matrix matrix to be set.\n * @returns this effect.\n */\n setMatrix(uniformName, matrix) {\n this._pipelineContext.setMatrix(uniformName, matrix);\n return this;\n }\n /**\n * Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)\n * @param uniformName Name of the variable.\n * @param matrix matrix to be set.\n * @returns this effect.\n */\n setMatrix3x3(uniformName, matrix) {\n // the cast is ok because it is gl.uniformMatrix3fv() which is called at the end, and this function accepts Float32Array and Array\n this._pipelineContext.setMatrix3x3(uniformName, matrix);\n return this;\n }\n /**\n * Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)\n * @param uniformName Name of the variable.\n * @param matrix matrix to be set.\n * @returns this effect.\n */\n setMatrix2x2(uniformName, matrix) {\n // the cast is ok because it is gl.uniformMatrix3fv() which is called at the end, and this function accepts Float32Array and Array\n this._pipelineContext.setMatrix2x2(uniformName, matrix);\n return this;\n }\n /**\n * Sets a float on a uniform variable.\n * @param uniformName Name of the variable.\n * @param value value to be set.\n * @returns this effect.\n */\n setFloat(uniformName, value) {\n this._pipelineContext.setFloat(uniformName, value);\n return this;\n }\n /**\n * Sets a boolean on a uniform variable.\n * @param uniformName Name of the variable.\n * @param bool value to be set.\n * @returns this effect.\n */\n setBool(uniformName, bool) {\n this._pipelineContext.setInt(uniformName, bool ? 1 : 0);\n return this;\n }\n /**\n * Sets a Vector2 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param vector2 vector2 to be set.\n * @returns this effect.\n */\n setVector2(uniformName, vector2) {\n this._pipelineContext.setVector2(uniformName, vector2);\n return this;\n }\n /**\n * Sets a float2 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First float in float2.\n * @param y Second float in float2.\n * @returns this effect.\n */\n setFloat2(uniformName, x, y) {\n this._pipelineContext.setFloat2(uniformName, x, y);\n return this;\n }\n /**\n * Sets a Vector3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param vector3 Value to be set.\n * @returns this effect.\n */\n setVector3(uniformName, vector3) {\n this._pipelineContext.setVector3(uniformName, vector3);\n return this;\n }\n /**\n * Sets a float3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First float in float3.\n * @param y Second float in float3.\n * @param z Third float in float3.\n * @returns this effect.\n */\n setFloat3(uniformName, x, y, z) {\n this._pipelineContext.setFloat3(uniformName, x, y, z);\n return this;\n }\n /**\n * Sets a Vector4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param vector4 Value to be set.\n * @returns this effect.\n */\n setVector4(uniformName, vector4) {\n this._pipelineContext.setVector4(uniformName, vector4);\n return this;\n }\n /**\n * Sets a Quaternion on a uniform variable.\n * @param uniformName Name of the variable.\n * @param quaternion Value to be set.\n * @returns this effect.\n */\n setQuaternion(uniformName, quaternion) {\n this._pipelineContext.setQuaternion(uniformName, quaternion);\n return this;\n }\n /**\n * Sets a float4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First float in float4.\n * @param y Second float in float4.\n * @param z Third float in float4.\n * @param w Fourth float in float4.\n * @returns this effect.\n */\n setFloat4(uniformName, x, y, z, w) {\n this._pipelineContext.setFloat4(uniformName, x, y, z, w);\n return this;\n }\n /**\n * Sets a Color3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param color3 Value to be set.\n * @returns this effect.\n */\n setColor3(uniformName, color3) {\n this._pipelineContext.setColor3(uniformName, color3);\n return this;\n }\n /**\n * Sets a Color4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param color3 Value to be set.\n * @param alpha Alpha value to be set.\n * @returns this effect.\n */\n setColor4(uniformName, color3, alpha) {\n this._pipelineContext.setColor4(uniformName, color3, alpha);\n return this;\n }\n /**\n * Sets a Color4 on a uniform variable\n * @param uniformName defines the name of the variable\n * @param color4 defines the value to be set\n * @returns this effect.\n */\n setDirectColor4(uniformName, color4) {\n this._pipelineContext.setDirectColor4(uniformName, color4);\n return this;\n }\n /**\n * Release all associated resources.\n **/\n dispose() {\n if (this._pipelineContext) {\n this._pipelineContext.dispose();\n }\n this._engine._releaseEffect(this);\n this._isDisposed = true;\n }\n /**\n * This function will add a new shader to the shader store\n * @param name the name of the shader\n * @param pixelShader optional pixel shader content\n * @param vertexShader optional vertex shader content\n * @param shaderLanguage the language the shader is written in (default: GLSL)\n */\n static RegisterShader(name, pixelShader, vertexShader, shaderLanguage = ShaderLanguage.GLSL) {\n if (pixelShader) {\n ShaderStore.GetShadersStore(shaderLanguage)[`${name}PixelShader`] = pixelShader;\n }\n if (vertexShader) {\n ShaderStore.GetShadersStore(shaderLanguage)[`${name}VertexShader`] = vertexShader;\n }\n }\n /**\n * Resets the cache of effects.\n */\n static ResetCache() {\n Effect._BaseCache = {};\n }\n }\n /**\n * Enable logging of the shader code when a compilation error occurs\n */\n Effect.LogShaderCodeOnCompilationError = true;\n Effect._UniqueIdSeed = 0;\n Effect._BaseCache = {};\n /**\n * Store of each shader (The can be looked up using effect.key)\n */\n Effect.ShadersStore = ShaderStore.ShadersStore;\n /**\n * Store of each included file for a shader (The can be looked up using effect.key)\n */\n Effect.IncludesShadersStore = ShaderStore.IncludesShadersStore;\n\n /**\n * @internal\n **/\n class DepthCullingState {\n /**\n * Initializes the state.\n * @param reset\n */\n constructor(reset = true) {\n this._isDepthTestDirty = false;\n this._isDepthMaskDirty = false;\n this._isDepthFuncDirty = false;\n this._isCullFaceDirty = false;\n this._isCullDirty = false;\n this._isZOffsetDirty = false;\n this._isFrontFaceDirty = false;\n if (reset) {\n this.reset();\n }\n }\n get isDirty() {\n return (this._isDepthFuncDirty ||\n this._isDepthTestDirty ||\n this._isDepthMaskDirty ||\n this._isCullFaceDirty ||\n this._isCullDirty ||\n this._isZOffsetDirty ||\n this._isFrontFaceDirty);\n }\n get zOffset() {\n return this._zOffset;\n }\n set zOffset(value) {\n if (this._zOffset === value) {\n return;\n }\n this._zOffset = value;\n this._isZOffsetDirty = true;\n }\n get zOffsetUnits() {\n return this._zOffsetUnits;\n }\n set zOffsetUnits(value) {\n if (this._zOffsetUnits === value) {\n return;\n }\n this._zOffsetUnits = value;\n this._isZOffsetDirty = true;\n }\n get cullFace() {\n return this._cullFace;\n }\n set cullFace(value) {\n if (this._cullFace === value) {\n return;\n }\n this._cullFace = value;\n this._isCullFaceDirty = true;\n }\n get cull() {\n return this._cull;\n }\n set cull(value) {\n if (this._cull === value) {\n return;\n }\n this._cull = value;\n this._isCullDirty = true;\n }\n get depthFunc() {\n return this._depthFunc;\n }\n set depthFunc(value) {\n if (this._depthFunc === value) {\n return;\n }\n this._depthFunc = value;\n this._isDepthFuncDirty = true;\n }\n get depthMask() {\n return this._depthMask;\n }\n set depthMask(value) {\n if (this._depthMask === value) {\n return;\n }\n this._depthMask = value;\n this._isDepthMaskDirty = true;\n }\n get depthTest() {\n return this._depthTest;\n }\n set depthTest(value) {\n if (this._depthTest === value) {\n return;\n }\n this._depthTest = value;\n this._isDepthTestDirty = true;\n }\n get frontFace() {\n return this._frontFace;\n }\n set frontFace(value) {\n if (this._frontFace === value) {\n return;\n }\n this._frontFace = value;\n this._isFrontFaceDirty = true;\n }\n reset() {\n this._depthMask = true;\n this._depthTest = true;\n this._depthFunc = null;\n this._cullFace = null;\n this._cull = null;\n this._zOffset = 0;\n this._zOffsetUnits = 0;\n this._frontFace = null;\n this._isDepthTestDirty = true;\n this._isDepthMaskDirty = true;\n this._isDepthFuncDirty = false;\n this._isCullFaceDirty = false;\n this._isCullDirty = false;\n this._isZOffsetDirty = true;\n this._isFrontFaceDirty = false;\n }\n apply(gl) {\n if (!this.isDirty) {\n return;\n }\n // Cull\n if (this._isCullDirty) {\n if (this.cull) {\n gl.enable(gl.CULL_FACE);\n }\n else {\n gl.disable(gl.CULL_FACE);\n }\n this._isCullDirty = false;\n }\n // Cull face\n if (this._isCullFaceDirty) {\n gl.cullFace(this.cullFace);\n this._isCullFaceDirty = false;\n }\n // Depth mask\n if (this._isDepthMaskDirty) {\n gl.depthMask(this.depthMask);\n this._isDepthMaskDirty = false;\n }\n // Depth test\n if (this._isDepthTestDirty) {\n if (this.depthTest) {\n gl.enable(gl.DEPTH_TEST);\n }\n else {\n gl.disable(gl.DEPTH_TEST);\n }\n this._isDepthTestDirty = false;\n }\n // Depth func\n if (this._isDepthFuncDirty) {\n gl.depthFunc(this.depthFunc);\n this._isDepthFuncDirty = false;\n }\n // zOffset\n if (this._isZOffsetDirty) {\n if (this.zOffset || this.zOffsetUnits) {\n gl.enable(gl.POLYGON_OFFSET_FILL);\n gl.polygonOffset(this.zOffset, this.zOffsetUnits);\n }\n else {\n gl.disable(gl.POLYGON_OFFSET_FILL);\n }\n this._isZOffsetDirty = false;\n }\n // Front face\n if (this._isFrontFaceDirty) {\n gl.frontFace(this.frontFace);\n this._isFrontFaceDirty = false;\n }\n }\n }\n\n /**\n * @internal\n **/\n class StencilState {\n constructor() {\n this.reset();\n }\n reset() {\n this.enabled = false;\n this.mask = 0xff;\n this.func = StencilState.ALWAYS;\n this.funcRef = 1;\n this.funcMask = 0xff;\n this.opStencilFail = StencilState.KEEP;\n this.opDepthFail = StencilState.KEEP;\n this.opStencilDepthPass = StencilState.REPLACE;\n }\n get stencilFunc() {\n return this.func;\n }\n set stencilFunc(value) {\n this.func = value;\n }\n get stencilFuncRef() {\n return this.funcRef;\n }\n set stencilFuncRef(value) {\n this.funcRef = value;\n }\n get stencilFuncMask() {\n return this.funcMask;\n }\n set stencilFuncMask(value) {\n this.funcMask = value;\n }\n get stencilOpStencilFail() {\n return this.opStencilFail;\n }\n set stencilOpStencilFail(value) {\n this.opStencilFail = value;\n }\n get stencilOpDepthFail() {\n return this.opDepthFail;\n }\n set stencilOpDepthFail(value) {\n this.opDepthFail = value;\n }\n get stencilOpStencilDepthPass() {\n return this.opStencilDepthPass;\n }\n set stencilOpStencilDepthPass(value) {\n this.opStencilDepthPass = value;\n }\n get stencilMask() {\n return this.mask;\n }\n set stencilMask(value) {\n this.mask = value;\n }\n get stencilTest() {\n return this.enabled;\n }\n set stencilTest(value) {\n this.enabled = value;\n }\n }\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */\n StencilState.ALWAYS = 519;\n /** Passed to stencilOperation to specify that stencil value must be kept */\n StencilState.KEEP = 7680;\n /** Passed to stencilOperation to specify that stencil value must be replaced */\n StencilState.REPLACE = 7681;\n\n /**\n * @internal\n **/\n class AlphaState {\n /**\n * Initializes the state.\n */\n constructor() {\n this._blendFunctionParameters = new Array(4);\n this._blendEquationParameters = new Array(2);\n this._blendConstants = new Array(4);\n this._isBlendConstantsDirty = false;\n this._alphaBlend = false;\n this._isAlphaBlendDirty = false;\n this._isBlendFunctionParametersDirty = false;\n this._isBlendEquationParametersDirty = false;\n this.reset();\n }\n get isDirty() {\n return this._isAlphaBlendDirty || this._isBlendFunctionParametersDirty || this._isBlendEquationParametersDirty;\n }\n get alphaBlend() {\n return this._alphaBlend;\n }\n set alphaBlend(value) {\n if (this._alphaBlend === value) {\n return;\n }\n this._alphaBlend = value;\n this._isAlphaBlendDirty = true;\n }\n setAlphaBlendConstants(r, g, b, a) {\n if (this._blendConstants[0] === r && this._blendConstants[1] === g && this._blendConstants[2] === b && this._blendConstants[3] === a) {\n return;\n }\n this._blendConstants[0] = r;\n this._blendConstants[1] = g;\n this._blendConstants[2] = b;\n this._blendConstants[3] = a;\n this._isBlendConstantsDirty = true;\n }\n setAlphaBlendFunctionParameters(value0, value1, value2, value3) {\n if (this._blendFunctionParameters[0] === value0 &&\n this._blendFunctionParameters[1] === value1 &&\n this._blendFunctionParameters[2] === value2 &&\n this._blendFunctionParameters[3] === value3) {\n return;\n }\n this._blendFunctionParameters[0] = value0;\n this._blendFunctionParameters[1] = value1;\n this._blendFunctionParameters[2] = value2;\n this._blendFunctionParameters[3] = value3;\n this._isBlendFunctionParametersDirty = true;\n }\n setAlphaEquationParameters(rgb, alpha) {\n if (this._blendEquationParameters[0] === rgb && this._blendEquationParameters[1] === alpha) {\n return;\n }\n this._blendEquationParameters[0] = rgb;\n this._blendEquationParameters[1] = alpha;\n this._isBlendEquationParametersDirty = true;\n }\n reset() {\n this._alphaBlend = false;\n this._blendFunctionParameters[0] = null;\n this._blendFunctionParameters[1] = null;\n this._blendFunctionParameters[2] = null;\n this._blendFunctionParameters[3] = null;\n this._blendEquationParameters[0] = null;\n this._blendEquationParameters[1] = null;\n this._blendConstants[0] = null;\n this._blendConstants[1] = null;\n this._blendConstants[2] = null;\n this._blendConstants[3] = null;\n this._isAlphaBlendDirty = true;\n this._isBlendFunctionParametersDirty = false;\n this._isBlendEquationParametersDirty = false;\n this._isBlendConstantsDirty = false;\n }\n apply(gl) {\n if (!this.isDirty) {\n return;\n }\n // Alpha blend\n if (this._isAlphaBlendDirty) {\n if (this._alphaBlend) {\n gl.enable(gl.BLEND);\n }\n else {\n gl.disable(gl.BLEND);\n }\n this._isAlphaBlendDirty = false;\n }\n // Alpha function\n if (this._isBlendFunctionParametersDirty) {\n gl.blendFuncSeparate(this._blendFunctionParameters[0], this._blendFunctionParameters[1], this._blendFunctionParameters[2], this._blendFunctionParameters[3]);\n this._isBlendFunctionParametersDirty = false;\n }\n // Alpha equation\n if (this._isBlendEquationParametersDirty) {\n gl.blendEquationSeparate(this._blendEquationParameters[0], this._blendEquationParameters[1]);\n this._isBlendEquationParametersDirty = false;\n }\n // Constants\n if (this._isBlendConstantsDirty) {\n gl.blendColor(this._blendConstants[0], this._blendConstants[1], this._blendConstants[2], this._blendConstants[3]);\n this._isBlendConstantsDirty = false;\n }\n }\n }\n\n /**\n * Class used to store a texture sampler data\n */\n class TextureSampler {\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapU() {\n return this._cachedWrapU;\n }\n set wrapU(value) {\n this._cachedWrapU = value;\n }\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapV() {\n return this._cachedWrapV;\n }\n set wrapV(value) {\n this._cachedWrapV = value;\n }\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapR() {\n return this._cachedWrapR;\n }\n set wrapR(value) {\n this._cachedWrapR = value;\n }\n /**\n * With compliant hardware and browser (supporting anisotropic filtering)\n * this defines the level of anisotropic filtering in the texture.\n * The higher the better but the slower.\n */\n get anisotropicFilteringLevel() {\n return this._cachedAnisotropicFilteringLevel;\n }\n set anisotropicFilteringLevel(value) {\n this._cachedAnisotropicFilteringLevel = value;\n }\n /**\n * Gets or sets the comparison function (513, 514, etc). Set 0 to not use a comparison function\n */\n get comparisonFunction() {\n return this._comparisonFunction;\n }\n set comparisonFunction(value) {\n this._comparisonFunction = value;\n }\n /**\n * Indicates to use the mip maps (if available on the texture).\n * Thanks to this flag, you can instruct the sampler to not sample the mipmaps even if they exist (and if the sampling mode is set to a value that normally samples the mipmaps!)\n */\n get useMipMaps() {\n return this._useMipMaps;\n }\n set useMipMaps(value) {\n this._useMipMaps = value;\n }\n /**\n * Creates a Sampler instance\n */\n constructor() {\n /**\n * Gets the sampling mode of the texture\n */\n this.samplingMode = -1;\n this._useMipMaps = true;\n /** @internal */\n this._cachedWrapU = null;\n /** @internal */\n this._cachedWrapV = null;\n /** @internal */\n this._cachedWrapR = null;\n /** @internal */\n this._cachedAnisotropicFilteringLevel = null;\n /** @internal */\n this._comparisonFunction = 0;\n }\n /**\n * Sets all the parameters of the sampler\n * @param wrapU u address mode (default: TEXTURE_WRAP_ADDRESSMODE)\n * @param wrapV v address mode (default: TEXTURE_WRAP_ADDRESSMODE)\n * @param wrapR r address mode (default: TEXTURE_WRAP_ADDRESSMODE)\n * @param anisotropicFilteringLevel anisotropic level (default: 1)\n * @param samplingMode sampling mode (default: 2)\n * @param comparisonFunction comparison function (default: 0 - no comparison function)\n * @returns the current sampler instance\n */\n setParameters(wrapU = 1, wrapV = 1, wrapR = 1, anisotropicFilteringLevel = 1, samplingMode = 2, comparisonFunction = 0) {\n this._cachedWrapU = wrapU;\n this._cachedWrapV = wrapV;\n this._cachedWrapR = wrapR;\n this._cachedAnisotropicFilteringLevel = anisotropicFilteringLevel;\n this.samplingMode = samplingMode;\n this._comparisonFunction = comparisonFunction;\n return this;\n }\n /**\n * Compares this sampler with another one\n * @param other sampler to compare with\n * @returns true if the samplers have the same parametres, else false\n */\n compareSampler(other) {\n return (this._cachedWrapU === other._cachedWrapU &&\n this._cachedWrapV === other._cachedWrapV &&\n this._cachedWrapR === other._cachedWrapR &&\n this._cachedAnisotropicFilteringLevel === other._cachedAnisotropicFilteringLevel &&\n this.samplingMode === other.samplingMode &&\n this._comparisonFunction === other._comparisonFunction &&\n this._useMipMaps === other._useMipMaps);\n }\n }\n\n /**\n * Defines the source of the internal texture\n */\n var InternalTextureSource;\n (function (InternalTextureSource) {\n /**\n * The source of the texture data is unknown\n */\n InternalTextureSource[InternalTextureSource[\"Unknown\"] = 0] = \"Unknown\";\n /**\n * Texture data comes from an URL\n */\n InternalTextureSource[InternalTextureSource[\"Url\"] = 1] = \"Url\";\n /**\n * Texture data is only used for temporary storage\n */\n InternalTextureSource[InternalTextureSource[\"Temp\"] = 2] = \"Temp\";\n /**\n * Texture data comes from raw data (ArrayBuffer)\n */\n InternalTextureSource[InternalTextureSource[\"Raw\"] = 3] = \"Raw\";\n /**\n * Texture content is dynamic (video or dynamic texture)\n */\n InternalTextureSource[InternalTextureSource[\"Dynamic\"] = 4] = \"Dynamic\";\n /**\n * Texture content is generated by rendering to it\n */\n InternalTextureSource[InternalTextureSource[\"RenderTarget\"] = 5] = \"RenderTarget\";\n /**\n * Texture content is part of a multi render target process\n */\n InternalTextureSource[InternalTextureSource[\"MultiRenderTarget\"] = 6] = \"MultiRenderTarget\";\n /**\n * Texture data comes from a cube data file\n */\n InternalTextureSource[InternalTextureSource[\"Cube\"] = 7] = \"Cube\";\n /**\n * Texture data comes from a raw cube data\n */\n InternalTextureSource[InternalTextureSource[\"CubeRaw\"] = 8] = \"CubeRaw\";\n /**\n * Texture data come from a prefiltered cube data file\n */\n InternalTextureSource[InternalTextureSource[\"CubePrefiltered\"] = 9] = \"CubePrefiltered\";\n /**\n * Texture content is raw 3D data\n */\n InternalTextureSource[InternalTextureSource[\"Raw3D\"] = 10] = \"Raw3D\";\n /**\n * Texture content is raw 2D array data\n */\n InternalTextureSource[InternalTextureSource[\"Raw2DArray\"] = 11] = \"Raw2DArray\";\n /**\n * Texture content is a depth/stencil texture\n */\n InternalTextureSource[InternalTextureSource[\"DepthStencil\"] = 12] = \"DepthStencil\";\n /**\n * Texture data comes from a raw cube data encoded with RGBD\n */\n InternalTextureSource[InternalTextureSource[\"CubeRawRGBD\"] = 13] = \"CubeRawRGBD\";\n /**\n * Texture content is a depth texture\n */\n InternalTextureSource[InternalTextureSource[\"Depth\"] = 14] = \"Depth\";\n })(InternalTextureSource || (InternalTextureSource = {}));\n /**\n * Class used to store data associated with WebGL texture data for the engine\n * This class should not be used directly\n */\n class InternalTexture extends TextureSampler {\n /**\n * Gets a boolean indicating if the texture uses mipmaps\n * TODO implements useMipMaps as a separate setting from generateMipMaps\n */\n get useMipMaps() {\n return this.generateMipMaps;\n }\n set useMipMaps(value) {\n this.generateMipMaps = value;\n }\n /** Gets the unique id of the internal texture */\n get uniqueId() {\n return this._uniqueId;\n }\n /** @internal */\n _setUniqueId(id) {\n this._uniqueId = id;\n }\n /**\n * Gets the Engine the texture belongs to.\n * @returns The babylon engine\n */\n getEngine() {\n return this._engine;\n }\n /**\n * Gets the data source type of the texture\n */\n get source() {\n return this._source;\n }\n /**\n * Creates a new InternalTexture\n * @param engine defines the engine to use\n * @param source defines the type of data that will be used\n * @param delayAllocation if the texture allocation should be delayed (default: false)\n */\n constructor(engine, source, delayAllocation = false) {\n super();\n /**\n * Defines if the texture is ready\n */\n this.isReady = false;\n /**\n * Defines if the texture is a cube texture\n */\n this.isCube = false;\n /**\n * Defines if the texture contains 3D data\n */\n this.is3D = false;\n /**\n * Defines if the texture contains 2D array data\n */\n this.is2DArray = false;\n /**\n * Defines if the texture contains multiview data\n */\n this.isMultiview = false;\n /**\n * Gets the URL used to load this texture\n */\n this.url = \"\";\n /**\n * Gets a boolean indicating if the texture needs mipmaps generation\n */\n this.generateMipMaps = false;\n /**\n * Gets the number of samples used by the texture (WebGL2+ only)\n */\n this.samples = 0;\n /**\n * Gets the type of the texture (int, float...)\n */\n this.type = -1;\n /**\n * Gets the format of the texture (RGB, RGBA...)\n */\n this.format = -1;\n /**\n * Observable called when the texture is loaded\n */\n this.onLoadedObservable = new Observable$1();\n /**\n * Observable called when the texture load is raising an error\n */\n this.onErrorObservable = new Observable$1();\n /**\n * If this callback is defined it will be called instead of the default _rebuild function\n */\n this.onRebuildCallback = null;\n /**\n * Gets the width of the texture\n */\n this.width = 0;\n /**\n * Gets the height of the texture\n */\n this.height = 0;\n /**\n * Gets the depth of the texture\n */\n this.depth = 0;\n /**\n * Gets the initial width of the texture (It could be rescaled if the current system does not support non power of two textures)\n */\n this.baseWidth = 0;\n /**\n * Gets the initial height of the texture (It could be rescaled if the current system does not support non power of two textures)\n */\n this.baseHeight = 0;\n /**\n * Gets the initial depth of the texture (It could be rescaled if the current system does not support non power of two textures)\n */\n this.baseDepth = 0;\n /**\n * Gets a boolean indicating if the texture is inverted on Y axis\n */\n this.invertY = false;\n // Private\n /** @internal */\n this._invertVScale = false;\n /** @internal */\n this._associatedChannel = -1;\n /** @internal */\n this._source = InternalTextureSource.Unknown;\n /** @internal */\n this._buffer = null;\n /** @internal */\n this._bufferView = null;\n /** @internal */\n this._bufferViewArray = null;\n /** @internal */\n this._bufferViewArrayArray = null;\n /** @internal */\n this._size = 0;\n /** @internal */\n this._extension = \"\";\n /** @internal */\n this._files = null;\n /** @internal */\n this._workingCanvas = null;\n /** @internal */\n this._workingContext = null;\n /** @internal */\n this._cachedCoordinatesMode = null;\n /** @internal */\n this._isDisabled = false;\n /** @internal */\n this._compression = null;\n /** @internal */\n this._sphericalPolynomial = null;\n /** @internal */\n this._sphericalPolynomialPromise = null;\n /** @internal */\n this._sphericalPolynomialComputed = false;\n /** @internal */\n this._lodGenerationScale = 0;\n /** @internal */\n this._lodGenerationOffset = 0;\n /** @internal */\n this._useSRGBBuffer = false;\n // The following three fields helps sharing generated fixed LODs for texture filtering\n // In environment not supporting the textureLOD extension like EDGE. They are for internal use only.\n // They are at the level of the gl texture to benefit from the cache.\n /** @internal */\n this._lodTextureHigh = null;\n /** @internal */\n this._lodTextureMid = null;\n /** @internal */\n this._lodTextureLow = null;\n /** @internal */\n this._isRGBD = false;\n /** @internal */\n this._linearSpecularLOD = false;\n /** @internal */\n this._irradianceTexture = null;\n /** @internal */\n this._hardwareTexture = null;\n /** @internal */\n this._maxLodLevel = null;\n /** @internal */\n this._references = 1;\n /** @internal */\n this._gammaSpace = null;\n this._engine = engine;\n this._source = source;\n this._uniqueId = InternalTexture._Counter++;\n if (!delayAllocation) {\n this._hardwareTexture = engine._createHardwareTexture();\n }\n }\n /**\n * Increments the number of references (ie. the number of Texture that point to it)\n */\n incrementReferences() {\n this._references++;\n }\n /**\n * Change the size of the texture (not the size of the content)\n * @param width defines the new width\n * @param height defines the new height\n * @param depth defines the new depth (1 by default)\n */\n updateSize(width, height, depth = 1) {\n this._engine.updateTextureDimensions(this, width, height, depth);\n this.width = width;\n this.height = height;\n this.depth = depth;\n this.baseWidth = width;\n this.baseHeight = height;\n this.baseDepth = depth;\n this._size = width * height * depth;\n }\n /** @internal */\n _rebuild() {\n var _a;\n this.isReady = false;\n this._cachedCoordinatesMode = null;\n this._cachedWrapU = null;\n this._cachedWrapV = null;\n this._cachedWrapR = null;\n this._cachedAnisotropicFilteringLevel = null;\n if (this.onRebuildCallback) {\n const data = this.onRebuildCallback(this);\n const swapAndSetIsReady = (proxyInternalTexture) => {\n proxyInternalTexture._swapAndDie(this, false);\n this.isReady = data.isReady;\n };\n if (data.isAsync) {\n data.proxy.then(swapAndSetIsReady);\n }\n else {\n swapAndSetIsReady(data.proxy);\n }\n return;\n }\n let proxy;\n switch (this.source) {\n case InternalTextureSource.Temp:\n break;\n case InternalTextureSource.Url:\n proxy = this._engine.createTexture((_a = this._originalUrl) !== null && _a !== void 0 ? _a : this.url, !this.generateMipMaps, this.invertY, null, this.samplingMode, \n // Do not use Proxy here as it could be fully synchronous\n // and proxy would be undefined.\n (temp) => {\n temp._swapAndDie(this, false);\n this.isReady = true;\n }, null, this._buffer, undefined, this.format, this._extension, undefined, undefined, undefined, this._useSRGBBuffer);\n return;\n case InternalTextureSource.Raw:\n proxy = this._engine.createRawTexture(this._bufferView, this.baseWidth, this.baseHeight, this.format, this.generateMipMaps, this.invertY, this.samplingMode, this._compression, this.type, undefined, this._useSRGBBuffer);\n proxy._swapAndDie(this, false);\n this.isReady = true;\n break;\n case InternalTextureSource.Raw3D:\n proxy = this._engine.createRawTexture3D(this._bufferView, this.baseWidth, this.baseHeight, this.baseDepth, this.format, this.generateMipMaps, this.invertY, this.samplingMode, this._compression, this.type);\n proxy._swapAndDie(this, false);\n this.isReady = true;\n break;\n case InternalTextureSource.Raw2DArray:\n proxy = this._engine.createRawTexture2DArray(this._bufferView, this.baseWidth, this.baseHeight, this.baseDepth, this.format, this.generateMipMaps, this.invertY, this.samplingMode, this._compression, this.type);\n proxy._swapAndDie(this, false);\n this.isReady = true;\n break;\n case InternalTextureSource.Dynamic:\n proxy = this._engine.createDynamicTexture(this.baseWidth, this.baseHeight, this.generateMipMaps, this.samplingMode);\n proxy._swapAndDie(this, false);\n this._engine.updateDynamicTexture(this, this._engine.getRenderingCanvas(), this.invertY, undefined, undefined, true);\n // The engine will make sure to update content so no need to flag it as isReady = true\n break;\n case InternalTextureSource.Cube:\n proxy = this._engine.createCubeTexture(this.url, null, this._files, !this.generateMipMaps, () => {\n proxy._swapAndDie(this, false);\n this.isReady = true;\n }, null, this.format, this._extension, false, 0, 0, null, undefined, this._useSRGBBuffer);\n return;\n case InternalTextureSource.CubeRaw:\n proxy = this._engine.createRawCubeTexture(this._bufferViewArray, this.width, this.format, this.type, this.generateMipMaps, this.invertY, this.samplingMode, this._compression);\n proxy._swapAndDie(this, false);\n this.isReady = true;\n break;\n case InternalTextureSource.CubeRawRGBD:\n // This case is being handeled by the environment texture tools and is not a part of the rebuild process.\n // To use CubeRawRGBD use updateRGBDAsync on the cube texture.\n return;\n case InternalTextureSource.CubePrefiltered:\n proxy = this._engine.createPrefilteredCubeTexture(this.url, null, this._lodGenerationScale, this._lodGenerationOffset, (proxy) => {\n if (proxy) {\n proxy._swapAndDie(this, false);\n }\n this.isReady = true;\n }, null, this.format, this._extension);\n proxy._sphericalPolynomial = this._sphericalPolynomial;\n return;\n }\n }\n /**\n * @internal\n */\n _swapAndDie(target, swapAll = true) {\n // TODO what about refcount on target?\n var _a;\n (_a = this._hardwareTexture) === null || _a === void 0 ? void 0 : _a.setUsage(target._source, this.generateMipMaps, this.isCube, this.width, this.height);\n target._hardwareTexture = this._hardwareTexture;\n if (swapAll) {\n target._isRGBD = this._isRGBD;\n }\n if (this._lodTextureHigh) {\n if (target._lodTextureHigh) {\n target._lodTextureHigh.dispose();\n }\n target._lodTextureHigh = this._lodTextureHigh;\n }\n if (this._lodTextureMid) {\n if (target._lodTextureMid) {\n target._lodTextureMid.dispose();\n }\n target._lodTextureMid = this._lodTextureMid;\n }\n if (this._lodTextureLow) {\n if (target._lodTextureLow) {\n target._lodTextureLow.dispose();\n }\n target._lodTextureLow = this._lodTextureLow;\n }\n if (this._irradianceTexture) {\n if (target._irradianceTexture) {\n target._irradianceTexture.dispose();\n }\n target._irradianceTexture = this._irradianceTexture;\n }\n const cache = this._engine.getLoadedTexturesCache();\n let index = cache.indexOf(this);\n if (index !== -1) {\n cache.splice(index, 1);\n }\n index = cache.indexOf(target);\n if (index === -1) {\n cache.push(target);\n }\n }\n /**\n * Dispose the current allocated resources\n */\n dispose() {\n this._references--;\n this.onLoadedObservable.clear();\n this.onErrorObservable.clear();\n if (this._references === 0) {\n this._engine._releaseTexture(this);\n this._hardwareTexture = null;\n }\n }\n }\n /** @internal */\n InternalTexture._Counter = 0;\n\n /** @internal */\n class WebGLShaderProcessor {\n constructor() {\n this.shaderLanguage = ShaderLanguage.GLSL;\n }\n postProcessor(code, defines, isFragment, processingContext, engine) {\n // Remove extensions\n if (!engine.getCaps().drawBuffersExtension) {\n // even if enclosed in #if/#endif, IE11 does parse the #extension declaration, so we need to remove it altogether\n const regex = /#extension.+GL_EXT_draw_buffers.+(enable|require)/g;\n code = code.replace(regex, \"\");\n }\n return code;\n }\n }\n\n const varyingRegex = /(flat\\s)?\\s*varying\\s*.*/;\n /** @internal */\n class WebGL2ShaderProcessor {\n constructor() {\n this.shaderLanguage = ShaderLanguage.GLSL;\n }\n attributeProcessor(attribute) {\n return attribute.replace(\"attribute\", \"in\");\n }\n varyingCheck(varying, _isFragment) {\n return varyingRegex.test(varying);\n }\n varyingProcessor(varying, isFragment) {\n return varying.replace(\"varying\", isFragment ? \"in\" : \"out\");\n }\n postProcessor(code, defines, isFragment) {\n const hasDrawBuffersExtension = code.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1;\n // Remove extensions\n const regex = /#extension.+(GL_OVR_multiview2|GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;\n code = code.replace(regex, \"\");\n // Replace instructions\n code = code.replace(/texture2D\\s*\\(/g, \"texture(\");\n if (isFragment) {\n const hasOutput = code.search(/layout *\\(location *= *0\\) *out/g) !== -1;\n code = code.replace(/texture2DLodEXT\\s*\\(/g, \"textureLod(\");\n code = code.replace(/textureCubeLodEXT\\s*\\(/g, \"textureLod(\");\n code = code.replace(/textureCube\\s*\\(/g, \"texture(\");\n code = code.replace(/gl_FragDepthEXT/g, \"gl_FragDepth\");\n code = code.replace(/gl_FragColor/g, \"glFragColor\");\n code = code.replace(/gl_FragData/g, \"glFragData\");\n code = code.replace(/void\\s+?main\\s*\\(/g, (hasDrawBuffersExtension || hasOutput ? \"\" : \"layout(location = 0) out vec4 glFragColor;\\n\") + \"void main(\");\n }\n else {\n const hasMultiviewExtension = defines.indexOf(\"#define MULTIVIEW\") !== -1;\n if (hasMultiviewExtension) {\n return \"#extension GL_OVR_multiview2 : require\\nlayout (num_views = 2) in;\\n\" + code;\n }\n }\n return code;\n }\n }\n\n /**\n * Class used to store gfx data (like WebGLBuffer)\n */\n class DataBuffer {\n /**\n * Gets the underlying buffer\n */\n get underlyingResource() {\n return null;\n }\n /**\n * Constructs the buffer\n */\n constructor() {\n /**\n * Gets or sets the number of objects referencing this buffer\n */\n this.references = 0;\n /** Gets or sets the size of the underlying buffer */\n this.capacity = 0;\n /**\n * Gets or sets a boolean indicating if the buffer contains 32bits indices\n */\n this.is32Bits = false;\n this.uniqueId = DataBuffer._Counter++;\n }\n }\n DataBuffer._Counter = 0;\n\n /** @internal */\n class WebGLDataBuffer extends DataBuffer {\n constructor(resource) {\n super();\n this._buffer = resource;\n }\n get underlyingResource() {\n return this._buffer;\n }\n }\n\n /** @internal */\n class WebGLPipelineContext {\n constructor() {\n this._valueCache = {};\n this.vertexCompilationError = null;\n this.fragmentCompilationError = null;\n this.programLinkError = null;\n this.programValidationError = null;\n /** @internal */\n this._isDisposed = false;\n }\n get isAsync() {\n return this.isParallelCompiled;\n }\n get isReady() {\n if (this.program) {\n if (this.isParallelCompiled) {\n return this.engine._isRenderingStateCompiled(this);\n }\n return true;\n }\n return false;\n }\n _handlesSpectorRebuildCallback(onCompiled) {\n if (onCompiled && this.program) {\n onCompiled(this.program);\n }\n }\n _fillEffectInformation(effect, uniformBuffersNames, uniformsNames, uniforms, samplerList, samplers, attributesNames, attributes) {\n const engine = this.engine;\n if (engine.supportsUniformBuffers) {\n for (const name in uniformBuffersNames) {\n effect.bindUniformBlock(name, uniformBuffersNames[name]);\n }\n }\n const effectAvailableUniforms = this.engine.getUniforms(this, uniformsNames);\n effectAvailableUniforms.forEach((uniform, index) => {\n uniforms[uniformsNames[index]] = uniform;\n });\n this._uniforms = uniforms;\n let index;\n for (index = 0; index < samplerList.length; index++) {\n const sampler = effect.getUniform(samplerList[index]);\n if (sampler == null) {\n samplerList.splice(index, 1);\n index--;\n }\n }\n samplerList.forEach((name, index) => {\n samplers[name] = index;\n });\n for (const attr of engine.getAttributes(this, attributesNames)) {\n attributes.push(attr);\n }\n }\n /**\n * Release all associated resources.\n **/\n dispose() {\n this._uniforms = {};\n this._isDisposed = true;\n }\n /**\n * @internal\n */\n _cacheMatrix(uniformName, matrix) {\n const cache = this._valueCache[uniformName];\n const flag = matrix.updateFlag;\n if (cache !== undefined && cache === flag) {\n return false;\n }\n this._valueCache[uniformName] = flag;\n return true;\n }\n /**\n * @internal\n */\n _cacheFloat2(uniformName, x, y) {\n let cache = this._valueCache[uniformName];\n if (!cache || cache.length !== 2) {\n cache = [x, y];\n this._valueCache[uniformName] = cache;\n return true;\n }\n let changed = false;\n if (cache[0] !== x) {\n cache[0] = x;\n changed = true;\n }\n if (cache[1] !== y) {\n cache[1] = y;\n changed = true;\n }\n return changed;\n }\n /**\n * @internal\n */\n _cacheFloat3(uniformName, x, y, z) {\n let cache = this._valueCache[uniformName];\n if (!cache || cache.length !== 3) {\n cache = [x, y, z];\n this._valueCache[uniformName] = cache;\n return true;\n }\n let changed = false;\n if (cache[0] !== x) {\n cache[0] = x;\n changed = true;\n }\n if (cache[1] !== y) {\n cache[1] = y;\n changed = true;\n }\n if (cache[2] !== z) {\n cache[2] = z;\n changed = true;\n }\n return changed;\n }\n /**\n * @internal\n */\n _cacheFloat4(uniformName, x, y, z, w) {\n let cache = this._valueCache[uniformName];\n if (!cache || cache.length !== 4) {\n cache = [x, y, z, w];\n this._valueCache[uniformName] = cache;\n return true;\n }\n let changed = false;\n if (cache[0] !== x) {\n cache[0] = x;\n changed = true;\n }\n if (cache[1] !== y) {\n cache[1] = y;\n changed = true;\n }\n if (cache[2] !== z) {\n cache[2] = z;\n changed = true;\n }\n if (cache[3] !== w) {\n cache[3] = w;\n changed = true;\n }\n return changed;\n }\n /**\n * Sets an integer value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param value Value to be set.\n */\n setInt(uniformName, value) {\n const cache = this._valueCache[uniformName];\n if (cache !== undefined && cache === value) {\n return;\n }\n if (this.engine.setInt(this._uniforms[uniformName], value)) {\n this._valueCache[uniformName] = value;\n }\n }\n /**\n * Sets a int2 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First int in int2.\n * @param y Second int in int2.\n */\n setInt2(uniformName, x, y) {\n if (this._cacheFloat2(uniformName, x, y)) {\n if (!this.engine.setInt2(this._uniforms[uniformName], x, y)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a int3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First int in int3.\n * @param y Second int in int3.\n * @param z Third int in int3.\n */\n setInt3(uniformName, x, y, z) {\n if (this._cacheFloat3(uniformName, x, y, z)) {\n if (!this.engine.setInt3(this._uniforms[uniformName], x, y, z)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a int4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First int in int4.\n * @param y Second int in int4.\n * @param z Third int in int4.\n * @param w Fourth int in int4.\n */\n setInt4(uniformName, x, y, z, w) {\n if (this._cacheFloat4(uniformName, x, y, z, w)) {\n if (!this.engine.setInt4(this._uniforms[uniformName], x, y, z, w)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets an int array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setIntArray(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setIntArray(this._uniforms[uniformName], array);\n }\n /**\n * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setIntArray2(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setIntArray2(this._uniforms[uniformName], array);\n }\n /**\n * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setIntArray3(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setIntArray3(this._uniforms[uniformName], array);\n }\n /**\n * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setIntArray4(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setIntArray4(this._uniforms[uniformName], array);\n }\n /**\n * Sets an unsigned integer value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param value Value to be set.\n */\n setUInt(uniformName, value) {\n const cache = this._valueCache[uniformName];\n if (cache !== undefined && cache === value) {\n return;\n }\n if (this.engine.setUInt(this._uniforms[uniformName], value)) {\n this._valueCache[uniformName] = value;\n }\n }\n /**\n * Sets an unsigned int2 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First unsigned int in uint2.\n * @param y Second unsigned int in uint2.\n */\n setUInt2(uniformName, x, y) {\n if (this._cacheFloat2(uniformName, x, y)) {\n if (!this.engine.setUInt2(this._uniforms[uniformName], x, y)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets an unsigned int3 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First unsigned int in uint3.\n * @param y Second unsigned int in uint3.\n * @param z Third unsigned int in uint3.\n */\n setUInt3(uniformName, x, y, z) {\n if (this._cacheFloat3(uniformName, x, y, z)) {\n if (!this.engine.setUInt3(this._uniforms[uniformName], x, y, z)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets an unsigned int4 value on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First unsigned int in uint4.\n * @param y Second unsigned int in uint4.\n * @param z Third unsigned int in uint4.\n * @param w Fourth unsigned int in uint4.\n */\n setUInt4(uniformName, x, y, z, w) {\n if (this._cacheFloat4(uniformName, x, y, z, w)) {\n if (!this.engine.setUInt4(this._uniforms[uniformName], x, y, z, w)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets an unsigned int array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setUIntArray(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setUIntArray(this._uniforms[uniformName], array);\n }\n /**\n * Sets an unsigned int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setUIntArray2(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setUIntArray2(this._uniforms[uniformName], array);\n }\n /**\n * Sets an unsigned int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setUIntArray3(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setUIntArray3(this._uniforms[uniformName], array);\n }\n /**\n * Sets an unsigned int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setUIntArray4(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setUIntArray4(this._uniforms[uniformName], array);\n }\n /**\n * Sets an array on a uniform variable.\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setArray(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setArray(this._uniforms[uniformName], array);\n }\n /**\n * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setArray2(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setArray2(this._uniforms[uniformName], array);\n }\n /**\n * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n * @returns this effect.\n */\n setArray3(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setArray3(this._uniforms[uniformName], array);\n }\n /**\n * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\n * @param uniformName Name of the variable.\n * @param array array to be set.\n */\n setArray4(uniformName, array) {\n this._valueCache[uniformName] = null;\n this.engine.setArray4(this._uniforms[uniformName], array);\n }\n /**\n * Sets matrices on a uniform variable.\n * @param uniformName Name of the variable.\n * @param matrices matrices to be set.\n */\n setMatrices(uniformName, matrices) {\n if (!matrices) {\n return;\n }\n this._valueCache[uniformName] = null;\n this.engine.setMatrices(this._uniforms[uniformName], matrices);\n }\n /**\n * Sets matrix on a uniform variable.\n * @param uniformName Name of the variable.\n * @param matrix matrix to be set.\n */\n setMatrix(uniformName, matrix) {\n if (this._cacheMatrix(uniformName, matrix)) {\n if (!this.engine.setMatrices(this._uniforms[uniformName], matrix.toArray())) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)\n * @param uniformName Name of the variable.\n * @param matrix matrix to be set.\n */\n setMatrix3x3(uniformName, matrix) {\n this._valueCache[uniformName] = null;\n this.engine.setMatrix3x3(this._uniforms[uniformName], matrix);\n }\n /**\n * Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)\n * @param uniformName Name of the variable.\n * @param matrix matrix to be set.\n */\n setMatrix2x2(uniformName, matrix) {\n this._valueCache[uniformName] = null;\n this.engine.setMatrix2x2(this._uniforms[uniformName], matrix);\n }\n /**\n * Sets a float on a uniform variable.\n * @param uniformName Name of the variable.\n * @param value value to be set.\n * @returns this effect.\n */\n setFloat(uniformName, value) {\n const cache = this._valueCache[uniformName];\n if (cache !== undefined && cache === value) {\n return;\n }\n if (this.engine.setFloat(this._uniforms[uniformName], value)) {\n this._valueCache[uniformName] = value;\n }\n }\n /**\n * Sets a Vector2 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param vector2 vector2 to be set.\n */\n setVector2(uniformName, vector2) {\n if (this._cacheFloat2(uniformName, vector2.x, vector2.y)) {\n if (!this.engine.setFloat2(this._uniforms[uniformName], vector2.x, vector2.y)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a float2 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First float in float2.\n * @param y Second float in float2.\n */\n setFloat2(uniformName, x, y) {\n if (this._cacheFloat2(uniformName, x, y)) {\n if (!this.engine.setFloat2(this._uniforms[uniformName], x, y)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a Vector3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param vector3 Value to be set.\n */\n setVector3(uniformName, vector3) {\n if (this._cacheFloat3(uniformName, vector3.x, vector3.y, vector3.z)) {\n if (!this.engine.setFloat3(this._uniforms[uniformName], vector3.x, vector3.y, vector3.z)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a float3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First float in float3.\n * @param y Second float in float3.\n * @param z Third float in float3.\n */\n setFloat3(uniformName, x, y, z) {\n if (this._cacheFloat3(uniformName, x, y, z)) {\n if (!this.engine.setFloat3(this._uniforms[uniformName], x, y, z)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a Vector4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param vector4 Value to be set.\n */\n setVector4(uniformName, vector4) {\n if (this._cacheFloat4(uniformName, vector4.x, vector4.y, vector4.z, vector4.w)) {\n if (!this.engine.setFloat4(this._uniforms[uniformName], vector4.x, vector4.y, vector4.z, vector4.w)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a Quaternion on a uniform variable.\n * @param uniformName Name of the variable.\n * @param quaternion Value to be set.\n */\n setQuaternion(uniformName, quaternion) {\n if (this._cacheFloat4(uniformName, quaternion.x, quaternion.y, quaternion.z, quaternion.w)) {\n if (!this.engine.setFloat4(this._uniforms[uniformName], quaternion.x, quaternion.y, quaternion.z, quaternion.w)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a float4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param x First float in float4.\n * @param y Second float in float4.\n * @param z Third float in float4.\n * @param w Fourth float in float4.\n * @returns this effect.\n */\n setFloat4(uniformName, x, y, z, w) {\n if (this._cacheFloat4(uniformName, x, y, z, w)) {\n if (!this.engine.setFloat4(this._uniforms[uniformName], x, y, z, w)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a Color3 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param color3 Value to be set.\n */\n setColor3(uniformName, color3) {\n if (this._cacheFloat3(uniformName, color3.r, color3.g, color3.b)) {\n if (!this.engine.setFloat3(this._uniforms[uniformName], color3.r, color3.g, color3.b)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a Color4 on a uniform variable.\n * @param uniformName Name of the variable.\n * @param color3 Value to be set.\n * @param alpha Alpha value to be set.\n */\n setColor4(uniformName, color3, alpha) {\n if (this._cacheFloat4(uniformName, color3.r, color3.g, color3.b, alpha)) {\n if (!this.engine.setFloat4(this._uniforms[uniformName], color3.r, color3.g, color3.b, alpha)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n /**\n * Sets a Color4 on a uniform variable\n * @param uniformName defines the name of the variable\n * @param color4 defines the value to be set\n */\n setDirectColor4(uniformName, color4) {\n if (this._cacheFloat4(uniformName, color4.r, color4.g, color4.b, color4.a)) {\n if (!this.engine.setFloat4(this._uniforms[uniformName], color4.r, color4.g, color4.b, color4.a)) {\n this._valueCache[uniformName] = null;\n }\n }\n }\n _getVertexShaderCode() {\n return this.vertexShader ? this.engine._getShaderSource(this.vertexShader) : null;\n }\n _getFragmentShaderCode() {\n return this.fragmentShader ? this.engine._getShaderSource(this.fragmentShader) : null;\n }\n }\n\n /** @internal */\n class WebGLHardwareTexture {\n get underlyingResource() {\n return this._webGLTexture;\n }\n constructor(existingTexture = null, context) {\n // There can be multiple buffers for a single WebGL texture because different layers of a 2DArrayTexture / 3DTexture\n // or different faces of a cube texture can be bound to different render targets at the same time.\n this._MSAARenderBuffers = null;\n this._context = context;\n if (!existingTexture) {\n existingTexture = context.createTexture();\n if (!existingTexture) {\n throw new Error(\"Unable to create webGL texture\");\n }\n }\n this.set(existingTexture);\n }\n setUsage() { }\n set(hardwareTexture) {\n this._webGLTexture = hardwareTexture;\n }\n reset() {\n this._webGLTexture = null;\n this._MSAARenderBuffers = null;\n }\n addMSAARenderBuffer(buffer) {\n if (!this._MSAARenderBuffers) {\n this._MSAARenderBuffers = [];\n }\n this._MSAARenderBuffers.push(buffer);\n }\n releaseMSAARenderBuffers() {\n if (this._MSAARenderBuffers) {\n for (const buffer of this._MSAARenderBuffers) {\n this._context.deleteRenderbuffer(buffer);\n }\n this._MSAARenderBuffers = null;\n }\n }\n release() {\n this.releaseMSAARenderBuffers();\n if (this._webGLTexture) {\n this._context.deleteTexture(this._webGLTexture);\n }\n this.reset();\n }\n }\n\n /** @internal */\n class DrawWrapper {\n static IsWrapper(effect) {\n return effect.getPipelineContext === undefined;\n }\n static GetEffect(effect) {\n return effect.getPipelineContext === undefined ? effect.effect : effect;\n }\n constructor(engine, createMaterialContext = true) {\n this.effect = null;\n this.defines = null;\n this.drawContext = engine.createDrawContext();\n if (createMaterialContext) {\n this.materialContext = engine.createMaterialContext();\n }\n }\n setEffect(effect, defines, resetContext = true) {\n var _a;\n this.effect = effect;\n if (defines !== undefined) {\n this.defines = defines;\n }\n if (resetContext) {\n (_a = this.drawContext) === null || _a === void 0 ? void 0 : _a.reset();\n }\n }\n dispose() {\n var _a;\n (_a = this.drawContext) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n }\n\n /**\n * @internal\n **/\n class StencilStateComposer {\n get isDirty() {\n return this._isStencilTestDirty || this._isStencilMaskDirty || this._isStencilFuncDirty || this._isStencilOpDirty;\n }\n get func() {\n return this._func;\n }\n set func(value) {\n if (this._func === value) {\n return;\n }\n this._func = value;\n this._isStencilFuncDirty = true;\n }\n get funcRef() {\n return this._funcRef;\n }\n set funcRef(value) {\n if (this._funcRef === value) {\n return;\n }\n this._funcRef = value;\n this._isStencilFuncDirty = true;\n }\n get funcMask() {\n return this._funcMask;\n }\n set funcMask(value) {\n if (this._funcMask === value) {\n return;\n }\n this._funcMask = value;\n this._isStencilFuncDirty = true;\n }\n get opStencilFail() {\n return this._opStencilFail;\n }\n set opStencilFail(value) {\n if (this._opStencilFail === value) {\n return;\n }\n this._opStencilFail = value;\n this._isStencilOpDirty = true;\n }\n get opDepthFail() {\n return this._opDepthFail;\n }\n set opDepthFail(value) {\n if (this._opDepthFail === value) {\n return;\n }\n this._opDepthFail = value;\n this._isStencilOpDirty = true;\n }\n get opStencilDepthPass() {\n return this._opStencilDepthPass;\n }\n set opStencilDepthPass(value) {\n if (this._opStencilDepthPass === value) {\n return;\n }\n this._opStencilDepthPass = value;\n this._isStencilOpDirty = true;\n }\n get mask() {\n return this._mask;\n }\n set mask(value) {\n if (this._mask === value) {\n return;\n }\n this._mask = value;\n this._isStencilMaskDirty = true;\n }\n get enabled() {\n return this._enabled;\n }\n set enabled(value) {\n if (this._enabled === value) {\n return;\n }\n this._enabled = value;\n this._isStencilTestDirty = true;\n }\n constructor(reset = true) {\n this._isStencilTestDirty = false;\n this._isStencilMaskDirty = false;\n this._isStencilFuncDirty = false;\n this._isStencilOpDirty = false;\n this.useStencilGlobalOnly = false;\n if (reset) {\n this.reset();\n }\n }\n reset() {\n var _a;\n this.stencilMaterial = undefined;\n (_a = this.stencilGlobal) === null || _a === void 0 ? void 0 : _a.reset();\n this._isStencilTestDirty = true;\n this._isStencilMaskDirty = true;\n this._isStencilFuncDirty = true;\n this._isStencilOpDirty = true;\n }\n apply(gl) {\n var _a;\n if (!gl) {\n return;\n }\n const stencilMaterialEnabled = !this.useStencilGlobalOnly && !!((_a = this.stencilMaterial) === null || _a === void 0 ? void 0 : _a.enabled);\n this.enabled = stencilMaterialEnabled ? this.stencilMaterial.enabled : this.stencilGlobal.enabled;\n this.func = stencilMaterialEnabled ? this.stencilMaterial.func : this.stencilGlobal.func;\n this.funcRef = stencilMaterialEnabled ? this.stencilMaterial.funcRef : this.stencilGlobal.funcRef;\n this.funcMask = stencilMaterialEnabled ? this.stencilMaterial.funcMask : this.stencilGlobal.funcMask;\n this.opStencilFail = stencilMaterialEnabled ? this.stencilMaterial.opStencilFail : this.stencilGlobal.opStencilFail;\n this.opDepthFail = stencilMaterialEnabled ? this.stencilMaterial.opDepthFail : this.stencilGlobal.opDepthFail;\n this.opStencilDepthPass = stencilMaterialEnabled ? this.stencilMaterial.opStencilDepthPass : this.stencilGlobal.opStencilDepthPass;\n this.mask = stencilMaterialEnabled ? this.stencilMaterial.mask : this.stencilGlobal.mask;\n if (!this.isDirty) {\n return;\n }\n // Stencil test\n if (this._isStencilTestDirty) {\n if (this.enabled) {\n gl.enable(gl.STENCIL_TEST);\n }\n else {\n gl.disable(gl.STENCIL_TEST);\n }\n this._isStencilTestDirty = false;\n }\n // Stencil mask\n if (this._isStencilMaskDirty) {\n gl.stencilMask(this.mask);\n this._isStencilMaskDirty = false;\n }\n // Stencil func\n if (this._isStencilFuncDirty) {\n gl.stencilFunc(this.func, this.funcRef, this.funcMask);\n this._isStencilFuncDirty = false;\n }\n // Stencil op\n if (this._isStencilOpDirty) {\n gl.stencilOp(this.opStencilFail, this.opDepthFail, this.opStencilDepthPass);\n this._isStencilOpDirty = false;\n }\n }\n }\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n /**\n * Keeps track of all the buffer info used in engine.\n */\n class BufferPointer {\n }\n /**\n * The base engine class (root of all engines)\n */\n class ThinEngine {\n /**\n * Returns the current npm package of the sdk\n */\n // Not mixed with Version for tooling purpose.\n static get NpmPackage() {\n return \"babylonjs@6.15.0\";\n }\n /**\n * Returns the current version of the framework\n */\n static get Version() {\n return \"6.15.0\";\n }\n /**\n * Returns a string describing the current engine\n */\n get description() {\n let description = this.name + this.webGLVersion;\n if (this._caps.parallelShaderCompile) {\n description += \" - Parallel shader compilation\";\n }\n return description;\n }\n /**\n * Gets or sets the name of the engine\n */\n get name() {\n return this._name;\n }\n set name(value) {\n this._name = value;\n }\n /**\n * Returns the version of the engine\n */\n get version() {\n return this._webGLVersion;\n }\n get isDisposed() {\n return this._isDisposed;\n }\n /**\n * Gets or sets the relative url used to load shaders if using the engine in non-minified mode\n */\n static get ShadersRepository() {\n return Effect.ShadersRepository;\n }\n static set ShadersRepository(value) {\n Effect.ShadersRepository = value;\n }\n /**\n * @internal\n */\n _getShaderProcessor(shaderLanguage) {\n return this._shaderProcessor;\n }\n /**\n * Gets or sets a boolean indicating if depth buffer should be reverse, going from far to near.\n * This can provide greater z depth for distant objects.\n */\n get useReverseDepthBuffer() {\n return this._useReverseDepthBuffer;\n }\n set useReverseDepthBuffer(useReverse) {\n if (useReverse === this._useReverseDepthBuffer) {\n return;\n }\n this._useReverseDepthBuffer = useReverse;\n if (useReverse) {\n this._depthCullingState.depthFunc = 518;\n }\n else {\n this._depthCullingState.depthFunc = 515;\n }\n }\n /**\n * Gets the current frame id\n */\n get frameId() {\n return this._frameId;\n }\n /**\n * Gets a boolean indicating that the engine supports uniform buffers\n * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets\n */\n get supportsUniformBuffers() {\n return this.webGLVersion > 1 && !this.disableUniformBuffers;\n }\n /**\n * Gets the options used for engine creation\n * @returns EngineOptions object\n */\n getCreationOptions() {\n return this._creationOptions;\n }\n /** @internal */\n get _shouldUseHighPrecisionShader() {\n return !!(this._caps.highPrecisionShaderSupported && this._highPrecisionShadersAllowed);\n }\n /**\n * Gets a boolean indicating that only power of 2 textures are supported\n * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them\n */\n get needPOTTextures() {\n return this._webGLVersion < 2 || this.forcePOTTextures;\n }\n /**\n * Gets the list of current active render loop functions\n * @returns an array with the current render loop functions\n */\n get activeRenderLoops() {\n return this._activeRenderLoops;\n }\n /**\n * Gets or sets a boolean indicating if resources should be retained to be able to handle context lost events\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#handling-webgl-context-lost\n */\n get doNotHandleContextLost() {\n return this._doNotHandleContextLost;\n }\n set doNotHandleContextLost(value) {\n this._doNotHandleContextLost = value;\n }\n get _supportsHardwareTextureRescaling() {\n return false;\n }\n /**\n * sets the object from which width and height will be taken from when getting render width and height\n * Will fallback to the gl object\n * @param dimensions the framebuffer width and height that will be used.\n */\n set framebufferDimensionsObject(dimensions) {\n this._framebufferDimensionsObject = dimensions;\n }\n /**\n * Gets the current viewport\n */\n get currentViewport() {\n return this._cachedViewport;\n }\n /**\n * Gets the default empty texture\n */\n get emptyTexture() {\n if (!this._emptyTexture) {\n this._emptyTexture = this.createRawTexture(new Uint8Array(4), 1, 1, 5, false, false, 1);\n }\n return this._emptyTexture;\n }\n /**\n * Gets the default empty 3D texture\n */\n get emptyTexture3D() {\n if (!this._emptyTexture3D) {\n this._emptyTexture3D = this.createRawTexture3D(new Uint8Array(4), 1, 1, 1, 5, false, false, 1);\n }\n return this._emptyTexture3D;\n }\n /**\n * Gets the default empty 2D array texture\n */\n get emptyTexture2DArray() {\n if (!this._emptyTexture2DArray) {\n this._emptyTexture2DArray = this.createRawTexture2DArray(new Uint8Array(4), 1, 1, 1, 5, false, false, 1);\n }\n return this._emptyTexture2DArray;\n }\n /**\n * Gets the default empty cube texture\n */\n get emptyCubeTexture() {\n if (!this._emptyCubeTexture) {\n const faceData = new Uint8Array(4);\n const cubeData = [faceData, faceData, faceData, faceData, faceData, faceData];\n this._emptyCubeTexture = this.createRawCubeTexture(cubeData, 1, 5, 0, false, false, 1);\n }\n return this._emptyCubeTexture;\n }\n /**\n * Gets a boolean indicating if the engine runs in WebGPU or not.\n */\n get isWebGPU() {\n return this._isWebGPU;\n }\n /**\n * Gets the shader platform name used by the effects.\n */\n get shaderPlatformName() {\n return this._shaderPlatformName;\n }\n /**\n * Enables or disables the snapshot rendering mode\n * Note that the WebGL engine does not support snapshot rendering so setting the value won't have any effect for this engine\n */\n get snapshotRendering() {\n return false;\n }\n set snapshotRendering(activate) {\n // WebGL engine does not support snapshot rendering\n }\n /**\n * Gets or sets the snapshot rendering mode\n */\n get snapshotRenderingMode() {\n return this._snapshotRenderingMode;\n }\n set snapshotRenderingMode(mode) {\n this._snapshotRenderingMode = mode;\n }\n /**\n * Creates a new snapshot at the next frame using the current snapshotRenderingMode\n */\n snapshotRenderingReset() {\n this.snapshotRendering = false;\n }\n static _CreateCanvas(width, height) {\n if (typeof document === \"undefined\") {\n return new OffscreenCanvas(width, height);\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n return canvas;\n }\n /**\n * Create a canvas. This method is overridden by other engines\n * @param width width\n * @param height height\n * @returns ICanvas interface\n */\n createCanvas(width, height) {\n return ThinEngine._CreateCanvas(width, height);\n }\n /**\n * Create an image to use with canvas\n * @returns IImage interface\n */\n createCanvasImage() {\n return document.createElement(\"img\");\n }\n /**\n * Creates a new engine\n * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context\n * @param antialias defines enable antialiasing (default: false)\n * @param options defines further options to be sent to the getContext() function\n * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)\n */\n constructor(canvasOrContext, antialias, options, adaptToDeviceRatio) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;\n /** @internal */\n this._name = \"WebGL\";\n this._isDisposed = false;\n /**\n * Gets or sets a boolean that indicates if textures must be forced to power of 2 size even if not required\n */\n this.forcePOTTextures = false;\n /**\n * Gets a boolean indicating if the engine is currently rendering in fullscreen mode\n */\n this.isFullscreen = false;\n /**\n * Gets or sets a boolean indicating if back faces must be culled. If false, front faces are culled instead (true by default)\n * If non null, this takes precedence over the value from the material\n */\n this.cullBackFaces = null;\n /**\n * Gets or sets a boolean indicating if the engine must keep rendering even if the window is not in foreground\n */\n this.renderEvenInBackground = true;\n /**\n * Gets or sets a boolean indicating that cache can be kept between frames\n */\n this.preventCacheWipeBetweenFrames = false;\n /** Gets or sets a boolean indicating if the engine should validate programs after compilation */\n this.validateShaderPrograms = false;\n this._useReverseDepthBuffer = false;\n /**\n * Indicates if the z range in NDC space is 0..1 (value: true) or -1..1 (value: false)\n */\n this.isNDCHalfZRange = false;\n /**\n * Indicates that the origin of the texture/framebuffer space is the bottom left corner. If false, the origin is top left\n */\n this.hasOriginBottomLeft = true;\n /**\n * Gets or sets a boolean indicating that uniform buffers must be disabled even if they are supported\n */\n this.disableUniformBuffers = false;\n /**\n * An event triggered when the engine is disposed.\n */\n this.onDisposeObservable = new Observable$1();\n this._frameId = 0;\n /** @internal */\n this._uniformBuffers = new Array();\n /** @internal */\n this._storageBuffers = new Array();\n /** @internal */\n this._webGLVersion = 1.0;\n this._windowIsBackground = false;\n this._highPrecisionShadersAllowed = true;\n /** @internal */\n this._badOS = false;\n /** @internal */\n this._badDesktopOS = false;\n this._renderingQueueLaunched = false;\n this._activeRenderLoops = new Array();\n // Lost context\n /**\n * Observable signaled when a context lost event is raised\n */\n this.onContextLostObservable = new Observable$1();\n /**\n * Observable signaled when a context restored event is raised\n */\n this.onContextRestoredObservable = new Observable$1();\n this._contextWasLost = false;\n /** @internal */\n this._doNotHandleContextLost = false;\n /**\n * Gets or sets a boolean indicating that vertex array object must be disabled even if they are supported\n */\n this.disableVertexArrayObjects = false;\n // States\n /** @internal */\n this._colorWrite = true;\n /** @internal */\n this._colorWriteChanged = true;\n /** @internal */\n this._depthCullingState = new DepthCullingState();\n /** @internal */\n this._stencilStateComposer = new StencilStateComposer();\n /** @internal */\n this._stencilState = new StencilState();\n /** @internal */\n this._alphaState = new AlphaState();\n /** @internal */\n this._alphaMode = 1;\n /** @internal */\n this._alphaEquation = 0;\n // Cache\n /** @internal */\n this._internalTexturesCache = new Array();\n /** @internal */\n this._renderTargetWrapperCache = new Array();\n /** @internal */\n this._activeChannel = 0;\n this._currentTextureChannel = -1;\n /** @internal */\n this._boundTexturesCache = {};\n this._compiledEffects = {};\n this._vertexAttribArraysEnabled = [];\n this._uintIndicesCurrentlySet = false;\n this._currentBoundBuffer = new Array();\n /** @internal */\n this._currentFramebuffer = null;\n /** @internal */\n this._dummyFramebuffer = null;\n this._currentBufferPointers = new Array();\n this._currentInstanceLocations = new Array();\n this._currentInstanceBuffers = new Array();\n this._vaoRecordInProgress = false;\n this._mustWipeVertexAttributes = false;\n this._nextFreeTextureSlots = new Array();\n this._maxSimultaneousTextures = 0;\n this._maxMSAASamplesOverride = null;\n this._activeRequests = new Array();\n /**\n * If set to true zooming in and out in the browser will rescale the hardware-scaling correctly.\n */\n this.adaptToDeviceRatio = false;\n /** @internal */\n this._lastDevicePixelRatio = 1.0;\n /** @internal */\n this._transformTextureUrl = null;\n /**\n * Gets information about the current host\n */\n this.hostInformation = {\n isMobile: false,\n };\n /**\n * Defines whether the engine has been created with the premultipliedAlpha option on or not.\n */\n this.premultipliedAlpha = true;\n /**\n * Observable event triggered before each texture is initialized\n */\n this.onBeforeTextureInitObservable = new Observable$1();\n /** @internal */\n this._isWebGPU = false;\n this._snapshotRenderingMode = 0;\n this._viewportCached = { x: 0, y: 0, z: 0, w: 0 };\n this._unpackFlipYCached = null;\n /**\n * In case you are sharing the context with other applications, it might\n * be interested to not cache the unpack flip y state to ensure a consistent\n * value would be set.\n */\n this.enableUnpackFlipYCached = true;\n this._boundUniforms = {};\n this.startTime = PrecisionDate.Now;\n let canvas = null;\n options = options || {};\n this._creationOptions = options;\n // Save this off for use in resize().\n this.adaptToDeviceRatio = adaptToDeviceRatio !== null && adaptToDeviceRatio !== void 0 ? adaptToDeviceRatio : false;\n this._stencilStateComposer.stencilGlobal = this._stencilState;\n PerformanceConfigurator.SetMatrixPrecision(!!options.useHighPrecisionMatrix);\n options.antialias = antialias !== null && antialias !== void 0 ? antialias : options.antialias;\n options.deterministicLockstep = (_a = options.deterministicLockstep) !== null && _a !== void 0 ? _a : false;\n options.lockstepMaxSteps = (_b = options.lockstepMaxSteps) !== null && _b !== void 0 ? _b : 4;\n options.timeStep = (_c = options.timeStep) !== null && _c !== void 0 ? _c : 1 / 60;\n options.audioEngine = (_d = options.audioEngine) !== null && _d !== void 0 ? _d : true;\n options.stencil = (_e = options.stencil) !== null && _e !== void 0 ? _e : true;\n this._audioContext = (_g = (_f = options.audioEngineOptions) === null || _f === void 0 ? void 0 : _f.audioContext) !== null && _g !== void 0 ? _g : null;\n this._audioDestination = (_j = (_h = options.audioEngineOptions) === null || _h === void 0 ? void 0 : _h.audioDestination) !== null && _j !== void 0 ? _j : null;\n this.premultipliedAlpha = (_k = options.premultipliedAlpha) !== null && _k !== void 0 ? _k : true;\n this.useExactSrgbConversions = (_l = options.useExactSrgbConversions) !== null && _l !== void 0 ? _l : false;\n this._doNotHandleContextLost = !!options.doNotHandleContextLost;\n this._isStencilEnable = options.stencil ? true : false;\n // Viewport\n adaptToDeviceRatio = adaptToDeviceRatio || options.adaptToDeviceRatio || false;\n const devicePixelRatio = IsWindowObjectExist() ? window.devicePixelRatio || 1.0 : 1.0;\n const limitDeviceRatio = options.limitDeviceRatio || devicePixelRatio;\n this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, devicePixelRatio) : 1.0;\n this._lastDevicePixelRatio = devicePixelRatio;\n if (!canvasOrContext) {\n return;\n }\n if (canvasOrContext.getContext) {\n canvas = canvasOrContext;\n this._renderingCanvas = canvas;\n if (options.preserveDrawingBuffer === undefined) {\n options.preserveDrawingBuffer = false;\n }\n if (options.xrCompatible === undefined) {\n options.xrCompatible = true;\n }\n // Exceptions\n if (navigator && navigator.userAgent) {\n this._setupMobileChecks();\n const ua = navigator.userAgent;\n for (const exception of ThinEngine.ExceptionList) {\n const key = exception.key;\n const targets = exception.targets;\n const check = new RegExp(key);\n if (check.test(ua)) {\n if (exception.capture && exception.captureConstraint) {\n const capture = exception.capture;\n const constraint = exception.captureConstraint;\n const regex = new RegExp(capture);\n const matches = regex.exec(ua);\n if (matches && matches.length > 0) {\n const capturedValue = parseInt(matches[matches.length - 1]);\n if (capturedValue >= constraint) {\n continue;\n }\n }\n }\n for (const target of targets) {\n switch (target) {\n case \"uniformBuffer\":\n this.disableUniformBuffers = true;\n break;\n case \"vao\":\n this.disableVertexArrayObjects = true;\n break;\n case \"antialias\":\n options.antialias = false;\n break;\n case \"maxMSAASamples\":\n this._maxMSAASamplesOverride = 1;\n break;\n }\n }\n }\n }\n }\n // Context lost\n if (!this._doNotHandleContextLost) {\n this._onContextLost = (evt) => {\n evt.preventDefault();\n this._contextWasLost = true;\n Logger.Warn(\"WebGL context lost.\");\n this.onContextLostObservable.notifyObservers(this);\n };\n this._onContextRestored = () => {\n this._restoreEngineAfterContextLost(this._initGLContext.bind(this));\n };\n canvas.addEventListener(\"webglcontextlost\", this._onContextLost, false);\n canvas.addEventListener(\"webglcontextrestored\", this._onContextRestored, false);\n options.powerPreference = options.powerPreference || \"high-performance\";\n }\n // Detect if we are running on a faulty buggy desktop OS.\n this._badDesktopOS = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n if (this._badDesktopOS) {\n options.xrCompatible = false;\n }\n // GL\n if (!options.disableWebGL2Support) {\n try {\n this._gl = (canvas.getContext(\"webgl2\", options) || canvas.getContext(\"experimental-webgl2\", options));\n if (this._gl) {\n this._webGLVersion = 2.0;\n this._shaderPlatformName = \"WEBGL2\";\n // Prevent weird browsers to lie (yeah that happens!)\n if (!this._gl.deleteQuery) {\n this._webGLVersion = 1.0;\n this._shaderPlatformName = \"WEBGL1\";\n }\n }\n }\n catch (e) {\n // Do nothing\n }\n }\n if (!this._gl) {\n if (!canvas) {\n throw new Error(\"The provided canvas is null or undefined.\");\n }\n try {\n this._gl = (canvas.getContext(\"webgl\", options) || canvas.getContext(\"experimental-webgl\", options));\n }\n catch (e) {\n throw new Error(\"WebGL not supported\");\n }\n }\n if (!this._gl) {\n throw new Error(\"WebGL not supported\");\n }\n }\n else {\n this._gl = canvasOrContext;\n this._renderingCanvas = this._gl.canvas;\n if (this._gl.renderbufferStorageMultisample) {\n this._webGLVersion = 2.0;\n this._shaderPlatformName = \"WEBGL2\";\n }\n else {\n this._shaderPlatformName = \"WEBGL1\";\n }\n const attributes = this._gl.getContextAttributes();\n if (attributes) {\n options.stencil = attributes.stencil;\n }\n }\n // Ensures a consistent color space unpacking of textures cross browser.\n this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);\n if (options.useHighPrecisionFloats !== undefined) {\n this._highPrecisionShadersAllowed = options.useHighPrecisionFloats;\n }\n this.resize();\n this._initGLContext();\n this._initFeatures();\n // Prepare buffer pointers\n for (let i = 0; i < this._caps.maxVertexAttribs; i++) {\n this._currentBufferPointers[i] = new BufferPointer();\n }\n // Shader processor\n this._shaderProcessor = this.webGLVersion > 1 ? new WebGL2ShaderProcessor() : new WebGLShaderProcessor();\n // Detect if we are running on a faulty buggy OS.\n this._badOS = /iPad/i.test(navigator.userAgent) || /iPhone/i.test(navigator.userAgent);\n // Starting with iOS 14, we can trust the browser\n // let matches = navigator.userAgent.match(/Version\\/(\\d+)/);\n // if (matches && matches.length === 2) {\n // if (parseInt(matches[1]) >= 14) {\n // this._badOS = false;\n // }\n // }\n const versionToLog = `Babylon.js v${ThinEngine.Version}`;\n console.log(versionToLog + ` - ${this.description}`);\n // Check setAttribute in case of workers\n if (this._renderingCanvas && this._renderingCanvas.setAttribute) {\n this._renderingCanvas.setAttribute(\"data-engine\", versionToLog);\n }\n }\n _setupMobileChecks() {\n if (!(navigator && navigator.userAgent)) {\n return;\n }\n // Function to check if running on mobile device\n this._checkForMobile = () => {\n const currentUA = navigator.userAgent;\n this.hostInformation.isMobile =\n currentUA.indexOf(\"Mobile\") !== -1 ||\n // Needed for iOS 13+ detection on iPad (inspired by solution from https://stackoverflow.com/questions/9038625/detect-if-device-is-ios)\n (currentUA.indexOf(\"Mac\") !== -1 && IsDocumentAvailable() && \"ontouchend\" in document);\n };\n // Set initial isMobile value\n this._checkForMobile();\n // Set up event listener to check when window is resized (used to get emulator activation to work properly)\n if (IsWindowObjectExist()) {\n window.addEventListener(\"resize\", this._checkForMobile);\n }\n }\n _restoreEngineAfterContextLost(initEngine) {\n // Adding a timeout to avoid race condition at browser level\n setTimeout(async () => {\n var _a;\n this._dummyFramebuffer = null;\n const depthTest = this._depthCullingState.depthTest; // backup those values because the call to initEngine / wipeCaches will reset them\n const depthFunc = this._depthCullingState.depthFunc;\n const depthMask = this._depthCullingState.depthMask;\n const stencilTest = this._stencilState.stencilTest;\n // Rebuild context\n await initEngine();\n // Ensure webgl and engine states are matching\n this.wipeCaches(true);\n // Rebuild effects\n this._rebuildEffects();\n (_a = this._rebuildComputeEffects) === null || _a === void 0 ? void 0 : _a.call(this);\n // Note:\n // The call to _rebuildBuffers must be made before the call to _rebuildInternalTextures because in the process of _rebuildBuffers the buffers used by the post process managers will be rebuilt\n // and we may need to use the post process manager of the scene during _rebuildInternalTextures (in WebGL1, non-POT textures are rescaled using a post process + post process manager of the scene)\n // Rebuild buffers\n this._rebuildBuffers();\n // Rebuild textures\n this._rebuildInternalTextures();\n // Rebuild textures\n this._rebuildRenderTargetWrappers();\n // Reset engine states after all the buffer/textures/... have been rebuilt\n this.wipeCaches(true);\n this._depthCullingState.depthTest = depthTest;\n this._depthCullingState.depthFunc = depthFunc;\n this._depthCullingState.depthMask = depthMask;\n this._stencilState.stencilTest = stencilTest;\n Logger.Warn(this.name + \" context successfully restored.\");\n this.onContextRestoredObservable.notifyObservers(this);\n this._contextWasLost = false;\n }, 0);\n }\n /**\n * Shared initialization across engines types.\n * @param canvas The canvas associated with this instance of the engine.\n */\n _sharedInit(canvas) {\n this._renderingCanvas = canvas;\n }\n /**\n * @internal\n */\n _getShaderProcessingContext(shaderLanguage) {\n return null;\n }\n _rebuildInternalTextures() {\n const currentState = this._internalTexturesCache.slice(); // Do a copy because the rebuild will add proxies\n for (const internalTexture of currentState) {\n internalTexture._rebuild();\n }\n }\n _rebuildRenderTargetWrappers() {\n const currentState = this._renderTargetWrapperCache.slice(); // Do a copy because the rebuild will add proxies\n for (const renderTargetWrapper of currentState) {\n renderTargetWrapper._rebuild();\n }\n }\n _rebuildEffects() {\n for (const key in this._compiledEffects) {\n const effect = this._compiledEffects[key];\n effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\n effect._wasPreviouslyReady = false;\n effect._prepareEffect();\n }\n Effect.ResetCache();\n }\n /**\n * Gets a boolean indicating if all created effects are ready\n * @returns true if all effects are ready\n */\n areAllEffectsReady() {\n for (const key in this._compiledEffects) {\n const effect = this._compiledEffects[key];\n if (!effect.isReady()) {\n return false;\n }\n }\n return true;\n }\n _rebuildBuffers() {\n // Uniforms\n for (const uniformBuffer of this._uniformBuffers) {\n uniformBuffer._rebuild();\n }\n // Storage buffers\n for (const storageBuffer of this._storageBuffers) {\n storageBuffer._rebuild();\n }\n }\n _initGLContext() {\n var _a;\n // Caps\n this._caps = {\n maxTexturesImageUnits: this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),\n maxCombinedTexturesImageUnits: this._gl.getParameter(this._gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),\n maxVertexTextureImageUnits: this._gl.getParameter(this._gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),\n maxTextureSize: this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),\n maxSamples: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_SAMPLES) : 1,\n maxCubemapTextureSize: this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),\n maxRenderTextureSize: this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),\n maxVertexAttribs: this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS),\n maxVaryingVectors: this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),\n maxFragmentUniformVectors: this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),\n maxVertexUniformVectors: this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),\n parallelShaderCompile: this._gl.getExtension(\"KHR_parallel_shader_compile\") || undefined,\n standardDerivatives: this._webGLVersion > 1 || this._gl.getExtension(\"OES_standard_derivatives\") !== null,\n maxAnisotropy: 1,\n astc: this._gl.getExtension(\"WEBGL_compressed_texture_astc\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_astc\"),\n bptc: this._gl.getExtension(\"EXT_texture_compression_bptc\") || this._gl.getExtension(\"WEBKIT_EXT_texture_compression_bptc\"),\n s3tc: this._gl.getExtension(\"WEBGL_compressed_texture_s3tc\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_s3tc\"),\n // eslint-disable-next-line @typescript-eslint/naming-convention\n s3tc_srgb: this._gl.getExtension(\"WEBGL_compressed_texture_s3tc_srgb\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_s3tc_srgb\"),\n pvrtc: this._gl.getExtension(\"WEBGL_compressed_texture_pvrtc\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_pvrtc\"),\n etc1: this._gl.getExtension(\"WEBGL_compressed_texture_etc1\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_etc1\"),\n etc2: this._gl.getExtension(\"WEBGL_compressed_texture_etc\") ||\n this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_etc\") ||\n this._gl.getExtension(\"WEBGL_compressed_texture_es3_0\"),\n textureAnisotropicFilterExtension: this._gl.getExtension(\"EXT_texture_filter_anisotropic\") ||\n this._gl.getExtension(\"WEBKIT_EXT_texture_filter_anisotropic\") ||\n this._gl.getExtension(\"MOZ_EXT_texture_filter_anisotropic\"),\n uintIndices: this._webGLVersion > 1 || this._gl.getExtension(\"OES_element_index_uint\") !== null,\n fragmentDepthSupported: this._webGLVersion > 1 || this._gl.getExtension(\"EXT_frag_depth\") !== null,\n highPrecisionShaderSupported: false,\n timerQuery: this._gl.getExtension(\"EXT_disjoint_timer_query_webgl2\") || this._gl.getExtension(\"EXT_disjoint_timer_query\"),\n supportOcclusionQuery: this._webGLVersion > 1,\n canUseTimestampForTimerQuery: false,\n drawBuffersExtension: false,\n maxMSAASamples: 1,\n colorBufferFloat: !!(this._webGLVersion > 1 && this._gl.getExtension(\"EXT_color_buffer_float\")),\n colorBufferHalfFloat: !!(this._webGLVersion > 1 && this._gl.getExtension(\"EXT_color_buffer_half_float\")),\n textureFloat: this._webGLVersion > 1 || this._gl.getExtension(\"OES_texture_float\") ? true : false,\n textureHalfFloat: this._webGLVersion > 1 || this._gl.getExtension(\"OES_texture_half_float\") ? true : false,\n textureHalfFloatRender: false,\n textureFloatLinearFiltering: false,\n textureFloatRender: false,\n textureHalfFloatLinearFiltering: false,\n vertexArrayObject: false,\n instancedArrays: false,\n textureLOD: this._webGLVersion > 1 || this._gl.getExtension(\"EXT_shader_texture_lod\") ? true : false,\n texelFetch: this._webGLVersion !== 1,\n blendMinMax: false,\n multiview: this._gl.getExtension(\"OVR_multiview2\"),\n oculusMultiview: this._gl.getExtension(\"OCULUS_multiview\"),\n depthTextureExtension: false,\n canUseGLInstanceID: this._webGLVersion > 1,\n canUseGLVertexID: this._webGLVersion > 1,\n supportComputeShaders: false,\n supportSRGBBuffers: false,\n supportTransformFeedbacks: this._webGLVersion > 1,\n textureMaxLevel: this._webGLVersion > 1,\n texture2DArrayMaxLayerCount: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_ARRAY_TEXTURE_LAYERS) : 128,\n disableMorphTargetTexture: false,\n };\n // Infos\n this._glVersion = this._gl.getParameter(this._gl.VERSION);\n const rendererInfo = this._gl.getExtension(\"WEBGL_debug_renderer_info\");\n if (rendererInfo != null) {\n this._glRenderer = this._gl.getParameter(rendererInfo.UNMASKED_RENDERER_WEBGL);\n this._glVendor = this._gl.getParameter(rendererInfo.UNMASKED_VENDOR_WEBGL);\n }\n if (!this._glVendor) {\n this._glVendor = this._gl.getParameter(this._gl.VENDOR) || \"Unknown vendor\";\n }\n if (!this._glRenderer) {\n this._glRenderer = this._gl.getParameter(this._gl.RENDERER) || \"Unknown renderer\";\n }\n // Constants\n if (this._gl.HALF_FLOAT_OES !== 0x8d61) {\n this._gl.HALF_FLOAT_OES = 0x8d61; // Half floating-point type (16-bit).\n }\n if (this._gl.RGBA16F !== 0x881a) {\n this._gl.RGBA16F = 0x881a; // RGBA 16-bit floating-point color-renderable internal sized format.\n }\n if (this._gl.RGBA32F !== 0x8814) {\n this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.\n }\n if (this._gl.DEPTH24_STENCIL8 !== 35056) {\n this._gl.DEPTH24_STENCIL8 = 35056;\n }\n // Extensions\n if (this._caps.timerQuery) {\n if (this._webGLVersion === 1) {\n this._gl.getQuery = this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery);\n }\n // WebGLQuery casted to number to avoid TS error\n this._caps.canUseTimestampForTimerQuery = ((_a = this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT, this._caps.timerQuery.QUERY_COUNTER_BITS_EXT)) !== null && _a !== void 0 ? _a : 0) > 0;\n }\n this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension\n ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT)\n : 0;\n this._caps.textureFloatLinearFiltering = this._caps.textureFloat && this._gl.getExtension(\"OES_texture_float_linear\") ? true : false;\n this._caps.textureFloatRender = this._caps.textureFloat && this._canRenderToFloatFramebuffer() ? true : false;\n this._caps.textureHalfFloatLinearFiltering =\n this._webGLVersion > 1 || (this._caps.textureHalfFloat && this._gl.getExtension(\"OES_texture_half_float_linear\")) ? true : false;\n // Compressed formats\n if (this._caps.astc) {\n this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;\n }\n if (this._caps.bptc) {\n this._gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = this._caps.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;\n }\n if (this._caps.s3tc_srgb) {\n this._gl.COMPRESSED_SRGB_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_S3TC_DXT1_EXT;\n this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;\n this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;\n }\n if (this._caps.etc2) {\n this._gl.COMPRESSED_SRGB8_ETC2 = this._caps.etc2.COMPRESSED_SRGB8_ETC2;\n this._gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = this._caps.etc2.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;\n }\n // Checks if some of the format renders first to allow the use of webgl inspector.\n if (this._webGLVersion > 1) {\n if (this._gl.HALF_FLOAT_OES !== 0x140b) {\n this._gl.HALF_FLOAT_OES = 0x140b;\n }\n }\n this._caps.textureHalfFloatRender = this._caps.textureHalfFloat && this._canRenderToHalfFloatFramebuffer();\n // Draw buffers\n if (this._webGLVersion > 1) {\n this._caps.drawBuffersExtension = true;\n this._caps.maxMSAASamples = this._maxMSAASamplesOverride !== null ? this._maxMSAASamplesOverride : this._gl.getParameter(this._gl.MAX_SAMPLES);\n }\n else {\n const drawBuffersExtension = this._gl.getExtension(\"WEBGL_draw_buffers\");\n if (drawBuffersExtension !== null) {\n this._caps.drawBuffersExtension = true;\n this._gl.drawBuffers = drawBuffersExtension.drawBuffersWEBGL.bind(drawBuffersExtension);\n this._gl.DRAW_FRAMEBUFFER = this._gl.FRAMEBUFFER;\n for (let i = 0; i < 16; i++) {\n this._gl[\"COLOR_ATTACHMENT\" + i + \"_WEBGL\"] = drawBuffersExtension[\"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\n }\n }\n }\n // Depth Texture\n if (this._webGLVersion > 1) {\n this._caps.depthTextureExtension = true;\n }\n else {\n const depthTextureExtension = this._gl.getExtension(\"WEBGL_depth_texture\");\n if (depthTextureExtension != null) {\n this._caps.depthTextureExtension = true;\n this._gl.UNSIGNED_INT_24_8 = depthTextureExtension.UNSIGNED_INT_24_8_WEBGL;\n }\n }\n // Vertex array object\n if (this.disableVertexArrayObjects) {\n this._caps.vertexArrayObject = false;\n }\n else if (this._webGLVersion > 1) {\n this._caps.vertexArrayObject = true;\n }\n else {\n const vertexArrayObjectExtension = this._gl.getExtension(\"OES_vertex_array_object\");\n if (vertexArrayObjectExtension != null) {\n this._caps.vertexArrayObject = true;\n this._gl.createVertexArray = vertexArrayObjectExtension.createVertexArrayOES.bind(vertexArrayObjectExtension);\n this._gl.bindVertexArray = vertexArrayObjectExtension.bindVertexArrayOES.bind(vertexArrayObjectExtension);\n this._gl.deleteVertexArray = vertexArrayObjectExtension.deleteVertexArrayOES.bind(vertexArrayObjectExtension);\n }\n }\n // Instances count\n if (this._webGLVersion > 1) {\n this._caps.instancedArrays = true;\n }\n else {\n const instanceExtension = this._gl.getExtension(\"ANGLE_instanced_arrays\");\n if (instanceExtension != null) {\n this._caps.instancedArrays = true;\n this._gl.drawArraysInstanced = instanceExtension.drawArraysInstancedANGLE.bind(instanceExtension);\n this._gl.drawElementsInstanced = instanceExtension.drawElementsInstancedANGLE.bind(instanceExtension);\n this._gl.vertexAttribDivisor = instanceExtension.vertexAttribDivisorANGLE.bind(instanceExtension);\n }\n else {\n this._caps.instancedArrays = false;\n }\n }\n if (this._gl.getShaderPrecisionFormat) {\n const vertexhighp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.HIGH_FLOAT);\n const fragmenthighp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);\n if (vertexhighp && fragmenthighp) {\n this._caps.highPrecisionShaderSupported = vertexhighp.precision !== 0 && fragmenthighp.precision !== 0;\n }\n }\n if (this._webGLVersion > 1) {\n this._caps.blendMinMax = true;\n }\n else {\n const blendMinMaxExtension = this._gl.getExtension(\"EXT_blend_minmax\");\n if (blendMinMaxExtension != null) {\n this._caps.blendMinMax = true;\n this._gl.MAX = blendMinMaxExtension.MAX_EXT;\n this._gl.MIN = blendMinMaxExtension.MIN_EXT;\n }\n }\n // sRGB buffers\n // only run this if not already set to true (in the constructor, for example)\n if (!this._caps.supportSRGBBuffers) {\n if (this._webGLVersion > 1) {\n this._caps.supportSRGBBuffers = true;\n this._glSRGBExtensionValues = {\n SRGB: WebGL2RenderingContext.SRGB,\n SRGB8: WebGL2RenderingContext.SRGB8,\n SRGB8_ALPHA8: WebGL2RenderingContext.SRGB8_ALPHA8,\n };\n }\n else {\n const sRGBExtension = this._gl.getExtension(\"EXT_sRGB\");\n if (sRGBExtension != null) {\n this._caps.supportSRGBBuffers = true;\n this._glSRGBExtensionValues = {\n SRGB: sRGBExtension.SRGB_EXT,\n SRGB8: sRGBExtension.SRGB_ALPHA_EXT,\n SRGB8_ALPHA8: sRGBExtension.SRGB_ALPHA_EXT,\n };\n }\n }\n // take into account the forced state that was provided in options\n // When the issue in angle/chrome is fixed the flag should be taken into account only when it is explicitly defined\n this._caps.supportSRGBBuffers = this._caps.supportSRGBBuffers && !!(this._creationOptions && this._creationOptions.forceSRGBBufferSupportState);\n }\n // Depth buffer\n this._depthCullingState.depthTest = true;\n this._depthCullingState.depthFunc = this._gl.LEQUAL;\n this._depthCullingState.depthMask = true;\n // Texture maps\n this._maxSimultaneousTextures = this._caps.maxCombinedTexturesImageUnits;\n for (let slot = 0; slot < this._maxSimultaneousTextures; slot++) {\n this._nextFreeTextureSlots.push(slot);\n }\n if (this._glRenderer === \"Mali-G72\") {\n // Overcome a bug when using a texture to store morph targets on Mali-G72\n this._caps.disableMorphTargetTexture = true;\n }\n }\n _initFeatures() {\n this._features = {\n forceBitmapOverHTMLImageElement: false,\n supportRenderAndCopyToLodForFloatTextures: this._webGLVersion !== 1,\n supportDepthStencilTexture: this._webGLVersion !== 1,\n supportShadowSamplers: this._webGLVersion !== 1,\n uniformBufferHardCheckMatrix: false,\n allowTexturePrefiltering: this._webGLVersion !== 1,\n trackUbosInFrame: false,\n checkUbosContentBeforeUpload: false,\n supportCSM: this._webGLVersion !== 1,\n basisNeedsPOT: this._webGLVersion === 1,\n support3DTextures: this._webGLVersion !== 1,\n needTypeSuffixInShaderConstants: this._webGLVersion !== 1,\n supportMSAA: this._webGLVersion !== 1,\n supportSSAO2: this._webGLVersion !== 1,\n supportExtendedTextureFormats: this._webGLVersion !== 1,\n supportSwitchCaseInShader: this._webGLVersion !== 1,\n supportSyncTextureRead: true,\n needsInvertingBitmap: true,\n useUBOBindingCache: true,\n needShaderCodeInlining: false,\n needToAlwaysBindUniformBuffers: false,\n supportRenderPasses: false,\n supportSpriteInstancing: true,\n _collectUbosUpdatedInFrame: false,\n };\n }\n /**\n * Gets version of the current webGL context\n * Keep it for back compat - use version instead\n */\n get webGLVersion() {\n return this._webGLVersion;\n }\n /**\n * Gets a string identifying the name of the class\n * @returns \"Engine\" string\n */\n getClassName() {\n return \"ThinEngine\";\n }\n /**\n * Returns true if the stencil buffer has been enabled through the creation option of the context.\n */\n get isStencilEnable() {\n return this._isStencilEnable;\n }\n /** @internal */\n _prepareWorkingCanvas() {\n if (this._workingCanvas) {\n return;\n }\n this._workingCanvas = this.createCanvas(1, 1);\n const context = this._workingCanvas.getContext(\"2d\");\n if (context) {\n this._workingContext = context;\n }\n }\n /**\n * Reset the texture cache to empty state\n */\n resetTextureCache() {\n for (const key in this._boundTexturesCache) {\n if (!Object.prototype.hasOwnProperty.call(this._boundTexturesCache, key)) {\n continue;\n }\n this._boundTexturesCache[key] = null;\n }\n this._currentTextureChannel = -1;\n }\n /**\n * Gets an object containing information about the current engine context\n * @returns an object containing the vendor, the renderer and the version of the current engine context\n */\n getInfo() {\n return this.getGlInfo();\n }\n /**\n * Gets an object containing information about the current webGL context\n * @returns an object containing the vendor, the renderer and the version of the current webGL context\n */\n getGlInfo() {\n return {\n vendor: this._glVendor,\n renderer: this._glRenderer,\n version: this._glVersion,\n };\n }\n /**\n * Defines the hardware scaling level.\n * By default the hardware scaling level is computed from the window device ratio.\n * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.\n * @param level defines the level to use\n */\n setHardwareScalingLevel(level) {\n this._hardwareScalingLevel = level;\n this.resize();\n }\n /**\n * Gets the current hardware scaling level.\n * By default the hardware scaling level is computed from the window device ratio.\n * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.\n * @returns a number indicating the current hardware scaling level\n */\n getHardwareScalingLevel() {\n return this._hardwareScalingLevel;\n }\n /**\n * Gets the list of loaded textures\n * @returns an array containing all loaded textures\n */\n getLoadedTexturesCache() {\n return this._internalTexturesCache;\n }\n /**\n * Gets the object containing all engine capabilities\n * @returns the EngineCapabilities object\n */\n getCaps() {\n return this._caps;\n }\n /**\n * stop executing a render loop function and remove it from the execution array\n * @param renderFunction defines the function to be removed. If not provided all functions will be removed.\n */\n stopRenderLoop(renderFunction) {\n if (!renderFunction) {\n this._activeRenderLoops.length = 0;\n this._cancelFrame();\n return;\n }\n const index = this._activeRenderLoops.indexOf(renderFunction);\n if (index >= 0) {\n this._activeRenderLoops.splice(index, 1);\n if (this._activeRenderLoops.length == 0) {\n this._cancelFrame();\n }\n }\n }\n _cancelFrame() {\n if (this._renderingQueueLaunched && this._frameHandler) {\n this._renderingQueueLaunched = false;\n if (!IsWindowObjectExist()) {\n if (typeof cancelAnimationFrame === \"function\") {\n return cancelAnimationFrame(this._frameHandler);\n }\n }\n else {\n const { cancelAnimationFrame } = this.getHostWindow() || window;\n if (typeof cancelAnimationFrame === \"function\") {\n return cancelAnimationFrame(this._frameHandler);\n }\n }\n return clearTimeout(this._frameHandler);\n }\n }\n /** @internal */\n _renderLoop() {\n if (!this._contextWasLost) {\n let shouldRender = true;\n if (this._isDisposed || (!this.renderEvenInBackground && this._windowIsBackground)) {\n shouldRender = false;\n }\n if (shouldRender) {\n // Start new frame\n this.beginFrame();\n for (let index = 0; index < this._activeRenderLoops.length; index++) {\n const renderFunction = this._activeRenderLoops[index];\n renderFunction();\n }\n // Present\n this.endFrame();\n }\n }\n if (this._activeRenderLoops.length > 0) {\n this._frameHandler = this._queueNewFrame(this._boundRenderFunction, this.getHostWindow());\n }\n else {\n this._renderingQueueLaunched = false;\n }\n }\n /**\n * Gets the HTML canvas attached with the current webGL context\n * @returns a HTML canvas\n */\n getRenderingCanvas() {\n return this._renderingCanvas;\n }\n /**\n * Gets the audio context specified in engine initialization options\n * @returns an Audio Context\n */\n getAudioContext() {\n return this._audioContext;\n }\n /**\n * Gets the audio destination specified in engine initialization options\n * @returns an audio destination node\n */\n getAudioDestination() {\n return this._audioDestination;\n }\n /**\n * Gets host window\n * @returns the host window object\n */\n getHostWindow() {\n if (!IsWindowObjectExist()) {\n return null;\n }\n if (this._renderingCanvas && this._renderingCanvas.ownerDocument && this._renderingCanvas.ownerDocument.defaultView) {\n return this._renderingCanvas.ownerDocument.defaultView;\n }\n return window;\n }\n /**\n * Gets the current render width\n * @param useScreen defines if screen size must be used (or the current render target if any)\n * @returns a number defining the current render width\n */\n getRenderWidth(useScreen = false) {\n if (!useScreen && this._currentRenderTarget) {\n return this._currentRenderTarget.width;\n }\n return this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferWidth : this._gl.drawingBufferWidth;\n }\n /**\n * Gets the current render height\n * @param useScreen defines if screen size must be used (or the current render target if any)\n * @returns a number defining the current render height\n */\n getRenderHeight(useScreen = false) {\n if (!useScreen && this._currentRenderTarget) {\n return this._currentRenderTarget.height;\n }\n return this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferHeight : this._gl.drawingBufferHeight;\n }\n /**\n * Can be used to override the current requestAnimationFrame requester.\n * @internal\n */\n _queueNewFrame(bindedRenderFunction, requester) {\n return ThinEngine.QueueNewFrame(bindedRenderFunction, requester);\n }\n /**\n * Register and execute a render loop. The engine can have more than one render function\n * @param renderFunction defines the function to continuously execute\n */\n runRenderLoop(renderFunction) {\n if (this._activeRenderLoops.indexOf(renderFunction) !== -1) {\n return;\n }\n this._activeRenderLoops.push(renderFunction);\n if (!this._renderingQueueLaunched) {\n this._renderingQueueLaunched = true;\n this._boundRenderFunction = this._renderLoop.bind(this);\n this._frameHandler = this._queueNewFrame(this._boundRenderFunction, this.getHostWindow());\n }\n }\n /**\n * Clear the current render buffer or the current render target (if any is set up)\n * @param color defines the color to use\n * @param backBuffer defines if the back buffer must be cleared\n * @param depth defines if the depth buffer must be cleared\n * @param stencil defines if the stencil buffer must be cleared\n */\n clear(color, backBuffer, depth, stencil = false) {\n var _a, _b;\n const useStencilGlobalOnly = this.stencilStateComposer.useStencilGlobalOnly;\n this.stencilStateComposer.useStencilGlobalOnly = true; // make sure the stencil mask is coming from the global stencil and not from a material (effect) which would currently be in effect\n this.applyStates();\n this.stencilStateComposer.useStencilGlobalOnly = useStencilGlobalOnly;\n let mode = 0;\n if (backBuffer && color) {\n let setBackBufferColor = true;\n if (this._currentRenderTarget) {\n const textureFormat = (_a = this._currentRenderTarget.texture) === null || _a === void 0 ? void 0 : _a.format;\n if (textureFormat === 8 ||\n textureFormat === 9 ||\n textureFormat === 10 ||\n textureFormat === 11) {\n const textureType = (_b = this._currentRenderTarget.texture) === null || _b === void 0 ? void 0 : _b.type;\n if (textureType === 7 || textureType === 5) {\n ThinEngine._TempClearColorUint32[0] = color.r * 255;\n ThinEngine._TempClearColorUint32[1] = color.g * 255;\n ThinEngine._TempClearColorUint32[2] = color.b * 255;\n ThinEngine._TempClearColorUint32[3] = color.a * 255;\n this._gl.clearBufferuiv(this._gl.COLOR, 0, ThinEngine._TempClearColorUint32);\n setBackBufferColor = false;\n }\n else {\n ThinEngine._TempClearColorInt32[0] = color.r * 255;\n ThinEngine._TempClearColorInt32[1] = color.g * 255;\n ThinEngine._TempClearColorInt32[2] = color.b * 255;\n ThinEngine._TempClearColorInt32[3] = color.a * 255;\n this._gl.clearBufferiv(this._gl.COLOR, 0, ThinEngine._TempClearColorInt32);\n setBackBufferColor = false;\n }\n }\n }\n if (setBackBufferColor) {\n this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);\n mode |= this._gl.COLOR_BUFFER_BIT;\n }\n }\n if (depth) {\n if (this.useReverseDepthBuffer) {\n this._depthCullingState.depthFunc = this._gl.GEQUAL;\n this._gl.clearDepth(0.0);\n }\n else {\n this._gl.clearDepth(1.0);\n }\n mode |= this._gl.DEPTH_BUFFER_BIT;\n }\n if (stencil) {\n this._gl.clearStencil(0);\n mode |= this._gl.STENCIL_BUFFER_BIT;\n }\n this._gl.clear(mode);\n }\n /**\n * @internal\n */\n _viewport(x, y, width, height) {\n if (x !== this._viewportCached.x || y !== this._viewportCached.y || width !== this._viewportCached.z || height !== this._viewportCached.w) {\n this._viewportCached.x = x;\n this._viewportCached.y = y;\n this._viewportCached.z = width;\n this._viewportCached.w = height;\n this._gl.viewport(x, y, width, height);\n }\n }\n /**\n * Set the WebGL's viewport\n * @param viewport defines the viewport element to be used\n * @param requiredWidth defines the width required for rendering. If not provided the rendering canvas' width is used\n * @param requiredHeight defines the height required for rendering. If not provided the rendering canvas' height is used\n */\n setViewport(viewport, requiredWidth, requiredHeight) {\n const width = requiredWidth || this.getRenderWidth();\n const height = requiredHeight || this.getRenderHeight();\n const x = viewport.x || 0;\n const y = viewport.y || 0;\n this._cachedViewport = viewport;\n this._viewport(x * width, y * height, width * viewport.width, height * viewport.height);\n }\n /**\n * Begin a new frame\n */\n beginFrame() { }\n /**\n * Enf the current frame\n */\n endFrame() {\n // Force a flush in case we are using a bad OS.\n if (this._badOS) {\n this.flushFramebuffer();\n }\n this._frameId++;\n }\n /**\n * Resize the view according to the canvas' size\n * @param forceSetSize true to force setting the sizes of the underlying canvas\n */\n resize(forceSetSize = false) {\n let width;\n let height;\n // Re-query hardware scaling level to handle zoomed-in resizing.\n if (this.adaptToDeviceRatio) {\n const devicePixelRatio = IsWindowObjectExist() ? window.devicePixelRatio || 1.0 : 1.0;\n const changeRatio = this._lastDevicePixelRatio / devicePixelRatio;\n this._lastDevicePixelRatio = devicePixelRatio;\n this._hardwareScalingLevel *= changeRatio;\n }\n if (IsWindowObjectExist() && IsDocumentAvailable()) {\n // make sure it is a Node object, and is a part of the document.\n if (this._renderingCanvas) {\n const boundingRect = this._renderingCanvas.getBoundingClientRect\n ? this._renderingCanvas.getBoundingClientRect()\n : {\n // fallback to last solution in case the function doesn't exist\n width: this._renderingCanvas.width * this._hardwareScalingLevel,\n height: this._renderingCanvas.height * this._hardwareScalingLevel,\n };\n width = this._renderingCanvas.clientWidth || boundingRect.width || this._renderingCanvas.width || 100;\n height = this._renderingCanvas.clientHeight || boundingRect.height || this._renderingCanvas.height || 100;\n }\n else {\n width = window.innerWidth;\n height = window.innerHeight;\n }\n }\n else {\n width = this._renderingCanvas ? this._renderingCanvas.width : 100;\n height = this._renderingCanvas ? this._renderingCanvas.height : 100;\n }\n this.setSize(width / this._hardwareScalingLevel, height / this._hardwareScalingLevel, forceSetSize);\n }\n /**\n * Force a specific size of the canvas\n * @param width defines the new canvas' width\n * @param height defines the new canvas' height\n * @param forceSetSize true to force setting the sizes of the underlying canvas\n * @returns true if the size was changed\n */\n setSize(width, height, forceSetSize = false) {\n if (!this._renderingCanvas) {\n return false;\n }\n width = width | 0;\n height = height | 0;\n if (!forceSetSize && this._renderingCanvas.width === width && this._renderingCanvas.height === height) {\n return false;\n }\n this._renderingCanvas.width = width;\n this._renderingCanvas.height = height;\n return true;\n }\n /**\n * Binds the frame buffer to the specified texture.\n * @param rtWrapper The render target wrapper to render to\n * @param faceIndex The face of the texture to render to in case of cube texture and if the render target wrapper is not a multi render target\n * @param requiredWidth The width of the target to render to\n * @param requiredHeight The height of the target to render to\n * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true\n * @param lodLevel Defines the lod level to bind to the frame buffer\n * @param layer Defines the 2d array index to bind to the frame buffer if the render target wrapper is not a multi render target\n */\n bindFramebuffer(rtWrapper, faceIndex = 0, requiredWidth, requiredHeight, forceFullscreenViewport, lodLevel = 0, layer = 0) {\n var _a, _b, _c, _d, _e;\n const webglRTWrapper = rtWrapper;\n if (this._currentRenderTarget) {\n this.unBindFramebuffer(this._currentRenderTarget);\n }\n this._currentRenderTarget = rtWrapper;\n this._bindUnboundFramebuffer(webglRTWrapper._MSAAFramebuffer ? webglRTWrapper._MSAAFramebuffer : webglRTWrapper._framebuffer);\n const gl = this._gl;\n if (!rtWrapper.isMulti) {\n if (rtWrapper.is2DArray) {\n gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, (_a = rtWrapper.texture._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource, lodLevel, layer);\n }\n else if (rtWrapper.isCube) {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, (_b = rtWrapper.texture._hardwareTexture) === null || _b === void 0 ? void 0 : _b.underlyingResource, lodLevel);\n }\n }\n const depthStencilTexture = rtWrapper._depthStencilTexture;\n if (depthStencilTexture) {\n const attachment = rtWrapper._depthStencilTextureWithStencil ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;\n if (rtWrapper.is2DArray) {\n gl.framebufferTextureLayer(gl.FRAMEBUFFER, attachment, (_c = depthStencilTexture._hardwareTexture) === null || _c === void 0 ? void 0 : _c.underlyingResource, lodLevel, layer);\n }\n else if (rtWrapper.isCube) {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, (_d = depthStencilTexture._hardwareTexture) === null || _d === void 0 ? void 0 : _d.underlyingResource, lodLevel);\n }\n else {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, (_e = depthStencilTexture._hardwareTexture) === null || _e === void 0 ? void 0 : _e.underlyingResource, lodLevel);\n }\n }\n if (this._cachedViewport && !forceFullscreenViewport) {\n this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);\n }\n else {\n if (!requiredWidth) {\n requiredWidth = rtWrapper.width;\n if (lodLevel) {\n requiredWidth = requiredWidth / Math.pow(2, lodLevel);\n }\n }\n if (!requiredHeight) {\n requiredHeight = rtWrapper.height;\n if (lodLevel) {\n requiredHeight = requiredHeight / Math.pow(2, lodLevel);\n }\n }\n this._viewport(0, 0, requiredWidth, requiredHeight);\n }\n this.wipeCaches();\n }\n /**\n * Set various states to the webGL context\n * @param culling defines culling state: true to enable culling, false to disable it\n * @param zOffset defines the value to apply to zOffset (0 by default)\n * @param force defines if states must be applied even if cache is up to date\n * @param reverseSide defines if culling must be reversed (CCW if false, CW if true)\n * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)\n * @param stencil stencil states to set\n * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)\n */\n setState(culling, zOffset = 0, force, reverseSide = false, cullBackFaces, stencil, zOffsetUnits = 0) {\n var _a, _b;\n // Culling\n if (this._depthCullingState.cull !== culling || force) {\n this._depthCullingState.cull = culling;\n }\n // Cull face\n const cullFace = ((_b = (_a = this.cullBackFaces) !== null && _a !== void 0 ? _a : cullBackFaces) !== null && _b !== void 0 ? _b : true) ? this._gl.BACK : this._gl.FRONT;\n if (this._depthCullingState.cullFace !== cullFace || force) {\n this._depthCullingState.cullFace = cullFace;\n }\n // Z offset\n this.setZOffset(zOffset);\n this.setZOffsetUnits(zOffsetUnits);\n // Front face\n const frontFace = reverseSide ? this._gl.CW : this._gl.CCW;\n if (this._depthCullingState.frontFace !== frontFace || force) {\n this._depthCullingState.frontFace = frontFace;\n }\n this._stencilStateComposer.stencilMaterial = stencil;\n }\n /**\n * Gets a boolean indicating if depth testing is enabled\n * @returns the current state\n */\n getDepthBuffer() {\n return this._depthCullingState.depthTest;\n }\n /**\n * Enable or disable depth buffering\n * @param enable defines the state to set\n */\n setDepthBuffer(enable) {\n this._depthCullingState.depthTest = enable;\n }\n /**\n * Set the z offset Factor to apply to current rendering\n * @param value defines the offset to apply\n */\n setZOffset(value) {\n this._depthCullingState.zOffset = this.useReverseDepthBuffer ? -value : value;\n }\n /**\n * Gets the current value of the zOffset Factor\n * @returns the current zOffset Factor state\n */\n getZOffset() {\n const zOffset = this._depthCullingState.zOffset;\n return this.useReverseDepthBuffer ? -zOffset : zOffset;\n }\n /**\n * Set the z offset Units to apply to current rendering\n * @param value defines the offset to apply\n */\n setZOffsetUnits(value) {\n this._depthCullingState.zOffsetUnits = this.useReverseDepthBuffer ? -value : value;\n }\n /**\n * Gets the current value of the zOffset Units\n * @returns the current zOffset Units state\n */\n getZOffsetUnits() {\n const zOffsetUnits = this._depthCullingState.zOffsetUnits;\n return this.useReverseDepthBuffer ? -zOffsetUnits : zOffsetUnits;\n }\n /**\n * @internal\n */\n _bindUnboundFramebuffer(framebuffer) {\n if (this._currentFramebuffer !== framebuffer) {\n this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, framebuffer);\n this._currentFramebuffer = framebuffer;\n }\n }\n /** @internal */\n _currentFrameBufferIsDefaultFrameBuffer() {\n return this._currentFramebuffer === null;\n }\n /**\n * Generates the mipmaps for a texture\n * @param texture texture to generate the mipmaps for\n */\n generateMipmaps(texture) {\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n }\n /**\n * Unbind the current render target texture from the webGL context\n * @param texture defines the render target wrapper to unbind\n * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated\n * @param onBeforeUnbind defines a function which will be called before the effective unbind\n */\n unBindFramebuffer(texture, disableGenerateMipMaps = false, onBeforeUnbind) {\n var _a;\n const webglRTWrapper = texture;\n this._currentRenderTarget = null;\n // If MSAA, we need to bitblt back to main texture\n const gl = this._gl;\n if (webglRTWrapper._MSAAFramebuffer) {\n if (texture.isMulti) {\n // This texture is part of a MRT texture, we need to treat all attachments\n this.unBindMultiColorAttachmentFramebuffer(texture, disableGenerateMipMaps, onBeforeUnbind);\n return;\n }\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, webglRTWrapper._MSAAFramebuffer);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, webglRTWrapper._framebuffer);\n gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);\n }\n if (((_a = texture.texture) === null || _a === void 0 ? void 0 : _a.generateMipMaps) && !disableGenerateMipMaps && !texture.isCube) {\n this.generateMipmaps(texture.texture);\n }\n if (onBeforeUnbind) {\n if (webglRTWrapper._MSAAFramebuffer) {\n // Bind the correct framebuffer\n this._bindUnboundFramebuffer(webglRTWrapper._framebuffer);\n }\n onBeforeUnbind();\n }\n this._bindUnboundFramebuffer(null);\n }\n /**\n * Force a webGL flush (ie. a flush of all waiting webGL commands)\n */\n flushFramebuffer() {\n this._gl.flush();\n }\n /**\n * Unbind the current render target and bind the default framebuffer\n */\n restoreDefaultFramebuffer() {\n if (this._currentRenderTarget) {\n this.unBindFramebuffer(this._currentRenderTarget);\n }\n else {\n this._bindUnboundFramebuffer(null);\n }\n if (this._cachedViewport) {\n this.setViewport(this._cachedViewport);\n }\n this.wipeCaches();\n }\n // VBOs\n /** @internal */\n _resetVertexBufferBinding() {\n this.bindArrayBuffer(null);\n this._cachedVertexBuffers = null;\n }\n /**\n * Creates a vertex buffer\n * @param data the data for the vertex buffer\n * @returns the new WebGL static buffer\n */\n createVertexBuffer(data) {\n return this._createVertexBuffer(data, this._gl.STATIC_DRAW);\n }\n _createVertexBuffer(data, usage) {\n const vbo = this._gl.createBuffer();\n if (!vbo) {\n throw new Error(\"Unable to create vertex buffer\");\n }\n const dataBuffer = new WebGLDataBuffer(vbo);\n this.bindArrayBuffer(dataBuffer);\n if (data instanceof Array) {\n this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), usage);\n }\n else {\n this._gl.bufferData(this._gl.ARRAY_BUFFER, data, usage);\n }\n this._resetVertexBufferBinding();\n dataBuffer.references = 1;\n return dataBuffer;\n }\n /**\n * Creates a dynamic vertex buffer\n * @param data the data for the dynamic vertex buffer\n * @returns the new WebGL dynamic buffer\n */\n createDynamicVertexBuffer(data) {\n return this._createVertexBuffer(data, this._gl.DYNAMIC_DRAW);\n }\n _resetIndexBufferBinding() {\n this.bindIndexBuffer(null);\n this._cachedIndexBuffer = null;\n }\n /**\n * Creates a new index buffer\n * @param indices defines the content of the index buffer\n * @param updatable defines if the index buffer must be updatable\n * @returns a new webGL buffer\n */\n createIndexBuffer(indices, updatable) {\n const vbo = this._gl.createBuffer();\n const dataBuffer = new WebGLDataBuffer(vbo);\n if (!vbo) {\n throw new Error(\"Unable to create index buffer\");\n }\n this.bindIndexBuffer(dataBuffer);\n const data = this._normalizeIndexData(indices);\n this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, data, updatable ? this._gl.DYNAMIC_DRAW : this._gl.STATIC_DRAW);\n this._resetIndexBufferBinding();\n dataBuffer.references = 1;\n dataBuffer.is32Bits = data.BYTES_PER_ELEMENT === 4;\n return dataBuffer;\n }\n _normalizeIndexData(indices) {\n const bytesPerElement = indices.BYTES_PER_ELEMENT;\n if (bytesPerElement === 2) {\n return indices;\n }\n // Check 32 bit support\n if (this._caps.uintIndices) {\n if (indices instanceof Uint32Array) {\n return indices;\n }\n else {\n // number[] or Int32Array, check if 32 bit is necessary\n for (let index = 0; index < indices.length; index++) {\n if (indices[index] >= 65535) {\n return new Uint32Array(indices);\n }\n }\n return new Uint16Array(indices);\n }\n }\n // No 32 bit support, force conversion to 16 bit (values greater 16 bit are lost)\n return new Uint16Array(indices);\n }\n /**\n * Bind a webGL buffer to the webGL context\n * @param buffer defines the buffer to bind\n */\n bindArrayBuffer(buffer) {\n if (!this._vaoRecordInProgress) {\n this._unbindVertexArrayObject();\n }\n this._bindBuffer(buffer, this._gl.ARRAY_BUFFER);\n }\n /**\n * Bind a specific block at a given index in a specific shader program\n * @param pipelineContext defines the pipeline context to use\n * @param blockName defines the block name\n * @param index defines the index where to bind the block\n */\n bindUniformBlock(pipelineContext, blockName, index) {\n const program = pipelineContext.program;\n const uniformLocation = this._gl.getUniformBlockIndex(program, blockName);\n this._gl.uniformBlockBinding(program, uniformLocation, index);\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n bindIndexBuffer(buffer) {\n if (!this._vaoRecordInProgress) {\n this._unbindVertexArrayObject();\n }\n this._bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);\n }\n _bindBuffer(buffer, target) {\n if (this._vaoRecordInProgress || this._currentBoundBuffer[target] !== buffer) {\n this._gl.bindBuffer(target, buffer ? buffer.underlyingResource : null);\n this._currentBoundBuffer[target] = buffer;\n }\n }\n /**\n * update the bound buffer with the given data\n * @param data defines the data to update\n */\n updateArrayBuffer(data) {\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);\n }\n _vertexAttribPointer(buffer, indx, size, type, normalized, stride, offset) {\n const pointer = this._currentBufferPointers[indx];\n if (!pointer) {\n return;\n }\n let changed = false;\n if (!pointer.active) {\n changed = true;\n pointer.active = true;\n pointer.index = indx;\n pointer.size = size;\n pointer.type = type;\n pointer.normalized = normalized;\n pointer.stride = stride;\n pointer.offset = offset;\n pointer.buffer = buffer;\n }\n else {\n if (pointer.buffer !== buffer) {\n pointer.buffer = buffer;\n changed = true;\n }\n if (pointer.size !== size) {\n pointer.size = size;\n changed = true;\n }\n if (pointer.type !== type) {\n pointer.type = type;\n changed = true;\n }\n if (pointer.normalized !== normalized) {\n pointer.normalized = normalized;\n changed = true;\n }\n if (pointer.stride !== stride) {\n pointer.stride = stride;\n changed = true;\n }\n if (pointer.offset !== offset) {\n pointer.offset = offset;\n changed = true;\n }\n }\n if (changed || this._vaoRecordInProgress) {\n this.bindArrayBuffer(buffer);\n if (type === this._gl.UNSIGNED_INT || type === this._gl.INT) {\n this._gl.vertexAttribIPointer(indx, size, type, stride, offset);\n }\n else {\n this._gl.vertexAttribPointer(indx, size, type, normalized, stride, offset);\n }\n }\n }\n /**\n * @internal\n */\n _bindIndexBufferWithCache(indexBuffer) {\n if (indexBuffer == null) {\n return;\n }\n if (this._cachedIndexBuffer !== indexBuffer) {\n this._cachedIndexBuffer = indexBuffer;\n this.bindIndexBuffer(indexBuffer);\n this._uintIndicesCurrentlySet = indexBuffer.is32Bits;\n }\n }\n _bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers) {\n const attributes = effect.getAttributesNames();\n if (!this._vaoRecordInProgress) {\n this._unbindVertexArrayObject();\n }\n this.unbindAllAttributes();\n for (let index = 0; index < attributes.length; index++) {\n const order = effect.getAttributeLocation(index);\n if (order >= 0) {\n const ai = attributes[index];\n let vertexBuffer = null;\n if (overrideVertexBuffers) {\n vertexBuffer = overrideVertexBuffers[ai];\n }\n if (!vertexBuffer) {\n vertexBuffer = vertexBuffers[ai];\n }\n if (!vertexBuffer) {\n continue;\n }\n this._gl.enableVertexAttribArray(order);\n if (!this._vaoRecordInProgress) {\n this._vertexAttribArraysEnabled[order] = true;\n }\n const buffer = vertexBuffer.getBuffer();\n if (buffer) {\n this._vertexAttribPointer(buffer, order, vertexBuffer.getSize(), vertexBuffer.type, vertexBuffer.normalized, vertexBuffer.byteStride, vertexBuffer.byteOffset);\n if (vertexBuffer.getIsInstanced()) {\n this._gl.vertexAttribDivisor(order, vertexBuffer.getInstanceDivisor());\n if (!this._vaoRecordInProgress) {\n this._currentInstanceLocations.push(order);\n this._currentInstanceBuffers.push(buffer);\n }\n }\n }\n }\n }\n }\n /**\n * Records a vertex array object\n * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects\n * @param vertexBuffers defines the list of vertex buffers to store\n * @param indexBuffer defines the index buffer to store\n * @param effect defines the effect to store\n * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers\n * @returns the new vertex array object\n */\n recordVertexArrayObject(vertexBuffers, indexBuffer, effect, overrideVertexBuffers) {\n const vao = this._gl.createVertexArray();\n if (!vao) {\n throw new Error(\"Unable to create VAO\");\n }\n this._vaoRecordInProgress = true;\n this._gl.bindVertexArray(vao);\n this._mustWipeVertexAttributes = true;\n this._bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers);\n this.bindIndexBuffer(indexBuffer);\n this._vaoRecordInProgress = false;\n this._gl.bindVertexArray(null);\n return vao;\n }\n /**\n * Bind a specific vertex array object\n * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects\n * @param vertexArrayObject defines the vertex array object to bind\n * @param indexBuffer defines the index buffer to bind\n */\n bindVertexArrayObject(vertexArrayObject, indexBuffer) {\n if (this._cachedVertexArrayObject !== vertexArrayObject) {\n this._cachedVertexArrayObject = vertexArrayObject;\n this._gl.bindVertexArray(vertexArrayObject);\n this._cachedVertexBuffers = null;\n this._cachedIndexBuffer = null;\n this._uintIndicesCurrentlySet = indexBuffer != null && indexBuffer.is32Bits;\n this._mustWipeVertexAttributes = true;\n }\n }\n /**\n * Bind webGl buffers directly to the webGL context\n * @param vertexBuffer defines the vertex buffer to bind\n * @param indexBuffer defines the index buffer to bind\n * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer\n * @param vertexStrideSize defines the vertex stride of the vertex buffer\n * @param effect defines the effect associated with the vertex buffer\n */\n bindBuffersDirectly(vertexBuffer, indexBuffer, vertexDeclaration, vertexStrideSize, effect) {\n if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {\n this._cachedVertexBuffers = vertexBuffer;\n this._cachedEffectForVertexBuffers = effect;\n const attributesCount = effect.getAttributesCount();\n this._unbindVertexArrayObject();\n this.unbindAllAttributes();\n let offset = 0;\n for (let index = 0; index < attributesCount; index++) {\n if (index < vertexDeclaration.length) {\n const order = effect.getAttributeLocation(index);\n if (order >= 0) {\n this._gl.enableVertexAttribArray(order);\n this._vertexAttribArraysEnabled[order] = true;\n this._vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);\n }\n offset += vertexDeclaration[index] * 4;\n }\n }\n }\n this._bindIndexBufferWithCache(indexBuffer);\n }\n _unbindVertexArrayObject() {\n if (!this._cachedVertexArrayObject) {\n return;\n }\n this._cachedVertexArrayObject = null;\n this._gl.bindVertexArray(null);\n }\n /**\n * Bind a list of vertex buffers to the webGL context\n * @param vertexBuffers defines the list of vertex buffers to bind\n * @param indexBuffer defines the index buffer to bind\n * @param effect defines the effect associated with the vertex buffers\n * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers\n */\n bindBuffers(vertexBuffers, indexBuffer, effect, overrideVertexBuffers) {\n if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {\n this._cachedVertexBuffers = vertexBuffers;\n this._cachedEffectForVertexBuffers = effect;\n this._bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers);\n }\n this._bindIndexBufferWithCache(indexBuffer);\n }\n /**\n * Unbind all instance attributes\n */\n unbindInstanceAttributes() {\n let boundBuffer;\n for (let i = 0, ul = this._currentInstanceLocations.length; i < ul; i++) {\n const instancesBuffer = this._currentInstanceBuffers[i];\n if (boundBuffer != instancesBuffer && instancesBuffer.references) {\n boundBuffer = instancesBuffer;\n this.bindArrayBuffer(instancesBuffer);\n }\n const offsetLocation = this._currentInstanceLocations[i];\n this._gl.vertexAttribDivisor(offsetLocation, 0);\n }\n this._currentInstanceBuffers.length = 0;\n this._currentInstanceLocations.length = 0;\n }\n /**\n * Release and free the memory of a vertex array object\n * @param vao defines the vertex array object to delete\n */\n releaseVertexArrayObject(vao) {\n this._gl.deleteVertexArray(vao);\n }\n /**\n * @internal\n */\n _releaseBuffer(buffer) {\n buffer.references--;\n if (buffer.references === 0) {\n this._deleteBuffer(buffer);\n return true;\n }\n return false;\n }\n _deleteBuffer(buffer) {\n this._gl.deleteBuffer(buffer.underlyingResource);\n }\n /**\n * Update the content of a webGL buffer used with instantiation and bind it to the webGL context\n * @param instancesBuffer defines the webGL buffer to update and bind\n * @param data defines the data to store in the buffer\n * @param offsetLocations defines the offsets or attributes information used to determine where data must be stored in the buffer\n */\n updateAndBindInstancesBuffer(instancesBuffer, data, offsetLocations) {\n this.bindArrayBuffer(instancesBuffer);\n if (data) {\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);\n }\n if (offsetLocations[0].index !== undefined) {\n this.bindInstancesBuffer(instancesBuffer, offsetLocations, true);\n }\n else {\n for (let index = 0; index < 4; index++) {\n const offsetLocation = offsetLocations[index];\n if (!this._vertexAttribArraysEnabled[offsetLocation]) {\n this._gl.enableVertexAttribArray(offsetLocation);\n this._vertexAttribArraysEnabled[offsetLocation] = true;\n }\n this._vertexAttribPointer(instancesBuffer, offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);\n this._gl.vertexAttribDivisor(offsetLocation, 1);\n this._currentInstanceLocations.push(offsetLocation);\n this._currentInstanceBuffers.push(instancesBuffer);\n }\n }\n }\n /**\n * Bind the content of a webGL buffer used with instantiation\n * @param instancesBuffer defines the webGL buffer to bind\n * @param attributesInfo defines the offsets or attributes information used to determine where data must be stored in the buffer\n * @param computeStride defines Whether to compute the strides from the info or use the default 0\n */\n bindInstancesBuffer(instancesBuffer, attributesInfo, computeStride = true) {\n this.bindArrayBuffer(instancesBuffer);\n let stride = 0;\n if (computeStride) {\n for (let i = 0; i < attributesInfo.length; i++) {\n const ai = attributesInfo[i];\n stride += ai.attributeSize * 4;\n }\n }\n for (let i = 0; i < attributesInfo.length; i++) {\n const ai = attributesInfo[i];\n if (ai.index === undefined) {\n ai.index = this._currentEffect.getAttributeLocationByName(ai.attributeName);\n }\n if (ai.index < 0) {\n continue;\n }\n if (!this._vertexAttribArraysEnabled[ai.index]) {\n this._gl.enableVertexAttribArray(ai.index);\n this._vertexAttribArraysEnabled[ai.index] = true;\n }\n this._vertexAttribPointer(instancesBuffer, ai.index, ai.attributeSize, ai.attributeType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);\n this._gl.vertexAttribDivisor(ai.index, ai.divisor === undefined ? 1 : ai.divisor);\n this._currentInstanceLocations.push(ai.index);\n this._currentInstanceBuffers.push(instancesBuffer);\n }\n }\n /**\n * Disable the instance attribute corresponding to the name in parameter\n * @param name defines the name of the attribute to disable\n */\n disableInstanceAttributeByName(name) {\n if (!this._currentEffect) {\n return;\n }\n const attributeLocation = this._currentEffect.getAttributeLocationByName(name);\n this.disableInstanceAttribute(attributeLocation);\n }\n /**\n * Disable the instance attribute corresponding to the location in parameter\n * @param attributeLocation defines the attribute location of the attribute to disable\n */\n disableInstanceAttribute(attributeLocation) {\n let shouldClean = false;\n let index;\n while ((index = this._currentInstanceLocations.indexOf(attributeLocation)) !== -1) {\n this._currentInstanceLocations.splice(index, 1);\n this._currentInstanceBuffers.splice(index, 1);\n shouldClean = true;\n index = this._currentInstanceLocations.indexOf(attributeLocation);\n }\n if (shouldClean) {\n this._gl.vertexAttribDivisor(attributeLocation, 0);\n this.disableAttributeByIndex(attributeLocation);\n }\n }\n /**\n * Disable the attribute corresponding to the location in parameter\n * @param attributeLocation defines the attribute location of the attribute to disable\n */\n disableAttributeByIndex(attributeLocation) {\n this._gl.disableVertexAttribArray(attributeLocation);\n this._vertexAttribArraysEnabled[attributeLocation] = false;\n this._currentBufferPointers[attributeLocation].active = false;\n }\n /**\n * Send a draw order\n * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)\n * @param indexStart defines the starting index\n * @param indexCount defines the number of index to draw\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\n */\n draw(useTriangles, indexStart, indexCount, instancesCount) {\n this.drawElementsType(useTriangles ? 0 : 1, indexStart, indexCount, instancesCount);\n }\n /**\n * Draw a list of points\n * @param verticesStart defines the index of first vertex to draw\n * @param verticesCount defines the count of vertices to draw\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\n */\n drawPointClouds(verticesStart, verticesCount, instancesCount) {\n this.drawArraysType(2, verticesStart, verticesCount, instancesCount);\n }\n /**\n * Draw a list of unindexed primitives\n * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)\n * @param verticesStart defines the index of first vertex to draw\n * @param verticesCount defines the count of vertices to draw\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\n */\n drawUnIndexed(useTriangles, verticesStart, verticesCount, instancesCount) {\n this.drawArraysType(useTriangles ? 0 : 1, verticesStart, verticesCount, instancesCount);\n }\n /**\n * Draw a list of indexed primitives\n * @param fillMode defines the primitive to use\n * @param indexStart defines the starting index\n * @param indexCount defines the number of index to draw\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\n */\n drawElementsType(fillMode, indexStart, indexCount, instancesCount) {\n // Apply states\n this.applyStates();\n this._reportDrawCall();\n // Render\n const drawMode = this._drawMode(fillMode);\n const indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;\n const mult = this._uintIndicesCurrentlySet ? 4 : 2;\n if (instancesCount) {\n this._gl.drawElementsInstanced(drawMode, indexCount, indexFormat, indexStart * mult, instancesCount);\n }\n else {\n this._gl.drawElements(drawMode, indexCount, indexFormat, indexStart * mult);\n }\n }\n /**\n * Draw a list of unindexed primitives\n * @param fillMode defines the primitive to use\n * @param verticesStart defines the index of first vertex to draw\n * @param verticesCount defines the count of vertices to draw\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\n */\n drawArraysType(fillMode, verticesStart, verticesCount, instancesCount) {\n // Apply states\n this.applyStates();\n this._reportDrawCall();\n const drawMode = this._drawMode(fillMode);\n if (instancesCount) {\n this._gl.drawArraysInstanced(drawMode, verticesStart, verticesCount, instancesCount);\n }\n else {\n this._gl.drawArrays(drawMode, verticesStart, verticesCount);\n }\n }\n _drawMode(fillMode) {\n switch (fillMode) {\n // Triangle views\n case 0:\n return this._gl.TRIANGLES;\n case 2:\n return this._gl.POINTS;\n case 1:\n return this._gl.LINES;\n // Draw modes\n case 3:\n return this._gl.POINTS;\n case 4:\n return this._gl.LINES;\n case 5:\n return this._gl.LINE_LOOP;\n case 6:\n return this._gl.LINE_STRIP;\n case 7:\n return this._gl.TRIANGLE_STRIP;\n case 8:\n return this._gl.TRIANGLE_FAN;\n default:\n return this._gl.TRIANGLES;\n }\n }\n /** @internal */\n _reportDrawCall() {\n // Will be implemented by children\n }\n // Shaders\n /**\n * @internal\n */\n _releaseEffect(effect) {\n if (this._compiledEffects[effect._key]) {\n delete this._compiledEffects[effect._key];\n }\n const pipelineContext = effect.getPipelineContext();\n if (pipelineContext) {\n this._deletePipelineContext(pipelineContext);\n }\n }\n /**\n * @internal\n */\n _deletePipelineContext(pipelineContext) {\n const webGLPipelineContext = pipelineContext;\n if (webGLPipelineContext && webGLPipelineContext.program) {\n webGLPipelineContext.program.__SPECTOR_rebuildProgram = null;\n this._gl.deleteProgram(webGLPipelineContext.program);\n }\n }\n /** @internal */\n _getGlobalDefines(defines) {\n if (defines) {\n if (this.isNDCHalfZRange) {\n defines[\"IS_NDC_HALF_ZRANGE\"] = \"\";\n }\n else {\n delete defines[\"IS_NDC_HALF_ZRANGE\"];\n }\n if (this.useReverseDepthBuffer) {\n defines[\"USE_REVERSE_DEPTHBUFFER\"] = \"\";\n }\n else {\n delete defines[\"USE_REVERSE_DEPTHBUFFER\"];\n }\n if (this.useExactSrgbConversions) {\n defines[\"USE_EXACT_SRGB_CONVERSIONS\"] = \"\";\n }\n else {\n delete defines[\"USE_EXACT_SRGB_CONVERSIONS\"];\n }\n return;\n }\n else {\n let s = \"\";\n if (this.isNDCHalfZRange) {\n s += \"#define IS_NDC_HALF_ZRANGE\";\n }\n if (this.useReverseDepthBuffer) {\n if (s) {\n s += \"\\n\";\n }\n s += \"#define USE_REVERSE_DEPTHBUFFER\";\n }\n if (this.useExactSrgbConversions) {\n if (s) {\n s += \"\\n\";\n }\n s += \"#define USE_EXACT_SRGB_CONVERSIONS\";\n }\n return s;\n }\n }\n /**\n * Create a new effect (used to store vertex/fragment shaders)\n * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)\n * @param attributesNamesOrOptions defines either a list of attribute names or an IEffectCreationOptions object\n * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use\n * @param samplers defines an array of string used to represent textures\n * @param defines defines the string containing the defines to use to compile the shaders\n * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails\n * @param onCompiled defines a function to call when the effect creation is successful\n * @param onError defines a function to call when the effect creation has failed\n * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)\n * @param shaderLanguage the language the shader is written in (default: GLSL)\n * @returns the new Effect\n */\n createEffect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, defines, fallbacks, onCompiled, onError, indexParameters, shaderLanguage = ShaderLanguage.GLSL) {\n var _a;\n const vertex = baseName.vertexElement || baseName.vertex || baseName.vertexToken || baseName.vertexSource || baseName;\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.fragmentToken || baseName.fragmentSource || baseName;\n const globalDefines = this._getGlobalDefines();\n let fullDefines = (_a = defines !== null && defines !== void 0 ? defines : attributesNamesOrOptions.defines) !== null && _a !== void 0 ? _a : \"\";\n if (globalDefines) {\n fullDefines += globalDefines;\n }\n const name = vertex + \"+\" + fragment + \"@\" + fullDefines;\n if (this._compiledEffects[name]) {\n const compiledEffect = this._compiledEffects[name];\n if (onCompiled && compiledEffect.isReady()) {\n onCompiled(compiledEffect);\n }\n return compiledEffect;\n }\n const effect = new Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, this, defines, fallbacks, onCompiled, onError, indexParameters, name, shaderLanguage);\n this._compiledEffects[name] = effect;\n return effect;\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static _ConcatenateShader(source, defines, shaderVersion = \"\") {\n return shaderVersion + (defines ? defines + \"\\n\" : \"\") + source;\n }\n _compileShader(source, type, defines, shaderVersion) {\n return this._compileRawShader(ThinEngine._ConcatenateShader(source, defines, shaderVersion), type);\n }\n _compileRawShader(source, type) {\n const gl = this._gl;\n const shader = gl.createShader(type === \"vertex\" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);\n if (!shader) {\n let error = gl.NO_ERROR;\n let tempError = gl.NO_ERROR;\n while ((tempError = gl.getError()) !== gl.NO_ERROR) {\n error = tempError;\n }\n throw new Error(`Something went wrong while creating a gl ${type} shader object. gl error=${error}, gl isContextLost=${gl.isContextLost()}, _contextWasLost=${this._contextWasLost}`);\n }\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n return shader;\n }\n /**\n * @internal\n */\n _getShaderSource(shader) {\n return this._gl.getShaderSource(shader);\n }\n /**\n * Directly creates a webGL program\n * @param pipelineContext defines the pipeline context to attach to\n * @param vertexCode defines the vertex shader code to use\n * @param fragmentCode defines the fragment shader code to use\n * @param context defines the webGL context to use (if not set, the current one will be used)\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\n * @returns the new webGL program\n */\n createRawShaderProgram(pipelineContext, vertexCode, fragmentCode, context, transformFeedbackVaryings = null) {\n context = context || this._gl;\n const vertexShader = this._compileRawShader(vertexCode, \"vertex\");\n const fragmentShader = this._compileRawShader(fragmentCode, \"fragment\");\n return this._createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings);\n }\n /**\n * Creates a webGL program\n * @param pipelineContext defines the pipeline context to attach to\n * @param vertexCode defines the vertex shader code to use\n * @param fragmentCode defines the fragment shader code to use\n * @param defines defines the string containing the defines to use to compile the shaders\n * @param context defines the webGL context to use (if not set, the current one will be used)\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\n * @returns the new webGL program\n */\n createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context, transformFeedbackVaryings = null) {\n context = context || this._gl;\n const shaderVersion = this._webGLVersion > 1 ? \"#version 300 es\\n#define WEBGL2 \\n\" : \"\";\n const vertexShader = this._compileShader(vertexCode, \"vertex\", defines, shaderVersion);\n const fragmentShader = this._compileShader(fragmentCode, \"fragment\", defines, shaderVersion);\n return this._createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings);\n }\n /**\n * Inline functions in shader code that are marked to be inlined\n * @param code code to inline\n * @returns inlined code\n */\n inlineShaderCode(code) {\n // no inlining needed in the WebGL engine\n return code;\n }\n /**\n * Creates a new pipeline context\n * @param shaderProcessingContext defines the shader processing context used during the processing if available\n * @returns the new pipeline\n */\n createPipelineContext(shaderProcessingContext) {\n const pipelineContext = new WebGLPipelineContext();\n pipelineContext.engine = this;\n if (this._caps.parallelShaderCompile) {\n pipelineContext.isParallelCompiled = true;\n }\n return pipelineContext;\n }\n /**\n * Creates a new material context\n * @returns the new context\n */\n createMaterialContext() {\n return undefined;\n }\n /**\n * Creates a new draw context\n * @returns the new context\n */\n createDrawContext() {\n return undefined;\n }\n _createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings = null) {\n const shaderProgram = context.createProgram();\n pipelineContext.program = shaderProgram;\n if (!shaderProgram) {\n throw new Error(\"Unable to create program\");\n }\n context.attachShader(shaderProgram, vertexShader);\n context.attachShader(shaderProgram, fragmentShader);\n context.linkProgram(shaderProgram);\n pipelineContext.context = context;\n pipelineContext.vertexShader = vertexShader;\n pipelineContext.fragmentShader = fragmentShader;\n if (!pipelineContext.isParallelCompiled) {\n this._finalizePipelineContext(pipelineContext);\n }\n return shaderProgram;\n }\n _finalizePipelineContext(pipelineContext) {\n const context = pipelineContext.context;\n const vertexShader = pipelineContext.vertexShader;\n const fragmentShader = pipelineContext.fragmentShader;\n const program = pipelineContext.program;\n const linked = context.getProgramParameter(program, context.LINK_STATUS);\n if (!linked) {\n // Get more info\n // Vertex\n if (!this._gl.getShaderParameter(vertexShader, this._gl.COMPILE_STATUS)) {\n const log = this._gl.getShaderInfoLog(vertexShader);\n if (log) {\n pipelineContext.vertexCompilationError = log;\n throw new Error(\"VERTEX SHADER \" + log);\n }\n }\n // Fragment\n if (!this._gl.getShaderParameter(fragmentShader, this._gl.COMPILE_STATUS)) {\n const log = this._gl.getShaderInfoLog(fragmentShader);\n if (log) {\n pipelineContext.fragmentCompilationError = log;\n throw new Error(\"FRAGMENT SHADER \" + log);\n }\n }\n const error = context.getProgramInfoLog(program);\n if (error) {\n pipelineContext.programLinkError = error;\n throw new Error(error);\n }\n }\n if (this.validateShaderPrograms) {\n context.validateProgram(program);\n const validated = context.getProgramParameter(program, context.VALIDATE_STATUS);\n if (!validated) {\n const error = context.getProgramInfoLog(program);\n if (error) {\n pipelineContext.programValidationError = error;\n throw new Error(error);\n }\n }\n }\n context.deleteShader(vertexShader);\n context.deleteShader(fragmentShader);\n pipelineContext.vertexShader = undefined;\n pipelineContext.fragmentShader = undefined;\n if (pipelineContext.onCompiled) {\n pipelineContext.onCompiled();\n pipelineContext.onCompiled = undefined;\n }\n }\n /**\n * @internal\n */\n _preparePipelineContext(pipelineContext, vertexSourceCode, fragmentSourceCode, createAsRaw, rawVertexSourceCode, rawFragmentSourceCode, rebuildRebind, defines, transformFeedbackVaryings, key) {\n const webGLRenderingState = pipelineContext;\n if (createAsRaw) {\n webGLRenderingState.program = this.createRawShaderProgram(webGLRenderingState, vertexSourceCode, fragmentSourceCode, undefined, transformFeedbackVaryings);\n }\n else {\n webGLRenderingState.program = this.createShaderProgram(webGLRenderingState, vertexSourceCode, fragmentSourceCode, defines, undefined, transformFeedbackVaryings);\n }\n webGLRenderingState.program.__SPECTOR_rebuildProgram = rebuildRebind;\n }\n /**\n * @internal\n */\n _isRenderingStateCompiled(pipelineContext) {\n const webGLPipelineContext = pipelineContext;\n if (this._isDisposed || webGLPipelineContext._isDisposed) {\n return false;\n }\n if (this._gl.getProgramParameter(webGLPipelineContext.program, this._caps.parallelShaderCompile.COMPLETION_STATUS_KHR)) {\n this._finalizePipelineContext(webGLPipelineContext);\n return true;\n }\n return false;\n }\n /**\n * @internal\n */\n _executeWhenRenderingStateIsCompiled(pipelineContext, action) {\n const webGLPipelineContext = pipelineContext;\n if (!webGLPipelineContext.isParallelCompiled) {\n action();\n return;\n }\n const oldHandler = webGLPipelineContext.onCompiled;\n if (oldHandler) {\n webGLPipelineContext.onCompiled = () => {\n oldHandler();\n action();\n };\n }\n else {\n webGLPipelineContext.onCompiled = action;\n }\n }\n /**\n * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names\n * @param pipelineContext defines the pipeline context to use\n * @param uniformsNames defines the list of uniform names\n * @returns an array of webGL uniform locations\n */\n getUniforms(pipelineContext, uniformsNames) {\n const results = new Array();\n const webGLPipelineContext = pipelineContext;\n for (let index = 0; index < uniformsNames.length; index++) {\n results.push(this._gl.getUniformLocation(webGLPipelineContext.program, uniformsNames[index]));\n }\n return results;\n }\n /**\n * Gets the list of active attributes for a given webGL program\n * @param pipelineContext defines the pipeline context to use\n * @param attributesNames defines the list of attribute names to get\n * @returns an array of indices indicating the offset of each attribute\n */\n getAttributes(pipelineContext, attributesNames) {\n const results = [];\n const webGLPipelineContext = pipelineContext;\n for (let index = 0; index < attributesNames.length; index++) {\n try {\n results.push(this._gl.getAttribLocation(webGLPipelineContext.program, attributesNames[index]));\n }\n catch (e) {\n results.push(-1);\n }\n }\n return results;\n }\n /**\n * Activates an effect, making it the current one (ie. the one used for rendering)\n * @param effect defines the effect to activate\n */\n enableEffect(effect) {\n effect = effect !== null && DrawWrapper.IsWrapper(effect) ? effect.effect : effect; // get only the effect, we don't need a Wrapper in the WebGL engine\n if (!effect || effect === this._currentEffect) {\n return;\n }\n this._stencilStateComposer.stencilMaterial = undefined;\n effect = effect;\n // Use program\n this.bindSamplers(effect);\n this._currentEffect = effect;\n if (effect.onBind) {\n effect.onBind(effect);\n }\n if (effect._onBindObservable) {\n effect._onBindObservable.notifyObservers(effect);\n }\n }\n /**\n * Set the value of an uniform to a number (int)\n * @param uniform defines the webGL uniform location where to store the value\n * @param value defines the int number to store\n * @returns true if the value was set\n */\n setInt(uniform, value) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform1i(uniform, value);\n return true;\n }\n /**\n * Set the value of an uniform to a int2\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @returns true if the value was set\n */\n setInt2(uniform, x, y) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform2i(uniform, x, y);\n return true;\n }\n /**\n * Set the value of an uniform to a int3\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @param z defines the 3rd component of the value\n * @returns true if the value was set\n */\n setInt3(uniform, x, y, z) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform3i(uniform, x, y, z);\n return true;\n }\n /**\n * Set the value of an uniform to a int4\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @param z defines the 3rd component of the value\n * @param w defines the 4th component of the value\n * @returns true if the value was set\n */\n setInt4(uniform, x, y, z, w) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform4i(uniform, x, y, z, w);\n return true;\n }\n /**\n * Set the value of an uniform to an array of int32\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of int32 to store\n * @returns true if the value was set\n */\n setIntArray(uniform, array) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform1iv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of int32 (stored as vec2)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of int32 to store\n * @returns true if the value was set\n */\n setIntArray2(uniform, array) {\n if (!uniform || array.length % 2 !== 0) {\n return false;\n }\n this._gl.uniform2iv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of int32 (stored as vec3)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of int32 to store\n * @returns true if the value was set\n */\n setIntArray3(uniform, array) {\n if (!uniform || array.length % 3 !== 0) {\n return false;\n }\n this._gl.uniform3iv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of int32 (stored as vec4)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of int32 to store\n * @returns true if the value was set\n */\n setIntArray4(uniform, array) {\n if (!uniform || array.length % 4 !== 0) {\n return false;\n }\n this._gl.uniform4iv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to a number (unsigned int)\n * @param uniform defines the webGL uniform location where to store the value\n * @param value defines the unsigned int number to store\n * @returns true if the value was set\n */\n setUInt(uniform, value) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform1ui(uniform, value);\n return true;\n }\n /**\n * Set the value of an uniform to a unsigned int2\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @returns true if the value was set\n */\n setUInt2(uniform, x, y) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform2ui(uniform, x, y);\n return true;\n }\n /**\n * Set the value of an uniform to a unsigned int3\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @param z defines the 3rd component of the value\n * @returns true if the value was set\n */\n setUInt3(uniform, x, y, z) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform3ui(uniform, x, y, z);\n return true;\n }\n /**\n * Set the value of an uniform to a unsigned int4\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @param z defines the 3rd component of the value\n * @param w defines the 4th component of the value\n * @returns true if the value was set\n */\n setUInt4(uniform, x, y, z, w) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform4ui(uniform, x, y, z, w);\n return true;\n }\n /**\n * Set the value of an uniform to an array of unsigned int32\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of unsigned int32 to store\n * @returns true if the value was set\n */\n setUIntArray(uniform, array) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform1uiv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of unsigned int32 (stored as vec2)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of unsigned int32 to store\n * @returns true if the value was set\n */\n setUIntArray2(uniform, array) {\n if (!uniform || array.length % 2 !== 0) {\n return false;\n }\n this._gl.uniform2uiv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of unsigned int32 (stored as vec3)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of unsigned int32 to store\n * @returns true if the value was set\n */\n setUIntArray3(uniform, array) {\n if (!uniform || array.length % 3 !== 0) {\n return false;\n }\n this._gl.uniform3uiv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of unsigned int32 (stored as vec4)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of unsigned int32 to store\n * @returns true if the value was set\n */\n setUIntArray4(uniform, array) {\n if (!uniform || array.length % 4 !== 0) {\n return false;\n }\n this._gl.uniform4uiv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of number\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of number to store\n * @returns true if the value was set\n */\n setArray(uniform, array) {\n if (!uniform) {\n return false;\n }\n if (array.length < 1) {\n return false;\n }\n this._gl.uniform1fv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of number (stored as vec2)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of number to store\n * @returns true if the value was set\n */\n setArray2(uniform, array) {\n if (!uniform || array.length % 2 !== 0) {\n return false;\n }\n this._gl.uniform2fv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of number (stored as vec3)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of number to store\n * @returns true if the value was set\n */\n setArray3(uniform, array) {\n if (!uniform || array.length % 3 !== 0) {\n return false;\n }\n this._gl.uniform3fv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of number (stored as vec4)\n * @param uniform defines the webGL uniform location where to store the value\n * @param array defines the array of number to store\n * @returns true if the value was set\n */\n setArray4(uniform, array) {\n if (!uniform || array.length % 4 !== 0) {\n return false;\n }\n this._gl.uniform4fv(uniform, array);\n return true;\n }\n /**\n * Set the value of an uniform to an array of float32 (stored as matrices)\n * @param uniform defines the webGL uniform location where to store the value\n * @param matrices defines the array of float32 to store\n * @returns true if the value was set\n */\n setMatrices(uniform, matrices) {\n if (!uniform) {\n return false;\n }\n this._gl.uniformMatrix4fv(uniform, false, matrices);\n return true;\n }\n /**\n * Set the value of an uniform to a matrix (3x3)\n * @param uniform defines the webGL uniform location where to store the value\n * @param matrix defines the Float32Array representing the 3x3 matrix to store\n * @returns true if the value was set\n */\n setMatrix3x3(uniform, matrix) {\n if (!uniform) {\n return false;\n }\n this._gl.uniformMatrix3fv(uniform, false, matrix);\n return true;\n }\n /**\n * Set the value of an uniform to a matrix (2x2)\n * @param uniform defines the webGL uniform location where to store the value\n * @param matrix defines the Float32Array representing the 2x2 matrix to store\n * @returns true if the value was set\n */\n setMatrix2x2(uniform, matrix) {\n if (!uniform) {\n return false;\n }\n this._gl.uniformMatrix2fv(uniform, false, matrix);\n return true;\n }\n /**\n * Set the value of an uniform to a number (float)\n * @param uniform defines the webGL uniform location where to store the value\n * @param value defines the float number to store\n * @returns true if the value was transferred\n */\n setFloat(uniform, value) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform1f(uniform, value);\n return true;\n }\n /**\n * Set the value of an uniform to a vec2\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @returns true if the value was set\n */\n setFloat2(uniform, x, y) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform2f(uniform, x, y);\n return true;\n }\n /**\n * Set the value of an uniform to a vec3\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @param z defines the 3rd component of the value\n * @returns true if the value was set\n */\n setFloat3(uniform, x, y, z) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform3f(uniform, x, y, z);\n return true;\n }\n /**\n * Set the value of an uniform to a vec4\n * @param uniform defines the webGL uniform location where to store the value\n * @param x defines the 1st component of the value\n * @param y defines the 2nd component of the value\n * @param z defines the 3rd component of the value\n * @param w defines the 4th component of the value\n * @returns true if the value was set\n */\n setFloat4(uniform, x, y, z, w) {\n if (!uniform) {\n return false;\n }\n this._gl.uniform4f(uniform, x, y, z, w);\n return true;\n }\n // States\n /**\n * Apply all cached states (depth, culling, stencil and alpha)\n */\n applyStates() {\n this._depthCullingState.apply(this._gl);\n this._stencilStateComposer.apply(this._gl);\n this._alphaState.apply(this._gl);\n if (this._colorWriteChanged) {\n this._colorWriteChanged = false;\n const enable = this._colorWrite;\n this._gl.colorMask(enable, enable, enable, enable);\n }\n }\n /**\n * Enable or disable color writing\n * @param enable defines the state to set\n */\n setColorWrite(enable) {\n if (enable !== this._colorWrite) {\n this._colorWriteChanged = true;\n this._colorWrite = enable;\n }\n }\n /**\n * Gets a boolean indicating if color writing is enabled\n * @returns the current color writing state\n */\n getColorWrite() {\n return this._colorWrite;\n }\n /**\n * Gets the depth culling state manager\n */\n get depthCullingState() {\n return this._depthCullingState;\n }\n /**\n * Gets the alpha state manager\n */\n get alphaState() {\n return this._alphaState;\n }\n /**\n * Gets the stencil state manager\n */\n get stencilState() {\n return this._stencilState;\n }\n /**\n * Gets the stencil state composer\n */\n get stencilStateComposer() {\n return this._stencilStateComposer;\n }\n // Textures\n /**\n * Clears the list of texture accessible through engine.\n * This can help preventing texture load conflict due to name collision.\n */\n clearInternalTexturesCache() {\n this._internalTexturesCache.length = 0;\n }\n /**\n * Force the entire cache to be cleared\n * You should not have to use this function unless your engine needs to share the webGL context with another engine\n * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)\n */\n wipeCaches(bruteForce) {\n if (this.preventCacheWipeBetweenFrames && !bruteForce) {\n return;\n }\n this._currentEffect = null;\n this._viewportCached.x = 0;\n this._viewportCached.y = 0;\n this._viewportCached.z = 0;\n this._viewportCached.w = 0;\n // Done before in case we clean the attributes\n this._unbindVertexArrayObject();\n if (bruteForce) {\n this._currentProgram = null;\n this.resetTextureCache();\n this._stencilStateComposer.reset();\n this._depthCullingState.reset();\n this._depthCullingState.depthFunc = this._gl.LEQUAL;\n this._alphaState.reset();\n this._alphaMode = 1;\n this._alphaEquation = 0;\n this._colorWrite = true;\n this._colorWriteChanged = true;\n this._unpackFlipYCached = null;\n this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);\n this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);\n this._mustWipeVertexAttributes = true;\n this.unbindAllAttributes();\n }\n this._resetVertexBufferBinding();\n this._cachedIndexBuffer = null;\n this._cachedEffectForVertexBuffers = null;\n this.bindIndexBuffer(null);\n }\n /**\n * @internal\n */\n _getSamplingParameters(samplingMode, generateMipMaps) {\n const gl = this._gl;\n let magFilter = gl.NEAREST;\n let minFilter = gl.NEAREST;\n switch (samplingMode) {\n case 11:\n magFilter = gl.LINEAR;\n if (generateMipMaps) {\n minFilter = gl.LINEAR_MIPMAP_NEAREST;\n }\n else {\n minFilter = gl.LINEAR;\n }\n break;\n case 3:\n magFilter = gl.LINEAR;\n if (generateMipMaps) {\n minFilter = gl.LINEAR_MIPMAP_LINEAR;\n }\n else {\n minFilter = gl.LINEAR;\n }\n break;\n case 8:\n magFilter = gl.NEAREST;\n if (generateMipMaps) {\n minFilter = gl.NEAREST_MIPMAP_LINEAR;\n }\n else {\n minFilter = gl.NEAREST;\n }\n break;\n case 4:\n magFilter = gl.NEAREST;\n if (generateMipMaps) {\n minFilter = gl.NEAREST_MIPMAP_NEAREST;\n }\n else {\n minFilter = gl.NEAREST;\n }\n break;\n case 5:\n magFilter = gl.NEAREST;\n if (generateMipMaps) {\n minFilter = gl.LINEAR_MIPMAP_NEAREST;\n }\n else {\n minFilter = gl.LINEAR;\n }\n break;\n case 6:\n magFilter = gl.NEAREST;\n if (generateMipMaps) {\n minFilter = gl.LINEAR_MIPMAP_LINEAR;\n }\n else {\n minFilter = gl.LINEAR;\n }\n break;\n case 7:\n magFilter = gl.NEAREST;\n minFilter = gl.LINEAR;\n break;\n case 1:\n magFilter = gl.NEAREST;\n minFilter = gl.NEAREST;\n break;\n case 9:\n magFilter = gl.LINEAR;\n if (generateMipMaps) {\n minFilter = gl.NEAREST_MIPMAP_NEAREST;\n }\n else {\n minFilter = gl.NEAREST;\n }\n break;\n case 10:\n magFilter = gl.LINEAR;\n if (generateMipMaps) {\n minFilter = gl.NEAREST_MIPMAP_LINEAR;\n }\n else {\n minFilter = gl.NEAREST;\n }\n break;\n case 2:\n magFilter = gl.LINEAR;\n minFilter = gl.LINEAR;\n break;\n case 12:\n magFilter = gl.LINEAR;\n minFilter = gl.NEAREST;\n break;\n }\n return {\n min: minFilter,\n mag: magFilter,\n };\n }\n /** @internal */\n _createTexture() {\n const texture = this._gl.createTexture();\n if (!texture) {\n throw new Error(\"Unable to create texture\");\n }\n return texture;\n }\n /** @internal */\n _createHardwareTexture() {\n return new WebGLHardwareTexture(this._createTexture(), this._gl);\n }\n /**\n * Creates an internal texture without binding it to a framebuffer\n * @internal\n * @param size defines the size of the texture\n * @param options defines the options used to create the texture\n * @param delayGPUTextureCreation true to delay the texture creation the first time it is really needed. false to create it right away\n * @param source source type of the texture\n * @returns a new internal texture\n */\n _createInternalTexture(size, options, delayGPUTextureCreation = true, source = InternalTextureSource.Unknown) {\n var _a;\n let generateMipMaps = false;\n let type = 0;\n let samplingMode = 3;\n let format = 5;\n let useSRGBBuffer = false;\n let samples = 1;\n let label;\n if (options !== undefined && typeof options === \"object\") {\n generateMipMaps = !!options.generateMipMaps;\n type = options.type === undefined ? 0 : options.type;\n samplingMode = options.samplingMode === undefined ? 3 : options.samplingMode;\n format = options.format === undefined ? 5 : options.format;\n useSRGBBuffer = options.useSRGBBuffer === undefined ? false : options.useSRGBBuffer;\n samples = (_a = options.samples) !== null && _a !== void 0 ? _a : 1;\n label = options.label;\n }\n else {\n generateMipMaps = !!options;\n }\n useSRGBBuffer && (useSRGBBuffer = this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU));\n if (type === 1 && !this._caps.textureFloatLinearFiltering) {\n // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE\n samplingMode = 1;\n }\n else if (type === 2 && !this._caps.textureHalfFloatLinearFiltering) {\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\n samplingMode = 1;\n }\n if (type === 1 && !this._caps.textureFloat) {\n type = 0;\n Logger.Warn(\"Float textures are not supported. Type forced to TEXTURETYPE_UNSIGNED_BYTE\");\n }\n const gl = this._gl;\n const texture = new InternalTexture(this, source);\n const width = size.width || size;\n const height = size.height || size;\n const layers = size.layers || 0;\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\n const target = layers !== 0 ? gl.TEXTURE_2D_ARRAY : gl.TEXTURE_2D;\n const sizedFormat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);\n const internalFormat = this._getInternalFormat(format);\n const textureType = this._getWebGLTextureType(type);\n // Bind\n this._bindTextureDirectly(target, texture);\n if (layers !== 0) {\n texture.is2DArray = true;\n gl.texImage3D(target, 0, sizedFormat, width, height, layers, 0, internalFormat, textureType, null);\n }\n else {\n gl.texImage2D(target, 0, sizedFormat, width, height, 0, internalFormat, textureType, null);\n }\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, filters.mag);\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, filters.min);\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n // MipMaps\n if (generateMipMaps) {\n this._gl.generateMipmap(target);\n }\n this._bindTextureDirectly(target, null);\n texture._useSRGBBuffer = useSRGBBuffer;\n texture.baseWidth = width;\n texture.baseHeight = height;\n texture.width = width;\n texture.height = height;\n texture.depth = layers;\n texture.isReady = true;\n texture.samples = samples;\n texture.generateMipMaps = generateMipMaps;\n texture.samplingMode = samplingMode;\n texture.type = type;\n texture.format = format;\n texture.label = label;\n this._internalTexturesCache.push(texture);\n return texture;\n }\n /**\n * @internal\n */\n _getUseSRGBBuffer(useSRGBBuffer, noMipmap) {\n // Generating mipmaps for sRGB textures is not supported in WebGL1 so we must disable the support if mipmaps is enabled\n return useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU || noMipmap);\n }\n _createTextureBase(url, noMipmap, invertY, scene, samplingMode = 3, onLoad = null, onError = null, prepareTexture, prepareTextureProcessFunction, buffer = null, fallback = null, format = null, forcedExtension = null, mimeType, loaderOptions, useSRGBBuffer) {\n url = url || \"\";\n const fromData = url.substr(0, 5) === \"data:\";\n const fromBlob = url.substr(0, 5) === \"blob:\";\n const isBase64 = fromData && url.indexOf(\";base64,\") !== -1;\n const texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Url);\n if (texture !== fallback) {\n texture.label = url.substring(0, 60); // default label, can be overriden by the caller\n }\n const originalUrl = url;\n if (this._transformTextureUrl && !isBase64 && !fallback && !buffer) {\n url = this._transformTextureUrl(url);\n }\n if (originalUrl !== url) {\n texture._originalUrl = originalUrl;\n }\n // establish the file extension, if possible\n const lastDot = url.lastIndexOf(\".\");\n let extension = forcedExtension ? forcedExtension : lastDot > -1 ? url.substring(lastDot).toLowerCase() : \"\";\n let loader = null;\n // Remove query string\n const queryStringIndex = extension.indexOf(\"?\");\n if (queryStringIndex > -1) {\n extension = extension.split(\"?\")[0];\n }\n for (const availableLoader of ThinEngine._TextureLoaders) {\n if (availableLoader.canLoad(extension, mimeType)) {\n loader = availableLoader;\n break;\n }\n }\n if (scene) {\n scene.addPendingData(texture);\n }\n texture.url = url;\n texture.generateMipMaps = !noMipmap;\n texture.samplingMode = samplingMode;\n texture.invertY = invertY;\n texture._useSRGBBuffer = this._getUseSRGBBuffer(!!useSRGBBuffer, noMipmap);\n if (!this._doNotHandleContextLost) {\n // Keep a link to the buffer only if we plan to handle context lost\n texture._buffer = buffer;\n }\n let onLoadObserver = null;\n if (onLoad && !fallback) {\n onLoadObserver = texture.onLoadedObservable.add(onLoad);\n }\n if (!fallback) {\n this._internalTexturesCache.push(texture);\n }\n const onInternalError = (message, exception) => {\n if (scene) {\n scene.removePendingData(texture);\n }\n if (url === originalUrl) {\n if (onLoadObserver) {\n texture.onLoadedObservable.remove(onLoadObserver);\n }\n if (EngineStore.UseFallbackTexture) {\n this._createTextureBase(EngineStore.FallbackTexture, noMipmap, texture.invertY, scene, samplingMode, null, onError, prepareTexture, prepareTextureProcessFunction, buffer, texture);\n }\n message = (message || \"Unknown error\") + (EngineStore.UseFallbackTexture ? \" - Fallback texture was used\" : \"\");\n texture.onErrorObservable.notifyObservers({ message, exception });\n if (onError) {\n onError(message, exception);\n }\n }\n else {\n // fall back to the original url if the transformed url fails to load\n Logger.Warn(`Failed to load ${url}, falling back to ${originalUrl}`);\n this._createTextureBase(originalUrl, noMipmap, texture.invertY, scene, samplingMode, onLoad, onError, prepareTexture, prepareTextureProcessFunction, buffer, texture, format, forcedExtension, mimeType, loaderOptions, useSRGBBuffer);\n }\n };\n // processing for non-image formats\n if (loader) {\n const callback = (data) => {\n loader.loadData(data, texture, (width, height, loadMipmap, isCompressed, done, loadFailed) => {\n if (loadFailed) {\n onInternalError(\"TextureLoader failed to load data\");\n }\n else {\n prepareTexture(texture, extension, scene, { width, height }, texture.invertY, !loadMipmap, isCompressed, () => {\n done();\n return false;\n }, samplingMode);\n }\n }, loaderOptions);\n };\n if (!buffer) {\n this._loadFile(url, (data) => callback(new Uint8Array(data)), undefined, scene ? scene.offlineProvider : undefined, true, (request, exception) => {\n onInternalError(\"Unable to load \" + (request ? request.responseURL : url, exception));\n });\n }\n else {\n if (buffer instanceof ArrayBuffer) {\n callback(new Uint8Array(buffer));\n }\n else if (ArrayBuffer.isView(buffer)) {\n callback(buffer);\n }\n else {\n if (onError) {\n onError(\"Unable to load: only ArrayBuffer or ArrayBufferView is supported\", null);\n }\n }\n }\n }\n else {\n const onload = (img) => {\n if (fromBlob && !this._doNotHandleContextLost) {\n // We need to store the image if we need to rebuild the texture\n // in case of a webgl context lost\n texture._buffer = img;\n }\n prepareTexture(texture, extension, scene, img, texture.invertY, noMipmap, false, prepareTextureProcessFunction, samplingMode);\n };\n // According to the WebGL spec section 6.10, ImageBitmaps must be inverted on creation.\n // So, we pass imageOrientation to _FileToolsLoadImage() as it may create an ImageBitmap.\n if (!fromData || isBase64) {\n if (buffer && (typeof buffer.decoding === \"string\" || buffer.close)) {\n onload(buffer);\n }\n else {\n ThinEngine._FileToolsLoadImage(url, onload, onInternalError, scene ? scene.offlineProvider : null, mimeType, texture.invertY && this._features.needsInvertingBitmap ? { imageOrientation: \"flipY\" } : undefined);\n }\n }\n else if (typeof buffer === \"string\" || buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer) || buffer instanceof Blob) {\n ThinEngine._FileToolsLoadImage(buffer, onload, onInternalError, scene ? scene.offlineProvider : null, mimeType, texture.invertY && this._features.needsInvertingBitmap ? { imageOrientation: \"flipY\" } : undefined);\n }\n else if (buffer) {\n onload(buffer);\n }\n }\n return texture;\n }\n /**\n * Usually called from Texture.ts.\n * Passed information to create a WebGLTexture\n * @param url defines a value which contains one of the following:\n * * A conventional http URL, e.g. 'http://...' or 'file://...'\n * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'\n * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'\n * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file\n * @param invertY when true, image is flipped when loaded. You probably want true. Certain compressed textures may invert this if their default is inverted (eg. ktx)\n * @param scene needed for loading to the correct scene\n * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)\n * @param onLoad optional callback to be called upon successful completion\n * @param onError optional callback to be called upon failure\n * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob\n * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities\n * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures\n * @param forcedExtension defines the extension to use to pick the right loader\n * @param mimeType defines an optional mime type\n * @param loaderOptions options to be passed to the loader\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\n * @returns a InternalTexture for assignment back into BABYLON.Texture\n */\n createTexture(url, noMipmap, invertY, scene, samplingMode = 3, onLoad = null, onError = null, buffer = null, fallback = null, format = null, forcedExtension = null, mimeType, loaderOptions, creationFlags, useSRGBBuffer) {\n return this._createTextureBase(url, noMipmap, invertY, scene, samplingMode, onLoad, onError, this._prepareWebGLTexture.bind(this), (potWidth, potHeight, img, extension, texture, continuationCallback) => {\n const gl = this._gl;\n const isPot = img.width === potWidth && img.height === potHeight;\n const internalFormat = format\n ? this._getInternalFormat(format, texture._useSRGBBuffer)\n : extension === \".jpg\" && !texture._useSRGBBuffer\n ? gl.RGB\n : texture._useSRGBBuffer\n ? this._glSRGBExtensionValues.SRGB8_ALPHA8\n : gl.RGBA;\n let texelFormat = format ? this._getInternalFormat(format) : extension === \".jpg\" && !texture._useSRGBBuffer ? gl.RGB : gl.RGBA;\n if (texture._useSRGBBuffer && this.webGLVersion === 1) {\n texelFormat = internalFormat;\n }\n if (isPot) {\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, img);\n return false;\n }\n const maxTextureSize = this._caps.maxTextureSize;\n if (img.width > maxTextureSize || img.height > maxTextureSize || !this._supportsHardwareTextureRescaling) {\n this._prepareWorkingCanvas();\n if (!this._workingCanvas || !this._workingContext) {\n return false;\n }\n this._workingCanvas.width = potWidth;\n this._workingCanvas.height = potHeight;\n this._workingContext.drawImage(img, 0, 0, img.width, img.height, 0, 0, potWidth, potHeight);\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, this._workingCanvas);\n texture.width = potWidth;\n texture.height = potHeight;\n return false;\n }\n else {\n // Using shaders when possible to rescale because canvas.drawImage is lossy\n const source = new InternalTexture(this, InternalTextureSource.Temp);\n this._bindTextureDirectly(gl.TEXTURE_2D, source, true);\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, img);\n this._rescaleTexture(source, texture, scene, internalFormat, () => {\n this._releaseTexture(source);\n this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);\n continuationCallback();\n });\n }\n return true;\n }, buffer, fallback, format, forcedExtension, mimeType, loaderOptions, useSRGBBuffer);\n }\n /**\n * Loads an image as an HTMLImageElement.\n * @param input url string, ArrayBuffer, or Blob to load\n * @param onLoad callback called when the image successfully loads\n * @param onError callback called when the image fails to load\n * @param offlineProvider offline provider for caching\n * @param mimeType optional mime type\n * @param imageBitmapOptions optional the options to use when creating an ImageBitmap\n * @returns the HTMLImageElement of the loaded image\n * @internal\n */\n static _FileToolsLoadImage(input, onLoad, onError, offlineProvider, mimeType, imageBitmapOptions) {\n throw _WarnImport(\"FileTools\");\n }\n /**\n * @internal\n */\n _rescaleTexture(source, destination, scene, internalFormat, onComplete) { }\n /**\n * Creates a raw texture\n * @param data defines the data to store in the texture\n * @param width defines the width of the texture\n * @param height defines the height of the texture\n * @param format defines the format of the data\n * @param generateMipMaps defines if the engine should generate the mip levels\n * @param invertY defines if data must be stored with Y axis inverted\n * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)\n * @param compression defines the compression used (null by default)\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\n * @returns the raw texture inside an InternalTexture\n */\n createRawTexture(data, width, height, format, generateMipMaps, invertY, samplingMode, compression = null, type = 0, creationFlags = 0, useSRGBBuffer = false) {\n throw _WarnImport(\"Engine.RawTexture\");\n }\n /**\n * Creates a new raw cube texture\n * @param data defines the array of data to use to create each face\n * @param size defines the size of the textures\n * @param format defines the format of the data\n * @param type defines the type of the data (like Engine.TEXTURETYPE_UNSIGNED_INT)\n * @param generateMipMaps defines if the engine should generate the mip levels\n * @param invertY defines if data must be stored with Y axis inverted\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\n * @param compression defines the compression used (null by default)\n * @returns the cube texture as an InternalTexture\n */\n createRawCubeTexture(data, size, format, type, generateMipMaps, invertY, samplingMode, compression = null) {\n throw _WarnImport(\"Engine.RawTexture\");\n }\n /**\n * Creates a new raw 3D texture\n * @param data defines the data used to create the texture\n * @param width defines the width of the texture\n * @param height defines the height of the texture\n * @param depth defines the depth of the texture\n * @param format defines the format of the texture\n * @param generateMipMaps defines if the engine must generate mip levels\n * @param invertY defines if data must be stored with Y axis inverted\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\n * @param compression defines the compressed used (can be null)\n * @param textureType defines the compressed used (can be null)\n * @returns a new raw 3D texture (stored in an InternalTexture)\n */\n createRawTexture3D(data, width, height, depth, format, generateMipMaps, invertY, samplingMode, compression = null, textureType = 0) {\n throw _WarnImport(\"Engine.RawTexture\");\n }\n /**\n * Creates a new raw 2D array texture\n * @param data defines the data used to create the texture\n * @param width defines the width of the texture\n * @param height defines the height of the texture\n * @param depth defines the number of layers of the texture\n * @param format defines the format of the texture\n * @param generateMipMaps defines if the engine must generate mip levels\n * @param invertY defines if data must be stored with Y axis inverted\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\n * @param compression defines the compressed used (can be null)\n * @param textureType defines the compressed used (can be null)\n * @returns a new raw 2D array texture (stored in an InternalTexture)\n */\n createRawTexture2DArray(data, width, height, depth, format, generateMipMaps, invertY, samplingMode, compression = null, textureType = 0) {\n throw _WarnImport(\"Engine.RawTexture\");\n }\n /**\n * @internal\n */\n _unpackFlipY(value) {\n if (this._unpackFlipYCached !== value) {\n this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, value ? 1 : 0);\n if (this.enableUnpackFlipYCached) {\n this._unpackFlipYCached = value;\n }\n }\n }\n /** @internal */\n _getUnpackAlignement() {\n return this._gl.getParameter(this._gl.UNPACK_ALIGNMENT);\n }\n _getTextureTarget(texture) {\n if (texture.isCube) {\n return this._gl.TEXTURE_CUBE_MAP;\n }\n else if (texture.is3D) {\n return this._gl.TEXTURE_3D;\n }\n else if (texture.is2DArray || texture.isMultiview) {\n return this._gl.TEXTURE_2D_ARRAY;\n }\n return this._gl.TEXTURE_2D;\n }\n /**\n * Update the sampling mode of a given texture\n * @param samplingMode defines the required sampling mode\n * @param texture defines the texture to update\n * @param generateMipMaps defines whether to generate mipmaps for the texture\n */\n updateTextureSamplingMode(samplingMode, texture, generateMipMaps = false) {\n const target = this._getTextureTarget(texture);\n const filters = this._getSamplingParameters(samplingMode, texture.useMipMaps || generateMipMaps);\n this._setTextureParameterInteger(target, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);\n this._setTextureParameterInteger(target, this._gl.TEXTURE_MIN_FILTER, filters.min);\n if (generateMipMaps) {\n texture.generateMipMaps = true;\n this._gl.generateMipmap(target);\n }\n this._bindTextureDirectly(target, null);\n texture.samplingMode = samplingMode;\n }\n /**\n * Update the dimensions of a texture\n * @param texture texture to update\n * @param width new width of the texture\n * @param height new height of the texture\n * @param depth new depth of the texture\n */\n updateTextureDimensions(texture, width, height, depth = 1) { }\n /**\n * Update the sampling mode of a given texture\n * @param texture defines the texture to update\n * @param wrapU defines the texture wrap mode of the u coordinates\n * @param wrapV defines the texture wrap mode of the v coordinates\n * @param wrapR defines the texture wrap mode of the r coordinates\n */\n updateTextureWrappingMode(texture, wrapU, wrapV = null, wrapR = null) {\n const target = this._getTextureTarget(texture);\n if (wrapU !== null) {\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(wrapU), texture);\n texture._cachedWrapU = wrapU;\n }\n if (wrapV !== null) {\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(wrapV), texture);\n texture._cachedWrapV = wrapV;\n }\n if ((texture.is2DArray || texture.is3D) && wrapR !== null) {\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(wrapR), texture);\n texture._cachedWrapR = wrapR;\n }\n this._bindTextureDirectly(target, null);\n }\n /**\n * @internal\n */\n _setupDepthStencilTexture(internalTexture, size, generateStencil, bilinearFiltering, comparisonFunction, samples = 1) {\n const width = size.width || size;\n const height = size.height || size;\n const layers = size.layers || 0;\n internalTexture.baseWidth = width;\n internalTexture.baseHeight = height;\n internalTexture.width = width;\n internalTexture.height = height;\n internalTexture.is2DArray = layers > 0;\n internalTexture.depth = layers;\n internalTexture.isReady = true;\n internalTexture.samples = samples;\n internalTexture.generateMipMaps = false;\n internalTexture.samplingMode = bilinearFiltering ? 2 : 1;\n internalTexture.type = 0;\n internalTexture._comparisonFunction = comparisonFunction;\n const gl = this._gl;\n const target = this._getTextureTarget(internalTexture);\n const samplingParameters = this._getSamplingParameters(internalTexture.samplingMode, false);\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, samplingParameters.mag);\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, samplingParameters.min);\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n // TEXTURE_COMPARE_FUNC/MODE are only availble in WebGL2.\n if (this.webGLVersion > 1) {\n if (comparisonFunction === 0) {\n gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, 515);\n gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.NONE);\n }\n else {\n gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);\n gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);\n }\n }\n }\n /**\n * @internal\n */\n _uploadCompressedDataToTextureDirectly(texture, internalFormat, width, height, data, faceIndex = 0, lod = 0) {\n const gl = this._gl;\n let target = gl.TEXTURE_2D;\n if (texture.isCube) {\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\n }\n if (texture._useSRGBBuffer) {\n switch (internalFormat) {\n case 37492:\n case 36196:\n // Note, if using ETC1 and sRGB is requested, this will use ETC2 if available.\n if (this._caps.etc2) {\n internalFormat = gl.COMPRESSED_SRGB8_ETC2;\n }\n else {\n texture._useSRGBBuffer = false;\n }\n break;\n case 37496:\n if (this._caps.etc2) {\n internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;\n }\n else {\n texture._useSRGBBuffer = false;\n }\n break;\n case 36492:\n internalFormat = gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;\n break;\n case 37808:\n internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;\n break;\n case 33776:\n if (this._caps.s3tc_srgb) {\n internalFormat = gl.COMPRESSED_SRGB_S3TC_DXT1_EXT;\n }\n else {\n // S3TC sRGB extension not supported\n texture._useSRGBBuffer = false;\n }\n break;\n case 33777:\n if (this._caps.s3tc_srgb) {\n internalFormat = gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;\n }\n else {\n // S3TC sRGB extension not supported\n texture._useSRGBBuffer = false;\n }\n break;\n case 33779:\n if (this._caps.s3tc_srgb) {\n internalFormat = gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;\n }\n else {\n // S3TC sRGB extension not supported\n texture._useSRGBBuffer = false;\n }\n break;\n default:\n // We don't support a sRGB format corresponding to internalFormat, so revert to non sRGB format\n texture._useSRGBBuffer = false;\n break;\n }\n }\n this._gl.compressedTexImage2D(target, lod, internalFormat, width, height, 0, data);\n }\n /**\n * @internal\n */\n _uploadDataToTextureDirectly(texture, imageData, faceIndex = 0, lod = 0, babylonInternalFormat, useTextureWidthAndHeight = false) {\n const gl = this._gl;\n const textureType = this._getWebGLTextureType(texture.type);\n const format = this._getInternalFormat(texture.format);\n const internalFormat = babylonInternalFormat === undefined\n ? this._getRGBABufferInternalSizedFormat(texture.type, texture.format, texture._useSRGBBuffer)\n : this._getInternalFormat(babylonInternalFormat, texture._useSRGBBuffer);\n this._unpackFlipY(texture.invertY);\n let target = gl.TEXTURE_2D;\n if (texture.isCube) {\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\n }\n const lodMaxWidth = Math.round(Math.log(texture.width) * Math.LOG2E);\n const lodMaxHeight = Math.round(Math.log(texture.height) * Math.LOG2E);\n const width = useTextureWidthAndHeight ? texture.width : Math.pow(2, Math.max(lodMaxWidth - lod, 0));\n const height = useTextureWidthAndHeight ? texture.height : Math.pow(2, Math.max(lodMaxHeight - lod, 0));\n gl.texImage2D(target, lod, internalFormat, width, height, 0, format, textureType, imageData);\n }\n /**\n * Update a portion of an internal texture\n * @param texture defines the texture to update\n * @param imageData defines the data to store into the texture\n * @param xOffset defines the x coordinates of the update rectangle\n * @param yOffset defines the y coordinates of the update rectangle\n * @param width defines the width of the update rectangle\n * @param height defines the height of the update rectangle\n * @param faceIndex defines the face index if texture is a cube (0 by default)\n * @param lod defines the lod level to update (0 by default)\n * @param generateMipMaps defines whether to generate mipmaps or not\n */\n updateTextureData(texture, imageData, xOffset, yOffset, width, height, faceIndex = 0, lod = 0, generateMipMaps = false) {\n const gl = this._gl;\n const textureType = this._getWebGLTextureType(texture.type);\n const format = this._getInternalFormat(texture.format);\n this._unpackFlipY(texture.invertY);\n let targetForBinding = gl.TEXTURE_2D;\n let target = gl.TEXTURE_2D;\n if (texture.isCube) {\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\n targetForBinding = gl.TEXTURE_CUBE_MAP;\n }\n this._bindTextureDirectly(targetForBinding, texture, true);\n gl.texSubImage2D(target, lod, xOffset, yOffset, width, height, format, textureType, imageData);\n if (generateMipMaps) {\n this._gl.generateMipmap(target);\n }\n this._bindTextureDirectly(targetForBinding, null);\n }\n /**\n * @internal\n */\n _uploadArrayBufferViewToTexture(texture, imageData, faceIndex = 0, lod = 0) {\n const gl = this._gl;\n const bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;\n this._bindTextureDirectly(bindTarget, texture, true);\n this._uploadDataToTextureDirectly(texture, imageData, faceIndex, lod);\n this._bindTextureDirectly(bindTarget, null, true);\n }\n _prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode) {\n const gl = this._gl;\n if (!gl) {\n return;\n }\n const filters = this._getSamplingParameters(samplingMode, !noMipmap);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);\n if (!noMipmap && !isCompressed) {\n gl.generateMipmap(gl.TEXTURE_2D);\n }\n this._bindTextureDirectly(gl.TEXTURE_2D, null);\n // this.resetTextureCache();\n if (scene) {\n scene.removePendingData(texture);\n }\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n }\n _prepareWebGLTexture(texture, extension, scene, img, invertY, noMipmap, isCompressed, processFunction, samplingMode = 3) {\n const maxTextureSize = this.getCaps().maxTextureSize;\n const potWidth = Math.min(maxTextureSize, this.needPOTTextures ? ThinEngine.GetExponentOfTwo(img.width, maxTextureSize) : img.width);\n const potHeight = Math.min(maxTextureSize, this.needPOTTextures ? ThinEngine.GetExponentOfTwo(img.height, maxTextureSize) : img.height);\n const gl = this._gl;\n if (!gl) {\n return;\n }\n if (!texture._hardwareTexture) {\n // this.resetTextureCache();\n if (scene) {\n scene.removePendingData(texture);\n }\n return;\n }\n this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\n texture.baseWidth = img.width;\n texture.baseHeight = img.height;\n texture.width = potWidth;\n texture.height = potHeight;\n texture.isReady = true;\n if (processFunction(potWidth, potHeight, img, extension, texture, () => {\n this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);\n })) {\n // Returning as texture needs extra async steps\n return;\n }\n this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);\n }\n /**\n * @internal\n */\n _setupFramebufferDepthAttachments(generateStencilBuffer, generateDepthBuffer, width, height, samples = 1) {\n const gl = this._gl;\n // Create the depth/stencil buffer\n if (generateStencilBuffer && generateDepthBuffer) {\n return this._createRenderBuffer(width, height, samples, gl.DEPTH_STENCIL, gl.DEPTH24_STENCIL8, gl.DEPTH_STENCIL_ATTACHMENT);\n }\n if (generateDepthBuffer) {\n let depthFormat = gl.DEPTH_COMPONENT16;\n if (this._webGLVersion > 1) {\n depthFormat = gl.DEPTH_COMPONENT32F;\n }\n return this._createRenderBuffer(width, height, samples, depthFormat, depthFormat, gl.DEPTH_ATTACHMENT);\n }\n if (generateStencilBuffer) {\n return this._createRenderBuffer(width, height, samples, gl.STENCIL_INDEX8, gl.STENCIL_INDEX8, gl.STENCIL_ATTACHMENT);\n }\n return null;\n }\n /**\n * @internal\n */\n _createRenderBuffer(width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer = true) {\n const gl = this._gl;\n const renderBuffer = gl.createRenderbuffer();\n return this._updateRenderBuffer(renderBuffer, width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer);\n }\n _updateRenderBuffer(renderBuffer, width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer = true) {\n const gl = this._gl;\n gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);\n if (samples > 1 && gl.renderbufferStorageMultisample) {\n gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, msInternalFormat, width, height);\n }\n else {\n gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);\n }\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderBuffer);\n if (unbindBuffer) {\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\n }\n return renderBuffer;\n }\n /**\n * @internal\n */\n _releaseTexture(texture) {\n var _a;\n this._deleteTexture((_a = texture._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource);\n // Unbind channels\n this.unbindAllTextures();\n const index = this._internalTexturesCache.indexOf(texture);\n if (index !== -1) {\n this._internalTexturesCache.splice(index, 1);\n }\n // Integrated fixed lod samplers.\n if (texture._lodTextureHigh) {\n texture._lodTextureHigh.dispose();\n }\n if (texture._lodTextureMid) {\n texture._lodTextureMid.dispose();\n }\n if (texture._lodTextureLow) {\n texture._lodTextureLow.dispose();\n }\n // Integrated irradiance map.\n if (texture._irradianceTexture) {\n texture._irradianceTexture.dispose();\n }\n }\n /**\n * @internal\n */\n _releaseRenderTargetWrapper(rtWrapper) {\n const index = this._renderTargetWrapperCache.indexOf(rtWrapper);\n if (index !== -1) {\n this._renderTargetWrapperCache.splice(index, 1);\n }\n }\n _deleteTexture(texture) {\n if (texture) {\n this._gl.deleteTexture(texture);\n }\n }\n _setProgram(program) {\n if (this._currentProgram !== program) {\n this._gl.useProgram(program);\n this._currentProgram = program;\n }\n }\n /**\n * Binds an effect to the webGL context\n * @param effect defines the effect to bind\n */\n bindSamplers(effect) {\n const webGLPipelineContext = effect.getPipelineContext();\n this._setProgram(webGLPipelineContext.program);\n const samplers = effect.getSamplers();\n for (let index = 0; index < samplers.length; index++) {\n const uniform = effect.getUniform(samplers[index]);\n if (uniform) {\n this._boundUniforms[index] = uniform;\n }\n }\n this._currentEffect = null;\n }\n _activateCurrentTexture() {\n if (this._currentTextureChannel !== this._activeChannel) {\n this._gl.activeTexture(this._gl.TEXTURE0 + this._activeChannel);\n this._currentTextureChannel = this._activeChannel;\n }\n }\n /**\n * @internal\n */\n _bindTextureDirectly(target, texture, forTextureDataUpdate = false, force = false) {\n var _a, _b;\n let wasPreviouslyBound = false;\n const isTextureForRendering = texture && texture._associatedChannel > -1;\n if (forTextureDataUpdate && isTextureForRendering) {\n this._activeChannel = texture._associatedChannel;\n }\n const currentTextureBound = this._boundTexturesCache[this._activeChannel];\n if (currentTextureBound !== texture || force) {\n this._activateCurrentTexture();\n if (texture && texture.isMultiview) {\n //this._gl.bindTexture(target, texture ? texture._colorTextureArray : null);\n console.error(target, texture);\n throw \"_bindTextureDirectly called with a multiview texture!\";\n }\n else {\n this._gl.bindTexture(target, (_b = (_a = texture === null || texture === void 0 ? void 0 : texture._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource) !== null && _b !== void 0 ? _b : null);\n }\n this._boundTexturesCache[this._activeChannel] = texture;\n if (texture) {\n texture._associatedChannel = this._activeChannel;\n }\n }\n else if (forTextureDataUpdate) {\n wasPreviouslyBound = true;\n this._activateCurrentTexture();\n }\n if (isTextureForRendering && !forTextureDataUpdate) {\n this._bindSamplerUniformToChannel(texture._associatedChannel, this._activeChannel);\n }\n return wasPreviouslyBound;\n }\n /**\n * @internal\n */\n _bindTexture(channel, texture, name) {\n if (channel === undefined) {\n return;\n }\n if (texture) {\n texture._associatedChannel = channel;\n }\n this._activeChannel = channel;\n const target = texture ? this._getTextureTarget(texture) : this._gl.TEXTURE_2D;\n this._bindTextureDirectly(target, texture);\n }\n /**\n * Unbind all textures from the webGL context\n */\n unbindAllTextures() {\n for (let channel = 0; channel < this._maxSimultaneousTextures; channel++) {\n this._activeChannel = channel;\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\n if (this.webGLVersion > 1) {\n this._bindTextureDirectly(this._gl.TEXTURE_3D, null);\n this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null);\n }\n }\n }\n /**\n * Sets a texture to the according uniform.\n * @param channel The texture channel\n * @param uniform The uniform to set\n * @param texture The texture to apply\n * @param name The name of the uniform in the effect\n */\n setTexture(channel, uniform, texture, name) {\n if (channel === undefined) {\n return;\n }\n if (uniform) {\n this._boundUniforms[channel] = uniform;\n }\n this._setTexture(channel, texture);\n }\n _bindSamplerUniformToChannel(sourceSlot, destination) {\n const uniform = this._boundUniforms[sourceSlot];\n if (!uniform || uniform._currentState === destination) {\n return;\n }\n this._gl.uniform1i(uniform, destination);\n uniform._currentState = destination;\n }\n _getTextureWrapMode(mode) {\n switch (mode) {\n case 1:\n return this._gl.REPEAT;\n case 0:\n return this._gl.CLAMP_TO_EDGE;\n case 2:\n return this._gl.MIRRORED_REPEAT;\n }\n return this._gl.REPEAT;\n }\n _setTexture(channel, texture, isPartOfTextureArray = false, depthStencilTexture = false, name = \"\") {\n // Not ready?\n if (!texture) {\n if (this._boundTexturesCache[channel] != null) {\n this._activeChannel = channel;\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\n if (this.webGLVersion > 1) {\n this._bindTextureDirectly(this._gl.TEXTURE_3D, null);\n this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null);\n }\n }\n return false;\n }\n // Video\n if (texture.video) {\n this._activeChannel = channel;\n const videoInternalTexture = texture.getInternalTexture();\n if (videoInternalTexture) {\n videoInternalTexture._associatedChannel = channel;\n }\n texture.update();\n }\n else if (texture.delayLoadState === 4) {\n // Delay loading\n texture.delayLoad();\n return false;\n }\n let internalTexture;\n if (depthStencilTexture) {\n internalTexture = texture.depthStencilTexture;\n }\n else if (texture.isReady()) {\n internalTexture = texture.getInternalTexture();\n }\n else if (texture.isCube) {\n internalTexture = this.emptyCubeTexture;\n }\n else if (texture.is3D) {\n internalTexture = this.emptyTexture3D;\n }\n else if (texture.is2DArray) {\n internalTexture = this.emptyTexture2DArray;\n }\n else {\n internalTexture = this.emptyTexture;\n }\n if (!isPartOfTextureArray && internalTexture) {\n internalTexture._associatedChannel = channel;\n }\n let needToBind = true;\n if (this._boundTexturesCache[channel] === internalTexture) {\n if (!isPartOfTextureArray) {\n this._bindSamplerUniformToChannel(internalTexture._associatedChannel, channel);\n }\n needToBind = false;\n }\n this._activeChannel = channel;\n const target = this._getTextureTarget(internalTexture);\n if (needToBind) {\n this._bindTextureDirectly(target, internalTexture, isPartOfTextureArray);\n }\n if (internalTexture && !internalTexture.isMultiview) {\n // CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT.\n if (internalTexture.isCube && internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) {\n internalTexture._cachedCoordinatesMode = texture.coordinatesMode;\n const textureWrapMode = texture.coordinatesMode !== 3 && texture.coordinatesMode !== 5\n ? 1\n : 0;\n texture.wrapU = textureWrapMode;\n texture.wrapV = textureWrapMode;\n }\n if (internalTexture._cachedWrapU !== texture.wrapU) {\n internalTexture._cachedWrapU = texture.wrapU;\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);\n }\n if (internalTexture._cachedWrapV !== texture.wrapV) {\n internalTexture._cachedWrapV = texture.wrapV;\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);\n }\n if (internalTexture.is3D && internalTexture._cachedWrapR !== texture.wrapR) {\n internalTexture._cachedWrapR = texture.wrapR;\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(texture.wrapR), internalTexture);\n }\n this._setAnisotropicLevel(target, internalTexture, texture.anisotropicFilteringLevel);\n }\n return true;\n }\n /**\n * Sets an array of texture to the webGL context\n * @param channel defines the channel where the texture array must be set\n * @param uniform defines the associated uniform location\n * @param textures defines the array of textures to bind\n * @param name name of the channel\n */\n setTextureArray(channel, uniform, textures, name) {\n if (channel === undefined || !uniform) {\n return;\n }\n if (!this._textureUnits || this._textureUnits.length !== textures.length) {\n this._textureUnits = new Int32Array(textures.length);\n }\n for (let i = 0; i < textures.length; i++) {\n const texture = textures[i].getInternalTexture();\n if (texture) {\n this._textureUnits[i] = channel + i;\n texture._associatedChannel = channel + i;\n }\n else {\n this._textureUnits[i] = -1;\n }\n }\n this._gl.uniform1iv(uniform, this._textureUnits);\n for (let index = 0; index < textures.length; index++) {\n this._setTexture(this._textureUnits[index], textures[index], true);\n }\n }\n /**\n * @internal\n */\n _setAnisotropicLevel(target, internalTexture, anisotropicFilteringLevel) {\n const anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;\n if (internalTexture.samplingMode !== 11 &&\n internalTexture.samplingMode !== 3 &&\n internalTexture.samplingMode !== 2) {\n anisotropicFilteringLevel = 1; // Forcing the anisotropic to 1 because else webgl will force filters to linear\n }\n if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== anisotropicFilteringLevel) {\n this._setTextureParameterFloat(target, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(anisotropicFilteringLevel, this._caps.maxAnisotropy), internalTexture);\n internalTexture._cachedAnisotropicFilteringLevel = anisotropicFilteringLevel;\n }\n }\n _setTextureParameterFloat(target, parameter, value, texture) {\n this._bindTextureDirectly(target, texture, true, true);\n this._gl.texParameterf(target, parameter, value);\n }\n _setTextureParameterInteger(target, parameter, value, texture) {\n if (texture) {\n this._bindTextureDirectly(target, texture, true, true);\n }\n this._gl.texParameteri(target, parameter, value);\n }\n /**\n * Unbind all vertex attributes from the webGL context\n */\n unbindAllAttributes() {\n if (this._mustWipeVertexAttributes) {\n this._mustWipeVertexAttributes = false;\n for (let i = 0; i < this._caps.maxVertexAttribs; i++) {\n this.disableAttributeByIndex(i);\n }\n return;\n }\n for (let i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {\n if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {\n continue;\n }\n this.disableAttributeByIndex(i);\n }\n }\n /**\n * Force the engine to release all cached effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled\n */\n releaseEffects() {\n for (const name in this._compiledEffects) {\n const webGLPipelineContext = this._compiledEffects[name].getPipelineContext();\n this._deletePipelineContext(webGLPipelineContext);\n }\n this._compiledEffects = {};\n }\n /**\n * Dispose and release all associated resources\n */\n dispose() {\n var _a;\n this._isDisposed = true;\n this.stopRenderLoop();\n // Clear observables\n if (this.onBeforeTextureInitObservable) {\n this.onBeforeTextureInitObservable.clear();\n }\n // Empty texture\n if (this._emptyTexture) {\n this._releaseTexture(this._emptyTexture);\n this._emptyTexture = null;\n }\n if (this._emptyCubeTexture) {\n this._releaseTexture(this._emptyCubeTexture);\n this._emptyCubeTexture = null;\n }\n if (this._dummyFramebuffer) {\n this._gl.deleteFramebuffer(this._dummyFramebuffer);\n }\n // Release effects\n this.releaseEffects();\n (_a = this.releaseComputeEffects) === null || _a === void 0 ? void 0 : _a.call(this);\n // Unbind\n this.unbindAllAttributes();\n this._boundUniforms = {};\n // Events\n if (IsWindowObjectExist()) {\n if (this._renderingCanvas) {\n if (!this._doNotHandleContextLost) {\n this._renderingCanvas.removeEventListener(\"webglcontextlost\", this._onContextLost);\n this._renderingCanvas.removeEventListener(\"webglcontextrestored\", this._onContextRestored);\n }\n window.removeEventListener(\"resize\", this._checkForMobile);\n }\n }\n this._workingCanvas = null;\n this._workingContext = null;\n this._currentBufferPointers.length = 0;\n this._renderingCanvas = null;\n this._currentProgram = null;\n this._boundRenderFunction = null;\n Effect.ResetCache();\n // Abort active requests\n for (const request of this._activeRequests) {\n request.abort();\n }\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n }\n /**\n * Attach a new callback raised when context lost event is fired\n * @param callback defines the callback to call\n */\n attachContextLostEvent(callback) {\n if (this._renderingCanvas) {\n this._renderingCanvas.addEventListener(\"webglcontextlost\", callback, false);\n }\n }\n /**\n * Attach a new callback raised when context restored event is fired\n * @param callback defines the callback to call\n */\n attachContextRestoredEvent(callback) {\n if (this._renderingCanvas) {\n this._renderingCanvas.addEventListener(\"webglcontextrestored\", callback, false);\n }\n }\n /**\n * Get the current error code of the webGL context\n * @returns the error code\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError\n */\n getError() {\n return this._gl.getError();\n }\n _canRenderToFloatFramebuffer() {\n if (this._webGLVersion > 1) {\n return this._caps.colorBufferFloat;\n }\n return this._canRenderToFramebuffer(1);\n }\n _canRenderToHalfFloatFramebuffer() {\n if (this._webGLVersion > 1) {\n return this._caps.colorBufferFloat;\n }\n return this._canRenderToFramebuffer(2);\n }\n // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture\n _canRenderToFramebuffer(type) {\n const gl = this._gl;\n //clear existing errors\n // eslint-disable-next-line no-empty\n while (gl.getError() !== gl.NO_ERROR) { }\n let successful = true;\n const texture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(type), 1, 1, 0, gl.RGBA, this._getWebGLTextureType(type), null);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n const fb = gl.createFramebuffer();\n gl.bindFramebuffer(gl.FRAMEBUFFER, fb);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\n successful = successful && status === gl.FRAMEBUFFER_COMPLETE;\n successful = successful && gl.getError() === gl.NO_ERROR;\n //try render by clearing frame buffer's color buffer\n if (successful) {\n gl.clear(gl.COLOR_BUFFER_BIT);\n successful = successful && gl.getError() === gl.NO_ERROR;\n }\n //try reading from frame to ensure render occurs (just creating the FBO is not sufficient to determine if rendering is supported)\n if (successful) {\n //in practice it's sufficient to just read from the backbuffer rather than handle potentially issues reading from the texture\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n const readFormat = gl.RGBA;\n const readType = gl.UNSIGNED_BYTE;\n const buffer = new Uint8Array(4);\n gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer);\n successful = successful && gl.getError() === gl.NO_ERROR;\n }\n //clean up\n gl.deleteTexture(texture);\n gl.deleteFramebuffer(fb);\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n //clear accumulated errors\n // eslint-disable-next-line no-empty\n while (!successful && gl.getError() !== gl.NO_ERROR) { }\n return successful;\n }\n /**\n * @internal\n */\n _getWebGLTextureType(type) {\n if (this._webGLVersion === 1) {\n switch (type) {\n case 1:\n return this._gl.FLOAT;\n case 2:\n return this._gl.HALF_FLOAT_OES;\n case 0:\n return this._gl.UNSIGNED_BYTE;\n case 8:\n return this._gl.UNSIGNED_SHORT_4_4_4_4;\n case 9:\n return this._gl.UNSIGNED_SHORT_5_5_5_1;\n case 10:\n return this._gl.UNSIGNED_SHORT_5_6_5;\n }\n return this._gl.UNSIGNED_BYTE;\n }\n switch (type) {\n case 3:\n return this._gl.BYTE;\n case 0:\n return this._gl.UNSIGNED_BYTE;\n case 4:\n return this._gl.SHORT;\n case 5:\n return this._gl.UNSIGNED_SHORT;\n case 6:\n return this._gl.INT;\n case 7: // Refers to UNSIGNED_INT\n return this._gl.UNSIGNED_INT;\n case 1:\n return this._gl.FLOAT;\n case 2:\n return this._gl.HALF_FLOAT;\n case 8:\n return this._gl.UNSIGNED_SHORT_4_4_4_4;\n case 9:\n return this._gl.UNSIGNED_SHORT_5_5_5_1;\n case 10:\n return this._gl.UNSIGNED_SHORT_5_6_5;\n case 11:\n return this._gl.UNSIGNED_INT_2_10_10_10_REV;\n case 12:\n return this._gl.UNSIGNED_INT_24_8;\n case 13:\n return this._gl.UNSIGNED_INT_10F_11F_11F_REV;\n case 14:\n return this._gl.UNSIGNED_INT_5_9_9_9_REV;\n case 15:\n return this._gl.FLOAT_32_UNSIGNED_INT_24_8_REV;\n }\n return this._gl.UNSIGNED_BYTE;\n }\n /**\n * @internal\n */\n _getInternalFormat(format, useSRGBBuffer = false) {\n let internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;\n switch (format) {\n case 0:\n internalFormat = this._gl.ALPHA;\n break;\n case 1:\n internalFormat = this._gl.LUMINANCE;\n break;\n case 2:\n internalFormat = this._gl.LUMINANCE_ALPHA;\n break;\n case 6:\n internalFormat = this._gl.RED;\n break;\n case 7:\n internalFormat = this._gl.RG;\n break;\n case 4:\n internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;\n break;\n case 5:\n internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;\n break;\n }\n if (this._webGLVersion > 1) {\n switch (format) {\n case 8:\n internalFormat = this._gl.RED_INTEGER;\n break;\n case 9:\n internalFormat = this._gl.RG_INTEGER;\n break;\n case 10:\n internalFormat = this._gl.RGB_INTEGER;\n break;\n case 11:\n internalFormat = this._gl.RGBA_INTEGER;\n break;\n }\n }\n return internalFormat;\n }\n /**\n * @internal\n */\n _getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer = false) {\n if (this._webGLVersion === 1) {\n if (format !== undefined) {\n switch (format) {\n case 0:\n return this._gl.ALPHA;\n case 1:\n return this._gl.LUMINANCE;\n case 2:\n return this._gl.LUMINANCE_ALPHA;\n case 4:\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;\n }\n }\n return this._gl.RGBA;\n }\n switch (type) {\n case 3:\n switch (format) {\n case 6:\n return this._gl.R8_SNORM;\n case 7:\n return this._gl.RG8_SNORM;\n case 4:\n return this._gl.RGB8_SNORM;\n case 8:\n return this._gl.R8I;\n case 9:\n return this._gl.RG8I;\n case 10:\n return this._gl.RGB8I;\n case 11:\n return this._gl.RGBA8I;\n default:\n return this._gl.RGBA8_SNORM;\n }\n case 0:\n switch (format) {\n case 6:\n return this._gl.R8;\n case 7:\n return this._gl.RG8;\n case 4:\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8 : this._gl.RGB8; // By default. Other possibilities are RGB565, SRGB8.\n case 5:\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8; // By default. Other possibilities are RGB5_A1, RGBA4, SRGB8_ALPHA8.\n case 8:\n return this._gl.R8UI;\n case 9:\n return this._gl.RG8UI;\n case 10:\n return this._gl.RGB8UI;\n case 11:\n return this._gl.RGBA8UI;\n case 0:\n return this._gl.ALPHA;\n case 1:\n return this._gl.LUMINANCE;\n case 2:\n return this._gl.LUMINANCE_ALPHA;\n default:\n return this._gl.RGBA8;\n }\n case 4:\n switch (format) {\n case 8:\n return this._gl.R16I;\n case 9:\n return this._gl.RG16I;\n case 10:\n return this._gl.RGB16I;\n case 11:\n return this._gl.RGBA16I;\n default:\n return this._gl.RGBA16I;\n }\n case 5:\n switch (format) {\n case 8:\n return this._gl.R16UI;\n case 9:\n return this._gl.RG16UI;\n case 10:\n return this._gl.RGB16UI;\n case 11:\n return this._gl.RGBA16UI;\n default:\n return this._gl.RGBA16UI;\n }\n case 6:\n switch (format) {\n case 8:\n return this._gl.R32I;\n case 9:\n return this._gl.RG32I;\n case 10:\n return this._gl.RGB32I;\n case 11:\n return this._gl.RGBA32I;\n default:\n return this._gl.RGBA32I;\n }\n case 7: // Refers to UNSIGNED_INT\n switch (format) {\n case 8:\n return this._gl.R32UI;\n case 9:\n return this._gl.RG32UI;\n case 10:\n return this._gl.RGB32UI;\n case 11:\n return this._gl.RGBA32UI;\n default:\n return this._gl.RGBA32UI;\n }\n case 1:\n switch (format) {\n case 6:\n return this._gl.R32F; // By default. Other possibility is R16F.\n case 7:\n return this._gl.RG32F; // By default. Other possibility is RG16F.\n case 4:\n return this._gl.RGB32F; // By default. Other possibilities are RGB16F, R11F_G11F_B10F, RGB9_E5.\n case 5:\n return this._gl.RGBA32F; // By default. Other possibility is RGBA16F.\n default:\n return this._gl.RGBA32F;\n }\n case 2:\n switch (format) {\n case 6:\n return this._gl.R16F;\n case 7:\n return this._gl.RG16F;\n case 4:\n return this._gl.RGB16F; // By default. Other possibilities are R11F_G11F_B10F, RGB9_E5.\n case 5:\n return this._gl.RGBA16F;\n default:\n return this._gl.RGBA16F;\n }\n case 10:\n return this._gl.RGB565;\n case 13:\n return this._gl.R11F_G11F_B10F;\n case 14:\n return this._gl.RGB9_E5;\n case 8:\n return this._gl.RGBA4;\n case 9:\n return this._gl.RGB5_A1;\n case 11:\n switch (format) {\n case 5:\n return this._gl.RGB10_A2; // By default. Other possibility is RGB5_A1.\n case 11:\n return this._gl.RGB10_A2UI;\n default:\n return this._gl.RGB10_A2;\n }\n }\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8;\n }\n /**\n * @internal\n */\n _getRGBAMultiSampleBufferFormat(type, format = 5) {\n switch (type) {\n case 1:\n switch (format) {\n case 6:\n return this._gl.R32F;\n default:\n return this._gl.RGBA32F;\n }\n case 2:\n switch (format) {\n case 6:\n return this._gl.R16F;\n default:\n return this._gl.RGBA16F;\n }\n }\n return this._gl.RGBA8;\n }\n /**\n * @internal\n */\n _loadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError) {\n const request = ThinEngine._FileToolsLoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError);\n this._activeRequests.push(request);\n request.onCompleteObservable.add((request) => {\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\n });\n return request;\n }\n /**\n * Loads a file from a url\n * @param url url to load\n * @param onSuccess callback called when the file successfully loads\n * @param onProgress callback called while file is loading (if the server supports this mode)\n * @param offlineProvider defines the offline provider for caching\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\n * @param onError callback called when the file fails to load\n * @returns a file request object\n * @internal\n */\n static _FileToolsLoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError) {\n throw _WarnImport(\"FileTools\");\n }\n /**\n * Reads pixels from the current frame buffer. Please note that this function can be slow\n * @param x defines the x coordinate of the rectangle where pixels must be read\n * @param y defines the y coordinate of the rectangle where pixels must be read\n * @param width defines the width of the rectangle where pixels must be read\n * @param height defines the height of the rectangle where pixels must be read\n * @param hasAlpha defines whether the output should have alpha or not (defaults to true)\n * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels\n * @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors\n */\n readPixels(x, y, width, height, hasAlpha = true, flushRenderer = true) {\n const numChannels = hasAlpha ? 4 : 3;\n const format = hasAlpha ? this._gl.RGBA : this._gl.RGB;\n const data = new Uint8Array(height * width * numChannels);\n if (flushRenderer) {\n this.flushFramebuffer();\n }\n this._gl.readPixels(x, y, width, height, format, this._gl.UNSIGNED_BYTE, data);\n return Promise.resolve(data);\n }\n /**\n * Gets a Promise indicating if the engine can be instantiated (ie. if a webGL context can be found)\n */\n static get IsSupportedAsync() {\n return Promise.resolve(this.isSupported());\n }\n /**\n * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)\n */\n static get IsSupported() {\n return this.isSupported(); // Backward compat\n }\n /**\n * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)\n * @returns true if the engine can be created\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static isSupported() {\n if (this._HasMajorPerformanceCaveat !== null) {\n return !this._HasMajorPerformanceCaveat; // We know it is performant so WebGL is supported\n }\n if (this._IsSupported === null) {\n try {\n const tempcanvas = this._CreateCanvas(1, 1);\n const gl = tempcanvas.getContext(\"webgl\") || tempcanvas.getContext(\"experimental-webgl\");\n this._IsSupported = gl != null && !!window.WebGLRenderingContext;\n }\n catch (e) {\n this._IsSupported = false;\n }\n }\n return this._IsSupported;\n }\n /**\n * Gets a boolean indicating if the engine can be instantiated on a performant device (ie. if a webGL context can be found and it does not use a slow implementation)\n */\n static get HasMajorPerformanceCaveat() {\n if (this._HasMajorPerformanceCaveat === null) {\n try {\n const tempcanvas = this._CreateCanvas(1, 1);\n const gl = tempcanvas.getContext(\"webgl\", { failIfMajorPerformanceCaveat: true }) ||\n tempcanvas.getContext(\"experimental-webgl\", { failIfMajorPerformanceCaveat: true });\n this._HasMajorPerformanceCaveat = !gl;\n }\n catch (e) {\n this._HasMajorPerformanceCaveat = false;\n }\n }\n return this._HasMajorPerformanceCaveat;\n }\n /**\n * Find the next highest power of two.\n * @param x Number to start search from.\n * @returns Next highest power of two.\n */\n static CeilingPOT(x) {\n x--;\n x |= x >> 1;\n x |= x >> 2;\n x |= x >> 4;\n x |= x >> 8;\n x |= x >> 16;\n x++;\n return x;\n }\n /**\n * Find the next lowest power of two.\n * @param x Number to start search from.\n * @returns Next lowest power of two.\n */\n static FloorPOT(x) {\n x = x | (x >> 1);\n x = x | (x >> 2);\n x = x | (x >> 4);\n x = x | (x >> 8);\n x = x | (x >> 16);\n return x - (x >> 1);\n }\n /**\n * Find the nearest power of two.\n * @param x Number to start search from.\n * @returns Next nearest power of two.\n */\n static NearestPOT(x) {\n const c = ThinEngine.CeilingPOT(x);\n const f = ThinEngine.FloorPOT(x);\n return c - x > x - f ? f : c;\n }\n /**\n * Get the closest exponent of two\n * @param value defines the value to approximate\n * @param max defines the maximum value to return\n * @param mode defines how to define the closest value\n * @returns closest exponent of two of the given value\n */\n static GetExponentOfTwo(value, max, mode = 2) {\n let pot;\n switch (mode) {\n case 1:\n pot = ThinEngine.FloorPOT(value);\n break;\n case 2:\n pot = ThinEngine.NearestPOT(value);\n break;\n case 3:\n default:\n pot = ThinEngine.CeilingPOT(value);\n break;\n }\n return Math.min(pot, max);\n }\n /**\n * Queue a new function into the requested animation frame pool (ie. this function will be executed by the browser (or the javascript engine) for the next frame)\n * @param func - the function to be called\n * @param requester - the object that will request the next frame. Falls back to window.\n * @returns frame number\n */\n static QueueNewFrame(func, requester) {\n // Note that there is kind of a typing issue here, as `setTimeout` might return something else than a number (NodeJs returns a NodeJS.Timeout object).\n // Also if the global `requestAnimationFrame`'s returnType is number, `requester.requestPostAnimationFrame` and `requester.requestAnimationFrame` types\n // are `any`.\n if (!IsWindowObjectExist()) {\n if (typeof requestAnimationFrame === \"function\") {\n return requestAnimationFrame(func);\n }\n }\n else {\n const { requestAnimationFrame } = requester || window;\n if (typeof requestAnimationFrame === \"function\") {\n return requestAnimationFrame(func);\n }\n }\n // fallback to the global `setTimeout`.\n // In most cases (aka in the browser), `window` is the global object, so instead of calling `window.setTimeout` we could call the global `setTimeout`.\n return setTimeout(func, 16);\n }\n /**\n * Gets host document\n * @returns the host document object\n */\n getHostDocument() {\n if (this._renderingCanvas && this._renderingCanvas.ownerDocument) {\n return this._renderingCanvas.ownerDocument;\n }\n return IsDocumentAvailable() ? document : null;\n }\n }\n ThinEngine._TempClearColorUint32 = new Uint32Array(4);\n ThinEngine._TempClearColorInt32 = new Int32Array(4);\n /** Use this array to turn off some WebGL2 features on known buggy browsers version */\n ThinEngine.ExceptionList = [\n { key: \"Chrome/63.0\", capture: \"63\\\\.0\\\\.3239\\\\.(\\\\d+)\", captureConstraint: 108, targets: [\"uniformBuffer\"] },\n { key: \"Firefox/58\", capture: null, captureConstraint: null, targets: [\"uniformBuffer\"] },\n { key: \"Firefox/59\", capture: null, captureConstraint: null, targets: [\"uniformBuffer\"] },\n { key: \"Chrome/72.+?Mobile\", capture: null, captureConstraint: null, targets: [\"vao\"] },\n { key: \"Chrome/73.+?Mobile\", capture: null, captureConstraint: null, targets: [\"vao\"] },\n { key: \"Chrome/74.+?Mobile\", capture: null, captureConstraint: null, targets: [\"vao\"] },\n { key: \"Mac OS.+Chrome/71\", capture: null, captureConstraint: null, targets: [\"vao\"] },\n { key: \"Mac OS.+Chrome/72\", capture: null, captureConstraint: null, targets: [\"vao\"] },\n { key: \"Mac OS.+Chrome\", capture: null, captureConstraint: null, targets: [\"uniformBuffer\"] },\n // desktop osx safari 15.4\n { key: \".*AppleWebKit.*(15.4).*Safari\", capture: null, captureConstraint: null, targets: [\"antialias\", \"maxMSAASamples\"] },\n // mobile browsers using safari 15.4 on ios\n { key: \".*(15.4).*AppleWebKit.*Safari\", capture: null, captureConstraint: null, targets: [\"antialias\", \"maxMSAASamples\"] },\n ];\n /** @internal */\n ThinEngine._TextureLoaders = [];\n // Updatable statics so stick with vars here\n /**\n * Gets or sets the epsilon value used by collision engine\n */\n ThinEngine.CollisionsEpsilon = 0.001;\n // Statics\n ThinEngine._IsSupported = null;\n ThinEngine._HasMajorPerformanceCaveat = null;\n\n /**\n * Class used to provide helper for timing\n */\n class TimingTools {\n /**\n * Polyfill for setImmediate\n * @param action defines the action to execute after the current execution block\n */\n static SetImmediate(action) {\n if (IsWindowObjectExist() && window.setImmediate) {\n window.setImmediate(action);\n }\n else {\n setTimeout(action, 1);\n }\n }\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n const Base64DataUrlRegEx = new RegExp(/^data:([^,]+\\/[^,]+)?;base64,/i);\n /** @ignore */\n class LoadFileError extends RuntimeError {\n /**\n * Creates a new LoadFileError\n * @param message defines the message of the error\n * @param object defines the optional web request\n */\n constructor(message, object) {\n super(message, ErrorCodes.LoadFileError);\n this.name = \"LoadFileError\";\n BaseError._setPrototypeOf(this, LoadFileError.prototype);\n if (object instanceof WebRequest) {\n this.request = object;\n }\n else {\n this.file = object;\n }\n }\n }\n /** @ignore */\n class RequestFileError extends RuntimeError {\n /**\n * Creates a new LoadFileError\n * @param message defines the message of the error\n * @param request defines the optional web request\n */\n constructor(message, request) {\n super(message, ErrorCodes.RequestFileError);\n this.request = request;\n this.name = \"RequestFileError\";\n BaseError._setPrototypeOf(this, RequestFileError.prototype);\n }\n }\n /** @ignore */\n class ReadFileError extends RuntimeError {\n /**\n * Creates a new ReadFileError\n * @param message defines the message of the error\n * @param file defines the optional file\n */\n constructor(message, file) {\n super(message, ErrorCodes.ReadFileError);\n this.file = file;\n this.name = \"ReadFileError\";\n BaseError._setPrototypeOf(this, ReadFileError.prototype);\n }\n }\n /**\n * @internal\n */\n const FileToolsOptions = {\n /**\n * Gets or sets the retry strategy to apply when an error happens while loading an asset.\n * When defining this function, return the wait time before trying again or return -1 to\n * stop retrying and error out.\n */\n DefaultRetryStrategy: RetryStrategy.ExponentialBackoff(),\n /**\n * Gets or sets the base URL to use to load assets\n */\n BaseUrl: \"\",\n /**\n * Default behaviour for cors in the application.\n * It can be a string if the expected behavior is identical in the entire app.\n * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)\n */\n CorsBehavior: \"anonymous\",\n /**\n * Gets or sets a function used to pre-process url before using them to load assets\n * @param url\n */\n PreprocessUrl: (url) => {\n return url;\n },\n };\n /**\n * Removes unwanted characters from an url\n * @param url defines the url to clean\n * @returns the cleaned url\n */\n const _CleanUrl = (url) => {\n url = url.replace(/#/gm, \"%23\");\n return url;\n };\n /**\n * Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.\n * @param url define the url we are trying\n * @param element define the dom element where to configure the cors policy\n * @internal\n */\n const SetCorsBehavior = (url, element) => {\n if (url && url.indexOf(\"data:\") === 0) {\n return;\n }\n if (FileToolsOptions.CorsBehavior) {\n if (typeof FileToolsOptions.CorsBehavior === \"string\" || FileToolsOptions.CorsBehavior instanceof String) {\n element.crossOrigin = FileToolsOptions.CorsBehavior;\n }\n else {\n const result = FileToolsOptions.CorsBehavior(url);\n if (result) {\n element.crossOrigin = result;\n }\n }\n }\n };\n /**\n * Loads an image as an HTMLImageElement.\n * @param input url string, ArrayBuffer, or Blob to load\n * @param onLoad callback called when the image successfully loads\n * @param onError callback called when the image fails to load\n * @param offlineProvider offline provider for caching\n * @param mimeType optional mime type\n * @param imageBitmapOptions\n * @returns the HTMLImageElement of the loaded image\n * @internal\n */\n const LoadImage = (input, onLoad, onError, offlineProvider, mimeType = \"\", imageBitmapOptions) => {\n var _a;\n let url;\n let usingObjectURL = false;\n if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {\n if (typeof Blob !== \"undefined\" && typeof URL !== \"undefined\") {\n url = URL.createObjectURL(new Blob([input], { type: mimeType }));\n usingObjectURL = true;\n }\n else {\n url = `data:${mimeType};base64,` + EncodeArrayBufferToBase64(input);\n }\n }\n else if (input instanceof Blob) {\n url = URL.createObjectURL(input);\n usingObjectURL = true;\n }\n else {\n url = _CleanUrl(input);\n url = FileToolsOptions.PreprocessUrl(input);\n }\n const engine = EngineStore.LastCreatedEngine;\n const onErrorHandler = (exception) => {\n if (onError) {\n const inputText = url || input.toString();\n onError(`Error while trying to load image: ${inputText.indexOf(\"http\") === 0 || inputText.length <= 128 ? inputText : inputText.slice(0, 128) + \"...\"}`, exception);\n }\n };\n if (typeof Image === \"undefined\" || ((_a = engine === null || engine === void 0 ? void 0 : engine._features.forceBitmapOverHTMLImageElement) !== null && _a !== void 0 ? _a : false)) {\n LoadFile(url, (data) => {\n engine\n .createImageBitmap(new Blob([data], { type: mimeType }), Object.assign({ premultiplyAlpha: \"none\" }, imageBitmapOptions))\n .then((imgBmp) => {\n onLoad(imgBmp);\n if (usingObjectURL) {\n URL.revokeObjectURL(url);\n }\n })\n .catch((reason) => {\n if (onError) {\n onError(\"Error while trying to load image: \" + input, reason);\n }\n });\n }, undefined, offlineProvider || undefined, true, (request, exception) => {\n onErrorHandler(exception);\n });\n return null;\n }\n const img = new Image();\n SetCorsBehavior(url, img);\n const handlersList = [];\n const loadHandlersList = () => {\n handlersList.forEach((handler) => {\n handler.target.addEventListener(handler.name, handler.handler);\n });\n };\n const unloadHandlersList = () => {\n handlersList.forEach((handler) => {\n handler.target.removeEventListener(handler.name, handler.handler);\n });\n handlersList.length = 0;\n };\n const loadHandler = () => {\n unloadHandlersList();\n onLoad(img);\n // Must revoke the URL after calling onLoad to avoid security exceptions in\n // certain scenarios (e.g. when hosted in vscode).\n if (usingObjectURL && img.src) {\n URL.revokeObjectURL(img.src);\n }\n };\n const errorHandler = (err) => {\n unloadHandlersList();\n onErrorHandler(err);\n if (usingObjectURL && img.src) {\n URL.revokeObjectURL(img.src);\n }\n };\n const cspHandler = (err) => {\n if (err.blockedURI !== img.src) {\n return;\n }\n unloadHandlersList();\n const cspException = new Error(`CSP violation of policy ${err.effectiveDirective} ${err.blockedURI}. Current policy is ${err.originalPolicy}`);\n EngineStore.UseFallbackTexture = false;\n onErrorHandler(cspException);\n if (usingObjectURL && img.src) {\n URL.revokeObjectURL(img.src);\n }\n img.src = \"\";\n };\n handlersList.push({ target: img, name: \"load\", handler: loadHandler });\n handlersList.push({ target: img, name: \"error\", handler: errorHandler });\n handlersList.push({ target: document, name: \"securitypolicyviolation\", handler: cspHandler });\n loadHandlersList();\n const fromBlob = url.substring(0, 5) === \"blob:\";\n const fromData = url.substring(0, 5) === \"data:\";\n const noOfflineSupport = () => {\n if (fromBlob || fromData) {\n img.src = url;\n }\n else {\n LoadFile(url, (data, _, contentType) => {\n const type = !mimeType && contentType ? contentType : mimeType;\n const blob = new Blob([data], { type });\n const url = URL.createObjectURL(blob);\n usingObjectURL = true;\n img.src = url;\n }, undefined, offlineProvider || undefined, true, (request, exception) => {\n onErrorHandler(exception);\n });\n }\n };\n const loadFromOfflineSupport = () => {\n if (offlineProvider) {\n offlineProvider.loadImage(url, img);\n }\n };\n if (!fromBlob && !fromData && offlineProvider && offlineProvider.enableTexturesOffline) {\n offlineProvider.open(loadFromOfflineSupport, noOfflineSupport);\n }\n else {\n if (url.indexOf(\"file:\") !== -1) {\n const textureName = decodeURIComponent(url.substring(5).toLowerCase());\n if (FilesInputStore.FilesToLoad[textureName] && typeof URL !== \"undefined\") {\n try {\n let blobURL;\n try {\n blobURL = URL.createObjectURL(FilesInputStore.FilesToLoad[textureName]);\n }\n catch (ex) {\n // Chrome doesn't support oneTimeOnly parameter\n blobURL = URL.createObjectURL(FilesInputStore.FilesToLoad[textureName]);\n }\n img.src = blobURL;\n usingObjectURL = true;\n }\n catch (e) {\n img.src = \"\";\n }\n return img;\n }\n }\n noOfflineSupport();\n }\n return img;\n };\n /**\n * Reads a file from a File object\n * @param file defines the file to load\n * @param onSuccess defines the callback to call when data is loaded\n * @param onProgress defines the callback to call during loading process\n * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer\n * @param onError defines the callback to call when an error occurs\n * @returns a file request object\n * @internal\n */\n const ReadFile = (file, onSuccess, onProgress, useArrayBuffer, onError) => {\n const reader = new FileReader();\n const fileRequest = {\n onCompleteObservable: new Observable$1(),\n abort: () => reader.abort(),\n };\n reader.onloadend = () => fileRequest.onCompleteObservable.notifyObservers(fileRequest);\n if (onError) {\n reader.onerror = () => {\n onError(new ReadFileError(`Unable to read ${file.name}`, file));\n };\n }\n reader.onload = (e) => {\n //target doesn't have result from ts 1.3\n onSuccess(e.target[\"result\"]);\n };\n if (onProgress) {\n reader.onprogress = onProgress;\n }\n if (!useArrayBuffer) {\n // Asynchronous read\n reader.readAsText(file);\n }\n else {\n reader.readAsArrayBuffer(file);\n }\n return fileRequest;\n };\n /**\n * Loads a file from a url, a data url, or a file url\n * @param fileOrUrl file, url, data url, or file url to load\n * @param onSuccess callback called when the file successfully loads\n * @param onProgress callback called while file is loading (if the server supports this mode)\n * @param offlineProvider defines the offline provider for caching\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\n * @param onError callback called when the file fails to load\n * @param onOpened\n * @returns a file request object\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const LoadFile = (fileOrUrl, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError, onOpened) => {\n if (fileOrUrl.name) {\n return ReadFile(fileOrUrl, onSuccess, onProgress, useArrayBuffer, onError\n ? (error) => {\n onError(undefined, error);\n }\n : undefined);\n }\n const url = fileOrUrl;\n // If file and file input are set\n if (url.indexOf(\"file:\") !== -1) {\n let fileName = decodeURIComponent(url.substring(5).toLowerCase());\n if (fileName.indexOf(\"./\") === 0) {\n fileName = fileName.substring(2);\n }\n const file = FilesInputStore.FilesToLoad[fileName];\n if (file) {\n return ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError ? (error) => onError(undefined, new LoadFileError(error.message, error.file)) : undefined);\n }\n }\n // For a Base64 Data URL\n const { match, type } = TestBase64DataUrl(url);\n if (match) {\n const fileRequest = {\n onCompleteObservable: new Observable$1(),\n abort: () => () => { },\n };\n try {\n const data = useArrayBuffer ? DecodeBase64UrlToBinary(url) : DecodeBase64UrlToString(url);\n onSuccess(data, undefined, type);\n }\n catch (error) {\n if (onError) {\n onError(undefined, error);\n }\n else {\n Logger.Error(error.message || \"Failed to parse the Data URL\");\n }\n }\n TimingTools.SetImmediate(() => {\n fileRequest.onCompleteObservable.notifyObservers(fileRequest);\n });\n return fileRequest;\n }\n return RequestFile(url, (data, request) => {\n onSuccess(data, request === null || request === void 0 ? void 0 : request.responseURL, request === null || request === void 0 ? void 0 : request.getResponseHeader(\"content-type\"));\n }, onProgress, offlineProvider, useArrayBuffer, onError\n ? (error) => {\n onError(error.request, new LoadFileError(error.message, error.request));\n }\n : undefined, onOpened);\n };\n /**\n * Loads a file from a url\n * @param url url to load\n * @param onSuccess callback called when the file successfully loads\n * @param onProgress callback called while file is loading (if the server supports this mode)\n * @param offlineProvider defines the offline provider for caching\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\n * @param onError callback called when the file fails to load\n * @param onOpened callback called when the web request is opened\n * @returns a file request object\n * @internal\n */\n const RequestFile = (url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError, onOpened) => {\n url = _CleanUrl(url);\n url = FileToolsOptions.PreprocessUrl(url);\n const loadUrl = FileToolsOptions.BaseUrl + url;\n let aborted = false;\n const fileRequest = {\n onCompleteObservable: new Observable$1(),\n abort: () => (aborted = true),\n };\n const requestFile = () => {\n let request = new WebRequest();\n let retryHandle = null;\n let onReadyStateChange;\n const unbindEvents = () => {\n if (!request) {\n return;\n }\n if (onProgress) {\n request.removeEventListener(\"progress\", onProgress);\n }\n if (onReadyStateChange) {\n request.removeEventListener(\"readystatechange\", onReadyStateChange);\n }\n request.removeEventListener(\"loadend\", onLoadEnd);\n };\n let onLoadEnd = () => {\n unbindEvents();\n fileRequest.onCompleteObservable.notifyObservers(fileRequest);\n fileRequest.onCompleteObservable.clear();\n onProgress = undefined;\n onReadyStateChange = null;\n onLoadEnd = null;\n onError = undefined;\n onOpened = undefined;\n onSuccess = undefined;\n };\n fileRequest.abort = () => {\n aborted = true;\n if (onLoadEnd) {\n onLoadEnd();\n }\n if (request && request.readyState !== (XMLHttpRequest.DONE || 4)) {\n request.abort();\n }\n if (retryHandle !== null) {\n clearTimeout(retryHandle);\n retryHandle = null;\n }\n request = null;\n };\n const handleError = (error) => {\n const message = error.message || \"Unknown error\";\n if (onError && request) {\n onError(new RequestFileError(message, request));\n }\n else {\n Logger.Error(message);\n }\n };\n const retryLoop = (retryIndex) => {\n if (!request) {\n return;\n }\n request.open(\"GET\", loadUrl);\n if (onOpened) {\n try {\n onOpened(request);\n }\n catch (e) {\n handleError(e);\n return;\n }\n }\n if (useArrayBuffer) {\n request.responseType = \"arraybuffer\";\n }\n if (onProgress) {\n request.addEventListener(\"progress\", onProgress);\n }\n if (onLoadEnd) {\n request.addEventListener(\"loadend\", onLoadEnd);\n }\n onReadyStateChange = () => {\n if (aborted || !request) {\n return;\n }\n // In case of undefined state in some browsers.\n if (request.readyState === (XMLHttpRequest.DONE || 4)) {\n // Some browsers have issues where onreadystatechange can be called multiple times with the same value.\n if (onReadyStateChange) {\n request.removeEventListener(\"readystatechange\", onReadyStateChange);\n }\n if ((request.status >= 200 && request.status < 300) || (request.status === 0 && (!IsWindowObjectExist() || IsFileURL()))) {\n try {\n if (onSuccess) {\n onSuccess(useArrayBuffer ? request.response : request.responseText, request);\n }\n }\n catch (e) {\n handleError(e);\n }\n return;\n }\n const retryStrategy = FileToolsOptions.DefaultRetryStrategy;\n if (retryStrategy) {\n const waitTime = retryStrategy(loadUrl, request, retryIndex);\n if (waitTime !== -1) {\n // Prevent the request from completing for retry.\n unbindEvents();\n request = new WebRequest();\n retryHandle = setTimeout(() => retryLoop(retryIndex + 1), waitTime);\n return;\n }\n }\n const error = new RequestFileError(\"Error status: \" + request.status + \" \" + request.statusText + \" - Unable to load \" + loadUrl, request);\n if (onError) {\n onError(error);\n }\n }\n };\n request.addEventListener(\"readystatechange\", onReadyStateChange);\n request.send();\n };\n retryLoop(0);\n };\n // Caching all files\n if (offlineProvider && offlineProvider.enableSceneOffline) {\n const noOfflineSupport = (request) => {\n if (request && request.status > 400) {\n if (onError) {\n onError(request);\n }\n }\n else {\n requestFile();\n }\n };\n const loadFromOfflineSupport = () => {\n // TODO: database needs to support aborting and should return a IFileRequest\n if (offlineProvider) {\n offlineProvider.loadFile(FileToolsOptions.BaseUrl + url, (data) => {\n if (!aborted && onSuccess) {\n onSuccess(data);\n }\n fileRequest.onCompleteObservable.notifyObservers(fileRequest);\n }, onProgress\n ? (event) => {\n if (!aborted && onProgress) {\n onProgress(event);\n }\n }\n : undefined, noOfflineSupport, useArrayBuffer);\n }\n };\n offlineProvider.open(loadFromOfflineSupport, noOfflineSupport);\n }\n else {\n requestFile();\n }\n return fileRequest;\n };\n /**\n * Checks if the loaded document was accessed via `file:`-Protocol.\n * @returns boolean\n * @internal\n */\n const IsFileURL = () => {\n return typeof location !== \"undefined\" && location.protocol === \"file:\";\n };\n /**\n * Test if the given uri is a valid base64 data url\n * @param uri The uri to test\n * @returns True if the uri is a base64 data url or false otherwise\n * @internal\n */\n const IsBase64DataUrl = (uri) => {\n return Base64DataUrlRegEx.test(uri);\n };\n const TestBase64DataUrl = (uri) => {\n const results = Base64DataUrlRegEx.exec(uri);\n if (results === null || results.length === 0) {\n return { match: false, type: \"\" };\n }\n else {\n const type = results[0].replace(\"data:\", \"\").replace(\"base64,\", \"\");\n return { match: true, type };\n }\n };\n /**\n * Decode the given base64 uri.\n * @param uri The uri to decode\n * @returns The decoded base64 data.\n * @internal\n */\n function DecodeBase64UrlToBinary(uri) {\n return DecodeBase64ToBinary(uri.split(\",\")[1]);\n }\n /**\n * Decode the given base64 uri into a UTF-8 encoded string.\n * @param uri The uri to decode\n * @returns The decoded base64 data.\n * @internal\n */\n const DecodeBase64UrlToString = (uri) => {\n return DecodeBase64ToString(uri.split(\",\")[1]);\n };\n /**\n * This will be executed automatically for UMD and es5.\n * If esm dev wants the side effects to execute they will have to run it manually\n * Once we build native modules those need to be exported.\n * @internal\n */\n const initSideEffects = () => {\n ThinEngine._FileToolsLoadImage = LoadImage;\n ThinEngine._FileToolsLoadFile = LoadFile;\n ShaderProcessor._FileToolsLoadFile = LoadFile;\n };\n initSideEffects();\n // deprecated\n /**\n * FileTools defined as any.\n * This should not be imported or used in future releases or in any module in the framework\n * @internal\n * @deprecated import the needed function from fileTools.ts\n */\n let FileTools;\n /**\n * @param DecodeBase64UrlToBinary\n * @param DecodeBase64UrlToString\n * @param FileToolsOptions\n * @internal\n */\n const _injectLTSFileTools = (DecodeBase64UrlToBinary, DecodeBase64UrlToString, FileToolsOptions, IsBase64DataUrl, IsFileURL, LoadFile, LoadImage, ReadFile, RequestFile, SetCorsBehavior) => {\n /**\n * Backwards compatibility.\n * @internal\n * @deprecated\n */\n FileTools = {\n DecodeBase64UrlToBinary,\n DecodeBase64UrlToString,\n DefaultRetryStrategy: FileToolsOptions.DefaultRetryStrategy,\n BaseUrl: FileToolsOptions.BaseUrl,\n CorsBehavior: FileToolsOptions.CorsBehavior,\n PreprocessUrl: FileToolsOptions.PreprocessUrl,\n IsBase64DataUrl,\n IsFileURL,\n LoadFile,\n LoadImage,\n ReadFile,\n RequestFile,\n SetCorsBehavior,\n };\n Object.defineProperty(FileTools, \"DefaultRetryStrategy\", {\n get: function () {\n return FileToolsOptions.DefaultRetryStrategy;\n },\n set: function (value) {\n FileToolsOptions.DefaultRetryStrategy = value;\n },\n });\n Object.defineProperty(FileTools, \"BaseUrl\", {\n get: function () {\n return FileToolsOptions.BaseUrl;\n },\n set: function (value) {\n FileToolsOptions.BaseUrl = value;\n },\n });\n Object.defineProperty(FileTools, \"PreprocessUrl\", {\n get: function () {\n return FileToolsOptions.PreprocessUrl;\n },\n set: function (value) {\n FileToolsOptions.PreprocessUrl = value;\n },\n });\n Object.defineProperty(FileTools, \"CorsBehavior\", {\n get: function () {\n return FileToolsOptions.CorsBehavior;\n },\n set: function (value) {\n FileToolsOptions.CorsBehavior = value;\n },\n });\n };\n _injectLTSFileTools(DecodeBase64UrlToBinary, DecodeBase64UrlToString, FileToolsOptions, IsBase64DataUrl, IsFileURL, LoadFile, LoadImage, ReadFile, RequestFile, SetCorsBehavior);\n\n /**\n * Class used to enable instantiation of objects by class name\n */\n class InstantiationTools {\n /**\n * Tries to instantiate a new object from a given class name\n * @param className defines the class name to instantiate\n * @returns the new object or null if the system was not able to do the instantiation\n */\n static Instantiate(className) {\n if (this.RegisteredExternalClasses && this.RegisteredExternalClasses[className]) {\n return this.RegisteredExternalClasses[className];\n }\n const internalClass = GetClass(className);\n if (internalClass) {\n return internalClass;\n }\n Logger.Warn(className + \" not found, you may have missed an import.\");\n const arr = className.split(\".\");\n let fn = window || this;\n for (let i = 0, len = arr.length; i < len; i++) {\n fn = fn[arr[i]];\n }\n if (typeof fn !== \"function\") {\n return null;\n }\n return fn;\n }\n }\n /**\n * Use this object to register external classes like custom textures or material\n * to allow the loaders to instantiate them\n */\n InstantiationTools.RegisteredExternalClasses = {};\n\n /**\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\n * Be aware Math.random() could cause collisions, but:\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\n * @returns a pseudo random id\n */\n function RandomGUID() {\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0, v = c === \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n }\n\n /**\n * Class containing a set of static utilities functions\n */\n class Tools {\n /**\n * Gets or sets the base URL to use to load assets\n */\n static get BaseUrl() {\n return FileToolsOptions.BaseUrl;\n }\n static set BaseUrl(value) {\n FileToolsOptions.BaseUrl = value;\n }\n /**\n * Gets or sets the retry strategy to apply when an error happens while loading an asset\n */\n static get DefaultRetryStrategy() {\n return FileToolsOptions.DefaultRetryStrategy;\n }\n static set DefaultRetryStrategy(strategy) {\n FileToolsOptions.DefaultRetryStrategy = strategy;\n }\n /**\n * Default behaviour for cors in the application.\n * It can be a string if the expected behavior is identical in the entire app.\n * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)\n */\n static get CorsBehavior() {\n return FileToolsOptions.CorsBehavior;\n }\n static set CorsBehavior(value) {\n FileToolsOptions.CorsBehavior = value;\n }\n /**\n * Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded\n * @ignorenaming\n */\n static get UseFallbackTexture() {\n return EngineStore.UseFallbackTexture;\n }\n static set UseFallbackTexture(value) {\n EngineStore.UseFallbackTexture = value;\n }\n /**\n * Use this object to register external classes like custom textures or material\n * to allow the loaders to instantiate them\n */\n static get RegisteredExternalClasses() {\n return InstantiationTools.RegisteredExternalClasses;\n }\n static set RegisteredExternalClasses(classes) {\n InstantiationTools.RegisteredExternalClasses = classes;\n }\n /**\n * Texture content used if a texture cannot loaded\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static get fallbackTexture() {\n return EngineStore.FallbackTexture;\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static set fallbackTexture(value) {\n EngineStore.FallbackTexture = value;\n }\n /**\n * Read the content of a byte array at a specified coordinates (taking in account wrapping)\n * @param u defines the coordinate on X axis\n * @param v defines the coordinate on Y axis\n * @param width defines the width of the source data\n * @param height defines the height of the source data\n * @param pixels defines the source byte array\n * @param color defines the output color\n */\n static FetchToRef(u, v, width, height, pixels, color) {\n const wrappedU = (Math.abs(u) * width) % width | 0;\n const wrappedV = (Math.abs(v) * height) % height | 0;\n const position = (wrappedU + wrappedV * width) * 4;\n color.r = pixels[position] / 255;\n color.g = pixels[position + 1] / 255;\n color.b = pixels[position + 2] / 255;\n color.a = pixels[position + 3] / 255;\n }\n /**\n * Interpolates between a and b via alpha\n * @param a The lower value (returned when alpha = 0)\n * @param b The upper value (returned when alpha = 1)\n * @param alpha The interpolation-factor\n * @returns The mixed value\n */\n static Mix(a, b, alpha) {\n return a * (1 - alpha) + b * alpha;\n }\n /**\n * Tries to instantiate a new object from a given class name\n * @param className defines the class name to instantiate\n * @returns the new object or null if the system was not able to do the instantiation\n */\n static Instantiate(className) {\n return InstantiationTools.Instantiate(className);\n }\n /**\n * Polyfill for setImmediate\n * @param action defines the action to execute after the current execution block\n */\n static SetImmediate(action) {\n TimingTools.SetImmediate(action);\n }\n /**\n * Function indicating if a number is an exponent of 2\n * @param value defines the value to test\n * @returns true if the value is an exponent of 2\n */\n static IsExponentOfTwo(value) {\n let count = 1;\n do {\n count *= 2;\n } while (count < value);\n return count === value;\n }\n /**\n * Returns the nearest 32-bit single precision float representation of a Number\n * @param value A Number. If the parameter is of a different type, it will get converted\n * to a number or to NaN if it cannot be converted\n * @returns number\n */\n static FloatRound(value) {\n if (Math.fround) {\n return Math.fround(value);\n }\n return (Tools._TmpFloatArray[0] = value), Tools._TmpFloatArray[0];\n }\n /**\n * Extracts the filename from a path\n * @param path defines the path to use\n * @returns the filename\n */\n static GetFilename(path) {\n const index = path.lastIndexOf(\"/\");\n if (index < 0) {\n return path;\n }\n return path.substring(index + 1);\n }\n /**\n * Extracts the \"folder\" part of a path (everything before the filename).\n * @param uri The URI to extract the info from\n * @param returnUnchangedIfNoSlash Do not touch the URI if no slashes are present\n * @returns The \"folder\" part of the path\n */\n static GetFolderPath(uri, returnUnchangedIfNoSlash = false) {\n const index = uri.lastIndexOf(\"/\");\n if (index < 0) {\n if (returnUnchangedIfNoSlash) {\n return uri;\n }\n return \"\";\n }\n return uri.substring(0, index + 1);\n }\n /**\n * Convert an angle in radians to degrees\n * @param angle defines the angle to convert\n * @returns the angle in degrees\n */\n static ToDegrees(angle) {\n return (angle * 180) / Math.PI;\n }\n /**\n * Convert an angle in degrees to radians\n * @param angle defines the angle to convert\n * @returns the angle in radians\n */\n static ToRadians(angle) {\n return (angle * Math.PI) / 180;\n }\n /**\n * Smooth angle changes (kind of low-pass filter), in particular for device orientation \"shaking\"\n * Use trigonometric functions to avoid discontinuity (0/360, -180/180)\n * @param previousAngle defines last angle value, in degrees\n * @param newAngle defines new angle value, in degrees\n * @param smoothFactor defines smoothing sensitivity; min 0: no smoothing, max 1: new data ignored\n * @returns the angle in degrees\n */\n static SmoothAngleChange(previousAngle, newAngle, smoothFactor = 0.9) {\n const previousAngleRad = this.ToRadians(previousAngle);\n const newAngleRad = this.ToRadians(newAngle);\n return this.ToDegrees(Math.atan2((1 - smoothFactor) * Math.sin(newAngleRad) + smoothFactor * Math.sin(previousAngleRad), (1 - smoothFactor) * Math.cos(newAngleRad) + smoothFactor * Math.cos(previousAngleRad)));\n }\n /**\n * Returns an array if obj is not an array\n * @param obj defines the object to evaluate as an array\n * @param allowsNullUndefined defines a boolean indicating if obj is allowed to be null or undefined\n * @returns either obj directly if obj is an array or a new array containing obj\n */\n static MakeArray(obj, allowsNullUndefined) {\n if (allowsNullUndefined !== true && (obj === undefined || obj == null)) {\n return null;\n }\n return Array.isArray(obj) ? obj : [obj];\n }\n /**\n * Gets the pointer prefix to use\n * @param engine defines the engine we are finding the prefix for\n * @returns \"pointer\" if touch is enabled. Else returns \"mouse\"\n */\n static GetPointerPrefix(engine) {\n let eventPrefix = \"pointer\";\n // Check if pointer events are supported\n if (IsWindowObjectExist() && !window.PointerEvent) {\n eventPrefix = \"mouse\";\n }\n // Special Fallback MacOS Safari...\n if (engine._badDesktopOS &&\n !engine._badOS &&\n // And not ipad pros who claim to be macs...\n !(document && \"ontouchend\" in document)) {\n eventPrefix = \"mouse\";\n }\n return eventPrefix;\n }\n /**\n * Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.\n * @param url define the url we are trying\n * @param element define the dom element where to configure the cors policy\n * @param element.crossOrigin\n */\n static SetCorsBehavior(url, element) {\n SetCorsBehavior(url, element);\n }\n /**\n * Sets the referrerPolicy behavior on a dom element.\n * @param referrerPolicy define the referrer policy to use\n * @param element define the dom element where to configure the referrer policy\n * @param element.referrerPolicy\n */\n static SetReferrerPolicyBehavior(referrerPolicy, element) {\n element.referrerPolicy = referrerPolicy;\n }\n // External files\n /**\n * Removes unwanted characters from an url\n * @param url defines the url to clean\n * @returns the cleaned url\n */\n static CleanUrl(url) {\n url = url.replace(/#/gm, \"%23\");\n return url;\n }\n /**\n * Gets or sets a function used to pre-process url before using them to load assets\n */\n static get PreprocessUrl() {\n return FileToolsOptions.PreprocessUrl;\n }\n static set PreprocessUrl(processor) {\n FileToolsOptions.PreprocessUrl = processor;\n }\n /**\n * Loads an image as an HTMLImageElement.\n * @param input url string, ArrayBuffer, or Blob to load\n * @param onLoad callback called when the image successfully loads\n * @param onError callback called when the image fails to load\n * @param offlineProvider offline provider for caching\n * @param mimeType optional mime type\n * @param imageBitmapOptions optional the options to use when creating an ImageBitmap\n * @returns the HTMLImageElement of the loaded image\n */\n static LoadImage(input, onLoad, onError, offlineProvider, mimeType, imageBitmapOptions) {\n return LoadImage(input, onLoad, onError, offlineProvider, mimeType, imageBitmapOptions);\n }\n /**\n * Loads a file from a url\n * @param url url string, ArrayBuffer, or Blob to load\n * @param onSuccess callback called when the file successfully loads\n * @param onProgress callback called while file is loading (if the server supports this mode)\n * @param offlineProvider defines the offline provider for caching\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\n * @param onError callback called when the file fails to load\n * @returns a file request object\n */\n static LoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError) {\n return LoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError);\n }\n /**\n * Loads a file from a url\n * @param url the file url to load\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\n * @returns a promise containing an ArrayBuffer corresponding to the loaded file\n */\n static LoadFileAsync(url, useArrayBuffer = true) {\n return new Promise((resolve, reject) => {\n LoadFile(url, (data) => {\n resolve(data);\n }, undefined, undefined, useArrayBuffer, (request, exception) => {\n reject(exception);\n });\n });\n }\n /**\n * Load a script (identified by an url). When the url returns, the\n * content of this file is added into a new script element, attached to the DOM (body element)\n * @param scriptUrl defines the url of the script to laod\n * @param onSuccess defines the callback called when the script is loaded\n * @param onError defines the callback to call if an error occurs\n * @param scriptId defines the id of the script element\n */\n static LoadScript(scriptUrl, onSuccess, onError, scriptId) {\n if (typeof importScripts === \"function\") {\n try {\n importScripts(scriptUrl);\n onSuccess();\n }\n catch (e) {\n onError === null || onError === void 0 ? void 0 : onError(`Unable to load script '${scriptUrl}' in worker`, e);\n }\n return;\n }\n else if (!IsWindowObjectExist()) {\n onError === null || onError === void 0 ? void 0 : onError(`Cannot load script '${scriptUrl}' outside of a window or a worker`);\n return;\n }\n const head = document.getElementsByTagName(\"head\")[0];\n const script = document.createElement(\"script\");\n script.setAttribute(\"type\", \"text/javascript\");\n script.setAttribute(\"src\", scriptUrl);\n if (scriptId) {\n script.id = scriptId;\n }\n script.onload = () => {\n if (onSuccess) {\n onSuccess();\n }\n };\n script.onerror = (e) => {\n if (onError) {\n onError(`Unable to load script '${scriptUrl}'`, e);\n }\n };\n head.appendChild(script);\n }\n /**\n * Load an asynchronous script (identified by an url). When the url returns, the\n * content of this file is added into a new script element, attached to the DOM (body element)\n * @param scriptUrl defines the url of the script to laod\n * @returns a promise request object\n */\n static LoadScriptAsync(scriptUrl) {\n return new Promise((resolve, reject) => {\n this.LoadScript(scriptUrl, () => {\n resolve();\n }, (message, exception) => {\n reject(exception || new Error(message));\n });\n });\n }\n /**\n * Loads a file from a blob\n * @param fileToLoad defines the blob to use\n * @param callback defines the callback to call when data is loaded\n * @param progressCallback defines the callback to call during loading process\n * @returns a file request object\n */\n static ReadFileAsDataURL(fileToLoad, callback, progressCallback) {\n const reader = new FileReader();\n const request = {\n onCompleteObservable: new Observable$1(),\n abort: () => reader.abort(),\n };\n reader.onloadend = () => {\n request.onCompleteObservable.notifyObservers(request);\n };\n reader.onload = (e) => {\n //target doesn't have result from ts 1.3\n callback(e.target[\"result\"]);\n };\n reader.onprogress = progressCallback;\n reader.readAsDataURL(fileToLoad);\n return request;\n }\n /**\n * Reads a file from a File object\n * @param file defines the file to load\n * @param onSuccess defines the callback to call when data is loaded\n * @param onProgress defines the callback to call during loading process\n * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer\n * @param onError defines the callback to call when an error occurs\n * @returns a file request object\n */\n static ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError) {\n return ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError);\n }\n /**\n * Creates a data url from a given string content\n * @param content defines the content to convert\n * @returns the new data url link\n */\n static FileAsURL(content) {\n const fileBlob = new Blob([content]);\n const url = window.URL;\n const link = url.createObjectURL(fileBlob);\n return link;\n }\n /**\n * Format the given number to a specific decimal format\n * @param value defines the number to format\n * @param decimals defines the number of decimals to use\n * @returns the formatted string\n */\n static Format(value, decimals = 2) {\n return value.toFixed(decimals);\n }\n /**\n * Tries to copy an object by duplicating every property\n * @param source defines the source object\n * @param destination defines the target object\n * @param doNotCopyList defines a list of properties to avoid\n * @param mustCopyList defines a list of properties to copy (even if they start with _)\n */\n static DeepCopy(source, destination, doNotCopyList, mustCopyList) {\n DeepCopier.DeepCopy(source, destination, doNotCopyList, mustCopyList);\n }\n /**\n * Gets a boolean indicating if the given object has no own property\n * @param obj defines the object to test\n * @returns true if object has no own property\n */\n static IsEmpty(obj) {\n for (const i in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, i)) {\n return false;\n }\n }\n return true;\n }\n /**\n * Function used to register events at window level\n * @param windowElement defines the Window object to use\n * @param events defines the events to register\n */\n static RegisterTopRootEvents(windowElement, events) {\n for (let index = 0; index < events.length; index++) {\n const event = events[index];\n windowElement.addEventListener(event.name, event.handler, false);\n try {\n if (window.parent) {\n window.parent.addEventListener(event.name, event.handler, false);\n }\n }\n catch (e) {\n // Silently fails...\n }\n }\n }\n /**\n * Function used to unregister events from window level\n * @param windowElement defines the Window object to use\n * @param events defines the events to unregister\n */\n static UnregisterTopRootEvents(windowElement, events) {\n for (let index = 0; index < events.length; index++) {\n const event = events[index];\n windowElement.removeEventListener(event.name, event.handler);\n try {\n if (windowElement.parent) {\n windowElement.parent.removeEventListener(event.name, event.handler);\n }\n }\n catch (e) {\n // Silently fails...\n }\n }\n }\n /**\n * Dumps the current bound framebuffer\n * @param width defines the rendering width\n * @param height defines the rendering height\n * @param engine defines the hosting engine\n * @param successCallback defines the callback triggered once the data are available\n * @param mimeType defines the mime type of the result\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n * @returns a void promise\n */\n static async DumpFramebuffer(width, height, engine, successCallback, mimeType = \"image/png\", fileName, quality) {\n throw _WarnImport(\"DumpTools\");\n }\n /**\n * Dumps an array buffer\n * @param width defines the rendering width\n * @param height defines the rendering height\n * @param data the data array\n * @param successCallback defines the callback triggered once the data are available\n * @param mimeType defines the mime type of the result\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\n * @param invertY true to invert the picture in the Y dimension\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n */\n static DumpData(width, height, data, successCallback, mimeType = \"image/png\", fileName, invertY = false, toArrayBuffer = false, quality) {\n throw _WarnImport(\"DumpTools\");\n }\n /**\n * Dumps an array buffer\n * @param width defines the rendering width\n * @param height defines the rendering height\n * @param data the data array\n * @param mimeType defines the mime type of the result\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\n * @param invertY true to invert the picture in the Y dimension\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n * @returns a promise that resolve to the final data\n */\n static DumpDataAsync(width, height, data, mimeType = \"image/png\", fileName, invertY = false, toArrayBuffer = false, quality) {\n throw _WarnImport(\"DumpTools\");\n }\n static _IsOffScreenCanvas(canvas) {\n return canvas.convertToBlob !== undefined;\n }\n /**\n * Converts the canvas data to blob.\n * This acts as a polyfill for browsers not supporting the to blob function.\n * @param canvas Defines the canvas to extract the data from (can be an offscreen canvas)\n * @param successCallback Defines the callback triggered once the data are available\n * @param mimeType Defines the mime type of the result\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n */\n static ToBlob(canvas, successCallback, mimeType = \"image/png\", quality) {\n // We need HTMLCanvasElement.toBlob for HD screenshots\n if (!Tools._IsOffScreenCanvas(canvas) && !canvas.toBlob) {\n // low performance polyfill based on toDataURL (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob)\n canvas.toBlob = function (callback, type, quality) {\n setTimeout(() => {\n const binStr = atob(this.toDataURL(type, quality).split(\",\")[1]), len = binStr.length, arr = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n arr[i] = binStr.charCodeAt(i);\n }\n callback(new Blob([arr]));\n });\n };\n }\n if (Tools._IsOffScreenCanvas(canvas)) {\n canvas\n .convertToBlob({\n type: mimeType,\n quality,\n })\n .then((blob) => successCallback(blob));\n }\n else {\n canvas.toBlob(function (blob) {\n successCallback(blob);\n }, mimeType, quality);\n }\n }\n /**\n * Download a Blob object\n * @param blob the Blob object\n * @param fileName the file name to download\n * @returns\n */\n static DownloadBlob(blob, fileName) {\n //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.\n if (\"download\" in document.createElement(\"a\")) {\n if (!fileName) {\n const date = new Date();\n const stringDate = (date.getFullYear() + \"-\" + (date.getMonth() + 1)).slice(2) + \"-\" + date.getDate() + \"_\" + date.getHours() + \"-\" + (\"0\" + date.getMinutes()).slice(-2);\n fileName = \"screenshot_\" + stringDate + \".png\";\n }\n Tools.Download(blob, fileName);\n }\n else {\n if (blob && typeof URL !== \"undefined\") {\n const url = URL.createObjectURL(blob);\n const newWindow = window.open(\"\");\n if (!newWindow) {\n return;\n }\n const img = newWindow.document.createElement(\"img\");\n img.onload = function () {\n // no longer need to read the blob so it's revoked\n URL.revokeObjectURL(url);\n };\n img.src = url;\n newWindow.document.body.appendChild(img);\n }\n }\n }\n /**\n * Encodes the canvas data to base 64, or automatically downloads the result if `fileName` is defined.\n * @param canvas The canvas to get the data from, which can be an offscreen canvas.\n * @param successCallback The callback which is triggered once the data is available. If `fileName` is defined, the callback will be invoked after the download occurs, and the `data` argument will be an empty string.\n * @param mimeType The mime type of the result.\n * @param fileName The name of the file to download. If defined, the result will automatically be downloaded. If not defined, and `successCallback` is also not defined, the result will automatically be downloaded with an auto-generated file name.\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n */\n static EncodeScreenshotCanvasData(canvas, successCallback, mimeType = \"image/png\", fileName, quality) {\n if (typeof fileName === \"string\" || !successCallback) {\n this.ToBlob(canvas, function (blob) {\n if (blob) {\n Tools.DownloadBlob(blob, fileName);\n }\n if (successCallback) {\n successCallback(\"\");\n }\n }, mimeType, quality);\n }\n else if (successCallback) {\n if (Tools._IsOffScreenCanvas(canvas)) {\n canvas\n .convertToBlob({\n type: mimeType,\n quality,\n })\n .then((blob) => {\n const reader = new FileReader();\n reader.readAsDataURL(blob);\n reader.onloadend = () => {\n const base64data = reader.result;\n successCallback(base64data);\n };\n });\n return;\n }\n const base64Image = canvas.toDataURL(mimeType, quality);\n successCallback(base64Image);\n }\n }\n /**\n * Downloads a blob in the browser\n * @param blob defines the blob to download\n * @param fileName defines the name of the downloaded file\n */\n static Download(blob, fileName) {\n if (typeof URL === \"undefined\") {\n return;\n }\n const url = window.URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n document.body.appendChild(a);\n a.style.display = \"none\";\n a.href = url;\n a.download = fileName;\n a.addEventListener(\"click\", () => {\n if (a.parentElement) {\n a.parentElement.removeChild(a);\n }\n });\n a.click();\n window.URL.revokeObjectURL(url);\n }\n /**\n * Will return the right value of the noPreventDefault variable\n * Needed to keep backwards compatibility to the old API.\n *\n * @param args arguments passed to the attachControl function\n * @returns the correct value for noPreventDefault\n */\n static BackCompatCameraNoPreventDefault(args) {\n // is it used correctly?\n if (typeof args[0] === \"boolean\") {\n return args[0];\n }\n else if (typeof args[1] === \"boolean\") {\n return args[1];\n }\n return false;\n }\n /**\n * Captures a screenshot of the current rendering\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\n * @param engine defines the rendering engine\n * @param camera defines the source camera\n * @param size This parameter can be set to a single number or to an object with the\n * following (optional) properties: precision, width, height. If a single number is passed,\n * it will be used for both width and height. If an object is passed, the screenshot size\n * will be derived from the parameters. The precision property is a multiplier allowing\n * rendering at a higher or lower resolution\n * @param successCallback defines the callback receives a single parameter which contains the\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\n * src parameter of an to display it\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\n * Check your browser for supported MIME types\n * @param forceDownload force the system to download the image even if a successCallback is provided\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static CreateScreenshot(engine, camera, size, successCallback, mimeType = \"image/png\", forceDownload = false, quality) {\n throw _WarnImport(\"ScreenshotTools\");\n }\n /**\n * Captures a screenshot of the current rendering\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\n * @param engine defines the rendering engine\n * @param camera defines the source camera\n * @param size This parameter can be set to a single number or to an object with the\n * following (optional) properties: precision, width, height. If a single number is passed,\n * it will be used for both width and height. If an object is passed, the screenshot size\n * will be derived from the parameters. The precision property is a multiplier allowing\n * rendering at a higher or lower resolution\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\n * Check your browser for supported MIME types\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\n * to the src parameter of an to display it\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static CreateScreenshotAsync(engine, camera, size, mimeType = \"image/png\", quality) {\n throw _WarnImport(\"ScreenshotTools\");\n }\n /**\n * Generates an image screenshot from the specified camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\n * @param engine The engine to use for rendering\n * @param camera The camera to use for rendering\n * @param size This parameter can be set to a single number or to an object with the\n * following (optional) properties: precision, width, height. If a single number is passed,\n * it will be used for both width and height. If an object is passed, the screenshot size\n * will be derived from the parameters. The precision property is a multiplier allowing\n * rendering at a higher or lower resolution\n * @param successCallback The callback receives a single parameter which contains the\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\n * src parameter of an to display it\n * @param mimeType The MIME type of the screenshot image (default: image/png).\n * Check your browser for supported MIME types\n * @param samples Texture samples (default: 1)\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\n * @param fileName A name for for the downloaded file.\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static CreateScreenshotUsingRenderTarget(engine, camera, size, successCallback, mimeType = \"image/png\", samples = 1, antialiasing = false, fileName, renderSprites = false, enableStencilBuffer = false, useLayerMask = true, quality) {\n throw _WarnImport(\"ScreenshotTools\");\n }\n /**\n * Generates an image screenshot from the specified camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\n * @param engine The engine to use for rendering\n * @param camera The camera to use for rendering\n * @param size This parameter can be set to a single number or to an object with the\n * following (optional) properties: precision, width, height. If a single number is passed,\n * it will be used for both width and height. If an object is passed, the screenshot size\n * will be derived from the parameters. The precision property is a multiplier allowing\n * rendering at a higher or lower resolution\n * @param mimeType The MIME type of the screenshot image (default: image/png).\n * Check your browser for supported MIME types\n * @param samples Texture samples (default: 1)\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\n * @param fileName A name for for the downloaded file.\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n * to the src parameter of an to display it\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static CreateScreenshotUsingRenderTargetAsync(engine, camera, size, mimeType = \"image/png\", samples = 1, antialiasing = false, fileName, renderSprites = false, enableStencilBuffer = false, useLayerMask = true, quality) {\n throw _WarnImport(\"ScreenshotTools\");\n }\n /**\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\n * Be aware Math.random() could cause collisions, but:\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\n * @returns a pseudo random id\n */\n static RandomId() {\n return RandomGUID();\n }\n /**\n * Test if the given uri is a base64 string\n * @deprecated Please use FileTools.IsBase64DataUrl instead.\n * @param uri The uri to test\n * @returns True if the uri is a base64 string or false otherwise\n */\n static IsBase64(uri) {\n return IsBase64DataUrl(uri);\n }\n /**\n * Decode the given base64 uri.\n * @deprecated Please use FileTools.DecodeBase64UrlToBinary instead.\n * @param uri The uri to decode\n * @returns The decoded base64 data.\n */\n static DecodeBase64(uri) {\n return DecodeBase64UrlToBinary(uri);\n }\n /**\n * Gets a value indicating the number of loading errors\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static get errorsCount() {\n return Logger.errorsCount;\n }\n /**\n * Log a message to the console\n * @param message defines the message to log\n */\n static Log(message) {\n Logger.Log(message);\n }\n /**\n * Write a warning message to the console\n * @param message defines the message to log\n */\n static Warn(message) {\n Logger.Warn(message);\n }\n /**\n * Write an error message to the console\n * @param message defines the message to log\n */\n static Error(message) {\n Logger.Error(message);\n }\n /**\n * Gets current log cache (list of logs)\n */\n static get LogCache() {\n return Logger.LogCache;\n }\n /**\n * Clears the log cache\n */\n static ClearLogCache() {\n Logger.ClearLogCache();\n }\n /**\n * Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)\n */\n static set LogLevels(level) {\n Logger.LogLevels = level;\n }\n /**\n * Sets the current performance log level\n */\n static set PerformanceLogLevel(level) {\n if ((level & Tools.PerformanceUserMarkLogLevel) === Tools.PerformanceUserMarkLogLevel) {\n Tools.StartPerformanceCounter = Tools._StartUserMark;\n Tools.EndPerformanceCounter = Tools._EndUserMark;\n return;\n }\n if ((level & Tools.PerformanceConsoleLogLevel) === Tools.PerformanceConsoleLogLevel) {\n Tools.StartPerformanceCounter = Tools._StartPerformanceConsole;\n Tools.EndPerformanceCounter = Tools._EndPerformanceConsole;\n return;\n }\n Tools.StartPerformanceCounter = Tools._StartPerformanceCounterDisabled;\n Tools.EndPerformanceCounter = Tools._EndPerformanceCounterDisabled;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static _StartPerformanceCounterDisabled(counterName, condition) { }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static _EndPerformanceCounterDisabled(counterName, condition) { }\n static _StartUserMark(counterName, condition = true) {\n if (!Tools._Performance) {\n if (!IsWindowObjectExist()) {\n return;\n }\n Tools._Performance = window.performance;\n }\n if (!condition || !Tools._Performance.mark) {\n return;\n }\n Tools._Performance.mark(counterName + \"-Begin\");\n }\n static _EndUserMark(counterName, condition = true) {\n if (!condition || !Tools._Performance.mark) {\n return;\n }\n Tools._Performance.mark(counterName + \"-End\");\n Tools._Performance.measure(counterName, counterName + \"-Begin\", counterName + \"-End\");\n }\n static _StartPerformanceConsole(counterName, condition = true) {\n if (!condition) {\n return;\n }\n Tools._StartUserMark(counterName, condition);\n if (console.time) {\n console.time(counterName);\n }\n }\n static _EndPerformanceConsole(counterName, condition = true) {\n if (!condition) {\n return;\n }\n Tools._EndUserMark(counterName, condition);\n console.timeEnd(counterName);\n }\n /**\n * Gets either window.performance.now() if supported or Date.now() else\n */\n static get Now() {\n return PrecisionDate.Now;\n }\n /**\n * This method will return the name of the class used to create the instance of the given object.\n * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator.\n * @param object the object to get the class name from\n * @param isType defines if the object is actually a type\n * @returns the name of the class, will be \"object\" for a custom data type not using the @className decorator\n */\n static GetClassName(object, isType = false) {\n let name = null;\n if (!isType && object.getClassName) {\n name = object.getClassName();\n }\n else {\n if (object instanceof Object) {\n const classObj = isType ? object : Object.getPrototypeOf(object);\n name = classObj.constructor[\"__bjsclassName__\"];\n }\n if (!name) {\n name = typeof object;\n }\n }\n return name;\n }\n /**\n * Gets the first element of an array satisfying a given predicate\n * @param array defines the array to browse\n * @param predicate defines the predicate to use\n * @returns null if not found or the element\n */\n static First(array, predicate) {\n for (const el of array) {\n if (predicate(el)) {\n return el;\n }\n }\n return null;\n }\n /**\n * This method will return the name of the full name of the class, including its owning module (if any).\n * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator or implementing a method getClassName():string (in which case the module won't be specified).\n * @param object the object to get the class name from\n * @param isType defines if the object is actually a type\n * @returns a string that can have two forms: \"moduleName.className\" if module was specified when the class' Name was registered or \"className\" if there was not module specified.\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static getFullClassName(object, isType = false) {\n let className = null;\n let moduleName = null;\n if (!isType && object.getClassName) {\n className = object.getClassName();\n }\n else {\n if (object instanceof Object) {\n const classObj = isType ? object : Object.getPrototypeOf(object);\n className = classObj.constructor[\"__bjsclassName__\"];\n moduleName = classObj.constructor[\"__bjsmoduleName__\"];\n }\n if (!className) {\n className = typeof object;\n }\n }\n if (!className) {\n return null;\n }\n return (moduleName != null ? moduleName + \".\" : \"\") + className;\n }\n /**\n * Returns a promise that resolves after the given amount of time.\n * @param delay Number of milliseconds to delay\n * @returns Promise that resolves after the given amount of time\n */\n static DelayAsync(delay) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve();\n }, delay);\n });\n }\n /**\n * Utility function to detect if the current user agent is Safari\n * @returns whether or not the current user agent is safari\n */\n static IsSafari() {\n if (!IsNavigatorAvailable()) {\n return false;\n }\n return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n }\n }\n /**\n * Enable/Disable Custom HTTP Request Headers globally.\n * default = false\n * @see CustomRequestHeaders\n */\n Tools.UseCustomRequestHeaders = false;\n /**\n * Custom HTTP Request Headers to be sent with XMLHttpRequests\n * i.e. when loading files, where the server/service expects an Authorization header\n */\n Tools.CustomRequestHeaders = WebRequest.CustomRequestHeaders;\n Tools._TmpFloatArray = new Float32Array(1);\n /**\n * Extracts text content from a DOM element hierarchy\n * Back Compat only, please use GetDOMTextContent instead.\n */\n Tools.GetDOMTextContent = GetDOMTextContent;\n Tools.GetAbsoluteUrl = typeof document === \"object\"\n ? (url) => {\n const a = document.createElement(\"a\");\n a.href = url;\n return a.href;\n }\n : typeof URL === \"function\" && typeof location === \"object\"\n ? (url) => new URL(url, location.origin).href\n : () => {\n throw new Error(\"Unable to get absolute URL. Override BABYLON.Tools.GetAbsoluteUrl to a custom implementation for the current context.\");\n };\n // Logs\n /**\n * No log\n */\n Tools.NoneLogLevel = Logger.NoneLogLevel;\n /**\n * Only message logs\n */\n Tools.MessageLogLevel = Logger.MessageLogLevel;\n /**\n * Only warning logs\n */\n Tools.WarningLogLevel = Logger.WarningLogLevel;\n /**\n * Only error logs\n */\n Tools.ErrorLogLevel = Logger.ErrorLogLevel;\n /**\n * All logs\n */\n Tools.AllLogLevel = Logger.AllLogLevel;\n /**\n * Checks if the window object exists\n * Back Compat only, please use IsWindowObjectExist instead.\n */\n Tools.IsWindowObjectExist = IsWindowObjectExist;\n // Performances\n /**\n * No performance log\n */\n Tools.PerformanceNoneLogLevel = 0;\n /**\n * Use user marks to log performance\n */\n Tools.PerformanceUserMarkLogLevel = 1;\n /**\n * Log performance to the console\n */\n Tools.PerformanceConsoleLogLevel = 2;\n /**\n * Starts a performance counter\n */\n Tools.StartPerformanceCounter = Tools._StartPerformanceCounterDisabled;\n /**\n * Ends a specific performance counter\n */\n Tools.EndPerformanceCounter = Tools._EndPerformanceCounterDisabled;\n /**\n * An implementation of a loop for asynchronous functions.\n */\n class AsyncLoop {\n /**\n * Constructor.\n * @param iterations the number of iterations.\n * @param func the function to run each iteration\n * @param successCallback the callback that will be called upon successful execution\n * @param offset starting offset.\n */\n constructor(\n /**\n * Defines the number of iterations for the loop\n */\n iterations, func, successCallback, offset = 0) {\n this.iterations = iterations;\n this.index = offset - 1;\n this._done = false;\n this._fn = func;\n this._successCallback = successCallback;\n }\n /**\n * Execute the next iteration. Must be called after the last iteration was finished.\n */\n executeNext() {\n if (!this._done) {\n if (this.index + 1 < this.iterations) {\n ++this.index;\n this._fn(this);\n }\n else {\n this.breakLoop();\n }\n }\n }\n /**\n * Break the loop and run the success callback.\n */\n breakLoop() {\n this._done = true;\n this._successCallback();\n }\n /**\n * Create and run an async loop.\n * @param iterations the number of iterations.\n * @param fn the function to run each iteration\n * @param successCallback the callback that will be called upon successful execution\n * @param offset starting offset.\n * @returns the created async loop object\n */\n static Run(iterations, fn, successCallback, offset = 0) {\n const loop = new AsyncLoop(iterations, fn, successCallback, offset);\n loop.executeNext();\n return loop;\n }\n /**\n * A for-loop that will run a given number of iterations synchronous and the rest async.\n * @param iterations total number of iterations\n * @param syncedIterations number of synchronous iterations in each async iteration.\n * @param fn the function to call each iteration.\n * @param callback a success call back that will be called when iterating stops.\n * @param breakFunction a break condition (optional)\n * @param timeout timeout settings for the setTimeout function. default - 0.\n * @returns the created async loop object\n */\n static SyncAsyncForLoop(iterations, syncedIterations, fn, callback, breakFunction, timeout = 0) {\n return AsyncLoop.Run(Math.ceil(iterations / syncedIterations), (loop) => {\n if (breakFunction && breakFunction()) {\n loop.breakLoop();\n }\n else {\n setTimeout(() => {\n for (let i = 0; i < syncedIterations; ++i) {\n const iteration = loop.index * syncedIterations + i;\n if (iteration >= iterations) {\n break;\n }\n fn(iteration);\n if (breakFunction && breakFunction()) {\n loop.breakLoop();\n break;\n }\n }\n loop.executeNext();\n }, timeout);\n }\n }, callback);\n }\n }\n // Will only be define if Tools is imported freeing up some space when only engine is required\n EngineStore.FallbackTexture =\n \"data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/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fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z\";\n\n /* eslint-disable @typescript-eslint/naming-convention */\n // \"Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed.\"\n // https://en.wikipedia.org/wiki/Coroutine\n // The inline scheduler simply steps the coroutine synchronously. This is useful for running a coroutine synchronously, and also as a helper function for other schedulers.\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function inlineScheduler(coroutine, onStep, onError) {\n try {\n const step = coroutine.next();\n if (step.done) {\n onStep(step);\n }\n else if (!step.value) {\n // NOTE: The properties of step have been narrowed, but the type of step itself is not narrowed, so the cast below is the most type safe way to deal with this without instantiating a new object to hold the values.\n onStep(step);\n }\n else {\n step.value.then(() => {\n step.value = undefined;\n onStep(step);\n }, onError);\n }\n }\n catch (error) {\n onError(error);\n }\n }\n // The yielding scheduler steps the coroutine synchronously until the specified time interval has elapsed, then yields control so other operations can be performed.\n // A single instance of a yielding scheduler could be shared across multiple coroutines to yield when their collective work exceeds the threshold.\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function createYieldingScheduler(yieldAfterMS = 25) {\n let startTime;\n return (coroutine, onStep, onError) => {\n const currentTime = performance.now();\n if (startTime === undefined || currentTime - startTime > yieldAfterMS) {\n // If this is the first coroutine step, or if the time interval has elapsed, record a new start time, and schedule the coroutine step to happen later, effectively yielding control of the execution context.\n startTime = currentTime;\n setTimeout(() => {\n inlineScheduler(coroutine, onStep, onError);\n }, 0);\n }\n else {\n // Otherwise it is not time to yield yet, so step the coroutine synchronously.\n inlineScheduler(coroutine, onStep, onError);\n }\n };\n }\n // Runs the specified coroutine with the specified scheduler. The success or error callback will be invoked when the coroutine finishes.\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function runCoroutine(coroutine, scheduler, onSuccess, onError, abortSignal) {\n const resume = () => {\n let reschedule;\n const onStep = (stepResult) => {\n if (stepResult.done) {\n // If the coroutine is done, report success.\n onSuccess(stepResult.value);\n }\n else {\n // If the coroutine is not done, resume the coroutine (via the scheduler).\n if (reschedule === undefined) {\n // If reschedule is undefined at this point, then the coroutine must have stepped synchronously, so just flag another loop iteration.\n reschedule = true;\n }\n else {\n // If reschedule is defined at this point, then the coroutine must have stepped asynchronously, so call resume to restart the step loop.\n resume();\n }\n }\n };\n do {\n reschedule = undefined;\n if (!abortSignal || !abortSignal.aborted) {\n scheduler(coroutine, onStep, onError);\n }\n else {\n onError(new Error(\"Aborted\"));\n }\n if (reschedule === undefined) {\n // If reschedule is undefined at this point, then the coroutine must have stepped asynchronously, so stop looping and let the coroutine be resumed later.\n reschedule = false;\n }\n } while (reschedule);\n };\n resume();\n }\n // Runs the specified coroutine synchronously.\n /**\n * @internal\n */\n function runCoroutineSync(coroutine, abortSignal) {\n // Run the coroutine with the inline scheduler, storing the returned value, or re-throwing the error (since the error callback will be called synchronously by the inline scheduler).\n let result;\n runCoroutine(coroutine, inlineScheduler, (r) => (result = r), (e) => {\n throw e;\n }, abortSignal);\n // Synchronously return the result of the coroutine.\n return result;\n }\n // Runs the specified coroutine asynchronously with the specified scheduler.\n /**\n * @internal\n */\n function runCoroutineAsync(coroutine, scheduler, abortSignal) {\n // Run the coroutine with a yielding scheduler, resolving or rejecting the result promise when the coroutine finishes.\n return new Promise((resolve, reject) => {\n runCoroutine(coroutine, scheduler, resolve, reject, abortSignal);\n });\n }\n /**\n * Given a function that returns a Coroutine, produce a function with the same parameters that returns a T.\n * The returned function runs the coroutine synchronously.\n * @param coroutineFactory A function that returns a Coroutine.\n * @param abortSignal\n * @returns A function that runs the coroutine synchronously.\n * @internal\n */\n function makeSyncFunction(coroutineFactory, abortSignal) {\n return (...params) => {\n // Run the coroutine synchronously.\n return runCoroutineSync(coroutineFactory(...params), abortSignal);\n };\n }\n\n /**\n * Defines an GC Friendly array where the backfield array do not shrink to prevent over allocations.\n */\n class SmartArray {\n /**\n * Instantiates a Smart Array.\n * @param capacity defines the default capacity of the array.\n */\n constructor(capacity) {\n /**\n * The active length of the array.\n */\n this.length = 0;\n this.data = new Array(capacity);\n this._id = SmartArray._GlobalId++;\n }\n /**\n * Pushes a value at the end of the active data.\n * @param value defines the object to push in the array.\n */\n push(value) {\n this.data[this.length++] = value;\n if (this.length > this.data.length) {\n this.data.length *= 2;\n }\n }\n /**\n * Iterates over the active data and apply the lambda to them.\n * @param func defines the action to apply on each value.\n */\n forEach(func) {\n for (let index = 0; index < this.length; index++) {\n func(this.data[index]);\n }\n }\n /**\n * Sorts the full sets of data.\n * @param compareFn defines the comparison function to apply.\n */\n sort(compareFn) {\n this.data.sort(compareFn);\n }\n /**\n * Resets the active data to an empty array.\n */\n reset() {\n this.length = 0;\n }\n /**\n * Releases all the data from the array as well as the array.\n */\n dispose() {\n this.reset();\n if (this.data) {\n this.data.length = 0;\n }\n }\n /**\n * Concats the active data with a given array.\n * @param array defines the data to concatenate with.\n */\n concat(array) {\n if (array.length === 0) {\n return;\n }\n if (this.length + array.length > this.data.length) {\n this.data.length = (this.length + array.length) * 2;\n }\n for (let index = 0; index < array.length; index++) {\n this.data[this.length++] = (array.data || array)[index];\n }\n }\n /**\n * Returns the position of a value in the active data.\n * @param value defines the value to find the index for\n * @returns the index if found in the active data otherwise -1\n */\n indexOf(value) {\n const position = this.data.indexOf(value);\n if (position >= this.length) {\n return -1;\n }\n return position;\n }\n /**\n * Returns whether an element is part of the active data.\n * @param value defines the value to look for\n * @returns true if found in the active data otherwise false\n */\n contains(value) {\n return this.indexOf(value) !== -1;\n }\n }\n // Statics\n SmartArray._GlobalId = 0;\n /**\n * Defines an GC Friendly array where the backfield array do not shrink to prevent over allocations.\n * The data in this array can only be present once\n */\n class SmartArrayNoDuplicate extends SmartArray {\n constructor() {\n super(...arguments);\n this._duplicateId = 0;\n }\n /**\n * Pushes a value at the end of the active data.\n * THIS DOES NOT PREVENT DUPPLICATE DATA\n * @param value defines the object to push in the array.\n */\n push(value) {\n super.push(value);\n if (!value.__smartArrayFlags) {\n value.__smartArrayFlags = {};\n }\n value.__smartArrayFlags[this._id] = this._duplicateId;\n }\n /**\n * Pushes a value at the end of the active data.\n * If the data is already present, it won t be added again\n * @param value defines the object to push in the array.\n * @returns true if added false if it was already present\n */\n pushNoDuplicate(value) {\n if (value.__smartArrayFlags && value.__smartArrayFlags[this._id] === this._duplicateId) {\n return false;\n }\n this.push(value);\n return true;\n }\n /**\n * Resets the active data to an empty array.\n */\n reset() {\n super.reset();\n this._duplicateId++;\n }\n /**\n * Concats the active data with a given array.\n * This ensures no duplicate will be present in the result.\n * @param array defines the data to concatenate with.\n */\n concatWithNoDuplicate(array) {\n if (array.length === 0) {\n return;\n }\n if (this.length + array.length > this.data.length) {\n this.data.length = (this.length + array.length) * 2;\n }\n for (let index = 0; index < array.length; index++) {\n const item = (array.data || array)[index];\n this.pushNoDuplicate(item);\n }\n }\n }\n\n /**\n * Class used to represent a viewport on screen\n */\n class Viewport {\n /**\n * Creates a Viewport object located at (x, y) and sized (width, height)\n * @param x defines viewport left coordinate\n * @param y defines viewport top coordinate\n * @param width defines the viewport width\n * @param height defines the viewport height\n */\n constructor(\n /** viewport left coordinate */\n x, \n /** viewport top coordinate */\n y, \n /**viewport width */\n width, \n /** viewport height */\n height) {\n this.x = x;\n this.y = y;\n this.width = width;\n this.height = height;\n }\n /**\n * Creates a new viewport using absolute sizing (from 0-> width, 0-> height instead of 0->1)\n * @param renderWidth defines the rendering width\n * @param renderHeight defines the rendering height\n * @returns a new Viewport\n */\n toGlobal(renderWidth, renderHeight) {\n return new Viewport(this.x * renderWidth, this.y * renderHeight, this.width * renderWidth, this.height * renderHeight);\n }\n /**\n * Stores absolute viewport value into a target viewport (from 0-> width, 0-> height instead of 0->1)\n * @param renderWidth defines the rendering width\n * @param renderHeight defines the rendering height\n * @param ref defines the target viewport\n * @returns the current viewport\n */\n toGlobalToRef(renderWidth, renderHeight, ref) {\n ref.x = this.x * renderWidth;\n ref.y = this.y * renderHeight;\n ref.width = this.width * renderWidth;\n ref.height = this.height * renderHeight;\n return this;\n }\n /**\n * Returns a new Viewport copied from the current one\n * @returns a new Viewport\n */\n clone() {\n return new Viewport(this.x, this.y, this.width, this.height);\n }\n }\n\n /**\n * Represents a plane by the equation ax + by + cz + d = 0\n */\n class Plane {\n /**\n * Creates a Plane object according to the given floats a, b, c, d and the plane equation : ax + by + cz + d = 0\n * @param a a component of the plane\n * @param b b component of the plane\n * @param c c component of the plane\n * @param d d component of the plane\n */\n constructor(a, b, c, d) {\n this.normal = new Vector3(a, b, c);\n this.d = d;\n }\n /**\n * @returns the plane coordinates as a new array of 4 elements [a, b, c, d].\n */\n asArray() {\n return [this.normal.x, this.normal.y, this.normal.z, this.d];\n }\n // Methods\n /**\n * @returns a new plane copied from the current Plane.\n */\n clone() {\n return new Plane(this.normal.x, this.normal.y, this.normal.z, this.d);\n }\n /**\n * @returns the string \"Plane\".\n */\n getClassName() {\n return \"Plane\";\n }\n /**\n * @returns the Plane hash code.\n */\n getHashCode() {\n let hash = this.normal.getHashCode();\n hash = (hash * 397) ^ (this.d | 0);\n return hash;\n }\n /**\n * Normalize the current Plane in place.\n * @returns the updated Plane.\n */\n normalize() {\n const norm = Math.sqrt(this.normal.x * this.normal.x + this.normal.y * this.normal.y + this.normal.z * this.normal.z);\n let magnitude = 0.0;\n if (norm !== 0) {\n magnitude = 1.0 / norm;\n }\n this.normal.x *= magnitude;\n this.normal.y *= magnitude;\n this.normal.z *= magnitude;\n this.d *= magnitude;\n return this;\n }\n /**\n * Applies a transformation the plane and returns the result\n * @param transformation the transformation matrix to be applied to the plane\n * @returns a new Plane as the result of the transformation of the current Plane by the given matrix.\n */\n transform(transformation) {\n const invertedMatrix = Plane._TmpMatrix;\n transformation.invertToRef(invertedMatrix);\n const m = invertedMatrix.m;\n const x = this.normal.x;\n const y = this.normal.y;\n const z = this.normal.z;\n const d = this.d;\n const normalX = x * m[0] + y * m[1] + z * m[2] + d * m[3];\n const normalY = x * m[4] + y * m[5] + z * m[6] + d * m[7];\n const normalZ = x * m[8] + y * m[9] + z * m[10] + d * m[11];\n const finalD = x * m[12] + y * m[13] + z * m[14] + d * m[15];\n return new Plane(normalX, normalY, normalZ, finalD);\n }\n /**\n * Compute the dot product between the point and the plane normal\n * @param point point to calculate the dot product with\n * @returns the dot product (float) of the point coordinates and the plane normal.\n */\n dotCoordinate(point) {\n return this.normal.x * point.x + this.normal.y * point.y + this.normal.z * point.z + this.d;\n }\n /**\n * Updates the current Plane from the plane defined by the three given points.\n * @param point1 one of the points used to construct the plane\n * @param point2 one of the points used to construct the plane\n * @param point3 one of the points used to construct the plane\n * @returns the updated Plane.\n */\n copyFromPoints(point1, point2, point3) {\n const x1 = point2.x - point1.x;\n const y1 = point2.y - point1.y;\n const z1 = point2.z - point1.z;\n const x2 = point3.x - point1.x;\n const y2 = point3.y - point1.y;\n const z2 = point3.z - point1.z;\n const yz = y1 * z2 - z1 * y2;\n const xz = z1 * x2 - x1 * z2;\n const xy = x1 * y2 - y1 * x2;\n const pyth = Math.sqrt(yz * yz + xz * xz + xy * xy);\n let invPyth;\n if (pyth !== 0) {\n invPyth = 1.0 / pyth;\n }\n else {\n invPyth = 0.0;\n }\n this.normal.x = yz * invPyth;\n this.normal.y = xz * invPyth;\n this.normal.z = xy * invPyth;\n this.d = -(this.normal.x * point1.x + this.normal.y * point1.y + this.normal.z * point1.z);\n return this;\n }\n /**\n * Checks if the plane is facing a given direction (meaning if the plane's normal is pointing in the opposite direction of the given vector).\n * Note that for this function to work as expected you should make sure that:\n * - direction and the plane normal are normalized\n * - epsilon is a number just bigger than -1, something like -0.99 for eg\n * @param direction the direction to check if the plane is facing\n * @param epsilon value the dot product is compared against (returns true if dot <= epsilon)\n * @returns True if the plane is facing the given direction\n */\n isFrontFacingTo(direction, epsilon) {\n const dot = Vector3.Dot(this.normal, direction);\n return dot <= epsilon;\n }\n /**\n * Calculates the distance to a point\n * @param point point to calculate distance to\n * @returns the signed distance (float) from the given point to the Plane.\n */\n signedDistanceTo(point) {\n return Vector3.Dot(point, this.normal) + this.d;\n }\n // Statics\n /**\n * Creates a plane from an array\n * @param array the array to create a plane from\n * @returns a new Plane from the given array.\n */\n static FromArray(array) {\n return new Plane(array[0], array[1], array[2], array[3]);\n }\n /**\n * Creates a plane from three points\n * @param point1 point used to create the plane\n * @param point2 point used to create the plane\n * @param point3 point used to create the plane\n * @returns a new Plane defined by the three given points.\n */\n static FromPoints(point1, point2, point3) {\n const result = new Plane(0.0, 0.0, 0.0, 0.0);\n result.copyFromPoints(point1, point2, point3);\n return result;\n }\n /**\n * Creates a plane from an origin point and a normal\n * @param origin origin of the plane to be constructed\n * @param normal normal of the plane to be constructed\n * @returns a new Plane the normal vector to this plane at the given origin point.\n * Note : the vector \"normal\" is updated because normalized.\n */\n static FromPositionAndNormal(origin, normal) {\n const result = new Plane(0.0, 0.0, 0.0, 0.0);\n normal.normalize();\n result.normal = normal;\n result.d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);\n return result;\n }\n /**\n * Calculates the distance from a plane and a point\n * @param origin origin of the plane to be constructed\n * @param normal normal of the plane to be constructed\n * @param point point to calculate distance to\n * @returns the signed distance between the plane defined by the normal vector at the \"origin\"\" point and the given other point.\n */\n static SignedDistanceToPlaneFromPositionAndNormal(origin, normal, point) {\n const d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);\n return Vector3.Dot(point, normal) + d;\n }\n }\n Plane._TmpMatrix = Matrix.Identity();\n\n /**\n * Represents a camera frustum\n */\n class Frustum {\n /**\n * Gets the planes representing the frustum\n * @param transform matrix to be applied to the returned planes\n * @returns a new array of 6 Frustum planes computed by the given transformation matrix.\n */\n static GetPlanes(transform) {\n const frustumPlanes = [];\n for (let index = 0; index < 6; index++) {\n frustumPlanes.push(new Plane(0.0, 0.0, 0.0, 0.0));\n }\n Frustum.GetPlanesToRef(transform, frustumPlanes);\n return frustumPlanes;\n }\n /**\n * Gets the near frustum plane transformed by the transform matrix\n * @param transform transformation matrix to be applied to the resulting frustum plane\n * @param frustumPlane the resulting frustum plane\n */\n static GetNearPlaneToRef(transform, frustumPlane) {\n const m = transform.m;\n frustumPlane.normal.x = m[3] + m[2];\n frustumPlane.normal.y = m[7] + m[6];\n frustumPlane.normal.z = m[11] + m[10];\n frustumPlane.d = m[15] + m[14];\n frustumPlane.normalize();\n }\n /**\n * Gets the far frustum plane transformed by the transform matrix\n * @param transform transformation matrix to be applied to the resulting frustum plane\n * @param frustumPlane the resulting frustum plane\n */\n static GetFarPlaneToRef(transform, frustumPlane) {\n const m = transform.m;\n frustumPlane.normal.x = m[3] - m[2];\n frustumPlane.normal.y = m[7] - m[6];\n frustumPlane.normal.z = m[11] - m[10];\n frustumPlane.d = m[15] - m[14];\n frustumPlane.normalize();\n }\n /**\n * Gets the left frustum plane transformed by the transform matrix\n * @param transform transformation matrix to be applied to the resulting frustum plane\n * @param frustumPlane the resulting frustum plane\n */\n static GetLeftPlaneToRef(transform, frustumPlane) {\n const m = transform.m;\n frustumPlane.normal.x = m[3] + m[0];\n frustumPlane.normal.y = m[7] + m[4];\n frustumPlane.normal.z = m[11] + m[8];\n frustumPlane.d = m[15] + m[12];\n frustumPlane.normalize();\n }\n /**\n * Gets the right frustum plane transformed by the transform matrix\n * @param transform transformation matrix to be applied to the resulting frustum plane\n * @param frustumPlane the resulting frustum plane\n */\n static GetRightPlaneToRef(transform, frustumPlane) {\n const m = transform.m;\n frustumPlane.normal.x = m[3] - m[0];\n frustumPlane.normal.y = m[7] - m[4];\n frustumPlane.normal.z = m[11] - m[8];\n frustumPlane.d = m[15] - m[12];\n frustumPlane.normalize();\n }\n /**\n * Gets the top frustum plane transformed by the transform matrix\n * @param transform transformation matrix to be applied to the resulting frustum plane\n * @param frustumPlane the resulting frustum plane\n */\n static GetTopPlaneToRef(transform, frustumPlane) {\n const m = transform.m;\n frustumPlane.normal.x = m[3] - m[1];\n frustumPlane.normal.y = m[7] - m[5];\n frustumPlane.normal.z = m[11] - m[9];\n frustumPlane.d = m[15] - m[13];\n frustumPlane.normalize();\n }\n /**\n * Gets the bottom frustum plane transformed by the transform matrix\n * @param transform transformation matrix to be applied to the resulting frustum plane\n * @param frustumPlane the resulting frustum plane\n */\n static GetBottomPlaneToRef(transform, frustumPlane) {\n const m = transform.m;\n frustumPlane.normal.x = m[3] + m[1];\n frustumPlane.normal.y = m[7] + m[5];\n frustumPlane.normal.z = m[11] + m[9];\n frustumPlane.d = m[15] + m[13];\n frustumPlane.normalize();\n }\n /**\n * Sets the given array \"frustumPlanes\" with the 6 Frustum planes computed by the given transformation matrix.\n * @param transform transformation matrix to be applied to the resulting frustum planes\n * @param frustumPlanes the resulting frustum planes\n */\n static GetPlanesToRef(transform, frustumPlanes) {\n // Near\n Frustum.GetNearPlaneToRef(transform, frustumPlanes[0]);\n // Far\n Frustum.GetFarPlaneToRef(transform, frustumPlanes[1]);\n // Left\n Frustum.GetLeftPlaneToRef(transform, frustumPlanes[2]);\n // Right\n Frustum.GetRightPlaneToRef(transform, frustumPlanes[3]);\n // Top\n Frustum.GetTopPlaneToRef(transform, frustumPlanes[4]);\n // Bottom\n Frustum.GetBottomPlaneToRef(transform, frustumPlanes[5]);\n }\n /**\n * Tests if a point is located between the frustum planes.\n * @param point defines the point to test\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if the point is located between the frustum planes\n */\n static IsPointInFrustum(point, frustumPlanes) {\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(point) < 0) {\n return false;\n }\n }\n return true;\n }\n }\n\n /**\n * This is the base class of all the camera used in the application.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\n */\n class Camera extends Node {\n /**\n * Define the current local position of the camera in the scene\n */\n get position() {\n return this._position;\n }\n set position(newPosition) {\n this._position = newPosition;\n }\n /**\n * The vector the camera should consider as up.\n * (default is Vector3(0, 1, 0) aka Vector3.Up())\n */\n set upVector(vec) {\n this._upVector = vec;\n }\n get upVector() {\n return this._upVector;\n }\n /**\n * The screen area in scene units squared\n */\n get screenArea() {\n var _a, _b, _c, _d;\n let x = 0;\n let y = 0;\n if (this.mode === Camera.PERSPECTIVE_CAMERA) {\n if (this.fovMode === Camera.FOVMODE_VERTICAL_FIXED) {\n y = this.minZ * 2 * Math.tan(this.fov / 2);\n x = this.getEngine().getAspectRatio(this) * y;\n }\n else {\n x = this.minZ * 2 * Math.tan(this.fov / 2);\n y = x / this.getEngine().getAspectRatio(this);\n }\n }\n else {\n const halfWidth = this.getEngine().getRenderWidth() / 2.0;\n const halfHeight = this.getEngine().getRenderHeight() / 2.0;\n x = ((_a = this.orthoRight) !== null && _a !== void 0 ? _a : halfWidth) - ((_b = this.orthoLeft) !== null && _b !== void 0 ? _b : -halfWidth);\n y = ((_c = this.orthoTop) !== null && _c !== void 0 ? _c : halfHeight) - ((_d = this.orthoBottom) !== null && _d !== void 0 ? _d : -halfHeight);\n }\n return x * y;\n }\n set orthoLeft(value) {\n this._orthoLeft = value;\n for (const rigCamera of this._rigCameras) {\n rigCamera.orthoLeft = value;\n }\n }\n get orthoLeft() {\n return this._orthoLeft;\n }\n set orthoRight(value) {\n this._orthoRight = value;\n for (const rigCamera of this._rigCameras) {\n rigCamera.orthoRight = value;\n }\n }\n get orthoRight() {\n return this._orthoRight;\n }\n set orthoBottom(value) {\n this._orthoBottom = value;\n for (const rigCamera of this._rigCameras) {\n rigCamera.orthoBottom = value;\n }\n }\n get orthoBottom() {\n return this._orthoBottom;\n }\n set orthoTop(value) {\n this._orthoTop = value;\n for (const rigCamera of this._rigCameras) {\n rigCamera.orthoTop = value;\n }\n }\n get orthoTop() {\n return this._orthoTop;\n }\n set mode(mode) {\n this._mode = mode;\n // Pass the mode down to the rig cameras\n for (const rigCamera of this._rigCameras) {\n rigCamera.mode = mode;\n }\n }\n get mode() {\n return this._mode;\n }\n /**\n * Instantiates a new camera object.\n * This should not be used directly but through the inherited cameras: ArcRotate, Free...\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\n * @param name Defines the name of the camera in the scene\n * @param position Defines the position of the camera\n * @param scene Defines the scene the camera belongs too\n * @param setActiveOnSceneIfNoneActive Defines if the camera should be set as active after creation if no other camera have been defined in the scene\n */\n constructor(name, position, scene, setActiveOnSceneIfNoneActive = true) {\n super(name, scene);\n /** @internal */\n this._position = Vector3.Zero();\n this._upVector = Vector3.Up();\n /**\n * Define the current limit on the left side for an orthographic camera\n * In scene unit\n */\n this._orthoLeft = null;\n /**\n * Define the current limit on the right side for an orthographic camera\n * In scene unit\n */\n this._orthoRight = null;\n /**\n * Define the current limit on the bottom side for an orthographic camera\n * In scene unit\n */\n this._orthoBottom = null;\n /**\n * Define the current limit on the top side for an orthographic camera\n * In scene unit\n */\n this._orthoTop = null;\n /**\n * Field Of View is set in Radians. (default is 0.8)\n */\n this.fov = 0.8;\n /**\n * Projection plane tilt around the X axis (horizontal), set in Radians. (default is 0)\n * Can be used to make vertical lines in world space actually vertical on the screen.\n * See https://forum.babylonjs.com/t/add-vertical-shift-to-3ds-max-exporter-babylon-cameras/17480\n */\n this.projectionPlaneTilt = 0;\n /**\n * Define the minimum distance the camera can see from.\n * This is important to note that the depth buffer are not infinite and the closer it starts\n * the more your scene might encounter depth fighting issue.\n */\n this.minZ = 1;\n /**\n * Define the maximum distance the camera can see to.\n * This is important to note that the depth buffer are not infinite and the further it end\n * the more your scene might encounter depth fighting issue.\n */\n this.maxZ = 10000.0;\n /**\n * Define the default inertia of the camera.\n * This helps giving a smooth feeling to the camera movement.\n */\n this.inertia = 0.9;\n /**\n * Define the mode of the camera (Camera.PERSPECTIVE_CAMERA or Camera.ORTHOGRAPHIC_CAMERA)\n */\n this._mode = Camera.PERSPECTIVE_CAMERA;\n /**\n * Define whether the camera is intermediate.\n * This is useful to not present the output directly to the screen in case of rig without post process for instance\n */\n this.isIntermediate = false;\n /**\n * Define the viewport of the camera.\n * This correspond to the portion of the screen the camera will render to in normalized 0 to 1 unit.\n */\n this.viewport = new Viewport(0, 0, 1.0, 1.0);\n /**\n * Restricts the camera to viewing objects with the same layerMask.\n * A camera with a layerMask of 1 will render mesh.layerMask & camera.layerMask!== 0\n */\n this.layerMask = 0x0fffffff;\n /**\n * fovMode sets the camera frustum bounds to the viewport bounds. (default is FOVMODE_VERTICAL_FIXED)\n */\n this.fovMode = Camera.FOVMODE_VERTICAL_FIXED;\n /**\n * Rig mode of the camera.\n * This is useful to create the camera with two \"eyes\" instead of one to create VR or stereoscopic scenes.\n * This is normally controlled byt the camera themselves as internal use.\n */\n this.cameraRigMode = Camera.RIG_MODE_NONE;\n /**\n * Defines the list of custom render target which are rendered to and then used as the input to this camera's render. Eg. display another camera view on a TV in the main scene\n * This is pretty helpful if you wish to make a camera render to a texture you could reuse somewhere\n * else in the scene. (Eg. security camera)\n *\n * To change the final output target of the camera, camera.outputRenderTarget should be used instead (eg. webXR renders to a render target corresponding to an HMD)\n */\n this.customRenderTargets = new Array();\n /**\n * When set, the camera will render to this render target instead of the default canvas\n *\n * If the desire is to use the output of a camera as a texture in the scene consider using camera.customRenderTargets instead\n */\n this.outputRenderTarget = null;\n /**\n * Observable triggered when the camera view matrix has changed.\n */\n this.onViewMatrixChangedObservable = new Observable$1();\n /**\n * Observable triggered when the camera Projection matrix has changed.\n */\n this.onProjectionMatrixChangedObservable = new Observable$1();\n /**\n * Observable triggered when the inputs have been processed.\n */\n this.onAfterCheckInputsObservable = new Observable$1();\n /**\n * Observable triggered when reset has been called and applied to the camera.\n */\n this.onRestoreStateObservable = new Observable$1();\n /**\n * Is this camera a part of a rig system?\n */\n this.isRigCamera = false;\n /** @internal */\n this._rigCameras = new Array();\n this._webvrViewMatrix = Matrix.Identity();\n /** @internal */\n this._skipRendering = false;\n /** @internal */\n this._projectionMatrix = new Matrix();\n /** @internal */\n this._postProcesses = new Array();\n /** @internal */\n this._activeMeshes = new SmartArray(256);\n this._globalPosition = Vector3.Zero();\n /** @internal */\n this._computedViewMatrix = Matrix.Identity();\n this._doNotComputeProjectionMatrix = false;\n this._transformMatrix = Matrix.Zero();\n this._refreshFrustumPlanes = true;\n this._absoluteRotation = Quaternion.Identity();\n /** @internal */\n this._isCamera = true;\n /** @internal */\n this._isLeftCamera = false;\n /** @internal */\n this._isRightCamera = false;\n this.getScene().addCamera(this);\n if (setActiveOnSceneIfNoneActive && !this.getScene().activeCamera) {\n this.getScene().activeCamera = this;\n }\n this.position = position;\n this.renderPassId = this.getScene().getEngine().createRenderPassId(`Camera ${name}`);\n }\n /**\n * Store current camera state (fov, position, etc..)\n * @returns the camera\n */\n storeState() {\n this._stateStored = true;\n this._storedFov = this.fov;\n return this;\n }\n /**\n * Restores the camera state values if it has been stored. You must call storeState() first\n */\n _restoreStateValues() {\n if (!this._stateStored) {\n return false;\n }\n this.fov = this._storedFov;\n return true;\n }\n /**\n * Restored camera state. You must call storeState() first.\n * @returns true if restored and false otherwise\n */\n restoreState() {\n if (this._restoreStateValues()) {\n this.onRestoreStateObservable.notifyObservers(this);\n return true;\n }\n return false;\n }\n /**\n * Gets the class name of the camera.\n * @returns the class name\n */\n getClassName() {\n return \"Camera\";\n }\n /**\n * Gets a string representation of the camera useful for debug purpose.\n * @param fullDetails Defines that a more verbose level of logging is required\n * @returns the string representation\n */\n toString(fullDetails) {\n let ret = \"Name: \" + this.name;\n ret += \", type: \" + this.getClassName();\n if (this.animations) {\n for (let i = 0; i < this.animations.length; i++) {\n ret += \", animation[0]: \" + this.animations[i].toString(fullDetails);\n }\n }\n return ret;\n }\n /**\n * Automatically tilts the projection plane, using `projectionPlaneTilt`, to correct the perspective effect on vertical lines.\n */\n applyVerticalCorrection() {\n const rot = this.absoluteRotation.toEulerAngles();\n this.projectionPlaneTilt = this._scene.useRightHandedSystem ? -rot.x : rot.x;\n }\n /**\n * Gets the current world space position of the camera.\n */\n get globalPosition() {\n return this._globalPosition;\n }\n /**\n * Gets the list of active meshes this frame (meshes no culled or excluded by lod s in the frame)\n * @returns the active meshe list\n */\n getActiveMeshes() {\n return this._activeMeshes;\n }\n /**\n * Check whether a mesh is part of the current active mesh list of the camera\n * @param mesh Defines the mesh to check\n * @returns true if active, false otherwise\n */\n isActiveMesh(mesh) {\n return this._activeMeshes.indexOf(mesh) !== -1;\n }\n /**\n * Is this camera ready to be used/rendered\n * @param completeCheck defines if a complete check (including post processes) has to be done (false by default)\n * @returns true if the camera is ready\n */\n isReady(completeCheck = false) {\n if (completeCheck) {\n for (const pp of this._postProcesses) {\n if (pp && !pp.isReady()) {\n return false;\n }\n }\n }\n return super.isReady(completeCheck);\n }\n /** @internal */\n _initCache() {\n super._initCache();\n this._cache.position = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cache.upVector = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cache.mode = undefined;\n this._cache.minZ = undefined;\n this._cache.maxZ = undefined;\n this._cache.fov = undefined;\n this._cache.fovMode = undefined;\n this._cache.aspectRatio = undefined;\n this._cache.orthoLeft = undefined;\n this._cache.orthoRight = undefined;\n this._cache.orthoBottom = undefined;\n this._cache.orthoTop = undefined;\n this._cache.renderWidth = undefined;\n this._cache.renderHeight = undefined;\n }\n /**\n * @internal\n */\n _updateCache(ignoreParentClass) {\n if (!ignoreParentClass) {\n super._updateCache();\n }\n this._cache.position.copyFrom(this.position);\n this._cache.upVector.copyFrom(this.upVector);\n }\n /** @internal */\n _isSynchronized() {\n return this._isSynchronizedViewMatrix() && this._isSynchronizedProjectionMatrix();\n }\n /** @internal */\n _isSynchronizedViewMatrix() {\n if (!super._isSynchronized()) {\n return false;\n }\n return this._cache.position.equals(this.position) && this._cache.upVector.equals(this.upVector) && this.isSynchronizedWithParent();\n }\n /** @internal */\n _isSynchronizedProjectionMatrix() {\n let check = this._cache.mode === this.mode && this._cache.minZ === this.minZ && this._cache.maxZ === this.maxZ;\n if (!check) {\n return false;\n }\n const engine = this.getEngine();\n if (this.mode === Camera.PERSPECTIVE_CAMERA) {\n check =\n this._cache.fov === this.fov &&\n this._cache.fovMode === this.fovMode &&\n this._cache.aspectRatio === engine.getAspectRatio(this) &&\n this._cache.projectionPlaneTilt === this.projectionPlaneTilt;\n }\n else {\n check =\n this._cache.orthoLeft === this.orthoLeft &&\n this._cache.orthoRight === this.orthoRight &&\n this._cache.orthoBottom === this.orthoBottom &&\n this._cache.orthoTop === this.orthoTop &&\n this._cache.renderWidth === engine.getRenderWidth() &&\n this._cache.renderHeight === engine.getRenderHeight();\n }\n return check;\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * This function is here because typescript removes the typing of the last function.\n * @param _ignored defines an ignored parameter kept for backward compatibility.\n * @param _noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(_ignored, _noPreventDefault) { }\n /**\n * Detach the current controls from the specified dom element.\n * This function is here because typescript removes the typing of the last function.\n * @param _ignored defines an ignored parameter kept for backward compatibility.\n */\n detachControl(_ignored) { }\n /**\n * Update the camera state according to the different inputs gathered during the frame.\n */\n update() {\n this._checkInputs();\n if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\n this._updateRigCameras();\n }\n // Attempt to update the camera's view and projection matrices.\n // This call is being made because these matrices are no longer being updated\n // as a part of the picking ray process (in addition to scene.render).\n this.getViewMatrix();\n this.getProjectionMatrix();\n }\n /** @internal */\n _checkInputs() {\n this.onAfterCheckInputsObservable.notifyObservers(this);\n }\n /** @internal */\n get rigCameras() {\n return this._rigCameras;\n }\n /**\n * Gets the post process used by the rig cameras\n */\n get rigPostProcess() {\n return this._rigPostProcess;\n }\n /**\n * Internal, gets the first post process.\n * @returns the first post process to be run on this camera.\n */\n _getFirstPostProcess() {\n for (let ppIndex = 0; ppIndex < this._postProcesses.length; ppIndex++) {\n if (this._postProcesses[ppIndex] !== null) {\n return this._postProcesses[ppIndex];\n }\n }\n return null;\n }\n _cascadePostProcessesToRigCams() {\n // invalidate framebuffer\n const firstPostProcess = this._getFirstPostProcess();\n if (firstPostProcess) {\n firstPostProcess.markTextureDirty();\n }\n // glue the rigPostProcess to the end of the user postprocesses & assign to each sub-camera\n for (let i = 0, len = this._rigCameras.length; i < len; i++) {\n const cam = this._rigCameras[i];\n const rigPostProcess = cam._rigPostProcess;\n // for VR rig, there does not have to be a post process\n if (rigPostProcess) {\n const isPass = rigPostProcess.getEffectName() === \"pass\";\n if (isPass) {\n // any rig which has a PassPostProcess for rig[0], cannot be isIntermediate when there are also user postProcesses\n cam.isIntermediate = this._postProcesses.length === 0;\n }\n cam._postProcesses = this._postProcesses.slice(0).concat(rigPostProcess);\n rigPostProcess.markTextureDirty();\n }\n else {\n cam._postProcesses = this._postProcesses.slice(0);\n }\n }\n }\n /**\n * Attach a post process to the camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses#attach-postprocess\n * @param postProcess The post process to attach to the camera\n * @param insertAt The position of the post process in case several of them are in use in the scene\n * @returns the position the post process has been inserted at\n */\n attachPostProcess(postProcess, insertAt = null) {\n if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {\n Logger.Error(\"You're trying to reuse a post process not defined as reusable.\");\n return 0;\n }\n if (insertAt == null || insertAt < 0) {\n this._postProcesses.push(postProcess);\n }\n else if (this._postProcesses[insertAt] === null) {\n this._postProcesses[insertAt] = postProcess;\n }\n else {\n this._postProcesses.splice(insertAt, 0, postProcess);\n }\n this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated\n // Update prePass\n if (this._scene.prePassRenderer) {\n this._scene.prePassRenderer.markAsDirty();\n }\n return this._postProcesses.indexOf(postProcess);\n }\n /**\n * Detach a post process to the camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses#attach-postprocess\n * @param postProcess The post process to detach from the camera\n */\n detachPostProcess(postProcess) {\n const idx = this._postProcesses.indexOf(postProcess);\n if (idx !== -1) {\n this._postProcesses[idx] = null;\n }\n // Update prePass\n if (this._scene.prePassRenderer) {\n this._scene.prePassRenderer.markAsDirty();\n }\n this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated\n }\n /**\n * Gets the current world matrix of the camera\n */\n getWorldMatrix() {\n if (this._isSynchronizedViewMatrix()) {\n return this._worldMatrix;\n }\n // Getting the the view matrix will also compute the world matrix.\n this.getViewMatrix();\n return this._worldMatrix;\n }\n /** @internal */\n _getViewMatrix() {\n return Matrix.Identity();\n }\n /**\n * Gets the current view matrix of the camera.\n * @param force forces the camera to recompute the matrix without looking at the cached state\n * @returns the view matrix\n */\n getViewMatrix(force) {\n if (!force && this._isSynchronizedViewMatrix()) {\n return this._computedViewMatrix;\n }\n this.updateCache();\n this._computedViewMatrix = this._getViewMatrix();\n this._currentRenderId = this.getScene().getRenderId();\n this._childUpdateId++;\n this._refreshFrustumPlanes = true;\n if (this._cameraRigParams && this._cameraRigParams.vrPreViewMatrix) {\n this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);\n }\n // Notify parent camera if rig camera is changed\n if (this.parent && this.parent.onViewMatrixChangedObservable) {\n this.parent.onViewMatrixChangedObservable.notifyObservers(this.parent);\n }\n this.onViewMatrixChangedObservable.notifyObservers(this);\n this._computedViewMatrix.invertToRef(this._worldMatrix);\n return this._computedViewMatrix;\n }\n /**\n * Freeze the projection matrix.\n * It will prevent the cache check of the camera projection compute and can speed up perf\n * if no parameter of the camera are meant to change\n * @param projection Defines manually a projection if necessary\n */\n freezeProjectionMatrix(projection) {\n this._doNotComputeProjectionMatrix = true;\n if (projection !== undefined) {\n this._projectionMatrix = projection;\n }\n }\n /**\n * Unfreeze the projection matrix if it has previously been freezed by freezeProjectionMatrix.\n */\n unfreezeProjectionMatrix() {\n this._doNotComputeProjectionMatrix = false;\n }\n /**\n * Gets the current projection matrix of the camera.\n * @param force forces the camera to recompute the matrix without looking at the cached state\n * @returns the projection matrix\n */\n getProjectionMatrix(force) {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n if (this._doNotComputeProjectionMatrix || (!force && this._isSynchronizedProjectionMatrix())) {\n return this._projectionMatrix;\n }\n // Cache\n this._cache.mode = this.mode;\n this._cache.minZ = this.minZ;\n this._cache.maxZ = this.maxZ;\n // Matrix\n this._refreshFrustumPlanes = true;\n const engine = this.getEngine();\n const scene = this.getScene();\n const reverseDepth = engine.useReverseDepthBuffer;\n if (this.mode === Camera.PERSPECTIVE_CAMERA) {\n this._cache.fov = this.fov;\n this._cache.fovMode = this.fovMode;\n this._cache.aspectRatio = engine.getAspectRatio(this);\n this._cache.projectionPlaneTilt = this.projectionPlaneTilt;\n if (this.minZ <= 0) {\n this.minZ = 0.1;\n }\n let getProjectionMatrix;\n if (scene.useRightHandedSystem) {\n getProjectionMatrix = Matrix.PerspectiveFovRHToRef;\n }\n else {\n getProjectionMatrix = Matrix.PerspectiveFovLHToRef;\n }\n getProjectionMatrix(this.fov, engine.getAspectRatio(this), reverseDepth ? this.maxZ : this.minZ, reverseDepth ? this.minZ : this.maxZ, this._projectionMatrix, this.fovMode === Camera.FOVMODE_VERTICAL_FIXED, engine.isNDCHalfZRange, this.projectionPlaneTilt, reverseDepth);\n }\n else {\n const halfWidth = engine.getRenderWidth() / 2.0;\n const halfHeight = engine.getRenderHeight() / 2.0;\n if (scene.useRightHandedSystem) {\n Matrix.OrthoOffCenterRHToRef((_a = this.orthoLeft) !== null && _a !== void 0 ? _a : -halfWidth, (_b = this.orthoRight) !== null && _b !== void 0 ? _b : halfWidth, (_c = this.orthoBottom) !== null && _c !== void 0 ? _c : -halfHeight, (_d = this.orthoTop) !== null && _d !== void 0 ? _d : halfHeight, reverseDepth ? this.maxZ : this.minZ, reverseDepth ? this.minZ : this.maxZ, this._projectionMatrix, engine.isNDCHalfZRange);\n }\n else {\n Matrix.OrthoOffCenterLHToRef((_e = this.orthoLeft) !== null && _e !== void 0 ? _e : -halfWidth, (_f = this.orthoRight) !== null && _f !== void 0 ? _f : halfWidth, (_g = this.orthoBottom) !== null && _g !== void 0 ? _g : -halfHeight, (_h = this.orthoTop) !== null && _h !== void 0 ? _h : halfHeight, reverseDepth ? this.maxZ : this.minZ, reverseDepth ? this.minZ : this.maxZ, this._projectionMatrix, engine.isNDCHalfZRange);\n }\n this._cache.orthoLeft = this.orthoLeft;\n this._cache.orthoRight = this.orthoRight;\n this._cache.orthoBottom = this.orthoBottom;\n this._cache.orthoTop = this.orthoTop;\n this._cache.renderWidth = engine.getRenderWidth();\n this._cache.renderHeight = engine.getRenderHeight();\n }\n this.onProjectionMatrixChangedObservable.notifyObservers(this);\n return this._projectionMatrix;\n }\n /**\n * Gets the transformation matrix (ie. the multiplication of view by projection matrices)\n * @returns a Matrix\n */\n getTransformationMatrix() {\n this._computedViewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);\n return this._transformMatrix;\n }\n _updateFrustumPlanes() {\n if (!this._refreshFrustumPlanes) {\n return;\n }\n this.getTransformationMatrix();\n if (!this._frustumPlanes) {\n this._frustumPlanes = Frustum.GetPlanes(this._transformMatrix);\n }\n else {\n Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);\n }\n this._refreshFrustumPlanes = false;\n }\n /**\n * Checks if a cullable object (mesh...) is in the camera frustum\n * This checks the bounding box center. See isCompletelyInFrustum for a full bounding check\n * @param target The object to check\n * @param checkRigCameras If the rig cameras should be checked (eg. with webVR camera both eyes should be checked) (Default: false)\n * @returns true if the object is in frustum otherwise false\n */\n isInFrustum(target, checkRigCameras = false) {\n this._updateFrustumPlanes();\n if (checkRigCameras && this.rigCameras.length > 0) {\n let result = false;\n this.rigCameras.forEach((cam) => {\n cam._updateFrustumPlanes();\n result = result || target.isInFrustum(cam._frustumPlanes);\n });\n return result;\n }\n else {\n return target.isInFrustum(this._frustumPlanes);\n }\n }\n /**\n * Checks if a cullable object (mesh...) is in the camera frustum\n * Unlike isInFrustum this checks the full bounding box\n * @param target The object to check\n * @returns true if the object is in frustum otherwise false\n */\n isCompletelyInFrustum(target) {\n this._updateFrustumPlanes();\n return target.isCompletelyInFrustum(this._frustumPlanes);\n }\n /**\n * Gets a ray in the forward direction from the camera.\n * @param length Defines the length of the ray to create\n * @param transform Defines the transform to apply to the ray, by default the world matrix is used to create a workd space ray\n * @param origin Defines the start point of the ray which defaults to the camera position\n * @returns the forward ray\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getForwardRay(length = 100, transform, origin) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Gets a ray in the forward direction from the camera.\n * @param refRay the ray to (re)use when setting the values\n * @param length Defines the length of the ray to create\n * @param transform Defines the transform to apply to the ray, by default the world matrx is used to create a workd space ray\n * @param origin Defines the start point of the ray which defaults to the camera position\n * @returns the forward ray\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getForwardRayToRef(refRay, length = 100, transform, origin) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Releases resources associated with this node.\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n // Observables\n this.onViewMatrixChangedObservable.clear();\n this.onProjectionMatrixChangedObservable.clear();\n this.onAfterCheckInputsObservable.clear();\n this.onRestoreStateObservable.clear();\n // Inputs\n if (this.inputs) {\n this.inputs.clear();\n }\n // Animations\n this.getScene().stopAnimation(this);\n // Remove from scene\n this.getScene().removeCamera(this);\n while (this._rigCameras.length > 0) {\n const camera = this._rigCameras.pop();\n if (camera) {\n camera.dispose();\n }\n }\n if (this._parentContainer) {\n const index = this._parentContainer.cameras.indexOf(this);\n if (index > -1) {\n this._parentContainer.cameras.splice(index, 1);\n }\n this._parentContainer = null;\n }\n // Postprocesses\n if (this._rigPostProcess) {\n this._rigPostProcess.dispose(this);\n this._rigPostProcess = null;\n this._postProcesses.length = 0;\n }\n else if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\n this._rigPostProcess = null;\n this._postProcesses.length = 0;\n }\n else {\n let i = this._postProcesses.length;\n while (--i >= 0) {\n const postProcess = this._postProcesses[i];\n if (postProcess) {\n postProcess.dispose(this);\n }\n }\n }\n // Render targets\n let i = this.customRenderTargets.length;\n while (--i >= 0) {\n this.customRenderTargets[i].dispose();\n }\n this.customRenderTargets.length = 0;\n // Active Meshes\n this._activeMeshes.dispose();\n this.getScene().getEngine().releaseRenderPassId(this.renderPassId);\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n /**\n * Gets the left camera of a rig setup in case of Rigged Camera\n */\n get isLeftCamera() {\n return this._isLeftCamera;\n }\n /**\n * Gets the right camera of a rig setup in case of Rigged Camera\n */\n get isRightCamera() {\n return this._isRightCamera;\n }\n /**\n * Gets the left camera of a rig setup in case of Rigged Camera\n */\n get leftCamera() {\n if (this._rigCameras.length < 1) {\n return null;\n }\n return this._rigCameras[0];\n }\n /**\n * Gets the right camera of a rig setup in case of Rigged Camera\n */\n get rightCamera() {\n if (this._rigCameras.length < 2) {\n return null;\n }\n return this._rigCameras[1];\n }\n /**\n * Gets the left camera target of a rig setup in case of Rigged Camera\n * @returns the target position\n */\n getLeftTarget() {\n if (this._rigCameras.length < 1) {\n return null;\n }\n return this._rigCameras[0].getTarget();\n }\n /**\n * Gets the right camera target of a rig setup in case of Rigged Camera\n * @returns the target position\n */\n getRightTarget() {\n if (this._rigCameras.length < 2) {\n return null;\n }\n return this._rigCameras[1].getTarget();\n }\n /**\n * @internal\n */\n setCameraRigMode(mode, rigParams) {\n if (this.cameraRigMode === mode) {\n return;\n }\n while (this._rigCameras.length > 0) {\n const camera = this._rigCameras.pop();\n if (camera) {\n camera.dispose();\n }\n }\n this.cameraRigMode = mode;\n this._cameraRigParams = {};\n //we have to implement stereo camera calcultating left and right viewpoints from interaxialDistance and target,\n //not from a given angle as it is now, but until that complete code rewriting provisional stereoHalfAngle value is introduced\n this._cameraRigParams.interaxialDistance = rigParams.interaxialDistance || 0.0637;\n this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(this._cameraRigParams.interaxialDistance / 0.0637);\n // create the rig cameras, unless none\n if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\n const leftCamera = this.createRigCamera(this.name + \"_L\", 0);\n if (leftCamera) {\n leftCamera._isLeftCamera = true;\n }\n const rightCamera = this.createRigCamera(this.name + \"_R\", 1);\n if (rightCamera) {\n rightCamera._isRightCamera = true;\n }\n if (leftCamera && rightCamera) {\n this._rigCameras.push(leftCamera);\n this._rigCameras.push(rightCamera);\n }\n }\n this._setRigMode(rigParams);\n this._cascadePostProcessesToRigCams();\n this.update();\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _setRigMode(rigParams) {\n // no-op\n }\n /** @internal */\n _getVRProjectionMatrix() {\n Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov, this._cameraRigParams.vrMetrics.aspectRatio, this.minZ, this.maxZ, this._cameraRigParams.vrWorkMatrix, true, this.getEngine().isNDCHalfZRange);\n this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix, this._projectionMatrix);\n return this._projectionMatrix;\n }\n _updateCameraRotationMatrix() {\n //Here for WebVR\n }\n _updateWebVRCameraRotationMatrix() {\n //Here for WebVR\n }\n /**\n * This function MUST be overwritten by the different WebVR cameras available.\n * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.\n * @internal\n */\n _getWebVRProjectionMatrix() {\n return Matrix.Identity();\n }\n /**\n * This function MUST be overwritten by the different WebVR cameras available.\n * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.\n * @internal\n */\n _getWebVRViewMatrix() {\n return Matrix.Identity();\n }\n /**\n * @internal\n */\n setCameraRigParameter(name, value) {\n if (!this._cameraRigParams) {\n this._cameraRigParams = {};\n }\n this._cameraRigParams[name] = value;\n //provisionnally:\n if (name === \"interaxialDistance\") {\n this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(value / 0.0637);\n }\n }\n /**\n * needs to be overridden by children so sub has required properties to be copied\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n createRigCamera(name, cameraIndex) {\n return null;\n }\n /**\n * May need to be overridden by children\n * @internal\n */\n _updateRigCameras() {\n for (let i = 0; i < this._rigCameras.length; i++) {\n this._rigCameras[i].minZ = this.minZ;\n this._rigCameras[i].maxZ = this.maxZ;\n this._rigCameras[i].fov = this.fov;\n this._rigCameras[i].upVector.copyFrom(this.upVector);\n }\n // only update viewport when ANAGLYPH\n if (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH) {\n this._rigCameras[0].viewport = this._rigCameras[1].viewport = this.viewport;\n }\n }\n /** @internal */\n _setupInputs() { }\n /**\n * Serialiaze the camera setup to a json representation\n * @returns the JSON representation\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this);\n serializationObject.uniqueId = this.uniqueId;\n // Type\n serializationObject.type = this.getClassName();\n // Parent\n if (this.parent) {\n this.parent._serializeAsParent(serializationObject);\n }\n if (this.inputs) {\n this.inputs.serialize(serializationObject);\n }\n // Animations\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\n serializationObject.ranges = this.serializeAnimationRanges();\n serializationObject.isEnabled = this.isEnabled();\n return serializationObject;\n }\n /**\n * Clones the current camera.\n * @param name The cloned camera name\n * @param newParent The cloned camera's new parent (none by default)\n * @returns the cloned camera\n */\n clone(name, newParent = null) {\n const camera = SerializationHelper.Clone(Camera.GetConstructorFromName(this.getClassName(), name, this.getScene(), this.interaxialDistance, this.isStereoscopicSideBySide), this);\n camera.name = name;\n camera.parent = newParent;\n this.onClonedObservable.notifyObservers(camera);\n return camera;\n }\n /**\n * Gets the direction of the camera relative to a given local axis.\n * @param localAxis Defines the reference axis to provide a relative direction.\n * @returns the direction\n */\n getDirection(localAxis) {\n const result = Vector3.Zero();\n this.getDirectionToRef(localAxis, result);\n return result;\n }\n /**\n * Returns the current camera absolute rotation\n */\n get absoluteRotation() {\n this.getWorldMatrix().decompose(undefined, this._absoluteRotation);\n return this._absoluteRotation;\n }\n /**\n * Gets the direction of the camera relative to a given local axis into a passed vector.\n * @param localAxis Defines the reference axis to provide a relative direction.\n * @param result Defines the vector to store the result in\n */\n getDirectionToRef(localAxis, result) {\n Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);\n }\n /**\n * Gets a camera constructor for a given camera type\n * @param type The type of the camera to construct (should be equal to one of the camera class name)\n * @param name The name of the camera the result will be able to instantiate\n * @param scene The scene the result will construct the camera in\n * @param interaxial_distance In case of stereoscopic setup, the distance between both eyes\n * @param isStereoscopicSideBySide In case of stereoscopic setup, should the sereo be side b side\n * @returns a factory method to construct the camera\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static GetConstructorFromName(type, name, scene, interaxial_distance = 0, isStereoscopicSideBySide = true) {\n const constructorFunc = Node.Construct(type, name, scene, {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interaxial_distance: interaxial_distance,\n isStereoscopicSideBySide: isStereoscopicSideBySide,\n });\n if (constructorFunc) {\n return constructorFunc;\n }\n // Default to universal camera\n return () => Camera._CreateDefaultParsedCamera(name, scene);\n }\n /**\n * Compute the world matrix of the camera.\n * @returns the camera world matrix\n */\n computeWorldMatrix() {\n return this.getWorldMatrix();\n }\n /**\n * Parse a JSON and creates the camera from the parsed information\n * @param parsedCamera The JSON to parse\n * @param scene The scene to instantiate the camera in\n * @returns the newly constructed camera\n */\n static Parse(parsedCamera, scene) {\n const type = parsedCamera.type;\n const construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);\n const camera = SerializationHelper.Parse(construct, parsedCamera, scene);\n // Parent\n if (parsedCamera.parentId !== undefined) {\n camera._waitingParentId = parsedCamera.parentId;\n }\n // Parent instance index\n if (parsedCamera.parentInstanceIndex !== undefined) {\n camera._waitingParentInstanceIndex = parsedCamera.parentInstanceIndex;\n }\n //If camera has an input manager, let it parse inputs settings\n if (camera.inputs) {\n camera.inputs.parse(parsedCamera);\n camera._setupInputs();\n }\n if (parsedCamera.upVector) {\n camera.upVector = Vector3.FromArray(parsedCamera.upVector); // need to force the upVector\n }\n if (camera.setPosition) {\n // need to force position\n camera.position.copyFromFloats(0, 0, 0);\n camera.setPosition(Vector3.FromArray(parsedCamera.position));\n }\n // Target\n if (parsedCamera.target) {\n if (camera.setTarget) {\n camera.setTarget(Vector3.FromArray(parsedCamera.target));\n }\n }\n // Apply 3d rig, when found\n if (parsedCamera.cameraRigMode) {\n const rigParams = parsedCamera.interaxial_distance ? { interaxialDistance: parsedCamera.interaxial_distance } : {};\n camera.setCameraRigMode(parsedCamera.cameraRigMode, rigParams);\n }\n // Animations\n if (parsedCamera.animations) {\n for (let animationIndex = 0; animationIndex < parsedCamera.animations.length; animationIndex++) {\n const parsedAnimation = parsedCamera.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n camera.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n Node.ParseAnimationRanges(camera, parsedCamera, scene);\n }\n if (parsedCamera.autoAnimate) {\n scene.beginAnimation(camera, parsedCamera.autoAnimateFrom, parsedCamera.autoAnimateTo, parsedCamera.autoAnimateLoop, parsedCamera.autoAnimateSpeed || 1.0);\n }\n // Check if isEnabled is defined to be back compatible with prior serialized versions.\n if (parsedCamera.isEnabled !== undefined) {\n camera.setEnabled(parsedCamera.isEnabled);\n }\n return camera;\n }\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Camera._CreateDefaultParsedCamera = (name, scene) => {\n throw _WarnImport(\"UniversalCamera\");\n };\n /**\n * This is the default projection mode used by the cameras.\n * It helps recreating a feeling of perspective and better appreciate depth.\n * This is the best way to simulate real life cameras.\n */\n Camera.PERSPECTIVE_CAMERA = 0;\n /**\n * This helps creating camera with an orthographic mode.\n * Orthographic is commonly used in engineering as a means to produce object specifications that communicate dimensions unambiguously, each line of 1 unit length (cm, meter..whatever) will appear to have the same length everywhere on the drawing. This allows the drafter to dimension only a subset of lines and let the reader know that other lines of that length on the drawing are also that length in reality. Every parallel line in the drawing is also parallel in the object.\n */\n Camera.ORTHOGRAPHIC_CAMERA = 1;\n /**\n * This is the default FOV mode for perspective cameras.\n * This setting aligns the upper and lower bounds of the viewport to the upper and lower bounds of the camera frustum.\n */\n Camera.FOVMODE_VERTICAL_FIXED = 0;\n /**\n * This setting aligns the left and right bounds of the viewport to the left and right bounds of the camera frustum.\n */\n Camera.FOVMODE_HORIZONTAL_FIXED = 1;\n /**\n * This specifies there is no need for a camera rig.\n * Basically only one eye is rendered corresponding to the camera.\n */\n Camera.RIG_MODE_NONE = 0;\n /**\n * Simulates a camera Rig with one blue eye and one red eye.\n * This can be use with 3d blue and red glasses.\n */\n Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH = 10;\n /**\n * Defines that both eyes of the camera will be rendered side by side with a parallel target.\n */\n Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = 11;\n /**\n * Defines that both eyes of the camera will be rendered side by side with a none parallel target.\n */\n Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;\n /**\n * Defines that both eyes of the camera will be rendered over under each other.\n */\n Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;\n /**\n * Defines that both eyes of the camera will be rendered on successive lines interlaced for passive 3d monitors.\n */\n Camera.RIG_MODE_STEREOSCOPIC_INTERLACED = 14;\n /**\n * Defines that both eyes of the camera should be renderered in a VR mode (carbox).\n */\n Camera.RIG_MODE_VR = 20;\n /**\n * Defines that both eyes of the camera should be renderered in a VR mode (webVR).\n */\n Camera.RIG_MODE_WEBVR = 21;\n /**\n * Custom rig mode allowing rig cameras to be populated manually with any number of cameras\n */\n Camera.RIG_MODE_CUSTOM = 22;\n /**\n * Defines if by default attaching controls should prevent the default javascript event to continue.\n */\n Camera.ForceAttachControlToAlwaysPreventDefault = false;\n __decorate$1([\n serializeAsVector3(\"position\")\n ], Camera.prototype, \"_position\", void 0);\n __decorate$1([\n serializeAsVector3(\"upVector\")\n ], Camera.prototype, \"_upVector\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"orthoLeft\", null);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"orthoRight\", null);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"orthoBottom\", null);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"orthoTop\", null);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"fov\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"projectionPlaneTilt\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"minZ\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"maxZ\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"inertia\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"mode\", null);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"layerMask\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"fovMode\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"cameraRigMode\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"interaxialDistance\", void 0);\n __decorate$1([\n serialize()\n ], Camera.prototype, \"isStereoscopicSideBySide\", void 0);\n\n /**\n * This class implement a typical dictionary using a string as key and the generic type T as value.\n * The underlying implementation relies on an associative array to ensure the best performances.\n * The value can be anything including 'null' but except 'undefined'\n */\n class StringDictionary {\n constructor() {\n this._count = 0;\n this._data = {};\n }\n /**\n * This will clear this dictionary and copy the content from the 'source' one.\n * If the T value is a custom object, it won't be copied/cloned, the same object will be used\n * @param source the dictionary to take the content from and copy to this dictionary\n */\n copyFrom(source) {\n this.clear();\n source.forEach((t, v) => this.add(t, v));\n }\n /**\n * Get a value based from its key\n * @param key the given key to get the matching value from\n * @returns the value if found, otherwise undefined is returned\n */\n get(key) {\n const val = this._data[key];\n if (val !== undefined) {\n return val;\n }\n return undefined;\n }\n /**\n * Get a value from its key or add it if it doesn't exist.\n * This method will ensure you that a given key/data will be present in the dictionary.\n * @param key the given key to get the matching value from\n * @param factory the factory that will create the value if the key is not present in the dictionary.\n * The factory will only be invoked if there's no data for the given key.\n * @returns the value corresponding to the key.\n */\n getOrAddWithFactory(key, factory) {\n let val = this.get(key);\n if (val !== undefined) {\n return val;\n }\n val = factory(key);\n if (val) {\n this.add(key, val);\n }\n return val;\n }\n /**\n * Get a value from its key if present in the dictionary otherwise add it\n * @param key the key to get the value from\n * @param val if there's no such key/value pair in the dictionary add it with this value\n * @returns the value corresponding to the key\n */\n getOrAdd(key, val) {\n const curVal = this.get(key);\n if (curVal !== undefined) {\n return curVal;\n }\n this.add(key, val);\n return val;\n }\n /**\n * Check if there's a given key in the dictionary\n * @param key the key to check for\n * @returns true if the key is present, false otherwise\n */\n contains(key) {\n return this._data[key] !== undefined;\n }\n /**\n * Add a new key and its corresponding value\n * @param key the key to add\n * @param value the value corresponding to the key\n * @returns true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary\n */\n add(key, value) {\n if (this._data[key] !== undefined) {\n return false;\n }\n this._data[key] = value;\n ++this._count;\n return true;\n }\n /**\n * Update a specific value associated to a key\n * @param key defines the key to use\n * @param value defines the value to store\n * @returns true if the value was updated (or false if the key was not found)\n */\n set(key, value) {\n if (this._data[key] === undefined) {\n return false;\n }\n this._data[key] = value;\n return true;\n }\n /**\n * Get the element of the given key and remove it from the dictionary\n * @param key defines the key to search\n * @returns the value associated with the key or null if not found\n */\n getAndRemove(key) {\n const val = this.get(key);\n if (val !== undefined) {\n delete this._data[key];\n --this._count;\n return val;\n }\n return null;\n }\n /**\n * Remove a key/value from the dictionary.\n * @param key the key to remove\n * @returns true if the item was successfully deleted, false if no item with such key exist in the dictionary\n */\n remove(key) {\n if (this.contains(key)) {\n delete this._data[key];\n --this._count;\n return true;\n }\n return false;\n }\n /**\n * Clear the whole content of the dictionary\n */\n clear() {\n this._data = {};\n this._count = 0;\n }\n /**\n * Gets the current count\n */\n get count() {\n return this._count;\n }\n /**\n * Execute a callback on each key/val of the dictionary.\n * Note that you can remove any element in this dictionary in the callback implementation\n * @param callback the callback to execute on a given key/value pair\n */\n forEach(callback) {\n for (const cur in this._data) {\n const val = this._data[cur];\n callback(cur, val);\n }\n }\n /**\n * Execute a callback on every occurrence of the dictionary until it returns a valid TRes object.\n * If the callback returns null or undefined the method will iterate to the next key/value pair\n * Note that you can remove any element in this dictionary in the callback implementation\n * @param callback the callback to execute, if it return a valid T instanced object the enumeration will stop and the object will be returned\n * @returns the first item\n */\n first(callback) {\n for (const cur in this._data) {\n const val = this._data[cur];\n const res = callback(cur, val);\n if (res) {\n return res;\n }\n }\n return null;\n }\n }\n\n /**\n * Base class of the scene acting as a container for the different elements composing a scene.\n * This class is dynamically extended by the different components of the scene increasing\n * flexibility and reducing coupling\n */\n class AbstractScene {\n constructor() {\n /**\n * Gets the list of root nodes (ie. nodes with no parent)\n */\n this.rootNodes = new Array();\n /** All of the cameras added to this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\n */\n this.cameras = new Array();\n /**\n * All of the lights added to this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n */\n this.lights = new Array();\n /**\n * All of the (abstract) meshes added to this scene\n */\n this.meshes = new Array();\n /**\n * The list of skeletons added to the scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons\n */\n this.skeletons = new Array();\n /**\n * All of the particle systems added to this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro\n */\n this.particleSystems = new Array();\n /**\n * Gets a list of Animations associated with the scene\n */\n this.animations = [];\n /**\n * All of the animation groups added to this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/groupAnimations\n */\n this.animationGroups = new Array();\n /**\n * All of the multi-materials added to this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\n */\n this.multiMaterials = new Array();\n /**\n * All of the materials added to this scene\n * In the context of a Scene, it is not supposed to be modified manually.\n * Any addition or removal should be done using the addMaterial and removeMaterial Scene methods.\n * Note also that the order of the Material within the array is not significant and might change.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction\n */\n this.materials = new Array();\n /**\n * The list of morph target managers added to the scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph\n */\n this.morphTargetManagers = new Array();\n /**\n * The list of geometries used in the scene.\n */\n this.geometries = new Array();\n /**\n * All of the transform nodes added to this scene\n * In the context of a Scene, it is not supposed to be modified manually.\n * Any addition or removal should be done using the addTransformNode and removeTransformNode Scene methods.\n * Note also that the order of the TransformNode within the array is not significant and might change.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/transform_node\n */\n this.transformNodes = new Array();\n /**\n * ActionManagers available on the scene.\n * @deprecated\n */\n this.actionManagers = new Array();\n /**\n * Textures to keep.\n */\n this.textures = new Array();\n /** @internal */\n this._environmentTexture = null;\n /**\n * The list of postprocesses added to the scene\n */\n this.postProcesses = new Array();\n }\n /**\n * Adds a parser in the list of available ones\n * @param name Defines the name of the parser\n * @param parser Defines the parser to add\n */\n static AddParser(name, parser) {\n this._BabylonFileParsers[name] = parser;\n }\n /**\n * Gets a general parser from the list of available ones\n * @param name Defines the name of the parser\n * @returns the requested parser or null\n */\n static GetParser(name) {\n if (this._BabylonFileParsers[name]) {\n return this._BabylonFileParsers[name];\n }\n return null;\n }\n /**\n * Adds n individual parser in the list of available ones\n * @param name Defines the name of the parser\n * @param parser Defines the parser to add\n */\n static AddIndividualParser(name, parser) {\n this._IndividualBabylonFileParsers[name] = parser;\n }\n /**\n * Gets an individual parser from the list of available ones\n * @param name Defines the name of the parser\n * @returns the requested parser or null\n */\n static GetIndividualParser(name) {\n if (this._IndividualBabylonFileParsers[name]) {\n return this._IndividualBabylonFileParsers[name];\n }\n return null;\n }\n /**\n * Parser json data and populate both a scene and its associated container object\n * @param jsonData Defines the data to parse\n * @param scene Defines the scene to parse the data for\n * @param container Defines the container attached to the parsing sequence\n * @param rootUrl Defines the root url of the data\n */\n static Parse(jsonData, scene, container, rootUrl) {\n for (const parserName in this._BabylonFileParsers) {\n if (Object.prototype.hasOwnProperty.call(this._BabylonFileParsers, parserName)) {\n this._BabylonFileParsers[parserName](jsonData, scene, container, rootUrl);\n }\n }\n }\n /**\n * Texture used in all pbr material as the reflection texture.\n * As in the majority of the scene they are the same (exception for multi room and so on),\n * this is easier to reference from here than from all the materials.\n */\n get environmentTexture() {\n return this._environmentTexture;\n }\n set environmentTexture(value) {\n this._environmentTexture = value;\n }\n /**\n * @returns all meshes, lights, cameras, transformNodes and bones\n */\n getNodes() {\n let nodes = new Array();\n nodes = nodes.concat(this.meshes);\n nodes = nodes.concat(this.lights);\n nodes = nodes.concat(this.cameras);\n nodes = nodes.concat(this.transformNodes); // dummies\n this.skeletons.forEach((skeleton) => (nodes = nodes.concat(skeleton.bones)));\n return nodes;\n }\n }\n /**\n * Stores the list of available parsers in the application.\n */\n AbstractScene._BabylonFileParsers = {};\n /**\n * Stores the list of available individual parsers in the application.\n */\n AbstractScene._IndividualBabylonFileParsers = {};\n\n /**\n * Manages the defines for the Material\n */\n class MaterialDefines {\n /**\n * Creates a new instance\n * @param externalProperties list of external properties to inject into the object\n */\n constructor(externalProperties) {\n /** @internal */\n this._keys = [];\n this._isDirty = true;\n /** @internal */\n this._areLightsDirty = true;\n /** @internal */\n this._areLightsDisposed = false;\n /** @internal */\n this._areAttributesDirty = true;\n /** @internal */\n this._areTexturesDirty = true;\n /** @internal */\n this._areFresnelDirty = true;\n /** @internal */\n this._areMiscDirty = true;\n /** @internal */\n this._arePrePassDirty = true;\n /** @internal */\n this._areImageProcessingDirty = true;\n /** @internal */\n this._normals = false;\n /** @internal */\n this._uvs = false;\n /** @internal */\n this._needNormals = false;\n /** @internal */\n this._needUVs = false;\n this._externalProperties = externalProperties;\n // Initialize External Properties\n if (externalProperties) {\n for (const prop in externalProperties) {\n if (Object.prototype.hasOwnProperty.call(externalProperties, prop)) {\n this._setDefaultValue(prop);\n }\n }\n }\n }\n /**\n * Specifies if the material needs to be re-calculated\n */\n get isDirty() {\n return this._isDirty;\n }\n /**\n * Marks the material to indicate that it has been re-calculated\n */\n markAsProcessed() {\n this._isDirty = false;\n this._areAttributesDirty = false;\n this._areTexturesDirty = false;\n this._areFresnelDirty = false;\n this._areLightsDirty = false;\n this._areLightsDisposed = false;\n this._areMiscDirty = false;\n this._arePrePassDirty = false;\n this._areImageProcessingDirty = false;\n }\n /**\n * Marks the material to indicate that it needs to be re-calculated\n */\n markAsUnprocessed() {\n this._isDirty = true;\n }\n /**\n * Marks the material to indicate all of its defines need to be re-calculated\n */\n markAllAsDirty() {\n this._areTexturesDirty = true;\n this._areAttributesDirty = true;\n this._areLightsDirty = true;\n this._areFresnelDirty = true;\n this._areMiscDirty = true;\n this._arePrePassDirty = false;\n this._areImageProcessingDirty = true;\n this._isDirty = true;\n }\n /**\n * Marks the material to indicate that image processing needs to be re-calculated\n */\n markAsImageProcessingDirty() {\n this._areImageProcessingDirty = true;\n this._isDirty = true;\n }\n /**\n * Marks the material to indicate the lights need to be re-calculated\n * @param disposed Defines whether the light is dirty due to dispose or not\n */\n markAsLightDirty(disposed = false) {\n this._areLightsDirty = true;\n this._areLightsDisposed = this._areLightsDisposed || disposed;\n this._isDirty = true;\n }\n /**\n * Marks the attribute state as changed\n */\n markAsAttributesDirty() {\n this._areAttributesDirty = true;\n this._isDirty = true;\n }\n /**\n * Marks the texture state as changed\n */\n markAsTexturesDirty() {\n this._areTexturesDirty = true;\n this._isDirty = true;\n }\n /**\n * Marks the fresnel state as changed\n */\n markAsFresnelDirty() {\n this._areFresnelDirty = true;\n this._isDirty = true;\n }\n /**\n * Marks the misc state as changed\n */\n markAsMiscDirty() {\n this._areMiscDirty = true;\n this._isDirty = true;\n }\n /**\n * Marks the prepass state as changed\n */\n markAsPrePassDirty() {\n this._arePrePassDirty = true;\n this._isDirty = true;\n }\n /**\n * Rebuilds the material defines\n */\n rebuild() {\n this._keys.length = 0;\n for (const key of Object.keys(this)) {\n if (key[0] === \"_\") {\n continue;\n }\n this._keys.push(key);\n }\n if (this._externalProperties) {\n for (const name in this._externalProperties) {\n if (this._keys.indexOf(name) === -1) {\n this._keys.push(name);\n }\n }\n }\n }\n /**\n * Specifies if two material defines are equal\n * @param other - A material define instance to compare to\n * @returns - Boolean indicating if the material defines are equal (true) or not (false)\n */\n isEqual(other) {\n if (this._keys.length !== other._keys.length) {\n return false;\n }\n for (let index = 0; index < this._keys.length; index++) {\n const prop = this._keys[index];\n if (this[prop] !== other[prop]) {\n return false;\n }\n }\n return true;\n }\n /**\n * Clones this instance's defines to another instance\n * @param other - material defines to clone values to\n */\n cloneTo(other) {\n if (this._keys.length !== other._keys.length) {\n other._keys = this._keys.slice(0);\n }\n for (let index = 0; index < this._keys.length; index++) {\n const prop = this._keys[index];\n other[prop] = this[prop];\n }\n }\n /**\n * Resets the material define values\n */\n reset() {\n this._keys.forEach((prop) => this._setDefaultValue(prop));\n }\n _setDefaultValue(prop) {\n var _a, _b, _c, _d, _e;\n const type = (_c = (_b = (_a = this._externalProperties) === null || _a === void 0 ? void 0 : _a[prop]) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : typeof this[prop];\n const defValue = (_e = (_d = this._externalProperties) === null || _d === void 0 ? void 0 : _d[prop]) === null || _e === void 0 ? void 0 : _e.default;\n switch (type) {\n case \"number\":\n this[prop] = defValue !== null && defValue !== void 0 ? defValue : 0;\n break;\n case \"string\":\n this[prop] = defValue !== null && defValue !== void 0 ? defValue : \"\";\n break;\n default:\n this[prop] = defValue !== null && defValue !== void 0 ? defValue : false;\n break;\n }\n }\n /**\n * Converts the material define values to a string\n * @returns - String of material define information\n */\n toString() {\n let result = \"\";\n for (let index = 0; index < this._keys.length; index++) {\n const prop = this._keys[index];\n const value = this[prop];\n const type = typeof value;\n switch (type) {\n case \"number\":\n case \"string\":\n result += \"#define \" + prop + \" \" + value + \"\\n\";\n break;\n default:\n if (value) {\n result += \"#define \" + prop + \"\\n\";\n }\n break;\n }\n }\n return result;\n }\n }\n\n /**\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n class ColorCurves {\n constructor() {\n this._dirty = true;\n this._tempColor = new Color4(0, 0, 0, 0);\n this._globalCurve = new Color4(0, 0, 0, 0);\n this._highlightsCurve = new Color4(0, 0, 0, 0);\n this._midtonesCurve = new Color4(0, 0, 0, 0);\n this._shadowsCurve = new Color4(0, 0, 0, 0);\n this._positiveCurve = new Color4(0, 0, 0, 0);\n this._negativeCurve = new Color4(0, 0, 0, 0);\n this._globalHue = 30;\n this._globalDensity = 0;\n this._globalSaturation = 0;\n this._globalExposure = 0;\n this._highlightsHue = 30;\n this._highlightsDensity = 0;\n this._highlightsSaturation = 0;\n this._highlightsExposure = 0;\n this._midtonesHue = 30;\n this._midtonesDensity = 0;\n this._midtonesSaturation = 0;\n this._midtonesExposure = 0;\n this._shadowsHue = 30;\n this._shadowsDensity = 0;\n this._shadowsSaturation = 0;\n this._shadowsExposure = 0;\n }\n /**\n * Gets the global Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n get globalHue() {\n return this._globalHue;\n }\n /**\n * Sets the global Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n set globalHue(value) {\n this._globalHue = value;\n this._dirty = true;\n }\n /**\n * Gets the global Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n get globalDensity() {\n return this._globalDensity;\n }\n /**\n * Sets the global Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n set globalDensity(value) {\n this._globalDensity = value;\n this._dirty = true;\n }\n /**\n * Gets the global Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n get globalSaturation() {\n return this._globalSaturation;\n }\n /**\n * Sets the global Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n set globalSaturation(value) {\n this._globalSaturation = value;\n this._dirty = true;\n }\n /**\n * Gets the global Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n get globalExposure() {\n return this._globalExposure;\n }\n /**\n * Sets the global Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n set globalExposure(value) {\n this._globalExposure = value;\n this._dirty = true;\n }\n /**\n * Gets the highlights Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n get highlightsHue() {\n return this._highlightsHue;\n }\n /**\n * Sets the highlights Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n set highlightsHue(value) {\n this._highlightsHue = value;\n this._dirty = true;\n }\n /**\n * Gets the highlights Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n get highlightsDensity() {\n return this._highlightsDensity;\n }\n /**\n * Sets the highlights Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n set highlightsDensity(value) {\n this._highlightsDensity = value;\n this._dirty = true;\n }\n /**\n * Gets the highlights Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n get highlightsSaturation() {\n return this._highlightsSaturation;\n }\n /**\n * Sets the highlights Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n set highlightsSaturation(value) {\n this._highlightsSaturation = value;\n this._dirty = true;\n }\n /**\n * Gets the highlights Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n get highlightsExposure() {\n return this._highlightsExposure;\n }\n /**\n * Sets the highlights Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n set highlightsExposure(value) {\n this._highlightsExposure = value;\n this._dirty = true;\n }\n /**\n * Gets the midtones Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n get midtonesHue() {\n return this._midtonesHue;\n }\n /**\n * Sets the midtones Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n set midtonesHue(value) {\n this._midtonesHue = value;\n this._dirty = true;\n }\n /**\n * Gets the midtones Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n get midtonesDensity() {\n return this._midtonesDensity;\n }\n /**\n * Sets the midtones Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n set midtonesDensity(value) {\n this._midtonesDensity = value;\n this._dirty = true;\n }\n /**\n * Gets the midtones Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n get midtonesSaturation() {\n return this._midtonesSaturation;\n }\n /**\n * Sets the midtones Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n set midtonesSaturation(value) {\n this._midtonesSaturation = value;\n this._dirty = true;\n }\n /**\n * Gets the midtones Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n get midtonesExposure() {\n return this._midtonesExposure;\n }\n /**\n * Sets the midtones Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n set midtonesExposure(value) {\n this._midtonesExposure = value;\n this._dirty = true;\n }\n /**\n * Gets the shadows Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n get shadowsHue() {\n return this._shadowsHue;\n }\n /**\n * Sets the shadows Hue value.\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\n */\n set shadowsHue(value) {\n this._shadowsHue = value;\n this._dirty = true;\n }\n /**\n * Gets the shadows Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n get shadowsDensity() {\n return this._shadowsDensity;\n }\n /**\n * Sets the shadows Density value.\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\n * Values less than zero provide a filter of opposite hue.\n */\n set shadowsDensity(value) {\n this._shadowsDensity = value;\n this._dirty = true;\n }\n /**\n * Gets the shadows Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n get shadowsSaturation() {\n return this._shadowsSaturation;\n }\n /**\n * Sets the shadows Saturation value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\n */\n set shadowsSaturation(value) {\n this._shadowsSaturation = value;\n this._dirty = true;\n }\n /**\n * Gets the shadows Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n get shadowsExposure() {\n return this._shadowsExposure;\n }\n /**\n * Sets the shadows Exposure value.\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\n */\n set shadowsExposure(value) {\n this._shadowsExposure = value;\n this._dirty = true;\n }\n /**\n * Returns the class name\n * @returns The class name\n */\n getClassName() {\n return \"ColorCurves\";\n }\n /**\n * Binds the color curves to the shader.\n * @param colorCurves The color curve to bind\n * @param effect The effect to bind to\n * @param positiveUniform The positive uniform shader parameter\n * @param neutralUniform The neutral uniform shader parameter\n * @param negativeUniform The negative uniform shader parameter\n */\n static Bind(colorCurves, effect, positiveUniform = \"vCameraColorCurvePositive\", neutralUniform = \"vCameraColorCurveNeutral\", negativeUniform = \"vCameraColorCurveNegative\") {\n if (colorCurves._dirty) {\n colorCurves._dirty = false;\n // Fill in global info.\n colorCurves._getColorGradingDataToRef(colorCurves._globalHue, colorCurves._globalDensity, colorCurves._globalSaturation, colorCurves._globalExposure, colorCurves._globalCurve);\n // Compute highlights info.\n colorCurves._getColorGradingDataToRef(colorCurves._highlightsHue, colorCurves._highlightsDensity, colorCurves._highlightsSaturation, colorCurves._highlightsExposure, colorCurves._tempColor);\n colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._highlightsCurve);\n // Compute midtones info.\n colorCurves._getColorGradingDataToRef(colorCurves._midtonesHue, colorCurves._midtonesDensity, colorCurves._midtonesSaturation, colorCurves._midtonesExposure, colorCurves._tempColor);\n colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._midtonesCurve);\n // Compute shadows info.\n colorCurves._getColorGradingDataToRef(colorCurves._shadowsHue, colorCurves._shadowsDensity, colorCurves._shadowsSaturation, colorCurves._shadowsExposure, colorCurves._tempColor);\n colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._shadowsCurve);\n // Compute deltas (neutral is midtones).\n colorCurves._highlightsCurve.subtractToRef(colorCurves._midtonesCurve, colorCurves._positiveCurve);\n colorCurves._midtonesCurve.subtractToRef(colorCurves._shadowsCurve, colorCurves._negativeCurve);\n }\n if (effect) {\n effect.setFloat4(positiveUniform, colorCurves._positiveCurve.r, colorCurves._positiveCurve.g, colorCurves._positiveCurve.b, colorCurves._positiveCurve.a);\n effect.setFloat4(neutralUniform, colorCurves._midtonesCurve.r, colorCurves._midtonesCurve.g, colorCurves._midtonesCurve.b, colorCurves._midtonesCurve.a);\n effect.setFloat4(negativeUniform, colorCurves._negativeCurve.r, colorCurves._negativeCurve.g, colorCurves._negativeCurve.b, colorCurves._negativeCurve.a);\n }\n }\n /**\n * Prepare the list of uniforms associated with the ColorCurves effects.\n * @param uniformsList The list of uniforms used in the effect\n */\n static PrepareUniforms(uniformsList) {\n uniformsList.push(\"vCameraColorCurveNeutral\", \"vCameraColorCurvePositive\", \"vCameraColorCurveNegative\");\n }\n /**\n * Returns color grading data based on a hue, density, saturation and exposure value.\n * @param hue\n * @param density\n * @param saturation The saturation.\n * @param exposure The exposure.\n * @param result The result data container.\n */\n _getColorGradingDataToRef(hue, density, saturation, exposure, result) {\n if (hue == null) {\n return;\n }\n hue = ColorCurves._Clamp(hue, 0, 360);\n density = ColorCurves._Clamp(density, -100, 100);\n saturation = ColorCurves._Clamp(saturation, -100, 100);\n exposure = ColorCurves._Clamp(exposure, -100, 100);\n // Remap the slider/config filter density with non-linear mapping and also scale by half\n // so that the maximum filter density is only 50% control. This provides fine control\n // for small values and reasonable range.\n density = ColorCurves._ApplyColorGradingSliderNonlinear(density);\n density *= 0.5;\n exposure = ColorCurves._ApplyColorGradingSliderNonlinear(exposure);\n if (density < 0) {\n density *= -1;\n hue = (hue + 180) % 360;\n }\n ColorCurves._FromHSBToRef(hue, density, 50 + 0.25 * exposure, result);\n result.scaleToRef(2, result);\n result.a = 1 + 0.01 * saturation;\n }\n /**\n * Takes an input slider value and returns an adjusted value that provides extra control near the centre.\n * @param value The input slider value in range [-100,100].\n * @returns Adjusted value.\n */\n static _ApplyColorGradingSliderNonlinear(value) {\n value /= 100;\n let x = Math.abs(value);\n x = Math.pow(x, 2);\n if (value < 0) {\n x *= -1;\n }\n x *= 100;\n return x;\n }\n /**\n * Returns an RGBA Color4 based on Hue, Saturation and Brightness (also referred to as value, HSV).\n * @param hue The hue (H) input.\n * @param saturation The saturation (S) input.\n * @param brightness The brightness (B) input.\n * @param result\n * @result An RGBA color represented as Vector4.\n */\n static _FromHSBToRef(hue, saturation, brightness, result) {\n let h = ColorCurves._Clamp(hue, 0, 360);\n const s = ColorCurves._Clamp(saturation / 100, 0, 1);\n const v = ColorCurves._Clamp(brightness / 100, 0, 1);\n if (s === 0) {\n result.r = v;\n result.g = v;\n result.b = v;\n }\n else {\n // sector 0 to 5\n h /= 60;\n const i = Math.floor(h);\n // fractional part of h\n const f = h - i;\n const p = v * (1 - s);\n const q = v * (1 - s * f);\n const t = v * (1 - s * (1 - f));\n switch (i) {\n case 0:\n result.r = v;\n result.g = t;\n result.b = p;\n break;\n case 1:\n result.r = q;\n result.g = v;\n result.b = p;\n break;\n case 2:\n result.r = p;\n result.g = v;\n result.b = t;\n break;\n case 3:\n result.r = p;\n result.g = q;\n result.b = v;\n break;\n case 4:\n result.r = t;\n result.g = p;\n result.b = v;\n break;\n default:\n // case 5:\n result.r = v;\n result.g = p;\n result.b = q;\n break;\n }\n }\n result.a = 1;\n }\n /**\n * Returns a value clamped between min and max\n * @param value The value to clamp\n * @param min The minimum of value\n * @param max The maximum of value\n * @returns The clamped value.\n */\n static _Clamp(value, min, max) {\n return Math.min(Math.max(value, min), max);\n }\n /**\n * Clones the current color curve instance.\n * @returns The cloned curves\n */\n clone() {\n return SerializationHelper.Clone(() => new ColorCurves(), this);\n }\n /**\n * Serializes the current color curve instance to a json representation.\n * @returns a JSON representation\n */\n serialize() {\n return SerializationHelper.Serialize(this);\n }\n /**\n * Parses the color curve from a json representation.\n * @param source the JSON source to parse\n * @returns The parsed curves\n */\n static Parse(source) {\n return SerializationHelper.Parse(() => new ColorCurves(), source, null, null);\n }\n }\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_globalHue\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_globalDensity\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_globalSaturation\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_globalExposure\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_highlightsHue\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_highlightsDensity\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_highlightsSaturation\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_highlightsExposure\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_midtonesHue\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_midtonesDensity\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_midtonesSaturation\", void 0);\n __decorate$1([\n serialize()\n ], ColorCurves.prototype, \"_midtonesExposure\", void 0);\n // References the dependencies.\n SerializationHelper._ColorCurvesParser = ColorCurves.Parse;\n\n /**\n * @internal\n */\n class ImageProcessingConfigurationDefines extends MaterialDefines {\n constructor() {\n super();\n this.IMAGEPROCESSING = false;\n this.VIGNETTE = false;\n this.VIGNETTEBLENDMODEMULTIPLY = false;\n this.VIGNETTEBLENDMODEOPAQUE = false;\n this.TONEMAPPING = false;\n this.TONEMAPPING_ACES = false;\n this.CONTRAST = false;\n this.COLORCURVES = false;\n this.COLORGRADING = false;\n this.COLORGRADING3D = false;\n this.SAMPLER3DGREENDEPTH = false;\n this.SAMPLER3DBGRMAP = false;\n this.DITHER = false;\n this.IMAGEPROCESSINGPOSTPROCESS = false;\n this.EXPOSURE = false;\n this.SKIPFINALCOLORCLAMP = false;\n this.rebuild();\n }\n }\n /**\n * This groups together the common properties used for image processing either in direct forward pass\n * or through post processing effect depending on the use of the image processing pipeline in your scene\n * or not.\n */\n class ImageProcessingConfiguration {\n constructor() {\n /**\n * Color curves setup used in the effect if colorCurvesEnabled is set to true\n */\n this.colorCurves = new ColorCurves();\n this._colorCurvesEnabled = false;\n this._colorGradingEnabled = false;\n this._colorGradingWithGreenDepth = true;\n this._colorGradingBGR = true;\n /** @internal */\n this._exposure = 1.0;\n this._toneMappingEnabled = false;\n this._toneMappingType = ImageProcessingConfiguration.TONEMAPPING_STANDARD;\n this._contrast = 1.0;\n /**\n * Vignette stretch size.\n */\n this.vignetteStretch = 0;\n /**\n * Vignette center X Offset.\n */\n this.vignetteCenterX = 0;\n /**\n * Vignette center Y Offset.\n */\n this.vignetteCenterY = 0;\n /**\n * Vignette weight or intensity of the vignette effect.\n */\n this.vignetteWeight = 1.5;\n /**\n * Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)\n * if vignetteEnabled is set to true.\n */\n this.vignetteColor = new Color4(0, 0, 0, 0);\n /**\n * Camera field of view used by the Vignette effect.\n */\n this.vignetteCameraFov = 0.5;\n this._vignetteBlendMode = ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;\n this._vignetteEnabled = false;\n this._ditheringEnabled = false;\n this._ditheringIntensity = 1.0 / 255.0;\n /** @internal */\n this._skipFinalColorClamp = false;\n /** @internal */\n this._applyByPostProcess = false;\n this._isEnabled = true;\n /**\n * An event triggered when the configuration changes and requires Shader to Update some parameters.\n */\n this.onUpdateParameters = new Observable$1();\n }\n /**\n * Gets whether the color curves effect is enabled.\n */\n get colorCurvesEnabled() {\n return this._colorCurvesEnabled;\n }\n /**\n * Sets whether the color curves effect is enabled.\n */\n set colorCurvesEnabled(value) {\n if (this._colorCurvesEnabled === value) {\n return;\n }\n this._colorCurvesEnabled = value;\n this._updateParameters();\n }\n /**\n * Color grading LUT texture used in the effect if colorGradingEnabled is set to true\n */\n get colorGradingTexture() {\n return this._colorGradingTexture;\n }\n /**\n * Color grading LUT texture used in the effect if colorGradingEnabled is set to true\n */\n set colorGradingTexture(value) {\n if (this._colorGradingTexture === value) {\n return;\n }\n this._colorGradingTexture = value;\n this._updateParameters();\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n get colorGradingEnabled() {\n return this._colorGradingEnabled;\n }\n /**\n * Sets whether the color grading effect is enabled.\n */\n set colorGradingEnabled(value) {\n if (this._colorGradingEnabled === value) {\n return;\n }\n this._colorGradingEnabled = value;\n this._updateParameters();\n }\n /**\n * Gets whether the color grading effect is using a green depth for the 3d Texture.\n */\n get colorGradingWithGreenDepth() {\n return this._colorGradingWithGreenDepth;\n }\n /**\n * Sets whether the color grading effect is using a green depth for the 3d Texture.\n */\n set colorGradingWithGreenDepth(value) {\n if (this._colorGradingWithGreenDepth === value) {\n return;\n }\n this._colorGradingWithGreenDepth = value;\n this._updateParameters();\n }\n /**\n * Gets whether the color grading texture contains BGR values.\n */\n get colorGradingBGR() {\n return this._colorGradingBGR;\n }\n /**\n * Sets whether the color grading texture contains BGR values.\n */\n set colorGradingBGR(value) {\n if (this._colorGradingBGR === value) {\n return;\n }\n this._colorGradingBGR = value;\n this._updateParameters();\n }\n /**\n * Gets the Exposure used in the effect.\n */\n get exposure() {\n return this._exposure;\n }\n /**\n * Sets the Exposure used in the effect.\n */\n set exposure(value) {\n if (this._exposure === value) {\n return;\n }\n this._exposure = value;\n this._updateParameters();\n }\n /**\n * Gets whether the tone mapping effect is enabled.\n */\n get toneMappingEnabled() {\n return this._toneMappingEnabled;\n }\n /**\n * Sets whether the tone mapping effect is enabled.\n */\n set toneMappingEnabled(value) {\n if (this._toneMappingEnabled === value) {\n return;\n }\n this._toneMappingEnabled = value;\n this._updateParameters();\n }\n /**\n * Gets the type of tone mapping effect.\n */\n get toneMappingType() {\n return this._toneMappingType;\n }\n /**\n * Sets the type of tone mapping effect used in BabylonJS.\n */\n set toneMappingType(value) {\n if (this._toneMappingType === value) {\n return;\n }\n this._toneMappingType = value;\n this._updateParameters();\n }\n /**\n * Gets the contrast used in the effect.\n */\n get contrast() {\n return this._contrast;\n }\n /**\n * Sets the contrast used in the effect.\n */\n set contrast(value) {\n if (this._contrast === value) {\n return;\n }\n this._contrast = value;\n this._updateParameters();\n }\n /**\n * Back Compat: Vignette center Y Offset.\n * @deprecated use vignetteCenterY instead\n */\n get vignetteCentreY() {\n return this.vignetteCenterY;\n }\n set vignetteCentreY(value) {\n this.vignetteCenterY = value;\n }\n /**\n * Back Compat: Vignette center X Offset.\n * @deprecated use vignetteCenterX instead\n */\n get vignetteCentreX() {\n return this.vignetteCenterX;\n }\n set vignetteCentreX(value) {\n this.vignetteCenterX = value;\n }\n /**\n * Gets the vignette blend mode allowing different kind of effect.\n */\n get vignetteBlendMode() {\n return this._vignetteBlendMode;\n }\n /**\n * Sets the vignette blend mode allowing different kind of effect.\n */\n set vignetteBlendMode(value) {\n if (this._vignetteBlendMode === value) {\n return;\n }\n this._vignetteBlendMode = value;\n this._updateParameters();\n }\n /**\n * Gets whether the vignette effect is enabled.\n */\n get vignetteEnabled() {\n return this._vignetteEnabled;\n }\n /**\n * Sets whether the vignette effect is enabled.\n */\n set vignetteEnabled(value) {\n if (this._vignetteEnabled === value) {\n return;\n }\n this._vignetteEnabled = value;\n this._updateParameters();\n }\n /**\n * Gets whether the dithering effect is enabled.\n * The dithering effect can be used to reduce banding.\n */\n get ditheringEnabled() {\n return this._ditheringEnabled;\n }\n /**\n * Sets whether the dithering effect is enabled.\n * The dithering effect can be used to reduce banding.\n */\n set ditheringEnabled(value) {\n if (this._ditheringEnabled === value) {\n return;\n }\n this._ditheringEnabled = value;\n this._updateParameters();\n }\n /**\n * Gets the dithering intensity. 0 is no dithering. Default is 1.0 / 255.0.\n */\n get ditheringIntensity() {\n return this._ditheringIntensity;\n }\n /**\n * Sets the dithering intensity. 0 is no dithering. Default is 1.0 / 255.0.\n */\n set ditheringIntensity(value) {\n if (this._ditheringIntensity === value) {\n return;\n }\n this._ditheringIntensity = value;\n this._updateParameters();\n }\n /**\n * If apply by post process is set to true, setting this to true will skip the the final color clamp step in the fragment shader\n * Applies to PBR materials.\n */\n get skipFinalColorClamp() {\n return this._skipFinalColorClamp;\n }\n /**\n * If apply by post process is set to true, setting this to true will skip the the final color clamp step in the fragment shader\n * Applies to PBR materials.\n */\n set skipFinalColorClamp(value) {\n if (this._skipFinalColorClamp === value) {\n return;\n }\n this._skipFinalColorClamp = value;\n this._updateParameters();\n }\n /**\n * Gets whether the image processing is applied through a post process or not.\n */\n get applyByPostProcess() {\n return this._applyByPostProcess;\n }\n /**\n * Sets whether the image processing is applied through a post process or not.\n */\n set applyByPostProcess(value) {\n if (this._applyByPostProcess === value) {\n return;\n }\n this._applyByPostProcess = value;\n this._updateParameters();\n }\n /**\n * Gets whether the image processing is enabled or not.\n */\n get isEnabled() {\n return this._isEnabled;\n }\n /**\n * Sets whether the image processing is enabled or not.\n */\n set isEnabled(value) {\n if (this._isEnabled === value) {\n return;\n }\n this._isEnabled = value;\n this._updateParameters();\n }\n /**\n * Method called each time the image processing information changes requires to recompile the effect.\n */\n _updateParameters() {\n this.onUpdateParameters.notifyObservers(this);\n }\n /**\n * Gets the current class name.\n * @returns \"ImageProcessingConfiguration\"\n */\n getClassName() {\n return \"ImageProcessingConfiguration\";\n }\n /**\n * Prepare the list of uniforms associated with the Image Processing effects.\n * @param uniforms The list of uniforms used in the effect\n * @param defines the list of defines currently in use\n */\n static PrepareUniforms(uniforms, defines) {\n if (defines.EXPOSURE) {\n uniforms.push(\"exposureLinear\");\n }\n if (defines.CONTRAST) {\n uniforms.push(\"contrast\");\n }\n if (defines.COLORGRADING) {\n uniforms.push(\"colorTransformSettings\");\n }\n if (defines.VIGNETTE || defines.DITHER) {\n uniforms.push(\"vInverseScreenSize\");\n }\n if (defines.VIGNETTE) {\n uniforms.push(\"vignetteSettings1\");\n uniforms.push(\"vignetteSettings2\");\n }\n if (defines.COLORCURVES) {\n ColorCurves.PrepareUniforms(uniforms);\n }\n if (defines.DITHER) {\n uniforms.push(\"ditherIntensity\");\n }\n }\n /**\n * Prepare the list of samplers associated with the Image Processing effects.\n * @param samplersList The list of uniforms used in the effect\n * @param defines the list of defines currently in use\n */\n static PrepareSamplers(samplersList, defines) {\n if (defines.COLORGRADING) {\n samplersList.push(\"txColorTransform\");\n }\n }\n /**\n * Prepare the list of defines associated to the shader.\n * @param defines the list of defines to complete\n * @param forPostProcess Define if we are currently in post process mode or not\n */\n prepareDefines(defines, forPostProcess = false) {\n if (forPostProcess !== this.applyByPostProcess || !this._isEnabled) {\n defines.VIGNETTE = false;\n defines.TONEMAPPING = false;\n defines.TONEMAPPING_ACES = false;\n defines.CONTRAST = false;\n defines.EXPOSURE = false;\n defines.COLORCURVES = false;\n defines.COLORGRADING = false;\n defines.COLORGRADING3D = false;\n defines.DITHER = false;\n defines.IMAGEPROCESSING = false;\n defines.SKIPFINALCOLORCLAMP = this.skipFinalColorClamp;\n defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess && this._isEnabled;\n return;\n }\n defines.VIGNETTE = this.vignetteEnabled;\n defines.VIGNETTEBLENDMODEMULTIPLY = this.vignetteBlendMode === ImageProcessingConfiguration._VIGNETTEMODE_MULTIPLY;\n defines.VIGNETTEBLENDMODEOPAQUE = !defines.VIGNETTEBLENDMODEMULTIPLY;\n defines.TONEMAPPING = this.toneMappingEnabled;\n switch (this._toneMappingType) {\n case ImageProcessingConfiguration.TONEMAPPING_ACES:\n defines.TONEMAPPING_ACES = true;\n break;\n default:\n defines.TONEMAPPING_ACES = false;\n break;\n }\n defines.CONTRAST = this.contrast !== 1.0;\n defines.EXPOSURE = this.exposure !== 1.0;\n defines.COLORCURVES = this.colorCurvesEnabled && !!this.colorCurves;\n defines.COLORGRADING = this.colorGradingEnabled && !!this.colorGradingTexture;\n if (defines.COLORGRADING) {\n defines.COLORGRADING3D = this.colorGradingTexture.is3D;\n }\n else {\n defines.COLORGRADING3D = false;\n }\n defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;\n defines.SAMPLER3DBGRMAP = this.colorGradingBGR;\n defines.DITHER = this._ditheringEnabled;\n defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;\n defines.SKIPFINALCOLORCLAMP = this.skipFinalColorClamp;\n defines.IMAGEPROCESSING = defines.VIGNETTE || defines.TONEMAPPING || defines.CONTRAST || defines.EXPOSURE || defines.COLORCURVES || defines.COLORGRADING || defines.DITHER;\n }\n /**\n * Returns true if all the image processing information are ready.\n * @returns True if ready, otherwise, false\n */\n isReady() {\n // Color Grading texture can not be none blocking.\n return !this.colorGradingEnabled || !this.colorGradingTexture || this.colorGradingTexture.isReady();\n }\n /**\n * Binds the image processing to the shader.\n * @param effect The effect to bind to\n * @param overrideAspectRatio Override the aspect ratio of the effect\n */\n bind(effect, overrideAspectRatio) {\n // Color Curves\n if (this._colorCurvesEnabled && this.colorCurves) {\n ColorCurves.Bind(this.colorCurves, effect);\n }\n // Vignette and dither handled together due to common uniform.\n if (this._vignetteEnabled || this._ditheringEnabled) {\n const inverseWidth = 1 / effect.getEngine().getRenderWidth();\n const inverseHeight = 1 / effect.getEngine().getRenderHeight();\n effect.setFloat2(\"vInverseScreenSize\", inverseWidth, inverseHeight);\n if (this._ditheringEnabled) {\n effect.setFloat(\"ditherIntensity\", 0.5 * this._ditheringIntensity);\n }\n if (this._vignetteEnabled) {\n const aspectRatio = overrideAspectRatio != null ? overrideAspectRatio : inverseHeight / inverseWidth;\n let vignetteScaleY = Math.tan(this.vignetteCameraFov * 0.5);\n let vignetteScaleX = vignetteScaleY * aspectRatio;\n const vignetteScaleGeometricMean = Math.sqrt(vignetteScaleX * vignetteScaleY);\n vignetteScaleX = Tools.Mix(vignetteScaleX, vignetteScaleGeometricMean, this.vignetteStretch);\n vignetteScaleY = Tools.Mix(vignetteScaleY, vignetteScaleGeometricMean, this.vignetteStretch);\n effect.setFloat4(\"vignetteSettings1\", vignetteScaleX, vignetteScaleY, -vignetteScaleX * this.vignetteCenterX, -vignetteScaleY * this.vignetteCenterY);\n const vignettePower = -2.0 * this.vignetteWeight;\n effect.setFloat4(\"vignetteSettings2\", this.vignetteColor.r, this.vignetteColor.g, this.vignetteColor.b, vignettePower);\n }\n }\n // Exposure\n effect.setFloat(\"exposureLinear\", this.exposure);\n // Contrast\n effect.setFloat(\"contrast\", this.contrast);\n // Color transform settings\n if (this.colorGradingTexture) {\n effect.setTexture(\"txColorTransform\", this.colorGradingTexture);\n const textureSize = this.colorGradingTexture.getSize().height;\n effect.setFloat4(\"colorTransformSettings\", (textureSize - 1) / textureSize, // textureScale\n 0.5 / textureSize, // textureOffset\n textureSize, // textureSize\n this.colorGradingTexture.level // weight\n );\n }\n }\n /**\n * Clones the current image processing instance.\n * @returns The cloned image processing\n */\n clone() {\n return SerializationHelper.Clone(() => new ImageProcessingConfiguration(), this);\n }\n /**\n * Serializes the current image processing instance to a json representation.\n * @returns a JSON representation\n */\n serialize() {\n return SerializationHelper.Serialize(this);\n }\n /**\n * Parses the image processing from a json representation.\n * @param source the JSON source to parse\n * @returns The parsed image processing\n */\n static Parse(source) {\n const parsed = SerializationHelper.Parse(() => new ImageProcessingConfiguration(), source, null, null);\n // Backward compatibility\n if (source.vignetteCentreX !== undefined) {\n parsed.vignetteCenterX = source.vignetteCentreX;\n }\n if (source.vignetteCentreY !== undefined) {\n parsed.vignetteCenterY = source.vignetteCentreY;\n }\n return parsed;\n }\n /**\n * Used to apply the vignette as a mix with the pixel color.\n */\n static get VIGNETTEMODE_MULTIPLY() {\n return this._VIGNETTEMODE_MULTIPLY;\n }\n /**\n * Used to apply the vignette as a replacement of the pixel color.\n */\n static get VIGNETTEMODE_OPAQUE() {\n return this._VIGNETTEMODE_OPAQUE;\n }\n }\n /**\n * Default tone mapping applied in BabylonJS.\n */\n ImageProcessingConfiguration.TONEMAPPING_STANDARD = 0;\n /**\n * ACES Tone mapping (used by default in unreal and unity). This can help getting closer\n * to other engines rendering to increase portability.\n */\n ImageProcessingConfiguration.TONEMAPPING_ACES = 1;\n // Static constants associated to the image processing.\n ImageProcessingConfiguration._VIGNETTEMODE_MULTIPLY = 0;\n ImageProcessingConfiguration._VIGNETTEMODE_OPAQUE = 1;\n __decorate$1([\n serializeAsColorCurves()\n ], ImageProcessingConfiguration.prototype, \"colorCurves\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_colorCurvesEnabled\", void 0);\n __decorate$1([\n serializeAsTexture(\"colorGradingTexture\")\n ], ImageProcessingConfiguration.prototype, \"_colorGradingTexture\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_colorGradingEnabled\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_colorGradingWithGreenDepth\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_colorGradingBGR\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_exposure\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_toneMappingEnabled\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_toneMappingType\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_contrast\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"vignetteStretch\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"vignetteCenterX\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"vignetteCenterY\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"vignetteWeight\", void 0);\n __decorate$1([\n serializeAsColor4()\n ], ImageProcessingConfiguration.prototype, \"vignetteColor\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"vignetteCameraFov\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_vignetteBlendMode\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_vignetteEnabled\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_ditheringEnabled\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_ditheringIntensity\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_skipFinalColorClamp\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_applyByPostProcess\", void 0);\n __decorate$1([\n serialize()\n ], ImageProcessingConfiguration.prototype, \"_isEnabled\", void 0);\n // References the dependencies.\n SerializationHelper._ImageProcessingConfigurationParser = ImageProcessingConfiguration.Parse;\n\n ThinEngine.prototype.createUniformBuffer = function (elements) {\n const ubo = this._gl.createBuffer();\n if (!ubo) {\n throw new Error(\"Unable to create uniform buffer\");\n }\n const result = new WebGLDataBuffer(ubo);\n this.bindUniformBuffer(result);\n if (elements instanceof Float32Array) {\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, elements, this._gl.STATIC_DRAW);\n }\n else {\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(elements), this._gl.STATIC_DRAW);\n }\n this.bindUniformBuffer(null);\n result.references = 1;\n return result;\n };\n ThinEngine.prototype.createDynamicUniformBuffer = function (elements) {\n const ubo = this._gl.createBuffer();\n if (!ubo) {\n throw new Error(\"Unable to create dynamic uniform buffer\");\n }\n const result = new WebGLDataBuffer(ubo);\n this.bindUniformBuffer(result);\n if (elements instanceof Float32Array) {\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, elements, this._gl.DYNAMIC_DRAW);\n }\n else {\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(elements), this._gl.DYNAMIC_DRAW);\n }\n this.bindUniformBuffer(null);\n result.references = 1;\n return result;\n };\n ThinEngine.prototype.updateUniformBuffer = function (uniformBuffer, elements, offset, count) {\n this.bindUniformBuffer(uniformBuffer);\n if (offset === undefined) {\n offset = 0;\n }\n if (count === undefined) {\n if (elements instanceof Float32Array) {\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, elements);\n }\n else {\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, new Float32Array(elements));\n }\n }\n else {\n if (elements instanceof Float32Array) {\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, elements.subarray(offset, offset + count));\n }\n else {\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, new Float32Array(elements).subarray(offset, offset + count));\n }\n }\n this.bindUniformBuffer(null);\n };\n ThinEngine.prototype.bindUniformBuffer = function (buffer) {\n this._gl.bindBuffer(this._gl.UNIFORM_BUFFER, buffer ? buffer.underlyingResource : null);\n };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ThinEngine.prototype.bindUniformBufferBase = function (buffer, location, name) {\n this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER, location, buffer ? buffer.underlyingResource : null);\n };\n ThinEngine.prototype.bindUniformBlock = function (pipelineContext, blockName, index) {\n const program = pipelineContext.program;\n const uniformLocation = this._gl.getUniformBlockIndex(program, blockName);\n if (uniformLocation !== 0xffffffff) {\n this._gl.uniformBlockBinding(program, uniformLocation, index);\n }\n };\n\n /**\n * Uniform buffer objects.\n *\n * Handles blocks of uniform on the GPU.\n *\n * If WebGL 2 is not available, this class falls back on traditional setUniformXXX calls.\n *\n * For more information, please refer to :\n * https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object\n */\n class UniformBuffer {\n /**\n * Instantiates a new Uniform buffer objects.\n *\n * Handles blocks of uniform on the GPU.\n *\n * If WebGL 2 is not available, this class falls back on traditional setUniformXXX calls.\n *\n * For more information, please refer to :\n * @see https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object\n * @param engine Define the engine the buffer is associated with\n * @param data Define the data contained in the buffer\n * @param dynamic Define if the buffer is updatable\n * @param name to assign to the buffer (debugging purpose)\n * @param forceNoUniformBuffer define that this object must not rely on UBO objects\n */\n constructor(engine, data, dynamic, name, forceNoUniformBuffer = false) {\n // Matrix cache\n this._valueCache = {};\n this._engine = engine;\n this._noUBO = !engine.supportsUniformBuffers || forceNoUniformBuffer;\n this._dynamic = dynamic;\n this._name = name !== null && name !== void 0 ? name : \"no-name\";\n this._data = data || [];\n this._uniformLocations = {};\n this._uniformSizes = {};\n this._uniformArraySizes = {};\n this._uniformLocationPointer = 0;\n this._needSync = false;\n if (this._engine._features.trackUbosInFrame) {\n this._buffers = [];\n this._bufferIndex = -1;\n this._createBufferOnWrite = false;\n this._currentFrameId = 0;\n }\n if (this._noUBO) {\n this.updateMatrix3x3 = this._updateMatrix3x3ForEffect;\n this.updateMatrix2x2 = this._updateMatrix2x2ForEffect;\n this.updateFloat = this._updateFloatForEffect;\n this.updateFloat2 = this._updateFloat2ForEffect;\n this.updateFloat3 = this._updateFloat3ForEffect;\n this.updateFloat4 = this._updateFloat4ForEffect;\n this.updateFloatArray = this._updateFloatArrayForEffect;\n this.updateArray = this._updateArrayForEffect;\n this.updateIntArray = this._updateIntArrayForEffect;\n this.updateUIntArray = this._updateUIntArrayForEffect;\n this.updateMatrix = this._updateMatrixForEffect;\n this.updateMatrices = this._updateMatricesForEffect;\n this.updateVector3 = this._updateVector3ForEffect;\n this.updateVector4 = this._updateVector4ForEffect;\n this.updateColor3 = this._updateColor3ForEffect;\n this.updateColor4 = this._updateColor4ForEffect;\n this.updateDirectColor4 = this._updateDirectColor4ForEffect;\n this.updateInt = this._updateIntForEffect;\n this.updateInt2 = this._updateInt2ForEffect;\n this.updateInt3 = this._updateInt3ForEffect;\n this.updateInt4 = this._updateInt4ForEffect;\n this.updateUInt = this._updateUIntForEffect;\n this.updateUInt2 = this._updateUInt2ForEffect;\n this.updateUInt3 = this._updateUInt3ForEffect;\n this.updateUInt4 = this._updateUInt4ForEffect;\n }\n else {\n this._engine._uniformBuffers.push(this);\n this.updateMatrix3x3 = this._updateMatrix3x3ForUniform;\n this.updateMatrix2x2 = this._updateMatrix2x2ForUniform;\n this.updateFloat = this._updateFloatForUniform;\n this.updateFloat2 = this._updateFloat2ForUniform;\n this.updateFloat3 = this._updateFloat3ForUniform;\n this.updateFloat4 = this._updateFloat4ForUniform;\n this.updateFloatArray = this._updateFloatArrayForUniform;\n this.updateArray = this._updateArrayForUniform;\n this.updateIntArray = this._updateIntArrayForUniform;\n this.updateUIntArray = this._updateUIntArrayForUniform;\n this.updateMatrix = this._updateMatrixForUniform;\n this.updateMatrices = this._updateMatricesForUniform;\n this.updateVector3 = this._updateVector3ForUniform;\n this.updateVector4 = this._updateVector4ForUniform;\n this.updateColor3 = this._updateColor3ForUniform;\n this.updateColor4 = this._updateColor4ForUniform;\n this.updateDirectColor4 = this._updateDirectColor4ForUniform;\n this.updateInt = this._updateIntForUniform;\n this.updateInt2 = this._updateInt2ForUniform;\n this.updateInt3 = this._updateInt3ForUniform;\n this.updateInt4 = this._updateInt4ForUniform;\n this.updateUInt = this._updateUIntForUniform;\n this.updateUInt2 = this._updateUInt2ForUniform;\n this.updateUInt3 = this._updateUInt3ForUniform;\n this.updateUInt4 = this._updateUInt4ForUniform;\n }\n }\n /**\n * Indicates if the buffer is using the WebGL2 UBO implementation,\n * or just falling back on setUniformXXX calls.\n */\n get useUbo() {\n return !this._noUBO;\n }\n /**\n * Indicates if the WebGL underlying uniform buffer is in sync\n * with the javascript cache data.\n */\n get isSync() {\n return !this._needSync;\n }\n /**\n * Indicates if the WebGL underlying uniform buffer is dynamic.\n * Also, a dynamic UniformBuffer will disable cache verification and always\n * update the underlying WebGL uniform buffer to the GPU.\n * @returns if Dynamic, otherwise false\n */\n isDynamic() {\n return this._dynamic !== undefined;\n }\n /**\n * The data cache on JS side.\n * @returns the underlying data as a float array\n */\n getData() {\n return this._bufferData;\n }\n /**\n * The underlying WebGL Uniform buffer.\n * @returns the webgl buffer\n */\n getBuffer() {\n return this._buffer;\n }\n /**\n * std140 layout specifies how to align data within an UBO structure.\n * See https://khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf#page=159\n * for specs.\n * @param size\n */\n _fillAlignment(size) {\n // This code has been simplified because we only use floats, vectors of 1, 2, 3, 4 components\n // and 4x4 matrices\n // TODO : change if other types are used\n let alignment;\n if (size <= 2) {\n alignment = size;\n }\n else {\n alignment = 4;\n }\n if (this._uniformLocationPointer % alignment !== 0) {\n const oldPointer = this._uniformLocationPointer;\n this._uniformLocationPointer += alignment - (this._uniformLocationPointer % alignment);\n const diff = this._uniformLocationPointer - oldPointer;\n for (let i = 0; i < diff; i++) {\n this._data.push(0);\n }\n }\n }\n /**\n * Adds an uniform in the buffer.\n * Warning : the subsequents calls of this function must be in the same order as declared in the shader\n * for the layout to be correct ! The addUniform function only handles types like float, vec2, vec3, vec4, mat4,\n * meaning size=1,2,3,4 or 16. It does not handle struct types.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param size Data size, or data directly.\n * @param arraySize The number of elements in the array, 0 if not an array.\n */\n addUniform(name, size, arraySize = 0) {\n if (this._noUBO) {\n return;\n }\n if (this._uniformLocations[name] !== undefined) {\n // Already existing uniform\n return;\n }\n // This function must be called in the order of the shader layout !\n // size can be the size of the uniform, or data directly\n let data;\n // std140 FTW...\n if (arraySize > 0) {\n if (size instanceof Array) {\n throw \"addUniform should not be use with Array in UBO: \" + name;\n }\n this._fillAlignment(4);\n this._uniformArraySizes[name] = { strideSize: size, arraySize };\n if (size == 16) {\n size = size * arraySize;\n }\n else {\n const perElementPadding = 4 - size;\n const totalPadding = perElementPadding * arraySize;\n size = size * arraySize + totalPadding;\n }\n data = [];\n // Fill with zeros\n for (let i = 0; i < size; i++) {\n data.push(0);\n }\n }\n else {\n if (size instanceof Array) {\n data = size;\n size = data.length;\n }\n else {\n size = size;\n data = [];\n // Fill with zeros\n for (let i = 0; i < size; i++) {\n data.push(0);\n }\n }\n this._fillAlignment(size);\n }\n this._uniformSizes[name] = size;\n this._uniformLocations[name] = this._uniformLocationPointer;\n this._uniformLocationPointer += size;\n for (let i = 0; i < size; i++) {\n this._data.push(data[i]);\n }\n this._needSync = true;\n }\n /**\n * Adds a Matrix 4x4 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param mat A 4x4 matrix.\n */\n addMatrix(name, mat) {\n this.addUniform(name, Array.prototype.slice.call(mat.toArray()));\n }\n /**\n * Adds a vec2 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param x Define the x component value of the vec2\n * @param y Define the y component value of the vec2\n */\n addFloat2(name, x, y) {\n const temp = [x, y];\n this.addUniform(name, temp);\n }\n /**\n * Adds a vec3 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param x Define the x component value of the vec3\n * @param y Define the y component value of the vec3\n * @param z Define the z component value of the vec3\n */\n addFloat3(name, x, y, z) {\n const temp = [x, y, z];\n this.addUniform(name, temp);\n }\n /**\n * Adds a vec3 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param color Define the vec3 from a Color\n */\n addColor3(name, color) {\n const temp = [color.r, color.g, color.b];\n this.addUniform(name, temp);\n }\n /**\n * Adds a vec4 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param color Define the rgb components from a Color\n * @param alpha Define the a component of the vec4\n */\n addColor4(name, color, alpha) {\n const temp = [color.r, color.g, color.b, alpha];\n this.addUniform(name, temp);\n }\n /**\n * Adds a vec3 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n * @param vector Define the vec3 components from a Vector\n */\n addVector3(name, vector) {\n const temp = [vector.x, vector.y, vector.z];\n this.addUniform(name, temp);\n }\n /**\n * Adds a Matrix 3x3 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n */\n addMatrix3x3(name) {\n this.addUniform(name, 12);\n }\n /**\n * Adds a Matrix 2x2 to the uniform buffer.\n * @param name Name of the uniform, as used in the uniform block in the shader.\n */\n addMatrix2x2(name) {\n this.addUniform(name, 8);\n }\n /**\n * Effectively creates the WebGL Uniform Buffer, once layout is completed with `addUniform`.\n */\n create() {\n if (this._noUBO) {\n return;\n }\n if (this._buffer) {\n return; // nothing to do\n }\n // See spec, alignment must be filled as a vec4\n this._fillAlignment(4);\n this._bufferData = new Float32Array(this._data);\n this._rebuild();\n this._needSync = true;\n }\n /** @internal */\n _rebuild() {\n if (this._noUBO || !this._bufferData) {\n return;\n }\n if (this._dynamic) {\n this._buffer = this._engine.createDynamicUniformBuffer(this._bufferData);\n }\n else {\n this._buffer = this._engine.createUniformBuffer(this._bufferData);\n }\n if (this._engine._features.trackUbosInFrame) {\n this._buffers.push([this._buffer, this._engine._features.checkUbosContentBeforeUpload ? this._bufferData.slice() : undefined]);\n this._bufferIndex = this._buffers.length - 1;\n this._createBufferOnWrite = false;\n }\n }\n /** @internal */\n get _numBuffers() {\n return this._buffers.length;\n }\n /** @internal */\n get _indexBuffer() {\n return this._bufferIndex;\n }\n /** Gets the name of this buffer */\n get name() {\n return this._name;\n }\n /** Gets the current effect */\n get currentEffect() {\n return this._currentEffect;\n }\n _buffersEqual(buf1, buf2) {\n for (let i = 0; i < buf1.length; ++i) {\n if (buf1[i] !== buf2[i]) {\n return false;\n }\n }\n return true;\n }\n _copyBuffer(src, dst) {\n for (let i = 0; i < src.length; ++i) {\n dst[i] = src[i];\n }\n }\n /**\n * Updates the WebGL Uniform Buffer on the GPU.\n * If the `dynamic` flag is set to true, no cache comparison is done.\n * Otherwise, the buffer will be updated only if the cache differs.\n */\n update() {\n if (this._noUBO) {\n return;\n }\n this.bindUniformBuffer();\n if (!this._buffer) {\n this.create();\n return;\n }\n if (!this._dynamic && !this._needSync) {\n this._createBufferOnWrite = this._engine._features.trackUbosInFrame;\n return;\n }\n if (this._buffers && this._buffers.length > 1 && this._buffers[this._bufferIndex][1]) {\n if (this._buffersEqual(this._bufferData, this._buffers[this._bufferIndex][1])) {\n this._needSync = false;\n this._createBufferOnWrite = this._engine._features.trackUbosInFrame;\n return;\n }\n else {\n this._copyBuffer(this._bufferData, this._buffers[this._bufferIndex][1]);\n }\n }\n this._engine.updateUniformBuffer(this._buffer, this._bufferData);\n if (this._engine._features._collectUbosUpdatedInFrame) {\n if (!UniformBuffer._UpdatedUbosInFrame[this._name]) {\n UniformBuffer._UpdatedUbosInFrame[this._name] = 0;\n }\n UniformBuffer._UpdatedUbosInFrame[this._name]++;\n }\n this._needSync = false;\n this._createBufferOnWrite = this._engine._features.trackUbosInFrame;\n }\n _createNewBuffer() {\n if (this._bufferIndex + 1 < this._buffers.length) {\n this._bufferIndex++;\n this._buffer = this._buffers[this._bufferIndex][0];\n this._createBufferOnWrite = false;\n this._needSync = true;\n }\n else {\n this._rebuild();\n }\n }\n _checkNewFrame() {\n if (this._engine._features.trackUbosInFrame && this._currentFrameId !== this._engine.frameId) {\n this._currentFrameId = this._engine.frameId;\n this._createBufferOnWrite = false;\n if (this._buffers && this._buffers.length > 0) {\n this._needSync = this._bufferIndex !== 0;\n this._bufferIndex = 0;\n this._buffer = this._buffers[this._bufferIndex][0];\n }\n else {\n this._bufferIndex = -1;\n }\n }\n }\n /**\n * Updates the value of an uniform. The `update` method must be called afterwards to make it effective in the GPU.\n * @param uniformName Define the name of the uniform, as used in the uniform block in the shader.\n * @param data Define the flattened data\n * @param size Define the size of the data.\n */\n updateUniform(uniformName, data, size) {\n this._checkNewFrame();\n let location = this._uniformLocations[uniformName];\n if (location === undefined) {\n if (this._buffer) {\n // Cannot add an uniform if the buffer is already created\n Logger.Error(\"Cannot add an uniform after UBO has been created.\");\n return;\n }\n this.addUniform(uniformName, size);\n location = this._uniformLocations[uniformName];\n }\n if (!this._buffer) {\n this.create();\n }\n if (!this._dynamic) {\n // Cache for static uniform buffers\n let changed = false;\n for (let i = 0; i < size; i++) {\n // We are checking the matrix cache before calling updateUniform so we do not need to check it here\n // Hence the test for size === 16 to simply commit the matrix values\n if ((size === 16 && !this._engine._features.uniformBufferHardCheckMatrix) || this._bufferData[location + i] !== Tools.FloatRound(data[i])) {\n changed = true;\n if (this._createBufferOnWrite) {\n this._createNewBuffer();\n }\n this._bufferData[location + i] = data[i];\n }\n }\n this._needSync = this._needSync || changed;\n }\n else {\n // No cache for dynamic\n for (let i = 0; i < size; i++) {\n this._bufferData[location + i] = data[i];\n }\n }\n }\n /**\n * Updates the value of an uniform. The `update` method must be called afterwards to make it effective in the GPU.\n * @param uniformName Define the name of the uniform, as used in the uniform block in the shader.\n * @param data Define the flattened data\n * @param size Define the size of the data.\n */\n updateUniformArray(uniformName, data, size) {\n this._checkNewFrame();\n const location = this._uniformLocations[uniformName];\n if (location === undefined) {\n Logger.Error(\"Cannot add an uniform Array dynamically. Please, add it using addUniform and make sure that uniform buffers are supported by the current engine.\");\n return;\n }\n if (!this._buffer) {\n this.create();\n }\n const arraySizes = this._uniformArraySizes[uniformName];\n if (!this._dynamic) {\n // Cache for static uniform buffers\n let changed = false;\n let countToFour = 0;\n let baseStride = 0;\n for (let i = 0; i < size; i++) {\n if (this._bufferData[location + baseStride * 4 + countToFour] !== Tools.FloatRound(data[i])) {\n changed = true;\n if (this._createBufferOnWrite) {\n this._createNewBuffer();\n }\n this._bufferData[location + baseStride * 4 + countToFour] = data[i];\n }\n countToFour++;\n if (countToFour === arraySizes.strideSize) {\n for (; countToFour < 4; countToFour++) {\n this._bufferData[location + baseStride * 4 + countToFour] = 0;\n }\n countToFour = 0;\n baseStride++;\n }\n }\n this._needSync = this._needSync || changed;\n }\n else {\n // No cache for dynamic\n for (let i = 0; i < size; i++) {\n this._bufferData[location + i] = data[i];\n }\n }\n }\n _cacheMatrix(name, matrix) {\n this._checkNewFrame();\n const cache = this._valueCache[name];\n const flag = matrix.updateFlag;\n if (cache !== undefined && cache === flag) {\n return false;\n }\n this._valueCache[name] = flag;\n return true;\n }\n // Update methods\n _updateMatrix3x3ForUniform(name, matrix) {\n // To match std140, matrix must be realigned\n for (let i = 0; i < 3; i++) {\n UniformBuffer._TempBuffer[i * 4] = matrix[i * 3];\n UniformBuffer._TempBuffer[i * 4 + 1] = matrix[i * 3 + 1];\n UniformBuffer._TempBuffer[i * 4 + 2] = matrix[i * 3 + 2];\n UniformBuffer._TempBuffer[i * 4 + 3] = 0.0;\n }\n this.updateUniform(name, UniformBuffer._TempBuffer, 12);\n }\n _updateMatrix3x3ForEffect(name, matrix) {\n this._currentEffect.setMatrix3x3(name, matrix);\n }\n _updateMatrix2x2ForEffect(name, matrix) {\n this._currentEffect.setMatrix2x2(name, matrix);\n }\n _updateMatrix2x2ForUniform(name, matrix) {\n // To match std140, matrix must be realigned\n for (let i = 0; i < 2; i++) {\n UniformBuffer._TempBuffer[i * 4] = matrix[i * 2];\n UniformBuffer._TempBuffer[i * 4 + 1] = matrix[i * 2 + 1];\n UniformBuffer._TempBuffer[i * 4 + 2] = 0.0;\n UniformBuffer._TempBuffer[i * 4 + 3] = 0.0;\n }\n this.updateUniform(name, UniformBuffer._TempBuffer, 8);\n }\n _updateFloatForEffect(name, x) {\n this._currentEffect.setFloat(name, x);\n }\n _updateFloatForUniform(name, x) {\n UniformBuffer._TempBuffer[0] = x;\n this.updateUniform(name, UniformBuffer._TempBuffer, 1);\n }\n _updateFloat2ForEffect(name, x, y, suffix = \"\") {\n this._currentEffect.setFloat2(name + suffix, x, y);\n }\n _updateFloat2ForUniform(name, x, y) {\n UniformBuffer._TempBuffer[0] = x;\n UniformBuffer._TempBuffer[1] = y;\n this.updateUniform(name, UniformBuffer._TempBuffer, 2);\n }\n _updateFloat3ForEffect(name, x, y, z, suffix = \"\") {\n this._currentEffect.setFloat3(name + suffix, x, y, z);\n }\n _updateFloat3ForUniform(name, x, y, z) {\n UniformBuffer._TempBuffer[0] = x;\n UniformBuffer._TempBuffer[1] = y;\n UniformBuffer._TempBuffer[2] = z;\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\n }\n _updateFloat4ForEffect(name, x, y, z, w, suffix = \"\") {\n this._currentEffect.setFloat4(name + suffix, x, y, z, w);\n }\n _updateFloat4ForUniform(name, x, y, z, w) {\n UniformBuffer._TempBuffer[0] = x;\n UniformBuffer._TempBuffer[1] = y;\n UniformBuffer._TempBuffer[2] = z;\n UniformBuffer._TempBuffer[3] = w;\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\n }\n _updateFloatArrayForEffect(name, array) {\n this._currentEffect.setFloatArray(name, array);\n }\n _updateFloatArrayForUniform(name, array) {\n this.updateUniformArray(name, array, array.length);\n }\n _updateArrayForEffect(name, array) {\n this._currentEffect.setArray(name, array);\n }\n _updateArrayForUniform(name, array) {\n this.updateUniformArray(name, array, array.length);\n }\n _updateIntArrayForEffect(name, array) {\n this._currentEffect.setIntArray(name, array);\n }\n _updateIntArrayForUniform(name, array) {\n UniformBuffer._TempBufferInt32View.set(array);\n this.updateUniformArray(name, UniformBuffer._TempBuffer, array.length);\n }\n _updateUIntArrayForEffect(name, array) {\n this._currentEffect.setUIntArray(name, array);\n }\n _updateUIntArrayForUniform(name, array) {\n UniformBuffer._TempBufferUInt32View.set(array);\n this.updateUniformArray(name, UniformBuffer._TempBuffer, array.length);\n }\n _updateMatrixForEffect(name, mat) {\n this._currentEffect.setMatrix(name, mat);\n }\n _updateMatrixForUniform(name, mat) {\n if (this._cacheMatrix(name, mat)) {\n this.updateUniform(name, mat.toArray(), 16);\n }\n }\n _updateMatricesForEffect(name, mat) {\n this._currentEffect.setMatrices(name, mat);\n }\n _updateMatricesForUniform(name, mat) {\n this.updateUniform(name, mat, mat.length);\n }\n _updateVector3ForEffect(name, vector) {\n this._currentEffect.setVector3(name, vector);\n }\n _updateVector3ForUniform(name, vector) {\n UniformBuffer._TempBuffer[0] = vector.x;\n UniformBuffer._TempBuffer[1] = vector.y;\n UniformBuffer._TempBuffer[2] = vector.z;\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\n }\n _updateVector4ForEffect(name, vector) {\n this._currentEffect.setVector4(name, vector);\n }\n _updateVector4ForUniform(name, vector) {\n UniformBuffer._TempBuffer[0] = vector.x;\n UniformBuffer._TempBuffer[1] = vector.y;\n UniformBuffer._TempBuffer[2] = vector.z;\n UniformBuffer._TempBuffer[3] = vector.w;\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\n }\n _updateColor3ForEffect(name, color, suffix = \"\") {\n this._currentEffect.setColor3(name + suffix, color);\n }\n _updateColor3ForUniform(name, color) {\n UniformBuffer._TempBuffer[0] = color.r;\n UniformBuffer._TempBuffer[1] = color.g;\n UniformBuffer._TempBuffer[2] = color.b;\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\n }\n _updateColor4ForEffect(name, color, alpha, suffix = \"\") {\n this._currentEffect.setColor4(name + suffix, color, alpha);\n }\n _updateDirectColor4ForEffect(name, color, suffix = \"\") {\n this._currentEffect.setDirectColor4(name + suffix, color);\n }\n _updateColor4ForUniform(name, color, alpha) {\n UniformBuffer._TempBuffer[0] = color.r;\n UniformBuffer._TempBuffer[1] = color.g;\n UniformBuffer._TempBuffer[2] = color.b;\n UniformBuffer._TempBuffer[3] = alpha;\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\n }\n _updateDirectColor4ForUniform(name, color) {\n UniformBuffer._TempBuffer[0] = color.r;\n UniformBuffer._TempBuffer[1] = color.g;\n UniformBuffer._TempBuffer[2] = color.b;\n UniformBuffer._TempBuffer[3] = color.a;\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\n }\n _updateIntForEffect(name, x, suffix = \"\") {\n this._currentEffect.setInt(name + suffix, x);\n }\n _updateIntForUniform(name, x) {\n UniformBuffer._TempBufferInt32View[0] = x;\n this.updateUniform(name, UniformBuffer._TempBuffer, 1);\n }\n _updateInt2ForEffect(name, x, y, suffix = \"\") {\n this._currentEffect.setInt2(name + suffix, x, y);\n }\n _updateInt2ForUniform(name, x, y) {\n UniformBuffer._TempBufferInt32View[0] = x;\n UniformBuffer._TempBufferInt32View[1] = y;\n this.updateUniform(name, UniformBuffer._TempBuffer, 2);\n }\n _updateInt3ForEffect(name, x, y, z, suffix = \"\") {\n this._currentEffect.setInt3(name + suffix, x, y, z);\n }\n _updateInt3ForUniform(name, x, y, z) {\n UniformBuffer._TempBufferInt32View[0] = x;\n UniformBuffer._TempBufferInt32View[1] = y;\n UniformBuffer._TempBufferInt32View[2] = z;\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\n }\n _updateInt4ForEffect(name, x, y, z, w, suffix = \"\") {\n this._currentEffect.setInt4(name + suffix, x, y, z, w);\n }\n _updateInt4ForUniform(name, x, y, z, w) {\n UniformBuffer._TempBufferInt32View[0] = x;\n UniformBuffer._TempBufferInt32View[1] = y;\n UniformBuffer._TempBufferInt32View[2] = z;\n UniformBuffer._TempBufferInt32View[3] = w;\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\n }\n _updateUIntForEffect(name, x, suffix = \"\") {\n this._currentEffect.setUInt(name + suffix, x);\n }\n _updateUIntForUniform(name, x) {\n UniformBuffer._TempBufferUInt32View[0] = x;\n this.updateUniform(name, UniformBuffer._TempBuffer, 1);\n }\n _updateUInt2ForEffect(name, x, y, suffix = \"\") {\n this._currentEffect.setUInt2(name + suffix, x, y);\n }\n _updateUInt2ForUniform(name, x, y) {\n UniformBuffer._TempBufferUInt32View[0] = x;\n UniformBuffer._TempBufferUInt32View[1] = y;\n this.updateUniform(name, UniformBuffer._TempBuffer, 2);\n }\n _updateUInt3ForEffect(name, x, y, z, suffix = \"\") {\n this._currentEffect.setUInt3(name + suffix, x, y, z);\n }\n _updateUInt3ForUniform(name, x, y, z) {\n UniformBuffer._TempBufferUInt32View[0] = x;\n UniformBuffer._TempBufferUInt32View[1] = y;\n UniformBuffer._TempBufferUInt32View[2] = z;\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\n }\n _updateUInt4ForEffect(name, x, y, z, w, suffix = \"\") {\n this._currentEffect.setUInt4(name + suffix, x, y, z, w);\n }\n _updateUInt4ForUniform(name, x, y, z, w) {\n UniformBuffer._TempBufferUInt32View[0] = x;\n UniformBuffer._TempBufferUInt32View[1] = y;\n UniformBuffer._TempBufferUInt32View[2] = z;\n UniformBuffer._TempBufferUInt32View[3] = w;\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\n }\n /**\n * Sets a sampler uniform on the effect.\n * @param name Define the name of the sampler.\n * @param texture Define the texture to set in the sampler\n */\n setTexture(name, texture) {\n this._currentEffect.setTexture(name, texture);\n }\n /**\n * Directly updates the value of the uniform in the cache AND on the GPU.\n * @param uniformName Define the name of the uniform, as used in the uniform block in the shader.\n * @param data Define the flattened data\n */\n updateUniformDirectly(uniformName, data) {\n this.updateUniform(uniformName, data, data.length);\n this.update();\n }\n /**\n * Associates an effect to this uniform buffer\n * @param effect Define the effect to associate the buffer to\n * @param name Name of the uniform block in the shader.\n */\n bindToEffect(effect, name) {\n this._currentEffect = effect;\n this._currentEffectName = name;\n }\n /**\n * Binds the current (GPU) buffer to the effect\n */\n bindUniformBuffer() {\n if (!this._noUBO && this._buffer && this._currentEffect) {\n this._currentEffect.bindUniformBuffer(this._buffer, this._currentEffectName);\n }\n }\n /**\n * Dissociates the current effect from this uniform buffer\n */\n unbindEffect() {\n this._currentEffect = undefined;\n this._currentEffectName = undefined;\n }\n /**\n * Sets the current state of the class (_bufferIndex, _buffer) to point to the data buffer passed in parameter if this buffer is one of the buffers handled by the class (meaning if it can be found in the _buffers array)\n * This method is meant to be able to update a buffer at any time: just call setDataBuffer to set the class in the right state, call some updateXXX methods and then call udpate() => that will update the GPU buffer on the graphic card\n * @param dataBuffer buffer to look for\n * @returns true if the buffer has been found and the class internal state points to it, else false\n */\n setDataBuffer(dataBuffer) {\n if (!this._buffers) {\n return this._buffer === dataBuffer;\n }\n for (let b = 0; b < this._buffers.length; ++b) {\n const buffer = this._buffers[b];\n if (buffer[0] === dataBuffer) {\n this._bufferIndex = b;\n this._buffer = dataBuffer;\n this._createBufferOnWrite = false;\n this._currentEffect = undefined;\n return true;\n }\n }\n return false;\n }\n /**\n * Disposes the uniform buffer.\n */\n dispose() {\n if (this._noUBO) {\n return;\n }\n const uniformBuffers = this._engine._uniformBuffers;\n const index = uniformBuffers.indexOf(this);\n if (index !== -1) {\n uniformBuffers[index] = uniformBuffers[uniformBuffers.length - 1];\n uniformBuffers.pop();\n }\n if (this._engine._features.trackUbosInFrame && this._buffers) {\n for (let i = 0; i < this._buffers.length; ++i) {\n const buffer = this._buffers[i][0];\n this._engine._releaseBuffer(buffer);\n }\n }\n else if (this._buffer && this._engine._releaseBuffer(this._buffer)) {\n this._buffer = null;\n }\n }\n }\n /** @internal */\n UniformBuffer._UpdatedUbosInFrame = {};\n // Pool for avoiding memory leaks\n UniformBuffer._MAX_UNIFORM_SIZE = 256;\n UniformBuffer._TempBuffer = new Float32Array(UniformBuffer._MAX_UNIFORM_SIZE);\n UniformBuffer._TempBufferInt32View = new Int32Array(UniformBuffer._TempBuffer.buffer);\n UniformBuffer._TempBufferUInt32View = new Uint32Array(UniformBuffer._TempBuffer.buffer);\n\n /**\n * Class used to store data that will be store in GPU memory\n */\n class Buffer$1 {\n /**\n * Constructor\n * @param engine the engine\n * @param data the data to use for this buffer\n * @param updatable whether the data is updatable\n * @param stride the stride (optional)\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\n * @param instanced whether the buffer is instanced (optional)\n * @param useBytes set to true if the stride in in bytes (optional)\n * @param divisor sets an optional divisor for instances (1 by default)\n */\n constructor(engine, data, updatable, stride = 0, postponeInternalCreation = false, instanced = false, useBytes = false, divisor) {\n this._isAlreadyOwned = false;\n if (engine.getScene) {\n // old versions of VertexBuffer accepted 'mesh' instead of 'engine'\n this._engine = engine.getScene().getEngine();\n }\n else {\n this._engine = engine;\n }\n this._updatable = updatable;\n this._instanced = instanced;\n this._divisor = divisor || 1;\n if (data instanceof DataBuffer) {\n this._data = null;\n this._buffer = data;\n }\n else {\n this._data = data;\n this._buffer = null;\n }\n this.byteStride = useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT;\n if (!postponeInternalCreation) {\n // by default\n this.create();\n }\n }\n /**\n * Create a new VertexBuffer based on the current buffer\n * @param kind defines the vertex buffer kind (position, normal, etc.)\n * @param offset defines offset in the buffer (0 by default)\n * @param size defines the size in floats of attributes (position is 3 for instance)\n * @param stride defines the stride size in floats in the buffer (the offset to apply to reach next value when data is interleaved)\n * @param instanced defines if the vertex buffer contains indexed data\n * @param useBytes defines if the offset and stride are in bytes *\n * @param divisor sets an optional divisor for instances (1 by default)\n * @returns the new vertex buffer\n */\n createVertexBuffer(kind, offset, size, stride, instanced, useBytes = false, divisor) {\n const byteOffset = useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT;\n const byteStride = stride ? (useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT) : this.byteStride;\n // a lot of these parameters are ignored as they are overridden by the buffer\n return new VertexBuffer(this._engine, this, kind, this._updatable, true, byteStride, instanced === undefined ? this._instanced : instanced, byteOffset, size, undefined, undefined, true, this._divisor || divisor);\n }\n // Properties\n /**\n * Gets a boolean indicating if the Buffer is updatable?\n * @returns true if the buffer is updatable\n */\n isUpdatable() {\n return this._updatable;\n }\n /**\n * Gets current buffer's data\n * @returns a DataArray or null\n */\n getData() {\n return this._data;\n }\n /**\n * Gets underlying native buffer\n * @returns underlying native buffer\n */\n getBuffer() {\n return this._buffer;\n }\n /**\n * Gets the stride in float32 units (i.e. byte stride / 4).\n * May not be an integer if the byte stride is not divisible by 4.\n * @returns the stride in float32 units\n * @deprecated Please use byteStride instead.\n */\n getStrideSize() {\n return this.byteStride / Float32Array.BYTES_PER_ELEMENT;\n }\n // Methods\n /**\n * Store data into the buffer. Creates the buffer if not used already.\n * If the buffer was already used, it will be updated only if it is updatable, otherwise it will do nothing.\n * @param data defines the data to store\n */\n create(data = null) {\n if (!data && this._buffer) {\n return; // nothing to do\n }\n data = data || this._data;\n if (!data) {\n return;\n }\n if (!this._buffer) {\n // create buffer\n if (this._updatable) {\n this._buffer = this._engine.createDynamicVertexBuffer(data);\n this._data = data;\n }\n else {\n this._buffer = this._engine.createVertexBuffer(data);\n }\n }\n else if (this._updatable) {\n // update buffer\n this._engine.updateDynamicVertexBuffer(this._buffer, data);\n this._data = data;\n }\n }\n /** @internal */\n _rebuild() {\n this._buffer = null;\n this.create(this._data);\n }\n /**\n * Update current buffer data\n * @param data defines the data to store\n */\n update(data) {\n this.create(data);\n }\n /**\n * Updates the data directly.\n * @param data the new data\n * @param offset the new offset\n * @param vertexCount the vertex count (optional)\n * @param useBytes set to true if the offset is in bytes\n */\n updateDirectly(data, offset, vertexCount, useBytes = false) {\n if (!this._buffer) {\n return;\n }\n if (this._updatable) {\n // update buffer\n this._engine.updateDynamicVertexBuffer(this._buffer, data, useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT, vertexCount ? vertexCount * this.byteStride : undefined);\n if (offset === 0 && vertexCount === undefined) {\n // Keep the data if we easily can\n this._data = data;\n }\n else {\n this._data = null;\n }\n }\n }\n /** @internal */\n _increaseReferences() {\n if (!this._buffer) {\n return;\n }\n if (!this._isAlreadyOwned) {\n this._isAlreadyOwned = true;\n return;\n }\n this._buffer.references++;\n }\n /**\n * Release all resources\n */\n dispose() {\n if (!this._buffer) {\n return;\n }\n if (this._engine._releaseBuffer(this._buffer)) {\n this._buffer = null;\n this._data = null;\n }\n }\n }\n /**\n * Specialized buffer used to store vertex data\n */\n class VertexBuffer {\n /**\n * Gets or sets the instance divisor when in instanced mode\n */\n get instanceDivisor() {\n return this._instanceDivisor;\n }\n set instanceDivisor(value) {\n const isInstanced = value != 0;\n this._instanceDivisor = value;\n if (isInstanced !== this._instanced) {\n this._instanced = isInstanced;\n this._computeHashCode();\n }\n }\n /**\n * Constructor\n * @param engine the engine\n * @param data the data to use for this vertex buffer\n * @param kind the vertex buffer kind\n * @param updatable whether the data is updatable\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\n * @param stride the stride (optional)\n * @param instanced whether the buffer is instanced (optional)\n * @param offset the offset of the data (optional)\n * @param size the number of components (optional)\n * @param type the type of the component (optional)\n * @param normalized whether the data contains normalized data (optional)\n * @param useBytes set to true if stride and offset are in bytes (optional)\n * @param divisor defines the instance divisor to use (1 by default)\n * @param takeBufferOwnership defines if the buffer should be released when the vertex buffer is disposed\n */\n constructor(engine, data, kind, updatable, postponeInternalCreation, stride, instanced, offset, size, type, normalized = false, useBytes = false, divisor = 1, takeBufferOwnership = false) {\n if (data instanceof Buffer$1) {\n this._buffer = data;\n this._ownsBuffer = takeBufferOwnership;\n }\n else {\n this._buffer = new Buffer$1(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes);\n this._ownsBuffer = true;\n }\n this.uniqueId = VertexBuffer._Counter++;\n this._kind = kind;\n if (type == undefined) {\n const vertexData = this.getData();\n this.type = VertexBuffer.FLOAT;\n if (vertexData instanceof Int8Array) {\n this.type = VertexBuffer.BYTE;\n }\n else if (vertexData instanceof Uint8Array) {\n this.type = VertexBuffer.UNSIGNED_BYTE;\n }\n else if (vertexData instanceof Int16Array) {\n this.type = VertexBuffer.SHORT;\n }\n else if (vertexData instanceof Uint16Array) {\n this.type = VertexBuffer.UNSIGNED_SHORT;\n }\n else if (vertexData instanceof Int32Array) {\n this.type = VertexBuffer.INT;\n }\n else if (vertexData instanceof Uint32Array) {\n this.type = VertexBuffer.UNSIGNED_INT;\n }\n }\n else {\n this.type = type;\n }\n const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);\n if (useBytes) {\n this._size = size || (stride ? stride / typeByteLength : VertexBuffer.DeduceStride(kind));\n this.byteStride = stride || this._buffer.byteStride || this._size * typeByteLength;\n this.byteOffset = offset || 0;\n }\n else {\n this._size = size || stride || VertexBuffer.DeduceStride(kind);\n this.byteStride = stride ? stride * typeByteLength : this._buffer.byteStride || this._size * typeByteLength;\n this.byteOffset = (offset || 0) * typeByteLength;\n }\n this.normalized = normalized;\n this._instanced = instanced !== undefined ? instanced : false;\n this._instanceDivisor = instanced ? divisor : 0;\n this._computeHashCode();\n }\n _computeHashCode() {\n // note: cast to any because the property is declared readonly\n this.hashCode =\n ((this.type - 5120) << 0) +\n ((this.normalized ? 1 : 0) << 3) +\n (this._size << 4) +\n ((this._instanced ? 1 : 0) << 6) +\n /* keep 5 bits free */\n (this.byteStride << 12);\n }\n /** @internal */\n _rebuild() {\n if (!this._buffer) {\n return;\n }\n this._buffer._rebuild();\n }\n /**\n * Returns the kind of the VertexBuffer (string)\n * @returns a string\n */\n getKind() {\n return this._kind;\n }\n // Properties\n /**\n * Gets a boolean indicating if the VertexBuffer is updatable?\n * @returns true if the buffer is updatable\n */\n isUpdatable() {\n return this._buffer.isUpdatable();\n }\n /**\n * Gets current buffer's data\n * @returns a DataArray or null\n */\n getData() {\n return this._buffer.getData();\n }\n /**\n * Gets current buffer's data as a float array. Float data is constructed if the vertex buffer data cannot be returned directly.\n * @param totalVertices number of vertices in the buffer to take into account\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\n * @returns a float array containing vertex data\n */\n getFloatData(totalVertices, forceCopy) {\n const data = this.getData();\n if (!data) {\n return null;\n }\n const tightlyPackedByteStride = this.getSize() * VertexBuffer.GetTypeByteLength(this.type);\n const count = totalVertices * this.getSize();\n if (this.type !== VertexBuffer.FLOAT || this.byteStride !== tightlyPackedByteStride) {\n const copy = new Float32Array(count);\n this.forEach(count, (value, index) => (copy[index] = value));\n return copy;\n }\n if (!(data instanceof Array || data instanceof Float32Array) || this.byteOffset !== 0 || data.length !== count) {\n if (data instanceof Array) {\n const offset = this.byteOffset / 4;\n return data.slice(offset, offset + count);\n }\n else if (data instanceof ArrayBuffer) {\n return new Float32Array(data, this.byteOffset, count);\n }\n else {\n let offset = data.byteOffset + this.byteOffset;\n if (forceCopy) {\n const result = new Float32Array(count);\n const source = new Float32Array(data.buffer, offset, count);\n result.set(source);\n return result;\n }\n // Protect against bad data\n const remainder = offset % 4;\n if (remainder) {\n offset = Math.max(0, offset - remainder);\n }\n return new Float32Array(data.buffer, offset, count);\n }\n }\n if (forceCopy) {\n return data.slice();\n }\n return data;\n }\n /**\n * Gets underlying native buffer\n * @returns underlying native buffer\n */\n getBuffer() {\n return this._buffer.getBuffer();\n }\n /**\n * Gets the stride in float32 units (i.e. byte stride / 4).\n * May not be an integer if the byte stride is not divisible by 4.\n * @returns the stride in float32 units\n * @deprecated Please use byteStride instead.\n */\n getStrideSize() {\n return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);\n }\n /**\n * Returns the offset as a multiple of the type byte length.\n * @returns the offset in bytes\n * @deprecated Please use byteOffset instead.\n */\n getOffset() {\n return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);\n }\n /**\n * Returns the number of components or the byte size per vertex attribute\n * @param sizeInBytes If true, returns the size in bytes or else the size in number of components of the vertex attribute (default: false)\n * @returns the number of components\n */\n getSize(sizeInBytes = false) {\n return sizeInBytes ? this._size * VertexBuffer.GetTypeByteLength(this.type) : this._size;\n }\n /**\n * Gets a boolean indicating is the internal buffer of the VertexBuffer is instanced\n * @returns true if this buffer is instanced\n */\n getIsInstanced() {\n return this._instanced;\n }\n /**\n * Returns the instancing divisor, zero for non-instanced (integer).\n * @returns a number\n */\n getInstanceDivisor() {\n return this._instanceDivisor;\n }\n // Methods\n /**\n * Store data into the buffer. If the buffer was already used it will be either recreated or updated depending on isUpdatable property\n * @param data defines the data to store\n */\n create(data) {\n this._buffer.create(data);\n }\n /**\n * Updates the underlying buffer according to the passed numeric array or Float32Array.\n * This function will create a new buffer if the current one is not updatable\n * @param data defines the data to store\n */\n update(data) {\n this._buffer.update(data);\n }\n /**\n * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.\n * Returns the directly updated WebGLBuffer.\n * @param data the new data\n * @param offset the new offset\n * @param useBytes set to true if the offset is in bytes\n */\n updateDirectly(data, offset, useBytes = false) {\n this._buffer.updateDirectly(data, offset, undefined, useBytes);\n }\n /**\n * Disposes the VertexBuffer and the underlying WebGLBuffer.\n */\n dispose() {\n if (this._ownsBuffer) {\n this._buffer.dispose();\n }\n }\n /**\n * Enumerates each value of this vertex buffer as numbers.\n * @param count the number of values to enumerate\n * @param callback the callback function called for each value\n */\n forEach(count, callback) {\n VertexBuffer.ForEach(this._buffer.getData(), this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);\n }\n /**\n * Deduces the stride given a kind.\n * @param kind The kind string to deduce\n * @returns The deduced stride\n */\n static DeduceStride(kind) {\n switch (kind) {\n case VertexBuffer.UVKind:\n case VertexBuffer.UV2Kind:\n case VertexBuffer.UV3Kind:\n case VertexBuffer.UV4Kind:\n case VertexBuffer.UV5Kind:\n case VertexBuffer.UV6Kind:\n return 2;\n case VertexBuffer.NormalKind:\n case VertexBuffer.PositionKind:\n return 3;\n case VertexBuffer.ColorKind:\n case VertexBuffer.MatricesIndicesKind:\n case VertexBuffer.MatricesIndicesExtraKind:\n case VertexBuffer.MatricesWeightsKind:\n case VertexBuffer.MatricesWeightsExtraKind:\n case VertexBuffer.TangentKind:\n return 4;\n default:\n throw new Error(\"Invalid kind '\" + kind + \"'\");\n }\n }\n /**\n * Gets the byte length of the given type.\n * @param type the type\n * @returns the number of bytes\n */\n static GetTypeByteLength(type) {\n switch (type) {\n case VertexBuffer.BYTE:\n case VertexBuffer.UNSIGNED_BYTE:\n return 1;\n case VertexBuffer.SHORT:\n case VertexBuffer.UNSIGNED_SHORT:\n return 2;\n case VertexBuffer.INT:\n case VertexBuffer.UNSIGNED_INT:\n case VertexBuffer.FLOAT:\n return 4;\n default:\n throw new Error(`Invalid type '${type}'`);\n }\n }\n /**\n * Enumerates each value of the given parameters as numbers.\n * @param data the data to enumerate\n * @param byteOffset the byte offset of the data\n * @param byteStride the byte stride of the data\n * @param componentCount the number of components per element\n * @param componentType the type of the component\n * @param count the number of values to enumerate\n * @param normalized whether the data is normalized\n * @param callback the callback function called for each value\n */\n static ForEach(data, byteOffset, byteStride, componentCount, componentType, count, normalized, callback) {\n if (data instanceof Array) {\n let offset = byteOffset / 4;\n const stride = byteStride / 4;\n for (let index = 0; index < count; index += componentCount) {\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\n callback(data[offset + componentIndex], index + componentIndex);\n }\n offset += stride;\n }\n }\n else {\n const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);\n const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);\n for (let index = 0; index < count; index += componentCount) {\n let componentByteOffset = byteOffset;\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\n const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);\n callback(value, index + componentIndex);\n componentByteOffset += componentByteLength;\n }\n byteOffset += byteStride;\n }\n }\n }\n static _GetFloatValue(dataView, type, byteOffset, normalized) {\n switch (type) {\n case VertexBuffer.BYTE: {\n let value = dataView.getInt8(byteOffset);\n if (normalized) {\n value = Math.max(value / 127, -1);\n }\n return value;\n }\n case VertexBuffer.UNSIGNED_BYTE: {\n let value = dataView.getUint8(byteOffset);\n if (normalized) {\n value = value / 255;\n }\n return value;\n }\n case VertexBuffer.SHORT: {\n let value = dataView.getInt16(byteOffset, true);\n if (normalized) {\n value = Math.max(value / 32767, -1);\n }\n return value;\n }\n case VertexBuffer.UNSIGNED_SHORT: {\n let value = dataView.getUint16(byteOffset, true);\n if (normalized) {\n value = value / 65535;\n }\n return value;\n }\n case VertexBuffer.INT: {\n return dataView.getInt32(byteOffset, true);\n }\n case VertexBuffer.UNSIGNED_INT: {\n return dataView.getUint32(byteOffset, true);\n }\n case VertexBuffer.FLOAT: {\n return dataView.getFloat32(byteOffset, true);\n }\n default: {\n throw new Error(`Invalid component type ${type}`);\n }\n }\n }\n }\n VertexBuffer._Counter = 0;\n /**\n * The byte type.\n */\n VertexBuffer.BYTE = 5120;\n /**\n * The unsigned byte type.\n */\n VertexBuffer.UNSIGNED_BYTE = 5121;\n /**\n * The short type.\n */\n VertexBuffer.SHORT = 5122;\n /**\n * The unsigned short type.\n */\n VertexBuffer.UNSIGNED_SHORT = 5123;\n /**\n * The integer type.\n */\n VertexBuffer.INT = 5124;\n /**\n * The unsigned integer type.\n */\n VertexBuffer.UNSIGNED_INT = 5125;\n /**\n * The float type.\n */\n VertexBuffer.FLOAT = 5126;\n // Enums\n /**\n * Positions\n */\n VertexBuffer.PositionKind = \"position\";\n /**\n * Normals\n */\n VertexBuffer.NormalKind = \"normal\";\n /**\n * Tangents\n */\n VertexBuffer.TangentKind = \"tangent\";\n /**\n * Texture coordinates\n */\n VertexBuffer.UVKind = \"uv\";\n /**\n * Texture coordinates 2\n */\n VertexBuffer.UV2Kind = \"uv2\";\n /**\n * Texture coordinates 3\n */\n VertexBuffer.UV3Kind = \"uv3\";\n /**\n * Texture coordinates 4\n */\n VertexBuffer.UV4Kind = \"uv4\";\n /**\n * Texture coordinates 5\n */\n VertexBuffer.UV5Kind = \"uv5\";\n /**\n * Texture coordinates 6\n */\n VertexBuffer.UV6Kind = \"uv6\";\n /**\n * Colors\n */\n VertexBuffer.ColorKind = \"color\";\n /**\n * Instance Colors\n */\n VertexBuffer.ColorInstanceKind = \"instanceColor\";\n /**\n * Matrix indices (for bones)\n */\n VertexBuffer.MatricesIndicesKind = \"matricesIndices\";\n /**\n * Matrix weights (for bones)\n */\n VertexBuffer.MatricesWeightsKind = \"matricesWeights\";\n /**\n * Additional matrix indices (for bones)\n */\n VertexBuffer.MatricesIndicesExtraKind = \"matricesIndicesExtra\";\n /**\n * Additional matrix weights (for bones)\n */\n VertexBuffer.MatricesWeightsExtraKind = \"matricesWeightsExtra\";\n\n /**\n * Information about the result of picking within a scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/picking_collisions\n */\n class PickingInfo {\n constructor() {\n /**\n * If the pick collided with an object\n */\n this.hit = false;\n /**\n * Distance away where the pick collided\n */\n this.distance = 0;\n /**\n * The location of pick collision\n */\n this.pickedPoint = null;\n /**\n * The mesh corresponding the pick collision\n */\n this.pickedMesh = null;\n /** (See getTextureCoordinates) The barycentric U coordinate that is used when calculating the texture coordinates of the collision.*/\n this.bu = 0;\n /** (See getTextureCoordinates) The barycentric V coordinate that is used when calculating the texture coordinates of the collision.*/\n this.bv = 0;\n /** The index of the face on the mesh that was picked, or the index of the Line if the picked Mesh is a LinesMesh */\n this.faceId = -1;\n /** The index of the face on the subMesh that was picked, or the index of the Line if the picked Mesh is a LinesMesh */\n this.subMeshFaceId = -1;\n /** Id of the submesh that was picked */\n this.subMeshId = 0;\n /** If a sprite was picked, this will be the sprite the pick collided with */\n this.pickedSprite = null;\n /** If we are picking a mesh with thin instance, this will give you the picked thin instance */\n this.thinInstanceIndex = -1;\n /**\n * The ray that was used to perform the picking.\n */\n this.ray = null;\n /**\n * If a mesh was used to do the picking (eg. 6dof controller) as a \"near interaction\", this will be populated.\n */\n this.originMesh = null;\n /**\n * The aim-space transform of the input used for picking, if it is an XR input source.\n */\n this.aimTransform = null;\n /**\n * The grip-space transform of the input used for picking, if it is an XR input source.\n * Some XR sources, such as input coming from head mounted displays, do not have this.\n */\n this.gripTransform = null;\n }\n /**\n * Gets the normal corresponding to the face the pick collided with\n * @param useWorldCoordinates If the resulting normal should be relative to the world (default: false)\n * @param useVerticesNormals If the vertices normals should be used to calculate the normal instead of the normal map (default: true)\n * @returns The normal corresponding to the face the pick collided with\n * @remarks Note that the returned normal will always point towards the picking ray.\n */\n getNormal(useWorldCoordinates = false, useVerticesNormals = true) {\n if (!this.pickedMesh || (useVerticesNormals && !this.pickedMesh.isVerticesDataPresent(VertexBuffer.NormalKind))) {\n return null;\n }\n let indices = this.pickedMesh.getIndices();\n if ((indices === null || indices === void 0 ? void 0 : indices.length) === 0) {\n indices = null;\n }\n let result;\n const tmp0 = TmpVectors.Vector3[0];\n const tmp1 = TmpVectors.Vector3[1];\n const tmp2 = TmpVectors.Vector3[2];\n if (useVerticesNormals) {\n const normals = this.pickedMesh.getVerticesData(VertexBuffer.NormalKind);\n let normal0 = indices\n ? Vector3.FromArrayToRef(normals, indices[this.faceId * 3] * 3, tmp0)\n : tmp0.copyFromFloats(normals[this.faceId * 3 * 3], normals[this.faceId * 3 * 3 + 1], normals[this.faceId * 3 * 3 + 2]);\n let normal1 = indices\n ? Vector3.FromArrayToRef(normals, indices[this.faceId * 3 + 1] * 3, tmp1)\n : tmp1.copyFromFloats(normals[(this.faceId * 3 + 1) * 3], normals[(this.faceId * 3 + 1) * 3 + 1], normals[(this.faceId * 3 + 1) * 3 + 2]);\n let normal2 = indices\n ? Vector3.FromArrayToRef(normals, indices[this.faceId * 3 + 2] * 3, tmp2)\n : tmp2.copyFromFloats(normals[(this.faceId * 3 + 2) * 3], normals[(this.faceId * 3 + 2) * 3 + 1], normals[(this.faceId * 3 + 2) * 3 + 2]);\n normal0 = normal0.scale(this.bu);\n normal1 = normal1.scale(this.bv);\n normal2 = normal2.scale(1.0 - this.bu - this.bv);\n result = new Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);\n }\n else {\n const positions = this.pickedMesh.getVerticesData(VertexBuffer.PositionKind);\n const vertex1 = indices\n ? Vector3.FromArrayToRef(positions, indices[this.faceId * 3] * 3, tmp0)\n : tmp0.copyFromFloats(positions[this.faceId * 3 * 3], positions[this.faceId * 3 * 3 + 1], positions[this.faceId * 3 * 3 + 2]);\n const vertex2 = indices\n ? Vector3.FromArrayToRef(positions, indices[this.faceId * 3 + 1] * 3, tmp1)\n : tmp1.copyFromFloats(positions[(this.faceId * 3 + 1) * 3], positions[(this.faceId * 3 + 1) * 3 + 1], positions[(this.faceId * 3 + 1) * 3 + 2]);\n const vertex3 = indices\n ? Vector3.FromArrayToRef(positions, indices[this.faceId * 3 + 2] * 3, tmp2)\n : tmp2.copyFromFloats(positions[(this.faceId * 3 + 2) * 3], positions[(this.faceId * 3 + 2) * 3 + 1], positions[(this.faceId * 3 + 2) * 3 + 2]);\n const p1p2 = vertex1.subtract(vertex2);\n const p3p2 = vertex3.subtract(vertex2);\n result = Vector3.Cross(p1p2, p3p2);\n }\n const transformNormalToWorld = (pickedMesh, n) => {\n let wm = pickedMesh.getWorldMatrix();\n if (pickedMesh.nonUniformScaling) {\n TmpVectors.Matrix[0].copyFrom(wm);\n wm = TmpVectors.Matrix[0];\n wm.setTranslationFromFloats(0, 0, 0);\n wm.invert();\n wm.transposeToRef(TmpVectors.Matrix[1]);\n wm = TmpVectors.Matrix[1];\n }\n Vector3.TransformNormalToRef(n, wm, n);\n };\n if (useWorldCoordinates) {\n transformNormalToWorld(this.pickedMesh, result);\n }\n if (this.ray) {\n const normalForDirectionChecking = TmpVectors.Vector3[0].copyFrom(result);\n if (!useWorldCoordinates) {\n // the normal has not been transformed to world space as part as the normal processing, so we must do it now\n transformNormalToWorld(this.pickedMesh, normalForDirectionChecking);\n }\n // Flip the normal if the picking ray is in the same direction.\n if (Vector3.Dot(normalForDirectionChecking, this.ray.direction) > 0) {\n result.negateInPlace();\n }\n }\n result.normalize();\n return result;\n }\n /**\n * Gets the texture coordinates of where the pick occurred\n * @param uvSet The UV set to use to calculate the texture coordinates (default: VertexBuffer.UVKind)\n * @returns The vector containing the coordinates of the texture\n */\n getTextureCoordinates(uvSet = VertexBuffer.UVKind) {\n if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(uvSet)) {\n return null;\n }\n const indices = this.pickedMesh.getIndices();\n if (!indices) {\n return null;\n }\n const uvs = this.pickedMesh.getVerticesData(uvSet);\n if (!uvs) {\n return null;\n }\n let uv0 = Vector2.FromArray(uvs, indices[this.faceId * 3] * 2);\n let uv1 = Vector2.FromArray(uvs, indices[this.faceId * 3 + 1] * 2);\n let uv2 = Vector2.FromArray(uvs, indices[this.faceId * 3 + 2] * 2);\n uv0 = uv0.scale(this.bu);\n uv1 = uv1.scale(this.bv);\n uv2 = uv2.scale(1.0 - this.bu - this.bv);\n return new Vector2(uv0.x + uv1.x + uv2.x, uv0.y + uv1.y + uv2.y);\n }\n }\n\n /**\n * ActionEvent is the event being sent when an action is triggered.\n */\n class ActionEvent {\n /**\n * Creates a new ActionEvent\n * @param source The mesh or sprite that triggered the action\n * @param pointerX The X mouse cursor position at the time of the event\n * @param pointerY The Y mouse cursor position at the time of the event\n * @param meshUnderPointer The mesh that is currently pointed at (can be null)\n * @param sourceEvent the original (browser) event that triggered the ActionEvent\n * @param additionalData additional data for the event\n */\n constructor(\n /** The mesh or sprite that triggered the action */\n source, \n /** The X mouse cursor position at the time of the event */\n pointerX, \n /** The Y mouse cursor position at the time of the event */\n pointerY, \n /** The mesh that is currently pointed at (can be null) */\n meshUnderPointer, \n /** the original (browser) event that triggered the ActionEvent */\n sourceEvent, \n /** additional data for the event */\n additionalData) {\n this.source = source;\n this.pointerX = pointerX;\n this.pointerY = pointerY;\n this.meshUnderPointer = meshUnderPointer;\n this.sourceEvent = sourceEvent;\n this.additionalData = additionalData;\n }\n /**\n * Helper function to auto-create an ActionEvent from a source mesh.\n * @param source The source mesh that triggered the event\n * @param evt The original (browser) event\n * @param additionalData additional data for the event\n * @returns the new ActionEvent\n */\n static CreateNew(source, evt, additionalData) {\n const scene = source.getScene();\n return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer || source, evt, additionalData);\n }\n /**\n * Helper function to auto-create an ActionEvent from a source sprite\n * @param source The source sprite that triggered the event\n * @param scene Scene associated with the sprite\n * @param evt The original (browser) event\n * @param additionalData additional data for the event\n * @returns the new ActionEvent\n */\n static CreateNewFromSprite(source, scene, evt, additionalData) {\n return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt, additionalData);\n }\n /**\n * Helper function to auto-create an ActionEvent from a scene. If triggered by a mesh use ActionEvent.CreateNew\n * @param scene the scene where the event occurred\n * @param evt The original (browser) event\n * @returns the new ActionEvent\n */\n static CreateNewFromScene(scene, evt) {\n return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);\n }\n /**\n * Helper function to auto-create an ActionEvent from a primitive\n * @param prim defines the target primitive\n * @param pointerPos defines the pointer position\n * @param evt The original (browser) event\n * @param additionalData additional data for the event\n * @returns the new ActionEvent\n */\n static CreateNewFromPrimitive(prim, pointerPos, evt, additionalData) {\n return new ActionEvent(prim, pointerPos.x, pointerPos.y, null, evt, additionalData);\n }\n }\n\n /**\n * PostProcessManager is used to manage one or more post processes or post process pipelines\n * See https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses\n */\n class PostProcessManager {\n /**\n * Creates a new instance PostProcess\n * @param scene The scene that the post process is associated with.\n */\n constructor(scene) {\n this._vertexBuffers = {};\n this._scene = scene;\n }\n _prepareBuffers() {\n if (this._vertexBuffers[VertexBuffer.PositionKind]) {\n return;\n }\n // VBO\n const vertices = [];\n vertices.push(1, 1);\n vertices.push(-1, 1);\n vertices.push(-1, -1);\n vertices.push(1, -1);\n this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(this._scene.getEngine(), vertices, VertexBuffer.PositionKind, false, false, 2);\n this._buildIndexBuffer();\n }\n _buildIndexBuffer() {\n // Indices\n const indices = [];\n indices.push(0);\n indices.push(1);\n indices.push(2);\n indices.push(0);\n indices.push(2);\n indices.push(3);\n this._indexBuffer = this._scene.getEngine().createIndexBuffer(indices);\n }\n /**\n * Rebuilds the vertex buffers of the manager.\n * @internal\n */\n _rebuild() {\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\n if (!vb) {\n return;\n }\n vb._rebuild();\n this._buildIndexBuffer();\n }\n // Methods\n /**\n * Prepares a frame to be run through a post process.\n * @param sourceTexture The input texture to the post processes. (default: null)\n * @param postProcesses An array of post processes to be run. (default: null)\n * @returns True if the post processes were able to be run.\n * @internal\n */\n _prepareFrame(sourceTexture = null, postProcesses = null) {\n const camera = this._scene.activeCamera;\n if (!camera) {\n return false;\n }\n postProcesses = postProcesses || camera._postProcesses.filter((pp) => {\n return pp != null;\n });\n if (!postProcesses || postProcesses.length === 0 || !this._scene.postProcessesEnabled) {\n return false;\n }\n postProcesses[0].activate(camera, sourceTexture, postProcesses !== null && postProcesses !== undefined);\n return true;\n }\n /**\n * Manually render a set of post processes to a texture.\n * Please note, the frame buffer won't be unbound after the call in case you have more render to do.\n * @param postProcesses An array of post processes to be run.\n * @param targetTexture The render target wrapper to render to.\n * @param forceFullscreenViewport force gl.viewport to be full screen eg. 0,0,textureWidth,textureHeight\n * @param faceIndex defines the face to render to if a cubemap is defined as the target\n * @param lodLevel defines which lod of the texture to render to\n * @param doNotBindFrambuffer If set to true, assumes that the framebuffer has been bound previously\n */\n directRender(postProcesses, targetTexture = null, forceFullscreenViewport = false, faceIndex = 0, lodLevel = 0, doNotBindFrambuffer = false) {\n var _a;\n const engine = this._scene.getEngine();\n for (let index = 0; index < postProcesses.length; index++) {\n if (index < postProcesses.length - 1) {\n postProcesses[index + 1].activate(this._scene.activeCamera, targetTexture === null || targetTexture === void 0 ? void 0 : targetTexture.texture);\n }\n else {\n if (targetTexture) {\n engine.bindFramebuffer(targetTexture, faceIndex, undefined, undefined, forceFullscreenViewport, lodLevel);\n }\n else if (!doNotBindFrambuffer) {\n engine.restoreDefaultFramebuffer();\n }\n (_a = engine._debugInsertMarker) === null || _a === void 0 ? void 0 : _a.call(engine, `post process ${postProcesses[index].name} output`);\n }\n const pp = postProcesses[index];\n const effect = pp.apply();\n if (effect) {\n pp.onBeforeRenderObservable.notifyObservers(effect);\n // VBOs\n this._prepareBuffers();\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\n // Draw order\n engine.drawElementsType(0, 0, 6);\n pp.onAfterRenderObservable.notifyObservers(effect);\n }\n }\n // Restore depth buffer\n engine.setDepthBuffer(true);\n engine.setDepthWrite(true);\n }\n /**\n * Finalize the result of the output of the postprocesses.\n * @param doNotPresent If true the result will not be displayed to the screen.\n * @param targetTexture The render target wrapper to render to.\n * @param faceIndex The index of the face to bind the target texture to.\n * @param postProcesses The array of post processes to render.\n * @param forceFullscreenViewport force gl.viewport to be full screen eg. 0,0,textureWidth,textureHeight (default: false)\n * @internal\n */\n _finalizeFrame(doNotPresent, targetTexture, faceIndex, postProcesses, forceFullscreenViewport = false) {\n var _a;\n const camera = this._scene.activeCamera;\n if (!camera) {\n return;\n }\n postProcesses = postProcesses || camera._postProcesses.filter((pp) => {\n return pp != null;\n });\n if (postProcesses.length === 0 || !this._scene.postProcessesEnabled) {\n return;\n }\n const engine = this._scene.getEngine();\n for (let index = 0, len = postProcesses.length; index < len; index++) {\n const pp = postProcesses[index];\n if (index < len - 1) {\n pp._outputTexture = postProcesses[index + 1].activate(camera, targetTexture === null || targetTexture === void 0 ? void 0 : targetTexture.texture);\n }\n else {\n if (targetTexture) {\n engine.bindFramebuffer(targetTexture, faceIndex, undefined, undefined, forceFullscreenViewport);\n pp._outputTexture = targetTexture;\n }\n else {\n engine.restoreDefaultFramebuffer();\n pp._outputTexture = null;\n }\n (_a = engine._debugInsertMarker) === null || _a === void 0 ? void 0 : _a.call(engine, `post process ${postProcesses[index].name} output`);\n }\n if (doNotPresent) {\n break;\n }\n const effect = pp.apply();\n if (effect) {\n pp.onBeforeRenderObservable.notifyObservers(effect);\n // VBOs\n this._prepareBuffers();\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\n // Draw order\n engine.drawElementsType(0, 0, 6);\n pp.onAfterRenderObservable.notifyObservers(effect);\n }\n }\n // Restore states\n engine.setDepthBuffer(true);\n engine.setDepthWrite(true);\n engine.setAlphaMode(0);\n }\n /**\n * Disposes of the post process manager.\n */\n dispose() {\n const buffer = this._vertexBuffers[VertexBuffer.PositionKind];\n if (buffer) {\n buffer.dispose();\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\n }\n if (this._indexBuffer) {\n this._scene.getEngine()._releaseBuffer(this._indexBuffer);\n this._indexBuffer = null;\n }\n }\n }\n\n /**\n * This represents the object necessary to create a rendering group.\n * This is exclusively used and created by the rendering manager.\n * To modify the behavior, you use the available helpers in your scene or meshes.\n * @internal\n */\n class RenderingGroup {\n /**\n * Set the opaque sort comparison function.\n * If null the sub meshes will be render in the order they were created\n */\n set opaqueSortCompareFn(value) {\n if (value) {\n this._opaqueSortCompareFn = value;\n }\n else {\n this._opaqueSortCompareFn = RenderingGroup.PainterSortCompare;\n }\n this._renderOpaque = this._renderOpaqueSorted;\n }\n /**\n * Set the alpha test sort comparison function.\n * If null the sub meshes will be render in the order they were created\n */\n set alphaTestSortCompareFn(value) {\n if (value) {\n this._alphaTestSortCompareFn = value;\n }\n else {\n this._alphaTestSortCompareFn = RenderingGroup.PainterSortCompare;\n }\n this._renderAlphaTest = this._renderAlphaTestSorted;\n }\n /**\n * Set the transparent sort comparison function.\n * If null the sub meshes will be render in the order they were created\n */\n set transparentSortCompareFn(value) {\n if (value) {\n this._transparentSortCompareFn = value;\n }\n else {\n this._transparentSortCompareFn = RenderingGroup.defaultTransparentSortCompare;\n }\n this._renderTransparent = this._renderTransparentSorted;\n }\n /**\n * Creates a new rendering group.\n * @param index The rendering group index\n * @param scene\n * @param opaqueSortCompareFn The opaque sort comparison function. If null no order is applied\n * @param alphaTestSortCompareFn The alpha test sort comparison function. If null no order is applied\n * @param transparentSortCompareFn The transparent sort comparison function. If null back to front + alpha index sort is applied\n */\n constructor(index, scene, opaqueSortCompareFn = null, alphaTestSortCompareFn = null, transparentSortCompareFn = null) {\n this.index = index;\n this._opaqueSubMeshes = new SmartArray(256);\n this._transparentSubMeshes = new SmartArray(256);\n this._alphaTestSubMeshes = new SmartArray(256);\n this._depthOnlySubMeshes = new SmartArray(256);\n this._particleSystems = new SmartArray(256);\n this._spriteManagers = new SmartArray(256);\n /** @internal */\n this._empty = true;\n /** @internal */\n this._edgesRenderers = new SmartArrayNoDuplicate(16);\n this._scene = scene;\n this.opaqueSortCompareFn = opaqueSortCompareFn;\n this.alphaTestSortCompareFn = alphaTestSortCompareFn;\n this.transparentSortCompareFn = transparentSortCompareFn;\n }\n /**\n * Render all the sub meshes contained in the group.\n * @param customRenderFunction Used to override the default render behaviour of the group.\n * @param renderSprites\n * @param renderParticles\n * @param activeMeshes\n * @returns true if rendered some submeshes.\n */\n render(customRenderFunction, renderSprites, renderParticles, activeMeshes) {\n if (customRenderFunction) {\n customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes, this._depthOnlySubMeshes);\n return;\n }\n const engine = this._scene.getEngine();\n // Depth only\n if (this._depthOnlySubMeshes.length !== 0) {\n engine.setColorWrite(false);\n this._renderAlphaTest(this._depthOnlySubMeshes);\n engine.setColorWrite(true);\n }\n // Opaque\n if (this._opaqueSubMeshes.length !== 0) {\n this._renderOpaque(this._opaqueSubMeshes);\n }\n // Alpha test\n if (this._alphaTestSubMeshes.length !== 0) {\n this._renderAlphaTest(this._alphaTestSubMeshes);\n }\n const stencilState = engine.getStencilBuffer();\n engine.setStencilBuffer(false);\n // Sprites\n if (renderSprites) {\n this._renderSprites();\n }\n // Particles\n if (renderParticles) {\n this._renderParticles(activeMeshes);\n }\n if (this.onBeforeTransparentRendering) {\n this.onBeforeTransparentRendering();\n }\n // Transparent\n if (this._transparentSubMeshes.length !== 0 || this._scene.useOrderIndependentTransparency) {\n engine.setStencilBuffer(stencilState);\n if (this._scene.useOrderIndependentTransparency) {\n const excludedMeshes = this._scene.depthPeelingRenderer.render(this._transparentSubMeshes);\n if (excludedMeshes.length) {\n // Render leftover meshes that could not be processed by depth peeling\n this._renderTransparent(excludedMeshes);\n }\n }\n else {\n this._renderTransparent(this._transparentSubMeshes);\n }\n engine.setAlphaMode(0);\n }\n // Set back stencil to false in case it changes before the edge renderer.\n engine.setStencilBuffer(false);\n // Edges\n if (this._edgesRenderers.length) {\n for (let edgesRendererIndex = 0; edgesRendererIndex < this._edgesRenderers.length; edgesRendererIndex++) {\n this._edgesRenderers.data[edgesRendererIndex].render();\n }\n engine.setAlphaMode(0);\n }\n // Restore Stencil state.\n engine.setStencilBuffer(stencilState);\n }\n /**\n * Renders the opaque submeshes in the order from the opaqueSortCompareFn.\n * @param subMeshes The submeshes to render\n */\n _renderOpaqueSorted(subMeshes) {\n return RenderingGroup._RenderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false);\n }\n /**\n * Renders the opaque submeshes in the order from the alphatestSortCompareFn.\n * @param subMeshes The submeshes to render\n */\n _renderAlphaTestSorted(subMeshes) {\n return RenderingGroup._RenderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false);\n }\n /**\n * Renders the opaque submeshes in the order from the transparentSortCompareFn.\n * @param subMeshes The submeshes to render\n */\n _renderTransparentSorted(subMeshes) {\n return RenderingGroup._RenderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true);\n }\n /**\n * Renders the submeshes in a specified order.\n * @param subMeshes The submeshes to sort before render\n * @param sortCompareFn The comparison function use to sort\n * @param camera The camera position use to preprocess the submeshes to help sorting\n * @param transparent Specifies to activate blending if true\n */\n static _RenderSorted(subMeshes, sortCompareFn, camera, transparent) {\n let subIndex = 0;\n let subMesh;\n const cameraPosition = camera ? camera.globalPosition : RenderingGroup._ZeroVector;\n if (transparent) {\n for (; subIndex < subMeshes.length; subIndex++) {\n subMesh = subMeshes.data[subIndex];\n subMesh._alphaIndex = subMesh.getMesh().alphaIndex;\n subMesh._distanceToCamera = Vector3.Distance(subMesh.getBoundingInfo().boundingSphere.centerWorld, cameraPosition);\n }\n }\n const sortedArray = subMeshes.length === subMeshes.data.length ? subMeshes.data : subMeshes.data.slice(0, subMeshes.length);\n if (sortCompareFn) {\n sortedArray.sort(sortCompareFn);\n }\n const scene = sortedArray[0].getMesh().getScene();\n for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {\n subMesh = sortedArray[subIndex];\n if (scene._activeMeshesFrozenButKeepClipping && !subMesh.isInFrustum(scene._frustumPlanes)) {\n continue;\n }\n if (transparent) {\n const material = subMesh.getMaterial();\n if (material && material.needDepthPrePass) {\n const engine = material.getScene().getEngine();\n engine.setColorWrite(false);\n engine.setAlphaMode(0);\n subMesh.render(false);\n engine.setColorWrite(true);\n }\n }\n subMesh.render(transparent);\n }\n }\n /**\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\n * are rendered back to front if in the same alpha index.\n *\n * @param a The first submesh\n * @param b The second submesh\n * @returns The result of the comparison\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static defaultTransparentSortCompare(a, b) {\n // Alpha index first\n if (a._alphaIndex > b._alphaIndex) {\n return 1;\n }\n if (a._alphaIndex < b._alphaIndex) {\n return -1;\n }\n // Then distance to camera\n return RenderingGroup.backToFrontSortCompare(a, b);\n }\n /**\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\n * are rendered back to front.\n *\n * @param a The first submesh\n * @param b The second submesh\n * @returns The result of the comparison\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static backToFrontSortCompare(a, b) {\n // Then distance to camera\n if (a._distanceToCamera < b._distanceToCamera) {\n return 1;\n }\n if (a._distanceToCamera > b._distanceToCamera) {\n return -1;\n }\n return 0;\n }\n /**\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\n * are rendered front to back (prevent overdraw).\n *\n * @param a The first submesh\n * @param b The second submesh\n * @returns The result of the comparison\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static frontToBackSortCompare(a, b) {\n // Then distance to camera\n if (a._distanceToCamera < b._distanceToCamera) {\n return -1;\n }\n if (a._distanceToCamera > b._distanceToCamera) {\n return 1;\n }\n return 0;\n }\n /**\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\n * are grouped by material then geometry.\n *\n * @param a The first submesh\n * @param b The second submesh\n * @returns The result of the comparison\n */\n static PainterSortCompare(a, b) {\n const meshA = a.getMesh();\n const meshB = b.getMesh();\n if (meshA.material && meshB.material) {\n return meshA.material.uniqueId - meshB.material.uniqueId;\n }\n return meshA.uniqueId - meshB.uniqueId;\n }\n /**\n * Resets the different lists of submeshes to prepare a new frame.\n */\n prepare() {\n this._opaqueSubMeshes.reset();\n this._transparentSubMeshes.reset();\n this._alphaTestSubMeshes.reset();\n this._depthOnlySubMeshes.reset();\n this._particleSystems.reset();\n this.prepareSprites();\n this._edgesRenderers.reset();\n this._empty = true;\n }\n /**\n * Resets the different lists of sprites to prepare a new frame.\n */\n prepareSprites() {\n this._spriteManagers.reset();\n }\n dispose() {\n this._opaqueSubMeshes.dispose();\n this._transparentSubMeshes.dispose();\n this._alphaTestSubMeshes.dispose();\n this._depthOnlySubMeshes.dispose();\n this._particleSystems.dispose();\n this._spriteManagers.dispose();\n this._edgesRenderers.dispose();\n }\n /**\n * Inserts the submesh in its correct queue depending on its material.\n * @param subMesh The submesh to dispatch\n * @param [mesh] Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.\n * @param [material] Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.\n */\n dispatch(subMesh, mesh, material) {\n // Get mesh and materials if not provided\n if (mesh === undefined) {\n mesh = subMesh.getMesh();\n }\n if (material === undefined) {\n material = subMesh.getMaterial();\n }\n if (material === null || material === undefined) {\n return;\n }\n if (material.needAlphaBlendingForMesh(mesh)) {\n // Transparent\n this._transparentSubMeshes.push(subMesh);\n }\n else if (material.needAlphaTesting()) {\n // Alpha test\n if (material.needDepthPrePass) {\n this._depthOnlySubMeshes.push(subMesh);\n }\n this._alphaTestSubMeshes.push(subMesh);\n }\n else {\n if (material.needDepthPrePass) {\n this._depthOnlySubMeshes.push(subMesh);\n }\n this._opaqueSubMeshes.push(subMesh); // Opaque\n }\n mesh._renderingGroup = this;\n if (mesh._edgesRenderer && mesh._edgesRenderer.isEnabled) {\n this._edgesRenderers.pushNoDuplicate(mesh._edgesRenderer);\n }\n this._empty = false;\n }\n dispatchSprites(spriteManager) {\n this._spriteManagers.push(spriteManager);\n this._empty = false;\n }\n dispatchParticles(particleSystem) {\n this._particleSystems.push(particleSystem);\n this._empty = false;\n }\n _renderParticles(activeMeshes) {\n if (this._particleSystems.length === 0) {\n return;\n }\n // Particles\n const activeCamera = this._scene.activeCamera;\n this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);\n for (let particleIndex = 0; particleIndex < this._particleSystems.length; particleIndex++) {\n const particleSystem = this._particleSystems.data[particleIndex];\n if ((activeCamera && activeCamera.layerMask & particleSystem.layerMask) === 0) {\n continue;\n }\n const emitter = particleSystem.emitter;\n if (!emitter.position || !activeMeshes || activeMeshes.indexOf(emitter) !== -1) {\n this._scene._activeParticles.addCount(particleSystem.render(), false);\n }\n }\n this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene);\n }\n _renderSprites() {\n if (!this._scene.spritesEnabled || this._spriteManagers.length === 0) {\n return;\n }\n // Sprites\n const activeCamera = this._scene.activeCamera;\n this._scene.onBeforeSpritesRenderingObservable.notifyObservers(this._scene);\n for (let id = 0; id < this._spriteManagers.length; id++) {\n const spriteManager = this._spriteManagers.data[id];\n if ((activeCamera && activeCamera.layerMask & spriteManager.layerMask) !== 0) {\n spriteManager.render();\n }\n }\n this._scene.onAfterSpritesRenderingObservable.notifyObservers(this._scene);\n }\n }\n RenderingGroup._ZeroVector = Vector3.Zero();\n\n /**\n * This class is used by the onRenderingGroupObservable\n */\n class RenderingGroupInfo {\n }\n /**\n * This is the manager responsible of all the rendering for meshes sprites and particles.\n * It is enable to manage the different groups as well as the different necessary sort functions.\n * This should not be used directly aside of the few static configurations\n */\n class RenderingManager {\n /**\n * Gets or sets a boolean indicating that the manager will not reset between frames.\n * This means that if a mesh becomes invisible or transparent it will not be visible until this boolean is set to false again.\n * By default, the rendering manager will dispatch all active meshes per frame (moving them to the transparent, opaque or alpha testing lists).\n * By turning this property on, you will accelerate the rendering by keeping all these lists unchanged between frames.\n */\n get maintainStateBetweenFrames() {\n return this._maintainStateBetweenFrames;\n }\n set maintainStateBetweenFrames(value) {\n if (value === this._maintainStateBetweenFrames) {\n return;\n }\n this._maintainStateBetweenFrames = value;\n // Restore wasDispatched flags when switching to maintainStateBetweenFrames to false\n if (!this._maintainStateBetweenFrames) {\n for (const mesh of this._scene.meshes) {\n if (mesh.subMeshes) {\n for (const subMesh of mesh.subMeshes) {\n subMesh._wasDispatched = false;\n }\n }\n }\n if (this._scene.spriteManagers) {\n for (const spriteManager of this._scene.spriteManagers) {\n spriteManager._wasDispatched = false;\n }\n }\n for (const particleSystem of this._scene.particleSystems) {\n particleSystem._wasDispatched = false;\n }\n }\n }\n /**\n * Instantiates a new rendering group for a particular scene\n * @param scene Defines the scene the groups belongs to\n */\n constructor(scene) {\n /**\n * @internal\n */\n this._useSceneAutoClearSetup = false;\n this._renderingGroups = new Array();\n this._autoClearDepthStencil = {};\n this._customOpaqueSortCompareFn = {};\n this._customAlphaTestSortCompareFn = {};\n this._customTransparentSortCompareFn = {};\n this._renderingGroupInfo = new RenderingGroupInfo();\n this._maintainStateBetweenFrames = false;\n this._scene = scene;\n for (let i = RenderingManager.MIN_RENDERINGGROUPS; i < RenderingManager.MAX_RENDERINGGROUPS; i++) {\n this._autoClearDepthStencil[i] = { autoClear: true, depth: true, stencil: true };\n }\n }\n /**\n * Gets the rendering group with the specified id.\n */\n getRenderingGroup(id) {\n const renderingGroupId = id || 0;\n this._prepareRenderingGroup(renderingGroupId);\n return this._renderingGroups[renderingGroupId];\n }\n _clearDepthStencilBuffer(depth = true, stencil = true) {\n if (this._depthStencilBufferAlreadyCleaned) {\n return;\n }\n this._scene.getEngine().clear(null, false, depth, stencil);\n this._depthStencilBufferAlreadyCleaned = true;\n }\n /**\n * Renders the entire managed groups. This is used by the scene or the different render targets.\n * @internal\n */\n render(customRenderFunction, activeMeshes, renderParticles, renderSprites) {\n // Update the observable context (not null as it only goes away on dispose)\n const info = this._renderingGroupInfo;\n info.scene = this._scene;\n info.camera = this._scene.activeCamera;\n // Dispatch sprites\n if (this._scene.spriteManagers && renderSprites) {\n for (let index = 0; index < this._scene.spriteManagers.length; index++) {\n const manager = this._scene.spriteManagers[index];\n this.dispatchSprites(manager);\n }\n }\n // Render\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\n this._depthStencilBufferAlreadyCleaned = index === RenderingManager.MIN_RENDERINGGROUPS;\n const renderingGroup = this._renderingGroups[index];\n if (!renderingGroup || renderingGroup._empty) {\n continue;\n }\n const renderingGroupMask = Math.pow(2, index);\n info.renderingGroupId = index;\n // Before Observable\n this._scene.onBeforeRenderingGroupObservable.notifyObservers(info, renderingGroupMask);\n // Clear depth/stencil if needed\n if (RenderingManager.AUTOCLEAR) {\n const autoClear = this._useSceneAutoClearSetup ? this._scene.getAutoClearDepthStencilSetup(index) : this._autoClearDepthStencil[index];\n if (autoClear && autoClear.autoClear) {\n this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);\n }\n }\n // Render\n for (const step of this._scene._beforeRenderingGroupDrawStage) {\n step.action(index);\n }\n renderingGroup.render(customRenderFunction, renderSprites, renderParticles, activeMeshes);\n for (const step of this._scene._afterRenderingGroupDrawStage) {\n step.action(index);\n }\n // After Observable\n this._scene.onAfterRenderingGroupObservable.notifyObservers(info, renderingGroupMask);\n }\n }\n /**\n * Resets the different information of the group to prepare a new frame\n * @internal\n */\n reset() {\n if (this.maintainStateBetweenFrames) {\n return;\n }\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\n const renderingGroup = this._renderingGroups[index];\n if (renderingGroup) {\n renderingGroup.prepare();\n }\n }\n }\n /**\n * Resets the sprites information of the group to prepare a new frame\n * @internal\n */\n resetSprites() {\n if (this.maintainStateBetweenFrames) {\n return;\n }\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\n const renderingGroup = this._renderingGroups[index];\n if (renderingGroup) {\n renderingGroup.prepareSprites();\n }\n }\n }\n /**\n * Dispose and release the group and its associated resources.\n * @internal\n */\n dispose() {\n this.freeRenderingGroups();\n this._renderingGroups.length = 0;\n this._renderingGroupInfo = null;\n }\n /**\n * Clear the info related to rendering groups preventing retention points during dispose.\n */\n freeRenderingGroups() {\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\n const renderingGroup = this._renderingGroups[index];\n if (renderingGroup) {\n renderingGroup.dispose();\n }\n }\n }\n _prepareRenderingGroup(renderingGroupId) {\n if (this._renderingGroups[renderingGroupId] === undefined) {\n this._renderingGroups[renderingGroupId] = new RenderingGroup(renderingGroupId, this._scene, this._customOpaqueSortCompareFn[renderingGroupId], this._customAlphaTestSortCompareFn[renderingGroupId], this._customTransparentSortCompareFn[renderingGroupId]);\n }\n }\n /**\n * Add a sprite manager to the rendering manager in order to render it this frame.\n * @param spriteManager Define the sprite manager to render\n */\n dispatchSprites(spriteManager) {\n if (this.maintainStateBetweenFrames && spriteManager._wasDispatched) {\n return;\n }\n spriteManager._wasDispatched = true;\n this.getRenderingGroup(spriteManager.renderingGroupId).dispatchSprites(spriteManager);\n }\n /**\n * Add a particle system to the rendering manager in order to render it this frame.\n * @param particleSystem Define the particle system to render\n */\n dispatchParticles(particleSystem) {\n if (this.maintainStateBetweenFrames && particleSystem._wasDispatched) {\n return;\n }\n particleSystem._wasDispatched = true;\n this.getRenderingGroup(particleSystem.renderingGroupId).dispatchParticles(particleSystem);\n }\n /**\n * Add a submesh to the manager in order to render it this frame\n * @param subMesh The submesh to dispatch\n * @param mesh Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.\n * @param material Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.\n */\n dispatch(subMesh, mesh, material) {\n if (mesh === undefined) {\n mesh = subMesh.getMesh();\n }\n if (this.maintainStateBetweenFrames && subMesh._wasDispatched) {\n return;\n }\n subMesh._wasDispatched = true;\n this.getRenderingGroup(mesh.renderingGroupId).dispatch(subMesh, mesh, material);\n }\n /**\n * Overrides the default sort function applied in the rendering group to prepare the meshes.\n * This allowed control for front to back rendering or reversely depending of the special needs.\n *\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param opaqueSortCompareFn The opaque queue comparison function use to sort.\n * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.\n * @param transparentSortCompareFn The transparent queue comparison function use to sort.\n */\n setRenderingOrder(renderingGroupId, opaqueSortCompareFn = null, alphaTestSortCompareFn = null, transparentSortCompareFn = null) {\n this._customOpaqueSortCompareFn[renderingGroupId] = opaqueSortCompareFn;\n this._customAlphaTestSortCompareFn[renderingGroupId] = alphaTestSortCompareFn;\n this._customTransparentSortCompareFn[renderingGroupId] = transparentSortCompareFn;\n if (this._renderingGroups[renderingGroupId]) {\n const group = this._renderingGroups[renderingGroupId];\n group.opaqueSortCompareFn = this._customOpaqueSortCompareFn[renderingGroupId];\n group.alphaTestSortCompareFn = this._customAlphaTestSortCompareFn[renderingGroupId];\n group.transparentSortCompareFn = this._customTransparentSortCompareFn[renderingGroupId];\n }\n }\n /**\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.\n *\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\n * @param depth Automatically clears depth between groups if true and autoClear is true.\n * @param stencil Automatically clears stencil between groups if true and autoClear is true.\n */\n setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil, depth = true, stencil = true) {\n this._autoClearDepthStencil[renderingGroupId] = {\n autoClear: autoClearDepthStencil,\n depth: depth,\n stencil: stencil,\n };\n }\n /**\n * Gets the current auto clear configuration for one rendering group of the rendering\n * manager.\n * @param index the rendering group index to get the information for\n * @returns The auto clear setup for the requested rendering group\n */\n getAutoClearDepthStencilSetup(index) {\n return this._autoClearDepthStencil[index];\n }\n }\n /**\n * The max id used for rendering groups (not included)\n */\n RenderingManager.MAX_RENDERINGGROUPS = 4;\n /**\n * The min id used for rendering groups (included)\n */\n RenderingManager.MIN_RENDERINGGROUPS = 0;\n /**\n * Used to globally prevent autoclearing scenes.\n */\n RenderingManager.AUTOCLEAR = true;\n\n /**\n * Groups all the scene component constants in one place to ease maintenance.\n * @internal\n */\n class SceneComponentConstants {\n }\n SceneComponentConstants.NAME_EFFECTLAYER = \"EffectLayer\";\n SceneComponentConstants.NAME_LAYER = \"Layer\";\n SceneComponentConstants.NAME_LENSFLARESYSTEM = \"LensFlareSystem\";\n SceneComponentConstants.NAME_BOUNDINGBOXRENDERER = \"BoundingBoxRenderer\";\n SceneComponentConstants.NAME_PARTICLESYSTEM = \"ParticleSystem\";\n SceneComponentConstants.NAME_GAMEPAD = \"Gamepad\";\n SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE = \"SimplificationQueue\";\n SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER = \"GeometryBufferRenderer\";\n SceneComponentConstants.NAME_PREPASSRENDERER = \"PrePassRenderer\";\n SceneComponentConstants.NAME_DEPTHRENDERER = \"DepthRenderer\";\n SceneComponentConstants.NAME_DEPTHPEELINGRENDERER = \"DepthPeelingRenderer\";\n SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER = \"PostProcessRenderPipelineManager\";\n SceneComponentConstants.NAME_SPRITE = \"Sprite\";\n SceneComponentConstants.NAME_SUBSURFACE = \"SubSurface\";\n SceneComponentConstants.NAME_OUTLINERENDERER = \"Outline\";\n SceneComponentConstants.NAME_PROCEDURALTEXTURE = \"ProceduralTexture\";\n SceneComponentConstants.NAME_SHADOWGENERATOR = \"ShadowGenerator\";\n SceneComponentConstants.NAME_OCTREE = \"Octree\";\n SceneComponentConstants.NAME_PHYSICSENGINE = \"PhysicsEngine\";\n SceneComponentConstants.NAME_AUDIO = \"Audio\";\n SceneComponentConstants.NAME_FLUIDRENDERER = \"FluidRenderer\";\n SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER = 0;\n SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER = 0;\n SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER = 0;\n SceneComponentConstants.STEP_PREACTIVEMESH_BOUNDINGBOXRENDERER = 0;\n SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER = 1;\n SceneComponentConstants.STEP_BEFORECAMERADRAW_PREPASS = 0;\n SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER = 1;\n SceneComponentConstants.STEP_BEFORECAMERADRAW_LAYER = 2;\n SceneComponentConstants.STEP_BEFORERENDERTARGETDRAW_PREPASS = 0;\n SceneComponentConstants.STEP_BEFORERENDERTARGETDRAW_LAYER = 1;\n SceneComponentConstants.STEP_BEFORERENDERINGMESH_PREPASS = 0;\n SceneComponentConstants.STEP_BEFORERENDERINGMESH_OUTLINE = 1;\n SceneComponentConstants.STEP_AFTERRENDERINGMESH_PREPASS = 0;\n SceneComponentConstants.STEP_AFTERRENDERINGMESH_OUTLINE = 1;\n SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW = 0;\n SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_BOUNDINGBOXRENDERER = 1;\n SceneComponentConstants.STEP_BEFORECAMERAUPDATE_SIMPLIFICATIONQUEUE = 0;\n SceneComponentConstants.STEP_BEFORECAMERAUPDATE_GAMEPAD = 1;\n SceneComponentConstants.STEP_BEFORECLEAR_PROCEDURALTEXTURE = 0;\n SceneComponentConstants.STEP_BEFORECLEAR_PREPASS = 1;\n SceneComponentConstants.STEP_BEFORERENDERTARGETCLEAR_PREPASS = 0;\n SceneComponentConstants.STEP_AFTERRENDERTARGETDRAW_PREPASS = 0;\n SceneComponentConstants.STEP_AFTERRENDERTARGETDRAW_LAYER = 1;\n SceneComponentConstants.STEP_AFTERCAMERADRAW_PREPASS = 0;\n SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER = 1;\n SceneComponentConstants.STEP_AFTERCAMERADRAW_LENSFLARESYSTEM = 2;\n SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;\n SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 4;\n SceneComponentConstants.STEP_AFTERCAMERADRAW_FLUIDRENDERER = 5;\n SceneComponentConstants.STEP_AFTERCAMERAPOSTPROCESS_LAYER = 0;\n SceneComponentConstants.STEP_AFTERRENDERTARGETPOSTPROCESS_LAYER = 0;\n SceneComponentConstants.STEP_AFTERRENDER_AUDIO = 0;\n SceneComponentConstants.STEP_GATHERRENDERTARGETS_DEPTHRENDERER = 0;\n SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER = 1;\n SceneComponentConstants.STEP_GATHERRENDERTARGETS_SHADOWGENERATOR = 2;\n SceneComponentConstants.STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER = 3;\n SceneComponentConstants.STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER = 0;\n SceneComponentConstants.STEP_GATHERACTIVECAMERARENDERTARGETS_FLUIDRENDERER = 1;\n SceneComponentConstants.STEP_POINTERMOVE_SPRITE = 0;\n SceneComponentConstants.STEP_POINTERDOWN_SPRITE = 0;\n SceneComponentConstants.STEP_POINTERUP_SPRITE = 0;\n /**\n * Representation of a stage in the scene (Basically a list of ordered steps)\n * @internal\n */\n class Stage extends Array {\n /**\n * Hide ctor from the rest of the world.\n * @param items The items to add.\n */\n constructor(items) {\n super(...items);\n }\n /**\n * Creates a new Stage.\n * @returns A new instance of a Stage\n */\n static Create() {\n return Object.create(Stage.prototype);\n }\n /**\n * Registers a step in an ordered way in the targeted stage.\n * @param index Defines the position to register the step in\n * @param component Defines the component attached to the step\n * @param action Defines the action to launch during the step\n */\n registerStep(index, component, action) {\n let i = 0;\n let maxIndex = Number.MAX_VALUE;\n for (; i < this.length; i++) {\n const step = this[i];\n maxIndex = step.index;\n if (index < maxIndex) {\n break;\n }\n }\n this.splice(i, 0, { index, component, action: action.bind(component) });\n }\n /**\n * Clears all the steps from the stage.\n */\n clear() {\n this.length = 0;\n }\n }\n\n /**\n * Gather the list of pointer event types as constants.\n */\n class PointerEventTypes {\n }\n /**\n * The pointerdown event is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons depressed to at least one button depressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer.\n */\n PointerEventTypes.POINTERDOWN = 0x01;\n /**\n * The pointerup event is fired when a pointer is no longer active.\n */\n PointerEventTypes.POINTERUP = 0x02;\n /**\n * The pointermove event is fired when a pointer changes coordinates.\n */\n PointerEventTypes.POINTERMOVE = 0x04;\n /**\n * The pointerwheel event is fired when a mouse wheel has been rotated.\n */\n PointerEventTypes.POINTERWHEEL = 0x08;\n /**\n * The pointerpick event is fired when a mesh or sprite has been picked by the pointer.\n */\n PointerEventTypes.POINTERPICK = 0x10;\n /**\n * The pointertap event is fired when a the object has been touched and released without drag.\n */\n PointerEventTypes.POINTERTAP = 0x20;\n /**\n * The pointerdoubletap event is fired when a the object has been touched and released twice without drag.\n */\n PointerEventTypes.POINTERDOUBLETAP = 0x40;\n /**\n * Base class of pointer info types.\n */\n class PointerInfoBase {\n /**\n * Instantiates the base class of pointers info.\n * @param type Defines the type of event (PointerEventTypes)\n * @param event Defines the related dom event\n */\n constructor(\n /**\n * Defines the type of event (PointerEventTypes)\n */\n type, \n /**\n * Defines the related dom event\n */\n event) {\n this.type = type;\n this.event = event;\n }\n }\n /**\n * This class is used to store pointer related info for the onPrePointerObservable event.\n * Set the skipOnPointerObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onPointerObservable\n */\n class PointerInfoPre extends PointerInfoBase {\n /**\n * Instantiates a PointerInfoPre to store pointer related info to the onPrePointerObservable event.\n * @param type Defines the type of event (PointerEventTypes)\n * @param event Defines the related dom event\n * @param localX Defines the local x coordinates of the pointer when the event occured\n * @param localY Defines the local y coordinates of the pointer when the event occured\n */\n constructor(type, event, localX, localY) {\n super(type, event);\n /**\n * Ray from a pointer if available (eg. 6dof controller)\n */\n this.ray = null;\n /**\n * The original picking info that was used to trigger the pointer event\n */\n this.originalPickingInfo = null;\n this.skipOnPointerObservable = false;\n this.localPosition = new Vector2(localX, localY);\n }\n }\n /**\n * This type contains all the data related to a pointer event in Babylon.js.\n * The event member is an instance of PointerEvent for all types except PointerWheel and is of type MouseWheelEvent when type equals PointerWheel. The different event types can be found in the PointerEventTypes class.\n */\n class PointerInfo extends PointerInfoBase {\n /**\n * Defines the picking info associated with this PointerInfo object (if applicable)\n */\n get pickInfo() {\n if (!this._pickInfo) {\n this._generatePickInfo();\n }\n return this._pickInfo;\n }\n /**\n * Instantiates a PointerInfo to store pointer related info to the onPointerObservable event.\n * @param type Defines the type of event (PointerEventTypes)\n * @param event Defines the related dom event\n * @param pickInfo Defines the picking info associated to the info (if any)\n * @param inputManager Defines the InputManager to use if there is no pickInfo\n */\n constructor(type, event, pickInfo, inputManager = null) {\n super(type, event);\n this._pickInfo = pickInfo;\n this._inputManager = inputManager;\n }\n /**\n * Generates the picking info if needed\n */\n /** @internal */\n _generatePickInfo() {\n if (this._inputManager) {\n this._pickInfo = this._inputManager._pickMove(this.event);\n this._inputManager._setRayOnPointerInfo(this._pickInfo, this.event);\n this._inputManager = null;\n }\n }\n }\n\n /**\n * Abstract class used to decouple action Manager from scene and meshes.\n * Do not instantiate.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions\n */\n class AbstractActionManager {\n constructor() {\n /** Gets the cursor to use when hovering items */\n this.hoverCursor = \"\";\n /** Gets the list of actions */\n this.actions = new Array();\n /**\n * Gets or sets a boolean indicating that the manager is recursive meaning that it can trigger action from children\n */\n this.isRecursive = false;\n }\n /**\n * Does exist one action manager with at least one trigger\n **/\n static get HasTriggers() {\n for (const t in AbstractActionManager.Triggers) {\n if (Object.prototype.hasOwnProperty.call(AbstractActionManager.Triggers, t)) {\n return true;\n }\n }\n return false;\n }\n /**\n * Does exist one action manager with at least one pick trigger\n **/\n static get HasPickTriggers() {\n for (const t in AbstractActionManager.Triggers) {\n if (Object.prototype.hasOwnProperty.call(AbstractActionManager.Triggers, t)) {\n const tAsInt = parseInt(t);\n if (tAsInt >= 1 && tAsInt <= 7) {\n return true;\n }\n }\n }\n return false;\n }\n /**\n * Does exist one action manager that handles actions of a given trigger\n * @param trigger defines the trigger to be tested\n * @returns a boolean indicating whether the trigger is handled by at least one action manager\n **/\n static HasSpecificTrigger(trigger) {\n for (const t in AbstractActionManager.Triggers) {\n if (Object.prototype.hasOwnProperty.call(AbstractActionManager.Triggers, t)) {\n const tAsInt = parseInt(t);\n if (tAsInt === trigger) {\n return true;\n }\n }\n }\n return false;\n }\n }\n /** Gets the list of active triggers */\n AbstractActionManager.Triggers = {};\n\n /**\n * Gather the list of keyboard event types as constants.\n */\n class KeyboardEventTypes {\n }\n /**\n * The keydown event is fired when a key becomes active (pressed).\n */\n KeyboardEventTypes.KEYDOWN = 0x01;\n /**\n * The keyup event is fired when a key has been released.\n */\n KeyboardEventTypes.KEYUP = 0x02;\n /**\n * This class is used to store keyboard related info for the onKeyboardObservable event.\n */\n class KeyboardInfo {\n /**\n * Instantiates a new keyboard info.\n * This class is used to store keyboard related info for the onKeyboardObservable event.\n * @param type Defines the type of event (KeyboardEventTypes)\n * @param event Defines the related dom event\n */\n constructor(\n /**\n * Defines the type of event (KeyboardEventTypes)\n */\n type, \n /**\n * Defines the related dom event\n */\n event) {\n this.type = type;\n this.event = event;\n }\n }\n /**\n * This class is used to store keyboard related info for the onPreKeyboardObservable event.\n * Set the skipOnKeyboardObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onKeyboardObservable\n */\n class KeyboardInfoPre extends KeyboardInfo {\n /**\n * Defines whether the engine should skip the next onKeyboardObservable associated to this pre.\n * @deprecated use skipOnKeyboardObservable property instead\n */\n get skipOnPointerObservable() {\n return this.skipOnKeyboardObservable;\n }\n set skipOnPointerObservable(value) {\n this.skipOnKeyboardObservable = value;\n }\n /**\n * Instantiates a new keyboard pre info.\n * This class is used to store keyboard related info for the onPreKeyboardObservable event.\n * @param type Defines the type of event (KeyboardEventTypes)\n * @param event Defines the related dom event\n */\n constructor(\n /**\n * Defines the type of event (KeyboardEventTypes)\n */\n type, \n /**\n * Defines the related dom event\n */\n event) {\n super(type, event);\n this.type = type;\n this.event = event;\n this.skipOnKeyboardObservable = false;\n }\n }\n\n /**\n * Enum for Device Types\n */\n var DeviceType;\n (function (DeviceType) {\n /** Generic */\n DeviceType[DeviceType[\"Generic\"] = 0] = \"Generic\";\n /** Keyboard */\n DeviceType[DeviceType[\"Keyboard\"] = 1] = \"Keyboard\";\n /** Mouse */\n DeviceType[DeviceType[\"Mouse\"] = 2] = \"Mouse\";\n /** Touch Pointers */\n DeviceType[DeviceType[\"Touch\"] = 3] = \"Touch\";\n /** PS4 Dual Shock */\n DeviceType[DeviceType[\"DualShock\"] = 4] = \"DualShock\";\n /** Xbox */\n DeviceType[DeviceType[\"Xbox\"] = 5] = \"Xbox\";\n /** Switch Controller */\n DeviceType[DeviceType[\"Switch\"] = 6] = \"Switch\";\n /** PS5 DualSense */\n DeviceType[DeviceType[\"DualSense\"] = 7] = \"DualSense\";\n })(DeviceType || (DeviceType = {}));\n // Device Enums\n /**\n * Enum for All Pointers (Touch/Mouse)\n */\n var PointerInput;\n (function (PointerInput) {\n /** Horizontal Axis (Not used in events/observables; only in polling) */\n PointerInput[PointerInput[\"Horizontal\"] = 0] = \"Horizontal\";\n /** Vertical Axis (Not used in events/observables; only in polling) */\n PointerInput[PointerInput[\"Vertical\"] = 1] = \"Vertical\";\n /** Left Click or Touch */\n PointerInput[PointerInput[\"LeftClick\"] = 2] = \"LeftClick\";\n /** Middle Click */\n PointerInput[PointerInput[\"MiddleClick\"] = 3] = \"MiddleClick\";\n /** Right Click */\n PointerInput[PointerInput[\"RightClick\"] = 4] = \"RightClick\";\n /** Browser Back */\n PointerInput[PointerInput[\"BrowserBack\"] = 5] = \"BrowserBack\";\n /** Browser Forward */\n PointerInput[PointerInput[\"BrowserForward\"] = 6] = \"BrowserForward\";\n /** Mouse Wheel X */\n PointerInput[PointerInput[\"MouseWheelX\"] = 7] = \"MouseWheelX\";\n /** Mouse Wheel Y */\n PointerInput[PointerInput[\"MouseWheelY\"] = 8] = \"MouseWheelY\";\n /** Mouse Wheel Z */\n PointerInput[PointerInput[\"MouseWheelZ\"] = 9] = \"MouseWheelZ\";\n /** Used in events/observables to identify if x/y changes occurred */\n PointerInput[PointerInput[\"Move\"] = 12] = \"Move\";\n })(PointerInput || (PointerInput = {}));\n /** @internal */\n var NativePointerInput;\n (function (NativePointerInput) {\n /** Horizontal Axis */\n NativePointerInput[NativePointerInput[\"Horizontal\"] = 0] = \"Horizontal\";\n /** Vertical Axis */\n NativePointerInput[NativePointerInput[\"Vertical\"] = 1] = \"Vertical\";\n /** Left Click or Touch */\n NativePointerInput[NativePointerInput[\"LeftClick\"] = 2] = \"LeftClick\";\n /** Middle Click */\n NativePointerInput[NativePointerInput[\"MiddleClick\"] = 3] = \"MiddleClick\";\n /** Right Click */\n NativePointerInput[NativePointerInput[\"RightClick\"] = 4] = \"RightClick\";\n /** Browser Back */\n NativePointerInput[NativePointerInput[\"BrowserBack\"] = 5] = \"BrowserBack\";\n /** Browser Forward */\n NativePointerInput[NativePointerInput[\"BrowserForward\"] = 6] = \"BrowserForward\";\n /** Mouse Wheel X */\n NativePointerInput[NativePointerInput[\"MouseWheelX\"] = 7] = \"MouseWheelX\";\n /** Mouse Wheel Y */\n NativePointerInput[NativePointerInput[\"MouseWheelY\"] = 8] = \"MouseWheelY\";\n /** Mouse Wheel Z */\n NativePointerInput[NativePointerInput[\"MouseWheelZ\"] = 9] = \"MouseWheelZ\";\n /** Delta X */\n NativePointerInput[NativePointerInput[\"DeltaHorizontal\"] = 10] = \"DeltaHorizontal\";\n /** Delta Y */\n NativePointerInput[NativePointerInput[\"DeltaVertical\"] = 11] = \"DeltaVertical\";\n })(NativePointerInput || (NativePointerInput = {}));\n /**\n * Enum for Dual Shock Gamepad\n */\n var DualShockInput;\n (function (DualShockInput) {\n /** Cross */\n DualShockInput[DualShockInput[\"Cross\"] = 0] = \"Cross\";\n /** Circle */\n DualShockInput[DualShockInput[\"Circle\"] = 1] = \"Circle\";\n /** Square */\n DualShockInput[DualShockInput[\"Square\"] = 2] = \"Square\";\n /** Triangle */\n DualShockInput[DualShockInput[\"Triangle\"] = 3] = \"Triangle\";\n /** L1 */\n DualShockInput[DualShockInput[\"L1\"] = 4] = \"L1\";\n /** R1 */\n DualShockInput[DualShockInput[\"R1\"] = 5] = \"R1\";\n /** L2 */\n DualShockInput[DualShockInput[\"L2\"] = 6] = \"L2\";\n /** R2 */\n DualShockInput[DualShockInput[\"R2\"] = 7] = \"R2\";\n /** Share */\n DualShockInput[DualShockInput[\"Share\"] = 8] = \"Share\";\n /** Options */\n DualShockInput[DualShockInput[\"Options\"] = 9] = \"Options\";\n /** L3 */\n DualShockInput[DualShockInput[\"L3\"] = 10] = \"L3\";\n /** R3 */\n DualShockInput[DualShockInput[\"R3\"] = 11] = \"R3\";\n /** DPadUp */\n DualShockInput[DualShockInput[\"DPadUp\"] = 12] = \"DPadUp\";\n /** DPadDown */\n DualShockInput[DualShockInput[\"DPadDown\"] = 13] = \"DPadDown\";\n /** DPadLeft */\n DualShockInput[DualShockInput[\"DPadLeft\"] = 14] = \"DPadLeft\";\n /** DRight */\n DualShockInput[DualShockInput[\"DPadRight\"] = 15] = \"DPadRight\";\n /** Home */\n DualShockInput[DualShockInput[\"Home\"] = 16] = \"Home\";\n /** TouchPad */\n DualShockInput[DualShockInput[\"TouchPad\"] = 17] = \"TouchPad\";\n /** LStickXAxis */\n DualShockInput[DualShockInput[\"LStickXAxis\"] = 18] = \"LStickXAxis\";\n /** LStickYAxis */\n DualShockInput[DualShockInput[\"LStickYAxis\"] = 19] = \"LStickYAxis\";\n /** RStickXAxis */\n DualShockInput[DualShockInput[\"RStickXAxis\"] = 20] = \"RStickXAxis\";\n /** RStickYAxis */\n DualShockInput[DualShockInput[\"RStickYAxis\"] = 21] = \"RStickYAxis\";\n })(DualShockInput || (DualShockInput = {}));\n /**\n * Enum for Dual Sense Gamepad\n */\n var DualSenseInput;\n (function (DualSenseInput) {\n /** Cross */\n DualSenseInput[DualSenseInput[\"Cross\"] = 0] = \"Cross\";\n /** Circle */\n DualSenseInput[DualSenseInput[\"Circle\"] = 1] = \"Circle\";\n /** Square */\n DualSenseInput[DualSenseInput[\"Square\"] = 2] = \"Square\";\n /** Triangle */\n DualSenseInput[DualSenseInput[\"Triangle\"] = 3] = \"Triangle\";\n /** L1 */\n DualSenseInput[DualSenseInput[\"L1\"] = 4] = \"L1\";\n /** R1 */\n DualSenseInput[DualSenseInput[\"R1\"] = 5] = \"R1\";\n /** L2 */\n DualSenseInput[DualSenseInput[\"L2\"] = 6] = \"L2\";\n /** R2 */\n DualSenseInput[DualSenseInput[\"R2\"] = 7] = \"R2\";\n /** Create */\n DualSenseInput[DualSenseInput[\"Create\"] = 8] = \"Create\";\n /** Options */\n DualSenseInput[DualSenseInput[\"Options\"] = 9] = \"Options\";\n /** L3 */\n DualSenseInput[DualSenseInput[\"L3\"] = 10] = \"L3\";\n /** R3 */\n DualSenseInput[DualSenseInput[\"R3\"] = 11] = \"R3\";\n /** DPadUp */\n DualSenseInput[DualSenseInput[\"DPadUp\"] = 12] = \"DPadUp\";\n /** DPadDown */\n DualSenseInput[DualSenseInput[\"DPadDown\"] = 13] = \"DPadDown\";\n /** DPadLeft */\n DualSenseInput[DualSenseInput[\"DPadLeft\"] = 14] = \"DPadLeft\";\n /** DRight */\n DualSenseInput[DualSenseInput[\"DPadRight\"] = 15] = \"DPadRight\";\n /** Home */\n DualSenseInput[DualSenseInput[\"Home\"] = 16] = \"Home\";\n /** TouchPad */\n DualSenseInput[DualSenseInput[\"TouchPad\"] = 17] = \"TouchPad\";\n /** LStickXAxis */\n DualSenseInput[DualSenseInput[\"LStickXAxis\"] = 18] = \"LStickXAxis\";\n /** LStickYAxis */\n DualSenseInput[DualSenseInput[\"LStickYAxis\"] = 19] = \"LStickYAxis\";\n /** RStickXAxis */\n DualSenseInput[DualSenseInput[\"RStickXAxis\"] = 20] = \"RStickXAxis\";\n /** RStickYAxis */\n DualSenseInput[DualSenseInput[\"RStickYAxis\"] = 21] = \"RStickYAxis\";\n })(DualSenseInput || (DualSenseInput = {}));\n /**\n * Enum for Xbox Gamepad\n */\n var XboxInput;\n (function (XboxInput) {\n /** A */\n XboxInput[XboxInput[\"A\"] = 0] = \"A\";\n /** B */\n XboxInput[XboxInput[\"B\"] = 1] = \"B\";\n /** X */\n XboxInput[XboxInput[\"X\"] = 2] = \"X\";\n /** Y */\n XboxInput[XboxInput[\"Y\"] = 3] = \"Y\";\n /** LB */\n XboxInput[XboxInput[\"LB\"] = 4] = \"LB\";\n /** RB */\n XboxInput[XboxInput[\"RB\"] = 5] = \"RB\";\n /** LT */\n XboxInput[XboxInput[\"LT\"] = 6] = \"LT\";\n /** RT */\n XboxInput[XboxInput[\"RT\"] = 7] = \"RT\";\n /** Back */\n XboxInput[XboxInput[\"Back\"] = 8] = \"Back\";\n /** Start */\n XboxInput[XboxInput[\"Start\"] = 9] = \"Start\";\n /** LS */\n XboxInput[XboxInput[\"LS\"] = 10] = \"LS\";\n /** RS */\n XboxInput[XboxInput[\"RS\"] = 11] = \"RS\";\n /** DPadUp */\n XboxInput[XboxInput[\"DPadUp\"] = 12] = \"DPadUp\";\n /** DPadDown */\n XboxInput[XboxInput[\"DPadDown\"] = 13] = \"DPadDown\";\n /** DPadLeft */\n XboxInput[XboxInput[\"DPadLeft\"] = 14] = \"DPadLeft\";\n /** DRight */\n XboxInput[XboxInput[\"DPadRight\"] = 15] = \"DPadRight\";\n /** Home */\n XboxInput[XboxInput[\"Home\"] = 16] = \"Home\";\n /** LStickXAxis */\n XboxInput[XboxInput[\"LStickXAxis\"] = 17] = \"LStickXAxis\";\n /** LStickYAxis */\n XboxInput[XboxInput[\"LStickYAxis\"] = 18] = \"LStickYAxis\";\n /** RStickXAxis */\n XboxInput[XboxInput[\"RStickXAxis\"] = 19] = \"RStickXAxis\";\n /** RStickYAxis */\n XboxInput[XboxInput[\"RStickYAxis\"] = 20] = \"RStickYAxis\";\n })(XboxInput || (XboxInput = {}));\n /**\n * Enum for Switch (Pro/JoyCon L+R) Gamepad\n */\n var SwitchInput;\n (function (SwitchInput) {\n /** B */\n SwitchInput[SwitchInput[\"B\"] = 0] = \"B\";\n /** A */\n SwitchInput[SwitchInput[\"A\"] = 1] = \"A\";\n /** Y */\n SwitchInput[SwitchInput[\"Y\"] = 2] = \"Y\";\n /** X */\n SwitchInput[SwitchInput[\"X\"] = 3] = \"X\";\n /** L */\n SwitchInput[SwitchInput[\"L\"] = 4] = \"L\";\n /** R */\n SwitchInput[SwitchInput[\"R\"] = 5] = \"R\";\n /** ZL */\n SwitchInput[SwitchInput[\"ZL\"] = 6] = \"ZL\";\n /** ZR */\n SwitchInput[SwitchInput[\"ZR\"] = 7] = \"ZR\";\n /** Minus */\n SwitchInput[SwitchInput[\"Minus\"] = 8] = \"Minus\";\n /** Plus */\n SwitchInput[SwitchInput[\"Plus\"] = 9] = \"Plus\";\n /** LS */\n SwitchInput[SwitchInput[\"LS\"] = 10] = \"LS\";\n /** RS */\n SwitchInput[SwitchInput[\"RS\"] = 11] = \"RS\";\n /** DPadUp */\n SwitchInput[SwitchInput[\"DPadUp\"] = 12] = \"DPadUp\";\n /** DPadDown */\n SwitchInput[SwitchInput[\"DPadDown\"] = 13] = \"DPadDown\";\n /** DPadLeft */\n SwitchInput[SwitchInput[\"DPadLeft\"] = 14] = \"DPadLeft\";\n /** DRight */\n SwitchInput[SwitchInput[\"DPadRight\"] = 15] = \"DPadRight\";\n /** Home */\n SwitchInput[SwitchInput[\"Home\"] = 16] = \"Home\";\n /** Capture */\n SwitchInput[SwitchInput[\"Capture\"] = 17] = \"Capture\";\n /** LStickXAxis */\n SwitchInput[SwitchInput[\"LStickXAxis\"] = 18] = \"LStickXAxis\";\n /** LStickYAxis */\n SwitchInput[SwitchInput[\"LStickYAxis\"] = 19] = \"LStickYAxis\";\n /** RStickXAxis */\n SwitchInput[SwitchInput[\"RStickXAxis\"] = 20] = \"RStickXAxis\";\n /** RStickYAxis */\n SwitchInput[SwitchInput[\"RStickYAxis\"] = 21] = \"RStickYAxis\";\n })(SwitchInput || (SwitchInput = {}));\n\n /**\n * Event Types\n */\n var DeviceInputEventType;\n (function (DeviceInputEventType) {\n // Pointers\n /** PointerMove */\n DeviceInputEventType[DeviceInputEventType[\"PointerMove\"] = 0] = \"PointerMove\";\n /** PointerDown */\n DeviceInputEventType[DeviceInputEventType[\"PointerDown\"] = 1] = \"PointerDown\";\n /** PointerUp */\n DeviceInputEventType[DeviceInputEventType[\"PointerUp\"] = 2] = \"PointerUp\";\n })(DeviceInputEventType || (DeviceInputEventType = {}));\n /**\n * Constants used for Events\n */\n class EventConstants {\n }\n /**\n * Pixel delta for Wheel Events (Default)\n */\n EventConstants.DOM_DELTA_PIXEL = 0x00;\n /**\n * Line delta for Wheel Events\n */\n EventConstants.DOM_DELTA_LINE = 0x01;\n /**\n * Page delta for Wheel Events\n */\n EventConstants.DOM_DELTA_PAGE = 0x02;\n\n /**\n * Class to wrap DeviceInputSystem data into an event object\n */\n class DeviceEventFactory {\n /**\n * Create device input events based on provided type and slot\n *\n * @param deviceType Type of device\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n * @param currentState Current value for given input\n * @param deviceInputSystem Reference to DeviceInputSystem\n * @param elementToAttachTo HTMLElement to reference as target for inputs\n * @returns IUIEvent object\n */\n static CreateDeviceEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo, pointerId) {\n switch (deviceType) {\n case DeviceType.Keyboard:\n return this._CreateKeyboardEvent(inputIndex, currentState, deviceInputSystem, elementToAttachTo);\n case DeviceType.Mouse:\n if (inputIndex === PointerInput.MouseWheelX || inputIndex === PointerInput.MouseWheelY || inputIndex === PointerInput.MouseWheelZ) {\n return this._CreateWheelEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo);\n }\n // eslint-disable-next-line no-fallthrough\n case DeviceType.Touch:\n return this._CreatePointerEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo, pointerId);\n default:\n throw `Unable to generate event for device ${DeviceType[deviceType]}`;\n }\n }\n /**\n * Creates pointer event\n *\n * @param deviceType Type of device\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n * @param currentState Current value for given input\n * @param deviceInputSystem Reference to DeviceInputSystem\n * @param elementToAttachTo HTMLElement to reference as target for inputs\n * @returns IUIEvent object (Pointer)\n */\n static _CreatePointerEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo, pointerId) {\n const evt = this._CreateMouseEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo);\n if (deviceType === DeviceType.Mouse) {\n evt.deviceType = DeviceType.Mouse;\n evt.pointerId = 1;\n evt.pointerType = \"mouse\";\n }\n else {\n evt.deviceType = DeviceType.Touch;\n evt.pointerId = pointerId !== null && pointerId !== void 0 ? pointerId : deviceSlot;\n evt.pointerType = \"touch\";\n }\n let buttons = 0;\n // Populate buttons property with current state of all mouse buttons\n // Uses values found on: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n buttons += deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.LeftClick);\n buttons += deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.RightClick) * 2;\n buttons += deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.MiddleClick) * 4;\n evt.buttons = buttons;\n if (inputIndex === PointerInput.Move) {\n evt.type = \"pointermove\";\n }\n else if (inputIndex >= PointerInput.LeftClick && inputIndex <= PointerInput.RightClick) {\n evt.type = currentState === 1 ? \"pointerdown\" : \"pointerup\";\n evt.button = inputIndex - 2;\n }\n return evt;\n }\n /**\n * Create Mouse Wheel Event\n * @param deviceType Type of device\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n * @param currentState Current value for given input\n * @param deviceInputSystem Reference to DeviceInputSystem\n * @param elementToAttachTo HTMLElement to reference as target for inputs\n * @returns IUIEvent object (Wheel)\n */\n static _CreateWheelEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo) {\n const evt = this._CreateMouseEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo);\n // While WheelEvents don't generally have a pointerId, we used to add one in the InputManager\n // This line has been added to make the InputManager more platform-agnostic\n // Similar code exists in the WebDeviceInputSystem to handle browser created events\n evt.pointerId = 1;\n evt.type = \"wheel\";\n evt.deltaMode = EventConstants.DOM_DELTA_PIXEL;\n evt.deltaX = 0;\n evt.deltaY = 0;\n evt.deltaZ = 0;\n switch (inputIndex) {\n case PointerInput.MouseWheelX:\n evt.deltaX = currentState;\n break;\n case PointerInput.MouseWheelY:\n evt.deltaY = currentState;\n break;\n case PointerInput.MouseWheelZ:\n evt.deltaZ = currentState;\n break;\n }\n return evt;\n }\n /**\n * Create Mouse Event\n * @param deviceType Type of device\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n * @param currentState Current value for given input\n * @param deviceInputSystem Reference to DeviceInputSystem\n * @param elementToAttachTo HTMLElement to reference as target for inputs\n * @returns IUIEvent object (Mouse)\n */\n static _CreateMouseEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo) {\n const evt = this._CreateEvent(elementToAttachTo);\n const pointerX = deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.Horizontal);\n const pointerY = deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.Vertical);\n // Handle offsets/deltas based on existence of HTMLElement\n if (elementToAttachTo) {\n evt.movementX = 0;\n evt.movementY = 0;\n evt.offsetX = evt.movementX - elementToAttachTo.getBoundingClientRect().x;\n evt.offsetY = evt.movementY - elementToAttachTo.getBoundingClientRect().y;\n }\n else {\n evt.movementX = deviceInputSystem.pollInput(deviceType, deviceSlot, NativePointerInput.DeltaHorizontal); // DeltaHorizontal\n evt.movementY = deviceInputSystem.pollInput(deviceType, deviceSlot, NativePointerInput.DeltaVertical); // DeltaVertical\n evt.offsetX = 0;\n evt.offsetY = 0;\n }\n this._CheckNonCharacterKeys(evt, deviceInputSystem);\n evt.clientX = pointerX;\n evt.clientY = pointerY;\n evt.x = pointerX;\n evt.y = pointerY;\n evt.deviceType = deviceType;\n evt.deviceSlot = deviceSlot;\n evt.inputIndex = inputIndex;\n return evt;\n }\n /**\n * Create Keyboard Event\n * @param inputIndex Id of input to be checked\n * @param currentState Current value for given input\n * @param deviceInputSystem Reference to DeviceInputSystem\n * @param elementToAttachTo HTMLElement to reference as target for inputs\n * @returns IEvent object (Keyboard)\n */\n static _CreateKeyboardEvent(inputIndex, currentState, deviceInputSystem, elementToAttachTo) {\n const evt = this._CreateEvent(elementToAttachTo);\n this._CheckNonCharacterKeys(evt, deviceInputSystem);\n evt.deviceType = DeviceType.Keyboard;\n evt.deviceSlot = 0;\n evt.inputIndex = inputIndex;\n evt.type = currentState === 1 ? \"keydown\" : \"keyup\";\n evt.key = String.fromCharCode(inputIndex);\n evt.keyCode = inputIndex;\n return evt;\n }\n /**\n * Add parameters for non-character keys (Ctrl, Alt, Meta, Shift)\n * @param evt Event object to add parameters to\n * @param deviceInputSystem DeviceInputSystem to pull values from\n */\n static _CheckNonCharacterKeys(evt, deviceInputSystem) {\n const isKeyboardActive = deviceInputSystem.isDeviceAvailable(DeviceType.Keyboard);\n const altKey = isKeyboardActive && deviceInputSystem.pollInput(DeviceType.Keyboard, 0, 18) === 1;\n const ctrlKey = isKeyboardActive && deviceInputSystem.pollInput(DeviceType.Keyboard, 0, 17) === 1;\n const metaKey = isKeyboardActive &&\n (deviceInputSystem.pollInput(DeviceType.Keyboard, 0, 91) === 1 ||\n deviceInputSystem.pollInput(DeviceType.Keyboard, 0, 92) === 1 ||\n deviceInputSystem.pollInput(DeviceType.Keyboard, 0, 93) === 1);\n const shiftKey = isKeyboardActive && deviceInputSystem.pollInput(DeviceType.Keyboard, 0, 16) === 1;\n evt.altKey = altKey;\n evt.ctrlKey = ctrlKey;\n evt.metaKey = metaKey;\n evt.shiftKey = shiftKey;\n }\n /**\n * Create base event object\n * @param elementToAttachTo Value to use as event target\n * @returns\n */\n static _CreateEvent(elementToAttachTo) {\n const evt = {};\n evt.preventDefault = () => { };\n evt.target = elementToAttachTo;\n return evt;\n }\n }\n\n /** @internal */\n class NativeDeviceInputSystem {\n constructor(onDeviceConnected, onDeviceDisconnected, onInputChanged) {\n this._nativeInput = _native.DeviceInputSystem\n ? new _native.DeviceInputSystem(onDeviceConnected, onDeviceDisconnected, (deviceType, deviceSlot, inputIndex, currentState) => {\n const evt = DeviceEventFactory.CreateDeviceEvent(deviceType, deviceSlot, inputIndex, currentState, this);\n onInputChanged(deviceType, deviceSlot, evt);\n })\n : this._createDummyNativeInput();\n }\n // Public functions\n /**\n * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.\n * @param deviceType Enum specifying device type\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n * @returns Current value of input\n */\n pollInput(deviceType, deviceSlot, inputIndex) {\n return this._nativeInput.pollInput(deviceType, deviceSlot, inputIndex);\n }\n /**\n * Check for a specific device in the DeviceInputSystem\n * @param deviceType Type of device to check for\n * @returns bool with status of device's existence\n */\n isDeviceAvailable(deviceType) {\n //TODO: FIx native side first\n return deviceType === DeviceType.Mouse || deviceType === DeviceType.Touch;\n }\n /**\n * Dispose of all the observables\n */\n dispose() {\n this._nativeInput.dispose();\n }\n /**\n * For versions of BabylonNative that don't have the NativeInput plugin initialized, create a dummy version\n * @returns Object with dummy functions\n */\n _createDummyNativeInput() {\n const nativeInput = {\n pollInput: () => {\n return 0;\n },\n isDeviceAvailable: () => {\n return false;\n },\n dispose: () => { },\n };\n return nativeInput;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const MAX_KEYCODES = 255;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const MAX_POINTER_INPUTS = Object.keys(PointerInput).length / 2;\n /** @internal */\n class WebDeviceInputSystem {\n constructor(engine, onDeviceConnected, onDeviceDisconnected, onInputChanged) {\n // Private Members\n this._inputs = [];\n this._keyboardActive = false;\n this._pointerActive = false;\n this._usingSafari = Tools.IsSafari();\n // Found solution for determining if MacOS is being used here:\n // https://stackoverflow.com/questions/10527983/best-way-to-detect-mac-os-x-or-windows-computers-with-javascript-or-jquery\n this._usingMacOS = IsNavigatorAvailable() && /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._keyboardDownEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._keyboardUpEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._keyboardBlurEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._pointerMoveEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._pointerDownEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._pointerUpEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._pointerCancelEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._pointerWheelEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._pointerBlurEvent = (evt) => { };\n this._eventsAttached = false;\n this._mouseId = -1;\n this._isUsingFirefox = IsNavigatorAvailable() && navigator.userAgent && navigator.userAgent.indexOf(\"Firefox\") !== -1;\n this._maxTouchPoints = 0;\n this._pointerInputClearObserver = null;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._gamepadConnectedEvent = (evt) => { };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._gamepadDisconnectedEvent = (evt) => { };\n this._eventPrefix = Tools.GetPointerPrefix(engine);\n this._engine = engine;\n this._onDeviceConnected = onDeviceConnected;\n this._onDeviceDisconnected = onDeviceDisconnected;\n this._onInputChanged = onInputChanged;\n // If we need a pointerId, set one for future use\n this._mouseId = this._isUsingFirefox ? 0 : 1;\n this._enableEvents();\n if (this._usingMacOS) {\n this._metaKeys = [];\n }\n // Set callback to enable event handler switching when inputElement changes\n if (!this._engine._onEngineViewChanged) {\n this._engine._onEngineViewChanged = () => {\n this._enableEvents();\n };\n }\n }\n // Public functions\n /**\n * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.\n * @param deviceType Enum specifying device type\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n * @returns Current value of input\n */\n pollInput(deviceType, deviceSlot, inputIndex) {\n const device = this._inputs[deviceType][deviceSlot];\n if (!device) {\n throw `Unable to find device ${DeviceType[deviceType]}`;\n }\n if (deviceType >= DeviceType.DualShock && deviceType <= DeviceType.DualSense) {\n this._updateDevice(deviceType, deviceSlot, inputIndex);\n }\n const currentValue = device[inputIndex];\n if (currentValue === undefined) {\n throw `Unable to find input ${inputIndex} for device ${DeviceType[deviceType]} in slot ${deviceSlot}`;\n }\n if (inputIndex === PointerInput.Move) {\n Tools.Warn(`Unable to provide information for PointerInput.Move. Try using PointerInput.Horizontal or PointerInput.Vertical for move data.`);\n }\n return currentValue;\n }\n /**\n * Check for a specific device in the DeviceInputSystem\n * @param deviceType Type of device to check for\n * @returns bool with status of device's existence\n */\n isDeviceAvailable(deviceType) {\n return this._inputs[deviceType] !== undefined;\n }\n /**\n * Dispose of all the eventlisteners\n */\n dispose() {\n // Callbacks\n this._onDeviceConnected = () => { };\n this._onDeviceDisconnected = () => { };\n this._onInputChanged = () => { };\n delete this._engine._onEngineViewChanged;\n if (this._elementToAttachTo) {\n this._disableEvents();\n }\n }\n /**\n * Enable listening for user input events\n */\n _enableEvents() {\n const inputElement = this === null || this === void 0 ? void 0 : this._engine.getInputElement();\n if (inputElement && (!this._eventsAttached || this._elementToAttachTo !== inputElement)) {\n // Remove events before adding to avoid double events or simultaneous events on multiple canvases\n this._disableEvents();\n // If the inputs array has already been created, zero it out to before setting up events\n if (this._inputs) {\n for (const inputs of this._inputs) {\n if (inputs) {\n for (const deviceSlotKey in inputs) {\n const deviceSlot = +deviceSlotKey;\n const device = inputs[deviceSlot];\n if (device) {\n for (let inputIndex = 0; inputIndex < device.length; inputIndex++) {\n device[inputIndex] = 0;\n }\n }\n }\n }\n }\n }\n this._elementToAttachTo = inputElement;\n // Set tab index for the inputElement to the engine's canvasTabIndex, if and only if the element's tab index is -1\n this._elementToAttachTo.tabIndex = this._elementToAttachTo.tabIndex !== -1 ? this._elementToAttachTo.tabIndex : this._engine.canvasTabIndex;\n this._handleKeyActions();\n this._handlePointerActions();\n this._handleGamepadActions();\n this._eventsAttached = true;\n // Check for devices that are already connected but aren't registered. Currently, only checks for gamepads and mouse\n this._checkForConnectedDevices();\n }\n }\n /**\n * Disable listening for user input events\n */\n _disableEvents() {\n if (this._elementToAttachTo) {\n // Blur Events\n this._elementToAttachTo.removeEventListener(\"blur\", this._keyboardBlurEvent);\n this._elementToAttachTo.removeEventListener(\"blur\", this._pointerBlurEvent);\n // Keyboard Events\n this._elementToAttachTo.removeEventListener(\"keydown\", this._keyboardDownEvent);\n this._elementToAttachTo.removeEventListener(\"keyup\", this._keyboardUpEvent);\n // Pointer Events\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"move\", this._pointerMoveEvent);\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"down\", this._pointerDownEvent);\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"up\", this._pointerUpEvent);\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"cancel\", this._pointerCancelEvent);\n this._elementToAttachTo.removeEventListener(this._wheelEventName, this._pointerWheelEvent);\n // Gamepad Events\n window.removeEventListener(\"gamepadconnected\", this._gamepadConnectedEvent);\n window.removeEventListener(\"gamepaddisconnected\", this._gamepadDisconnectedEvent);\n }\n if (this._pointerInputClearObserver) {\n this._engine.onEndFrameObservable.remove(this._pointerInputClearObserver);\n }\n this._eventsAttached = false;\n }\n /**\n * Checks for existing connections to devices and register them, if necessary\n * Currently handles gamepads and mouse\n */\n _checkForConnectedDevices() {\n if (navigator.getGamepads) {\n const gamepads = navigator.getGamepads();\n for (const gamepad of gamepads) {\n if (gamepad) {\n this._addGamePad(gamepad);\n }\n }\n }\n // If the device in use has mouse capabilities, pre-register mouse\n if (typeof matchMedia === \"function\" && matchMedia(\"(pointer:fine)\").matches) {\n // This will provide a dummy value for the cursor position and is expected to be overridden when the first mouse event happens.\n // There isn't any good way to get the current position outside of a pointer event so that's why this was done.\n this._addPointerDevice(DeviceType.Mouse, 0, 0, 0);\n }\n }\n // Private functions\n /**\n * Add a gamepad to the DeviceInputSystem\n * @param gamepad A single DOM Gamepad object\n */\n _addGamePad(gamepad) {\n const deviceType = this._getGamepadDeviceType(gamepad.id);\n const deviceSlot = gamepad.index;\n this._gamepads = this._gamepads || new Array(gamepad.index + 1);\n this._registerDevice(deviceType, deviceSlot, gamepad.buttons.length + gamepad.axes.length);\n this._gamepads[deviceSlot] = deviceType;\n }\n /**\n * Add pointer device to DeviceInputSystem\n * @param deviceType Type of Pointer to add\n * @param deviceSlot Pointer ID (0 for mouse, pointerId for Touch)\n * @param currentX Current X at point of adding\n * @param currentY Current Y at point of adding\n */\n _addPointerDevice(deviceType, deviceSlot, currentX, currentY) {\n if (!this._pointerActive) {\n this._pointerActive = true;\n }\n this._registerDevice(deviceType, deviceSlot, MAX_POINTER_INPUTS);\n const pointer = this._inputs[deviceType][deviceSlot]; /* initialize our pointer position immediately after registration */\n pointer[0] = currentX;\n pointer[1] = currentY;\n }\n /**\n * Add device and inputs to device array\n * @param deviceType Enum specifying device type\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param numberOfInputs Number of input entries to create for given device\n */\n _registerDevice(deviceType, deviceSlot, numberOfInputs) {\n if (deviceSlot === undefined) {\n throw `Unable to register device ${DeviceType[deviceType]} to undefined slot.`;\n }\n if (!this._inputs[deviceType]) {\n this._inputs[deviceType] = {};\n }\n if (!this._inputs[deviceType][deviceSlot]) {\n const device = new Array(numberOfInputs);\n device.fill(0);\n this._inputs[deviceType][deviceSlot] = device;\n this._onDeviceConnected(deviceType, deviceSlot);\n }\n }\n /**\n * Given a specific device name, remove that device from the device map\n * @param deviceType Enum specifying device type\n * @param deviceSlot \"Slot\" or index that device is referenced in\n */\n _unregisterDevice(deviceType, deviceSlot) {\n if (this._inputs[deviceType][deviceSlot]) {\n delete this._inputs[deviceType][deviceSlot];\n this._onDeviceDisconnected(deviceType, deviceSlot);\n }\n }\n /**\n * Handle all actions that come from keyboard interaction\n */\n _handleKeyActions() {\n this._keyboardDownEvent = (evt) => {\n if (!this._keyboardActive) {\n this._keyboardActive = true;\n this._registerDevice(DeviceType.Keyboard, 0, MAX_KEYCODES);\n }\n const kbKey = this._inputs[DeviceType.Keyboard][0];\n if (kbKey) {\n kbKey[evt.keyCode] = 1;\n const deviceEvent = evt;\n deviceEvent.inputIndex = evt.keyCode;\n if (this._usingMacOS && evt.metaKey && evt.key !== \"Meta\") {\n if (!this._metaKeys.includes(evt.keyCode)) {\n this._metaKeys.push(evt.keyCode);\n }\n }\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\n }\n };\n this._keyboardUpEvent = (evt) => {\n if (!this._keyboardActive) {\n this._keyboardActive = true;\n this._registerDevice(DeviceType.Keyboard, 0, MAX_KEYCODES);\n }\n const kbKey = this._inputs[DeviceType.Keyboard][0];\n if (kbKey) {\n kbKey[evt.keyCode] = 0;\n const deviceEvent = evt;\n deviceEvent.inputIndex = evt.keyCode;\n if (this._usingMacOS && evt.key === \"Meta\" && this._metaKeys.length > 0) {\n for (const keyCode of this._metaKeys) {\n const deviceEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Keyboard, 0, keyCode, 0, this, this._elementToAttachTo);\n kbKey[keyCode] = 0;\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\n }\n this._metaKeys.splice(0, this._metaKeys.length);\n }\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\n }\n };\n this._keyboardBlurEvent = () => {\n if (this._keyboardActive) {\n const kbKey = this._inputs[DeviceType.Keyboard][0];\n for (let i = 0; i < kbKey.length; i++) {\n if (kbKey[i] !== 0) {\n kbKey[i] = 0;\n const deviceEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Keyboard, 0, i, 0, this, this._elementToAttachTo);\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\n }\n }\n if (this._usingMacOS) {\n this._metaKeys.splice(0, this._metaKeys.length);\n }\n }\n };\n this._elementToAttachTo.addEventListener(\"keydown\", this._keyboardDownEvent);\n this._elementToAttachTo.addEventListener(\"keyup\", this._keyboardUpEvent);\n this._elementToAttachTo.addEventListener(\"blur\", this._keyboardBlurEvent);\n }\n /**\n * Handle all actions that come from pointer interaction\n */\n _handlePointerActions() {\n // If maxTouchPoints is defined, use that value. Otherwise, allow for a minimum for supported gestures like pinch\n this._maxTouchPoints = (IsNavigatorAvailable() && navigator.maxTouchPoints) || 2;\n if (!this._activeTouchIds) {\n this._activeTouchIds = new Array(this._maxTouchPoints);\n }\n for (let i = 0; i < this._maxTouchPoints; i++) {\n this._activeTouchIds[i] = -1;\n }\n this._pointerMoveEvent = (evt) => {\n const deviceType = this._getPointerType(evt);\n const deviceSlot = deviceType === DeviceType.Mouse ? 0 : this._activeTouchIds.indexOf(evt.pointerId);\n if (!this._inputs[deviceType]) {\n this._inputs[deviceType] = {};\n }\n if (!this._inputs[deviceType][deviceSlot]) {\n this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);\n }\n const pointer = this._inputs[deviceType][deviceSlot];\n if (pointer) {\n const deviceEvent = evt;\n deviceEvent.inputIndex = PointerInput.Move;\n pointer[PointerInput.Horizontal] = evt.clientX;\n pointer[PointerInput.Vertical] = evt.clientY;\n if (evt.pointerId === undefined) {\n evt.pointerId = this._mouseId;\n }\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n // Lets Propagate the event for move with same position.\n if (!this._usingSafari && evt.button !== -1) {\n deviceEvent.inputIndex = evt.button + 2;\n pointer[evt.button + 2] = pointer[evt.button + 2] ? 0 : 1; // Reverse state of button if evt.button has value\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n }\n }\n };\n this._pointerDownEvent = (evt) => {\n const deviceType = this._getPointerType(evt);\n let deviceSlot = deviceType === DeviceType.Mouse ? 0 : evt.pointerId;\n if (deviceType === DeviceType.Touch) {\n const idx = this._activeTouchIds.indexOf(-1);\n if (idx >= 0) {\n deviceSlot = idx;\n this._activeTouchIds[idx] = evt.pointerId;\n }\n else {\n // We can't find an open slot to store new pointer so just return (can only support max number of touches)\n Tools.Warn(`Max number of touches exceeded. Ignoring touches in excess of ${this._maxTouchPoints}`);\n return;\n }\n }\n if (!this._inputs[deviceType]) {\n this._inputs[deviceType] = {};\n }\n if (!this._inputs[deviceType][deviceSlot]) {\n this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);\n }\n else if (deviceType === DeviceType.Touch) {\n this._onDeviceConnected(deviceType, deviceSlot);\n }\n const pointer = this._inputs[deviceType][deviceSlot];\n if (pointer) {\n const previousHorizontal = pointer[PointerInput.Horizontal];\n const previousVertical = pointer[PointerInput.Vertical];\n if (deviceType === DeviceType.Mouse) {\n // Mouse; Set pointerId if undefined\n if (evt.pointerId === undefined) {\n evt.pointerId = this._mouseId;\n }\n if (!document.pointerLockElement) {\n try {\n this._elementToAttachTo.setPointerCapture(this._mouseId);\n }\n catch (e) {\n // DO NOTHING\n }\n }\n }\n else {\n // Touch; Since touches are dynamically assigned, only set capture if we have an id\n if (evt.pointerId && !document.pointerLockElement) {\n try {\n this._elementToAttachTo.setPointerCapture(evt.pointerId);\n }\n catch (e) {\n // DO NOTHING\n }\n }\n }\n pointer[PointerInput.Horizontal] = evt.clientX;\n pointer[PointerInput.Vertical] = evt.clientY;\n pointer[evt.button + 2] = 1;\n const deviceEvent = evt;\n // NOTE: The +2 used here to is because PointerInput has the same value progression for its mouse buttons as PointerEvent.button\n // However, we have our X and Y values front-loaded to group together the touch inputs but not break this progression\n // EG. ([X, Y, Left-click], Middle-click, etc...)\n deviceEvent.inputIndex = evt.button + 2;\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n if (previousHorizontal !== evt.clientX || previousVertical !== evt.clientY) {\n deviceEvent.inputIndex = PointerInput.Move;\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n }\n }\n };\n this._pointerUpEvent = (evt) => {\n var _a, _b, _c, _d, _e;\n const deviceType = this._getPointerType(evt);\n const deviceSlot = deviceType === DeviceType.Mouse ? 0 : this._activeTouchIds.indexOf(evt.pointerId);\n if (deviceType === DeviceType.Touch) {\n if (deviceSlot === -1) {\n return;\n }\n else {\n this._activeTouchIds[deviceSlot] = -1;\n }\n }\n const pointer = (_a = this._inputs[deviceType]) === null || _a === void 0 ? void 0 : _a[deviceSlot];\n if (pointer && pointer[evt.button + 2] !== 0) {\n const previousHorizontal = pointer[PointerInput.Horizontal];\n const previousVertical = pointer[PointerInput.Vertical];\n pointer[PointerInput.Horizontal] = evt.clientX;\n pointer[PointerInput.Vertical] = evt.clientY;\n pointer[evt.button + 2] = 0;\n const deviceEvent = evt;\n if (evt.pointerId === undefined) {\n evt.pointerId = this._mouseId;\n }\n if (previousHorizontal !== evt.clientX || previousVertical !== evt.clientY) {\n deviceEvent.inputIndex = PointerInput.Move;\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n }\n // NOTE: The +2 used here to is because PointerInput has the same value progression for its mouse buttons as PointerEvent.button\n // However, we have our X and Y values front-loaded to group together the touch inputs but not break this progression\n // EG. ([X, Y, Left-click], Middle-click, etc...)\n deviceEvent.inputIndex = evt.button + 2;\n if (deviceType === DeviceType.Mouse && this._mouseId >= 0 && ((_c = (_b = this._elementToAttachTo).hasPointerCapture) === null || _c === void 0 ? void 0 : _c.call(_b, this._mouseId))) {\n this._elementToAttachTo.releasePointerCapture(this._mouseId);\n }\n else if (evt.pointerId && ((_e = (_d = this._elementToAttachTo).hasPointerCapture) === null || _e === void 0 ? void 0 : _e.call(_d, evt.pointerId))) {\n this._elementToAttachTo.releasePointerCapture(evt.pointerId);\n }\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n if (deviceType === DeviceType.Touch) {\n this._onDeviceDisconnected(deviceType, deviceSlot);\n }\n }\n };\n this._pointerCancelEvent = (evt) => {\n var _a, _b, _c, _d;\n if (evt.pointerType === \"mouse\") {\n const pointer = this._inputs[DeviceType.Mouse][0];\n if (this._mouseId >= 0 && ((_b = (_a = this._elementToAttachTo).hasPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, this._mouseId))) {\n this._elementToAttachTo.releasePointerCapture(this._mouseId);\n }\n for (let inputIndex = PointerInput.LeftClick; inputIndex <= PointerInput.BrowserForward; inputIndex++) {\n if (pointer[inputIndex] === 1) {\n pointer[inputIndex] = 0;\n const deviceEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Mouse, 0, inputIndex, 0, this, this._elementToAttachTo);\n this._onInputChanged(DeviceType.Mouse, 0, deviceEvent);\n }\n }\n }\n else {\n const deviceSlot = this._activeTouchIds.indexOf(evt.pointerId);\n if ((_d = (_c = this._elementToAttachTo).hasPointerCapture) === null || _d === void 0 ? void 0 : _d.call(_c, evt.pointerId)) {\n this._elementToAttachTo.releasePointerCapture(evt.pointerId);\n }\n this._inputs[DeviceType.Touch][deviceSlot][PointerInput.LeftClick] = 0;\n const deviceEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Touch, deviceSlot, PointerInput.LeftClick, 0, this, this._elementToAttachTo, evt.pointerId);\n this._onInputChanged(DeviceType.Touch, deviceSlot, deviceEvent);\n this._activeTouchIds[deviceSlot] = -1;\n this._onDeviceDisconnected(DeviceType.Touch, deviceSlot);\n }\n };\n // Set Wheel Event Name, code originally from scene.inputManager\n this._wheelEventName =\n \"onwheel\" in document.createElement(\"div\")\n ? \"wheel\" // Modern browsers support \"wheel\"\n : document.onmousewheel !== undefined\n ? \"mousewheel\" // Webkit and IE support at least \"mousewheel\"\n : \"DOMMouseScroll\"; // let's assume that remaining browsers are older Firefox\n // Code originally in scene.inputManager.ts\n // Chrome reports warning in console if wheel listener doesn't set an explicit passive option.\n // IE11 only supports captureEvent:boolean, not options:object, and it defaults to false.\n // Feature detection technique copied from: https://github.com/github/eventlistener-polyfill (MIT license)\n let passiveSupported = false;\n const noop = function () { };\n try {\n const options = Object.defineProperty({}, \"passive\", {\n get: function () {\n passiveSupported = true;\n },\n });\n this._elementToAttachTo.addEventListener(\"test\", noop, options);\n this._elementToAttachTo.removeEventListener(\"test\", noop, options);\n }\n catch (e) {\n /* */\n }\n this._pointerBlurEvent = () => {\n var _a, _b, _c, _d, _e;\n // Handle mouse buttons\n if (this.isDeviceAvailable(DeviceType.Mouse)) {\n const pointer = this._inputs[DeviceType.Mouse][0];\n if (this._mouseId >= 0 && ((_b = (_a = this._elementToAttachTo).hasPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, this._mouseId))) {\n this._elementToAttachTo.releasePointerCapture(this._mouseId);\n }\n for (let inputIndex = PointerInput.LeftClick; inputIndex <= PointerInput.BrowserForward; inputIndex++) {\n if (pointer[inputIndex] === 1) {\n pointer[inputIndex] = 0;\n const deviceEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Mouse, 0, inputIndex, 0, this, this._elementToAttachTo);\n this._onInputChanged(DeviceType.Mouse, 0, deviceEvent);\n }\n }\n }\n // Handle Active Touches\n if (this.isDeviceAvailable(DeviceType.Touch)) {\n const pointer = this._inputs[DeviceType.Touch];\n for (let deviceSlot = 0; deviceSlot < this._activeTouchIds.length; deviceSlot++) {\n const pointerId = this._activeTouchIds[deviceSlot];\n if ((_d = (_c = this._elementToAttachTo).hasPointerCapture) === null || _d === void 0 ? void 0 : _d.call(_c, pointerId)) {\n this._elementToAttachTo.releasePointerCapture(pointerId);\n }\n if (pointerId !== -1 && ((_e = pointer[deviceSlot]) === null || _e === void 0 ? void 0 : _e[PointerInput.LeftClick]) === 1) {\n pointer[deviceSlot][PointerInput.LeftClick] = 0;\n const deviceEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Touch, deviceSlot, PointerInput.LeftClick, 0, this, this._elementToAttachTo, pointerId);\n this._onInputChanged(DeviceType.Touch, deviceSlot, deviceEvent);\n this._activeTouchIds[deviceSlot] = -1;\n this._onDeviceDisconnected(DeviceType.Touch, deviceSlot);\n }\n }\n }\n };\n this._pointerWheelEvent = (evt) => {\n const deviceType = DeviceType.Mouse;\n const deviceSlot = 0;\n if (!this._inputs[deviceType]) {\n this._inputs[deviceType] = [];\n }\n if (!this._inputs[deviceType][deviceSlot]) {\n this._pointerActive = true;\n this._registerDevice(deviceType, deviceSlot, MAX_POINTER_INPUTS);\n }\n const pointer = this._inputs[deviceType][deviceSlot];\n if (pointer) {\n pointer[PointerInput.MouseWheelX] = evt.deltaX || 0;\n pointer[PointerInput.MouseWheelY] = evt.deltaY || evt.wheelDelta || 0;\n pointer[PointerInput.MouseWheelZ] = evt.deltaZ || 0;\n const deviceEvent = evt;\n // By default, there is no pointerId for mouse wheel events so we'll add one here\n // This logic was originally in the InputManager but was added here to make the\n // InputManager more platform-agnostic\n if (evt.pointerId === undefined) {\n evt.pointerId = this._mouseId;\n }\n if (pointer[PointerInput.MouseWheelX] !== 0) {\n deviceEvent.inputIndex = PointerInput.MouseWheelX;\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n }\n if (pointer[PointerInput.MouseWheelY] !== 0) {\n deviceEvent.inputIndex = PointerInput.MouseWheelY;\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n }\n if (pointer[PointerInput.MouseWheelZ] !== 0) {\n deviceEvent.inputIndex = PointerInput.MouseWheelZ;\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\n }\n }\n };\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"move\", this._pointerMoveEvent);\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"down\", this._pointerDownEvent);\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"up\", this._pointerUpEvent);\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"cancel\", this._pointerCancelEvent);\n this._elementToAttachTo.addEventListener(\"blur\", this._pointerBlurEvent);\n this._elementToAttachTo.addEventListener(this._wheelEventName, this._pointerWheelEvent, passiveSupported ? { passive: false } : false);\n // Since there's no up or down event for mouse wheel or delta x/y, clear mouse values at end of frame\n this._pointerInputClearObserver = this._engine.onEndFrameObservable.add(() => {\n if (this.isDeviceAvailable(DeviceType.Mouse)) {\n const pointer = this._inputs[DeviceType.Mouse][0];\n pointer[PointerInput.MouseWheelX] = 0;\n pointer[PointerInput.MouseWheelY] = 0;\n pointer[PointerInput.MouseWheelZ] = 0;\n }\n });\n }\n /**\n * Handle all actions that come from gamepad interaction\n */\n _handleGamepadActions() {\n this._gamepadConnectedEvent = (evt) => {\n this._addGamePad(evt.gamepad);\n };\n this._gamepadDisconnectedEvent = (evt) => {\n if (this._gamepads) {\n const deviceType = this._getGamepadDeviceType(evt.gamepad.id);\n const deviceSlot = evt.gamepad.index;\n this._unregisterDevice(deviceType, deviceSlot);\n delete this._gamepads[deviceSlot];\n }\n };\n window.addEventListener(\"gamepadconnected\", this._gamepadConnectedEvent);\n window.addEventListener(\"gamepaddisconnected\", this._gamepadDisconnectedEvent);\n }\n /**\n * Update all non-event based devices with each frame\n * @param deviceType Enum specifying device type\n * @param deviceSlot \"Slot\" or index that device is referenced in\n * @param inputIndex Id of input to be checked\n */\n _updateDevice(deviceType, deviceSlot, inputIndex) {\n // Gamepads\n const gp = navigator.getGamepads()[deviceSlot];\n if (gp && deviceType === this._gamepads[deviceSlot]) {\n const device = this._inputs[deviceType][deviceSlot];\n if (inputIndex >= gp.buttons.length) {\n device[inputIndex] = gp.axes[inputIndex - gp.buttons.length].valueOf();\n }\n else {\n device[inputIndex] = gp.buttons[inputIndex].value;\n }\n }\n }\n /**\n * Gets DeviceType from the device name\n * @param deviceName Name of Device from DeviceInputSystem\n * @returns DeviceType enum value\n */\n _getGamepadDeviceType(deviceName) {\n if (deviceName.indexOf(\"054c\") !== -1) {\n // DualShock 4 Gamepad\n return deviceName.indexOf(\"0ce6\") !== -1 ? DeviceType.DualSense : DeviceType.DualShock;\n }\n else if (deviceName.indexOf(\"Xbox One\") !== -1 || deviceName.search(\"Xbox 360\") !== -1 || deviceName.search(\"xinput\") !== -1) {\n // Xbox Gamepad\n return DeviceType.Xbox;\n }\n else if (deviceName.indexOf(\"057e\") !== -1) {\n // Switch Gamepad\n return DeviceType.Switch;\n }\n return DeviceType.Generic;\n }\n /**\n * Get DeviceType from a given pointer/mouse/touch event.\n * @param evt PointerEvent to evaluate\n * @returns DeviceType interpreted from event\n */\n _getPointerType(evt) {\n let deviceType = DeviceType.Mouse;\n if (evt.pointerType === \"touch\" || evt.pointerType === \"pen\" || evt.touches) {\n deviceType = DeviceType.Touch;\n }\n return deviceType;\n }\n }\n\n /**\n * Class that handles all input for a specific device\n */\n class DeviceSource {\n /**\n * Default Constructor\n * @param deviceInputSystem - Reference to DeviceInputSystem\n * @param deviceType - Type of device\n * @param deviceSlot - \"Slot\" or index that device is referenced in\n */\n constructor(deviceInputSystem, \n /** Type of device */\n deviceType, \n /** \"Slot\" or index that device is referenced in */\n deviceSlot = 0) {\n this.deviceType = deviceType;\n this.deviceSlot = deviceSlot;\n // Public Members\n /**\n * Observable to handle device input changes per device\n */\n this.onInputChangedObservable = new Observable$1();\n this._deviceInputSystem = deviceInputSystem;\n }\n /**\n * Get input for specific input\n * @param inputIndex - index of specific input on device\n * @returns Input value from DeviceInputSystem\n */\n getInput(inputIndex) {\n return this._deviceInputSystem.pollInput(this.deviceType, this.deviceSlot, inputIndex);\n }\n }\n\n /** @internal */\n class InternalDeviceSourceManager {\n constructor(engine) {\n this._registeredManagers = new Array();\n this._refCount = 0;\n // Public Functions\n this.registerManager = (manager) => {\n for (let deviceType = 0; deviceType < this._devices.length; deviceType++) {\n const device = this._devices[deviceType];\n for (const deviceSlotKey in device) {\n const deviceSlot = +deviceSlotKey;\n manager._addDevice(new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot));\n }\n }\n this._registeredManagers.push(manager);\n };\n this.unregisterManager = (manager) => {\n const idx = this._registeredManagers.indexOf(manager);\n if (idx > -1) {\n this._registeredManagers.splice(idx, 1);\n }\n };\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\n this._devices = new Array(numberOfDeviceTypes);\n const onDeviceConnected = (deviceType, deviceSlot) => {\n if (!this._devices[deviceType]) {\n this._devices[deviceType] = new Array();\n }\n if (!this._devices[deviceType][deviceSlot]) {\n this._devices[deviceType][deviceSlot] = deviceSlot;\n }\n for (const manager of this._registeredManagers) {\n const deviceSource = new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot);\n manager._addDevice(deviceSource);\n }\n };\n const onDeviceDisconnected = (deviceType, deviceSlot) => {\n var _a;\n if ((_a = this._devices[deviceType]) === null || _a === void 0 ? void 0 : _a[deviceSlot]) {\n delete this._devices[deviceType][deviceSlot];\n }\n for (const manager of this._registeredManagers) {\n manager._removeDevice(deviceType, deviceSlot);\n }\n };\n const onInputChanged = (deviceType, deviceSlot, eventData) => {\n if (eventData) {\n for (const manager of this._registeredManagers) {\n manager._onInputChanged(deviceType, deviceSlot, eventData);\n }\n }\n };\n if (typeof _native !== \"undefined\") {\n this._deviceInputSystem = new NativeDeviceInputSystem(onDeviceConnected, onDeviceDisconnected, onInputChanged);\n }\n else {\n this._deviceInputSystem = new WebDeviceInputSystem(engine, onDeviceConnected, onDeviceDisconnected, onInputChanged);\n }\n }\n dispose() {\n this._deviceInputSystem.dispose();\n }\n }\n\n /**\n * Class to keep track of devices\n */\n class DeviceSourceManager {\n // Public Functions\n /**\n * Gets a DeviceSource, given a type and slot\n * @param deviceType - Type of Device\n * @param deviceSlot - Slot or ID of device\n * @returns DeviceSource\n */\n getDeviceSource(deviceType, deviceSlot) {\n if (deviceSlot === undefined) {\n if (this._firstDevice[deviceType] === undefined) {\n return null;\n }\n deviceSlot = this._firstDevice[deviceType];\n }\n if (!this._devices[deviceType] || this._devices[deviceType][deviceSlot] === undefined) {\n return null;\n }\n return this._devices[deviceType][deviceSlot];\n }\n /**\n * Gets an array of DeviceSource objects for a given device type\n * @param deviceType - Type of Device\n * @returns All available DeviceSources of a given type\n */\n getDeviceSources(deviceType) {\n // If device type hasn't had any devices connected yet, return empty array.\n if (!this._devices[deviceType]) {\n return [];\n }\n return this._devices[deviceType].filter((source) => {\n return !!source;\n });\n }\n /**\n * Default constructor\n * @param engine - Used to get canvas (if applicable)\n */\n constructor(engine) {\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\n this._devices = new Array(numberOfDeviceTypes);\n this._firstDevice = new Array(numberOfDeviceTypes);\n this._engine = engine;\n if (!this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager = new InternalDeviceSourceManager(engine);\n }\n this._engine._deviceSourceManager._refCount++;\n // Observables\n this.onDeviceConnectedObservable = new Observable$1((observer) => {\n for (const devices of this._devices) {\n if (devices) {\n for (const device of devices) {\n if (device) {\n this.onDeviceConnectedObservable.notifyObserver(observer, device);\n }\n }\n }\n }\n });\n this.onDeviceDisconnectedObservable = new Observable$1();\n this._engine._deviceSourceManager.registerManager(this);\n this._onDisposeObserver = engine.onDisposeObservable.add(() => {\n this.dispose();\n });\n }\n /**\n * Dispose of DeviceSourceManager\n */\n dispose() {\n // Null out observable refs\n this.onDeviceConnectedObservable.clear();\n this.onDeviceDisconnectedObservable.clear();\n if (this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager.unregisterManager(this);\n if (--this._engine._deviceSourceManager._refCount < 1) {\n this._engine._deviceSourceManager.dispose();\n delete this._engine._deviceSourceManager;\n }\n }\n this._engine.onDisposeObservable.remove(this._onDisposeObserver);\n }\n // Hidden Functions\n /**\n * @param deviceSource - Source to add\n * @internal\n */\n _addDevice(deviceSource) {\n if (!this._devices[deviceSource.deviceType]) {\n this._devices[deviceSource.deviceType] = new Array();\n }\n if (!this._devices[deviceSource.deviceType][deviceSource.deviceSlot]) {\n this._devices[deviceSource.deviceType][deviceSource.deviceSlot] = deviceSource;\n this._updateFirstDevices(deviceSource.deviceType);\n }\n this.onDeviceConnectedObservable.notifyObservers(deviceSource);\n }\n /**\n * @param deviceType - DeviceType\n * @param deviceSlot - DeviceSlot\n * @internal\n */\n _removeDevice(deviceType, deviceSlot) {\n var _a, _b;\n const deviceSource = (_a = this._devices[deviceType]) === null || _a === void 0 ? void 0 : _a[deviceSlot]; // Grab local reference to use before removing from devices\n this.onDeviceDisconnectedObservable.notifyObservers(deviceSource);\n if ((_b = this._devices[deviceType]) === null || _b === void 0 ? void 0 : _b[deviceSlot]) {\n delete this._devices[deviceType][deviceSlot];\n }\n // Even if we don't delete a device, we should still check for the first device as things may have gotten out of sync.\n this._updateFirstDevices(deviceType);\n }\n /**\n * @param deviceType - DeviceType\n * @param deviceSlot - DeviceSlot\n * @param eventData - Event\n * @internal\n */\n _onInputChanged(deviceType, deviceSlot, eventData) {\n var _a, _b;\n (_b = (_a = this._devices[deviceType]) === null || _a === void 0 ? void 0 : _a[deviceSlot]) === null || _b === void 0 ? void 0 : _b.onInputChangedObservable.notifyObservers(eventData);\n }\n // Private Functions\n _updateFirstDevices(type) {\n switch (type) {\n case DeviceType.Keyboard:\n case DeviceType.Mouse:\n this._firstDevice[type] = 0;\n break;\n case DeviceType.Touch:\n case DeviceType.DualSense:\n case DeviceType.DualShock:\n case DeviceType.Xbox:\n case DeviceType.Switch:\n case DeviceType.Generic: {\n delete this._firstDevice[type];\n // eslint-disable-next-line no-case-declarations\n const devices = this._devices[type];\n if (devices) {\n for (let i = 0; i < devices.length; i++) {\n if (devices[i]) {\n this._firstDevice[type] = i;\n break;\n }\n }\n }\n break;\n }\n }\n }\n }\n\n /** @internal */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _ClickInfo {\n constructor() {\n this._singleClick = false;\n this._doubleClick = false;\n this._hasSwiped = false;\n this._ignore = false;\n }\n get singleClick() {\n return this._singleClick;\n }\n get doubleClick() {\n return this._doubleClick;\n }\n get hasSwiped() {\n return this._hasSwiped;\n }\n get ignore() {\n return this._ignore;\n }\n set singleClick(b) {\n this._singleClick = b;\n }\n set doubleClick(b) {\n this._doubleClick = b;\n }\n set hasSwiped(b) {\n this._hasSwiped = b;\n }\n set ignore(b) {\n this._ignore = b;\n }\n }\n /**\n * Class used to manage all inputs for the scene.\n */\n class InputManager {\n /**\n * Creates a new InputManager\n * @param scene - defines the hosting scene\n */\n constructor(scene) {\n /** This is a defensive check to not allow control attachment prior to an already active one. If already attached, previous control is unattached before attaching the new one. */\n this._alreadyAttached = false;\n this._meshPickProceed = false;\n this._currentPickResult = null;\n this._previousPickResult = null;\n this._totalPointersPressed = 0;\n this._doubleClickOccured = false;\n this._isSwiping = false;\n this._swipeButtonPressed = -1;\n this._skipPointerTap = false;\n this._isMultiTouchGesture = false;\n this._pointerX = 0;\n this._pointerY = 0;\n this._startingPointerPosition = new Vector2(0, 0);\n this._previousStartingPointerPosition = new Vector2(0, 0);\n this._startingPointerTime = 0;\n this._previousStartingPointerTime = 0;\n this._pointerCaptures = {};\n this._meshUnderPointerId = {};\n this._movePointerInfo = null;\n this._cameraObserverCount = 0;\n this._delayedClicks = [null, null, null, null, null];\n this._deviceSourceManager = null;\n this._scene = scene || EngineStore.LastCreatedScene;\n if (!this._scene) {\n return;\n }\n }\n /**\n * Gets the mesh that is currently under the pointer\n * @returns Mesh that the pointer is pointer is hovering over\n */\n get meshUnderPointer() {\n if (this._movePointerInfo) {\n // Because _pointerOverMesh is populated as part of _pickMove, we need to force a pick to update it.\n // Calling _pickMove calls _setCursorAndPointerOverMesh which calls setPointerOverMesh\n this._movePointerInfo._generatePickInfo();\n // Once we have what we need, we can clear _movePointerInfo because we don't need it anymore\n this._movePointerInfo = null;\n }\n return this._pointerOverMesh;\n }\n /**\n * When using more than one pointer (for example in XR) you can get the mesh under the specific pointer\n * @param pointerId - the pointer id to use\n * @returns The mesh under this pointer id or null if not found\n */\n getMeshUnderPointerByPointerId(pointerId) {\n return this._meshUnderPointerId[pointerId] || null;\n }\n /**\n * Gets the pointer coordinates in 2D without any translation (ie. straight out of the pointer event)\n * @returns Vector with X/Y values directly from pointer event\n */\n get unTranslatedPointer() {\n return new Vector2(this._unTranslatedPointerX, this._unTranslatedPointerY);\n }\n /**\n * Gets or sets the current on-screen X position of the pointer\n * @returns Translated X with respect to screen\n */\n get pointerX() {\n return this._pointerX;\n }\n set pointerX(value) {\n this._pointerX = value;\n }\n /**\n * Gets or sets the current on-screen Y position of the pointer\n * @returns Translated Y with respect to screen\n */\n get pointerY() {\n return this._pointerY;\n }\n set pointerY(value) {\n this._pointerY = value;\n }\n _updatePointerPosition(evt) {\n const canvasRect = this._scene.getEngine().getInputElementClientRect();\n if (!canvasRect) {\n return;\n }\n this._pointerX = evt.clientX - canvasRect.left;\n this._pointerY = evt.clientY - canvasRect.top;\n this._unTranslatedPointerX = this._pointerX;\n this._unTranslatedPointerY = this._pointerY;\n }\n _processPointerMove(pickResult, evt) {\n const scene = this._scene;\n const engine = scene.getEngine();\n const canvas = engine.getInputElement();\n if (canvas) {\n canvas.tabIndex = engine.canvasTabIndex;\n // Restore pointer\n if (!scene.doNotHandleCursors) {\n canvas.style.cursor = scene.defaultCursor;\n }\n }\n this._setCursorAndPointerOverMesh(pickResult, evt, scene);\n for (const step of scene._pointerMoveStage) {\n // If _pointerMoveState is defined, we have an active spriteManager and can't use Lazy Picking\n // Therefore, we need to force a pick to update the pickResult\n pickResult = pickResult || this._pickMove(evt);\n const isMeshPicked = (pickResult === null || pickResult === void 0 ? void 0 : pickResult.pickedMesh) ? true : false;\n pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, isMeshPicked, canvas);\n }\n const type = evt.inputIndex >= PointerInput.MouseWheelX && evt.inputIndex <= PointerInput.MouseWheelZ ? PointerEventTypes.POINTERWHEEL : PointerEventTypes.POINTERMOVE;\n if (scene.onPointerMove) {\n // Because of lazy picking, we need to force a pick to update the pickResult\n pickResult = pickResult || this._pickMove(evt);\n scene.onPointerMove(evt, pickResult, type);\n }\n let pointerInfo;\n if (pickResult) {\n pointerInfo = new PointerInfo(type, evt, pickResult);\n this._setRayOnPointerInfo(pickResult, evt);\n }\n else {\n pointerInfo = new PointerInfo(type, evt, null, this);\n this._movePointerInfo = pointerInfo;\n }\n if (scene.onPointerObservable.hasObservers()) {\n scene.onPointerObservable.notifyObservers(pointerInfo, type);\n }\n }\n // Pointers handling\n /** @internal */\n _setRayOnPointerInfo(pickInfo, event) {\n const scene = this._scene;\n if (pickInfo && scene._pickingAvailable) {\n if (!pickInfo.ray) {\n pickInfo.ray = scene.createPickingRay(event.offsetX, event.offsetY, Matrix.Identity(), scene.activeCamera);\n }\n }\n }\n /** @internal */\n _addCameraPointerObserver(observer, mask) {\n this._cameraObserverCount++;\n return this._scene.onPointerObservable.add(observer, mask);\n }\n /** @internal */\n _removeCameraPointerObserver(observer) {\n this._cameraObserverCount--;\n return this._scene.onPointerObservable.remove(observer);\n }\n _checkForPicking() {\n return !!(this._scene.onPointerObservable.observers.length > this._cameraObserverCount || this._scene.onPointerPick);\n }\n _checkPrePointerObservable(pickResult, evt, type) {\n const scene = this._scene;\n const pi = new PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);\n if (pickResult) {\n pi.originalPickingInfo = pickResult;\n pi.ray = pickResult.ray;\n if (pickResult.originMesh) {\n pi.nearInteractionPickingInfo = pickResult;\n }\n }\n scene.onPrePointerObservable.notifyObservers(pi, type);\n if (pi.skipOnPointerObservable) {\n return true;\n }\n else {\n return false;\n }\n }\n /** @internal */\n _pickMove(evt) {\n const scene = this._scene;\n const pickResult = scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerMovePredicate, scene.pointerMoveFastCheck, scene.cameraToUseForPointers, scene.pointerMoveTrianglePredicate);\n this._setCursorAndPointerOverMesh(pickResult, evt, scene);\n return pickResult;\n }\n _setCursorAndPointerOverMesh(pickResult, evt, scene) {\n const engine = scene.getEngine();\n const canvas = engine.getInputElement();\n if (pickResult === null || pickResult === void 0 ? void 0 : pickResult.pickedMesh) {\n this.setPointerOverMesh(pickResult.pickedMesh, evt.pointerId, pickResult, evt);\n if (!scene.doNotHandleCursors && canvas && this._pointerOverMesh) {\n const actionManager = this._pointerOverMesh._getActionManagerForTrigger();\n if (actionManager && actionManager.hasPointerTriggers) {\n canvas.style.cursor = actionManager.hoverCursor || scene.hoverCursor;\n }\n }\n }\n else {\n this.setPointerOverMesh(null, evt.pointerId, pickResult, evt);\n }\n }\n /**\n * Use this method to simulate a pointer move on a mesh\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\n * @param pickResult - pickingInfo of the object wished to simulate pointer event on\n * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\n */\n simulatePointerMove(pickResult, pointerEventInit) {\n const evt = new PointerEvent(\"pointermove\", pointerEventInit);\n evt.inputIndex = PointerInput.Move;\n if (this._checkPrePointerObservable(pickResult, evt, PointerEventTypes.POINTERMOVE)) {\n return;\n }\n this._processPointerMove(pickResult, evt);\n }\n /**\n * Use this method to simulate a pointer down on a mesh\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\n * @param pickResult - pickingInfo of the object wished to simulate pointer event on\n * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\n */\n simulatePointerDown(pickResult, pointerEventInit) {\n const evt = new PointerEvent(\"pointerdown\", pointerEventInit);\n evt.inputIndex = evt.button + 2;\n if (this._checkPrePointerObservable(pickResult, evt, PointerEventTypes.POINTERDOWN)) {\n return;\n }\n this._processPointerDown(pickResult, evt);\n }\n _processPointerDown(pickResult, evt) {\n const scene = this._scene;\n if (pickResult === null || pickResult === void 0 ? void 0 : pickResult.pickedMesh) {\n this._pickedDownMesh = pickResult.pickedMesh;\n const actionManager = pickResult.pickedMesh._getActionManagerForTrigger();\n if (actionManager) {\n if (actionManager.hasPickTriggers) {\n actionManager.processTrigger(5, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n switch (evt.button) {\n case 0:\n actionManager.processTrigger(2, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n break;\n case 1:\n actionManager.processTrigger(4, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n break;\n case 2:\n actionManager.processTrigger(3, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n break;\n }\n }\n if (actionManager.hasSpecificTrigger(8)) {\n window.setTimeout(() => {\n const pickResult = scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, (mesh) => ((mesh.isPickable &&\n mesh.isVisible &&\n mesh.isReady() &&\n mesh.actionManager &&\n mesh.actionManager.hasSpecificTrigger(8) &&\n mesh === this._pickedDownMesh)), false, scene.cameraToUseForPointers);\n if ((pickResult === null || pickResult === void 0 ? void 0 : pickResult.pickedMesh) && actionManager) {\n if (this._totalPointersPressed !== 0 && Date.now() - this._startingPointerTime > InputManager.LongPressDelay && !this._isPointerSwiping()) {\n this._startingPointerTime = 0;\n actionManager.processTrigger(8, ActionEvent.CreateNew(pickResult.pickedMesh, evt));\n }\n }\n }, InputManager.LongPressDelay);\n }\n }\n }\n else {\n for (const step of scene._pointerDownStage) {\n pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt, false);\n }\n }\n let pointerInfo;\n const type = PointerEventTypes.POINTERDOWN;\n if (pickResult) {\n if (scene.onPointerDown) {\n scene.onPointerDown(evt, pickResult, type);\n }\n pointerInfo = new PointerInfo(type, evt, pickResult);\n this._setRayOnPointerInfo(pickResult, evt);\n }\n else {\n pointerInfo = new PointerInfo(type, evt, null, this);\n }\n if (scene.onPointerObservable.hasObservers()) {\n scene.onPointerObservable.notifyObservers(pointerInfo, type);\n }\n }\n /**\n * @internal\n * @internals Boolean if delta for pointer exceeds drag movement threshold\n */\n _isPointerSwiping() {\n return this._isSwiping;\n }\n /**\n * Use this method to simulate a pointer up on a mesh\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\n * @param pickResult - pickingInfo of the object wished to simulate pointer event on\n * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\n * @param doubleTap - indicates that the pointer up event should be considered as part of a double click (false by default)\n */\n simulatePointerUp(pickResult, pointerEventInit, doubleTap) {\n const evt = new PointerEvent(\"pointerup\", pointerEventInit);\n evt.inputIndex = PointerInput.Move;\n const clickInfo = new _ClickInfo();\n if (doubleTap) {\n clickInfo.doubleClick = true;\n }\n else {\n clickInfo.singleClick = true;\n }\n if (this._checkPrePointerObservable(pickResult, evt, PointerEventTypes.POINTERUP)) {\n return;\n }\n this._processPointerUp(pickResult, evt, clickInfo);\n }\n _processPointerUp(pickResult, evt, clickInfo) {\n const scene = this._scene;\n if (pickResult === null || pickResult === void 0 ? void 0 : pickResult.pickedMesh) {\n this._pickedUpMesh = pickResult.pickedMesh;\n if (this._pickedDownMesh === this._pickedUpMesh) {\n if (scene.onPointerPick) {\n scene.onPointerPick(evt, pickResult);\n }\n if (clickInfo.singleClick && !clickInfo.ignore && scene.onPointerObservable.observers.length > this._cameraObserverCount) {\n const type = PointerEventTypes.POINTERPICK;\n const pi = new PointerInfo(type, evt, pickResult);\n this._setRayOnPointerInfo(pickResult, evt);\n scene.onPointerObservable.notifyObservers(pi, type);\n }\n }\n const actionManager = pickResult.pickedMesh._getActionManagerForTrigger();\n if (actionManager && !clickInfo.ignore) {\n actionManager.processTrigger(7, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n if (!clickInfo.hasSwiped && clickInfo.singleClick) {\n actionManager.processTrigger(1, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n }\n const doubleClickActionManager = pickResult.pickedMesh._getActionManagerForTrigger(6);\n if (clickInfo.doubleClick && doubleClickActionManager) {\n doubleClickActionManager.processTrigger(6, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\n }\n }\n }\n else {\n if (!clickInfo.ignore) {\n for (const step of scene._pointerUpStage) {\n pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt, clickInfo.doubleClick);\n }\n }\n }\n if (this._pickedDownMesh && this._pickedDownMesh !== this._pickedUpMesh) {\n const pickedDownActionManager = this._pickedDownMesh._getActionManagerForTrigger(16);\n if (pickedDownActionManager) {\n pickedDownActionManager.processTrigger(16, ActionEvent.CreateNew(this._pickedDownMesh, evt));\n }\n }\n if (!clickInfo.ignore) {\n const pi = new PointerInfo(PointerEventTypes.POINTERUP, evt, pickResult);\n // Set ray on picking info. Note that this info will also be reused for the tap notification.\n this._setRayOnPointerInfo(pickResult, evt);\n scene.onPointerObservable.notifyObservers(pi, PointerEventTypes.POINTERUP);\n if (scene.onPointerUp) {\n scene.onPointerUp(evt, pickResult, PointerEventTypes.POINTERUP);\n }\n if (!clickInfo.hasSwiped && !this._skipPointerTap && !this._isMultiTouchGesture) {\n let type = 0;\n if (clickInfo.singleClick) {\n type = PointerEventTypes.POINTERTAP;\n }\n else if (clickInfo.doubleClick) {\n type = PointerEventTypes.POINTERDOUBLETAP;\n }\n if (type) {\n const pi = new PointerInfo(type, evt, pickResult);\n if (scene.onPointerObservable.hasObservers() && scene.onPointerObservable.hasSpecificMask(type)) {\n scene.onPointerObservable.notifyObservers(pi, type);\n }\n }\n }\n }\n }\n /**\n * Gets a boolean indicating if the current pointer event is captured (meaning that the scene has already handled the pointer down)\n * @param pointerId - defines the pointer id to use in a multi-touch scenario (0 by default)\n * @returns true if the pointer was captured\n */\n isPointerCaptured(pointerId = 0) {\n return this._pointerCaptures[pointerId];\n }\n /**\n * Attach events to the canvas (To handle actionManagers triggers and raise onPointerMove, onPointerDown and onPointerUp\n * @param attachUp - defines if you want to attach events to pointerup\n * @param attachDown - defines if you want to attach events to pointerdown\n * @param attachMove - defines if you want to attach events to pointermove\n * @param elementToAttachTo - defines the target DOM element to attach to (will use the canvas by default)\n */\n attachControl(attachUp = true, attachDown = true, attachMove = true, elementToAttachTo = null) {\n const scene = this._scene;\n const engine = scene.getEngine();\n if (!elementToAttachTo) {\n elementToAttachTo = engine.getInputElement();\n }\n if (this._alreadyAttached) {\n this.detachControl();\n }\n if (elementToAttachTo) {\n this._alreadyAttachedTo = elementToAttachTo;\n }\n this._deviceSourceManager = new DeviceSourceManager(engine);\n // Because this is only called from _initClickEvent, which is called in _onPointerUp, we'll use the pointerUpPredicate for the pick call\n this._initActionManager = (act) => {\n if (!this._meshPickProceed) {\n const pickResult = scene.skipPointerUpPicking || (scene._registeredActions === 0 && !this._checkForPicking() && !scene.onPointerUp)\n ? null\n : scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerUpPredicate, scene.pointerUpFastCheck, scene.cameraToUseForPointers);\n this._currentPickResult = pickResult;\n if (pickResult) {\n act = pickResult.hit && pickResult.pickedMesh ? pickResult.pickedMesh._getActionManagerForTrigger() : null;\n }\n this._meshPickProceed = true;\n }\n return act;\n };\n this._delayedSimpleClick = (btn, clickInfo, cb) => {\n // double click delay is over and that no double click has been raised since, or the 2 consecutive keys pressed are different\n if ((Date.now() - this._previousStartingPointerTime > InputManager.DoubleClickDelay && !this._doubleClickOccured) || btn !== this._previousButtonPressed) {\n this._doubleClickOccured = false;\n clickInfo.singleClick = true;\n clickInfo.ignore = false;\n // If we have a delayed click, we need to resolve the TAP event\n if (this._delayedClicks[btn]) {\n const evt = this._delayedClicks[btn].evt;\n const type = PointerEventTypes.POINTERTAP;\n const pi = new PointerInfo(type, evt, this._currentPickResult);\n if (scene.onPointerObservable.hasObservers() && scene.onPointerObservable.hasSpecificMask(type)) {\n scene.onPointerObservable.notifyObservers(pi, type);\n }\n // Clear the delayed click\n this._delayedClicks[btn] = null;\n }\n }\n };\n this._initClickEvent = (obs1, obs2, evt, cb) => {\n var _a, _b;\n const clickInfo = new _ClickInfo();\n this._currentPickResult = null;\n let act = null;\n let checkPicking = obs1.hasSpecificMask(PointerEventTypes.POINTERPICK) ||\n obs2.hasSpecificMask(PointerEventTypes.POINTERPICK) ||\n obs1.hasSpecificMask(PointerEventTypes.POINTERTAP) ||\n obs2.hasSpecificMask(PointerEventTypes.POINTERTAP) ||\n obs1.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP) ||\n obs2.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP);\n if (!checkPicking && AbstractActionManager) {\n act = this._initActionManager(act, clickInfo);\n if (act) {\n checkPicking = act.hasPickTriggers;\n }\n }\n let needToIgnoreNext = false;\n if (checkPicking) {\n const btn = evt.button;\n clickInfo.hasSwiped = this._isPointerSwiping();\n if (!clickInfo.hasSwiped) {\n let checkSingleClickImmediately = !InputManager.ExclusiveDoubleClickMode;\n if (!checkSingleClickImmediately) {\n checkSingleClickImmediately = !obs1.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP) && !obs2.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP);\n if (checkSingleClickImmediately && !AbstractActionManager.HasSpecificTrigger(6)) {\n act = this._initActionManager(act, clickInfo);\n if (act) {\n checkSingleClickImmediately = !act.hasSpecificTrigger(6);\n }\n }\n }\n if (checkSingleClickImmediately) {\n // single click detected if double click delay is over or two different successive keys pressed without exclusive double click or no double click required\n if (Date.now() - this._previousStartingPointerTime > InputManager.DoubleClickDelay || btn !== this._previousButtonPressed) {\n clickInfo.singleClick = true;\n cb(clickInfo, this._currentPickResult);\n needToIgnoreNext = true;\n }\n }\n // at least one double click is required to be check and exclusive double click is enabled\n else {\n // Queue up a delayed click, just in case this isn't a double click\n // It should be noted that while this delayed event happens\n // because of user input, it shouldn't be considered as a direct,\n // timing-dependent result of that input. It's meant to just fire the TAP event\n const delayedClick = {\n evt: evt,\n clickInfo: clickInfo,\n timeoutId: window.setTimeout(this._delayedSimpleClick.bind(this, btn, clickInfo, cb), InputManager.DoubleClickDelay),\n };\n this._delayedClicks[btn] = delayedClick;\n }\n let checkDoubleClick = obs1.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP) || obs2.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP);\n if (!checkDoubleClick && AbstractActionManager.HasSpecificTrigger(6)) {\n act = this._initActionManager(act, clickInfo);\n if (act) {\n checkDoubleClick = act.hasSpecificTrigger(6);\n }\n }\n if (checkDoubleClick) {\n // two successive keys pressed are equal, double click delay is not over and double click has not just occurred\n if (btn === this._previousButtonPressed && Date.now() - this._previousStartingPointerTime < InputManager.DoubleClickDelay && !this._doubleClickOccured) {\n // pointer has not moved for 2 clicks, it's a double click\n if (!clickInfo.hasSwiped && !this._isPointerSwiping()) {\n this._previousStartingPointerTime = 0;\n this._doubleClickOccured = true;\n clickInfo.doubleClick = true;\n clickInfo.ignore = false;\n // If we have a pending click, we need to cancel it\n if (InputManager.ExclusiveDoubleClickMode && this._delayedClicks[btn]) {\n clearTimeout((_a = this._delayedClicks[btn]) === null || _a === void 0 ? void 0 : _a.timeoutId);\n this._delayedClicks[btn] = null;\n }\n cb(clickInfo, this._currentPickResult);\n }\n // if the two successive clicks are too far, it's just two simple clicks\n else {\n this._doubleClickOccured = false;\n this._previousStartingPointerTime = this._startingPointerTime;\n this._previousStartingPointerPosition.x = this._startingPointerPosition.x;\n this._previousStartingPointerPosition.y = this._startingPointerPosition.y;\n this._previousButtonPressed = btn;\n if (InputManager.ExclusiveDoubleClickMode) {\n // If we have a delayed click, we need to cancel it\n if (this._delayedClicks[btn]) {\n clearTimeout((_b = this._delayedClicks[btn]) === null || _b === void 0 ? void 0 : _b.timeoutId);\n this._delayedClicks[btn] = null;\n }\n cb(clickInfo, this._previousPickResult);\n }\n else {\n cb(clickInfo, this._currentPickResult);\n }\n }\n needToIgnoreNext = true;\n }\n // just the first click of the double has been raised\n else {\n this._doubleClickOccured = false;\n this._previousStartingPointerTime = this._startingPointerTime;\n this._previousStartingPointerPosition.x = this._startingPointerPosition.x;\n this._previousStartingPointerPosition.y = this._startingPointerPosition.y;\n this._previousButtonPressed = btn;\n }\n }\n }\n }\n // Even if ExclusiveDoubleClickMode is true, we need to always handle\n // up events at time of execution, unless we're explicitly ignoring them.\n if (!needToIgnoreNext) {\n cb(clickInfo, this._currentPickResult);\n }\n };\n this._onPointerMove = (evt) => {\n this._updatePointerPosition(evt);\n // Check if pointer leaves DragMovementThreshold range to determine if swipe is occurring\n if (!this._isSwiping && this._swipeButtonPressed !== -1) {\n this._isSwiping =\n Math.abs(this._startingPointerPosition.x - this._pointerX) > InputManager.DragMovementThreshold ||\n Math.abs(this._startingPointerPosition.y - this._pointerY) > InputManager.DragMovementThreshold;\n }\n // Because there's a race condition between pointermove and pointerlockchange events, we need to\n // verify that the pointer is still locked after each pointermove event.\n if (engine.isPointerLock) {\n engine._verifyPointerLock();\n }\n // PreObservable support\n if (this._checkPrePointerObservable(null, evt, evt.inputIndex >= PointerInput.MouseWheelX && evt.inputIndex <= PointerInput.MouseWheelZ ? PointerEventTypes.POINTERWHEEL : PointerEventTypes.POINTERMOVE)) {\n return;\n }\n if (!scene.cameraToUseForPointers && !scene.activeCamera) {\n return;\n }\n if (scene.skipPointerMovePicking) {\n this._processPointerMove(new PickingInfo(), evt);\n return;\n }\n if (!scene.pointerMovePredicate) {\n scene.pointerMovePredicate = (mesh) => mesh.isPickable &&\n mesh.isVisible &&\n mesh.isReady() &&\n mesh.isEnabled() &&\n (mesh.enablePointerMoveEvents || scene.constantlyUpdateMeshUnderPointer || mesh._getActionManagerForTrigger() !== null) &&\n (!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0);\n }\n const pickResult = scene._registeredActions > 0 || scene.constantlyUpdateMeshUnderPointer ? this._pickMove(evt) : null;\n this._processPointerMove(pickResult, evt);\n };\n this._onPointerDown = (evt) => {\n var _a;\n this._totalPointersPressed++;\n this._pickedDownMesh = null;\n this._meshPickProceed = false;\n // If ExclusiveDoubleClickMode is true, we need to resolve any pending delayed clicks\n if (InputManager.ExclusiveDoubleClickMode) {\n for (let i = 0; i < this._delayedClicks.length; i++) {\n if (this._delayedClicks[i]) {\n // If the button that was pressed is the same as the one that was released,\n // just clear the timer. This will be resolved in the up event.\n if (evt.button === i) {\n clearTimeout((_a = this._delayedClicks[i]) === null || _a === void 0 ? void 0 : _a.timeoutId);\n }\n else {\n // Otherwise, we need to resolve the click\n const clickInfo = this._delayedClicks[i].clickInfo;\n this._doubleClickOccured = false;\n clickInfo.singleClick = true;\n clickInfo.ignore = false;\n const prevEvt = this._delayedClicks[i].evt;\n const type = PointerEventTypes.POINTERTAP;\n const pi = new PointerInfo(type, prevEvt, this._currentPickResult);\n if (scene.onPointerObservable.hasObservers() && scene.onPointerObservable.hasSpecificMask(type)) {\n scene.onPointerObservable.notifyObservers(pi, type);\n }\n // Clear the delayed click\n this._delayedClicks[i] = null;\n }\n }\n }\n }\n this._updatePointerPosition(evt);\n if (this._swipeButtonPressed === -1) {\n this._swipeButtonPressed = evt.button;\n }\n if (scene.preventDefaultOnPointerDown && elementToAttachTo) {\n evt.preventDefault();\n elementToAttachTo.focus();\n }\n this._startingPointerPosition.x = this._pointerX;\n this._startingPointerPosition.y = this._pointerY;\n this._startingPointerTime = Date.now();\n // PreObservable support\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERDOWN)) {\n return;\n }\n if (!scene.cameraToUseForPointers && !scene.activeCamera) {\n return;\n }\n this._pointerCaptures[evt.pointerId] = true;\n if (!scene.pointerDownPredicate) {\n scene.pointerDownPredicate = (mesh) => {\n return (mesh.isPickable &&\n mesh.isVisible &&\n mesh.isReady() &&\n mesh.isEnabled() &&\n (!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0));\n };\n }\n // Meshes\n this._pickedDownMesh = null;\n let pickResult;\n if (scene.skipPointerDownPicking || (scene._registeredActions === 0 && !this._checkForPicking() && !scene.onPointerDown)) {\n pickResult = new PickingInfo();\n }\n else {\n pickResult = scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerDownPredicate, scene.pointerDownFastCheck, scene.cameraToUseForPointers);\n }\n this._processPointerDown(pickResult, evt);\n };\n this._onPointerUp = (evt) => {\n if (this._totalPointersPressed === 0) {\n // We are attaching the pointer up to windows because of a bug in FF\n return; // So we need to test it the pointer down was pressed before.\n }\n this._totalPointersPressed--;\n this._pickedUpMesh = null;\n this._meshPickProceed = false;\n this._updatePointerPosition(evt);\n if (scene.preventDefaultOnPointerUp && elementToAttachTo) {\n evt.preventDefault();\n elementToAttachTo.focus();\n }\n this._initClickEvent(scene.onPrePointerObservable, scene.onPointerObservable, evt, (clickInfo, pickResult) => {\n // PreObservable support\n if (scene.onPrePointerObservable.hasObservers()) {\n this._skipPointerTap = false;\n if (!clickInfo.ignore) {\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERUP)) {\n // If we're skipping the next observable, we need to reset the swipe state before returning\n if (this._swipeButtonPressed === evt.button) {\n this._isSwiping = false;\n this._swipeButtonPressed = -1;\n }\n // If we're going to skip the POINTERUP, we need to reset the pointer capture\n if (evt.buttons === 0) {\n this._pointerCaptures[evt.pointerId] = false;\n }\n return;\n }\n if (!clickInfo.hasSwiped) {\n if (clickInfo.singleClick && scene.onPrePointerObservable.hasSpecificMask(PointerEventTypes.POINTERTAP)) {\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERTAP)) {\n this._skipPointerTap = true;\n }\n }\n if (clickInfo.doubleClick && scene.onPrePointerObservable.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP)) {\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERDOUBLETAP)) {\n this._skipPointerTap = true;\n }\n }\n }\n }\n }\n // There should be a pointer captured at this point so if there isn't we should reset and return\n if (!this._pointerCaptures[evt.pointerId]) {\n if (this._swipeButtonPressed === evt.button) {\n this._isSwiping = false;\n this._swipeButtonPressed = -1;\n }\n return;\n }\n // Only release capture if all buttons are released\n if (evt.buttons === 0) {\n this._pointerCaptures[evt.pointerId] = false;\n }\n if (!scene.cameraToUseForPointers && !scene.activeCamera) {\n return;\n }\n if (!scene.pointerUpPredicate) {\n scene.pointerUpPredicate = (mesh) => {\n return (mesh.isPickable &&\n mesh.isVisible &&\n mesh.isReady() &&\n mesh.isEnabled() &&\n (!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0));\n };\n }\n // Meshes\n if (!this._meshPickProceed && ((AbstractActionManager && AbstractActionManager.HasTriggers) || this._checkForPicking() || scene.onPointerUp)) {\n this._initActionManager(null, clickInfo);\n }\n if (!pickResult) {\n pickResult = this._currentPickResult;\n }\n this._processPointerUp(pickResult, evt, clickInfo);\n this._previousPickResult = this._currentPickResult;\n if (this._swipeButtonPressed === evt.button) {\n this._isSwiping = false;\n this._swipeButtonPressed = -1;\n }\n });\n };\n this._onKeyDown = (evt) => {\n const type = KeyboardEventTypes.KEYDOWN;\n if (scene.onPreKeyboardObservable.hasObservers()) {\n const pi = new KeyboardInfoPre(type, evt);\n scene.onPreKeyboardObservable.notifyObservers(pi, type);\n if (pi.skipOnKeyboardObservable) {\n return;\n }\n }\n if (scene.onKeyboardObservable.hasObservers()) {\n const pi = new KeyboardInfo(type, evt);\n scene.onKeyboardObservable.notifyObservers(pi, type);\n }\n if (scene.actionManager) {\n scene.actionManager.processTrigger(14, ActionEvent.CreateNewFromScene(scene, evt));\n }\n };\n this._onKeyUp = (evt) => {\n const type = KeyboardEventTypes.KEYUP;\n if (scene.onPreKeyboardObservable.hasObservers()) {\n const pi = new KeyboardInfoPre(type, evt);\n scene.onPreKeyboardObservable.notifyObservers(pi, type);\n if (pi.skipOnKeyboardObservable) {\n return;\n }\n }\n if (scene.onKeyboardObservable.hasObservers()) {\n const pi = new KeyboardInfo(type, evt);\n scene.onKeyboardObservable.notifyObservers(pi, type);\n }\n if (scene.actionManager) {\n scene.actionManager.processTrigger(15, ActionEvent.CreateNewFromScene(scene, evt));\n }\n };\n // If a device connects that we can handle, wire up the observable\n this._deviceSourceManager.onDeviceConnectedObservable.add((deviceSource) => {\n if (deviceSource.deviceType === DeviceType.Mouse) {\n deviceSource.onInputChangedObservable.add((eventData) => {\n if (eventData.inputIndex === PointerInput.LeftClick ||\n eventData.inputIndex === PointerInput.MiddleClick ||\n eventData.inputIndex === PointerInput.RightClick ||\n eventData.inputIndex === PointerInput.BrowserBack ||\n eventData.inputIndex === PointerInput.BrowserForward) {\n if (attachDown && deviceSource.getInput(eventData.inputIndex) === 1) {\n this._onPointerDown(eventData);\n }\n else if (attachUp && deviceSource.getInput(eventData.inputIndex) === 0) {\n this._onPointerUp(eventData);\n }\n }\n else if (attachMove) {\n if (eventData.inputIndex === PointerInput.Move) {\n this._onPointerMove(eventData);\n }\n else if (eventData.inputIndex === PointerInput.MouseWheelX ||\n eventData.inputIndex === PointerInput.MouseWheelY ||\n eventData.inputIndex === PointerInput.MouseWheelZ) {\n this._onPointerMove(eventData);\n }\n }\n });\n }\n else if (deviceSource.deviceType === DeviceType.Touch) {\n deviceSource.onInputChangedObservable.add((eventData) => {\n if (eventData.inputIndex === PointerInput.LeftClick) {\n if (attachDown && deviceSource.getInput(eventData.inputIndex) === 1) {\n this._onPointerDown(eventData);\n if (this._totalPointersPressed > 1) {\n this._isMultiTouchGesture = true;\n }\n }\n else if (attachUp && deviceSource.getInput(eventData.inputIndex) === 0) {\n this._onPointerUp(eventData);\n if (this._totalPointersPressed === 0) {\n this._isMultiTouchGesture = false;\n }\n }\n }\n if (attachMove && eventData.inputIndex === PointerInput.Move) {\n this._onPointerMove(eventData);\n }\n });\n }\n else if (deviceSource.deviceType === DeviceType.Keyboard) {\n deviceSource.onInputChangedObservable.add((eventData) => {\n if (eventData.type === \"keydown\") {\n this._onKeyDown(eventData);\n }\n else if (eventData.type === \"keyup\") {\n this._onKeyUp(eventData);\n }\n });\n }\n });\n this._alreadyAttached = true;\n }\n /**\n * Detaches all event handlers\n */\n detachControl() {\n if (this._alreadyAttached) {\n this._deviceSourceManager.dispose();\n this._deviceSourceManager = null;\n // Cursor\n if (this._alreadyAttachedTo && !this._scene.doNotHandleCursors) {\n this._alreadyAttachedTo.style.cursor = this._scene.defaultCursor;\n }\n this._alreadyAttached = false;\n this._alreadyAttachedTo = null;\n }\n }\n /**\n * Force the value of meshUnderPointer\n * @param mesh - defines the mesh to use\n * @param pointerId - optional pointer id when using more than one pointer. Defaults to 0\n * @param pickResult - optional pickingInfo data used to find mesh\n * @param evt - optional pointer event\n */\n setPointerOverMesh(mesh, pointerId = 0, pickResult, evt) {\n if (this._meshUnderPointerId[pointerId] === mesh && (!mesh || !mesh._internalAbstractMeshDataInfo._pointerOverDisableMeshTesting)) {\n return;\n }\n const underPointerMesh = this._meshUnderPointerId[pointerId];\n let actionManager;\n if (underPointerMesh) {\n actionManager = underPointerMesh._getActionManagerForTrigger(10);\n if (actionManager) {\n actionManager.processTrigger(10, ActionEvent.CreateNew(underPointerMesh, evt, { pointerId }));\n }\n }\n if (mesh) {\n this._meshUnderPointerId[pointerId] = mesh;\n this._pointerOverMesh = mesh;\n actionManager = mesh._getActionManagerForTrigger(9);\n if (actionManager) {\n actionManager.processTrigger(9, ActionEvent.CreateNew(mesh, evt, { pointerId, pickResult }));\n }\n }\n else {\n delete this._meshUnderPointerId[pointerId];\n this._pointerOverMesh = null;\n }\n }\n /**\n * Gets the mesh under the pointer\n * @returns a Mesh or null if no mesh is under the pointer\n */\n getPointerOverMesh() {\n return this.meshUnderPointer;\n }\n /**\n * @param mesh - Mesh to invalidate\n * @internal\n */\n _invalidateMesh(mesh) {\n if (this._pointerOverMesh === mesh) {\n this._pointerOverMesh = null;\n }\n if (this._pickedDownMesh === mesh) {\n this._pickedDownMesh = null;\n }\n if (this._pickedUpMesh === mesh) {\n this._pickedUpMesh = null;\n }\n for (const pointerId in this._meshUnderPointerId) {\n if (this._meshUnderPointerId[pointerId] === mesh) {\n delete this._meshUnderPointerId[pointerId];\n }\n }\n }\n }\n /** The distance in pixel that you have to move to prevent some events */\n InputManager.DragMovementThreshold = 10; // in pixels\n /** Time in milliseconds to wait to raise long press events if button is still pressed */\n InputManager.LongPressDelay = 500; // in milliseconds\n /** Time in milliseconds with two consecutive clicks will be considered as a double click */\n InputManager.DoubleClickDelay = 300; // in milliseconds\n /**\n * This flag will modify the behavior so that, when true, a click will happen if and only if\n * another click DOES NOT happen within the DoubleClickDelay time frame. If another click does\n * happen within that time frame, the first click will not fire an event and and a double click will occur.\n */\n InputManager.ExclusiveDoubleClickMode = false;\n\n /**\n * This class is used to track a performance counter which is number based.\n * The user has access to many properties which give statistics of different nature.\n *\n * The implementer can track two kinds of Performance Counter: time and count.\n * For time you can optionally call fetchNewFrame() to notify the start of a new frame to monitor, then call beginMonitoring() to start and endMonitoring() to record the lapsed time. endMonitoring takes a newFrame parameter for you to specify if the monitored time should be set for a new frame or accumulated to the current frame being monitored.\n * For count you first have to call fetchNewFrame() to notify the start of a new frame to monitor, then call addCount() how many time required to increment the count value you monitor.\n */\n class PerfCounter {\n /**\n * Returns the smallest value ever\n */\n get min() {\n return this._min;\n }\n /**\n * Returns the biggest value ever\n */\n get max() {\n return this._max;\n }\n /**\n * Returns the average value since the performance counter is running\n */\n get average() {\n return this._average;\n }\n /**\n * Returns the average value of the last second the counter was monitored\n */\n get lastSecAverage() {\n return this._lastSecAverage;\n }\n /**\n * Returns the current value\n */\n get current() {\n return this._current;\n }\n /**\n * Gets the accumulated total\n */\n get total() {\n return this._totalAccumulated;\n }\n /**\n * Gets the total value count\n */\n get count() {\n return this._totalValueCount;\n }\n /**\n * Creates a new counter\n */\n constructor() {\n this._startMonitoringTime = 0;\n this._min = 0;\n this._max = 0;\n this._average = 0;\n this._lastSecAverage = 0;\n this._current = 0;\n this._totalValueCount = 0;\n this._totalAccumulated = 0;\n this._lastSecAccumulated = 0;\n this._lastSecTime = 0;\n this._lastSecValueCount = 0;\n }\n /**\n * Call this method to start monitoring a new frame.\n * This scenario is typically used when you accumulate monitoring time many times for a single frame, you call this method at the start of the frame, then beginMonitoring to start recording and endMonitoring(false) to accumulated the recorded time to the PerfCounter or addCount() to accumulate a monitored count.\n */\n fetchNewFrame() {\n this._totalValueCount++;\n this._current = 0;\n this._lastSecValueCount++;\n }\n /**\n * Call this method to monitor a count of something (e.g. mesh drawn in viewport count)\n * @param newCount the count value to add to the monitored count\n * @param fetchResult true when it's the last time in the frame you add to the counter and you wish to update the statistics properties (min/max/average), false if you only want to update statistics.\n */\n addCount(newCount, fetchResult) {\n if (!PerfCounter.Enabled) {\n return;\n }\n this._current += newCount;\n if (fetchResult) {\n this._fetchResult();\n }\n }\n /**\n * Start monitoring this performance counter\n */\n beginMonitoring() {\n if (!PerfCounter.Enabled) {\n return;\n }\n this._startMonitoringTime = PrecisionDate.Now;\n }\n /**\n * Compute the time lapsed since the previous beginMonitoring() call.\n * @param newFrame true by default to fetch the result and monitor a new frame, if false the time monitored will be added to the current frame counter\n */\n endMonitoring(newFrame = true) {\n if (!PerfCounter.Enabled) {\n return;\n }\n if (newFrame) {\n this.fetchNewFrame();\n }\n const currentTime = PrecisionDate.Now;\n this._current = currentTime - this._startMonitoringTime;\n if (newFrame) {\n this._fetchResult();\n }\n }\n /**\n * Call this method to end the monitoring of a frame.\n * This scenario is typically used when you accumulate monitoring time many times for a single frame, you call this method at the end of the frame, after beginMonitoring to start recording and endMonitoring(false) to accumulated the recorded time to the PerfCounter or addCount() to accumulate a monitored count.\n */\n endFrame() {\n this._fetchResult();\n }\n _fetchResult() {\n this._totalAccumulated += this._current;\n this._lastSecAccumulated += this._current;\n // Min/Max update\n this._min = Math.min(this._min, this._current);\n this._max = Math.max(this._max, this._current);\n this._average = this._totalAccumulated / this._totalValueCount;\n // Reset last sec?\n const now = PrecisionDate.Now;\n if (now - this._lastSecTime > 1000) {\n this._lastSecAverage = this._lastSecAccumulated / this._lastSecValueCount;\n this._lastSecTime = now;\n this._lastSecAccumulated = 0;\n this._lastSecValueCount = 0;\n }\n }\n }\n /**\n * Gets or sets a global boolean to turn on and off all the counters\n */\n PerfCounter.Enabled = true;\n\n /**\n * Helper class used to generate session unique ID\n */\n class UniqueIdGenerator {\n /**\n * Gets an unique (relatively to the current scene) Id\n */\n static get UniqueId() {\n const result = this._UniqueIdCounter;\n this._UniqueIdCounter++;\n return result;\n }\n }\n // Statics\n UniqueIdGenerator._UniqueIdCounter = 1;\n\n /** Defines the cross module constantsused by lights to avoid circular dependencies */\n class LightConstants {\n /**\n * Sort function to order lights for rendering.\n * @param a First Light object to compare to second.\n * @param b Second Light object to compare first.\n * @returns -1 to reduce's a's index relative to be, 0 for no change, 1 to increase a's index relative to b.\n */\n static CompareLightsPriority(a, b) {\n //shadow-casting lights have priority over non-shadow-casting lights\n //the renderPriority is a secondary sort criterion\n if (a.shadowEnabled !== b.shadowEnabled) {\n return (b.shadowEnabled ? 1 : 0) - (a.shadowEnabled ? 1 : 0);\n }\n return b.renderPriority - a.renderPriority;\n }\n }\n /**\n * Falloff Default: light is falling off following the material specification:\n * standard material is using standard falloff whereas pbr material can request special falloff per materials.\n */\n LightConstants.FALLOFF_DEFAULT = 0;\n /**\n * Falloff Physical: light is falling off following the inverse squared distance law.\n */\n LightConstants.FALLOFF_PHYSICAL = 1;\n /**\n * Falloff gltf: light is falling off as described in the gltf moving to PBR document\n * to enhance interoperability with other engines.\n */\n LightConstants.FALLOFF_GLTF = 2;\n /**\n * Falloff Standard: light is falling off like in the standard material\n * to enhance interoperability with other materials.\n */\n LightConstants.FALLOFF_STANDARD = 3;\n //lightmapMode Consts\n /**\n * If every light affecting the material is in this lightmapMode,\n * material.lightmapTexture adds or multiplies\n * (depends on material.useLightmapAsShadowmap)\n * after every other light calculations.\n */\n LightConstants.LIGHTMAP_DEFAULT = 0;\n /**\n * material.lightmapTexture as only diffuse lighting from this light\n * adds only specular lighting from this light\n * adds dynamic shadows\n */\n LightConstants.LIGHTMAP_SPECULAR = 1;\n /**\n * material.lightmapTexture as only lighting\n * no light calculation from this light\n * only adds dynamic shadows from this light\n */\n LightConstants.LIGHTMAP_SHADOWSONLY = 2;\n // Intensity Mode Consts\n /**\n * Each light type uses the default quantity according to its type:\n * point/spot lights use luminous intensity\n * directional lights use illuminance\n */\n LightConstants.INTENSITYMODE_AUTOMATIC = 0;\n /**\n * lumen (lm)\n */\n LightConstants.INTENSITYMODE_LUMINOUSPOWER = 1;\n /**\n * candela (lm/sr)\n */\n LightConstants.INTENSITYMODE_LUMINOUSINTENSITY = 2;\n /**\n * lux (lm/m^2)\n */\n LightConstants.INTENSITYMODE_ILLUMINANCE = 3;\n /**\n * nit (cd/m^2)\n */\n LightConstants.INTENSITYMODE_LUMINANCE = 4;\n // Light types ids const.\n /**\n * Light type const id of the point light.\n */\n LightConstants.LIGHTTYPEID_POINTLIGHT = 0;\n /**\n * Light type const id of the directional light.\n */\n LightConstants.LIGHTTYPEID_DIRECTIONALLIGHT = 1;\n /**\n * Light type const id of the spot light.\n */\n LightConstants.LIGHTTYPEID_SPOTLIGHT = 2;\n /**\n * Light type const id of the hemispheric light.\n */\n LightConstants.LIGHTTYPEID_HEMISPHERICLIGHT = 3;\n\n /**\n * Class used to store configuration data associated with pointer picking\n */\n class PointerPickingConfiguration {\n constructor() {\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\n */\n this.pointerDownFastCheck = false;\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\n */\n this.pointerUpFastCheck = false;\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\n */\n this.pointerMoveFastCheck = false;\n /**\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer move event occurs.\n */\n this.skipPointerMovePicking = false;\n /**\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer down event occurs.\n */\n this.skipPointerDownPicking = false;\n /**\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer up event occurs. Off by default.\n */\n this.skipPointerUpPicking = false;\n }\n }\n\n /**\n * Define how the scene should favor performance over ease of use\n */\n var ScenePerformancePriority;\n (function (ScenePerformancePriority) {\n /** Default mode. No change. Performance will be treated as less important than backward compatibility */\n ScenePerformancePriority[ScenePerformancePriority[\"BackwardCompatible\"] = 0] = \"BackwardCompatible\";\n /** Some performance options will be turned on trying to strike a balance between perf and ease of use */\n ScenePerformancePriority[ScenePerformancePriority[\"Intermediate\"] = 1] = \"Intermediate\";\n /** Performance will be top priority */\n ScenePerformancePriority[ScenePerformancePriority[\"Aggressive\"] = 2] = \"Aggressive\";\n })(ScenePerformancePriority || (ScenePerformancePriority = {}));\n /**\n * Represents a scene to be rendered by the engine.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene\n */\n class Scene extends AbstractScene {\n /**\n * Factory used to create the default material.\n * @param scene The scene to create the material for\n * @returns The default material\n */\n static DefaultMaterialFactory(scene) {\n throw _WarnImport(\"StandardMaterial\");\n }\n /**\n * Factory used to create the a collision coordinator.\n * @returns The collision coordinator\n */\n static CollisionCoordinatorFactory() {\n throw _WarnImport(\"DefaultCollisionCoordinator\");\n }\n /**\n * Texture used in all pbr material as the reflection texture.\n * As in the majority of the scene they are the same (exception for multi room and so on),\n * this is easier to reference from here than from all the materials.\n */\n get environmentTexture() {\n return this._environmentTexture;\n }\n /**\n * Texture used in all pbr material as the reflection texture.\n * As in the majority of the scene they are the same (exception for multi room and so on),\n * this is easier to set here than in all the materials.\n */\n set environmentTexture(value) {\n if (this._environmentTexture === value) {\n return;\n }\n this._environmentTexture = value;\n this.markAllMaterialsAsDirty(1);\n }\n /**\n * Default image processing configuration used either in the rendering\n * Forward main pass or through the imageProcessingPostProcess if present.\n * As in the majority of the scene they are the same (exception for multi camera),\n * this is easier to reference from here than from all the materials and post process.\n *\n * No setter as we it is a shared configuration, you can set the values instead.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Gets or sets a value indicating how to treat performance relatively to ease of use and backward compatibility\n */\n get performancePriority() {\n return this._performancePriority;\n }\n set performancePriority(value) {\n if (value === this._performancePriority) {\n return;\n }\n this._performancePriority = value;\n switch (value) {\n case ScenePerformancePriority.BackwardCompatible:\n this.skipFrustumClipping = false;\n this._renderingManager.maintainStateBetweenFrames = false;\n this.skipPointerMovePicking = false;\n this.autoClear = true;\n break;\n case ScenePerformancePriority.Intermediate:\n this.skipFrustumClipping = false;\n this._renderingManager.maintainStateBetweenFrames = false;\n this.skipPointerMovePicking = true;\n this.autoClear = false;\n break;\n case ScenePerformancePriority.Aggressive:\n this.skipFrustumClipping = true;\n this._renderingManager.maintainStateBetweenFrames = true;\n this.skipPointerMovePicking = true;\n this.autoClear = false;\n break;\n }\n this.onScenePerformancePriorityChangedObservable.notifyObservers(value);\n }\n /**\n * Gets or sets a boolean indicating if all rendering must be done in wireframe\n */\n set forceWireframe(value) {\n if (this._forceWireframe === value) {\n return;\n }\n this._forceWireframe = value;\n this.markAllMaterialsAsDirty(16);\n }\n get forceWireframe() {\n return this._forceWireframe;\n }\n /**\n * Gets or sets a boolean indicating if we should skip the frustum clipping part of the active meshes selection\n */\n set skipFrustumClipping(value) {\n if (this._skipFrustumClipping === value) {\n return;\n }\n this._skipFrustumClipping = value;\n }\n get skipFrustumClipping() {\n return this._skipFrustumClipping;\n }\n /**\n * Gets or sets a boolean indicating if all rendering must be done in point cloud\n */\n set forcePointsCloud(value) {\n if (this._forcePointsCloud === value) {\n return;\n }\n this._forcePointsCloud = value;\n this.markAllMaterialsAsDirty(16);\n }\n get forcePointsCloud() {\n return this._forcePointsCloud;\n }\n /**\n * Gets or sets the animation properties override\n */\n get animationPropertiesOverride() {\n return this._animationPropertiesOverride;\n }\n set animationPropertiesOverride(value) {\n this._animationPropertiesOverride = value;\n }\n /** Sets a function to be executed when this scene is disposed. */\n set onDispose(callback) {\n if (this._onDisposeObserver) {\n this.onDisposeObservable.remove(this._onDisposeObserver);\n }\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\n }\n /** Sets a function to be executed before rendering this scene */\n set beforeRender(callback) {\n if (this._onBeforeRenderObserver) {\n this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\n }\n if (callback) {\n this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);\n }\n }\n /** Sets a function to be executed after rendering this scene */\n set afterRender(callback) {\n if (this._onAfterRenderObserver) {\n this.onAfterRenderObservable.remove(this._onAfterRenderObserver);\n }\n if (callback) {\n this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);\n }\n }\n /** Sets a function to be executed before rendering a camera*/\n set beforeCameraRender(callback) {\n if (this._onBeforeCameraRenderObserver) {\n this.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);\n }\n this._onBeforeCameraRenderObserver = this.onBeforeCameraRenderObservable.add(callback);\n }\n /** Sets a function to be executed after rendering a camera*/\n set afterCameraRender(callback) {\n if (this._onAfterCameraRenderObserver) {\n this.onAfterCameraRenderObservable.remove(this._onAfterCameraRenderObserver);\n }\n this._onAfterCameraRenderObserver = this.onAfterCameraRenderObservable.add(callback);\n }\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\n */\n get pointerDownPredicate() {\n return this._pointerPickingConfiguration.pointerDownPredicate;\n }\n set pointerDownPredicate(value) {\n this._pointerPickingConfiguration.pointerDownPredicate = value;\n }\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\n */\n get pointerUpPredicate() {\n return this._pointerPickingConfiguration.pointerUpPredicate;\n }\n set pointerUpPredicate(value) {\n this._pointerPickingConfiguration.pointerUpPredicate = value;\n }\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\n */\n get pointerMovePredicate() {\n return this._pointerPickingConfiguration.pointerMovePredicate;\n }\n set pointerMovePredicate(value) {\n this._pointerPickingConfiguration.pointerMovePredicate = value;\n }\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\n */\n get pointerDownFastCheck() {\n return this._pointerPickingConfiguration.pointerDownFastCheck;\n }\n set pointerDownFastCheck(value) {\n this._pointerPickingConfiguration.pointerDownFastCheck = value;\n }\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\n */\n get pointerUpFastCheck() {\n return this._pointerPickingConfiguration.pointerUpFastCheck;\n }\n set pointerUpFastCheck(value) {\n this._pointerPickingConfiguration.pointerUpFastCheck = value;\n }\n /**\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\n */\n get pointerMoveFastCheck() {\n return this._pointerPickingConfiguration.pointerMoveFastCheck;\n }\n set pointerMoveFastCheck(value) {\n this._pointerPickingConfiguration.pointerMoveFastCheck = value;\n }\n /**\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer move event occurs.\n */\n get skipPointerMovePicking() {\n return this._pointerPickingConfiguration.skipPointerMovePicking;\n }\n set skipPointerMovePicking(value) {\n this._pointerPickingConfiguration.skipPointerMovePicking = value;\n }\n /**\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer down event occurs.\n */\n get skipPointerDownPicking() {\n return this._pointerPickingConfiguration.skipPointerDownPicking;\n }\n set skipPointerDownPicking(value) {\n this._pointerPickingConfiguration.skipPointerDownPicking = value;\n }\n /**\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer up event occurs. Off by default.\n */\n get skipPointerUpPicking() {\n return this._pointerPickingConfiguration.skipPointerUpPicking;\n }\n set skipPointerUpPicking(value) {\n this._pointerPickingConfiguration.skipPointerUpPicking = value;\n }\n /**\n * Gets the pointer coordinates without any translation (ie. straight out of the pointer event)\n */\n get unTranslatedPointer() {\n return this._inputManager.unTranslatedPointer;\n }\n /**\n * Gets or sets the distance in pixel that you have to move to prevent some events. Default is 10 pixels\n */\n static get DragMovementThreshold() {\n return InputManager.DragMovementThreshold;\n }\n static set DragMovementThreshold(value) {\n InputManager.DragMovementThreshold = value;\n }\n /**\n * Time in milliseconds to wait to raise long press events if button is still pressed. Default is 500 ms\n */\n static get LongPressDelay() {\n return InputManager.LongPressDelay;\n }\n static set LongPressDelay(value) {\n InputManager.LongPressDelay = value;\n }\n /**\n * Time in milliseconds to wait to raise long press events if button is still pressed. Default is 300 ms\n */\n static get DoubleClickDelay() {\n return InputManager.DoubleClickDelay;\n }\n static set DoubleClickDelay(value) {\n InputManager.DoubleClickDelay = value;\n }\n /** If you need to check double click without raising a single click at first click, enable this flag */\n static get ExclusiveDoubleClickMode() {\n return InputManager.ExclusiveDoubleClickMode;\n }\n static set ExclusiveDoubleClickMode(value) {\n InputManager.ExclusiveDoubleClickMode = value;\n }\n /**\n * Bind the current view position to an effect.\n * @param effect The effect to be bound\n * @param variableName name of the shader variable that will hold the eye position\n * @param isVector3 true to indicates that variableName is a Vector3 and not a Vector4\n * @returns the computed eye position\n */\n bindEyePosition(effect, variableName = \"vEyePosition\", isVector3 = false) {\n var _a;\n const eyePosition = this._forcedViewPosition\n ? this._forcedViewPosition\n : this._mirroredCameraPosition\n ? this._mirroredCameraPosition\n : (_a = this.activeCamera.globalPosition) !== null && _a !== void 0 ? _a : this.activeCamera.devicePosition;\n const invertNormal = this.useRightHandedSystem === (this._mirroredCameraPosition != null);\n TmpVectors.Vector4[0].set(eyePosition.x, eyePosition.y, eyePosition.z, invertNormal ? -1 : 1);\n if (effect) {\n if (isVector3) {\n effect.setFloat3(variableName, TmpVectors.Vector4[0].x, TmpVectors.Vector4[0].y, TmpVectors.Vector4[0].z);\n }\n else {\n effect.setVector4(variableName, TmpVectors.Vector4[0]);\n }\n }\n return TmpVectors.Vector4[0];\n }\n /**\n * Update the scene ubo before it can be used in rendering processing\n * @returns the scene UniformBuffer\n */\n finalizeSceneUbo() {\n const ubo = this.getSceneUniformBuffer();\n const eyePosition = this.bindEyePosition(null);\n ubo.updateFloat4(\"vEyePosition\", eyePosition.x, eyePosition.y, eyePosition.z, eyePosition.w);\n ubo.update();\n return ubo;\n }\n /**\n * Gets or sets a boolean indicating if the scene must use right-handed coordinates system\n */\n set useRightHandedSystem(value) {\n if (this._useRightHandedSystem === value) {\n return;\n }\n this._useRightHandedSystem = value;\n this.markAllMaterialsAsDirty(16);\n }\n get useRightHandedSystem() {\n return this._useRightHandedSystem;\n }\n /**\n * Sets the step Id used by deterministic lock step\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n * @param newStepId defines the step Id\n */\n setStepId(newStepId) {\n this._currentStepId = newStepId;\n }\n /**\n * Gets the step Id used by deterministic lock step\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n * @returns the step Id\n */\n getStepId() {\n return this._currentStepId;\n }\n /**\n * Gets the internal step used by deterministic lock step\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n * @returns the internal step\n */\n getInternalStep() {\n return this._currentInternalStep;\n }\n /**\n * Gets or sets a boolean indicating if fog is enabled on this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\n * (Default is true)\n */\n set fogEnabled(value) {\n if (this._fogEnabled === value) {\n return;\n }\n this._fogEnabled = value;\n this.markAllMaterialsAsDirty(16);\n }\n get fogEnabled() {\n return this._fogEnabled;\n }\n /**\n * Gets or sets the fog mode to use\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\n * | mode | value |\n * | --- | --- |\n * | FOGMODE_NONE | 0 |\n * | FOGMODE_EXP | 1 |\n * | FOGMODE_EXP2 | 2 |\n * | FOGMODE_LINEAR | 3 |\n */\n set fogMode(value) {\n if (this._fogMode === value) {\n return;\n }\n this._fogMode = value;\n this.markAllMaterialsAsDirty(16);\n }\n get fogMode() {\n return this._fogMode;\n }\n /**\n * Flag indicating that the frame buffer binding is handled by another component\n */\n get prePass() {\n return !!this.prePassRenderer && this.prePassRenderer.defaultRT.enabled;\n }\n /**\n * Gets or sets a boolean indicating if shadows are enabled on this scene\n */\n set shadowsEnabled(value) {\n if (this._shadowsEnabled === value) {\n return;\n }\n this._shadowsEnabled = value;\n this.markAllMaterialsAsDirty(2);\n }\n get shadowsEnabled() {\n return this._shadowsEnabled;\n }\n /**\n * Gets or sets a boolean indicating if lights are enabled on this scene\n */\n set lightsEnabled(value) {\n if (this._lightsEnabled === value) {\n return;\n }\n this._lightsEnabled = value;\n this.markAllMaterialsAsDirty(2);\n }\n get lightsEnabled() {\n return this._lightsEnabled;\n }\n /** All of the active cameras added to this scene. */\n get activeCameras() {\n return this._activeCameras;\n }\n set activeCameras(cameras) {\n if (this._unObserveActiveCameras) {\n this._unObserveActiveCameras();\n this._unObserveActiveCameras = null;\n }\n if (cameras) {\n this._unObserveActiveCameras = _ObserveArray(cameras, () => {\n this.onActiveCamerasChanged.notifyObservers(this);\n });\n }\n this._activeCameras = cameras;\n }\n /** Gets or sets the current active camera */\n get activeCamera() {\n return this._activeCamera;\n }\n set activeCamera(value) {\n if (value === this._activeCamera) {\n return;\n }\n this._activeCamera = value;\n this.onActiveCameraChanged.notifyObservers(this);\n }\n /** The default material used on meshes when no material is affected */\n get defaultMaterial() {\n if (!this._defaultMaterial) {\n this._defaultMaterial = Scene.DefaultMaterialFactory(this);\n }\n return this._defaultMaterial;\n }\n /** The default material used on meshes when no material is affected */\n set defaultMaterial(value) {\n this._defaultMaterial = value;\n }\n /**\n * Gets or sets a boolean indicating if textures are enabled on this scene\n */\n set texturesEnabled(value) {\n if (this._texturesEnabled === value) {\n return;\n }\n this._texturesEnabled = value;\n this.markAllMaterialsAsDirty(1);\n }\n get texturesEnabled() {\n return this._texturesEnabled;\n }\n /**\n * Gets or sets a boolean indicating if skeletons are enabled on this scene\n */\n set skeletonsEnabled(value) {\n if (this._skeletonsEnabled === value) {\n return;\n }\n this._skeletonsEnabled = value;\n this.markAllMaterialsAsDirty(8);\n }\n get skeletonsEnabled() {\n return this._skeletonsEnabled;\n }\n /** @internal */\n get collisionCoordinator() {\n if (!this._collisionCoordinator) {\n this._collisionCoordinator = Scene.CollisionCoordinatorFactory();\n this._collisionCoordinator.init(this);\n }\n return this._collisionCoordinator;\n }\n /**\n * Gets the scene's rendering manager\n */\n get renderingManager() {\n return this._renderingManager;\n }\n /**\n * Gets the list of frustum planes (built from the active camera)\n */\n get frustumPlanes() {\n return this._frustumPlanes;\n }\n /**\n * Registers the transient components if needed.\n */\n _registerTransientComponents() {\n // Register components that have been associated lately to the scene.\n if (this._transientComponents.length > 0) {\n for (const component of this._transientComponents) {\n component.register();\n }\n this._transientComponents.length = 0;\n }\n }\n /**\n * @internal\n * Add a component to the scene.\n * Note that the ccomponent could be registered on th next frame if this is called after\n * the register component stage.\n * @param component Defines the component to add to the scene\n */\n _addComponent(component) {\n this._components.push(component);\n this._transientComponents.push(component);\n const serializableComponent = component;\n if (serializableComponent.addFromContainer && serializableComponent.serialize) {\n this._serializableComponents.push(serializableComponent);\n }\n }\n /**\n * @internal\n * Gets a component from the scene.\n * @param name defines the name of the component to retrieve\n * @returns the component or null if not present\n */\n _getComponent(name) {\n for (const component of this._components) {\n if (component.name === name) {\n return component;\n }\n }\n return null;\n }\n /**\n * Creates a new Scene\n * @param engine defines the engine to use to render this scene\n * @param options defines the scene options\n */\n constructor(engine, options) {\n super();\n // Members\n /** @internal */\n this._inputManager = new InputManager(this);\n /** Define this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position */\n this.cameraToUseForPointers = null;\n /** @internal */\n this._isScene = true;\n /** @internal */\n this._blockEntityCollection = false;\n /**\n * Gets or sets a boolean that indicates if the scene must clear the render buffer before rendering a frame\n */\n this.autoClear = true;\n /**\n * Gets or sets a boolean that indicates if the scene must clear the depth and stencil buffers before rendering a frame\n */\n this.autoClearDepthAndStencil = true;\n /**\n * Defines the color used to clear the render buffer (Default is (0.2, 0.2, 0.3, 1.0))\n */\n this.clearColor = new Color4(0.2, 0.2, 0.3, 1.0);\n /**\n * Defines the color used to simulate the ambient color (Default is (0, 0, 0))\n */\n this.ambientColor = new Color3(0, 0, 0);\n /**\n * Intensity of the environment in all pbr material.\n * This dims or reinforces the IBL lighting overall (reflection and diffuse).\n * As in the majority of the scene they are the same (exception for multi room and so on),\n * this is easier to reference from here than from all the materials.\n */\n this.environmentIntensity = 1;\n this._performancePriority = ScenePerformancePriority.BackwardCompatible;\n /**\n * Observable triggered when the performance priority is changed\n */\n this.onScenePerformancePriorityChangedObservable = new Observable$1();\n this._forceWireframe = false;\n this._skipFrustumClipping = false;\n this._forcePointsCloud = false;\n /**\n * Gets or sets a boolean indicating if animations are enabled\n */\n this.animationsEnabled = true;\n this._animationPropertiesOverride = null;\n /**\n * Gets or sets a boolean indicating if a constant deltatime has to be used\n * This is mostly useful for testing purposes when you do not want the animations to scale with the framerate\n */\n this.useConstantAnimationDeltaTime = false;\n /**\n * Gets or sets a boolean indicating if the scene must keep the meshUnderPointer property updated\n * Please note that it requires to run a ray cast through the scene on every frame\n */\n this.constantlyUpdateMeshUnderPointer = false;\n /**\n * Defines the HTML cursor to use when hovering over interactive elements\n */\n this.hoverCursor = \"pointer\";\n /**\n * Defines the HTML default cursor to use (empty by default)\n */\n this.defaultCursor = \"\";\n /**\n * Defines whether cursors are handled by the scene.\n */\n this.doNotHandleCursors = false;\n /**\n * This is used to call preventDefault() on pointer down\n * in order to block unwanted artifacts like system double clicks\n */\n this.preventDefaultOnPointerDown = true;\n /**\n * This is used to call preventDefault() on pointer up\n * in order to block unwanted artifacts like system double clicks\n */\n this.preventDefaultOnPointerUp = true;\n // Metadata\n /**\n * Gets or sets user defined metadata\n */\n this.metadata = null;\n /**\n * For internal use only. Please do not use.\n */\n this.reservedDataStore = null;\n /**\n * Use this array to add regular expressions used to disable offline support for specific urls\n */\n this.disableOfflineSupportExceptionRules = new Array();\n /**\n * An event triggered when the scene is disposed.\n */\n this.onDisposeObservable = new Observable$1();\n this._onDisposeObserver = null;\n /**\n * An event triggered before rendering the scene (right after animations and physics)\n */\n this.onBeforeRenderObservable = new Observable$1();\n this._onBeforeRenderObserver = null;\n /**\n * An event triggered after rendering the scene\n */\n this.onAfterRenderObservable = new Observable$1();\n /**\n * An event triggered after rendering the scene for an active camera (When scene.render is called this will be called after each camera)\n * This is triggered for each \"sub\" camera in a Camera Rig unlike onAfterCameraRenderObservable\n */\n this.onAfterRenderCameraObservable = new Observable$1();\n this._onAfterRenderObserver = null;\n /**\n * An event triggered before animating the scene\n */\n this.onBeforeAnimationsObservable = new Observable$1();\n /**\n * An event triggered after animations processing\n */\n this.onAfterAnimationsObservable = new Observable$1();\n /**\n * An event triggered before draw calls are ready to be sent\n */\n this.onBeforeDrawPhaseObservable = new Observable$1();\n /**\n * An event triggered after draw calls have been sent\n */\n this.onAfterDrawPhaseObservable = new Observable$1();\n /**\n * An event triggered when the scene is ready\n */\n this.onReadyObservable = new Observable$1();\n /**\n * An event triggered before rendering a camera\n */\n this.onBeforeCameraRenderObservable = new Observable$1();\n this._onBeforeCameraRenderObserver = null;\n /**\n * An event triggered after rendering a camera\n * This is triggered for the full rig Camera only unlike onAfterRenderCameraObservable\n */\n this.onAfterCameraRenderObservable = new Observable$1();\n this._onAfterCameraRenderObserver = null;\n /**\n * An event triggered when active meshes evaluation is about to start\n */\n this.onBeforeActiveMeshesEvaluationObservable = new Observable$1();\n /**\n * An event triggered when active meshes evaluation is done\n */\n this.onAfterActiveMeshesEvaluationObservable = new Observable$1();\n /**\n * An event triggered when particles rendering is about to start\n * Note: This event can be trigger more than once per frame (because particles can be rendered by render target textures as well)\n */\n this.onBeforeParticlesRenderingObservable = new Observable$1();\n /**\n * An event triggered when particles rendering is done\n * Note: This event can be trigger more than once per frame (because particles can be rendered by render target textures as well)\n */\n this.onAfterParticlesRenderingObservable = new Observable$1();\n /**\n * An event triggered when SceneLoader.Append or SceneLoader.Load or SceneLoader.ImportMesh were successfully executed\n */\n this.onDataLoadedObservable = new Observable$1();\n /**\n * An event triggered when a camera is created\n */\n this.onNewCameraAddedObservable = new Observable$1();\n /**\n * An event triggered when a camera is removed\n */\n this.onCameraRemovedObservable = new Observable$1();\n /**\n * An event triggered when a light is created\n */\n this.onNewLightAddedObservable = new Observable$1();\n /**\n * An event triggered when a light is removed\n */\n this.onLightRemovedObservable = new Observable$1();\n /**\n * An event triggered when a geometry is created\n */\n this.onNewGeometryAddedObservable = new Observable$1();\n /**\n * An event triggered when a geometry is removed\n */\n this.onGeometryRemovedObservable = new Observable$1();\n /**\n * An event triggered when a transform node is created\n */\n this.onNewTransformNodeAddedObservable = new Observable$1();\n /**\n * An event triggered when a transform node is removed\n */\n this.onTransformNodeRemovedObservable = new Observable$1();\n /**\n * An event triggered when a mesh is created\n */\n this.onNewMeshAddedObservable = new Observable$1();\n /**\n * An event triggered when a mesh is removed\n */\n this.onMeshRemovedObservable = new Observable$1();\n /**\n * An event triggered when a skeleton is created\n */\n this.onNewSkeletonAddedObservable = new Observable$1();\n /**\n * An event triggered when a skeleton is removed\n */\n this.onSkeletonRemovedObservable = new Observable$1();\n /**\n * An event triggered when a material is created\n */\n this.onNewMaterialAddedObservable = new Observable$1();\n /**\n * An event triggered when a multi material is created\n */\n this.onNewMultiMaterialAddedObservable = new Observable$1();\n /**\n * An event triggered when a material is removed\n */\n this.onMaterialRemovedObservable = new Observable$1();\n /**\n * An event triggered when a multi material is removed\n */\n this.onMultiMaterialRemovedObservable = new Observable$1();\n /**\n * An event triggered when a texture is created\n */\n this.onNewTextureAddedObservable = new Observable$1();\n /**\n * An event triggered when a texture is removed\n */\n this.onTextureRemovedObservable = new Observable$1();\n /**\n * An event triggered when render targets are about to be rendered\n * Can happen multiple times per frame.\n */\n this.onBeforeRenderTargetsRenderObservable = new Observable$1();\n /**\n * An event triggered when render targets were rendered.\n * Can happen multiple times per frame.\n */\n this.onAfterRenderTargetsRenderObservable = new Observable$1();\n /**\n * An event triggered before calculating deterministic simulation step\n */\n this.onBeforeStepObservable = new Observable$1();\n /**\n * An event triggered after calculating deterministic simulation step\n */\n this.onAfterStepObservable = new Observable$1();\n /**\n * An event triggered when the activeCamera property is updated\n */\n this.onActiveCameraChanged = new Observable$1();\n /**\n * An event triggered when the activeCameras property is updated\n */\n this.onActiveCamerasChanged = new Observable$1();\n /**\n * This Observable will be triggered before rendering each renderingGroup of each rendered camera.\n * The RenderingGroupInfo class contains all the information about the context in which the observable is called\n * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)\n */\n this.onBeforeRenderingGroupObservable = new Observable$1();\n /**\n * This Observable will be triggered after rendering each renderingGroup of each rendered camera.\n * The RenderingGroupInfo class contains all the information about the context in which the observable is called\n * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)\n */\n this.onAfterRenderingGroupObservable = new Observable$1();\n /**\n * This Observable will when a mesh has been imported into the scene.\n */\n this.onMeshImportedObservable = new Observable$1();\n /**\n * This Observable will when an animation file has been imported into the scene.\n */\n this.onAnimationFileImportedObservable = new Observable$1();\n // Animations\n /** @internal */\n this._registeredForLateAnimationBindings = new SmartArrayNoDuplicate(256);\n // Pointers\n this._pointerPickingConfiguration = new PointerPickingConfiguration();\n /**\n * This observable event is triggered when any ponter event is triggered. It is registered during Scene.attachControl() and it is called BEFORE the 3D engine process anything (mesh/sprite picking for instance).\n * You have the possibility to skip the process and the call to onPointerObservable by setting PointerInfoPre.skipOnPointerObservable to true\n */\n this.onPrePointerObservable = new Observable$1();\n /**\n * Observable event triggered each time an input event is received from the rendering canvas\n */\n this.onPointerObservable = new Observable$1();\n // Keyboard\n /**\n * This observable event is triggered when any keyboard event si raised and registered during Scene.attachControl()\n * You have the possibility to skip the process and the call to onKeyboardObservable by setting KeyboardInfoPre.skipOnPointerObservable to true\n */\n this.onPreKeyboardObservable = new Observable$1();\n /**\n * Observable event triggered each time an keyboard event is received from the hosting window\n */\n this.onKeyboardObservable = new Observable$1();\n // Coordinates system\n this._useRightHandedSystem = false;\n // Deterministic lockstep\n this._timeAccumulator = 0;\n this._currentStepId = 0;\n this._currentInternalStep = 0;\n // Fog\n this._fogEnabled = true;\n this._fogMode = Scene.FOGMODE_NONE;\n /**\n * Gets or sets the fog color to use\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\n * (Default is Color3(0.2, 0.2, 0.3))\n */\n this.fogColor = new Color3(0.2, 0.2, 0.3);\n /**\n * Gets or sets the fog density to use\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\n * (Default is 0.1)\n */\n this.fogDensity = 0.1;\n /**\n * Gets or sets the fog start distance to use\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\n * (Default is 0)\n */\n this.fogStart = 0;\n /**\n * Gets or sets the fog end distance to use\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\n * (Default is 1000)\n */\n this.fogEnd = 1000.0;\n /**\n * Flag indicating if we need to store previous matrices when rendering\n */\n this.needsPreviousWorldMatrices = false;\n // Lights\n this._shadowsEnabled = true;\n this._lightsEnabled = true;\n this._unObserveActiveCameras = null;\n // Textures\n this._texturesEnabled = true;\n // Physics\n /**\n * Gets or sets a boolean indicating if physic engines are enabled on this scene\n */\n this.physicsEnabled = true;\n // Particles\n /**\n * Gets or sets a boolean indicating if particles are enabled on this scene\n */\n this.particlesEnabled = true;\n // Sprites\n /**\n * Gets or sets a boolean indicating if sprites are enabled on this scene\n */\n this.spritesEnabled = true;\n // Skeletons\n this._skeletonsEnabled = true;\n // Lens flares\n /**\n * Gets or sets a boolean indicating if lens flares are enabled on this scene\n */\n this.lensFlaresEnabled = true;\n // Collisions\n /**\n * Gets or sets a boolean indicating if collisions are enabled on this scene\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n */\n this.collisionsEnabled = true;\n /**\n * Defines the gravity applied to this scene (used only for collisions)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n */\n this.gravity = new Vector3(0, -9.807, 0);\n // Postprocesses\n /**\n * Gets or sets a boolean indicating if postprocesses are enabled on this scene\n */\n this.postProcessesEnabled = true;\n // Customs render targets\n /**\n * Gets or sets a boolean indicating if render targets are enabled on this scene\n */\n this.renderTargetsEnabled = true;\n /**\n * Gets or sets a boolean indicating if next render targets must be dumped as image for debugging purposes\n * We recommend not using it and instead rely on Spector.js: http://spector.babylonjs.com\n */\n this.dumpNextRenderTargets = false;\n /**\n * The list of user defined render targets added to the scene\n */\n this.customRenderTargets = new Array();\n /**\n * Gets the list of meshes imported to the scene through SceneLoader\n */\n this.importedMeshesFiles = new Array();\n // Probes\n /**\n * Gets or sets a boolean indicating if probes are enabled on this scene\n */\n this.probesEnabled = true;\n this._meshesForIntersections = new SmartArrayNoDuplicate(256);\n // Procedural textures\n /**\n * Gets or sets a boolean indicating if procedural textures are enabled on this scene\n */\n this.proceduralTexturesEnabled = true;\n // Performance counters\n this._totalVertices = new PerfCounter();\n /** @internal */\n this._activeIndices = new PerfCounter();\n /** @internal */\n this._activeParticles = new PerfCounter();\n /** @internal */\n this._activeBones = new PerfCounter();\n /** @internal */\n this._animationTime = 0;\n /**\n * Gets or sets a general scale for animation speed\n * @see https://www.babylonjs-playground.com/#IBU2W7#3\n */\n this.animationTimeScale = 1;\n this._renderId = 0;\n this._frameId = 0;\n this._executeWhenReadyTimeoutId = null;\n this._intermediateRendering = false;\n this._defaultFrameBufferCleared = false;\n this._viewUpdateFlag = -1;\n this._projectionUpdateFlag = -1;\n /** @internal */\n this._toBeDisposed = new Array(256);\n this._activeRequests = new Array();\n /** @internal */\n this._pendingData = new Array();\n this._isDisposed = false;\n /**\n * Gets or sets a boolean indicating that all submeshes of active meshes must be rendered\n * Use this boolean to avoid computing frustum clipping on submeshes (This could help when you are CPU bound)\n */\n this.dispatchAllSubMeshesOfActiveMeshes = false;\n this._activeMeshes = new SmartArray(256);\n this._processedMaterials = new SmartArray(256);\n this._renderTargets = new SmartArrayNoDuplicate(256);\n this._materialsRenderTargets = new SmartArrayNoDuplicate(256);\n /** @internal */\n this._activeParticleSystems = new SmartArray(256);\n this._activeSkeletons = new SmartArrayNoDuplicate(32);\n this._softwareSkinnedMeshes = new SmartArrayNoDuplicate(32);\n /** @internal */\n this._activeAnimatables = new Array();\n this._transformMatrix = Matrix.Zero();\n /**\n * Gets or sets a boolean indicating if lights must be sorted by priority (off by default)\n * This is useful if there are more lights that the maximum simulteanous authorized\n */\n this.requireLightSorting = false;\n /**\n * @internal\n * Backing store of defined scene components.\n */\n this._components = [];\n /**\n * @internal\n * Backing store of defined scene components.\n */\n this._serializableComponents = [];\n /**\n * List of components to register on the next registration step.\n */\n this._transientComponents = [];\n /**\n * @internal\n * Defines the actions happening before camera updates.\n */\n this._beforeCameraUpdateStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening before clear the canvas.\n */\n this._beforeClearStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening before clear the canvas.\n */\n this._beforeRenderTargetClearStage = Stage.Create();\n /**\n * @internal\n * Defines the actions when collecting render targets for the frame.\n */\n this._gatherRenderTargetsStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening for one camera in the frame.\n */\n this._gatherActiveCameraRenderTargetsStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening during the per mesh ready checks.\n */\n this._isReadyForMeshStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening before evaluate active mesh checks.\n */\n this._beforeEvaluateActiveMeshStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening during the evaluate sub mesh checks.\n */\n this._evaluateSubMeshStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening during the active mesh stage.\n */\n this._preActiveMeshStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening during the per camera render target step.\n */\n this._cameraDrawRenderTargetStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just before the active camera is drawing.\n */\n this._beforeCameraDrawStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just before a render target is drawing.\n */\n this._beforeRenderTargetDrawStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just before a rendering group is drawing.\n */\n this._beforeRenderingGroupDrawStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just before a mesh is drawing.\n */\n this._beforeRenderingMeshStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just after a mesh has been drawn.\n */\n this._afterRenderingMeshStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just after a rendering group has been drawn.\n */\n this._afterRenderingGroupDrawStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just after the active camera has been drawn.\n */\n this._afterCameraDrawStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just after the post processing\n */\n this._afterCameraPostProcessStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just after a render target has been drawn.\n */\n this._afterRenderTargetDrawStage = Stage.Create();\n /**\n * Defines the actions happening just after the post processing on a render target\n */\n this._afterRenderTargetPostProcessStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening just after rendering all cameras and computing intersections.\n */\n this._afterRenderStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening when a pointer move event happens.\n */\n this._pointerMoveStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening when a pointer down event happens.\n */\n this._pointerDownStage = Stage.Create();\n /**\n * @internal\n * Defines the actions happening when a pointer up event happens.\n */\n this._pointerUpStage = Stage.Create();\n /**\n * an optional map from Geometry Id to Geometry index in the 'geometries' array\n */\n this._geometriesByUniqueId = null;\n this._defaultMeshCandidates = {\n data: [],\n length: 0,\n };\n this._defaultSubMeshCandidates = {\n data: [],\n length: 0,\n };\n this._preventFreeActiveMeshesAndRenderingGroups = false;\n /** @internal */\n this._activeMeshesFrozen = false;\n /** @internal */\n this._activeMeshesFrozenButKeepClipping = false;\n this._skipEvaluateActiveMeshesCompletely = false;\n /** @internal */\n this._allowPostProcessClearColor = true;\n /**\n * User updatable function that will return a deterministic frame time when engine is in deterministic lock step mode\n */\n this.getDeterministicFrameTime = () => {\n return this._engine.getTimeStep();\n };\n /** @internal */\n this._registeredActions = 0;\n this._blockMaterialDirtyMechanism = false;\n /**\n * Internal perfCollector instance used for sharing between inspector and playground.\n * Marked as protected to allow sharing between prototype extensions, but disallow access at toplevel.\n */\n this._perfCollector = null;\n this.activeCameras = new Array();\n const fullOptions = Object.assign({ useGeometryUniqueIdsMap: true, useMaterialMeshMap: true, useClonedMeshMap: true, virtual: false }, options);\n this._engine = engine || EngineStore.LastCreatedEngine;\n if (!fullOptions.virtual) {\n EngineStore._LastCreatedScene = this;\n this._engine.scenes.push(this);\n }\n else {\n this._engine._virtualScenes.push(this);\n }\n this._uid = null;\n this._renderingManager = new RenderingManager(this);\n if (PostProcessManager) {\n this.postProcessManager = new PostProcessManager(this);\n }\n if (IsWindowObjectExist()) {\n this.attachControl();\n }\n // Uniform Buffer\n this._createUbo();\n // Default Image processing definition\n if (ImageProcessingConfiguration) {\n this._imageProcessingConfiguration = new ImageProcessingConfiguration();\n }\n this.setDefaultCandidateProviders();\n if (fullOptions.useGeometryUniqueIdsMap) {\n this._geometriesByUniqueId = {};\n }\n this.useMaterialMeshMap = fullOptions.useMaterialMeshMap;\n this.useClonedMeshMap = fullOptions.useClonedMeshMap;\n if (!options || !options.virtual) {\n this._engine.onNewSceneAddedObservable.notifyObservers(this);\n }\n }\n /**\n * Gets a string identifying the name of the class\n * @returns \"Scene\" string\n */\n getClassName() {\n return \"Scene\";\n }\n /**\n * @internal\n */\n _getDefaultMeshCandidates() {\n this._defaultMeshCandidates.data = this.meshes;\n this._defaultMeshCandidates.length = this.meshes.length;\n return this._defaultMeshCandidates;\n }\n /**\n * @internal\n */\n _getDefaultSubMeshCandidates(mesh) {\n this._defaultSubMeshCandidates.data = mesh.subMeshes;\n this._defaultSubMeshCandidates.length = mesh.subMeshes.length;\n return this._defaultSubMeshCandidates;\n }\n /**\n * Sets the default candidate providers for the scene.\n * This sets the getActiveMeshCandidates, getActiveSubMeshCandidates, getIntersectingSubMeshCandidates\n * and getCollidingSubMeshCandidates to their default function\n */\n setDefaultCandidateProviders() {\n this.getActiveMeshCandidates = this._getDefaultMeshCandidates.bind(this);\n this.getActiveSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);\n this.getIntersectingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);\n this.getCollidingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);\n }\n /**\n * Gets the mesh that is currently under the pointer\n */\n get meshUnderPointer() {\n return this._inputManager.meshUnderPointer;\n }\n /**\n * Gets or sets the current on-screen X position of the pointer\n */\n get pointerX() {\n return this._inputManager.pointerX;\n }\n set pointerX(value) {\n this._inputManager.pointerX = value;\n }\n /**\n * Gets or sets the current on-screen Y position of the pointer\n */\n get pointerY() {\n return this._inputManager.pointerY;\n }\n set pointerY(value) {\n this._inputManager.pointerY = value;\n }\n /**\n * Gets the cached material (ie. the latest rendered one)\n * @returns the cached material\n */\n getCachedMaterial() {\n return this._cachedMaterial;\n }\n /**\n * Gets the cached effect (ie. the latest rendered one)\n * @returns the cached effect\n */\n getCachedEffect() {\n return this._cachedEffect;\n }\n /**\n * Gets the cached visibility state (ie. the latest rendered one)\n * @returns the cached visibility state\n */\n getCachedVisibility() {\n return this._cachedVisibility;\n }\n /**\n * Gets a boolean indicating if the current material / effect / visibility must be bind again\n * @param material defines the current material\n * @param effect defines the current effect\n * @param visibility defines the current visibility state\n * @returns true if one parameter is not cached\n */\n isCachedMaterialInvalid(material, effect, visibility = 1) {\n return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;\n }\n /**\n * Gets the engine associated with the scene\n * @returns an Engine\n */\n getEngine() {\n return this._engine;\n }\n /**\n * Gets the total number of vertices rendered per frame\n * @returns the total number of vertices rendered per frame\n */\n getTotalVertices() {\n return this._totalVertices.current;\n }\n /**\n * Gets the performance counter for total vertices\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\n */\n get totalVerticesPerfCounter() {\n return this._totalVertices;\n }\n /**\n * Gets the total number of active indices rendered per frame (You can deduce the number of rendered triangles by dividing this number by 3)\n * @returns the total number of active indices rendered per frame\n */\n getActiveIndices() {\n return this._activeIndices.current;\n }\n /**\n * Gets the performance counter for active indices\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\n */\n get totalActiveIndicesPerfCounter() {\n return this._activeIndices;\n }\n /**\n * Gets the total number of active particles rendered per frame\n * @returns the total number of active particles rendered per frame\n */\n getActiveParticles() {\n return this._activeParticles.current;\n }\n /**\n * Gets the performance counter for active particles\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\n */\n get activeParticlesPerfCounter() {\n return this._activeParticles;\n }\n /**\n * Gets the total number of active bones rendered per frame\n * @returns the total number of active bones rendered per frame\n */\n getActiveBones() {\n return this._activeBones.current;\n }\n /**\n * Gets the performance counter for active bones\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\n */\n get activeBonesPerfCounter() {\n return this._activeBones;\n }\n /**\n * Gets the array of active meshes\n * @returns an array of AbstractMesh\n */\n getActiveMeshes() {\n return this._activeMeshes;\n }\n /**\n * Gets the animation ratio (which is 1.0 is the scene renders at 60fps and 2 if the scene renders at 30fps, etc.)\n * @returns a number\n */\n getAnimationRatio() {\n return this._animationRatio !== undefined ? this._animationRatio : 1;\n }\n /**\n * Gets an unique Id for the current render phase\n * @returns a number\n */\n getRenderId() {\n return this._renderId;\n }\n /**\n * Gets an unique Id for the current frame\n * @returns a number\n */\n getFrameId() {\n return this._frameId;\n }\n /** Call this function if you want to manually increment the render Id*/\n incrementRenderId() {\n this._renderId++;\n }\n _createUbo() {\n this.setSceneUniformBuffer(this.createSceneUniformBuffer());\n }\n /**\n * Use this method to simulate a pointer move on a mesh\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\n * @param pickResult pickingInfo of the object wished to simulate pointer event on\n * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\n * @returns the current scene\n */\n simulatePointerMove(pickResult, pointerEventInit) {\n this._inputManager.simulatePointerMove(pickResult, pointerEventInit);\n return this;\n }\n /**\n * Use this method to simulate a pointer down on a mesh\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\n * @param pickResult pickingInfo of the object wished to simulate pointer event on\n * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\n * @returns the current scene\n */\n simulatePointerDown(pickResult, pointerEventInit) {\n this._inputManager.simulatePointerDown(pickResult, pointerEventInit);\n return this;\n }\n /**\n * Use this method to simulate a pointer up on a mesh\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\n * @param pickResult pickingInfo of the object wished to simulate pointer event on\n * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\n * @param doubleTap indicates that the pointer up event should be considered as part of a double click (false by default)\n * @returns the current scene\n */\n simulatePointerUp(pickResult, pointerEventInit, doubleTap) {\n this._inputManager.simulatePointerUp(pickResult, pointerEventInit, doubleTap);\n return this;\n }\n /**\n * Gets a boolean indicating if the current pointer event is captured (meaning that the scene has already handled the pointer down)\n * @param pointerId defines the pointer id to use in a multi-touch scenario (0 by default)\n * @returns true if the pointer was captured\n */\n isPointerCaptured(pointerId = 0) {\n return this._inputManager.isPointerCaptured(pointerId);\n }\n /**\n * Attach events to the canvas (To handle actionManagers triggers and raise onPointerMove, onPointerDown and onPointerUp\n * @param attachUp defines if you want to attach events to pointerup\n * @param attachDown defines if you want to attach events to pointerdown\n * @param attachMove defines if you want to attach events to pointermove\n */\n attachControl(attachUp = true, attachDown = true, attachMove = true) {\n this._inputManager.attachControl(attachUp, attachDown, attachMove);\n }\n /** Detaches all event handlers*/\n detachControl() {\n this._inputManager.detachControl();\n }\n /**\n * This function will check if the scene can be rendered (textures are loaded, shaders are compiled)\n * Delay loaded resources are not taking in account\n * @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: true)\n * @returns true if all required resources are ready\n */\n isReady(checkRenderTargets = true) {\n var _a, _b, _c;\n if (this._isDisposed) {\n return false;\n }\n let index;\n const engine = this.getEngine();\n const currentRenderPassId = engine.currentRenderPassId;\n engine.currentRenderPassId = (_b = (_a = this.activeCamera) === null || _a === void 0 ? void 0 : _a.renderPassId) !== null && _b !== void 0 ? _b : currentRenderPassId;\n let isReady = true;\n // Pending data\n if (this._pendingData.length > 0) {\n isReady = false;\n }\n // Ensures that the pre-pass renderer is enabled if it is to be enabled.\n (_c = this.prePassRenderer) === null || _c === void 0 ? void 0 : _c.update();\n // Meshes\n if (checkRenderTargets) {\n this._processedMaterials.reset();\n this._materialsRenderTargets.reset();\n }\n for (index = 0; index < this.meshes.length; index++) {\n const mesh = this.meshes[index];\n if (!mesh.subMeshes || mesh.subMeshes.length === 0) {\n continue;\n }\n // Do not stop at the first encountered \"unready\" object as we want to ensure\n // all materials are starting off their compilation in parallel.\n if (!mesh.isReady(true)) {\n isReady = false;\n continue;\n }\n const hardwareInstancedRendering = mesh.hasThinInstances ||\n mesh.getClassName() === \"InstancedMesh\" ||\n mesh.getClassName() === \"InstancedLinesMesh\" ||\n (engine.getCaps().instancedArrays && mesh.instances.length > 0);\n // Is Ready For Mesh\n for (const step of this._isReadyForMeshStage) {\n if (!step.action(mesh, hardwareInstancedRendering)) {\n isReady = false;\n }\n }\n if (!checkRenderTargets) {\n continue;\n }\n const mat = mesh.material || this.defaultMaterial;\n if (mat) {\n if (mat._storeEffectOnSubMeshes) {\n for (const subMesh of mesh.subMeshes) {\n const material = subMesh.getMaterial();\n if (material && material.hasRenderTargetTextures && material.getRenderTargetTextures != null) {\n if (this._processedMaterials.indexOf(material) === -1) {\n this._processedMaterials.push(material);\n this._materialsRenderTargets.concatWithNoDuplicate(material.getRenderTargetTextures());\n }\n }\n }\n }\n else {\n if (mat.hasRenderTargetTextures && mat.getRenderTargetTextures != null) {\n if (this._processedMaterials.indexOf(mat) === -1) {\n this._processedMaterials.push(mat);\n this._materialsRenderTargets.concatWithNoDuplicate(mat.getRenderTargetTextures());\n }\n }\n }\n }\n }\n // Render targets\n if (checkRenderTargets) {\n for (index = 0; index < this._materialsRenderTargets.length; ++index) {\n const rtt = this._materialsRenderTargets.data[index];\n if (!rtt.isReadyForRendering()) {\n isReady = false;\n }\n }\n }\n // Geometries\n for (index = 0; index < this.geometries.length; index++) {\n const geometry = this.geometries[index];\n if (geometry.delayLoadState === 2) {\n isReady = false;\n }\n }\n // Post-processes\n if (this.activeCameras && this.activeCameras.length > 0) {\n for (const camera of this.activeCameras) {\n if (!camera.isReady(true)) {\n isReady = false;\n }\n }\n }\n else if (this.activeCamera) {\n if (!this.activeCamera.isReady(true)) {\n isReady = false;\n }\n }\n // Particles\n for (const particleSystem of this.particleSystems) {\n if (!particleSystem.isReady()) {\n isReady = false;\n }\n }\n // Layers\n if (this.layers) {\n for (const layer of this.layers) {\n if (!layer.isReady()) {\n isReady = false;\n }\n }\n }\n // Effects\n if (!engine.areAllEffectsReady()) {\n isReady = false;\n }\n engine.currentRenderPassId = currentRenderPassId;\n return isReady;\n }\n /** Resets all cached information relative to material (including effect and visibility) */\n resetCachedMaterial() {\n this._cachedMaterial = null;\n this._cachedEffect = null;\n this._cachedVisibility = null;\n }\n /**\n * Registers a function to be called before every frame render\n * @param func defines the function to register\n */\n registerBeforeRender(func) {\n this.onBeforeRenderObservable.add(func);\n }\n /**\n * Unregisters a function called before every frame render\n * @param func defines the function to unregister\n */\n unregisterBeforeRender(func) {\n this.onBeforeRenderObservable.removeCallback(func);\n }\n /**\n * Registers a function to be called after every frame render\n * @param func defines the function to register\n */\n registerAfterRender(func) {\n this.onAfterRenderObservable.add(func);\n }\n /**\n * Unregisters a function called after every frame render\n * @param func defines the function to unregister\n */\n unregisterAfterRender(func) {\n this.onAfterRenderObservable.removeCallback(func);\n }\n _executeOnceBeforeRender(func) {\n const execFunc = () => {\n func();\n setTimeout(() => {\n this.unregisterBeforeRender(execFunc);\n });\n };\n this.registerBeforeRender(execFunc);\n }\n /**\n * The provided function will run before render once and will be disposed afterwards.\n * A timeout delay can be provided so that the function will be executed in N ms.\n * The timeout is using the browser's native setTimeout so time percision cannot be guaranteed.\n * @param func The function to be executed.\n * @param timeout optional delay in ms\n */\n executeOnceBeforeRender(func, timeout) {\n if (timeout !== undefined) {\n setTimeout(() => {\n this._executeOnceBeforeRender(func);\n }, timeout);\n }\n else {\n this._executeOnceBeforeRender(func);\n }\n }\n /**\n * This function can help adding any object to the list of data awaited to be ready in order to check for a complete scene loading.\n * @param data defines the object to wait for\n */\n addPendingData(data) {\n this._pendingData.push(data);\n }\n /**\n * Remove a pending data from the loading list which has previously been added with addPendingData.\n * @param data defines the object to remove from the pending list\n */\n removePendingData(data) {\n const wasLoading = this.isLoading;\n const index = this._pendingData.indexOf(data);\n if (index !== -1) {\n this._pendingData.splice(index, 1);\n }\n if (wasLoading && !this.isLoading) {\n this.onDataLoadedObservable.notifyObservers(this);\n }\n }\n /**\n * Returns the number of items waiting to be loaded\n * @returns the number of items waiting to be loaded\n */\n getWaitingItemsCount() {\n return this._pendingData.length;\n }\n /**\n * Returns a boolean indicating if the scene is still loading data\n */\n get isLoading() {\n return this._pendingData.length > 0;\n }\n /**\n * Registers a function to be executed when the scene is ready\n * @param func - the function to be executed\n * @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: false)\n */\n executeWhenReady(func, checkRenderTargets = false) {\n this.onReadyObservable.addOnce(func);\n if (this._executeWhenReadyTimeoutId !== null) {\n return;\n }\n this._checkIsReady(checkRenderTargets);\n }\n /**\n * Returns a promise that resolves when the scene is ready\n * @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: false)\n * @returns A promise that resolves when the scene is ready\n */\n whenReadyAsync(checkRenderTargets = false) {\n return new Promise((resolve) => {\n this.executeWhenReady(() => {\n resolve();\n }, checkRenderTargets);\n });\n }\n /**\n * @internal\n */\n _checkIsReady(checkRenderTargets = false) {\n this._registerTransientComponents();\n if (this.isReady(checkRenderTargets)) {\n this.onReadyObservable.notifyObservers(this);\n this.onReadyObservable.clear();\n this._executeWhenReadyTimeoutId = null;\n return;\n }\n if (this._isDisposed) {\n this.onReadyObservable.clear();\n this._executeWhenReadyTimeoutId = null;\n return;\n }\n this._executeWhenReadyTimeoutId = setTimeout(() => {\n // Ensure materials effects are checked outside render loops\n this.incrementRenderId();\n this._checkIsReady(checkRenderTargets);\n }, 100);\n }\n /**\n * Gets all animatable attached to the scene\n */\n get animatables() {\n return this._activeAnimatables;\n }\n /**\n * Resets the last animation time frame.\n * Useful to override when animations start running when loading a scene for the first time.\n */\n resetLastAnimationTimeFrame() {\n this._animationTimeLast = PrecisionDate.Now;\n }\n // Matrix\n /**\n * Gets the current view matrix\n * @returns a Matrix\n */\n getViewMatrix() {\n return this._viewMatrix;\n }\n /**\n * Gets the current projection matrix\n * @returns a Matrix\n */\n getProjectionMatrix() {\n return this._projectionMatrix;\n }\n /**\n * Gets the current transform matrix\n * @returns a Matrix made of View * Projection\n */\n getTransformMatrix() {\n return this._transformMatrix;\n }\n /**\n * Sets the current transform matrix\n * @param viewL defines the View matrix to use\n * @param projectionL defines the Projection matrix to use\n * @param viewR defines the right View matrix to use (if provided)\n * @param projectionR defines the right Projection matrix to use (if provided)\n */\n setTransformMatrix(viewL, projectionL, viewR, projectionR) {\n // clear the multiviewSceneUbo if no viewR and projectionR are defined\n if (!viewR && !projectionR && this._multiviewSceneUbo) {\n this._multiviewSceneUbo.dispose();\n this._multiviewSceneUbo = null;\n }\n if (this._viewUpdateFlag === viewL.updateFlag && this._projectionUpdateFlag === projectionL.updateFlag) {\n return;\n }\n this._viewUpdateFlag = viewL.updateFlag;\n this._projectionUpdateFlag = projectionL.updateFlag;\n this._viewMatrix = viewL;\n this._projectionMatrix = projectionL;\n this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);\n // Update frustum\n if (!this._frustumPlanes) {\n this._frustumPlanes = Frustum.GetPlanes(this._transformMatrix);\n }\n else {\n Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);\n }\n if (this._multiviewSceneUbo && this._multiviewSceneUbo.useUbo) {\n this._updateMultiviewUbo(viewR, projectionR);\n }\n else if (this._sceneUbo.useUbo) {\n this._sceneUbo.updateMatrix(\"viewProjection\", this._transformMatrix);\n this._sceneUbo.updateMatrix(\"view\", this._viewMatrix);\n this._sceneUbo.updateMatrix(\"projection\", this._projectionMatrix);\n }\n }\n /**\n * Gets the uniform buffer used to store scene data\n * @returns a UniformBuffer\n */\n getSceneUniformBuffer() {\n return this._multiviewSceneUbo ? this._multiviewSceneUbo : this._sceneUbo;\n }\n /**\n * Creates a scene UBO\n * @param name name of the uniform buffer (optional, for debugging purpose only)\n * @returns a new ubo\n */\n createSceneUniformBuffer(name) {\n const sceneUbo = new UniformBuffer(this._engine, undefined, false, name !== null && name !== void 0 ? name : \"scene\");\n sceneUbo.addUniform(\"viewProjection\", 16);\n sceneUbo.addUniform(\"view\", 16);\n sceneUbo.addUniform(\"projection\", 16);\n sceneUbo.addUniform(\"vEyePosition\", 4);\n return sceneUbo;\n }\n /**\n * Sets the scene ubo\n * @param ubo the ubo to set for the scene\n */\n setSceneUniformBuffer(ubo) {\n this._sceneUbo = ubo;\n this._viewUpdateFlag = -1;\n this._projectionUpdateFlag = -1;\n }\n /**\n * Gets an unique (relatively to the current scene) Id\n * @returns an unique number for the scene\n */\n getUniqueId() {\n return UniqueIdGenerator.UniqueId;\n }\n /**\n * Add a mesh to the list of scene's meshes\n * @param newMesh defines the mesh to add\n * @param recursive if all child meshes should also be added to the scene\n */\n addMesh(newMesh, recursive = false) {\n if (this._blockEntityCollection) {\n return;\n }\n this.meshes.push(newMesh);\n newMesh._resyncLightSources();\n if (!newMesh.parent) {\n newMesh._addToSceneRootNodes();\n }\n this.onNewMeshAddedObservable.notifyObservers(newMesh);\n if (recursive) {\n newMesh.getChildMeshes().forEach((m) => {\n this.addMesh(m);\n });\n }\n }\n /**\n * Remove a mesh for the list of scene's meshes\n * @param toRemove defines the mesh to remove\n * @param recursive if all child meshes should also be removed from the scene\n * @returns the index where the mesh was in the mesh list\n */\n removeMesh(toRemove, recursive = false) {\n const index = this.meshes.indexOf(toRemove);\n if (index !== -1) {\n // Remove from the scene if mesh found\n this.meshes[index] = this.meshes[this.meshes.length - 1];\n this.meshes.pop();\n if (!toRemove.parent) {\n toRemove._removeFromSceneRootNodes();\n }\n }\n this._inputManager._invalidateMesh(toRemove);\n this.onMeshRemovedObservable.notifyObservers(toRemove);\n if (recursive) {\n toRemove.getChildMeshes().forEach((m) => {\n this.removeMesh(m);\n });\n }\n return index;\n }\n /**\n * Add a transform node to the list of scene's transform nodes\n * @param newTransformNode defines the transform node to add\n */\n addTransformNode(newTransformNode) {\n if (this._blockEntityCollection) {\n return;\n }\n if (newTransformNode.getScene() === this && newTransformNode._indexInSceneTransformNodesArray !== -1) {\n // Already there?\n return;\n }\n newTransformNode._indexInSceneTransformNodesArray = this.transformNodes.length;\n this.transformNodes.push(newTransformNode);\n if (!newTransformNode.parent) {\n newTransformNode._addToSceneRootNodes();\n }\n this.onNewTransformNodeAddedObservable.notifyObservers(newTransformNode);\n }\n /**\n * Remove a transform node for the list of scene's transform nodes\n * @param toRemove defines the transform node to remove\n * @returns the index where the transform node was in the transform node list\n */\n removeTransformNode(toRemove) {\n const index = toRemove._indexInSceneTransformNodesArray;\n if (index !== -1) {\n if (index !== this.transformNodes.length - 1) {\n const lastNode = this.transformNodes[this.transformNodes.length - 1];\n this.transformNodes[index] = lastNode;\n lastNode._indexInSceneTransformNodesArray = index;\n }\n toRemove._indexInSceneTransformNodesArray = -1;\n this.transformNodes.pop();\n if (!toRemove.parent) {\n toRemove._removeFromSceneRootNodes();\n }\n }\n this.onTransformNodeRemovedObservable.notifyObservers(toRemove);\n return index;\n }\n /**\n * Remove a skeleton for the list of scene's skeletons\n * @param toRemove defines the skeleton to remove\n * @returns the index where the skeleton was in the skeleton list\n */\n removeSkeleton(toRemove) {\n const index = this.skeletons.indexOf(toRemove);\n if (index !== -1) {\n // Remove from the scene if found\n this.skeletons.splice(index, 1);\n this.onSkeletonRemovedObservable.notifyObservers(toRemove);\n // Clean active container\n this._executeActiveContainerCleanup(this._activeSkeletons);\n }\n return index;\n }\n /**\n * Remove a morph target for the list of scene's morph targets\n * @param toRemove defines the morph target to remove\n * @returns the index where the morph target was in the morph target list\n */\n removeMorphTargetManager(toRemove) {\n const index = this.morphTargetManagers.indexOf(toRemove);\n if (index !== -1) {\n // Remove from the scene if found\n this.morphTargetManagers.splice(index, 1);\n }\n return index;\n }\n /**\n * Remove a light for the list of scene's lights\n * @param toRemove defines the light to remove\n * @returns the index where the light was in the light list\n */\n removeLight(toRemove) {\n const index = this.lights.indexOf(toRemove);\n if (index !== -1) {\n // Remove from meshes\n for (const mesh of this.meshes) {\n mesh._removeLightSource(toRemove, false);\n }\n // Remove from the scene if mesh found\n this.lights.splice(index, 1);\n this.sortLightsByPriority();\n if (!toRemove.parent) {\n toRemove._removeFromSceneRootNodes();\n }\n }\n this.onLightRemovedObservable.notifyObservers(toRemove);\n return index;\n }\n /**\n * Remove a camera for the list of scene's cameras\n * @param toRemove defines the camera to remove\n * @returns the index where the camera was in the camera list\n */\n removeCamera(toRemove) {\n const index = this.cameras.indexOf(toRemove);\n if (index !== -1) {\n // Remove from the scene if mesh found\n this.cameras.splice(index, 1);\n if (!toRemove.parent) {\n toRemove._removeFromSceneRootNodes();\n }\n }\n // Remove from activeCameras\n if (this.activeCameras) {\n const index2 = this.activeCameras.indexOf(toRemove);\n if (index2 !== -1) {\n // Remove from the scene if mesh found\n this.activeCameras.splice(index2, 1);\n }\n }\n // Reset the activeCamera\n if (this.activeCamera === toRemove) {\n if (this.cameras.length > 0) {\n this.activeCamera = this.cameras[0];\n }\n else {\n this.activeCamera = null;\n }\n }\n this.onCameraRemovedObservable.notifyObservers(toRemove);\n return index;\n }\n /**\n * Remove a particle system for the list of scene's particle systems\n * @param toRemove defines the particle system to remove\n * @returns the index where the particle system was in the particle system list\n */\n removeParticleSystem(toRemove) {\n const index = this.particleSystems.indexOf(toRemove);\n if (index !== -1) {\n this.particleSystems.splice(index, 1);\n // Clean active container\n this._executeActiveContainerCleanup(this._activeParticleSystems);\n }\n return index;\n }\n /**\n * Remove a animation for the list of scene's animations\n * @param toRemove defines the animation to remove\n * @returns the index where the animation was in the animation list\n */\n removeAnimation(toRemove) {\n const index = this.animations.indexOf(toRemove);\n if (index !== -1) {\n this.animations.splice(index, 1);\n }\n return index;\n }\n /**\n * Will stop the animation of the given target\n * @param target - the target\n * @param animationName - the name of the animation to stop (all animations will be stopped if both this and targetMask are empty)\n * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)\n */\n stopAnimation(target, animationName, targetMask) {\n // Do nothing as code will be provided by animation component\n }\n /**\n * Removes the given animation group from this scene.\n * @param toRemove The animation group to remove\n * @returns The index of the removed animation group\n */\n removeAnimationGroup(toRemove) {\n const index = this.animationGroups.indexOf(toRemove);\n if (index !== -1) {\n this.animationGroups.splice(index, 1);\n }\n return index;\n }\n /**\n * Removes the given multi-material from this scene.\n * @param toRemove The multi-material to remove\n * @returns The index of the removed multi-material\n */\n removeMultiMaterial(toRemove) {\n const index = this.multiMaterials.indexOf(toRemove);\n if (index !== -1) {\n this.multiMaterials.splice(index, 1);\n }\n this.onMultiMaterialRemovedObservable.notifyObservers(toRemove);\n return index;\n }\n /**\n * Removes the given material from this scene.\n * @param toRemove The material to remove\n * @returns The index of the removed material\n */\n removeMaterial(toRemove) {\n const index = toRemove._indexInSceneMaterialArray;\n if (index !== -1 && index < this.materials.length) {\n if (index !== this.materials.length - 1) {\n const lastMaterial = this.materials[this.materials.length - 1];\n this.materials[index] = lastMaterial;\n lastMaterial._indexInSceneMaterialArray = index;\n }\n toRemove._indexInSceneMaterialArray = -1;\n this.materials.pop();\n }\n this.onMaterialRemovedObservable.notifyObservers(toRemove);\n return index;\n }\n /**\n * Removes the given action manager from this scene.\n * @deprecated\n * @param toRemove The action manager to remove\n * @returns The index of the removed action manager\n */\n removeActionManager(toRemove) {\n const index = this.actionManagers.indexOf(toRemove);\n if (index !== -1) {\n this.actionManagers.splice(index, 1);\n }\n return index;\n }\n /**\n * Removes the given texture from this scene.\n * @param toRemove The texture to remove\n * @returns The index of the removed texture\n */\n removeTexture(toRemove) {\n const index = this.textures.indexOf(toRemove);\n if (index !== -1) {\n this.textures.splice(index, 1);\n }\n this.onTextureRemovedObservable.notifyObservers(toRemove);\n return index;\n }\n /**\n * Adds the given light to this scene\n * @param newLight The light to add\n */\n addLight(newLight) {\n if (this._blockEntityCollection) {\n return;\n }\n this.lights.push(newLight);\n this.sortLightsByPriority();\n if (!newLight.parent) {\n newLight._addToSceneRootNodes();\n }\n // Add light to all meshes (To support if the light is removed and then re-added)\n for (const mesh of this.meshes) {\n if (mesh.lightSources.indexOf(newLight) === -1) {\n mesh.lightSources.push(newLight);\n mesh._resyncLightSources();\n }\n }\n this.onNewLightAddedObservable.notifyObservers(newLight);\n }\n /**\n * Sorts the list list based on light priorities\n */\n sortLightsByPriority() {\n if (this.requireLightSorting) {\n this.lights.sort(LightConstants.CompareLightsPriority);\n }\n }\n /**\n * Adds the given camera to this scene\n * @param newCamera The camera to add\n */\n addCamera(newCamera) {\n if (this._blockEntityCollection) {\n return;\n }\n this.cameras.push(newCamera);\n this.onNewCameraAddedObservable.notifyObservers(newCamera);\n if (!newCamera.parent) {\n newCamera._addToSceneRootNodes();\n }\n }\n /**\n * Adds the given skeleton to this scene\n * @param newSkeleton The skeleton to add\n */\n addSkeleton(newSkeleton) {\n if (this._blockEntityCollection) {\n return;\n }\n this.skeletons.push(newSkeleton);\n this.onNewSkeletonAddedObservable.notifyObservers(newSkeleton);\n }\n /**\n * Adds the given particle system to this scene\n * @param newParticleSystem The particle system to add\n */\n addParticleSystem(newParticleSystem) {\n if (this._blockEntityCollection) {\n return;\n }\n this.particleSystems.push(newParticleSystem);\n }\n /**\n * Adds the given animation to this scene\n * @param newAnimation The animation to add\n */\n addAnimation(newAnimation) {\n if (this._blockEntityCollection) {\n return;\n }\n this.animations.push(newAnimation);\n }\n /**\n * Adds the given animation group to this scene.\n * @param newAnimationGroup The animation group to add\n */\n addAnimationGroup(newAnimationGroup) {\n if (this._blockEntityCollection) {\n return;\n }\n this.animationGroups.push(newAnimationGroup);\n }\n /**\n * Adds the given multi-material to this scene\n * @param newMultiMaterial The multi-material to add\n */\n addMultiMaterial(newMultiMaterial) {\n if (this._blockEntityCollection) {\n return;\n }\n this.multiMaterials.push(newMultiMaterial);\n this.onNewMultiMaterialAddedObservable.notifyObservers(newMultiMaterial);\n }\n /**\n * Adds the given material to this scene\n * @param newMaterial The material to add\n */\n addMaterial(newMaterial) {\n if (this._blockEntityCollection) {\n return;\n }\n if (newMaterial.getScene() === this && newMaterial._indexInSceneMaterialArray !== -1) {\n // Already there??\n return;\n }\n newMaterial._indexInSceneMaterialArray = this.materials.length;\n this.materials.push(newMaterial);\n this.onNewMaterialAddedObservable.notifyObservers(newMaterial);\n }\n /**\n * Adds the given morph target to this scene\n * @param newMorphTargetManager The morph target to add\n */\n addMorphTargetManager(newMorphTargetManager) {\n if (this._blockEntityCollection) {\n return;\n }\n this.morphTargetManagers.push(newMorphTargetManager);\n }\n /**\n * Adds the given geometry to this scene\n * @param newGeometry The geometry to add\n */\n addGeometry(newGeometry) {\n if (this._blockEntityCollection) {\n return;\n }\n if (this._geometriesByUniqueId) {\n this._geometriesByUniqueId[newGeometry.uniqueId] = this.geometries.length;\n }\n this.geometries.push(newGeometry);\n }\n /**\n * Adds the given action manager to this scene\n * @deprecated\n * @param newActionManager The action manager to add\n */\n addActionManager(newActionManager) {\n this.actionManagers.push(newActionManager);\n }\n /**\n * Adds the given texture to this scene.\n * @param newTexture The texture to add\n */\n addTexture(newTexture) {\n if (this._blockEntityCollection) {\n return;\n }\n this.textures.push(newTexture);\n this.onNewTextureAddedObservable.notifyObservers(newTexture);\n }\n /**\n * Switch active camera\n * @param newCamera defines the new active camera\n * @param attachControl defines if attachControl must be called for the new active camera (default: true)\n */\n switchActiveCamera(newCamera, attachControl = true) {\n const canvas = this._engine.getInputElement();\n if (!canvas) {\n return;\n }\n if (this.activeCamera) {\n this.activeCamera.detachControl();\n }\n this.activeCamera = newCamera;\n if (attachControl) {\n newCamera.attachControl();\n }\n }\n /**\n * sets the active camera of the scene using its Id\n * @param id defines the camera's Id\n * @returns the new active camera or null if none found.\n */\n setActiveCameraById(id) {\n const camera = this.getCameraById(id);\n if (camera) {\n this.activeCamera = camera;\n return camera;\n }\n return null;\n }\n /**\n * sets the active camera of the scene using its name\n * @param name defines the camera's name\n * @returns the new active camera or null if none found.\n */\n setActiveCameraByName(name) {\n const camera = this.getCameraByName(name);\n if (camera) {\n this.activeCamera = camera;\n return camera;\n }\n return null;\n }\n /**\n * get an animation group using its name\n * @param name defines the material's name\n * @returns the animation group or null if none found.\n */\n getAnimationGroupByName(name) {\n for (let index = 0; index < this.animationGroups.length; index++) {\n if (this.animationGroups[index].name === name) {\n return this.animationGroups[index];\n }\n }\n return null;\n }\n _getMaterial(allowMultiMaterials, predicate) {\n for (let index = 0; index < this.materials.length; index++) {\n const material = this.materials[index];\n if (predicate(material)) {\n return material;\n }\n }\n if (allowMultiMaterials) {\n for (let index = 0; index < this.multiMaterials.length; index++) {\n const material = this.multiMaterials[index];\n if (predicate(material)) {\n return material;\n }\n }\n }\n return null;\n }\n /**\n * Get a material using its unique id\n * @param uniqueId defines the material's unique id\n * @param allowMultiMaterials determines whether multimaterials should be considered\n * @returns the material or null if none found.\n */\n getMaterialByUniqueID(uniqueId, allowMultiMaterials = false) {\n return this._getMaterial(allowMultiMaterials, (m) => m.uniqueId === uniqueId);\n }\n /**\n * get a material using its id\n * @param id defines the material's Id\n * @param allowMultiMaterials determines whether multimaterials should be considered\n * @returns the material or null if none found.\n */\n getMaterialById(id, allowMultiMaterials = false) {\n return this._getMaterial(allowMultiMaterials, (m) => m.id === id);\n }\n /**\n * Gets a material using its name\n * @param name defines the material's name\n * @param allowMultiMaterials determines whether multimaterials should be considered\n * @returns the material or null if none found.\n */\n getMaterialByName(name, allowMultiMaterials = false) {\n return this._getMaterial(allowMultiMaterials, (m) => m.name === name);\n }\n /**\n * Gets a last added material using a given id\n * @param id defines the material's id\n * @param allowMultiMaterials determines whether multimaterials should be considered\n * @returns the last material with the given id or null if none found.\n */\n getLastMaterialById(id, allowMultiMaterials = false) {\n for (let index = this.materials.length - 1; index >= 0; index--) {\n if (this.materials[index].id === id) {\n return this.materials[index];\n }\n }\n if (allowMultiMaterials) {\n for (let index = this.multiMaterials.length - 1; index >= 0; index--) {\n if (this.multiMaterials[index].id === id) {\n return this.multiMaterials[index];\n }\n }\n }\n return null;\n }\n /**\n * Get a texture using its unique id\n * @param uniqueId defines the texture's unique id\n * @returns the texture or null if none found.\n */\n getTextureByUniqueId(uniqueId) {\n for (let index = 0; index < this.textures.length; index++) {\n if (this.textures[index].uniqueId === uniqueId) {\n return this.textures[index];\n }\n }\n return null;\n }\n /**\n * Gets a texture using its name\n * @param name defines the texture's name\n * @returns the texture or null if none found.\n */\n getTextureByName(name) {\n for (let index = 0; index < this.textures.length; index++) {\n if (this.textures[index].name === name) {\n return this.textures[index];\n }\n }\n return null;\n }\n /**\n * Gets a camera using its Id\n * @param id defines the Id to look for\n * @returns the camera or null if not found\n */\n getCameraById(id) {\n for (let index = 0; index < this.cameras.length; index++) {\n if (this.cameras[index].id === id) {\n return this.cameras[index];\n }\n }\n return null;\n }\n /**\n * Gets a camera using its unique Id\n * @param uniqueId defines the unique Id to look for\n * @returns the camera or null if not found\n */\n getCameraByUniqueId(uniqueId) {\n for (let index = 0; index < this.cameras.length; index++) {\n if (this.cameras[index].uniqueId === uniqueId) {\n return this.cameras[index];\n }\n }\n return null;\n }\n /**\n * Gets a camera using its name\n * @param name defines the camera's name\n * @returns the camera or null if none found.\n */\n getCameraByName(name) {\n for (let index = 0; index < this.cameras.length; index++) {\n if (this.cameras[index].name === name) {\n return this.cameras[index];\n }\n }\n return null;\n }\n /**\n * Gets a bone using its Id\n * @param id defines the bone's Id\n * @returns the bone or null if not found\n */\n getBoneById(id) {\n for (let skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {\n const skeleton = this.skeletons[skeletonIndex];\n for (let boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {\n if (skeleton.bones[boneIndex].id === id) {\n return skeleton.bones[boneIndex];\n }\n }\n }\n return null;\n }\n /**\n * Gets a bone using its id\n * @param name defines the bone's name\n * @returns the bone or null if not found\n */\n getBoneByName(name) {\n for (let skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {\n const skeleton = this.skeletons[skeletonIndex];\n for (let boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {\n if (skeleton.bones[boneIndex].name === name) {\n return skeleton.bones[boneIndex];\n }\n }\n }\n return null;\n }\n /**\n * Gets a light node using its name\n * @param name defines the the light's name\n * @returns the light or null if none found.\n */\n getLightByName(name) {\n for (let index = 0; index < this.lights.length; index++) {\n if (this.lights[index].name === name) {\n return this.lights[index];\n }\n }\n return null;\n }\n /**\n * Gets a light node using its Id\n * @param id defines the light's Id\n * @returns the light or null if none found.\n */\n getLightById(id) {\n for (let index = 0; index < this.lights.length; index++) {\n if (this.lights[index].id === id) {\n return this.lights[index];\n }\n }\n return null;\n }\n /**\n * Gets a light node using its scene-generated unique Id\n * @param uniqueId defines the light's unique Id\n * @returns the light or null if none found.\n */\n getLightByUniqueId(uniqueId) {\n for (let index = 0; index < this.lights.length; index++) {\n if (this.lights[index].uniqueId === uniqueId) {\n return this.lights[index];\n }\n }\n return null;\n }\n /**\n * Gets a particle system by Id\n * @param id defines the particle system Id\n * @returns the corresponding system or null if none found\n */\n getParticleSystemById(id) {\n for (let index = 0; index < this.particleSystems.length; index++) {\n if (this.particleSystems[index].id === id) {\n return this.particleSystems[index];\n }\n }\n return null;\n }\n /**\n * Gets a geometry using its Id\n * @param id defines the geometry's Id\n * @returns the geometry or null if none found.\n */\n getGeometryById(id) {\n for (let index = 0; index < this.geometries.length; index++) {\n if (this.geometries[index].id === id) {\n return this.geometries[index];\n }\n }\n return null;\n }\n _getGeometryByUniqueId(uniqueId) {\n if (this._geometriesByUniqueId) {\n const index = this._geometriesByUniqueId[uniqueId];\n if (index !== undefined) {\n return this.geometries[index];\n }\n }\n else {\n for (let index = 0; index < this.geometries.length; index++) {\n if (this.geometries[index].uniqueId === uniqueId) {\n return this.geometries[index];\n }\n }\n }\n return null;\n }\n /**\n * Add a new geometry to this scene\n * @param geometry defines the geometry to be added to the scene.\n * @param force defines if the geometry must be pushed even if a geometry with this id already exists\n * @returns a boolean defining if the geometry was added or not\n */\n pushGeometry(geometry, force) {\n if (!force && this._getGeometryByUniqueId(geometry.uniqueId)) {\n return false;\n }\n this.addGeometry(geometry);\n this.onNewGeometryAddedObservable.notifyObservers(geometry);\n return true;\n }\n /**\n * Removes an existing geometry\n * @param geometry defines the geometry to be removed from the scene\n * @returns a boolean defining if the geometry was removed or not\n */\n removeGeometry(geometry) {\n let index;\n if (this._geometriesByUniqueId) {\n index = this._geometriesByUniqueId[geometry.uniqueId];\n if (index === undefined) {\n return false;\n }\n }\n else {\n index = this.geometries.indexOf(geometry);\n if (index < 0) {\n return false;\n }\n }\n if (index !== this.geometries.length - 1) {\n const lastGeometry = this.geometries[this.geometries.length - 1];\n if (lastGeometry) {\n this.geometries[index] = lastGeometry;\n if (this._geometriesByUniqueId) {\n this._geometriesByUniqueId[lastGeometry.uniqueId] = index;\n }\n }\n }\n if (this._geometriesByUniqueId) {\n this._geometriesByUniqueId[geometry.uniqueId] = undefined;\n }\n this.geometries.pop();\n this.onGeometryRemovedObservable.notifyObservers(geometry);\n return true;\n }\n /**\n * Gets the list of geometries attached to the scene\n * @returns an array of Geometry\n */\n getGeometries() {\n return this.geometries;\n }\n /**\n * Gets the first added mesh found of a given Id\n * @param id defines the Id to search for\n * @returns the mesh found or null if not found at all\n */\n getMeshById(id) {\n for (let index = 0; index < this.meshes.length; index++) {\n if (this.meshes[index].id === id) {\n return this.meshes[index];\n }\n }\n return null;\n }\n /**\n * Gets a list of meshes using their Id\n * @param id defines the Id to search for\n * @returns a list of meshes\n */\n getMeshesById(id) {\n return this.meshes.filter(function (m) {\n return m.id === id;\n });\n }\n /**\n * Gets the first added transform node found of a given Id\n * @param id defines the Id to search for\n * @returns the found transform node or null if not found at all.\n */\n getTransformNodeById(id) {\n for (let index = 0; index < this.transformNodes.length; index++) {\n if (this.transformNodes[index].id === id) {\n return this.transformNodes[index];\n }\n }\n return null;\n }\n /**\n * Gets a transform node with its auto-generated unique Id\n * @param uniqueId defines the unique Id to search for\n * @returns the found transform node or null if not found at all.\n */\n getTransformNodeByUniqueId(uniqueId) {\n for (let index = 0; index < this.transformNodes.length; index++) {\n if (this.transformNodes[index].uniqueId === uniqueId) {\n return this.transformNodes[index];\n }\n }\n return null;\n }\n /**\n * Gets a list of transform nodes using their Id\n * @param id defines the Id to search for\n * @returns a list of transform nodes\n */\n getTransformNodesById(id) {\n return this.transformNodes.filter(function (m) {\n return m.id === id;\n });\n }\n /**\n * Gets a mesh with its auto-generated unique Id\n * @param uniqueId defines the unique Id to search for\n * @returns the found mesh or null if not found at all.\n */\n getMeshByUniqueId(uniqueId) {\n for (let index = 0; index < this.meshes.length; index++) {\n if (this.meshes[index].uniqueId === uniqueId) {\n return this.meshes[index];\n }\n }\n return null;\n }\n /**\n * Gets a the last added mesh using a given Id\n * @param id defines the Id to search for\n * @returns the found mesh or null if not found at all.\n */\n getLastMeshById(id) {\n for (let index = this.meshes.length - 1; index >= 0; index--) {\n if (this.meshes[index].id === id) {\n return this.meshes[index];\n }\n }\n return null;\n }\n /**\n * Gets a the last transform node using a given Id\n * @param id defines the Id to search for\n * @returns the found mesh or null if not found at all.\n */\n getLastTransformNodeById(id) {\n for (let index = this.transformNodes.length - 1; index >= 0; index--) {\n if (this.transformNodes[index].id === id) {\n return this.transformNodes[index];\n }\n }\n return null;\n }\n /**\n * Gets a the last added node (Mesh, Camera, Light) using a given Id\n * @param id defines the Id to search for\n * @returns the found node or null if not found at all\n */\n getLastEntryById(id) {\n let index;\n for (index = this.meshes.length - 1; index >= 0; index--) {\n if (this.meshes[index].id === id) {\n return this.meshes[index];\n }\n }\n for (index = this.transformNodes.length - 1; index >= 0; index--) {\n if (this.transformNodes[index].id === id) {\n return this.transformNodes[index];\n }\n }\n for (index = this.cameras.length - 1; index >= 0; index--) {\n if (this.cameras[index].id === id) {\n return this.cameras[index];\n }\n }\n for (index = this.lights.length - 1; index >= 0; index--) {\n if (this.lights[index].id === id) {\n return this.lights[index];\n }\n }\n return null;\n }\n /**\n * Gets a node (Mesh, Camera, Light) using a given Id\n * @param id defines the Id to search for\n * @returns the found node or null if not found at all\n */\n getNodeById(id) {\n const mesh = this.getMeshById(id);\n if (mesh) {\n return mesh;\n }\n const transformNode = this.getTransformNodeById(id);\n if (transformNode) {\n return transformNode;\n }\n const light = this.getLightById(id);\n if (light) {\n return light;\n }\n const camera = this.getCameraById(id);\n if (camera) {\n return camera;\n }\n const bone = this.getBoneById(id);\n if (bone) {\n return bone;\n }\n return null;\n }\n /**\n * Gets a node (Mesh, Camera, Light) using a given name\n * @param name defines the name to search for\n * @returns the found node or null if not found at all.\n */\n getNodeByName(name) {\n const mesh = this.getMeshByName(name);\n if (mesh) {\n return mesh;\n }\n const transformNode = this.getTransformNodeByName(name);\n if (transformNode) {\n return transformNode;\n }\n const light = this.getLightByName(name);\n if (light) {\n return light;\n }\n const camera = this.getCameraByName(name);\n if (camera) {\n return camera;\n }\n const bone = this.getBoneByName(name);\n if (bone) {\n return bone;\n }\n return null;\n }\n /**\n * Gets a mesh using a given name\n * @param name defines the name to search for\n * @returns the found mesh or null if not found at all.\n */\n getMeshByName(name) {\n for (let index = 0; index < this.meshes.length; index++) {\n if (this.meshes[index].name === name) {\n return this.meshes[index];\n }\n }\n return null;\n }\n /**\n * Gets a transform node using a given name\n * @param name defines the name to search for\n * @returns the found transform node or null if not found at all.\n */\n getTransformNodeByName(name) {\n for (let index = 0; index < this.transformNodes.length; index++) {\n if (this.transformNodes[index].name === name) {\n return this.transformNodes[index];\n }\n }\n return null;\n }\n /**\n * Gets a skeleton using a given Id (if many are found, this function will pick the last one)\n * @param id defines the Id to search for\n * @returns the found skeleton or null if not found at all.\n */\n getLastSkeletonById(id) {\n for (let index = this.skeletons.length - 1; index >= 0; index--) {\n if (this.skeletons[index].id === id) {\n return this.skeletons[index];\n }\n }\n return null;\n }\n /**\n * Gets a skeleton using a given auto generated unique id\n * @param uniqueId defines the unique id to search for\n * @returns the found skeleton or null if not found at all.\n */\n getSkeletonByUniqueId(uniqueId) {\n for (let index = 0; index < this.skeletons.length; index++) {\n if (this.skeletons[index].uniqueId === uniqueId) {\n return this.skeletons[index];\n }\n }\n return null;\n }\n /**\n * Gets a skeleton using a given id (if many are found, this function will pick the first one)\n * @param id defines the id to search for\n * @returns the found skeleton or null if not found at all.\n */\n getSkeletonById(id) {\n for (let index = 0; index < this.skeletons.length; index++) {\n if (this.skeletons[index].id === id) {\n return this.skeletons[index];\n }\n }\n return null;\n }\n /**\n * Gets a skeleton using a given name\n * @param name defines the name to search for\n * @returns the found skeleton or null if not found at all.\n */\n getSkeletonByName(name) {\n for (let index = 0; index < this.skeletons.length; index++) {\n if (this.skeletons[index].name === name) {\n return this.skeletons[index];\n }\n }\n return null;\n }\n /**\n * Gets a morph target manager using a given id (if many are found, this function will pick the last one)\n * @param id defines the id to search for\n * @returns the found morph target manager or null if not found at all.\n */\n getMorphTargetManagerById(id) {\n for (let index = 0; index < this.morphTargetManagers.length; index++) {\n if (this.morphTargetManagers[index].uniqueId === id) {\n return this.morphTargetManagers[index];\n }\n }\n return null;\n }\n /**\n * Gets a morph target using a given id (if many are found, this function will pick the first one)\n * @param id defines the id to search for\n * @returns the found morph target or null if not found at all.\n */\n getMorphTargetById(id) {\n for (let managerIndex = 0; managerIndex < this.morphTargetManagers.length; ++managerIndex) {\n const morphTargetManager = this.morphTargetManagers[managerIndex];\n for (let index = 0; index < morphTargetManager.numTargets; ++index) {\n const target = morphTargetManager.getTarget(index);\n if (target.id === id) {\n return target;\n }\n }\n }\n return null;\n }\n /**\n * Gets a morph target using a given name (if many are found, this function will pick the first one)\n * @param name defines the name to search for\n * @returns the found morph target or null if not found at all.\n */\n getMorphTargetByName(name) {\n for (let managerIndex = 0; managerIndex < this.morphTargetManagers.length; ++managerIndex) {\n const morphTargetManager = this.morphTargetManagers[managerIndex];\n for (let index = 0; index < morphTargetManager.numTargets; ++index) {\n const target = morphTargetManager.getTarget(index);\n if (target.name === name) {\n return target;\n }\n }\n }\n return null;\n }\n /**\n * Gets a post process using a given name (if many are found, this function will pick the first one)\n * @param name defines the name to search for\n * @returns the found post process or null if not found at all.\n */\n getPostProcessByName(name) {\n for (let postProcessIndex = 0; postProcessIndex < this.postProcesses.length; ++postProcessIndex) {\n const postProcess = this.postProcesses[postProcessIndex];\n if (postProcess.name === name) {\n return postProcess;\n }\n }\n return null;\n }\n /**\n * Gets a boolean indicating if the given mesh is active\n * @param mesh defines the mesh to look for\n * @returns true if the mesh is in the active list\n */\n isActiveMesh(mesh) {\n return this._activeMeshes.indexOf(mesh) !== -1;\n }\n /**\n * Return a unique id as a string which can serve as an identifier for the scene\n */\n get uid() {\n if (!this._uid) {\n this._uid = Tools.RandomId();\n }\n return this._uid;\n }\n /**\n * Add an externally attached data from its key.\n * This method call will fail and return false, if such key already exists.\n * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.\n * @param key the unique key that identifies the data\n * @param data the data object to associate to the key for this Engine instance\n * @returns true if no such key were already present and the data was added successfully, false otherwise\n */\n addExternalData(key, data) {\n if (!this._externalData) {\n this._externalData = new StringDictionary();\n }\n return this._externalData.add(key, data);\n }\n /**\n * Get an externally attached data from its key\n * @param key the unique key that identifies the data\n * @returns the associated data, if present (can be null), or undefined if not present\n */\n getExternalData(key) {\n if (!this._externalData) {\n return null;\n }\n return this._externalData.get(key);\n }\n /**\n * Get an externally attached data from its key, create it using a factory if it's not already present\n * @param key the unique key that identifies the data\n * @param factory the factory that will be called to create the instance if and only if it doesn't exists\n * @returns the associated data, can be null if the factory returned null.\n */\n getOrAddExternalDataWithFactory(key, factory) {\n if (!this._externalData) {\n this._externalData = new StringDictionary();\n }\n return this._externalData.getOrAddWithFactory(key, factory);\n }\n /**\n * Remove an externally attached data from the Engine instance\n * @param key the unique key that identifies the data\n * @returns true if the data was successfully removed, false if it doesn't exist\n */\n removeExternalData(key) {\n return this._externalData.remove(key);\n }\n _evaluateSubMesh(subMesh, mesh, initialMesh, forcePush) {\n if (forcePush || subMesh.isInFrustum(this._frustumPlanes)) {\n for (const step of this._evaluateSubMeshStage) {\n step.action(mesh, subMesh);\n }\n const material = subMesh.getMaterial();\n if (material !== null && material !== undefined) {\n // Render targets\n if (material.hasRenderTargetTextures && material.getRenderTargetTextures != null) {\n if (this._processedMaterials.indexOf(material) === -1) {\n this._processedMaterials.push(material);\n this._materialsRenderTargets.concatWithNoDuplicate(material.getRenderTargetTextures());\n }\n }\n // Dispatch\n this._renderingManager.dispatch(subMesh, mesh, material);\n }\n }\n }\n /**\n * Clear the processed materials smart array preventing retention point in material dispose.\n */\n freeProcessedMaterials() {\n this._processedMaterials.dispose();\n }\n /** Gets or sets a boolean blocking all the calls to freeActiveMeshes and freeRenderingGroups\n * It can be used in order to prevent going through methods freeRenderingGroups and freeActiveMeshes several times to improve performance\n * when disposing several meshes in a row or a hierarchy of meshes.\n * When used, it is the responsibility of the user to blockfreeActiveMeshesAndRenderingGroups back to false.\n */\n get blockfreeActiveMeshesAndRenderingGroups() {\n return this._preventFreeActiveMeshesAndRenderingGroups;\n }\n set blockfreeActiveMeshesAndRenderingGroups(value) {\n if (this._preventFreeActiveMeshesAndRenderingGroups === value) {\n return;\n }\n if (value) {\n this.freeActiveMeshes();\n this.freeRenderingGroups();\n }\n this._preventFreeActiveMeshesAndRenderingGroups = value;\n }\n /**\n * Clear the active meshes smart array preventing retention point in mesh dispose.\n */\n freeActiveMeshes() {\n if (this.blockfreeActiveMeshesAndRenderingGroups) {\n return;\n }\n this._activeMeshes.dispose();\n if (this.activeCamera && this.activeCamera._activeMeshes) {\n this.activeCamera._activeMeshes.dispose();\n }\n if (this.activeCameras) {\n for (let i = 0; i < this.activeCameras.length; i++) {\n const activeCamera = this.activeCameras[i];\n if (activeCamera && activeCamera._activeMeshes) {\n activeCamera._activeMeshes.dispose();\n }\n }\n }\n }\n /**\n * Clear the info related to rendering groups preventing retention points during dispose.\n */\n freeRenderingGroups() {\n if (this.blockfreeActiveMeshesAndRenderingGroups) {\n return;\n }\n if (this._renderingManager) {\n this._renderingManager.freeRenderingGroups();\n }\n if (this.textures) {\n for (let i = 0; i < this.textures.length; i++) {\n const texture = this.textures[i];\n if (texture && texture.renderList) {\n texture.freeRenderingGroups();\n }\n }\n }\n }\n /** @internal */\n _isInIntermediateRendering() {\n return this._intermediateRendering;\n }\n /**\n * Use this function to stop evaluating active meshes. The current list will be keep alive between frames\n * @param skipEvaluateActiveMeshes defines an optional boolean indicating that the evaluate active meshes step must be completely skipped\n * @param onSuccess optional success callback\n * @param onError optional error callback\n * @param freezeMeshes defines if meshes should be frozen (true by default)\n * @param keepFrustumCulling defines if you want to keep running the frustum clipping (false by default)\n * @returns the current scene\n */\n freezeActiveMeshes(skipEvaluateActiveMeshes = false, onSuccess, onError, freezeMeshes = true, keepFrustumCulling = false) {\n this.executeWhenReady(() => {\n if (!this.activeCamera) {\n onError && onError(\"No active camera found\");\n return;\n }\n if (!this._frustumPlanes) {\n this.updateTransformMatrix();\n }\n this._evaluateActiveMeshes();\n this._activeMeshesFrozen = true;\n this._activeMeshesFrozenButKeepClipping = keepFrustumCulling;\n this._skipEvaluateActiveMeshesCompletely = skipEvaluateActiveMeshes;\n if (freezeMeshes) {\n for (let index = 0; index < this._activeMeshes.length; index++) {\n this._activeMeshes.data[index]._freeze();\n }\n }\n onSuccess && onSuccess();\n });\n return this;\n }\n /**\n * Use this function to restart evaluating active meshes on every frame\n * @returns the current scene\n */\n unfreezeActiveMeshes() {\n for (let index = 0; index < this.meshes.length; index++) {\n const mesh = this.meshes[index];\n if (mesh._internalAbstractMeshDataInfo) {\n mesh._internalAbstractMeshDataInfo._isActive = false;\n }\n }\n for (let index = 0; index < this._activeMeshes.length; index++) {\n this._activeMeshes.data[index]._unFreeze();\n }\n this._activeMeshesFrozen = false;\n return this;\n }\n _executeActiveContainerCleanup(container) {\n const isInFastMode = this._engine.snapshotRendering && this._engine.snapshotRenderingMode === 1;\n if (!isInFastMode && this._activeMeshesFrozen && this._activeMeshes.length) {\n return; // Do not execute in frozen mode\n }\n // We need to ensure we are not in the rendering loop\n this.onBeforeRenderObservable.addOnce(() => container.dispose());\n }\n _evaluateActiveMeshes() {\n var _a;\n if (this._engine.snapshotRendering && this._engine.snapshotRenderingMode === 1) {\n if (this._activeMeshes.length > 0) {\n (_a = this.activeCamera) === null || _a === void 0 ? void 0 : _a._activeMeshes.reset();\n this._activeMeshes.reset();\n this._renderingManager.reset();\n this._processedMaterials.reset();\n this._activeParticleSystems.reset();\n this._activeSkeletons.reset();\n this._softwareSkinnedMeshes.reset();\n }\n return;\n }\n if (this._activeMeshesFrozen && this._activeMeshes.length) {\n if (!this._skipEvaluateActiveMeshesCompletely) {\n const len = this._activeMeshes.length;\n for (let i = 0; i < len; i++) {\n const mesh = this._activeMeshes.data[i];\n mesh.computeWorldMatrix();\n }\n }\n if (this._activeParticleSystems) {\n const psLength = this._activeParticleSystems.length;\n for (let i = 0; i < psLength; i++) {\n this._activeParticleSystems.data[i].animate();\n }\n }\n this._renderingManager.resetSprites();\n return;\n }\n if (!this.activeCamera) {\n return;\n }\n this.onBeforeActiveMeshesEvaluationObservable.notifyObservers(this);\n this.activeCamera._activeMeshes.reset();\n this._activeMeshes.reset();\n this._renderingManager.reset();\n this._processedMaterials.reset();\n this._activeParticleSystems.reset();\n this._activeSkeletons.reset();\n this._softwareSkinnedMeshes.reset();\n this._materialsRenderTargets.reset();\n for (const step of this._beforeEvaluateActiveMeshStage) {\n step.action();\n }\n // Determine mesh candidates\n const meshes = this.getActiveMeshCandidates();\n // Check each mesh\n const len = meshes.length;\n for (let i = 0; i < len; i++) {\n const mesh = meshes.data[i];\n mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate = false;\n if (mesh.isBlocked) {\n continue;\n }\n this._totalVertices.addCount(mesh.getTotalVertices(), false);\n if (!mesh.isReady() || !mesh.isEnabled() || mesh.scaling.hasAZeroComponent) {\n continue;\n }\n mesh.computeWorldMatrix();\n // Intersections\n if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers2(12, 13)) {\n this._meshesForIntersections.pushNoDuplicate(mesh);\n }\n // Switch to current LOD\n let meshToRender = this.customLODSelector ? this.customLODSelector(mesh, this.activeCamera) : mesh.getLOD(this.activeCamera);\n mesh._internalAbstractMeshDataInfo._currentLOD = meshToRender;\n mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate = true;\n if (meshToRender === undefined || meshToRender === null) {\n continue;\n }\n // Compute world matrix if LOD is billboard\n if (meshToRender !== mesh && meshToRender.billboardMode !== 0) {\n meshToRender.computeWorldMatrix();\n }\n mesh._preActivate();\n if (mesh.isVisible &&\n mesh.visibility > 0 &&\n (mesh.layerMask & this.activeCamera.layerMask) !== 0 &&\n (this._skipFrustumClipping || mesh.alwaysSelectAsActiveMesh || mesh.isInFrustum(this._frustumPlanes))) {\n this._activeMeshes.push(mesh);\n this.activeCamera._activeMeshes.push(mesh);\n if (meshToRender !== mesh) {\n meshToRender._activate(this._renderId, false);\n }\n for (const step of this._preActiveMeshStage) {\n step.action(mesh);\n }\n if (mesh._activate(this._renderId, false)) {\n if (!mesh.isAnInstance) {\n meshToRender._internalAbstractMeshDataInfo._onlyForInstances = false;\n }\n else {\n if (mesh._internalAbstractMeshDataInfo._actAsRegularMesh) {\n meshToRender = mesh;\n }\n }\n meshToRender._internalAbstractMeshDataInfo._isActive = true;\n this._activeMesh(mesh, meshToRender);\n }\n mesh._postActivate();\n }\n }\n this.onAfterActiveMeshesEvaluationObservable.notifyObservers(this);\n // Particle systems\n if (this.particlesEnabled) {\n this.onBeforeParticlesRenderingObservable.notifyObservers(this);\n for (let particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {\n const particleSystem = this.particleSystems[particleIndex];\n if (!particleSystem.isStarted() || !particleSystem.emitter) {\n continue;\n }\n const emitter = particleSystem.emitter;\n if (!emitter.position || emitter.isEnabled()) {\n this._activeParticleSystems.push(particleSystem);\n particleSystem.animate();\n this._renderingManager.dispatchParticles(particleSystem);\n }\n }\n this.onAfterParticlesRenderingObservable.notifyObservers(this);\n }\n }\n _activeMesh(sourceMesh, mesh) {\n if (this._skeletonsEnabled && mesh.skeleton !== null && mesh.skeleton !== undefined) {\n if (this._activeSkeletons.pushNoDuplicate(mesh.skeleton)) {\n mesh.skeleton.prepare();\n this._activeBones.addCount(mesh.skeleton.bones.length, false);\n }\n if (!mesh.computeBonesUsingShaders) {\n this._softwareSkinnedMeshes.pushNoDuplicate(mesh);\n }\n }\n let forcePush = sourceMesh.hasInstances || sourceMesh.isAnInstance || this.dispatchAllSubMeshesOfActiveMeshes || this._skipFrustumClipping || mesh.alwaysSelectAsActiveMesh;\n if (mesh && mesh.subMeshes && mesh.subMeshes.length > 0) {\n const subMeshes = this.getActiveSubMeshCandidates(mesh);\n const len = subMeshes.length;\n forcePush = forcePush || len === 1;\n for (let i = 0; i < len; i++) {\n const subMesh = subMeshes.data[i];\n this._evaluateSubMesh(subMesh, mesh, sourceMesh, forcePush);\n }\n }\n }\n /**\n * Update the transform matrix to update from the current active camera\n * @param force defines a boolean used to force the update even if cache is up to date\n */\n updateTransformMatrix(force) {\n if (!this.activeCamera) {\n return;\n }\n if (this.activeCamera._renderingMultiview) {\n const leftCamera = this.activeCamera._rigCameras[0];\n const rightCamera = this.activeCamera._rigCameras[1];\n this.setTransformMatrix(leftCamera.getViewMatrix(), leftCamera.getProjectionMatrix(force), rightCamera.getViewMatrix(), rightCamera.getProjectionMatrix(force));\n }\n else {\n this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));\n }\n }\n _bindFrameBuffer(camera, clear = true) {\n if (camera && camera._multiviewTexture) {\n camera._multiviewTexture._bindFrameBuffer();\n }\n else if (camera && camera.outputRenderTarget) {\n camera.outputRenderTarget._bindFrameBuffer();\n }\n else {\n if (!this._engine._currentFrameBufferIsDefaultFrameBuffer()) {\n this._engine.restoreDefaultFramebuffer();\n }\n }\n if (clear) {\n this._clearFrameBuffer(camera);\n }\n }\n _clearFrameBuffer(camera) {\n // we assume the framebuffer currently bound is the right one\n if (camera && camera._multiviewTexture) ;\n else if (camera && camera.outputRenderTarget && !camera._renderingMultiview) {\n const rtt = camera.outputRenderTarget;\n if (rtt.onClearObservable.hasObservers()) {\n rtt.onClearObservable.notifyObservers(this._engine);\n }\n else if (!rtt.skipInitialClear) {\n if (this.autoClear) {\n this._engine.clear(rtt.clearColor || this.clearColor, !rtt._cleared, true, true);\n }\n rtt._cleared = true;\n }\n }\n else {\n if (!this._defaultFrameBufferCleared) {\n this._defaultFrameBufferCleared = true;\n this._clear();\n }\n else {\n this._engine.clear(null, false, true, true);\n }\n }\n }\n /**\n * @internal\n */\n _renderForCamera(camera, rigParent, bindFrameBuffer = true) {\n var _a, _b, _c;\n if (camera && camera._skipRendering) {\n return;\n }\n const engine = this._engine;\n // Use _activeCamera instead of activeCamera to avoid onActiveCameraChanged\n this._activeCamera = camera;\n if (!this.activeCamera) {\n throw new Error(\"Active camera not set\");\n }\n // Viewport\n engine.setViewport(this.activeCamera.viewport);\n // Camera\n this.resetCachedMaterial();\n this._renderId++;\n if (!this.prePass && bindFrameBuffer) {\n let skipInitialClear = true;\n if (camera._renderingMultiview && camera.outputRenderTarget) {\n skipInitialClear = camera.outputRenderTarget.skipInitialClear;\n if (this.autoClear) {\n this._defaultFrameBufferCleared = false;\n camera.outputRenderTarget.skipInitialClear = false;\n }\n }\n this._bindFrameBuffer(this._activeCamera);\n if (camera._renderingMultiview && camera.outputRenderTarget) {\n camera.outputRenderTarget.skipInitialClear = skipInitialClear;\n }\n }\n this.updateTransformMatrix();\n this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera);\n // Meshes\n this._evaluateActiveMeshes();\n // Software skinning\n for (let softwareSkinnedMeshIndex = 0; softwareSkinnedMeshIndex < this._softwareSkinnedMeshes.length; softwareSkinnedMeshIndex++) {\n const mesh = this._softwareSkinnedMeshes.data[softwareSkinnedMeshIndex];\n mesh.applySkeleton(mesh.skeleton);\n }\n // Render targets\n this.onBeforeRenderTargetsRenderObservable.notifyObservers(this);\n this._renderTargets.concatWithNoDuplicate(this._materialsRenderTargets);\n if (camera.customRenderTargets && camera.customRenderTargets.length > 0) {\n this._renderTargets.concatWithNoDuplicate(camera.customRenderTargets);\n }\n if (rigParent && rigParent.customRenderTargets && rigParent.customRenderTargets.length > 0) {\n this._renderTargets.concatWithNoDuplicate(rigParent.customRenderTargets);\n }\n if (this.environmentTexture && this.environmentTexture.isRenderTarget) {\n this._renderTargets.pushNoDuplicate(this.environmentTexture);\n }\n // Collects render targets from external components.\n for (const step of this._gatherActiveCameraRenderTargetsStage) {\n step.action(this._renderTargets);\n }\n let needRebind = false;\n if (this.renderTargetsEnabled) {\n this._intermediateRendering = true;\n if (this._renderTargets.length > 0) {\n Tools.StartPerformanceCounter(\"Render targets\", this._renderTargets.length > 0);\n for (let renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {\n const renderTarget = this._renderTargets.data[renderIndex];\n if (renderTarget._shouldRender()) {\n this._renderId++;\n const hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;\n renderTarget.render(hasSpecialRenderTargetCamera, this.dumpNextRenderTargets);\n needRebind = true;\n }\n }\n Tools.EndPerformanceCounter(\"Render targets\", this._renderTargets.length > 0);\n this._renderId++;\n }\n for (const step of this._cameraDrawRenderTargetStage) {\n needRebind = step.action(this.activeCamera) || needRebind;\n }\n this._intermediateRendering = false;\n }\n this._engine.currentRenderPassId = (_c = (_b = (_a = camera.outputRenderTarget) === null || _a === void 0 ? void 0 : _a.renderPassId) !== null && _b !== void 0 ? _b : camera.renderPassId) !== null && _c !== void 0 ? _c : 0;\n // Restore framebuffer after rendering to targets\n if (needRebind && !this.prePass) {\n this._bindFrameBuffer(this._activeCamera, false);\n }\n this.onAfterRenderTargetsRenderObservable.notifyObservers(this);\n // Prepare Frame\n if (this.postProcessManager && !camera._multiviewTexture && !this.prePass) {\n this.postProcessManager._prepareFrame();\n }\n // Before Camera Draw\n for (const step of this._beforeCameraDrawStage) {\n step.action(this.activeCamera);\n }\n // Render\n this.onBeforeDrawPhaseObservable.notifyObservers(this);\n if (engine.snapshotRendering && engine.snapshotRenderingMode === 1) {\n this.finalizeSceneUbo();\n }\n this._renderingManager.render(null, null, true, true);\n this.onAfterDrawPhaseObservable.notifyObservers(this);\n // After Camera Draw\n for (const step of this._afterCameraDrawStage) {\n step.action(this.activeCamera);\n }\n // Finalize frame\n if (this.postProcessManager && !camera._multiviewTexture) {\n // if the camera has an output render target, render the post process to the render target\n const texture = camera.outputRenderTarget ? camera.outputRenderTarget.renderTarget : undefined;\n this.postProcessManager._finalizeFrame(camera.isIntermediate, texture);\n }\n // After post process\n for (const step of this._afterCameraPostProcessStage) {\n step.action(this.activeCamera);\n }\n // Reset some special arrays\n this._renderTargets.reset();\n this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera);\n }\n _processSubCameras(camera, bindFrameBuffer = true) {\n if (camera.cameraRigMode === 0 || camera._renderingMultiview) {\n if (camera._renderingMultiview && !this._multiviewSceneUbo) {\n this._createMultiviewUbo();\n }\n this._renderForCamera(camera, undefined, bindFrameBuffer);\n this.onAfterRenderCameraObservable.notifyObservers(camera);\n return;\n }\n if (camera._useMultiviewToSingleView) {\n this._renderMultiviewToSingleView(camera);\n }\n else {\n // rig cameras\n this.onBeforeCameraRenderObservable.notifyObservers(camera);\n for (let index = 0; index < camera._rigCameras.length; index++) {\n this._renderForCamera(camera._rigCameras[index], camera);\n }\n }\n // Use _activeCamera instead of activeCamera to avoid onActiveCameraChanged\n this._activeCamera = camera;\n this.updateTransformMatrix();\n this.onAfterRenderCameraObservable.notifyObservers(camera);\n }\n _checkIntersections() {\n for (let index = 0; index < this._meshesForIntersections.length; index++) {\n const sourceMesh = this._meshesForIntersections.data[index];\n if (!sourceMesh.actionManager) {\n continue;\n }\n for (let actionIndex = 0; sourceMesh.actionManager && actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {\n const action = sourceMesh.actionManager.actions[actionIndex];\n if (action.trigger === 12 || action.trigger === 13) {\n const parameters = action.getTriggerParameter();\n const otherMesh = parameters.mesh ? parameters.mesh : parameters;\n const areIntersecting = otherMesh.intersectsMesh(sourceMesh, parameters.usePreciseIntersection);\n const currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);\n if (areIntersecting && currentIntersectionInProgress === -1) {\n if (action.trigger === 12) {\n action._executeCurrent(ActionEvent.CreateNew(sourceMesh, undefined, otherMesh));\n sourceMesh._intersectionsInProgress.push(otherMesh);\n }\n else if (action.trigger === 13) {\n sourceMesh._intersectionsInProgress.push(otherMesh);\n }\n }\n else if (!areIntersecting && currentIntersectionInProgress > -1) {\n //They intersected, and now they don't.\n //is this trigger an exit trigger? execute an event.\n if (action.trigger === 13) {\n action._executeCurrent(ActionEvent.CreateNew(sourceMesh, undefined, otherMesh));\n }\n //if this is an exit trigger, or no exit trigger exists, remove the id from the intersection in progress array.\n if (!sourceMesh.actionManager.hasSpecificTrigger(13, (parameter) => {\n const parameterMesh = parameter.mesh ? parameter.mesh : parameter;\n return otherMesh === parameterMesh;\n }) ||\n action.trigger === 13) {\n sourceMesh._intersectionsInProgress.splice(currentIntersectionInProgress, 1);\n }\n }\n }\n }\n }\n }\n /**\n * @internal\n */\n _advancePhysicsEngineStep(step) {\n // Do nothing. Code will be replaced if physics engine component is referenced\n }\n /** @internal */\n _animate() {\n // Nothing to do as long as Animatable have not been imported.\n }\n /** Execute all animations (for a frame) */\n animate() {\n if (this._engine.isDeterministicLockStep()) {\n let deltaTime = Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime)) + this._timeAccumulator;\n const defaultFrameTime = this._engine.getTimeStep();\n const defaultFPS = 1000.0 / defaultFrameTime / 1000.0;\n let stepsTaken = 0;\n const maxSubSteps = this._engine.getLockstepMaxSteps();\n let internalSteps = Math.floor(deltaTime / defaultFrameTime);\n internalSteps = Math.min(internalSteps, maxSubSteps);\n while (deltaTime > 0 && stepsTaken < internalSteps) {\n this.onBeforeStepObservable.notifyObservers(this);\n // Animations\n this._animationRatio = defaultFrameTime * defaultFPS;\n this._animate();\n this.onAfterAnimationsObservable.notifyObservers(this);\n // Physics\n if (this.physicsEnabled) {\n this._advancePhysicsEngineStep(defaultFrameTime);\n }\n this.onAfterStepObservable.notifyObservers(this);\n this._currentStepId++;\n stepsTaken++;\n deltaTime -= defaultFrameTime;\n }\n this._timeAccumulator = deltaTime < 0 ? 0 : deltaTime;\n }\n else {\n // Animations\n const deltaTime = this.useConstantAnimationDeltaTime ? 16 : Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime));\n this._animationRatio = deltaTime * (60.0 / 1000.0);\n this._animate();\n this.onAfterAnimationsObservable.notifyObservers(this);\n // Physics\n if (this.physicsEnabled) {\n this._advancePhysicsEngineStep(deltaTime);\n }\n }\n }\n _clear() {\n if (this.autoClearDepthAndStencil || this.autoClear) {\n this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, this.autoClearDepthAndStencil, this.autoClearDepthAndStencil);\n }\n }\n _checkCameraRenderTarget(camera) {\n var _a;\n if ((camera === null || camera === void 0 ? void 0 : camera.outputRenderTarget) && !(camera === null || camera === void 0 ? void 0 : camera.isRigCamera)) {\n camera.outputRenderTarget._cleared = false;\n }\n if ((_a = camera === null || camera === void 0 ? void 0 : camera.rigCameras) === null || _a === void 0 ? void 0 : _a.length) {\n for (let i = 0; i < camera.rigCameras.length; ++i) {\n const rtt = camera.rigCameras[i].outputRenderTarget;\n if (rtt) {\n rtt._cleared = false;\n }\n }\n }\n }\n /**\n * Resets the draw wrappers cache of all meshes\n * @param passId If provided, releases only the draw wrapper corresponding to this render pass id\n */\n resetDrawCache(passId) {\n if (!this.meshes) {\n return;\n }\n for (const mesh of this.meshes) {\n mesh.resetDrawCache(passId);\n }\n }\n /**\n * Render the scene\n * @param updateCameras defines a boolean indicating if cameras must update according to their inputs (true by default)\n * @param ignoreAnimations defines a boolean indicating if animations should not be executed (false by default)\n */\n render(updateCameras = true, ignoreAnimations = false) {\n var _a, _b, _c;\n if (this.isDisposed) {\n return;\n }\n if (this.onReadyObservable.hasObservers() && this._executeWhenReadyTimeoutId === null) {\n this._checkIsReady();\n }\n this._frameId++;\n this._defaultFrameBufferCleared = false;\n this._checkCameraRenderTarget(this.activeCamera);\n if ((_a = this.activeCameras) === null || _a === void 0 ? void 0 : _a.length) {\n this.activeCameras.forEach(this._checkCameraRenderTarget);\n }\n // Register components that have been associated lately to the scene.\n this._registerTransientComponents();\n this._activeParticles.fetchNewFrame();\n this._totalVertices.fetchNewFrame();\n this._activeIndices.fetchNewFrame();\n this._activeBones.fetchNewFrame();\n this._meshesForIntersections.reset();\n this.resetCachedMaterial();\n this.onBeforeAnimationsObservable.notifyObservers(this);\n // Actions\n if (this.actionManager) {\n this.actionManager.processTrigger(11);\n }\n // Animations\n if (!ignoreAnimations) {\n this.animate();\n }\n // Before camera update steps\n for (const step of this._beforeCameraUpdateStage) {\n step.action();\n }\n // Update Cameras\n if (updateCameras) {\n if (this.activeCameras && this.activeCameras.length > 0) {\n for (let cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {\n const camera = this.activeCameras[cameraIndex];\n camera.update();\n if (camera.cameraRigMode !== 0) {\n // rig cameras\n for (let index = 0; index < camera._rigCameras.length; index++) {\n camera._rigCameras[index].update();\n }\n }\n }\n }\n else if (this.activeCamera) {\n this.activeCamera.update();\n if (this.activeCamera.cameraRigMode !== 0) {\n // rig cameras\n for (let index = 0; index < this.activeCamera._rigCameras.length; index++) {\n this.activeCamera._rigCameras[index].update();\n }\n }\n }\n }\n // Before render\n this.onBeforeRenderObservable.notifyObservers(this);\n const engine = this.getEngine();\n // Customs render targets\n this.onBeforeRenderTargetsRenderObservable.notifyObservers(this);\n const currentActiveCamera = ((_b = this.activeCameras) === null || _b === void 0 ? void 0 : _b.length) ? this.activeCameras[0] : this.activeCamera;\n if (this.renderTargetsEnabled) {\n Tools.StartPerformanceCounter(\"Custom render targets\", this.customRenderTargets.length > 0);\n this._intermediateRendering = true;\n for (let customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {\n const renderTarget = this.customRenderTargets[customIndex];\n if (renderTarget._shouldRender()) {\n this._renderId++;\n this.activeCamera = renderTarget.activeCamera || this.activeCamera;\n if (!this.activeCamera) {\n throw new Error(\"Active camera not set\");\n }\n // Viewport\n engine.setViewport(this.activeCamera.viewport);\n // Camera\n this.updateTransformMatrix();\n renderTarget.render(currentActiveCamera !== this.activeCamera, this.dumpNextRenderTargets);\n }\n }\n Tools.EndPerformanceCounter(\"Custom render targets\", this.customRenderTargets.length > 0);\n this._intermediateRendering = false;\n this._renderId++;\n }\n this._engine.currentRenderPassId = (_c = currentActiveCamera === null || currentActiveCamera === void 0 ? void 0 : currentActiveCamera.renderPassId) !== null && _c !== void 0 ? _c : 0;\n // Restore back buffer\n this.activeCamera = currentActiveCamera;\n if (this._activeCamera && this._activeCamera.cameraRigMode !== 22 && !this.prePass) {\n this._bindFrameBuffer(this._activeCamera, false);\n }\n this.onAfterRenderTargetsRenderObservable.notifyObservers(this);\n for (const step of this._beforeClearStage) {\n step.action();\n }\n // Clear\n this._clearFrameBuffer(this.activeCamera);\n // Collects render targets from external components.\n for (const step of this._gatherRenderTargetsStage) {\n step.action(this._renderTargets);\n }\n // Multi-cameras?\n if (this.activeCameras && this.activeCameras.length > 0) {\n for (let cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {\n this._processSubCameras(this.activeCameras[cameraIndex], cameraIndex > 0);\n }\n }\n else {\n if (!this.activeCamera) {\n throw new Error(\"No camera defined\");\n }\n this._processSubCameras(this.activeCamera, !!this.activeCamera.outputRenderTarget);\n }\n // Intersection checks\n this._checkIntersections();\n // Executes the after render stage actions.\n for (const step of this._afterRenderStage) {\n step.action();\n }\n // After render\n if (this.afterRender) {\n this.afterRender();\n }\n this.onAfterRenderObservable.notifyObservers(this);\n // Cleaning\n if (this._toBeDisposed.length) {\n for (let index = 0; index < this._toBeDisposed.length; index++) {\n const data = this._toBeDisposed[index];\n if (data) {\n data.dispose();\n }\n }\n this._toBeDisposed.length = 0;\n }\n if (this.dumpNextRenderTargets) {\n this.dumpNextRenderTargets = false;\n }\n this._activeBones.addCount(0, true);\n this._activeIndices.addCount(0, true);\n this._activeParticles.addCount(0, true);\n this._engine.restoreDefaultFramebuffer();\n }\n /**\n * Freeze all materials\n * A frozen material will not be updatable but should be faster to render\n * Note: multimaterials will not be frozen, but their submaterials will\n */\n freezeMaterials() {\n for (let i = 0; i < this.materials.length; i++) {\n this.materials[i].freeze();\n }\n }\n /**\n * Unfreeze all materials\n * A frozen material will not be updatable but should be faster to render\n */\n unfreezeMaterials() {\n for (let i = 0; i < this.materials.length; i++) {\n this.materials[i].unfreeze();\n }\n }\n /**\n * Releases all held resources\n */\n dispose() {\n if (this.isDisposed) {\n return;\n }\n this.beforeRender = null;\n this.afterRender = null;\n this.metadata = null;\n this.skeletons.length = 0;\n this.morphTargetManagers.length = 0;\n this._transientComponents.length = 0;\n this._isReadyForMeshStage.clear();\n this._beforeEvaluateActiveMeshStage.clear();\n this._evaluateSubMeshStage.clear();\n this._preActiveMeshStage.clear();\n this._cameraDrawRenderTargetStage.clear();\n this._beforeCameraDrawStage.clear();\n this._beforeRenderTargetDrawStage.clear();\n this._beforeRenderingGroupDrawStage.clear();\n this._beforeRenderingMeshStage.clear();\n this._afterRenderingMeshStage.clear();\n this._afterRenderingGroupDrawStage.clear();\n this._afterCameraDrawStage.clear();\n this._afterRenderTargetDrawStage.clear();\n this._afterRenderStage.clear();\n this._beforeCameraUpdateStage.clear();\n this._beforeClearStage.clear();\n this._gatherRenderTargetsStage.clear();\n this._gatherActiveCameraRenderTargetsStage.clear();\n this._pointerMoveStage.clear();\n this._pointerDownStage.clear();\n this._pointerUpStage.clear();\n this.importedMeshesFiles = new Array();\n if (this.stopAllAnimations) {\n // Ensures that no animatable notifies a callback that could start a new animation group, constantly adding new animatables to the active list...\n this._activeAnimatables.forEach((animatable) => {\n animatable.onAnimationEndObservable.clear();\n animatable.onAnimationEnd = null;\n });\n this.stopAllAnimations();\n }\n this.resetCachedMaterial();\n // Smart arrays\n if (this.activeCamera) {\n this.activeCamera._activeMeshes.dispose();\n this.activeCamera = null;\n }\n this.activeCameras = null;\n this._activeMeshes.dispose();\n this._renderingManager.dispose();\n this._processedMaterials.dispose();\n this._activeParticleSystems.dispose();\n this._activeSkeletons.dispose();\n this._softwareSkinnedMeshes.dispose();\n this._renderTargets.dispose();\n this._materialsRenderTargets.dispose();\n this._registeredForLateAnimationBindings.dispose();\n this._meshesForIntersections.dispose();\n this._toBeDisposed.length = 0;\n // Abort active requests\n const activeRequests = this._activeRequests.slice();\n for (const request of activeRequests) {\n request.abort();\n }\n this._activeRequests.length = 0;\n // Events\n try {\n this.onDisposeObservable.notifyObservers(this);\n }\n catch (e) {\n console.error(\"An error occurred while calling onDisposeObservable!\", e);\n }\n this.detachControl();\n // Detach cameras\n const canvas = this._engine.getInputElement();\n if (canvas) {\n for (let index = 0; index < this.cameras.length; index++) {\n this.cameras[index].detachControl();\n }\n }\n // Release animation groups\n this._disposeList(this.animationGroups);\n // Release lights\n this._disposeList(this.lights);\n // Release meshes\n this._disposeList(this.meshes, (item) => item.dispose(true));\n this._disposeList(this.transformNodes, (item) => item.dispose(true));\n // Release cameras\n const cameras = this.cameras;\n this._disposeList(cameras);\n // Release materials\n if (this._defaultMaterial) {\n this._defaultMaterial.dispose();\n }\n this._disposeList(this.multiMaterials);\n this._disposeList(this.materials);\n // Release particles\n this._disposeList(this.particleSystems);\n // Release postProcesses\n this._disposeList(this.postProcesses);\n // Release textures\n this._disposeList(this.textures);\n // Release morph targets\n this._disposeList(this.morphTargetManagers);\n // Release UBO\n this._sceneUbo.dispose();\n if (this._multiviewSceneUbo) {\n this._multiviewSceneUbo.dispose();\n }\n // Post-processes\n this.postProcessManager.dispose();\n // Components\n this._disposeList(this._components);\n // Remove from engine\n let index = this._engine.scenes.indexOf(this);\n if (index > -1) {\n this._engine.scenes.splice(index, 1);\n }\n if (EngineStore._LastCreatedScene === this) {\n if (this._engine.scenes.length > 0) {\n EngineStore._LastCreatedScene = this._engine.scenes[this._engine.scenes.length - 1];\n }\n else {\n EngineStore._LastCreatedScene = null;\n }\n }\n index = this._engine._virtualScenes.indexOf(this);\n if (index > -1) {\n this._engine._virtualScenes.splice(index, 1);\n }\n this._engine.wipeCaches(true);\n this.onDisposeObservable.clear();\n this.onBeforeRenderObservable.clear();\n this.onAfterRenderObservable.clear();\n this.onBeforeRenderTargetsRenderObservable.clear();\n this.onAfterRenderTargetsRenderObservable.clear();\n this.onAfterStepObservable.clear();\n this.onBeforeStepObservable.clear();\n this.onBeforeActiveMeshesEvaluationObservable.clear();\n this.onAfterActiveMeshesEvaluationObservable.clear();\n this.onBeforeParticlesRenderingObservable.clear();\n this.onAfterParticlesRenderingObservable.clear();\n this.onBeforeDrawPhaseObservable.clear();\n this.onAfterDrawPhaseObservable.clear();\n this.onBeforeAnimationsObservable.clear();\n this.onAfterAnimationsObservable.clear();\n this.onDataLoadedObservable.clear();\n this.onBeforeRenderingGroupObservable.clear();\n this.onAfterRenderingGroupObservable.clear();\n this.onMeshImportedObservable.clear();\n this.onBeforeCameraRenderObservable.clear();\n this.onAfterCameraRenderObservable.clear();\n this.onAfterRenderCameraObservable.clear();\n this.onReadyObservable.clear();\n this.onNewCameraAddedObservable.clear();\n this.onCameraRemovedObservable.clear();\n this.onNewLightAddedObservable.clear();\n this.onLightRemovedObservable.clear();\n this.onNewGeometryAddedObservable.clear();\n this.onGeometryRemovedObservable.clear();\n this.onNewTransformNodeAddedObservable.clear();\n this.onTransformNodeRemovedObservable.clear();\n this.onNewMeshAddedObservable.clear();\n this.onMeshRemovedObservable.clear();\n this.onNewSkeletonAddedObservable.clear();\n this.onSkeletonRemovedObservable.clear();\n this.onNewMaterialAddedObservable.clear();\n this.onNewMultiMaterialAddedObservable.clear();\n this.onMaterialRemovedObservable.clear();\n this.onMultiMaterialRemovedObservable.clear();\n this.onNewTextureAddedObservable.clear();\n this.onTextureRemovedObservable.clear();\n this.onPrePointerObservable.clear();\n this.onPointerObservable.clear();\n this.onPreKeyboardObservable.clear();\n this.onKeyboardObservable.clear();\n this.onActiveCameraChanged.clear();\n this.onScenePerformancePriorityChangedObservable.clear();\n this._isDisposed = true;\n }\n _disposeList(items, callback) {\n const itemsCopy = items.slice(0);\n callback = callback !== null && callback !== void 0 ? callback : ((item) => item.dispose());\n for (const item of itemsCopy) {\n callback(item);\n }\n items.length = 0;\n }\n /**\n * Gets if the scene is already disposed\n */\n get isDisposed() {\n return this._isDisposed;\n }\n /**\n * Call this function to reduce memory footprint of the scene.\n * Vertex buffers will not store CPU data anymore (this will prevent picking, collisions or physics to work correctly)\n */\n clearCachedVertexData() {\n for (let meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {\n const mesh = this.meshes[meshIndex];\n const geometry = mesh.geometry;\n if (geometry) {\n geometry.clearCachedData();\n }\n }\n }\n /**\n * This function will remove the local cached buffer data from texture.\n * It will save memory but will prevent the texture from being rebuilt\n */\n cleanCachedTextureBuffer() {\n for (const baseTexture of this.textures) {\n const buffer = baseTexture._buffer;\n if (buffer) {\n baseTexture._buffer = null;\n }\n }\n }\n /**\n * Get the world extend vectors with an optional filter\n *\n * @param filterPredicate the predicate - which meshes should be included when calculating the world size\n * @returns {{ min: Vector3; max: Vector3 }} min and max vectors\n */\n getWorldExtends(filterPredicate) {\n const min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n const max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n filterPredicate = filterPredicate || (() => true);\n this.meshes.filter(filterPredicate).forEach((mesh) => {\n mesh.computeWorldMatrix(true);\n if (!mesh.subMeshes || mesh.subMeshes.length === 0 || mesh.infiniteDistance) {\n return;\n }\n const boundingInfo = mesh.getBoundingInfo();\n const minBox = boundingInfo.boundingBox.minimumWorld;\n const maxBox = boundingInfo.boundingBox.maximumWorld;\n Vector3.CheckExtends(minBox, min, max);\n Vector3.CheckExtends(maxBox, min, max);\n });\n return {\n min: min,\n max: max,\n };\n }\n // Picking\n /**\n * Creates a ray that can be used to pick in the scene\n * @param x defines the x coordinate of the origin (on-screen)\n * @param y defines the y coordinate of the origin (on-screen)\n * @param world defines the world matrix to use if you want to pick in object space (instead of world space)\n * @param camera defines the camera to use for the picking\n * @param cameraViewSpace defines if picking will be done in view space (false by default)\n * @returns a Ray\n */\n createPickingRay(x, y, world, camera, cameraViewSpace = false) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Creates a ray that can be used to pick in the scene\n * @param x defines the x coordinate of the origin (on-screen)\n * @param y defines the y coordinate of the origin (on-screen)\n * @param world defines the world matrix to use if you want to pick in object space (instead of world space)\n * @param result defines the ray where to store the picking ray\n * @param camera defines the camera to use for the picking\n * @param cameraViewSpace defines if picking will be done in view space (false by default)\n * @param enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)\n * @returns the current scene\n */\n createPickingRayToRef(x, y, world, result, camera, cameraViewSpace = false, enableDistantPicking = false) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Creates a ray that can be used to pick in the scene\n * @param x defines the x coordinate of the origin (on-screen)\n * @param y defines the y coordinate of the origin (on-screen)\n * @param camera defines the camera to use for the picking\n * @returns a Ray\n */\n createPickingRayInCameraSpace(x, y, camera) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Creates a ray that can be used to pick in the scene\n * @param x defines the x coordinate of the origin (on-screen)\n * @param y defines the y coordinate of the origin (on-screen)\n * @param result defines the ray where to store the picking ray\n * @param camera defines the camera to use for the picking\n * @returns the current scene\n */\n createPickingRayInCameraSpaceToRef(x, y, result, camera) {\n throw _WarnImport(\"Ray\");\n }\n /** @internal */\n get _pickingAvailable() {\n return false;\n }\n /** Launch a ray to try to pick a mesh in the scene\n * @param x position on screen\n * @param y position on screen\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\n * @param fastCheck defines if the first intersection will be used (and not the closest)\n * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @returns a PickingInfo\n */\n pick(x, y, predicate, fastCheck, camera, trianglePredicate) {\n // Dummy info if picking as not been imported\n return new PickingInfo();\n }\n /** Launch a ray to try to pick a mesh in the scene using only bounding information of the main mesh (not using submeshes)\n * @param x position on screen\n * @param y position on screen\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\n * @param fastCheck defines if the first intersection will be used (and not the closest)\n * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used\n * @returns a PickingInfo (Please note that some info will not be set like distance, bv, bu and everything that cannot be capture by only using bounding infos)\n */\n pickWithBoundingInfo(x, y, predicate, fastCheck, camera) {\n // Dummy info if picking as not been imported\n return new PickingInfo();\n }\n /**\n * Use the given ray to pick a mesh in the scene. A mesh triangle can be picked both from its front and back sides,\n * irrespective of orientation.\n * @param ray The ray to use to pick meshes\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must have isPickable set to true\n * @param fastCheck defines if the first intersection will be used (and not the closest)\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @returns a PickingInfo\n */\n pickWithRay(ray, predicate, fastCheck, trianglePredicate) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Launch a ray to try to pick a mesh in the scene. A mesh triangle can be picked both from its front and back sides,\n * irrespective of orientation.\n * @param x X position on screen\n * @param y Y position on screen\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\n * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @returns an array of PickingInfo\n */\n multiPick(x, y, predicate, camera, trianglePredicate) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Launch a ray to try to pick a mesh in the scene\n * @param ray Ray to use\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @returns an array of PickingInfo\n */\n multiPickWithRay(ray, predicate, trianglePredicate) {\n throw _WarnImport(\"Ray\");\n }\n /**\n * Force the value of meshUnderPointer\n * @param mesh defines the mesh to use\n * @param pointerId optional pointer id when using more than one pointer\n * @param pickResult optional pickingInfo data used to find mesh\n */\n setPointerOverMesh(mesh, pointerId, pickResult) {\n this._inputManager.setPointerOverMesh(mesh, pointerId, pickResult);\n }\n /**\n * Gets the mesh under the pointer\n * @returns a Mesh or null if no mesh is under the pointer\n */\n getPointerOverMesh() {\n return this._inputManager.getPointerOverMesh();\n }\n // Misc.\n /** @internal */\n _rebuildGeometries() {\n for (const geometry of this.geometries) {\n geometry._rebuild();\n }\n for (const mesh of this.meshes) {\n mesh._rebuild();\n }\n if (this.postProcessManager) {\n this.postProcessManager._rebuild();\n }\n for (const component of this._components) {\n component.rebuild();\n }\n for (const system of this.particleSystems) {\n system.rebuild();\n }\n if (this.spriteManagers) {\n for (const spriteMgr of this.spriteManagers) {\n spriteMgr.rebuild();\n }\n }\n }\n /** @internal */\n _rebuildTextures() {\n for (const texture of this.textures) {\n texture._rebuild();\n }\n this.markAllMaterialsAsDirty(1);\n }\n // Tags\n _getByTags(list, tagsQuery, forEach) {\n if (tagsQuery === undefined) {\n // returns the complete list (could be done with Tags.MatchesQuery but no need to have a for-loop here)\n return list;\n }\n const listByTags = [];\n forEach =\n forEach ||\n ((item) => {\n return;\n });\n for (const i in list) {\n const item = list[i];\n if (Tags && Tags.MatchesQuery(item, tagsQuery)) {\n listByTags.push(item);\n forEach(item);\n }\n }\n return listByTags;\n }\n /**\n * Get a list of meshes by tags\n * @param tagsQuery defines the tags query to use\n * @param forEach defines a predicate used to filter results\n * @returns an array of Mesh\n */\n getMeshesByTags(tagsQuery, forEach) {\n return this._getByTags(this.meshes, tagsQuery, forEach);\n }\n /**\n * Get a list of cameras by tags\n * @param tagsQuery defines the tags query to use\n * @param forEach defines a predicate used to filter results\n * @returns an array of Camera\n */\n getCamerasByTags(tagsQuery, forEach) {\n return this._getByTags(this.cameras, tagsQuery, forEach);\n }\n /**\n * Get a list of lights by tags\n * @param tagsQuery defines the tags query to use\n * @param forEach defines a predicate used to filter results\n * @returns an array of Light\n */\n getLightsByTags(tagsQuery, forEach) {\n return this._getByTags(this.lights, tagsQuery, forEach);\n }\n /**\n * Get a list of materials by tags\n * @param tagsQuery defines the tags query to use\n * @param forEach defines a predicate used to filter results\n * @returns an array of Material\n */\n getMaterialByTags(tagsQuery, forEach) {\n return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));\n }\n /**\n * Get a list of transform nodes by tags\n * @param tagsQuery defines the tags query to use\n * @param forEach defines a predicate used to filter results\n * @returns an array of TransformNode\n */\n getTransformNodesByTags(tagsQuery, forEach) {\n return this._getByTags(this.transformNodes, tagsQuery, forEach);\n }\n /**\n * Overrides the default sort function applied in the rendering group to prepare the meshes.\n * This allowed control for front to back rendering or reversly depending of the special needs.\n *\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param opaqueSortCompareFn The opaque queue comparison function use to sort.\n * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.\n * @param transparentSortCompareFn The transparent queue comparison function use to sort.\n */\n setRenderingOrder(renderingGroupId, opaqueSortCompareFn = null, alphaTestSortCompareFn = null, transparentSortCompareFn = null) {\n this._renderingManager.setRenderingOrder(renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn);\n }\n /**\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.\n *\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\n * @param depth Automatically clears depth between groups if true and autoClear is true.\n * @param stencil Automatically clears stencil between groups if true and autoClear is true.\n */\n setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil, depth = true, stencil = true) {\n this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil, depth, stencil);\n }\n /**\n * Gets the current auto clear configuration for one rendering group of the rendering\n * manager.\n * @param index the rendering group index to get the information for\n * @returns The auto clear setup for the requested rendering group\n */\n getAutoClearDepthStencilSetup(index) {\n return this._renderingManager.getAutoClearDepthStencilSetup(index);\n }\n /** Gets or sets a boolean blocking all the calls to markAllMaterialsAsDirty (ie. the materials won't be updated if they are out of sync) */\n get blockMaterialDirtyMechanism() {\n return this._blockMaterialDirtyMechanism;\n }\n set blockMaterialDirtyMechanism(value) {\n if (this._blockMaterialDirtyMechanism === value) {\n return;\n }\n this._blockMaterialDirtyMechanism = value;\n if (!value) {\n // Do a complete update\n this.markAllMaterialsAsDirty(63);\n }\n }\n /**\n * Will flag all materials as dirty to trigger new shader compilation\n * @param flag defines the flag used to specify which material part must be marked as dirty\n * @param predicate If not null, it will be used to specify if a material has to be marked as dirty\n */\n markAllMaterialsAsDirty(flag, predicate) {\n if (this._blockMaterialDirtyMechanism) {\n return;\n }\n for (const material of this.materials) {\n if (predicate && !predicate(material)) {\n continue;\n }\n material.markAsDirty(flag);\n }\n }\n /**\n * @internal\n */\n _loadFile(fileOrUrl, onSuccess, onProgress, useOfflineSupport, useArrayBuffer, onError, onOpened) {\n const request = LoadFile(fileOrUrl, onSuccess, onProgress, useOfflineSupport ? this.offlineProvider : undefined, useArrayBuffer, onError, onOpened);\n this._activeRequests.push(request);\n request.onCompleteObservable.add((request) => {\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\n });\n return request;\n }\n /**\n * @internal\n */\n _loadFileAsync(fileOrUrl, onProgress, useOfflineSupport, useArrayBuffer, onOpened) {\n return new Promise((resolve, reject) => {\n this._loadFile(fileOrUrl, (data) => {\n resolve(data);\n }, onProgress, useOfflineSupport, useArrayBuffer, (request, exception) => {\n reject(exception);\n }, onOpened);\n });\n }\n /**\n * @internal\n */\n _requestFile(url, onSuccess, onProgress, useOfflineSupport, useArrayBuffer, onError, onOpened) {\n const request = RequestFile(url, onSuccess, onProgress, useOfflineSupport ? this.offlineProvider : undefined, useArrayBuffer, onError, onOpened);\n this._activeRequests.push(request);\n request.onCompleteObservable.add((request) => {\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\n });\n return request;\n }\n /**\n * @internal\n */\n _requestFileAsync(url, onProgress, useOfflineSupport, useArrayBuffer, onOpened) {\n return new Promise((resolve, reject) => {\n this._requestFile(url, (data) => {\n resolve(data);\n }, onProgress, useOfflineSupport, useArrayBuffer, (error) => {\n reject(error);\n }, onOpened);\n });\n }\n /**\n * @internal\n */\n _readFile(file, onSuccess, onProgress, useArrayBuffer, onError) {\n const request = ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError);\n this._activeRequests.push(request);\n request.onCompleteObservable.add((request) => {\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\n });\n return request;\n }\n /**\n * @internal\n */\n _readFileAsync(file, onProgress, useArrayBuffer) {\n return new Promise((resolve, reject) => {\n this._readFile(file, (data) => {\n resolve(data);\n }, onProgress, useArrayBuffer, (error) => {\n reject(error);\n });\n });\n }\n /**\n * This method gets the performance collector belonging to the scene, which is generally shared with the inspector.\n * @returns the perf collector belonging to the scene.\n */\n getPerfCollector() {\n throw _WarnImport(\"performanceViewerSceneExtension\");\n }\n // deprecated\n /**\n * Sets the active camera of the scene using its Id\n * @param id defines the camera's Id\n * @returns the new active camera or null if none found.\n * @deprecated Please use setActiveCameraById instead\n */\n setActiveCameraByID(id) {\n return this.setActiveCameraById(id);\n }\n /**\n * Get a material using its id\n * @param id defines the material's Id\n * @returns the material or null if none found.\n * @deprecated Please use getMaterialById instead\n */\n getMaterialByID(id) {\n return this.getMaterialById(id);\n }\n /**\n * Gets a the last added material using a given id\n * @param id defines the material's Id\n * @returns the last material with the given id or null if none found.\n * @deprecated Please use getLastMaterialById instead\n */\n getLastMaterialByID(id) {\n return this.getLastMaterialById(id);\n }\n /**\n * Get a texture using its unique id\n * @param uniqueId defines the texture's unique id\n * @returns the texture or null if none found.\n * @deprecated Please use getTextureByUniqueId instead\n */\n getTextureByUniqueID(uniqueId) {\n return this.getTextureByUniqueId(uniqueId);\n }\n /**\n * Gets a camera using its Id\n * @param id defines the Id to look for\n * @returns the camera or null if not found\n * @deprecated Please use getCameraById instead\n */\n getCameraByID(id) {\n return this.getCameraById(id);\n }\n /**\n * Gets a camera using its unique Id\n * @param uniqueId defines the unique Id to look for\n * @returns the camera or null if not found\n * @deprecated Please use getCameraByUniqueId instead\n */\n getCameraByUniqueID(uniqueId) {\n return this.getCameraByUniqueId(uniqueId);\n }\n /**\n * Gets a bone using its Id\n * @param id defines the bone's Id\n * @returns the bone or null if not found\n * @deprecated Please use getBoneById instead\n */\n getBoneByID(id) {\n return this.getBoneById(id);\n }\n /**\n * Gets a light node using its Id\n * @param id defines the light's Id\n * @returns the light or null if none found.\n * @deprecated Please use getLightById instead\n */\n getLightByID(id) {\n return this.getLightById(id);\n }\n /**\n * Gets a light node using its scene-generated unique Id\n * @param uniqueId defines the light's unique Id\n * @returns the light or null if none found.\n * @deprecated Please use getLightByUniqueId instead\n */\n getLightByUniqueID(uniqueId) {\n return this.getLightByUniqueId(uniqueId);\n }\n /**\n * Gets a particle system by Id\n * @param id defines the particle system Id\n * @returns the corresponding system or null if none found\n * @deprecated Please use getParticleSystemById instead\n */\n getParticleSystemByID(id) {\n return this.getParticleSystemById(id);\n }\n /**\n * Gets a geometry using its Id\n * @param id defines the geometry's Id\n * @returns the geometry or null if none found.\n * @deprecated Please use getGeometryById instead\n */\n getGeometryByID(id) {\n return this.getGeometryById(id);\n }\n /**\n * Gets the first added mesh found of a given Id\n * @param id defines the Id to search for\n * @returns the mesh found or null if not found at all\n * @deprecated Please use getMeshById instead\n */\n getMeshByID(id) {\n return this.getMeshById(id);\n }\n /**\n * Gets a mesh with its auto-generated unique Id\n * @param uniqueId defines the unique Id to search for\n * @returns the found mesh or null if not found at all.\n * @deprecated Please use getMeshByUniqueId instead\n */\n getMeshByUniqueID(uniqueId) {\n return this.getMeshByUniqueId(uniqueId);\n }\n /**\n * Gets a the last added mesh using a given Id\n * @param id defines the Id to search for\n * @returns the found mesh or null if not found at all.\n * @deprecated Please use getLastMeshById instead\n */\n getLastMeshByID(id) {\n return this.getLastMeshById(id);\n }\n /**\n * Gets a list of meshes using their Id\n * @param id defines the Id to search for\n * @returns a list of meshes\n * @deprecated Please use getMeshesById instead\n */\n getMeshesByID(id) {\n return this.getMeshesById(id);\n }\n /**\n * Gets the first added transform node found of a given Id\n * @param id defines the Id to search for\n * @returns the found transform node or null if not found at all.\n * @deprecated Please use getTransformNodeById instead\n */\n getTransformNodeByID(id) {\n return this.getTransformNodeById(id);\n }\n /**\n * Gets a transform node with its auto-generated unique Id\n * @param uniqueId defines the unique Id to search for\n * @returns the found transform node or null if not found at all.\n * @deprecated Please use getTransformNodeByUniqueId instead\n */\n getTransformNodeByUniqueID(uniqueId) {\n return this.getTransformNodeByUniqueId(uniqueId);\n }\n /**\n * Gets a list of transform nodes using their Id\n * @param id defines the Id to search for\n * @returns a list of transform nodes\n * @deprecated Please use getTransformNodesById instead\n */\n getTransformNodesByID(id) {\n return this.getTransformNodesById(id);\n }\n /**\n * Gets a node (Mesh, Camera, Light) using a given Id\n * @param id defines the Id to search for\n * @returns the found node or null if not found at all\n * @deprecated Please use getNodeById instead\n */\n getNodeByID(id) {\n return this.getNodeById(id);\n }\n /**\n * Gets a the last added node (Mesh, Camera, Light) using a given Id\n * @param id defines the Id to search for\n * @returns the found node or null if not found at all\n * @deprecated Please use getLastEntryById instead\n */\n getLastEntryByID(id) {\n return this.getLastEntryById(id);\n }\n /**\n * Gets a skeleton using a given Id (if many are found, this function will pick the last one)\n * @param id defines the Id to search for\n * @returns the found skeleton or null if not found at all.\n * @deprecated Please use getLastSkeletonById instead\n */\n getLastSkeletonByID(id) {\n return this.getLastSkeletonById(id);\n }\n }\n /** The fog is deactivated */\n Scene.FOGMODE_NONE = 0;\n /** The fog density is following an exponential function */\n Scene.FOGMODE_EXP = 1;\n /** The fog density is following an exponential function faster than FOGMODE_EXP */\n Scene.FOGMODE_EXP2 = 2;\n /** The fog density is following a linear function. */\n Scene.FOGMODE_LINEAR = 3;\n /**\n * Gets or sets the minimum deltatime when deterministic lock step is enabled\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n */\n Scene.MinDeltaTime = 1.0;\n /**\n * Gets or sets the maximum deltatime when deterministic lock step is enabled\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n */\n Scene.MaxDeltaTime = 1000.0;\n\n /**\n * @internal\n */\n class IntersectionInfo {\n constructor(bu, bv, distance) {\n this.bu = bu;\n this.bv = bv;\n this.distance = distance;\n this.faceId = 0;\n this.subMeshId = 0;\n }\n }\n\n /**\n * Class used to store bounding box information\n */\n class BoundingBox {\n /**\n * Creates a new bounding box\n * @param min defines the minimum vector (in local space)\n * @param max defines the maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n constructor(min, max, worldMatrix) {\n /**\n * Gets the 8 vectors representing the bounding box in local space\n */\n this.vectors = ArrayTools.BuildArray(8, Vector3.Zero);\n /**\n * Gets the center of the bounding box in local space\n */\n this.center = Vector3.Zero();\n /**\n * Gets the center of the bounding box in world space\n */\n this.centerWorld = Vector3.Zero();\n /**\n * Gets the extend size in local space\n */\n this.extendSize = Vector3.Zero();\n /**\n * Gets the extend size in world space\n */\n this.extendSizeWorld = Vector3.Zero();\n /**\n * Gets the OBB (object bounding box) directions\n */\n this.directions = ArrayTools.BuildArray(3, Vector3.Zero);\n /**\n * Gets the 8 vectors representing the bounding box in world space\n */\n this.vectorsWorld = ArrayTools.BuildArray(8, Vector3.Zero);\n /**\n * Gets the minimum vector in world space\n */\n this.minimumWorld = Vector3.Zero();\n /**\n * Gets the maximum vector in world space\n */\n this.maximumWorld = Vector3.Zero();\n /**\n * Gets the minimum vector in local space\n */\n this.minimum = Vector3.Zero();\n /**\n * Gets the maximum vector in local space\n */\n this.maximum = Vector3.Zero();\n /** @internal */\n this._drawWrapperFront = null;\n /** @internal */\n this._drawWrapperBack = null;\n this.reConstruct(min, max, worldMatrix);\n }\n // Methods\n /**\n * Recreates the entire bounding box from scratch as if we call the constructor in place\n * @param min defines the new minimum vector (in local space)\n * @param max defines the new maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n reConstruct(min, max, worldMatrix) {\n const minX = min.x, minY = min.y, minZ = min.z, maxX = max.x, maxY = max.y, maxZ = max.z;\n const vectors = this.vectors;\n this.minimum.copyFromFloats(minX, minY, minZ);\n this.maximum.copyFromFloats(maxX, maxY, maxZ);\n vectors[0].copyFromFloats(minX, minY, minZ);\n vectors[1].copyFromFloats(maxX, maxY, maxZ);\n vectors[2].copyFromFloats(maxX, minY, minZ);\n vectors[3].copyFromFloats(minX, maxY, minZ);\n vectors[4].copyFromFloats(minX, minY, maxZ);\n vectors[5].copyFromFloats(maxX, maxY, minZ);\n vectors[6].copyFromFloats(minX, maxY, maxZ);\n vectors[7].copyFromFloats(maxX, minY, maxZ);\n // OBB\n max.addToRef(min, this.center).scaleInPlace(0.5);\n max.subtractToRef(min, this.extendSize).scaleInPlace(0.5);\n this._worldMatrix = worldMatrix || Matrix.IdentityReadOnly;\n this._update(this._worldMatrix);\n }\n /**\n * Scale the current bounding box by applying a scale factor\n * @param factor defines the scale factor to apply\n * @returns the current bounding box\n */\n scale(factor) {\n const tmpVectors = BoundingBox._TmpVector3;\n const diff = this.maximum.subtractToRef(this.minimum, tmpVectors[0]);\n const len = diff.length();\n diff.normalizeFromLength(len);\n const distance = len * factor;\n const newRadius = diff.scaleInPlace(distance * 0.5);\n const min = this.center.subtractToRef(newRadius, tmpVectors[1]);\n const max = this.center.addToRef(newRadius, tmpVectors[2]);\n this.reConstruct(min, max, this._worldMatrix);\n return this;\n }\n /**\n * Gets the world matrix of the bounding box\n * @returns a matrix\n */\n getWorldMatrix() {\n return this._worldMatrix;\n }\n /**\n * @internal\n */\n _update(world) {\n const minWorld = this.minimumWorld;\n const maxWorld = this.maximumWorld;\n const directions = this.directions;\n const vectorsWorld = this.vectorsWorld;\n const vectors = this.vectors;\n if (!world.isIdentity()) {\n minWorld.setAll(Number.MAX_VALUE);\n maxWorld.setAll(-Number.MAX_VALUE);\n for (let index = 0; index < 8; ++index) {\n const v = vectorsWorld[index];\n Vector3.TransformCoordinatesToRef(vectors[index], world, v);\n minWorld.minimizeInPlace(v);\n maxWorld.maximizeInPlace(v);\n }\n // Extend\n maxWorld.subtractToRef(minWorld, this.extendSizeWorld).scaleInPlace(0.5);\n maxWorld.addToRef(minWorld, this.centerWorld).scaleInPlace(0.5);\n }\n else {\n minWorld.copyFrom(this.minimum);\n maxWorld.copyFrom(this.maximum);\n for (let index = 0; index < 8; ++index) {\n vectorsWorld[index].copyFrom(vectors[index]);\n }\n // Extend\n this.extendSizeWorld.copyFrom(this.extendSize);\n this.centerWorld.copyFrom(this.center);\n }\n Vector3.FromArrayToRef(world.m, 0, directions[0]);\n Vector3.FromArrayToRef(world.m, 4, directions[1]);\n Vector3.FromArrayToRef(world.m, 8, directions[2]);\n this._worldMatrix = world;\n }\n /**\n * Tests if the bounding box is intersecting the frustum planes\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an intersection\n */\n isInFrustum(frustumPlanes) {\n return BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);\n }\n /**\n * Tests if the bounding box is entirely inside the frustum planes\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an inclusion\n */\n isCompletelyInFrustum(frustumPlanes) {\n return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);\n }\n /**\n * Tests if a point is inside the bounding box\n * @param point defines the point to test\n * @returns true if the point is inside the bounding box\n */\n intersectsPoint(point) {\n const min = this.minimumWorld;\n const max = this.maximumWorld;\n const minX = min.x, minY = min.y, minZ = min.z, maxX = max.x, maxY = max.y, maxZ = max.z;\n const pointX = point.x, pointY = point.y, pointZ = point.z;\n const delta = -Epsilon;\n if (maxX - pointX < delta || delta > pointX - minX) {\n return false;\n }\n if (maxY - pointY < delta || delta > pointY - minY) {\n return false;\n }\n if (maxZ - pointZ < delta || delta > pointZ - minZ) {\n return false;\n }\n return true;\n }\n /**\n * Tests if the bounding box intersects with a bounding sphere\n * @param sphere defines the sphere to test\n * @returns true if there is an intersection\n */\n intersectsSphere(sphere) {\n return BoundingBox.IntersectsSphere(this.minimumWorld, this.maximumWorld, sphere.centerWorld, sphere.radiusWorld);\n }\n /**\n * Tests if the bounding box intersects with a box defined by a min and max vectors\n * @param min defines the min vector to use\n * @param max defines the max vector to use\n * @returns true if there is an intersection\n */\n intersectsMinMax(min, max) {\n const myMin = this.minimumWorld;\n const myMax = this.maximumWorld;\n const myMinX = myMin.x, myMinY = myMin.y, myMinZ = myMin.z, myMaxX = myMax.x, myMaxY = myMax.y, myMaxZ = myMax.z;\n const minX = min.x, minY = min.y, minZ = min.z, maxX = max.x, maxY = max.y, maxZ = max.z;\n if (myMaxX < minX || myMinX > maxX) {\n return false;\n }\n if (myMaxY < minY || myMinY > maxY) {\n return false;\n }\n if (myMaxZ < minZ || myMinZ > maxZ) {\n return false;\n }\n return true;\n }\n /**\n * Disposes the resources of the class\n */\n dispose() {\n var _a, _b;\n (_a = this._drawWrapperFront) === null || _a === void 0 ? void 0 : _a.dispose();\n (_b = this._drawWrapperBack) === null || _b === void 0 ? void 0 : _b.dispose();\n }\n // Statics\n /**\n * Tests if two bounding boxes are intersections\n * @param box0 defines the first box to test\n * @param box1 defines the second box to test\n * @returns true if there is an intersection\n */\n static Intersects(box0, box1) {\n return box0.intersectsMinMax(box1.minimumWorld, box1.maximumWorld);\n }\n /**\n * Tests if a bounding box defines by a min/max vectors intersects a sphere\n * @param minPoint defines the minimum vector of the bounding box\n * @param maxPoint defines the maximum vector of the bounding box\n * @param sphereCenter defines the sphere center\n * @param sphereRadius defines the sphere radius\n * @returns true if there is an intersection\n */\n static IntersectsSphere(minPoint, maxPoint, sphereCenter, sphereRadius) {\n const vector = BoundingBox._TmpVector3[0];\n Vector3.ClampToRef(sphereCenter, minPoint, maxPoint, vector);\n const num = Vector3.DistanceSquared(sphereCenter, vector);\n return num <= sphereRadius * sphereRadius;\n }\n /**\n * Tests if a bounding box defined with 8 vectors is entirely inside frustum planes\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an inclusion\n */\n static IsCompletelyInFrustum(boundingVectors, frustumPlanes) {\n for (let p = 0; p < 6; ++p) {\n const frustumPlane = frustumPlanes[p];\n for (let i = 0; i < 8; ++i) {\n if (frustumPlane.dotCoordinate(boundingVectors[i]) < 0) {\n return false;\n }\n }\n }\n return true;\n }\n /**\n * Tests if a bounding box defined with 8 vectors intersects frustum planes\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an intersection\n */\n static IsInFrustum(boundingVectors, frustumPlanes) {\n for (let p = 0; p < 6; ++p) {\n let canReturnFalse = true;\n const frustumPlane = frustumPlanes[p];\n for (let i = 0; i < 8; ++i) {\n if (frustumPlane.dotCoordinate(boundingVectors[i]) >= 0) {\n canReturnFalse = false;\n break;\n }\n }\n if (canReturnFalse) {\n return false;\n }\n }\n return true;\n }\n }\n BoundingBox._TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);\n\n /**\n * Class used to store bounding sphere information\n */\n class BoundingSphere {\n /**\n * Creates a new bounding sphere\n * @param min defines the minimum vector (in local space)\n * @param max defines the maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n constructor(min, max, worldMatrix) {\n /**\n * Gets the center of the bounding sphere in local space\n */\n this.center = Vector3.Zero();\n /**\n * Gets the center of the bounding sphere in world space\n */\n this.centerWorld = Vector3.Zero();\n /**\n * Gets the minimum vector in local space\n */\n this.minimum = Vector3.Zero();\n /**\n * Gets the maximum vector in local space\n */\n this.maximum = Vector3.Zero();\n this.reConstruct(min, max, worldMatrix);\n }\n /**\n * Recreates the entire bounding sphere from scratch as if we call the constructor in place\n * @param min defines the new minimum vector (in local space)\n * @param max defines the new maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n reConstruct(min, max, worldMatrix) {\n this.minimum.copyFrom(min);\n this.maximum.copyFrom(max);\n const distance = Vector3.Distance(min, max);\n max.addToRef(min, this.center).scaleInPlace(0.5);\n this.radius = distance * 0.5;\n this._update(worldMatrix || Matrix.IdentityReadOnly);\n }\n /**\n * Scale the current bounding sphere by applying a scale factor\n * @param factor defines the scale factor to apply\n * @returns the current bounding box\n */\n scale(factor) {\n const newRadius = this.radius * factor;\n const tmpVectors = BoundingSphere._TmpVector3;\n const tempRadiusVector = tmpVectors[0].setAll(newRadius);\n const min = this.center.subtractToRef(tempRadiusVector, tmpVectors[1]);\n const max = this.center.addToRef(tempRadiusVector, tmpVectors[2]);\n this.reConstruct(min, max, this._worldMatrix);\n return this;\n }\n /**\n * Gets the world matrix of the bounding box\n * @returns a matrix\n */\n getWorldMatrix() {\n return this._worldMatrix;\n }\n // Methods\n /**\n * @internal\n */\n _update(worldMatrix) {\n if (!worldMatrix.isIdentity()) {\n Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);\n const tempVector = BoundingSphere._TmpVector3[0];\n Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, worldMatrix, tempVector);\n this.radiusWorld = Math.max(Math.abs(tempVector.x), Math.abs(tempVector.y), Math.abs(tempVector.z)) * this.radius;\n }\n else {\n this.centerWorld.copyFrom(this.center);\n this.radiusWorld = this.radius;\n }\n }\n /**\n * Tests if the bounding sphere is intersecting the frustum planes\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an intersection\n */\n isInFrustum(frustumPlanes) {\n const center = this.centerWorld;\n const radius = this.radiusWorld;\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(center) <= -radius) {\n return false;\n }\n }\n return true;\n }\n /**\n * Tests if the bounding sphere center is in between the frustum planes.\n * Used for optimistic fast inclusion.\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if the sphere center is in between the frustum planes\n */\n isCenterInFrustum(frustumPlanes) {\n const center = this.centerWorld;\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(center) < 0) {\n return false;\n }\n }\n return true;\n }\n /**\n * Tests if a point is inside the bounding sphere\n * @param point defines the point to test\n * @returns true if the point is inside the bounding sphere\n */\n intersectsPoint(point) {\n const squareDistance = Vector3.DistanceSquared(this.centerWorld, point);\n if (this.radiusWorld * this.radiusWorld < squareDistance) {\n return false;\n }\n return true;\n }\n // Statics\n /**\n * Checks if two sphere intersect\n * @param sphere0 sphere 0\n * @param sphere1 sphere 1\n * @returns true if the spheres intersect\n */\n static Intersects(sphere0, sphere1) {\n const squareDistance = Vector3.DistanceSquared(sphere0.centerWorld, sphere1.centerWorld);\n const radiusSum = sphere0.radiusWorld + sphere1.radiusWorld;\n if (radiusSum * radiusSum < squareDistance) {\n return false;\n }\n return true;\n }\n /**\n * Creates a sphere from a center and a radius\n * @param center The center\n * @param radius radius\n * @param matrix Optional worldMatrix\n * @returns The sphere\n */\n static CreateFromCenterAndRadius(center, radius, matrix) {\n this._TmpVector3[0].copyFrom(center);\n this._TmpVector3[1].copyFromFloats(0, 0, radius);\n this._TmpVector3[2].copyFrom(center);\n this._TmpVector3[0].addInPlace(this._TmpVector3[1]);\n this._TmpVector3[2].subtractInPlace(this._TmpVector3[1]);\n const sphere = new BoundingSphere(this._TmpVector3[0], this._TmpVector3[2]);\n if (matrix) {\n sphere._worldMatrix = matrix;\n }\n else {\n sphere._worldMatrix = Matrix.Identity();\n }\n return sphere;\n }\n }\n BoundingSphere._TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);\n\n const _result0 = { min: 0, max: 0 };\n const _result1 = { min: 0, max: 0 };\n const computeBoxExtents = (axis, box, result) => {\n const p = Vector3.Dot(box.centerWorld, axis);\n const r0 = Math.abs(Vector3.Dot(box.directions[0], axis)) * box.extendSize.x;\n const r1 = Math.abs(Vector3.Dot(box.directions[1], axis)) * box.extendSize.y;\n const r2 = Math.abs(Vector3.Dot(box.directions[2], axis)) * box.extendSize.z;\n const r = r0 + r1 + r2;\n result.min = p - r;\n result.max = p + r;\n };\n const axisOverlap = (axis, box0, box1) => {\n computeBoxExtents(axis, box0, _result0);\n computeBoxExtents(axis, box1, _result1);\n return !(_result0.min > _result1.max || _result1.min > _result0.max);\n };\n /**\n * Info for a bounding data of a mesh\n */\n class BoundingInfo {\n /**\n * Constructs bounding info\n * @param minimum min vector of the bounding box/sphere\n * @param maximum max vector of the bounding box/sphere\n * @param worldMatrix defines the new world matrix\n */\n constructor(minimum, maximum, worldMatrix) {\n this._isLocked = false;\n this.boundingBox = new BoundingBox(minimum, maximum, worldMatrix);\n this.boundingSphere = new BoundingSphere(minimum, maximum, worldMatrix);\n }\n /**\n * Recreates the entire bounding info from scratch as if we call the constructor in place\n * @param min defines the new minimum vector (in local space)\n * @param max defines the new maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n reConstruct(min, max, worldMatrix) {\n this.boundingBox.reConstruct(min, max, worldMatrix);\n this.boundingSphere.reConstruct(min, max, worldMatrix);\n }\n /**\n * min vector of the bounding box/sphere\n */\n get minimum() {\n return this.boundingBox.minimum;\n }\n /**\n * max vector of the bounding box/sphere\n */\n get maximum() {\n return this.boundingBox.maximum;\n }\n /**\n * If the info is locked and won't be updated to avoid perf overhead\n */\n get isLocked() {\n return this._isLocked;\n }\n set isLocked(value) {\n this._isLocked = value;\n }\n // Methods\n /**\n * Updates the bounding sphere and box\n * @param world world matrix to be used to update\n */\n update(world) {\n if (this._isLocked) {\n return;\n }\n this.boundingBox._update(world);\n this.boundingSphere._update(world);\n }\n /**\n * Recreate the bounding info to be centered around a specific point given a specific extend.\n * @param center New center of the bounding info\n * @param extend New extend of the bounding info\n * @returns the current bounding info\n */\n centerOn(center, extend) {\n const minimum = BoundingInfo._TmpVector3[0].copyFrom(center).subtractInPlace(extend);\n const maximum = BoundingInfo._TmpVector3[1].copyFrom(center).addInPlace(extend);\n this.boundingBox.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\n this.boundingSphere.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\n return this;\n }\n /**\n * Grows the bounding info to include the given point.\n * @param point The point that will be included in the current bounding info (in local space)\n * @returns the current bounding info\n */\n encapsulate(point) {\n const minimum = Vector3.Minimize(this.minimum, point);\n const maximum = Vector3.Maximize(this.maximum, point);\n this.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\n return this;\n }\n /**\n * Grows the bounding info to encapsulate the given bounding info.\n * @param toEncapsulate The bounding info that will be encapsulated in the current bounding info\n * @returns the current bounding info\n */\n encapsulateBoundingInfo(toEncapsulate) {\n const invw = TmpVectors.Matrix[0];\n this.boundingBox.getWorldMatrix().invertToRef(invw);\n const v = TmpVectors.Vector3[0];\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.minimumWorld, invw, v);\n this.encapsulate(v);\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.maximumWorld, invw, v);\n this.encapsulate(v);\n return this;\n }\n /**\n * Scale the current bounding info by applying a scale factor\n * @param factor defines the scale factor to apply\n * @returns the current bounding info\n */\n scale(factor) {\n this.boundingBox.scale(factor);\n this.boundingSphere.scale(factor);\n return this;\n }\n /**\n * Returns `true` if the bounding info is within the frustum defined by the passed array of planes.\n * @param frustumPlanes defines the frustum to test\n * @param strategy defines the strategy to use for the culling (default is BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD)\n * The different strategies available are:\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD most accurate but slower @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_STANDARD\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY faster but less accurate @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\n * @returns true if the bounding info is in the frustum planes\n */\n isInFrustum(frustumPlanes, strategy = 0) {\n const inclusionTest = strategy === 2 || strategy === 3;\n if (inclusionTest) {\n if (this.boundingSphere.isCenterInFrustum(frustumPlanes)) {\n return true;\n }\n }\n if (!this.boundingSphere.isInFrustum(frustumPlanes)) {\n return false;\n }\n const bSphereOnlyTest = strategy === 1 || strategy === 3;\n if (bSphereOnlyTest) {\n return true;\n }\n return this.boundingBox.isInFrustum(frustumPlanes);\n }\n /**\n * Gets the world distance between the min and max points of the bounding box\n */\n get diagonalLength() {\n const boundingBox = this.boundingBox;\n const diag = boundingBox.maximumWorld.subtractToRef(boundingBox.minimumWorld, BoundingInfo._TmpVector3[0]);\n return diag.length();\n }\n /**\n * Checks if a cullable object (mesh...) is in the camera frustum\n * Unlike isInFrustum this checks the full bounding box\n * @param frustumPlanes Camera near/planes\n * @returns true if the object is in frustum otherwise false\n */\n isCompletelyInFrustum(frustumPlanes) {\n return this.boundingBox.isCompletelyInFrustum(frustumPlanes);\n }\n /**\n * @internal\n */\n _checkCollision(collider) {\n return collider._canDoCollision(this.boundingSphere.centerWorld, this.boundingSphere.radiusWorld, this.boundingBox.minimumWorld, this.boundingBox.maximumWorld);\n }\n /**\n * Checks if a point is inside the bounding box and bounding sphere or the mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\n * @param point the point to check intersection with\n * @returns if the point intersects\n */\n intersectsPoint(point) {\n if (!this.boundingSphere.centerWorld) {\n return false;\n }\n if (!this.boundingSphere.intersectsPoint(point)) {\n return false;\n }\n if (!this.boundingBox.intersectsPoint(point)) {\n return false;\n }\n return true;\n }\n /**\n * Checks if another bounding info intersects the bounding box and bounding sphere or the mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\n * @param boundingInfo the bounding info to check intersection with\n * @param precise if the intersection should be done using OBB\n * @returns if the bounding info intersects\n */\n intersects(boundingInfo, precise) {\n if (!BoundingSphere.Intersects(this.boundingSphere, boundingInfo.boundingSphere)) {\n return false;\n }\n if (!BoundingBox.Intersects(this.boundingBox, boundingInfo.boundingBox)) {\n return false;\n }\n if (!precise) {\n return true;\n }\n const box0 = this.boundingBox;\n const box1 = boundingInfo.boundingBox;\n if (!axisOverlap(box0.directions[0], box0, box1)) {\n return false;\n }\n if (!axisOverlap(box0.directions[1], box0, box1)) {\n return false;\n }\n if (!axisOverlap(box0.directions[2], box0, box1)) {\n return false;\n }\n if (!axisOverlap(box1.directions[0], box0, box1)) {\n return false;\n }\n if (!axisOverlap(box1.directions[1], box0, box1)) {\n return false;\n }\n if (!axisOverlap(box1.directions[2], box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[0]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[1]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[2]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[0]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[1]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[2]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[0]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[1]), box0, box1)) {\n return false;\n }\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[2]), box0, box1)) {\n return false;\n }\n return true;\n }\n }\n BoundingInfo._TmpVector3 = ArrayTools.BuildArray(2, Vector3.Zero);\n\n // This helper class is only here so we can apply the nativeOverride decorator to functions.\n class MathHelpers {\n static extractMinAndMaxIndexed(positions, indices, indexStart, indexCount, minimum, maximum) {\n for (let index = indexStart; index < indexStart + indexCount; index++) {\n const offset = indices[index] * 3;\n const x = positions[offset];\n const y = positions[offset + 1];\n const z = positions[offset + 2];\n minimum.minimizeInPlaceFromFloats(x, y, z);\n maximum.maximizeInPlaceFromFloats(x, y, z);\n }\n }\n static extractMinAndMax(positions, start, count, stride, minimum, maximum) {\n for (let index = start, offset = start * stride; index < start + count; index++, offset += stride) {\n const x = positions[offset];\n const y = positions[offset + 1];\n const z = positions[offset + 2];\n minimum.minimizeInPlaceFromFloats(x, y, z);\n maximum.maximizeInPlaceFromFloats(x, y, z);\n }\n }\n }\n __decorate$1([\n nativeOverride.filter((...[positions, indices]) => !Array.isArray(positions) && !Array.isArray(indices))\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ], MathHelpers, \"extractMinAndMaxIndexed\", null);\n __decorate$1([\n nativeOverride.filter((...[positions]) => !Array.isArray(positions))\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ], MathHelpers, \"extractMinAndMax\", null);\n /**\n * Extracts minimum and maximum values from a list of indexed positions\n * @param positions defines the positions to use\n * @param indices defines the indices to the positions\n * @param indexStart defines the start index\n * @param indexCount defines the end index\n * @param bias defines bias value to add to the result\n * @returns minimum and maximum values\n */\n function extractMinAndMaxIndexed(positions, indices, indexStart, indexCount, bias = null) {\n const minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n const maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n MathHelpers.extractMinAndMaxIndexed(positions, indices, indexStart, indexCount, minimum, maximum);\n if (bias) {\n minimum.x -= minimum.x * bias.x + bias.y;\n minimum.y -= minimum.y * bias.x + bias.y;\n minimum.z -= minimum.z * bias.x + bias.y;\n maximum.x += maximum.x * bias.x + bias.y;\n maximum.y += maximum.y * bias.x + bias.y;\n maximum.z += maximum.z * bias.x + bias.y;\n }\n return {\n minimum: minimum,\n maximum: maximum,\n };\n }\n /**\n * Extracts minimum and maximum values from a list of positions\n * @param positions defines the positions to use\n * @param start defines the start index in the positions array\n * @param count defines the number of positions to handle\n * @param bias defines bias value to add to the result\n * @param stride defines the stride size to use (distance between two positions in the positions array)\n * @returns minimum and maximum values\n */\n function extractMinAndMax(positions, start, count, bias = null, stride) {\n const minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n const maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n if (!stride) {\n stride = 3;\n }\n MathHelpers.extractMinAndMax(positions, start, count, stride, minimum, maximum);\n if (bias) {\n minimum.x -= minimum.x * bias.x + bias.y;\n minimum.y -= minimum.y * bias.x + bias.y;\n minimum.z -= minimum.z * bias.x + bias.y;\n maximum.x += maximum.x * bias.x + bias.y;\n maximum.y += maximum.y * bias.x + bias.y;\n maximum.z += maximum.z * bias.x + bias.y;\n }\n return {\n minimum: minimum,\n maximum: maximum,\n };\n }\n\n /**\n * Defines a subdivision inside a mesh\n */\n class SubMesh {\n /**\n * Gets material defines used by the effect associated to the sub mesh\n */\n get materialDefines() {\n var _a;\n return this._mainDrawWrapperOverride ? this._mainDrawWrapperOverride.defines : (_a = this._getDrawWrapper()) === null || _a === void 0 ? void 0 : _a.defines;\n }\n /**\n * Sets material defines used by the effect associated to the sub mesh\n */\n set materialDefines(defines) {\n var _a;\n const drawWrapper = (_a = this._mainDrawWrapperOverride) !== null && _a !== void 0 ? _a : this._getDrawWrapper(undefined, true);\n drawWrapper.defines = defines;\n }\n /**\n * @internal\n */\n _getDrawWrapper(passId, createIfNotExisting = false) {\n passId = passId !== null && passId !== void 0 ? passId : this._engine.currentRenderPassId;\n let drawWrapper = this._drawWrappers[passId];\n if (!drawWrapper && createIfNotExisting) {\n this._drawWrappers[passId] = drawWrapper = new DrawWrapper(this._mesh.getScene().getEngine());\n }\n return drawWrapper;\n }\n /**\n * @internal\n */\n _removeDrawWrapper(passId, disposeWrapper = true) {\n var _a;\n if (disposeWrapper) {\n (_a = this._drawWrappers[passId]) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n this._drawWrappers[passId] = undefined;\n }\n /**\n * Gets associated (main) effect (possibly the effect override if defined)\n */\n get effect() {\n var _a, _b;\n return this._mainDrawWrapperOverride ? this._mainDrawWrapperOverride.effect : (_b = (_a = this._getDrawWrapper()) === null || _a === void 0 ? void 0 : _a.effect) !== null && _b !== void 0 ? _b : null;\n }\n /** @internal */\n get _drawWrapper() {\n var _a;\n return (_a = this._mainDrawWrapperOverride) !== null && _a !== void 0 ? _a : this._getDrawWrapper(undefined, true);\n }\n /** @internal */\n get _drawWrapperOverride() {\n return this._mainDrawWrapperOverride;\n }\n /**\n * @internal\n */\n _setMainDrawWrapperOverride(wrapper) {\n this._mainDrawWrapperOverride = wrapper;\n }\n /**\n * Sets associated effect (effect used to render this submesh)\n * @param effect defines the effect to associate with\n * @param defines defines the set of defines used to compile this effect\n * @param materialContext material context associated to the effect\n * @param resetContext true to reset the draw context\n */\n setEffect(effect, defines = null, materialContext, resetContext = true) {\n const drawWrapper = this._drawWrapper;\n drawWrapper.setEffect(effect, defines, resetContext);\n if (materialContext !== undefined) {\n drawWrapper.materialContext = materialContext;\n }\n if (!effect) {\n drawWrapper.defines = null;\n drawWrapper.materialContext = undefined;\n }\n }\n /**\n * Resets the draw wrappers cache\n * @param passId If provided, releases only the draw wrapper corresponding to this render pass id\n */\n resetDrawCache(passId) {\n if (this._drawWrappers) {\n if (passId !== undefined) {\n this._removeDrawWrapper(passId);\n return;\n }\n else {\n for (const drawWrapper of this._drawWrappers) {\n drawWrapper === null || drawWrapper === void 0 ? void 0 : drawWrapper.dispose();\n }\n }\n }\n this._drawWrappers = [];\n }\n /**\n * Add a new submesh to a mesh\n * @param materialIndex defines the material index to use\n * @param verticesStart defines vertex index start\n * @param verticesCount defines vertices count\n * @param indexStart defines index start\n * @param indexCount defines indices count\n * @param mesh defines the parent mesh\n * @param renderingMesh defines an optional rendering mesh\n * @param createBoundingBox defines if bounding box should be created for this submesh\n * @returns the new submesh\n */\n static AddToMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox = true) {\n return new SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox);\n }\n /**\n * Creates a new submesh\n * @param materialIndex defines the material index to use\n * @param verticesStart defines vertex index start\n * @param verticesCount defines vertices count\n * @param indexStart defines index start\n * @param indexCount defines indices count\n * @param mesh defines the parent mesh\n * @param renderingMesh defines an optional rendering mesh\n * @param createBoundingBox defines if bounding box should be created for this submesh\n * @param addToMesh defines a boolean indicating that the submesh must be added to the mesh.subMeshes array (true by default)\n */\n constructor(\n /** the material index to use */\n materialIndex, \n /** vertex index start */\n verticesStart, \n /** vertices count */\n verticesCount, \n /** index start */\n indexStart, \n /** indices count */\n indexCount, mesh, renderingMesh, createBoundingBox = true, addToMesh = true) {\n this.materialIndex = materialIndex;\n this.verticesStart = verticesStart;\n this.verticesCount = verticesCount;\n this.indexStart = indexStart;\n this.indexCount = indexCount;\n this._mainDrawWrapperOverride = null;\n /** @internal */\n this._linesIndexCount = 0;\n this._linesIndexBuffer = null;\n /** @internal */\n this._lastColliderWorldVertices = null;\n /** @internal */\n this._lastColliderTransformMatrix = null;\n /** @internal */\n this._wasDispatched = false;\n /** @internal */\n this._renderId = 0;\n /** @internal */\n this._alphaIndex = 0;\n /** @internal */\n this._distanceToCamera = 0;\n this._currentMaterial = null;\n this._mesh = mesh;\n this._renderingMesh = renderingMesh || mesh;\n if (addToMesh) {\n mesh.subMeshes.push(this);\n }\n this._engine = this._mesh.getScene().getEngine();\n this.resetDrawCache();\n this._trianglePlanes = [];\n this._id = mesh.subMeshes.length - 1;\n if (createBoundingBox) {\n this.refreshBoundingInfo();\n mesh.computeWorldMatrix(true);\n }\n }\n /**\n * Returns true if this submesh covers the entire parent mesh\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n get IsGlobal() {\n return this.verticesStart === 0 && this.verticesCount === this._mesh.getTotalVertices() && this.indexStart === 0 && this.indexCount === this._mesh.getTotalIndices();\n }\n /**\n * Returns the submesh BoundingInfo object\n * @returns current bounding info (or mesh's one if the submesh is global)\n */\n getBoundingInfo() {\n if (this.IsGlobal) {\n return this._mesh.getBoundingInfo();\n }\n return this._boundingInfo;\n }\n /**\n * Sets the submesh BoundingInfo\n * @param boundingInfo defines the new bounding info to use\n * @returns the SubMesh\n */\n setBoundingInfo(boundingInfo) {\n this._boundingInfo = boundingInfo;\n return this;\n }\n /**\n * Returns the mesh of the current submesh\n * @returns the parent mesh\n */\n getMesh() {\n return this._mesh;\n }\n /**\n * Returns the rendering mesh of the submesh\n * @returns the rendering mesh (could be different from parent mesh)\n */\n getRenderingMesh() {\n return this._renderingMesh;\n }\n /**\n * Returns the replacement mesh of the submesh\n * @returns the replacement mesh (could be different from parent mesh)\n */\n getReplacementMesh() {\n return this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : null;\n }\n /**\n * Returns the effective mesh of the submesh\n * @returns the effective mesh (could be different from parent mesh)\n */\n getEffectiveMesh() {\n const replacementMesh = this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : null;\n return replacementMesh ? replacementMesh : this._renderingMesh;\n }\n /**\n * Returns the submesh material\n * @param getDefaultMaterial Defines whether or not to get the default material if nothing has been defined.\n * @returns null or the current material\n */\n getMaterial(getDefaultMaterial = true) {\n var _a;\n const rootMaterial = (_a = this._renderingMesh.getMaterialForRenderPass(this._engine.currentRenderPassId)) !== null && _a !== void 0 ? _a : this._renderingMesh.material;\n if (!rootMaterial) {\n return getDefaultMaterial ? this._mesh.getScene().defaultMaterial : null;\n }\n else if (this._isMultiMaterial(rootMaterial)) {\n const effectiveMaterial = rootMaterial.getSubMaterial(this.materialIndex);\n if (this._currentMaterial !== effectiveMaterial) {\n this._currentMaterial = effectiveMaterial;\n this.resetDrawCache();\n }\n return effectiveMaterial;\n }\n return rootMaterial;\n }\n _isMultiMaterial(material) {\n return material.getSubMaterial !== undefined;\n }\n // Methods\n /**\n * Sets a new updated BoundingInfo object to the submesh\n * @param data defines an optional position array to use to determine the bounding info\n * @returns the SubMesh\n */\n refreshBoundingInfo(data = null) {\n this._lastColliderWorldVertices = null;\n if (this.IsGlobal || !this._renderingMesh || !this._renderingMesh.geometry) {\n return this;\n }\n if (!data) {\n data = this._renderingMesh.getVerticesData(VertexBuffer.PositionKind);\n }\n if (!data) {\n this._boundingInfo = this._mesh.getBoundingInfo();\n return this;\n }\n const indices = this._renderingMesh.getIndices();\n let extend;\n //is this the only submesh?\n if (this.indexStart === 0 && this.indexCount === indices.length) {\n const boundingInfo = this._renderingMesh.getBoundingInfo();\n //the rendering mesh's bounding info can be used, it is the standard submesh for all indices.\n extend = { minimum: boundingInfo.minimum.clone(), maximum: boundingInfo.maximum.clone() };\n }\n else {\n extend = extractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount, this._renderingMesh.geometry.boundingBias);\n }\n if (this._boundingInfo) {\n this._boundingInfo.reConstruct(extend.minimum, extend.maximum);\n }\n else {\n this._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);\n }\n return this;\n }\n /**\n * @internal\n */\n _checkCollision(collider) {\n const boundingInfo = this.getBoundingInfo();\n return boundingInfo._checkCollision(collider);\n }\n /**\n * Updates the submesh BoundingInfo\n * @param world defines the world matrix to use to update the bounding info\n * @returns the submesh\n */\n updateBoundingInfo(world) {\n let boundingInfo = this.getBoundingInfo();\n if (!boundingInfo) {\n this.refreshBoundingInfo();\n boundingInfo = this.getBoundingInfo();\n }\n if (boundingInfo) {\n boundingInfo.update(world);\n }\n return this;\n }\n /**\n * True is the submesh bounding box intersects the frustum defined by the passed array of planes.\n * @param frustumPlanes defines the frustum planes\n * @returns true if the submesh is intersecting with the frustum\n */\n isInFrustum(frustumPlanes) {\n const boundingInfo = this.getBoundingInfo();\n if (!boundingInfo) {\n return false;\n }\n return boundingInfo.isInFrustum(frustumPlanes, this._mesh.cullingStrategy);\n }\n /**\n * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes\n * @param frustumPlanes defines the frustum planes\n * @returns true if the submesh is inside the frustum\n */\n isCompletelyInFrustum(frustumPlanes) {\n const boundingInfo = this.getBoundingInfo();\n if (!boundingInfo) {\n return false;\n }\n return boundingInfo.isCompletelyInFrustum(frustumPlanes);\n }\n /**\n * Renders the submesh\n * @param enableAlphaMode defines if alpha needs to be used\n * @returns the submesh\n */\n render(enableAlphaMode) {\n this._renderingMesh.render(this, enableAlphaMode, this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : undefined);\n return this;\n }\n /**\n * @internal\n */\n _getLinesIndexBuffer(indices, engine) {\n if (!this._linesIndexBuffer) {\n const linesIndices = [];\n for (let index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {\n linesIndices.push(indices[index], indices[index + 1], indices[index + 1], indices[index + 2], indices[index + 2], indices[index]);\n }\n this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);\n this._linesIndexCount = linesIndices.length;\n }\n return this._linesIndexBuffer;\n }\n /**\n * Checks if the submesh intersects with a ray\n * @param ray defines the ray to test\n * @returns true is the passed ray intersects the submesh bounding box\n */\n canIntersects(ray) {\n const boundingInfo = this.getBoundingInfo();\n if (!boundingInfo) {\n return false;\n }\n return ray.intersectsBox(boundingInfo.boundingBox);\n }\n /**\n * Intersects current submesh with a ray\n * @param ray defines the ray to test\n * @param positions defines mesh's positions array\n * @param indices defines mesh's indices array\n * @param fastCheck defines if the first intersection will be used (and not the closest)\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @returns intersection info or null if no intersection\n */\n intersects(ray, positions, indices, fastCheck, trianglePredicate) {\n const material = this.getMaterial();\n if (!material) {\n return null;\n }\n let step = 3;\n let checkStopper = false;\n switch (material.fillMode) {\n case 3:\n case 5:\n case 6:\n case 8:\n return null;\n case 7:\n step = 1;\n checkStopper = true;\n break;\n }\n // LineMesh first as it's also a Mesh...\n if (material.fillMode === 4) {\n // Check if mesh is unindexed\n if (!indices.length) {\n return this._intersectUnIndexedLines(ray, positions, indices, this._mesh.intersectionThreshold, fastCheck);\n }\n return this._intersectLines(ray, positions, indices, this._mesh.intersectionThreshold, fastCheck);\n }\n else {\n // Check if mesh is unindexed\n if (!indices.length && this._mesh._unIndexed) {\n return this._intersectUnIndexedTriangles(ray, positions, indices, fastCheck, trianglePredicate);\n }\n return this._intersectTriangles(ray, positions, indices, step, checkStopper, fastCheck, trianglePredicate);\n }\n }\n /**\n * @internal\n */\n _intersectLines(ray, positions, indices, intersectionThreshold, fastCheck) {\n let intersectInfo = null;\n // Line test\n for (let index = this.indexStart; index < this.indexStart + this.indexCount; index += 2) {\n const p0 = positions[indices[index]];\n const p1 = positions[indices[index + 1]];\n const length = ray.intersectionSegment(p0, p1, intersectionThreshold);\n if (length < 0) {\n continue;\n }\n if (fastCheck || !intersectInfo || length < intersectInfo.distance) {\n intersectInfo = new IntersectionInfo(null, null, length);\n intersectInfo.faceId = index / 2;\n if (fastCheck) {\n break;\n }\n }\n }\n return intersectInfo;\n }\n /**\n * @internal\n */\n _intersectUnIndexedLines(ray, positions, indices, intersectionThreshold, fastCheck) {\n let intersectInfo = null;\n // Line test\n for (let index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 2) {\n const p0 = positions[index];\n const p1 = positions[index + 1];\n const length = ray.intersectionSegment(p0, p1, intersectionThreshold);\n if (length < 0) {\n continue;\n }\n if (fastCheck || !intersectInfo || length < intersectInfo.distance) {\n intersectInfo = new IntersectionInfo(null, null, length);\n intersectInfo.faceId = index / 2;\n if (fastCheck) {\n break;\n }\n }\n }\n return intersectInfo;\n }\n /**\n * @internal\n */\n _intersectTriangles(ray, positions, indices, step, checkStopper, fastCheck, trianglePredicate) {\n let intersectInfo = null;\n // Triangles test\n let faceId = -1;\n for (let index = this.indexStart; index < this.indexStart + this.indexCount - (3 - step); index += step) {\n faceId++;\n const indexA = indices[index];\n const indexB = indices[index + 1];\n const indexC = indices[index + 2];\n if (checkStopper && indexC === 0xffffffff) {\n index += 2;\n continue;\n }\n const p0 = positions[indexA];\n const p1 = positions[indexB];\n const p2 = positions[indexC];\n // stay defensive and don't check against undefined positions.\n if (!p0 || !p1 || !p2) {\n continue;\n }\n if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray, indexA, indexB, indexC)) {\n continue;\n }\n const currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);\n if (currentIntersectInfo) {\n if (currentIntersectInfo.distance < 0) {\n continue;\n }\n if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {\n intersectInfo = currentIntersectInfo;\n intersectInfo.faceId = faceId;\n if (fastCheck) {\n break;\n }\n }\n }\n }\n return intersectInfo;\n }\n /**\n * @internal\n */\n _intersectUnIndexedTriangles(ray, positions, indices, fastCheck, trianglePredicate) {\n let intersectInfo = null;\n // Triangles test\n for (let index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 3) {\n const p0 = positions[index];\n const p1 = positions[index + 1];\n const p2 = positions[index + 2];\n if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray, -1, -1, -1)) {\n continue;\n }\n const currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);\n if (currentIntersectInfo) {\n if (currentIntersectInfo.distance < 0) {\n continue;\n }\n if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {\n intersectInfo = currentIntersectInfo;\n intersectInfo.faceId = index / 3;\n if (fastCheck) {\n break;\n }\n }\n }\n }\n return intersectInfo;\n }\n /** @internal */\n _rebuild() {\n if (this._linesIndexBuffer) {\n this._linesIndexBuffer = null;\n }\n }\n // Clone\n /**\n * Creates a new submesh from the passed mesh\n * @param newMesh defines the new hosting mesh\n * @param newRenderingMesh defines an optional rendering mesh\n * @returns the new submesh\n */\n clone(newMesh, newRenderingMesh) {\n const result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);\n if (!this.IsGlobal) {\n const boundingInfo = this.getBoundingInfo();\n if (!boundingInfo) {\n return result;\n }\n result._boundingInfo = new BoundingInfo(boundingInfo.minimum, boundingInfo.maximum);\n }\n return result;\n }\n // Dispose\n /**\n * Release associated resources\n */\n dispose() {\n if (this._linesIndexBuffer) {\n this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer);\n this._linesIndexBuffer = null;\n }\n // Remove from mesh\n const index = this._mesh.subMeshes.indexOf(this);\n this._mesh.subMeshes.splice(index, 1);\n this.resetDrawCache();\n }\n /**\n * Gets the class name\n * @returns the string \"SubMesh\".\n */\n getClassName() {\n return \"SubMesh\";\n }\n // Statics\n /**\n * Creates a new submesh from indices data\n * @param materialIndex the index of the main mesh material\n * @param startIndex the index where to start the copy in the mesh indices array\n * @param indexCount the number of indices to copy then from the startIndex\n * @param mesh the main mesh to create the submesh from\n * @param renderingMesh the optional rendering mesh\n * @param createBoundingBox defines if bounding box should be created for this submesh\n * @returns a new submesh\n */\n static CreateFromIndices(materialIndex, startIndex, indexCount, mesh, renderingMesh, createBoundingBox = true) {\n let minVertexIndex = Number.MAX_VALUE;\n let maxVertexIndex = -Number.MAX_VALUE;\n const whatWillRender = renderingMesh || mesh;\n const indices = whatWillRender.getIndices();\n for (let index = startIndex; index < startIndex + indexCount; index++) {\n const vertexIndex = indices[index];\n if (vertexIndex < minVertexIndex) {\n minVertexIndex = vertexIndex;\n }\n if (vertexIndex > maxVertexIndex) {\n maxVertexIndex = vertexIndex;\n }\n }\n return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh, createBoundingBox);\n }\n }\n\n /** Class used to attach material info to sub section of a vertex data class */\n class VertexDataMaterialInfo {\n }\n /**\n * This class contains the various kinds of data on every vertex of a mesh used in determining its shape and appearance\n */\n class VertexData {\n constructor() {\n this._applyTo = makeSyncFunction(this._applyToCoroutine.bind(this));\n }\n /**\n * Uses the passed data array to set the set the values for the specified kind of data\n * @param data a linear array of floating numbers\n * @param kind the type of data that is being set, eg positions, colors etc\n */\n set(data, kind) {\n if (!data.length) {\n Logger.Warn(`Setting vertex data kind '${kind}' with an empty array`);\n }\n switch (kind) {\n case VertexBuffer.PositionKind:\n this.positions = data;\n break;\n case VertexBuffer.NormalKind:\n this.normals = data;\n break;\n case VertexBuffer.TangentKind:\n this.tangents = data;\n break;\n case VertexBuffer.UVKind:\n this.uvs = data;\n break;\n case VertexBuffer.UV2Kind:\n this.uvs2 = data;\n break;\n case VertexBuffer.UV3Kind:\n this.uvs3 = data;\n break;\n case VertexBuffer.UV4Kind:\n this.uvs4 = data;\n break;\n case VertexBuffer.UV5Kind:\n this.uvs5 = data;\n break;\n case VertexBuffer.UV6Kind:\n this.uvs6 = data;\n break;\n case VertexBuffer.ColorKind:\n this.colors = data;\n break;\n case VertexBuffer.MatricesIndicesKind:\n this.matricesIndices = data;\n break;\n case VertexBuffer.MatricesWeightsKind:\n this.matricesWeights = data;\n break;\n case VertexBuffer.MatricesIndicesExtraKind:\n this.matricesIndicesExtra = data;\n break;\n case VertexBuffer.MatricesWeightsExtraKind:\n this.matricesWeightsExtra = data;\n break;\n }\n }\n /**\n * Associates the vertexData to the passed Mesh.\n * Sets it as updatable or not (default `false`)\n * @param mesh the mesh the vertexData is applied to\n * @param updatable when used and having the value true allows new data to update the vertexData\n * @returns the VertexData\n */\n applyToMesh(mesh, updatable) {\n this._applyTo(mesh, updatable, false);\n return this;\n }\n /**\n * Associates the vertexData to the passed Geometry.\n * Sets it as updatable or not (default `false`)\n * @param geometry the geometry the vertexData is applied to\n * @param updatable when used and having the value true allows new data to update the vertexData\n * @returns VertexData\n */\n applyToGeometry(geometry, updatable) {\n this._applyTo(geometry, updatable, false);\n return this;\n }\n /**\n * Updates the associated mesh\n * @param mesh the mesh to be updated\n * @returns VertexData\n */\n updateMesh(mesh) {\n this._update(mesh);\n return this;\n }\n /**\n * Updates the associated geometry\n * @param geometry the geometry to be updated\n * @returns VertexData.\n */\n updateGeometry(geometry) {\n this._update(geometry);\n return this;\n }\n /**\n * @internal\n */\n *_applyToCoroutine(meshOrGeometry, updatable = false, isAsync) {\n if (this.positions) {\n meshOrGeometry.setVerticesData(VertexBuffer.PositionKind, this.positions, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.normals) {\n meshOrGeometry.setVerticesData(VertexBuffer.NormalKind, this.normals, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.tangents) {\n meshOrGeometry.setVerticesData(VertexBuffer.TangentKind, this.tangents, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.uvs) {\n meshOrGeometry.setVerticesData(VertexBuffer.UVKind, this.uvs, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.uvs2) {\n meshOrGeometry.setVerticesData(VertexBuffer.UV2Kind, this.uvs2, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.uvs3) {\n meshOrGeometry.setVerticesData(VertexBuffer.UV3Kind, this.uvs3, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.uvs4) {\n meshOrGeometry.setVerticesData(VertexBuffer.UV4Kind, this.uvs4, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.uvs5) {\n meshOrGeometry.setVerticesData(VertexBuffer.UV5Kind, this.uvs5, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.uvs6) {\n meshOrGeometry.setVerticesData(VertexBuffer.UV6Kind, this.uvs6, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.colors) {\n meshOrGeometry.setVerticesData(VertexBuffer.ColorKind, this.colors, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.matricesIndices) {\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesIndicesKind, this.matricesIndices, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.matricesWeights) {\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.matricesIndicesExtra) {\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.matricesWeightsExtra) {\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updatable);\n if (isAsync) {\n yield;\n }\n }\n if (this.indices) {\n meshOrGeometry.setIndices(this.indices, null, updatable);\n if (isAsync) {\n yield;\n }\n }\n else {\n meshOrGeometry.setIndices([], null);\n }\n if (meshOrGeometry.subMeshes && this.materialInfos && this.materialInfos.length > 1) {\n const mesh = meshOrGeometry;\n mesh.subMeshes = [];\n for (const matInfo of this.materialInfos) {\n new SubMesh(matInfo.materialIndex, matInfo.verticesStart, matInfo.verticesCount, matInfo.indexStart, matInfo.indexCount, mesh);\n }\n }\n return this;\n }\n _update(meshOrGeometry, updateExtends, makeItUnique) {\n if (this.positions) {\n meshOrGeometry.updateVerticesData(VertexBuffer.PositionKind, this.positions, updateExtends, makeItUnique);\n }\n if (this.normals) {\n meshOrGeometry.updateVerticesData(VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);\n }\n if (this.tangents) {\n meshOrGeometry.updateVerticesData(VertexBuffer.TangentKind, this.tangents, updateExtends, makeItUnique);\n }\n if (this.uvs) {\n meshOrGeometry.updateVerticesData(VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);\n }\n if (this.uvs2) {\n meshOrGeometry.updateVerticesData(VertexBuffer.UV2Kind, this.uvs2, updateExtends, makeItUnique);\n }\n if (this.uvs3) {\n meshOrGeometry.updateVerticesData(VertexBuffer.UV3Kind, this.uvs3, updateExtends, makeItUnique);\n }\n if (this.uvs4) {\n meshOrGeometry.updateVerticesData(VertexBuffer.UV4Kind, this.uvs4, updateExtends, makeItUnique);\n }\n if (this.uvs5) {\n meshOrGeometry.updateVerticesData(VertexBuffer.UV5Kind, this.uvs5, updateExtends, makeItUnique);\n }\n if (this.uvs6) {\n meshOrGeometry.updateVerticesData(VertexBuffer.UV6Kind, this.uvs6, updateExtends, makeItUnique);\n }\n if (this.colors) {\n meshOrGeometry.updateVerticesData(VertexBuffer.ColorKind, this.colors, updateExtends, makeItUnique);\n }\n if (this.matricesIndices) {\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesIndicesKind, this.matricesIndices, updateExtends, makeItUnique);\n }\n if (this.matricesWeights) {\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);\n }\n if (this.matricesIndicesExtra) {\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updateExtends, makeItUnique);\n }\n if (this.matricesWeightsExtra) {\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updateExtends, makeItUnique);\n }\n if (this.indices) {\n meshOrGeometry.setIndices(this.indices, null);\n }\n return this;\n }\n static _TransformVector3Coordinates(coordinates, transformation, offset = 0, length = coordinates.length) {\n const coordinate = TmpVectors.Vector3[0];\n const transformedCoordinate = TmpVectors.Vector3[1];\n for (let index = offset; index < offset + length; index += 3) {\n Vector3.FromArrayToRef(coordinates, index, coordinate);\n Vector3.TransformCoordinatesToRef(coordinate, transformation, transformedCoordinate);\n coordinates[index] = transformedCoordinate.x;\n coordinates[index + 1] = transformedCoordinate.y;\n coordinates[index + 2] = transformedCoordinate.z;\n }\n }\n static _TransformVector3Normals(normals, transformation, offset = 0, length = normals.length) {\n const normal = TmpVectors.Vector3[0];\n const transformedNormal = TmpVectors.Vector3[1];\n for (let index = offset; index < offset + length; index += 3) {\n Vector3.FromArrayToRef(normals, index, normal);\n Vector3.TransformNormalToRef(normal, transformation, transformedNormal);\n normals[index] = transformedNormal.x;\n normals[index + 1] = transformedNormal.y;\n normals[index + 2] = transformedNormal.z;\n }\n }\n static _TransformVector4Normals(normals, transformation, offset = 0, length = normals.length) {\n const normal = TmpVectors.Vector4[0];\n const transformedNormal = TmpVectors.Vector4[1];\n for (let index = offset; index < offset + length; index += 4) {\n Vector4.FromArrayToRef(normals, index, normal);\n Vector4.TransformNormalToRef(normal, transformation, transformedNormal);\n normals[index] = transformedNormal.x;\n normals[index + 1] = transformedNormal.y;\n normals[index + 2] = transformedNormal.z;\n normals[index + 3] = transformedNormal.w;\n }\n }\n static _FlipFaces(indices, offset = 0, length = indices.length) {\n for (let index = offset; index < offset + length; index += 3) {\n const tmp = indices[index + 1];\n indices[index + 1] = indices[index + 2];\n indices[index + 2] = tmp;\n }\n }\n /**\n * Transforms each position and each normal of the vertexData according to the passed Matrix\n * @param matrix the transforming matrix\n * @returns the VertexData\n */\n transform(matrix) {\n const flip = matrix.determinant() < 0;\n if (this.positions) {\n VertexData._TransformVector3Coordinates(this.positions, matrix);\n }\n if (this.normals) {\n VertexData._TransformVector3Normals(this.normals, matrix);\n }\n if (this.tangents) {\n VertexData._TransformVector4Normals(this.tangents, matrix);\n }\n if (flip && this.indices) {\n VertexData._FlipFaces(this.indices);\n }\n return this;\n }\n /**\n * Generates an array of vertex data where each vertex data only has one material info\n * @returns An array of VertexData\n */\n splitBasedOnMaterialID() {\n if (!this.materialInfos || this.materialInfos.length < 2) {\n return [this];\n }\n const result = new Array();\n for (const materialInfo of this.materialInfos) {\n const vertexData = new VertexData();\n if (this.positions) {\n vertexData.positions = this.positions.slice(materialInfo.verticesStart * 3, (materialInfo.verticesCount + materialInfo.verticesStart) * 3);\n }\n if (this.normals) {\n vertexData.normals = this.normals.slice(materialInfo.verticesStart * 3, (materialInfo.verticesCount + materialInfo.verticesStart) * 3);\n }\n if (this.tangents) {\n vertexData.tangents = this.tangents.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\n }\n if (this.colors) {\n vertexData.colors = this.colors.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\n }\n if (this.uvs) {\n vertexData.uvs = this.uvs.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\n }\n if (this.uvs2) {\n vertexData.uvs2 = this.uvs2.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\n }\n if (this.uvs3) {\n vertexData.uvs3 = this.uvs3.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\n }\n if (this.uvs4) {\n vertexData.uvs4 = this.uvs4.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\n }\n if (this.uvs5) {\n vertexData.uvs5 = this.uvs5.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\n }\n if (this.uvs6) {\n vertexData.uvs6 = this.uvs6.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\n }\n if (this.matricesIndices) {\n vertexData.matricesIndices = this.matricesIndices.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\n }\n if (this.matricesIndicesExtra) {\n vertexData.matricesIndicesExtra = this.matricesIndicesExtra.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\n }\n if (this.matricesWeights) {\n vertexData.matricesWeights = this.matricesWeights.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\n }\n if (this.matricesWeightsExtra) {\n vertexData.matricesWeightsExtra = this.matricesWeightsExtra.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\n }\n if (this.indices) {\n vertexData.indices = [];\n for (let index = materialInfo.indexStart; index < materialInfo.indexStart + materialInfo.indexCount; index++) {\n vertexData.indices.push(this.indices[index] - materialInfo.verticesStart);\n }\n }\n const newMaterialInfo = new VertexDataMaterialInfo();\n newMaterialInfo.indexStart = 0;\n newMaterialInfo.indexCount = vertexData.indices ? vertexData.indices.length : 0;\n newMaterialInfo.materialIndex = materialInfo.materialIndex;\n newMaterialInfo.verticesStart = 0;\n newMaterialInfo.verticesCount = (vertexData.positions ? vertexData.positions.length : 0) / 3;\n vertexData.materialInfos = [newMaterialInfo];\n result.push(vertexData);\n }\n return result;\n }\n /**\n * Merges the passed VertexData into the current one\n * @param others the VertexData to be merged into the current one\n * @param use32BitsIndices defines a boolean indicating if indices must be store in a 32 bits array\n * @param forceCloneIndices defines a boolean indicating if indices are forced to be cloned\n * @param mergeMaterialIds defines a boolean indicating if we need to merge the material infos\n * @param enableCompletion defines a boolean indicating if the vertex data should be completed to be compatible\n * @returns the modified VertexData\n */\n merge(others, use32BitsIndices = false, forceCloneIndices = false, mergeMaterialIds = false, enableCompletion = false) {\n const vertexDatas = Array.isArray(others)\n ? others.map((other) => {\n return { vertexData: other };\n })\n : [{ vertexData: others }];\n return runCoroutineSync(this._mergeCoroutine(undefined, vertexDatas, use32BitsIndices, false, forceCloneIndices, mergeMaterialIds, enableCompletion));\n }\n /**\n * @internal\n */\n *_mergeCoroutine(transform, vertexDatas, use32BitsIndices = false, isAsync, forceCloneIndices, mergeMaterialIds = false, enableCompletion = false) {\n var _a, _b, _c, _d;\n this._validate();\n let others = vertexDatas.map((vertexData) => vertexData.vertexData);\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let root = this;\n for (const other of others) {\n if (!other) {\n continue;\n }\n other._validate();\n if (!enableCompletion) {\n if (!this.normals !== !other.normals ||\n !this.tangents !== !other.tangents ||\n !this.uvs !== !other.uvs ||\n !this.uvs2 !== !other.uvs2 ||\n !this.uvs3 !== !other.uvs3 ||\n !this.uvs4 !== !other.uvs4 ||\n !this.uvs5 !== !other.uvs5 ||\n !this.uvs6 !== !other.uvs6 ||\n !this.colors !== !other.colors ||\n !this.matricesIndices !== !other.matricesIndices ||\n !this.matricesWeights !== !other.matricesWeights ||\n !this.matricesIndicesExtra !== !other.matricesIndicesExtra ||\n !this.matricesWeightsExtra !== !other.matricesWeightsExtra) {\n throw new Error(\"Cannot merge vertex data that do not have the same set of attributes\");\n }\n }\n else {\n if (!this.normals !== !other.normals) {\n if (!this.normals) {\n this.normals = Array.from(other.normals);\n }\n else {\n other.normals = Array.from(this.normals);\n }\n }\n if (!this.tangents !== !other.tangents) {\n if (!this.tangents) {\n this.tangents = Array.from(other.tangents);\n }\n else {\n other.tangents = Array.from(this.tangents);\n }\n }\n if (!this.uvs !== !other.uvs) {\n if (!this.uvs) {\n this.uvs = Array.from(other.uvs);\n }\n else {\n other.uvs = Array.from(this.uvs);\n }\n }\n if (!this.uvs2 !== !other.uvs2) {\n if (!this.uvs2) {\n this.uvs2 = Array.from(other.uvs2);\n }\n else {\n other.uvs2 = Array.from(this.uvs2);\n }\n }\n if (!this.uvs3 !== !other.uvs3) {\n if (!this.uvs3) {\n this.uvs3 = Array.from(other.uvs3);\n }\n else {\n other.uvs3 = Array.from(this.uvs3);\n }\n }\n if (!this.uvs4 !== !other.uvs4) {\n if (!this.uvs4) {\n this.uvs4 = Array.from(other.uvs4);\n }\n else {\n other.uvs4 = Array.from(this.uvs4);\n }\n }\n if (!this.uvs5 !== !other.uvs5) {\n if (!this.uvs5) {\n this.uvs5 = Array.from(other.uvs5);\n }\n else {\n other.uvs5 = Array.from(this.uvs5);\n }\n }\n if (!this.uvs6 !== !other.uvs6) {\n if (!this.uvs6) {\n this.uvs6 = Array.from(other.uvs6);\n }\n else {\n other.uvs6 = Array.from(this.uvs6);\n }\n }\n if (!this.colors !== !other.colors) {\n if (!this.colors) {\n this.colors = Array.from(other.colors);\n }\n else {\n other.colors = Array.from(this.colors);\n }\n }\n if (!this.matricesIndices !== !other.matricesIndices) {\n if (!this.matricesIndices) {\n this.matricesIndices = Array.from(other.matricesIndices);\n }\n else {\n other.matricesIndices = Array.from(this.matricesIndices);\n }\n }\n if (!this.matricesWeights !== !other.matricesWeights) {\n if (!this.matricesWeights) {\n this.matricesWeights = Array.from(other.matricesWeights);\n }\n else {\n other.matricesWeights = Array.from(this.matricesWeights);\n }\n }\n if (!this.matricesIndicesExtra !== !other.matricesIndicesExtra) {\n if (!this.matricesIndicesExtra) {\n this.matricesIndicesExtra = Array.from(other.matricesIndicesExtra);\n }\n else {\n other.matricesIndicesExtra = Array.from(this.matricesIndicesExtra);\n }\n }\n if (!this.matricesWeightsExtra !== !other.matricesWeightsExtra) {\n if (!this.matricesWeightsExtra) {\n this.matricesWeightsExtra = Array.from(other.matricesWeightsExtra);\n }\n else {\n other.matricesWeightsExtra = Array.from(this.matricesWeightsExtra);\n }\n }\n }\n }\n if (mergeMaterialIds) {\n // Merge material infos\n let materialIndex = 0;\n let indexOffset = 0;\n let vertexOffset = 0;\n const materialInfos = [];\n let currentMaterialInfo = null;\n const vertexDataList = [];\n // We need to split vertexData with more than one materialInfo\n for (const split of this.splitBasedOnMaterialID()) {\n vertexDataList.push({ vertexData: split, transform: transform });\n }\n for (const vertexData of vertexDatas) {\n for (const split of vertexData.vertexData.splitBasedOnMaterialID()) {\n vertexDataList.push({ vertexData: split, transform: vertexData.transform });\n }\n }\n // Sort by material IDs\n vertexDataList.sort((a, b) => {\n const matInfoA = a.vertexData.materialInfos ? a.vertexData.materialInfos[0].materialIndex : 0;\n const matInfoB = b.vertexData.materialInfos ? b.vertexData.materialInfos[0].materialIndex : 0;\n if (matInfoA > matInfoB) {\n return 1;\n }\n if (matInfoA === matInfoB) {\n return 0;\n }\n return -1;\n });\n // Build the new material info\n for (const vertexDataSource of vertexDataList) {\n const vertexData = vertexDataSource.vertexData;\n if (vertexData.materialInfos) {\n materialIndex = vertexData.materialInfos[0].materialIndex;\n }\n else {\n materialIndex = 0;\n }\n if (currentMaterialInfo && currentMaterialInfo.materialIndex === materialIndex) {\n currentMaterialInfo.indexCount += vertexData.indices.length;\n currentMaterialInfo.verticesCount += vertexData.positions.length / 3;\n }\n else {\n const materialInfo = new VertexDataMaterialInfo();\n materialInfo.materialIndex = materialIndex;\n materialInfo.indexStart = indexOffset;\n materialInfo.indexCount = vertexData.indices.length;\n materialInfo.verticesStart = vertexOffset;\n materialInfo.verticesCount = vertexData.positions.length / 3;\n materialInfos.push(materialInfo);\n currentMaterialInfo = materialInfo;\n }\n indexOffset += vertexData.indices.length;\n vertexOffset += vertexData.positions.length / 3;\n }\n // Extract sorted values\n const first = vertexDataList.splice(0, 1)[0];\n root = first.vertexData;\n transform = first.transform;\n others = vertexDataList.map((v) => v.vertexData);\n vertexDatas = vertexDataList;\n this.materialInfos = materialInfos;\n }\n // Merge geometries\n const totalIndices = others.reduce((indexSum, vertexData) => { var _a, _b; return indexSum + ((_b = (_a = vertexData.indices) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); }, (_b = (_a = root.indices) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);\n const sliceIndices = forceCloneIndices || others.some((vertexData) => vertexData.indices === root.indices);\n let indices = sliceIndices ? (_c = root.indices) === null || _c === void 0 ? void 0 : _c.slice() : root.indices;\n if (totalIndices > 0) {\n let indicesOffset = (_d = indices === null || indices === void 0 ? void 0 : indices.length) !== null && _d !== void 0 ? _d : 0;\n if (!indices) {\n indices = new Array(totalIndices);\n }\n if (indices.length !== totalIndices) {\n if (Array.isArray(indices)) {\n indices.length = totalIndices;\n }\n else {\n const temp = use32BitsIndices || indices instanceof Uint32Array ? new Uint32Array(totalIndices) : new Uint16Array(totalIndices);\n temp.set(indices);\n indices = temp;\n }\n if (transform && transform.determinant() < 0) {\n VertexData._FlipFaces(indices, 0, indicesOffset);\n }\n }\n let positionsOffset = root.positions ? root.positions.length / 3 : 0;\n for (const { vertexData: other, transform } of vertexDatas) {\n if (other.indices) {\n for (let index = 0; index < other.indices.length; index++) {\n indices[indicesOffset + index] = other.indices[index] + positionsOffset;\n }\n if (transform && transform.determinant() < 0) {\n VertexData._FlipFaces(indices, indicesOffset, other.indices.length);\n }\n // The call to _validate already checked for positions\n positionsOffset += other.positions.length / 3;\n indicesOffset += other.indices.length;\n if (isAsync) {\n yield;\n }\n }\n }\n }\n this.indices = indices;\n this.positions = VertexData._MergeElement(VertexBuffer.PositionKind, root.positions, transform, vertexDatas.map((other) => [other.vertexData.positions, other.transform]));\n if (isAsync) {\n yield;\n }\n if (root.normals) {\n this.normals = VertexData._MergeElement(VertexBuffer.NormalKind, root.normals, transform, vertexDatas.map((other) => [other.vertexData.normals, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.tangents) {\n this.tangents = VertexData._MergeElement(VertexBuffer.TangentKind, root.tangents, transform, vertexDatas.map((other) => [other.vertexData.tangents, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.uvs) {\n this.uvs = VertexData._MergeElement(VertexBuffer.UVKind, root.uvs, transform, vertexDatas.map((other) => [other.vertexData.uvs, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.uvs2) {\n this.uvs2 = VertexData._MergeElement(VertexBuffer.UV2Kind, root.uvs2, transform, vertexDatas.map((other) => [other.vertexData.uvs2, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.uvs3) {\n this.uvs3 = VertexData._MergeElement(VertexBuffer.UV3Kind, root.uvs3, transform, vertexDatas.map((other) => [other.vertexData.uvs3, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.uvs4) {\n this.uvs4 = VertexData._MergeElement(VertexBuffer.UV4Kind, root.uvs4, transform, vertexDatas.map((other) => [other.vertexData.uvs4, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.uvs5) {\n this.uvs5 = VertexData._MergeElement(VertexBuffer.UV5Kind, root.uvs5, transform, vertexDatas.map((other) => [other.vertexData.uvs5, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.uvs6) {\n this.uvs6 = VertexData._MergeElement(VertexBuffer.UV6Kind, root.uvs6, transform, vertexDatas.map((other) => [other.vertexData.uvs6, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.colors) {\n this.colors = VertexData._MergeElement(VertexBuffer.ColorKind, root.colors, transform, vertexDatas.map((other) => [other.vertexData.colors, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.matricesIndices) {\n this.matricesIndices = VertexData._MergeElement(VertexBuffer.MatricesIndicesKind, root.matricesIndices, transform, vertexDatas.map((other) => [other.vertexData.matricesIndices, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.matricesWeights) {\n this.matricesWeights = VertexData._MergeElement(VertexBuffer.MatricesWeightsKind, root.matricesWeights, transform, vertexDatas.map((other) => [other.vertexData.matricesWeights, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.matricesIndicesExtra) {\n this.matricesIndicesExtra = VertexData._MergeElement(VertexBuffer.MatricesIndicesExtraKind, root.matricesIndicesExtra, transform, vertexDatas.map((other) => [other.vertexData.matricesIndicesExtra, other.transform]));\n if (isAsync) {\n yield;\n }\n }\n if (root.matricesWeightsExtra) {\n this.matricesWeightsExtra = VertexData._MergeElement(VertexBuffer.MatricesWeightsExtraKind, root.matricesWeightsExtra, transform, vertexDatas.map((other) => [other.vertexData.matricesWeightsExtra, other.transform]));\n }\n return this;\n }\n static _MergeElement(kind, source, transform, others) {\n const nonNullOthers = others.filter((other) => other[0] !== null && other[0] !== undefined);\n // If there is no source to copy and no other non-null sources then skip this element.\n if (!source && nonNullOthers.length == 0) {\n return source;\n }\n if (!source) {\n return this._MergeElement(kind, nonNullOthers[0][0], nonNullOthers[0][1], nonNullOthers.slice(1));\n }\n const len = nonNullOthers.reduce((sumLen, elements) => sumLen + elements[0].length, source.length);\n const transformRange = kind === VertexBuffer.PositionKind\n ? VertexData._TransformVector3Coordinates\n : kind === VertexBuffer.NormalKind\n ? VertexData._TransformVector3Normals\n : kind === VertexBuffer.TangentKind\n ? VertexData._TransformVector4Normals\n : () => { };\n if (source instanceof Float32Array) {\n // use non-loop method when the source is Float32Array\n const ret32 = new Float32Array(len);\n ret32.set(source);\n transform && transformRange(ret32, transform, 0, source.length);\n let offset = source.length;\n for (const [vertexData, transform] of nonNullOthers) {\n ret32.set(vertexData, offset);\n transform && transformRange(ret32, transform, offset, vertexData.length);\n offset += vertexData.length;\n }\n return ret32;\n }\n else {\n // don't use concat as it is super slow, just loop for other cases\n const ret = new Array(len);\n for (let i = 0; i < source.length; i++) {\n ret[i] = source[i];\n }\n transform && transformRange(ret, transform, 0, source.length);\n let offset = source.length;\n for (const [vertexData, transform] of nonNullOthers) {\n for (let i = 0; i < vertexData.length; i++) {\n ret[offset + i] = vertexData[i];\n }\n transform && transformRange(ret, transform, offset, vertexData.length);\n offset += vertexData.length;\n }\n return ret;\n }\n }\n _validate() {\n if (!this.positions) {\n throw new RuntimeError(\"Positions are required\", ErrorCodes.MeshInvalidPositionsError);\n }\n const getElementCount = (kind, values) => {\n const stride = VertexBuffer.DeduceStride(kind);\n if (values.length % stride !== 0) {\n throw new Error(\"The \" + kind + \"s array count must be a multiple of \" + stride);\n }\n return values.length / stride;\n };\n const positionsElementCount = getElementCount(VertexBuffer.PositionKind, this.positions);\n const validateElementCount = (kind, values) => {\n const elementCount = getElementCount(kind, values);\n if (elementCount !== positionsElementCount) {\n throw new Error(\"The \" + kind + \"s element count (\" + elementCount + \") does not match the positions count (\" + positionsElementCount + \")\");\n }\n };\n if (this.normals) {\n validateElementCount(VertexBuffer.NormalKind, this.normals);\n }\n if (this.tangents) {\n validateElementCount(VertexBuffer.TangentKind, this.tangents);\n }\n if (this.uvs) {\n validateElementCount(VertexBuffer.UVKind, this.uvs);\n }\n if (this.uvs2) {\n validateElementCount(VertexBuffer.UV2Kind, this.uvs2);\n }\n if (this.uvs3) {\n validateElementCount(VertexBuffer.UV3Kind, this.uvs3);\n }\n if (this.uvs4) {\n validateElementCount(VertexBuffer.UV4Kind, this.uvs4);\n }\n if (this.uvs5) {\n validateElementCount(VertexBuffer.UV5Kind, this.uvs5);\n }\n if (this.uvs6) {\n validateElementCount(VertexBuffer.UV6Kind, this.uvs6);\n }\n if (this.colors) {\n validateElementCount(VertexBuffer.ColorKind, this.colors);\n }\n if (this.matricesIndices) {\n validateElementCount(VertexBuffer.MatricesIndicesKind, this.matricesIndices);\n }\n if (this.matricesWeights) {\n validateElementCount(VertexBuffer.MatricesWeightsKind, this.matricesWeights);\n }\n if (this.matricesIndicesExtra) {\n validateElementCount(VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra);\n }\n if (this.matricesWeightsExtra) {\n validateElementCount(VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra);\n }\n }\n /**\n * Clone the current vertex data\n * @returns a copy of the current data\n */\n clone() {\n const serializationObject = this.serialize();\n return VertexData.Parse(serializationObject);\n }\n /**\n * Serializes the VertexData\n * @returns a serialized object\n */\n serialize() {\n const serializationObject = {};\n if (this.positions) {\n serializationObject.positions = Array.from(this.positions);\n }\n if (this.normals) {\n serializationObject.normals = Array.from(this.normals);\n }\n if (this.tangents) {\n serializationObject.tangents = Array.from(this.tangents);\n }\n if (this.uvs) {\n serializationObject.uvs = Array.from(this.uvs);\n }\n if (this.uvs2) {\n serializationObject.uvs2 = Array.from(this.uvs2);\n }\n if (this.uvs3) {\n serializationObject.uvs3 = Array.from(this.uvs3);\n }\n if (this.uvs4) {\n serializationObject.uvs4 = Array.from(this.uvs4);\n }\n if (this.uvs5) {\n serializationObject.uvs5 = Array.from(this.uvs5);\n }\n if (this.uvs6) {\n serializationObject.uvs6 = Array.from(this.uvs6);\n }\n if (this.colors) {\n serializationObject.colors = Array.from(this.colors);\n }\n if (this.matricesIndices) {\n serializationObject.matricesIndices = Array.from(this.matricesIndices);\n serializationObject.matricesIndices._isExpanded = true;\n }\n if (this.matricesWeights) {\n serializationObject.matricesWeights = Array.from(this.matricesWeights);\n }\n if (this.matricesIndicesExtra) {\n serializationObject.matricesIndicesExtra = Array.from(this.matricesIndicesExtra);\n serializationObject.matricesIndicesExtra._isExpanded = true;\n }\n if (this.matricesWeightsExtra) {\n serializationObject.matricesWeightsExtra = Array.from(this.matricesWeightsExtra);\n }\n serializationObject.indices = Array.from(this.indices);\n if (this.materialInfos) {\n serializationObject.materialInfos = [];\n for (const materialInfo of this.materialInfos) {\n const materialInfoSerializationObject = {\n indexStart: materialInfo.indexStart,\n indexCount: materialInfo.indexCount,\n materialIndex: materialInfo.materialIndex,\n verticesStart: materialInfo.verticesStart,\n verticesCount: materialInfo.verticesCount,\n };\n serializationObject.materialInfos.push(materialInfoSerializationObject);\n }\n }\n return serializationObject;\n }\n // Statics\n /**\n * Extracts the vertexData from a mesh\n * @param mesh the mesh from which to extract the VertexData\n * @param copyWhenShared defines if the VertexData must be cloned when shared between multiple meshes, optional, default false\n * @param forceCopy indicating that the VertexData must be cloned, optional, default false\n * @returns the object VertexData associated to the passed mesh\n */\n static ExtractFromMesh(mesh, copyWhenShared, forceCopy) {\n return VertexData._ExtractFrom(mesh, copyWhenShared, forceCopy);\n }\n /**\n * Extracts the vertexData from the geometry\n * @param geometry the geometry from which to extract the VertexData\n * @param copyWhenShared defines if the VertexData must be cloned when the geometry is shared between multiple meshes, optional, default false\n * @param forceCopy indicating that the VertexData must be cloned, optional, default false\n * @returns the object VertexData associated to the passed mesh\n */\n static ExtractFromGeometry(geometry, copyWhenShared, forceCopy) {\n return VertexData._ExtractFrom(geometry, copyWhenShared, forceCopy);\n }\n static _ExtractFrom(meshOrGeometry, copyWhenShared, forceCopy) {\n const result = new VertexData();\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.PositionKind)) {\n result.positions = meshOrGeometry.getVerticesData(VertexBuffer.PositionKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n result.normals = meshOrGeometry.getVerticesData(VertexBuffer.NormalKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.TangentKind)) {\n result.tangents = meshOrGeometry.getVerticesData(VertexBuffer.TangentKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UVKind)) {\n result.uvs = meshOrGeometry.getVerticesData(VertexBuffer.UVKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\n result.uvs2 = meshOrGeometry.getVerticesData(VertexBuffer.UV2Kind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV3Kind)) {\n result.uvs3 = meshOrGeometry.getVerticesData(VertexBuffer.UV3Kind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV4Kind)) {\n result.uvs4 = meshOrGeometry.getVerticesData(VertexBuffer.UV4Kind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV5Kind)) {\n result.uvs5 = meshOrGeometry.getVerticesData(VertexBuffer.UV5Kind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV6Kind)) {\n result.uvs6 = meshOrGeometry.getVerticesData(VertexBuffer.UV6Kind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.ColorKind)) {\n result.colors = meshOrGeometry.getVerticesData(VertexBuffer.ColorKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {\n result.matricesIndices = meshOrGeometry.getVerticesData(VertexBuffer.MatricesIndicesKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\n result.matricesWeights = meshOrGeometry.getVerticesData(VertexBuffer.MatricesWeightsKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesIndicesExtraKind)) {\n result.matricesIndicesExtra = meshOrGeometry.getVerticesData(VertexBuffer.MatricesIndicesExtraKind, copyWhenShared, forceCopy);\n }\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesWeightsExtraKind)) {\n result.matricesWeightsExtra = meshOrGeometry.getVerticesData(VertexBuffer.MatricesWeightsExtraKind, copyWhenShared, forceCopy);\n }\n result.indices = meshOrGeometry.getIndices(copyWhenShared, forceCopy);\n return result;\n }\n /**\n * Creates the VertexData for a Ribbon\n * @param options an object used to set the following optional parameters for the ribbon, required but can be empty\n * * pathArray array of paths, each of which an array of successive Vector3\n * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false\n * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false\n * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false\n * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional\n * * colors a linear array, of length 4 * number of vertices, of custom color values, optional\n * @param options.pathArray\n * @param options.closeArray\n * @param options.closePath\n * @param options.offset\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.invertUV\n * @param options.uvs\n * @param options.colors\n * @returns the VertexData of the ribbon\n * @deprecated use CreateRibbonVertexData instead\n */\n static CreateRibbon(options) {\n throw _WarnImport(\"ribbonBuilder\");\n }\n /**\n * Creates the VertexData for a box\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * size sets the width, height and depth of the box to the value of size, optional default 1\n * * width sets the width (x direction) of the box, overwrites the width set by size, optional, default size\n * * height sets the height (y direction) of the box, overwrites the height set by size, optional, default size\n * * depth sets the depth (z direction) of the box, overwrites the depth set by size, optional, default size\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.depth\n * @param options.faceUV\n * @param options.faceColors\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the box\n * @deprecated Please use CreateBoxVertexData from the BoxBuilder file instead\n */\n static CreateBox(options) {\n throw _WarnImport(\"boxBuilder\");\n }\n /**\n * Creates the VertexData for a tiled box\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * faceTiles sets the pattern, tile size and number of tiles for a face\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * @param options.pattern\n * @param options.width\n * @param options.height\n * @param options.depth\n * @param options.tileSize\n * @param options.tileWidth\n * @param options.tileHeight\n * @param options.alignHorizontal\n * @param options.alignVertical\n * @param options.faceUV\n * @param options.faceColors\n * @param options.sideOrientation\n * @returns the VertexData of the box\n * @deprecated Please use CreateTiledBoxVertexData instead\n */\n static CreateTiledBox(options) {\n throw _WarnImport(\"tiledBoxBuilder\");\n }\n /**\n * Creates the VertexData for a tiled plane\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * pattern a limited pattern arrangement depending on the number\n * * tileSize sets the width, height and depth of the tile to the value of size, optional default 1\n * * tileWidth sets the width (x direction) of the tile, overwrites the width set by size, optional, default size\n * * tileHeight sets the height (y direction) of the tile, overwrites the height set by size, optional, default size\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.pattern\n * @param options.tileSize\n * @param options.tileWidth\n * @param options.tileHeight\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.alignHorizontal\n * @param options.alignVertical\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the tiled plane\n * @deprecated use CreateTiledPlaneVertexData instead\n */\n static CreateTiledPlane(options) {\n throw _WarnImport(\"tiledPlaneBuilder\");\n }\n /**\n * Creates the VertexData for an ellipsoid, defaults to a sphere\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * segments sets the number of horizontal strips optional, default 32\n * * diameter sets the axes dimensions, diameterX, diameterY and diameterZ to the value of diameter, optional default 1\n * * diameterX sets the diameterX (x direction) of the ellipsoid, overwrites the diameterX set by diameter, optional, default diameter\n * * diameterY sets the diameterY (y direction) of the ellipsoid, overwrites the diameterY set by diameter, optional, default diameter\n * * diameterZ sets the diameterZ (z direction) of the ellipsoid, overwrites the diameterZ set by diameter, optional, default diameter\n * * arc a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the circumference (latitude) given by the arc value, optional, default 1\n * * slice a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the height (latitude) given by the arc value, optional, default 1\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.segments\n * @param options.diameter\n * @param options.diameterX\n * @param options.diameterY\n * @param options.diameterZ\n * @param options.arc\n * @param options.slice\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the ellipsoid\n * @deprecated use CreateSphereVertexData instead\n */\n static CreateSphere(options) {\n throw _WarnImport(\"sphereBuilder\");\n }\n /**\n * Creates the VertexData for a cylinder, cone or prism\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * height sets the height (y direction) of the cylinder, optional, default 2\n * * diameterTop sets the diameter of the top of the cone, overwrites diameter, optional, default diameter\n * * diameterBottom sets the diameter of the bottom of the cone, overwrites diameter, optional, default diameter\n * * diameter sets the diameter of the top and bottom of the cone, optional default 1\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\n * * subdivisions` the number of rings along the cylinder height, optional, default 1\n * * arc a number from 0 to 1, to create an unclosed cylinder based on the fraction of the circumference given by the arc value, optional, default 1\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * * hasRings when true makes each subdivision independently treated as a face for faceUV and faceColors, optional, default false\n * * enclose when true closes an open cylinder by adding extra flat faces between the height axis and vertical edges, think cut cake\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.height\n * @param options.diameterTop\n * @param options.diameterBottom\n * @param options.diameter\n * @param options.tessellation\n * @param options.subdivisions\n * @param options.arc\n * @param options.faceColors\n * @param options.faceUV\n * @param options.hasRings\n * @param options.enclose\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the cylinder, cone or prism\n * @deprecated please use CreateCylinderVertexData instead\n */\n static CreateCylinder(options) {\n throw _WarnImport(\"cylinderBuilder\");\n }\n /**\n * Creates the VertexData for a torus\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * diameter the diameter of the torus, optional default 1\n * * thickness the diameter of the tube forming the torus, optional default 0.5\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the torus\n * @deprecated use CreateTorusVertexData instead\n */\n static CreateTorus(options) {\n throw _WarnImport(\"torusBuilder\");\n }\n /**\n * Creates the VertexData of the LineSystem\n * @param options an object used to set the following optional parameters for the LineSystem, required but can be empty\n * - lines an array of lines, each line being an array of successive Vector3\n * - colors an array of line colors, each of the line colors being an array of successive Color4, one per line point\n * @param options.lines\n * @param options.colors\n * @returns the VertexData of the LineSystem\n * @deprecated use CreateLineSystemVertexData instead\n */\n static CreateLineSystem(options) {\n throw _WarnImport(\"linesBuilder\");\n }\n /**\n * Create the VertexData for a DashedLines\n * @param options an object used to set the following optional parameters for the DashedLines, required but can be empty\n * - points an array successive Vector3\n * - dashSize the size of the dashes relative to the dash number, optional, default 3\n * - gapSize the size of the gap between two successive dashes relative to the dash number, optional, default 1\n * - dashNb the intended total number of dashes, optional, default 200\n * @param options.points\n * @param options.dashSize\n * @param options.gapSize\n * @param options.dashNb\n * @returns the VertexData for the DashedLines\n * @deprecated use CreateDashedLinesVertexData instead\n */\n static CreateDashedLines(options) {\n throw _WarnImport(\"linesBuilder\");\n }\n /**\n * Creates the VertexData for a Ground\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\n * - width the width (x direction) of the ground, optional, default 1\n * - height the height (z direction) of the ground, optional, default 1\n * - subdivisions the number of subdivisions per side, optional, default 1\n * @param options.width\n * @param options.height\n * @param options.subdivisions\n * @param options.subdivisionsX\n * @param options.subdivisionsY\n * @returns the VertexData of the Ground\n * @deprecated Please use CreateGroundVertexData instead\n */\n static CreateGround(options) {\n throw _WarnImport(\"groundBuilder\");\n }\n /**\n * Creates the VertexData for a TiledGround by subdividing the ground into tiles\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\n * * xmin the ground minimum X coordinate, optional, default -1\n * * zmin the ground minimum Z coordinate, optional, default -1\n * * xmax the ground maximum X coordinate, optional, default 1\n * * zmax the ground maximum Z coordinate, optional, default 1\n * * subdivisions a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the ground width and height creating 'tiles', default {w: 6, h: 6}\n * * precision a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the tile width and height, default {w: 2, h: 2}\n * @param options.xmin\n * @param options.zmin\n * @param options.xmax\n * @param options.zmax\n * @param options.subdivisions\n * @param options.subdivisions.w\n * @param options.subdivisions.h\n * @param options.precision\n * @param options.precision.w\n * @param options.precision.h\n * @returns the VertexData of the TiledGround\n * @deprecated use CreateTiledGroundVertexData instead\n */\n static CreateTiledGround(options) {\n throw _WarnImport(\"groundBuilder\");\n }\n /**\n * Creates the VertexData of the Ground designed from a heightmap\n * @param options an object used to set the following parameters for the Ground, required and provided by CreateGroundFromHeightMap\n * * width the width (x direction) of the ground\n * * height the height (z direction) of the ground\n * * subdivisions the number of subdivisions per side\n * * minHeight the minimum altitude on the ground, optional, default 0\n * * maxHeight the maximum altitude on the ground, optional default 1\n * * colorFilter the filter to apply to the image pixel colors to compute the height, optional Color3, default (0.3, 0.59, 0.11)\n * * buffer the array holding the image color data\n * * bufferWidth the width of image\n * * bufferHeight the height of image\n * * alphaFilter Remove any data where the alpha channel is below this value, defaults 0 (all data visible)\n * @param options.width\n * @param options.height\n * @param options.subdivisions\n * @param options.minHeight\n * @param options.maxHeight\n * @param options.colorFilter\n * @param options.buffer\n * @param options.bufferWidth\n * @param options.bufferHeight\n * @param options.alphaFilter\n * @returns the VertexData of the Ground designed from a heightmap\n * @deprecated use CreateGroundFromHeightMapVertexData instead\n */\n static CreateGroundFromHeightMap(options) {\n throw _WarnImport(\"groundBuilder\");\n }\n /**\n * Creates the VertexData for a Plane\n * @param options an object used to set the following optional parameters for the plane, required but can be empty\n * * size sets the width and height of the plane to the value of size, optional default 1\n * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size\n * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the box\n * @deprecated use CreatePlaneVertexData instead\n */\n static CreatePlane(options) {\n throw _WarnImport(\"planeBuilder\");\n }\n /**\n * Creates the VertexData of the Disc or regular Polygon\n * @param options an object used to set the following optional parameters for the disc, required but can be empty\n * * radius the radius of the disc, optional default 0.5\n * * tessellation the number of polygon sides, optional, default 64\n * * arc a number from 0 to 1, to create an unclosed polygon based on the fraction of the circumference given by the arc value, optional, default 1\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.radius\n * @param options.tessellation\n * @param options.arc\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the box\n * @deprecated use CreateDiscVertexData instead\n */\n static CreateDisc(options) {\n throw _WarnImport(\"discBuilder\");\n }\n /**\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\n * All parameters are provided by CreatePolygon as needed\n * @param polygon a mesh built from polygonTriangulation.build()\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param wrap a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\n * @returns the VertexData of the Polygon\n * @deprecated use CreatePolygonVertexData instead\n */\n static CreatePolygon(polygon, sideOrientation, fUV, fColors, frontUVs, backUVs, wrap) {\n throw _WarnImport(\"polygonBuilder\");\n }\n /**\n * Creates the VertexData of the IcoSphere\n * @param options an object used to set the following optional parameters for the IcoSphere, required but can be empty\n * * radius the radius of the IcoSphere, optional default 1\n * * radiusX allows stretching in the x direction, optional, default radius\n * * radiusY allows stretching in the y direction, optional, default radius\n * * radiusZ allows stretching in the z direction, optional, default radius\n * * flat when true creates a flat shaded mesh, optional, default true\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.radius\n * @param options.radiusX\n * @param options.radiusY\n * @param options.radiusZ\n * @param options.flat\n * @param options.subdivisions\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the IcoSphere\n * @deprecated use CreateIcoSphereVertexData instead\n */\n static CreateIcoSphere(options) {\n throw _WarnImport(\"icoSphereBuilder\");\n }\n // inspired from // http://stemkoski.github.io/Three.js/Polyhedra.html\n /**\n * Creates the VertexData for a Polyhedron\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\n * * type provided types are:\n * * 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)\n * * 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)\n * * size the size of the IcoSphere, optional default 1\n * * sizeX allows stretching in the x direction, optional, default size\n * * sizeY allows stretching in the y direction, optional, default size\n * * sizeZ allows stretching in the z direction, optional, default size\n * * custom a number that overwrites the type to create from an extended set of polyhedron from https://www.babylonjs-playground.com/#21QRSK#15 with minimised editor\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * * flat when true creates a flat shaded mesh, optional, default true\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.type\n * @param options.size\n * @param options.sizeX\n * @param options.sizeY\n * @param options.sizeZ\n * @param options.custom\n * @param options.faceUV\n * @param options.faceColors\n * @param options.flat\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the Polyhedron\n * @deprecated use CreatePolyhedronVertexData instead\n */\n static CreatePolyhedron(options) {\n throw _WarnImport(\"polyhedronBuilder\");\n }\n /**\n * Creates the VertexData for a Capsule, inspired from https://github.com/maximeq/three-js-capsule-geometry/blob/master/src/CapsuleBufferGeometry.js\n * @param options an object used to set the following optional parameters for the capsule, required but can be empty\n * @returns the VertexData of the Capsule\n * @deprecated Please use CreateCapsuleVertexData from the capsuleBuilder file instead\n */\n static CreateCapsule(options = {\n orientation: Vector3.Up(),\n subdivisions: 2,\n tessellation: 16,\n height: 1,\n radius: 0.25,\n capSubdivisions: 6,\n }) {\n throw _WarnImport(\"capsuleBuilder\");\n }\n // based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473\n /**\n * Creates the VertexData for a TorusKnot\n * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty\n * * radius the radius of the torus knot, optional, default 2\n * * tube the thickness of the tube, optional, default 0.5\n * * radialSegments the number of sides on each tube segments, optional, default 32\n * * tubularSegments the number of tubes to decompose the knot into, optional, default 32\n * * p the number of windings around the z axis, optional, default 2\n * * q the number of windings around the x axis, optional, default 3\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.radius\n * @param options.tube\n * @param options.radialSegments\n * @param options.tubularSegments\n * @param options.p\n * @param options.q\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the Torus Knot\n * @deprecated use CreateTorusKnotVertexData instead\n */\n static CreateTorusKnot(options) {\n throw _WarnImport(\"torusKnotBuilder\");\n }\n // Tools\n /**\n * Compute normals for given positions and indices\n * @param positions an array of vertex positions, [...., x, y, z, ......]\n * @param indices an array of indices in groups of three for each triangular facet, [...., i, j, k, ......]\n * @param normals an array of vertex normals, [...., x, y, z, ......]\n * @param options an object used to set the following optional parameters for the TorusKnot, optional\n * * facetNormals : optional array of facet normals (vector3)\n * * facetPositions : optional array of facet positions (vector3)\n * * facetPartitioning : optional partitioning array. facetPositions is required for facetPartitioning computation\n * * ratio : optional partitioning ratio / bounding box, required for facetPartitioning computation\n * * bInfo : optional bounding info, required for facetPartitioning computation\n * * bbSize : optional bounding box size data, required for facetPartitioning computation\n * * subDiv : optional partitioning data about subdivisions on each axis (int), required for facetPartitioning computation\n * * useRightHandedSystem: optional boolean to for right handed system computation\n * * depthSort : optional boolean to enable the facet depth sort computation\n * * distanceTo : optional Vector3 to compute the facet depth from this location\n * * depthSortedFacets : optional array of depthSortedFacets to store the facet distances from the reference location\n * @param options.facetNormals\n * @param options.facetPositions\n * @param options.facetPartitioning\n * @param options.ratio\n * @param options.bInfo\n * @param options.bbSize\n * @param options.subDiv\n * @param options.useRightHandedSystem\n * @param options.depthSort\n * @param options.distanceTo\n * @param options.depthSortedFacets\n */\n static ComputeNormals(positions, indices, normals, options) {\n // temporary scalar variables\n let index = 0; // facet index\n let p1p2x = 0.0; // p1p2 vector x coordinate\n let p1p2y = 0.0; // p1p2 vector y coordinate\n let p1p2z = 0.0; // p1p2 vector z coordinate\n let p3p2x = 0.0; // p3p2 vector x coordinate\n let p3p2y = 0.0; // p3p2 vector y coordinate\n let p3p2z = 0.0; // p3p2 vector z coordinate\n let faceNormalx = 0.0; // facet normal x coordinate\n let faceNormaly = 0.0; // facet normal y coordinate\n let faceNormalz = 0.0; // facet normal z coordinate\n let length = 0.0; // facet normal length before normalization\n let v1x = 0; // vector1 x index in the positions array\n let v1y = 0; // vector1 y index in the positions array\n let v1z = 0; // vector1 z index in the positions array\n let v2x = 0; // vector2 x index in the positions array\n let v2y = 0; // vector2 y index in the positions array\n let v2z = 0; // vector2 z index in the positions array\n let v3x = 0; // vector3 x index in the positions array\n let v3y = 0; // vector3 y index in the positions array\n let v3z = 0; // vector3 z index in the positions array\n let computeFacetNormals = false;\n let computeFacetPositions = false;\n let computeFacetPartitioning = false;\n let computeDepthSort = false;\n let faceNormalSign = 1;\n let ratio = 0;\n let distanceTo = null;\n if (options) {\n computeFacetNormals = options.facetNormals ? true : false;\n computeFacetPositions = options.facetPositions ? true : false;\n computeFacetPartitioning = options.facetPartitioning ? true : false;\n faceNormalSign = options.useRightHandedSystem === true ? -1 : 1;\n ratio = options.ratio || 0;\n computeDepthSort = options.depthSort ? true : false;\n distanceTo = options.distanceTo;\n if (computeDepthSort) {\n if (distanceTo === undefined) {\n distanceTo = Vector3.Zero();\n }\n }\n }\n // facetPartitioning reinit if needed\n let xSubRatio = 0;\n let ySubRatio = 0;\n let zSubRatio = 0;\n let subSq = 0;\n if (computeFacetPartitioning && options && options.bbSize) {\n //let bbSizeMax = options.bbSize.x > options.bbSize.y ? options.bbSize.x : options.bbSize.y;\n //bbSizeMax = bbSizeMax > options.bbSize.z ? bbSizeMax : options.bbSize.z;\n xSubRatio = (options.subDiv.X * ratio) / options.bbSize.x;\n ySubRatio = (options.subDiv.Y * ratio) / options.bbSize.y;\n zSubRatio = (options.subDiv.Z * ratio) / options.bbSize.z;\n subSq = options.subDiv.max * options.subDiv.max;\n options.facetPartitioning.length = 0;\n }\n // reset the normals\n for (index = 0; index < positions.length; index++) {\n normals[index] = 0.0;\n }\n // Loop : 1 indice triplet = 1 facet\n const nbFaces = (indices.length / 3) | 0;\n for (index = 0; index < nbFaces; index++) {\n // get the indexes of the coordinates of each vertex of the facet\n v1x = indices[index * 3] * 3;\n v1y = v1x + 1;\n v1z = v1x + 2;\n v2x = indices[index * 3 + 1] * 3;\n v2y = v2x + 1;\n v2z = v2x + 2;\n v3x = indices[index * 3 + 2] * 3;\n v3y = v3x + 1;\n v3z = v3x + 2;\n p1p2x = positions[v1x] - positions[v2x]; // compute two vectors per facet : p1p2 and p3p2\n p1p2y = positions[v1y] - positions[v2y];\n p1p2z = positions[v1z] - positions[v2z];\n p3p2x = positions[v3x] - positions[v2x];\n p3p2y = positions[v3y] - positions[v2y];\n p3p2z = positions[v3z] - positions[v2z];\n // compute the face normal with the cross product\n faceNormalx = faceNormalSign * (p1p2y * p3p2z - p1p2z * p3p2y);\n faceNormaly = faceNormalSign * (p1p2z * p3p2x - p1p2x * p3p2z);\n faceNormalz = faceNormalSign * (p1p2x * p3p2y - p1p2y * p3p2x);\n // normalize this normal and store it in the array facetData\n length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);\n length = length === 0 ? 1.0 : length;\n faceNormalx /= length;\n faceNormaly /= length;\n faceNormalz /= length;\n if (computeFacetNormals && options) {\n options.facetNormals[index].x = faceNormalx;\n options.facetNormals[index].y = faceNormaly;\n options.facetNormals[index].z = faceNormalz;\n }\n if (computeFacetPositions && options) {\n // compute and the facet barycenter coordinates in the array facetPositions\n options.facetPositions[index].x = (positions[v1x] + positions[v2x] + positions[v3x]) / 3.0;\n options.facetPositions[index].y = (positions[v1y] + positions[v2y] + positions[v3y]) / 3.0;\n options.facetPositions[index].z = (positions[v1z] + positions[v2z] + positions[v3z]) / 3.0;\n }\n if (computeFacetPartitioning && options) {\n // store the facet indexes in arrays in the main facetPartitioning array :\n // compute each facet vertex (+ facet barycenter) index in the partiniong array\n const ox = Math.floor((options.facetPositions[index].x - options.bInfo.minimum.x * ratio) * xSubRatio);\n const oy = Math.floor((options.facetPositions[index].y - options.bInfo.minimum.y * ratio) * ySubRatio);\n const oz = Math.floor((options.facetPositions[index].z - options.bInfo.minimum.z * ratio) * zSubRatio);\n const b1x = Math.floor((positions[v1x] - options.bInfo.minimum.x * ratio) * xSubRatio);\n const b1y = Math.floor((positions[v1y] - options.bInfo.minimum.y * ratio) * ySubRatio);\n const b1z = Math.floor((positions[v1z] - options.bInfo.minimum.z * ratio) * zSubRatio);\n const b2x = Math.floor((positions[v2x] - options.bInfo.minimum.x * ratio) * xSubRatio);\n const b2y = Math.floor((positions[v2y] - options.bInfo.minimum.y * ratio) * ySubRatio);\n const b2z = Math.floor((positions[v2z] - options.bInfo.minimum.z * ratio) * zSubRatio);\n const b3x = Math.floor((positions[v3x] - options.bInfo.minimum.x * ratio) * xSubRatio);\n const b3y = Math.floor((positions[v3y] - options.bInfo.minimum.y * ratio) * ySubRatio);\n const b3z = Math.floor((positions[v3z] - options.bInfo.minimum.z * ratio) * zSubRatio);\n const block_idx_v1 = b1x + options.subDiv.max * b1y + subSq * b1z;\n const block_idx_v2 = b2x + options.subDiv.max * b2y + subSq * b2z;\n const block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;\n const block_idx_o = ox + options.subDiv.max * oy + subSq * oz;\n options.facetPartitioning[block_idx_o] = options.facetPartitioning[block_idx_o] ? options.facetPartitioning[block_idx_o] : new Array();\n options.facetPartitioning[block_idx_v1] = options.facetPartitioning[block_idx_v1] ? options.facetPartitioning[block_idx_v1] : new Array();\n options.facetPartitioning[block_idx_v2] = options.facetPartitioning[block_idx_v2] ? options.facetPartitioning[block_idx_v2] : new Array();\n options.facetPartitioning[block_idx_v3] = options.facetPartitioning[block_idx_v3] ? options.facetPartitioning[block_idx_v3] : new Array();\n // push each facet index in each block containing the vertex\n options.facetPartitioning[block_idx_v1].push(index);\n if (block_idx_v2 != block_idx_v1) {\n options.facetPartitioning[block_idx_v2].push(index);\n }\n if (!(block_idx_v3 == block_idx_v2 || block_idx_v3 == block_idx_v1)) {\n options.facetPartitioning[block_idx_v3].push(index);\n }\n if (!(block_idx_o == block_idx_v1 || block_idx_o == block_idx_v2 || block_idx_o == block_idx_v3)) {\n options.facetPartitioning[block_idx_o].push(index);\n }\n }\n if (computeDepthSort && options && options.facetPositions) {\n const dsf = options.depthSortedFacets[index];\n dsf.ind = index * 3;\n dsf.sqDistance = Vector3.DistanceSquared(options.facetPositions[index], distanceTo);\n }\n // compute the normals anyway\n normals[v1x] += faceNormalx; // accumulate all the normals per face\n normals[v1y] += faceNormaly;\n normals[v1z] += faceNormalz;\n normals[v2x] += faceNormalx;\n normals[v2y] += faceNormaly;\n normals[v2z] += faceNormalz;\n normals[v3x] += faceNormalx;\n normals[v3y] += faceNormaly;\n normals[v3z] += faceNormalz;\n }\n // last normalization of each normal\n for (index = 0; index < normals.length / 3; index++) {\n faceNormalx = normals[index * 3];\n faceNormaly = normals[index * 3 + 1];\n faceNormalz = normals[index * 3 + 2];\n length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);\n length = length === 0 ? 1.0 : length;\n faceNormalx /= length;\n faceNormaly /= length;\n faceNormalz /= length;\n normals[index * 3] = faceNormalx;\n normals[index * 3 + 1] = faceNormaly;\n normals[index * 3 + 2] = faceNormalz;\n }\n }\n /**\n * @internal\n */\n static _ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs) {\n const li = indices.length;\n const ln = normals.length;\n let i;\n let n;\n sideOrientation = sideOrientation || VertexData.DEFAULTSIDE;\n switch (sideOrientation) {\n case VertexData.FRONTSIDE:\n // nothing changed\n break;\n case VertexData.BACKSIDE:\n // indices\n for (i = 0; i < li; i += 3) {\n const tmp = indices[i];\n indices[i] = indices[i + 2];\n indices[i + 2] = tmp;\n }\n // normals\n for (n = 0; n < ln; n++) {\n normals[n] = -normals[n];\n }\n break;\n case VertexData.DOUBLESIDE: {\n // positions\n const lp = positions.length;\n const l = lp / 3;\n for (let p = 0; p < lp; p++) {\n positions[lp + p] = positions[p];\n }\n // indices\n for (i = 0; i < li; i += 3) {\n indices[i + li] = indices[i + 2] + l;\n indices[i + 1 + li] = indices[i + 1] + l;\n indices[i + 2 + li] = indices[i] + l;\n }\n // normals\n for (n = 0; n < ln; n++) {\n normals[ln + n] = -normals[n];\n }\n // uvs\n const lu = uvs.length;\n let u = 0;\n for (u = 0; u < lu; u++) {\n uvs[u + lu] = uvs[u];\n }\n frontUVs = frontUVs ? frontUVs : new Vector4(0.0, 0.0, 1.0, 1.0);\n backUVs = backUVs ? backUVs : new Vector4(0.0, 0.0, 1.0, 1.0);\n u = 0;\n for (i = 0; i < lu / 2; i++) {\n uvs[u] = frontUVs.x + (frontUVs.z - frontUVs.x) * uvs[u];\n uvs[u + 1] = frontUVs.y + (frontUVs.w - frontUVs.y) * uvs[u + 1];\n uvs[u + lu] = backUVs.x + (backUVs.z - backUVs.x) * uvs[u + lu];\n uvs[u + lu + 1] = backUVs.y + (backUVs.w - backUVs.y) * uvs[u + lu + 1];\n u += 2;\n }\n break;\n }\n }\n }\n /**\n * Creates a VertexData from serialized data\n * @param parsedVertexData the parsed data from an imported file\n * @returns a VertexData\n */\n static Parse(parsedVertexData) {\n const vertexData = new VertexData();\n // positions\n const positions = parsedVertexData.positions;\n if (positions) {\n vertexData.set(positions, VertexBuffer.PositionKind);\n }\n // normals\n const normals = parsedVertexData.normals;\n if (normals) {\n vertexData.set(normals, VertexBuffer.NormalKind);\n }\n // tangents\n const tangents = parsedVertexData.tangents;\n if (tangents) {\n vertexData.set(tangents, VertexBuffer.TangentKind);\n }\n // uvs\n const uvs = parsedVertexData.uvs;\n if (uvs) {\n vertexData.set(uvs, VertexBuffer.UVKind);\n }\n // uv2s\n const uvs2 = parsedVertexData.uvs2;\n if (uvs2) {\n vertexData.set(uvs2, VertexBuffer.UV2Kind);\n }\n // uv3s\n const uvs3 = parsedVertexData.uvs3;\n if (uvs3) {\n vertexData.set(uvs3, VertexBuffer.UV3Kind);\n }\n // uv4s\n const uvs4 = parsedVertexData.uvs4;\n if (uvs4) {\n vertexData.set(uvs4, VertexBuffer.UV4Kind);\n }\n // uv5s\n const uvs5 = parsedVertexData.uvs5;\n if (uvs5) {\n vertexData.set(uvs5, VertexBuffer.UV5Kind);\n }\n // uv6s\n const uvs6 = parsedVertexData.uvs6;\n if (uvs6) {\n vertexData.set(uvs6, VertexBuffer.UV6Kind);\n }\n // colors\n const colors = parsedVertexData.colors;\n if (colors) {\n vertexData.set(Color4.CheckColors4(colors, positions.length / 3), VertexBuffer.ColorKind);\n }\n // matricesIndices\n const matricesIndices = parsedVertexData.matricesIndices;\n if (matricesIndices) {\n vertexData.set(matricesIndices, VertexBuffer.MatricesIndicesKind);\n }\n // matricesWeights\n const matricesWeights = parsedVertexData.matricesWeights;\n if (matricesWeights) {\n vertexData.set(matricesWeights, VertexBuffer.MatricesWeightsKind);\n }\n // indices\n const indices = parsedVertexData.indices;\n if (indices) {\n vertexData.indices = indices;\n }\n // MaterialInfos\n const materialInfos = parsedVertexData.materialInfos;\n if (materialInfos) {\n vertexData.materialInfos = [];\n for (const materialInfoFromJSON of materialInfos) {\n const materialInfo = new VertexDataMaterialInfo();\n materialInfo.indexCount = materialInfoFromJSON.indexCount;\n materialInfo.indexStart = materialInfoFromJSON.indexStart;\n materialInfo.verticesCount = materialInfoFromJSON.verticesCount;\n materialInfo.verticesStart = materialInfoFromJSON.verticesStart;\n materialInfo.materialIndex = materialInfoFromJSON.materialIndex;\n vertexData.materialInfos.push(materialInfo);\n }\n }\n return vertexData;\n }\n /**\n * Applies VertexData created from the imported parameters to the geometry\n * @param parsedVertexData the parsed data from an imported file\n * @param geometry the geometry to apply the VertexData to\n */\n static ImportVertexData(parsedVertexData, geometry) {\n const vertexData = VertexData.Parse(parsedVertexData);\n geometry.setAllVerticesData(vertexData, parsedVertexData.updatable);\n }\n }\n /**\n * Mesh side orientation : usually the external or front surface\n */\n VertexData.FRONTSIDE = 0;\n /**\n * Mesh side orientation : usually the internal or back surface\n */\n VertexData.BACKSIDE = 1;\n /**\n * Mesh side orientation : both internal and external or front and back surfaces\n */\n VertexData.DOUBLESIDE = 2;\n /**\n * Mesh side orientation : by default, `FRONTSIDE`\n */\n VertexData.DEFAULTSIDE = 0;\n __decorate$1([\n nativeOverride.filter((...[coordinates]) => !Array.isArray(coordinates))\n ], VertexData, \"_TransformVector3Coordinates\", null);\n __decorate$1([\n nativeOverride.filter((...[normals]) => !Array.isArray(normals))\n ], VertexData, \"_TransformVector3Normals\", null);\n __decorate$1([\n nativeOverride.filter((...[normals]) => !Array.isArray(normals))\n ], VertexData, \"_TransformVector4Normals\", null);\n __decorate$1([\n nativeOverride.filter((...[indices]) => !Array.isArray(indices))\n ], VertexData, \"_FlipFaces\", null);\n\n /**\n * Class used to represent data loading progression\n */\n class SceneLoaderFlags {\n /**\n * Gets or sets a boolean indicating if entire scene must be loaded even if scene contains incremental data\n */\n static get ForceFullSceneLoadingForIncremental() {\n return SceneLoaderFlags._ForceFullSceneLoadingForIncremental;\n }\n static set ForceFullSceneLoadingForIncremental(value) {\n SceneLoaderFlags._ForceFullSceneLoadingForIncremental = value;\n }\n /**\n * Gets or sets a boolean indicating if loading screen must be displayed while loading a scene\n */\n static get ShowLoadingScreen() {\n return SceneLoaderFlags._ShowLoadingScreen;\n }\n static set ShowLoadingScreen(value) {\n SceneLoaderFlags._ShowLoadingScreen = value;\n }\n /**\n * Defines the current logging level (while loading the scene)\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static get loggingLevel() {\n return SceneLoaderFlags._LoggingLevel;\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static set loggingLevel(value) {\n SceneLoaderFlags._LoggingLevel = value;\n }\n /**\n * Gets or set a boolean indicating if matrix weights must be cleaned upon loading\n */\n static get CleanBoneMatrixWeights() {\n return SceneLoaderFlags._CleanBoneMatrixWeights;\n }\n static set CleanBoneMatrixWeights(value) {\n SceneLoaderFlags._CleanBoneMatrixWeights = value;\n }\n }\n // Flags\n SceneLoaderFlags._ForceFullSceneLoadingForIncremental = false;\n SceneLoaderFlags._ShowLoadingScreen = true;\n SceneLoaderFlags._CleanBoneMatrixWeights = false;\n SceneLoaderFlags._LoggingLevel = 0;\n\n /**\n * Options used to control default behaviors regarding compatibility support\n */\n class CompatibilityOptions {\n }\n /**\n * Defines if the system should use OpenGL convention for UVs when creating geometry or loading .babylon files (false by default)\n */\n CompatibilityOptions.UseOpenGLOrientationForUV = false;\n\n /**\n * Class used to store geometry data (vertex buffers + index buffer)\n */\n class Geometry {\n /**\n * Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y\n */\n get boundingBias() {\n return this._boundingBias;\n }\n /**\n * Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y\n */\n set boundingBias(value) {\n if (this._boundingBias) {\n this._boundingBias.copyFrom(value);\n }\n else {\n this._boundingBias = value.clone();\n }\n this._updateBoundingInfo(true, null);\n }\n /**\n * Static function used to attach a new empty geometry to a mesh\n * @param mesh defines the mesh to attach the geometry to\n * @returns the new Geometry\n */\n static CreateGeometryForMesh(mesh) {\n const geometry = new Geometry(Geometry.RandomId(), mesh.getScene());\n geometry.applyToMesh(mesh);\n return geometry;\n }\n /** Get the list of meshes using this geometry */\n get meshes() {\n return this._meshes;\n }\n /**\n * Creates a new geometry\n * @param id defines the unique ID\n * @param scene defines the hosting scene\n * @param vertexData defines the VertexData used to get geometry data\n * @param updatable defines if geometry must be updatable (false by default)\n * @param mesh defines the mesh that will be associated with the geometry\n */\n constructor(id, scene, vertexData, updatable = false, mesh = null) {\n /**\n * Gets the delay loading state of the geometry (none by default which means not delayed)\n */\n this.delayLoadState = 0;\n this._totalVertices = 0;\n this._isDisposed = false;\n this._indexBufferIsUpdatable = false;\n this._positionsCache = [];\n /** @internal */\n this._parentContainer = null;\n /**\n * If set to true (false by default), the bounding info applied to the meshes sharing this geometry will be the bounding info defined at the class level\n * and won't be computed based on the vertex positions (which is what we get when useBoundingInfoFromGeometry = false)\n */\n this.useBoundingInfoFromGeometry = false;\n this._scene = scene || EngineStore.LastCreatedScene;\n if (!this._scene) {\n return;\n }\n this.id = id;\n this.uniqueId = this._scene.getUniqueId();\n this._engine = this._scene.getEngine();\n this._meshes = [];\n //Init vertex buffer cache\n this._vertexBuffers = {};\n this._indices = [];\n this._updatable = updatable;\n // vertexData\n if (vertexData) {\n this.setAllVerticesData(vertexData, updatable);\n }\n else {\n this._totalVertices = 0;\n }\n if (this._engine.getCaps().vertexArrayObject) {\n this._vertexArrayObjects = {};\n }\n // applyToMesh\n if (mesh) {\n this.applyToMesh(mesh);\n mesh.computeWorldMatrix(true);\n }\n }\n /**\n * Gets the current extend of the geometry\n */\n get extend() {\n return this._extend;\n }\n /**\n * Gets the hosting scene\n * @returns the hosting Scene\n */\n getScene() {\n return this._scene;\n }\n /**\n * Gets the hosting engine\n * @returns the hosting Engine\n */\n getEngine() {\n return this._engine;\n }\n /**\n * Defines if the geometry is ready to use\n * @returns true if the geometry is ready to be used\n */\n isReady() {\n return this.delayLoadState === 1 || this.delayLoadState === 0;\n }\n /**\n * Gets a value indicating that the geometry should not be serialized\n */\n get doNotSerialize() {\n for (let index = 0; index < this._meshes.length; index++) {\n if (!this._meshes[index].doNotSerialize) {\n return false;\n }\n }\n return true;\n }\n /** @internal */\n _rebuild() {\n if (this._vertexArrayObjects) {\n this._vertexArrayObjects = {};\n }\n // Index buffer\n if (this._meshes.length !== 0 && this._indices) {\n this._indexBuffer = this._engine.createIndexBuffer(this._indices, this._updatable);\n }\n // Vertex buffers\n for (const key in this._vertexBuffers) {\n const vertexBuffer = this._vertexBuffers[key];\n vertexBuffer._rebuild();\n }\n }\n /**\n * Affects all geometry data in one call\n * @param vertexData defines the geometry data\n * @param updatable defines if the geometry must be flagged as updatable (false as default)\n */\n setAllVerticesData(vertexData, updatable) {\n vertexData.applyToGeometry(this, updatable);\n this._notifyUpdate();\n }\n /**\n * Set specific vertex data\n * @param kind defines the data kind (Position, normal, etc...)\n * @param data defines the vertex data to use\n * @param updatable defines if the vertex must be flagged as updatable (false as default)\n * @param stride defines the stride to use (0 by default). This value is deduced from the kind value if not specified\n */\n setVerticesData(kind, data, updatable = false, stride) {\n if (updatable && Array.isArray(data)) {\n // to avoid converting to Float32Array at each draw call in engine.updateDynamicVertexBuffer, we make the conversion a single time here\n data = new Float32Array(data);\n }\n const buffer = new VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);\n this.setVerticesBuffer(buffer);\n }\n /**\n * Removes a specific vertex data\n * @param kind defines the data kind (Position, normal, etc...)\n */\n removeVerticesData(kind) {\n if (this._vertexBuffers[kind]) {\n this._vertexBuffers[kind].dispose();\n delete this._vertexBuffers[kind];\n }\n if (this._vertexArrayObjects) {\n this._disposeVertexArrayObjects();\n }\n }\n /**\n * Affect a vertex buffer to the geometry. the vertexBuffer.getKind() function is used to determine where to store the data\n * @param buffer defines the vertex buffer to use\n * @param totalVertices defines the total number of vertices for position kind (could be null)\n * @param disposeExistingBuffer disposes the existing buffer, if any (default: true)\n */\n setVerticesBuffer(buffer, totalVertices = null, disposeExistingBuffer = true) {\n const kind = buffer.getKind();\n if (this._vertexBuffers[kind] && disposeExistingBuffer) {\n this._vertexBuffers[kind].dispose();\n }\n if (buffer._buffer) {\n buffer._buffer._increaseReferences();\n }\n this._vertexBuffers[kind] = buffer;\n const meshes = this._meshes;\n const numOfMeshes = meshes.length;\n if (kind === VertexBuffer.PositionKind) {\n const data = buffer.getData();\n if (totalVertices != null) {\n this._totalVertices = totalVertices;\n }\n else {\n if (data != null) {\n this._totalVertices = data.length / (buffer.type === VertexBuffer.BYTE ? buffer.byteStride : buffer.byteStride / 4);\n }\n }\n this._updateExtend(data);\n this._resetPointsArrayCache();\n for (let index = 0; index < numOfMeshes; index++) {\n const mesh = meshes[index];\n mesh.buildBoundingInfo(this._extend.minimum, this._extend.maximum);\n mesh._createGlobalSubMesh(mesh.isUnIndexed);\n mesh.computeWorldMatrix(true);\n mesh.synchronizeInstances();\n }\n }\n this._notifyUpdate(kind);\n }\n /**\n * Update a specific vertex buffer\n * This function will directly update the underlying DataBuffer according to the passed numeric array or Float32Array\n * It will do nothing if the buffer is not updatable\n * @param kind defines the data kind (Position, normal, etc...)\n * @param data defines the data to use\n * @param offset defines the offset in the target buffer where to store the data\n * @param useBytes set to true if the offset is in bytes\n */\n updateVerticesDataDirectly(kind, data, offset, useBytes = false) {\n const vertexBuffer = this.getVertexBuffer(kind);\n if (!vertexBuffer) {\n return;\n }\n vertexBuffer.updateDirectly(data, offset, useBytes);\n this._notifyUpdate(kind);\n }\n /**\n * Update a specific vertex buffer\n * This function will create a new buffer if the current one is not updatable\n * @param kind defines the data kind (Position, normal, etc...)\n * @param data defines the data to use\n * @param updateExtends defines if the geometry extends must be recomputed (false by default)\n */\n updateVerticesData(kind, data, updateExtends = false) {\n const vertexBuffer = this.getVertexBuffer(kind);\n if (!vertexBuffer) {\n return;\n }\n vertexBuffer.update(data);\n if (kind === VertexBuffer.PositionKind) {\n this._updateBoundingInfo(updateExtends, data);\n }\n this._notifyUpdate(kind);\n }\n _updateBoundingInfo(updateExtends, data) {\n if (updateExtends) {\n this._updateExtend(data);\n }\n this._resetPointsArrayCache();\n if (updateExtends) {\n const meshes = this._meshes;\n for (const mesh of meshes) {\n if (mesh.hasBoundingInfo) {\n mesh.getBoundingInfo().reConstruct(this._extend.minimum, this._extend.maximum);\n }\n else {\n mesh.buildBoundingInfo(this._extend.minimum, this._extend.maximum);\n }\n const subMeshes = mesh.subMeshes;\n for (const subMesh of subMeshes) {\n subMesh.refreshBoundingInfo();\n }\n }\n }\n }\n /**\n * @internal\n */\n _bind(effect, indexToBind, overrideVertexBuffers, overrideVertexArrayObjects) {\n if (!effect) {\n return;\n }\n if (indexToBind === undefined) {\n indexToBind = this._indexBuffer;\n }\n const vbs = this.getVertexBuffers();\n if (!vbs) {\n return;\n }\n if (indexToBind != this._indexBuffer || (!this._vertexArrayObjects && !overrideVertexArrayObjects)) {\n this._engine.bindBuffers(vbs, indexToBind, effect, overrideVertexBuffers);\n return;\n }\n const vaos = overrideVertexArrayObjects ? overrideVertexArrayObjects : this._vertexArrayObjects;\n // Using VAO\n if (!vaos[effect.key]) {\n vaos[effect.key] = this._engine.recordVertexArrayObject(vbs, indexToBind, effect, overrideVertexBuffers);\n }\n this._engine.bindVertexArrayObject(vaos[effect.key], indexToBind);\n }\n /**\n * Gets total number of vertices\n * @returns the total number of vertices\n */\n getTotalVertices() {\n if (!this.isReady()) {\n return 0;\n }\n return this._totalVertices;\n }\n /**\n * Gets a specific vertex data attached to this geometry. Float data is constructed if the vertex buffer data cannot be returned directly.\n * @param kind defines the data kind (Position, normal, etc...)\n * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\n * @returns a float array containing vertex data\n */\n getVerticesData(kind, copyWhenShared, forceCopy) {\n const vertexBuffer = this.getVertexBuffer(kind);\n if (!vertexBuffer) {\n return null;\n }\n return vertexBuffer.getFloatData(this._totalVertices, forceCopy || (copyWhenShared && this._meshes.length !== 1));\n }\n /**\n * Returns a boolean defining if the vertex data for the requested `kind` is updatable\n * @param kind defines the data kind (Position, normal, etc...)\n * @returns true if the vertex buffer with the specified kind is updatable\n */\n isVertexBufferUpdatable(kind) {\n const vb = this._vertexBuffers[kind];\n if (!vb) {\n return false;\n }\n return vb.isUpdatable();\n }\n /**\n * Gets a specific vertex buffer\n * @param kind defines the data kind (Position, normal, etc...)\n * @returns a VertexBuffer\n */\n getVertexBuffer(kind) {\n if (!this.isReady()) {\n return null;\n }\n return this._vertexBuffers[kind];\n }\n /**\n * Returns all vertex buffers\n * @returns an object holding all vertex buffers indexed by kind\n */\n getVertexBuffers() {\n if (!this.isReady()) {\n return null;\n }\n return this._vertexBuffers;\n }\n /**\n * Gets a boolean indicating if specific vertex buffer is present\n * @param kind defines the data kind (Position, normal, etc...)\n * @returns true if data is present\n */\n isVerticesDataPresent(kind) {\n if (!this._vertexBuffers) {\n if (this._delayInfo) {\n return this._delayInfo.indexOf(kind) !== -1;\n }\n return false;\n }\n return this._vertexBuffers[kind] !== undefined;\n }\n /**\n * Gets a list of all attached data kinds (Position, normal, etc...)\n * @returns a list of string containing all kinds\n */\n getVerticesDataKinds() {\n const result = [];\n let kind;\n if (!this._vertexBuffers && this._delayInfo) {\n for (kind in this._delayInfo) {\n result.push(kind);\n }\n }\n else {\n for (kind in this._vertexBuffers) {\n result.push(kind);\n }\n }\n return result;\n }\n /**\n * Update index buffer\n * @param indices defines the indices to store in the index buffer\n * @param offset defines the offset in the target buffer where to store the data\n * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)\n */\n updateIndices(indices, offset, gpuMemoryOnly = false) {\n if (!this._indexBuffer) {\n return;\n }\n if (!this._indexBufferIsUpdatable) {\n this.setIndices(indices, null, true);\n }\n else {\n const needToUpdateSubMeshes = indices.length !== this._indices.length;\n if (!gpuMemoryOnly) {\n this._indices = indices.slice();\n }\n this._engine.updateDynamicIndexBuffer(this._indexBuffer, indices, offset);\n if (needToUpdateSubMeshes) {\n for (const mesh of this._meshes) {\n mesh._createGlobalSubMesh(true);\n }\n }\n }\n }\n /**\n * Creates a new index buffer\n * @param indices defines the indices to store in the index buffer\n * @param totalVertices defines the total number of vertices (could be null)\n * @param updatable defines if the index buffer must be flagged as updatable (false by default)\n */\n setIndices(indices, totalVertices = null, updatable = false) {\n if (this._indexBuffer) {\n this._engine._releaseBuffer(this._indexBuffer);\n }\n this._indices = indices;\n this._indexBufferIsUpdatable = updatable;\n if (this._meshes.length !== 0 && this._indices) {\n this._indexBuffer = this._engine.createIndexBuffer(this._indices, updatable);\n }\n if (totalVertices != undefined) {\n // including null and undefined\n this._totalVertices = totalVertices;\n }\n for (const mesh of this._meshes) {\n mesh._createGlobalSubMesh(true);\n mesh.synchronizeInstances();\n }\n this._notifyUpdate();\n }\n /**\n * Return the total number of indices\n * @returns the total number of indices\n */\n getTotalIndices() {\n if (!this.isReady()) {\n return 0;\n }\n return this._indices.length;\n }\n /**\n * Gets the index buffer array\n * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\n * @returns the index buffer array\n */\n getIndices(copyWhenShared, forceCopy) {\n if (!this.isReady()) {\n return null;\n }\n const orig = this._indices;\n if (!forceCopy && (!copyWhenShared || this._meshes.length === 1)) {\n return orig;\n }\n else {\n return orig.slice();\n }\n }\n /**\n * Gets the index buffer\n * @returns the index buffer\n */\n getIndexBuffer() {\n if (!this.isReady()) {\n return null;\n }\n return this._indexBuffer;\n }\n /**\n * @internal\n */\n _releaseVertexArrayObject(effect = null) {\n if (!effect || !this._vertexArrayObjects) {\n return;\n }\n if (this._vertexArrayObjects[effect.key]) {\n this._engine.releaseVertexArrayObject(this._vertexArrayObjects[effect.key]);\n delete this._vertexArrayObjects[effect.key];\n }\n }\n /**\n * Release the associated resources for a specific mesh\n * @param mesh defines the source mesh\n * @param shouldDispose defines if the geometry must be disposed if there is no more mesh pointing to it\n */\n releaseForMesh(mesh, shouldDispose) {\n const meshes = this._meshes;\n const index = meshes.indexOf(mesh);\n if (index === -1) {\n return;\n }\n meshes.splice(index, 1);\n if (this._vertexArrayObjects) {\n mesh._invalidateInstanceVertexArrayObject();\n }\n mesh._geometry = null;\n if (meshes.length === 0 && shouldDispose) {\n this.dispose();\n }\n }\n /**\n * Apply current geometry to a given mesh\n * @param mesh defines the mesh to apply geometry to\n */\n applyToMesh(mesh) {\n if (mesh._geometry === this) {\n return;\n }\n const previousGeometry = mesh._geometry;\n if (previousGeometry) {\n previousGeometry.releaseForMesh(mesh);\n }\n if (this._vertexArrayObjects) {\n mesh._invalidateInstanceVertexArrayObject();\n }\n const meshes = this._meshes;\n // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()\n mesh._geometry = this;\n mesh._internalAbstractMeshDataInfo._positions = null;\n this._scene.pushGeometry(this);\n meshes.push(mesh);\n if (this.isReady()) {\n this._applyToMesh(mesh);\n }\n else if (this._boundingInfo) {\n mesh.setBoundingInfo(this._boundingInfo);\n }\n }\n _updateExtend(data = null) {\n if (this.useBoundingInfoFromGeometry && this._boundingInfo) {\n this._extend = {\n minimum: this._boundingInfo.minimum.clone(),\n maximum: this._boundingInfo.maximum.clone(),\n };\n }\n else {\n if (!data) {\n data = this.getVerticesData(VertexBuffer.PositionKind);\n // This can happen if the buffer comes from a Hardware Buffer where\n // The data have not been uploaded by Babylon. (ex: Compute Shaders and Storage Buffers)\n if (!data) {\n return;\n }\n }\n this._extend = extractMinAndMax(data, 0, this._totalVertices, this.boundingBias, 3);\n }\n }\n _applyToMesh(mesh) {\n const numOfMeshes = this._meshes.length;\n // vertexBuffers\n for (const kind in this._vertexBuffers) {\n if (numOfMeshes === 1) {\n this._vertexBuffers[kind].create();\n }\n if (kind === VertexBuffer.PositionKind) {\n if (!this._extend) {\n this._updateExtend();\n }\n mesh.buildBoundingInfo(this._extend.minimum, this._extend.maximum);\n mesh._createGlobalSubMesh(mesh.isUnIndexed);\n //bounding info was just created again, world matrix should be applied again.\n mesh._updateBoundingInfo();\n }\n }\n // indexBuffer\n if (numOfMeshes === 1 && this._indices && this._indices.length > 0) {\n this._indexBuffer = this._engine.createIndexBuffer(this._indices, this._updatable);\n }\n // morphTargets\n mesh._syncGeometryWithMorphTargetManager();\n // instances\n mesh.synchronizeInstances();\n }\n _notifyUpdate(kind) {\n if (this.onGeometryUpdated) {\n this.onGeometryUpdated(this, kind);\n }\n if (this._vertexArrayObjects) {\n this._disposeVertexArrayObjects();\n }\n for (const mesh of this._meshes) {\n mesh._markSubMeshesAsAttributesDirty();\n }\n }\n /**\n * Load the geometry if it was flagged as delay loaded\n * @param scene defines the hosting scene\n * @param onLoaded defines a callback called when the geometry is loaded\n */\n load(scene, onLoaded) {\n if (this.delayLoadState === 2) {\n return;\n }\n if (this.isReady()) {\n if (onLoaded) {\n onLoaded();\n }\n return;\n }\n this.delayLoadState = 2;\n this._queueLoad(scene, onLoaded);\n }\n _queueLoad(scene, onLoaded) {\n if (!this.delayLoadingFile) {\n return;\n }\n scene.addPendingData(this);\n scene._loadFile(this.delayLoadingFile, (data) => {\n if (!this._delayLoadingFunction) {\n return;\n }\n this._delayLoadingFunction(JSON.parse(data), this);\n this.delayLoadState = 1;\n this._delayInfo = [];\n scene.removePendingData(this);\n const meshes = this._meshes;\n const numOfMeshes = meshes.length;\n for (let index = 0; index < numOfMeshes; index++) {\n this._applyToMesh(meshes[index]);\n }\n if (onLoaded) {\n onLoaded();\n }\n }, undefined, true);\n }\n /**\n * Invert the geometry to move from a right handed system to a left handed one.\n */\n toLeftHanded() {\n // Flip faces\n const tIndices = this.getIndices(false);\n if (tIndices != null && tIndices.length > 0) {\n for (let i = 0; i < tIndices.length; i += 3) {\n const tTemp = tIndices[i + 0];\n tIndices[i + 0] = tIndices[i + 2];\n tIndices[i + 2] = tTemp;\n }\n this.setIndices(tIndices);\n }\n // Negate position.z\n const tPositions = this.getVerticesData(VertexBuffer.PositionKind, false);\n if (tPositions != null && tPositions.length > 0) {\n for (let i = 0; i < tPositions.length; i += 3) {\n tPositions[i + 2] = -tPositions[i + 2];\n }\n this.setVerticesData(VertexBuffer.PositionKind, tPositions, false);\n }\n // Negate normal.z\n const tNormals = this.getVerticesData(VertexBuffer.NormalKind, false);\n if (tNormals != null && tNormals.length > 0) {\n for (let i = 0; i < tNormals.length; i += 3) {\n tNormals[i + 2] = -tNormals[i + 2];\n }\n this.setVerticesData(VertexBuffer.NormalKind, tNormals, false);\n }\n }\n // Cache\n /** @internal */\n _resetPointsArrayCache() {\n this._positions = null;\n }\n /** @internal */\n _generatePointsArray() {\n if (this._positions) {\n return true;\n }\n const data = this.getVerticesData(VertexBuffer.PositionKind);\n if (!data || data.length === 0) {\n return false;\n }\n for (let index = this._positionsCache.length * 3, arrayIdx = this._positionsCache.length; index < data.length; index += 3, ++arrayIdx) {\n this._positionsCache[arrayIdx] = Vector3.FromArray(data, index);\n }\n for (let index = 0, arrayIdx = 0; index < data.length; index += 3, ++arrayIdx) {\n this._positionsCache[arrayIdx].set(data[0 + index], data[1 + index], data[2 + index]);\n }\n // just in case the number of positions was reduced, splice the array\n this._positionsCache.length = data.length / 3;\n this._positions = this._positionsCache;\n return true;\n }\n /**\n * Gets a value indicating if the geometry is disposed\n * @returns true if the geometry was disposed\n */\n isDisposed() {\n return this._isDisposed;\n }\n _disposeVertexArrayObjects() {\n if (this._vertexArrayObjects) {\n for (const kind in this._vertexArrayObjects) {\n this._engine.releaseVertexArrayObject(this._vertexArrayObjects[kind]);\n }\n this._vertexArrayObjects = {}; // Will trigger a rebuild of the VAO if supported\n const meshes = this._meshes;\n const numOfMeshes = meshes.length;\n for (let index = 0; index < numOfMeshes; index++) {\n meshes[index]._invalidateInstanceVertexArrayObject();\n }\n }\n }\n /**\n * Free all associated resources\n */\n dispose() {\n const meshes = this._meshes;\n const numOfMeshes = meshes.length;\n let index;\n for (index = 0; index < numOfMeshes; index++) {\n this.releaseForMesh(meshes[index]);\n }\n this._meshes.length = 0;\n this._disposeVertexArrayObjects();\n for (const kind in this._vertexBuffers) {\n this._vertexBuffers[kind].dispose();\n }\n this._vertexBuffers = {};\n this._totalVertices = 0;\n if (this._indexBuffer) {\n this._engine._releaseBuffer(this._indexBuffer);\n }\n this._indexBuffer = null;\n this._indices = [];\n this.delayLoadState = 0;\n this.delayLoadingFile = null;\n this._delayLoadingFunction = null;\n this._delayInfo = [];\n this._boundingInfo = null;\n this._scene.removeGeometry(this);\n if (this._parentContainer) {\n const index = this._parentContainer.geometries.indexOf(this);\n if (index > -1) {\n this._parentContainer.geometries.splice(index, 1);\n }\n this._parentContainer = null;\n }\n this._isDisposed = true;\n }\n /**\n * Clone the current geometry into a new geometry\n * @param id defines the unique ID of the new geometry\n * @returns a new geometry object\n */\n copy(id) {\n const vertexData = new VertexData();\n vertexData.indices = [];\n const indices = this.getIndices();\n if (indices) {\n for (let index = 0; index < indices.length; index++) {\n vertexData.indices.push(indices[index]);\n }\n }\n let updatable = false;\n let stopChecking = false;\n let kind;\n for (kind in this._vertexBuffers) {\n // using slice() to make a copy of the array and not just reference it\n const data = this.getVerticesData(kind);\n if (data) {\n if (data instanceof Float32Array) {\n vertexData.set(new Float32Array(data), kind);\n }\n else {\n vertexData.set(data.slice(0), kind);\n }\n if (!stopChecking) {\n const vb = this.getVertexBuffer(kind);\n if (vb) {\n updatable = vb.isUpdatable();\n stopChecking = !updatable;\n }\n }\n }\n }\n const geometry = new Geometry(id, this._scene, vertexData, updatable);\n geometry.delayLoadState = this.delayLoadState;\n geometry.delayLoadingFile = this.delayLoadingFile;\n geometry._delayLoadingFunction = this._delayLoadingFunction;\n for (kind in this._delayInfo) {\n geometry._delayInfo = geometry._delayInfo || [];\n geometry._delayInfo.push(kind);\n }\n // Bounding info\n geometry._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);\n return geometry;\n }\n /**\n * Serialize the current geometry info (and not the vertices data) into a JSON object\n * @returns a JSON representation of the current geometry data (without the vertices data)\n */\n serialize() {\n const serializationObject = {};\n serializationObject.id = this.id;\n serializationObject.uniqueId = this.uniqueId;\n serializationObject.updatable = this._updatable;\n if (Tags && Tags.HasTags(this)) {\n serializationObject.tags = Tags.GetTags(this);\n }\n return serializationObject;\n }\n _toNumberArray(origin) {\n if (Array.isArray(origin)) {\n return origin;\n }\n else {\n return Array.prototype.slice.call(origin);\n }\n }\n /**\n * Release any memory retained by the cached data on the Geometry.\n *\n * Call this function to reduce memory footprint of the mesh.\n * Vertex buffers will not store CPU data anymore (this will prevent picking, collisions or physics to work correctly)\n */\n clearCachedData() {\n this._indices = [];\n this._resetPointsArrayCache();\n for (const vbName in this._vertexBuffers) {\n if (!Object.prototype.hasOwnProperty.call(this._vertexBuffers, vbName)) {\n continue;\n }\n this._vertexBuffers[vbName]._buffer._data = null;\n }\n }\n /**\n * Serialize all vertices data into a JSON object\n * @returns a JSON representation of the current geometry data\n */\n serializeVerticeData() {\n const serializationObject = this.serialize();\n if (this.isVerticesDataPresent(VertexBuffer.PositionKind)) {\n serializationObject.positions = this._toNumberArray(this.getVerticesData(VertexBuffer.PositionKind));\n if (this.isVertexBufferUpdatable(VertexBuffer.PositionKind)) {\n serializationObject.positions._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n serializationObject.normals = this._toNumberArray(this.getVerticesData(VertexBuffer.NormalKind));\n if (this.isVertexBufferUpdatable(VertexBuffer.NormalKind)) {\n serializationObject.normals._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.TangentKind)) {\n serializationObject.tangents = this._toNumberArray(this.getVerticesData(VertexBuffer.TangentKind));\n if (this.isVertexBufferUpdatable(VertexBuffer.TangentKind)) {\n serializationObject.tangents._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.UVKind)) {\n serializationObject.uvs = this._toNumberArray(this.getVerticesData(VertexBuffer.UVKind));\n if (this.isVertexBufferUpdatable(VertexBuffer.UVKind)) {\n serializationObject.uvs._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\n serializationObject.uv2s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV2Kind));\n if (this.isVertexBufferUpdatable(VertexBuffer.UV2Kind)) {\n serializationObject.uv2s._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.UV3Kind)) {\n serializationObject.uv3s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV3Kind));\n if (this.isVertexBufferUpdatable(VertexBuffer.UV3Kind)) {\n serializationObject.uv3s._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.UV4Kind)) {\n serializationObject.uv4s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV4Kind));\n if (this.isVertexBufferUpdatable(VertexBuffer.UV4Kind)) {\n serializationObject.uv4s._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.UV5Kind)) {\n serializationObject.uv5s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV5Kind));\n if (this.isVertexBufferUpdatable(VertexBuffer.UV5Kind)) {\n serializationObject.uv5s._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.UV6Kind)) {\n serializationObject.uv6s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV6Kind));\n if (this.isVertexBufferUpdatable(VertexBuffer.UV6Kind)) {\n serializationObject.uv6s._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.ColorKind)) {\n serializationObject.colors = this._toNumberArray(this.getVerticesData(VertexBuffer.ColorKind));\n if (this.isVertexBufferUpdatable(VertexBuffer.ColorKind)) {\n serializationObject.colors._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {\n serializationObject.matricesIndices = this._toNumberArray(this.getVerticesData(VertexBuffer.MatricesIndicesKind));\n serializationObject.matricesIndices._isExpanded = true;\n if (this.isVertexBufferUpdatable(VertexBuffer.MatricesIndicesKind)) {\n serializationObject.matricesIndices._updatable = true;\n }\n }\n if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\n serializationObject.matricesWeights = this._toNumberArray(this.getVerticesData(VertexBuffer.MatricesWeightsKind));\n if (this.isVertexBufferUpdatable(VertexBuffer.MatricesWeightsKind)) {\n serializationObject.matricesWeights._updatable = true;\n }\n }\n serializationObject.indices = this._toNumberArray(this.getIndices());\n return serializationObject;\n }\n // Statics\n /**\n * Extracts a clone of a mesh geometry\n * @param mesh defines the source mesh\n * @param id defines the unique ID of the new geometry object\n * @returns the new geometry object\n */\n static ExtractFromMesh(mesh, id) {\n const geometry = mesh._geometry;\n if (!geometry) {\n return null;\n }\n return geometry.copy(id);\n }\n /**\n * You should now use Tools.RandomId(), this method is still here for legacy reasons.\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\n * Be aware Math.random() could cause collisions, but:\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\n * @returns a string containing a new GUID\n */\n static RandomId() {\n return Tools.RandomId();\n }\n static _GetGeometryByLoadedUniqueId(uniqueId, scene) {\n for (let index = 0; index < scene.geometries.length; index++) {\n if (scene.geometries[index]._loadedUniqueId === uniqueId) {\n return scene.geometries[index];\n }\n }\n return null;\n }\n /**\n * @internal\n */\n static _ImportGeometry(parsedGeometry, mesh) {\n const scene = mesh.getScene();\n // Geometry\n const geometryUniqueId = parsedGeometry.geometryUniqueId;\n const geometryId = parsedGeometry.geometryId;\n if (geometryUniqueId || geometryId) {\n const geometry = geometryUniqueId ? this._GetGeometryByLoadedUniqueId(geometryUniqueId, scene) : scene.getGeometryById(geometryId);\n if (geometry) {\n geometry.applyToMesh(mesh);\n }\n }\n else if (parsedGeometry instanceof ArrayBuffer) {\n const binaryInfo = mesh._binaryInfo;\n if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {\n const positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);\n mesh.setVerticesData(VertexBuffer.PositionKind, positionsData, false);\n }\n if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {\n const normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);\n mesh.setVerticesData(VertexBuffer.NormalKind, normalsData, false);\n }\n if (binaryInfo.tangetsAttrDesc && binaryInfo.tangetsAttrDesc.count > 0) {\n const tangentsData = new Float32Array(parsedGeometry, binaryInfo.tangetsAttrDesc.offset, binaryInfo.tangetsAttrDesc.count);\n mesh.setVerticesData(VertexBuffer.TangentKind, tangentsData, false);\n }\n if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {\n const uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n for (let index = 1; index < uvsData.length; index += 2) {\n uvsData[index] = 1 - uvsData[index];\n }\n }\n mesh.setVerticesData(VertexBuffer.UVKind, uvsData, false);\n }\n if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {\n const uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n for (let index = 1; index < uvs2Data.length; index += 2) {\n uvs2Data[index] = 1 - uvs2Data[index];\n }\n }\n mesh.setVerticesData(VertexBuffer.UV2Kind, uvs2Data, false);\n }\n if (binaryInfo.uvs3AttrDesc && binaryInfo.uvs3AttrDesc.count > 0) {\n const uvs3Data = new Float32Array(parsedGeometry, binaryInfo.uvs3AttrDesc.offset, binaryInfo.uvs3AttrDesc.count);\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n for (let index = 1; index < uvs3Data.length; index += 2) {\n uvs3Data[index] = 1 - uvs3Data[index];\n }\n }\n mesh.setVerticesData(VertexBuffer.UV3Kind, uvs3Data, false);\n }\n if (binaryInfo.uvs4AttrDesc && binaryInfo.uvs4AttrDesc.count > 0) {\n const uvs4Data = new Float32Array(parsedGeometry, binaryInfo.uvs4AttrDesc.offset, binaryInfo.uvs4AttrDesc.count);\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n for (let index = 1; index < uvs4Data.length; index += 2) {\n uvs4Data[index] = 1 - uvs4Data[index];\n }\n }\n mesh.setVerticesData(VertexBuffer.UV4Kind, uvs4Data, false);\n }\n if (binaryInfo.uvs5AttrDesc && binaryInfo.uvs5AttrDesc.count > 0) {\n const uvs5Data = new Float32Array(parsedGeometry, binaryInfo.uvs5AttrDesc.offset, binaryInfo.uvs5AttrDesc.count);\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n for (let index = 1; index < uvs5Data.length; index += 2) {\n uvs5Data[index] = 1 - uvs5Data[index];\n }\n }\n mesh.setVerticesData(VertexBuffer.UV5Kind, uvs5Data, false);\n }\n if (binaryInfo.uvs6AttrDesc && binaryInfo.uvs6AttrDesc.count > 0) {\n const uvs6Data = new Float32Array(parsedGeometry, binaryInfo.uvs6AttrDesc.offset, binaryInfo.uvs6AttrDesc.count);\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n for (let index = 1; index < uvs6Data.length; index += 2) {\n uvs6Data[index] = 1 - uvs6Data[index];\n }\n }\n mesh.setVerticesData(VertexBuffer.UV6Kind, uvs6Data, false);\n }\n if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {\n const colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);\n mesh.setVerticesData(VertexBuffer.ColorKind, colorsData, false, binaryInfo.colorsAttrDesc.stride);\n }\n if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {\n const matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);\n const floatIndices = [];\n for (let i = 0; i < matricesIndicesData.length; i++) {\n const index = matricesIndicesData[i];\n floatIndices.push(index & 0x000000ff);\n floatIndices.push((index & 0x0000ff00) >> 8);\n floatIndices.push((index & 0x00ff0000) >> 16);\n floatIndices.push((index >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\n }\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, false);\n }\n if (binaryInfo.matricesIndicesExtraAttrDesc && binaryInfo.matricesIndicesExtraAttrDesc.count > 0) {\n const matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesExtraAttrDesc.offset, binaryInfo.matricesIndicesExtraAttrDesc.count);\n const floatIndices = [];\n for (let i = 0; i < matricesIndicesData.length; i++) {\n const index = matricesIndicesData[i];\n floatIndices.push(index & 0x000000ff);\n floatIndices.push((index & 0x0000ff00) >> 8);\n floatIndices.push((index & 0x00ff0000) >> 16);\n floatIndices.push((index >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\n }\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, false);\n }\n if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {\n const matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);\n mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);\n }\n if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {\n const indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);\n mesh.setIndices(indicesData, null);\n }\n if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {\n const subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);\n mesh.subMeshes = [];\n for (let i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {\n const materialIndex = subMeshesData[i * 5 + 0];\n const verticesStart = subMeshesData[i * 5 + 1];\n const verticesCount = subMeshesData[i * 5 + 2];\n const indexStart = subMeshesData[i * 5 + 3];\n const indexCount = subMeshesData[i * 5 + 4];\n SubMesh.AddToMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);\n }\n }\n }\n else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {\n mesh.setVerticesData(VertexBuffer.PositionKind, parsedGeometry.positions, parsedGeometry.positions._updatable);\n mesh.setVerticesData(VertexBuffer.NormalKind, parsedGeometry.normals, parsedGeometry.normals._updatable);\n if (parsedGeometry.tangents) {\n mesh.setVerticesData(VertexBuffer.TangentKind, parsedGeometry.tangents, parsedGeometry.tangents._updatable);\n }\n if (parsedGeometry.uvs) {\n mesh.setVerticesData(VertexBuffer.UVKind, parsedGeometry.uvs, parsedGeometry.uvs._updatable);\n }\n if (parsedGeometry.uvs2) {\n mesh.setVerticesData(VertexBuffer.UV2Kind, parsedGeometry.uvs2, parsedGeometry.uvs2._updatable);\n }\n if (parsedGeometry.uvs3) {\n mesh.setVerticesData(VertexBuffer.UV3Kind, parsedGeometry.uvs3, parsedGeometry.uvs3._updatable);\n }\n if (parsedGeometry.uvs4) {\n mesh.setVerticesData(VertexBuffer.UV4Kind, parsedGeometry.uvs4, parsedGeometry.uvs4._updatable);\n }\n if (parsedGeometry.uvs5) {\n mesh.setVerticesData(VertexBuffer.UV5Kind, parsedGeometry.uvs5, parsedGeometry.uvs5._updatable);\n }\n if (parsedGeometry.uvs6) {\n mesh.setVerticesData(VertexBuffer.UV6Kind, parsedGeometry.uvs6, parsedGeometry.uvs6._updatable);\n }\n if (parsedGeometry.colors) {\n mesh.setVerticesData(VertexBuffer.ColorKind, Color4.CheckColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), parsedGeometry.colors._updatable);\n }\n if (parsedGeometry.matricesIndices) {\n if (!parsedGeometry.matricesIndices._isExpanded) {\n const floatIndices = [];\n for (let i = 0; i < parsedGeometry.matricesIndices.length; i++) {\n const matricesIndex = parsedGeometry.matricesIndices[i];\n floatIndices.push(matricesIndex & 0x000000ff);\n floatIndices.push((matricesIndex & 0x0000ff00) >> 8);\n floatIndices.push((matricesIndex & 0x00ff0000) >> 16);\n floatIndices.push((matricesIndex >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\n }\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, parsedGeometry.matricesIndices._updatable);\n }\n else {\n delete parsedGeometry.matricesIndices._isExpanded;\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, parsedGeometry.matricesIndices._updatable);\n }\n }\n if (parsedGeometry.matricesIndicesExtra) {\n if (!parsedGeometry.matricesIndicesExtra._isExpanded) {\n const floatIndices = [];\n for (let i = 0; i < parsedGeometry.matricesIndicesExtra.length; i++) {\n const matricesIndex = parsedGeometry.matricesIndicesExtra[i];\n floatIndices.push(matricesIndex & 0x000000ff);\n floatIndices.push((matricesIndex & 0x0000ff00) >> 8);\n floatIndices.push((matricesIndex & 0x00ff0000) >> 16);\n floatIndices.push((matricesIndex >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\n }\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, parsedGeometry.matricesIndicesExtra._updatable);\n }\n else {\n delete parsedGeometry.matricesIndices._isExpanded;\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, parsedGeometry.matricesIndicesExtra, parsedGeometry.matricesIndicesExtra._updatable);\n }\n }\n if (parsedGeometry.matricesWeights) {\n Geometry._CleanMatricesWeights(parsedGeometry, mesh);\n mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);\n }\n if (parsedGeometry.matricesWeightsExtra) {\n mesh.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);\n }\n mesh.setIndices(parsedGeometry.indices, null);\n }\n // SubMeshes\n if (parsedGeometry.subMeshes) {\n mesh.subMeshes = [];\n for (let subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {\n const parsedSubMesh = parsedGeometry.subMeshes[subIndex];\n SubMesh.AddToMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);\n }\n }\n // Flat shading\n if (mesh._shouldGenerateFlatShading) {\n mesh.convertToFlatShadedMesh();\n mesh._shouldGenerateFlatShading = false;\n }\n // Update\n mesh.computeWorldMatrix(true);\n scene.onMeshImportedObservable.notifyObservers(mesh);\n }\n static _CleanMatricesWeights(parsedGeometry, mesh) {\n const epsilon = 1e-3;\n if (!SceneLoaderFlags.CleanBoneMatrixWeights) {\n return;\n }\n let noInfluenceBoneIndex = 0.0;\n if (parsedGeometry.skeletonId > -1) {\n const skeleton = mesh.getScene().getLastSkeletonById(parsedGeometry.skeletonId);\n if (!skeleton) {\n return;\n }\n noInfluenceBoneIndex = skeleton.bones.length;\n }\n else {\n return;\n }\n const matricesIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);\n const matricesIndicesExtra = mesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);\n const matricesWeights = parsedGeometry.matricesWeights;\n const matricesWeightsExtra = parsedGeometry.matricesWeightsExtra;\n const influencers = parsedGeometry.numBoneInfluencer;\n const size = matricesWeights.length;\n for (let i = 0; i < size; i += 4) {\n let weight = 0.0;\n let firstZeroWeight = -1;\n for (let j = 0; j < 4; j++) {\n const w = matricesWeights[i + j];\n weight += w;\n if (w < epsilon && firstZeroWeight < 0) {\n firstZeroWeight = j;\n }\n }\n if (matricesWeightsExtra) {\n for (let j = 0; j < 4; j++) {\n const w = matricesWeightsExtra[i + j];\n weight += w;\n if (w < epsilon && firstZeroWeight < 0) {\n firstZeroWeight = j + 4;\n }\n }\n }\n if (firstZeroWeight < 0 || firstZeroWeight > influencers - 1) {\n firstZeroWeight = influencers - 1;\n }\n if (weight > epsilon) {\n const mweight = 1.0 / weight;\n for (let j = 0; j < 4; j++) {\n matricesWeights[i + j] *= mweight;\n }\n if (matricesWeightsExtra) {\n for (let j = 0; j < 4; j++) {\n matricesWeightsExtra[i + j] *= mweight;\n }\n }\n }\n else {\n if (firstZeroWeight >= 4) {\n matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;\n matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;\n }\n else {\n matricesWeights[i + firstZeroWeight] = 1.0 - weight;\n matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;\n }\n }\n }\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);\n if (parsedGeometry.matricesWeightsExtra) {\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);\n }\n }\n /**\n * Create a new geometry from persisted data (Using .babylon file format)\n * @param parsedVertexData defines the persisted data\n * @param scene defines the hosting scene\n * @param rootUrl defines the root url to use to load assets (like delayed data)\n * @returns the new geometry object\n */\n static Parse(parsedVertexData, scene, rootUrl) {\n const geometry = new Geometry(parsedVertexData.id, scene, undefined, parsedVertexData.updatable);\n geometry._loadedUniqueId = parsedVertexData.uniqueId;\n if (Tags) {\n Tags.AddTagsTo(geometry, parsedVertexData.tags);\n }\n if (parsedVertexData.delayLoadingFile) {\n geometry.delayLoadState = 4;\n geometry.delayLoadingFile = rootUrl + parsedVertexData.delayLoadingFile;\n geometry._boundingInfo = new BoundingInfo(Vector3.FromArray(parsedVertexData.boundingBoxMinimum), Vector3.FromArray(parsedVertexData.boundingBoxMaximum));\n geometry._delayInfo = [];\n if (parsedVertexData.hasUVs) {\n geometry._delayInfo.push(VertexBuffer.UVKind);\n }\n if (parsedVertexData.hasUVs2) {\n geometry._delayInfo.push(VertexBuffer.UV2Kind);\n }\n if (parsedVertexData.hasUVs3) {\n geometry._delayInfo.push(VertexBuffer.UV3Kind);\n }\n if (parsedVertexData.hasUVs4) {\n geometry._delayInfo.push(VertexBuffer.UV4Kind);\n }\n if (parsedVertexData.hasUVs5) {\n geometry._delayInfo.push(VertexBuffer.UV5Kind);\n }\n if (parsedVertexData.hasUVs6) {\n geometry._delayInfo.push(VertexBuffer.UV6Kind);\n }\n if (parsedVertexData.hasColors) {\n geometry._delayInfo.push(VertexBuffer.ColorKind);\n }\n if (parsedVertexData.hasMatricesIndices) {\n geometry._delayInfo.push(VertexBuffer.MatricesIndicesKind);\n }\n if (parsedVertexData.hasMatricesWeights) {\n geometry._delayInfo.push(VertexBuffer.MatricesWeightsKind);\n }\n geometry._delayLoadingFunction = VertexData.ImportVertexData;\n }\n else {\n VertexData.ImportVertexData(parsedVertexData, geometry);\n }\n scene.pushGeometry(geometry, true);\n return geometry;\n }\n }\n\n /**\n * Performance monitor tracks rolling average frame-time and frame-time variance over a user defined sliding-window\n */\n class PerformanceMonitor {\n /**\n * constructor\n * @param frameSampleSize The number of samples required to saturate the sliding window\n */\n constructor(frameSampleSize = 30) {\n this._enabled = true;\n this._rollingFrameTime = new RollingAverage(frameSampleSize);\n }\n /**\n * Samples current frame\n * @param timeMs A timestamp in milliseconds of the current frame to compare with other frames\n */\n sampleFrame(timeMs = PrecisionDate.Now) {\n if (!this._enabled) {\n return;\n }\n if (this._lastFrameTimeMs != null) {\n const dt = timeMs - this._lastFrameTimeMs;\n this._rollingFrameTime.add(dt);\n }\n this._lastFrameTimeMs = timeMs;\n }\n /**\n * Returns the average frame time in milliseconds over the sliding window (or the subset of frames sampled so far)\n */\n get averageFrameTime() {\n return this._rollingFrameTime.average;\n }\n /**\n * Returns the variance frame time in milliseconds over the sliding window (or the subset of frames sampled so far)\n */\n get averageFrameTimeVariance() {\n return this._rollingFrameTime.variance;\n }\n /**\n * Returns the frame time of the most recent frame\n */\n get instantaneousFrameTime() {\n return this._rollingFrameTime.history(0);\n }\n /**\n * Returns the average framerate in frames per second over the sliding window (or the subset of frames sampled so far)\n */\n get averageFPS() {\n return 1000.0 / this._rollingFrameTime.average;\n }\n /**\n * Returns the average framerate in frames per second using the most recent frame time\n */\n get instantaneousFPS() {\n const history = this._rollingFrameTime.history(0);\n if (history === 0) {\n return 0;\n }\n return 1000.0 / history;\n }\n /**\n * Returns true if enough samples have been taken to completely fill the sliding window\n */\n get isSaturated() {\n return this._rollingFrameTime.isSaturated();\n }\n /**\n * Enables contributions to the sliding window sample set\n */\n enable() {\n this._enabled = true;\n }\n /**\n * Disables contributions to the sliding window sample set\n * Samples will not be interpolated over the disabled period\n */\n disable() {\n this._enabled = false;\n //clear last sample to avoid interpolating over the disabled period when next enabled\n this._lastFrameTimeMs = null;\n }\n /**\n * Returns true if sampling is enabled\n */\n get isEnabled() {\n return this._enabled;\n }\n /**\n * Resets performance monitor\n */\n reset() {\n //clear last sample to avoid interpolating over the disabled period when next enabled\n this._lastFrameTimeMs = null;\n //wipe record\n this._rollingFrameTime.reset();\n }\n }\n /**\n * RollingAverage\n *\n * Utility to efficiently compute the rolling average and variance over a sliding window of samples\n */\n class RollingAverage {\n /**\n * constructor\n * @param length The number of samples required to saturate the sliding window\n */\n constructor(length) {\n this._samples = new Array(length);\n this.reset();\n }\n /**\n * Adds a sample to the sample set\n * @param v The sample value\n */\n add(v) {\n //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance\n let delta;\n //we need to check if we've already wrapped round\n if (this.isSaturated()) {\n //remove bottom of stack from mean\n const bottomValue = this._samples[this._pos];\n delta = bottomValue - this.average;\n this.average -= delta / (this._sampleCount - 1);\n this._m2 -= delta * (bottomValue - this.average);\n }\n else {\n this._sampleCount++;\n }\n //add new value to mean\n delta = v - this.average;\n this.average += delta / this._sampleCount;\n this._m2 += delta * (v - this.average);\n //set the new variance\n this.variance = this._m2 / (this._sampleCount - 1);\n this._samples[this._pos] = v;\n this._pos++;\n this._pos %= this._samples.length; //positive wrap around\n }\n /**\n * Returns previously added values or null if outside of history or outside the sliding window domain\n * @param i Index in history. For example, pass 0 for the most recent value and 1 for the value before that\n * @returns Value previously recorded with add() or null if outside of range\n */\n history(i) {\n if (i >= this._sampleCount || i >= this._samples.length) {\n return 0;\n }\n const i0 = this._wrapPosition(this._pos - 1.0);\n return this._samples[this._wrapPosition(i0 - i)];\n }\n /**\n * Returns true if enough samples have been taken to completely fill the sliding window\n * @returns true if sample-set saturated\n */\n isSaturated() {\n return this._sampleCount >= this._samples.length;\n }\n /**\n * Resets the rolling average (equivalent to 0 samples taken so far)\n */\n reset() {\n this.average = 0;\n this.variance = 0;\n this._sampleCount = 0;\n this._pos = 0;\n this._m2 = 0;\n }\n /**\n * Wraps a value around the sample range boundaries\n * @param i Position in sample range, for example if the sample length is 5, and i is -3, then 2 will be returned.\n * @returns Wrapped position in sample range\n */\n _wrapPosition(i) {\n const max = this._samples.length;\n return ((i % max) + max) % max;\n }\n }\n\n ThinEngine.prototype.setAlphaConstants = function (r, g, b, a) {\n this._alphaState.setAlphaBlendConstants(r, g, b, a);\n };\n ThinEngine.prototype.setAlphaMode = function (mode, noDepthWriteChange = false) {\n if (this._alphaMode === mode) {\n if (!noDepthWriteChange) {\n // Make sure we still have the correct depth mask according to the alpha mode (a transparent material could have forced writting to the depth buffer, for instance)\n const depthMask = mode === 0;\n if (this.depthCullingState.depthMask !== depthMask) {\n this.depthCullingState.depthMask = depthMask;\n }\n }\n return;\n }\n switch (mode) {\n case 0:\n this._alphaState.alphaBlend = false;\n break;\n case 7:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 8:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\n this._alphaState.alphaBlend = true;\n break;\n case 2:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 6:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ZERO, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 1:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 3:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 4:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR, this._gl.ZERO, this._gl.ONE, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 5:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 9:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.CONSTANT_COLOR, this._gl.ONE_MINUS_CONSTANT_COLOR, this._gl.CONSTANT_ALPHA, this._gl.ONE_MINUS_CONSTANT_ALPHA);\n this._alphaState.alphaBlend = true;\n break;\n case 10:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\n this._alphaState.alphaBlend = true;\n break;\n case 11:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ONE, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 12:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ZERO);\n this._alphaState.alphaBlend = true;\n break;\n case 13:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE_MINUS_DST_COLOR, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE_MINUS_DST_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA);\n this._alphaState.alphaBlend = true;\n break;\n case 14:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\n this._alphaState.alphaBlend = true;\n break;\n case 15:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ONE, this._gl.ZERO);\n this._alphaState.alphaBlend = true;\n break;\n case 16:\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE_MINUS_DST_COLOR, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ZERO, this._gl.ONE);\n this._alphaState.alphaBlend = true;\n break;\n case 17:\n // Same as ALPHA_COMBINE but accumulates (1 - alpha) values in the alpha channel for a later readout in order independant transparency\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\n this._alphaState.alphaBlend = true;\n break;\n }\n if (!noDepthWriteChange) {\n this.depthCullingState.depthMask = mode === 0;\n }\n this._alphaMode = mode;\n };\n ThinEngine.prototype.getAlphaMode = function () {\n return this._alphaMode;\n };\n ThinEngine.prototype.setAlphaEquation = function (equation) {\n if (this._alphaEquation === equation) {\n return;\n }\n switch (equation) {\n case 0:\n this._alphaState.setAlphaEquationParameters(32774, 32774);\n break;\n case 1:\n this._alphaState.setAlphaEquationParameters(32778, 32778);\n break;\n case 2:\n this._alphaState.setAlphaEquationParameters(32779, 32779);\n break;\n case 3:\n this._alphaState.setAlphaEquationParameters(32776, 32776);\n break;\n case 4:\n this._alphaState.setAlphaEquationParameters(32775, 32775);\n break;\n case 5:\n this._alphaState.setAlphaEquationParameters(32775, 32774);\n break;\n }\n this._alphaEquation = equation;\n };\n ThinEngine.prototype.getAlphaEquation = function () {\n return this._alphaEquation;\n };\n\n /**\n * Allocate a typed array depending on a texture type. Optionally can copy existing data in the buffer.\n * @param type type of the texture\n * @param sizeOrDstBuffer size of the array OR an existing buffer that will be used as the destination of the copy (if copyBuffer is provided)\n * @param sizeInBytes true if the size of the array is given in bytes, false if it is the number of elements of the array\n * @param copyBuffer if provided, buffer to copy into the destination buffer (either a newly allocated buffer if sizeOrDstBuffer is a number or use sizeOrDstBuffer as the destination buffer otherwise)\n * @returns the allocated buffer or sizeOrDstBuffer if the latter is an ArrayBuffer\n */\n function allocateAndCopyTypedBuffer(type, sizeOrDstBuffer, sizeInBytes = false, copyBuffer) {\n switch (type) {\n case 3: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Int8Array(sizeOrDstBuffer) : new Int8Array(sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Int8Array(copyBuffer));\n }\n return buffer;\n }\n case 0: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint8Array(sizeOrDstBuffer) : new Uint8Array(sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Uint8Array(copyBuffer));\n }\n return buffer;\n }\n case 4: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Int16Array(sizeOrDstBuffer) : new Int16Array(sizeInBytes ? sizeOrDstBuffer / 2 : sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Int16Array(copyBuffer));\n }\n return buffer;\n }\n case 5:\n case 8:\n case 9:\n case 10:\n case 2: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint16Array(sizeOrDstBuffer) : new Uint16Array(sizeInBytes ? sizeOrDstBuffer / 2 : sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Uint16Array(copyBuffer));\n }\n return buffer;\n }\n case 6: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Int32Array(sizeOrDstBuffer) : new Int32Array(sizeInBytes ? sizeOrDstBuffer / 4 : sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Int32Array(copyBuffer));\n }\n return buffer;\n }\n case 7:\n case 11:\n case 12:\n case 13:\n case 14:\n case 15: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint32Array(sizeOrDstBuffer) : new Uint32Array(sizeInBytes ? sizeOrDstBuffer / 4 : sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Uint32Array(copyBuffer));\n }\n return buffer;\n }\n case 1: {\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Float32Array(sizeOrDstBuffer) : new Float32Array(sizeInBytes ? sizeOrDstBuffer / 4 : sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Float32Array(copyBuffer));\n }\n return buffer;\n }\n }\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint8Array(sizeOrDstBuffer) : new Uint8Array(sizeOrDstBuffer);\n if (copyBuffer) {\n buffer.set(new Uint8Array(copyBuffer));\n }\n return buffer;\n }\n ThinEngine.prototype._readTexturePixelsSync = function (texture, width, height, faceIndex = -1, level = 0, buffer = null, flushRenderer = true, noDataConversion = false, x = 0, y = 0) {\n var _a, _b;\n const gl = this._gl;\n if (!gl) {\n throw new Error(\"Engine does not have gl rendering context.\");\n }\n if (!this._dummyFramebuffer) {\n const dummy = gl.createFramebuffer();\n if (!dummy) {\n throw new Error(\"Unable to create dummy framebuffer\");\n }\n this._dummyFramebuffer = dummy;\n }\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._dummyFramebuffer);\n if (faceIndex > -1) {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, (_a = texture._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource, level);\n }\n else {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, (_b = texture._hardwareTexture) === null || _b === void 0 ? void 0 : _b.underlyingResource, level);\n }\n let readType = texture.type !== undefined ? this._getWebGLTextureType(texture.type) : gl.UNSIGNED_BYTE;\n if (!noDataConversion) {\n switch (readType) {\n case gl.UNSIGNED_BYTE:\n if (!buffer) {\n buffer = new Uint8Array(4 * width * height);\n }\n readType = gl.UNSIGNED_BYTE;\n break;\n default:\n if (!buffer) {\n buffer = new Float32Array(4 * width * height);\n }\n readType = gl.FLOAT;\n break;\n }\n }\n else if (!buffer) {\n buffer = allocateAndCopyTypedBuffer(texture.type, 4 * width * height);\n }\n if (flushRenderer) {\n this.flushFramebuffer();\n }\n gl.readPixels(x, y, width, height, gl.RGBA, readType, buffer);\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._currentFramebuffer);\n return buffer;\n };\n ThinEngine.prototype._readTexturePixels = function (texture, width, height, faceIndex = -1, level = 0, buffer = null, flushRenderer = true, noDataConversion = false, x = 0, y = 0) {\n return Promise.resolve(this._readTexturePixelsSync(texture, width, height, faceIndex, level, buffer, flushRenderer, noDataConversion, x, y));\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ThinEngine.prototype.updateDynamicIndexBuffer = function (indexBuffer, indices, offset = 0) {\n // Force cache update\n this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER] = null;\n this.bindIndexBuffer(indexBuffer);\n let view;\n if (indexBuffer.is32Bits) {\n // anything else than Uint32Array needs to be converted to Uint32Array\n view = indices instanceof Uint32Array ? indices : new Uint32Array(indices);\n }\n else {\n // anything else than Uint16Array needs to be converted to Uint16Array\n view = indices instanceof Uint16Array ? indices : new Uint16Array(indices);\n }\n this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, view, this._gl.DYNAMIC_DRAW);\n this._resetIndexBufferBinding();\n };\n ThinEngine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, data, byteOffset, byteLength) {\n this.bindArrayBuffer(vertexBuffer);\n if (byteOffset === undefined) {\n byteOffset = 0;\n }\n const dataLength = data.byteLength || data.length;\n if (byteLength === undefined || (byteLength >= dataLength && byteOffset === 0)) {\n if (data instanceof Array) {\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, new Float32Array(data));\n }\n else {\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, data);\n }\n }\n else {\n if (data instanceof Array) {\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(data).subarray(byteOffset, byteOffset + byteLength));\n }\n else {\n if (data instanceof ArrayBuffer) {\n data = new Uint8Array(data, byteOffset, byteLength);\n }\n else {\n data = new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);\n }\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);\n }\n }\n this._resetVertexBufferBinding();\n };\n\n /**\n * The engine class is responsible for interfacing with all lower-level APIs such as WebGL and Audio\n */\n class Engine extends ThinEngine {\n /**\n * Returns the current npm package of the sdk\n */\n // Not mixed with Version for tooling purpose.\n static get NpmPackage() {\n return ThinEngine.NpmPackage;\n }\n /**\n * Returns the current version of the framework\n */\n static get Version() {\n return ThinEngine.Version;\n }\n /** Gets the list of created engines */\n static get Instances() {\n return EngineStore.Instances;\n }\n /**\n * Gets the latest created engine\n */\n static get LastCreatedEngine() {\n return EngineStore.LastCreatedEngine;\n }\n /**\n * Gets the latest created scene\n */\n static get LastCreatedScene() {\n return EngineStore.LastCreatedScene;\n }\n /** @internal */\n /**\n * Engine abstraction for loading and creating an image bitmap from a given source string.\n * @param imageSource source to load the image from.\n * @param options An object that sets options for the image's extraction.\n * @returns ImageBitmap.\n */\n _createImageBitmapFromSource(imageSource, options) {\n const promise = new Promise((resolve, reject) => {\n const image = new Image();\n image.onload = () => {\n image.decode().then(() => {\n this.createImageBitmap(image, options).then((imageBitmap) => {\n resolve(imageBitmap);\n });\n });\n };\n image.onerror = () => {\n reject(`Error loading image ${image.src}`);\n };\n image.src = imageSource;\n });\n return promise;\n }\n /**\n * Engine abstraction for createImageBitmap\n * @param image source for image\n * @param options An object that sets options for the image's extraction.\n * @returns ImageBitmap\n */\n createImageBitmap(image, options) {\n return createImageBitmap(image, options);\n }\n /**\n * Resize an image and returns the image data as an uint8array\n * @param image image to resize\n * @param bufferWidth destination buffer width\n * @param bufferHeight destination buffer height\n * @returns an uint8array containing RGBA values of bufferWidth * bufferHeight size\n */\n resizeImageBitmap(image, bufferWidth, bufferHeight) {\n const canvas = this.createCanvas(bufferWidth, bufferHeight);\n const context = canvas.getContext(\"2d\");\n if (!context) {\n throw new Error(\"Unable to get 2d context for resizeImageBitmap\");\n }\n context.drawImage(image, 0, 0);\n // Create VertexData from map data\n // Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949\n const buffer = context.getImageData(0, 0, bufferWidth, bufferHeight).data;\n return buffer;\n }\n /**\n * Will flag all materials in all scenes in all engines as dirty to trigger new shader compilation\n * @param flag defines which part of the materials must be marked as dirty\n * @param predicate defines a predicate used to filter which materials should be affected\n */\n static MarkAllMaterialsAsDirty(flag, predicate) {\n for (let engineIndex = 0; engineIndex < Engine.Instances.length; engineIndex++) {\n const engine = Engine.Instances[engineIndex];\n for (let sceneIndex = 0; sceneIndex < engine.scenes.length; sceneIndex++) {\n engine.scenes[sceneIndex].markAllMaterialsAsDirty(flag, predicate);\n }\n }\n }\n /**\n * Method called to create the default loading screen.\n * This can be overridden in your own app.\n * @param canvas The rendering canvas element\n * @returns The loading screen\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static DefaultLoadingScreenFactory(canvas) {\n throw _WarnImport(\"LoadingScreen\");\n }\n get _supportsHardwareTextureRescaling() {\n return !!Engine._RescalePostProcessFactory;\n }\n /**\n * Gets the performance monitor attached to this engine\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation\n */\n get performanceMonitor() {\n return this._performanceMonitor;\n }\n /**\n * (WebGPU only) True (default) to be in compatibility mode, meaning rendering all existing scenes without artifacts (same rendering than WebGL).\n * Setting the property to false will improve performances but may not work in some scenes if some precautions are not taken.\n * See https://doc.babylonjs.com/setup/support/webGPU/webGPUOptimization/webGPUNonCompatibilityMode for more details\n */\n get compatibilityMode() {\n return this._compatibilityMode;\n }\n set compatibilityMode(mode) {\n // not supported in WebGL\n this._compatibilityMode = true;\n }\n // Events\n /**\n * Gets the HTML element used to attach event listeners\n * @returns a HTML element\n */\n getInputElement() {\n return this._renderingCanvas;\n }\n /**\n * Creates a new engine\n * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context\n * @param antialias defines enable antialiasing (default: false)\n * @param options defines further options to be sent to the getContext() function\n * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)\n */\n constructor(canvasOrContext, antialias, options, adaptToDeviceRatio = false) {\n super(canvasOrContext, antialias, options, adaptToDeviceRatio);\n // Members\n /**\n * Gets or sets a boolean to enable/disable IndexedDB support and avoid XHR on .manifest\n **/\n this.enableOfflineSupport = false;\n /**\n * Gets or sets a boolean to enable/disable checking manifest if IndexedDB support is enabled (js will always consider the database is up to date)\n **/\n this.disableManifestCheck = false;\n /**\n * Gets or sets a boolean to enable/disable the context menu (right-click) from appearing on the main canvas\n */\n this.disableContextMenu = true;\n /**\n * Gets the list of created scenes\n */\n this.scenes = new Array();\n /** @internal */\n this._virtualScenes = new Array();\n /**\n * Event raised when a new scene is created\n */\n this.onNewSceneAddedObservable = new Observable$1();\n /**\n * Gets the list of created postprocesses\n */\n this.postProcesses = new Array();\n /**\n * Gets a boolean indicating if the pointer is currently locked\n */\n this.isPointerLock = false;\n // Observables\n /**\n * Observable event triggered each time the rendering canvas is resized\n */\n this.onResizeObservable = new Observable$1();\n /**\n * Observable event triggered each time the canvas loses focus\n */\n this.onCanvasBlurObservable = new Observable$1();\n /**\n * Observable event triggered each time the canvas gains focus\n */\n this.onCanvasFocusObservable = new Observable$1();\n /**\n * Observable event triggered each time the canvas receives pointerout event\n */\n this.onCanvasPointerOutObservable = new Observable$1();\n /**\n * Observable raised when the engine begins a new frame\n */\n this.onBeginFrameObservable = new Observable$1();\n /**\n * If set, will be used to request the next animation frame for the render loop\n */\n this.customAnimationFrameRequester = null;\n /**\n * Observable raised when the engine ends the current frame\n */\n this.onEndFrameObservable = new Observable$1();\n /**\n * Observable raised when the engine is about to compile a shader\n */\n this.onBeforeShaderCompilationObservable = new Observable$1();\n /**\n * Observable raised when the engine has just compiled a shader\n */\n this.onAfterShaderCompilationObservable = new Observable$1();\n // Deterministic lockstepMaxSteps\n this._deterministicLockstep = false;\n this._lockstepMaxSteps = 4;\n this._timeStep = 1 / 60;\n // FPS\n this._fps = 60;\n this._deltaTime = 0;\n /** @internal */\n this._drawCalls = new PerfCounter();\n /** Gets or sets the tab index to set to the rendering canvas. 1 is the minimum value to set to be able to capture keyboard events */\n this.canvasTabIndex = 1;\n /**\n * Turn this value on if you want to pause FPS computation when in background\n */\n this.disablePerformanceMonitorInBackground = false;\n this._performanceMonitor = new PerformanceMonitor();\n this._compatibilityMode = true;\n /**\n * Gets or sets the current render pass id\n */\n this.currentRenderPassId = 0;\n this._renderPassNames = [\"main\"];\n Engine.Instances.push(this);\n if (!canvasOrContext) {\n return;\n }\n this._features.supportRenderPasses = true;\n options = this._creationOptions;\n if (canvasOrContext.getContext) {\n const canvas = canvasOrContext;\n this._sharedInit(canvas);\n this._connectVREvents();\n }\n // Load WebVR Devices\n this._prepareVRComponent();\n if (options.autoEnableWebVR) {\n this.initWebVR();\n }\n }\n _initGLContext() {\n super._initGLContext();\n this._rescalePostProcess = null;\n }\n /**\n * Shared initialization across engines types.\n * @param canvas The canvas associated with this instance of the engine.\n */\n _sharedInit(canvas) {\n super._sharedInit(canvas);\n this._onCanvasFocus = () => {\n this.onCanvasFocusObservable.notifyObservers(this);\n };\n this._onCanvasBlur = () => {\n this.onCanvasBlurObservable.notifyObservers(this);\n };\n this._onCanvasContextMenu = (evt) => {\n if (this.disableContextMenu) {\n evt.preventDefault();\n }\n };\n canvas.addEventListener(\"focus\", this._onCanvasFocus);\n canvas.addEventListener(\"blur\", this._onCanvasBlur);\n canvas.addEventListener(\"contextmenu\", this._onCanvasContextMenu);\n this._onBlur = () => {\n if (this.disablePerformanceMonitorInBackground) {\n this._performanceMonitor.disable();\n }\n this._windowIsBackground = true;\n };\n this._onFocus = () => {\n if (this.disablePerformanceMonitorInBackground) {\n this._performanceMonitor.enable();\n }\n this._windowIsBackground = false;\n };\n this._onCanvasPointerOut = (ev) => {\n // Check that the element at the point of the pointer out isn't the canvas and if it isn't, notify observers\n // Note: This is a workaround for a bug with Safari\n if (document.elementFromPoint(ev.clientX, ev.clientY) !== canvas) {\n this.onCanvasPointerOutObservable.notifyObservers(ev);\n }\n };\n const hostWindow = this.getHostWindow(); // it calls IsWindowObjectExist()\n if (hostWindow && typeof hostWindow.addEventListener === \"function\") {\n hostWindow.addEventListener(\"blur\", this._onBlur);\n hostWindow.addEventListener(\"focus\", this._onFocus);\n }\n canvas.addEventListener(\"pointerout\", this._onCanvasPointerOut);\n if (!this._creationOptions.doNotHandleTouchAction) {\n this._disableTouchAction();\n }\n // Create Audio Engine if needed.\n if (!Engine.audioEngine && this._creationOptions.audioEngine && Engine.AudioEngineFactory) {\n Engine.audioEngine = Engine.AudioEngineFactory(this.getRenderingCanvas(), this.getAudioContext(), this.getAudioDestination());\n }\n if (IsDocumentAvailable()) {\n // Fullscreen\n this._onFullscreenChange = () => {\n this.isFullscreen = !!document.fullscreenElement;\n // Pointer lock\n if (this.isFullscreen && this._pointerLockRequested && canvas) {\n Engine._RequestPointerlock(canvas);\n }\n };\n document.addEventListener(\"fullscreenchange\", this._onFullscreenChange, false);\n document.addEventListener(\"webkitfullscreenchange\", this._onFullscreenChange, false);\n // Pointer lock\n this._onPointerLockChange = () => {\n this.isPointerLock = document.pointerLockElement === canvas;\n };\n document.addEventListener(\"pointerlockchange\", this._onPointerLockChange, false);\n document.addEventListener(\"webkitpointerlockchange\", this._onPointerLockChange, false);\n }\n this.enableOfflineSupport = Engine.OfflineProviderFactory !== undefined;\n this._deterministicLockstep = !!this._creationOptions.deterministicLockstep;\n this._lockstepMaxSteps = this._creationOptions.lockstepMaxSteps || 0;\n this._timeStep = this._creationOptions.timeStep || 1 / 60;\n }\n /** @internal */\n _verifyPointerLock() {\n var _a;\n (_a = this._onPointerLockChange) === null || _a === void 0 ? void 0 : _a.call(this);\n }\n /**\n * Gets current aspect ratio\n * @param viewportOwner defines the camera to use to get the aspect ratio\n * @param useScreen defines if screen size must be used (or the current render target if any)\n * @returns a number defining the aspect ratio\n */\n getAspectRatio(viewportOwner, useScreen = false) {\n const viewport = viewportOwner.viewport;\n return (this.getRenderWidth(useScreen) * viewport.width) / (this.getRenderHeight(useScreen) * viewport.height);\n }\n /**\n * Gets current screen aspect ratio\n * @returns a number defining the aspect ratio\n */\n getScreenAspectRatio() {\n return this.getRenderWidth(true) / this.getRenderHeight(true);\n }\n /**\n * Gets the client rect of the HTML canvas attached with the current webGL context\n * @returns a client rectangle\n */\n getRenderingCanvasClientRect() {\n if (!this._renderingCanvas) {\n return null;\n }\n return this._renderingCanvas.getBoundingClientRect();\n }\n /**\n * Gets the client rect of the HTML element used for events\n * @returns a client rectangle\n */\n getInputElementClientRect() {\n if (!this._renderingCanvas) {\n return null;\n }\n return this.getInputElement().getBoundingClientRect();\n }\n /**\n * Gets a boolean indicating that the engine is running in deterministic lock step mode\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n * @returns true if engine is in deterministic lock step mode\n */\n isDeterministicLockStep() {\n return this._deterministicLockstep;\n }\n /**\n * Gets the max steps when engine is running in deterministic lock step\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\n * @returns the max steps\n */\n getLockstepMaxSteps() {\n return this._lockstepMaxSteps;\n }\n /**\n * Returns the time in ms between steps when using deterministic lock step.\n * @returns time step in (ms)\n */\n getTimeStep() {\n return this._timeStep * 1000;\n }\n /**\n * Force the mipmap generation for the given render target texture\n * @param texture defines the render target texture to use\n * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.\n */\n generateMipMapsForCubemap(texture, unbind = true) {\n if (texture.generateMipMaps) {\n const gl = this._gl;\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\n gl.generateMipmap(gl.TEXTURE_CUBE_MAP);\n if (unbind) {\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n }\n }\n }\n /** States */\n /**\n * Gets a boolean indicating if depth writing is enabled\n * @returns the current depth writing state\n */\n getDepthWrite() {\n return this._depthCullingState.depthMask;\n }\n /**\n * Enable or disable depth writing\n * @param enable defines the state to set\n */\n setDepthWrite(enable) {\n this._depthCullingState.depthMask = enable;\n }\n /**\n * Gets a boolean indicating if stencil buffer is enabled\n * @returns the current stencil buffer state\n */\n getStencilBuffer() {\n return this._stencilState.stencilTest;\n }\n /**\n * Enable or disable the stencil buffer\n * @param enable defines if the stencil buffer must be enabled or disabled\n */\n setStencilBuffer(enable) {\n this._stencilState.stencilTest = enable;\n }\n /**\n * Gets the current stencil mask\n * @returns a number defining the new stencil mask to use\n */\n getStencilMask() {\n return this._stencilState.stencilMask;\n }\n /**\n * Sets the current stencil mask\n * @param mask defines the new stencil mask to use\n */\n setStencilMask(mask) {\n this._stencilState.stencilMask = mask;\n }\n /**\n * Gets the current stencil function\n * @returns a number defining the stencil function to use\n */\n getStencilFunction() {\n return this._stencilState.stencilFunc;\n }\n /**\n * Gets the current stencil reference value\n * @returns a number defining the stencil reference value to use\n */\n getStencilFunctionReference() {\n return this._stencilState.stencilFuncRef;\n }\n /**\n * Gets the current stencil mask\n * @returns a number defining the stencil mask to use\n */\n getStencilFunctionMask() {\n return this._stencilState.stencilFuncMask;\n }\n /**\n * Sets the current stencil function\n * @param stencilFunc defines the new stencil function to use\n */\n setStencilFunction(stencilFunc) {\n this._stencilState.stencilFunc = stencilFunc;\n }\n /**\n * Sets the current stencil reference\n * @param reference defines the new stencil reference to use\n */\n setStencilFunctionReference(reference) {\n this._stencilState.stencilFuncRef = reference;\n }\n /**\n * Sets the current stencil mask\n * @param mask defines the new stencil mask to use\n */\n setStencilFunctionMask(mask) {\n this._stencilState.stencilFuncMask = mask;\n }\n /**\n * Gets the current stencil operation when stencil fails\n * @returns a number defining stencil operation to use when stencil fails\n */\n getStencilOperationFail() {\n return this._stencilState.stencilOpStencilFail;\n }\n /**\n * Gets the current stencil operation when depth fails\n * @returns a number defining stencil operation to use when depth fails\n */\n getStencilOperationDepthFail() {\n return this._stencilState.stencilOpDepthFail;\n }\n /**\n * Gets the current stencil operation when stencil passes\n * @returns a number defining stencil operation to use when stencil passes\n */\n getStencilOperationPass() {\n return this._stencilState.stencilOpStencilDepthPass;\n }\n /**\n * Sets the stencil operation to use when stencil fails\n * @param operation defines the stencil operation to use when stencil fails\n */\n setStencilOperationFail(operation) {\n this._stencilState.stencilOpStencilFail = operation;\n }\n /**\n * Sets the stencil operation to use when depth fails\n * @param operation defines the stencil operation to use when depth fails\n */\n setStencilOperationDepthFail(operation) {\n this._stencilState.stencilOpDepthFail = operation;\n }\n /**\n * Sets the stencil operation to use when stencil passes\n * @param operation defines the stencil operation to use when stencil passes\n */\n setStencilOperationPass(operation) {\n this._stencilState.stencilOpStencilDepthPass = operation;\n }\n /**\n * Sets a boolean indicating if the dithering state is enabled or disabled\n * @param value defines the dithering state\n */\n setDitheringState(value) {\n if (value) {\n this._gl.enable(this._gl.DITHER);\n }\n else {\n this._gl.disable(this._gl.DITHER);\n }\n }\n /**\n * Sets a boolean indicating if the rasterizer state is enabled or disabled\n * @param value defines the rasterizer state\n */\n setRasterizerState(value) {\n if (value) {\n this._gl.disable(this._gl.RASTERIZER_DISCARD);\n }\n else {\n this._gl.enable(this._gl.RASTERIZER_DISCARD);\n }\n }\n /**\n * Gets the current depth function\n * @returns a number defining the depth function\n */\n getDepthFunction() {\n return this._depthCullingState.depthFunc;\n }\n /**\n * Sets the current depth function\n * @param depthFunc defines the function to use\n */\n setDepthFunction(depthFunc) {\n this._depthCullingState.depthFunc = depthFunc;\n }\n /**\n * Sets the current depth function to GREATER\n */\n setDepthFunctionToGreater() {\n this.setDepthFunction(516);\n }\n /**\n * Sets the current depth function to GEQUAL\n */\n setDepthFunctionToGreaterOrEqual() {\n this.setDepthFunction(518);\n }\n /**\n * Sets the current depth function to LESS\n */\n setDepthFunctionToLess() {\n this.setDepthFunction(513);\n }\n /**\n * Sets the current depth function to LEQUAL\n */\n setDepthFunctionToLessOrEqual() {\n this.setDepthFunction(515);\n }\n /**\n * Caches the the state of the stencil buffer\n */\n cacheStencilState() {\n this._cachedStencilBuffer = this.getStencilBuffer();\n this._cachedStencilFunction = this.getStencilFunction();\n this._cachedStencilMask = this.getStencilMask();\n this._cachedStencilOperationPass = this.getStencilOperationPass();\n this._cachedStencilOperationFail = this.getStencilOperationFail();\n this._cachedStencilOperationDepthFail = this.getStencilOperationDepthFail();\n this._cachedStencilReference = this.getStencilFunctionReference();\n }\n /**\n * Restores the state of the stencil buffer\n */\n restoreStencilState() {\n this.setStencilFunction(this._cachedStencilFunction);\n this.setStencilMask(this._cachedStencilMask);\n this.setStencilBuffer(this._cachedStencilBuffer);\n this.setStencilOperationPass(this._cachedStencilOperationPass);\n this.setStencilOperationFail(this._cachedStencilOperationFail);\n this.setStencilOperationDepthFail(this._cachedStencilOperationDepthFail);\n this.setStencilFunctionReference(this._cachedStencilReference);\n }\n /**\n * Directly set the WebGL Viewport\n * @param x defines the x coordinate of the viewport (in screen space)\n * @param y defines the y coordinate of the viewport (in screen space)\n * @param width defines the width of the viewport (in screen space)\n * @param height defines the height of the viewport (in screen space)\n * @returns the current viewport Object (if any) that is being replaced by this call. You can restore this viewport later on to go back to the original state\n */\n setDirectViewport(x, y, width, height) {\n const currentViewport = this._cachedViewport;\n this._cachedViewport = null;\n this._viewport(x, y, width, height);\n return currentViewport;\n }\n /**\n * Executes a scissor clear (ie. a clear on a specific portion of the screen)\n * @param x defines the x-coordinate of the bottom left corner of the clear rectangle\n * @param y defines the y-coordinate of the corner of the clear rectangle\n * @param width defines the width of the clear rectangle\n * @param height defines the height of the clear rectangle\n * @param clearColor defines the clear color\n */\n scissorClear(x, y, width, height, clearColor) {\n this.enableScissor(x, y, width, height);\n this.clear(clearColor, true, true, true);\n this.disableScissor();\n }\n /**\n * Enable scissor test on a specific rectangle (ie. render will only be executed on a specific portion of the screen)\n * @param x defines the x-coordinate of the bottom left corner of the clear rectangle\n * @param y defines the y-coordinate of the corner of the clear rectangle\n * @param width defines the width of the clear rectangle\n * @param height defines the height of the clear rectangle\n */\n enableScissor(x, y, width, height) {\n const gl = this._gl;\n // Change state\n gl.enable(gl.SCISSOR_TEST);\n gl.scissor(x, y, width, height);\n }\n /**\n * Disable previously set scissor test rectangle\n */\n disableScissor() {\n const gl = this._gl;\n gl.disable(gl.SCISSOR_TEST);\n }\n /**\n * @internal\n */\n _reportDrawCall(numDrawCalls = 1) {\n this._drawCalls.addCount(numDrawCalls, false);\n }\n /**\n * Initializes a webVR display and starts listening to display change events\n * The onVRDisplayChangedObservable will be notified upon these changes\n * @returns The onVRDisplayChangedObservable\n */\n initWebVR() {\n throw _WarnImport(\"WebVRCamera\");\n }\n /** @internal */\n _prepareVRComponent() {\n // Do nothing as the engine side effect will overload it\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _connectVREvents(canvas, document) {\n // Do nothing as the engine side effect will overload it\n }\n /** @internal */\n _submitVRFrame() {\n // Do nothing as the engine side effect will overload it\n }\n /**\n * Call this function to leave webVR mode\n * Will do nothing if webVR is not supported or if there is no webVR device\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRCamera\n */\n disableVR() {\n // Do nothing as the engine side effect will overload it\n }\n /**\n * Gets a boolean indicating that the system is in VR mode and is presenting\n * @returns true if VR mode is engaged\n */\n isVRPresenting() {\n return false;\n }\n /** @internal */\n _requestVRFrame() {\n // Do nothing as the engine side effect will overload it\n }\n /**\n * @internal\n */\n _loadFileAsync(url, offlineProvider, useArrayBuffer) {\n return new Promise((resolve, reject) => {\n this._loadFile(url, (data) => {\n resolve(data);\n }, undefined, offlineProvider, useArrayBuffer, (request, exception) => {\n reject(exception);\n });\n });\n }\n /**\n * Gets the source code of the vertex shader associated with a specific webGL program\n * @param program defines the program to use\n * @returns a string containing the source code of the vertex shader associated with the program\n */\n getVertexShaderSource(program) {\n const shaders = this._gl.getAttachedShaders(program);\n if (!shaders) {\n return null;\n }\n return this._gl.getShaderSource(shaders[0]);\n }\n /**\n * Gets the source code of the fragment shader associated with a specific webGL program\n * @param program defines the program to use\n * @returns a string containing the source code of the fragment shader associated with the program\n */\n getFragmentShaderSource(program) {\n const shaders = this._gl.getAttachedShaders(program);\n if (!shaders) {\n return null;\n }\n return this._gl.getShaderSource(shaders[1]);\n }\n /**\n * Sets a depth stencil texture from a render target to the according uniform.\n * @param channel The texture channel\n * @param uniform The uniform to set\n * @param texture The render target texture containing the depth stencil texture to apply\n * @param name The texture name\n */\n setDepthStencilTexture(channel, uniform, texture, name) {\n if (channel === undefined) {\n return;\n }\n if (uniform) {\n this._boundUniforms[channel] = uniform;\n }\n if (!texture || !texture.depthStencilTexture) {\n this._setTexture(channel, null, undefined, undefined, name);\n }\n else {\n this._setTexture(channel, texture, false, true, name);\n }\n }\n /**\n * Sets a texture to the webGL context from a postprocess\n * @param channel defines the channel to use\n * @param postProcess defines the source postprocess\n * @param name name of the channel\n */\n setTextureFromPostProcess(channel, postProcess, name) {\n var _a;\n let postProcessInput = null;\n if (postProcess) {\n if (postProcess._forcedOutputTexture) {\n postProcessInput = postProcess._forcedOutputTexture;\n }\n else if (postProcess._textures.data[postProcess._currentRenderTextureInd]) {\n postProcessInput = postProcess._textures.data[postProcess._currentRenderTextureInd];\n }\n }\n this._bindTexture(channel, (_a = postProcessInput === null || postProcessInput === void 0 ? void 0 : postProcessInput.texture) !== null && _a !== void 0 ? _a : null, name);\n }\n /**\n * Binds the output of the passed in post process to the texture channel specified\n * @param channel The channel the texture should be bound to\n * @param postProcess The post process which's output should be bound\n * @param name name of the channel\n */\n setTextureFromPostProcessOutput(channel, postProcess, name) {\n var _a, _b;\n this._bindTexture(channel, (_b = (_a = postProcess === null || postProcess === void 0 ? void 0 : postProcess._outputTexture) === null || _a === void 0 ? void 0 : _a.texture) !== null && _b !== void 0 ? _b : null, name);\n }\n _rebuildBuffers() {\n // Index / Vertex\n for (const scene of this.scenes) {\n scene.resetCachedMaterial();\n scene._rebuildGeometries();\n scene._rebuildTextures();\n }\n for (const scene of this._virtualScenes) {\n scene.resetCachedMaterial();\n scene._rebuildGeometries();\n scene._rebuildTextures();\n }\n super._rebuildBuffers();\n }\n /** @internal */\n _renderFrame() {\n for (let index = 0; index < this._activeRenderLoops.length; index++) {\n const renderFunction = this._activeRenderLoops[index];\n renderFunction();\n }\n }\n _cancelFrame() {\n if (this._renderingQueueLaunched && this.customAnimationFrameRequester) {\n this._renderingQueueLaunched = false;\n const { cancelAnimationFrame } = this.customAnimationFrameRequester;\n if (cancelAnimationFrame) {\n cancelAnimationFrame(this.customAnimationFrameRequester.requestID);\n }\n }\n else {\n super._cancelFrame();\n }\n }\n _renderLoop() {\n if (!this._contextWasLost) {\n let shouldRender = true;\n if (this.isDisposed || (!this.renderEvenInBackground && this._windowIsBackground)) {\n shouldRender = false;\n }\n if (shouldRender) {\n // Start new frame\n this.beginFrame();\n // Child canvases\n if (!this._renderViews()) {\n // Main frame\n this._renderFrame();\n }\n // Present\n this.endFrame();\n }\n }\n if (this._activeRenderLoops.length > 0) {\n // Register new frame\n if (this.customAnimationFrameRequester) {\n this.customAnimationFrameRequester.requestID = this._queueNewFrame(this.customAnimationFrameRequester.renderFunction || this._boundRenderFunction, this.customAnimationFrameRequester);\n this._frameHandler = this.customAnimationFrameRequester.requestID;\n }\n else if (this.isVRPresenting()) {\n this._requestVRFrame();\n }\n else {\n this._frameHandler = this._queueNewFrame(this._boundRenderFunction, this.getHostWindow());\n }\n }\n else {\n this._renderingQueueLaunched = false;\n }\n }\n /** @internal */\n _renderViews() {\n return false;\n }\n /**\n * Toggle full screen mode\n * @param requestPointerLock defines if a pointer lock should be requested from the user\n */\n switchFullscreen(requestPointerLock) {\n if (this.isFullscreen) {\n this.exitFullscreen();\n }\n else {\n this.enterFullscreen(requestPointerLock);\n }\n }\n /**\n * Enters full screen mode\n * @param requestPointerLock defines if a pointer lock should be requested from the user\n */\n enterFullscreen(requestPointerLock) {\n if (!this.isFullscreen) {\n this._pointerLockRequested = requestPointerLock;\n if (this._renderingCanvas) {\n Engine._RequestFullscreen(this._renderingCanvas);\n }\n }\n }\n /**\n * Exits full screen mode\n */\n exitFullscreen() {\n if (this.isFullscreen) {\n Engine._ExitFullscreen();\n }\n }\n /**\n * Enters Pointerlock mode\n */\n enterPointerlock() {\n if (this._renderingCanvas) {\n Engine._RequestPointerlock(this._renderingCanvas);\n }\n }\n /**\n * Exits Pointerlock mode\n */\n exitPointerlock() {\n Engine._ExitPointerlock();\n }\n /**\n * Begin a new frame\n */\n beginFrame() {\n this._measureFps();\n this.onBeginFrameObservable.notifyObservers(this);\n super.beginFrame();\n }\n /**\n * End the current frame\n */\n endFrame() {\n super.endFrame();\n this._submitVRFrame();\n this.onEndFrameObservable.notifyObservers(this);\n }\n /**\n * Resize the view according to the canvas' size\n * @param forceSetSize true to force setting the sizes of the underlying canvas\n */\n resize(forceSetSize = false) {\n // We're not resizing the size of the canvas while in VR mode & presenting\n if (this.isVRPresenting()) {\n return;\n }\n super.resize(forceSetSize);\n }\n /**\n * Force a specific size of the canvas\n * @param width defines the new canvas' width\n * @param height defines the new canvas' height\n * @param forceSetSize true to force setting the sizes of the underlying canvas\n * @returns true if the size was changed\n */\n setSize(width, height, forceSetSize = false) {\n if (!this._renderingCanvas) {\n return false;\n }\n if (!super.setSize(width, height, forceSetSize)) {\n return false;\n }\n if (this.scenes) {\n for (let index = 0; index < this.scenes.length; index++) {\n const scene = this.scenes[index];\n for (let camIndex = 0; camIndex < scene.cameras.length; camIndex++) {\n const cam = scene.cameras[camIndex];\n cam._currentRenderId = 0;\n }\n }\n if (this.onResizeObservable.hasObservers()) {\n this.onResizeObservable.notifyObservers(this);\n }\n }\n return true;\n }\n _deletePipelineContext(pipelineContext) {\n const webGLPipelineContext = pipelineContext;\n if (webGLPipelineContext && webGLPipelineContext.program) {\n if (webGLPipelineContext.transformFeedback) {\n this.deleteTransformFeedback(webGLPipelineContext.transformFeedback);\n webGLPipelineContext.transformFeedback = null;\n }\n }\n super._deletePipelineContext(pipelineContext);\n }\n createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context, transformFeedbackVaryings = null) {\n context = context || this._gl;\n this.onBeforeShaderCompilationObservable.notifyObservers(this);\n const program = super.createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context, transformFeedbackVaryings);\n this.onAfterShaderCompilationObservable.notifyObservers(this);\n return program;\n }\n _createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings = null) {\n const shaderProgram = context.createProgram();\n pipelineContext.program = shaderProgram;\n if (!shaderProgram) {\n throw new Error(\"Unable to create program\");\n }\n context.attachShader(shaderProgram, vertexShader);\n context.attachShader(shaderProgram, fragmentShader);\n if (this.webGLVersion > 1 && transformFeedbackVaryings) {\n const transformFeedback = this.createTransformFeedback();\n this.bindTransformFeedback(transformFeedback);\n this.setTranformFeedbackVaryings(shaderProgram, transformFeedbackVaryings);\n pipelineContext.transformFeedback = transformFeedback;\n }\n context.linkProgram(shaderProgram);\n if (this.webGLVersion > 1 && transformFeedbackVaryings) {\n this.bindTransformFeedback(null);\n }\n pipelineContext.context = context;\n pipelineContext.vertexShader = vertexShader;\n pipelineContext.fragmentShader = fragmentShader;\n if (!pipelineContext.isParallelCompiled) {\n this._finalizePipelineContext(pipelineContext);\n }\n return shaderProgram;\n }\n /**\n * @internal\n */\n _releaseTexture(texture) {\n super._releaseTexture(texture);\n }\n /**\n * @internal\n */\n _releaseRenderTargetWrapper(rtWrapper) {\n super._releaseRenderTargetWrapper(rtWrapper);\n // Set output texture of post process to null if the framebuffer has been released/disposed\n this.scenes.forEach((scene) => {\n scene.postProcesses.forEach((postProcess) => {\n if (postProcess._outputTexture === rtWrapper) {\n postProcess._outputTexture = null;\n }\n });\n scene.cameras.forEach((camera) => {\n camera._postProcesses.forEach((postProcess) => {\n if (postProcess) {\n if (postProcess._outputTexture === rtWrapper) {\n postProcess._outputTexture = null;\n }\n }\n });\n });\n });\n }\n /**\n * Gets the names of the render passes that are currently created\n * @returns list of the render pass names\n */\n getRenderPassNames() {\n return this._renderPassNames;\n }\n /**\n * Gets the name of the current render pass\n * @returns name of the current render pass\n */\n getCurrentRenderPassName() {\n return this._renderPassNames[this.currentRenderPassId];\n }\n /**\n * Creates a render pass id\n * @param name Name of the render pass (for debug purpose only)\n * @returns the id of the new render pass\n */\n createRenderPassId(name) {\n // Note: render pass id == 0 is always for the main render pass\n const id = ++Engine._RenderPassIdCounter;\n this._renderPassNames[id] = name !== null && name !== void 0 ? name : \"NONAME\";\n return id;\n }\n /**\n * Releases a render pass id\n * @param id id of the render pass to release\n */\n releaseRenderPassId(id) {\n this._renderPassNames[id] = undefined;\n for (let s = 0; s < this.scenes.length; ++s) {\n const scene = this.scenes[s];\n for (let m = 0; m < scene.meshes.length; ++m) {\n const mesh = scene.meshes[m];\n if (mesh.subMeshes) {\n for (let b = 0; b < mesh.subMeshes.length; ++b) {\n const subMesh = mesh.subMeshes[b];\n subMesh._removeDrawWrapper(id);\n }\n }\n }\n }\n }\n /**\n * @internal\n * Rescales a texture\n * @param source input texture\n * @param destination destination texture\n * @param scene scene to use to render the resize\n * @param internalFormat format to use when resizing\n * @param onComplete callback to be called when resize has completed\n */\n _rescaleTexture(source, destination, scene, internalFormat, onComplete) {\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR);\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR);\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);\n const rtt = this.createRenderTargetTexture({\n width: destination.width,\n height: destination.height,\n }, {\n generateMipMaps: false,\n type: 0,\n samplingMode: 2,\n generateDepthBuffer: false,\n generateStencilBuffer: false,\n });\n if (!this._rescalePostProcess && Engine._RescalePostProcessFactory) {\n this._rescalePostProcess = Engine._RescalePostProcessFactory(this);\n }\n if (this._rescalePostProcess) {\n this._rescalePostProcess.externalTextureSamplerBinding = true;\n this._rescalePostProcess.getEffect().executeWhenCompiled(() => {\n this._rescalePostProcess.onApply = function (effect) {\n effect._bindTexture(\"textureSampler\", source);\n };\n let hostingScene = scene;\n if (!hostingScene) {\n hostingScene = this.scenes[this.scenes.length - 1];\n }\n hostingScene.postProcessManager.directRender([this._rescalePostProcess], rtt, true);\n this._bindTextureDirectly(this._gl.TEXTURE_2D, destination, true);\n this._gl.copyTexImage2D(this._gl.TEXTURE_2D, 0, internalFormat, 0, 0, destination.width, destination.height, 0);\n this.unBindFramebuffer(rtt);\n rtt.dispose();\n if (onComplete) {\n onComplete();\n }\n });\n }\n }\n // FPS\n /**\n * Gets the current framerate\n * @returns a number representing the framerate\n */\n getFps() {\n return this._fps;\n }\n /**\n * Gets the time spent between current and previous frame\n * @returns a number representing the delta time in ms\n */\n getDeltaTime() {\n return this._deltaTime;\n }\n _measureFps() {\n this._performanceMonitor.sampleFrame();\n this._fps = this._performanceMonitor.averageFPS;\n this._deltaTime = this._performanceMonitor.instantaneousFrameTime || 0;\n }\n /**\n * Wraps an external web gl texture in a Babylon texture.\n * @param texture defines the external texture\n * @param hasMipMaps defines whether the external texture has mip maps (default: false)\n * @param samplingMode defines the sampling mode for the external texture (default: 3)\n * @returns the babylon internal texture\n */\n wrapWebGLTexture(texture, hasMipMaps = false, samplingMode = 3) {\n const hardwareTexture = new WebGLHardwareTexture(texture, this._gl);\n const internalTexture = new InternalTexture(this, InternalTextureSource.Unknown, true);\n internalTexture._hardwareTexture = hardwareTexture;\n internalTexture.isReady = true;\n internalTexture.useMipMaps = hasMipMaps;\n this.updateTextureSamplingMode(samplingMode, internalTexture);\n return internalTexture;\n }\n /**\n * @internal\n */\n _uploadImageToTexture(texture, image, faceIndex = 0, lod = 0) {\n const gl = this._gl;\n const textureType = this._getWebGLTextureType(texture.type);\n const format = this._getInternalFormat(texture.format);\n const internalFormat = this._getRGBABufferInternalSizedFormat(texture.type, format);\n const bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;\n this._bindTextureDirectly(bindTarget, texture, true);\n this._unpackFlipY(texture.invertY);\n let target = gl.TEXTURE_2D;\n if (texture.isCube) {\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\n }\n gl.texImage2D(target, lod, internalFormat, format, textureType, image);\n this._bindTextureDirectly(bindTarget, null, true);\n }\n /**\n * Updates a depth texture Comparison Mode and Function.\n * If the comparison Function is equal to 0, the mode will be set to none.\n * Otherwise, this only works in webgl 2 and requires a shadow sampler in the shader.\n * @param texture The texture to set the comparison function for\n * @param comparisonFunction The comparison function to set, 0 if no comparison required\n */\n updateTextureComparisonFunction(texture, comparisonFunction) {\n if (this.webGLVersion === 1) {\n Logger.Error(\"WebGL 1 does not support texture comparison.\");\n return;\n }\n const gl = this._gl;\n if (texture.isCube) {\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);\n if (comparisonFunction === 0) {\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_FUNC, 515);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_MODE, gl.NONE);\n }\n else {\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);\n }\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\n }\n else {\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\n if (comparisonFunction === 0) {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, 515);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.NONE);\n }\n else {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);\n }\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n }\n texture._comparisonFunction = comparisonFunction;\n }\n /**\n * Creates a webGL buffer to use with instantiation\n * @param capacity defines the size of the buffer\n * @returns the webGL buffer\n */\n createInstancesBuffer(capacity) {\n const buffer = this._gl.createBuffer();\n if (!buffer) {\n throw new Error(\"Unable to create instance buffer\");\n }\n const result = new WebGLDataBuffer(buffer);\n result.capacity = capacity;\n this.bindArrayBuffer(result);\n this._gl.bufferData(this._gl.ARRAY_BUFFER, capacity, this._gl.DYNAMIC_DRAW);\n result.references = 1;\n return result;\n }\n /**\n * Delete a webGL buffer used with instantiation\n * @param buffer defines the webGL buffer to delete\n */\n deleteInstancesBuffer(buffer) {\n this._gl.deleteBuffer(buffer);\n }\n _clientWaitAsync(sync, flags = 0, intervalms = 10) {\n const gl = this._gl;\n return new Promise((resolve, reject) => {\n const check = () => {\n const res = gl.clientWaitSync(sync, flags, 0);\n if (res == gl.WAIT_FAILED) {\n reject();\n return;\n }\n if (res == gl.TIMEOUT_EXPIRED) {\n setTimeout(check, intervalms);\n return;\n }\n resolve();\n };\n check();\n });\n }\n /**\n * @internal\n */\n _readPixelsAsync(x, y, w, h, format, type, outputBuffer) {\n if (this._webGLVersion < 2) {\n throw new Error(\"_readPixelsAsync only work on WebGL2+\");\n }\n const gl = this._gl;\n const buf = gl.createBuffer();\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);\n gl.bufferData(gl.PIXEL_PACK_BUFFER, outputBuffer.byteLength, gl.STREAM_READ);\n gl.readPixels(x, y, w, h, format, type, 0);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);\n if (!sync) {\n return null;\n }\n gl.flush();\n return this._clientWaitAsync(sync, 0, 10).then(() => {\n gl.deleteSync(sync);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);\n gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, outputBuffer);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n gl.deleteBuffer(buf);\n return outputBuffer;\n });\n }\n dispose() {\n this.hideLoadingUI();\n this.onNewSceneAddedObservable.clear();\n // Release postProcesses\n while (this.postProcesses.length) {\n this.postProcesses[0].dispose();\n }\n // Rescale PP\n if (this._rescalePostProcess) {\n this._rescalePostProcess.dispose();\n }\n // Release scenes\n while (this.scenes.length) {\n this.scenes[0].dispose();\n }\n while (this._virtualScenes.length) {\n this._virtualScenes[0].dispose();\n }\n // Release audio engine\n if (EngineStore.Instances.length === 1 && Engine.audioEngine) {\n Engine.audioEngine.dispose();\n Engine.audioEngine = null;\n }\n //WebVR\n this.disableVR();\n // Events\n const hostWindow = this.getHostWindow(); // it calls IsWindowObjectExist()\n if (hostWindow && typeof hostWindow.removeEventListener === \"function\") {\n hostWindow.removeEventListener(\"blur\", this._onBlur);\n hostWindow.removeEventListener(\"focus\", this._onFocus);\n }\n if (this._renderingCanvas) {\n this._renderingCanvas.removeEventListener(\"focus\", this._onCanvasFocus);\n this._renderingCanvas.removeEventListener(\"blur\", this._onCanvasBlur);\n this._renderingCanvas.removeEventListener(\"pointerout\", this._onCanvasPointerOut);\n this._renderingCanvas.removeEventListener(\"contextmenu\", this._onCanvasContextMenu);\n }\n if (IsDocumentAvailable()) {\n document.removeEventListener(\"fullscreenchange\", this._onFullscreenChange);\n document.removeEventListener(\"mozfullscreenchange\", this._onFullscreenChange);\n document.removeEventListener(\"webkitfullscreenchange\", this._onFullscreenChange);\n document.removeEventListener(\"msfullscreenchange\", this._onFullscreenChange);\n document.removeEventListener(\"pointerlockchange\", this._onPointerLockChange);\n document.removeEventListener(\"mspointerlockchange\", this._onPointerLockChange);\n document.removeEventListener(\"mozpointerlockchange\", this._onPointerLockChange);\n document.removeEventListener(\"webkitpointerlockchange\", this._onPointerLockChange);\n }\n super.dispose();\n // Remove from Instances\n const index = EngineStore.Instances.indexOf(this);\n if (index >= 0) {\n EngineStore.Instances.splice(index, 1);\n }\n // no more engines left in the engine store? Notify!\n if (!Engine.Instances.length) {\n EngineStore.OnEnginesDisposedObservable.notifyObservers(this);\n }\n // Observables\n this.onResizeObservable.clear();\n this.onCanvasBlurObservable.clear();\n this.onCanvasFocusObservable.clear();\n this.onCanvasPointerOutObservable.clear();\n this.onBeginFrameObservable.clear();\n this.onEndFrameObservable.clear();\n }\n _disableTouchAction() {\n if (!this._renderingCanvas || !this._renderingCanvas.setAttribute) {\n return;\n }\n this._renderingCanvas.setAttribute(\"touch-action\", \"none\");\n this._renderingCanvas.style.touchAction = \"none\";\n this._renderingCanvas.style.webkitTapHighlightColor = \"transparent\";\n }\n // Loading screen\n /**\n * Display the loading screen\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\n */\n displayLoadingUI() {\n if (!IsWindowObjectExist()) {\n return;\n }\n const loadingScreen = this.loadingScreen;\n if (loadingScreen) {\n loadingScreen.displayLoadingUI();\n }\n }\n /**\n * Hide the loading screen\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\n */\n hideLoadingUI() {\n if (!IsWindowObjectExist()) {\n return;\n }\n const loadingScreen = this._loadingScreen;\n if (loadingScreen) {\n loadingScreen.hideLoadingUI();\n }\n }\n /**\n * Gets the current loading screen object\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\n */\n get loadingScreen() {\n if (!this._loadingScreen && this._renderingCanvas) {\n this._loadingScreen = Engine.DefaultLoadingScreenFactory(this._renderingCanvas);\n }\n return this._loadingScreen;\n }\n /**\n * Sets the current loading screen object\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\n */\n set loadingScreen(loadingScreen) {\n this._loadingScreen = loadingScreen;\n }\n /**\n * Sets the current loading screen text\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\n */\n set loadingUIText(text) {\n this.loadingScreen.loadingUIText = text;\n }\n /**\n * Sets the current loading screen background color\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\n */\n set loadingUIBackgroundColor(color) {\n this.loadingScreen.loadingUIBackgroundColor = color;\n }\n /**\n * creates and returns a new video element\n * @param constraints video constraints\n * @returns video element\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n createVideoElement(constraints) {\n return document.createElement(\"video\");\n }\n /** Pointerlock and fullscreen */\n /**\n * Ask the browser to promote the current element to pointerlock mode\n * @param element defines the DOM element to promote\n */\n static _RequestPointerlock(element) {\n if (element.requestPointerLock) {\n // In some browsers, requestPointerLock returns a promise.\n // Handle possible rejections to avoid an unhandled top-level exception.\n const promise = element.requestPointerLock();\n if (promise instanceof Promise)\n promise\n .then(() => {\n element.focus();\n })\n .catch(() => { });\n else\n element.focus();\n }\n }\n /**\n * Asks the browser to exit pointerlock mode\n */\n static _ExitPointerlock() {\n if (document.exitPointerLock) {\n document.exitPointerLock();\n }\n }\n /**\n * Ask the browser to promote the current element to fullscreen rendering mode\n * @param element defines the DOM element to promote\n */\n static _RequestFullscreen(element) {\n const requestFunction = element.requestFullscreen || element.webkitRequestFullscreen;\n if (!requestFunction) {\n return;\n }\n requestFunction.call(element);\n }\n /**\n * Asks the browser to exit fullscreen mode\n */\n static _ExitFullscreen() {\n const anyDoc = document;\n if (document.exitFullscreen) {\n document.exitFullscreen();\n }\n else if (anyDoc.webkitCancelFullScreen) {\n anyDoc.webkitCancelFullScreen();\n }\n }\n /**\n * Get Font size information\n * @param font font name\n * @returns an object containing ascent, height and descent\n */\n getFontOffset(font) {\n const text = document.createElement(\"span\");\n text.innerHTML = \"Hg\";\n text.setAttribute(\"style\", `font: ${font} !important`);\n const block = document.createElement(\"div\");\n block.style.display = \"inline-block\";\n block.style.width = \"1px\";\n block.style.height = \"0px\";\n block.style.verticalAlign = \"bottom\";\n const div = document.createElement(\"div\");\n div.style.whiteSpace = \"nowrap\";\n div.appendChild(text);\n div.appendChild(block);\n document.body.appendChild(div);\n let fontAscent = 0;\n let fontHeight = 0;\n try {\n fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;\n block.style.verticalAlign = \"baseline\";\n fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;\n }\n finally {\n document.body.removeChild(div);\n }\n return { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };\n }\n }\n // Const statics\n /** Defines that alpha blending is disabled */\n Engine.ALPHA_DISABLE = 0;\n /** Defines that alpha blending to SRC ALPHA * SRC + DEST */\n Engine.ALPHA_ADD = 1;\n /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */\n Engine.ALPHA_COMBINE = 2;\n /** Defines that alpha blending to DEST - SRC * DEST */\n Engine.ALPHA_SUBTRACT = 3;\n /** Defines that alpha blending to SRC * DEST */\n Engine.ALPHA_MULTIPLY = 4;\n /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC) * DEST */\n Engine.ALPHA_MAXIMIZED = 5;\n /** Defines that alpha blending to SRC + DEST */\n Engine.ALPHA_ONEONE = 6;\n /** Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST */\n Engine.ALPHA_PREMULTIPLIED = 7;\n /**\n * Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST\n * Alpha will be set to (1 - SRC ALPHA) * DEST ALPHA\n */\n Engine.ALPHA_PREMULTIPLIED_PORTERDUFF = 8;\n /** Defines that alpha blending to CST * SRC + (1 - CST) * DEST */\n Engine.ALPHA_INTERPOLATE = 9;\n /**\n * Defines that alpha blending to SRC + (1 - SRC) * DEST\n * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DEST ALPHA\n */\n Engine.ALPHA_SCREENMODE = 10;\n /** Defines that the resource is not delayed*/\n Engine.DELAYLOADSTATE_NONE = 0;\n /** Defines that the resource was successfully delay loaded */\n Engine.DELAYLOADSTATE_LOADED = 1;\n /** Defines that the resource is currently delay loading */\n Engine.DELAYLOADSTATE_LOADING = 2;\n /** Defines that the resource is delayed and has not started loading */\n Engine.DELAYLOADSTATE_NOTLOADED = 4;\n // Depht or Stencil test Constants.\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn */\n Engine.NEVER = 512;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */\n Engine.ALWAYS = 519;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value */\n Engine.LESS = 513;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value */\n Engine.EQUAL = 514;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value */\n Engine.LEQUAL = 515;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value */\n Engine.GREATER = 516;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value */\n Engine.GEQUAL = 518;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value */\n Engine.NOTEQUAL = 517;\n // Stencil Actions Constants.\n /** Passed to stencilOperation to specify that stencil value must be kept */\n Engine.KEEP = 7680;\n /** Passed to stencilOperation to specify that stencil value must be replaced */\n Engine.REPLACE = 7681;\n /** Passed to stencilOperation to specify that stencil value must be incremented */\n Engine.INCR = 7682;\n /** Passed to stencilOperation to specify that stencil value must be decremented */\n Engine.DECR = 7683;\n /** Passed to stencilOperation to specify that stencil value must be inverted */\n Engine.INVERT = 5386;\n /** Passed to stencilOperation to specify that stencil value must be incremented with wrapping */\n Engine.INCR_WRAP = 34055;\n /** Passed to stencilOperation to specify that stencil value must be decremented with wrapping */\n Engine.DECR_WRAP = 34056;\n /** Texture is not repeating outside of 0..1 UVs */\n Engine.TEXTURE_CLAMP_ADDRESSMODE = 0;\n /** Texture is repeating outside of 0..1 UVs */\n Engine.TEXTURE_WRAP_ADDRESSMODE = 1;\n /** Texture is repeating and mirrored */\n Engine.TEXTURE_MIRROR_ADDRESSMODE = 2;\n /** ALPHA */\n Engine.TEXTUREFORMAT_ALPHA = 0;\n /** LUMINANCE */\n Engine.TEXTUREFORMAT_LUMINANCE = 1;\n /** LUMINANCE_ALPHA */\n Engine.TEXTUREFORMAT_LUMINANCE_ALPHA = 2;\n /** RGB */\n Engine.TEXTUREFORMAT_RGB = 4;\n /** RGBA */\n Engine.TEXTUREFORMAT_RGBA = 5;\n /** RED */\n Engine.TEXTUREFORMAT_RED = 6;\n /** RED (2nd reference) */\n Engine.TEXTUREFORMAT_R = 6;\n /** RG */\n Engine.TEXTUREFORMAT_RG = 7;\n /** RED_INTEGER */\n Engine.TEXTUREFORMAT_RED_INTEGER = 8;\n /** RED_INTEGER (2nd reference) */\n Engine.TEXTUREFORMAT_R_INTEGER = 8;\n /** RG_INTEGER */\n Engine.TEXTUREFORMAT_RG_INTEGER = 9;\n /** RGB_INTEGER */\n Engine.TEXTUREFORMAT_RGB_INTEGER = 10;\n /** RGBA_INTEGER */\n Engine.TEXTUREFORMAT_RGBA_INTEGER = 11;\n /** UNSIGNED_BYTE */\n Engine.TEXTURETYPE_UNSIGNED_BYTE = 0;\n /** UNSIGNED_BYTE (2nd reference) */\n Engine.TEXTURETYPE_UNSIGNED_INT = 0;\n /** FLOAT */\n Engine.TEXTURETYPE_FLOAT = 1;\n /** HALF_FLOAT */\n Engine.TEXTURETYPE_HALF_FLOAT = 2;\n /** BYTE */\n Engine.TEXTURETYPE_BYTE = 3;\n /** SHORT */\n Engine.TEXTURETYPE_SHORT = 4;\n /** UNSIGNED_SHORT */\n Engine.TEXTURETYPE_UNSIGNED_SHORT = 5;\n /** INT */\n Engine.TEXTURETYPE_INT = 6;\n /** UNSIGNED_INT */\n Engine.TEXTURETYPE_UNSIGNED_INTEGER = 7;\n /** UNSIGNED_SHORT_4_4_4_4 */\n Engine.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4 = 8;\n /** UNSIGNED_SHORT_5_5_5_1 */\n Engine.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1 = 9;\n /** UNSIGNED_SHORT_5_6_5 */\n Engine.TEXTURETYPE_UNSIGNED_SHORT_5_6_5 = 10;\n /** UNSIGNED_INT_2_10_10_10_REV */\n Engine.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV = 11;\n /** UNSIGNED_INT_24_8 */\n Engine.TEXTURETYPE_UNSIGNED_INT_24_8 = 12;\n /** UNSIGNED_INT_10F_11F_11F_REV */\n Engine.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV = 13;\n /** UNSIGNED_INT_5_9_9_9_REV */\n Engine.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV = 14;\n /** FLOAT_32_UNSIGNED_INT_24_8_REV */\n Engine.TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV = 15;\n /** nearest is mag = nearest and min = nearest and mip = none */\n Engine.TEXTURE_NEAREST_SAMPLINGMODE = 1;\n /** Bilinear is mag = linear and min = linear and mip = nearest */\n Engine.TEXTURE_BILINEAR_SAMPLINGMODE = 2;\n /** Trilinear is mag = linear and min = linear and mip = linear */\n Engine.TEXTURE_TRILINEAR_SAMPLINGMODE = 3;\n /** nearest is mag = nearest and min = nearest and mip = linear */\n Engine.TEXTURE_NEAREST_NEAREST_MIPLINEAR = 8;\n /** Bilinear is mag = linear and min = linear and mip = nearest */\n Engine.TEXTURE_LINEAR_LINEAR_MIPNEAREST = 11;\n /** Trilinear is mag = linear and min = linear and mip = linear */\n Engine.TEXTURE_LINEAR_LINEAR_MIPLINEAR = 3;\n /** mag = nearest and min = nearest and mip = nearest */\n Engine.TEXTURE_NEAREST_NEAREST_MIPNEAREST = 4;\n /** mag = nearest and min = linear and mip = nearest */\n Engine.TEXTURE_NEAREST_LINEAR_MIPNEAREST = 5;\n /** mag = nearest and min = linear and mip = linear */\n Engine.TEXTURE_NEAREST_LINEAR_MIPLINEAR = 6;\n /** mag = nearest and min = linear and mip = none */\n Engine.TEXTURE_NEAREST_LINEAR = 7;\n /** mag = nearest and min = nearest and mip = none */\n Engine.TEXTURE_NEAREST_NEAREST = 1;\n /** mag = linear and min = nearest and mip = nearest */\n Engine.TEXTURE_LINEAR_NEAREST_MIPNEAREST = 9;\n /** mag = linear and min = nearest and mip = linear */\n Engine.TEXTURE_LINEAR_NEAREST_MIPLINEAR = 10;\n /** mag = linear and min = linear and mip = none */\n Engine.TEXTURE_LINEAR_LINEAR = 2;\n /** mag = linear and min = nearest and mip = none */\n Engine.TEXTURE_LINEAR_NEAREST = 12;\n /** Explicit coordinates mode */\n Engine.TEXTURE_EXPLICIT_MODE = 0;\n /** Spherical coordinates mode */\n Engine.TEXTURE_SPHERICAL_MODE = 1;\n /** Planar coordinates mode */\n Engine.TEXTURE_PLANAR_MODE = 2;\n /** Cubic coordinates mode */\n Engine.TEXTURE_CUBIC_MODE = 3;\n /** Projection coordinates mode */\n Engine.TEXTURE_PROJECTION_MODE = 4;\n /** Skybox coordinates mode */\n Engine.TEXTURE_SKYBOX_MODE = 5;\n /** Inverse Cubic coordinates mode */\n Engine.TEXTURE_INVCUBIC_MODE = 6;\n /** Equirectangular coordinates mode */\n Engine.TEXTURE_EQUIRECTANGULAR_MODE = 7;\n /** Equirectangular Fixed coordinates mode */\n Engine.TEXTURE_FIXED_EQUIRECTANGULAR_MODE = 8;\n /** Equirectangular Fixed Mirrored coordinates mode */\n Engine.TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;\n // Texture rescaling mode\n /** Defines that texture rescaling will use a floor to find the closer power of 2 size */\n Engine.SCALEMODE_FLOOR = 1;\n /** Defines that texture rescaling will look for the nearest power of 2 size */\n Engine.SCALEMODE_NEAREST = 2;\n /** Defines that texture rescaling will use a ceil to find the closer power of 2 size */\n Engine.SCALEMODE_CEILING = 3;\n /**\n * Method called to create the default rescale post process on each engine.\n */\n Engine._RescalePostProcessFactory = null;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Engine._RenderPassIdCounter = 0;\n\n /** Defines supported spaces */\n var Space;\n (function (Space) {\n /** Local (object) space */\n Space[Space[\"LOCAL\"] = 0] = \"LOCAL\";\n /** World space */\n Space[Space[\"WORLD\"] = 1] = \"WORLD\";\n /** Bone space */\n Space[Space[\"BONE\"] = 2] = \"BONE\";\n })(Space || (Space = {}));\n /** Defines the 3 main axes */\n class Axis {\n }\n /** X axis */\n Axis.X = new Vector3(1.0, 0.0, 0.0);\n /** Y axis */\n Axis.Y = new Vector3(0.0, 1.0, 0.0);\n /** Z axis */\n Axis.Z = new Vector3(0.0, 0.0, 1.0);\n /**\n * Defines cartesian components.\n */\n var Coordinate;\n (function (Coordinate) {\n /** X axis */\n Coordinate[Coordinate[\"X\"] = 0] = \"X\";\n /** Y axis */\n Coordinate[Coordinate[\"Y\"] = 1] = \"Y\";\n /** Z axis */\n Coordinate[Coordinate[\"Z\"] = 2] = \"Z\";\n })(Coordinate || (Coordinate = {}));\n\n const convertRHSToLHS = Matrix.Compose(Vector3.One(), Quaternion.FromEulerAngles(0, Math.PI, 0), Vector3.Zero());\n /**\n * A TransformNode is an object that is not rendered but can be used as a center of transformation. This can decrease memory usage and increase rendering speed compared to using an empty mesh as a parent and is less complicated than using a pivot matrix.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/transform_node\n */\n class TransformNode extends Node {\n /**\n * Gets or sets the billboard mode. Default is 0.\n *\n * | Value | Type | Description |\n * | --- | --- | --- |\n * | 0 | BILLBOARDMODE_NONE | |\n * | 1 | BILLBOARDMODE_X | |\n * | 2 | BILLBOARDMODE_Y | |\n * | 4 | BILLBOARDMODE_Z | |\n * | 7 | BILLBOARDMODE_ALL | |\n *\n */\n get billboardMode() {\n return this._billboardMode;\n }\n set billboardMode(value) {\n if (this._billboardMode === value) {\n return;\n }\n this._billboardMode = value;\n this._cache.useBillboardPosition = (this._billboardMode & TransformNode.BILLBOARDMODE_USE_POSITION) !== 0;\n this._computeUseBillboardPath();\n }\n /**\n * Gets or sets a boolean indicating that parent rotation should be preserved when using billboards.\n * This could be useful for glTF objects where parent rotation helps converting from right handed to left handed\n */\n get preserveParentRotationForBillboard() {\n return this._preserveParentRotationForBillboard;\n }\n set preserveParentRotationForBillboard(value) {\n if (value === this._preserveParentRotationForBillboard) {\n return;\n }\n this._preserveParentRotationForBillboard = value;\n this._computeUseBillboardPath();\n }\n _computeUseBillboardPath() {\n this._cache.useBillboardPath = this._billboardMode !== TransformNode.BILLBOARDMODE_NONE && !this.preserveParentRotationForBillboard;\n }\n /**\n * Gets or sets the distance of the object to max, often used by skybox\n */\n get infiniteDistance() {\n return this._infiniteDistance;\n }\n set infiniteDistance(value) {\n if (this._infiniteDistance === value) {\n return;\n }\n this._infiniteDistance = value;\n }\n constructor(name, scene = null, isPure = true) {\n super(name, scene);\n this._forward = new Vector3(0, 0, 1);\n this._up = new Vector3(0, 1, 0);\n this._right = new Vector3(1, 0, 0);\n // Properties\n this._position = Vector3.Zero();\n this._rotation = Vector3.Zero();\n this._rotationQuaternion = null;\n this._scaling = Vector3.One();\n this._transformToBoneReferal = null;\n this._isAbsoluteSynced = false;\n this._billboardMode = TransformNode.BILLBOARDMODE_NONE;\n this._preserveParentRotationForBillboard = false;\n /**\n * Multiplication factor on scale x/y/z when computing the world matrix. Eg. for a 1x1x1 cube setting this to 2 will make it a 2x2x2 cube\n */\n this.scalingDeterminant = 1;\n this._infiniteDistance = false;\n /**\n * Gets or sets a boolean indicating that non uniform scaling (when at least one component is different from others) should be ignored.\n * By default the system will update normals to compensate\n */\n this.ignoreNonUniformScaling = false;\n /**\n * Gets or sets a boolean indicating that even if rotationQuaternion is defined, you can keep updating rotation property and Babylon.js will just mix both\n */\n this.reIntegrateRotationIntoRotationQuaternion = false;\n // Cache\n /** @internal */\n this._poseMatrix = null;\n /** @internal */\n this._localMatrix = Matrix.Zero();\n this._usePivotMatrix = false;\n this._absolutePosition = Vector3.Zero();\n this._absoluteScaling = Vector3.Zero();\n this._absoluteRotationQuaternion = Quaternion.Identity();\n this._pivotMatrix = Matrix.Identity();\n /** @internal */\n this._postMultiplyPivotMatrix = false;\n this._isWorldMatrixFrozen = false;\n /** @internal */\n this._indexInSceneTransformNodesArray = -1;\n /**\n * An event triggered after the world matrix is updated\n */\n this.onAfterWorldMatrixUpdateObservable = new Observable$1();\n this._nonUniformScaling = false;\n if (isPure) {\n this.getScene().addTransformNode(this);\n }\n }\n /**\n * Gets a string identifying the name of the class\n * @returns \"TransformNode\" string\n */\n getClassName() {\n return \"TransformNode\";\n }\n /**\n * Gets or set the node position (default is (0.0, 0.0, 0.0))\n */\n get position() {\n return this._position;\n }\n set position(newPosition) {\n this._position = newPosition;\n this._isDirty = true;\n }\n /**\n * return true if a pivot has been set\n * @returns true if a pivot matrix is used\n */\n isUsingPivotMatrix() {\n return this._usePivotMatrix;\n }\n /**\n * Gets or sets the rotation property : a Vector3 defining the rotation value in radians around each local axis X, Y, Z (default is (0.0, 0.0, 0.0)).\n * If rotation quaternion is set, this Vector3 will be ignored and copy from the quaternion\n */\n get rotation() {\n return this._rotation;\n }\n set rotation(newRotation) {\n this._rotation = newRotation;\n this._rotationQuaternion = null;\n this._isDirty = true;\n }\n /**\n * Gets or sets the scaling property : a Vector3 defining the node scaling along each local axis X, Y, Z (default is (1.0, 1.0, 1.0)).\n */\n get scaling() {\n return this._scaling;\n }\n set scaling(newScaling) {\n this._scaling = newScaling;\n this._isDirty = true;\n }\n /**\n * Gets or sets the rotation Quaternion property : this a Quaternion object defining the node rotation by using a unit quaternion (undefined by default, but can be null).\n * If set, only the rotationQuaternion is then used to compute the node rotation (ie. node.rotation will be ignored)\n */\n get rotationQuaternion() {\n return this._rotationQuaternion;\n }\n set rotationQuaternion(quaternion) {\n this._rotationQuaternion = quaternion;\n //reset the rotation vector.\n if (quaternion) {\n this._rotation.setAll(0.0);\n }\n this._isDirty = true;\n }\n /**\n * The forward direction of that transform in world space.\n */\n get forward() {\n Vector3.TransformNormalFromFloatsToRef(0, 0, this.getScene().useRightHandedSystem ? -1.0 : 1.0, this.getWorldMatrix(), this._forward);\n return this._forward.normalize();\n }\n /**\n * The up direction of that transform in world space.\n */\n get up() {\n Vector3.TransformNormalFromFloatsToRef(0, 1, 0, this.getWorldMatrix(), this._up);\n return this._up.normalize();\n }\n /**\n * The right direction of that transform in world space.\n */\n get right() {\n Vector3.TransformNormalFromFloatsToRef(this.getScene().useRightHandedSystem ? -1.0 : 1.0, 0, 0, this.getWorldMatrix(), this._right);\n return this._right.normalize();\n }\n /**\n * Copies the parameter passed Matrix into the mesh Pose matrix.\n * @param matrix the matrix to copy the pose from\n * @returns this TransformNode.\n */\n updatePoseMatrix(matrix) {\n if (!this._poseMatrix) {\n this._poseMatrix = matrix.clone();\n return this;\n }\n this._poseMatrix.copyFrom(matrix);\n return this;\n }\n /**\n * Returns the mesh Pose matrix.\n * @returns the pose matrix\n */\n getPoseMatrix() {\n if (!this._poseMatrix) {\n this._poseMatrix = Matrix.Identity();\n }\n return this._poseMatrix;\n }\n /** @internal */\n _isSynchronized() {\n const cache = this._cache;\n if (this._billboardMode !== cache.billboardMode || this._billboardMode !== TransformNode.BILLBOARDMODE_NONE) {\n return false;\n }\n if (cache.pivotMatrixUpdated) {\n return false;\n }\n if (this._infiniteDistance) {\n return false;\n }\n if (this._position._isDirty) {\n return false;\n }\n if (this._scaling._isDirty) {\n return false;\n }\n if ((this._rotationQuaternion && this._rotationQuaternion._isDirty) || this._rotation._isDirty) {\n return false;\n }\n return true;\n }\n /** @internal */\n _initCache() {\n super._initCache();\n const cache = this._cache;\n cache.localMatrixUpdated = false;\n cache.billboardMode = -1;\n cache.infiniteDistance = false;\n cache.useBillboardPosition = false;\n cache.useBillboardPath = false;\n }\n /**\n * Returns the current mesh absolute position.\n * Returns a Vector3.\n */\n get absolutePosition() {\n return this.getAbsolutePosition();\n }\n /**\n * Returns the current mesh absolute scaling.\n * Returns a Vector3.\n */\n get absoluteScaling() {\n this._syncAbsoluteScalingAndRotation();\n return this._absoluteScaling;\n }\n /**\n * Returns the current mesh absolute rotation.\n * Returns a Quaternion.\n */\n get absoluteRotationQuaternion() {\n this._syncAbsoluteScalingAndRotation();\n return this._absoluteRotationQuaternion;\n }\n /**\n * Sets a new matrix to apply before all other transformation\n * @param matrix defines the transform matrix\n * @returns the current TransformNode\n */\n setPreTransformMatrix(matrix) {\n return this.setPivotMatrix(matrix, false);\n }\n /**\n * Sets a new pivot matrix to the current node\n * @param matrix defines the new pivot matrix to use\n * @param postMultiplyPivotMatrix defines if the pivot matrix must be cancelled in the world matrix. When this parameter is set to true (default), the inverse of the pivot matrix is also applied at the end to cancel the transformation effect\n * @returns the current TransformNode\n */\n setPivotMatrix(matrix, postMultiplyPivotMatrix = true) {\n this._pivotMatrix.copyFrom(matrix);\n this._usePivotMatrix = !this._pivotMatrix.isIdentity();\n this._cache.pivotMatrixUpdated = true;\n this._postMultiplyPivotMatrix = postMultiplyPivotMatrix;\n if (this._postMultiplyPivotMatrix) {\n if (!this._pivotMatrixInverse) {\n this._pivotMatrixInverse = Matrix.Invert(this._pivotMatrix);\n }\n else {\n this._pivotMatrix.invertToRef(this._pivotMatrixInverse);\n }\n }\n return this;\n }\n /**\n * Returns the mesh pivot matrix.\n * Default : Identity.\n * @returns the matrix\n */\n getPivotMatrix() {\n return this._pivotMatrix;\n }\n /**\n * Instantiate (when possible) or clone that node with its hierarchy\n * @param newParent defines the new parent to use for the instance (or clone)\n * @param options defines options to configure how copy is done\n * @param options.doNotInstantiate defines if the model must be instantiated or just cloned\n * @param onNewNodeCreated defines an option callback to call when a clone or an instance is created\n * @returns an instance (or a clone) of the current node with its hierarchy\n */\n instantiateHierarchy(newParent = null, options, onNewNodeCreated) {\n const clone = this.clone(\"Clone of \" + (this.name || this.id), newParent || this.parent, true);\n if (clone) {\n if (onNewNodeCreated) {\n onNewNodeCreated(this, clone);\n }\n }\n for (const child of this.getChildTransformNodes(true)) {\n child.instantiateHierarchy(clone, options, onNewNodeCreated);\n }\n return clone;\n }\n /**\n * Prevents the World matrix to be computed any longer\n * @param newWorldMatrix defines an optional matrix to use as world matrix\n * @param decompose defines whether to decompose the given newWorldMatrix or directly assign\n * @returns the TransformNode.\n */\n freezeWorldMatrix(newWorldMatrix = null, decompose = false) {\n if (newWorldMatrix) {\n if (decompose) {\n this._rotation.setAll(0);\n this._rotationQuaternion = this._rotationQuaternion || Quaternion.Identity();\n newWorldMatrix.decompose(this._scaling, this._rotationQuaternion, this._position);\n this.computeWorldMatrix(true);\n }\n else {\n this._worldMatrix = newWorldMatrix;\n this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);\n this._afterComputeWorldMatrix();\n }\n }\n else {\n this._isWorldMatrixFrozen = false; // no guarantee world is not already frozen, switch off temporarily\n this.computeWorldMatrix(true);\n }\n this._isDirty = false;\n this._isWorldMatrixFrozen = true;\n return this;\n }\n /**\n * Allows back the World matrix computation.\n * @returns the TransformNode.\n */\n unfreezeWorldMatrix() {\n this._isWorldMatrixFrozen = false;\n this.computeWorldMatrix(true);\n return this;\n }\n /**\n * True if the World matrix has been frozen.\n */\n get isWorldMatrixFrozen() {\n return this._isWorldMatrixFrozen;\n }\n /**\n * Returns the mesh absolute position in the World.\n * @returns a Vector3.\n */\n getAbsolutePosition() {\n this.computeWorldMatrix();\n return this._absolutePosition;\n }\n /**\n * Sets the mesh absolute position in the World from a Vector3 or an Array(3).\n * @param absolutePosition the absolute position to set\n * @returns the TransformNode.\n */\n setAbsolutePosition(absolutePosition) {\n if (!absolutePosition) {\n return this;\n }\n let absolutePositionX;\n let absolutePositionY;\n let absolutePositionZ;\n if (absolutePosition.x === undefined) {\n if (arguments.length < 3) {\n return this;\n }\n absolutePositionX = arguments[0];\n absolutePositionY = arguments[1];\n absolutePositionZ = arguments[2];\n }\n else {\n absolutePositionX = absolutePosition.x;\n absolutePositionY = absolutePosition.y;\n absolutePositionZ = absolutePosition.z;\n }\n if (this.parent) {\n const invertParentWorldMatrix = TmpVectors.Matrix[0];\n this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);\n Vector3.TransformCoordinatesFromFloatsToRef(absolutePositionX, absolutePositionY, absolutePositionZ, invertParentWorldMatrix, this.position);\n }\n else {\n this.position.x = absolutePositionX;\n this.position.y = absolutePositionY;\n this.position.z = absolutePositionZ;\n }\n this._absolutePosition.copyFrom(absolutePosition);\n return this;\n }\n /**\n * Sets the mesh position in its local space.\n * @param vector3 the position to set in localspace\n * @returns the TransformNode.\n */\n setPositionWithLocalVector(vector3) {\n this.computeWorldMatrix();\n this.position = Vector3.TransformNormal(vector3, this._localMatrix);\n return this;\n }\n /**\n * Returns the mesh position in the local space from the current World matrix values.\n * @returns a new Vector3.\n */\n getPositionExpressedInLocalSpace() {\n this.computeWorldMatrix();\n const invLocalWorldMatrix = TmpVectors.Matrix[0];\n this._localMatrix.invertToRef(invLocalWorldMatrix);\n return Vector3.TransformNormal(this.position, invLocalWorldMatrix);\n }\n /**\n * Translates the mesh along the passed Vector3 in its local space.\n * @param vector3 the distance to translate in localspace\n * @returns the TransformNode.\n */\n locallyTranslate(vector3) {\n this.computeWorldMatrix(true);\n this.position = Vector3.TransformCoordinates(vector3, this._localMatrix);\n return this;\n }\n /**\n * Orients a mesh towards a target point. Mesh must be drawn facing user.\n * @param targetPoint the position (must be in same space as current mesh) to look at\n * @param yawCor optional yaw (y-axis) correction in radians\n * @param pitchCor optional pitch (x-axis) correction in radians\n * @param rollCor optional roll (z-axis) correction in radians\n * @param space the chosen space of the target\n * @returns the TransformNode.\n */\n lookAt(targetPoint, yawCor = 0, pitchCor = 0, rollCor = 0, space = Space.LOCAL) {\n const dv = TransformNode._LookAtVectorCache;\n const pos = space === Space.LOCAL ? this.position : this.getAbsolutePosition();\n targetPoint.subtractToRef(pos, dv);\n this.setDirection(dv, yawCor, pitchCor, rollCor);\n // Correct for parent's rotation offset\n if (space === Space.WORLD && this.parent) {\n if (this.rotationQuaternion) {\n // Get local rotation matrix of the looking object\n const rotationMatrix = TmpVectors.Matrix[0];\n this.rotationQuaternion.toRotationMatrix(rotationMatrix);\n // Offset rotation by parent's inverted rotation matrix to correct in world space\n const parentRotationMatrix = TmpVectors.Matrix[1];\n this.parent.getWorldMatrix().getRotationMatrixToRef(parentRotationMatrix);\n parentRotationMatrix.invert();\n rotationMatrix.multiplyToRef(parentRotationMatrix, rotationMatrix);\n this.rotationQuaternion.fromRotationMatrix(rotationMatrix);\n }\n else {\n // Get local rotation matrix of the looking object\n const quaternionRotation = TmpVectors.Quaternion[0];\n Quaternion.FromEulerVectorToRef(this.rotation, quaternionRotation);\n const rotationMatrix = TmpVectors.Matrix[0];\n quaternionRotation.toRotationMatrix(rotationMatrix);\n // Offset rotation by parent's inverted rotation matrix to correct in world space\n const parentRotationMatrix = TmpVectors.Matrix[1];\n this.parent.getWorldMatrix().getRotationMatrixToRef(parentRotationMatrix);\n parentRotationMatrix.invert();\n rotationMatrix.multiplyToRef(parentRotationMatrix, rotationMatrix);\n quaternionRotation.fromRotationMatrix(rotationMatrix);\n quaternionRotation.toEulerAnglesToRef(this.rotation);\n }\n }\n return this;\n }\n /**\n * Returns a new Vector3 that is the localAxis, expressed in the mesh local space, rotated like the mesh.\n * This Vector3 is expressed in the World space.\n * @param localAxis axis to rotate\n * @returns a new Vector3 that is the localAxis, expressed in the mesh local space, rotated like the mesh.\n */\n getDirection(localAxis) {\n const result = Vector3.Zero();\n this.getDirectionToRef(localAxis, result);\n return result;\n }\n /**\n * Sets the Vector3 \"result\" as the rotated Vector3 \"localAxis\" in the same rotation than the mesh.\n * localAxis is expressed in the mesh local space.\n * result is computed in the World space from the mesh World matrix.\n * @param localAxis axis to rotate\n * @param result the resulting transformnode\n * @returns this TransformNode.\n */\n getDirectionToRef(localAxis, result) {\n Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);\n return this;\n }\n /**\n * Sets this transform node rotation to the given local axis.\n * @param localAxis the axis in local space\n * @param yawCor optional yaw (y-axis) correction in radians\n * @param pitchCor optional pitch (x-axis) correction in radians\n * @param rollCor optional roll (z-axis) correction in radians\n * @returns this TransformNode\n */\n setDirection(localAxis, yawCor = 0, pitchCor = 0, rollCor = 0) {\n const yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\n const pitch = -Math.atan2(localAxis.y, len);\n if (this.rotationQuaternion) {\n Quaternion.RotationYawPitchRollToRef(yaw + yawCor, pitch + pitchCor, rollCor, this.rotationQuaternion);\n }\n else {\n this.rotation.x = pitch + pitchCor;\n this.rotation.y = yaw + yawCor;\n this.rotation.z = rollCor;\n }\n return this;\n }\n /**\n * Sets a new pivot point to the current node\n * @param point defines the new pivot point to use\n * @param space defines if the point is in world or local space (local by default)\n * @returns the current TransformNode\n */\n setPivotPoint(point, space = Space.LOCAL) {\n if (this.getScene().getRenderId() == 0) {\n this.computeWorldMatrix(true);\n }\n const wm = this.getWorldMatrix();\n if (space == Space.WORLD) {\n const tmat = TmpVectors.Matrix[0];\n wm.invertToRef(tmat);\n point = Vector3.TransformCoordinates(point, tmat);\n }\n return this.setPivotMatrix(Matrix.Translation(-point.x, -point.y, -point.z), true);\n }\n /**\n * Returns a new Vector3 set with the mesh pivot point coordinates in the local space.\n * @returns the pivot point\n */\n getPivotPoint() {\n const point = Vector3.Zero();\n this.getPivotPointToRef(point);\n return point;\n }\n /**\n * Sets the passed Vector3 \"result\" with the coordinates of the mesh pivot point in the local space.\n * @param result the vector3 to store the result\n * @returns this TransformNode.\n */\n getPivotPointToRef(result) {\n result.x = -this._pivotMatrix.m[12];\n result.y = -this._pivotMatrix.m[13];\n result.z = -this._pivotMatrix.m[14];\n return this;\n }\n /**\n * Returns a new Vector3 set with the mesh pivot point World coordinates.\n * @returns a new Vector3 set with the mesh pivot point World coordinates.\n */\n getAbsolutePivotPoint() {\n const point = Vector3.Zero();\n this.getAbsolutePivotPointToRef(point);\n return point;\n }\n /**\n * Sets the Vector3 \"result\" coordinates with the mesh pivot point World coordinates.\n * @param result vector3 to store the result\n * @returns this TransformNode.\n */\n getAbsolutePivotPointToRef(result) {\n this.getPivotPointToRef(result);\n Vector3.TransformCoordinatesToRef(result, this.getWorldMatrix(), result);\n return this;\n }\n /**\n * Flag the transform node as dirty (Forcing it to update everything)\n * @param property if set to \"rotation\" the objects rotationQuaternion will be set to null\n * @returns this node\n */\n markAsDirty(property) {\n if (this._isDirty) {\n return this;\n }\n // We need to explicitly update the children\n // as the scene.evaluateActiveMeshes will not poll the transform nodes\n if (this._children) {\n for (const child of this._children) {\n child.markAsDirty(property);\n }\n }\n return super.markAsDirty(property);\n }\n /**\n * Defines the passed node as the parent of the current node.\n * The node will remain exactly where it is and its position / rotation will be updated accordingly.\n * Note that if the mesh has a pivot matrix / point defined it will be applied after the parent was updated.\n * In that case the node will not remain in the same space as it is, as the pivot will be applied.\n * To avoid this, you can set updatePivot to true and the pivot will be updated to identity\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/parent\n * @param node the node ot set as the parent\n * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.\n * @param updatePivot if true, update the pivot matrix to keep the node in the same space as before\n * @returns this TransformNode.\n */\n setParent(node, preserveScalingSign = false, updatePivot = false) {\n if (!node && !this.parent) {\n return this;\n }\n const quatRotation = TmpVectors.Quaternion[0];\n const position = TmpVectors.Vector3[0];\n const scale = TmpVectors.Vector3[1];\n const invParentMatrix = TmpVectors.Matrix[1];\n Matrix.IdentityToRef(invParentMatrix);\n const composedMatrix = TmpVectors.Matrix[0];\n this.computeWorldMatrix(true);\n let currentRotation = this.rotationQuaternion;\n if (!currentRotation) {\n currentRotation = TransformNode._TmpRotation;\n Quaternion.RotationYawPitchRollToRef(this._rotation.y, this._rotation.x, this._rotation.z, currentRotation);\n }\n // current global transformation without pivot\n Matrix.ComposeToRef(this.scaling, currentRotation, this.position, composedMatrix);\n if (this.parent) {\n composedMatrix.multiplyToRef(this.parent.computeWorldMatrix(true), composedMatrix);\n }\n // is a node was set, calculate the difference between this and the node\n if (node) {\n node.computeWorldMatrix(true).invertToRef(invParentMatrix);\n composedMatrix.multiplyToRef(invParentMatrix, composedMatrix);\n }\n composedMatrix.decompose(scale, quatRotation, position, preserveScalingSign ? this : undefined);\n if (this.rotationQuaternion) {\n this.rotationQuaternion.copyFrom(quatRotation);\n }\n else {\n quatRotation.toEulerAnglesToRef(this.rotation);\n }\n this.scaling.copyFrom(scale);\n this.position.copyFrom(position);\n this.parent = node;\n if (updatePivot) {\n this.setPivotMatrix(Matrix.Identity());\n }\n return this;\n }\n /**\n * True if the scaling property of this object is non uniform eg. (1,2,1)\n */\n get nonUniformScaling() {\n return this._nonUniformScaling;\n }\n /**\n * @internal\n */\n _updateNonUniformScalingState(value) {\n if (this._nonUniformScaling === value) {\n return false;\n }\n this._nonUniformScaling = value;\n return true;\n }\n /**\n * Attach the current TransformNode to another TransformNode associated with a bone\n * @param bone Bone affecting the TransformNode\n * @param affectedTransformNode TransformNode associated with the bone\n * @returns this object\n */\n attachToBone(bone, affectedTransformNode) {\n this._currentParentWhenAttachingToBone = this.parent;\n this._transformToBoneReferal = affectedTransformNode;\n this.parent = bone;\n bone.getSkeleton().prepare(); // make sure bone.getFinalMatrix() is up to date\n if (bone.getFinalMatrix().determinant() < 0) {\n this.scalingDeterminant *= -1;\n }\n return this;\n }\n /**\n * Detach the transform node if its associated with a bone\n * @param resetToPreviousParent Indicates if the parent that was in effect when attachToBone was called should be set back or if we should set parent to null instead (defaults to the latter)\n * @returns this object\n */\n detachFromBone(resetToPreviousParent = false) {\n if (!this.parent) {\n if (resetToPreviousParent) {\n this.parent = this._currentParentWhenAttachingToBone;\n }\n return this;\n }\n if (this.parent.getWorldMatrix().determinant() < 0) {\n this.scalingDeterminant *= -1;\n }\n this._transformToBoneReferal = null;\n if (resetToPreviousParent) {\n this.parent = this._currentParentWhenAttachingToBone;\n }\n else {\n this.parent = null;\n }\n return this;\n }\n /**\n * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space.\n * space (default LOCAL) can be either Space.LOCAL, either Space.WORLD.\n * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.\n * The passed axis is also normalized.\n * @param axis the axis to rotate around\n * @param amount the amount to rotate in radians\n * @param space Space to rotate in (Default: local)\n * @returns the TransformNode.\n */\n rotate(axis, amount, space) {\n axis.normalize();\n if (!this.rotationQuaternion) {\n this.rotationQuaternion = this.rotation.toQuaternion();\n this.rotation.setAll(0);\n }\n let rotationQuaternion;\n if (!space || space === Space.LOCAL) {\n rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, TransformNode._RotationAxisCache);\n this.rotationQuaternion.multiplyToRef(rotationQuaternion, this.rotationQuaternion);\n }\n else {\n if (this.parent) {\n const invertParentWorldMatrix = TmpVectors.Matrix[0];\n this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);\n axis = Vector3.TransformNormal(axis, invertParentWorldMatrix);\n }\n rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, TransformNode._RotationAxisCache);\n rotationQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n return this;\n }\n /**\n * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.\n * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.\n * The passed axis is also normalized. .\n * Method is based on http://www.euclideanspace.com/maths/geometry/affine/aroundPoint/index.htm\n * @param point the point to rotate around\n * @param axis the axis to rotate around\n * @param amount the amount to rotate in radians\n * @returns the TransformNode\n */\n rotateAround(point, axis, amount) {\n axis.normalize();\n if (!this.rotationQuaternion) {\n this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);\n this.rotation.setAll(0);\n }\n const tmpVector = TmpVectors.Vector3[0];\n const finalScale = TmpVectors.Vector3[1];\n const finalTranslation = TmpVectors.Vector3[2];\n const finalRotation = TmpVectors.Quaternion[0];\n const translationMatrix = TmpVectors.Matrix[0]; // T\n const translationMatrixInv = TmpVectors.Matrix[1]; // T'\n const rotationMatrix = TmpVectors.Matrix[2]; // R\n const finalMatrix = TmpVectors.Matrix[3]; // T' x R x T\n point.subtractToRef(this.position, tmpVector);\n Matrix.TranslationToRef(tmpVector.x, tmpVector.y, tmpVector.z, translationMatrix); // T\n Matrix.TranslationToRef(-tmpVector.x, -tmpVector.y, -tmpVector.z, translationMatrixInv); // T'\n Matrix.RotationAxisToRef(axis, amount, rotationMatrix); // R\n translationMatrixInv.multiplyToRef(rotationMatrix, finalMatrix); // T' x R\n finalMatrix.multiplyToRef(translationMatrix, finalMatrix); // T' x R x T\n finalMatrix.decompose(finalScale, finalRotation, finalTranslation);\n this.position.addInPlace(finalTranslation);\n finalRotation.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n return this;\n }\n /**\n * Translates the mesh along the axis vector for the passed distance in the given space.\n * space (default LOCAL) can be either Space.LOCAL, either Space.WORLD.\n * @param axis the axis to translate in\n * @param distance the distance to translate\n * @param space Space to rotate in (Default: local)\n * @returns the TransformNode.\n */\n translate(axis, distance, space) {\n const displacementVector = axis.scale(distance);\n if (!space || space === Space.LOCAL) {\n const tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);\n this.setPositionWithLocalVector(tempV3);\n }\n else {\n this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));\n }\n return this;\n }\n /**\n * Adds a rotation step to the mesh current rotation.\n * x, y, z are Euler angles expressed in radians.\n * This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set.\n * This means this rotation is made in the mesh local space only.\n * It's useful to set a custom rotation order different from the BJS standard one YXZ.\n * Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis.\n * ```javascript\n * mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3);\n * ```\n * Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values.\n * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles.\n * @param x Rotation to add\n * @param y Rotation to add\n * @param z Rotation to add\n * @returns the TransformNode.\n */\n addRotation(x, y, z) {\n let rotationQuaternion;\n if (this.rotationQuaternion) {\n rotationQuaternion = this.rotationQuaternion;\n }\n else {\n rotationQuaternion = TmpVectors.Quaternion[1];\n Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, rotationQuaternion);\n }\n const accumulation = TmpVectors.Quaternion[0];\n Quaternion.RotationYawPitchRollToRef(y, x, z, accumulation);\n rotationQuaternion.multiplyInPlace(accumulation);\n if (!this.rotationQuaternion) {\n rotationQuaternion.toEulerAnglesToRef(this.rotation);\n }\n return this;\n }\n /**\n * @internal\n */\n _getEffectiveParent() {\n return this.parent;\n }\n /**\n * Returns whether the transform node world matrix computation needs the camera information to be computed.\n * This is the case when the node is a billboard or has an infinite distance for instance.\n * @returns true if the world matrix computation needs the camera information to be computed\n */\n isWorldMatrixCameraDependent() {\n return (this._infiniteDistance && !this.parent) || (this._billboardMode !== TransformNode.BILLBOARDMODE_NONE && !this.preserveParentRotationForBillboard);\n }\n /**\n * Computes the world matrix of the node\n * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\n * @param camera defines the camera used if different from the scene active camera (This is used with modes like Billboard or infinite distance)\n * @returns the world matrix\n */\n computeWorldMatrix(force = false, camera = null) {\n if (this._isWorldMatrixFrozen && !this._isDirty) {\n return this._worldMatrix;\n }\n const currentRenderId = this.getScene().getRenderId();\n if (!this._isDirty && !force && (this._currentRenderId === currentRenderId || this.isSynchronized())) {\n this._currentRenderId = currentRenderId;\n return this._worldMatrix;\n }\n camera = camera || this.getScene().activeCamera;\n this._updateCache();\n const cache = this._cache;\n cache.pivotMatrixUpdated = false;\n cache.billboardMode = this.billboardMode;\n cache.infiniteDistance = this.infiniteDistance;\n cache.parent = this._parentNode;\n this._currentRenderId = currentRenderId;\n this._childUpdateId += 1;\n this._isDirty = false;\n this._position._isDirty = false;\n this._rotation._isDirty = false;\n this._scaling._isDirty = false;\n const parent = this._getEffectiveParent();\n // Scaling\n const scaling = TransformNode._TmpScaling;\n let translation = this._position;\n // Translation\n if (this._infiniteDistance) {\n if (!this.parent && camera) {\n const cameraWorldMatrix = camera.getWorldMatrix();\n const cameraGlobalPosition = new Vector3(cameraWorldMatrix.m[12], cameraWorldMatrix.m[13], cameraWorldMatrix.m[14]);\n translation = TransformNode._TmpTranslation;\n translation.copyFromFloats(this._position.x + cameraGlobalPosition.x, this._position.y + cameraGlobalPosition.y, this._position.z + cameraGlobalPosition.z);\n }\n }\n // Scaling\n scaling.copyFromFloats(this._scaling.x * this.scalingDeterminant, this._scaling.y * this.scalingDeterminant, this._scaling.z * this.scalingDeterminant);\n // Rotation\n let rotation;\n if (this._rotationQuaternion) {\n this._rotationQuaternion._isDirty = false;\n rotation = this._rotationQuaternion;\n if (this.reIntegrateRotationIntoRotationQuaternion) {\n const len = this.rotation.lengthSquared();\n if (len) {\n this._rotationQuaternion.multiplyInPlace(Quaternion.RotationYawPitchRoll(this._rotation.y, this._rotation.x, this._rotation.z));\n this._rotation.copyFromFloats(0, 0, 0);\n }\n }\n }\n else {\n rotation = TransformNode._TmpRotation;\n Quaternion.RotationYawPitchRollToRef(this._rotation.y, this._rotation.x, this._rotation.z, rotation);\n }\n // Compose\n if (this._usePivotMatrix) {\n const scaleMatrix = TmpVectors.Matrix[1];\n Matrix.ScalingToRef(scaling.x, scaling.y, scaling.z, scaleMatrix);\n // Rotation\n const rotationMatrix = TmpVectors.Matrix[0];\n rotation.toRotationMatrix(rotationMatrix);\n // Composing transformations\n this._pivotMatrix.multiplyToRef(scaleMatrix, TmpVectors.Matrix[4]);\n TmpVectors.Matrix[4].multiplyToRef(rotationMatrix, this._localMatrix);\n // Post multiply inverse of pivotMatrix\n if (this._postMultiplyPivotMatrix) {\n this._localMatrix.multiplyToRef(this._pivotMatrixInverse, this._localMatrix);\n }\n this._localMatrix.addTranslationFromFloats(translation.x, translation.y, translation.z);\n }\n else {\n Matrix.ComposeToRef(scaling, rotation, translation, this._localMatrix);\n }\n // Parent\n if (parent && parent.getWorldMatrix) {\n if (force) {\n parent.computeWorldMatrix(force);\n }\n if (cache.useBillboardPath) {\n if (this._transformToBoneReferal) {\n parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), TmpVectors.Matrix[7]);\n }\n else {\n TmpVectors.Matrix[7].copyFrom(parent.getWorldMatrix());\n }\n // Extract scaling and translation from parent\n const translation = TmpVectors.Vector3[5];\n const scale = TmpVectors.Vector3[6];\n const orientation = TmpVectors.Quaternion[0];\n TmpVectors.Matrix[7].decompose(scale, orientation, translation);\n Matrix.ScalingToRef(scale.x, scale.y, scale.z, TmpVectors.Matrix[7]);\n TmpVectors.Matrix[7].setTranslation(translation);\n if (TransformNode.BillboardUseParentOrientation) {\n // set localMatrix translation to be transformed against parent's orientation.\n this._position.applyRotationQuaternionToRef(orientation, translation);\n this._localMatrix.setTranslation(translation);\n }\n this._localMatrix.multiplyToRef(TmpVectors.Matrix[7], this._worldMatrix);\n }\n else {\n if (this._transformToBoneReferal) {\n this._localMatrix.multiplyToRef(parent.getWorldMatrix(), TmpVectors.Matrix[6]);\n TmpVectors.Matrix[6].multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), this._worldMatrix);\n }\n else {\n this._localMatrix.multiplyToRef(parent.getWorldMatrix(), this._worldMatrix);\n }\n }\n this._markSyncedWithParent();\n }\n else {\n this._worldMatrix.copyFrom(this._localMatrix);\n }\n // Billboarding based on camera orientation (testing PG:http://www.babylonjs-playground.com/#UJEIL#13)\n if (cache.useBillboardPath && camera && this.billboardMode && !cache.useBillboardPosition) {\n const storedTranslation = TmpVectors.Vector3[0];\n this._worldMatrix.getTranslationToRef(storedTranslation); // Save translation\n // Cancel camera rotation\n TmpVectors.Matrix[1].copyFrom(camera.getViewMatrix());\n if (this._scene.useRightHandedSystem) {\n TmpVectors.Matrix[1].multiplyToRef(convertRHSToLHS, TmpVectors.Matrix[1]);\n }\n TmpVectors.Matrix[1].setTranslationFromFloats(0, 0, 0);\n TmpVectors.Matrix[1].invertToRef(TmpVectors.Matrix[0]);\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_ALL) !== TransformNode.BILLBOARDMODE_ALL) {\n TmpVectors.Matrix[0].decompose(undefined, TmpVectors.Quaternion[0], undefined);\n const eulerAngles = TmpVectors.Vector3[1];\n TmpVectors.Quaternion[0].toEulerAnglesToRef(eulerAngles);\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_X) !== TransformNode.BILLBOARDMODE_X) {\n eulerAngles.x = 0;\n }\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Y) !== TransformNode.BILLBOARDMODE_Y) {\n eulerAngles.y = 0;\n }\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Z) !== TransformNode.BILLBOARDMODE_Z) {\n eulerAngles.z = 0;\n }\n Matrix.RotationYawPitchRollToRef(eulerAngles.y, eulerAngles.x, eulerAngles.z, TmpVectors.Matrix[0]);\n }\n this._worldMatrix.setTranslationFromFloats(0, 0, 0);\n this._worldMatrix.multiplyToRef(TmpVectors.Matrix[0], this._worldMatrix);\n // Restore translation\n this._worldMatrix.setTranslation(TmpVectors.Vector3[0]);\n }\n // Billboarding based on camera position\n else if (cache.useBillboardPath && camera && cache.useBillboardPosition) {\n const storedTranslation = TmpVectors.Vector3[0];\n // Save translation\n this._worldMatrix.getTranslationToRef(storedTranslation);\n // Compute camera position in local space\n const cameraPosition = camera.globalPosition;\n this._worldMatrix.invertToRef(TmpVectors.Matrix[1]);\n const camInObjSpace = TmpVectors.Vector3[1];\n Vector3.TransformCoordinatesToRef(cameraPosition, TmpVectors.Matrix[1], camInObjSpace);\n camInObjSpace.normalize();\n // Find the lookAt info in local space\n const yaw = -Math.atan2(camInObjSpace.z, camInObjSpace.x) + Math.PI / 2;\n const len = Math.sqrt(camInObjSpace.x * camInObjSpace.x + camInObjSpace.z * camInObjSpace.z);\n const pitch = -Math.atan2(camInObjSpace.y, len);\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, 0, TmpVectors.Quaternion[0]);\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_ALL) !== TransformNode.BILLBOARDMODE_ALL) {\n const eulerAngles = TmpVectors.Vector3[1];\n TmpVectors.Quaternion[0].toEulerAnglesToRef(eulerAngles);\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_X) !== TransformNode.BILLBOARDMODE_X) {\n eulerAngles.x = 0;\n }\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Y) !== TransformNode.BILLBOARDMODE_Y) {\n eulerAngles.y = 0;\n }\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Z) !== TransformNode.BILLBOARDMODE_Z) {\n eulerAngles.z = 0;\n }\n Matrix.RotationYawPitchRollToRef(eulerAngles.y, eulerAngles.x, eulerAngles.z, TmpVectors.Matrix[0]);\n }\n else {\n Matrix.FromQuaternionToRef(TmpVectors.Quaternion[0], TmpVectors.Matrix[0]);\n }\n // Cancel translation\n this._worldMatrix.setTranslationFromFloats(0, 0, 0);\n // Rotate according to lookat (diff from local to lookat)\n this._worldMatrix.multiplyToRef(TmpVectors.Matrix[0], this._worldMatrix);\n // Restore translation\n this._worldMatrix.setTranslation(TmpVectors.Vector3[0]);\n }\n // Normal matrix\n if (!this.ignoreNonUniformScaling) {\n if (this._scaling.isNonUniformWithinEpsilon(0.000001)) {\n this._updateNonUniformScalingState(true);\n }\n else if (parent && parent._nonUniformScaling) {\n this._updateNonUniformScalingState(parent._nonUniformScaling);\n }\n else {\n this._updateNonUniformScalingState(false);\n }\n }\n else {\n this._updateNonUniformScalingState(false);\n }\n this._afterComputeWorldMatrix();\n // Absolute position\n this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);\n this._isAbsoluteSynced = false;\n // Callbacks\n this.onAfterWorldMatrixUpdateObservable.notifyObservers(this);\n if (!this._poseMatrix) {\n this._poseMatrix = Matrix.Invert(this._worldMatrix);\n }\n // Cache the determinant\n this._worldMatrixDeterminantIsDirty = true;\n return this._worldMatrix;\n }\n /**\n * Resets this nodeTransform's local matrix to Matrix.Identity().\n * @param independentOfChildren indicates if all child nodeTransform's world-space transform should be preserved.\n */\n resetLocalMatrix(independentOfChildren = true) {\n this.computeWorldMatrix();\n if (independentOfChildren) {\n const children = this.getChildren();\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n if (child) {\n child.computeWorldMatrix();\n const bakedMatrix = TmpVectors.Matrix[0];\n child._localMatrix.multiplyToRef(this._localMatrix, bakedMatrix);\n const tmpRotationQuaternion = TmpVectors.Quaternion[0];\n bakedMatrix.decompose(child.scaling, tmpRotationQuaternion, child.position);\n if (child.rotationQuaternion) {\n child.rotationQuaternion.copyFrom(tmpRotationQuaternion);\n }\n else {\n tmpRotationQuaternion.toEulerAnglesToRef(child.rotation);\n }\n }\n }\n }\n this.scaling.copyFromFloats(1, 1, 1);\n this.position.copyFromFloats(0, 0, 0);\n this.rotation.copyFromFloats(0, 0, 0);\n //only if quaternion is already set\n if (this.rotationQuaternion) {\n this.rotationQuaternion = Quaternion.Identity();\n }\n this._worldMatrix = Matrix.Identity();\n }\n _afterComputeWorldMatrix() { }\n /**\n * If you'd like to be called back after the mesh position, rotation or scaling has been updated.\n * @param func callback function to add\n *\n * @returns the TransformNode.\n */\n registerAfterWorldMatrixUpdate(func) {\n this.onAfterWorldMatrixUpdateObservable.add(func);\n return this;\n }\n /**\n * Removes a registered callback function.\n * @param func callback function to remove\n * @returns the TransformNode.\n */\n unregisterAfterWorldMatrixUpdate(func) {\n this.onAfterWorldMatrixUpdateObservable.removeCallback(func);\n return this;\n }\n /**\n * Gets the position of the current mesh in camera space\n * @param camera defines the camera to use\n * @returns a position\n */\n getPositionInCameraSpace(camera = null) {\n if (!camera) {\n camera = this.getScene().activeCamera;\n }\n return Vector3.TransformCoordinates(this.getAbsolutePosition(), camera.getViewMatrix());\n }\n /**\n * Returns the distance from the mesh to the active camera\n * @param camera defines the camera to use\n * @returns the distance\n */\n getDistanceToCamera(camera = null) {\n if (!camera) {\n camera = this.getScene().activeCamera;\n }\n return this.getAbsolutePosition().subtract(camera.globalPosition).length();\n }\n /**\n * Clone the current transform node\n * @param name Name of the new clone\n * @param newParent New parent for the clone\n * @param doNotCloneChildren Do not clone children hierarchy\n * @returns the new transform node\n */\n clone(name, newParent, doNotCloneChildren) {\n const result = SerializationHelper.Clone(() => new TransformNode(name, this.getScene()), this);\n result.name = name;\n result.id = name;\n if (newParent) {\n result.parent = newParent;\n }\n if (!doNotCloneChildren) {\n // Children\n const directDescendants = this.getDescendants(true);\n for (let index = 0; index < directDescendants.length; index++) {\n const child = directDescendants[index];\n if (child.clone) {\n child.clone(name + \".\" + child.name, result);\n }\n }\n }\n return result;\n }\n /**\n * Serializes the objects information.\n * @param currentSerializationObject defines the object to serialize in\n * @returns the serialized object\n */\n serialize(currentSerializationObject) {\n const serializationObject = SerializationHelper.Serialize(this, currentSerializationObject);\n serializationObject.type = this.getClassName();\n serializationObject.uniqueId = this.uniqueId;\n // Parent\n if (this.parent) {\n this.parent._serializeAsParent(serializationObject);\n }\n serializationObject.localMatrix = this.getPivotMatrix().asArray();\n serializationObject.isEnabled = this.isEnabled();\n return serializationObject;\n }\n // Statics\n /**\n * Returns a new TransformNode object parsed from the source provided.\n * @param parsedTransformNode is the source.\n * @param scene the scene the object belongs to\n * @param rootUrl is a string, it's the root URL to prefix the `delayLoadingFile` property with\n * @returns a new TransformNode object parsed from the source provided.\n */\n static Parse(parsedTransformNode, scene, rootUrl) {\n const transformNode = SerializationHelper.Parse(() => new TransformNode(parsedTransformNode.name, scene), parsedTransformNode, scene, rootUrl);\n if (parsedTransformNode.localMatrix) {\n transformNode.setPreTransformMatrix(Matrix.FromArray(parsedTransformNode.localMatrix));\n }\n else if (parsedTransformNode.pivotMatrix) {\n transformNode.setPivotMatrix(Matrix.FromArray(parsedTransformNode.pivotMatrix));\n }\n transformNode.setEnabled(parsedTransformNode.isEnabled);\n transformNode._waitingParsedUniqueId = parsedTransformNode.uniqueId;\n // Parent\n if (parsedTransformNode.parentId !== undefined) {\n transformNode._waitingParentId = parsedTransformNode.parentId;\n }\n if (parsedTransformNode.parentInstanceIndex !== undefined) {\n transformNode._waitingParentInstanceIndex = parsedTransformNode.parentInstanceIndex;\n }\n return transformNode;\n }\n /**\n * Get all child-transformNodes of this node\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\n * @returns an array of TransformNode\n */\n getChildTransformNodes(directDescendantsOnly, predicate) {\n const results = [];\n this._getDescendants(results, directDescendantsOnly, (node) => {\n return (!predicate || predicate(node)) && node instanceof TransformNode;\n });\n return results;\n }\n /**\n * Releases resources associated with this transform node.\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n // Animations\n this.getScene().stopAnimation(this);\n // Remove from scene\n this.getScene().removeTransformNode(this);\n if (this._parentContainer) {\n const index = this._parentContainer.transformNodes.indexOf(this);\n if (index > -1) {\n this._parentContainer.transformNodes.splice(index, 1);\n }\n this._parentContainer = null;\n }\n this.onAfterWorldMatrixUpdateObservable.clear();\n if (doNotRecurse) {\n const transformNodes = this.getChildTransformNodes(true);\n for (const transformNode of transformNodes) {\n transformNode.parent = null;\n transformNode.computeWorldMatrix(true);\n }\n }\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n /**\n * Uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units)\n * @param includeDescendants Use the hierarchy's bounding box instead of the mesh's bounding box. Default is false\n * @param ignoreRotation ignore rotation when computing the scale (ie. object will be axis aligned). Default is false\n * @param predicate predicate that is passed in to getHierarchyBoundingVectors when selecting which object should be included when scaling\n * @returns the current mesh\n */\n normalizeToUnitCube(includeDescendants = true, ignoreRotation = false, predicate) {\n let storedRotation = null;\n let storedRotationQuaternion = null;\n if (ignoreRotation) {\n if (this.rotationQuaternion) {\n storedRotationQuaternion = this.rotationQuaternion.clone();\n this.rotationQuaternion.copyFromFloats(0, 0, 0, 1);\n }\n else if (this.rotation) {\n storedRotation = this.rotation.clone();\n this.rotation.copyFromFloats(0, 0, 0);\n }\n }\n const boundingVectors = this.getHierarchyBoundingVectors(includeDescendants, predicate);\n const sizeVec = boundingVectors.max.subtract(boundingVectors.min);\n const maxDimension = Math.max(sizeVec.x, sizeVec.y, sizeVec.z);\n if (maxDimension === 0) {\n return this;\n }\n const scale = 1 / maxDimension;\n this.scaling.scaleInPlace(scale);\n if (ignoreRotation) {\n if (this.rotationQuaternion && storedRotationQuaternion) {\n this.rotationQuaternion.copyFrom(storedRotationQuaternion);\n }\n else if (this.rotation && storedRotation) {\n this.rotation.copyFrom(storedRotation);\n }\n }\n return this;\n }\n _syncAbsoluteScalingAndRotation() {\n if (!this._isAbsoluteSynced) {\n this._worldMatrix.decompose(this._absoluteScaling, this._absoluteRotationQuaternion);\n this._isAbsoluteSynced = true;\n }\n }\n }\n // Statics\n /**\n * Object will not rotate to face the camera\n */\n TransformNode.BILLBOARDMODE_NONE = 0;\n /**\n * Object will rotate to face the camera but only on the x axis\n */\n TransformNode.BILLBOARDMODE_X = 1;\n /**\n * Object will rotate to face the camera but only on the y axis\n */\n TransformNode.BILLBOARDMODE_Y = 2;\n /**\n * Object will rotate to face the camera but only on the z axis\n */\n TransformNode.BILLBOARDMODE_Z = 4;\n /**\n * Object will rotate to face the camera\n */\n TransformNode.BILLBOARDMODE_ALL = 7;\n /**\n * Object will rotate to face the camera's position instead of orientation\n */\n TransformNode.BILLBOARDMODE_USE_POSITION = 128;\n /**\n * Child transform with Billboard flags should or should not apply parent rotation (default if off)\n */\n TransformNode.BillboardUseParentOrientation = false;\n TransformNode._TmpRotation = Quaternion.Zero();\n TransformNode._TmpScaling = Vector3.Zero();\n TransformNode._TmpTranslation = Vector3.Zero();\n TransformNode._LookAtVectorCache = new Vector3(0, 0, 0);\n TransformNode._RotationAxisCache = new Quaternion();\n __decorate$1([\n serializeAsVector3(\"position\")\n ], TransformNode.prototype, \"_position\", void 0);\n __decorate$1([\n serializeAsVector3(\"rotation\")\n ], TransformNode.prototype, \"_rotation\", void 0);\n __decorate$1([\n serializeAsQuaternion(\"rotationQuaternion\")\n ], TransformNode.prototype, \"_rotationQuaternion\", void 0);\n __decorate$1([\n serializeAsVector3(\"scaling\")\n ], TransformNode.prototype, \"_scaling\", void 0);\n __decorate$1([\n serialize(\"billboardMode\")\n ], TransformNode.prototype, \"_billboardMode\", void 0);\n __decorate$1([\n serialize()\n ], TransformNode.prototype, \"scalingDeterminant\", void 0);\n __decorate$1([\n serialize(\"infiniteDistance\")\n ], TransformNode.prototype, \"_infiniteDistance\", void 0);\n __decorate$1([\n serialize()\n ], TransformNode.prototype, \"ignoreNonUniformScaling\", void 0);\n __decorate$1([\n serialize()\n ], TransformNode.prototype, \"reIntegrateRotationIntoRotationQuaternion\", void 0);\n\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _MeshCollisionData {\n constructor() {\n this._checkCollisions = false;\n this._collisionMask = -1;\n this._collisionGroup = -1;\n this._surroundingMeshes = null;\n this._collider = null;\n this._oldPositionForCollisions = new Vector3(0, 0, 0);\n this._diffPositionForCollisions = new Vector3(0, 0, 0);\n this._collisionResponse = true;\n }\n }\n\n /** @internal */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _FacetDataStorage {\n constructor() {\n this.facetNb = 0; // facet number\n this.partitioningSubdivisions = 10; // number of subdivisions per axis in the partitioning space\n this.partitioningBBoxRatio = 1.01; // the partitioning array space is by default 1% bigger than the bounding box\n this.facetDataEnabled = false; // is the facet data feature enabled on this mesh ?\n this.facetParameters = {}; // keep a reference to the object parameters to avoid memory re-allocation\n this.bbSize = Vector3.Zero(); // bbox size approximated for facet data\n this.subDiv = {\n // actual number of subdivisions per axis for ComputeNormals()\n max: 1,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n X: 1,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Y: 1,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Z: 1,\n };\n this.facetDepthSort = false; // is the facet depth sort to be computed\n this.facetDepthSortEnabled = false; // is the facet depth sort initialized\n }\n }\n /**\n * @internal\n **/\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _InternalAbstractMeshDataInfo {\n constructor() {\n this._hasVertexAlpha = false;\n this._useVertexColors = true;\n this._numBoneInfluencers = 4;\n this._applyFog = true;\n this._receiveShadows = false;\n this._facetData = new _FacetDataStorage();\n this._visibility = 1.0;\n this._skeleton = null;\n this._layerMask = 0x0fffffff;\n this._computeBonesUsingShaders = true;\n this._isActive = false;\n this._onlyForInstances = false;\n this._isActiveIntermediate = false;\n this._onlyForInstancesIntermediate = false;\n this._actAsRegularMesh = false;\n this._currentLOD = null;\n this._currentLODIsUpToDate = false;\n this._collisionRetryCount = 3;\n this._morphTargetManager = null;\n this._renderingGroupId = 0;\n this._bakedVertexAnimationManager = null;\n this._material = null;\n this._positions = null;\n this._pointerOverDisableMeshTesting = false;\n // Collisions\n this._meshCollisionData = new _MeshCollisionData();\n this._enableDistantPicking = false;\n /** @internal\n * Bounding info that is unnafected by the addition of thin instances\n */\n this._rawBoundingInfo = null;\n }\n }\n /**\n * Class used to store all common mesh properties\n */\n class AbstractMesh extends TransformNode {\n /**\n * No billboard\n */\n static get BILLBOARDMODE_NONE() {\n return TransformNode.BILLBOARDMODE_NONE;\n }\n /** Billboard on X axis */\n static get BILLBOARDMODE_X() {\n return TransformNode.BILLBOARDMODE_X;\n }\n /** Billboard on Y axis */\n static get BILLBOARDMODE_Y() {\n return TransformNode.BILLBOARDMODE_Y;\n }\n /** Billboard on Z axis */\n static get BILLBOARDMODE_Z() {\n return TransformNode.BILLBOARDMODE_Z;\n }\n /** Billboard on all axes */\n static get BILLBOARDMODE_ALL() {\n return TransformNode.BILLBOARDMODE_ALL;\n }\n /** Billboard on using position instead of orientation */\n static get BILLBOARDMODE_USE_POSITION() {\n return TransformNode.BILLBOARDMODE_USE_POSITION;\n }\n /**\n * Gets the number of facets in the mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#what-is-a-mesh-facet\n */\n get facetNb() {\n return this._internalAbstractMeshDataInfo._facetData.facetNb;\n }\n /**\n * Gets or set the number (integer) of subdivisions per axis in the partitioning space\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#tweaking-the-partitioning\n */\n get partitioningSubdivisions() {\n return this._internalAbstractMeshDataInfo._facetData.partitioningSubdivisions;\n }\n set partitioningSubdivisions(nb) {\n this._internalAbstractMeshDataInfo._facetData.partitioningSubdivisions = nb;\n }\n /**\n * The ratio (float) to apply to the bounding box size to set to the partitioning space.\n * Ex : 1.01 (default) the partitioning space is 1% bigger than the bounding box\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#tweaking-the-partitioning\n */\n get partitioningBBoxRatio() {\n return this._internalAbstractMeshDataInfo._facetData.partitioningBBoxRatio;\n }\n set partitioningBBoxRatio(ratio) {\n this._internalAbstractMeshDataInfo._facetData.partitioningBBoxRatio = ratio;\n }\n /**\n * Gets or sets a boolean indicating that the facets must be depth sorted on next call to `updateFacetData()`.\n * Works only for updatable meshes.\n * Doesn't work with multi-materials\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#facet-depth-sort\n */\n get mustDepthSortFacets() {\n return this._internalAbstractMeshDataInfo._facetData.facetDepthSort;\n }\n set mustDepthSortFacets(sort) {\n this._internalAbstractMeshDataInfo._facetData.facetDepthSort = sort;\n }\n /**\n * The location (Vector3) where the facet depth sort must be computed from.\n * By default, the active camera position.\n * Used only when facet depth sort is enabled\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#facet-depth-sort\n */\n get facetDepthSortFrom() {\n return this._internalAbstractMeshDataInfo._facetData.facetDepthSortFrom;\n }\n set facetDepthSortFrom(location) {\n this._internalAbstractMeshDataInfo._facetData.facetDepthSortFrom = location;\n }\n /** number of collision detection tries. Change this value if not all collisions are detected and handled properly */\n get collisionRetryCount() {\n return this._internalAbstractMeshDataInfo._collisionRetryCount;\n }\n set collisionRetryCount(retryCount) {\n this._internalAbstractMeshDataInfo._collisionRetryCount = retryCount;\n }\n /**\n * gets a boolean indicating if facetData is enabled\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#what-is-a-mesh-facet\n */\n get isFacetDataEnabled() {\n return this._internalAbstractMeshDataInfo._facetData.facetDataEnabled;\n }\n /**\n * Gets or sets the morph target manager\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets\n */\n get morphTargetManager() {\n return this._internalAbstractMeshDataInfo._morphTargetManager;\n }\n set morphTargetManager(value) {\n if (this._internalAbstractMeshDataInfo._morphTargetManager === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._morphTargetManager = value;\n this._syncGeometryWithMorphTargetManager();\n }\n /**\n * Gets or sets the baked vertex animation manager\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/baked_texture_animations\n */\n get bakedVertexAnimationManager() {\n return this._internalAbstractMeshDataInfo._bakedVertexAnimationManager;\n }\n set bakedVertexAnimationManager(value) {\n if (this._internalAbstractMeshDataInfo._bakedVertexAnimationManager === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._bakedVertexAnimationManager = value;\n this._markSubMeshesAsAttributesDirty();\n }\n /** @internal */\n _syncGeometryWithMorphTargetManager() { }\n /**\n * @internal\n */\n _updateNonUniformScalingState(value) {\n if (!super._updateNonUniformScalingState(value)) {\n return false;\n }\n this._markSubMeshesAsMiscDirty();\n return true;\n }\n /** @internal */\n get rawBoundingInfo() {\n return this._internalAbstractMeshDataInfo._rawBoundingInfo;\n }\n set rawBoundingInfo(boundingInfo) {\n this._internalAbstractMeshDataInfo._rawBoundingInfo = boundingInfo;\n }\n /** Set a function to call when this mesh collides with another one */\n set onCollide(callback) {\n if (this._internalAbstractMeshDataInfo._meshCollisionData._onCollideObserver) {\n this.onCollideObservable.remove(this._internalAbstractMeshDataInfo._meshCollisionData._onCollideObserver);\n }\n this._internalAbstractMeshDataInfo._meshCollisionData._onCollideObserver = this.onCollideObservable.add(callback);\n }\n /** Set a function to call when the collision's position changes */\n set onCollisionPositionChange(callback) {\n if (this._internalAbstractMeshDataInfo._meshCollisionData._onCollisionPositionChangeObserver) {\n this.onCollisionPositionChangeObservable.remove(this._internalAbstractMeshDataInfo._meshCollisionData._onCollisionPositionChangeObserver);\n }\n this._internalAbstractMeshDataInfo._meshCollisionData._onCollisionPositionChangeObserver = this.onCollisionPositionChangeObservable.add(callback);\n }\n /**\n * Gets or sets mesh visibility between 0 and 1 (default is 1)\n */\n get visibility() {\n return this._internalAbstractMeshDataInfo._visibility;\n }\n /**\n * Gets or sets mesh visibility between 0 and 1 (default is 1)\n */\n set visibility(value) {\n if (this._internalAbstractMeshDataInfo._visibility === value) {\n return;\n }\n const oldValue = this._internalAbstractMeshDataInfo._visibility;\n this._internalAbstractMeshDataInfo._visibility = value;\n if ((oldValue === 1 && value !== 1) || (oldValue !== 1 && value === 1)) {\n this._markSubMeshesAsDirty((defines) => {\n defines.markAsMiscDirty();\n defines.markAsPrePassDirty();\n });\n }\n }\n /**\n * Gets or sets the property which disables the test that is checking that the mesh under the pointer is the same than the previous time we tested for it (default: false).\n * Set this property to true if you want thin instances picking to be reported accurately when moving over the mesh.\n * Note that setting this property to true will incur some performance penalties when dealing with pointer events for this mesh so use it sparingly.\n */\n get pointerOverDisableMeshTesting() {\n return this._internalAbstractMeshDataInfo._pointerOverDisableMeshTesting;\n }\n set pointerOverDisableMeshTesting(disable) {\n this._internalAbstractMeshDataInfo._pointerOverDisableMeshTesting = disable;\n }\n /**\n * Specifies the rendering group id for this mesh (0 by default)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering#rendering-groups\n */\n get renderingGroupId() {\n return this._internalAbstractMeshDataInfo._renderingGroupId;\n }\n set renderingGroupId(value) {\n this._internalAbstractMeshDataInfo._renderingGroupId = value;\n }\n /** Gets or sets current material */\n get material() {\n return this._internalAbstractMeshDataInfo._material;\n }\n set material(value) {\n if (this._internalAbstractMeshDataInfo._material === value) {\n return;\n }\n // remove from material mesh map id needed\n if (this._internalAbstractMeshDataInfo._material && this._internalAbstractMeshDataInfo._material.meshMap) {\n this._internalAbstractMeshDataInfo._material.meshMap[this.uniqueId] = undefined;\n }\n this._internalAbstractMeshDataInfo._material = value;\n if (value && value.meshMap) {\n value.meshMap[this.uniqueId] = this;\n }\n if (this.onMaterialChangedObservable.hasObservers()) {\n this.onMaterialChangedObservable.notifyObservers(this);\n }\n if (!this.subMeshes) {\n return;\n }\n this.resetDrawCache();\n this._unBindEffect();\n }\n /**\n * Gets the material used to render the mesh in a specific render pass\n * @param renderPassId render pass id\n * @returns material used for the render pass. If no specific material is used for this render pass, undefined is returned (meaning mesh.material is used for this pass)\n */\n getMaterialForRenderPass(renderPassId) {\n var _a;\n return (_a = this._internalAbstractMeshDataInfo._materialForRenderPass) === null || _a === void 0 ? void 0 : _a[renderPassId];\n }\n /**\n * Sets the material to be used to render the mesh in a specific render pass\n * @param renderPassId render pass id\n * @param material material to use for this render pass. If undefined is passed, no specific material will be used for this render pass but the regular material will be used instead (mesh.material)\n */\n setMaterialForRenderPass(renderPassId, material) {\n this.resetDrawCache(renderPassId);\n if (!this._internalAbstractMeshDataInfo._materialForRenderPass) {\n this._internalAbstractMeshDataInfo._materialForRenderPass = [];\n }\n this._internalAbstractMeshDataInfo._materialForRenderPass[renderPassId] = material;\n }\n /**\n * Gets or sets a boolean indicating that this mesh can receive realtime shadows\n * @see https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\n */\n get receiveShadows() {\n return this._internalAbstractMeshDataInfo._receiveShadows;\n }\n set receiveShadows(value) {\n if (this._internalAbstractMeshDataInfo._receiveShadows === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._receiveShadows = value;\n this._markSubMeshesAsLightDirty();\n }\n /** Gets or sets a boolean indicating that this mesh contains vertex color data with alpha values */\n get hasVertexAlpha() {\n return this._internalAbstractMeshDataInfo._hasVertexAlpha;\n }\n set hasVertexAlpha(value) {\n if (this._internalAbstractMeshDataInfo._hasVertexAlpha === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._hasVertexAlpha = value;\n this._markSubMeshesAsAttributesDirty();\n this._markSubMeshesAsMiscDirty();\n }\n /** Gets or sets a boolean indicating that this mesh needs to use vertex color data to render (if this kind of vertex data is available in the geometry) */\n get useVertexColors() {\n return this._internalAbstractMeshDataInfo._useVertexColors;\n }\n set useVertexColors(value) {\n if (this._internalAbstractMeshDataInfo._useVertexColors === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._useVertexColors = value;\n this._markSubMeshesAsAttributesDirty();\n }\n /**\n * Gets or sets a boolean indicating that bone animations must be computed by the GPU (true by default)\n */\n get computeBonesUsingShaders() {\n return this._internalAbstractMeshDataInfo._computeBonesUsingShaders;\n }\n set computeBonesUsingShaders(value) {\n if (this._internalAbstractMeshDataInfo._computeBonesUsingShaders === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._computeBonesUsingShaders = value;\n this._markSubMeshesAsAttributesDirty();\n }\n /** Gets or sets the number of allowed bone influences per vertex (4 by default) */\n get numBoneInfluencers() {\n return this._internalAbstractMeshDataInfo._numBoneInfluencers;\n }\n set numBoneInfluencers(value) {\n if (this._internalAbstractMeshDataInfo._numBoneInfluencers === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._numBoneInfluencers = value;\n this._markSubMeshesAsAttributesDirty();\n }\n /** Gets or sets a boolean indicating that this mesh will allow fog to be rendered on it (true by default) */\n get applyFog() {\n return this._internalAbstractMeshDataInfo._applyFog;\n }\n set applyFog(value) {\n if (this._internalAbstractMeshDataInfo._applyFog === value) {\n return;\n }\n this._internalAbstractMeshDataInfo._applyFog = value;\n this._markSubMeshesAsMiscDirty();\n }\n /** When enabled, decompose picking matrices for better precision with large values for mesh position and scling */\n get enableDistantPicking() {\n return this._internalAbstractMeshDataInfo._enableDistantPicking;\n }\n set enableDistantPicking(value) {\n this._internalAbstractMeshDataInfo._enableDistantPicking = value;\n }\n /**\n * Gets or sets the current layer mask (default is 0x0FFFFFFF)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/layerMasksAndMultiCam\n */\n get layerMask() {\n return this._internalAbstractMeshDataInfo._layerMask;\n }\n set layerMask(value) {\n if (value === this._internalAbstractMeshDataInfo._layerMask) {\n return;\n }\n this._internalAbstractMeshDataInfo._layerMask = value;\n this._resyncLightSources();\n }\n /**\n * Gets or sets a collision mask used to mask collisions (default is -1).\n * A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0\n */\n get collisionMask() {\n return this._internalAbstractMeshDataInfo._meshCollisionData._collisionMask;\n }\n set collisionMask(mask) {\n this._internalAbstractMeshDataInfo._meshCollisionData._collisionMask = !isNaN(mask) ? mask : -1;\n }\n /**\n * Gets or sets a collision response flag (default is true).\n * when collisionResponse is false, events are still triggered but colliding entity has no response\n * This helps creating trigger volume when user wants collision feedback events but not position/velocity\n * to respond to the collision.\n */\n get collisionResponse() {\n return this._internalAbstractMeshDataInfo._meshCollisionData._collisionResponse;\n }\n set collisionResponse(response) {\n this._internalAbstractMeshDataInfo._meshCollisionData._collisionResponse = response;\n }\n /**\n * Gets or sets the current collision group mask (-1 by default).\n * A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0\n */\n get collisionGroup() {\n return this._internalAbstractMeshDataInfo._meshCollisionData._collisionGroup;\n }\n set collisionGroup(mask) {\n this._internalAbstractMeshDataInfo._meshCollisionData._collisionGroup = !isNaN(mask) ? mask : -1;\n }\n /**\n * Gets or sets current surrounding meshes (null by default).\n *\n * By default collision detection is tested against every mesh in the scene.\n * It is possible to set surroundingMeshes to a defined list of meshes and then only these specified\n * meshes will be tested for the collision.\n *\n * Note: if set to an empty array no collision will happen when this mesh is moved.\n */\n get surroundingMeshes() {\n return this._internalAbstractMeshDataInfo._meshCollisionData._surroundingMeshes;\n }\n set surroundingMeshes(meshes) {\n this._internalAbstractMeshDataInfo._meshCollisionData._surroundingMeshes = meshes;\n }\n /** Gets the list of lights affecting that mesh */\n get lightSources() {\n return this._lightSources;\n }\n /** @internal */\n get _positions() {\n return null;\n }\n /**\n * Gets or sets a skeleton to apply skinning transformations\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons\n */\n set skeleton(value) {\n const skeleton = this._internalAbstractMeshDataInfo._skeleton;\n if (skeleton && skeleton.needInitialSkinMatrix) {\n skeleton._unregisterMeshWithPoseMatrix(this);\n }\n if (value && value.needInitialSkinMatrix) {\n value._registerMeshWithPoseMatrix(this);\n }\n this._internalAbstractMeshDataInfo._skeleton = value;\n if (!this._internalAbstractMeshDataInfo._skeleton) {\n this._bonesTransformMatrices = null;\n }\n this._markSubMeshesAsAttributesDirty();\n }\n get skeleton() {\n return this._internalAbstractMeshDataInfo._skeleton;\n }\n // Constructor\n /**\n * Creates a new AbstractMesh\n * @param name defines the name of the mesh\n * @param scene defines the hosting scene\n */\n constructor(name, scene = null) {\n super(name, scene, false);\n // Internal data\n /** @internal */\n this._internalAbstractMeshDataInfo = new _InternalAbstractMeshDataInfo();\n /** @internal */\n this._waitingMaterialId = null;\n /**\n * The culling strategy to use to check whether the mesh must be rendered or not.\n * This value can be changed at any time and will be used on the next render mesh selection.\n * The possible values are :\n * - AbstractMesh.CULLINGSTRATEGY_STANDARD\n * - AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\n * Please read each static variable documentation to get details about the culling process.\n * */\n this.cullingStrategy = AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY;\n // Events\n /**\n * An event triggered when this mesh collides with another one\n */\n this.onCollideObservable = new Observable$1();\n /**\n * An event triggered when the collision's position changes\n */\n this.onCollisionPositionChangeObservable = new Observable$1();\n /**\n * An event triggered when material is changed\n */\n this.onMaterialChangedObservable = new Observable$1();\n // Properties\n /**\n * Gets or sets the orientation for POV movement & rotation\n */\n this.definedFacingForward = true;\n /** @internal */\n this._occlusionQuery = null;\n /** @internal */\n this._renderingGroup = null;\n /** Gets or sets the alpha index used to sort transparent meshes\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering#alpha-index\n */\n this.alphaIndex = Number.MAX_VALUE;\n /**\n * Gets or sets a boolean indicating if the mesh is visible (renderable). Default is true\n */\n this.isVisible = true;\n /**\n * Gets or sets a boolean indicating if the mesh can be picked (by scene.pick for instance or through actions). Default is true\n */\n this.isPickable = true;\n /**\n * Gets or sets a boolean indicating if the mesh can be near picked. Default is false\n */\n this.isNearPickable = false;\n /**\n * Gets or sets a boolean indicating if the mesh can be near grabbed. Default is false\n */\n this.isNearGrabbable = false;\n /** Gets or sets a boolean indicating that bounding boxes of subMeshes must be rendered as well (false by default) */\n this.showSubMeshesBoundingBox = false;\n /** Gets or sets a boolean indicating if the mesh must be considered as a ray blocker for lens flares (false by default)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/lenseFlare\n */\n this.isBlocker = false;\n /**\n * Gets or sets a boolean indicating that pointer move events must be supported on this mesh (false by default)\n */\n this.enablePointerMoveEvents = false;\n /** Defines color to use when rendering outline */\n this.outlineColor = Color3.Red();\n /** Define width to use when rendering outline */\n this.outlineWidth = 0.02;\n /** Defines color to use when rendering overlay */\n this.overlayColor = Color3.Red();\n /** Defines alpha to use when rendering overlay */\n this.overlayAlpha = 0.5;\n /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes selection (true by default) */\n this.useOctreeForRenderingSelection = true;\n /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes picking (true by default) */\n this.useOctreeForPicking = true;\n /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes collision (true by default) */\n this.useOctreeForCollisions = true;\n /**\n * True if the mesh must be rendered in any case (this will shortcut the frustum clipping phase)\n */\n this.alwaysSelectAsActiveMesh = false;\n /**\n * Gets or sets a boolean indicating that the bounding info does not need to be kept in sync (for performance reason)\n */\n this.doNotSyncBoundingInfo = false;\n /**\n * Gets or sets the current action manager\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions\n */\n this.actionManager = null;\n /**\n * Gets or sets the ellipsoid used to impersonate this mesh when using collision engine (default is (0.5, 1, 0.5))\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n */\n this.ellipsoid = new Vector3(0.5, 1, 0.5);\n /**\n * Gets or sets the ellipsoid offset used to impersonate this mesh when using collision engine (default is (0, 0, 0))\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n */\n this.ellipsoidOffset = new Vector3(0, 0, 0);\n // Edges\n /**\n * Defines edge width used when edgesRenderer is enabled\n * @see https://www.babylonjs-playground.com/#10OJSG#13\n */\n this.edgesWidth = 1;\n /**\n * Defines edge color used when edgesRenderer is enabled\n * @see https://www.babylonjs-playground.com/#10OJSG#13\n */\n this.edgesColor = new Color4(1, 0, 0, 1);\n /** @internal */\n this._edgesRenderer = null;\n /** @internal */\n this._masterMesh = null;\n this._boundingInfo = null;\n this._boundingInfoIsDirty = true;\n /** @internal */\n this._renderId = 0;\n /** @internal */\n this._intersectionsInProgress = new Array();\n /** @internal */\n this._unIndexed = false;\n /** @internal */\n this._lightSources = new Array();\n // Loading properties\n /** @internal */\n this._waitingData = {\n lods: null,\n actions: null,\n freezeWorldMatrix: null,\n };\n /** @internal */\n this._bonesTransformMatrices = null;\n /** @internal */\n this._transformMatrixTexture = null;\n /**\n * An event triggered when the mesh is rebuilt.\n */\n this.onRebuildObservable = new Observable$1();\n this._onCollisionPositionChange = (collisionId, newPosition, collidedMesh = null) => {\n newPosition.subtractToRef(this._internalAbstractMeshDataInfo._meshCollisionData._oldPositionForCollisions, this._internalAbstractMeshDataInfo._meshCollisionData._diffPositionForCollisions);\n if (this._internalAbstractMeshDataInfo._meshCollisionData._diffPositionForCollisions.length() > Engine.CollisionsEpsilon) {\n this.position.addInPlace(this._internalAbstractMeshDataInfo._meshCollisionData._diffPositionForCollisions);\n }\n if (collidedMesh) {\n this.onCollideObservable.notifyObservers(collidedMesh);\n }\n this.onCollisionPositionChangeObservable.notifyObservers(this.position);\n };\n scene = this.getScene();\n scene.addMesh(this);\n this._resyncLightSources();\n // Mesh Uniform Buffer.\n this._uniformBuffer = new UniformBuffer(this.getScene().getEngine(), undefined, undefined, name, !this.getScene().getEngine().isWebGPU);\n this._buildUniformLayout();\n switch (scene.performancePriority) {\n case ScenePerformancePriority.Aggressive:\n this.doNotSyncBoundingInfo = true;\n // eslint-disable-next-line no-fallthrough\n case ScenePerformancePriority.Intermediate:\n this.alwaysSelectAsActiveMesh = true;\n this.isPickable = false;\n break;\n }\n }\n _buildUniformLayout() {\n this._uniformBuffer.addUniform(\"world\", 16);\n this._uniformBuffer.addUniform(\"visibility\", 1);\n this._uniformBuffer.create();\n }\n /**\n * Transfer the mesh values to its UBO.\n * @param world The world matrix associated with the mesh\n */\n transferToEffect(world) {\n const ubo = this._uniformBuffer;\n ubo.updateMatrix(\"world\", world);\n ubo.updateFloat(\"visibility\", this._internalAbstractMeshDataInfo._visibility);\n ubo.update();\n }\n /**\n * Gets the mesh uniform buffer.\n * @returns the uniform buffer of the mesh.\n */\n getMeshUniformBuffer() {\n return this._uniformBuffer;\n }\n /**\n * Returns the string \"AbstractMesh\"\n * @returns \"AbstractMesh\"\n */\n getClassName() {\n return \"AbstractMesh\";\n }\n /**\n * Gets a string representation of the current mesh\n * @param fullDetails defines a boolean indicating if full details must be included\n * @returns a string representation of the current mesh\n */\n toString(fullDetails) {\n let ret = \"Name: \" + this.name + \", isInstance: \" + (this.getClassName() !== \"InstancedMesh\" ? \"YES\" : \"NO\");\n ret += \", # of submeshes: \" + (this.subMeshes ? this.subMeshes.length : 0);\n const skeleton = this._internalAbstractMeshDataInfo._skeleton;\n if (skeleton) {\n ret += \", skeleton: \" + skeleton.name;\n }\n if (fullDetails) {\n ret += \", billboard mode: \" + [\"NONE\", \"X\", \"Y\", null, \"Z\", null, null, \"ALL\"][this.billboardMode];\n ret += \", freeze wrld mat: \" + (this._isWorldMatrixFrozen || this._waitingData.freezeWorldMatrix ? \"YES\" : \"NO\");\n }\n return ret;\n }\n /**\n * @internal\n */\n _getEffectiveParent() {\n if (this._masterMesh && this.billboardMode !== TransformNode.BILLBOARDMODE_NONE) {\n return this._masterMesh;\n }\n return super._getEffectiveParent();\n }\n /**\n * @internal\n */\n _getActionManagerForTrigger(trigger, initialCall = true) {\n if (this.actionManager && (initialCall || this.actionManager.isRecursive)) {\n if (trigger) {\n if (this.actionManager.hasSpecificTrigger(trigger)) {\n return this.actionManager;\n }\n }\n else {\n return this.actionManager;\n }\n }\n if (!this.parent) {\n return null;\n }\n return this.parent._getActionManagerForTrigger(trigger, false);\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _rebuild(dispose = false) {\n this.onRebuildObservable.notifyObservers(this);\n if (this._occlusionQuery !== null) {\n this._occlusionQuery = null;\n }\n if (!this.subMeshes) {\n return;\n }\n for (const subMesh of this.subMeshes) {\n subMesh._rebuild();\n }\n }\n /** @internal */\n _resyncLightSources() {\n this._lightSources.length = 0;\n for (const light of this.getScene().lights) {\n if (!light.isEnabled()) {\n continue;\n }\n if (light.canAffectMesh(this)) {\n this._lightSources.push(light);\n }\n }\n this._markSubMeshesAsLightDirty();\n }\n /**\n * @internal\n */\n _resyncLightSource(light) {\n const isIn = light.isEnabled() && light.canAffectMesh(this);\n const index = this._lightSources.indexOf(light);\n let removed = false;\n if (index === -1) {\n if (!isIn) {\n return;\n }\n this._lightSources.push(light);\n }\n else {\n if (isIn) {\n return;\n }\n removed = true;\n this._lightSources.splice(index, 1);\n }\n this._markSubMeshesAsLightDirty(removed);\n }\n /** @internal */\n _unBindEffect() {\n for (const subMesh of this.subMeshes) {\n subMesh.setEffect(null);\n }\n }\n /**\n * @internal\n */\n _removeLightSource(light, dispose) {\n const index = this._lightSources.indexOf(light);\n if (index === -1) {\n return;\n }\n this._lightSources.splice(index, 1);\n this._markSubMeshesAsLightDirty(dispose);\n }\n _markSubMeshesAsDirty(func) {\n if (!this.subMeshes) {\n return;\n }\n for (const subMesh of this.subMeshes) {\n for (let i = 0; i < subMesh._drawWrappers.length; ++i) {\n const drawWrapper = subMesh._drawWrappers[i];\n if (!drawWrapper || !drawWrapper.defines || !drawWrapper.defines.markAllAsDirty) {\n continue;\n }\n func(drawWrapper.defines);\n }\n }\n }\n /**\n * @internal\n */\n _markSubMeshesAsLightDirty(dispose = false) {\n this._markSubMeshesAsDirty((defines) => defines.markAsLightDirty(dispose));\n }\n /** @internal */\n _markSubMeshesAsAttributesDirty() {\n this._markSubMeshesAsDirty((defines) => defines.markAsAttributesDirty());\n }\n /** @internal */\n _markSubMeshesAsMiscDirty() {\n this._markSubMeshesAsDirty((defines) => defines.markAsMiscDirty());\n }\n /**\n * Flag the AbstractMesh as dirty (Forcing it to update everything)\n * @param property if set to \"rotation\" the objects rotationQuaternion will be set to null\n * @returns this AbstractMesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n markAsDirty(property) {\n this._currentRenderId = Number.MAX_VALUE;\n this._isDirty = true;\n return this;\n }\n /**\n * Resets the draw wrappers cache for all submeshes of this abstract mesh\n * @param passId If provided, releases only the draw wrapper corresponding to this render pass id\n */\n resetDrawCache(passId) {\n if (!this.subMeshes) {\n return;\n }\n for (const subMesh of this.subMeshes) {\n subMesh.resetDrawCache(passId);\n }\n }\n // Methods\n /**\n * Returns true if the mesh is blocked. Implemented by child classes\n */\n get isBlocked() {\n return false;\n }\n /**\n * Returns the mesh itself by default. Implemented by child classes\n * @param camera defines the camera to use to pick the right LOD level\n * @returns the currentAbstractMesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getLOD(camera) {\n return this;\n }\n /**\n * Returns 0 by default. Implemented by child classes\n * @returns an integer\n */\n getTotalVertices() {\n return 0;\n }\n /**\n * Returns a positive integer : the total number of indices in this mesh geometry.\n * @returns the number of indices or zero if the mesh has no geometry.\n */\n getTotalIndices() {\n return 0;\n }\n /**\n * Returns null by default. Implemented by child classes\n * @returns null\n */\n getIndices() {\n return null;\n }\n /**\n * Returns the array of the requested vertex data kind. Implemented by child classes\n * @param kind defines the vertex data kind to use\n * @returns null\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getVerticesData(kind) {\n return null;\n }\n /**\n * Sets the vertex data of the mesh geometry for the requested `kind`.\n * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.\n * Note that a new underlying VertexBuffer object is created each call.\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.\n * @param kind defines vertex data kind:\n * * VertexBuffer.PositionKind\n * * VertexBuffer.UVKind\n * * VertexBuffer.UV2Kind\n * * VertexBuffer.UV3Kind\n * * VertexBuffer.UV4Kind\n * * VertexBuffer.UV5Kind\n * * VertexBuffer.UV6Kind\n * * VertexBuffer.ColorKind\n * * VertexBuffer.MatricesIndicesKind\n * * VertexBuffer.MatricesIndicesExtraKind\n * * VertexBuffer.MatricesWeightsKind\n * * VertexBuffer.MatricesWeightsExtraKind\n * @param data defines the data source\n * @param updatable defines if the data must be flagged as updatable (or static)\n * @param stride defines the vertex stride (size of an entire vertex). Can be null and in this case will be deduced from vertex data kind\n * @returns the current mesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setVerticesData(kind, data, updatable, stride) {\n return this;\n }\n /**\n * Updates the existing vertex data of the mesh geometry for the requested `kind`.\n * If the mesh has no geometry, it is simply returned as it is.\n * @param kind defines vertex data kind:\n * * VertexBuffer.PositionKind\n * * VertexBuffer.UVKind\n * * VertexBuffer.UV2Kind\n * * VertexBuffer.UV3Kind\n * * VertexBuffer.UV4Kind\n * * VertexBuffer.UV5Kind\n * * VertexBuffer.UV6Kind\n * * VertexBuffer.ColorKind\n * * VertexBuffer.MatricesIndicesKind\n * * VertexBuffer.MatricesIndicesExtraKind\n * * VertexBuffer.MatricesWeightsKind\n * * VertexBuffer.MatricesWeightsExtraKind\n * @param data defines the data source\n * @param updateExtends If `kind` is `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed\n * @param makeItUnique If true, a new global geometry is created from this data and is set to the mesh\n * @returns the current mesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n updateVerticesData(kind, data, updateExtends, makeItUnique) {\n return this;\n }\n /**\n * Sets the mesh indices,\n * If the mesh has no geometry, a new Geometry object is created and set to the mesh.\n * @param indices Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array)\n * @param totalVertices Defines the total number of vertices\n * @returns the current mesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setIndices(indices, totalVertices) {\n return this;\n }\n /**\n * Gets a boolean indicating if specific vertex data is present\n * @param kind defines the vertex data kind to use\n * @returns true is data kind is present\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isVerticesDataPresent(kind) {\n return false;\n }\n /**\n * Returns the mesh BoundingInfo object or creates a new one and returns if it was undefined.\n * Note that it returns a shallow bounding of the mesh (i.e. it does not include children).\n * However, if the mesh contains thin instances, it will be expanded to include them. If you want the \"raw\" bounding data instead, then use `getRawBoundingInfo()`.\n * To get the full bounding of all children, call `getHierarchyBoundingVectors` instead.\n * @returns a BoundingInfo\n */\n getBoundingInfo() {\n if (this._masterMesh) {\n return this._masterMesh.getBoundingInfo();\n }\n if (this._boundingInfoIsDirty) {\n this._boundingInfoIsDirty = false;\n // this._boundingInfo is being created if undefined\n this._updateBoundingInfo();\n }\n // cannot be null.\n return this._boundingInfo;\n }\n /**\n * Returns the bounding info unnafected by instance data.\n * @returns the bounding info of the mesh unaffected by instance data.\n */\n getRawBoundingInfo() {\n var _a;\n return (_a = this.rawBoundingInfo) !== null && _a !== void 0 ? _a : this.getBoundingInfo();\n }\n /**\n * Overwrite the current bounding info\n * @param boundingInfo defines the new bounding info\n * @returns the current mesh\n */\n setBoundingInfo(boundingInfo) {\n this._boundingInfo = boundingInfo;\n return this;\n }\n /**\n * Returns true if there is already a bounding info\n */\n get hasBoundingInfo() {\n return this._boundingInfo !== null;\n }\n /**\n * Creates a new bounding info for the mesh\n * @param minimum min vector of the bounding box/sphere\n * @param maximum max vector of the bounding box/sphere\n * @param worldMatrix defines the new world matrix\n * @returns the new bounding info\n */\n buildBoundingInfo(minimum, maximum, worldMatrix) {\n this._boundingInfo = new BoundingInfo(minimum, maximum, worldMatrix);\n return this._boundingInfo;\n }\n /**\n * Uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units)\n * @param includeDescendants Use the hierarchy's bounding box instead of the mesh's bounding box. Default is false\n * @param ignoreRotation ignore rotation when computing the scale (ie. object will be axis aligned). Default is false\n * @param predicate predicate that is passed in to getHierarchyBoundingVectors when selecting which object should be included when scaling\n * @returns the current mesh\n */\n normalizeToUnitCube(includeDescendants = true, ignoreRotation = false, predicate) {\n return super.normalizeToUnitCube(includeDescendants, ignoreRotation, predicate);\n }\n /** Gets a boolean indicating if this mesh has skinning data and an attached skeleton */\n get useBones() {\n return ((this.skeleton &&\n this.getScene().skeletonsEnabled &&\n this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) &&\n this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)));\n }\n /** @internal */\n _preActivate() { }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _preActivateForIntermediateRendering(renderId) { }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _activate(renderId, intermediateRendering) {\n this._renderId = renderId;\n return true;\n }\n /** @internal */\n _postActivate() {\n // Do nothing\n }\n /** @internal */\n _freeze() {\n // Do nothing\n }\n /** @internal */\n _unFreeze() {\n // Do nothing\n }\n /**\n * Gets the current world matrix\n * @returns a Matrix\n */\n getWorldMatrix() {\n if (this._masterMesh && this.billboardMode === TransformNode.BILLBOARDMODE_NONE) {\n return this._masterMesh.getWorldMatrix();\n }\n return super.getWorldMatrix();\n }\n /** @internal */\n _getWorldMatrixDeterminant() {\n if (this._masterMesh) {\n return this._masterMesh._getWorldMatrixDeterminant();\n }\n return super._getWorldMatrixDeterminant();\n }\n /**\n * Gets a boolean indicating if this mesh is an instance or a regular mesh\n */\n get isAnInstance() {\n return false;\n }\n /**\n * Gets a boolean indicating if this mesh has instances\n */\n get hasInstances() {\n return false;\n }\n /**\n * Gets a boolean indicating if this mesh has thin instances\n */\n get hasThinInstances() {\n return false;\n }\n // ================================== Point of View Movement =================================\n /**\n * Perform relative position change from the point of view of behind the front of the mesh.\n * This is performed taking into account the meshes current rotation, so you do not have to care.\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\n * @param amountRight defines the distance on the right axis\n * @param amountUp defines the distance on the up axis\n * @param amountForward defines the distance on the forward axis\n * @returns the current mesh\n */\n movePOV(amountRight, amountUp, amountForward) {\n this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));\n return this;\n }\n /**\n * Calculate relative position change from the point of view of behind the front of the mesh.\n * This is performed taking into account the meshes current rotation, so you do not have to care.\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\n * @param amountRight defines the distance on the right axis\n * @param amountUp defines the distance on the up axis\n * @param amountForward defines the distance on the forward axis\n * @returns the new displacement vector\n */\n calcMovePOV(amountRight, amountUp, amountForward) {\n const rotMatrix = new Matrix();\n const rotQuaternion = this.rotationQuaternion ? this.rotationQuaternion : Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);\n rotQuaternion.toRotationMatrix(rotMatrix);\n const translationDelta = Vector3.Zero();\n const defForwardMult = this.definedFacingForward ? -1 : 1;\n Vector3.TransformCoordinatesFromFloatsToRef(amountRight * defForwardMult, amountUp, amountForward * defForwardMult, rotMatrix, translationDelta);\n return translationDelta;\n }\n // ================================== Point of View Rotation =================================\n /**\n * Perform relative rotation change from the point of view of behind the front of the mesh.\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\n * @param flipBack defines the flip\n * @param twirlClockwise defines the twirl\n * @param tiltRight defines the tilt\n * @returns the current mesh\n */\n rotatePOV(flipBack, twirlClockwise, tiltRight) {\n this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));\n return this;\n }\n /**\n * Calculate relative rotation change from the point of view of behind the front of the mesh.\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\n * @param flipBack defines the flip\n * @param twirlClockwise defines the twirl\n * @param tiltRight defines the tilt\n * @returns the new rotation vector\n */\n calcRotatePOV(flipBack, twirlClockwise, tiltRight) {\n const defForwardMult = this.definedFacingForward ? 1 : -1;\n return new Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);\n }\n /**\n * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.\n * This means the mesh underlying bounding box and sphere are recomputed.\n * @param applySkeleton defines whether to apply the skeleton before computing the bounding info\n * @param applyMorph defines whether to apply the morph target before computing the bounding info\n * @returns the current mesh\n */\n refreshBoundingInfo(applySkeleton = false, applyMorph = false) {\n if (this._boundingInfo && this._boundingInfo.isLocked) {\n return this;\n }\n this._refreshBoundingInfo(this._getPositionData(applySkeleton, applyMorph), null);\n return this;\n }\n /**\n * @internal\n */\n _refreshBoundingInfo(data, bias) {\n if (data) {\n const extend = extractMinAndMax(data, 0, this.getTotalVertices(), bias);\n if (this._boundingInfo) {\n this._boundingInfo.reConstruct(extend.minimum, extend.maximum);\n }\n else {\n this._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);\n }\n }\n if (this.subMeshes) {\n for (let index = 0; index < this.subMeshes.length; index++) {\n this.subMeshes[index].refreshBoundingInfo(data);\n }\n }\n this._updateBoundingInfo();\n }\n /**\n * Internal function to get buffer data and possibly apply morphs and normals\n * @param applySkeleton\n * @param applyMorph\n * @param data\n * @param kind the kind of data you want. Can be Normal or Position\n */\n _getData(applySkeleton = false, applyMorph = false, data, kind = VertexBuffer.PositionKind) {\n data = data !== null && data !== void 0 ? data : this.getVerticesData(kind).slice();\n if (data && applyMorph && this.morphTargetManager) {\n let faceIndexCount = 0;\n let positionIndex = 0;\n for (let vertexCount = 0; vertexCount < data.length; vertexCount++) {\n for (let targetCount = 0; targetCount < this.morphTargetManager.numTargets; targetCount++) {\n const targetMorph = this.morphTargetManager.getTarget(targetCount);\n const influence = targetMorph.influence;\n if (influence > 0.0) {\n const morphTargetPositions = targetMorph.getPositions();\n if (morphTargetPositions) {\n data[vertexCount] += (morphTargetPositions[vertexCount] - data[vertexCount]) * influence;\n }\n }\n }\n faceIndexCount++;\n if (kind === VertexBuffer.PositionKind) {\n if (this._positions && faceIndexCount === 3) {\n // We want to merge into positions every 3 indices starting (but not 0)\n faceIndexCount = 0;\n const index = positionIndex * 3;\n this._positions[positionIndex++].copyFromFloats(data[index], data[index + 1], data[index + 2]);\n }\n }\n }\n }\n if (data && applySkeleton && this.skeleton) {\n const matricesIndicesData = this.getVerticesData(VertexBuffer.MatricesIndicesKind);\n const matricesWeightsData = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\n if (matricesWeightsData && matricesIndicesData) {\n const needExtras = this.numBoneInfluencers > 4;\n const matricesIndicesExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;\n const matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;\n const skeletonMatrices = this.skeleton.getTransformMatrices(this);\n const tempVector = TmpVectors.Vector3[0];\n const finalMatrix = TmpVectors.Matrix[0];\n const tempMatrix = TmpVectors.Matrix[1];\n let matWeightIdx = 0;\n for (let index = 0; index < data.length; index += 3, matWeightIdx += 4) {\n finalMatrix.reset();\n let inf;\n let weight;\n for (inf = 0; inf < 4; inf++) {\n weight = matricesWeightsData[matWeightIdx + inf];\n if (weight > 0) {\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesData[matWeightIdx + inf] * 16), weight, tempMatrix);\n finalMatrix.addToSelf(tempMatrix);\n }\n }\n if (needExtras) {\n for (inf = 0; inf < 4; inf++) {\n weight = matricesWeightsExtraData[matWeightIdx + inf];\n if (weight > 0) {\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesExtraData[matWeightIdx + inf] * 16), weight, tempMatrix);\n finalMatrix.addToSelf(tempMatrix);\n }\n }\n }\n if (kind === VertexBuffer.NormalKind) {\n Vector3.TransformNormalFromFloatsToRef(data[index], data[index + 1], data[index + 2], finalMatrix, tempVector);\n }\n else {\n Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], finalMatrix, tempVector);\n }\n tempVector.toArray(data, index);\n if (kind === VertexBuffer.PositionKind && this._positions) {\n this._positions[index / 3].copyFrom(tempVector);\n }\n }\n }\n }\n return data;\n }\n /**\n * Get the normals vertex data and optionally apply skeleton and morphing.\n * @param applySkeleton defines whether to apply the skeleton\n * @param applyMorph defines whether to apply the morph target\n * @returns the normals data\n */\n getNormalsData(applySkeleton = false, applyMorph = false) {\n return this._getData(applySkeleton, applyMorph, null, VertexBuffer.NormalKind);\n }\n /**\n * Get the position vertex data and optionally apply skeleton and morphing.\n * @param applySkeleton defines whether to apply the skeleton\n * @param applyMorph defines whether to apply the morph target\n * @param data defines the position data to apply the skeleton and morph to\n * @returns the position data\n */\n getPositionData(applySkeleton = false, applyMorph = false, data) {\n return this._getData(applySkeleton, applyMorph, data, VertexBuffer.PositionKind);\n }\n /**\n * @internal\n */\n _getPositionData(applySkeleton, applyMorph) {\n var _a;\n let data = this.getVerticesData(VertexBuffer.PositionKind);\n if (this._internalAbstractMeshDataInfo._positions) {\n this._internalAbstractMeshDataInfo._positions = null;\n }\n if (data && ((applySkeleton && this.skeleton) || (applyMorph && this.morphTargetManager))) {\n data = data.slice();\n this._generatePointsArray();\n if (this._positions) {\n const pos = this._positions;\n this._internalAbstractMeshDataInfo._positions = new Array(pos.length);\n for (let i = 0; i < pos.length; i++) {\n this._internalAbstractMeshDataInfo._positions[i] = ((_a = pos[i]) === null || _a === void 0 ? void 0 : _a.clone()) || new Vector3();\n }\n }\n return this.getPositionData(applySkeleton, applyMorph, data);\n }\n return data;\n }\n /** @internal */\n _updateBoundingInfo() {\n if (this._boundingInfo) {\n this._boundingInfo.update(this.worldMatrixFromCache);\n }\n else {\n this._boundingInfo = new BoundingInfo(Vector3.Zero(), Vector3.Zero(), this.worldMatrixFromCache);\n }\n this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\n return this;\n }\n /**\n * @internal\n */\n _updateSubMeshesBoundingInfo(matrix) {\n if (!this.subMeshes) {\n return this;\n }\n const count = this.subMeshes.length;\n for (let subIndex = 0; subIndex < count; subIndex++) {\n const subMesh = this.subMeshes[subIndex];\n if (count > 1 || !subMesh.IsGlobal) {\n subMesh.updateBoundingInfo(matrix);\n }\n }\n return this;\n }\n /** @internal */\n _afterComputeWorldMatrix() {\n if (this.doNotSyncBoundingInfo) {\n return;\n }\n // Bounding info\n this._boundingInfoIsDirty = true;\n }\n /**\n * Returns `true` if the mesh is within the frustum defined by the passed array of planes.\n * A mesh is in the frustum if its bounding box intersects the frustum\n * @param frustumPlanes defines the frustum to test\n * @returns true if the mesh is in the frustum planes\n */\n isInFrustum(frustumPlanes) {\n return this.getBoundingInfo().isInFrustum(frustumPlanes, this.cullingStrategy);\n }\n /**\n * Returns `true` if the mesh is completely in the frustum defined be the passed array of planes.\n * A mesh is completely in the frustum if its bounding box it completely inside the frustum.\n * @param frustumPlanes defines the frustum to test\n * @returns true if the mesh is completely in the frustum planes\n */\n isCompletelyInFrustum(frustumPlanes) {\n return this.getBoundingInfo().isCompletelyInFrustum(frustumPlanes);\n }\n /**\n * True if the mesh intersects another mesh or a SolidParticle object\n * @param mesh defines a target mesh or SolidParticle to test\n * @param precise Unless the parameter `precise` is set to `true` the intersection is computed according to Axis Aligned Bounding Boxes (AABB), else according to OBB (Oriented BBoxes)\n * @param includeDescendants Can be set to true to test if the mesh defined in parameters intersects with the current mesh or any child meshes\n * @returns true if there is an intersection\n */\n intersectsMesh(mesh, precise = false, includeDescendants) {\n const boundingInfo = this.getBoundingInfo();\n const otherBoundingInfo = mesh.getBoundingInfo();\n if (boundingInfo.intersects(otherBoundingInfo, precise)) {\n return true;\n }\n if (includeDescendants) {\n for (const child of this.getChildMeshes()) {\n if (child.intersectsMesh(mesh, precise, true)) {\n return true;\n }\n }\n }\n return false;\n }\n /**\n * Returns true if the passed point (Vector3) is inside the mesh bounding box\n * @param point defines the point to test\n * @returns true if there is an intersection\n */\n intersectsPoint(point) {\n return this.getBoundingInfo().intersectsPoint(point);\n }\n // Collisions\n /**\n * Gets or sets a boolean indicating that this mesh can be used in the collision engine\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n */\n get checkCollisions() {\n return this._internalAbstractMeshDataInfo._meshCollisionData._checkCollisions;\n }\n set checkCollisions(collisionEnabled) {\n this._internalAbstractMeshDataInfo._meshCollisionData._checkCollisions = collisionEnabled;\n }\n /**\n * Gets Collider object used to compute collisions (not physics)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n */\n get collider() {\n return this._internalAbstractMeshDataInfo._meshCollisionData._collider;\n }\n /**\n * Move the mesh using collision engine\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\n * @param displacement defines the requested displacement vector\n * @returns the current mesh\n */\n moveWithCollisions(displacement) {\n const globalPosition = this.getAbsolutePosition();\n globalPosition.addToRef(this.ellipsoidOffset, this._internalAbstractMeshDataInfo._meshCollisionData._oldPositionForCollisions);\n const coordinator = this.getScene().collisionCoordinator;\n if (!this._internalAbstractMeshDataInfo._meshCollisionData._collider) {\n this._internalAbstractMeshDataInfo._meshCollisionData._collider = coordinator.createCollider();\n }\n this._internalAbstractMeshDataInfo._meshCollisionData._collider._radius = this.ellipsoid;\n coordinator.getNewPosition(this._internalAbstractMeshDataInfo._meshCollisionData._oldPositionForCollisions, displacement, this._internalAbstractMeshDataInfo._meshCollisionData._collider, this.collisionRetryCount, this, this._onCollisionPositionChange, this.uniqueId);\n return this;\n }\n // Collisions\n /**\n * @internal\n */\n _collideForSubMesh(subMesh, transformMatrix, collider) {\n var _a;\n this._generatePointsArray();\n if (!this._positions) {\n return this;\n }\n // Transformation\n if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {\n subMesh._lastColliderTransformMatrix = transformMatrix.clone();\n subMesh._lastColliderWorldVertices = [];\n subMesh._trianglePlanes = [];\n const start = subMesh.verticesStart;\n const end = subMesh.verticesStart + subMesh.verticesCount;\n for (let i = start; i < end; i++) {\n subMesh._lastColliderWorldVertices.push(Vector3.TransformCoordinates(this._positions[i], transformMatrix));\n }\n }\n // Collide\n collider._collide(subMesh._trianglePlanes, subMesh._lastColliderWorldVertices, this.getIndices(), subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart, !!subMesh.getMaterial(), this, this._shouldConvertRHS(), ((_a = subMesh.getMaterial()) === null || _a === void 0 ? void 0 : _a.fillMode) === 7);\n return this;\n }\n /**\n * @internal\n */\n _processCollisionsForSubMeshes(collider, transformMatrix) {\n const subMeshes = this._scene.getCollidingSubMeshCandidates(this, collider);\n const len = subMeshes.length;\n for (let index = 0; index < len; index++) {\n const subMesh = subMeshes.data[index];\n // Bounding test\n if (len > 1 && !subMesh._checkCollision(collider)) {\n continue;\n }\n this._collideForSubMesh(subMesh, transformMatrix, collider);\n }\n return this;\n }\n /** @internal */\n _shouldConvertRHS() {\n return false;\n }\n /**\n * @internal\n */\n _checkCollision(collider) {\n // Bounding box test\n if (!this.getBoundingInfo()._checkCollision(collider)) {\n return this;\n }\n // Transformation matrix\n const collisionsScalingMatrix = TmpVectors.Matrix[0];\n const collisionsTransformMatrix = TmpVectors.Matrix[1];\n Matrix.ScalingToRef(1.0 / collider._radius.x, 1.0 / collider._radius.y, 1.0 / collider._radius.z, collisionsScalingMatrix);\n this.worldMatrixFromCache.multiplyToRef(collisionsScalingMatrix, collisionsTransformMatrix);\n this._processCollisionsForSubMeshes(collider, collisionsTransformMatrix);\n return this;\n }\n // Picking\n /** @internal */\n _generatePointsArray() {\n return false;\n }\n /**\n * Checks if the passed Ray intersects with the mesh. A mesh triangle can be picked both from its front and back sides,\n * irrespective of orientation.\n * @param ray defines the ray to use. It should be in the mesh's LOCAL coordinate space.\n * @param fastCheck defines if fast mode (but less precise) must be used (false by default)\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\n * @param worldToUse defines the world matrix to use to get the world coordinate of the intersection point\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\n * @returns the picking info\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\n */\n intersects(ray, fastCheck, trianglePredicate, onlyBoundingInfo = false, worldToUse, skipBoundingInfo = false) {\n const pickingInfo = new PickingInfo();\n const className = this.getClassName();\n const intersectionThreshold = className === \"InstancedLinesMesh\" || className === \"LinesMesh\" || className === \"GreasedLineMesh\" ? this.intersectionThreshold : 0;\n const boundingInfo = this.getBoundingInfo();\n if (!this.subMeshes) {\n return pickingInfo;\n }\n if (!skipBoundingInfo &&\n (!ray.intersectsSphere(boundingInfo.boundingSphere, intersectionThreshold) || !ray.intersectsBox(boundingInfo.boundingBox, intersectionThreshold))) {\n return pickingInfo;\n }\n if (onlyBoundingInfo) {\n pickingInfo.hit = skipBoundingInfo ? false : true;\n pickingInfo.pickedMesh = skipBoundingInfo ? null : this;\n pickingInfo.distance = skipBoundingInfo ? 0 : Vector3.Distance(ray.origin, boundingInfo.boundingSphere.center);\n pickingInfo.subMeshId = 0;\n return pickingInfo;\n }\n if (!this._generatePointsArray()) {\n return pickingInfo;\n }\n let intersectInfo = null;\n const subMeshes = this._scene.getIntersectingSubMeshCandidates(this, ray);\n const len = subMeshes.length;\n // Check if all submeshes are using a material that don't allow picking (point/lines rendering)\n // if no submesh can be picked that way, then fallback to BBox picking\n let anySubmeshSupportIntersect = false;\n for (let index = 0; index < len; index++) {\n const subMesh = subMeshes.data[index];\n const material = subMesh.getMaterial();\n if (!material) {\n continue;\n }\n if (material.fillMode == 7 ||\n material.fillMode == 0 ||\n material.fillMode == 1 ||\n material.fillMode == 2 ||\n material.fillMode == 4) {\n anySubmeshSupportIntersect = true;\n break;\n }\n }\n // no sub mesh support intersection, fallback to BBox that has already be done\n if (!anySubmeshSupportIntersect) {\n pickingInfo.hit = true;\n pickingInfo.pickedMesh = this;\n pickingInfo.distance = Vector3.Distance(ray.origin, boundingInfo.boundingSphere.center);\n pickingInfo.subMeshId = -1;\n return pickingInfo;\n }\n // at least 1 submesh supports intersection, keep going\n for (let index = 0; index < len; index++) {\n const subMesh = subMeshes.data[index];\n // Bounding test\n if (len > 1 && !subMesh.canIntersects(ray)) {\n continue;\n }\n const currentIntersectInfo = subMesh.intersects(ray, this._positions, this.getIndices(), fastCheck, trianglePredicate);\n if (currentIntersectInfo) {\n if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {\n intersectInfo = currentIntersectInfo;\n intersectInfo.subMeshId = index;\n if (fastCheck) {\n break;\n }\n }\n }\n }\n if (intersectInfo) {\n // Get picked point\n const world = worldToUse !== null && worldToUse !== void 0 ? worldToUse : this.getWorldMatrix();\n const worldOrigin = TmpVectors.Vector3[0];\n const direction = TmpVectors.Vector3[1];\n Vector3.TransformCoordinatesToRef(ray.origin, world, worldOrigin);\n ray.direction.scaleToRef(intersectInfo.distance, direction);\n const worldDirection = Vector3.TransformNormal(direction, world);\n const pickedPoint = worldDirection.addInPlace(worldOrigin);\n // Return result\n pickingInfo.hit = true;\n pickingInfo.distance = Vector3.Distance(worldOrigin, pickedPoint);\n pickingInfo.pickedPoint = pickedPoint;\n pickingInfo.pickedMesh = this;\n pickingInfo.bu = intersectInfo.bu || 0;\n pickingInfo.bv = intersectInfo.bv || 0;\n pickingInfo.subMeshFaceId = intersectInfo.faceId;\n pickingInfo.faceId = intersectInfo.faceId + subMeshes.data[intersectInfo.subMeshId].indexStart / (this.getClassName().indexOf(\"LinesMesh\") !== -1 ? 2 : 3);\n pickingInfo.subMeshId = intersectInfo.subMeshId;\n return pickingInfo;\n }\n return pickingInfo;\n }\n /**\n * Clones the current mesh\n * @param name defines the mesh name\n * @param newParent defines the new mesh parent\n * @param doNotCloneChildren defines a boolean indicating that children must not be cloned (false by default)\n * @returns the new mesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n clone(name, newParent, doNotCloneChildren) {\n return null;\n }\n /**\n * Disposes all the submeshes of the current meshnp\n * @returns the current mesh\n */\n releaseSubMeshes() {\n if (this.subMeshes) {\n while (this.subMeshes.length) {\n this.subMeshes[0].dispose();\n }\n }\n else {\n this.subMeshes = new Array();\n }\n return this;\n }\n /**\n * Releases resources associated with this abstract mesh.\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n let index;\n // mesh map release.\n if (this._scene.useMaterialMeshMap) {\n // remove from material mesh map id needed\n if (this._internalAbstractMeshDataInfo._material && this._internalAbstractMeshDataInfo._material.meshMap) {\n this._internalAbstractMeshDataInfo._material.meshMap[this.uniqueId] = undefined;\n }\n }\n // Smart Array Retainers.\n this.getScene().freeActiveMeshes();\n this.getScene().freeRenderingGroups();\n // Action manager\n if (this.actionManager !== undefined && this.actionManager !== null) {\n this.actionManager.dispose();\n this.actionManager = null;\n }\n // Skeleton\n this._internalAbstractMeshDataInfo._skeleton = null;\n if (this._transformMatrixTexture) {\n this._transformMatrixTexture.dispose();\n this._transformMatrixTexture = null;\n }\n // Intersections in progress\n for (index = 0; index < this._intersectionsInProgress.length; index++) {\n const other = this._intersectionsInProgress[index];\n const pos = other._intersectionsInProgress.indexOf(this);\n other._intersectionsInProgress.splice(pos, 1);\n }\n this._intersectionsInProgress.length = 0;\n // Lights\n const lights = this.getScene().lights;\n lights.forEach((light) => {\n let meshIndex = light.includedOnlyMeshes.indexOf(this);\n if (meshIndex !== -1) {\n light.includedOnlyMeshes.splice(meshIndex, 1);\n }\n meshIndex = light.excludedMeshes.indexOf(this);\n if (meshIndex !== -1) {\n light.excludedMeshes.splice(meshIndex, 1);\n }\n // Shadow generators\n const generators = light.getShadowGenerators();\n if (generators) {\n const iterator = generators.values();\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\n const generator = key.value;\n const shadowMap = generator.getShadowMap();\n if (shadowMap && shadowMap.renderList) {\n meshIndex = shadowMap.renderList.indexOf(this);\n if (meshIndex !== -1) {\n shadowMap.renderList.splice(meshIndex, 1);\n }\n }\n }\n }\n });\n // SubMeshes\n if (this.getClassName() !== \"InstancedMesh\" || this.getClassName() !== \"InstancedLinesMesh\") {\n this.releaseSubMeshes();\n }\n // Query\n const engine = this.getScene().getEngine();\n if (this._occlusionQuery !== null) {\n this.isOcclusionQueryInProgress = false;\n engine.deleteQuery(this._occlusionQuery);\n this._occlusionQuery = null;\n }\n // Engine\n engine.wipeCaches();\n // Remove from scene\n this.getScene().removeMesh(this);\n if (this._parentContainer) {\n const index = this._parentContainer.meshes.indexOf(this);\n if (index > -1) {\n this._parentContainer.meshes.splice(index, 1);\n }\n this._parentContainer = null;\n }\n if (disposeMaterialAndTextures) {\n if (this.material) {\n if (this.material.getClassName() === \"MultiMaterial\") {\n this.material.dispose(false, true, true);\n }\n else {\n this.material.dispose(false, true);\n }\n }\n }\n if (!doNotRecurse) {\n // Particles\n for (index = 0; index < this.getScene().particleSystems.length; index++) {\n if (this.getScene().particleSystems[index].emitter === this) {\n this.getScene().particleSystems[index].dispose();\n index--;\n }\n }\n }\n // facet data\n if (this._internalAbstractMeshDataInfo._facetData.facetDataEnabled) {\n this.disableFacetData();\n }\n this._uniformBuffer.dispose();\n this.onAfterWorldMatrixUpdateObservable.clear();\n this.onCollideObservable.clear();\n this.onCollisionPositionChangeObservable.clear();\n this.onRebuildObservable.clear();\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n /**\n * Adds the passed mesh as a child to the current mesh\n * @param mesh defines the child mesh\n * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.\n * @returns the current mesh\n */\n addChild(mesh, preserveScalingSign = false) {\n mesh.setParent(this, preserveScalingSign);\n return this;\n }\n /**\n * Removes the passed mesh from the current mesh children list\n * @param mesh defines the child mesh\n * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.\n * @returns the current mesh\n */\n removeChild(mesh, preserveScalingSign = false) {\n mesh.setParent(null, preserveScalingSign);\n return this;\n }\n // Facet data\n /** @internal */\n _initFacetData() {\n const data = this._internalAbstractMeshDataInfo._facetData;\n if (!data.facetNormals) {\n data.facetNormals = new Array();\n }\n if (!data.facetPositions) {\n data.facetPositions = new Array();\n }\n if (!data.facetPartitioning) {\n data.facetPartitioning = new Array();\n }\n data.facetNb = (this.getIndices().length / 3) | 0;\n data.partitioningSubdivisions = data.partitioningSubdivisions ? data.partitioningSubdivisions : 10; // default nb of partitioning subdivisions = 10\n data.partitioningBBoxRatio = data.partitioningBBoxRatio ? data.partitioningBBoxRatio : 1.01; // default ratio 1.01 = the partitioning is 1% bigger than the bounding box\n for (let f = 0; f < data.facetNb; f++) {\n data.facetNormals[f] = Vector3.Zero();\n data.facetPositions[f] = Vector3.Zero();\n }\n data.facetDataEnabled = true;\n return this;\n }\n /**\n * Updates the mesh facetData arrays and the internal partitioning when the mesh is morphed or updated.\n * This method can be called within the render loop.\n * You don't need to call this method by yourself in the render loop when you update/morph a mesh with the methods CreateXXX() as they automatically manage this computation\n * @returns the current mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n updateFacetData() {\n const data = this._internalAbstractMeshDataInfo._facetData;\n if (!data.facetDataEnabled) {\n this._initFacetData();\n }\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\n const indices = this.getIndices();\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\n const bInfo = this.getBoundingInfo();\n if (data.facetDepthSort && !data.facetDepthSortEnabled) {\n // init arrays, matrix and sort function on first call\n data.facetDepthSortEnabled = true;\n if (indices instanceof Uint16Array) {\n data.depthSortedIndices = new Uint16Array(indices);\n }\n else if (indices instanceof Uint32Array) {\n data.depthSortedIndices = new Uint32Array(indices);\n }\n else {\n let needs32bits = false;\n for (let i = 0; i < indices.length; i++) {\n if (indices[i] > 65535) {\n needs32bits = true;\n break;\n }\n }\n if (needs32bits) {\n data.depthSortedIndices = new Uint32Array(indices);\n }\n else {\n data.depthSortedIndices = new Uint16Array(indices);\n }\n }\n data.facetDepthSortFunction = function (f1, f2) {\n return f2.sqDistance - f1.sqDistance;\n };\n if (!data.facetDepthSortFrom) {\n const camera = this.getScene().activeCamera;\n data.facetDepthSortFrom = camera ? camera.position : Vector3.Zero();\n }\n data.depthSortedFacets = [];\n for (let f = 0; f < data.facetNb; f++) {\n const depthSortedFacet = { ind: f * 3, sqDistance: 0.0 };\n data.depthSortedFacets.push(depthSortedFacet);\n }\n data.invertedMatrix = Matrix.Identity();\n data.facetDepthSortOrigin = Vector3.Zero();\n }\n data.bbSize.x = bInfo.maximum.x - bInfo.minimum.x > Epsilon ? bInfo.maximum.x - bInfo.minimum.x : Epsilon;\n data.bbSize.y = bInfo.maximum.y - bInfo.minimum.y > Epsilon ? bInfo.maximum.y - bInfo.minimum.y : Epsilon;\n data.bbSize.z = bInfo.maximum.z - bInfo.minimum.z > Epsilon ? bInfo.maximum.z - bInfo.minimum.z : Epsilon;\n let bbSizeMax = data.bbSize.x > data.bbSize.y ? data.bbSize.x : data.bbSize.y;\n bbSizeMax = bbSizeMax > data.bbSize.z ? bbSizeMax : data.bbSize.z;\n data.subDiv.max = data.partitioningSubdivisions;\n data.subDiv.X = Math.floor((data.subDiv.max * data.bbSize.x) / bbSizeMax); // adjust the number of subdivisions per axis\n data.subDiv.Y = Math.floor((data.subDiv.max * data.bbSize.y) / bbSizeMax); // according to each bbox size per axis\n data.subDiv.Z = Math.floor((data.subDiv.max * data.bbSize.z) / bbSizeMax);\n data.subDiv.X = data.subDiv.X < 1 ? 1 : data.subDiv.X; // at least one subdivision\n data.subDiv.Y = data.subDiv.Y < 1 ? 1 : data.subDiv.Y;\n data.subDiv.Z = data.subDiv.Z < 1 ? 1 : data.subDiv.Z;\n // set the parameters for ComputeNormals()\n data.facetParameters.facetNormals = this.getFacetLocalNormals();\n data.facetParameters.facetPositions = this.getFacetLocalPositions();\n data.facetParameters.facetPartitioning = this.getFacetLocalPartitioning();\n data.facetParameters.bInfo = bInfo;\n data.facetParameters.bbSize = data.bbSize;\n data.facetParameters.subDiv = data.subDiv;\n data.facetParameters.ratio = this.partitioningBBoxRatio;\n data.facetParameters.depthSort = data.facetDepthSort;\n if (data.facetDepthSort && data.facetDepthSortEnabled) {\n this.computeWorldMatrix(true);\n this._worldMatrix.invertToRef(data.invertedMatrix);\n Vector3.TransformCoordinatesToRef(data.facetDepthSortFrom, data.invertedMatrix, data.facetDepthSortOrigin);\n data.facetParameters.distanceTo = data.facetDepthSortOrigin;\n }\n data.facetParameters.depthSortedFacets = data.depthSortedFacets;\n if (normals) {\n VertexData.ComputeNormals(positions, indices, normals, data.facetParameters);\n }\n if (data.facetDepthSort && data.facetDepthSortEnabled) {\n data.depthSortedFacets.sort(data.facetDepthSortFunction);\n const l = (data.depthSortedIndices.length / 3) | 0;\n for (let f = 0; f < l; f++) {\n const sind = data.depthSortedFacets[f].ind;\n data.depthSortedIndices[f * 3] = indices[sind];\n data.depthSortedIndices[f * 3 + 1] = indices[sind + 1];\n data.depthSortedIndices[f * 3 + 2] = indices[sind + 2];\n }\n this.updateIndices(data.depthSortedIndices, undefined, true);\n }\n return this;\n }\n /**\n * Returns the facetLocalNormals array.\n * The normals are expressed in the mesh local spac\n * @returns an array of Vector3\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetLocalNormals() {\n const facetData = this._internalAbstractMeshDataInfo._facetData;\n if (!facetData.facetNormals) {\n this.updateFacetData();\n }\n return facetData.facetNormals;\n }\n /**\n * Returns the facetLocalPositions array.\n * The facet positions are expressed in the mesh local space\n * @returns an array of Vector3\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetLocalPositions() {\n const facetData = this._internalAbstractMeshDataInfo._facetData;\n if (!facetData.facetPositions) {\n this.updateFacetData();\n }\n return facetData.facetPositions;\n }\n /**\n * Returns the facetLocalPartitioning array\n * @returns an array of array of numbers\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetLocalPartitioning() {\n const facetData = this._internalAbstractMeshDataInfo._facetData;\n if (!facetData.facetPartitioning) {\n this.updateFacetData();\n }\n return facetData.facetPartitioning;\n }\n /**\n * Returns the i-th facet position in the world system.\n * This method allocates a new Vector3 per call\n * @param i defines the facet index\n * @returns a new Vector3\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetPosition(i) {\n const pos = Vector3.Zero();\n this.getFacetPositionToRef(i, pos);\n return pos;\n }\n /**\n * Sets the reference Vector3 with the i-th facet position in the world system\n * @param i defines the facet index\n * @param ref defines the target vector\n * @returns the current mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetPositionToRef(i, ref) {\n const localPos = this.getFacetLocalPositions()[i];\n const world = this.getWorldMatrix();\n Vector3.TransformCoordinatesToRef(localPos, world, ref);\n return this;\n }\n /**\n * Returns the i-th facet normal in the world system.\n * This method allocates a new Vector3 per call\n * @param i defines the facet index\n * @returns a new Vector3\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetNormal(i) {\n const norm = Vector3.Zero();\n this.getFacetNormalToRef(i, norm);\n return norm;\n }\n /**\n * Sets the reference Vector3 with the i-th facet normal in the world system\n * @param i defines the facet index\n * @param ref defines the target vector\n * @returns the current mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetNormalToRef(i, ref) {\n const localNorm = this.getFacetLocalNormals()[i];\n Vector3.TransformNormalToRef(localNorm, this.getWorldMatrix(), ref);\n return this;\n }\n /**\n * Returns the facets (in an array) in the same partitioning block than the one the passed coordinates are located (expressed in the mesh local system)\n * @param x defines x coordinate\n * @param y defines y coordinate\n * @param z defines z coordinate\n * @returns the array of facet indexes\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetsAtLocalCoordinates(x, y, z) {\n const bInfo = this.getBoundingInfo();\n const data = this._internalAbstractMeshDataInfo._facetData;\n const ox = Math.floor(((x - bInfo.minimum.x * data.partitioningBBoxRatio) * data.subDiv.X * data.partitioningBBoxRatio) / data.bbSize.x);\n const oy = Math.floor(((y - bInfo.minimum.y * data.partitioningBBoxRatio) * data.subDiv.Y * data.partitioningBBoxRatio) / data.bbSize.y);\n const oz = Math.floor(((z - bInfo.minimum.z * data.partitioningBBoxRatio) * data.subDiv.Z * data.partitioningBBoxRatio) / data.bbSize.z);\n if (ox < 0 || ox > data.subDiv.max || oy < 0 || oy > data.subDiv.max || oz < 0 || oz > data.subDiv.max) {\n return null;\n }\n return data.facetPartitioning[ox + data.subDiv.max * oy + data.subDiv.max * data.subDiv.max * oz];\n }\n /**\n * Returns the closest mesh facet index at (x,y,z) World coordinates, null if not found\n * @param x defines x coordinate\n * @param y defines y coordinate\n * @param z defines z coordinate\n * @param projected sets as the (x,y,z) world projection on the facet\n * @param checkFace if true (default false), only the facet \"facing\" to (x,y,z) or only the ones \"turning their backs\", according to the parameter \"facing\" are returned\n * @param facing if facing and checkFace are true, only the facet \"facing\" to (x, y, z) are returned : positive dot (x, y, z) * facet position. If facing si false and checkFace is true, only the facet \"turning their backs\" to (x, y, z) are returned : negative dot (x, y, z) * facet position\n * @returns the face index if found (or null instead)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getClosestFacetAtCoordinates(x, y, z, projected, checkFace = false, facing = true) {\n const world = this.getWorldMatrix();\n const invMat = TmpVectors.Matrix[5];\n world.invertToRef(invMat);\n const invVect = TmpVectors.Vector3[8];\n Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, invMat, invVect); // transform (x,y,z) to coordinates in the mesh local space\n const closest = this.getClosestFacetAtLocalCoordinates(invVect.x, invVect.y, invVect.z, projected, checkFace, facing);\n if (projected) {\n // transform the local computed projected vector to world coordinates\n Vector3.TransformCoordinatesFromFloatsToRef(projected.x, projected.y, projected.z, world, projected);\n }\n return closest;\n }\n /**\n * Returns the closest mesh facet index at (x,y,z) local coordinates, null if not found\n * @param x defines x coordinate\n * @param y defines y coordinate\n * @param z defines z coordinate\n * @param projected sets as the (x,y,z) local projection on the facet\n * @param checkFace if true (default false), only the facet \"facing\" to (x,y,z) or only the ones \"turning their backs\", according to the parameter \"facing\" are returned\n * @param facing if facing and checkFace are true, only the facet \"facing\" to (x, y, z) are returned : positive dot (x, y, z) * facet position. If facing si false and checkFace is true, only the facet \"turning their backs\" to (x, y, z) are returned : negative dot (x, y, z) * facet position\n * @returns the face index if found (or null instead)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getClosestFacetAtLocalCoordinates(x, y, z, projected, checkFace = false, facing = true) {\n let closest = null;\n let tmpx = 0.0;\n let tmpy = 0.0;\n let tmpz = 0.0;\n let d = 0.0; // tmp dot facet normal * facet position\n let t0 = 0.0;\n let projx = 0.0;\n let projy = 0.0;\n let projz = 0.0;\n // Get all the facets in the same partitioning block than (x, y, z)\n const facetPositions = this.getFacetLocalPositions();\n const facetNormals = this.getFacetLocalNormals();\n const facetsInBlock = this.getFacetsAtLocalCoordinates(x, y, z);\n if (!facetsInBlock) {\n return null;\n }\n // Get the closest facet to (x, y, z)\n let shortest = Number.MAX_VALUE; // init distance vars\n let tmpDistance = shortest;\n let fib; // current facet in the block\n let norm; // current facet normal\n let p0; // current facet barycenter position\n // loop on all the facets in the current partitioning block\n for (let idx = 0; idx < facetsInBlock.length; idx++) {\n fib = facetsInBlock[idx];\n norm = facetNormals[fib];\n p0 = facetPositions[fib];\n d = (x - p0.x) * norm.x + (y - p0.y) * norm.y + (z - p0.z) * norm.z;\n if (!checkFace || (checkFace && facing && d >= 0.0) || (checkFace && !facing && d <= 0.0)) {\n // compute (x,y,z) projection on the facet = (projx, projy, projz)\n d = norm.x * p0.x + norm.y * p0.y + norm.z * p0.z;\n t0 = -(norm.x * x + norm.y * y + norm.z * z - d) / (norm.x * norm.x + norm.y * norm.y + norm.z * norm.z);\n projx = x + norm.x * t0;\n projy = y + norm.y * t0;\n projz = z + norm.z * t0;\n tmpx = projx - x;\n tmpy = projy - y;\n tmpz = projz - z;\n tmpDistance = tmpx * tmpx + tmpy * tmpy + tmpz * tmpz; // compute length between (x, y, z) and its projection on the facet\n if (tmpDistance < shortest) {\n // just keep the closest facet to (x, y, z)\n shortest = tmpDistance;\n closest = fib;\n if (projected) {\n projected.x = projx;\n projected.y = projy;\n projected.z = projz;\n }\n }\n }\n }\n return closest;\n }\n /**\n * Returns the object \"parameter\" set with all the expected parameters for facetData computation by ComputeNormals()\n * @returns the parameters\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n getFacetDataParameters() {\n return this._internalAbstractMeshDataInfo._facetData.facetParameters;\n }\n /**\n * Disables the feature FacetData and frees the related memory\n * @returns the current mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\n */\n disableFacetData() {\n const facetData = this._internalAbstractMeshDataInfo._facetData;\n if (facetData.facetDataEnabled) {\n facetData.facetDataEnabled = false;\n facetData.facetPositions = new Array();\n facetData.facetNormals = new Array();\n facetData.facetPartitioning = new Array();\n facetData.facetParameters = null;\n facetData.depthSortedIndices = new Uint32Array(0);\n }\n return this;\n }\n /**\n * Updates the AbstractMesh indices array\n * @param indices defines the data source\n * @param offset defines the offset in the index buffer where to store the new data (can be null)\n * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)\n * @returns the current mesh\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n updateIndices(indices, offset, gpuMemoryOnly = false) {\n return this;\n }\n /**\n * Creates new normals data for the mesh\n * @param updatable defines if the normal vertex buffer must be flagged as updatable\n * @returns the current mesh\n */\n createNormals(updatable) {\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\n const indices = this.getIndices();\n let normals;\n if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n normals = this.getVerticesData(VertexBuffer.NormalKind);\n }\n else {\n normals = [];\n }\n VertexData.ComputeNormals(positions, indices, normals, { useRightHandedSystem: this.getScene().useRightHandedSystem });\n this.setVerticesData(VertexBuffer.NormalKind, normals, updatable);\n return this;\n }\n /**\n * Align the mesh with a normal\n * @param normal defines the normal to use\n * @param upDirection can be used to redefined the up vector to use (will use the (0, 1, 0) by default)\n * @returns the current mesh\n */\n alignWithNormal(normal, upDirection) {\n if (!upDirection) {\n upDirection = Axis.Y;\n }\n const axisX = TmpVectors.Vector3[0];\n const axisZ = TmpVectors.Vector3[1];\n Vector3.CrossToRef(upDirection, normal, axisZ);\n Vector3.CrossToRef(normal, axisZ, axisX);\n if (this.rotationQuaternion) {\n Quaternion.RotationQuaternionFromAxisToRef(axisX, normal, axisZ, this.rotationQuaternion);\n }\n else {\n Vector3.RotationFromAxisToRef(axisX, normal, axisZ, this.rotation);\n }\n return this;\n }\n /** @internal */\n _checkOcclusionQuery() {\n // Will be replaced by correct code if Occlusion queries are referenced\n return false;\n }\n /**\n * Disables the mesh edge rendering mode\n * @returns the currentAbstractMesh\n */\n disableEdgesRendering() {\n throw _WarnImport(\"EdgesRenderer\");\n }\n /**\n * Enables the edge rendering mode on the mesh.\n * This mode makes the mesh edges visible\n * @param epsilon defines the maximal distance between two angles to detect a face\n * @param checkVerticesInsteadOfIndices indicates that we should check vertex list directly instead of faces\n * @param options options to the edge renderer\n * @returns the currentAbstractMesh\n * @see https://www.babylonjs-playground.com/#19O9TU#0\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n enableEdgesRendering(epsilon, checkVerticesInsteadOfIndices, options) {\n throw _WarnImport(\"EdgesRenderer\");\n }\n /**\n * This function returns all of the particle systems in the scene that use the mesh as an emitter.\n * @returns an array of particle systems in the scene that use the mesh as an emitter\n */\n getConnectedParticleSystems() {\n return this._scene.particleSystems.filter((particleSystem) => particleSystem.emitter === this);\n }\n }\n /** No occlusion */\n AbstractMesh.OCCLUSION_TYPE_NONE = 0;\n /** Occlusion set to optimistic */\n AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC = 1;\n /** Occlusion set to strict */\n AbstractMesh.OCCLUSION_TYPE_STRICT = 2;\n /** Use an accurate occlusion algorithm */\n AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;\n /** Use a conservative occlusion algorithm */\n AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;\n /** Default culling strategy : this is an exclusion test and it's the more accurate.\n * Test order :\n * Is the bounding sphere outside the frustum ?\n * If not, are the bounding box vertices outside the frustum ?\n * It not, then the cullable object is in the frustum.\n */\n AbstractMesh.CULLINGSTRATEGY_STANDARD = 0;\n /** Culling strategy : Bounding Sphere Only.\n * This is an exclusion test. It's faster than the standard strategy because the bounding box is not tested.\n * It's also less accurate than the standard because some not visible objects can still be selected.\n * Test : is the bounding sphere outside the frustum ?\n * If not, then the cullable object is in the frustum.\n */\n AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = 1;\n /** Culling strategy : Optimistic Inclusion.\n * This in an inclusion test first, then the standard exclusion test.\n * This can be faster when a cullable object is expected to be almost always in the camera frustum.\n * This could also be a little slower than the standard test when the tested object center is not the frustum but one of its bounding box vertex is still inside.\n * Anyway, it's as accurate as the standard strategy.\n * Test :\n * Is the cullable object bounding sphere center in the frustum ?\n * If not, apply the default culling strategy.\n */\n AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = 2;\n /** Culling strategy : Optimistic Inclusion then Bounding Sphere Only.\n * This in an inclusion test first, then the bounding sphere only exclusion test.\n * This can be the fastest test when a cullable object is expected to be almost always in the camera frustum.\n * This could also be a little slower than the BoundingSphereOnly strategy when the tested object center is not in the frustum but its bounding sphere still intersects it.\n * It's less accurate than the standard strategy and as accurate as the BoundingSphereOnly strategy.\n * Test :\n * Is the cullable object bounding sphere center in the frustum ?\n * If not, apply the Bounding Sphere Only strategy. No Bounding Box is tested here.\n */\n AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = 3;\n RegisterClass(\"BABYLON.AbstractMesh\", AbstractMesh);\n\n /** @internal */\n function addClipPlaneUniforms(uniforms) {\n if (uniforms.indexOf(\"vClipPlane\") === -1) {\n uniforms.push(\"vClipPlane\");\n }\n if (uniforms.indexOf(\"vClipPlane2\") === -1) {\n uniforms.push(\"vClipPlane2\");\n }\n if (uniforms.indexOf(\"vClipPlane3\") === -1) {\n uniforms.push(\"vClipPlane3\");\n }\n if (uniforms.indexOf(\"vClipPlane4\") === -1) {\n uniforms.push(\"vClipPlane4\");\n }\n if (uniforms.indexOf(\"vClipPlane5\") === -1) {\n uniforms.push(\"vClipPlane5\");\n }\n if (uniforms.indexOf(\"vClipPlane6\") === -1) {\n uniforms.push(\"vClipPlane6\");\n }\n }\n /** @internal */\n function prepareStringDefinesForClipPlanes(primaryHolder, secondaryHolder, defines) {\n var _a, _b, _c, _d, _e, _f;\n const clipPlane = !!((_a = primaryHolder.clipPlane) !== null && _a !== void 0 ? _a : secondaryHolder.clipPlane);\n const clipPlane2 = !!((_b = primaryHolder.clipPlane2) !== null && _b !== void 0 ? _b : secondaryHolder.clipPlane2);\n const clipPlane3 = !!((_c = primaryHolder.clipPlane3) !== null && _c !== void 0 ? _c : secondaryHolder.clipPlane3);\n const clipPlane4 = !!((_d = primaryHolder.clipPlane4) !== null && _d !== void 0 ? _d : secondaryHolder.clipPlane4);\n const clipPlane5 = !!((_e = primaryHolder.clipPlane5) !== null && _e !== void 0 ? _e : secondaryHolder.clipPlane5);\n const clipPlane6 = !!((_f = primaryHolder.clipPlane6) !== null && _f !== void 0 ? _f : secondaryHolder.clipPlane6);\n if (clipPlane)\n defines.push(\"#define CLIPPLANE\");\n if (clipPlane2)\n defines.push(\"#define CLIPPLANE2\");\n if (clipPlane3)\n defines.push(\"#define CLIPPLANE3\");\n if (clipPlane4)\n defines.push(\"#define CLIPPLANE4\");\n if (clipPlane5)\n defines.push(\"#define CLIPPLANE5\");\n if (clipPlane6)\n defines.push(\"#define CLIPPLANE6\");\n }\n /** @internal */\n function prepareDefinesForClipPlanes(primaryHolder, secondaryHolder, defines) {\n var _a, _b, _c, _d, _e, _f;\n let changed = false;\n const clipPlane = !!((_a = primaryHolder.clipPlane) !== null && _a !== void 0 ? _a : secondaryHolder.clipPlane);\n const clipPlane2 = !!((_b = primaryHolder.clipPlane2) !== null && _b !== void 0 ? _b : secondaryHolder.clipPlane2);\n const clipPlane3 = !!((_c = primaryHolder.clipPlane3) !== null && _c !== void 0 ? _c : secondaryHolder.clipPlane3);\n const clipPlane4 = !!((_d = primaryHolder.clipPlane4) !== null && _d !== void 0 ? _d : secondaryHolder.clipPlane4);\n const clipPlane5 = !!((_e = primaryHolder.clipPlane5) !== null && _e !== void 0 ? _e : secondaryHolder.clipPlane5);\n const clipPlane6 = !!((_f = primaryHolder.clipPlane6) !== null && _f !== void 0 ? _f : secondaryHolder.clipPlane6);\n // Do not factorize this code, it breaks browsers optimizations.\n if (defines[\"CLIPPLANE\"] !== clipPlane) {\n defines[\"CLIPPLANE\"] = clipPlane;\n changed = true;\n }\n if (defines[\"CLIPPLANE2\"] !== clipPlane2) {\n defines[\"CLIPPLANE2\"] = clipPlane2;\n changed = true;\n }\n if (defines[\"CLIPPLANE3\"] !== clipPlane3) {\n defines[\"CLIPPLANE3\"] = clipPlane3;\n changed = true;\n }\n if (defines[\"CLIPPLANE4\"] !== clipPlane4) {\n defines[\"CLIPPLANE4\"] = clipPlane4;\n changed = true;\n }\n if (defines[\"CLIPPLANE5\"] !== clipPlane5) {\n defines[\"CLIPPLANE5\"] = clipPlane5;\n changed = true;\n }\n if (defines[\"CLIPPLANE6\"] !== clipPlane6) {\n defines[\"CLIPPLANE6\"] = clipPlane6;\n changed = true;\n }\n return changed;\n }\n /** @internal */\n function bindClipPlane(effect, primaryHolder, secondaryHolder) {\n var _a, _b, _c, _d, _e, _f;\n let clipPlane = (_a = primaryHolder.clipPlane) !== null && _a !== void 0 ? _a : secondaryHolder.clipPlane;\n setClipPlane(effect, \"vClipPlane\", clipPlane);\n clipPlane = (_b = primaryHolder.clipPlane2) !== null && _b !== void 0 ? _b : secondaryHolder.clipPlane2;\n setClipPlane(effect, \"vClipPlane2\", clipPlane);\n clipPlane = (_c = primaryHolder.clipPlane3) !== null && _c !== void 0 ? _c : secondaryHolder.clipPlane3;\n setClipPlane(effect, \"vClipPlane3\", clipPlane);\n clipPlane = (_d = primaryHolder.clipPlane4) !== null && _d !== void 0 ? _d : secondaryHolder.clipPlane4;\n setClipPlane(effect, \"vClipPlane4\", clipPlane);\n clipPlane = (_e = primaryHolder.clipPlane5) !== null && _e !== void 0 ? _e : secondaryHolder.clipPlane5;\n setClipPlane(effect, \"vClipPlane5\", clipPlane);\n clipPlane = (_f = primaryHolder.clipPlane6) !== null && _f !== void 0 ? _f : secondaryHolder.clipPlane6;\n setClipPlane(effect, \"vClipPlane6\", clipPlane);\n }\n function setClipPlane(effect, uniformName, clipPlane) {\n if (clipPlane) {\n effect.setFloat4(uniformName, clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);\n }\n }\n\n /**\n * \"Static Class\" containing the most commonly used helper while dealing with material for rendering purpose.\n *\n * It contains the basic tools to help defining defines, binding uniform for the common part of the materials.\n *\n * This works by convention in BabylonJS but is meant to be use only with shader following the in place naming rules and conventions.\n */\n class MaterialHelper {\n /**\n * Binds the scene's uniform buffer to the effect.\n * @param effect defines the effect to bind to the scene uniform buffer\n * @param sceneUbo defines the uniform buffer storing scene data\n */\n static BindSceneUniformBuffer(effect, sceneUbo) {\n sceneUbo.bindToEffect(effect, \"Scene\");\n }\n /**\n * Helps preparing the defines values about the UVs in used in the effect.\n * UVs are shared as much as we can across channels in the shaders.\n * @param texture The texture we are preparing the UVs for\n * @param defines The defines to update\n * @param key The channel key \"diffuse\", \"specular\"... used in the shader\n */\n static PrepareDefinesForMergedUV(texture, defines, key) {\n defines._needUVs = true;\n defines[key] = true;\n if (texture.optimizeUVAllocation && texture.getTextureMatrix().isIdentityAs3x2()) {\n defines[key + \"DIRECTUV\"] = texture.coordinatesIndex + 1;\n defines[\"MAINUV\" + (texture.coordinatesIndex + 1)] = true;\n }\n else {\n defines[key + \"DIRECTUV\"] = 0;\n }\n }\n /**\n * Binds a texture matrix value to its corresponding uniform\n * @param texture The texture to bind the matrix for\n * @param uniformBuffer The uniform buffer receiving the data\n * @param key The channel key \"diffuse\", \"specular\"... used in the shader\n */\n static BindTextureMatrix(texture, uniformBuffer, key) {\n const matrix = texture.getTextureMatrix();\n uniformBuffer.updateMatrix(key + \"Matrix\", matrix);\n }\n /**\n * Gets the current status of the fog (should it be enabled?)\n * @param mesh defines the mesh to evaluate for fog support\n * @param scene defines the hosting scene\n * @returns true if fog must be enabled\n */\n static GetFogState(mesh, scene) {\n return scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE;\n }\n /**\n * Helper used to prepare the list of defines associated with misc. values for shader compilation\n * @param mesh defines the current mesh\n * @param scene defines the current scene\n * @param useLogarithmicDepth defines if logarithmic depth has to be turned on\n * @param pointsCloud defines if point cloud rendering has to be turned on\n * @param fogEnabled defines if fog has to be turned on\n * @param alphaTest defines if alpha testing has to be turned on\n * @param defines defines the current list of defines\n * @param applyDecalAfterDetail Defines if the decal is applied after or before the detail\n */\n static PrepareDefinesForMisc(mesh, scene, useLogarithmicDepth, pointsCloud, fogEnabled, alphaTest, defines, applyDecalAfterDetail = false) {\n if (defines._areMiscDirty) {\n defines[\"LOGARITHMICDEPTH\"] = useLogarithmicDepth;\n defines[\"POINTSIZE\"] = pointsCloud;\n defines[\"FOG\"] = fogEnabled && this.GetFogState(mesh, scene);\n defines[\"NONUNIFORMSCALING\"] = mesh.nonUniformScaling;\n defines[\"ALPHATEST\"] = alphaTest;\n defines[\"DECAL_AFTER_DETAIL\"] = applyDecalAfterDetail;\n }\n }\n /**\n * Helper used to prepare the defines relative to the active camera\n * @param scene defines the current scene\n * @param defines specifies the list of active defines\n * @returns true if the defines have been updated, else false\n */\n static PrepareDefinesForCamera(scene, defines) {\n let changed = false;\n if (scene.activeCamera) {\n const wasOrtho = defines[\"CAMERA_ORTHOGRAPHIC\"] ? 1 : 0;\n const wasPersp = defines[\"CAMERA_PERSPECTIVE\"] ? 1 : 0;\n const isOrtho = scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA ? 1 : 0;\n const isPersp = scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA ? 1 : 0;\n if (wasOrtho ^ isOrtho || wasPersp ^ isPersp) {\n defines[\"CAMERA_ORTHOGRAPHIC\"] = isOrtho === 1;\n defines[\"CAMERA_PERSPECTIVE\"] = isPersp === 1;\n changed = true;\n }\n }\n return changed;\n }\n /**\n * Helper used to prepare the list of defines associated with frame values for shader compilation\n * @param scene defines the current scene\n * @param engine defines the current engine\n * @param material defines the material we are compiling the shader for\n * @param defines specifies the list of active defines\n * @param useInstances defines if instances have to be turned on\n * @param useClipPlane defines if clip plane have to be turned on\n * @param useThinInstances defines if thin instances have to be turned on\n */\n static PrepareDefinesForFrameBoundValues(scene, engine, material, defines, useInstances, useClipPlane = null, useThinInstances = false) {\n let changed = MaterialHelper.PrepareDefinesForCamera(scene, defines);\n if (useClipPlane !== false) {\n changed = prepareDefinesForClipPlanes(material, scene, defines);\n }\n if (defines[\"DEPTHPREPASS\"] !== !engine.getColorWrite()) {\n defines[\"DEPTHPREPASS\"] = !defines[\"DEPTHPREPASS\"];\n changed = true;\n }\n if (defines[\"INSTANCES\"] !== useInstances) {\n defines[\"INSTANCES\"] = useInstances;\n changed = true;\n }\n if (defines[\"THIN_INSTANCES\"] !== useThinInstances) {\n defines[\"THIN_INSTANCES\"] = useThinInstances;\n changed = true;\n }\n if (changed) {\n defines.markAsUnprocessed();\n }\n }\n /**\n * Prepares the defines for bones\n * @param mesh The mesh containing the geometry data we will draw\n * @param defines The defines to update\n */\n static PrepareDefinesForBones(mesh, defines) {\n if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\n defines[\"NUM_BONE_INFLUENCERS\"] = mesh.numBoneInfluencers;\n const materialSupportsBoneTexture = defines[\"BONETEXTURE\"] !== undefined;\n if (mesh.skeleton.isUsingTextureForMatrices && materialSupportsBoneTexture) {\n defines[\"BONETEXTURE\"] = true;\n }\n else {\n defines[\"BonesPerMesh\"] = mesh.skeleton.bones.length + 1;\n defines[\"BONETEXTURE\"] = materialSupportsBoneTexture ? false : undefined;\n const prePassRenderer = mesh.getScene().prePassRenderer;\n if (prePassRenderer && prePassRenderer.enabled) {\n const nonExcluded = prePassRenderer.excludedSkinnedMesh.indexOf(mesh) === -1;\n defines[\"BONES_VELOCITY_ENABLED\"] = nonExcluded;\n }\n }\n }\n else {\n defines[\"NUM_BONE_INFLUENCERS\"] = 0;\n defines[\"BonesPerMesh\"] = 0;\n if (defines[\"BONETEXTURE\"] !== undefined) {\n defines[\"BONETEXTURE\"] = false;\n }\n }\n }\n /**\n * Prepares the defines for morph targets\n * @param mesh The mesh containing the geometry data we will draw\n * @param defines The defines to update\n */\n static PrepareDefinesForMorphTargets(mesh, defines) {\n const manager = mesh.morphTargetManager;\n if (manager) {\n defines[\"MORPHTARGETS_UV\"] = manager.supportsUVs && defines[\"UV1\"];\n defines[\"MORPHTARGETS_TANGENT\"] = manager.supportsTangents && defines[\"TANGENT\"];\n defines[\"MORPHTARGETS_NORMAL\"] = manager.supportsNormals && defines[\"NORMAL\"];\n defines[\"MORPHTARGETS\"] = manager.numInfluencers > 0;\n defines[\"NUM_MORPH_INFLUENCERS\"] = manager.numInfluencers;\n defines[\"MORPHTARGETS_TEXTURE\"] = manager.isUsingTextureForTargets;\n }\n else {\n defines[\"MORPHTARGETS_UV\"] = false;\n defines[\"MORPHTARGETS_TANGENT\"] = false;\n defines[\"MORPHTARGETS_NORMAL\"] = false;\n defines[\"MORPHTARGETS\"] = false;\n defines[\"NUM_MORPH_INFLUENCERS\"] = 0;\n }\n }\n /**\n * Prepares the defines for baked vertex animation\n * @param mesh The mesh containing the geometry data we will draw\n * @param defines The defines to update\n */\n static PrepareDefinesForBakedVertexAnimation(mesh, defines) {\n const manager = mesh.bakedVertexAnimationManager;\n defines[\"BAKED_VERTEX_ANIMATION_TEXTURE\"] = manager && manager.isEnabled ? true : false;\n }\n /**\n * Prepares the defines used in the shader depending on the attributes data available in the mesh\n * @param mesh The mesh containing the geometry data we will draw\n * @param defines The defines to update\n * @param useVertexColor Precise whether vertex colors should be used or not (override mesh info)\n * @param useBones Precise whether bones should be used or not (override mesh info)\n * @param useMorphTargets Precise whether morph targets should be used or not (override mesh info)\n * @param useVertexAlpha Precise whether vertex alpha should be used or not (override mesh info)\n * @param useBakedVertexAnimation Precise whether baked vertex animation should be used or not (override mesh info)\n * @returns false if defines are considered not dirty and have not been checked\n */\n static PrepareDefinesForAttributes(mesh, defines, useVertexColor, useBones, useMorphTargets = false, useVertexAlpha = true, useBakedVertexAnimation = true) {\n if (!defines._areAttributesDirty && defines._needNormals === defines._normals && defines._needUVs === defines._uvs) {\n return false;\n }\n defines._normals = defines._needNormals;\n defines._uvs = defines._needUVs;\n defines[\"NORMAL\"] = defines._needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind);\n if (defines._needNormals && mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {\n defines[\"TANGENT\"] = true;\n }\n for (let i = 1; i <= 6; ++i) {\n defines[\"UV\" + i] = defines._needUVs ? mesh.isVerticesDataPresent(`uv${i === 1 ? \"\" : i}`) : false;\n }\n if (useVertexColor) {\n const hasVertexColors = mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind);\n defines[\"VERTEXCOLOR\"] = hasVertexColors;\n defines[\"VERTEXALPHA\"] = mesh.hasVertexAlpha && hasVertexColors && useVertexAlpha;\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.ColorInstanceKind) && (mesh.hasInstances || mesh.hasThinInstances)) {\n defines[\"INSTANCESCOLOR\"] = true;\n }\n if (useBones) {\n this.PrepareDefinesForBones(mesh, defines);\n }\n if (useMorphTargets) {\n this.PrepareDefinesForMorphTargets(mesh, defines);\n }\n if (useBakedVertexAnimation) {\n this.PrepareDefinesForBakedVertexAnimation(mesh, defines);\n }\n return true;\n }\n /**\n * Prepares the defines related to multiview\n * @param scene The scene we are intending to draw\n * @param defines The defines to update\n */\n static PrepareDefinesForMultiview(scene, defines) {\n if (scene.activeCamera) {\n const previousMultiview = defines.MULTIVIEW;\n defines.MULTIVIEW = scene.activeCamera.outputRenderTarget !== null && scene.activeCamera.outputRenderTarget.getViewCount() > 1;\n if (defines.MULTIVIEW != previousMultiview) {\n defines.markAsUnprocessed();\n }\n }\n }\n /**\n * Prepares the defines related to order independant transparency\n * @param scene The scene we are intending to draw\n * @param defines The defines to update\n * @param needAlphaBlending Determines if the material needs alpha blending\n */\n static PrepareDefinesForOIT(scene, defines, needAlphaBlending) {\n const previousDefine = defines.ORDER_INDEPENDENT_TRANSPARENCY;\n const previousDefine16Bits = defines.ORDER_INDEPENDENT_TRANSPARENCY_16BITS;\n defines.ORDER_INDEPENDENT_TRANSPARENCY = scene.useOrderIndependentTransparency && needAlphaBlending;\n defines.ORDER_INDEPENDENT_TRANSPARENCY_16BITS = !scene.getEngine().getCaps().textureFloatLinearFiltering;\n if (previousDefine !== defines.ORDER_INDEPENDENT_TRANSPARENCY || previousDefine16Bits !== defines.ORDER_INDEPENDENT_TRANSPARENCY_16BITS) {\n defines.markAsUnprocessed();\n }\n }\n /**\n * Prepares the defines related to the prepass\n * @param scene The scene we are intending to draw\n * @param defines The defines to update\n * @param canRenderToMRT Indicates if this material renders to several textures in the prepass\n */\n static PrepareDefinesForPrePass(scene, defines, canRenderToMRT) {\n const previousPrePass = defines.PREPASS;\n if (!defines._arePrePassDirty) {\n return;\n }\n const texturesList = [\n {\n type: 1,\n define: \"PREPASS_POSITION\",\n index: \"PREPASS_POSITION_INDEX\",\n },\n {\n type: 2,\n define: \"PREPASS_VELOCITY\",\n index: \"PREPASS_VELOCITY_INDEX\",\n },\n {\n type: 3,\n define: \"PREPASS_REFLECTIVITY\",\n index: \"PREPASS_REFLECTIVITY_INDEX\",\n },\n {\n type: 0,\n define: \"PREPASS_IRRADIANCE\",\n index: \"PREPASS_IRRADIANCE_INDEX\",\n },\n {\n type: 7,\n define: \"PREPASS_ALBEDO_SQRT\",\n index: \"PREPASS_ALBEDO_SQRT_INDEX\",\n },\n {\n type: 5,\n define: \"PREPASS_DEPTH\",\n index: \"PREPASS_DEPTH_INDEX\",\n },\n {\n type: 6,\n define: \"PREPASS_NORMAL\",\n index: \"PREPASS_NORMAL_INDEX\",\n },\n ];\n if (scene.prePassRenderer && scene.prePassRenderer.enabled && canRenderToMRT) {\n defines.PREPASS = true;\n defines.SCENE_MRT_COUNT = scene.prePassRenderer.mrtCount;\n for (let i = 0; i < texturesList.length; i++) {\n const index = scene.prePassRenderer.getIndex(texturesList[i].type);\n if (index !== -1) {\n defines[texturesList[i].define] = true;\n defines[texturesList[i].index] = index;\n }\n else {\n defines[texturesList[i].define] = false;\n }\n }\n }\n else {\n defines.PREPASS = false;\n for (let i = 0; i < texturesList.length; i++) {\n defines[texturesList[i].define] = false;\n }\n }\n if (defines.PREPASS != previousPrePass) {\n defines.markAsUnprocessed();\n defines.markAsImageProcessingDirty();\n }\n }\n /**\n * Prepares the defines related to the light information passed in parameter\n * @param scene The scene we are intending to draw\n * @param mesh The mesh the effect is compiling for\n * @param light The light the effect is compiling for\n * @param lightIndex The index of the light\n * @param defines The defines to update\n * @param specularSupported Specifies whether specular is supported or not (override lights data)\n * @param state Defines the current state regarding what is needed (normals, etc...)\n * @param state.needNormals\n * @param state.needRebuild\n * @param state.shadowEnabled\n * @param state.specularEnabled\n * @param state.lightmapMode\n */\n static PrepareDefinesForLight(scene, mesh, light, lightIndex, defines, specularSupported, state) {\n var _a;\n state.needNormals = true;\n if (defines[\"LIGHT\" + lightIndex] === undefined) {\n state.needRebuild = true;\n }\n defines[\"LIGHT\" + lightIndex] = true;\n defines[\"SPOTLIGHT\" + lightIndex] = false;\n defines[\"HEMILIGHT\" + lightIndex] = false;\n defines[\"POINTLIGHT\" + lightIndex] = false;\n defines[\"DIRLIGHT\" + lightIndex] = false;\n light.prepareLightSpecificDefines(defines, lightIndex);\n // FallOff.\n defines[\"LIGHT_FALLOFF_PHYSICAL\" + lightIndex] = false;\n defines[\"LIGHT_FALLOFF_GLTF\" + lightIndex] = false;\n defines[\"LIGHT_FALLOFF_STANDARD\" + lightIndex] = false;\n switch (light.falloffType) {\n case LightConstants.FALLOFF_GLTF:\n defines[\"LIGHT_FALLOFF_GLTF\" + lightIndex] = true;\n break;\n case LightConstants.FALLOFF_PHYSICAL:\n defines[\"LIGHT_FALLOFF_PHYSICAL\" + lightIndex] = true;\n break;\n case LightConstants.FALLOFF_STANDARD:\n defines[\"LIGHT_FALLOFF_STANDARD\" + lightIndex] = true;\n break;\n }\n // Specular\n if (specularSupported && !light.specular.equalsFloats(0, 0, 0)) {\n state.specularEnabled = true;\n }\n // Shadows\n defines[\"SHADOW\" + lightIndex] = false;\n defines[\"SHADOWCSM\" + lightIndex] = false;\n defines[\"SHADOWCSMDEBUG\" + lightIndex] = false;\n defines[\"SHADOWCSMNUM_CASCADES\" + lightIndex] = false;\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + lightIndex] = false;\n defines[\"SHADOWCSMNOBLEND\" + lightIndex] = false;\n defines[\"SHADOWCSM_RIGHTHANDED\" + lightIndex] = false;\n defines[\"SHADOWPCF\" + lightIndex] = false;\n defines[\"SHADOWPCSS\" + lightIndex] = false;\n defines[\"SHADOWPOISSON\" + lightIndex] = false;\n defines[\"SHADOWESM\" + lightIndex] = false;\n defines[\"SHADOWCLOSEESM\" + lightIndex] = false;\n defines[\"SHADOWCUBE\" + lightIndex] = false;\n defines[\"SHADOWLOWQUALITY\" + lightIndex] = false;\n defines[\"SHADOWMEDIUMQUALITY\" + lightIndex] = false;\n if (mesh && mesh.receiveShadows && scene.shadowsEnabled && light.shadowEnabled) {\n const shadowGenerator = (_a = light.getShadowGenerator(scene.activeCamera)) !== null && _a !== void 0 ? _a : light.getShadowGenerator();\n if (shadowGenerator) {\n const shadowMap = shadowGenerator.getShadowMap();\n if (shadowMap) {\n if (shadowMap.renderList && shadowMap.renderList.length > 0) {\n state.shadowEnabled = true;\n shadowGenerator.prepareDefines(defines, lightIndex);\n }\n }\n }\n }\n if (light.lightmapMode != LightConstants.LIGHTMAP_DEFAULT) {\n state.lightmapMode = true;\n defines[\"LIGHTMAPEXCLUDED\" + lightIndex] = true;\n defines[\"LIGHTMAPNOSPECULAR\" + lightIndex] = light.lightmapMode == LightConstants.LIGHTMAP_SHADOWSONLY;\n }\n else {\n defines[\"LIGHTMAPEXCLUDED\" + lightIndex] = false;\n defines[\"LIGHTMAPNOSPECULAR\" + lightIndex] = false;\n }\n }\n /**\n * Prepares the defines related to the light information passed in parameter\n * @param scene The scene we are intending to draw\n * @param mesh The mesh the effect is compiling for\n * @param defines The defines to update\n * @param specularSupported Specifies whether specular is supported or not (override lights data)\n * @param maxSimultaneousLights Specifies how manuy lights can be added to the effect at max\n * @param disableLighting Specifies whether the lighting is disabled (override scene and light)\n * @returns true if normals will be required for the rest of the effect\n */\n static PrepareDefinesForLights(scene, mesh, defines, specularSupported, maxSimultaneousLights = 4, disableLighting = false) {\n if (!defines._areLightsDirty) {\n return defines._needNormals;\n }\n let lightIndex = 0;\n const state = {\n needNormals: defines._needNormals,\n needRebuild: false,\n lightmapMode: false,\n shadowEnabled: false,\n specularEnabled: false,\n };\n if (scene.lightsEnabled && !disableLighting) {\n for (const light of mesh.lightSources) {\n this.PrepareDefinesForLight(scene, mesh, light, lightIndex, defines, specularSupported, state);\n lightIndex++;\n if (lightIndex === maxSimultaneousLights) {\n break;\n }\n }\n }\n defines[\"SPECULARTERM\"] = state.specularEnabled;\n defines[\"SHADOWS\"] = state.shadowEnabled;\n // Resetting all other lights if any\n for (let index = lightIndex; index < maxSimultaneousLights; index++) {\n if (defines[\"LIGHT\" + index] !== undefined) {\n defines[\"LIGHT\" + index] = false;\n defines[\"HEMILIGHT\" + index] = false;\n defines[\"POINTLIGHT\" + index] = false;\n defines[\"DIRLIGHT\" + index] = false;\n defines[\"SPOTLIGHT\" + index] = false;\n defines[\"SHADOW\" + index] = false;\n defines[\"SHADOWCSM\" + index] = false;\n defines[\"SHADOWCSMDEBUG\" + index] = false;\n defines[\"SHADOWCSMNUM_CASCADES\" + index] = false;\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + index] = false;\n defines[\"SHADOWCSMNOBLEND\" + index] = false;\n defines[\"SHADOWCSM_RIGHTHANDED\" + index] = false;\n defines[\"SHADOWPCF\" + index] = false;\n defines[\"SHADOWPCSS\" + index] = false;\n defines[\"SHADOWPOISSON\" + index] = false;\n defines[\"SHADOWESM\" + index] = false;\n defines[\"SHADOWCLOSEESM\" + index] = false;\n defines[\"SHADOWCUBE\" + index] = false;\n defines[\"SHADOWLOWQUALITY\" + index] = false;\n defines[\"SHADOWMEDIUMQUALITY\" + index] = false;\n }\n }\n const caps = scene.getEngine().getCaps();\n if (defines[\"SHADOWFLOAT\"] === undefined) {\n state.needRebuild = true;\n }\n defines[\"SHADOWFLOAT\"] =\n state.shadowEnabled && ((caps.textureFloatRender && caps.textureFloatLinearFiltering) || (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering));\n defines[\"LIGHTMAPEXCLUDED\"] = state.lightmapMode;\n if (state.needRebuild) {\n defines.rebuild();\n }\n return state.needNormals;\n }\n /**\n * Prepares the uniforms and samplers list to be used in the effect (for a specific light)\n * @param lightIndex defines the light index\n * @param uniformsList The uniform list\n * @param samplersList The sampler list\n * @param projectedLightTexture defines if projected texture must be used\n * @param uniformBuffersList defines an optional list of uniform buffers\n * @param updateOnlyBuffersList True to only update the uniformBuffersList array\n */\n static PrepareUniformsAndSamplersForLight(lightIndex, uniformsList, samplersList, projectedLightTexture, uniformBuffersList = null, updateOnlyBuffersList = false) {\n if (uniformBuffersList) {\n uniformBuffersList.push(\"Light\" + lightIndex);\n }\n if (updateOnlyBuffersList) {\n return;\n }\n uniformsList.push(\"vLightData\" + lightIndex, \"vLightDiffuse\" + lightIndex, \"vLightSpecular\" + lightIndex, \"vLightDirection\" + lightIndex, \"vLightFalloff\" + lightIndex, \"vLightGround\" + lightIndex, \"lightMatrix\" + lightIndex, \"shadowsInfo\" + lightIndex, \"depthValues\" + lightIndex);\n samplersList.push(\"shadowSampler\" + lightIndex);\n samplersList.push(\"depthSampler\" + lightIndex);\n uniformsList.push(\"viewFrustumZ\" + lightIndex, \"cascadeBlendFactor\" + lightIndex, \"lightSizeUVCorrection\" + lightIndex, \"depthCorrection\" + lightIndex, \"penumbraDarkness\" + lightIndex, \"frustumLengths\" + lightIndex);\n if (projectedLightTexture) {\n samplersList.push(\"projectionLightSampler\" + lightIndex);\n uniformsList.push(\"textureProjectionMatrix\" + lightIndex);\n }\n }\n /**\n * Prepares the uniforms and samplers list to be used in the effect\n * @param uniformsListOrOptions The uniform names to prepare or an EffectCreationOptions containing the list and extra information\n * @param samplersList The sampler list\n * @param defines The defines helping in the list generation\n * @param maxSimultaneousLights The maximum number of simultaneous light allowed in the effect\n */\n static PrepareUniformsAndSamplersList(uniformsListOrOptions, samplersList, defines, maxSimultaneousLights = 4) {\n let uniformsList;\n let uniformBuffersList = null;\n if (uniformsListOrOptions.uniformsNames) {\n const options = uniformsListOrOptions;\n uniformsList = options.uniformsNames;\n uniformBuffersList = options.uniformBuffersNames;\n samplersList = options.samplers;\n defines = options.defines;\n maxSimultaneousLights = options.maxSimultaneousLights || 0;\n }\n else {\n uniformsList = uniformsListOrOptions;\n if (!samplersList) {\n samplersList = [];\n }\n }\n for (let lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {\n if (!defines[\"LIGHT\" + lightIndex]) {\n break;\n }\n this.PrepareUniformsAndSamplersForLight(lightIndex, uniformsList, samplersList, defines[\"PROJECTEDLIGHTTEXTURE\" + lightIndex], uniformBuffersList);\n }\n if (defines[\"NUM_MORPH_INFLUENCERS\"]) {\n uniformsList.push(\"morphTargetInfluences\");\n }\n if (defines[\"BAKED_VERTEX_ANIMATION_TEXTURE\"]) {\n uniformsList.push(\"bakedVertexAnimationSettings\");\n uniformsList.push(\"bakedVertexAnimationTextureSizeInverted\");\n uniformsList.push(\"bakedVertexAnimationTime\");\n samplersList.push(\"bakedVertexAnimationTexture\");\n }\n }\n /**\n * This helps decreasing rank by rank the shadow quality (0 being the highest rank and quality)\n * @param defines The defines to update while falling back\n * @param fallbacks The authorized effect fallbacks\n * @param maxSimultaneousLights The maximum number of lights allowed\n * @param rank the current rank of the Effect\n * @returns The newly affected rank\n */\n static HandleFallbacksForShadows(defines, fallbacks, maxSimultaneousLights = 4, rank = 0) {\n let lightFallbackRank = 0;\n for (let lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {\n if (!defines[\"LIGHT\" + lightIndex]) {\n break;\n }\n if (lightIndex > 0) {\n lightFallbackRank = rank + lightIndex;\n fallbacks.addFallback(lightFallbackRank, \"LIGHT\" + lightIndex);\n }\n if (!defines[\"SHADOWS\"]) {\n if (defines[\"SHADOW\" + lightIndex]) {\n fallbacks.addFallback(rank, \"SHADOW\" + lightIndex);\n }\n if (defines[\"SHADOWPCF\" + lightIndex]) {\n fallbacks.addFallback(rank, \"SHADOWPCF\" + lightIndex);\n }\n if (defines[\"SHADOWPCSS\" + lightIndex]) {\n fallbacks.addFallback(rank, \"SHADOWPCSS\" + lightIndex);\n }\n if (defines[\"SHADOWPOISSON\" + lightIndex]) {\n fallbacks.addFallback(rank, \"SHADOWPOISSON\" + lightIndex);\n }\n if (defines[\"SHADOWESM\" + lightIndex]) {\n fallbacks.addFallback(rank, \"SHADOWESM\" + lightIndex);\n }\n if (defines[\"SHADOWCLOSEESM\" + lightIndex]) {\n fallbacks.addFallback(rank, \"SHADOWCLOSEESM\" + lightIndex);\n }\n }\n }\n return lightFallbackRank++;\n }\n /**\n * Prepares the list of attributes required for morph targets according to the effect defines.\n * @param attribs The current list of supported attribs\n * @param mesh The mesh to prepare the morph targets attributes for\n * @param influencers The number of influencers\n */\n static PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, influencers) {\n this._TmpMorphInfluencers.NUM_MORPH_INFLUENCERS = influencers;\n this.PrepareAttributesForMorphTargets(attribs, mesh, this._TmpMorphInfluencers);\n }\n /**\n * Prepares the list of attributes required for morph targets according to the effect defines.\n * @param attribs The current list of supported attribs\n * @param mesh The mesh to prepare the morph targets attributes for\n * @param defines The current Defines of the effect\n */\n static PrepareAttributesForMorphTargets(attribs, mesh, defines) {\n const influencers = defines[\"NUM_MORPH_INFLUENCERS\"];\n if (influencers > 0 && EngineStore.LastCreatedEngine) {\n const maxAttributesCount = EngineStore.LastCreatedEngine.getCaps().maxVertexAttribs;\n const manager = mesh.morphTargetManager;\n if (manager === null || manager === void 0 ? void 0 : manager.isUsingTextureForTargets) {\n return;\n }\n const normal = manager && manager.supportsNormals && defines[\"NORMAL\"];\n const tangent = manager && manager.supportsTangents && defines[\"TANGENT\"];\n const uv = manager && manager.supportsUVs && defines[\"UV1\"];\n for (let index = 0; index < influencers; index++) {\n attribs.push(VertexBuffer.PositionKind + index);\n if (normal) {\n attribs.push(VertexBuffer.NormalKind + index);\n }\n if (tangent) {\n attribs.push(VertexBuffer.TangentKind + index);\n }\n if (uv) {\n attribs.push(VertexBuffer.UVKind + \"_\" + index);\n }\n if (attribs.length > maxAttributesCount) {\n Logger.Error(\"Cannot add more vertex attributes for mesh \" + mesh.name);\n }\n }\n }\n }\n /**\n * Prepares the list of attributes required for baked vertex animations according to the effect defines.\n * @param attribs The current list of supported attribs\n * @param mesh The mesh to prepare the morph targets attributes for\n * @param defines The current Defines of the effect\n */\n static PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines) {\n const enabled = defines[\"BAKED_VERTEX_ANIMATION_TEXTURE\"] && defines[\"INSTANCES\"];\n if (enabled) {\n attribs.push(\"bakedVertexAnimationSettingsInstanced\");\n }\n }\n /**\n * Prepares the list of attributes required for bones according to the effect defines.\n * @param attribs The current list of supported attribs\n * @param mesh The mesh to prepare the bones attributes for\n * @param defines The current Defines of the effect\n * @param fallbacks The current effect fallback strategy\n */\n static PrepareAttributesForBones(attribs, mesh, defines, fallbacks) {\n if (defines[\"NUM_BONE_INFLUENCERS\"] > 0) {\n fallbacks.addCPUSkinningFallback(0, mesh);\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (defines[\"NUM_BONE_INFLUENCERS\"] > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n }\n }\n /**\n * Check and prepare the list of attributes required for instances according to the effect defines.\n * @param attribs The current list of supported attribs\n * @param defines The current MaterialDefines of the effect\n */\n static PrepareAttributesForInstances(attribs, defines) {\n if (defines[\"INSTANCES\"] || defines[\"THIN_INSTANCES\"]) {\n this.PushAttributesForInstances(attribs, !!defines[\"PREPASS_VELOCITY\"]);\n }\n if (defines.INSTANCESCOLOR) {\n attribs.push(VertexBuffer.ColorInstanceKind);\n }\n }\n /**\n * Add the list of attributes required for instances to the attribs array.\n * @param attribs The current list of supported attribs\n * @param needsPreviousMatrices If the shader needs previous matrices\n */\n static PushAttributesForInstances(attribs, needsPreviousMatrices = false) {\n attribs.push(\"world0\");\n attribs.push(\"world1\");\n attribs.push(\"world2\");\n attribs.push(\"world3\");\n if (needsPreviousMatrices) {\n attribs.push(\"previousWorld0\");\n attribs.push(\"previousWorld1\");\n attribs.push(\"previousWorld2\");\n attribs.push(\"previousWorld3\");\n }\n }\n /**\n * Binds the light information to the effect.\n * @param light The light containing the generator\n * @param effect The effect we are binding the data to\n * @param lightIndex The light index in the effect used to render\n */\n static BindLightProperties(light, effect, lightIndex) {\n light.transferToEffect(effect, lightIndex + \"\");\n }\n /**\n * Binds the lights information from the scene to the effect for the given mesh.\n * @param light Light to bind\n * @param lightIndex Light index\n * @param scene The scene where the light belongs to\n * @param effect The effect we are binding the data to\n * @param useSpecular Defines if specular is supported\n * @param receiveShadows Defines if the effect (mesh) we bind the light for receives shadows\n */\n static BindLight(light, lightIndex, scene, effect, useSpecular, receiveShadows = true) {\n light._bindLight(lightIndex, scene, effect, useSpecular, receiveShadows);\n }\n /**\n * Binds the lights information from the scene to the effect for the given mesh.\n * @param scene The scene the lights belongs to\n * @param mesh The mesh we are binding the information to render\n * @param effect The effect we are binding the data to\n * @param defines The generated defines for the effect\n * @param maxSimultaneousLights The maximum number of light that can be bound to the effect\n */\n static BindLights(scene, mesh, effect, defines, maxSimultaneousLights = 4) {\n const len = Math.min(mesh.lightSources.length, maxSimultaneousLights);\n for (let i = 0; i < len; i++) {\n const light = mesh.lightSources[i];\n this.BindLight(light, i, scene, effect, typeof defines === \"boolean\" ? defines : defines[\"SPECULARTERM\"], mesh.receiveShadows);\n }\n }\n /**\n * Binds the fog information from the scene to the effect for the given mesh.\n * @param scene The scene the lights belongs to\n * @param mesh The mesh we are binding the information to render\n * @param effect The effect we are binding the data to\n * @param linearSpace Defines if the fog effect is applied in linear space\n */\n static BindFogParameters(scene, mesh, effect, linearSpace = false) {\n if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {\n effect.setFloat4(\"vFogInfos\", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);\n // Convert fog color to linear space if used in a linear space computed shader.\n if (linearSpace) {\n scene.fogColor.toLinearSpaceToRef(this._TempFogColor, scene.getEngine().useExactSrgbConversions);\n effect.setColor3(\"vFogColor\", this._TempFogColor);\n }\n else {\n effect.setColor3(\"vFogColor\", scene.fogColor);\n }\n }\n }\n /**\n * Binds the bones information from the mesh to the effect.\n * @param mesh The mesh we are binding the information to render\n * @param effect The effect we are binding the data to\n * @param prePassConfiguration Configuration for the prepass, in case prepass is activated\n */\n static BindBonesParameters(mesh, effect, prePassConfiguration) {\n if (!effect || !mesh) {\n return;\n }\n if (mesh.computeBonesUsingShaders && effect._bonesComputationForcedToCPU) {\n mesh.computeBonesUsingShaders = false;\n }\n if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\n const skeleton = mesh.skeleton;\n if (skeleton.isUsingTextureForMatrices && effect.getUniformIndex(\"boneTextureWidth\") > -1) {\n const boneTexture = skeleton.getTransformMatrixTexture(mesh);\n effect.setTexture(\"boneSampler\", boneTexture);\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\n }\n else {\n const matrices = skeleton.getTransformMatrices(mesh);\n if (matrices) {\n effect.setMatrices(\"mBones\", matrices);\n if (prePassConfiguration && mesh.getScene().prePassRenderer && mesh.getScene().prePassRenderer.getIndex(2)) {\n if (!prePassConfiguration.previousBones[mesh.uniqueId]) {\n prePassConfiguration.previousBones[mesh.uniqueId] = matrices.slice();\n }\n effect.setMatrices(\"mPreviousBones\", prePassConfiguration.previousBones[mesh.uniqueId]);\n MaterialHelper._CopyBonesTransformationMatrices(matrices, prePassConfiguration.previousBones[mesh.uniqueId]);\n }\n }\n }\n }\n }\n // Copies the bones transformation matrices into the target array and returns the target's reference\n static _CopyBonesTransformationMatrices(source, target) {\n target.set(source);\n return target;\n }\n /**\n * Binds the morph targets information from the mesh to the effect.\n * @param abstractMesh The mesh we are binding the information to render\n * @param effect The effect we are binding the data to\n */\n static BindMorphTargetParameters(abstractMesh, effect) {\n const manager = abstractMesh.morphTargetManager;\n if (!abstractMesh || !manager) {\n return;\n }\n effect.setFloatArray(\"morphTargetInfluences\", manager.influences);\n }\n /**\n * Binds the logarithmic depth information from the scene to the effect for the given defines.\n * @param defines The generated defines used in the effect\n * @param effect The effect we are binding the data to\n * @param scene The scene we are willing to render with logarithmic scale for\n */\n static BindLogDepth(defines, effect, scene) {\n if (!defines || defines[\"LOGARITHMICDEPTH\"] || (defines.indexOf && defines.indexOf(\"LOGARITHMICDEPTH\") >= 0)) {\n const camera = scene.activeCamera;\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n Logger.Error(\"Logarithmic depth is not compatible with orthographic cameras!\", 20);\n }\n effect.setFloat(\"logarithmicDepthConstant\", 2.0 / (Math.log(camera.maxZ + 1.0) / Math.LN2));\n }\n }\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n MaterialHelper._TmpMorphInfluencers = { NUM_MORPH_INFLUENCERS: 0 };\n MaterialHelper._TempFogColor = Color3.Black();\n\n /**\n * Class that holds the different stencil states of a material\n * Usage example: https://playground.babylonjs.com/#CW5PRI#10\n */\n class MaterialStencilState {\n /**\n * Creates a material stencil state instance\n */\n constructor() {\n this.reset();\n }\n /**\n * Resets all the stencil states to default values\n */\n reset() {\n this.enabled = false;\n this.mask = 0xff;\n this.func = 519;\n this.funcRef = 1;\n this.funcMask = 0xff;\n this.opStencilFail = 7680;\n this.opDepthFail = 7680;\n this.opStencilDepthPass = 7681;\n }\n /**\n * Gets or sets the stencil function\n */\n get func() {\n return this._func;\n }\n set func(value) {\n this._func = value;\n }\n /**\n * Gets or sets the stencil function reference\n */\n get funcRef() {\n return this._funcRef;\n }\n set funcRef(value) {\n this._funcRef = value;\n }\n /**\n * Gets or sets the stencil function mask\n */\n get funcMask() {\n return this._funcMask;\n }\n set funcMask(value) {\n this._funcMask = value;\n }\n /**\n * Gets or sets the operation when the stencil test fails\n */\n get opStencilFail() {\n return this._opStencilFail;\n }\n set opStencilFail(value) {\n this._opStencilFail = value;\n }\n /**\n * Gets or sets the operation when the depth test fails\n */\n get opDepthFail() {\n return this._opDepthFail;\n }\n set opDepthFail(value) {\n this._opDepthFail = value;\n }\n /**\n * Gets or sets the operation when the stencil+depth test succeeds\n */\n get opStencilDepthPass() {\n return this._opStencilDepthPass;\n }\n set opStencilDepthPass(value) {\n this._opStencilDepthPass = value;\n }\n /**\n * Gets or sets the stencil mask\n */\n get mask() {\n return this._mask;\n }\n set mask(value) {\n this._mask = value;\n }\n /**\n * Enables or disables the stencil test\n */\n get enabled() {\n return this._enabled;\n }\n set enabled(value) {\n this._enabled = value;\n }\n /**\n * Get the current class name, useful for serialization or dynamic coding.\n * @returns \"MaterialStencilState\"\n */\n getClassName() {\n return \"MaterialStencilState\";\n }\n /**\n * Makes a duplicate of the current configuration into another one.\n * @param stencilState defines stencil state where to copy the info\n */\n copyTo(stencilState) {\n SerializationHelper.Clone(() => stencilState, this);\n }\n /**\n * Serializes this stencil configuration.\n * @returns - An object with the serialized config.\n */\n serialize() {\n return SerializationHelper.Serialize(this);\n }\n /**\n * Parses a stencil state configuration from a serialized object.\n * @param source - Serialized object.\n * @param scene Defines the scene we are parsing for\n * @param rootUrl Defines the rootUrl to load from\n */\n parse(source, scene, rootUrl) {\n SerializationHelper.Parse(() => this, source, scene, rootUrl);\n }\n }\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"func\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"funcRef\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"funcMask\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"opStencilFail\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"opDepthFail\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"opStencilDepthPass\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"mask\", null);\n __decorate$1([\n serialize()\n ], MaterialStencilState.prototype, \"enabled\", null);\n\n /**\n * @internal\n */\n var MaterialPluginEvent;\n (function (MaterialPluginEvent) {\n MaterialPluginEvent[MaterialPluginEvent[\"Created\"] = 1] = \"Created\";\n MaterialPluginEvent[MaterialPluginEvent[\"Disposed\"] = 2] = \"Disposed\";\n MaterialPluginEvent[MaterialPluginEvent[\"GetDefineNames\"] = 4] = \"GetDefineNames\";\n MaterialPluginEvent[MaterialPluginEvent[\"PrepareUniformBuffer\"] = 8] = \"PrepareUniformBuffer\";\n MaterialPluginEvent[MaterialPluginEvent[\"IsReadyForSubMesh\"] = 16] = \"IsReadyForSubMesh\";\n MaterialPluginEvent[MaterialPluginEvent[\"PrepareDefines\"] = 32] = \"PrepareDefines\";\n MaterialPluginEvent[MaterialPluginEvent[\"BindForSubMesh\"] = 64] = \"BindForSubMesh\";\n MaterialPluginEvent[MaterialPluginEvent[\"PrepareEffect\"] = 128] = \"PrepareEffect\";\n MaterialPluginEvent[MaterialPluginEvent[\"GetAnimatables\"] = 256] = \"GetAnimatables\";\n MaterialPluginEvent[MaterialPluginEvent[\"GetActiveTextures\"] = 512] = \"GetActiveTextures\";\n MaterialPluginEvent[MaterialPluginEvent[\"HasTexture\"] = 1024] = \"HasTexture\";\n MaterialPluginEvent[MaterialPluginEvent[\"FillRenderTargetTextures\"] = 2048] = \"FillRenderTargetTextures\";\n MaterialPluginEvent[MaterialPluginEvent[\"HasRenderTargetTextures\"] = 4096] = \"HasRenderTargetTextures\";\n MaterialPluginEvent[MaterialPluginEvent[\"HardBindForSubMesh\"] = 8192] = \"HardBindForSubMesh\";\n })(MaterialPluginEvent || (MaterialPluginEvent = {}));\n\n /**\n * Base class for the main features of a material in Babylon.js\n */\n class Material {\n /**\n * If the material can be rendered to several textures with MRT extension\n */\n get canRenderToMRT() {\n // By default, shaders are not compatible with MRTs\n // Base classes should override that if their shader supports MRT\n return false;\n }\n /**\n * Sets the alpha value of the material\n */\n set alpha(value) {\n if (this._alpha === value) {\n return;\n }\n const oldValue = this._alpha;\n this._alpha = value;\n // Only call dirty when there is a state change (no alpha / alpha)\n if (oldValue === 1 || value === 1) {\n this.markAsDirty(Material.MiscDirtyFlag + Material.PrePassDirtyFlag);\n }\n }\n /**\n * Gets the alpha value of the material\n */\n get alpha() {\n return this._alpha;\n }\n /**\n * Sets the culling state (true to enable culling, false to disable)\n */\n set backFaceCulling(value) {\n if (this._backFaceCulling === value) {\n return;\n }\n this._backFaceCulling = value;\n this.markAsDirty(Material.TextureDirtyFlag);\n }\n /**\n * Gets the culling state\n */\n get backFaceCulling() {\n return this._backFaceCulling;\n }\n /**\n * Sets the type of faces that should be culled (true for back faces, false for front faces)\n */\n set cullBackFaces(value) {\n if (this._cullBackFaces === value) {\n return;\n }\n this._cullBackFaces = value;\n this.markAsDirty(Material.TextureDirtyFlag);\n }\n /**\n * Gets the type of faces that should be culled\n */\n get cullBackFaces() {\n return this._cullBackFaces;\n }\n /**\n * Block the dirty-mechanism for this specific material\n * When set to false after being true the material will be marked as dirty.\n */\n get blockDirtyMechanism() {\n return this._blockDirtyMechanism;\n }\n set blockDirtyMechanism(value) {\n if (this._blockDirtyMechanism === value) {\n return;\n }\n this._blockDirtyMechanism = value;\n if (!value) {\n this.markDirty();\n }\n }\n /**\n * This allows you to modify the material without marking it as dirty after every change.\n * This function should be used if you need to make more than one dirty-enabling change to the material - adding a texture, setting a new fill mode and so on.\n * The callback will pass the material as an argument, so you can make your changes to it.\n * @param callback the callback to be executed that will update the material\n */\n atomicMaterialsUpdate(callback) {\n this.blockDirtyMechanism = true;\n try {\n callback(this);\n }\n finally {\n this.blockDirtyMechanism = false;\n }\n }\n /**\n * Gets a boolean indicating that current material needs to register RTT\n */\n get hasRenderTargetTextures() {\n this._eventInfo.hasRenderTargetTextures = false;\n this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);\n return this._eventInfo.hasRenderTargetTextures;\n }\n /**\n * Called during a dispose event\n */\n set onDispose(callback) {\n if (this._onDisposeObserver) {\n this.onDisposeObservable.remove(this._onDisposeObserver);\n }\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\n }\n /**\n * An event triggered when the material is bound\n */\n get onBindObservable() {\n if (!this._onBindObservable) {\n this._onBindObservable = new Observable$1();\n }\n return this._onBindObservable;\n }\n /**\n * Called during a bind event\n */\n set onBind(callback) {\n if (this._onBindObserver) {\n this.onBindObservable.remove(this._onBindObserver);\n }\n this._onBindObserver = this.onBindObservable.add(callback);\n }\n /**\n * An event triggered when the material is unbound\n */\n get onUnBindObservable() {\n if (!this._onUnBindObservable) {\n this._onUnBindObservable = new Observable$1();\n }\n return this._onUnBindObservable;\n }\n /**\n * An event triggered when the effect is (re)created\n */\n get onEffectCreatedObservable() {\n if (!this._onEffectCreatedObservable) {\n this._onEffectCreatedObservable = new Observable$1();\n }\n return this._onEffectCreatedObservable;\n }\n /**\n * Sets the value of the alpha mode.\n *\n * | Value | Type | Description |\n * | --- | --- | --- |\n * | 0 | ALPHA_DISABLE | |\n * | 1 | ALPHA_ADD | |\n * | 2 | ALPHA_COMBINE | |\n * | 3 | ALPHA_SUBTRACT | |\n * | 4 | ALPHA_MULTIPLY | |\n * | 5 | ALPHA_MAXIMIZED | |\n * | 6 | ALPHA_ONEONE | |\n * | 7 | ALPHA_PREMULTIPLIED | |\n * | 8 | ALPHA_PREMULTIPLIED_PORTERDUFF | |\n * | 9 | ALPHA_INTERPOLATE | |\n * | 10 | ALPHA_SCREENMODE | |\n *\n */\n set alphaMode(value) {\n if (this._alphaMode === value) {\n return;\n }\n this._alphaMode = value;\n this.markAsDirty(Material.TextureDirtyFlag);\n }\n /**\n * Gets the value of the alpha mode\n */\n get alphaMode() {\n return this._alphaMode;\n }\n /**\n * Sets the need depth pre-pass value\n */\n set needDepthPrePass(value) {\n if (this._needDepthPrePass === value) {\n return;\n }\n this._needDepthPrePass = value;\n if (this._needDepthPrePass) {\n this.checkReadyOnEveryCall = true;\n }\n }\n /**\n * Gets the depth pre-pass value\n */\n get needDepthPrePass() {\n return this._needDepthPrePass;\n }\n /**\n * Can this material render to prepass\n */\n get isPrePassCapable() {\n return false;\n }\n /**\n * Sets the state for enabling fog\n */\n set fogEnabled(value) {\n if (this._fogEnabled === value) {\n return;\n }\n this._fogEnabled = value;\n this.markAsDirty(Material.MiscDirtyFlag);\n }\n /**\n * Gets the value of the fog enabled state\n */\n get fogEnabled() {\n return this._fogEnabled;\n }\n get wireframe() {\n switch (this._fillMode) {\n case Material.WireFrameFillMode:\n case Material.LineListDrawMode:\n case Material.LineLoopDrawMode:\n case Material.LineStripDrawMode:\n return true;\n }\n return this._scene.forceWireframe;\n }\n /**\n * Sets the state of wireframe mode\n */\n set wireframe(value) {\n this.fillMode = value ? Material.WireFrameFillMode : Material.TriangleFillMode;\n }\n /**\n * Gets the value specifying if point clouds are enabled\n */\n get pointsCloud() {\n switch (this._fillMode) {\n case Material.PointFillMode:\n case Material.PointListDrawMode:\n return true;\n }\n return this._scene.forcePointsCloud;\n }\n /**\n * Sets the state of point cloud mode\n */\n set pointsCloud(value) {\n this.fillMode = value ? Material.PointFillMode : Material.TriangleFillMode;\n }\n /**\n * Gets the material fill mode\n */\n get fillMode() {\n return this._fillMode;\n }\n /**\n * Sets the material fill mode\n */\n set fillMode(value) {\n if (this._fillMode === value) {\n return;\n }\n this._fillMode = value;\n this.markAsDirty(Material.MiscDirtyFlag);\n }\n /** @internal */\n _getDrawWrapper() {\n return this._drawWrapper;\n }\n /**\n * @internal\n */\n _setDrawWrapper(drawWrapper) {\n this._drawWrapper = drawWrapper;\n }\n /**\n * Creates a material instance\n * @param name defines the name of the material\n * @param scene defines the scene to reference\n * @param doNotAdd specifies if the material should be added to the scene\n */\n constructor(name, scene, doNotAdd) {\n /**\n * Custom shadow depth material to use for shadow rendering instead of the in-built one\n */\n this.shadowDepthWrapper = null;\n /**\n * Gets or sets a boolean indicating that the material is allowed (if supported) to do shader hot swapping.\n * This means that the material can keep using a previous shader while a new one is being compiled.\n * This is mostly used when shader parallel compilation is supported (true by default)\n */\n this.allowShaderHotSwapping = true;\n /**\n * Gets or sets user defined metadata\n */\n this.metadata = null;\n /**\n * For internal use only. Please do not use.\n */\n this.reservedDataStore = null;\n /**\n * Specifies if the ready state should be checked on each call\n */\n this.checkReadyOnEveryCall = false;\n /**\n * Specifies if the ready state should be checked once\n */\n this.checkReadyOnlyOnce = false;\n /**\n * The state of the material\n */\n this.state = \"\";\n /**\n * The alpha value of the material\n */\n this._alpha = 1.0;\n /**\n * Specifies if back face culling is enabled\n */\n this._backFaceCulling = true;\n /**\n * Specifies if back or front faces should be culled (when culling is enabled)\n */\n this._cullBackFaces = true;\n this._blockDirtyMechanism = false;\n /**\n * Callback triggered when the material is compiled\n */\n this.onCompiled = null;\n /**\n * Callback triggered when an error occurs\n */\n this.onError = null;\n /**\n * Callback triggered to get the render target textures\n */\n this.getRenderTargetTextures = null;\n /**\n * Specifies if the material should be serialized\n */\n this.doNotSerialize = false;\n /**\n * @internal\n */\n this._storeEffectOnSubMeshes = false;\n /**\n * Stores the animations for the material\n */\n this.animations = null;\n /**\n * An event triggered when the material is disposed\n */\n this.onDisposeObservable = new Observable$1();\n /**\n * An observer which watches for dispose events\n */\n this._onDisposeObserver = null;\n this._onUnBindObservable = null;\n /**\n * An observer which watches for bind events\n */\n this._onBindObserver = null;\n /**\n * Stores the value of the alpha mode\n */\n this._alphaMode = 2;\n /**\n * Stores the state of the need depth pre-pass value\n */\n this._needDepthPrePass = false;\n /**\n * Specifies if depth writing should be disabled\n */\n this.disableDepthWrite = false;\n /**\n * Specifies if color writing should be disabled\n */\n this.disableColorWrite = false;\n /**\n * Specifies if depth writing should be forced\n */\n this.forceDepthWrite = false;\n /**\n * Specifies the depth function that should be used. 0 means the default engine function\n */\n this.depthFunction = 0;\n /**\n * Specifies if there should be a separate pass for culling\n */\n this.separateCullingPass = false;\n /**\n * Stores the state specifying if fog should be enabled\n */\n this._fogEnabled = true;\n /**\n * Stores the size of points\n */\n this.pointSize = 1.0;\n /**\n * Stores the z offset Factor value\n */\n this.zOffset = 0;\n /**\n * Stores the z offset Units value\n */\n this.zOffsetUnits = 0;\n /**\n * Gives access to the stencil properties of the material\n */\n this.stencil = new MaterialStencilState();\n /**\n * Specifies if uniform buffers should be used\n */\n this._useUBO = false;\n /**\n * Stores the fill mode state\n */\n this._fillMode = Material.TriangleFillMode;\n /**\n * Specifies if the depth write state should be cached\n */\n this._cachedDepthWriteState = false;\n /**\n * Specifies if the color write state should be cached\n */\n this._cachedColorWriteState = false;\n /**\n * Specifies if the depth function state should be cached\n */\n this._cachedDepthFunctionState = 0;\n /** @internal */\n this._indexInSceneMaterialArray = -1;\n /** @internal */\n this.meshMap = null;\n /** @internal */\n this._parentContainer = null;\n /** @internal */\n this._uniformBufferLayoutBuilt = false;\n this._eventInfo = {}; // will be initialized before each event notification\n /** @internal */\n this._callbackPluginEventGeneric = () => void 0;\n /** @internal */\n this._callbackPluginEventIsReadyForSubMesh = () => void 0;\n /** @internal */\n this._callbackPluginEventPrepareDefines = () => void 0;\n /** @internal */\n this._callbackPluginEventPrepareDefinesBeforeAttributes = () => void 0;\n /** @internal */\n this._callbackPluginEventHardBindForSubMesh = () => void 0;\n /** @internal */\n this._callbackPluginEventBindForSubMesh = () => void 0;\n /** @internal */\n this._callbackPluginEventHasRenderTargetTextures = () => void 0;\n /** @internal */\n this._callbackPluginEventFillRenderTargetTextures = () => void 0;\n /**\n * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.\n */\n this._forceAlphaTest = false;\n /**\n * The transparency mode of the material.\n */\n this._transparencyMode = null;\n this.name = name;\n const setScene = scene || EngineStore.LastCreatedScene;\n if (!setScene) {\n return;\n }\n this._scene = setScene;\n this._dirtyCallbacks = {};\n this._dirtyCallbacks[1] = this._markAllSubMeshesAsTexturesDirty.bind(this);\n this._dirtyCallbacks[2] = this._markAllSubMeshesAsLightsDirty.bind(this);\n this._dirtyCallbacks[4] = this._markAllSubMeshesAsFresnelDirty.bind(this);\n this._dirtyCallbacks[8] = this._markAllSubMeshesAsAttributesDirty.bind(this);\n this._dirtyCallbacks[16] = this._markAllSubMeshesAsMiscDirty.bind(this);\n this._dirtyCallbacks[32] = this._markAllSubMeshesAsPrePassDirty.bind(this);\n this._dirtyCallbacks[63] = this._markAllSubMeshesAsAllDirty.bind(this);\n this.id = name || Tools.RandomId();\n this.uniqueId = this._scene.getUniqueId();\n this._materialContext = this._scene.getEngine().createMaterialContext();\n this._drawWrapper = new DrawWrapper(this._scene.getEngine(), false);\n this._drawWrapper.materialContext = this._materialContext;\n if (this._scene.useRightHandedSystem) {\n this.sideOrientation = Material.ClockWiseSideOrientation;\n }\n else {\n this.sideOrientation = Material.CounterClockWiseSideOrientation;\n }\n this._uniformBuffer = new UniformBuffer(this._scene.getEngine(), undefined, undefined, name);\n this._useUBO = this.getScene().getEngine().supportsUniformBuffers;\n if (!doNotAdd) {\n this._scene.addMaterial(this);\n }\n if (this._scene.useMaterialMeshMap) {\n this.meshMap = {};\n }\n Material.OnEventObservable.notifyObservers(this, MaterialPluginEvent.Created);\n }\n /**\n * Returns a string representation of the current material\n * @param fullDetails defines a boolean indicating which levels of logging is desired\n * @returns a string with material information\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n toString(fullDetails) {\n const ret = \"Name: \" + this.name;\n return ret;\n }\n /**\n * Gets the class name of the material\n * @returns a string with the class name of the material\n */\n getClassName() {\n return \"Material\";\n }\n /** @internal */\n get _isMaterial() {\n return true;\n }\n /**\n * Specifies if updates for the material been locked\n */\n get isFrozen() {\n return this.checkReadyOnlyOnce;\n }\n /**\n * Locks updates for the material\n */\n freeze() {\n this.markDirty();\n this.checkReadyOnlyOnce = true;\n }\n /**\n * Unlocks updates for the material\n */\n unfreeze() {\n this.markDirty();\n this.checkReadyOnlyOnce = false;\n }\n /**\n * Specifies if the material is ready to be used\n * @param mesh defines the mesh to check\n * @param useInstances specifies if instances should be used\n * @returns a boolean indicating if the material is ready to be used\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isReady(mesh, useInstances) {\n return true;\n }\n /**\n * Specifies that the submesh is ready to be used\n * @param mesh defines the mesh to check\n * @param subMesh defines which submesh to check\n * @param useInstances specifies that instances should be used\n * @returns a boolean indicating that the submesh is ready or not\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isReadyForSubMesh(mesh, subMesh, useInstances) {\n const defines = subMesh.materialDefines;\n if (!defines) {\n return false;\n }\n this._eventInfo.isReadyForSubMesh = true;\n this._eventInfo.defines = defines;\n this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);\n return this._eventInfo.isReadyForSubMesh;\n }\n /**\n * Returns the material effect\n * @returns the effect associated with the material\n */\n getEffect() {\n return this._drawWrapper.effect;\n }\n /**\n * Returns the current scene\n * @returns a Scene\n */\n getScene() {\n return this._scene;\n }\n /**\n * Gets the current transparency mode.\n */\n get transparencyMode() {\n return this._transparencyMode;\n }\n /**\n * Sets the transparency mode of the material.\n *\n * | Value | Type | Description |\n * | ----- | ----------------------------------- | ----------- |\n * | 0 | OPAQUE | |\n * | 1 | ALPHATEST | |\n * | 2 | ALPHABLEND | |\n * | 3 | ALPHATESTANDBLEND | |\n *\n */\n set transparencyMode(value) {\n if (this._transparencyMode === value) {\n return;\n }\n this._transparencyMode = value;\n this._forceAlphaTest = value === Material.MATERIAL_ALPHATESTANDBLEND;\n this._markAllSubMeshesAsTexturesAndMiscDirty();\n }\n /**\n * Returns true if alpha blending should be disabled.\n */\n get _disableAlphaBlending() {\n return this._transparencyMode === Material.MATERIAL_OPAQUE || this._transparencyMode === Material.MATERIAL_ALPHATEST;\n }\n /**\n * Specifies whether or not this material should be rendered in alpha blend mode.\n * @returns a boolean specifying if alpha blending is needed\n */\n needAlphaBlending() {\n if (this._disableAlphaBlending) {\n return false;\n }\n return this.alpha < 1.0;\n }\n /**\n * Specifies if the mesh will require alpha blending\n * @param mesh defines the mesh to check\n * @returns a boolean specifying if alpha blending is needed for the mesh\n */\n needAlphaBlendingForMesh(mesh) {\n if (mesh.visibility < 1.0) {\n return true;\n }\n if (this._disableAlphaBlending) {\n return false;\n }\n return mesh.hasVertexAlpha || this.needAlphaBlending();\n }\n /**\n * Specifies whether or not this material should be rendered in alpha test mode.\n * @returns a boolean specifying if an alpha test is needed.\n */\n needAlphaTesting() {\n if (this._forceAlphaTest) {\n return true;\n }\n return false;\n }\n /**\n * Specifies if material alpha testing should be turned on for the mesh\n * @param mesh defines the mesh to check\n */\n _shouldTurnAlphaTestOn(mesh) {\n return !this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting();\n }\n /**\n * Gets the texture used for the alpha test\n * @returns the texture to use for alpha testing\n */\n getAlphaTestTexture() {\n return null;\n }\n /**\n * Marks the material to indicate that it needs to be re-calculated\n * @param forceMaterialDirty - Forces the material to be marked as dirty for all components (same as this.markAsDirty(Material.AllDirtyFlag)). You should use this flag if the material is frozen and you want to force a recompilation.\n */\n markDirty(forceMaterialDirty = false) {\n const meshes = this.getScene().meshes;\n for (const mesh of meshes) {\n if (!mesh.subMeshes) {\n continue;\n }\n for (const subMesh of mesh.subMeshes) {\n if (subMesh.getMaterial() !== this) {\n continue;\n }\n if (!subMesh.effect) {\n continue;\n }\n subMesh.effect._wasPreviouslyReady = false;\n subMesh.effect._wasPreviouslyUsingInstances = null;\n subMesh.effect._forceRebindOnNextCall = forceMaterialDirty;\n }\n }\n if (forceMaterialDirty) {\n this.markAsDirty(Material.AllDirtyFlag);\n }\n }\n /**\n * @internal\n */\n _preBind(effect, overrideOrientation = null) {\n const engine = this._scene.getEngine();\n const orientation = overrideOrientation == null ? this.sideOrientation : overrideOrientation;\n const reverse = orientation === Material.ClockWiseSideOrientation;\n engine.enableEffect(effect ? effect : this._getDrawWrapper());\n engine.setState(this.backFaceCulling, this.zOffset, false, reverse, this._scene._mirroredCameraPosition ? !this.cullBackFaces : this.cullBackFaces, this.stencil, this.zOffsetUnits);\n return reverse;\n }\n /**\n * Binds the material to the mesh\n * @param world defines the world transformation matrix\n * @param mesh defines the mesh to bind the material to\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n bind(world, mesh) { }\n /**\n * Initializes the uniform buffer layout for the shader.\n */\n buildUniformLayout() {\n const ubo = this._uniformBuffer;\n this._eventInfo.ubo = ubo;\n this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareUniformBuffer, this._eventInfo);\n ubo.create();\n this._uniformBufferLayoutBuilt = true;\n }\n /**\n * Binds the submesh to the material\n * @param world defines the world transformation matrix\n * @param mesh defines the mesh containing the submesh\n * @param subMesh defines the submesh to bind the material to\n */\n bindForSubMesh(world, mesh, subMesh) {\n const effect = subMesh.effect;\n if (!effect) {\n return;\n }\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventBindForSubMesh(this._eventInfo);\n effect._forceRebindOnNextCall = false;\n }\n /**\n * Binds the world matrix to the material\n * @param world defines the world transformation matrix\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n bindOnlyWorldMatrix(world) { }\n /**\n * Binds the view matrix to the effect\n * @param effect defines the effect to bind the view matrix to\n */\n bindView(effect) {\n if (!this._useUBO) {\n effect.setMatrix(\"view\", this.getScene().getViewMatrix());\n }\n else {\n this._needToBindSceneUbo = true;\n }\n }\n /**\n * Binds the view projection and projection matrices to the effect\n * @param effect defines the effect to bind the view projection and projection matrices to\n */\n bindViewProjection(effect) {\n if (!this._useUBO) {\n effect.setMatrix(\"viewProjection\", this.getScene().getTransformMatrix());\n effect.setMatrix(\"projection\", this.getScene().getProjectionMatrix());\n }\n else {\n this._needToBindSceneUbo = true;\n }\n }\n /**\n * Binds the view matrix to the effect\n * @param effect defines the effect to bind the view matrix to\n * @param variableName name of the shader variable that will hold the eye position\n */\n bindEyePosition(effect, variableName) {\n if (!this._useUBO) {\n this._scene.bindEyePosition(effect, variableName);\n }\n else {\n this._needToBindSceneUbo = true;\n }\n }\n /**\n * Processes to execute after binding the material to a mesh\n * @param mesh defines the rendered mesh\n * @param effect\n */\n _afterBind(mesh, effect = null) {\n this._scene._cachedMaterial = this;\n if (this._needToBindSceneUbo) {\n if (effect) {\n this._needToBindSceneUbo = false;\n MaterialHelper.BindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());\n this._scene.finalizeSceneUbo();\n }\n }\n if (mesh) {\n this._scene._cachedVisibility = mesh.visibility;\n }\n else {\n this._scene._cachedVisibility = 1;\n }\n if (this._onBindObservable && mesh) {\n this._onBindObservable.notifyObservers(mesh);\n }\n if (this.disableDepthWrite) {\n const engine = this._scene.getEngine();\n this._cachedDepthWriteState = engine.getDepthWrite();\n engine.setDepthWrite(false);\n }\n if (this.disableColorWrite) {\n const engine = this._scene.getEngine();\n this._cachedColorWriteState = engine.getColorWrite();\n engine.setColorWrite(false);\n }\n if (this.depthFunction !== 0) {\n const engine = this._scene.getEngine();\n this._cachedDepthFunctionState = engine.getDepthFunction() || 0;\n engine.setDepthFunction(this.depthFunction);\n }\n }\n /**\n * Unbinds the material from the mesh\n */\n unbind() {\n if (this._onUnBindObservable) {\n this._onUnBindObservable.notifyObservers(this);\n }\n if (this.depthFunction !== 0) {\n const engine = this._scene.getEngine();\n engine.setDepthFunction(this._cachedDepthFunctionState);\n }\n if (this.disableDepthWrite) {\n const engine = this._scene.getEngine();\n engine.setDepthWrite(this._cachedDepthWriteState);\n }\n if (this.disableColorWrite) {\n const engine = this._scene.getEngine();\n engine.setColorWrite(this._cachedColorWriteState);\n }\n }\n /**\n * Returns the animatable textures.\n * @returns - Array of animatable textures.\n */\n getAnimatables() {\n this._eventInfo.animatables = [];\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetAnimatables, this._eventInfo);\n return this._eventInfo.animatables;\n }\n /**\n * Gets the active textures from the material\n * @returns an array of textures\n */\n getActiveTextures() {\n this._eventInfo.activeTextures = [];\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetActiveTextures, this._eventInfo);\n return this._eventInfo.activeTextures;\n }\n /**\n * Specifies if the material uses a texture\n * @param texture defines the texture to check against the material\n * @returns a boolean specifying if the material uses the texture\n */\n hasTexture(texture) {\n this._eventInfo.hasTexture = false;\n this._eventInfo.texture = texture;\n this._callbackPluginEventGeneric(MaterialPluginEvent.HasTexture, this._eventInfo);\n return this._eventInfo.hasTexture;\n }\n /**\n * Makes a duplicate of the material, and gives it a new name\n * @param name defines the new name for the duplicated material\n * @returns the cloned material\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n clone(name) {\n return null;\n }\n _clonePlugins(targetMaterial, rootUrl) {\n const serializationObject = {};\n // Create plugins in targetMaterial in case they don't exist\n this._serializePlugins(serializationObject);\n Material._parsePlugins(serializationObject, targetMaterial, this._scene, rootUrl);\n // Copy the properties of the current plugins to the cloned material's plugins\n if (this.pluginManager) {\n for (const plugin of this.pluginManager._plugins) {\n const targetPlugin = targetMaterial.pluginManager.getPlugin(plugin.name);\n plugin.copyTo(targetPlugin);\n }\n }\n }\n /**\n * Gets the meshes bound to the material\n * @returns an array of meshes bound to the material\n */\n getBindedMeshes() {\n if (this.meshMap) {\n const result = new Array();\n for (const meshId in this.meshMap) {\n const mesh = this.meshMap[meshId];\n if (mesh) {\n result.push(mesh);\n }\n }\n return result;\n }\n else {\n const meshes = this._scene.meshes;\n return meshes.filter((mesh) => mesh.material === this);\n }\n }\n /**\n * Force shader compilation\n * @param mesh defines the mesh associated with this material\n * @param onCompiled defines a function to execute once the material is compiled\n * @param options defines the options to configure the compilation\n * @param onError defines a function to execute if the material fails compiling\n */\n forceCompilation(mesh, onCompiled, options, onError) {\n const localOptions = Object.assign({ clipPlane: false, useInstances: false }, options);\n const scene = this.getScene();\n const currentHotSwapingState = this.allowShaderHotSwapping;\n this.allowShaderHotSwapping = false; // Turned off to let us evaluate the real compilation state\n const checkReady = () => {\n if (!this._scene || !this._scene.getEngine()) {\n return;\n }\n const clipPlaneState = scene.clipPlane;\n if (localOptions.clipPlane) {\n scene.clipPlane = new Plane(0, 0, 0, 1);\n }\n if (this._storeEffectOnSubMeshes) {\n let allDone = true, lastError = null;\n if (mesh.subMeshes) {\n const tempSubMesh = new SubMesh(0, 0, 0, 0, 0, mesh, undefined, false, false);\n if (tempSubMesh.materialDefines) {\n tempSubMesh.materialDefines._renderId = -1;\n }\n if (!this.isReadyForSubMesh(mesh, tempSubMesh, localOptions.useInstances)) {\n if (tempSubMesh.effect && tempSubMesh.effect.getCompilationError() && tempSubMesh.effect.allFallbacksProcessed()) {\n lastError = tempSubMesh.effect.getCompilationError();\n }\n else {\n allDone = false;\n setTimeout(checkReady, 16);\n }\n }\n }\n if (allDone) {\n this.allowShaderHotSwapping = currentHotSwapingState;\n if (lastError) {\n if (onError) {\n onError(lastError);\n }\n }\n if (onCompiled) {\n onCompiled(this);\n }\n }\n }\n else {\n if (this.isReady()) {\n this.allowShaderHotSwapping = currentHotSwapingState;\n if (onCompiled) {\n onCompiled(this);\n }\n }\n else {\n setTimeout(checkReady, 16);\n }\n }\n if (localOptions.clipPlane) {\n scene.clipPlane = clipPlaneState;\n }\n };\n checkReady();\n }\n /**\n * Force shader compilation\n * @param mesh defines the mesh that will use this material\n * @param options defines additional options for compiling the shaders\n * @returns a promise that resolves when the compilation completes\n */\n forceCompilationAsync(mesh, options) {\n return new Promise((resolve, reject) => {\n this.forceCompilation(mesh, () => {\n resolve();\n }, options, (reason) => {\n reject(reason);\n });\n });\n }\n /**\n * Marks a define in the material to indicate that it needs to be re-computed\n * @param flag defines a flag used to determine which parts of the material have to be marked as dirty\n */\n markAsDirty(flag) {\n if (this.getScene().blockMaterialDirtyMechanism || this._blockDirtyMechanism) {\n return;\n }\n Material._DirtyCallbackArray.length = 0;\n if (flag & Material.TextureDirtyFlag) {\n Material._DirtyCallbackArray.push(Material._TextureDirtyCallBack);\n }\n if (flag & Material.LightDirtyFlag) {\n Material._DirtyCallbackArray.push(Material._LightsDirtyCallBack);\n }\n if (flag & Material.FresnelDirtyFlag) {\n Material._DirtyCallbackArray.push(Material._FresnelDirtyCallBack);\n }\n if (flag & Material.AttributesDirtyFlag) {\n Material._DirtyCallbackArray.push(Material._AttributeDirtyCallBack);\n }\n if (flag & Material.MiscDirtyFlag) {\n Material._DirtyCallbackArray.push(Material._MiscDirtyCallBack);\n }\n if (flag & Material.PrePassDirtyFlag) {\n Material._DirtyCallbackArray.push(Material._PrePassDirtyCallBack);\n }\n if (Material._DirtyCallbackArray.length) {\n this._markAllSubMeshesAsDirty(Material._RunDirtyCallBacks);\n }\n this.getScene().resetCachedMaterial();\n }\n /**\n * Resets the draw wrappers cache for all submeshes that are using this material\n */\n resetDrawCache() {\n const meshes = this.getScene().meshes;\n for (const mesh of meshes) {\n if (!mesh.subMeshes) {\n continue;\n }\n for (const subMesh of mesh.subMeshes) {\n if (subMesh.getMaterial() !== this) {\n continue;\n }\n subMesh.resetDrawCache();\n }\n }\n }\n /**\n * Marks all submeshes of a material to indicate that their material defines need to be re-calculated\n * @param func defines a function which checks material defines against the submeshes\n */\n _markAllSubMeshesAsDirty(func) {\n if (this.getScene().blockMaterialDirtyMechanism || this._blockDirtyMechanism) {\n return;\n }\n const meshes = this.getScene().meshes;\n for (const mesh of meshes) {\n if (!mesh.subMeshes) {\n continue;\n }\n for (const subMesh of mesh.subMeshes) {\n // We want to skip the submeshes which are not using this material or which have not yet rendered at least once\n if (subMesh.getMaterial(false) !== this) {\n continue;\n }\n for (const drawWrapper of subMesh._drawWrappers) {\n if (!drawWrapper || !drawWrapper.defines || !drawWrapper.defines.markAllAsDirty) {\n continue;\n }\n if (this._materialContext === drawWrapper.materialContext) {\n func(drawWrapper.defines);\n }\n }\n }\n }\n }\n /**\n * Indicates that the scene should check if the rendering now needs a prepass\n */\n _markScenePrePassDirty() {\n if (this.getScene().blockMaterialDirtyMechanism || this._blockDirtyMechanism) {\n return;\n }\n const prePassRenderer = this.getScene().enablePrePassRenderer();\n if (prePassRenderer) {\n prePassRenderer.markAsDirty();\n }\n }\n /**\n * Indicates that we need to re-calculated for all submeshes\n */\n _markAllSubMeshesAsAllDirty() {\n this._markAllSubMeshesAsDirty(Material._AllDirtyCallBack);\n }\n /**\n * Indicates that image processing needs to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsImageProcessingDirty() {\n this._markAllSubMeshesAsDirty(Material._ImageProcessingDirtyCallBack);\n }\n /**\n * Indicates that textures need to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsTexturesDirty() {\n this._markAllSubMeshesAsDirty(Material._TextureDirtyCallBack);\n }\n /**\n * Indicates that fresnel needs to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsFresnelDirty() {\n this._markAllSubMeshesAsDirty(Material._FresnelDirtyCallBack);\n }\n /**\n * Indicates that fresnel and misc need to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsFresnelAndMiscDirty() {\n this._markAllSubMeshesAsDirty(Material._FresnelAndMiscDirtyCallBack);\n }\n /**\n * Indicates that lights need to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsLightsDirty() {\n this._markAllSubMeshesAsDirty(Material._LightsDirtyCallBack);\n }\n /**\n * Indicates that attributes need to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsAttributesDirty() {\n this._markAllSubMeshesAsDirty(Material._AttributeDirtyCallBack);\n }\n /**\n * Indicates that misc needs to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsMiscDirty() {\n this._markAllSubMeshesAsDirty(Material._MiscDirtyCallBack);\n }\n /**\n * Indicates that prepass needs to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsPrePassDirty() {\n this._markAllSubMeshesAsDirty(Material._MiscDirtyCallBack);\n }\n /**\n * Indicates that textures and misc need to be re-calculated for all submeshes\n */\n _markAllSubMeshesAsTexturesAndMiscDirty() {\n this._markAllSubMeshesAsDirty(Material._TextureAndMiscDirtyCallBack);\n }\n _checkScenePerformancePriority() {\n if (this._scene.performancePriority !== ScenePerformancePriority.BackwardCompatible) {\n this.checkReadyOnlyOnce = true;\n // re-set the flag when the perf priority changes\n const observer = this._scene.onScenePerformancePriorityChangedObservable.addOnce(() => {\n this.checkReadyOnlyOnce = false;\n });\n // if this material is disposed before the scene is disposed, cleanup the observer\n this.onDisposeObservable.add(() => {\n this._scene.onScenePerformancePriorityChangedObservable.remove(observer);\n });\n }\n }\n /**\n * Sets the required values to the prepass renderer.\n * @param prePassRenderer defines the prepass renderer to setup.\n * @returns true if the pre pass is needed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setPrePassRenderer(prePassRenderer) {\n // Do Nothing by default\n return false;\n }\n /**\n * Disposes the material\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\n * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh\n */\n dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh) {\n const scene = this.getScene();\n // Animations\n scene.stopAnimation(this);\n scene.freeProcessedMaterials();\n // Remove from scene\n scene.removeMaterial(this);\n this._eventInfo.forceDisposeTextures = forceDisposeTextures;\n this._callbackPluginEventGeneric(MaterialPluginEvent.Disposed, this._eventInfo);\n if (this._parentContainer) {\n const index = this._parentContainer.materials.indexOf(this);\n if (index > -1) {\n this._parentContainer.materials.splice(index, 1);\n }\n this._parentContainer = null;\n }\n if (notBoundToMesh !== true) {\n // Remove from meshes\n if (this.meshMap) {\n for (const meshId in this.meshMap) {\n const mesh = this.meshMap[meshId];\n if (mesh) {\n mesh.material = null; // will set the entry in the map to undefined\n this.releaseVertexArrayObject(mesh, forceDisposeEffect);\n }\n }\n }\n else {\n const meshes = scene.meshes;\n for (const mesh of meshes) {\n if (mesh.material === this && !mesh.sourceMesh) {\n mesh.material = null;\n this.releaseVertexArrayObject(mesh, forceDisposeEffect);\n }\n }\n }\n }\n this._uniformBuffer.dispose();\n // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect\n if (forceDisposeEffect && this._drawWrapper.effect) {\n if (!this._storeEffectOnSubMeshes) {\n this._drawWrapper.effect.dispose();\n }\n this._drawWrapper.effect = null;\n }\n this.metadata = null;\n // Callback\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n if (this._onBindObservable) {\n this._onBindObservable.clear();\n }\n if (this._onUnBindObservable) {\n this._onUnBindObservable.clear();\n }\n if (this._onEffectCreatedObservable) {\n this._onEffectCreatedObservable.clear();\n }\n if (this._eventInfo) {\n this._eventInfo = {};\n }\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n releaseVertexArrayObject(mesh, forceDisposeEffect) {\n if (mesh.geometry) {\n const geometry = mesh.geometry;\n if (this._storeEffectOnSubMeshes) {\n for (const subMesh of mesh.subMeshes) {\n geometry._releaseVertexArrayObject(subMesh.effect);\n if (forceDisposeEffect && subMesh.effect) {\n subMesh.effect.dispose();\n }\n }\n }\n else {\n geometry._releaseVertexArrayObject(this._drawWrapper.effect);\n }\n }\n }\n /**\n * Serializes this material\n * @returns the serialized material object\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this);\n serializationObject.stencil = this.stencil.serialize();\n serializationObject.uniqueId = this.uniqueId;\n this._serializePlugins(serializationObject);\n return serializationObject;\n }\n _serializePlugins(serializationObject) {\n serializationObject.plugins = {};\n if (this.pluginManager) {\n for (const plugin of this.pluginManager._plugins) {\n serializationObject.plugins[plugin.getClassName()] = plugin.serialize();\n }\n }\n }\n /**\n * Creates a material from parsed material data\n * @param parsedMaterial defines parsed material data\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures\n * @returns a new material\n */\n static Parse(parsedMaterial, scene, rootUrl) {\n if (!parsedMaterial.customType) {\n parsedMaterial.customType = \"BABYLON.StandardMaterial\";\n }\n else if (parsedMaterial.customType === \"BABYLON.PBRMaterial\" && parsedMaterial.overloadedAlbedo) {\n parsedMaterial.customType = \"BABYLON.LegacyPBRMaterial\";\n if (!BABYLON.LegacyPBRMaterial) {\n Logger.Error(\"Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library.\");\n return null;\n }\n }\n const materialType = Tools.Instantiate(parsedMaterial.customType);\n const material = materialType.Parse(parsedMaterial, scene, rootUrl);\n material._loadedUniqueId = parsedMaterial.uniqueId;\n return material;\n }\n static _parsePlugins(serializationObject, material, scene, rootUrl) {\n var _a;\n if (!serializationObject.plugins) {\n return;\n }\n for (const pluginClassName in serializationObject.plugins) {\n const pluginData = serializationObject.plugins[pluginClassName];\n let plugin = (_a = material.pluginManager) === null || _a === void 0 ? void 0 : _a.getPlugin(pluginData.name);\n if (!plugin) {\n const pluginClassType = Tools.Instantiate(\"BABYLON.\" + pluginClassName);\n if (pluginClassType) {\n plugin = new pluginClassType(material);\n }\n }\n plugin === null || plugin === void 0 ? void 0 : plugin.parse(pluginData, scene, rootUrl);\n }\n }\n }\n /**\n * Returns the triangle fill mode\n */\n Material.TriangleFillMode = 0;\n /**\n * Returns the wireframe mode\n */\n Material.WireFrameFillMode = 1;\n /**\n * Returns the point fill mode\n */\n Material.PointFillMode = 2;\n /**\n * Returns the point list draw mode\n */\n Material.PointListDrawMode = 3;\n /**\n * Returns the line list draw mode\n */\n Material.LineListDrawMode = 4;\n /**\n * Returns the line loop draw mode\n */\n Material.LineLoopDrawMode = 5;\n /**\n * Returns the line strip draw mode\n */\n Material.LineStripDrawMode = 6;\n /**\n * Returns the triangle strip draw mode\n */\n Material.TriangleStripDrawMode = 7;\n /**\n * Returns the triangle fan draw mode\n */\n Material.TriangleFanDrawMode = 8;\n /**\n * Stores the clock-wise side orientation\n */\n Material.ClockWiseSideOrientation = 0;\n /**\n * Stores the counter clock-wise side orientation\n */\n Material.CounterClockWiseSideOrientation = 1;\n /**\n * The dirty texture flag value\n */\n Material.TextureDirtyFlag = 1;\n /**\n * The dirty light flag value\n */\n Material.LightDirtyFlag = 2;\n /**\n * The dirty fresnel flag value\n */\n Material.FresnelDirtyFlag = 4;\n /**\n * The dirty attribute flag value\n */\n Material.AttributesDirtyFlag = 8;\n /**\n * The dirty misc flag value\n */\n Material.MiscDirtyFlag = 16;\n /**\n * The dirty prepass flag value\n */\n Material.PrePassDirtyFlag = 32;\n /**\n * The all dirty flag value\n */\n Material.AllDirtyFlag = 63;\n /**\n * MaterialTransparencyMode: No transparency mode, Alpha channel is not use.\n */\n Material.MATERIAL_OPAQUE = 0;\n /**\n * MaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.\n */\n Material.MATERIAL_ALPHATEST = 1;\n /**\n * MaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\n */\n Material.MATERIAL_ALPHABLEND = 2;\n /**\n * MaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\n * They are also discarded below the alpha cutoff threshold to improve performances.\n */\n Material.MATERIAL_ALPHATESTANDBLEND = 3;\n /**\n * The Whiteout method is used to blend normals.\n * Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/\n */\n Material.MATERIAL_NORMALBLENDMETHOD_WHITEOUT = 0;\n /**\n * The Reoriented Normal Mapping method is used to blend normals.\n * Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/\n */\n Material.MATERIAL_NORMALBLENDMETHOD_RNM = 1;\n /**\n * Event observable which raises global events common to all materials (like MaterialPluginEvent.Created)\n */\n Material.OnEventObservable = new Observable$1();\n Material._AllDirtyCallBack = (defines) => defines.markAllAsDirty();\n Material._ImageProcessingDirtyCallBack = (defines) => defines.markAsImageProcessingDirty();\n Material._TextureDirtyCallBack = (defines) => defines.markAsTexturesDirty();\n Material._FresnelDirtyCallBack = (defines) => defines.markAsFresnelDirty();\n Material._MiscDirtyCallBack = (defines) => defines.markAsMiscDirty();\n Material._PrePassDirtyCallBack = (defines) => defines.markAsPrePassDirty();\n Material._LightsDirtyCallBack = (defines) => defines.markAsLightDirty();\n Material._AttributeDirtyCallBack = (defines) => defines.markAsAttributesDirty();\n Material._FresnelAndMiscDirtyCallBack = (defines) => {\n Material._FresnelDirtyCallBack(defines);\n Material._MiscDirtyCallBack(defines);\n };\n Material._TextureAndMiscDirtyCallBack = (defines) => {\n Material._TextureDirtyCallBack(defines);\n Material._MiscDirtyCallBack(defines);\n };\n Material._DirtyCallbackArray = [];\n Material._RunDirtyCallBacks = (defines) => {\n for (const cb of Material._DirtyCallbackArray) {\n cb(defines);\n }\n };\n __decorate$1([\n serialize()\n ], Material.prototype, \"id\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"uniqueId\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"name\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"metadata\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"checkReadyOnEveryCall\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"checkReadyOnlyOnce\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"state\", void 0);\n __decorate$1([\n serialize(\"alpha\")\n ], Material.prototype, \"_alpha\", void 0);\n __decorate$1([\n serialize(\"backFaceCulling\")\n ], Material.prototype, \"_backFaceCulling\", void 0);\n __decorate$1([\n serialize(\"cullBackFaces\")\n ], Material.prototype, \"_cullBackFaces\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"sideOrientation\", void 0);\n __decorate$1([\n serialize(\"alphaMode\")\n ], Material.prototype, \"_alphaMode\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"_needDepthPrePass\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"disableDepthWrite\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"disableColorWrite\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"forceDepthWrite\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"depthFunction\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"separateCullingPass\", void 0);\n __decorate$1([\n serialize(\"fogEnabled\")\n ], Material.prototype, \"_fogEnabled\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"pointSize\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"zOffset\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"zOffsetUnits\", void 0);\n __decorate$1([\n serialize()\n ], Material.prototype, \"pointsCloud\", null);\n __decorate$1([\n serialize()\n ], Material.prototype, \"fillMode\", null);\n __decorate$1([\n serialize()\n ], Material.prototype, \"transparencyMode\", null);\n\n /**\n * A multi-material is used to apply different materials to different parts of the same object without the need of\n * separate meshes. This can be use to improve performances.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\n */\n class MultiMaterial extends Material {\n /**\n * Gets or Sets the list of Materials used within the multi material.\n * They need to be ordered according to the submeshes order in the associated mesh\n */\n get subMaterials() {\n return this._subMaterials;\n }\n set subMaterials(value) {\n this._subMaterials = value;\n this._hookArray(value);\n }\n /**\n * Function used to align with Node.getChildren()\n * @returns the list of Materials used within the multi material\n */\n getChildren() {\n return this.subMaterials;\n }\n /**\n * Instantiates a new Multi Material\n * A multi-material is used to apply different materials to different parts of the same object without the need of\n * separate meshes. This can be use to improve performances.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\n * @param name Define the name in the scene\n * @param scene Define the scene the material belongs to\n */\n constructor(name, scene) {\n super(name, scene, true);\n /** @internal */\n this._waitingSubMaterialsUniqueIds = [];\n this.getScene().addMultiMaterial(this);\n this.subMaterials = new Array();\n this._storeEffectOnSubMeshes = true; // multimaterial is considered like a push material\n }\n _hookArray(array) {\n const oldPush = array.push;\n array.push = (...items) => {\n const result = oldPush.apply(array, items);\n this._markAllSubMeshesAsTexturesDirty();\n return result;\n };\n const oldSplice = array.splice;\n array.splice = (index, deleteCount) => {\n const deleted = oldSplice.apply(array, [index, deleteCount]);\n this._markAllSubMeshesAsTexturesDirty();\n return deleted;\n };\n }\n /**\n * Get one of the submaterial by its index in the submaterials array\n * @param index The index to look the sub material at\n * @returns The Material if the index has been defined\n */\n getSubMaterial(index) {\n if (index < 0 || index >= this.subMaterials.length) {\n return this.getScene().defaultMaterial;\n }\n return this.subMaterials[index];\n }\n /**\n * Get the list of active textures for the whole sub materials list.\n * @returns All the textures that will be used during the rendering\n */\n getActiveTextures() {\n return super.getActiveTextures().concat(...this.subMaterials.map((subMaterial) => {\n if (subMaterial) {\n return subMaterial.getActiveTextures();\n }\n else {\n return [];\n }\n }));\n }\n /**\n * Specifies if any sub-materials of this multi-material use a given texture.\n * @param texture Defines the texture to check against this multi-material's sub-materials.\n * @returns A boolean specifying if any sub-material of this multi-material uses the texture.\n */\n hasTexture(texture) {\n var _a;\n if (super.hasTexture(texture)) {\n return true;\n }\n for (let i = 0; i < this.subMaterials.length; i++) {\n if ((_a = this.subMaterials[i]) === null || _a === void 0 ? void 0 : _a.hasTexture(texture)) {\n return true;\n }\n }\n return false;\n }\n /**\n * Gets the current class name of the material e.g. \"MultiMaterial\"\n * Mainly use in serialization.\n * @returns the class name\n */\n getClassName() {\n return \"MultiMaterial\";\n }\n /**\n * Checks if the material is ready to render the requested sub mesh\n * @param mesh Define the mesh the submesh belongs to\n * @param subMesh Define the sub mesh to look readiness for\n * @param useInstances Define whether or not the material is used with instances\n * @returns true if ready, otherwise false\n */\n isReadyForSubMesh(mesh, subMesh, useInstances) {\n for (let index = 0; index < this.subMaterials.length; index++) {\n const subMaterial = this.subMaterials[index];\n if (subMaterial) {\n if (subMaterial._storeEffectOnSubMeshes) {\n if (!subMaterial.isReadyForSubMesh(mesh, subMesh, useInstances)) {\n return false;\n }\n continue;\n }\n if (!subMaterial.isReady(mesh)) {\n return false;\n }\n }\n }\n return true;\n }\n /**\n * Clones the current material and its related sub materials\n * @param name Define the name of the newly cloned material\n * @param cloneChildren Define if submaterial will be cloned or shared with the parent instance\n * @returns the cloned material\n */\n clone(name, cloneChildren) {\n const newMultiMaterial = new MultiMaterial(name, this.getScene());\n for (let index = 0; index < this.subMaterials.length; index++) {\n let subMaterial = null;\n const current = this.subMaterials[index];\n if (cloneChildren && current) {\n subMaterial = current.clone(name + \"-\" + current.name);\n }\n else {\n subMaterial = this.subMaterials[index];\n }\n newMultiMaterial.subMaterials.push(subMaterial);\n }\n return newMultiMaterial;\n }\n /**\n * Serializes the materials into a JSON representation.\n * @returns the JSON representation\n */\n serialize() {\n const serializationObject = {};\n serializationObject.name = this.name;\n serializationObject.id = this.id;\n serializationObject.uniqueId = this.uniqueId;\n if (Tags) {\n serializationObject.tags = Tags.GetTags(this);\n }\n serializationObject.materialsUniqueIds = [];\n serializationObject.materials = [];\n for (let matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {\n const subMat = this.subMaterials[matIndex];\n if (subMat) {\n serializationObject.materialsUniqueIds.push(subMat.uniqueId);\n serializationObject.materials.push(subMat.id);\n }\n else {\n serializationObject.materialsUniqueIds.push(null);\n serializationObject.materials.push(null);\n }\n }\n return serializationObject;\n }\n /**\n * Dispose the material and release its associated resources\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)\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)\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)\n */\n dispose(forceDisposeEffect, forceDisposeTextures, forceDisposeChildren) {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n if (forceDisposeChildren) {\n for (let index = 0; index < this.subMaterials.length; index++) {\n const subMaterial = this.subMaterials[index];\n if (subMaterial) {\n subMaterial.dispose(forceDisposeEffect, forceDisposeTextures);\n }\n }\n }\n const index = scene.multiMaterials.indexOf(this);\n if (index >= 0) {\n scene.multiMaterials.splice(index, 1);\n }\n super.dispose(forceDisposeEffect, forceDisposeTextures);\n }\n /**\n * Creates a MultiMaterial from parsed MultiMaterial data.\n * @param parsedMultiMaterial defines parsed MultiMaterial data.\n * @param scene defines the hosting scene\n * @returns a new MultiMaterial\n */\n static ParseMultiMaterial(parsedMultiMaterial, scene) {\n const multiMaterial = new MultiMaterial(parsedMultiMaterial.name, scene);\n multiMaterial.id = parsedMultiMaterial.id;\n multiMaterial._loadedUniqueId = parsedMultiMaterial.uniqueId;\n if (Tags) {\n Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);\n }\n if (parsedMultiMaterial.materialsUniqueIds) {\n multiMaterial._waitingSubMaterialsUniqueIds = parsedMultiMaterial.materialsUniqueIds;\n }\n else {\n parsedMultiMaterial.materials.forEach((subMatId) => multiMaterial.subMaterials.push(scene.getLastMaterialById(subMatId)));\n }\n return multiMaterial;\n }\n }\n RegisterClass(\"BABYLON.MultiMaterial\", MultiMaterial);\n\n /**\n * Class used to represent a specific level of detail of a mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\n */\n class MeshLODLevel {\n /**\n * Creates a new LOD level\n * @param distanceOrScreenCoverage defines either the distance or the screen coverage where this level should start being displayed\n * @param mesh defines the mesh to use to render this level\n */\n constructor(\n /** Either distance from the center of the object to show this level or the screen coverage if `useLODScreenCoverage` is set to `true` on the mesh*/\n distanceOrScreenCoverage, \n /** Defines the mesh to use to render this level */\n mesh) {\n this.distanceOrScreenCoverage = distanceOrScreenCoverage;\n this.mesh = mesh;\n }\n }\n\n /**\n * @internal\n **/\n class _CreationDataStorage {\n }\n /**\n * @internal\n **/\n class _InstanceDataStorage {\n constructor() {\n this.visibleInstances = {};\n this.batchCache = new _InstancesBatch();\n this.batchCacheReplacementModeInFrozenMode = new _InstancesBatch();\n this.instancesBufferSize = 32 * 16 * 4; // let's start with a maximum of 32 instances\n }\n }\n /**\n * @internal\n **/\n class _InstancesBatch {\n constructor() {\n this.mustReturn = false;\n this.visibleInstances = new Array();\n this.renderSelf = new Array();\n this.hardwareInstancedRendering = new Array();\n }\n }\n /**\n * @internal\n **/\n class _ThinInstanceDataStorage {\n constructor() {\n this.instancesCount = 0;\n this.matrixBuffer = null;\n this.previousMatrixBuffer = null;\n this.matrixBufferSize = 32 * 16; // let's start with a maximum of 32 thin instances\n this.matrixData = null;\n this.boundingVectors = [];\n this.worldMatrices = null;\n }\n }\n /**\n * @internal\n **/\n class _InternalMeshDataInfo {\n constructor() {\n this._areNormalsFrozen = false; // Will be used by ribbons mainly\n // Will be used to save a source mesh reference, If any\n this._source = null;\n // Will be used to for fast cloned mesh lookup\n this.meshMap = null;\n this._preActivateId = -1;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this._LODLevels = new Array();\n /** Alternative definition of LOD level, using screen coverage instead of distance */\n this._useLODScreenCoverage = false;\n this._effectiveMaterial = null;\n this._forcedInstanceCount = 0;\n this._overrideRenderingFillMode = null;\n }\n }\n /**\n * Class used to represent renderable models\n */\n class Mesh extends AbstractMesh {\n /**\n * Gets the default side orientation.\n * @param orientation the orientation to value to attempt to get\n * @returns the default orientation\n * @internal\n */\n static _GetDefaultSideOrientation(orientation) {\n return orientation || Mesh.FRONTSIDE; // works as Mesh.FRONTSIDE is 0\n }\n /**\n * Determines if the LOD levels are intended to be calculated using screen coverage (surface area ratio) instead of distance.\n */\n get useLODScreenCoverage() {\n return this._internalMeshDataInfo._useLODScreenCoverage;\n }\n set useLODScreenCoverage(value) {\n this._internalMeshDataInfo._useLODScreenCoverage = value;\n this._sortLODLevels();\n }\n get computeBonesUsingShaders() {\n return this._internalAbstractMeshDataInfo._computeBonesUsingShaders;\n }\n set computeBonesUsingShaders(value) {\n if (this._internalAbstractMeshDataInfo._computeBonesUsingShaders === value) {\n return;\n }\n if (value && this._internalMeshDataInfo._sourcePositions) {\n // switch from software to GPU computation: we need to reset the vertex and normal buffers that have been updated by the software process\n this.setVerticesData(VertexBuffer.PositionKind, this._internalMeshDataInfo._sourcePositions, true);\n if (this._internalMeshDataInfo._sourceNormals) {\n this.setVerticesData(VertexBuffer.NormalKind, this._internalMeshDataInfo._sourceNormals, true);\n }\n this._internalMeshDataInfo._sourcePositions = null;\n this._internalMeshDataInfo._sourceNormals = null;\n }\n this._internalAbstractMeshDataInfo._computeBonesUsingShaders = value;\n this._markSubMeshesAsAttributesDirty();\n }\n /**\n * An event triggered before rendering the mesh\n */\n get onBeforeRenderObservable() {\n if (!this._internalMeshDataInfo._onBeforeRenderObservable) {\n this._internalMeshDataInfo._onBeforeRenderObservable = new Observable$1();\n }\n return this._internalMeshDataInfo._onBeforeRenderObservable;\n }\n /**\n * An event triggered before binding the mesh\n */\n get onBeforeBindObservable() {\n if (!this._internalMeshDataInfo._onBeforeBindObservable) {\n this._internalMeshDataInfo._onBeforeBindObservable = new Observable$1();\n }\n return this._internalMeshDataInfo._onBeforeBindObservable;\n }\n /**\n * An event triggered after rendering the mesh\n */\n get onAfterRenderObservable() {\n if (!this._internalMeshDataInfo._onAfterRenderObservable) {\n this._internalMeshDataInfo._onAfterRenderObservable = new Observable$1();\n }\n return this._internalMeshDataInfo._onAfterRenderObservable;\n }\n /**\n * An event triggeredbetween rendering pass when using separateCullingPass = true\n */\n get onBetweenPassObservable() {\n if (!this._internalMeshDataInfo._onBetweenPassObservable) {\n this._internalMeshDataInfo._onBetweenPassObservable = new Observable$1();\n }\n return this._internalMeshDataInfo._onBetweenPassObservable;\n }\n /**\n * An event triggered before drawing the mesh\n */\n get onBeforeDrawObservable() {\n if (!this._internalMeshDataInfo._onBeforeDrawObservable) {\n this._internalMeshDataInfo._onBeforeDrawObservable = new Observable$1();\n }\n return this._internalMeshDataInfo._onBeforeDrawObservable;\n }\n /**\n * Sets a callback to call before drawing the mesh. It is recommended to use onBeforeDrawObservable instead\n */\n set onBeforeDraw(callback) {\n if (this._onBeforeDrawObserver) {\n this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver);\n }\n this._onBeforeDrawObserver = this.onBeforeDrawObservable.add(callback);\n }\n get hasInstances() {\n return this.instances.length > 0;\n }\n get hasThinInstances() {\n var _a;\n return ((_a = this._thinInstanceDataStorage.instancesCount) !== null && _a !== void 0 ? _a : 0) > 0;\n }\n /**\n * Gets or sets the forced number of instances to display.\n * If 0 (default value), the number of instances is not forced and depends on the draw type\n * (regular / instance / thin instances mesh)\n */\n get forcedInstanceCount() {\n return this._internalMeshDataInfo._forcedInstanceCount;\n }\n set forcedInstanceCount(count) {\n this._internalMeshDataInfo._forcedInstanceCount = count;\n }\n /**\n * Use this property to override the Material's fillMode value\n */\n get overrideRenderingFillMode() {\n return this._internalMeshDataInfo._overrideRenderingFillMode;\n }\n set overrideRenderingFillMode(fillMode) {\n this._internalMeshDataInfo._overrideRenderingFillMode = fillMode;\n }\n /**\n * Gets the source mesh (the one used to clone this one from)\n */\n get source() {\n return this._internalMeshDataInfo._source;\n }\n /**\n * Gets the list of clones of this mesh\n * The scene must have been constructed with useClonedMeshMap=true for this to work!\n * Note that useClonedMeshMap=true is the default setting\n */\n get cloneMeshMap() {\n return this._internalMeshDataInfo.meshMap;\n }\n /**\n * Gets or sets a boolean indicating that this mesh does not use index buffer\n */\n get isUnIndexed() {\n return this._unIndexed;\n }\n set isUnIndexed(value) {\n if (this._unIndexed !== value) {\n this._unIndexed = value;\n this._markSubMeshesAsAttributesDirty();\n }\n }\n /** Gets the array buffer used to store the instanced buffer used for instances' world matrices */\n get worldMatrixInstancedBuffer() {\n return this._instanceDataStorage.instancesData;\n }\n /** Gets the array buffer used to store the instanced buffer used for instances' previous world matrices */\n get previousWorldMatrixInstancedBuffer() {\n return this._instanceDataStorage.instancesPreviousData;\n }\n /** Gets or sets a boolean indicating that the update of the instance buffer of the world matrices is manual */\n get manualUpdateOfWorldMatrixInstancedBuffer() {\n return this._instanceDataStorage.manualUpdate;\n }\n set manualUpdateOfWorldMatrixInstancedBuffer(value) {\n this._instanceDataStorage.manualUpdate = value;\n }\n /** Gets or sets a boolean indicating that the update of the instance buffer of the world matrices is manual */\n get manualUpdateOfPreviousWorldMatrixInstancedBuffer() {\n return this._instanceDataStorage.previousManualUpdate;\n }\n set manualUpdateOfPreviousWorldMatrixInstancedBuffer(value) {\n this._instanceDataStorage.previousManualUpdate = value;\n }\n /** Gets or sets a boolean indicating that the update of the instance buffer of the world matrices must be performed in all cases (and notably even in frozen mode) */\n get forceWorldMatrixInstancedBufferUpdate() {\n return this._instanceDataStorage.forceMatrixUpdates;\n }\n set forceWorldMatrixInstancedBufferUpdate(value) {\n this._instanceDataStorage.forceMatrixUpdates = value;\n }\n /**\n * @constructor\n * @param name The value used by scene.getMeshByName() to do a lookup.\n * @param scene The scene to add this mesh to.\n * @param parent The parent of this mesh, if it has one\n * @param source An optional Mesh from which geometry is shared, cloned.\n * @param doNotCloneChildren When cloning, skip cloning child meshes of source, default False.\n * When false, achieved by calling a clone(), also passing False.\n * This will make creation of children, recursive.\n * @param clonePhysicsImpostor When cloning, include cloning mesh physics impostor, default True.\n */\n constructor(name, scene = null, parent = null, source = null, doNotCloneChildren, clonePhysicsImpostor = true) {\n super(name, scene);\n // Internal data\n this._internalMeshDataInfo = new _InternalMeshDataInfo();\n // Members\n /**\n * Gets the delay loading state of the mesh (when delay loading is turned on)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/incrementalLoading\n */\n this.delayLoadState = 0;\n /**\n * Gets the list of instances created from this mesh\n * it is not supposed to be modified manually.\n * Note also that the order of the InstancedMesh wihin the array is not significant and might change.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\n */\n this.instances = new Array();\n // Private\n /** @internal */\n this._creationDataStorage = null;\n /** @internal */\n this._geometry = null;\n /** @internal */\n this._instanceDataStorage = new _InstanceDataStorage();\n /** @internal */\n this._thinInstanceDataStorage = new _ThinInstanceDataStorage();\n /** @internal */\n this._shouldGenerateFlatShading = false;\n // Use by builder only to know what orientation were the mesh build in.\n /** @internal */\n this._originalBuilderSideOrientation = Mesh.DEFAULTSIDE;\n /**\n * Use this property to change the original side orientation defined at construction time\n */\n this.overrideMaterialSideOrientation = null;\n /**\n * Gets or sets a boolean indicating whether to render ignoring the active camera's max z setting. (false by default)\n * You should not mix meshes that have this property set to true with meshes that have it set to false if they all write\n * to the depth buffer, because the z-values are not comparable in the two cases and you will get rendering artifacts if you do.\n * You can set the property to true for meshes that do not write to the depth buffer, or set the same value (either false or true) otherwise.\n * Note this will reduce performance when set to true.\n */\n this.ignoreCameraMaxZ = false;\n scene = this.getScene();\n this._onBeforeDraw = (isInstance, world, effectiveMaterial) => {\n if (isInstance && effectiveMaterial) {\n if (this._uniformBuffer) {\n this.transferToEffect(world);\n }\n else {\n effectiveMaterial.bindOnlyWorldMatrix(world);\n }\n }\n };\n if (source) {\n // Geometry\n if (source._geometry) {\n source._geometry.applyToMesh(this);\n }\n // Deep copy\n DeepCopier.DeepCopy(source, this, [\n \"name\",\n \"material\",\n \"skeleton\",\n \"instances\",\n \"parent\",\n \"uniqueId\",\n \"source\",\n \"metadata\",\n \"morphTargetManager\",\n \"hasInstances\",\n \"worldMatrixInstancedBuffer\",\n \"previousWorldMatrixInstancedBuffer\",\n \"hasLODLevels\",\n \"geometry\",\n \"isBlocked\",\n \"areNormalsFrozen\",\n \"facetNb\",\n \"isFacetDataEnabled\",\n \"lightSources\",\n \"useBones\",\n \"isAnInstance\",\n \"collider\",\n \"edgesRenderer\",\n \"forward\",\n \"up\",\n \"right\",\n \"absolutePosition\",\n \"absoluteScaling\",\n \"absoluteRotationQuaternion\",\n \"isWorldMatrixFrozen\",\n \"nonUniformScaling\",\n \"behaviors\",\n \"worldMatrixFromCache\",\n \"hasThinInstances\",\n \"cloneMeshMap\",\n \"hasBoundingInfo\",\n \"physicsBody\",\n \"physicsImpostor\",\n ], [\"_poseMatrix\"]);\n // Source mesh\n this._internalMeshDataInfo._source = source;\n if (scene.useClonedMeshMap) {\n if (!source._internalMeshDataInfo.meshMap) {\n source._internalMeshDataInfo.meshMap = {};\n }\n source._internalMeshDataInfo.meshMap[this.uniqueId] = this;\n }\n // Construction Params\n // Clone parameters allowing mesh to be updated in case of parametric shapes.\n this._originalBuilderSideOrientation = source._originalBuilderSideOrientation;\n this._creationDataStorage = source._creationDataStorage;\n // Animation ranges\n if (source._ranges) {\n const ranges = source._ranges;\n for (const name in ranges) {\n if (!Object.prototype.hasOwnProperty.call(ranges, name)) {\n continue;\n }\n if (!ranges[name]) {\n continue;\n }\n this.createAnimationRange(name, ranges[name].from, ranges[name].to);\n }\n }\n // Metadata\n if (source.metadata && source.metadata.clone) {\n this.metadata = source.metadata.clone();\n }\n else {\n this.metadata = source.metadata;\n }\n this._internalMetadata = source._internalMetadata;\n // Tags\n if (Tags && Tags.HasTags(source)) {\n Tags.AddTagsTo(this, Tags.GetTags(source, true));\n }\n // Enabled. We shouldn't need to check the source's ancestors, as this mesh\n // will have the same ones.\n this.setEnabled(source.isEnabled(false));\n // Parent\n this.parent = source.parent;\n // Pivot\n this.setPivotMatrix(source.getPivotMatrix());\n this.id = name + \".\" + source.id;\n // Material\n this.material = source.material;\n if (!doNotCloneChildren) {\n // Children\n const directDescendants = source.getDescendants(true);\n for (let index = 0; index < directDescendants.length; index++) {\n const child = directDescendants[index];\n if (child.clone) {\n child.clone(name + \".\" + child.name, this);\n }\n }\n }\n // Morphs\n if (source.morphTargetManager) {\n this.morphTargetManager = source.morphTargetManager;\n }\n // Physics clone\n if (scene.getPhysicsEngine) {\n const physicsEngine = scene.getPhysicsEngine();\n if (clonePhysicsImpostor && physicsEngine) {\n if (physicsEngine.getPluginVersion() === 1) {\n const impostor = physicsEngine.getImpostorForPhysicsObject(source);\n if (impostor) {\n this.physicsImpostor = impostor.clone(this);\n }\n }\n else if (physicsEngine.getPluginVersion() === 2) {\n if (source.physicsBody) {\n source.physicsBody.clone(this);\n }\n }\n }\n }\n // Particles\n for (let index = 0; index < scene.particleSystems.length; index++) {\n const system = scene.particleSystems[index];\n if (system.emitter === source) {\n system.clone(system.name, this);\n }\n }\n // Skeleton\n this.skeleton = source.skeleton;\n this.refreshBoundingInfo(true, true);\n this.computeWorldMatrix(true);\n }\n // Parent\n if (parent !== null) {\n this.parent = parent;\n }\n this._instanceDataStorage.hardwareInstancedRendering = this.getEngine().getCaps().instancedArrays;\n this._internalMeshDataInfo._onMeshReadyObserverAdded = (observer) => {\n // only notify once! then unregister the observer\n observer.unregisterOnNextCall = true;\n if (this.isReady(true)) {\n this.onMeshReadyObservable.notifyObservers(this);\n }\n else {\n if (!this._internalMeshDataInfo._checkReadinessObserver) {\n this._internalMeshDataInfo._checkReadinessObserver = this._scene.onBeforeRenderObservable.add(() => {\n // check for complete readiness\n if (this.isReady(true)) {\n this._scene.onBeforeRenderObservable.remove(this._internalMeshDataInfo._checkReadinessObserver);\n this._internalMeshDataInfo._checkReadinessObserver = null;\n this.onMeshReadyObservable.notifyObservers(this);\n }\n });\n }\n }\n };\n this.onMeshReadyObservable = new Observable$1(this._internalMeshDataInfo._onMeshReadyObserverAdded);\n if (source) {\n source.onClonedObservable.notifyObservers(this);\n }\n }\n instantiateHierarchy(newParent = null, options, onNewNodeCreated) {\n const instance = this.getTotalVertices() === 0 || (options && options.doNotInstantiate && (options.doNotInstantiate === true || options.doNotInstantiate(this)))\n ? this.clone(\"Clone of \" + (this.name || this.id), newParent || this.parent, true)\n : this.createInstance(\"instance of \" + (this.name || this.id));\n instance.parent = newParent || this.parent;\n instance.position = this.position.clone();\n instance.scaling = this.scaling.clone();\n if (this.rotationQuaternion) {\n instance.rotationQuaternion = this.rotationQuaternion.clone();\n }\n else {\n instance.rotation = this.rotation.clone();\n }\n if (onNewNodeCreated) {\n onNewNodeCreated(this, instance);\n }\n for (const child of this.getChildTransformNodes(true)) {\n // instancedMesh should have a different sourced mesh\n if (child.getClassName() === \"InstancedMesh\" && instance.getClassName() === \"Mesh\" && child.sourceMesh === this) {\n child.instantiateHierarchy(instance, {\n doNotInstantiate: (options && options.doNotInstantiate) || false,\n newSourcedMesh: instance,\n }, onNewNodeCreated);\n }\n else {\n child.instantiateHierarchy(instance, options, onNewNodeCreated);\n }\n }\n return instance;\n }\n /**\n * Gets the class name\n * @returns the string \"Mesh\".\n */\n getClassName() {\n return \"Mesh\";\n }\n /** @internal */\n get _isMesh() {\n return true;\n }\n /**\n * Returns a description of this mesh\n * @param fullDetails define if full details about this mesh must be used\n * @returns a descriptive string representing this mesh\n */\n toString(fullDetails) {\n let ret = super.toString(fullDetails);\n ret += \", n vertices: \" + this.getTotalVertices();\n ret += \", parent: \" + (this._waitingParentId ? this._waitingParentId : this.parent ? this.parent.name : \"NONE\");\n if (this.animations) {\n for (let i = 0; i < this.animations.length; i++) {\n ret += \", animation[0]: \" + this.animations[i].toString(fullDetails);\n }\n }\n if (fullDetails) {\n if (this._geometry) {\n const ib = this.getIndices();\n const vb = this.getVerticesData(VertexBuffer.PositionKind);\n if (vb && ib) {\n ret += \", flat shading: \" + (vb.length / 3 === ib.length ? \"YES\" : \"NO\");\n }\n }\n else {\n ret += \", flat shading: UNKNOWN\";\n }\n }\n return ret;\n }\n /** @internal */\n _unBindEffect() {\n super._unBindEffect();\n for (const instance of this.instances) {\n instance._unBindEffect();\n }\n }\n /**\n * Gets a boolean indicating if this mesh has LOD\n */\n get hasLODLevels() {\n return this._internalMeshDataInfo._LODLevels.length > 0;\n }\n /**\n * Gets the list of MeshLODLevel associated with the current mesh\n * @returns an array of MeshLODLevel\n */\n getLODLevels() {\n return this._internalMeshDataInfo._LODLevels;\n }\n _sortLODLevels() {\n const sortingOrderFactor = this._internalMeshDataInfo._useLODScreenCoverage ? -1 : 1;\n this._internalMeshDataInfo._LODLevels.sort((a, b) => {\n if (a.distanceOrScreenCoverage < b.distanceOrScreenCoverage) {\n return sortingOrderFactor;\n }\n if (a.distanceOrScreenCoverage > b.distanceOrScreenCoverage) {\n return -sortingOrderFactor;\n }\n return 0;\n });\n }\n /**\n * Add a mesh as LOD level triggered at the given distance.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\n * @param distanceOrScreenCoverage Either distance from the center of the object to show this level or the screen coverage if `useScreenCoverage` is set to `true`.\n * If screen coverage, value is a fraction of the screen's total surface, between 0 and 1.\n * Example Playground for distance https://playground.babylonjs.com/#QE7KM#197\n * Example Playground for screen coverage https://playground.babylonjs.com/#QE7KM#196\n * @param mesh The mesh to be added as LOD level (can be null)\n * @returns This mesh (for chaining)\n */\n addLODLevel(distanceOrScreenCoverage, mesh) {\n if (mesh && mesh._masterMesh) {\n Logger.Warn(\"You cannot use a mesh as LOD level twice\");\n return this;\n }\n const level = new MeshLODLevel(distanceOrScreenCoverage, mesh);\n this._internalMeshDataInfo._LODLevels.push(level);\n if (mesh) {\n mesh._masterMesh = this;\n }\n this._sortLODLevels();\n return this;\n }\n /**\n * Returns the LOD level mesh at the passed distance or null if not found.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\n * @param distance The distance from the center of the object to show this level\n * @returns a Mesh or `null`\n */\n getLODLevelAtDistance(distance) {\n const internalDataInfo = this._internalMeshDataInfo;\n for (let index = 0; index < internalDataInfo._LODLevels.length; index++) {\n const level = internalDataInfo._LODLevels[index];\n if (level.distanceOrScreenCoverage === distance) {\n return level.mesh;\n }\n }\n return null;\n }\n /**\n * Remove a mesh from the LOD array\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\n * @param mesh defines the mesh to be removed\n * @returns This mesh (for chaining)\n */\n removeLODLevel(mesh) {\n const internalDataInfo = this._internalMeshDataInfo;\n for (let index = 0; index < internalDataInfo._LODLevels.length; index++) {\n if (internalDataInfo._LODLevels[index].mesh === mesh) {\n internalDataInfo._LODLevels.splice(index, 1);\n if (mesh) {\n mesh._masterMesh = null;\n }\n }\n }\n this._sortLODLevels();\n return this;\n }\n /**\n * Returns the registered LOD mesh distant from the parameter `camera` position if any, else returns the current mesh.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\n * @param camera defines the camera to use to compute distance\n * @param boundingSphere defines a custom bounding sphere to use instead of the one from this mesh\n * @returns This mesh (for chaining)\n */\n getLOD(camera, boundingSphere) {\n const internalDataInfo = this._internalMeshDataInfo;\n if (!internalDataInfo._LODLevels || internalDataInfo._LODLevels.length === 0) {\n return this;\n }\n const bSphere = boundingSphere || this.getBoundingInfo().boundingSphere;\n const distanceToCamera = camera.mode === Camera.ORTHOGRAPHIC_CAMERA ? camera.minZ : bSphere.centerWorld.subtract(camera.globalPosition).length();\n let compareValue = distanceToCamera;\n let compareSign = 1;\n if (internalDataInfo._useLODScreenCoverage) {\n const screenArea = camera.screenArea;\n let meshArea = (bSphere.radiusWorld * camera.minZ) / distanceToCamera;\n meshArea = meshArea * meshArea * Math.PI;\n compareValue = meshArea / screenArea;\n compareSign = -1;\n }\n if (compareSign * internalDataInfo._LODLevels[internalDataInfo._LODLevels.length - 1].distanceOrScreenCoverage > compareSign * compareValue) {\n if (this.onLODLevelSelection) {\n this.onLODLevelSelection(compareValue, this, this);\n }\n return this;\n }\n for (let index = 0; index < internalDataInfo._LODLevels.length; index++) {\n const level = internalDataInfo._LODLevels[index];\n if (compareSign * level.distanceOrScreenCoverage < compareSign * compareValue) {\n if (level.mesh) {\n if (level.mesh.delayLoadState === 4) {\n level.mesh._checkDelayState();\n return this;\n }\n if (level.mesh.delayLoadState === 2) {\n return this;\n }\n level.mesh._preActivate();\n level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\n }\n if (this.onLODLevelSelection) {\n this.onLODLevelSelection(compareValue, this, level.mesh);\n }\n return level.mesh;\n }\n }\n if (this.onLODLevelSelection) {\n this.onLODLevelSelection(compareValue, this, this);\n }\n return this;\n }\n /**\n * Gets the mesh internal Geometry object\n */\n get geometry() {\n return this._geometry;\n }\n /**\n * Returns the total number of vertices within the mesh geometry or zero if the mesh has no geometry.\n * @returns the total number of vertices\n */\n getTotalVertices() {\n if (this._geometry === null || this._geometry === undefined) {\n return 0;\n }\n return this._geometry.getTotalVertices();\n }\n /**\n * Returns the content of an associated vertex buffer\n * @param kind defines which buffer to read from (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param copyWhenShared defines a boolean indicating that if the mesh geometry is shared among some other meshes, the returned array is a copy of the internal one\n * @param forceCopy defines a boolean forcing the copy of the buffer no matter what the value of copyWhenShared is\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\n * @returns a FloatArray or null if the mesh has no geometry or no vertex buffer for this kind.\n */\n getVerticesData(kind, copyWhenShared, forceCopy, bypassInstanceData) {\n var _a, _b;\n if (!this._geometry) {\n return null;\n }\n let data = bypassInstanceData\n ? undefined\n : (_b = (_a = this._userInstancedBuffersStorage) === null || _a === void 0 ? void 0 : _a.vertexBuffers[kind]) === null || _b === void 0 ? void 0 : _b.getFloatData(this.instances.length + 1, // +1 because the master mesh is not included in the instances array\n forceCopy || (copyWhenShared && this._geometry.meshes.length !== 1));\n if (!data) {\n data = this._geometry.getVerticesData(kind, copyWhenShared, forceCopy);\n }\n return data;\n }\n /**\n * Returns the mesh VertexBuffer object from the requested `kind`\n * @param kind defines which buffer to read from (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.NormalKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\n * @returns a FloatArray or null if the mesh has no vertex buffer for this kind.\n */\n getVertexBuffer(kind, bypassInstanceData) {\n var _a, _b;\n if (!this._geometry) {\n return null;\n }\n return (_b = (bypassInstanceData ? undefined : (_a = this._userInstancedBuffersStorage) === null || _a === void 0 ? void 0 : _a.vertexBuffers[kind])) !== null && _b !== void 0 ? _b : this._geometry.getVertexBuffer(kind);\n }\n /**\n * Tests if a specific vertex buffer is associated with this mesh\n * @param kind defines which buffer to check (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.NormalKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\n * @returns a boolean\n */\n isVerticesDataPresent(kind, bypassInstanceData) {\n var _a;\n if (!this._geometry) {\n if (this._delayInfo) {\n return this._delayInfo.indexOf(kind) !== -1;\n }\n return false;\n }\n return (!bypassInstanceData && ((_a = this._userInstancedBuffersStorage) === null || _a === void 0 ? void 0 : _a.vertexBuffers[kind]) !== undefined) || this._geometry.isVerticesDataPresent(kind);\n }\n /**\n * Returns a boolean defining if the vertex data for the requested `kind` is updatable.\n * @param kind defines which buffer to check (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\n * @returns a boolean\n */\n isVertexBufferUpdatable(kind, bypassInstanceData) {\n var _a;\n if (!this._geometry) {\n if (this._delayInfo) {\n return this._delayInfo.indexOf(kind) !== -1;\n }\n return false;\n }\n if (!bypassInstanceData) {\n const buffer = (_a = this._userInstancedBuffersStorage) === null || _a === void 0 ? void 0 : _a.vertexBuffers[kind];\n if (buffer) {\n return buffer.isUpdatable();\n }\n }\n return this._geometry.isVertexBufferUpdatable(kind);\n }\n /**\n * Returns a string which contains the list of existing `kinds` of Vertex Data associated with this mesh.\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\n * @returns an array of strings\n */\n getVerticesDataKinds(bypassInstanceData) {\n if (!this._geometry) {\n const result = new Array();\n if (this._delayInfo) {\n this._delayInfo.forEach(function (kind) {\n result.push(kind);\n });\n }\n return result;\n }\n const kinds = this._geometry.getVerticesDataKinds();\n if (!bypassInstanceData && this._userInstancedBuffersStorage) {\n for (const kind in this._userInstancedBuffersStorage.vertexBuffers) {\n if (kinds.indexOf(kind) === -1) {\n kinds.push(kind);\n }\n }\n }\n return kinds;\n }\n /**\n * Returns a positive integer : the total number of indices in this mesh geometry.\n * @returns the numner of indices or zero if the mesh has no geometry.\n */\n getTotalIndices() {\n if (!this._geometry) {\n return 0;\n }\n return this._geometry.getTotalIndices();\n }\n /**\n * Returns an array of integers or a typed array (Int32Array, Uint32Array, Uint16Array) populated with the mesh indices.\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.\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\n * @returns the indices array or an empty array if the mesh has no geometry\n */\n getIndices(copyWhenShared, forceCopy) {\n if (!this._geometry) {\n return [];\n }\n return this._geometry.getIndices(copyWhenShared, forceCopy);\n }\n get isBlocked() {\n return this._masterMesh !== null && this._masterMesh !== undefined;\n }\n /**\n * Determine if the current mesh is ready to be rendered\n * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)\n * @param forceInstanceSupport will check if the mesh will be ready when used with instances (false by default)\n * @returns true if all associated assets are ready (material, textures, shaders)\n */\n isReady(completeCheck = false, forceInstanceSupport = false) {\n var _a, _b, _c, _d, _e, _f, _g;\n if (this.delayLoadState === 2) {\n return false;\n }\n if (!super.isReady(completeCheck)) {\n return false;\n }\n if (!this.subMeshes || this.subMeshes.length === 0) {\n return true;\n }\n if (!completeCheck) {\n return true;\n }\n const engine = this.getEngine();\n const scene = this.getScene();\n const hardwareInstancedRendering = forceInstanceSupport || (engine.getCaps().instancedArrays && (this.instances.length > 0 || this.hasThinInstances));\n this.computeWorldMatrix();\n const mat = this.material || scene.defaultMaterial;\n if (mat) {\n if (mat._storeEffectOnSubMeshes) {\n for (const subMesh of this.subMeshes) {\n const effectiveMaterial = subMesh.getMaterial();\n if (effectiveMaterial) {\n if (effectiveMaterial._storeEffectOnSubMeshes) {\n if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {\n return false;\n }\n }\n else {\n if (!effectiveMaterial.isReady(this, hardwareInstancedRendering)) {\n return false;\n }\n }\n }\n }\n }\n else {\n if (!mat.isReady(this, hardwareInstancedRendering)) {\n return false;\n }\n }\n }\n // Shadows\n const currentRenderPassId = engine.currentRenderPassId;\n for (const light of this.lightSources) {\n const generators = light.getShadowGenerators();\n if (!generators) {\n continue;\n }\n const iterator = generators.values();\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\n const generator = key.value;\n if (generator && (!((_a = generator.getShadowMap()) === null || _a === void 0 ? void 0 : _a.renderList) || (((_b = generator.getShadowMap()) === null || _b === void 0 ? void 0 : _b.renderList) && ((_d = (_c = generator.getShadowMap()) === null || _c === void 0 ? void 0 : _c.renderList) === null || _d === void 0 ? void 0 : _d.indexOf(this)) !== -1))) {\n const shadowMap = generator.getShadowMap();\n const renderPassIds = (_e = shadowMap.renderPassIds) !== null && _e !== void 0 ? _e : [engine.currentRenderPassId];\n for (let p = 0; p < renderPassIds.length; ++p) {\n engine.currentRenderPassId = renderPassIds[p];\n for (const subMesh of this.subMeshes) {\n if (!generator.isReady(subMesh, hardwareInstancedRendering, (_g = (_f = subMesh.getMaterial()) === null || _f === void 0 ? void 0 : _f.needAlphaBlendingForMesh(this)) !== null && _g !== void 0 ? _g : false)) {\n engine.currentRenderPassId = currentRenderPassId;\n return false;\n }\n }\n }\n engine.currentRenderPassId = currentRenderPassId;\n }\n }\n }\n // LOD\n for (const lod of this._internalMeshDataInfo._LODLevels) {\n if (lod.mesh && !lod.mesh.isReady(hardwareInstancedRendering)) {\n return false;\n }\n }\n return true;\n }\n /**\n * Gets a boolean indicating if the normals aren't to be recomputed on next mesh `positions` array update. This property is pertinent only for updatable parametric shapes.\n */\n get areNormalsFrozen() {\n return this._internalMeshDataInfo._areNormalsFrozen;\n }\n /**\n * This function affects parametric shapes on vertex position update only : ribbons, tubes, etc. It has no effect at all on other shapes. It prevents the mesh normals from being recomputed on next `positions` array update.\n * @returns the current mesh\n */\n freezeNormals() {\n this._internalMeshDataInfo._areNormalsFrozen = true;\n return this;\n }\n /**\n * This function affects parametric shapes on vertex position update only : ribbons, tubes, etc. It has no effect at all on other shapes. It reactivates the mesh normals computation if it was previously frozen\n * @returns the current mesh\n */\n unfreezeNormals() {\n this._internalMeshDataInfo._areNormalsFrozen = false;\n return this;\n }\n /**\n * Sets a value overriding the instance count. Only applicable when custom instanced InterleavedVertexBuffer are used rather than InstancedMeshs\n */\n set overridenInstanceCount(count) {\n this._instanceDataStorage.overridenInstanceCount = count;\n }\n // Methods\n /** @internal */\n _preActivate() {\n const internalDataInfo = this._internalMeshDataInfo;\n const sceneRenderId = this.getScene().getRenderId();\n if (internalDataInfo._preActivateId === sceneRenderId) {\n return this;\n }\n internalDataInfo._preActivateId = sceneRenderId;\n this._instanceDataStorage.visibleInstances = null;\n return this;\n }\n /**\n * @internal\n */\n _preActivateForIntermediateRendering(renderId) {\n if (this._instanceDataStorage.visibleInstances) {\n this._instanceDataStorage.visibleInstances.intermediateDefaultRenderId = renderId;\n }\n return this;\n }\n /**\n * @internal\n */\n _registerInstanceForRenderId(instance, renderId) {\n if (!this._instanceDataStorage.visibleInstances) {\n this._instanceDataStorage.visibleInstances = {\n defaultRenderId: renderId,\n selfDefaultRenderId: this._renderId,\n };\n }\n if (!this._instanceDataStorage.visibleInstances[renderId]) {\n if (this._instanceDataStorage.previousRenderId !== undefined && this._instanceDataStorage.isFrozen) {\n this._instanceDataStorage.visibleInstances[this._instanceDataStorage.previousRenderId] = null;\n }\n this._instanceDataStorage.previousRenderId = renderId;\n this._instanceDataStorage.visibleInstances[renderId] = new Array();\n }\n this._instanceDataStorage.visibleInstances[renderId].push(instance);\n return this;\n }\n _afterComputeWorldMatrix() {\n super._afterComputeWorldMatrix();\n if (!this.hasThinInstances) {\n return;\n }\n if (!this.doNotSyncBoundingInfo) {\n this.thinInstanceRefreshBoundingInfo(false);\n }\n }\n /** @internal */\n _postActivate() {\n if (this.edgesShareWithInstances && this.edgesRenderer && this.edgesRenderer.isEnabled && this._renderingGroup) {\n this._renderingGroup._edgesRenderers.pushNoDuplicate(this.edgesRenderer);\n this.edgesRenderer.customInstances.push(this.getWorldMatrix());\n }\n }\n /**\n * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.\n * This means the mesh underlying bounding box and sphere are recomputed.\n * @param applySkeleton defines whether to apply the skeleton before computing the bounding info\n * @param applyMorph defines whether to apply the morph target before computing the bounding info\n * @returns the current mesh\n */\n refreshBoundingInfo(applySkeleton = false, applyMorph = false) {\n if (this.hasBoundingInfo && this.getBoundingInfo().isLocked) {\n return this;\n }\n const bias = this.geometry ? this.geometry.boundingBias : null;\n this._refreshBoundingInfo(this._getPositionData(applySkeleton, applyMorph), bias);\n return this;\n }\n /**\n * @internal\n */\n _createGlobalSubMesh(force) {\n const totalVertices = this.getTotalVertices();\n if (!totalVertices || !this.getIndices()) {\n return null;\n }\n // Check if we need to recreate the submeshes\n if (this.subMeshes && this.subMeshes.length > 0) {\n const ib = this.getIndices();\n if (!ib) {\n return null;\n }\n const totalIndices = ib.length;\n let needToRecreate = false;\n if (force) {\n needToRecreate = true;\n }\n else {\n for (const submesh of this.subMeshes) {\n if (submesh.indexStart + submesh.indexCount > totalIndices) {\n needToRecreate = true;\n break;\n }\n if (submesh.verticesStart + submesh.verticesCount > totalVertices) {\n needToRecreate = true;\n break;\n }\n }\n }\n if (!needToRecreate) {\n return this.subMeshes[0];\n }\n }\n this.releaseSubMeshes();\n return new SubMesh(0, 0, totalVertices, 0, this.getTotalIndices(), this);\n }\n /**\n * This function will subdivide the mesh into multiple submeshes\n * @param count defines the expected number of submeshes\n */\n subdivide(count) {\n if (count < 1) {\n return;\n }\n const totalIndices = this.getTotalIndices();\n let subdivisionSize = (totalIndices / count) | 0;\n let offset = 0;\n // Ensure that subdivisionSize is a multiple of 3\n while (subdivisionSize % 3 !== 0) {\n subdivisionSize++;\n }\n this.releaseSubMeshes();\n for (let index = 0; index < count; index++) {\n if (offset >= totalIndices) {\n break;\n }\n SubMesh.CreateFromIndices(0, offset, index === count - 1 ? totalIndices - offset : subdivisionSize, this, undefined, false);\n offset += subdivisionSize;\n }\n this.refreshBoundingInfo();\n this.synchronizeInstances();\n }\n /**\n * Copy a FloatArray into a specific associated vertex buffer\n * @param kind defines which buffer to write to (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param data defines the data source\n * @param updatable defines if the updated vertex buffer must be flagged as updatable\n * @param stride defines the data stride size (can be null)\n * @returns the current mesh\n */\n setVerticesData(kind, data, updatable = false, stride) {\n if (!this._geometry) {\n const vertexData = new VertexData();\n vertexData.set(data, kind);\n const scene = this.getScene();\n new Geometry(Geometry.RandomId(), scene, vertexData, updatable, this);\n }\n else {\n this._geometry.setVerticesData(kind, data, updatable, stride);\n }\n return this;\n }\n /**\n * Delete a vertex buffer associated with this mesh\n * @param kind defines which buffer to delete (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n */\n removeVerticesData(kind) {\n if (!this._geometry) {\n return;\n }\n this._geometry.removeVerticesData(kind);\n }\n /**\n * Flags an associated vertex buffer as updatable\n * @param kind defines which buffer to use (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param updatable defines if the updated vertex buffer must be flagged as updatable\n */\n markVerticesDataAsUpdatable(kind, updatable = true) {\n const vb = this.getVertexBuffer(kind);\n if (!vb || vb.isUpdatable() === updatable) {\n return;\n }\n this.setVerticesData(kind, this.getVerticesData(kind), updatable);\n }\n /**\n * Sets the mesh global Vertex Buffer\n * @param buffer defines the buffer to use\n * @param disposeExistingBuffer disposes the existing buffer, if any (default: true)\n * @returns the current mesh\n */\n setVerticesBuffer(buffer, disposeExistingBuffer = true) {\n if (!this._geometry) {\n this._geometry = Geometry.CreateGeometryForMesh(this);\n }\n this._geometry.setVerticesBuffer(buffer, null, disposeExistingBuffer);\n return this;\n }\n /**\n * Update a specific associated vertex buffer\n * @param kind defines which buffer to write to (positions, indices, normals, etc). Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n * @param data defines the data source\n * @param updateExtends defines if extends info of the mesh must be updated (can be null). This is mostly useful for \"position\" kind\n * @param makeItUnique defines if the geometry associated with the mesh must be cloned to make the change only for this mesh (and not all meshes associated with the same geometry)\n * @returns the current mesh\n */\n updateVerticesData(kind, data, updateExtends, makeItUnique) {\n if (!this._geometry) {\n return this;\n }\n if (!makeItUnique) {\n this._geometry.updateVerticesData(kind, data, updateExtends);\n }\n else {\n this.makeGeometryUnique();\n this.updateVerticesData(kind, data, updateExtends, false);\n }\n return this;\n }\n /**\n * This method updates the vertex positions of an updatable mesh according to the `positionFunction` returned values.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#other-shapes-updatemeshpositions\n * @param positionFunction is a simple JS function what is passed the mesh `positions` array. It doesn't need to return anything\n * @param computeNormals is a boolean (default true) to enable/disable the mesh normal recomputation after the vertex position update\n * @returns the current mesh\n */\n updateMeshPositions(positionFunction, computeNormals = true) {\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\n if (!positions) {\n return this;\n }\n positionFunction(positions);\n this.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\n if (computeNormals) {\n const indices = this.getIndices();\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\n if (!normals) {\n return this;\n }\n VertexData.ComputeNormals(positions, indices, normals);\n this.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);\n }\n return this;\n }\n /**\n * Creates a un-shared specific occurence of the geometry for the mesh.\n * @returns the current mesh\n */\n makeGeometryUnique() {\n if (!this._geometry) {\n return this;\n }\n if (this._geometry.meshes.length === 1) {\n return this;\n }\n const oldGeometry = this._geometry;\n const geometry = this._geometry.copy(Geometry.RandomId());\n oldGeometry.releaseForMesh(this, true);\n geometry.applyToMesh(this);\n return this;\n }\n /**\n * Set the index buffer of this mesh\n * @param indices defines the source data\n * @param totalVertices defines the total number of vertices referenced by this index data (can be null)\n * @param updatable defines if the updated index buffer must be flagged as updatable (default is false)\n * @returns the current mesh\n */\n setIndices(indices, totalVertices = null, updatable = false) {\n if (!this._geometry) {\n const vertexData = new VertexData();\n vertexData.indices = indices;\n const scene = this.getScene();\n new Geometry(Geometry.RandomId(), scene, vertexData, updatable, this);\n }\n else {\n this._geometry.setIndices(indices, totalVertices, updatable);\n }\n return this;\n }\n /**\n * Update the current index buffer\n * @param indices defines the source data\n * @param offset defines the offset in the index buffer where to store the new data (can be null)\n * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)\n * @returns the current mesh\n */\n updateIndices(indices, offset, gpuMemoryOnly = false) {\n if (!this._geometry) {\n return this;\n }\n this._geometry.updateIndices(indices, offset, gpuMemoryOnly);\n return this;\n }\n /**\n * Invert the geometry to move from a right handed system to a left handed one.\n * @returns the current mesh\n */\n toLeftHanded() {\n if (!this._geometry) {\n return this;\n }\n this._geometry.toLeftHanded();\n return this;\n }\n /**\n * @internal\n */\n _bind(subMesh, effect, fillMode, allowInstancedRendering = true) {\n if (!this._geometry) {\n return this;\n }\n const engine = this.getScene().getEngine();\n // Morph targets\n if (this.morphTargetManager && this.morphTargetManager.isUsingTextureForTargets) {\n this.morphTargetManager._bind(effect);\n }\n // Wireframe\n let indexToBind;\n if (this._unIndexed) {\n indexToBind = null;\n }\n else {\n switch (this._getRenderingFillMode(fillMode)) {\n case Material.PointFillMode:\n indexToBind = null;\n break;\n case Material.WireFrameFillMode:\n indexToBind = subMesh._getLinesIndexBuffer(this.getIndices(), engine);\n break;\n default:\n case Material.TriangleFillMode:\n indexToBind = this._geometry.getIndexBuffer();\n break;\n }\n }\n // VBOs\n if (!allowInstancedRendering || !this._userInstancedBuffersStorage || this.hasThinInstances) {\n this._geometry._bind(effect, indexToBind);\n }\n else {\n this._geometry._bind(effect, indexToBind, this._userInstancedBuffersStorage.vertexBuffers, this._userInstancedBuffersStorage.vertexArrayObjects);\n }\n return this;\n }\n /**\n * @internal\n */\n _draw(subMesh, fillMode, instancesCount) {\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\n return this;\n }\n if (this._internalMeshDataInfo._onBeforeDrawObservable) {\n this._internalMeshDataInfo._onBeforeDrawObservable.notifyObservers(this);\n }\n const scene = this.getScene();\n const engine = scene.getEngine();\n if (this._unIndexed || fillMode == Material.PointFillMode) {\n // or triangles as points\n engine.drawArraysType(fillMode, subMesh.verticesStart, subMesh.verticesCount, this.forcedInstanceCount || instancesCount);\n }\n else if (fillMode == Material.WireFrameFillMode) {\n // Triangles as wireframe\n engine.drawElementsType(fillMode, 0, subMesh._linesIndexCount, this.forcedInstanceCount || instancesCount);\n }\n else {\n engine.drawElementsType(fillMode, subMesh.indexStart, subMesh.indexCount, this.forcedInstanceCount || instancesCount);\n }\n return this;\n }\n /**\n * Registers for this mesh a javascript function called just before the rendering process\n * @param func defines the function to call before rendering this mesh\n * @returns the current mesh\n */\n registerBeforeRender(func) {\n this.onBeforeRenderObservable.add(func);\n return this;\n }\n /**\n * Disposes a previously registered javascript function called before the rendering\n * @param func defines the function to remove\n * @returns the current mesh\n */\n unregisterBeforeRender(func) {\n this.onBeforeRenderObservable.removeCallback(func);\n return this;\n }\n /**\n * Registers for this mesh a javascript function called just after the rendering is complete\n * @param func defines the function to call after rendering this mesh\n * @returns the current mesh\n */\n registerAfterRender(func) {\n this.onAfterRenderObservable.add(func);\n return this;\n }\n /**\n * Disposes a previously registered javascript function called after the rendering.\n * @param func defines the function to remove\n * @returns the current mesh\n */\n unregisterAfterRender(func) {\n this.onAfterRenderObservable.removeCallback(func);\n return this;\n }\n /**\n * @internal\n */\n _getInstancesRenderList(subMeshId, isReplacementMode = false) {\n if (this._instanceDataStorage.isFrozen) {\n if (isReplacementMode) {\n this._instanceDataStorage.batchCacheReplacementModeInFrozenMode.hardwareInstancedRendering[subMeshId] = false;\n this._instanceDataStorage.batchCacheReplacementModeInFrozenMode.renderSelf[subMeshId] = true;\n return this._instanceDataStorage.batchCacheReplacementModeInFrozenMode;\n }\n if (this._instanceDataStorage.previousBatch) {\n return this._instanceDataStorage.previousBatch;\n }\n }\n const scene = this.getScene();\n const isInIntermediateRendering = scene._isInIntermediateRendering();\n const onlyForInstances = isInIntermediateRendering\n ? this._internalAbstractMeshDataInfo._onlyForInstancesIntermediate\n : this._internalAbstractMeshDataInfo._onlyForInstances;\n const batchCache = this._instanceDataStorage.batchCache;\n batchCache.mustReturn = false;\n batchCache.renderSelf[subMeshId] = isReplacementMode || (!onlyForInstances && this.isEnabled() && this.isVisible);\n batchCache.visibleInstances[subMeshId] = null;\n if (this._instanceDataStorage.visibleInstances && !isReplacementMode) {\n const visibleInstances = this._instanceDataStorage.visibleInstances;\n const currentRenderId = scene.getRenderId();\n const defaultRenderId = isInIntermediateRendering ? visibleInstances.intermediateDefaultRenderId : visibleInstances.defaultRenderId;\n batchCache.visibleInstances[subMeshId] = visibleInstances[currentRenderId];\n if (!batchCache.visibleInstances[subMeshId] && defaultRenderId) {\n batchCache.visibleInstances[subMeshId] = visibleInstances[defaultRenderId];\n }\n }\n batchCache.hardwareInstancedRendering[subMeshId] =\n !isReplacementMode &&\n this._instanceDataStorage.hardwareInstancedRendering &&\n batchCache.visibleInstances[subMeshId] !== null &&\n batchCache.visibleInstances[subMeshId] !== undefined;\n this._instanceDataStorage.previousBatch = batchCache;\n return batchCache;\n }\n /**\n * @internal\n */\n _renderWithInstances(subMesh, fillMode, batch, effect, engine) {\n var _a;\n const visibleInstances = batch.visibleInstances[subMesh._id];\n const visibleInstanceCount = visibleInstances ? visibleInstances.length : 0;\n const instanceStorage = this._instanceDataStorage;\n const currentInstancesBufferSize = instanceStorage.instancesBufferSize;\n let instancesBuffer = instanceStorage.instancesBuffer;\n let instancesPreviousBuffer = instanceStorage.instancesPreviousBuffer;\n const matricesCount = visibleInstanceCount + 1;\n const bufferSize = matricesCount * 16 * 4;\n while (instanceStorage.instancesBufferSize < bufferSize) {\n instanceStorage.instancesBufferSize *= 2;\n }\n if (!instanceStorage.instancesData || currentInstancesBufferSize != instanceStorage.instancesBufferSize) {\n instanceStorage.instancesData = new Float32Array(instanceStorage.instancesBufferSize / 4);\n }\n if ((this._scene.needsPreviousWorldMatrices && !instanceStorage.instancesPreviousData) || currentInstancesBufferSize != instanceStorage.instancesBufferSize) {\n instanceStorage.instancesPreviousData = new Float32Array(instanceStorage.instancesBufferSize / 4);\n }\n let offset = 0;\n let instancesCount = 0;\n const renderSelf = batch.renderSelf[subMesh._id];\n const needUpdateBuffer = !instancesBuffer ||\n currentInstancesBufferSize !== instanceStorage.instancesBufferSize ||\n (this._scene.needsPreviousWorldMatrices && !instanceStorage.instancesPreviousBuffer);\n if (!this._instanceDataStorage.manualUpdate && (!instanceStorage.isFrozen || needUpdateBuffer)) {\n const world = this.getWorldMatrix();\n if (renderSelf) {\n if (this._scene.needsPreviousWorldMatrices) {\n if (!instanceStorage.masterMeshPreviousWorldMatrix) {\n instanceStorage.masterMeshPreviousWorldMatrix = world.clone();\n instanceStorage.masterMeshPreviousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\n }\n else {\n instanceStorage.masterMeshPreviousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\n instanceStorage.masterMeshPreviousWorldMatrix.copyFrom(world);\n }\n }\n world.copyToArray(instanceStorage.instancesData, offset);\n offset += 16;\n instancesCount++;\n }\n if (visibleInstances) {\n if (Mesh.INSTANCEDMESH_SORT_TRANSPARENT && this._scene.activeCamera && ((_a = subMesh.getMaterial()) === null || _a === void 0 ? void 0 : _a.needAlphaBlendingForMesh(subMesh.getRenderingMesh()))) {\n const cameraPosition = this._scene.activeCamera.globalPosition;\n for (let instanceIndex = 0; instanceIndex < visibleInstances.length; instanceIndex++) {\n const instanceMesh = visibleInstances[instanceIndex];\n instanceMesh._distanceToCamera = Vector3.Distance(instanceMesh.getBoundingInfo().boundingSphere.centerWorld, cameraPosition);\n }\n visibleInstances.sort((m1, m2) => {\n return m1._distanceToCamera > m2._distanceToCamera ? -1 : m1._distanceToCamera < m2._distanceToCamera ? 1 : 0;\n });\n }\n for (let instanceIndex = 0; instanceIndex < visibleInstances.length; instanceIndex++) {\n const instance = visibleInstances[instanceIndex];\n const matrix = instance.getWorldMatrix();\n matrix.copyToArray(instanceStorage.instancesData, offset);\n if (this._scene.needsPreviousWorldMatrices) {\n if (!instance._previousWorldMatrix) {\n instance._previousWorldMatrix = matrix.clone();\n instance._previousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\n }\n else {\n instance._previousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\n instance._previousWorldMatrix.copyFrom(matrix);\n }\n }\n offset += 16;\n instancesCount++;\n }\n }\n }\n else {\n instancesCount = (renderSelf ? 1 : 0) + visibleInstanceCount;\n }\n if (needUpdateBuffer) {\n if (instancesBuffer) {\n instancesBuffer.dispose();\n }\n if (instancesPreviousBuffer) {\n instancesPreviousBuffer.dispose();\n }\n instancesBuffer = new Buffer$1(engine, instanceStorage.instancesData, true, 16, false, true);\n instanceStorage.instancesBuffer = instancesBuffer;\n if (!this._userInstancedBuffersStorage) {\n this._userInstancedBuffersStorage = {\n data: {},\n vertexBuffers: {},\n strides: {},\n sizes: {},\n vertexArrayObjects: this.getEngine().getCaps().vertexArrayObject ? {} : undefined,\n };\n }\n this._userInstancedBuffersStorage.vertexBuffers[\"world0\"] = instancesBuffer.createVertexBuffer(\"world0\", 0, 4);\n this._userInstancedBuffersStorage.vertexBuffers[\"world1\"] = instancesBuffer.createVertexBuffer(\"world1\", 4, 4);\n this._userInstancedBuffersStorage.vertexBuffers[\"world2\"] = instancesBuffer.createVertexBuffer(\"world2\", 8, 4);\n this._userInstancedBuffersStorage.vertexBuffers[\"world3\"] = instancesBuffer.createVertexBuffer(\"world3\", 12, 4);\n if (this._scene.needsPreviousWorldMatrices) {\n instancesPreviousBuffer = new Buffer$1(engine, instanceStorage.instancesPreviousData, true, 16, false, true);\n instanceStorage.instancesPreviousBuffer = instancesPreviousBuffer;\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld0\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld0\", 0, 4);\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld1\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld1\", 4, 4);\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld2\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld2\", 8, 4);\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld3\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld3\", 12, 4);\n }\n this._invalidateInstanceVertexArrayObject();\n }\n else {\n if (!this._instanceDataStorage.isFrozen || this._instanceDataStorage.forceMatrixUpdates) {\n instancesBuffer.updateDirectly(instanceStorage.instancesData, 0, instancesCount);\n if (this._scene.needsPreviousWorldMatrices && (!this._instanceDataStorage.manualUpdate || this._instanceDataStorage.previousManualUpdate)) {\n instancesPreviousBuffer.updateDirectly(instanceStorage.instancesPreviousData, 0, instancesCount);\n }\n }\n }\n this._processInstancedBuffers(visibleInstances, renderSelf);\n // Stats\n this.getScene()._activeIndices.addCount(subMesh.indexCount * instancesCount, false);\n // Draw\n if (engine._currentDrawContext) {\n engine._currentDrawContext.useInstancing = true;\n }\n this._bind(subMesh, effect, fillMode);\n this._draw(subMesh, fillMode, instancesCount);\n // Write current matrices as previous matrices in case of manual update\n // Default behaviour when previous matrices are not specified explicitly\n // Will break if instances number/order changes\n if (this._scene.needsPreviousWorldMatrices &&\n !needUpdateBuffer &&\n this._instanceDataStorage.manualUpdate &&\n (!this._instanceDataStorage.isFrozen || this._instanceDataStorage.forceMatrixUpdates) &&\n !this._instanceDataStorage.previousManualUpdate) {\n instancesPreviousBuffer.updateDirectly(instanceStorage.instancesData, 0, instancesCount);\n }\n engine.unbindInstanceAttributes();\n return this;\n }\n /**\n * @internal\n */\n _renderWithThinInstances(subMesh, fillMode, effect, engine) {\n var _a, _b;\n // Stats\n const instancesCount = (_b = (_a = this._thinInstanceDataStorage) === null || _a === void 0 ? void 0 : _a.instancesCount) !== null && _b !== void 0 ? _b : 0;\n this.getScene()._activeIndices.addCount(subMesh.indexCount * instancesCount, false);\n // Draw\n if (engine._currentDrawContext) {\n engine._currentDrawContext.useInstancing = true;\n }\n this._bind(subMesh, effect, fillMode);\n this._draw(subMesh, fillMode, instancesCount);\n // Write current matrices as previous matrices\n // Default behaviour when previous matrices are not specified explicitly\n // Will break if instances number/order changes\n if (this._scene.needsPreviousWorldMatrices && !this._thinInstanceDataStorage.previousMatrixData && this._thinInstanceDataStorage.matrixData) {\n if (!this._thinInstanceDataStorage.previousMatrixBuffer) {\n this._thinInstanceDataStorage.previousMatrixBuffer = this._thinInstanceCreateMatrixBuffer(\"previousWorld\", this._thinInstanceDataStorage.matrixData, false);\n }\n else {\n this._thinInstanceDataStorage.previousMatrixBuffer.updateDirectly(this._thinInstanceDataStorage.matrixData, 0, instancesCount);\n }\n }\n engine.unbindInstanceAttributes();\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _processInstancedBuffers(visibleInstances, renderSelf) {\n // Do nothing\n }\n /**\n * @internal\n */\n _processRendering(renderingMesh, subMesh, effect, fillMode, batch, hardwareInstancedRendering, onBeforeDraw, effectiveMaterial) {\n const scene = this.getScene();\n const engine = scene.getEngine();\n fillMode = this._getRenderingFillMode(fillMode);\n if (hardwareInstancedRendering && subMesh.getRenderingMesh().hasThinInstances) {\n this._renderWithThinInstances(subMesh, fillMode, effect, engine);\n return this;\n }\n if (hardwareInstancedRendering) {\n this._renderWithInstances(subMesh, fillMode, batch, effect, engine);\n }\n else {\n if (engine._currentDrawContext) {\n engine._currentDrawContext.useInstancing = false;\n }\n let instanceCount = 0;\n if (batch.renderSelf[subMesh._id]) {\n // Draw\n if (onBeforeDraw) {\n onBeforeDraw(false, renderingMesh.getWorldMatrix(), effectiveMaterial);\n }\n instanceCount++;\n this._draw(subMesh, fillMode, this._instanceDataStorage.overridenInstanceCount);\n }\n const visibleInstancesForSubMesh = batch.visibleInstances[subMesh._id];\n if (visibleInstancesForSubMesh) {\n const visibleInstanceCount = visibleInstancesForSubMesh.length;\n instanceCount += visibleInstanceCount;\n // Stats\n for (let instanceIndex = 0; instanceIndex < visibleInstanceCount; instanceIndex++) {\n const instance = visibleInstancesForSubMesh[instanceIndex];\n // World\n const world = instance.getWorldMatrix();\n if (onBeforeDraw) {\n onBeforeDraw(true, world, effectiveMaterial);\n }\n // Draw\n this._draw(subMesh, fillMode);\n }\n }\n // Stats\n scene._activeIndices.addCount(subMesh.indexCount * instanceCount, false);\n }\n return this;\n }\n /**\n * @internal\n */\n _rebuild(dispose = false) {\n if (this._instanceDataStorage.instancesBuffer) {\n // Dispose instance buffer to be recreated in _renderWithInstances when rendered\n if (dispose) {\n this._instanceDataStorage.instancesBuffer.dispose();\n }\n this._instanceDataStorage.instancesBuffer = null;\n }\n if (this._userInstancedBuffersStorage) {\n for (const kind in this._userInstancedBuffersStorage.vertexBuffers) {\n const buffer = this._userInstancedBuffersStorage.vertexBuffers[kind];\n if (buffer) {\n // Dispose instance buffer to be recreated in _renderWithInstances when rendered\n if (dispose) {\n buffer.dispose();\n }\n this._userInstancedBuffersStorage.vertexBuffers[kind] = null;\n }\n }\n if (this._userInstancedBuffersStorage.vertexArrayObjects) {\n this._userInstancedBuffersStorage.vertexArrayObjects = {};\n }\n }\n this._internalMeshDataInfo._effectiveMaterial = null;\n super._rebuild(dispose);\n }\n /** @internal */\n _freeze() {\n if (!this.subMeshes) {\n return;\n }\n // Prepare batches\n for (let index = 0; index < this.subMeshes.length; index++) {\n this._getInstancesRenderList(index);\n }\n this._internalMeshDataInfo._effectiveMaterial = null;\n this._instanceDataStorage.isFrozen = true;\n }\n /** @internal */\n _unFreeze() {\n this._instanceDataStorage.isFrozen = false;\n this._instanceDataStorage.previousBatch = null;\n }\n /**\n * Triggers the draw call for the mesh. Usually, you don't need to call this method by your own because the mesh rendering is handled by the scene rendering manager\n * @param subMesh defines the subMesh to render\n * @param enableAlphaMode defines if alpha mode can be changed\n * @param effectiveMeshReplacement defines an optional mesh used to provide info for the rendering\n * @returns the current mesh\n */\n render(subMesh, enableAlphaMode, effectiveMeshReplacement) {\n var _a, _b, _c;\n const scene = this.getScene();\n if (this._internalAbstractMeshDataInfo._isActiveIntermediate) {\n this._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n }\n else {\n this._internalAbstractMeshDataInfo._isActive = false;\n }\n if (this._checkOcclusionQuery() && !this._occlusionDataStorage.forceRenderingWhenOccluded) {\n return this;\n }\n // Managing instances\n const batch = this._getInstancesRenderList(subMesh._id, !!effectiveMeshReplacement);\n if (batch.mustReturn) {\n return this;\n }\n // Checking geometry state\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\n return this;\n }\n const engine = scene.getEngine();\n let oldCameraMaxZ = 0;\n let oldCamera = null;\n if (this.ignoreCameraMaxZ && scene.activeCamera && !scene._isInIntermediateRendering()) {\n oldCameraMaxZ = scene.activeCamera.maxZ;\n oldCamera = scene.activeCamera;\n scene.activeCamera.maxZ = 0;\n scene.updateTransformMatrix(true);\n }\n if (this._internalMeshDataInfo._onBeforeRenderObservable) {\n this._internalMeshDataInfo._onBeforeRenderObservable.notifyObservers(this);\n }\n const renderingMesh = subMesh.getRenderingMesh();\n const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] ||\n renderingMesh.hasThinInstances ||\n (!!this._userInstancedBuffersStorage && !subMesh.getMesh()._internalAbstractMeshDataInfo._actAsRegularMesh);\n const instanceDataStorage = this._instanceDataStorage;\n const material = subMesh.getMaterial();\n if (!material) {\n if (oldCamera) {\n oldCamera.maxZ = oldCameraMaxZ;\n scene.updateTransformMatrix(true);\n }\n return this;\n }\n // Material\n if (!instanceDataStorage.isFrozen || !this._internalMeshDataInfo._effectiveMaterial || this._internalMeshDataInfo._effectiveMaterial !== material) {\n if (material._storeEffectOnSubMeshes) {\n if (!material.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {\n if (oldCamera) {\n oldCamera.maxZ = oldCameraMaxZ;\n scene.updateTransformMatrix(true);\n }\n return this;\n }\n }\n else if (!material.isReady(this, hardwareInstancedRendering)) {\n if (oldCamera) {\n oldCamera.maxZ = oldCameraMaxZ;\n scene.updateTransformMatrix(true);\n }\n return this;\n }\n this._internalMeshDataInfo._effectiveMaterial = material;\n }\n else if ((material._storeEffectOnSubMeshes && !((_a = subMesh.effect) === null || _a === void 0 ? void 0 : _a._wasPreviouslyReady)) ||\n (!material._storeEffectOnSubMeshes && !((_b = material.getEffect()) === null || _b === void 0 ? void 0 : _b._wasPreviouslyReady))) {\n if (oldCamera) {\n oldCamera.maxZ = oldCameraMaxZ;\n scene.updateTransformMatrix(true);\n }\n return this;\n }\n // Alpha mode\n if (enableAlphaMode) {\n engine.setAlphaMode(this._internalMeshDataInfo._effectiveMaterial.alphaMode);\n }\n let drawWrapper;\n if (this._internalMeshDataInfo._effectiveMaterial._storeEffectOnSubMeshes) {\n drawWrapper = subMesh._drawWrapper;\n }\n else {\n drawWrapper = this._internalMeshDataInfo._effectiveMaterial._getDrawWrapper();\n }\n const effect = (_c = drawWrapper === null || drawWrapper === void 0 ? void 0 : drawWrapper.effect) !== null && _c !== void 0 ? _c : null;\n for (const step of scene._beforeRenderingMeshStage) {\n step.action(this, subMesh, batch, effect);\n }\n if (!drawWrapper || !effect) {\n if (oldCamera) {\n oldCamera.maxZ = oldCameraMaxZ;\n scene.updateTransformMatrix(true);\n }\n return this;\n }\n const effectiveMesh = effectiveMeshReplacement || this;\n let sideOrientation;\n if (!instanceDataStorage.isFrozen && (this._internalMeshDataInfo._effectiveMaterial.backFaceCulling || this.overrideMaterialSideOrientation !== null)) {\n const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();\n sideOrientation = this.overrideMaterialSideOrientation;\n if (sideOrientation == null) {\n sideOrientation = this._internalMeshDataInfo._effectiveMaterial.sideOrientation;\n }\n if (mainDeterminant < 0) {\n sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;\n }\n instanceDataStorage.sideOrientation = sideOrientation;\n }\n else {\n sideOrientation = instanceDataStorage.sideOrientation;\n }\n const reverse = this._internalMeshDataInfo._effectiveMaterial._preBind(drawWrapper, sideOrientation);\n if (this._internalMeshDataInfo._effectiveMaterial.forceDepthWrite) {\n engine.setDepthWrite(true);\n }\n // Bind\n const effectiveMaterial = this._internalMeshDataInfo._effectiveMaterial;\n const fillMode = effectiveMaterial.fillMode;\n if (this._internalMeshDataInfo._onBeforeBindObservable) {\n this._internalMeshDataInfo._onBeforeBindObservable.notifyObservers(this);\n }\n if (!hardwareInstancedRendering) {\n // Binding will be done later because we need to add more info to the VB\n this._bind(subMesh, effect, fillMode, false);\n }\n const world = effectiveMesh.getWorldMatrix();\n if (effectiveMaterial._storeEffectOnSubMeshes) {\n effectiveMaterial.bindForSubMesh(world, this, subMesh);\n }\n else {\n effectiveMaterial.bind(world, this);\n }\n if (!effectiveMaterial.backFaceCulling && effectiveMaterial.separateCullingPass) {\n engine.setState(true, effectiveMaterial.zOffset, false, !reverse, effectiveMaterial.cullBackFaces, effectiveMaterial.stencil, effectiveMaterial.zOffsetUnits);\n this._processRendering(this, subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, this._internalMeshDataInfo._effectiveMaterial);\n engine.setState(true, effectiveMaterial.zOffset, false, reverse, effectiveMaterial.cullBackFaces, effectiveMaterial.stencil, effectiveMaterial.zOffsetUnits);\n if (this._internalMeshDataInfo._onBetweenPassObservable) {\n this._internalMeshDataInfo._onBetweenPassObservable.notifyObservers(subMesh);\n }\n }\n // Draw\n this._processRendering(this, subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, this._internalMeshDataInfo._effectiveMaterial);\n // Unbind\n this._internalMeshDataInfo._effectiveMaterial.unbind();\n for (const step of scene._afterRenderingMeshStage) {\n step.action(this, subMesh, batch, effect);\n }\n if (this._internalMeshDataInfo._onAfterRenderObservable) {\n this._internalMeshDataInfo._onAfterRenderObservable.notifyObservers(this);\n }\n if (oldCamera) {\n oldCamera.maxZ = oldCameraMaxZ;\n scene.updateTransformMatrix(true);\n }\n if (scene.performancePriority === ScenePerformancePriority.Aggressive && !instanceDataStorage.isFrozen) {\n this._freeze();\n }\n return this;\n }\n /**\n * Renormalize the mesh and patch it up if there are no weights\n * Similar to normalization by adding the weights compute the reciprocal and multiply all elements, this wil ensure that everything adds to 1.\n * However in the case of zero weights then we set just a single influence to 1.\n * We check in the function for extra's present and if so we use the normalizeSkinWeightsWithExtras rather than the FourWeights version.\n */\n cleanMatrixWeights() {\n if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\n if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsExtraKind)) {\n this._normalizeSkinWeightsAndExtra();\n }\n else {\n this._normalizeSkinFourWeights();\n }\n }\n }\n // faster 4 weight version.\n _normalizeSkinFourWeights() {\n const matricesWeights = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\n const numWeights = matricesWeights.length;\n for (let a = 0; a < numWeights; a += 4) {\n // accumulate weights\n const t = matricesWeights[a] + matricesWeights[a + 1] + matricesWeights[a + 2] + matricesWeights[a + 3];\n // check for invalid weight and just set it to 1.\n if (t === 0) {\n matricesWeights[a] = 1;\n }\n else {\n // renormalize so everything adds to 1 use reciprocal\n const recip = 1 / t;\n matricesWeights[a] *= recip;\n matricesWeights[a + 1] *= recip;\n matricesWeights[a + 2] *= recip;\n matricesWeights[a + 3] *= recip;\n }\n }\n this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);\n }\n // handle special case of extra verts. (in theory gltf can handle 12 influences)\n _normalizeSkinWeightsAndExtra() {\n const matricesWeightsExtra = this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind);\n const matricesWeights = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\n const numWeights = matricesWeights.length;\n for (let a = 0; a < numWeights; a += 4) {\n // accumulate weights\n let t = matricesWeights[a] + matricesWeights[a + 1] + matricesWeights[a + 2] + matricesWeights[a + 3];\n t += matricesWeightsExtra[a] + matricesWeightsExtra[a + 1] + matricesWeightsExtra[a + 2] + matricesWeightsExtra[a + 3];\n // check for invalid weight and just set it to 1.\n if (t === 0) {\n matricesWeights[a] = 1;\n }\n else {\n // renormalize so everything adds to 1 use reciprocal\n const recip = 1 / t;\n matricesWeights[a] *= recip;\n matricesWeights[a + 1] *= recip;\n matricesWeights[a + 2] *= recip;\n matricesWeights[a + 3] *= recip;\n // same goes for extras\n matricesWeightsExtra[a] *= recip;\n matricesWeightsExtra[a + 1] *= recip;\n matricesWeightsExtra[a + 2] *= recip;\n matricesWeightsExtra[a + 3] *= recip;\n }\n }\n this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);\n this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsExtra);\n }\n /**\n * ValidateSkinning is used to determine that a mesh has valid skinning data along with skin metrics, if missing weights,\n * or not normalized it is returned as invalid mesh the string can be used for console logs, or on screen messages to let\n * the user know there was an issue with importing the mesh\n * @returns a validation object with skinned, valid and report string\n */\n validateSkinning() {\n const matricesWeightsExtra = this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind);\n const matricesWeights = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\n if (matricesWeights === null || this.skeleton == null) {\n return { skinned: false, valid: true, report: \"not skinned\" };\n }\n const numWeights = matricesWeights.length;\n let numberNotSorted = 0;\n let missingWeights = 0;\n let maxUsedWeights = 0;\n let numberNotNormalized = 0;\n const numInfluences = matricesWeightsExtra === null ? 4 : 8;\n const usedWeightCounts = new Array();\n for (let a = 0; a <= numInfluences; a++) {\n usedWeightCounts[a] = 0;\n }\n const toleranceEpsilon = 0.001;\n for (let a = 0; a < numWeights; a += 4) {\n let lastWeight = matricesWeights[a];\n let t = lastWeight;\n let usedWeights = t === 0 ? 0 : 1;\n for (let b = 1; b < numInfluences; b++) {\n const d = b < 4 ? matricesWeights[a + b] : matricesWeightsExtra[a + b - 4];\n if (d > lastWeight) {\n numberNotSorted++;\n }\n if (d !== 0) {\n usedWeights++;\n }\n t += d;\n lastWeight = d;\n }\n // count the buffer weights usage\n usedWeightCounts[usedWeights]++;\n // max influences\n if (usedWeights > maxUsedWeights) {\n maxUsedWeights = usedWeights;\n }\n // check for invalid weight and just set it to 1.\n if (t === 0) {\n missingWeights++;\n }\n else {\n // renormalize so everything adds to 1 use reciprocal\n const recip = 1 / t;\n let tolerance = 0;\n for (let b = 0; b < numInfluences; b++) {\n if (b < 4) {\n tolerance += Math.abs(matricesWeights[a + b] - matricesWeights[a + b] * recip);\n }\n else {\n tolerance += Math.abs(matricesWeightsExtra[a + b - 4] - matricesWeightsExtra[a + b - 4] * recip);\n }\n }\n // arbitrary epsilon value for dictating not normalized\n if (tolerance > toleranceEpsilon) {\n numberNotNormalized++;\n }\n }\n }\n // validate bone indices are in range of the skeleton\n const numBones = this.skeleton.bones.length;\n const matricesIndices = this.getVerticesData(VertexBuffer.MatricesIndicesKind);\n const matricesIndicesExtra = this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);\n let numBadBoneIndices = 0;\n for (let a = 0; a < numWeights; a += 4) {\n for (let b = 0; b < numInfluences; b++) {\n const index = b < 4 ? matricesIndices[a + b] : matricesIndicesExtra[a + b - 4];\n if (index >= numBones || index < 0) {\n numBadBoneIndices++;\n }\n }\n }\n // log mesh stats\n const output = \"Number of Weights = \" +\n numWeights / 4 +\n \"\\nMaximum influences = \" +\n maxUsedWeights +\n \"\\nMissing Weights = \" +\n missingWeights +\n \"\\nNot Sorted = \" +\n numberNotSorted +\n \"\\nNot Normalized = \" +\n numberNotNormalized +\n \"\\nWeightCounts = [\" +\n usedWeightCounts +\n \"]\" +\n \"\\nNumber of bones = \" +\n numBones +\n \"\\nBad Bone Indices = \" +\n numBadBoneIndices;\n return { skinned: true, valid: missingWeights === 0 && numberNotNormalized === 0 && numBadBoneIndices === 0, report: output };\n }\n /** @internal */\n _checkDelayState() {\n const scene = this.getScene();\n if (this._geometry) {\n this._geometry.load(scene);\n }\n else if (this.delayLoadState === 4) {\n this.delayLoadState = 2;\n this._queueLoad(scene);\n }\n return this;\n }\n _queueLoad(scene) {\n scene.addPendingData(this);\n const getBinaryData = this.delayLoadingFile.indexOf(\".babylonbinarymeshdata\") !== -1;\n Tools.LoadFile(this.delayLoadingFile, (data) => {\n if (data instanceof ArrayBuffer) {\n this._delayLoadingFunction(data, this);\n }\n else {\n this._delayLoadingFunction(JSON.parse(data), this);\n }\n this.instances.forEach((instance) => {\n instance.refreshBoundingInfo();\n instance._syncSubMeshes();\n });\n this.delayLoadState = 1;\n scene.removePendingData(this);\n }, () => { }, scene.offlineProvider, getBinaryData);\n return this;\n }\n /**\n * Returns `true` if the mesh is within the frustum defined by the passed array of planes.\n * A mesh is in the frustum if its bounding box intersects the frustum\n * @param frustumPlanes defines the frustum to test\n * @returns true if the mesh is in the frustum planes\n */\n isInFrustum(frustumPlanes) {\n if (this.delayLoadState === 2) {\n return false;\n }\n if (!super.isInFrustum(frustumPlanes)) {\n return false;\n }\n this._checkDelayState();\n return true;\n }\n /**\n * Sets the mesh material by the material or multiMaterial `id` property\n * @param id is a string identifying the material or the multiMaterial\n * @returns the current mesh\n */\n setMaterialById(id) {\n const materials = this.getScene().materials;\n let index;\n for (index = materials.length - 1; index > -1; index--) {\n if (materials[index].id === id) {\n this.material = materials[index];\n return this;\n }\n }\n // Multi\n const multiMaterials = this.getScene().multiMaterials;\n for (index = multiMaterials.length - 1; index > -1; index--) {\n if (multiMaterials[index].id === id) {\n this.material = multiMaterials[index];\n return this;\n }\n }\n return this;\n }\n /**\n * Returns as a new array populated with the mesh material and/or skeleton, if any.\n * @returns an array of IAnimatable\n */\n getAnimatables() {\n const results = new Array();\n if (this.material) {\n results.push(this.material);\n }\n if (this.skeleton) {\n results.push(this.skeleton);\n }\n return results;\n }\n /**\n * Modifies the mesh geometry according to the passed transformation matrix.\n * This method returns nothing, but it really modifies the mesh even if it's originally not set as updatable.\n * The mesh normals are modified using the same transformation.\n * Note that, under the hood, this method sets a new VertexBuffer each call.\n * @param transform defines the transform matrix to use\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/bakingTransforms\n * @returns the current mesh\n */\n bakeTransformIntoVertices(transform) {\n // Position\n if (!this.isVerticesDataPresent(VertexBuffer.PositionKind)) {\n return this;\n }\n const submeshes = this.subMeshes.splice(0);\n this._resetPointsArrayCache();\n let data = this.getVerticesData(VertexBuffer.PositionKind);\n const temp = Vector3.Zero();\n let index;\n for (index = 0; index < data.length; index += 3) {\n Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp).toArray(data, index);\n }\n this.setVerticesData(VertexBuffer.PositionKind, data, this.getVertexBuffer(VertexBuffer.PositionKind).isUpdatable());\n // Normals\n if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n data = this.getVerticesData(VertexBuffer.NormalKind);\n for (index = 0; index < data.length; index += 3) {\n Vector3.TransformNormalFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp)\n .normalize()\n .toArray(data, index);\n }\n this.setVerticesData(VertexBuffer.NormalKind, data, this.getVertexBuffer(VertexBuffer.NormalKind).isUpdatable());\n }\n // flip faces?\n if (transform.determinant() < 0) {\n this.flipFaces();\n }\n // Restore submeshes\n this.releaseSubMeshes();\n this.subMeshes = submeshes;\n return this;\n }\n /**\n * Modifies the mesh geometry according to its own current World Matrix.\n * The mesh World Matrix is then reset.\n * This method returns nothing but really modifies the mesh even if it's originally not set as updatable.\n * Note that, under the hood, this method sets a new VertexBuffer each call.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/bakingTransforms\n * @param bakeIndependentlyOfChildren indicates whether to preserve all child nodes' World Matrix during baking\n * @returns the current mesh\n */\n bakeCurrentTransformIntoVertices(bakeIndependentlyOfChildren = true) {\n this.bakeTransformIntoVertices(this.computeWorldMatrix(true));\n this.resetLocalMatrix(bakeIndependentlyOfChildren);\n return this;\n }\n // Cache\n /** @internal */\n get _positions() {\n if (this._internalAbstractMeshDataInfo._positions) {\n return this._internalAbstractMeshDataInfo._positions;\n }\n if (this._geometry) {\n return this._geometry._positions;\n }\n return null;\n }\n /** @internal */\n _resetPointsArrayCache() {\n if (this._geometry) {\n this._geometry._resetPointsArrayCache();\n }\n return this;\n }\n /** @internal */\n _generatePointsArray() {\n if (this._geometry) {\n return this._geometry._generatePointsArray();\n }\n return false;\n }\n /**\n * Returns a new Mesh object generated from the current mesh properties.\n * This method must not get confused with createInstance()\n * @param name is a string, the name given to the new mesh\n * @param newParent can be any Node object (default `null`)\n * @param doNotCloneChildren allows/denies the recursive cloning of the original mesh children if any (default `false`)\n * @param clonePhysicsImpostor allows/denies the cloning in the same time of the original mesh `body` used by the physics engine, if any (default `true`)\n * @returns a new mesh\n */\n clone(name = \"\", newParent = null, doNotCloneChildren, clonePhysicsImpostor = true) {\n return new Mesh(name, this.getScene(), newParent, this, doNotCloneChildren, clonePhysicsImpostor);\n }\n /**\n * Releases resources associated with this mesh.\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n this.morphTargetManager = null;\n if (this._geometry) {\n this._geometry.releaseForMesh(this, true);\n }\n const internalDataInfo = this._internalMeshDataInfo;\n if (internalDataInfo._onBeforeDrawObservable) {\n internalDataInfo._onBeforeDrawObservable.clear();\n }\n if (internalDataInfo._onBeforeBindObservable) {\n internalDataInfo._onBeforeBindObservable.clear();\n }\n if (internalDataInfo._onBeforeRenderObservable) {\n internalDataInfo._onBeforeRenderObservable.clear();\n }\n if (internalDataInfo._onAfterRenderObservable) {\n internalDataInfo._onAfterRenderObservable.clear();\n }\n if (internalDataInfo._onBetweenPassObservable) {\n internalDataInfo._onBetweenPassObservable.clear();\n }\n // Sources\n if (this._scene.useClonedMeshMap) {\n if (internalDataInfo.meshMap) {\n for (const uniqueId in internalDataInfo.meshMap) {\n const mesh = internalDataInfo.meshMap[uniqueId];\n if (mesh) {\n mesh._internalMeshDataInfo._source = null;\n internalDataInfo.meshMap[uniqueId] = undefined;\n }\n }\n }\n if (internalDataInfo._source && internalDataInfo._source._internalMeshDataInfo.meshMap) {\n internalDataInfo._source._internalMeshDataInfo.meshMap[this.uniqueId] = undefined;\n }\n }\n else {\n const meshes = this.getScene().meshes;\n for (const abstractMesh of meshes) {\n const mesh = abstractMesh;\n if (mesh._internalMeshDataInfo && mesh._internalMeshDataInfo._source && mesh._internalMeshDataInfo._source === this) {\n mesh._internalMeshDataInfo._source = null;\n }\n }\n }\n internalDataInfo._source = null;\n this._instanceDataStorage.visibleInstances = {};\n // Instances\n this._disposeInstanceSpecificData();\n // Thin instances\n this._disposeThinInstanceSpecificData();\n if (this._internalMeshDataInfo._checkReadinessObserver) {\n this._scene.onBeforeRenderObservable.remove(this._internalMeshDataInfo._checkReadinessObserver);\n }\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n /** @internal */\n _disposeInstanceSpecificData() {\n // Do nothing\n }\n /** @internal */\n _disposeThinInstanceSpecificData() {\n // Do nothing\n }\n /** @internal */\n _invalidateInstanceVertexArrayObject() {\n // Do nothing\n }\n /**\n * Modifies the mesh geometry according to a displacement map.\n * A displacement map is a colored image. Each pixel color value (actually a gradient computed from red, green, blue values) will give the displacement to apply to each mesh vertex.\n * The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated.\n * @param url is a string, the URL from the image file is to be downloaded.\n * @param minHeight is the lower limit of the displacement.\n * @param maxHeight is the upper limit of the displacement.\n * @param onSuccess is an optional Javascript function to be called just after the mesh is modified. It is passed the modified mesh and must return nothing.\n * @param uvOffset is an optional vector2 used to offset UV.\n * @param uvScale is an optional vector2 used to scale UV.\n * @param forceUpdate defines whether or not to force an update of the generated buffers. This is useful to apply on a deserialized model for instance.\n * @returns the Mesh.\n */\n applyDisplacementMap(url, minHeight, maxHeight, onSuccess, uvOffset, uvScale, forceUpdate = false) {\n const scene = this.getScene();\n const onload = (img) => {\n // Getting height map data\n const heightMapWidth = img.width;\n const heightMapHeight = img.height;\n const canvas = this.getEngine().createCanvas(heightMapWidth, heightMapHeight);\n const context = canvas.getContext(\"2d\");\n context.drawImage(img, 0, 0);\n // Create VertexData from map data\n //Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949\n const buffer = context.getImageData(0, 0, heightMapWidth, heightMapHeight).data;\n this.applyDisplacementMapFromBuffer(buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight, uvOffset, uvScale, forceUpdate);\n //execute success callback, if set\n if (onSuccess) {\n onSuccess(this);\n }\n };\n Tools.LoadImage(url, onload, () => { }, scene.offlineProvider);\n return this;\n }\n /**\n * Modifies the mesh geometry according to a displacementMap buffer.\n * A displacement map is a colored image. Each pixel color value (actually a gradient computed from red, green, blue values) will give the displacement to apply to each mesh vertex.\n * The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated.\n * @param buffer is a `Uint8Array` buffer containing series of `Uint8` lower than 255, the red, green, blue and alpha values of each successive pixel.\n * @param heightMapWidth is the width of the buffer image.\n * @param heightMapHeight is the height of the buffer image.\n * @param minHeight is the lower limit of the displacement.\n * @param maxHeight is the upper limit of the displacement.\n * @param uvOffset is an optional vector2 used to offset UV.\n * @param uvScale is an optional vector2 used to scale UV.\n * @param forceUpdate defines whether or not to force an update of the generated buffers. This is useful to apply on a deserialized model for instance.\n * @returns the Mesh.\n */\n applyDisplacementMapFromBuffer(buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight, uvOffset, uvScale, forceUpdate = false) {\n if (!this.isVerticesDataPresent(VertexBuffer.PositionKind) || !this.isVerticesDataPresent(VertexBuffer.NormalKind) || !this.isVerticesDataPresent(VertexBuffer.UVKind)) {\n Logger.Warn(\"Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing\");\n return this;\n }\n const positions = this.getVerticesData(VertexBuffer.PositionKind, true, true);\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\n const uvs = this.getVerticesData(VertexBuffer.UVKind);\n let position = Vector3.Zero();\n const normal = Vector3.Zero();\n const uv = Vector2.Zero();\n uvOffset = uvOffset || Vector2.Zero();\n uvScale = uvScale || new Vector2(1, 1);\n for (let index = 0; index < positions.length; index += 3) {\n Vector3.FromArrayToRef(positions, index, position);\n Vector3.FromArrayToRef(normals, index, normal);\n Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);\n // Compute height\n const u = (Math.abs(uv.x * uvScale.x + (uvOffset.x % 1)) * (heightMapWidth - 1)) % heightMapWidth | 0;\n const v = (Math.abs(uv.y * uvScale.y + (uvOffset.y % 1)) * (heightMapHeight - 1)) % heightMapHeight | 0;\n const pos = (u + v * heightMapWidth) * 4;\n const r = buffer[pos] / 255.0;\n const g = buffer[pos + 1] / 255.0;\n const b = buffer[pos + 2] / 255.0;\n const gradient = r * 0.3 + g * 0.59 + b * 0.11;\n normal.normalize();\n normal.scaleInPlace(minHeight + (maxHeight - minHeight) * gradient);\n position = position.add(normal);\n position.toArray(positions, index);\n }\n VertexData.ComputeNormals(positions, this.getIndices(), normals);\n if (forceUpdate) {\n this.setVerticesData(VertexBuffer.PositionKind, positions);\n this.setVerticesData(VertexBuffer.NormalKind, normals);\n this.setVerticesData(VertexBuffer.UVKind, uvs);\n }\n else {\n this.updateVerticesData(VertexBuffer.PositionKind, positions);\n this.updateVerticesData(VertexBuffer.NormalKind, normals);\n }\n return this;\n }\n _getFlattenedNormals(indices, positions) {\n const normals = new Float32Array(indices.length * 3);\n let normalsCount = 0;\n // Decide if normals should be flipped\n const flipNormalGeneration = this.overrideMaterialSideOrientation ===\n (this._scene.useRightHandedSystem ? 1 : 0);\n // Generate new normals\n for (let index = 0; index < indices.length; index += 3) {\n const p1 = Vector3.FromArray(positions, indices[index] * 3);\n const p2 = Vector3.FromArray(positions, indices[index + 1] * 3);\n const p3 = Vector3.FromArray(positions, indices[index + 2] * 3);\n const p1p2 = p1.subtract(p2);\n const p3p2 = p3.subtract(p2);\n const normal = Vector3.Normalize(Vector3.Cross(p1p2, p3p2));\n if (flipNormalGeneration) {\n normal.scaleInPlace(-1);\n }\n // Store same normals for every vertex\n for (let localIndex = 0; localIndex < 3; localIndex++) {\n normals[normalsCount++] = normal.x;\n normals[normalsCount++] = normal.y;\n normals[normalsCount++] = normal.z;\n }\n }\n return normals;\n }\n _convertToUnIndexedMesh(flattenNormals = false) {\n const kinds = this.getVerticesDataKinds();\n const indices = this.getIndices();\n const data = {};\n const separateVertices = (data, stride) => {\n const newData = new Float32Array(indices.length * stride);\n let count = 0;\n for (let index = 0; index < indices.length; index++) {\n for (let offset = 0; offset < stride; offset++) {\n newData[count++] = data[indices[index] * stride + offset];\n }\n }\n return newData;\n };\n // Save previous submeshes\n const previousSubmeshes = this.geometry ? this.subMeshes.slice(0) : [];\n // Cache vertex data\n for (const kind of kinds) {\n data[kind] = this.getVerticesData(kind);\n }\n // Update vertex data\n for (const kind of kinds) {\n const vertexBuffer = this.getVertexBuffer(kind);\n const stride = vertexBuffer.getStrideSize();\n if (flattenNormals && kind === VertexBuffer.NormalKind) {\n const normals = this._getFlattenedNormals(indices, data[VertexBuffer.PositionKind]);\n this.setVerticesData(VertexBuffer.NormalKind, normals, vertexBuffer.isUpdatable(), stride);\n }\n else {\n this.setVerticesData(kind, separateVertices(data[kind], stride), vertexBuffer.isUpdatable(), stride);\n }\n }\n // Update morph targets\n if (this.morphTargetManager) {\n for (let targetIndex = 0; targetIndex < this.morphTargetManager.numTargets; targetIndex++) {\n const target = this.morphTargetManager.getTarget(targetIndex);\n const positions = target.getPositions();\n target.setPositions(separateVertices(positions, 3));\n const normals = target.getNormals();\n if (normals) {\n target.setNormals(flattenNormals ? this._getFlattenedNormals(indices, positions) : separateVertices(normals, 3));\n }\n const tangents = target.getTangents();\n if (tangents) {\n target.setTangents(separateVertices(tangents, 3));\n }\n const uvs = target.getUVs();\n if (uvs) {\n target.setUVs(separateVertices(uvs, 2));\n }\n }\n this.morphTargetManager.synchronize();\n }\n // Update indices\n for (let index = 0; index < indices.length; index++) {\n indices[index] = index;\n }\n this.setIndices(indices);\n this._unIndexed = true;\n // Update submeshes\n this.releaseSubMeshes();\n for (const previousOne of previousSubmeshes) {\n SubMesh.AddToMesh(previousOne.materialIndex, previousOne.indexStart, previousOne.indexCount, previousOne.indexStart, previousOne.indexCount, this);\n }\n this.synchronizeInstances();\n return this;\n }\n /**\n * Modify the mesh to get a flat shading rendering.\n * This means each mesh facet will then have its own normals. Usually new vertices are added in the mesh geometry to get this result.\n * Warning : the mesh is really modified even if not set originally as updatable and, under the hood, a new VertexBuffer is allocated.\n * @returns current mesh\n */\n convertToFlatShadedMesh() {\n return this._convertToUnIndexedMesh(true);\n }\n /**\n * This method removes all the mesh indices and add new vertices (duplication) in order to unfold facets into buffers.\n * In other words, more vertices, no more indices and a single bigger VBO.\n * The mesh is really modified even if not set originally as updatable. Under the hood, a new VertexBuffer is allocated.\n * @returns current mesh\n */\n convertToUnIndexedMesh() {\n return this._convertToUnIndexedMesh();\n }\n /**\n * Inverses facet orientations.\n * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.\n * @param flipNormals will also inverts the normals\n * @returns current mesh\n */\n flipFaces(flipNormals = false) {\n const vertex_data = VertexData.ExtractFromMesh(this);\n let i;\n if (flipNormals && this.isVerticesDataPresent(VertexBuffer.NormalKind) && vertex_data.normals) {\n for (i = 0; i < vertex_data.normals.length; i++) {\n vertex_data.normals[i] *= -1;\n }\n }\n if (vertex_data.indices) {\n let temp;\n for (i = 0; i < vertex_data.indices.length; i += 3) {\n // reassign indices\n temp = vertex_data.indices[i + 1];\n vertex_data.indices[i + 1] = vertex_data.indices[i + 2];\n vertex_data.indices[i + 2] = temp;\n }\n }\n vertex_data.applyToMesh(this, this.isVertexBufferUpdatable(VertexBuffer.PositionKind));\n return this;\n }\n /**\n * Increase the number of facets and hence vertices in a mesh\n * Vertex normals are interpolated from existing vertex normals\n * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.\n * @param numberPerEdge the number of new vertices to add to each edge of a facet, optional default 1\n */\n increaseVertices(numberPerEdge = 1) {\n const vertex_data = VertexData.ExtractFromMesh(this);\n const currentIndices = vertex_data.indices && !Array.isArray(vertex_data.indices) && Array.from ? Array.from(vertex_data.indices) : vertex_data.indices;\n const positions = vertex_data.positions && !Array.isArray(vertex_data.positions) && Array.from ? Array.from(vertex_data.positions) : vertex_data.positions;\n const uvs = vertex_data.uvs && !Array.isArray(vertex_data.uvs) && Array.from ? Array.from(vertex_data.uvs) : vertex_data.uvs;\n const normals = vertex_data.normals && !Array.isArray(vertex_data.normals) && Array.from ? Array.from(vertex_data.normals) : vertex_data.normals;\n if (!currentIndices || !positions) {\n Logger.Warn(\"Couldn't increase number of vertices : VertexData must contain at least indices and positions\");\n }\n else {\n vertex_data.indices = currentIndices;\n vertex_data.positions = positions;\n if (uvs) {\n vertex_data.uvs = uvs;\n }\n if (normals) {\n vertex_data.normals = normals;\n }\n const segments = numberPerEdge + 1; //segments per current facet edge, become sides of new facets\n const tempIndices = new Array();\n for (let i = 0; i < segments + 1; i++) {\n tempIndices[i] = new Array();\n }\n let a; //vertex index of one end of a side\n let b; //vertex index of other end of the side\n const deltaPosition = new Vector3(0, 0, 0);\n const deltaNormal = new Vector3(0, 0, 0);\n const deltaUV = new Vector2(0, 0);\n const indices = new Array();\n const vertexIndex = new Array();\n const side = new Array();\n let len;\n let positionPtr = positions.length;\n let uvPtr;\n if (uvs) {\n uvPtr = uvs.length;\n }\n let normalsPtr;\n if (normals) {\n normalsPtr = normals.length;\n }\n for (let i = 0; i < currentIndices.length; i += 3) {\n vertexIndex[0] = currentIndices[i];\n vertexIndex[1] = currentIndices[i + 1];\n vertexIndex[2] = currentIndices[i + 2];\n for (let j = 0; j < 3; j++) {\n a = vertexIndex[j];\n b = vertexIndex[(j + 1) % 3];\n if (side[a] === undefined && side[b] === undefined) {\n side[a] = new Array();\n side[b] = new Array();\n }\n else {\n if (side[a] === undefined) {\n side[a] = new Array();\n }\n if (side[b] === undefined) {\n side[b] = new Array();\n }\n }\n if (side[a][b] === undefined && side[b][a] === undefined) {\n side[a][b] = [];\n deltaPosition.x = (positions[3 * b] - positions[3 * a]) / segments;\n deltaPosition.y = (positions[3 * b + 1] - positions[3 * a + 1]) / segments;\n deltaPosition.z = (positions[3 * b + 2] - positions[3 * a + 2]) / segments;\n if (normals) {\n deltaNormal.x = (normals[3 * b] - normals[3 * a]) / segments;\n deltaNormal.y = (normals[3 * b + 1] - normals[3 * a + 1]) / segments;\n deltaNormal.z = (normals[3 * b + 2] - normals[3 * a + 2]) / segments;\n }\n if (uvs) {\n deltaUV.x = (uvs[2 * b] - uvs[2 * a]) / segments;\n deltaUV.y = (uvs[2 * b + 1] - uvs[2 * a + 1]) / segments;\n }\n side[a][b].push(a);\n for (let k = 1; k < segments; k++) {\n side[a][b].push(positions.length / 3);\n positions[positionPtr++] = positions[3 * a] + k * deltaPosition.x;\n positions[positionPtr++] = positions[3 * a + 1] + k * deltaPosition.y;\n positions[positionPtr++] = positions[3 * a + 2] + k * deltaPosition.z;\n if (normals) {\n normals[normalsPtr++] = normals[3 * a] + k * deltaNormal.x;\n normals[normalsPtr++] = normals[3 * a + 1] + k * deltaNormal.y;\n normals[normalsPtr++] = normals[3 * a + 2] + k * deltaNormal.z;\n }\n if (uvs) {\n uvs[uvPtr++] = uvs[2 * a] + k * deltaUV.x;\n uvs[uvPtr++] = uvs[2 * a + 1] + k * deltaUV.y;\n }\n }\n side[a][b].push(b);\n side[b][a] = new Array();\n len = side[a][b].length;\n for (let idx = 0; idx < len; idx++) {\n side[b][a][idx] = side[a][b][len - 1 - idx];\n }\n }\n }\n //Calculate positions, normals and uvs of new internal vertices\n tempIndices[0][0] = currentIndices[i];\n tempIndices[1][0] = side[currentIndices[i]][currentIndices[i + 1]][1];\n tempIndices[1][1] = side[currentIndices[i]][currentIndices[i + 2]][1];\n for (let k = 2; k < segments; k++) {\n tempIndices[k][0] = side[currentIndices[i]][currentIndices[i + 1]][k];\n tempIndices[k][k] = side[currentIndices[i]][currentIndices[i + 2]][k];\n deltaPosition.x = (positions[3 * tempIndices[k][k]] - positions[3 * tempIndices[k][0]]) / k;\n deltaPosition.y = (positions[3 * tempIndices[k][k] + 1] - positions[3 * tempIndices[k][0] + 1]) / k;\n deltaPosition.z = (positions[3 * tempIndices[k][k] + 2] - positions[3 * tempIndices[k][0] + 2]) / k;\n if (normals) {\n deltaNormal.x = (normals[3 * tempIndices[k][k]] - normals[3 * tempIndices[k][0]]) / k;\n deltaNormal.y = (normals[3 * tempIndices[k][k] + 1] - normals[3 * tempIndices[k][0] + 1]) / k;\n deltaNormal.z = (normals[3 * tempIndices[k][k] + 2] - normals[3 * tempIndices[k][0] + 2]) / k;\n }\n if (uvs) {\n deltaUV.x = (uvs[2 * tempIndices[k][k]] - uvs[2 * tempIndices[k][0]]) / k;\n deltaUV.y = (uvs[2 * tempIndices[k][k] + 1] - uvs[2 * tempIndices[k][0] + 1]) / k;\n }\n for (let j = 1; j < k; j++) {\n tempIndices[k][j] = positions.length / 3;\n positions[positionPtr++] = positions[3 * tempIndices[k][0]] + j * deltaPosition.x;\n positions[positionPtr++] = positions[3 * tempIndices[k][0] + 1] + j * deltaPosition.y;\n positions[positionPtr++] = positions[3 * tempIndices[k][0] + 2] + j * deltaPosition.z;\n if (normals) {\n normals[normalsPtr++] = normals[3 * tempIndices[k][0]] + j * deltaNormal.x;\n normals[normalsPtr++] = normals[3 * tempIndices[k][0] + 1] + j * deltaNormal.y;\n normals[normalsPtr++] = normals[3 * tempIndices[k][0] + 2] + j * deltaNormal.z;\n }\n if (uvs) {\n uvs[uvPtr++] = uvs[2 * tempIndices[k][0]] + j * deltaUV.x;\n uvs[uvPtr++] = uvs[2 * tempIndices[k][0] + 1] + j * deltaUV.y;\n }\n }\n }\n tempIndices[segments] = side[currentIndices[i + 1]][currentIndices[i + 2]];\n // reform indices\n indices.push(tempIndices[0][0], tempIndices[1][0], tempIndices[1][1]);\n for (let k = 1; k < segments; k++) {\n let j;\n for (j = 0; j < k; j++) {\n indices.push(tempIndices[k][j], tempIndices[k + 1][j], tempIndices[k + 1][j + 1]);\n indices.push(tempIndices[k][j], tempIndices[k + 1][j + 1], tempIndices[k][j + 1]);\n }\n indices.push(tempIndices[k][j], tempIndices[k + 1][j], tempIndices[k + 1][j + 1]);\n }\n }\n vertex_data.indices = indices;\n vertex_data.applyToMesh(this, this.isVertexBufferUpdatable(VertexBuffer.PositionKind));\n }\n }\n /**\n * Force adjacent facets to share vertices and remove any facets that have all vertices in a line\n * This will undo any application of covertToFlatShadedMesh\n * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.\n */\n forceSharedVertices() {\n const vertex_data = VertexData.ExtractFromMesh(this);\n const currentUVs = vertex_data.uvs;\n const currentIndices = vertex_data.indices;\n const currentPositions = vertex_data.positions;\n const currentColors = vertex_data.colors;\n const currentMatrixIndices = vertex_data.matricesIndices;\n const currentMatrixWeights = vertex_data.matricesWeights;\n const currentMatrixIndicesExtra = vertex_data.matricesIndicesExtra;\n const currentMatrixWeightsExtra = vertex_data.matricesWeightsExtra;\n if (currentIndices === void 0 || currentPositions === void 0 || currentIndices === null || currentPositions === null) {\n Logger.Warn(\"VertexData contains empty entries\");\n }\n else {\n const positions = new Array();\n const indices = new Array();\n const uvs = new Array();\n const colors = new Array();\n const matrixIndices = new Array();\n const matrixWeights = new Array();\n const matrixIndicesExtra = new Array();\n const matrixWeightsExtra = new Array();\n let pstring = new Array(); //lists facet vertex positions (a,b,c) as string \"a|b|c\"\n let indexPtr = 0; // pointer to next available index value\n const uniquePositions = {}; // unique vertex positions\n let ptr; // pointer to element in uniquePositions\n let facet;\n for (let i = 0; i < currentIndices.length; i += 3) {\n facet = [currentIndices[i], currentIndices[i + 1], currentIndices[i + 2]]; //facet vertex indices\n pstring = new Array();\n for (let j = 0; j < 3; j++) {\n pstring[j] = \"\";\n for (let k = 0; k < 3; k++) {\n //small values make 0\n if (Math.abs(currentPositions[3 * facet[j] + k]) < 0.00000001) {\n currentPositions[3 * facet[j] + k] = 0;\n }\n pstring[j] += currentPositions[3 * facet[j] + k] + \"|\";\n }\n }\n //check facet vertices to see that none are repeated\n // do not process any facet that has a repeated vertex, ie is a line\n if (!(pstring[0] == pstring[1] || pstring[0] == pstring[2] || pstring[1] == pstring[2])) {\n //for each facet position check if already listed in uniquePositions\n // if not listed add to uniquePositions and set index pointer\n // if listed use its index in uniquePositions and new index pointer\n for (let j = 0; j < 3; j++) {\n ptr = uniquePositions[pstring[j]];\n if (ptr === undefined) {\n uniquePositions[pstring[j]] = indexPtr;\n ptr = indexPtr++;\n //not listed so add individual x, y, z coordinates to positions\n for (let k = 0; k < 3; k++) {\n positions.push(currentPositions[3 * facet[j] + k]);\n }\n if (currentColors !== null && currentColors !== void 0) {\n for (let k = 0; k < 4; k++) {\n colors.push(currentColors[4 * facet[j] + k]);\n }\n }\n if (currentUVs !== null && currentUVs !== void 0) {\n for (let k = 0; k < 2; k++) {\n uvs.push(currentUVs[2 * facet[j] + k]);\n }\n }\n if (currentMatrixIndices !== null && currentMatrixIndices !== void 0) {\n for (let k = 0; k < 4; k++) {\n matrixIndices.push(currentMatrixIndices[4 * facet[j] + k]);\n }\n }\n if (currentMatrixWeights !== null && currentMatrixWeights !== void 0) {\n for (let k = 0; k < 4; k++) {\n matrixWeights.push(currentMatrixWeights[4 * facet[j] + k]);\n }\n }\n if (currentMatrixIndicesExtra !== null && currentMatrixIndicesExtra !== void 0) {\n for (let k = 0; k < 4; k++) {\n matrixIndicesExtra.push(currentMatrixIndicesExtra[4 * facet[j] + k]);\n }\n }\n if (currentMatrixWeightsExtra !== null && currentMatrixWeightsExtra !== void 0) {\n for (let k = 0; k < 4; k++) {\n matrixWeightsExtra.push(currentMatrixWeightsExtra[4 * facet[j] + k]);\n }\n }\n }\n // add new index pointer to indices array\n indices.push(ptr);\n }\n }\n }\n const normals = new Array();\n VertexData.ComputeNormals(positions, indices, normals);\n //create new vertex data object and update\n vertex_data.positions = positions;\n vertex_data.indices = indices;\n vertex_data.normals = normals;\n if (currentUVs !== null && currentUVs !== void 0) {\n vertex_data.uvs = uvs;\n }\n if (currentColors !== null && currentColors !== void 0) {\n vertex_data.colors = colors;\n }\n if (currentMatrixIndices !== null && currentMatrixIndices !== void 0) {\n vertex_data.matricesIndices = matrixIndices;\n }\n if (currentMatrixWeights !== null && currentMatrixWeights !== void 0) {\n vertex_data.matricesWeights = matrixWeights;\n }\n if (currentMatrixIndicesExtra !== null && currentMatrixIndicesExtra !== void 0) {\n vertex_data.matricesIndicesExtra = matrixIndicesExtra;\n }\n if (currentMatrixWeights !== null && currentMatrixWeights !== void 0) {\n vertex_data.matricesWeightsExtra = matrixWeightsExtra;\n }\n vertex_data.applyToMesh(this, this.isVertexBufferUpdatable(VertexBuffer.PositionKind));\n }\n }\n // Instances\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/naming-convention\n static _instancedMeshFactory(name, mesh) {\n throw _WarnImport(\"InstancedMesh\");\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static _PhysicsImpostorParser(scene, physicObject, jsonObject) {\n throw _WarnImport(\"PhysicsImpostor\");\n }\n /**\n * Creates a new InstancedMesh object from the mesh model.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\n * @param name defines the name of the new instance\n * @returns a new InstancedMesh\n */\n createInstance(name) {\n return Mesh._instancedMeshFactory(name, this);\n }\n /**\n * Synchronises all the mesh instance submeshes to the current mesh submeshes, if any.\n * After this call, all the mesh instances have the same submeshes than the current mesh.\n * @returns the current mesh\n */\n synchronizeInstances() {\n for (let instanceIndex = 0; instanceIndex < this.instances.length; instanceIndex++) {\n const instance = this.instances[instanceIndex];\n instance._syncSubMeshes();\n }\n return this;\n }\n /**\n * Optimization of the mesh's indices, in case a mesh has duplicated vertices.\n * The function will only reorder the indices and will not remove unused vertices to avoid problems with submeshes.\n * This should be used together with the simplification to avoid disappearing triangles.\n * @param successCallback an optional success callback to be called after the optimization finished.\n * @returns the current mesh\n */\n optimizeIndices(successCallback) {\n const indices = this.getIndices();\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\n if (!positions || !indices) {\n return this;\n }\n const vectorPositions = new Array();\n for (let pos = 0; pos < positions.length; pos = pos + 3) {\n vectorPositions.push(Vector3.FromArray(positions, pos));\n }\n const dupes = new Array();\n AsyncLoop.SyncAsyncForLoop(vectorPositions.length, 40, (iteration) => {\n const realPos = vectorPositions.length - 1 - iteration;\n const testedPosition = vectorPositions[realPos];\n for (let j = 0; j < realPos; ++j) {\n const againstPosition = vectorPositions[j];\n if (testedPosition.equals(againstPosition)) {\n dupes[realPos] = j;\n break;\n }\n }\n }, () => {\n for (let i = 0; i < indices.length; ++i) {\n indices[i] = dupes[indices[i]] || indices[i];\n }\n //indices are now reordered\n const originalSubMeshes = this.subMeshes.slice(0);\n this.setIndices(indices);\n this.subMeshes = originalSubMeshes;\n if (successCallback) {\n successCallback(this);\n }\n });\n return this;\n }\n /**\n * Serialize current mesh\n * @param serializationObject defines the object which will receive the serialization data\n */\n serialize(serializationObject = {}) {\n serializationObject.name = this.name;\n serializationObject.id = this.id;\n serializationObject.uniqueId = this.uniqueId;\n serializationObject.type = this.getClassName();\n if (Tags && Tags.HasTags(this)) {\n serializationObject.tags = Tags.GetTags(this);\n }\n serializationObject.position = this.position.asArray();\n if (this.rotationQuaternion) {\n serializationObject.rotationQuaternion = this.rotationQuaternion.asArray();\n }\n else if (this.rotation) {\n serializationObject.rotation = this.rotation.asArray();\n }\n serializationObject.scaling = this.scaling.asArray();\n if (this._postMultiplyPivotMatrix) {\n serializationObject.pivotMatrix = this.getPivotMatrix().asArray();\n }\n else {\n serializationObject.localMatrix = this.getPivotMatrix().asArray();\n }\n serializationObject.isEnabled = this.isEnabled(false);\n serializationObject.isVisible = this.isVisible;\n serializationObject.infiniteDistance = this.infiniteDistance;\n serializationObject.pickable = this.isPickable;\n serializationObject.receiveShadows = this.receiveShadows;\n serializationObject.billboardMode = this.billboardMode;\n serializationObject.visibility = this.visibility;\n serializationObject.checkCollisions = this.checkCollisions;\n serializationObject.isBlocker = this.isBlocker;\n serializationObject.overrideMaterialSideOrientation = this.overrideMaterialSideOrientation;\n // Parent\n if (this.parent) {\n this.parent._serializeAsParent(serializationObject);\n }\n // Geometry\n serializationObject.isUnIndexed = this.isUnIndexed;\n const geometry = this._geometry;\n if (geometry && this.subMeshes) {\n serializationObject.geometryUniqueId = geometry.uniqueId;\n serializationObject.geometryId = geometry.id;\n // SubMeshes\n serializationObject.subMeshes = [];\n for (let subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {\n const subMesh = this.subMeshes[subIndex];\n serializationObject.subMeshes.push({\n materialIndex: subMesh.materialIndex,\n verticesStart: subMesh.verticesStart,\n verticesCount: subMesh.verticesCount,\n indexStart: subMesh.indexStart,\n indexCount: subMesh.indexCount,\n });\n }\n }\n // Material\n if (this.material) {\n if (!this.material.doNotSerialize) {\n serializationObject.materialUniqueId = this.material.uniqueId;\n serializationObject.materialId = this.material.id; // back compat\n }\n }\n else {\n this.material = null;\n serializationObject.materialUniqueId = this._scene.defaultMaterial.uniqueId;\n serializationObject.materialId = this._scene.defaultMaterial.id; // back compat\n }\n // Morph targets\n if (this.morphTargetManager) {\n serializationObject.morphTargetManagerId = this.morphTargetManager.uniqueId;\n }\n // Skeleton\n if (this.skeleton) {\n serializationObject.skeletonId = this.skeleton.id;\n serializationObject.numBoneInfluencers = this.numBoneInfluencers;\n }\n // Physics\n //TODO implement correct serialization for physics impostors.\n if (this.getScene()._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE)) {\n const impostor = this.getPhysicsImpostor();\n if (impostor) {\n serializationObject.physicsMass = impostor.getParam(\"mass\");\n serializationObject.physicsFriction = impostor.getParam(\"friction\");\n serializationObject.physicsRestitution = impostor.getParam(\"mass\");\n serializationObject.physicsImpostor = impostor.type;\n }\n }\n // Metadata\n if (this.metadata) {\n serializationObject.metadata = this.metadata;\n }\n // Instances\n serializationObject.instances = [];\n for (let index = 0; index < this.instances.length; index++) {\n const instance = this.instances[index];\n if (instance.doNotSerialize) {\n continue;\n }\n const serializationInstance = {\n name: instance.name,\n id: instance.id,\n isEnabled: instance.isEnabled(false),\n isVisible: instance.isVisible,\n isPickable: instance.isPickable,\n checkCollisions: instance.checkCollisions,\n position: instance.position.asArray(),\n scaling: instance.scaling.asArray(),\n };\n if (instance.parent) {\n instance.parent._serializeAsParent(serializationInstance);\n }\n if (instance.rotationQuaternion) {\n serializationInstance.rotationQuaternion = instance.rotationQuaternion.asArray();\n }\n else if (instance.rotation) {\n serializationInstance.rotation = instance.rotation.asArray();\n }\n // Physics\n //TODO implement correct serialization for physics impostors.\n if (this.getScene()._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE)) {\n const impostor = instance.getPhysicsImpostor();\n if (impostor) {\n serializationInstance.physicsMass = impostor.getParam(\"mass\");\n serializationInstance.physicsFriction = impostor.getParam(\"friction\");\n serializationInstance.physicsRestitution = impostor.getParam(\"mass\");\n serializationInstance.physicsImpostor = impostor.type;\n }\n }\n // Metadata\n if (instance.metadata) {\n serializationInstance.metadata = instance.metadata;\n }\n // Action Manager\n if (instance.actionManager) {\n serializationInstance.actions = instance.actionManager.serialize(instance.name);\n }\n serializationObject.instances.push(serializationInstance);\n // Animations\n SerializationHelper.AppendSerializedAnimations(instance, serializationInstance);\n serializationInstance.ranges = instance.serializeAnimationRanges();\n }\n // Thin instances\n if (this._thinInstanceDataStorage.instancesCount && this._thinInstanceDataStorage.matrixData) {\n serializationObject.thinInstances = {\n instancesCount: this._thinInstanceDataStorage.instancesCount,\n matrixData: Array.from(this._thinInstanceDataStorage.matrixData),\n matrixBufferSize: this._thinInstanceDataStorage.matrixBufferSize,\n enablePicking: this.thinInstanceEnablePicking,\n };\n if (this._userThinInstanceBuffersStorage) {\n const userThinInstance = {\n data: {},\n sizes: {},\n strides: {},\n };\n for (const kind in this._userThinInstanceBuffersStorage.data) {\n userThinInstance.data[kind] = Array.from(this._userThinInstanceBuffersStorage.data[kind]);\n userThinInstance.sizes[kind] = this._userThinInstanceBuffersStorage.sizes[kind];\n userThinInstance.strides[kind] = this._userThinInstanceBuffersStorage.strides[kind];\n }\n serializationObject.thinInstances.userThinInstance = userThinInstance;\n }\n }\n // Animations\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\n serializationObject.ranges = this.serializeAnimationRanges();\n // Layer mask\n serializationObject.layerMask = this.layerMask;\n // Alpha\n serializationObject.alphaIndex = this.alphaIndex;\n serializationObject.hasVertexAlpha = this.hasVertexAlpha;\n // Overlay\n serializationObject.overlayAlpha = this.overlayAlpha;\n serializationObject.overlayColor = this.overlayColor.asArray();\n serializationObject.renderOverlay = this.renderOverlay;\n // Fog\n serializationObject.applyFog = this.applyFog;\n // Action Manager\n if (this.actionManager) {\n serializationObject.actions = this.actionManager.serialize(this.name);\n }\n return serializationObject;\n }\n /** @internal */\n _syncGeometryWithMorphTargetManager() {\n if (!this.geometry) {\n return;\n }\n this._markSubMeshesAsAttributesDirty();\n const morphTargetManager = this._internalAbstractMeshDataInfo._morphTargetManager;\n if (morphTargetManager && morphTargetManager.vertexCount) {\n if (morphTargetManager.vertexCount !== this.getTotalVertices()) {\n Logger.Error(\"Mesh is incompatible with morph targets. Targets and mesh must all have the same vertices count.\");\n this.morphTargetManager = null;\n return;\n }\n if (morphTargetManager.isUsingTextureForTargets) {\n return;\n }\n for (let index = 0; index < morphTargetManager.numInfluencers; index++) {\n const morphTarget = morphTargetManager.getActiveTarget(index);\n const positions = morphTarget.getPositions();\n if (!positions) {\n Logger.Error(\"Invalid morph target. Target must have positions.\");\n return;\n }\n this.geometry.setVerticesData(VertexBuffer.PositionKind + index, positions, false, 3);\n const normals = morphTarget.getNormals();\n if (normals) {\n this.geometry.setVerticesData(VertexBuffer.NormalKind + index, normals, false, 3);\n }\n const tangents = morphTarget.getTangents();\n if (tangents) {\n this.geometry.setVerticesData(VertexBuffer.TangentKind + index, tangents, false, 3);\n }\n const uvs = morphTarget.getUVs();\n if (uvs) {\n this.geometry.setVerticesData(VertexBuffer.UVKind + \"_\" + index, uvs, false, 2);\n }\n }\n }\n else {\n let index = 0;\n // Positions\n while (this.geometry.isVerticesDataPresent(VertexBuffer.PositionKind + index)) {\n this.geometry.removeVerticesData(VertexBuffer.PositionKind + index);\n if (this.geometry.isVerticesDataPresent(VertexBuffer.NormalKind + index)) {\n this.geometry.removeVerticesData(VertexBuffer.NormalKind + index);\n }\n if (this.geometry.isVerticesDataPresent(VertexBuffer.TangentKind + index)) {\n this.geometry.removeVerticesData(VertexBuffer.TangentKind + index);\n }\n if (this.geometry.isVerticesDataPresent(VertexBuffer.UVKind + index)) {\n this.geometry.removeVerticesData(VertexBuffer.UVKind + \"_\" + index);\n }\n index++;\n }\n }\n }\n /**\n * Returns a new Mesh object parsed from the source provided.\n * @param parsedMesh is the source\n * @param scene defines the hosting scene\n * @param rootUrl is the root URL to prefix the `delayLoadingFile` property with\n * @returns a new Mesh\n */\n static Parse(parsedMesh, scene, rootUrl) {\n let mesh;\n if (parsedMesh.type && parsedMesh.type === \"LinesMesh\") {\n mesh = Mesh._LinesMeshParser(parsedMesh, scene);\n }\n else if (parsedMesh.type && parsedMesh.type === \"GroundMesh\") {\n mesh = Mesh._GroundMeshParser(parsedMesh, scene);\n }\n else if (parsedMesh.type && parsedMesh.type === \"GoldbergMesh\") {\n mesh = Mesh._GoldbergMeshParser(parsedMesh, scene);\n }\n else if (parsedMesh.type && parsedMesh.type === \"GreasedLineMesh\") {\n mesh = Mesh._GreasedLineMeshParser(parsedMesh, scene);\n }\n else if (parsedMesh.type && parsedMesh.type === \"TrailMesh\") {\n mesh = Mesh._TrailMeshParser(parsedMesh, scene);\n }\n else {\n mesh = new Mesh(parsedMesh.name, scene);\n }\n mesh.id = parsedMesh.id;\n mesh._waitingParsedUniqueId = parsedMesh.uniqueId;\n if (Tags) {\n Tags.AddTagsTo(mesh, parsedMesh.tags);\n }\n mesh.position = Vector3.FromArray(parsedMesh.position);\n if (parsedMesh.metadata !== undefined) {\n mesh.metadata = parsedMesh.metadata;\n }\n if (parsedMesh.rotationQuaternion) {\n mesh.rotationQuaternion = Quaternion.FromArray(parsedMesh.rotationQuaternion);\n }\n else if (parsedMesh.rotation) {\n mesh.rotation = Vector3.FromArray(parsedMesh.rotation);\n }\n mesh.scaling = Vector3.FromArray(parsedMesh.scaling);\n if (parsedMesh.localMatrix) {\n mesh.setPreTransformMatrix(Matrix.FromArray(parsedMesh.localMatrix));\n }\n else if (parsedMesh.pivotMatrix) {\n mesh.setPivotMatrix(Matrix.FromArray(parsedMesh.pivotMatrix));\n }\n mesh.setEnabled(parsedMesh.isEnabled);\n mesh.isVisible = parsedMesh.isVisible;\n mesh.infiniteDistance = parsedMesh.infiniteDistance;\n mesh.showBoundingBox = parsedMesh.showBoundingBox;\n mesh.showSubMeshesBoundingBox = parsedMesh.showSubMeshesBoundingBox;\n if (parsedMesh.applyFog !== undefined) {\n mesh.applyFog = parsedMesh.applyFog;\n }\n if (parsedMesh.pickable !== undefined) {\n mesh.isPickable = parsedMesh.pickable;\n }\n if (parsedMesh.alphaIndex !== undefined) {\n mesh.alphaIndex = parsedMesh.alphaIndex;\n }\n mesh.receiveShadows = parsedMesh.receiveShadows;\n if (parsedMesh.billboardMode !== undefined) {\n mesh.billboardMode = parsedMesh.billboardMode;\n }\n if (parsedMesh.visibility !== undefined) {\n mesh.visibility = parsedMesh.visibility;\n }\n mesh.checkCollisions = parsedMesh.checkCollisions;\n mesh.overrideMaterialSideOrientation = parsedMesh.overrideMaterialSideOrientation;\n if (parsedMesh.isBlocker !== undefined) {\n mesh.isBlocker = parsedMesh.isBlocker;\n }\n mesh._shouldGenerateFlatShading = parsedMesh.useFlatShading;\n // freezeWorldMatrix\n if (parsedMesh.freezeWorldMatrix) {\n mesh._waitingData.freezeWorldMatrix = parsedMesh.freezeWorldMatrix;\n }\n // Parent\n if (parsedMesh.parentId !== undefined) {\n mesh._waitingParentId = parsedMesh.parentId;\n }\n if (parsedMesh.parentInstanceIndex !== undefined) {\n mesh._waitingParentInstanceIndex = parsedMesh.parentInstanceIndex;\n }\n // Actions\n if (parsedMesh.actions !== undefined) {\n mesh._waitingData.actions = parsedMesh.actions;\n }\n // Overlay\n if (parsedMesh.overlayAlpha !== undefined) {\n mesh.overlayAlpha = parsedMesh.overlayAlpha;\n }\n if (parsedMesh.overlayColor !== undefined) {\n mesh.overlayColor = Color3.FromArray(parsedMesh.overlayColor);\n }\n if (parsedMesh.renderOverlay !== undefined) {\n mesh.renderOverlay = parsedMesh.renderOverlay;\n }\n // Geometry\n mesh.isUnIndexed = !!parsedMesh.isUnIndexed;\n mesh.hasVertexAlpha = parsedMesh.hasVertexAlpha;\n if (parsedMesh.delayLoadingFile) {\n mesh.delayLoadState = 4;\n mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;\n mesh.buildBoundingInfo(Vector3.FromArray(parsedMesh.boundingBoxMinimum), Vector3.FromArray(parsedMesh.boundingBoxMaximum));\n if (parsedMesh._binaryInfo) {\n mesh._binaryInfo = parsedMesh._binaryInfo;\n }\n mesh._delayInfo = [];\n if (parsedMesh.hasUVs) {\n mesh._delayInfo.push(VertexBuffer.UVKind);\n }\n if (parsedMesh.hasUVs2) {\n mesh._delayInfo.push(VertexBuffer.UV2Kind);\n }\n if (parsedMesh.hasUVs3) {\n mesh._delayInfo.push(VertexBuffer.UV3Kind);\n }\n if (parsedMesh.hasUVs4) {\n mesh._delayInfo.push(VertexBuffer.UV4Kind);\n }\n if (parsedMesh.hasUVs5) {\n mesh._delayInfo.push(VertexBuffer.UV5Kind);\n }\n if (parsedMesh.hasUVs6) {\n mesh._delayInfo.push(VertexBuffer.UV6Kind);\n }\n if (parsedMesh.hasColors) {\n mesh._delayInfo.push(VertexBuffer.ColorKind);\n }\n if (parsedMesh.hasMatricesIndices) {\n mesh._delayInfo.push(VertexBuffer.MatricesIndicesKind);\n }\n if (parsedMesh.hasMatricesWeights) {\n mesh._delayInfo.push(VertexBuffer.MatricesWeightsKind);\n }\n mesh._delayLoadingFunction = Geometry._ImportGeometry;\n if (SceneLoaderFlags.ForceFullSceneLoadingForIncremental) {\n mesh._checkDelayState();\n }\n }\n else {\n Geometry._ImportGeometry(parsedMesh, mesh);\n }\n // Material\n if (parsedMesh.materialUniqueId) {\n mesh._waitingMaterialId = parsedMesh.materialUniqueId;\n }\n else if (parsedMesh.materialId) {\n mesh._waitingMaterialId = parsedMesh.materialId;\n }\n // Morph targets\n if (parsedMesh.morphTargetManagerId > -1) {\n mesh.morphTargetManager = scene.getMorphTargetManagerById(parsedMesh.morphTargetManagerId);\n }\n // Skeleton\n if (parsedMesh.skeletonId !== undefined && parsedMesh.skeletonId !== null) {\n mesh.skeleton = scene.getLastSkeletonById(parsedMesh.skeletonId);\n if (parsedMesh.numBoneInfluencers) {\n mesh.numBoneInfluencers = parsedMesh.numBoneInfluencers;\n }\n }\n // Animations\n if (parsedMesh.animations) {\n for (let animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {\n const parsedAnimation = parsedMesh.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n mesh.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n Node.ParseAnimationRanges(mesh, parsedMesh, scene);\n }\n if (parsedMesh.autoAnimate) {\n scene.beginAnimation(mesh, parsedMesh.autoAnimateFrom, parsedMesh.autoAnimateTo, parsedMesh.autoAnimateLoop, parsedMesh.autoAnimateSpeed || 1.0);\n }\n // Layer Mask\n if (parsedMesh.layerMask && !isNaN(parsedMesh.layerMask)) {\n mesh.layerMask = Math.abs(parseInt(parsedMesh.layerMask));\n }\n else {\n mesh.layerMask = 0x0fffffff;\n }\n // Physics\n if (parsedMesh.physicsImpostor) {\n Mesh._PhysicsImpostorParser(scene, mesh, parsedMesh);\n }\n // Levels\n if (parsedMesh.lodMeshIds) {\n mesh._waitingData.lods = {\n ids: parsedMesh.lodMeshIds,\n distances: parsedMesh.lodDistances ? parsedMesh.lodDistances : null,\n coverages: parsedMesh.lodCoverages ? parsedMesh.lodCoverages : null,\n };\n }\n // Instances\n if (parsedMesh.instances) {\n for (let index = 0; index < parsedMesh.instances.length; index++) {\n const parsedInstance = parsedMesh.instances[index];\n const instance = mesh.createInstance(parsedInstance.name);\n if (parsedInstance.id) {\n instance.id = parsedInstance.id;\n }\n if (Tags) {\n if (parsedInstance.tags) {\n Tags.AddTagsTo(instance, parsedInstance.tags);\n }\n else {\n Tags.AddTagsTo(instance, parsedMesh.tags);\n }\n }\n instance.position = Vector3.FromArray(parsedInstance.position);\n if (parsedInstance.metadata !== undefined) {\n instance.metadata = parsedInstance.metadata;\n }\n if (parsedInstance.parentId !== undefined) {\n instance._waitingParentId = parsedInstance.parentId;\n }\n if (parsedInstance.parentInstanceIndex !== undefined) {\n instance._waitingParentInstanceIndex = parsedInstance.parentInstanceIndex;\n }\n if (parsedInstance.isEnabled !== undefined && parsedInstance.isEnabled !== null) {\n instance.setEnabled(parsedInstance.isEnabled);\n }\n if (parsedInstance.isVisible !== undefined && parsedInstance.isVisible !== null) {\n instance.isVisible = parsedInstance.isVisible;\n }\n if (parsedInstance.isPickable !== undefined && parsedInstance.isPickable !== null) {\n instance.isPickable = parsedInstance.isPickable;\n }\n if (parsedInstance.rotationQuaternion) {\n instance.rotationQuaternion = Quaternion.FromArray(parsedInstance.rotationQuaternion);\n }\n else if (parsedInstance.rotation) {\n instance.rotation = Vector3.FromArray(parsedInstance.rotation);\n }\n instance.scaling = Vector3.FromArray(parsedInstance.scaling);\n if (parsedInstance.checkCollisions != undefined && parsedInstance.checkCollisions != null) {\n instance.checkCollisions = parsedInstance.checkCollisions;\n }\n if (parsedInstance.pickable != undefined && parsedInstance.pickable != null) {\n instance.isPickable = parsedInstance.pickable;\n }\n if (parsedInstance.showBoundingBox != undefined && parsedInstance.showBoundingBox != null) {\n instance.showBoundingBox = parsedInstance.showBoundingBox;\n }\n if (parsedInstance.showSubMeshesBoundingBox != undefined && parsedInstance.showSubMeshesBoundingBox != null) {\n instance.showSubMeshesBoundingBox = parsedInstance.showSubMeshesBoundingBox;\n }\n if (parsedInstance.alphaIndex != undefined && parsedInstance.showSubMeshesBoundingBox != null) {\n instance.alphaIndex = parsedInstance.alphaIndex;\n }\n // Physics\n if (parsedInstance.physicsImpostor) {\n Mesh._PhysicsImpostorParser(scene, instance, parsedInstance);\n }\n // Actions\n if (parsedInstance.actions !== undefined) {\n instance._waitingData.actions = parsedInstance.actions;\n }\n // Animation\n if (parsedInstance.animations) {\n for (let animationIndex = 0; animationIndex < parsedInstance.animations.length; animationIndex++) {\n const parsedAnimation = parsedInstance.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n instance.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n Node.ParseAnimationRanges(instance, parsedInstance, scene);\n if (parsedInstance.autoAnimate) {\n scene.beginAnimation(instance, parsedInstance.autoAnimateFrom, parsedInstance.autoAnimateTo, parsedInstance.autoAnimateLoop, parsedInstance.autoAnimateSpeed || 1.0);\n }\n }\n }\n }\n // Thin instances\n if (parsedMesh.thinInstances) {\n const thinInstances = parsedMesh.thinInstances;\n mesh.thinInstanceEnablePicking = !!thinInstances.enablePicking;\n if (thinInstances.matrixData) {\n mesh.thinInstanceSetBuffer(\"matrix\", new Float32Array(thinInstances.matrixData), 16, false);\n mesh._thinInstanceDataStorage.matrixBufferSize = thinInstances.matrixBufferSize;\n mesh._thinInstanceDataStorage.instancesCount = thinInstances.instancesCount;\n }\n else {\n mesh._thinInstanceDataStorage.matrixBufferSize = thinInstances.matrixBufferSize;\n }\n if (parsedMesh.thinInstances.userThinInstance) {\n const userThinInstance = parsedMesh.thinInstances.userThinInstance;\n for (const kind in userThinInstance.data) {\n mesh.thinInstanceSetBuffer(kind, new Float32Array(userThinInstance.data[kind]), userThinInstance.strides[kind], false);\n mesh._userThinInstanceBuffersStorage.sizes[kind] = userThinInstance.sizes[kind];\n }\n }\n }\n return mesh;\n }\n // Skeletons\n /**\n * Prepare internal position array for software CPU skinning\n * @returns original positions used for CPU skinning. Useful for integrating Morphing with skeletons in same mesh\n */\n setPositionsForCPUSkinning() {\n const internalDataInfo = this._internalMeshDataInfo;\n if (!internalDataInfo._sourcePositions) {\n const source = this.getVerticesData(VertexBuffer.PositionKind);\n if (!source) {\n return internalDataInfo._sourcePositions;\n }\n internalDataInfo._sourcePositions = new Float32Array(source);\n if (!this.isVertexBufferUpdatable(VertexBuffer.PositionKind)) {\n this.setVerticesData(VertexBuffer.PositionKind, source, true);\n }\n }\n return internalDataInfo._sourcePositions;\n }\n /**\n * Prepare internal normal array for software CPU skinning\n * @returns original normals used for CPU skinning. Useful for integrating Morphing with skeletons in same mesh.\n */\n setNormalsForCPUSkinning() {\n const internalDataInfo = this._internalMeshDataInfo;\n if (!internalDataInfo._sourceNormals) {\n const source = this.getVerticesData(VertexBuffer.NormalKind);\n if (!source) {\n return internalDataInfo._sourceNormals;\n }\n internalDataInfo._sourceNormals = new Float32Array(source);\n if (!this.isVertexBufferUpdatable(VertexBuffer.NormalKind)) {\n this.setVerticesData(VertexBuffer.NormalKind, source, true);\n }\n }\n return internalDataInfo._sourceNormals;\n }\n /**\n * Updates the vertex buffer by applying transformation from the bones\n * @param skeleton defines the skeleton to apply to current mesh\n * @returns the current mesh\n */\n applySkeleton(skeleton) {\n if (!this.geometry) {\n return this;\n }\n if (this.geometry._softwareSkinningFrameId == this.getScene().getFrameId()) {\n return this;\n }\n this.geometry._softwareSkinningFrameId = this.getScene().getFrameId();\n if (!this.isVerticesDataPresent(VertexBuffer.PositionKind)) {\n return this;\n }\n if (!this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {\n return this;\n }\n if (!this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\n return this;\n }\n const hasNormals = this.isVerticesDataPresent(VertexBuffer.NormalKind);\n const internalDataInfo = this._internalMeshDataInfo;\n if (!internalDataInfo._sourcePositions) {\n const submeshes = this.subMeshes.slice();\n this.setPositionsForCPUSkinning();\n this.subMeshes = submeshes;\n }\n if (hasNormals && !internalDataInfo._sourceNormals) {\n this.setNormalsForCPUSkinning();\n }\n // positionsData checks for not being Float32Array will only pass at most once\n let positionsData = this.getVerticesData(VertexBuffer.PositionKind);\n if (!positionsData) {\n return this;\n }\n if (!(positionsData instanceof Float32Array)) {\n positionsData = new Float32Array(positionsData);\n }\n // normalsData checks for not being Float32Array will only pass at most once\n let normalsData = this.getVerticesData(VertexBuffer.NormalKind);\n if (hasNormals) {\n if (!normalsData) {\n return this;\n }\n if (!(normalsData instanceof Float32Array)) {\n normalsData = new Float32Array(normalsData);\n }\n }\n const matricesIndicesData = this.getVerticesData(VertexBuffer.MatricesIndicesKind);\n const matricesWeightsData = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\n if (!matricesWeightsData || !matricesIndicesData) {\n return this;\n }\n const needExtras = this.numBoneInfluencers > 4;\n const matricesIndicesExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;\n const matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;\n const skeletonMatrices = skeleton.getTransformMatrices(this);\n const tempVector3 = Vector3.Zero();\n const finalMatrix = new Matrix();\n const tempMatrix = new Matrix();\n let matWeightIdx = 0;\n let inf;\n for (let index = 0; index < positionsData.length; index += 3, matWeightIdx += 4) {\n let weight;\n for (inf = 0; inf < 4; inf++) {\n weight = matricesWeightsData[matWeightIdx + inf];\n if (weight > 0) {\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesData[matWeightIdx + inf] * 16), weight, tempMatrix);\n finalMatrix.addToSelf(tempMatrix);\n }\n }\n if (needExtras) {\n for (inf = 0; inf < 4; inf++) {\n weight = matricesWeightsExtraData[matWeightIdx + inf];\n if (weight > 0) {\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesExtraData[matWeightIdx + inf] * 16), weight, tempMatrix);\n finalMatrix.addToSelf(tempMatrix);\n }\n }\n }\n Vector3.TransformCoordinatesFromFloatsToRef(internalDataInfo._sourcePositions[index], internalDataInfo._sourcePositions[index + 1], internalDataInfo._sourcePositions[index + 2], finalMatrix, tempVector3);\n tempVector3.toArray(positionsData, index);\n if (hasNormals) {\n Vector3.TransformNormalFromFloatsToRef(internalDataInfo._sourceNormals[index], internalDataInfo._sourceNormals[index + 1], internalDataInfo._sourceNormals[index + 2], finalMatrix, tempVector3);\n tempVector3.toArray(normalsData, index);\n }\n finalMatrix.reset();\n }\n this.updateVerticesData(VertexBuffer.PositionKind, positionsData);\n if (hasNormals) {\n this.updateVerticesData(VertexBuffer.NormalKind, normalsData);\n }\n return this;\n }\n // Tools\n /**\n * Returns an object containing a min and max Vector3 which are the minimum and maximum vectors of each mesh bounding box from the passed array, in the world coordinates\n * @param meshes defines the list of meshes to scan\n * @returns an object `{min:` Vector3`, max:` Vector3`}`\n */\n static MinMax(meshes) {\n let minVector = null;\n let maxVector = null;\n meshes.forEach(function (mesh) {\n const boundingInfo = mesh.getBoundingInfo();\n const boundingBox = boundingInfo.boundingBox;\n if (!minVector || !maxVector) {\n minVector = boundingBox.minimumWorld;\n maxVector = boundingBox.maximumWorld;\n }\n else {\n minVector.minimizeInPlace(boundingBox.minimumWorld);\n maxVector.maximizeInPlace(boundingBox.maximumWorld);\n }\n });\n if (!minVector || !maxVector) {\n return {\n min: Vector3.Zero(),\n max: Vector3.Zero(),\n };\n }\n return {\n min: minVector,\n max: maxVector,\n };\n }\n /**\n * Returns the center of the `{min:` Vector3`, max:` Vector3`}` or the center of MinMax vector3 computed from a mesh array\n * @param meshesOrMinMaxVector could be an array of meshes or a `{min:` Vector3`, max:` Vector3`}` object\n * @returns a vector3\n */\n static Center(meshesOrMinMaxVector) {\n const minMaxVector = meshesOrMinMaxVector instanceof Array ? Mesh.MinMax(meshesOrMinMaxVector) : meshesOrMinMaxVector;\n return Vector3.Center(minMaxVector.min, minMaxVector.max);\n }\n /**\n * Merge the array of meshes into a single mesh for performance reasons.\n * @param meshes array of meshes with the vertices to merge. Entries cannot be empty meshes.\n * @param disposeSource when true (default), dispose of the vertices from the source meshes.\n * @param allow32BitsIndices when the sum of the vertices > 64k, this must be set to true.\n * @param meshSubclass (optional) can be set to a Mesh where the merged vertices will be inserted.\n * @param subdivideWithSubMeshes when true (false default), subdivide mesh into subMeshes.\n * @param multiMultiMaterials when true (false default), subdivide mesh into subMeshes with multiple materials, ignores subdivideWithSubMeshes.\n * @returns a new mesh\n */\n static MergeMeshes(meshes, disposeSource = true, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials) {\n return runCoroutineSync(Mesh._MergeMeshesCoroutine(meshes, disposeSource, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials, false));\n }\n /**\n * Merge the array of meshes into a single mesh for performance reasons.\n * @param meshes array of meshes with the vertices to merge. Entries cannot be empty meshes.\n * @param disposeSource when true (default), dispose of the vertices from the source meshes.\n * @param allow32BitsIndices when the sum of the vertices > 64k, this must be set to true.\n * @param meshSubclass (optional) can be set to a Mesh where the merged vertices will be inserted.\n * @param subdivideWithSubMeshes when true (false default), subdivide mesh into subMeshes.\n * @param multiMultiMaterials when true (false default), subdivide mesh into subMeshes with multiple materials, ignores subdivideWithSubMeshes.\n * @returns a new mesh\n */\n static MergeMeshesAsync(meshes, disposeSource = true, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials) {\n return runCoroutineAsync(Mesh._MergeMeshesCoroutine(meshes, disposeSource, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials, true), createYieldingScheduler());\n }\n static *_MergeMeshesCoroutine(meshes, disposeSource = true, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials, isAsync) {\n // Remove any null/undefined entries from the mesh array\n meshes = meshes.filter(Boolean);\n if (meshes.length === 0) {\n return null;\n }\n let index;\n if (!allow32BitsIndices) {\n let totalVertices = 0;\n // Counting vertices\n for (index = 0; index < meshes.length; index++) {\n totalVertices += meshes[index].getTotalVertices();\n if (totalVertices >= 65536) {\n Logger.Warn(\"Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices\");\n return null;\n }\n }\n }\n if (multiMultiMaterials) {\n subdivideWithSubMeshes = false;\n }\n const materialArray = new Array();\n const materialIndexArray = new Array();\n // Merge\n const indiceArray = new Array();\n const currentOverrideMaterialSideOrientation = meshes[0].overrideMaterialSideOrientation;\n for (index = 0; index < meshes.length; index++) {\n const mesh = meshes[index];\n if (mesh.isAnInstance) {\n Logger.Warn(\"Cannot merge instance meshes.\");\n return null;\n }\n if (currentOverrideMaterialSideOrientation !== mesh.overrideMaterialSideOrientation) {\n Logger.Warn(\"Cannot merge meshes with different overrideMaterialSideOrientation values.\");\n return null;\n }\n if (subdivideWithSubMeshes) {\n indiceArray.push(mesh.getTotalIndices());\n }\n if (multiMultiMaterials) {\n if (mesh.material) {\n const material = mesh.material;\n if (material instanceof MultiMaterial) {\n for (let matIndex = 0; matIndex < material.subMaterials.length; matIndex++) {\n if (materialArray.indexOf(material.subMaterials[matIndex]) < 0) {\n materialArray.push(material.subMaterials[matIndex]);\n }\n }\n for (let subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {\n materialIndexArray.push(materialArray.indexOf(material.subMaterials[mesh.subMeshes[subIndex].materialIndex]));\n indiceArray.push(mesh.subMeshes[subIndex].indexCount);\n }\n }\n else {\n if (materialArray.indexOf(material) < 0) {\n materialArray.push(material);\n }\n for (let subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {\n materialIndexArray.push(materialArray.indexOf(material));\n indiceArray.push(mesh.subMeshes[subIndex].indexCount);\n }\n }\n }\n else {\n for (let subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {\n materialIndexArray.push(0);\n indiceArray.push(mesh.subMeshes[subIndex].indexCount);\n }\n }\n }\n }\n const source = meshes[0];\n const getVertexDataFromMesh = (mesh) => {\n const wm = mesh.computeWorldMatrix(true);\n const vertexData = VertexData.ExtractFromMesh(mesh, false, false);\n return { vertexData, transform: wm };\n };\n const { vertexData: sourceVertexData, transform: sourceTransform } = getVertexDataFromMesh(source);\n if (isAsync) {\n yield;\n }\n const meshVertexDatas = new Array(meshes.length - 1);\n for (let i = 1; i < meshes.length; i++) {\n meshVertexDatas[i - 1] = getVertexDataFromMesh(meshes[i]);\n if (isAsync) {\n yield;\n }\n }\n const mergeCoroutine = sourceVertexData._mergeCoroutine(sourceTransform, meshVertexDatas, allow32BitsIndices, isAsync, !disposeSource);\n let mergeCoroutineStep = mergeCoroutine.next();\n while (!mergeCoroutineStep.done) {\n if (isAsync) {\n yield;\n }\n mergeCoroutineStep = mergeCoroutine.next();\n }\n const vertexData = mergeCoroutineStep.value;\n if (!meshSubclass) {\n meshSubclass = new Mesh(source.name + \"_merged\", source.getScene());\n }\n const applyToCoroutine = vertexData._applyToCoroutine(meshSubclass, undefined, isAsync);\n let applyToCoroutineStep = applyToCoroutine.next();\n while (!applyToCoroutineStep.done) {\n if (isAsync) {\n yield;\n }\n applyToCoroutineStep = applyToCoroutine.next();\n }\n // Setting properties\n meshSubclass.checkCollisions = source.checkCollisions;\n meshSubclass.overrideMaterialSideOrientation = source.overrideMaterialSideOrientation;\n // Cleaning\n if (disposeSource) {\n for (index = 0; index < meshes.length; index++) {\n meshes[index].dispose();\n }\n }\n // Subdivide\n if (subdivideWithSubMeshes || multiMultiMaterials) {\n //-- removal of global submesh\n meshSubclass.releaseSubMeshes();\n index = 0;\n let offset = 0;\n //-- apply subdivision according to index table\n while (index < indiceArray.length) {\n SubMesh.CreateFromIndices(0, offset, indiceArray[index], meshSubclass, undefined, false);\n offset += indiceArray[index];\n index++;\n }\n for (const subMesh of meshSubclass.subMeshes) {\n subMesh.refreshBoundingInfo();\n }\n meshSubclass.computeWorldMatrix(true);\n }\n if (multiMultiMaterials) {\n const newMultiMaterial = new MultiMaterial(source.name + \"_merged\", source.getScene());\n newMultiMaterial.subMaterials = materialArray;\n for (let subIndex = 0; subIndex < meshSubclass.subMeshes.length; subIndex++) {\n meshSubclass.subMeshes[subIndex].materialIndex = materialIndexArray[subIndex];\n }\n meshSubclass.material = newMultiMaterial;\n }\n else {\n meshSubclass.material = source.material;\n }\n return meshSubclass;\n }\n /**\n * @internal\n */\n addInstance(instance) {\n instance._indexInSourceMeshInstanceArray = this.instances.length;\n this.instances.push(instance);\n }\n /**\n * @internal\n */\n removeInstance(instance) {\n // Remove from mesh\n const index = instance._indexInSourceMeshInstanceArray;\n if (index != -1) {\n if (index !== this.instances.length - 1) {\n const last = this.instances[this.instances.length - 1];\n this.instances[index] = last;\n last._indexInSourceMeshInstanceArray = index;\n }\n instance._indexInSourceMeshInstanceArray = -1;\n this.instances.pop();\n }\n }\n /** @internal */\n _shouldConvertRHS() {\n return this.overrideMaterialSideOrientation === Material.CounterClockWiseSideOrientation;\n }\n /** @internal */\n _getRenderingFillMode(fillMode) {\n var _a;\n const scene = this.getScene();\n if (scene.forcePointsCloud)\n return Material.PointFillMode;\n if (scene.forceWireframe)\n return Material.WireFrameFillMode;\n return (_a = this.overrideRenderingFillMode) !== null && _a !== void 0 ? _a : fillMode;\n }\n // deprecated methods\n /**\n * Sets the mesh material by the material or multiMaterial `id` property\n * @param id is a string identifying the material or the multiMaterial\n * @returns the current mesh\n * @deprecated Please use MeshBuilder instead Please use setMaterialById instead\n */\n setMaterialByID(id) {\n return this.setMaterialById(id);\n }\n /**\n * Creates a ribbon mesh.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n * @param name defines the name of the mesh to create\n * @param pathArray is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry.\n * @param closeArray creates a seam between the first and the last paths of the path array (default is false)\n * @param closePath creates a seam between the first and the last points of each path of the path array\n * @param offset is taken in account only if the `pathArray` is containing a single path\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @param instance defines an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#ribbon)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateRibbon(name, pathArray, closeArray, closePath, offset, scene, updatable, sideOrientation, instance) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a plane polygonal mesh. By default, this is a disc.\n * @param name defines the name of the mesh to create\n * @param radius sets the radius size (float) of the polygon (default 0.5)\n * @param tessellation sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateDisc(name, radius, tessellation, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a box mesh.\n * @param name defines the name of the mesh to create\n * @param size sets the size (float) of each box side (default 1)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateBox(name, size, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a sphere mesh.\n * @param name defines the name of the mesh to create\n * @param segments sets the sphere number of horizontal stripes (positive integer, default 32)\n * @param diameter sets the diameter size (float) of the sphere (default 1)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateSphere(name, segments, diameter, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a hemisphere mesh.\n * @param name defines the name of the mesh to create\n * @param segments sets the sphere number of horizontal stripes (positive integer, default 32)\n * @param diameter sets the diameter size (float) of the sphere (default 1)\n * @param scene defines the hosting scene\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateHemisphere(name, segments, diameter, scene) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a cylinder or a cone mesh.\n * @param name defines the name of the mesh to create\n * @param height sets the height size (float) of the cylinder/cone (float, default 2)\n * @param diameterTop set the top cap diameter (floats, default 1)\n * @param diameterBottom set the bottom cap diameter (floats, default 1). This value can't be zero\n * @param tessellation sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance\n * @param subdivisions sets the number of rings along the cylinder height (positive integer, default 1)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateCylinder(name, height, diameterTop, diameterBottom, tessellation, subdivisions, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n // Torus (Code from SharpDX.org)\n /**\n * Creates a torus mesh.\n * @param name defines the name of the mesh to create\n * @param diameter sets the diameter size (float) of the torus (default 1)\n * @param thickness sets the diameter size of the tube of the torus (float, default 0.5)\n * @param tessellation sets the number of torus sides (positive integer, default 16)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateTorus(name, diameter, thickness, tessellation, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a torus knot mesh.\n * @param name defines the name of the mesh to create\n * @param radius sets the global radius size (float) of the torus knot (default 2)\n * @param tube sets the diameter size of the tube of the torus (float, default 0.5)\n * @param radialSegments sets the number of sides on each tube segments (positive integer, default 32)\n * @param tubularSegments sets the number of tubes to decompose the knot into (positive integer, default 32)\n * @param p the number of windings on X axis (positive integers, default 2)\n * @param q the number of windings on Y axis (positive integers, default 3)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateTorusKnot(name, radius, tube, radialSegments, tubularSegments, p, q, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a line mesh..\n * @param name defines the name of the mesh to create\n * @param points is an array successive Vector3\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines).\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateLines(name, points, scene, updatable, instance) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a dashed line mesh.\n * @param name defines the name of the mesh to create\n * @param points is an array successive Vector3\n * @param dashSize is the size of the dashes relatively the dash number (positive float, default 3)\n * @param gapSize is the size of the gap between two successive dashes relatively the dash number (positive float, default 1)\n * @param dashNb is the intended total number of dashes (positive integer, default 200)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateDashedLines(name, points, dashSize, gapSize, dashNb, scene, updatable, instance) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a polygon mesh.Please consider using the same method from the MeshBuilder class instead\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.\n * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.\n * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * Remember you can only change the shape positions, not their number when updating a polygon.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#non-regular-polygon\n * @param name defines the name of the mesh to create\n * @param shape is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\n * @param scene defines the hosting scene\n * @param holes is a required array of arrays of successive Vector3 used to defines holes in the polygon\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @param earcutInjection can be used to inject your own earcut reference\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreatePolygon(name, shape, scene, holes, updatable, sideOrientation, earcutInjection) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates an extruded polygon mesh, with depth in the Y direction..\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-non-regular-polygon\n * @param name defines the name of the mesh to create\n * @param shape is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\n * @param depth defines the height of extrusion\n * @param scene defines the hosting scene\n * @param holes is a required array of arrays of successive Vector3 used to defines holes in the polygon\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @param earcutInjection can be used to inject your own earcut reference\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static ExtrudePolygon(name, shape, depth, scene, holes, updatable, sideOrientation, earcutInjection) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates an extruded shape mesh.\n * The extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\n * @param name defines the name of the mesh to create\n * @param shape is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis\n * @param path is a required array of successive Vector3. This is the axis curve the shape is extruded along\n * @param scale is the value to scale the shape\n * @param rotation is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve\n * @param cap sets the way the extruded shape is capped. Possible values : Mesh.NO_CAP (default), Mesh.CAP_START, Mesh.CAP_END, Mesh.CAP_ALL\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#extruded-shape)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static ExtrudeShape(name, shape, path, scale, rotation, cap, scene, updatable, sideOrientation, instance) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates an custom extruded shape mesh.\n * The custom extrusion is a parametric shape.\n * It has no predefined shape. Its final shape will depend on the input parameters.\n *\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\n * @param name defines the name of the mesh to create\n * @param shape is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis\n * @param path is a required array of successive Vector3. This is the axis curve the shape is extruded along\n * @param scaleFunction is a custom Javascript function called on each path point\n * @param rotationFunction is a custom Javascript function called on each path point\n * @param ribbonCloseArray forces the extrusion underlying ribbon to close all the paths in its `pathArray`\n * @param ribbonClosePath forces the extrusion underlying ribbon to close its `pathArray`\n * @param cap sets the way the extruded shape is capped. Possible values : Mesh.NO_CAP (default), Mesh.CAP_START, Mesh.CAP_END, Mesh.CAP_ALL\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#extruded-shape)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static ExtrudeShapeCustom(name, shape, path, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, scene, updatable, sideOrientation, instance) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates lathe mesh.\n * The lathe is a shape with a symmetry axis : a 2D model shape is rotated around this axis to design the lathe.\n * @param name defines the name of the mesh to create\n * @param shape is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero\n * @param radius is the radius value of the lathe\n * @param tessellation is the side number of the lathe.\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateLathe(name, shape, radius, tessellation, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a plane mesh.\n * @param name defines the name of the mesh to create\n * @param size sets the size (float) of both sides of the plane at once (default 1)\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreatePlane(name, size, scene, updatable, sideOrientation) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a ground mesh.\n * @param name defines the name of the mesh to create\n * @param width set the width of the ground\n * @param height set the height of the ground\n * @param subdivisions sets the number of subdivisions per side\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateGround(name, width, height, subdivisions, scene, updatable) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a tiled ground mesh.\n * @param name defines the name of the mesh to create\n * @param xmin set the ground minimum X coordinate\n * @param zmin set the ground minimum Y coordinate\n * @param xmax set the ground maximum X coordinate\n * @param zmax set the ground maximum Z coordinate\n * @param subdivisions is an object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the numbers of subdivisions on the ground width and height. Each subdivision is called a tile\n * @param precision is an object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the numbers of subdivisions on the ground width and height of each tile\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateTiledGround(name, xmin, zmin, xmax, zmax, subdivisions, precision, scene, updatable) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a ground mesh from a height map.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/height_map\n * @param name defines the name of the mesh to create\n * @param url sets the URL of the height map image resource\n * @param width set the ground width size\n * @param height set the ground height size\n * @param subdivisions sets the number of subdivision per side\n * @param minHeight is the minimum altitude on the ground\n * @param maxHeight is the maximum altitude on the ground\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param onReady is a callback function that will be called once the mesh is built (the height map download can last some time)\n * @param alphaFilter will filter any data where the alpha channel is below this value, defaults 0 (all data visible)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateGroundFromHeightMap(name, url, width, height, subdivisions, minHeight, maxHeight, scene, updatable, onReady, alphaFilter) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a tube mesh.\n * The tube is a parametric shape.\n * It has no predefined shape. Its final shape will depend on the input parameters.\n *\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n * @param name defines the name of the mesh to create\n * @param path is a required array of successive Vector3. It is the curve used as the axis of the tube\n * @param radius sets the tube radius size\n * @param tessellation is the number of sides on the tubular surface\n * @param radiusFunction is a custom function. If it is not null, it overrides the parameter `radius`. This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path\n * @param cap sets the way the extruded shape is capped. Possible values : Mesh.NO_CAP (default), Mesh.CAP_START, Mesh.CAP_END, Mesh.CAP_ALL\n * @param scene defines the hosting scene\n * @param updatable defines if the mesh must be flagged as updatable\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\n * @param instance is an instance of an existing Tube object to be updated with the passed `pathArray` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#tube)\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateTube(name, path, radius, tessellation, radiusFunction, cap, scene, updatable, sideOrientation, instance) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a polyhedron mesh.\n *.\n * * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embedded types. Please refer to the type sheet in the tutorial to choose the wanted type\n * * The parameter `size` (positive float, default 1) sets the polygon size\n * * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value)\n * * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overwrittes the parameter `type`\n * * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron\n * * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`)\n * * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\n * * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored\n * * You can also set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh to create\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreatePolyhedron(name, options, scene) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided\n * * The parameter `radius` sets the radius size (float) of the icosphere (default 1)\n * * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value than `radius`)\n * * The parameter `subdivisions` sets the number of subdivisions (positive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size\n * * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface\n * * You can also set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra#icosphere\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateIcoSphere(name, options, scene) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Creates a decal mesh.\n *.\n * A decal is a mesh usually applied as a model onto the surface of another mesh\n * @param name defines the name of the mesh\n * @param sourceMesh defines the mesh receiving the decal\n * @param position sets the position of the decal in world coordinates\n * @param normal sets the normal of the mesh where the decal is applied onto in world coordinates\n * @param size sets the decal scaling\n * @param angle sets the angle to rotate the decal\n * @returns a new Mesh\n * @deprecated Please use MeshBuilder instead\n */\n static CreateDecal(name, sourceMesh, position, normal, size, angle) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /** Creates a Capsule Mesh\n * @param name defines the name of the mesh.\n * @param options the constructors options used to shape the mesh.\n * @param scene defines the scene the mesh is scoped to.\n * @returns the capsule mesh\n * @see https://doc.babylonjs.com/how_to/capsule_shape\n * @deprecated Please use MeshBuilder instead\n */\n static CreateCapsule(name, options, scene) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n /**\n * Extends a mesh to a Goldberg mesh\n * Warning the mesh to convert MUST be an import of a perviously exported Goldberg mesh\n * @param mesh the mesh to convert\n * @returns the extended mesh\n * @deprecated Please use ExtendMeshToGoldberg instead\n */\n static ExtendToGoldberg(mesh) {\n throw new Error(\"Import MeshBuilder to populate this function\");\n }\n }\n // Consts\n /**\n * Mesh side orientation : usually the external or front surface\n */\n Mesh.FRONTSIDE = VertexData.FRONTSIDE;\n /**\n * Mesh side orientation : usually the internal or back surface\n */\n Mesh.BACKSIDE = VertexData.BACKSIDE;\n /**\n * Mesh side orientation : both internal and external or front and back surfaces\n */\n Mesh.DOUBLESIDE = VertexData.DOUBLESIDE;\n /**\n * Mesh side orientation : by default, `FRONTSIDE`\n */\n Mesh.DEFAULTSIDE = VertexData.DEFAULTSIDE;\n /**\n * Mesh cap setting : no cap\n */\n Mesh.NO_CAP = 0;\n /**\n * Mesh cap setting : one cap at the beginning of the mesh\n */\n Mesh.CAP_START = 1;\n /**\n * Mesh cap setting : one cap at the end of the mesh\n */\n Mesh.CAP_END = 2;\n /**\n * Mesh cap setting : two caps, one at the beginning and one at the end of the mesh\n */\n Mesh.CAP_ALL = 3;\n /**\n * Mesh pattern setting : no flip or rotate\n */\n Mesh.NO_FLIP = 0;\n /**\n * Mesh pattern setting : flip (reflect in y axis) alternate tiles on each row or column\n */\n Mesh.FLIP_TILE = 1;\n /**\n * Mesh pattern setting : rotate (180degs) alternate tiles on each row or column\n */\n Mesh.ROTATE_TILE = 2;\n /**\n * Mesh pattern setting : flip (reflect in y axis) all tiles on alternate rows\n */\n Mesh.FLIP_ROW = 3;\n /**\n * Mesh pattern setting : rotate (180degs) all tiles on alternate rows\n */\n Mesh.ROTATE_ROW = 4;\n /**\n * Mesh pattern setting : flip and rotate alternate tiles on each row or column\n */\n Mesh.FLIP_N_ROTATE_TILE = 5;\n /**\n * Mesh pattern setting : rotate pattern and rotate\n */\n Mesh.FLIP_N_ROTATE_ROW = 6;\n /**\n * Mesh tile positioning : part tiles same on left/right or top/bottom\n */\n Mesh.CENTER = 0;\n /**\n * Mesh tile positioning : part tiles on left\n */\n Mesh.LEFT = 1;\n /**\n * Mesh tile positioning : part tiles on right\n */\n Mesh.RIGHT = 2;\n /**\n * Mesh tile positioning : part tiles on top\n */\n Mesh.TOP = 3;\n /**\n * Mesh tile positioning : part tiles on bottom\n */\n Mesh.BOTTOM = 4;\n /**\n * Indicates that the instanced meshes should be sorted from back to front before rendering if their material is transparent\n */\n Mesh.INSTANCEDMESH_SORT_TRANSPARENT = false;\n // Statics\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Mesh._GroundMeshParser = (parsedMesh, scene) => {\n throw _WarnImport(\"GroundMesh\");\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Mesh._GoldbergMeshParser = (parsedMesh, scene) => {\n throw _WarnImport(\"GoldbergMesh\");\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Mesh._LinesMeshParser = (parsedMesh, scene) => {\n throw _WarnImport(\"LinesMesh\");\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Mesh._GreasedLineMeshParser = (parsedMesh, scene) => {\n throw _WarnImport(\"GreasedLineMesh\");\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Mesh._TrailMeshParser = (parsedMesh, scene) => {\n throw _WarnImport(\"TrailMesh\");\n };\n RegisterClass(\"BABYLON.Mesh\", Mesh);\n\n /**\n * The autoRotation behavior (AutoRotationBehavior) is designed to create a smooth rotation of an ArcRotateCamera when there is no user interaction.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior\n */\n class AutoRotationBehavior {\n constructor() {\n this._zoomStopsAnimation = false;\n this._idleRotationSpeed = 0.05;\n this._idleRotationWaitTime = 2000;\n this._idleRotationSpinupTime = 2000;\n this.targetAlpha = null;\n this._isPointerDown = false;\n this._lastFrameTime = null;\n this._lastInteractionTime = -Infinity;\n this._cameraRotationSpeed = 0;\n this._lastFrameRadius = 0;\n }\n /**\n * Gets the name of the behavior.\n */\n get name() {\n return \"AutoRotation\";\n }\n /**\n * Sets the flag that indicates if user zooming should stop animation.\n */\n set zoomStopsAnimation(flag) {\n this._zoomStopsAnimation = flag;\n }\n /**\n * Gets the flag that indicates if user zooming should stop animation.\n */\n get zoomStopsAnimation() {\n return this._zoomStopsAnimation;\n }\n /**\n * Sets the default speed at which the camera rotates around the model.\n */\n set idleRotationSpeed(speed) {\n this._idleRotationSpeed = speed;\n }\n /**\n * Gets the default speed at which the camera rotates around the model.\n */\n get idleRotationSpeed() {\n return this._idleRotationSpeed;\n }\n /**\n * Sets the time (in milliseconds) to wait after user interaction before the camera starts rotating.\n */\n set idleRotationWaitTime(time) {\n this._idleRotationWaitTime = time;\n }\n /**\n * Gets the time (milliseconds) to wait after user interaction before the camera starts rotating.\n */\n get idleRotationWaitTime() {\n return this._idleRotationWaitTime;\n }\n /**\n * Sets the time (milliseconds) to take to spin up to the full idle rotation speed.\n */\n set idleRotationSpinupTime(time) {\n this._idleRotationSpinupTime = time;\n }\n /**\n * Gets the time (milliseconds) to take to spin up to the full idle rotation speed.\n */\n get idleRotationSpinupTime() {\n return this._idleRotationSpinupTime;\n }\n /**\n * Gets a value indicating if the camera is currently rotating because of this behavior\n */\n get rotationInProgress() {\n return Math.abs(this._cameraRotationSpeed) > 0;\n }\n /**\n * Initializes the behavior.\n */\n init() {\n // Do nothing\n }\n /**\n * Attaches the behavior to its arc rotate camera.\n * @param camera Defines the camera to attach the behavior to\n */\n attach(camera) {\n this._attachedCamera = camera;\n const scene = this._attachedCamera.getScene();\n this._onPrePointerObservableObserver = scene.onPrePointerObservable.add((pointerInfoPre) => {\n if (pointerInfoPre.type === PointerEventTypes.POINTERDOWN) {\n this._isPointerDown = true;\n return;\n }\n if (pointerInfoPre.type === PointerEventTypes.POINTERUP) {\n this._isPointerDown = false;\n }\n });\n this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {\n if (this._reachTargetAlpha()) {\n return;\n }\n const now = PrecisionDate.Now;\n let dt = 0;\n if (this._lastFrameTime != null) {\n dt = now - this._lastFrameTime;\n }\n this._lastFrameTime = now;\n // Stop the animation if there is user interaction and the animation should stop for this interaction\n this._applyUserInteraction();\n const timeToRotation = now - this._lastInteractionTime - this._idleRotationWaitTime;\n const scale = Math.max(Math.min(timeToRotation / this._idleRotationSpinupTime, 1), 0);\n this._cameraRotationSpeed = this._idleRotationSpeed * scale;\n // Step camera rotation by rotation speed\n if (this._attachedCamera) {\n this._attachedCamera.alpha -= this._cameraRotationSpeed * (dt / 1000);\n }\n });\n }\n /**\n * Detaches the behavior from its current arc rotate camera.\n */\n detach() {\n if (!this._attachedCamera) {\n return;\n }\n const scene = this._attachedCamera.getScene();\n if (this._onPrePointerObservableObserver) {\n scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);\n }\n this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);\n this._attachedCamera = null;\n }\n /**\n * Force-reset the last interaction time\n * @param customTime an optional time that will be used instead of the current last interaction time. For example `Date.now()`\n */\n resetLastInteractionTime(customTime) {\n this._lastInteractionTime = customTime !== null && customTime !== void 0 ? customTime : PrecisionDate.Now;\n }\n /**\n * Returns true if camera alpha reaches the target alpha\n * @returns true if camera alpha reaches the target alpha\n */\n _reachTargetAlpha() {\n if (this._attachedCamera && this.targetAlpha) {\n return Math.abs(this._attachedCamera.alpha - this.targetAlpha) < Epsilon;\n }\n return false;\n }\n /**\n * Returns true if user is scrolling.\n * @returns true if user is scrolling.\n */\n _userIsZooming() {\n if (!this._attachedCamera) {\n return false;\n }\n return this._attachedCamera.inertialRadiusOffset !== 0;\n }\n _shouldAnimationStopForInteraction() {\n if (!this._attachedCamera) {\n return false;\n }\n let zoomHasHitLimit = false;\n if (this._lastFrameRadius === this._attachedCamera.radius && this._attachedCamera.inertialRadiusOffset !== 0) {\n zoomHasHitLimit = true;\n }\n // Update the record of previous radius - works as an approx. indicator of hitting radius limits\n this._lastFrameRadius = this._attachedCamera.radius;\n return this._zoomStopsAnimation ? zoomHasHitLimit : this._userIsZooming();\n }\n /**\n * Applies any current user interaction to the camera. Takes into account maximum alpha rotation.\n */\n _applyUserInteraction() {\n if (this._userIsMoving() && !this._shouldAnimationStopForInteraction()) {\n this._lastInteractionTime = PrecisionDate.Now;\n }\n }\n // Tools\n _userIsMoving() {\n if (!this._attachedCamera) {\n return false;\n }\n return (this._attachedCamera.inertialAlphaOffset !== 0 ||\n this._attachedCamera.inertialBetaOffset !== 0 ||\n this._attachedCamera.inertialRadiusOffset !== 0 ||\n this._attachedCamera.inertialPanningX !== 0 ||\n this._attachedCamera.inertialPanningY !== 0 ||\n this._isPointerDown);\n }\n }\n\n /**\n * Defines potential orientation for back face culling\n */\n var Orientation;\n (function (Orientation) {\n /**\n * Clockwise\n */\n Orientation[Orientation[\"CW\"] = 0] = \"CW\";\n /** Counter clockwise */\n Orientation[Orientation[\"CCW\"] = 1] = \"CCW\";\n })(Orientation || (Orientation = {}));\n /**\n * Defines angle representation\n */\n class Angle {\n /**\n * Creates an Angle object of \"radians\" radians (float).\n * @param radians the angle in radians\n */\n constructor(radians) {\n this._radians = radians;\n if (this._radians < 0.0) {\n this._radians += 2.0 * Math.PI;\n }\n }\n /**\n * Get value in degrees\n * @returns the Angle value in degrees (float)\n */\n degrees() {\n return (this._radians * 180.0) / Math.PI;\n }\n /**\n * Get value in radians\n * @returns the Angle value in radians (float)\n */\n radians() {\n return this._radians;\n }\n /**\n * Gets a new Angle object valued with the gradient angle, in radians, of the line joining two points\n * @param a defines first point as the origin\n * @param b defines point\n * @returns a new Angle\n */\n static BetweenTwoPoints(a, b) {\n const delta = b.subtract(a);\n const theta = Math.atan2(delta.y, delta.x);\n return new Angle(theta);\n }\n /**\n * Gets a new Angle object from the given float in radians\n * @param radians defines the angle value in radians\n * @returns a new Angle\n */\n static FromRadians(radians) {\n return new Angle(radians);\n }\n /**\n * Gets a new Angle object from the given float in degrees\n * @param degrees defines the angle value in degrees\n * @returns a new Angle\n */\n static FromDegrees(degrees) {\n return new Angle((degrees * Math.PI) / 180.0);\n }\n }\n /**\n * This represents an arc in a 2d space.\n */\n class Arc2 {\n /**\n * Creates an Arc object from the three given points : start, middle and end.\n * @param startPoint Defines the start point of the arc\n * @param midPoint Defines the middle point of the arc\n * @param endPoint Defines the end point of the arc\n */\n constructor(\n /** Defines the start point of the arc */\n startPoint, \n /** Defines the mid point of the arc */\n midPoint, \n /** Defines the end point of the arc */\n endPoint) {\n this.startPoint = startPoint;\n this.midPoint = midPoint;\n this.endPoint = endPoint;\n const temp = Math.pow(midPoint.x, 2) + Math.pow(midPoint.y, 2);\n const startToMid = (Math.pow(startPoint.x, 2) + Math.pow(startPoint.y, 2) - temp) / 2;\n const midToEnd = (temp - Math.pow(endPoint.x, 2) - Math.pow(endPoint.y, 2)) / 2;\n const det = (startPoint.x - midPoint.x) * (midPoint.y - endPoint.y) - (midPoint.x - endPoint.x) * (startPoint.y - midPoint.y);\n this.centerPoint = new Vector2((startToMid * (midPoint.y - endPoint.y) - midToEnd * (startPoint.y - midPoint.y)) / det, ((startPoint.x - midPoint.x) * midToEnd - (midPoint.x - endPoint.x) * startToMid) / det);\n this.radius = this.centerPoint.subtract(this.startPoint).length();\n this.startAngle = Angle.BetweenTwoPoints(this.centerPoint, this.startPoint);\n const a1 = this.startAngle.degrees();\n let a2 = Angle.BetweenTwoPoints(this.centerPoint, this.midPoint).degrees();\n let a3 = Angle.BetweenTwoPoints(this.centerPoint, this.endPoint).degrees();\n // angles correction\n if (a2 - a1 > +180.0) {\n a2 -= 360.0;\n }\n if (a2 - a1 < -180.0) {\n a2 += 360.0;\n }\n if (a3 - a2 > +180.0) {\n a3 -= 360.0;\n }\n if (a3 - a2 < -180.0) {\n a3 += 360.0;\n }\n this.orientation = a2 - a1 < 0 ? Orientation.CW : Orientation.CCW;\n this.angle = Angle.FromDegrees(this.orientation === Orientation.CW ? a1 - a3 : a3 - a1);\n }\n }\n /**\n * Represents a 2D path made up of multiple 2D points\n */\n class Path2 {\n /**\n * Creates a Path2 object from the starting 2D coordinates x and y.\n * @param x the starting points x value\n * @param y the starting points y value\n */\n constructor(x, y) {\n this._points = new Array();\n this._length = 0.0;\n /**\n * If the path start and end point are the same\n */\n this.closed = false;\n this._points.push(new Vector2(x, y));\n }\n /**\n * Adds a new segment until the given coordinates (x, y) to the current Path2.\n * @param x the added points x value\n * @param y the added points y value\n * @returns the updated Path2.\n */\n addLineTo(x, y) {\n if (this.closed) {\n return this;\n }\n const newPoint = new Vector2(x, y);\n const previousPoint = this._points[this._points.length - 1];\n this._points.push(newPoint);\n this._length += newPoint.subtract(previousPoint).length();\n return this;\n }\n /**\n * Adds _numberOfSegments_ segments according to the arc definition (middle point coordinates, end point coordinates, the arc start point being the current Path2 last point) to the current Path2.\n * @param midX middle point x value\n * @param midY middle point y value\n * @param endX end point x value\n * @param endY end point y value\n * @param numberOfSegments (default: 36)\n * @returns the updated Path2.\n */\n addArcTo(midX, midY, endX, endY, numberOfSegments = 36) {\n if (this.closed) {\n return this;\n }\n const startPoint = this._points[this._points.length - 1];\n const midPoint = new Vector2(midX, midY);\n const endPoint = new Vector2(endX, endY);\n const arc = new Arc2(startPoint, midPoint, endPoint);\n let increment = arc.angle.radians() / numberOfSegments;\n if (arc.orientation === Orientation.CW) {\n increment *= -1;\n }\n let currentAngle = arc.startAngle.radians() + increment;\n for (let i = 0; i < numberOfSegments; i++) {\n const x = Math.cos(currentAngle) * arc.radius + arc.centerPoint.x;\n const y = Math.sin(currentAngle) * arc.radius + arc.centerPoint.y;\n this.addLineTo(x, y);\n currentAngle += increment;\n }\n return this;\n }\n /**\n * Adds _numberOfSegments_ segments according to the quadratic curve definition to the current Path2.\n * @param controlX control point x value\n * @param controlY control point y value\n * @param endX end point x value\n * @param endY end point y value\n * @param numberOfSegments (default: 36)\n * @returns the updated Path2.\n */\n addQuadraticCurveTo(controlX, controlY, endX, endY, numberOfSegments = 36) {\n if (this.closed) {\n return this;\n }\n const equation = (t, val0, val1, val2) => {\n const res = (1.0 - t) * (1.0 - t) * val0 + 2.0 * t * (1.0 - t) * val1 + t * t * val2;\n return res;\n };\n const startPoint = this._points[this._points.length - 1];\n for (let i = 0; i <= numberOfSegments; i++) {\n const step = i / numberOfSegments;\n const x = equation(step, startPoint.x, controlX, endX);\n const y = equation(step, startPoint.y, controlY, endY);\n this.addLineTo(x, y);\n }\n return this;\n }\n /**\n * Adds _numberOfSegments_ segments according to the bezier curve definition to the current Path2.\n * @param originTangentX tangent vector at the origin point x value\n * @param originTangentY tangent vector at the origin point y value\n * @param destinationTangentX tangent vector at the destination point x value\n * @param destinationTangentY tangent vector at the destination point y value\n * @param endX end point x value\n * @param endY end point y value\n * @param numberOfSegments (default: 36)\n * @returns the updated Path2.\n */\n addBezierCurveTo(originTangentX, originTangentY, destinationTangentX, destinationTangentY, endX, endY, numberOfSegments = 36) {\n if (this.closed) {\n return this;\n }\n const equation = (t, val0, val1, val2, val3) => {\n const res = (1.0 - t) * (1.0 - t) * (1.0 - t) * val0 + 3.0 * t * (1.0 - t) * (1.0 - t) * val1 + 3.0 * t * t * (1.0 - t) * val2 + t * t * t * val3;\n return res;\n };\n const startPoint = this._points[this._points.length - 1];\n for (let i = 0; i <= numberOfSegments; i++) {\n const step = i / numberOfSegments;\n const x = equation(step, startPoint.x, originTangentX, destinationTangentX, endX);\n const y = equation(step, startPoint.y, originTangentY, destinationTangentY, endY);\n this.addLineTo(x, y);\n }\n return this;\n }\n /**\n * Defines if a given point is inside the polygon defines by the path\n * @param point defines the point to test\n * @returns true if the point is inside\n */\n isPointInside(point) {\n let isInside = false;\n const count = this._points.length;\n for (let p = count - 1, q = 0; q < count; p = q++) {\n let edgeLow = this._points[p];\n let edgeHigh = this._points[q];\n let edgeDx = edgeHigh.x - edgeLow.x;\n let edgeDy = edgeHigh.y - edgeLow.y;\n if (Math.abs(edgeDy) > Number.EPSILON) {\n // Not parallel\n if (edgeDy < 0) {\n edgeLow = this._points[q];\n edgeDx = -edgeDx;\n edgeHigh = this._points[p];\n edgeDy = -edgeDy;\n }\n if (point.y < edgeLow.y || point.y > edgeHigh.y) {\n continue;\n }\n if (point.y === edgeLow.y && point.x === edgeLow.x) {\n return true;\n }\n else {\n const perpEdge = edgeDy * (point.x - edgeLow.x) - edgeDx * (point.y - edgeLow.y);\n if (perpEdge === 0) {\n return true;\n }\n if (perpEdge < 0) {\n continue;\n }\n isInside = !isInside;\n }\n }\n else {\n // parallel or collinear\n if (point.y !== edgeLow.y) {\n continue;\n }\n if ((edgeHigh.x <= point.x && point.x <= edgeLow.x) || (edgeLow.x <= point.x && point.x <= edgeHigh.x)) {\n return true;\n }\n }\n }\n return isInside;\n }\n /**\n * Closes the Path2.\n * @returns the Path2.\n */\n close() {\n this.closed = true;\n return this;\n }\n /**\n * Gets the sum of the distance between each sequential point in the path\n * @returns the Path2 total length (float).\n */\n length() {\n let result = this._length;\n if (this.closed) {\n const lastPoint = this._points[this._points.length - 1];\n const firstPoint = this._points[0];\n result += firstPoint.subtract(lastPoint).length();\n }\n return result;\n }\n /**\n * Gets the area of the polygon defined by the path\n * @returns area value\n */\n area() {\n const n = this._points.length;\n let value = 0.0;\n for (let p = n - 1, q = 0; q < n; p = q++) {\n value += this._points[p].x * this._points[q].y - this._points[q].x * this._points[p].y;\n }\n return value * 0.5;\n }\n /**\n * Gets the points which construct the path\n * @returns the Path2 internal array of points.\n */\n getPoints() {\n return this._points;\n }\n /**\n * Retreives the point at the distance aways from the starting point\n * @param normalizedLengthPosition the length along the path to retrieve the point from\n * @returns a new Vector2 located at a percentage of the Path2 total length on this path.\n */\n getPointAtLengthPosition(normalizedLengthPosition) {\n if (normalizedLengthPosition < 0 || normalizedLengthPosition > 1) {\n return Vector2.Zero();\n }\n const lengthPosition = normalizedLengthPosition * this.length();\n let previousOffset = 0;\n for (let i = 0; i < this._points.length; i++) {\n const j = (i + 1) % this._points.length;\n const a = this._points[i];\n const b = this._points[j];\n const bToA = b.subtract(a);\n const nextOffset = bToA.length() + previousOffset;\n if (lengthPosition >= previousOffset && lengthPosition <= nextOffset) {\n const dir = bToA.normalize();\n const localOffset = lengthPosition - previousOffset;\n return new Vector2(a.x + dir.x * localOffset, a.y + dir.y * localOffset);\n }\n previousOffset = nextOffset;\n }\n return Vector2.Zero();\n }\n /**\n * Creates a new path starting from an x and y position\n * @param x starting x value\n * @param y starting y value\n * @returns a new Path2 starting at the coordinates (x, y).\n */\n static StartingAt(x, y) {\n return new Path2(x, y);\n }\n }\n /**\n * Represents a 3D path made up of multiple 3D points\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D\n */\n class Path3D {\n /**\n * new Path3D(path, normal, raw)\n * Creates a Path3D. A Path3D is a logical math object, so not a mesh.\n * please read the description in the tutorial : https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D\n * @param path an array of Vector3, the curve axis of the Path3D\n * @param firstNormal (options) Vector3, the first wanted normal to the curve. Ex (0, 1, 0) for a vertical normal.\n * @param raw (optional, default false) : boolean, if true the returned Path3D isn't normalized. Useful to depict path acceleration or speed.\n * @param alignTangentsWithPath (optional, default false) : boolean, if true the tangents will be aligned with the path.\n */\n constructor(\n /**\n * an array of Vector3, the curve axis of the Path3D\n */\n path, firstNormal = null, raw, alignTangentsWithPath = false) {\n this.path = path;\n this._curve = new Array();\n this._distances = new Array();\n this._tangents = new Array();\n this._normals = new Array();\n this._binormals = new Array();\n // holds interpolated point data\n this._pointAtData = {\n id: 0,\n point: Vector3.Zero(),\n previousPointArrayIndex: 0,\n position: 0,\n subPosition: 0,\n interpolateReady: false,\n interpolationMatrix: Matrix.Identity(),\n };\n for (let p = 0; p < path.length; p++) {\n this._curve[p] = path[p].clone(); // hard copy\n }\n this._raw = raw || false;\n this._alignTangentsWithPath = alignTangentsWithPath;\n this._compute(firstNormal, alignTangentsWithPath);\n }\n /**\n * Returns the Path3D array of successive Vector3 designing its curve.\n * @returns the Path3D array of successive Vector3 designing its curve.\n */\n getCurve() {\n return this._curve;\n }\n /**\n * Returns the Path3D array of successive Vector3 designing its curve.\n * @returns the Path3D array of successive Vector3 designing its curve.\n */\n getPoints() {\n return this._curve;\n }\n /**\n * @returns the computed length (float) of the path.\n */\n length() {\n return this._distances[this._distances.length - 1];\n }\n /**\n * Returns an array populated with tangent vectors on each Path3D curve point.\n * @returns an array populated with tangent vectors on each Path3D curve point.\n */\n getTangents() {\n return this._tangents;\n }\n /**\n * Returns an array populated with normal vectors on each Path3D curve point.\n * @returns an array populated with normal vectors on each Path3D curve point.\n */\n getNormals() {\n return this._normals;\n }\n /**\n * Returns an array populated with binormal vectors on each Path3D curve point.\n * @returns an array populated with binormal vectors on each Path3D curve point.\n */\n getBinormals() {\n return this._binormals;\n }\n /**\n * Returns an array populated with distances (float) of the i-th point from the first curve point.\n * @returns an array populated with distances (float) of the i-th point from the first curve point.\n */\n getDistances() {\n return this._distances;\n }\n /**\n * Returns an interpolated point along this path\n * @param position the position of the point along this path, from 0.0 to 1.0\n * @returns a new Vector3 as the point\n */\n getPointAt(position) {\n return this._updatePointAtData(position).point;\n }\n /**\n * Returns the tangent vector of an interpolated Path3D curve point at the specified position along this path.\n * @param position the position of the point along this path, from 0.0 to 1.0\n * @param interpolated (optional, default false) : boolean, if true returns an interpolated tangent instead of the tangent of the previous path point.\n * @returns a tangent vector corresponding to the interpolated Path3D curve point, if not interpolated, the tangent is taken from the precomputed tangents array.\n */\n getTangentAt(position, interpolated = false) {\n this._updatePointAtData(position, interpolated);\n return interpolated ? Vector3.TransformCoordinates(Vector3.Forward(), this._pointAtData.interpolationMatrix) : this._tangents[this._pointAtData.previousPointArrayIndex];\n }\n /**\n * Returns the tangent vector of an interpolated Path3D curve point at the specified position along this path.\n * @param position the position of the point along this path, from 0.0 to 1.0\n * @param interpolated (optional, default false) : boolean, if true returns an interpolated normal instead of the normal of the previous path point.\n * @returns a normal vector corresponding to the interpolated Path3D curve point, if not interpolated, the normal is taken from the precomputed normals array.\n */\n getNormalAt(position, interpolated = false) {\n this._updatePointAtData(position, interpolated);\n return interpolated ? Vector3.TransformCoordinates(Vector3.Right(), this._pointAtData.interpolationMatrix) : this._normals[this._pointAtData.previousPointArrayIndex];\n }\n /**\n * Returns the binormal vector of an interpolated Path3D curve point at the specified position along this path.\n * @param position the position of the point along this path, from 0.0 to 1.0\n * @param interpolated (optional, default false) : boolean, if true returns an interpolated binormal instead of the binormal of the previous path point.\n * @returns a binormal vector corresponding to the interpolated Path3D curve point, if not interpolated, the binormal is taken from the precomputed binormals array.\n */\n getBinormalAt(position, interpolated = false) {\n this._updatePointAtData(position, interpolated);\n return interpolated ? Vector3.TransformCoordinates(Vector3.UpReadOnly, this._pointAtData.interpolationMatrix) : this._binormals[this._pointAtData.previousPointArrayIndex];\n }\n /**\n * Returns the distance (float) of an interpolated Path3D curve point at the specified position along this path.\n * @param position the position of the point along this path, from 0.0 to 1.0\n * @returns the distance of the interpolated Path3D curve point at the specified position along this path.\n */\n getDistanceAt(position) {\n return this.length() * position;\n }\n /**\n * Returns the array index of the previous point of an interpolated point along this path\n * @param position the position of the point to interpolate along this path, from 0.0 to 1.0\n * @returns the array index\n */\n getPreviousPointIndexAt(position) {\n this._updatePointAtData(position);\n return this._pointAtData.previousPointArrayIndex;\n }\n /**\n * Returns the position of an interpolated point relative to the two path points it lies between, from 0.0 (point A) to 1.0 (point B)\n * @param position the position of the point to interpolate along this path, from 0.0 to 1.0\n * @returns the sub position\n */\n getSubPositionAt(position) {\n this._updatePointAtData(position);\n return this._pointAtData.subPosition;\n }\n /**\n * Returns the position of the closest virtual point on this path to an arbitrary Vector3, from 0.0 to 1.0\n * @param target the vector of which to get the closest position to\n * @returns the position of the closest virtual point on this path to the target vector\n */\n getClosestPositionTo(target) {\n let smallestDistance = Number.MAX_VALUE;\n let closestPosition = 0.0;\n for (let i = 0; i < this._curve.length - 1; i++) {\n const point = this._curve[i + 0];\n const tangent = this._curve[i + 1].subtract(point).normalize();\n const subLength = this._distances[i + 1] - this._distances[i + 0];\n const subPosition = Math.min((Math.max(Vector3.Dot(tangent, target.subtract(point).normalize()), 0.0) * Vector3.Distance(point, target)) / subLength, 1.0);\n const distance = Vector3.Distance(point.add(tangent.scale(subPosition * subLength)), target);\n if (distance < smallestDistance) {\n smallestDistance = distance;\n closestPosition = (this._distances[i + 0] + subLength * subPosition) / this.length();\n }\n }\n return closestPosition;\n }\n /**\n * Returns a sub path (slice) of this path\n * @param start the position of the fist path point, from 0.0 to 1.0, or a negative value, which will get wrapped around from the end of the path to 0.0 to 1.0 values\n * @param end the position of the last path point, from 0.0 to 1.0, or a negative value, which will get wrapped around from the end of the path to 0.0 to 1.0 values\n * @returns a sub path (slice) of this path\n */\n slice(start = 0.0, end = 1.0) {\n if (start < 0.0) {\n start = 1 - ((start * -1.0) % 1.0);\n }\n if (end < 0.0) {\n end = 1 - ((end * -1.0) % 1.0);\n }\n if (start > end) {\n const _start = start;\n start = end;\n end = _start;\n }\n const curvePoints = this.getCurve();\n const startPoint = this.getPointAt(start);\n let startIndex = this.getPreviousPointIndexAt(start);\n const endPoint = this.getPointAt(end);\n const endIndex = this.getPreviousPointIndexAt(end) + 1;\n const slicePoints = [];\n if (start !== 0.0) {\n startIndex++;\n slicePoints.push(startPoint);\n }\n slicePoints.push(...curvePoints.slice(startIndex, endIndex));\n if (end !== 1.0 || start === 1.0) {\n slicePoints.push(endPoint);\n }\n return new Path3D(slicePoints, this.getNormalAt(start), this._raw, this._alignTangentsWithPath);\n }\n /**\n * Forces the Path3D tangent, normal, binormal and distance recomputation.\n * @param path path which all values are copied into the curves points\n * @param firstNormal which should be projected onto the curve\n * @param alignTangentsWithPath (optional, default false) : boolean, if true the tangents will be aligned with the path\n * @returns the same object updated.\n */\n update(path, firstNormal = null, alignTangentsWithPath = false) {\n for (let p = 0; p < path.length; p++) {\n this._curve[p].x = path[p].x;\n this._curve[p].y = path[p].y;\n this._curve[p].z = path[p].z;\n }\n this._compute(firstNormal, alignTangentsWithPath);\n return this;\n }\n // private function compute() : computes tangents, normals and binormals\n _compute(firstNormal, alignTangentsWithPath = false) {\n const l = this._curve.length;\n if (l < 2) {\n return;\n }\n // first and last tangents\n this._tangents[0] = this._getFirstNonNullVector(0);\n if (!this._raw) {\n this._tangents[0].normalize();\n }\n this._tangents[l - 1] = this._curve[l - 1].subtract(this._curve[l - 2]);\n if (!this._raw) {\n this._tangents[l - 1].normalize();\n }\n // normals and binormals at first point : arbitrary vector with _normalVector()\n const tg0 = this._tangents[0];\n const pp0 = this._normalVector(tg0, firstNormal);\n this._normals[0] = pp0;\n if (!this._raw) {\n this._normals[0].normalize();\n }\n this._binormals[0] = Vector3.Cross(tg0, this._normals[0]);\n if (!this._raw) {\n this._binormals[0].normalize();\n }\n this._distances[0] = 0.0;\n // normals and binormals : next points\n let prev; // previous vector (segment)\n let cur; // current vector (segment)\n let curTang; // current tangent\n // previous normal\n let prevNor; // previous normal\n let prevBinor; // previous binormal\n for (let i = 1; i < l; i++) {\n // tangents\n prev = this._getLastNonNullVector(i);\n if (i < l - 1) {\n cur = this._getFirstNonNullVector(i);\n this._tangents[i] = alignTangentsWithPath ? cur : prev.add(cur);\n this._tangents[i].normalize();\n }\n this._distances[i] = this._distances[i - 1] + this._curve[i].subtract(this._curve[i - 1]).length();\n // normals and binormals\n // http://www.cs.cmu.edu/afs/andrew/scs/cs/15-462/web/old/asst2camera.html\n curTang = this._tangents[i];\n prevBinor = this._binormals[i - 1];\n this._normals[i] = Vector3.Cross(prevBinor, curTang);\n if (!this._raw) {\n if (this._normals[i].length() === 0) {\n prevNor = this._normals[i - 1];\n this._normals[i] = prevNor.clone();\n }\n else {\n this._normals[i].normalize();\n }\n }\n this._binormals[i] = Vector3.Cross(curTang, this._normals[i]);\n if (!this._raw) {\n this._binormals[i].normalize();\n }\n }\n this._pointAtData.id = NaN;\n }\n // private function getFirstNonNullVector(index)\n // returns the first non null vector from index : curve[index + N].subtract(curve[index])\n _getFirstNonNullVector(index) {\n let i = 1;\n let nNVector = this._curve[index + i].subtract(this._curve[index]);\n while (nNVector.length() === 0 && index + i + 1 < this._curve.length) {\n i++;\n nNVector = this._curve[index + i].subtract(this._curve[index]);\n }\n return nNVector;\n }\n // private function getLastNonNullVector(index)\n // returns the last non null vector from index : curve[index].subtract(curve[index - N])\n _getLastNonNullVector(index) {\n let i = 1;\n let nLVector = this._curve[index].subtract(this._curve[index - i]);\n while (nLVector.length() === 0 && index > i + 1) {\n i++;\n nLVector = this._curve[index].subtract(this._curve[index - i]);\n }\n return nLVector;\n }\n // private function normalVector(v0, vt, va) :\n // returns an arbitrary point in the plane defined by the point v0 and the vector vt orthogonal to this plane\n // if va is passed, it returns the va projection on the plane orthogonal to vt at the point v0\n _normalVector(vt, va) {\n let normal0;\n let tgl = vt.length();\n if (tgl === 0.0) {\n tgl = 1.0;\n }\n if (va === undefined || va === null) {\n let point;\n if (!Scalar.WithinEpsilon(Math.abs(vt.y) / tgl, 1.0, Epsilon)) {\n // search for a point in the plane\n point = new Vector3(0.0, -1.0, 0.0);\n }\n else if (!Scalar.WithinEpsilon(Math.abs(vt.x) / tgl, 1.0, Epsilon)) {\n point = new Vector3(1.0, 0.0, 0.0);\n }\n else if (!Scalar.WithinEpsilon(Math.abs(vt.z) / tgl, 1.0, Epsilon)) {\n point = new Vector3(0.0, 0.0, 1.0);\n }\n else {\n point = Vector3.Zero();\n }\n normal0 = Vector3.Cross(vt, point);\n }\n else {\n normal0 = Vector3.Cross(vt, va);\n Vector3.CrossToRef(normal0, vt, normal0);\n }\n normal0.normalize();\n return normal0;\n }\n /**\n * Updates the point at data for an interpolated point along this curve\n * @param position the position of the point along this curve, from 0.0 to 1.0\n * @param interpolateTNB\n * @interpolateTNB whether to compute the interpolated tangent, normal and binormal\n * @returns the (updated) point at data\n */\n _updatePointAtData(position, interpolateTNB = false) {\n // set an id for caching the result\n if (this._pointAtData.id === position) {\n if (!this._pointAtData.interpolateReady) {\n this._updateInterpolationMatrix();\n }\n return this._pointAtData;\n }\n else {\n this._pointAtData.id = position;\n }\n const curvePoints = this.getPoints();\n // clamp position between 0.0 and 1.0\n if (position <= 0.0) {\n return this._setPointAtData(0.0, 0.0, curvePoints[0], 0, interpolateTNB);\n }\n else if (position >= 1.0) {\n return this._setPointAtData(1.0, 1.0, curvePoints[curvePoints.length - 1], curvePoints.length - 1, interpolateTNB);\n }\n let previousPoint = curvePoints[0];\n let currentPoint;\n let currentLength = 0.0;\n const targetLength = position * this.length();\n for (let i = 1; i < curvePoints.length; i++) {\n currentPoint = curvePoints[i];\n const distance = Vector3.Distance(previousPoint, currentPoint);\n currentLength += distance;\n if (currentLength === targetLength) {\n return this._setPointAtData(position, 1.0, currentPoint, i, interpolateTNB);\n }\n else if (currentLength > targetLength) {\n const toLength = currentLength - targetLength;\n const diff = toLength / distance;\n const dir = previousPoint.subtract(currentPoint);\n const point = currentPoint.add(dir.scaleInPlace(diff));\n return this._setPointAtData(position, 1 - diff, point, i - 1, interpolateTNB);\n }\n previousPoint = currentPoint;\n }\n return this._pointAtData;\n }\n /**\n * Updates the point at data from the specified parameters\n * @param position where along the path the interpolated point is, from 0.0 to 1.0\n * @param subPosition\n * @param point the interpolated point\n * @param parentIndex the index of an existing curve point that is on, or else positionally the first behind, the interpolated point\n * @param interpolateTNB\n */\n _setPointAtData(position, subPosition, point, parentIndex, interpolateTNB) {\n this._pointAtData.point = point;\n this._pointAtData.position = position;\n this._pointAtData.subPosition = subPosition;\n this._pointAtData.previousPointArrayIndex = parentIndex;\n this._pointAtData.interpolateReady = interpolateTNB;\n if (interpolateTNB) {\n this._updateInterpolationMatrix();\n }\n return this._pointAtData;\n }\n /**\n * Updates the point at interpolation matrix for the tangents, normals and binormals\n */\n _updateInterpolationMatrix() {\n this._pointAtData.interpolationMatrix = Matrix.Identity();\n const parentIndex = this._pointAtData.previousPointArrayIndex;\n if (parentIndex !== this._tangents.length - 1) {\n const index = parentIndex + 1;\n const tangentFrom = this._tangents[parentIndex].clone();\n const normalFrom = this._normals[parentIndex].clone();\n const binormalFrom = this._binormals[parentIndex].clone();\n const tangentTo = this._tangents[index].clone();\n const normalTo = this._normals[index].clone();\n const binormalTo = this._binormals[index].clone();\n const quatFrom = Quaternion.RotationQuaternionFromAxis(normalFrom, binormalFrom, tangentFrom);\n const quatTo = Quaternion.RotationQuaternionFromAxis(normalTo, binormalTo, tangentTo);\n const quatAt = Quaternion.Slerp(quatFrom, quatTo, this._pointAtData.subPosition);\n quatAt.toRotationMatrix(this._pointAtData.interpolationMatrix);\n }\n }\n }\n /**\n * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.\n * A Curve3 is designed from a series of successive Vector3.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves\n */\n class Curve3 {\n /**\n * Returns a Curve3 object along a Quadratic Bezier curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#quadratic-bezier-curve\n * @param v0 (Vector3) the origin point of the Quadratic Bezier\n * @param v1 (Vector3) the control point\n * @param v2 (Vector3) the end point of the Quadratic Bezier\n * @param nbPoints (integer) the wanted number of points in the curve\n * @returns the created Curve3\n */\n static CreateQuadraticBezier(v0, v1, v2, nbPoints) {\n nbPoints = nbPoints > 2 ? nbPoints : 3;\n const bez = new Array();\n const equation = (t, val0, val1, val2) => {\n const res = (1.0 - t) * (1.0 - t) * val0 + 2.0 * t * (1.0 - t) * val1 + t * t * val2;\n return res;\n };\n for (let i = 0; i <= nbPoints; i++) {\n bez.push(new Vector3(equation(i / nbPoints, v0.x, v1.x, v2.x), equation(i / nbPoints, v0.y, v1.y, v2.y), equation(i / nbPoints, v0.z, v1.z, v2.z)));\n }\n return new Curve3(bez);\n }\n /**\n * Returns a Curve3 object along a Cubic Bezier curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#cubic-bezier-curve\n * @param v0 (Vector3) the origin point of the Cubic Bezier\n * @param v1 (Vector3) the first control point\n * @param v2 (Vector3) the second control point\n * @param v3 (Vector3) the end point of the Cubic Bezier\n * @param nbPoints (integer) the wanted number of points in the curve\n * @returns the created Curve3\n */\n static CreateCubicBezier(v0, v1, v2, v3, nbPoints) {\n nbPoints = nbPoints > 3 ? nbPoints : 4;\n const bez = new Array();\n const equation = (t, val0, val1, val2, val3) => {\n const res = (1.0 - t) * (1.0 - t) * (1.0 - t) * val0 + 3.0 * t * (1.0 - t) * (1.0 - t) * val1 + 3.0 * t * t * (1.0 - t) * val2 + t * t * t * val3;\n return res;\n };\n for (let i = 0; i <= nbPoints; i++) {\n bez.push(new Vector3(equation(i / nbPoints, v0.x, v1.x, v2.x, v3.x), equation(i / nbPoints, v0.y, v1.y, v2.y, v3.y), equation(i / nbPoints, v0.z, v1.z, v2.z, v3.z)));\n }\n return new Curve3(bez);\n }\n /**\n * Returns a Curve3 object along a Hermite Spline curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-spline\n * @param p1 (Vector3) the origin point of the Hermite Spline\n * @param t1 (Vector3) the tangent vector at the origin point\n * @param p2 (Vector3) the end point of the Hermite Spline\n * @param t2 (Vector3) the tangent vector at the end point\n * @param nSeg (integer) the number of curve segments or nSeg + 1 points in the array\n * @returns the created Curve3\n */\n static CreateHermiteSpline(p1, t1, p2, t2, nSeg) {\n const hermite = new Array();\n const step = 1.0 / nSeg;\n for (let i = 0; i <= nSeg; i++) {\n hermite.push(Vector3.Hermite(p1, t1, p2, t2, i * step));\n }\n return new Curve3(hermite);\n }\n /**\n * Returns a Curve3 object along a CatmullRom Spline curve :\n * @param points (array of Vector3) the points the spline must pass through. At least, four points required\n * @param nbPoints (integer) the wanted number of points between each curve control points\n * @param closed (boolean) optional with default false, when true forms a closed loop from the points\n * @returns the created Curve3\n */\n static CreateCatmullRomSpline(points, nbPoints, closed) {\n const catmullRom = new Array();\n const step = 1.0 / nbPoints;\n let amount = 0.0;\n if (closed) {\n const pointsCount = points.length;\n for (let i = 0; i < pointsCount; i++) {\n amount = 0;\n for (let c = 0; c < nbPoints; c++) {\n catmullRom.push(Vector3.CatmullRom(points[i % pointsCount], points[(i + 1) % pointsCount], points[(i + 2) % pointsCount], points[(i + 3) % pointsCount], amount));\n amount += step;\n }\n }\n catmullRom.push(catmullRom[0]);\n }\n else {\n const totalPoints = new Array();\n totalPoints.push(points[0].clone());\n Array.prototype.push.apply(totalPoints, points);\n totalPoints.push(points[points.length - 1].clone());\n let i = 0;\n for (; i < totalPoints.length - 3; i++) {\n amount = 0;\n for (let c = 0; c < nbPoints; c++) {\n catmullRom.push(Vector3.CatmullRom(totalPoints[i], totalPoints[i + 1], totalPoints[i + 2], totalPoints[i + 3], amount));\n amount += step;\n }\n }\n i--;\n catmullRom.push(Vector3.CatmullRom(totalPoints[i], totalPoints[i + 1], totalPoints[i + 2], totalPoints[i + 3], amount));\n }\n return new Curve3(catmullRom);\n }\n /**\n * Returns a Curve3 object along an arc through three vector3 points:\n * The three points should not be colinear. When they are the Curve3 is empty.\n * @param first (Vector3) the first point the arc must pass through.\n * @param second (Vector3) the second point the arc must pass through.\n * @param third (Vector3) the third point the arc must pass through.\n * @param steps (number) the larger the number of steps the more detailed the arc.\n * @param closed (boolean) optional with default false, when true forms the chord from the first and third point\n * @param fullCircle Circle (boolean) optional with default false, when true forms the complete circle through the three points\n * @returns the created Curve3\n */\n static ArcThru3Points(first, second, third, steps = 32, closed = false, fullCircle = false) {\n const arc = new Array();\n const vec1 = second.subtract(first);\n const vec2 = third.subtract(second);\n const vec3 = first.subtract(third);\n const zAxis = Vector3.Cross(vec1, vec2);\n const len4 = zAxis.length();\n if (len4 < Math.pow(10, -8)) {\n return new Curve3(arc); // colinear points arc is empty\n }\n const len1_sq = vec1.lengthSquared();\n const len2_sq = vec2.lengthSquared();\n const len3_sq = vec3.lengthSquared();\n const len4_sq = zAxis.lengthSquared();\n const len1 = vec1.length();\n const len2 = vec2.length();\n const len3 = vec3.length();\n const radius = (0.5 * len1 * len2 * len3) / len4;\n const dot1 = Vector3.Dot(vec1, vec3);\n const dot2 = Vector3.Dot(vec1, vec2);\n const dot3 = Vector3.Dot(vec2, vec3);\n const a = (-0.5 * len2_sq * dot1) / len4_sq;\n const b = (-0.5 * len3_sq * dot2) / len4_sq;\n const c = (-0.5 * len1_sq * dot3) / len4_sq;\n const center = first.scale(a).add(second.scale(b)).add(third.scale(c));\n const radiusVec = first.subtract(center);\n const xAxis = radiusVec.normalize();\n const yAxis = Vector3.Cross(zAxis, xAxis).normalize();\n if (fullCircle) {\n const dStep = (2 * Math.PI) / steps;\n for (let theta = 0; theta <= 2 * Math.PI; theta += dStep) {\n arc.push(center.add(xAxis.scale(radius * Math.cos(theta)).add(yAxis.scale(radius * Math.sin(theta)))));\n }\n arc.push(first);\n }\n else {\n const dStep = 1 / steps;\n let theta = 0;\n let point = Vector3.Zero();\n do {\n point = center.add(xAxis.scale(radius * Math.cos(theta)).add(yAxis.scale(radius * Math.sin(theta))));\n arc.push(point);\n theta += dStep;\n } while (!point.equalsWithEpsilon(third, radius * dStep * 1.1));\n arc.push(third);\n if (closed) {\n arc.push(first);\n }\n }\n return new Curve3(arc);\n }\n /**\n * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.\n * A Curve3 is designed from a series of successive Vector3.\n * Tuto : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#curve3-object\n * @param points points which make up the curve\n */\n constructor(points) {\n this._length = 0.0;\n this._points = points;\n this._length = this._computeLength(points);\n }\n /**\n * @returns the Curve3 stored array of successive Vector3\n */\n getPoints() {\n return this._points;\n }\n /**\n * @returns the computed length (float) of the curve.\n */\n length() {\n return this._length;\n }\n /**\n * Returns a new instance of Curve3 object : var curve = curveA.continue(curveB);\n * This new Curve3 is built by translating and sticking the curveB at the end of the curveA.\n * curveA and curveB keep unchanged.\n * @param curve the curve to continue from this curve\n * @returns the newly constructed curve\n */\n continue(curve) {\n const lastPoint = this._points[this._points.length - 1];\n const continuedPoints = this._points.slice();\n const curvePoints = curve.getPoints();\n for (let i = 1; i < curvePoints.length; i++) {\n continuedPoints.push(curvePoints[i].subtract(curvePoints[0]).add(lastPoint));\n }\n const continuedCurve = new Curve3(continuedPoints);\n return continuedCurve;\n }\n _computeLength(path) {\n let l = 0;\n for (let i = 1; i < path.length; i++) {\n l += path[i].subtract(path[i - 1]).length();\n }\n return l;\n }\n }\n\n /**\n * Base class used for every default easing function.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\n */\n class EasingFunction {\n constructor() {\n this._easingMode = EasingFunction.EASINGMODE_EASEIN;\n }\n /**\n * Sets the easing mode of the current function.\n * @param easingMode Defines the willing mode (EASINGMODE_EASEIN, EASINGMODE_EASEOUT or EASINGMODE_EASEINOUT)\n */\n setEasingMode(easingMode) {\n const n = Math.min(Math.max(easingMode, 0), 2);\n this._easingMode = n;\n }\n /**\n * Gets the current easing mode.\n * @returns the easing mode\n */\n getEasingMode() {\n return this._easingMode;\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n easeInCore(gradient) {\n throw new Error(\"You must implement this method\");\n }\n /**\n * Given an input gradient between 0 and 1, this returns the corresponding value\n * of the easing function.\n * @param gradient Defines the value between 0 and 1 we want the easing value for\n * @returns the corresponding value on the curve defined by the easing function\n */\n ease(gradient) {\n switch (this._easingMode) {\n case EasingFunction.EASINGMODE_EASEIN:\n return this.easeInCore(gradient);\n case EasingFunction.EASINGMODE_EASEOUT:\n return 1 - this.easeInCore(1 - gradient);\n }\n if (gradient >= 0.5) {\n return (1 - this.easeInCore((1 - gradient) * 2)) * 0.5 + 0.5;\n }\n return this.easeInCore(gradient * 2) * 0.5;\n }\n }\n /**\n * Interpolation follows the mathematical formula associated with the easing function.\n */\n EasingFunction.EASINGMODE_EASEIN = 0;\n /**\n * Interpolation follows 100% interpolation minus the output of the formula associated with the easing function.\n */\n EasingFunction.EASINGMODE_EASEOUT = 1;\n /**\n * Interpolation uses EaseIn for the first half of the animation and EaseOut for the second half.\n */\n EasingFunction.EASINGMODE_EASEINOUT = 2;\n /**\n * Easing function with a circle shape (see link below).\n * @see https://easings.net/#easeInCirc\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\n */\n class CircleEase extends EasingFunction {\n /**\n * @internal\n */\n easeInCore(gradient) {\n gradient = Math.max(0, Math.min(1, gradient));\n return 1.0 - Math.sqrt(1.0 - gradient * gradient);\n }\n }\n /**\n * Easing function with a ease back shape (see link below).\n * @see https://easings.net/#easeInBack\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\n */\n class BackEase extends EasingFunction {\n /**\n * Instantiates a back ease easing\n * @see https://easings.net/#easeInBack\n * @param amplitude Defines the amplitude of the function\n */\n constructor(\n /** Defines the amplitude of the function */\n amplitude = 1) {\n super();\n this.amplitude = amplitude;\n }\n /**\n * @internal\n */\n easeInCore(gradient) {\n const num = Math.max(0, this.amplitude);\n return Math.pow(gradient, 3.0) - gradient * num * Math.sin(3.1415926535897931 * gradient);\n }\n }\n /**\n * Easing function with an exponential shape (see link below).\n * @see https://easings.net/#easeInExpo\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\n */\n class ExponentialEase extends EasingFunction {\n /**\n * Instantiates an exponential easing function\n * @see https://easings.net/#easeInExpo\n * @param exponent Defines the exponent of the function\n */\n constructor(\n /** Defines the exponent of the function */\n exponent = 2) {\n super();\n this.exponent = exponent;\n }\n /**\n * @internal\n */\n easeInCore(gradient) {\n if (this.exponent <= 0) {\n return gradient;\n }\n return (Math.exp(this.exponent * gradient) - 1.0) / (Math.exp(this.exponent) - 1.0);\n }\n }\n /**\n * Easing function with a power of 2 shape (see link below).\n * @see https://easings.net/#easeInQuad\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\n */\n class QuadraticEase extends EasingFunction {\n /**\n * @internal\n */\n easeInCore(gradient) {\n return gradient * gradient;\n }\n }\n /**\n * Easing function with a sin shape (see link below).\n * @see https://easings.net/#easeInSine\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\n */\n class SineEase extends EasingFunction {\n /**\n * @internal\n */\n easeInCore(gradient) {\n return 1.0 - Math.sin(1.5707963267948966 * (1.0 - gradient));\n }\n }\n\n /**\n * Enum for the animation key frame interpolation type\n */\n var AnimationKeyInterpolation;\n (function (AnimationKeyInterpolation) {\n /**\n * Use tangents to interpolate between start and end values.\n */\n AnimationKeyInterpolation[AnimationKeyInterpolation[\"NONE\"] = 0] = \"NONE\";\n /**\n * Do not interpolate between keys and use the start key value only. Tangents are ignored\n */\n AnimationKeyInterpolation[AnimationKeyInterpolation[\"STEP\"] = 1] = \"STEP\";\n })(AnimationKeyInterpolation || (AnimationKeyInterpolation = {}));\n\n /**\n * Represents the range of an animation\n */\n class AnimationRange {\n /**\n * Initializes the range of an animation\n * @param name The name of the animation range\n * @param from The starting frame of the animation\n * @param to The ending frame of the animation\n */\n constructor(\n /**The name of the animation range**/\n name, \n /**The starting frame of the animation */\n from, \n /**The ending frame of the animation*/\n to) {\n this.name = name;\n this.from = from;\n this.to = to;\n }\n /**\n * Makes a copy of the animation range\n * @returns A copy of the animation range\n */\n clone() {\n return new AnimationRange(this.name, this.from, this.to);\n }\n }\n\n /**\n * Size containing width and height\n */\n class Size {\n /**\n * Creates a Size object from the given width and height (floats).\n * @param width width of the new size\n * @param height height of the new size\n */\n constructor(width, height) {\n this.width = width;\n this.height = height;\n }\n /**\n * Returns a string with the Size width and height\n * @returns a string with the Size width and height\n */\n toString() {\n return `{W: ${this.width}, H: ${this.height}}`;\n }\n /**\n * \"Size\"\n * @returns the string \"Size\"\n */\n getClassName() {\n return \"Size\";\n }\n /**\n * Returns the Size hash code.\n * @returns a hash code for a unique width and height\n */\n getHashCode() {\n let hash = this.width | 0;\n hash = (hash * 397) ^ (this.height | 0);\n return hash;\n }\n /**\n * Updates the current size from the given one.\n * @param src the given size\n */\n copyFrom(src) {\n this.width = src.width;\n this.height = src.height;\n }\n /**\n * Updates in place the current Size from the given floats.\n * @param width width of the new size\n * @param height height of the new size\n * @returns the updated Size.\n */\n copyFromFloats(width, height) {\n this.width = width;\n this.height = height;\n return this;\n }\n /**\n * Updates in place the current Size from the given floats.\n * @param width width to set\n * @param height height to set\n * @returns the updated Size.\n */\n set(width, height) {\n return this.copyFromFloats(width, height);\n }\n /**\n * Multiplies the width and height by numbers\n * @param w factor to multiple the width by\n * @param h factor to multiple the height by\n * @returns a new Size set with the multiplication result of the current Size and the given floats.\n */\n multiplyByFloats(w, h) {\n return new Size(this.width * w, this.height * h);\n }\n /**\n * Clones the size\n * @returns a new Size copied from the given one.\n */\n clone() {\n return new Size(this.width, this.height);\n }\n /**\n * True if the current Size and the given one width and height are strictly equal.\n * @param other the other size to compare against\n * @returns True if the current Size and the given one width and height are strictly equal.\n */\n equals(other) {\n if (!other) {\n return false;\n }\n return this.width === other.width && this.height === other.height;\n }\n /**\n * The surface of the Size : width * height (float).\n */\n get surface() {\n return this.width * this.height;\n }\n /**\n * Create a new size of zero\n * @returns a new Size set to (0.0, 0.0)\n */\n static Zero() {\n return new Size(0.0, 0.0);\n }\n /**\n * Sums the width and height of two sizes\n * @param otherSize size to add to this size\n * @returns a new Size set as the addition result of the current Size and the given one.\n */\n add(otherSize) {\n const r = new Size(this.width + otherSize.width, this.height + otherSize.height);\n return r;\n }\n /**\n * Subtracts the width and height of two\n * @param otherSize size to subtract to this size\n * @returns a new Size set as the subtraction result of the given one from the current Size.\n */\n subtract(otherSize) {\n const r = new Size(this.width - otherSize.width, this.height - otherSize.height);\n return r;\n }\n /**\n * Creates a new Size set at the linear interpolation \"amount\" between \"start\" and \"end\"\n * @param start starting size to lerp between\n * @param end end size to lerp between\n * @param amount amount to lerp between the start and end values\n * @returns a new Size set at the linear interpolation \"amount\" between \"start\" and \"end\"\n */\n static Lerp(start, end, amount) {\n const w = start.width + (end.width - start.width) * amount;\n const h = start.height + (end.height - start.height) * amount;\n return new Size(w, h);\n }\n }\n\n /**\n * Class used to store any kind of animation\n */\n class Animation {\n /**\n * @internal Internal use\n */\n static _PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction) {\n let dataType = undefined;\n if (!isNaN(parseFloat(from)) && isFinite(from)) {\n dataType = Animation.ANIMATIONTYPE_FLOAT;\n }\n else if (from instanceof Quaternion) {\n dataType = Animation.ANIMATIONTYPE_QUATERNION;\n }\n else if (from instanceof Vector3) {\n dataType = Animation.ANIMATIONTYPE_VECTOR3;\n }\n else if (from instanceof Vector2) {\n dataType = Animation.ANIMATIONTYPE_VECTOR2;\n }\n else if (from instanceof Color3) {\n dataType = Animation.ANIMATIONTYPE_COLOR3;\n }\n else if (from instanceof Color4) {\n dataType = Animation.ANIMATIONTYPE_COLOR4;\n }\n else if (from instanceof Size) {\n dataType = Animation.ANIMATIONTYPE_SIZE;\n }\n if (dataType == undefined) {\n return null;\n }\n const animation = new Animation(name, targetProperty, framePerSecond, dataType, loopMode);\n const keys = [\n { frame: 0, value: from },\n { frame: totalFrame, value: to },\n ];\n animation.setKeys(keys);\n if (easingFunction !== undefined) {\n animation.setEasingFunction(easingFunction);\n }\n return animation;\n }\n /**\n * Sets up an animation\n * @param property The property to animate\n * @param animationType The animation type to apply\n * @param framePerSecond The frames per second of the animation\n * @param easingFunction The easing function used in the animation\n * @returns The created animation\n */\n static CreateAnimation(property, animationType, framePerSecond, easingFunction) {\n const animation = new Animation(property + \"Animation\", property, framePerSecond, animationType, Animation.ANIMATIONLOOPMODE_CONSTANT);\n animation.setEasingFunction(easingFunction);\n return animation;\n }\n /**\n * Create and start an animation on a node\n * @param name defines the name of the global animation that will be run on all nodes\n * @param target defines the target where the animation will take place\n * @param targetProperty defines property to animate\n * @param framePerSecond defines the number of frame per second yo use\n * @param totalFrame defines the number of frames in total\n * @param from defines the initial value\n * @param to defines the final value\n * @param loopMode defines which loop mode you want to use (off by default)\n * @param easingFunction defines the easing function to use (linear by default)\n * @param onAnimationEnd defines the callback to call when animation end\n * @param scene defines the hosting scene\n * @returns the animatable created for this animation\n */\n static CreateAndStartAnimation(name, target, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd, scene) {\n const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);\n if (!animation) {\n return null;\n }\n if (target.getScene) {\n scene = target.getScene();\n }\n if (!scene) {\n return null;\n }\n return scene.beginDirectAnimation(target, [animation], 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);\n }\n /**\n * Create and start an animation on a node and its descendants\n * @param name defines the name of the global animation that will be run on all nodes\n * @param node defines the root node where the animation will take place\n * @param directDescendantsOnly if true only direct descendants will be used, if false direct and also indirect (children of children, an so on in a recursive manner) descendants will be used\n * @param targetProperty defines property to animate\n * @param framePerSecond defines the number of frame per second to use\n * @param totalFrame defines the number of frames in total\n * @param from defines the initial value\n * @param to defines the final value\n * @param loopMode defines which loop mode you want to use (off by default)\n * @param easingFunction defines the easing function to use (linear by default)\n * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)\n * @returns the list of animatables created for all nodes\n * @example https://www.babylonjs-playground.com/#MH0VLI\n */\n static CreateAndStartHierarchyAnimation(name, node, directDescendantsOnly, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd) {\n const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);\n if (!animation) {\n return null;\n }\n const scene = node.getScene();\n return scene.beginDirectHierarchyAnimation(node, directDescendantsOnly, [animation], 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);\n }\n /**\n * Creates a new animation, merges it with the existing animations and starts it\n * @param name Name of the animation\n * @param node Node which contains the scene that begins the animations\n * @param targetProperty Specifies which property to animate\n * @param framePerSecond The frames per second of the animation\n * @param totalFrame The total number of frames\n * @param from The frame at the beginning of the animation\n * @param to The frame at the end of the animation\n * @param loopMode Specifies the loop mode of the animation\n * @param easingFunction (Optional) The easing function of the animation, which allow custom mathematical formulas for animations\n * @param onAnimationEnd Callback to run once the animation is complete\n * @returns Nullable animation\n */\n static CreateMergeAndStartAnimation(name, node, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd) {\n const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);\n if (!animation) {\n return null;\n }\n node.animations.push(animation);\n return node.getScene().beginAnimation(node, 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);\n }\n /**\n * Convert the keyframes for all animations belonging to the group to be relative to a given reference frame.\n * @param sourceAnimation defines the Animation containing keyframes to convert\n * @param referenceFrame defines the frame that keyframes in the range will be relative to\n * @param range defines the name of the AnimationRange belonging to the Animation to convert\n * @param cloneOriginal defines whether or not to clone the animation and convert the clone or convert the original animation (default is false)\n * @param clonedName defines the name of the resulting cloned Animation if cloneOriginal is true\n * @returns a new Animation if cloneOriginal is true or the original Animation if cloneOriginal is false\n */\n static MakeAnimationAdditive(sourceAnimation, referenceFrame = 0, range, cloneOriginal = false, clonedName) {\n let animation = sourceAnimation;\n if (cloneOriginal) {\n animation = sourceAnimation.clone();\n animation.name = clonedName || animation.name;\n }\n if (!animation._keys.length) {\n return animation;\n }\n referenceFrame = referenceFrame >= 0 ? referenceFrame : 0;\n let startIndex = 0;\n const firstKey = animation._keys[0];\n let endIndex = animation._keys.length - 1;\n const lastKey = animation._keys[endIndex];\n const valueStore = {\n referenceValue: firstKey.value,\n referencePosition: TmpVectors.Vector3[0],\n referenceQuaternion: TmpVectors.Quaternion[0],\n referenceScaling: TmpVectors.Vector3[1],\n keyPosition: TmpVectors.Vector3[2],\n keyQuaternion: TmpVectors.Quaternion[1],\n keyScaling: TmpVectors.Vector3[3],\n };\n let referenceFound = false;\n let from = firstKey.frame;\n let to = lastKey.frame;\n if (range) {\n const rangeValue = animation.getRange(range);\n if (rangeValue) {\n from = rangeValue.from;\n to = rangeValue.to;\n }\n }\n let fromKeyFound = firstKey.frame === from;\n let toKeyFound = lastKey.frame === to;\n // There's only one key, so use it\n if (animation._keys.length === 1) {\n const value = animation._getKeyValue(animation._keys[0]);\n valueStore.referenceValue = value.clone ? value.clone() : value;\n referenceFound = true;\n }\n // Reference frame is before the first frame, so just use the first frame\n else if (referenceFrame <= firstKey.frame) {\n const value = animation._getKeyValue(firstKey.value);\n valueStore.referenceValue = value.clone ? value.clone() : value;\n referenceFound = true;\n }\n // Reference frame is after the last frame, so just use the last frame\n else if (referenceFrame >= lastKey.frame) {\n const value = animation._getKeyValue(lastKey.value);\n valueStore.referenceValue = value.clone ? value.clone() : value;\n referenceFound = true;\n }\n // Find key bookends, create them if they don't exist\n let index = 0;\n while (!referenceFound || !fromKeyFound || (!toKeyFound && index < animation._keys.length - 1)) {\n const currentKey = animation._keys[index];\n const nextKey = animation._keys[index + 1];\n // If reference frame wasn't found yet, check if we can interpolate to it\n if (!referenceFound && referenceFrame >= currentKey.frame && referenceFrame <= nextKey.frame) {\n let value;\n if (referenceFrame === currentKey.frame) {\n value = animation._getKeyValue(currentKey.value);\n }\n else if (referenceFrame === nextKey.frame) {\n value = animation._getKeyValue(nextKey.value);\n }\n else {\n const animationState = {\n key: index,\n repeatCount: 0,\n loopMode: this.ANIMATIONLOOPMODE_CONSTANT,\n };\n value = animation._interpolate(referenceFrame, animationState);\n }\n valueStore.referenceValue = value.clone ? value.clone() : value;\n referenceFound = true;\n }\n // If from key wasn't found yet, check if we can interpolate to it\n if (!fromKeyFound && from >= currentKey.frame && from <= nextKey.frame) {\n if (from === currentKey.frame) {\n startIndex = index;\n }\n else if (from === nextKey.frame) {\n startIndex = index + 1;\n }\n else {\n const animationState = {\n key: index,\n repeatCount: 0,\n loopMode: this.ANIMATIONLOOPMODE_CONSTANT,\n };\n const value = animation._interpolate(from, animationState);\n const key = {\n frame: from,\n value: value.clone ? value.clone() : value,\n };\n animation._keys.splice(index + 1, 0, key);\n startIndex = index + 1;\n }\n fromKeyFound = true;\n }\n // If to key wasn't found yet, check if we can interpolate to it\n if (!toKeyFound && to >= currentKey.frame && to <= nextKey.frame) {\n if (to === currentKey.frame) {\n endIndex = index;\n }\n else if (to === nextKey.frame) {\n endIndex = index + 1;\n }\n else {\n const animationState = {\n key: index,\n repeatCount: 0,\n loopMode: this.ANIMATIONLOOPMODE_CONSTANT,\n };\n const value = animation._interpolate(to, animationState);\n const key = {\n frame: to,\n value: value.clone ? value.clone() : value,\n };\n animation._keys.splice(index + 1, 0, key);\n endIndex = index + 1;\n }\n toKeyFound = true;\n }\n index++;\n }\n // Conjugate the quaternion\n if (animation.dataType === Animation.ANIMATIONTYPE_QUATERNION) {\n valueStore.referenceValue.normalize().conjugateInPlace();\n }\n // Decompose matrix and conjugate the quaternion\n else if (animation.dataType === Animation.ANIMATIONTYPE_MATRIX) {\n valueStore.referenceValue.decompose(valueStore.referenceScaling, valueStore.referenceQuaternion, valueStore.referencePosition);\n valueStore.referenceQuaternion.normalize().conjugateInPlace();\n }\n // Subtract the reference value from all of the key values\n for (index = startIndex; index <= endIndex; index++) {\n const key = animation._keys[index];\n // If this key was duplicated to create a frame 0 key, skip it because its value has already been updated\n if (index && animation.dataType !== Animation.ANIMATIONTYPE_FLOAT && key.value === firstKey.value) {\n continue;\n }\n switch (animation.dataType) {\n case Animation.ANIMATIONTYPE_MATRIX:\n key.value.decompose(valueStore.keyScaling, valueStore.keyQuaternion, valueStore.keyPosition);\n valueStore.keyPosition.subtractInPlace(valueStore.referencePosition);\n valueStore.keyScaling.divideInPlace(valueStore.referenceScaling);\n valueStore.referenceQuaternion.multiplyToRef(valueStore.keyQuaternion, valueStore.keyQuaternion);\n Matrix.ComposeToRef(valueStore.keyScaling, valueStore.keyQuaternion, valueStore.keyPosition, key.value);\n break;\n case Animation.ANIMATIONTYPE_QUATERNION:\n valueStore.referenceValue.multiplyToRef(key.value, key.value);\n break;\n case Animation.ANIMATIONTYPE_VECTOR2:\n case Animation.ANIMATIONTYPE_VECTOR3:\n case Animation.ANIMATIONTYPE_COLOR3:\n case Animation.ANIMATIONTYPE_COLOR4:\n key.value.subtractToRef(valueStore.referenceValue, key.value);\n break;\n case Animation.ANIMATIONTYPE_SIZE:\n key.value.width -= valueStore.referenceValue.width;\n key.value.height -= valueStore.referenceValue.height;\n break;\n default:\n key.value -= valueStore.referenceValue;\n }\n }\n return animation;\n }\n /**\n * Transition property of an host to the target Value\n * @param property The property to transition\n * @param targetValue The target Value of the property\n * @param host The object where the property to animate belongs\n * @param scene Scene used to run the animation\n * @param frameRate Framerate (in frame/s) to use\n * @param transition The transition type we want to use\n * @param duration The duration of the animation, in milliseconds\n * @param onAnimationEnd Callback trigger at the end of the animation\n * @returns Nullable animation\n */\n static TransitionTo(property, targetValue, host, scene, frameRate, transition, duration, onAnimationEnd = null) {\n if (duration <= 0) {\n host[property] = targetValue;\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n return null;\n }\n const endFrame = frameRate * (duration / 1000);\n transition.setKeys([\n {\n frame: 0,\n value: host[property].clone ? host[property].clone() : host[property],\n },\n {\n frame: endFrame,\n value: targetValue,\n },\n ]);\n if (!host.animations) {\n host.animations = [];\n }\n host.animations.push(transition);\n const animation = scene.beginAnimation(host, 0, endFrame, false);\n animation.onAnimationEnd = onAnimationEnd;\n return animation;\n }\n /**\n * Return the array of runtime animations currently using this animation\n */\n get runtimeAnimations() {\n return this._runtimeAnimations;\n }\n /**\n * Specifies if any of the runtime animations are currently running\n */\n get hasRunningRuntimeAnimations() {\n for (const runtimeAnimation of this._runtimeAnimations) {\n if (!runtimeAnimation.isStopped()) {\n return true;\n }\n }\n return false;\n }\n /**\n * Initializes the animation\n * @param name Name of the animation\n * @param targetProperty Property to animate\n * @param framePerSecond The frames per second of the animation\n * @param dataType The data type of the animation\n * @param loopMode The loop mode of the animation\n * @param enableBlending Specifies if blending should be enabled\n */\n constructor(\n /**Name of the animation */\n name, \n /**Property to animate */\n targetProperty, \n /**The frames per second of the animation */\n framePerSecond, \n /**The data type of the animation */\n dataType, \n /**The loop mode of the animation */\n loopMode, \n /**Specifies if blending should be enabled */\n enableBlending) {\n this.name = name;\n this.targetProperty = targetProperty;\n this.framePerSecond = framePerSecond;\n this.dataType = dataType;\n this.loopMode = loopMode;\n this.enableBlending = enableBlending;\n /**\n * Stores the easing function of the animation\n */\n this._easingFunction = null;\n /**\n * @internal Internal use only\n */\n this._runtimeAnimations = new Array();\n /**\n * The set of event that will be linked to this animation\n */\n this._events = new Array();\n /**\n * Stores the blending speed of the animation\n */\n this.blendingSpeed = 0.01;\n /**\n * Stores the animation ranges for the animation\n */\n this._ranges = {};\n this.targetPropertyPath = targetProperty.split(\".\");\n this.dataType = dataType;\n this.loopMode = loopMode === undefined ? Animation.ANIMATIONLOOPMODE_CYCLE : loopMode;\n this.uniqueId = Animation._UniqueIdGenerator++;\n }\n // Methods\n /**\n * Converts the animation to a string\n * @param fullDetails support for multiple levels of logging within scene loading\n * @returns String form of the animation\n */\n toString(fullDetails) {\n let ret = \"Name: \" + this.name + \", property: \" + this.targetProperty;\n ret += \", datatype: \" + [\"Float\", \"Vector3\", \"Quaternion\", \"Matrix\", \"Color3\", \"Vector2\"][this.dataType];\n ret += \", nKeys: \" + (this._keys ? this._keys.length : \"none\");\n ret += \", nRanges: \" + (this._ranges ? Object.keys(this._ranges).length : \"none\");\n if (fullDetails) {\n ret += \", Ranges: {\";\n let first = true;\n for (const name in this._ranges) {\n if (first) {\n ret += \", \";\n first = false;\n }\n ret += name;\n }\n ret += \"}\";\n }\n return ret;\n }\n /**\n * Add an event to this animation\n * @param event Event to add\n */\n addEvent(event) {\n this._events.push(event);\n this._events.sort((a, b) => a.frame - b.frame);\n }\n /**\n * Remove all events found at the given frame\n * @param frame The frame to remove events from\n */\n removeEvents(frame) {\n for (let index = 0; index < this._events.length; index++) {\n if (this._events[index].frame === frame) {\n this._events.splice(index, 1);\n index--;\n }\n }\n }\n /**\n * Retrieves all the events from the animation\n * @returns Events from the animation\n */\n getEvents() {\n return this._events;\n }\n /**\n * Creates an animation range\n * @param name Name of the animation range\n * @param from Starting frame of the animation range\n * @param to Ending frame of the animation\n */\n createRange(name, from, to) {\n // check name not already in use; could happen for bones after serialized\n if (!this._ranges[name]) {\n this._ranges[name] = new AnimationRange(name, from, to);\n }\n }\n /**\n * Deletes an animation range by name\n * @param name Name of the animation range to delete\n * @param deleteFrames Specifies if the key frames for the range should also be deleted (true) or not (false)\n */\n deleteRange(name, deleteFrames = true) {\n const range = this._ranges[name];\n if (!range) {\n return;\n }\n if (deleteFrames) {\n const from = range.from;\n const to = range.to;\n // this loop MUST go high to low for multiple splices to work\n for (let key = this._keys.length - 1; key >= 0; key--) {\n if (this._keys[key].frame >= from && this._keys[key].frame <= to) {\n this._keys.splice(key, 1);\n }\n }\n }\n this._ranges[name] = null; // said much faster than 'delete this._range[name]'\n }\n /**\n * Gets the animation range by name, or null if not defined\n * @param name Name of the animation range\n * @returns Nullable animation range\n */\n getRange(name) {\n return this._ranges[name];\n }\n /**\n * Gets the key frames from the animation\n * @returns The key frames of the animation\n */\n getKeys() {\n return this._keys;\n }\n /**\n * Gets the highest frame rate of the animation\n * @returns Highest frame rate of the animation\n */\n getHighestFrame() {\n let ret = 0;\n for (let key = 0, nKeys = this._keys.length; key < nKeys; key++) {\n if (ret < this._keys[key].frame) {\n ret = this._keys[key].frame;\n }\n }\n return ret;\n }\n /**\n * Gets the easing function of the animation\n * @returns Easing function of the animation\n */\n getEasingFunction() {\n return this._easingFunction;\n }\n /**\n * Sets the easing function of the animation\n * @param easingFunction A custom mathematical formula for animation\n */\n setEasingFunction(easingFunction) {\n this._easingFunction = easingFunction;\n }\n /**\n * Interpolates a scalar linearly\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated scalar value\n */\n floatInterpolateFunction(startValue, endValue, gradient) {\n return Scalar.Lerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a scalar cubically\n * @param startValue Start value of the animation curve\n * @param outTangent End tangent of the animation\n * @param endValue End value of the animation curve\n * @param inTangent Start tangent of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated scalar value\n */\n floatInterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {\n return Scalar.Hermite(startValue, outTangent, endValue, inTangent, gradient);\n }\n /**\n * Interpolates a quaternion using a spherical linear interpolation\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated quaternion value\n */\n quaternionInterpolateFunction(startValue, endValue, gradient) {\n return Quaternion.Slerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a quaternion cubically\n * @param startValue Start value of the animation curve\n * @param outTangent End tangent of the animation curve\n * @param endValue End value of the animation curve\n * @param inTangent Start tangent of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated quaternion value\n */\n quaternionInterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {\n return Quaternion.Hermite(startValue, outTangent, endValue, inTangent, gradient).normalize();\n }\n /**\n * Interpolates a Vector3 linearly\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\n * @returns Interpolated scalar value\n */\n vector3InterpolateFunction(startValue, endValue, gradient) {\n return Vector3.Lerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a Vector3 cubically\n * @param startValue Start value of the animation curve\n * @param outTangent End tangent of the animation\n * @param endValue End value of the animation curve\n * @param inTangent Start tangent of the animation curve\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\n * @returns InterpolatedVector3 value\n */\n vector3InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {\n return Vector3.Hermite(startValue, outTangent, endValue, inTangent, gradient);\n }\n /**\n * Interpolates a Vector2 linearly\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\n * @returns Interpolated Vector2 value\n */\n vector2InterpolateFunction(startValue, endValue, gradient) {\n return Vector2.Lerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a Vector2 cubically\n * @param startValue Start value of the animation curve\n * @param outTangent End tangent of the animation\n * @param endValue End value of the animation curve\n * @param inTangent Start tangent of the animation curve\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\n * @returns Interpolated Vector2 value\n */\n vector2InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {\n return Vector2.Hermite(startValue, outTangent, endValue, inTangent, gradient);\n }\n /**\n * Interpolates a size linearly\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated Size value\n */\n sizeInterpolateFunction(startValue, endValue, gradient) {\n return Size.Lerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a Color3 linearly\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated Color3 value\n */\n color3InterpolateFunction(startValue, endValue, gradient) {\n return Color3.Lerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a Color3 cubically\n * @param startValue Start value of the animation curve\n * @param outTangent End tangent of the animation\n * @param endValue End value of the animation curve\n * @param inTangent Start tangent of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns interpolated value\n */\n color3InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {\n return Color3.Hermite(startValue, outTangent, endValue, inTangent, gradient);\n }\n /**\n * Interpolates a Color4 linearly\n * @param startValue Start value of the animation curve\n * @param endValue End value of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns Interpolated Color3 value\n */\n color4InterpolateFunction(startValue, endValue, gradient) {\n return Color4.Lerp(startValue, endValue, gradient);\n }\n /**\n * Interpolates a Color4 cubically\n * @param startValue Start value of the animation curve\n * @param outTangent End tangent of the animation\n * @param endValue End value of the animation curve\n * @param inTangent Start tangent of the animation curve\n * @param gradient Scalar amount to interpolate\n * @returns interpolated value\n */\n color4InterpolateFunctionWithTangents(startValue, outTangent, endValue, inTangent, gradient) {\n return Color4.Hermite(startValue, outTangent, endValue, inTangent, gradient);\n }\n /**\n * @internal Internal use only\n */\n _getKeyValue(value) {\n if (typeof value === \"function\") {\n return value();\n }\n return value;\n }\n /**\n * Evaluate the animation value at a given frame\n * @param currentFrame defines the frame where we want to evaluate the animation\n * @returns the animation value\n */\n evaluate(currentFrame) {\n return this._interpolate(currentFrame, {\n key: 0,\n repeatCount: 0,\n loopMode: Animation.ANIMATIONLOOPMODE_CONSTANT,\n });\n }\n /**\n * @internal Internal use only\n */\n _interpolate(currentFrame, state) {\n if (state.loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && state.repeatCount > 0) {\n return state.highLimitValue.clone ? state.highLimitValue.clone() : state.highLimitValue;\n }\n const keys = this._keys;\n const keysLength = keys.length;\n let key = state.key;\n while (key >= 0 && currentFrame < keys[key].frame) {\n --key;\n }\n while (key + 1 <= keysLength - 1 && currentFrame >= keys[key + 1].frame) {\n ++key;\n }\n state.key = key;\n if (key < 0) {\n return this._getKeyValue(keys[0].value);\n }\n else if (key + 1 > keysLength - 1) {\n return this._getKeyValue(keys[keysLength - 1].value);\n }\n const startKey = keys[key];\n const endKey = keys[key + 1];\n const startValue = this._getKeyValue(startKey.value);\n const endValue = this._getKeyValue(endKey.value);\n if (startKey.interpolation === AnimationKeyInterpolation.STEP) {\n if (endKey.frame > currentFrame) {\n return startValue;\n }\n else {\n return endValue;\n }\n }\n const useTangent = startKey.outTangent !== undefined && endKey.inTangent !== undefined;\n const frameDelta = endKey.frame - startKey.frame;\n // gradient : percent of currentFrame between the frame inf and the frame sup\n let gradient = (currentFrame - startKey.frame) / frameDelta;\n // check for easingFunction and correction of gradient\n const easingFunction = this.getEasingFunction();\n if (easingFunction !== null) {\n gradient = easingFunction.ease(gradient);\n }\n switch (this.dataType) {\n // Float\n case Animation.ANIMATIONTYPE_FLOAT: {\n const floatValue = useTangent\n ? this.floatInterpolateFunctionWithTangents(startValue, startKey.outTangent * frameDelta, endValue, endKey.inTangent * frameDelta, gradient)\n : this.floatInterpolateFunction(startValue, endValue, gradient);\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return floatValue;\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return state.offsetValue * state.repeatCount + floatValue;\n }\n break;\n }\n // Quaternion\n case Animation.ANIMATIONTYPE_QUATERNION: {\n const quatValue = useTangent\n ? this.quaternionInterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\n : this.quaternionInterpolateFunction(startValue, endValue, gradient);\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return quatValue;\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return quatValue.addInPlace(state.offsetValue.scale(state.repeatCount));\n }\n return quatValue;\n }\n // Vector3\n case Animation.ANIMATIONTYPE_VECTOR3: {\n const vec3Value = useTangent\n ? this.vector3InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\n : this.vector3InterpolateFunction(startValue, endValue, gradient);\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return vec3Value;\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return vec3Value.add(state.offsetValue.scale(state.repeatCount));\n }\n break;\n }\n // Vector2\n case Animation.ANIMATIONTYPE_VECTOR2: {\n const vec2Value = useTangent\n ? this.vector2InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\n : this.vector2InterpolateFunction(startValue, endValue, gradient);\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return vec2Value;\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return vec2Value.add(state.offsetValue.scale(state.repeatCount));\n }\n break;\n }\n // Size\n case Animation.ANIMATIONTYPE_SIZE: {\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return this.sizeInterpolateFunction(startValue, endValue, gradient);\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return this.sizeInterpolateFunction(startValue, endValue, gradient).add(state.offsetValue.scale(state.repeatCount));\n }\n break;\n }\n // Color3\n case Animation.ANIMATIONTYPE_COLOR3: {\n const color3Value = useTangent\n ? this.color3InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\n : this.color3InterpolateFunction(startValue, endValue, gradient);\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return color3Value;\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return color3Value.add(state.offsetValue.scale(state.repeatCount));\n }\n break;\n }\n // Color4\n case Animation.ANIMATIONTYPE_COLOR4: {\n const color4Value = useTangent\n ? this.color4InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\n : this.color4InterpolateFunction(startValue, endValue, gradient);\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO:\n return color4Value;\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\n return color4Value.add(state.offsetValue.scale(state.repeatCount));\n }\n break;\n }\n // Matrix\n case Animation.ANIMATIONTYPE_MATRIX: {\n switch (state.loopMode) {\n case Animation.ANIMATIONLOOPMODE_CYCLE:\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\n case Animation.ANIMATIONLOOPMODE_YOYO: {\n if (Animation.AllowMatricesInterpolation) {\n return this.matrixInterpolateFunction(startValue, endValue, gradient, state.workValue);\n }\n return startValue;\n }\n case Animation.ANIMATIONLOOPMODE_RELATIVE: {\n return startValue;\n }\n }\n break;\n }\n }\n return 0;\n }\n /**\n * Defines the function to use to interpolate matrices\n * @param startValue defines the start matrix\n * @param endValue defines the end matrix\n * @param gradient defines the gradient between both matrices\n * @param result defines an optional target matrix where to store the interpolation\n * @returns the interpolated matrix\n */\n matrixInterpolateFunction(startValue, endValue, gradient, result) {\n if (Animation.AllowMatrixDecomposeForInterpolation) {\n if (result) {\n Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);\n return result;\n }\n return Matrix.DecomposeLerp(startValue, endValue, gradient);\n }\n if (result) {\n Matrix.LerpToRef(startValue, endValue, gradient, result);\n return result;\n }\n return Matrix.Lerp(startValue, endValue, gradient);\n }\n /**\n * Makes a copy of the animation\n * @returns Cloned animation\n */\n clone() {\n const clone = new Animation(this.name, this.targetPropertyPath.join(\".\"), this.framePerSecond, this.dataType, this.loopMode);\n clone.enableBlending = this.enableBlending;\n clone.blendingSpeed = this.blendingSpeed;\n if (this._keys) {\n clone.setKeys(this._keys);\n }\n if (this._ranges) {\n clone._ranges = {};\n for (const name in this._ranges) {\n const range = this._ranges[name];\n if (!range) {\n continue;\n }\n clone._ranges[name] = range.clone();\n }\n }\n return clone;\n }\n /**\n * Sets the key frames of the animation\n * @param values The animation key frames to set\n */\n setKeys(values) {\n this._keys = values.slice(0);\n }\n /**\n * Serializes the animation to an object\n * @returns Serialized object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.name = this.name;\n serializationObject.property = this.targetProperty;\n serializationObject.framePerSecond = this.framePerSecond;\n serializationObject.dataType = this.dataType;\n serializationObject.loopBehavior = this.loopMode;\n serializationObject.enableBlending = this.enableBlending;\n serializationObject.blendingSpeed = this.blendingSpeed;\n const dataType = this.dataType;\n serializationObject.keys = [];\n const keys = this.getKeys();\n for (let index = 0; index < keys.length; index++) {\n const animationKey = keys[index];\n const key = {};\n key.frame = animationKey.frame;\n switch (dataType) {\n case Animation.ANIMATIONTYPE_FLOAT:\n key.values = [animationKey.value];\n if (animationKey.inTangent !== undefined) {\n key.values.push(animationKey.inTangent);\n }\n if (animationKey.outTangent !== undefined) {\n if (animationKey.inTangent === undefined) {\n key.values.push(undefined);\n }\n key.values.push(animationKey.outTangent);\n }\n if (animationKey.interpolation !== undefined) {\n if (animationKey.inTangent === undefined) {\n key.values.push(undefined);\n }\n if (animationKey.outTangent === undefined) {\n key.values.push(undefined);\n }\n key.values.push(animationKey.interpolation);\n }\n break;\n case Animation.ANIMATIONTYPE_QUATERNION:\n case Animation.ANIMATIONTYPE_MATRIX:\n case Animation.ANIMATIONTYPE_VECTOR3:\n case Animation.ANIMATIONTYPE_COLOR3:\n case Animation.ANIMATIONTYPE_COLOR4:\n key.values = animationKey.value.asArray();\n if (animationKey.inTangent != undefined) {\n key.values.push(animationKey.inTangent.asArray());\n }\n if (animationKey.outTangent != undefined) {\n if (animationKey.inTangent === undefined) {\n key.values.push(undefined);\n }\n key.values.push(animationKey.outTangent.asArray());\n }\n if (animationKey.interpolation !== undefined) {\n if (animationKey.inTangent === undefined) {\n key.values.push(undefined);\n }\n if (animationKey.outTangent === undefined) {\n key.values.push(undefined);\n }\n key.values.push(animationKey.interpolation);\n }\n break;\n }\n serializationObject.keys.push(key);\n }\n serializationObject.ranges = [];\n for (const name in this._ranges) {\n const source = this._ranges[name];\n if (!source) {\n continue;\n }\n const range = {};\n range.name = name;\n range.from = source.from;\n range.to = source.to;\n serializationObject.ranges.push(range);\n }\n return serializationObject;\n }\n /**\n * @internal\n */\n static _UniversalLerp(left, right, amount) {\n const constructor = left.constructor;\n if (constructor.Lerp) {\n // Lerp supported\n return constructor.Lerp(left, right, amount);\n }\n else if (constructor.Slerp) {\n // Slerp supported\n return constructor.Slerp(left, right, amount);\n }\n else if (left.toFixed) {\n // Number\n return left * (1.0 - amount) + amount * right;\n }\n else {\n // Blending not supported\n return right;\n }\n }\n /**\n * Parses an animation object and creates an animation\n * @param parsedAnimation Parsed animation object\n * @returns Animation object\n */\n static Parse(parsedAnimation) {\n const animation = new Animation(parsedAnimation.name, parsedAnimation.property, parsedAnimation.framePerSecond, parsedAnimation.dataType, parsedAnimation.loopBehavior);\n const dataType = parsedAnimation.dataType;\n const keys = [];\n let data;\n let index;\n if (parsedAnimation.enableBlending) {\n animation.enableBlending = parsedAnimation.enableBlending;\n }\n if (parsedAnimation.blendingSpeed) {\n animation.blendingSpeed = parsedAnimation.blendingSpeed;\n }\n for (index = 0; index < parsedAnimation.keys.length; index++) {\n const key = parsedAnimation.keys[index];\n let inTangent = undefined;\n let outTangent = undefined;\n let interpolation = undefined;\n switch (dataType) {\n case Animation.ANIMATIONTYPE_FLOAT:\n data = key.values[0];\n if (key.values.length >= 2) {\n inTangent = key.values[1];\n }\n if (key.values.length >= 3) {\n outTangent = key.values[2];\n }\n if (key.values.length >= 4) {\n interpolation = key.values[3];\n }\n break;\n case Animation.ANIMATIONTYPE_QUATERNION:\n data = Quaternion.FromArray(key.values);\n if (key.values.length >= 8) {\n const _inTangent = Quaternion.FromArray(key.values.slice(4, 8));\n if (!_inTangent.equals(Quaternion.Zero())) {\n inTangent = _inTangent;\n }\n }\n if (key.values.length >= 12) {\n const _outTangent = Quaternion.FromArray(key.values.slice(8, 12));\n if (!_outTangent.equals(Quaternion.Zero())) {\n outTangent = _outTangent;\n }\n }\n if (key.values.length >= 13) {\n interpolation = key.values[12];\n }\n break;\n case Animation.ANIMATIONTYPE_MATRIX:\n data = Matrix.FromArray(key.values);\n if (key.values.length >= 17) {\n interpolation = key.values[16];\n }\n break;\n case Animation.ANIMATIONTYPE_COLOR3:\n data = Color3.FromArray(key.values);\n if (key.values[3]) {\n inTangent = Color3.FromArray(key.values[3]);\n }\n if (key.values[4]) {\n outTangent = Color3.FromArray(key.values[4]);\n }\n if (key.values[5]) {\n interpolation = key.values[5];\n }\n break;\n case Animation.ANIMATIONTYPE_COLOR4:\n data = Color4.FromArray(key.values);\n if (key.values[4]) {\n inTangent = Color4.FromArray(key.values[4]);\n }\n if (key.values[5]) {\n outTangent = Color4.FromArray(key.values[5]);\n }\n if (key.values[6]) {\n interpolation = Color4.FromArray(key.values[6]);\n }\n break;\n case Animation.ANIMATIONTYPE_VECTOR3:\n default:\n data = Vector3.FromArray(key.values);\n if (key.values[3]) {\n inTangent = Vector3.FromArray(key.values[3]);\n }\n if (key.values[4]) {\n outTangent = Vector3.FromArray(key.values[4]);\n }\n if (key.values[5]) {\n interpolation = key.values[5];\n }\n break;\n }\n const keyData = {};\n keyData.frame = key.frame;\n keyData.value = data;\n if (inTangent != undefined) {\n keyData.inTangent = inTangent;\n }\n if (outTangent != undefined) {\n keyData.outTangent = outTangent;\n }\n if (interpolation != undefined) {\n keyData.interpolation = interpolation;\n }\n keys.push(keyData);\n }\n animation.setKeys(keys);\n if (parsedAnimation.ranges) {\n for (index = 0; index < parsedAnimation.ranges.length; index++) {\n data = parsedAnimation.ranges[index];\n animation.createRange(data.name, data.from, data.to);\n }\n }\n return animation;\n }\n /**\n * Appends the serialized animations from the source animations\n * @param source Source containing the animations\n * @param destination Target to store the animations\n */\n static AppendSerializedAnimations(source, destination) {\n SerializationHelper.AppendSerializedAnimations(source, destination);\n }\n /**\n * Creates a new animation or an array of animations from a snippet saved in a remote file\n * @param name defines the name of the animation to create (can be null or empty to use the one from the json data)\n * @param url defines the url to load from\n * @returns a promise that will resolve to the new animation or an array of animations\n */\n static ParseFromFileAsync(name, url) {\n return new Promise((resolve, reject) => {\n const request = new WebRequest();\n request.addEventListener(\"readystatechange\", () => {\n if (request.readyState == 4) {\n if (request.status == 200) {\n let serializationObject = JSON.parse(request.responseText);\n if (serializationObject.animations) {\n serializationObject = serializationObject.animations;\n }\n if (serializationObject.length) {\n const output = new Array();\n for (const serializedAnimation of serializationObject) {\n output.push(this.Parse(serializedAnimation));\n }\n resolve(output);\n }\n else {\n const output = this.Parse(serializationObject);\n if (name) {\n output.name = name;\n }\n resolve(output);\n }\n }\n else {\n reject(\"Unable to load the animation\");\n }\n }\n });\n request.open(\"GET\", url);\n request.send();\n });\n }\n /**\n * Creates an animation or an array of animations from a snippet saved by the Inspector\n * @param snippetId defines the snippet to load\n * @returns a promise that will resolve to the new animation or a new array of animations\n */\n static ParseFromSnippetAsync(snippetId) {\n return new Promise((resolve, reject) => {\n const request = new WebRequest();\n request.addEventListener(\"readystatechange\", () => {\n if (request.readyState == 4) {\n if (request.status == 200) {\n const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);\n if (snippet.animations) {\n const serializationObject = JSON.parse(snippet.animations);\n const outputs = new Array();\n for (const serializedAnimation of serializationObject.animations) {\n const output = this.Parse(serializedAnimation);\n output.snippetId = snippetId;\n outputs.push(output);\n }\n resolve(outputs);\n }\n else {\n const serializationObject = JSON.parse(snippet.animation);\n const output = this.Parse(serializationObject);\n output.snippetId = snippetId;\n resolve(output);\n }\n }\n else {\n reject(\"Unable to load the snippet \" + snippetId);\n }\n }\n });\n request.open(\"GET\", this.SnippetUrl + \"/\" + snippetId.replace(/#/g, \"/\"));\n request.send();\n });\n }\n }\n Animation._UniqueIdGenerator = 0;\n /**\n * Use matrix interpolation instead of using direct key value when animating matrices\n */\n Animation.AllowMatricesInterpolation = false;\n /**\n * When matrix interpolation is enabled, this boolean forces the system to use Matrix.DecomposeLerp instead of Matrix.Lerp. Interpolation is more precise but slower\n */\n Animation.AllowMatrixDecomposeForInterpolation = true;\n /** Define the Url to load snippets */\n Animation.SnippetUrl = `https://snippet.babylonjs.com`;\n // Statics\n /**\n * Float animation type\n */\n Animation.ANIMATIONTYPE_FLOAT = 0;\n /**\n * Vector3 animation type\n */\n Animation.ANIMATIONTYPE_VECTOR3 = 1;\n /**\n * Quaternion animation type\n */\n Animation.ANIMATIONTYPE_QUATERNION = 2;\n /**\n * Matrix animation type\n */\n Animation.ANIMATIONTYPE_MATRIX = 3;\n /**\n * Color3 animation type\n */\n Animation.ANIMATIONTYPE_COLOR3 = 4;\n /**\n * Color3 animation type\n */\n Animation.ANIMATIONTYPE_COLOR4 = 7;\n /**\n * Vector2 animation type\n */\n Animation.ANIMATIONTYPE_VECTOR2 = 5;\n /**\n * Size animation type\n */\n Animation.ANIMATIONTYPE_SIZE = 6;\n /**\n * Relative Loop Mode\n */\n Animation.ANIMATIONLOOPMODE_RELATIVE = 0;\n /**\n * Cycle Loop Mode\n */\n Animation.ANIMATIONLOOPMODE_CYCLE = 1;\n /**\n * Constant Loop Mode\n */\n Animation.ANIMATIONLOOPMODE_CONSTANT = 2;\n /**\n * Yoyo Loop Mode\n */\n Animation.ANIMATIONLOOPMODE_YOYO = 4;\n /**\n * Creates an animation or an array of animations from a snippet saved by the Inspector\n * @deprecated Please use ParseFromSnippetAsync instead\n * @param snippetId defines the snippet to load\n * @returns a promise that will resolve to the new animation or a new array of animations\n */\n Animation.CreateFromSnippetAsync = Animation.ParseFromSnippetAsync;\n RegisterClass(\"BABYLON.Animation\", Animation);\n Node._AnimationRangeFactory = (name, from, to) => new AnimationRange(name, from, to);\n\n /**\n * Add a bouncing effect to an ArcRotateCamera when reaching a specified minimum and maximum radius\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior\n */\n class BouncingBehavior {\n constructor() {\n /**\n * The duration of the animation, in milliseconds\n */\n this.transitionDuration = 450;\n /**\n * Length of the distance animated by the transition when lower radius is reached\n */\n this.lowerRadiusTransitionRange = 2;\n /**\n * Length of the distance animated by the transition when upper radius is reached\n */\n this.upperRadiusTransitionRange = -2;\n this._autoTransitionRange = false;\n // Animations\n this._radiusIsAnimating = false;\n this._radiusBounceTransition = null;\n this._animatables = new Array();\n }\n /**\n * Gets the name of the behavior.\n */\n get name() {\n return \"Bouncing\";\n }\n /**\n * Gets a value indicating if the lowerRadiusTransitionRange and upperRadiusTransitionRange are defined automatically\n */\n get autoTransitionRange() {\n return this._autoTransitionRange;\n }\n /**\n * Sets a value indicating if the lowerRadiusTransitionRange and upperRadiusTransitionRange are defined automatically\n * Transition ranges will be set to 5% of the bounding box diagonal in world space\n */\n set autoTransitionRange(value) {\n if (this._autoTransitionRange === value) {\n return;\n }\n this._autoTransitionRange = value;\n const camera = this._attachedCamera;\n if (!camera) {\n return;\n }\n if (value) {\n this._onMeshTargetChangedObserver = camera.onMeshTargetChangedObservable.add((mesh) => {\n if (!mesh) {\n return;\n }\n mesh.computeWorldMatrix(true);\n const diagonal = mesh.getBoundingInfo().diagonalLength;\n this.lowerRadiusTransitionRange = diagonal * 0.05;\n this.upperRadiusTransitionRange = diagonal * 0.05;\n });\n }\n else if (this._onMeshTargetChangedObserver) {\n camera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);\n }\n }\n /**\n * Initializes the behavior.\n */\n init() {\n // Do nothing\n }\n /**\n * Attaches the behavior to its arc rotate camera.\n * @param camera Defines the camera to attach the behavior to\n */\n attach(camera) {\n this._attachedCamera = camera;\n this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {\n if (!this._attachedCamera) {\n return;\n }\n // Add the bounce animation to the lower radius limit\n if (this._isRadiusAtLimit(this._attachedCamera.lowerRadiusLimit)) {\n this._applyBoundRadiusAnimation(this.lowerRadiusTransitionRange);\n }\n // Add the bounce animation to the upper radius limit\n if (this._isRadiusAtLimit(this._attachedCamera.upperRadiusLimit)) {\n this._applyBoundRadiusAnimation(this.upperRadiusTransitionRange);\n }\n });\n }\n /**\n * Detaches the behavior from its current arc rotate camera.\n */\n detach() {\n if (!this._attachedCamera) {\n return;\n }\n if (this._onAfterCheckInputsObserver) {\n this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);\n }\n if (this._onMeshTargetChangedObserver) {\n this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);\n }\n this._attachedCamera = null;\n }\n /**\n * Checks if the camera radius is at the specified limit. Takes into account animation locks.\n * @param radiusLimit The limit to check against.\n * @returns Bool to indicate if at limit.\n */\n _isRadiusAtLimit(radiusLimit) {\n if (!this._attachedCamera) {\n return false;\n }\n if (this._attachedCamera.radius === radiusLimit && !this._radiusIsAnimating) {\n return true;\n }\n return false;\n }\n /**\n * Applies an animation to the radius of the camera, extending by the radiusDelta.\n * @param radiusDelta The delta by which to animate to. Can be negative.\n */\n _applyBoundRadiusAnimation(radiusDelta) {\n if (!this._attachedCamera) {\n return;\n }\n if (!this._radiusBounceTransition) {\n BouncingBehavior.EasingFunction.setEasingMode(BouncingBehavior.EasingMode);\n this._radiusBounceTransition = Animation.CreateAnimation(\"radius\", Animation.ANIMATIONTYPE_FLOAT, 60, BouncingBehavior.EasingFunction);\n }\n // Prevent zoom until bounce has completed\n this._cachedWheelPrecision = this._attachedCamera.wheelPrecision;\n this._attachedCamera.wheelPrecision = Infinity;\n this._attachedCamera.inertialRadiusOffset = 0;\n // Animate to the radius limit\n this.stopAllAnimations();\n this._radiusIsAnimating = true;\n const animatable = Animation.TransitionTo(\"radius\", this._attachedCamera.radius + radiusDelta, this._attachedCamera, this._attachedCamera.getScene(), 60, this._radiusBounceTransition, this.transitionDuration, () => this._clearAnimationLocks());\n if (animatable) {\n this._animatables.push(animatable);\n }\n }\n /**\n * Removes all animation locks. Allows new animations to be added to any of the camera properties.\n */\n _clearAnimationLocks() {\n this._radiusIsAnimating = false;\n if (this._attachedCamera) {\n this._attachedCamera.wheelPrecision = this._cachedWheelPrecision;\n }\n }\n /**\n * Stops and removes all animations that have been applied to the camera\n */\n stopAllAnimations() {\n if (this._attachedCamera) {\n this._attachedCamera.animations = [];\n }\n while (this._animatables.length) {\n this._animatables[0].onAnimationEnd = null;\n this._animatables[0].stop();\n this._animatables.shift();\n }\n }\n }\n /**\n * The easing function used by animations\n */\n BouncingBehavior.EasingFunction = new BackEase(0.3);\n /**\n * The easing mode used by animations\n */\n BouncingBehavior.EasingMode = EasingFunction.EASINGMODE_EASEOUT;\n\n /**\n * The framing behavior (FramingBehavior) is designed to automatically position an ArcRotateCamera when its target is set to a mesh. It is also useful if you want to prevent the camera to go under a virtual horizontal plane.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior\n */\n class FramingBehavior {\n constructor() {\n /**\n * An event triggered when the animation to zoom on target mesh has ended\n */\n this.onTargetFramingAnimationEndObservable = new Observable$1();\n this._mode = FramingBehavior.FitFrustumSidesMode;\n this._radiusScale = 1.0;\n this._positionScale = 0.5;\n this._defaultElevation = 0.3;\n this._elevationReturnTime = 1500;\n this._elevationReturnWaitTime = 1000;\n this._zoomStopsAnimation = false;\n this._framingTime = 1500;\n /**\n * Define if the behavior should automatically change the configured\n * camera limits and sensibilities.\n */\n this.autoCorrectCameraLimitsAndSensibility = true;\n this._isPointerDown = false;\n this._lastInteractionTime = -Infinity;\n // Framing control\n this._animatables = new Array();\n this._betaIsAnimating = false;\n }\n /**\n * Gets the name of the behavior.\n */\n get name() {\n return \"Framing\";\n }\n /**\n * Sets the current mode used by the behavior\n */\n set mode(mode) {\n this._mode = mode;\n }\n /**\n * Gets current mode used by the behavior.\n */\n get mode() {\n return this._mode;\n }\n /**\n * Sets the scale applied to the radius (1 by default)\n */\n set radiusScale(radius) {\n this._radiusScale = radius;\n }\n /**\n * Gets the scale applied to the radius\n */\n get radiusScale() {\n return this._radiusScale;\n }\n /**\n * Sets the scale to apply on Y axis to position camera focus. 0.5 by default which means the center of the bounding box.\n */\n set positionScale(scale) {\n this._positionScale = scale;\n }\n /**\n * Gets the scale to apply on Y axis to position camera focus. 0.5 by default which means the center of the bounding box.\n */\n get positionScale() {\n return this._positionScale;\n }\n /**\n * Sets the angle above/below the horizontal plane to return to when the return to default elevation idle\n * behaviour is triggered, in radians.\n */\n set defaultElevation(elevation) {\n this._defaultElevation = elevation;\n }\n /**\n * Gets the angle above/below the horizontal plane to return to when the return to default elevation idle\n * behaviour is triggered, in radians.\n */\n get defaultElevation() {\n return this._defaultElevation;\n }\n /**\n * Sets the time (in milliseconds) taken to return to the default beta position.\n * Negative value indicates camera should not return to default.\n */\n set elevationReturnTime(speed) {\n this._elevationReturnTime = speed;\n }\n /**\n * Gets the time (in milliseconds) taken to return to the default beta position.\n * Negative value indicates camera should not return to default.\n */\n get elevationReturnTime() {\n return this._elevationReturnTime;\n }\n /**\n * Sets the delay (in milliseconds) taken before the camera returns to the default beta position.\n */\n set elevationReturnWaitTime(time) {\n this._elevationReturnWaitTime = time;\n }\n /**\n * Gets the delay (in milliseconds) taken before the camera returns to the default beta position.\n */\n get elevationReturnWaitTime() {\n return this._elevationReturnWaitTime;\n }\n /**\n * Sets the flag that indicates if user zooming should stop animation.\n */\n set zoomStopsAnimation(flag) {\n this._zoomStopsAnimation = flag;\n }\n /**\n * Gets the flag that indicates if user zooming should stop animation.\n */\n get zoomStopsAnimation() {\n return this._zoomStopsAnimation;\n }\n /**\n * Sets the transition time when framing the mesh, in milliseconds\n */\n set framingTime(time) {\n this._framingTime = time;\n }\n /**\n * Gets the transition time when framing the mesh, in milliseconds\n */\n get framingTime() {\n return this._framingTime;\n }\n /**\n * Initializes the behavior.\n */\n init() {\n // Do nothing\n }\n /**\n * Attaches the behavior to its arc rotate camera.\n * @param camera Defines the camera to attach the behavior to\n */\n attach(camera) {\n this._attachedCamera = camera;\n const scene = this._attachedCamera.getScene();\n FramingBehavior.EasingFunction.setEasingMode(FramingBehavior.EasingMode);\n this._onPrePointerObservableObserver = scene.onPrePointerObservable.add((pointerInfoPre) => {\n if (pointerInfoPre.type === PointerEventTypes.POINTERDOWN) {\n this._isPointerDown = true;\n return;\n }\n if (pointerInfoPre.type === PointerEventTypes.POINTERUP) {\n this._isPointerDown = false;\n }\n });\n this._onMeshTargetChangedObserver = camera.onMeshTargetChangedObservable.add((mesh) => {\n if (mesh) {\n this.zoomOnMesh(mesh, undefined, () => {\n this.onTargetFramingAnimationEndObservable.notifyObservers();\n });\n }\n });\n this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {\n // Stop the animation if there is user interaction and the animation should stop for this interaction\n this._applyUserInteraction();\n // Maintain the camera above the ground. If the user pulls the camera beneath the ground plane, lift it\n // back to the default position after a given timeout\n this._maintainCameraAboveGround();\n });\n }\n /**\n * Detaches the behavior from its current arc rotate camera.\n */\n detach() {\n if (!this._attachedCamera) {\n return;\n }\n const scene = this._attachedCamera.getScene();\n if (this._onPrePointerObservableObserver) {\n scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);\n }\n if (this._onAfterCheckInputsObserver) {\n this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);\n }\n if (this._onMeshTargetChangedObserver) {\n this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);\n }\n this._attachedCamera = null;\n }\n /**\n * Targets the given mesh and updates zoom level accordingly.\n * @param mesh The mesh to target.\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\n * @param onAnimationEnd Callback triggered at the end of the framing animation\n */\n zoomOnMesh(mesh, focusOnOriginXZ = false, onAnimationEnd = null) {\n mesh.computeWorldMatrix(true);\n const boundingBox = mesh.getBoundingInfo().boundingBox;\n this.zoomOnBoundingInfo(boundingBox.minimumWorld, boundingBox.maximumWorld, focusOnOriginXZ, onAnimationEnd);\n }\n /**\n * Targets the given mesh with its children and updates zoom level accordingly.\n * @param mesh The mesh to target.\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\n * @param onAnimationEnd Callback triggered at the end of the framing animation\n */\n zoomOnMeshHierarchy(mesh, focusOnOriginXZ = false, onAnimationEnd = null) {\n mesh.computeWorldMatrix(true);\n const boundingBox = mesh.getHierarchyBoundingVectors(true);\n this.zoomOnBoundingInfo(boundingBox.min, boundingBox.max, focusOnOriginXZ, onAnimationEnd);\n }\n /**\n * Targets the given meshes with their children and updates zoom level accordingly.\n * @param meshes The mesh to target.\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\n * @param onAnimationEnd Callback triggered at the end of the framing animation\n */\n zoomOnMeshesHierarchy(meshes, focusOnOriginXZ = false, onAnimationEnd = null) {\n const min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n const max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n for (let i = 0; i < meshes.length; i++) {\n const boundingInfo = meshes[i].getHierarchyBoundingVectors(true);\n Vector3.CheckExtends(boundingInfo.min, min, max);\n Vector3.CheckExtends(boundingInfo.max, min, max);\n }\n this.zoomOnBoundingInfo(min, max, focusOnOriginXZ, onAnimationEnd);\n }\n /**\n * Targets the bounding box info defined by its extends and updates zoom level accordingly.\n * @param minimumWorld Determines the smaller position of the bounding box extend\n * @param maximumWorld Determines the bigger position of the bounding box extend\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\n * @param onAnimationEnd Callback triggered at the end of the framing animation\n * @returns true if the zoom was done\n */\n zoomOnBoundingInfo(minimumWorld, maximumWorld, focusOnOriginXZ = false, onAnimationEnd = null) {\n let zoomTarget;\n if (!this._attachedCamera) {\n return false;\n }\n // Find target by interpolating from bottom of bounding box in world-space to top via framingPositionY\n const bottom = minimumWorld.y;\n const top = maximumWorld.y;\n const zoomTargetY = bottom + (top - bottom) * this._positionScale;\n const radiusWorld = maximumWorld.subtract(minimumWorld).scale(0.5);\n if (focusOnOriginXZ) {\n zoomTarget = new Vector3(0, zoomTargetY, 0);\n }\n else {\n const centerWorld = minimumWorld.add(radiusWorld);\n zoomTarget = new Vector3(centerWorld.x, zoomTargetY, centerWorld.z);\n }\n if (!this._vectorTransition) {\n this._vectorTransition = Animation.CreateAnimation(\"target\", Animation.ANIMATIONTYPE_VECTOR3, 60, FramingBehavior.EasingFunction);\n }\n this._betaIsAnimating = true;\n let animatable = Animation.TransitionTo(\"target\", zoomTarget, this._attachedCamera, this._attachedCamera.getScene(), 60, this._vectorTransition, this._framingTime);\n if (animatable) {\n this._animatables.push(animatable);\n }\n // sets the radius and lower radius bounds\n // Small delta ensures camera is not always at lower zoom limit.\n let radius = 0;\n if (this._mode === FramingBehavior.FitFrustumSidesMode) {\n const position = this._calculateLowerRadiusFromModelBoundingSphere(minimumWorld, maximumWorld);\n if (this.autoCorrectCameraLimitsAndSensibility) {\n this._attachedCamera.lowerRadiusLimit = radiusWorld.length() + this._attachedCamera.minZ;\n }\n radius = position;\n }\n else if (this._mode === FramingBehavior.IgnoreBoundsSizeMode) {\n radius = this._calculateLowerRadiusFromModelBoundingSphere(minimumWorld, maximumWorld);\n if (this.autoCorrectCameraLimitsAndSensibility && this._attachedCamera.lowerRadiusLimit === null) {\n this._attachedCamera.lowerRadiusLimit = this._attachedCamera.minZ;\n }\n }\n // Set sensibilities\n if (this.autoCorrectCameraLimitsAndSensibility) {\n const extend = maximumWorld.subtract(minimumWorld).length();\n this._attachedCamera.panningSensibility = 5000 / extend;\n this._attachedCamera.wheelPrecision = 100 / radius;\n }\n // transition to new radius\n if (!this._radiusTransition) {\n this._radiusTransition = Animation.CreateAnimation(\"radius\", Animation.ANIMATIONTYPE_FLOAT, 60, FramingBehavior.EasingFunction);\n }\n animatable = Animation.TransitionTo(\"radius\", radius, this._attachedCamera, this._attachedCamera.getScene(), 60, this._radiusTransition, this._framingTime, () => {\n this.stopAllAnimations();\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n if (this._attachedCamera && this._attachedCamera.useInputToRestoreState) {\n this._attachedCamera.storeState();\n }\n });\n if (animatable) {\n this._animatables.push(animatable);\n }\n return true;\n }\n /**\n * Calculates the lowest radius for the camera based on the bounding box of the mesh.\n * @param minimumWorld\n * @param maximumWorld\n * @returns The minimum distance from the primary mesh's center point at which the camera must be kept in order\n *\t\t to fully enclose the mesh in the viewing frustum.\n */\n _calculateLowerRadiusFromModelBoundingSphere(minimumWorld, maximumWorld) {\n const size = maximumWorld.subtract(minimumWorld);\n const boxVectorGlobalDiagonal = size.length();\n const frustumSlope = this._getFrustumSlope();\n // Formula for setting distance\n // (Good explanation: http://stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene)\n const radiusWithoutFraming = boxVectorGlobalDiagonal * 0.5;\n // Horizon distance\n const radius = radiusWithoutFraming * this._radiusScale;\n const distanceForHorizontalFrustum = radius * Math.sqrt(1.0 + 1.0 / (frustumSlope.x * frustumSlope.x));\n const distanceForVerticalFrustum = radius * Math.sqrt(1.0 + 1.0 / (frustumSlope.y * frustumSlope.y));\n let distance = Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum);\n const camera = this._attachedCamera;\n if (!camera) {\n return 0;\n }\n if (camera.lowerRadiusLimit && this._mode === FramingBehavior.IgnoreBoundsSizeMode) {\n // Don't exceed the requested limit\n distance = distance < camera.lowerRadiusLimit ? camera.lowerRadiusLimit : distance;\n }\n // Don't exceed the upper radius limit\n if (camera.upperRadiusLimit) {\n distance = distance > camera.upperRadiusLimit ? camera.upperRadiusLimit : distance;\n }\n return distance;\n }\n /**\n * Keeps the camera above the ground plane. If the user pulls the camera below the ground plane, the camera\n * is automatically returned to its default position (expected to be above ground plane).\n */\n _maintainCameraAboveGround() {\n if (this._elevationReturnTime < 0) {\n return;\n }\n const timeSinceInteraction = PrecisionDate.Now - this._lastInteractionTime;\n const defaultBeta = Math.PI * 0.5 - this._defaultElevation;\n const limitBeta = Math.PI * 0.5;\n // Bring the camera back up if below the ground plane\n if (this._attachedCamera && !this._betaIsAnimating && this._attachedCamera.beta > limitBeta && timeSinceInteraction >= this._elevationReturnWaitTime) {\n this._betaIsAnimating = true;\n //Transition to new position\n this.stopAllAnimations();\n if (!this._betaTransition) {\n this._betaTransition = Animation.CreateAnimation(\"beta\", Animation.ANIMATIONTYPE_FLOAT, 60, FramingBehavior.EasingFunction);\n }\n const animatabe = Animation.TransitionTo(\"beta\", defaultBeta, this._attachedCamera, this._attachedCamera.getScene(), 60, this._betaTransition, this._elevationReturnTime, () => {\n this._clearAnimationLocks();\n this.stopAllAnimations();\n });\n if (animatabe) {\n this._animatables.push(animatabe);\n }\n }\n }\n /**\n * Returns the frustum slope based on the canvas ratio and camera FOV\n * @returns The frustum slope represented as a Vector2 with X and Y slopes\n */\n _getFrustumSlope() {\n // Calculate the viewport ratio\n // Aspect Ratio is Height/Width.\n const camera = this._attachedCamera;\n if (!camera) {\n return Vector2.Zero();\n }\n const engine = camera.getScene().getEngine();\n const aspectRatio = engine.getAspectRatio(camera);\n // Camera FOV is the vertical field of view (top-bottom) in radians.\n // Slope of the frustum top/bottom planes in view space, relative to the forward vector.\n const frustumSlopeY = Math.tan(camera.fov / 2);\n // Slope of the frustum left/right planes in view space, relative to the forward vector.\n // Provides the amount that one side (e.g. left) of the frustum gets wider for every unit\n // along the forward vector.\n const frustumSlopeX = frustumSlopeY * aspectRatio;\n return new Vector2(frustumSlopeX, frustumSlopeY);\n }\n /**\n * Removes all animation locks. Allows new animations to be added to any of the arcCamera properties.\n */\n _clearAnimationLocks() {\n this._betaIsAnimating = false;\n }\n /**\n * Applies any current user interaction to the camera. Takes into account maximum alpha rotation.\n */\n _applyUserInteraction() {\n if (this.isUserIsMoving) {\n this._lastInteractionTime = PrecisionDate.Now;\n this.stopAllAnimations();\n this._clearAnimationLocks();\n }\n }\n /**\n * Stops and removes all animations that have been applied to the camera\n */\n stopAllAnimations() {\n if (this._attachedCamera) {\n this._attachedCamera.animations = [];\n }\n while (this._animatables.length) {\n if (this._animatables[0]) {\n this._animatables[0].onAnimationEnd = null;\n this._animatables[0].stop();\n }\n this._animatables.shift();\n }\n }\n /**\n * Gets a value indicating if the user is moving the camera\n */\n get isUserIsMoving() {\n if (!this._attachedCamera) {\n return false;\n }\n return (this._attachedCamera.inertialAlphaOffset !== 0 ||\n this._attachedCamera.inertialBetaOffset !== 0 ||\n this._attachedCamera.inertialRadiusOffset !== 0 ||\n this._attachedCamera.inertialPanningX !== 0 ||\n this._attachedCamera.inertialPanningY !== 0 ||\n this._isPointerDown);\n }\n }\n /**\n * The easing function used by animations\n */\n FramingBehavior.EasingFunction = new ExponentialEase();\n /**\n * The easing mode used by animations\n */\n FramingBehavior.EasingMode = EasingFunction.EASINGMODE_EASEINOUT;\n // Statics\n /**\n * The camera can move all the way towards the mesh.\n */\n FramingBehavior.IgnoreBoundsSizeMode = 0;\n /**\n * The camera is not allowed to zoom closer to the mesh than the point at which the adjusted bounding sphere touches the frustum sides\n */\n FramingBehavior.FitFrustumSidesMode = 1;\n\n /**\n * A target camera takes a mesh or position as a target and continues to look at it while it moves.\n * This is the base of the follow, arc rotate cameras and Free camera\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\n */\n class TargetCamera extends Camera {\n /**\n * Instantiates a target camera that takes a mesh or position as a target and continues to look at it while it moves.\n * This is the base of the follow, arc rotate cameras and Free camera\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\n * @param name Defines the name of the camera in the scene\n * @param position Defines the start position of the camera in the scene\n * @param scene Defines the scene the camera belongs to\n * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined\n */\n constructor(name, position, scene, setActiveOnSceneIfNoneActive = true) {\n super(name, position, scene, setActiveOnSceneIfNoneActive);\n this._tmpUpVector = Vector3.Zero();\n this._tmpTargetVector = Vector3.Zero();\n /**\n * Define the current direction the camera is moving to\n */\n this.cameraDirection = new Vector3(0, 0, 0);\n /**\n * Define the current rotation the camera is rotating to\n */\n this.cameraRotation = new Vector2(0, 0);\n /** Gets or sets a boolean indicating that the scaling of the parent hierarchy will not be taken in account by the camera */\n this.ignoreParentScaling = false;\n /**\n * When set, the up vector of the camera will be updated by the rotation of the camera\n */\n this.updateUpVectorFromRotation = false;\n this._tmpQuaternion = new Quaternion();\n /**\n * Define the current rotation of the camera\n */\n this.rotation = new Vector3(0, 0, 0);\n /**\n * Define the current speed of the camera\n */\n this.speed = 2.0;\n /**\n * Add constraint to the camera to prevent it to move freely in all directions and\n * around all axis.\n */\n this.noRotationConstraint = false;\n /**\n * Reverses mouselook direction to 'natural' panning as opposed to traditional direct\n * panning\n */\n this.invertRotation = false;\n /**\n * Speed multiplier for inverse camera panning\n */\n this.inverseRotationSpeed = 0.2;\n /**\n * Define the current target of the camera as an object or a position.\n * Please note that locking a target will disable panning.\n */\n this.lockedTarget = null;\n /** @internal */\n this._currentTarget = Vector3.Zero();\n /** @internal */\n this._initialFocalDistance = 1;\n /** @internal */\n this._viewMatrix = Matrix.Zero();\n /** @internal */\n this._camMatrix = Matrix.Zero();\n /** @internal */\n this._cameraTransformMatrix = Matrix.Zero();\n /** @internal */\n this._cameraRotationMatrix = Matrix.Zero();\n /** @internal */\n this._referencePoint = new Vector3(0, 0, 1);\n /** @internal */\n this._transformedReferencePoint = Vector3.Zero();\n this._deferredPositionUpdate = new Vector3();\n this._deferredRotationQuaternionUpdate = new Quaternion();\n this._deferredRotationUpdate = new Vector3();\n this._deferredUpdated = false;\n this._deferOnly = false;\n this._defaultUp = Vector3.Up();\n this._cachedRotationZ = 0;\n this._cachedQuaternionRotationZ = 0;\n }\n /**\n * Gets the position in front of the camera at a given distance.\n * @param distance The distance from the camera we want the position to be\n * @returns the position\n */\n getFrontPosition(distance) {\n this.getWorldMatrix();\n const direction = this.getTarget().subtract(this.position);\n direction.normalize();\n direction.scaleInPlace(distance);\n return this.globalPosition.add(direction);\n }\n /** @internal */\n _getLockedTargetPosition() {\n if (!this.lockedTarget) {\n return null;\n }\n if (this.lockedTarget.absolutePosition) {\n const lockedTarget = this.lockedTarget;\n const m = lockedTarget.computeWorldMatrix();\n // in some cases the absolute position resets externally, but doesn't update since the matrix is cached.\n m.getTranslationToRef(lockedTarget.absolutePosition);\n }\n return this.lockedTarget.absolutePosition || this.lockedTarget;\n }\n /**\n * Store current camera state of the camera (fov, position, rotation, etc..)\n * @returns the camera\n */\n storeState() {\n this._storedPosition = this.position.clone();\n this._storedRotation = this.rotation.clone();\n if (this.rotationQuaternion) {\n this._storedRotationQuaternion = this.rotationQuaternion.clone();\n }\n return super.storeState();\n }\n /**\n * Restored camera state. You must call storeState() first\n * @returns whether it was successful or not\n * @internal\n */\n _restoreStateValues() {\n if (!super._restoreStateValues()) {\n return false;\n }\n this.position = this._storedPosition.clone();\n this.rotation = this._storedRotation.clone();\n if (this.rotationQuaternion) {\n this.rotationQuaternion = this._storedRotationQuaternion.clone();\n }\n this.cameraDirection.copyFromFloats(0, 0, 0);\n this.cameraRotation.copyFromFloats(0, 0);\n return true;\n }\n /** @internal */\n _initCache() {\n super._initCache();\n this._cache.lockedTarget = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cache.rotation = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cache.rotationQuaternion = new Quaternion(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n }\n /**\n * @internal\n */\n _updateCache(ignoreParentClass) {\n if (!ignoreParentClass) {\n super._updateCache();\n }\n const lockedTargetPosition = this._getLockedTargetPosition();\n if (!lockedTargetPosition) {\n this._cache.lockedTarget = null;\n }\n else {\n if (!this._cache.lockedTarget) {\n this._cache.lockedTarget = lockedTargetPosition.clone();\n }\n else {\n this._cache.lockedTarget.copyFrom(lockedTargetPosition);\n }\n }\n this._cache.rotation.copyFrom(this.rotation);\n if (this.rotationQuaternion) {\n this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);\n }\n }\n // Synchronized\n /** @internal */\n _isSynchronizedViewMatrix() {\n if (!super._isSynchronizedViewMatrix()) {\n return false;\n }\n const lockedTargetPosition = this._getLockedTargetPosition();\n return ((this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition) &&\n (this.rotationQuaternion ? this.rotationQuaternion.equals(this._cache.rotationQuaternion) : this._cache.rotation.equals(this.rotation)));\n }\n // Methods\n /** @internal */\n _computeLocalCameraSpeed() {\n const engine = this.getEngine();\n return this.speed * Math.sqrt(engine.getDeltaTime() / (engine.getFps() * 100.0));\n }\n // Target\n /**\n * Defines the target the camera should look at.\n * @param target Defines the new target as a Vector\n */\n setTarget(target) {\n this.upVector.normalize();\n this._initialFocalDistance = target.subtract(this.position).length();\n if (this.position.z === target.z) {\n this.position.z += Epsilon;\n }\n this._referencePoint.normalize().scaleInPlace(this._initialFocalDistance);\n Matrix.LookAtLHToRef(this.position, target, this._defaultUp, this._camMatrix);\n this._camMatrix.invert();\n this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);\n const vDir = target.subtract(this.position);\n if (vDir.x >= 0.0) {\n this.rotation.y = -Math.atan(vDir.z / vDir.x) + Math.PI / 2.0;\n }\n else {\n this.rotation.y = -Math.atan(vDir.z / vDir.x) - Math.PI / 2.0;\n }\n this.rotation.z = 0;\n if (isNaN(this.rotation.x)) {\n this.rotation.x = 0;\n }\n if (isNaN(this.rotation.y)) {\n this.rotation.y = 0;\n }\n if (isNaN(this.rotation.z)) {\n this.rotation.z = 0;\n }\n if (this.rotationQuaternion) {\n Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this.rotationQuaternion);\n }\n }\n /**\n * Defines the target point of the camera.\n * The camera looks towards it form the radius distance.\n */\n get target() {\n return this.getTarget();\n }\n set target(value) {\n this.setTarget(value);\n }\n /**\n * Return the current target position of the camera. This value is expressed in local space.\n * @returns the target position\n */\n getTarget() {\n return this._currentTarget;\n }\n /** @internal */\n _decideIfNeedsToMove() {\n return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;\n }\n /** @internal */\n _updatePosition() {\n if (this.parent) {\n this.parent.getWorldMatrix().invertToRef(TmpVectors.Matrix[0]);\n Vector3.TransformNormalToRef(this.cameraDirection, TmpVectors.Matrix[0], TmpVectors.Vector3[0]);\n this._deferredPositionUpdate.addInPlace(TmpVectors.Vector3[0]);\n if (!this._deferOnly) {\n this.position.copyFrom(this._deferredPositionUpdate);\n }\n else {\n this._deferredUpdated = true;\n }\n return;\n }\n this._deferredPositionUpdate.addInPlace(this.cameraDirection);\n if (!this._deferOnly) {\n this.position.copyFrom(this._deferredPositionUpdate);\n }\n else {\n this._deferredUpdated = true;\n }\n }\n /** @internal */\n _checkInputs() {\n const directionMultiplier = this.invertRotation ? -this.inverseRotationSpeed : 1.0;\n const needToMove = this._decideIfNeedsToMove();\n const needToRotate = this.cameraRotation.x || this.cameraRotation.y;\n this._deferredUpdated = false;\n this._deferredRotationUpdate.copyFrom(this.rotation);\n this._deferredPositionUpdate.copyFrom(this.position);\n if (this.rotationQuaternion) {\n this._deferredRotationQuaternionUpdate.copyFrom(this.rotationQuaternion);\n }\n // Move\n if (needToMove) {\n this._updatePosition();\n }\n // Rotate\n if (needToRotate) {\n //rotate, if quaternion is set and rotation was used\n if (this.rotationQuaternion) {\n this.rotationQuaternion.toEulerAnglesToRef(this._deferredRotationUpdate);\n }\n this._deferredRotationUpdate.x += this.cameraRotation.x * directionMultiplier;\n this._deferredRotationUpdate.y += this.cameraRotation.y * directionMultiplier;\n // Apply constraints\n if (!this.noRotationConstraint) {\n const limit = 1.570796;\n if (this._deferredRotationUpdate.x > limit) {\n this._deferredRotationUpdate.x = limit;\n }\n if (this._deferredRotationUpdate.x < -limit) {\n this._deferredRotationUpdate.x = -limit;\n }\n }\n if (!this._deferOnly) {\n this.rotation.copyFrom(this._deferredRotationUpdate);\n }\n else {\n this._deferredUpdated = true;\n }\n //rotate, if quaternion is set and rotation was used\n if (this.rotationQuaternion) {\n const len = this._deferredRotationUpdate.lengthSquared();\n if (len) {\n Quaternion.RotationYawPitchRollToRef(this._deferredRotationUpdate.y, this._deferredRotationUpdate.x, this._deferredRotationUpdate.z, this._deferredRotationQuaternionUpdate);\n if (!this._deferOnly) {\n this.rotationQuaternion.copyFrom(this._deferredRotationQuaternionUpdate);\n }\n else {\n this._deferredUpdated = true;\n }\n }\n }\n }\n // Inertia\n if (needToMove) {\n if (Math.abs(this.cameraDirection.x) < this.speed * Epsilon) {\n this.cameraDirection.x = 0;\n }\n if (Math.abs(this.cameraDirection.y) < this.speed * Epsilon) {\n this.cameraDirection.y = 0;\n }\n if (Math.abs(this.cameraDirection.z) < this.speed * Epsilon) {\n this.cameraDirection.z = 0;\n }\n this.cameraDirection.scaleInPlace(this.inertia);\n }\n if (needToRotate) {\n if (Math.abs(this.cameraRotation.x) < this.speed * Epsilon) {\n this.cameraRotation.x = 0;\n }\n if (Math.abs(this.cameraRotation.y) < this.speed * Epsilon) {\n this.cameraRotation.y = 0;\n }\n this.cameraRotation.scaleInPlace(this.inertia);\n }\n super._checkInputs();\n }\n _updateCameraRotationMatrix() {\n if (this.rotationQuaternion) {\n this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix);\n }\n else {\n Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);\n }\n }\n /**\n * Update the up vector to apply the rotation of the camera (So if you changed the camera rotation.z this will let you update the up vector as well)\n * @returns the current camera\n */\n _rotateUpVectorWithCameraRotationMatrix() {\n Vector3.TransformNormalToRef(this._defaultUp, this._cameraRotationMatrix, this.upVector);\n return this;\n }\n /** @internal */\n _getViewMatrix() {\n if (this.lockedTarget) {\n this.setTarget(this._getLockedTargetPosition());\n }\n // Compute\n this._updateCameraRotationMatrix();\n // Apply the changed rotation to the upVector\n if (this.rotationQuaternion && this._cachedQuaternionRotationZ != this.rotationQuaternion.z) {\n this._rotateUpVectorWithCameraRotationMatrix();\n this._cachedQuaternionRotationZ = this.rotationQuaternion.z;\n }\n else if (this._cachedRotationZ !== this.rotation.z) {\n this._rotateUpVectorWithCameraRotationMatrix();\n this._cachedRotationZ = this.rotation.z;\n }\n Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);\n // Computing target and final matrix\n this.position.addToRef(this._transformedReferencePoint, this._currentTarget);\n if (this.updateUpVectorFromRotation) {\n if (this.rotationQuaternion) {\n Axis.Y.rotateByQuaternionToRef(this.rotationQuaternion, this.upVector);\n }\n else {\n Quaternion.FromEulerVectorToRef(this.rotation, this._tmpQuaternion);\n Axis.Y.rotateByQuaternionToRef(this._tmpQuaternion, this.upVector);\n }\n }\n this._computeViewMatrix(this.position, this._currentTarget, this.upVector);\n return this._viewMatrix;\n }\n _computeViewMatrix(position, target, up) {\n if (this.ignoreParentScaling) {\n if (this.parent) {\n const parentWorldMatrix = this.parent.getWorldMatrix();\n Vector3.TransformCoordinatesToRef(position, parentWorldMatrix, this._globalPosition);\n Vector3.TransformCoordinatesToRef(target, parentWorldMatrix, this._tmpTargetVector);\n Vector3.TransformNormalToRef(up, parentWorldMatrix, this._tmpUpVector);\n this._markSyncedWithParent();\n }\n else {\n this._globalPosition.copyFrom(position);\n this._tmpTargetVector.copyFrom(target);\n this._tmpUpVector.copyFrom(up);\n }\n if (this.getScene().useRightHandedSystem) {\n Matrix.LookAtRHToRef(this._globalPosition, this._tmpTargetVector, this._tmpUpVector, this._viewMatrix);\n }\n else {\n Matrix.LookAtLHToRef(this._globalPosition, this._tmpTargetVector, this._tmpUpVector, this._viewMatrix);\n }\n return;\n }\n if (this.getScene().useRightHandedSystem) {\n Matrix.LookAtRHToRef(position, target, up, this._viewMatrix);\n }\n else {\n Matrix.LookAtLHToRef(position, target, up, this._viewMatrix);\n }\n if (this.parent) {\n const parentWorldMatrix = this.parent.getWorldMatrix();\n this._viewMatrix.invert();\n this._viewMatrix.multiplyToRef(parentWorldMatrix, this._viewMatrix);\n this._viewMatrix.getTranslationToRef(this._globalPosition);\n this._viewMatrix.invert();\n this._markSyncedWithParent();\n }\n else {\n this._globalPosition.copyFrom(position);\n }\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n createRigCamera(name, cameraIndex) {\n if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\n const rigCamera = new TargetCamera(name, this.position.clone(), this.getScene());\n rigCamera.isRigCamera = true;\n rigCamera.rigParent = this;\n if (this.cameraRigMode === Camera.RIG_MODE_VR || this.cameraRigMode === Camera.RIG_MODE_WEBVR) {\n if (!this.rotationQuaternion) {\n this.rotationQuaternion = new Quaternion();\n }\n rigCamera._cameraRigParams = {};\n rigCamera.rotationQuaternion = new Quaternion();\n }\n rigCamera.mode = this.mode;\n rigCamera.orthoLeft = this.orthoLeft;\n rigCamera.orthoRight = this.orthoRight;\n rigCamera.orthoTop = this.orthoTop;\n rigCamera.orthoBottom = this.orthoBottom;\n return rigCamera;\n }\n return null;\n }\n /**\n * @internal\n */\n _updateRigCameras() {\n const camLeft = this._rigCameras[0];\n const camRight = this._rigCameras[1];\n this.computeWorldMatrix();\n switch (this.cameraRigMode) {\n case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:\n case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:\n case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED: {\n //provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:\n const leftSign = this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED ? 1 : -1;\n const rightSign = this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED ? -1 : 1;\n this._getRigCamPositionAndTarget(this._cameraRigParams.stereoHalfAngle * leftSign, camLeft);\n this._getRigCamPositionAndTarget(this._cameraRigParams.stereoHalfAngle * rightSign, camRight);\n break;\n }\n case Camera.RIG_MODE_VR:\n if (camLeft.rotationQuaternion) {\n camLeft.rotationQuaternion.copyFrom(this.rotationQuaternion);\n camRight.rotationQuaternion.copyFrom(this.rotationQuaternion);\n }\n else {\n camLeft.rotation.copyFrom(this.rotation);\n camRight.rotation.copyFrom(this.rotation);\n }\n camLeft.position.copyFrom(this.position);\n camRight.position.copyFrom(this.position);\n break;\n }\n super._updateRigCameras();\n }\n _getRigCamPositionAndTarget(halfSpace, rigCamera) {\n const target = this.getTarget();\n target.subtractToRef(this.position, TargetCamera._TargetFocalPoint);\n TargetCamera._TargetFocalPoint.normalize().scaleInPlace(this._initialFocalDistance);\n const newFocalTarget = TargetCamera._TargetFocalPoint.addInPlace(this.position);\n Matrix.TranslationToRef(-newFocalTarget.x, -newFocalTarget.y, -newFocalTarget.z, TargetCamera._TargetTransformMatrix);\n TargetCamera._TargetTransformMatrix.multiplyToRef(Matrix.RotationAxis(rigCamera.upVector, halfSpace), TargetCamera._RigCamTransformMatrix);\n Matrix.TranslationToRef(newFocalTarget.x, newFocalTarget.y, newFocalTarget.z, TargetCamera._TargetTransformMatrix);\n TargetCamera._RigCamTransformMatrix.multiplyToRef(TargetCamera._TargetTransformMatrix, TargetCamera._RigCamTransformMatrix);\n Vector3.TransformCoordinatesToRef(this.position, TargetCamera._RigCamTransformMatrix, rigCamera.position);\n rigCamera.setTarget(newFocalTarget);\n }\n /**\n * Gets the current object class name.\n * @returns the class name\n */\n getClassName() {\n return \"TargetCamera\";\n }\n }\n TargetCamera._RigCamTransformMatrix = new Matrix();\n TargetCamera._TargetTransformMatrix = new Matrix();\n TargetCamera._TargetFocalPoint = new Vector3();\n __decorate$1([\n serializeAsVector3()\n ], TargetCamera.prototype, \"rotation\", void 0);\n __decorate$1([\n serialize()\n ], TargetCamera.prototype, \"speed\", void 0);\n __decorate$1([\n serializeAsMeshReference(\"lockedTargetId\")\n ], TargetCamera.prototype, \"lockedTarget\", void 0);\n\n /**\n * @ignore\n * This is a list of all the different input types that are available in the application.\n * Fo instance: ArcRotateCameraGamepadInput...\n */\n // eslint-disable-next-line no-var, @typescript-eslint/naming-convention\n var CameraInputTypes = {};\n /**\n * This represents the input manager used within a camera.\n * It helps dealing with all the different kind of input attached to a camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class CameraInputsManager {\n /**\n * Instantiate a new Camera Input Manager.\n * @param camera Defines the camera the input manager belongs to\n */\n constructor(camera) {\n /**\n * Defines the dom element the camera is collecting inputs from.\n * This is null if the controls have not been attached.\n */\n this.attachedToElement = false;\n this.attached = {};\n this.camera = camera;\n this.checkInputs = () => { };\n }\n /**\n * Add an input method to a camera\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n * @param input Camera input method\n */\n add(input) {\n const type = input.getSimpleName();\n if (this.attached[type]) {\n Logger.Warn(\"camera input of type \" + type + \" already exists on camera\");\n return;\n }\n this.attached[type] = input;\n input.camera = this.camera;\n // for checkInputs, we are dynamically creating a function\n // the goal is to avoid the performance penalty of looping for inputs in the render loop\n if (input.checkInputs) {\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\n }\n if (this.attachedToElement) {\n input.attachControl(this.noPreventDefault);\n }\n }\n /**\n * Remove a specific input method from a camera\n * example: camera.inputs.remove(camera.inputs.attached.mouse);\n * @param inputToRemove camera input method\n */\n remove(inputToRemove) {\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input === inputToRemove) {\n input.detachControl();\n input.camera = null;\n delete this.attached[cam];\n this.rebuildInputCheck();\n return;\n }\n }\n }\n /**\n * Remove a specific input type from a camera\n * example: camera.inputs.remove(\"ArcRotateCameraGamepadInput\");\n * @param inputType the type of the input to remove\n */\n removeByType(inputType) {\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input.getClassName() === inputType) {\n input.detachControl();\n input.camera = null;\n delete this.attached[cam];\n this.rebuildInputCheck();\n }\n }\n }\n _addCheckInputs(fn) {\n const current = this.checkInputs;\n return () => {\n current();\n fn();\n };\n }\n /**\n * Attach the input controls to the currently attached dom element to listen the events from.\n * @param input Defines the input to attach\n */\n attachInput(input) {\n if (this.attachedToElement) {\n input.attachControl(this.noPreventDefault);\n }\n }\n /**\n * Attach the current manager inputs controls to a specific dom element to listen the events from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachElement(noPreventDefault = false) {\n if (this.attachedToElement) {\n return;\n }\n noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;\n this.attachedToElement = true;\n this.noPreventDefault = noPreventDefault;\n for (const cam in this.attached) {\n this.attached[cam].attachControl(noPreventDefault);\n }\n }\n /**\n * Detach the current manager inputs controls from a specific dom element.\n * @param disconnect Defines whether the input should be removed from the current list of attached inputs\n */\n detachElement(disconnect = false) {\n for (const cam in this.attached) {\n this.attached[cam].detachControl();\n if (disconnect) {\n this.attached[cam].camera = null;\n }\n }\n this.attachedToElement = false;\n }\n /**\n * Rebuild the dynamic inputCheck function from the current list of\n * defined inputs in the manager.\n */\n rebuildInputCheck() {\n this.checkInputs = () => { };\n for (const cam in this.attached) {\n const input = this.attached[cam];\n if (input.checkInputs) {\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\n }\n }\n }\n /**\n * Remove all attached input methods from a camera\n */\n clear() {\n if (this.attachedToElement) {\n this.detachElement(true);\n }\n this.attached = {};\n this.attachedToElement = false;\n this.checkInputs = () => { };\n }\n /**\n * Serialize the current input manager attached to a camera.\n * This ensures than once parsed,\n * the input associated to the camera will be identical to the current ones\n * @param serializedCamera Defines the camera serialization JSON the input serialization should write to\n */\n serialize(serializedCamera) {\n const inputs = {};\n for (const cam in this.attached) {\n const input = this.attached[cam];\n const res = SerializationHelper.Serialize(input);\n inputs[input.getClassName()] = res;\n }\n serializedCamera.inputsmgr = inputs;\n }\n /**\n * Parses an input manager serialized JSON to restore the previous list of inputs\n * and states associated to a camera.\n * @param parsedCamera Defines the JSON to parse\n */\n parse(parsedCamera) {\n const parsedInputs = parsedCamera.inputsmgr;\n if (parsedInputs) {\n this.clear();\n for (const n in parsedInputs) {\n const construct = CameraInputTypes[n];\n if (construct) {\n const parsedinput = parsedInputs[n];\n const input = SerializationHelper.Parse(() => {\n return new construct();\n }, parsedinput, null);\n this.add(input);\n }\n }\n }\n else {\n //2016-03-08 this part is for managing backward compatibility\n for (const n in this.attached) {\n const construct = CameraInputTypes[this.attached[n].getClassName()];\n if (construct) {\n const input = SerializationHelper.Parse(() => {\n return new construct();\n }, parsedCamera, null);\n this.remove(this.attached[n]);\n this.add(input);\n }\n }\n }\n }\n }\n\n /**\n * Base class for Camera Pointer Inputs.\n * See FollowCameraPointersInput in src/Cameras/Inputs/followCameraPointersInput.ts\n * for example usage.\n */\n class BaseCameraPointersInput {\n constructor() {\n this._currentActiveButton = -1;\n /**\n * Defines the buttons associated with the input to handle camera move.\n */\n this.buttons = [0, 1, 2];\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n const engine = this.camera.getEngine();\n const element = engine.getInputElement();\n let previousPinchSquaredDistance = 0;\n let previousMultiTouchPanPosition = null;\n this._pointA = null;\n this._pointB = null;\n this._altKey = false;\n this._ctrlKey = false;\n this._metaKey = false;\n this._shiftKey = false;\n this._buttonsPressed = 0;\n this._pointerInput = (p) => {\n var _a, _b;\n const evt = p.event;\n const isTouch = evt.pointerType === \"touch\";\n if (engine.isInVRExclusivePointerMode) {\n return;\n }\n if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {\n return;\n }\n const srcElement = evt.target;\n this._altKey = evt.altKey;\n this._ctrlKey = evt.ctrlKey;\n this._metaKey = evt.metaKey;\n this._shiftKey = evt.shiftKey;\n this._buttonsPressed = evt.buttons;\n if (engine.isPointerLock) {\n const offsetX = evt.movementX;\n const offsetY = evt.movementY;\n this.onTouch(null, offsetX, offsetY);\n this._pointA = null;\n this._pointB = null;\n }\n else if (p.type !== PointerEventTypes.POINTERDOWN && isTouch && ((_a = this._pointA) === null || _a === void 0 ? void 0 : _a.pointerId) !== evt.pointerId && ((_b = this._pointB) === null || _b === void 0 ? void 0 : _b.pointerId) !== evt.pointerId) {\n return; // If we get a non-down event for a touch that we're not tracking, ignore it\n }\n else if (p.type === PointerEventTypes.POINTERDOWN && (this._currentActiveButton === -1 || isTouch)) {\n try {\n srcElement === null || srcElement === void 0 ? void 0 : srcElement.setPointerCapture(evt.pointerId);\n }\n catch (e) {\n //Nothing to do with the error. Execution will continue.\n }\n if (this._pointA === null) {\n this._pointA = {\n x: evt.clientX,\n y: evt.clientY,\n pointerId: evt.pointerId,\n type: evt.pointerType,\n };\n }\n else if (this._pointB === null) {\n this._pointB = {\n x: evt.clientX,\n y: evt.clientY,\n pointerId: evt.pointerId,\n type: evt.pointerType,\n };\n }\n else {\n return; // We are already tracking two pointers so ignore this one\n }\n if (this._currentActiveButton === -1 && !isTouch) {\n this._currentActiveButton = evt.button;\n }\n this.onButtonDown(evt);\n if (!noPreventDefault) {\n evt.preventDefault();\n element && element.focus();\n }\n }\n else if (p.type === PointerEventTypes.POINTERDOUBLETAP) {\n this.onDoubleTap(evt.pointerType);\n }\n else if (p.type === PointerEventTypes.POINTERUP && (this._currentActiveButton === evt.button || isTouch)) {\n try {\n srcElement === null || srcElement === void 0 ? void 0 : srcElement.releasePointerCapture(evt.pointerId);\n }\n catch (e) {\n //Nothing to do with the error.\n }\n if (!isTouch) {\n this._pointB = null; // Mouse and pen are mono pointer\n }\n //would be better to use pointers.remove(evt.pointerId) for multitouch gestures,\n //but emptying completely pointers collection is required to fix a bug on iPhone :\n //when changing orientation while pinching camera,\n //one pointer stay pressed forever if we don't release all pointers\n //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected\n if (engine._badOS) {\n this._pointA = this._pointB = null;\n }\n else {\n //only remove the impacted pointer in case of multitouch allowing on most\n //platforms switching from rotate to zoom and pan seamlessly.\n if (this._pointB && this._pointA && this._pointA.pointerId == evt.pointerId) {\n this._pointA = this._pointB;\n this._pointB = null;\n }\n else if (this._pointA && this._pointB && this._pointB.pointerId == evt.pointerId) {\n this._pointB = null;\n }\n else {\n this._pointA = this._pointB = null;\n }\n }\n if (previousPinchSquaredDistance !== 0 || previousMultiTouchPanPosition) {\n // Previous pinch data is populated but a button has been lifted\n // so pinch has ended.\n this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, 0, // pinchSquaredDistance\n previousMultiTouchPanPosition, null // multiTouchPanPosition\n );\n previousPinchSquaredDistance = 0;\n previousMultiTouchPanPosition = null;\n }\n this._currentActiveButton = -1;\n this.onButtonUp(evt);\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n }\n else if (p.type === PointerEventTypes.POINTERMOVE) {\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n // One button down\n if (this._pointA && this._pointB === null) {\n const offsetX = evt.clientX - this._pointA.x;\n const offsetY = evt.clientY - this._pointA.y;\n this.onTouch(this._pointA, offsetX, offsetY);\n this._pointA.x = evt.clientX;\n this._pointA.y = evt.clientY;\n }\n // Two buttons down: pinch\n else if (this._pointA && this._pointB) {\n const ed = this._pointA.pointerId === evt.pointerId ? this._pointA : this._pointB;\n ed.x = evt.clientX;\n ed.y = evt.clientY;\n const distX = this._pointA.x - this._pointB.x;\n const distY = this._pointA.y - this._pointB.y;\n const pinchSquaredDistance = distX * distX + distY * distY;\n const multiTouchPanPosition = {\n x: (this._pointA.x + this._pointB.x) / 2,\n y: (this._pointA.y + this._pointB.y) / 2,\n pointerId: evt.pointerId,\n type: p.type,\n };\n this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition);\n previousMultiTouchPanPosition = multiTouchPanPosition;\n previousPinchSquaredDistance = pinchSquaredDistance;\n }\n }\n };\n this._observer = this.camera\n .getScene()\n ._inputManager._addCameraPointerObserver(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE | PointerEventTypes.POINTERDOUBLETAP);\n this._onLostFocus = () => {\n this._pointA = this._pointB = null;\n previousPinchSquaredDistance = 0;\n previousMultiTouchPanPosition = null;\n this.onLostFocus();\n };\n this._contextMenuBind = this.onContextMenu.bind(this);\n element && element.addEventListener(\"contextmenu\", this._contextMenuBind, false);\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\n if (hostWindow) {\n Tools.RegisterTopRootEvents(hostWindow, [{ name: \"blur\", handler: this._onLostFocus }]);\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._onLostFocus) {\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\n if (hostWindow) {\n Tools.UnregisterTopRootEvents(hostWindow, [{ name: \"blur\", handler: this._onLostFocus }]);\n }\n }\n if (this._observer) {\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\n this._observer = null;\n if (this._contextMenuBind) {\n const inputElement = this.camera.getScene().getEngine().getInputElement();\n inputElement && inputElement.removeEventListener(\"contextmenu\", this._contextMenuBind);\n }\n this._onLostFocus = null;\n }\n this._altKey = false;\n this._ctrlKey = false;\n this._metaKey = false;\n this._shiftKey = false;\n this._buttonsPressed = 0;\n this._currentActiveButton = -1;\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"BaseCameraPointersInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"pointers\";\n }\n /**\n * Called on pointer POINTERDOUBLETAP event.\n * Override this method to provide functionality on POINTERDOUBLETAP event.\n * @param type\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDoubleTap(type) { }\n /**\n * Called on pointer POINTERMOVE event if only a single touch is active.\n * Override this method to provide functionality.\n * @param point\n * @param offsetX\n * @param offsetY\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onTouch(point, offsetX, offsetY) { }\n /**\n * Called on pointer POINTERMOVE event if multiple touches are active.\n * Override this method to provide functionality.\n * @param _pointA\n * @param _pointB\n * @param previousPinchSquaredDistance\n * @param pinchSquaredDistance\n * @param previousMultiTouchPanPosition\n * @param multiTouchPanPosition\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onMultiTouch(_pointA, _pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition) { }\n /**\n * Called on JS contextmenu event.\n * Override this method to provide functionality.\n * @param evt\n */\n onContextMenu(evt) {\n evt.preventDefault();\n }\n /**\n * Called each time a new POINTERDOWN event occurs. Ie, for each button\n * press.\n * Override this method to provide functionality.\n * @param evt\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onButtonDown(evt) { }\n /**\n * Called each time a new POINTERUP event occurs. Ie, for each button\n * release.\n * Override this method to provide functionality.\n * @param evt\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onButtonUp(evt) { }\n /**\n * Called when window becomes inactive.\n * Override this method to provide functionality.\n */\n onLostFocus() { }\n }\n __decorate$1([\n serialize()\n ], BaseCameraPointersInput.prototype, \"buttons\", void 0);\n\n /**\n * Manage the pointers inputs to control an arc rotate camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class ArcRotateCameraPointersInput extends BaseCameraPointersInput {\n constructor() {\n super(...arguments);\n /**\n * Defines the buttons associated with the input to handle camera move.\n */\n this.buttons = [0, 1, 2];\n /**\n * Defines the pointer angular sensibility along the X axis or how fast is\n * the camera rotating.\n */\n this.angularSensibilityX = 1000.0;\n /**\n * Defines the pointer angular sensibility along the Y axis or how fast is\n * the camera rotating.\n */\n this.angularSensibilityY = 1000.0;\n /**\n * Defines the pointer pinch precision or how fast is the camera zooming.\n */\n this.pinchPrecision = 12.0;\n /**\n * pinchDeltaPercentage will be used instead of pinchPrecision if different\n * from 0.\n * It defines the percentage of current camera.radius to use as delta when\n * pinch zoom is used.\n */\n this.pinchDeltaPercentage = 0;\n /**\n * When useNaturalPinchZoom is true, multi touch zoom will zoom in such\n * that any object in the plane at the camera's target point will scale\n * perfectly with finger motion.\n * Overrides pinchDeltaPercentage and pinchPrecision.\n */\n this.useNaturalPinchZoom = false;\n /**\n * Defines whether zoom (2 fingers pinch) is enabled through multitouch\n */\n this.pinchZoom = true;\n /**\n * Defines the pointer panning sensibility or how fast is the camera moving.\n */\n this.panningSensibility = 1000.0;\n /**\n * Defines whether panning (2 fingers swipe) is enabled through multitouch.\n */\n this.multiTouchPanning = true;\n /**\n * Defines whether panning is enabled for both pan (2 fingers swipe) and\n * zoom (pinch) through multitouch.\n */\n this.multiTouchPanAndZoom = true;\n /**\n * Revers pinch action direction.\n */\n this.pinchInwards = true;\n this._isPanClick = false;\n this._twoFingerActivityCount = 0;\n this._isPinching = false;\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCameraPointersInput\";\n }\n /**\n * Move camera from multi touch panning positions.\n * @param previousMultiTouchPanPosition\n * @param multiTouchPanPosition\n */\n _computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition) {\n if (this.panningSensibility !== 0 && previousMultiTouchPanPosition && multiTouchPanPosition) {\n const moveDeltaX = multiTouchPanPosition.x - previousMultiTouchPanPosition.x;\n const moveDeltaY = multiTouchPanPosition.y - previousMultiTouchPanPosition.y;\n this.camera.inertialPanningX += -moveDeltaX / this.panningSensibility;\n this.camera.inertialPanningY += moveDeltaY / this.panningSensibility;\n }\n }\n /**\n * Move camera from pinch zoom distances.\n * @param previousPinchSquaredDistance\n * @param pinchSquaredDistance\n */\n _computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance) {\n const radius = this.camera.radius || ArcRotateCameraPointersInput.MinimumRadiusForPinch;\n if (this.useNaturalPinchZoom) {\n this.camera.radius = (radius * Math.sqrt(previousPinchSquaredDistance)) / Math.sqrt(pinchSquaredDistance);\n }\n else if (this.pinchDeltaPercentage) {\n this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchSquaredDistance) * 0.001 * radius * this.pinchDeltaPercentage;\n }\n else {\n this.camera.inertialRadiusOffset +=\n (pinchSquaredDistance - previousPinchSquaredDistance) /\n ((this.pinchPrecision * (this.pinchInwards ? 1 : -1) * (this.angularSensibilityX + this.angularSensibilityY)) / 2);\n }\n }\n /**\n * Called on pointer POINTERMOVE event if only a single touch is active.\n * @param point\n * @param offsetX\n * @param offsetY\n */\n onTouch(point, offsetX, offsetY) {\n if (this.panningSensibility !== 0 && ((this._ctrlKey && this.camera._useCtrlForPanning) || this._isPanClick)) {\n this.camera.inertialPanningX += -offsetX / this.panningSensibility;\n this.camera.inertialPanningY += offsetY / this.panningSensibility;\n }\n else {\n this.camera.inertialAlphaOffset -= offsetX / this.angularSensibilityX;\n this.camera.inertialBetaOffset -= offsetY / this.angularSensibilityY;\n }\n }\n /**\n * Called on pointer POINTERDOUBLETAP event.\n */\n onDoubleTap() {\n if (this.camera.useInputToRestoreState) {\n this.camera.restoreState();\n }\n }\n /**\n * Called on pointer POINTERMOVE event if multiple touches are active.\n * @param pointA\n * @param pointB\n * @param previousPinchSquaredDistance\n * @param pinchSquaredDistance\n * @param previousMultiTouchPanPosition\n * @param multiTouchPanPosition\n */\n onMultiTouch(pointA, pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition) {\n if (previousPinchSquaredDistance === 0 && previousMultiTouchPanPosition === null) {\n // First time this method is called for new pinch.\n // Next time this is called there will be a\n // previousPinchSquaredDistance and pinchSquaredDistance to compare.\n return;\n }\n if (pinchSquaredDistance === 0 && multiTouchPanPosition === null) {\n // Last time this method is called at the end of a pinch.\n return;\n }\n // Zoom and panning enabled together\n if (this.multiTouchPanAndZoom) {\n this._computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance);\n this._computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition);\n // Zoom and panning enabled but only one at a time\n }\n else if (this.multiTouchPanning && this.pinchZoom) {\n this._twoFingerActivityCount++;\n if (this._isPinching ||\n (this._twoFingerActivityCount < 20 && Math.abs(Math.sqrt(pinchSquaredDistance) - Math.sqrt(previousPinchSquaredDistance)) > this.camera.pinchToPanMaxDistance)) {\n // Since pinch has not been active long, assume we intend to zoom.\n this._computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance);\n // Since we are pinching, remain pinching on next iteration.\n this._isPinching = true;\n }\n else {\n // Pause between pinch starting and moving implies not a zoom event. Pan instead.\n this._computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition);\n }\n // Panning enabled, zoom disabled\n }\n else if (this.multiTouchPanning) {\n this._computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition);\n // Zoom enabled, panning disabled\n }\n else if (this.pinchZoom) {\n this._computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance);\n }\n }\n /**\n * Called each time a new POINTERDOWN event occurs. Ie, for each button\n * press.\n * @param evt\n */\n onButtonDown(evt) {\n this._isPanClick = evt.button === this.camera._panningMouseButton;\n }\n /**\n * Called each time a new POINTERUP event occurs. Ie, for each button\n * release.\n */\n onButtonUp() {\n this._twoFingerActivityCount = 0;\n this._isPinching = false;\n }\n /**\n * Called when window becomes inactive.\n */\n onLostFocus() {\n this._isPanClick = false;\n this._twoFingerActivityCount = 0;\n this._isPinching = false;\n }\n }\n /**\n * The minimum radius used for pinch, to avoid radius lock at 0\n */\n ArcRotateCameraPointersInput.MinimumRadiusForPinch = 0.001;\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"buttons\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"angularSensibilityX\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"angularSensibilityY\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"pinchPrecision\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"pinchDeltaPercentage\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"useNaturalPinchZoom\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"pinchZoom\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"panningSensibility\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"multiTouchPanning\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraPointersInput.prototype, \"multiTouchPanAndZoom\", void 0);\n CameraInputTypes[\"ArcRotateCameraPointersInput\"] = ArcRotateCameraPointersInput;\n\n /**\n * Manage the keyboard inputs to control the movement of an arc rotate camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class ArcRotateCameraKeyboardMoveInput {\n constructor() {\n /**\n * Defines the list of key codes associated with the up action (increase alpha)\n */\n this.keysUp = [38];\n /**\n * Defines the list of key codes associated with the down action (decrease alpha)\n */\n this.keysDown = [40];\n /**\n * Defines the list of key codes associated with the left action (increase beta)\n */\n this.keysLeft = [37];\n /**\n * Defines the list of key codes associated with the right action (decrease beta)\n */\n this.keysRight = [39];\n /**\n * Defines the list of key codes associated with the reset action.\n * Those keys reset the camera to its last stored state (with the method camera.storeState())\n */\n this.keysReset = [220];\n /**\n * Defines the panning sensibility of the inputs.\n * (How fast is the camera panning)\n */\n this.panningSensibility = 50.0;\n /**\n * Defines the zooming sensibility of the inputs.\n * (How fast is the camera zooming)\n */\n this.zoomingSensibility = 25.0;\n /**\n * Defines whether maintaining the alt key down switch the movement mode from\n * orientation to zoom.\n */\n this.useAltToZoom = true;\n /**\n * Rotation speed of the camera\n */\n this.angularSpeed = 0.01;\n this._keys = new Array();\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // was there a second variable defined?\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n if (this._onCanvasBlurObserver) {\n return;\n }\n this._scene = this.camera.getScene();\n this._engine = this._scene.getEngine();\n this._onCanvasBlurObserver = this._engine.onCanvasBlurObservable.add(() => {\n this._keys.length = 0;\n });\n this._onKeyboardObserver = this._scene.onKeyboardObservable.add((info) => {\n const evt = info.event;\n if (!evt.metaKey) {\n if (info.type === KeyboardEventTypes.KEYDOWN) {\n this._ctrlPressed = evt.ctrlKey;\n this._altPressed = evt.altKey;\n if (this.keysUp.indexOf(evt.keyCode) !== -1 ||\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\n this.keysReset.indexOf(evt.keyCode) !== -1) {\n const index = this._keys.indexOf(evt.keyCode);\n if (index === -1) {\n this._keys.push(evt.keyCode);\n }\n if (evt.preventDefault) {\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n }\n }\n }\n else {\n if (this.keysUp.indexOf(evt.keyCode) !== -1 ||\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\n this.keysReset.indexOf(evt.keyCode) !== -1) {\n const index = this._keys.indexOf(evt.keyCode);\n if (index >= 0) {\n this._keys.splice(index, 1);\n }\n if (evt.preventDefault) {\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n }\n }\n }\n }\n });\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._scene) {\n if (this._onKeyboardObserver) {\n this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);\n }\n if (this._onCanvasBlurObserver) {\n this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);\n }\n this._onKeyboardObserver = null;\n this._onCanvasBlurObserver = null;\n }\n this._keys.length = 0;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this._onKeyboardObserver) {\n const camera = this.camera;\n for (let index = 0; index < this._keys.length; index++) {\n const keyCode = this._keys[index];\n if (this.keysLeft.indexOf(keyCode) !== -1) {\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\n camera.inertialPanningX -= 1 / this.panningSensibility;\n }\n else {\n camera.inertialAlphaOffset -= this.angularSpeed;\n }\n }\n else if (this.keysUp.indexOf(keyCode) !== -1) {\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\n camera.inertialPanningY += 1 / this.panningSensibility;\n }\n else if (this._altPressed && this.useAltToZoom) {\n camera.inertialRadiusOffset += 1 / this.zoomingSensibility;\n }\n else {\n camera.inertialBetaOffset -= this.angularSpeed;\n }\n }\n else if (this.keysRight.indexOf(keyCode) !== -1) {\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\n camera.inertialPanningX += 1 / this.panningSensibility;\n }\n else {\n camera.inertialAlphaOffset += this.angularSpeed;\n }\n }\n else if (this.keysDown.indexOf(keyCode) !== -1) {\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\n camera.inertialPanningY -= 1 / this.panningSensibility;\n }\n else if (this._altPressed && this.useAltToZoom) {\n camera.inertialRadiusOffset -= 1 / this.zoomingSensibility;\n }\n else {\n camera.inertialBetaOffset += this.angularSpeed;\n }\n }\n else if (this.keysReset.indexOf(keyCode) !== -1) {\n if (camera.useInputToRestoreState) {\n camera.restoreState();\n }\n }\n }\n }\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCameraKeyboardMoveInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"keyboard\";\n }\n }\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"keysUp\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"keysDown\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"keysLeft\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"keysRight\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"keysReset\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"panningSensibility\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"zoomingSensibility\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"useAltToZoom\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraKeyboardMoveInput.prototype, \"angularSpeed\", void 0);\n CameraInputTypes[\"ArcRotateCameraKeyboardMoveInput\"] = ArcRotateCameraKeyboardMoveInput;\n\n /**\n * Firefox uses a different scheme to report scroll distances to other\n * browsers. Rather than use complicated methods to calculate the exact\n * multiple we need to apply, let's just cheat and use a constant.\n * https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode\n * https://stackoverflow.com/questions/20110224/what-is-the-height-of-a-line-in-a-wheel-event-deltamode-dom-delta-line\n */\n const ffMultiplier = 40;\n /**\n * Manage the mouse wheel inputs to control an arc rotate camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class ArcRotateCameraMouseWheelInput {\n constructor() {\n /**\n * Gets or Set the mouse wheel precision or how fast is the camera zooming.\n */\n this.wheelPrecision = 3.0;\n /**\n * Gets or Set the boolean value that controls whether or not the mouse wheel\n * zooms to the location of the mouse pointer or not. The default is false.\n */\n this.zoomToMouseLocation = false;\n /**\n * wheelDeltaPercentage will be used instead of wheelPrecision if different from 0.\n * It defines the percentage of current camera.radius to use as delta when wheel is used.\n */\n this.wheelDeltaPercentage = 0;\n /**\n * If set, this function will be used to set the radius delta that will be added to the current camera radius\n */\n this.customComputeDeltaFromMouseWheel = null;\n this._inertialPanning = Vector3.Zero();\n }\n _computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta, radius) {\n let delta = 0;\n const wheelDelta = mouseWheelDelta * 0.01 * this.wheelDeltaPercentage * radius;\n if (mouseWheelDelta > 0) {\n delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);\n }\n else {\n delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);\n }\n return delta;\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n this._wheel = (p) => {\n //sanity check - this should be a PointerWheel event.\n if (p.type !== PointerEventTypes.POINTERWHEEL) {\n return;\n }\n const event = p.event;\n let delta = 0;\n const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly\n const wheelDelta = -(event.deltaY * platformScale);\n if (this.customComputeDeltaFromMouseWheel) {\n delta = this.customComputeDeltaFromMouseWheel(wheelDelta, this, event);\n }\n else {\n if (this.wheelDeltaPercentage) {\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, this.camera.radius);\n // If zooming in, estimate the target radius and use that to compute the delta for inertia\n // this will stop multiple scroll events zooming in from adding too much inertia\n if (delta > 0) {\n let estimatedTargetRadius = this.camera.radius;\n let targetInertia = this.camera.inertialRadiusOffset + delta;\n for (let i = 0; i < 20 && Math.abs(targetInertia) > 0.001; i++) {\n estimatedTargetRadius -= targetInertia;\n targetInertia *= this.camera.inertia;\n }\n estimatedTargetRadius = Scalar.Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);\n }\n }\n else {\n delta = wheelDelta / (this.wheelPrecision * 40);\n }\n }\n if (delta) {\n if (this.zoomToMouseLocation) {\n // If we are zooming to the mouse location, then we need to get the hit plane at the start of the zoom gesture if it doesn't exist\n // The hit plane is normally calculated after the first motion and each time there's motion so if we don't do this first,\n // the first zoom will be to the center of the screen\n if (!this._hitPlane) {\n this._updateHitPlane();\n }\n this._zoomToMouse(delta);\n }\n else {\n this.camera.inertialRadiusOffset += delta;\n }\n }\n if (event.preventDefault) {\n if (!noPreventDefault) {\n event.preventDefault();\n }\n }\n };\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel, PointerEventTypes.POINTERWHEEL);\n if (this.zoomToMouseLocation) {\n this._inertialPanning.setAll(0);\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._observer) {\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\n this._observer = null;\n this._wheel = null;\n }\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (!this.zoomToMouseLocation) {\n return;\n }\n const camera = this.camera;\n const motion = 0.0 + camera.inertialAlphaOffset + camera.inertialBetaOffset + camera.inertialRadiusOffset;\n if (motion) {\n // if zooming is still happening as a result of inertia, then we also need to update\n // the hit plane.\n this._updateHitPlane();\n // Note we cannot use arcRotateCamera.inertialPlanning here because arcRotateCamera panning\n // uses a different panningInertia which could cause this panning to get out of sync with\n // the zooming, and for this to work they must be exactly in sync.\n camera.target.addInPlace(this._inertialPanning);\n this._inertialPanning.scaleInPlace(camera.inertia);\n this._zeroIfClose(this._inertialPanning);\n }\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCameraMouseWheelInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"mousewheel\";\n }\n _updateHitPlane() {\n const camera = this.camera;\n const direction = camera.target.subtract(camera.position);\n this._hitPlane = Plane.FromPositionAndNormal(camera.target, direction);\n }\n // Get position on the hit plane\n _getPosition() {\n var _a;\n const camera = this.camera;\n const scene = camera.getScene();\n // since the _hitPlane is always updated to be orthogonal to the camera position vector\n // we don't have to worry about this ray shooting off to infinity. This ray creates\n // a vector defining where we want to zoom to.\n const ray = scene.createPickingRay(scene.pointerX, scene.pointerY, Matrix.Identity(), camera, false);\n // Since the camera is the origin of the picking ray, we need to offset it by the camera's offset manually\n ray.origin.x -= camera.targetScreenOffset.x;\n ray.origin.y -= camera.targetScreenOffset.y;\n let distance = 0;\n if (this._hitPlane) {\n distance = (_a = ray.intersectsPlane(this._hitPlane)) !== null && _a !== void 0 ? _a : 0;\n }\n // not using this ray again, so modifying its vectors here is fine\n return ray.origin.addInPlace(ray.direction.scaleInPlace(distance));\n }\n _zoomToMouse(delta) {\n var _a, _b;\n const camera = this.camera;\n const inertiaComp = 1 - camera.inertia;\n if (camera.lowerRadiusLimit) {\n const lowerLimit = (_a = camera.lowerRadiusLimit) !== null && _a !== void 0 ? _a : 0;\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp < lowerLimit) {\n delta = (camera.radius - lowerLimit) * inertiaComp - camera.inertialRadiusOffset;\n }\n }\n if (camera.upperRadiusLimit) {\n const upperLimit = (_b = camera.upperRadiusLimit) !== null && _b !== void 0 ? _b : 0;\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp > upperLimit) {\n delta = (camera.radius - upperLimit) * inertiaComp - camera.inertialRadiusOffset;\n }\n }\n const zoomDistance = delta / inertiaComp;\n const ratio = zoomDistance / camera.radius;\n const vec = this._getPosition();\n // Now this vector tells us how much we also need to pan the camera\n // so the targeted mouse location becomes the center of zooming.\n const directionToZoomLocation = TmpVectors.Vector3[6];\n vec.subtractToRef(camera.target, directionToZoomLocation);\n directionToZoomLocation.scaleInPlace(ratio);\n directionToZoomLocation.scaleInPlace(inertiaComp);\n this._inertialPanning.addInPlace(directionToZoomLocation);\n camera.inertialRadiusOffset += delta;\n }\n // Sets x y or z of passed in vector to zero if less than Epsilon.\n _zeroIfClose(vec) {\n if (Math.abs(vec.x) < Epsilon) {\n vec.x = 0;\n }\n if (Math.abs(vec.y) < Epsilon) {\n vec.y = 0;\n }\n if (Math.abs(vec.z) < Epsilon) {\n vec.z = 0;\n }\n }\n }\n __decorate$1([\n serialize()\n ], ArcRotateCameraMouseWheelInput.prototype, \"wheelPrecision\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraMouseWheelInput.prototype, \"zoomToMouseLocation\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraMouseWheelInput.prototype, \"wheelDeltaPercentage\", void 0);\n CameraInputTypes[\"ArcRotateCameraMouseWheelInput\"] = ArcRotateCameraMouseWheelInput;\n\n /**\n * Default Inputs manager for the ArcRotateCamera.\n * It groups all the default supported inputs for ease of use.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class ArcRotateCameraInputsManager extends CameraInputsManager {\n /**\n * Instantiates a new ArcRotateCameraInputsManager.\n * @param camera Defines the camera the inputs belong to\n */\n constructor(camera) {\n super(camera);\n }\n /**\n * Add mouse wheel input support to the input manager.\n * @returns the current input manager\n */\n addMouseWheel() {\n this.add(new ArcRotateCameraMouseWheelInput());\n return this;\n }\n /**\n * Add pointers input support to the input manager.\n * @returns the current input manager\n */\n addPointers() {\n this.add(new ArcRotateCameraPointersInput());\n return this;\n }\n /**\n * Add keyboard input support to the input manager.\n * @returns the current input manager\n */\n addKeyboard() {\n this.add(new ArcRotateCameraKeyboardMoveInput());\n return this;\n }\n }\n\n Node.AddNodeConstructor(\"ArcRotateCamera\", (name, scene) => {\n return () => new ArcRotateCamera(name, 0, 0, 1.0, Vector3.Zero(), scene);\n });\n /**\n * This represents an orbital type of camera.\n *\n * This camera always points towards a given target position and can be rotated around that target with the target as the centre of rotation. It can be controlled with cursors and mouse, or with touch events.\n * Think of this camera as one orbiting its target position, or more imaginatively as a spy satellite orbiting the earth. Its position relative to the target (earth) can be set by three parameters, alpha (radians) the longitudinal rotation, beta (radians) the latitudinal rotation and radius the distance from the target position.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#arc-rotate-camera\n */\n class ArcRotateCamera extends TargetCamera {\n /**\n * Defines the target point of the camera.\n * The camera looks towards it from the radius distance.\n */\n get target() {\n return this._target;\n }\n set target(value) {\n this.setTarget(value);\n }\n /**\n * Defines the target mesh of the camera.\n * The camera looks towards it from the radius distance.\n * Please note that setting a target host will disable panning.\n */\n get targetHost() {\n return this._targetHost;\n }\n set targetHost(value) {\n if (value) {\n this.setTarget(value);\n }\n }\n /**\n * Return the current target position of the camera. This value is expressed in local space.\n * @returns the target position\n */\n getTarget() {\n return this.target;\n }\n /**\n * Define the current local position of the camera in the scene\n */\n get position() {\n return this._position;\n }\n set position(newPosition) {\n this.setPosition(newPosition);\n }\n /**\n * The vector the camera should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up())\n * Setting this will copy the given vector to the camera's upVector, and set rotation matrices to and from Y up.\n * DO NOT set the up vector using copyFrom or copyFromFloats, as this bypasses setting the above matrices.\n */\n set upVector(vec) {\n if (!this._upToYMatrix) {\n this._yToUpMatrix = new Matrix();\n this._upToYMatrix = new Matrix();\n this._upVector = Vector3.Zero();\n }\n vec.normalize();\n this._upVector.copyFrom(vec);\n this.setMatUp();\n }\n get upVector() {\n return this._upVector;\n }\n /**\n * Sets the Y-up to camera up-vector rotation matrix, and the up-vector to Y-up rotation matrix.\n */\n setMatUp() {\n // from y-up to custom-up (used in _getViewMatrix)\n Matrix.RotationAlignToRef(Vector3.UpReadOnly, this._upVector, this._yToUpMatrix);\n // from custom-up to y-up (used in rebuildAnglesAndRadius)\n Matrix.RotationAlignToRef(this._upVector, Vector3.UpReadOnly, this._upToYMatrix);\n }\n //-- begin properties for backward compatibility for inputs\n /**\n * Gets or Set the pointer angular sensibility along the X axis or how fast is the camera rotating.\n */\n get angularSensibilityX() {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n return pointers.angularSensibilityX;\n }\n return 0;\n }\n set angularSensibilityX(value) {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n pointers.angularSensibilityX = value;\n }\n }\n /**\n * Gets or Set the pointer angular sensibility along the Y axis or how fast is the camera rotating.\n */\n get angularSensibilityY() {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n return pointers.angularSensibilityY;\n }\n return 0;\n }\n set angularSensibilityY(value) {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n pointers.angularSensibilityY = value;\n }\n }\n /**\n * Gets or Set the pointer pinch precision or how fast is the camera zooming.\n */\n get pinchPrecision() {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n return pointers.pinchPrecision;\n }\n return 0;\n }\n set pinchPrecision(value) {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n pointers.pinchPrecision = value;\n }\n }\n /**\n * Gets or Set the pointer pinch delta percentage or how fast is the camera zooming.\n * It will be used instead of pinchDeltaPrecision if different from 0.\n * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.\n */\n get pinchDeltaPercentage() {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n return pointers.pinchDeltaPercentage;\n }\n return 0;\n }\n set pinchDeltaPercentage(value) {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n pointers.pinchDeltaPercentage = value;\n }\n }\n /**\n * Gets or Set the pointer use natural pinch zoom to override the pinch precision\n * and pinch delta percentage.\n * When useNaturalPinchZoom is true, multi touch zoom will zoom in such\n * that any object in the plane at the camera's target point will scale\n * perfectly with finger motion.\n */\n get useNaturalPinchZoom() {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n return pointers.useNaturalPinchZoom;\n }\n return false;\n }\n set useNaturalPinchZoom(value) {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n pointers.useNaturalPinchZoom = value;\n }\n }\n /**\n * Gets or Set the pointer panning sensibility or how fast is the camera moving.\n */\n get panningSensibility() {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n return pointers.panningSensibility;\n }\n return 0;\n }\n set panningSensibility(value) {\n const pointers = this.inputs.attached[\"pointers\"];\n if (pointers) {\n pointers.panningSensibility = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control beta angle in a positive direction.\n */\n get keysUp() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysUp;\n }\n return [];\n }\n set keysUp(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysUp = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control beta angle in a negative direction.\n */\n get keysDown() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysDown;\n }\n return [];\n }\n set keysDown(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysDown = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control alpha angle in a negative direction.\n */\n get keysLeft() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysLeft;\n }\n return [];\n }\n set keysLeft(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysLeft = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control alpha angle in a positive direction.\n */\n get keysRight() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysRight;\n }\n return [];\n }\n set keysRight(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysRight = value;\n }\n }\n /**\n * Gets or Set the mouse wheel precision or how fast is the camera zooming.\n */\n get wheelPrecision() {\n const mousewheel = this.inputs.attached[\"mousewheel\"];\n if (mousewheel) {\n return mousewheel.wheelPrecision;\n }\n return 0;\n }\n set wheelPrecision(value) {\n const mousewheel = this.inputs.attached[\"mousewheel\"];\n if (mousewheel) {\n mousewheel.wheelPrecision = value;\n }\n }\n /**\n * Gets or Set the boolean value that controls whether or not the mouse wheel\n * zooms to the location of the mouse pointer or not. The default is false.\n */\n get zoomToMouseLocation() {\n const mousewheel = this.inputs.attached[\"mousewheel\"];\n if (mousewheel) {\n return mousewheel.zoomToMouseLocation;\n }\n return false;\n }\n set zoomToMouseLocation(value) {\n const mousewheel = this.inputs.attached[\"mousewheel\"];\n if (mousewheel) {\n mousewheel.zoomToMouseLocation = value;\n }\n }\n /**\n * Gets or Set the mouse wheel delta percentage or how fast is the camera zooming.\n * It will be used instead of pinchDeltaPrecision if different from 0.\n * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.\n */\n get wheelDeltaPercentage() {\n const mousewheel = this.inputs.attached[\"mousewheel\"];\n if (mousewheel) {\n return mousewheel.wheelDeltaPercentage;\n }\n return 0;\n }\n set wheelDeltaPercentage(value) {\n const mousewheel = this.inputs.attached[\"mousewheel\"];\n if (mousewheel) {\n mousewheel.wheelDeltaPercentage = value;\n }\n }\n /**\n * Gets the bouncing behavior of the camera if it has been enabled.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior\n */\n get bouncingBehavior() {\n return this._bouncingBehavior;\n }\n /**\n * Defines if the bouncing behavior of the camera is enabled on the camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior\n */\n get useBouncingBehavior() {\n return this._bouncingBehavior != null;\n }\n set useBouncingBehavior(value) {\n if (value === this.useBouncingBehavior) {\n return;\n }\n if (value) {\n this._bouncingBehavior = new BouncingBehavior();\n this.addBehavior(this._bouncingBehavior);\n }\n else if (this._bouncingBehavior) {\n this.removeBehavior(this._bouncingBehavior);\n this._bouncingBehavior = null;\n }\n }\n /**\n * Gets the framing behavior of the camera if it has been enabled.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior\n */\n get framingBehavior() {\n return this._framingBehavior;\n }\n /**\n * Defines if the framing behavior of the camera is enabled on the camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior\n */\n get useFramingBehavior() {\n return this._framingBehavior != null;\n }\n set useFramingBehavior(value) {\n if (value === this.useFramingBehavior) {\n return;\n }\n if (value) {\n this._framingBehavior = new FramingBehavior();\n this.addBehavior(this._framingBehavior);\n }\n else if (this._framingBehavior) {\n this.removeBehavior(this._framingBehavior);\n this._framingBehavior = null;\n }\n }\n /**\n * Gets the auto rotation behavior of the camera if it has been enabled.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior\n */\n get autoRotationBehavior() {\n return this._autoRotationBehavior;\n }\n /**\n * Defines if the auto rotation behavior of the camera is enabled on the camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior\n */\n get useAutoRotationBehavior() {\n return this._autoRotationBehavior != null;\n }\n set useAutoRotationBehavior(value) {\n if (value === this.useAutoRotationBehavior) {\n return;\n }\n if (value) {\n this._autoRotationBehavior = new AutoRotationBehavior();\n this.addBehavior(this._autoRotationBehavior);\n }\n else if (this._autoRotationBehavior) {\n this.removeBehavior(this._autoRotationBehavior);\n this._autoRotationBehavior = null;\n }\n }\n /**\n * Instantiates a new ArcRotateCamera in a given scene\n * @param name Defines the name of the camera\n * @param alpha Defines the camera rotation along the longitudinal axis\n * @param beta Defines the camera rotation along the latitudinal axis\n * @param radius Defines the camera distance from its target\n * @param target Defines the camera target\n * @param scene Defines the scene the camera belongs to\n * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined\n */\n constructor(name, alpha, beta, radius, target, scene, setActiveOnSceneIfNoneActive = true) {\n super(name, Vector3.Zero(), scene, setActiveOnSceneIfNoneActive);\n /**\n * Current inertia value on the longitudinal axis.\n * The bigger this number the longer it will take for the camera to stop.\n */\n this.inertialAlphaOffset = 0;\n /**\n * Current inertia value on the latitudinal axis.\n * The bigger this number the longer it will take for the camera to stop.\n */\n this.inertialBetaOffset = 0;\n /**\n * Current inertia value on the radius axis.\n * The bigger this number the longer it will take for the camera to stop.\n */\n this.inertialRadiusOffset = 0;\n /**\n * Minimum allowed angle on the longitudinal axis.\n * This can help limiting how the Camera is able to move in the scene.\n */\n this.lowerAlphaLimit = null;\n /**\n * Maximum allowed angle on the longitudinal axis.\n * This can help limiting how the Camera is able to move in the scene.\n */\n this.upperAlphaLimit = null;\n /**\n * Minimum allowed angle on the latitudinal axis.\n * This can help limiting how the Camera is able to move in the scene.\n */\n this.lowerBetaLimit = 0.01;\n /**\n * Maximum allowed angle on the latitudinal axis.\n * This can help limiting how the Camera is able to move in the scene.\n */\n this.upperBetaLimit = Math.PI - 0.01;\n /**\n * Minimum allowed distance of the camera to the target (The camera can not get closer).\n * This can help limiting how the Camera is able to move in the scene.\n */\n this.lowerRadiusLimit = null;\n /**\n * Maximum allowed distance of the camera to the target (The camera can not get further).\n * This can help limiting how the Camera is able to move in the scene.\n */\n this.upperRadiusLimit = null;\n /**\n * Defines the current inertia value used during panning of the camera along the X axis.\n */\n this.inertialPanningX = 0;\n /**\n * Defines the current inertia value used during panning of the camera along the Y axis.\n */\n this.inertialPanningY = 0;\n /**\n * Defines the distance used to consider the camera in pan mode vs pinch/zoom.\n * Basically if your fingers moves away from more than this distance you will be considered\n * in pinch mode.\n */\n this.pinchToPanMaxDistance = 20;\n /**\n * Defines the maximum distance the camera can pan.\n * This could help keeping the camera always in your scene.\n */\n this.panningDistanceLimit = null;\n /**\n * Defines the target of the camera before panning.\n */\n this.panningOriginTarget = Vector3.Zero();\n /**\n * Defines the value of the inertia used during panning.\n * 0 would mean stop inertia and one would mean no deceleration at all.\n */\n this.panningInertia = 0.9;\n //-- end properties for backward compatibility for inputs\n /**\n * Defines how much the radius should be scaled while zooming on a particular mesh (through the zoomOn function)\n */\n this.zoomOnFactor = 1;\n /**\n * Defines a screen offset for the camera position.\n */\n this.targetScreenOffset = Vector2.Zero();\n /**\n * Allows the camera to be completely reversed.\n * If false the camera can not arrive upside down.\n */\n this.allowUpsideDown = true;\n /**\n * Define if double tap/click is used to restore the previously saved state of the camera.\n */\n this.useInputToRestoreState = true;\n /** @internal */\n this._viewMatrix = new Matrix();\n /**\n * Defines the allowed panning axis.\n */\n this.panningAxis = new Vector3(1, 1, 0);\n this._transformedDirection = new Vector3();\n /**\n * Defines if camera will eliminate transform on y axis.\n */\n this.mapPanning = false;\n /**\n * Observable triggered when the mesh target has been changed on the camera.\n */\n this.onMeshTargetChangedObservable = new Observable$1();\n /**\n * Defines whether the camera should check collision with the objects oh the scene.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#how-can-i-do-this-\n */\n this.checkCollisions = false;\n /**\n * Defines the collision radius of the camera.\n * This simulates a sphere around the camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#arcrotatecamera\n */\n this.collisionRadius = new Vector3(0.5, 0.5, 0.5);\n this._previousPosition = Vector3.Zero();\n this._collisionVelocity = Vector3.Zero();\n this._newPosition = Vector3.Zero();\n this._computationVector = Vector3.Zero();\n this._onCollisionPositionChange = (collisionId, newPosition, collidedMesh = null) => {\n if (!collidedMesh) {\n this._previousPosition.copyFrom(this._position);\n }\n else {\n this.setPosition(newPosition);\n if (this.onCollide) {\n this.onCollide(collidedMesh);\n }\n }\n // Recompute because of constraints\n const cosa = Math.cos(this.alpha);\n const sina = Math.sin(this.alpha);\n const cosb = Math.cos(this.beta);\n let sinb = Math.sin(this.beta);\n if (sinb === 0) {\n sinb = 0.0001;\n }\n const target = this._getTargetPosition();\n this._computationVector.copyFromFloats(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb);\n target.addToRef(this._computationVector, this._newPosition);\n this._position.copyFrom(this._newPosition);\n let up = this.upVector;\n if (this.allowUpsideDown && this.beta < 0) {\n up = up.clone();\n up = up.negate();\n }\n this._computeViewMatrix(this._position, target, up);\n this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);\n this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);\n this._collisionTriggered = false;\n };\n this._target = Vector3.Zero();\n if (target) {\n this.setTarget(target);\n }\n this.alpha = alpha;\n this.beta = beta;\n this.radius = radius;\n this.getViewMatrix();\n this.inputs = new ArcRotateCameraInputsManager(this);\n this.inputs.addKeyboard().addMouseWheel().addPointers();\n }\n // Cache\n /** @internal */\n _initCache() {\n super._initCache();\n this._cache._target = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cache.alpha = undefined;\n this._cache.beta = undefined;\n this._cache.radius = undefined;\n this._cache.targetScreenOffset = Vector2.Zero();\n }\n /**\n * @internal\n */\n _updateCache(ignoreParentClass) {\n if (!ignoreParentClass) {\n super._updateCache();\n }\n this._cache._target.copyFrom(this._getTargetPosition());\n this._cache.alpha = this.alpha;\n this._cache.beta = this.beta;\n this._cache.radius = this.radius;\n this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset);\n }\n _getTargetPosition() {\n if (this._targetHost && this._targetHost.getAbsolutePosition) {\n const pos = this._targetHost.getAbsolutePosition();\n if (this._targetBoundingCenter) {\n pos.addToRef(this._targetBoundingCenter, this._target);\n }\n else {\n this._target.copyFrom(pos);\n }\n }\n const lockedTargetPosition = this._getLockedTargetPosition();\n if (lockedTargetPosition) {\n return lockedTargetPosition;\n }\n return this._target;\n }\n /**\n * Stores the current state of the camera (alpha, beta, radius and target)\n * @returns the camera itself\n */\n storeState() {\n this._storedAlpha = this.alpha;\n this._storedBeta = this.beta;\n this._storedRadius = this.radius;\n this._storedTarget = this._getTargetPosition().clone();\n this._storedTargetScreenOffset = this.targetScreenOffset.clone();\n return super.storeState();\n }\n /**\n * @internal\n * Restored camera state. You must call storeState() first\n */\n _restoreStateValues() {\n if (!super._restoreStateValues()) {\n return false;\n }\n this.setTarget(this._storedTarget.clone());\n this.alpha = this._storedAlpha;\n this.beta = this._storedBeta;\n this.radius = this._storedRadius;\n this.targetScreenOffset = this._storedTargetScreenOffset.clone();\n this.inertialAlphaOffset = 0;\n this.inertialBetaOffset = 0;\n this.inertialRadiusOffset = 0;\n this.inertialPanningX = 0;\n this.inertialPanningY = 0;\n return true;\n }\n // Synchronized\n /** @internal */\n _isSynchronizedViewMatrix() {\n if (!super._isSynchronizedViewMatrix()) {\n return false;\n }\n return (this._cache._target.equals(this._getTargetPosition()) &&\n this._cache.alpha === this.alpha &&\n this._cache.beta === this.beta &&\n this._cache.radius === this.radius &&\n this._cache.targetScreenOffset.equals(this.targetScreenOffset));\n }\n /**\n * Attached controls to the current camera.\n * @param ignored defines an ignored parameter kept for backward compatibility.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls\n * @param panningMouseButton Defines whether panning is allowed through mouse click button\n */\n attachControl(ignored, noPreventDefault, useCtrlForPanning = true, panningMouseButton = 2) {\n // eslint-disable-next-line prefer-rest-params\n const args = arguments;\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(args);\n this._useCtrlForPanning = useCtrlForPanning;\n this._panningMouseButton = panningMouseButton;\n // backwards compatibility\n if (typeof args[0] === \"boolean\") {\n if (args.length > 1) {\n this._useCtrlForPanning = args[1];\n }\n if (args.length > 2) {\n this._panningMouseButton = args[2];\n }\n }\n this.inputs.attachElement(noPreventDefault);\n this._reset = () => {\n this.inertialAlphaOffset = 0;\n this.inertialBetaOffset = 0;\n this.inertialRadiusOffset = 0;\n this.inertialPanningX = 0;\n this.inertialPanningY = 0;\n };\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n this.inputs.detachElement();\n if (this._reset) {\n this._reset();\n }\n }\n /** @internal */\n _checkInputs() {\n //if (async) collision inspection was triggered, don't update the camera's position - until the collision callback was called.\n if (this._collisionTriggered) {\n return;\n }\n this.inputs.checkInputs();\n // Inertia\n if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {\n const directionModifier = this.invertRotation ? -1 : 1;\n let inertialAlphaOffset = this.inertialAlphaOffset;\n if (this.beta <= 0) {\n inertialAlphaOffset *= -1;\n }\n if (this.getScene().useRightHandedSystem) {\n inertialAlphaOffset *= -1;\n }\n if (this.parent && this.parent._getWorldMatrixDeterminant() < 0) {\n inertialAlphaOffset *= -1;\n }\n this.alpha += inertialAlphaOffset * directionModifier;\n this.beta += this.inertialBetaOffset * directionModifier;\n this.radius -= this.inertialRadiusOffset;\n this.inertialAlphaOffset *= this.inertia;\n this.inertialBetaOffset *= this.inertia;\n this.inertialRadiusOffset *= this.inertia;\n if (Math.abs(this.inertialAlphaOffset) < Epsilon) {\n this.inertialAlphaOffset = 0;\n }\n if (Math.abs(this.inertialBetaOffset) < Epsilon) {\n this.inertialBetaOffset = 0;\n }\n if (Math.abs(this.inertialRadiusOffset) < this.speed * Epsilon) {\n this.inertialRadiusOffset = 0;\n }\n }\n // Panning inertia\n if (this.inertialPanningX !== 0 || this.inertialPanningY !== 0) {\n const localDirection = new Vector3(this.inertialPanningX, this.inertialPanningY, this.inertialPanningY);\n this._viewMatrix.invertToRef(this._cameraTransformMatrix);\n localDirection.multiplyInPlace(this.panningAxis);\n Vector3.TransformNormalToRef(localDirection, this._cameraTransformMatrix, this._transformedDirection);\n // Eliminate y if mapPanning is enabled\n if (this.mapPanning || !this.panningAxis.y) {\n this._transformedDirection.y = 0;\n }\n if (!this._targetHost) {\n if (this.panningDistanceLimit) {\n this._transformedDirection.addInPlace(this._target);\n const distanceSquared = Vector3.DistanceSquared(this._transformedDirection, this.panningOriginTarget);\n if (distanceSquared <= this.panningDistanceLimit * this.panningDistanceLimit) {\n this._target.copyFrom(this._transformedDirection);\n }\n }\n else {\n this._target.addInPlace(this._transformedDirection);\n }\n }\n this.inertialPanningX *= this.panningInertia;\n this.inertialPanningY *= this.panningInertia;\n if (Math.abs(this.inertialPanningX) < this.speed * Epsilon) {\n this.inertialPanningX = 0;\n }\n if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) {\n this.inertialPanningY = 0;\n }\n }\n // Limits\n this._checkLimits();\n super._checkInputs();\n }\n _checkLimits() {\n if (this.lowerBetaLimit === null || this.lowerBetaLimit === undefined) {\n if (this.allowUpsideDown && this.beta > Math.PI) {\n this.beta = this.beta - 2 * Math.PI;\n }\n }\n else {\n if (this.beta < this.lowerBetaLimit) {\n this.beta = this.lowerBetaLimit;\n }\n }\n if (this.upperBetaLimit === null || this.upperBetaLimit === undefined) {\n if (this.allowUpsideDown && this.beta < -Math.PI) {\n this.beta = this.beta + 2 * Math.PI;\n }\n }\n else {\n if (this.beta > this.upperBetaLimit) {\n this.beta = this.upperBetaLimit;\n }\n }\n if (this.lowerAlphaLimit !== null && this.alpha < this.lowerAlphaLimit) {\n this.alpha = this.lowerAlphaLimit;\n }\n if (this.upperAlphaLimit !== null && this.alpha > this.upperAlphaLimit) {\n this.alpha = this.upperAlphaLimit;\n }\n if (this.lowerRadiusLimit !== null && this.radius < this.lowerRadiusLimit) {\n this.radius = this.lowerRadiusLimit;\n this.inertialRadiusOffset = 0;\n }\n if (this.upperRadiusLimit !== null && this.radius > this.upperRadiusLimit) {\n this.radius = this.upperRadiusLimit;\n this.inertialRadiusOffset = 0;\n }\n }\n /**\n * Rebuilds angles (alpha, beta) and radius from the give position and target\n */\n rebuildAnglesAndRadius() {\n this._position.subtractToRef(this._getTargetPosition(), this._computationVector);\n // need to rotate to Y up equivalent if up vector not Axis.Y\n if (this._upVector.x !== 0 || this._upVector.y !== 1.0 || this._upVector.z !== 0) {\n Vector3.TransformCoordinatesToRef(this._computationVector, this._upToYMatrix, this._computationVector);\n }\n this.radius = this._computationVector.length();\n if (this.radius === 0) {\n this.radius = 0.0001; // Just to avoid division by zero\n }\n // Alpha\n const previousAlpha = this.alpha;\n if (this._computationVector.x === 0 && this._computationVector.z === 0) {\n this.alpha = Math.PI / 2; // avoid division by zero when looking along up axis, and set to acos(0)\n }\n else {\n this.alpha = Math.acos(this._computationVector.x / Math.sqrt(Math.pow(this._computationVector.x, 2) + Math.pow(this._computationVector.z, 2)));\n }\n if (this._computationVector.z < 0) {\n this.alpha = 2 * Math.PI - this.alpha;\n }\n // Calculate the number of revolutions between the new and old alpha values.\n const alphaCorrectionTurns = Math.round((previousAlpha - this.alpha) / (2.0 * Math.PI));\n // Adjust alpha so that its numerical representation is the closest one to the old value.\n this.alpha += alphaCorrectionTurns * 2.0 * Math.PI;\n // Beta\n this.beta = Math.acos(this._computationVector.y / this.radius);\n this._checkLimits();\n }\n /**\n * Use a position to define the current camera related information like alpha, beta and radius\n * @param position Defines the position to set the camera at\n */\n setPosition(position) {\n if (this._position.equals(position)) {\n return;\n }\n this._position.copyFrom(position);\n this.rebuildAnglesAndRadius();\n }\n /**\n * Defines the target the camera should look at.\n * This will automatically adapt alpha beta and radius to fit within the new target.\n * Please note that setting a target as a mesh will disable panning.\n * @param target Defines the new target as a Vector or a mesh\n * @param toBoundingCenter In case of a mesh target, defines whether to target the mesh position or its bounding information center\n * @param allowSamePosition If false, prevents reapplying the new computed position if it is identical to the current one (optim)\n * @param cloneAlphaBetaRadius If true, replicate the current setup (alpha, beta, radius) on the new target\n */\n setTarget(target, toBoundingCenter = false, allowSamePosition = false, cloneAlphaBetaRadius = false) {\n var _a;\n cloneAlphaBetaRadius = (_a = this.overrideCloneAlphaBetaRadius) !== null && _a !== void 0 ? _a : cloneAlphaBetaRadius;\n if (target.getBoundingInfo) {\n if (toBoundingCenter) {\n this._targetBoundingCenter = target.getBoundingInfo().boundingBox.centerWorld.clone();\n }\n else {\n this._targetBoundingCenter = null;\n }\n target.computeWorldMatrix();\n this._targetHost = target;\n this._target = this._getTargetPosition();\n this.onMeshTargetChangedObservable.notifyObservers(this._targetHost);\n }\n else {\n const newTarget = target;\n const currentTarget = this._getTargetPosition();\n if (currentTarget && !allowSamePosition && currentTarget.equals(newTarget)) {\n return;\n }\n this._targetHost = null;\n this._target = newTarget;\n this._targetBoundingCenter = null;\n this.onMeshTargetChangedObservable.notifyObservers(null);\n }\n if (!cloneAlphaBetaRadius) {\n this.rebuildAnglesAndRadius();\n }\n }\n /** @internal */\n _getViewMatrix() {\n // Compute\n const cosa = Math.cos(this.alpha);\n const sina = Math.sin(this.alpha);\n const cosb = Math.cos(this.beta);\n let sinb = Math.sin(this.beta);\n if (sinb === 0) {\n sinb = 0.0001;\n }\n if (this.radius === 0) {\n this.radius = 0.0001; // Just to avoid division by zero\n }\n const target = this._getTargetPosition();\n this._computationVector.copyFromFloats(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb);\n // Rotate according to up vector\n if (this._upVector.x !== 0 || this._upVector.y !== 1.0 || this._upVector.z !== 0) {\n Vector3.TransformCoordinatesToRef(this._computationVector, this._yToUpMatrix, this._computationVector);\n }\n target.addToRef(this._computationVector, this._newPosition);\n if (this.getScene().collisionsEnabled && this.checkCollisions) {\n const coordinator = this.getScene().collisionCoordinator;\n if (!this._collider) {\n this._collider = coordinator.createCollider();\n }\n this._collider._radius = this.collisionRadius;\n this._newPosition.subtractToRef(this._position, this._collisionVelocity);\n this._collisionTriggered = true;\n coordinator.getNewPosition(this._position, this._collisionVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);\n }\n else {\n this._position.copyFrom(this._newPosition);\n let up = this.upVector;\n if (this.allowUpsideDown && sinb < 0) {\n up = up.negate();\n }\n this._computeViewMatrix(this._position, target, up);\n this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);\n this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);\n }\n this._currentTarget = target;\n return this._viewMatrix;\n }\n /**\n * Zooms on a mesh to be at the min distance where we could see it fully in the current viewport.\n * @param meshes Defines the mesh to zoom on\n * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)\n */\n zoomOn(meshes, doNotUpdateMaxZ = false) {\n meshes = meshes || this.getScene().meshes;\n const minMaxVector = Mesh.MinMax(meshes);\n const distance = Vector3.Distance(minMaxVector.min, minMaxVector.max);\n this.radius = distance * this.zoomOnFactor;\n this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);\n }\n /**\n * Focus on a mesh or a bounding box. This adapts the target and maxRadius if necessary but does not update the current radius.\n * The target will be changed but the radius\n * @param meshesOrMinMaxVectorAndDistance Defines the mesh or bounding info to focus on\n * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)\n */\n focusOn(meshesOrMinMaxVectorAndDistance, doNotUpdateMaxZ = false) {\n let meshesOrMinMaxVector;\n let distance;\n if (meshesOrMinMaxVectorAndDistance.min === undefined) {\n // meshes\n const meshes = meshesOrMinMaxVectorAndDistance || this.getScene().meshes;\n meshesOrMinMaxVector = Mesh.MinMax(meshes);\n distance = Vector3.Distance(meshesOrMinMaxVector.min, meshesOrMinMaxVector.max);\n }\n else {\n //minMaxVector and distance\n const minMaxVectorAndDistance = meshesOrMinMaxVectorAndDistance;\n meshesOrMinMaxVector = minMaxVectorAndDistance;\n distance = minMaxVectorAndDistance.distance;\n }\n this._target = Mesh.Center(meshesOrMinMaxVector);\n if (!doNotUpdateMaxZ) {\n this.maxZ = distance * 2;\n }\n }\n /**\n * @override\n * Override Camera.createRigCamera\n */\n createRigCamera(name, cameraIndex) {\n let alphaShift = 0;\n switch (this.cameraRigMode) {\n case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:\n case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:\n case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED:\n case Camera.RIG_MODE_VR:\n alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? 1 : -1);\n break;\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:\n alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? -1 : 1);\n break;\n }\n const rigCam = new ArcRotateCamera(name, this.alpha + alphaShift, this.beta, this.radius, this._target, this.getScene());\n rigCam._cameraRigParams = {};\n rigCam.isRigCamera = true;\n rigCam.rigParent = this;\n rigCam.upVector = this.upVector;\n rigCam.mode = this.mode;\n rigCam.orthoLeft = this.orthoLeft;\n rigCam.orthoRight = this.orthoRight;\n rigCam.orthoBottom = this.orthoBottom;\n rigCam.orthoTop = this.orthoTop;\n return rigCam;\n }\n /**\n * @internal\n * @override\n * Override Camera._updateRigCameras\n */\n _updateRigCameras() {\n const camLeft = this._rigCameras[0];\n const camRight = this._rigCameras[1];\n camLeft.beta = camRight.beta = this.beta;\n switch (this.cameraRigMode) {\n case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:\n case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:\n case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED:\n case Camera.RIG_MODE_VR:\n camLeft.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;\n camRight.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;\n break;\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:\n camLeft.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;\n camRight.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;\n break;\n }\n super._updateRigCameras();\n }\n /**\n * Destroy the camera and release the current resources hold by it.\n */\n dispose() {\n this.inputs.clear();\n super.dispose();\n }\n /**\n * Gets the current object class name.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCamera\";\n }\n }\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"alpha\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"beta\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"radius\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"overrideCloneAlphaBetaRadius\", void 0);\n __decorate$1([\n serializeAsVector3(\"target\")\n ], ArcRotateCamera.prototype, \"_target\", void 0);\n __decorate$1([\n serializeAsMeshReference(\"targetHost\")\n ], ArcRotateCamera.prototype, \"_targetHost\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"inertialAlphaOffset\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"inertialBetaOffset\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"inertialRadiusOffset\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"lowerAlphaLimit\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"upperAlphaLimit\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"lowerBetaLimit\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"upperBetaLimit\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"lowerRadiusLimit\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"upperRadiusLimit\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"inertialPanningX\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"inertialPanningY\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"pinchToPanMaxDistance\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"panningDistanceLimit\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], ArcRotateCamera.prototype, \"panningOriginTarget\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"panningInertia\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"zoomToMouseLocation\", null);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"zoomOnFactor\", void 0);\n __decorate$1([\n serializeAsVector2()\n ], ArcRotateCamera.prototype, \"targetScreenOffset\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"allowUpsideDown\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCamera.prototype, \"useInputToRestoreState\", void 0);\n\n /**\n * Class representing a ray with position and direction\n */\n class Ray {\n /**\n * Creates a new ray\n * @param origin origin point\n * @param direction direction\n * @param length length of the ray\n */\n constructor(\n /** origin point */\n origin, \n /** direction */\n direction, \n /** length of the ray */\n length = Number.MAX_VALUE) {\n this.origin = origin;\n this.direction = direction;\n this.length = length;\n }\n // Methods\n /**\n * Clone the current ray\n * @returns a new ray\n */\n clone() {\n return new Ray(this.origin.clone(), this.direction.clone(), this.length);\n }\n /**\n * Checks if the ray intersects a box\n * This does not account for the ray length by design to improve perfs.\n * @param minimum bound of the box\n * @param maximum bound of the box\n * @param intersectionTreshold extra extend to be added to the box in all direction\n * @returns if the box was hit\n */\n intersectsBoxMinMax(minimum, maximum, intersectionTreshold = 0) {\n const newMinimum = Ray._TmpVector3[0].copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);\n const newMaximum = Ray._TmpVector3[1].copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);\n let d = 0.0;\n let maxValue = Number.MAX_VALUE;\n let inv;\n let min;\n let max;\n let temp;\n if (Math.abs(this.direction.x) < 0.0000001) {\n if (this.origin.x < newMinimum.x || this.origin.x > newMaximum.x) {\n return false;\n }\n }\n else {\n inv = 1.0 / this.direction.x;\n min = (newMinimum.x - this.origin.x) * inv;\n max = (newMaximum.x - this.origin.x) * inv;\n if (max === -Infinity) {\n max = Infinity;\n }\n if (min > max) {\n temp = min;\n min = max;\n max = temp;\n }\n d = Math.max(min, d);\n maxValue = Math.min(max, maxValue);\n if (d > maxValue) {\n return false;\n }\n }\n if (Math.abs(this.direction.y) < 0.0000001) {\n if (this.origin.y < newMinimum.y || this.origin.y > newMaximum.y) {\n return false;\n }\n }\n else {\n inv = 1.0 / this.direction.y;\n min = (newMinimum.y - this.origin.y) * inv;\n max = (newMaximum.y - this.origin.y) * inv;\n if (max === -Infinity) {\n max = Infinity;\n }\n if (min > max) {\n temp = min;\n min = max;\n max = temp;\n }\n d = Math.max(min, d);\n maxValue = Math.min(max, maxValue);\n if (d > maxValue) {\n return false;\n }\n }\n if (Math.abs(this.direction.z) < 0.0000001) {\n if (this.origin.z < newMinimum.z || this.origin.z > newMaximum.z) {\n return false;\n }\n }\n else {\n inv = 1.0 / this.direction.z;\n min = (newMinimum.z - this.origin.z) * inv;\n max = (newMaximum.z - this.origin.z) * inv;\n if (max === -Infinity) {\n max = Infinity;\n }\n if (min > max) {\n temp = min;\n min = max;\n max = temp;\n }\n d = Math.max(min, d);\n maxValue = Math.min(max, maxValue);\n if (d > maxValue) {\n return false;\n }\n }\n return true;\n }\n /**\n * Checks if the ray intersects a box\n * This does not account for the ray lenght by design to improve perfs.\n * @param box the bounding box to check\n * @param intersectionTreshold extra extend to be added to the BoundingBox in all direction\n * @returns if the box was hit\n */\n intersectsBox(box, intersectionTreshold = 0) {\n return this.intersectsBoxMinMax(box.minimum, box.maximum, intersectionTreshold);\n }\n /**\n * If the ray hits a sphere\n * @param sphere the bounding sphere to check\n * @param intersectionTreshold extra extend to be added to the BoundingSphere in all direction\n * @returns true if it hits the sphere\n */\n intersectsSphere(sphere, intersectionTreshold = 0) {\n const x = sphere.center.x - this.origin.x;\n const y = sphere.center.y - this.origin.y;\n const z = sphere.center.z - this.origin.z;\n const pyth = x * x + y * y + z * z;\n const radius = sphere.radius + intersectionTreshold;\n const rr = radius * radius;\n if (pyth <= rr) {\n return true;\n }\n const dot = x * this.direction.x + y * this.direction.y + z * this.direction.z;\n if (dot < 0.0) {\n return false;\n }\n const temp = pyth - dot * dot;\n return temp <= rr;\n }\n /**\n * If the ray hits a triange\n * @param vertex0 triangle vertex\n * @param vertex1 triangle vertex\n * @param vertex2 triangle vertex\n * @returns intersection information if hit\n */\n intersectsTriangle(vertex0, vertex1, vertex2) {\n const edge1 = Ray._TmpVector3[0];\n const edge2 = Ray._TmpVector3[1];\n const pvec = Ray._TmpVector3[2];\n const tvec = Ray._TmpVector3[3];\n const qvec = Ray._TmpVector3[4];\n vertex1.subtractToRef(vertex0, edge1);\n vertex2.subtractToRef(vertex0, edge2);\n Vector3.CrossToRef(this.direction, edge2, pvec);\n const det = Vector3.Dot(edge1, pvec);\n if (det === 0) {\n return null;\n }\n const invdet = 1 / det;\n this.origin.subtractToRef(vertex0, tvec);\n const bv = Vector3.Dot(tvec, pvec) * invdet;\n if (bv < 0 || bv > 1.0) {\n return null;\n }\n Vector3.CrossToRef(tvec, edge1, qvec);\n const bw = Vector3.Dot(this.direction, qvec) * invdet;\n if (bw < 0 || bv + bw > 1.0) {\n return null;\n }\n //check if the distance is longer than the predefined length.\n const distance = Vector3.Dot(edge2, qvec) * invdet;\n if (distance > this.length) {\n return null;\n }\n return new IntersectionInfo(1 - bv - bw, bv, distance);\n }\n /**\n * Checks if ray intersects a plane\n * @param plane the plane to check\n * @returns the distance away it was hit\n */\n intersectsPlane(plane) {\n let distance;\n const result1 = Vector3.Dot(plane.normal, this.direction);\n if (Math.abs(result1) < 9.99999997475243e-7) {\n return null;\n }\n else {\n const result2 = Vector3.Dot(plane.normal, this.origin);\n distance = (-plane.d - result2) / result1;\n if (distance < 0.0) {\n if (distance < -9.99999997475243e-7) {\n return null;\n }\n else {\n return 0;\n }\n }\n return distance;\n }\n }\n /**\n * Calculate the intercept of a ray on a given axis\n * @param axis to check 'x' | 'y' | 'z'\n * @param offset from axis interception (i.e. an offset of 1y is intercepted above ground)\n * @returns a vector containing the coordinates where 'axis' is equal to zero (else offset), or null if there is no intercept.\n */\n intersectsAxis(axis, offset = 0) {\n switch (axis) {\n case \"y\": {\n const t = (this.origin.y - offset) / this.direction.y;\n if (t > 0) {\n return null;\n }\n return new Vector3(this.origin.x + this.direction.x * -t, offset, this.origin.z + this.direction.z * -t);\n }\n case \"x\": {\n const t = (this.origin.x - offset) / this.direction.x;\n if (t > 0) {\n return null;\n }\n return new Vector3(offset, this.origin.y + this.direction.y * -t, this.origin.z + this.direction.z * -t);\n }\n case \"z\": {\n const t = (this.origin.z - offset) / this.direction.z;\n if (t > 0) {\n return null;\n }\n return new Vector3(this.origin.x + this.direction.x * -t, this.origin.y + this.direction.y * -t, offset);\n }\n default:\n return null;\n }\n }\n /**\n * Checks if ray intersects a mesh. The ray is defined in WORLD space. A mesh triangle can be picked both from its front and back sides,\n * irrespective of orientation.\n * @param mesh the mesh to check\n * @param fastCheck defines if the first intersection will be used (and not the closest)\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\n * @param worldToUse defines the world matrix to use to get the world coordinate of the intersection point\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\n * @returns picking info of the intersection\n */\n intersectsMesh(mesh, fastCheck, trianglePredicate, onlyBoundingInfo = false, worldToUse, skipBoundingInfo = false) {\n const tm = TmpVectors.Matrix[0];\n mesh.getWorldMatrix().invertToRef(tm);\n if (this._tmpRay) {\n Ray.TransformToRef(this, tm, this._tmpRay);\n }\n else {\n this._tmpRay = Ray.Transform(this, tm);\n }\n return mesh.intersects(this._tmpRay, fastCheck, trianglePredicate, onlyBoundingInfo, worldToUse, skipBoundingInfo);\n }\n /**\n * Checks if ray intersects a mesh\n * @param meshes the meshes to check\n * @param fastCheck defines if the first intersection will be used (and not the closest)\n * @param results array to store result in\n * @returns Array of picking infos\n */\n intersectsMeshes(meshes, fastCheck, results) {\n if (results) {\n results.length = 0;\n }\n else {\n results = [];\n }\n for (let i = 0; i < meshes.length; i++) {\n const pickInfo = this.intersectsMesh(meshes[i], fastCheck);\n if (pickInfo.hit) {\n results.push(pickInfo);\n }\n }\n results.sort(this._comparePickingInfo);\n return results;\n }\n _comparePickingInfo(pickingInfoA, pickingInfoB) {\n if (pickingInfoA.distance < pickingInfoB.distance) {\n return -1;\n }\n else if (pickingInfoA.distance > pickingInfoB.distance) {\n return 1;\n }\n else {\n return 0;\n }\n }\n /**\n * Intersection test between the ray and a given segment within a given tolerance (threshold)\n * @param sega the first point of the segment to test the intersection against\n * @param segb the second point of the segment to test the intersection against\n * @param threshold the tolerance margin, if the ray doesn't intersect the segment but is close to the given threshold, the intersection is successful\n * @returns the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection\n */\n intersectionSegment(sega, segb, threshold) {\n const o = this.origin;\n const u = TmpVectors.Vector3[0];\n const rsegb = TmpVectors.Vector3[1];\n const v = TmpVectors.Vector3[2];\n const w = TmpVectors.Vector3[3];\n segb.subtractToRef(sega, u);\n this.direction.scaleToRef(Ray._Rayl, v);\n o.addToRef(v, rsegb);\n sega.subtractToRef(o, w);\n const a = Vector3.Dot(u, u); // always >= 0\n const b = Vector3.Dot(u, v);\n const c = Vector3.Dot(v, v); // always >= 0\n const d = Vector3.Dot(u, w);\n const e = Vector3.Dot(v, w);\n const D = a * c - b * b; // always >= 0\n let sN, sD = D; // sc = sN / sD, default sD = D >= 0\n let tN, tD = D; // tc = tN / tD, default tD = D >= 0\n // compute the line parameters of the two closest points\n if (D < Ray._Smallnum) {\n // the lines are almost parallel\n sN = 0.0; // force using point P0 on segment S1\n sD = 1.0; // to prevent possible division by 0.0 later\n tN = e;\n tD = c;\n }\n else {\n // get the closest points on the infinite lines\n sN = b * e - c * d;\n tN = a * e - b * d;\n if (sN < 0.0) {\n // sc < 0 => the s=0 edge is visible\n sN = 0.0;\n tN = e;\n tD = c;\n }\n else if (sN > sD) {\n // sc > 1 => the s=1 edge is visible\n sN = sD;\n tN = e + b;\n tD = c;\n }\n }\n if (tN < 0.0) {\n // tc < 0 => the t=0 edge is visible\n tN = 0.0;\n // recompute sc for this edge\n if (-d < 0.0) {\n sN = 0.0;\n }\n else if (-d > a) {\n sN = sD;\n }\n else {\n sN = -d;\n sD = a;\n }\n }\n else if (tN > tD) {\n // tc > 1 => the t=1 edge is visible\n tN = tD;\n // recompute sc for this edge\n if (-d + b < 0.0) {\n sN = 0;\n }\n else if (-d + b > a) {\n sN = sD;\n }\n else {\n sN = -d + b;\n sD = a;\n }\n }\n // finally do the division to get sc and tc\n const sc = Math.abs(sN) < Ray._Smallnum ? 0.0 : sN / sD;\n const tc = Math.abs(tN) < Ray._Smallnum ? 0.0 : tN / tD;\n // get the difference of the two closest points\n const qtc = TmpVectors.Vector3[4];\n v.scaleToRef(tc, qtc);\n const qsc = TmpVectors.Vector3[5];\n u.scaleToRef(sc, qsc);\n qsc.addInPlace(w);\n const dP = TmpVectors.Vector3[6];\n qsc.subtractToRef(qtc, dP); // = S1(sc) - S2(tc)\n const isIntersected = tc > 0 && tc <= this.length && dP.lengthSquared() < threshold * threshold; // return intersection result\n if (isIntersected) {\n return qsc.length();\n }\n return -1;\n }\n /**\n * Update the ray from viewport position\n * @param x position\n * @param y y position\n * @param viewportWidth viewport width\n * @param viewportHeight viewport height\n * @param world world matrix\n * @param view view matrix\n * @param projection projection matrix\n * @param enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)\n * @returns this ray updated\n */\n update(x, y, viewportWidth, viewportHeight, world, view, projection, enableDistantPicking = false) {\n if (enableDistantPicking) {\n // With world matrices having great values (like 8000000000 on 1 or more scaling or position axis),\n // multiplying view/projection/world and doing invert will result in loss of float precision in the matrix.\n // One way to fix it is to compute the ray with world at identity then transform the ray in object space.\n // This is slower (2 matrix inverts instead of 1) but precision is preserved.\n // This is hidden behind `EnableDistantPicking` flag (default is false)\n if (!Ray._RayDistant) {\n Ray._RayDistant = Ray.Zero();\n }\n Ray._RayDistant.unprojectRayToRef(x, y, viewportWidth, viewportHeight, Matrix.IdentityReadOnly, view, projection);\n const tm = TmpVectors.Matrix[0];\n world.invertToRef(tm);\n Ray.TransformToRef(Ray._RayDistant, tm, this);\n }\n else {\n this.unprojectRayToRef(x, y, viewportWidth, viewportHeight, world, view, projection);\n }\n return this;\n }\n // Statics\n /**\n * Creates a ray with origin and direction of 0,0,0\n * @returns the new ray\n */\n static Zero() {\n return new Ray(Vector3.Zero(), Vector3.Zero());\n }\n /**\n * Creates a new ray from screen space and viewport\n * @param x position\n * @param y y position\n * @param viewportWidth viewport width\n * @param viewportHeight viewport height\n * @param world world matrix\n * @param view view matrix\n * @param projection projection matrix\n * @returns new ray\n */\n static CreateNew(x, y, viewportWidth, viewportHeight, world, view, projection) {\n const result = Ray.Zero();\n return result.update(x, y, viewportWidth, viewportHeight, world, view, projection);\n }\n /**\n * Function will create a new transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be\n * transformed to the given world matrix.\n * @param origin The origin point\n * @param end The end point\n * @param world a matrix to transform the ray to. Default is the identity matrix.\n * @returns the new ray\n */\n static CreateNewFromTo(origin, end, world = Matrix.IdentityReadOnly) {\n const direction = end.subtract(origin);\n const length = Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);\n direction.normalize();\n return Ray.Transform(new Ray(origin, direction, length), world);\n }\n /**\n * Transforms a ray by a matrix\n * @param ray ray to transform\n * @param matrix matrix to apply\n * @returns the resulting new ray\n */\n static Transform(ray, matrix) {\n const result = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 0));\n Ray.TransformToRef(ray, matrix, result);\n return result;\n }\n /**\n * Transforms a ray by a matrix\n * @param ray ray to transform\n * @param matrix matrix to apply\n * @param result ray to store result in\n */\n static TransformToRef(ray, matrix, result) {\n Vector3.TransformCoordinatesToRef(ray.origin, matrix, result.origin);\n Vector3.TransformNormalToRef(ray.direction, matrix, result.direction);\n result.length = ray.length;\n const dir = result.direction;\n const len = dir.length();\n if (!(len === 0 || len === 1)) {\n const num = 1.0 / len;\n dir.x *= num;\n dir.y *= num;\n dir.z *= num;\n result.length *= len;\n }\n }\n /**\n * Unproject a ray from screen space to object space\n * @param sourceX defines the screen space x coordinate to use\n * @param sourceY defines the screen space y coordinate to use\n * @param viewportWidth defines the current width of the viewport\n * @param viewportHeight defines the current height of the viewport\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\n * @param view defines the view matrix to use\n * @param projection defines the projection matrix to use\n */\n unprojectRayToRef(sourceX, sourceY, viewportWidth, viewportHeight, world, view, projection) {\n const matrix = TmpVectors.Matrix[0];\n world.multiplyToRef(view, matrix);\n matrix.multiplyToRef(projection, matrix);\n matrix.invert();\n const engine = EngineStore.LastCreatedEngine;\n const nearScreenSource = TmpVectors.Vector3[0];\n nearScreenSource.x = (sourceX / viewportWidth) * 2 - 1;\n nearScreenSource.y = -((sourceY / viewportHeight) * 2 - 1);\n nearScreenSource.z = (engine === null || engine === void 0 ? void 0 : engine.useReverseDepthBuffer) ? 1 : (engine === null || engine === void 0 ? void 0 : engine.isNDCHalfZRange) ? 0 : -1;\n // far Z need to be close but < to 1 or camera projection matrix with maxZ = 0 will NaN\n const farScreenSource = TmpVectors.Vector3[1].copyFromFloats(nearScreenSource.x, nearScreenSource.y, 1.0 - 1e-8);\n const nearVec3 = TmpVectors.Vector3[2];\n const farVec3 = TmpVectors.Vector3[3];\n Vector3._UnprojectFromInvertedMatrixToRef(nearScreenSource, matrix, nearVec3);\n Vector3._UnprojectFromInvertedMatrixToRef(farScreenSource, matrix, farVec3);\n this.origin.copyFrom(nearVec3);\n farVec3.subtractToRef(nearVec3, this.direction);\n this.direction.normalize();\n }\n }\n Ray._TmpVector3 = ArrayTools.BuildArray(6, Vector3.Zero);\n Ray._RayDistant = Ray.Zero();\n Ray._Smallnum = 0.00000001;\n Ray._Rayl = 10e8;\n Scene.prototype.createPickingRay = function (x, y, world, camera, cameraViewSpace = false) {\n const result = Ray.Zero();\n this.createPickingRayToRef(x, y, world, result, camera, cameraViewSpace);\n return result;\n };\n Scene.prototype.createPickingRayToRef = function (x, y, world, result, camera, cameraViewSpace = false, enableDistantPicking = false) {\n const engine = this.getEngine();\n if (!camera) {\n if (!this.activeCamera) {\n return this;\n }\n camera = this.activeCamera;\n }\n const cameraViewport = camera.viewport;\n const viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());\n // Moving coordinates to local viewport world\n x = x / engine.getHardwareScalingLevel() - viewport.x;\n y = y / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - viewport.y - viewport.height);\n result.update(x, y, viewport.width, viewport.height, world ? world : Matrix.IdentityReadOnly, cameraViewSpace ? Matrix.IdentityReadOnly : camera.getViewMatrix(), camera.getProjectionMatrix(), enableDistantPicking);\n return this;\n };\n Scene.prototype.createPickingRayInCameraSpace = function (x, y, camera) {\n const result = Ray.Zero();\n this.createPickingRayInCameraSpaceToRef(x, y, result, camera);\n return result;\n };\n Scene.prototype.createPickingRayInCameraSpaceToRef = function (x, y, result, camera) {\n if (!PickingInfo) {\n return this;\n }\n const engine = this.getEngine();\n if (!camera) {\n if (!this.activeCamera) {\n throw new Error(\"Active camera not set\");\n }\n camera = this.activeCamera;\n }\n const cameraViewport = camera.viewport;\n const viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());\n const identity = Matrix.Identity();\n // Moving coordinates to local viewport world\n x = x / engine.getHardwareScalingLevel() - viewport.x;\n y = y / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - viewport.y - viewport.height);\n result.update(x, y, viewport.width, viewport.height, identity, identity, camera.getProjectionMatrix());\n return this;\n };\n Scene.prototype._internalPickForMesh = function (pickingInfo, rayFunction, mesh, world, fastCheck, onlyBoundingInfo, trianglePredicate, skipBoundingInfo) {\n const ray = rayFunction(world, mesh.enableDistantPicking);\n const result = mesh.intersects(ray, fastCheck, trianglePredicate, onlyBoundingInfo, world, skipBoundingInfo);\n if (!result || !result.hit) {\n return null;\n }\n if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance) {\n return null;\n }\n return result;\n };\n Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck, onlyBoundingInfo, trianglePredicate) {\n let pickingInfo = null;\n const computeWorldMatrixForCamera = !!(this.activeCameras && this.activeCameras.length > 1 && this.cameraToUseForPointers !== this.activeCamera);\n const currentCamera = this.cameraToUseForPointers || this.activeCamera;\n for (let meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {\n const mesh = this.meshes[meshIndex];\n if (predicate) {\n if (!predicate(mesh)) {\n continue;\n }\n }\n else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {\n continue;\n }\n const forceCompute = computeWorldMatrixForCamera && mesh.isWorldMatrixCameraDependent();\n const world = mesh.computeWorldMatrix(forceCompute, currentCamera);\n if (mesh.hasThinInstances && mesh.thinInstanceEnablePicking) {\n // first check if the ray intersects the whole bounding box/sphere of the mesh\n const result = this._internalPickForMesh(pickingInfo, rayFunction, mesh, world, true, true, trianglePredicate);\n if (result) {\n if (onlyBoundingInfo) {\n // the user only asked for a bounding info check so we can return\n return result;\n }\n const tmpMatrix = TmpVectors.Matrix[1];\n const thinMatrices = mesh.thinInstanceGetWorldMatrices();\n for (let index = 0; index < thinMatrices.length; index++) {\n const thinMatrix = thinMatrices[index];\n thinMatrix.multiplyToRef(world, tmpMatrix);\n const result = this._internalPickForMesh(pickingInfo, rayFunction, mesh, tmpMatrix, fastCheck, onlyBoundingInfo, trianglePredicate, true);\n if (result) {\n pickingInfo = result;\n pickingInfo.thinInstanceIndex = index;\n if (fastCheck) {\n return pickingInfo;\n }\n }\n }\n }\n }\n else {\n const result = this._internalPickForMesh(pickingInfo, rayFunction, mesh, world, fastCheck, onlyBoundingInfo, trianglePredicate);\n if (result) {\n pickingInfo = result;\n if (fastCheck) {\n return pickingInfo;\n }\n }\n }\n }\n return pickingInfo || new PickingInfo();\n };\n Scene.prototype._internalMultiPick = function (rayFunction, predicate, trianglePredicate) {\n if (!PickingInfo) {\n return null;\n }\n const pickingInfos = new Array();\n const computeWorldMatrixForCamera = !!(this.activeCameras && this.activeCameras.length > 1 && this.cameraToUseForPointers !== this.activeCamera);\n const currentCamera = this.cameraToUseForPointers || this.activeCamera;\n for (let meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {\n const mesh = this.meshes[meshIndex];\n if (predicate) {\n if (!predicate(mesh)) {\n continue;\n }\n }\n else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {\n continue;\n }\n const forceCompute = computeWorldMatrixForCamera && mesh.isWorldMatrixCameraDependent();\n const world = mesh.computeWorldMatrix(forceCompute, currentCamera);\n if (mesh.hasThinInstances && mesh.thinInstanceEnablePicking) {\n const result = this._internalPickForMesh(null, rayFunction, mesh, world, true, true, trianglePredicate);\n if (result) {\n const tmpMatrix = TmpVectors.Matrix[1];\n const thinMatrices = mesh.thinInstanceGetWorldMatrices();\n for (let index = 0; index < thinMatrices.length; index++) {\n const thinMatrix = thinMatrices[index];\n thinMatrix.multiplyToRef(world, tmpMatrix);\n const result = this._internalPickForMesh(null, rayFunction, mesh, tmpMatrix, false, false, trianglePredicate, true);\n if (result) {\n result.thinInstanceIndex = index;\n pickingInfos.push(result);\n }\n }\n }\n }\n else {\n const result = this._internalPickForMesh(null, rayFunction, mesh, world, false, false, trianglePredicate);\n if (result) {\n pickingInfos.push(result);\n }\n }\n }\n return pickingInfos;\n };\n Scene.prototype.pickWithBoundingInfo = function (x, y, predicate, fastCheck, camera) {\n if (!PickingInfo) {\n return null;\n }\n const result = this._internalPick((world) => {\n if (!this._tempPickingRay) {\n this._tempPickingRay = Ray.Zero();\n }\n this.createPickingRayToRef(x, y, world, this._tempPickingRay, camera || null);\n return this._tempPickingRay;\n }, predicate, fastCheck, true);\n if (result) {\n result.ray = this.createPickingRay(x, y, Matrix.Identity(), camera || null);\n }\n return result;\n };\n Object.defineProperty(Scene.prototype, \"_pickingAvailable\", {\n get: () => true,\n enumerable: false,\n configurable: false,\n });\n Scene.prototype.pick = function (x, y, predicate, fastCheck, camera, trianglePredicate, _enableDistantPicking = false) {\n const result = this._internalPick((world, enableDistantPicking) => {\n if (!this._tempPickingRay) {\n this._tempPickingRay = Ray.Zero();\n }\n this.createPickingRayToRef(x, y, world, this._tempPickingRay, camera || null, false, enableDistantPicking);\n return this._tempPickingRay;\n }, predicate, fastCheck, false, trianglePredicate);\n if (result) {\n result.ray = this.createPickingRay(x, y, Matrix.Identity(), camera || null);\n }\n return result;\n };\n Scene.prototype.pickWithRay = function (ray, predicate, fastCheck, trianglePredicate) {\n const result = this._internalPick((world) => {\n if (!this._pickWithRayInverseMatrix) {\n this._pickWithRayInverseMatrix = Matrix.Identity();\n }\n world.invertToRef(this._pickWithRayInverseMatrix);\n if (!this._cachedRayForTransform) {\n this._cachedRayForTransform = Ray.Zero();\n }\n Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);\n return this._cachedRayForTransform;\n }, predicate, fastCheck, false, trianglePredicate);\n if (result) {\n result.ray = ray;\n }\n return result;\n };\n Scene.prototype.multiPick = function (x, y, predicate, camera, trianglePredicate) {\n return this._internalMultiPick((world) => this.createPickingRay(x, y, world, camera || null), predicate, trianglePredicate);\n };\n Scene.prototype.multiPickWithRay = function (ray, predicate, trianglePredicate) {\n return this._internalMultiPick((world) => {\n if (!this._pickWithRayInverseMatrix) {\n this._pickWithRayInverseMatrix = Matrix.Identity();\n }\n world.invertToRef(this._pickWithRayInverseMatrix);\n if (!this._cachedRayForTransform) {\n this._cachedRayForTransform = Ray.Zero();\n }\n Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);\n return this._cachedRayForTransform;\n }, predicate, trianglePredicate);\n };\n Camera.prototype.getForwardRay = function (length = 100, transform, origin) {\n return this.getForwardRayToRef(new Ray(Vector3.Zero(), Vector3.Zero(), length), length, transform, origin);\n };\n Camera.prototype.getForwardRayToRef = function (refRay, length = 100, transform, origin) {\n if (!transform) {\n transform = this.getWorldMatrix();\n }\n refRay.length = length;\n if (!origin) {\n refRay.origin.copyFrom(this.position);\n }\n else {\n refRay.origin.copyFrom(origin);\n }\n TmpVectors.Vector3[2].set(0, 0, this._scene.useRightHandedSystem ? -1 : 1);\n Vector3.TransformNormalToRef(TmpVectors.Vector3[2], transform, TmpVectors.Vector3[3]);\n Vector3.NormalizeToRef(TmpVectors.Vector3[3], refRay.direction);\n return refRay;\n };\n\n /* eslint-disable @typescript-eslint/naming-convention */\n // https://dickyjim.wordpress.com/2013/09/04/spherical-harmonics-for-beginners/\n // http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf\n // https://www.ppsloan.org/publications/StupidSH36.pdf\n // http://cseweb.ucsd.edu/~ravir/papers/envmap/envmap.pdf\n // https://www.ppsloan.org/publications/SHJCGT.pdf\n // https://www.ppsloan.org/publications/shdering.pdf\n // https://google.github.io/filament/Filament.md.html#annex/sphericalharmonics\n // https://patapom.com/blog/SHPortal/\n // https://imdoingitwrong.wordpress.com/2011/04/14/spherical-harmonics-wtf/\n // Using real SH basis:\n // m>0 m m\n // y = sqrt(2) * K * P * cos(m*phi) * cos(theta)\n // l l l\n //\n // m<0 m |m|\n // y = sqrt(2) * K * P * sin(m*phi) * cos(theta)\n // l l l\n //\n // m=0 0 0\n // y = K * P * trigono terms\n // l l l\n //\n // m (2l + 1)(l - |m|)!\n // K = sqrt(------------------)\n // l 4pi(l + |m|)!\n //\n // and P by recursion:\n //\n // P00(x) = 1\n // P01(x) = x\n // Pll(x) = (-1^l)(2l - 1)!!(1-x*x)^(1/2)\n // ((2l - 1)x[Pl-1/m]-(l + m - 1)[Pl-2/m])\n // Plm(x) = ---------------------------------------\n // l - m\n // Leaving the trigonometric terms aside we can precompute the constants to :\n const SH3ylmBasisConstants = [\n Math.sqrt(1 / (4 * Math.PI)),\n -Math.sqrt(3 / (4 * Math.PI)),\n Math.sqrt(3 / (4 * Math.PI)),\n -Math.sqrt(3 / (4 * Math.PI)),\n Math.sqrt(15 / (4 * Math.PI)),\n -Math.sqrt(15 / (4 * Math.PI)),\n Math.sqrt(5 / (16 * Math.PI)),\n -Math.sqrt(15 / (4 * Math.PI)),\n Math.sqrt(15 / (16 * Math.PI)), // l22\n ];\n // cm = cos(m * phi)\n // sm = sin(m * phi)\n // {x,y,z} = {cos(phi)sin(theta), sin(phi)sin(theta), cos(theta)}\n // By recursion on using trigo identities:\n const SH3ylmBasisTrigonometricTerms = [\n () => 1,\n (direction) => direction.y,\n (direction) => direction.z,\n (direction) => direction.x,\n (direction) => direction.x * direction.y,\n (direction) => direction.y * direction.z,\n (direction) => 3 * direction.z * direction.z - 1,\n (direction) => direction.x * direction.z,\n (direction) => direction.x * direction.x - direction.y * direction.y, // l22\n ];\n // Wrap the full compute\n const applySH3 = (lm, direction) => {\n return SH3ylmBasisConstants[lm] * SH3ylmBasisTrigonometricTerms[lm](direction);\n };\n // Derived from the integration of the a kernel convolution to SH.\n // Great explanation here: https://patapom.com/blog/SHPortal/#about-distant-radiance-and-irradiance-environments\n const SHCosKernelConvolution = [Math.PI, (2 * Math.PI) / 3, (2 * Math.PI) / 3, (2 * Math.PI) / 3, Math.PI / 4, Math.PI / 4, Math.PI / 4, Math.PI / 4, Math.PI / 4];\n /**\n * Class representing spherical harmonics coefficients to the 3rd degree\n */\n class SphericalHarmonics {\n constructor() {\n /**\n * Defines whether or not the harmonics have been prescaled for rendering.\n */\n this.preScaled = false;\n /**\n * The l0,0 coefficients of the spherical harmonics\n */\n this.l00 = Vector3.Zero();\n /**\n * The l1,-1 coefficients of the spherical harmonics\n */\n this.l1_1 = Vector3.Zero();\n /**\n * The l1,0 coefficients of the spherical harmonics\n */\n this.l10 = Vector3.Zero();\n /**\n * The l1,1 coefficients of the spherical harmonics\n */\n this.l11 = Vector3.Zero();\n /**\n * The l2,-2 coefficients of the spherical harmonics\n */\n this.l2_2 = Vector3.Zero();\n /**\n * The l2,-1 coefficients of the spherical harmonics\n */\n this.l2_1 = Vector3.Zero();\n /**\n * The l2,0 coefficients of the spherical harmonics\n */\n this.l20 = Vector3.Zero();\n /**\n * The l2,1 coefficients of the spherical harmonics\n */\n this.l21 = Vector3.Zero();\n /**\n * The l2,2 coefficients of the spherical harmonics\n */\n this.l22 = Vector3.Zero();\n }\n /**\n * Adds a light to the spherical harmonics\n * @param direction the direction of the light\n * @param color the color of the light\n * @param deltaSolidAngle the delta solid angle of the light\n */\n addLight(direction, color, deltaSolidAngle) {\n TmpVectors.Vector3[0].set(color.r, color.g, color.b);\n const colorVector = TmpVectors.Vector3[0];\n const c = TmpVectors.Vector3[1];\n colorVector.scaleToRef(deltaSolidAngle, c);\n c.scaleToRef(applySH3(0, direction), TmpVectors.Vector3[2]);\n this.l00.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(1, direction), TmpVectors.Vector3[2]);\n this.l1_1.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(2, direction), TmpVectors.Vector3[2]);\n this.l10.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(3, direction), TmpVectors.Vector3[2]);\n this.l11.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(4, direction), TmpVectors.Vector3[2]);\n this.l2_2.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(5, direction), TmpVectors.Vector3[2]);\n this.l2_1.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(6, direction), TmpVectors.Vector3[2]);\n this.l20.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(7, direction), TmpVectors.Vector3[2]);\n this.l21.addInPlace(TmpVectors.Vector3[2]);\n c.scaleToRef(applySH3(8, direction), TmpVectors.Vector3[2]);\n this.l22.addInPlace(TmpVectors.Vector3[2]);\n }\n /**\n * Scales the spherical harmonics by the given amount\n * @param scale the amount to scale\n */\n scaleInPlace(scale) {\n this.l00.scaleInPlace(scale);\n this.l1_1.scaleInPlace(scale);\n this.l10.scaleInPlace(scale);\n this.l11.scaleInPlace(scale);\n this.l2_2.scaleInPlace(scale);\n this.l2_1.scaleInPlace(scale);\n this.l20.scaleInPlace(scale);\n this.l21.scaleInPlace(scale);\n this.l22.scaleInPlace(scale);\n }\n /**\n * Convert from incident radiance (Li) to irradiance (E) by applying convolution with the cosine-weighted hemisphere.\n *\n * ```\n * E_lm = A_l * L_lm\n * ```\n *\n * In spherical harmonics this convolution amounts to scaling factors for each frequency band.\n * This corresponds to equation 5 in \"An Efficient Representation for Irradiance Environment Maps\", where\n * the scaling factors are given in equation 9.\n */\n convertIncidentRadianceToIrradiance() {\n // Constant (Band 0)\n this.l00.scaleInPlace(SHCosKernelConvolution[0]);\n // Linear (Band 1)\n this.l1_1.scaleInPlace(SHCosKernelConvolution[1]);\n this.l10.scaleInPlace(SHCosKernelConvolution[2]);\n this.l11.scaleInPlace(SHCosKernelConvolution[3]);\n // Quadratic (Band 2)\n this.l2_2.scaleInPlace(SHCosKernelConvolution[4]);\n this.l2_1.scaleInPlace(SHCosKernelConvolution[5]);\n this.l20.scaleInPlace(SHCosKernelConvolution[6]);\n this.l21.scaleInPlace(SHCosKernelConvolution[7]);\n this.l22.scaleInPlace(SHCosKernelConvolution[8]);\n }\n /**\n * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.\n *\n * ```\n * L = (1/pi) * E * rho\n * ```\n *\n * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.\n */\n convertIrradianceToLambertianRadiance() {\n this.scaleInPlace(1.0 / Math.PI);\n // The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied\n // (The pixel shader must apply albedo after texture fetches, etc).\n }\n /**\n * Integrates the reconstruction coefficients directly in to the SH preventing further\n * required operations at run time.\n *\n * This is simply done by scaling back the SH with Ylm constants parameter.\n * The trigonometric part being applied by the shader at run time.\n */\n preScaleForRendering() {\n this.preScaled = true;\n this.l00.scaleInPlace(SH3ylmBasisConstants[0]);\n this.l1_1.scaleInPlace(SH3ylmBasisConstants[1]);\n this.l10.scaleInPlace(SH3ylmBasisConstants[2]);\n this.l11.scaleInPlace(SH3ylmBasisConstants[3]);\n this.l2_2.scaleInPlace(SH3ylmBasisConstants[4]);\n this.l2_1.scaleInPlace(SH3ylmBasisConstants[5]);\n this.l20.scaleInPlace(SH3ylmBasisConstants[6]);\n this.l21.scaleInPlace(SH3ylmBasisConstants[7]);\n this.l22.scaleInPlace(SH3ylmBasisConstants[8]);\n }\n /**\n * update the spherical harmonics coefficients from the given array\n * @param data defines the 9x3 coefficients (l00, l1-1, l10, l11, l2-2, l2-1, l20, l21, l22)\n * @returns the spherical harmonics (this)\n */\n updateFromArray(data) {\n Vector3.FromArrayToRef(data[0], 0, this.l00);\n Vector3.FromArrayToRef(data[1], 0, this.l1_1);\n Vector3.FromArrayToRef(data[2], 0, this.l10);\n Vector3.FromArrayToRef(data[3], 0, this.l11);\n Vector3.FromArrayToRef(data[4], 0, this.l2_2);\n Vector3.FromArrayToRef(data[5], 0, this.l2_1);\n Vector3.FromArrayToRef(data[6], 0, this.l20);\n Vector3.FromArrayToRef(data[7], 0, this.l21);\n Vector3.FromArrayToRef(data[8], 0, this.l22);\n return this;\n }\n /**\n * update the spherical harmonics coefficients from the given floats array\n * @param data defines the 9x3 coefficients (l00, l1-1, l10, l11, l2-2, l2-1, l20, l21, l22)\n * @returns the spherical harmonics (this)\n */\n updateFromFloatsArray(data) {\n Vector3.FromFloatsToRef(data[0], data[1], data[2], this.l00);\n Vector3.FromFloatsToRef(data[3], data[4], data[5], this.l1_1);\n Vector3.FromFloatsToRef(data[6], data[7], data[8], this.l10);\n Vector3.FromFloatsToRef(data[9], data[10], data[11], this.l11);\n Vector3.FromFloatsToRef(data[12], data[13], data[14], this.l2_2);\n Vector3.FromFloatsToRef(data[15], data[16], data[17], this.l2_1);\n Vector3.FromFloatsToRef(data[18], data[19], data[20], this.l20);\n Vector3.FromFloatsToRef(data[21], data[22], data[23], this.l21);\n Vector3.FromFloatsToRef(data[24], data[25], data[26], this.l22);\n return this;\n }\n /**\n * Constructs a spherical harmonics from an array.\n * @param data defines the 9x3 coefficients (l00, l1-1, l10, l11, l2-2, l2-1, l20, l21, l22)\n * @returns the spherical harmonics\n */\n static FromArray(data) {\n const sh = new SphericalHarmonics();\n return sh.updateFromArray(data);\n }\n // Keep for references.\n /**\n * Gets the spherical harmonics from polynomial\n * @param polynomial the spherical polynomial\n * @returns the spherical harmonics\n */\n static FromPolynomial(polynomial) {\n const result = new SphericalHarmonics();\n result.l00 = polynomial.xx.scale(0.376127).add(polynomial.yy.scale(0.376127)).add(polynomial.zz.scale(0.376126));\n result.l1_1 = polynomial.y.scale(0.977204);\n result.l10 = polynomial.z.scale(0.977204);\n result.l11 = polynomial.x.scale(0.977204);\n result.l2_2 = polynomial.xy.scale(1.16538);\n result.l2_1 = polynomial.yz.scale(1.16538);\n result.l20 = polynomial.zz.scale(1.34567).subtract(polynomial.xx.scale(0.672834)).subtract(polynomial.yy.scale(0.672834));\n result.l21 = polynomial.zx.scale(1.16538);\n result.l22 = polynomial.xx.scale(1.16538).subtract(polynomial.yy.scale(1.16538));\n result.l1_1.scaleInPlace(-1);\n result.l11.scaleInPlace(-1);\n result.l2_1.scaleInPlace(-1);\n result.l21.scaleInPlace(-1);\n result.scaleInPlace(Math.PI);\n return result;\n }\n }\n /**\n * Class representing spherical polynomial coefficients to the 3rd degree\n */\n class SphericalPolynomial {\n constructor() {\n /**\n * The x coefficients of the spherical polynomial\n */\n this.x = Vector3.Zero();\n /**\n * The y coefficients of the spherical polynomial\n */\n this.y = Vector3.Zero();\n /**\n * The z coefficients of the spherical polynomial\n */\n this.z = Vector3.Zero();\n /**\n * The xx coefficients of the spherical polynomial\n */\n this.xx = Vector3.Zero();\n /**\n * The yy coefficients of the spherical polynomial\n */\n this.yy = Vector3.Zero();\n /**\n * The zz coefficients of the spherical polynomial\n */\n this.zz = Vector3.Zero();\n /**\n * The xy coefficients of the spherical polynomial\n */\n this.xy = Vector3.Zero();\n /**\n * The yz coefficients of the spherical polynomial\n */\n this.yz = Vector3.Zero();\n /**\n * The zx coefficients of the spherical polynomial\n */\n this.zx = Vector3.Zero();\n }\n /**\n * The spherical harmonics used to create the polynomials.\n */\n get preScaledHarmonics() {\n if (!this._harmonics) {\n this._harmonics = SphericalHarmonics.FromPolynomial(this);\n }\n if (!this._harmonics.preScaled) {\n this._harmonics.preScaleForRendering();\n }\n return this._harmonics;\n }\n /**\n * Adds an ambient color to the spherical polynomial\n * @param color the color to add\n */\n addAmbient(color) {\n TmpVectors.Vector3[0].copyFromFloats(color.r, color.g, color.b);\n const colorVector = TmpVectors.Vector3[0];\n this.xx.addInPlace(colorVector);\n this.yy.addInPlace(colorVector);\n this.zz.addInPlace(colorVector);\n }\n /**\n * Scales the spherical polynomial by the given amount\n * @param scale the amount to scale\n */\n scaleInPlace(scale) {\n this.x.scaleInPlace(scale);\n this.y.scaleInPlace(scale);\n this.z.scaleInPlace(scale);\n this.xx.scaleInPlace(scale);\n this.yy.scaleInPlace(scale);\n this.zz.scaleInPlace(scale);\n this.yz.scaleInPlace(scale);\n this.zx.scaleInPlace(scale);\n this.xy.scaleInPlace(scale);\n }\n /**\n * Updates the spherical polynomial from harmonics\n * @param harmonics the spherical harmonics\n * @returns the spherical polynomial\n */\n updateFromHarmonics(harmonics) {\n this._harmonics = harmonics;\n this.x.copyFrom(harmonics.l11);\n this.x.scaleInPlace(1.02333).scaleInPlace(-1);\n this.y.copyFrom(harmonics.l1_1);\n this.y.scaleInPlace(1.02333).scaleInPlace(-1);\n this.z.copyFrom(harmonics.l10);\n this.z.scaleInPlace(1.02333);\n this.xx.copyFrom(harmonics.l00);\n TmpVectors.Vector3[0].copyFrom(harmonics.l20).scaleInPlace(0.247708);\n TmpVectors.Vector3[1].copyFrom(harmonics.l22).scaleInPlace(0.429043);\n this.xx.scaleInPlace(0.886277).subtractInPlace(TmpVectors.Vector3[0]).addInPlace(TmpVectors.Vector3[1]);\n this.yy.copyFrom(harmonics.l00);\n this.yy.scaleInPlace(0.886277).subtractInPlace(TmpVectors.Vector3[0]).subtractInPlace(TmpVectors.Vector3[1]);\n this.zz.copyFrom(harmonics.l00);\n TmpVectors.Vector3[0].copyFrom(harmonics.l20).scaleInPlace(0.495417);\n this.zz.scaleInPlace(0.886277).addInPlace(TmpVectors.Vector3[0]);\n this.yz.copyFrom(harmonics.l2_1);\n this.yz.scaleInPlace(0.858086).scaleInPlace(-1);\n this.zx.copyFrom(harmonics.l21);\n this.zx.scaleInPlace(0.858086).scaleInPlace(-1);\n this.xy.copyFrom(harmonics.l2_2);\n this.xy.scaleInPlace(0.858086);\n this.scaleInPlace(1.0 / Math.PI);\n return this;\n }\n /**\n * Gets the spherical polynomial from harmonics\n * @param harmonics the spherical harmonics\n * @returns the spherical polynomial\n */\n static FromHarmonics(harmonics) {\n const result = new SphericalPolynomial();\n return result.updateFromHarmonics(harmonics);\n }\n /**\n * Constructs a spherical polynomial from an array.\n * @param data defines the 9x3 coefficients (x, y, z, xx, yy, zz, yz, zx, xy)\n * @returns the spherical polynomial\n */\n static FromArray(data) {\n const sp = new SphericalPolynomial();\n Vector3.FromArrayToRef(data[0], 0, sp.x);\n Vector3.FromArrayToRef(data[1], 0, sp.y);\n Vector3.FromArrayToRef(data[2], 0, sp.z);\n Vector3.FromArrayToRef(data[3], 0, sp.xx);\n Vector3.FromArrayToRef(data[4], 0, sp.yy);\n Vector3.FromArrayToRef(data[5], 0, sp.zz);\n Vector3.FromArrayToRef(data[6], 0, sp.yz);\n Vector3.FromArrayToRef(data[7], 0, sp.zx);\n Vector3.FromArrayToRef(data[8], 0, sp.xy);\n return sp;\n }\n }\n\n const ray1 = Ray.Zero();\n const vector1 = Vector3.Zero();\n const vector2 = Vector3.Zero();\n const vector3 = Vector3.Zero();\n function getCameraPositionWithOffset(camera) {\n if (camera instanceof ArcRotateCamera) {\n camera.getForwardRayToRef(ray1);\n Vector3.CrossToRef(ray1.direction, Vector3.Up(), vector1);\n Vector3.CrossToRef(ray1.direction, vector1, vector2);\n vector1.normalize().scaleInPlace(-camera.targetScreenOffset.x);\n vector2.normalize().scaleInPlace(camera.targetScreenOffset.y);\n vector3.copyFrom(camera.globalPosition);\n vector3.addInPlace(vector1).addInPlace(vector2);\n return vector3;\n }\n else {\n return camera.globalPosition;\n }\n }\n function toRadians(degrees) {\n const scalar = Math.PI / 180;\n return degrees * scalar;\n }\n function roundVectorToPlaces(vector, significance = 1, direction) {\n vector.x = roundToPlaces(vector.x, significance, direction);\n vector.y = roundToPlaces(vector.y, significance, direction);\n vector.z = roundToPlaces(vector.z, significance, direction);\n }\n function roundToPlaces(value, significance = 1, direction = 'round') {\n const isRound = Math.round(value / significance) * significance === value;\n if (isRound) {\n return value;\n }\n const n = (value / significance) * (1 + Number.EPSILON);\n let tmp;\n if (direction === 'ceil') {\n tmp = Math.ceil(n);\n }\n else if (direction === 'floor') {\n tmp = Math.floor(n);\n }\n else {\n tmp = Math.round(n);\n }\n return tmp * significance;\n }\n function rotationToVector(toVector, fromVector) {\n const result = new Quaternion();\n if (!fromVector) {\n fromVector = new Vector3(0, 1, 0);\n }\n rotationToVectorToRef(toVector, fromVector, result);\n return result;\n }\n function transformVectorWithQuat(vector, quat) {\n const transform = new Matrix();\n quat.toRotationMatrix(transform);\n const transformVector = Vector3.TransformCoordinates(vector, transform);\n return transformVector;\n }\n function applyTransformToVector(vector, transform) {\n const v = new Vector3(vector.x, vector.y, vector.z);\n const matrix = Matrix.Compose(new Vector3(1, 1, 1), Quaternion.Identity(), v);\n return applyTransformToSpace(matrix, transform);\n }\n function applyTransformToSpace(worldTransform, inSpace) {\n if (!inSpace) {\n inSpace = Matrix.Identity();\n }\n const inSpaceInv = inSpace.clone().invert();\n if (Array.isArray(worldTransform)) {\n worldTransform = Matrix.FromArray(worldTransform);\n }\n const spaceTransform = inSpace.multiply(worldTransform);\n spaceTransform.multiplyToRef(inSpaceInv, spaceTransform);\n const t = new Vector3();\n const q = new Quaternion();\n const s = new Vector3();\n spaceTransform.decompose(s, q, t);\n return {\n position: { x: t.x, y: t.y, z: t.z },\n rotation: exports.KbQuaternion.FromQuat(q),\n scaling: { x: s.x, y: s.y, z: s.z },\n };\n // const fromSpaceRotation = fromSpace.rotationQuaternion ? fromSpace.rotationQuaternion : Quaternion.Identity();\n // const toSpaceRotation = toSpace.rotationQuaternion ? toSpace.rotationQuaternion : Quaternion.Identity();\n // const fromSpaceRotationInverse = fromSpaceRotation.clone().invert();\n // const toSpaceRotationInverse = toSpaceRotation.clone().invert();\n // const q1 = q.clone().multiply(fromSpaceRotationInverse);\n // const q2 = toSpaceRotationInverse.multiply(q1);\n // const q3 = q2.multiply(toSpaceRotation);\n // return q3;\n }\n function computeLocalTransform(node) {\n let rotation;\n if (node.useEuler) {\n rotation = Quaternion.FromEulerAngles(toRadians(node.eulerRotation.x), toRadians(node.eulerRotation.y), toRadians(node.eulerRotation.z));\n }\n else {\n rotation = Quaternion.RotationAxis(node.rotationAxis.toVec3(), node.rotationAngle * (Math.PI / 180));\n }\n const pivotTransform = node.pivot ? Matrix.Translation(-node.pivot.x, -node.pivot.y, -node.pivot.z) : undefined;\n const scalingTransform = Matrix.Scaling(node.scaling, node.scaling, node.scaling);\n const rotationTransform = new Matrix();\n Matrix.FromQuaternionToRef(rotation, rotationTransform);\n const translationTransform = Matrix.Translation(node.position.x, node.position.y, node.position.z);\n const transform = Matrix.Identity();\n if (pivotTransform) {\n transform.multiplyToRef(pivotTransform, transform);\n }\n transform.multiplyToRef(scalingTransform, transform);\n transform.multiplyToRef(rotationTransform, transform);\n transform.multiplyToRef(translationTransform, transform);\n if (pivotTransform) {\n transform.multiplyToRef(pivotTransform.invert(), transform);\n }\n return transform;\n }\n function rotationToVectorToRef(_toVector, _fromVector, result) {\n const toVector = _toVector.clone().normalize();\n const fromVector = _fromVector.clone().normalize();\n if (Vector3.Dot(fromVector, toVector) > 0.9999999) {\n result.set(0, 0, 0, 1); // Identity Quaternion\n }\n if (Vector3.Dot(fromVector, toVector) < -0.9999999) {\n // Rotate 180 degrees about arbitrary axis\n return Quaternion.RotationAxisToRef(Vector3.Right().equals(toVector) ? Vector3.Up().cross(toVector) : Vector3.Right().cross(toVector), Math.PI, result);\n }\n const rotAxis = toVector.cross(fromVector);\n const w = -Math.acos(Vector3.Dot(fromVector, toVector));\n return Quaternion.RotationAxisToRef(rotAxis, w, result);\n }\n function degreeToRadian(vectorDegree, optionalResult) {\n optionalResult = optionalResult || new Vector3();\n if (vectorDegree !== optionalResult) {\n optionalResult.copyFrom(vectorDegree);\n }\n return multiplyScalar(optionalResult, Math.PI / 180);\n }\n function multiplyScalar(vec, scalar) {\n vec.x *= scalar;\n vec.y *= scalar;\n vec.z *= scalar;\n return vec;\n }\n function computeNormal(normals) {\n const vertex1 = normals[0];\n const vertex2 = normals[1];\n const vertex3 = normals[2];\n const p1p2 = vertex1.subtract(vertex2);\n const p3p2 = vertex3.subtract(vertex2);\n const normal = Vector3.Normalize(Vector3.Cross(p1p2, p3p2));\n return normal;\n }\n function applyMatrix4(thisVect, m) {\n const x = thisVect.x, y = thisVect.y, z = thisVect.z;\n const e = m.asArray();\n thisVect.x = e[0] * x + e[4] * y + e[8] * z + e[12];\n thisVect.y = e[1] * x + e[5] * y + e[9] * z + e[13];\n thisVect.z = e[2] * x + e[6] * y + e[10] * z + e[14];\n return thisVect;\n }\n function mathClamp(x, a, b) {\n return x < a ? a : x > b ? b : x;\n }\n function makeRotationAxis(axis, angle) {\n const c = Math.cos(angle);\n const s = Math.sin(angle);\n const t = 1 - c;\n const x = axis.x, y = axis.y, z = axis.z;\n const tx = t * x, ty = t * y;\n const matrix = Matrix.FromValues(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);\n return matrix;\n }\n function getRotationBtwVectors(u, v) {\n //http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final\n v.clone().normalize();\n u.clone().normalize();\n const dot = Vector3.Dot(u, v);\n const k = 1; //we are using unit vectors, so just use \"1\" instead of: Math.sqrt(u.length()^2 * v.length()^2);\n let w = k + dot;\n let r;\n if (w < 0.0000001) {\n /* If u and v are exactly opposite, rotate 180 degrees\n * around an arbitrary orthogonal axis. Axis normalisation\n * can happen later, when we normalise the quaternion. */\n w = 0;\n r = Math.abs(u.x) > Math.abs(u.z) ? new Vector3(-u.y, u.x, 0) : new Vector3(0, -u.z, u.y);\n }\n else {\n r = Vector3.Cross(u, v);\n }\n return new Quaternion(r.x, r.y, r.z, w).normalize();\n }\n function addArrays(arrayA, arrayB) {\n if (arrayA.length == 0) {\n return arrayB;\n }\n if (arrayB.length == 0) {\n return arrayA;\n }\n const result = [];\n const n = Math.min(arrayA.length, arrayB.length);\n for (let i = 0; i < n; i++) {\n result[i] = arrayA[i] + arrayB[i];\n }\n return result;\n }\n (function (AxisType) {\n AxisType[AxisType[\"X\"] = 1] = \"X\";\n AxisType[AxisType[\"Y\"] = 2] = \"Y\";\n AxisType[AxisType[\"Z\"] = 3] = \"Z\";\n AxisType[AxisType[\"Custom\"] = 4] = \"Custom\";\n })(exports.AxisType || (exports.AxisType = {}));\n\n var KbVector_1;\n exports.KbVector = KbVector_1 = class KbVector {\n constructor(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n if (!isFinite(x) || isNaN(x)) {\n this.x = 0;\n console.error('Error: Non numeric or infinite value detected in x-value of a vector, please check snapcode for mistakes.');\n }\n if (!isFinite(y) || isNaN(y)) {\n this.y = 0;\n console.error('Error: Non numeric or infinite value detected in y-value of a vector, please check snapcode for mistakes.');\n }\n if (!isFinite(z) || isNaN(z)) {\n this.z = 0;\n console.error('Error: Non numeric or infinite value detected in z-value of a vector, please check snapcode for mistakes.');\n }\n }\n add(v) {\n return new KbVector_1(this.x + v.x, this.y + v.y, this.z + v.z);\n }\n subtract(v) {\n return new KbVector_1(this.x - v.x, this.y - v.y, this.z - v.z);\n }\n multiply(v) {\n return new KbVector_1(this.x * v.x, this.y * v.y, this.z * v.z);\n }\n divide(v) {\n const newX = v.x !== 0 ? this.x / v.x : 0;\n const newY = v.y !== 0 ? this.y / v.y : 0;\n const newZ = v.z !== 0 ? this.z / v.z : 0;\n return new KbVector_1(newX, newY, newZ);\n }\n crossProduct(v) {\n const x = this.y * v.z - this.z * v.y;\n const y = this.z * v.x - this.x * v.z;\n const z = this.x * v.y - this.y * v.x;\n return new KbVector_1(x, y, z);\n }\n dotProduct(v) {\n return this.x * v.x + this.y * v.y + this.z * v.z;\n }\n length() {\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\n }\n normalize() {\n const l = this.length();\n if (l === 0 || l === 1.0) {\n return this.clone();\n }\n return this.scale(1.0 / l);\n }\n scale(s) {\n return new KbVector_1(this.x * s, this.y * s, this.z * s);\n }\n equal(v) {\n return v.x == this.x && v.y == this.y && v.z == this.z;\n }\n clone() {\n return new KbVector_1(this.x, this.y, this.z);\n }\n assign(v) {\n return new KbVector_1(typeof v.x === 'number' ? v.x : this.x, typeof v.y === 'number' ? v.y : this.y, typeof v.z === 'number' ? v.z : this.z);\n }\n shiftClone(component, amount) {\n if (component === 'x') {\n return new KbVector_1(amount, this.y, this.z);\n }\n else if (component === 'y') {\n return new KbVector_1(this.x, amount, this.z);\n }\n else {\n return new KbVector_1(this.x, this.y, amount);\n }\n }\n toString() {\n return `{ x: ${this.x}, y: ${this.y}, z: ${this.z} }`;\n }\n toObject() {\n return { x: this.x, y: this.y, z: this.z };\n }\n round(significance = 1, direction) {\n return new KbVector_1(roundToPlaces(this.x, significance, direction), roundToPlaces(this.y, significance, direction), roundToPlaces(this.z, significance, direction));\n }\n static Zero() {\n return new KbVector_1(0, 0, 0);\n }\n static Identity() {\n return new KbVector_1(1, 1, 1);\n }\n static From(v) {\n return new KbVector_1(v.x, v.y, v.z);\n }\n };\n exports.KbVector = KbVector_1 = __decorate([\n Kb3dModel({\n token: Token.KbVector,\n trackChanges: false,\n create: args => new KbVector_1(args.x || 0, args.y || 0, args.z || 0),\n }),\n __param(0, Ignore()),\n __param(1, Ignore()),\n __param(2, Ignore())\n ], exports.KbVector);\n\n var KbQuaternion_1;\n exports.KbQuaternion = KbQuaternion_1 = class KbQuaternion {\n constructor(x, y, z, w) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n if (this.w > 1) {\n this.w = 1;\n }\n if (this.w < -1) {\n this.w = -1;\n }\n }\n clone() {\n return new KbQuaternion_1(this.x, this.y, this.z, this.w);\n }\n assign(v) {\n return new KbQuaternion_1(typeof v.x === 'number' ? v.x : this.x, typeof v.y === 'number' ? v.y : this.y, typeof v.z === 'number' ? v.z : this.z, typeof v.w === 'number' ? v.w : this.w);\n }\n toEuler() {\n let x, y, z;\n const qz = this.z;\n const qx = this.x;\n const qy = this.y;\n const qw = this.w;\n const sqw = qw * qw;\n const sqz = qz * qz;\n const sqx = qx * qx;\n const sqy = qy * qy;\n const zAxisY = qy * qz - qx * qw;\n const limit = 0.4999999;\n if (zAxisY < -limit) {\n y = 2 * Math.atan2(qy, qw);\n x = Math.PI / 2;\n z = 0;\n }\n else if (zAxisY > limit) {\n y = 2 * Math.atan2(qy, qw);\n x = -Math.PI / 2;\n z = 0;\n }\n else {\n z = Math.atan2(2.0 * (qx * qy + qz * qw), -sqz - sqx + sqy + sqw);\n x = Math.asin(-2.0 * (qz * qy - qx * qw));\n y = Math.atan2(2.0 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);\n }\n const scalar = 180 / Math.PI;\n return new exports.KbVector(x * scalar, y * scalar, z * scalar);\n }\n multiply(q) {\n const x = this.x * q.w + this.y * q.z - this.z * q.y + this.w * q.x;\n const y = -this.x * q.z + this.y * q.w + this.z * q.x + this.w * q.y;\n const z = this.x * q.y - this.y * q.x + this.z * q.w + this.w * q.z;\n const w = -this.x * q.x - this.y * q.y - this.z * q.z + this.w * q.w;\n return new KbQuaternion_1(x, y, z, w);\n }\n equal(q) {\n return (!!q &&\n basicallyEqual(q.x, this.x) &&\n basicallyEqual(q.y, this.y) &&\n basicallyEqual(q.z, this.z) &&\n basicallyEqual(q.w, this.w));\n }\n toObject() {\n return { x: this.x, y: this.y, z: this.z, w: this.w };\n }\n getAngle() {\n return this._getRadAngle() * (180 / Math.PI);\n }\n _getRadAngle() {\n return Math.acos(this.w) * 2;\n }\n getAxis() {\n const angle = this._getRadAngle();\n const sin = Math.sin(angle / 2);\n if (sin === 0) {\n return exports.KbVector.Zero();\n }\n else {\n return new exports.KbVector(this.x / sin, this.y / sin, this.z / sin).normalize();\n }\n }\n static FromRotationAxis(axis, angle) {\n // var sin = Math.sin(angle / 2);\n // axis.normalize();\n // result.w = Math.cos(angle / 2);\n // result.x = axis._x * sin;\n // result.y = axis._y * sin;\n // result.z = axis._z * sin;\n const rad = (angle * Math.PI) / 180;\n const sin = Math.sin(rad / 2);\n const nAxis = axis.normalize();\n const result = new KbQuaternion_1(nAxis.x * sin, nAxis.y * sin, nAxis.z * sin, Math.cos(rad / 2));\n return result;\n }\n static FromYawPitchRoll(dV) {\n const v = dV.scale(Math.PI / 180);\n const halfRoll = v.z * 0.5;\n const halfPitch = v.x * 0.5;\n const halfYaw = v.y * 0.5;\n const sinRoll = Math.sin(halfRoll);\n const cosRoll = Math.cos(halfRoll);\n const sinPitch = Math.sin(halfPitch);\n const cosPitch = Math.cos(halfPitch);\n const sinYaw = Math.sin(halfYaw);\n const cosYaw = Math.cos(halfYaw);\n const result = new KbQuaternion_1(cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll, sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll, cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll, cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll);\n return result;\n }\n static Identity() {\n return new KbQuaternion_1(0, 0, 0, 1);\n }\n static From(q) {\n return new KbQuaternion_1(q.x, q.y, q.z, q.w);\n }\n };\n exports.KbQuaternion = KbQuaternion_1 = __decorate([\n Kb3dModel({\n token: Token.KbQuaternion,\n trackChanges: false,\n create: args => new KbQuaternion_1(args.x || 0, args.y || 0, args.z || 0, args.w || 1),\n }),\n __param(0, Ignore()),\n __param(1, Ignore()),\n __param(2, Ignore()),\n __param(3, Ignore())\n ], exports.KbQuaternion);\n function basicallyEqual(a, b) {\n return Math.abs(a - b) < 0.0000000001; // To deal with floating point errors\n }\n\n exports.SpaceNode = class SpaceNode extends exports.Kb3dObject {\n constructor() {\n super();\n this._showPivot = false;\n // this._rotationQuaternion = nodeConfig.rotationQuaternion ? KbQuaternion.FromVec3(nodeConfig.rotationQuaternion) : KbQuaternion.Identity();\n // this._rotation = this._rotationQuaternion.toEuler();\n }\n getRotationQuaternion() {\n if (this.useEuler && this.eulerRotation) {\n return exports.KbQuaternion.FromYawPitchRoll(this.eulerRotation);\n }\n else if (this.rotationAxis && this.rotationAngle !== undefined) {\n return exports.KbQuaternion.FromRotationAxis(this.rotationAxis, this.rotationAngle);\n }\n return exports.KbQuaternion.Identity();\n }\n setRotationQuaternion(q) {\n if (this.useEuler) {\n this.eulerRotation = q.toEuler();\n }\n else {\n this.rotationAngle = q.getAngle();\n this.rotationAxis = q.getAxis();\n }\n }\n get features() {\n if (!this._features)\n this._features = [];\n return this._features;\n }\n set features(val) {\n this._features = val;\n }\n get connectors() {\n if (!this._connectors)\n this._connectors = [];\n return this._connectors;\n }\n set connectors(val) {\n this._connectors = val;\n }\n getChildren() {\n return [...this.features, ...this.connectors];\n }\n getChildArrayForType(token) {\n if (token.isFeature()) {\n return this.features;\n }\n else if (token == Token.Connector) {\n return this.connectors;\n }\n else {\n throw Error('unexpected token');\n }\n }\n getAncestors() {\n return super.getAncestors();\n }\n copyPropertiesTo(target) {\n target.name = this.name;\n target.visible = this.visible;\n target.position = this.position;\n target.useEuler = this.useEuler;\n target.eulerRotation = this.eulerRotation;\n target.rotationAngle = this.rotationAngle;\n target.rotationAxis = this.rotationAxis;\n target.scaling = this.scaling;\n target.pivot = this.pivot;\n target.fixed = this.fixed;\n target._primeMover = this._primeMover;\n target._showPivot = this._showPivot;\n target.preTransform = this.preTransform;\n }\n getFeatureByName(name) {\n return [...this.features, ...this.connectors].find(f => f.name.isEqual(name));\n }\n rotate(axis, angle) {\n axis.normalize();\n const q = exports.KbQuaternion.FromRotationAxis(axis, angle);\n this.setRotationQuaternion(this.getRotationQuaternion().multiply(q));\n }\n };\n __decorate([\n Enumerable()\n ], exports.SpaceNode.prototype, \"features\", null);\n __decorate([\n Enumerable()\n ], exports.SpaceNode.prototype, \"connectors\", null);\n exports.SpaceNode = __decorate([\n BaseKb3dModel({\n token: Token.SpaceNode,\n })\n ], exports.SpaceNode);\n\n var MeshNode_1;\n exports.MeshNode = MeshNode_1 = class MeshNode extends exports.SpaceNode {\n constructor() {\n super();\n this._polygonCount = 0;\n this._verticesCount = 0;\n this.materialId = null;\n }\n getSpaceChildren() {\n return new Array();\n }\n copyPropertiesTo(target) {\n super.copyPropertiesTo(target);\n if (target instanceof MeshNode_1) {\n target.flipSurfaceOrientation = this.flipSurfaceOrientation;\n target.receiveShadows = this.receiveShadows;\n target.castShadows = this.castShadows;\n target.checkCollisions = this.checkCollisions;\n target.materialId = this.materialId;\n target.opacity = this.opacity;\n }\n }\n };\n __decorate([\n NodeReference(exports.MaterialNode, '')\n ], exports.MeshNode.prototype, \"materialId\", void 0);\n exports.MeshNode = MeshNode_1 = __decorate([\n BaseKb3dModel({\n token: Token.MeshNode,\n })\n ], exports.MeshNode);\n\n var PrimitiveMeshNode_1;\n exports.PrimitiveMeshNode = PrimitiveMeshNode_1 = class PrimitiveMeshNode extends exports.MeshNode {\n constructor() {\n super();\n }\n copyPropertiesTo(target) {\n super.copyPropertiesTo(target);\n if (target instanceof PrimitiveMeshNode_1) {\n target.uvOverrides = this.uvOverrides;\n target.sideOrientation = this.sideOrientation;\n }\n }\n };\n exports.PrimitiveMeshNode = PrimitiveMeshNode_1 = __decorate([\n BaseKb3dModel({\n token: Token.PrimitiveMeshNode,\n })\n ], exports.PrimitiveMeshNode);\n\n exports.BoxNode = class BoxNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.BoxNode = __decorate([\n Kb3dModel({\n token: Token.BoxNode,\n })\n ], exports.BoxNode);\n function isBoxMesh(node) {\n return instanceOf(node, Token.BoxNode);\n }\n\n exports.ConeNode = class ConeNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.ConeNode = __decorate([\n Kb3dModel({\n token: Token.ConeNode,\n })\n ], exports.ConeNode);\n function isConeMesh(node) {\n return instanceOf(node, Token.ConeNode);\n }\n\n var CustomMeshNode_1;\n /**\n * A Mesh Node. Must be a descendant of the MeshRoot node.\n * @param {Object} nodeConfig The configuration object of the node.\n * @param {string} nodeConfig.name The name of the node. Required.\n * @param {Object} parent The parent of this node. Optional, but mesh nodes should have parents if they are to be displayed.\n * @property\n */\n exports.CustomMeshNode = CustomMeshNode_1 = class CustomMeshNode extends exports.MeshNode {\n constructor() {\n super();\n /** Loading state of mesh. Used to keep track of when a request is in flight */\n this._loading = null;\n }\n get hasGeometry() {\n return this.geometryId != null && this.geometryId != '';\n }\n get geometryLoaded() {\n return this._geometry != null;\n }\n copyPropertiesTo(target) {\n super.copyPropertiesTo(target);\n if (target instanceof CustomMeshNode_1) {\n target.geometryId = this.geometryId;\n }\n }\n };\n __decorate([\n IgnoreChanges\n ], exports.CustomMeshNode.prototype, \"_loading\", void 0);\n exports.CustomMeshNode = CustomMeshNode_1 = __decorate([\n Kb3dModel({\n token: Token.CustomMeshNode,\n })\n ], exports.CustomMeshNode);\n\n exports.CylinderNode = class CylinderNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.CylinderNode = __decorate([\n Kb3dModel({\n token: Token.CylinderNode,\n })\n ], exports.CylinderNode);\n function isCylinderMesh(node) {\n return instanceOf(node, Token.CylinderNode);\n }\n\n exports.DiscNode = class DiscNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.DiscNode = __decorate([\n Kb3dModel({\n token: Token.DiscNode,\n })\n ], exports.DiscNode);\n function isDiscMesh(node) {\n return instanceOf(node, Token.DiscNode);\n }\n\n exports.MeshGroupNode = class MeshGroupNode extends exports.SpaceNode {\n constructor() {\n super();\n }\n get meshes() {\n if (!this._meshes)\n this._meshes = [];\n return this._meshes;\n }\n set meshes(val) {\n this._meshes = val;\n }\n getChildren() {\n return super.getChildren().concat(this.meshes);\n }\n getChildArrayForType(token) {\n if (token.isMeshOrGroup() || token.isLight()) {\n return this.meshes;\n }\n else if (token.isConnector()) {\n return this.connectors;\n }\n else {\n throw 'unexpected token';\n }\n }\n getSpaceChildren() {\n return this.meshes;\n }\n };\n __decorate([\n Enumerable()\n ], exports.MeshGroupNode.prototype, \"meshes\", null);\n exports.MeshGroupNode = __decorate([\n Kb3dModel({\n token: Token.MeshGroupNode,\n })\n ], exports.MeshGroupNode);\n\n function isMeshGroupNode(node) {\n return instanceOf(node, Token.MeshGroupNode);\n }\n function isCustomMeshNode(node) {\n return instanceOf(node, Token.CustomMeshNode);\n }\n function isSketchNode(node) {\n return instanceOf(node, Token.SketchNode);\n }\n function isTextNode(node) {\n return instanceOf(node, Token.TextNode);\n }\n function isSketchControlPoint(node) {\n return instanceOf(node, Token.SketchControlPoint);\n }\n function isMeshNode(node) {\n return instanceOfAny(node, ...Token.MeshTokens);\n }\n function isPrimitiveMeshNode(node) {\n return instanceOf(node, Token.PrimitiveMeshNode);\n }\n function isSpaceNode(node) {\n return instanceOf(node, Token.SpaceNode);\n }\n function isPickable(node) {\n if (node instanceof exports.SpaceNode || node instanceof exports.AnnotationNode) {\n return true;\n }\n else {\n return false;\n }\n }\n function isTrackedMeshNode(node) {\n return isMeshNode(node) && isTrackedInstanceOfAny(node, ...Token.MeshAndGroupTokens);\n }\n\n exports.PlaneNode = class PlaneNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.PlaneNode = __decorate([\n Kb3dModel({\n token: Token.PlaneNode,\n })\n ], exports.PlaneNode);\n function isPlaneMesh(node) {\n return instanceOf(node, Token.PlaneNode);\n }\n\n var KbColor_1;\n exports.KbColor = KbColor_1 = class KbColor {\n constructor(r, g, b, a = 1) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n }\n clone() {\n return new KbColor_1(this.r, this.g, this.b, this.a);\n }\n assign(c) {\n return new KbColor_1(typeof c.r === 'number' ? c.r : this.r, typeof c.g === 'number' ? c.g : this.g, typeof c.b === 'number' ? c.b : this.b, typeof c.a === 'number' ? c.a : this.a);\n }\n equal(c) {\n return !!c && c.r == this.r && c.g == this.g && c.b == this.b && c.a == this.a;\n }\n cssString() {\n if (this.a < 1) {\n return `rgba(${this.r * 255}, ${this.g * 255}, ${this.b * 255}, ${this.a})`;\n }\n else {\n return `rgb(${this.r * 255}, ${this.g * 255}, ${this.b * 255})`;\n }\n }\n toObject() {\n return { r: this.r, g: this.g, b: this.b, a: this.a };\n }\n toIntObject() {\n return { r: this.r * 255, g: this.g * 255, b: this.b * 255, a: this.a };\n }\n static From(c) {\n return new KbColor_1(c.r, c.g, c.b, c.a);\n }\n static FromIntObject(c) {\n return new KbColor_1(c.r / 255, c.g / 255, c.b / 255, c.a != null ? c.a : 1);\n }\n static White() {\n return new KbColor_1(1, 1, 1, 1);\n }\n static Black() {\n return new KbColor_1(0, 0, 0, 1);\n }\n static Transparent() {\n return new KbColor_1(0, 0, 0, 0);\n }\n static Green() {\n return new KbColor_1(0, 1, 0);\n }\n static Red() {\n return new KbColor_1(1, 0, 0);\n }\n static KbmaxOrange() {\n return new KbColor_1(227 / 255, 131 / 255, 28 / 255);\n }\n static KbmaxBlue() {\n return new KbColor_1(8 / 255, 72 / 255, 96 / 255);\n }\n };\n exports.KbColor = KbColor_1 = __decorate([\n Kb3dModel({\n token: Token.KbColor,\n trackChanges: false,\n create: args => new KbColor_1(args.r || 0, args.g || 0, args.b || 0, args.a),\n }),\n __param(0, Ignore()),\n __param(1, Ignore()),\n __param(2, Ignore()),\n __param(3, Ignore())\n ], exports.KbColor);\n\n var KbGeometry_1;\n const NEW_GEOMETRY = 'NEW_GEOMETRY';\n const MAX_INT16 = 32767;\n const MAX_UINT16 = 65535;\n exports.KbGeometry = KbGeometry_1 = class KbGeometry {\n /**\n * A geometry object. Geometries are immutable, once they are created they should not be modified.\n */\n constructor() {\n this.shared = false;\n }\n clone() {\n const newGeometry = new KbGeometry_1();\n newGeometry.indices = this.indices;\n newGeometry.positions = this.positions;\n newGeometry.normals = this.normals;\n newGeometry.tangents = this.tangents;\n newGeometry.uvs = this.uvs;\n return newGeometry;\n }\n /**\n * Freeze a geometry to enforce the immutability of geometries\n */\n // freeze() {\n // Object.freeze(this);\n // Object.freeze(this.vertexData);\n // }\n // update(vertexData: Partial) {\n // const newVertexData = { ...this.vertexData, ...vertexData };\n // const newGeometry = new KbGeometry(newVertexData, this.id);\n // return newGeometry;\n // }\n extractFromBinary(fileData, meshNode) {\n const dataView = new DataView(fileData);\n let curPos;\n // indices\n const indicesOffset = dataView.getInt32(0, true);\n curPos = 4;\n const indicesDataSize = dataView.getInt32(curPos, true);\n curPos += 4;\n let indices;\n if (indicesDataSize === 16) {\n const indices16 = new Uint16Array(fileData, curPos, indicesOffset / 2);\n indices = Uint32Array.from(indices16);\n curPos += indicesOffset;\n }\n else if (indicesDataSize === 32) {\n indices = new Uint32Array(fileData, curPos, indicesOffset / 4);\n curPos += indicesOffset;\n }\n else {\n throw Error('Unknown indices data size ' + meshNode.name);\n }\n // positions\n const posOffset = dataView.getInt32(curPos, true);\n curPos += 4;\n const posDataSize = dataView.getInt32(curPos, true);\n curPos += 4;\n const posRatio = dataView.getInt32(curPos, true);\n curPos += 4;\n let positions;\n if (posDataSize === 32) {\n positions = new Float32Array(fileData.slice(curPos, curPos + posOffset));\n for (let i = 0; i < positions.length; i++) {\n positions[i] /= posRatio;\n }\n curPos += posOffset;\n }\n else {\n throw Error('Invalid positions in binary ' + meshNode.name);\n }\n // normals\n const norOffset = dataView.getInt32(curPos, true);\n curPos += 4;\n const norDataSize = dataView.getInt32(curPos, true);\n curPos += 4;\n const norRatio = dataView.getInt32(curPos, true);\n curPos += 4;\n let normals;\n if (norDataSize === 16) {\n const normalsInt = new Int16Array(fileData.slice(curPos, curPos + norOffset));\n normals = new Float32Array(normalsInt.length);\n for (let i = 0; i < normalsInt.length; i++) {\n normals[i] = normalsInt[i] / norRatio;\n }\n curPos += norOffset;\n }\n else {\n throw Error('Invalid normals in binary ' + meshNode.name);\n }\n const uvsOffset = dataView.getInt32(curPos, true);\n curPos += 4;\n const uvsDataSize = dataView.getInt32(curPos, true);\n curPos += 4;\n const uvsRatio = dataView.getInt32(curPos, true);\n curPos += 4;\n let uvs;\n if (uvsDataSize === 16) {\n const uvsInt = new Int16Array(fileData.slice(curPos, curPos + uvsOffset));\n uvs = new Float32Array(uvsInt.length);\n for (let i = 0; i < uvsInt.length; i++) {\n uvs[i] = uvsInt[i] / uvsRatio;\n }\n curPos += uvsOffset;\n }\n else {\n throw Error('Invalid uvs in binary ' + meshNode.name);\n }\n // Error reporting\n if (indices.length % 3 > 0) {\n console.warn('Incomplete indices triangles in mesh ' + meshNode.name);\n }\n if (positions.length % 3 > 0) {\n console.warn('Incomplete position vectors in mesh ' + meshNode.name);\n }\n if (normals.length % 3 > 0) {\n console.warn('Incomplete normal vectors in mesh ' + meshNode.name);\n }\n if (uvs.length % 2 > 0) {\n console.warn('Incomplete uv vectors in mesh ' + meshNode.name);\n }\n if (uvs.length > 0 && positions.length !== normals.length) {\n console.warn('Normals and Positions array size mismatch in ' + meshNode.name);\n }\n if (uvs.length > 0 && positions.length / 3 !== uvs.length / 2) {\n console.warn('UV array size mismatch in ' + meshNode.name);\n }\n // End error reporting\n this.positions = positions;\n this.indices = indices;\n if (normals.length > 0) {\n this.normals = normals;\n }\n if (uvs.length > 0) {\n this.uvs = uvs;\n }\n }\n toBinary() {\n if (!this.positions || !this.indices) {\n return;\n }\n const positions = this.positions;\n const indices = this.indices;\n const normals = this.normals || new Float32Array([]);\n const uvs = this.uvs || new Float32Array([]);\n let fileLen = 0;\n let indicesOffset = 8; // indices data markers\n let indicesBits = 0;\n let indicesLength = 0;\n let posOffset = 0;\n let posBits = 0;\n let posLength = 0;\n let normalsOffset = 0;\n let normalsBits = 0;\n let normalsLength = 0;\n let uvsOffset = 0;\n let uvsBits = 0;\n let uvsLength = 0;\n // calculate the total size of the array\n fileLen += indicesOffset;\n if (canFitInUInt16Bit(indices)) {\n // write a 16bit array\n indicesBits = 16;\n indicesLength = indices.length * 2;\n fileLen += indicesLength;\n }\n else {\n // write a 32bit array\n indicesBits = 32;\n indicesLength = indices.length * 4;\n fileLen += indicesLength;\n }\n fileLen += 12; // position data markers\n posOffset = fileLen;\n posBits = 32;\n fileLen += positions.length * 4;\n posLength = positions.length * 4;\n fileLen += 12; // normals data markers\n normalsOffset = fileLen;\n // write the normals 16 bit array\n normalsBits = 16;\n fileLen += normals.length * 2;\n normalsLength = normals.length * 2;\n fileLen += 12; // uv data markers\n uvsOffset = fileLen;\n uvsBits = 16;\n fileLen += uvs.length * 2;\n uvsLength = uvs.length * 2;\n // create the buffer that represent the binary file\n const buffer = new ArrayBuffer(fileLen);\n const bufferView = new DataView(buffer);\n // let's write the data into the bufferView\n // write the indices\n bufferView.setInt32(indicesOffset - 8, indicesLength, true); // NOTICE that by default JS is big endian, but since our servers are x86 we are little endian\n bufferView.setInt32(indicesOffset - 4, indicesBits, true);\n if (indicesBits == 16) {\n for (let i = 0; i < indices.length; i++) {\n bufferView.setUint16(indicesOffset, indices[i], true);\n indicesOffset += 2;\n }\n }\n else if (indicesBits == 32) {\n for (let i = 0; i < indices.length; i++) {\n bufferView.setUint32(indicesOffset, indices[i], true);\n indicesOffset += 4;\n }\n }\n // write the positions\n bufferView.setInt32(posOffset - 12, posLength, true);\n bufferView.setInt32(posOffset - 8, posBits, true);\n bufferView.setInt32(posOffset - 4, 1, true); // ratio\n if (posBits == 32) {\n for (let i = 0; i < positions.length; i++) {\n bufferView.setFloat32(posOffset, positions[i], true);\n posOffset += 4;\n }\n }\n else {\n console.error('Fix me - non-32bit positions not supported');\n }\n // write the normals\n bufferView.setInt32(normalsOffset - 12, normalsLength, true);\n bufferView.setInt32(normalsOffset - 8, normalsBits, true);\n bufferView.setInt32(normalsOffset - 4, MAX_INT16, true);\n if (normalsBits == 16) {\n for (let i = 0; i < normals.length; i++) {\n const n = floatToIntStore(normals[i], MAX_INT16);\n bufferView.setInt16(normalsOffset, n, true);\n normalsOffset += 2;\n }\n }\n else {\n console.error('Fix me - non-16bit normals not supported');\n }\n // write the UVs\n bufferView.setInt32(uvsOffset - 12, uvsLength, true);\n bufferView.setInt32(uvsOffset - 8, uvsBits, true);\n bufferView.setInt32(uvsOffset - 4, MAX_INT16, true);\n if (uvsBits == 16) {\n for (let i = 0; i < uvs.length; i++) {\n const n = floatToIntStore(uvs[i], MAX_INT16);\n bufferView.setInt16(uvsOffset, n, true);\n uvsOffset += 2;\n }\n }\n else {\n console.error('Fix me - non-16bit uvs not supported');\n }\n return buffer;\n }\n };\n exports.KbGeometry = KbGeometry_1 = __decorate([\n Kb3dModel({\n token: Token.KbGeometry,\n trackChanges: false,\n })\n ], exports.KbGeometry);\n // function canFitInInt16Bit(inArray: Float32Array): boolean {\n // for (let i = 0; i < inArray.length; i++) {\n // const val = inArray[i];\n // if (val > 327.68 || val < -327.68) {\n // return false;\n // }\n // }\n // return true;\n // }\n // function canFitInInt8Bit(inArray: Float32Array): boolean {\n // for (let i = 0; i < inArray.length; i++) {\n // const val = inArray[i];\n // if (val > 1.28 || val < -1.28) {\n // return false;\n // }\n // }\n // return true;\n // }\n function canFitInUInt16Bit(inArray) {\n for (let i = 0; i < inArray.length; i++) {\n const val = inArray[i];\n if (val > MAX_UINT16) {\n return false;\n }\n }\n return true;\n }\n function floatToIntStore(float, maxInt, maxVal = 1) {\n // this function convert a value between -327.68 and 327.68 to an int 16. we use the convention to have only 2 decimal numbers\n float = (Math.min(Math.max(-maxVal, float), maxVal) * maxInt) / maxVal;\n const outVal = Math.trunc(float);\n return outVal;\n }\n\n var SketchNode_1;\n exports.SketchNode = SketchNode_1 = class SketchNode extends exports.MeshNode {\n constructor() {\n super();\n this._boundingBoxMin = exports.KbVector.Zero();\n this._boundingBoxMax = exports.KbVector.Zero();\n this._boundingBoxChanges = new Subject();\n this._controlPoints = [];\n this._lineSegmentStartingPoints = [];\n // todo remove\n this._sketchPoints = new Float32Array();\n this.paths = [];\n /** Whether to generate a face for this path */\n this.addFace = false;\n this.closePath = false;\n this.flipPath = false;\n this.tracePath = false;\n }\n getChildren() {\n return super.getChildren().concat(this.paths);\n }\n getChildArrayForType(token) {\n if (token.isSketchPath()) {\n return this.paths;\n }\n else {\n return super.getChildArrayForType(token);\n }\n }\n getBoundingBox() {\n const min = new exports.KbVector(this.boundingXOverride == null ? this._boundingBoxMin.x : -this.boundingXOverride / 2, this.boundingYOverride == null ? this._boundingBoxMin.y : -this.boundingYOverride / 2, this.boundingZOverride == null ? this._boundingBoxMin.z : -this.boundingZOverride / 2);\n const max = new exports.KbVector(this.boundingXOverride == null ? this._boundingBoxMax.x : this.boundingXOverride / 2, this.boundingYOverride == null ? this._boundingBoxMax.y : this.boundingYOverride / 2, this.boundingZOverride == null ? this._boundingBoxMax.z : this.boundingZOverride / 2);\n const centerBB = this._boundingBoxMin.add(this._boundingBoxMax).scale(0.5);\n const center = new exports.KbVector(this.boundingXOverride == null ? centerBB.x : 0, this.boundingYOverride == null ? centerBB.y : 0, this.boundingZOverride == null ? centerBB.z : 0);\n return {\n min,\n max,\n center,\n };\n }\n getSketchLength() {\n let sketchLength = 0;\n this.paths.forEach(path => {\n let lastPosition = undefined;\n path._points.forEach(point => {\n if (!lastPosition) {\n lastPosition = point;\n }\n else {\n const currentPos = point;\n const distance = Math.sqrt(Math.pow(lastPosition.x - currentPos.x, 2) +\n Math.pow(lastPosition.y - currentPos.y, 2) +\n Math.pow(lastPosition.z - currentPos.z, 2));\n sketchLength += distance;\n lastPosition = currentPos;\n }\n });\n });\n return sketchLength;\n }\n };\n __decorate([\n NodeReference(SketchNode_1)\n ], exports.SketchNode.prototype, \"clonePath\", void 0);\n exports.SketchNode = SketchNode_1 = __decorate([\n Kb3dModel({\n token: Token.SketchNode,\n })\n ], exports.SketchNode);\n\n exports.SketchPath = class SketchPath extends exports.Kb3dObject {\n constructor() {\n super(...arguments);\n /** Path control points */\n this.controlPoints = [];\n /** How smooth to make this path when rasterizing to geometry */\n this.tessellation = 16;\n /** For grouping paths as one contiguous shape. Only required for hole-path matching */\n this.pathGroupKey = 'default';\n this._expanded = false;\n this._points = [];\n }\n getChildren() {\n return super.getChildren().concat(this.controlPoints);\n }\n getChildArrayForType(token) {\n if (token.isConnector()) {\n return this.controlPoints;\n }\n else {\n return super.getChildArrayForType(token);\n }\n }\n getAncestors() {\n return super.getAncestors();\n }\n };\n exports.SketchPath = __decorate([\n Kb3dModel({\n token: Token.SketchPath,\n })\n ], exports.SketchPath);\n\n exports.SphereNode = class SphereNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.SphereNode = __decorate([\n Kb3dModel({\n token: Token.SphereNode,\n })\n ], exports.SphereNode);\n function isSphereMesh(node) {\n return instanceOf(node, Token.SphereNode);\n }\n\n exports.TextNode = class TextNode extends exports.MeshNode {\n constructor() {\n super(...arguments);\n this.curveRadius = 0;\n this.charSpacing = 1;\n this.text = '';\n }\n };\n exports.TextNode = __decorate([\n Kb3dModel({\n token: Token.TextNode,\n })\n ], exports.TextNode);\n\n exports.TorusNode = class TorusNode extends exports.PrimitiveMeshNode {\n constructor() {\n super();\n }\n };\n exports.TorusNode = __decorate([\n Kb3dModel({\n token: Token.TorusNode,\n })\n ], exports.TorusNode);\n function isTorusMesh(node) {\n return instanceOf(node, Token.TorusNode);\n }\n\n class PatternFeature extends exports.Feature {\n }\n PatternFeature._affects = new Set(ALL_GEOMETRY);\n PatternFeature._affectedBy = new Set(ALL_GEOMETRY);\n __decorate([\n NodeReference(exports.SketchNode)\n ], PatternFeature.prototype, \"meshId\", void 0);\n function isPattern(o) {\n return instanceOfAny(o, Token.LinearPatternFeature, Token.CircularPatternFeature);\n }\n\n exports.CircularPatternFeature = class CircularPatternFeature extends PatternFeature {\n };\n exports.CircularPatternFeature._affects = new Set(ALL_GEOMETRY);\n exports.CircularPatternFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.CircularPatternFeature = __decorate([\n Kb3dModel({\n token: Token.CircularPatternFeature,\n })\n ], exports.CircularPatternFeature);\n function isCircularPattern(o) {\n return instanceOf(o, Token.CircularPatternFeature);\n }\n\n exports.Connector = class Connector extends exports.BaseConnector {\n getAncestors() {\n return super.getAncestors();\n }\n getSpaceParent() {\n return this._parent;\n }\n };\n exports.Connector = __decorate([\n Kb3dModel({\n token: Token.Connector,\n })\n ], exports.Connector);\n function isConnector(o) {\n return instanceOf(o, Token.Connector);\n }\n\n exports.DeleteFacesFeature = class DeleteFacesFeature extends exports.Feature {\n constructor() {\n super(...arguments);\n this.vertexGroups = [];\n }\n };\n exports.DeleteFacesFeature._dependsOn = new Set([exports.eMeshChangeTypes.VertexIndices]);\n exports.DeleteFacesFeature._affects = new Set([exports.eMeshChangeTypes.VertexIndices, exports.eMeshChangeTypes.Submeshes]);\n exports.DeleteFacesFeature._affectedBy = new Set([exports.eMeshChangeTypes.VertexIndices, exports.eMeshChangeTypes.Submeshes]);\n exports.DeleteFacesFeature = __decorate([\n Kb3dModel({\n token: Token.DeleteFacesFeature,\n })\n ], exports.DeleteFacesFeature);\n\n exports.DisplacementMapFeature = class DisplacementMapFeature extends exports.Feature {\n constructor(_materialService) {\n super();\n this._materialService = _materialService;\n this._initialized = false;\n }\n get textures() {\n if (!this._textures)\n this._textures = [];\n return this._textures;\n }\n set textures(val) {\n this._textures = val;\n }\n getChildren() {\n return [...this.textures];\n }\n getChildArrayForType(token) {\n if (token.isTexture()) {\n return this.textures;\n }\n else {\n throw 'unexpected token';\n }\n }\n };\n exports.DisplacementMapFeature._affects = new Set([exports.eMeshChangeTypes.VertexNormals, exports.eMeshChangeTypes.VertexPositions]);\n exports.DisplacementMapFeature._affectedBy = new Set(ALL_GEOMETRY);\n __decorate([\n Enumerable()\n ], exports.DisplacementMapFeature.prototype, \"textures\", null);\n exports.DisplacementMapFeature = __decorate([\n Kb3dModel({\n token: Token.DisplacementMapFeature,\n }),\n __param(0, Inject(Token.MaterialService))\n ], exports.DisplacementMapFeature);\n\n exports.ExtrudeFeature = class ExtrudeFeature extends exports.Feature {\n constructor() {\n super(...arguments);\n this.vertexGroups = [];\n }\n };\n exports.ExtrudeFeature._affects = new Set(ALL_GEOMETRY);\n exports.ExtrudeFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.ExtrudeFeature = __decorate([\n Kb3dModel({\n token: Token.ExtrudeFeature,\n })\n ], exports.ExtrudeFeature);\n\n exports.JoinGeometryFeature = class JoinGeometryFeature extends exports.Feature {\n };\n exports.JoinGeometryFeature._affects = new Set(ALL_GEOMETRY);\n exports.JoinGeometryFeature._affectedBy = new Set(ALL_CHANGES);\n __decorate([\n NodeReference(exports.MeshNode)\n ], exports.JoinGeometryFeature.prototype, \"meshId\", void 0);\n exports.JoinGeometryFeature = __decorate([\n Kb3dModel({\n token: Token.JoinGeometryFeature,\n })\n ], exports.JoinGeometryFeature);\n\n exports.LinearPatternFeature = class LinearPatternFeature extends PatternFeature {\n };\n exports.LinearPatternFeature._affects = new Set(ALL_GEOMETRY);\n exports.LinearPatternFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.LinearPatternFeature = __decorate([\n Kb3dModel({\n token: Token.LinearPatternFeature,\n })\n ], exports.LinearPatternFeature);\n function isLinearPattern(o) {\n return instanceOf(o, Token.LinearPatternFeature);\n }\n\n exports.SliceFeature = class SliceFeature extends exports.Feature {\n };\n exports.SliceFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.SliceFeature._affects = new Set(ALL_GEOMETRY);\n exports.SliceFeature = __decorate([\n Kb3dModel({\n token: Token.SliceFeature,\n })\n ], exports.SliceFeature);\n\n exports.MirrorFeature = class MirrorFeature extends exports.SliceFeature {\n };\n exports.MirrorFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.MirrorFeature._affects = new Set(ALL_GEOMETRY);\n exports.MirrorFeature = __decorate([\n Kb3dModel({\n token: Token.MirrorFeature,\n })\n ], exports.MirrorFeature);\n\n exports.MoveVerticesFeature = class MoveVerticesFeature extends exports.Feature {\n constructor() {\n super(...arguments);\n this._previewParticleSize = 0.005;\n }\n get vertexIndices() {\n if (!this._vertexIndices)\n this._vertexIndices = [];\n return this._vertexIndices;\n }\n set vertexIndices(val) {\n this._vertexIndices = val;\n }\n };\n exports.MoveVerticesFeature._dependsOn = new Set([exports.eMeshChangeTypes.VertexIndices]);\n exports.MoveVerticesFeature._affectedBy = new Set([exports.eMeshChangeTypes.VertexPositions]);\n exports.MoveVerticesFeature._affects = new Set([exports.eMeshChangeTypes.VertexPositions]);\n __decorate([\n IgnoreChanges\n ], exports.MoveVerticesFeature.prototype, \"_vertexIndices\", void 0);\n __decorate([\n Enumerable()\n ], exports.MoveVerticesFeature.prototype, \"vertexIndices\", null);\n exports.MoveVerticesFeature = __decorate([\n Kb3dModel({\n token: Token.MoveVerticesFeature,\n })\n ], exports.MoveVerticesFeature);\n\n exports.NormalSmoothingFeature = class NormalSmoothingFeature extends exports.Feature {\n constructor() {\n super(...arguments);\n this.vertexGroups = [];\n this.smooth = true;\n }\n };\n //static _dependsOn = new Set([eMeshChangeTypes.VertexIndices]);\n exports.NormalSmoothingFeature._affects = new Set(ALL_GEOMETRY);\n exports.NormalSmoothingFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.NormalSmoothingFeature = __decorate([\n Kb3dModel({\n token: Token.NormalSmoothingFeature,\n })\n ], exports.NormalSmoothingFeature);\n\n (function (eContainerItemLayout) {\n eContainerItemLayout[\"horizontal\"] = \"horizontal\";\n eContainerItemLayout[\"vertical\"] = \"vertical\";\n eContainerItemLayout[\"absolute\"] = \"absolute\";\n })(exports.eContainerItemLayout || (exports.eContainerItemLayout = {}));\n (function (eContainerChildAlignment) {\n eContainerChildAlignment[\"inherit\"] = \"inherit\";\n eContainerChildAlignment[\"stretch\"] = \"stretch\";\n eContainerChildAlignment[\"start\"] = \"start\";\n eContainerChildAlignment[\"center\"] = \"center\";\n eContainerChildAlignment[\"end\"] = \"end\";\n })(exports.eContainerChildAlignment || (exports.eContainerChildAlignment = {}));\n (function (eContainerItemAlignment) {\n eContainerItemAlignment[\"stretch\"] = \"stretch\";\n eContainerItemAlignment[\"start\"] = \"start\";\n eContainerItemAlignment[\"center\"] = \"center\";\n eContainerItemAlignment[\"end\"] = \"end\";\n })(exports.eContainerItemAlignment || (exports.eContainerItemAlignment = {}));\n (function (eContainerItemJustify) {\n eContainerItemJustify[\"start\"] = \"start\";\n eContainerItemJustify[\"center\"] = \"center\";\n eContainerItemJustify[\"end\"] = \"end\";\n })(exports.eContainerItemJustify || (exports.eContainerItemJustify = {}));\n (function (eScroll) {\n eScroll[\"none\"] = \"none\";\n eScroll[\"auto\"] = \"auto\";\n eScroll[\"x\"] = \"x\";\n eScroll[\"y\"] = \"y\";\n })(exports.eScroll || (exports.eScroll = {}));\n (function (eRelativeSize) {\n eRelativeSize[\"auto\"] = \"auto\";\n eRelativeSize[\"x1\"] = \"x1\";\n eRelativeSize[\"x2\"] = \"x2\";\n eRelativeSize[\"x3\"] = \"x3\";\n eRelativeSize[\"x4\"] = \"x4\";\n eRelativeSize[\"x5\"] = \"x5\";\n eRelativeSize[\"x6\"] = \"x6\";\n eRelativeSize[\"x7\"] = \"x7\";\n eRelativeSize[\"x8\"] = \"x8\";\n eRelativeSize[\"x9\"] = \"x9\";\n eRelativeSize[\"x10\"] = \"x10\";\n eRelativeSize[\"x11\"] = \"x11\";\n eRelativeSize[\"x12\"] = \"x12\";\n eRelativeSize[\"custom\"] = \"custom\";\n })(exports.eRelativeSize || (exports.eRelativeSize = {}));\n (function (ePadding) {\n ePadding[\"none\"] = \"none\";\n ePadding[\"small\"] = \"small\";\n ePadding[\"medium\"] = \"medium\";\n ePadding[\"large\"] = \"large\";\n })(exports.ePadding || (exports.ePadding = {}));\n (function (eColorShade) {\n eColorShade[\"default\"] = \"default\";\n eColorShade[\"lighter1\"] = \"lighter1\";\n eColorShade[\"lighter2\"] = \"lighter2\";\n eColorShade[\"lighter3\"] = \"lighter3\";\n eColorShade[\"lighter4\"] = \"lighter4\";\n eColorShade[\"darker1\"] = \"darker1\";\n eColorShade[\"darker2\"] = \"darker2\";\n eColorShade[\"darker3\"] = \"darker3\";\n eColorShade[\"darker4\"] = \"darker4\";\n })(exports.eColorShade || (exports.eColorShade = {}));\n (function (eBackgroundColor) {\n eBackgroundColor[\"background\"] = \"background\";\n eBackgroundColor[\"primary\"] = \"primary\";\n eBackgroundColor[\"accent\"] = \"accent\";\n eBackgroundColor[\"warning\"] = \"warning\";\n eBackgroundColor[\"success\"] = \"success\";\n eBackgroundColor[\"input\"] = \"input\";\n eBackgroundColor[\"header\"] = \"header\";\n })(exports.eBackgroundColor || (exports.eBackgroundColor = {}));\n (function (eElevation) {\n eElevation[\"none\"] = \"none\";\n eElevation[\"z1\"] = \"z1\";\n eElevation[\"z2\"] = \"z2\";\n eElevation[\"z3\"] = \"z3\";\n eElevation[\"z4\"] = \"z4\";\n eElevation[\"z5\"] = \"z5\";\n eElevation[\"z6\"] = \"z6\";\n eElevation[\"z7\"] = \"z7\";\n eElevation[\"z8\"] = \"z8\";\n })(exports.eElevation || (exports.eElevation = {}));\n (function (eRuleType) {\n eRuleType[\"value\"] = \"value\";\n eRuleType[\"visibility\"] = \"visibility\";\n eRuleType[\"validation\"] = \"validation\";\n eRuleType[\"pricing\"] = \"pricing\";\n eRuleType[\"message\"] = \"message\";\n eRuleType[\"loaded\"] = \"loaded\";\n eRuleType[\"submit\"] = \"submit\";\n eRuleType[\"pageChanged\"] = \"pageChanged\";\n eRuleType[\"tabChanged\"] = \"tabChanged\";\n eRuleType[\"expanderChanged\"] = \"expanderChanged\";\n eRuleType[\"output\"] = \"output\";\n eRuleType[\"action\"] = \"action\";\n eRuleType[\"function\"] = \"function\";\n eRuleType[\"global\"] = \"global\";\n eRuleType[\"globalEvent\"] = \"globalEvent\";\n eRuleType[\"safeFunction\"] = \"safeFunction\";\n eRuleType[\"naming\"] = \"naming\";\n eRuleType[\"field\"] = \"field\";\n eRuleType[\"button\"] = \"button\";\n eRuleType[\"svgViewer\"] = \"svgViewer\";\n eRuleType[\"dragStart\"] = \"dragStart\";\n eRuleType[\"dragMove\"] = \"dragMove\";\n eRuleType[\"dragEnd\"] = \"dragEnd\";\n eRuleType[\"optionFilter\"] = \"optionFilter\";\n eRuleType[\"nested\"] = \"nested\";\n eRuleType[\"resize\"] = \"resize\";\n eRuleType[\"nestedSetSelected\"] = \"nestedSetSelected\";\n eRuleType[\"keyboard\"] = \"keyboard\";\n eRuleType[\"manufacture\"] = \"manufacture\";\n eRuleType[\"kineticDocumentRules\"] = \"kineticDocumentRules\";\n eRuleType[\"layout\"] = \"layout\";\n eRuleType[\"configuratorAdded\"] = \"configuratorAdded\";\n eRuleType[\"configuratorRemoved\"] = \"configuratorRemoved\";\n eRuleType[\"configuratorCopied\"] = \"configuratorCopied\";\n eRuleType[\"product\"] = \"product\";\n eRuleType[\"workflow\"] = \"workflow\";\n eRuleType[\"beforeBuild\"] = \"beforeBuild\";\n eRuleType[\"globalDefinition\"] = \"globalDefinition\";\n eRuleType[\"quote\"] = \"quote\";\n eRuleType[\"scene\"] = \"scene\";\n eRuleType[\"sceneLoaded\"] = \"sceneLoaded\";\n eRuleType[\"xrEnter\"] = \"xrEnter\";\n eRuleType[\"xrExit\"] = \"xrExit\";\n })(exports.eRuleType || (exports.eRuleType = {}));\n (function (eToolbarPosition) {\n eToolbarPosition[\"hidden\"] = \"hidden\";\n eToolbarPosition[\"topLeft\"] = \"topLeft\";\n eToolbarPosition[\"topRight\"] = \"topRight\";\n eToolbarPosition[\"bottomLeft\"] = \"bottomLeft\";\n eToolbarPosition[\"bottomRight\"] = \"bottomRight\";\n })(exports.eToolbarPosition || (exports.eToolbarPosition = {}));\n (function (eValidationTiming) {\n eValidationTiming[\"always\"] = \"always\";\n eValidationTiming[\"onTouched\"] = \"onTouched\";\n })(exports.eValidationTiming || (exports.eValidationTiming = {}));\n (function (eViewerMode) {\n eViewerMode[\"none\"] = \"none\";\n eViewerMode[\"media\"] = \"media\";\n eViewerMode[\"scene\"] = \"scene\";\n })(exports.eViewerMode || (exports.eViewerMode = {}));\n (function (ePosition) {\n ePosition[\"left\"] = \"left\";\n ePosition[\"right\"] = \"right\";\n })(exports.ePosition || (exports.ePosition = {}));\n (function (eIconStyle) {\n eIconStyle[\"none\"] = \"none\";\n eIconStyle[\"icon\"] = \"icon\";\n eIconStyle[\"media\"] = \"media\";\n })(exports.eIconStyle || (exports.eIconStyle = {}));\n (function (eExportType) {\n eExportType[\"_custom\"] = \"_custom\";\n eExportType[\"pdf\"] = \"pdf\";\n eExportType[\"bmp\"] = \"bmp\";\n eExportType[\"doc\"] = \"doc\";\n eExportType[\"docm\"] = \"docm\";\n eExportType[\"dot\"] = \"dot\";\n eExportType[\"dotm\"] = \"dotm\";\n eExportType[\"dotx\"] = \"dotx\";\n eExportType[\"emf\"] = \"emf\";\n eExportType[\"epub\"] = \"epub\";\n eExportType[\"html\"] = \"html\";\n eExportType[\"jpg\"] = \"jpg\";\n eExportType[\"gif\"] = \"gif\";\n eExportType[\"tiff\"] = \"tiff\";\n eExportType[\"dwf\"] = \"dwf\";\n eExportType[\"edrw\"] = \"edrw\";\n eExportType[\"png\"] = \"png\";\n eExportType[\"odt\"] = \"odt\";\n eExportType[\"rtf\"] = \"rtf\";\n eExportType[\"tif\"] = \"tif\";\n eExportType[\"xaml\"] = \"xaml\";\n eExportType[\"xps\"] = \"xps\";\n eExportType[\"ods\"] = \"ods\";\n eExportType[\"svg\"] = \"svg\";\n eExportType[\"txt\"] = \"txt\";\n eExportType[\"easm\"] = \"easm\";\n eExportType[\"prt\"] = \"prt\";\n eExportType[\"g\"] = \"g\";\n eExportType[\"dwg\"] = \"dwg\";\n eExportType[\"dxf\"] = \"dxf\";\n eExportType[\"sldprt\"] = \"sldprt\";\n eExportType[\"sldasm\"] = \"sldasm\";\n eExportType[\"slddrw\"] = \"slddrw\";\n eExportType[\"sldlfp\"] = \"sldlfp\";\n eExportType[\"x_t\"] = \"x_t\";\n eExportType[\"x_b\"] = \"x_b\";\n eExportType[\"igs\"] = \"igs\";\n eExportType[\"stl\"] = \"stl\";\n eExportType[\"wrl\"] = \"wrl\";\n eExportType[\"u3d\"] = \"u3d\";\n eExportType[\"psd\"] = \"psd\";\n eExportType[\"ai\"] = \"ai\";\n eExportType[\"cgr\"] = \"cgr\";\n eExportType[\"asm\"] = \"asm\";\n eExportType[\"hcg\"] = \"hcg\";\n eExportType[\"hsf\"] = \"hsf\";\n eExportType[\"sat\"] = \"sat\";\n eExportType[\"stp\"] = \"stp\";\n eExportType[\"step\"] = \"step\";\n eExportType[\"vda\"] = \"vda\";\n eExportType[\"neu\"] = \"neu\";\n eExportType[\"iv\"] = \"iv\";\n eExportType[\"slp\"] = \"slp\";\n eExportType[\"eps\"] = \"eps\";\n eExportType[\"catproduct\"] = \"catproduct\";\n eExportType[\"jt\"] = \"jt\";\n eExportType[\"zgl\"] = \"zgl\";\n eExportType[\"xgl\"] = \"xgl\";\n eExportType[\"csv\"] = \"csv\";\n eExportType[\"xml\"] = \"xml\";\n })(exports.eExportType || (exports.eExportType = {}));\n (function (eHotspotSource) {\n eHotspotSource[\"none\"] = \"none\";\n eHotspotSource[\"text\"] = \"text\";\n eHotspotSource[\"media\"] = \"media\";\n eHotspotSource[\"element\"] = \"element\";\n })(exports.eHotspotSource || (exports.eHotspotSource = {}));\n (function (eHotspotAttach) {\n eHotspotAttach[\"topLeft\"] = \"topLeft\";\n eHotspotAttach[\"top\"] = \"top\";\n eHotspotAttach[\"topRight\"] = \"topRight\";\n eHotspotAttach[\"left\"] = \"left\";\n eHotspotAttach[\"center\"] = \"center\";\n eHotspotAttach[\"right\"] = \"right\";\n eHotspotAttach[\"bottomLeft\"] = \"bottomLeft\";\n eHotspotAttach[\"bottom\"] = \"bottom\";\n eHotspotAttach[\"bottomRight\"] = \"bottomRight\";\n })(exports.eHotspotAttach || (exports.eHotspotAttach = {}));\n (function (eHotspotPosition) {\n eHotspotPosition[\"manual\"] = \"manual\";\n eHotspotPosition[\"target\"] = \"target\";\n })(exports.eHotspotPosition || (exports.eHotspotPosition = {}));\n (function (eHotspotShape) {\n eHotspotShape[\"circle\"] = \"circle\";\n eHotspotShape[\"circleWithText\"] = \"circleWithText\";\n eHotspotShape[\"image\"] = \"image\";\n eHotspotShape[\"mesh\"] = \"mesh\";\n eHotspotShape[\"text\"] = \"text\";\n })(exports.eHotspotShape || (exports.eHotspotShape = {}));\n (function (eAnimationEasing) {\n eAnimationEasing[\"linear\"] = \"linear\";\n eAnimationEasing[\"easeInQuad\"] = \"easeInQuad\";\n eAnimationEasing[\"easeOutQuad\"] = \"easeOutQuad\";\n eAnimationEasing[\"easeInOutQuad\"] = \"easeInOutQuad\";\n eAnimationEasing[\"easeInCubic\"] = \"easeInCubic\";\n eAnimationEasing[\"easeOutCubic\"] = \"easeOutCubic\";\n eAnimationEasing[\"easeInOutCubic\"] = \"easeInOutCubic\";\n eAnimationEasing[\"easeInQuart\"] = \"easeInQuart\";\n eAnimationEasing[\"easeOutQuart\"] = \"easeOutQuart\";\n eAnimationEasing[\"easeInOutQuart\"] = \"easeInOutQuart\";\n eAnimationEasing[\"easeInQuint\"] = \"easeInQuint\";\n eAnimationEasing[\"easeOutQuint\"] = \"easeOutQuint\";\n eAnimationEasing[\"easeInOutQuint\"] = \"easeInOutQuint\";\n eAnimationEasing[\"easeInSine\"] = \"easeInSine\";\n eAnimationEasing[\"easeOutSine\"] = \"easeOutSine\";\n eAnimationEasing[\"easeInOutSine\"] = \"easeInOutSine\";\n eAnimationEasing[\"easeInExpo\"] = \"easeInExpo\";\n eAnimationEasing[\"easeOutExpo\"] = \"easeOutExpo\";\n eAnimationEasing[\"easeInOutExpo\"] = \"easeInOutExpo\";\n eAnimationEasing[\"easeInCirc\"] = \"easeInCirc\";\n eAnimationEasing[\"easeOutCirc\"] = \"easeOutCirc\";\n eAnimationEasing[\"easeInOutCirc\"] = \"easeInOutCirc\";\n eAnimationEasing[\"easeInElastic\"] = \"easeInElastic\";\n eAnimationEasing[\"easeOutElastic\"] = \"easeOutElastic\";\n eAnimationEasing[\"easeInOutElastic\"] = \"easeInOutElastic\";\n eAnimationEasing[\"easeInBack\"] = \"easeInBack\";\n eAnimationEasing[\"easeOutBack\"] = \"easeOutBack\";\n eAnimationEasing[\"easeInOutBack\"] = \"easeInOutBack\";\n eAnimationEasing[\"easeInBounce\"] = \"easeInBounce\";\n eAnimationEasing[\"easeOutBounce\"] = \"easeOutBounce\";\n eAnimationEasing[\"easeInOutBounce\"] = \"easeInOutBounce\";\n })(exports.eAnimationEasing || (exports.eAnimationEasing = {}));\n (function (eQueryMode) {\n eQueryMode[\"none\"] = \"none\";\n eQueryMode[\"table\"] = \"table\";\n eQueryMode[\"database\"] = \"database\";\n eQueryMode[\"array\"] = \"array\";\n eQueryMode[\"optionFilter\"] = \"optionFilter\";\n eQueryMode[\"parentOptionFilter\"] = \"parentOptionFilter\";\n })(exports.eQueryMode || (exports.eQueryMode = {}));\n (function (eOptionFilterSource) {\n eOptionFilterSource[\"table\"] = \"table\";\n eOptionFilterSource[\"database\"] = \"database\";\n eOptionFilterSource[\"query\"] = \"query\";\n eOptionFilterSource[\"safeFunction\"] = \"safeFunction\";\n eOptionFilterSource[\"optionFilter\"] = \"optionFilter\";\n })(exports.eOptionFilterSource || (exports.eOptionFilterSource = {}));\n (function (eOutputType) {\n eOutputType[\"none\"] = \"none\";\n eOutputType[\"word\"] = \"word\";\n eOutputType[\"excel\"] = \"excel\";\n eOutputType[\"image\"] = \"image\";\n eOutputType[\"solidworks\"] = \"solidworks\";\n eOutputType[\"inventor\"] = \"inventor\";\n eOutputType[\"creo\"] = \"creo\";\n eOutputType[\"creo3\"] = \"creo3\";\n eOutputType[\"cadDrawing\"] = \"cadDrawing\";\n eOutputType[\"bom\"] = \"bom\";\n eOutputType[\"sceneRender\"] = \"sceneRender\";\n eOutputType[\"pdf\"] = \"pdf\";\n eOutputType[\"salesforce\"] = \"salesforce\";\n eOutputType[\"autoCad\"] = \"autoCad\";\n eOutputType[\"zip\"] = \"zip\";\n eOutputType[\"svg\"] = \"svg\";\n eOutputType[\"text\"] = \"text\";\n })(exports.eOutputType || (exports.eOutputType = {}));\n (function (eOutputFieldType) {\n eOutputFieldType[\"wordText\"] = \"wordText\";\n eOutputFieldType[\"wordContainer\"] = \"wordContainer\";\n eOutputFieldType[\"wordImage\"] = \"wordImage\";\n eOutputFieldType[\"wordList\"] = \"wordList\";\n eOutputFieldType[\"excelSheet\"] = \"excelSheet\";\n eOutputFieldType[\"excelCell\"] = \"excelCell\";\n eOutputFieldType[\"excelImage\"] = \"excelImage\";\n eOutputFieldType[\"excelTable\"] = \"excelTable\";\n eOutputFieldType[\"excelChart\"] = \"excelChart\";\n eOutputFieldType[\"cadReplaceComponent\"] = \"cadReplaceComponent\";\n eOutputFieldType[\"cadAngleMate\"] = \"cadAngleMate\";\n eOutputFieldType[\"cadCoincidentMate\"] = \"cadCoincidentMate\";\n eOutputFieldType[\"cadCoordinateSystemMate\"] = \"cadCoordinateSystemMate\";\n eOutputFieldType[\"cadDistanceMate\"] = \"cadDistanceMate\";\n eOutputFieldType[\"cadPositionConstraint\"] = \"cadPositionConstraint\";\n eOutputFieldType[\"cadDimension\"] = \"cadDimension\";\n eOutputFieldType[\"cadFeature\"] = \"cadFeature\";\n eOutputFieldType[\"cadLibFeature\"] = \"cadLibFeature\";\n eOutputFieldType[\"cadCustomProperty\"] = \"cadCustomProperty\";\n eOutputFieldType[\"cadComponent\"] = \"cadComponent\";\n eOutputFieldType[\"cadDrawingView\"] = \"cadDrawingView\";\n eOutputFieldType[\"cadDrawingSheet\"] = \"cadDrawingSheet\";\n eOutputFieldType[\"cadDrawingAnnotation\"] = \"cadDrawingAnnotation\";\n eOutputFieldType[\"cadDynamicDrawingDimension\"] = \"cadDynamicDrawingDimension\";\n eOutputFieldType[\"cadDynamicDrawingAnnotation\"] = \"cadDynamicDrawingAnnotation\";\n eOutputFieldType[\"cadDynamicComponent\"] = \"cadDynamicComponent\";\n eOutputFieldType[\"cadNestedComponent\"] = \"cadNestedComponent\";\n eOutputFieldType[\"cadScaleFeature\"] = \"cadScaleFeature\";\n eOutputFieldType[\"cadAnnotation\"] = \"cadAnnotation\";\n eOutputFieldType[\"cadText\"] = \"cadText\";\n eOutputFieldType[\"cadParameter\"] = \"cadParameter\";\n eOutputFieldType[\"cadRepresentation\"] = \"cadRepresentation\";\n eOutputFieldType[\"cadPoint\"] = \"cadPoint\";\n eOutputFieldType[\"cadLayer\"] = \"cadLayer\";\n eOutputFieldType[\"bomMapping\"] = \"bomMapping\";\n eOutputFieldType[\"salesForceObject\"] = \"salesForceObject\";\n eOutputFieldType[\"cadDrawingDimension\"] = \"cadDrawingDimension\";\n eOutputFieldType[\"pdfSection\"] = \"pdfSection\";\n eOutputFieldType[\"cadLibReference\"] = \"cadLibReference\";\n eOutputFieldType[\"cadLibDimension\"] = \"cadLibDimension\";\n eOutputFieldType[\"cadBlock\"] = \"cadBlock\";\n eOutputFieldType[\"cadBlockArray\"] = \"cadBlockArray\";\n eOutputFieldType[\"zipSection\"] = \"zipSection\";\n })(exports.eOutputFieldType || (exports.eOutputFieldType = {}));\n (function (eSingleOptionBehavior) {\n eSingleOptionBehavior[\"nothing\"] = \"nothing\";\n eSingleOptionBehavior[\"disable\"] = \"disable\";\n eSingleOptionBehavior[\"hide\"] = \"hide\";\n })(exports.eSingleOptionBehavior || (exports.eSingleOptionBehavior = {}));\n (function (eConfiguratorImageSource) {\n eConfiguratorImageSource[\"none\"] = \"none\";\n eConfiguratorImageSource[\"media\"] = \"media\";\n eConfiguratorImageSource[\"scene\"] = \"scene\";\n })(exports.eConfiguratorImageSource || (exports.eConfiguratorImageSource = {}));\n (function (eTextColor) {\n eTextColor[\"normal\"] = \"normal\";\n eTextColor[\"header\"] = \"header\";\n eTextColor[\"primary\"] = \"primary\";\n eTextColor[\"accent\"] = \"accent\";\n eTextColor[\"error\"] = \"error\";\n eTextColor[\"success\"] = \"success\";\n })(exports.eTextColor || (exports.eTextColor = {}));\n (function (eConfiguratorEntityType) {\n eConfiguratorEntityType[\"product\"] = \"product\";\n eConfiguratorEntityType[\"quoteHeader\"] = \"quoteHeader\";\n })(exports.eConfiguratorEntityType || (exports.eConfiguratorEntityType = {}));\n (function (eBackground) {\n eBackground[\"color\"] = \"color\";\n eBackground[\"transparent\"] = \"transparent\";\n eBackground[\"environment\"] = \"environment\";\n })(exports.eBackground || (exports.eBackground = {}));\n (function (eSideOrientation) {\n eSideOrientation[\"frontSide\"] = \"frontSide\";\n eSideOrientation[\"backSide\"] = \"backSide\";\n eSideOrientation[\"doubleSide\"] = \"doubleSide\";\n })(exports.eSideOrientation || (exports.eSideOrientation = {}));\n (function (eUvMode) {\n eUvMode[\"planar\"] = \"planar\";\n eUvMode[\"box\"] = \"box\";\n eUvMode[\"cylindrical\"] = \"cylindrical\";\n eUvMode[\"spherical\"] = \"spherical\";\n eUvMode[\"useExisting\"] = \"useExisting\";\n })(exports.eUvMode || (exports.eUvMode = {}));\n (function (eMaterialViewMode) {\n eMaterialViewMode[\"shaded\"] = \"shaded\";\n eMaterialViewMode[\"edges\"] = \"edges\";\n eMaterialViewMode[\"wireframe\"] = \"wireframe\";\n })(exports.eMaterialViewMode || (exports.eMaterialViewMode = {}));\n (function (eMaterialLocation) {\n eMaterialLocation[\"local\"] = \"local\";\n eMaterialLocation[\"global\"] = \"global\";\n eMaterialLocation[\"library\"] = \"library\";\n })(exports.eMaterialLocation || (exports.eMaterialLocation = {}));\n (function (eAlphaMode) {\n eAlphaMode[\"disable\"] = \"disable\";\n eAlphaMode[\"add\"] = \"add\";\n eAlphaMode[\"combine\"] = \"combine\";\n eAlphaMode[\"subtract\"] = \"subtract\";\n eAlphaMode[\"multiply\"] = \"multiply\";\n })(exports.eAlphaMode || (exports.eAlphaMode = {}));\n (function (eViewpointType) {\n eViewpointType[\"orbit\"] = \"orbit\";\n eViewpointType[\"firstPerson\"] = \"firstPerson\";\n eViewpointType[\"overhead\"] = \"overhead\";\n })(exports.eViewpointType || (exports.eViewpointType = {}));\n (function (eViewpointProjection) {\n eViewpointProjection[\"perspective\"] = \"perspective\";\n eViewpointProjection[\"orthographic\"] = \"orthographic\";\n })(exports.eViewpointProjection || (exports.eViewpointProjection = {}));\n (function (eViewpointTargetMode) {\n eViewpointTargetMode[\"rotation\"] = \"rotation\";\n eViewpointTargetMode[\"point\"] = \"point\";\n eViewpointTargetMode[\"mesh\"] = \"mesh\";\n })(exports.eViewpointTargetMode || (exports.eViewpointTargetMode = {}));\n (function (eConnectorPositionMode) {\n eConnectorPositionMode[\"boundingBox\"] = \"boundingBox\";\n eConnectorPositionMode[\"absolute\"] = \"absolute\";\n eConnectorPositionMode[\"moveAlongSketch\"] = \"moveAlongSketch\";\n })(exports.eConnectorPositionMode || (exports.eConnectorPositionMode = {}));\n (function (eDragMode) {\n eDragMode[\"plane\"] = \"plane\";\n eDragMode[\"free\"] = \"free\";\n eDragMode[\"surface\"] = \"surface\";\n })(exports.eDragMode || (exports.eDragMode = {}));\n (function (eConnectionMode) {\n eConnectionMode[\"none\"] = \"none\";\n eConnectionMode[\"world\"] = \"world\";\n eConnectionMode[\"screen\"] = \"screen\";\n })(exports.eConnectionMode || (exports.eConnectionMode = {}));\n (function (eEasing) {\n eEasing[\"linear\"] = \"linear\";\n eEasing[\"quadraticIn\"] = \"quadraticIn\";\n eEasing[\"quadraticOut\"] = \"quadraticOut\";\n eEasing[\"quadraticInOut\"] = \"quadraticInOut\";\n eEasing[\"cubicIn\"] = \"cubicIn\";\n eEasing[\"cubicOut\"] = \"cubicOut\";\n eEasing[\"cubicInOut\"] = \"cubicInOut\";\n eEasing[\"quarticIn\"] = \"quarticIn\";\n eEasing[\"quarticOut\"] = \"quarticOut\";\n eEasing[\"quarticInOut\"] = \"quarticInOut\";\n eEasing[\"quinticIn\"] = \"quinticIn\";\n eEasing[\"quinticOut\"] = \"quinticOut\";\n eEasing[\"quinticInOut\"] = \"quinticInOut\";\n eEasing[\"sinusoidalIn\"] = \"sinusoidalIn\";\n eEasing[\"sinusoidalOut\"] = \"sinusoidalOut\";\n eEasing[\"sinusoidalInOut\"] = \"sinusoidalInOut\";\n eEasing[\"exponentialIn\"] = \"exponentialIn\";\n eEasing[\"exponentialOut\"] = \"exponentialOut\";\n eEasing[\"exponentialInOut\"] = \"exponentialInOut\";\n eEasing[\"circularIn\"] = \"circularIn\";\n eEasing[\"circularOut\"] = \"circularOut\";\n eEasing[\"circularInOut\"] = \"circularInOut\";\n eEasing[\"elasticIn\"] = \"elasticIn\";\n eEasing[\"elasticOut\"] = \"elasticOut\";\n eEasing[\"elasticInOut\"] = \"elasticInOut\";\n eEasing[\"backIn\"] = \"backIn\";\n eEasing[\"backOut\"] = \"backOut\";\n eEasing[\"backInOut\"] = \"backInOut\";\n eEasing[\"bounceIn\"] = \"bounceIn\";\n eEasing[\"bounceOut\"] = \"bounceOut\";\n eEasing[\"bounceInOut\"] = \"bounceInOut\";\n })(exports.eEasing || (exports.eEasing = {}));\n (function (eCylinderCap) {\n eCylinderCap[\"none\"] = \"none\";\n eCylinderCap[\"start\"] = \"start\";\n eCylinderCap[\"end\"] = \"end\";\n eCylinderCap[\"both\"] = \"both\";\n })(exports.eCylinderCap || (exports.eCylinderCap = {}));\n (function (eJoinType) {\n eJoinType[\"union\"] = \"union\";\n eJoinType[\"intersect\"] = \"intersect\";\n eJoinType[\"cut\"] = \"cut\";\n })(exports.eJoinType || (exports.eJoinType = {}));\n (function (eShadowQuality) {\n eShadowQuality[\"low\"] = \"low\";\n eShadowQuality[\"medium\"] = \"medium\";\n eShadowQuality[\"high\"] = \"high\";\n })(exports.eShadowQuality || (exports.eShadowQuality = {}));\n (function (eShadowResolution) {\n eShadowResolution[\"low\"] = \"low\";\n eShadowResolution[\"medium\"] = \"medium\";\n eShadowResolution[\"high\"] = \"high\";\n })(exports.eShadowResolution || (exports.eShadowResolution = {}));\n (function (eShadowFilter) {\n eShadowFilter[\"none\"] = \"none\";\n eShadowFilter[\"simple\"] = \"simple\";\n eShadowFilter[\"advanced\"] = \"advanced\";\n })(exports.eShadowFilter || (exports.eShadowFilter = {}));\n (function (eMaterialWorkflow) {\n eMaterialWorkflow[\"metallicRoughness\"] = \"metallicRoughness\";\n eMaterialWorkflow[\"specularGlossiness\"] = \"specularGlossiness\";\n })(exports.eMaterialWorkflow || (exports.eMaterialWorkflow = {}));\n (function (eFeatureCenter) {\n eFeatureCenter[\"barycenter\"] = \"barycenter\";\n eFeatureCenter[\"meshPivotPoint\"] = \"meshPivotPoint\";\n })(exports.eFeatureCenter || (exports.eFeatureCenter = {}));\n (function (eJobStatus) {\n eJobStatus[\"none\"] = \"none\";\n eJobStatus[\"waiting\"] = \"waiting\";\n eJobStatus[\"queued\"] = \"queued\";\n eJobStatus[\"working\"] = \"working\";\n eJobStatus[\"complete\"] = \"complete\";\n eJobStatus[\"failed\"] = \"failed\";\n })(exports.eJobStatus || (exports.eJobStatus = {}));\n (function (eJobType) {\n eJobType[\"build\"] = \"build\";\n eJobType[\"render\"] = \"render\";\n eJobType[\"notification\"] = \"notification\";\n eJobType[\"upsertProductsToSfdc\"] = \"upsertProductsToSfdc\";\n eJobType[\"pullSfdcProducts\"] = \"pullSfdcProducts\";\n eJobType[\"submitFromSfdcCpq\"] = \"submitFromSfdcCpq\";\n eJobType[\"completeBuildState\"] = \"completeBuildState\";\n eJobType[\"cleanDb\"] = \"cleanDb\";\n eJobType[\"deployment\"] = \"deployment\";\n eJobType[\"sceneImport\"] = \"sceneImport\";\n eJobType[\"sceneExport\"] = \"sceneExport\";\n eJobType[\"sceneConvert\"] = \"sceneConvert\";\n eJobType[\"completeQuoteProductBuild\"] = \"completeQuoteProductBuild\";\n eJobType[\"configuratorExport\"] = \"configuratorExport\";\n eJobType[\"configuratorImport\"] = \"configuratorImport\";\n })(exports.eJobType || (exports.eJobType = {}));\n (function (eEnvironment) {\n eEnvironment[\"prod\"] = \"prod\";\n eEnvironment[\"test\"] = \"test\";\n eEnvironment[\"dev\"] = \"dev\";\n })(exports.eEnvironment || (exports.eEnvironment = {}));\n (function (eImportType) {\n eImportType[\"external\"] = \"external\";\n eImportType[\"kb3d\"] = \"kb3d\";\n })(exports.eImportType || (exports.eImportType = {}));\n (function (eQueueMessageType) {\n eQueueMessageType[\"builder\"] = \"builder\";\n eQueueMessageType[\"cleanDb\"] = \"cleanDb\";\n eQueueMessageType[\"completeBuildState\"] = \"completeBuildState\";\n eQueueMessageType[\"notification\"] = \"notification\";\n eQueueMessageType[\"render\"] = \"render\";\n eQueueMessageType[\"pullSfdcProducts\"] = \"pullSfdcProducts\";\n eQueueMessageType[\"upsertProductsToSfdc\"] = \"upsertProductsToSfdc\";\n eQueueMessageType[\"submitFromSfdcCpq\"] = \"submitFromSfdcCpq\";\n eQueueMessageType[\"deployment\"] = \"deployment\";\n eQueueMessageType[\"completeQuoteProductBuild\"] = \"completeQuoteProductBuild\";\n eQueueMessageType[\"sceneImport\"] = \"sceneImport\";\n eQueueMessageType[\"sceneExport\"] = \"sceneExport\";\n eQueueMessageType[\"sceneConvert\"] = \"sceneConvert\";\n })(exports.eQueueMessageType || (exports.eQueueMessageType = {}));\n (function (eMateType) {\n eMateType[\"fastened\"] = \"fastened\";\n eMateType[\"revolute\"] = \"revolute\";\n eMateType[\"slider\"] = \"slider\";\n eMateType[\"planar\"] = \"planar\";\n eMateType[\"cylindrical\"] = \"cylindrical\";\n eMateType[\"ball\"] = \"ball\";\n eMateType[\"parallel\"] = \"parallel\";\n })(exports.eMateType || (exports.eMateType = {}));\n (function (eValidationType) {\n eValidationType[\"error\"] = \"error\";\n eValidationType[\"warning\"] = \"warning\";\n eValidationType[\"info\"] = \"info\";\n })(exports.eValidationType || (exports.eValidationType = {}));\n (function (eValidationSource) {\n eValidationSource[\"snap\"] = \"snap\";\n eValidationSource[\"configurator\"] = \"configurator\";\n eValidationSource[\"scene\"] = \"scene\";\n })(exports.eValidationSource || (exports.eValidationSource = {}));\n (function (eTextureChannel) {\n eTextureChannel[\"emissive\"] = \"emissive\";\n eTextureChannel[\"albedo\"] = \"albedo\";\n eTextureChannel[\"ambient\"] = \"ambient\";\n eTextureChannel[\"opacity\"] = \"opacity\";\n eTextureChannel[\"reflection\"] = \"reflection\";\n eTextureChannel[\"specular\"] = \"specular\";\n eTextureChannel[\"metallic\"] = \"metallic\";\n eTextureChannel[\"roughness\"] = \"roughness\";\n eTextureChannel[\"glossiness\"] = \"glossiness\";\n eTextureChannel[\"normal\"] = \"normal\";\n eTextureChannel[\"ambientOcclusion\"] = \"ambientOcclusion\";\n eTextureChannel[\"anisotropyTangent\"] = \"anisotropyTangent\";\n eTextureChannel[\"subsurfaceThickness\"] = \"subsurfaceThickness\";\n eTextureChannel[\"clearCoatNormal\"] = \"clearCoatNormal\";\n })(exports.eTextureChannel || (exports.eTextureChannel = {}));\n (function (eTextureHorizontalAlign) {\n eTextureHorizontalAlign[\"left\"] = \"left\";\n eTextureHorizontalAlign[\"center\"] = \"center\";\n eTextureHorizontalAlign[\"right\"] = \"right\";\n })(exports.eTextureHorizontalAlign || (exports.eTextureHorizontalAlign = {}));\n (function (eTextureVerticalAlign) {\n eTextureVerticalAlign[\"top\"] = \"top\";\n eTextureVerticalAlign[\"middle\"] = \"middle\";\n eTextureVerticalAlign[\"bottom\"] = \"bottom\";\n })(exports.eTextureVerticalAlign || (exports.eTextureVerticalAlign = {}));\n (function (eTextureFit) {\n eTextureFit[\"none\"] = \"none\";\n eTextureFit[\"stretch\"] = \"stretch\";\n eTextureFit[\"contain\"] = \"contain\";\n })(exports.eTextureFit || (exports.eTextureFit = {}));\n (function (eTextureBlendMode) {\n eTextureBlendMode[\"normal\"] = \"normal\";\n eTextureBlendMode[\"multiply\"] = \"multiply\";\n eTextureBlendMode[\"screen\"] = \"screen\";\n eTextureBlendMode[\"overlay\"] = \"overlay\";\n eTextureBlendMode[\"darken\"] = \"darken\";\n eTextureBlendMode[\"lighten\"] = \"lighten\";\n eTextureBlendMode[\"hue\"] = \"hue\";\n eTextureBlendMode[\"saturation\"] = \"saturation\";\n eTextureBlendMode[\"color\"] = \"color\";\n eTextureBlendMode[\"luminosity\"] = \"luminosity\";\n eTextureBlendMode[\"difference\"] = \"difference\";\n eTextureBlendMode[\"mask\"] = \"mask\";\n eTextureBlendMode[\"vector\"] = \"vector\";\n })(exports.eTextureBlendMode || (exports.eTextureBlendMode = {}));\n (function (eTextureWrapAddressMode) {\n eTextureWrapAddressMode[\"repeat\"] = \"repeat\";\n eTextureWrapAddressMode[\"clamp\"] = \"clamp\";\n })(exports.eTextureWrapAddressMode || (exports.eTextureWrapAddressMode = {}));\n (function (eAnnotationLineStyle) {\n eAnnotationLineStyle[\"solid\"] = \"solid\";\n eAnnotationLineStyle[\"dashed\"] = \"dashed\";\n eAnnotationLineStyle[\"dotted\"] = \"dotted\";\n eAnnotationLineStyle[\"none\"] = \"none\";\n })(exports.eAnnotationLineStyle || (exports.eAnnotationLineStyle = {}));\n (function (eDimensionLineCapStyle) {\n eDimensionLineCapStyle[\"none\"] = \"none\";\n eDimensionLineCapStyle[\"arrow\"] = \"arrow\";\n eDimensionLineCapStyle[\"line\"] = \"line\";\n })(exports.eDimensionLineCapStyle || (exports.eDimensionLineCapStyle = {}));\n (function (eDimensionAxis) {\n eDimensionAxis[\"free\"] = \"free\";\n eDimensionAxis[\"x\"] = \"x\";\n eDimensionAxis[\"y\"] = \"y\";\n eDimensionAxis[\"z\"] = \"z\";\n })(exports.eDimensionAxis || (exports.eDimensionAxis = {}));\n (function (eLoadingExperience) {\n eLoadingExperience[\"none\"] = \"none\";\n eLoadingExperience[\"fade\"] = \"fade\";\n eLoadingExperience[\"spinner\"] = \"spinner\";\n eLoadingExperience[\"image\"] = \"image\";\n })(exports.eLoadingExperience || (exports.eLoadingExperience = {}));\n (function (eReflectionType) {\n eReflectionType[\"plane\"] = \"plane\";\n eReflectionType[\"probe\"] = \"probe\";\n })(exports.eReflectionType || (exports.eReflectionType = {}));\n (function (eRenderMode) {\n eRenderMode[\"shaded\"] = \"shaded\";\n eRenderMode[\"wireframe\"] = \"wireframe\";\n eRenderMode[\"edge\"] = \"edge\";\n eRenderMode[\"hiddenEdges\"] = \"hiddenEdges\";\n })(exports.eRenderMode || (exports.eRenderMode = {}));\n (function (eTextureSamplingMode) {\n eTextureSamplingMode[\"nearest\"] = \"nearest\";\n eTextureSamplingMode[\"bilinear\"] = \"bilinear\";\n eTextureSamplingMode[\"trilinear\"] = \"trilinear\";\n })(exports.eTextureSamplingMode || (exports.eTextureSamplingMode = {}));\n (function (eAxis) {\n eAxis[\"x\"] = \"x\";\n eAxis[\"y\"] = \"y\";\n eAxis[\"z\"] = \"z\";\n })(exports.eAxis || (exports.eAxis = {}));\n (function (eSketchPathType) {\n eSketchPathType[\"points\"] = \"points\";\n eSketchPathType[\"arcThrough3Points\"] = \"arcThrough3Points\";\n eSketchPathType[\"centerRadiusCircle\"] = \"centerRadiusCircle\";\n eSketchPathType[\"catmullRom\"] = \"catmullRom\";\n eSketchPathType[\"cubicBezier\"] = \"cubicBezier\";\n eSketchPathType[\"quadraticBezier\"] = \"quadraticBezier\";\n eSketchPathType[\"hermite\"] = \"hermite\";\n })(exports.eSketchPathType || (exports.eSketchPathType = {}));\n (function (eFilterControl) {\n eFilterControl[\"none\"] = \"none\";\n eFilterControl[\"text\"] = \"text\";\n eFilterControl[\"select\"] = \"select\";\n eFilterControl[\"multiSelect\"] = \"multiSelect\";\n eFilterControl[\"dateRange\"] = \"dateRange\";\n eFilterControl[\"numberRange\"] = \"numberRange\";\n eFilterControl[\"suggest\"] = \"suggest\";\n eFilterControl[\"checkbox\"] = \"checkbox\";\n })(exports.eFilterControl || (exports.eFilterControl = {}));\n (function (eFilterSource) {\n eFilterSource[\"none\"] = \"none\";\n eFilterSource[\"enum\"] = \"enum\";\n eFilterSource[\"properties\"] = \"properties\";\n eFilterSource[\"users\"] = \"users\";\n eFilterSource[\"states\"] = \"states\";\n eFilterSource[\"configurators\"] = \"configurators\";\n eFilterSource[\"fields\"] = \"fields\";\n eFilterSource[\"customers\"] = \"customers\";\n eFilterSource[\"roles\"] = \"roles\";\n eFilterSource[\"productSorts\"] = \"productSorts\";\n eFilterSource[\"manufacturers\"] = \"manufacturers\";\n eFilterSource[\"attributes\"] = \"attributes\";\n eFilterSource[\"suggestContacts\"] = \"suggestContacts\";\n eFilterSource[\"suggestCustomers\"] = \"suggestCustomers\";\n eFilterSource[\"suggestQuotes\"] = \"suggestQuotes\";\n eFilterSource[\"suggestProducts\"] = \"suggestProducts\";\n eFilterSource[\"headerFields\"] = \"headerFields\";\n })(exports.eFilterSource || (exports.eFilterSource = {}));\n (function (eFilterType) {\n eFilterType[\"property\"] = \"property\";\n eFilterType[\"fieldValue\"] = \"fieldValue\";\n eFilterType[\"sort\"] = \"sort\";\n eFilterType[\"attribute\"] = \"attribute\";\n eFilterType[\"headerValue\"] = \"headerValue\";\n })(exports.eFilterType || (exports.eFilterType = {}));\n (function (eFieldType) {\n eFieldType[\"text\"] = \"text\";\n eFieldType[\"number\"] = \"number\";\n eFieldType[\"boolean\"] = \"boolean\";\n eFieldType[\"color\"] = \"color\";\n eFieldType[\"date\"] = \"date\";\n eFieldType[\"upload\"] = \"upload\";\n eFieldType[\"textArray\"] = \"textArray\";\n eFieldType[\"numberArray\"] = \"numberArray\";\n eFieldType[\"colorArray\"] = \"colorArray\";\n })(exports.eFieldType || (exports.eFieldType = {}));\n\n var _kb3dEnums = /*#__PURE__*/Object.freeze({\n __proto__: null,\n get eContainerItemLayout () { return exports.eContainerItemLayout; },\n get eContainerChildAlignment () { return exports.eContainerChildAlignment; },\n get eContainerItemAlignment () { return exports.eContainerItemAlignment; },\n get eContainerItemJustify () { return exports.eContainerItemJustify; },\n get eScroll () { return exports.eScroll; },\n get eRelativeSize () { return exports.eRelativeSize; },\n get ePadding () { return exports.ePadding; },\n get eColorShade () { return exports.eColorShade; },\n get eBackgroundColor () { return exports.eBackgroundColor; },\n get eElevation () { return exports.eElevation; },\n get eRuleType () { return exports.eRuleType; },\n get eToolbarPosition () { return exports.eToolbarPosition; },\n get eValidationTiming () { return exports.eValidationTiming; },\n get eViewerMode () { return exports.eViewerMode; },\n get ePosition () { return exports.ePosition; },\n get eIconStyle () { return exports.eIconStyle; },\n get eExportType () { return exports.eExportType; },\n get eHotspotSource () { return exports.eHotspotSource; },\n get eHotspotAttach () { return exports.eHotspotAttach; },\n get eHotspotPosition () { return exports.eHotspotPosition; },\n get eHotspotShape () { return exports.eHotspotShape; },\n get eAnimationEasing () { return exports.eAnimationEasing; },\n get eQueryMode () { return exports.eQueryMode; },\n get eOptionFilterSource () { return exports.eOptionFilterSource; },\n get eOutputType () { return exports.eOutputType; },\n get eOutputFieldType () { return exports.eOutputFieldType; },\n get eSingleOptionBehavior () { return exports.eSingleOptionBehavior; },\n get eConfiguratorImageSource () { return exports.eConfiguratorImageSource; },\n get eTextColor () { return exports.eTextColor; },\n get eConfiguratorEntityType () { return exports.eConfiguratorEntityType; },\n get eBackground () { return exports.eBackground; },\n get eSideOrientation () { return exports.eSideOrientation; },\n get eUvMode () { return exports.eUvMode; },\n get eMaterialViewMode () { return exports.eMaterialViewMode; },\n get eMaterialLocation () { return exports.eMaterialLocation; },\n get eAlphaMode () { return exports.eAlphaMode; },\n get eViewpointType () { return exports.eViewpointType; },\n get eViewpointProjection () { return exports.eViewpointProjection; },\n get eViewpointTargetMode () { return exports.eViewpointTargetMode; },\n get eConnectorPositionMode () { return exports.eConnectorPositionMode; },\n get eDragMode () { return exports.eDragMode; },\n get eConnectionMode () { return exports.eConnectionMode; },\n get eEasing () { return exports.eEasing; },\n get eCylinderCap () { return exports.eCylinderCap; },\n get eJoinType () { return exports.eJoinType; },\n get eShadowQuality () { return exports.eShadowQuality; },\n get eShadowResolution () { return exports.eShadowResolution; },\n get eShadowFilter () { return exports.eShadowFilter; },\n get eMaterialWorkflow () { return exports.eMaterialWorkflow; },\n get eFeatureCenter () { return exports.eFeatureCenter; },\n get eJobStatus () { return exports.eJobStatus; },\n get eJobType () { return exports.eJobType; },\n get eEnvironment () { return exports.eEnvironment; },\n get eImportType () { return exports.eImportType; },\n get eQueueMessageType () { return exports.eQueueMessageType; },\n get eMateType () { return exports.eMateType; },\n get eValidationType () { return exports.eValidationType; },\n get eValidationSource () { return exports.eValidationSource; },\n get eTextureChannel () { return exports.eTextureChannel; },\n get eTextureHorizontalAlign () { return exports.eTextureHorizontalAlign; },\n get eTextureVerticalAlign () { return exports.eTextureVerticalAlign; },\n get eTextureFit () { return exports.eTextureFit; },\n get eTextureBlendMode () { return exports.eTextureBlendMode; },\n get eTextureWrapAddressMode () { return exports.eTextureWrapAddressMode; },\n get eAnnotationLineStyle () { return exports.eAnnotationLineStyle; },\n get eDimensionLineCapStyle () { return exports.eDimensionLineCapStyle; },\n get eDimensionAxis () { return exports.eDimensionAxis; },\n get eLoadingExperience () { return exports.eLoadingExperience; },\n get eReflectionType () { return exports.eReflectionType; },\n get eRenderMode () { return exports.eRenderMode; },\n get eTextureSamplingMode () { return exports.eTextureSamplingMode; },\n get eAxis () { return exports.eAxis; },\n get eSketchPathType () { return exports.eSketchPathType; },\n get eFilterControl () { return exports.eFilterControl; },\n get eFilterSource () { return exports.eFilterSource; },\n get eFilterType () { return exports.eFilterType; },\n get eFieldType () { return exports.eFieldType; }\n });\n\n exports.SketchControlPoint = class SketchControlPoint extends exports.BaseConnector {\n constructor() {\n super(...arguments);\n this.enabled = true; // non-configurable\n this.positionMode = exports.eConnectorPositionMode.absolute;\n }\n getSketch() {\n var _a;\n return (_a = this._parent) === null || _a === void 0 ? void 0 : _a._parent;\n }\n getSpaceParent() {\n return this.getSketch();\n }\n getAncestors() {\n return super.getAncestors();\n }\n };\n exports.SketchControlPoint = __decorate([\n Kb3dModel({\n token: Token.SketchControlPoint,\n })\n ], exports.SketchControlPoint);\n\n exports.UvMapFeature = class UvMapFeature extends exports.Feature {\n constructor() {\n var _a;\n super(...arguments);\n this.worldPosition = (_a = this._parent) === null || _a === void 0 ? void 0 : _a.position;\n }\n };\n exports.UvMapFeature._affects = new Set(ALL_GEOMETRY);\n exports.UvMapFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.UvMapFeature = __decorate([\n Kb3dModel({\n token: Token.UvMapFeature,\n })\n ], exports.UvMapFeature);\n\n exports.SubmeshFeature = class SubmeshFeature extends exports.UvMapFeature {\n constructor() {\n super(...arguments);\n this.vertexGroups = [];\n }\n };\n exports.SubmeshFeature._dependsOn = new Set([exports.eMeshChangeTypes.VertexIndices]);\n exports.SubmeshFeature._affects = new Set(ALL_GEOMETRY);\n exports.SubmeshFeature._affectedBy = new Set(ALL_GEOMETRY);\n exports.SubmeshFeature = __decorate([\n Kb3dModel({\n token: Token.SubmeshFeature,\n })\n ], exports.SubmeshFeature);\n function isSubmesh(o) {\n return instanceOf(o, Token.SubmeshFeature);\n }\n\n exports.SweepFeature = class SweepFeature extends exports.ExtrudeFeature {\n constructor() {\n super(...arguments);\n this.size = 0;\n }\n };\n exports.SweepFeature._affects = new Set(ALL_GEOMETRY);\n exports.SweepFeature._affectedBy = new Set([...ALL_GEOMETRY, exports.eMeshChangeTypes.Transform]);\n __decorate([\n NodeReference(exports.BaseConnector)\n ], exports.SweepFeature.prototype, \"start\", void 0);\n __decorate([\n NodeReference(exports.BaseConnector)\n ], exports.SweepFeature.prototype, \"end\", void 0);\n __decorate([\n NodeReference(exports.SketchNode)\n ], exports.SweepFeature.prototype, \"path\", void 0);\n exports.SweepFeature = __decorate([\n Kb3dModel({\n token: Token.SweepFeature,\n })\n ], exports.SweepFeature);\n\n exports.TransformFeature = class TransformFeature extends exports.Feature {\n };\n exports.TransformFeature._affectedBy = new Set([exports.eMeshChangeTypes.Transform, exports.eMeshChangeTypes.VertexPositions]);\n exports.TransformFeature._affects = new Set([exports.eMeshChangeTypes.VertexPositions]);\n exports.TransformFeature = __decorate([\n Kb3dModel({\n token: Token.TransformFeature,\n })\n ], exports.TransformFeature);\n\n exports.WeldVerticesFeature = class WeldVerticesFeature extends exports.Feature {\n get vertexIndices() {\n if (!this._vertexIndices)\n this._vertexIndices = [];\n return this._vertexIndices;\n }\n set vertexIndices(val) {\n this._vertexIndices = val;\n }\n };\n exports.WeldVerticesFeature._dependsOn = new Set([exports.eMeshChangeTypes.VertexIndices]);\n exports.WeldVerticesFeature._affectedBy = new Set([exports.eMeshChangeTypes.VertexPositions, exports.eMeshChangeTypes.VertexIndices]);\n exports.WeldVerticesFeature._affects = new Set([\n exports.eMeshChangeTypes.VertexPositions,\n exports.eMeshChangeTypes.VertexIndices,\n exports.eMeshChangeTypes.VertexUvs,\n exports.eMeshChangeTypes.VertexNormals,\n exports.eMeshChangeTypes.Submeshes,\n ]);\n __decorate([\n IgnoreChanges\n ], exports.WeldVerticesFeature.prototype, \"_vertexIndices\", void 0);\n __decorate([\n Enumerable()\n ], exports.WeldVerticesFeature.prototype, \"vertexIndices\", null);\n exports.WeldVerticesFeature = __decorate([\n Kb3dModel({\n token: Token.WeldVerticesFeature,\n })\n ], exports.WeldVerticesFeature);\n\n exports.AnnotationNode = class AnnotationNode extends exports.Kb3dObject {\n constructor() {\n super();\n this.label = '';\n this.preloadFontStylesheet = '';\n }\n };\n __decorate([\n NodeReference(exports.Connector, 'position', 'direction', 'angle')\n ], exports.AnnotationNode.prototype, \"targetId\", void 0);\n exports.AnnotationNode = __decorate([\n Kb3dModel({\n token: Token.AnnotationNode,\n })\n ], exports.AnnotationNode);\n function isAnnotation(node) {\n return instanceOfAny(node, Token.AnnotationNode, Token.DimensionNode);\n }\n\n exports.DimensionNode = class DimensionNode extends exports.AnnotationNode {\n constructor() {\n super();\n }\n };\n __decorate([\n NodeReference(exports.Connector, 'position')\n ], exports.DimensionNode.prototype, \"target2Id\", void 0);\n exports.DimensionNode = __decorate([\n Kb3dModel({\n token: Token.DimensionNode,\n })\n ], exports.DimensionNode);\n\n (function (eHandler) {\n eHandler[\"click\"] = \"click\";\n eHandler[\"doubleClick\"] = \"doubleClick\";\n eHandler[\"draggable\"] = \"draggable\";\n eHandler[\"hotspot\"] = \"hotspot\";\n eHandler[\"boundingBox\"] = \"boundingBox\";\n })(exports.eHandler || (exports.eHandler = {}));\n /** A 2 layer map that stores values by a key 1st, then a 2nd level of a string tag, then an array of values */\n class TagArrayMap {\n constructor() {\n this._db = new Map();\n }\n get(key, tag) {\n var _a;\n const v = (_a = this._db.get(key)) === null || _a === void 0 ? void 0 : _a.get(tag);\n return v || [];\n }\n deleteByKeyValue(key, value) {\n const e = this._db.get(key);\n if (e) {\n for (const values of e.values()) {\n values.removeWhere(v => v == value);\n }\n this.deleteEntryIfEmpty(key);\n }\n }\n getByKey(key) {\n if (this._db.has(key)) {\n return this._db.get(key).all();\n }\n return [];\n }\n set(key, tag, value) {\n var _a;\n if (!this._db.has(key))\n this._db.set(key, new ArrayMap());\n (_a = this._db.get(key)) === null || _a === void 0 ? void 0 : _a.add(tag, value);\n }\n deleteByTag(...tags) {\n const result = [];\n for (const [key, value] of this._db.entries()) {\n const nodeResult = {};\n result.push({ node: key, handlers: nodeResult });\n for (const tag of tags) {\n const handler = value.get(tag);\n if (handler) {\n nodeResult[tag] = handler;\n }\n value.delete(tag);\n }\n this.deleteEntryIfEmpty(key);\n }\n return result;\n }\n delete(key, tag) {\n const e = this._db.get(key);\n if (e) {\n const result = e.get(tag);\n e.delete(tag);\n this.deleteEntryIfEmpty(key);\n return result;\n }\n return [];\n }\n deleteByKey(key) {\n const handlers = this._db.get(key);\n const result = {};\n if (handlers) {\n handlers.forEach((value, key) => {\n result[key] = value;\n });\n }\n this._db.delete(key);\n return result;\n }\n clear() {\n this._db.clear();\n }\n has(key, tag) {\n return this.get(key, tag).length > 0;\n }\n deleteEntryIfEmpty(key) {\n const e = this._db.get(key);\n if (e && !e.size)\n this._db.delete(key);\n }\n }\n class ArrayMap extends Map {\n get(key) {\n return super.get(key) || [];\n }\n add(key, ...values) {\n if (!this.has(key)) {\n super.set(key, [...values]);\n }\n else {\n this.get(key).push(...values);\n }\n }\n removeValue(key, ...values) {\n const arr = super.get(key);\n if (arr) {\n arr.removeWhere(i => values.some(v => v == i));\n }\n }\n all() {\n return [...this.values()].flat();\n }\n }\n class SetMap extends Map {\n get(key) {\n const set = super.get(key);\n if (!set)\n super.set(key, new Set());\n return super.get(key);\n }\n add(key, ...values) {\n const s = this.get(key);\n for (const v of values)\n s.add(v);\n }\n removeValue(key, ...values) {\n const s = super.get(key);\n if (s) {\n for (const v of values)\n s.delete(v);\n }\n }\n all() {\n return [...this.values()].flat();\n }\n }\n class HandlerMap extends TagArrayMap {\n constructor(manager) {\n super();\n this.manager = manager;\n }\n add(idNameOrNode, tag, handler) {\n let nodes = new Array();\n if (typeof idNameOrNode == 'string') {\n nodes = this.manager.getNodesByIdOrName(idNameOrNode, true);\n }\n else {\n nodes.push(idNameOrNode);\n }\n for (const n of nodes) {\n if (isPickable(n)) {\n this.set(n, tag, handler);\n }\n }\n }\n }\n\n exports.ImportInfo = class ImportInfo {\n };\n exports.ImportInfo = __decorate([\n Kb3dModel({\n token: Token.ImportInfo,\n trackChanges: false,\n })\n ], exports.ImportInfo);\n\n const fontFilesLoading = new Map();\n const stylesheetsLoading = new Map();\n const fontFamilySrcs = new Map();\n class FontService {\n constructor(httpService, assetRoot = '') {\n this.httpService = httpService;\n this.assetRoot = assetRoot;\n /** Can be both the font face name as well as the font file URL */\n this.readyFonts = new Map();\n }\n loadFont(stylesheetUrl, fontFamilies) {\n const fontFaceSet = document.fonts;\n if (typeof fontFaceSet === 'undefined') {\n return Promise.reject('FontFaceSet api not available');\n }\n return this.loadStylesheet(stylesheetUrl).then(() => this.loadFontFamily(fontFaceSet, fontFamilies));\n }\n loadFontByFile(path) {\n const absPath = isAbsoluteUrl(path) ? path : this.getAbsoluteFontPath(path);\n let loadPromise;\n if (fontFilesLoading.has(absPath)) {\n loadPromise = fontFilesLoading.get(absPath);\n }\n else {\n const promise = this.httpService.getPublicStatic(absPath, 'arraybuffer');\n fontFilesLoading.set(absPath, promise);\n loadPromise = promise;\n }\n return loadPromise.then(buffer => {\n if (buffer.byteLength === 0) {\n return Promise.reject('Could not fetch font');\n }\n else {\n this.readyFonts.set(path, buffer);\n }\n return buffer;\n });\n }\n loadFontData(stylesheetUrl, fontFamilies) {\n return this.loadStylesheet(stylesheetUrl).then(() => this.getFontData(fontFamilies));\n }\n getAbsoluteFontPath(relativePath) {\n return `${this.assetRoot}/media/${relativePath}`; //it's a relative path to the media folder\n }\n loadStylesheet(stylesheetUrl) {\n let stylesheetLoad = stylesheetsLoading.get(stylesheetUrl);\n if (!stylesheetLoad) {\n stylesheetLoad = this.httpService.getPublicStatic(stylesheetUrl).then(res => {\n // Parse the css and store the srcs to the font files\n const fontFaces = res.matchAll(/@font-face\\s*{([\\s\\S]*?)}/gm);\n for (const face of fontFaces) {\n const fontFamilyMatch = face[1].match(/font-family\\s*:\\s*['\"]?(.*?)['\"]?[;,\\n]/m);\n if (fontFamilyMatch) {\n const fontFamilyName = fontFamilyMatch[1];\n const srcMatch = face[1].match(/src\\s*:.*?url\\s*\\([\\s\"']*(.*?)[\\s\"']*\\)/m);\n if (srcMatch) {\n const fontSrc = srcMatch[1];\n fontFamilySrcs.set(fontFamilyName.trim().toLowerCase(), fontSrc.trim());\n }\n }\n }\n });\n stylesheetsLoading.set(stylesheetUrl, stylesheetLoad);\n }\n return stylesheetLoad;\n }\n getFontData(fontFamilies) {\n const loadFaces = [];\n const loadPromises = [];\n fontFamilies.forEach(fontFamily => {\n const fontSrc = fontFamilySrcs.get(fontFamily.trim().toLowerCase());\n if (!fontSrc) {\n console.warn(`Font family ${fontFamily} not found. Is it being loaded by the preloaded stylesheet?`);\n }\n else if (fontFilesLoading.has(fontFamily)) {\n loadPromises.push(fontFilesLoading.get(fontFamily));\n loadFaces.push(fontFamily);\n }\n else {\n const promise = this.httpService.getPublicStatic(fontSrc, 'arraybuffer');\n fontFilesLoading.set(fontFamily, promise);\n loadPromises.push(promise);\n loadFaces.push(fontFamily);\n }\n });\n const resMap = {};\n return Promise.all(loadPromises).then(buffers => {\n buffers.forEach((buffer, index) => {\n resMap[loadFaces[index]] = buffer;\n this.readyFonts.set(loadFaces[index], buffer);\n });\n return resMap;\n });\n }\n loadFontFamily(fontFaceSet, fontFamilies) {\n return this.getFontData(fontFamilies).then(resultData => {\n const resultFonts = [];\n fontFamilies.forEach(fontFamily => {\n if (resultData[fontFamily]) {\n const newFontFace = new FontFace(fontFamily, resultData[fontFamily]);\n // @ts-expect-error TS 5.1.6 definition does not include add on FontFaceSet\n fontFaceSet.add(newFontFace);\n resultFonts.push(newFontFace);\n }\n else {\n console.warn('Could not load font ' + fontFamily);\n }\n });\n return resultFonts;\n });\n }\n }\n\n (function (eContentType) {\n eContentType[\"json\"] = \"application/json\";\n eContentType[\"formData\"] = \"multipart/form-data\";\n })(exports.eContentType || (exports.eContentType = {}));\n const ABORTED = 'ABORTED';\n class HttpService {\n constructor(environment) {\n this.environment = environment;\n this.trackedAssetCalls = new Array();\n this.deferredAssetCalls = new Array();\n this.httpCallsToAbort = new Map();\n this.deferredExecuted = false;\n }\n addCacheParams(url) {\n return this.getUrlWithParams(url, this.getEnvironmentCacheParams());\n }\n get(url, params, trackAssetCall = true) {\n if (!isAbsoluteUrl(url) && this.environment) {\n // api calls in the test and prod environments should send the last deploy,\n // which allows the browser cache to store results for some calls\n if (this.environment) {\n const addParams = this.getEnvironmentCacheParams();\n params = params ? { ...params, ...addParams } : addParams;\n }\n }\n const u = this.getUrlWithParams(url, params);\n const p = this.fetchWrapper(u, 'GET');\n if (trackAssetCall) {\n this.trackAssetCall(p);\n }\n return p;\n }\n getPublicStatic(url, type = 'text', params, trackAssetCall = true) {\n const u = this.getUrlWithParams(url, params);\n const requestInit = {\n method: 'GET',\n credentials: 'omit',\n };\n const p = fetch(u, requestInit).then(res => {\n if (type === 'text') {\n return res.text();\n }\n else if (type === 'blob') {\n return res.blob();\n }\n else if (type === 'arraybuffer') {\n return res.arrayBuffer();\n }\n else {\n return res.json();\n }\n });\n if (trackAssetCall) {\n this.trackAssetCall(p);\n }\n return p;\n }\n post(url, body, contentType = exports.eContentType.json) {\n return this.fetchWrapper(url, 'POST', body, contentType);\n }\n put(url, body, contentType = exports.eContentType.json) {\n return this.fetchWrapper(url, 'PUT', body, contentType);\n }\n delete(url, params) {\n const u = this.getUrlWithParams(url, params);\n return this.fetchWrapper(u, 'DELETE');\n }\n getBinary(url, responseType, trackAssetCall, appendCacheParameters = false, abortSubject) {\n const xhr = new XMLHttpRequest();\n if (appendCacheParameters && !isAbsoluteUrl(url) && this.environment) {\n if (this.environment) {\n const addParams = this.getEnvironmentCacheParams();\n url = this.getUrlWithParams(url, addParams);\n }\n }\n const abortSub = abortSubject === null || abortSubject === void 0 ? void 0 : abortSubject.subscribe(() => {\n xhr.abort();\n });\n const p = new Promise((resolve, reject) => {\n xhr.open('GET', url, true);\n xhr.responseType = responseType;\n xhr.onload = function (oEvent) {\n if (xhr.status >= 200 && xhr.status < 300) {\n const allHeaders = xhr.getAllResponseHeaders();\n let height = null, width = null;\n if (allHeaders.match(/Original-Height/i)) {\n height = xhr.getResponseHeader('X-Original-Height');\n width = xhr.getResponseHeader('X-Original-Width');\n }\n const response = {\n data: xhr.response,\n };\n if (height && width) {\n response.height = parseInt(height);\n response.width = parseInt(width);\n }\n resolve(response);\n }\n else {\n reject(xhr.statusText);\n }\n abortSub === null || abortSub === void 0 ? void 0 : abortSub.unsubscribe();\n };\n xhr.onerror = e => {\n reject(e);\n abortSub === null || abortSub === void 0 ? void 0 : abortSub.unsubscribe();\n };\n xhr.onabort = () => {\n reject(ABORTED);\n // do nothing\n };\n xhr.send(null);\n });\n if (trackAssetCall) {\n this.trackAssetCall(p);\n }\n return p;\n }\n /**\n * delays execution of parameter function until all blocking assets have been loaded for the scene.\n * executes immediately if scene is already loaded.\n */\n defer(func, priority = 100) {\n if (this.deferredExecuted) {\n return func();\n }\n else {\n return new Promise((resolve, reject) => {\n this.deferredAssetCalls.push({ func, resolve, reject, priority });\n });\n }\n }\n executeDeferredCalls() {\n this.deferredAssetCalls.sort((a, b) => a.priority - b.priority);\n for (const call of this.deferredAssetCalls) {\n call.func().then(call.resolve).catch(call.reject);\n }\n this.deferredAssetCalls = [];\n this.deferredExecuted = true;\n }\n trackAssetCall(p) {\n const trackedPromise = p.finally(() => {\n this.trackedAssetCalls.remove(trackedPromise);\n });\n this.trackedAssetCalls.push(trackedPromise);\n }\n getEnvironmentCacheParams() {\n if (this.environment) {\n const params = {};\n if (this.environment.lastDeploy) {\n params.d = this.environment.lastDeploy.toString();\n }\n if (this.environment.cacheBuster) {\n params.v = this.environment.cacheBuster;\n }\n return params;\n }\n return {};\n }\n getUrlWithParams(url, params) {\n if (!params)\n return url;\n const urlParams = new URLSearchParams(Object.entries(params));\n let prefix = '?';\n if (url.match(/\\?/)) {\n prefix = '&';\n }\n return `${url}${prefix}${urlParams.toString()}`;\n }\n fetchWrapper(url, method, body, contentType = exports.eContentType.json) {\n const headers = new Headers();\n const requestInit = {\n method,\n headers,\n credentials: 'include',\n };\n if (method.equalsAny('POST', 'PUT')) {\n if (contentType == exports.eContentType.json) {\n headers.append('Content-Type', contentType);\n requestInit.body = JSON.stringify(body);\n }\n else if (contentType == exports.eContentType.formData) {\n requestInit.body = body;\n }\n }\n const p = fetch(url, requestInit).then(r => {\n if (r.ok) {\n return r.json().catch(() => body);\n }\n else {\n throw new Error(JSON.stringify(r));\n }\n });\n return p;\n }\n }\n\n const MOBILE_WIDTH = 847;\n function isMobile() {\n return window != null && window.innerWidth < MOBILE_WIDTH;\n }\n\n function getRotatedDimensions(width, height, rAngle) {\n const rad = (rAngle * Math.PI) / 180;\n return {\n width: width * Math.cos(rad) + height * Math.sin(rad),\n height: width * Math.sin(rad) + height * Math.cos(rad),\n };\n }\n function scaleImagePreserveAspect(targetWidth, targetHeight, naturalWidth, naturalHeight) {\n let drawWidth, drawHeight;\n const imageWidth = naturalWidth || 256;\n const imageHeight = naturalHeight || 256;\n if (imageWidth > imageHeight) {\n drawWidth = targetWidth;\n drawHeight = (imageHeight / imageWidth) * targetWidth;\n }\n else {\n drawWidth = (imageWidth / imageHeight) * targetHeight;\n drawHeight = targetHeight;\n }\n return {\n drawWidth: Math.ceil(drawWidth),\n drawHeight: Math.ceil(drawHeight),\n };\n }\n function getBinClampedSize(width, height, rounding = 'floor') {\n if (rounding === 'floor') {\n const log2 = Math.min(Math.log2(width), Math.log2(height));\n return Math.pow(2, Math.floor(log2));\n }\n else {\n const log2 = Math.max(Math.log2(width), Math.log2(height));\n return Math.pow(2, Math.ceil(log2));\n }\n }\n\n const KBMAXPREFIX = '____kbm____';\n const LOCAL_ENVIRONMENT_DOMAIN = 'library://';\n\n const SLOW_NETWORK_THRESHOLD = 100; // kB per second\n let slowWarningThrown = false;\n function attachLoadingTimer(p) {\n const startTime = performance.now();\n p.then(result => {\n if (slowWarningThrown) {\n return;\n }\n let fileSize = 0;\n const endTime = performance.now();\n if ('byteLength' in result.data) {\n fileSize = result.data.byteLength;\n }\n else if ('size' in result.data) {\n fileSize = result.data.size;\n }\n if (startTime && endTime && fileSize > 50000) {\n const resultTime = endTime - startTime; // in milliseconds\n // if download speed is less than 100 kB per second, throw slow loading warning\n if (fileSize / resultTime < SLOW_NETWORK_THRESHOLD) {\n console.warn('Slow network detected. Scene experience may be degraded.');\n slowWarningThrown = true;\n }\n }\n }).catch(() => {\n // Do nothing\n });\n return p;\n }\n\n const LIBRARY_PATH = '%LIBRARY%';\n // If this is a raster image, we store the bitmap. If this is an SVG, then we store the blob so it can be resized efficiently\n const textureCache = new Map();\n const materialCache = new Map();\n const TEXTURE_SIZES = [128, 256, 512, 1024, 2048, null];\n const LIBRARY_TEXTURE_SIZES = [256, 256, 512, 1024, 2048, 2048];\n const LIBRARY_ENV_SIZES = [128, 256, 512, 1024];\n const LIBRARY_MOBILE_ENV_SIZES = [128, 128, 256, 512];\n const MAX_DETAIL_LEVEL = 5;\n exports.MaterialService = class MaterialService {\n constructor(httpService, assetRoot, forceFullSizeTextures = false) {\n this.httpService = httpService;\n this.assetRoot = assetRoot;\n this.forceFullSizeTextures = forceFullSizeTextures;\n this.trackedAssetCalls = new Array();\n this.materialUpdateChannel = new Map();\n this.abortSubjects = new Map();\n this.textureDetailLevel = MAX_DETAIL_LEVEL;\n if (forceFullSizeTextures) {\n this.textureDetailLevel = -1;\n }\n else if (window.screen.width <= 1024 || window.screen.height <= 1024) {\n this.textureDetailLevel = 2;\n }\n }\n getMaterialLibraryCategories() {\n const categoryIds = Object.keys(materialDefinitionSet);\n return categoryIds.map(id => ({\n id,\n label: materialDefinitionSet[id].label,\n }));\n }\n getMaterialLibraryOptions(category) {\n return LibraryMaterialsByCategory.get(category) || [];\n }\n getMaterialById(guid) {\n if (materialCache.has(guid)) {\n return materialCache.get(guid);\n }\n else {\n let obs;\n const material = LibraryMaterials.get(guid);\n if (material) {\n //it's a library material\n obs = of(material\n //asapScheduler\n );\n }\n else {\n //maybe a global material\n obs = from(this.httpService.get(`/api/materials/${guid}`));\n }\n const updateChannel = new BehaviorSubject(null);\n this.materialUpdateChannel.set(guid, updateChannel);\n obs = combineLatest([obs, updateChannel])\n .pipe(map(([material, updatedMaterial]) => {\n if (!material) {\n return undefined;\n }\n return { ...material, ...(updatedMaterial || {}) };\n }))\n .pipe(shareReplay(1));\n materialCache.set(guid, obs);\n return obs;\n }\n }\n getTexturePath(node, detailLevel) {\n let width = null;\n let height = null;\n if (!node.path) {\n return '';\n }\n if (detailLevel === undefined) {\n detailLevel = this.textureDetailLevel;\n }\n detailLevel = Math.min(MAX_DETAIL_LEVEL, detailLevel);\n if (node.path.startsWith(LIBRARY_PATH)) {\n return this.getLibraryTexturePath(node.path, detailLevel);\n }\n else if (!isAbsoluteUrl(node.path)) {\n const url = this.getAbsoluteTexturePath(node.path);\n if (detailLevel >= 0) {\n width = TEXTURE_SIZES[detailLevel];\n }\n if (detailLevel >= 0) {\n height = TEXTURE_SIZES[detailLevel];\n }\n const params = [];\n if (width != null)\n params.push(`width=${width}`);\n if (height != null)\n params.push(`height=${height}`);\n if (params.length > 0) {\n return url + '?' + params.join('&');\n }\n else {\n return url;\n }\n }\n else {\n return node.path;\n }\n }\n getTextureImage(node, trackAssetCall = true) {\n const initialUrl = this.getTexturePath(node, 0);\n const url = this.getTexturePath(node);\n let bitmapObs;\n if (textureCache.has(url)) {\n bitmapObs = textureCache.get(url);\n }\n else {\n bitmapObs = new Observable(subject => {\n const activeLinkAbort = this.abortSubjects.get(node._dynamicId);\n // if there already is an httpService call on this node. Abort the previous one\n if (activeLinkAbort) {\n activeLinkAbort.next();\n }\n const abortTextureLoad = new Subject();\n this.abortSubjects.set(node._dynamicId, abortTextureLoad);\n // Textures are absolute so we have to add the cache params before passing to http service\n // With this code library textures are always progressively loaded regardless of the scene setting because they do not have a root scene\n // revisit this if we want to change this behavior but it is non-trivial to do so\n if (this.forceFullSizeTextures || (node._rootScene && !node._rootScene.progressiveTextureLoad)) {\n const cacheParamUrl = this.assetRoot && url.startsWith(this.assetRoot) ? this.httpService.addCacheParams(url) : url;\n attachLoadingTimer(this.httpService.getBinary(cacheParamUrl, 'blob', false, true, abortTextureLoad)).then(blobResult => {\n // clear the abort once the full image is loaded\n const activeLinkAbort = this.abortSubjects.get(node._dynamicId);\n if (activeLinkAbort) {\n activeLinkAbort.complete();\n this.abortSubjects.delete(node._dynamicId);\n }\n processImageBlob(blobResult).then(result => {\n if (result) {\n subject.next({ bitmap: result, url: cacheParamUrl });\n subject.complete();\n }\n });\n }, err => {\n if (err !== ABORTED) {\n console.warn(`Could not load texture ${cacheParamUrl}: ` + err.toString());\n }\n subject.complete();\n });\n }\n else {\n const initialCacheParamUrl = this.assetRoot && url.startsWith(this.assetRoot)\n ? this.httpService.addCacheParams(initialUrl)\n : initialUrl;\n const loadStartTime = performance.now();\n attachLoadingTimer(this.httpService.getBinary(initialCacheParamUrl, 'blob', false, true, abortTextureLoad)).then(initialBlobResult => {\n processImageBlob(initialBlobResult).then(result => {\n const loadTime = performance.now() - loadStartTime;\n if (loadTime > 2000) {\n console.warn(`Texture ${initialCacheParamUrl} took ${loadTime}ms to load`);\n }\n if (result) {\n subject.next({ bitmap: result, url: initialCacheParamUrl });\n }\n const cacheParamUrl = this.assetRoot && url.startsWith(this.assetRoot)\n ? this.httpService.addCacheParams(url)\n : url;\n this.httpService\n .defer(() => this.httpService.getBinary(cacheParamUrl, 'blob', false, true, abortTextureLoad))\n .then(blobResult => {\n // clear the abort once the full image is loaded\n const activeLinkAbort = this.abortSubjects.get(node._dynamicId);\n if (activeLinkAbort) {\n activeLinkAbort.complete();\n this.abortSubjects.delete(node._dynamicId);\n }\n processImageBlob(blobResult).then(result => {\n if (result) {\n subject.next({ bitmap: result, url: cacheParamUrl });\n subject.complete();\n }\n });\n }, err => {\n if (err !== ABORTED) {\n console.warn(`Could not load texture ${cacheParamUrl}: ` + err.toString());\n }\n subject.complete();\n });\n });\n }, err => {\n if (err !== ABORTED) {\n console.warn(`Could not load texture ${initialCacheParamUrl}: ` + err.toString());\n }\n subject.complete();\n });\n }\n }).pipe(shareReplay(1));\n }\n function processImageBlob(blob) {\n if (blob && blob.data) {\n if (blob.data.type === 'image/svg+xml') {\n return Promise.resolve(blob.data);\n }\n else {\n if (blob.data.type.match(/image/)) {\n const opts = blob.width && blob.height\n ? {\n resizeWidth: blob.width,\n resizeHeight: blob.height,\n resizeQuality: 'medium',\n }\n : undefined;\n return createImageBitmap(blob.data, opts).then(bitmap => {\n return Promise.resolve(bitmap);\n });\n }\n else {\n console.warn('source file is not an image: ', url);\n }\n }\n }\n return Promise.resolve(null);\n }\n textureCache.set(url, bitmapObs);\n const obs = bitmapObs.pipe(switchMap(res => {\n /** bitmap is returned as blob for SVGs and imageBitmap for raster images */\n if (res.bitmap instanceof Blob) {\n const blobToConvert = res.bitmap;\n return new Promise((resolve, reject) => {\n const imageElement = document.createElement('img');\n const blobUrl = URL.createObjectURL(blobToConvert);\n imageElement.onload = () => {\n // Figure out what resolution to actually draw the SVG at to fit within the envelope\n const scaled = scaleImagePreserveAspect(node.width, node.height, imageElement.naturalWidth, imageElement.naturalHeight);\n createImageBitmap(imageElement, {\n resizeWidth: scaled.drawWidth,\n resizeHeight: scaled.drawHeight,\n }).then(bitmap => {\n resolve({ bitmap: bitmap, url: res.url });\n });\n };\n imageElement.onerror = e => {\n reject(e);\n };\n imageElement.src = blobUrl;\n });\n }\n else {\n return of({ bitmap: res.bitmap, url: res.url });\n }\n }));\n if (trackAssetCall) {\n this.trackAssetCall(obs.pipe(take(1)).toPromise());\n }\n return obs;\n }\n getLibraryTexturePath(relativePath, quality = 0) {\n const path = relativePath.substring(LIBRARY_PATH.length);\n let res;\n if (quality < 0) {\n res = LIBRARY_TEXTURE_SIZES[LIBRARY_TEXTURE_SIZES.length - 1];\n }\n else {\n res = LIBRARY_TEXTURE_SIZES[quality];\n }\n return `${this.assetRoot}/assets/textures/${path}_${res}.jpg`;\n }\n getAbsoluteTexturePath(relativePath) {\n return `${this.assetRoot}/media/${relativePath}`; //it's a relative path to the media folder\n }\n getAbsoluteEnvironmentPath(path, quality) {\n if (path) {\n let url;\n if (path.startsWith(LOCAL_ENVIRONMENT_DOMAIN)) {\n const res = isMobile() ? LIBRARY_MOBILE_ENV_SIZES[quality] : LIBRARY_ENV_SIZES[quality];\n url = `${this.assetRoot}/assets/environments/${path.replace(LOCAL_ENVIRONMENT_DOMAIN, '')}_${res}.env`;\n }\n else {\n url = this.getAbsoluteTexturePath(path);\n }\n return this.httpService.addCacheParams(url);\n }\n return '';\n }\n searchMaterialByName(name, loadArchivedMaterials) {\n var _a;\n const archivedFilter = { type: 'property', property: 'archived', values: [false] };\n const searchArgs = { query: name + '*', sortField: 'Name', filters: [], descending: false };\n if (!loadArchivedMaterials) {\n (_a = searchArgs.filters) === null || _a === void 0 ? void 0 : _a.push(archivedFilter);\n }\n let result = null;\n if (name) {\n result = this.httpService.post('/api/materials/search', searchArgs);\n }\n return result;\n }\n getMaterialNameList() {\n const archivedFilter = { type: 'property', property: 'archived', values: [false] };\n const searchArgs = { fields: ['Guid', 'Name'], take: 10000, filters: [archivedFilter] };\n return this.httpService.post('/api/materials/search', searchArgs);\n }\n setMaterialCache(guid, mat) {\n materialCache.set(guid, of(mat));\n }\n trackAssetCall(p) {\n const trackedPromise = p.finally(() => {\n this.trackedAssetCalls.remove(trackedPromise);\n });\n this.trackedAssetCalls.push(trackedPromise);\n }\n };\n exports.MaterialService = __decorate([\n Kb3dService({\n token: Token.MaterialService,\n })\n ], exports.MaterialService);\n const LibraryMaterials = new Map();\n const LibraryMaterialsByCategory = new Map();\n const LibraryEnvironments = new Array();\n const LibraryEnvironmentsMap = new Map();\n function makeLibraryMaterial(tag, index) {\n //pad the index string with zeros\n let indexStr = index + '';\n while (indexStr.length < 2)\n indexStr = '0' + indexStr;\n const iname = tag + indexStr;\n const baseUrl = `${tag}/${iname}`;\n return {\n id: -1,\n name: iname,\n guid: iname,\n tags: [{ name: tag }],\n data: {\n $type: Token.AdvancedMaterialNode.key,\n name: iname,\n id: iname,\n location: exports.eMaterialLocation.library,\n textures: [\n {\n $type: 'FileTextureLayer',\n channel: exports.eTextureChannel.ambientOcclusion,\n path: `${LIBRARY_PATH}${baseUrl}_ao`,\n },\n {\n $type: 'FileTextureLayer',\n channel: exports.eTextureChannel.albedo,\n path: `${LIBRARY_PATH}${baseUrl}_col`,\n },\n {\n $type: 'FileTextureLayer',\n channel: exports.eTextureChannel.metallic,\n path: `${LIBRARY_PATH}${baseUrl}_met`,\n },\n {\n $type: 'FileTextureLayer',\n channel: exports.eTextureChannel.normal,\n path: `${LIBRARY_PATH}${baseUrl}_nrm`,\n },\n {\n $type: 'FileTextureLayer',\n channel: exports.eTextureChannel.roughness,\n path: `${LIBRARY_PATH}${baseUrl}_rgh`,\n },\n //{ $type: \"FileTextureLayer\", channel: eTextureChannel.displacement, path: `${LIBRARY_PATH}${baseUrl}_disp` },\n ],\n },\n };\n }\n function fillLibraryMaterialsMap() {\n for (const tag in materialDefinitionSet) {\n const entry = materialDefinitionSet[tag];\n for (let index = 1; index <= entry.count; index++) {\n const mat = makeLibraryMaterial(tag, index);\n const matData = mat.data;\n matData.roughness = 1;\n matData.metallic = 0;\n if (entry.omit) {\n const omit = entry.omit;\n matData.textures = matData.textures.filter(t => {\n if (omit[t.channel]) {\n if (omit[t.channel] === true) {\n return false;\n }\n if (Array.isArray(omit[t.channel]) && omit[t.channel].some(i => i === index)) {\n return false;\n }\n }\n return true;\n });\n }\n // Metallic is multiplied against the texture, so if the material has a metallic texture then set metallic to 1.\n if (matData.textures.findIndex(t => t.channel === exports.eTextureChannel.metallic) > -1) {\n matData.metallic = 1;\n }\n if (entry.props) {\n for (const p in entry.props) {\n mat.data[p] = entry.props[p];\n }\n }\n LibraryMaterials.set(mat.guid, mat);\n let categoryList = LibraryMaterialsByCategory.get(tag);\n if (!categoryList) {\n categoryList = [];\n }\n categoryList.push(mat);\n LibraryMaterialsByCategory.set(tag, categoryList);\n }\n }\n }\n const materialDefinitionSet = {\n asphalt: {\n label: 'Asphalt',\n count: 15,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 9, 10, 11, 12, 13, 14, 15],\n },\n },\n bark: {\n label: 'Bark',\n count: 6,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1],\n },\n },\n bricks: {\n label: 'Bricks',\n count: 17,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 3, 4],\n },\n },\n chipboard: {\n label: 'Chipboard',\n count: 3,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n },\n },\n concrete: {\n label: 'Concrete',\n count: 17,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 12, 14, 15, 16, 17],\n [exports.eTextureChannel.roughness]: [1],\n },\n },\n corrugatedsteel: {\n label: 'Corrugated Steel',\n count: 5,\n },\n diamondplate: {\n label: 'Diamond Plate',\n count: 4,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n [exports.eTextureChannel.albedo]: [4],\n },\n },\n fabric: {\n label: 'Fabric',\n count: 29,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n [exports.eTextureChannel.metallic]: true,\n },\n },\n gravel: {\n label: 'Gravel',\n count: 8,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2],\n },\n },\n ground: {\n label: 'Ground',\n count: 28,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 3, 17],\n },\n },\n ice: {\n label: 'Ice',\n count: 4,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n leather: {\n label: 'Leather',\n count: 14,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14],\n },\n },\n marble: {\n label: 'Marble',\n count: 5,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n metal: {\n label: 'Metal',\n count: 27,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n metalplates: {\n label: 'Metal Plate',\n count: 3,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n paint: {\n label: 'Paint',\n count: 6,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n },\n },\n paintedmetal: {\n label: 'Painted Metal',\n count: 5,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n paintedplaster: {\n label: 'Painted Plaster',\n count: 5,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n [exports.eTextureChannel.metallic]: true,\n },\n },\n pavingstones: {\n label: 'Paving Stones',\n count: 41,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 3, 4],\n },\n },\n pipe: {\n label: 'Pipe',\n count: 4,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n planks: {\n label: 'Planks',\n count: 9,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: [1, 2],\n },\n },\n plastic: {\n label: 'Plastic',\n count: 5,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n rock: {\n label: 'Rock',\n count: 14,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 6, 7, 8, 9],\n [exports.eTextureChannel.albedo]: [4],\n },\n },\n rocks: {\n label: 'Rocks',\n count: 6,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n },\n },\n roofingtiles: {\n label: 'Roofing Tiles',\n count: 5,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n rust: {\n label: 'Rust',\n count: 5,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n },\n },\n scratches: {\n label: 'Scratches',\n count: 5,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.albedo]: true,\n },\n },\n terrazzo: {\n label: 'Terrazzo',\n count: 8,\n omit: {\n [exports.eTextureChannel.ambientOcclusion]: true,\n [exports.eTextureChannel.metallic]: true,\n },\n },\n tiles: {\n label: 'Tiles',\n count: 37,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [\n 1, 2, 3, 4, 5, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 29, 30, 31, 32, 33, 34, 35, 36, 37,\n ],\n },\n },\n wood: {\n label: 'Wood',\n count: 20,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20],\n },\n },\n woodfloor: {\n label: 'Wood Floor',\n count: 28,\n omit: {\n [exports.eTextureChannel.metallic]: true,\n [exports.eTextureChannel.ambientOcclusion]: [1, 2, 4, 5, 6, 8],\n },\n },\n woodsiding: {\n label: 'Wood Siding',\n count: 8,\n omit: {\n [exports.eTextureChannel.metallic]: [5, 6, 7],\n },\n },\n };\n fillLibraryMaterialsMap();\n /** create library environments */\n for (const env of [\n // \"country\",\n // \"environment\",\n // \"forest\",\n // \"night\",\n // \"parking\",\n // \"room\",\n 'adams_place_bridge',\n 'aerodynamics_workshop',\n 'autoshop',\n 'ballroom',\n 'boiler_room',\n 'cape_hill',\n 'colorful_studio',\n 'fireplace',\n 'greenwich_park',\n 'hospital_room',\n 'industrial_pipe_and_valve',\n 'leadenhall_market',\n 'machine_shop',\n 'modern_buildings_night',\n 'museum_of_ethnography',\n 'mutianyu',\n 'old_bus_depot',\n 'photo_studio',\n 'preller_drive',\n 'red_wall',\n 'rooitou_park',\n 'royal_esplanade',\n 'schadowplatz',\n 'small_cathedral',\n 'spruit_sunrise',\n 'studio_small',\n 'surgery',\n 'venice_sunset',\n 'winter_evening',\n 'wooden_lounge',\n ]) {\n const label = env\n .split('_')\n .map(s => s.capitalize())\n .join(' ');\n const o = {\n name: env,\n label,\n path: `${LOCAL_ENVIRONMENT_DOMAIN}${env}`,\n previewUrl: `environments/${env}.jpg`,\n };\n LibraryEnvironments.push(o);\n LibraryEnvironmentsMap.set(o.path, o);\n }\n\n const geometryCache = new Map();\n class MeshService {\n constructor(httpService, assetRoot) {\n this.httpService = httpService;\n this.assetRoot = assetRoot;\n }\n /**\n * Loads the geometry for a mesh node and adds it to the node, mutating the node object.\n * @param meshNode Mesh node to load geometry for\n */\n hydrateGeometry(meshNode) {\n if (!isCustomMeshNode(meshNode) || !meshNode.geometryId) {\n return Promise.resolve(meshNode);\n }\n else {\n let request = geometryCache.get(meshNode.geometryId);\n let shared = false;\n if (!request) {\n request = attachLoadingTimer(this.httpService.getBinary(`${this.assetRoot}/meshes/${meshNode.geometryId}`, 'arraybuffer', true)).then(response => {\n if (response && response.data) {\n const geometry = meshNode._manager.create(Token.KbGeometry);\n geometry.extractFromBinary(response.data, meshNode);\n return geometry;\n }\n return Promise.reject();\n }, err => {\n console.error(`Geometry for \"${meshNode.name}\" could not be loaded`, err);\n return null;\n });\n geometryCache.set(meshNode.geometryId, request);\n }\n else {\n shared = true;\n }\n return request.then(geometry => {\n if (geometry) {\n if (shared) {\n geometry.shared = true;\n }\n meshNode._geometry = geometry;\n }\n return meshNode;\n });\n }\n }\n }\n\n exports.LightNode = class LightNode extends exports.SpaceNode {\n constructor() {\n super();\n }\n getSpaceChildren() {\n return [];\n }\n };\n exports.LightNode = __decorate([\n BaseKb3dModel({\n token: Token.LightNode,\n })\n ], exports.LightNode);\n function isLightNode(node) {\n return instanceOfAny(node, ...Token.LightTokens);\n }\n\n exports.SceneNode = class SceneNode extends exports.MeshGroupNode {\n constructor() {\n super();\n this._forceGrid = false;\n }\n get materials() {\n if (!this._materials)\n this._materials = [];\n return this._materials;\n }\n set materials(val) {\n this._materials = val;\n }\n get lights() {\n if (!this._lights)\n this._lights = [];\n return this._lights;\n }\n set lights(val) {\n this._lights = val;\n }\n get viewpoints() {\n if (!this._viewpoints)\n this._viewpoints = [];\n return this._viewpoints;\n }\n set viewpoints(val) {\n this._viewpoints = val;\n }\n get scenes() {\n if (!this._scenes)\n this._scenes = [];\n return this._scenes;\n }\n set scenes(val) {\n this._scenes = val;\n }\n get mates() {\n if (!this._mates)\n this._mates = [];\n return this._mates;\n }\n set mates(val) {\n this._mates = val;\n }\n get annotations() {\n if (!this._annotations)\n this._annotations = [];\n return this._annotations;\n }\n set annotations(val) {\n this._annotations = val;\n }\n get importHistory() {\n if (!this._importHistory)\n this._importHistory = [];\n return this._importHistory;\n }\n set importHistory(val) {\n this._importHistory = val;\n }\n get exportHistory() {\n if (!this._exportHistory)\n this._exportHistory = [];\n return this._importHistory;\n }\n set exportHistory(val) {\n this._exportHistory = val;\n }\n getChildren() {\n return [\n ...this.meshes,\n ...this.materials,\n ...this.lights,\n ...this.viewpoints,\n ...this.mates,\n ...this.connectors,\n ...this.annotations,\n ];\n }\n getChildArrayForType(token) {\n if (token.isMeshOrGroup() || token.isLight()) {\n return this.meshes;\n }\n else if (token.isMaterial()) {\n return this.materials;\n }\n else if (token.isViewpoint()) {\n return this.viewpoints;\n }\n else if (token.isMate()) {\n return this.mates;\n }\n else if (token.isConnector()) {\n return this.connectors;\n }\n else if (token.isAnnotation()) {\n return this.annotations;\n }\n else {\n throw 'unexpected token';\n }\n }\n getChildArray(node) {\n if (Token.withKey(node.$type).isLight()) {\n // Lights can be defined as meshes but can be in the light array as well, so we have to check there\n if (this.lights.contains(node)) {\n return this.lights;\n }\n }\n return super.getChildArray(node);\n }\n isNested() {\n return this._parent != null;\n }\n runOnAllScenes(action) {\n action(this);\n for (const nested of this.scenes) {\n nested.runOnAllScenes(action);\n }\n }\n getSpaceChildren() {\n return this.meshes.concat(this.scenes);\n }\n getNestedPathTo(node) {\n let path = node.id;\n let parent = node._parentScene;\n let isPath = false;\n while (parent) {\n if (parent === this)\n break;\n path = parent.nestedId + '/' + path;\n isPath = true;\n parent = parent._parent;\n }\n return `${isPath ? '@' : ''}${path}`;\n }\n getAllConnectors() {\n const connectors = new Array();\n this.runOnAllScenes(s => {\n connectors.push(...s._manager.getByToken(Token.Connector).filter(c => c.enabled));\n });\n return connectors;\n }\n getAllSketchControlPoints() {\n const points = new Array();\n this.runOnAllScenes(s => {\n points.push(...s._manager.getByToken(Token.SketchControlPoint).filter(c => c.enabled));\n });\n return points;\n }\n };\n __decorate([\n IgnoreChanges\n ], exports.SceneNode.prototype, \"conversionMap\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.SceneNode.prototype, \"_configurator\", void 0);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"materials\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"lights\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"viewpoints\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"scenes\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"mates\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"annotations\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"importHistory\", null);\n __decorate([\n Enumerable()\n ], exports.SceneNode.prototype, \"exportHistory\", null);\n exports.SceneNode = __decorate([\n Kb3dModel({\n token: Token.SceneNode,\n })\n ], exports.SceneNode);\n function isSceneNode(node) {\n return instanceOf(node, Token.SceneNode);\n }\n\n const SET_TYPE = '__set';\n /** contains all kb3dobjects keyed by their dynamic Id, to fetch nodes from the 3d engine ID */\n const dynamicDb = new Map();\n function getByDynamicId(dynamicId, throwOnNotFound = false) {\n if (throwOnNotFound && !dynamicDb.has(dynamicId)) {\n throw `kb3d object with id ${dynamicId} not found`;\n }\n return dynamicDb.get(dynamicId);\n }\n (function (ImportOperation) {\n ImportOperation[ImportOperation[\"ignore\"] = 0] = \"ignore\";\n ImportOperation[ImportOperation[\"add\"] = 1] = \"add\";\n ImportOperation[ImportOperation[\"replace\"] = 2] = \"replace\";\n })(exports.ImportOperation || (exports.ImportOperation = {}));\n class Kb3dManager {\n constructor(options) {\n this.isDevEnvironment = true;\n /** contains all kb3dobjects */\n this._db = new Map();\n /** contains all objects keyed by their token */\n this._tokenDb = new SetMap();\n /** contains all nodes (but not other kinds of objects) */\n this._nodeDb = new Map();\n /** holds a cache of name searches that have been performed with their results */\n this._nameSearchCache = new Map();\n /** contains nested scenes keyed by their nestedId */\n this._nestedSceneDb = new Map();\n /** holds a cache of click handlers that have been added to nodes in the context of this manager */\n this.clickHandlers = new HandlerMap(this);\n this.doubleClickHandlers = new HandlerMap(this);\n this.draggables = new HandlerMap(this);\n this.hotspotClickHandlers = new TagArrayMap();\n this.boundingboxChangeHandlers = new HandlerMap(this);\n //if no services are provided, then use the default services\n if (options && options.services) {\n this.services = options.services;\n }\n else {\n const httpService = new HttpService(options === null || options === void 0 ? void 0 : options.environment);\n if ((options === null || options === void 0 ? void 0 : options.environment) && options.environment.lastDeploy) {\n this.isDevEnvironment = false;\n }\n this.services = new Map([\n [Token.HttpService, httpService],\n [\n Token.MaterialService,\n new exports.MaterialService(httpService, options === null || options === void 0 ? void 0 : options.assetRoot, options === null || options === void 0 ? void 0 : options.forceFullSizeTextures),\n ],\n [Token.MeshService, new MeshService(httpService, options === null || options === void 0 ? void 0 : options.assetRoot)],\n [Token.FontService, new FontService(httpService, options === null || options === void 0 ? void 0 : options.assetRoot)],\n ]);\n }\n }\n getService(serviceToken) {\n return this.services.get(serviceToken);\n }\n dispose() {\n /**only clear items out of the dynamic db that were part of this manager (as it is static and holds dynamic ids for all managers) */\n for (const [, value] of this._db) {\n dynamicDb.delete(value._dynamicId);\n }\n this._db.clear();\n this._nodeDb.clear();\n this.clickHandlers.clear();\n this.doubleClickHandlers.clear();\n this.draggables.clear();\n this.hotspotClickHandlers.clear();\n this.boundingboxChangeHandlers.clear();\n this._nameSearchCache.clear();\n this._tokenDb.clear();\n this._nestedSceneDb.clear();\n }\n /**\n * Accepts either a node id or a name to search for nodes. If using\n * node name wildcards * are allowed. The action provided will be run\n * on each of the matching nodes, with the args passed in to that action.\n * @param idOrName\n * @param action\n * @param args\n * @param useCache\n */\n runOnNodes(idOrName, action, args, useCache = true) {\n if (isGuid(idOrName)) {\n const node = this.getById(idOrName);\n if (node)\n action(node, args);\n }\n else {\n const nodes = this.getNodesByName(idOrName, useCache);\n for (const node of nodes) {\n action(node, args);\n }\n }\n }\n // @child1/xxxxx-xxxxxx-xxxx\n getById(id) {\n if (id && id.startsWith('@')) {\n //it's a nested path id\n const segments = id.split('/');\n const nestedId = segments.shift().substring(1).toLowerCase();\n const nestedScene = this._nestedSceneDb.get(nestedId);\n if (nestedScene) {\n let subId = segments.join('/');\n if (segments.length > 1)\n subId = '@' + subId;\n return nestedScene._manager.getNodeByIdOrName(subId);\n }\n }\n else {\n return this._db.get(id);\n }\n }\n getAll() {\n return [...this._db.values()];\n }\n getAllNodes() {\n return [...this._nodeDb.values()];\n }\n /**\n * Accepts either a node id or a name to search for nodes. Only returns the first\n * matching node. If using node name wildcards * are allowed.\n * @param idOrName\n * @param useCache\n */\n getNodeByIdOrName(idOrName, useCache = true) {\n if (typeof idOrName == 'string') {\n if (isGuid(idOrName) || idOrName.startsWith('@')) {\n return this.getById(idOrName);\n }\n else {\n return this.getFirstNodeByName(idOrName, useCache);\n }\n }\n else if (idOrName instanceof exports.Kb3dObject) {\n return idOrName;\n }\n }\n /**\n * Accepts either a node id or a name to search for nodes. If using\n * node name wildcards * are allowed.\n * @param idOrName\n * @param useCache\n */\n getNodesByIdOrName(idOrName, useCache = true) {\n const res = [];\n if (typeof idOrName == 'string') {\n if (isGuid(idOrName)) {\n const n = this.getById(idOrName);\n if (n)\n res.push(n);\n }\n else {\n res.push(...this.getNodesByName(idOrName, useCache));\n }\n }\n else if (idOrName instanceof exports.Kb3dObject) {\n res.push(idOrName);\n }\n return res;\n }\n /**\n * Get's the first node that matches the name given. Wildcards * are allowed.\n * @param name\n * @param useCache\n */\n getFirstNodeByName(name, useCache = true) {\n const nodes = this.getNodesByName(name, useCache);\n if (nodes && nodes.length) {\n return nodes[0];\n }\n }\n /**\n * Returns a list of nodes that match the name given.\n * Wildcards * are allowed.\n * Results will be fed from a search cache if useCache is true\n * @param name\n * @param useCache\n */\n getNodesByName(name, useCache = true) {\n if (useCache && this._nameSearchCache.has(name)) {\n return this._nameSearchCache.get(name);\n }\n const results = new Array();\n const re = this.getWildcardRegex(name);\n for (const [, node] of this._db) {\n if (re.test(node.name)) {\n results.push(node);\n }\n }\n this._nameSearchCache.set(name, results);\n return results;\n }\n getNodesContainingName(name, useCache = true) {\n if (useCache && this._nameSearchCache.has(name)) {\n return this._nameSearchCache.get(name);\n }\n const results = new Array();\n const re = this.getWildcardRegex(name);\n for (const [, node] of this._db) {\n if (re.test(node.name)) {\n results.push(node);\n }\n }\n this._nameSearchCache.set(name, results);\n return results;\n }\n getByToken(token) {\n return [...this._tokenDb.get(token).values()];\n }\n getByTokens(...tokens) {\n return tokens.flatMap(t => [...this._tokenDb.get(t).values()]);\n }\n /** escapes the given string so that any special characters will be processed literally in a regex search */\n escapeRegex(str) {\n return str.replace(/([.*+?^=!:${}()|[\\]/\\\\])/g, '\\\\$1');\n }\n /**\n * Given a string with wildcards *, will provide a regex that can be used to\n * match strings.\n * @param rule\n */\n getWildcardRegex(rule) {\n // \".\" => Find a single character, except newline or line terminator\n // \".*\" => Matches any string that contains zero or more characters\n rule = rule.split('*').map(this.escapeRegex).join('.*');\n // \"^\" => Matches any string with the following at the beginning of it\n // \"$\" => Matches any string with that in front at the end of it\n rule = '^' + rule + '$';\n //Create a regular expression object for matching string\n return new RegExp(rule, 'i');\n }\n /**\n * absorbs a kb3d object that already exists into the manager.\n * @param o\n */\n register(o) {\n if (o instanceof exports.Kb3dObject) {\n if (!this._db.has(o.id)) {\n if (isTrackedClass(o)) {\n o.isModified = true; //force a full round of change detection if this is a newly registered object\n }\n }\n this._db.set(o.id, o);\n dynamicDb.set(o._dynamicId, o);\n this._tokenDb.add(Token.withKey(o.$type), o);\n if (o.isNode()) {\n this._nodeDb.set(o.id, o);\n }\n }\n }\n unregister(o) {\n if (o instanceof exports.Kb3dObject) {\n this.clickHandlers.deleteByKey(o);\n this.doubleClickHandlers.deleteByKey(o);\n this.draggables.deleteByKey(o);\n this.boundingboxChangeHandlers.deleteByKey(o);\n this._db.delete(o.id);\n dynamicDb.delete(o._dynamicId);\n this._tokenDb.removeValue(Token.withKey(o.$type), o);\n if (o.isNode()) {\n this._nodeDb.delete(o.id);\n }\n if (o instanceof exports.SceneNode && o.isNested()) {\n this._nestedSceneDb.delete(o.nestedId);\n }\n }\n }\n /**\n * Creates an instance of a kb3d model, given a token\n * and an anonymous object in the shape of the model that\n * can be used to set properties on it.\n *\n * As part of the creation process, we do things in this order:\n *\n * 1. Create an instance of the class. If a create function was provided\n * in the decorator for the class, that is used to create the instance.\n * If not, then it's created by calling the constructor of the class\n * with no arguments.\n * 2. We then apply default values to the properties of the class\n * 3. We then apply the args that were passed in to set properties on the class\n * 4. We then register the object into the map using it's id so it can be quickly retrieved\n */\n create(token, args = {}, options) {\n var _a;\n options = { includeChildNodes: true, ...options };\n const modelDef = Kb3dModels.get(token);\n if (!modelDef) {\n throw `could not find model with token: ${token.key}`;\n }\n const constructorParameters = getConstructorParamsForModel(modelDef);\n const hydratedParameters = [];\n for (const i of constructorParameters) {\n if (!i.ignore) {\n const service = (_a = this.services) === null || _a === void 0 ? void 0 : _a.get(i.token);\n if (!service) {\n throw `Injected service of type '${i.token.key} could not be found to inject into the constructor of type '${token.key}`;\n }\n hydratedParameters.push(service);\n }\n }\n let model;\n if (modelDef.create) {\n model = modelDef.create(args);\n }\n else {\n model = new modelDef.classConstructor(...hydratedParameters);\n }\n //now initialize the model for when no create function was given\n if (!modelDef.create) {\n this.initializeModel(isTrackedClass(model) ? model.rawNode : model, args, modelDef, options);\n }\n if (model instanceof exports.SceneNode) {\n model._manager = this;\n model.calculateParents(); //because calculateParents also registers the item, we must call this after initialization, otherwise it won't have the right id\n }\n if (modelDef.afterCreate) {\n modelDef.afterCreate(model);\n }\n //need to clear the name cache since we just created a new node\n //no need to clear if the node is a primitive as they are never fetched by name\n if (!token.isPrimitive()) {\n this._nameSearchCache.clear();\n }\n return model;\n }\n serializeToJson(instance, options) {\n const o = this.serialize(instance, options);\n const json = JSON.stringify(o, null, (options === null || options === void 0 ? void 0 : options.prettyPrint) ? 2 : undefined);\n return json;\n }\n serialize(instance, options) {\n options = {\n includeChildNodes: true,\n isRoot: true,\n omitDefaultValues: true,\n ...options,\n };\n let result = { $type: instance.$type };\n const defaultValues = defaults[instance.$type];\n for (const key in instance) {\n if (\n // Never persist properties beginning with an underscore\n key.substr(0, 1) !== '_' &&\n // If a property is the same as a default value, remove it\n (!options.omitDefaultValues ||\n !defaultValues ||\n !this.shallowEquals(defaultValues[key], instance[key]))) {\n if (!isObject$1(instance[key])) {\n // For primitives, just copy the values over\n result[key] = instance[key];\n }\n else if (Array.isArray(instance[key])) {\n const sourceArray = instance[key];\n if (sourceArray.length && typeof sourceArray[0] !== 'object') {\n //it's an array of primitives\n result[key] = sourceArray.slice(0); //clone the array of primitives\n }\n else {\n result[key] = []; //make sure there is an array on target prop. Recreate it if one is there already.\n for (const sourceItem of sourceArray) {\n if (!sourceItem.$type ||\n !Token.withKey(sourceItem.$type).isNode() ||\n options.includeChildNodes) {\n // exclude it if it's a kb3d model and includeChildren is false\n const targetItem = this.serialize(sourceItem, { ...options, isRoot: false });\n if (targetItem) {\n result[key].push(targetItem);\n }\n }\n }\n }\n }\n else if (instance[key] instanceof Map) {\n console.error('implement serializing maps');\n }\n else if (instance[key] instanceof Set) {\n result[key] = {\n $type: SET_TYPE,\n values: Array.from(instance[key].values()),\n };\n }\n else {\n // For anything else, try deserializing. The deserializer will just copy the property if it is not a serialized class.\n result[key] = this.serialize(instance[key], { ...options, isRoot: false });\n }\n }\n }\n if (instance.$type) {\n const modelDef = Kb3dModels.get(Token.withKey(instance.$type));\n if (modelDef && modelDef.onSerializing) {\n const include = modelDef.onSerializing(instance, result);\n // Always serialize the object if it is the root object. Otherwise, let the class decide.\n if (include === false && !options.isRoot) {\n result = undefined;\n }\n }\n }\n return result;\n }\n /**\n * See notes for the create() function as this is virtually the same.\n * The only difference is that the type here is discovered through the $type\n * property of the args object instead of an explicit token.\n * @param object\n */\n deserialize(object, options) {\n if (!object || !object.$type) {\n return object;\n }\n else if (object.$type === SET_TYPE) {\n return new Set(object.values);\n }\n return this.create(Token.withKey(object.$type), object, options);\n }\n deserializeJson(json) {\n const object = JSON.parse(json);\n return this.deserialize(object);\n }\n clone(objectToClone) {\n //make sure it's a kb3d model\n if (!objectToClone)\n throw 'no object provided to clone';\n if (!('$type' in objectToClone)) {\n throw 'object passed to clone function must be a kb3d model and have a $type defined';\n }\n const json = this.serializeToJson(objectToClone);\n const object = JSON.parse(json);\n return this.deserialize(object, { issueNewIds: true });\n }\n nestScene(nestedId, parent, serializedNested = {}) {\n const nestedMan = new Kb3dManager({ services: this.services });\n if (serializedNested.lights) {\n serializedNested.lights.clear();\n }\n const nested = nestedMan.create(Token.SceneNode, serializedNested);\n nested.nestedId = nestedId.replace('/', '');\n parent.scenes.push(nested);\n this._nestedSceneDb.set(nested.nestedId.toLowerCase(), nested);\n return nested;\n }\n getNodeNamePathMap() {\n const meshMap = new Map();\n const matMap = new Map();\n const lightMap = new Map();\n const allNodes = this._nodeDb.values();\n for (const n of allNodes) {\n if (isLightNode(n)) {\n lightMap.set(n.getNamePath(), n);\n }\n else if (isMaterialNode(n)) {\n matMap.set(n.getNamePath(), n);\n }\n else {\n meshMap.set(n.getNamePath(), n);\n }\n }\n return {\n meshes: meshMap,\n lights: lightMap,\n materials: matMap,\n };\n }\n previewImport(parent, imported) {\n const sceneNode = parent._parentScene;\n if (!sceneNode || !imported.scene)\n return;\n const nMap = this.getNodeNamePathMap();\n const processNode = (node, parentNamePath) => {\n const token = Token.withKey(node['$type']);\n const namePath = token !== Token.SceneNode && node.name\n ? [parentNamePath, node.name].filter(Boolean).join('/')\n : parentNamePath;\n let matchingNode;\n if (token.isLight()) {\n matchingNode = nMap.lights.get(namePath);\n }\n else if (token.isMaterial()) {\n matchingNode = nMap.materials.get(namePath);\n }\n else {\n matchingNode = nMap.meshes.get(namePath);\n }\n const p = {\n node,\n type: Token.withKey(node['$type']),\n namePath,\n matchingNode,\n operation: matchingNode ? exports.ImportOperation.replace : exports.ImportOperation.add,\n };\n p.children = ['meshes', 'materials', 'lights', 'viewpoints'].flatMap(childProp => {\n const childArr = node[childProp];\n return childArr\n ? childArr.map(c => {\n const cNode = processNode(c, childProp === 'meshes' ? namePath : '');\n cNode.parent = p;\n return cNode;\n })\n : [];\n });\n return p;\n };\n const pathToImportParent = parent.getNamePath();\n imported.scene['$type'] = 'SceneNode';\n return processNode(imported.scene, pathToImportParent).children;\n }\n import(previews, parentNode, root = true) {\n const nMap = this.getNodeNamePathMap();\n // Materials have to come first so we know how they reconnect to the meshes to them\n previews.sort((a, b) => {\n if (a.type.isMaterial() && !b.type.isMaterial()) {\n return -1;\n }\n else {\n return 0;\n }\n });\n for (const p of previews) {\n if (p.operation !== exports.ImportOperation.ignore) {\n let thisNode;\n if (p.operation === exports.ImportOperation.add || !p.matchingNode) {\n const parentPath = p.namePath.substring(0, p.namePath.lastIndexOf('/'));\n let parent;\n if (!parentPath) {\n parent = parentNode;\n }\n else if (p.type.isLight()) {\n parent = nMap.lights.get(parentPath);\n }\n else if (p.type.isMaterial()) {\n parent = nMap.materials.get(parentPath);\n }\n else {\n parent = nMap.meshes.get(parentPath);\n }\n const newNode = this.deserialize(p.node, { includeChildNodes: false });\n if (instanceOfAny(newNode, ...Token.GlobalLightTokens) &&\n instanceOf(parentNode, Token.SceneNode)) {\n parentNode.lights.push(newNode);\n }\n else if ((parent === null || parent === void 0 ? void 0 : parent.id) === parentNode.id) {\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.addChildren(newNode);\n }\n thisNode = newNode;\n }\n else {\n // replace\n const originalId = p.matchingNode.id;\n const matchingMeshNode = isMeshNode(p.matchingNode) ? p.matchingNode : undefined;\n const originalMaterialId = matchingMeshNode ? matchingMeshNode.materialId : undefined;\n this.assign(p.matchingNode, p.node, { includeChildNodes: false });\n p.matchingNode.id = originalId;\n // If the new materialId from the import exists, that means the material was imported and added and can be used.\n // If the new materialId from the import does not exist, use the old materialId because the material was updated but\n // kept the original ID.\n if (matchingMeshNode && originalMaterialId && matchingMeshNode.materialId) {\n if (!this.getById(matchingMeshNode.materialId)) {\n matchingMeshNode.materialId = originalMaterialId;\n }\n }\n // Trigger change detection on this existing node\n if (isTrackedClass(p.matchingNode)) {\n p.matchingNode.isModified = true;\n }\n thisNode = p.matchingNode;\n }\n if (thisNode instanceof exports.SpaceNode || thisNode instanceof exports.MaterialNode) {\n this.import(p.children, thisNode, false);\n }\n else if (p.children && p.children.length > 0) {\n throw Error('Children on non-space node or non-material-node, how did this happen');\n }\n }\n }\n }\n initializeModel(model, args, modelDef, options) {\n this.setModelDefaultValues(model);\n this.assign(model, args, options);\n }\n setModelDefaultValues(o) {\n const values = defaults[o.$type];\n if (values) {\n for (const prop in values) {\n if (values[prop] && values[prop].$type) {\n o[prop] = this.deserialize(values[prop]);\n }\n else if (isObject$1(values[prop])) {\n o[prop] = { ...values[prop] }; //need to clone the object from default values otherwise the class and defaults will both be pointing to same instance!\n }\n else {\n o[prop] = values[prop];\n }\n }\n }\n }\n assign(model, args, options) {\n options = {\n includeChildNodes: true,\n issueNewIds: false,\n copyingToDifferentNode: false,\n ...options,\n };\n if (args) {\n if (options.copyingToDifferentNode) {\n // If we are using assign to copy properties from one node to another, serialize the data\n if (args instanceof exports.Kb3dObject) {\n const defaultValues = { $type: args.$type };\n this.setModelDefaultValues(defaultValues);\n args = { ...defaultValues, ...this.serialize(args) };\n }\n }\n for (const prop in args) {\n // Never persist properties beginning with an underscore\n if (prop.substr(0, 1) == '_')\n continue;\n if (options.copyingToDifferentNode) {\n if ((prop.isEqual('id') && model.id) || prop.isEqual('$type')) {\n continue; // skip id's if copying to an existing node so the node retains its ID\n }\n }\n if (options.issueNewIds && prop.isEqual('id') && args.$type)\n continue; //skip id's if options specify so it will use the new one it generates during construction\n const sourceProp = args[prop];\n if (typeof model === 'undefined') {\n throw Error(); // this should never happen, this means a reference is being lost somewhere\n }\n if (prop === 'parent' || sourceProp === model[prop]) {\n // Don't break parent relationships\n continue; // Don't break parent relationships\n }\n if (!isObject$1(args[prop])) {\n // For primitives, just copy the values over\n model[prop] = args[prop];\n }\n else if (Array.isArray(sourceProp)) {\n // make sure there is an array on target prop. Recreate it if one is there already.\n if (model[prop]) {\n if (options.includeChildNodes ||\n !(model[prop].length > 0 &&\n model[prop][0].$type &&\n Token.withKey(model[prop][0].$type).isNode())) {\n model[prop].clear();\n }\n }\n else {\n model[prop] = [];\n }\n for (const sourceItem of sourceProp) {\n let targetItem;\n if (sourceItem.$type) {\n //it's one of our types so deserialize it\n if (options.includeChildNodes || !Token.withKey(sourceItem.$type).isNode()) {\n targetItem = this.deserialize(sourceItem, options);\n model[prop].push(targetItem);\n }\n }\n else if (isObject$1(sourceItem)) {\n targetItem = {};\n model[prop].push(targetItem);\n this.assign(targetItem, sourceItem, options);\n }\n else {\n //primitive type\n model[prop].push(sourceItem);\n }\n }\n }\n else {\n if (sourceProp.$type) {\n //it's one of our types so deserialize it\n if (options.includeChildNodes || !Token.withKey(sourceProp.$type).isNode()) {\n model[prop] = this.deserialize(sourceProp, options);\n }\n }\n else if (isObject$1(sourceProp)) {\n const targetItem = {};\n model[prop] = targetItem;\n this.assign(targetItem, sourceProp, options);\n }\n else {\n //primitive type\n model[prop] = sourceProp;\n }\n }\n }\n }\n }\n shallowEquals(a, b) {\n if (!isObject$1(a)) {\n return a === b;\n }\n for (const aProp in a) {\n if (aProp.substring(0, 1) !== '_') {\n if (!(aProp in b)) {\n return false;\n }\n if (a[aProp] !== b[aProp]) {\n return false;\n }\n }\n }\n for (const bProp in b) {\n if (bProp.substring(0, 1) !== '_') {\n if (!(bProp in a)) {\n return false;\n }\n if (b[bProp] !== a[bProp]) {\n return false;\n }\n }\n }\n return true;\n }\n }\n\n class ShadowLightNode extends exports.LightNode {\n constructor() {\n super();\n }\n }\n\n exports.DirectionalLightNode = class DirectionalLightNode extends ShadowLightNode {\n constructor() {\n super();\n }\n };\n exports.DirectionalLightNode = __decorate([\n Kb3dModel({\n token: Token.DirectionalLightNode,\n })\n ], exports.DirectionalLightNode);\n\n exports.HemisphericLightNode = class HemisphericLightNode extends exports.LightNode {\n constructor() {\n super();\n }\n };\n exports.HemisphericLightNode = __decorate([\n Kb3dModel({\n token: Token.HemisphericLightNode,\n })\n ], exports.HemisphericLightNode);\n\n exports.PointLightNode = class PointLightNode extends ShadowLightNode {\n constructor() {\n super();\n }\n };\n exports.PointLightNode = __decorate([\n Kb3dModel({\n token: Token.PointLightNode,\n })\n ], exports.PointLightNode);\n\n exports.SpotLightNode = class SpotLightNode extends exports.DirectionalLightNode {\n constructor() {\n super();\n }\n };\n exports.SpotLightNode = __decorate([\n Kb3dModel({\n token: Token.SpotLightNode,\n })\n ], exports.SpotLightNode);\n\n exports.TextureLayer = class TextureLayer extends exports.MaterialMapping {\n constructor() {\n super(...arguments);\n this._init = false;\n this._external = false;\n }\n init(parent) {\n if (!this._init) {\n this._parent = parent;\n // Normally this function is called when the node is added to an array on the parent, but textures live in defined properties on a material.\n // So we have to explicitly call it here, on texture init. The texture won't be doing anything before init anyways.\n this.calculateParents();\n if (isTrackedClass(this)) {\n // Always track changes on initialized textures because they may be attached to global materials\n this.trackChanges(true);\n this._init = true;\n }\n }\n }\n };\n __decorate([\n IgnoreHistory\n ], exports.TextureLayer.prototype, \"_init\", void 0);\n __decorate([\n IgnoreHistory\n ], exports.TextureLayer.prototype, \"_external\", void 0);\n exports.TextureLayer = __decorate([\n BaseKb3dModel({\n token: Token.TextureLayer,\n })\n ], exports.TextureLayer);\n function isTextureLayer(node) {\n return instanceOfAny(node, ...Token.TextureLayerTokens);\n }\n\n exports.AdvancedMaterialNode = class AdvancedMaterialNode extends exports.MaterialNode {\n constructor(_materialService) {\n super(_materialService);\n this._initialized = false;\n this._initialized = false;\n }\n get materials() {\n if (!this._materials)\n this._materials = [];\n return this._materials;\n }\n set materials(val) {\n this._materials = val;\n }\n };\n __decorate([\n Enumerable()\n ], exports.AdvancedMaterialNode.prototype, \"materials\", null);\n __decorate([\n IgnoreChanges\n ], exports.AdvancedMaterialNode.prototype, \"_initialized\", void 0);\n exports.AdvancedMaterialNode = __decorate([\n Kb3dModel({\n token: Token.AdvancedMaterialNode,\n onSerializing: (node, o) => {\n var _a;\n if (node.parentMaterialId == null) {\n return true;\n }\n // remove any textures that are from the parent material\n o.textures = (_a = o.textures) === null || _a === void 0 ? void 0 : _a.filter(texture => !texture._external);\n // remove any properties from the serialization that are inherited from a global or library material\n const keys = Object.keys(o);\n for (const p of keys) {\n if (node._overriddenPropertiesSet && !node._overriddenPropertiesSet.has(p) && p !== 'textures') {\n delete o[p];\n }\n }\n if (node._overriddenPropertiesSet) {\n o.overriddenProperties = Array.from(node._overriddenPropertiesSet).map(val => val.toString());\n }\n return node.location == exports.eMaterialLocation.local;\n },\n addedToChildArray: (node, child) => {\n if (child instanceof exports.TextureLayer) {\n if (node._initialized) {\n child.init(node);\n }\n }\n },\n afterCreate: node => {\n node.overriddenProperties.forEach(val => node._overriddenPropertiesSet.add(val));\n node.calculateParents(); //parents need to be calculated again because the texture children don't exist yet the first time it is run\n node.refreshParentMaterial();\n },\n }),\n __param(0, Inject(Token.MaterialService))\n ], exports.AdvancedMaterialNode);\n\n exports.ColorFillTextureLayer = class ColorFillTextureLayer extends exports.TextureLayer {\n };\n exports.ColorFillTextureLayer = __decorate([\n Kb3dModel({\n token: Token.ColorFillTextureLayer,\n })\n ], exports.ColorFillTextureLayer);\n\n exports.FileTextureLayer = class FileTextureLayer extends exports.TextureLayer {\n constructor() {\n super(...arguments);\n this.path = '';\n this._needsImageUpdate = false;\n this.flipNormalsRg = false;\n }\n };\n __decorate([\n IgnoreChanges\n ], exports.FileTextureLayer.prototype, \"_needsImageUpdate\", void 0);\n __decorate([\n IgnoreHistory\n ], exports.FileTextureLayer.prototype, \"_buffer\", void 0);\n exports.FileTextureLayer = __decorate([\n Kb3dModel({\n token: Token.FileTextureLayer,\n onSerializing: (node, o) => {\n return !node._external; // TODO Copy this to other layer types\n },\n })\n ], exports.FileTextureLayer);\n\n exports.SvgTextureLayer = class SvgTextureLayer extends exports.TextureLayer {\n constructor() {\n super(...arguments);\n this.svgXml = '';\n this.height = 256;\n this.width = 256;\n this.preloadFontStylesheet = '';\n }\n };\n exports.SvgTextureLayer = __decorate([\n Kb3dModel({\n token: Token.SvgTextureLayer,\n })\n ], exports.SvgTextureLayer);\n\n exports.TextTextureLayer = class TextTextureLayer extends exports.TextureLayer {\n };\n exports.TextTextureLayer = __decorate([\n Kb3dModel({\n token: Token.TextTextureLayer,\n })\n ], exports.TextTextureLayer);\n\n exports.MateNode = class MateNode extends exports.Kb3dObject {\n constructor() {\n super();\n }\n getC1() {\n var _a;\n return (_a = this._manager) === null || _a === void 0 ? void 0 : _a.getById(this.connector1);\n }\n getC2() {\n var _a;\n return (_a = this._manager) === null || _a === void 0 ? void 0 : _a.getById(this.connector2);\n }\n isActive() {\n return this.enabled && this.getC1() != null && this.getC2() != null;\n }\n };\n __decorate([\n NodeReference(exports.BaseConnector, 'position', 'direction', 'angle')\n ], exports.MateNode.prototype, \"connector1\", void 0);\n __decorate([\n NodeReference(exports.BaseConnector, 'position', 'direction', 'angle')\n ], exports.MateNode.prototype, \"connector2\", void 0);\n __decorate([\n IgnoreChanges\n ], exports.MateNode.prototype, \"_swap\", void 0);\n exports.MateNode = __decorate([\n Kb3dModel({\n token: Token.MateNode,\n validate: (n, v) => {\n var _a, _b, _c, _d, _e, _f, _g;\n if (n.changes.hasAny('connector1', 'connector2')) {\n v.assert(n, 'connector1', n.connector1 != null && ((_a = n._manager) === null || _a === void 0 ? void 0 : _a.getById(n.connector1)) != null, 'Connector is required');\n v.assert(n, 'connector2', n.connector2 != null && ((_b = n._manager) === null || _b === void 0 ? void 0 : _b.getById(n.connector2)) != null, 'Connector is required');\n v.assert(n, 'connector2', ((_d = (_c = n._manager) === null || _c === void 0 ? void 0 : _c.getById(n.connector1)) === null || _d === void 0 ? void 0 : _d._parent) !== ((_f = (_e = n._manager) === null || _e === void 0 ? void 0 : _e.getById(n.connector2)) === null || _f === void 0 ? void 0 : _f._parent) ||\n ((_g = n._manager) === null || _g === void 0 ? void 0 : _g.getById(n.connector1)) == null, 'Connectors cannot have the same parent node');\n }\n },\n })\n ], exports.MateNode);\n function isMate(node) {\n return instanceOf(node, Token.MateNode);\n }\n\n class Validator {\n constructor() {\n this.vmap = new Map();\n }\n getAll() {\n return this.vmap;\n }\n validateNode(node) {\n const model = Kb3dModels.get(node._token);\n if (model && model.validate) {\n model.validate(node, this);\n }\n }\n nodeIsValid(node) {\n return (!this.vmap.has(node.id) ||\n !this.vmap.get(node.id).size ||\n [...this.vmap.get(node.id).values()].every(a => a == null || a.length == 0));\n }\n getErrors(nodeId, prop) {\n var _a;\n return (_a = this.vmap.get(nodeId)) === null || _a === void 0 ? void 0 : _a.get(prop);\n }\n /** removes all validation errors for the given property */\n clearProp(node, prop) {\n var _a;\n if (this.vmap.has(node.id) && this.vmap.get(node.id).has(prop)) {\n (_a = this.vmap.get(node.id)) === null || _a === void 0 ? void 0 : _a.delete(prop);\n }\n return this;\n }\n /** removes a specific validation errors for the given property */\n clearPropError(node, prop, ...errors) {\n return this.clearPropErrorWhere(node, prop, e => e.equalsAny(...errors));\n }\n clearPropErrorWhere(node, prop, predicate) {\n var _a, _b;\n if (this.vmap.has(node.id) && this.vmap.get(node.id).has(prop)) {\n (_b = (_a = this.vmap\n .get(node.id)) === null || _a === void 0 ? void 0 : _a.get(prop)) === null || _b === void 0 ? void 0 : _b.removeWhere(e => predicate(e));\n }\n return this;\n }\n clearNode(node) {\n this.vmap.delete(node.id);\n }\n addError(node, prop, ...errors) {\n if (!this.vmap.has(node.id)) {\n this.vmap.set(node.id, new Map());\n }\n const entry = this.vmap.get(node.id);\n const sprop = prop;\n if (!entry.has(sprop)) {\n entry.set(sprop, [...errors]);\n }\n else {\n const existingErrors = entry.get(sprop);\n for (const err of errors) {\n if (!existingErrors.contains(err)) {\n existingErrors.push(err);\n }\n }\n }\n return this;\n }\n assert(node, prop, expression, ...errors) {\n if (expression) {\n this.clearPropError(node, prop, ...errors);\n }\n else {\n this.addError(node, prop, ...errors);\n }\n return this;\n }\n }\n\n exports.ViewpointNode = class ViewpointNode extends exports.Kb3dObject {\n constructor() {\n super();\n this.offsetX = 0; // For panning\n this.offsetY = 0;\n this.allowOrbit = true;\n this.allowPan = true;\n this.allowZoom = true;\n this.limitMinimumTargetDistance = false;\n this.limitLatOrbit = false;\n this.limitLngOrbit = false;\n this.type = exports.eViewpointType.orbit;\n this.targetMode = exports.eViewpointTargetMode.point;\n this.position = exports.KbVector.Zero();\n this.rotation = exports.KbVector.Zero();\n this.targetPoint = exports.KbVector.Zero();\n this.fov = defaults.ViewpointNode.fov;\n this.projection = exports.eViewpointProjection.perspective;\n }\n get type() {\n return this._type;\n }\n set type(newType) {\n this._type = newType;\n switch (newType) {\n case exports.eViewpointType.firstPerson:\n this.targetMode = exports.eViewpointTargetMode.rotation;\n this.projection = exports.eViewpointProjection.perspective;\n break;\n }\n }\n };\n __decorate([\n Enumerable()\n ], exports.ViewpointNode.prototype, \"type\", null);\n exports.ViewpointNode = __decorate([\n Kb3dModel({\n token: Token.ViewpointNode,\n onSerializing: (node, o) => {\n // remove any target properties not relevant to the target mode\n if (node.targetMode === exports.eViewpointTargetMode.rotation) {\n delete o.targetPoint;\n delete node.targetMeshId;\n }\n else if (node.targetMode === exports.eViewpointTargetMode.point) {\n delete o.rotation;\n delete node.targetMeshId;\n }\n else if (node.targetMode === exports.eViewpointTargetMode.mesh) {\n delete o.targetPoint;\n delete o.rotation;\n }\n return true;\n },\n validate: (n, v) => {\n var _a;\n if (n.changes.hasAny('targetMode', 'targetMeshId')) {\n const exp = n.targetMode != exports.eViewpointTargetMode.mesh ||\n (n.targetMeshId != null && ((_a = n._manager) === null || _a === void 0 ? void 0 : _a.getById(n.targetMeshId)) != null);\n v.assert(n, 'targetMeshId', exp, 'Target mesh required');\n }\n },\n })\n ], exports.ViewpointNode);\n function isViewpointNode(node) {\n return instanceOf(node, Token.ViewpointNode);\n }\n\n /**\n * Does a topological sort of directed graph with cycle detection and warning.\n * @param nodes a map where the key is the node and value is an array containing the nodes the key node depends on\n * @param nameSelector function that returns a descriptive name for the node\n */\n function topologicalSort(nodes, nameSelector) {\n const visited = new Set();\n const path = new Set();\n const sorted = new Set();\n const cycles = new Array();\n for (const [node] of nodes) {\n recurse(nodes, nameSelector, node, visited, path, sorted, cycles);\n }\n // console.log(`Original graph: ${getDescriptor(nameSelector, ...nodes.keys())}`);\n // console.log(`Sorted graph: ${getDescriptor(nameSelector, ...sorted)}`);\n return {\n sorted,\n cycles,\n };\n }\n function recurse(nodes, nameSelector, node, visited, path, sorted, cycles) {\n if (path.has(node)) {\n const items = [...path].reverse();\n cycles.push(items);\n //console.warn(`Cycle detected: ${getDescriptor(nameSelector, ...path, node)}`);\n }\n if (visited.has(node))\n return;\n visited.add(node);\n path.add(node);\n const edges = nodes.get(node);\n if (edges) {\n for (const edge of edges) {\n recurse(nodes, nameSelector, edge, visited, path, sorted, cycles);\n }\n }\n path.delete(node);\n sorted.add(node);\n }\n // function getDescriptor(nameSelector: (n: any) => string, ...nodes: any[]){\n // return nodes.map(n => nameSelector(n)).join(\" -> \");\n // }\n\n /**\n * Base class of all the textures in babylon.\n * It groups all the common properties required to work with Thin Engine.\n */\n class ThinTexture {\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapU() {\n return this._wrapU;\n }\n set wrapU(value) {\n this._wrapU = value;\n }\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapV() {\n return this._wrapV;\n }\n set wrapV(value) {\n this._wrapV = value;\n }\n /**\n * How a texture is mapped.\n * Unused in thin texture mode.\n */\n get coordinatesMode() {\n return 0;\n }\n /**\n * Define if the texture is a cube texture or if false a 2d texture.\n */\n get isCube() {\n if (!this._texture) {\n return false;\n }\n return this._texture.isCube;\n }\n set isCube(value) {\n if (!this._texture) {\n return;\n }\n this._texture.isCube = value;\n }\n /**\n * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.\n */\n get is3D() {\n if (!this._texture) {\n return false;\n }\n return this._texture.is3D;\n }\n set is3D(value) {\n if (!this._texture) {\n return;\n }\n this._texture.is3D = value;\n }\n /**\n * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.\n */\n get is2DArray() {\n if (!this._texture) {\n return false;\n }\n return this._texture.is2DArray;\n }\n set is2DArray(value) {\n if (!this._texture) {\n return;\n }\n this._texture.is2DArray = value;\n }\n /**\n * Get the class name of the texture.\n * @returns \"ThinTexture\"\n */\n getClassName() {\n return \"ThinTexture\";\n }\n static _IsRenderTargetWrapper(texture) {\n return (texture === null || texture === void 0 ? void 0 : texture._shareDepth) !== undefined;\n }\n /**\n * Instantiates a new ThinTexture.\n * Base class of all the textures in babylon.\n * This can be used as an internal texture wrapper in ThinEngine to benefit from the cache\n * @param internalTexture Define the internalTexture to wrap. You can also pass a RenderTargetWrapper, in which case the texture will be the render target's texture\n */\n constructor(internalTexture) {\n this._wrapU = 1;\n this._wrapV = 1;\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n this.wrapR = 1;\n /**\n * With compliant hardware and browser (supporting anisotropic filtering)\n * this defines the level of anisotropic filtering in the texture.\n * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.\n */\n this.anisotropicFilteringLevel = 4;\n /**\n * Define the current state of the loading sequence when in delayed load mode.\n */\n this.delayLoadState = 0;\n /** @internal */\n this._texture = null;\n this._engine = null;\n this._cachedSize = Size.Zero();\n this._cachedBaseSize = Size.Zero();\n /** @internal */\n this._initialSamplingMode = 2;\n this._texture = ThinTexture._IsRenderTargetWrapper(internalTexture) ? internalTexture.texture : internalTexture;\n if (this._texture) {\n this._engine = this._texture.getEngine();\n }\n }\n /**\n * Get if the texture is ready to be used (downloaded, converted, mip mapped...).\n * @returns true if fully ready\n */\n isReady() {\n if (this.delayLoadState === 4) {\n this.delayLoad();\n return false;\n }\n if (this._texture) {\n return this._texture.isReady;\n }\n return false;\n }\n /**\n * Triggers the load sequence in delayed load mode.\n */\n delayLoad() { }\n /**\n * Get the underlying lower level texture from Babylon.\n * @returns the internal texture\n */\n getInternalTexture() {\n return this._texture;\n }\n /**\n * Get the size of the texture.\n * @returns the texture size.\n */\n getSize() {\n if (this._texture) {\n if (this._texture.width) {\n this._cachedSize.width = this._texture.width;\n this._cachedSize.height = this._texture.height;\n return this._cachedSize;\n }\n if (this._texture._size) {\n this._cachedSize.width = this._texture._size;\n this._cachedSize.height = this._texture._size;\n return this._cachedSize;\n }\n }\n return this._cachedSize;\n }\n /**\n * Get the base size of the texture.\n * It can be different from the size if the texture has been resized for POT for instance\n * @returns the base size\n */\n getBaseSize() {\n if (!this.isReady() || !this._texture) {\n this._cachedBaseSize.width = 0;\n this._cachedBaseSize.height = 0;\n return this._cachedBaseSize;\n }\n if (this._texture._size) {\n this._cachedBaseSize.width = this._texture._size;\n this._cachedBaseSize.height = this._texture._size;\n return this._cachedBaseSize;\n }\n this._cachedBaseSize.width = this._texture.baseWidth;\n this._cachedBaseSize.height = this._texture.baseHeight;\n return this._cachedBaseSize;\n }\n /**\n * Get the current sampling mode associated with the texture.\n */\n get samplingMode() {\n if (!this._texture) {\n return this._initialSamplingMode;\n }\n return this._texture.samplingMode;\n }\n /**\n * Update the sampling mode of the texture.\n * Default is Trilinear mode.\n *\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 1 | NEAREST_SAMPLINGMODE or NEAREST_NEAREST_MIPLINEAR | Nearest is: mag = nearest, min = nearest, mip = linear |\n * | 2 | BILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPNEAREST | Bilinear is: mag = linear, min = linear, mip = nearest |\n * | 3 | TRILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPLINEAR | Trilinear is: mag = linear, min = linear, mip = linear |\n * | 4 | NEAREST_NEAREST_MIPNEAREST | |\n * | 5 | NEAREST_LINEAR_MIPNEAREST | |\n * | 6 | NEAREST_LINEAR_MIPLINEAR | |\n * | 7 | NEAREST_LINEAR | |\n * | 8 | NEAREST_NEAREST | |\n * | 9 | LINEAR_NEAREST_MIPNEAREST | |\n * | 10 | LINEAR_NEAREST_MIPLINEAR | |\n * | 11 | LINEAR_LINEAR | |\n * | 12 | LINEAR_NEAREST | |\n *\n * > _mag_: magnification filter (close to the viewer)\n * > _min_: minification filter (far from the viewer)\n * > _mip_: filter used between mip map levels\n *@param samplingMode Define the new sampling mode of the texture\n */\n updateSamplingMode(samplingMode) {\n if (this._texture && this._engine) {\n this._engine.updateTextureSamplingMode(samplingMode, this._texture);\n }\n }\n /**\n * Release and destroy the underlying lower level texture aka internalTexture.\n */\n releaseInternalTexture() {\n if (this._texture) {\n this._texture.dispose();\n this._texture = null;\n }\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n if (this._texture) {\n this.releaseInternalTexture();\n this._engine = null;\n }\n }\n }\n\n /**\n * Base class of all the textures in babylon.\n * It groups all the common properties the materials, post process, lights... might need\n * in order to make a correct use of the texture.\n */\n class BaseTexture extends ThinTexture {\n /**\n * Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).\n */\n set hasAlpha(value) {\n if (this._hasAlpha === value) {\n return;\n }\n this._hasAlpha = value;\n if (this._scene) {\n this._scene.markAllMaterialsAsDirty(1, (mat) => {\n return mat.hasTexture(this);\n });\n }\n }\n get hasAlpha() {\n return this._hasAlpha;\n }\n /**\n * Defines if the alpha value should be determined via the rgb values.\n * If true the luminance of the pixel might be used to find the corresponding alpha value.\n */\n set getAlphaFromRGB(value) {\n if (this._getAlphaFromRGB === value) {\n return;\n }\n this._getAlphaFromRGB = value;\n if (this._scene) {\n this._scene.markAllMaterialsAsDirty(1, (mat) => {\n return mat.hasTexture(this);\n });\n }\n }\n get getAlphaFromRGB() {\n return this._getAlphaFromRGB;\n }\n /**\n * Define the UV channel to use starting from 0 and defaulting to 0.\n * This is part of the texture as textures usually maps to one uv set.\n */\n set coordinatesIndex(value) {\n if (this._coordinatesIndex === value) {\n return;\n }\n this._coordinatesIndex = value;\n if (this._scene) {\n this._scene.markAllMaterialsAsDirty(1, (mat) => {\n return mat.hasTexture(this);\n });\n }\n }\n get coordinatesIndex() {\n return this._coordinatesIndex;\n }\n /**\n * How a texture is mapped.\n *\n * | Value | Type | Description |\n * | ----- | ----------------------------------- | ----------- |\n * | 0 | EXPLICIT_MODE | |\n * | 1 | SPHERICAL_MODE | |\n * | 2 | PLANAR_MODE | |\n * | 3 | CUBIC_MODE | |\n * | 4 | PROJECTION_MODE | |\n * | 5 | SKYBOX_MODE | |\n * | 6 | INVCUBIC_MODE | |\n * | 7 | EQUIRECTANGULAR_MODE | |\n * | 8 | FIXED_EQUIRECTANGULAR_MODE | |\n * | 9 | FIXED_EQUIRECTANGULAR_MIRRORED_MODE | |\n */\n set coordinatesMode(value) {\n if (this._coordinatesMode === value) {\n return;\n }\n this._coordinatesMode = value;\n if (this._scene) {\n this._scene.markAllMaterialsAsDirty(1, (mat) => {\n return mat.hasTexture(this);\n });\n }\n }\n get coordinatesMode() {\n return this._coordinatesMode;\n }\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapU() {\n return this._wrapU;\n }\n set wrapU(value) {\n this._wrapU = value;\n }\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n get wrapV() {\n return this._wrapV;\n }\n set wrapV(value) {\n this._wrapV = value;\n }\n /**\n * Define if the texture is a cube texture or if false a 2d texture.\n */\n get isCube() {\n if (!this._texture) {\n return this._isCube;\n }\n return this._texture.isCube;\n }\n set isCube(value) {\n if (!this._texture) {\n this._isCube = value;\n }\n else {\n this._texture.isCube = value;\n }\n }\n /**\n * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.\n */\n get is3D() {\n if (!this._texture) {\n return false;\n }\n return this._texture.is3D;\n }\n set is3D(value) {\n if (!this._texture) {\n return;\n }\n this._texture.is3D = value;\n }\n /**\n * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.\n */\n get is2DArray() {\n if (!this._texture) {\n return false;\n }\n return this._texture.is2DArray;\n }\n set is2DArray(value) {\n if (!this._texture) {\n return;\n }\n this._texture.is2DArray = value;\n }\n /**\n * Define if the texture contains data in gamma space (most of the png/jpg aside bump).\n * HDR texture are usually stored in linear space.\n * This only impacts the PBR and Background materials\n */\n get gammaSpace() {\n if (!this._texture) {\n return this._gammaSpace;\n }\n else {\n if (this._texture._gammaSpace === null) {\n this._texture._gammaSpace = this._gammaSpace;\n }\n }\n return this._texture._gammaSpace && !this._texture._useSRGBBuffer;\n }\n set gammaSpace(gamma) {\n if (!this._texture) {\n if (this._gammaSpace === gamma) {\n return;\n }\n this._gammaSpace = gamma;\n }\n else {\n if (this._texture._gammaSpace === gamma) {\n return;\n }\n this._texture._gammaSpace = gamma;\n }\n this._markAllSubMeshesAsTexturesDirty();\n }\n /**\n * Gets or sets whether or not the texture contains RGBD data.\n */\n get isRGBD() {\n return this._texture != null && this._texture._isRGBD;\n }\n set isRGBD(value) {\n if (this._texture) {\n this._texture._isRGBD = value;\n }\n }\n /**\n * Are mip maps generated for this texture or not.\n */\n get noMipmap() {\n return false;\n }\n /**\n * With prefiltered texture, defined the offset used during the prefiltering steps.\n */\n get lodGenerationOffset() {\n if (this._texture) {\n return this._texture._lodGenerationOffset;\n }\n return 0.0;\n }\n set lodGenerationOffset(value) {\n if (this._texture) {\n this._texture._lodGenerationOffset = value;\n }\n }\n /**\n * With prefiltered texture, defined the scale used during the prefiltering steps.\n */\n get lodGenerationScale() {\n if (this._texture) {\n return this._texture._lodGenerationScale;\n }\n return 0.0;\n }\n set lodGenerationScale(value) {\n if (this._texture) {\n this._texture._lodGenerationScale = value;\n }\n }\n /**\n * With prefiltered texture, defined if the specular generation is based on a linear ramp.\n * By default we are using a log2 of the linear roughness helping to keep a better resolution for\n * average roughness values.\n */\n get linearSpecularLOD() {\n if (this._texture) {\n return this._texture._linearSpecularLOD;\n }\n return false;\n }\n set linearSpecularLOD(value) {\n if (this._texture) {\n this._texture._linearSpecularLOD = value;\n }\n }\n /**\n * In case a better definition than spherical harmonics is required for the diffuse part of the environment.\n * You can set the irradiance texture to rely on a texture instead of the spherical approach.\n * This texture need to have the same characteristics than its parent (Cube vs 2d, coordinates mode, Gamma/Linear, RGBD).\n */\n get irradianceTexture() {\n if (this._texture) {\n return this._texture._irradianceTexture;\n }\n return null;\n }\n set irradianceTexture(value) {\n if (this._texture) {\n this._texture._irradianceTexture = value;\n }\n }\n /**\n * Define the unique id of the texture in the scene.\n */\n get uid() {\n if (!this._uid) {\n this._uid = RandomGUID();\n }\n return this._uid;\n }\n /**\n * Return a string representation of the texture.\n * @returns the texture as a string\n */\n toString() {\n return this.name;\n }\n /**\n * Get the class name of the texture.\n * @returns \"BaseTexture\"\n */\n getClassName() {\n return \"BaseTexture\";\n }\n /**\n * Callback triggered when the texture has been disposed.\n * Kept for back compatibility, you can use the onDisposeObservable instead.\n */\n set onDispose(callback) {\n if (this._onDisposeObserver) {\n this.onDisposeObservable.remove(this._onDisposeObserver);\n }\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\n }\n /**\n * Define if the texture is preventing a material to render or not.\n * If not and the texture is not ready, the engine will use a default black texture instead.\n */\n get isBlocking() {\n return true;\n }\n /**\n * Was there any loading error?\n */\n get loadingError() {\n return this._loadingError;\n }\n /**\n * If a loading error occurred this object will be populated with information about the error.\n */\n get errorObject() {\n return this._errorObject;\n }\n /**\n * Instantiates a new BaseTexture.\n * Base class of all the textures in babylon.\n * It groups all the common properties the materials, post process, lights... might need\n * in order to make a correct use of the texture.\n * @param sceneOrEngine Define the scene or engine the texture belongs to\n * @param internalTexture Define the internal texture associated with the texture\n */\n constructor(sceneOrEngine, internalTexture = null) {\n super(null);\n /**\n * Gets or sets an object used to store user defined information.\n */\n this.metadata = null;\n /**\n * For internal use only. Please do not use.\n */\n this.reservedDataStore = null;\n this._hasAlpha = false;\n this._getAlphaFromRGB = false;\n /**\n * Intensity or strength of the texture.\n * It is commonly used by materials to fine tune the intensity of the texture\n */\n this.level = 1;\n this._coordinatesIndex = 0;\n /**\n * Gets or sets a boolean indicating that the texture should try to reduce shader code if there is no UV manipulation.\n * (ie. when texture.getTextureMatrix().isIdentityAs3x2() returns true)\n */\n this.optimizeUVAllocation = true;\n this._coordinatesMode = 0;\n /**\n * | Value | Type | Description |\n * | ----- | ------------------ | ----------- |\n * | 0 | CLAMP_ADDRESSMODE | |\n * | 1 | WRAP_ADDRESSMODE | |\n * | 2 | MIRROR_ADDRESSMODE | |\n */\n this.wrapR = 1;\n /**\n * With compliant hardware and browser (supporting anisotropic filtering)\n * this defines the level of anisotropic filtering in the texture.\n * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.\n */\n this.anisotropicFilteringLevel = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL;\n /** @internal */\n this._isCube = false;\n this._gammaSpace = true;\n /**\n * Is Z inverted in the texture (useful in a cube texture).\n */\n this.invertZ = false;\n /**\n * @internal\n */\n this.lodLevelInAlpha = false;\n /**\n * Define if the texture is a render target.\n */\n this.isRenderTarget = false;\n /** @internal */\n this._prefiltered = false;\n /** @internal */\n this._forceSerialize = false;\n /**\n * Define the list of animation attached to the texture.\n */\n this.animations = new Array();\n /**\n * An event triggered when the texture is disposed.\n */\n this.onDisposeObservable = new Observable$1();\n this._onDisposeObserver = null;\n this._scene = null;\n /** @internal */\n this._uid = null;\n /** @internal */\n this._parentContainer = null;\n this._loadingError = false;\n if (sceneOrEngine) {\n if (BaseTexture._IsScene(sceneOrEngine)) {\n this._scene = sceneOrEngine;\n }\n else {\n this._engine = sceneOrEngine;\n }\n }\n else {\n this._scene = EngineStore.LastCreatedScene;\n }\n if (this._scene) {\n this.uniqueId = this._scene.getUniqueId();\n this._scene.addTexture(this);\n this._engine = this._scene.getEngine();\n }\n this._texture = internalTexture;\n this._uid = null;\n }\n /**\n * Get the scene the texture belongs to.\n * @returns the scene or null if undefined\n */\n getScene() {\n return this._scene;\n }\n /** @internal */\n _getEngine() {\n return this._engine;\n }\n /**\n * Checks if the texture has the same transform matrix than another texture\n * @param texture texture to check against\n * @returns true if the transforms are the same, else false\n */\n checkTransformsAreIdentical(texture) {\n return texture !== null;\n }\n /**\n * Get the texture transform matrix used to offset tile the texture for instance.\n * @returns the transformation matrix\n */\n getTextureMatrix() {\n return Matrix.IdentityReadOnly;\n }\n /**\n * Get the texture reflection matrix used to rotate/transform the reflection.\n * @returns the reflection matrix\n */\n getReflectionTextureMatrix() {\n return Matrix.IdentityReadOnly;\n }\n /**\n * Gets a suitable rotate/transform matrix when the texture is used for refraction.\n * There's a separate function from getReflectionTextureMatrix because refraction requires a special configuration of the matrix in right-handed mode.\n * @returns The refraction matrix\n */\n getRefractionTextureMatrix() {\n return this.getReflectionTextureMatrix();\n }\n /**\n * Get if the texture is ready to be consumed (either it is ready or it is not blocking)\n * @returns true if ready, not blocking or if there was an error loading the texture\n */\n isReadyOrNotBlocking() {\n return !this.isBlocking || this.isReady() || this.loadingError;\n }\n /**\n * Scales the texture if is `canRescale()`\n * @param ratio the resize factor we want to use to rescale\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n scale(ratio) { }\n /**\n * Get if the texture can rescale.\n */\n get canRescale() {\n return false;\n }\n /**\n * @internal\n */\n _getFromCache(url, noMipmap, sampling, invertY, useSRGBBuffer, isCube) {\n const engine = this._getEngine();\n if (!engine) {\n return null;\n }\n const correctedUseSRGBBuffer = engine._getUseSRGBBuffer(!!useSRGBBuffer, noMipmap);\n const texturesCache = engine.getLoadedTexturesCache();\n for (let index = 0; index < texturesCache.length; index++) {\n const texturesCacheEntry = texturesCache[index];\n if (useSRGBBuffer === undefined || correctedUseSRGBBuffer === texturesCacheEntry._useSRGBBuffer) {\n if (invertY === undefined || invertY === texturesCacheEntry.invertY) {\n if (texturesCacheEntry.url === url && texturesCacheEntry.generateMipMaps === !noMipmap) {\n if (!sampling || sampling === texturesCacheEntry.samplingMode) {\n if (isCube === undefined || isCube === texturesCacheEntry.isCube) {\n texturesCacheEntry.incrementReferences();\n return texturesCacheEntry;\n }\n }\n }\n }\n }\n }\n return null;\n }\n /** @internal */\n _rebuild() { }\n /**\n * Clones the texture.\n * @returns the cloned texture\n */\n clone() {\n return null;\n }\n /**\n * Get the texture underlying type (INT, FLOAT...)\n */\n get textureType() {\n if (!this._texture) {\n return 0;\n }\n return this._texture.type !== undefined ? this._texture.type : 0;\n }\n /**\n * Get the texture underlying format (RGB, RGBA...)\n */\n get textureFormat() {\n if (!this._texture) {\n return 5;\n }\n return this._texture.format !== undefined ? this._texture.format : 5;\n }\n /**\n * Indicates that textures need to be re-calculated for all materials\n */\n _markAllSubMeshesAsTexturesDirty() {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n scene.markAllMaterialsAsDirty(1);\n }\n /**\n * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.\n * This will returns an RGBA array buffer containing either in values (0-255) or\n * float values (0-1) depending of the underlying buffer type.\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @param buffer defines a user defined buffer to fill with data (can be null)\n * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels\n * @param noDataConversion false to convert the data to Uint8Array (if texture type is UNSIGNED_BYTE) or to Float32Array (if texture type is anything but UNSIGNED_BYTE). If true, the type of the generated buffer (if buffer==null) will depend on the type of the texture\n * @param x defines the region x coordinates to start reading from (default to 0)\n * @param y defines the region y coordinates to start reading from (default to 0)\n * @param width defines the region width to read from (default to the texture size at level)\n * @param height defines the region width to read from (default to the texture size at level)\n * @returns The Array buffer promise containing the pixels data.\n */\n readPixels(faceIndex = 0, level = 0, buffer = null, flushRenderer = true, noDataConversion = false, x = 0, y = 0, width = Number.MAX_VALUE, height = Number.MAX_VALUE) {\n if (!this._texture) {\n return null;\n }\n const engine = this._getEngine();\n if (!engine) {\n return null;\n }\n const size = this.getSize();\n let maxWidth = size.width;\n let maxHeight = size.height;\n if (level !== 0) {\n maxWidth = maxWidth / Math.pow(2, level);\n maxHeight = maxHeight / Math.pow(2, level);\n maxWidth = Math.round(maxWidth);\n maxHeight = Math.round(maxHeight);\n }\n width = Math.min(maxWidth, width);\n height = Math.min(maxHeight, height);\n try {\n if (this._texture.isCube) {\n return engine._readTexturePixels(this._texture, width, height, faceIndex, level, buffer, flushRenderer, noDataConversion, x, y);\n }\n return engine._readTexturePixels(this._texture, width, height, -1, level, buffer, flushRenderer, noDataConversion, x, y);\n }\n catch (e) {\n return null;\n }\n }\n /**\n * @internal\n */\n _readPixelsSync(faceIndex = 0, level = 0, buffer = null, flushRenderer = true, noDataConversion = false) {\n if (!this._texture) {\n return null;\n }\n const size = this.getSize();\n let width = size.width;\n let height = size.height;\n const engine = this._getEngine();\n if (!engine) {\n return null;\n }\n if (level != 0) {\n width = width / Math.pow(2, level);\n height = height / Math.pow(2, level);\n width = Math.round(width);\n height = Math.round(height);\n }\n try {\n if (this._texture.isCube) {\n return engine._readTexturePixelsSync(this._texture, width, height, faceIndex, level, buffer, flushRenderer, noDataConversion);\n }\n return engine._readTexturePixelsSync(this._texture, width, height, -1, level, buffer, flushRenderer, noDataConversion);\n }\n catch (e) {\n return null;\n }\n }\n /** @internal */\n get _lodTextureHigh() {\n if (this._texture) {\n return this._texture._lodTextureHigh;\n }\n return null;\n }\n /** @internal */\n get _lodTextureMid() {\n if (this._texture) {\n return this._texture._lodTextureMid;\n }\n return null;\n }\n /** @internal */\n get _lodTextureLow() {\n if (this._texture) {\n return this._texture._lodTextureLow;\n }\n return null;\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n if (this._scene) {\n // Animations\n if (this._scene.stopAnimation) {\n this._scene.stopAnimation(this);\n }\n // Remove from scene\n this._scene.removePendingData(this);\n const index = this._scene.textures.indexOf(this);\n if (index >= 0) {\n this._scene.textures.splice(index, 1);\n }\n this._scene.onTextureRemovedObservable.notifyObservers(this);\n this._scene = null;\n if (this._parentContainer) {\n const index = this._parentContainer.textures.indexOf(this);\n if (index > -1) {\n this._parentContainer.textures.splice(index, 1);\n }\n this._parentContainer = null;\n }\n }\n // Callback\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n this.metadata = null;\n super.dispose();\n }\n /**\n * Serialize the texture into a JSON representation that can be parsed later on.\n * @param allowEmptyName True to force serialization even if name is empty. Default: false\n * @returns the JSON representation of the texture\n */\n serialize(allowEmptyName = false) {\n if (!this.name && !allowEmptyName) {\n return null;\n }\n const serializationObject = SerializationHelper.Serialize(this);\n // Animations\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\n return serializationObject;\n }\n /**\n * Helper function to be called back once a list of texture contains only ready textures.\n * @param textures Define the list of textures to wait for\n * @param callback Define the callback triggered once the entire list will be ready\n */\n static WhenAllReady(textures, callback) {\n let numRemaining = textures.length;\n if (numRemaining === 0) {\n callback();\n return;\n }\n for (let i = 0; i < textures.length; i++) {\n const texture = textures[i];\n if (texture.isReady()) {\n if (--numRemaining === 0) {\n callback();\n }\n }\n else {\n const onLoadObservable = texture.onLoadObservable;\n if (onLoadObservable) {\n onLoadObservable.addOnce(() => {\n if (--numRemaining === 0) {\n callback();\n }\n });\n }\n else {\n if (--numRemaining === 0) {\n callback();\n }\n }\n }\n }\n }\n static _IsScene(sceneOrEngine) {\n return sceneOrEngine.getClassName() === \"Scene\";\n }\n }\n /**\n * Default anisotropic filtering level for the application.\n * It is set to 4 as a good tradeoff between perf and quality.\n */\n BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL = 4;\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"uniqueId\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"name\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"metadata\", void 0);\n __decorate$1([\n serialize(\"hasAlpha\")\n ], BaseTexture.prototype, \"_hasAlpha\", void 0);\n __decorate$1([\n serialize(\"getAlphaFromRGB\")\n ], BaseTexture.prototype, \"_getAlphaFromRGB\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"level\", void 0);\n __decorate$1([\n serialize(\"coordinatesIndex\")\n ], BaseTexture.prototype, \"_coordinatesIndex\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"optimizeUVAllocation\", void 0);\n __decorate$1([\n serialize(\"coordinatesMode\")\n ], BaseTexture.prototype, \"_coordinatesMode\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"wrapU\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"wrapV\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"wrapR\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"anisotropicFilteringLevel\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"isCube\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"is3D\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"is2DArray\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"gammaSpace\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"invertZ\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"lodLevelInAlpha\", void 0);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"lodGenerationOffset\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"lodGenerationScale\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"linearSpecularLOD\", null);\n __decorate$1([\n serializeAsTexture()\n ], BaseTexture.prototype, \"irradianceTexture\", null);\n __decorate$1([\n serialize()\n ], BaseTexture.prototype, \"isRenderTarget\", void 0);\n\n /**\n * Transform some pixel data to a base64 string\n * @param pixels defines the pixel data to transform to base64\n * @param size defines the width and height of the (texture) data\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\n * @returns The base64 encoded string or null\n */\n function GenerateBase64StringFromPixelData(pixels, size, invertY = false) {\n const width = size.width;\n const height = size.height;\n if (pixels instanceof Float32Array) {\n let len = pixels.byteLength / pixels.BYTES_PER_ELEMENT;\n const npixels = new Uint8Array(len);\n while (--len >= 0) {\n let val = pixels[len];\n if (val < 0) {\n val = 0;\n }\n else if (val > 1) {\n val = 1;\n }\n npixels[len] = val * 255;\n }\n pixels = npixels;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n return null;\n }\n const imageData = ctx.createImageData(width, height);\n const castData = imageData.data;\n castData.set(pixels);\n ctx.putImageData(imageData, 0, 0);\n if (invertY) {\n const canvas2 = document.createElement(\"canvas\");\n canvas2.width = width;\n canvas2.height = height;\n const ctx2 = canvas2.getContext(\"2d\");\n if (!ctx2) {\n return null;\n }\n ctx2.translate(0, height);\n ctx2.scale(1, -1);\n ctx2.drawImage(canvas, 0, 0);\n return canvas2.toDataURL(\"image/png\");\n }\n return canvas.toDataURL(\"image/png\");\n }\n /**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null\n */\n function GenerateBase64StringFromTexture(texture, faceIndex = 0, level = 0) {\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return null;\n }\n const pixels = texture._readPixelsSync(faceIndex, level);\n if (!pixels) {\n return null;\n }\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\n }\n /**\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\n * @param texture defines the texture to read pixels from\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\n * @returns The base64 encoded string or null wrapped in a promise\n */\n async function GenerateBase64StringFromTextureAsync(texture, faceIndex = 0, level = 0) {\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return null;\n }\n const pixels = await texture.readPixels(faceIndex, level);\n if (!pixels) {\n return null;\n }\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\n }\n\n /**\n * This represents a texture in babylon. It can be easily loaded from a network, base64 or html input.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#texture\n */\n class Texture extends BaseTexture {\n /**\n * Are mip maps generated for this texture or not.\n */\n get noMipmap() {\n return this._noMipmap;\n }\n /** Returns the texture mime type if it was defined by a loader (undefined else) */\n get mimeType() {\n return this._mimeType;\n }\n /**\n * Is the texture preventing material to render while loading.\n * If false, a default texture will be used instead of the loading one during the preparation step.\n */\n set isBlocking(value) {\n this._isBlocking = value;\n }\n get isBlocking() {\n return this._isBlocking;\n }\n /**\n * Gets a boolean indicating if the texture needs to be inverted on the y axis during loading\n */\n get invertY() {\n return this._invertY;\n }\n /**\n * Instantiates a new texture.\n * This represents a texture in babylon. It can be easily loaded from a network, base64 or html input.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#texture\n * @param url defines the url of the picture to load as a texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param noMipmapOrOptions defines if the texture will require mip maps or not or set of all options to create the texture\n * @param invertY defines if the texture needs to be inverted on the y axis during loading\n * @param samplingMode defines the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)\n * @param onLoad defines a callback triggered when the texture has been loaded\n * @param onError defines a callback triggered when an error occurred during the loading session\n * @param buffer defines the buffer to load the texture from in case the texture is loaded from a buffer representation\n * @param deleteBuffer defines if the buffer we are loading the texture from should be deleted after load\n * @param format defines the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)\n * @param mimeType defines an optional mime type information\n * @param loaderOptions options to be passed to the loader\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @param forcedExtension defines the extension to use to pick the right loader\n */\n constructor(url, sceneOrEngine, noMipmapOrOptions, invertY, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, onLoad = null, onError = null, buffer = null, deleteBuffer = false, format, mimeType, loaderOptions, creationFlags, forcedExtension) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j;\n super(sceneOrEngine);\n /**\n * Define the url of the texture.\n */\n this.url = null;\n /**\n * Define an offset on the texture to offset the u coordinates of the UVs\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#offsetting\n */\n this.uOffset = 0;\n /**\n * Define an offset on the texture to offset the v coordinates of the UVs\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#offsetting\n */\n this.vOffset = 0;\n /**\n * Define an offset on the texture to scale the u coordinates of the UVs\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#tiling\n */\n this.uScale = 1.0;\n /**\n * Define an offset on the texture to scale the v coordinates of the UVs\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#tiling\n */\n this.vScale = 1.0;\n /**\n * Define an offset on the texture to rotate around the u coordinates of the UVs\n * The angle is defined in radians.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials\n */\n this.uAng = 0;\n /**\n * Define an offset on the texture to rotate around the v coordinates of the UVs\n * The angle is defined in radians.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials\n */\n this.vAng = 0;\n /**\n * Define an offset on the texture to rotate around the w coordinates of the UVs (in case of 3d texture)\n * The angle is defined in radians.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials\n */\n this.wAng = 0;\n /**\n * Defines the center of rotation (U)\n */\n this.uRotationCenter = 0.5;\n /**\n * Defines the center of rotation (V)\n */\n this.vRotationCenter = 0.5;\n /**\n * Defines the center of rotation (W)\n */\n this.wRotationCenter = 0.5;\n /**\n * Sets this property to true to avoid deformations when rotating the texture with non-uniform scaling\n */\n this.homogeneousRotationInUVTransform = false;\n /**\n * List of inspectable custom properties (used by the Inspector)\n * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility\n */\n this.inspectableCustomProperties = null;\n /** @internal */\n this._noMipmap = false;\n /** @internal */\n this._invertY = false;\n this._rowGenerationMatrix = null;\n this._cachedTextureMatrix = null;\n this._projectionModeMatrix = null;\n this._t0 = null;\n this._t1 = null;\n this._t2 = null;\n this._cachedUOffset = -1;\n this._cachedVOffset = -1;\n this._cachedUScale = 0;\n this._cachedVScale = 0;\n this._cachedUAng = -1;\n this._cachedVAng = -1;\n this._cachedWAng = -1;\n this._cachedReflectionProjectionMatrixId = -1;\n this._cachedURotationCenter = -1;\n this._cachedVRotationCenter = -1;\n this._cachedWRotationCenter = -1;\n this._cachedHomogeneousRotationInUVTransform = false;\n this._cachedReflectionTextureMatrix = null;\n this._cachedReflectionUOffset = -1;\n this._cachedReflectionVOffset = -1;\n this._cachedReflectionUScale = 0;\n this._cachedReflectionVScale = 0;\n this._cachedReflectionCoordinatesMode = -1;\n /** @internal */\n this._buffer = null;\n this._deleteBuffer = false;\n this._format = null;\n this._delayedOnLoad = null;\n this._delayedOnError = null;\n /**\n * Observable triggered once the texture has been loaded.\n */\n this.onLoadObservable = new Observable$1();\n this._isBlocking = true;\n this.name = url || \"\";\n this.url = url;\n let noMipmap;\n let useSRGBBuffer = false;\n let internalTexture = null;\n if (typeof noMipmapOrOptions === \"object\" && noMipmapOrOptions !== null) {\n noMipmap = (_a = noMipmapOrOptions.noMipmap) !== null && _a !== void 0 ? _a : false;\n invertY = (_b = noMipmapOrOptions.invertY) !== null && _b !== void 0 ? _b : (CompatibilityOptions.UseOpenGLOrientationForUV ? false : true);\n samplingMode = (_c = noMipmapOrOptions.samplingMode) !== null && _c !== void 0 ? _c : Texture.TRILINEAR_SAMPLINGMODE;\n onLoad = (_d = noMipmapOrOptions.onLoad) !== null && _d !== void 0 ? _d : null;\n onError = (_e = noMipmapOrOptions.onError) !== null && _e !== void 0 ? _e : null;\n buffer = (_f = noMipmapOrOptions.buffer) !== null && _f !== void 0 ? _f : null;\n deleteBuffer = (_g = noMipmapOrOptions.deleteBuffer) !== null && _g !== void 0 ? _g : false;\n format = noMipmapOrOptions.format;\n mimeType = noMipmapOrOptions.mimeType;\n loaderOptions = noMipmapOrOptions.loaderOptions;\n creationFlags = noMipmapOrOptions.creationFlags;\n useSRGBBuffer = (_h = noMipmapOrOptions.useSRGBBuffer) !== null && _h !== void 0 ? _h : false;\n internalTexture = (_j = noMipmapOrOptions.internalTexture) !== null && _j !== void 0 ? _j : null;\n }\n else {\n noMipmap = !!noMipmapOrOptions;\n }\n this._noMipmap = noMipmap;\n this._invertY = invertY === undefined ? (CompatibilityOptions.UseOpenGLOrientationForUV ? false : true) : invertY;\n this._initialSamplingMode = samplingMode;\n this._buffer = buffer;\n this._deleteBuffer = deleteBuffer;\n this._mimeType = mimeType;\n this._loaderOptions = loaderOptions;\n this._creationFlags = creationFlags;\n this._useSRGBBuffer = useSRGBBuffer;\n this._forcedExtension = forcedExtension;\n if (format) {\n this._format = format;\n }\n const scene = this.getScene();\n const engine = this._getEngine();\n if (!engine) {\n return;\n }\n engine.onBeforeTextureInitObservable.notifyObservers(this);\n const load = () => {\n if (this._texture) {\n if (this._texture._invertVScale) {\n this.vScale *= -1;\n this.vOffset += 1;\n }\n // Update texture to match internal texture's wrapping\n if (this._texture._cachedWrapU !== null) {\n this.wrapU = this._texture._cachedWrapU;\n this._texture._cachedWrapU = null;\n }\n if (this._texture._cachedWrapV !== null) {\n this.wrapV = this._texture._cachedWrapV;\n this._texture._cachedWrapV = null;\n }\n if (this._texture._cachedWrapR !== null) {\n this.wrapR = this._texture._cachedWrapR;\n this._texture._cachedWrapR = null;\n }\n }\n if (this.onLoadObservable.hasObservers()) {\n this.onLoadObservable.notifyObservers(this);\n }\n if (onLoad) {\n onLoad();\n }\n if (!this.isBlocking && scene) {\n scene.resetCachedMaterial();\n }\n };\n const errorHandler = (message, exception) => {\n this._loadingError = true;\n this._errorObject = { message, exception };\n if (onError) {\n onError(message, exception);\n }\n Texture.OnTextureLoadErrorObservable.notifyObservers(this);\n };\n if (!this.url && !internalTexture) {\n this._delayedOnLoad = load;\n this._delayedOnError = errorHandler;\n return;\n }\n this._texture = internalTexture !== null && internalTexture !== void 0 ? internalTexture : this._getFromCache(this.url, noMipmap, samplingMode, this._invertY, useSRGBBuffer);\n if (!this._texture) {\n if (!scene || !scene.useDelayedTextureLoading) {\n try {\n this._texture = engine.createTexture(this.url, noMipmap, this._invertY, scene, samplingMode, load, errorHandler, this._buffer, undefined, this._format, this._forcedExtension, mimeType, loaderOptions, creationFlags, useSRGBBuffer);\n }\n catch (e) {\n errorHandler(\"error loading\", e);\n throw e;\n }\n if (deleteBuffer) {\n this._buffer = null;\n }\n }\n else {\n this.delayLoadState = 4;\n this._delayedOnLoad = load;\n this._delayedOnError = errorHandler;\n }\n }\n else {\n if (this._texture.isReady) {\n TimingTools.SetImmediate(() => load());\n }\n else {\n const loadObserver = this._texture.onLoadedObservable.add(load);\n this._texture.onErrorObservable.add((e) => {\n var _a;\n errorHandler(e.message, e.exception);\n (_a = this._texture) === null || _a === void 0 ? void 0 : _a.onLoadedObservable.remove(loadObserver);\n });\n }\n }\n }\n /**\n * Update the url (and optional buffer) of this texture if url was null during construction.\n * @param url the url of the texture\n * @param buffer the buffer of the texture (defaults to null)\n * @param onLoad callback called when the texture is loaded (defaults to null)\n * @param forcedExtension defines the extension to use to pick the right loader\n */\n updateURL(url, buffer = null, onLoad, forcedExtension) {\n if (this.url) {\n this.releaseInternalTexture();\n this.getScene().markAllMaterialsAsDirty(1);\n }\n if (!this.name || this.name.startsWith(\"data:\")) {\n this.name = url;\n }\n this.url = url;\n this._buffer = buffer;\n this._forcedExtension = forcedExtension;\n this.delayLoadState = 4;\n if (onLoad) {\n this._delayedOnLoad = onLoad;\n }\n this.delayLoad();\n }\n /**\n * Finish the loading sequence of a texture flagged as delayed load.\n * @internal\n */\n delayLoad() {\n if (this.delayLoadState !== 4) {\n return;\n }\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n this.delayLoadState = 1;\n this._texture = this._getFromCache(this.url, this._noMipmap, this.samplingMode, this._invertY, this._useSRGBBuffer);\n if (!this._texture) {\n this._texture = scene\n .getEngine()\n .createTexture(this.url, this._noMipmap, this._invertY, scene, this.samplingMode, this._delayedOnLoad, this._delayedOnError, this._buffer, null, this._format, this._forcedExtension, this._mimeType, this._loaderOptions, this._creationFlags, this._useSRGBBuffer);\n if (this._deleteBuffer) {\n this._buffer = null;\n }\n }\n else {\n if (this._delayedOnLoad) {\n if (this._texture.isReady) {\n TimingTools.SetImmediate(this._delayedOnLoad);\n }\n else {\n this._texture.onLoadedObservable.add(this._delayedOnLoad);\n }\n }\n }\n this._delayedOnLoad = null;\n this._delayedOnError = null;\n }\n _prepareRowForTextureGeneration(x, y, z, t) {\n x *= this._cachedUScale;\n y *= this._cachedVScale;\n x -= this.uRotationCenter * this._cachedUScale;\n y -= this.vRotationCenter * this._cachedVScale;\n z -= this.wRotationCenter;\n Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix, t);\n t.x += this.uRotationCenter * this._cachedUScale + this._cachedUOffset;\n t.y += this.vRotationCenter * this._cachedVScale + this._cachedVOffset;\n t.z += this.wRotationCenter;\n }\n /**\n * Checks if the texture has the same transform matrix than another texture\n * @param texture texture to check against\n * @returns true if the transforms are the same, else false\n */\n checkTransformsAreIdentical(texture) {\n return (texture !== null &&\n this.uOffset === texture.uOffset &&\n this.vOffset === texture.vOffset &&\n this.uScale === texture.uScale &&\n this.vScale === texture.vScale &&\n this.uAng === texture.uAng &&\n this.vAng === texture.vAng &&\n this.wAng === texture.wAng);\n }\n /**\n * Get the current texture matrix which includes the requested offsetting, tiling and rotation components.\n * @param uBase\n * @returns the transform matrix of the texture.\n */\n getTextureMatrix(uBase = 1) {\n if (this.uOffset === this._cachedUOffset &&\n this.vOffset === this._cachedVOffset &&\n this.uScale * uBase === this._cachedUScale &&\n this.vScale === this._cachedVScale &&\n this.uAng === this._cachedUAng &&\n this.vAng === this._cachedVAng &&\n this.wAng === this._cachedWAng &&\n this.uRotationCenter === this._cachedURotationCenter &&\n this.vRotationCenter === this._cachedVRotationCenter &&\n this.wRotationCenter === this._cachedWRotationCenter &&\n this.homogeneousRotationInUVTransform === this._cachedHomogeneousRotationInUVTransform) {\n return this._cachedTextureMatrix;\n }\n this._cachedUOffset = this.uOffset;\n this._cachedVOffset = this.vOffset;\n this._cachedUScale = this.uScale * uBase;\n this._cachedVScale = this.vScale;\n this._cachedUAng = this.uAng;\n this._cachedVAng = this.vAng;\n this._cachedWAng = this.wAng;\n this._cachedURotationCenter = this.uRotationCenter;\n this._cachedVRotationCenter = this.vRotationCenter;\n this._cachedWRotationCenter = this.wRotationCenter;\n this._cachedHomogeneousRotationInUVTransform = this.homogeneousRotationInUVTransform;\n if (!this._cachedTextureMatrix || !this._rowGenerationMatrix) {\n this._cachedTextureMatrix = Matrix.Zero();\n this._rowGenerationMatrix = new Matrix();\n this._t0 = Vector3.Zero();\n this._t1 = Vector3.Zero();\n this._t2 = Vector3.Zero();\n }\n Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix);\n if (this.homogeneousRotationInUVTransform) {\n Matrix.TranslationToRef(-this._cachedURotationCenter, -this._cachedVRotationCenter, -this._cachedWRotationCenter, TmpVectors.Matrix[0]);\n Matrix.TranslationToRef(this._cachedURotationCenter, this._cachedVRotationCenter, this._cachedWRotationCenter, TmpVectors.Matrix[1]);\n Matrix.ScalingToRef(this._cachedUScale, this._cachedVScale, 0, TmpVectors.Matrix[2]);\n Matrix.TranslationToRef(this._cachedUOffset, this._cachedVOffset, 0, TmpVectors.Matrix[3]);\n TmpVectors.Matrix[0].multiplyToRef(this._rowGenerationMatrix, this._cachedTextureMatrix);\n this._cachedTextureMatrix.multiplyToRef(TmpVectors.Matrix[1], this._cachedTextureMatrix);\n this._cachedTextureMatrix.multiplyToRef(TmpVectors.Matrix[2], this._cachedTextureMatrix);\n this._cachedTextureMatrix.multiplyToRef(TmpVectors.Matrix[3], this._cachedTextureMatrix);\n // copy the translation row to the 3rd row of the matrix so that we don't need to update the shaders (which expects the translation to be on the 3rd row)\n this._cachedTextureMatrix.setRowFromFloats(2, this._cachedTextureMatrix.m[12], this._cachedTextureMatrix.m[13], this._cachedTextureMatrix.m[14], 1);\n }\n else {\n this._prepareRowForTextureGeneration(0, 0, 0, this._t0);\n this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1);\n this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2);\n this._t1.subtractInPlace(this._t0);\n this._t2.subtractInPlace(this._t0);\n Matrix.FromValuesToRef(this._t1.x, this._t1.y, this._t1.z, 0.0, this._t2.x, this._t2.y, this._t2.z, 0.0, this._t0.x, this._t0.y, this._t0.z, 0.0, 0.0, 0.0, 0.0, 1.0, this._cachedTextureMatrix);\n }\n const scene = this.getScene();\n if (!scene) {\n return this._cachedTextureMatrix;\n }\n if (this.optimizeUVAllocation) {\n // We flag the materials that are using this texture as \"texture dirty\" because depending on the fact that the matrix is the identity or not, some defines\n // will get different values (see MaterialHelper.PrepareDefinesForMergedUV), meaning we should regenerate the effect accordingly\n scene.markAllMaterialsAsDirty(1, (mat) => {\n return mat.hasTexture(this);\n });\n }\n return this._cachedTextureMatrix;\n }\n /**\n * Get the current matrix used to apply reflection. This is useful to rotate an environment texture for instance.\n * @returns The reflection texture transform\n */\n getReflectionTextureMatrix() {\n const scene = this.getScene();\n if (!scene) {\n return this._cachedReflectionTextureMatrix;\n }\n if (this.uOffset === this._cachedReflectionUOffset &&\n this.vOffset === this._cachedReflectionVOffset &&\n this.uScale === this._cachedReflectionUScale &&\n this.vScale === this._cachedReflectionVScale &&\n this.coordinatesMode === this._cachedReflectionCoordinatesMode) {\n if (this.coordinatesMode === Texture.PROJECTION_MODE) {\n if (this._cachedReflectionProjectionMatrixId === scene.getProjectionMatrix().updateFlag) {\n return this._cachedReflectionTextureMatrix;\n }\n }\n else {\n return this._cachedReflectionTextureMatrix;\n }\n }\n if (!this._cachedReflectionTextureMatrix) {\n this._cachedReflectionTextureMatrix = Matrix.Zero();\n }\n if (!this._projectionModeMatrix) {\n this._projectionModeMatrix = Matrix.Zero();\n }\n const flagMaterialsAsTextureDirty = this._cachedReflectionCoordinatesMode !== this.coordinatesMode;\n this._cachedReflectionUOffset = this.uOffset;\n this._cachedReflectionVOffset = this.vOffset;\n this._cachedReflectionUScale = this.uScale;\n this._cachedReflectionVScale = this.vScale;\n this._cachedReflectionCoordinatesMode = this.coordinatesMode;\n switch (this.coordinatesMode) {\n case Texture.PLANAR_MODE: {\n Matrix.IdentityToRef(this._cachedReflectionTextureMatrix);\n this._cachedReflectionTextureMatrix[0] = this.uScale;\n this._cachedReflectionTextureMatrix[5] = this.vScale;\n this._cachedReflectionTextureMatrix[12] = this.uOffset;\n this._cachedReflectionTextureMatrix[13] = this.vOffset;\n break;\n }\n case Texture.PROJECTION_MODE: {\n Matrix.FromValuesToRef(0.5, 0.0, 0.0, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 1.0, 1.0, this._projectionModeMatrix);\n const projectionMatrix = scene.getProjectionMatrix();\n this._cachedReflectionProjectionMatrixId = projectionMatrix.updateFlag;\n projectionMatrix.multiplyToRef(this._projectionModeMatrix, this._cachedReflectionTextureMatrix);\n break;\n }\n default:\n Matrix.IdentityToRef(this._cachedReflectionTextureMatrix);\n break;\n }\n if (flagMaterialsAsTextureDirty) {\n // We flag the materials that are using this texture as \"texture dirty\" if the coordinatesMode has changed.\n // Indeed, this property is used to set the value of some defines used to generate the effect (in material.isReadyForSubMesh), so we must make sure this code will be re-executed and the effect recreated if necessary\n scene.markAllMaterialsAsDirty(1, (mat) => {\n return mat.getActiveTextures().indexOf(this) !== -1;\n });\n }\n return this._cachedReflectionTextureMatrix;\n }\n /**\n * Clones the texture.\n * @returns the cloned texture\n */\n clone() {\n const options = {\n noMipmap: this._noMipmap,\n invertY: this._invertY,\n samplingMode: this.samplingMode,\n onLoad: undefined,\n onError: undefined,\n buffer: this._texture ? this._texture._buffer : undefined,\n deleteBuffer: this._deleteBuffer,\n format: this.textureFormat,\n mimeType: this.mimeType,\n loaderOptions: this._loaderOptions,\n creationFlags: this._creationFlags,\n useSRGBBuffer: this._useSRGBBuffer,\n };\n return SerializationHelper.Clone(() => {\n return new Texture(this._texture ? this._texture.url : null, this.getScene(), options);\n }, this);\n }\n /**\n * Serialize the texture to a JSON representation we can easily use in the respective Parse function.\n * @returns The JSON representation of the texture\n */\n serialize() {\n var _a, _b;\n const savedName = this.name;\n if (!Texture.SerializeBuffers) {\n if (this.name.startsWith(\"data:\")) {\n this.name = \"\";\n }\n }\n if (this.name.startsWith(\"data:\") && this.url === this.name) {\n this.url = \"\";\n }\n const serializationObject = super.serialize(Texture._SerializeInternalTextureUniqueId);\n if (!serializationObject) {\n return null;\n }\n if (Texture.SerializeBuffers || Texture.ForceSerializeBuffers) {\n if (typeof this._buffer === \"string\" && this._buffer.substr(0, 5) === \"data:\") {\n serializationObject.base64String = this._buffer;\n serializationObject.name = serializationObject.name.replace(\"data:\", \"\");\n }\n else if (this.url && this.url.startsWith(\"data:\") && this._buffer instanceof Uint8Array) {\n serializationObject.base64String = \"data:image/png;base64,\" + EncodeArrayBufferToBase64(this._buffer);\n }\n else if (Texture.ForceSerializeBuffers || (this.url && this.url.startsWith(\"blob:\")) || this._forceSerialize) {\n serializationObject.base64String =\n !this._engine || this._engine._features.supportSyncTextureRead ? GenerateBase64StringFromTexture(this) : GenerateBase64StringFromTextureAsync(this);\n }\n }\n serializationObject.invertY = this._invertY;\n serializationObject.samplingMode = this.samplingMode;\n serializationObject._creationFlags = this._creationFlags;\n serializationObject._useSRGBBuffer = this._useSRGBBuffer;\n if (Texture._SerializeInternalTextureUniqueId) {\n serializationObject.internalTextureUniqueId = (_b = (_a = this._texture) === null || _a === void 0 ? void 0 : _a.uniqueId) !== null && _b !== void 0 ? _b : undefined;\n }\n this.name = savedName;\n return serializationObject;\n }\n /**\n * Get the current class name of the texture useful for serialization or dynamic coding.\n * @returns \"Texture\"\n */\n getClassName() {\n return \"Texture\";\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n super.dispose();\n this.onLoadObservable.clear();\n this._delayedOnLoad = null;\n this._delayedOnError = null;\n this._buffer = null;\n }\n /**\n * Parse the JSON representation of a texture in order to recreate the texture in the given scene.\n * @param parsedTexture Define the JSON representation of the texture\n * @param scene Define the scene the parsed texture should be instantiated in\n * @param rootUrl Define the root url of the parsing sequence in the case of relative dependencies\n * @returns The parsed texture if successful\n */\n static Parse(parsedTexture, scene, rootUrl) {\n if (parsedTexture.customType) {\n const customTexture = InstantiationTools.Instantiate(parsedTexture.customType);\n // Update Sampling Mode\n const parsedCustomTexture = customTexture.Parse(parsedTexture, scene, rootUrl);\n if (parsedTexture.samplingMode && parsedCustomTexture.updateSamplingMode && parsedCustomTexture._samplingMode) {\n if (parsedCustomTexture._samplingMode !== parsedTexture.samplingMode) {\n parsedCustomTexture.updateSamplingMode(parsedTexture.samplingMode);\n }\n }\n return parsedCustomTexture;\n }\n if (parsedTexture.isCube && !parsedTexture.isRenderTarget) {\n return Texture._CubeTextureParser(parsedTexture, scene, rootUrl);\n }\n const hasInternalTextureUniqueId = parsedTexture.internalTextureUniqueId !== undefined;\n if (!parsedTexture.name && !parsedTexture.isRenderTarget && !hasInternalTextureUniqueId) {\n return null;\n }\n let internalTexture;\n if (hasInternalTextureUniqueId) {\n const cache = scene.getEngine().getLoadedTexturesCache();\n for (const texture of cache) {\n if (texture.uniqueId === parsedTexture.internalTextureUniqueId) {\n internalTexture = texture;\n break;\n }\n }\n }\n const onLoaded = (texture) => {\n var _a;\n // Clear cache\n if (texture && texture._texture) {\n texture._texture._cachedWrapU = null;\n texture._texture._cachedWrapV = null;\n texture._texture._cachedWrapR = null;\n }\n // Update Sampling Mode\n if (parsedTexture.samplingMode) {\n const sampling = parsedTexture.samplingMode;\n if (texture && texture.samplingMode !== sampling) {\n texture.updateSamplingMode(sampling);\n }\n }\n // Animations\n if (texture && parsedTexture.animations) {\n for (let animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {\n const parsedAnimation = parsedTexture.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n texture.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n }\n if (hasInternalTextureUniqueId && !internalTexture) {\n (_a = texture === null || texture === void 0 ? void 0 : texture._texture) === null || _a === void 0 ? void 0 : _a._setUniqueId(parsedTexture.internalTextureUniqueId);\n }\n };\n const texture = SerializationHelper.Parse(() => {\n var _a, _b, _c;\n let generateMipMaps = true;\n if (parsedTexture.noMipmap) {\n generateMipMaps = false;\n }\n if (parsedTexture.mirrorPlane) {\n const mirrorTexture = Texture._CreateMirror(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);\n mirrorTexture._waitingRenderList = parsedTexture.renderList;\n mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);\n onLoaded(mirrorTexture);\n return mirrorTexture;\n }\n else if (parsedTexture.isRenderTarget) {\n let renderTargetTexture = null;\n if (parsedTexture.isCube) {\n // Search for an existing reflection probe (which contains a cube render target texture)\n if (scene.reflectionProbes) {\n for (let index = 0; index < scene.reflectionProbes.length; index++) {\n const probe = scene.reflectionProbes[index];\n if (probe.name === parsedTexture.name) {\n return probe.cubeTexture;\n }\n }\n }\n }\n else {\n renderTargetTexture = Texture._CreateRenderTargetTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps, (_a = parsedTexture._creationFlags) !== null && _a !== void 0 ? _a : 0);\n renderTargetTexture._waitingRenderList = parsedTexture.renderList;\n }\n onLoaded(renderTargetTexture);\n return renderTargetTexture;\n }\n else {\n let texture;\n if (parsedTexture.base64String && !internalTexture) {\n // name and url are the same to ensure caching happens from the actual base64 string\n texture = Texture.CreateFromBase64String(parsedTexture.base64String, parsedTexture.base64String, scene, !generateMipMaps, parsedTexture.invertY, parsedTexture.samplingMode, () => {\n onLoaded(texture);\n }, (_b = parsedTexture._creationFlags) !== null && _b !== void 0 ? _b : 0, (_c = parsedTexture._useSRGBBuffer) !== null && _c !== void 0 ? _c : false);\n // prettier name to fit with the loaded data\n texture.name = parsedTexture.name;\n }\n else {\n let url;\n if (parsedTexture.name && (parsedTexture.name.indexOf(\"://\") > 0 || parsedTexture.name.startsWith(\"data:\"))) {\n url = parsedTexture.name;\n }\n else {\n url = rootUrl + parsedTexture.name;\n }\n if (parsedTexture.url && (parsedTexture.url.startsWith(\"data:\") || Texture.UseSerializedUrlIfAny)) {\n url = parsedTexture.url;\n }\n const options = {\n noMipmap: !generateMipMaps,\n invertY: parsedTexture.invertY,\n samplingMode: parsedTexture.samplingMode,\n onLoad: () => {\n onLoaded(texture);\n },\n internalTexture,\n };\n texture = new Texture(url, scene, options);\n }\n return texture;\n }\n }, parsedTexture, scene);\n return texture;\n }\n /**\n * Creates a texture from its base 64 representation.\n * @param data Define the base64 payload without the data: prefix\n * @param name Define the name of the texture in the scene useful fo caching purpose for instance\n * @param scene Define the scene the texture should belong to\n * @param noMipmapOrOptions defines if the texture will require mip maps or not or set of all options to create the texture\n * @param invertY define if the texture needs to be inverted on the y axis during loading\n * @param samplingMode define the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)\n * @param onLoad define a callback triggered when the texture has been loaded\n * @param onError define a callback triggered when an error occurred during the loading session\n * @param format define the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @returns the created texture\n */\n static CreateFromBase64String(data, name, scene, noMipmapOrOptions, invertY, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, onLoad = null, onError = null, format = 5, creationFlags) {\n return new Texture(\"data:\" + name, scene, noMipmapOrOptions, invertY, samplingMode, onLoad, onError, data, false, format, undefined, undefined, creationFlags);\n }\n /**\n * Creates a texture from its data: representation. (data: will be added in case only the payload has been passed in)\n * @param name Define the name of the texture in the scene useful fo caching purpose for instance\n * @param buffer define the buffer to load the texture from in case the texture is loaded from a buffer representation\n * @param scene Define the scene the texture should belong to\n * @param deleteBuffer define if the buffer we are loading the texture from should be deleted after load\n * @param noMipmapOrOptions defines if the texture will require mip maps or not or set of all options to create the texture\n * @param invertY define if the texture needs to be inverted on the y axis during loading\n * @param samplingMode define the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)\n * @param onLoad define a callback triggered when the texture has been loaded\n * @param onError define a callback triggered when an error occurred during the loading session\n * @param format define the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @returns the created texture\n */\n static LoadFromDataString(name, buffer, scene, deleteBuffer = false, noMipmapOrOptions, invertY = true, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, onLoad = null, onError = null, format = 5, creationFlags) {\n if (name.substr(0, 5) !== \"data:\") {\n name = \"data:\" + name;\n }\n return new Texture(name, scene, noMipmapOrOptions, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer, format, undefined, undefined, creationFlags);\n }\n }\n /**\n * Gets or sets a general boolean used to indicate that textures containing direct data (buffers) must be saved as part of the serialization process\n */\n Texture.SerializeBuffers = true;\n /**\n * Gets or sets a general boolean used to indicate that texture buffers must be saved as part of the serialization process.\n * If no buffer exists, one will be created as base64 string from the internal webgl data.\n */\n Texture.ForceSerializeBuffers = false;\n /**\n * This observable will notify when any texture had a loading error\n */\n Texture.OnTextureLoadErrorObservable = new Observable$1();\n /** @internal */\n Texture._SerializeInternalTextureUniqueId = false;\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Texture._CubeTextureParser = (jsonTexture, scene, rootUrl) => {\n throw _WarnImport(\"CubeTexture\");\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Texture._CreateMirror = (name, renderTargetSize, scene, generateMipMaps) => {\n throw _WarnImport(\"MirrorTexture\");\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Texture._CreateRenderTargetTexture = (name, renderTargetSize, scene, generateMipMaps, creationFlags) => {\n throw _WarnImport(\"RenderTargetTexture\");\n };\n /** nearest is mag = nearest and min = nearest and no mip */\n Texture.NEAREST_SAMPLINGMODE = 1;\n /** nearest is mag = nearest and min = nearest and mip = linear */\n Texture.NEAREST_NEAREST_MIPLINEAR = 8; // nearest is mag = nearest and min = nearest and mip = linear\n /** Bilinear is mag = linear and min = linear and no mip */\n Texture.BILINEAR_SAMPLINGMODE = 2;\n /** Bilinear is mag = linear and min = linear and mip = nearest */\n Texture.LINEAR_LINEAR_MIPNEAREST = 11; // Bilinear is mag = linear and min = linear and mip = nearest\n /** Trilinear is mag = linear and min = linear and mip = linear */\n Texture.TRILINEAR_SAMPLINGMODE = 3;\n /** Trilinear is mag = linear and min = linear and mip = linear */\n Texture.LINEAR_LINEAR_MIPLINEAR = 3; // Trilinear is mag = linear and min = linear and mip = linear\n /** mag = nearest and min = nearest and mip = nearest */\n Texture.NEAREST_NEAREST_MIPNEAREST = 4;\n /** mag = nearest and min = linear and mip = nearest */\n Texture.NEAREST_LINEAR_MIPNEAREST = 5;\n /** mag = nearest and min = linear and mip = linear */\n Texture.NEAREST_LINEAR_MIPLINEAR = 6;\n /** mag = nearest and min = linear and mip = none */\n Texture.NEAREST_LINEAR = 7;\n /** mag = nearest and min = nearest and mip = none */\n Texture.NEAREST_NEAREST = 1;\n /** mag = linear and min = nearest and mip = nearest */\n Texture.LINEAR_NEAREST_MIPNEAREST = 9;\n /** mag = linear and min = nearest and mip = linear */\n Texture.LINEAR_NEAREST_MIPLINEAR = 10;\n /** mag = linear and min = linear and mip = none */\n Texture.LINEAR_LINEAR = 2;\n /** mag = linear and min = nearest and mip = none */\n Texture.LINEAR_NEAREST = 12;\n /** Explicit coordinates mode */\n Texture.EXPLICIT_MODE = 0;\n /** Spherical coordinates mode */\n Texture.SPHERICAL_MODE = 1;\n /** Planar coordinates mode */\n Texture.PLANAR_MODE = 2;\n /** Cubic coordinates mode */\n Texture.CUBIC_MODE = 3;\n /** Projection coordinates mode */\n Texture.PROJECTION_MODE = 4;\n /** Inverse Cubic coordinates mode */\n Texture.SKYBOX_MODE = 5;\n /** Inverse Cubic coordinates mode */\n Texture.INVCUBIC_MODE = 6;\n /** Equirectangular coordinates mode */\n Texture.EQUIRECTANGULAR_MODE = 7;\n /** Equirectangular Fixed coordinates mode */\n Texture.FIXED_EQUIRECTANGULAR_MODE = 8;\n /** Equirectangular Fixed Mirrored coordinates mode */\n Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;\n /** Texture is not repeating outside of 0..1 UVs */\n Texture.CLAMP_ADDRESSMODE = 0;\n /** Texture is repeating outside of 0..1 UVs */\n Texture.WRAP_ADDRESSMODE = 1;\n /** Texture is repeating and mirrored */\n Texture.MIRROR_ADDRESSMODE = 2;\n /**\n * Gets or sets a boolean which defines if the texture url must be build from the serialized URL instead of just using the name and loading them side by side with the scene file\n */\n Texture.UseSerializedUrlIfAny = false;\n __decorate$1([\n serialize()\n ], Texture.prototype, \"url\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"uOffset\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"vOffset\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"uScale\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"vScale\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"uAng\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"vAng\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"wAng\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"uRotationCenter\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"vRotationCenter\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"wRotationCenter\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"homogeneousRotationInUVTransform\", void 0);\n __decorate$1([\n serialize()\n ], Texture.prototype, \"isBlocking\", null);\n // References the dependencies.\n RegisterClass(\"BABYLON.Texture\", Texture);\n SerializationHelper._TextureParser = Texture.Parse;\n\n /**\n * Configuration needed for prepass-capable materials\n */\n class PrePassConfiguration {\n constructor() {\n /**\n * Previous world matrices of meshes carrying this material\n * Used for computing velocity\n */\n this.previousWorldMatrices = {};\n /**\n * Previous bones of meshes carrying this material\n * Used for computing velocity\n */\n this.previousBones = {};\n }\n /**\n * Add the required uniforms to the current list.\n * @param uniforms defines the current uniform list.\n */\n static AddUniforms(uniforms) {\n uniforms.push(\"previousWorld\", \"previousViewProjection\", \"mPreviousBones\");\n }\n /**\n * Add the required samplers to the current list.\n * @param samplers defines the current sampler list.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static AddSamplers(samplers) {\n // pass\n }\n /**\n * Binds the material data.\n * @param effect defines the effect to update\n * @param scene defines the scene the material belongs to.\n * @param mesh The mesh\n * @param world World matrix of this mesh\n * @param isFrozen Is the material frozen\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n bindForSubMesh(effect, scene, mesh, world, isFrozen) {\n if (scene.prePassRenderer && scene.prePassRenderer.enabled && scene.prePassRenderer.currentRTisSceneRT) {\n if (scene.prePassRenderer.getIndex(2) !== -1) {\n if (!this.previousWorldMatrices[mesh.uniqueId]) {\n this.previousWorldMatrices[mesh.uniqueId] = world.clone();\n }\n if (!this.previousViewProjection) {\n this.previousViewProjection = scene.getTransformMatrix().clone();\n this.currentViewProjection = scene.getTransformMatrix().clone();\n }\n const engine = scene.getEngine();\n if (this.currentViewProjection.updateFlag !== scene.getTransformMatrix().updateFlag) {\n // First update of the prepass configuration for this rendering pass\n this._lastUpdateFrameId = engine.frameId;\n this.previousViewProjection.copyFrom(this.currentViewProjection);\n this.currentViewProjection.copyFrom(scene.getTransformMatrix());\n }\n else if (this._lastUpdateFrameId !== engine.frameId) {\n // The scene transformation did not change from the previous frame (so no camera motion), we must update previousViewProjection accordingly\n this._lastUpdateFrameId = engine.frameId;\n this.previousViewProjection.copyFrom(this.currentViewProjection);\n }\n effect.setMatrix(\"previousWorld\", this.previousWorldMatrices[mesh.uniqueId]);\n effect.setMatrix(\"previousViewProjection\", this.previousViewProjection);\n this.previousWorldMatrices[mesh.uniqueId] = world.clone();\n }\n }\n }\n }\n\n /**\n * Base class of materials working in push mode in babylon JS\n * @internal\n */\n class PushMaterial extends Material {\n constructor(name, scene, storeEffectOnSubMeshes = true) {\n super(name, scene);\n this._normalMatrix = new Matrix();\n this._storeEffectOnSubMeshes = storeEffectOnSubMeshes;\n }\n getEffect() {\n return this._storeEffectOnSubMeshes ? this._activeEffect : super.getEffect();\n }\n isReady(mesh, useInstances) {\n if (!mesh) {\n return false;\n }\n if (!this._storeEffectOnSubMeshes) {\n return true;\n }\n if (!mesh.subMeshes || mesh.subMeshes.length === 0) {\n return true;\n }\n return this.isReadyForSubMesh(mesh, mesh.subMeshes[0], useInstances);\n }\n _isReadyForSubMesh(subMesh) {\n const defines = subMesh.materialDefines;\n if (!this.checkReadyOnEveryCall && subMesh.effect && defines) {\n if (defines._renderId === this.getScene().getRenderId()) {\n return true;\n }\n }\n return false;\n }\n /**\n * Binds the given world matrix to the active effect\n *\n * @param world the matrix to bind\n */\n bindOnlyWorldMatrix(world) {\n this._activeEffect.setMatrix(\"world\", world);\n }\n /**\n * Binds the given normal matrix to the active effect\n *\n * @param normalMatrix the matrix to bind\n */\n bindOnlyNormalMatrix(normalMatrix) {\n this._activeEffect.setMatrix(\"normalMatrix\", normalMatrix);\n }\n bind(world, mesh) {\n if (!mesh) {\n return;\n }\n this.bindForSubMesh(world, mesh, mesh.subMeshes[0]);\n }\n _afterBind(mesh, effect = null) {\n super._afterBind(mesh, effect);\n this.getScene()._cachedEffect = effect;\n if (effect) {\n effect._forceRebindOnNextCall = false;\n }\n }\n _mustRebind(scene, effect, visibility = 1) {\n return scene.isCachedMaterialInvalid(this, effect, visibility);\n }\n dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh) {\n this._activeEffect = undefined;\n super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);\n }\n }\n\n /**\n * This groups all the flags used to control the materials channel.\n */\n class MaterialFlags {\n /**\n * Are diffuse textures enabled in the application.\n */\n static get DiffuseTextureEnabled() {\n return this._DiffuseTextureEnabled;\n }\n static set DiffuseTextureEnabled(value) {\n if (this._DiffuseTextureEnabled === value) {\n return;\n }\n this._DiffuseTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are detail textures enabled in the application.\n */\n static get DetailTextureEnabled() {\n return this._DetailTextureEnabled;\n }\n static set DetailTextureEnabled(value) {\n if (this._DetailTextureEnabled === value) {\n return;\n }\n this._DetailTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are decal maps enabled in the application.\n */\n static get DecalMapEnabled() {\n return this._DecalMapEnabled;\n }\n static set DecalMapEnabled(value) {\n if (this._DecalMapEnabled === value) {\n return;\n }\n this._DecalMapEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are ambient textures enabled in the application.\n */\n static get AmbientTextureEnabled() {\n return this._AmbientTextureEnabled;\n }\n static set AmbientTextureEnabled(value) {\n if (this._AmbientTextureEnabled === value) {\n return;\n }\n this._AmbientTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are opacity textures enabled in the application.\n */\n static get OpacityTextureEnabled() {\n return this._OpacityTextureEnabled;\n }\n static set OpacityTextureEnabled(value) {\n if (this._OpacityTextureEnabled === value) {\n return;\n }\n this._OpacityTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are reflection textures enabled in the application.\n */\n static get ReflectionTextureEnabled() {\n return this._ReflectionTextureEnabled;\n }\n static set ReflectionTextureEnabled(value) {\n if (this._ReflectionTextureEnabled === value) {\n return;\n }\n this._ReflectionTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are emissive textures enabled in the application.\n */\n static get EmissiveTextureEnabled() {\n return this._EmissiveTextureEnabled;\n }\n static set EmissiveTextureEnabled(value) {\n if (this._EmissiveTextureEnabled === value) {\n return;\n }\n this._EmissiveTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are specular textures enabled in the application.\n */\n static get SpecularTextureEnabled() {\n return this._SpecularTextureEnabled;\n }\n static set SpecularTextureEnabled(value) {\n if (this._SpecularTextureEnabled === value) {\n return;\n }\n this._SpecularTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are bump textures enabled in the application.\n */\n static get BumpTextureEnabled() {\n return this._BumpTextureEnabled;\n }\n static set BumpTextureEnabled(value) {\n if (this._BumpTextureEnabled === value) {\n return;\n }\n this._BumpTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are lightmap textures enabled in the application.\n */\n static get LightmapTextureEnabled() {\n return this._LightmapTextureEnabled;\n }\n static set LightmapTextureEnabled(value) {\n if (this._LightmapTextureEnabled === value) {\n return;\n }\n this._LightmapTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are refraction textures enabled in the application.\n */\n static get RefractionTextureEnabled() {\n return this._RefractionTextureEnabled;\n }\n static set RefractionTextureEnabled(value) {\n if (this._RefractionTextureEnabled === value) {\n return;\n }\n this._RefractionTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are color grading textures enabled in the application.\n */\n static get ColorGradingTextureEnabled() {\n return this._ColorGradingTextureEnabled;\n }\n static set ColorGradingTextureEnabled(value) {\n if (this._ColorGradingTextureEnabled === value) {\n return;\n }\n this._ColorGradingTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are fresnels enabled in the application.\n */\n static get FresnelEnabled() {\n return this._FresnelEnabled;\n }\n static set FresnelEnabled(value) {\n if (this._FresnelEnabled === value) {\n return;\n }\n this._FresnelEnabled = value;\n Engine.MarkAllMaterialsAsDirty(4);\n }\n /**\n * Are clear coat textures enabled in the application.\n */\n static get ClearCoatTextureEnabled() {\n return this._ClearCoatTextureEnabled;\n }\n static set ClearCoatTextureEnabled(value) {\n if (this._ClearCoatTextureEnabled === value) {\n return;\n }\n this._ClearCoatTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are clear coat bump textures enabled in the application.\n */\n static get ClearCoatBumpTextureEnabled() {\n return this._ClearCoatBumpTextureEnabled;\n }\n static set ClearCoatBumpTextureEnabled(value) {\n if (this._ClearCoatBumpTextureEnabled === value) {\n return;\n }\n this._ClearCoatBumpTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are clear coat tint textures enabled in the application.\n */\n static get ClearCoatTintTextureEnabled() {\n return this._ClearCoatTintTextureEnabled;\n }\n static set ClearCoatTintTextureEnabled(value) {\n if (this._ClearCoatTintTextureEnabled === value) {\n return;\n }\n this._ClearCoatTintTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are sheen textures enabled in the application.\n */\n static get SheenTextureEnabled() {\n return this._SheenTextureEnabled;\n }\n static set SheenTextureEnabled(value) {\n if (this._SheenTextureEnabled === value) {\n return;\n }\n this._SheenTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are anisotropic textures enabled in the application.\n */\n static get AnisotropicTextureEnabled() {\n return this._AnisotropicTextureEnabled;\n }\n static set AnisotropicTextureEnabled(value) {\n if (this._AnisotropicTextureEnabled === value) {\n return;\n }\n this._AnisotropicTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are thickness textures enabled in the application.\n */\n static get ThicknessTextureEnabled() {\n return this._ThicknessTextureEnabled;\n }\n static set ThicknessTextureEnabled(value) {\n if (this._ThicknessTextureEnabled === value) {\n return;\n }\n this._ThicknessTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are refraction intensity textures enabled in the application.\n */\n static get RefractionIntensityTextureEnabled() {\n return this._ThicknessTextureEnabled;\n }\n static set RefractionIntensityTextureEnabled(value) {\n if (this._RefractionIntensityTextureEnabled === value) {\n return;\n }\n this._RefractionIntensityTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are translucency intensity textures enabled in the application.\n */\n static get TranslucencyIntensityTextureEnabled() {\n return this._ThicknessTextureEnabled;\n }\n static set TranslucencyIntensityTextureEnabled(value) {\n if (this._TranslucencyIntensityTextureEnabled === value) {\n return;\n }\n this._TranslucencyIntensityTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n /**\n * Are translucency intensity textures enabled in the application.\n */\n static get IridescenceTextureEnabled() {\n return this._IridescenceTextureEnabled;\n }\n static set IridescenceTextureEnabled(value) {\n if (this._IridescenceTextureEnabled === value) {\n return;\n }\n this._IridescenceTextureEnabled = value;\n Engine.MarkAllMaterialsAsDirty(1);\n }\n }\n // Flags used to enable or disable a type of texture for all Standard Materials\n MaterialFlags._DiffuseTextureEnabled = true;\n MaterialFlags._DetailTextureEnabled = true;\n MaterialFlags._DecalMapEnabled = true;\n MaterialFlags._AmbientTextureEnabled = true;\n MaterialFlags._OpacityTextureEnabled = true;\n MaterialFlags._ReflectionTextureEnabled = true;\n MaterialFlags._EmissiveTextureEnabled = true;\n MaterialFlags._SpecularTextureEnabled = true;\n MaterialFlags._BumpTextureEnabled = true;\n MaterialFlags._LightmapTextureEnabled = true;\n MaterialFlags._RefractionTextureEnabled = true;\n MaterialFlags._ColorGradingTextureEnabled = true;\n MaterialFlags._FresnelEnabled = true;\n MaterialFlags._ClearCoatTextureEnabled = true;\n MaterialFlags._ClearCoatBumpTextureEnabled = true;\n MaterialFlags._ClearCoatTintTextureEnabled = true;\n MaterialFlags._SheenTextureEnabled = true;\n MaterialFlags._AnisotropicTextureEnabled = true;\n MaterialFlags._ThicknessTextureEnabled = true;\n MaterialFlags._RefractionIntensityTextureEnabled = true;\n MaterialFlags._TranslucencyIntensityTextureEnabled = true;\n MaterialFlags._IridescenceTextureEnabled = true;\n\n // Do not edit.\n const name = \"decalFragmentDeclaration\";\n const shader = `#ifdef DECAL\nuniform vec4 vDecalInfos;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name] = shader;\n\n // Do not edit.\n const name$1 = \"defaultFragmentDeclaration\";\n const shader$1 = `uniform vec4 vEyePosition;uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;uniform vec3 vAmbientColor;uniform float visibility;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#ifdef ALPHATEST\nuniform float alphaCutOff;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION) || defined(PREPASS)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;uniform vec4 refractionRightColor;\n#endif\n#if defined(USE_LOCAL_REFRACTIONMAP_CUBIC) && defined(REFRACTIONMAP_3D)\nuniform vec3 vRefractionPosition;uniform vec3 vRefractionSize; \n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;uniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;uniform vec4 emissiveRightColor;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION) || defined(REFLECTIONMAP_EQUIRECTANGULAR) || defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_SKYBOX)\nuniform mat4 reflectionMatrix;\n#endif\n#ifndef REFLECTIONMAP_SKYBOX\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;uniform vec3 vReflectionSize; \n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;uniform vec4 reflectionRightColor;\n#endif\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;\n#endif\n#include\n#define ADDITIONAL_FRAGMENT_DECLARATION\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1] = shader$1;\n\n // Do not edit.\n const name$2 = \"sceneUboDeclaration\";\n const shader$2 = `layout(std140,column_major) uniform;uniform Scene {mat4 viewProjection;\n#ifdef MULTIVIEW\nmat4 viewProjectionR;\n#endif \nmat4 view;mat4 projection;vec4 vEyePosition;};\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2] = shader$2;\n\n // Do not edit.\n const name$3 = \"meshUboDeclaration\";\n const shader$3 = `#ifdef WEBGL2\nuniform mat4 world;uniform float visibility;\n#else\nlayout(std140,column_major) uniform;uniform Mesh\n{mat4 world;float visibility;};\n#endif\n#define WORLD_UBO\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$3] = shader$3;\n\n // Do not edit.\n const name$4 = \"defaultUboDeclaration\";\n const shader$4 = `layout(std140,column_major) uniform;uniform Material\n{vec4 diffuseLeftColor;vec4 diffuseRightColor;vec4 opacityParts;vec4 reflectionLeftColor;vec4 reflectionRightColor;vec4 refractionLeftColor;vec4 refractionRightColor;vec4 emissiveLeftColor;vec4 emissiveRightColor;vec2 vDiffuseInfos;vec2 vAmbientInfos;vec2 vOpacityInfos;vec2 vReflectionInfos;vec3 vReflectionPosition;vec3 vReflectionSize;vec2 vEmissiveInfos;vec2 vLightmapInfos;vec2 vSpecularInfos;vec3 vBumpInfos;mat4 diffuseMatrix;mat4 ambientMatrix;mat4 opacityMatrix;mat4 reflectionMatrix;mat4 emissiveMatrix;mat4 lightmapMatrix;mat4 specularMatrix;mat4 bumpMatrix;vec2 vTangentSpaceParams;float pointSize;float alphaCutOff;mat4 refractionMatrix;vec4 vRefractionInfos;vec3 vRefractionPosition;vec3 vRefractionSize;vec4 vSpecularColor;vec3 vEmissiveColor;vec4 vDiffuseColor;vec3 vAmbientColor;\n#define ADDITIONAL_UBO_DECLARATION\n};\n#include\n#include\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$4] = shader$4;\n\n // Do not edit.\n const name$5 = \"prePassDeclaration\";\n const shader$5 = `#ifdef PREPASS\n#extension GL_EXT_draw_buffers : require\nlayout(location=0) out highp vec4 glFragData[{X}];highp vec4 gl_FragColor;\n#ifdef PREPASS_DEPTH\nvarying highp vec3 vViewPos;\n#endif\n#ifdef PREPASS_VELOCITY\nvarying highp vec4 vCurrentPosition;varying highp vec4 vPreviousPosition;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$5] = shader$5;\n\n // Do not edit.\n const name$6 = \"oitDeclaration\";\n const shader$6 = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY\n#extension GL_EXT_draw_buffers : require\nlayout(location=0) out vec2 depth; \nlayout(location=1) out vec4 frontColor;layout(location=2) out vec4 backColor;\n#define MAX_DEPTH 99999.0\nhighp vec4 gl_FragColor;uniform sampler2D oitDepthSampler;uniform sampler2D oitFrontColorSampler;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$6] = shader$6;\n\n // Do not edit.\n const name$7 = \"mainUVVaryingDeclaration\";\n const shader$7 = `#ifdef MAINUV{X}\nvarying vec2 vMainUV{X};\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$7] = shader$7;\n\n // Do not edit.\n const name$8 = \"helperFunctions\";\n const shader$8 = `const float PI=3.1415926535897932384626433832795;const float HALF_MIN=5.96046448e-08; \nconst float LinearEncodePowerApprox=2.2;const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);const float Epsilon=0.0000001;\n#define saturate(x) clamp(x,0.0,1.0)\n#define absEps(x) abs(x)+Epsilon\n#define maxEps(x) max(x,Epsilon)\n#define saturateEps(x) clamp(x,Epsilon,1.0)\nmat3 transposeMat3(mat3 inMatrix) {vec3 i0=inMatrix[0];vec3 i1=inMatrix[1];vec3 i2=inMatrix[2];mat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);return outMatrix;}\nmat3 inverseMat3(mat3 inMatrix) {float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}\n#if USE_EXACT_SRGB_CONVERSIONS\nvec3 toLinearSpaceExact(vec3 color)\n{vec3 nearZeroSection=0.0773993808*color;vec3 remainingSection=pow(0.947867299*(color+vec3(0.055)),vec3(2.4));\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nreturn mix(remainingSection,nearZeroSection,lessThanEqual(color,vec3(0.04045)));\n#else\nreturn\nvec3(\ncolor.r<=0.04045 ? nearZeroSection.r : remainingSection.r,\ncolor.g<=0.04045 ? nearZeroSection.g : remainingSection.g,\ncolor.b<=0.04045 ? nearZeroSection.b : remainingSection.b);\n#endif\n}\nvec3 toGammaSpaceExact(vec3 color)\n{vec3 nearZeroSection=12.92*color;vec3 remainingSection=1.055*pow(color,vec3(0.41666))-vec3(0.055);\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nreturn mix(remainingSection,nearZeroSection,lessThanEqual(color,vec3(0.0031308)));\n#else\nreturn\nvec3(\ncolor.r<=0.0031308 ? nearZeroSection.r : remainingSection.r,\ncolor.g<=0.0031308 ? nearZeroSection.g : remainingSection.g,\ncolor.b<=0.0031308 ? nearZeroSection.b : remainingSection.b);\n#endif\n}\n#endif\nfloat toLinearSpace(float color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nfloat nearZeroSection=0.0773993808*color;float remainingSection=pow(0.947867299*(color+0.055),2.4);return color<=0.04045 ? nearZeroSection : remainingSection;\n#else\nreturn pow(color,LinearEncodePowerApprox);\n#endif\n}\nvec3 toLinearSpace(vec3 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn toLinearSpaceExact(color);\n#else\nreturn pow(color,vec3(LinearEncodePowerApprox));\n#endif\n}\nvec4 toLinearSpace(vec4 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn vec4(toLinearSpaceExact(color.rgb),color.a);\n#else\nreturn vec4(pow(color.rgb,vec3(LinearEncodePowerApprox)),color.a);\n#endif\n}\nfloat toGammaSpace(float color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nfloat nearZeroSection=12.92*color;float remainingSection=1.055*pow(color,0.41666)-0.055;return color<=0.0031308 ? nearZeroSection : remainingSection;\n#else\nreturn pow(color,GammaEncodePowerApprox);\n#endif\n}\nvec3 toGammaSpace(vec3 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn toGammaSpaceExact(color);\n#else\nreturn pow(color,vec3(GammaEncodePowerApprox));\n#endif\n}\nvec4 toGammaSpace(vec4 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn vec4(toGammaSpaceExact(color.rgb),color.a);\n#else\nreturn vec4(pow(color.rgb,vec3(GammaEncodePowerApprox)),color.a);\n#endif\n}\nfloat square(float value)\n{return value*value;}\nvec3 square(vec3 value)\n{return value*value;}\nfloat pow5(float value) {float sq=value*value;return sq*sq*value;}\nfloat getLuminance(vec3 color)\n{return clamp(dot(color,LuminanceEncodeApprox),0.,1.);}\nfloat getRand(vec2 seed) {return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);}\nfloat dither(vec2 seed,float varianceAmount) {float rand=getRand(seed);float normVariance=varianceAmount/255.0;float dither=mix(-normVariance,normVariance,rand);return dither;}\nconst float rgbdMaxRange=255.0;vec4 toRGBD(vec3 color) {float maxRGB=maxEps(max(color.r,max(color.g,color.b)));float D =max(rgbdMaxRange/maxRGB,1.);D =clamp(floor(D)/255.0,0.,1.);vec3 rgb=color.rgb*D;rgb=toGammaSpace(rgb);return vec4(clamp(rgb,0.,1.),D); }\nvec3 fromRGBD(vec4 rgbd) {rgbd.rgb=toLinearSpace(rgbd.rgb);return rgbd.rgb/rgbd.a;}\nvec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {vec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;vec3 halfSize=cubeSize*0.5;vec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)*invOrigVec;vec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)*invOrigVec;vec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);float distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);vec3 intersectPositionWS=vertexPos+origVec*distance;return intersectPositionWS-cubePos;}\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$8] = shader$8;\n\n // Do not edit.\n const name$9 = \"lightFragmentDeclaration\";\n const shader$9 = `#ifdef LIGHT{X}\nuniform vec4 vLightData{X};uniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec4 vLightSpecular{X};\n#else\nvec4 vLightSpecular{X}=vec4(0.);\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];uniform float viewFrustumZ{X}[SHADOWCSMNUM_CASCADES{X}];uniform float frustumLengths{X}[SHADOWCSMNUM_CASCADES{X}];uniform float cascadeBlendFactor{X};varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};uniform highp sampler2DArray depthSampler{X};uniform vec2 lightSizeUVCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float depthCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float penumbraDarkness{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};\n#else\nuniform highp sampler2DArray shadowSampler{X};\n#endif\n#ifdef SHADOWCSMDEBUG{X}\nconst vec3 vCascadeColorsMultiplier{X}[8]=vec3[8]\n(\nvec3 ( 1.5,0.0,0.0 ),\nvec3 ( 0.0,1.5,0.0 ),\nvec3 ( 0.0,0.0,5.5 ),\nvec3 ( 1.5,0.0,5.5 ),\nvec3 ( 1.5,1.5,0.0 ),\nvec3 ( 1.0,1.0,1.0 ),\nvec3 ( 0.0,1.0,5.5 ),\nvec3 ( 0.5,3.5,0.75 )\n);vec3 shadowDebug{X};\n#endif\n#ifdef SHADOWCSMUSESHADOWMAXZ{X}\nint index{X}=-1;\n#else\nint index{X}=SHADOWCSMNUM_CASCADES{X}-1;\n#endif\nfloat diff{X}=0.;\n#elif defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};uniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};uniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};uniform vec4 vLightFalloff{X};\n#elif defined(POINTLIGHT{X})\nuniform vec4 vLightFalloff{X};\n#elif defined(HEMILIGHT{X})\nuniform vec3 vLightGround{X};\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};uniform sampler2D projectionLightSampler{X};\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$9] = shader$9;\n\n // Do not edit.\n const name$a = \"lightUboDeclaration\";\n const shader$a = `#ifdef LIGHT{X}\nuniform Light{X}\n{vec4 vLightData;vec4 vLightDiffuse;vec4 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;vec4 vLightFalloff;\n#elif defined(POINTLIGHT{X})\nvec4 vLightFalloff;\n#elif defined(HEMILIGHT{X})\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;vec2 depthValues;} light{X};\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};uniform sampler2D projectionLightSampler{X};\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];uniform float viewFrustumZ{X}[SHADOWCSMNUM_CASCADES{X}];uniform float frustumLengths{X}[SHADOWCSMNUM_CASCADES{X}];uniform float cascadeBlendFactor{X};varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};uniform highp sampler2DArray depthSampler{X};uniform vec2 lightSizeUVCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float depthCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float penumbraDarkness{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};\n#else\nuniform highp sampler2DArray shadowSampler{X};\n#endif\n#ifdef SHADOWCSMDEBUG{X}\nconst vec3 vCascadeColorsMultiplier{X}[8]=vec3[8]\n(\nvec3 ( 1.5,0.0,0.0 ),\nvec3 ( 0.0,1.5,0.0 ),\nvec3 ( 0.0,0.0,5.5 ),\nvec3 ( 1.5,0.0,5.5 ),\nvec3 ( 1.5,1.5,0.0 ),\nvec3 ( 1.0,1.0,1.0 ),\nvec3 ( 0.0,1.0,5.5 ),\nvec3 ( 0.5,3.5,0.75 )\n);vec3 shadowDebug{X};\n#endif\n#ifdef SHADOWCSMUSESHADOWMAXZ{X}\nint index{X}=-1;\n#else\nint index{X}=SHADOWCSMNUM_CASCADES{X}-1;\n#endif\nfloat diff{X}=0.;\n#elif defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X}; \n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};uniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$a] = shader$a;\n\n // Do not edit.\n const name$b = \"lightsFragmentFunctions\";\n const shader$b = `struct lightingInfo\n{vec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};lightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {lightingInfo result;vec3 lightVectorW;float attenuation=1.0;if (lightData.w==0.)\n{vec3 direction=lightData.xyz-vPositionW;attenuation=max(0.,1.0-length(direction)/range);lightVectorW=normalize(direction);}\nelse\n{lightVectorW=normalize(-lightData.xyz);}\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\nvec3 angleW=normalize(viewDirectionW+lightVectorW);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {lightingInfo result;vec3 direction=lightData.xyz-vPositionW;vec3 lightVectorW=normalize(direction);float attenuation=max(0.,1.0-length(direction)/range);float cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));if (cosAngle>=lightDirection.w)\n{cosAngle=max(0.,pow(cosAngle,lightData.w));attenuation*=cosAngle;float ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\nvec3 angleW=normalize(viewDirectionW+lightVectorW);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {lightingInfo result;float ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor;\n#endif\nreturn result;}\n#define inline\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);strq/=strq.w;vec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;return textureColor;}`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$b] = shader$b;\n\n // Do not edit.\n const name$c = \"shadowsFragmentFunctions\";\n const shader$c = `#ifdef SHADOWS\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)\n#else\n#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)\n#endif\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{const vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);return dot(color,bit_shift);}\n#endif\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{float mask=smoothstep(1.0-frustumEdgeFalloff,1.00000012,clamp(dot(clipSpace,clipSpace),0.,1.));return mix(value,1.0,mask);}\n#define inline\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{vec3 directionToLight=vPositionW-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);depth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nreturn depth>shadow ? darkness : 1.0;}\n#define inline\nfloat computeShadowWithPoissonSamplingCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{vec3 directionToLight=vPositionW-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);depth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;float visibility=1.;vec3 poissonDisk[4];poissonDisk[0]=vec3(-1.0,1.0,-1.0);poissonDisk[1]=vec3(1.0,-1.0,-1.0);poissonDisk[2]=vec3(-1.0,-1.0,-1.0);poissonDisk[3]=vec3(1.0,-1.0,1.0);\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))shadow ? computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff) : 1.;}\n#endif\n#define inline\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(TEXTUREFUNC(shadowSampler,uv,0.));\n#else\nfloat shadow=TEXTUREFUNC(shadowSampler,uv,0.).x;\n#endif\nreturn shadowPixelDepth>shadow ? computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff) : 1.;}}\n#define inline\nfloat computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0);float visibility=1.;vec2 poissonDisk[4];poissonDisk[0]=vec2(-0.94201624,-0.39906216);poissonDisk[1]=vec2(0.94558609,-0.76890725);poissonDisk[2]=vec2(-0.094184101,-0.92938870);poissonDisk[3]=vec2(0.34495938,0.29387760);\n#ifndef SHADOWFLOAT\nif (unpack(TEXTUREFUNC(shadowSampler,uv+poissonDisk[0]*mapSize,0.))1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(TEXTUREFUNC(shadowSampler,uv,0.));\n#else\nfloat shadowMapSample=TEXTUREFUNC(shadowSampler,uv,0.).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}\n#define inline\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(TEXTUREFUNC(shadowSampler,uv,0.));\n#else\nfloat shadowMapSample=TEXTUREFUNC(shadowSampler,uv,0.).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}\n#ifdef IS_NDC_HALF_ZRANGE\n#define ZINCLIP clipSpace.z\n#else\n#define ZINCLIP uvDepth.z\n#endif\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define GREATEST_LESS_THAN_ONE 0.99999994\n#define inline\nfloat computeShadowWithCSMPCF1(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec4 uvDepthLayer=vec4(uvDepth.x,uvDepth.y,layer,uvDepth.z);float shadow=texture2D(shadowSampler,uvDepthLayer);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}\n#define inline\nfloat computeShadowWithCSMPCF3(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=3.-2.*st;vec2 uvw1=1.+2.*st;vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[0]),layer,uvDepth.z));shadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[0]),layer,uvDepth.z));shadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[1]),layer,uvDepth.z));shadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[1]),layer,uvDepth.z));shadow=shadow/16.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}\n#define inline\nfloat computeShadowWithCSMPCF5(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=4.-3.*st;vec2 uvw1=vec2(7.);vec2 uvw2=1.+3.*st;vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[0]),layer,uvDepth.z));shadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[0]),layer,uvDepth.z));shadow+=uvw2.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[0]),layer,uvDepth.z));shadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[1]),layer,uvDepth.z));shadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[1]),layer,uvDepth.z));shadow+=uvw2.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[1]),layer,uvDepth.z));shadow+=uvw0.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[2]),layer,uvDepth.z));shadow+=uvw1.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[2]),layer,uvDepth.z));shadow+=uvw2.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[2]),layer,uvDepth.z));shadow=shadow/144.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}\n#define inline\nfloat computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)\n{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;float shadow=TEXTUREFUNC(shadowSampler,uvDepth,0.);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}\n#define inline\nfloat computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=3.-2.*st;vec2 uvw1=1.+2.*st;vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z),0.);shadow+=uvw1.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z),0.);shadow+=uvw0.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z),0.);shadow+=uvw1.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z),0.);shadow=shadow/16.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}\n#define inline\nfloat computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=4.-3.*st;vec2 uvw1=vec2(7.);vec2 uvw2=1.+3.*st;vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z),0.);shadow+=uvw1.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z),0.);shadow+=uvw2.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z),0.);shadow+=uvw0.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z),0.);shadow+=uvw1.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z),0.);shadow+=uvw2.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z),0.);shadow+=uvw0.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z),0.);shadow+=uvw1.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z),0.);shadow+=uvw2.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z),0.);shadow=shadow/144.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}\nconst vec3 PoissonSamplers32[64]=vec3[64](\nvec3(0.06407013,0.05409927,0.),\nvec3(0.7366577,0.5789394,0.),\nvec3(-0.6270542,-0.5320278,0.),\nvec3(-0.4096107,0.8411095,0.),\nvec3(0.6849564,-0.4990818,0.),\nvec3(-0.874181,-0.04579735,0.),\nvec3(0.9989998,0.0009880066,0.),\nvec3(-0.004920578,-0.9151649,0.),\nvec3(0.1805763,0.9747483,0.),\nvec3(-0.2138451,0.2635818,0.),\nvec3(0.109845,0.3884785,0.),\nvec3(0.06876755,-0.3581074,0.),\nvec3(0.374073,-0.7661266,0.),\nvec3(0.3079132,-0.1216763,0.),\nvec3(-0.3794335,-0.8271583,0.),\nvec3(-0.203878,-0.07715034,0.),\nvec3(0.5912697,0.1469799,0.),\nvec3(-0.88069,0.3031784,0.),\nvec3(0.5040108,0.8283722,0.),\nvec3(-0.5844124,0.5494877,0.),\nvec3(0.6017799,-0.1726654,0.),\nvec3(-0.5554981,0.1559997,0.),\nvec3(-0.3016369,-0.3900928,0.),\nvec3(-0.5550632,-0.1723762,0.),\nvec3(0.925029,0.2995041,0.),\nvec3(-0.2473137,0.5538505,0.),\nvec3(0.9183037,-0.2862392,0.),\nvec3(0.2469421,0.6718712,0.),\nvec3(0.3916397,-0.4328209,0.),\nvec3(-0.03576927,-0.6220032,0.),\nvec3(-0.04661255,0.7995201,0.),\nvec3(0.4402924,0.3640312,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.)\n);const vec3 PoissonSamplers64[64]=vec3[64](\nvec3(-0.613392,0.617481,0.),\nvec3(0.170019,-0.040254,0.),\nvec3(-0.299417,0.791925,0.),\nvec3(0.645680,0.493210,0.),\nvec3(-0.651784,0.717887,0.),\nvec3(0.421003,0.027070,0.),\nvec3(-0.817194,-0.271096,0.),\nvec3(-0.705374,-0.668203,0.),\nvec3(0.977050,-0.108615,0.),\nvec3(0.063326,0.142369,0.),\nvec3(0.203528,0.214331,0.),\nvec3(-0.667531,0.326090,0.),\nvec3(-0.098422,-0.295755,0.),\nvec3(-0.885922,0.215369,0.),\nvec3(0.566637,0.605213,0.),\nvec3(0.039766,-0.396100,0.),\nvec3(0.751946,0.453352,0.),\nvec3(0.078707,-0.715323,0.),\nvec3(-0.075838,-0.529344,0.),\nvec3(0.724479,-0.580798,0.),\nvec3(0.222999,-0.215125,0.),\nvec3(-0.467574,-0.405438,0.),\nvec3(-0.248268,-0.814753,0.),\nvec3(0.354411,-0.887570,0.),\nvec3(0.175817,0.382366,0.),\nvec3(0.487472,-0.063082,0.),\nvec3(-0.084078,0.898312,0.),\nvec3(0.488876,-0.783441,0.),\nvec3(0.470016,0.217933,0.),\nvec3(-0.696890,-0.549791,0.),\nvec3(-0.149693,0.605762,0.),\nvec3(0.034211,0.979980,0.),\nvec3(0.503098,-0.308878,0.),\nvec3(-0.016205,-0.872921,0.),\nvec3(0.385784,-0.393902,0.),\nvec3(-0.146886,-0.859249,0.),\nvec3(0.643361,0.164098,0.),\nvec3(0.634388,-0.049471,0.),\nvec3(-0.688894,0.007843,0.),\nvec3(0.464034,-0.188818,0.),\nvec3(-0.440840,0.137486,0.),\nvec3(0.364483,0.511704,0.),\nvec3(0.034028,0.325968,0.),\nvec3(0.099094,-0.308023,0.),\nvec3(0.693960,-0.366253,0.),\nvec3(0.678884,-0.204688,0.),\nvec3(0.001801,0.780328,0.),\nvec3(0.145177,-0.898984,0.),\nvec3(0.062655,-0.611866,0.),\nvec3(0.315226,-0.604297,0.),\nvec3(-0.780145,0.486251,0.),\nvec3(-0.371868,0.882138,0.),\nvec3(0.200476,0.494430,0.),\nvec3(-0.494552,-0.711051,0.),\nvec3(0.612476,0.705252,0.),\nvec3(-0.578845,-0.768792,0.),\nvec3(-0.772454,-0.090976,0.),\nvec3(0.504440,0.372295,0.),\nvec3(0.155736,0.065157,0.),\nvec3(0.391522,0.849605,0.),\nvec3(-0.620106,-0.328104,0.),\nvec3(0.789239,-0.419965,0.),\nvec3(-0.545396,0.538133,0.),\nvec3(-0.178564,-0.596057,0.)\n);\n#define inline\nfloat computeShadowWithCSMPCSS(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray depthSampler,highp sampler2DArrayShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers,vec2 lightSizeUVCorrection,float depthCorrection,float penumbraDarkness)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec4 uvDepthLayer=vec4(uvDepth.x,uvDepth.y,layer,uvDepth.z);float blockerDepth=0.0;float sumBlockerDepth=0.0;float numBlocker=0.0;for (int i=0; i1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;float blockerDepth=0.0;float sumBlockerDepth=0.0;float numBlocker=0.0;for (int i=0; i(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_SAMPLERNAME_,bump)\n#endif\n#if defined(DETAIL)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)\n#endif\n#if defined(BUMP) && defined(PARALLAX)\nconst float minSamples=4.;const float maxSamples=15.;const int iMaxSamples=15;vec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {float parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;parallaxLimit*=parallaxScale;vec2 vOffsetDir=normalize(vViewDirCoT.xy);vec2 vMaxOffset=vOffsetDir*parallaxLimit;float numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));float stepSize=1.0/numSamples;float currRayHeight=1.0;vec2 vCurrOffset=vec2(0,0);vec2 vLastOffset=vec2(0,0);float lastSampledHeight=1.0;float currSampledHeight=1.0;bool keepWorking=true;for (int i=0; icurrRayHeight)\n{float delta1=currSampledHeight-currRayHeight;float delta2=(currRayHeight+stepSize)-lastSampledHeight;float ratio=delta1/(delta1+delta2);vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;keepWorking=false;}\nelse\n{currRayHeight-=stepSize;vLastOffset=vCurrOffset;vCurrOffset+=stepSize*vMaxOffset;lastSampledHeight=currSampledHeight;}}\nreturn vCurrOffset;}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{float height=texture2D(bumpSampler,vBumpUV).w;vec2 texCoordOffset=heightScale*viewDir.xy*height;return -texCoordOffset;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$j] = shader$j;\n\n // Do not edit.\n const name$k = \"clipPlaneFragmentDeclaration\";\n const shader$k = `#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nvarying float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nvarying float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nvarying float fClipDistance4;\n#endif\n#ifdef CLIPPLANE5\nvarying float fClipDistance5;\n#endif\n#ifdef CLIPPLANE6\nvarying float fClipDistance6;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$k] = shader$k;\n\n // Do not edit.\n const name$l = \"logDepthDeclaration\";\n const shader$l = `#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;varying float vFragmentDepth;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$l] = shader$l;\n\n // Do not edit.\n const name$m = \"fogFragmentDeclaration\";\n const shader$m = `#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;uniform vec3 vFogColor;varying vec3 vFogDistance;float CalcFogFactor()\n{float fogCoeff=1.0;float fogStart=vFogInfos.y;float fogEnd=vFogInfos.z;float fogDensity=vFogInfos.w;float fogDistance=length(vFogDistance);if (FOGMODE_LINEAR==vFogInfos.x)\n{fogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);}\nelse if (FOGMODE_EXP==vFogInfos.x)\n{fogCoeff=1.0/pow(E,fogDistance*fogDensity);}\nelse if (FOGMODE_EXP2==vFogInfos.x)\n{fogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);}\nreturn clamp(fogCoeff,0.0,1.0);}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$m] = shader$m;\n\n // Do not edit.\n const name$n = \"clipPlaneFragment\";\n const shader$n = `#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)\nif (false) {}\n#endif\n#ifdef CLIPPLANE\nelse if (fClipDistance>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE2\nelse if (fClipDistance2>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE3\nelse if (fClipDistance3>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE4\nelse if (fClipDistance4>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE5\nelse if (fClipDistance5>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE6\nelse if (fClipDistance6>0.0)\n{discard;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$n] = shader$n;\n\n // Do not edit.\n const name$o = \"bumpFragment\";\n const shader$o = `vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#elif defined(BUMP)\nfloat normalScale=vBumpInfos.y;\n#else\nfloat normalScale=1.0;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#elif defined(BUMP)\nvec2 TBNUV=gl_FrontFacing ? vBumpUV : -vBumpUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vTangentSpaceParams);\n#else\nvec2 TBNUV=gl_FrontFacing ? vDetailUV : -vDetailUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vec2(1.,1.));\n#endif\n#elif defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nvec2 TBNUV=gl_FrontFacing ? vMainUV1 : -vMainUV1;mat3 TBN=cotangent_frame(normalW,vPositionW,TBNUV,vec2(1.,1.));\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef DETAIL\nvec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);vec2 detailNormalRG=detailColor.wy*2.0-1.0;float detailNormalB=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));vec3 detailNormal=vec3(detailNormalRG,detailNormalB);\n#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\n#define CUSTOM_FRAGMENT_BUMP_FRAGMENT\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);normalW=normalize(mat3(normalMatrix)*normalW);\n#elif !defined(DETAIL)\nnormalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);\n#else\nvec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;\n#if DETAIL_NORMALBLENDMETHOD==0 \ndetailNormal.xy*=vDetailInfos.z;vec3 blendedNormal=normalize(vec3(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));\n#elif DETAIL_NORMALBLENDMETHOD==1 \ndetailNormal.xy*=vDetailInfos.z;bumpNormal+=vec3(0.0,0.0,1.0);detailNormal*=vec3(-1.0,-1.0,1.0);vec3 blendedNormal=bumpNormal*dot(bumpNormal,detailNormal)/bumpNormal.z-detailNormal;\n#endif\nnormalW=perturbNormalBase(TBN,blendedNormal,vBumpInfos.y);\n#endif\n#elif defined(DETAIL)\ndetailNormal.xy*=vDetailInfos.z;normalW=perturbNormalBase(TBN,detailNormal,vDetailInfos.z);\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$o] = shader$o;\n\n // Do not edit.\n const name$p = \"decalFragment\";\n const shader$p = `#ifdef DECAL\n#ifdef GAMMADECAL\ndecalColor.rgb=toLinearSpace(decalColor.rgb);\n#endif\n#ifdef DECAL_SMOOTHALPHA\ndecalColor.a*=decalColor.a;\n#endif\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,decalColor.rgb,decalColor.a);\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$p] = shader$p;\n\n // Do not edit.\n const name$q = \"depthPrePass\";\n const shader$q = `#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);return;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$q] = shader$q;\n\n // Do not edit.\n const name$r = \"lightFragment\";\n const shader$r = `#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\npreInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#elif defined(POINTLIGHT{X})\npreInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#elif defined(HEMILIGHT{X})\npreInfo=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#elif defined(DIRLIGHT{X})\npreInfo=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#endif\npreInfo.NdotV=NdotV;\n#ifdef SPOTLIGHT{X}\n#ifdef LIGHT_FALLOFF_GLTF{X}\npreInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);preInfo.attenuation*=computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);\n#elif defined(LIGHT_FALLOFF_PHYSICAL{X})\npreInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);preInfo.attenuation*=computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w);\n#elif defined(LIGHT_FALLOFF_STANDARD{X})\npreInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);preInfo.attenuation*=computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w);\n#else\npreInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);preInfo.attenuation*=computeDirectionalLightFalloff(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);\n#endif\n#elif defined(POINTLIGHT{X})\n#ifdef LIGHT_FALLOFF_GLTF{X}\npreInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);\n#elif defined(LIGHT_FALLOFF_PHYSICAL{X})\npreInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);\n#elif defined(LIGHT_FALLOFF_STANDARD{X})\npreInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);\n#else\npreInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);\n#endif\n#else\npreInfo.attenuation=1.0;\n#endif\n#ifdef HEMILIGHT{X}\npreInfo.roughness=roughness;\n#else\npreInfo.roughness=adjustRoughnessFromLightProperties(roughness,light{X}.vLightSpecular.a,preInfo.lightDistance);\n#endif\n#ifdef IRIDESCENCE\npreInfo.iridescenceIntensity=iridescenceIntensity;\n#endif\n#ifdef HEMILIGHT{X}\ninfo.diffuse=computeHemisphericDiffuseLighting(preInfo,light{X}.vLightDiffuse.rgb,light{X}.vLightGround);\n#elif defined(SS_TRANSLUCENCY)\ninfo.diffuse=computeDiffuseAndTransmittedLighting(preInfo,light{X}.vLightDiffuse.rgb,subSurfaceOut.transmittance);\n#else\ninfo.diffuse=computeDiffuseLighting(preInfo,light{X}.vLightDiffuse.rgb);\n#endif\n#ifdef SPECULARTERM\n#ifdef ANISOTROPIC\ninfo.specular=computeAnisotropicSpecularLighting(preInfo,viewDirectionW,normalW,anisotropicOut.anisotropicTangent,anisotropicOut.anisotropicBitangent,anisotropicOut.anisotropy,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,AARoughnessFactors.x,light{X}.vLightDiffuse.rgb);\n#else\ninfo.specular=computeSpecularLighting(preInfo,normalW,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,AARoughnessFactors.x,light{X}.vLightDiffuse.rgb);\n#endif\n#endif\n#ifdef SHEEN\n#ifdef SHEEN_LINKWITHALBEDO\npreInfo.roughness=sheenOut.sheenIntensity;\n#else\n#ifdef HEMILIGHT{X}\npreInfo.roughness=sheenOut.sheenRoughness;\n#else\npreInfo.roughness=adjustRoughnessFromLightProperties(sheenOut.sheenRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);\n#endif\n#endif\ninfo.sheen=computeSheenLighting(preInfo,normalW,sheenOut.sheenColor,specularEnvironmentR90,AARoughnessFactors.x,light{X}.vLightDiffuse.rgb);\n#endif\n#ifdef CLEARCOAT\n#ifdef HEMILIGHT{X}\npreInfo.roughness=clearcoatOut.clearCoatRoughness;\n#else\npreInfo.roughness=adjustRoughnessFromLightProperties(clearcoatOut.clearCoatRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);\n#endif\ninfo.clearCoat=computeClearCoatLighting(preInfo,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatAARoughnessFactors.x,clearcoatOut.clearCoatIntensity,light{X}.vLightDiffuse.rgb);\n#ifdef CLEARCOAT_TINT\nabsorption=computeClearCoatLightingAbsorption(clearcoatOut.clearCoatNdotVRefract,preInfo.L,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatColor,clearcoatOut.clearCoatThickness,clearcoatOut.clearCoatIntensity);info.diffuse*=absorption;\n#ifdef SPECULARTERM\ninfo.specular*=absorption;\n#endif\n#endif\ninfo.diffuse*=info.clearCoat.w;\n#ifdef SPECULARTERM\ninfo.specular*=info.clearCoat.w;\n#endif\n#ifdef SHEEN\ninfo.sheen*=info.clearCoat.w;\n#endif\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightDiffuse.a,glossiness);\n#elif defined(HEMILIGHT{X})\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightGround,glossiness);\n#elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\ninfo.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler{X},textureProjectionMatrix{X});\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nfor (int i=0; i=0.) {index{X}=i;break;}}\n#ifdef SHADOWCSMUSESHADOWMAXZ{X}\nif (index{X}>=0)\n#endif\n{\n#if defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithCSMPCF1(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithCSMPCF3(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithCSMPCF5(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithCSMPCSS16(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithCSMPCSS32(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#else\nshadow=computeShadowWithCSMPCSS64(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#endif\n#else\nshadow=computeShadowCSM(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#ifdef SHADOWCSMDEBUG{X}\nshadowDebug{X}=vec3(shadow)*vCascadeColorsMultiplier{X}[index{X}];\n#endif\n#ifndef SHADOWCSMNOBLEND{X}\nfloat frustumLength=frustumLengths{X}[index{X}];float diffRatio=clamp(diff{X}/frustumLength,0.,1.)*cascadeBlendFactor{X};if (index{X}<(SHADOWCSMNUM_CASCADES{X}-1) && diffRatio<1.)\n{index{X}+=1;float nextShadow=0.;\n#if defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nnextShadow=computeShadowWithCSMPCF1(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nnextShadow=computeShadowWithCSMPCF3(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nnextShadow=computeShadowWithCSMPCF5(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nnextShadow=computeShadowWithCSMPCSS16(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#elif defined(SHADOWMEDIUMQUALITY{X})\nnextShadow=computeShadowWithCSMPCSS32(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#else\nnextShadow=computeShadowWithCSMPCSS64(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#endif\n#else\nnextShadow=computeShadowCSM(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\nshadow=mix(nextShadow,shadow,diffRatio);\n#ifdef SHADOWCSMDEBUG{X}\nshadowDebug{X}=mix(vec3(nextShadow)*vCascadeColorsMultiplier{X}[index{X}],shadowDebug{X},diffRatio);\n#endif\n}\n#endif\n}\n#elif defined(SHADOWCLOSEESM{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWESM{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPOISSON{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPoissonSamplingCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPoissonSampling(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCF1(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCF3(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCF5(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCSS16(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCSS32(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCSS64(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;shadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor.rgb*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor.rgb;\n#endif\n#endif\n#ifdef CLEARCOAT\n#ifndef LIGHTMAPNOSPECULAR{X}\nclearCoatBase+=info.clearCoat.rgb*shadow*lightmapColor.rgb;\n#endif\n#endif\n#ifdef SHEEN\n#ifndef LIGHTMAPNOSPECULAR{X}\nsheenBase+=info.sheen.rgb*shadow;\n#endif\n#endif\n#else\n#ifdef SHADOWCSMDEBUG{X}\ndiffuseBase+=info.diffuse*shadowDebug{X};\n#else \ndiffuseBase+=info.diffuse*shadow;\n#endif\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#ifdef CLEARCOAT\nclearCoatBase+=info.clearCoat.rgb*shadow;\n#endif\n#ifdef SHEEN\nsheenBase+=info.sheen.rgb*shadow;\n#endif\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$r] = shader$r;\n\n // Do not edit.\n const name$s = \"logDepthFragment\";\n const shader$s = `#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$s] = shader$s;\n\n // Do not edit.\n const name$t = \"fogFragment\";\n const shader$t = `#ifdef FOG\nfloat fog=CalcFogFactor();\n#ifdef PBR\nfog=toLinearSpace(fog);\n#endif\ncolor.rgb=mix(vFogColor,color.rgb,fog);\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$t] = shader$t;\n\n // Do not edit.\n const name$u = \"oitFragment\";\n const shader$u = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY\nfloat fragDepth=gl_FragCoord.z; \n#ifdef ORDER_INDEPENDENT_TRANSPARENCY_16BITS\nuint halfFloat=packHalf2x16(vec2(fragDepth));vec2 full=unpackHalf2x16(halfFloat);fragDepth=full.x;\n#endif\nivec2 fragCoord=ivec2(gl_FragCoord.xy);vec2 lastDepth=texelFetch(oitDepthSampler,fragCoord,0).rg;vec4 lastFrontColor=texelFetch(oitFrontColorSampler,fragCoord,0);depth.rg=vec2(-MAX_DEPTH);frontColor=lastFrontColor;backColor=vec4(0.0);\n#ifdef USE_REVERSE_DEPTHBUFFER\nfloat furthestDepth=-lastDepth.x;float nearestDepth=lastDepth.y;\n#else\nfloat nearestDepth=-lastDepth.x;float furthestDepth=lastDepth.y;\n#endif\nfloat alphaMultiplier=1.0-lastFrontColor.a;\n#ifdef USE_REVERSE_DEPTHBUFFER\nif (fragDepth>nearestDepth || fragDepthfurthestDepth) {\n#endif\nreturn;}\n#ifdef USE_REVERSE_DEPTHBUFFER\nif (fragDepthfurthestDepth) {\n#else\nif (fragDepth>nearestDepth && fragDepth\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include[SCENE_MRT_COUNT]\n#include\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#define RECIPROCAL_PI2 0.15915494\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include[1..7]\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_SAMPLERNAME_,diffuse)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULARTERM)\n#include(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_SAMPLERNAME_,specular)\n#endif\n#include\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#if defined(ALPHATEST) && !defined(ALPHATEST_AFTERALLALPHACOMPUTATIONS)\nif (baseColor.a(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#include\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef DETAIL\nbaseColor.rgb=baseColor.rgb*2.0*mix(0.5,detailColor.r,vDetailInfos.y);\n#endif\n#if defined(DECAL) && defined(DECAL_AFTER_DETAIL)\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#include(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);\n#ifdef RGBDLIGHTMAP\nlightmapColor.rgb=fromRGBD(lightmapColor);\n#endif\nlightmapColor.rgb*=vLightmapInfos.y;\n#endif\n#include[0..maxSimultaneousLights]\nvec4 refractionColor=vec4(0.,0.,0.,1.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\n#ifdef USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,vRefractionSize,vRefractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec4 refractionLookup=textureCube(refractionCubeSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=texture2D(refraction2DSampler,refractionCoords);\n#endif\n#ifdef RGBDREFRACTION\nrefractionColor.rgb=fromRGBD(refractionColor);\n#endif\n#ifdef IS_REFRACTION_LINEAR\nrefractionColor.rgb=toGammaSpace(refractionColor.rgb);\n#endif\nrefractionColor.rgb*=vRefractionInfos.x;\n#endif\nvec4 reflectionColor=vec4(0.,0.,0.,1.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nvReflectionUVW.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias);\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW);\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;reflectionColor=texture2D(reflection2DSampler,coords);\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef IS_REFLECTION_LINEAR\nreflectionColor.rgb=toGammaSpace(reflectionColor.rgb);\n#endif\nreflectionColor.rgb*=vReflectionInfos.x;\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor.rgb*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);refractionColor.rgb*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n#ifdef ALPHATEST\n#ifdef ALPHATEST_AFTERALLALPHACOMPUTATIONS\nif (alpha\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);\n#endif\n#endif\ncolor.a*=visibility;\n#ifdef PREMULTIPLYALPHA\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\n#ifdef PREPASS\nfloat writeGeometryInfo=color.a>0.4 ? 1.0 : 0.0;gl_FragData[0]=color; \n#ifdef PREPASS_POSITION\ngl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);\n#endif\n#ifdef PREPASS_VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);\n#endif\n#ifdef PREPASS_IRRADIANCE\ngl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_DEPTH\ngl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_NORMAL\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo); \n#endif\n#ifdef PREPASS_ALBEDO_SQRT\ngl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_REFLECTIVITY\n#if defined(SPECULARTERM)\n#if defined(SPECULAR)\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularMapColor))*writeGeometryInfo; \n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularColor),1.0)*writeGeometryInfo;\n#endif\n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(0.0,0.0,0.0,1.0)*writeGeometryInfo;\n#endif\n#endif\n#endif\n#if !defined(PREPASS) || defined(WEBGL2)\ngl_FragColor=color;\n#endif\n#include\n#if ORDER_INDEPENDENT_TRANSPARENCY\nif (fragDepth==nearestDepth) {frontColor.rgb+=color.rgb*color.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-color.a);} else {backColor+=color;}\n#endif\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$v] = shader$v;\n\n // Do not edit.\n const name$w = \"decalVertexDeclaration\";\n const shader$w = `#ifdef DECAL\nuniform vec4 vDecalInfos;uniform mat4 decalMatrix;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$w] = shader$w;\n\n // Do not edit.\n const name$x = \"defaultVertexDeclaration\";\n const shader$x = `uniform mat4 viewProjection;uniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;uniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef REFLECTION\nuniform mat4 reflectionMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$x] = shader$x;\n\n // Do not edit.\n const name$y = \"uvAttributeDeclaration\";\n const shader$y = `#ifdef UV{X}\nattribute vec2 uv{X};\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$y] = shader$y;\n\n // Do not edit.\n const name$z = \"bonesDeclaration\";\n const shader$z = `#if NUM_BONE_INFLUENCERS>0\nattribute vec4 matricesIndices;attribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;attribute vec4 matricesWeightsExtra;\n#endif\n#ifndef BAKED_VERTEX_ANIMATION_TEXTURE\n#ifdef BONETEXTURE\nuniform sampler2D boneSampler;uniform float boneTextureWidth;\n#else\nuniform mat4 mBones[BonesPerMesh];\n#ifdef BONES_VELOCITY_ENABLED\nuniform mat4 mPreviousBones[BonesPerMesh];\n#endif\n#endif\n#ifdef BONETEXTURE\n#define inline\nmat4 readMatrixFromRawSampler(sampler2D smp,float index)\n{float offset=index *4.0;float dx=1.0/boneTextureWidth;vec4 m0=texture2D(smp,vec2(dx*(offset+0.5),0.));vec4 m1=texture2D(smp,vec2(dx*(offset+1.5),0.));vec4 m2=texture2D(smp,vec2(dx*(offset+2.5),0.));vec4 m3=texture2D(smp,vec2(dx*(offset+3.5),0.));return mat4(m0,m1,m2,m3);}\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$z] = shader$z;\n\n // Do not edit.\n const name$A = \"bakedVertexAnimationDeclaration\";\n const shader$A = `#ifdef BAKED_VERTEX_ANIMATION_TEXTURE\nuniform float bakedVertexAnimationTime;uniform vec2 bakedVertexAnimationTextureSizeInverted;uniform vec4 bakedVertexAnimationSettings;uniform sampler2D bakedVertexAnimationTexture;\n#ifdef INSTANCES\nattribute vec4 bakedVertexAnimationSettingsInstanced;\n#endif\n#define inline\nmat4 readMatrixFromRawSamplerVAT(sampler2D smp,float index,float frame)\n{float offset=index*4.0;float frameUV=(frame+0.5)*bakedVertexAnimationTextureSizeInverted.y;float dx=bakedVertexAnimationTextureSizeInverted.x;vec4 m0=texture2D(smp,vec2(dx*(offset+0.5),frameUV));vec4 m1=texture2D(smp,vec2(dx*(offset+1.5),frameUV));vec4 m2=texture2D(smp,vec2(dx*(offset+2.5),frameUV));vec4 m3=texture2D(smp,vec2(dx*(offset+3.5),frameUV));return mat4(m0,m1,m2,m3);}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$A] = shader$A;\n\n // Do not edit.\n const name$B = \"instancesDeclaration\";\n const shader$B = `#ifdef INSTANCES\nattribute vec4 world0;attribute vec4 world1;attribute vec4 world2;attribute vec4 world3;\n#ifdef INSTANCESCOLOR\nattribute vec4 instanceColor;\n#endif\n#if defined(THIN_INSTANCES) && !defined(WORLD_UBO)\nuniform mat4 world;\n#endif\n#if defined(VELOCITY) || defined(PREPASS_VELOCITY)\nattribute vec4 previousWorld0;attribute vec4 previousWorld1;attribute vec4 previousWorld2;attribute vec4 previousWorld3;\n#ifdef THIN_INSTANCES\nuniform mat4 previousWorld;\n#endif\n#endif\n#else\n#if !defined(WORLD_UBO)\nuniform mat4 world;\n#endif\n#if defined(VELOCITY) || defined(PREPASS_VELOCITY)\nuniform mat4 previousWorld;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$B] = shader$B;\n\n // Do not edit.\n const name$C = \"prePassVertexDeclaration\";\n const shader$C = `#ifdef PREPASS\n#ifdef PREPASS_DEPTH\nvarying vec3 vViewPos;\n#endif\n#ifdef PREPASS_VELOCITY\nuniform mat4 previousViewProjection;varying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$C] = shader$C;\n\n // Do not edit.\n const name$D = \"samplerVertexDeclaration\";\n const shader$D = `#if defined(_DEFINENAME_) && _DEFINENAME_DIRECTUV==0\nvarying vec2 v_VARYINGNAME_UV;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$D] = shader$D;\n\n // Do not edit.\n const name$E = \"bumpVertexDeclaration\";\n const shader$E = `#if defined(BUMP) || defined(PARALLAX) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$E] = shader$E;\n\n // Do not edit.\n const name$F = \"clipPlaneVertexDeclaration\";\n const shader$F = `#ifdef CLIPPLANE\nuniform vec4 vClipPlane;varying float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nuniform vec4 vClipPlane2;varying float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nuniform vec4 vClipPlane3;varying float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nuniform vec4 vClipPlane4;varying float fClipDistance4;\n#endif\n#ifdef CLIPPLANE5\nuniform vec4 vClipPlane5;varying float fClipDistance5;\n#endif\n#ifdef CLIPPLANE6\nuniform vec4 vClipPlane6;varying float fClipDistance6;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$F] = shader$F;\n\n // Do not edit.\n const name$G = \"fogVertexDeclaration\";\n const shader$G = `#ifdef FOG\nvarying vec3 vFogDistance;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$G] = shader$G;\n\n // Do not edit.\n const name$H = \"lightVxFragmentDeclaration\";\n const shader$H = `#ifdef LIGHT{X}\nuniform vec4 vLightData{X};uniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec4 vLightSpecular{X};\n#else\nvec4 vLightSpecular{X}=vec4(0.);\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#elif defined(SHADOWCUBE{X})\n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};uniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};uniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};uniform vec4 vLightFalloff{X};\n#elif defined(POINTLIGHT{X})\nuniform vec4 vLightFalloff{X};\n#elif defined(HEMILIGHT{X})\nuniform vec3 vLightGround{X};\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$H] = shader$H;\n\n // Do not edit.\n const name$I = \"lightVxUboDeclaration\";\n const shader$I = `#ifdef LIGHT{X}\nuniform Light{X}\n{vec4 vLightData;vec4 vLightDiffuse;vec4 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;vec4 vLightFalloff;\n#elif defined(POINTLIGHT{X})\nvec4 vLightFalloff;\n#elif defined(HEMILIGHT{X})\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;vec2 depthValues;} light{X};\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#elif defined(SHADOWCUBE{X})\n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};uniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$I] = shader$I;\n\n // Do not edit.\n const name$J = \"morphTargetsVertexGlobalDeclaration\";\n const shader$J = `#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#ifdef MORPHTARGETS_TEXTURE \nprecision mediump sampler2DArray; \nuniform float morphTargetTextureIndices[NUM_MORPH_INFLUENCERS];uniform vec3 morphTargetTextureInfo;uniform sampler2DArray morphTargets;vec3 readVector3FromRawSampler(int targetIndex,float vertexIndex)\n{ \nfloat y=floor(vertexIndex/morphTargetTextureInfo.y);float x=vertexIndex-y*morphTargetTextureInfo.y;vec3 textureUV=vec3((x+0.5)/morphTargetTextureInfo.y,(y+0.5)/morphTargetTextureInfo.z,morphTargetTextureIndices[targetIndex]);return texture(morphTargets,textureUV).xyz;}\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$J] = shader$J;\n\n // Do not edit.\n const name$K = \"morphTargetsVertexDeclaration\";\n const shader$K = `#ifdef MORPHTARGETS\n#ifndef MORPHTARGETS_TEXTURE\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#ifdef MORPHTARGETS_UV\nattribute vec2 uv_{X};\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$K] = shader$K;\n\n // Do not edit.\n const name$L = \"morphTargetsVertexGlobal\";\n const shader$L = `#ifdef MORPHTARGETS\n#ifdef MORPHTARGETS_TEXTURE\nfloat vertexID;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$L] = shader$L;\n\n // Do not edit.\n const name$M = \"morphTargetsVertex\";\n const shader$M = `#ifdef MORPHTARGETS\n#ifdef MORPHTARGETS_TEXTURE \nvertexID=float(gl_VertexID)*morphTargetTextureInfo.x;positionUpdated+=(readVector3FromRawSampler({X},vertexID)-position)*morphTargetInfluences[{X}];vertexID+=1.0;\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(readVector3FromRawSampler({X},vertexID) -normal)*morphTargetInfluences[{X}];vertexID+=1.0;\n#endif\n#ifdef MORPHTARGETS_UV\nuvUpdated+=(readVector3FromRawSampler({X},vertexID).xy-uv)*morphTargetInfluences[{X}];vertexID+=1.0;\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(readVector3FromRawSampler({X},vertexID) -tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#else\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_UV\nuvUpdated+=(uv_{X}-uv)*morphTargetInfluences[{X}];\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$M] = shader$M;\n\n // Do not edit.\n const name$N = \"instancesVertex\";\n const shader$N = `#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#if defined(PREPASS_VELOCITY) || defined(VELOCITY)\nmat4 finalPreviousWorld=mat4(previousWorld0,previousWorld1,previousWorld2,previousWorld3);\n#endif\n#ifdef THIN_INSTANCES\nfinalWorld=world*finalWorld;\n#if defined(PREPASS_VELOCITY) || defined(VELOCITY)\nfinalPreviousWorld=previousWorld*finalPreviousWorld;\n#endif\n#endif\n#else\nmat4 finalWorld=world;\n#if defined(PREPASS_VELOCITY) || defined(VELOCITY)\nmat4 finalPreviousWorld=previousWorld;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$N] = shader$N;\n\n // Do not edit.\n const name$O = \"bonesVertex\";\n const shader$O = `#ifndef BAKED_VERTEX_ANIMATION_TEXTURE\n#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\n#ifdef BONETEXTURE\ninfluence=readMatrixFromRawSampler(boneSampler,matricesIndices[0])*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndices[1])*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndices[2])*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndices[3])*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[0])*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[1])*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[2])*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[3])*matricesWeightsExtra[3];\n#endif\n#else\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\n#endif\nfinalWorld=finalWorld*influence;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$O] = shader$O;\n\n // Do not edit.\n const name$P = \"bakedVertexAnimation\";\n const shader$P = `#ifdef BAKED_VERTEX_ANIMATION_TEXTURE\n{\n#ifdef INSTANCES\n#define BVASNAME bakedVertexAnimationSettingsInstanced\n#else\n#define BVASNAME bakedVertexAnimationSettings\n#endif\nfloat VATStartFrame=BVASNAME.x;float VATEndFrame=BVASNAME.y;float VATOffsetFrame=BVASNAME.z;float VATSpeed=BVASNAME.w;float totalFrames=VATEndFrame-VATStartFrame+1.0;float time=bakedVertexAnimationTime*VATSpeed/totalFrames;float frameCorrection=time<1.0 ? 0.0 : 1.0;float numOfFrames=totalFrames-frameCorrection;float VATFrameNum=fract(time)*numOfFrames;VATFrameNum=mod(VATFrameNum+VATOffsetFrame,numOfFrames);VATFrameNum=floor(VATFrameNum);VATFrameNum+=VATStartFrame+frameCorrection;mat4 VATInfluence;VATInfluence=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[0],VATFrameNum)*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[1],VATFrameNum)*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[2],VATFrameNum)*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[3],VATFrameNum)*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[0],VATFrameNum)*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[1],VATFrameNum)*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[2],VATFrameNum)*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[3],VATFrameNum)*matricesWeightsExtra[3];\n#endif\nfinalWorld=finalWorld*VATInfluence;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$P] = shader$P;\n\n // Do not edit.\n const name$Q = \"prePassVertex\";\n const shader$Q = `#ifdef PREPASS_DEPTH\nvViewPos=(view*worldPos).rgb;\n#endif\n#if defined(PREPASS_VELOCITY) && defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*worldPos;\n#if NUM_BONE_INFLUENCERS>0\nmat4 previousInfluence;previousInfluence=mPreviousBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\npreviousInfluence+=mPreviousBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\npreviousInfluence+=mPreviousBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\npreviousInfluence+=mPreviousBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\nvPreviousPosition=previousViewProjection*finalPreviousWorld*previousInfluence*vec4(positionUpdated,1.0);\n#else\nvPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$Q] = shader$Q;\n\n // Do not edit.\n const name$R = \"uvVariableDeclaration\";\n const shader$R = `#if !defined(UV{X}) && defined(MAINUV{X})\nvec2 uv{X}=vec2(0.,0.);\n#endif\n#ifdef MAINUV{X}\nvMainUV{X}=uv{X};\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$R] = shader$R;\n\n // Do not edit.\n const name$S = \"samplerVertexImplementation\";\n const shader$S = `#if defined(_DEFINENAME_) && _DEFINENAME_DIRECTUV==0\nif (v_INFONAME_==0.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uvUpdated,1.0,0.0));}\n#ifdef UV2\nelse if (v_INFONAME_==1.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv2,1.0,0.0));}\n#endif\n#ifdef UV3\nelse if (v_INFONAME_==2.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv3,1.0,0.0));}\n#endif\n#ifdef UV4\nelse if (v_INFONAME_==3.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv4,1.0,0.0));}\n#endif\n#ifdef UV5\nelse if (v_INFONAME_==4.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv5,1.0,0.0));}\n#endif\n#ifdef UV6\nelse if (v_INFONAME_==5.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv6,1.0,0.0));}\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$S] = shader$S;\n\n // Do not edit.\n const name$T = \"bumpVertex\";\n const shader$T = `#if defined(BUMP) || defined(PARALLAX) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);vec3 tbnTangent=normalize(tangentUpdated.xyz);vec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;vTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$T] = shader$T;\n\n // Do not edit.\n const name$U = \"clipPlaneVertex\";\n const shader$U = `#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n#ifdef CLIPPLANE2\nfClipDistance2=dot(worldPos,vClipPlane2);\n#endif\n#ifdef CLIPPLANE3\nfClipDistance3=dot(worldPos,vClipPlane3);\n#endif\n#ifdef CLIPPLANE4\nfClipDistance4=dot(worldPos,vClipPlane4);\n#endif\n#ifdef CLIPPLANE5\nfClipDistance5=dot(worldPos,vClipPlane5);\n#endif\n#ifdef CLIPPLANE6\nfClipDistance6=dot(worldPos,vClipPlane6);\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$U] = shader$U;\n\n // Do not edit.\n const name$V = \"fogVertex\";\n const shader$V = `#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$V] = shader$V;\n\n // Do not edit.\n const name$W = \"shadowsVertex\";\n const shader$W = `#ifdef SHADOWS\n#if defined(SHADOWCSM{X})\nvPositionFromCamera{X}=view*worldPos;for (int i=0; i\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#include[2..7]\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n#include\n#include\n#include\n#include[1..7]\n#include(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap)\n#if defined(SPECULARTERM)\n#include(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular)\n#endif\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal)\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightVxFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif\n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include\n#if defined(PREPASS) && defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#if defined(INSTANCES) && defined(THIN_INSTANCES)\nvNormalW=normalUpdated/vec3(dot(normalWorld[0],normalWorld[0]),dot(normalWorld[1],normalWorld[1]),dot(normalWorld[2],normalWorld[2]));vNormalW=normalize(normalWorld*vNormalW);\n#else\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#endif\n#define CUSTOM_VERTEX_UPDATE_WORLDPOS\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\nvPositionW=vec3(worldPos);\n#include\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n#ifndef UV1\nvec2 uvUpdated=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uvUpdated;\n#endif\n#include[2..7]\n#include(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_MATRIXNAME_,diffuse,_INFONAME_,DiffuseInfos.x)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_MATRIXNAME_,detail,_INFONAME_,DetailInfos.x)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_MATRIXNAME_,ambient,_INFONAME_,AmbientInfos.x)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_MATRIXNAME_,opacity,_INFONAME_,OpacityInfos.x)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_MATRIXNAME_,emissive,_INFONAME_,EmissiveInfos.x)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_MATRIXNAME_,lightmap,_INFONAME_,LightmapInfos.x)\n#if defined(SPECULARTERM)\n#include(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_MATRIXNAME_,specular,_INFONAME_,SpecularInfos.x)\n#endif\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_MATRIXNAME_,bump,_INFONAME_,BumpInfos.x)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_MATRIXNAME_,decal,_INFONAME_,DecalInfos.x)\n#include\n#include\n#include\n#include[0..maxSimultaneousLights]\n#include\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$_] = shader$_;\n\n /**\n * EffectFallbacks can be used to add fallbacks (properties to disable) to certain properties when desired to improve performance.\n * (Eg. Start at high quality with reflection and fog, if fps is low, remove reflection, if still low remove fog)\n */\n class EffectFallbacks {\n constructor() {\n this._defines = {};\n this._currentRank = 32;\n this._maxRank = -1;\n this._mesh = null;\n }\n /**\n * Removes the fallback from the bound mesh.\n */\n unBindMesh() {\n this._mesh = null;\n }\n /**\n * Adds a fallback on the specified property.\n * @param rank The rank of the fallback (Lower ranks will be fallbacked to first)\n * @param define The name of the define in the shader\n */\n addFallback(rank, define) {\n if (!this._defines[rank]) {\n if (rank < this._currentRank) {\n this._currentRank = rank;\n }\n if (rank > this._maxRank) {\n this._maxRank = rank;\n }\n this._defines[rank] = new Array();\n }\n this._defines[rank].push(define);\n }\n /**\n * Sets the mesh to use CPU skinning when needing to fallback.\n * @param rank The rank of the fallback (Lower ranks will be fallbacked to first)\n * @param mesh The mesh to use the fallbacks.\n */\n addCPUSkinningFallback(rank, mesh) {\n this._mesh = mesh;\n if (rank < this._currentRank) {\n this._currentRank = rank;\n }\n if (rank > this._maxRank) {\n this._maxRank = rank;\n }\n }\n /**\n * Checks to see if more fallbacks are still available.\n */\n get hasMoreFallbacks() {\n return this._currentRank <= this._maxRank;\n }\n /**\n * Removes the defines that should be removed when falling back.\n * @param currentDefines defines the current define statements for the shader.\n * @param effect defines the current effect we try to compile\n * @returns The resulting defines with defines of the current rank removed.\n */\n reduce(currentDefines, effect) {\n // First we try to switch to CPU skinning\n if (this._mesh && this._mesh.computeBonesUsingShaders && this._mesh.numBoneInfluencers > 0) {\n this._mesh.computeBonesUsingShaders = false;\n currentDefines = currentDefines.replace(\"#define NUM_BONE_INFLUENCERS \" + this._mesh.numBoneInfluencers, \"#define NUM_BONE_INFLUENCERS 0\");\n effect._bonesComputationForcedToCPU = true;\n const scene = this._mesh.getScene();\n for (let index = 0; index < scene.meshes.length; index++) {\n const otherMesh = scene.meshes[index];\n if (!otherMesh.material) {\n if (!this._mesh.material && otherMesh.computeBonesUsingShaders && otherMesh.numBoneInfluencers > 0) {\n otherMesh.computeBonesUsingShaders = false;\n }\n continue;\n }\n if (!otherMesh.computeBonesUsingShaders || otherMesh.numBoneInfluencers === 0) {\n continue;\n }\n if (otherMesh.material.getEffect() === effect) {\n otherMesh.computeBonesUsingShaders = false;\n }\n else if (otherMesh.subMeshes) {\n for (const subMesh of otherMesh.subMeshes) {\n const subMeshEffect = subMesh.effect;\n if (subMeshEffect === effect) {\n otherMesh.computeBonesUsingShaders = false;\n break;\n }\n }\n }\n }\n }\n else {\n const currentFallbacks = this._defines[this._currentRank];\n if (currentFallbacks) {\n for (let index = 0; index < currentFallbacks.length; index++) {\n currentDefines = currentDefines.replace(\"#define \" + currentFallbacks[index], \"\");\n }\n }\n this._currentRank++;\n }\n return currentDefines;\n }\n }\n\n const rxOption = new RegExp(\"^([gimus]+)!\");\n /**\n * Class that manages the plugins of a material\n * @since 5.0\n */\n class MaterialPluginManager {\n /**\n * Creates a new instance of the plugin manager\n * @param material material that this manager will manage the plugins for\n */\n constructor(material) {\n /** @internal */\n this._plugins = [];\n this._activePlugins = [];\n this._activePluginsForExtraEvents = [];\n this._material = material;\n this._scene = material.getScene();\n this._engine = this._scene.getEngine();\n }\n /**\n * @internal\n */\n _addPlugin(plugin) {\n for (let i = 0; i < this._plugins.length; ++i) {\n if (this._plugins[i].name === plugin.name) {\n return false;\n }\n }\n if (this._material._uniformBufferLayoutBuilt) {\n throw `The plugin \"${plugin.name}\" can't be added to the material \"${this._material.name}\" because this material has already been used for rendering! Please add plugins to materials before any rendering with this material occurs.`;\n }\n const pluginClassName = plugin.getClassName();\n if (!MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]) {\n MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName] = \"MATERIALPLUGIN_\" + ++MaterialPluginManager._MaterialPluginCounter;\n }\n this._material._callbackPluginEventGeneric = this._handlePluginEvent.bind(this);\n this._plugins.push(plugin);\n this._plugins.sort((a, b) => a.priority - b.priority);\n this._codeInjectionPoints = {};\n const defineNamesFromPlugins = {};\n defineNamesFromPlugins[MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]] = {\n type: \"boolean\",\n default: true,\n };\n for (const plugin of this._plugins) {\n plugin.collectDefines(defineNamesFromPlugins);\n this._collectPointNames(\"vertex\", plugin.getCustomCode(\"vertex\"));\n this._collectPointNames(\"fragment\", plugin.getCustomCode(\"fragment\"));\n }\n this._defineNamesFromPlugins = defineNamesFromPlugins;\n return true;\n }\n /**\n * @internal\n */\n _activatePlugin(plugin) {\n if (this._activePlugins.indexOf(plugin) === -1) {\n this._activePlugins.push(plugin);\n this._activePlugins.sort((a, b) => a.priority - b.priority);\n this._material._callbackPluginEventIsReadyForSubMesh = this._handlePluginEventIsReadyForSubMesh.bind(this);\n this._material._callbackPluginEventPrepareDefinesBeforeAttributes = this._handlePluginEventPrepareDefinesBeforeAttributes.bind(this);\n this._material._callbackPluginEventPrepareDefines = this._handlePluginEventPrepareDefines.bind(this);\n this._material._callbackPluginEventBindForSubMesh = this._handlePluginEventBindForSubMesh.bind(this);\n if (plugin.registerForExtraEvents) {\n this._activePluginsForExtraEvents.push(plugin);\n this._activePluginsForExtraEvents.sort((a, b) => a.priority - b.priority);\n this._material._callbackPluginEventHasRenderTargetTextures = this._handlePluginEventHasRenderTargetTextures.bind(this);\n this._material._callbackPluginEventFillRenderTargetTextures = this._handlePluginEventFillRenderTargetTextures.bind(this);\n this._material._callbackPluginEventHardBindForSubMesh = this._handlePluginEventHardBindForSubMesh.bind(this);\n }\n }\n }\n /**\n * Gets a plugin from the list of plugins managed by this manager\n * @param name name of the plugin\n * @returns the plugin if found, else null\n */\n getPlugin(name) {\n for (let i = 0; i < this._plugins.length; ++i) {\n if (this._plugins[i].name === name) {\n return this._plugins[i];\n }\n }\n return null;\n }\n _handlePluginEventIsReadyForSubMesh(eventData) {\n let isReady = true;\n for (const plugin of this._activePlugins) {\n isReady = isReady && plugin.isReadyForSubMesh(eventData.defines, this._scene, this._engine, eventData.subMesh);\n }\n eventData.isReadyForSubMesh = isReady;\n }\n _handlePluginEventPrepareDefinesBeforeAttributes(eventData) {\n for (const plugin of this._activePlugins) {\n plugin.prepareDefinesBeforeAttributes(eventData.defines, this._scene, eventData.mesh);\n }\n }\n _handlePluginEventPrepareDefines(eventData) {\n for (const plugin of this._activePlugins) {\n plugin.prepareDefines(eventData.defines, this._scene, eventData.mesh);\n }\n }\n _handlePluginEventHardBindForSubMesh(eventData) {\n for (const plugin of this._activePluginsForExtraEvents) {\n plugin.hardBindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\n }\n }\n _handlePluginEventBindForSubMesh(eventData) {\n for (const plugin of this._activePlugins) {\n plugin.bindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\n }\n }\n _handlePluginEventHasRenderTargetTextures(eventData) {\n let hasRenderTargetTextures = false;\n for (const plugin of this._activePluginsForExtraEvents) {\n hasRenderTargetTextures = plugin.hasRenderTargetTextures();\n if (hasRenderTargetTextures) {\n break;\n }\n }\n eventData.hasRenderTargetTextures = hasRenderTargetTextures;\n }\n _handlePluginEventFillRenderTargetTextures(eventData) {\n for (const plugin of this._activePluginsForExtraEvents) {\n plugin.fillRenderTargetTextures(eventData.renderTargets);\n }\n }\n _handlePluginEvent(id, info) {\n var _a;\n switch (id) {\n case MaterialPluginEvent.GetActiveTextures: {\n const eventData = info;\n for (const plugin of this._activePlugins) {\n plugin.getActiveTextures(eventData.activeTextures);\n }\n break;\n }\n case MaterialPluginEvent.GetAnimatables: {\n const eventData = info;\n for (const plugin of this._activePlugins) {\n plugin.getAnimatables(eventData.animatables);\n }\n break;\n }\n case MaterialPluginEvent.HasTexture: {\n const eventData = info;\n let hasTexture = false;\n for (const plugin of this._activePlugins) {\n hasTexture = plugin.hasTexture(eventData.texture);\n if (hasTexture) {\n break;\n }\n }\n eventData.hasTexture = hasTexture;\n break;\n }\n case MaterialPluginEvent.Disposed: {\n const eventData = info;\n for (const plugin of this._plugins) {\n plugin.dispose(eventData.forceDisposeTextures);\n }\n break;\n }\n case MaterialPluginEvent.GetDefineNames: {\n const eventData = info;\n eventData.defineNames = this._defineNamesFromPlugins;\n break;\n }\n case MaterialPluginEvent.PrepareEffect: {\n const eventData = info;\n for (const plugin of this._activePlugins) {\n eventData.fallbackRank = plugin.addFallbacks(eventData.defines, eventData.fallbacks, eventData.fallbackRank);\n plugin.getAttributes(eventData.attributes, this._scene, eventData.mesh);\n }\n if (this._uniformList.length > 0) {\n eventData.uniforms.push(...this._uniformList);\n }\n if (this._samplerList.length > 0) {\n eventData.samplers.push(...this._samplerList);\n }\n if (this._uboList.length > 0) {\n eventData.uniformBuffersNames.push(...this._uboList);\n }\n eventData.customCode = this._injectCustomCode(eventData, eventData.customCode);\n break;\n }\n case MaterialPluginEvent.PrepareUniformBuffer: {\n const eventData = info;\n this._uboDeclaration = \"\";\n this._vertexDeclaration = \"\";\n this._fragmentDeclaration = \"\";\n this._uniformList = [];\n this._samplerList = [];\n this._uboList = [];\n for (const plugin of this._plugins) {\n const uniforms = plugin.getUniforms();\n if (uniforms) {\n if (uniforms.ubo) {\n for (const uniform of uniforms.ubo) {\n if (uniform.size && uniform.type) {\n const arraySize = (_a = uniform.arraySize) !== null && _a !== void 0 ? _a : 0;\n eventData.ubo.addUniform(uniform.name, uniform.size, arraySize);\n this._uboDeclaration += `${uniform.type} ${uniform.name}${arraySize > 0 ? `[${arraySize}]` : \"\"};\\n`;\n }\n this._uniformList.push(uniform.name);\n }\n }\n if (uniforms.vertex) {\n this._vertexDeclaration += uniforms.vertex + \"\\n\";\n }\n if (uniforms.fragment) {\n this._fragmentDeclaration += uniforms.fragment + \"\\n\";\n }\n }\n plugin.getSamplers(this._samplerList);\n plugin.getUniformBuffersNames(this._uboList);\n }\n break;\n }\n }\n }\n _collectPointNames(shaderType, customCode) {\n if (!customCode) {\n return;\n }\n for (const pointName in customCode) {\n if (!this._codeInjectionPoints[shaderType]) {\n this._codeInjectionPoints[shaderType] = {};\n }\n this._codeInjectionPoints[shaderType][pointName] = true;\n }\n }\n _injectCustomCode(eventData, existingCallback) {\n return (shaderType, code) => {\n var _a, _b;\n if (existingCallback) {\n code = existingCallback(shaderType, code);\n }\n if (this._uboDeclaration) {\n code = code.replace(\"#define ADDITIONAL_UBO_DECLARATION\", this._uboDeclaration);\n }\n if (this._vertexDeclaration) {\n code = code.replace(\"#define ADDITIONAL_VERTEX_DECLARATION\", this._vertexDeclaration);\n }\n if (this._fragmentDeclaration) {\n code = code.replace(\"#define ADDITIONAL_FRAGMENT_DECLARATION\", this._fragmentDeclaration);\n }\n const points = (_a = this._codeInjectionPoints) === null || _a === void 0 ? void 0 : _a[shaderType];\n if (!points) {\n return code;\n }\n let processorOptions = null;\n for (let pointName in points) {\n let injectedCode = \"\";\n for (const plugin of this._activePlugins) {\n let customCode = (_b = plugin.getCustomCode(shaderType)) === null || _b === void 0 ? void 0 : _b[pointName];\n if (!customCode) {\n continue;\n }\n if (plugin.resolveIncludes) {\n if (processorOptions === null) {\n const shaderLanguage = ShaderLanguage.GLSL;\n processorOptions = {\n defines: [],\n indexParameters: eventData.indexParameters,\n isFragment: false,\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\n processor: undefined,\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\n shadersRepository: ShaderStore.GetShadersRepository(shaderLanguage),\n includesShadersStore: ShaderStore.GetIncludesShadersStore(shaderLanguage),\n version: undefined,\n platformName: this._engine.shaderPlatformName,\n processingContext: undefined,\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\n processCodeAfterIncludes: undefined, // not used by _ProcessIncludes\n };\n }\n processorOptions.isFragment = shaderType === \"fragment\";\n ShaderProcessor._ProcessIncludes(customCode, processorOptions, (code) => (customCode = code));\n }\n injectedCode += customCode + \"\\n\";\n }\n if (injectedCode.length > 0) {\n if (pointName.charAt(0) === \"!\") {\n // pointName is a regular expression\n pointName = pointName.substring(1);\n let regexFlags = \"g\";\n if (pointName.charAt(0) === \"!\") {\n // no flags\n regexFlags = \"\";\n pointName = pointName.substring(1);\n }\n else {\n // get the flag(s)\n const matchOption = rxOption.exec(pointName);\n if (matchOption && matchOption.length >= 2) {\n regexFlags = matchOption[1];\n pointName = pointName.substring(regexFlags.length + 1);\n }\n }\n if (regexFlags.indexOf(\"g\") < 0) {\n // we force the \"g\" flag so that the regexp object is stateful!\n regexFlags += \"g\";\n }\n const sourceCode = code;\n const rx = new RegExp(pointName, regexFlags);\n let match = rx.exec(sourceCode);\n while (match !== null) {\n let newCode = injectedCode;\n for (let i = 0; i < match.length; ++i) {\n newCode = newCode.replace(\"$\" + i, match[i]);\n }\n code = code.replace(match[0], newCode);\n match = rx.exec(sourceCode);\n }\n }\n else {\n const fullPointName = \"#define \" + pointName;\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\n }\n }\n }\n return code;\n };\n }\n }\n /** Map a plugin class name to a #define name (used in the vertex/fragment shaders as a marker of the plugin usage) */\n MaterialPluginManager._MaterialPluginClassToMainDefine = {};\n MaterialPluginManager._MaterialPluginCounter = 0;\n (() => {\n EngineStore.OnEnginesDisposedObservable.add(() => {\n UnregisterAllMaterialPlugins();\n });\n })();\n const plugins = [];\n let observer = null;\n /**\n * Clear the list of global material plugins\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function UnregisterAllMaterialPlugins() {\n plugins.length = 0;\n Material.OnEventObservable.remove(observer);\n observer = null;\n }\n\n /**\n * Base class for material plugins.\n * @since 5.0\n */\n class MaterialPluginBase {\n _enable(enable) {\n if (enable) {\n this._pluginManager._activatePlugin(this);\n }\n }\n /**\n * Creates a new material plugin\n * @param material parent material of the plugin\n * @param name name of the plugin\n * @param priority priority of the plugin\n * @param defines list of defines used by the plugin. The value of the property is the default value for this property\n * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)\n * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)\n * @param resolveIncludes Indicates that any #include directive in the plugin code must be replaced by the corresponding code (default: false)\n */\n constructor(material, name, priority, defines, addToPluginList = true, enable = false, resolveIncludes = false) {\n /**\n * Defines the priority of the plugin. Lower numbers run first.\n */\n this.priority = 500;\n /**\n * Indicates that any #include directive in the plugin code must be replaced by the corresponding code.\n */\n this.resolveIncludes = false;\n /**\n * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)\n */\n this.registerForExtraEvents = false;\n this._material = material;\n this.name = name;\n this.priority = priority;\n this.resolveIncludes = resolveIncludes;\n if (!material.pluginManager) {\n material.pluginManager = new MaterialPluginManager(material);\n material.onDisposeObservable.add(() => {\n material.pluginManager = undefined;\n });\n }\n this._pluginDefineNames = defines;\n this._pluginManager = material.pluginManager;\n if (addToPluginList) {\n this._pluginManager._addPlugin(this);\n }\n if (enable) {\n this._enable(true);\n }\n this.markAllDefinesAsDirty = material._dirtyCallbacks[63];\n }\n /**\n * Gets the current class name useful for serialization or dynamic coding.\n * @returns The class name.\n */\n getClassName() {\n return \"MaterialPluginBase\";\n }\n /**\n * Specifies that the submesh is ready to be used.\n * @param defines the list of \"defines\" to update.\n * @param scene defines the scene the material belongs to.\n * @param engine the engine this scene belongs to.\n * @param subMesh the submesh to check for readiness\n * @returns - boolean indicating that the submesh is ready or not.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isReadyForSubMesh(defines, scene, engine, subMesh) {\n return true;\n }\n /**\n * Binds the material data (this function is called even if mustRebind() returns false)\n * @param uniformBuffer defines the Uniform buffer to fill in.\n * @param scene defines the scene the material belongs to.\n * @param engine defines the engine the material belongs to.\n * @param subMesh the submesh to bind data for\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n hardBindForSubMesh(uniformBuffer, scene, engine, subMesh) { }\n /**\n * Binds the material data.\n * @param uniformBuffer defines the Uniform buffer to fill in.\n * @param scene defines the scene the material belongs to.\n * @param engine the engine this scene belongs to.\n * @param subMesh the submesh to bind data for\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n bindForSubMesh(uniformBuffer, scene, engine, subMesh) { }\n /**\n * Disposes the resources of the material.\n * @param forceDisposeTextures - Forces the disposal of all textures.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dispose(forceDisposeTextures) { }\n /**\n * Returns a list of custom shader code fragments to customize the shader.\n * @param shaderType \"vertex\" or \"fragment\"\n * @returns null if no code to be added, or a list of pointName =\\> code.\n * Note that `pointName` can also be a regular expression if it starts with a `!`.\n * In that case, the string found by the regular expression (if any) will be\n * replaced by the code provided.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getCustomCode(shaderType) {\n return null;\n }\n /**\n * Collects all defines.\n * @param defines The object to append to.\n */\n collectDefines(defines) {\n if (!this._pluginDefineNames) {\n return;\n }\n for (const key of Object.keys(this._pluginDefineNames)) {\n if (key[0] === \"_\") {\n continue;\n }\n const type = typeof this._pluginDefineNames[key];\n defines[key] = {\n type: type === \"number\" ? \"number\" : type === \"string\" ? \"string\" : type === \"boolean\" ? \"boolean\" : \"object\",\n default: this._pluginDefineNames[key],\n };\n }\n }\n /**\n * Sets the defines for the next rendering. Called before MaterialHelper.PrepareDefinesForAttributes is called.\n * @param defines the list of \"defines\" to update.\n * @param scene defines the scene to the material belongs to.\n * @param mesh the mesh being rendered\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n prepareDefinesBeforeAttributes(defines, scene, mesh) { }\n /**\n * Sets the defines for the next rendering\n * @param defines the list of \"defines\" to update.\n * @param scene defines the scene to the material belongs to.\n * @param mesh the mesh being rendered\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n prepareDefines(defines, scene, mesh) { }\n /**\n * Checks to see if a texture is used in the material.\n * @param texture - Base texture to use.\n * @returns - Boolean specifying if a texture is used in the material.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n hasTexture(texture) {\n return false;\n }\n /**\n * Gets a boolean indicating that current material needs to register RTT\n * @returns true if this uses a render target otherwise false.\n */\n hasRenderTargetTextures() {\n return false;\n }\n /**\n * Fills the list of render target textures.\n * @param renderTargets the list of render targets to update\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n fillRenderTargetTextures(renderTargets) { }\n /**\n * Returns an array of the actively used textures.\n * @param activeTextures Array of BaseTextures\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getActiveTextures(activeTextures) { }\n /**\n * Returns the animatable textures.\n * @param animatables Array of animatable textures.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getAnimatables(animatables) { }\n /**\n * Add fallbacks to the effect fallbacks list.\n * @param defines defines the Base texture to use.\n * @param fallbacks defines the current fallback list.\n * @param currentRank defines the current fallback rank.\n * @returns the new fallback rank.\n */\n addFallbacks(defines, fallbacks, currentRank) {\n return currentRank;\n }\n /**\n * Gets the samplers used by the plugin.\n * @param samplers list that the sampler names should be added to.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getSamplers(samplers) { }\n /**\n * Gets the attributes used by the plugin.\n * @param attributes list that the attribute names should be added to.\n * @param scene the scene that the material belongs to.\n * @param mesh the mesh being rendered.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getAttributes(attributes, scene, mesh) { }\n /**\n * Gets the uniform buffers names added by the plugin.\n * @param ubos list that the ubo names should be added to.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getUniformBuffersNames(ubos) { }\n /**\n * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)\n * @returns the description of the uniforms\n */\n getUniforms() {\n return {};\n }\n /**\n * Makes a duplicate of the current configuration into another one.\n * @param plugin define the config where to copy the info\n */\n copyTo(plugin) {\n SerializationHelper.Clone(() => plugin, this);\n }\n /**\n * Serializes this plugin configuration.\n * @returns - An object with the serialized config.\n */\n serialize() {\n return SerializationHelper.Serialize(this);\n }\n /**\n * Parses a plugin configuration from a serialized object.\n * @param source - Serialized object.\n * @param scene Defines the scene we are parsing for\n * @param rootUrl Defines the rootUrl to load from\n */\n parse(source, scene, rootUrl) {\n SerializationHelper.Parse(() => this, source, scene, rootUrl);\n }\n }\n __decorate$1([\n serialize()\n ], MaterialPluginBase.prototype, \"name\", void 0);\n __decorate$1([\n serialize()\n ], MaterialPluginBase.prototype, \"priority\", void 0);\n __decorate$1([\n serialize()\n ], MaterialPluginBase.prototype, \"resolveIncludes\", void 0);\n __decorate$1([\n serialize()\n ], MaterialPluginBase.prototype, \"registerForExtraEvents\", void 0);\n\n /**\n * @internal\n */\n class MaterialDetailMapDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.DETAIL = false;\n this.DETAILDIRECTUV = 0;\n this.DETAIL_NORMALBLENDMETHOD = 0;\n }\n }\n /**\n * Plugin that implements the detail map component of a material\n *\n * Inspired from:\n * Unity: https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@9.0/manual/Mask-Map-and-Detail-Map.html and https://docs.unity3d.com/Manual/StandardShaderMaterialParameterDetail.html\n * Unreal: https://docs.unrealengine.com/en-US/Engine/Rendering/Materials/HowTo/DetailTexturing/index.html\n * Cryengine: https://docs.cryengine.com/display/SDKDOC2/Detail+Maps\n */\n class DetailMapConfiguration extends MaterialPluginBase {\n /** @internal */\n _markAllSubMeshesAsTexturesDirty() {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"DetailMap\", 140, new MaterialDetailMapDefines(), addToPluginList);\n this._texture = null;\n /**\n * Defines how strongly the detail diffuse/albedo channel is blended with the regular diffuse/albedo texture\n * Bigger values mean stronger blending\n */\n this.diffuseBlendLevel = 1;\n /**\n * Defines how strongly the detail roughness channel is blended with the regular roughness value\n * Bigger values mean stronger blending. Only used with PBR materials\n */\n this.roughnessBlendLevel = 1;\n /**\n * Defines how strong the bump effect from the detail map is\n * Bigger values mean stronger effect\n */\n this.bumpLevel = 1;\n this._normalBlendMethod = Material.MATERIAL_NORMALBLENDMETHOD_WHITEOUT;\n this._isEnabled = false;\n /**\n * Enable or disable the detail map on this material\n */\n this.isEnabled = false;\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];\n }\n isReadyForSubMesh(defines, scene, engine) {\n if (!this._isEnabled) {\n return true;\n }\n if (defines._areTexturesDirty && scene.texturesEnabled) {\n if (engine.getCaps().standardDerivatives && this._texture && MaterialFlags.DetailTextureEnabled) {\n // Detail texture cannot be not blocking.\n if (!this._texture.isReady()) {\n return false;\n }\n }\n }\n return true;\n }\n prepareDefines(defines, scene) {\n if (this._isEnabled) {\n defines.DETAIL_NORMALBLENDMETHOD = this._normalBlendMethod;\n const engine = scene.getEngine();\n if (defines._areTexturesDirty) {\n if (engine.getCaps().standardDerivatives && this._texture && MaterialFlags.DetailTextureEnabled && this._isEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"DETAIL\");\n defines.DETAIL_NORMALBLENDMETHOD = this._normalBlendMethod;\n }\n else {\n defines.DETAIL = false;\n }\n }\n }\n else {\n defines.DETAIL = false;\n }\n }\n bindForSubMesh(uniformBuffer, scene) {\n if (!this._isEnabled) {\n return;\n }\n const isFrozen = this._material.isFrozen;\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n if (this._texture && MaterialFlags.DetailTextureEnabled) {\n uniformBuffer.updateFloat4(\"vDetailInfos\", this._texture.coordinatesIndex, this.diffuseBlendLevel, this.bumpLevel, this.roughnessBlendLevel);\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"detail\");\n }\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.DetailTextureEnabled) {\n uniformBuffer.setTexture(\"detailSampler\", this._texture);\n }\n }\n }\n hasTexture(texture) {\n if (this._texture === texture) {\n return true;\n }\n return false;\n }\n getActiveTextures(activeTextures) {\n if (this._texture) {\n activeTextures.push(this._texture);\n }\n }\n getAnimatables(animatables) {\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\n animatables.push(this._texture);\n }\n }\n dispose(forceDisposeTextures) {\n var _a;\n if (forceDisposeTextures) {\n (_a = this._texture) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n }\n getClassName() {\n return \"DetailMapConfiguration\";\n }\n getSamplers(samplers) {\n samplers.push(\"detailSampler\");\n }\n getUniforms() {\n return {\n ubo: [\n { name: \"vDetailInfos\", size: 4, type: \"vec4\" },\n { name: \"detailMatrix\", size: 16, type: \"mat4\" },\n ],\n };\n }\n }\n __decorate$1([\n serializeAsTexture(\"detailTexture\"),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], DetailMapConfiguration.prototype, \"texture\", void 0);\n __decorate$1([\n serialize()\n ], DetailMapConfiguration.prototype, \"diffuseBlendLevel\", void 0);\n __decorate$1([\n serialize()\n ], DetailMapConfiguration.prototype, \"roughnessBlendLevel\", void 0);\n __decorate$1([\n serialize()\n ], DetailMapConfiguration.prototype, \"bumpLevel\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], DetailMapConfiguration.prototype, \"normalBlendMethod\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], DetailMapConfiguration.prototype, \"isEnabled\", void 0);\n\n const onCreatedEffectParameters = { effect: null, subMesh: null };\n /** @internal */\n class StandardMaterialDefines extends MaterialDefines {\n /**\n * Initializes the Standard Material defines.\n * @param externalProperties The external properties\n */\n constructor(externalProperties) {\n super(externalProperties);\n this.MAINUV1 = false;\n this.MAINUV2 = false;\n this.MAINUV3 = false;\n this.MAINUV4 = false;\n this.MAINUV5 = false;\n this.MAINUV6 = false;\n this.DIFFUSE = false;\n this.DIFFUSEDIRECTUV = 0;\n this.BAKED_VERTEX_ANIMATION_TEXTURE = false;\n this.AMBIENT = false;\n this.AMBIENTDIRECTUV = 0;\n this.OPACITY = false;\n this.OPACITYDIRECTUV = 0;\n this.OPACITYRGB = false;\n this.REFLECTION = false;\n this.EMISSIVE = false;\n this.EMISSIVEDIRECTUV = 0;\n this.SPECULAR = false;\n this.SPECULARDIRECTUV = 0;\n this.BUMP = false;\n this.BUMPDIRECTUV = 0;\n this.PARALLAX = false;\n this.PARALLAXOCCLUSION = false;\n this.SPECULAROVERALPHA = false;\n this.CLIPPLANE = false;\n this.CLIPPLANE2 = false;\n this.CLIPPLANE3 = false;\n this.CLIPPLANE4 = false;\n this.CLIPPLANE5 = false;\n this.CLIPPLANE6 = false;\n this.ALPHATEST = false;\n this.DEPTHPREPASS = false;\n this.ALPHAFROMDIFFUSE = false;\n this.POINTSIZE = false;\n this.FOG = false;\n this.SPECULARTERM = false;\n this.DIFFUSEFRESNEL = false;\n this.OPACITYFRESNEL = false;\n this.REFLECTIONFRESNEL = false;\n this.REFRACTIONFRESNEL = false;\n this.EMISSIVEFRESNEL = false;\n this.FRESNEL = false;\n this.NORMAL = false;\n this.TANGENT = false;\n this.UV1 = false;\n this.UV2 = false;\n this.UV3 = false;\n this.UV4 = false;\n this.UV5 = false;\n this.UV6 = false;\n this.VERTEXCOLOR = false;\n this.VERTEXALPHA = false;\n this.NUM_BONE_INFLUENCERS = 0;\n this.BonesPerMesh = 0;\n this.BONETEXTURE = false;\n this.BONES_VELOCITY_ENABLED = false;\n this.INSTANCES = false;\n this.THIN_INSTANCES = false;\n this.INSTANCESCOLOR = false;\n this.GLOSSINESS = false;\n this.ROUGHNESS = false;\n this.EMISSIVEASILLUMINATION = false;\n this.LINKEMISSIVEWITHDIFFUSE = false;\n this.REFLECTIONFRESNELFROMSPECULAR = false;\n this.LIGHTMAP = false;\n this.LIGHTMAPDIRECTUV = 0;\n this.OBJECTSPACE_NORMALMAP = false;\n this.USELIGHTMAPASSHADOWMAP = false;\n this.REFLECTIONMAP_3D = false;\n this.REFLECTIONMAP_SPHERICAL = false;\n this.REFLECTIONMAP_PLANAR = false;\n this.REFLECTIONMAP_CUBIC = false;\n this.USE_LOCAL_REFLECTIONMAP_CUBIC = false;\n this.USE_LOCAL_REFRACTIONMAP_CUBIC = false;\n this.REFLECTIONMAP_PROJECTION = false;\n this.REFLECTIONMAP_SKYBOX = false;\n this.REFLECTIONMAP_EXPLICIT = false;\n this.REFLECTIONMAP_EQUIRECTANGULAR = false;\n this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\n this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\n this.REFLECTIONMAP_OPPOSITEZ = false;\n this.INVERTCUBICMAP = false;\n this.LOGARITHMICDEPTH = false;\n this.REFRACTION = false;\n this.REFRACTIONMAP_3D = false;\n this.REFLECTIONOVERALPHA = false;\n this.TWOSIDEDLIGHTING = false;\n this.SHADOWFLOAT = false;\n this.MORPHTARGETS = false;\n this.MORPHTARGETS_NORMAL = false;\n this.MORPHTARGETS_TANGENT = false;\n this.MORPHTARGETS_UV = false;\n this.NUM_MORPH_INFLUENCERS = 0;\n this.MORPHTARGETS_TEXTURE = false;\n this.NONUNIFORMSCALING = false; // https://playground.babylonjs.com#V6DWIH\n this.PREMULTIPLYALPHA = false; // https://playground.babylonjs.com#LNVJJ7\n this.ALPHATEST_AFTERALLALPHACOMPUTATIONS = false;\n this.ALPHABLEND = true;\n this.PREPASS = false;\n this.PREPASS_IRRADIANCE = false;\n this.PREPASS_IRRADIANCE_INDEX = -1;\n this.PREPASS_ALBEDO_SQRT = false;\n this.PREPASS_ALBEDO_SQRT_INDEX = -1;\n this.PREPASS_DEPTH = false;\n this.PREPASS_DEPTH_INDEX = -1;\n this.PREPASS_NORMAL = false;\n this.PREPASS_NORMAL_INDEX = -1;\n this.PREPASS_POSITION = false;\n this.PREPASS_POSITION_INDEX = -1;\n this.PREPASS_VELOCITY = false;\n this.PREPASS_VELOCITY_INDEX = -1;\n this.PREPASS_REFLECTIVITY = false;\n this.PREPASS_REFLECTIVITY_INDEX = -1;\n this.SCENE_MRT_COUNT = 0;\n this.RGBDLIGHTMAP = false;\n this.RGBDREFLECTION = false;\n this.RGBDREFRACTION = false;\n this.IMAGEPROCESSING = false;\n this.VIGNETTE = false;\n this.VIGNETTEBLENDMODEMULTIPLY = false;\n this.VIGNETTEBLENDMODEOPAQUE = false;\n this.TONEMAPPING = false;\n this.TONEMAPPING_ACES = false;\n this.CONTRAST = false;\n this.COLORCURVES = false;\n this.COLORGRADING = false;\n this.COLORGRADING3D = false;\n this.SAMPLER3DGREENDEPTH = false;\n this.SAMPLER3DBGRMAP = false;\n this.DITHER = false;\n this.IMAGEPROCESSINGPOSTPROCESS = false;\n this.SKIPFINALCOLORCLAMP = false;\n this.MULTIVIEW = false;\n this.ORDER_INDEPENDENT_TRANSPARENCY = false;\n this.ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;\n this.CAMERA_ORTHOGRAPHIC = false;\n this.CAMERA_PERSPECTIVE = false;\n /**\n * If the reflection texture on this material is in linear color space\n * @internal\n */\n this.IS_REFLECTION_LINEAR = false;\n /**\n * If the refraction texture on this material is in linear color space\n * @internal\n */\n this.IS_REFRACTION_LINEAR = false;\n this.EXPOSURE = false;\n this.DECAL_AFTER_DETAIL = false;\n this.rebuild();\n }\n setReflectionMode(modeToEnable) {\n const modes = [\n \"REFLECTIONMAP_CUBIC\",\n \"REFLECTIONMAP_EXPLICIT\",\n \"REFLECTIONMAP_PLANAR\",\n \"REFLECTIONMAP_PROJECTION\",\n \"REFLECTIONMAP_PROJECTION\",\n \"REFLECTIONMAP_SKYBOX\",\n \"REFLECTIONMAP_SPHERICAL\",\n \"REFLECTIONMAP_EQUIRECTANGULAR\",\n \"REFLECTIONMAP_EQUIRECTANGULAR_FIXED\",\n \"REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\",\n ];\n for (const mode of modes) {\n this[mode] = mode === modeToEnable;\n }\n }\n }\n /**\n * This is the default material used in Babylon. It is the best trade off between quality\n * and performances.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction\n */\n class StandardMaterial extends PushMaterial {\n /**\n * Gets the image processing configuration used either in this material.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Sets the Default image processing configuration used either in the this material.\n *\n * If sets to null, the scene one is in use.\n */\n set imageProcessingConfiguration(value) {\n this._attachImageProcessingConfiguration(value);\n // Ensure the effect will be rebuilt.\n this._markAllSubMeshesAsTexturesDirty();\n }\n /**\n * Attaches a new image processing configuration to the Standard Material.\n * @param configuration\n */\n _attachImageProcessingConfiguration(configuration) {\n if (configuration === this._imageProcessingConfiguration) {\n return;\n }\n // Detaches observer\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n // Pick the scene configuration if needed\n if (!configuration) {\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\n }\n else {\n this._imageProcessingConfiguration = configuration;\n }\n // Attaches observer\n if (this._imageProcessingConfiguration) {\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\n this._markAllSubMeshesAsImageProcessingDirty();\n });\n }\n }\n /**\n * Can this material render to prepass\n */\n get isPrePassCapable() {\n return !this.disableDepthWrite;\n }\n /**\n * Gets whether the color curves effect is enabled.\n */\n get cameraColorCurvesEnabled() {\n return this.imageProcessingConfiguration.colorCurvesEnabled;\n }\n /**\n * Sets whether the color curves effect is enabled.\n */\n set cameraColorCurvesEnabled(value) {\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n get cameraColorGradingEnabled() {\n return this.imageProcessingConfiguration.colorGradingEnabled;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n set cameraColorGradingEnabled(value) {\n this.imageProcessingConfiguration.colorGradingEnabled = value;\n }\n /**\n * Gets whether tonemapping is enabled or not.\n */\n get cameraToneMappingEnabled() {\n return this._imageProcessingConfiguration.toneMappingEnabled;\n }\n /**\n * Sets whether tonemapping is enabled or not\n */\n set cameraToneMappingEnabled(value) {\n this._imageProcessingConfiguration.toneMappingEnabled = value;\n }\n /**\n * The camera exposure used on this material.\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\n * This corresponds to a photographic exposure.\n */\n get cameraExposure() {\n return this._imageProcessingConfiguration.exposure;\n }\n /**\n * The camera exposure used on this material.\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\n * This corresponds to a photographic exposure.\n */\n set cameraExposure(value) {\n this._imageProcessingConfiguration.exposure = value;\n }\n /**\n * Gets The camera contrast used on this material.\n */\n get cameraContrast() {\n return this._imageProcessingConfiguration.contrast;\n }\n /**\n * Sets The camera contrast used on this material.\n */\n set cameraContrast(value) {\n this._imageProcessingConfiguration.contrast = value;\n }\n /**\n * Gets the Color Grading 2D Lookup Texture.\n */\n get cameraColorGradingTexture() {\n return this._imageProcessingConfiguration.colorGradingTexture;\n }\n /**\n * Sets the Color Grading 2D Lookup Texture.\n */\n set cameraColorGradingTexture(value) {\n this._imageProcessingConfiguration.colorGradingTexture = value;\n }\n /**\n * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n get cameraColorCurves() {\n return this._imageProcessingConfiguration.colorCurves;\n }\n /**\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n set cameraColorCurves(value) {\n this._imageProcessingConfiguration.colorCurves = value;\n }\n /**\n * Can this material render to several textures at once\n */\n get canRenderToMRT() {\n return true;\n }\n /**\n * Instantiates a new standard material.\n * This is the default material used in Babylon. It is the best trade off between quality\n * and performances.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction\n * @param name Define the name of the material in the scene\n * @param scene Define the scene the material belong to\n */\n constructor(name, scene) {\n super(name, scene);\n this._diffuseTexture = null;\n this._ambientTexture = null;\n this._opacityTexture = null;\n this._reflectionTexture = null;\n this._emissiveTexture = null;\n this._specularTexture = null;\n this._bumpTexture = null;\n this._lightmapTexture = null;\n this._refractionTexture = null;\n /**\n * The color of the material lit by the environmental background lighting.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#ambient-color-example\n */\n this.ambientColor = new Color3(0, 0, 0);\n /**\n * The basic color of the material as viewed under a light.\n */\n this.diffuseColor = new Color3(1, 1, 1);\n /**\n * Define how the color and intensity of the highlight given by the light in the material.\n */\n this.specularColor = new Color3(1, 1, 1);\n /**\n * Define the color of the material as if self lit.\n * This will be mixed in the final result even in the absence of light.\n */\n this.emissiveColor = new Color3(0, 0, 0);\n /**\n * Defines how sharp are the highlights in the material.\n * The bigger the value the sharper giving a more glossy feeling to the result.\n * Reversely, the smaller the value the blurrier giving a more rough feeling to the result.\n */\n this.specularPower = 64;\n this._useAlphaFromDiffuseTexture = false;\n this._useEmissiveAsIllumination = false;\n this._linkEmissiveWithDiffuse = false;\n this._useSpecularOverAlpha = false;\n this._useReflectionOverAlpha = false;\n this._disableLighting = false;\n this._useObjectSpaceNormalMap = false;\n this._useParallax = false;\n this._useParallaxOcclusion = false;\n /**\n * Apply a scaling factor that determine which \"depth\" the height map should reprensent. A value between 0.05 and 0.1 is reasonnable in Parallax, you can reach 0.2 using Parallax Occlusion.\n */\n this.parallaxScaleBias = 0.05;\n this._roughness = 0;\n /**\n * In case of refraction, define the value of the index of refraction.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#how-to-obtain-reflections-and-refractions\n */\n this.indexOfRefraction = 0.98;\n /**\n * Invert the refraction texture alongside the y axis.\n * It can be useful with procedural textures or probe for instance.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#how-to-obtain-reflections-and-refractions\n */\n this.invertRefractionY = true;\n /**\n * Defines the alpha limits in alpha test mode.\n */\n this.alphaCutOff = 0.4;\n this._useLightmapAsShadowmap = false;\n this._useReflectionFresnelFromSpecular = false;\n this._useGlossinessFromSpecularMapAlpha = false;\n this._maxSimultaneousLights = 4;\n this._invertNormalMapX = false;\n this._invertNormalMapY = false;\n this._twoSidedLighting = false;\n this._applyDecalMapAfterDetailMap = false;\n this._renderTargets = new SmartArray(16);\n this._worldViewProjectionMatrix = Matrix.Zero();\n this._globalAmbientColor = new Color3(0, 0, 0);\n this._cacheHasRenderTargetTextures = false;\n this.detailMap = new DetailMapConfiguration(this);\n // Setup the default processing configuration to the scene.\n this._attachImageProcessingConfiguration(null);\n this.prePassConfiguration = new PrePassConfiguration();\n this.getRenderTargetTextures = () => {\n this._renderTargets.reset();\n if (StandardMaterial.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n this._renderTargets.push(this._reflectionTexture);\n }\n if (StandardMaterial.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\n this._renderTargets.push(this._refractionTexture);\n }\n this._eventInfo.renderTargets = this._renderTargets;\n this._callbackPluginEventFillRenderTargetTextures(this._eventInfo);\n return this._renderTargets;\n };\n }\n /**\n * Gets a boolean indicating that current material needs to register RTT\n */\n get hasRenderTargetTextures() {\n if (StandardMaterial.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n return true;\n }\n if (StandardMaterial.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\n return true;\n }\n return this._cacheHasRenderTargetTextures;\n }\n /**\n * Gets the current class name of the material e.g. \"StandardMaterial\"\n * Mainly use in serialization.\n * @returns the class name\n */\n getClassName() {\n return \"StandardMaterial\";\n }\n /**\n * In case the depth buffer does not allow enough depth precision for your scene (might be the case in large scenes)\n * You can try switching to logarithmic depth.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/logarithmicDepthBuffer\n */\n get useLogarithmicDepth() {\n return this._useLogarithmicDepth;\n }\n set useLogarithmicDepth(value) {\n this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;\n this._markAllSubMeshesAsMiscDirty();\n }\n /**\n * Specifies if the material will require alpha blending\n * @returns a boolean specifying if alpha blending is needed\n */\n needAlphaBlending() {\n if (this._disableAlphaBlending) {\n return false;\n }\n return (this.alpha < 1.0 ||\n this._opacityTexture != null ||\n this._shouldUseAlphaFromDiffuseTexture() ||\n (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled));\n }\n /**\n * Specifies if this material should be rendered in alpha test mode\n * @returns a boolean specifying if an alpha test is needed.\n */\n needAlphaTesting() {\n if (this._forceAlphaTest) {\n return true;\n }\n return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST);\n }\n /**\n * Specifies whether or not the alpha value of the diffuse texture should be used for alpha blending.\n */\n _shouldUseAlphaFromDiffuseTexture() {\n return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture && this._transparencyMode !== Material.MATERIAL_OPAQUE;\n }\n /**\n * Specifies whether or not there is a usable alpha channel for transparency.\n */\n _hasAlphaChannel() {\n return (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._opacityTexture != null;\n }\n /**\n * Get the texture used for alpha test purpose.\n * @returns the diffuse texture in case of the standard material.\n */\n getAlphaTestTexture() {\n return this._diffuseTexture;\n }\n /**\n * Get if the submesh is ready to be used and all its information available.\n * Child classes can use it to update shaders\n * @param mesh defines the mesh to check\n * @param subMesh defines which submesh to check\n * @param useInstances specifies that instances should be used\n * @returns a boolean indicating that the submesh is ready or not\n */\n isReadyForSubMesh(mesh, subMesh, useInstances = false) {\n if (!this._uniformBufferLayoutBuilt) {\n this.buildUniformLayout();\n }\n if (subMesh.effect && this.isFrozen) {\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\n return true;\n }\n }\n if (!subMesh.materialDefines) {\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetDefineNames, this._eventInfo);\n subMesh.materialDefines = new StandardMaterialDefines(this._eventInfo.defineNames);\n }\n const scene = this.getScene();\n const defines = subMesh.materialDefines;\n if (this._isReadyForSubMesh(subMesh)) {\n return true;\n }\n const engine = scene.getEngine();\n // Lights\n defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);\n // Multiview\n MaterialHelper.PrepareDefinesForMultiview(scene, defines);\n // PrePass\n const oit = this.needAlphaBlendingForMesh(mesh) && this.getScene().useOrderIndependentTransparency;\n MaterialHelper.PrepareDefinesForPrePass(scene, defines, this.canRenderToMRT && !oit);\n // Order independant transparency\n MaterialHelper.PrepareDefinesForOIT(scene, defines, oit);\n // Textures\n if (defines._areTexturesDirty) {\n this._eventInfo.hasRenderTargetTextures = false;\n this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);\n this._cacheHasRenderTargetTextures = this._eventInfo.hasRenderTargetTextures;\n defines._needUVs = false;\n for (let i = 1; i <= 6; ++i) {\n defines[\"MAINUV\" + i] = false;\n }\n if (scene.texturesEnabled) {\n defines.DIFFUSEDIRECTUV = 0;\n defines.BUMPDIRECTUV = 0;\n defines.AMBIENTDIRECTUV = 0;\n defines.OPACITYDIRECTUV = 0;\n defines.EMISSIVEDIRECTUV = 0;\n defines.SPECULARDIRECTUV = 0;\n defines.LIGHTMAPDIRECTUV = 0;\n if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {\n if (!this._diffuseTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture, defines, \"DIFFUSE\");\n }\n }\n else {\n defines.DIFFUSE = false;\n }\n if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {\n if (!this._ambientTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture, defines, \"AMBIENT\");\n }\n }\n else {\n defines.AMBIENT = false;\n }\n if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {\n if (!this._opacityTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture, defines, \"OPACITY\");\n defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;\n }\n }\n else {\n defines.OPACITY = false;\n }\n if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {\n if (!this._reflectionTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n defines._needNormals = true;\n defines.REFLECTION = true;\n defines.ROUGHNESS = this._roughness > 0;\n defines.REFLECTIONOVERALPHA = this._useReflectionOverAlpha;\n defines.INVERTCUBICMAP = this._reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE;\n defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;\n defines.REFLECTIONMAP_OPPOSITEZ =\n defines.REFLECTIONMAP_3D && this.getScene().useRightHandedSystem ? !this._reflectionTexture.invertZ : this._reflectionTexture.invertZ;\n defines.RGBDREFLECTION = this._reflectionTexture.isRGBD;\n switch (this._reflectionTexture.coordinatesMode) {\n case Texture.EXPLICIT_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_EXPLICIT\");\n break;\n case Texture.PLANAR_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_PLANAR\");\n break;\n case Texture.PROJECTION_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_PROJECTION\");\n break;\n case Texture.SKYBOX_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_SKYBOX\");\n break;\n case Texture.SPHERICAL_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_SPHERICAL\");\n break;\n case Texture.EQUIRECTANGULAR_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_EQUIRECTANGULAR\");\n break;\n case Texture.FIXED_EQUIRECTANGULAR_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_EQUIRECTANGULAR_FIXED\");\n break;\n case Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:\n defines.setReflectionMode(\"REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\");\n break;\n case Texture.CUBIC_MODE:\n case Texture.INVCUBIC_MODE:\n default:\n defines.setReflectionMode(\"REFLECTIONMAP_CUBIC\");\n break;\n }\n defines.USE_LOCAL_REFLECTIONMAP_CUBIC = this._reflectionTexture.boundingBoxSize ? true : false;\n }\n }\n else {\n defines.REFLECTION = false;\n defines.REFLECTIONMAP_OPPOSITEZ = false;\n }\n if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {\n if (!this._emissiveTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture, defines, \"EMISSIVE\");\n }\n }\n else {\n defines.EMISSIVE = false;\n }\n if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {\n if (!this._lightmapTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture, defines, \"LIGHTMAP\");\n defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;\n defines.RGBDLIGHTMAP = this._lightmapTexture.isRGBD;\n }\n }\n else {\n defines.LIGHTMAP = false;\n }\n if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {\n if (!this._specularTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._specularTexture, defines, \"SPECULAR\");\n defines.GLOSSINESS = this._useGlossinessFromSpecularMapAlpha;\n }\n }\n else {\n defines.SPECULAR = false;\n }\n if (scene.getEngine().getCaps().standardDerivatives && this._bumpTexture && StandardMaterial.BumpTextureEnabled) {\n // Bump texture can not be not blocking.\n if (!this._bumpTexture.isReady()) {\n return false;\n }\n else {\n MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, \"BUMP\");\n defines.PARALLAX = this._useParallax;\n defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;\n }\n defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;\n }\n else {\n defines.BUMP = false;\n defines.PARALLAX = false;\n defines.PARALLAXOCCLUSION = false;\n }\n if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {\n if (!this._refractionTexture.isReadyOrNotBlocking()) {\n return false;\n }\n else {\n defines._needUVs = true;\n defines.REFRACTION = true;\n defines.REFRACTIONMAP_3D = this._refractionTexture.isCube;\n defines.RGBDREFRACTION = this._refractionTexture.isRGBD;\n defines.USE_LOCAL_REFRACTIONMAP_CUBIC = this._refractionTexture.boundingBoxSize ? true : false;\n }\n }\n else {\n defines.REFRACTION = false;\n }\n defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;\n }\n else {\n defines.DIFFUSE = false;\n defines.AMBIENT = false;\n defines.OPACITY = false;\n defines.REFLECTION = false;\n defines.EMISSIVE = false;\n defines.LIGHTMAP = false;\n defines.BUMP = false;\n defines.REFRACTION = false;\n }\n defines.ALPHAFROMDIFFUSE = this._shouldUseAlphaFromDiffuseTexture();\n defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;\n defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;\n defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;\n defines.PREMULTIPLYALPHA = this.alphaMode === 7 || this.alphaMode === 8;\n defines.ALPHATEST_AFTERALLALPHACOMPUTATIONS = this.transparencyMode !== null;\n defines.ALPHABLEND = this.transparencyMode === null || this.needAlphaBlendingForMesh(mesh); // check on null for backward compatibility\n }\n this._eventInfo.isReadyForSubMesh = true;\n this._eventInfo.defines = defines;\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);\n if (!this._eventInfo.isReadyForSubMesh) {\n return false;\n }\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\n if (!this._imageProcessingConfiguration.isReady()) {\n return false;\n }\n this._imageProcessingConfiguration.prepareDefines(defines);\n defines.IS_REFLECTION_LINEAR = this.reflectionTexture != null && !this.reflectionTexture.gammaSpace;\n defines.IS_REFRACTION_LINEAR = this.refractionTexture != null && !this.refractionTexture.gammaSpace;\n }\n if (defines._areFresnelDirty) {\n if (StandardMaterial.FresnelEnabled) {\n // Fresnel\n if (this._diffuseFresnelParameters ||\n this._opacityFresnelParameters ||\n this._emissiveFresnelParameters ||\n this._refractionFresnelParameters ||\n this._reflectionFresnelParameters) {\n defines.DIFFUSEFRESNEL = this._diffuseFresnelParameters && this._diffuseFresnelParameters.isEnabled;\n defines.OPACITYFRESNEL = this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;\n defines.REFLECTIONFRESNEL = this._reflectionFresnelParameters && this._reflectionFresnelParameters.isEnabled;\n defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;\n defines.REFRACTIONFRESNEL = this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled;\n defines.EMISSIVEFRESNEL = this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled;\n defines._needNormals = true;\n defines.FRESNEL = true;\n }\n }\n else {\n defines.FRESNEL = false;\n }\n }\n // Misc.\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, defines, this._applyDecalMapAfterDetailMap);\n // Values that need to be evaluated on every frame\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);\n // External config\n this._eventInfo.defines = defines;\n this._eventInfo.mesh = mesh;\n this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);\n // Attribs\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);\n // External config\n this._callbackPluginEventPrepareDefines(this._eventInfo);\n // Get correct effect\n let forceWasNotReadyPreviously = false;\n if (defines.isDirty) {\n const lightDisposed = defines._areLightsDisposed;\n defines.markAsProcessed();\n // Fallbacks\n const fallbacks = new EffectFallbacks();\n if (defines.REFLECTION) {\n fallbacks.addFallback(0, \"REFLECTION\");\n }\n if (defines.SPECULAR) {\n fallbacks.addFallback(0, \"SPECULAR\");\n }\n if (defines.BUMP) {\n fallbacks.addFallback(0, \"BUMP\");\n }\n if (defines.PARALLAX) {\n fallbacks.addFallback(1, \"PARALLAX\");\n }\n if (defines.PARALLAXOCCLUSION) {\n fallbacks.addFallback(0, \"PARALLAXOCCLUSION\");\n }\n if (defines.SPECULAROVERALPHA) {\n fallbacks.addFallback(0, \"SPECULAROVERALPHA\");\n }\n if (defines.FOG) {\n fallbacks.addFallback(1, \"FOG\");\n }\n if (defines.POINTSIZE) {\n fallbacks.addFallback(0, \"POINTSIZE\");\n }\n if (defines.LOGARITHMICDEPTH) {\n fallbacks.addFallback(0, \"LOGARITHMICDEPTH\");\n }\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);\n if (defines.SPECULARTERM) {\n fallbacks.addFallback(0, \"SPECULARTERM\");\n }\n if (defines.DIFFUSEFRESNEL) {\n fallbacks.addFallback(1, \"DIFFUSEFRESNEL\");\n }\n if (defines.OPACITYFRESNEL) {\n fallbacks.addFallback(2, \"OPACITYFRESNEL\");\n }\n if (defines.REFLECTIONFRESNEL) {\n fallbacks.addFallback(3, \"REFLECTIONFRESNEL\");\n }\n if (defines.EMISSIVEFRESNEL) {\n fallbacks.addFallback(4, \"EMISSIVEFRESNEL\");\n }\n if (defines.FRESNEL) {\n fallbacks.addFallback(4, \"FRESNEL\");\n }\n if (defines.MULTIVIEW) {\n fallbacks.addFallback(0, \"MULTIVIEW\");\n }\n //Attributes\n const attribs = [VertexBuffer.PositionKind];\n if (defines.NORMAL) {\n attribs.push(VertexBuffer.NormalKind);\n }\n if (defines.TANGENT) {\n attribs.push(VertexBuffer.TangentKind);\n }\n for (let i = 1; i <= 6; ++i) {\n if (defines[\"UV\" + i]) {\n attribs.push(`uv${i === 1 ? \"\" : i}`);\n }\n }\n if (defines.VERTEXCOLOR) {\n attribs.push(VertexBuffer.ColorKind);\n }\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\n MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);\n MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\n let shaderName = \"default\";\n const uniforms = [\n \"world\",\n \"view\",\n \"viewProjection\",\n \"vEyePosition\",\n \"vLightsType\",\n \"vAmbientColor\",\n \"vDiffuseColor\",\n \"vSpecularColor\",\n \"vEmissiveColor\",\n \"visibility\",\n \"vFogInfos\",\n \"vFogColor\",\n \"pointSize\",\n \"vDiffuseInfos\",\n \"vAmbientInfos\",\n \"vOpacityInfos\",\n \"vReflectionInfos\",\n \"vEmissiveInfos\",\n \"vSpecularInfos\",\n \"vBumpInfos\",\n \"vLightmapInfos\",\n \"vRefractionInfos\",\n \"mBones\",\n \"diffuseMatrix\",\n \"ambientMatrix\",\n \"opacityMatrix\",\n \"reflectionMatrix\",\n \"emissiveMatrix\",\n \"specularMatrix\",\n \"bumpMatrix\",\n \"normalMatrix\",\n \"lightmapMatrix\",\n \"refractionMatrix\",\n \"diffuseLeftColor\",\n \"diffuseRightColor\",\n \"opacityParts\",\n \"reflectionLeftColor\",\n \"reflectionRightColor\",\n \"emissiveLeftColor\",\n \"emissiveRightColor\",\n \"refractionLeftColor\",\n \"refractionRightColor\",\n \"vReflectionPosition\",\n \"vReflectionSize\",\n \"vRefractionPosition\",\n \"vRefractionSize\",\n \"logarithmicDepthConstant\",\n \"vTangentSpaceParams\",\n \"alphaCutOff\",\n \"boneTextureWidth\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n ];\n const samplers = [\n \"diffuseSampler\",\n \"ambientSampler\",\n \"opacitySampler\",\n \"reflectionCubeSampler\",\n \"reflection2DSampler\",\n \"emissiveSampler\",\n \"specularSampler\",\n \"bumpSampler\",\n \"lightmapSampler\",\n \"refractionCubeSampler\",\n \"refraction2DSampler\",\n \"boneSampler\",\n \"morphTargets\",\n \"oitDepthSampler\",\n \"oitFrontColorSampler\",\n ];\n const uniformBuffers = [\"Material\", \"Scene\", \"Mesh\"];\n const indexParameters = { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS };\n this._eventInfo.fallbacks = fallbacks;\n this._eventInfo.fallbackRank = 0;\n this._eventInfo.defines = defines;\n this._eventInfo.uniforms = uniforms;\n this._eventInfo.attributes = attribs;\n this._eventInfo.samplers = samplers;\n this._eventInfo.uniformBuffersNames = uniformBuffers;\n this._eventInfo.customCode = undefined;\n this._eventInfo.mesh = mesh;\n this._eventInfo.indexParameters = indexParameters;\n this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareEffect, this._eventInfo);\n PrePassConfiguration.AddUniforms(uniforms);\n PrePassConfiguration.AddSamplers(samplers);\n if (ImageProcessingConfiguration) {\n ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);\n ImageProcessingConfiguration.PrepareSamplers(samplers, defines);\n }\n MaterialHelper.PrepareUniformsAndSamplersList({\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: defines,\n maxSimultaneousLights: this._maxSimultaneousLights,\n });\n addClipPlaneUniforms(uniforms);\n const csnrOptions = {};\n if (this.customShaderNameResolve) {\n shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs, csnrOptions);\n }\n const join = defines.toString();\n const previousEffect = subMesh.effect;\n let effect = scene.getEngine().createEffect(shaderName, {\n attributes: attribs,\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: join,\n fallbacks: fallbacks,\n onCompiled: this.onCompiled,\n onError: this.onError,\n indexParameters,\n processFinalCode: csnrOptions.processFinalCode,\n processCodeAfterIncludes: this._eventInfo.customCode,\n multiTarget: defines.PREPASS,\n }, engine);\n this._eventInfo.customCode = undefined;\n if (effect) {\n if (this._onEffectCreatedObservable) {\n onCreatedEffectParameters.effect = effect;\n onCreatedEffectParameters.subMesh = subMesh;\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);\n }\n // Use previous effect while new one is compiling\n if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {\n effect = previousEffect;\n defines.markAsUnprocessed();\n forceWasNotReadyPreviously = this.isFrozen;\n if (lightDisposed) {\n // re register in case it takes more than one frame.\n defines._areLightsDisposed = true;\n return false;\n }\n }\n else {\n scene.resetCachedMaterial();\n subMesh.setEffect(effect, defines, this._materialContext);\n }\n }\n }\n if (!subMesh.effect || !subMesh.effect.isReady()) {\n return false;\n }\n defines._renderId = scene.getRenderId();\n subMesh.effect._wasPreviouslyReady = forceWasNotReadyPreviously ? false : true;\n subMesh.effect._wasPreviouslyUsingInstances = useInstances;\n this._checkScenePerformancePriority();\n return true;\n }\n /**\n * Builds the material UBO layouts.\n * Used internally during the effect preparation.\n */\n buildUniformLayout() {\n // Order is important !\n const ubo = this._uniformBuffer;\n ubo.addUniform(\"diffuseLeftColor\", 4);\n ubo.addUniform(\"diffuseRightColor\", 4);\n ubo.addUniform(\"opacityParts\", 4);\n ubo.addUniform(\"reflectionLeftColor\", 4);\n ubo.addUniform(\"reflectionRightColor\", 4);\n ubo.addUniform(\"refractionLeftColor\", 4);\n ubo.addUniform(\"refractionRightColor\", 4);\n ubo.addUniform(\"emissiveLeftColor\", 4);\n ubo.addUniform(\"emissiveRightColor\", 4);\n ubo.addUniform(\"vDiffuseInfos\", 2);\n ubo.addUniform(\"vAmbientInfos\", 2);\n ubo.addUniform(\"vOpacityInfos\", 2);\n ubo.addUniform(\"vReflectionInfos\", 2);\n ubo.addUniform(\"vReflectionPosition\", 3);\n ubo.addUniform(\"vReflectionSize\", 3);\n ubo.addUniform(\"vEmissiveInfos\", 2);\n ubo.addUniform(\"vLightmapInfos\", 2);\n ubo.addUniform(\"vSpecularInfos\", 2);\n ubo.addUniform(\"vBumpInfos\", 3);\n ubo.addUniform(\"diffuseMatrix\", 16);\n ubo.addUniform(\"ambientMatrix\", 16);\n ubo.addUniform(\"opacityMatrix\", 16);\n ubo.addUniform(\"reflectionMatrix\", 16);\n ubo.addUniform(\"emissiveMatrix\", 16);\n ubo.addUniform(\"lightmapMatrix\", 16);\n ubo.addUniform(\"specularMatrix\", 16);\n ubo.addUniform(\"bumpMatrix\", 16);\n ubo.addUniform(\"vTangentSpaceParams\", 2);\n ubo.addUniform(\"pointSize\", 1);\n ubo.addUniform(\"alphaCutOff\", 1);\n ubo.addUniform(\"refractionMatrix\", 16);\n ubo.addUniform(\"vRefractionInfos\", 4);\n ubo.addUniform(\"vRefractionPosition\", 3);\n ubo.addUniform(\"vRefractionSize\", 3);\n ubo.addUniform(\"vSpecularColor\", 4);\n ubo.addUniform(\"vEmissiveColor\", 3);\n ubo.addUniform(\"vDiffuseColor\", 4);\n ubo.addUniform(\"vAmbientColor\", 3);\n super.buildUniformLayout();\n }\n /**\n * Binds the submesh to this material by preparing the effect and shader to draw\n * @param world defines the world transformation matrix\n * @param mesh defines the mesh containing the submesh\n * @param subMesh defines the submesh to bind the material to\n */\n bindForSubMesh(world, mesh, subMesh) {\n var _a;\n const scene = this.getScene();\n const defines = subMesh.materialDefines;\n if (!defines) {\n return;\n }\n const effect = subMesh.effect;\n if (!effect) {\n return;\n }\n this._activeEffect = effect;\n // Matrices Mesh.\n mesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\n mesh.transferToEffect(world);\n // Binding unconditionally\n this._uniformBuffer.bindToEffect(effect, \"Material\");\n this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventHardBindForSubMesh(this._eventInfo);\n // Normal Matrix\n if (defines.OBJECTSPACE_NORMALMAP) {\n world.toNormalMatrix(this._normalMatrix);\n this.bindOnlyNormalMatrix(this._normalMatrix);\n }\n const mustRebind = effect._forceRebindOnNextCall || this._mustRebind(scene, effect, mesh.visibility);\n // Bones\n MaterialHelper.BindBonesParameters(mesh, effect);\n const ubo = this._uniformBuffer;\n if (mustRebind) {\n this.bindViewProjection(effect);\n if (!ubo.useUbo || !this.isFrozen || !ubo.isSync || effect._forceRebindOnNextCall) {\n if (StandardMaterial.FresnelEnabled && defines.FRESNEL) {\n // Fresnel\n if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {\n ubo.updateColor4(\"diffuseLeftColor\", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);\n ubo.updateColor4(\"diffuseRightColor\", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);\n }\n if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {\n ubo.updateColor4(\"opacityParts\", new Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);\n }\n if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {\n ubo.updateColor4(\"reflectionLeftColor\", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);\n ubo.updateColor4(\"reflectionRightColor\", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);\n }\n if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {\n ubo.updateColor4(\"refractionLeftColor\", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);\n ubo.updateColor4(\"refractionRightColor\", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);\n }\n if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {\n ubo.updateColor4(\"emissiveLeftColor\", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);\n ubo.updateColor4(\"emissiveRightColor\", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);\n }\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {\n ubo.updateFloat2(\"vDiffuseInfos\", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);\n MaterialHelper.BindTextureMatrix(this._diffuseTexture, ubo, \"diffuse\");\n }\n if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {\n ubo.updateFloat2(\"vAmbientInfos\", this._ambientTexture.coordinatesIndex, this._ambientTexture.level);\n MaterialHelper.BindTextureMatrix(this._ambientTexture, ubo, \"ambient\");\n }\n if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {\n ubo.updateFloat2(\"vOpacityInfos\", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);\n MaterialHelper.BindTextureMatrix(this._opacityTexture, ubo, \"opacity\");\n }\n if (this._hasAlphaChannel()) {\n ubo.updateFloat(\"alphaCutOff\", this.alphaCutOff);\n }\n if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {\n ubo.updateFloat2(\"vReflectionInfos\", this._reflectionTexture.level, this.roughness);\n ubo.updateMatrix(\"reflectionMatrix\", this._reflectionTexture.getReflectionTextureMatrix());\n if (this._reflectionTexture.boundingBoxSize) {\n const cubeTexture = this._reflectionTexture;\n ubo.updateVector3(\"vReflectionPosition\", cubeTexture.boundingBoxPosition);\n ubo.updateVector3(\"vReflectionSize\", cubeTexture.boundingBoxSize);\n }\n }\n if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {\n ubo.updateFloat2(\"vEmissiveInfos\", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);\n MaterialHelper.BindTextureMatrix(this._emissiveTexture, ubo, \"emissive\");\n }\n if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {\n ubo.updateFloat2(\"vLightmapInfos\", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);\n MaterialHelper.BindTextureMatrix(this._lightmapTexture, ubo, \"lightmap\");\n }\n if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {\n ubo.updateFloat2(\"vSpecularInfos\", this._specularTexture.coordinatesIndex, this._specularTexture.level);\n MaterialHelper.BindTextureMatrix(this._specularTexture, ubo, \"specular\");\n }\n if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {\n ubo.updateFloat3(\"vBumpInfos\", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);\n MaterialHelper.BindTextureMatrix(this._bumpTexture, ubo, \"bump\");\n if (scene._mirroredCameraPosition) {\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);\n }\n else {\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);\n }\n }\n if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {\n let depth = 1.0;\n if (!this._refractionTexture.isCube) {\n ubo.updateMatrix(\"refractionMatrix\", this._refractionTexture.getReflectionTextureMatrix());\n if (this._refractionTexture.depth) {\n depth = this._refractionTexture.depth;\n }\n }\n ubo.updateFloat4(\"vRefractionInfos\", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);\n if (this._refractionTexture.boundingBoxSize) {\n const cubeTexture = this._refractionTexture;\n ubo.updateVector3(\"vRefractionPosition\", cubeTexture.boundingBoxPosition);\n ubo.updateVector3(\"vRefractionSize\", cubeTexture.boundingBoxSize);\n }\n }\n }\n // Point size\n if (this.pointsCloud) {\n ubo.updateFloat(\"pointSize\", this.pointSize);\n }\n if (defines.SPECULARTERM) {\n ubo.updateColor4(\"vSpecularColor\", this.specularColor, this.specularPower);\n }\n ubo.updateColor3(\"vEmissiveColor\", StandardMaterial.EmissiveTextureEnabled ? this.emissiveColor : Color3.BlackReadOnly);\n ubo.updateColor4(\"vDiffuseColor\", this.diffuseColor, this.alpha);\n scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);\n ubo.updateColor3(\"vAmbientColor\", this._globalAmbientColor);\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {\n effect.setTexture(\"diffuseSampler\", this._diffuseTexture);\n }\n if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {\n effect.setTexture(\"ambientSampler\", this._ambientTexture);\n }\n if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {\n effect.setTexture(\"opacitySampler\", this._opacityTexture);\n }\n if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {\n if (this._reflectionTexture.isCube) {\n effect.setTexture(\"reflectionCubeSampler\", this._reflectionTexture);\n }\n else {\n effect.setTexture(\"reflection2DSampler\", this._reflectionTexture);\n }\n }\n if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {\n effect.setTexture(\"emissiveSampler\", this._emissiveTexture);\n }\n if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {\n effect.setTexture(\"lightmapSampler\", this._lightmapTexture);\n }\n if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {\n effect.setTexture(\"specularSampler\", this._specularTexture);\n }\n if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {\n effect.setTexture(\"bumpSampler\", this._bumpTexture);\n }\n if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {\n if (this._refractionTexture.isCube) {\n effect.setTexture(\"refractionCubeSampler\", this._refractionTexture);\n }\n else {\n effect.setTexture(\"refraction2DSampler\", this._refractionTexture);\n }\n }\n }\n // OIT with depth peeling\n if (this.getScene().useOrderIndependentTransparency && this.needAlphaBlendingForMesh(mesh)) {\n this.getScene().depthPeelingRenderer.bind(effect);\n }\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventBindForSubMesh(this._eventInfo);\n // Clip plane\n bindClipPlane(effect, this, scene);\n // Colors\n this.bindEyePosition(effect);\n }\n else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {\n this._needToBindSceneUbo = true;\n }\n if (mustRebind || !this.isFrozen) {\n // Lights\n if (scene.lightsEnabled && !this._disableLighting) {\n MaterialHelper.BindLights(scene, mesh, effect, defines, this._maxSimultaneousLights);\n }\n // View\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) ||\n this._reflectionTexture ||\n this._refractionTexture ||\n mesh.receiveShadows ||\n defines.PREPASS) {\n this.bindView(effect);\n }\n // Fog\n MaterialHelper.BindFogParameters(scene, mesh, effect);\n // Morph targets\n if (defines.NUM_MORPH_INFLUENCERS) {\n MaterialHelper.BindMorphTargetParameters(mesh, effect);\n }\n if (defines.BAKED_VERTEX_ANIMATION_TEXTURE) {\n (_a = mesh.bakedVertexAnimationManager) === null || _a === void 0 ? void 0 : _a.bind(effect, defines.INSTANCES);\n }\n // Log. depth\n if (this.useLogarithmicDepth) {\n MaterialHelper.BindLogDepth(defines, effect, scene);\n }\n // image processing\n if (this._imageProcessingConfiguration && !this._imageProcessingConfiguration.applyByPostProcess) {\n this._imageProcessingConfiguration.bind(this._activeEffect);\n }\n }\n this._afterBind(mesh, this._activeEffect);\n ubo.update();\n }\n /**\n * Get the list of animatables in the material.\n * @returns the list of animatables object used in the material\n */\n getAnimatables() {\n const results = super.getAnimatables();\n if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {\n results.push(this._diffuseTexture);\n }\n if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {\n results.push(this._ambientTexture);\n }\n if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {\n results.push(this._opacityTexture);\n }\n if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {\n results.push(this._reflectionTexture);\n }\n if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {\n results.push(this._emissiveTexture);\n }\n if (this._specularTexture && this._specularTexture.animations && this._specularTexture.animations.length > 0) {\n results.push(this._specularTexture);\n }\n if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {\n results.push(this._bumpTexture);\n }\n if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {\n results.push(this._lightmapTexture);\n }\n if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {\n results.push(this._refractionTexture);\n }\n return results;\n }\n /**\n * Gets the active textures from the material\n * @returns an array of textures\n */\n getActiveTextures() {\n const activeTextures = super.getActiveTextures();\n if (this._diffuseTexture) {\n activeTextures.push(this._diffuseTexture);\n }\n if (this._ambientTexture) {\n activeTextures.push(this._ambientTexture);\n }\n if (this._opacityTexture) {\n activeTextures.push(this._opacityTexture);\n }\n if (this._reflectionTexture) {\n activeTextures.push(this._reflectionTexture);\n }\n if (this._emissiveTexture) {\n activeTextures.push(this._emissiveTexture);\n }\n if (this._specularTexture) {\n activeTextures.push(this._specularTexture);\n }\n if (this._bumpTexture) {\n activeTextures.push(this._bumpTexture);\n }\n if (this._lightmapTexture) {\n activeTextures.push(this._lightmapTexture);\n }\n if (this._refractionTexture) {\n activeTextures.push(this._refractionTexture);\n }\n return activeTextures;\n }\n /**\n * Specifies if the material uses a texture\n * @param texture defines the texture to check against the material\n * @returns a boolean specifying if the material uses the texture\n */\n hasTexture(texture) {\n if (super.hasTexture(texture)) {\n return true;\n }\n if (this._diffuseTexture === texture) {\n return true;\n }\n if (this._ambientTexture === texture) {\n return true;\n }\n if (this._opacityTexture === texture) {\n return true;\n }\n if (this._reflectionTexture === texture) {\n return true;\n }\n if (this._emissiveTexture === texture) {\n return true;\n }\n if (this._specularTexture === texture) {\n return true;\n }\n if (this._bumpTexture === texture) {\n return true;\n }\n if (this._lightmapTexture === texture) {\n return true;\n }\n if (this._refractionTexture === texture) {\n return true;\n }\n return false;\n }\n /**\n * Disposes the material\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\n */\n dispose(forceDisposeEffect, forceDisposeTextures) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j;\n if (forceDisposeTextures) {\n (_a = this._diffuseTexture) === null || _a === void 0 ? void 0 : _a.dispose();\n (_b = this._ambientTexture) === null || _b === void 0 ? void 0 : _b.dispose();\n (_c = this._opacityTexture) === null || _c === void 0 ? void 0 : _c.dispose();\n (_d = this._reflectionTexture) === null || _d === void 0 ? void 0 : _d.dispose();\n (_e = this._emissiveTexture) === null || _e === void 0 ? void 0 : _e.dispose();\n (_f = this._specularTexture) === null || _f === void 0 ? void 0 : _f.dispose();\n (_g = this._bumpTexture) === null || _g === void 0 ? void 0 : _g.dispose();\n (_h = this._lightmapTexture) === null || _h === void 0 ? void 0 : _h.dispose();\n (_j = this._refractionTexture) === null || _j === void 0 ? void 0 : _j.dispose();\n }\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n super.dispose(forceDisposeEffect, forceDisposeTextures);\n }\n /**\n * Makes a duplicate of the material, and gives it a new name\n * @param name defines the new name for the duplicated material\n * @param cloneTexturesOnlyOnce - if a texture is used in more than one channel (e.g diffuse and opacity), only clone it once and reuse it on the other channels. Default false.\n * @param rootUrl defines the root URL to use to load textures\n * @returns the cloned material\n */\n clone(name, cloneTexturesOnlyOnce = true, rootUrl = \"\") {\n const result = SerializationHelper.Clone(() => new StandardMaterial(name, this.getScene()), this, { cloneTexturesOnlyOnce });\n result.name = name;\n result.id = name;\n this.stencil.copyTo(result.stencil);\n this._clonePlugins(result, rootUrl);\n return result;\n }\n /**\n * Creates a standard material from parsed material data\n * @param source defines the JSON representation of the material\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a new standard material\n */\n static Parse(source, scene, rootUrl) {\n const material = SerializationHelper.Parse(() => new StandardMaterial(source.name, scene), source, scene, rootUrl);\n if (source.stencil) {\n material.stencil.parse(source.stencil, scene, rootUrl);\n }\n Material._parsePlugins(source, material, scene, rootUrl);\n return material;\n }\n // Flags used to enable or disable a type of texture for all Standard Materials\n /**\n * Are diffuse textures enabled in the application.\n */\n static get DiffuseTextureEnabled() {\n return MaterialFlags.DiffuseTextureEnabled;\n }\n static set DiffuseTextureEnabled(value) {\n MaterialFlags.DiffuseTextureEnabled = value;\n }\n /**\n * Are detail textures enabled in the application.\n */\n static get DetailTextureEnabled() {\n return MaterialFlags.DetailTextureEnabled;\n }\n static set DetailTextureEnabled(value) {\n MaterialFlags.DetailTextureEnabled = value;\n }\n /**\n * Are ambient textures enabled in the application.\n */\n static get AmbientTextureEnabled() {\n return MaterialFlags.AmbientTextureEnabled;\n }\n static set AmbientTextureEnabled(value) {\n MaterialFlags.AmbientTextureEnabled = value;\n }\n /**\n * Are opacity textures enabled in the application.\n */\n static get OpacityTextureEnabled() {\n return MaterialFlags.OpacityTextureEnabled;\n }\n static set OpacityTextureEnabled(value) {\n MaterialFlags.OpacityTextureEnabled = value;\n }\n /**\n * Are reflection textures enabled in the application.\n */\n static get ReflectionTextureEnabled() {\n return MaterialFlags.ReflectionTextureEnabled;\n }\n static set ReflectionTextureEnabled(value) {\n MaterialFlags.ReflectionTextureEnabled = value;\n }\n /**\n * Are emissive textures enabled in the application.\n */\n static get EmissiveTextureEnabled() {\n return MaterialFlags.EmissiveTextureEnabled;\n }\n static set EmissiveTextureEnabled(value) {\n MaterialFlags.EmissiveTextureEnabled = value;\n }\n /**\n * Are specular textures enabled in the application.\n */\n static get SpecularTextureEnabled() {\n return MaterialFlags.SpecularTextureEnabled;\n }\n static set SpecularTextureEnabled(value) {\n MaterialFlags.SpecularTextureEnabled = value;\n }\n /**\n * Are bump textures enabled in the application.\n */\n static get BumpTextureEnabled() {\n return MaterialFlags.BumpTextureEnabled;\n }\n static set BumpTextureEnabled(value) {\n MaterialFlags.BumpTextureEnabled = value;\n }\n /**\n * Are lightmap textures enabled in the application.\n */\n static get LightmapTextureEnabled() {\n return MaterialFlags.LightmapTextureEnabled;\n }\n static set LightmapTextureEnabled(value) {\n MaterialFlags.LightmapTextureEnabled = value;\n }\n /**\n * Are refraction textures enabled in the application.\n */\n static get RefractionTextureEnabled() {\n return MaterialFlags.RefractionTextureEnabled;\n }\n static set RefractionTextureEnabled(value) {\n MaterialFlags.RefractionTextureEnabled = value;\n }\n /**\n * Are color grading textures enabled in the application.\n */\n static get ColorGradingTextureEnabled() {\n return MaterialFlags.ColorGradingTextureEnabled;\n }\n static set ColorGradingTextureEnabled(value) {\n MaterialFlags.ColorGradingTextureEnabled = value;\n }\n /**\n * Are fresnels enabled in the application.\n */\n static get FresnelEnabled() {\n return MaterialFlags.FresnelEnabled;\n }\n static set FresnelEnabled(value) {\n MaterialFlags.FresnelEnabled = value;\n }\n }\n __decorate$1([\n serializeAsTexture(\"diffuseTexture\")\n ], StandardMaterial.prototype, \"_diffuseTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], StandardMaterial.prototype, \"diffuseTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"ambientTexture\")\n ], StandardMaterial.prototype, \"_ambientTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"ambientTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"opacityTexture\")\n ], StandardMaterial.prototype, \"_opacityTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], StandardMaterial.prototype, \"opacityTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"reflectionTexture\")\n ], StandardMaterial.prototype, \"_reflectionTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"reflectionTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"emissiveTexture\")\n ], StandardMaterial.prototype, \"_emissiveTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"emissiveTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"specularTexture\")\n ], StandardMaterial.prototype, \"_specularTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"specularTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"bumpTexture\")\n ], StandardMaterial.prototype, \"_bumpTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"bumpTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"lightmapTexture\")\n ], StandardMaterial.prototype, \"_lightmapTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"lightmapTexture\", void 0);\n __decorate$1([\n serializeAsTexture(\"refractionTexture\")\n ], StandardMaterial.prototype, \"_refractionTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"refractionTexture\", void 0);\n __decorate$1([\n serializeAsColor3(\"ambient\")\n ], StandardMaterial.prototype, \"ambientColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"diffuse\")\n ], StandardMaterial.prototype, \"diffuseColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"specular\")\n ], StandardMaterial.prototype, \"specularColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"emissive\")\n ], StandardMaterial.prototype, \"emissiveColor\", void 0);\n __decorate$1([\n serialize()\n ], StandardMaterial.prototype, \"specularPower\", void 0);\n __decorate$1([\n serialize(\"useAlphaFromDiffuseTexture\")\n ], StandardMaterial.prototype, \"_useAlphaFromDiffuseTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], StandardMaterial.prototype, \"useAlphaFromDiffuseTexture\", void 0);\n __decorate$1([\n serialize(\"useEmissiveAsIllumination\")\n ], StandardMaterial.prototype, \"_useEmissiveAsIllumination\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useEmissiveAsIllumination\", void 0);\n __decorate$1([\n serialize(\"linkEmissiveWithDiffuse\")\n ], StandardMaterial.prototype, \"_linkEmissiveWithDiffuse\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"linkEmissiveWithDiffuse\", void 0);\n __decorate$1([\n serialize(\"useSpecularOverAlpha\")\n ], StandardMaterial.prototype, \"_useSpecularOverAlpha\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useSpecularOverAlpha\", void 0);\n __decorate$1([\n serialize(\"useReflectionOverAlpha\")\n ], StandardMaterial.prototype, \"_useReflectionOverAlpha\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useReflectionOverAlpha\", void 0);\n __decorate$1([\n serialize(\"disableLighting\")\n ], StandardMaterial.prototype, \"_disableLighting\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], StandardMaterial.prototype, \"disableLighting\", void 0);\n __decorate$1([\n serialize(\"useObjectSpaceNormalMap\")\n ], StandardMaterial.prototype, \"_useObjectSpaceNormalMap\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useObjectSpaceNormalMap\", void 0);\n __decorate$1([\n serialize(\"useParallax\")\n ], StandardMaterial.prototype, \"_useParallax\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useParallax\", void 0);\n __decorate$1([\n serialize(\"useParallaxOcclusion\")\n ], StandardMaterial.prototype, \"_useParallaxOcclusion\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useParallaxOcclusion\", void 0);\n __decorate$1([\n serialize()\n ], StandardMaterial.prototype, \"parallaxScaleBias\", void 0);\n __decorate$1([\n serialize(\"roughness\")\n ], StandardMaterial.prototype, \"_roughness\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"roughness\", void 0);\n __decorate$1([\n serialize()\n ], StandardMaterial.prototype, \"indexOfRefraction\", void 0);\n __decorate$1([\n serialize()\n ], StandardMaterial.prototype, \"invertRefractionY\", void 0);\n __decorate$1([\n serialize()\n ], StandardMaterial.prototype, \"alphaCutOff\", void 0);\n __decorate$1([\n serialize(\"useLightmapAsShadowmap\")\n ], StandardMaterial.prototype, \"_useLightmapAsShadowmap\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useLightmapAsShadowmap\", void 0);\n __decorate$1([\n serializeAsFresnelParameters(\"diffuseFresnelParameters\")\n ], StandardMaterial.prototype, \"_diffuseFresnelParameters\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\n ], StandardMaterial.prototype, \"diffuseFresnelParameters\", void 0);\n __decorate$1([\n serializeAsFresnelParameters(\"opacityFresnelParameters\")\n ], StandardMaterial.prototype, \"_opacityFresnelParameters\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsFresnelAndMiscDirty\")\n ], StandardMaterial.prototype, \"opacityFresnelParameters\", void 0);\n __decorate$1([\n serializeAsFresnelParameters(\"reflectionFresnelParameters\")\n ], StandardMaterial.prototype, \"_reflectionFresnelParameters\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\n ], StandardMaterial.prototype, \"reflectionFresnelParameters\", void 0);\n __decorate$1([\n serializeAsFresnelParameters(\"refractionFresnelParameters\")\n ], StandardMaterial.prototype, \"_refractionFresnelParameters\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\n ], StandardMaterial.prototype, \"refractionFresnelParameters\", void 0);\n __decorate$1([\n serializeAsFresnelParameters(\"emissiveFresnelParameters\")\n ], StandardMaterial.prototype, \"_emissiveFresnelParameters\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\n ], StandardMaterial.prototype, \"emissiveFresnelParameters\", void 0);\n __decorate$1([\n serialize(\"useReflectionFresnelFromSpecular\")\n ], StandardMaterial.prototype, \"_useReflectionFresnelFromSpecular\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\n ], StandardMaterial.prototype, \"useReflectionFresnelFromSpecular\", void 0);\n __decorate$1([\n serialize(\"useGlossinessFromSpecularMapAlpha\")\n ], StandardMaterial.prototype, \"_useGlossinessFromSpecularMapAlpha\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"useGlossinessFromSpecularMapAlpha\", void 0);\n __decorate$1([\n serialize(\"maxSimultaneousLights\")\n ], StandardMaterial.prototype, \"_maxSimultaneousLights\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], StandardMaterial.prototype, \"maxSimultaneousLights\", void 0);\n __decorate$1([\n serialize(\"invertNormalMapX\")\n ], StandardMaterial.prototype, \"_invertNormalMapX\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"invertNormalMapX\", void 0);\n __decorate$1([\n serialize(\"invertNormalMapY\")\n ], StandardMaterial.prototype, \"_invertNormalMapY\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"invertNormalMapY\", void 0);\n __decorate$1([\n serialize(\"twoSidedLighting\")\n ], StandardMaterial.prototype, \"_twoSidedLighting\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], StandardMaterial.prototype, \"twoSidedLighting\", void 0);\n __decorate$1([\n serialize(\"applyDecalMapAfterDetailMap\")\n ], StandardMaterial.prototype, \"_applyDecalMapAfterDetailMap\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], StandardMaterial.prototype, \"applyDecalMapAfterDetailMap\", void 0);\n __decorate$1([\n serialize()\n ], StandardMaterial.prototype, \"useLogarithmicDepth\", null);\n RegisterClass(\"BABYLON.StandardMaterial\", StandardMaterial);\n Scene.DefaultMaterialFactory = (scene) => {\n return new StandardMaterial(\"default material\", scene);\n };\n\n // Do not edit.\n const name$$ = \"postprocessVertexShader\";\n const shader$$ = `attribute vec2 position;uniform vec2 scale;varying vec2 vUV;const vec2 madd=vec2(0.5,0.5);\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvUV=(position*madd+madd)*scale;gl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$$] = shader$$;\n\n /**\n * Wrapper around a render target (either single or multi textures)\n */\n class RenderTargetWrapper {\n /**\n * Gets the depth/stencil texture (if created by a createDepthStencilTexture() call)\n */\n get depthStencilTexture() {\n return this._depthStencilTexture;\n }\n /**\n * Indicates if the depth/stencil texture has a stencil aspect\n */\n get depthStencilTextureWithStencil() {\n return this._depthStencilTextureWithStencil;\n }\n /**\n * Defines if the render target wrapper is for a cube texture or if false a 2d texture\n */\n get isCube() {\n return this._isCube;\n }\n /**\n * Defines if the render target wrapper is for a single or multi target render wrapper\n */\n get isMulti() {\n return this._isMulti;\n }\n /**\n * Defines if the render target wrapper is for a single or an array of textures\n */\n get is2DArray() {\n return this.layers > 0;\n }\n /**\n * Gets the size of the render target wrapper (used for cubes, as width=height in this case)\n */\n get size() {\n return this.width;\n }\n /**\n * Gets the width of the render target wrapper\n */\n get width() {\n return this._size.width || this._size;\n }\n /**\n * Gets the height of the render target wrapper\n */\n get height() {\n return this._size.height || this._size;\n }\n /**\n * Gets the number of layers of the render target wrapper (only used if is2DArray is true and wrapper is not a multi render target)\n */\n get layers() {\n return this._size.layers || 0;\n }\n /**\n * Gets the render texture. If this is a multi render target, gets the first texture\n */\n get texture() {\n var _a, _b;\n return (_b = (_a = this._textures) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null;\n }\n /**\n * Gets the list of render textures. If we are not in a multi render target, the list will be null (use the texture getter instead)\n */\n get textures() {\n return this._textures;\n }\n /**\n * Gets the face indices that correspond to the list of render textures. If we are not in a multi render target, the list will be null\n */\n get faceIndices() {\n return this._faceIndices;\n }\n /**\n * Gets the layer indices that correspond to the list of render textures. If we are not in a multi render target, the list will be null\n */\n get layerIndices() {\n return this._layerIndices;\n }\n /**\n * Gets the sample count of the render target\n */\n get samples() {\n return this._samples;\n }\n /**\n * Sets the sample count of the render target\n * @param value sample count\n * @param initializeBuffers If set to true, the engine will make an initializing call to drawBuffers (only used when isMulti=true).\n * @param force true to force calling the update sample count engine function even if the current sample count is equal to value\n * @returns the sample count that has been set\n */\n setSamples(value, initializeBuffers = true, force = false) {\n if (this.samples === value && !force) {\n return value;\n }\n const result = this._isMulti\n ? this._engine.updateMultipleRenderTargetTextureSampleCount(this, value, initializeBuffers)\n : this._engine.updateRenderTargetTextureSampleCount(this, value);\n this._samples = value;\n return result;\n }\n /**\n * Initializes the render target wrapper\n * @param isMulti true if the wrapper is a multi render target\n * @param isCube true if the wrapper should render to a cube texture\n * @param size size of the render target (width/height/layers)\n * @param engine engine used to create the render target\n */\n constructor(isMulti, isCube, size, engine) {\n this._textures = null;\n this._faceIndices = null;\n this._layerIndices = null;\n /** @internal */\n this._samples = 1;\n /** @internal */\n this._attachments = null;\n /** @internal */\n this._generateStencilBuffer = false;\n /** @internal */\n this._generateDepthBuffer = false;\n /** @internal */\n this._depthStencilTextureWithStencil = false;\n this._isMulti = isMulti;\n this._isCube = isCube;\n this._size = size;\n this._engine = engine;\n this._depthStencilTexture = null;\n }\n /**\n * Sets the render target texture(s)\n * @param textures texture(s) to set\n */\n setTextures(textures) {\n if (Array.isArray(textures)) {\n this._textures = textures;\n }\n else if (textures) {\n this._textures = [textures];\n }\n else {\n this._textures = null;\n }\n }\n /**\n * Set a texture in the textures array\n * @param texture The texture to set\n * @param index The index in the textures array to set\n * @param disposePrevious If this function should dispose the previous texture\n */\n setTexture(texture, index = 0, disposePrevious = true) {\n if (!this._textures) {\n this._textures = [];\n }\n if (this._textures[index] && disposePrevious) {\n this._textures[index].dispose();\n }\n this._textures[index] = texture;\n }\n /**\n * Sets the layer and face indices of every render target texture bound to each color attachment\n * @param layers The layers of each texture to be set\n * @param faces The faces of each texture to be set\n */\n setLayerAndFaceIndices(layers, faces) {\n this._layerIndices = layers;\n this._faceIndices = faces;\n }\n /**\n * Sets the layer and face indices of a texture in the textures array that should be bound to each color attachment\n * @param index The index of the texture in the textures array to modify\n * @param layer The layer of the texture to be set\n * @param face The face of the texture to be set\n */\n setLayerAndFaceIndex(index = 0, layer, face) {\n if (!this._layerIndices) {\n this._layerIndices = [];\n }\n if (!this._faceIndices) {\n this._faceIndices = [];\n }\n if (layer !== undefined && layer >= 0) {\n this._layerIndices[index] = layer;\n }\n if (face !== undefined && face >= 0) {\n this._faceIndices[index] = face;\n }\n }\n /**\n * Creates the depth/stencil texture\n * @param comparisonFunction Comparison function to use for the texture\n * @param bilinearFiltering true if bilinear filtering should be used when sampling the texture\n * @param generateStencil true if the stencil aspect should also be created\n * @param samples sample count to use when creating the texture\n * @param format format of the depth texture\n * @param label defines the label to use for the texture (for debugging purpose only)\n * @returns the depth/stencil created texture\n */\n createDepthStencilTexture(comparisonFunction = 0, bilinearFiltering = true, generateStencil = false, samples = 1, format = 14, label) {\n var _a;\n (_a = this._depthStencilTexture) === null || _a === void 0 ? void 0 : _a.dispose();\n this._depthStencilTextureWithStencil = generateStencil;\n this._depthStencilTexture = this._engine.createDepthStencilTexture(this._size, {\n bilinearFiltering,\n comparisonFunction,\n generateStencil,\n isCube: this._isCube,\n samples,\n depthTextureFormat: format,\n label,\n }, this);\n return this._depthStencilTexture;\n }\n /**\n * Shares the depth buffer of this render target with another render target.\n * @internal\n * @param renderTarget Destination renderTarget\n */\n _shareDepth(renderTarget) {\n if (this._depthStencilTexture) {\n if (renderTarget._depthStencilTexture) {\n renderTarget._depthStencilTexture.dispose();\n }\n renderTarget._depthStencilTexture = this._depthStencilTexture;\n this._depthStencilTexture.incrementReferences();\n }\n }\n /**\n * @internal\n */\n _swapAndDie(target) {\n if (this.texture) {\n this.texture._swapAndDie(target);\n }\n this._textures = null;\n this.dispose(true);\n }\n _cloneRenderTargetWrapper() {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n let rtw = null;\n if (this._isMulti) {\n const textureArray = this.textures;\n if (textureArray && textureArray.length > 0) {\n let generateDepthTexture = false;\n let textureCount = textureArray.length;\n const lastTextureSource = textureArray[textureArray.length - 1]._source;\n if (lastTextureSource === InternalTextureSource.Depth || lastTextureSource === InternalTextureSource.DepthStencil) {\n generateDepthTexture = true;\n textureCount--;\n }\n const samplingModes = [];\n const types = [];\n const formats = [];\n const targetTypes = [];\n const faceIndex = [];\n const layerIndex = [];\n const layerCounts = [];\n const internalTexture2Index = {};\n for (let i = 0; i < textureCount; ++i) {\n const texture = textureArray[i];\n samplingModes.push(texture.samplingMode);\n types.push(texture.type);\n formats.push(texture.format);\n const index = internalTexture2Index[texture.uniqueId];\n if (index !== undefined) {\n targetTypes.push(-1);\n layerCounts.push(0);\n }\n else {\n internalTexture2Index[texture.uniqueId] = i;\n if (texture.is2DArray) {\n targetTypes.push(35866);\n layerCounts.push(texture.depth);\n }\n else if (texture.isCube) {\n targetTypes.push(34067);\n layerCounts.push(0);\n } /*else if (texture.isCubeArray) {\n targetTypes.push(3735928559);\n layerCounts.push(texture.depth);\n }*/\n else if (texture.is3D) {\n targetTypes.push(32879);\n layerCounts.push(texture.depth);\n }\n else {\n targetTypes.push(3553);\n layerCounts.push(0);\n }\n }\n if (this._faceIndices) {\n faceIndex.push((_a = this._faceIndices[i]) !== null && _a !== void 0 ? _a : 0);\n }\n if (this._layerIndices) {\n layerIndex.push((_b = this._layerIndices[i]) !== null && _b !== void 0 ? _b : 0);\n }\n }\n const optionsMRT = {\n samplingModes,\n generateMipMaps: textureArray[0].generateMipMaps,\n generateDepthBuffer: this._generateDepthBuffer,\n generateStencilBuffer: this._generateStencilBuffer,\n generateDepthTexture,\n types,\n formats,\n textureCount,\n targetTypes,\n faceIndex,\n layerIndex,\n layerCounts,\n };\n const size = {\n width: this.width,\n height: this.height,\n };\n rtw = this._engine.createMultipleRenderTarget(size, optionsMRT);\n for (let i = 0; i < textureCount; ++i) {\n if (targetTypes[i] !== -1) {\n continue;\n }\n const index = internalTexture2Index[textureArray[i].uniqueId];\n rtw.setTexture(rtw.textures[index], i);\n }\n }\n }\n else {\n const options = {};\n options.generateDepthBuffer = this._generateDepthBuffer;\n options.generateMipMaps = (_d = (_c = this.texture) === null || _c === void 0 ? void 0 : _c.generateMipMaps) !== null && _d !== void 0 ? _d : false;\n options.generateStencilBuffer = this._generateStencilBuffer;\n options.samplingMode = (_e = this.texture) === null || _e === void 0 ? void 0 : _e.samplingMode;\n options.type = (_f = this.texture) === null || _f === void 0 ? void 0 : _f.type;\n options.format = (_g = this.texture) === null || _g === void 0 ? void 0 : _g.format;\n if (this.isCube) {\n rtw = this._engine.createRenderTargetCubeTexture(this.width, options);\n }\n else {\n const size = {\n width: this.width,\n height: this.height,\n layers: this.is2DArray ? (_h = this.texture) === null || _h === void 0 ? void 0 : _h.depth : undefined,\n };\n rtw = this._engine.createRenderTargetTexture(size, options);\n }\n rtw.texture.isReady = true;\n }\n return rtw;\n }\n _swapRenderTargetWrapper(target) {\n if (this._textures && target._textures) {\n for (let i = 0; i < this._textures.length; ++i) {\n this._textures[i]._swapAndDie(target._textures[i], false);\n target._textures[i].isReady = true;\n }\n }\n if (this._depthStencilTexture && target._depthStencilTexture) {\n this._depthStencilTexture._swapAndDie(target._depthStencilTexture);\n target._depthStencilTexture.isReady = true;\n }\n this._textures = null;\n this._depthStencilTexture = null;\n }\n /** @internal */\n _rebuild() {\n const rtw = this._cloneRenderTargetWrapper();\n if (!rtw) {\n return;\n }\n if (this._depthStencilTexture) {\n const samplingMode = this._depthStencilTexture.samplingMode;\n const bilinear = samplingMode === 2 ||\n samplingMode === 3 ||\n samplingMode === 11;\n rtw.createDepthStencilTexture(this._depthStencilTexture._comparisonFunction, bilinear, this._depthStencilTextureWithStencil, this._depthStencilTexture.samples);\n }\n if (this.samples > 1) {\n rtw.setSamples(this.samples);\n }\n rtw._swapRenderTargetWrapper(this);\n rtw.dispose();\n }\n /**\n * Releases the internal render textures\n */\n releaseTextures() {\n var _a, _b;\n if (this._textures) {\n for (let i = 0; (_b = i < ((_a = this._textures) === null || _a === void 0 ? void 0 : _a.length)) !== null && _b !== void 0 ? _b : 0; ++i) {\n this._textures[i].dispose();\n }\n }\n this._textures = null;\n }\n /**\n * Disposes the whole render target wrapper\n * @param disposeOnlyFramebuffers true if only the frame buffers should be released (used for the WebGL engine). If false, all the textures will also be released\n */\n dispose(disposeOnlyFramebuffers = false) {\n var _a;\n if (!disposeOnlyFramebuffers) {\n (_a = this._depthStencilTexture) === null || _a === void 0 ? void 0 : _a.dispose();\n this._depthStencilTexture = null;\n this.releaseTextures();\n }\n this._engine._releaseRenderTargetWrapper(this);\n }\n }\n\n /** @internal */\n class WebGLRenderTargetWrapper extends RenderTargetWrapper {\n constructor(isMulti, isCube, size, engine, context) {\n super(isMulti, isCube, size, engine);\n /**\n * @internal\n */\n this._framebuffer = null;\n /**\n * @internal\n */\n this._depthStencilBuffer = null;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n /**\n * @internal\n */\n this._MSAAFramebuffer = null;\n // Multiview\n /**\n * @internal\n */\n this._colorTextureArray = null;\n /**\n * @internal\n */\n this._depthStencilTextureArray = null;\n /**\n * @internal\n */\n this._disposeOnlyFramebuffers = false;\n this._context = context;\n }\n _cloneRenderTargetWrapper() {\n let rtw = null;\n if (this._colorTextureArray && this._depthStencilTextureArray) {\n rtw = this._engine.createMultiviewRenderTargetTexture(this.width, this.height);\n rtw.texture.isReady = true;\n }\n else {\n rtw = super._cloneRenderTargetWrapper();\n }\n return rtw;\n }\n _swapRenderTargetWrapper(target) {\n super._swapRenderTargetWrapper(target);\n target._framebuffer = this._framebuffer;\n target._depthStencilBuffer = this._depthStencilBuffer;\n target._MSAAFramebuffer = this._MSAAFramebuffer;\n target._colorTextureArray = this._colorTextureArray;\n target._depthStencilTextureArray = this._depthStencilTextureArray;\n this._framebuffer = this._depthStencilBuffer = this._MSAAFramebuffer = this._colorTextureArray = this._depthStencilTextureArray = null;\n }\n /**\n * Shares the depth buffer of this render target with another render target.\n * @internal\n * @param renderTarget Destination renderTarget\n */\n _shareDepth(renderTarget) {\n super._shareDepth(renderTarget);\n const gl = this._context;\n const depthbuffer = this._depthStencilBuffer;\n const framebuffer = renderTarget._MSAAFramebuffer || renderTarget._framebuffer;\n if (renderTarget._depthStencilBuffer) {\n gl.deleteRenderbuffer(renderTarget._depthStencilBuffer);\n }\n renderTarget._depthStencilBuffer = this._depthStencilBuffer;\n this._engine._bindUnboundFramebuffer(framebuffer);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthbuffer);\n this._engine._bindUnboundFramebuffer(null);\n }\n /**\n * Binds a texture to this render target on a specific attachment\n * @param texture The texture to bind to the framebuffer\n * @param attachmentIndex Index of the attachment\n * @param faceIndexOrLayer The face or layer of the texture to render to in case of cube texture or array texture\n * @param lodLevel defines the lod level to bind to the frame buffer\n */\n _bindTextureRenderTarget(texture, attachmentIndex = 0, faceIndexOrLayer, lodLevel = 0) {\n var _a, _b, _c, _d;\n if (!texture._hardwareTexture) {\n return;\n }\n const framebuffer = this._framebuffer;\n const currentFB = this._engine._currentFramebuffer;\n this._engine._bindUnboundFramebuffer(framebuffer);\n if (this._engine.webGLVersion > 1) {\n const gl = this._context;\n const attachment = gl[\"COLOR_ATTACHMENT\" + attachmentIndex];\n if (texture.is2DArray || texture.is3D) {\n faceIndexOrLayer = (_b = faceIndexOrLayer !== null && faceIndexOrLayer !== void 0 ? faceIndexOrLayer : (_a = this.layerIndices) === null || _a === void 0 ? void 0 : _a[attachmentIndex]) !== null && _b !== void 0 ? _b : 0;\n gl.framebufferTextureLayer(gl.FRAMEBUFFER, attachment, texture._hardwareTexture.underlyingResource, lodLevel, faceIndexOrLayer);\n }\n else if (texture.isCube) {\n // if face index is not specified, try to query it from faceIndices\n // default is face 0\n faceIndexOrLayer = (_d = faceIndexOrLayer !== null && faceIndexOrLayer !== void 0 ? faceIndexOrLayer : (_c = this.faceIndices) === null || _c === void 0 ? void 0 : _c[attachmentIndex]) !== null && _d !== void 0 ? _d : 0;\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndexOrLayer, texture._hardwareTexture.underlyingResource, lodLevel);\n }\n else {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, texture._hardwareTexture.underlyingResource, lodLevel);\n }\n }\n else {\n // Default behavior (WebGL)\n const gl = this._context;\n const attachment = gl[\"COLOR_ATTACHMENT\" + attachmentIndex + \"_WEBGL\"];\n const target = faceIndexOrLayer !== undefined ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndexOrLayer : gl.TEXTURE_2D;\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, target, texture._hardwareTexture.underlyingResource, lodLevel);\n }\n this._engine._bindUnboundFramebuffer(currentFB);\n }\n /**\n * Set a texture in the textures array\n * @param texture the texture to set\n * @param index the index in the textures array to set\n * @param disposePrevious If this function should dispose the previous texture\n */\n setTexture(texture, index = 0, disposePrevious = true) {\n super.setTexture(texture, index, disposePrevious);\n this._bindTextureRenderTarget(texture, index);\n }\n /**\n * Sets the layer and face indices of every render target texture\n * @param layers The layer of the texture to be set (make negative to not modify)\n * @param faces The face of the texture to be set (make negative to not modify)\n */\n setLayerAndFaceIndices(layers, faces) {\n var _a, _b;\n super.setLayerAndFaceIndices(layers, faces);\n if (!this.textures || !this.layerIndices || !this.faceIndices) {\n return;\n }\n // the length of this._attachments is the right one as it does not count the depth texture, in case we generated it\n const textureCount = (_b = (_a = this._attachments) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : this.textures.length;\n for (let index = 0; index < textureCount; index++) {\n const texture = this.textures[index];\n if (!texture) {\n // The target type was probably -1 at creation time and setTexture has not been called yet for this index\n continue;\n }\n if (texture.is2DArray || texture.is3D) {\n this._bindTextureRenderTarget(texture, index, this.layerIndices[index]);\n }\n else if (texture.isCube) {\n this._bindTextureRenderTarget(texture, index, this.faceIndices[index]);\n }\n else {\n this._bindTextureRenderTarget(texture, index);\n }\n }\n }\n /**\n * Set the face and layer indices of a texture in the textures array\n * @param index The index of the texture in the textures array to modify\n * @param layer The layer of the texture to be set\n * @param face The face of the texture to be set\n */\n setLayerAndFaceIndex(index = 0, layer, face) {\n super.setLayerAndFaceIndex(index, layer, face);\n if (!this.textures || !this.layerIndices || !this.faceIndices) {\n return;\n }\n const texture = this.textures[index];\n if (texture.is2DArray || texture.is3D) {\n this._bindTextureRenderTarget(this.textures[index], index, this.layerIndices[index]);\n }\n else if (texture.isCube) {\n this._bindTextureRenderTarget(this.textures[index], index, this.faceIndices[index]);\n }\n }\n dispose(disposeOnlyFramebuffers = this._disposeOnlyFramebuffers) {\n const gl = this._context;\n if (!disposeOnlyFramebuffers) {\n if (this._colorTextureArray) {\n this._context.deleteTexture(this._colorTextureArray);\n this._colorTextureArray = null;\n }\n if (this._depthStencilTextureArray) {\n this._context.deleteTexture(this._depthStencilTextureArray);\n this._depthStencilTextureArray = null;\n }\n }\n if (this._framebuffer) {\n gl.deleteFramebuffer(this._framebuffer);\n this._framebuffer = null;\n }\n if (this._depthStencilBuffer) {\n gl.deleteRenderbuffer(this._depthStencilBuffer);\n this._depthStencilBuffer = null;\n }\n if (this._MSAAFramebuffer) {\n gl.deleteFramebuffer(this._MSAAFramebuffer);\n this._MSAAFramebuffer = null;\n }\n super.dispose(disposeOnlyFramebuffers);\n }\n }\n\n ThinEngine.prototype._createHardwareRenderTargetWrapper = function (isMulti, isCube, size) {\n const rtWrapper = new WebGLRenderTargetWrapper(isMulti, isCube, size, this, this._gl);\n this._renderTargetWrapperCache.push(rtWrapper);\n return rtWrapper;\n };\n ThinEngine.prototype.createRenderTargetTexture = function (size, options) {\n var _a, _b;\n const rtWrapper = this._createHardwareRenderTargetWrapper(false, false, size);\n let generateDepthBuffer = true;\n let generateStencilBuffer = false;\n let noColorAttachment = false;\n let colorAttachment = undefined;\n let samples = 1;\n if (options !== undefined && typeof options === \"object\") {\n generateDepthBuffer = (_a = options.generateDepthBuffer) !== null && _a !== void 0 ? _a : true;\n generateStencilBuffer = !!options.generateStencilBuffer;\n noColorAttachment = !!options.noColorAttachment;\n colorAttachment = options.colorAttachment;\n samples = (_b = options.samples) !== null && _b !== void 0 ? _b : 1;\n }\n const texture = colorAttachment || (noColorAttachment ? null : this._createInternalTexture(size, options, true, InternalTextureSource.RenderTarget));\n const width = size.width || size;\n const height = size.height || size;\n const currentFrameBuffer = this._currentFramebuffer;\n const gl = this._gl;\n // Create the framebuffer\n const framebuffer = gl.createFramebuffer();\n this._bindUnboundFramebuffer(framebuffer);\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(generateStencilBuffer, generateDepthBuffer, width, height);\n // No need to rebind on every frame\n if (texture && !texture.is2DArray) {\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture._hardwareTexture.underlyingResource, 0);\n }\n this._bindUnboundFramebuffer(currentFrameBuffer);\n rtWrapper._framebuffer = framebuffer;\n rtWrapper._generateDepthBuffer = generateDepthBuffer;\n rtWrapper._generateStencilBuffer = generateStencilBuffer;\n rtWrapper.setTextures(texture);\n this.updateRenderTargetTextureSampleCount(rtWrapper, samples);\n return rtWrapper;\n };\n ThinEngine.prototype.createDepthStencilTexture = function (size, options, rtWrapper) {\n if (options.isCube) {\n const width = size.width || size;\n return this._createDepthStencilCubeTexture(width, options, rtWrapper);\n }\n else {\n return this._createDepthStencilTexture(size, options, rtWrapper);\n }\n };\n ThinEngine.prototype._createDepthStencilTexture = function (size, options, rtWrapper) {\n const gl = this._gl;\n const layers = size.layers || 0;\n const target = layers !== 0 ? gl.TEXTURE_2D_ARRAY : gl.TEXTURE_2D;\n const internalTexture = new InternalTexture(this, InternalTextureSource.DepthStencil);\n if (!this._caps.depthTextureExtension) {\n Logger.Error(\"Depth texture is not supported by your browser or hardware.\");\n return internalTexture;\n }\n const internalOptions = Object.assign({ bilinearFiltering: false, comparisonFunction: 0, generateStencil: false }, options);\n this._bindTextureDirectly(target, internalTexture, true);\n this._setupDepthStencilTexture(internalTexture, size, internalOptions.generateStencil, internalOptions.comparisonFunction === 0 ? false : internalOptions.bilinearFiltering, internalOptions.comparisonFunction, internalOptions.samples);\n if (internalOptions.depthTextureFormat !== undefined) {\n if (internalOptions.depthTextureFormat !== 15 &&\n internalOptions.depthTextureFormat !== 16 &&\n internalOptions.depthTextureFormat !== 17 &&\n internalOptions.depthTextureFormat !== 13 &&\n internalOptions.depthTextureFormat !== 14 &&\n internalOptions.depthTextureFormat !== 18) {\n Logger.Error(\"Depth texture format is not supported.\");\n return internalTexture;\n }\n internalTexture.format = internalOptions.depthTextureFormat;\n }\n else {\n internalTexture.format = internalOptions.generateStencil ? 13 : 16;\n }\n const hasStencil = internalTexture.format === 17 ||\n internalTexture.format === 13 ||\n internalTexture.format === 18;\n rtWrapper._depthStencilTexture = internalTexture;\n rtWrapper._depthStencilTextureWithStencil = hasStencil;\n let type = gl.UNSIGNED_INT;\n if (internalTexture.format === 15) {\n type = gl.UNSIGNED_SHORT;\n }\n else if (internalTexture.format === 17 || internalTexture.format === 13) {\n type = gl.UNSIGNED_INT_24_8;\n }\n else if (internalTexture.format === 14) {\n type = gl.FLOAT;\n }\n else if (internalTexture.format === 18) {\n type = gl.FLOAT_32_UNSIGNED_INT_24_8_REV;\n }\n const format = hasStencil ? gl.DEPTH_STENCIL : gl.DEPTH_COMPONENT;\n let internalFormat = format;\n if (this.webGLVersion > 1) {\n if (internalTexture.format === 15) {\n internalFormat = gl.DEPTH_COMPONENT16;\n }\n else if (internalTexture.format === 16) {\n internalFormat = gl.DEPTH_COMPONENT24;\n }\n else if (internalTexture.format === 17 || internalTexture.format === 13) {\n internalFormat = gl.DEPTH24_STENCIL8;\n }\n else if (internalTexture.format === 14) {\n internalFormat = gl.DEPTH_COMPONENT32F;\n }\n else if (internalTexture.format === 18) {\n internalFormat = gl.DEPTH32F_STENCIL8;\n }\n }\n if (internalTexture.is2DArray) {\n gl.texImage3D(target, 0, internalFormat, internalTexture.width, internalTexture.height, layers, 0, format, type, null);\n }\n else {\n gl.texImage2D(target, 0, internalFormat, internalTexture.width, internalTexture.height, 0, format, type, null);\n }\n this._bindTextureDirectly(target, null);\n this._internalTexturesCache.push(internalTexture);\n // Dispose previous depth/stencil render buffers and clear the corresponding attachment.\n // Next time this framebuffer is bound, the new depth/stencil texture will be attached.\n const glRtWrapper = rtWrapper;\n if (glRtWrapper._depthStencilBuffer) {\n const currentFrameBuffer = this._currentFramebuffer;\n this._bindUnboundFramebuffer(glRtWrapper._framebuffer);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);\n this._bindUnboundFramebuffer(currentFrameBuffer);\n gl.deleteRenderbuffer(glRtWrapper._depthStencilBuffer);\n glRtWrapper._depthStencilBuffer = null;\n }\n return internalTexture;\n };\n ThinEngine.prototype.updateRenderTargetTextureSampleCount = function (rtWrapper, samples) {\n if (this.webGLVersion < 2 || !rtWrapper || !rtWrapper.texture) {\n return 1;\n }\n if (rtWrapper.samples === samples) {\n return samples;\n }\n const gl = this._gl;\n samples = Math.min(samples, this.getCaps().maxMSAASamples);\n // Dispose previous render buffers\n if (rtWrapper._depthStencilBuffer) {\n gl.deleteRenderbuffer(rtWrapper._depthStencilBuffer);\n rtWrapper._depthStencilBuffer = null;\n }\n if (rtWrapper._MSAAFramebuffer) {\n gl.deleteFramebuffer(rtWrapper._MSAAFramebuffer);\n rtWrapper._MSAAFramebuffer = null;\n }\n const hardwareTexture = rtWrapper.texture._hardwareTexture;\n hardwareTexture.releaseMSAARenderBuffers();\n if (samples > 1 && typeof gl.renderbufferStorageMultisample === \"function\") {\n const framebuffer = gl.createFramebuffer();\n if (!framebuffer) {\n throw new Error(\"Unable to create multi sampled framebuffer\");\n }\n rtWrapper._MSAAFramebuffer = framebuffer;\n this._bindUnboundFramebuffer(rtWrapper._MSAAFramebuffer);\n const colorRenderbuffer = this._createRenderBuffer(rtWrapper.texture.width, rtWrapper.texture.height, samples, -1 /* not used */, this._getRGBAMultiSampleBufferFormat(rtWrapper.texture.type), gl.COLOR_ATTACHMENT0, false);\n if (!colorRenderbuffer) {\n throw new Error(\"Unable to create multi sampled framebuffer\");\n }\n hardwareTexture.addMSAARenderBuffer(colorRenderbuffer);\n }\n else {\n this._bindUnboundFramebuffer(rtWrapper._framebuffer);\n }\n rtWrapper.texture.samples = samples;\n rtWrapper._samples = samples;\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(rtWrapper._generateStencilBuffer, rtWrapper._generateDepthBuffer, rtWrapper.texture.width, rtWrapper.texture.height, samples);\n this._bindUnboundFramebuffer(null);\n return samples;\n };\n\n /**\n * PostProcess can be used to apply a shader to a texture after it has been rendered\n * See https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses\n */\n class PostProcess {\n /**\n * Registers a shader code processing with a post process name.\n * @param postProcessName name of the post process. Use null for the fallback shader code processing. This is the shader code processing that will be used in case no specific shader code processing has been associated to a post process name\n * @param customShaderCodeProcessing shader code processing to associate to the post process name\n * @returns\n */\n static RegisterShaderCodeProcessing(postProcessName, customShaderCodeProcessing) {\n if (!customShaderCodeProcessing) {\n delete PostProcess._CustomShaderCodeProcessing[postProcessName !== null && postProcessName !== void 0 ? postProcessName : \"\"];\n return;\n }\n PostProcess._CustomShaderCodeProcessing[postProcessName !== null && postProcessName !== void 0 ? postProcessName : \"\"] = customShaderCodeProcessing;\n }\n static _GetShaderCodeProcessing(postProcessName) {\n var _a;\n return (_a = PostProcess._CustomShaderCodeProcessing[postProcessName]) !== null && _a !== void 0 ? _a : PostProcess._CustomShaderCodeProcessing[\"\"];\n }\n /**\n * Number of sample textures (default: 1)\n */\n get samples() {\n return this._samples;\n }\n set samples(n) {\n this._samples = Math.min(n, this._engine.getCaps().maxMSAASamples);\n this._textures.forEach((texture) => {\n texture.setSamples(this._samples);\n });\n }\n /**\n * Returns the fragment url or shader name used in the post process.\n * @returns the fragment url or name in the shader store.\n */\n getEffectName() {\n return this._fragmentUrl;\n }\n /**\n * A function that is added to the onActivateObservable\n */\n set onActivate(callback) {\n if (this._onActivateObserver) {\n this.onActivateObservable.remove(this._onActivateObserver);\n }\n if (callback) {\n this._onActivateObserver = this.onActivateObservable.add(callback);\n }\n }\n /**\n * A function that is added to the onSizeChangedObservable\n */\n set onSizeChanged(callback) {\n if (this._onSizeChangedObserver) {\n this.onSizeChangedObservable.remove(this._onSizeChangedObserver);\n }\n this._onSizeChangedObserver = this.onSizeChangedObservable.add(callback);\n }\n /**\n * A function that is added to the onApplyObservable\n */\n set onApply(callback) {\n if (this._onApplyObserver) {\n this.onApplyObservable.remove(this._onApplyObserver);\n }\n this._onApplyObserver = this.onApplyObservable.add(callback);\n }\n /**\n * A function that is added to the onBeforeRenderObservable\n */\n set onBeforeRender(callback) {\n if (this._onBeforeRenderObserver) {\n this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\n }\n this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);\n }\n /**\n * A function that is added to the onAfterRenderObservable\n */\n set onAfterRender(callback) {\n if (this._onAfterRenderObserver) {\n this.onAfterRenderObservable.remove(this._onAfterRenderObserver);\n }\n this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);\n }\n /**\n * The input texture for this post process and the output texture of the previous post process. When added to a pipeline the previous post process will\n * render it's output into this texture and this texture will be used as textureSampler in the fragment shader of this post process.\n */\n get inputTexture() {\n return this._textures.data[this._currentRenderTextureInd];\n }\n set inputTexture(value) {\n this._forcedOutputTexture = value;\n }\n /**\n * Since inputTexture should always be defined, if we previously manually set `inputTexture`,\n * the only way to unset it is to use this function to restore its internal state\n */\n restoreDefaultInputTexture() {\n if (this._forcedOutputTexture) {\n this._forcedOutputTexture = null;\n this.markTextureDirty();\n }\n }\n /**\n * Gets the camera which post process is applied to.\n * @returns The camera the post process is applied to.\n */\n getCamera() {\n return this._camera;\n }\n /**\n * Gets the texel size of the postprocess.\n * See https://en.wikipedia.org/wiki/Texel_(graphics)\n */\n get texelSize() {\n if (this._shareOutputWithPostProcess) {\n return this._shareOutputWithPostProcess.texelSize;\n }\n if (this._forcedOutputTexture) {\n this._texelSize.copyFromFloats(1.0 / this._forcedOutputTexture.width, 1.0 / this._forcedOutputTexture.height);\n }\n return this._texelSize;\n }\n /**\n * Creates a new instance PostProcess\n * @param name The name of the PostProcess.\n * @param fragmentUrl The url of the fragment shader to be used.\n * @param parameters Array of the names of uniform non-sampler2D variables that will be passed to the shader.\n * @param samplers Array of the names of uniform sampler2D variables that will be passed to the shader.\n * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)\n * @param camera The camera to apply the render pass to.\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\n * @param engine The engine which the post process will be applied. (default: current engine)\n * @param reusable If the post process can be reused on the same frame. (default: false)\n * @param defines String of defines that will be set when running the fragment shader. (default: null)\n * @param textureType Type of textures used when performing the post process. (default: 0)\n * @param vertexUrl The url of the vertex shader to be used. (default: \"postprocess\")\n * @param indexParameters The index parameters to be used for babylons include syntax \"#include[0..varyingCount]\". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx\n * @param blockCompilation If the shader should not be compiled immediatly. (default: false)\n * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)\n */\n constructor(name, fragmentUrl, parameters, samplers, options, camera, samplingMode = 1, engine, reusable, defines = null, textureType = 0, vertexUrl = \"postprocess\", indexParameters, blockCompilation = false, textureFormat = 5, shaderLanguage = ShaderLanguage.GLSL) {\n /** @internal */\n this._parentContainer = null;\n /**\n * Width of the texture to apply the post process on\n */\n this.width = -1;\n /**\n * Height of the texture to apply the post process on\n */\n this.height = -1;\n /**\n * Gets the node material used to create this postprocess (null if the postprocess was manually created)\n */\n this.nodeMaterialSource = null;\n /**\n * Internal, reference to the location where this postprocess was output to. (Typically the texture on the next postprocess in the chain)\n * @internal\n */\n this._outputTexture = null;\n /**\n * If the buffer needs to be cleared before applying the post process. (default: true)\n * Should be set to false if shader will overwrite all previous pixels.\n */\n this.autoClear = true;\n /**\n * If clearing the buffer should be forced in autoClear mode, even when alpha mode is enabled (default: false).\n * By default, the buffer will only be cleared if alpha mode is disabled (and autoClear is true).\n */\n this.forceAutoClearInAlphaMode = false;\n /**\n * Type of alpha mode to use when performing the post process (default: Engine.ALPHA_DISABLE)\n */\n this.alphaMode = 0;\n /**\n * Animations to be used for the post processing\n */\n this.animations = new Array();\n /**\n * Enable Pixel Perfect mode where texture is not scaled to be power of 2.\n * Can only be used on a single postprocess or on the last one of a chain. (default: false)\n */\n this.enablePixelPerfectMode = false;\n /**\n * Force the postprocess to be applied without taking in account viewport\n */\n this.forceFullscreenViewport = true;\n /**\n * Scale mode for the post process (default: Engine.SCALEMODE_FLOOR)\n *\n * | Value | Type | Description |\n * | ----- | ----------------------------------- | ----------- |\n * | 1 | SCALEMODE_FLOOR | [engine.scalemode_floor](https://doc.babylonjs.com/api/classes/babylon.engine#scalemode_floor) |\n * | 2 | SCALEMODE_NEAREST | [engine.scalemode_nearest](https://doc.babylonjs.com/api/classes/babylon.engine#scalemode_nearest) |\n * | 3 | SCALEMODE_CEILING | [engine.scalemode_ceiling](https://doc.babylonjs.com/api/classes/babylon.engine#scalemode_ceiling) |\n *\n */\n this.scaleMode = 1;\n /**\n * Force textures to be a power of two (default: false)\n */\n this.alwaysForcePOT = false;\n this._samples = 1;\n /**\n * Modify the scale of the post process to be the same as the viewport (default: false)\n */\n this.adaptScaleToCurrentViewport = false;\n this._reusable = false;\n this._renderId = 0;\n /**\n * if externalTextureSamplerBinding is true, the \"apply\" method won't bind the textureSampler texture, it is expected to be done by the \"outside\" (by the onApplyObservable observer most probably).\n * counter-productive in some cases because if the texture bound by \"apply\" is different from the currently texture bound, (the one set by the onApplyObservable observer, for eg) some\n * internal structures (materialContext) will be dirtified, which may impact performances\n */\n this.externalTextureSamplerBinding = false;\n /**\n * Smart array of input and output textures for the post process.\n * @internal\n */\n this._textures = new SmartArray(2);\n /**\n * Smart array of input and output textures for the post process.\n * @internal\n */\n this._textureCache = [];\n /**\n * The index in _textures that corresponds to the output texture.\n * @internal\n */\n this._currentRenderTextureInd = 0;\n this._scaleRatio = new Vector2(1, 1);\n this._texelSize = Vector2.Zero();\n // Events\n /**\n * An event triggered when the postprocess is activated.\n */\n this.onActivateObservable = new Observable$1();\n /**\n * An event triggered when the postprocess changes its size.\n */\n this.onSizeChangedObservable = new Observable$1();\n /**\n * An event triggered when the postprocess applies its effect.\n */\n this.onApplyObservable = new Observable$1();\n /**\n * An event triggered before rendering the postprocess\n */\n this.onBeforeRenderObservable = new Observable$1();\n /**\n * An event triggered after rendering the postprocess\n */\n this.onAfterRenderObservable = new Observable$1();\n this.name = name;\n if (camera != null) {\n this._camera = camera;\n this._scene = camera.getScene();\n camera.attachPostProcess(this);\n this._engine = this._scene.getEngine();\n this._scene.postProcesses.push(this);\n this.uniqueId = this._scene.getUniqueId();\n }\n else if (engine) {\n this._engine = engine;\n this._engine.postProcesses.push(this);\n }\n this._options = options;\n this.renderTargetSamplingMode = samplingMode ? samplingMode : 1;\n this._reusable = reusable || false;\n this._textureType = textureType;\n this._textureFormat = textureFormat;\n this._shaderLanguage = shaderLanguage;\n this._samplers = samplers || [];\n this._samplers.push(\"textureSampler\");\n this._fragmentUrl = fragmentUrl;\n this._vertexUrl = vertexUrl;\n this._parameters = parameters || [];\n this._parameters.push(\"scale\");\n this._indexParameters = indexParameters;\n this._drawWrapper = new DrawWrapper(this._engine);\n if (!blockCompilation) {\n this.updateEffect(defines);\n }\n }\n /**\n * Gets a string identifying the name of the class\n * @returns \"PostProcess\" string\n */\n getClassName() {\n return \"PostProcess\";\n }\n /**\n * Gets the engine which this post process belongs to.\n * @returns The engine the post process was enabled with.\n */\n getEngine() {\n return this._engine;\n }\n /**\n * The effect that is created when initializing the post process.\n * @returns The created effect corresponding the the postprocess.\n */\n getEffect() {\n return this._drawWrapper.effect;\n }\n /**\n * To avoid multiple redundant textures for multiple post process, the output the output texture for this post process can be shared with another.\n * @param postProcess The post process to share the output with.\n * @returns This post process.\n */\n shareOutputWith(postProcess) {\n this._disposeTextures();\n this._shareOutputWithPostProcess = postProcess;\n return this;\n }\n /**\n * Reverses the effect of calling shareOutputWith and returns the post process back to its original state.\n * This should be called if the post process that shares output with this post process is disabled/disposed.\n */\n useOwnOutput() {\n if (this._textures.length == 0) {\n this._textures = new SmartArray(2);\n }\n this._shareOutputWithPostProcess = null;\n }\n /**\n * Updates the effect with the current post process compile time values and recompiles the shader.\n * @param defines Define statements that should be added at the beginning of the shader. (default: null)\n * @param uniforms Set of uniform variables that will be passed to the shader. (default: null)\n * @param samplers Set of Texture2D variables that will be passed to the shader. (default: null)\n * @param indexParameters The index parameters to be used for babylons include syntax \"#include[0..varyingCount]\". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx\n * @param onCompiled Called when the shader has been compiled.\n * @param onError Called if there is an error when compiling a shader.\n * @param vertexUrl The url of the vertex shader to be used (default: the one given at construction time)\n * @param fragmentUrl The url of the fragment shader to be used (default: the one given at construction time)\n */\n updateEffect(defines = null, uniforms = null, samplers = null, indexParameters, onCompiled, onError, vertexUrl, fragmentUrl) {\n var _a, _b;\n const customShaderCodeProcessing = PostProcess._GetShaderCodeProcessing(this.name);\n if (customShaderCodeProcessing === null || customShaderCodeProcessing === void 0 ? void 0 : customShaderCodeProcessing.defineCustomBindings) {\n const newUniforms = (_a = uniforms === null || uniforms === void 0 ? void 0 : uniforms.slice()) !== null && _a !== void 0 ? _a : [];\n newUniforms.push(...this._parameters);\n const newSamplers = (_b = samplers === null || samplers === void 0 ? void 0 : samplers.slice()) !== null && _b !== void 0 ? _b : [];\n newSamplers.push(...this._samplers);\n defines = customShaderCodeProcessing.defineCustomBindings(this.name, defines, newUniforms, newSamplers);\n uniforms = newUniforms;\n samplers = newSamplers;\n }\n this._postProcessDefines = defines;\n this._drawWrapper.effect = this._engine.createEffect({ vertex: vertexUrl !== null && vertexUrl !== void 0 ? vertexUrl : this._vertexUrl, fragment: fragmentUrl !== null && fragmentUrl !== void 0 ? fragmentUrl : this._fragmentUrl }, {\n attributes: [\"position\"],\n uniformsNames: uniforms || this._parameters,\n uniformBuffersNames: [],\n samplers: samplers || this._samplers,\n defines: defines !== null ? defines : \"\",\n fallbacks: null,\n onCompiled: onCompiled !== null && onCompiled !== void 0 ? onCompiled : null,\n onError: onError !== null && onError !== void 0 ? onError : null,\n indexParameters: indexParameters || this._indexParameters,\n processCodeAfterIncludes: (customShaderCodeProcessing === null || customShaderCodeProcessing === void 0 ? void 0 : customShaderCodeProcessing.processCodeAfterIncludes)\n ? (shaderType, code) => customShaderCodeProcessing.processCodeAfterIncludes(this.name, shaderType, code)\n : null,\n processFinalCode: (customShaderCodeProcessing === null || customShaderCodeProcessing === void 0 ? void 0 : customShaderCodeProcessing.processFinalCode)\n ? (shaderType, code) => customShaderCodeProcessing.processFinalCode(this.name, shaderType, code)\n : null,\n shaderLanguage: this._shaderLanguage,\n }, this._engine);\n }\n /**\n * The post process is reusable if it can be used multiple times within one frame.\n * @returns If the post process is reusable\n */\n isReusable() {\n return this._reusable;\n }\n /** invalidate frameBuffer to hint the postprocess to create a depth buffer */\n markTextureDirty() {\n this.width = -1;\n }\n _createRenderTargetTexture(textureSize, textureOptions, channel = 0) {\n for (let i = 0; i < this._textureCache.length; i++) {\n if (this._textureCache[i].texture.width === textureSize.width &&\n this._textureCache[i].texture.height === textureSize.height &&\n this._textureCache[i].postProcessChannel === channel &&\n this._textureCache[i].texture._generateDepthBuffer === textureOptions.generateDepthBuffer &&\n this._textureCache[i].texture.samples === textureOptions.samples) {\n return this._textureCache[i].texture;\n }\n }\n const tex = this._engine.createRenderTargetTexture(textureSize, textureOptions);\n this._textureCache.push({ texture: tex, postProcessChannel: channel, lastUsedRenderId: -1 });\n return tex;\n }\n _flushTextureCache() {\n const currentRenderId = this._renderId;\n for (let i = this._textureCache.length - 1; i >= 0; i--) {\n if (currentRenderId - this._textureCache[i].lastUsedRenderId > 100) {\n let currentlyUsed = false;\n for (let j = 0; j < this._textures.length; j++) {\n if (this._textures.data[j] === this._textureCache[i].texture) {\n currentlyUsed = true;\n break;\n }\n }\n if (!currentlyUsed) {\n this._textureCache[i].texture.dispose();\n this._textureCache.splice(i, 1);\n }\n }\n }\n }\n _resize(width, height, camera, needMipMaps, forceDepthStencil) {\n if (this._textures.length > 0) {\n this._textures.reset();\n }\n this.width = width;\n this.height = height;\n let firstPP = null;\n for (let i = 0; i < camera._postProcesses.length; i++) {\n if (camera._postProcesses[i] !== null) {\n firstPP = camera._postProcesses[i];\n break;\n }\n }\n const textureSize = { width: this.width, height: this.height };\n const textureOptions = {\n generateMipMaps: needMipMaps,\n generateDepthBuffer: forceDepthStencil || firstPP === this,\n generateStencilBuffer: (forceDepthStencil || firstPP === this) && this._engine.isStencilEnable,\n samplingMode: this.renderTargetSamplingMode,\n type: this._textureType,\n format: this._textureFormat,\n samples: this._samples,\n label: \"PostProcessRTT-\" + this.name,\n };\n this._textures.push(this._createRenderTargetTexture(textureSize, textureOptions, 0));\n if (this._reusable) {\n this._textures.push(this._createRenderTargetTexture(textureSize, textureOptions, 1));\n }\n this._texelSize.copyFromFloats(1.0 / this.width, 1.0 / this.height);\n this.onSizeChangedObservable.notifyObservers(this);\n }\n /**\n * Activates the post process by intializing the textures to be used when executed. Notifies onActivateObservable.\n * When this post process is used in a pipeline, this is call will bind the input texture of this post process to the output of the previous.\n * @param camera The camera that will be used in the post process. This camera will be used when calling onActivateObservable.\n * @param sourceTexture The source texture to be inspected to get the width and height if not specified in the post process constructor. (default: null)\n * @param forceDepthStencil If true, a depth and stencil buffer will be generated. (default: false)\n * @returns The render target wrapper that was bound to be written to.\n */\n activate(camera, sourceTexture = null, forceDepthStencil) {\n var _a, _b;\n camera = camera || this._camera;\n const scene = camera.getScene();\n const engine = scene.getEngine();\n const maxSize = engine.getCaps().maxTextureSize;\n let requiredWidth = ((sourceTexture ? sourceTexture.width : this._engine.getRenderWidth(true)) * this._options) | 0;\n const requiredHeight = ((sourceTexture ? sourceTexture.height : this._engine.getRenderHeight(true)) * this._options) | 0;\n // If rendering to a webvr camera's left or right eye only half the width should be used to avoid resize when rendered to screen\n const webVRCamera = camera.parent;\n if (webVRCamera && (webVRCamera.leftCamera == camera || webVRCamera.rightCamera == camera)) {\n requiredWidth /= 2;\n }\n let desiredWidth = this._options.width || requiredWidth;\n let desiredHeight = this._options.height || requiredHeight;\n const needMipMaps = this.renderTargetSamplingMode !== 7 &&\n this.renderTargetSamplingMode !== 1 &&\n this.renderTargetSamplingMode !== 2;\n if (!this._shareOutputWithPostProcess && !this._forcedOutputTexture) {\n if (this.adaptScaleToCurrentViewport) {\n const currentViewport = engine.currentViewport;\n if (currentViewport) {\n desiredWidth *= currentViewport.width;\n desiredHeight *= currentViewport.height;\n }\n }\n if (needMipMaps || this.alwaysForcePOT) {\n if (!this._options.width) {\n desiredWidth = engine.needPOTTextures ? Engine.GetExponentOfTwo(desiredWidth, maxSize, this.scaleMode) : desiredWidth;\n }\n if (!this._options.height) {\n desiredHeight = engine.needPOTTextures ? Engine.GetExponentOfTwo(desiredHeight, maxSize, this.scaleMode) : desiredHeight;\n }\n }\n if (this.width !== desiredWidth || this.height !== desiredHeight) {\n this._resize(desiredWidth, desiredHeight, camera, needMipMaps, forceDepthStencil);\n }\n this._textures.forEach((texture) => {\n if (texture.samples !== this.samples) {\n this._engine.updateRenderTargetTextureSampleCount(texture, this.samples);\n }\n });\n this._flushTextureCache();\n this._renderId++;\n }\n let target;\n if (this._shareOutputWithPostProcess) {\n target = this._shareOutputWithPostProcess.inputTexture;\n }\n else if (this._forcedOutputTexture) {\n target = this._forcedOutputTexture;\n this.width = this._forcedOutputTexture.width;\n this.height = this._forcedOutputTexture.height;\n }\n else {\n target = this.inputTexture;\n let cache;\n for (let i = 0; i < this._textureCache.length; i++) {\n if (this._textureCache[i].texture === target) {\n cache = this._textureCache[i];\n break;\n }\n }\n if (cache) {\n cache.lastUsedRenderId = this._renderId;\n }\n }\n // Bind the input of this post process to be used as the output of the previous post process.\n if (this.enablePixelPerfectMode) {\n this._scaleRatio.copyFromFloats(requiredWidth / desiredWidth, requiredHeight / desiredHeight);\n this._engine.bindFramebuffer(target, 0, requiredWidth, requiredHeight, this.forceFullscreenViewport);\n }\n else {\n this._scaleRatio.copyFromFloats(1, 1);\n this._engine.bindFramebuffer(target, 0, undefined, undefined, this.forceFullscreenViewport);\n }\n (_b = (_a = this._engine)._debugInsertMarker) === null || _b === void 0 ? void 0 : _b.call(_a, `post process ${this.name} input`);\n this.onActivateObservable.notifyObservers(camera);\n // Clear\n if (this.autoClear && (this.alphaMode === 0 || this.forceAutoClearInAlphaMode)) {\n this._engine.clear(this.clearColor ? this.clearColor : scene.clearColor, scene._allowPostProcessClearColor, true, true);\n }\n if (this._reusable) {\n this._currentRenderTextureInd = (this._currentRenderTextureInd + 1) % 2;\n }\n return target;\n }\n /**\n * If the post process is supported.\n */\n get isSupported() {\n return this._drawWrapper.effect.isSupported;\n }\n /**\n * The aspect ratio of the output texture.\n */\n get aspectRatio() {\n if (this._shareOutputWithPostProcess) {\n return this._shareOutputWithPostProcess.aspectRatio;\n }\n if (this._forcedOutputTexture) {\n return this._forcedOutputTexture.width / this._forcedOutputTexture.height;\n }\n return this.width / this.height;\n }\n /**\n * Get a value indicating if the post-process is ready to be used\n * @returns true if the post-process is ready (shader is compiled)\n */\n isReady() {\n var _a, _b;\n return (_b = (_a = this._drawWrapper.effect) === null || _a === void 0 ? void 0 : _a.isReady()) !== null && _b !== void 0 ? _b : false;\n }\n /**\n * Binds all textures and uniforms to the shader, this will be run on every pass.\n * @returns the effect corresponding to this post process. Null if not compiled or not ready.\n */\n apply() {\n var _a, _b, _c;\n // Check\n if (!((_a = this._drawWrapper.effect) === null || _a === void 0 ? void 0 : _a.isReady())) {\n return null;\n }\n // States\n this._engine.enableEffect(this._drawWrapper);\n this._engine.setState(false);\n this._engine.setDepthBuffer(false);\n this._engine.setDepthWrite(false);\n // Alpha\n this._engine.setAlphaMode(this.alphaMode);\n if (this.alphaConstants) {\n this.getEngine().setAlphaConstants(this.alphaConstants.r, this.alphaConstants.g, this.alphaConstants.b, this.alphaConstants.a);\n }\n // Bind the output texture of the preivous post process as the input to this post process.\n let source;\n if (this._shareOutputWithPostProcess) {\n source = this._shareOutputWithPostProcess.inputTexture;\n }\n else if (this._forcedOutputTexture) {\n source = this._forcedOutputTexture;\n }\n else {\n source = this.inputTexture;\n }\n if (!this.externalTextureSamplerBinding) {\n this._drawWrapper.effect._bindTexture(\"textureSampler\", source === null || source === void 0 ? void 0 : source.texture);\n }\n // Parameters\n this._drawWrapper.effect.setVector2(\"scale\", this._scaleRatio);\n this.onApplyObservable.notifyObservers(this._drawWrapper.effect);\n (_c = (_b = PostProcess._GetShaderCodeProcessing(this.name)) === null || _b === void 0 ? void 0 : _b.bindCustomBindings) === null || _c === void 0 ? void 0 : _c.call(_b, this.name, this._drawWrapper.effect);\n return this._drawWrapper.effect;\n }\n _disposeTextures() {\n if (this._shareOutputWithPostProcess || this._forcedOutputTexture) {\n this._disposeTextureCache();\n return;\n }\n this._disposeTextureCache();\n this._textures.dispose();\n }\n _disposeTextureCache() {\n for (let i = this._textureCache.length - 1; i >= 0; i--) {\n this._textureCache[i].texture.dispose();\n }\n this._textureCache.length = 0;\n }\n /**\n * Sets the required values to the prepass renderer.\n * @param prePassRenderer defines the prepass renderer to setup.\n * @returns true if the pre pass is needed.\n */\n setPrePassRenderer(prePassRenderer) {\n if (this._prePassEffectConfiguration) {\n this._prePassEffectConfiguration = prePassRenderer.addEffectConfiguration(this._prePassEffectConfiguration);\n this._prePassEffectConfiguration.enabled = true;\n return true;\n }\n return false;\n }\n /**\n * Disposes the post process.\n * @param camera The camera to dispose the post process on.\n */\n dispose(camera) {\n camera = camera || this._camera;\n this._disposeTextures();\n let index;\n if (this._scene) {\n index = this._scene.postProcesses.indexOf(this);\n if (index !== -1) {\n this._scene.postProcesses.splice(index, 1);\n }\n }\n if (this._parentContainer) {\n const index = this._parentContainer.postProcesses.indexOf(this);\n if (index > -1) {\n this._parentContainer.postProcesses.splice(index, 1);\n }\n this._parentContainer = null;\n }\n index = this._engine.postProcesses.indexOf(this);\n if (index !== -1) {\n this._engine.postProcesses.splice(index, 1);\n }\n if (!camera) {\n return;\n }\n camera.detachPostProcess(this);\n index = camera._postProcesses.indexOf(this);\n if (index === 0 && camera._postProcesses.length > 0) {\n const firstPostProcess = this._camera._getFirstPostProcess();\n if (firstPostProcess) {\n firstPostProcess.markTextureDirty();\n }\n }\n this.onActivateObservable.clear();\n this.onAfterRenderObservable.clear();\n this.onApplyObservable.clear();\n this.onBeforeRenderObservable.clear();\n this.onSizeChangedObservable.clear();\n }\n /**\n * Serializes the post process to a JSON object\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this);\n const camera = this.getCamera() || (this._scene && this._scene.activeCamera);\n serializationObject.customType = \"BABYLON.\" + this.getClassName();\n serializationObject.cameraId = camera ? camera.id : null;\n serializationObject.reusable = this._reusable;\n serializationObject.textureType = this._textureType;\n serializationObject.fragmentUrl = this._fragmentUrl;\n serializationObject.parameters = this._parameters;\n serializationObject.samplers = this._samplers;\n serializationObject.options = this._options;\n serializationObject.defines = this._postProcessDefines;\n serializationObject.textureFormat = this._textureFormat;\n serializationObject.vertexUrl = this._vertexUrl;\n serializationObject.indexParameters = this._indexParameters;\n return serializationObject;\n }\n /**\n * Clones this post process\n * @returns a new post process similar to this one\n */\n clone() {\n const serializationObject = this.serialize();\n serializationObject._engine = this._engine;\n serializationObject.cameraId = null;\n const result = PostProcess.Parse(serializationObject, this._scene, \"\");\n if (!result) {\n return null;\n }\n result.onActivateObservable = this.onActivateObservable.clone();\n result.onSizeChangedObservable = this.onSizeChangedObservable.clone();\n result.onApplyObservable = this.onApplyObservable.clone();\n result.onBeforeRenderObservable = this.onBeforeRenderObservable.clone();\n result.onAfterRenderObservable = this.onAfterRenderObservable.clone();\n result._prePassEffectConfiguration = this._prePassEffectConfiguration;\n return result;\n }\n /**\n * Creates a material from parsed material data\n * @param parsedPostProcess defines parsed post process data\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures\n * @returns a new post process\n */\n static Parse(parsedPostProcess, scene, rootUrl) {\n const postProcessType = GetClass(parsedPostProcess.customType);\n if (!postProcessType || !postProcessType._Parse) {\n return null;\n }\n const camera = scene ? scene.getCameraById(parsedPostProcess.cameraId) : null;\n return postProcessType._Parse(parsedPostProcess, camera, scene, rootUrl);\n }\n /**\n * @internal\n */\n static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {\n return SerializationHelper.Parse(() => {\n return new PostProcess(parsedPostProcess.name, parsedPostProcess.fragmentUrl, parsedPostProcess.parameters, parsedPostProcess.samplers, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, parsedPostProcess._engine, parsedPostProcess.reusable, parsedPostProcess.defines, parsedPostProcess.textureType, parsedPostProcess.vertexUrl, parsedPostProcess.indexParameters, false, parsedPostProcess.textureFormat);\n }, parsedPostProcess, scene, rootUrl);\n }\n }\n PostProcess._CustomShaderCodeProcessing = {};\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"uniqueId\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"name\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"width\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"height\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"renderTargetSamplingMode\", void 0);\n __decorate$1([\n serializeAsColor4()\n ], PostProcess.prototype, \"clearColor\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"autoClear\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"forceAutoClearInAlphaMode\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"alphaMode\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"alphaConstants\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"enablePixelPerfectMode\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"forceFullscreenViewport\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"scaleMode\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"alwaysForcePOT\", void 0);\n __decorate$1([\n serialize(\"samples\")\n ], PostProcess.prototype, \"_samples\", void 0);\n __decorate$1([\n serialize()\n ], PostProcess.prototype, \"adaptScaleToCurrentViewport\", void 0);\n RegisterClass(\"BABYLON.PostProcess\", PostProcess);\n\n // Do not edit.\n const name$10 = \"rgbdDecodePixelShader\";\n const shader$10 = `varying vec2 vUV;uniform sampler2D textureSampler;\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{gl_FragColor=vec4(fromRGBD(texture2D(textureSampler,vUV)),1.0);}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$10] = shader$10;\n\n ThinEngine.prototype.createRenderTargetCubeTexture = function (size, options) {\n const rtWrapper = this._createHardwareRenderTargetWrapper(false, true, size);\n const fullOptions = Object.assign({ generateMipMaps: true, generateDepthBuffer: true, generateStencilBuffer: false, type: 0, samplingMode: 3, format: 5 }, options);\n fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;\n if (fullOptions.type === 1 && !this._caps.textureFloatLinearFiltering) {\n // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE\n fullOptions.samplingMode = 1;\n }\n else if (fullOptions.type === 2 && !this._caps.textureHalfFloatLinearFiltering) {\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\n fullOptions.samplingMode = 1;\n }\n const gl = this._gl;\n const texture = new InternalTexture(this, InternalTextureSource.RenderTarget);\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\n const filters = this._getSamplingParameters(fullOptions.samplingMode, fullOptions.generateMipMaps);\n if (fullOptions.type === 1 && !this._caps.textureFloat) {\n fullOptions.type = 0;\n Logger.Warn(\"Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type\");\n }\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n for (let face = 0; face < 6; face++) {\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), size, size, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);\n }\n // Create the framebuffer\n const framebuffer = gl.createFramebuffer();\n this._bindUnboundFramebuffer(framebuffer);\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(fullOptions.generateStencilBuffer, fullOptions.generateDepthBuffer, size, size);\n // MipMaps\n if (fullOptions.generateMipMaps) {\n gl.generateMipmap(gl.TEXTURE_CUBE_MAP);\n }\n // Unbind\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n this._bindUnboundFramebuffer(null);\n rtWrapper._framebuffer = framebuffer;\n rtWrapper._generateDepthBuffer = fullOptions.generateDepthBuffer;\n rtWrapper._generateStencilBuffer = fullOptions.generateStencilBuffer;\n texture.width = size;\n texture.height = size;\n texture.isReady = true;\n texture.isCube = true;\n texture.samples = 1;\n texture.generateMipMaps = fullOptions.generateMipMaps;\n texture.samplingMode = fullOptions.samplingMode;\n texture.type = fullOptions.type;\n texture.format = fullOptions.format;\n this._internalTexturesCache.push(texture);\n rtWrapper.setTextures(texture);\n return rtWrapper;\n };\n\n // Fullscreen quad buffers by default.\n const defaultOptions = {\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\n indices: [0, 1, 2, 0, 2, 3],\n };\n /**\n * Helper class to render one or more effects.\n * You can access the previous rendering in your shader by declaring a sampler named textureSampler\n */\n class EffectRenderer {\n /**\n * Creates an effect renderer\n * @param engine the engine to use for rendering\n * @param options defines the options of the effect renderer\n */\n constructor(engine, options = defaultOptions) {\n var _a, _b;\n this._fullscreenViewport = new Viewport(0, 0, 1, 1);\n const positions = (_a = options.positions) !== null && _a !== void 0 ? _a : defaultOptions.positions;\n const indices = (_b = options.indices) !== null && _b !== void 0 ? _b : defaultOptions.indices;\n this.engine = engine;\n this._vertexBuffers = {\n [VertexBuffer.PositionKind]: new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false, false, 2),\n };\n this._indexBuffer = engine.createIndexBuffer(indices);\n this._onContextRestoredObserver = engine.onContextRestoredObservable.add(() => {\n this._indexBuffer = engine.createIndexBuffer(indices);\n for (const key in this._vertexBuffers) {\n const vertexBuffer = this._vertexBuffers[key];\n vertexBuffer._rebuild();\n }\n });\n }\n /**\n * Sets the current viewport in normalized coordinates 0-1\n * @param viewport Defines the viewport to set (defaults to 0 0 1 1)\n */\n setViewport(viewport = this._fullscreenViewport) {\n this.engine.setViewport(viewport);\n }\n /**\n * Binds the embedded attributes buffer to the effect.\n * @param effect Defines the effect to bind the attributes for\n */\n bindBuffers(effect) {\n this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\n }\n /**\n * Sets the current effect wrapper to use during draw.\n * The effect needs to be ready before calling this api.\n * This also sets the default full screen position attribute.\n * @param effectWrapper Defines the effect to draw with\n */\n applyEffectWrapper(effectWrapper) {\n this.engine.setState(true);\n this.engine.depthCullingState.depthTest = false;\n this.engine.stencilState.stencilTest = false;\n this.engine.enableEffect(effectWrapper._drawWrapper);\n this.bindBuffers(effectWrapper.effect);\n effectWrapper.onApplyObservable.notifyObservers({});\n }\n /**\n * Saves engine states\n */\n saveStates() {\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\n }\n /**\n * Restores engine states\n */\n restoreStates() {\n this.engine.depthCullingState.depthTest = this._savedStateDepthTest;\n this.engine.stencilState.stencilTest = this._savedStateStencilTest;\n }\n /**\n * Draws a full screen quad.\n */\n draw() {\n this.engine.drawElementsType(0, 0, 6);\n }\n _isRenderTargetTexture(texture) {\n return texture.renderTarget !== undefined;\n }\n /**\n * renders one or more effects to a specified texture\n * @param effectWrapper the effect to renderer\n * @param outputTexture texture to draw to, if null it will render to the screen.\n */\n render(effectWrapper, outputTexture = null) {\n // Ensure effect is ready\n if (!effectWrapper.effect.isReady()) {\n return;\n }\n this.saveStates();\n // Reset state\n this.setViewport();\n const out = outputTexture === null ? null : this._isRenderTargetTexture(outputTexture) ? outputTexture.renderTarget : outputTexture;\n if (out) {\n this.engine.bindFramebuffer(out);\n }\n this.applyEffectWrapper(effectWrapper);\n this.draw();\n if (out) {\n this.engine.unBindFramebuffer(out);\n }\n this.restoreStates();\n }\n /**\n * Disposes of the effect renderer\n */\n dispose() {\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\n if (vertexBuffer) {\n vertexBuffer.dispose();\n delete this._vertexBuffers[VertexBuffer.PositionKind];\n }\n if (this._indexBuffer) {\n this.engine._releaseBuffer(this._indexBuffer);\n }\n if (this._onContextRestoredObserver) {\n this.engine.onContextRestoredObservable.remove(this._onContextRestoredObserver);\n this._onContextRestoredObserver = null;\n }\n }\n }\n /**\n * Wraps an effect to be used for rendering\n */\n class EffectWrapper {\n /**\n * The underlying effect\n */\n get effect() {\n return this._drawWrapper.effect;\n }\n set effect(effect) {\n this._drawWrapper.effect = effect;\n }\n /**\n * Creates an effect to be renderer\n * @param creationOptions options to create the effect\n */\n constructor(creationOptions) {\n /**\n * Event that is fired right before the effect is drawn (should be used to update uniforms)\n */\n this.onApplyObservable = new Observable$1();\n let effectCreationOptions;\n const uniformNames = creationOptions.uniformNames || [];\n if (creationOptions.vertexShader) {\n effectCreationOptions = {\n fragmentSource: creationOptions.fragmentShader,\n vertexSource: creationOptions.vertexShader,\n spectorName: creationOptions.name || \"effectWrapper\",\n };\n }\n else {\n // Default scale to use in post process vertex shader.\n uniformNames.push(\"scale\");\n effectCreationOptions = {\n fragmentSource: creationOptions.fragmentShader,\n vertex: \"postprocess\",\n spectorName: creationOptions.name || \"effectWrapper\",\n };\n // Sets the default scale to identity for the post process vertex shader.\n this.onApplyObservable.add(() => {\n this.effect.setFloat2(\"scale\", 1, 1);\n });\n }\n const defines = creationOptions.defines ? creationOptions.defines.join(\"\\n\") : \"\";\n this._drawWrapper = new DrawWrapper(creationOptions.engine);\n if (creationOptions.useShaderStore) {\n effectCreationOptions.fragment = effectCreationOptions.fragmentSource;\n if (!effectCreationOptions.vertex) {\n effectCreationOptions.vertex = effectCreationOptions.vertexSource;\n }\n delete effectCreationOptions.fragmentSource;\n delete effectCreationOptions.vertexSource;\n this.effect = creationOptions.engine.createEffect(effectCreationOptions, creationOptions.attributeNames || [\"position\"], uniformNames, creationOptions.samplerNames, defines, undefined, creationOptions.onCompiled, undefined, undefined, creationOptions.shaderLanguage);\n }\n else {\n this.effect = new Effect(effectCreationOptions, creationOptions.attributeNames || [\"position\"], uniformNames, creationOptions.samplerNames, creationOptions.engine, defines, undefined, creationOptions.onCompiled, undefined, undefined, undefined, creationOptions.shaderLanguage);\n this._onContextRestoredObserver = creationOptions.engine.onContextRestoredObservable.add(() => {\n this.effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\n this.effect._wasPreviouslyReady = false;\n this.effect._prepareEffect();\n });\n }\n }\n /**\n * Disposes of the effect wrapper\n */\n dispose() {\n if (this._onContextRestoredObserver) {\n this.effect.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\n this._onContextRestoredObserver = null;\n }\n this.effect.dispose();\n }\n }\n\n // Do not edit.\n const name$11 = \"passPixelShader\";\n const shader$11 = `varying vec2 vUV;uniform sampler2D textureSampler;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{gl_FragColor=texture2D(textureSampler,vUV);}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$11] = shader$11;\n /** @internal */\n const passPixelShader = { name: name$11, shader: shader$11 };\n\n /**\n * Class containing a set of static utilities functions to dump data from a canvas\n */\n class DumpTools {\n static _CreateDumpRenderer() {\n if (!DumpTools._DumpToolsEngine) {\n let canvas = new OffscreenCanvas(100, 100); // will be resized later\n let engine = null;\n const options = {\n preserveDrawingBuffer: true,\n depth: false,\n stencil: false,\n alpha: true,\n premultipliedAlpha: false,\n antialias: false,\n failIfMajorPerformanceCaveat: false,\n };\n try {\n engine = new ThinEngine(canvas, false, options);\n }\n catch (e) {\n // The browser does not support WebGL context in OffscreenCanvas, fallback on a regular canvas\n canvas = document.createElement(\"canvas\");\n engine = new ThinEngine(canvas, false, options);\n }\n engine.getCaps().parallelShaderCompile = undefined;\n const renderer = new EffectRenderer(engine);\n const wrapper = new EffectWrapper({\n engine,\n name: passPixelShader.name,\n fragmentShader: passPixelShader.shader,\n samplerNames: [\"textureSampler\"],\n });\n DumpTools._DumpToolsEngine = {\n canvas,\n engine,\n renderer,\n wrapper,\n };\n }\n return DumpTools._DumpToolsEngine;\n }\n /**\n * Dumps the current bound framebuffer\n * @param width defines the rendering width\n * @param height defines the rendering height\n * @param engine defines the hosting engine\n * @param successCallback defines the callback triggered once the data are available\n * @param mimeType defines the mime type of the result\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n * @returns a void promise\n */\n static async DumpFramebuffer(width, height, engine, successCallback, mimeType = \"image/png\", fileName, quality) {\n // Read the contents of the framebuffer\n const bufferView = await engine.readPixels(0, 0, width, height);\n const data = new Uint8Array(bufferView.buffer);\n DumpTools.DumpData(width, height, data, successCallback, mimeType, fileName, true, undefined, quality);\n }\n /**\n * Dumps an array buffer\n * @param width defines the rendering width\n * @param height defines the rendering height\n * @param data the data array\n * @param mimeType defines the mime type of the result\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\n * @param invertY true to invert the picture in the Y dimension\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n * @returns a promise that resolve to the final data\n */\n static DumpDataAsync(width, height, data, mimeType = \"image/png\", fileName, invertY = false, toArrayBuffer = false, quality) {\n return new Promise((resolve) => {\n DumpTools.DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);\n });\n }\n /**\n * Dumps an array buffer\n * @param width defines the rendering width\n * @param height defines the rendering height\n * @param data the data array\n * @param successCallback defines the callback triggered once the data are available\n * @param mimeType defines the mime type of the result\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\n * @param invertY true to invert the picture in the Y dimension\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\n */\n static DumpData(width, height, data, successCallback, mimeType = \"image/png\", fileName, invertY = false, toArrayBuffer = false, quality) {\n const renderer = DumpTools._CreateDumpRenderer();\n renderer.engine.setSize(width, height, true);\n // Convert if data are float32\n if (data instanceof Float32Array) {\n const data2 = new Uint8Array(data.length);\n let n = data.length;\n while (n--) {\n const v = data[n];\n data2[n] = Math.round(Scalar.Clamp(v) * 255);\n }\n data = data2;\n }\n // Create the image\n const texture = renderer.engine.createRawTexture(data, width, height, 5, false, !invertY, 1);\n renderer.renderer.setViewport();\n renderer.renderer.applyEffectWrapper(renderer.wrapper);\n renderer.wrapper.effect._bindTexture(\"textureSampler\", texture);\n renderer.renderer.draw();\n if (toArrayBuffer) {\n Tools.ToBlob(renderer.canvas, (blob) => {\n const fileReader = new FileReader();\n fileReader.onload = (event) => {\n const arrayBuffer = event.target.result;\n if (successCallback) {\n successCallback(arrayBuffer);\n }\n };\n fileReader.readAsArrayBuffer(blob);\n }, mimeType, quality);\n }\n else {\n Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);\n }\n texture.dispose();\n }\n /**\n * Dispose the dump tools associated resources\n */\n static Dispose() {\n if (DumpTools._DumpToolsEngine) {\n DumpTools._DumpToolsEngine.wrapper.dispose();\n DumpTools._DumpToolsEngine.renderer.dispose();\n DumpTools._DumpToolsEngine.engine.dispose();\n }\n DumpTools._DumpToolsEngine = null;\n }\n }\n /**\n * This will be executed automatically for UMD and es5.\n * If esm dev wants the side effects to execute they will have to run it manually\n * Once we build native modules those need to be exported.\n * @internal\n */\n const initSideEffects$1 = () => {\n // References the dependencies.\n Tools.DumpData = DumpTools.DumpData;\n Tools.DumpDataAsync = DumpTools.DumpDataAsync;\n Tools.DumpFramebuffer = DumpTools.DumpFramebuffer;\n };\n initSideEffects$1();\n\n /**\n * This Helps creating a texture that will be created from a camera in your scene.\n * It is basically a dynamic texture that could be used to create special effects for instance.\n * Actually, It is the base of lot of effects in the framework like post process, shadows, effect layers and rendering pipelines...\n */\n class RenderTargetTexture extends Texture {\n /**\n * Use this list to define the list of mesh you want to render.\n */\n get renderList() {\n return this._renderList;\n }\n set renderList(value) {\n if (this._unObserveRenderList) {\n this._unObserveRenderList();\n this._unObserveRenderList = null;\n }\n if (value) {\n this._unObserveRenderList = _ObserveArray(value, this._renderListHasChanged);\n }\n this._renderList = value;\n }\n /**\n * Post-processes for this render target\n */\n get postProcesses() {\n return this._postProcesses;\n }\n get _prePassEnabled() {\n return !!this._prePassRenderTarget && this._prePassRenderTarget.enabled;\n }\n /**\n * Set a after unbind callback in the texture.\n * This has been kept for backward compatibility and use of onAfterUnbindObservable is recommended.\n */\n set onAfterUnbind(callback) {\n if (this._onAfterUnbindObserver) {\n this.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\n }\n this._onAfterUnbindObserver = this.onAfterUnbindObservable.add(callback);\n }\n /**\n * Set a before render callback in the texture.\n * This has been kept for backward compatibility and use of onBeforeRenderObservable is recommended.\n */\n set onBeforeRender(callback) {\n if (this._onBeforeRenderObserver) {\n this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\n }\n this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);\n }\n /**\n * Set a after render callback in the texture.\n * This has been kept for backward compatibility and use of onAfterRenderObservable is recommended.\n */\n set onAfterRender(callback) {\n if (this._onAfterRenderObserver) {\n this.onAfterRenderObservable.remove(this._onAfterRenderObserver);\n }\n this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);\n }\n /**\n * Set a clear callback in the texture.\n * This has been kept for backward compatibility and use of onClearObservable is recommended.\n */\n set onClear(callback) {\n if (this._onClearObserver) {\n this.onClearObservable.remove(this._onClearObserver);\n }\n this._onClearObserver = this.onClearObservable.add(callback);\n }\n /**\n * Gets the render pass ids used by the render target texture. For a single render target the array length will be 1, for a cube texture it will be 6 and for\n * a 2D texture array it will return an array of ids the size of the 2D texture array\n */\n get renderPassIds() {\n return this._renderPassIds;\n }\n /**\n * Gets the current value of the refreshId counter\n */\n get currentRefreshId() {\n return this._currentRefreshId;\n }\n /**\n * Sets a specific material to be used to render a mesh/a list of meshes in this render target texture\n * @param mesh mesh or array of meshes\n * @param material material or array of materials to use for this render pass. If undefined is passed, no specific material will be used but the regular material instead (mesh.material). It's possible to provide an array of materials to use a different material for each rendering in the case of a cube texture (6 rendering) and a 2D texture array (as many rendering as the length of the array)\n */\n setMaterialForRendering(mesh, material) {\n let meshes;\n if (!Array.isArray(mesh)) {\n meshes = [mesh];\n }\n else {\n meshes = mesh;\n }\n for (let j = 0; j < meshes.length; ++j) {\n for (let i = 0; i < this._renderPassIds.length; ++i) {\n meshes[j].setMaterialForRenderPass(this._renderPassIds[i], material !== undefined ? (Array.isArray(material) ? material[i] : material) : undefined);\n }\n }\n }\n /**\n * Define if the texture has multiple draw buffers or if false a single draw buffer.\n */\n get isMulti() {\n var _a, _b;\n return (_b = (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.isMulti) !== null && _b !== void 0 ? _b : false;\n }\n /**\n * Gets render target creation options that were used.\n */\n get renderTargetOptions() {\n return this._renderTargetOptions;\n }\n /**\n * Gets the render target wrapper associated with this render target\n */\n get renderTarget() {\n return this._renderTarget;\n }\n _onRatioRescale() {\n if (this._sizeRatio) {\n this.resize(this._initialSizeParameter);\n }\n }\n /**\n * Gets or sets the size of the bounding box associated with the texture (when in cube mode)\n * When defined, the cubemap will switch to local mode\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\n * @example https://www.babylonjs-playground.com/#RNASML\n */\n set boundingBoxSize(value) {\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\n return;\n }\n this._boundingBoxSize = value;\n const scene = this.getScene();\n if (scene) {\n scene.markAllMaterialsAsDirty(1);\n }\n }\n get boundingBoxSize() {\n return this._boundingBoxSize;\n }\n /**\n * In case the RTT has been created with a depth texture, get the associated\n * depth texture.\n * Otherwise, return null.\n */\n get depthStencilTexture() {\n var _a, _b;\n return (_b = (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a._depthStencilTexture) !== null && _b !== void 0 ? _b : null;\n }\n /** @internal */\n constructor(name, size, scene, generateMipMaps = false, doNotChangeAspectRatio = true, type = 0, isCube = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, generateDepthBuffer = true, generateStencilBuffer = false, isMulti = false, format = 5, delayAllocation = false, samples, creationFlags, noColorAttachment = false, useSRGBBuffer = false) {\n var _a, _b, _c, _d, _e, _f;\n let colorAttachment = undefined;\n if (typeof generateMipMaps === \"object\") {\n const options = generateMipMaps;\n generateMipMaps = !!options.generateMipMaps;\n doNotChangeAspectRatio = (_a = options.doNotChangeAspectRatio) !== null && _a !== void 0 ? _a : true;\n type = (_b = options.type) !== null && _b !== void 0 ? _b : 0;\n isCube = !!options.isCube;\n samplingMode = (_c = options.samplingMode) !== null && _c !== void 0 ? _c : Texture.TRILINEAR_SAMPLINGMODE;\n generateDepthBuffer = (_d = options.generateDepthBuffer) !== null && _d !== void 0 ? _d : true;\n generateStencilBuffer = !!options.generateStencilBuffer;\n isMulti = !!options.isMulti;\n format = (_e = options.format) !== null && _e !== void 0 ? _e : 5;\n delayAllocation = !!options.delayAllocation;\n samples = options.samples;\n creationFlags = options.creationFlags;\n noColorAttachment = !!options.noColorAttachment;\n useSRGBBuffer = !!options.useSRGBBuffer;\n colorAttachment = options.colorAttachment;\n }\n super(null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format);\n this._unObserveRenderList = null;\n this._renderListHasChanged = (_functionName, previousLength) => {\n var _a;\n const newLength = this._renderList ? this._renderList.length : 0;\n if ((previousLength === 0 && newLength > 0) || newLength === 0) {\n (_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.meshes.forEach((mesh) => {\n mesh._markSubMeshesAsLightDirty();\n });\n }\n };\n /**\n * Define if particles should be rendered in your texture.\n */\n this.renderParticles = true;\n /**\n * Define if sprites should be rendered in your texture.\n */\n this.renderSprites = false;\n /**\n * Force checking the layerMask property even if a custom list of meshes is provided (ie. if renderList is not undefined)\n */\n this.forceLayerMaskCheck = false;\n /**\n * Define if the camera viewport should be respected while rendering the texture or if the render should be done to the entire texture.\n */\n this.ignoreCameraViewport = false;\n /**\n * An event triggered when the texture is unbind.\n */\n this.onBeforeBindObservable = new Observable$1();\n /**\n * An event triggered when the texture is unbind.\n */\n this.onAfterUnbindObservable = new Observable$1();\n /**\n * An event triggered before rendering the texture\n */\n this.onBeforeRenderObservable = new Observable$1();\n /**\n * An event triggered after rendering the texture\n */\n this.onAfterRenderObservable = new Observable$1();\n /**\n * An event triggered after the texture clear\n */\n this.onClearObservable = new Observable$1();\n /**\n * An event triggered when the texture is resized.\n */\n this.onResizeObservable = new Observable$1();\n /** @internal */\n this._cleared = false;\n /**\n * Skip the initial clear of the rtt at the beginning of the frame render loop\n */\n this.skipInitialClear = false;\n this._currentRefreshId = -1;\n this._refreshRate = 1;\n this._samples = 1;\n this._canRescale = true;\n this._renderTarget = null;\n /**\n * Gets or sets the center of the bounding box associated with the texture (when in cube mode)\n * It must define where the camera used to render the texture is set\n */\n this.boundingBoxPosition = Vector3.Zero();\n scene = this.getScene();\n if (!scene) {\n return;\n }\n const engine = this.getScene().getEngine();\n this._coordinatesMode = Texture.PROJECTION_MODE;\n this.renderList = new Array();\n this.name = name;\n this.isRenderTarget = true;\n this._initialSizeParameter = size;\n this._renderPassIds = [];\n this._isCubeData = isCube;\n this._processSizeParameter(size);\n this.renderPassId = this._renderPassIds[0];\n this._resizeObserver = engine.onResizeObservable.add(() => { });\n this._generateMipMaps = generateMipMaps ? true : false;\n this._doNotChangeAspectRatio = doNotChangeAspectRatio;\n // Rendering groups\n this._renderingManager = new RenderingManager(scene);\n this._renderingManager._useSceneAutoClearSetup = true;\n if (isMulti) {\n return;\n }\n this._renderTargetOptions = {\n generateMipMaps: generateMipMaps,\n type: type,\n format: (_f = this._format) !== null && _f !== void 0 ? _f : undefined,\n samplingMode: this.samplingMode,\n generateDepthBuffer: generateDepthBuffer,\n generateStencilBuffer: generateStencilBuffer,\n samples,\n creationFlags,\n noColorAttachment: noColorAttachment,\n useSRGBBuffer,\n colorAttachment: colorAttachment,\n label: this.name,\n };\n if (this.samplingMode === Texture.NEAREST_SAMPLINGMODE) {\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\n }\n if (!delayAllocation) {\n if (isCube) {\n this._renderTarget = scene.getEngine().createRenderTargetCubeTexture(this.getRenderSize(), this._renderTargetOptions);\n this.coordinatesMode = Texture.INVCUBIC_MODE;\n this._textureMatrix = Matrix.Identity();\n }\n else {\n this._renderTarget = scene.getEngine().createRenderTargetTexture(this._size, this._renderTargetOptions);\n }\n this._texture = this._renderTarget.texture;\n if (samples !== undefined) {\n this.samples = samples;\n }\n }\n }\n /**\n * Creates a depth stencil texture.\n * This is only available in WebGL 2 or with the depth texture extension available.\n * @param comparisonFunction Specifies the comparison function to set on the texture. If 0 or undefined, the texture is not in comparison mode (default: 0)\n * @param bilinearFiltering Specifies whether or not bilinear filtering is enable on the texture (default: true)\n * @param generateStencil Specifies whether or not a stencil should be allocated in the texture (default: false)\n * @param samples sample count of the depth/stencil texture (default: 1)\n * @param format format of the depth texture (default: 14)\n */\n createDepthStencilTexture(comparisonFunction = 0, bilinearFiltering = true, generateStencil = false, samples = 1, format = 14) {\n var _a;\n (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.createDepthStencilTexture(comparisonFunction, bilinearFiltering, generateStencil, samples, format);\n }\n _releaseRenderPassId() {\n if (this._scene) {\n const engine = this._scene.getEngine();\n for (let i = 0; i < this._renderPassIds.length; ++i) {\n engine.releaseRenderPassId(this._renderPassIds[i]);\n }\n }\n this._renderPassIds = [];\n }\n _createRenderPassId() {\n this._releaseRenderPassId();\n const engine = this._scene.getEngine(); // scene can't be null in a RenderTargetTexture, see constructor\n const numPasses = this._isCubeData ? 6 : this.getRenderLayers() || 1;\n for (let i = 0; i < numPasses; ++i) {\n this._renderPassIds[i] = engine.createRenderPassId(`RenderTargetTexture - ${this.name}#${i}`);\n }\n }\n _processSizeParameter(size, createRenderPassIds = true) {\n if (size.ratio) {\n this._sizeRatio = size.ratio;\n const engine = this._getEngine();\n this._size = {\n width: this._bestReflectionRenderTargetDimension(engine.getRenderWidth(), this._sizeRatio),\n height: this._bestReflectionRenderTargetDimension(engine.getRenderHeight(), this._sizeRatio),\n };\n }\n else {\n this._size = size;\n }\n if (createRenderPassIds) {\n this._createRenderPassId();\n }\n }\n /**\n * Define the number of samples to use in case of MSAA.\n * It defaults to one meaning no MSAA has been enabled.\n */\n get samples() {\n var _a, _b;\n return (_b = (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.samples) !== null && _b !== void 0 ? _b : this._samples;\n }\n set samples(value) {\n if (this._renderTarget) {\n this._samples = this._renderTarget.setSamples(value);\n }\n }\n /**\n * Resets the refresh counter of the texture and start bak from scratch.\n * Could be useful to regenerate the texture if it is setup to render only once.\n */\n resetRefreshCounter() {\n this._currentRefreshId = -1;\n }\n /**\n * Define the refresh rate of the texture or the rendering frequency.\n * Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...\n */\n get refreshRate() {\n return this._refreshRate;\n }\n set refreshRate(value) {\n this._refreshRate = value;\n this.resetRefreshCounter();\n }\n /**\n * Adds a post process to the render target rendering passes.\n * @param postProcess define the post process to add\n */\n addPostProcess(postProcess) {\n if (!this._postProcessManager) {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n this._postProcessManager = new PostProcessManager(scene);\n this._postProcesses = new Array();\n }\n this._postProcesses.push(postProcess);\n this._postProcesses[0].autoClear = false;\n }\n /**\n * Clear all the post processes attached to the render target\n * @param dispose define if the cleared post processes should also be disposed (false by default)\n */\n clearPostProcesses(dispose = false) {\n if (!this._postProcesses) {\n return;\n }\n if (dispose) {\n for (const postProcess of this._postProcesses) {\n postProcess.dispose();\n }\n }\n this._postProcesses = [];\n }\n /**\n * Remove one of the post process from the list of attached post processes to the texture\n * @param postProcess define the post process to remove from the list\n */\n removePostProcess(postProcess) {\n if (!this._postProcesses) {\n return;\n }\n const index = this._postProcesses.indexOf(postProcess);\n if (index === -1) {\n return;\n }\n this._postProcesses.splice(index, 1);\n if (this._postProcesses.length > 0) {\n this._postProcesses[0].autoClear = false;\n }\n }\n /** @internal */\n _shouldRender() {\n if (this._currentRefreshId === -1) {\n // At least render once\n this._currentRefreshId = 1;\n return true;\n }\n if (this.refreshRate === this._currentRefreshId) {\n this._currentRefreshId = 1;\n return true;\n }\n this._currentRefreshId++;\n return false;\n }\n /**\n * Gets the actual render size of the texture.\n * @returns the width of the render size\n */\n getRenderSize() {\n return this.getRenderWidth();\n }\n /**\n * Gets the actual render width of the texture.\n * @returns the width of the render size\n */\n getRenderWidth() {\n if (this._size.width) {\n return this._size.width;\n }\n return this._size;\n }\n /**\n * Gets the actual render height of the texture.\n * @returns the height of the render size\n */\n getRenderHeight() {\n if (this._size.width) {\n return this._size.height;\n }\n return this._size;\n }\n /**\n * Gets the actual number of layers of the texture.\n * @returns the number of layers\n */\n getRenderLayers() {\n const layers = this._size.layers;\n if (layers) {\n return layers;\n }\n return 0;\n }\n /**\n * Don't allow this render target texture to rescale. Mainly used to prevent rescaling by the scene optimizer.\n */\n disableRescaling() {\n this._canRescale = false;\n }\n /**\n * Get if the texture can be rescaled or not.\n */\n get canRescale() {\n return this._canRescale;\n }\n /**\n * Resize the texture using a ratio.\n * @param ratio the ratio to apply to the texture size in order to compute the new target size\n */\n scale(ratio) {\n const newSize = Math.max(1, this.getRenderSize() * ratio);\n this.resize(newSize);\n }\n /**\n * Get the texture reflection matrix used to rotate/transform the reflection.\n * @returns the reflection matrix\n */\n getReflectionTextureMatrix() {\n if (this.isCube) {\n return this._textureMatrix;\n }\n return super.getReflectionTextureMatrix();\n }\n /**\n * Resize the texture to a new desired size.\n * Be careful as it will recreate all the data in the new texture.\n * @param size Define the new size. It can be:\n * - a number for squared texture,\n * - an object containing { width: number, height: number }\n * - or an object containing a ratio { ratio: number }\n */\n resize(size) {\n var _a;\n const wasCube = this.isCube;\n (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.dispose();\n this._renderTarget = null;\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n this._processSizeParameter(size, false);\n if (wasCube) {\n this._renderTarget = scene.getEngine().createRenderTargetCubeTexture(this.getRenderSize(), this._renderTargetOptions);\n }\n else {\n this._renderTarget = scene.getEngine().createRenderTargetTexture(this._size, this._renderTargetOptions);\n }\n this._texture = this._renderTarget.texture;\n if (this._renderTargetOptions.samples !== undefined) {\n this.samples = this._renderTargetOptions.samples;\n }\n if (this.onResizeObservable.hasObservers()) {\n this.onResizeObservable.notifyObservers(this);\n }\n }\n /**\n * Renders all the objects from the render list into the texture.\n * @param useCameraPostProcess Define if camera post processes should be used during the rendering\n * @param dumpForDebug Define if the rendering result should be dumped (copied) for debugging purpose\n */\n render(useCameraPostProcess = false, dumpForDebug = false) {\n this._render(useCameraPostProcess, dumpForDebug);\n }\n /**\n * This function will check if the render target texture can be rendered (textures are loaded, shaders are compiled)\n * @returns true if all required resources are ready\n */\n isReadyForRendering() {\n return this._render(false, false, true);\n }\n _render(useCameraPostProcess = false, dumpForDebug = false, checkReadiness = false) {\n var _a;\n const scene = this.getScene();\n if (!scene) {\n return checkReadiness;\n }\n const engine = scene.getEngine();\n if (this.useCameraPostProcesses !== undefined) {\n useCameraPostProcess = this.useCameraPostProcesses;\n }\n if (this._waitingRenderList) {\n this.renderList = [];\n for (let index = 0; index < this._waitingRenderList.length; index++) {\n const id = this._waitingRenderList[index];\n const mesh = scene.getMeshById(id);\n if (mesh) {\n this.renderList.push(mesh);\n }\n }\n this._waitingRenderList = undefined;\n }\n // Is predicate defined?\n if (this.renderListPredicate) {\n if (this.renderList) {\n this.renderList.length = 0; // Clear previous renderList\n }\n else {\n this.renderList = [];\n }\n const scene = this.getScene();\n if (!scene) {\n return checkReadiness;\n }\n const sceneMeshes = scene.meshes;\n for (let index = 0; index < sceneMeshes.length; index++) {\n const mesh = sceneMeshes[index];\n if (this.renderListPredicate(mesh)) {\n this.renderList.push(mesh);\n }\n }\n }\n const currentRenderPassId = engine.currentRenderPassId;\n this.onBeforeBindObservable.notifyObservers(this);\n // Set custom projection.\n // Needs to be before binding to prevent changing the aspect ratio.\n const camera = (_a = this.activeCamera) !== null && _a !== void 0 ? _a : scene.activeCamera;\n const sceneCamera = scene.activeCamera;\n if (camera) {\n if (camera !== scene.activeCamera) {\n scene.setTransformMatrix(camera.getViewMatrix(), camera.getProjectionMatrix(true));\n scene.activeCamera = camera;\n }\n engine.setViewport(camera.rigParent ? camera.rigParent.viewport : camera.viewport, this.getRenderWidth(), this.getRenderHeight());\n }\n this._defaultRenderListPrepared = false;\n let returnValue = checkReadiness;\n if (!checkReadiness) {\n if (this.is2DArray && !this.isMulti) {\n for (let layer = 0; layer < this.getRenderLayers(); layer++) {\n this._renderToTarget(0, useCameraPostProcess, dumpForDebug, layer, camera);\n scene.incrementRenderId();\n scene.resetCachedMaterial();\n }\n }\n else if (this.isCube && !this.isMulti) {\n for (let face = 0; face < 6; face++) {\n this._renderToTarget(face, useCameraPostProcess, dumpForDebug, undefined, camera);\n scene.incrementRenderId();\n scene.resetCachedMaterial();\n }\n }\n else {\n this._renderToTarget(0, useCameraPostProcess, dumpForDebug, undefined, camera);\n }\n }\n else {\n if (!scene.getViewMatrix()) {\n // We probably didn't execute scene.render() yet, so make sure we have a view/projection matrix setup for the scene\n scene.updateTransformMatrix();\n }\n const numLayers = this.is2DArray ? this.getRenderLayers() : this.isCube ? 6 : 1;\n for (let layer = 0; layer < numLayers && returnValue; layer++) {\n let currentRenderList = null;\n const defaultRenderList = this.renderList ? this.renderList : scene.getActiveMeshes().data;\n const defaultRenderListLength = this.renderList ? this.renderList.length : scene.getActiveMeshes().length;\n engine.currentRenderPassId = this._renderPassIds[layer];\n this.onBeforeRenderObservable.notifyObservers(layer);\n if (this.getCustomRenderList) {\n currentRenderList = this.getCustomRenderList(layer, defaultRenderList, defaultRenderListLength);\n }\n if (!currentRenderList) {\n currentRenderList = defaultRenderList;\n }\n if (!this._doNotChangeAspectRatio) {\n scene.updateTransformMatrix(true);\n }\n for (let i = 0; i < currentRenderList.length && returnValue; ++i) {\n const mesh = currentRenderList[i];\n if (!mesh.isEnabled() || mesh.isBlocked || !mesh.isVisible || !mesh.subMeshes) {\n continue;\n }\n if (this.customIsReadyFunction) {\n if (!this.customIsReadyFunction(mesh, this.refreshRate, checkReadiness)) {\n returnValue = false;\n continue;\n }\n }\n else if (!mesh.isReady(true)) {\n returnValue = false;\n continue;\n }\n }\n this.onAfterRenderObservable.notifyObservers(layer);\n if (this.is2DArray || this.isCube) {\n scene.incrementRenderId();\n scene.resetCachedMaterial();\n }\n }\n }\n this.onAfterUnbindObservable.notifyObservers(this);\n engine.currentRenderPassId = currentRenderPassId;\n if (sceneCamera) {\n scene.activeCamera = sceneCamera;\n // Do not avoid setting uniforms when multiple scenes are active as another camera may have overwrite these\n if (scene.getEngine().scenes.length > 1 || (this.activeCamera && this.activeCamera !== scene.activeCamera)) {\n scene.setTransformMatrix(scene.activeCamera.getViewMatrix(), scene.activeCamera.getProjectionMatrix(true));\n }\n engine.setViewport(scene.activeCamera.viewport);\n }\n scene.resetCachedMaterial();\n return returnValue;\n }\n _bestReflectionRenderTargetDimension(renderDimension, scale) {\n const minimum = 128;\n const x = renderDimension * scale;\n const curved = Engine.NearestPOT(x + (minimum * minimum) / (minimum + x));\n // Ensure we don't exceed the render dimension (while staying POT)\n return Math.min(Engine.FloorPOT(renderDimension), curved);\n }\n _prepareRenderingManager(currentRenderList, currentRenderListLength, camera, checkLayerMask) {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n this._renderingManager.reset();\n const sceneRenderId = scene.getRenderId();\n for (let meshIndex = 0; meshIndex < currentRenderListLength; meshIndex++) {\n const mesh = currentRenderList[meshIndex];\n if (mesh && !mesh.isBlocked) {\n if (this.customIsReadyFunction) {\n if (!this.customIsReadyFunction(mesh, this.refreshRate, false)) {\n this.resetRefreshCounter();\n continue;\n }\n }\n else if (!mesh.isReady(this.refreshRate === 0)) {\n this.resetRefreshCounter();\n continue;\n }\n if (!mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate && scene.activeCamera) {\n mesh._internalAbstractMeshDataInfo._currentLOD = scene.customLODSelector\n ? scene.customLODSelector(mesh, this.activeCamera || scene.activeCamera)\n : mesh.getLOD(this.activeCamera || scene.activeCamera);\n mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate = true;\n }\n if (!mesh._internalAbstractMeshDataInfo._currentLOD) {\n continue;\n }\n let meshToRender = mesh._internalAbstractMeshDataInfo._currentLOD;\n meshToRender._preActivateForIntermediateRendering(sceneRenderId);\n let isMasked;\n if (checkLayerMask && camera) {\n isMasked = (mesh.layerMask & camera.layerMask) === 0;\n }\n else {\n isMasked = false;\n }\n if (mesh.isEnabled() && mesh.isVisible && mesh.subMeshes && !isMasked) {\n if (meshToRender !== mesh) {\n meshToRender._activate(sceneRenderId, true);\n }\n if (mesh._activate(sceneRenderId, true) && mesh.subMeshes.length) {\n if (!mesh.isAnInstance) {\n meshToRender._internalAbstractMeshDataInfo._onlyForInstancesIntermediate = false;\n }\n else {\n if (mesh._internalAbstractMeshDataInfo._actAsRegularMesh) {\n meshToRender = mesh;\n }\n }\n meshToRender._internalAbstractMeshDataInfo._isActiveIntermediate = true;\n for (let subIndex = 0; subIndex < meshToRender.subMeshes.length; subIndex++) {\n const subMesh = meshToRender.subMeshes[subIndex];\n this._renderingManager.dispatch(subMesh, meshToRender);\n }\n }\n }\n }\n }\n for (let particleIndex = 0; particleIndex < scene.particleSystems.length; particleIndex++) {\n const particleSystem = scene.particleSystems[particleIndex];\n const emitter = particleSystem.emitter;\n if (!particleSystem.isStarted() || !emitter || (emitter.position && !emitter.isEnabled())) {\n continue;\n }\n this._renderingManager.dispatchParticles(particleSystem);\n }\n }\n /**\n * @internal\n * @param faceIndex face index to bind to if this is a cubetexture\n * @param layer defines the index of the texture to bind in the array\n */\n _bindFrameBuffer(faceIndex = 0, layer = 0) {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n const engine = scene.getEngine();\n if (this._renderTarget) {\n engine.bindFramebuffer(this._renderTarget, this.isCube ? faceIndex : undefined, undefined, undefined, this.ignoreCameraViewport, 0, layer);\n }\n }\n _unbindFrameBuffer(engine, faceIndex) {\n if (!this._renderTarget) {\n return;\n }\n engine.unBindFramebuffer(this._renderTarget, this.isCube, () => {\n this.onAfterRenderObservable.notifyObservers(faceIndex);\n });\n }\n /**\n * @internal\n */\n _prepareFrame(scene, faceIndex, layer, useCameraPostProcess) {\n if (this._postProcessManager) {\n if (!this._prePassEnabled) {\n this._postProcessManager._prepareFrame(this._texture, this._postProcesses);\n }\n }\n else if (!useCameraPostProcess || !scene.postProcessManager._prepareFrame(this._texture)) {\n this._bindFrameBuffer(faceIndex, layer);\n }\n }\n _renderToTarget(faceIndex, useCameraPostProcess, dumpForDebug, layer = 0, camera = null) {\n var _a, _b, _c, _d, _e, _f;\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n const engine = scene.getEngine();\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, `render to face #${faceIndex} layer #${layer}`, 1);\n // Bind\n this._prepareFrame(scene, faceIndex, layer, useCameraPostProcess);\n if (this.is2DArray) {\n engine.currentRenderPassId = this._renderPassIds[layer];\n this.onBeforeRenderObservable.notifyObservers(layer);\n }\n else {\n engine.currentRenderPassId = this._renderPassIds[faceIndex];\n this.onBeforeRenderObservable.notifyObservers(faceIndex);\n }\n const fastPath = engine.snapshotRendering && engine.snapshotRenderingMode === 1;\n if (!fastPath) {\n // Get the list of meshes to render\n let currentRenderList = null;\n const defaultRenderList = this.renderList ? this.renderList : scene.getActiveMeshes().data;\n const defaultRenderListLength = this.renderList ? this.renderList.length : scene.getActiveMeshes().length;\n if (this.getCustomRenderList) {\n currentRenderList = this.getCustomRenderList(this.is2DArray ? layer : faceIndex, defaultRenderList, defaultRenderListLength);\n }\n if (!currentRenderList) {\n // No custom render list provided, we prepare the rendering for the default list, but check\n // first if we did not already performed the preparation before so as to avoid re-doing it several times\n if (!this._defaultRenderListPrepared) {\n this._prepareRenderingManager(defaultRenderList, defaultRenderListLength, camera, !this.renderList || this.forceLayerMaskCheck);\n this._defaultRenderListPrepared = true;\n }\n currentRenderList = defaultRenderList;\n }\n else {\n // Prepare the rendering for the custom render list provided\n this._prepareRenderingManager(currentRenderList, currentRenderList.length, camera, this.forceLayerMaskCheck);\n }\n // Before clear\n for (const step of scene._beforeRenderTargetClearStage) {\n step.action(this, faceIndex, layer);\n }\n // Clear\n if (this.onClearObservable.hasObservers()) {\n this.onClearObservable.notifyObservers(engine);\n }\n else {\n if (!this.skipInitialClear) {\n engine.clear(this.clearColor || scene.clearColor, true, true, true);\n }\n }\n if (!this._doNotChangeAspectRatio) {\n scene.updateTransformMatrix(true);\n }\n // Before Camera Draw\n for (const step of scene._beforeRenderTargetDrawStage) {\n step.action(this, faceIndex, layer);\n }\n // Render\n this._renderingManager.render(this.customRenderFunction, currentRenderList, this.renderParticles, this.renderSprites);\n // After Camera Draw\n for (const step of scene._afterRenderTargetDrawStage) {\n step.action(this, faceIndex, layer);\n }\n const saveGenerateMipMaps = (_c = (_b = this._texture) === null || _b === void 0 ? void 0 : _b.generateMipMaps) !== null && _c !== void 0 ? _c : false;\n if (this._texture) {\n this._texture.generateMipMaps = false; // if left true, the mipmaps will be generated (if this._texture.generateMipMaps = true) when the first post process binds its own RTT: by doing so it will unbind the current RTT,\n // which will trigger a mipmap generation. We don't want this because it's a wasted work, we will do an unbind of the current RTT at the end of the process (see unbindFrameBuffer) which will\n // trigger the generation of the final mipmaps\n }\n if (this._postProcessManager) {\n this._postProcessManager._finalizeFrame(false, (_d = this._renderTarget) !== null && _d !== void 0 ? _d : undefined, faceIndex, this._postProcesses, this.ignoreCameraViewport);\n }\n else if (useCameraPostProcess) {\n scene.postProcessManager._finalizeFrame(false, (_e = this._renderTarget) !== null && _e !== void 0 ? _e : undefined, faceIndex);\n }\n for (const step of scene._afterRenderTargetPostProcessStage) {\n step.action(this, faceIndex, layer);\n }\n if (this._texture) {\n this._texture.generateMipMaps = saveGenerateMipMaps;\n }\n if (!this._doNotChangeAspectRatio) {\n scene.updateTransformMatrix(true);\n }\n // Dump ?\n if (dumpForDebug) {\n DumpTools.DumpFramebuffer(this.getRenderWidth(), this.getRenderHeight(), engine);\n }\n }\n else {\n // Clear\n if (this.onClearObservable.hasObservers()) {\n this.onClearObservable.notifyObservers(engine);\n }\n else {\n if (!this.skipInitialClear) {\n engine.clear(this.clearColor || scene.clearColor, true, true, true);\n }\n }\n }\n // Unbind\n this._unbindFrameBuffer(engine, faceIndex);\n if (this._texture && this.isCube && faceIndex === 5) {\n engine.generateMipMapsForCubemap(this._texture);\n }\n (_f = engine._debugPopGroup) === null || _f === void 0 ? void 0 : _f.call(engine, 1);\n }\n /**\n * Overrides the default sort function applied in the rendering group to prepare the meshes.\n * This allowed control for front to back rendering or reversely depending of the special needs.\n *\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param opaqueSortCompareFn The opaque queue comparison function use to sort.\n * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.\n * @param transparentSortCompareFn The transparent queue comparison function use to sort.\n */\n setRenderingOrder(renderingGroupId, opaqueSortCompareFn = null, alphaTestSortCompareFn = null, transparentSortCompareFn = null) {\n this._renderingManager.setRenderingOrder(renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn);\n }\n /**\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.\n *\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\n */\n setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil) {\n this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);\n this._renderingManager._useSceneAutoClearSetup = false;\n }\n /**\n * Clones the texture.\n * @returns the cloned texture\n */\n clone() {\n const textureSize = this.getSize();\n const newTexture = new RenderTargetTexture(this.name, textureSize, this.getScene(), this._renderTargetOptions.generateMipMaps, this._doNotChangeAspectRatio, this._renderTargetOptions.type, this.isCube, this._renderTargetOptions.samplingMode, this._renderTargetOptions.generateDepthBuffer, this._renderTargetOptions.generateStencilBuffer, undefined, this._renderTargetOptions.format, undefined, this._renderTargetOptions.samples);\n // Base texture\n newTexture.hasAlpha = this.hasAlpha;\n newTexture.level = this.level;\n // RenderTarget Texture\n newTexture.coordinatesMode = this.coordinatesMode;\n if (this.renderList) {\n newTexture.renderList = this.renderList.slice(0);\n }\n return newTexture;\n }\n /**\n * Serialize the texture to a JSON representation we can easily use in the respective Parse function.\n * @returns The JSON representation of the texture\n */\n serialize() {\n if (!this.name) {\n return null;\n }\n const serializationObject = super.serialize();\n serializationObject.renderTargetSize = this.getRenderSize();\n serializationObject.renderList = [];\n if (this.renderList) {\n for (let index = 0; index < this.renderList.length; index++) {\n serializationObject.renderList.push(this.renderList[index].id);\n }\n }\n return serializationObject;\n }\n /**\n * This will remove the attached framebuffer objects. The texture will not be able to be used as render target anymore\n */\n disposeFramebufferObjects() {\n var _a;\n (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.dispose(true);\n }\n /**\n * Release and destroy the underlying lower level texture aka internalTexture.\n */\n releaseInternalTexture() {\n var _a;\n (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.releaseTextures();\n this._texture = null;\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n var _a;\n this.onResizeObservable.clear();\n this.onClearObservable.clear();\n this.onAfterRenderObservable.clear();\n this.onAfterUnbindObservable.clear();\n this.onBeforeBindObservable.clear();\n this.onBeforeRenderObservable.clear();\n if (this._postProcessManager) {\n this._postProcessManager.dispose();\n this._postProcessManager = null;\n }\n if (this._prePassRenderTarget) {\n this._prePassRenderTarget.dispose();\n }\n this._releaseRenderPassId();\n this.clearPostProcesses(true);\n if (this._resizeObserver) {\n this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver);\n this._resizeObserver = null;\n }\n this.renderList = null;\n // Remove from custom render targets\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n let index = scene.customRenderTargets.indexOf(this);\n if (index >= 0) {\n scene.customRenderTargets.splice(index, 1);\n }\n for (const camera of scene.cameras) {\n index = camera.customRenderTargets.indexOf(this);\n if (index >= 0) {\n camera.customRenderTargets.splice(index, 1);\n }\n }\n (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.dispose();\n this._renderTarget = null;\n this._texture = null;\n super.dispose();\n }\n /** @internal */\n _rebuild() {\n if (this.refreshRate === RenderTargetTexture.REFRESHRATE_RENDER_ONCE) {\n this.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;\n }\n if (this._postProcessManager) {\n this._postProcessManager._rebuild();\n }\n }\n /**\n * Clear the info related to rendering groups preventing retention point in material dispose.\n */\n freeRenderingGroups() {\n if (this._renderingManager) {\n this._renderingManager.freeRenderingGroups();\n }\n }\n /**\n * Gets the number of views the corresponding to the texture (eg. a MultiviewRenderTarget will have > 1)\n * @returns the view count\n */\n getViewCount() {\n return 1;\n }\n }\n /**\n * The texture will only be rendered once which can be useful to improve performance if everything in your render is static for instance.\n */\n RenderTargetTexture.REFRESHRATE_RENDER_ONCE = 0;\n /**\n * The texture will only be rendered rendered every frame and is recommended for dynamic contents.\n */\n RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME = 1;\n /**\n * The texture will be rendered every 2 frames which could be enough if your dynamic objects are not\n * the central point of your effect and can save a lot of performances.\n */\n RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYTWOFRAMES = 2;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Texture._CreateRenderTargetTexture = (name, renderTargetSize, scene, generateMipMaps, creationFlags) => {\n return new RenderTargetTexture(name, renderTargetSize, scene, generateMipMaps);\n };\n\n // Do not edit.\n const name$12 = \"passCubePixelShader\";\n const shader$12 = `varying vec2 vUV;uniform samplerCube textureSampler;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{vec2 uv=vUV*2.0-1.0;\n#ifdef POSITIVEX\ngl_FragColor=textureCube(textureSampler,vec3(1.001,uv.y,uv.x));\n#endif\n#ifdef NEGATIVEX\ngl_FragColor=textureCube(textureSampler,vec3(-1.001,uv.y,uv.x));\n#endif\n#ifdef POSITIVEY\ngl_FragColor=textureCube(textureSampler,vec3(uv.y,1.001,uv.x));\n#endif\n#ifdef NEGATIVEY\ngl_FragColor=textureCube(textureSampler,vec3(uv.y,-1.001,uv.x));\n#endif\n#ifdef POSITIVEZ\ngl_FragColor=textureCube(textureSampler,vec3(uv,1.001));\n#endif\n#ifdef NEGATIVEZ\ngl_FragColor=textureCube(textureSampler,vec3(uv,-1.001));\n#endif\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$12] = shader$12;\n\n /**\n * PassPostProcess which produces an output the same as it's input\n */\n class PassPostProcess extends PostProcess {\n /**\n * Gets a string identifying the name of the class\n * @returns \"PassPostProcess\" string\n */\n getClassName() {\n return \"PassPostProcess\";\n }\n /**\n * Creates the PassPostProcess\n * @param name The name of the effect.\n * @param options The required width/height ratio to downsize to before computing the render pass.\n * @param camera The camera to apply the render pass to.\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\n * @param engine The engine which the post process will be applied. (default: current engine)\n * @param reusable If the post process can be reused on the same frame. (default: false)\n * @param textureType The type of texture to be used when performing the post processing.\n * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)\n */\n constructor(name, options, camera = null, samplingMode, engine, reusable, textureType = 0, blockCompilation = false) {\n super(name, \"pass\", null, null, options, camera, samplingMode, engine, reusable, undefined, textureType, undefined, null, blockCompilation);\n }\n /**\n * @internal\n */\n static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {\n return SerializationHelper.Parse(() => {\n return new PassPostProcess(parsedPostProcess.name, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, parsedPostProcess._engine, parsedPostProcess.reusable);\n }, parsedPostProcess, scene, rootUrl);\n }\n }\n RegisterClass(\"BABYLON.PassPostProcess\", PassPostProcess);\n Engine._RescalePostProcessFactory = (engine) => {\n return new PassPostProcess(\"rescale\", 1, null, 2, engine, false, 0);\n };\n\n /**\n * Uses the GPU to create a copy texture rescaled at a given size\n * @param texture Texture to copy from\n * @param width defines the desired width\n * @param height defines the desired height\n * @param useBilinearMode defines if bilinear mode has to be used\n * @returns the generated texture\n */\n function CreateResizedCopy(texture, width, height, useBilinearMode = true) {\n const scene = texture.getScene();\n const engine = scene.getEngine();\n const rtt = new RenderTargetTexture(\"resized\" + texture.name, { width: width, height: height }, scene, !texture.noMipmap, true, texture._texture.type, false, texture.samplingMode, false);\n rtt.wrapU = texture.wrapU;\n rtt.wrapV = texture.wrapV;\n rtt.uOffset = texture.uOffset;\n rtt.vOffset = texture.vOffset;\n rtt.uScale = texture.uScale;\n rtt.vScale = texture.vScale;\n rtt.uAng = texture.uAng;\n rtt.vAng = texture.vAng;\n rtt.wAng = texture.wAng;\n rtt.coordinatesIndex = texture.coordinatesIndex;\n rtt.level = texture.level;\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\n rtt._texture.isReady = false;\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\n const passPostProcess = new PassPostProcess(\"pass\", 1, null, useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE, engine, false, 0);\n passPostProcess.externalTextureSamplerBinding = true;\n passPostProcess.getEffect().executeWhenCompiled(() => {\n passPostProcess.onApply = function (effect) {\n effect.setTexture(\"textureSampler\", texture);\n };\n const internalTexture = rtt.renderTarget;\n if (internalTexture) {\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\n engine.unBindFramebuffer(internalTexture);\n rtt.disposeFramebufferObjects();\n passPostProcess.dispose();\n rtt.getInternalTexture().isReady = true;\n }\n });\n return rtt;\n }\n /**\n * Apply a post process to a texture\n * @param postProcessName name of the fragment post process\n * @param internalTexture the texture to encode\n * @param scene the scene hosting the texture\n * @param type type of the output texture. If not provided, use the one from internalTexture\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\n * @param format format of the output texture. If not provided, use the one from internalTexture\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\n */\n function ApplyPostProcess(postProcessName, internalTexture, scene, type, samplingMode, format, width, height) {\n // Gets everything ready.\n const engine = internalTexture.getEngine();\n internalTexture.isReady = false;\n samplingMode = samplingMode !== null && samplingMode !== void 0 ? samplingMode : internalTexture.samplingMode;\n type = type !== null && type !== void 0 ? type : internalTexture.type;\n format = format !== null && format !== void 0 ? format : internalTexture.format;\n width = width !== null && width !== void 0 ? width : internalTexture.width;\n height = height !== null && height !== void 0 ? height : internalTexture.height;\n if (type === -1) {\n type = 0;\n }\n return new Promise((resolve) => {\n // Create the post process\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\n postProcess.externalTextureSamplerBinding = true;\n // Hold the output of the decoding.\n const encodedTexture = engine.createRenderTargetTexture({ width: width, height: height }, {\n generateDepthBuffer: false,\n generateMipMaps: false,\n generateStencilBuffer: false,\n samplingMode,\n type,\n format,\n });\n postProcess.getEffect().executeWhenCompiled(() => {\n // PP Render Pass\n postProcess.onApply = (effect) => {\n effect._bindTexture(\"textureSampler\", internalTexture);\n effect.setFloat2(\"scale\", 1, 1);\n };\n scene.postProcessManager.directRender([postProcess], encodedTexture, true);\n // Cleanup\n engine.restoreDefaultFramebuffer();\n engine._releaseTexture(internalTexture);\n if (postProcess) {\n postProcess.dispose();\n }\n // Internal Swap\n encodedTexture._swapAndDie(internalTexture);\n // Ready to get rolling again.\n internalTexture.type = type;\n internalTexture.format = 5;\n internalTexture.isReady = true;\n resolve(internalTexture);\n });\n });\n }\n // ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\n let floatView;\n let int32View;\n /**\n * Converts a number to half float\n * @param value number to convert\n * @returns converted number\n */\n function ToHalfFloat(value) {\n if (!floatView) {\n floatView = new Float32Array(1);\n int32View = new Int32Array(floatView.buffer);\n }\n floatView[0] = value;\n const x = int32View[0];\n let bits = (x >> 16) & 0x8000; /* Get the sign */\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\n const e = (x >> 23) & 0xff; /* Using int is faster here */\n /* If zero, or denormal, or exponent underflows too much for a denormal\n * half, return signed zero. */\n if (e < 103) {\n return bits;\n }\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\n if (e > 142) {\n bits |= 0x7c00;\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\n * not Inf, so make sure we set one mantissa bit too. */\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\n return bits;\n }\n /* If exponent underflows but not too much, return a denormal */\n if (e < 113) {\n m |= 0x0800;\n /* Extra rounding may overflow and set mantissa to 0 and exponent\n * to 1, which is OK. */\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\n return bits;\n }\n bits |= ((e - 112) << 10) | (m >> 1);\n bits += m & 1;\n return bits;\n }\n /**\n * Converts a half float to a number\n * @param value half float to convert\n * @returns converted half float\n */\n function FromHalfFloat(value) {\n const s = (value & 0x8000) >> 15;\n const e = (value & 0x7c00) >> 10;\n const f = value & 0x03ff;\n if (e === 0) {\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\n }\n else if (e == 0x1f) {\n return f ? NaN : (s ? -1 : 1) * Infinity;\n }\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\n }\n /**\n * Class used to host texture specific utilities\n */\n const TextureTools = {\n /**\n * Uses the GPU to create a copy texture rescaled at a given size\n * @param texture Texture to copy from\n * @param width defines the desired width\n * @param height defines the desired height\n * @param useBilinearMode defines if bilinear mode has to be used\n * @returns the generated texture\n */\n CreateResizedCopy,\n /**\n * Apply a post process to a texture\n * @param postProcessName name of the fragment post process\n * @param internalTexture the texture to encode\n * @param scene the scene hosting the texture\n * @param type type of the output texture. If not provided, use the one from internalTexture\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\n * @param format format of the output texture. If not provided, use the one from internalTexture\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\n */\n ApplyPostProcess,\n /**\n * Converts a number to half float\n * @param value number to convert\n * @returns converted number\n */\n ToHalfFloat,\n /**\n * Converts a half float to a number\n * @param value half float to convert\n * @returns converted half float\n */\n FromHalfFloat,\n };\n\n /**\n * Class used to host RGBD texture specific utilities\n */\n class RGBDTextureTools {\n /**\n * Expand the RGBD Texture from RGBD to Half Float if possible.\n * @param texture the texture to expand.\n */\n static ExpandRGBDTexture(texture) {\n const internalTexture = texture._texture;\n if (!internalTexture || !texture.isRGBD) {\n return;\n }\n // Gets everything ready.\n const engine = internalTexture.getEngine();\n const caps = engine.getCaps();\n const isReady = internalTexture.isReady;\n let expandTexture = false;\n // If half float available we can uncompress the texture\n if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\n expandTexture = true;\n internalTexture.type = 2;\n }\n // If full float available we can uncompress the texture\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\n expandTexture = true;\n internalTexture.type = 1;\n }\n if (expandTexture) {\n // Do not use during decode.\n internalTexture.isReady = false;\n internalTexture._isRGBD = false;\n internalTexture.invertY = false;\n }\n const expandRGBDTexture = () => {\n // Expand the texture if possible\n if (expandTexture) {\n // Simply run through the decode PP.\n const rgbdPostProcess = new PostProcess(\"rgbdDecode\", \"rgbdDecode\", null, null, 1, null, 3, engine, false, undefined, internalTexture.type, undefined, null, false);\n rgbdPostProcess.externalTextureSamplerBinding = true;\n // Hold the output of the decoding.\n const expandedTexture = engine.createRenderTargetTexture(internalTexture.width, {\n generateDepthBuffer: false,\n generateMipMaps: false,\n generateStencilBuffer: false,\n samplingMode: internalTexture.samplingMode,\n type: internalTexture.type,\n format: 5,\n });\n rgbdPostProcess.getEffect().executeWhenCompiled(() => {\n // PP Render Pass\n rgbdPostProcess.onApply = (effect) => {\n effect._bindTexture(\"textureSampler\", internalTexture);\n effect.setFloat2(\"scale\", 1, 1);\n };\n texture.getScene().postProcessManager.directRender([rgbdPostProcess], expandedTexture, true);\n // Cleanup\n engine.restoreDefaultFramebuffer();\n engine._releaseTexture(internalTexture);\n if (rgbdPostProcess) {\n rgbdPostProcess.dispose();\n }\n // Internal Swap\n expandedTexture._swapAndDie(internalTexture);\n // Ready to get rolling again.\n internalTexture.isReady = true;\n });\n }\n };\n if (isReady) {\n expandRGBDTexture();\n }\n else {\n texture.onLoadObservable.addOnce(expandRGBDTexture);\n }\n }\n /**\n * Encode the texture to RGBD if possible.\n * @param internalTexture the texture to encode\n * @param scene the scene hosting the texture\n * @param outputTextureType type of the texture in which the encoding is performed\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\n */\n static EncodeTextureToRGBD(internalTexture, scene, outputTextureType = 0) {\n return ApplyPostProcess(\"rgbdEncode\", internalTexture, scene, outputTextureType, 1, 5);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const _environmentBRDFBase64Texture = \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAgAElEQ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WiXwDYPoJyYuCD238ulvuzwt6KgHf0shWKsqCFFGjB/w8HU8eeTED9wAAAAABJRU5ErkJggg==\";\n let _instanceNumber = 0;\n /**\n * Gets a default environment BRDF for MS-BRDF Height Correlated BRDF\n * @param scene defines the hosting scene\n * @returns the environment BRDF texture\n */\n const GetEnvironmentBRDFTexture = (scene) => {\n if (!scene.environmentBRDFTexture) {\n // Forces Delayed Texture Loading to prevent undefined error whilst setting RGBD values.\n const useDelayedTextureLoading = scene.useDelayedTextureLoading;\n scene.useDelayedTextureLoading = false;\n const previousState = scene._blockEntityCollection;\n scene._blockEntityCollection = false;\n const texture = Texture.CreateFromBase64String(_environmentBRDFBase64Texture, \"EnvironmentBRDFTexture\" + _instanceNumber++, scene, true, false, Texture.BILINEAR_SAMPLINGMODE);\n scene._blockEntityCollection = previousState;\n // BRDF Texture should not be cached here due to pre processing and redundant scene caches.\n const texturesCache = scene.getEngine().getLoadedTexturesCache();\n const index = texturesCache.indexOf(texture.getInternalTexture());\n if (index !== -1) {\n texturesCache.splice(index, 1);\n }\n texture.isRGBD = true;\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\n scene.environmentBRDFTexture = texture;\n scene.useDelayedTextureLoading = useDelayedTextureLoading;\n RGBDTextureTools.ExpandRGBDTexture(texture);\n const observer = scene.getEngine().onContextRestoredObservable.add(() => {\n texture.isRGBD = true;\n const checkReady = () => {\n if (texture.isReady()) {\n RGBDTextureTools.ExpandRGBDTexture(texture);\n }\n else {\n Tools.SetImmediate(checkReady);\n }\n };\n checkReady();\n });\n scene.onDisposeObservable.add(() => {\n scene.getEngine().onContextRestoredObservable.remove(observer);\n });\n }\n return scene.environmentBRDFTexture;\n };\n\n /**\n * @internal\n */\n class MaterialBRDFDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.BRDF_V_HEIGHT_CORRELATED = false;\n this.MS_BRDF_ENERGY_CONSERVATION = false;\n this.SPHERICAL_HARMONICS = false;\n this.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = false;\n }\n }\n /**\n * Plugin that implements the BRDF component of the PBR material\n */\n class PBRBRDFConfiguration extends MaterialPluginBase {\n /** @internal */\n _markAllSubMeshesAsMiscDirty() {\n this._internalMarkAllSubMeshesAsMiscDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"PBRBRDF\", 90, new MaterialBRDFDefines(), addToPluginList);\n this._useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;\n /**\n * Defines if the material uses energy conservation.\n */\n this.useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;\n this._useSmithVisibilityHeightCorrelated = PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED;\n /**\n * LEGACY Mode set to false\n * Defines if the material uses height smith correlated visibility term.\n * If you intent to not use our default BRDF, you need to load a separate BRDF Texture for the PBR\n * You can either load https://assets.babylonjs.com/environments/uncorrelatedBRDF.png\n * or https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds to have more precision\n * Not relying on height correlated will also disable energy conservation.\n */\n this.useSmithVisibilityHeightCorrelated = PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED;\n this._useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;\n /**\n * LEGACY Mode set to false\n * Defines if the material uses spherical harmonics vs spherical polynomials for the\n * diffuse part of the IBL.\n * The harmonics despite a tiny bigger cost has been proven to provide closer results\n * to the ground truth.\n */\n this.useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;\n this._useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;\n /**\n * Defines if the material uses energy conservation, when the specular workflow is active.\n * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).\n * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.\n * In the deactivated case, the material author has to ensure energy conservation, for a physically plausible rendering.\n */\n this.useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;\n this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[16];\n this._enable(true);\n }\n prepareDefines(defines) {\n defines.BRDF_V_HEIGHT_CORRELATED = this._useSmithVisibilityHeightCorrelated;\n defines.MS_BRDF_ENERGY_CONSERVATION = this._useEnergyConservation && this._useSmithVisibilityHeightCorrelated;\n defines.SPHERICAL_HARMONICS = this._useSphericalHarmonics;\n defines.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = this._useSpecularGlossinessInputEnergyConservation;\n }\n getClassName() {\n return \"PBRBRDFConfiguration\";\n }\n }\n /**\n * Default value used for the energy conservation.\n * This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.\n */\n PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION = true;\n /**\n * Default value used for the Smith Visibility Height Correlated mode.\n * This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.\n */\n PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED = true;\n /**\n * Default value used for the IBL diffuse part.\n * This can help switching back to the polynomials mode globally which is a tiny bit\n * less GPU intensive at the drawback of a lower quality.\n */\n PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS = true;\n /**\n * Default value used for activating energy conservation for the specular workflow.\n * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).\n * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.\n */\n PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION = true;\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRBRDFConfiguration.prototype, \"useEnergyConservation\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRBRDFConfiguration.prototype, \"useSmithVisibilityHeightCorrelated\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRBRDFConfiguration.prototype, \"useSphericalHarmonics\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRBRDFConfiguration.prototype, \"useSpecularGlossinessInputEnergyConservation\", void 0);\n\n class FileFaceOrientation {\n constructor(name, worldAxisForNormal, worldAxisForFileX, worldAxisForFileY) {\n this.name = name;\n this.worldAxisForNormal = worldAxisForNormal;\n this.worldAxisForFileX = worldAxisForFileX;\n this.worldAxisForFileY = worldAxisForFileY;\n }\n }\n /**\n * Helper class dealing with the extraction of spherical polynomial dataArray\n * from a cube map.\n */\n class CubeMapToSphericalPolynomialTools {\n /**\n * Converts a texture to the according Spherical Polynomial data.\n * This extracts the first 3 orders only as they are the only one used in the lighting.\n *\n * @param texture The texture to extract the information from.\n * @returns The Spherical Polynomial data.\n */\n static ConvertCubeMapTextureToSphericalPolynomial(texture) {\n var _a;\n if (!texture.isCube) {\n // Only supports cube Textures currently.\n return null;\n }\n (_a = texture.getScene()) === null || _a === void 0 ? void 0 : _a.getEngine().flushFramebuffer();\n const size = texture.getSize().width;\n const rightPromise = texture.readPixels(0, undefined, undefined, false);\n const leftPromise = texture.readPixels(1, undefined, undefined, false);\n let upPromise;\n let downPromise;\n if (texture.isRenderTarget) {\n upPromise = texture.readPixels(3, undefined, undefined, false);\n downPromise = texture.readPixels(2, undefined, undefined, false);\n }\n else {\n upPromise = texture.readPixels(2, undefined, undefined, false);\n downPromise = texture.readPixels(3, undefined, undefined, false);\n }\n const frontPromise = texture.readPixels(4, undefined, undefined, false);\n const backPromise = texture.readPixels(5, undefined, undefined, false);\n const gammaSpace = texture.gammaSpace;\n // Always read as RGBA.\n const format = 5;\n let type = 0;\n if (texture.textureType == 1 || texture.textureType == 2) {\n type = 1;\n }\n return new Promise((resolve) => {\n Promise.all([leftPromise, rightPromise, upPromise, downPromise, frontPromise, backPromise]).then(([left, right, up, down, front, back]) => {\n const cubeInfo = {\n size,\n right,\n left,\n up,\n down,\n front,\n back,\n format,\n type,\n gammaSpace,\n };\n resolve(this.ConvertCubeMapToSphericalPolynomial(cubeInfo));\n });\n });\n }\n /**\n * Compute the area on the unit sphere of the rectangle defined by (x,y) and the origin\n * See https://www.rorydriscoll.com/2012/01/15/cubemap-texel-solid-angle/\n * @param x\n * @param y\n */\n static _AreaElement(x, y) {\n return Math.atan2(x * y, Math.sqrt(x * x + y * y + 1));\n }\n /**\n * Converts a cubemap to the according Spherical Polynomial data.\n * This extracts the first 3 orders only as they are the only one used in the lighting.\n *\n * @param cubeInfo The Cube map to extract the information from.\n * @returns The Spherical Polynomial data.\n */\n static ConvertCubeMapToSphericalPolynomial(cubeInfo) {\n const sphericalHarmonics = new SphericalHarmonics();\n let totalSolidAngle = 0.0;\n // The (u,v) range is [-1,+1], so the distance between each texel is 2/Size.\n const du = 2.0 / cubeInfo.size;\n const dv = du;\n const halfTexel = 0.5 * du;\n // The (u,v) of the first texel is half a texel from the corner (-1,-1).\n const minUV = halfTexel - 1.0;\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\n const fileFace = this._FileFaces[faceIndex];\n const dataArray = cubeInfo[fileFace.name];\n let v = minUV;\n // TODO: we could perform the summation directly into a SphericalPolynomial (SP), which is more efficient than SphericalHarmonic (SH).\n // This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.\n // Because SP is still linear, so summation is fine in that basis.\n const stride = cubeInfo.format === 5 ? 4 : 3;\n for (let y = 0; y < cubeInfo.size; y++) {\n let u = minUV;\n for (let x = 0; x < cubeInfo.size; x++) {\n // World direction (not normalised)\n const worldDirection = fileFace.worldAxisForFileX.scale(u).add(fileFace.worldAxisForFileY.scale(v)).add(fileFace.worldAxisForNormal);\n worldDirection.normalize();\n const deltaSolidAngle = this._AreaElement(u - halfTexel, v - halfTexel) -\n this._AreaElement(u - halfTexel, v + halfTexel) -\n this._AreaElement(u + halfTexel, v - halfTexel) +\n this._AreaElement(u + halfTexel, v + halfTexel);\n let r = dataArray[y * cubeInfo.size * stride + x * stride + 0];\n let g = dataArray[y * cubeInfo.size * stride + x * stride + 1];\n let b = dataArray[y * cubeInfo.size * stride + x * stride + 2];\n // Prevent NaN harmonics with extreme HDRI data.\n if (isNaN(r)) {\n r = 0;\n }\n if (isNaN(g)) {\n g = 0;\n }\n if (isNaN(b)) {\n b = 0;\n }\n // Handle Integer types.\n if (cubeInfo.type === 0) {\n r /= 255;\n g /= 255;\n b /= 255;\n }\n // Handle Gamma space textures.\n if (cubeInfo.gammaSpace) {\n r = Math.pow(Scalar.Clamp(r), ToLinearSpace);\n g = Math.pow(Scalar.Clamp(g), ToLinearSpace);\n b = Math.pow(Scalar.Clamp(b), ToLinearSpace);\n }\n // Prevent to explode in case of really high dynamic ranges.\n // sh 3 would not be enough to accurately represent it.\n const max = this.MAX_HDRI_VALUE;\n if (this.PRESERVE_CLAMPED_COLORS) {\n const currentMax = Math.max(r, g, b);\n if (currentMax > max) {\n const factor = max / currentMax;\n r *= factor;\n g *= factor;\n b *= factor;\n }\n }\n else {\n r = Scalar.Clamp(r, 0, max);\n g = Scalar.Clamp(g, 0, max);\n b = Scalar.Clamp(b, 0, max);\n }\n const color = new Color3(r, g, b);\n sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);\n totalSolidAngle += deltaSolidAngle;\n u += du;\n }\n v += dv;\n }\n }\n // Solid angle for entire sphere is 4*pi\n const sphereSolidAngle = 4.0 * Math.PI;\n // Adjust the solid angle to allow for how many faces we processed.\n const facesProcessed = 6.0;\n const expectedSolidAngle = (sphereSolidAngle * facesProcessed) / 6.0;\n // Adjust the harmonics so that the accumulated solid angle matches the expected solid angle.\n // This is needed because the numerical integration over the cube uses a\n // small angle approximation of solid angle for each texel (see deltaSolidAngle),\n // and also to compensate for accumulative error due to float precision in the summation.\n const correctionFactor = expectedSolidAngle / totalSolidAngle;\n sphericalHarmonics.scaleInPlace(correctionFactor);\n sphericalHarmonics.convertIncidentRadianceToIrradiance();\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\n return SphericalPolynomial.FromHarmonics(sphericalHarmonics);\n }\n }\n CubeMapToSphericalPolynomialTools._FileFaces = [\n new FileFaceOrientation(\"right\", new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)),\n new FileFaceOrientation(\"left\", new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, -1, 0)),\n new FileFaceOrientation(\"up\", new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)),\n new FileFaceOrientation(\"down\", new Vector3(0, -1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1)),\n new FileFaceOrientation(\"front\", new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0)),\n new FileFaceOrientation(\"back\", new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0)), // -Z bottom\n ];\n /** @internal */\n CubeMapToSphericalPolynomialTools.MAX_HDRI_VALUE = 4096;\n /** @internal */\n CubeMapToSphericalPolynomialTools.PRESERVE_CLAMPED_COLORS = false;\n\n BaseTexture.prototype.forceSphericalPolynomialsRecompute = function () {\n if (this._texture) {\n this._texture._sphericalPolynomial = null;\n this._texture._sphericalPolynomialPromise = null;\n this._texture._sphericalPolynomialComputed = false;\n }\n };\n Object.defineProperty(BaseTexture.prototype, \"sphericalPolynomial\", {\n get: function () {\n if (this._texture) {\n if (this._texture._sphericalPolynomial || this._texture._sphericalPolynomialComputed) {\n return this._texture._sphericalPolynomial;\n }\n if (this._texture.isReady) {\n if (!this._texture._sphericalPolynomialPromise) {\n this._texture._sphericalPolynomialPromise = CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this);\n if (this._texture._sphericalPolynomialPromise === null) {\n this._texture._sphericalPolynomialComputed = true;\n }\n else {\n this._texture._sphericalPolynomialPromise.then((sphericalPolynomial) => {\n this._texture._sphericalPolynomial = sphericalPolynomial;\n this._texture._sphericalPolynomialComputed = true;\n });\n }\n }\n return null;\n }\n }\n return null;\n },\n set: function (value) {\n if (this._texture) {\n this._texture._sphericalPolynomial = value;\n }\n },\n enumerable: true,\n configurable: true,\n });\n\n // Do not edit.\n const name$13 = \"pbrFragmentDeclaration\";\n const shader$13 = `uniform vec4 vEyePosition;uniform vec3 vReflectionColor;uniform vec4 vAlbedoColor;uniform vec4 vLightingIntensity;uniform vec4 vReflectivityColor;uniform vec4 vMetallicReflectanceFactors;uniform vec3 vEmissiveColor;uniform float visibility;uniform vec3 vAmbientColor;\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec4 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef REFLECTIVITY\nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(SS_REFRACTION) || defined(PREPASS)\nuniform mat4 view;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REALTIME_FILTERING\nuniform vec2 vReflectionFilteringInfo;\n#endif\nuniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;uniform vec3 vReflectionSize; \n#endif\n#endif\n#if defined(SS_REFRACTION) && defined(SS_USE_LOCAL_REFRACTIONMAP_CUBIC)\nuniform vec3 vRefractionPosition;uniform vec3 vRefractionSize; \n#endif\n#ifdef CLEARCOAT\nuniform vec2 vClearCoatParams;uniform vec4 vClearCoatRefractionParams;\n#if defined(CLEARCOAT_TEXTURE) || defined(CLEARCOAT_TEXTURE_ROUGHNESS)\nuniform vec4 vClearCoatInfos;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nuniform mat4 clearCoatMatrix;\n#endif\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS\nuniform mat4 clearCoatRoughnessMatrix;\n#endif\n#ifdef CLEARCOAT_BUMP\nuniform vec2 vClearCoatBumpInfos;uniform vec2 vClearCoatTangentSpaceParams;uniform mat4 clearCoatBumpMatrix;\n#endif\n#ifdef CLEARCOAT_TINT\nuniform vec4 vClearCoatTintParams;uniform float clearCoatColorAtDistance;\n#ifdef CLEARCOAT_TINT_TEXTURE\nuniform vec2 vClearCoatTintInfos;uniform mat4 clearCoatTintMatrix;\n#endif\n#endif\n#endif\n#ifdef IRIDESCENCE\nuniform vec4 vIridescenceParams;\n#if defined(IRIDESCENCE_TEXTURE) || defined(IRIDESCENCE_THICKNESS_TEXTURE)\nuniform vec4 vIridescenceInfos;\n#endif\n#ifdef IRIDESCENCE_TEXTURE\nuniform mat4 iridescenceMatrix;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nuniform mat4 iridescenceThicknessMatrix;\n#endif\n#endif\n#ifdef ANISOTROPIC\nuniform vec3 vAnisotropy;\n#ifdef ANISOTROPIC_TEXTURE\nuniform vec2 vAnisotropyInfos;uniform mat4 anisotropyMatrix;\n#endif\n#endif\n#ifdef SHEEN\nuniform vec4 vSheenColor;\n#ifdef SHEEN_ROUGHNESS\nuniform float vSheenRoughness;\n#endif\n#if defined(SHEEN_TEXTURE) || defined(SHEEN_TEXTURE_ROUGHNESS)\nuniform vec4 vSheenInfos;\n#endif\n#ifdef SHEEN_TEXTURE\nuniform mat4 sheenMatrix;\n#endif\n#ifdef SHEEN_TEXTURE_ROUGHNESS\nuniform mat4 sheenRoughnessMatrix;\n#endif\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\nuniform vec4 vRefractionMicrosurfaceInfos;uniform vec4 vRefractionInfos;uniform mat4 refractionMatrix;\n#ifdef REALTIME_FILTERING\nuniform vec2 vRefractionFilteringInfo;\n#endif\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nuniform vec2 vThicknessInfos;uniform mat4 thicknessMatrix;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nuniform vec2 vRefractionIntensityInfos;uniform mat4 refractionIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nuniform vec2 vTranslucencyIntensityInfos;uniform mat4 translucencyIntensityMatrix;\n#endif\nuniform vec2 vThicknessParam;uniform vec3 vDiffusionDistance;uniform vec4 vTintColor;uniform vec3 vSubSurfaceIntensity;\n#endif\n#ifdef PREPASS\n#ifdef SS_SCATTERING\nuniform float scatteringDiffusionProfile;\n#endif\n#endif\n#if DEBUGMODE>0\nuniform vec2 vDebugMode;\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;\n#endif\n#include\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nuniform vec3 vSphericalL00;uniform vec3 vSphericalL1_1;uniform vec3 vSphericalL10;uniform vec3 vSphericalL11;uniform vec3 vSphericalL2_2;uniform vec3 vSphericalL2_1;uniform vec3 vSphericalL20;uniform vec3 vSphericalL21;uniform vec3 vSphericalL22;\n#else\nuniform vec3 vSphericalX;uniform vec3 vSphericalY;uniform vec3 vSphericalZ;uniform vec3 vSphericalXX_ZZ;uniform vec3 vSphericalYY_ZZ;uniform vec3 vSphericalZZ;uniform vec3 vSphericalXY;uniform vec3 vSphericalYZ;uniform vec3 vSphericalZX;\n#endif\n#endif\n#define ADDITIONAL_FRAGMENT_DECLARATION\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$13] = shader$13;\n\n // Do not edit.\n const name$14 = \"pbrUboDeclaration\";\n const shader$14 = `layout(std140,column_major) uniform;uniform Material {vec2 vAlbedoInfos;vec4 vAmbientInfos;vec2 vOpacityInfos;vec2 vEmissiveInfos;vec2 vLightmapInfos;vec3 vReflectivityInfos;vec2 vMicroSurfaceSamplerInfos;vec2 vReflectionInfos;vec2 vReflectionFilteringInfo;vec3 vReflectionPosition;vec3 vReflectionSize;vec3 vBumpInfos;mat4 albedoMatrix;mat4 ambientMatrix;mat4 opacityMatrix;mat4 emissiveMatrix;mat4 lightmapMatrix;mat4 reflectivityMatrix;mat4 microSurfaceSamplerMatrix;mat4 bumpMatrix;vec2 vTangentSpaceParams;mat4 reflectionMatrix;vec3 vReflectionColor;vec4 vAlbedoColor;vec4 vLightingIntensity;vec3 vReflectionMicrosurfaceInfos;float pointSize;vec4 vReflectivityColor;vec3 vEmissiveColor;vec3 vAmbientColor;vec2 vDebugMode;vec4 vMetallicReflectanceFactors;vec2 vMetallicReflectanceInfos;mat4 metallicReflectanceMatrix;vec2 vReflectanceInfos;mat4 reflectanceMatrix;vec3 vSphericalL00;vec3 vSphericalL1_1;vec3 vSphericalL10;vec3 vSphericalL11;vec3 vSphericalL2_2;vec3 vSphericalL2_1;vec3 vSphericalL20;vec3 vSphericalL21;vec3 vSphericalL22;vec3 vSphericalX;vec3 vSphericalY;vec3 vSphericalZ;vec3 vSphericalXX_ZZ;vec3 vSphericalYY_ZZ;vec3 vSphericalZZ;vec3 vSphericalXY;vec3 vSphericalYZ;vec3 vSphericalZX;\n#define ADDITIONAL_UBO_DECLARATION\n};\n#include\n#include\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$14] = shader$14;\n\n // Do not edit.\n const name$15 = \"pbrFragmentExtraDeclaration\";\n const shader$15 = `varying vec3 vPositionW;\n#if DEBUGMODE>0\nvarying vec4 vClipSpacePosition;\n#endif\n#include[1..7]\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#endif\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$15] = shader$15;\n\n // Do not edit.\n const name$16 = \"samplerFragmentAlternateDeclaration\";\n const shader$16 = `#ifdef _DEFINENAME_\n#if _DEFINENAME_DIRECTUV==1\n#define v_VARYINGNAME_UV vMainUV1\n#elif _DEFINENAME_DIRECTUV==2\n#define v_VARYINGNAME_UV vMainUV2\n#elif _DEFINENAME_DIRECTUV==3\n#define v_VARYINGNAME_UV vMainUV3\n#elif _DEFINENAME_DIRECTUV==4\n#define v_VARYINGNAME_UV vMainUV4\n#elif _DEFINENAME_DIRECTUV==5\n#define v_VARYINGNAME_UV vMainUV5\n#elif _DEFINENAME_DIRECTUV==6\n#define v_VARYINGNAME_UV vMainUV6\n#else\nvarying vec2 v_VARYINGNAME_UV;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$16] = shader$16;\n\n // Do not edit.\n const name$17 = \"pbrFragmentSamplersDeclaration\";\n const shader$17 = `#include(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo,_SAMPLERNAME_,albedo)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)\n#include(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity,_SAMPLERNAME_,reflectivity)\n#include(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler,_SAMPLERNAME_,microSurface)\n#include(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance,_SAMPLERNAME_,metallicReflectance)\n#include(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance,_SAMPLERNAME_,reflectance)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)\n#ifdef CLEARCOAT\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat,_SAMPLERNAME_,clearCoat)\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness)\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL)\nuniform sampler2D clearCoatRoughnessSampler;\n#endif\n#include(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump,_SAMPLERNAME_,clearCoatBump)\n#include(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint,_SAMPLERNAME_,clearCoatTint)\n#endif\n#ifdef IRIDESCENCE\n#include(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence,_SAMPLERNAME_,iridescence)\n#include(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness,_SAMPLERNAME_,iridescenceThickness)\n#endif\n#ifdef SHEEN\n#include(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen,_SAMPLERNAME_,sheen)\n#include(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness)\n#if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL)\nuniform sampler2D sheenRoughnessSampler;\n#endif\n#endif\n#ifdef ANISOTROPIC\n#include(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy,_SAMPLERNAME_,anisotropy)\n#endif\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;\n#endif\n#ifdef USEIRRADIANCEMAP\nuniform samplerCube irradianceSampler;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform sampler2D reflectionSamplerLow;uniform sampler2D reflectionSamplerHigh;\n#endif\n#ifdef USEIRRADIANCEMAP\nuniform sampler2D irradianceSampler;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\n#ifdef SS_REFRACTIONMAP_3D\n#define sampleRefraction(s,c) textureCube(s,c)\nuniform samplerCube refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;uniform samplerCube refractionSamplerHigh;\n#endif\n#else\n#define sampleRefraction(s,c) texture2D(s,c)\nuniform sampler2D refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform sampler2D refractionSamplerLow;uniform sampler2D refractionSamplerHigh;\n#endif\n#endif\n#endif\n#include(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness,_SAMPLERNAME_,thickness)\n#include(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity,_SAMPLERNAME_,refractionIntensity)\n#include(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity,_SAMPLERNAME_,translucencyIntensity)\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$17] = shader$17;\n\n // Do not edit.\n const name$18 = \"subSurfaceScatteringFunctions\";\n const shader$18 = `bool testLightingForSSS(float diffusionProfile)\n{return diffusionProfile<1.;}`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$18] = shader$18;\n\n // Do not edit.\n const name$19 = \"importanceSampling\";\n const shader$19 = `vec3 hemisphereCosSample(vec2 u) {float phi=2.*PI*u.x;float cosTheta2=1.-u.y;float cosTheta=sqrt(cosTheta2);float sinTheta=sqrt(1.-cosTheta2);return vec3(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}\nvec3 hemisphereImportanceSampleDggx(vec2 u,float a) {float phi=2.*PI*u.x;float cosTheta2=(1.-u.y)/(1.+(a+1.)*((a-1.)*u.y));float cosTheta=sqrt(cosTheta2);float sinTheta=sqrt(1.-cosTheta2);return vec3(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}\nvec3 hemisphereImportanceSampleDCharlie(vec2 u,float a) { \nfloat phi=2.*PI*u.x;float sinTheta=pow(u.y,a/(2.*a+1.));float cosTheta=sqrt(1.-sinTheta*sinTheta);return vec3(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$19] = shader$19;\n\n // Do not edit.\n const name$1a = \"pbrHelperFunctions\";\n const shader$1a = `#define RECIPROCAL_PI2 0.15915494\n#define RECIPROCAL_PI 0.31830988618\n#define MINIMUMVARIANCE 0.0005\nfloat convertRoughnessToAverageSlope(float roughness)\n{return square(roughness)+MINIMUMVARIANCE;}\nfloat fresnelGrazingReflectance(float reflectance0) {float reflectance90=saturate(reflectance0*25.0);return reflectance90;}\nvec2 getAARoughnessFactors(vec3 normalVector) {\n#ifdef SPECULARAA\nvec3 nDfdx=dFdx(normalVector.xyz);vec3 nDfdy=dFdy(normalVector.xyz);float slopeSquare=max(dot(nDfdx,nDfdx),dot(nDfdy,nDfdy));float geometricRoughnessFactor=pow(saturate(slopeSquare),0.333);float geometricAlphaGFactor=sqrt(slopeSquare);geometricAlphaGFactor*=0.75;return vec2(geometricRoughnessFactor,geometricAlphaGFactor);\n#else\nreturn vec2(0.);\n#endif\n}\n#ifdef ANISOTROPIC\n#ifdef ANISOTROPIC_LEGACY\nvec2 getAnisotropicRoughness(float alphaG,float anisotropy) {float alphaT=max(alphaG*(1.0+anisotropy),MINIMUMVARIANCE);float alphaB=max(alphaG*(1.0-anisotropy),MINIMUMVARIANCE);return vec2(alphaT,alphaB);}\nvec3 getAnisotropicBentNormals(const vec3 T,const vec3 B,const vec3 N,const vec3 V,float anisotropy,float roughness) {vec3 anisotropicFrameDirection=anisotropy>=0.0 ? B : T;vec3 anisotropicFrameTangent=cross(normalize(anisotropicFrameDirection),V);vec3 anisotropicFrameNormal=cross(anisotropicFrameTangent,anisotropicFrameDirection);vec3 anisotropicNormal=normalize(mix(N,anisotropicFrameNormal,abs(anisotropy)));return anisotropicNormal;}\n#else\nvec2 getAnisotropicRoughness(float alphaG,float anisotropy) {float alphaT=max(mix(alphaG,1.0,anisotropy*anisotropy),MINIMUMVARIANCE);float alphaB=max(alphaG,MINIMUMVARIANCE);return vec2(alphaT,alphaB);}\nvec3 getAnisotropicBentNormals(const vec3 T,const vec3 B,const vec3 N,const vec3 V,float anisotropy,float roughness) {vec3 bentNormal=cross(B,V);bentNormal=normalize(cross(bentNormal,B));float a=square(square(1.0-anisotropy*(1.0-roughness)));bentNormal=normalize(mix(bentNormal,N,a));return bentNormal;}\n#endif\n#endif\n#if defined(CLEARCOAT) || defined(SS_REFRACTION)\nvec3 cocaLambert(vec3 alpha,float distance) {return exp(-alpha*distance);}\nvec3 cocaLambert(float NdotVRefract,float NdotLRefract,vec3 alpha,float thickness) {return cocaLambert(alpha,(thickness*((NdotLRefract+NdotVRefract)/(NdotLRefract*NdotVRefract))));}\nvec3 computeColorAtDistanceInMedia(vec3 color,float distance) {return -log(color)/distance;}\nvec3 computeClearCoatAbsorption(float NdotVRefract,float NdotLRefract,vec3 clearCoatColor,float clearCoatThickness,float clearCoatIntensity) {vec3 clearCoatAbsorption=mix(vec3(1.0),\ncocaLambert(NdotVRefract,NdotLRefract,clearCoatColor,clearCoatThickness),\nclearCoatIntensity);return clearCoatAbsorption;}\n#endif\n#ifdef MICROSURFACEAUTOMATIC\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{const float kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;float reflectivityLuminance=getLuminance(reflectivityColor);float reflectivityLuma=sqrt(reflectivityLuminance);microSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;return microSurface;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1a] = shader$1a;\n\n // Do not edit.\n const name$1b = \"harmonicsFunctions\";\n const shader$1b = `#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nvec3 computeEnvironmentIrradiance(vec3 normal) {return vSphericalL00\n+ vSphericalL1_1*(normal.y)\n+ vSphericalL10*(normal.z)\n+ vSphericalL11*(normal.x)\n+ vSphericalL2_2*(normal.y*normal.x)\n+ vSphericalL2_1*(normal.y*normal.z)\n+ vSphericalL20*((3.0*normal.z*normal.z)-1.0)\n+ vSphericalL21*(normal.z*normal.x)\n+ vSphericalL22*(normal.x*normal.x-(normal.y*normal.y));}\n#else\nvec3 computeEnvironmentIrradiance(vec3 normal) {float Nx=normal.x;float Ny=normal.y;float Nz=normal.z;vec3 C1=vSphericalZZ.rgb;vec3 Cx=vSphericalX.rgb;vec3 Cy=vSphericalY.rgb;vec3 Cz=vSphericalZ.rgb;vec3 Cxx_zz=vSphericalXX_ZZ.rgb;vec3 Cyy_zz=vSphericalYY_ZZ.rgb;vec3 Cxy=vSphericalXY.rgb;vec3 Cyz=vSphericalYZ.rgb;vec3 Czx=vSphericalZX.rgb;vec3 a1=Cyy_zz*Ny+Cy;vec3 a2=Cyz*Nz+a1;vec3 b1=Czx*Nz+Cx;vec3 b2=Cxy*Ny+b1;vec3 b3=Cxx_zz*Nx+b2;vec3 t1=Cz *Nz+C1;vec3 t2=a2 *Ny+t1;vec3 t3=b3 *Nx+t2;return t3;}\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1b] = shader$1b;\n\n // Do not edit.\n const name$1c = \"pbrDirectLightingSetupFunctions\";\n const shader$1c = `struct preLightingInfo\n{vec3 lightOffset;float lightDistanceSquared;float lightDistance;float attenuation;vec3 L;vec3 H;float NdotV;float NdotLUnclamped;float NdotL;float VdotH;float roughness;\n#ifdef IRIDESCENCE\nfloat iridescenceIntensity;\n#endif\n};preLightingInfo computePointAndSpotPreLightingInfo(vec4 lightData,vec3 V,vec3 N) {preLightingInfo result;result.lightOffset=lightData.xyz-vPositionW;result.lightDistanceSquared=dot(result.lightOffset,result.lightOffset);result.lightDistance=sqrt(result.lightDistanceSquared);result.L=normalize(result.lightOffset);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);return result;}\npreLightingInfo computeDirectionalPreLightingInfo(vec4 lightData,vec3 V,vec3 N) {preLightingInfo result;result.lightDistance=length(-lightData.xyz);result.L=normalize(-lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);return result;}\npreLightingInfo computeHemisphericPreLightingInfo(vec4 lightData,vec3 V,vec3 N) {preLightingInfo result;result.NdotL=dot(N,lightData.xyz)*0.5+0.5;result.NdotL=saturateEps(result.NdotL);result.NdotLUnclamped=result.NdotL;\n#ifdef SPECULARTERM\nresult.L=normalize(lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));\n#endif\nreturn result;}`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1c] = shader$1c;\n\n // Do not edit.\n const name$1d = \"pbrDirectLightingFalloffFunctions\";\n const shader$1d = `float computeDistanceLightFalloff_Standard(vec3 lightOffset,float range)\n{return max(0.,1.0-length(lightOffset)/range);}\nfloat computeDistanceLightFalloff_Physical(float lightDistanceSquared)\n{return 1.0/maxEps(lightDistanceSquared);}\nfloat computeDistanceLightFalloff_GLTF(float lightDistanceSquared,float inverseSquaredRange)\n{float lightDistanceFalloff=1.0/maxEps(lightDistanceSquared);float factor=lightDistanceSquared*inverseSquaredRange;float attenuation=saturate(1.0-factor*factor);attenuation*=attenuation;lightDistanceFalloff*=attenuation;return lightDistanceFalloff;}\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range,float inverseSquaredRange)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nreturn computeDistanceLightFalloff_Physical(lightDistanceSquared);\n#elif defined(USEGLTFLIGHTFALLOFF)\nreturn computeDistanceLightFalloff_GLTF(lightDistanceSquared,inverseSquaredRange);\n#else\nreturn computeDistanceLightFalloff_Standard(lightOffset,range);\n#endif\n}\nfloat computeDirectionalLightFalloff_Standard(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent)\n{float falloff=0.0;float cosAngle=maxEps(dot(-lightDirection,directionToLightCenterW));if (cosAngle>=cosHalfAngle)\n{falloff=max(0.,pow(cosAngle,exponent));}\nreturn falloff;}\nfloat computeDirectionalLightFalloff_Physical(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle)\n{const float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);vec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);float falloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));return falloff;}\nfloat computeDirectionalLightFalloff_GLTF(vec3 lightDirection,vec3 directionToLightCenterW,float lightAngleScale,float lightAngleOffset)\n{float cd=dot(-lightDirection,directionToLightCenterW);float falloff=saturate(cd*lightAngleScale+lightAngleOffset);falloff*=falloff;return falloff;}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent,float lightAngleScale,float lightAngleOffset)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nreturn computeDirectionalLightFalloff_Physical(lightDirection,directionToLightCenterW,cosHalfAngle);\n#elif defined(USEGLTFLIGHTFALLOFF)\nreturn computeDirectionalLightFalloff_GLTF(lightDirection,directionToLightCenterW,lightAngleScale,lightAngleOffset);\n#else\nreturn computeDirectionalLightFalloff_Standard(lightDirection,directionToLightCenterW,cosHalfAngle,exponent);\n#endif\n}`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1d] = shader$1d;\n\n // Do not edit.\n const name$1e = \"pbrBRDFFunctions\";\n const shader$1e = `#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n#ifdef MS_BRDF_ENERGY_CONSERVATION\nvec3 getEnergyConservationFactor(const vec3 specularEnvironmentR0,const vec3 environmentBrdf) {return 1.0+specularEnvironmentR0*(1.0/environmentBrdf.y-1.0);}\n#endif\n#ifdef ENVIRONMENTBRDF\nvec3 getBRDFLookup(float NdotV,float perceptualRoughness) {vec2 UV=vec2(NdotV,perceptualRoughness);vec4 brdfLookup=texture2D(environmentBrdfSampler,UV);\n#ifdef ENVIRONMENTBRDF_RGBD\nbrdfLookup.rgb=fromRGBD(brdfLookup.rgba);\n#endif\nreturn brdfLookup.rgb;}\nvec3 getReflectanceFromBRDFLookup(const vec3 specularEnvironmentR0,const vec3 specularEnvironmentR90,const vec3 environmentBrdf) {\n#ifdef BRDF_V_HEIGHT_CORRELATED\nvec3 reflectance=(specularEnvironmentR90-specularEnvironmentR0)*environmentBrdf.x+specularEnvironmentR0*environmentBrdf.y;\n#else\nvec3 reflectance=specularEnvironmentR0*environmentBrdf.x+specularEnvironmentR90*environmentBrdf.y;\n#endif\nreturn reflectance;}\nvec3 getReflectanceFromBRDFLookup(const vec3 specularEnvironmentR0,const vec3 environmentBrdf) {\n#ifdef BRDF_V_HEIGHT_CORRELATED\nvec3 reflectance=mix(environmentBrdf.xxx,environmentBrdf.yyy,specularEnvironmentR0);\n#else\nvec3 reflectance=specularEnvironmentR0*environmentBrdf.x+environmentBrdf.y;\n#endif\nreturn reflectance;}\n#endif\n/* NOT USED\n#if defined(SHEEN) && defined(SHEEN_SOFTER)\nfloat getBRDFLookupCharlieSheen(float NdotV,float perceptualRoughness)\n{float c=1.0-NdotV;float c3=c*c*c;return 0.65584461*c3+1.0/(4.16526551+exp(-7.97291361*perceptualRoughness+6.33516894));}\n#endif\n*/\n#if !defined(ENVIRONMENTBRDF) || defined(REFLECTIONMAP_SKYBOX) || defined(ALPHAFRESNEL)\nvec3 getReflectanceFromAnalyticalBRDFLookup_Jones(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{float weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);return reflectance0+weight*(reflectance90-reflectance0)*pow5(saturate(1.0-VdotN));}\n#endif\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF)\n/**\n* The sheen BRDF not containing F can be easily stored in the blue channel of the BRDF texture.\n* The blue channel contains DCharlie*VAshikhmin*NdotL as a lokkup table\n*/\nvec3 getSheenReflectanceFromBRDFLookup(const vec3 reflectance0,const vec3 environmentBrdf) {vec3 sheenEnvironmentReflectance=reflectance0*environmentBrdf.b;return sheenEnvironmentReflectance;}\n#endif\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{return reflectance0+(reflectance90-reflectance0)*pow5(1.0-VdotH);}\nfloat fresnelSchlickGGX(float VdotH,float reflectance0,float reflectance90)\n{return reflectance0+(reflectance90-reflectance0)*pow5(1.0-VdotH);}\n#ifdef CLEARCOAT\nvec3 getR0RemappedForClearCoat(vec3 f0) {\n#ifdef CLEARCOAT_DEFAULTIOR\n#ifdef MOBILE\nreturn saturate(f0*(f0*0.526868+0.529324)-0.0482256);\n#else\nreturn saturate(f0*(f0*(0.941892-0.263008*f0)+0.346479)-0.0285998);\n#endif\n#else\nvec3 s=sqrt(f0);vec3 t=(vClearCoatRefractionParams.z+vClearCoatRefractionParams.w*s)/(vClearCoatRefractionParams.w+vClearCoatRefractionParams.z*s);return square(t);\n#endif\n}\n#endif\n#ifdef IRIDESCENCE\nconst mat3 XYZ_TO_REC709=mat3(\n3.2404542,-0.9692660, 0.0556434,\n-1.5371385, 1.8760108,-0.2040259,\n-0.4985314, 0.0415560, 1.0572252\n);vec3 getIORTfromAirToSurfaceR0(vec3 f0) {vec3 sqrtF0=sqrt(f0);return (1.+sqrtF0)/(1.-sqrtF0);}\nvec3 getR0fromIORs(vec3 iorT,float iorI) {return square((iorT-vec3(iorI))/(iorT+vec3(iorI)));}\nfloat getR0fromIORs(float iorT,float iorI) {return square((iorT-iorI)/(iorT+iorI));}\nvec3 evalSensitivity(float opd,vec3 shift) {float phase=2.0*PI*opd*1.0e-9;const vec3 val=vec3(5.4856e-13,4.4201e-13,5.2481e-13);const vec3 pos=vec3(1.6810e+06,1.7953e+06,2.2084e+06);const vec3 var=vec3(4.3278e+09,9.3046e+09,6.6121e+09);vec3 xyz=val*sqrt(2.0*PI*var)*cos(pos*phase+shift)*exp(-square(phase)*var);xyz.x+=9.7470e-14*sqrt(2.0*PI*4.5282e+09)*cos(2.2399e+06*phase+shift[0])*exp(-4.5282e+09*square(phase));xyz/=1.0685e-7;vec3 srgb=XYZ_TO_REC709*xyz;return srgb;}\nvec3 evalIridescence(float outsideIOR,float eta2,float cosTheta1,float thinFilmThickness,vec3 baseF0) {vec3 I=vec3(1.0);float iridescenceIOR=mix(outsideIOR,eta2,smoothstep(0.0,0.03,thinFilmThickness));float sinTheta2Sq=square(outsideIOR/iridescenceIOR)*(1.0-square(cosTheta1));float cosTheta2Sq=1.0-sinTheta2Sq;if (cosTheta2Sq<0.0) {return I;}\nfloat cosTheta2=sqrt(cosTheta2Sq);float R0=getR0fromIORs(iridescenceIOR,outsideIOR);float R12=fresnelSchlickGGX(cosTheta1,R0,1.);float R21=R12;float T121=1.0-R12;float phi12=0.0;if (iridescenceIOR0\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nfloat radicalInverse_VdC(uint bits) \n{bits=(bits<<16u) | (bits>>16u);bits=((bits & 0x55555555u)<<1u) | ((bits & 0xAAAAAAAAu)>>1u);bits=((bits & 0x33333333u)<<2u) | ((bits & 0xCCCCCCCCu)>>2u);bits=((bits & 0x0F0F0F0Fu)<<4u) | ((bits & 0xF0F0F0F0u)>>4u);bits=((bits & 0x00FF00FFu)<<8u) | ((bits & 0xFF00FF00u)>>8u);return float(bits)*2.3283064365386963e-10; }\nvec2 hammersley(uint i,uint N)\n{return vec2(float(i)/float(N),radicalInverse_VdC(i));}\n#else\nfloat vanDerCorpus(int n,int base)\n{float invBase=1.0/float(base);float denom =1.0;float result =0.0;for(int i=0; i<32; ++i)\n{if(n>0)\n{denom =mod(float(n),2.0);result+=denom*invBase;invBase=invBase/2.0;n =int(float(n)/2.0);}}\nreturn result;}\nvec2 hammersley(int i,int N)\n{return vec2(float(i)/float(N),vanDerCorpus(i,2));}\n#endif\nfloat log4(float x) {return log2(x)/2.;}\nconst float NUM_SAMPLES_FLOAT=float(NUM_SAMPLES);const float NUM_SAMPLES_FLOAT_INVERSED=1./NUM_SAMPLES_FLOAT;const float K=4.;\n#define inline\nvec3 irradiance(samplerCube inputTexture,vec3 inputN,vec2 filteringInfo)\n{vec3 n=normalize(inputN);vec3 result=vec3(0.0);vec3 tangent=abs(n.z)<0.999 ? vec3(0.,0.,1.) : vec3(1.,0.,0.);tangent=normalize(cross(tangent,n));vec3 bitangent=cross(n,tangent);mat3 tbn=mat3(tangent,bitangent,n);float maxLevel=filteringInfo.y;float dim0=filteringInfo.x;float omegaP=(4.*PI)/(6.*dim0*dim0);\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nfor(uint i=0u; i0.) {float pdf_inversed=PI/NoL;float omegaS=NUM_SAMPLES_FLOAT_INVERSED*pdf_inversed;float l=log4(omegaS)-log4(omegaP)+log4(K);float mipLevel=clamp(l,0.0,maxLevel);vec3 c=textureCubeLodEXT(inputTexture,tbn*Ls,mipLevel).rgb;\n#ifdef GAMMA_INPUT\nc=toLinearSpace(c);\n#endif\nresult+=c;}}\nresult=result*NUM_SAMPLES_FLOAT_INVERSED;return result;}\n#define inline\nvec3 radiance(float alphaG,samplerCube inputTexture,vec3 inputN,vec2 filteringInfo)\n{vec3 n=normalize(inputN);if (alphaG==0.) {vec3 c=textureCube(inputTexture,n).rgb;\n#ifdef GAMMA_INPUT\nc=toLinearSpace(c);\n#endif\nreturn c;} else {vec3 result=vec3(0.);vec3 tangent=abs(n.z)<0.999 ? vec3(0.,0.,1.) : vec3(1.,0.,0.);tangent=normalize(cross(tangent,n));vec3 bitangent=cross(n,tangent);mat3 tbn=mat3(tangent,bitangent,n);float maxLevel=filteringInfo.y;float dim0=filteringInfo.x;float omegaP=(4.*PI)/(6.*dim0*dim0);float weight=0.;\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nfor(uint i=0u; i0.) {float pdf_inversed=4./normalDistributionFunction_TrowbridgeReitzGGX(NoH,alphaG);float omegaS=NUM_SAMPLES_FLOAT_INVERSED*pdf_inversed;float l=log4(omegaS)-log4(omegaP)+log4(K);float mipLevel=clamp(float(l),0.0,maxLevel);weight+=NoL;vec3 c=textureCubeLodEXT(inputTexture,tbn*L,mipLevel).rgb;\n#ifdef GAMMA_INPUT\nc=toLinearSpace(c);\n#endif\nresult+=c*NoL;}}\nresult=result/weight;return result;}}\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1f] = shader$1f;\n\n // Do not edit.\n const name$1g = \"pbrDirectLightingFunctions\";\n const shader$1g = `#define CLEARCOATREFLECTANCE90 1.0\nstruct lightingInfo\n{vec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef CLEARCOAT\nvec4 clearCoat;\n#endif\n#ifdef SHEEN\nvec3 sheen;\n#endif\n};float adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance) {\n#if defined(USEPHYSICALLIGHTFALLOFF) || defined(USEGLTFLIGHTFALLOFF)\nfloat lightRoughness=lightRadius/lightDistance;float totalRoughness=saturate(lightRoughness+roughness);return totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nvec3 computeHemisphericDiffuseLighting(preLightingInfo info,vec3 lightColor,vec3 groundColor) {return mix(groundColor,lightColor,info.NdotL);}\nvec3 computeDiffuseLighting(preLightingInfo info,vec3 lightColor) {float diffuseTerm=diffuseBRDF_Burley(info.NdotL,info.NdotV,info.VdotH,info.roughness);return diffuseTerm*info.attenuation*info.NdotL*lightColor;}\n#define inline\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);strq/=strq.w;vec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;return toLinearSpace(textureColor);}\n#ifdef SS_TRANSLUCENCY\nvec3 computeDiffuseAndTransmittedLighting(preLightingInfo info,vec3 lightColor,vec3 transmittance) {float NdotL=absEps(info.NdotLUnclamped);float wrapNdotL=computeWrappedDiffuseNdotL(NdotL,0.02);float trAdapt=step(0.,info.NdotLUnclamped);vec3 transmittanceNdotL=mix(transmittance*wrapNdotL,vec3(wrapNdotL),trAdapt);float diffuseTerm=diffuseBRDF_Burley(NdotL,info.NdotV,info.VdotH,info.roughness);return diffuseTerm*transmittanceNdotL*info.attenuation*lightColor;}\n#endif\n#ifdef SPECULARTERM\nvec3 computeSpecularLighting(preLightingInfo info,vec3 N,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,vec3 lightColor) {float NdotH=saturateEps(dot(N,info.H));float roughness=max(info.roughness,geometricRoughnessFactor);float alphaG=convertRoughnessToAverageSlope(roughness);vec3 fresnel=fresnelSchlickGGX(info.VdotH,reflectance0,reflectance90);\n#ifdef IRIDESCENCE\nfresnel=mix(fresnel,reflectance0,info.iridescenceIntensity);\n#endif\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\n#ifdef BRDF_V_HEIGHT_CORRELATED\nfloat smithVisibility=smithVisibility_GGXCorrelated(info.NdotL,info.NdotV,alphaG);\n#else\nfloat smithVisibility=smithVisibility_TrowbridgeReitzGGXFast(info.NdotL,info.NdotV,alphaG);\n#endif\nvec3 specTerm=fresnel*distribution*smithVisibility;return specTerm*info.attenuation*info.NdotL*lightColor;}\n#endif\n#ifdef ANISOTROPIC\nvec3 computeAnisotropicSpecularLighting(preLightingInfo info,vec3 V,vec3 N,vec3 T,vec3 B,float anisotropy,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,vec3 lightColor) {float NdotH=saturateEps(dot(N,info.H));float TdotH=dot(T,info.H);float BdotH=dot(B,info.H);float TdotV=dot(T,V);float BdotV=dot(B,V);float TdotL=dot(T,info.L);float BdotL=dot(B,info.L);float alphaG=convertRoughnessToAverageSlope(info.roughness);vec2 alphaTB=getAnisotropicRoughness(alphaG,anisotropy);alphaTB=max(alphaTB,square(geometricRoughnessFactor));vec3 fresnel=fresnelSchlickGGX(info.VdotH,reflectance0,reflectance90);\n#ifdef IRIDESCENCE\nfresnel=mix(fresnel,reflectance0,info.iridescenceIntensity);\n#endif\nfloat distribution=normalDistributionFunction_BurleyGGX_Anisotropic(NdotH,TdotH,BdotH,alphaTB);float smithVisibility=smithVisibility_GGXCorrelated_Anisotropic(info.NdotL,info.NdotV,TdotV,BdotV,TdotL,BdotL,alphaTB);vec3 specTerm=fresnel*distribution*smithVisibility;return specTerm*info.attenuation*info.NdotL*lightColor;}\n#endif\n#ifdef CLEARCOAT\nvec4 computeClearCoatLighting(preLightingInfo info,vec3 Ncc,float geometricRoughnessFactor,float clearCoatIntensity,vec3 lightColor) {float NccdotL=saturateEps(dot(Ncc,info.L));float NccdotH=saturateEps(dot(Ncc,info.H));float clearCoatRoughness=max(info.roughness,geometricRoughnessFactor);float alphaG=convertRoughnessToAverageSlope(clearCoatRoughness);float fresnel=fresnelSchlickGGX(info.VdotH,vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnel*=clearCoatIntensity;float distribution=normalDistributionFunction_TrowbridgeReitzGGX(NccdotH,alphaG);float kelemenVisibility=visibility_Kelemen(info.VdotH);float clearCoatTerm=fresnel*distribution*kelemenVisibility;return vec4(\nclearCoatTerm*info.attenuation*NccdotL*lightColor,\n1.0-fresnel\n);}\nvec3 computeClearCoatLightingAbsorption(float NdotVRefract,vec3 L,vec3 Ncc,vec3 clearCoatColor,float clearCoatThickness,float clearCoatIntensity) {vec3 LRefract=-refract(L,Ncc,vClearCoatRefractionParams.y);float NdotLRefract=saturateEps(dot(Ncc,LRefract));vec3 absorption=computeClearCoatAbsorption(NdotVRefract,NdotLRefract,clearCoatColor,clearCoatThickness,clearCoatIntensity);return absorption;}\n#endif\n#ifdef SHEEN\nvec3 computeSheenLighting(preLightingInfo info,vec3 N,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,vec3 lightColor) {float NdotH=saturateEps(dot(N,info.H));float roughness=max(info.roughness,geometricRoughnessFactor);float alphaG=convertRoughnessToAverageSlope(roughness);float fresnel=1.;float distribution=normalDistributionFunction_CharlieSheen(NdotH,alphaG);/*#ifdef SHEEN_SOFTER\nfloat visibility=visibility_CharlieSheen(info.NdotL,info.NdotV,alphaG);\n#else */\nfloat visibility=visibility_Ashikhmin(info.NdotL,info.NdotV);/* #endif */\nfloat sheenTerm=fresnel*distribution*visibility;return sheenTerm*info.attenuation*info.NdotL*lightColor;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1g] = shader$1g;\n\n // Do not edit.\n const name$1h = \"pbrIBLFunctions\";\n const shader$1h = `#if defined(REFLECTION) || defined(SS_REFRACTION)\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float microsurfaceAverageSlope) {float microsurfaceAverageSlopeTexels=cubeMapDimensionPixels*microsurfaceAverageSlope;float lod=log2(microsurfaceAverageSlopeTexels);return lod;}\nfloat getLinearLodFromRoughness(float cubeMapDimensionPixels,float roughness) {float lod=log2(cubeMapDimensionPixels)*roughness;return lod;}\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(RADIANCEOCCLUSION)\nfloat environmentRadianceOcclusion(float ambientOcclusion,float NdotVUnclamped) {float temp=NdotVUnclamped+ambientOcclusion;return saturate(square(temp)-1.0+ambientOcclusion);}\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(HORIZONOCCLUSION)\nfloat environmentHorizonOcclusion(vec3 view,vec3 normal,vec3 geometricNormal) {vec3 reflection=reflect(view,normal);float temp=saturate(1.0+1.1*dot(reflection,geometricNormal));return square(temp);}\n#endif\n#if defined(LODINREFLECTIONALPHA) || defined(SS_LODINREFRACTIONALPHA)\n#define UNPACK_LOD(x) (1.0-x)*255.0\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float alphaG,float NdotV) {float microsurfaceAverageSlope=alphaG;microsurfaceAverageSlope*=sqrt(abs(NdotV));return getLodFromAlphaG(cubeMapDimensionPixels,microsurfaceAverageSlope);}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1h] = shader$1h;\n\n // Do not edit.\n const name$1i = \"pbrBlockAlbedoOpacity\";\n const shader$1i = `struct albedoOpacityOutParams\n{vec3 surfaceAlbedo;float alpha;};\n#define pbr_inline\nvoid albedoOpacityBlock(\nin vec4 vAlbedoColor,\n#ifdef ALBEDO\nin vec4 albedoTexture,\nin vec2 albedoInfos,\n#endif\n#ifdef OPACITY\nin vec4 opacityMap,\nin vec2 vOpacityInfos,\n#endif\n#ifdef DETAIL\nin vec4 detailColor,\nin vec4 vDetailInfos,\n#endif\n#ifdef DECAL\nin vec4 decalColor,\nin vec4 vDecalInfos,\n#endif\nout albedoOpacityOutParams outParams\n)\n{vec3 surfaceAlbedo=vAlbedoColor.rgb;float alpha=vAlbedoColor.a;\n#ifdef ALBEDO\n#if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)\nalpha*=albedoTexture.a;\n#endif\n#ifdef GAMMAALBEDO\nsurfaceAlbedo*=toLinearSpace(albedoTexture.rgb);\n#else\nsurfaceAlbedo*=albedoTexture.rgb;\n#endif\nsurfaceAlbedo*=albedoInfos.y;\n#endif\n#ifndef DECAL_AFTER_DETAIL\n#include\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nsurfaceAlbedo*=vColor.rgb;\n#endif\n#ifdef DETAIL\nfloat detailAlbedo=2.0*mix(0.5,detailColor.r,vDetailInfos.y);surfaceAlbedo.rgb=surfaceAlbedo.rgb*detailAlbedo*detailAlbedo; \n#endif\n#ifdef DECAL_AFTER_DETAIL\n#include\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_ALBEDO\n#ifdef OPACITY\n#ifdef OPACITYRGB\nalpha=getLuminance(opacityMap.rgb);\n#else\nalpha*=opacityMap.a;\n#endif\nalpha*=vOpacityInfos.y;\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#if !defined(SS_LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)\n#ifdef ALPHATEST \n#if DEBUGMODE != 88\nif (alpha0\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness;\n#ifdef REFLECTIVITY\nvec4 surfaceMetallicColorMap;\n#endif\n#ifndef FROSTBITE_REFLECTANCE\nvec3 metallicF0;\n#endif\n#else\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap;\n#endif\n#endif\n#endif\n};\n#define pbr_inline\nvoid reflectivityBlock(\nin vec4 vReflectivityColor,\n#ifdef METALLICWORKFLOW\nin vec3 surfaceAlbedo,\nin vec4 metallicReflectanceFactors,\n#endif\n#ifdef REFLECTIVITY\nin vec3 reflectivityInfos,\nin vec4 surfaceMetallicOrReflectivityColorMap,\n#endif\n#if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)\nin vec3 ambientOcclusionColorIn,\n#endif\n#ifdef MICROSURFACEMAP\nin vec4 microSurfaceTexel,\n#endif\n#ifdef DETAIL\nin vec4 detailColor,\nin vec4 vDetailInfos,\n#endif\nout reflectivityOutParams outParams\n)\n{float microSurface=vReflectivityColor.a;vec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef REFLECTIVITY\n#if DEBUGMODE>0\noutParams.surfaceMetallicColorMap=surfaceMetallicOrReflectivityColorMap;\n#endif\n#ifdef AOSTOREINMETALMAPRED\nvec3 aoStoreInMetalMap=vec3(surfaceMetallicOrReflectivityColorMap.r,surfaceMetallicOrReflectivityColorMap.r,surfaceMetallicOrReflectivityColorMap.r);outParams.ambientOcclusionColor=mix(ambientOcclusionColorIn,aoStoreInMetalMap,reflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicOrReflectivityColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicOrReflectivityColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicOrReflectivityColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicOrReflectivityColorMap.g;\n#endif\n#endif\n#endif\n#ifdef DETAIL\nfloat detailRoughness=mix(0.5,detailColor.b,vDetailInfos.w);float loLerp=mix(0.,metallicRoughness.g,detailRoughness*2.);float hiLerp=mix(metallicRoughness.g,1.,(detailRoughness-0.5)*2.);metallicRoughness.g=mix(loLerp,hiLerp,step(detailRoughness,0.5));\n#endif\n#ifdef MICROSURFACEMAP\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n#if DEBUGMODE>0\noutParams.metallicRoughness=metallicRoughness;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS\nmicroSurface=1.0-metallicRoughness.g;vec3 baseColor=surfaceAlbedo;\n#ifdef FROSTBITE_REFLECTANCE\noutParams.surfaceAlbedo=baseColor.rgb*(1.0-metallicRoughness.r);surfaceReflectivityColor=mix(0.16*reflectance*reflectance,baseColor,metallicRoughness.r);\n#else\nvec3 metallicF0=metallicReflectanceFactors.rgb;\n#if DEBUGMODE>0\noutParams.metallicF0=metallicF0;\n#endif\noutParams.surfaceAlbedo=mix(baseColor.rgb*(1.0-metallicF0),vec3(0.,0.,0.),metallicRoughness.r);surfaceReflectivityColor=mix(metallicF0,baseColor,metallicRoughness.r);\n#endif\n#else\n#ifdef REFLECTIVITY\nsurfaceReflectivityColor*=surfaceMetallicOrReflectivityColorMap.rgb;\n#if DEBUGMODE>0\noutParams.surfaceReflectivityColorMap=surfaceMetallicOrReflectivityColorMap;\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface*=surfaceMetallicOrReflectivityColorMap.a;microSurface*=reflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#ifdef MICROSURFACEMAP\nmicroSurface*=microSurfaceTexel.r;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_MICROSURFACE\n#endif\n#endif\n#endif\nmicroSurface=saturate(microSurface);float roughness=1.-microSurface;outParams.microSurface=microSurface;outParams.roughness=roughness;outParams.surfaceReflectivityColor=surfaceReflectivityColor;}\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1j] = shader$1j;\n\n // Do not edit.\n const name$1k = \"pbrBlockAmbientOcclusion\";\n const shader$1k = `struct ambientOcclusionOutParams\n{vec3 ambientOcclusionColor;\n#if DEBUGMODE>0 && defined(AMBIENT)\nvec3 ambientOcclusionColorMap;\n#endif\n};\n#define pbr_inline\nvoid ambientOcclusionBlock(\n#ifdef AMBIENT\nin vec3 ambientOcclusionColorMap_,\nin vec4 vAmbientInfos,\n#endif\nout ambientOcclusionOutParams outParams\n)\n{vec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=ambientOcclusionColorMap_*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE\nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#if DEBUGMODE>0\noutParams.ambientOcclusionColorMap=ambientOcclusionColorMap;\n#endif\n#endif\noutParams.ambientOcclusionColor=ambientOcclusionColor;}\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1k] = shader$1k;\n\n // Do not edit.\n const name$1l = \"pbrBlockAlphaFresnel\";\n const shader$1l = `#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\nstruct alphaFresnelOutParams\n{float alpha;};\n#define pbr_inline\nvoid alphaFresnelBlock(\nin vec3 normalW,\nin vec3 viewDirectionW,\nin float alpha,\nin float microSurface,\nout alphaFresnelOutParams outParams\n)\n{float opacityPerceptual=alpha;\n#ifdef LINEARALPHAFRESNEL\nfloat opacity0=opacityPerceptual;\n#else\nfloat opacity0=opacityPerceptual*opacityPerceptual;\n#endif\nfloat opacity90=fresnelGrazingReflectance(opacity0);vec3 normalForward=faceforward(normalW,-viewDirectionW,normalW);outParams.alpha=getReflectanceFromAnalyticalBRDFLookup_Jones(saturate(dot(viewDirectionW,normalForward)),vec3(opacity0),vec3(opacity90),sqrt(microSurface)).x;\n#ifdef ALPHATEST\nif (outParams.alpha0 && defined(ANISOTROPIC_TEXTURE)\nvec3 anisotropyMapData;\n#endif\n};\n#define pbr_inline\nvoid anisotropicBlock(\nin vec3 vAnisotropy,\nin float roughness,\n#ifdef ANISOTROPIC_TEXTURE\nin vec3 anisotropyMapData,\n#endif\nin mat3 TBN,\nin vec3 normalW,\nin vec3 viewDirectionW,\nout anisotropicOutParams outParams\n)\n{float anisotropy=vAnisotropy.b;vec3 anisotropyDirection=vec3(vAnisotropy.xy,0.);\n#ifdef ANISOTROPIC_TEXTURE\nanisotropy*=anisotropyMapData.b;\n#if DEBUGMODE>0\noutParams.anisotropyMapData=anisotropyMapData;\n#endif\nanisotropyMapData.rg=anisotropyMapData.rg*2.0-1.0;\n#ifdef ANISOTROPIC_LEGACY\nanisotropyDirection.rg*=anisotropyMapData.rg;\n#else\nanisotropyDirection.xy=mat2(anisotropyDirection.x,anisotropyDirection.y,-anisotropyDirection.y,anisotropyDirection.x)*normalize(anisotropyMapData.rg);\n#endif\n#endif\nmat3 anisoTBN=mat3(normalize(TBN[0]),normalize(TBN[1]),normalize(TBN[2]));vec3 anisotropicTangent=normalize(anisoTBN*anisotropyDirection);vec3 anisotropicBitangent=normalize(cross(anisoTBN[2],anisotropicTangent));outParams.anisotropy=anisotropy;outParams.anisotropicTangent=anisotropicTangent;outParams.anisotropicBitangent=anisotropicBitangent;outParams.anisotropicNormal=getAnisotropicBentNormals(anisotropicTangent,anisotropicBitangent,normalW,viewDirectionW,anisotropy,roughness);}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1m] = shader$1m;\n\n // Do not edit.\n const name$1n = \"pbrBlockReflection\";\n const shader$1n = `#ifdef REFLECTION\nstruct reflectionOutParams\n{vec4 environmentRadiance;vec3 environmentIrradiance;\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords;\n#else\nvec2 reflectionCoords;\n#endif\n#ifdef SS_TRANSLUCENCY\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nvec3 irradianceVector;\n#endif\n#endif\n#endif\n};\n#define pbr_inline\nvoid createReflectionCoords(\nin vec3 vPositionW,\nin vec3 normalW,\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#ifdef REFLECTIONMAP_3D\nout vec3 reflectionCoords\n#else\nout vec2 reflectionCoords\n#endif\n)\n{\n#ifdef ANISOTROPIC\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),anisotropicOut.anisotropicNormal);\n#else\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#endif\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\nreflectionCoords=reflectionVector;\n#else\nreflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n}\n#define pbr_inline\n#define inline\nvoid sampleReflectionTexture(\nin float alphaG,\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nin float NdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nin float roughness,\n#endif\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\nconst vec3 reflectionCoords,\n#else\nin sampler2D reflectionSampler,\nconst vec2 reflectionCoords,\n#endif\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\nout vec4 environmentRadiance\n)\n{\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);\n#elif defined(LINEARSPECULARREFLECTION)\nfloat reflectionLOD=getLinearLodFromRoughness(vReflectionMicrosurfaceInfos.x,roughness);\n#else\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG);\n#endif\n#ifdef LODBASEDMICROSFURACE\nreflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\n#ifdef LODINREFLECTIONALPHA\nfloat automaticReflectionLOD=UNPACK_LOD(sampleReflection(reflectionSampler,reflectionCoords).a);float requestedReflectionLOD=max(automaticReflectionLOD,reflectionLOD);\n#else\nfloat requestedReflectionLOD=reflectionLOD;\n#endif\n#ifdef REALTIME_FILTERING\nenvironmentRadiance=vec4(radiance(alphaG,reflectionSampler,reflectionCoords,vReflectionFilteringInfo),1.0);\n#else\nenvironmentRadiance=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);\n#endif\n#else\nfloat lodReflectionNormalized=saturate(reflectionLOD/log2(vReflectionMicrosurfaceInfos.x));float lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;vec4 environmentMid=sampleReflection(reflectionSampler,reflectionCoords);if (lodReflectionNormalizedDoubled<1.0){environmentRadiance=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords),\nenvironmentMid,\nlodReflectionNormalizedDoubled\n);} else {environmentRadiance=mix(\nenvironmentMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords),\nlodReflectionNormalizedDoubled-1.0\n);}\n#endif\n#ifdef RGBDREFLECTION\nenvironmentRadiance.rgb=fromRGBD(environmentRadiance);\n#endif\n#ifdef GAMMAREFLECTION\nenvironmentRadiance.rgb=toLinearSpace(environmentRadiance.rgb);\n#endif\nenvironmentRadiance.rgb*=vReflectionInfos.x;environmentRadiance.rgb*=vReflectionColor.rgb;}\n#define pbr_inline\n#define inline\nvoid reflectionBlock(\nin vec3 vPositionW,\nin vec3 normalW,\nin float alphaG,\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nin float NdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nin float roughness,\n#endif\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\n#else\nin sampler2D reflectionSampler,\n#endif\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nin vec3 vEnvironmentIrradiance,\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nin mat4 reflectionMatrix,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\n#ifdef REFLECTIONMAP_3D\nin samplerCube irradianceSampler,\n#else\nin sampler2D irradianceSampler,\n#endif\n#endif\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\nout reflectionOutParams outParams\n)\n{vec4 environmentRadiance=vec4(0.,0.,0.,0.);\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=vec3(0.);\n#else\nvec2 reflectionCoords=vec2(0.);\n#endif\ncreateReflectionCoords(\nvPositionW,\nnormalW,\n#ifdef ANISOTROPIC\nanisotropicOut,\n#endif\nreflectionCoords\n);sampleReflectionTexture(\nalphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nroughness,\n#endif\n#ifdef REFLECTIONMAP_3D\nreflectionSampler,\nreflectionCoords,\n#else\nreflectionSampler,\nreflectionCoords,\n#endif\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nenvironmentRadiance\n);vec3 environmentIrradiance=vec3(0.,0.,0.);\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nenvironmentIrradiance=vEnvironmentIrradiance;\n#else\n#ifdef ANISOTROPIC\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(anisotropicOut.anisotropicNormal,0)).xyz;\n#else\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#endif\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\n#ifdef INVERTCUBICMAP\nirradianceVector.y*=-1.0;\n#endif\n#if defined(REALTIME_FILTERING)\nenvironmentIrradiance=irradiance(reflectionSampler,irradianceVector,vReflectionFilteringInfo);\n#else\nenvironmentIrradiance=computeEnvironmentIrradiance(irradianceVector);\n#endif\n#ifdef SS_TRANSLUCENCY\noutParams.irradianceVector=irradianceVector;\n#endif\n#endif\n#elif defined(USEIRRADIANCEMAP)\nvec4 environmentIrradiance4=sampleReflection(irradianceSampler,reflectionCoords);environmentIrradiance=environmentIrradiance4.rgb;\n#ifdef RGBDREFLECTION\nenvironmentIrradiance.rgb=fromRGBD(environmentIrradiance4);\n#endif\n#ifdef GAMMAREFLECTION\nenvironmentIrradiance.rgb=toLinearSpace(environmentIrradiance.rgb);\n#endif\n#endif\nenvironmentIrradiance*=vReflectionColor.rgb;outParams.environmentRadiance=environmentRadiance;outParams.environmentIrradiance=environmentIrradiance;outParams.reflectionCoords=reflectionCoords;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1n] = shader$1n;\n\n // Do not edit.\n const name$1o = \"pbrBlockSheen\";\n const shader$1o = `#ifdef SHEEN\nstruct sheenOutParams\n{float sheenIntensity;vec3 sheenColor;float sheenRoughness;\n#ifdef SHEEN_LINKWITHALBEDO\nvec3 surfaceAlbedo;\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\nfloat sheenAlbedoScaling;\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nvec3 finalSheenRadianceScaled;\n#endif\n#if DEBUGMODE>0\n#ifdef SHEEN_TEXTURE\nvec4 sheenMapData;\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nvec3 sheenEnvironmentReflectance;\n#endif\n#endif\n};\n#define pbr_inline\n#define inline\nvoid sheenBlock(\nin vec4 vSheenColor,\n#ifdef SHEEN_ROUGHNESS\nin float vSheenRoughness,\n#if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)\nin vec4 sheenMapRoughnessData,\n#endif\n#endif\nin float roughness,\n#ifdef SHEEN_TEXTURE\nin vec4 sheenMapData,\nin float sheenMapLevel,\n#endif\nin float reflectance,\n#ifdef SHEEN_LINKWITHALBEDO\nin vec3 baseColor,\nin vec3 surfaceAlbedo,\n#endif\n#ifdef ENVIRONMENTBRDF\nin float NdotV,\nin vec3 environmentBrdf,\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nin vec2 AARoughnessFactors,\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\nin vec4 vLightingIntensity,\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\nin vec3 reflectionCoords,\n#else\nin sampler2D reflectionSampler,\nin vec2 reflectionCoords,\n#endif\nin float NdotVUnclamped,\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)\nin float seo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)\nin float eho,\n#endif\n#endif\nout sheenOutParams outParams\n)\n{float sheenIntensity=vSheenColor.a;\n#ifdef SHEEN_TEXTURE\n#if DEBUGMODE>0\noutParams.sheenMapData=sheenMapData;\n#endif\n#endif\n#ifdef SHEEN_LINKWITHALBEDO\nfloat sheenFactor=pow5(1.0-sheenIntensity);vec3 sheenColor=baseColor.rgb*(1.0-sheenFactor);float sheenRoughness=sheenIntensity;outParams.surfaceAlbedo=surfaceAlbedo*sheenFactor;\n#ifdef SHEEN_TEXTURE\nsheenIntensity*=sheenMapData.a;\n#endif\n#else\nvec3 sheenColor=vSheenColor.rgb;\n#ifdef SHEEN_TEXTURE\n#ifdef SHEEN_GAMMATEXTURE\nsheenColor.rgb*=toLinearSpace(sheenMapData.rgb);\n#else\nsheenColor.rgb*=sheenMapData.rgb;\n#endif\nsheenColor.rgb*=sheenMapLevel;\n#endif\n#ifdef SHEEN_ROUGHNESS\nfloat sheenRoughness=vSheenRoughness;\n#ifdef SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE\n#if defined(SHEEN_TEXTURE)\nsheenRoughness*=sheenMapData.a;\n#endif\n#elif defined(SHEEN_TEXTURE_ROUGHNESS)\n#ifdef SHEEN_TEXTURE_ROUGHNESS_IDENTICAL\nsheenRoughness*=sheenMapData.a;\n#else\nsheenRoughness*=sheenMapRoughnessData.a;\n#endif\n#endif\n#else\nfloat sheenRoughness=roughness;\n#ifdef SHEEN_TEXTURE\nsheenIntensity*=sheenMapData.a;\n#endif\n#endif\n#if !defined(SHEEN_ALBEDOSCALING)\nsheenIntensity*=(1.-reflectance);\n#endif\nsheenColor*=sheenIntensity;\n#endif\n#ifdef ENVIRONMENTBRDF\n/*#ifdef SHEEN_SOFTER\nvec3 environmentSheenBrdf=vec3(0.,0.,getBRDFLookupCharlieSheen(NdotV,sheenRoughness));\n#else*/\n#ifdef SHEEN_ROUGHNESS\nvec3 environmentSheenBrdf=getBRDFLookup(NdotV,sheenRoughness);\n#else\nvec3 environmentSheenBrdf=environmentBrdf;\n#endif\n/*#endif*/\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nfloat sheenAlphaG=convertRoughnessToAverageSlope(sheenRoughness);\n#ifdef SPECULARAA\nsheenAlphaG+=AARoughnessFactors.y;\n#endif\nvec4 environmentSheenRadiance=vec4(0.,0.,0.,0.);sampleReflectionTexture(\nsheenAlphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nsheenRoughness,\n#endif\nreflectionSampler,\nreflectionCoords,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nenvironmentSheenRadiance\n);vec3 sheenEnvironmentReflectance=getSheenReflectanceFromBRDFLookup(sheenColor,environmentSheenBrdf);\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)\nsheenEnvironmentReflectance*=seo;\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)\nsheenEnvironmentReflectance*=eho;\n#endif\n#if DEBUGMODE>0\noutParams.sheenEnvironmentReflectance=sheenEnvironmentReflectance;\n#endif\noutParams.finalSheenRadianceScaled=\nenvironmentSheenRadiance.rgb *\nsheenEnvironmentReflectance *\nvLightingIntensity.z;\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\noutParams.sheenAlbedoScaling=1.0-sheenIntensity*max(max(sheenColor.r,sheenColor.g),sheenColor.b)*environmentSheenBrdf.b;\n#endif\noutParams.sheenIntensity=sheenIntensity;outParams.sheenColor=sheenColor;outParams.sheenRoughness=sheenRoughness;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1o] = shader$1o;\n\n // Do not edit.\n const name$1p = \"pbrBlockClearcoat\";\n const shader$1p = `struct clearcoatOutParams\n{vec3 specularEnvironmentR0;float conservationFactor;vec3 clearCoatNormalW;vec2 clearCoatAARoughnessFactors;float clearCoatIntensity;float clearCoatRoughness;\n#ifdef REFLECTION\nvec3 finalClearCoatRadianceScaled;\n#endif\n#ifdef CLEARCOAT_TINT\nvec3 absorption;float clearCoatNdotVRefract;vec3 clearCoatColor;float clearCoatThickness;\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nvec3 energyConservationFactorClearCoat;\n#endif\n#if DEBUGMODE>0\n#ifdef CLEARCOAT_BUMP\nmat3 TBNClearCoat;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nvec2 clearCoatMapData;\n#endif\n#if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)\nvec4 clearCoatTintMapData;\n#endif\n#ifdef REFLECTION\nvec4 environmentClearCoatRadiance;vec3 clearCoatEnvironmentReflectance;\n#endif\nfloat clearCoatNdotV;\n#endif\n};\n#ifdef CLEARCOAT\n#define pbr_inline\n#define inline\nvoid clearcoatBlock(\nin vec3 vPositionW,\nin vec3 geometricNormalW,\nin vec3 viewDirectionW,\nin vec2 vClearCoatParams,\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\nin vec4 clearCoatMapRoughnessData,\n#endif\nin vec3 specularEnvironmentR0,\n#ifdef CLEARCOAT_TEXTURE\nin vec2 clearCoatMapData,\n#endif\n#ifdef CLEARCOAT_TINT\nin vec4 vClearCoatTintParams,\nin float clearCoatColorAtDistance,\nin vec4 vClearCoatRefractionParams,\n#ifdef CLEARCOAT_TINT_TEXTURE\nin vec4 clearCoatTintMapData,\n#endif\n#endif\n#ifdef CLEARCOAT_BUMP\nin vec2 vClearCoatBumpInfos,\nin vec4 clearCoatBumpMapData,\nin vec2 vClearCoatBumpUV,\n#if defined(TANGENT) && defined(NORMAL)\nin mat3 vTBN,\n#else\nin vec2 vClearCoatTangentSpaceParams,\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nin mat4 normalMatrix,\n#endif\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nin vec3 faceNormal,\n#endif\n#ifdef REFLECTION\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\nin vec4 vLightingIntensity,\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\n#else\nin sampler2D reflectionSampler,\n#endif\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n#ifdef RADIANCEOCCLUSION\nin float ambientMonochrome,\n#endif\n#endif\n#if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)\nin float frontFacingMultiplier,\n#endif\nout clearcoatOutParams outParams\n)\n{float clearCoatIntensity=vClearCoatParams.x;float clearCoatRoughness=vClearCoatParams.y;\n#ifdef CLEARCOAT_TEXTURE\nclearCoatIntensity*=clearCoatMapData.x;\n#ifdef CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE\nclearCoatRoughness*=clearCoatMapData.y;\n#endif\n#if DEBUGMODE>0\noutParams.clearCoatMapData=clearCoatMapData;\n#endif\n#endif\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL\nclearCoatRoughness*=clearCoatMapData.y;\n#else\nclearCoatRoughness*=clearCoatMapRoughnessData.y;\n#endif\n#endif\noutParams.clearCoatIntensity=clearCoatIntensity;outParams.clearCoatRoughness=clearCoatRoughness;\n#ifdef CLEARCOAT_TINT\nvec3 clearCoatColor=vClearCoatTintParams.rgb;float clearCoatThickness=vClearCoatTintParams.a;\n#ifdef CLEARCOAT_TINT_TEXTURE\n#ifdef CLEARCOAT_TINT_GAMMATEXTURE\nclearCoatColor*=toLinearSpace(clearCoatTintMapData.rgb);\n#else\nclearCoatColor*=clearCoatTintMapData.rgb;\n#endif\nclearCoatThickness*=clearCoatTintMapData.a;\n#if DEBUGMODE>0\noutParams.clearCoatTintMapData=clearCoatTintMapData;\n#endif\n#endif\noutParams.clearCoatColor=computeColorAtDistanceInMedia(clearCoatColor,clearCoatColorAtDistance);outParams.clearCoatThickness=clearCoatThickness;\n#endif\n#ifdef CLEARCOAT_REMAP_F0\nvec3 specularEnvironmentR0Updated=getR0RemappedForClearCoat(specularEnvironmentR0);\n#else\nvec3 specularEnvironmentR0Updated=specularEnvironmentR0;\n#endif\noutParams.specularEnvironmentR0=mix(specularEnvironmentR0,specularEnvironmentR0Updated,clearCoatIntensity);vec3 clearCoatNormalW=geometricNormalW;\n#ifdef CLEARCOAT_BUMP\n#ifdef NORMALXYSCALE\nfloat clearCoatNormalScale=1.0;\n#else\nfloat clearCoatNormalScale=vClearCoatBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBNClearCoat=vTBN;\n#else\nvec2 TBNClearCoatUV=vClearCoatBumpUV*frontFacingMultiplier;mat3 TBNClearCoat=cotangent_frame(clearCoatNormalW*clearCoatNormalScale,vPositionW,TBNClearCoatUV,vClearCoatTangentSpaceParams);\n#endif\n#if DEBUGMODE>0\noutParams.TBNClearCoat=TBNClearCoat;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nclearCoatNormalW=normalize(clearCoatBumpMapData.xyz *2.0-1.0);clearCoatNormalW=normalize(mat3(normalMatrix)*clearCoatNormalW);\n#else\nclearCoatNormalW=perturbNormal(TBNClearCoat,clearCoatBumpMapData.xyz,vClearCoatBumpInfos.y);\n#endif\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nclearCoatNormalW*=sign(dot(clearCoatNormalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nclearCoatNormalW=clearCoatNormalW*frontFacingMultiplier;\n#endif\noutParams.clearCoatNormalW=clearCoatNormalW;outParams.clearCoatAARoughnessFactors=getAARoughnessFactors(clearCoatNormalW.xyz);float clearCoatNdotVUnclamped=dot(clearCoatNormalW,viewDirectionW);float clearCoatNdotV=absEps(clearCoatNdotVUnclamped);\n#if DEBUGMODE>0\noutParams.clearCoatNdotV=clearCoatNdotV;\n#endif\n#ifdef CLEARCOAT_TINT\nvec3 clearCoatVRefract=refract(-viewDirectionW,clearCoatNormalW,vClearCoatRefractionParams.y);outParams.clearCoatNdotVRefract=absEps(dot(clearCoatNormalW,clearCoatVRefract));\n#endif\n#if defined(ENVIRONMENTBRDF) && (!defined(REFLECTIONMAP_SKYBOX) || defined(MS_BRDF_ENERGY_CONSERVATION))\nvec3 environmentClearCoatBrdf=getBRDFLookup(clearCoatNdotV,clearCoatRoughness);\n#endif\n#if defined(REFLECTION)\nfloat clearCoatAlphaG=convertRoughnessToAverageSlope(clearCoatRoughness);\n#ifdef SPECULARAA\nclearCoatAlphaG+=outParams.clearCoatAARoughnessFactors.y;\n#endif\nvec4 environmentClearCoatRadiance=vec4(0.,0.,0.,0.);vec3 clearCoatReflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),clearCoatNormalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nclearCoatReflectionVector.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\nvec3 clearCoatReflectionCoords=clearCoatReflectionVector;\n#else\nvec2 clearCoatReflectionCoords=clearCoatReflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nclearCoatReflectionCoords/=clearCoatReflectionVector.z;\n#endif\nclearCoatReflectionCoords.y=1.0-clearCoatReflectionCoords.y;\n#endif\nsampleReflectionTexture(\nclearCoatAlphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nclearCoatNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nclearCoatRoughness,\n#endif\nreflectionSampler,\nclearCoatReflectionCoords,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nenvironmentClearCoatRadiance\n);\n#if DEBUGMODE>0\noutParams.environmentClearCoatRadiance=environmentClearCoatRadiance;\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\nvec3 clearCoatEnvironmentReflectance=getReflectanceFromBRDFLookup(vec3(vClearCoatRefractionParams.x),environmentClearCoatBrdf);\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat clearCoatEho=environmentHorizonOcclusion(-viewDirectionW,clearCoatNormalW,geometricNormalW);clearCoatEnvironmentReflectance*=clearCoatEho;\n#endif\n#endif\n#endif\n#else\nvec3 clearCoatEnvironmentReflectance=getReflectanceFromAnalyticalBRDFLookup_Jones(clearCoatNdotV,vec3(1.),vec3(1.),sqrt(1.-clearCoatRoughness));\n#endif\nclearCoatEnvironmentReflectance*=clearCoatIntensity;\n#if DEBUGMODE>0\noutParams.clearCoatEnvironmentReflectance=clearCoatEnvironmentReflectance;\n#endif\noutParams.finalClearCoatRadianceScaled=\nenvironmentClearCoatRadiance.rgb *\nclearCoatEnvironmentReflectance *\nvLightingIntensity.z;\n#endif\n#if defined(CLEARCOAT_TINT)\noutParams.absorption=computeClearCoatAbsorption(outParams.clearCoatNdotVRefract,outParams.clearCoatNdotVRefract,outParams.clearCoatColor,clearCoatThickness,clearCoatIntensity);\n#endif\nfloat fresnelIBLClearCoat=fresnelSchlickGGX(clearCoatNdotV,vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnelIBLClearCoat*=clearCoatIntensity;outParams.conservationFactor=(1.-fresnelIBLClearCoat);\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\noutParams.energyConservationFactorClearCoat=getEnergyConservationFactor(outParams.specularEnvironmentR0,environmentClearCoatBrdf);\n#endif\n}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1p] = shader$1p;\n\n // Do not edit.\n const name$1q = \"pbrBlockIridescence\";\n const shader$1q = `struct iridescenceOutParams\n{float iridescenceIntensity;float iridescenceIOR;float iridescenceThickness;vec3 specularEnvironmentR0;};\n#ifdef IRIDESCENCE\n#define pbr_inline\n#define inline\nvoid iridescenceBlock(\nin vec4 vIridescenceParams,\nin float viewAngle,\nin vec3 specularEnvironmentR0,\n#ifdef IRIDESCENCE_TEXTURE\nin vec2 iridescenceMapData,\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nin vec2 iridescenceThicknessMapData,\n#endif\n#ifdef CLEARCOAT\nin float NdotVUnclamped,\n#ifdef CLEARCOAT_TEXTURE\nin vec2 clearCoatMapData,\n#endif\n#endif\nout iridescenceOutParams outParams\n)\n{float iridescenceIntensity=vIridescenceParams.x;float iridescenceIOR=vIridescenceParams.y;float iridescenceThicknessMin=vIridescenceParams.z;float iridescenceThicknessMax=vIridescenceParams.w;float iridescenceThicknessWeight=1.;\n#ifdef IRIDESCENCE_TEXTURE\niridescenceIntensity*=iridescenceMapData.x;\n#ifdef IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE\niridescenceThicknessWeight=iridescenceMapData.g;\n#endif\n#endif\n#if defined(IRIDESCENCE_THICKNESS_TEXTURE)\niridescenceThicknessWeight=iridescenceThicknessMapData.g;\n#endif\nfloat iridescenceThickness=mix(iridescenceThicknessMin,iridescenceThicknessMax,iridescenceThicknessWeight);float topIor=1.; \n#ifdef CLEARCOAT\nfloat clearCoatIntensity=vClearCoatParams.x;\n#ifdef CLEARCOAT_TEXTURE\nclearCoatIntensity*=clearCoatMapData.x;\n#endif\ntopIor=mix(1.0,vClearCoatRefractionParams.w-1.,clearCoatIntensity);viewAngle=sqrt(1.0+square(1.0/topIor)*(square(NdotVUnclamped)-1.0));\n#endif\nvec3 iridescenceFresnel=evalIridescence(topIor,iridescenceIOR,viewAngle,iridescenceThickness,specularEnvironmentR0);outParams.specularEnvironmentR0=mix(specularEnvironmentR0,iridescenceFresnel,iridescenceIntensity);outParams.iridescenceIntensity=iridescenceIntensity;outParams.iridescenceThickness=iridescenceThickness;outParams.iridescenceIOR=iridescenceIOR;}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1q] = shader$1q;\n\n // Do not edit.\n const name$1r = \"pbrBlockSubSurface\";\n const shader$1r = `struct subSurfaceOutParams\n{vec3 specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nvec3 finalRefraction;vec3 surfaceAlbedo;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nfloat alpha;\n#endif\n#ifdef REFLECTION\nfloat refractionFactorForIrradiance;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nvec3 transmittance;float translucencyIntensity;\n#ifdef REFLECTION\nvec3 refractionIrradiance;\n#endif\n#endif\n#if DEBUGMODE>0\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec4 thicknessMap;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction;vec3 refractionTransmittance;\n#endif\n#endif\n};\n#ifdef SUBSURFACE\n#define pbr_inline\n#define inline\nvoid subSurfaceBlock(\nin vec3 vSubSurfaceIntensity,\nin vec2 vThicknessParam,\nin vec4 vTintColor,\nin vec3 normalW,\nin vec3 specularEnvironmentReflectance,\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nin vec4 thicknessMap,\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nin vec4 refractionIntensityMap,\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nin vec4 translucencyIntensityMap,\n#endif\n#ifdef REFLECTION\n#ifdef SS_TRANSLUCENCY\nin mat4 reflectionMatrix,\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nin vec3 irradianceVector_,\n#endif\n#if defined(REALTIME_FILTERING)\nin samplerCube reflectionSampler,\nin vec2 vReflectionFilteringInfo,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\n#ifdef REFLECTIONMAP_3D\nin samplerCube irradianceSampler,\n#else\nin sampler2D irradianceSampler,\n#endif\n#endif\n#endif\n#endif\n#if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)\nin vec3 surfaceAlbedo,\n#endif\n#ifdef SS_REFRACTION\nin vec3 vPositionW,\nin vec3 viewDirectionW,\nin mat4 view,\nin vec4 vRefractionInfos,\nin mat4 refractionMatrix,\nin vec4 vRefractionMicrosurfaceInfos,\nin vec4 vLightingIntensity,\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nin float alpha,\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nin float NdotVUnclamped,\n#endif\n#ifdef SS_LINEARSPECULARREFRACTION\nin float roughness,\n#endif\nin float alphaG,\n#ifdef SS_REFRACTIONMAP_3D\nin samplerCube refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin samplerCube refractionSamplerLow,\nin samplerCube refractionSamplerHigh,\n#endif\n#else\nin sampler2D refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin sampler2D refractionSamplerLow,\nin sampler2D refractionSamplerHigh,\n#endif\n#endif\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vRefractionFilteringInfo,\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nin vec3 refractionPosition,\nin vec3 refractionSize,\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nin vec3 vDiffusionDistance,\n#endif\nout subSurfaceOutParams outParams\n)\n{outParams.specularEnvironmentReflectance=specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nfloat refractionIntensity=vSubSurfaceIntensity.x;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nrefractionIntensity*=(1.0-alpha);outParams.alpha=1.0;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nfloat translucencyIntensity=vSubSurfaceIntensity.y;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\n#if defined(SS_USE_GLTF_TEXTURES)\nfloat thickness=thicknessMap.g*vThicknessParam.y+vThicknessParam.x;\n#else\nfloat thickness=thicknessMap.r*vThicknessParam.y+vThicknessParam.x;\n#endif\n#if DEBUGMODE>0\noutParams.thicknessMap=thicknessMap;\n#endif\n#ifdef SS_MASK_FROM_THICKNESS_TEXTURE\n#if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE)\n#if defined(SS_USE_GLTF_TEXTURES)\nrefractionIntensity*=thicknessMap.r;\n#else\nrefractionIntensity*=thicknessMap.g;\n#endif\n#endif\n#if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE)\ntranslucencyIntensity*=thicknessMap.b;\n#endif\n#endif\n#else\nfloat thickness=vThicknessParam.y;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\n#ifdef SS_USE_GLTF_TEXTURES\nrefractionIntensity*=refractionIntensityMap.r;\n#else\nrefractionIntensity*=refractionIntensityMap.g;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\ntranslucencyIntensity*=translucencyIntensityMap.b;\n#endif\n#ifdef SS_TRANSLUCENCY\nthickness=maxEps(thickness);vec3 transmittance=transmittanceBRDF_Burley(vTintColor.rgb,vDiffusionDistance,thickness);transmittance*=translucencyIntensity;outParams.transmittance=transmittance;outParams.translucencyIntensity=translucencyIntensity;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction=vec4(0.,0.,0.,0.);\n#ifdef ANISOTROPIC\nvec3 refractionVector=refract(-viewDirectionW,anisotropicOut.anisotropicNormal,vRefractionInfos.y);\n#else\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#endif\n#ifdef SS_REFRACTIONMAP_OPPOSITEZ\nrefractionVector.z*=-1.0;\n#endif\n#ifdef SS_REFRACTIONMAP_3D\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,refractionSize,refractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec3 refractionCoords=refractionVector;refractionCoords=vec3(refractionMatrix*vec4(refractionCoords,0));\n#else\n#ifdef SS_USE_THICKNESS_AS_DEPTH\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*thickness,1.0)));\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n#endif\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;\n#endif\n#ifdef SS_HAS_THICKNESS\nfloat ior=vRefractionInfos.y;\n#else\nfloat ior=vRefractionMicrosurfaceInfos.w;\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG,NdotVUnclamped);\n#elif defined(SS_LINEARSPECULARREFRACTION)\nfloat refractionRoughness=alphaG;refractionRoughness=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLinearLodFromRoughness(vRefractionMicrosurfaceInfos.x,refractionRoughness);\n#else\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG);\n#endif\n#ifdef LODBASEDMICROSFURACE\nrefractionLOD=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;\n#ifdef SS_LODINREFRACTIONALPHA\nfloat automaticRefractionLOD=UNPACK_LOD(sampleRefraction(refractionSampler,refractionCoords).a);float requestedRefractionLOD=max(automaticRefractionLOD,refractionLOD);\n#else\nfloat requestedRefractionLOD=refractionLOD;\n#endif\n#if defined(REALTIME_FILTERING) && defined(SS_REFRACTIONMAP_3D)\nenvironmentRefraction=vec4(radiance(alphaG,refractionSampler,refractionCoords,vRefractionFilteringInfo),1.0);\n#else\nenvironmentRefraction=sampleRefractionLod(refractionSampler,refractionCoords,requestedRefractionLOD);\n#endif\n#else\nfloat lodRefractionNormalized=saturate(refractionLOD/log2(vRefractionMicrosurfaceInfos.x));float lodRefractionNormalizedDoubled=lodRefractionNormalized*2.0;vec4 environmentRefractionMid=sampleRefraction(refractionSampler,refractionCoords);if (lodRefractionNormalizedDoubled<1.0){environmentRefraction=mix(\nsampleRefraction(refractionSamplerHigh,refractionCoords),\nenvironmentRefractionMid,\nlodRefractionNormalizedDoubled\n);} else {environmentRefraction=mix(\nenvironmentRefractionMid,\nsampleRefraction(refractionSamplerLow,refractionCoords),\nlodRefractionNormalizedDoubled-1.0\n);}\n#endif\n#ifdef SS_RGBDREFRACTION\nenvironmentRefraction.rgb=fromRGBD(environmentRefraction);\n#endif\n#ifdef SS_GAMMAREFRACTION\nenvironmentRefraction.rgb=toLinearSpace(environmentRefraction.rgb);\n#endif\nenvironmentRefraction.rgb*=vRefractionInfos.x;\n#endif\n#ifdef SS_REFRACTION\nvec3 refractionTransmittance=vec3(refractionIntensity);\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,thickness);\n#elif defined(SS_LINKREFRACTIONTOTRANSPARENCY)\nfloat maxChannel=max(max(surfaceAlbedo.r,surfaceAlbedo.g),surfaceAlbedo.b);vec3 volumeAlbedo=saturate(maxChannel*surfaceAlbedo);environmentRefraction.rgb*=volumeAlbedo;\n#else\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,vThicknessParam.y);\n#endif\n#ifdef SS_ALBEDOFORREFRACTIONTINT\nenvironmentRefraction.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.surfaceAlbedo=surfaceAlbedo*(1.-refractionIntensity);\n#ifdef REFLECTION\noutParams.refractionFactorForIrradiance=(1.-refractionIntensity);\n#endif\n#ifdef UNUSED_MULTIPLEBOUNCES\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);outParams.specularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,refractionIntensity);\n#endif\nrefractionTransmittance*=1.0-outParams.specularEnvironmentReflectance;\n#if DEBUGMODE>0\noutParams.refractionTransmittance=refractionTransmittance;\n#endif\noutParams.finalRefraction=environmentRefraction.rgb*refractionTransmittance*vLightingIntensity.z;\n#if DEBUGMODE>0\noutParams.environmentRefraction=environmentRefraction;\n#endif\n#endif\n#if defined(REFLECTION) && defined(SS_TRANSLUCENCY)\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX) || !defined(USESPHERICALFROMREFLECTIONMAP)\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\n#ifdef INVERTCUBICMAP\nirradianceVector.y*=-1.0;\n#endif\n#else\nvec3 irradianceVector=irradianceVector_;\n#endif\n#if defined(USESPHERICALFROMREFLECTIONMAP)\n#if defined(REALTIME_FILTERING)\nvec3 refractionIrradiance=irradiance(reflectionSampler,-irradianceVector,vReflectionFilteringInfo);\n#else\nvec3 refractionIrradiance=computeEnvironmentIrradiance(-irradianceVector);\n#endif\n#elif defined(USEIRRADIANCEMAP)\n#ifdef REFLECTIONMAP_3D\nvec3 irradianceCoords=irradianceVector;\n#else\nvec2 irradianceCoords=irradianceVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nirradianceCoords/=irradianceVector.z;\n#endif\nirradianceCoords.y=1.0-irradianceCoords.y;\n#endif\nvec4 refractionIrradiance=sampleReflection(irradianceSampler,-irradianceCoords);\n#ifdef RGBDREFLECTION\nrefractionIrradiance.rgb=fromRGBD(refractionIrradiance);\n#endif\n#ifdef GAMMAREFLECTION\nrefractionIrradiance.rgb=toLinearSpace(refractionIrradiance.rgb);\n#endif\n#else\nvec4 refractionIrradiance=vec4(0.);\n#endif\nrefractionIrradiance.rgb*=transmittance;\n#ifdef SS_ALBEDOFORTRANSLUCENCYTINT\nrefractionIrradiance.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.refractionIrradiance=refractionIrradiance.rgb;\n#endif\n}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1r] = shader$1r;\n\n // Do not edit.\n const name$1s = \"pbrBlockNormalGeometric\";\n const shader$1s = `vec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#endif\nvec3 geometricNormalW=normalW;\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\ngeometricNormalW=gl_FrontFacing ? geometricNormalW : -geometricNormalW;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1s] = shader$1s;\n\n // Do not edit.\n const name$1t = \"pbrBlockNormalFinal\";\n const shader$1t = `#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nvec3 faceNormal=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#if defined(TWOSIDEDLIGHTING)\nfaceNormal=gl_FrontFacing ? faceNormal : -faceNormal;\n#endif\nnormalW*=sign(dot(normalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1t] = shader$1t;\n\n // Do not edit.\n const name$1u = \"pbrBlockLightmapInit\";\n const shader$1u = `#ifdef LIGHTMAP\nvec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);\n#ifdef RGBDLIGHTMAP\nlightmapColor.rgb=fromRGBD(lightmapColor);\n#endif\n#ifdef GAMMALIGHTMAP\nlightmapColor.rgb=toLinearSpace(lightmapColor.rgb);\n#endif\nlightmapColor.rgb*=vLightmapInfos.y;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1u] = shader$1u;\n\n // Do not edit.\n const name$1v = \"pbrBlockGeometryInfo\";\n const shader$1v = `float NdotVUnclamped=dot(normalW,viewDirectionW);float NdotV=absEps(NdotVUnclamped);float alphaG=convertRoughnessToAverageSlope(roughness);vec2 AARoughnessFactors=getAARoughnessFactors(normalW.xyz);\n#ifdef SPECULARAA\nalphaG+=AARoughnessFactors.y;\n#endif\n#if defined(ENVIRONMENTBRDF)\nvec3 environmentBrdf=getBRDFLookup(NdotV,roughness);\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n#ifdef RADIANCEOCCLUSION\n#ifdef AMBIENTINGRAYSCALE\nfloat ambientMonochrome=aoOut.ambientOcclusionColor.r;\n#else\nfloat ambientMonochrome=getLuminance(aoOut.ambientOcclusionColor);\n#endif\nfloat seo=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat eho=environmentHorizonOcclusion(-viewDirectionW,normalW,geometricNormalW);\n#endif\n#endif\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1v] = shader$1v;\n\n // Do not edit.\n const name$1w = \"pbrBlockReflectance0\";\n const shader$1w = `float reflectance=max(max(reflectivityOut.surfaceReflectivityColor.r,reflectivityOut.surfaceReflectivityColor.g),reflectivityOut.surfaceReflectivityColor.b);vec3 specularEnvironmentR0=reflectivityOut.surfaceReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec3 specularEnvironmentR90=vec3(metallicReflectanceFactors.a);\n#else \nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\n#endif\n#ifdef ALPHAFRESNEL\nfloat reflectance90=fresnelGrazingReflectance(reflectance);specularEnvironmentR90=specularEnvironmentR90*reflectance90;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1w] = shader$1w;\n\n // Do not edit.\n const name$1x = \"pbrBlockReflectance\";\n const shader$1x = `#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\nvec3 specularEnvironmentReflectance=getReflectanceFromBRDFLookup(clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,environmentBrdf);\n#ifdef RADIANCEOCCLUSION\nspecularEnvironmentReflectance*=seo;\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nspecularEnvironmentReflectance*=eho;\n#endif\n#endif\n#endif\n#else\nvec3 specularEnvironmentReflectance=getReflectanceFromAnalyticalBRDFLookup_Jones(NdotV,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n#endif\n#ifdef CLEARCOAT\nspecularEnvironmentReflectance*=clearcoatOut.conservationFactor;\n#if defined(CLEARCOAT_TINT)\nspecularEnvironmentReflectance*=clearcoatOut.absorption;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1x] = shader$1x;\n\n // Do not edit.\n const name$1y = \"pbrBlockDirectLighting\";\n const shader$1y = `vec3 diffuseBase=vec3(0.,0.,0.);\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#ifdef CLEARCOAT\nvec3 clearCoatBase=vec3(0.,0.,0.);\n#endif\n#ifdef SHEEN\nvec3 sheenBase=vec3(0.,0.,0.);\n#endif\npreLightingInfo preInfo;lightingInfo info;float shadow=1.; \n#if defined(CLEARCOAT) && defined(CLEARCOAT_TINT)\nvec3 absorption=vec3(0.);\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1y] = shader$1y;\n\n // Do not edit.\n const name$1z = \"pbrBlockFinalLitComponents\";\n const shader$1z = `#if defined(ENVIRONMENTBRDF)\n#ifdef MS_BRDF_ENERGY_CONSERVATION\nvec3 energyConservationFactor=getEnergyConservationFactor(clearcoatOut.specularEnvironmentR0,environmentBrdf);\n#endif\n#endif\n#ifndef METALLICWORKFLOW\n#ifdef SPECULAR_GLOSSINESS_ENERGY_CONSERVATION\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\n#endif\n#endif\n#if defined(SHEEN) && defined(SHEEN_ALBEDOSCALING) && defined(ENVIRONMENTBRDF)\nsurfaceAlbedo.rgb=sheenOut.sheenAlbedoScaling*surfaceAlbedo.rgb;\n#endif\n#ifdef REFLECTION\nvec3 finalIrradiance=reflectionOut.environmentIrradiance;\n#if defined(CLEARCOAT)\nfinalIrradiance*=clearcoatOut.conservationFactor;\n#if defined(CLEARCOAT_TINT)\nfinalIrradiance*=clearcoatOut.absorption;\n#endif\n#endif\n#if defined(SS_REFRACTION)\nfinalIrradiance*=subSurfaceOut.refractionFactorForIrradiance;\n#endif\n#if defined(SS_TRANSLUCENCY)\nfinalIrradiance*=(1.0-subSurfaceOut.translucencyIntensity);finalIrradiance+=subSurfaceOut.refractionIrradiance;\n#endif\nfinalIrradiance*=surfaceAlbedo.rgb;finalIrradiance*=vLightingIntensity.z;finalIrradiance*=aoOut.ambientOcclusionColor;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase;finalSpecular=max(finalSpecular,0.0);vec3 finalSpecularScaled=finalSpecular*vLightingIntensity.x*vLightingIntensity.w;\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nfinalSpecularScaled*=energyConservationFactor;\n#endif\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\nfinalSpecularScaled*=sheenOut.sheenAlbedoScaling;\n#endif\n#endif\n#ifdef REFLECTION\nvec3 finalRadiance=reflectionOut.environmentRadiance.rgb;finalRadiance*=subSurfaceOut.specularEnvironmentReflectance;vec3 finalRadianceScaled=finalRadiance*vLightingIntensity.z;\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nfinalRadianceScaled*=energyConservationFactor;\n#endif\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\nfinalRadianceScaled*=sheenOut.sheenAlbedoScaling;\n#endif\n#endif\n#ifdef SHEEN\nvec3 finalSheen=sheenBase*sheenOut.sheenColor;finalSheen=max(finalSheen,0.0);vec3 finalSheenScaled=finalSheen*vLightingIntensity.x*vLightingIntensity.w;\n#if defined(CLEARCOAT) && defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nsheenOut.finalSheenRadianceScaled*=clearcoatOut.conservationFactor;\n#if defined(CLEARCOAT_TINT)\nsheenOut.finalSheenRadianceScaled*=clearcoatOut.absorption;\n#endif\n#endif\n#endif\n#ifdef CLEARCOAT\nvec3 finalClearCoat=clearCoatBase;finalClearCoat=max(finalClearCoat,0.0);vec3 finalClearCoatScaled=finalClearCoat*vLightingIntensity.x*vLightingIntensity.w;\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nfinalClearCoatScaled*=clearcoatOut.energyConservationFactorClearCoat;\n#endif\n#ifdef SS_REFRACTION\nsubSurfaceOut.finalRefraction*=clearcoatOut.conservationFactor;\n#ifdef CLEARCOAT_TINT\nsubSurfaceOut.finalRefraction*=clearcoatOut.absorption;\n#endif\n#endif\n#endif\n#ifdef ALPHABLEND\nfloat luminanceOverAlpha=0.0;\n#if defined(REFLECTION) && defined(RADIANCEOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalRadianceScaled);\n#if defined(CLEARCOAT)\nluminanceOverAlpha+=getLuminance(clearcoatOut.finalClearCoatRadianceScaled);\n#endif\n#endif\n#if defined(SPECULARTERM) && defined(SPECULAROVERALPHA)\nluminanceOverAlpha+=getLuminance(finalSpecularScaled);\n#endif\n#if defined(CLEARCOAT) && defined(CLEARCOATOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalClearCoatScaled);\n#endif\n#if defined(RADIANCEOVERALPHA) || defined(SPECULAROVERALPHA) || defined(CLEARCOATOVERALPHA)\nalpha=saturate(alpha+luminanceOverAlpha*luminanceOverAlpha);\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1z] = shader$1z;\n\n // Do not edit.\n const name$1A = \"pbrBlockFinalUnlitComponents\";\n const shader$1A = `vec3 finalDiffuse=diffuseBase;finalDiffuse*=surfaceAlbedo.rgb;finalDiffuse=max(finalDiffuse,0.0);finalDiffuse*=vLightingIntensity.x;vec3 finalAmbient=vAmbientColor;finalAmbient*=surfaceAlbedo.rgb;vec3 finalEmissive=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\n#ifdef GAMMAEMISSIVE\nfinalEmissive*=toLinearSpace(emissiveColorTex.rgb);\n#else\nfinalEmissive*=emissiveColorTex.rgb;\n#endif\nfinalEmissive*= vEmissiveInfos.y;\n#endif\nfinalEmissive*=vLightingIntensity.y;\n#ifdef AMBIENT\nvec3 ambientOcclusionForDirectDiffuse=mix(vec3(1.),aoOut.ambientOcclusionColor,vAmbientInfos.w);\n#else\nvec3 ambientOcclusionForDirectDiffuse=aoOut.ambientOcclusionColor;\n#endif\nfinalAmbient*=aoOut.ambientOcclusionColor;finalDiffuse*=ambientOcclusionForDirectDiffuse;\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1A] = shader$1A;\n\n // Do not edit.\n const name$1B = \"pbrBlockFinalColorComposition\";\n const shader$1B = `vec4 finalColor=vec4(\n#ifndef UNLIT\n#ifdef REFLECTION\nfinalIrradiance +\n#endif\n#ifdef SPECULARTERM\nfinalSpecularScaled +\n#endif\n#ifdef SHEEN\nfinalSheenScaled +\n#endif\n#ifdef CLEARCOAT\nfinalClearCoatScaled +\n#endif\n#ifdef REFLECTION\nfinalRadianceScaled +\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF)\nsheenOut.finalSheenRadianceScaled +\n#endif\n#ifdef CLEARCOAT\nclearcoatOut.finalClearCoatRadianceScaled +\n#endif\n#endif\n#ifdef SS_REFRACTION\nsubSurfaceOut.finalRefraction +\n#endif\n#endif\nfinalAmbient +\nfinalDiffuse,\nalpha);\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor.rgb;\n#else\nfinalColor.rgb+=lightmapColor.rgb;\n#endif\n#endif\n#endif\nfinalColor.rgb+=finalEmissive;\n#define CUSTOM_FRAGMENT_BEFORE_FOG\nfinalColor=max(finalColor,0.0);\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1B] = shader$1B;\n\n // Do not edit.\n const name$1C = \"pbrBlockImageProcessing\";\n const shader$1C = `#if defined(IMAGEPROCESSINGPOSTPROCESS) || defined(SS_SCATTERING)\n#if !defined(SKIPFINALCOLORCLAMP)\nfinalColor.rgb=clamp(finalColor.rgb,0.,30.0);\n#endif\n#else\nfinalColor=applyImageProcessing(finalColor);\n#endif\nfinalColor.a*=visibility;\n#ifdef PREMULTIPLYALPHA\nfinalColor.rgb*=finalColor.a;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1C] = shader$1C;\n\n // Do not edit.\n const name$1D = \"pbrDebug\";\n const shader$1D = `#if DEBUGMODE>0\nif (vClipSpacePosition.x/vClipSpacePosition.w>=vDebugMode.x) {\n#if DEBUGMODE==1\ngl_FragColor.rgb=vPositionW.rgb;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==2 && defined(NORMAL)\ngl_FragColor.rgb=vNormalW.rgb;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==3 && defined(BUMP) || DEBUGMODE==3 && defined(PARALLAX) || DEBUGMODE==3 && defined(ANISOTROPIC)\ngl_FragColor.rgb=TBN[0];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==4 && defined(BUMP) || DEBUGMODE==4 && defined(PARALLAX) || DEBUGMODE==4 && defined(ANISOTROPIC)\ngl_FragColor.rgb=TBN[1];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==5\ngl_FragColor.rgb=normalW;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==6 && defined(MAINUV1)\ngl_FragColor.rgb=vec3(vMainUV1,0.0);\n#elif DEBUGMODE==7 && defined(MAINUV2)\ngl_FragColor.rgb=vec3(vMainUV2,0.0);\n#elif DEBUGMODE==8 && defined(CLEARCOAT) && defined(CLEARCOAT_BUMP)\ngl_FragColor.rgb=clearcoatOut.TBNClearCoat[0];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==9 && defined(CLEARCOAT) && defined(CLEARCOAT_BUMP)\ngl_FragColor.rgb=clearcoatOut.TBNClearCoat[1];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==10 && defined(CLEARCOAT)\ngl_FragColor.rgb=clearcoatOut.clearCoatNormalW;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==11 && defined(ANISOTROPIC)\ngl_FragColor.rgb=anisotropicOut.anisotropicNormal;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==12 && defined(ANISOTROPIC)\ngl_FragColor.rgb=anisotropicOut.anisotropicTangent;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==13 && defined(ANISOTROPIC)\ngl_FragColor.rgb=anisotropicOut.anisotropicBitangent;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==20 && defined(ALBEDO)\ngl_FragColor.rgb=albedoTexture.rgb;\n#ifndef GAMMAALBEDO\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==21 && defined(AMBIENT)\ngl_FragColor.rgb=aoOut.ambientOcclusionColorMap.rgb;\n#elif DEBUGMODE==22 && defined(OPACITY)\ngl_FragColor.rgb=opacityMap.rgb;\n#elif DEBUGMODE==23 && defined(EMISSIVE)\ngl_FragColor.rgb=emissiveColorTex.rgb;\n#ifndef GAMMAEMISSIVE\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==24 && defined(LIGHTMAP)\ngl_FragColor.rgb=lightmapColor.rgb;\n#ifndef GAMMALIGHTMAP\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==25 && defined(REFLECTIVITY) && defined(METALLICWORKFLOW)\ngl_FragColor.rgb=reflectivityOut.surfaceMetallicColorMap.rgb;\n#elif DEBUGMODE==26 && defined(REFLECTIVITY) && !defined(METALLICWORKFLOW)\ngl_FragColor.rgb=reflectivityOut.surfaceReflectivityColorMap.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==27 && defined(CLEARCOAT) && defined(CLEARCOAT_TEXTURE)\ngl_FragColor.rgb=vec3(clearcoatOut.clearCoatMapData.rg,0.0);\n#elif DEBUGMODE==28 && defined(CLEARCOAT) && defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)\ngl_FragColor.rgb=clearcoatOut.clearCoatTintMapData.rgb;\n#elif DEBUGMODE==29 && defined(SHEEN) && defined(SHEEN_TEXTURE)\ngl_FragColor.rgb=sheenOut.sheenMapData.rgb;\n#elif DEBUGMODE==30 && defined(ANISOTROPIC) && defined(ANISOTROPIC_TEXTURE)\ngl_FragColor.rgb=anisotropicOut.anisotropyMapData.rgb;\n#elif DEBUGMODE==31 && defined(SUBSURFACE) && defined(SS_THICKNESSANDMASK_TEXTURE)\ngl_FragColor.rgb=subSurfaceOut.thicknessMap.rgb;\n#elif DEBUGMODE==32 && defined(BUMP)\ngl_FragColor.rgb=texture2D(bumpSampler,vBumpUV).rgb;\n#elif DEBUGMODE==40 && defined(SS_REFRACTION)\ngl_FragColor.rgb=subSurfaceOut.environmentRefraction.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==41 && defined(REFLECTION)\ngl_FragColor.rgb=reflectionOut.environmentRadiance.rgb;\n#ifndef GAMMAREFLECTION\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==42 && defined(CLEARCOAT) && defined(REFLECTION)\ngl_FragColor.rgb=clearcoatOut.environmentClearCoatRadiance.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==50\ngl_FragColor.rgb=diffuseBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==51 && defined(SPECULARTERM)\ngl_FragColor.rgb=specularBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==52 && defined(CLEARCOAT)\ngl_FragColor.rgb=clearCoatBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==53 && defined(SHEEN)\ngl_FragColor.rgb=sheenBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==54 && defined(REFLECTION)\ngl_FragColor.rgb=reflectionOut.environmentIrradiance.rgb;\n#ifndef GAMMAREFLECTION\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==60\ngl_FragColor.rgb=surfaceAlbedo.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==61\ngl_FragColor.rgb=clearcoatOut.specularEnvironmentR0;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==62 && defined(METALLICWORKFLOW)\ngl_FragColor.rgb=vec3(reflectivityOut.metallicRoughness.r);\n#elif DEBUGMODE==71 && defined(METALLICWORKFLOW)\ngl_FragColor.rgb=reflectivityOut.metallicF0;\n#elif DEBUGMODE==63\ngl_FragColor.rgb=vec3(roughness);\n#elif DEBUGMODE==64\ngl_FragColor.rgb=vec3(alphaG);\n#elif DEBUGMODE==65\ngl_FragColor.rgb=vec3(NdotV);\n#elif DEBUGMODE==66 && defined(CLEARCOAT) && defined(CLEARCOAT_TINT)\ngl_FragColor.rgb=clearcoatOut.clearCoatColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==67 && defined(CLEARCOAT)\ngl_FragColor.rgb=vec3(clearcoatOut.clearCoatRoughness);\n#elif DEBUGMODE==68 && defined(CLEARCOAT)\ngl_FragColor.rgb=vec3(clearcoatOut.clearCoatNdotV);\n#elif DEBUGMODE==69 && defined(SUBSURFACE) && defined(SS_TRANSLUCENCY)\ngl_FragColor.rgb=subSurfaceOut.transmittance;\n#elif DEBUGMODE==70 && defined(SUBSURFACE) && defined(SS_REFRACTION)\ngl_FragColor.rgb=subSurfaceOut.refractionTransmittance;\n#elif DEBUGMODE==72\ngl_FragColor.rgb=vec3(microSurface);\n#elif DEBUGMODE==73\ngl_FragColor.rgb=vAlbedoColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==74 && !defined(METALLICWORKFLOW)\ngl_FragColor.rgb=vReflectivityColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==75\ngl_FragColor.rgb=vEmissiveColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==80 && defined(RADIANCEOCCLUSION)\ngl_FragColor.rgb=vec3(seo);\n#elif DEBUGMODE==81 && defined(HORIZONOCCLUSION)\ngl_FragColor.rgb=vec3(eho);\n#elif DEBUGMODE==82 && defined(MS_BRDF_ENERGY_CONSERVATION)\ngl_FragColor.rgb=vec3(energyConservationFactor);\n#elif DEBUGMODE==83 && defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\ngl_FragColor.rgb=specularEnvironmentReflectance;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==84 && defined(CLEARCOAT) && defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\ngl_FragColor.rgb=clearcoatOut.clearCoatEnvironmentReflectance;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==85 && defined(SHEEN) && defined(REFLECTION)\ngl_FragColor.rgb=sheenOut.sheenEnvironmentReflectance;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==86 && defined(ALPHABLEND)\ngl_FragColor.rgb=vec3(luminanceOverAlpha);\n#elif DEBUGMODE==87\ngl_FragColor.rgb=vec3(alpha);\n#elif DEBUGMODE==88 && defined(ALBEDO)\ngl_FragColor.rgb=vec3(albedoTexture.a);\n#else\nfloat stripeWidth=30.;float stripePos=floor((gl_FragCoord.x+gl_FragCoord.y)/stripeWidth);float whichColor=mod(stripePos,2.);vec3 color1=vec3(.6,.2,.2);vec3 color2=vec3(.3,.1,.1);gl_FragColor.rgb=mix(color1,color2,whichColor);\n#endif\ngl_FragColor.rgb*=vDebugMode.y;\n#ifdef DEBUGMODE_NORMALIZE\ngl_FragColor.rgb=normalize(gl_FragColor.rgb)*0.5+0.5;\n#endif\n#ifdef DEBUGMODE_GAMMA\ngl_FragColor.rgb=toGammaSpace(gl_FragColor.rgb);\n#endif\ngl_FragColor.a=1.0;\n#ifdef PREPASS\ngl_FragData[0]=toLinearSpace(gl_FragColor); \ngl_FragData[1]=vec4(0.,0.,0.,0.); \n#endif\n}\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1D] = shader$1D;\n\n // Do not edit.\n const name$1E = \"pbrPixelShader\";\n const shader$1E = `#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD) || defined(SPECULARAA) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#include[SCENE_MRT_COUNT]\nprecision highp float;\n#include\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE\n#endif\n#include<__decl__pbrFragment>\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#ifdef REFLECTION\n#include\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\n#include\n#include\n#include\nalbedoOpacityOutParams albedoOpacityOut;\n#ifdef ALBEDO\nvec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#endif\n#ifdef DECAL\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#endif\nalbedoOpacityBlock(\nvAlbedoColor,\n#ifdef ALBEDO\nalbedoTexture,\nvAlbedoInfos,\n#endif\n#ifdef OPACITY\nopacityMap,\nvOpacityInfos,\n#endif\n#ifdef DETAIL\ndetailColor,\nvDetailInfos,\n#endif\n#ifdef DECAL\ndecalColor,\nvDecalInfos,\n#endif\nalbedoOpacityOut\n);vec3 surfaceAlbedo=albedoOpacityOut.surfaceAlbedo;float alpha=albedoOpacityOut.alpha;\n#define CUSTOM_FRAGMENT_UPDATE_ALPHA\n#include\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\nambientOcclusionOutParams aoOut;\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb;\n#endif\nambientOcclusionBlock(\n#ifdef AMBIENT\nambientOcclusionColorMap,\nvAmbientInfos,\n#endif\naoOut\n);\n#include\n#ifdef UNLIT\nvec3 diffuseBase=vec3(1.,1.,1.);\n#else\nvec3 baseColor=surfaceAlbedo;reflectivityOutParams reflectivityOut;\n#if defined(REFLECTIVITY)\nvec4 surfaceMetallicOrReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);vec4 baseReflectivity=surfaceMetallicOrReflectivityColorMap;\n#ifndef METALLICWORKFLOW\n#ifdef REFLECTIVITY_GAMMA\nsurfaceMetallicOrReflectivityColorMap=toLinearSpace(surfaceMetallicOrReflectivityColorMap);\n#endif\nsurfaceMetallicOrReflectivityColorMap.rgb*=vReflectivityInfos.y;\n#endif\n#endif\n#if defined(MICROSURFACEMAP)\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\n#endif\n#ifdef METALLICWORKFLOW\nvec4 metallicReflectanceFactors=vMetallicReflectanceFactors;\n#ifdef REFLECTANCE\nvec4 reflectanceFactorsMap=texture2D(reflectanceSampler,vReflectanceUV+uvOffset);\n#ifdef REFLECTANCE_GAMMA\nreflectanceFactorsMap=toLinearSpace(reflectanceFactorsMap);\n#endif\nmetallicReflectanceFactors.rgb*=reflectanceFactorsMap.rgb;\n#endif\n#ifdef METALLIC_REFLECTANCE\nvec4 metallicReflectanceFactorsMap=texture2D(metallicReflectanceSampler,vMetallicReflectanceUV+uvOffset);\n#ifdef METALLIC_REFLECTANCE_GAMMA\nmetallicReflectanceFactorsMap=toLinearSpace(metallicReflectanceFactorsMap);\n#endif\n#ifndef METALLIC_REFLECTANCE_USE_ALPHA_ONLY\nmetallicReflectanceFactors.rgb*=metallicReflectanceFactorsMap.rgb;\n#endif\nmetallicReflectanceFactors*=metallicReflectanceFactorsMap.a;\n#endif\n#endif\nreflectivityBlock(\nvReflectivityColor,\n#ifdef METALLICWORKFLOW\nsurfaceAlbedo,\nmetallicReflectanceFactors,\n#endif\n#ifdef REFLECTIVITY\nvReflectivityInfos,\nsurfaceMetallicOrReflectivityColorMap,\n#endif\n#if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)\naoOut.ambientOcclusionColor,\n#endif\n#ifdef MICROSURFACEMAP\nmicroSurfaceTexel,\n#endif\n#ifdef DETAIL\ndetailColor,\nvDetailInfos,\n#endif\nreflectivityOut\n);float microSurface=reflectivityOut.microSurface;float roughness=reflectivityOut.roughness;\n#ifdef METALLICWORKFLOW\nsurfaceAlbedo=reflectivityOut.surfaceAlbedo;\n#endif\n#if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)\naoOut.ambientOcclusionColor=reflectivityOut.ambientOcclusionColor;\n#endif\n#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\nalphaFresnelOutParams alphaFresnelOut;alphaFresnelBlock(\nnormalW,\nviewDirectionW,\nalpha,\nmicroSurface,\nalphaFresnelOut\n);alpha=alphaFresnelOut.alpha;\n#endif\n#endif\n#include\n#ifdef ANISOTROPIC\nanisotropicOutParams anisotropicOut;\n#ifdef ANISOTROPIC_TEXTURE\nvec3 anisotropyMapData=texture2D(anisotropySampler,vAnisotropyUV+uvOffset).rgb*vAnisotropyInfos.y;\n#endif\nanisotropicBlock(\nvAnisotropy,\nroughness,\n#ifdef ANISOTROPIC_TEXTURE\nanisotropyMapData,\n#endif\nTBN,\nnormalW,\nviewDirectionW,\nanisotropicOut\n);\n#endif\n#ifdef REFLECTION\nreflectionOutParams reflectionOut;\n#ifndef USE_CUSTOM_REFLECTION\nreflectionBlock(\nvPositionW,\nnormalW,\nalphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#ifdef ANISOTROPIC\nanisotropicOut,\n#endif\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nroughness,\n#endif\nreflectionSampler,\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nvEnvironmentIrradiance,\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nreflectionMatrix,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\nirradianceSampler,\n#endif\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nreflectionOut\n);\n#else\n#define CUSTOM_REFLECTION\n#endif\n#endif\n#include\n#ifdef SHEEN\nsheenOutParams sheenOut;\n#ifdef SHEEN_TEXTURE\nvec4 sheenMapData=texture2D(sheenSampler,vSheenUV+uvOffset);\n#endif\n#if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)\nvec4 sheenMapRoughnessData=texture2D(sheenRoughnessSampler,vSheenRoughnessUV+uvOffset)*vSheenInfos.w;\n#endif\nsheenBlock(\nvSheenColor,\n#ifdef SHEEN_ROUGHNESS\nvSheenRoughness,\n#if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)\nsheenMapRoughnessData,\n#endif\n#endif\nroughness,\n#ifdef SHEEN_TEXTURE\nsheenMapData,\nvSheenInfos.y,\n#endif\nreflectance,\n#ifdef SHEEN_LINKWITHALBEDO\nbaseColor,\nsurfaceAlbedo,\n#endif\n#ifdef ENVIRONMENTBRDF\nNdotV,\nenvironmentBrdf,\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nAARoughnessFactors,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\nvLightingIntensity,\nreflectionSampler,\nreflectionOut.reflectionCoords,\nNdotVUnclamped,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)\nseo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)\neho,\n#endif\n#endif\nsheenOut\n);\n#ifdef SHEEN_LINKWITHALBEDO\nsurfaceAlbedo=sheenOut.surfaceAlbedo;\n#endif\n#endif\n#ifdef CLEARCOAT\n#ifdef CLEARCOAT_TEXTURE\nvec2 clearCoatMapData=texture2D(clearCoatSampler,vClearCoatUV+uvOffset).rg*vClearCoatInfos.y;\n#endif\n#endif\n#ifdef IRIDESCENCE\niridescenceOutParams iridescenceOut;\n#ifdef IRIDESCENCE_TEXTURE\nvec2 iridescenceMapData=texture2D(iridescenceSampler,vIridescenceUV+uvOffset).rg*vIridescenceInfos.y;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nvec2 iridescenceThicknessMapData=texture2D(iridescenceThicknessSampler,vIridescenceThicknessUV+uvOffset).rg*vIridescenceInfos.w;\n#endif\niridescenceBlock(\nvIridescenceParams,\nNdotV,\nspecularEnvironmentR0,\n#ifdef IRIDESCENCE_TEXTURE\niridescenceMapData,\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\niridescenceThicknessMapData,\n#endif\n#ifdef CLEARCOAT\nNdotVUnclamped,\n#ifdef CLEARCOAT_TEXTURE\nclearCoatMapData,\n#endif\n#endif\niridescenceOut\n);float iridescenceIntensity=iridescenceOut.iridescenceIntensity;specularEnvironmentR0=iridescenceOut.specularEnvironmentR0;\n#endif\nclearcoatOutParams clearcoatOut;\n#ifdef CLEARCOAT\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\nvec4 clearCoatMapRoughnessData=texture2D(clearCoatRoughnessSampler,vClearCoatRoughnessUV+uvOffset)*vClearCoatInfos.w;\n#endif\n#if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)\nvec4 clearCoatTintMapData=texture2D(clearCoatTintSampler,vClearCoatTintUV+uvOffset);\n#endif\n#ifdef CLEARCOAT_BUMP\nvec4 clearCoatBumpMapData=texture2D(clearCoatBumpSampler,vClearCoatBumpUV+uvOffset);\n#endif\nclearcoatBlock(\nvPositionW,\ngeometricNormalW,\nviewDirectionW,\nvClearCoatParams,\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\nclearCoatMapRoughnessData,\n#endif\nspecularEnvironmentR0,\n#ifdef CLEARCOAT_TEXTURE\nclearCoatMapData,\n#endif\n#ifdef CLEARCOAT_TINT\nvClearCoatTintParams,\nclearCoatColorAtDistance,\nvClearCoatRefractionParams,\n#ifdef CLEARCOAT_TINT_TEXTURE\nclearCoatTintMapData,\n#endif\n#endif\n#ifdef CLEARCOAT_BUMP\nvClearCoatBumpInfos,\nclearCoatBumpMapData,\nvClearCoatBumpUV,\n#if defined(TANGENT) && defined(NORMAL)\nvTBN,\n#else\nvClearCoatTangentSpaceParams,\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nnormalMatrix,\n#endif\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nfaceNormal,\n#endif\n#ifdef REFLECTION\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\nvLightingIntensity,\nreflectionSampler,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n#ifdef RADIANCEOCCLUSION\nambientMonochrome,\n#endif\n#endif\n#if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)\n(gl_FrontFacing ? 1. : -1.),\n#endif\nclearcoatOut\n);\n#else\nclearcoatOut.specularEnvironmentR0=specularEnvironmentR0;\n#endif\n#include\nsubSurfaceOutParams subSurfaceOut;\n#ifdef SUBSURFACE\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec4 thicknessMap=texture2D(thicknessSampler,vThicknessUV+uvOffset);\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nvec4 refractionIntensityMap=texture2D(refractionIntensitySampler,vRefractionIntensityUV+uvOffset);\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nvec4 translucencyIntensityMap=texture2D(translucencyIntensitySampler,vTranslucencyIntensityUV+uvOffset);\n#endif\nsubSurfaceBlock(\nvSubSurfaceIntensity,\nvThicknessParam,\nvTintColor,\nnormalW,\nspecularEnvironmentReflectance,\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nthicknessMap,\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nrefractionIntensityMap,\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\ntranslucencyIntensityMap,\n#endif\n#ifdef REFLECTION\n#ifdef SS_TRANSLUCENCY\nreflectionMatrix,\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nreflectionOut.irradianceVector,\n#endif\n#if defined(REALTIME_FILTERING)\nreflectionSampler,\nvReflectionFilteringInfo,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\nirradianceSampler,\n#endif\n#endif\n#endif\n#if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)\nsurfaceAlbedo,\n#endif\n#ifdef SS_REFRACTION\nvPositionW,\nviewDirectionW,\nview,\nvRefractionInfos,\nrefractionMatrix,\nvRefractionMicrosurfaceInfos,\nvLightingIntensity,\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nalpha,\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nNdotVUnclamped,\n#endif\n#ifdef SS_LINEARSPECULARREFRACTION\nroughness,\n#endif\nalphaG,\nrefractionSampler,\n#ifndef LODBASEDMICROSFURACE\nrefractionSamplerLow,\nrefractionSamplerHigh,\n#endif\n#ifdef ANISOTROPIC\nanisotropicOut,\n#endif\n#ifdef REALTIME_FILTERING\nvRefractionFilteringInfo,\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nvRefractionPosition,\nvRefractionSize,\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nvDiffusionDistance,\n#endif\nsubSurfaceOut\n);\n#ifdef SS_REFRACTION\nsurfaceAlbedo=subSurfaceOut.surfaceAlbedo;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nalpha=subSurfaceOut.alpha;\n#endif\n#endif\n#else\nsubSurfaceOut.specularEnvironmentReflectance=specularEnvironmentReflectance;\n#endif\n#include\n#include[0..maxSimultaneousLights]\n#include\n#endif \n#include\n#define CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\n#include\n#include\n#include(color,finalColor)\n#include\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\n#ifdef PREPASS\nfloat writeGeometryInfo=finalColor.a>0.4 ? 1.0 : 0.0;\n#ifdef PREPASS_POSITION\ngl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);\n#endif\n#ifdef PREPASS_VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);\n#endif\n#ifdef PREPASS_ALBEDO_SQRT\nvec3 sqAlbedo=sqrt(surfaceAlbedo); \n#endif\n#ifdef PREPASS_IRRADIANCE\nvec3 irradiance=finalDiffuse;\n#ifndef UNLIT\n#ifdef REFLECTION\nirradiance+=finalIrradiance;\n#endif\n#endif\n#ifdef SS_SCATTERING\ngl_FragData[0]=vec4(finalColor.rgb-irradiance,finalColor.a); \nirradiance/=sqAlbedo;\n#else\ngl_FragData[0]=finalColor; \nfloat scatteringDiffusionProfile=255.;\n#endif\ngl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(clamp(irradiance,vec3(0.),vec3(1.)),writeGeometryInfo*scatteringDiffusionProfile/255.); \n#else\ngl_FragData[0]=vec4(finalColor.rgb,finalColor.a);\n#endif\n#ifdef PREPASS_DEPTH\ngl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_NORMAL\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo); \n#endif\n#ifdef PREPASS_ALBEDO_SQRT\ngl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(sqAlbedo,writeGeometryInfo); \n#endif\n#ifdef PREPASS_REFLECTIVITY\n#ifndef UNLIT\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(specularEnvironmentR0,microSurface)*writeGeometryInfo;\n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4( 0.0,0.0,0.0,1.0 )*writeGeometryInfo;\n#endif\n#endif\n#endif\n#if !defined(PREPASS) || defined(WEBGL2)\ngl_FragColor=finalColor;\n#endif\n#include\n#if ORDER_INDEPENDENT_TRANSPARENCY\nif (fragDepth==nearestDepth) {frontColor.rgb+=finalColor.rgb*finalColor.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-finalColor.a);} else {backColor+=finalColor;}\n#endif\n#include\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1E] = shader$1E;\n\n // Do not edit.\n const name$1F = \"pbrVertexDeclaration\";\n const shader$1F = `uniform mat4 view;uniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;uniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec4 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;uniform mat4 reflectivityMatrix;\n#endif\n#ifdef METALLIC_REFLECTANCE\nuniform vec2 vMetallicReflectanceInfos;uniform mat4 metallicReflectanceMatrix;\n#endif\n#ifdef REFLECTANCE\nuniform vec2 vReflectanceInfos;uniform mat4 reflectanceMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;uniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;\n#endif\n#ifdef CLEARCOAT\n#if defined(CLEARCOAT_TEXTURE) || defined(CLEARCOAT_TEXTURE_ROUGHNESS)\nuniform vec4 vClearCoatInfos;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nuniform mat4 clearCoatMatrix;\n#endif\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS\nuniform mat4 clearCoatRoughnessMatrix;\n#endif\n#ifdef CLEARCOAT_BUMP\nuniform vec2 vClearCoatBumpInfos;uniform mat4 clearCoatBumpMatrix;\n#endif\n#ifdef CLEARCOAT_TINT_TEXTURE\nuniform vec2 vClearCoatTintInfos;uniform mat4 clearCoatTintMatrix;\n#endif\n#endif\n#ifdef IRIDESCENCE\n#if defined(IRIDESCENCE_TEXTURE) || defined(IRIDESCENCE_THICKNESS_TEXTURE)\nuniform vec4 vIridescenceInfos;\n#endif\n#ifdef IRIDESCENCE_TEXTURE\nuniform mat4 iridescenceMatrix;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nuniform mat4 iridescenceThicknessMatrix;\n#endif\n#endif\n#ifdef ANISOTROPIC\n#ifdef ANISOTROPIC_TEXTURE\nuniform vec2 vAnisotropyInfos;uniform mat4 anisotropyMatrix;\n#endif\n#endif\n#ifdef SHEEN\n#if defined(SHEEN_TEXTURE) || defined(SHEEN_TEXTURE_ROUGHNESS)\nuniform vec4 vSheenInfos;\n#endif\n#ifdef SHEEN_TEXTURE\nuniform mat4 sheenMatrix;\n#endif\n#ifdef SHEEN_TEXTURE_ROUGHNESS\nuniform mat4 sheenRoughnessMatrix;\n#endif\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\nuniform vec4 vRefractionInfos;uniform mat4 refractionMatrix;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nuniform vec2 vThicknessInfos;uniform mat4 thicknessMatrix;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nuniform vec2 vRefractionIntensityInfos;uniform mat4 refractionIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nuniform vec2 vTranslucencyIntensityInfos;uniform mat4 translucencyIntensityMatrix;\n#endif\n#endif\n#ifdef NORMAL\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nuniform vec3 vSphericalL00;uniform vec3 vSphericalL1_1;uniform vec3 vSphericalL10;uniform vec3 vSphericalL11;uniform vec3 vSphericalL2_2;uniform vec3 vSphericalL2_1;uniform vec3 vSphericalL20;uniform vec3 vSphericalL21;uniform vec3 vSphericalL22;\n#else\nuniform vec3 vSphericalX;uniform vec3 vSphericalY;uniform vec3 vSphericalZ;uniform vec3 vSphericalXX_ZZ;uniform vec3 vSphericalYY_ZZ;uniform vec3 vSphericalZZ;uniform vec3 vSphericalXY;uniform vec3 vSphericalYZ;uniform vec3 vSphericalZX;\n#endif\n#endif\n#endif\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1F] = shader$1F;\n\n // Do not edit.\n const name$1G = \"pbrVertexShader\";\n const shader$1G = `precision highp float;\n#include<__decl__pbrVertex>\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#include[2..7]\n#include[1..7]\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n#include\n#include\n#include\n#include(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap)\n#include(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity)\n#include(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler)\n#include(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance)\n#include(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance)\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal)\n#ifdef CLEARCOAT\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat)\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness)\n#include(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump)\n#include(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint)\n#endif\n#ifdef IRIDESCENCE\n#include(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence)\n#include(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness)\n#endif\n#ifdef SHEEN\n#include(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen)\n#include(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness)\n#endif\n#ifdef ANISOTROPIC\n#include(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy)\n#endif\n#ifdef SUBSURFACE\n#include(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness)\n#include(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity)\n#include(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity)\n#endif\nvarying vec3 vPositionW;\n#if DEBUGMODE>0\nvarying vec4 vClipSpacePosition;\n#endif\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#include\n#endif\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightVxFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif\n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include\n#if defined(PREPASS) && defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);vPositionW=vec3(worldPos);\n#include\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#if defined(INSTANCES) && defined(THIN_INSTANCES)\nvNormalW=normalUpdated/vec3(dot(normalWorld[0],normalWorld[0]),dot(normalWorld[1],normalWorld[1]),dot(normalWorld[2],normalWorld[2]));vNormalW=normalize(normalWorld*vNormalW);\n#else\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvec3 reflectionVector=vec3(reflectionMatrix*vec4(vNormalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\nvEnvironmentIrradiance=computeEnvironmentIrradiance(reflectionVector);\n#endif\n#endif\n#define CUSTOM_VERTEX_UPDATE_WORLDPOS\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\n#if DEBUGMODE>0\nvClipSpacePosition=gl_Position;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n#ifndef UV1\nvec2 uvUpdated=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uvUpdated;\n#endif\n#include[2..7]\n#include(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo,_MATRIXNAME_,albedo,_INFONAME_,AlbedoInfos.x)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_MATRIXNAME_,detail,_INFONAME_,DetailInfos.x)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_MATRIXNAME_,ambient,_INFONAME_,AmbientInfos.x)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_MATRIXNAME_,opacity,_INFONAME_,OpacityInfos.x)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_MATRIXNAME_,emissive,_INFONAME_,EmissiveInfos.x)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_MATRIXNAME_,lightmap,_INFONAME_,LightmapInfos.x)\n#include(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity,_MATRIXNAME_,reflectivity,_INFONAME_,ReflectivityInfos.x)\n#include(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler,_MATRIXNAME_,microSurfaceSampler,_INFONAME_,MicroSurfaceSamplerInfos.x)\n#include(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance,_MATRIXNAME_,metallicReflectance,_INFONAME_,MetallicReflectanceInfos.x)\n#include(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance,_MATRIXNAME_,reflectance,_INFONAME_,ReflectanceInfos.x)\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_MATRIXNAME_,bump,_INFONAME_,BumpInfos.x)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_MATRIXNAME_,decal,_INFONAME_,DecalInfos.x)\n#ifdef CLEARCOAT\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat,_MATRIXNAME_,clearCoat,_INFONAME_,ClearCoatInfos.x)\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness,_MATRIXNAME_,clearCoatRoughness,_INFONAME_,ClearCoatInfos.z)\n#include(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump,_MATRIXNAME_,clearCoatBump,_INFONAME_,ClearCoatBumpInfos.x)\n#include(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint,_MATRIXNAME_,clearCoatTint,_INFONAME_,ClearCoatTintInfos.x)\n#endif\n#ifdef IRIDESCENCE\n#include(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence,_MATRIXNAME_,iridescence,_INFONAME_,IridescenceInfos.x)\n#include(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness,_MATRIXNAME_,iridescenceThickness,_INFONAME_,IridescenceInfos.z)\n#endif\n#ifdef SHEEN\n#include(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen,_MATRIXNAME_,sheen,_INFONAME_,SheenInfos.x)\n#include(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness,_MATRIXNAME_,sheen,_INFONAME_,SheenInfos.z)\n#endif\n#ifdef ANISOTROPIC\n#include(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy,_MATRIXNAME_,anisotropy,_INFONAME_,AnisotropyInfos.x)\n#endif\n#ifdef SUBSURFACE\n#include(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness,_MATRIXNAME_,thickness,_INFONAME_,ThicknessInfos.x)\n#include(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity,_MATRIXNAME_,refractionIntensity,_INFONAME_,RefractionIntensityInfos.x)\n#include(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity,_MATRIXNAME_,translucencyIntensity,_INFONAME_,TranslucencyIntensityInfos.x)\n#endif\n#include\n#include\n#include\n#include[0..maxSimultaneousLights]\n#include\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1G] = shader$1G;\n\n /**\n * @internal\n */\n class MaterialClearCoatDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.CLEARCOAT = false;\n this.CLEARCOAT_DEFAULTIOR = false;\n this.CLEARCOAT_TEXTURE = false;\n this.CLEARCOAT_TEXTURE_ROUGHNESS = false;\n this.CLEARCOAT_TEXTUREDIRECTUV = 0;\n this.CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV = 0;\n this.CLEARCOAT_BUMP = false;\n this.CLEARCOAT_BUMPDIRECTUV = 0;\n this.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\n this.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL = false;\n this.CLEARCOAT_REMAP_F0 = false;\n this.CLEARCOAT_TINT = false;\n this.CLEARCOAT_TINT_TEXTURE = false;\n this.CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;\n this.CLEARCOAT_TINT_GAMMATEXTURE = false;\n }\n }\n /**\n * Plugin that implements the clear coat component of the PBR material\n */\n class PBRClearCoatConfiguration extends MaterialPluginBase {\n /** @internal */\n _markAllSubMeshesAsTexturesDirty() {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"PBRClearCoat\", 100, new MaterialClearCoatDefines(), addToPluginList);\n this._isEnabled = false;\n /**\n * Defines if the clear coat is enabled in the material.\n */\n this.isEnabled = false;\n /**\n * Defines the clear coat layer strength (between 0 and 1) it defaults to 1.\n */\n this.intensity = 1;\n /**\n * Defines the clear coat layer roughness.\n */\n this.roughness = 0;\n this._indexOfRefraction = PBRClearCoatConfiguration._DefaultIndexOfRefraction;\n /**\n * Defines the index of refraction of the clear coat.\n * This defaults to 1.5 corresponding to a 0.04 f0 or a 4% reflectance at normal incidence\n * The default fits with a polyurethane material.\n * Changing the default value is more performance intensive.\n */\n this.indexOfRefraction = PBRClearCoatConfiguration._DefaultIndexOfRefraction;\n this._texture = null;\n /**\n * Stores the clear coat values in a texture (red channel is intensity and green channel is roughness)\n * If useRoughnessFromMainTexture is false, the green channel of texture is not used and the green channel of textureRoughness is used instead\n * if textureRoughness is not empty, else no texture roughness is used\n */\n this.texture = null;\n this._useRoughnessFromMainTexture = true;\n /**\n * Indicates that the green channel of the texture property will be used for roughness (default: true)\n * If false, the green channel from textureRoughness is used for roughness\n */\n this.useRoughnessFromMainTexture = true;\n this._textureRoughness = null;\n /**\n * Stores the clear coat roughness in a texture (green channel)\n * Not used if useRoughnessFromMainTexture is true\n */\n this.textureRoughness = null;\n this._remapF0OnInterfaceChange = true;\n /**\n * Defines if the F0 value should be remapped to account for the interface change in the material.\n */\n this.remapF0OnInterfaceChange = true;\n this._bumpTexture = null;\n /**\n * Define the clear coat specific bump texture.\n */\n this.bumpTexture = null;\n this._isTintEnabled = false;\n /**\n * Defines if the clear coat tint is enabled in the material.\n */\n this.isTintEnabled = false;\n /**\n * Defines the clear coat tint of the material.\n * This is only use if tint is enabled\n */\n this.tintColor = Color3.White();\n /**\n * Defines the distance at which the tint color should be found in the\n * clear coat media.\n * This is only use if tint is enabled\n */\n this.tintColorAtDistance = 1;\n /**\n * Defines the clear coat layer thickness.\n * This is only use if tint is enabled\n */\n this.tintThickness = 1;\n this._tintTexture = null;\n /**\n * Stores the clear tint values in a texture.\n * rgb is tint\n * a is a thickness factor\n */\n this.tintTexture = null;\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];\n }\n isReadyForSubMesh(defines, scene, engine) {\n if (!this._isEnabled) {\n return true;\n }\n const disableBumpMap = this._material._disableBumpMap;\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {\n if (!this._texture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._textureRoughness && MaterialFlags.ClearCoatTextureEnabled) {\n if (!this._textureRoughness.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.ClearCoatBumpTextureEnabled && !disableBumpMap) {\n // Bump texture cannot be not blocking.\n if (!this._bumpTexture.isReady()) {\n return false;\n }\n }\n if (this._isTintEnabled && this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\n if (!this._tintTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n }\n }\n return true;\n }\n prepareDefinesBeforeAttributes(defines, scene) {\n var _a;\n if (this._isEnabled) {\n defines.CLEARCOAT = true;\n defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = this._useRoughnessFromMainTexture;\n defines.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL =\n this._texture !== null && this._texture._texture === ((_a = this._textureRoughness) === null || _a === void 0 ? void 0 : _a._texture) && this._texture.checkTransformsAreIdentical(this._textureRoughness);\n defines.CLEARCOAT_REMAP_F0 = this._remapF0OnInterfaceChange;\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"CLEARCOAT_TEXTURE\");\n }\n else {\n defines.CLEARCOAT_TEXTURE = false;\n }\n if (this._textureRoughness && MaterialFlags.ClearCoatTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._textureRoughness, defines, \"CLEARCOAT_TEXTURE_ROUGHNESS\");\n }\n else {\n defines.CLEARCOAT_TEXTURE_ROUGHNESS = false;\n }\n if (this._bumpTexture && MaterialFlags.ClearCoatBumpTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, \"CLEARCOAT_BUMP\");\n }\n else {\n defines.CLEARCOAT_BUMP = false;\n }\n defines.CLEARCOAT_DEFAULTIOR = this._indexOfRefraction === PBRClearCoatConfiguration._DefaultIndexOfRefraction;\n if (this._isTintEnabled) {\n defines.CLEARCOAT_TINT = true;\n if (this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._tintTexture, defines, \"CLEARCOAT_TINT_TEXTURE\");\n defines.CLEARCOAT_TINT_GAMMATEXTURE = this._tintTexture.gammaSpace;\n }\n else {\n defines.CLEARCOAT_TINT_TEXTURE = false;\n }\n }\n else {\n defines.CLEARCOAT_TINT = false;\n defines.CLEARCOAT_TINT_TEXTURE = false;\n }\n }\n }\n }\n else {\n defines.CLEARCOAT = false;\n defines.CLEARCOAT_TEXTURE = false;\n defines.CLEARCOAT_TEXTURE_ROUGHNESS = false;\n defines.CLEARCOAT_BUMP = false;\n defines.CLEARCOAT_TINT = false;\n defines.CLEARCOAT_TINT_TEXTURE = false;\n defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\n defines.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL = false;\n defines.CLEARCOAT_DEFAULTIOR = false;\n defines.CLEARCOAT_TEXTUREDIRECTUV = 0;\n defines.CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV = 0;\n defines.CLEARCOAT_BUMPDIRECTUV = 0;\n defines.CLEARCOAT_REMAP_F0 = false;\n defines.CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;\n defines.CLEARCOAT_TINT_GAMMATEXTURE = false;\n }\n }\n bindForSubMesh(uniformBuffer, scene, engine, subMesh) {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n if (!this._isEnabled) {\n return;\n }\n const defines = subMesh.materialDefines;\n const isFrozen = this._material.isFrozen;\n const disableBumpMap = this._material._disableBumpMap;\n const invertNormalMapX = this._material._invertNormalMapX;\n const invertNormalMapY = this._material._invertNormalMapY;\n const identicalTextures = defines.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL;\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n if (identicalTextures && MaterialFlags.ClearCoatTextureEnabled) {\n uniformBuffer.updateFloat4(\"vClearCoatInfos\", this._texture.coordinatesIndex, this._texture.level, -1, -1);\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"clearCoat\");\n }\n else if ((this._texture || this._textureRoughness) && MaterialFlags.ClearCoatTextureEnabled) {\n uniformBuffer.updateFloat4(\"vClearCoatInfos\", (_b = (_a = this._texture) === null || _a === void 0 ? void 0 : _a.coordinatesIndex) !== null && _b !== void 0 ? _b : 0, (_d = (_c = this._texture) === null || _c === void 0 ? void 0 : _c.level) !== null && _d !== void 0 ? _d : 0, (_f = (_e = this._textureRoughness) === null || _e === void 0 ? void 0 : _e.coordinatesIndex) !== null && _f !== void 0 ? _f : 0, (_h = (_g = this._textureRoughness) === null || _g === void 0 ? void 0 : _g.level) !== null && _h !== void 0 ? _h : 0);\n if (this._texture) {\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"clearCoat\");\n }\n if (this._textureRoughness && !identicalTextures && !defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE) {\n MaterialHelper.BindTextureMatrix(this._textureRoughness, uniformBuffer, \"clearCoatRoughness\");\n }\n }\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.ClearCoatTextureEnabled && !disableBumpMap) {\n uniformBuffer.updateFloat2(\"vClearCoatBumpInfos\", this._bumpTexture.coordinatesIndex, this._bumpTexture.level);\n MaterialHelper.BindTextureMatrix(this._bumpTexture, uniformBuffer, \"clearCoatBump\");\n if (scene._mirroredCameraPosition) {\n uniformBuffer.updateFloat2(\"vClearCoatTangentSpaceParams\", invertNormalMapX ? 1.0 : -1.0, invertNormalMapY ? 1.0 : -1.0);\n }\n else {\n uniformBuffer.updateFloat2(\"vClearCoatTangentSpaceParams\", invertNormalMapX ? -1.0 : 1.0, invertNormalMapY ? -1.0 : 1.0);\n }\n }\n if (this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\n uniformBuffer.updateFloat2(\"vClearCoatTintInfos\", this._tintTexture.coordinatesIndex, this._tintTexture.level);\n MaterialHelper.BindTextureMatrix(this._tintTexture, uniformBuffer, \"clearCoatTint\");\n }\n // Clear Coat General params\n uniformBuffer.updateFloat2(\"vClearCoatParams\", this.intensity, this.roughness);\n // Clear Coat Refraction params\n const a = 1 - this._indexOfRefraction;\n const b = 1 + this._indexOfRefraction;\n const f0 = Math.pow(-a / b, 2); // Schlicks approx: (ior1 - ior2) / (ior1 + ior2) where ior2 for air is close to vacuum = 1.\n const eta = 1 / this._indexOfRefraction;\n uniformBuffer.updateFloat4(\"vClearCoatRefractionParams\", f0, eta, a, b);\n if (this._isTintEnabled) {\n uniformBuffer.updateFloat4(\"vClearCoatTintParams\", this.tintColor.r, this.tintColor.g, this.tintColor.b, Math.max(0.00001, this.tintThickness));\n uniformBuffer.updateFloat(\"clearCoatColorAtDistance\", Math.max(0.00001, this.tintColorAtDistance));\n }\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {\n uniformBuffer.setTexture(\"clearCoatSampler\", this._texture);\n }\n if (this._textureRoughness && !identicalTextures && !defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE && MaterialFlags.ClearCoatTextureEnabled) {\n uniformBuffer.setTexture(\"clearCoatRoughnessSampler\", this._textureRoughness);\n }\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.ClearCoatBumpTextureEnabled && !disableBumpMap) {\n uniformBuffer.setTexture(\"clearCoatBumpSampler\", this._bumpTexture);\n }\n if (this._isTintEnabled && this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\n uniformBuffer.setTexture(\"clearCoatTintSampler\", this._tintTexture);\n }\n }\n }\n hasTexture(texture) {\n if (this._texture === texture) {\n return true;\n }\n if (this._textureRoughness === texture) {\n return true;\n }\n if (this._bumpTexture === texture) {\n return true;\n }\n if (this._tintTexture === texture) {\n return true;\n }\n return false;\n }\n getActiveTextures(activeTextures) {\n if (this._texture) {\n activeTextures.push(this._texture);\n }\n if (this._textureRoughness) {\n activeTextures.push(this._textureRoughness);\n }\n if (this._bumpTexture) {\n activeTextures.push(this._bumpTexture);\n }\n if (this._tintTexture) {\n activeTextures.push(this._tintTexture);\n }\n }\n getAnimatables(animatables) {\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\n animatables.push(this._texture);\n }\n if (this._textureRoughness && this._textureRoughness.animations && this._textureRoughness.animations.length > 0) {\n animatables.push(this._textureRoughness);\n }\n if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {\n animatables.push(this._bumpTexture);\n }\n if (this._tintTexture && this._tintTexture.animations && this._tintTexture.animations.length > 0) {\n animatables.push(this._tintTexture);\n }\n }\n dispose(forceDisposeTextures) {\n var _a, _b, _c, _d;\n if (forceDisposeTextures) {\n (_a = this._texture) === null || _a === void 0 ? void 0 : _a.dispose();\n (_b = this._textureRoughness) === null || _b === void 0 ? void 0 : _b.dispose();\n (_c = this._bumpTexture) === null || _c === void 0 ? void 0 : _c.dispose();\n (_d = this._tintTexture) === null || _d === void 0 ? void 0 : _d.dispose();\n }\n }\n getClassName() {\n return \"PBRClearCoatConfiguration\";\n }\n addFallbacks(defines, fallbacks, currentRank) {\n if (defines.CLEARCOAT_BUMP) {\n fallbacks.addFallback(currentRank++, \"CLEARCOAT_BUMP\");\n }\n if (defines.CLEARCOAT_TINT) {\n fallbacks.addFallback(currentRank++, \"CLEARCOAT_TINT\");\n }\n if (defines.CLEARCOAT) {\n fallbacks.addFallback(currentRank++, \"CLEARCOAT\");\n }\n return currentRank;\n }\n getSamplers(samplers) {\n samplers.push(\"clearCoatSampler\", \"clearCoatRoughnessSampler\", \"clearCoatBumpSampler\", \"clearCoatTintSampler\");\n }\n getUniforms() {\n return {\n ubo: [\n { name: \"vClearCoatParams\", size: 2, type: \"vec2\" },\n { name: \"vClearCoatRefractionParams\", size: 4, type: \"vec4\" },\n { name: \"vClearCoatInfos\", size: 4, type: \"vec4\" },\n { name: \"clearCoatMatrix\", size: 16, type: \"mat4\" },\n { name: \"clearCoatRoughnessMatrix\", size: 16, type: \"mat4\" },\n { name: \"vClearCoatBumpInfos\", size: 2, type: \"vec2\" },\n { name: \"vClearCoatTangentSpaceParams\", size: 2, type: \"vec2\" },\n { name: \"clearCoatBumpMatrix\", size: 16, type: \"mat4\" },\n { name: \"vClearCoatTintParams\", size: 4, type: \"vec4\" },\n { name: \"clearCoatColorAtDistance\", size: 1, type: \"float\" },\n { name: \"vClearCoatTintInfos\", size: 2, type: \"vec2\" },\n { name: \"clearCoatTintMatrix\", size: 16, type: \"mat4\" },\n ],\n };\n }\n }\n /**\n * This defaults to 1.5 corresponding to a 0.04 f0 or a 4% reflectance at normal incidence\n * The default fits with a polyurethane material.\n * @internal\n */\n PBRClearCoatConfiguration._DefaultIndexOfRefraction = 1.5;\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"isEnabled\", void 0);\n __decorate$1([\n serialize()\n ], PBRClearCoatConfiguration.prototype, \"intensity\", void 0);\n __decorate$1([\n serialize()\n ], PBRClearCoatConfiguration.prototype, \"roughness\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"indexOfRefraction\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"texture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"useRoughnessFromMainTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"textureRoughness\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"remapF0OnInterfaceChange\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"bumpTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"isTintEnabled\", void 0);\n __decorate$1([\n serializeAsColor3()\n ], PBRClearCoatConfiguration.prototype, \"tintColor\", void 0);\n __decorate$1([\n serialize()\n ], PBRClearCoatConfiguration.prototype, \"tintColorAtDistance\", void 0);\n __decorate$1([\n serialize()\n ], PBRClearCoatConfiguration.prototype, \"tintThickness\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRClearCoatConfiguration.prototype, \"tintTexture\", void 0);\n\n /**\n * @internal\n */\n class MaterialIridescenceDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.IRIDESCENCE = false;\n this.IRIDESCENCE_TEXTURE = false;\n this.IRIDESCENCE_TEXTUREDIRECTUV = 0;\n this.IRIDESCENCE_THICKNESS_TEXTURE = false;\n this.IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV = 0;\n this.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE = false;\n }\n }\n /**\n * Plugin that implements the iridescence (thin film) component of the PBR material\n */\n class PBRIridescenceConfiguration extends MaterialPluginBase {\n /** @internal */\n _markAllSubMeshesAsTexturesDirty() {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"PBRIridescence\", 110, new MaterialIridescenceDefines(), addToPluginList);\n this._isEnabled = false;\n /**\n * Defines if the iridescence is enabled in the material.\n */\n this.isEnabled = false;\n /**\n * Defines the iridescence layer strength (between 0 and 1) it defaults to 1.\n */\n this.intensity = 1;\n /**\n * Defines the minimum thickness of the thin-film layer given in nanometers (nm).\n */\n this.minimumThickness = PBRIridescenceConfiguration._DefaultMinimumThickness;\n /**\n * Defines the maximum thickness of the thin-film layer given in nanometers (nm). This will be the thickness used if not thickness texture has been set.\n */\n this.maximumThickness = PBRIridescenceConfiguration._DefaultMaximumThickness;\n /**\n * Defines the maximum thickness of the thin-film layer given in nanometers (nm).\n */\n this.indexOfRefraction = PBRIridescenceConfiguration._DefaultIndexOfRefraction;\n this._texture = null;\n /**\n * Stores the iridescence intensity in a texture (red channel)\n */\n this.texture = null;\n this._thicknessTexture = null;\n /**\n * Stores the iridescence thickness in a texture (green channel)\n */\n this.thicknessTexture = null;\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];\n }\n isReadyForSubMesh(defines, scene) {\n if (!this._isEnabled) {\n return true;\n }\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.IridescenceTextureEnabled) {\n if (!this._texture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {\n if (!this._thicknessTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n }\n }\n return true;\n }\n prepareDefinesBeforeAttributes(defines, scene) {\n var _a;\n if (this._isEnabled) {\n defines.IRIDESCENCE = true;\n defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE =\n this._texture !== null && this._texture._texture === ((_a = this._thicknessTexture) === null || _a === void 0 ? void 0 : _a._texture) && this._texture.checkTransformsAreIdentical(this._thicknessTexture);\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.IridescenceTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"IRIDESCENCE_TEXTURE\");\n }\n else {\n defines.IRIDESCENCE_TEXTURE = false;\n }\n if (!defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE && this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._thicknessTexture, defines, \"IRIDESCENCE_THICKNESS_TEXTURE\");\n }\n else {\n defines.IRIDESCENCE_THICKNESS_TEXTURE = false;\n }\n }\n }\n }\n else {\n defines.IRIDESCENCE = false;\n defines.IRIDESCENCE_TEXTURE = false;\n defines.IRIDESCENCE_THICKNESS_TEXTURE = false;\n defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE = false;\n defines.IRIDESCENCE_TEXTUREDIRECTUV = 0;\n defines.IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV = 0;\n }\n }\n bindForSubMesh(uniformBuffer, scene, engine, subMesh) {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n if (!this._isEnabled) {\n return;\n }\n const defines = subMesh.materialDefines;\n const isFrozen = this._material.isFrozen;\n const identicalTextures = defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE;\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n if (identicalTextures && MaterialFlags.IridescenceTextureEnabled) {\n uniformBuffer.updateFloat4(\"vIridescenceInfos\", this._texture.coordinatesIndex, this._texture.level, -1, -1);\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"iridescence\");\n }\n else if ((this._texture || this._thicknessTexture) && MaterialFlags.IridescenceTextureEnabled) {\n uniformBuffer.updateFloat4(\"vIridescenceInfos\", (_b = (_a = this._texture) === null || _a === void 0 ? void 0 : _a.coordinatesIndex) !== null && _b !== void 0 ? _b : 0, (_d = (_c = this._texture) === null || _c === void 0 ? void 0 : _c.level) !== null && _d !== void 0 ? _d : 0, (_f = (_e = this._thicknessTexture) === null || _e === void 0 ? void 0 : _e.coordinatesIndex) !== null && _f !== void 0 ? _f : 0, (_h = (_g = this._thicknessTexture) === null || _g === void 0 ? void 0 : _g.level) !== null && _h !== void 0 ? _h : 0);\n if (this._texture) {\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"iridescence\");\n }\n if (this._thicknessTexture && !identicalTextures && !defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE) {\n MaterialHelper.BindTextureMatrix(this._thicknessTexture, uniformBuffer, \"iridescenceThickness\");\n }\n }\n // Clear Coat General params\n uniformBuffer.updateFloat4(\"vIridescenceParams\", this.intensity, this.indexOfRefraction, this.minimumThickness, this.maximumThickness);\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.IridescenceTextureEnabled) {\n uniformBuffer.setTexture(\"iridescenceSampler\", this._texture);\n }\n if (this._thicknessTexture && !identicalTextures && !defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE && MaterialFlags.IridescenceTextureEnabled) {\n uniformBuffer.setTexture(\"iridescenceThicknessSampler\", this._thicknessTexture);\n }\n }\n }\n hasTexture(texture) {\n if (this._texture === texture) {\n return true;\n }\n if (this._thicknessTexture === texture) {\n return true;\n }\n return false;\n }\n getActiveTextures(activeTextures) {\n if (this._texture) {\n activeTextures.push(this._texture);\n }\n if (this._thicknessTexture) {\n activeTextures.push(this._thicknessTexture);\n }\n }\n getAnimatables(animatables) {\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\n animatables.push(this._texture);\n }\n if (this._thicknessTexture && this._thicknessTexture.animations && this._thicknessTexture.animations.length > 0) {\n animatables.push(this._thicknessTexture);\n }\n }\n dispose(forceDisposeTextures) {\n var _a, _b;\n if (forceDisposeTextures) {\n (_a = this._texture) === null || _a === void 0 ? void 0 : _a.dispose();\n (_b = this._thicknessTexture) === null || _b === void 0 ? void 0 : _b.dispose();\n }\n }\n getClassName() {\n return \"PBRIridescenceConfiguration\";\n }\n addFallbacks(defines, fallbacks, currentRank) {\n if (defines.IRIDESCENCE) {\n fallbacks.addFallback(currentRank++, \"IRIDESCENCE\");\n }\n return currentRank;\n }\n getSamplers(samplers) {\n samplers.push(\"iridescenceSampler\", \"iridescenceThicknessSampler\");\n }\n getUniforms() {\n return {\n ubo: [\n { name: \"vIridescenceParams\", size: 4, type: \"vec4\" },\n { name: \"vIridescenceInfos\", size: 4, type: \"vec4\" },\n { name: \"iridescenceMatrix\", size: 16, type: \"mat4\" },\n { name: \"iridescenceThicknessMatrix\", size: 16, type: \"mat4\" },\n ],\n };\n }\n }\n /**\n * The default minimum thickness of the thin-film layer given in nanometers (nm).\n * Defaults to 100 nm.\n * @internal\n */\n PBRIridescenceConfiguration._DefaultMinimumThickness = 100;\n /**\n * The default maximum thickness of the thin-film layer given in nanometers (nm).\n * Defaults to 400 nm.\n * @internal\n */\n PBRIridescenceConfiguration._DefaultMaximumThickness = 400;\n /**\n * The default index of refraction of the thin-film layer.\n * Defaults to 1.3\n * @internal\n */\n PBRIridescenceConfiguration._DefaultIndexOfRefraction = 1.3;\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRIridescenceConfiguration.prototype, \"isEnabled\", void 0);\n __decorate$1([\n serialize()\n ], PBRIridescenceConfiguration.prototype, \"intensity\", void 0);\n __decorate$1([\n serialize()\n ], PBRIridescenceConfiguration.prototype, \"minimumThickness\", void 0);\n __decorate$1([\n serialize()\n ], PBRIridescenceConfiguration.prototype, \"maximumThickness\", void 0);\n __decorate$1([\n serialize()\n ], PBRIridescenceConfiguration.prototype, \"indexOfRefraction\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRIridescenceConfiguration.prototype, \"texture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRIridescenceConfiguration.prototype, \"thicknessTexture\", void 0);\n\n /**\n * @internal\n */\n class MaterialAnisotropicDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.ANISOTROPIC = false;\n this.ANISOTROPIC_TEXTURE = false;\n this.ANISOTROPIC_TEXTUREDIRECTUV = 0;\n this.ANISOTROPIC_LEGACY = false;\n this.MAINUV1 = false;\n }\n }\n /**\n * Plugin that implements the anisotropic component of the PBR material\n */\n class PBRAnisotropicConfiguration extends MaterialPluginBase {\n /**\n * Sets the anisotropy direction as an angle.\n */\n set angle(value) {\n this.direction.x = Math.cos(value);\n this.direction.y = Math.sin(value);\n }\n /**\n * Gets the anisotropy angle value in radians.\n * @returns the anisotropy angle value in radians.\n */\n get angle() {\n return Math.atan2(this.direction.y, this.direction.x);\n }\n /** @internal */\n _markAllSubMeshesAsTexturesDirty() {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n /** @internal */\n _markAllSubMeshesAsMiscDirty() {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsMiscDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"PBRAnisotropic\", 110, new MaterialAnisotropicDefines(), addToPluginList);\n this._isEnabled = false;\n /**\n * Defines if the anisotropy is enabled in the material.\n */\n this.isEnabled = false;\n /**\n * Defines the anisotropy strength (between 0 and 1) it defaults to 1.\n */\n this.intensity = 1;\n /**\n * Defines if the effect is along the tangents, bitangents or in between.\n * By default, the effect is \"stretching\" the highlights along the tangents.\n */\n this.direction = new Vector2(1, 0);\n this._texture = null;\n /**\n * Stores the anisotropy values in a texture.\n * rg is direction (like normal from -1 to 1)\n * b is a intensity\n */\n this.texture = null;\n this._legacy = false;\n /**\n * Defines if the anisotropy is in legacy mode for backwards compatibility before 6.4.0.\n */\n this.legacy = false;\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];\n this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[16];\n }\n isReadyForSubMesh(defines, scene) {\n if (!this._isEnabled) {\n return true;\n }\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\n if (!this._texture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n }\n }\n return true;\n }\n prepareDefinesBeforeAttributes(defines, scene, mesh) {\n if (this._isEnabled) {\n defines.ANISOTROPIC = this._isEnabled;\n if (this._isEnabled && !mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {\n defines._needUVs = true;\n defines.MAINUV1 = true;\n }\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"ANISOTROPIC_TEXTURE\");\n }\n else {\n defines.ANISOTROPIC_TEXTURE = false;\n }\n }\n }\n if (defines._areMiscDirty) {\n defines.ANISOTROPIC_LEGACY = this._legacy;\n }\n }\n else {\n defines.ANISOTROPIC = false;\n defines.ANISOTROPIC_TEXTURE = false;\n defines.ANISOTROPIC_TEXTUREDIRECTUV = 0;\n defines.ANISOTROPIC_LEGACY = false;\n }\n }\n bindForSubMesh(uniformBuffer, scene) {\n if (!this._isEnabled) {\n return;\n }\n const isFrozen = this._material.isFrozen;\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\n uniformBuffer.updateFloat2(\"vAnisotropyInfos\", this._texture.coordinatesIndex, this._texture.level);\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"anisotropy\");\n }\n // Anisotropy\n uniformBuffer.updateFloat3(\"vAnisotropy\", this.direction.x, this.direction.y, this.intensity);\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\n uniformBuffer.setTexture(\"anisotropySampler\", this._texture);\n }\n }\n }\n hasTexture(texture) {\n if (this._texture === texture) {\n return true;\n }\n return false;\n }\n getActiveTextures(activeTextures) {\n if (this._texture) {\n activeTextures.push(this._texture);\n }\n }\n getAnimatables(animatables) {\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\n animatables.push(this._texture);\n }\n }\n dispose(forceDisposeTextures) {\n if (forceDisposeTextures) {\n if (this._texture) {\n this._texture.dispose();\n }\n }\n }\n getClassName() {\n return \"PBRAnisotropicConfiguration\";\n }\n addFallbacks(defines, fallbacks, currentRank) {\n if (defines.ANISOTROPIC) {\n fallbacks.addFallback(currentRank++, \"ANISOTROPIC\");\n }\n return currentRank;\n }\n getSamplers(samplers) {\n samplers.push(\"anisotropySampler\");\n }\n getUniforms() {\n return {\n ubo: [\n { name: \"vAnisotropy\", size: 3, type: \"vec3\" },\n { name: \"vAnisotropyInfos\", size: 2, type: \"vec2\" },\n { name: \"anisotropyMatrix\", size: 16, type: \"mat4\" },\n ],\n };\n }\n /**\n * Parses a anisotropy Configuration from a serialized object.\n * @param source - Serialized object.\n * @param scene Defines the scene we are parsing for\n * @param rootUrl Defines the rootUrl to load from\n */\n parse(source, scene, rootUrl) {\n super.parse(source, scene, rootUrl);\n // Backward compatibility\n if (source.legacy === undefined) {\n this.legacy = true;\n }\n }\n }\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRAnisotropicConfiguration.prototype, \"isEnabled\", void 0);\n __decorate$1([\n serialize()\n ], PBRAnisotropicConfiguration.prototype, \"intensity\", void 0);\n __decorate$1([\n serializeAsVector2()\n ], PBRAnisotropicConfiguration.prototype, \"direction\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRAnisotropicConfiguration.prototype, \"texture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRAnisotropicConfiguration.prototype, \"legacy\", void 0);\n\n /**\n * @internal\n */\n class MaterialSheenDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.SHEEN = false;\n this.SHEEN_TEXTURE = false;\n this.SHEEN_GAMMATEXTURE = false;\n this.SHEEN_TEXTURE_ROUGHNESS = false;\n this.SHEEN_TEXTUREDIRECTUV = 0;\n this.SHEEN_TEXTURE_ROUGHNESSDIRECTUV = 0;\n this.SHEEN_LINKWITHALBEDO = false;\n this.SHEEN_ROUGHNESS = false;\n this.SHEEN_ALBEDOSCALING = false;\n this.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\n this.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL = false;\n }\n }\n /**\n * Plugin that implements the sheen component of the PBR material.\n */\n class PBRSheenConfiguration extends MaterialPluginBase {\n /** @internal */\n _markAllSubMeshesAsTexturesDirty() {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"Sheen\", 120, new MaterialSheenDefines(), addToPluginList);\n this._isEnabled = false;\n /**\n * Defines if the material uses sheen.\n */\n this.isEnabled = false;\n this._linkSheenWithAlbedo = false;\n /**\n * Defines if the sheen is linked to the sheen color.\n */\n this.linkSheenWithAlbedo = false;\n /**\n * Defines the sheen intensity.\n */\n this.intensity = 1;\n /**\n * Defines the sheen color.\n */\n this.color = Color3.White();\n this._texture = null;\n /**\n * Stores the sheen tint values in a texture.\n * rgb is tint\n * a is a intensity or roughness if the roughness property has been defined and useRoughnessFromTexture is true (in that case, textureRoughness won't be used)\n * If the roughness property has been defined and useRoughnessFromTexture is false then the alpha channel is not used to modulate roughness\n */\n this.texture = null;\n this._useRoughnessFromMainTexture = true;\n /**\n * Indicates that the alpha channel of the texture property will be used for roughness.\n * Has no effect if the roughness (and texture!) property is not defined\n */\n this.useRoughnessFromMainTexture = true;\n this._roughness = null;\n /**\n * Defines the sheen roughness.\n * It is not taken into account if linkSheenWithAlbedo is true.\n * To stay backward compatible, material roughness is used instead if sheen roughness = null\n */\n this.roughness = null;\n this._textureRoughness = null;\n /**\n * Stores the sheen roughness in a texture.\n * alpha channel is the roughness. This texture won't be used if the texture property is not empty and useRoughnessFromTexture is true\n */\n this.textureRoughness = null;\n this._albedoScaling = false;\n /**\n * If true, the sheen effect is layered above the base BRDF with the albedo-scaling technique.\n * It allows the strength of the sheen effect to not depend on the base color of the material,\n * making it easier to setup and tweak the effect\n */\n this.albedoScaling = false;\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];\n }\n isReadyForSubMesh(defines, scene) {\n if (!this._isEnabled) {\n return true;\n }\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.SheenTextureEnabled) {\n if (!this._texture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._textureRoughness && MaterialFlags.SheenTextureEnabled) {\n if (!this._textureRoughness.isReadyOrNotBlocking()) {\n return false;\n }\n }\n }\n }\n return true;\n }\n prepareDefinesBeforeAttributes(defines, scene) {\n var _a;\n if (this._isEnabled) {\n defines.SHEEN = true;\n defines.SHEEN_LINKWITHALBEDO = this._linkSheenWithAlbedo;\n defines.SHEEN_ROUGHNESS = this._roughness !== null;\n defines.SHEEN_ALBEDOSCALING = this._albedoScaling;\n defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = this._useRoughnessFromMainTexture;\n defines.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL =\n this._texture !== null && this._texture._texture === ((_a = this._textureRoughness) === null || _a === void 0 ? void 0 : _a._texture) && this._texture.checkTransformsAreIdentical(this._textureRoughness);\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.SheenTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"SHEEN_TEXTURE\");\n defines.SHEEN_GAMMATEXTURE = this._texture.gammaSpace;\n }\n else {\n defines.SHEEN_TEXTURE = false;\n }\n if (this._textureRoughness && MaterialFlags.SheenTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._textureRoughness, defines, \"SHEEN_TEXTURE_ROUGHNESS\");\n }\n else {\n defines.SHEEN_TEXTURE_ROUGHNESS = false;\n }\n }\n }\n }\n else {\n defines.SHEEN = false;\n defines.SHEEN_TEXTURE = false;\n defines.SHEEN_TEXTURE_ROUGHNESS = false;\n defines.SHEEN_LINKWITHALBEDO = false;\n defines.SHEEN_ROUGHNESS = false;\n defines.SHEEN_ALBEDOSCALING = false;\n defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\n defines.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL = false;\n defines.SHEEN_GAMMATEXTURE = false;\n defines.SHEEN_TEXTUREDIRECTUV = 0;\n defines.SHEEN_TEXTURE_ROUGHNESSDIRECTUV = 0;\n }\n }\n bindForSubMesh(uniformBuffer, scene, engine, subMesh) {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n if (!this._isEnabled) {\n return;\n }\n const defines = subMesh.materialDefines;\n const isFrozen = this._material.isFrozen;\n const identicalTextures = defines.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL;\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n if (identicalTextures && MaterialFlags.SheenTextureEnabled) {\n uniformBuffer.updateFloat4(\"vSheenInfos\", this._texture.coordinatesIndex, this._texture.level, -1, -1);\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"sheen\");\n }\n else if ((this._texture || this._textureRoughness) && MaterialFlags.SheenTextureEnabled) {\n uniformBuffer.updateFloat4(\"vSheenInfos\", (_b = (_a = this._texture) === null || _a === void 0 ? void 0 : _a.coordinatesIndex) !== null && _b !== void 0 ? _b : 0, (_d = (_c = this._texture) === null || _c === void 0 ? void 0 : _c.level) !== null && _d !== void 0 ? _d : 0, (_f = (_e = this._textureRoughness) === null || _e === void 0 ? void 0 : _e.coordinatesIndex) !== null && _f !== void 0 ? _f : 0, (_h = (_g = this._textureRoughness) === null || _g === void 0 ? void 0 : _g.level) !== null && _h !== void 0 ? _h : 0);\n if (this._texture) {\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"sheen\");\n }\n if (this._textureRoughness && !identicalTextures && !defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE) {\n MaterialHelper.BindTextureMatrix(this._textureRoughness, uniformBuffer, \"sheenRoughness\");\n }\n }\n // Sheen\n uniformBuffer.updateFloat4(\"vSheenColor\", this.color.r, this.color.g, this.color.b, this.intensity);\n if (this._roughness !== null) {\n uniformBuffer.updateFloat(\"vSheenRoughness\", this._roughness);\n }\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._texture && MaterialFlags.SheenTextureEnabled) {\n uniformBuffer.setTexture(\"sheenSampler\", this._texture);\n }\n if (this._textureRoughness && !identicalTextures && !defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE && MaterialFlags.SheenTextureEnabled) {\n uniformBuffer.setTexture(\"sheenRoughnessSampler\", this._textureRoughness);\n }\n }\n }\n hasTexture(texture) {\n if (this._texture === texture) {\n return true;\n }\n if (this._textureRoughness === texture) {\n return true;\n }\n return false;\n }\n getActiveTextures(activeTextures) {\n if (this._texture) {\n activeTextures.push(this._texture);\n }\n if (this._textureRoughness) {\n activeTextures.push(this._textureRoughness);\n }\n }\n getAnimatables(animatables) {\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\n animatables.push(this._texture);\n }\n if (this._textureRoughness && this._textureRoughness.animations && this._textureRoughness.animations.length > 0) {\n animatables.push(this._textureRoughness);\n }\n }\n dispose(forceDisposeTextures) {\n var _a, _b;\n if (forceDisposeTextures) {\n (_a = this._texture) === null || _a === void 0 ? void 0 : _a.dispose();\n (_b = this._textureRoughness) === null || _b === void 0 ? void 0 : _b.dispose();\n }\n }\n getClassName() {\n return \"PBRSheenConfiguration\";\n }\n addFallbacks(defines, fallbacks, currentRank) {\n if (defines.SHEEN) {\n fallbacks.addFallback(currentRank++, \"SHEEN\");\n }\n return currentRank;\n }\n getSamplers(samplers) {\n samplers.push(\"sheenSampler\", \"sheenRoughnessSampler\");\n }\n getUniforms() {\n return {\n ubo: [\n { name: \"vSheenColor\", size: 4, type: \"vec4\" },\n { name: \"vSheenRoughness\", size: 1, type: \"float\" },\n { name: \"vSheenInfos\", size: 4, type: \"vec4\" },\n { name: \"sheenMatrix\", size: 16, type: \"mat4\" },\n { name: \"sheenRoughnessMatrix\", size: 16, type: \"mat4\" },\n ],\n };\n }\n }\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"isEnabled\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"linkSheenWithAlbedo\", void 0);\n __decorate$1([\n serialize()\n ], PBRSheenConfiguration.prototype, \"intensity\", void 0);\n __decorate$1([\n serializeAsColor3()\n ], PBRSheenConfiguration.prototype, \"color\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"texture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"useRoughnessFromMainTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"roughness\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"textureRoughness\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSheenConfiguration.prototype, \"albedoScaling\", void 0);\n\n /**\n * @internal\n */\n class MaterialSubSurfaceDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n this.SUBSURFACE = false;\n this.SS_REFRACTION = false;\n this.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = false;\n this.SS_TRANSLUCENCY = false;\n this.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = false;\n this.SS_SCATTERING = false;\n this.SS_THICKNESSANDMASK_TEXTURE = false;\n this.SS_THICKNESSANDMASK_TEXTUREDIRECTUV = 0;\n this.SS_HAS_THICKNESS = false;\n this.SS_REFRACTIONINTENSITY_TEXTURE = false;\n this.SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV = 0;\n this.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;\n this.SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV = 0;\n this.SS_REFRACTIONMAP_3D = false;\n this.SS_REFRACTIONMAP_OPPOSITEZ = false;\n this.SS_LODINREFRACTIONALPHA = false;\n this.SS_GAMMAREFRACTION = false;\n this.SS_RGBDREFRACTION = false;\n this.SS_LINEARSPECULARREFRACTION = false;\n this.SS_LINKREFRACTIONTOTRANSPARENCY = false;\n this.SS_ALBEDOFORREFRACTIONTINT = false;\n this.SS_ALBEDOFORTRANSLUCENCYTINT = false;\n this.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;\n this.SS_USE_THICKNESS_AS_DEPTH = false;\n this.SS_MASK_FROM_THICKNESS_TEXTURE = false;\n this.SS_USE_GLTF_TEXTURES = false;\n }\n }\n /**\n * Plugin that implements the sub surface component of the PBR material\n */\n class PBRSubSurfaceConfiguration extends MaterialPluginBase {\n /**\n * Diffusion profile for subsurface scattering.\n * Useful for better scattering in the skins or foliages.\n */\n get scatteringDiffusionProfile() {\n if (!this._scene.subSurfaceConfiguration) {\n return null;\n }\n return this._scene.subSurfaceConfiguration.ssDiffusionProfileColors[this._scatteringDiffusionProfileIndex];\n }\n set scatteringDiffusionProfile(c) {\n if (!this._scene.enableSubSurfaceForPrePass()) {\n // Not supported\n return;\n }\n // addDiffusionProfile automatically checks for doubles\n if (c) {\n this._scatteringDiffusionProfileIndex = this._scene.subSurfaceConfiguration.addDiffusionProfile(c);\n }\n }\n /**\n * Index of refraction of the material's volume.\n * https://en.wikipedia.org/wiki/List_of_refractive_indices\n *\n * This ONLY impacts refraction. If not provided or given a non-valid value,\n * the volume will use the same IOR as the surface.\n */\n get volumeIndexOfRefraction() {\n if (this._volumeIndexOfRefraction >= 1.0) {\n return this._volumeIndexOfRefraction;\n }\n return this._indexOfRefraction;\n }\n set volumeIndexOfRefraction(value) {\n if (value >= 1.0) {\n this._volumeIndexOfRefraction = value;\n }\n else {\n this._volumeIndexOfRefraction = -1.0;\n }\n }\n /** @internal */\n _markAllSubMeshesAsTexturesDirty() {\n this._enable(this._isRefractionEnabled || this._isTranslucencyEnabled || this._isScatteringEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n /** @internal */\n _markScenePrePassDirty() {\n this._internalMarkAllSubMeshesAsTexturesDirty();\n this._internalMarkScenePrePassDirty();\n }\n constructor(material, addToPluginList = true) {\n super(material, \"PBRSubSurface\", 130, new MaterialSubSurfaceDefines(), addToPluginList);\n this._isRefractionEnabled = false;\n /**\n * Defines if the refraction is enabled in the material.\n */\n this.isRefractionEnabled = false;\n this._isTranslucencyEnabled = false;\n /**\n * Defines if the translucency is enabled in the material.\n */\n this.isTranslucencyEnabled = false;\n this._isScatteringEnabled = false;\n /**\n * Defines if the sub surface scattering is enabled in the material.\n */\n this.isScatteringEnabled = false;\n this._scatteringDiffusionProfileIndex = 0;\n /**\n * Defines the refraction intensity of the material.\n * The refraction when enabled replaces the Diffuse part of the material.\n * The intensity helps transitioning between diffuse and refraction.\n */\n this.refractionIntensity = 1;\n /**\n * Defines the translucency intensity of the material.\n * When translucency has been enabled, this defines how much of the \"translucency\"\n * is added to the diffuse part of the material.\n */\n this.translucencyIntensity = 1;\n /**\n * When enabled, transparent surfaces will be tinted with the albedo colour (independent of thickness)\n */\n this.useAlbedoToTintRefraction = false;\n /**\n * When enabled, translucent surfaces will be tinted with the albedo colour (independent of thickness)\n */\n this.useAlbedoToTintTranslucency = false;\n this._thicknessTexture = null;\n /**\n * Stores the average thickness of a mesh in a texture (The texture is holding the values linearly).\n * The red (or green if useGltfStyleTextures=true) channel of the texture should contain the thickness remapped between 0 and 1.\n * 0 would mean minimumThickness\n * 1 would mean maximumThickness\n * The other channels might be use as a mask to vary the different effects intensity.\n */\n this.thicknessTexture = null;\n this._refractionTexture = null;\n /**\n * Defines the texture to use for refraction.\n */\n this.refractionTexture = null;\n /** @internal */\n this._indexOfRefraction = 1.5;\n /**\n * Index of refraction of the material base layer.\n * https://en.wikipedia.org/wiki/List_of_refractive_indices\n *\n * This does not only impact refraction but also the Base F0 of Dielectric Materials.\n *\n * From dielectric fresnel rules: F0 = square((iorT - iorI) / (iorT + iorI))\n */\n this.indexOfRefraction = 1.5;\n this._volumeIndexOfRefraction = -1.0;\n this._invertRefractionY = false;\n /**\n * Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.\n */\n this.invertRefractionY = false;\n /** @internal */\n this._linkRefractionWithTransparency = false;\n /**\n * This parameters will make the material used its opacity to control how much it is refracting against not.\n * Materials half opaque for instance using refraction could benefit from this control.\n */\n this.linkRefractionWithTransparency = false;\n /**\n * Defines the minimum thickness stored in the thickness map.\n * If no thickness map is defined, this value will be used to simulate thickness.\n */\n this.minimumThickness = 0;\n /**\n * Defines the maximum thickness stored in the thickness map.\n */\n this.maximumThickness = 1;\n /**\n * Defines that the thickness should be used as a measure of the depth volume.\n */\n this.useThicknessAsDepth = false;\n /**\n * Defines the volume tint of the material.\n * This is used for both translucency and scattering.\n */\n this.tintColor = Color3.White();\n /**\n * Defines the distance at which the tint color should be found in the media.\n * This is used for refraction only.\n */\n this.tintColorAtDistance = 1;\n /**\n * Defines how far each channel transmit through the media.\n * It is defined as a color to simplify it selection.\n */\n this.diffusionDistance = Color3.White();\n this._useMaskFromThicknessTexture = false;\n /**\n * Stores the intensity of the different subsurface effects in the thickness texture.\n * Note that if refractionIntensityTexture and/or translucencyIntensityTexture is provided it takes precedence over thicknessTexture + useMaskFromThicknessTexture\n * * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.\n * * the blue channel is the translucency intensity.\n */\n this.useMaskFromThicknessTexture = false;\n this._refractionIntensityTexture = null;\n /**\n * Stores the intensity of the refraction. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture\n * * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.\n */\n this.refractionIntensityTexture = null;\n this._translucencyIntensityTexture = null;\n /**\n * Stores the intensity of the translucency. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture\n * * the blue channel is the translucency intensity.\n */\n this.translucencyIntensityTexture = null;\n this._useGltfStyleTextures = false;\n /**\n * Use channels layout used by glTF:\n * * thicknessTexture: the green (instead of red) channel is the thickness\n * * thicknessTexture/refractionIntensityTexture: the red (instead of green) channel is the refraction intensity\n * * thicknessTexture/translucencyIntensityTexture: no change, use the blue channel for the translucency intensity\n */\n this.useGltfStyleTextures = false;\n this._scene = material.getScene();\n this.registerForExtraEvents = true;\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];\n this._internalMarkScenePrePassDirty = material._dirtyCallbacks[32];\n }\n isReadyForSubMesh(defines, scene) {\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\n return true;\n }\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\n if (!this._thicknessTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n const refractionTexture = this._getRefractionTexture(scene);\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\n if (!refractionTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n }\n }\n return true;\n }\n prepareDefinesBeforeAttributes(defines, scene) {\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\n defines.SUBSURFACE = false;\n defines.SS_TRANSLUCENCY = false;\n defines.SS_SCATTERING = false;\n defines.SS_REFRACTION = false;\n defines.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = false;\n defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = false;\n defines.SS_THICKNESSANDMASK_TEXTURE = false;\n defines.SS_THICKNESSANDMASK_TEXTUREDIRECTUV = 0;\n defines.SS_HAS_THICKNESS = false;\n defines.SS_REFRACTIONINTENSITY_TEXTURE = false;\n defines.SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV = 0;\n defines.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;\n defines.SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV = 0;\n defines.SS_REFRACTIONMAP_3D = false;\n defines.SS_REFRACTIONMAP_OPPOSITEZ = false;\n defines.SS_LODINREFRACTIONALPHA = false;\n defines.SS_GAMMAREFRACTION = false;\n defines.SS_RGBDREFRACTION = false;\n defines.SS_LINEARSPECULARREFRACTION = false;\n defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;\n defines.SS_ALBEDOFORREFRACTIONTINT = false;\n defines.SS_ALBEDOFORTRANSLUCENCYTINT = false;\n defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;\n defines.SS_USE_THICKNESS_AS_DEPTH = false;\n defines.SS_MASK_FROM_THICKNESS_TEXTURE = false;\n defines.SS_USE_GLTF_TEXTURES = false;\n return;\n }\n if (defines._areTexturesDirty) {\n defines.SUBSURFACE = true;\n defines.SS_TRANSLUCENCY = this._isTranslucencyEnabled;\n defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = false;\n defines.SS_SCATTERING = this._isScatteringEnabled;\n defines.SS_THICKNESSANDMASK_TEXTURE = false;\n defines.SS_REFRACTIONINTENSITY_TEXTURE = false;\n defines.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;\n defines.SS_HAS_THICKNESS = false;\n defines.SS_MASK_FROM_THICKNESS_TEXTURE = false;\n defines.SS_USE_GLTF_TEXTURES = false;\n defines.SS_REFRACTION = false;\n defines.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = false;\n defines.SS_REFRACTIONMAP_3D = false;\n defines.SS_GAMMAREFRACTION = false;\n defines.SS_RGBDREFRACTION = false;\n defines.SS_LINEARSPECULARREFRACTION = false;\n defines.SS_REFRACTIONMAP_OPPOSITEZ = false;\n defines.SS_LODINREFRACTIONALPHA = false;\n defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;\n defines.SS_ALBEDOFORREFRACTIONTINT = false;\n defines.SS_ALBEDOFORTRANSLUCENCYTINT = false;\n defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;\n defines.SS_USE_THICKNESS_AS_DEPTH = false;\n const refractionIntensityTextureIsThicknessTexture = !!this._thicknessTexture &&\n !!this._refractionIntensityTexture &&\n this._refractionIntensityTexture.checkTransformsAreIdentical(this._thicknessTexture) &&\n this._refractionIntensityTexture._texture === this._thicknessTexture._texture;\n const translucencyIntensityTextureIsThicknessTexture = !!this._thicknessTexture &&\n !!this._translucencyIntensityTexture &&\n this._translucencyIntensityTexture.checkTransformsAreIdentical(this._thicknessTexture) &&\n this._translucencyIntensityTexture._texture === this._thicknessTexture._texture;\n // if true, it means the refraction/translucency textures are the same than the thickness texture so there's no need to pass them to the shader, only thicknessTexture\n const useOnlyThicknessTexture = (refractionIntensityTextureIsThicknessTexture || !this._refractionIntensityTexture) &&\n (translucencyIntensityTextureIsThicknessTexture || !this._translucencyIntensityTexture);\n if (defines._areTexturesDirty) {\n if (scene.texturesEnabled) {\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._thicknessTexture, defines, \"SS_THICKNESSANDMASK_TEXTURE\");\n }\n if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && !useOnlyThicknessTexture) {\n MaterialHelper.PrepareDefinesForMergedUV(this._refractionIntensityTexture, defines, \"SS_REFRACTIONINTENSITY_TEXTURE\");\n }\n if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && !useOnlyThicknessTexture) {\n MaterialHelper.PrepareDefinesForMergedUV(this._translucencyIntensityTexture, defines, \"SS_TRANSLUCENCYINTENSITY_TEXTURE\");\n }\n }\n }\n defines.SS_HAS_THICKNESS = this.maximumThickness - this.minimumThickness !== 0.0;\n defines.SS_MASK_FROM_THICKNESS_TEXTURE =\n (this._useMaskFromThicknessTexture || !!this._refractionIntensityTexture || !!this._translucencyIntensityTexture) && useOnlyThicknessTexture;\n defines.SS_USE_GLTF_TEXTURES = this._useGltfStyleTextures;\n defines.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = (this._useMaskFromThicknessTexture || !!this._refractionIntensityTexture) && useOnlyThicknessTexture;\n defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = (this._useMaskFromThicknessTexture || !!this._translucencyIntensityTexture) && useOnlyThicknessTexture;\n if (this._isRefractionEnabled) {\n if (scene.texturesEnabled) {\n const refractionTexture = this._getRefractionTexture(scene);\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\n defines.SS_REFRACTION = true;\n defines.SS_REFRACTIONMAP_3D = refractionTexture.isCube;\n defines.SS_GAMMAREFRACTION = refractionTexture.gammaSpace;\n defines.SS_RGBDREFRACTION = refractionTexture.isRGBD;\n defines.SS_LINEARSPECULARREFRACTION = refractionTexture.linearSpecularLOD;\n defines.SS_REFRACTIONMAP_OPPOSITEZ = this._scene.useRightHandedSystem && refractionTexture.isCube ? !refractionTexture.invertZ : refractionTexture.invertZ;\n defines.SS_LODINREFRACTIONALPHA = refractionTexture.lodLevelInAlpha;\n defines.SS_LINKREFRACTIONTOTRANSPARENCY = this._linkRefractionWithTransparency;\n defines.SS_ALBEDOFORREFRACTIONTINT = this.useAlbedoToTintRefraction;\n defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = refractionTexture.isCube && refractionTexture.boundingBoxSize;\n defines.SS_USE_THICKNESS_AS_DEPTH = this.useThicknessAsDepth;\n }\n }\n }\n if (this._isTranslucencyEnabled) {\n defines.SS_ALBEDOFORTRANSLUCENCYTINT = this.useAlbedoToTintTranslucency;\n }\n }\n }\n /**\n * Binds the material data (this function is called even if mustRebind() returns false)\n * @param uniformBuffer defines the Uniform buffer to fill in.\n * @param scene defines the scene the material belongs to.\n * @param engine defines the engine the material belongs to.\n * @param subMesh the submesh to bind data for\n */\n hardBindForSubMesh(uniformBuffer, scene, engine, subMesh) {\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\n return;\n }\n subMesh.getRenderingMesh().getWorldMatrix().decompose(TmpVectors.Vector3[0]);\n const thicknessScale = Math.max(Math.abs(TmpVectors.Vector3[0].x), Math.abs(TmpVectors.Vector3[0].y), Math.abs(TmpVectors.Vector3[0].z));\n uniformBuffer.updateFloat2(\"vThicknessParam\", this.minimumThickness * thicknessScale, (this.maximumThickness - this.minimumThickness) * thicknessScale);\n }\n bindForSubMesh(uniformBuffer, scene, engine, subMesh) {\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\n return;\n }\n const defines = subMesh.materialDefines;\n const isFrozen = this._material.isFrozen;\n const realTimeFiltering = this._material.realTimeFiltering;\n const lodBasedMicrosurface = defines.LODBASEDMICROSFURACE;\n const refractionTexture = this._getRefractionTexture(scene);\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\n uniformBuffer.updateFloat2(\"vThicknessInfos\", this._thicknessTexture.coordinatesIndex, this._thicknessTexture.level);\n MaterialHelper.BindTextureMatrix(this._thicknessTexture, uniformBuffer, \"thickness\");\n }\n if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && defines.SS_REFRACTIONINTENSITY_TEXTURE) {\n uniformBuffer.updateFloat2(\"vRefractionIntensityInfos\", this._refractionIntensityTexture.coordinatesIndex, this._refractionIntensityTexture.level);\n MaterialHelper.BindTextureMatrix(this._refractionIntensityTexture, uniformBuffer, \"refractionIntensity\");\n }\n if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && defines.SS_TRANSLUCENCYINTENSITY_TEXTURE) {\n uniformBuffer.updateFloat2(\"vTranslucencyIntensityInfos\", this._translucencyIntensityTexture.coordinatesIndex, this._translucencyIntensityTexture.level);\n MaterialHelper.BindTextureMatrix(this._translucencyIntensityTexture, uniformBuffer, \"translucencyIntensity\");\n }\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\n uniformBuffer.updateMatrix(\"refractionMatrix\", refractionTexture.getRefractionTextureMatrix());\n let depth = 1.0;\n if (!refractionTexture.isCube) {\n if (refractionTexture.depth) {\n depth = refractionTexture.depth;\n }\n }\n const width = refractionTexture.getSize().width;\n const refractionIor = this.volumeIndexOfRefraction;\n uniformBuffer.updateFloat4(\"vRefractionInfos\", refractionTexture.level, 1 / refractionIor, depth, this._invertRefractionY ? -1 : 1);\n uniformBuffer.updateFloat4(\"vRefractionMicrosurfaceInfos\", width, refractionTexture.lodGenerationScale, refractionTexture.lodGenerationOffset, 1.0 / this.indexOfRefraction);\n if (realTimeFiltering) {\n uniformBuffer.updateFloat2(\"vRefractionFilteringInfo\", width, Scalar.Log2(width));\n }\n if (refractionTexture.boundingBoxSize) {\n const cubeTexture = refractionTexture;\n uniformBuffer.updateVector3(\"vRefractionPosition\", cubeTexture.boundingBoxPosition);\n uniformBuffer.updateVector3(\"vRefractionSize\", cubeTexture.boundingBoxSize);\n }\n }\n if (this._isScatteringEnabled) {\n uniformBuffer.updateFloat(\"scatteringDiffusionProfile\", this._scatteringDiffusionProfileIndex);\n }\n uniformBuffer.updateColor3(\"vDiffusionDistance\", this.diffusionDistance);\n uniformBuffer.updateFloat4(\"vTintColor\", this.tintColor.r, this.tintColor.g, this.tintColor.b, Math.max(0.00001, this.tintColorAtDistance));\n uniformBuffer.updateFloat3(\"vSubSurfaceIntensity\", this.refractionIntensity, this.translucencyIntensity, 0);\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\n uniformBuffer.setTexture(\"thicknessSampler\", this._thicknessTexture);\n }\n if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && defines.SS_REFRACTIONINTENSITY_TEXTURE) {\n uniformBuffer.setTexture(\"refractionIntensitySampler\", this._refractionIntensityTexture);\n }\n if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && defines.SS_TRANSLUCENCYINTENSITY_TEXTURE) {\n uniformBuffer.setTexture(\"translucencyIntensitySampler\", this._translucencyIntensityTexture);\n }\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\n if (lodBasedMicrosurface) {\n uniformBuffer.setTexture(\"refractionSampler\", refractionTexture);\n }\n else {\n uniformBuffer.setTexture(\"refractionSampler\", refractionTexture._lodTextureMid || refractionTexture);\n uniformBuffer.setTexture(\"refractionSamplerLow\", refractionTexture._lodTextureLow || refractionTexture);\n uniformBuffer.setTexture(\"refractionSamplerHigh\", refractionTexture._lodTextureHigh || refractionTexture);\n }\n }\n }\n }\n /**\n * Returns the texture used for refraction or null if none is used.\n * @param scene defines the scene the material belongs to.\n * @returns - Refraction texture if present. If no refraction texture and refraction\n * is linked with transparency, returns environment texture. Otherwise, returns null.\n */\n _getRefractionTexture(scene) {\n if (this._refractionTexture) {\n return this._refractionTexture;\n }\n if (this._isRefractionEnabled) {\n return scene.environmentTexture;\n }\n return null;\n }\n /**\n * Returns true if alpha blending should be disabled.\n */\n get disableAlphaBlending() {\n return this._isRefractionEnabled && this._linkRefractionWithTransparency;\n }\n /**\n * Fills the list of render target textures.\n * @param renderTargets the list of render targets to update\n */\n fillRenderTargetTextures(renderTargets) {\n if (MaterialFlags.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\n renderTargets.push(this._refractionTexture);\n }\n }\n hasTexture(texture) {\n if (this._thicknessTexture === texture) {\n return true;\n }\n if (this._refractionTexture === texture) {\n return true;\n }\n return false;\n }\n hasRenderTargetTextures() {\n if (MaterialFlags.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\n return true;\n }\n return false;\n }\n getActiveTextures(activeTextures) {\n if (this._thicknessTexture) {\n activeTextures.push(this._thicknessTexture);\n }\n if (this._refractionTexture) {\n activeTextures.push(this._refractionTexture);\n }\n }\n getAnimatables(animatables) {\n if (this._thicknessTexture && this._thicknessTexture.animations && this._thicknessTexture.animations.length > 0) {\n animatables.push(this._thicknessTexture);\n }\n if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {\n animatables.push(this._refractionTexture);\n }\n }\n dispose(forceDisposeTextures) {\n if (forceDisposeTextures) {\n if (this._thicknessTexture) {\n this._thicknessTexture.dispose();\n }\n if (this._refractionTexture) {\n this._refractionTexture.dispose();\n }\n }\n }\n getClassName() {\n return \"PBRSubSurfaceConfiguration\";\n }\n addFallbacks(defines, fallbacks, currentRank) {\n if (defines.SS_SCATTERING) {\n fallbacks.addFallback(currentRank++, \"SS_SCATTERING\");\n }\n if (defines.SS_TRANSLUCENCY) {\n fallbacks.addFallback(currentRank++, \"SS_TRANSLUCENCY\");\n }\n return currentRank;\n }\n getSamplers(samplers) {\n samplers.push(\"thicknessSampler\", \"refractionIntensitySampler\", \"translucencyIntensitySampler\", \"refractionSampler\", \"refractionSamplerLow\", \"refractionSamplerHigh\");\n }\n getUniforms() {\n return {\n ubo: [\n { name: \"vRefractionMicrosurfaceInfos\", size: 4, type: \"vec4\" },\n { name: \"vRefractionFilteringInfo\", size: 2, type: \"vec2\" },\n { name: \"vTranslucencyIntensityInfos\", size: 2, type: \"vec2\" },\n { name: \"vRefractionInfos\", size: 4, type: \"vec4\" },\n { name: \"refractionMatrix\", size: 16, type: \"mat4\" },\n { name: \"vThicknessInfos\", size: 2, type: \"vec2\" },\n { name: \"vRefractionIntensityInfos\", size: 2, type: \"vec2\" },\n { name: \"thicknessMatrix\", size: 16, type: \"mat4\" },\n { name: \"refractionIntensityMatrix\", size: 16, type: \"mat4\" },\n { name: \"translucencyIntensityMatrix\", size: 16, type: \"mat4\" },\n { name: \"vThicknessParam\", size: 2, type: \"vec2\" },\n { name: \"vDiffusionDistance\", size: 3, type: \"vec3\" },\n { name: \"vTintColor\", size: 4, type: \"vec4\" },\n { name: \"vSubSurfaceIntensity\", size: 3, type: \"vec3\" },\n { name: \"vRefractionPosition\", size: 3, type: \"vec3\" },\n { name: \"vRefractionSize\", size: 3, type: \"vec3\" },\n { name: \"scatteringDiffusionProfile\", size: 1, type: \"float\" },\n ],\n };\n }\n }\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"isRefractionEnabled\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"isTranslucencyEnabled\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markScenePrePassDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"isScatteringEnabled\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"_scatteringDiffusionProfileIndex\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"refractionIntensity\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"translucencyIntensity\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"useAlbedoToTintRefraction\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"useAlbedoToTintTranslucency\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"thicknessTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"refractionTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"indexOfRefraction\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"_volumeIndexOfRefraction\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"volumeIndexOfRefraction\", null);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"invertRefractionY\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"linkRefractionWithTransparency\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"minimumThickness\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"maximumThickness\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"useThicknessAsDepth\", void 0);\n __decorate$1([\n serializeAsColor3()\n ], PBRSubSurfaceConfiguration.prototype, \"tintColor\", void 0);\n __decorate$1([\n serialize()\n ], PBRSubSurfaceConfiguration.prototype, \"tintColorAtDistance\", void 0);\n __decorate$1([\n serializeAsColor3()\n ], PBRSubSurfaceConfiguration.prototype, \"diffusionDistance\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"useMaskFromThicknessTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"refractionIntensityTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"translucencyIntensityTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRSubSurfaceConfiguration.prototype, \"useGltfStyleTextures\", void 0);\n\n const onCreatedEffectParameters$1 = { effect: null, subMesh: null };\n /**\n * Manages the defines for the PBR Material.\n * @internal\n */\n class PBRMaterialDefines extends MaterialDefines {\n /**\n * Initializes the PBR Material defines.\n * @param externalProperties The external properties\n */\n constructor(externalProperties) {\n super(externalProperties);\n this.PBR = true;\n this.NUM_SAMPLES = \"0\";\n this.REALTIME_FILTERING = false;\n this.MAINUV1 = false;\n this.MAINUV2 = false;\n this.MAINUV3 = false;\n this.MAINUV4 = false;\n this.MAINUV5 = false;\n this.MAINUV6 = false;\n this.UV1 = false;\n this.UV2 = false;\n this.UV3 = false;\n this.UV4 = false;\n this.UV5 = false;\n this.UV6 = false;\n this.ALBEDO = false;\n this.GAMMAALBEDO = false;\n this.ALBEDODIRECTUV = 0;\n this.VERTEXCOLOR = false;\n this.BAKED_VERTEX_ANIMATION_TEXTURE = false;\n this.AMBIENT = false;\n this.AMBIENTDIRECTUV = 0;\n this.AMBIENTINGRAYSCALE = false;\n this.OPACITY = false;\n this.VERTEXALPHA = false;\n this.OPACITYDIRECTUV = 0;\n this.OPACITYRGB = false;\n this.ALPHATEST = false;\n this.DEPTHPREPASS = false;\n this.ALPHABLEND = false;\n this.ALPHAFROMALBEDO = false;\n this.ALPHATESTVALUE = \"0.5\";\n this.SPECULAROVERALPHA = false;\n this.RADIANCEOVERALPHA = false;\n this.ALPHAFRESNEL = false;\n this.LINEARALPHAFRESNEL = false;\n this.PREMULTIPLYALPHA = false;\n this.EMISSIVE = false;\n this.EMISSIVEDIRECTUV = 0;\n this.GAMMAEMISSIVE = false;\n this.REFLECTIVITY = false;\n this.REFLECTIVITY_GAMMA = false;\n this.REFLECTIVITYDIRECTUV = 0;\n this.SPECULARTERM = false;\n this.MICROSURFACEFROMREFLECTIVITYMAP = false;\n this.MICROSURFACEAUTOMATIC = false;\n this.LODBASEDMICROSFURACE = false;\n this.MICROSURFACEMAP = false;\n this.MICROSURFACEMAPDIRECTUV = 0;\n this.METALLICWORKFLOW = false;\n this.ROUGHNESSSTOREINMETALMAPALPHA = false;\n this.ROUGHNESSSTOREINMETALMAPGREEN = false;\n this.METALLNESSSTOREINMETALMAPBLUE = false;\n this.AOSTOREINMETALMAPRED = false;\n this.METALLIC_REFLECTANCE = false;\n this.METALLIC_REFLECTANCE_GAMMA = false;\n this.METALLIC_REFLECTANCEDIRECTUV = 0;\n this.METALLIC_REFLECTANCE_USE_ALPHA_ONLY = false;\n this.REFLECTANCE = false;\n this.REFLECTANCE_GAMMA = false;\n this.REFLECTANCEDIRECTUV = 0;\n this.ENVIRONMENTBRDF = false;\n this.ENVIRONMENTBRDF_RGBD = false;\n this.NORMAL = false;\n this.TANGENT = false;\n this.BUMP = false;\n this.BUMPDIRECTUV = 0;\n this.OBJECTSPACE_NORMALMAP = false;\n this.PARALLAX = false;\n this.PARALLAXOCCLUSION = false;\n this.NORMALXYSCALE = true;\n this.LIGHTMAP = false;\n this.LIGHTMAPDIRECTUV = 0;\n this.USELIGHTMAPASSHADOWMAP = false;\n this.GAMMALIGHTMAP = false;\n this.RGBDLIGHTMAP = false;\n this.REFLECTION = false;\n this.REFLECTIONMAP_3D = false;\n this.REFLECTIONMAP_SPHERICAL = false;\n this.REFLECTIONMAP_PLANAR = false;\n this.REFLECTIONMAP_CUBIC = false;\n this.USE_LOCAL_REFLECTIONMAP_CUBIC = false;\n this.REFLECTIONMAP_PROJECTION = false;\n this.REFLECTIONMAP_SKYBOX = false;\n this.REFLECTIONMAP_EXPLICIT = false;\n this.REFLECTIONMAP_EQUIRECTANGULAR = false;\n this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\n this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\n this.INVERTCUBICMAP = false;\n this.USESPHERICALFROMREFLECTIONMAP = false;\n this.USEIRRADIANCEMAP = false;\n this.USESPHERICALINVERTEX = false;\n this.REFLECTIONMAP_OPPOSITEZ = false;\n this.LODINREFLECTIONALPHA = false;\n this.GAMMAREFLECTION = false;\n this.RGBDREFLECTION = false;\n this.LINEARSPECULARREFLECTION = false;\n this.RADIANCEOCCLUSION = false;\n this.HORIZONOCCLUSION = false;\n this.INSTANCES = false;\n this.THIN_INSTANCES = false;\n this.INSTANCESCOLOR = false;\n this.PREPASS = false;\n this.PREPASS_IRRADIANCE = false;\n this.PREPASS_IRRADIANCE_INDEX = -1;\n this.PREPASS_ALBEDO_SQRT = false;\n this.PREPASS_ALBEDO_SQRT_INDEX = -1;\n this.PREPASS_DEPTH = false;\n this.PREPASS_DEPTH_INDEX = -1;\n this.PREPASS_NORMAL = false;\n this.PREPASS_NORMAL_INDEX = -1;\n this.PREPASS_POSITION = false;\n this.PREPASS_POSITION_INDEX = -1;\n this.PREPASS_VELOCITY = false;\n this.PREPASS_VELOCITY_INDEX = -1;\n this.PREPASS_REFLECTIVITY = false;\n this.PREPASS_REFLECTIVITY_INDEX = -1;\n this.SCENE_MRT_COUNT = 0;\n this.NUM_BONE_INFLUENCERS = 0;\n this.BonesPerMesh = 0;\n this.BONETEXTURE = false;\n this.BONES_VELOCITY_ENABLED = false;\n this.NONUNIFORMSCALING = false;\n this.MORPHTARGETS = false;\n this.MORPHTARGETS_NORMAL = false;\n this.MORPHTARGETS_TANGENT = false;\n this.MORPHTARGETS_UV = false;\n this.NUM_MORPH_INFLUENCERS = 0;\n this.MORPHTARGETS_TEXTURE = false;\n this.IMAGEPROCESSING = false;\n this.VIGNETTE = false;\n this.VIGNETTEBLENDMODEMULTIPLY = false;\n this.VIGNETTEBLENDMODEOPAQUE = false;\n this.TONEMAPPING = false;\n this.TONEMAPPING_ACES = false;\n this.CONTRAST = false;\n this.COLORCURVES = false;\n this.COLORGRADING = false;\n this.COLORGRADING3D = false;\n this.SAMPLER3DGREENDEPTH = false;\n this.SAMPLER3DBGRMAP = false;\n this.DITHER = false;\n this.IMAGEPROCESSINGPOSTPROCESS = false;\n this.SKIPFINALCOLORCLAMP = false;\n this.EXPOSURE = false;\n this.MULTIVIEW = false;\n this.ORDER_INDEPENDENT_TRANSPARENCY = false;\n this.ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;\n this.USEPHYSICALLIGHTFALLOFF = false;\n this.USEGLTFLIGHTFALLOFF = false;\n this.TWOSIDEDLIGHTING = false;\n this.SHADOWFLOAT = false;\n this.CLIPPLANE = false;\n this.CLIPPLANE2 = false;\n this.CLIPPLANE3 = false;\n this.CLIPPLANE4 = false;\n this.CLIPPLANE5 = false;\n this.CLIPPLANE6 = false;\n this.POINTSIZE = false;\n this.FOG = false;\n this.LOGARITHMICDEPTH = false;\n this.CAMERA_ORTHOGRAPHIC = false;\n this.CAMERA_PERSPECTIVE = false;\n this.FORCENORMALFORWARD = false;\n this.SPECULARAA = false;\n this.UNLIT = false;\n this.DECAL_AFTER_DETAIL = false;\n this.DEBUGMODE = 0;\n this.rebuild();\n }\n /**\n * Resets the PBR Material defines.\n */\n reset() {\n super.reset();\n this.ALPHATESTVALUE = \"0.5\";\n this.PBR = true;\n this.NORMALXYSCALE = true;\n }\n }\n /**\n * The Physically based material base class of BJS.\n *\n * This offers the main features of a standard PBR material.\n * For more information, please refer to the documentation :\n * https://doc.babylonjs.com/features/featuresDeepDive/materials/using/introToPBR\n */\n class PBRBaseMaterial extends PushMaterial {\n /**\n * Enables realtime filtering on the texture.\n */\n get realTimeFiltering() {\n return this._realTimeFiltering;\n }\n set realTimeFiltering(b) {\n this._realTimeFiltering = b;\n this.markAsDirty(1);\n }\n /**\n * Quality switch for realtime filtering\n */\n get realTimeFilteringQuality() {\n return this._realTimeFilteringQuality;\n }\n set realTimeFilteringQuality(n) {\n this._realTimeFilteringQuality = n;\n this.markAsDirty(1);\n }\n /**\n * Can this material render to several textures at once\n */\n get canRenderToMRT() {\n return true;\n }\n /**\n * Attaches a new image processing configuration to the PBR Material.\n * @param configuration\n */\n _attachImageProcessingConfiguration(configuration) {\n if (configuration === this._imageProcessingConfiguration) {\n return;\n }\n // Detaches observer.\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n // Pick the scene configuration if needed.\n if (!configuration) {\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\n }\n else {\n this._imageProcessingConfiguration = configuration;\n }\n // Attaches observer.\n if (this._imageProcessingConfiguration) {\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\n this._markAllSubMeshesAsImageProcessingDirty();\n });\n }\n }\n /**\n * Instantiates a new PBRMaterial instance.\n *\n * @param name The material name\n * @param scene The scene the material will be use in.\n */\n constructor(name, scene) {\n super(name, scene);\n /**\n * Intensity of the direct lights e.g. the four lights available in your scene.\n * This impacts both the direct diffuse and specular highlights.\n * @internal\n */\n this._directIntensity = 1.0;\n /**\n * Intensity of the emissive part of the material.\n * This helps controlling the emissive effect without modifying the emissive color.\n * @internal\n */\n this._emissiveIntensity = 1.0;\n /**\n * Intensity of the environment e.g. how much the environment will light the object\n * either through harmonics for rough material or through the reflection for shiny ones.\n * @internal\n */\n this._environmentIntensity = 1.0;\n /**\n * This is a special control allowing the reduction of the specular highlights coming from the\n * four lights of the scene. Those highlights may not be needed in full environment lighting.\n * @internal\n */\n this._specularIntensity = 1.0;\n /**\n * This stores the direct, emissive, environment, and specular light intensities into a Vector4.\n */\n this._lightingInfos = new Vector4(this._directIntensity, this._emissiveIntensity, this._environmentIntensity, this._specularIntensity);\n /**\n * Debug Control allowing disabling the bump map on this material.\n * @internal\n */\n this._disableBumpMap = false;\n /**\n * AKA Diffuse Texture in standard nomenclature.\n * @internal\n */\n this._albedoTexture = null;\n /**\n * AKA Occlusion Texture in other nomenclature.\n * @internal\n */\n this._ambientTexture = null;\n /**\n * AKA Occlusion Texture Intensity in other nomenclature.\n * @internal\n */\n this._ambientTextureStrength = 1.0;\n /**\n * Defines how much the AO map is occluding the analytical lights (point spot...).\n * 1 means it completely occludes it\n * 0 mean it has no impact\n * @internal\n */\n this._ambientTextureImpactOnAnalyticalLights = PBRBaseMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;\n /**\n * Stores the alpha values in a texture.\n * @internal\n */\n this._opacityTexture = null;\n /**\n * Stores the reflection values in a texture.\n * @internal\n */\n this._reflectionTexture = null;\n /**\n * Stores the emissive values in a texture.\n * @internal\n */\n this._emissiveTexture = null;\n /**\n * AKA Specular texture in other nomenclature.\n * @internal\n */\n this._reflectivityTexture = null;\n /**\n * Used to switch from specular/glossiness to metallic/roughness workflow.\n * @internal\n */\n this._metallicTexture = null;\n /**\n * Specifies the metallic scalar of the metallic/roughness workflow.\n * Can also be used to scale the metalness values of the metallic texture.\n * @internal\n */\n this._metallic = null;\n /**\n * Specifies the roughness scalar of the metallic/roughness workflow.\n * Can also be used to scale the roughness values of the metallic texture.\n * @internal\n */\n this._roughness = null;\n /**\n * In metallic workflow, specifies an F0 factor to help configuring the material F0.\n * By default the indexOfrefraction is used to compute F0;\n *\n * This is used as a factor against the default reflectance at normal incidence to tweak it.\n *\n * F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor;\n * F90 = metallicReflectanceColor;\n * @internal\n */\n this._metallicF0Factor = 1;\n /**\n * In metallic workflow, specifies an F0 color.\n * By default the F90 is always 1;\n *\n * Please note that this factor is also used as a factor against the default reflectance at normal incidence.\n *\n * F0 = defaultF0_from_IOR * metallicF0Factor * metallicReflectanceColor\n * F90 = metallicF0Factor;\n * @internal\n */\n this._metallicReflectanceColor = Color3.White();\n /**\n * Specifies that only the A channel from _metallicReflectanceTexture should be used.\n * If false, both RGB and A channels will be used\n * @internal\n */\n this._useOnlyMetallicFromMetallicReflectanceTexture = false;\n /**\n * Defines to store metallicReflectanceColor in RGB and metallicF0Factor in A\n * This is multiply against the scalar values defined in the material.\n * @internal\n */\n this._metallicReflectanceTexture = null;\n /**\n * Defines to store reflectanceColor in RGB\n * This is multiplied against the scalar values defined in the material.\n * If both _reflectanceTexture and _metallicReflectanceTexture textures are provided and _useOnlyMetallicFromMetallicReflectanceTexture\n * is false, _metallicReflectanceTexture takes precedence and _reflectanceTexture is not used\n * @internal\n */\n this._reflectanceTexture = null;\n /**\n * Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.\n * Gray Scale represents roughness in metallic mode and glossiness in specular mode.\n * @internal\n */\n this._microSurfaceTexture = null;\n /**\n * Stores surface normal data used to displace a mesh in a texture.\n * @internal\n */\n this._bumpTexture = null;\n /**\n * Stores the pre-calculated light information of a mesh in a texture.\n * @internal\n */\n this._lightmapTexture = null;\n /**\n * The color of a material in ambient lighting.\n * @internal\n */\n this._ambientColor = new Color3(0, 0, 0);\n /**\n * AKA Diffuse Color in other nomenclature.\n * @internal\n */\n this._albedoColor = new Color3(1, 1, 1);\n /**\n * AKA Specular Color in other nomenclature.\n * @internal\n */\n this._reflectivityColor = new Color3(1, 1, 1);\n /**\n * The color applied when light is reflected from a material.\n * @internal\n */\n this._reflectionColor = new Color3(1, 1, 1);\n /**\n * The color applied when light is emitted from a material.\n * @internal\n */\n this._emissiveColor = new Color3(0, 0, 0);\n /**\n * AKA Glossiness in other nomenclature.\n * @internal\n */\n this._microSurface = 0.9;\n /**\n * Specifies that the material will use the light map as a show map.\n * @internal\n */\n this._useLightmapAsShadowmap = false;\n /**\n * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal\n * makes the reflect vector face the model (under horizon).\n * @internal\n */\n this._useHorizonOcclusion = true;\n /**\n * This parameters will enable/disable radiance occlusion by preventing the radiance to lit\n * too much the area relying on ambient texture to define their ambient occlusion.\n * @internal\n */\n this._useRadianceOcclusion = true;\n /**\n * Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.\n * @internal\n */\n this._useAlphaFromAlbedoTexture = false;\n /**\n * Specifies that the material will keeps the specular highlights over a transparent surface (only the most luminous ones).\n * A car glass is a good example of that. When sun reflects on it you can not see what is behind.\n * @internal\n */\n this._useSpecularOverAlpha = true;\n /**\n * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.\n * @internal\n */\n this._useMicroSurfaceFromReflectivityMapAlpha = false;\n /**\n * Specifies if the metallic texture contains the roughness information in its alpha channel.\n * @internal\n */\n this._useRoughnessFromMetallicTextureAlpha = true;\n /**\n * Specifies if the metallic texture contains the roughness information in its green channel.\n * @internal\n */\n this._useRoughnessFromMetallicTextureGreen = false;\n /**\n * Specifies if the metallic texture contains the metallness information in its blue channel.\n * @internal\n */\n this._useMetallnessFromMetallicTextureBlue = false;\n /**\n * Specifies if the metallic texture contains the ambient occlusion information in its red channel.\n * @internal\n */\n this._useAmbientOcclusionFromMetallicTextureRed = false;\n /**\n * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.\n * @internal\n */\n this._useAmbientInGrayScale = false;\n /**\n * In case the reflectivity map does not contain the microsurface information in its alpha channel,\n * The material will try to infer what glossiness each pixel should be.\n * @internal\n */\n this._useAutoMicroSurfaceFromReflectivityMap = false;\n /**\n * Defines the falloff type used in this material.\n * It by default is Physical.\n * @internal\n */\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL;\n /**\n * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most luminous ones).\n * A car glass is a good example of that. When the street lights reflects on it you can not see what is behind.\n * @internal\n */\n this._useRadianceOverAlpha = true;\n /**\n * Allows using an object space normal map (instead of tangent space).\n * @internal\n */\n this._useObjectSpaceNormalMap = false;\n /**\n * Allows using the bump map in parallax mode.\n * @internal\n */\n this._useParallax = false;\n /**\n * Allows using the bump map in parallax occlusion mode.\n * @internal\n */\n this._useParallaxOcclusion = false;\n /**\n * Controls the scale bias of the parallax mode.\n * @internal\n */\n this._parallaxScaleBias = 0.05;\n /**\n * If sets to true, disables all the lights affecting the material.\n * @internal\n */\n this._disableLighting = false;\n /**\n * Number of Simultaneous lights allowed on the material.\n * @internal\n */\n this._maxSimultaneousLights = 4;\n /**\n * If sets to true, x component of normal map value will be inverted (x = 1.0 - x).\n * @internal\n */\n this._invertNormalMapX = false;\n /**\n * If sets to true, y component of normal map value will be inverted (y = 1.0 - y).\n * @internal\n */\n this._invertNormalMapY = false;\n /**\n * If sets to true and backfaceCulling is false, normals will be flipped on the backside.\n * @internal\n */\n this._twoSidedLighting = false;\n /**\n * Defines the alpha limits in alpha test mode.\n * @internal\n */\n this._alphaCutOff = 0.4;\n /**\n * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.\n * @internal\n */\n this._forceAlphaTest = false;\n /**\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\n * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)\n * @internal\n */\n this._useAlphaFresnel = false;\n /**\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\n * And/Or occlude the blended part. (alpha stays linear to compute the fresnel)\n * @internal\n */\n this._useLinearAlphaFresnel = false;\n /**\n * Specifies the environment BRDF texture used to compute the scale and offset roughness values\n * from cos theta and roughness:\n * http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf\n * @internal\n */\n this._environmentBRDFTexture = null;\n /**\n * Force the shader to compute irradiance in the fragment shader in order to take bump in account.\n * @internal\n */\n this._forceIrradianceInFragment = false;\n this._realTimeFiltering = false;\n this._realTimeFilteringQuality = 8;\n /**\n * Force normal to face away from face.\n * @internal\n */\n this._forceNormalForward = false;\n /**\n * Enables specular anti aliasing in the PBR shader.\n * It will both interacts on the Geometry for analytical and IBL lighting.\n * It also prefilter the roughness map based on the bump values.\n * @internal\n */\n this._enableSpecularAntiAliasing = false;\n /**\n * Keep track of the image processing observer to allow dispose and replace.\n */\n this._imageProcessingObserver = null;\n /**\n * Stores the available render targets.\n */\n this._renderTargets = new SmartArray(16);\n /**\n * Sets the global ambient color for the material used in lighting calculations.\n */\n this._globalAmbientColor = new Color3(0, 0, 0);\n /**\n * Enables the use of logarithmic depth buffers, which is good for wide depth buffers.\n */\n this._useLogarithmicDepth = false;\n /**\n * If set to true, no lighting calculations will be applied.\n */\n this._unlit = false;\n /**\n * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)\n */\n this._applyDecalMapAfterDetailMap = false;\n this._debugMode = 0;\n /**\n * @internal\n * This is reserved for the inspector.\n * Defines the material debug mode.\n * It helps seeing only some components of the material while troubleshooting.\n */\n this.debugMode = 0;\n /**\n * @internal\n * This is reserved for the inspector.\n * Specify from where on screen the debug mode should start.\n * The value goes from -1 (full screen) to 1 (not visible)\n * It helps with side by side comparison against the final render\n * This defaults to -1\n */\n this.debugLimit = -1;\n /**\n * @internal\n * This is reserved for the inspector.\n * As the default viewing range might not be enough (if the ambient is really small for instance)\n * You can use the factor to better multiply the final value.\n */\n this.debugFactor = 1;\n this._cacheHasRenderTargetTextures = false;\n this.brdf = new PBRBRDFConfiguration(this);\n this.clearCoat = new PBRClearCoatConfiguration(this);\n this.iridescence = new PBRIridescenceConfiguration(this);\n this.anisotropy = new PBRAnisotropicConfiguration(this);\n this.sheen = new PBRSheenConfiguration(this);\n this.subSurface = new PBRSubSurfaceConfiguration(this);\n this.detailMap = new DetailMapConfiguration(this);\n // Setup the default processing configuration to the scene.\n this._attachImageProcessingConfiguration(null);\n this.getRenderTargetTextures = () => {\n this._renderTargets.reset();\n if (MaterialFlags.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n this._renderTargets.push(this._reflectionTexture);\n }\n this._eventInfo.renderTargets = this._renderTargets;\n this._callbackPluginEventFillRenderTargetTextures(this._eventInfo);\n return this._renderTargets;\n };\n this._environmentBRDFTexture = GetEnvironmentBRDFTexture(this.getScene());\n this.prePassConfiguration = new PrePassConfiguration();\n }\n /**\n * Gets a boolean indicating that current material needs to register RTT\n */\n get hasRenderTargetTextures() {\n if (MaterialFlags.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n return true;\n }\n return this._cacheHasRenderTargetTextures;\n }\n /**\n * Can this material render to prepass\n */\n get isPrePassCapable() {\n return !this.disableDepthWrite;\n }\n /**\n * Gets the name of the material class.\n */\n getClassName() {\n return \"PBRBaseMaterial\";\n }\n /**\n * Enabled the use of logarithmic depth buffers, which is good for wide depth buffers.\n */\n get useLogarithmicDepth() {\n return this._useLogarithmicDepth;\n }\n /**\n * Enabled the use of logarithmic depth buffers, which is good for wide depth buffers.\n */\n set useLogarithmicDepth(value) {\n this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;\n }\n /**\n * Returns true if alpha blending should be disabled.\n */\n get _disableAlphaBlending() {\n var _a;\n return (this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_OPAQUE ||\n this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST ||\n ((_a = this.subSurface) === null || _a === void 0 ? void 0 : _a.disableAlphaBlending));\n }\n /**\n * Specifies whether or not this material should be rendered in alpha blend mode.\n */\n needAlphaBlending() {\n if (this._disableAlphaBlending) {\n return false;\n }\n return this.alpha < 1.0 || this._opacityTexture != null || this._shouldUseAlphaFromAlbedoTexture();\n }\n /**\n * Specifies whether or not this material should be rendered in alpha test mode.\n */\n needAlphaTesting() {\n var _a;\n if (this._forceAlphaTest) {\n return true;\n }\n if ((_a = this.subSurface) === null || _a === void 0 ? void 0 : _a.disableAlphaBlending) {\n return false;\n }\n return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST);\n }\n /**\n * Specifies whether or not the alpha value of the albedo texture should be used for alpha blending.\n */\n _shouldUseAlphaFromAlbedoTexture() {\n return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE;\n }\n /**\n * Specifies whether or not there is a usable alpha channel for transparency.\n */\n _hasAlphaChannel() {\n return (this._albedoTexture != null && this._albedoTexture.hasAlpha) || this._opacityTexture != null;\n }\n /**\n * Gets the texture used for the alpha test.\n */\n getAlphaTestTexture() {\n return this._albedoTexture;\n }\n /**\n * Specifies that the submesh is ready to be used.\n * @param mesh - BJS mesh.\n * @param subMesh - A submesh of the BJS mesh. Used to check if it is ready.\n * @param useInstances - Specifies that instances should be used.\n * @returns - boolean indicating that the submesh is ready or not.\n */\n isReadyForSubMesh(mesh, subMesh, useInstances) {\n var _a;\n if (!this._uniformBufferLayoutBuilt) {\n this.buildUniformLayout();\n }\n if (subMesh.effect && this.isFrozen) {\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\n return true;\n }\n }\n if (!subMesh.materialDefines) {\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetDefineNames, this._eventInfo);\n subMesh.materialDefines = new PBRMaterialDefines(this._eventInfo.defineNames);\n }\n const defines = subMesh.materialDefines;\n if (this._isReadyForSubMesh(subMesh)) {\n return true;\n }\n const scene = this.getScene();\n const engine = scene.getEngine();\n if (defines._areTexturesDirty) {\n this._eventInfo.hasRenderTargetTextures = false;\n this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);\n this._cacheHasRenderTargetTextures = this._eventInfo.hasRenderTargetTextures;\n if (scene.texturesEnabled) {\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\n if (!this._albedoTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\n if (!this._ambientTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\n if (!this._opacityTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n const reflectionTexture = this._getReflectionTexture();\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n if (!reflectionTexture.isReadyOrNotBlocking()) {\n return false;\n }\n if (reflectionTexture.irradianceTexture) {\n if (!reflectionTexture.irradianceTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n else {\n // Not ready until spherical are ready too.\n if (!reflectionTexture.sphericalPolynomial && ((_a = reflectionTexture.getInternalTexture()) === null || _a === void 0 ? void 0 : _a._sphericalPolynomialPromise)) {\n return false;\n }\n }\n }\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\n if (!this._lightmapTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\n if (!this._emissiveTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (MaterialFlags.SpecularTextureEnabled) {\n if (this._metallicTexture) {\n if (!this._metallicTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n else if (this._reflectivityTexture) {\n if (!this._reflectivityTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._metallicReflectanceTexture) {\n if (!this._metallicReflectanceTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._reflectanceTexture) {\n if (!this._reflectanceTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n if (this._microSurfaceTexture) {\n if (!this._microSurfaceTexture.isReadyOrNotBlocking()) {\n return false;\n }\n }\n }\n if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\n // Bump texture cannot be not blocking.\n if (!this._bumpTexture.isReady()) {\n return false;\n }\n }\n if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {\n // This is blocking.\n if (!this._environmentBRDFTexture.isReady()) {\n return false;\n }\n }\n }\n }\n this._eventInfo.isReadyForSubMesh = true;\n this._eventInfo.defines = defines;\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);\n if (!this._eventInfo.isReadyForSubMesh) {\n return false;\n }\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\n if (!this._imageProcessingConfiguration.isReady()) {\n return false;\n }\n }\n if (!engine.getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n mesh.createNormals(true);\n Logger.Warn(\"PBRMaterial: Normals have been created for the mesh: \" + mesh.name);\n }\n const previousEffect = subMesh.effect;\n const lightDisposed = defines._areLightsDisposed;\n let effect = this._prepareEffect(mesh, defines, this.onCompiled, this.onError, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);\n let forceWasNotReadyPreviously = false;\n if (effect) {\n if (this._onEffectCreatedObservable) {\n onCreatedEffectParameters$1.effect = effect;\n onCreatedEffectParameters$1.subMesh = subMesh;\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters$1);\n }\n // Use previous effect while new one is compiling\n if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {\n effect = previousEffect;\n defines.markAsUnprocessed();\n forceWasNotReadyPreviously = this.isFrozen;\n if (lightDisposed) {\n // re register in case it takes more than one frame.\n defines._areLightsDisposed = true;\n return false;\n }\n }\n else {\n scene.resetCachedMaterial();\n subMesh.setEffect(effect, defines, this._materialContext);\n }\n }\n if (!subMesh.effect || !subMesh.effect.isReady()) {\n return false;\n }\n defines._renderId = scene.getRenderId();\n subMesh.effect._wasPreviouslyReady = forceWasNotReadyPreviously ? false : true;\n subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;\n this._checkScenePerformancePriority();\n return true;\n }\n /**\n * Specifies if the material uses metallic roughness workflow.\n * @returns boolean specifying if the material uses metallic roughness workflow.\n */\n isMetallicWorkflow() {\n if (this._metallic != null || this._roughness != null || this._metallicTexture) {\n return true;\n }\n return false;\n }\n _prepareEffect(mesh, defines, onCompiled = null, onError = null, useInstances = null, useClipPlane = null, useThinInstances) {\n this._prepareDefines(mesh, defines, useInstances, useClipPlane, useThinInstances);\n if (!defines.isDirty) {\n return null;\n }\n defines.markAsProcessed();\n const scene = this.getScene();\n const engine = scene.getEngine();\n // Fallbacks\n const fallbacks = new EffectFallbacks();\n let fallbackRank = 0;\n if (defines.USESPHERICALINVERTEX) {\n fallbacks.addFallback(fallbackRank++, \"USESPHERICALINVERTEX\");\n }\n if (defines.FOG) {\n fallbacks.addFallback(fallbackRank, \"FOG\");\n }\n if (defines.SPECULARAA) {\n fallbacks.addFallback(fallbackRank, \"SPECULARAA\");\n }\n if (defines.POINTSIZE) {\n fallbacks.addFallback(fallbackRank, \"POINTSIZE\");\n }\n if (defines.LOGARITHMICDEPTH) {\n fallbacks.addFallback(fallbackRank, \"LOGARITHMICDEPTH\");\n }\n if (defines.PARALLAX) {\n fallbacks.addFallback(fallbackRank, \"PARALLAX\");\n }\n if (defines.PARALLAXOCCLUSION) {\n fallbacks.addFallback(fallbackRank++, \"PARALLAXOCCLUSION\");\n }\n if (defines.ENVIRONMENTBRDF) {\n fallbacks.addFallback(fallbackRank++, \"ENVIRONMENTBRDF\");\n }\n if (defines.TANGENT) {\n fallbacks.addFallback(fallbackRank++, \"TANGENT\");\n }\n if (defines.BUMP) {\n fallbacks.addFallback(fallbackRank++, \"BUMP\");\n }\n fallbackRank = MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights, fallbackRank++);\n if (defines.SPECULARTERM) {\n fallbacks.addFallback(fallbackRank++, \"SPECULARTERM\");\n }\n if (defines.USESPHERICALFROMREFLECTIONMAP) {\n fallbacks.addFallback(fallbackRank++, \"USESPHERICALFROMREFLECTIONMAP\");\n }\n if (defines.USEIRRADIANCEMAP) {\n fallbacks.addFallback(fallbackRank++, \"USEIRRADIANCEMAP\");\n }\n if (defines.LIGHTMAP) {\n fallbacks.addFallback(fallbackRank++, \"LIGHTMAP\");\n }\n if (defines.NORMAL) {\n fallbacks.addFallback(fallbackRank++, \"NORMAL\");\n }\n if (defines.AMBIENT) {\n fallbacks.addFallback(fallbackRank++, \"AMBIENT\");\n }\n if (defines.EMISSIVE) {\n fallbacks.addFallback(fallbackRank++, \"EMISSIVE\");\n }\n if (defines.VERTEXCOLOR) {\n fallbacks.addFallback(fallbackRank++, \"VERTEXCOLOR\");\n }\n if (defines.MORPHTARGETS) {\n fallbacks.addFallback(fallbackRank++, \"MORPHTARGETS\");\n }\n if (defines.MULTIVIEW) {\n fallbacks.addFallback(0, \"MULTIVIEW\");\n }\n //Attributes\n const attribs = [VertexBuffer.PositionKind];\n if (defines.NORMAL) {\n attribs.push(VertexBuffer.NormalKind);\n }\n if (defines.TANGENT) {\n attribs.push(VertexBuffer.TangentKind);\n }\n for (let i = 1; i <= 6; ++i) {\n if (defines[\"UV\" + i]) {\n attribs.push(`uv${i === 1 ? \"\" : i}`);\n }\n }\n if (defines.VERTEXCOLOR) {\n attribs.push(VertexBuffer.ColorKind);\n }\n if (defines.INSTANCESCOLOR) {\n attribs.push(VertexBuffer.ColorInstanceKind);\n }\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\n MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);\n MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\n let shaderName = \"pbr\";\n const uniforms = [\n \"world\",\n \"view\",\n \"viewProjection\",\n \"vEyePosition\",\n \"vLightsType\",\n \"vAmbientColor\",\n \"vAlbedoColor\",\n \"vReflectivityColor\",\n \"vMetallicReflectanceFactors\",\n \"vEmissiveColor\",\n \"visibility\",\n \"vReflectionColor\",\n \"vFogInfos\",\n \"vFogColor\",\n \"pointSize\",\n \"vAlbedoInfos\",\n \"vAmbientInfos\",\n \"vOpacityInfos\",\n \"vReflectionInfos\",\n \"vReflectionPosition\",\n \"vReflectionSize\",\n \"vEmissiveInfos\",\n \"vReflectivityInfos\",\n \"vReflectionFilteringInfo\",\n \"vMetallicReflectanceInfos\",\n \"vReflectanceInfos\",\n \"vMicroSurfaceSamplerInfos\",\n \"vBumpInfos\",\n \"vLightmapInfos\",\n \"mBones\",\n \"albedoMatrix\",\n \"ambientMatrix\",\n \"opacityMatrix\",\n \"reflectionMatrix\",\n \"emissiveMatrix\",\n \"reflectivityMatrix\",\n \"normalMatrix\",\n \"microSurfaceSamplerMatrix\",\n \"bumpMatrix\",\n \"lightmapMatrix\",\n \"metallicReflectanceMatrix\",\n \"reflectanceMatrix\",\n \"vLightingIntensity\",\n \"logarithmicDepthConstant\",\n \"vSphericalX\",\n \"vSphericalY\",\n \"vSphericalZ\",\n \"vSphericalXX_ZZ\",\n \"vSphericalYY_ZZ\",\n \"vSphericalZZ\",\n \"vSphericalXY\",\n \"vSphericalYZ\",\n \"vSphericalZX\",\n \"vSphericalL00\",\n \"vSphericalL1_1\",\n \"vSphericalL10\",\n \"vSphericalL11\",\n \"vSphericalL2_2\",\n \"vSphericalL2_1\",\n \"vSphericalL20\",\n \"vSphericalL21\",\n \"vSphericalL22\",\n \"vReflectionMicrosurfaceInfos\",\n \"vTangentSpaceParams\",\n \"boneTextureWidth\",\n \"vDebugMode\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n ];\n const samplers = [\n \"albedoSampler\",\n \"reflectivitySampler\",\n \"ambientSampler\",\n \"emissiveSampler\",\n \"bumpSampler\",\n \"lightmapSampler\",\n \"opacitySampler\",\n \"reflectionSampler\",\n \"reflectionSamplerLow\",\n \"reflectionSamplerHigh\",\n \"irradianceSampler\",\n \"microSurfaceSampler\",\n \"environmentBrdfSampler\",\n \"boneSampler\",\n \"metallicReflectanceSampler\",\n \"reflectanceSampler\",\n \"morphTargets\",\n \"oitDepthSampler\",\n \"oitFrontColorSampler\",\n ];\n const uniformBuffers = [\"Material\", \"Scene\", \"Mesh\"];\n const indexParameters = { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS };\n this._eventInfo.fallbacks = fallbacks;\n this._eventInfo.fallbackRank = fallbackRank;\n this._eventInfo.defines = defines;\n this._eventInfo.uniforms = uniforms;\n this._eventInfo.attributes = attribs;\n this._eventInfo.samplers = samplers;\n this._eventInfo.uniformBuffersNames = uniformBuffers;\n this._eventInfo.customCode = undefined;\n this._eventInfo.mesh = mesh;\n this._eventInfo.indexParameters = indexParameters;\n this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareEffect, this._eventInfo);\n PrePassConfiguration.AddUniforms(uniforms);\n PrePassConfiguration.AddSamplers(samplers);\n addClipPlaneUniforms(uniforms);\n if (ImageProcessingConfiguration) {\n ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);\n ImageProcessingConfiguration.PrepareSamplers(samplers, defines);\n }\n MaterialHelper.PrepareUniformsAndSamplersList({\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: defines,\n maxSimultaneousLights: this._maxSimultaneousLights,\n });\n const csnrOptions = {};\n if (this.customShaderNameResolve) {\n shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs, csnrOptions);\n }\n const join = defines.toString();\n const effect = engine.createEffect(shaderName, {\n attributes: attribs,\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: join,\n fallbacks: fallbacks,\n onCompiled: onCompiled,\n onError: onError,\n indexParameters,\n processFinalCode: csnrOptions.processFinalCode,\n processCodeAfterIncludes: this._eventInfo.customCode,\n multiTarget: defines.PREPASS,\n }, engine);\n this._eventInfo.customCode = undefined;\n return effect;\n }\n _prepareDefines(mesh, defines, useInstances = null, useClipPlane = null, useThinInstances = false) {\n var _a;\n const scene = this.getScene();\n const engine = scene.getEngine();\n // Lights\n MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);\n defines._needNormals = true;\n // Multiview\n MaterialHelper.PrepareDefinesForMultiview(scene, defines);\n // PrePass\n const oit = this.needAlphaBlendingForMesh(mesh) && this.getScene().useOrderIndependentTransparency;\n MaterialHelper.PrepareDefinesForPrePass(scene, defines, this.canRenderToMRT && !oit);\n // Order independant transparency\n MaterialHelper.PrepareDefinesForOIT(scene, defines, oit);\n // Textures\n defines.METALLICWORKFLOW = this.isMetallicWorkflow();\n if (defines._areTexturesDirty) {\n defines._needUVs = false;\n for (let i = 1; i <= 6; ++i) {\n defines[\"MAINUV\" + i] = false;\n }\n if (scene.texturesEnabled) {\n defines.ALBEDODIRECTUV = 0;\n defines.AMBIENTDIRECTUV = 0;\n defines.OPACITYDIRECTUV = 0;\n defines.EMISSIVEDIRECTUV = 0;\n defines.REFLECTIVITYDIRECTUV = 0;\n defines.MICROSURFACEMAPDIRECTUV = 0;\n defines.METALLIC_REFLECTANCEDIRECTUV = 0;\n defines.REFLECTANCEDIRECTUV = 0;\n defines.BUMPDIRECTUV = 0;\n defines.LIGHTMAPDIRECTUV = 0;\n if (engine.getCaps().textureLOD) {\n defines.LODBASEDMICROSFURACE = true;\n }\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._albedoTexture, defines, \"ALBEDO\");\n defines.GAMMAALBEDO = this._albedoTexture.gammaSpace;\n }\n else {\n defines.ALBEDO = false;\n }\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture, defines, \"AMBIENT\");\n defines.AMBIENTINGRAYSCALE = this._useAmbientInGrayScale;\n }\n else {\n defines.AMBIENT = false;\n }\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture, defines, \"OPACITY\");\n defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;\n }\n else {\n defines.OPACITY = false;\n }\n const reflectionTexture = this._getReflectionTexture();\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n defines.REFLECTION = true;\n defines.GAMMAREFLECTION = reflectionTexture.gammaSpace;\n defines.RGBDREFLECTION = reflectionTexture.isRGBD;\n defines.LODINREFLECTIONALPHA = reflectionTexture.lodLevelInAlpha;\n defines.LINEARSPECULARREFLECTION = reflectionTexture.linearSpecularLOD;\n if (this.realTimeFiltering && this.realTimeFilteringQuality > 0) {\n defines.NUM_SAMPLES = \"\" + this.realTimeFilteringQuality;\n if (engine._features.needTypeSuffixInShaderConstants) {\n defines.NUM_SAMPLES = defines.NUM_SAMPLES + \"u\";\n }\n defines.REALTIME_FILTERING = true;\n }\n else {\n defines.REALTIME_FILTERING = false;\n }\n defines.INVERTCUBICMAP = reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE;\n defines.REFLECTIONMAP_3D = reflectionTexture.isCube;\n defines.REFLECTIONMAP_OPPOSITEZ = defines.REFLECTIONMAP_3D && this.getScene().useRightHandedSystem ? !reflectionTexture.invertZ : reflectionTexture.invertZ;\n defines.REFLECTIONMAP_CUBIC = false;\n defines.REFLECTIONMAP_EXPLICIT = false;\n defines.REFLECTIONMAP_PLANAR = false;\n defines.REFLECTIONMAP_PROJECTION = false;\n defines.REFLECTIONMAP_SKYBOX = false;\n defines.REFLECTIONMAP_SPHERICAL = false;\n defines.REFLECTIONMAP_EQUIRECTANGULAR = false;\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\n switch (reflectionTexture.coordinatesMode) {\n case Texture.EXPLICIT_MODE:\n defines.REFLECTIONMAP_EXPLICIT = true;\n break;\n case Texture.PLANAR_MODE:\n defines.REFLECTIONMAP_PLANAR = true;\n break;\n case Texture.PROJECTION_MODE:\n defines.REFLECTIONMAP_PROJECTION = true;\n break;\n case Texture.SKYBOX_MODE:\n defines.REFLECTIONMAP_SKYBOX = true;\n break;\n case Texture.SPHERICAL_MODE:\n defines.REFLECTIONMAP_SPHERICAL = true;\n break;\n case Texture.EQUIRECTANGULAR_MODE:\n defines.REFLECTIONMAP_EQUIRECTANGULAR = true;\n break;\n case Texture.FIXED_EQUIRECTANGULAR_MODE:\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;\n break;\n case Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;\n break;\n case Texture.CUBIC_MODE:\n case Texture.INVCUBIC_MODE:\n default:\n defines.REFLECTIONMAP_CUBIC = true;\n defines.USE_LOCAL_REFLECTIONMAP_CUBIC = reflectionTexture.boundingBoxSize ? true : false;\n break;\n }\n if (reflectionTexture.coordinatesMode !== Texture.SKYBOX_MODE) {\n if (reflectionTexture.irradianceTexture) {\n defines.USEIRRADIANCEMAP = true;\n defines.USESPHERICALFROMREFLECTIONMAP = false;\n }\n // Assume using spherical polynomial if the reflection texture is a cube map\n else if (reflectionTexture.isCube) {\n defines.USESPHERICALFROMREFLECTIONMAP = true;\n defines.USEIRRADIANCEMAP = false;\n if (this._forceIrradianceInFragment || this.realTimeFiltering || engine.getCaps().maxVaryingVectors <= 8) {\n defines.USESPHERICALINVERTEX = false;\n }\n else {\n defines.USESPHERICALINVERTEX = true;\n }\n }\n }\n }\n else {\n defines.REFLECTION = false;\n defines.REFLECTIONMAP_3D = false;\n defines.REFLECTIONMAP_SPHERICAL = false;\n defines.REFLECTIONMAP_PLANAR = false;\n defines.REFLECTIONMAP_CUBIC = false;\n defines.USE_LOCAL_REFLECTIONMAP_CUBIC = false;\n defines.REFLECTIONMAP_PROJECTION = false;\n defines.REFLECTIONMAP_SKYBOX = false;\n defines.REFLECTIONMAP_EXPLICIT = false;\n defines.REFLECTIONMAP_EQUIRECTANGULAR = false;\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\n defines.INVERTCUBICMAP = false;\n defines.USESPHERICALFROMREFLECTIONMAP = false;\n defines.USEIRRADIANCEMAP = false;\n defines.USESPHERICALINVERTEX = false;\n defines.REFLECTIONMAP_OPPOSITEZ = false;\n defines.LODINREFLECTIONALPHA = false;\n defines.GAMMAREFLECTION = false;\n defines.RGBDREFLECTION = false;\n defines.LINEARSPECULARREFLECTION = false;\n }\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture, defines, \"LIGHTMAP\");\n defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;\n defines.GAMMALIGHTMAP = this._lightmapTexture.gammaSpace;\n defines.RGBDLIGHTMAP = this._lightmapTexture.isRGBD;\n }\n else {\n defines.LIGHTMAP = false;\n }\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\n MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture, defines, \"EMISSIVE\");\n defines.GAMMAEMISSIVE = this._emissiveTexture.gammaSpace;\n }\n else {\n defines.EMISSIVE = false;\n }\n if (MaterialFlags.SpecularTextureEnabled) {\n if (this._metallicTexture) {\n MaterialHelper.PrepareDefinesForMergedUV(this._metallicTexture, defines, \"REFLECTIVITY\");\n defines.ROUGHNESSSTOREINMETALMAPALPHA = this._useRoughnessFromMetallicTextureAlpha;\n defines.ROUGHNESSSTOREINMETALMAPGREEN = !this._useRoughnessFromMetallicTextureAlpha && this._useRoughnessFromMetallicTextureGreen;\n defines.METALLNESSSTOREINMETALMAPBLUE = this._useMetallnessFromMetallicTextureBlue;\n defines.AOSTOREINMETALMAPRED = this._useAmbientOcclusionFromMetallicTextureRed;\n defines.REFLECTIVITY_GAMMA = false;\n }\n else if (this._reflectivityTexture) {\n MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture, defines, \"REFLECTIVITY\");\n defines.MICROSURFACEFROMREFLECTIVITYMAP = this._useMicroSurfaceFromReflectivityMapAlpha;\n defines.MICROSURFACEAUTOMATIC = this._useAutoMicroSurfaceFromReflectivityMap;\n defines.REFLECTIVITY_GAMMA = this._reflectivityTexture.gammaSpace;\n }\n else {\n defines.REFLECTIVITY = false;\n }\n if (this._metallicReflectanceTexture || this._reflectanceTexture) {\n const identicalTextures = this._metallicReflectanceTexture !== null &&\n this._metallicReflectanceTexture._texture === ((_a = this._reflectanceTexture) === null || _a === void 0 ? void 0 : _a._texture) &&\n this._metallicReflectanceTexture.checkTransformsAreIdentical(this._reflectanceTexture);\n defines.METALLIC_REFLECTANCE_USE_ALPHA_ONLY = this._useOnlyMetallicFromMetallicReflectanceTexture && !identicalTextures;\n if (this._metallicReflectanceTexture) {\n MaterialHelper.PrepareDefinesForMergedUV(this._metallicReflectanceTexture, defines, \"METALLIC_REFLECTANCE\");\n defines.METALLIC_REFLECTANCE_GAMMA = this._metallicReflectanceTexture.gammaSpace;\n }\n else {\n defines.METALLIC_REFLECTANCE = false;\n }\n if (this._reflectanceTexture &&\n !identicalTextures &&\n (!this._metallicReflectanceTexture || (this._metallicReflectanceTexture && this._useOnlyMetallicFromMetallicReflectanceTexture))) {\n MaterialHelper.PrepareDefinesForMergedUV(this._reflectanceTexture, defines, \"REFLECTANCE\");\n defines.REFLECTANCE_GAMMA = this._reflectanceTexture.gammaSpace;\n }\n else {\n defines.REFLECTANCE = false;\n }\n }\n else {\n defines.METALLIC_REFLECTANCE = false;\n defines.REFLECTANCE = false;\n }\n if (this._microSurfaceTexture) {\n MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture, defines, \"MICROSURFACEMAP\");\n }\n else {\n defines.MICROSURFACEMAP = false;\n }\n }\n else {\n defines.REFLECTIVITY = false;\n defines.MICROSURFACEMAP = false;\n }\n if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\n MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, \"BUMP\");\n if (this._useParallax && this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\n defines.PARALLAX = true;\n defines.PARALLAXOCCLUSION = !!this._useParallaxOcclusion;\n }\n else {\n defines.PARALLAX = false;\n }\n defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;\n }\n else {\n defines.BUMP = false;\n defines.PARALLAX = false;\n defines.PARALLAXOCCLUSION = false;\n defines.OBJECTSPACE_NORMALMAP = false;\n }\n if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {\n defines.ENVIRONMENTBRDF = true;\n defines.ENVIRONMENTBRDF_RGBD = this._environmentBRDFTexture.isRGBD;\n }\n else {\n defines.ENVIRONMENTBRDF = false;\n defines.ENVIRONMENTBRDF_RGBD = false;\n }\n if (this._shouldUseAlphaFromAlbedoTexture()) {\n defines.ALPHAFROMALBEDO = true;\n }\n else {\n defines.ALPHAFROMALBEDO = false;\n }\n }\n defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;\n if (this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_STANDARD) {\n defines.USEPHYSICALLIGHTFALLOFF = false;\n defines.USEGLTFLIGHTFALLOFF = false;\n }\n else if (this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_GLTF) {\n defines.USEPHYSICALLIGHTFALLOFF = false;\n defines.USEGLTFLIGHTFALLOFF = true;\n }\n else {\n defines.USEPHYSICALLIGHTFALLOFF = true;\n defines.USEGLTFLIGHTFALLOFF = false;\n }\n defines.RADIANCEOVERALPHA = this._useRadianceOverAlpha;\n if (!this.backFaceCulling && this._twoSidedLighting) {\n defines.TWOSIDEDLIGHTING = true;\n }\n else {\n defines.TWOSIDEDLIGHTING = false;\n }\n defines.SPECULARAA = engine.getCaps().standardDerivatives && this._enableSpecularAntiAliasing;\n }\n if (defines._areTexturesDirty || defines._areMiscDirty) {\n defines.ALPHATESTVALUE = `${this._alphaCutOff}${this._alphaCutOff % 1 === 0 ? \".\" : \"\"}`;\n defines.PREMULTIPLYALPHA = this.alphaMode === 7 || this.alphaMode === 8;\n defines.ALPHABLEND = this.needAlphaBlendingForMesh(mesh);\n defines.ALPHAFRESNEL = this._useAlphaFresnel || this._useLinearAlphaFresnel;\n defines.LINEARALPHAFRESNEL = this._useLinearAlphaFresnel;\n }\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\n this._imageProcessingConfiguration.prepareDefines(defines);\n }\n defines.FORCENORMALFORWARD = this._forceNormalForward;\n defines.RADIANCEOCCLUSION = this._useRadianceOcclusion;\n defines.HORIZONOCCLUSION = this._useHorizonOcclusion;\n // Misc.\n if (defines._areMiscDirty) {\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, defines, this._applyDecalMapAfterDetailMap);\n defines.UNLIT = this._unlit || ((this.pointsCloud || this.wireframe) && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind));\n defines.DEBUGMODE = this._debugMode;\n }\n // Values that need to be evaluated on every frame\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false, useClipPlane, useThinInstances);\n // External config\n this._eventInfo.defines = defines;\n this._eventInfo.mesh = mesh;\n this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);\n // Attribs\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE);\n // External config\n this._callbackPluginEventPrepareDefines(this._eventInfo);\n }\n /**\n * Force shader compilation\n * @param mesh\n * @param onCompiled\n * @param options\n */\n forceCompilation(mesh, onCompiled, options) {\n const localOptions = Object.assign({ clipPlane: false, useInstances: false }, options);\n if (!this._uniformBufferLayoutBuilt) {\n this.buildUniformLayout();\n }\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetDefineNames, this._eventInfo);\n const defines = new PBRMaterialDefines(this._eventInfo.defineNames);\n const effect = this._prepareEffect(mesh, defines, undefined, undefined, localOptions.useInstances, localOptions.clipPlane, mesh.hasThinInstances);\n if (this._onEffectCreatedObservable) {\n onCreatedEffectParameters$1.effect = effect;\n onCreatedEffectParameters$1.subMesh = null;\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters$1);\n }\n if (effect.isReady()) {\n if (onCompiled) {\n onCompiled(this);\n }\n }\n else {\n effect.onCompileObservable.add(() => {\n if (onCompiled) {\n onCompiled(this);\n }\n });\n }\n }\n /**\n * Initializes the uniform buffer layout for the shader.\n */\n buildUniformLayout() {\n // Order is important !\n const ubo = this._uniformBuffer;\n ubo.addUniform(\"vAlbedoInfos\", 2);\n ubo.addUniform(\"vAmbientInfos\", 4);\n ubo.addUniform(\"vOpacityInfos\", 2);\n ubo.addUniform(\"vEmissiveInfos\", 2);\n ubo.addUniform(\"vLightmapInfos\", 2);\n ubo.addUniform(\"vReflectivityInfos\", 3);\n ubo.addUniform(\"vMicroSurfaceSamplerInfos\", 2);\n ubo.addUniform(\"vReflectionInfos\", 2);\n ubo.addUniform(\"vReflectionFilteringInfo\", 2);\n ubo.addUniform(\"vReflectionPosition\", 3);\n ubo.addUniform(\"vReflectionSize\", 3);\n ubo.addUniform(\"vBumpInfos\", 3);\n ubo.addUniform(\"albedoMatrix\", 16);\n ubo.addUniform(\"ambientMatrix\", 16);\n ubo.addUniform(\"opacityMatrix\", 16);\n ubo.addUniform(\"emissiveMatrix\", 16);\n ubo.addUniform(\"lightmapMatrix\", 16);\n ubo.addUniform(\"reflectivityMatrix\", 16);\n ubo.addUniform(\"microSurfaceSamplerMatrix\", 16);\n ubo.addUniform(\"bumpMatrix\", 16);\n ubo.addUniform(\"vTangentSpaceParams\", 2);\n ubo.addUniform(\"reflectionMatrix\", 16);\n ubo.addUniform(\"vReflectionColor\", 3);\n ubo.addUniform(\"vAlbedoColor\", 4);\n ubo.addUniform(\"vLightingIntensity\", 4);\n ubo.addUniform(\"vReflectionMicrosurfaceInfos\", 3);\n ubo.addUniform(\"pointSize\", 1);\n ubo.addUniform(\"vReflectivityColor\", 4);\n ubo.addUniform(\"vEmissiveColor\", 3);\n ubo.addUniform(\"vAmbientColor\", 3);\n ubo.addUniform(\"vDebugMode\", 2);\n ubo.addUniform(\"vMetallicReflectanceFactors\", 4);\n ubo.addUniform(\"vMetallicReflectanceInfos\", 2);\n ubo.addUniform(\"metallicReflectanceMatrix\", 16);\n ubo.addUniform(\"vReflectanceInfos\", 2);\n ubo.addUniform(\"reflectanceMatrix\", 16);\n ubo.addUniform(\"vSphericalL00\", 3);\n ubo.addUniform(\"vSphericalL1_1\", 3);\n ubo.addUniform(\"vSphericalL10\", 3);\n ubo.addUniform(\"vSphericalL11\", 3);\n ubo.addUniform(\"vSphericalL2_2\", 3);\n ubo.addUniform(\"vSphericalL2_1\", 3);\n ubo.addUniform(\"vSphericalL20\", 3);\n ubo.addUniform(\"vSphericalL21\", 3);\n ubo.addUniform(\"vSphericalL22\", 3);\n ubo.addUniform(\"vSphericalX\", 3);\n ubo.addUniform(\"vSphericalY\", 3);\n ubo.addUniform(\"vSphericalZ\", 3);\n ubo.addUniform(\"vSphericalXX_ZZ\", 3);\n ubo.addUniform(\"vSphericalYY_ZZ\", 3);\n ubo.addUniform(\"vSphericalZZ\", 3);\n ubo.addUniform(\"vSphericalXY\", 3);\n ubo.addUniform(\"vSphericalYZ\", 3);\n ubo.addUniform(\"vSphericalZX\", 3);\n super.buildUniformLayout();\n }\n /**\n * Binds the submesh data.\n * @param world - The world matrix.\n * @param mesh - The BJS mesh.\n * @param subMesh - A submesh of the BJS mesh.\n */\n bindForSubMesh(world, mesh, subMesh) {\n var _a, _b, _c, _d;\n const scene = this.getScene();\n const defines = subMesh.materialDefines;\n if (!defines) {\n return;\n }\n const effect = subMesh.effect;\n if (!effect) {\n return;\n }\n this._activeEffect = effect;\n // Matrices Mesh.\n mesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\n mesh.transferToEffect(world);\n const engine = scene.getEngine();\n // Binding unconditionally\n this._uniformBuffer.bindToEffect(effect, \"Material\");\n this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventHardBindForSubMesh(this._eventInfo);\n // Normal Matrix\n if (defines.OBJECTSPACE_NORMALMAP) {\n world.toNormalMatrix(this._normalMatrix);\n this.bindOnlyNormalMatrix(this._normalMatrix);\n }\n const mustRebind = effect._forceRebindOnNextCall || this._mustRebind(scene, effect, mesh.visibility);\n // Bones\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect, this.prePassConfiguration);\n let reflectionTexture = null;\n const ubo = this._uniformBuffer;\n if (mustRebind) {\n this.bindViewProjection(effect);\n reflectionTexture = this._getReflectionTexture();\n if (!ubo.useUbo || !this.isFrozen || !ubo.isSync || effect._forceRebindOnNextCall) {\n // Texture uniforms\n if (scene.texturesEnabled) {\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\n ubo.updateFloat2(\"vAlbedoInfos\", this._albedoTexture.coordinatesIndex, this._albedoTexture.level);\n MaterialHelper.BindTextureMatrix(this._albedoTexture, ubo, \"albedo\");\n }\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\n ubo.updateFloat4(\"vAmbientInfos\", this._ambientTexture.coordinatesIndex, this._ambientTexture.level, this._ambientTextureStrength, this._ambientTextureImpactOnAnalyticalLights);\n MaterialHelper.BindTextureMatrix(this._ambientTexture, ubo, \"ambient\");\n }\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\n ubo.updateFloat2(\"vOpacityInfos\", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);\n MaterialHelper.BindTextureMatrix(this._opacityTexture, ubo, \"opacity\");\n }\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n ubo.updateMatrix(\"reflectionMatrix\", reflectionTexture.getReflectionTextureMatrix());\n ubo.updateFloat2(\"vReflectionInfos\", reflectionTexture.level, 0);\n if (reflectionTexture.boundingBoxSize) {\n const cubeTexture = reflectionTexture;\n ubo.updateVector3(\"vReflectionPosition\", cubeTexture.boundingBoxPosition);\n ubo.updateVector3(\"vReflectionSize\", cubeTexture.boundingBoxSize);\n }\n if (this.realTimeFiltering) {\n const width = reflectionTexture.getSize().width;\n ubo.updateFloat2(\"vReflectionFilteringInfo\", width, Scalar.Log2(width));\n }\n if (!defines.USEIRRADIANCEMAP) {\n const polynomials = reflectionTexture.sphericalPolynomial;\n if (defines.USESPHERICALFROMREFLECTIONMAP && polynomials) {\n if (defines.SPHERICAL_HARMONICS) {\n const preScaledHarmonics = polynomials.preScaledHarmonics;\n ubo.updateVector3(\"vSphericalL00\", preScaledHarmonics.l00);\n ubo.updateVector3(\"vSphericalL1_1\", preScaledHarmonics.l1_1);\n ubo.updateVector3(\"vSphericalL10\", preScaledHarmonics.l10);\n ubo.updateVector3(\"vSphericalL11\", preScaledHarmonics.l11);\n ubo.updateVector3(\"vSphericalL2_2\", preScaledHarmonics.l2_2);\n ubo.updateVector3(\"vSphericalL2_1\", preScaledHarmonics.l2_1);\n ubo.updateVector3(\"vSphericalL20\", preScaledHarmonics.l20);\n ubo.updateVector3(\"vSphericalL21\", preScaledHarmonics.l21);\n ubo.updateVector3(\"vSphericalL22\", preScaledHarmonics.l22);\n }\n else {\n ubo.updateFloat3(\"vSphericalX\", polynomials.x.x, polynomials.x.y, polynomials.x.z);\n ubo.updateFloat3(\"vSphericalY\", polynomials.y.x, polynomials.y.y, polynomials.y.z);\n ubo.updateFloat3(\"vSphericalZ\", polynomials.z.x, polynomials.z.y, polynomials.z.z);\n ubo.updateFloat3(\"vSphericalXX_ZZ\", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);\n ubo.updateFloat3(\"vSphericalYY_ZZ\", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);\n ubo.updateFloat3(\"vSphericalZZ\", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);\n ubo.updateFloat3(\"vSphericalXY\", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);\n ubo.updateFloat3(\"vSphericalYZ\", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);\n ubo.updateFloat3(\"vSphericalZX\", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);\n }\n }\n }\n ubo.updateFloat3(\"vReflectionMicrosurfaceInfos\", reflectionTexture.getSize().width, reflectionTexture.lodGenerationScale, reflectionTexture.lodGenerationOffset);\n }\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\n ubo.updateFloat2(\"vEmissiveInfos\", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);\n MaterialHelper.BindTextureMatrix(this._emissiveTexture, ubo, \"emissive\");\n }\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\n ubo.updateFloat2(\"vLightmapInfos\", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);\n MaterialHelper.BindTextureMatrix(this._lightmapTexture, ubo, \"lightmap\");\n }\n if (MaterialFlags.SpecularTextureEnabled) {\n if (this._metallicTexture) {\n ubo.updateFloat3(\"vReflectivityInfos\", this._metallicTexture.coordinatesIndex, this._metallicTexture.level, this._ambientTextureStrength);\n MaterialHelper.BindTextureMatrix(this._metallicTexture, ubo, \"reflectivity\");\n }\n else if (this._reflectivityTexture) {\n ubo.updateFloat3(\"vReflectivityInfos\", this._reflectivityTexture.coordinatesIndex, this._reflectivityTexture.level, 1.0);\n MaterialHelper.BindTextureMatrix(this._reflectivityTexture, ubo, \"reflectivity\");\n }\n if (this._metallicReflectanceTexture) {\n ubo.updateFloat2(\"vMetallicReflectanceInfos\", this._metallicReflectanceTexture.coordinatesIndex, this._metallicReflectanceTexture.level);\n MaterialHelper.BindTextureMatrix(this._metallicReflectanceTexture, ubo, \"metallicReflectance\");\n }\n if (this._reflectanceTexture && defines.REFLECTANCE) {\n ubo.updateFloat2(\"vReflectanceInfos\", this._reflectanceTexture.coordinatesIndex, this._reflectanceTexture.level);\n MaterialHelper.BindTextureMatrix(this._reflectanceTexture, ubo, \"reflectance\");\n }\n if (this._microSurfaceTexture) {\n ubo.updateFloat2(\"vMicroSurfaceSamplerInfos\", this._microSurfaceTexture.coordinatesIndex, this._microSurfaceTexture.level);\n MaterialHelper.BindTextureMatrix(this._microSurfaceTexture, ubo, \"microSurfaceSampler\");\n }\n }\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\n ubo.updateFloat3(\"vBumpInfos\", this._bumpTexture.coordinatesIndex, this._bumpTexture.level, this._parallaxScaleBias);\n MaterialHelper.BindTextureMatrix(this._bumpTexture, ubo, \"bump\");\n if (scene._mirroredCameraPosition) {\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);\n }\n else {\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);\n }\n }\n }\n // Point size\n if (this.pointsCloud) {\n ubo.updateFloat(\"pointSize\", this.pointSize);\n }\n // Colors\n if (defines.METALLICWORKFLOW) {\n TmpColors.Color3[0].r = this._metallic === undefined || this._metallic === null ? 1 : this._metallic;\n TmpColors.Color3[0].g = this._roughness === undefined || this._roughness === null ? 1 : this._roughness;\n ubo.updateColor4(\"vReflectivityColor\", TmpColors.Color3[0], 1);\n const ior = (_b = (_a = this.subSurface) === null || _a === void 0 ? void 0 : _a._indexOfRefraction) !== null && _b !== void 0 ? _b : 1.5;\n const outsideIOR = 1; // consider air as clear coat and other layers would remap in the shader.\n // We are here deriving our default reflectance from a common value for none metallic surface.\n // Based of the schlick fresnel approximation model\n // for dielectrics.\n const f0 = Math.pow((ior - outsideIOR) / (ior + outsideIOR), 2);\n // Tweak the default F0 and F90 based on our given setup\n this._metallicReflectanceColor.scaleToRef(f0 * this._metallicF0Factor, TmpColors.Color3[0]);\n const metallicF90 = this._metallicF0Factor;\n ubo.updateColor4(\"vMetallicReflectanceFactors\", TmpColors.Color3[0], metallicF90);\n }\n else {\n ubo.updateColor4(\"vReflectivityColor\", this._reflectivityColor, this._microSurface);\n }\n ubo.updateColor3(\"vEmissiveColor\", MaterialFlags.EmissiveTextureEnabled ? this._emissiveColor : Color3.BlackReadOnly);\n ubo.updateColor3(\"vReflectionColor\", this._reflectionColor);\n if (!defines.SS_REFRACTION && ((_c = this.subSurface) === null || _c === void 0 ? void 0 : _c._linkRefractionWithTransparency)) {\n ubo.updateColor4(\"vAlbedoColor\", this._albedoColor, 1);\n }\n else {\n ubo.updateColor4(\"vAlbedoColor\", this._albedoColor, this.alpha);\n }\n // Misc\n this._lightingInfos.x = this._directIntensity;\n this._lightingInfos.y = this._emissiveIntensity;\n this._lightingInfos.z = this._environmentIntensity * scene.environmentIntensity;\n this._lightingInfos.w = this._specularIntensity;\n ubo.updateVector4(\"vLightingIntensity\", this._lightingInfos);\n // Colors\n scene.ambientColor.multiplyToRef(this._ambientColor, this._globalAmbientColor);\n ubo.updateColor3(\"vAmbientColor\", this._globalAmbientColor);\n ubo.updateFloat2(\"vDebugMode\", this.debugLimit, this.debugFactor);\n }\n // Textures\n if (scene.texturesEnabled) {\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\n ubo.setTexture(\"albedoSampler\", this._albedoTexture);\n }\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\n ubo.setTexture(\"ambientSampler\", this._ambientTexture);\n }\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\n ubo.setTexture(\"opacitySampler\", this._opacityTexture);\n }\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n if (defines.LODBASEDMICROSFURACE) {\n ubo.setTexture(\"reflectionSampler\", reflectionTexture);\n }\n else {\n ubo.setTexture(\"reflectionSampler\", reflectionTexture._lodTextureMid || reflectionTexture);\n ubo.setTexture(\"reflectionSamplerLow\", reflectionTexture._lodTextureLow || reflectionTexture);\n ubo.setTexture(\"reflectionSamplerHigh\", reflectionTexture._lodTextureHigh || reflectionTexture);\n }\n if (defines.USEIRRADIANCEMAP) {\n ubo.setTexture(\"irradianceSampler\", reflectionTexture.irradianceTexture);\n }\n }\n if (defines.ENVIRONMENTBRDF) {\n ubo.setTexture(\"environmentBrdfSampler\", this._environmentBRDFTexture);\n }\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\n ubo.setTexture(\"emissiveSampler\", this._emissiveTexture);\n }\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\n ubo.setTexture(\"lightmapSampler\", this._lightmapTexture);\n }\n if (MaterialFlags.SpecularTextureEnabled) {\n if (this._metallicTexture) {\n ubo.setTexture(\"reflectivitySampler\", this._metallicTexture);\n }\n else if (this._reflectivityTexture) {\n ubo.setTexture(\"reflectivitySampler\", this._reflectivityTexture);\n }\n if (this._metallicReflectanceTexture) {\n ubo.setTexture(\"metallicReflectanceSampler\", this._metallicReflectanceTexture);\n }\n if (this._reflectanceTexture && defines.REFLECTANCE) {\n ubo.setTexture(\"reflectanceSampler\", this._reflectanceTexture);\n }\n if (this._microSurfaceTexture) {\n ubo.setTexture(\"microSurfaceSampler\", this._microSurfaceTexture);\n }\n }\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\n ubo.setTexture(\"bumpSampler\", this._bumpTexture);\n }\n }\n // OIT with depth peeling\n if (this.getScene().useOrderIndependentTransparency && this.needAlphaBlendingForMesh(mesh)) {\n this.getScene().depthPeelingRenderer.bind(effect);\n }\n this._eventInfo.subMesh = subMesh;\n this._callbackPluginEventBindForSubMesh(this._eventInfo);\n // Clip plane\n bindClipPlane(this._activeEffect, this, scene);\n this.bindEyePosition(effect);\n }\n else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {\n this._needToBindSceneUbo = true;\n }\n if (mustRebind || !this.isFrozen) {\n // Lights\n if (scene.lightsEnabled && !this._disableLighting) {\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);\n }\n // View\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || reflectionTexture || mesh.receiveShadows || defines.PREPASS) {\n this.bindView(effect);\n }\n // Fog\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect, true);\n // Morph targets\n if (defines.NUM_MORPH_INFLUENCERS) {\n MaterialHelper.BindMorphTargetParameters(mesh, this._activeEffect);\n }\n if (defines.BAKED_VERTEX_ANIMATION_TEXTURE) {\n (_d = mesh.bakedVertexAnimationManager) === null || _d === void 0 ? void 0 : _d.bind(effect, defines.INSTANCES);\n }\n // image processing\n this._imageProcessingConfiguration.bind(this._activeEffect);\n // Log. depth\n MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);\n }\n this._afterBind(mesh, this._activeEffect);\n ubo.update();\n }\n /**\n * Returns the animatable textures.\n * If material have animatable metallic texture, then reflectivity texture will not be returned, even if it has animations.\n * @returns - Array of animatable textures.\n */\n getAnimatables() {\n const results = super.getAnimatables();\n if (this._albedoTexture && this._albedoTexture.animations && this._albedoTexture.animations.length > 0) {\n results.push(this._albedoTexture);\n }\n if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {\n results.push(this._ambientTexture);\n }\n if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {\n results.push(this._opacityTexture);\n }\n if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {\n results.push(this._reflectionTexture);\n }\n if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {\n results.push(this._emissiveTexture);\n }\n if (this._metallicTexture && this._metallicTexture.animations && this._metallicTexture.animations.length > 0) {\n results.push(this._metallicTexture);\n }\n else if (this._reflectivityTexture && this._reflectivityTexture.animations && this._reflectivityTexture.animations.length > 0) {\n results.push(this._reflectivityTexture);\n }\n if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {\n results.push(this._bumpTexture);\n }\n if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {\n results.push(this._lightmapTexture);\n }\n if (this._metallicReflectanceTexture && this._metallicReflectanceTexture.animations && this._metallicReflectanceTexture.animations.length > 0) {\n results.push(this._metallicReflectanceTexture);\n }\n if (this._reflectanceTexture && this._reflectanceTexture.animations && this._reflectanceTexture.animations.length > 0) {\n results.push(this._reflectanceTexture);\n }\n if (this._microSurfaceTexture && this._microSurfaceTexture.animations && this._microSurfaceTexture.animations.length > 0) {\n results.push(this._microSurfaceTexture);\n }\n return results;\n }\n /**\n * Returns the texture used for reflections.\n * @returns - Reflection texture if present. Otherwise, returns the environment texture.\n */\n _getReflectionTexture() {\n if (this._reflectionTexture) {\n return this._reflectionTexture;\n }\n return this.getScene().environmentTexture;\n }\n /**\n * Returns an array of the actively used textures.\n * @returns - Array of BaseTextures\n */\n getActiveTextures() {\n const activeTextures = super.getActiveTextures();\n if (this._albedoTexture) {\n activeTextures.push(this._albedoTexture);\n }\n if (this._ambientTexture) {\n activeTextures.push(this._ambientTexture);\n }\n if (this._opacityTexture) {\n activeTextures.push(this._opacityTexture);\n }\n if (this._reflectionTexture) {\n activeTextures.push(this._reflectionTexture);\n }\n if (this._emissiveTexture) {\n activeTextures.push(this._emissiveTexture);\n }\n if (this._reflectivityTexture) {\n activeTextures.push(this._reflectivityTexture);\n }\n if (this._metallicTexture) {\n activeTextures.push(this._metallicTexture);\n }\n if (this._metallicReflectanceTexture) {\n activeTextures.push(this._metallicReflectanceTexture);\n }\n if (this._reflectanceTexture) {\n activeTextures.push(this._reflectanceTexture);\n }\n if (this._microSurfaceTexture) {\n activeTextures.push(this._microSurfaceTexture);\n }\n if (this._bumpTexture) {\n activeTextures.push(this._bumpTexture);\n }\n if (this._lightmapTexture) {\n activeTextures.push(this._lightmapTexture);\n }\n return activeTextures;\n }\n /**\n * Checks to see if a texture is used in the material.\n * @param texture - Base texture to use.\n * @returns - Boolean specifying if a texture is used in the material.\n */\n hasTexture(texture) {\n if (super.hasTexture(texture)) {\n return true;\n }\n if (this._albedoTexture === texture) {\n return true;\n }\n if (this._ambientTexture === texture) {\n return true;\n }\n if (this._opacityTexture === texture) {\n return true;\n }\n if (this._reflectionTexture === texture) {\n return true;\n }\n if (this._emissiveTexture === texture) {\n return true;\n }\n if (this._reflectivityTexture === texture) {\n return true;\n }\n if (this._metallicTexture === texture) {\n return true;\n }\n if (this._metallicReflectanceTexture === texture) {\n return true;\n }\n if (this._reflectanceTexture === texture) {\n return true;\n }\n if (this._microSurfaceTexture === texture) {\n return true;\n }\n if (this._bumpTexture === texture) {\n return true;\n }\n if (this._lightmapTexture === texture) {\n return true;\n }\n return false;\n }\n /**\n * Sets the required values to the prepass renderer.\n * It can't be sets when subsurface scattering of this material is disabled.\n * When scene have ability to enable subsurface prepass effect, it will enable.\n */\n setPrePassRenderer() {\n var _a;\n if (!((_a = this.subSurface) === null || _a === void 0 ? void 0 : _a.isScatteringEnabled)) {\n return false;\n }\n const subSurfaceConfiguration = this.getScene().enableSubSurfaceForPrePass();\n if (subSurfaceConfiguration) {\n subSurfaceConfiguration.enabled = true;\n }\n return true;\n }\n /**\n * Disposes the resources of the material.\n * @param forceDisposeEffect - Forces the disposal of effects.\n * @param forceDisposeTextures - Forces the disposal of all textures.\n */\n dispose(forceDisposeEffect, forceDisposeTextures) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;\n if (forceDisposeTextures) {\n if (this._environmentBRDFTexture && this.getScene().environmentBRDFTexture !== this._environmentBRDFTexture) {\n this._environmentBRDFTexture.dispose();\n }\n (_a = this._albedoTexture) === null || _a === void 0 ? void 0 : _a.dispose();\n (_b = this._ambientTexture) === null || _b === void 0 ? void 0 : _b.dispose();\n (_c = this._opacityTexture) === null || _c === void 0 ? void 0 : _c.dispose();\n (_d = this._reflectionTexture) === null || _d === void 0 ? void 0 : _d.dispose();\n (_e = this._emissiveTexture) === null || _e === void 0 ? void 0 : _e.dispose();\n (_f = this._metallicTexture) === null || _f === void 0 ? void 0 : _f.dispose();\n (_g = this._reflectivityTexture) === null || _g === void 0 ? void 0 : _g.dispose();\n (_h = this._bumpTexture) === null || _h === void 0 ? void 0 : _h.dispose();\n (_j = this._lightmapTexture) === null || _j === void 0 ? void 0 : _j.dispose();\n (_k = this._metallicReflectanceTexture) === null || _k === void 0 ? void 0 : _k.dispose();\n (_l = this._reflectanceTexture) === null || _l === void 0 ? void 0 : _l.dispose();\n (_m = this._microSurfaceTexture) === null || _m === void 0 ? void 0 : _m.dispose();\n }\n this._renderTargets.dispose();\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n super.dispose(forceDisposeEffect, forceDisposeTextures);\n }\n }\n /**\n * PBRMaterialTransparencyMode: No transparency mode, Alpha channel is not use.\n */\n PBRBaseMaterial.PBRMATERIAL_OPAQUE = Material.MATERIAL_OPAQUE;\n /**\n * PBRMaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.\n */\n PBRBaseMaterial.PBRMATERIAL_ALPHATEST = Material.MATERIAL_ALPHATEST;\n /**\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\n */\n PBRBaseMaterial.PBRMATERIAL_ALPHABLEND = Material.MATERIAL_ALPHABLEND;\n /**\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\n * They are also discarded below the alpha cutoff threshold to improve performances.\n */\n PBRBaseMaterial.PBRMATERIAL_ALPHATESTANDBLEND = Material.MATERIAL_ALPHATESTANDBLEND;\n /**\n * Defines the default value of how much AO map is occluding the analytical lights\n * (point spot...).\n */\n PBRBaseMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS = 0;\n /**\n * PBRMaterialLightFalloff Physical: light is falling off following the inverse squared distance law.\n */\n PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL = 0;\n /**\n * PBRMaterialLightFalloff gltf: light is falling off as described in the gltf moving to PBR document\n * to enhance interoperability with other engines.\n */\n PBRBaseMaterial.LIGHTFALLOFF_GLTF = 1;\n /**\n * PBRMaterialLightFalloff Standard: light is falling off like in the standard material\n * to enhance interoperability with other materials.\n */\n PBRBaseMaterial.LIGHTFALLOFF_STANDARD = 2;\n __decorate$1([\n serializeAsImageProcessingConfiguration()\n ], PBRBaseMaterial.prototype, \"_imageProcessingConfiguration\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRBaseMaterial.prototype, \"debugMode\", void 0);\n __decorate$1([\n serialize()\n ], PBRBaseMaterial.prototype, \"useLogarithmicDepth\", null);\n\n /**\n * The Physically based material of BJS.\n *\n * This offers the main features of a standard PBR material.\n * For more information, please refer to the documentation :\n * https://doc.babylonjs.com/features/featuresDeepDive/materials/using/introToPBR\n */\n class PBRMaterial extends PBRBaseMaterial {\n /**\n * Stores the refracted light information in a texture.\n */\n get refractionTexture() {\n return this.subSurface.refractionTexture;\n }\n set refractionTexture(value) {\n this.subSurface.refractionTexture = value;\n if (value) {\n this.subSurface.isRefractionEnabled = true;\n }\n else if (!this.subSurface.linkRefractionWithTransparency) {\n this.subSurface.isRefractionEnabled = false;\n }\n }\n /**\n * Index of refraction of the material base layer.\n * https://en.wikipedia.org/wiki/List_of_refractive_indices\n *\n * This does not only impact refraction but also the Base F0 of Dielectric Materials.\n *\n * From dielectric fresnel rules: F0 = square((iorT - iorI) / (iorT + iorI))\n */\n get indexOfRefraction() {\n return this.subSurface.indexOfRefraction;\n }\n set indexOfRefraction(value) {\n this.subSurface.indexOfRefraction = value;\n }\n /**\n * Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.\n */\n get invertRefractionY() {\n return this.subSurface.invertRefractionY;\n }\n set invertRefractionY(value) {\n this.subSurface.invertRefractionY = value;\n }\n /**\n * This parameters will make the material used its opacity to control how much it is refracting against not.\n * Materials half opaque for instance using refraction could benefit from this control.\n */\n get linkRefractionWithTransparency() {\n return this.subSurface.linkRefractionWithTransparency;\n }\n set linkRefractionWithTransparency(value) {\n this.subSurface.linkRefractionWithTransparency = value;\n if (value) {\n this.subSurface.isRefractionEnabled = true;\n }\n }\n /**\n * BJS is using an hardcoded light falloff based on a manually sets up range.\n * In PBR, one way to represents the falloff is to use the inverse squared root algorithm.\n * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.\n */\n get usePhysicalLightFalloff() {\n return this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL;\n }\n /**\n * BJS is using an hardcoded light falloff based on a manually sets up range.\n * In PBR, one way to represents the falloff is to use the inverse squared root algorithm.\n * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.\n */\n set usePhysicalLightFalloff(value) {\n if (value !== this.usePhysicalLightFalloff) {\n // Ensure the effect will be rebuilt.\n this._markAllSubMeshesAsTexturesDirty();\n if (value) {\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL;\n }\n else {\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_STANDARD;\n }\n }\n }\n /**\n * In order to support the falloff compatibility with gltf, a special mode has been added\n * to reproduce the gltf light falloff.\n */\n get useGLTFLightFalloff() {\n return this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_GLTF;\n }\n /**\n * In order to support the falloff compatibility with gltf, a special mode has been added\n * to reproduce the gltf light falloff.\n */\n set useGLTFLightFalloff(value) {\n if (value !== this.useGLTFLightFalloff) {\n // Ensure the effect will be rebuilt.\n this._markAllSubMeshesAsTexturesDirty();\n if (value) {\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_GLTF;\n }\n else {\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_STANDARD;\n }\n }\n }\n /**\n * Gets the image processing configuration used either in this material.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Sets the Default image processing configuration used either in the this material.\n *\n * If sets to null, the scene one is in use.\n */\n set imageProcessingConfiguration(value) {\n this._attachImageProcessingConfiguration(value);\n // Ensure the effect will be rebuilt.\n this._markAllSubMeshesAsTexturesDirty();\n }\n /**\n * Gets whether the color curves effect is enabled.\n */\n get cameraColorCurvesEnabled() {\n return this.imageProcessingConfiguration.colorCurvesEnabled;\n }\n /**\n * Sets whether the color curves effect is enabled.\n */\n set cameraColorCurvesEnabled(value) {\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n get cameraColorGradingEnabled() {\n return this.imageProcessingConfiguration.colorGradingEnabled;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n set cameraColorGradingEnabled(value) {\n this.imageProcessingConfiguration.colorGradingEnabled = value;\n }\n /**\n * Gets whether tonemapping is enabled or not.\n */\n get cameraToneMappingEnabled() {\n return this._imageProcessingConfiguration.toneMappingEnabled;\n }\n /**\n * Sets whether tonemapping is enabled or not\n */\n set cameraToneMappingEnabled(value) {\n this._imageProcessingConfiguration.toneMappingEnabled = value;\n }\n /**\n * The camera exposure used on this material.\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\n * This corresponds to a photographic exposure.\n */\n get cameraExposure() {\n return this._imageProcessingConfiguration.exposure;\n }\n /**\n * The camera exposure used on this material.\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\n * This corresponds to a photographic exposure.\n */\n set cameraExposure(value) {\n this._imageProcessingConfiguration.exposure = value;\n }\n /**\n * Gets The camera contrast used on this material.\n */\n get cameraContrast() {\n return this._imageProcessingConfiguration.contrast;\n }\n /**\n * Sets The camera contrast used on this material.\n */\n set cameraContrast(value) {\n this._imageProcessingConfiguration.contrast = value;\n }\n /**\n * Gets the Color Grading 2D Lookup Texture.\n */\n get cameraColorGradingTexture() {\n return this._imageProcessingConfiguration.colorGradingTexture;\n }\n /**\n * Sets the Color Grading 2D Lookup Texture.\n */\n set cameraColorGradingTexture(value) {\n this._imageProcessingConfiguration.colorGradingTexture = value;\n }\n /**\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n get cameraColorCurves() {\n return this._imageProcessingConfiguration.colorCurves;\n }\n /**\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n set cameraColorCurves(value) {\n this._imageProcessingConfiguration.colorCurves = value;\n }\n /**\n * Instantiates a new PBRMaterial instance.\n *\n * @param name The material name\n * @param scene The scene the material will be use in.\n */\n constructor(name, scene) {\n super(name, scene);\n /**\n * Intensity of the direct lights e.g. the four lights available in your scene.\n * This impacts both the direct diffuse and specular highlights.\n */\n this.directIntensity = 1.0;\n /**\n * Intensity of the emissive part of the material.\n * This helps controlling the emissive effect without modifying the emissive color.\n */\n this.emissiveIntensity = 1.0;\n /**\n * Intensity of the environment e.g. how much the environment will light the object\n * either through harmonics for rough material or through the reflection for shiny ones.\n */\n this.environmentIntensity = 1.0;\n /**\n * This is a special control allowing the reduction of the specular highlights coming from the\n * four lights of the scene. Those highlights may not be needed in full environment lighting.\n */\n this.specularIntensity = 1.0;\n /**\n * Debug Control allowing disabling the bump map on this material.\n */\n this.disableBumpMap = false;\n /**\n * AKA Occlusion Texture Intensity in other nomenclature.\n */\n this.ambientTextureStrength = 1.0;\n /**\n * Defines how much the AO map is occluding the analytical lights (point spot...).\n * 1 means it completely occludes it\n * 0 mean it has no impact\n */\n this.ambientTextureImpactOnAnalyticalLights = PBRMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;\n /**\n * In metallic workflow, specifies an F0 factor to help configuring the material F0.\n * By default the indexOfrefraction is used to compute F0;\n *\n * This is used as a factor against the default reflectance at normal incidence to tweak it.\n *\n * F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor;\n * F90 = metallicReflectanceColor;\n */\n this.metallicF0Factor = 1;\n /**\n * In metallic workflow, specifies an F0 color.\n * By default the F90 is always 1;\n *\n * Please note that this factor is also used as a factor against the default reflectance at normal incidence.\n *\n * F0 = defaultF0_from_IOR * metallicF0Factor * metallicReflectanceColor\n * F90 = metallicF0Factor;\n */\n this.metallicReflectanceColor = Color3.White();\n /**\n * Specifies that only the A channel from metallicReflectanceTexture should be used.\n * If false, both RGB and A channels will be used\n */\n this.useOnlyMetallicFromMetallicReflectanceTexture = false;\n /**\n * The color of a material in ambient lighting.\n */\n this.ambientColor = new Color3(0, 0, 0);\n /**\n * AKA Diffuse Color in other nomenclature.\n */\n this.albedoColor = new Color3(1, 1, 1);\n /**\n * AKA Specular Color in other nomenclature.\n */\n this.reflectivityColor = new Color3(1, 1, 1);\n /**\n * The color reflected from the material.\n */\n this.reflectionColor = new Color3(1.0, 1.0, 1.0);\n /**\n * The color emitted from the material.\n */\n this.emissiveColor = new Color3(0, 0, 0);\n /**\n * AKA Glossiness in other nomenclature.\n */\n this.microSurface = 1.0;\n /**\n * If true, the light map contains occlusion information instead of lighting info.\n */\n this.useLightmapAsShadowmap = false;\n /**\n * Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.\n */\n this.useAlphaFromAlbedoTexture = false;\n /**\n * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.\n */\n this.forceAlphaTest = false;\n /**\n * Defines the alpha limits in alpha test mode.\n */\n this.alphaCutOff = 0.4;\n /**\n * Specifies that the material will keep the specular highlights over a transparent surface (only the most luminous ones).\n * A car glass is a good example of that. When sun reflects on it you can not see what is behind.\n */\n this.useSpecularOverAlpha = true;\n /**\n * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.\n */\n this.useMicroSurfaceFromReflectivityMapAlpha = false;\n /**\n * Specifies if the metallic texture contains the roughness information in its alpha channel.\n */\n this.useRoughnessFromMetallicTextureAlpha = true;\n /**\n * Specifies if the metallic texture contains the roughness information in its green channel.\n */\n this.useRoughnessFromMetallicTextureGreen = false;\n /**\n * Specifies if the metallic texture contains the metallness information in its blue channel.\n */\n this.useMetallnessFromMetallicTextureBlue = false;\n /**\n * Specifies if the metallic texture contains the ambient occlusion information in its red channel.\n */\n this.useAmbientOcclusionFromMetallicTextureRed = false;\n /**\n * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.\n */\n this.useAmbientInGrayScale = false;\n /**\n * In case the reflectivity map does not contain the microsurface information in its alpha channel,\n * The material will try to infer what glossiness each pixel should be.\n */\n this.useAutoMicroSurfaceFromReflectivityMap = false;\n /**\n * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most luminous ones).\n * A car glass is a good example of that. When the street lights reflects on it you can not see what is behind.\n */\n this.useRadianceOverAlpha = true;\n /**\n * Allows using an object space normal map (instead of tangent space).\n */\n this.useObjectSpaceNormalMap = false;\n /**\n * Allows using the bump map in parallax mode.\n */\n this.useParallax = false;\n /**\n * Allows using the bump map in parallax occlusion mode.\n */\n this.useParallaxOcclusion = false;\n /**\n * Controls the scale bias of the parallax mode.\n */\n this.parallaxScaleBias = 0.05;\n /**\n * If sets to true, disables all the lights affecting the material.\n */\n this.disableLighting = false;\n /**\n * Force the shader to compute irradiance in the fragment shader in order to take bump in account.\n */\n this.forceIrradianceInFragment = false;\n /**\n * Number of Simultaneous lights allowed on the material.\n */\n this.maxSimultaneousLights = 4;\n /**\n * If sets to true, x component of normal map value will invert (x = 1.0 - x).\n */\n this.invertNormalMapX = false;\n /**\n * If sets to true, y component of normal map value will invert (y = 1.0 - y).\n */\n this.invertNormalMapY = false;\n /**\n * If sets to true and backfaceCulling is false, normals will be flipped on the backside.\n */\n this.twoSidedLighting = false;\n /**\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\n * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)\n */\n this.useAlphaFresnel = false;\n /**\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\n * And/Or occlude the blended part. (alpha stays linear to compute the fresnel)\n */\n this.useLinearAlphaFresnel = false;\n /**\n * Let user defines the brdf lookup texture used for IBL.\n * A default 8bit version is embedded but you could point at :\n * * Default texture: https://assets.babylonjs.com/environments/correlatedMSBRDF_RGBD.png\n * * Default 16bit pixel depth texture: https://assets.babylonjs.com/environments/correlatedMSBRDF.dds\n * * LEGACY Default None correlated https://assets.babylonjs.com/environments/uncorrelatedBRDF_RGBD.png\n * * LEGACY Default None correlated 16bit pixel depth https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds\n */\n this.environmentBRDFTexture = null;\n /**\n * Force normal to face away from face.\n */\n this.forceNormalForward = false;\n /**\n * Enables specular anti aliasing in the PBR shader.\n * It will both interacts on the Geometry for analytical and IBL lighting.\n * It also prefilter the roughness map based on the bump values.\n */\n this.enableSpecularAntiAliasing = false;\n /**\n * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal\n * makes the reflect vector face the model (under horizon).\n */\n this.useHorizonOcclusion = true;\n /**\n * This parameters will enable/disable radiance occlusion by preventing the radiance to lit\n * too much the area relying on ambient texture to define their ambient occlusion.\n */\n this.useRadianceOcclusion = true;\n /**\n * If set to true, no lighting calculations will be applied.\n */\n this.unlit = false;\n /**\n * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)\n */\n this.applyDecalMapAfterDetailMap = false;\n this._environmentBRDFTexture = GetEnvironmentBRDFTexture(this.getScene());\n }\n /**\n * Returns the name of this material class.\n */\n getClassName() {\n return \"PBRMaterial\";\n }\n /**\n * Makes a duplicate of the current material.\n * @param name - name to use for the new material.\n * @param cloneTexturesOnlyOnce - if a texture is used in more than one channel (e.g diffuse and opacity), only clone it once and reuse it on the other channels. Default false.\n * @param rootUrl defines the root URL to use to load textures\n */\n clone(name, cloneTexturesOnlyOnce = true, rootUrl = \"\") {\n const clone = SerializationHelper.Clone(() => new PBRMaterial(name, this.getScene()), this, { cloneTexturesOnlyOnce });\n clone.id = name;\n clone.name = name;\n this.stencil.copyTo(clone.stencil);\n this._clonePlugins(clone, rootUrl);\n return clone;\n }\n /**\n * Serializes this PBR Material.\n * @returns - An object with the serialized material.\n */\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.customType = \"BABYLON.PBRMaterial\";\n return serializationObject;\n }\n // Statics\n /**\n * Parses a PBR Material from a serialized object.\n * @param source - Serialized object.\n * @param scene - BJS scene instance.\n * @param rootUrl - url for the scene object\n * @returns - PBRMaterial\n */\n static Parse(source, scene, rootUrl) {\n const material = SerializationHelper.Parse(() => new PBRMaterial(source.name, scene), source, scene, rootUrl);\n if (source.stencil) {\n material.stencil.parse(source.stencil, scene, rootUrl);\n }\n Material._parsePlugins(source, material, scene, rootUrl);\n // The code block below ensures backward compatibility with serialized materials before plugins are automatically serialized.\n if (source.clearCoat) {\n material.clearCoat.parse(source.clearCoat, scene, rootUrl);\n }\n if (source.anisotropy) {\n material.anisotropy.parse(source.anisotropy, scene, rootUrl);\n }\n if (source.brdf) {\n material.brdf.parse(source.brdf, scene, rootUrl);\n }\n if (source.sheen) {\n material.sheen.parse(source.sheen, scene, rootUrl);\n }\n if (source.subSurface) {\n material.subSurface.parse(source.subSurface, scene, rootUrl);\n }\n if (source.iridescence) {\n material.iridescence.parse(source.iridescence, scene, rootUrl);\n }\n return material;\n }\n }\n /**\n * PBRMaterialTransparencyMode: No transparency mode, Alpha channel is not use.\n */\n PBRMaterial.PBRMATERIAL_OPAQUE = PBRBaseMaterial.PBRMATERIAL_OPAQUE;\n /**\n * PBRMaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.\n */\n PBRMaterial.PBRMATERIAL_ALPHATEST = PBRBaseMaterial.PBRMATERIAL_ALPHATEST;\n /**\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\n */\n PBRMaterial.PBRMATERIAL_ALPHABLEND = PBRBaseMaterial.PBRMATERIAL_ALPHABLEND;\n /**\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\n * They are also discarded below the alpha cutoff threshold to improve performances.\n */\n PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND = PBRBaseMaterial.PBRMATERIAL_ALPHATESTANDBLEND;\n /**\n * Defines the default value of how much AO map is occluding the analytical lights\n * (point spot...).\n */\n PBRMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS = PBRBaseMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"directIntensity\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"emissiveIntensity\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"environmentIntensity\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"specularIntensity\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"disableBumpMap\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"albedoTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"ambientTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"ambientTextureStrength\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"ambientTextureImpactOnAnalyticalLights\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], PBRMaterial.prototype, \"opacityTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"reflectionTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"emissiveTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"reflectivityTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"metallicTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"metallic\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"roughness\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"metallicF0Factor\", void 0);\n __decorate$1([\n serializeAsColor3(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"metallicReflectanceColor\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useOnlyMetallicFromMetallicReflectanceTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"metallicReflectanceTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"reflectanceTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"microSurfaceTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"bumpTexture\", void 0);\n __decorate$1([\n serializeAsTexture(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\", null)\n ], PBRMaterial.prototype, \"lightmapTexture\", void 0);\n __decorate$1([\n serializeAsColor3(\"ambient\"),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"ambientColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"albedo\"),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"albedoColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"reflectivity\"),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"reflectivityColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"reflection\"),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"reflectionColor\", void 0);\n __decorate$1([\n serializeAsColor3(\"emissive\"),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"emissiveColor\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"microSurface\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useLightmapAsShadowmap\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], PBRMaterial.prototype, \"useAlphaFromAlbedoTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], PBRMaterial.prototype, \"forceAlphaTest\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\n ], PBRMaterial.prototype, \"alphaCutOff\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useSpecularOverAlpha\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useMicroSurfaceFromReflectivityMapAlpha\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useRoughnessFromMetallicTextureAlpha\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useRoughnessFromMetallicTextureGreen\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useMetallnessFromMetallicTextureBlue\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useAmbientOcclusionFromMetallicTextureRed\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useAmbientInGrayScale\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useAutoMicroSurfaceFromReflectivityMap\", void 0);\n __decorate$1([\n serialize()\n ], PBRMaterial.prototype, \"usePhysicalLightFalloff\", null);\n __decorate$1([\n serialize()\n ], PBRMaterial.prototype, \"useGLTFLightFalloff\", null);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useRadianceOverAlpha\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useObjectSpaceNormalMap\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useParallax\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useParallaxOcclusion\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"parallaxScaleBias\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], PBRMaterial.prototype, \"disableLighting\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"forceIrradianceInFragment\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], PBRMaterial.prototype, \"maxSimultaneousLights\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"invertNormalMapX\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"invertNormalMapY\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"twoSidedLighting\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useAlphaFresnel\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useLinearAlphaFresnel\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"environmentBRDFTexture\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"forceNormalForward\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"enableSpecularAntiAliasing\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useHorizonOcclusion\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], PBRMaterial.prototype, \"useRadianceOcclusion\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRMaterial.prototype, \"unlit\", void 0);\n __decorate$1([\n serialize(),\n expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\n ], PBRMaterial.prototype, \"applyDecalMapAfterDetailMap\", void 0);\n RegisterClass(\"BABYLON.PBRMaterial\", PBRMaterial);\n\n /**\n * Base class of all the lights in Babylon. It groups all the generic information about lights.\n * Lights are used, as you would expect, to affect how meshes are seen, in terms of both illumination and colour.\n * All meshes allow light to pass through them unless shadow generation is activated. The default number of lights allowed is four but this can be increased.\n */\n class Light extends Node {\n /**\n * Defines how far from the source the light is impacting in scene units.\n * Note: Unused in PBR material as the distance light falloff is defined following the inverse squared falloff.\n */\n get range() {\n return this._range;\n }\n /**\n * Defines how far from the source the light is impacting in scene units.\n * Note: Unused in PBR material as the distance light falloff is defined following the inverse squared falloff.\n */\n set range(value) {\n this._range = value;\n this._inverseSquaredRange = 1.0 / (this.range * this.range);\n }\n /**\n * Gets the photometric scale used to interpret the intensity.\n * This is only relevant with PBR Materials where the light intensity can be defined in a physical way.\n */\n get intensityMode() {\n return this._intensityMode;\n }\n /**\n * Sets the photometric scale used to interpret the intensity.\n * This is only relevant with PBR Materials where the light intensity can be defined in a physical way.\n */\n set intensityMode(value) {\n this._intensityMode = value;\n this._computePhotometricScale();\n }\n /**\n * Gets the light radius used by PBR Materials to simulate soft area lights.\n */\n get radius() {\n return this._radius;\n }\n /**\n * sets the light radius used by PBR Materials to simulate soft area lights.\n */\n set radius(value) {\n this._radius = value;\n this._computePhotometricScale();\n }\n /**\n * Gets whether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching\n * the current shadow generator.\n */\n get shadowEnabled() {\n return this._shadowEnabled;\n }\n /**\n * Sets whether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching\n * the current shadow generator.\n */\n set shadowEnabled(value) {\n if (this._shadowEnabled === value) {\n return;\n }\n this._shadowEnabled = value;\n this._markMeshesAsLightDirty();\n }\n /**\n * Gets the only meshes impacted by this light.\n */\n get includedOnlyMeshes() {\n return this._includedOnlyMeshes;\n }\n /**\n * Sets the only meshes impacted by this light.\n */\n set includedOnlyMeshes(value) {\n this._includedOnlyMeshes = value;\n this._hookArrayForIncludedOnly(value);\n }\n /**\n * Gets the meshes not impacted by this light.\n */\n get excludedMeshes() {\n return this._excludedMeshes;\n }\n /**\n * Sets the meshes not impacted by this light.\n */\n set excludedMeshes(value) {\n this._excludedMeshes = value;\n this._hookArrayForExcluded(value);\n }\n /**\n * Gets the layer id use to find what meshes are not impacted by the light.\n * Inactive if 0\n */\n get excludeWithLayerMask() {\n return this._excludeWithLayerMask;\n }\n /**\n * Sets the layer id use to find what meshes are not impacted by the light.\n * Inactive if 0\n */\n set excludeWithLayerMask(value) {\n this._excludeWithLayerMask = value;\n this._resyncMeshes();\n }\n /**\n * Gets the layer id use to find what meshes are impacted by the light.\n * Inactive if 0\n */\n get includeOnlyWithLayerMask() {\n return this._includeOnlyWithLayerMask;\n }\n /**\n * Sets the layer id use to find what meshes are impacted by the light.\n * Inactive if 0\n */\n set includeOnlyWithLayerMask(value) {\n this._includeOnlyWithLayerMask = value;\n this._resyncMeshes();\n }\n /**\n * Gets the lightmap mode of this light (should be one of the constants defined by Light.LIGHTMAP_x)\n */\n get lightmapMode() {\n return this._lightmapMode;\n }\n /**\n * Sets the lightmap mode of this light (should be one of the constants defined by Light.LIGHTMAP_x)\n */\n set lightmapMode(value) {\n if (this._lightmapMode === value) {\n return;\n }\n this._lightmapMode = value;\n this._markMeshesAsLightDirty();\n }\n /**\n * Creates a Light object in the scene.\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n * @param name The friendly name of the light\n * @param scene The scene the light belongs too\n */\n constructor(name, scene) {\n super(name, scene);\n /**\n * Diffuse gives the basic color to an object.\n */\n this.diffuse = new Color3(1.0, 1.0, 1.0);\n /**\n * Specular produces a highlight color on an object.\n * Note: This is not affecting PBR materials.\n */\n this.specular = new Color3(1.0, 1.0, 1.0);\n /**\n * Defines the falloff type for this light. This lets overriding how punctual light are\n * falling off base on range or angle.\n * This can be set to any values in Light.FALLOFF_x.\n *\n * Note: This is only useful for PBR Materials at the moment. This could be extended if required to\n * other types of materials.\n */\n this.falloffType = Light.FALLOFF_DEFAULT;\n /**\n * Strength of the light.\n * Note: By default it is define in the framework own unit.\n * Note: In PBR materials the intensityMode can be use to chose what unit the intensity is defined in.\n */\n this.intensity = 1.0;\n this._range = Number.MAX_VALUE;\n this._inverseSquaredRange = 0;\n /**\n * Cached photometric scale default to 1.0 as the automatic intensity mode defaults to 1.0 for every type\n * of light.\n */\n this._photometricScale = 1.0;\n this._intensityMode = Light.INTENSITYMODE_AUTOMATIC;\n this._radius = 0.00001;\n /**\n * Defines the rendering priority of the lights. It can help in case of fallback or number of lights\n * exceeding the number allowed of the materials.\n */\n this.renderPriority = 0;\n this._shadowEnabled = true;\n this._excludeWithLayerMask = 0;\n this._includeOnlyWithLayerMask = 0;\n this._lightmapMode = 0;\n /**\n * Shadow generators associated to the light.\n * @internal Internal use only.\n */\n this._shadowGenerators = null;\n /**\n * @internal Internal use only.\n */\n this._excludedMeshesIds = new Array();\n /**\n * @internal Internal use only.\n */\n this._includedOnlyMeshesIds = new Array();\n /** @internal */\n this._isLight = true;\n this.getScene().addLight(this);\n this._uniformBuffer = new UniformBuffer(this.getScene().getEngine(), undefined, undefined, name);\n this._buildUniformLayout();\n this.includedOnlyMeshes = new Array();\n this.excludedMeshes = new Array();\n this._resyncMeshes();\n }\n /**\n * Sets the passed Effect \"effect\" with the Light textures.\n * @param effect The effect to update\n * @param lightIndex The index of the light in the effect to update\n * @returns The light\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n transferTexturesToEffect(effect, lightIndex) {\n // Do nothing by default.\n return this;\n }\n /**\n * Binds the lights information from the scene to the effect for the given mesh.\n * @param lightIndex Light index\n * @param scene The scene where the light belongs to\n * @param effect The effect we are binding the data to\n * @param useSpecular Defines if specular is supported\n * @param receiveShadows Defines if the effect (mesh) we bind the light for receives shadows\n */\n _bindLight(lightIndex, scene, effect, useSpecular, receiveShadows = true) {\n var _a;\n const iAsString = lightIndex.toString();\n let needUpdate = false;\n this._uniformBuffer.bindToEffect(effect, \"Light\" + iAsString);\n if (this._renderId !== scene.getRenderId() || this._lastUseSpecular !== useSpecular || !this._uniformBuffer.useUbo) {\n this._renderId = scene.getRenderId();\n this._lastUseSpecular = useSpecular;\n const scaledIntensity = this.getScaledIntensity();\n this.transferToEffect(effect, iAsString);\n this.diffuse.scaleToRef(scaledIntensity, TmpColors.Color3[0]);\n this._uniformBuffer.updateColor4(\"vLightDiffuse\", TmpColors.Color3[0], this.range, iAsString);\n if (useSpecular) {\n this.specular.scaleToRef(scaledIntensity, TmpColors.Color3[1]);\n this._uniformBuffer.updateColor4(\"vLightSpecular\", TmpColors.Color3[1], this.radius, iAsString);\n }\n needUpdate = true;\n }\n // Textures might still need to be rebound.\n this.transferTexturesToEffect(effect, iAsString);\n // Shadows\n if (scene.shadowsEnabled && this.shadowEnabled && receiveShadows) {\n const shadowGenerator = (_a = this.getShadowGenerator(scene.activeCamera)) !== null && _a !== void 0 ? _a : this.getShadowGenerator();\n if (shadowGenerator) {\n shadowGenerator.bindShadowLight(iAsString, effect);\n needUpdate = true;\n }\n }\n if (needUpdate) {\n this._uniformBuffer.update();\n }\n else {\n this._uniformBuffer.bindUniformBuffer();\n }\n }\n /**\n * Returns the string \"Light\".\n * @returns the class name\n */\n getClassName() {\n return \"Light\";\n }\n /**\n * Converts the light information to a readable string for debug purpose.\n * @param fullDetails Supports for multiple levels of logging within scene loading\n * @returns the human readable light info\n */\n toString(fullDetails) {\n let ret = \"Name: \" + this.name;\n ret += \", type: \" + [\"Point\", \"Directional\", \"Spot\", \"Hemispheric\"][this.getTypeID()];\n if (this.animations) {\n for (let i = 0; i < this.animations.length; i++) {\n ret += \", animation[0]: \" + this.animations[i].toString(fullDetails);\n }\n }\n return ret;\n }\n /** @internal */\n _syncParentEnabledState() {\n super._syncParentEnabledState();\n if (!this.isDisposed()) {\n this._resyncMeshes();\n }\n }\n /**\n * Set the enabled state of this node.\n * @param value - the new enabled state\n */\n setEnabled(value) {\n super.setEnabled(value);\n this._resyncMeshes();\n }\n /**\n * Returns the Light associated shadow generator if any.\n * @param camera Camera for which the shadow generator should be retrieved (default: null). If null, retrieves the default shadow generator\n * @returns the associated shadow generator.\n */\n getShadowGenerator(camera = null) {\n var _a;\n if (this._shadowGenerators === null) {\n return null;\n }\n return (_a = this._shadowGenerators.get(camera)) !== null && _a !== void 0 ? _a : null;\n }\n /**\n * Returns all the shadow generators associated to this light\n * @returns\n */\n getShadowGenerators() {\n return this._shadowGenerators;\n }\n /**\n * Returns a Vector3, the absolute light position in the World.\n * @returns the world space position of the light\n */\n getAbsolutePosition() {\n return Vector3.Zero();\n }\n /**\n * Specifies if the light will affect the passed mesh.\n * @param mesh The mesh to test against the light\n * @returns true the mesh is affected otherwise, false.\n */\n canAffectMesh(mesh) {\n if (!mesh) {\n return true;\n }\n if (this.includedOnlyMeshes && this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {\n return false;\n }\n if (this.excludedMeshes && this.excludedMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {\n return false;\n }\n if (this.includeOnlyWithLayerMask !== 0 && (this.includeOnlyWithLayerMask & mesh.layerMask) === 0) {\n return false;\n }\n if (this.excludeWithLayerMask !== 0 && this.excludeWithLayerMask & mesh.layerMask) {\n return false;\n }\n return true;\n }\n /**\n * Releases resources associated with this node.\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n if (this._shadowGenerators) {\n const iterator = this._shadowGenerators.values();\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\n const shadowGenerator = key.value;\n shadowGenerator.dispose();\n }\n this._shadowGenerators = null;\n }\n // Animations\n this.getScene().stopAnimation(this);\n if (this._parentContainer) {\n const index = this._parentContainer.lights.indexOf(this);\n if (index > -1) {\n this._parentContainer.lights.splice(index, 1);\n }\n this._parentContainer = null;\n }\n // Remove from meshes\n for (const mesh of this.getScene().meshes) {\n mesh._removeLightSource(this, true);\n }\n this._uniformBuffer.dispose();\n // Remove from scene\n this.getScene().removeLight(this);\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n /**\n * Returns the light type ID (integer).\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\n */\n getTypeID() {\n return 0;\n }\n /**\n * Returns the intensity scaled by the Photometric Scale according to the light type and intensity mode.\n * @returns the scaled intensity in intensity mode unit\n */\n getScaledIntensity() {\n return this._photometricScale * this.intensity;\n }\n /**\n * Returns a new Light object, named \"name\", from the current one.\n * @param name The name of the cloned light\n * @param newParent The parent of this light, if it has one\n * @returns the new created light\n */\n clone(name, newParent = null) {\n const constructor = Light.GetConstructorFromName(this.getTypeID(), name, this.getScene());\n if (!constructor) {\n return null;\n }\n const clonedLight = SerializationHelper.Clone(constructor, this);\n if (name) {\n clonedLight.name = name;\n }\n if (newParent) {\n clonedLight.parent = newParent;\n }\n clonedLight.setEnabled(this.isEnabled());\n this.onClonedObservable.notifyObservers(clonedLight);\n return clonedLight;\n }\n /**\n * Serializes the current light into a Serialization object.\n * @returns the serialized object.\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this);\n serializationObject.uniqueId = this.uniqueId;\n // Type\n serializationObject.type = this.getTypeID();\n // Parent\n if (this.parent) {\n this.parent._serializeAsParent(serializationObject);\n }\n // Inclusion / exclusions\n if (this.excludedMeshes.length > 0) {\n serializationObject.excludedMeshesIds = [];\n this.excludedMeshes.forEach((mesh) => {\n serializationObject.excludedMeshesIds.push(mesh.id);\n });\n }\n if (this.includedOnlyMeshes.length > 0) {\n serializationObject.includedOnlyMeshesIds = [];\n this.includedOnlyMeshes.forEach((mesh) => {\n serializationObject.includedOnlyMeshesIds.push(mesh.id);\n });\n }\n // Animations\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\n serializationObject.ranges = this.serializeAnimationRanges();\n serializationObject.isEnabled = this.isEnabled();\n return serializationObject;\n }\n /**\n * Creates a new typed light from the passed type (integer) : point light = 0, directional light = 1, spot light = 2, hemispheric light = 3.\n * This new light is named \"name\" and added to the passed scene.\n * @param type Type according to the types available in Light.LIGHTTYPEID_x\n * @param name The friendly name of the light\n * @param scene The scene the new light will belong to\n * @returns the constructor function\n */\n static GetConstructorFromName(type, name, scene) {\n const constructorFunc = Node.Construct(\"Light_Type_\" + type, name, scene);\n if (constructorFunc) {\n return constructorFunc;\n }\n // Default to no light for none present once.\n return null;\n }\n /**\n * Parses the passed \"parsedLight\" and returns a new instanced Light from this parsing.\n * @param parsedLight The JSON representation of the light\n * @param scene The scene to create the parsed light in\n * @returns the created light after parsing\n */\n static Parse(parsedLight, scene) {\n const constructor = Light.GetConstructorFromName(parsedLight.type, parsedLight.name, scene);\n if (!constructor) {\n return null;\n }\n const light = SerializationHelper.Parse(constructor, parsedLight, scene);\n // Inclusion / exclusions\n if (parsedLight.excludedMeshesIds) {\n light._excludedMeshesIds = parsedLight.excludedMeshesIds;\n }\n if (parsedLight.includedOnlyMeshesIds) {\n light._includedOnlyMeshesIds = parsedLight.includedOnlyMeshesIds;\n }\n // Parent\n if (parsedLight.parentId !== undefined) {\n light._waitingParentId = parsedLight.parentId;\n }\n if (parsedLight.parentInstanceIndex !== undefined) {\n light._waitingParentInstanceIndex = parsedLight.parentInstanceIndex;\n }\n // Falloff\n if (parsedLight.falloffType !== undefined) {\n light.falloffType = parsedLight.falloffType;\n }\n // Lightmaps\n if (parsedLight.lightmapMode !== undefined) {\n light.lightmapMode = parsedLight.lightmapMode;\n }\n // Animations\n if (parsedLight.animations) {\n for (let animationIndex = 0; animationIndex < parsedLight.animations.length; animationIndex++) {\n const parsedAnimation = parsedLight.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n light.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n Node.ParseAnimationRanges(light, parsedLight, scene);\n }\n if (parsedLight.autoAnimate) {\n scene.beginAnimation(light, parsedLight.autoAnimateFrom, parsedLight.autoAnimateTo, parsedLight.autoAnimateLoop, parsedLight.autoAnimateSpeed || 1.0);\n }\n // Check if isEnabled is defined to be back compatible with prior serialized versions.\n if (parsedLight.isEnabled !== undefined) {\n light.setEnabled(parsedLight.isEnabled);\n }\n return light;\n }\n _hookArrayForExcluded(array) {\n const oldPush = array.push;\n array.push = (...items) => {\n const result = oldPush.apply(array, items);\n for (const item of items) {\n item._resyncLightSource(this);\n }\n return result;\n };\n const oldSplice = array.splice;\n array.splice = (index, deleteCount) => {\n const deleted = oldSplice.apply(array, [index, deleteCount]);\n for (const item of deleted) {\n item._resyncLightSource(this);\n }\n return deleted;\n };\n for (const item of array) {\n item._resyncLightSource(this);\n }\n }\n _hookArrayForIncludedOnly(array) {\n const oldPush = array.push;\n array.push = (...items) => {\n const result = oldPush.apply(array, items);\n this._resyncMeshes();\n return result;\n };\n const oldSplice = array.splice;\n array.splice = (index, deleteCount) => {\n const deleted = oldSplice.apply(array, [index, deleteCount]);\n this._resyncMeshes();\n return deleted;\n };\n this._resyncMeshes();\n }\n _resyncMeshes() {\n for (const mesh of this.getScene().meshes) {\n mesh._resyncLightSource(this);\n }\n }\n /**\n * Forces the meshes to update their light related information in their rendering used effects\n * @internal Internal Use Only\n */\n _markMeshesAsLightDirty() {\n for (const mesh of this.getScene().meshes) {\n if (mesh.lightSources.indexOf(this) !== -1) {\n mesh._markSubMeshesAsLightDirty();\n }\n }\n }\n /**\n * Recomputes the cached photometric scale if needed.\n */\n _computePhotometricScale() {\n this._photometricScale = this._getPhotometricScale();\n this.getScene().resetCachedMaterial();\n }\n /**\n * Returns the Photometric Scale according to the light type and intensity mode.\n */\n _getPhotometricScale() {\n let photometricScale = 0.0;\n const lightTypeID = this.getTypeID();\n //get photometric mode\n let photometricMode = this.intensityMode;\n if (photometricMode === Light.INTENSITYMODE_AUTOMATIC) {\n if (lightTypeID === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {\n photometricMode = Light.INTENSITYMODE_ILLUMINANCE;\n }\n else {\n photometricMode = Light.INTENSITYMODE_LUMINOUSINTENSITY;\n }\n }\n //compute photometric scale\n switch (lightTypeID) {\n case Light.LIGHTTYPEID_POINTLIGHT:\n case Light.LIGHTTYPEID_SPOTLIGHT:\n switch (photometricMode) {\n case Light.INTENSITYMODE_LUMINOUSPOWER:\n photometricScale = 1.0 / (4.0 * Math.PI);\n break;\n case Light.INTENSITYMODE_LUMINOUSINTENSITY:\n photometricScale = 1.0;\n break;\n case Light.INTENSITYMODE_LUMINANCE:\n photometricScale = this.radius * this.radius;\n break;\n }\n break;\n case Light.LIGHTTYPEID_DIRECTIONALLIGHT:\n switch (photometricMode) {\n case Light.INTENSITYMODE_ILLUMINANCE:\n photometricScale = 1.0;\n break;\n case Light.INTENSITYMODE_LUMINANCE: {\n // When radius (and therefore solid angle) is non-zero a directional lights brightness can be specified via central (peak) luminance.\n // For a directional light the 'radius' defines the angular radius (in radians) rather than world-space radius (e.g. in metres).\n let apexAngleRadians = this.radius;\n // Impose a minimum light angular size to avoid the light becoming an infinitely small angular light source (i.e. a dirac delta function).\n apexAngleRadians = Math.max(apexAngleRadians, 0.001);\n const solidAngle = 2.0 * Math.PI * (1.0 - Math.cos(apexAngleRadians));\n photometricScale = solidAngle;\n break;\n }\n }\n break;\n case Light.LIGHTTYPEID_HEMISPHERICLIGHT:\n // No fall off in hemispheric light.\n photometricScale = 1.0;\n break;\n }\n return photometricScale;\n }\n /**\n * Reorder the light in the scene according to their defined priority.\n * @internal Internal Use Only\n */\n _reorderLightsInScene() {\n const scene = this.getScene();\n if (this._renderPriority != 0) {\n scene.requireLightSorting = true;\n }\n this.getScene().sortLightsByPriority();\n }\n }\n /**\n * Falloff Default: light is falling off following the material specification:\n * standard material is using standard falloff whereas pbr material can request special falloff per materials.\n */\n Light.FALLOFF_DEFAULT = LightConstants.FALLOFF_DEFAULT;\n /**\n * Falloff Physical: light is falling off following the inverse squared distance law.\n */\n Light.FALLOFF_PHYSICAL = LightConstants.FALLOFF_PHYSICAL;\n /**\n * Falloff gltf: light is falling off as described in the gltf moving to PBR document\n * to enhance interoperability with other engines.\n */\n Light.FALLOFF_GLTF = LightConstants.FALLOFF_GLTF;\n /**\n * Falloff Standard: light is falling off like in the standard material\n * to enhance interoperability with other materials.\n */\n Light.FALLOFF_STANDARD = LightConstants.FALLOFF_STANDARD;\n //lightmapMode Consts\n /**\n * If every light affecting the material is in this lightmapMode,\n * material.lightmapTexture adds or multiplies\n * (depends on material.useLightmapAsShadowmap)\n * after every other light calculations.\n */\n Light.LIGHTMAP_DEFAULT = LightConstants.LIGHTMAP_DEFAULT;\n /**\n * material.lightmapTexture as only diffuse lighting from this light\n * adds only specular lighting from this light\n * adds dynamic shadows\n */\n Light.LIGHTMAP_SPECULAR = LightConstants.LIGHTMAP_SPECULAR;\n /**\n * material.lightmapTexture as only lighting\n * no light calculation from this light\n * only adds dynamic shadows from this light\n */\n Light.LIGHTMAP_SHADOWSONLY = LightConstants.LIGHTMAP_SHADOWSONLY;\n // Intensity Mode Consts\n /**\n * Each light type uses the default quantity according to its type:\n * point/spot lights use luminous intensity\n * directional lights use illuminance\n */\n Light.INTENSITYMODE_AUTOMATIC = LightConstants.INTENSITYMODE_AUTOMATIC;\n /**\n * lumen (lm)\n */\n Light.INTENSITYMODE_LUMINOUSPOWER = LightConstants.INTENSITYMODE_LUMINOUSPOWER;\n /**\n * candela (lm/sr)\n */\n Light.INTENSITYMODE_LUMINOUSINTENSITY = LightConstants.INTENSITYMODE_LUMINOUSINTENSITY;\n /**\n * lux (lm/m^2)\n */\n Light.INTENSITYMODE_ILLUMINANCE = LightConstants.INTENSITYMODE_ILLUMINANCE;\n /**\n * nit (cd/m^2)\n */\n Light.INTENSITYMODE_LUMINANCE = LightConstants.INTENSITYMODE_LUMINANCE;\n // Light types ids const.\n /**\n * Light type const id of the point light.\n */\n Light.LIGHTTYPEID_POINTLIGHT = LightConstants.LIGHTTYPEID_POINTLIGHT;\n /**\n * Light type const id of the directional light.\n */\n Light.LIGHTTYPEID_DIRECTIONALLIGHT = LightConstants.LIGHTTYPEID_DIRECTIONALLIGHT;\n /**\n * Light type const id of the spot light.\n */\n Light.LIGHTTYPEID_SPOTLIGHT = LightConstants.LIGHTTYPEID_SPOTLIGHT;\n /**\n * Light type const id of the hemispheric light.\n */\n Light.LIGHTTYPEID_HEMISPHERICLIGHT = LightConstants.LIGHTTYPEID_HEMISPHERICLIGHT;\n __decorate$1([\n serializeAsColor3()\n ], Light.prototype, \"diffuse\", void 0);\n __decorate$1([\n serializeAsColor3()\n ], Light.prototype, \"specular\", void 0);\n __decorate$1([\n serialize()\n ], Light.prototype, \"falloffType\", void 0);\n __decorate$1([\n serialize()\n ], Light.prototype, \"intensity\", void 0);\n __decorate$1([\n serialize()\n ], Light.prototype, \"range\", null);\n __decorate$1([\n serialize()\n ], Light.prototype, \"intensityMode\", null);\n __decorate$1([\n serialize()\n ], Light.prototype, \"radius\", null);\n __decorate$1([\n serialize()\n ], Light.prototype, \"_renderPriority\", void 0);\n __decorate$1([\n expandToProperty(\"_reorderLightsInScene\")\n ], Light.prototype, \"renderPriority\", void 0);\n __decorate$1([\n serialize(\"shadowEnabled\")\n ], Light.prototype, \"_shadowEnabled\", void 0);\n __decorate$1([\n serialize(\"excludeWithLayerMask\")\n ], Light.prototype, \"_excludeWithLayerMask\", void 0);\n __decorate$1([\n serialize(\"includeOnlyWithLayerMask\")\n ], Light.prototype, \"_includeOnlyWithLayerMask\", void 0);\n __decorate$1([\n serialize(\"lightmapMode\")\n ], Light.prototype, \"_lightmapMode\", void 0);\n\n Node.AddNodeConstructor(\"Light_Type_3\", (name, scene) => {\n return () => new HemisphericLight(name, Vector3.Zero(), scene);\n });\n /**\n * The HemisphericLight simulates the ambient environment light,\n * so the passed direction is the light reflection direction, not the incoming direction.\n */\n class HemisphericLight extends Light {\n /**\n * Creates a HemisphericLight object in the scene according to the passed direction (Vector3).\n * The HemisphericLight simulates the ambient environment light, so the passed direction is the light reflection direction, not the incoming direction.\n * The HemisphericLight can't cast shadows.\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n * @param name The friendly name of the light\n * @param direction The direction of the light reflection\n * @param scene The scene the light belongs to\n */\n constructor(name, direction, scene) {\n super(name, scene);\n /**\n * The groundColor is the light in the opposite direction to the one specified during creation.\n * You can think of the diffuse and specular light as coming from the centre of the object in the given direction and the groundColor light in the opposite direction.\n */\n this.groundColor = new Color3(0.0, 0.0, 0.0);\n this.direction = direction || Vector3.Up();\n }\n _buildUniformLayout() {\n this._uniformBuffer.addUniform(\"vLightData\", 4);\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\n this._uniformBuffer.addUniform(\"vLightGround\", 3);\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\n this._uniformBuffer.addUniform(\"depthValues\", 2);\n this._uniformBuffer.create();\n }\n /**\n * Returns the string \"HemisphericLight\".\n * @returns The class name\n */\n getClassName() {\n return \"HemisphericLight\";\n }\n /**\n * Sets the HemisphericLight direction towards the passed target (Vector3).\n * Returns the updated direction.\n * @param target The target the direction should point to\n * @returns The computed direction\n */\n setDirectionToTarget(target) {\n this.direction = Vector3.Normalize(target.subtract(Vector3.Zero()));\n return this.direction;\n }\n /**\n * Returns the shadow generator associated to the light.\n * @returns Always null for hemispheric lights because it does not support shadows.\n */\n getShadowGenerator() {\n return null;\n }\n /**\n * Sets the passed Effect object with the HemisphericLight normalized direction and color and the passed name (string).\n * @param _effect The effect to update\n * @param lightIndex The index of the light in the effect to update\n * @returns The hemispheric light\n */\n transferToEffect(_effect, lightIndex) {\n const normalizeDirection = Vector3.Normalize(this.direction);\n this._uniformBuffer.updateFloat4(\"vLightData\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0.0, lightIndex);\n this._uniformBuffer.updateColor3(\"vLightGround\", this.groundColor.scale(this.intensity), lightIndex);\n return this;\n }\n transferToNodeMaterialEffect(effect, lightDataUniformName) {\n const normalizeDirection = Vector3.Normalize(this.direction);\n effect.setFloat3(lightDataUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z);\n return this;\n }\n /**\n * Computes the world matrix of the node\n * @returns the world matrix\n */\n computeWorldMatrix() {\n if (!this._worldMatrix) {\n this._worldMatrix = Matrix.Identity();\n }\n return this._worldMatrix;\n }\n /**\n * Returns the integer 3.\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\n */\n getTypeID() {\n return Light.LIGHTTYPEID_HEMISPHERICLIGHT;\n }\n /**\n * Prepares the list of defines specific to the light type.\n * @param defines the list of defines\n * @param lightIndex defines the index of the light for the effect\n */\n prepareLightSpecificDefines(defines, lightIndex) {\n defines[\"HEMILIGHT\" + lightIndex] = true;\n }\n }\n __decorate$1([\n serializeAsColor3()\n ], HemisphericLight.prototype, \"groundColor\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], HemisphericLight.prototype, \"direction\", void 0);\n\n // Do not edit.\n const name$1H = \"kernelBlurVaryingDeclaration\";\n const shader$1H = `varying vec2 sampleCoord{X};`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1H] = shader$1H;\n\n // Do not edit.\n const name$1I = \"packingFunctions\";\n const shader$1I = `vec4 pack(float depth)\n{const vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);const vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);vec4 res=fract(depth*bit_shift);res-=res.xxyz*bit_mask;return res;}\nfloat unpack(vec4 color)\n{const vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);return dot(color,bit_shift);}`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1I] = shader$1I;\n\n // Do not edit.\n const name$1J = \"kernelBlurFragment\";\n const shader$1J = `#ifdef DOF\nfactor=sampleCoC(sampleCoord{X}); \ncomputedWeight=KERNEL_WEIGHT{X}*factor;sumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCoord{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCoord{X})*computedWeight;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1J] = shader$1J;\n\n // Do not edit.\n const name$1K = \"kernelBlurFragment2\";\n const shader$1K = `#ifdef DOF\nfactor=sampleCoC(sampleCenter+delta*KERNEL_DEP_OFFSET{X});computedWeight=KERNEL_DEP_WEIGHT{X}*factor;sumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_DEP_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X})*computedWeight;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1K] = shader$1K;\n\n // Do not edit.\n const name$1L = \"kernelBlurPixelShader\";\n const shader$1L = `uniform sampler2D textureSampler;uniform vec2 delta;varying vec2 sampleCenter;\n#ifdef DOF\nuniform sampler2D circleOfConfusionSampler;float sampleCoC(in vec2 offset) {float coc=texture2D(circleOfConfusionSampler,offset).r;return coc; }\n#endif\n#include[0..varyingCount]\n#ifdef PACKEDFLOAT\n#include\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{float computedWeight=0.0;\n#ifdef PACKEDFLOAT\nfloat blend=0.;\n#else\nvec4 blend=vec4(0.);\n#endif\n#ifdef DOF\nfloat sumOfWeights=CENTER_WEIGHT; \nfloat factor=0.0;\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter))*CENTER_WEIGHT;\n#else\nblend+=texture2D(textureSampler,sampleCenter)*CENTER_WEIGHT;\n#endif\n#endif\n#include[0..varyingCount]\n#include[0..depCount]\n#ifdef PACKEDFLOAT\ngl_FragColor=pack(blend);\n#else\ngl_FragColor=blend;\n#endif\n#ifdef DOF\ngl_FragColor/=sumOfWeights;\n#endif\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1L] = shader$1L;\n\n // Do not edit.\n const name$1M = \"kernelBlurVertex\";\n const shader$1M = `sampleCoord{X}=sampleCenter+delta*KERNEL_OFFSET{X};`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1M] = shader$1M;\n\n // Do not edit.\n const name$1N = \"kernelBlurVertexShader\";\n const shader$1N = `attribute vec2 position;uniform vec2 delta;varying vec2 sampleCenter;\n#include[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nsampleCenter=(position*madd+madd);\n#include[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1N] = shader$1N;\n\n /**\n * The Blur Post Process which blurs an image based on a kernel and direction.\n * Can be used twice in x and y directions to perform a gaussian blur in two passes.\n */\n class BlurPostProcess extends PostProcess {\n /**\n * Sets the length in pixels of the blur sample region\n */\n set kernel(v) {\n if (this._idealKernel === v) {\n return;\n }\n v = Math.max(v, 1);\n this._idealKernel = v;\n this._kernel = this._nearestBestKernel(v);\n if (!this._blockCompilation) {\n this._updateParameters();\n }\n }\n /**\n * Gets the length in pixels of the blur sample region\n */\n get kernel() {\n return this._idealKernel;\n }\n /**\n * Sets whether or not the blur needs to unpack/repack floats\n */\n set packedFloat(v) {\n if (this._packedFloat === v) {\n return;\n }\n this._packedFloat = v;\n if (!this._blockCompilation) {\n this._updateParameters();\n }\n }\n /**\n * Gets whether or not the blur is unpacking/repacking floats\n */\n get packedFloat() {\n return this._packedFloat;\n }\n /**\n * Gets a string identifying the name of the class\n * @returns \"BlurPostProcess\" string\n */\n getClassName() {\n return \"BlurPostProcess\";\n }\n /**\n * Creates a new instance BlurPostProcess\n * @param name The name of the effect.\n * @param direction The direction in which to blur the image.\n * @param kernel The size of the kernel to be used when computing the blur. eg. Size of 3 will blur the center pixel by 2 pixels surrounding it.\n * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)\n * @param camera The camera to apply the render pass to.\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\n * @param engine The engine which the post process will be applied. (default: current engine)\n * @param reusable If the post process can be reused on the same frame. (default: false)\n * @param textureType Type of textures used when performing the post process. (default: 0)\n * @param defines\n * @param _blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)\n * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)\n */\n constructor(name, direction, kernel, options, camera, samplingMode = Texture.BILINEAR_SAMPLINGMODE, engine, reusable, textureType = 0, defines = \"\", _blockCompilation = false, textureFormat = 5) {\n super(name, \"kernelBlur\", [\"delta\", \"direction\"], [\"circleOfConfusionSampler\"], options, camera, samplingMode, engine, reusable, null, textureType, \"kernelBlur\", { varyingCount: 0, depCount: 0 }, true, textureFormat);\n this._blockCompilation = _blockCompilation;\n this._packedFloat = false;\n this._staticDefines = \"\";\n this._staticDefines = defines;\n this.direction = direction;\n this.onApplyObservable.add((effect) => {\n if (this._outputTexture) {\n effect.setFloat2(\"delta\", (1 / this._outputTexture.width) * this.direction.x, (1 / this._outputTexture.height) * this.direction.y);\n }\n else {\n effect.setFloat2(\"delta\", (1 / this.width) * this.direction.x, (1 / this.height) * this.direction.y);\n }\n });\n this.kernel = kernel;\n }\n /**\n * Updates the effect with the current post process compile time values and recompiles the shader.\n * @param defines Define statements that should be added at the beginning of the shader. (default: null)\n * @param uniforms Set of uniform variables that will be passed to the shader. (default: null)\n * @param samplers Set of Texture2D variables that will be passed to the shader. (default: null)\n * @param indexParameters The index parameters to be used for babylons include syntax \"#include[0..varyingCount]\". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx\n * @param onCompiled Called when the shader has been compiled.\n * @param onError Called if there is an error when compiling a shader.\n */\n updateEffect(defines = null, uniforms = null, samplers = null, indexParameters, onCompiled, onError) {\n this._updateParameters(onCompiled, onError);\n }\n _updateParameters(onCompiled, onError) {\n // Generate sampling offsets and weights\n const N = this._kernel;\n const centerIndex = (N - 1) / 2;\n // Generate Gaussian sampling weights over kernel\n let offsets = [];\n let weights = [];\n let totalWeight = 0;\n for (let i = 0; i < N; i++) {\n const u = i / (N - 1);\n const w = this._gaussianWeight(u * 2.0 - 1);\n offsets[i] = i - centerIndex;\n weights[i] = w;\n totalWeight += w;\n }\n // Normalize weights\n for (let i = 0; i < weights.length; i++) {\n weights[i] /= totalWeight;\n }\n // Optimize: combine samples to take advantage of hardware linear sampling\n // Walk from left to center, combining pairs (symmetrically)\n const linearSamplingWeights = [];\n const linearSamplingOffsets = [];\n const linearSamplingMap = [];\n for (let i = 0; i <= centerIndex; i += 2) {\n const j = Math.min(i + 1, Math.floor(centerIndex));\n const singleCenterSample = i === j;\n if (singleCenterSample) {\n linearSamplingMap.push({ o: offsets[i], w: weights[i] });\n }\n else {\n const sharedCell = j === centerIndex;\n const weightLinear = weights[i] + weights[j] * (sharedCell ? 0.5 : 1);\n const offsetLinear = offsets[i] + 1 / (1 + weights[i] / weights[j]);\n if (offsetLinear === 0) {\n linearSamplingMap.push({ o: offsets[i], w: weights[i] });\n linearSamplingMap.push({ o: offsets[i + 1], w: weights[i + 1] });\n }\n else {\n linearSamplingMap.push({ o: offsetLinear, w: weightLinear });\n linearSamplingMap.push({ o: -offsetLinear, w: weightLinear });\n }\n }\n }\n for (let i = 0; i < linearSamplingMap.length; i++) {\n linearSamplingOffsets[i] = linearSamplingMap[i].o;\n linearSamplingWeights[i] = linearSamplingMap[i].w;\n }\n // Replace with optimized\n offsets = linearSamplingOffsets;\n weights = linearSamplingWeights;\n // Generate shaders\n const maxVaryingRows = this.getEngine().getCaps().maxVaryingVectors;\n const freeVaryingVec2 = Math.max(maxVaryingRows, 0) - 1; // Because of sampleCenter\n let varyingCount = Math.min(offsets.length, freeVaryingVec2);\n let defines = \"\";\n defines += this._staticDefines;\n // The DOF fragment should ignore the center pixel when looping as it is handled manually in the fragment shader.\n if (this._staticDefines.indexOf(\"DOF\") != -1) {\n defines += `#define CENTER_WEIGHT ${this._glslFloat(weights[varyingCount - 1])}\\n`;\n varyingCount--;\n }\n for (let i = 0; i < varyingCount; i++) {\n defines += `#define KERNEL_OFFSET${i} ${this._glslFloat(offsets[i])}\\n`;\n defines += `#define KERNEL_WEIGHT${i} ${this._glslFloat(weights[i])}\\n`;\n }\n let depCount = 0;\n for (let i = freeVaryingVec2; i < offsets.length; i++) {\n defines += `#define KERNEL_DEP_OFFSET${depCount} ${this._glslFloat(offsets[i])}\\n`;\n defines += `#define KERNEL_DEP_WEIGHT${depCount} ${this._glslFloat(weights[i])}\\n`;\n depCount++;\n }\n if (this.packedFloat) {\n defines += `#define PACKEDFLOAT 1`;\n }\n this._blockCompilation = false;\n super.updateEffect(defines, null, null, {\n varyingCount: varyingCount,\n depCount: depCount,\n }, onCompiled, onError);\n }\n /**\n * Best kernels are odd numbers that when divided by 2, their integer part is even, so 5, 9 or 13.\n * Other odd kernels optimize correctly but require proportionally more samples, even kernels are\n * possible but will produce minor visual artifacts. Since each new kernel requires a new shader we\n * want to minimize kernel changes, having gaps between physical kernels is helpful in that regard.\n * The gaps between physical kernels are compensated for in the weighting of the samples\n * @param idealKernel Ideal blur kernel.\n * @returns Nearest best kernel.\n */\n _nearestBestKernel(idealKernel) {\n const v = Math.round(idealKernel);\n for (const k of [v, v - 1, v + 1, v - 2, v + 2]) {\n if (k % 2 !== 0 && Math.floor(k / 2) % 2 === 0 && k > 0) {\n return Math.max(k, 3);\n }\n }\n return Math.max(v, 3);\n }\n /**\n * Calculates the value of a Gaussian distribution with sigma 3 at a given point.\n * @param x The point on the Gaussian distribution to sample.\n * @returns the value of the Gaussian function at x.\n */\n _gaussianWeight(x) {\n //reference: Engines/ImageProcessingBlur.cpp #dcc760\n // We are evaluating the Gaussian (normal) distribution over a kernel parameter space of [-1,1],\n // so we truncate at three standard deviations by setting stddev (sigma) to 1/3.\n // The choice of 3-sigma truncation is common but arbitrary, and means that the signal is\n // truncated at around 1.3% of peak strength.\n //the distribution is scaled to account for the difference between the actual kernel size and the requested kernel size\n const sigma = 1 / 3;\n const denominator = Math.sqrt(2.0 * Math.PI) * sigma;\n const exponent = -((x * x) / (2.0 * sigma * sigma));\n const weight = (1.0 / denominator) * Math.exp(exponent);\n return weight;\n }\n /**\n * Generates a string that can be used as a floating point number in GLSL.\n * @param x Value to print.\n * @param decimalFigures Number of decimal places to print the number to (excluding trailing 0s).\n * @returns GLSL float string.\n */\n _glslFloat(x, decimalFigures = 8) {\n return x.toFixed(decimalFigures).replace(/0+$/, \"\");\n }\n /**\n * @internal\n */\n static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {\n return SerializationHelper.Parse(() => {\n return new BlurPostProcess(parsedPostProcess.name, parsedPostProcess.direction, parsedPostProcess.kernel, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, scene.getEngine(), parsedPostProcess.reusable, parsedPostProcess.textureType, undefined, false);\n }, parsedPostProcess, scene, rootUrl);\n }\n }\n __decorate$1([\n serialize(\"kernel\")\n ], BlurPostProcess.prototype, \"_kernel\", void 0);\n __decorate$1([\n serialize(\"packedFloat\")\n ], BlurPostProcess.prototype, \"_packedFloat\", void 0);\n __decorate$1([\n serializeAsVector2()\n ], BlurPostProcess.prototype, \"direction\", void 0);\n RegisterClass(\"BABYLON.BlurPostProcess\", BlurPostProcess);\n\n /**\n * Mirror texture can be used to simulate the view from a mirror in a scene.\n * It will dynamically be rendered every frame to adapt to the camera point of view.\n * You can then easily use it as a reflectionTexture on a flat surface.\n * In case the surface is not a plane, please consider relying on reflection probes.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#mirrortexture\n */\n class MirrorTexture extends RenderTargetTexture {\n /**\n * Define the blur ratio used to blur the reflection if needed.\n */\n set blurRatio(value) {\n if (this._blurRatio === value) {\n return;\n }\n this._blurRatio = value;\n this._preparePostProcesses();\n }\n get blurRatio() {\n return this._blurRatio;\n }\n /**\n * Define the adaptive blur kernel used to blur the reflection if needed.\n * This will autocompute the closest best match for the `blurKernel`\n */\n set adaptiveBlurKernel(value) {\n this._adaptiveBlurKernel = value;\n this._autoComputeBlurKernel();\n }\n /**\n * Define the blur kernel used to blur the reflection if needed.\n * Please consider using `adaptiveBlurKernel` as it could find the closest best value for you.\n */\n set blurKernel(value) {\n this.blurKernelX = value;\n this.blurKernelY = value;\n }\n /**\n * Define the blur kernel on the X Axis used to blur the reflection if needed.\n * Please consider using `adaptiveBlurKernel` as it could find the closest best value for you.\n */\n set blurKernelX(value) {\n if (this._blurKernelX === value) {\n return;\n }\n this._blurKernelX = value;\n this._preparePostProcesses();\n }\n get blurKernelX() {\n return this._blurKernelX;\n }\n /**\n * Define the blur kernel on the Y Axis used to blur the reflection if needed.\n * Please consider using `adaptiveBlurKernel` as it could find the closest best value for you.\n */\n set blurKernelY(value) {\n if (this._blurKernelY === value) {\n return;\n }\n this._blurKernelY = value;\n this._preparePostProcesses();\n }\n get blurKernelY() {\n return this._blurKernelY;\n }\n _autoComputeBlurKernel() {\n const engine = this.getScene().getEngine();\n const dw = this.getRenderWidth() / engine.getRenderWidth();\n const dh = this.getRenderHeight() / engine.getRenderHeight();\n this.blurKernelX = this._adaptiveBlurKernel * dw;\n this.blurKernelY = this._adaptiveBlurKernel * dh;\n }\n _onRatioRescale() {\n if (this._sizeRatio) {\n this.resize(this._initialSizeParameter);\n if (!this._adaptiveBlurKernel) {\n this._preparePostProcesses();\n }\n }\n if (this._adaptiveBlurKernel) {\n this._autoComputeBlurKernel();\n }\n }\n _updateGammaSpace() {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n this.gammaSpace = !scene.imageProcessingConfiguration.isEnabled || !scene.imageProcessingConfiguration.applyByPostProcess;\n }\n /**\n * Instantiates a Mirror Texture.\n * Mirror texture can be used to simulate the view from a mirror in a scene.\n * It will dynamically be rendered every frame to adapt to the camera point of view.\n * You can then easily use it as a reflectionTexture on a flat surface.\n * In case the surface is not a plane, please consider relying on reflection probes.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#mirrors\n * @param name\n * @param size\n * @param scene\n * @param generateMipMaps\n * @param type\n * @param samplingMode\n * @param generateDepthBuffer\n */\n constructor(name, size, scene, generateMipMaps, type = 0, samplingMode = Texture.BILINEAR_SAMPLINGMODE, generateDepthBuffer = true) {\n super(name, size, scene, generateMipMaps, true, type, false, samplingMode, generateDepthBuffer);\n /**\n * Define the reflection plane we want to use. The mirrorPlane is usually set to the constructed reflector.\n * It is possible to directly set the mirrorPlane by directly using a Plane(a, b, c, d) where a, b and c give the plane normal vector (a, b, c) and d is a scalar displacement from the mirrorPlane to the origin. However in all but the very simplest of situations it is more straight forward to set it to the reflector as stated in the doc.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#mirrors\n */\n this.mirrorPlane = new Plane(0, 1, 0, 1);\n this._transformMatrix = Matrix.Zero();\n this._mirrorMatrix = Matrix.Zero();\n this._adaptiveBlurKernel = 0;\n this._blurKernelX = 0;\n this._blurKernelY = 0;\n this._blurRatio = 1.0;\n scene = this.getScene();\n if (!scene) {\n return this;\n }\n this.ignoreCameraViewport = true;\n this._updateGammaSpace();\n this._imageProcessingConfigChangeObserver = scene.imageProcessingConfiguration.onUpdateParameters.add(() => {\n this._updateGammaSpace();\n });\n const engine = scene.getEngine();\n if (engine.supportsUniformBuffers) {\n this._sceneUBO = scene.createSceneUniformBuffer(`Scene for Mirror Texture (name \"${name}\")`);\n }\n this.onBeforeBindObservable.add(() => {\n var _a;\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, `mirror generation for ${name}`, 1);\n });\n this.onAfterUnbindObservable.add(() => {\n var _a;\n (_a = engine._debugPopGroup) === null || _a === void 0 ? void 0 : _a.call(engine, 1);\n });\n let saveClipPlane;\n this.onBeforeRenderObservable.add(() => {\n if (this._sceneUBO) {\n this._currentSceneUBO = scene.getSceneUniformBuffer();\n scene.setSceneUniformBuffer(this._sceneUBO);\n scene.getSceneUniformBuffer().unbindEffect();\n }\n Matrix.ReflectionToRef(this.mirrorPlane, this._mirrorMatrix);\n this._mirrorMatrix.multiplyToRef(scene.getViewMatrix(), this._transformMatrix);\n scene.setTransformMatrix(this._transformMatrix, scene.getProjectionMatrix());\n saveClipPlane = scene.clipPlane;\n scene.clipPlane = this.mirrorPlane;\n scene._mirroredCameraPosition = Vector3.TransformCoordinates(scene.activeCamera.globalPosition, this._mirrorMatrix);\n });\n this.onAfterRenderObservable.add(() => {\n if (this._sceneUBO) {\n scene.setSceneUniformBuffer(this._currentSceneUBO);\n }\n scene.updateTransformMatrix();\n scene._mirroredCameraPosition = null;\n scene.clipPlane = saveClipPlane;\n });\n }\n _preparePostProcesses() {\n this.clearPostProcesses(true);\n if (this._blurKernelX && this._blurKernelY) {\n const engine = this.getScene().getEngine();\n const textureType = engine.getCaps().textureFloatRender && engine.getCaps().textureFloatLinearFiltering ? 1 : 2;\n this._blurX = new BlurPostProcess(\"horizontal blur\", new Vector2(1.0, 0), this._blurKernelX, this._blurRatio, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, textureType);\n this._blurX.autoClear = false;\n if (this._blurRatio === 1 && this.samples < 2 && this._texture) {\n this._blurX.inputTexture = this._renderTarget;\n }\n else {\n this._blurX.alwaysForcePOT = true;\n }\n this._blurY = new BlurPostProcess(\"vertical blur\", new Vector2(0, 1.0), this._blurKernelY, this._blurRatio, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, textureType);\n this._blurY.autoClear = false;\n this._blurY.alwaysForcePOT = this._blurRatio !== 1;\n this.addPostProcess(this._blurX);\n this.addPostProcess(this._blurY);\n }\n else {\n if (this._blurY) {\n this.removePostProcess(this._blurY);\n this._blurY.dispose();\n this._blurY = null;\n }\n if (this._blurX) {\n this.removePostProcess(this._blurX);\n this._blurX.dispose();\n this._blurX = null;\n }\n }\n }\n /**\n * Clone the mirror texture.\n * @returns the cloned texture\n */\n clone() {\n const scene = this.getScene();\n if (!scene) {\n return this;\n }\n const textureSize = this.getSize();\n const newTexture = new MirrorTexture(this.name, textureSize.width, scene, this._renderTargetOptions.generateMipMaps, this._renderTargetOptions.type, this._renderTargetOptions.samplingMode, this._renderTargetOptions.generateDepthBuffer);\n // Base texture\n newTexture.hasAlpha = this.hasAlpha;\n newTexture.level = this.level;\n // Mirror Texture\n newTexture.mirrorPlane = this.mirrorPlane.clone();\n if (this.renderList) {\n newTexture.renderList = this.renderList.slice(0);\n }\n return newTexture;\n }\n /**\n * Serialize the texture to a JSON representation you could use in Parse later on\n * @returns the serialized JSON representation\n */\n serialize() {\n if (!this.name) {\n return null;\n }\n const serializationObject = super.serialize();\n serializationObject.mirrorPlane = this.mirrorPlane.asArray();\n return serializationObject;\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n var _a;\n super.dispose();\n const scene = this.getScene();\n if (scene) {\n scene.imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingConfigChangeObserver);\n }\n (_a = this._sceneUBO) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n }\n Texture._CreateMirror = (name, renderTargetSize, scene, generateMipMaps) => {\n return new MirrorTexture(name, renderTargetSize, scene, generateMipMaps);\n };\n\n ThinEngine.prototype._createDepthStencilCubeTexture = function (size, options, rtWrapper) {\n const internalTexture = new InternalTexture(this, InternalTextureSource.DepthStencil);\n internalTexture.isCube = true;\n if (this.webGLVersion === 1) {\n Logger.Error(\"Depth cube texture is not supported by WebGL 1.\");\n return internalTexture;\n }\n const internalOptions = Object.assign({ bilinearFiltering: false, comparisonFunction: 0, generateStencil: false }, options);\n const gl = this._gl;\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, internalTexture, true);\n this._setupDepthStencilTexture(internalTexture, size, internalOptions.generateStencil, internalOptions.bilinearFiltering, internalOptions.comparisonFunction);\n rtWrapper._depthStencilTexture = internalTexture;\n rtWrapper._depthStencilTextureWithStencil = internalOptions.generateStencil;\n // Create the depth/stencil buffer\n for (let face = 0; face < 6; face++) {\n if (internalOptions.generateStencil) {\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, gl.DEPTH24_STENCIL8, size, size, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, null);\n }\n else {\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, gl.DEPTH_COMPONENT24, size, size, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);\n }\n }\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n this._internalTexturesCache.push(internalTexture);\n return internalTexture;\n };\n ThinEngine.prototype._partialLoadFile = function (url, index, loadedFiles, onfinish, onErrorCallBack = null) {\n const onload = (data) => {\n loadedFiles[index] = data;\n loadedFiles._internalCount++;\n if (loadedFiles._internalCount === 6) {\n onfinish(loadedFiles);\n }\n };\n const onerror = (request, exception) => {\n if (onErrorCallBack && request) {\n onErrorCallBack(request.status + \" \" + request.statusText, exception);\n }\n };\n this._loadFile(url, onload, undefined, undefined, true, onerror);\n };\n ThinEngine.prototype._cascadeLoadFiles = function (scene, onfinish, files, onError = null) {\n const loadedFiles = [];\n loadedFiles._internalCount = 0;\n for (let index = 0; index < 6; index++) {\n this._partialLoadFile(files[index], index, loadedFiles, onfinish, onError);\n }\n };\n ThinEngine.prototype._cascadeLoadImgs = function (scene, texture, onfinish, files, onError = null, mimeType) {\n const loadedImages = [];\n loadedImages._internalCount = 0;\n for (let index = 0; index < 6; index++) {\n this._partialLoadImg(files[index], index, loadedImages, scene, texture, onfinish, onError, mimeType);\n }\n };\n ThinEngine.prototype._partialLoadImg = function (url, index, loadedImages, scene, texture, onfinish, onErrorCallBack = null, mimeType) {\n const tokenPendingData = RandomGUID();\n const onload = (img) => {\n loadedImages[index] = img;\n loadedImages._internalCount++;\n if (scene) {\n scene.removePendingData(tokenPendingData);\n }\n if (loadedImages._internalCount === 6 && onfinish) {\n onfinish(texture, loadedImages);\n }\n };\n const onerror = (message, exception) => {\n if (scene) {\n scene.removePendingData(tokenPendingData);\n }\n if (onErrorCallBack) {\n onErrorCallBack(message, exception);\n }\n };\n LoadImage(url, onload, onerror, scene ? scene.offlineProvider : null, mimeType);\n if (scene) {\n scene.addPendingData(tokenPendingData);\n }\n };\n ThinEngine.prototype._setCubeMapTextureParams = function (texture, loadMipmap, maxLevel) {\n const gl = this._gl;\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, loadMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n texture.samplingMode = loadMipmap ? 3 : 2;\n if (loadMipmap && this.getCaps().textureMaxLevel && maxLevel !== undefined && maxLevel > 0) {\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAX_LEVEL, maxLevel);\n texture._maxLodLevel = maxLevel;\n }\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n };\n ThinEngine.prototype.createCubeTextureBase = function (rootUrl, scene, files, noMipmap, onLoad = null, onError = null, format, forcedExtension = null, createPolynomials = false, lodScale = 0, lodOffset = 0, fallback = null, beforeLoadCubeDataCallback = null, imageHandler = null, useSRGBBuffer = false) {\n const texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube);\n texture.isCube = true;\n texture.url = rootUrl;\n texture.generateMipMaps = !noMipmap;\n texture._lodGenerationScale = lodScale;\n texture._lodGenerationOffset = lodOffset;\n texture._useSRGBBuffer = !!useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU || !!noMipmap);\n if (texture !== fallback) {\n texture.label = rootUrl.substring(0, 60); // default label, can be overriden by the caller\n }\n if (!this._doNotHandleContextLost) {\n texture._extension = forcedExtension;\n texture._files = files;\n }\n const originalRootUrl = rootUrl;\n if (this._transformTextureUrl && !fallback) {\n rootUrl = this._transformTextureUrl(rootUrl);\n }\n const rootUrlWithoutUriParams = rootUrl.split(\"?\")[0];\n const lastDot = rootUrlWithoutUriParams.lastIndexOf(\".\");\n const extension = forcedExtension ? forcedExtension : lastDot > -1 ? rootUrlWithoutUriParams.substring(lastDot).toLowerCase() : \"\";\n let loader = null;\n for (const availableLoader of ThinEngine._TextureLoaders) {\n if (availableLoader.canLoad(extension)) {\n loader = availableLoader;\n break;\n }\n }\n const onInternalError = (request, exception) => {\n if (rootUrl === originalRootUrl) {\n if (onError && request) {\n onError(request.status + \" \" + request.statusText, exception);\n }\n }\n else {\n // fall back to the original url if the transformed url fails to load\n Logger.Warn(`Failed to load ${rootUrl}, falling back to the ${originalRootUrl}`);\n this.createCubeTextureBase(originalRootUrl, scene, files, !!noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, texture, beforeLoadCubeDataCallback, imageHandler, useSRGBBuffer);\n }\n };\n if (loader) {\n const onloaddata = (data) => {\n if (beforeLoadCubeDataCallback) {\n beforeLoadCubeDataCallback(texture, data);\n }\n loader.loadCubeData(data, texture, createPolynomials, onLoad, onError);\n };\n if (files && files.length === 6) {\n if (loader.supportCascades) {\n this._cascadeLoadFiles(scene, (images) => onloaddata(images.map((image) => new Uint8Array(image))), files, onError);\n }\n else {\n if (onError) {\n onError(\"Textures type does not support cascades.\");\n }\n else {\n Logger.Warn(\"Texture loader does not support cascades.\");\n }\n }\n }\n else {\n this._loadFile(rootUrl, (data) => onloaddata(new Uint8Array(data)), undefined, undefined, true, onInternalError);\n }\n }\n else {\n if (!files) {\n throw new Error(\"Cannot load cubemap because files were not defined\");\n }\n this._cascadeLoadImgs(scene, texture, (texture, imgs) => {\n if (imageHandler) {\n imageHandler(texture, imgs);\n }\n }, files, onError);\n }\n this._internalTexturesCache.push(texture);\n return texture;\n };\n ThinEngine.prototype.createCubeTexture = function (rootUrl, scene, files, noMipmap, onLoad = null, onError = null, format, forcedExtension = null, createPolynomials = false, lodScale = 0, lodOffset = 0, fallback = null, loaderOptions, useSRGBBuffer = false) {\n const gl = this._gl;\n return this.createCubeTextureBase(rootUrl, scene, files, !!noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, fallback, (texture) => this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true), (texture, imgs) => {\n const width = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(imgs[0].width, this._caps.maxCubemapTextureSize) : imgs[0].width;\n const height = width;\n const faces = [\n gl.TEXTURE_CUBE_MAP_POSITIVE_X,\n gl.TEXTURE_CUBE_MAP_POSITIVE_Y,\n gl.TEXTURE_CUBE_MAP_POSITIVE_Z,\n gl.TEXTURE_CUBE_MAP_NEGATIVE_X,\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,\n ];\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\n this._unpackFlipY(false);\n const internalFormat = format ? this._getInternalFormat(format, texture._useSRGBBuffer) : texture._useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : gl.RGBA;\n let texelFormat = format ? this._getInternalFormat(format) : gl.RGBA;\n if (texture._useSRGBBuffer && this.webGLVersion === 1) {\n texelFormat = internalFormat;\n }\n for (let index = 0; index < faces.length; index++) {\n if (imgs[index].width !== width || imgs[index].height !== height) {\n this._prepareWorkingCanvas();\n if (!this._workingCanvas || !this._workingContext) {\n Logger.Warn(\"Cannot create canvas to resize texture.\");\n return;\n }\n this._workingCanvas.width = width;\n this._workingCanvas.height = height;\n this._workingContext.drawImage(imgs[index], 0, 0, imgs[index].width, imgs[index].height, 0, 0, width, height);\n gl.texImage2D(faces[index], 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, this._workingCanvas);\n }\n else {\n gl.texImage2D(faces[index], 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, imgs[index]);\n }\n }\n if (!noMipmap) {\n gl.generateMipmap(gl.TEXTURE_CUBE_MAP);\n }\n this._setCubeMapTextureParams(texture, !noMipmap);\n texture.width = width;\n texture.height = height;\n texture.isReady = true;\n if (format) {\n texture.format = format;\n }\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n if (onLoad) {\n onLoad();\n }\n }, !!useSRGBBuffer);\n };\n\n /**\n * Class for creating a cube texture\n */\n class CubeTexture extends BaseTexture {\n /**\n * Gets or sets the size of the bounding box associated with the cube texture\n * When defined, the cubemap will switch to local mode\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\n * @example https://www.babylonjs-playground.com/#RNASML\n */\n set boundingBoxSize(value) {\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\n return;\n }\n this._boundingBoxSize = value;\n const scene = this.getScene();\n if (scene) {\n scene.markAllMaterialsAsDirty(1);\n }\n }\n /**\n * Returns the bounding box size\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#using-local-cubemap-mode\n */\n get boundingBoxSize() {\n return this._boundingBoxSize;\n }\n /**\n * Sets texture matrix rotation angle around Y axis in radians.\n */\n set rotationY(value) {\n this._rotationY = value;\n this.setReflectionTextureMatrix(Matrix.RotationY(this._rotationY));\n }\n /**\n * Gets texture matrix rotation angle around Y axis radians.\n */\n get rotationY() {\n return this._rotationY;\n }\n /**\n * Are mip maps generated for this texture or not.\n */\n get noMipmap() {\n return this._noMipmap;\n }\n /**\n * Gets the forced extension (if any)\n */\n get forcedExtension() {\n return this._forcedExtension;\n }\n /**\n * Creates a cube texture from an array of image urls\n * @param files defines an array of image urls\n * @param scene defines the hosting scene\n * @param noMipmap specifies if mip maps are not used\n * @returns a cube texture\n */\n static CreateFromImages(files, scene, noMipmap) {\n let rootUrlKey = \"\";\n files.forEach((url) => (rootUrlKey += url));\n return new CubeTexture(rootUrlKey, scene, null, noMipmap, files);\n }\n /**\n * Creates and return a texture created from prefilterd data by tools like IBL Baker or Lys.\n * @param url defines the url of the prefiltered texture\n * @param scene defines the scene the texture is attached to\n * @param forcedExtension defines the extension of the file if different from the url\n * @param createPolynomials defines whether or not to create polynomial harmonics from the texture data if necessary\n * @returns the prefiltered texture\n */\n static CreateFromPrefilteredData(url, scene, forcedExtension = null, createPolynomials = true) {\n const oldValue = scene.useDelayedTextureLoading;\n scene.useDelayedTextureLoading = false;\n const result = new CubeTexture(url, scene, null, false, null, null, null, undefined, true, forcedExtension, createPolynomials);\n scene.useDelayedTextureLoading = oldValue;\n return result;\n }\n /**\n * Creates a cube texture to use with reflection for instance. It can be based upon dds or six images as well\n * as prefiltered data.\n * @param rootUrl defines the url of the texture or the root name of the six images\n * @param sceneOrEngine defines the scene or engine the texture is attached to\n * @param extensions defines the suffixes add to the picture name in case six images are in use like _px.jpg...\n * @param noMipmap defines if mipmaps should be created or not\n * @param files defines the six files to load for the different faces in that order: px, py, pz, nx, ny, nz\n * @param onLoad defines a callback triggered at the end of the file load if no errors occurred\n * @param onError defines a callback triggered in case of error during load\n * @param format defines the internal format to use for the texture once loaded\n * @param prefiltered defines whether or not the texture is created from prefiltered data\n * @param forcedExtension defines the extensions to use (force a special type of file to load) in case it is different from the file name\n * @param createPolynomials defines whether or not to create polynomial harmonics from the texture data if necessary\n * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness\n * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness\n * @param loaderOptions options to be passed to the loader\n * @param useSRGBBuffer Defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU) (default: false)\n * @returns the cube texture\n */\n constructor(rootUrl, sceneOrEngine, extensions = null, noMipmap = false, files = null, onLoad = null, onError = null, format = 5, prefiltered = false, forcedExtension = null, createPolynomials = false, lodScale = 0.8, lodOffset = 0, loaderOptions, useSRGBBuffer) {\n var _a;\n super(sceneOrEngine);\n this._lodScale = 0.8;\n this._lodOffset = 0;\n /**\n * Observable triggered once the texture has been loaded.\n */\n this.onLoadObservable = new Observable$1();\n /**\n * Gets or sets the center of the bounding box associated with the cube texture.\n * It must define where the camera used to render the texture was set\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#using-local-cubemap-mode\n */\n this.boundingBoxPosition = Vector3.Zero();\n this._rotationY = 0;\n /** @internal */\n this._files = null;\n this._forcedExtension = null;\n this._extensions = null;\n this._textureMatrixRefraction = new Matrix();\n this.name = rootUrl;\n this.url = rootUrl;\n this._noMipmap = noMipmap;\n this.hasAlpha = false;\n this._format = format;\n this.isCube = true;\n this._textureMatrix = Matrix.Identity();\n this._createPolynomials = createPolynomials;\n this.coordinatesMode = Texture.CUBIC_MODE;\n this._extensions = extensions;\n this._files = files;\n this._forcedExtension = forcedExtension;\n this._loaderOptions = loaderOptions;\n this._useSRGBBuffer = useSRGBBuffer;\n this._lodScale = lodScale;\n this._lodOffset = lodOffset;\n if (!rootUrl && !files) {\n return;\n }\n this.updateURL(rootUrl, forcedExtension, onLoad, prefiltered, onError, extensions, (_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.useDelayedTextureLoading, files);\n }\n /**\n * Get the current class name of the texture useful for serialization or dynamic coding.\n * @returns \"CubeTexture\"\n */\n getClassName() {\n return \"CubeTexture\";\n }\n /**\n * Update the url (and optional buffer) of this texture if url was null during construction.\n * @param url the url of the texture\n * @param forcedExtension defines the extension to use\n * @param onLoad callback called when the texture is loaded (defaults to null)\n * @param prefiltered Defines whether the updated texture is prefiltered or not\n * @param onError callback called if there was an error during the loading process (defaults to null)\n * @param extensions defines the suffixes add to the picture name in case six images are in use like _px.jpg...\n * @param delayLoad defines if the texture should be loaded now (false by default)\n * @param files defines the six files to load for the different faces in that order: px, py, pz, nx, ny, nz\n */\n updateURL(url, forcedExtension, onLoad = null, prefiltered = false, onError = null, extensions = null, delayLoad = false, files = null) {\n if (!this.name || this.name.startsWith(\"data:\")) {\n this.name = url;\n }\n this.url = url;\n if (forcedExtension) {\n this._forcedExtension = forcedExtension;\n }\n const lastDot = url.lastIndexOf(\".\");\n const extension = forcedExtension ? forcedExtension : lastDot > -1 ? url.substring(lastDot).toLowerCase() : \"\";\n const isDDS = extension.indexOf(\".dds\") === 0;\n const isEnv = extension.indexOf(\".env\") === 0;\n const isBasis = extension.indexOf(\".basis\") === 0;\n if (isEnv) {\n this.gammaSpace = false;\n this._prefiltered = false;\n this.anisotropicFilteringLevel = 1;\n }\n else {\n this._prefiltered = prefiltered;\n if (prefiltered) {\n this.gammaSpace = false;\n this.anisotropicFilteringLevel = 1;\n }\n }\n if (files) {\n this._files = files;\n }\n else {\n if (!isBasis && !isEnv && !isDDS && !extensions) {\n extensions = [\"_px.jpg\", \"_py.jpg\", \"_pz.jpg\", \"_nx.jpg\", \"_ny.jpg\", \"_nz.jpg\"];\n }\n this._files = this._files || [];\n this._files.length = 0;\n if (extensions) {\n for (let index = 0; index < extensions.length; index++) {\n this._files.push(url + extensions[index]);\n }\n this._extensions = extensions;\n }\n }\n if (delayLoad) {\n this.delayLoadState = 4;\n this._delayedOnLoad = onLoad;\n this._delayedOnError = onError;\n }\n else {\n this._loadTexture(onLoad, onError);\n }\n }\n /**\n * Delays loading of the cube texture\n * @param forcedExtension defines the extension to use\n */\n delayLoad(forcedExtension) {\n if (this.delayLoadState !== 4) {\n return;\n }\n if (forcedExtension) {\n this._forcedExtension = forcedExtension;\n }\n this.delayLoadState = 1;\n this._loadTexture(this._delayedOnLoad, this._delayedOnError);\n }\n /**\n * Returns the reflection texture matrix\n * @returns the reflection texture matrix\n */\n getReflectionTextureMatrix() {\n return this._textureMatrix;\n }\n /**\n * Sets the reflection texture matrix\n * @param value Reflection texture matrix\n */\n setReflectionTextureMatrix(value) {\n var _a, _b;\n if (value.updateFlag === this._textureMatrix.updateFlag) {\n return;\n }\n if (value.isIdentity() !== this._textureMatrix.isIdentity()) {\n (_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.markAllMaterialsAsDirty(1, (mat) => mat.getActiveTextures().indexOf(this) !== -1);\n }\n this._textureMatrix = value;\n if (!((_b = this.getScene()) === null || _b === void 0 ? void 0 : _b.useRightHandedSystem)) {\n return;\n }\n const scale = TmpVectors.Vector3[0];\n const quat = TmpVectors.Quaternion[0];\n const trans = TmpVectors.Vector3[1];\n this._textureMatrix.decompose(scale, quat, trans);\n quat.z *= -1; // these two operations correspond to negating the x and y euler angles\n quat.w *= -1;\n Matrix.ComposeToRef(scale, quat, trans, this._textureMatrixRefraction);\n }\n /**\n * Gets a suitable rotate/transform matrix when the texture is used for refraction.\n * There's a separate function from getReflectionTextureMatrix because refraction requires a special configuration of the matrix in right-handed mode.\n * @returns The refraction matrix\n */\n getRefractionTextureMatrix() {\n var _a;\n return ((_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.useRightHandedSystem) ? this._textureMatrixRefraction : this._textureMatrix;\n }\n _loadTexture(onLoad = null, onError = null) {\n var _a;\n const scene = this.getScene();\n const oldTexture = this._texture;\n this._texture = this._getFromCache(this.url, this._noMipmap, undefined, undefined, this._useSRGBBuffer, this.isCube);\n const onLoadProcessing = () => {\n var _a;\n this.onLoadObservable.notifyObservers(this);\n if (oldTexture) {\n oldTexture.dispose();\n (_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.markAllMaterialsAsDirty(1);\n }\n if (onLoad) {\n onLoad();\n }\n };\n const errorHandler = (message, exception) => {\n this._loadingError = true;\n this._errorObject = { message, exception };\n if (onError) {\n onError(message, exception);\n }\n Texture.OnTextureLoadErrorObservable.notifyObservers(this);\n };\n if (!this._texture) {\n if (this._prefiltered) {\n this._texture = this._getEngine().createPrefilteredCubeTexture(this.url, scene, this._lodScale, this._lodOffset, onLoad, errorHandler, this._format, this._forcedExtension, this._createPolynomials);\n }\n else {\n this._texture = this._getEngine().createCubeTexture(this.url, scene, this._files, this._noMipmap, onLoad, errorHandler, this._format, this._forcedExtension, false, this._lodScale, this._lodOffset, null, this._loaderOptions, !!this._useSRGBBuffer);\n }\n (_a = this._texture) === null || _a === void 0 ? void 0 : _a.onLoadedObservable.add(() => this.onLoadObservable.notifyObservers(this));\n }\n else {\n if (this._texture.isReady) {\n Tools.SetImmediate(() => onLoadProcessing());\n }\n else {\n this._texture.onLoadedObservable.add(() => onLoadProcessing());\n }\n }\n }\n /**\n * Parses text to create a cube texture\n * @param parsedTexture define the serialized text to read from\n * @param scene defines the hosting scene\n * @param rootUrl defines the root url of the cube texture\n * @returns a cube texture\n */\n static Parse(parsedTexture, scene, rootUrl) {\n const texture = SerializationHelper.Parse(() => {\n var _a;\n let prefiltered = false;\n if (parsedTexture.prefiltered) {\n prefiltered = parsedTexture.prefiltered;\n }\n return new CubeTexture(rootUrl + ((_a = parsedTexture.url) !== null && _a !== void 0 ? _a : parsedTexture.name), scene, parsedTexture.extensions, false, parsedTexture.files || null, null, null, undefined, prefiltered, parsedTexture.forcedExtension);\n }, parsedTexture, scene);\n // Local Cubemaps\n if (parsedTexture.boundingBoxPosition) {\n texture.boundingBoxPosition = Vector3.FromArray(parsedTexture.boundingBoxPosition);\n }\n if (parsedTexture.boundingBoxSize) {\n texture.boundingBoxSize = Vector3.FromArray(parsedTexture.boundingBoxSize);\n }\n // Animations\n if (parsedTexture.animations) {\n for (let animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {\n const parsedAnimation = parsedTexture.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n texture.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n }\n return texture;\n }\n /**\n * Makes a clone, or deep copy, of the cube texture\n * @returns a new cube texture\n */\n clone() {\n let uniqueId = 0;\n const newCubeTexture = SerializationHelper.Clone(() => {\n const cubeTexture = new CubeTexture(this.url, this.getScene() || this._getEngine(), this._extensions, this._noMipmap, this._files);\n uniqueId = cubeTexture.uniqueId;\n return cubeTexture;\n }, this);\n newCubeTexture.uniqueId = uniqueId;\n return newCubeTexture;\n }\n }\n __decorate$1([\n serialize()\n ], CubeTexture.prototype, \"url\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], CubeTexture.prototype, \"boundingBoxPosition\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], CubeTexture.prototype, \"boundingBoxSize\", null);\n __decorate$1([\n serialize(\"rotationY\")\n ], CubeTexture.prototype, \"rotationY\", null);\n __decorate$1([\n serialize(\"files\")\n ], CubeTexture.prototype, \"_files\", void 0);\n __decorate$1([\n serialize(\"forcedExtension\")\n ], CubeTexture.prototype, \"_forcedExtension\", void 0);\n __decorate$1([\n serialize(\"extensions\")\n ], CubeTexture.prototype, \"_extensions\", void 0);\n __decorate$1([\n serializeAsMatrix(\"textureMatrix\")\n ], CubeTexture.prototype, \"_textureMatrix\", void 0);\n __decorate$1([\n serializeAsMatrix(\"textureMatrixRefraction\")\n ], CubeTexture.prototype, \"_textureMatrixRefraction\", void 0);\n Texture._CubeTextureParser = CubeTexture.Parse;\n // Some exporters relies on Tools.Instantiate\n RegisterClass(\"BABYLON.CubeTexture\", CubeTexture);\n\n // Do not edit.\n const name$1O = \"backgroundFragmentDeclaration\";\n const shader$1O = `uniform vec4 vEyePosition;uniform vec4 vPrimaryColor;\n#ifdef USEHIGHLIGHTANDSHADOWCOLORS\nuniform vec4 vPrimaryColorShadow;\n#endif\nuniform float shadowLevel;uniform float alpha;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1O] = shader$1O;\n\n // Do not edit.\n const name$1P = \"backgroundUboDeclaration\";\n const shader$1P = `layout(std140,column_major) uniform;uniform Material\n{uniform vec4 vPrimaryColor;uniform vec4 vPrimaryColorShadow;uniform vec2 vDiffuseInfos;uniform vec2 vReflectionInfos;uniform mat4 diffuseMatrix;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;uniform float fFovMultiplier;uniform float pointSize;uniform float shadowLevel;uniform float alpha;\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n};\n#include\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1P] = shader$1P;\n\n // Do not edit.\n const name$1Q = \"backgroundPixelShader\";\n const shader$1Q = `#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n#include\n#define RECIPROCAL_PI2 0.15915494\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV==1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV==2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{float weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);return reflectance0+weight*(reflectance90-reflectance0)*pow5(saturate(1.0-VdotN));}\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\nfloat shadow=1.;float globalShadow=0.;float shadowLightCount=0.;\n#include[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n#ifndef BACKMAT_SHADOWONLY\nvec4 reflectionColor=vec4(1.,1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;reflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);\n#else\nfloat lodReflectionNormalized=saturate(reflectionLOD);float lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;vec4 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords);if(lodReflectionNormalizedDoubled<1.0){reflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords),\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);} else {reflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords),\nlodReflectionNormalizedDoubled-1.0\n);}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);reflectionColor=reflectionSample;\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor.rgb=toLinearSpace(reflectionColor.rgb);\n#endif\n#ifdef REFLECTIONBGR\nreflectionColor.rgb=reflectionColor.bgr;\n#endif\nreflectionColor.rgb*=vReflectionInfos.x;\n#endif\nvec3 diffuseColor=vec3(1.,1.,1.);float finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor.rgb*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\n#ifdef USEHIGHLIGHTANDSHADOWCOLORS\nvec3 mainColor=mix(vPrimaryColorShadow.rgb,vPrimaryColor.rgb,colorBase);\n#else\nvec3 mainColor=vPrimaryColor.rgb;\n#endif\nvec3 finalColor=colorBase*mainColor;\n#endif\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;vec3 reflectionReflectance0=vReflectionControl.yyy;vec3 reflectionReflectance90=vReflectionControl.zzz;float VdotN=dot(normalize(vEyePosition.xyz),normalW);vec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(saturate(VdotN),reflectionReflectance0,reflectionReflectance90,1.0);reflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-saturate(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w);reflectionDistanceFalloff*=reflectionDistanceFalloff;reflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor.rgb,saturate(reflectionAmount));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition.xyz-vBackgroundCenter));const float startAngle=0.1;float fadeFactor=saturate(viewAngleToFloor/startAngle);finalAlpha*=fadeFactor*fadeFactor;\n#endif\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\nvec4 color=vec4(finalColor,finalAlpha);\n#else\nvec4 color=vec4(vPrimaryColor.rgb,(1.0-clamp(globalShadow,0.,1.))*alpha);\n#endif\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n#if !defined(SKIPFINALCOLORCLAMP)\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#endif\n#else\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\ncolor.rgb*=color.a;\n#endif\n#ifdef NOISE\ncolor.rgb+=dither(vPositionW.xy,0.5);color=max(color,0.0);\n#endif\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1Q] = shader$1Q;\n\n // Do not edit.\n const name$1R = \"backgroundVertexDeclaration\";\n const shader$1R = `uniform mat4 view;uniform mat4 viewProjection;uniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;uniform float fFovMultiplier;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$1R] = shader$1R;\n\n // Do not edit.\n const name$1S = \"backgroundVertexShader\";\n const shader$1S = `precision highp float;\n#include<__decl__backgroundVertex>\n#include\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n#include\n#include\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV==0\nvarying vec2 vDiffuseUV;\n#endif\n#include\n#include\n#include<__decl__lightVxFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif\n#include\n#include\n#include\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*finalWorld*vec4(position,1.0);} else {gl_Position=viewProjectionR*finalWorld*vec4(position,1.0);}\n#else\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#endif\nvec4 worldPos=finalWorld*vec4(position,1.0);vPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#ifdef EQUIRECTANGULAR_RELFECTION_FOV\nmat3 screenToWorld=inverseMat3(mat3(finalWorld*viewProjection));vec3 segment=mix(vDirectionW,screenToWorld*vec3(0.0,0.0,1.0),abs(fFovMultiplier-1.0));if (fFovMultiplier<=1.0) {vDirectionW=normalize(segment);} else {vDirectionW=normalize(vDirectionW+(vDirectionW-segment));}\n#endif\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV==0\nif (vDiffuseInfos.x==0.)\n{vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));}\nelse\n{vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));}\n#endif\n#include\n#include\n#include[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1S] = shader$1S;\n\n /**\n * Background material defines definition.\n * @internal Mainly internal Use\n */\n class BackgroundMaterialDefines extends MaterialDefines {\n /**\n * Constructor of the defines.\n */\n constructor() {\n super();\n /**\n * True if the diffuse texture is in use.\n */\n this.DIFFUSE = false;\n /**\n * The direct UV channel to use.\n */\n this.DIFFUSEDIRECTUV = 0;\n /**\n * True if the diffuse texture is in gamma space.\n */\n this.GAMMADIFFUSE = false;\n /**\n * True if the diffuse texture has opacity in the alpha channel.\n */\n this.DIFFUSEHASALPHA = false;\n /**\n * True if you want the material to fade to transparent at grazing angle.\n */\n this.OPACITYFRESNEL = false;\n /**\n * True if an extra blur needs to be added in the reflection.\n */\n this.REFLECTIONBLUR = false;\n /**\n * True if you want the material to fade to reflection at grazing angle.\n */\n this.REFLECTIONFRESNEL = false;\n /**\n * True if you want the material to falloff as far as you move away from the scene center.\n */\n this.REFLECTIONFALLOFF = false;\n /**\n * False if the current Webgl implementation does not support the texture lod extension.\n */\n this.TEXTURELODSUPPORT = false;\n /**\n * True to ensure the data are premultiplied.\n */\n this.PREMULTIPLYALPHA = false;\n /**\n * True if the texture contains cooked RGB values and not gray scaled multipliers.\n */\n this.USERGBCOLOR = false;\n /**\n * True if highlight and shadow levels have been specified. It can help ensuring the main perceived color\n * stays aligned with the desired configuration.\n */\n this.USEHIGHLIGHTANDSHADOWCOLORS = false;\n /**\n * True if only shadows must be rendered\n */\n this.BACKMAT_SHADOWONLY = false;\n /**\n * True to add noise in order to reduce the banding effect.\n */\n this.NOISE = false;\n /**\n * is the reflection texture in BGR color scheme?\n * Mainly used to solve a bug in ios10 video tag\n */\n this.REFLECTIONBGR = false;\n this.IMAGEPROCESSING = false;\n this.VIGNETTE = false;\n this.VIGNETTEBLENDMODEMULTIPLY = false;\n this.VIGNETTEBLENDMODEOPAQUE = false;\n this.TONEMAPPING = false;\n this.TONEMAPPING_ACES = false;\n this.CONTRAST = false;\n this.COLORCURVES = false;\n this.COLORGRADING = false;\n this.COLORGRADING3D = false;\n this.SAMPLER3DGREENDEPTH = false;\n this.SAMPLER3DBGRMAP = false;\n this.DITHER = false;\n this.IMAGEPROCESSINGPOSTPROCESS = false;\n this.SKIPFINALCOLORCLAMP = false;\n this.EXPOSURE = false;\n this.MULTIVIEW = false;\n // Reflection.\n this.REFLECTION = false;\n this.REFLECTIONMAP_3D = false;\n this.REFLECTIONMAP_SPHERICAL = false;\n this.REFLECTIONMAP_PLANAR = false;\n this.REFLECTIONMAP_CUBIC = false;\n this.REFLECTIONMAP_PROJECTION = false;\n this.REFLECTIONMAP_SKYBOX = false;\n this.REFLECTIONMAP_EXPLICIT = false;\n this.REFLECTIONMAP_EQUIRECTANGULAR = false;\n this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\n this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\n this.INVERTCUBICMAP = false;\n this.REFLECTIONMAP_OPPOSITEZ = false;\n this.LODINREFLECTIONALPHA = false;\n this.GAMMAREFLECTION = false;\n this.RGBDREFLECTION = false;\n this.EQUIRECTANGULAR_RELFECTION_FOV = false;\n // Default BJS.\n this.MAINUV1 = false;\n this.MAINUV2 = false;\n this.UV1 = false;\n this.UV2 = false;\n this.CLIPPLANE = false;\n this.CLIPPLANE2 = false;\n this.CLIPPLANE3 = false;\n this.CLIPPLANE4 = false;\n this.CLIPPLANE5 = false;\n this.CLIPPLANE6 = false;\n this.POINTSIZE = false;\n this.FOG = false;\n this.NORMAL = false;\n this.NUM_BONE_INFLUENCERS = 0;\n this.BonesPerMesh = 0;\n this.INSTANCES = false;\n this.SHADOWFLOAT = false;\n this.LOGARITHMICDEPTH = false;\n this.NONUNIFORMSCALING = false;\n this.ALPHATEST = false;\n this.rebuild();\n }\n }\n /**\n * Background material used to create an efficient environment around your scene.\n */\n class BackgroundMaterial extends PushMaterial {\n /**\n * Experimental Internal Use Only.\n *\n * Key light Color in \"perceptual value\" meaning the color you would like to see on screen.\n * This acts as a helper to set the primary color to a more \"human friendly\" value.\n * Conversion to linear space as well as exposure and tone mapping correction will be applied to keep the\n * output color as close as possible from the chosen value.\n * (This does not account for contrast color grading and color curves as they are considered post effect and not directly\n * part of lighting setup.)\n */\n get _perceptualColor() {\n return this.__perceptualColor;\n }\n set _perceptualColor(value) {\n this.__perceptualColor = value;\n this._computePrimaryColorFromPerceptualColor();\n this._markAllSubMeshesAsLightsDirty();\n }\n /**\n * Defines the level of the shadows (dark area of the reflection map) in order to help scaling the colors.\n * The color opposite to the primary color is used at the level chosen to define what the black area would look.\n */\n get primaryColorShadowLevel() {\n return this._primaryColorShadowLevel;\n }\n set primaryColorShadowLevel(value) {\n this._primaryColorShadowLevel = value;\n this._computePrimaryColors();\n this._markAllSubMeshesAsLightsDirty();\n }\n /**\n * Defines the level of the highlights (highlight area of the reflection map) in order to help scaling the colors.\n * The primary color is used at the level chosen to define what the white area would look.\n */\n get primaryColorHighlightLevel() {\n return this._primaryColorHighlightLevel;\n }\n set primaryColorHighlightLevel(value) {\n this._primaryColorHighlightLevel = value;\n this._computePrimaryColors();\n this._markAllSubMeshesAsLightsDirty();\n }\n /**\n * Sets the reflection reflectance fresnel values according to the default standard\n * empirically know to work well :-)\n */\n set reflectionStandardFresnelWeight(value) {\n let reflectionWeight = value;\n if (reflectionWeight < 0.5) {\n reflectionWeight = reflectionWeight * 2.0;\n this.reflectionReflectance0 = BackgroundMaterial.StandardReflectance0 * reflectionWeight;\n this.reflectionReflectance90 = BackgroundMaterial.StandardReflectance90 * reflectionWeight;\n }\n else {\n reflectionWeight = reflectionWeight * 2.0 - 1.0;\n this.reflectionReflectance0 = BackgroundMaterial.StandardReflectance0 + (1.0 - BackgroundMaterial.StandardReflectance0) * reflectionWeight;\n this.reflectionReflectance90 = BackgroundMaterial.StandardReflectance90 + (1.0 - BackgroundMaterial.StandardReflectance90) * reflectionWeight;\n }\n }\n /**\n * The current fov(field of view) multiplier, 0.0 - 2.0. Defaults to 1.0. Lower values \"zoom in\" and higher values \"zoom out\".\n * Best used when trying to implement visual zoom effects like fish-eye or binoculars while not adjusting camera fov.\n * Recommended to be keep at 1.0 except for special cases.\n */\n get fovMultiplier() {\n return this._fovMultiplier;\n }\n set fovMultiplier(value) {\n if (isNaN(value)) {\n value = 1.0;\n }\n this._fovMultiplier = Math.max(0.0, Math.min(2.0, value));\n }\n /**\n * Attaches a new image processing configuration to the PBR Material.\n * @param configuration (if null the scene configuration will be use)\n */\n _attachImageProcessingConfiguration(configuration) {\n if (configuration === this._imageProcessingConfiguration) {\n return;\n }\n // Detaches observer.\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n // Pick the scene configuration if needed.\n if (!configuration) {\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\n }\n else {\n this._imageProcessingConfiguration = configuration;\n }\n // Attaches observer.\n if (this._imageProcessingConfiguration) {\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\n this._computePrimaryColorFromPerceptualColor();\n this._markAllSubMeshesAsImageProcessingDirty();\n });\n }\n }\n /**\n * Gets the image processing configuration used either in this material.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Sets the Default image processing configuration used either in the this material.\n *\n * If sets to null, the scene one is in use.\n */\n set imageProcessingConfiguration(value) {\n this._attachImageProcessingConfiguration(value);\n // Ensure the effect will be rebuilt.\n this._markAllSubMeshesAsTexturesDirty();\n }\n /**\n * Gets whether the color curves effect is enabled.\n */\n get cameraColorCurvesEnabled() {\n return this.imageProcessingConfiguration.colorCurvesEnabled;\n }\n /**\n * Sets whether the color curves effect is enabled.\n */\n set cameraColorCurvesEnabled(value) {\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n get cameraColorGradingEnabled() {\n return this.imageProcessingConfiguration.colorGradingEnabled;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n set cameraColorGradingEnabled(value) {\n this.imageProcessingConfiguration.colorGradingEnabled = value;\n }\n /**\n * Gets whether tonemapping is enabled or not.\n */\n get cameraToneMappingEnabled() {\n return this._imageProcessingConfiguration.toneMappingEnabled;\n }\n /**\n * Sets whether tonemapping is enabled or not\n */\n set cameraToneMappingEnabled(value) {\n this._imageProcessingConfiguration.toneMappingEnabled = value;\n }\n /**\n * The camera exposure used on this material.\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\n * This corresponds to a photographic exposure.\n */\n get cameraExposure() {\n return this._imageProcessingConfiguration.exposure;\n }\n /**\n * The camera exposure used on this material.\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\n * This corresponds to a photographic exposure.\n */\n set cameraExposure(value) {\n this._imageProcessingConfiguration.exposure = value;\n }\n /**\n * Gets The camera contrast used on this material.\n */\n get cameraContrast() {\n return this._imageProcessingConfiguration.contrast;\n }\n /**\n * Sets The camera contrast used on this material.\n */\n set cameraContrast(value) {\n this._imageProcessingConfiguration.contrast = value;\n }\n /**\n * Gets the Color Grading 2D Lookup Texture.\n */\n get cameraColorGradingTexture() {\n return this._imageProcessingConfiguration.colorGradingTexture;\n }\n /**\n * Sets the Color Grading 2D Lookup Texture.\n */\n set cameraColorGradingTexture(value) {\n this.imageProcessingConfiguration.colorGradingTexture = value;\n }\n /**\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n get cameraColorCurves() {\n return this.imageProcessingConfiguration.colorCurves;\n }\n /**\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\n */\n set cameraColorCurves(value) {\n this.imageProcessingConfiguration.colorCurves = value;\n }\n /**\n * Instantiates a Background Material in the given scene\n * @param name The friendly name of the material\n * @param scene The scene to add the material to\n */\n constructor(name, scene) {\n super(name, scene);\n /**\n * Key light Color (multiply against the environment texture)\n */\n this.primaryColor = Color3.White();\n this._primaryColorShadowLevel = 0;\n this._primaryColorHighlightLevel = 0;\n /**\n * Reflection Texture used in the material.\n * Should be author in a specific way for the best result (refer to the documentation).\n */\n this.reflectionTexture = null;\n /**\n * Reflection Texture level of blur.\n *\n * Can be use to reuse an existing HDR Texture and target a specific LOD to prevent authoring the\n * texture twice.\n */\n this.reflectionBlur = 0;\n /**\n * Diffuse Texture used in the material.\n * Should be author in a specific way for the best result (refer to the documentation).\n */\n this.diffuseTexture = null;\n this._shadowLights = null;\n /**\n * Specify the list of lights casting shadow on the material.\n * All scene shadow lights will be included if null.\n */\n this.shadowLights = null;\n /**\n * Helps adjusting the shadow to a softer level if required.\n * 0 means black shadows and 1 means no shadows.\n */\n this.shadowLevel = 0;\n /**\n * In case of opacity Fresnel or reflection falloff, this is use as a scene center.\n * It is usually zero but might be interesting to modify according to your setup.\n */\n this.sceneCenter = Vector3.Zero();\n /**\n * This helps specifying that the material is falling off to the sky box at grazing angle.\n * This helps ensuring a nice transition when the camera goes under the ground.\n */\n this.opacityFresnel = true;\n /**\n * This helps specifying that the material is falling off from diffuse to the reflection texture at grazing angle.\n * This helps adding a mirror texture on the ground.\n */\n this.reflectionFresnel = false;\n /**\n * This helps specifying the falloff radius off the reflection texture from the sceneCenter.\n * This helps adding a nice falloff effect to the reflection if used as a mirror for instance.\n */\n this.reflectionFalloffDistance = 0.0;\n /**\n * This specifies the weight of the reflection against the background in case of reflection Fresnel.\n */\n this.reflectionAmount = 1.0;\n /**\n * This specifies the weight of the reflection at grazing angle.\n */\n this.reflectionReflectance0 = 0.05;\n /**\n * This specifies the weight of the reflection at a perpendicular point of view.\n */\n this.reflectionReflectance90 = 0.5;\n /**\n * Helps to directly use the maps channels instead of their level.\n */\n this.useRGBColor = true;\n /**\n * This helps reducing the banding effect that could occur on the background.\n */\n this.enableNoise = false;\n this._fovMultiplier = 1.0;\n /**\n * Enable the FOV adjustment feature controlled by fovMultiplier.\n */\n this.useEquirectangularFOV = false;\n this._maxSimultaneousLights = 4;\n /**\n * Number of Simultaneous lights allowed on the material.\n */\n this.maxSimultaneousLights = 4;\n this._shadowOnly = false;\n /**\n * Make the material only render shadows\n */\n this.shadowOnly = false;\n /**\n * Keep track of the image processing observer to allow dispose and replace.\n */\n this._imageProcessingObserver = null;\n /**\n * Due to a bug in iOS10, video tags (which are using the background material) are in BGR and not RGB.\n * Setting this flag to true (not done automatically!) will convert it back to RGB.\n */\n this.switchToBGR = false;\n // Temp values kept as cache in the material.\n this._renderTargets = new SmartArray(16);\n this._reflectionControls = Vector4.Zero();\n this._white = Color3.White();\n this._primaryShadowColor = Color3.Black();\n this._primaryHighlightColor = Color3.Black();\n // Setup the default processing configuration to the scene.\n this._attachImageProcessingConfiguration(null);\n this.getRenderTargetTextures = () => {\n this._renderTargets.reset();\n if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {\n this._renderTargets.push(this._diffuseTexture);\n }\n if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n this._renderTargets.push(this._reflectionTexture);\n }\n return this._renderTargets;\n };\n }\n /**\n * Gets a boolean indicating that current material needs to register RTT\n */\n get hasRenderTargetTextures() {\n if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {\n return true;\n }\n if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n return true;\n }\n return false;\n }\n /**\n * The entire material has been created in order to prevent overdraw.\n * @returns false\n */\n needAlphaTesting() {\n return true;\n }\n /**\n * The entire material has been created in order to prevent overdraw.\n * @returns true if blending is enable\n */\n needAlphaBlending() {\n return this.alpha < 1 || (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._shadowOnly;\n }\n /**\n * Checks whether the material is ready to be rendered for a given mesh.\n * @param mesh The mesh to render\n * @param subMesh The submesh to check against\n * @param useInstances Specify wether or not the material is used with instances\n * @returns true if all the dependencies are ready (Textures, Effects...)\n */\n isReadyForSubMesh(mesh, subMesh, useInstances = false) {\n if (subMesh.effect && this.isFrozen) {\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\n return true;\n }\n }\n if (!subMesh.materialDefines) {\n subMesh.materialDefines = new BackgroundMaterialDefines();\n }\n const scene = this.getScene();\n const defines = subMesh.materialDefines;\n if (this._isReadyForSubMesh(subMesh)) {\n return true;\n }\n const engine = scene.getEngine();\n // Lights\n MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);\n defines._needNormals = true;\n // Multiview\n MaterialHelper.PrepareDefinesForMultiview(scene, defines);\n // Textures\n if (defines._areTexturesDirty) {\n defines._needUVs = false;\n if (scene.texturesEnabled) {\n if (scene.getEngine().getCaps().textureLOD) {\n defines.TEXTURELODSUPPORT = true;\n }\n if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {\n if (!this._diffuseTexture.isReadyOrNotBlocking()) {\n return false;\n }\n MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture, defines, \"DIFFUSE\");\n defines.DIFFUSEHASALPHA = this._diffuseTexture.hasAlpha;\n defines.GAMMADIFFUSE = this._diffuseTexture.gammaSpace;\n defines.OPACITYFRESNEL = this._opacityFresnel;\n }\n else {\n defines.DIFFUSE = false;\n defines.DIFFUSEDIRECTUV = 0;\n defines.DIFFUSEHASALPHA = false;\n defines.GAMMADIFFUSE = false;\n defines.OPACITYFRESNEL = false;\n }\n const reflectionTexture = this._reflectionTexture;\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n if (!reflectionTexture.isReadyOrNotBlocking()) {\n return false;\n }\n defines.REFLECTION = true;\n defines.GAMMAREFLECTION = reflectionTexture.gammaSpace;\n defines.RGBDREFLECTION = reflectionTexture.isRGBD;\n defines.REFLECTIONBLUR = this._reflectionBlur > 0;\n defines.LODINREFLECTIONALPHA = reflectionTexture.lodLevelInAlpha;\n defines.EQUIRECTANGULAR_RELFECTION_FOV = this.useEquirectangularFOV;\n defines.REFLECTIONBGR = this.switchToBGR;\n if (reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {\n defines.INVERTCUBICMAP = true;\n }\n defines.REFLECTIONMAP_3D = reflectionTexture.isCube;\n defines.REFLECTIONMAP_OPPOSITEZ = defines.REFLECTIONMAP_3D && this.getScene().useRightHandedSystem ? !reflectionTexture.invertZ : reflectionTexture.invertZ;\n switch (reflectionTexture.coordinatesMode) {\n case Texture.EXPLICIT_MODE:\n defines.REFLECTIONMAP_EXPLICIT = true;\n break;\n case Texture.PLANAR_MODE:\n defines.REFLECTIONMAP_PLANAR = true;\n break;\n case Texture.PROJECTION_MODE:\n defines.REFLECTIONMAP_PROJECTION = true;\n break;\n case Texture.SKYBOX_MODE:\n defines.REFLECTIONMAP_SKYBOX = true;\n break;\n case Texture.SPHERICAL_MODE:\n defines.REFLECTIONMAP_SPHERICAL = true;\n break;\n case Texture.EQUIRECTANGULAR_MODE:\n defines.REFLECTIONMAP_EQUIRECTANGULAR = true;\n break;\n case Texture.FIXED_EQUIRECTANGULAR_MODE:\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;\n break;\n case Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;\n break;\n case Texture.CUBIC_MODE:\n case Texture.INVCUBIC_MODE:\n default:\n defines.REFLECTIONMAP_CUBIC = true;\n break;\n }\n if (this.reflectionFresnel) {\n defines.REFLECTIONFRESNEL = true;\n defines.REFLECTIONFALLOFF = this.reflectionFalloffDistance > 0;\n this._reflectionControls.x = this.reflectionAmount;\n this._reflectionControls.y = this.reflectionReflectance0;\n this._reflectionControls.z = this.reflectionReflectance90;\n this._reflectionControls.w = 1 / this.reflectionFalloffDistance;\n }\n else {\n defines.REFLECTIONFRESNEL = false;\n defines.REFLECTIONFALLOFF = false;\n }\n }\n else {\n defines.REFLECTION = false;\n defines.REFLECTIONFRESNEL = false;\n defines.REFLECTIONFALLOFF = false;\n defines.REFLECTIONBLUR = false;\n defines.REFLECTIONMAP_3D = false;\n defines.REFLECTIONMAP_SPHERICAL = false;\n defines.REFLECTIONMAP_PLANAR = false;\n defines.REFLECTIONMAP_CUBIC = false;\n defines.REFLECTIONMAP_PROJECTION = false;\n defines.REFLECTIONMAP_SKYBOX = false;\n defines.REFLECTIONMAP_EXPLICIT = false;\n defines.REFLECTIONMAP_EQUIRECTANGULAR = false;\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\n defines.INVERTCUBICMAP = false;\n defines.REFLECTIONMAP_OPPOSITEZ = false;\n defines.LODINREFLECTIONALPHA = false;\n defines.GAMMAREFLECTION = false;\n defines.RGBDREFLECTION = false;\n }\n }\n defines.PREMULTIPLYALPHA = this.alphaMode === 7 || this.alphaMode === 8;\n defines.USERGBCOLOR = this._useRGBColor;\n defines.NOISE = this._enableNoise;\n }\n if (defines._areLightsDirty) {\n defines.USEHIGHLIGHTANDSHADOWCOLORS = !this._useRGBColor && (this._primaryColorShadowLevel !== 0 || this._primaryColorHighlightLevel !== 0);\n defines.BACKMAT_SHADOWONLY = this._shadowOnly;\n }\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\n if (!this._imageProcessingConfiguration.isReady()) {\n return false;\n }\n this._imageProcessingConfiguration.prepareDefines(defines);\n }\n // Misc.\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);\n // Values that need to be evaluated on every frame\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);\n // Attribs\n if (MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {\n if (mesh) {\n if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n mesh.createNormals(true);\n Logger.Warn(\"BackgroundMaterial: Normals have been created for the mesh: \" + mesh.name);\n }\n }\n }\n // Get correct effect\n if (defines.isDirty) {\n defines.markAsProcessed();\n scene.resetCachedMaterial();\n // Fallbacks\n const fallbacks = new EffectFallbacks();\n if (defines.FOG) {\n fallbacks.addFallback(0, \"FOG\");\n }\n if (defines.POINTSIZE) {\n fallbacks.addFallback(1, \"POINTSIZE\");\n }\n if (defines.MULTIVIEW) {\n fallbacks.addFallback(0, \"MULTIVIEW\");\n }\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);\n //Attributes\n const attribs = [VertexBuffer.PositionKind];\n if (defines.NORMAL) {\n attribs.push(VertexBuffer.NormalKind);\n }\n if (defines.UV1) {\n attribs.push(VertexBuffer.UVKind);\n }\n if (defines.UV2) {\n attribs.push(VertexBuffer.UV2Kind);\n }\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\n const uniforms = [\n \"world\",\n \"view\",\n \"viewProjection\",\n \"vEyePosition\",\n \"vLightsType\",\n \"vFogInfos\",\n \"vFogColor\",\n \"pointSize\",\n \"mBones\",\n \"vPrimaryColor\",\n \"vPrimaryColorShadow\",\n \"vReflectionInfos\",\n \"reflectionMatrix\",\n \"vReflectionMicrosurfaceInfos\",\n \"fFovMultiplier\",\n \"shadowLevel\",\n \"alpha\",\n \"vBackgroundCenter\",\n \"vReflectionControl\",\n \"vDiffuseInfos\",\n \"diffuseMatrix\",\n ];\n addClipPlaneUniforms(uniforms);\n const samplers = [\"diffuseSampler\", \"reflectionSampler\", \"reflectionSamplerLow\", \"reflectionSamplerHigh\"];\n const uniformBuffers = [\"Material\", \"Scene\"];\n if (ImageProcessingConfiguration) {\n ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);\n ImageProcessingConfiguration.PrepareSamplers(samplers, defines);\n }\n MaterialHelper.PrepareUniformsAndSamplersList({\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: defines,\n maxSimultaneousLights: this._maxSimultaneousLights,\n });\n const join = defines.toString();\n const effect = scene.getEngine().createEffect(\"background\", {\n attributes: attribs,\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: join,\n fallbacks: fallbacks,\n onCompiled: this.onCompiled,\n onError: this.onError,\n indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights },\n }, engine);\n subMesh.setEffect(effect, defines, this._materialContext);\n this.buildUniformLayout();\n }\n if (!subMesh.effect || !subMesh.effect.isReady()) {\n return false;\n }\n defines._renderId = scene.getRenderId();\n subMesh.effect._wasPreviouslyReady = true;\n subMesh.effect._wasPreviouslyUsingInstances = useInstances;\n this._checkScenePerformancePriority();\n return true;\n }\n /**\n * Compute the primary color according to the chosen perceptual color.\n */\n _computePrimaryColorFromPerceptualColor() {\n if (!this.__perceptualColor) {\n return;\n }\n this._primaryColor.copyFrom(this.__perceptualColor);\n // Revert gamma space.\n this._primaryColor.toLinearSpaceToRef(this._primaryColor, this.getScene().getEngine().useExactSrgbConversions);\n // Revert image processing configuration.\n if (this._imageProcessingConfiguration) {\n // Revert Exposure.\n this._primaryColor.scaleToRef(1 / this._imageProcessingConfiguration.exposure, this._primaryColor);\n }\n this._computePrimaryColors();\n }\n /**\n * Compute the highlights and shadow colors according to their chosen levels.\n */\n _computePrimaryColors() {\n if (this._primaryColorShadowLevel === 0 && this._primaryColorHighlightLevel === 0) {\n return;\n }\n // Find the highlight color based on the configuration.\n this._primaryColor.scaleToRef(this._primaryColorShadowLevel, this._primaryShadowColor);\n this._primaryColor.subtractToRef(this._primaryShadowColor, this._primaryShadowColor);\n // Find the shadow color based on the configuration.\n this._white.subtractToRef(this._primaryColor, this._primaryHighlightColor);\n this._primaryHighlightColor.scaleToRef(this._primaryColorHighlightLevel, this._primaryHighlightColor);\n this._primaryColor.addToRef(this._primaryHighlightColor, this._primaryHighlightColor);\n }\n /**\n * Build the uniform buffer used in the material.\n */\n buildUniformLayout() {\n // Order is important !\n this._uniformBuffer.addUniform(\"vPrimaryColor\", 4);\n this._uniformBuffer.addUniform(\"vPrimaryColorShadow\", 4);\n this._uniformBuffer.addUniform(\"vDiffuseInfos\", 2);\n this._uniformBuffer.addUniform(\"vReflectionInfos\", 2);\n this._uniformBuffer.addUniform(\"diffuseMatrix\", 16);\n this._uniformBuffer.addUniform(\"reflectionMatrix\", 16);\n this._uniformBuffer.addUniform(\"vReflectionMicrosurfaceInfos\", 3);\n this._uniformBuffer.addUniform(\"fFovMultiplier\", 1);\n this._uniformBuffer.addUniform(\"pointSize\", 1);\n this._uniformBuffer.addUniform(\"shadowLevel\", 1);\n this._uniformBuffer.addUniform(\"alpha\", 1);\n this._uniformBuffer.addUniform(\"vBackgroundCenter\", 3);\n this._uniformBuffer.addUniform(\"vReflectionControl\", 4);\n this._uniformBuffer.create();\n }\n /**\n * Unbind the material.\n */\n unbind() {\n if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {\n this._uniformBuffer.setTexture(\"diffuseSampler\", null);\n }\n if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\n this._uniformBuffer.setTexture(\"reflectionSampler\", null);\n }\n super.unbind();\n }\n /**\n * Bind only the world matrix to the material.\n * @param world The world matrix to bind.\n */\n bindOnlyWorldMatrix(world) {\n this._activeEffect.setMatrix(\"world\", world);\n }\n /**\n * Bind the material for a dedicated submeh (every used meshes will be considered opaque).\n * @param world The world matrix to bind.\n * @param mesh\n * @param subMesh The submesh to bind for.\n */\n bindForSubMesh(world, mesh, subMesh) {\n const scene = this.getScene();\n const defines = subMesh.materialDefines;\n if (!defines) {\n return;\n }\n const effect = subMesh.effect;\n if (!effect) {\n return;\n }\n this._activeEffect = effect;\n // Matrices\n this.bindOnlyWorldMatrix(world);\n // Bones\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect);\n const mustRebind = this._mustRebind(scene, effect, mesh.visibility);\n if (mustRebind) {\n this._uniformBuffer.bindToEffect(effect, \"Material\");\n this.bindViewProjection(effect);\n const reflectionTexture = this._reflectionTexture;\n if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {\n // Texture uniforms\n if (scene.texturesEnabled) {\n if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {\n this._uniformBuffer.updateFloat2(\"vDiffuseInfos\", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);\n MaterialHelper.BindTextureMatrix(this._diffuseTexture, this._uniformBuffer, \"diffuse\");\n }\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n this._uniformBuffer.updateMatrix(\"reflectionMatrix\", reflectionTexture.getReflectionTextureMatrix());\n this._uniformBuffer.updateFloat2(\"vReflectionInfos\", reflectionTexture.level, this._reflectionBlur);\n this._uniformBuffer.updateFloat3(\"vReflectionMicrosurfaceInfos\", reflectionTexture.getSize().width, reflectionTexture.lodGenerationScale, reflectionTexture.lodGenerationOffset);\n }\n }\n if (this.shadowLevel > 0) {\n this._uniformBuffer.updateFloat(\"shadowLevel\", this.shadowLevel);\n }\n this._uniformBuffer.updateFloat(\"alpha\", this.alpha);\n // Point size\n if (this.pointsCloud) {\n this._uniformBuffer.updateFloat(\"pointSize\", this.pointSize);\n }\n if (defines.USEHIGHLIGHTANDSHADOWCOLORS) {\n this._uniformBuffer.updateColor4(\"vPrimaryColor\", this._primaryHighlightColor, 1.0);\n this._uniformBuffer.updateColor4(\"vPrimaryColorShadow\", this._primaryShadowColor, 1.0);\n }\n else {\n this._uniformBuffer.updateColor4(\"vPrimaryColor\", this._primaryColor, 1.0);\n }\n }\n this._uniformBuffer.updateFloat(\"fFovMultiplier\", this._fovMultiplier);\n // Textures\n if (scene.texturesEnabled) {\n if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {\n this._uniformBuffer.setTexture(\"diffuseSampler\", this._diffuseTexture);\n }\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\n if (defines.REFLECTIONBLUR && defines.TEXTURELODSUPPORT) {\n this._uniformBuffer.setTexture(\"reflectionSampler\", reflectionTexture);\n }\n else if (!defines.REFLECTIONBLUR) {\n this._uniformBuffer.setTexture(\"reflectionSampler\", reflectionTexture);\n }\n else {\n this._uniformBuffer.setTexture(\"reflectionSampler\", reflectionTexture._lodTextureMid || reflectionTexture);\n this._uniformBuffer.setTexture(\"reflectionSamplerLow\", reflectionTexture._lodTextureLow || reflectionTexture);\n this._uniformBuffer.setTexture(\"reflectionSamplerHigh\", reflectionTexture._lodTextureHigh || reflectionTexture);\n }\n if (defines.REFLECTIONFRESNEL) {\n this._uniformBuffer.updateFloat3(\"vBackgroundCenter\", this.sceneCenter.x, this.sceneCenter.y, this.sceneCenter.z);\n this._uniformBuffer.updateFloat4(\"vReflectionControl\", this._reflectionControls.x, this._reflectionControls.y, this._reflectionControls.z, this._reflectionControls.w);\n }\n }\n }\n // Clip plane\n bindClipPlane(this._activeEffect, this, scene);\n scene.bindEyePosition(effect);\n }\n else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {\n this._uniformBuffer.bindToEffect(effect, \"Material\");\n this._needToBindSceneUbo = true;\n }\n if (mustRebind || !this.isFrozen) {\n if (scene.lightsEnabled) {\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);\n }\n // View\n this.bindView(effect);\n // Fog\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect, true);\n // image processing\n if (this._imageProcessingConfiguration) {\n this._imageProcessingConfiguration.bind(this._activeEffect);\n }\n }\n this._afterBind(mesh, this._activeEffect);\n this._uniformBuffer.update();\n }\n /**\n * Checks to see if a texture is used in the material.\n * @param texture - Base texture to use.\n * @returns - Boolean specifying if a texture is used in the material.\n */\n hasTexture(texture) {\n if (super.hasTexture(texture)) {\n return true;\n }\n if (this._reflectionTexture === texture) {\n return true;\n }\n if (this._diffuseTexture === texture) {\n return true;\n }\n return false;\n }\n /**\n * Dispose the material.\n * @param forceDisposeEffect Force disposal of the associated effect.\n * @param forceDisposeTextures Force disposal of the associated textures.\n */\n dispose(forceDisposeEffect = false, forceDisposeTextures = false) {\n if (forceDisposeTextures) {\n if (this.diffuseTexture) {\n this.diffuseTexture.dispose();\n }\n if (this.reflectionTexture) {\n this.reflectionTexture.dispose();\n }\n }\n this._renderTargets.dispose();\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n super.dispose(forceDisposeEffect);\n }\n /**\n * Clones the material.\n * @param name The cloned name.\n * @returns The cloned material.\n */\n clone(name) {\n return SerializationHelper.Clone(() => new BackgroundMaterial(name, this.getScene()), this);\n }\n /**\n * Serializes the current material to its JSON representation.\n * @returns The JSON representation.\n */\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.customType = \"BABYLON.BackgroundMaterial\";\n return serializationObject;\n }\n /**\n * Gets the class name of the material\n * @returns \"BackgroundMaterial\"\n */\n getClassName() {\n return \"BackgroundMaterial\";\n }\n /**\n * Parse a JSON input to create back a background material.\n * @param source The JSON data to parse\n * @param scene The scene to create the parsed material in\n * @param rootUrl The root url of the assets the material depends upon\n * @returns the instantiated BackgroundMaterial.\n */\n static Parse(source, scene, rootUrl) {\n return SerializationHelper.Parse(() => new BackgroundMaterial(source.name, scene), source, scene, rootUrl);\n }\n }\n /**\n * Standard reflectance value at parallel view angle.\n */\n BackgroundMaterial.StandardReflectance0 = 0.05;\n /**\n * Standard reflectance value at grazing angle.\n */\n BackgroundMaterial.StandardReflectance90 = 0.5;\n __decorate$1([\n serializeAsColor3()\n ], BackgroundMaterial.prototype, \"_primaryColor\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], BackgroundMaterial.prototype, \"primaryColor\", void 0);\n __decorate$1([\n serializeAsColor3()\n ], BackgroundMaterial.prototype, \"__perceptualColor\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_primaryColorShadowLevel\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_primaryColorHighlightLevel\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], BackgroundMaterial.prototype, \"primaryColorHighlightLevel\", null);\n __decorate$1([\n serializeAsTexture()\n ], BackgroundMaterial.prototype, \"_reflectionTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionTexture\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_reflectionBlur\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionBlur\", void 0);\n __decorate$1([\n serializeAsTexture()\n ], BackgroundMaterial.prototype, \"_diffuseTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"diffuseTexture\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"shadowLights\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_shadowLevel\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"shadowLevel\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], BackgroundMaterial.prototype, \"_sceneCenter\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"sceneCenter\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_opacityFresnel\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"opacityFresnel\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_reflectionFresnel\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionFresnel\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_reflectionFalloffDistance\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionFalloffDistance\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_reflectionAmount\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionAmount\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_reflectionReflectance0\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionReflectance0\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_reflectionReflectance90\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"reflectionReflectance90\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_useRGBColor\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"useRGBColor\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_enableNoise\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"enableNoise\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_maxSimultaneousLights\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n ], BackgroundMaterial.prototype, \"maxSimultaneousLights\", void 0);\n __decorate$1([\n serialize()\n ], BackgroundMaterial.prototype, \"_shadowOnly\", void 0);\n __decorate$1([\n expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\n ], BackgroundMaterial.prototype, \"shadowOnly\", void 0);\n __decorate$1([\n serializeAsImageProcessingConfiguration()\n ], BackgroundMaterial.prototype, \"_imageProcessingConfiguration\", void 0);\n RegisterClass(\"BABYLON.BackgroundMaterial\", BackgroundMaterial);\n\n /**\n * Creates the VertexData for a Plane\n * @param options an object used to set the following optional parameters for the plane, required but can be empty\n * * size sets the width and height of the plane to the value of size, optional default 1\n * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size\n * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the box\n */\n function CreatePlaneVertexData(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n const width = options.width || options.size || 1;\n const height = options.height || options.size || 1;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // Vertices\n const halfWidth = width / 2.0;\n const halfHeight = height / 2.0;\n positions.push(-halfWidth, -halfHeight, 0);\n normals.push(0, 0, -1.0);\n uvs.push(0.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 : 0.0);\n positions.push(halfWidth, -halfHeight, 0);\n normals.push(0, 0, -1.0);\n uvs.push(1.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 : 0.0);\n positions.push(halfWidth, halfHeight, 0);\n normals.push(0, 0, -1.0);\n uvs.push(1.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 0.0 : 1.0);\n positions.push(-halfWidth, halfHeight, 0);\n normals.push(0, 0, -1.0);\n uvs.push(0.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 0.0 : 1.0);\n // Indices\n indices.push(0);\n indices.push(1);\n indices.push(2);\n indices.push(0);\n indices.push(2);\n indices.push(3);\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a plane mesh\n * * The parameter `size` sets the size (float) of both sides of the plane at once (default 1)\n * * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value of `size`)\n * * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.updatable\n * @param options.sourcePlane\n * @param scene defines the hosting scene\n * @returns the plane mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#plane\n */\n function CreatePlane(name, options = {}, scene = null) {\n const plane = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n plane._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreatePlaneVertexData(options);\n vertexData.applyToMesh(plane, options.updatable);\n if (options.sourcePlane) {\n plane.translate(options.sourcePlane.normal, -options.sourcePlane.d);\n plane.setDirection(options.sourcePlane.normal.scale(-1));\n }\n return plane;\n }\n /**\n * Class containing static functions to help procedurally build meshes\n * @deprecated use the function directly from the module\n */\n const PlaneBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreatePlane,\n };\n VertexData.CreatePlane = CreatePlaneVertexData;\n Mesh.CreatePlane = (name, size, scene, updatable, sideOrientation) => {\n const options = {\n size,\n width: size,\n height: size,\n sideOrientation,\n updatable,\n };\n return CreatePlane(name, options, scene);\n };\n\n Mesh._GroundMeshParser = (parsedMesh, scene) => {\n return GroundMesh.Parse(parsedMesh, scene);\n };\n /**\n * Mesh representing the ground\n */\n class GroundMesh extends Mesh {\n constructor(name, scene) {\n super(name, scene);\n /** If octree should be generated */\n this.generateOctree = false;\n }\n /**\n * \"GroundMesh\"\n * @returns \"GroundMesh\"\n */\n getClassName() {\n return \"GroundMesh\";\n }\n /**\n * The minimum of x and y subdivisions\n */\n get subdivisions() {\n return Math.min(this._subdivisionsX, this._subdivisionsY);\n }\n /**\n * X subdivisions\n */\n get subdivisionsX() {\n return this._subdivisionsX;\n }\n /**\n * Y subdivisions\n */\n get subdivisionsY() {\n return this._subdivisionsY;\n }\n /**\n * This function will divide the mesh into submeshes and update an octree to help to select the right submeshes\n * for rendering, picking and collision computations. Please note that you must have a decent number of submeshes\n * to get performance improvements when using an octree.\n * @param chunksCount the number of submeshes the mesh will be divided into\n * @param octreeBlocksSize the maximum size of the octree blocks (Default: 32)\n */\n optimize(chunksCount, octreeBlocksSize = 32) {\n this._subdivisionsX = chunksCount;\n this._subdivisionsY = chunksCount;\n this.subdivide(chunksCount);\n // Call the octree system optimization if it is defined.\n const thisAsAny = this;\n if (thisAsAny.createOrUpdateSubmeshesOctree) {\n thisAsAny.createOrUpdateSubmeshesOctree(octreeBlocksSize);\n }\n }\n /**\n * Returns a height (y) value in the World system :\n * the ground altitude at the coordinates (x, z) expressed in the World system.\n * @param x x coordinate\n * @param z z coordinate\n * @returns the ground y position if (x, z) are outside the ground surface.\n */\n getHeightAtCoordinates(x, z) {\n const world = this.getWorldMatrix();\n const invMat = TmpVectors.Matrix[5];\n world.invertToRef(invMat);\n const tmpVect = TmpVectors.Vector3[8];\n Vector3.TransformCoordinatesFromFloatsToRef(x, 0.0, z, invMat, tmpVect); // transform x,z in the mesh local space\n x = tmpVect.x;\n z = tmpVect.z;\n if (x < this._minX || x >= this._maxX || z <= this._minZ || z > this._maxZ) {\n return this.position.y;\n }\n if (!this._heightQuads || this._heightQuads.length == 0) {\n this._initHeightQuads();\n this._computeHeightQuads();\n }\n const facet = this._getFacetAt(x, z);\n const y = -(facet.x * x + facet.z * z + facet.w) / facet.y;\n // return y in the World system\n Vector3.TransformCoordinatesFromFloatsToRef(0.0, y, 0.0, world, tmpVect);\n return tmpVect.y;\n }\n /**\n * Returns a normalized vector (Vector3) orthogonal to the ground\n * at the ground coordinates (x, z) expressed in the World system.\n * @param x x coordinate\n * @param z z coordinate\n * @returns Vector3(0.0, 1.0, 0.0) if (x, z) are outside the ground surface.\n */\n getNormalAtCoordinates(x, z) {\n const normal = new Vector3(0.0, 1.0, 0.0);\n this.getNormalAtCoordinatesToRef(x, z, normal);\n return normal;\n }\n /**\n * Updates the Vector3 passed a reference with a normalized vector orthogonal to the ground\n * at the ground coordinates (x, z) expressed in the World system.\n * Doesn't update the reference Vector3 if (x, z) are outside the ground surface.\n * @param x x coordinate\n * @param z z coordinate\n * @param ref vector to store the result\n * @returns the GroundMesh.\n */\n getNormalAtCoordinatesToRef(x, z, ref) {\n const world = this.getWorldMatrix();\n const tmpMat = TmpVectors.Matrix[5];\n world.invertToRef(tmpMat);\n const tmpVect = TmpVectors.Vector3[8];\n Vector3.TransformCoordinatesFromFloatsToRef(x, 0.0, z, tmpMat, tmpVect); // transform x,z in the mesh local space\n x = tmpVect.x;\n z = tmpVect.z;\n if (x < this._minX || x > this._maxX || z < this._minZ || z > this._maxZ) {\n return this;\n }\n if (!this._heightQuads || this._heightQuads.length == 0) {\n this._initHeightQuads();\n this._computeHeightQuads();\n }\n const facet = this._getFacetAt(x, z);\n Vector3.TransformNormalFromFloatsToRef(facet.x, facet.y, facet.z, world, ref);\n return this;\n }\n /**\n * Force the heights to be recomputed for getHeightAtCoordinates() or getNormalAtCoordinates()\n * if the ground has been updated.\n * This can be used in the render loop.\n * @returns the GroundMesh.\n */\n updateCoordinateHeights() {\n if (!this._heightQuads || this._heightQuads.length == 0) {\n this._initHeightQuads();\n }\n this._computeHeightQuads();\n return this;\n }\n // Returns the element \"facet\" from the heightQuads array relative to (x, z) local coordinates\n _getFacetAt(x, z) {\n // retrieve col and row from x, z coordinates in the ground local system\n const col = Math.floor(((x + this._maxX) * this._subdivisionsX) / this._width);\n const row = Math.floor((-(z + this._maxZ) * this._subdivisionsY) / this._height + this._subdivisionsY);\n const quad = this._heightQuads[row * this._subdivisionsX + col];\n let facet;\n if (z < quad.slope.x * x + quad.slope.y) {\n facet = quad.facet1;\n }\n else {\n facet = quad.facet2;\n }\n return facet;\n }\n // Creates and populates the heightMap array with \"facet\" elements :\n // a quad is two triangular facets separated by a slope, so a \"facet\" element is 1 slope + 2 facets\n // slope : Vector2(c, h) = 2D diagonal line equation setting apart two triangular facets in a quad : z = cx + h\n // facet1 : Vector4(a, b, c, d) = first facet 3D plane equation : ax + by + cz + d = 0\n // facet2 : Vector4(a, b, c, d) = second facet 3D plane equation : ax + by + cz + d = 0\n // Returns the GroundMesh.\n _initHeightQuads() {\n const subdivisionsX = this._subdivisionsX;\n const subdivisionsY = this._subdivisionsY;\n this._heightQuads = new Array();\n for (let row = 0; row < subdivisionsY; row++) {\n for (let col = 0; col < subdivisionsX; col++) {\n const quad = { slope: Vector2.Zero(), facet1: new Vector4(0.0, 0.0, 0.0, 0.0), facet2: new Vector4(0.0, 0.0, 0.0, 0.0) };\n this._heightQuads[row * subdivisionsX + col] = quad;\n }\n }\n return this;\n }\n // Compute each quad element values and update the the heightMap array :\n // slope : Vector2(c, h) = 2D diagonal line equation setting apart two triangular facets in a quad : z = cx + h\n // facet1 : Vector4(a, b, c, d) = first facet 3D plane equation : ax + by + cz + d = 0\n // facet2 : Vector4(a, b, c, d) = second facet 3D plane equation : ax + by + cz + d = 0\n // Returns the GroundMesh.\n _computeHeightQuads() {\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\n if (!positions) {\n return this;\n }\n const v1 = TmpVectors.Vector3[3];\n const v2 = TmpVectors.Vector3[2];\n const v3 = TmpVectors.Vector3[1];\n const v4 = TmpVectors.Vector3[0];\n const v1v2 = TmpVectors.Vector3[4];\n const v1v3 = TmpVectors.Vector3[5];\n const v1v4 = TmpVectors.Vector3[6];\n const norm1 = TmpVectors.Vector3[7];\n const norm2 = TmpVectors.Vector3[8];\n let i = 0;\n let j = 0;\n let k = 0;\n let cd = 0; // 2D slope coefficient : z = cd * x + h\n let h = 0;\n let d1 = 0; // facet plane equation : ax + by + cz + d = 0\n let d2 = 0;\n const subdivisionsX = this._subdivisionsX;\n const subdivisionsY = this._subdivisionsY;\n for (let row = 0; row < subdivisionsY; row++) {\n for (let col = 0; col < subdivisionsX; col++) {\n i = col * 3;\n j = row * (subdivisionsX + 1) * 3;\n k = (row + 1) * (subdivisionsX + 1) * 3;\n v1.x = positions[j + i];\n v1.y = positions[j + i + 1];\n v1.z = positions[j + i + 2];\n v2.x = positions[j + i + 3];\n v2.y = positions[j + i + 4];\n v2.z = positions[j + i + 5];\n v3.x = positions[k + i];\n v3.y = positions[k + i + 1];\n v3.z = positions[k + i + 2];\n v4.x = positions[k + i + 3];\n v4.y = positions[k + i + 4];\n v4.z = positions[k + i + 5];\n // 2D slope V1V4\n cd = (v4.z - v1.z) / (v4.x - v1.x);\n h = v1.z - cd * v1.x; // v1 belongs to the slope\n // facet equations :\n // we compute each facet normal vector\n // the equation of the facet plane is : norm.x * x + norm.y * y + norm.z * z + d = 0\n // we compute the value d by applying the equation to v1 which belongs to the plane\n // then we store the facet equation in a Vector4\n v2.subtractToRef(v1, v1v2);\n v3.subtractToRef(v1, v1v3);\n v4.subtractToRef(v1, v1v4);\n Vector3.CrossToRef(v1v4, v1v3, norm1); // caution : CrossToRef uses the Tmp class\n Vector3.CrossToRef(v1v2, v1v4, norm2);\n norm1.normalize();\n norm2.normalize();\n d1 = -(norm1.x * v1.x + norm1.y * v1.y + norm1.z * v1.z);\n d2 = -(norm2.x * v2.x + norm2.y * v2.y + norm2.z * v2.z);\n const quad = this._heightQuads[row * subdivisionsX + col];\n quad.slope.copyFromFloats(cd, h);\n quad.facet1.copyFromFloats(norm1.x, norm1.y, norm1.z, d1);\n quad.facet2.copyFromFloats(norm2.x, norm2.y, norm2.z, d2);\n }\n }\n return this;\n }\n /**\n * Serializes this ground mesh\n * @param serializationObject object to write serialization to\n */\n serialize(serializationObject) {\n super.serialize(serializationObject);\n serializationObject.subdivisionsX = this._subdivisionsX;\n serializationObject.subdivisionsY = this._subdivisionsY;\n serializationObject.minX = this._minX;\n serializationObject.maxX = this._maxX;\n serializationObject.minZ = this._minZ;\n serializationObject.maxZ = this._maxZ;\n serializationObject.width = this._width;\n serializationObject.height = this._height;\n }\n /**\n * Parses a serialized ground mesh\n * @param parsedMesh the serialized mesh\n * @param scene the scene to create the ground mesh in\n * @returns the created ground mesh\n */\n static Parse(parsedMesh, scene) {\n const result = new GroundMesh(parsedMesh.name, scene);\n result._subdivisionsX = parsedMesh.subdivisionsX || 1;\n result._subdivisionsY = parsedMesh.subdivisionsY || 1;\n result._minX = parsedMesh.minX;\n result._maxX = parsedMesh.maxX;\n result._minZ = parsedMesh.minZ;\n result._maxZ = parsedMesh.maxZ;\n result._width = parsedMesh.width;\n result._height = parsedMesh.height;\n return result;\n }\n }\n\n /**\n * Creates the VertexData for a Ground\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\n * - width the width (x direction) of the ground, optional, default 1\n * - height the height (z direction) of the ground, optional, default 1\n * - subdivisions the number of subdivisions per side, optional, default 1\n * @param options.width\n * @param options.height\n * @param options.subdivisions\n * @param options.subdivisionsX\n * @param options.subdivisionsY\n * @returns the VertexData of the Ground\n */\n function CreateGroundVertexData(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n let row, col;\n const width = options.width || 1;\n const height = options.height || 1;\n const subdivisionsX = (options.subdivisionsX || options.subdivisions || 1) | 0;\n const subdivisionsY = (options.subdivisionsY || options.subdivisions || 1) | 0;\n for (row = 0; row <= subdivisionsY; row++) {\n for (col = 0; col <= subdivisionsX; col++) {\n const position = new Vector3((col * width) / subdivisionsX - width / 2.0, 0, ((subdivisionsY - row) * height) / subdivisionsY - height / 2.0);\n const normal = new Vector3(0, 1.0, 0);\n positions.push(position.x, position.y, position.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(col / subdivisionsX, CompatibilityOptions.UseOpenGLOrientationForUV ? row / subdivisionsY : 1.0 - row / subdivisionsY);\n }\n }\n for (row = 0; row < subdivisionsY; row++) {\n for (col = 0; col < subdivisionsX; col++) {\n indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));\n indices.push(col + 1 + row * (subdivisionsX + 1));\n indices.push(col + row * (subdivisionsX + 1));\n indices.push(col + (row + 1) * (subdivisionsX + 1));\n indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));\n indices.push(col + row * (subdivisionsX + 1));\n }\n }\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates the VertexData for a TiledGround by subdividing the ground into tiles\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\n * * xmin the ground minimum X coordinate, optional, default -1\n * * zmin the ground minimum Z coordinate, optional, default -1\n * * xmax the ground maximum X coordinate, optional, default 1\n * * zmax the ground maximum Z coordinate, optional, default 1\n * * subdivisions a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the ground width and height creating 'tiles', default {w: 6, h: 6}\n * * precision a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the tile width and height, default {w: 2, h: 2}\n * @param options.xmin\n * @param options.zmin\n * @param options.xmax\n * @param options.zmax\n * @param options.subdivisions\n * @param options.subdivisions.w\n * @param options.subdivisions.h\n * @param options.precision\n * @param options.precision.w\n * @param options.precision.h\n * @returns the VertexData of the TiledGround\n */\n function CreateTiledGroundVertexData(options) {\n const xmin = options.xmin !== undefined && options.xmin !== null ? options.xmin : -1.0;\n const zmin = options.zmin !== undefined && options.zmin !== null ? options.zmin : -1.0;\n const xmax = options.xmax !== undefined && options.xmax !== null ? options.xmax : 1.0;\n const zmax = options.zmax !== undefined && options.zmax !== null ? options.zmax : 1.0;\n const subdivisions = options.subdivisions || { w: 1, h: 1 };\n const precision = options.precision || { w: 1, h: 1 };\n const indices = new Array();\n const positions = new Array();\n const normals = new Array();\n const uvs = new Array();\n let row, col, tileRow, tileCol;\n subdivisions.h = subdivisions.h < 1 ? 1 : subdivisions.h;\n subdivisions.w = subdivisions.w < 1 ? 1 : subdivisions.w;\n precision.w = precision.w < 1 ? 1 : precision.w;\n precision.h = precision.h < 1 ? 1 : precision.h;\n const tileSize = {\n w: (xmax - xmin) / subdivisions.w,\n h: (zmax - zmin) / subdivisions.h,\n };\n function applyTile(xTileMin, zTileMin, xTileMax, zTileMax) {\n // Indices\n const base = positions.length / 3;\n const rowLength = precision.w + 1;\n for (row = 0; row < precision.h; row++) {\n for (col = 0; col < precision.w; col++) {\n const square = [base + col + row * rowLength, base + (col + 1) + row * rowLength, base + (col + 1) + (row + 1) * rowLength, base + col + (row + 1) * rowLength];\n indices.push(square[1]);\n indices.push(square[2]);\n indices.push(square[3]);\n indices.push(square[0]);\n indices.push(square[1]);\n indices.push(square[3]);\n }\n }\n // Position, normals and uvs\n const position = Vector3.Zero();\n const normal = new Vector3(0, 1.0, 0);\n for (row = 0; row <= precision.h; row++) {\n position.z = (row * (zTileMax - zTileMin)) / precision.h + zTileMin;\n for (col = 0; col <= precision.w; col++) {\n position.x = (col * (xTileMax - xTileMin)) / precision.w + xTileMin;\n position.y = 0;\n positions.push(position.x, position.y, position.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(col / precision.w, row / precision.h);\n }\n }\n }\n for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {\n for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {\n applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);\n }\n }\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates the VertexData of the Ground designed from a heightmap\n * @param options an object used to set the following parameters for the Ground, required and provided by CreateGroundFromHeightMap\n * * width the width (x direction) of the ground\n * * height the height (z direction) of the ground\n * * subdivisions the number of subdivisions per side\n * * minHeight the minimum altitude on the ground, optional, default 0\n * * maxHeight the maximum altitude on the ground, optional default 1\n * * colorFilter the filter to apply to the image pixel colors to compute the height, optional Color3, default (0.3, 0.59, 0.11)\n * * buffer the array holding the image color data\n * * bufferWidth the width of image\n * * bufferHeight the height of image\n * * alphaFilter Remove any data where the alpha channel is below this value, defaults 0 (all data visible)\n * @param options.width\n * @param options.height\n * @param options.subdivisions\n * @param options.minHeight\n * @param options.maxHeight\n * @param options.colorFilter\n * @param options.buffer\n * @param options.bufferWidth\n * @param options.bufferHeight\n * @param options.alphaFilter\n * @returns the VertexData of the Ground designed from a heightmap\n */\n function CreateGroundFromHeightMapVertexData(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n let row, col;\n const filter = options.colorFilter || new Color3(0.3, 0.59, 0.11);\n const alphaFilter = options.alphaFilter || 0.0;\n let invert = false;\n if (options.minHeight > options.maxHeight) {\n invert = true;\n const temp = options.maxHeight;\n options.maxHeight = options.minHeight;\n options.minHeight = temp;\n }\n // Vertices\n for (row = 0; row <= options.subdivisions; row++) {\n for (col = 0; col <= options.subdivisions; col++) {\n const position = new Vector3((col * options.width) / options.subdivisions - options.width / 2.0, 0, ((options.subdivisions - row) * options.height) / options.subdivisions - options.height / 2.0);\n // Compute height\n const heightMapX = (((position.x + options.width / 2) / options.width) * (options.bufferWidth - 1)) | 0;\n const heightMapY = ((1.0 - (position.z + options.height / 2) / options.height) * (options.bufferHeight - 1)) | 0;\n const pos = (heightMapX + heightMapY * options.bufferWidth) * 4;\n let r = options.buffer[pos] / 255.0;\n let g = options.buffer[pos + 1] / 255.0;\n let b = options.buffer[pos + 2] / 255.0;\n const a = options.buffer[pos + 3] / 255.0;\n if (invert) {\n r = 1.0 - r;\n g = 1.0 - g;\n b = 1.0 - b;\n }\n const gradient = r * filter.r + g * filter.g + b * filter.b;\n // If our alpha channel is not within our filter then we will assign a 'special' height\n // Then when building the indices, we will ignore any vertex that is using the special height\n if (a >= alphaFilter) {\n position.y = options.minHeight + (options.maxHeight - options.minHeight) * gradient;\n }\n else {\n position.y = options.minHeight - Epsilon; // We can't have a height below minHeight, normally.\n }\n // Add vertex\n positions.push(position.x, position.y, position.z);\n normals.push(0, 0, 0);\n uvs.push(col / options.subdivisions, 1.0 - row / options.subdivisions);\n }\n }\n // Indices\n for (row = 0; row < options.subdivisions; row++) {\n for (col = 0; col < options.subdivisions; col++) {\n // Calculate Indices\n const idx1 = col + 1 + (row + 1) * (options.subdivisions + 1);\n const idx2 = col + 1 + row * (options.subdivisions + 1);\n const idx3 = col + row * (options.subdivisions + 1);\n const idx4 = col + (row + 1) * (options.subdivisions + 1);\n // Check that all indices are visible (based on our special height)\n // Only display the vertex if all Indices are visible\n // Positions are stored x,y,z for each vertex, hence the * 3 and + 1 for height\n const isVisibleIdx1 = positions[idx1 * 3 + 1] >= options.minHeight;\n const isVisibleIdx2 = positions[idx2 * 3 + 1] >= options.minHeight;\n const isVisibleIdx3 = positions[idx3 * 3 + 1] >= options.minHeight;\n if (isVisibleIdx1 && isVisibleIdx2 && isVisibleIdx3) {\n indices.push(idx1);\n indices.push(idx2);\n indices.push(idx3);\n }\n const isVisibleIdx4 = positions[idx4 * 3 + 1] >= options.minHeight;\n if (isVisibleIdx4 && isVisibleIdx1 && isVisibleIdx3) {\n indices.push(idx4);\n indices.push(idx1);\n indices.push(idx3);\n }\n }\n }\n // Normals\n VertexData.ComputeNormals(positions, indices, normals);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a ground mesh\n * * The parameters `width` and `height` (floats, default 1) set the width and height sizes of the ground\n * * The parameter `subdivisions` (positive integer) sets the number of subdivisions per side\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.width\n * @param options.height\n * @param options.subdivisions\n * @param options.subdivisionsX\n * @param options.subdivisionsY\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the ground mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#ground\n */\n function CreateGround(name, options = {}, scene) {\n const ground = new GroundMesh(name, scene);\n ground._setReady(false);\n ground._subdivisionsX = options.subdivisionsX || options.subdivisions || 1;\n ground._subdivisionsY = options.subdivisionsY || options.subdivisions || 1;\n ground._width = options.width || 1;\n ground._height = options.height || 1;\n ground._maxX = ground._width / 2;\n ground._maxZ = ground._height / 2;\n ground._minX = -ground._maxX;\n ground._minZ = -ground._maxZ;\n const vertexData = CreateGroundVertexData(options);\n vertexData.applyToMesh(ground, options.updatable);\n ground._setReady(true);\n return ground;\n }\n /**\n * Creates a tiled ground mesh\n * * The parameters `xmin` and `xmax` (floats, default -1 and 1) set the ground minimum and maximum X coordinates\n * * The parameters `zmin` and `zmax` (floats, default -1 and 1) set the ground minimum and maximum Z coordinates\n * * The parameter `subdivisions` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the numbers of subdivisions on the ground width and height. Each subdivision is called a tile\n * * The parameter `precision` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the numbers of subdivisions on the ground width and height of each tile\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.xmin\n * @param options.zmin\n * @param options.xmax\n * @param options.zmax\n * @param options.subdivisions\n * @param options.subdivisions.w\n * @param options.subdivisions.h\n * @param options.precision\n * @param options.precision.w\n * @param options.precision.h\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the tiled ground mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#tiled-ground\n */\n function CreateTiledGround(name, options, scene = null) {\n const tiledGround = new Mesh(name, scene);\n const vertexData = CreateTiledGroundVertexData(options);\n vertexData.applyToMesh(tiledGround, options.updatable);\n return tiledGround;\n }\n /**\n * Creates a ground mesh from a height map\n * * The parameter `url` sets the URL of the height map image resource.\n * * The parameters `width` and `height` (positive floats, default 10) set the ground width and height sizes.\n * * The parameter `subdivisions` (positive integer, default 1) sets the number of subdivision per side.\n * * The parameter `minHeight` (float, default 0) is the minimum altitude on the ground.\n * * The parameter `maxHeight` (float, default 1) is the maximum altitude on the ground.\n * * The parameter `colorFilter` (optional Color3, default (0.3, 0.59, 0.11) ) is the filter to apply to the image pixel colors to compute the height.\n * * The parameter `onReady` is a javascript callback function that will be called once the mesh is just built (the height map download can last some time).\n * * The parameter `alphaFilter` will filter any data where the alpha channel is below this value, defaults 0 (all data visible)\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param url defines the url to the height map\n * @param options defines the options used to create the mesh\n * @param options.width\n * @param options.height\n * @param options.subdivisions\n * @param options.minHeight\n * @param options.maxHeight\n * @param options.colorFilter\n * @param options.alphaFilter\n * @param options.updatable\n * @param options.onReady\n * @param scene defines the hosting scene\n * @returns the ground mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/height_map\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#ground-from-a-height-map\n */\n function CreateGroundFromHeightMap(name, url, options = {}, scene = null) {\n const width = options.width || 10.0;\n const height = options.height || 10.0;\n const subdivisions = options.subdivisions || 1 | 0;\n const minHeight = options.minHeight || 0.0;\n const maxHeight = options.maxHeight || 1.0;\n const filter = options.colorFilter || new Color3(0.3, 0.59, 0.11);\n const alphaFilter = options.alphaFilter || 0.0;\n const updatable = options.updatable;\n const onReady = options.onReady;\n scene = scene || EngineStore.LastCreatedScene;\n const ground = new GroundMesh(name, scene);\n ground._subdivisionsX = subdivisions;\n ground._subdivisionsY = subdivisions;\n ground._width = width;\n ground._height = height;\n ground._maxX = ground._width / 2.0;\n ground._maxZ = ground._height / 2.0;\n ground._minX = -ground._maxX;\n ground._minZ = -ground._maxZ;\n ground._setReady(false);\n const onload = (img) => {\n const bufferWidth = img.width;\n const bufferHeight = img.height;\n if (scene.isDisposed) {\n return;\n }\n const buffer = scene === null || scene === void 0 ? void 0 : scene.getEngine().resizeImageBitmap(img, bufferWidth, bufferHeight);\n const vertexData = CreateGroundFromHeightMapVertexData({\n width: width,\n height: height,\n subdivisions: subdivisions,\n minHeight: minHeight,\n maxHeight: maxHeight,\n colorFilter: filter,\n buffer: buffer,\n bufferWidth: bufferWidth,\n bufferHeight: bufferHeight,\n alphaFilter: alphaFilter,\n });\n vertexData.applyToMesh(ground, updatable);\n //execute ready callback, if set\n if (onReady) {\n onReady(ground);\n }\n ground._setReady(true);\n };\n Tools.LoadImage(url, onload, () => { }, scene.offlineProvider);\n return ground;\n }\n /**\n * Class containing static functions to help procedurally build meshes\n * @deprecated use the functions directly from the module\n */\n const GroundBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateGround,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateGroundFromHeightMap,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateTiledGround,\n };\n VertexData.CreateGround = CreateGroundVertexData;\n VertexData.CreateTiledGround = CreateTiledGroundVertexData;\n VertexData.CreateGroundFromHeightMap = CreateGroundFromHeightMapVertexData;\n Mesh.CreateGround = (name, width, height, subdivisions, scene, updatable) => {\n const options = {\n width,\n height,\n subdivisions,\n updatable,\n };\n return CreateGround(name, options, scene);\n };\n Mesh.CreateTiledGround = (name, xmin, zmin, xmax, zmax, subdivisions, precision, scene, updatable) => {\n const options = {\n xmin,\n zmin,\n xmax,\n zmax,\n subdivisions,\n precision,\n updatable,\n };\n return CreateTiledGround(name, options, scene);\n };\n Mesh.CreateGroundFromHeightMap = (name, url, width, height, subdivisions, minHeight, maxHeight, scene, updatable, onReady, alphaFilter) => {\n const options = {\n width,\n height,\n subdivisions,\n minHeight,\n maxHeight,\n updatable,\n onReady,\n alphaFilter,\n };\n return CreateGroundFromHeightMap(name, url, options, scene);\n };\n\n /**\n * Creates the VertexData for a box\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * size sets the width, height and depth of the box to the value of size, optional default 1\n * * width sets the width (x direction) of the box, overwrites the width set by size, optional, default size\n * * height sets the height (y direction) of the box, overwrites the height set by size, optional, default size\n * * depth sets the depth (z direction) of the box, overwrites the depth set by size, optional, default size\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.depth\n * @param options.faceUV\n * @param options.faceColors\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.wrap\n * @param options.topBaseAt\n * @param options.bottomBaseAt\n * @returns the VertexData of the box\n */\n function CreateBoxVertexData(options) {\n const nbFaces = 6;\n let indices = [0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23];\n const normals = [\n 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0,\n 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0,\n ];\n const uvs = [];\n let positions = [];\n const width = options.width || options.size || 1;\n const height = options.height || options.size || 1;\n const depth = options.depth || options.size || 1;\n const wrap = options.wrap || false;\n let topBaseAt = options.topBaseAt === void 0 ? 1 : options.topBaseAt;\n let bottomBaseAt = options.bottomBaseAt === void 0 ? 0 : options.bottomBaseAt;\n topBaseAt = (topBaseAt + 4) % 4; // places values as 0 to 3\n bottomBaseAt = (bottomBaseAt + 4) % 4; // places values as 0 to 3\n const topOrder = [2, 0, 3, 1];\n const bottomOrder = [2, 0, 1, 3];\n let topIndex = topOrder[topBaseAt];\n let bottomIndex = bottomOrder[bottomBaseAt];\n let basePositions = [\n 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1,\n 1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1,\n ];\n if (wrap) {\n indices = [2, 3, 0, 2, 0, 1, 4, 5, 6, 4, 6, 7, 9, 10, 11, 9, 11, 8, 12, 14, 15, 12, 13, 14];\n basePositions = [\n -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1,\n ];\n let topFaceBase = [\n [1, 1, 1],\n [-1, 1, 1],\n [-1, 1, -1],\n [1, 1, -1],\n ];\n let bottomFaceBase = [\n [-1, -1, 1],\n [1, -1, 1],\n [1, -1, -1],\n [-1, -1, -1],\n ];\n const topFaceOrder = [17, 18, 19, 16];\n const bottomFaceOrder = [22, 23, 20, 21];\n while (topIndex > 0) {\n topFaceBase.unshift(topFaceBase.pop());\n topFaceOrder.unshift(topFaceOrder.pop());\n topIndex--;\n }\n while (bottomIndex > 0) {\n bottomFaceBase.unshift(bottomFaceBase.pop());\n bottomFaceOrder.unshift(bottomFaceOrder.pop());\n bottomIndex--;\n }\n topFaceBase = topFaceBase.flat();\n bottomFaceBase = bottomFaceBase.flat();\n basePositions = basePositions.concat(topFaceBase).concat(bottomFaceBase);\n indices.push(topFaceOrder[0], topFaceOrder[2], topFaceOrder[3], topFaceOrder[0], topFaceOrder[1], topFaceOrder[2]);\n indices.push(bottomFaceOrder[0], bottomFaceOrder[2], bottomFaceOrder[3], bottomFaceOrder[0], bottomFaceOrder[1], bottomFaceOrder[2]);\n }\n const scaleArray = [width / 2, height / 2, depth / 2];\n positions = basePositions.reduce((accumulator, currentValue, currentIndex) => accumulator.concat(currentValue * scaleArray[currentIndex % 3]), []);\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const faceUV = options.faceUV || new Array(6);\n const faceColors = options.faceColors;\n const colors = [];\n // default face colors and UV if undefined\n for (let f = 0; f < 6; f++) {\n if (faceUV[f] === undefined) {\n faceUV[f] = new Vector4(0, 0, 1, 1);\n }\n if (faceColors && faceColors[f] === undefined) {\n faceColors[f] = new Color4(1, 1, 1, 1);\n }\n }\n // Create each face in turn.\n for (let index = 0; index < nbFaces; index++) {\n uvs.push(faceUV[index].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].w : faceUV[index].w);\n uvs.push(faceUV[index].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].w : faceUV[index].w);\n uvs.push(faceUV[index].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].y : faceUV[index].y);\n uvs.push(faceUV[index].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].y : faceUV[index].y);\n if (faceColors) {\n for (let c = 0; c < 4; c++) {\n colors.push(faceColors[index].r, faceColors[index].g, faceColors[index].b, faceColors[index].a);\n }\n }\n }\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n if (faceColors) {\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\n vertexData.colors = totalColors;\n }\n return vertexData;\n }\n /**\n * Creates a box mesh\n * * The parameter `size` sets the size (float) of each box side (default 1)\n * * You can set some different box dimensions by using the parameters `width`, `height` and `depth` (all by default have the same value of `size`)\n * * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of 6 Color3 elements) and `faceUV` (an array of 6 Vector4 elements)\n * * Please read this tutorial : https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#box\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.depth\n * @param options.faceUV\n * @param options.faceColors\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.wrap\n * @param options.topBaseAt\n * @param options.bottomBaseAt\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the box mesh\n */\n function CreateBox(name, options = {}, scene = null) {\n const box = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n box._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateBoxVertexData(options);\n vertexData.applyToMesh(box, options.updatable);\n return box;\n }\n /**\n * Class containing static functions to help procedurally build meshes\n * @deprecated please use CreateBox directly\n */\n const BoxBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateBox,\n };\n // Side effects\n VertexData.CreateBox = CreateBoxVertexData;\n Mesh.CreateBox = (name, size, scene = null, updatable, sideOrientation) => {\n const options = {\n size,\n sideOrientation,\n updatable,\n };\n return CreateBox(name, options, scene);\n };\n\n /**\n * The EnvironmentHelper class can be used to add a fully featured non-expensive background to your scene.\n * It includes by default a skybox and a ground relying on the BackgroundMaterial.\n * It also helps with the default setup of your ImageProcessingConfiguration.\n */\n class EnvironmentHelper {\n /**\n * Creates the default options for the helper.\n * @param scene The scene the environment helper belongs to.\n */\n static _GetDefaultOptions(scene) {\n return {\n createGround: true,\n groundSize: 15,\n groundTexture: this._GroundTextureCDNUrl,\n groundColor: new Color3(0.2, 0.2, 0.3).toLinearSpace(scene.getEngine().useExactSrgbConversions).scale(3),\n groundOpacity: 0.9,\n enableGroundShadow: true,\n groundShadowLevel: 0.5,\n enableGroundMirror: false,\n groundMirrorSizeRatio: 0.3,\n groundMirrorBlurKernel: 64,\n groundMirrorAmount: 1,\n groundMirrorFresnelWeight: 1,\n groundMirrorFallOffDistance: 0,\n groundMirrorTextureType: 0,\n groundYBias: 0.00001,\n createSkybox: true,\n skyboxSize: 20,\n skyboxTexture: this._SkyboxTextureCDNUrl,\n skyboxColor: new Color3(0.2, 0.2, 0.3).toLinearSpace(scene.getEngine().useExactSrgbConversions).scale(3),\n backgroundYRotation: 0,\n sizeAuto: true,\n rootPosition: Vector3.Zero(),\n setupImageProcessing: true,\n environmentTexture: this._EnvironmentTextureCDNUrl,\n cameraExposure: 0.8,\n cameraContrast: 1.2,\n toneMappingEnabled: true,\n };\n }\n /**\n * Gets the root mesh created by the helper.\n */\n get rootMesh() {\n return this._rootMesh;\n }\n /**\n * Gets the skybox created by the helper.\n */\n get skybox() {\n return this._skybox;\n }\n /**\n * Gets the skybox texture created by the helper.\n */\n get skyboxTexture() {\n return this._skyboxTexture;\n }\n /**\n * Gets the skybox material created by the helper.\n */\n get skyboxMaterial() {\n return this._skyboxMaterial;\n }\n /**\n * Gets the ground mesh created by the helper.\n */\n get ground() {\n return this._ground;\n }\n /**\n * Gets the ground texture created by the helper.\n */\n get groundTexture() {\n return this._groundTexture;\n }\n /**\n * Gets the ground mirror created by the helper.\n */\n get groundMirror() {\n return this._groundMirror;\n }\n /**\n * Gets the ground mirror render list to helps pushing the meshes\n * you wish in the ground reflection.\n */\n get groundMirrorRenderList() {\n if (this._groundMirror) {\n return this._groundMirror.renderList;\n }\n return null;\n }\n /**\n * Gets the ground material created by the helper.\n */\n get groundMaterial() {\n return this._groundMaterial;\n }\n /**\n * constructor\n * @param options Defines the options we want to customize the helper\n * @param scene The scene to add the material to\n */\n constructor(options, scene) {\n this._errorHandler = (message, exception) => {\n this.onErrorObservable.notifyObservers({ message: message, exception: exception });\n };\n this._options = Object.assign(Object.assign({}, EnvironmentHelper._GetDefaultOptions(scene)), options);\n this._scene = scene;\n this.onErrorObservable = new Observable$1();\n this._setupBackground();\n this._setupImageProcessing();\n }\n /**\n * Updates the background according to the new options\n * @param options\n */\n updateOptions(options) {\n const newOptions = Object.assign(Object.assign({}, this._options), options);\n if (this._ground && !newOptions.createGround) {\n this._ground.dispose();\n this._ground = null;\n }\n if (this._groundMaterial && !newOptions.createGround) {\n this._groundMaterial.dispose();\n this._groundMaterial = null;\n }\n if (this._groundTexture) {\n if (this._options.groundTexture != newOptions.groundTexture) {\n this._groundTexture.dispose();\n this._groundTexture = null;\n }\n }\n if (this._skybox && !newOptions.createSkybox) {\n this._skybox.dispose();\n this._skybox = null;\n }\n if (this._skyboxMaterial && !newOptions.createSkybox) {\n this._skyboxMaterial.dispose();\n this._skyboxMaterial = null;\n }\n if (this._skyboxTexture) {\n if (this._options.skyboxTexture != newOptions.skyboxTexture) {\n this._skyboxTexture.dispose();\n this._skyboxTexture = null;\n }\n }\n if (this._groundMirror && !newOptions.enableGroundMirror) {\n this._groundMirror.dispose();\n this._groundMirror = null;\n }\n if (this._scene.environmentTexture) {\n if (this._options.environmentTexture != newOptions.environmentTexture) {\n this._scene.environmentTexture.dispose();\n }\n }\n this._options = newOptions;\n this._setupBackground();\n this._setupImageProcessing();\n }\n /**\n * Sets the primary color of all the available elements.\n * @param color the main color to affect to the ground and the background\n */\n setMainColor(color) {\n if (this.groundMaterial) {\n this.groundMaterial.primaryColor = color;\n }\n if (this.skyboxMaterial) {\n this.skyboxMaterial.primaryColor = color;\n }\n if (this.groundMirror) {\n this.groundMirror.clearColor = new Color4(color.r, color.g, color.b, 1.0);\n }\n }\n /**\n * Setup the image processing according to the specified options.\n */\n _setupImageProcessing() {\n if (this._options.setupImageProcessing) {\n this._scene.imageProcessingConfiguration.contrast = this._options.cameraContrast;\n this._scene.imageProcessingConfiguration.exposure = this._options.cameraExposure;\n this._scene.imageProcessingConfiguration.toneMappingEnabled = this._options.toneMappingEnabled;\n this._setupEnvironmentTexture();\n }\n }\n /**\n * Setup the environment texture according to the specified options.\n */\n _setupEnvironmentTexture() {\n if (this._scene.environmentTexture) {\n return;\n }\n if (this._options.environmentTexture instanceof BaseTexture) {\n this._scene.environmentTexture = this._options.environmentTexture;\n return;\n }\n const environmentTexture = CubeTexture.CreateFromPrefilteredData(this._options.environmentTexture, this._scene);\n this._scene.environmentTexture = environmentTexture;\n }\n /**\n * Setup the background according to the specified options.\n */\n _setupBackground() {\n if (!this._rootMesh) {\n this._rootMesh = new Mesh(\"BackgroundHelper\", this._scene);\n }\n this._rootMesh.rotation.y = this._options.backgroundYRotation;\n const sceneSize = this._getSceneSize();\n if (this._options.createGround) {\n this._setupGround(sceneSize);\n this._setupGroundMaterial();\n this._setupGroundDiffuseTexture();\n if (this._options.enableGroundMirror) {\n this._setupGroundMirrorTexture(sceneSize);\n }\n this._setupMirrorInGroundMaterial();\n }\n if (this._options.createSkybox) {\n this._setupSkybox(sceneSize);\n this._setupSkyboxMaterial();\n this._setupSkyboxReflectionTexture();\n }\n this._rootMesh.position.x = sceneSize.rootPosition.x;\n this._rootMesh.position.z = sceneSize.rootPosition.z;\n this._rootMesh.position.y = sceneSize.rootPosition.y;\n }\n /**\n * Get the scene sizes according to the setup.\n */\n _getSceneSize() {\n let groundSize = this._options.groundSize;\n let skyboxSize = this._options.skyboxSize;\n let rootPosition = this._options.rootPosition;\n if (!this._scene.meshes || this._scene.meshes.length === 1) {\n // 1 only means the root of the helper.\n return { groundSize, skyboxSize, rootPosition };\n }\n const sceneExtends = this._scene.getWorldExtends((mesh) => {\n return mesh !== this._ground && mesh !== this._rootMesh && mesh !== this._skybox;\n });\n const sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);\n if (this._options.sizeAuto) {\n if (this._scene.activeCamera instanceof ArcRotateCamera && this._scene.activeCamera.upperRadiusLimit) {\n groundSize = this._scene.activeCamera.upperRadiusLimit * 2;\n skyboxSize = groundSize;\n }\n const sceneDiagonalLenght = sceneDiagonal.length();\n if (sceneDiagonalLenght > groundSize) {\n groundSize = sceneDiagonalLenght * 2;\n skyboxSize = groundSize;\n }\n // 10 % bigger.\n groundSize *= 1.1;\n skyboxSize *= 1.5;\n rootPosition = sceneExtends.min.add(sceneDiagonal.scale(0.5));\n rootPosition.y = sceneExtends.min.y - this._options.groundYBias;\n }\n return { groundSize, skyboxSize, rootPosition };\n }\n /**\n * Setup the ground according to the specified options.\n * @param sceneSize\n */\n _setupGround(sceneSize) {\n if (!this._ground || this._ground.isDisposed()) {\n this._ground = CreatePlane(\"BackgroundPlane\", { size: sceneSize.groundSize }, this._scene);\n this._ground.rotation.x = Math.PI / 2; // Face up by default.\n this._ground.parent = this._rootMesh;\n this._ground.onDisposeObservable.add(() => {\n this._ground = null;\n });\n }\n this._ground.receiveShadows = this._options.enableGroundShadow;\n }\n /**\n * Setup the ground material according to the specified options.\n */\n _setupGroundMaterial() {\n if (!this._groundMaterial) {\n this._groundMaterial = new BackgroundMaterial(\"BackgroundPlaneMaterial\", this._scene);\n }\n this._groundMaterial.alpha = this._options.groundOpacity;\n this._groundMaterial.alphaMode = 8;\n this._groundMaterial.shadowLevel = this._options.groundShadowLevel;\n this._groundMaterial.primaryColor = this._options.groundColor;\n this._groundMaterial.useRGBColor = false;\n this._groundMaterial.enableNoise = true;\n if (this._ground) {\n this._ground.material = this._groundMaterial;\n }\n }\n /**\n * Setup the ground diffuse texture according to the specified options.\n */\n _setupGroundDiffuseTexture() {\n if (!this._groundMaterial) {\n return;\n }\n if (this._groundTexture) {\n return;\n }\n if (this._options.groundTexture instanceof BaseTexture) {\n this._groundMaterial.diffuseTexture = this._options.groundTexture;\n return;\n }\n this._groundTexture = new Texture(this._options.groundTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);\n this._groundTexture.gammaSpace = false;\n this._groundTexture.hasAlpha = true;\n this._groundMaterial.diffuseTexture = this._groundTexture;\n }\n /**\n * Setup the ground mirror texture according to the specified options.\n * @param sceneSize\n */\n _setupGroundMirrorTexture(sceneSize) {\n const wrapping = Texture.CLAMP_ADDRESSMODE;\n if (!this._groundMirror) {\n this._groundMirror = new MirrorTexture(\"BackgroundPlaneMirrorTexture\", { ratio: this._options.groundMirrorSizeRatio }, this._scene, false, this._options.groundMirrorTextureType, Texture.BILINEAR_SAMPLINGMODE, true);\n this._groundMirror.mirrorPlane = new Plane(0, -1, 0, sceneSize.rootPosition.y);\n this._groundMirror.anisotropicFilteringLevel = 1;\n this._groundMirror.wrapU = wrapping;\n this._groundMirror.wrapV = wrapping;\n if (this._groundMirror.renderList) {\n for (let i = 0; i < this._scene.meshes.length; i++) {\n const mesh = this._scene.meshes[i];\n if (mesh !== this._ground && mesh !== this._skybox && mesh !== this._rootMesh) {\n this._groundMirror.renderList.push(mesh);\n }\n }\n }\n }\n const gammaGround = this._options.groundColor.toGammaSpace(this._scene.getEngine().useExactSrgbConversions);\n this._groundMirror.clearColor = new Color4(gammaGround.r, gammaGround.g, gammaGround.b, 1);\n this._groundMirror.adaptiveBlurKernel = this._options.groundMirrorBlurKernel;\n }\n /**\n * Setup the ground to receive the mirror texture.\n */\n _setupMirrorInGroundMaterial() {\n if (this._groundMaterial) {\n this._groundMaterial.reflectionTexture = this._groundMirror;\n this._groundMaterial.reflectionFresnel = true;\n this._groundMaterial.reflectionAmount = this._options.groundMirrorAmount;\n this._groundMaterial.reflectionStandardFresnelWeight = this._options.groundMirrorFresnelWeight;\n this._groundMaterial.reflectionFalloffDistance = this._options.groundMirrorFallOffDistance;\n }\n }\n /**\n * Setup the skybox according to the specified options.\n * @param sceneSize\n */\n _setupSkybox(sceneSize) {\n if (!this._skybox || this._skybox.isDisposed()) {\n this._skybox = CreateBox(\"BackgroundSkybox\", { size: sceneSize.skyboxSize, sideOrientation: Mesh.BACKSIDE }, this._scene);\n this._skybox.onDisposeObservable.add(() => {\n this._skybox = null;\n });\n }\n this._skybox.parent = this._rootMesh;\n }\n /**\n * Setup the skybox material according to the specified options.\n */\n _setupSkyboxMaterial() {\n if (!this._skybox) {\n return;\n }\n if (!this._skyboxMaterial) {\n this._skyboxMaterial = new BackgroundMaterial(\"BackgroundSkyboxMaterial\", this._scene);\n }\n this._skyboxMaterial.useRGBColor = false;\n this._skyboxMaterial.primaryColor = this._options.skyboxColor;\n this._skyboxMaterial.enableNoise = true;\n this._skybox.material = this._skyboxMaterial;\n }\n /**\n * Setup the skybox reflection texture according to the specified options.\n */\n _setupSkyboxReflectionTexture() {\n if (!this._skyboxMaterial) {\n return;\n }\n if (this._skyboxTexture) {\n return;\n }\n if (this._options.skyboxTexture instanceof BaseTexture) {\n this._skyboxMaterial.reflectionTexture = this._options.skyboxTexture;\n return;\n }\n this._skyboxTexture = new CubeTexture(this._options.skyboxTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);\n this._skyboxTexture.coordinatesMode = Texture.SKYBOX_MODE;\n this._skyboxTexture.gammaSpace = false;\n this._skyboxMaterial.reflectionTexture = this._skyboxTexture;\n }\n /**\n * Dispose all the elements created by the Helper.\n */\n dispose() {\n if (this._groundMaterial) {\n this._groundMaterial.dispose(true, true);\n }\n if (this._skyboxMaterial) {\n this._skyboxMaterial.dispose(true, true);\n }\n this._rootMesh.dispose(false);\n }\n }\n /**\n * Default ground texture URL.\n */\n EnvironmentHelper._GroundTextureCDNUrl = \"https://assets.babylonjs.com/environments/backgroundGround.png\";\n /**\n * Default skybox texture URL.\n */\n EnvironmentHelper._SkyboxTextureCDNUrl = \"https://assets.babylonjs.com/environments/backgroundSkybox.dds\";\n /**\n * Default environment texture URL.\n */\n EnvironmentHelper._EnvironmentTextureCDNUrl = \"https://assets.babylonjs.com/environments/environmentSpecular.env\";\n\n /**\n * Manage the keyboard inputs to control the movement of a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraKeyboardMoveInput {\n constructor() {\n /**\n * Gets or Set the list of keyboard keys used to control the forward move of the camera.\n */\n this.keysUp = [38];\n /**\n * Gets or Set the list of keyboard keys used to control the upward move of the camera.\n */\n this.keysUpward = [33];\n /**\n * Gets or Set the list of keyboard keys used to control the backward move of the camera.\n */\n this.keysDown = [40];\n /**\n * Gets or Set the list of keyboard keys used to control the downward move of the camera.\n */\n this.keysDownward = [34];\n /**\n * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.\n */\n this.keysLeft = [37];\n /**\n * Gets or Set the list of keyboard keys used to control the right strafe move of the camera.\n */\n this.keysRight = [39];\n /**\n * Defines the pointer angular sensibility along the X and Y axis or how fast is the camera rotating.\n */\n this.rotationSpeed = 0.5;\n /**\n * Gets or Set the list of keyboard keys used to control the left rotation move of the camera.\n */\n this.keysRotateLeft = [];\n /**\n * Gets or Set the list of keyboard keys used to control the right rotation move of the camera.\n */\n this.keysRotateRight = [];\n /**\n * Gets or Set the list of keyboard keys used to control the up rotation move of the camera.\n */\n this.keysRotateUp = [];\n /**\n * Gets or Set the list of keyboard keys used to control the down rotation move of the camera.\n */\n this.keysRotateDown = [];\n this._keys = new Array();\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n if (this._onCanvasBlurObserver) {\n return;\n }\n this._scene = this.camera.getScene();\n this._engine = this._scene.getEngine();\n this._onCanvasBlurObserver = this._engine.onCanvasBlurObservable.add(() => {\n this._keys.length = 0;\n });\n this._onKeyboardObserver = this._scene.onKeyboardObservable.add((info) => {\n const evt = info.event;\n if (!evt.metaKey) {\n if (info.type === KeyboardEventTypes.KEYDOWN) {\n if (this.keysUp.indexOf(evt.keyCode) !== -1 ||\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\n this.keysUpward.indexOf(evt.keyCode) !== -1 ||\n this.keysDownward.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateLeft.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateRight.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateUp.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateDown.indexOf(evt.keyCode) !== -1) {\n const index = this._keys.indexOf(evt.keyCode);\n if (index === -1) {\n this._keys.push(evt.keyCode);\n }\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n }\n }\n else {\n if (this.keysUp.indexOf(evt.keyCode) !== -1 ||\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\n this.keysUpward.indexOf(evt.keyCode) !== -1 ||\n this.keysDownward.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateLeft.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateRight.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateUp.indexOf(evt.keyCode) !== -1 ||\n this.keysRotateDown.indexOf(evt.keyCode) !== -1) {\n const index = this._keys.indexOf(evt.keyCode);\n if (index >= 0) {\n this._keys.splice(index, 1);\n }\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n }\n }\n }\n });\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._scene) {\n if (this._onKeyboardObserver) {\n this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);\n }\n if (this._onCanvasBlurObserver) {\n this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);\n }\n this._onKeyboardObserver = null;\n this._onCanvasBlurObserver = null;\n }\n this._keys.length = 0;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this._onKeyboardObserver) {\n const camera = this.camera;\n // Keyboard\n for (let index = 0; index < this._keys.length; index++) {\n const keyCode = this._keys[index];\n const speed = camera._computeLocalCameraSpeed();\n if (this.keysLeft.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(-speed, 0, 0);\n }\n else if (this.keysUp.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, 0, speed);\n }\n else if (this.keysRight.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(speed, 0, 0);\n }\n else if (this.keysDown.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, 0, -speed);\n }\n else if (this.keysUpward.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, speed, 0);\n }\n else if (this.keysDownward.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, -speed, 0);\n }\n else if (this.keysRotateLeft.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, 0, 0);\n camera.cameraRotation.y -= this._getLocalRotation();\n }\n else if (this.keysRotateRight.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, 0, 0);\n camera.cameraRotation.y += this._getLocalRotation();\n }\n else if (this.keysRotateUp.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, 0, 0);\n camera.cameraRotation.x -= this._getLocalRotation();\n }\n else if (this.keysRotateDown.indexOf(keyCode) !== -1) {\n camera._localDirection.copyFromFloats(0, 0, 0);\n camera.cameraRotation.x += this._getLocalRotation();\n }\n if (camera.getScene().useRightHandedSystem) {\n camera._localDirection.z *= -1;\n }\n camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);\n Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);\n camera.cameraDirection.addInPlace(camera._transformedDirection);\n }\n }\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCameraKeyboardMoveInput\";\n }\n /** @internal */\n _onLostFocus() {\n this._keys.length = 0;\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"keyboard\";\n }\n _getLocalRotation() {\n let rotation = (this.rotationSpeed * this._engine.getDeltaTime()) / 1000;\n if (this.camera.getScene().useRightHandedSystem) {\n rotation *= -1;\n }\n if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) {\n rotation *= -1;\n }\n return rotation;\n }\n }\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysUp\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysUpward\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysDown\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysDownward\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysLeft\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysRight\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"rotationSpeed\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysRotateLeft\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysRotateRight\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysRotateUp\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraKeyboardMoveInput.prototype, \"keysRotateDown\", void 0);\n CameraInputTypes[\"FreeCameraKeyboardMoveInput\"] = FreeCameraKeyboardMoveInput;\n\n /**\n * Manage the mouse inputs to control the movement of a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraMouseInput {\n /**\n * Manage the mouse inputs to control the movement of a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n * @param touchEnabled Defines if touch is enabled or not\n */\n constructor(\n /**\n * Define if touch is enabled in the mouse input\n */\n touchEnabled = true) {\n this.touchEnabled = touchEnabled;\n /**\n * Defines the buttons associated with the input to handle camera move.\n */\n this.buttons = [0, 1, 2];\n /**\n * Defines the pointer angular sensibility along the X and Y axis or how fast is the camera rotating.\n */\n this.angularSensibility = 2000.0;\n this._previousPosition = null;\n /**\n * Observable for when a pointer move event occurs containing the move offset\n */\n this.onPointerMovedObservable = new Observable$1();\n /**\n * @internal\n * If the camera should be rotated automatically based on pointer movement\n */\n this._allowCameraRotation = true;\n this._currentActiveButton = -1;\n this._activePointerId = -1;\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n const engine = this.camera.getEngine();\n const element = engine.getInputElement();\n if (!this._pointerInput) {\n this._pointerInput = (p) => {\n const evt = p.event;\n const isTouch = evt.pointerType === \"touch\";\n if (engine.isInVRExclusivePointerMode) {\n return;\n }\n if (!this.touchEnabled && isTouch) {\n return;\n }\n if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {\n return;\n }\n const srcElement = evt.target;\n if (p.type === PointerEventTypes.POINTERDOWN) {\n // If the input is touch with more than one touch OR if the input is mouse and there is already an active button, return\n if ((isTouch && this._activePointerId !== -1) || (!isTouch && this._currentActiveButton !== -1)) {\n return;\n }\n this._activePointerId = evt.pointerId;\n try {\n srcElement === null || srcElement === void 0 ? void 0 : srcElement.setPointerCapture(evt.pointerId);\n }\n catch (e) {\n //Nothing to do with the error. Execution will continue.\n }\n if (this._currentActiveButton === -1) {\n this._currentActiveButton = evt.button;\n }\n this._previousPosition = {\n x: evt.clientX,\n y: evt.clientY,\n };\n if (!noPreventDefault) {\n evt.preventDefault();\n element && element.focus();\n }\n // This is required to move while pointer button is down\n if (engine.isPointerLock && this._onMouseMove) {\n this._onMouseMove(p.event);\n }\n }\n else if (p.type === PointerEventTypes.POINTERUP) {\n // If input is touch with a different touch id OR if input is mouse with a different button, return\n if ((isTouch && this._activePointerId !== evt.pointerId) || (!isTouch && this._currentActiveButton !== evt.button)) {\n return;\n }\n try {\n srcElement === null || srcElement === void 0 ? void 0 : srcElement.releasePointerCapture(evt.pointerId);\n }\n catch (e) {\n //Nothing to do with the error.\n }\n this._currentActiveButton = -1;\n this._previousPosition = null;\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n this._activePointerId = -1;\n }\n else if (p.type === PointerEventTypes.POINTERMOVE && (this._activePointerId === evt.pointerId || !isTouch)) {\n if (engine.isPointerLock && this._onMouseMove) {\n this._onMouseMove(p.event);\n }\n else if (this._previousPosition) {\n let offsetX = evt.clientX - this._previousPosition.x;\n const offsetY = evt.clientY - this._previousPosition.y;\n if (this.camera.getScene().useRightHandedSystem) {\n offsetX *= -1;\n }\n if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) {\n offsetX *= -1;\n }\n if (this._allowCameraRotation) {\n this.camera.cameraRotation.y += offsetX / this.angularSensibility;\n this.camera.cameraRotation.x += offsetY / this.angularSensibility;\n }\n this.onPointerMovedObservable.notifyObservers({ offsetX: offsetX, offsetY: offsetY });\n this._previousPosition = {\n x: evt.clientX,\n y: evt.clientY,\n };\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n }\n }\n };\n }\n this._onMouseMove = (evt) => {\n if (!engine.isPointerLock) {\n return;\n }\n if (engine.isInVRExclusivePointerMode) {\n return;\n }\n let offsetX = evt.movementX;\n if (this.camera.getScene().useRightHandedSystem) {\n offsetX *= -1;\n }\n if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) {\n offsetX *= -1;\n }\n this.camera.cameraRotation.y += offsetX / this.angularSensibility;\n const offsetY = evt.movementY;\n this.camera.cameraRotation.x += offsetY / this.angularSensibility;\n this._previousPosition = null;\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n };\n this._observer = this.camera\n .getScene()\n ._inputManager._addCameraPointerObserver(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);\n if (element) {\n this._contextMenuBind = this.onContextMenu.bind(this);\n element.addEventListener(\"contextmenu\", this._contextMenuBind, false); // TODO: We need to figure out how to handle this for Native\n }\n }\n /**\n * Called on JS contextmenu event.\n * Override this method to provide functionality.\n * @param evt\n */\n onContextMenu(evt) {\n evt.preventDefault();\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._observer) {\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\n if (this._contextMenuBind) {\n const engine = this.camera.getEngine();\n const element = engine.getInputElement();\n element && element.removeEventListener(\"contextmenu\", this._contextMenuBind);\n }\n if (this.onPointerMovedObservable) {\n this.onPointerMovedObservable.clear();\n }\n this._observer = null;\n this._onMouseMove = null;\n this._previousPosition = null;\n }\n this._activePointerId = -1;\n this._currentActiveButton = -1;\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCameraMouseInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"mouse\";\n }\n }\n __decorate$1([\n serialize()\n ], FreeCameraMouseInput.prototype, \"buttons\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraMouseInput.prototype, \"angularSensibility\", void 0);\n CameraInputTypes[\"FreeCameraMouseInput\"] = FreeCameraMouseInput;\n\n /**\n * Base class for mouse wheel input..\n * See FollowCameraMouseWheelInput in src/Cameras/Inputs/freeCameraMouseWheelInput.ts\n * for example usage.\n */\n class BaseCameraMouseWheelInput {\n constructor() {\n /**\n * How fast is the camera moves in relation to X axis mouseWheel events.\n * Use negative value to reverse direction.\n */\n this.wheelPrecisionX = 3.0;\n /**\n * How fast is the camera moves in relation to Y axis mouseWheel events.\n * Use negative value to reverse direction.\n */\n this.wheelPrecisionY = 3.0;\n /**\n * How fast is the camera moves in relation to Z axis mouseWheel events.\n * Use negative value to reverse direction.\n */\n this.wheelPrecisionZ = 3.0;\n /**\n * Observable for when a mouse wheel move event occurs.\n */\n this.onChangedObservable = new Observable$1();\n /**\n * Incremental value of multiple mouse wheel movements of the X axis.\n * Should be zero-ed when read.\n */\n this._wheelDeltaX = 0;\n /**\n * Incremental value of multiple mouse wheel movements of the Y axis.\n * Should be zero-ed when read.\n */\n this._wheelDeltaY = 0;\n /**\n * Incremental value of multiple mouse wheel movements of the Z axis.\n * Should be zero-ed when read.\n */\n this._wheelDeltaZ = 0;\n /**\n * Firefox uses a different scheme to report scroll distances to other\n * browsers. Rather than use complicated methods to calculate the exact\n * multiple we need to apply, let's just cheat and use a constant.\n * https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode\n * https://stackoverflow.com/questions/20110224/what-is-the-height-of-a-line-in-a-wheel-event-deltamode-dom-delta-line\n */\n this._ffMultiplier = 12;\n /**\n * Different event attributes for wheel data fall into a few set ranges.\n * Some relevant but dated date here:\n * https://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers\n */\n this._normalize = 120;\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls\n * should call preventdefault().\n * (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n this._wheel = (pointer) => {\n // sanity check - this should be a PointerWheel event.\n if (pointer.type !== PointerEventTypes.POINTERWHEEL) {\n return;\n }\n const event = pointer.event;\n const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? this._ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly\n this._wheelDeltaX += (this.wheelPrecisionX * platformScale * event.deltaX) / this._normalize;\n this._wheelDeltaY -= (this.wheelPrecisionY * platformScale * event.deltaY) / this._normalize;\n this._wheelDeltaZ += (this.wheelPrecisionZ * platformScale * event.deltaZ) / this._normalize;\n if (event.preventDefault) {\n if (!noPreventDefault) {\n event.preventDefault();\n }\n }\n };\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel, PointerEventTypes.POINTERWHEEL);\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._observer) {\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\n this._observer = null;\n this._wheel = null;\n }\n if (this.onChangedObservable) {\n this.onChangedObservable.clear();\n }\n }\n /**\n * Called for each rendered frame.\n */\n checkInputs() {\n this.onChangedObservable.notifyObservers({\n wheelDeltaX: this._wheelDeltaX,\n wheelDeltaY: this._wheelDeltaY,\n wheelDeltaZ: this._wheelDeltaZ,\n });\n // Clear deltas.\n this._wheelDeltaX = 0;\n this._wheelDeltaY = 0;\n this._wheelDeltaZ = 0;\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"BaseCameraMouseWheelInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"mousewheel\";\n }\n }\n __decorate$1([\n serialize()\n ], BaseCameraMouseWheelInput.prototype, \"wheelPrecisionX\", void 0);\n __decorate$1([\n serialize()\n ], BaseCameraMouseWheelInput.prototype, \"wheelPrecisionY\", void 0);\n __decorate$1([\n serialize()\n ], BaseCameraMouseWheelInput.prototype, \"wheelPrecisionZ\", void 0);\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n var _CameraProperty;\n (function (_CameraProperty) {\n _CameraProperty[_CameraProperty[\"MoveRelative\"] = 0] = \"MoveRelative\";\n _CameraProperty[_CameraProperty[\"RotateRelative\"] = 1] = \"RotateRelative\";\n _CameraProperty[_CameraProperty[\"MoveScene\"] = 2] = \"MoveScene\";\n })(_CameraProperty || (_CameraProperty = {}));\n /**\n * Manage the mouse wheel inputs to control a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraMouseWheelInput extends BaseCameraMouseWheelInput {\n constructor() {\n super(...arguments);\n this._moveRelative = Vector3.Zero();\n this._rotateRelative = Vector3.Zero();\n this._moveScene = Vector3.Zero();\n /**\n * These are set to the desired default behaviour.\n */\n this._wheelXAction = _CameraProperty.MoveRelative;\n this._wheelXActionCoordinate = Coordinate.X;\n this._wheelYAction = _CameraProperty.MoveRelative;\n this._wheelYActionCoordinate = Coordinate.Z;\n this._wheelZAction = null;\n this._wheelZActionCoordinate = null;\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCameraMouseWheelInput\";\n }\n /**\n * Set which movement axis (relative to camera's orientation) the mouse\n * wheel's X axis controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelXMoveRelative(axis) {\n if (axis === null && this._wheelXAction !== _CameraProperty.MoveRelative) {\n // Attempting to clear different _wheelXAction.\n return;\n }\n this._wheelXAction = _CameraProperty.MoveRelative;\n this._wheelXActionCoordinate = axis;\n }\n /**\n * Get the configured movement axis (relative to camera's orientation) the\n * mouse wheel's X axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelXMoveRelative() {\n if (this._wheelXAction !== _CameraProperty.MoveRelative) {\n return null;\n }\n return this._wheelXActionCoordinate;\n }\n /**\n * Set which movement axis (relative to camera's orientation) the mouse\n * wheel's Y axis controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelYMoveRelative(axis) {\n if (axis === null && this._wheelYAction !== _CameraProperty.MoveRelative) {\n // Attempting to clear different _wheelYAction.\n return;\n }\n this._wheelYAction = _CameraProperty.MoveRelative;\n this._wheelYActionCoordinate = axis;\n }\n /**\n * Get the configured movement axis (relative to camera's orientation) the\n * mouse wheel's Y axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelYMoveRelative() {\n if (this._wheelYAction !== _CameraProperty.MoveRelative) {\n return null;\n }\n return this._wheelYActionCoordinate;\n }\n /**\n * Set which movement axis (relative to camera's orientation) the mouse\n * wheel's Z axis controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelZMoveRelative(axis) {\n if (axis === null && this._wheelZAction !== _CameraProperty.MoveRelative) {\n // Attempting to clear different _wheelZAction.\n return;\n }\n this._wheelZAction = _CameraProperty.MoveRelative;\n this._wheelZActionCoordinate = axis;\n }\n /**\n * Get the configured movement axis (relative to camera's orientation) the\n * mouse wheel's Z axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelZMoveRelative() {\n if (this._wheelZAction !== _CameraProperty.MoveRelative) {\n return null;\n }\n return this._wheelZActionCoordinate;\n }\n /**\n * Set which rotation axis (relative to camera's orientation) the mouse\n * wheel's X axis controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelXRotateRelative(axis) {\n if (axis === null && this._wheelXAction !== _CameraProperty.RotateRelative) {\n // Attempting to clear different _wheelXAction.\n return;\n }\n this._wheelXAction = _CameraProperty.RotateRelative;\n this._wheelXActionCoordinate = axis;\n }\n /**\n * Get the configured rotation axis (relative to camera's orientation) the\n * mouse wheel's X axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelXRotateRelative() {\n if (this._wheelXAction !== _CameraProperty.RotateRelative) {\n return null;\n }\n return this._wheelXActionCoordinate;\n }\n /**\n * Set which rotation axis (relative to camera's orientation) the mouse\n * wheel's Y axis controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelYRotateRelative(axis) {\n if (axis === null && this._wheelYAction !== _CameraProperty.RotateRelative) {\n // Attempting to clear different _wheelYAction.\n return;\n }\n this._wheelYAction = _CameraProperty.RotateRelative;\n this._wheelYActionCoordinate = axis;\n }\n /**\n * Get the configured rotation axis (relative to camera's orientation) the\n * mouse wheel's Y axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelYRotateRelative() {\n if (this._wheelYAction !== _CameraProperty.RotateRelative) {\n return null;\n }\n return this._wheelYActionCoordinate;\n }\n /**\n * Set which rotation axis (relative to camera's orientation) the mouse\n * wheel's Z axis controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelZRotateRelative(axis) {\n if (axis === null && this._wheelZAction !== _CameraProperty.RotateRelative) {\n // Attempting to clear different _wheelZAction.\n return;\n }\n this._wheelZAction = _CameraProperty.RotateRelative;\n this._wheelZActionCoordinate = axis;\n }\n /**\n * Get the configured rotation axis (relative to camera's orientation) the\n * mouse wheel's Z axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelZRotateRelative() {\n if (this._wheelZAction !== _CameraProperty.RotateRelative) {\n return null;\n }\n return this._wheelZActionCoordinate;\n }\n /**\n * Set which movement axis (relative to the scene) the mouse wheel's X axis\n * controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelXMoveScene(axis) {\n if (axis === null && this._wheelXAction !== _CameraProperty.MoveScene) {\n // Attempting to clear different _wheelXAction.\n return;\n }\n this._wheelXAction = _CameraProperty.MoveScene;\n this._wheelXActionCoordinate = axis;\n }\n /**\n * Get the configured movement axis (relative to the scene) the mouse wheel's\n * X axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelXMoveScene() {\n if (this._wheelXAction !== _CameraProperty.MoveScene) {\n return null;\n }\n return this._wheelXActionCoordinate;\n }\n /**\n * Set which movement axis (relative to the scene) the mouse wheel's Y axis\n * controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelYMoveScene(axis) {\n if (axis === null && this._wheelYAction !== _CameraProperty.MoveScene) {\n // Attempting to clear different _wheelYAction.\n return;\n }\n this._wheelYAction = _CameraProperty.MoveScene;\n this._wheelYActionCoordinate = axis;\n }\n /**\n * Get the configured movement axis (relative to the scene) the mouse wheel's\n * Y axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelYMoveScene() {\n if (this._wheelYAction !== _CameraProperty.MoveScene) {\n return null;\n }\n return this._wheelYActionCoordinate;\n }\n /**\n * Set which movement axis (relative to the scene) the mouse wheel's Z axis\n * controls.\n * @param axis The axis to be moved. Set null to clear.\n */\n set wheelZMoveScene(axis) {\n if (axis === null && this._wheelZAction !== _CameraProperty.MoveScene) {\n // Attempting to clear different _wheelZAction.\n return;\n }\n this._wheelZAction = _CameraProperty.MoveScene;\n this._wheelZActionCoordinate = axis;\n }\n /**\n * Get the configured movement axis (relative to the scene) the mouse wheel's\n * Z axis controls.\n * @returns The configured axis or null if none.\n */\n get wheelZMoveScene() {\n if (this._wheelZAction !== _CameraProperty.MoveScene) {\n return null;\n }\n return this._wheelZActionCoordinate;\n }\n /**\n * Called for each rendered frame.\n */\n checkInputs() {\n if (this._wheelDeltaX === 0 && this._wheelDeltaY === 0 && this._wheelDeltaZ == 0) {\n return;\n }\n // Clear the camera properties that we might be updating.\n this._moveRelative.setAll(0);\n this._rotateRelative.setAll(0);\n this._moveScene.setAll(0);\n // Set the camera properties that are to be updated.\n this._updateCamera();\n if (this.camera.getScene().useRightHandedSystem) {\n // TODO: Does this need done for worldUpdate too?\n this._moveRelative.z *= -1;\n }\n // Convert updates relative to camera to world position update.\n const cameraTransformMatrix = Matrix.Zero();\n this.camera.getViewMatrix().invertToRef(cameraTransformMatrix);\n const transformedDirection = Vector3.Zero();\n Vector3.TransformNormalToRef(this._moveRelative, cameraTransformMatrix, transformedDirection);\n // Apply updates to camera position.\n this.camera.cameraRotation.x += this._rotateRelative.x / 200;\n this.camera.cameraRotation.y += this._rotateRelative.y / 200;\n this.camera.cameraDirection.addInPlace(transformedDirection);\n this.camera.cameraDirection.addInPlace(this._moveScene);\n // Call the base class implementation to handle observers and do cleanup.\n super.checkInputs();\n }\n /**\n * Update the camera according to any configured properties for the 3\n * mouse-wheel axis.\n */\n _updateCamera() {\n // Do the camera updates for each of the 3 touch-wheel axis.\n this._updateCameraProperty(this._wheelDeltaX, this._wheelXAction, this._wheelXActionCoordinate);\n this._updateCameraProperty(this._wheelDeltaY, this._wheelYAction, this._wheelYActionCoordinate);\n this._updateCameraProperty(this._wheelDeltaZ, this._wheelZAction, this._wheelZActionCoordinate);\n }\n /**\n * Update one property of the camera.\n * @param value\n * @param cameraProperty\n * @param coordinate\n */\n _updateCameraProperty(\n /* Mouse-wheel delta. */\n value, \n /* Camera property to be changed. */\n cameraProperty, \n /* Axis of Camera property to be changed. */\n coordinate) {\n if (value === 0) {\n // Mouse wheel has not moved.\n return;\n }\n if (cameraProperty === null || coordinate === null) {\n // Mouse wheel axis not configured.\n return;\n }\n let action = null;\n switch (cameraProperty) {\n case _CameraProperty.MoveRelative:\n action = this._moveRelative;\n break;\n case _CameraProperty.RotateRelative:\n action = this._rotateRelative;\n break;\n case _CameraProperty.MoveScene:\n action = this._moveScene;\n break;\n }\n switch (coordinate) {\n case Coordinate.X:\n action.set(value, 0, 0);\n break;\n case Coordinate.Y:\n action.set(0, value, 0);\n break;\n case Coordinate.Z:\n action.set(0, 0, value);\n break;\n }\n }\n }\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelXMoveRelative\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelYMoveRelative\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelZMoveRelative\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelXRotateRelative\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelYRotateRelative\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelZRotateRelative\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelXMoveScene\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelYMoveScene\", null);\n __decorate$1([\n serialize()\n ], FreeCameraMouseWheelInput.prototype, \"wheelZMoveScene\", null);\n CameraInputTypes[\"FreeCameraMouseWheelInput\"] = FreeCameraMouseWheelInput;\n\n /**\n * Manage the touch inputs to control the movement of a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraTouchInput {\n /**\n * Manage the touch inputs to control the movement of a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n * @param allowMouse Defines if mouse events can be treated as touch events\n */\n constructor(\n /**\n * Define if mouse events can be treated as touch events\n */\n allowMouse = false) {\n this.allowMouse = allowMouse;\n /**\n * Defines the touch sensibility for rotation.\n * The lower the faster.\n */\n this.touchAngularSensibility = 200000.0;\n /**\n * Defines the touch sensibility for move.\n * The lower the faster.\n */\n this.touchMoveSensibility = 250.0;\n /**\n * Swap touch actions so that one touch is used for rotation and multiple for movement\n */\n this.singleFingerRotate = false;\n this._offsetX = null;\n this._offsetY = null;\n this._pointerPressed = new Array();\n this._isSafari = Tools.IsSafari();\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n let previousPosition = null;\n if (this._pointerInput === undefined) {\n this._onLostFocus = () => {\n this._offsetX = null;\n this._offsetY = null;\n };\n this._pointerInput = (p) => {\n const evt = p.event;\n const isMouseEvent = evt.pointerType === \"mouse\" || (this._isSafari && typeof evt.pointerType === \"undefined\");\n if (!this.allowMouse && isMouseEvent) {\n return;\n }\n if (p.type === PointerEventTypes.POINTERDOWN) {\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n this._pointerPressed.push(evt.pointerId);\n if (this._pointerPressed.length !== 1) {\n return;\n }\n previousPosition = {\n x: evt.clientX,\n y: evt.clientY,\n };\n }\n else if (p.type === PointerEventTypes.POINTERUP) {\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n const index = this._pointerPressed.indexOf(evt.pointerId);\n if (index === -1) {\n return;\n }\n this._pointerPressed.splice(index, 1);\n if (index != 0) {\n return;\n }\n previousPosition = null;\n this._offsetX = null;\n this._offsetY = null;\n }\n else if (p.type === PointerEventTypes.POINTERMOVE) {\n if (!noPreventDefault) {\n evt.preventDefault();\n }\n if (!previousPosition) {\n return;\n }\n const index = this._pointerPressed.indexOf(evt.pointerId);\n if (index != 0) {\n return;\n }\n this._offsetX = evt.clientX - previousPosition.x;\n this._offsetY = -(evt.clientY - previousPosition.y);\n }\n };\n }\n this._observer = this.camera\n .getScene()\n ._inputManager._addCameraPointerObserver(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);\n if (this._onLostFocus) {\n const engine = this.camera.getEngine();\n const element = engine.getInputElement();\n element && element.addEventListener(\"blur\", this._onLostFocus);\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n if (this._pointerInput) {\n if (this._observer) {\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\n this._observer = null;\n }\n if (this._onLostFocus) {\n const engine = this.camera.getEngine();\n const element = engine.getInputElement();\n element && element.removeEventListener(\"blur\", this._onLostFocus);\n this._onLostFocus = null;\n }\n this._pointerPressed.length = 0;\n this._offsetX = null;\n this._offsetY = null;\n }\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this._offsetX === null || this._offsetY === null) {\n return;\n }\n if (this._offsetX === 0 && this._offsetY === 0) {\n return;\n }\n const camera = this.camera;\n camera.cameraRotation.y = this._offsetX / this.touchAngularSensibility;\n const rotateCamera = (this.singleFingerRotate && this._pointerPressed.length === 1) || (!this.singleFingerRotate && this._pointerPressed.length > 1);\n if (rotateCamera) {\n camera.cameraRotation.x = -this._offsetY / this.touchAngularSensibility;\n }\n else {\n const speed = camera._computeLocalCameraSpeed();\n const direction = new Vector3(0, 0, this.touchMoveSensibility !== 0 ? (speed * this._offsetY) / this.touchMoveSensibility : 0);\n Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);\n camera.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));\n }\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCameraTouchInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"touch\";\n }\n }\n __decorate$1([\n serialize()\n ], FreeCameraTouchInput.prototype, \"touchAngularSensibility\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraTouchInput.prototype, \"touchMoveSensibility\", void 0);\n CameraInputTypes[\"FreeCameraTouchInput\"] = FreeCameraTouchInput;\n\n /**\n * Default Inputs manager for the FreeCamera.\n * It groups all the default supported inputs for ease of use.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraInputsManager extends CameraInputsManager {\n /**\n * Instantiates a new FreeCameraInputsManager.\n * @param camera Defines the camera the inputs belong to\n */\n constructor(camera) {\n super(camera);\n /**\n * @internal\n */\n this._mouseInput = null;\n /**\n * @internal\n */\n this._mouseWheelInput = null;\n }\n /**\n * Add keyboard input support to the input manager.\n * @returns the current input manager\n */\n addKeyboard() {\n this.add(new FreeCameraKeyboardMoveInput());\n return this;\n }\n /**\n * Add mouse input support to the input manager.\n * @param touchEnabled if the FreeCameraMouseInput should support touch (default: true)\n * @returns the current input manager\n */\n addMouse(touchEnabled = true) {\n if (!this._mouseInput) {\n this._mouseInput = new FreeCameraMouseInput(touchEnabled);\n this.add(this._mouseInput);\n }\n return this;\n }\n /**\n * Removes the mouse input support from the manager\n * @returns the current input manager\n */\n removeMouse() {\n if (this._mouseInput) {\n this.remove(this._mouseInput);\n }\n return this;\n }\n /**\n * Add mouse wheel input support to the input manager.\n * @returns the current input manager\n */\n addMouseWheel() {\n if (!this._mouseWheelInput) {\n this._mouseWheelInput = new FreeCameraMouseWheelInput();\n this.add(this._mouseWheelInput);\n }\n return this;\n }\n /**\n * Removes the mouse wheel input support from the manager\n * @returns the current input manager\n */\n removeMouseWheel() {\n if (this._mouseWheelInput) {\n this.remove(this._mouseWheelInput);\n }\n return this;\n }\n /**\n * Add touch input support to the input manager.\n * @returns the current input manager\n */\n addTouch() {\n this.add(new FreeCameraTouchInput());\n return this;\n }\n /**\n * Remove all attached input methods from a camera\n */\n clear() {\n super.clear();\n this._mouseInput = null;\n }\n }\n\n /**\n * This represents a free type of camera. It can be useful in First Person Shooter game for instance.\n * Please consider using the new UniversalCamera instead as it adds more functionality like the gamepad.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\n */\n class FreeCamera extends TargetCamera {\n /**\n * Gets the input sensibility for a mouse input. (default is 2000.0)\n * Higher values reduce sensitivity.\n */\n get angularSensibility() {\n const mouse = this.inputs.attached[\"mouse\"];\n if (mouse) {\n return mouse.angularSensibility;\n }\n return 0;\n }\n /**\n * Sets the input sensibility for a mouse input. (default is 2000.0)\n * Higher values reduce sensitivity.\n */\n set angularSensibility(value) {\n const mouse = this.inputs.attached[\"mouse\"];\n if (mouse) {\n mouse.angularSensibility = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the forward move of the camera.\n */\n get keysUp() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysUp;\n }\n return [];\n }\n set keysUp(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysUp = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the upward move of the camera.\n */\n get keysUpward() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysUpward;\n }\n return [];\n }\n set keysUpward(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysUpward = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the backward move of the camera.\n */\n get keysDown() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysDown;\n }\n return [];\n }\n set keysDown(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysDown = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the downward move of the camera.\n */\n get keysDownward() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysDownward;\n }\n return [];\n }\n set keysDownward(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysDownward = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.\n */\n get keysLeft() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysLeft;\n }\n return [];\n }\n set keysLeft(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysLeft = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the right strafe move of the camera.\n */\n get keysRight() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysRight;\n }\n return [];\n }\n set keysRight(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysRight = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the left rotation move of the camera.\n */\n get keysRotateLeft() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysRotateLeft;\n }\n return [];\n }\n set keysRotateLeft(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysRotateLeft = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the right rotation move of the camera.\n */\n get keysRotateRight() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysRotateRight;\n }\n return [];\n }\n set keysRotateRight(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysRotateRight = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the up rotation move of the camera.\n */\n get keysRotateUp() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysRotateUp;\n }\n return [];\n }\n set keysRotateUp(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysRotateUp = value;\n }\n }\n /**\n * Gets or Set the list of keyboard keys used to control the down rotation move of the camera.\n */\n get keysRotateDown() {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n return keyboard.keysRotateDown;\n }\n return [];\n }\n set keysRotateDown(value) {\n const keyboard = this.inputs.attached[\"keyboard\"];\n if (keyboard) {\n keyboard.keysRotateDown = value;\n }\n }\n /**\n * Instantiates a Free Camera.\n * This represents a free type of camera. It can be useful in First Person Shooter game for instance.\n * Please consider using the new UniversalCamera instead as it adds more functionality like touch to this camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\n * @param name Define the name of the camera in the scene\n * @param position Define the start position of the camera in the scene\n * @param scene Define the scene the camera belongs to\n * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined\n */\n constructor(name, position, scene, setActiveOnSceneIfNoneActive = true) {\n super(name, position, scene, setActiveOnSceneIfNoneActive);\n /**\n * Define the collision ellipsoid of the camera.\n * This is helpful to simulate a camera body like the player body around the camera\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#arcrotatecamera\n */\n this.ellipsoid = new Vector3(0.5, 1, 0.5);\n /**\n * Define an offset for the position of the ellipsoid around the camera.\n * This can be helpful to determine the center of the body near the gravity center of the body\n * instead of its head.\n */\n this.ellipsoidOffset = new Vector3(0, 0, 0);\n /**\n * Enable or disable collisions of the camera with the rest of the scene objects.\n */\n this.checkCollisions = false;\n /**\n * Enable or disable gravity on the camera.\n */\n this.applyGravity = false;\n this._needMoveForGravity = false;\n this._oldPosition = Vector3.Zero();\n this._diffPosition = Vector3.Zero();\n this._newPosition = Vector3.Zero();\n // Collisions\n this._collisionMask = -1;\n this._onCollisionPositionChange = (collisionId, newPosition, collidedMesh = null) => {\n this._newPosition.copyFrom(newPosition);\n this._newPosition.subtractToRef(this._oldPosition, this._diffPosition);\n if (this._diffPosition.length() > Engine.CollisionsEpsilon) {\n this.position.addToRef(this._diffPosition, this._deferredPositionUpdate);\n if (!this._deferOnly) {\n this.position.copyFrom(this._deferredPositionUpdate);\n }\n else {\n this._deferredUpdated = true;\n }\n // call onCollide, if defined. Note that in case of deferred update, the actual position change might happen in the next frame.\n if (this.onCollide && collidedMesh) {\n this.onCollide(collidedMesh);\n }\n }\n };\n this.inputs = new FreeCameraInputsManager(this);\n this.inputs.addKeyboard().addMouse();\n }\n /**\n * Attached controls to the current camera.\n * @param ignored defines an ignored parameter kept for backward compatibility.\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\n */\n attachControl(ignored, noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n this.inputs.attachElement(noPreventDefault);\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n this.inputs.detachElement();\n this.cameraDirection = new Vector3(0, 0, 0);\n this.cameraRotation = new Vector2(0, 0);\n }\n /**\n * Define a collision mask to limit the list of object the camera can collide with\n */\n get collisionMask() {\n return this._collisionMask;\n }\n set collisionMask(mask) {\n this._collisionMask = !isNaN(mask) ? mask : -1;\n }\n /**\n * @internal\n */\n _collideWithWorld(displacement) {\n let globalPosition;\n if (this.parent) {\n globalPosition = Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());\n }\n else {\n globalPosition = this.position;\n }\n globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);\n this._oldPosition.addInPlace(this.ellipsoidOffset);\n const coordinator = this.getScene().collisionCoordinator;\n if (!this._collider) {\n this._collider = coordinator.createCollider();\n }\n this._collider._radius = this.ellipsoid;\n this._collider.collisionMask = this._collisionMask;\n //no need for clone, as long as gravity is not on.\n let actualDisplacement = displacement;\n //add gravity to the direction to prevent the dual-collision checking\n if (this.applyGravity) {\n //this prevents mending with cameraDirection, a global variable of the free camera class.\n actualDisplacement = displacement.add(this.getScene().gravity);\n }\n coordinator.getNewPosition(this._oldPosition, actualDisplacement, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);\n }\n /** @internal */\n _checkInputs() {\n if (!this._localDirection) {\n this._localDirection = Vector3.Zero();\n this._transformedDirection = Vector3.Zero();\n }\n this.inputs.checkInputs();\n super._checkInputs();\n }\n /**\n * Enable movement without a user input. This allows gravity to always be applied.\n */\n set needMoveForGravity(value) {\n this._needMoveForGravity = value;\n }\n /**\n * When true, gravity is applied whether there is user input or not.\n */\n get needMoveForGravity() {\n return this._needMoveForGravity;\n }\n /** @internal */\n _decideIfNeedsToMove() {\n return this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;\n }\n /** @internal */\n _updatePosition() {\n if (this.checkCollisions && this.getScene().collisionsEnabled) {\n this._collideWithWorld(this.cameraDirection);\n }\n else {\n super._updatePosition();\n }\n }\n /**\n * Destroy the camera and release the current resources hold by it.\n */\n dispose() {\n this.inputs.clear();\n super.dispose();\n }\n /**\n * Gets the current object class name.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCamera\";\n }\n }\n __decorate$1([\n serializeAsVector3()\n ], FreeCamera.prototype, \"ellipsoid\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], FreeCamera.prototype, \"ellipsoidOffset\", void 0);\n __decorate$1([\n serialize()\n ], FreeCamera.prototype, \"checkCollisions\", void 0);\n __decorate$1([\n serialize()\n ], FreeCamera.prototype, \"applyGravity\", void 0);\n\n /**\n * Add orientation input support to the input manager.\n * @param smoothFactor deviceOrientation smoothing. 0: no smoothing, 1: new data ignored, 0.9 recommended for smoothing\n * @returns the current input manager\n */\n FreeCameraInputsManager.prototype.addDeviceOrientation = function (smoothFactor) {\n if (!this._deviceOrientationInput) {\n this._deviceOrientationInput = new FreeCameraDeviceOrientationInput();\n if (smoothFactor) {\n this._deviceOrientationInput.smoothFactor = smoothFactor;\n }\n this.add(this._deviceOrientationInput);\n }\n return this;\n };\n /**\n * Takes information about the orientation of the device as reported by the deviceorientation event to orient the camera.\n * Screen rotation is taken into account.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraDeviceOrientationInput {\n /**\n * Can be used to detect if a device orientation sensor is available on a device\n * @param timeout amount of time in milliseconds to wait for a response from the sensor (default: infinite)\n * @returns a promise that will resolve on orientation change\n */\n static WaitForOrientationChangeAsync(timeout) {\n return new Promise((res, rej) => {\n let gotValue = false;\n const eventHandler = () => {\n window.removeEventListener(\"deviceorientation\", eventHandler);\n gotValue = true;\n res();\n };\n // If timeout is populated reject the promise\n if (timeout) {\n setTimeout(() => {\n if (!gotValue) {\n window.removeEventListener(\"deviceorientation\", eventHandler);\n rej(\"WaitForOrientationChangeAsync timed out\");\n }\n }, timeout);\n }\n if (typeof DeviceOrientationEvent !== \"undefined\" && typeof DeviceOrientationEvent.requestPermission === \"function\") {\n DeviceOrientationEvent\n .requestPermission()\n .then((response) => {\n if (response == \"granted\") {\n window.addEventListener(\"deviceorientation\", eventHandler);\n }\n else {\n Tools.Warn(\"Permission not granted.\");\n }\n })\n .catch((error) => {\n Tools.Error(error);\n });\n }\n else {\n window.addEventListener(\"deviceorientation\", eventHandler);\n }\n });\n }\n /**\n * Instantiates a new input\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n constructor() {\n this._screenOrientationAngle = 0;\n this._screenQuaternion = new Quaternion();\n this._alpha = 0;\n this._beta = 0;\n this._gamma = 0;\n /** alpha+beta+gamma smoothing. 0: no smoothing, 1: new data ignored, 0.9 recommended for smoothing */\n this.smoothFactor = 0;\n /**\n * @internal\n */\n this._onDeviceOrientationChangedObservable = new Observable$1();\n this._orientationChanged = () => {\n this._screenOrientationAngle =\n window.orientation !== undefined\n ? +window.orientation\n : window.screen.orientation && window.screen.orientation[\"angle\"]\n ? window.screen.orientation.angle\n : 0;\n this._screenOrientationAngle = -Tools.ToRadians(this._screenOrientationAngle / 2);\n this._screenQuaternion.copyFromFloats(0, Math.sin(this._screenOrientationAngle), 0, Math.cos(this._screenOrientationAngle));\n };\n this._deviceOrientation = (evt) => {\n if (this.smoothFactor) {\n this._alpha = evt.alpha !== null ? Tools.SmoothAngleChange(this._alpha, evt.alpha, this.smoothFactor) : 0;\n this._beta = evt.beta !== null ? Tools.SmoothAngleChange(this._beta, evt.beta, this.smoothFactor) : 0;\n this._gamma = evt.gamma !== null ? Tools.SmoothAngleChange(this._gamma, evt.gamma, this.smoothFactor) : 0;\n }\n else {\n this._alpha = evt.alpha !== null ? evt.alpha : 0;\n this._beta = evt.beta !== null ? evt.beta : 0;\n this._gamma = evt.gamma !== null ? evt.gamma : 0;\n }\n if (evt.alpha !== null) {\n this._onDeviceOrientationChangedObservable.notifyObservers();\n }\n };\n this._constantTranform = new Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));\n this._orientationChanged();\n }\n /**\n * Define the camera controlled by the input.\n */\n get camera() {\n return this._camera;\n }\n set camera(camera) {\n this._camera = camera;\n if (this._camera != null && !this._camera.rotationQuaternion) {\n this._camera.rotationQuaternion = new Quaternion();\n }\n if (this._camera) {\n this._camera.onDisposeObservable.add(() => {\n this._onDeviceOrientationChangedObservable.clear();\n });\n }\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n */\n attachControl() {\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\n if (hostWindow) {\n const eventHandler = () => {\n hostWindow.addEventListener(\"orientationchange\", this._orientationChanged);\n hostWindow.addEventListener(\"deviceorientation\", this._deviceOrientation);\n //In certain cases, the attach control is called AFTER orientation was changed,\n //So this is needed.\n this._orientationChanged();\n };\n if (typeof DeviceOrientationEvent !== \"undefined\" && typeof DeviceOrientationEvent.requestPermission === \"function\") {\n DeviceOrientationEvent\n .requestPermission()\n .then((response) => {\n if (response === \"granted\") {\n eventHandler();\n }\n else {\n Tools.Warn(\"Permission not granted.\");\n }\n })\n .catch((error) => {\n Tools.Error(error);\n });\n }\n else {\n eventHandler();\n }\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n window.removeEventListener(\"orientationchange\", this._orientationChanged);\n window.removeEventListener(\"deviceorientation\", this._deviceOrientation);\n this._alpha = 0;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n //if no device orientation provided, don't update the rotation.\n //Only testing against alpha under the assumption thatnorientation will never be so exact when set.\n if (!this._alpha) {\n return;\n }\n Quaternion.RotationYawPitchRollToRef(Tools.ToRadians(this._alpha), Tools.ToRadians(this._beta), -Tools.ToRadians(this._gamma), this.camera.rotationQuaternion);\n this._camera.rotationQuaternion.multiplyInPlace(this._screenQuaternion);\n this._camera.rotationQuaternion.multiplyInPlace(this._constantTranform);\n //Mirror on XY Plane\n this._camera.rotationQuaternion.z *= -1;\n this._camera.rotationQuaternion.w *= -1;\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCameraDeviceOrientationInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"deviceOrientation\";\n }\n }\n CameraInputTypes[\"FreeCameraDeviceOrientationInput\"] = FreeCameraDeviceOrientationInput;\n\n Node.AddNodeConstructor(\"DeviceOrientationCamera\", (name, scene) => {\n return () => new DeviceOrientationCamera(name, Vector3.Zero(), scene);\n });\n // We're mainly based on the logic defined into the FreeCamera code\n /**\n * This is a camera specifically designed to react to device orientation events such as a modern mobile device\n * being tilted forward or back and left or right.\n */\n class DeviceOrientationCamera extends FreeCamera {\n /**\n * Creates a new device orientation camera\n * @param name The name of the camera\n * @param position The start position camera\n * @param scene The scene the camera belongs to\n */\n constructor(name, position, scene) {\n super(name, position, scene);\n this._tmpDragQuaternion = new Quaternion();\n this._disablePointerInputWhenUsingDeviceOrientation = true;\n this._dragFactor = 0;\n this._quaternionCache = new Quaternion();\n this.inputs.addDeviceOrientation();\n // When the orientation sensor fires it's first event, disable mouse input\n if (this.inputs._deviceOrientationInput) {\n this.inputs._deviceOrientationInput._onDeviceOrientationChangedObservable.addOnce(() => {\n if (this._disablePointerInputWhenUsingDeviceOrientation) {\n if (this.inputs._mouseInput) {\n this.inputs._mouseInput._allowCameraRotation = false;\n this.inputs._mouseInput.onPointerMovedObservable.add((e) => {\n if (this._dragFactor != 0) {\n if (!this._initialQuaternion) {\n this._initialQuaternion = new Quaternion();\n }\n // Rotate the initial space around the y axis to allow users to \"turn around\" via touch/mouse\n Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);\n this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);\n }\n });\n }\n }\n });\n }\n }\n /**\n * Gets or sets a boolean indicating that pointer input must be disabled on first orientation sensor update (Default: true)\n */\n get disablePointerInputWhenUsingDeviceOrientation() {\n return this._disablePointerInputWhenUsingDeviceOrientation;\n }\n set disablePointerInputWhenUsingDeviceOrientation(value) {\n this._disablePointerInputWhenUsingDeviceOrientation = value;\n }\n /**\n * Enabled turning on the y axis when the orientation sensor is active\n * @param dragFactor the factor that controls the turn speed (default: 1/300)\n */\n enableHorizontalDragging(dragFactor = 1 / 300) {\n this._dragFactor = dragFactor;\n }\n /**\n * Gets the current instance class name (\"DeviceOrientationCamera\").\n * This helps avoiding instanceof at run time.\n * @returns the class name\n */\n getClassName() {\n return \"DeviceOrientationCamera\";\n }\n /**\n * @internal\n * Checks and applies the current values of the inputs to the camera. (Internal use only)\n */\n _checkInputs() {\n super._checkInputs();\n this._quaternionCache.copyFrom(this.rotationQuaternion);\n if (this._initialQuaternion) {\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n }\n /**\n * Reset the camera to its default orientation on the specified axis only.\n * @param axis The axis to reset\n */\n resetToCurrentRotation(axis = Axis.Y) {\n //can only work if this camera has a rotation quaternion already.\n if (!this.rotationQuaternion) {\n return;\n }\n if (!this._initialQuaternion) {\n this._initialQuaternion = new Quaternion();\n }\n this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);\n [\"x\", \"y\", \"z\"].forEach((axisName) => {\n if (!axis[axisName]) {\n this._initialQuaternion[axisName] = 0;\n }\n else {\n this._initialQuaternion[axisName] *= -1;\n }\n });\n this._initialQuaternion.normalize();\n //force rotation update\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\n }\n }\n\n /**\n * This represents all the required metrics to create a VR camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#device-orientation-camera\n */\n class VRCameraMetrics {\n constructor() {\n /**\n * Define if the current vr camera should compensate the distortion of the lens or not.\n */\n this.compensateDistortion = true;\n /**\n * Defines if multiview should be enabled when rendering (Default: false)\n */\n this.multiviewEnabled = false;\n }\n /**\n * Gets the rendering aspect ratio based on the provided resolutions.\n */\n get aspectRatio() {\n return this.hResolution / (2 * this.vResolution);\n }\n /**\n * Gets the aspect ratio based on the FOV, scale factors, and real screen sizes.\n */\n get aspectRatioFov() {\n return 2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance));\n }\n /**\n * @internal\n */\n get leftHMatrix() {\n const meters = this.hScreenSize / 4 - this.lensSeparationDistance / 2;\n const h = (4 * meters) / this.hScreenSize;\n return Matrix.Translation(h, 0, 0);\n }\n /**\n * @internal\n */\n get rightHMatrix() {\n const meters = this.hScreenSize / 4 - this.lensSeparationDistance / 2;\n const h = (4 * meters) / this.hScreenSize;\n return Matrix.Translation(-h, 0, 0);\n }\n /**\n * @internal\n */\n get leftPreViewMatrix() {\n return Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);\n }\n /**\n * @internal\n */\n get rightPreViewMatrix() {\n return Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);\n }\n /**\n * Get the default VRMetrics based on the most generic setup.\n * @returns the default vr metrics\n */\n static GetDefault() {\n const result = new VRCameraMetrics();\n result.hResolution = 1280;\n result.vResolution = 800;\n result.hScreenSize = 0.149759993;\n result.vScreenSize = 0.0935999975;\n result.vScreenCenter = 0.0467999987;\n result.eyeToScreenDistance = 0.0410000011;\n result.lensSeparationDistance = 0.063500002;\n result.interpupillaryDistance = 0.064000003;\n result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];\n result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];\n result.postProcessScaleFactor = 1.714605507808412;\n result.lensCenterOffset = 0.151976421;\n return result;\n }\n }\n\n // Do not edit.\n const name$1T = \"vrDistortionCorrectionPixelShader\";\n const shader$1T = `varying vec2 vUV;uniform sampler2D textureSampler;uniform vec2 LensCenter;uniform vec2 Scale;uniform vec2 ScaleIn;uniform vec4 HmdWarpParam;vec2 HmdWarp(vec2 in01) {vec2 theta=(in01-LensCenter)*ScaleIn; \nfloat rSq=theta.x*theta.x+theta.y*theta.y;vec2 rvector=theta*(HmdWarpParam.x+HmdWarpParam.y*rSq+HmdWarpParam.z*rSq*rSq+HmdWarpParam.w*rSq*rSq*rSq);return LensCenter+Scale*rvector;}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec2 tc=HmdWarp(vUV);if (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\ngl_FragColor=vec4(0.0,0.0,0.0,0.0);else{gl_FragColor=texture2D(textureSampler,tc);}}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1T] = shader$1T;\n\n /**\n * VRDistortionCorrectionPostProcess used for mobile VR\n */\n class VRDistortionCorrectionPostProcess extends PostProcess {\n /**\n * Gets a string identifying the name of the class\n * @returns \"VRDistortionCorrectionPostProcess\" string\n */\n getClassName() {\n return \"VRDistortionCorrectionPostProcess\";\n }\n /**\n * Initializes the VRDistortionCorrectionPostProcess\n * @param name The name of the effect.\n * @param camera The camera to apply the render pass to.\n * @param isRightEye If this is for the right eye distortion\n * @param vrMetrics All the required metrics for the VR camera\n */\n constructor(name, camera, isRightEye, vrMetrics) {\n super(name, \"vrDistortionCorrection\", [\"LensCenter\", \"Scale\", \"ScaleIn\", \"HmdWarpParam\"], null, vrMetrics.postProcessScaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);\n this._isRightEye = isRightEye;\n this._distortionFactors = vrMetrics.distortionK;\n this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;\n this._lensCenterOffset = vrMetrics.lensCenterOffset;\n this.adaptScaleToCurrentViewport = true;\n this.onSizeChangedObservable.add(() => {\n this._scaleIn = new Vector2(2, 2 / this.aspectRatio);\n this._scaleFactor = new Vector2(0.5 * (1 / this._postProcessScaleFactor), 0.5 * (1 / this._postProcessScaleFactor) * this.aspectRatio);\n this._lensCenter = new Vector2(this._isRightEye ? 0.5 - this._lensCenterOffset * 0.5 : 0.5 + this._lensCenterOffset * 0.5, 0.5);\n });\n this.onApplyObservable.add((effect) => {\n effect.setFloat2(\"LensCenter\", this._lensCenter.x, this._lensCenter.y);\n effect.setFloat2(\"Scale\", this._scaleFactor.x, this._scaleFactor.y);\n effect.setFloat2(\"ScaleIn\", this._scaleIn.x, this._scaleIn.y);\n effect.setFloat4(\"HmdWarpParam\", this._distortionFactors[0], this._distortionFactors[1], this._distortionFactors[2], this._distortionFactors[3]);\n });\n }\n }\n\n // Do not edit.\n const name$1U = \"vrMultiviewToSingleviewPixelShader\";\n const shader$1U = `precision mediump sampler2DArray;varying vec2 vUV;uniform sampler2DArray multiviewSampler;uniform int imageIndex;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{gl_FragColor=texture2D(multiviewSampler,vec3(vUV,imageIndex));}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1U] = shader$1U;\n\n /**\n * Renders to multiple views with a single draw call\n * @see https://www.khronos.org/registry/webgl/extensions/OVR_multiview2/\n */\n class MultiviewRenderTarget extends RenderTargetTexture {\n set samples(value) {\n // We override this setter because multisampling is handled by framebufferTextureMultisampleMultiviewOVR\n this._samples = value;\n }\n get samples() {\n return this._samples;\n }\n /**\n * Creates a multiview render target\n * @param scene scene used with the render target\n * @param size the size of the render target (used for each view)\n */\n constructor(scene, size = 512) {\n super(\"multiview rtt\", size, scene, false, true, 0, false, undefined, false, false, true, undefined, true);\n this._renderTarget = this.getScene().getEngine().createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight());\n this._texture = this._renderTarget.texture;\n this._texture.isMultiview = true;\n this._texture.format = 5;\n this.samples = this._getEngine().getCaps().maxSamples || this.samples;\n this._texture.samples = this._samples;\n }\n /**\n * @internal\n */\n _bindFrameBuffer() {\n if (!this._renderTarget) {\n return;\n }\n this.getScene().getEngine().bindMultiviewFramebuffer(this._renderTarget);\n }\n /**\n * Gets the number of views the corresponding to the texture (eg. a MultiviewRenderTarget will have > 1)\n * @returns the view count\n */\n getViewCount() {\n return 2;\n }\n }\n\n Engine.prototype.createMultiviewRenderTargetTexture = function (width, height, colorTexture, depthStencilTexture) {\n const gl = this._gl;\n if (!this.getCaps().multiview) {\n throw \"Multiview is not supported\";\n }\n const rtWrapper = this._createHardwareRenderTargetWrapper(false, false, { width, height });\n rtWrapper._framebuffer = gl.createFramebuffer();\n const internalTexture = new InternalTexture(this, InternalTextureSource.Unknown, true);\n internalTexture.width = width;\n internalTexture.height = height;\n internalTexture.isMultiview = true;\n if (!colorTexture) {\n colorTexture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D_ARRAY, colorTexture);\n gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RGBA8, width, height, 2);\n }\n rtWrapper._colorTextureArray = colorTexture;\n if (!depthStencilTexture) {\n depthStencilTexture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D_ARRAY, depthStencilTexture);\n gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.DEPTH24_STENCIL8, width, height, 2);\n }\n rtWrapper._depthStencilTextureArray = depthStencilTexture;\n internalTexture.isReady = true;\n rtWrapper.setTextures(internalTexture);\n rtWrapper._depthStencilTexture = internalTexture;\n return rtWrapper;\n };\n Engine.prototype.bindMultiviewFramebuffer = function (_multiviewTexture) {\n const multiviewTexture = _multiviewTexture;\n const gl = this._gl;\n const ext = this.getCaps().oculusMultiview || this.getCaps().multiview;\n this.bindFramebuffer(multiviewTexture, undefined, undefined, undefined, true);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, multiviewTexture._framebuffer);\n if (multiviewTexture._colorTextureArray && multiviewTexture._depthStencilTextureArray) {\n if (this.getCaps().oculusMultiview) {\n ext.framebufferTextureMultisampleMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, multiviewTexture._colorTextureArray, 0, multiviewTexture.samples, 0, 2);\n ext.framebufferTextureMultisampleMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, multiviewTexture._depthStencilTextureArray, 0, multiviewTexture.samples, 0, 2);\n }\n else {\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, multiviewTexture._colorTextureArray, 0, 0, 2);\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, multiviewTexture._depthStencilTextureArray, 0, 0, 2);\n }\n }\n else {\n throw \"Invalid multiview frame buffer\";\n }\n };\n Engine.prototype.bindSpaceWarpFramebuffer = function (_spaceWarpTexture) {\n const spaceWarpTexture = _spaceWarpTexture;\n const gl = this._gl;\n const ext = this.getCaps().oculusMultiview || this.getCaps().multiview;\n this.bindFramebuffer(spaceWarpTexture, undefined, undefined, undefined, true);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, spaceWarpTexture._framebuffer);\n if (spaceWarpTexture._colorTextureArray && spaceWarpTexture._depthStencilTextureArray) {\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, spaceWarpTexture._colorTextureArray, 0, 0, 2);\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, spaceWarpTexture._depthStencilTextureArray, 0, 0, 2);\n }\n else {\n throw new Error(\"Invalid Space Warp framebuffer\");\n }\n };\n Camera.prototype._useMultiviewToSingleView = false;\n Camera.prototype._multiviewTexture = null;\n Camera.prototype._resizeOrCreateMultiviewTexture = function (width, height) {\n if (!this._multiviewTexture) {\n this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), { width: width, height: height });\n }\n else if (this._multiviewTexture.getRenderWidth() != width || this._multiviewTexture.getRenderHeight() != height) {\n this._multiviewTexture.dispose();\n this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), { width: width, height: height });\n }\n };\n function createMultiviewUbo(engine, name) {\n const ubo = new UniformBuffer(engine, undefined, true, name);\n ubo.addUniform(\"viewProjection\", 16);\n ubo.addUniform(\"viewProjectionR\", 16);\n ubo.addUniform(\"view\", 16);\n ubo.addUniform(\"projection\", 16);\n ubo.addUniform(\"vEyePosition\", 4);\n return ubo;\n }\n const currentCreateSceneUniformBuffer = Scene.prototype.createSceneUniformBuffer;\n Scene.prototype._transformMatrixR = Matrix.Zero();\n Scene.prototype._multiviewSceneUbo = null;\n Scene.prototype._createMultiviewUbo = function () {\n this._multiviewSceneUbo = createMultiviewUbo(this.getEngine(), \"scene_multiview\");\n };\n Scene.prototype.createSceneUniformBuffer = function (name) {\n if (this._multiviewSceneUbo) {\n return createMultiviewUbo(this.getEngine(), name);\n }\n return currentCreateSceneUniformBuffer.bind(this)(name);\n };\n Scene.prototype._updateMultiviewUbo = function (viewR, projectionR) {\n if (viewR && projectionR) {\n viewR.multiplyToRef(projectionR, this._transformMatrixR);\n }\n if (viewR && projectionR) {\n viewR.multiplyToRef(projectionR, TmpVectors.Matrix[0]);\n Frustum.GetRightPlaneToRef(TmpVectors.Matrix[0], this._frustumPlanes[3]); // Replace right plane by second camera right plane\n }\n if (this._multiviewSceneUbo) {\n this._multiviewSceneUbo.updateMatrix(\"viewProjection\", this.getTransformMatrix());\n this._multiviewSceneUbo.updateMatrix(\"viewProjectionR\", this._transformMatrixR);\n this._multiviewSceneUbo.updateMatrix(\"view\", this._viewMatrix);\n this._multiviewSceneUbo.updateMatrix(\"projection\", this._projectionMatrix);\n }\n };\n Scene.prototype._renderMultiviewToSingleView = function (camera) {\n // Multiview is only able to be displayed directly for API's such as webXR\n // This displays a multiview image by rendering to the multiview image and then\n // copying the result into the sub cameras instead of rendering them and proceeding as normal from there\n // Render to a multiview texture\n camera._resizeOrCreateMultiviewTexture(camera._rigPostProcess && camera._rigPostProcess && camera._rigPostProcess.width > 0 ? camera._rigPostProcess.width : this.getEngine().getRenderWidth(true), camera._rigPostProcess && camera._rigPostProcess && camera._rigPostProcess.height > 0 ? camera._rigPostProcess.height : this.getEngine().getRenderHeight(true));\n if (!this._multiviewSceneUbo) {\n this._createMultiviewUbo();\n }\n camera.outputRenderTarget = camera._multiviewTexture;\n this._renderForCamera(camera);\n camera.outputRenderTarget = null;\n // Consume the multiview texture through a shader for each eye\n for (let index = 0; index < camera._rigCameras.length; index++) {\n const engine = this.getEngine();\n this._activeCamera = camera._rigCameras[index];\n engine.setViewport(this._activeCamera.viewport);\n if (this.postProcessManager) {\n this.postProcessManager._prepareFrame();\n this.postProcessManager._finalizeFrame(this._activeCamera.isIntermediate);\n }\n }\n };\n\n /**\n * VRMultiviewToSingleview used to convert multiview texture arrays to standard textures for scenarios such as webVR\n * This will not be used for webXR as it supports displaying texture arrays directly\n */\n class VRMultiviewToSingleviewPostProcess extends PostProcess {\n /**\n * Gets a string identifying the name of the class\n * @returns \"VRMultiviewToSingleviewPostProcess\" string\n */\n getClassName() {\n return \"VRMultiviewToSingleviewPostProcess\";\n }\n /**\n * Initializes a VRMultiviewToSingleview\n * @param name name of the post process\n * @param camera camera to be applied to\n * @param scaleFactor scaling factor to the size of the output texture\n */\n constructor(name, camera, scaleFactor) {\n super(name, \"vrMultiviewToSingleview\", [\"imageIndex\"], [\"multiviewSampler\"], scaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);\n const cam = camera !== null && camera !== void 0 ? camera : this.getCamera();\n this.onSizeChangedObservable.add(() => { });\n this.onApplyObservable.add((effect) => {\n if (cam._scene.activeCamera && cam._scene.activeCamera.isLeftCamera) {\n effect.setInt(\"imageIndex\", 0);\n }\n else {\n effect.setInt(\"imageIndex\", 1);\n }\n effect.setTexture(\"multiviewSampler\", cam._multiviewTexture);\n });\n }\n }\n\n /**\n * @internal\n */\n function setVRRigMode(camera, rigParams) {\n const metrics = rigParams.vrCameraMetrics || VRCameraMetrics.GetDefault();\n camera._rigCameras[0]._cameraRigParams.vrMetrics = metrics;\n camera._rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\n camera._rigCameras[0]._cameraRigParams.vrWorkMatrix = new Matrix();\n camera._rigCameras[0]._cameraRigParams.vrHMatrix = metrics.leftHMatrix;\n camera._rigCameras[0]._cameraRigParams.vrPreViewMatrix = metrics.leftPreViewMatrix;\n camera._rigCameras[0].getProjectionMatrix = camera._rigCameras[0]._getVRProjectionMatrix;\n camera._rigCameras[1]._cameraRigParams.vrMetrics = metrics;\n camera._rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\n camera._rigCameras[1]._cameraRigParams.vrWorkMatrix = new Matrix();\n camera._rigCameras[1]._cameraRigParams.vrHMatrix = metrics.rightHMatrix;\n camera._rigCameras[1]._cameraRigParams.vrPreViewMatrix = metrics.rightPreViewMatrix;\n camera._rigCameras[1].getProjectionMatrix = camera._rigCameras[1]._getVRProjectionMatrix;\n // For multiview on a webVR camera\n // First multiview will be rendered to camera._multiviewTexture\n // Then this postprocess will run on each eye to copy the right texture to each eye\n if (metrics.multiviewEnabled) {\n if (!camera.getScene().getEngine().getCaps().multiview) {\n Logger.Warn(\"Multiview is not supported, falling back to standard rendering\");\n metrics.multiviewEnabled = false;\n }\n else {\n camera._useMultiviewToSingleView = true;\n camera._rigPostProcess = new VRMultiviewToSingleviewPostProcess(\"VRMultiviewToSingleview\", camera, metrics.postProcessScaleFactor);\n }\n }\n if (metrics.compensateDistortion) {\n camera._rigCameras[0]._rigPostProcess = new VRDistortionCorrectionPostProcess(\"VR_Distort_Compensation_Left\", camera._rigCameras[0], false, metrics);\n camera._rigCameras[1]._rigPostProcess = new VRDistortionCorrectionPostProcess(\"VR_Distort_Compensation_Right\", camera._rigCameras[1], true, metrics);\n }\n }\n\n Node.AddNodeConstructor(\"VRDeviceOrientationFreeCamera\", (name, scene) => {\n return () => new VRDeviceOrientationFreeCamera(name, Vector3.Zero(), scene);\n });\n /**\n * Camera used to simulate VR rendering (based on FreeCamera)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#vr-device-orientation-cameras\n */\n class VRDeviceOrientationFreeCamera extends DeviceOrientationCamera {\n /**\n * Creates a new VRDeviceOrientationFreeCamera\n * @param name defines camera name\n * @param position defines the start position of the camera\n * @param scene defines the scene the camera belongs to\n * @param compensateDistortion defines if the camera needs to compensate the lens distortion\n * @param vrCameraMetrics defines the vr metrics associated to the camera\n */\n constructor(name, position, scene, compensateDistortion = true, vrCameraMetrics = VRCameraMetrics.GetDefault()) {\n super(name, position, scene);\n this._setRigMode = setVRRigMode.bind(null, this);\n vrCameraMetrics.compensateDistortion = compensateDistortion;\n this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });\n }\n /**\n * Gets camera class name\n * @returns VRDeviceOrientationFreeCamera\n */\n getClassName() {\n return \"VRDeviceOrientationFreeCamera\";\n }\n }\n\n /**\n * Represents a gamepad\n */\n class Gamepad {\n /**\n * Specifies if the gamepad has been connected\n */\n get isConnected() {\n return this._isConnected;\n }\n /**\n * Initializes the gamepad\n * @param id The id of the gamepad\n * @param index The index of the gamepad\n * @param browserGamepad The browser gamepad\n * @param leftStickX The x component of the left joystick\n * @param leftStickY The y component of the left joystick\n * @param rightStickX The x component of the right joystick\n * @param rightStickY The y component of the right joystick\n */\n constructor(\n /**\n * The id of the gamepad\n */\n id, \n /**\n * The index of the gamepad\n */\n index, \n /**\n * The browser gamepad\n */\n browserGamepad, leftStickX = 0, leftStickY = 1, rightStickX = 2, rightStickY = 3) {\n this.id = id;\n this.index = index;\n this.browserGamepad = browserGamepad;\n this._leftStick = { x: 0, y: 0 };\n this._rightStick = { x: 0, y: 0 };\n /** @internal */\n this._isConnected = true;\n /**\n * Specifies whether the left control stick should be Y-inverted\n */\n this._invertLeftStickY = false;\n this.type = Gamepad.GAMEPAD;\n this._leftStickAxisX = leftStickX;\n this._leftStickAxisY = leftStickY;\n this._rightStickAxisX = rightStickX;\n this._rightStickAxisY = rightStickY;\n if (this.browserGamepad.axes.length >= 2) {\n this._leftStick = { x: this.browserGamepad.axes[this._leftStickAxisX], y: this.browserGamepad.axes[this._leftStickAxisY] };\n }\n if (this.browserGamepad.axes.length >= 4) {\n this._rightStick = { x: this.browserGamepad.axes[this._rightStickAxisX], y: this.browserGamepad.axes[this._rightStickAxisY] };\n }\n }\n /**\n * Callback triggered when the left joystick has changed\n * @param callback\n */\n onleftstickchanged(callback) {\n this._onleftstickchanged = callback;\n }\n /**\n * Callback triggered when the right joystick has changed\n * @param callback\n */\n onrightstickchanged(callback) {\n this._onrightstickchanged = callback;\n }\n /**\n * Gets the left joystick\n */\n get leftStick() {\n return this._leftStick;\n }\n /**\n * Sets the left joystick values\n */\n set leftStick(newValues) {\n if (this._onleftstickchanged && (this._leftStick.x !== newValues.x || this._leftStick.y !== newValues.y)) {\n this._onleftstickchanged(newValues);\n }\n this._leftStick = newValues;\n }\n /**\n * Gets the right joystick\n */\n get rightStick() {\n return this._rightStick;\n }\n /**\n * Sets the right joystick value\n */\n set rightStick(newValues) {\n if (this._onrightstickchanged && (this._rightStick.x !== newValues.x || this._rightStick.y !== newValues.y)) {\n this._onrightstickchanged(newValues);\n }\n this._rightStick = newValues;\n }\n /**\n * Updates the gamepad joystick positions\n */\n update() {\n if (this._leftStick) {\n this.leftStick = { x: this.browserGamepad.axes[this._leftStickAxisX], y: this.browserGamepad.axes[this._leftStickAxisY] };\n if (this._invertLeftStickY) {\n this.leftStick.y *= -1;\n }\n }\n if (this._rightStick) {\n this.rightStick = { x: this.browserGamepad.axes[this._rightStickAxisX], y: this.browserGamepad.axes[this._rightStickAxisY] };\n }\n }\n /**\n * Disposes the gamepad\n */\n dispose() { }\n }\n /**\n * Represents a gamepad controller\n */\n Gamepad.GAMEPAD = 0;\n /**\n * Represents a generic controller\n */\n Gamepad.GENERIC = 1;\n /**\n * Represents an XBox controller\n */\n Gamepad.XBOX = 2;\n /**\n * Represents a pose-enabled controller\n */\n Gamepad.POSE_ENABLED = 3;\n /**\n * Represents an Dual Shock controller\n */\n Gamepad.DUALSHOCK = 4;\n /**\n * Represents a generic gamepad\n */\n class GenericPad extends Gamepad {\n /**\n * Callback triggered when a button has been pressed\n * @param callback Called when a button has been pressed\n */\n onbuttondown(callback) {\n this._onbuttondown = callback;\n }\n /**\n * Callback triggered when a button has been released\n * @param callback Called when a button has been released\n */\n onbuttonup(callback) {\n this._onbuttonup = callback;\n }\n /**\n * Initializes the generic gamepad\n * @param id The id of the generic gamepad\n * @param index The index of the generic gamepad\n * @param browserGamepad The browser gamepad\n */\n constructor(id, index, browserGamepad) {\n super(id, index, browserGamepad);\n /**\n * Observable triggered when a button has been pressed\n */\n this.onButtonDownObservable = new Observable$1();\n /**\n * Observable triggered when a button has been released\n */\n this.onButtonUpObservable = new Observable$1();\n this.type = Gamepad.GENERIC;\n this._buttons = new Array(browserGamepad.buttons.length);\n }\n _setButtonValue(newValue, currentValue, buttonIndex) {\n if (newValue !== currentValue) {\n if (newValue === 1) {\n if (this._onbuttondown) {\n this._onbuttondown(buttonIndex);\n }\n this.onButtonDownObservable.notifyObservers(buttonIndex);\n }\n if (newValue === 0) {\n if (this._onbuttonup) {\n this._onbuttonup(buttonIndex);\n }\n this.onButtonUpObservable.notifyObservers(buttonIndex);\n }\n }\n return newValue;\n }\n /**\n * Updates the generic gamepad\n */\n update() {\n super.update();\n for (let index = 0; index < this._buttons.length; index++) {\n this._buttons[index] = this._setButtonValue(this.browserGamepad.buttons[index].value, this._buttons[index], index);\n }\n }\n /**\n * Disposes the generic gamepad\n */\n dispose() {\n super.dispose();\n this.onButtonDownObservable.clear();\n this.onButtonUpObservable.clear();\n }\n }\n\n /**\n * Defines the types of pose enabled controllers that are supported\n */\n var PoseEnabledControllerType;\n (function (PoseEnabledControllerType) {\n /**\n * HTC Vive\n */\n PoseEnabledControllerType[PoseEnabledControllerType[\"VIVE\"] = 0] = \"VIVE\";\n /**\n * Oculus Rift\n */\n PoseEnabledControllerType[PoseEnabledControllerType[\"OCULUS\"] = 1] = \"OCULUS\";\n /**\n * Windows mixed reality\n */\n PoseEnabledControllerType[PoseEnabledControllerType[\"WINDOWS\"] = 2] = \"WINDOWS\";\n /**\n * Samsung gear VR\n */\n PoseEnabledControllerType[PoseEnabledControllerType[\"GEAR_VR\"] = 3] = \"GEAR_VR\";\n /**\n * Google Daydream\n */\n PoseEnabledControllerType[PoseEnabledControllerType[\"DAYDREAM\"] = 4] = \"DAYDREAM\";\n /**\n * Generic\n */\n PoseEnabledControllerType[PoseEnabledControllerType[\"GENERIC\"] = 5] = \"GENERIC\";\n })(PoseEnabledControllerType || (PoseEnabledControllerType = {}));\n /**\n * Defines the PoseEnabledControllerHelper object that is used initialize a gamepad as the controller type it is specified as (eg. windows mixed reality controller)\n */\n class PoseEnabledControllerHelper {\n /**\n * Initializes a gamepad as the controller type it is specified as (eg. windows mixed reality controller)\n * @param vrGamepad the gamepad to initialized\n * @returns a vr controller of the type the gamepad identified as\n */\n static InitiateController(vrGamepad) {\n for (const factory of this._ControllerFactories) {\n if (factory.canCreate(vrGamepad)) {\n return factory.create(vrGamepad);\n }\n }\n if (this._DefaultControllerFactory) {\n return this._DefaultControllerFactory(vrGamepad);\n }\n throw \"The type of gamepad you are trying to load needs to be imported first or is not supported.\";\n }\n }\n /** @internal */\n PoseEnabledControllerHelper._ControllerFactories = [];\n /** @internal */\n PoseEnabledControllerHelper._DefaultControllerFactory = null;\n /**\n * Defines the PoseEnabledController object that contains state of a vr capable controller\n */\n class PoseEnabledController extends Gamepad {\n /**\n * @internal\n */\n _disableTrackPosition(fixedPosition) {\n if (this._trackPosition) {\n this._calculatedPosition.copyFrom(fixedPosition);\n this._trackPosition = false;\n }\n }\n /**\n * Creates a new PoseEnabledController from a gamepad\n * @param browserGamepad the gamepad that the PoseEnabledController should be created from\n */\n constructor(browserGamepad) {\n super(browserGamepad.id, browserGamepad.index, browserGamepad);\n /**\n * If the controller is used in a webXR session\n */\n this.isXR = false;\n // Represents device position and rotation in room space. Should only be used to help calculate babylon space values\n this._deviceRoomPosition = Vector3.Zero();\n this._deviceRoomRotationQuaternion = new Quaternion();\n /**\n * The device position in babylon space\n */\n this.devicePosition = Vector3.Zero();\n /**\n * The device rotation in babylon space\n */\n this.deviceRotationQuaternion = new Quaternion();\n /**\n * The scale factor of the device in babylon space\n */\n this.deviceScaleFactor = 1;\n // Used to convert 6dof controllers to 3dof\n this._trackPosition = true;\n this._maxRotationDistFromHeadset = Math.PI / 5;\n this._draggedRoomRotation = 0;\n this._leftHandSystemQuaternion = new Quaternion();\n /**\n * Internal, matrix used to convert room space to babylon space\n * @internal\n */\n this._deviceToWorld = Matrix.Identity();\n /**\n * Node to be used when casting a ray from the controller\n * @internal\n */\n this._pointingPoseNode = null;\n this._workingMatrix = Matrix.Identity();\n /**\n * @internal\n */\n this._meshAttachedObservable = new Observable$1();\n this.type = Gamepad.POSE_ENABLED;\n this.controllerType = PoseEnabledControllerType.GENERIC;\n this.position = Vector3.Zero();\n this.rotationQuaternion = new Quaternion();\n this._calculatedPosition = Vector3.Zero();\n this._calculatedRotation = new Quaternion();\n Quaternion.RotationYawPitchRollToRef(Math.PI, 0, 0, this._leftHandSystemQuaternion);\n }\n /**\n * Updates the state of the pose enabled controller and mesh based on the current position and rotation of the controller\n */\n update() {\n super.update();\n this._updatePoseAndMesh();\n }\n /**\n * Updates only the pose device and mesh without doing any button event checking\n */\n _updatePoseAndMesh() {\n if (this.isXR) {\n return;\n }\n const pose = this.browserGamepad.pose;\n this.updateFromDevice(pose);\n if (!this._trackPosition &&\n EngineStore.LastCreatedScene &&\n EngineStore.LastCreatedScene.activeCamera &&\n EngineStore.LastCreatedScene.activeCamera.devicePosition) {\n const camera = EngineStore.LastCreatedScene.activeCamera;\n camera._computeDevicePosition();\n this._deviceToWorld.setTranslation(camera.devicePosition);\n if (camera.deviceRotationQuaternion) {\n camera._deviceRoomRotationQuaternion.toEulerAnglesToRef(TmpVectors.Vector3[0]);\n // Find the radian distance away that the headset is from the controllers rotation\n const distanceAway = Math.atan2(Math.sin(TmpVectors.Vector3[0].y - this._draggedRoomRotation), Math.cos(TmpVectors.Vector3[0].y - this._draggedRoomRotation));\n if (Math.abs(distanceAway) > this._maxRotationDistFromHeadset) {\n // Only rotate enouph to be within the _maxRotationDistFromHeadset\n const rotationAmount = distanceAway - (distanceAway < 0 ? -this._maxRotationDistFromHeadset : this._maxRotationDistFromHeadset);\n this._draggedRoomRotation += rotationAmount;\n // Rotate controller around headset\n const sin = Math.sin(-rotationAmount);\n const cos = Math.cos(-rotationAmount);\n this._calculatedPosition.x = this._calculatedPosition.x * cos - this._calculatedPosition.z * sin;\n this._calculatedPosition.z = this._calculatedPosition.x * sin + this._calculatedPosition.z * cos;\n }\n }\n }\n Vector3.TransformCoordinatesToRef(this._calculatedPosition, this._deviceToWorld, this.devicePosition);\n this._deviceToWorld.getRotationMatrixToRef(this._workingMatrix);\n Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);\n this.deviceRotationQuaternion.multiplyInPlace(this._calculatedRotation);\n if (this._mesh) {\n this._mesh.position.copyFrom(this.devicePosition);\n if (this._mesh.rotationQuaternion) {\n this._mesh.rotationQuaternion.copyFrom(this.deviceRotationQuaternion);\n }\n }\n }\n /**\n * Updates the state of the pose enbaled controller based on the raw pose data from the device\n * @param poseData raw pose fromthe device\n */\n updateFromDevice(poseData) {\n if (this.isXR) {\n return;\n }\n if (poseData) {\n this.rawPose = poseData;\n if (poseData.position) {\n this._deviceRoomPosition.copyFromFloats(poseData.position[0], poseData.position[1], -poseData.position[2]);\n if (this._mesh && this._mesh.getScene().useRightHandedSystem) {\n this._deviceRoomPosition.z *= -1;\n }\n if (this._trackPosition) {\n this._deviceRoomPosition.scaleToRef(this.deviceScaleFactor, this._calculatedPosition);\n }\n this._calculatedPosition.addInPlace(this.position);\n }\n const pose = this.rawPose;\n if (poseData.orientation && pose.orientation && pose.orientation.length === 4) {\n this._deviceRoomRotationQuaternion.copyFromFloats(pose.orientation[0], pose.orientation[1], -pose.orientation[2], -pose.orientation[3]);\n if (this._mesh) {\n if (this._mesh.getScene().useRightHandedSystem) {\n this._deviceRoomRotationQuaternion.z *= -1;\n this._deviceRoomRotationQuaternion.w *= -1;\n }\n else {\n this._deviceRoomRotationQuaternion.multiplyToRef(this._leftHandSystemQuaternion, this._deviceRoomRotationQuaternion);\n }\n }\n // if the camera is set, rotate to the camera's rotation\n this._deviceRoomRotationQuaternion.multiplyToRef(this.rotationQuaternion, this._calculatedRotation);\n }\n }\n }\n /**\n * Attaches a mesh to the controller\n * @param mesh the mesh to be attached\n */\n attachToMesh(mesh) {\n if (this._mesh) {\n this._mesh.parent = null;\n }\n this._mesh = mesh;\n if (this._poseControlledCamera) {\n this._mesh.parent = this._poseControlledCamera;\n }\n if (!this._mesh.rotationQuaternion) {\n this._mesh.rotationQuaternion = new Quaternion();\n }\n // Sync controller mesh and pointing pose node's state with controller, this is done to avoid a frame where position is 0,0,0 when attaching mesh\n if (!this.isXR) {\n this._updatePoseAndMesh();\n if (this._pointingPoseNode) {\n const parents = [];\n let obj = this._pointingPoseNode;\n while (obj.parent) {\n parents.push(obj.parent);\n obj = obj.parent;\n }\n parents.reverse().forEach((p) => {\n p.computeWorldMatrix(true);\n });\n }\n }\n this._meshAttachedObservable.notifyObservers(mesh);\n }\n /**\n * Attaches the controllers mesh to a camera\n * @param camera the camera the mesh should be attached to\n */\n attachToPoseControlledCamera(camera) {\n this._poseControlledCamera = camera;\n if (this._mesh) {\n this._mesh.parent = this._poseControlledCamera;\n }\n }\n /**\n * Disposes of the controller\n */\n dispose() {\n if (this._mesh) {\n this._mesh.dispose();\n }\n this._mesh = null;\n super.dispose();\n }\n /**\n * The mesh that is attached to the controller\n */\n get mesh() {\n return this._mesh;\n }\n /**\n * Gets the ray of the controller in the direction the controller is pointing\n * @param length the length the resulting ray should be\n * @returns a ray in the direction the controller is pointing\n */\n getForwardRay(length = 100) {\n if (!this.mesh) {\n return new Ray(Vector3.Zero(), new Vector3(0, 0, 1), length);\n }\n const m = this._pointingPoseNode ? this._pointingPoseNode.getWorldMatrix() : this.mesh.getWorldMatrix();\n const origin = m.getTranslation();\n const forward = new Vector3(0, 0, -1);\n const forwardWorld = Vector3.TransformNormal(forward, m);\n const direction = Vector3.Normalize(forwardWorld);\n return new Ray(origin, direction, length);\n }\n }\n /**\n * Name of the child mesh that can be used to cast a ray from the controller\n */\n PoseEnabledController.POINTING_POSE = \"POINTING_POSE\";\n\n /**\n * @internal\n */\n function setWebVRRigMode(camera, rigParams) {\n if (rigParams.vrDisplay) {\n const leftEye = rigParams.vrDisplay.getEyeParameters(\"left\");\n const rightEye = rigParams.vrDisplay.getEyeParameters(\"right\");\n //Left eye\n camera._rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\n camera._rigCameras[0].setCameraRigParameter(\"left\", true);\n //leaving this for future reference\n camera._rigCameras[0].setCameraRigParameter(\"specs\", rigParams.specs);\n camera._rigCameras[0].setCameraRigParameter(\"eyeParameters\", leftEye);\n camera._rigCameras[0].setCameraRigParameter(\"frameData\", rigParams.frameData);\n camera._rigCameras[0].setCameraRigParameter(\"parentCamera\", rigParams.parentCamera);\n camera._rigCameras[0]._cameraRigParams.vrWorkMatrix = new Matrix();\n camera._rigCameras[0].getProjectionMatrix = camera._getWebVRProjectionMatrix;\n camera._rigCameras[0].parent = camera;\n camera._rigCameras[0]._getViewMatrix = camera._getWebVRViewMatrix;\n //Right eye\n camera._rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\n camera._rigCameras[1].setCameraRigParameter(\"eyeParameters\", rightEye);\n camera._rigCameras[1].setCameraRigParameter(\"specs\", rigParams.specs);\n camera._rigCameras[1].setCameraRigParameter(\"frameData\", rigParams.frameData);\n camera._rigCameras[1].setCameraRigParameter(\"parentCamera\", rigParams.parentCamera);\n camera._rigCameras[1]._cameraRigParams.vrWorkMatrix = new Matrix();\n camera._rigCameras[1].getProjectionMatrix = camera._getWebVRProjectionMatrix;\n camera._rigCameras[1].parent = camera;\n camera._rigCameras[1]._getViewMatrix = camera._getWebVRViewMatrix;\n }\n }\n\n Object.defineProperty(Engine.prototype, \"isInVRExclusivePointerMode\", {\n get: function () {\n return this._vrExclusivePointerMode;\n },\n enumerable: true,\n configurable: true,\n });\n Engine.prototype._prepareVRComponent = function () {\n this._vrSupported = false;\n this._vrExclusivePointerMode = false;\n this.onVRDisplayChangedObservable = new Observable$1();\n this.onVRRequestPresentComplete = new Observable$1();\n this.onVRRequestPresentStart = new Observable$1();\n };\n Engine.prototype.isVRDevicePresent = function () {\n return !!this._vrDisplay;\n };\n Engine.prototype.getVRDevice = function () {\n return this._vrDisplay;\n };\n Engine.prototype.initWebVR = function () {\n this.initWebVRAsync();\n return this.onVRDisplayChangedObservable;\n };\n Engine.prototype.initWebVRAsync = function () {\n const notifyObservers = () => {\n const eventArgs = {\n vrDisplay: this._vrDisplay,\n vrSupported: this._vrSupported,\n };\n this.onVRDisplayChangedObservable.notifyObservers(eventArgs);\n this._webVRInitPromise = new Promise((res) => {\n res(eventArgs);\n });\n };\n if (!this._onVrDisplayConnect) {\n this._onVrDisplayConnect = (event) => {\n this._vrDisplay = event.display;\n notifyObservers();\n };\n this._onVrDisplayDisconnect = () => {\n this._vrDisplay.cancelAnimationFrame(this._frameHandler);\n this._vrDisplay = undefined;\n this._frameHandler = Engine.QueueNewFrame(this._boundRenderFunction);\n notifyObservers();\n };\n this._onVrDisplayPresentChange = () => {\n this._vrExclusivePointerMode = this._vrDisplay && this._vrDisplay.isPresenting;\n };\n const hostWindow = this.getHostWindow();\n if (hostWindow) {\n hostWindow.addEventListener(\"vrdisplayconnect\", this._onVrDisplayConnect);\n hostWindow.addEventListener(\"vrdisplaydisconnect\", this._onVrDisplayDisconnect);\n hostWindow.addEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChange);\n }\n }\n this._webVRInitPromise = this._webVRInitPromise || this._getVRDisplaysAsync();\n this._webVRInitPromise.then(notifyObservers);\n return this._webVRInitPromise;\n };\n Engine.prototype._getVRDisplaysAsync = function () {\n return new Promise((res) => {\n if (navigator.getVRDisplays) {\n navigator.getVRDisplays().then((devices) => {\n this._vrSupported = true;\n // note that devices may actually be an empty array. This is fine;\n // we expect this._vrDisplay to be undefined in this case.\n this._vrDisplay = devices[0];\n res({\n vrDisplay: this._vrDisplay,\n vrSupported: this._vrSupported,\n });\n });\n }\n else {\n this._vrDisplay = undefined;\n this._vrSupported = false;\n res({\n vrDisplay: this._vrDisplay,\n vrSupported: this._vrSupported,\n });\n }\n });\n };\n Engine.prototype.enableVR = function (options) {\n if (this._vrDisplay && !this._vrDisplay.isPresenting) {\n const onResolved = () => {\n this.onVRRequestPresentComplete.notifyObservers(true);\n this._onVRFullScreenTriggered();\n };\n const onRejected = () => {\n this.onVRRequestPresentComplete.notifyObservers(false);\n };\n this.onVRRequestPresentStart.notifyObservers(this);\n const presentationAttributes = {\n highRefreshRate: this.vrPresentationAttributes ? this.vrPresentationAttributes.highRefreshRate : false,\n foveationLevel: this.vrPresentationAttributes ? this.vrPresentationAttributes.foveationLevel : 1,\n multiview: (this.getCaps().multiview || this.getCaps().oculusMultiview) && options.useMultiview,\n };\n this._vrDisplay\n .requestPresent([\n Object.assign({ source: this.getRenderingCanvas(), attributes: presentationAttributes }, presentationAttributes),\n ])\n .then(onResolved)\n .catch(onRejected);\n }\n };\n Engine.prototype._onVRFullScreenTriggered = function () {\n if (this._vrDisplay && this._vrDisplay.isPresenting) {\n //get the old size before we change\n this._oldSize = new Size(this.getRenderWidth(), this.getRenderHeight());\n this._oldHardwareScaleFactor = this.getHardwareScalingLevel();\n //get the width and height, change the render size\n const leftEye = this._vrDisplay.getEyeParameters(\"left\");\n this.setHardwareScalingLevel(1);\n this.setSize(leftEye.renderWidth * 2, leftEye.renderHeight);\n }\n else {\n this.setHardwareScalingLevel(this._oldHardwareScaleFactor);\n this.setSize(this._oldSize.width, this._oldSize.height);\n }\n };\n Engine.prototype.disableVR = function () {\n if (this._vrDisplay && this._vrDisplay.isPresenting) {\n this._vrDisplay\n .exitPresent()\n .then(() => this._onVRFullScreenTriggered())\n .catch(() => this._onVRFullScreenTriggered());\n }\n if (IsWindowObjectExist()) {\n window.removeEventListener(\"vrdisplaypointerrestricted\", this._onVRDisplayPointerRestricted);\n window.removeEventListener(\"vrdisplaypointerunrestricted\", this._onVRDisplayPointerUnrestricted);\n if (this._onVrDisplayConnect) {\n window.removeEventListener(\"vrdisplayconnect\", this._onVrDisplayConnect);\n if (this._onVrDisplayDisconnect) {\n window.removeEventListener(\"vrdisplaydisconnect\", this._onVrDisplayDisconnect);\n }\n if (this._onVrDisplayPresentChange) {\n window.removeEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChange);\n }\n this._onVrDisplayConnect = null;\n this._onVrDisplayDisconnect = null;\n }\n }\n };\n Engine.prototype._connectVREvents = function (canvas, document) {\n this._onVRDisplayPointerRestricted = () => {\n if (canvas) {\n canvas.requestPointerLock();\n }\n };\n this._onVRDisplayPointerUnrestricted = () => {\n // Edge fix - for some reason document is not present and this is window\n if (!document) {\n const hostWindow = this.getHostWindow();\n if (hostWindow.document && hostWindow.document.exitPointerLock) {\n hostWindow.document.exitPointerLock();\n }\n return;\n }\n if (!document.exitPointerLock) {\n return;\n }\n document.exitPointerLock();\n };\n if (IsWindowObjectExist()) {\n const hostWindow = this.getHostWindow();\n hostWindow.addEventListener(\"vrdisplaypointerrestricted\", this._onVRDisplayPointerRestricted, false);\n hostWindow.addEventListener(\"vrdisplaypointerunrestricted\", this._onVRDisplayPointerUnrestricted, false);\n }\n };\n Engine.prototype._submitVRFrame = function () {\n // Submit frame to the vr device, if enabled\n if (this._vrDisplay && this._vrDisplay.isPresenting) {\n // TODO: We should only submit the frame if we read frameData successfully.\n try {\n this._vrDisplay.submitFrame();\n }\n catch (e) {\n Tools.Warn(\"webVR submitFrame has had an unexpected failure: \" + e);\n }\n }\n };\n Engine.prototype.isVRPresenting = function () {\n return this._vrDisplay && this._vrDisplay.isPresenting;\n };\n Engine.prototype._requestVRFrame = function () {\n this._frameHandler = Engine.QueueNewFrame(this._boundRenderFunction, this._vrDisplay);\n };\n\n Node.AddNodeConstructor(\"WebVRFreeCamera\", (name, scene) => {\n return () => new WebVRFreeCamera(name, Vector3.Zero(), scene);\n });\n Node.AddNodeConstructor(\"WebVRGamepadCamera\", (name, scene) => {\n return () => new WebVRFreeCamera(name, Vector3.Zero(), scene);\n });\n /**\n * This represents a WebVR camera.\n * The WebVR camera is Babylon's simple interface to interaction with Windows Mixed Reality, HTC Vive and Oculus Rift.\n * @deprecated Use WebXR instead - https://doc.babylonjs.com/features/featuresDeepDive/webXR\n * @example https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRCamera\n */\n class WebVRFreeCamera extends FreeCamera {\n /**\n * Instantiates a WebVRFreeCamera.\n * @param name The name of the WebVRFreeCamera\n * @param position The starting anchor position for the camera\n * @param scene The scene the camera belongs to\n * @param _webVROptions a set of customizable options for the webVRCamera\n */\n constructor(name, position, scene, _webVROptions = {}) {\n super(name, position, scene);\n this._webVROptions = _webVROptions;\n /**\n * @internal\n * The vrDisplay tied to the camera. See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay\n */\n this._vrDevice = null;\n /**\n * The rawPose of the vrDevice.\n */\n this.rawPose = null;\n this._specsVersion = \"1.1\";\n this._attached = false;\n this._descendants = [];\n // Represents device position and rotation in room space. Should only be used to help calculate babylon space values\n this._deviceRoomPosition = Vector3.Zero();\n /** @internal */\n this._deviceRoomRotationQuaternion = Quaternion.Identity();\n this._standingMatrix = null;\n /**\n * Represents device position in babylon space.\n */\n this.devicePosition = Vector3.Zero();\n /**\n * Represents device rotation in babylon space.\n */\n this.deviceRotationQuaternion = Quaternion.Identity();\n /**\n * The scale of the device to be used when translating from device space to babylon space.\n */\n this.deviceScaleFactor = 1;\n this._deviceToWorld = Matrix.Identity();\n this._worldToDevice = Matrix.Identity();\n /**\n * References to the webVR controllers for the vrDevice.\n */\n this.controllers = [];\n /**\n * Emits an event when a controller is attached.\n */\n this.onControllersAttachedObservable = new Observable$1();\n /**\n * Emits an event when a controller's mesh has been loaded;\n */\n this.onControllerMeshLoadedObservable = new Observable$1();\n /**\n * Emits an event when the HMD's pose has been updated.\n */\n this.onPoseUpdatedFromDeviceObservable = new Observable$1();\n this._poseSet = false;\n /**\n * If the rig cameras be used as parent instead of this camera.\n */\n this.rigParenting = true;\n this._defaultHeight = undefined;\n this._setRigMode = setWebVRRigMode.bind(null, this);\n this._detachIfAttached = () => {\n const vrDisplay = this.getEngine().getVRDevice();\n if (vrDisplay && !vrDisplay.isPresenting) {\n this.detachControl();\n }\n };\n this._workingVector = Vector3.Zero();\n this._oneVector = Vector3.One();\n this._workingMatrix = Matrix.Identity();\n this._tmpMatrix = new Matrix();\n this._cache.position = Vector3.Zero();\n if (_webVROptions.defaultHeight) {\n this._defaultHeight = _webVROptions.defaultHeight;\n this.position.y = this._defaultHeight;\n }\n this.minZ = 0.1;\n //legacy support - the compensation boolean was removed.\n if (arguments.length === 5) {\n // eslint-disable-next-line prefer-rest-params\n this._webVROptions = arguments[4];\n }\n // default webVR options\n if (this._webVROptions.trackPosition == undefined) {\n this._webVROptions.trackPosition = true;\n }\n if (this._webVROptions.controllerMeshes == undefined) {\n this._webVROptions.controllerMeshes = true;\n }\n if (this._webVROptions.defaultLightingOnControllers == undefined) {\n this._webVROptions.defaultLightingOnControllers = true;\n }\n this.rotationQuaternion = new Quaternion();\n if (this._webVROptions && this._webVROptions.positionScale) {\n this.deviceScaleFactor = this._webVROptions.positionScale;\n }\n //enable VR\n const engine = this.getEngine();\n this._onVREnabled = (success) => {\n if (success) {\n this.initControllers();\n }\n };\n engine.onVRRequestPresentComplete.add(this._onVREnabled);\n engine.initWebVR().add((event) => {\n if (!event.vrDisplay || this._vrDevice === event.vrDisplay) {\n return;\n }\n this._vrDevice = event.vrDisplay;\n //reset the rig parameters.\n this.setCameraRigMode(Camera.RIG_MODE_WEBVR, { parentCamera: this, vrDisplay: this._vrDevice, frameData: this._frameData, specs: this._specsVersion });\n if (this._attached) {\n this.getEngine().enableVR(this._webVROptions);\n }\n });\n if (typeof VRFrameData !== \"undefined\") {\n this._frameData = new VRFrameData();\n }\n if (_webVROptions.useMultiview) {\n if (!this.getScene().getEngine().getCaps().multiview) {\n Logger.Warn(\"Multiview is not supported, falling back to standard rendering\");\n this._useMultiviewToSingleView = false;\n }\n else {\n this._useMultiviewToSingleView = true;\n this._rigPostProcess = new VRMultiviewToSingleviewPostProcess(\"VRMultiviewToSingleview\", this, 1.0);\n }\n }\n /**\n * The idea behind the following lines:\n * objects that have the camera as parent should actually have the rig cameras as a parent.\n * BUT, each of those cameras has a different view matrix, which means that if we set the parent to the first rig camera,\n * the second will not show it correctly.\n *\n * To solve this - each object that has the camera as parent will be added to a protected array.\n * When the rig camera renders, it will take this array and set all of those to be its children.\n * This way, the right camera will be used as a parent, and the mesh will be rendered correctly.\n * Amazing!\n */\n this.getScene().onBeforeCameraRenderObservable.add((camera) => {\n if (camera.parent === this && this.rigParenting) {\n this._descendants = this.getDescendants(true, (n) => {\n // don't take the cameras or the controllers!\n const isController = this.controllers.some((controller) => {\n return controller._mesh === n;\n });\n const isRigCamera = this._rigCameras.indexOf(n) !== -1;\n return !isController && !isRigCamera;\n });\n this._descendants.forEach((node) => {\n node.parent = camera;\n });\n }\n });\n this.getScene().onAfterCameraRenderObservable.add((camera) => {\n if (camera.parent === this && this.rigParenting) {\n this._descendants.forEach((node) => {\n node.parent = this;\n });\n }\n });\n }\n /**\n * Gets the device distance from the ground in meters.\n * @returns the distance in meters from the vrDevice to ground in device space. If standing matrix is not supported for the vrDevice 0 is returned.\n */\n deviceDistanceToRoomGround() {\n if (this._standingMatrix) {\n // Add standing matrix offset to get real offset from ground in room\n this._standingMatrix.getTranslationToRef(this._workingVector);\n return this._deviceRoomPosition.y + this._workingVector.y;\n }\n //If VRDisplay does not inform stage parameters and no default height is set we fallback to zero.\n return this._defaultHeight || 0;\n }\n /**\n * Enables the standing matrix when supported. This can be used to position the user's view the correct height from the ground.\n * @param callback will be called when the standing matrix is set. Callback parameter is if the standing matrix is supported.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n useStandingMatrix(callback = (bool) => { }) {\n // Use standing matrix if available\n this.getEngine()\n .initWebVRAsync()\n .then((result) => {\n if (!result.vrDisplay || !result.vrDisplay.stageParameters || !result.vrDisplay.stageParameters.sittingToStandingTransform || !this._webVROptions.trackPosition) {\n callback(false);\n }\n else {\n this._standingMatrix = new Matrix();\n Matrix.FromFloat32ArrayToRefScaled(result.vrDisplay.stageParameters.sittingToStandingTransform, 0, 1, this._standingMatrix);\n if (!this.getScene().useRightHandedSystem) {\n if (this._standingMatrix) {\n this._standingMatrix.toggleModelMatrixHandInPlace();\n }\n }\n callback(true);\n }\n });\n }\n /**\n * Enables the standing matrix when supported. This can be used to position the user's view the correct height from the ground.\n * @returns A promise with a boolean set to if the standing matrix is supported.\n */\n useStandingMatrixAsync() {\n return new Promise((res) => {\n this.useStandingMatrix((supported) => {\n res(supported);\n });\n });\n }\n /**\n * Disposes the camera\n */\n dispose() {\n this._detachIfAttached();\n this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);\n if (this._updateCacheWhenTrackingDisabledObserver) {\n this._scene.onBeforeRenderObservable.remove(this._updateCacheWhenTrackingDisabledObserver);\n }\n super.dispose();\n }\n /**\n * Gets a vrController by name.\n * @param name The name of the controller to retrieve\n * @returns the controller matching the name specified or null if not found\n */\n getControllerByName(name) {\n for (const gp of this.controllers) {\n if (gp.hand === name) {\n return gp;\n }\n }\n return null;\n }\n /**\n * The controller corresponding to the users left hand.\n */\n get leftController() {\n if (!this._leftController) {\n this._leftController = this.getControllerByName(\"left\");\n }\n return this._leftController;\n }\n /**\n * The controller corresponding to the users right hand.\n */\n get rightController() {\n if (!this._rightController) {\n this._rightController = this.getControllerByName(\"right\");\n }\n return this._rightController;\n }\n /**\n * Casts a ray forward from the vrCamera's gaze.\n * @param length Length of the ray (default: 100)\n * @returns the ray corresponding to the gaze\n */\n getForwardRay(length = 100) {\n if (this.leftCamera) {\n // Use left eye to avoid computation to compute center on every call\n return super.getForwardRay(length, this.leftCamera.getWorldMatrix(), this.leftCamera.globalPosition); // Need the actual rendered camera\n }\n else {\n return super.getForwardRay(length);\n }\n }\n /**\n * @internal\n * Updates the camera based on device's frame data\n */\n _checkInputs() {\n if (this._vrDevice && this._vrDevice.isPresenting) {\n this._vrDevice.getFrameData(this._frameData);\n this.updateFromDevice(this._frameData.pose);\n }\n super._checkInputs();\n }\n /**\n * Updates the poseControlled values based on the input device pose.\n * @param poseData Pose coming from the device\n */\n updateFromDevice(poseData) {\n if (poseData && poseData.orientation && poseData.orientation.length === 4) {\n this.rawPose = poseData;\n this._deviceRoomRotationQuaternion.copyFromFloats(poseData.orientation[0], poseData.orientation[1], -poseData.orientation[2], -poseData.orientation[3]);\n if (this.getScene().useRightHandedSystem) {\n this._deviceRoomRotationQuaternion.z *= -1;\n this._deviceRoomRotationQuaternion.w *= -1;\n }\n if (this._webVROptions.trackPosition && this.rawPose.position) {\n this._deviceRoomPosition.copyFromFloats(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2]);\n if (this.getScene().useRightHandedSystem) {\n this._deviceRoomPosition.z *= -1;\n }\n }\n this._poseSet = true;\n }\n }\n /**\n * WebVR's attach control will start broadcasting frames to the device.\n * Note that in certain browsers (chrome for example) this function must be called\n * within a user-interaction callback. Example:\n *
 scene.onPointerDown = function() { camera.attachControl(canvas); }
\n *\n * @param noPreventDefault prevent the default html element operation when attaching the vrDevice\n */\n attachControl(noPreventDefault) {\n // eslint-disable-next-line prefer-rest-params\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\n super.attachControl(noPreventDefault);\n this._attached = true;\n noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;\n if (this._vrDevice) {\n this.getEngine().enableVR(this._webVROptions);\n }\n const hostWindow = this._scene.getEngine().getHostWindow();\n if (hostWindow) {\n hostWindow.addEventListener(\"vrdisplaypresentchange\", this._detachIfAttached);\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);\n this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);\n super.detachControl();\n this._attached = false;\n this.getEngine().disableVR();\n window.removeEventListener(\"vrdisplaypresentchange\", this._detachIfAttached);\n }\n /**\n * @returns the name of this class\n */\n getClassName() {\n return \"WebVRFreeCamera\";\n }\n /**\n * Calls resetPose on the vrDisplay\n * See: https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/resetPose\n */\n resetToCurrentRotation() {\n //uses the vrDisplay's \"resetPose()\".\n //pitch and roll won't be affected.\n this._vrDevice.resetPose();\n }\n /**\n * @internal\n * Updates the rig cameras (left and right eye)\n */\n _updateRigCameras() {\n const camLeft = this._rigCameras[0];\n const camRight = this._rigCameras[1];\n camLeft.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion);\n camRight.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion);\n camLeft.position.copyFrom(this._deviceRoomPosition);\n camRight.position.copyFrom(this._deviceRoomPosition);\n }\n // Remove translation from 6dof headset if trackposition is set to false\n _correctPositionIfNotTrackPosition(matrix, isViewMatrix = false) {\n if (this.rawPose && this.rawPose.position && !this._webVROptions.trackPosition) {\n Matrix.TranslationToRef(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2], this._tmpMatrix);\n if (!isViewMatrix) {\n this._tmpMatrix.invert();\n }\n this._tmpMatrix.multiplyToRef(matrix, matrix);\n }\n }\n /**\n * @internal\n * Updates the cached values of the camera\n * @param ignoreParentClass ignores updating the parent class's cache (default: false)\n */\n _updateCache(ignoreParentClass) {\n if (!this.rotationQuaternion.equals(this._cache.rotationQuaternion) || !this.position.equals(this._cache.position)) {\n // Update to ensure devicePosition is up to date with most recent _deviceRoomPosition\n if (!this._updateCacheCalled) {\n // make sure it is only called once per loop. this.update() might cause an infinite loop.\n this._updateCacheCalled = true;\n this.update();\n }\n // Set working vector to the device position in room space rotated by the new rotation\n this.rotationQuaternion.toRotationMatrix(this._workingMatrix);\n Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._workingMatrix, this._workingVector);\n // Subtract this vector from the current device position in world to get the translation for the device world matrix\n this.devicePosition.subtractToRef(this._workingVector, this._workingVector);\n Matrix.ComposeToRef(this._oneVector, this.rotationQuaternion, this._workingVector, this._deviceToWorld);\n // Add translation from anchor position\n this._deviceToWorld.getTranslationToRef(this._workingVector);\n this._workingVector.addInPlace(this.position);\n this._workingVector.subtractInPlace(this._cache.position);\n this._deviceToWorld.setTranslation(this._workingVector);\n // Set an inverted matrix to be used when updating the camera\n this._deviceToWorld.invertToRef(this._worldToDevice);\n // Update the gamepad to ensure the mesh is updated on the same frame as camera\n this.controllers.forEach((controller) => {\n controller._deviceToWorld.copyFrom(this._deviceToWorld);\n this._correctPositionIfNotTrackPosition(controller._deviceToWorld);\n controller.update();\n });\n }\n if (!ignoreParentClass) {\n super._updateCache();\n }\n this._updateCacheCalled = false;\n }\n /**\n * @internal\n * Get current device position in babylon world\n */\n _computeDevicePosition() {\n Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._deviceToWorld, this.devicePosition);\n }\n /**\n * Updates the current device position and rotation in the babylon world\n */\n update() {\n this._computeDevicePosition();\n // Get current device rotation in babylon world\n Matrix.FromQuaternionToRef(this._deviceRoomRotationQuaternion, this._workingMatrix);\n this._workingMatrix.multiplyToRef(this._deviceToWorld, this._workingMatrix);\n Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);\n if (this._poseSet) {\n this.onPoseUpdatedFromDeviceObservable.notifyObservers(null);\n }\n super.update();\n }\n /**\n * @internal\n * Gets the view matrix of this camera (Always set to identity as left and right eye cameras contain the actual view matrix)\n * @returns an identity matrix\n */\n _getViewMatrix() {\n return Matrix.Identity();\n }\n /**\n * This function is called by the two RIG cameras.\n * 'this' is the left or right camera (and NOT (!!!) the WebVRFreeCamera instance)\n * @internal\n */\n _getWebVRViewMatrix() {\n // Update the parent camera prior to using a child camera to avoid desynchronization\n const parentCamera = this._cameraRigParams[\"parentCamera\"];\n parentCamera._updateCache();\n //WebVR 1.1\n const viewArray = this._cameraRigParams[\"left\"] ? this._cameraRigParams[\"frameData\"].leftViewMatrix : this._cameraRigParams[\"frameData\"].rightViewMatrix;\n Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);\n if (!this.getScene().useRightHandedSystem) {\n this._webvrViewMatrix.toggleModelMatrixHandInPlace();\n }\n // update the camera rotation matrix\n this._webvrViewMatrix.getRotationMatrixToRef(this._cameraRotationMatrix);\n Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);\n // Computing target and final matrix\n this.position.addToRef(this._transformedReferencePoint, this._currentTarget);\n // should the view matrix be updated with scale and position offset?\n if (parentCamera.deviceScaleFactor !== 1) {\n this._webvrViewMatrix.invert();\n // scale the position, if set\n if (parentCamera.deviceScaleFactor) {\n this._webvrViewMatrix.multiplyAtIndex(12, parentCamera.deviceScaleFactor);\n this._webvrViewMatrix.multiplyAtIndex(13, parentCamera.deviceScaleFactor);\n this._webvrViewMatrix.multiplyAtIndex(14, parentCamera.deviceScaleFactor);\n }\n this._webvrViewMatrix.invert();\n }\n // Remove translation from 6dof headset if trackposition is set to false\n parentCamera._correctPositionIfNotTrackPosition(this._webvrViewMatrix, true);\n parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);\n // Compute global position\n this._workingMatrix = this._workingMatrix || Matrix.Identity();\n this._webvrViewMatrix.invertToRef(this._workingMatrix);\n this._workingMatrix.multiplyToRef(parentCamera.getWorldMatrix(), this._workingMatrix);\n this._workingMatrix.getTranslationToRef(this._globalPosition);\n this._markSyncedWithParent();\n return this._webvrViewMatrix;\n }\n /** @internal */\n _getWebVRProjectionMatrix() {\n const parentCamera = this.parent;\n parentCamera._vrDevice.depthNear = parentCamera.minZ;\n parentCamera._vrDevice.depthFar = parentCamera.maxZ;\n const projectionArray = this._cameraRigParams[\"left\"] ? this._cameraRigParams[\"frameData\"].leftProjectionMatrix : this._cameraRigParams[\"frameData\"].rightProjectionMatrix;\n Matrix.FromArrayToRef(projectionArray, 0, this._projectionMatrix);\n //babylon compatible matrix\n if (!this.getScene().useRightHandedSystem) {\n this._projectionMatrix.toggleProjectionMatrixHandInPlace();\n }\n return this._projectionMatrix;\n }\n /**\n * Initializes the controllers and their meshes\n */\n initControllers() {\n this.controllers.length = 0;\n const manager = this.getScene().gamepadManager;\n this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add((gamepad) => {\n if (gamepad.type === Gamepad.POSE_ENABLED) {\n const webVrController = gamepad;\n if (webVrController.defaultModel) {\n webVrController.defaultModel.setEnabled(false);\n }\n if (webVrController.hand === \"right\") {\n this._rightController = null;\n }\n if (webVrController.hand === \"left\") {\n this._leftController = null;\n }\n const controllerIndex = this.controllers.indexOf(webVrController);\n if (controllerIndex !== -1) {\n this.controllers.splice(controllerIndex, 1);\n }\n }\n });\n this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {\n if (gamepad.type === Gamepad.POSE_ENABLED) {\n const webVrController = gamepad;\n if (!this._webVROptions.trackPosition) {\n webVrController._disableTrackPosition(new Vector3(webVrController.hand == \"left\" ? -0.15 : 0.15, -0.5, 0.25));\n // Cache must be updated before rendering controllers to avoid them being one frame behind\n if (!this._updateCacheWhenTrackingDisabledObserver) {\n this._updateCacheWhenTrackingDisabledObserver = this._scene.onBeforeRenderObservable.add(() => {\n this._updateCache();\n });\n }\n }\n webVrController.deviceScaleFactor = this.deviceScaleFactor;\n webVrController._deviceToWorld.copyFrom(this._deviceToWorld);\n this._correctPositionIfNotTrackPosition(webVrController._deviceToWorld);\n if (this._webVROptions.controllerMeshes) {\n if (webVrController.defaultModel) {\n webVrController.defaultModel.setEnabled(true);\n }\n else {\n // Load the meshes\n webVrController.initControllerMesh(this.getScene(), (loadedMesh) => {\n loadedMesh.scaling.scaleInPlace(this.deviceScaleFactor);\n this.onControllerMeshLoadedObservable.notifyObservers(webVrController);\n if (this._webVROptions.defaultLightingOnControllers) {\n if (!this._lightOnControllers) {\n this._lightOnControllers = new HemisphericLight(\"vrControllersLight\", new Vector3(0, 1, 0), this.getScene());\n }\n const activateLightOnSubMeshes = function (mesh, light) {\n const children = mesh.getChildren();\n if (children && children.length !== 0) {\n children.forEach((mesh) => {\n light.includedOnlyMeshes.push(mesh);\n activateLightOnSubMeshes(mesh, light);\n });\n }\n };\n this._lightOnControllers.includedOnlyMeshes.push(loadedMesh);\n activateLightOnSubMeshes(loadedMesh, this._lightOnControllers);\n }\n });\n }\n }\n webVrController.attachToPoseControlledCamera(this);\n // since this is async - sanity check. Is the controller already stored?\n if (this.controllers.indexOf(webVrController) === -1) {\n //add to the controllers array\n this.controllers.push(webVrController);\n // Forced to add some control code for Vive as it doesn't always fill properly the \"hand\" property\n // Sometimes, both controllers are set correctly (left and right), sometimes none, sometimes only one of them...\n // So we're overriding setting left & right manually to be sure\n let firstViveWandDetected = false;\n for (let i = 0; i < this.controllers.length; i++) {\n if (this.controllers[i].controllerType === PoseEnabledControllerType.VIVE) {\n if (!firstViveWandDetected) {\n firstViveWandDetected = true;\n this.controllers[i].hand = \"left\";\n }\n else {\n this.controllers[i].hand = \"right\";\n }\n }\n }\n //did we find enough controllers? Great! let the developer know.\n if (this.controllers.length >= 2) {\n this.onControllersAttachedObservable.notifyObservers(this.controllers);\n }\n }\n }\n });\n }\n }\n\n /**\n * Defines the WebVRController object that represents controllers tracked in 3D space\n * @deprecated Use WebXR instead\n */\n class WebVRController extends PoseEnabledController {\n /**\n * Fired when a controller button's state has changed\n * @param callback the callback containing the button that was modified\n */\n onButtonStateChange(callback) {\n this._onButtonStateChange = callback;\n }\n /**\n * The default controller model for the controller\n */\n get defaultModel() {\n return this._defaultModel;\n }\n /**\n * Creates a new WebVRController from a gamepad\n * @param vrGamepad the gamepad that the WebVRController should be created from\n */\n constructor(vrGamepad) {\n super(vrGamepad);\n // Observables\n /**\n * Fired when the trigger state has changed\n */\n this.onTriggerStateChangedObservable = new Observable$1();\n /**\n * Fired when the main button state has changed\n */\n this.onMainButtonStateChangedObservable = new Observable$1();\n /**\n * Fired when the secondary button state has changed\n */\n this.onSecondaryButtonStateChangedObservable = new Observable$1();\n /**\n * Fired when the pad state has changed\n */\n this.onPadStateChangedObservable = new Observable$1();\n /**\n * Fired when controllers stick values have changed\n */\n this.onPadValuesChangedObservable = new Observable$1();\n /**\n * X and Y axis corresponding to the controllers joystick\n */\n this.pad = { x: 0, y: 0 };\n // avoid GC, store state in a tmp object\n this._changes = {\n pressChanged: false,\n touchChanged: false,\n valueChanged: false,\n changed: false,\n };\n this._buttons = new Array(vrGamepad.buttons.length);\n this.hand = vrGamepad.hand;\n }\n /**\n * Updates the state of the controller and mesh based on the current position and rotation of the controller\n */\n update() {\n super.update();\n for (let index = 0; index < this._buttons.length; index++) {\n this._setButtonValue(this.browserGamepad.buttons[index], this._buttons[index], index);\n }\n if (this.leftStick.x !== this.pad.x || this.leftStick.y !== this.pad.y) {\n this.pad.x = this.leftStick.x;\n this.pad.y = this.leftStick.y;\n this.onPadValuesChangedObservable.notifyObservers(this.pad);\n }\n }\n _setButtonValue(newState, currentState, buttonIndex) {\n if (!newState) {\n newState = {\n pressed: false,\n touched: false,\n value: 0,\n };\n }\n if (!currentState) {\n this._buttons[buttonIndex] = {\n pressed: newState.pressed,\n touched: newState.touched,\n value: newState.value,\n };\n return;\n }\n this._checkChanges(newState, currentState);\n if (this._changes.changed) {\n this._onButtonStateChange && this._onButtonStateChange(this.index, buttonIndex, newState);\n this._handleButtonChange(buttonIndex, newState, this._changes);\n }\n this._buttons[buttonIndex].pressed = newState.pressed;\n this._buttons[buttonIndex].touched = newState.touched;\n // oculus triggers are never 0, thou not touched.\n this._buttons[buttonIndex].value = newState.value < 0.00000001 ? 0 : newState.value;\n }\n _checkChanges(newState, currentState) {\n this._changes.pressChanged = newState.pressed !== currentState.pressed;\n this._changes.touchChanged = newState.touched !== currentState.touched;\n this._changes.valueChanged = newState.value !== currentState.value;\n this._changes.changed = this._changes.pressChanged || this._changes.touchChanged || this._changes.valueChanged;\n return this._changes;\n }\n /**\n * Disposes of th webVRController\n */\n dispose() {\n super.dispose();\n this._defaultModel = null;\n this.onTriggerStateChangedObservable.clear();\n this.onMainButtonStateChangedObservable.clear();\n this.onSecondaryButtonStateChangedObservable.clear();\n this.onPadStateChangedObservable.clear();\n this.onPadValuesChangedObservable.clear();\n }\n }\n\n /**\n * Defines supported buttons for XBox360 compatible gamepads\n */\n var Xbox360Button;\n (function (Xbox360Button) {\n /** A */\n Xbox360Button[Xbox360Button[\"A\"] = 0] = \"A\";\n /** B */\n Xbox360Button[Xbox360Button[\"B\"] = 1] = \"B\";\n /** X */\n Xbox360Button[Xbox360Button[\"X\"] = 2] = \"X\";\n /** Y */\n Xbox360Button[Xbox360Button[\"Y\"] = 3] = \"Y\";\n /** Left button */\n Xbox360Button[Xbox360Button[\"LB\"] = 4] = \"LB\";\n /** Right button */\n Xbox360Button[Xbox360Button[\"RB\"] = 5] = \"RB\";\n /** Back */\n Xbox360Button[Xbox360Button[\"Back\"] = 8] = \"Back\";\n /** Start */\n Xbox360Button[Xbox360Button[\"Start\"] = 9] = \"Start\";\n /** Left stick */\n Xbox360Button[Xbox360Button[\"LeftStick\"] = 10] = \"LeftStick\";\n /** Right stick */\n Xbox360Button[Xbox360Button[\"RightStick\"] = 11] = \"RightStick\";\n })(Xbox360Button || (Xbox360Button = {}));\n /** Defines values for XBox360 DPad */\n var Xbox360Dpad;\n (function (Xbox360Dpad) {\n /** Up */\n Xbox360Dpad[Xbox360Dpad[\"Up\"] = 12] = \"Up\";\n /** Down */\n Xbox360Dpad[Xbox360Dpad[\"Down\"] = 13] = \"Down\";\n /** Left */\n Xbox360Dpad[Xbox360Dpad[\"Left\"] = 14] = \"Left\";\n /** Right */\n Xbox360Dpad[Xbox360Dpad[\"Right\"] = 15] = \"Right\";\n })(Xbox360Dpad || (Xbox360Dpad = {}));\n /**\n * Defines a XBox360 gamepad\n */\n class Xbox360Pad extends Gamepad {\n /**\n * Creates a new XBox360 gamepad object\n * @param id defines the id of this gamepad\n * @param index defines its index\n * @param gamepad defines the internal HTML gamepad object\n * @param xboxOne defines if it is a XBox One gamepad\n */\n constructor(id, index, gamepad, xboxOne = false) {\n super(id, index, gamepad, 0, 1, 2, 3);\n this._leftTrigger = 0;\n this._rightTrigger = 0;\n /** Observable raised when a button is pressed */\n this.onButtonDownObservable = new Observable$1();\n /** Observable raised when a button is released */\n this.onButtonUpObservable = new Observable$1();\n /** Observable raised when a pad is pressed */\n this.onPadDownObservable = new Observable$1();\n /** Observable raised when a pad is released */\n this.onPadUpObservable = new Observable$1();\n this._buttonA = 0;\n this._buttonB = 0;\n this._buttonX = 0;\n this._buttonY = 0;\n this._buttonBack = 0;\n this._buttonStart = 0;\n this._buttonLB = 0;\n this._buttonRB = 0;\n this._buttonLeftStick = 0;\n this._buttonRightStick = 0;\n this._dPadUp = 0;\n this._dPadDown = 0;\n this._dPadLeft = 0;\n this._dPadRight = 0;\n this._isXboxOnePad = false;\n this.type = Gamepad.XBOX;\n this._isXboxOnePad = xboxOne;\n }\n /**\n * Defines the callback to call when left trigger is pressed\n * @param callback defines the callback to use\n */\n onlefttriggerchanged(callback) {\n this._onlefttriggerchanged = callback;\n }\n /**\n * Defines the callback to call when right trigger is pressed\n * @param callback defines the callback to use\n */\n onrighttriggerchanged(callback) {\n this._onrighttriggerchanged = callback;\n }\n /**\n * Gets the left trigger value\n */\n get leftTrigger() {\n return this._leftTrigger;\n }\n /**\n * Sets the left trigger value\n */\n set leftTrigger(newValue) {\n if (this._onlefttriggerchanged && this._leftTrigger !== newValue) {\n this._onlefttriggerchanged(newValue);\n }\n this._leftTrigger = newValue;\n }\n /**\n * Gets the right trigger value\n */\n get rightTrigger() {\n return this._rightTrigger;\n }\n /**\n * Sets the right trigger value\n */\n set rightTrigger(newValue) {\n if (this._onrighttriggerchanged && this._rightTrigger !== newValue) {\n this._onrighttriggerchanged(newValue);\n }\n this._rightTrigger = newValue;\n }\n /**\n * Defines the callback to call when a button is pressed\n * @param callback defines the callback to use\n */\n onbuttondown(callback) {\n this._onbuttondown = callback;\n }\n /**\n * Defines the callback to call when a button is released\n * @param callback defines the callback to use\n */\n onbuttonup(callback) {\n this._onbuttonup = callback;\n }\n /**\n * Defines the callback to call when a pad is pressed\n * @param callback defines the callback to use\n */\n ondpaddown(callback) {\n this._ondpaddown = callback;\n }\n /**\n * Defines the callback to call when a pad is released\n * @param callback defines the callback to use\n */\n ondpadup(callback) {\n this._ondpadup = callback;\n }\n _setButtonValue(newValue, currentValue, buttonType) {\n if (newValue !== currentValue) {\n if (newValue === 1) {\n if (this._onbuttondown) {\n this._onbuttondown(buttonType);\n }\n this.onButtonDownObservable.notifyObservers(buttonType);\n }\n if (newValue === 0) {\n if (this._onbuttonup) {\n this._onbuttonup(buttonType);\n }\n this.onButtonUpObservable.notifyObservers(buttonType);\n }\n }\n return newValue;\n }\n _setDPadValue(newValue, currentValue, buttonType) {\n if (newValue !== currentValue) {\n if (newValue === 1) {\n if (this._ondpaddown) {\n this._ondpaddown(buttonType);\n }\n this.onPadDownObservable.notifyObservers(buttonType);\n }\n if (newValue === 0) {\n if (this._ondpadup) {\n this._ondpadup(buttonType);\n }\n this.onPadUpObservable.notifyObservers(buttonType);\n }\n }\n return newValue;\n }\n /**\n * Gets the value of the `A` button\n */\n get buttonA() {\n return this._buttonA;\n }\n /**\n * Sets the value of the `A` button\n */\n set buttonA(value) {\n this._buttonA = this._setButtonValue(value, this._buttonA, Xbox360Button.A);\n }\n /**\n * Gets the value of the `B` button\n */\n get buttonB() {\n return this._buttonB;\n }\n /**\n * Sets the value of the `B` button\n */\n set buttonB(value) {\n this._buttonB = this._setButtonValue(value, this._buttonB, Xbox360Button.B);\n }\n /**\n * Gets the value of the `X` button\n */\n get buttonX() {\n return this._buttonX;\n }\n /**\n * Sets the value of the `X` button\n */\n set buttonX(value) {\n this._buttonX = this._setButtonValue(value, this._buttonX, Xbox360Button.X);\n }\n /**\n * Gets the value of the `Y` button\n */\n get buttonY() {\n return this._buttonY;\n }\n /**\n * Sets the value of the `Y` button\n */\n set buttonY(value) {\n this._buttonY = this._setButtonValue(value, this._buttonY, Xbox360Button.Y);\n }\n /**\n * Gets the value of the `Start` button\n */\n get buttonStart() {\n return this._buttonStart;\n }\n /**\n * Sets the value of the `Start` button\n */\n set buttonStart(value) {\n this._buttonStart = this._setButtonValue(value, this._buttonStart, Xbox360Button.Start);\n }\n /**\n * Gets the value of the `Back` button\n */\n get buttonBack() {\n return this._buttonBack;\n }\n /**\n * Sets the value of the `Back` button\n */\n set buttonBack(value) {\n this._buttonBack = this._setButtonValue(value, this._buttonBack, Xbox360Button.Back);\n }\n /**\n * Gets the value of the `Left` button\n */\n get buttonLB() {\n return this._buttonLB;\n }\n /**\n * Sets the value of the `Left` button\n */\n set buttonLB(value) {\n this._buttonLB = this._setButtonValue(value, this._buttonLB, Xbox360Button.LB);\n }\n /**\n * Gets the value of the `Right` button\n */\n get buttonRB() {\n return this._buttonRB;\n }\n /**\n * Sets the value of the `Right` button\n */\n set buttonRB(value) {\n this._buttonRB = this._setButtonValue(value, this._buttonRB, Xbox360Button.RB);\n }\n /**\n * Gets the value of the Left joystick\n */\n get buttonLeftStick() {\n return this._buttonLeftStick;\n }\n /**\n * Sets the value of the Left joystick\n */\n set buttonLeftStick(value) {\n this._buttonLeftStick = this._setButtonValue(value, this._buttonLeftStick, Xbox360Button.LeftStick);\n }\n /**\n * Gets the value of the Right joystick\n */\n get buttonRightStick() {\n return this._buttonRightStick;\n }\n /**\n * Sets the value of the Right joystick\n */\n set buttonRightStick(value) {\n this._buttonRightStick = this._setButtonValue(value, this._buttonRightStick, Xbox360Button.RightStick);\n }\n /**\n * Gets the value of D-pad up\n */\n get dPadUp() {\n return this._dPadUp;\n }\n /**\n * Sets the value of D-pad up\n */\n set dPadUp(value) {\n this._dPadUp = this._setDPadValue(value, this._dPadUp, Xbox360Dpad.Up);\n }\n /**\n * Gets the value of D-pad down\n */\n get dPadDown() {\n return this._dPadDown;\n }\n /**\n * Sets the value of D-pad down\n */\n set dPadDown(value) {\n this._dPadDown = this._setDPadValue(value, this._dPadDown, Xbox360Dpad.Down);\n }\n /**\n * Gets the value of D-pad left\n */\n get dPadLeft() {\n return this._dPadLeft;\n }\n /**\n * Sets the value of D-pad left\n */\n set dPadLeft(value) {\n this._dPadLeft = this._setDPadValue(value, this._dPadLeft, Xbox360Dpad.Left);\n }\n /**\n * Gets the value of D-pad right\n */\n get dPadRight() {\n return this._dPadRight;\n }\n /**\n * Sets the value of D-pad right\n */\n set dPadRight(value) {\n this._dPadRight = this._setDPadValue(value, this._dPadRight, Xbox360Dpad.Right);\n }\n /**\n * Force the gamepad to synchronize with device values\n */\n update() {\n super.update();\n if (this._isXboxOnePad) {\n this.buttonA = this.browserGamepad.buttons[0].value;\n this.buttonB = this.browserGamepad.buttons[1].value;\n this.buttonX = this.browserGamepad.buttons[2].value;\n this.buttonY = this.browserGamepad.buttons[3].value;\n this.buttonLB = this.browserGamepad.buttons[4].value;\n this.buttonRB = this.browserGamepad.buttons[5].value;\n this.leftTrigger = this.browserGamepad.buttons[6].value;\n this.rightTrigger = this.browserGamepad.buttons[7].value;\n this.buttonBack = this.browserGamepad.buttons[8].value;\n this.buttonStart = this.browserGamepad.buttons[9].value;\n this.buttonLeftStick = this.browserGamepad.buttons[10].value;\n this.buttonRightStick = this.browserGamepad.buttons[11].value;\n this.dPadUp = this.browserGamepad.buttons[12].value;\n this.dPadDown = this.browserGamepad.buttons[13].value;\n this.dPadLeft = this.browserGamepad.buttons[14].value;\n this.dPadRight = this.browserGamepad.buttons[15].value;\n }\n else {\n this.buttonA = this.browserGamepad.buttons[0].value;\n this.buttonB = this.browserGamepad.buttons[1].value;\n this.buttonX = this.browserGamepad.buttons[2].value;\n this.buttonY = this.browserGamepad.buttons[3].value;\n this.buttonLB = this.browserGamepad.buttons[4].value;\n this.buttonRB = this.browserGamepad.buttons[5].value;\n this.leftTrigger = this.browserGamepad.buttons[6].value;\n this.rightTrigger = this.browserGamepad.buttons[7].value;\n this.buttonBack = this.browserGamepad.buttons[8].value;\n this.buttonStart = this.browserGamepad.buttons[9].value;\n this.buttonLeftStick = this.browserGamepad.buttons[10].value;\n this.buttonRightStick = this.browserGamepad.buttons[11].value;\n this.dPadUp = this.browserGamepad.buttons[12].value;\n this.dPadDown = this.browserGamepad.buttons[13].value;\n this.dPadLeft = this.browserGamepad.buttons[14].value;\n this.dPadRight = this.browserGamepad.buttons[15].value;\n }\n }\n /**\n * Disposes the gamepad\n */\n dispose() {\n super.dispose();\n this.onButtonDownObservable.clear();\n this.onButtonUpObservable.clear();\n this.onPadDownObservable.clear();\n this.onPadUpObservable.clear();\n }\n }\n\n ThinEngine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {\n const texture = new InternalTexture(this, InternalTextureSource.Dynamic);\n texture.baseWidth = width;\n texture.baseHeight = height;\n if (generateMipMaps) {\n width = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(width, this._caps.maxTextureSize) : width;\n height = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(height, this._caps.maxTextureSize) : height;\n }\n // this.resetTextureCache();\n texture.width = width;\n texture.height = height;\n texture.isReady = false;\n texture.generateMipMaps = generateMipMaps;\n texture.samplingMode = samplingMode;\n this.updateTextureSamplingMode(samplingMode, texture);\n this._internalTexturesCache.push(texture);\n return texture;\n };\n ThinEngine.prototype.updateDynamicTexture = function (texture, source, invertY, premulAlpha = false, format, forceBindTexture = false, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n allowGPUOptimization = false) {\n if (!texture) {\n return;\n }\n const gl = this._gl;\n const target = gl.TEXTURE_2D;\n const wasPreviouslyBound = this._bindTextureDirectly(target, texture, true, forceBindTexture);\n this._unpackFlipY(invertY === undefined ? texture.invertY : invertY);\n if (premulAlpha) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);\n }\n const textureType = this._getWebGLTextureType(texture.type);\n const glformat = this._getInternalFormat(format ? format : texture.format);\n const internalFormat = this._getRGBABufferInternalSizedFormat(texture.type, glformat);\n gl.texImage2D(target, 0, internalFormat, glformat, textureType, source);\n if (texture.generateMipMaps) {\n gl.generateMipmap(target);\n }\n if (!wasPreviouslyBound) {\n this._bindTextureDirectly(target, null);\n }\n if (premulAlpha) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);\n }\n texture.isReady = true;\n };\n\n /**\n * A class extending Texture allowing drawing on a texture\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/dynamicTexture\n */\n class DynamicTexture extends Texture {\n /**\n * Creates a DynamicTexture\n * @param name defines the name of the texture\n * @param options provides 3 alternatives for width and height of texture, a canvas, object with width and height properties, number for both width and height\n * @param scene defines the scene where you want the texture\n * @param generateMipMaps defines the use of MinMaps or not (default is false)\n * @param samplingMode defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)\n * @param format defines the texture format to use (default is Engine.TEXTUREFORMAT_RGBA)\n * @param invertY defines if the texture needs to be inverted on the y axis during loading\n */\n constructor(name, options, scene = null, generateMipMaps = false, samplingMode = 3, format = 5, invertY) {\n super(null, scene, !generateMipMaps, invertY, samplingMode, undefined, undefined, undefined, undefined, format);\n this.name = name;\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\n this._generateMipMaps = generateMipMaps;\n const engine = this._getEngine();\n if (!engine) {\n return;\n }\n if (options.getContext) {\n this._canvas = options;\n this._texture = engine.createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);\n }\n else {\n this._canvas = engine.createCanvas(1, 1);\n if (options.width || options.width === 0) {\n this._texture = engine.createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);\n }\n else {\n this._texture = engine.createDynamicTexture(options, options, generateMipMaps, samplingMode);\n }\n }\n const textureSize = this.getSize();\n if (this._canvas.width !== textureSize.width) {\n this._canvas.width = textureSize.width;\n }\n if (this._canvas.height !== textureSize.height) {\n this._canvas.height = textureSize.height;\n }\n this._context = this._canvas.getContext(\"2d\");\n }\n /**\n * Get the current class name of the texture useful for serialization or dynamic coding.\n * @returns \"DynamicTexture\"\n */\n getClassName() {\n return \"DynamicTexture\";\n }\n /**\n * Gets the current state of canRescale\n */\n get canRescale() {\n return true;\n }\n _recreate(textureSize) {\n this._canvas.width = textureSize.width;\n this._canvas.height = textureSize.height;\n this.releaseInternalTexture();\n this._texture = this._getEngine().createDynamicTexture(textureSize.width, textureSize.height, this._generateMipMaps, this.samplingMode);\n }\n /**\n * Scales the texture\n * @param ratio the scale factor to apply to both width and height\n */\n scale(ratio) {\n const textureSize = this.getSize();\n textureSize.width *= ratio;\n textureSize.height *= ratio;\n this._recreate(textureSize);\n }\n /**\n * Resizes the texture\n * @param width the new width\n * @param height the new height\n */\n scaleTo(width, height) {\n const textureSize = this.getSize();\n textureSize.width = width;\n textureSize.height = height;\n this._recreate(textureSize);\n }\n /**\n * Gets the context of the canvas used by the texture\n * @returns the canvas context of the dynamic texture\n */\n getContext() {\n return this._context;\n }\n /**\n * Clears the texture\n */\n clear() {\n const size = this.getSize();\n this._context.fillRect(0, 0, size.width, size.height);\n }\n /**\n * Updates the texture\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\n * @param premulAlpha defines if alpha is stored as premultiplied (default is false)\n * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature \"allowGPUOptimizationsForGUI\" being true)\n */\n update(invertY, premulAlpha = false, allowGPUOptimization = false) {\n this._getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY, premulAlpha, this._format || undefined, undefined, allowGPUOptimization);\n }\n /**\n * Draws text onto the texture\n * @param text defines the text to be drawn\n * @param x defines the placement of the text from the left\n * @param y defines the placement of the text from the top when invertY is true and from the bottom when false\n * @param font defines the font to be used with font-style, font-size, font-name\n * @param color defines the color used for the text\n * @param clearColor defines the color for the canvas, use null to not overwrite canvas\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\n * @param update defines whether texture is immediately update (default is true)\n */\n drawText(text, x, y, font, color, clearColor, invertY, update = true) {\n const size = this.getSize();\n if (clearColor) {\n this._context.fillStyle = clearColor;\n this._context.fillRect(0, 0, size.width, size.height);\n }\n this._context.font = font;\n if (x === null || x === undefined) {\n const textSize = this._context.measureText(text);\n x = (size.width - textSize.width) / 2;\n }\n if (y === null || y === undefined) {\n const fontSize = parseInt(font.replace(/\\D/g, \"\"));\n y = size.height / 2 + fontSize / 3.65;\n }\n this._context.fillStyle = color || \"\";\n this._context.fillText(text, x, y);\n if (update) {\n this.update(invertY);\n }\n }\n /**\n * Clones the texture\n * @returns the clone of the texture.\n */\n clone() {\n const scene = this.getScene();\n if (!scene) {\n return this;\n }\n const textureSize = this.getSize();\n const newTexture = new DynamicTexture(this.name, textureSize, scene, this._generateMipMaps);\n // Base texture\n newTexture.hasAlpha = this.hasAlpha;\n newTexture.level = this.level;\n // Dynamic Texture\n newTexture.wrapU = this.wrapU;\n newTexture.wrapV = this.wrapV;\n return newTexture;\n }\n /**\n * Serializes the dynamic texture. The scene should be ready before the dynamic texture is serialized\n * @returns a serialized dynamic texture object\n */\n serialize() {\n const scene = this.getScene();\n if (scene && !scene.isReady()) {\n Logger.Warn(\"The scene must be ready before serializing the dynamic texture\");\n }\n const serializationObject = super.serialize();\n if (DynamicTexture._IsCanvasElement(this._canvas)) {\n serializationObject.base64String = this._canvas.toDataURL();\n }\n serializationObject.invertY = this._invertY;\n serializationObject.samplingMode = this.samplingMode;\n return serializationObject;\n }\n static _IsCanvasElement(canvas) {\n return canvas.toDataURL !== undefined;\n }\n /** @internal */\n _rebuild() {\n this.update();\n }\n }\n\n // Do not edit.\n const name$1V = \"imageProcessingPixelShader\";\n const shader$1V = `varying vec2 vUV;uniform sampler2D textureSampler;\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec4 result=texture2D(textureSampler,vUV);\n#ifdef IMAGEPROCESSING\n#ifndef FROMLINEARSPACE\nresult.rgb=toLinearSpace(result.rgb);\n#endif\nresult=applyImageProcessing(result);\n#else\n#ifdef FROMLINEARSPACE\nresult=applyImageProcessing(result);\n#endif\n#endif\ngl_FragColor=result;}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1V] = shader$1V;\n\n /**\n * ImageProcessingPostProcess\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses#imageprocessing\n */\n class ImageProcessingPostProcess extends PostProcess {\n /**\n * Gets the image processing configuration used either in this material.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Sets the Default image processing configuration used either in the this material.\n *\n * If sets to null, the scene one is in use.\n */\n set imageProcessingConfiguration(value) {\n // We are almost sure it is applied by post process as\n // We are in the post process :-)\n value.applyByPostProcess = true;\n this._attachImageProcessingConfiguration(value);\n }\n /**\n * Attaches a new image processing configuration to the PBR Material.\n * @param configuration\n * @param doNotBuild\n */\n _attachImageProcessingConfiguration(configuration, doNotBuild = false) {\n if (configuration === this._imageProcessingConfiguration) {\n return;\n }\n // Detaches observer.\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n // Pick the scene configuration if needed.\n if (!configuration) {\n let scene = null;\n const engine = this.getEngine();\n const camera = this.getCamera();\n if (camera) {\n scene = camera.getScene();\n }\n else if (engine && engine.scenes) {\n const scenes = engine.scenes;\n scene = scenes[scenes.length - 1];\n }\n else {\n scene = EngineStore.LastCreatedScene;\n }\n if (scene) {\n this._imageProcessingConfiguration = scene.imageProcessingConfiguration;\n }\n else {\n this._imageProcessingConfiguration = new ImageProcessingConfiguration();\n }\n }\n else {\n this._imageProcessingConfiguration = configuration;\n }\n // Attaches observer.\n if (this._imageProcessingConfiguration) {\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\n this._updateParameters();\n });\n }\n // Ensure the effect will be rebuilt.\n if (!doNotBuild) {\n this._updateParameters();\n }\n }\n /**\n * If the post process is supported.\n */\n get isSupported() {\n const effect = this.getEffect();\n return !effect || effect.isSupported;\n }\n /**\n * Gets Color curves setup used in the effect if colorCurvesEnabled is set to true .\n */\n get colorCurves() {\n return this.imageProcessingConfiguration.colorCurves;\n }\n /**\n * Sets Color curves setup used in the effect if colorCurvesEnabled is set to true .\n */\n set colorCurves(value) {\n this.imageProcessingConfiguration.colorCurves = value;\n }\n /**\n * Gets whether the color curves effect is enabled.\n */\n get colorCurvesEnabled() {\n return this.imageProcessingConfiguration.colorCurvesEnabled;\n }\n /**\n * Sets whether the color curves effect is enabled.\n */\n set colorCurvesEnabled(value) {\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\n }\n /**\n * Gets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.\n */\n get colorGradingTexture() {\n return this.imageProcessingConfiguration.colorGradingTexture;\n }\n /**\n * Sets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.\n */\n set colorGradingTexture(value) {\n this.imageProcessingConfiguration.colorGradingTexture = value;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n get colorGradingEnabled() {\n return this.imageProcessingConfiguration.colorGradingEnabled;\n }\n /**\n * Gets whether the color grading effect is enabled.\n */\n set colorGradingEnabled(value) {\n this.imageProcessingConfiguration.colorGradingEnabled = value;\n }\n /**\n * Gets exposure used in the effect.\n */\n get exposure() {\n return this.imageProcessingConfiguration.exposure;\n }\n /**\n * Sets exposure used in the effect.\n */\n set exposure(value) {\n this.imageProcessingConfiguration.exposure = value;\n }\n /**\n * Gets whether tonemapping is enabled or not.\n */\n get toneMappingEnabled() {\n return this._imageProcessingConfiguration.toneMappingEnabled;\n }\n /**\n * Sets whether tonemapping is enabled or not\n */\n set toneMappingEnabled(value) {\n this._imageProcessingConfiguration.toneMappingEnabled = value;\n }\n /**\n * Gets the type of tone mapping effect.\n */\n get toneMappingType() {\n return this._imageProcessingConfiguration.toneMappingType;\n }\n /**\n * Sets the type of tone mapping effect.\n */\n set toneMappingType(value) {\n this._imageProcessingConfiguration.toneMappingType = value;\n }\n /**\n * Gets contrast used in the effect.\n */\n get contrast() {\n return this.imageProcessingConfiguration.contrast;\n }\n /**\n * Sets contrast used in the effect.\n */\n set contrast(value) {\n this.imageProcessingConfiguration.contrast = value;\n }\n /**\n * Gets Vignette stretch size.\n */\n get vignetteStretch() {\n return this.imageProcessingConfiguration.vignetteStretch;\n }\n /**\n * Sets Vignette stretch size.\n */\n set vignetteStretch(value) {\n this.imageProcessingConfiguration.vignetteStretch = value;\n }\n /**\n * Gets Vignette center X Offset.\n * @deprecated use vignetteCenterX instead\n */\n get vignetteCentreX() {\n return this.imageProcessingConfiguration.vignetteCenterX;\n }\n /**\n * Sets Vignette center X Offset.\n * @deprecated use vignetteCenterX instead\n */\n set vignetteCentreX(value) {\n this.imageProcessingConfiguration.vignetteCenterX = value;\n }\n /**\n * Gets Vignette center Y Offset.\n * @deprecated use vignetteCenterY instead\n */\n get vignetteCentreY() {\n return this.imageProcessingConfiguration.vignetteCenterY;\n }\n /**\n * Sets Vignette center Y Offset.\n * @deprecated use vignetteCenterY instead\n */\n set vignetteCentreY(value) {\n this.imageProcessingConfiguration.vignetteCenterY = value;\n }\n /**\n * Vignette center Y Offset.\n */\n get vignetteCenterY() {\n return this.imageProcessingConfiguration.vignetteCenterY;\n }\n set vignetteCenterY(value) {\n this.imageProcessingConfiguration.vignetteCenterY = value;\n }\n /**\n * Vignette center X Offset.\n */\n get vignetteCenterX() {\n return this.imageProcessingConfiguration.vignetteCenterX;\n }\n set vignetteCenterX(value) {\n this.imageProcessingConfiguration.vignetteCenterX = value;\n }\n /**\n * Gets Vignette weight or intensity of the vignette effect.\n */\n get vignetteWeight() {\n return this.imageProcessingConfiguration.vignetteWeight;\n }\n /**\n * Sets Vignette weight or intensity of the vignette effect.\n */\n set vignetteWeight(value) {\n this.imageProcessingConfiguration.vignetteWeight = value;\n }\n /**\n * Gets Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)\n * if vignetteEnabled is set to true.\n */\n get vignetteColor() {\n return this.imageProcessingConfiguration.vignetteColor;\n }\n /**\n * Sets Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)\n * if vignetteEnabled is set to true.\n */\n set vignetteColor(value) {\n this.imageProcessingConfiguration.vignetteColor = value;\n }\n /**\n * Gets Camera field of view used by the Vignette effect.\n */\n get vignetteCameraFov() {\n return this.imageProcessingConfiguration.vignetteCameraFov;\n }\n /**\n * Sets Camera field of view used by the Vignette effect.\n */\n set vignetteCameraFov(value) {\n this.imageProcessingConfiguration.vignetteCameraFov = value;\n }\n /**\n * Gets the vignette blend mode allowing different kind of effect.\n */\n get vignetteBlendMode() {\n return this.imageProcessingConfiguration.vignetteBlendMode;\n }\n /**\n * Sets the vignette blend mode allowing different kind of effect.\n */\n set vignetteBlendMode(value) {\n this.imageProcessingConfiguration.vignetteBlendMode = value;\n }\n /**\n * Gets whether the vignette effect is enabled.\n */\n get vignetteEnabled() {\n return this.imageProcessingConfiguration.vignetteEnabled;\n }\n /**\n * Sets whether the vignette effect is enabled.\n */\n set vignetteEnabled(value) {\n this.imageProcessingConfiguration.vignetteEnabled = value;\n }\n /**\n * Gets intensity of the dithering effect.\n */\n get ditheringIntensity() {\n return this.imageProcessingConfiguration.ditheringIntensity;\n }\n /**\n * Sets intensity of the dithering effect.\n */\n set ditheringIntensity(value) {\n this.imageProcessingConfiguration.ditheringIntensity = value;\n }\n /**\n * Gets whether the dithering effect is enabled.\n */\n get ditheringEnabled() {\n return this.imageProcessingConfiguration.ditheringEnabled;\n }\n /**\n * Sets whether the dithering effect is enabled.\n */\n set ditheringEnabled(value) {\n this.imageProcessingConfiguration.ditheringEnabled = value;\n }\n /**\n * Gets whether the input of the processing is in Gamma or Linear Space.\n */\n get fromLinearSpace() {\n return this._fromLinearSpace;\n }\n /**\n * Sets whether the input of the processing is in Gamma or Linear Space.\n */\n set fromLinearSpace(value) {\n if (this._fromLinearSpace === value) {\n return;\n }\n this._fromLinearSpace = value;\n this._updateParameters();\n }\n constructor(name, options, camera = null, samplingMode, engine, reusable, textureType = 0, imageProcessingConfiguration) {\n super(name, \"imageProcessing\", [], [], options, camera, samplingMode, engine, reusable, null, textureType, \"postprocess\", null, true);\n this._fromLinearSpace = true;\n /**\n * Defines cache preventing GC.\n */\n this._defines = {\n IMAGEPROCESSING: false,\n VIGNETTE: false,\n VIGNETTEBLENDMODEMULTIPLY: false,\n VIGNETTEBLENDMODEOPAQUE: false,\n TONEMAPPING: false,\n TONEMAPPING_ACES: false,\n CONTRAST: false,\n COLORCURVES: false,\n COLORGRADING: false,\n COLORGRADING3D: false,\n FROMLINEARSPACE: false,\n SAMPLER3DGREENDEPTH: false,\n SAMPLER3DBGRMAP: false,\n DITHER: false,\n IMAGEPROCESSINGPOSTPROCESS: false,\n EXPOSURE: false,\n SKIPFINALCOLORCLAMP: false,\n };\n // Setup the configuration as forced by the constructor. This would then not force the\n // scene materials output in linear space and let untouched the default forward pass.\n if (imageProcessingConfiguration) {\n imageProcessingConfiguration.applyByPostProcess = true;\n this._attachImageProcessingConfiguration(imageProcessingConfiguration, true);\n // This will cause the shader to be compiled\n this._updateParameters();\n }\n // Setup the default processing configuration to the scene.\n else {\n this._attachImageProcessingConfiguration(null, true);\n this.imageProcessingConfiguration.applyByPostProcess = true;\n }\n this.onApply = (effect) => {\n this.imageProcessingConfiguration.bind(effect, this.aspectRatio);\n };\n }\n /**\n * \"ImageProcessingPostProcess\"\n * @returns \"ImageProcessingPostProcess\"\n */\n getClassName() {\n return \"ImageProcessingPostProcess\";\n }\n /**\n * @internal\n */\n _updateParameters() {\n this._defines.FROMLINEARSPACE = this._fromLinearSpace;\n this.imageProcessingConfiguration.prepareDefines(this._defines, true);\n let defines = \"\";\n for (const define in this._defines) {\n if (this._defines[define]) {\n defines += `#define ${define};\\n`;\n }\n }\n const samplers = [\"textureSampler\"];\n const uniforms = [\"scale\"];\n if (ImageProcessingConfiguration) {\n ImageProcessingConfiguration.PrepareSamplers(samplers, this._defines);\n ImageProcessingConfiguration.PrepareUniforms(uniforms, this._defines);\n }\n this.updateEffect(defines, uniforms, samplers);\n }\n dispose(camera) {\n super.dispose(camera);\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n if (this._imageProcessingConfiguration) {\n this.imageProcessingConfiguration.applyByPostProcess = false;\n }\n }\n }\n __decorate$1([\n serialize()\n ], ImageProcessingPostProcess.prototype, \"_fromLinearSpace\", void 0);\n\n /**\n * Defines supported buttons for DualShock compatible gamepads\n */\n var DualShockButton;\n (function (DualShockButton) {\n /** Cross */\n DualShockButton[DualShockButton[\"Cross\"] = 0] = \"Cross\";\n /** Circle */\n DualShockButton[DualShockButton[\"Circle\"] = 1] = \"Circle\";\n /** Square */\n DualShockButton[DualShockButton[\"Square\"] = 2] = \"Square\";\n /** Triangle */\n DualShockButton[DualShockButton[\"Triangle\"] = 3] = \"Triangle\";\n /** L1 */\n DualShockButton[DualShockButton[\"L1\"] = 4] = \"L1\";\n /** R1 */\n DualShockButton[DualShockButton[\"R1\"] = 5] = \"R1\";\n /** Share */\n DualShockButton[DualShockButton[\"Share\"] = 8] = \"Share\";\n /** Options */\n DualShockButton[DualShockButton[\"Options\"] = 9] = \"Options\";\n /** Left stick */\n DualShockButton[DualShockButton[\"LeftStick\"] = 10] = \"LeftStick\";\n /** Right stick */\n DualShockButton[DualShockButton[\"RightStick\"] = 11] = \"RightStick\";\n })(DualShockButton || (DualShockButton = {}));\n /** Defines values for DualShock DPad */\n var DualShockDpad;\n (function (DualShockDpad) {\n /** Up */\n DualShockDpad[DualShockDpad[\"Up\"] = 12] = \"Up\";\n /** Down */\n DualShockDpad[DualShockDpad[\"Down\"] = 13] = \"Down\";\n /** Left */\n DualShockDpad[DualShockDpad[\"Left\"] = 14] = \"Left\";\n /** Right */\n DualShockDpad[DualShockDpad[\"Right\"] = 15] = \"Right\";\n })(DualShockDpad || (DualShockDpad = {}));\n /**\n * Defines a DualShock gamepad\n */\n class DualShockPad extends Gamepad {\n /**\n * Creates a new DualShock gamepad object\n * @param id defines the id of this gamepad\n * @param index defines its index\n * @param gamepad defines the internal HTML gamepad object\n */\n constructor(id, index, gamepad) {\n super(id.replace(\"STANDARD GAMEPAD\", \"SONY PLAYSTATION DUALSHOCK\"), index, gamepad, 0, 1, 2, 3);\n this._leftTrigger = 0;\n this._rightTrigger = 0;\n /** Observable raised when a button is pressed */\n this.onButtonDownObservable = new Observable$1();\n /** Observable raised when a button is released */\n this.onButtonUpObservable = new Observable$1();\n /** Observable raised when a pad is pressed */\n this.onPadDownObservable = new Observable$1();\n /** Observable raised when a pad is released */\n this.onPadUpObservable = new Observable$1();\n this._buttonCross = 0;\n this._buttonCircle = 0;\n this._buttonSquare = 0;\n this._buttonTriangle = 0;\n this._buttonShare = 0;\n this._buttonOptions = 0;\n this._buttonL1 = 0;\n this._buttonR1 = 0;\n this._buttonLeftStick = 0;\n this._buttonRightStick = 0;\n this._dPadUp = 0;\n this._dPadDown = 0;\n this._dPadLeft = 0;\n this._dPadRight = 0;\n this.type = Gamepad.DUALSHOCK;\n }\n /**\n * Defines the callback to call when left trigger is pressed\n * @param callback defines the callback to use\n */\n onlefttriggerchanged(callback) {\n this._onlefttriggerchanged = callback;\n }\n /**\n * Defines the callback to call when right trigger is pressed\n * @param callback defines the callback to use\n */\n onrighttriggerchanged(callback) {\n this._onrighttriggerchanged = callback;\n }\n /**\n * Gets the left trigger value\n */\n get leftTrigger() {\n return this._leftTrigger;\n }\n /**\n * Sets the left trigger value\n */\n set leftTrigger(newValue) {\n if (this._onlefttriggerchanged && this._leftTrigger !== newValue) {\n this._onlefttriggerchanged(newValue);\n }\n this._leftTrigger = newValue;\n }\n /**\n * Gets the right trigger value\n */\n get rightTrigger() {\n return this._rightTrigger;\n }\n /**\n * Sets the right trigger value\n */\n set rightTrigger(newValue) {\n if (this._onrighttriggerchanged && this._rightTrigger !== newValue) {\n this._onrighttriggerchanged(newValue);\n }\n this._rightTrigger = newValue;\n }\n /**\n * Defines the callback to call when a button is pressed\n * @param callback defines the callback to use\n */\n onbuttondown(callback) {\n this._onbuttondown = callback;\n }\n /**\n * Defines the callback to call when a button is released\n * @param callback defines the callback to use\n */\n onbuttonup(callback) {\n this._onbuttonup = callback;\n }\n /**\n * Defines the callback to call when a pad is pressed\n * @param callback defines the callback to use\n */\n ondpaddown(callback) {\n this._ondpaddown = callback;\n }\n /**\n * Defines the callback to call when a pad is released\n * @param callback defines the callback to use\n */\n ondpadup(callback) {\n this._ondpadup = callback;\n }\n _setButtonValue(newValue, currentValue, buttonType) {\n if (newValue !== currentValue) {\n if (newValue === 1) {\n if (this._onbuttondown) {\n this._onbuttondown(buttonType);\n }\n this.onButtonDownObservable.notifyObservers(buttonType);\n }\n if (newValue === 0) {\n if (this._onbuttonup) {\n this._onbuttonup(buttonType);\n }\n this.onButtonUpObservable.notifyObservers(buttonType);\n }\n }\n return newValue;\n }\n _setDPadValue(newValue, currentValue, buttonType) {\n if (newValue !== currentValue) {\n if (newValue === 1) {\n if (this._ondpaddown) {\n this._ondpaddown(buttonType);\n }\n this.onPadDownObservable.notifyObservers(buttonType);\n }\n if (newValue === 0) {\n if (this._ondpadup) {\n this._ondpadup(buttonType);\n }\n this.onPadUpObservable.notifyObservers(buttonType);\n }\n }\n return newValue;\n }\n /**\n * Gets the value of the `Cross` button\n */\n get buttonCross() {\n return this._buttonCross;\n }\n /**\n * Sets the value of the `Cross` button\n */\n set buttonCross(value) {\n this._buttonCross = this._setButtonValue(value, this._buttonCross, DualShockButton.Cross);\n }\n /**\n * Gets the value of the `Circle` button\n */\n get buttonCircle() {\n return this._buttonCircle;\n }\n /**\n * Sets the value of the `Circle` button\n */\n set buttonCircle(value) {\n this._buttonCircle = this._setButtonValue(value, this._buttonCircle, DualShockButton.Circle);\n }\n /**\n * Gets the value of the `Square` button\n */\n get buttonSquare() {\n return this._buttonSquare;\n }\n /**\n * Sets the value of the `Square` button\n */\n set buttonSquare(value) {\n this._buttonSquare = this._setButtonValue(value, this._buttonSquare, DualShockButton.Square);\n }\n /**\n * Gets the value of the `Triangle` button\n */\n get buttonTriangle() {\n return this._buttonTriangle;\n }\n /**\n * Sets the value of the `Triangle` button\n */\n set buttonTriangle(value) {\n this._buttonTriangle = this._setButtonValue(value, this._buttonTriangle, DualShockButton.Triangle);\n }\n /**\n * Gets the value of the `Options` button\n */\n get buttonOptions() {\n return this._buttonOptions;\n }\n /**\n * Sets the value of the `Options` button\n */\n set buttonOptions(value) {\n this._buttonOptions = this._setButtonValue(value, this._buttonOptions, DualShockButton.Options);\n }\n /**\n * Gets the value of the `Share` button\n */\n get buttonShare() {\n return this._buttonShare;\n }\n /**\n * Sets the value of the `Share` button\n */\n set buttonShare(value) {\n this._buttonShare = this._setButtonValue(value, this._buttonShare, DualShockButton.Share);\n }\n /**\n * Gets the value of the `L1` button\n */\n get buttonL1() {\n return this._buttonL1;\n }\n /**\n * Sets the value of the `L1` button\n */\n set buttonL1(value) {\n this._buttonL1 = this._setButtonValue(value, this._buttonL1, DualShockButton.L1);\n }\n /**\n * Gets the value of the `R1` button\n */\n get buttonR1() {\n return this._buttonR1;\n }\n /**\n * Sets the value of the `R1` button\n */\n set buttonR1(value) {\n this._buttonR1 = this._setButtonValue(value, this._buttonR1, DualShockButton.R1);\n }\n /**\n * Gets the value of the Left joystick\n */\n get buttonLeftStick() {\n return this._buttonLeftStick;\n }\n /**\n * Sets the value of the Left joystick\n */\n set buttonLeftStick(value) {\n this._buttonLeftStick = this._setButtonValue(value, this._buttonLeftStick, DualShockButton.LeftStick);\n }\n /**\n * Gets the value of the Right joystick\n */\n get buttonRightStick() {\n return this._buttonRightStick;\n }\n /**\n * Sets the value of the Right joystick\n */\n set buttonRightStick(value) {\n this._buttonRightStick = this._setButtonValue(value, this._buttonRightStick, DualShockButton.RightStick);\n }\n /**\n * Gets the value of D-pad up\n */\n get dPadUp() {\n return this._dPadUp;\n }\n /**\n * Sets the value of D-pad up\n */\n set dPadUp(value) {\n this._dPadUp = this._setDPadValue(value, this._dPadUp, DualShockDpad.Up);\n }\n /**\n * Gets the value of D-pad down\n */\n get dPadDown() {\n return this._dPadDown;\n }\n /**\n * Sets the value of D-pad down\n */\n set dPadDown(value) {\n this._dPadDown = this._setDPadValue(value, this._dPadDown, DualShockDpad.Down);\n }\n /**\n * Gets the value of D-pad left\n */\n get dPadLeft() {\n return this._dPadLeft;\n }\n /**\n * Sets the value of D-pad left\n */\n set dPadLeft(value) {\n this._dPadLeft = this._setDPadValue(value, this._dPadLeft, DualShockDpad.Left);\n }\n /**\n * Gets the value of D-pad right\n */\n get dPadRight() {\n return this._dPadRight;\n }\n /**\n * Sets the value of D-pad right\n */\n set dPadRight(value) {\n this._dPadRight = this._setDPadValue(value, this._dPadRight, DualShockDpad.Right);\n }\n /**\n * Force the gamepad to synchronize with device values\n */\n update() {\n super.update();\n this.buttonCross = this.browserGamepad.buttons[0].value;\n this.buttonCircle = this.browserGamepad.buttons[1].value;\n this.buttonSquare = this.browserGamepad.buttons[2].value;\n this.buttonTriangle = this.browserGamepad.buttons[3].value;\n this.buttonL1 = this.browserGamepad.buttons[4].value;\n this.buttonR1 = this.browserGamepad.buttons[5].value;\n this.leftTrigger = this.browserGamepad.buttons[6].value;\n this.rightTrigger = this.browserGamepad.buttons[7].value;\n this.buttonShare = this.browserGamepad.buttons[8].value;\n this.buttonOptions = this.browserGamepad.buttons[9].value;\n this.buttonLeftStick = this.browserGamepad.buttons[10].value;\n this.buttonRightStick = this.browserGamepad.buttons[11].value;\n this.dPadUp = this.browserGamepad.buttons[12].value;\n this.dPadDown = this.browserGamepad.buttons[13].value;\n this.dPadLeft = this.browserGamepad.buttons[14].value;\n this.dPadRight = this.browserGamepad.buttons[15].value;\n }\n /**\n * Disposes the gamepad\n */\n dispose() {\n super.dispose();\n this.onButtonDownObservable.clear();\n this.onButtonUpObservable.clear();\n this.onPadDownObservable.clear();\n this.onPadUpObservable.clear();\n }\n }\n\n /**\n * Manager for handling gamepads\n */\n class GamepadManager {\n /**\n * Initializes the gamepad manager\n * @param _scene BabylonJS scene\n */\n constructor(_scene) {\n this._scene = _scene;\n this._babylonGamepads = [];\n this._oneGamepadConnected = false;\n /** @internal */\n this._isMonitoring = false;\n /**\n * observable to be triggered when the gamepad controller has been disconnected\n */\n this.onGamepadDisconnectedObservable = new Observable$1();\n if (!IsWindowObjectExist()) {\n this._gamepadEventSupported = false;\n }\n else {\n this._gamepadEventSupported = \"GamepadEvent\" in window;\n this._gamepadSupport = navigator && navigator.getGamepads;\n }\n this.onGamepadConnectedObservable = new Observable$1((observer) => {\n // This will be used to raise the onGamepadConnected for all gamepads ALREADY connected\n for (const i in this._babylonGamepads) {\n const gamepad = this._babylonGamepads[i];\n if (gamepad && gamepad._isConnected) {\n this.onGamepadConnectedObservable.notifyObserver(observer, gamepad);\n }\n }\n });\n this._onGamepadConnectedEvent = (evt) => {\n const gamepad = evt.gamepad;\n if (gamepad.index in this._babylonGamepads) {\n if (this._babylonGamepads[gamepad.index].isConnected) {\n return;\n }\n }\n let newGamepad;\n if (this._babylonGamepads[gamepad.index]) {\n newGamepad = this._babylonGamepads[gamepad.index];\n newGamepad.browserGamepad = gamepad;\n newGamepad._isConnected = true;\n }\n else {\n newGamepad = this._addNewGamepad(gamepad);\n }\n this.onGamepadConnectedObservable.notifyObservers(newGamepad);\n this._startMonitoringGamepads();\n };\n this._onGamepadDisconnectedEvent = (evt) => {\n const gamepad = evt.gamepad;\n // Remove the gamepad from the list of gamepads to monitor.\n for (const i in this._babylonGamepads) {\n if (this._babylonGamepads[i].index === gamepad.index) {\n const disconnectedGamepad = this._babylonGamepads[i];\n disconnectedGamepad._isConnected = false;\n this.onGamepadDisconnectedObservable.notifyObservers(disconnectedGamepad);\n disconnectedGamepad.dispose && disconnectedGamepad.dispose();\n break;\n }\n }\n };\n if (this._gamepadSupport) {\n //first add already-connected gamepads\n this._updateGamepadObjects();\n if (this._babylonGamepads.length) {\n this._startMonitoringGamepads();\n }\n // Checking if the gamepad connected event is supported (like in Firefox)\n if (this._gamepadEventSupported) {\n const hostWindow = this._scene ? this._scene.getEngine().getHostWindow() : window;\n if (hostWindow) {\n hostWindow.addEventListener(\"gamepadconnected\", this._onGamepadConnectedEvent, false);\n hostWindow.addEventListener(\"gamepaddisconnected\", this._onGamepadDisconnectedEvent, false);\n }\n }\n else {\n this._startMonitoringGamepads();\n }\n }\n }\n /**\n * The gamepads in the game pad manager\n */\n get gamepads() {\n return this._babylonGamepads;\n }\n /**\n * Get the gamepad controllers based on type\n * @param type The type of gamepad controller\n * @returns Nullable gamepad\n */\n getGamepadByType(type = Gamepad.XBOX) {\n for (const gamepad of this._babylonGamepads) {\n if (gamepad && gamepad.type === type) {\n return gamepad;\n }\n }\n return null;\n }\n /**\n * Disposes the gamepad manager\n */\n dispose() {\n if (this._gamepadEventSupported) {\n if (this._onGamepadConnectedEvent) {\n window.removeEventListener(\"gamepadconnected\", this._onGamepadConnectedEvent);\n }\n if (this._onGamepadDisconnectedEvent) {\n window.removeEventListener(\"gamepaddisconnected\", this._onGamepadDisconnectedEvent);\n }\n this._onGamepadConnectedEvent = null;\n this._onGamepadDisconnectedEvent = null;\n }\n this._babylonGamepads.forEach((gamepad) => {\n gamepad.dispose();\n });\n this.onGamepadConnectedObservable.clear();\n this.onGamepadDisconnectedObservable.clear();\n this._oneGamepadConnected = false;\n this._stopMonitoringGamepads();\n this._babylonGamepads = [];\n }\n _addNewGamepad(gamepad) {\n if (!this._oneGamepadConnected) {\n this._oneGamepadConnected = true;\n }\n let newGamepad;\n const dualShock = gamepad.id.search(\"054c\") !== -1 && gamepad.id.search(\"0ce6\") === -1;\n const xboxOne = gamepad.id.search(\"Xbox One\") !== -1;\n if (xboxOne ||\n gamepad.id.search(\"Xbox 360\") !== -1 ||\n gamepad.id.search(\"xinput\") !== -1 ||\n (gamepad.id.search(\"045e\") !== -1 && gamepad.id.search(\"Surface Dock\") === -1)) {\n // make sure the Surface Dock Extender is not detected as an xbox controller\n newGamepad = new Xbox360Pad(gamepad.id, gamepad.index, gamepad, xboxOne);\n }\n else if (dualShock) {\n newGamepad = new DualShockPad(gamepad.id, gamepad.index, gamepad);\n }\n // if pose is supported, use the (WebVR) pose enabled controller\n else if (gamepad.pose) {\n newGamepad = PoseEnabledControllerHelper.InitiateController(gamepad);\n }\n else {\n newGamepad = new GenericPad(gamepad.id, gamepad.index, gamepad);\n }\n this._babylonGamepads[newGamepad.index] = newGamepad;\n return newGamepad;\n }\n _startMonitoringGamepads() {\n if (!this._isMonitoring) {\n this._isMonitoring = true;\n //back-comp\n this._checkGamepadsStatus();\n }\n }\n _stopMonitoringGamepads() {\n this._isMonitoring = false;\n }\n /** @internal */\n _checkGamepadsStatus() {\n // Hack to be compatible Chrome\n this._updateGamepadObjects();\n for (const i in this._babylonGamepads) {\n const gamepad = this._babylonGamepads[i];\n if (!gamepad || !gamepad.isConnected) {\n continue;\n }\n try {\n gamepad.update();\n }\n catch (_a) {\n if (this._loggedErrors.indexOf(gamepad.index) === -1) {\n Tools.Warn(`Error updating gamepad ${gamepad.id}`);\n this._loggedErrors.push(gamepad.index);\n }\n }\n }\n if (this._isMonitoring) {\n Engine.QueueNewFrame(() => {\n this._checkGamepadsStatus();\n });\n }\n }\n // This function is called only on Chrome, which does not properly support\n // connection/disconnection events and forces you to recopy again the gamepad object\n _updateGamepadObjects() {\n const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];\n for (let i = 0; i < gamepads.length; i++) {\n const gamepad = gamepads[i];\n if (gamepad) {\n if (!this._babylonGamepads[gamepad.index]) {\n const newGamepad = this._addNewGamepad(gamepad);\n this.onGamepadConnectedObservable.notifyObservers(newGamepad);\n }\n else {\n // Forced to copy again this object for Chrome for unknown reason\n this._babylonGamepads[i].browserGamepad = gamepad;\n if (!this._babylonGamepads[i].isConnected) {\n this._babylonGamepads[i]._isConnected = true;\n this.onGamepadConnectedObservable.notifyObservers(this._babylonGamepads[i]);\n }\n }\n }\n }\n }\n }\n\n /**\n * Manage the gamepad inputs to control a free camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class FreeCameraGamepadInput {\n constructor() {\n /**\n * Defines the gamepad rotation sensibility.\n * This is the threshold from when rotation starts to be accounted for to prevent jittering.\n */\n this.gamepadAngularSensibility = 200;\n /**\n * Defines the gamepad move sensibility.\n * This is the threshold from when moving starts to be accounted for for to prevent jittering.\n */\n this.gamepadMoveSensibility = 40;\n /**\n * Defines the minimum value at which any analog stick input is ignored.\n * Note: This value should only be a value between 0 and 1.\n */\n this.deadzoneDelta = 0.1;\n this._yAxisScale = 1.0;\n this._cameraTransform = Matrix.Identity();\n this._deltaTransform = Vector3.Zero();\n this._vector3 = Vector3.Zero();\n this._vector2 = Vector2.Zero();\n }\n /**\n * Gets or sets a boolean indicating that Yaxis (for right stick) should be inverted\n */\n get invertYAxis() {\n return this._yAxisScale !== 1.0;\n }\n set invertYAxis(value) {\n this._yAxisScale = value ? -1.0 : 1.0;\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n */\n attachControl() {\n const manager = this.camera.getScene().gamepadManager;\n this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {\n if (gamepad.type !== Gamepad.POSE_ENABLED) {\n // prioritize XBOX gamepads.\n if (!this.gamepad || gamepad.type === Gamepad.XBOX) {\n this.gamepad = gamepad;\n }\n }\n });\n this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add((gamepad) => {\n if (this.gamepad === gamepad) {\n this.gamepad = null;\n }\n });\n // check if there are already other controllers connected\n this.gamepad = manager.getGamepadByType(Gamepad.XBOX);\n // if no xbox controller was found, but there are gamepad controllers, take the first one\n if (!this.gamepad && manager.gamepads.length) {\n this.gamepad = manager.gamepads[0];\n }\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);\n this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);\n this.gamepad = null;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this.gamepad && this.gamepad.leftStick) {\n const camera = this.camera;\n const lsValues = this.gamepad.leftStick;\n if (this.gamepadMoveSensibility !== 0) {\n lsValues.x = Math.abs(lsValues.x) > this.deadzoneDelta ? lsValues.x / this.gamepadMoveSensibility : 0;\n lsValues.y = Math.abs(lsValues.y) > this.deadzoneDelta ? lsValues.y / this.gamepadMoveSensibility : 0;\n }\n let rsValues = this.gamepad.rightStick;\n if (rsValues && this.gamepadAngularSensibility !== 0) {\n rsValues.x = Math.abs(rsValues.x) > this.deadzoneDelta ? rsValues.x / this.gamepadAngularSensibility : 0;\n rsValues.y = (Math.abs(rsValues.y) > this.deadzoneDelta ? rsValues.y / this.gamepadAngularSensibility : 0) * this._yAxisScale;\n }\n else {\n rsValues = { x: 0, y: 0 };\n }\n if (!camera.rotationQuaternion) {\n Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, this._cameraTransform);\n }\n else {\n camera.rotationQuaternion.toRotationMatrix(this._cameraTransform);\n }\n const speed = camera._computeLocalCameraSpeed() * 50.0;\n this._vector3.copyFromFloats(lsValues.x * speed, 0, -lsValues.y * speed);\n Vector3.TransformCoordinatesToRef(this._vector3, this._cameraTransform, this._deltaTransform);\n camera.cameraDirection.addInPlace(this._deltaTransform);\n this._vector2.copyFromFloats(rsValues.y, rsValues.x);\n camera.cameraRotation.addInPlace(this._vector2);\n }\n }\n /**\n * Gets the class name of the current input.\n * @returns the class name\n */\n getClassName() {\n return \"FreeCameraGamepadInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"gamepad\";\n }\n }\n __decorate$1([\n serialize()\n ], FreeCameraGamepadInput.prototype, \"gamepadAngularSensibility\", void 0);\n __decorate$1([\n serialize()\n ], FreeCameraGamepadInput.prototype, \"gamepadMoveSensibility\", void 0);\n CameraInputTypes[\"FreeCameraGamepadInput\"] = FreeCameraGamepadInput;\n\n /**\n * Manage the gamepad inputs to control an arc rotate camera.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\n */\n class ArcRotateCameraGamepadInput {\n constructor() {\n /**\n * Defines the gamepad rotation sensibility.\n * This is the threshold from when rotation starts to be accounted for to prevent jittering.\n */\n this.gamepadRotationSensibility = 80;\n /**\n * Defines the gamepad move sensibility.\n * This is the threshold from when moving starts to be accounted for for to prevent jittering.\n */\n this.gamepadMoveSensibility = 40;\n this._yAxisScale = 1.0;\n }\n /**\n * Gets or sets a boolean indicating that Yaxis (for right stick) should be inverted\n */\n get invertYAxis() {\n return this._yAxisScale !== 1.0;\n }\n set invertYAxis(value) {\n this._yAxisScale = value ? -1.0 : 1.0;\n }\n /**\n * Attach the input controls to a specific dom element to get the input from.\n */\n attachControl() {\n const manager = this.camera.getScene().gamepadManager;\n this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {\n if (gamepad.type !== Gamepad.POSE_ENABLED) {\n // prioritize XBOX gamepads.\n if (!this.gamepad || gamepad.type === Gamepad.XBOX) {\n this.gamepad = gamepad;\n }\n }\n });\n this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add((gamepad) => {\n if (this.gamepad === gamepad) {\n this.gamepad = null;\n }\n });\n this.gamepad = manager.getGamepadByType(Gamepad.XBOX);\n }\n /**\n * Detach the current controls from the specified dom element.\n */\n detachControl() {\n this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);\n this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);\n this.gamepad = null;\n }\n /**\n * Update the current camera state depending on the inputs that have been used this frame.\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\n */\n checkInputs() {\n if (this.gamepad) {\n const camera = this.camera;\n const rsValues = this.gamepad.rightStick;\n if (rsValues) {\n if (rsValues.x != 0) {\n const normalizedRX = rsValues.x / this.gamepadRotationSensibility;\n if (normalizedRX != 0 && Math.abs(normalizedRX) > 0.005) {\n camera.inertialAlphaOffset += normalizedRX;\n }\n }\n if (rsValues.y != 0) {\n const normalizedRY = (rsValues.y / this.gamepadRotationSensibility) * this._yAxisScale;\n if (normalizedRY != 0 && Math.abs(normalizedRY) > 0.005) {\n camera.inertialBetaOffset += normalizedRY;\n }\n }\n }\n const lsValues = this.gamepad.leftStick;\n if (lsValues && lsValues.y != 0) {\n const normalizedLY = lsValues.y / this.gamepadMoveSensibility;\n if (normalizedLY != 0 && Math.abs(normalizedLY) > 0.005) {\n this.camera.inertialRadiusOffset -= normalizedLY;\n }\n }\n }\n }\n /**\n * Gets the class name of the current intput.\n * @returns the class name\n */\n getClassName() {\n return \"ArcRotateCameraGamepadInput\";\n }\n /**\n * Get the friendly name associated with the input class.\n * @returns the input friendly name\n */\n getSimpleName() {\n return \"gamepad\";\n }\n }\n __decorate$1([\n serialize()\n ], ArcRotateCameraGamepadInput.prototype, \"gamepadRotationSensibility\", void 0);\n __decorate$1([\n serialize()\n ], ArcRotateCameraGamepadInput.prototype, \"gamepadMoveSensibility\", void 0);\n CameraInputTypes[\"ArcRotateCameraGamepadInput\"] = ArcRotateCameraGamepadInput;\n\n Object.defineProperty(Scene.prototype, \"gamepadManager\", {\n get: function () {\n if (!this._gamepadManager) {\n this._gamepadManager = new GamepadManager(this);\n let component = this._getComponent(SceneComponentConstants.NAME_GAMEPAD);\n if (!component) {\n component = new GamepadSystemSceneComponent(this);\n this._addComponent(component);\n }\n }\n return this._gamepadManager;\n },\n enumerable: true,\n configurable: true,\n });\n /**\n * Adds a gamepad to the free camera inputs manager\n */\n FreeCameraInputsManager.prototype.addGamepad = function () {\n this.add(new FreeCameraGamepadInput());\n return this;\n };\n /**\n * Adds a gamepad to the arc rotate camera inputs manager\n */\n ArcRotateCameraInputsManager.prototype.addGamepad = function () {\n this.add(new ArcRotateCameraGamepadInput());\n return this;\n };\n /**\n * Defines the gamepad scene component responsible to manage gamepads in a given scene\n */\n class GamepadSystemSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpfull to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_GAMEPAD;\n this.scene = scene;\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._beforeCameraUpdateStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERAUPDATE_GAMEPAD, this, this._beforeCameraUpdate);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do for gamepads\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n const gamepadManager = this.scene._gamepadManager;\n if (gamepadManager) {\n gamepadManager.dispose();\n this.scene._gamepadManager = null;\n }\n }\n _beforeCameraUpdate() {\n const gamepadManager = this.scene._gamepadManager;\n if (gamepadManager && gamepadManager._isMonitoring) {\n gamepadManager._checkGamepadsStatus();\n }\n }\n }\n\n // Static values to help the garbage collector\n // Quaternion\n const _staticOffsetValueQuaternion = Object.freeze(new Quaternion(0, 0, 0, 0));\n // Vector3\n const _staticOffsetValueVector3 = Object.freeze(Vector3.Zero());\n // Vector2\n const _staticOffsetValueVector2 = Object.freeze(Vector2.Zero());\n // Size\n const _staticOffsetValueSize = Object.freeze(Size.Zero());\n // Color3\n const _staticOffsetValueColor3 = Object.freeze(Color3.Black());\n /**\n * Defines a runtime animation\n */\n class RuntimeAnimation {\n /**\n * Gets the current frame of the runtime animation\n */\n get currentFrame() {\n return this._currentFrame;\n }\n /**\n * Gets the weight of the runtime animation\n */\n get weight() {\n return this._weight;\n }\n /**\n * Gets the current value of the runtime animation\n */\n get currentValue() {\n return this._currentValue;\n }\n /**\n * Gets or sets the target path of the runtime animation\n */\n get targetPath() {\n return this._targetPath;\n }\n /**\n * Gets the actual target of the runtime animation\n */\n get target() {\n return this._currentActiveTarget;\n }\n /**\n * Gets the additive state of the runtime animation\n */\n get isAdditive() {\n return this._host && this._host.isAdditive;\n }\n /**\n * Create a new RuntimeAnimation object\n * @param target defines the target of the animation\n * @param animation defines the source animation object\n * @param scene defines the hosting scene\n * @param host defines the initiating Animatable\n */\n constructor(target, animation, scene, host) {\n this._events = new Array();\n /**\n * The current frame of the runtime animation\n */\n this._currentFrame = 0;\n /**\n * The original value of the runtime animation\n */\n this._originalValue = new Array();\n /**\n * The original blend value of the runtime animation\n */\n this._originalBlendValue = null;\n /**\n * The offsets cache of the runtime animation\n */\n this._offsetsCache = {};\n /**\n * The high limits cache of the runtime animation\n */\n this._highLimitsCache = {};\n /**\n * Specifies if the runtime animation has been stopped\n */\n this._stopped = false;\n /**\n * The blending factor of the runtime animation\n */\n this._blendingFactor = 0;\n /**\n * The current value of the runtime animation\n */\n this._currentValue = null;\n this._currentActiveTarget = null;\n this._directTarget = null;\n /**\n * The target path of the runtime animation\n */\n this._targetPath = \"\";\n /**\n * The weight of the runtime animation\n */\n this._weight = 1.0;\n /**\n * The absolute frame offset of the runtime animation\n */\n this._absoluteFrameOffset = 0;\n /**\n * The previous elapsed time (since start of animation) of the runtime animation\n */\n this._previousElapsedTime = 0;\n /**\n * The previous absolute frame of the runtime animation (meaning, without taking into account the from/to values, only the elapsed time and the fps)\n */\n this._previousAbsoluteFrame = 0;\n this._targetIsArray = false;\n this._animation = animation;\n this._target = target;\n this._scene = scene;\n this._host = host;\n this._activeTargets = [];\n animation._runtimeAnimations.push(this);\n // State\n this._animationState = {\n key: 0,\n repeatCount: 0,\n loopMode: this._getCorrectLoopMode(),\n };\n if (this._animation.dataType === Animation.ANIMATIONTYPE_MATRIX) {\n this._animationState.workValue = Matrix.Zero();\n }\n // Limits\n this._keys = this._animation.getKeys();\n this._minFrame = this._keys[0].frame;\n this._maxFrame = this._keys[this._keys.length - 1].frame;\n this._minValue = this._keys[0].value;\n this._maxValue = this._keys[this._keys.length - 1].value;\n // Add a start key at frame 0 if missing\n if (this._minFrame !== 0) {\n const newKey = { frame: 0, value: this._minValue };\n this._keys.splice(0, 0, newKey);\n }\n // Check data\n if (this._target instanceof Array) {\n let index = 0;\n for (const target of this._target) {\n this._preparePath(target, index);\n this._getOriginalValues(index);\n index++;\n }\n this._targetIsArray = true;\n }\n else {\n this._preparePath(this._target);\n this._getOriginalValues();\n this._targetIsArray = false;\n this._directTarget = this._activeTargets[0];\n }\n // Cloning events locally\n const events = animation.getEvents();\n if (events && events.length > 0) {\n events.forEach((e) => {\n this._events.push(e._clone());\n });\n }\n this._enableBlending = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.enableBlending : this._animation.enableBlending;\n }\n _preparePath(target, targetIndex = 0) {\n const targetPropertyPath = this._animation.targetPropertyPath;\n if (targetPropertyPath.length > 1) {\n let property = target[targetPropertyPath[0]];\n for (let index = 1; index < targetPropertyPath.length - 1; index++) {\n property = property[targetPropertyPath[index]];\n }\n this._targetPath = targetPropertyPath[targetPropertyPath.length - 1];\n this._activeTargets[targetIndex] = property;\n }\n else {\n this._targetPath = targetPropertyPath[0];\n this._activeTargets[targetIndex] = target;\n }\n }\n /**\n * Gets the animation from the runtime animation\n */\n get animation() {\n return this._animation;\n }\n /**\n * Resets the runtime animation to the beginning\n * @param restoreOriginal defines whether to restore the target property to the original value\n */\n reset(restoreOriginal = false) {\n if (restoreOriginal) {\n if (this._target instanceof Array) {\n let index = 0;\n for (const target of this._target) {\n if (this._originalValue[index] !== undefined) {\n this._setValue(target, this._activeTargets[index], this._originalValue[index], -1, index);\n }\n index++;\n }\n }\n else {\n if (this._originalValue[0] !== undefined) {\n this._setValue(this._target, this._directTarget, this._originalValue[0], -1, 0);\n }\n }\n }\n this._offsetsCache = {};\n this._highLimitsCache = {};\n this._currentFrame = 0;\n this._blendingFactor = 0;\n // Events\n for (let index = 0; index < this._events.length; index++) {\n this._events[index].isDone = false;\n }\n }\n /**\n * Specifies if the runtime animation is stopped\n * @returns Boolean specifying if the runtime animation is stopped\n */\n isStopped() {\n return this._stopped;\n }\n /**\n * Disposes of the runtime animation\n */\n dispose() {\n const index = this._animation.runtimeAnimations.indexOf(this);\n if (index > -1) {\n this._animation.runtimeAnimations.splice(index, 1);\n }\n }\n /**\n * Apply the interpolated value to the target\n * @param currentValue defines the value computed by the animation\n * @param weight defines the weight to apply to this value (Defaults to 1.0)\n */\n setValue(currentValue, weight) {\n if (this._targetIsArray) {\n for (let index = 0; index < this._target.length; index++) {\n const target = this._target[index];\n this._setValue(target, this._activeTargets[index], currentValue, weight, index);\n }\n return;\n }\n this._setValue(this._target, this._directTarget, currentValue, weight, 0);\n }\n _getOriginalValues(targetIndex = 0) {\n let originalValue;\n const target = this._activeTargets[targetIndex];\n if (target.getRestPose && this._targetPath === \"_matrix\") {\n // For bones\n originalValue = target.getRestPose();\n }\n else {\n originalValue = target[this._targetPath];\n }\n if (originalValue && originalValue.clone) {\n this._originalValue[targetIndex] = originalValue.clone();\n }\n else {\n this._originalValue[targetIndex] = originalValue;\n }\n }\n _setValue(target, destination, currentValue, weight, targetIndex) {\n // Set value\n this._currentActiveTarget = destination;\n this._weight = weight;\n if (this._enableBlending && this._blendingFactor <= 1.0) {\n if (!this._originalBlendValue) {\n const originalValue = destination[this._targetPath];\n if (originalValue.clone) {\n this._originalBlendValue = originalValue.clone();\n }\n else {\n this._originalBlendValue = originalValue;\n }\n }\n if (this._originalBlendValue.m) {\n // Matrix\n if (Animation.AllowMatrixDecomposeForInterpolation) {\n if (this._currentValue) {\n Matrix.DecomposeLerpToRef(this._originalBlendValue, currentValue, this._blendingFactor, this._currentValue);\n }\n else {\n this._currentValue = Matrix.DecomposeLerp(this._originalBlendValue, currentValue, this._blendingFactor);\n }\n }\n else {\n if (this._currentValue) {\n Matrix.LerpToRef(this._originalBlendValue, currentValue, this._blendingFactor, this._currentValue);\n }\n else {\n this._currentValue = Matrix.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);\n }\n }\n }\n else {\n this._currentValue = Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);\n }\n const blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;\n this._blendingFactor += blendingSpeed;\n }\n else {\n if (!this._currentValue) {\n if (currentValue === null || currentValue === void 0 ? void 0 : currentValue.clone) {\n this._currentValue = currentValue.clone();\n }\n else {\n this._currentValue = currentValue;\n }\n }\n else if (this._currentValue.copyFrom) {\n this._currentValue.copyFrom(currentValue);\n }\n else {\n this._currentValue = currentValue;\n }\n }\n if (weight !== -1.0) {\n this._scene._registerTargetForLateAnimationBinding(this, this._originalValue[targetIndex]);\n }\n else {\n destination[this._targetPath] = this._currentValue;\n }\n if (target.markAsDirty) {\n target.markAsDirty(this._animation.targetProperty);\n }\n }\n /**\n * Gets the loop pmode of the runtime animation\n * @returns Loop Mode\n */\n _getCorrectLoopMode() {\n if (this._target && this._target.animationPropertiesOverride) {\n return this._target.animationPropertiesOverride.loopMode;\n }\n return this._animation.loopMode;\n }\n /**\n * Move the current animation to a given frame\n * @param frame defines the frame to move to\n */\n goToFrame(frame) {\n const keys = this._animation.getKeys();\n if (frame < keys[0].frame) {\n frame = keys[0].frame;\n }\n else if (frame > keys[keys.length - 1].frame) {\n frame = keys[keys.length - 1].frame;\n }\n // Need to reset animation events\n const events = this._events;\n if (events.length) {\n for (let index = 0; index < events.length; index++) {\n if (!events[index].onlyOnce) {\n // reset events in the future\n events[index].isDone = events[index].frame < frame;\n }\n }\n }\n this._currentFrame = frame;\n const currentValue = this._animation._interpolate(frame, this._animationState);\n this.setValue(currentValue, -1);\n }\n /**\n * @internal Internal use only\n */\n _prepareForSpeedRatioChange(newSpeedRatio) {\n const newAbsoluteFrame = (this._previousElapsedTime * (this._animation.framePerSecond * newSpeedRatio)) / 1000.0;\n this._absoluteFrameOffset = this._previousAbsoluteFrame - newAbsoluteFrame;\n }\n /**\n * Execute the current animation\n * @param elapsedTimeSinceAnimationStart defines the elapsed time (in milliseconds) since the animation was started\n * @param from defines the lower frame of the animation range\n * @param to defines the upper frame of the animation range\n * @param loop defines if the current animation must loop\n * @param speedRatio defines the current speed ratio\n * @param weight defines the weight of the animation (default is -1 so no weight)\n * @returns a boolean indicating if the animation is running\n */\n animate(elapsedTimeSinceAnimationStart, from, to, loop, speedRatio, weight = -1.0) {\n const animation = this._animation;\n const targetPropertyPath = animation.targetPropertyPath;\n if (!targetPropertyPath || targetPropertyPath.length < 1) {\n this._stopped = true;\n return false;\n }\n let returnValue = true;\n // Check limits\n if (from < this._minFrame || from > this._maxFrame) {\n from = this._minFrame;\n }\n if (to < this._minFrame || to > this._maxFrame) {\n to = this._maxFrame;\n }\n const frameRange = to - from;\n let offsetValue;\n // Compute the frame according to the elapsed time and the fps of the animation (\"from\" and \"to\" are not factored in!)\n let absoluteFrame = (elapsedTimeSinceAnimationStart * (animation.framePerSecond * speedRatio)) / 1000.0 + this._absoluteFrameOffset;\n let highLimitValue = 0;\n // Apply the yoyo function if required\n if (loop && this._animationState.loopMode === Animation.ANIMATIONLOOPMODE_YOYO) {\n const position = (absoluteFrame - from) / frameRange;\n // Apply the yoyo curve\n const yoyoPosition = Math.abs(Math.sin(position * Math.PI));\n // Map the yoyo position back to the range\n absoluteFrame = yoyoPosition * frameRange + from;\n }\n this._previousElapsedTime = elapsedTimeSinceAnimationStart;\n this._previousAbsoluteFrame = absoluteFrame;\n if (!loop && to >= from && absoluteFrame >= frameRange) {\n // If we are out of range and not looping get back to caller\n returnValue = false;\n highLimitValue = animation._getKeyValue(this._maxValue);\n }\n else if (!loop && from >= to && absoluteFrame <= frameRange) {\n returnValue = false;\n highLimitValue = animation._getKeyValue(this._minValue);\n }\n else if (this._animationState.loopMode !== Animation.ANIMATIONLOOPMODE_CYCLE) {\n const keyOffset = to.toString() + from.toString();\n if (!this._offsetsCache[keyOffset]) {\n this._animationState.repeatCount = 0;\n this._animationState.loopMode = Animation.ANIMATIONLOOPMODE_CYCLE; // force a specific codepath in animation._interpolate()!\n const fromValue = animation._interpolate(from, this._animationState);\n const toValue = animation._interpolate(to, this._animationState);\n this._animationState.loopMode = this._getCorrectLoopMode();\n switch (animation.dataType) {\n // Float\n case Animation.ANIMATIONTYPE_FLOAT:\n this._offsetsCache[keyOffset] = toValue - fromValue;\n break;\n // Quaternion\n case Animation.ANIMATIONTYPE_QUATERNION:\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\n break;\n // Vector3\n case Animation.ANIMATIONTYPE_VECTOR3:\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\n break;\n // Vector2\n case Animation.ANIMATIONTYPE_VECTOR2:\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\n break;\n // Size\n case Animation.ANIMATIONTYPE_SIZE:\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\n break;\n // Color3\n case Animation.ANIMATIONTYPE_COLOR3:\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\n break;\n }\n this._highLimitsCache[keyOffset] = toValue;\n }\n highLimitValue = this._highLimitsCache[keyOffset];\n offsetValue = this._offsetsCache[keyOffset];\n }\n if (offsetValue === undefined) {\n switch (animation.dataType) {\n // Float\n case Animation.ANIMATIONTYPE_FLOAT:\n offsetValue = 0;\n break;\n // Quaternion\n case Animation.ANIMATIONTYPE_QUATERNION:\n offsetValue = _staticOffsetValueQuaternion;\n break;\n // Vector3\n case Animation.ANIMATIONTYPE_VECTOR3:\n offsetValue = _staticOffsetValueVector3;\n break;\n // Vector2\n case Animation.ANIMATIONTYPE_VECTOR2:\n offsetValue = _staticOffsetValueVector2;\n break;\n // Size\n case Animation.ANIMATIONTYPE_SIZE:\n offsetValue = _staticOffsetValueSize;\n break;\n // Color3\n case Animation.ANIMATIONTYPE_COLOR3:\n offsetValue = _staticOffsetValueColor3;\n }\n }\n // Compute value\n let currentFrame;\n if (this._host && this._host.syncRoot) {\n // If we must sync with an animatable, calculate the current frame based on the frame of the root animatable\n const syncRoot = this._host.syncRoot;\n const hostNormalizedFrame = (syncRoot.masterFrame - syncRoot.fromFrame) / (syncRoot.toFrame - syncRoot.fromFrame);\n currentFrame = from + frameRange * hostNormalizedFrame;\n }\n else {\n if ((absoluteFrame > 0 && from > to) || (absoluteFrame < 0 && from < to)) {\n currentFrame = returnValue && frameRange !== 0 ? to + (absoluteFrame % frameRange) : from;\n }\n else {\n currentFrame = returnValue && frameRange !== 0 ? from + (absoluteFrame % frameRange) : to;\n }\n }\n const events = this._events;\n // Reset event/state if looping\n if ((speedRatio > 0 && this.currentFrame > currentFrame) || (speedRatio < 0 && this.currentFrame < currentFrame)) {\n this._onLoop();\n // Need to reset animation events\n for (let index = 0; index < events.length; index++) {\n if (!events[index].onlyOnce) {\n // reset event, the animation is looping\n events[index].isDone = false;\n }\n }\n this._animationState.key = speedRatio > 0 ? 0 : animation.getKeys().length - 1;\n }\n this._currentFrame = currentFrame;\n this._animationState.repeatCount = frameRange === 0 ? 0 : (absoluteFrame / frameRange) >> 0;\n this._animationState.highLimitValue = highLimitValue;\n this._animationState.offsetValue = offsetValue;\n const currentValue = animation._interpolate(currentFrame, this._animationState);\n // Set value\n this.setValue(currentValue, weight);\n // Check events\n if (events.length) {\n for (let index = 0; index < events.length; index++) {\n // Make sure current frame has passed event frame and that event frame is within the current range\n // Also, handle both forward and reverse animations\n if ((frameRange > 0 && currentFrame >= events[index].frame && events[index].frame >= from) ||\n (frameRange < 0 && currentFrame <= events[index].frame && events[index].frame <= from)) {\n const event = events[index];\n if (!event.isDone) {\n // If event should be done only once, remove it.\n if (event.onlyOnce) {\n events.splice(index, 1);\n index--;\n }\n event.isDone = true;\n event.action(currentFrame);\n } // Don't do anything if the event has already been done.\n }\n }\n }\n if (!returnValue) {\n this._stopped = true;\n }\n return returnValue;\n }\n }\n\n /**\n * Class used to store bone information\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons\n */\n class Bone extends Node {\n /** @internal */\n get _matrix() {\n this._compose();\n return this._localMatrix;\n }\n /** @internal */\n set _matrix(value) {\n // skip if the matrices are the same\n if (value.updateFlag === this._localMatrix.updateFlag && !this._needToCompose) {\n return;\n }\n this._needToCompose = false; // in case there was a pending compose\n this._localMatrix.copyFrom(value);\n this._markAsDirtyAndDecompose();\n }\n /**\n * Create a new bone\n * @param name defines the bone name\n * @param skeleton defines the parent skeleton\n * @param parentBone defines the parent (can be null if the bone is the root)\n * @param localMatrix defines the local matrix (default: identity)\n * @param restMatrix defines the rest matrix (default: localMatrix)\n * @param bindMatrix defines the bind matrix (default: localMatrix)\n * @param index defines index of the bone in the hierarchy (default: null)\n */\n constructor(\n /**\n * defines the bone name\n */\n name, skeleton, parentBone = null, localMatrix = null, restMatrix = null, bindMatrix = null, index = null) {\n var _a;\n super(name, skeleton.getScene());\n this.name = name;\n /**\n * Gets the list of child bones\n */\n this.children = new Array();\n /** Gets the animations associated with this bone */\n this.animations = new Array();\n /**\n * @internal Internal only\n * Set this value to map this bone to a different index in the transform matrices\n * Set this value to -1 to exclude the bone from the transform matrices\n */\n this._index = null;\n this._scalingDeterminant = 1;\n this._needToDecompose = true;\n this._needToCompose = false;\n /** @internal */\n this._linkedTransformNode = null;\n /** @internal */\n this._waitingTransformNodeId = null;\n this._skeleton = skeleton;\n this._localMatrix = (_a = localMatrix === null || localMatrix === void 0 ? void 0 : localMatrix.clone()) !== null && _a !== void 0 ? _a : Matrix.Identity();\n this._restMatrix = restMatrix !== null && restMatrix !== void 0 ? restMatrix : this._localMatrix.clone();\n this._bindMatrix = bindMatrix !== null && bindMatrix !== void 0 ? bindMatrix : this._localMatrix.clone();\n this._index = index;\n this._absoluteMatrix = new Matrix();\n this._absoluteBindMatrix = new Matrix();\n this._absoluteInverseBindMatrix = new Matrix();\n this._finalMatrix = new Matrix();\n skeleton.bones.push(this);\n this.setParent(parentBone, false);\n this._updateAbsoluteBindMatrices();\n }\n /**\n * Gets the current object class name.\n * @returns the class name\n */\n getClassName() {\n return \"Bone\";\n }\n // Members\n /**\n * Gets the parent skeleton\n * @returns a skeleton\n */\n getSkeleton() {\n return this._skeleton;\n }\n get parent() {\n return this._parentNode;\n }\n /**\n * Gets parent bone\n * @returns a bone or null if the bone is the root of the bone hierarchy\n */\n getParent() {\n return this.parent;\n }\n /**\n * Returns an array containing the children of the bone\n * @returns an array containing the children of the bone (can be empty if the bone has no children)\n */\n getChildren() {\n return this.children;\n }\n /**\n * Gets the node index in matrix array generated for rendering\n * @returns the node index\n */\n getIndex() {\n return this._index === null ? this.getSkeleton().bones.indexOf(this) : this._index;\n }\n set parent(newParent) {\n this.setParent(newParent);\n }\n /**\n * Sets the parent bone\n * @param parent defines the parent (can be null if the bone is the root)\n * @param updateAbsoluteBindMatrices defines if the absolute bind and absolute inverse bind matrices must be updated\n */\n setParent(parent, updateAbsoluteBindMatrices = true) {\n if (this.parent === parent) {\n return;\n }\n if (this.parent) {\n const index = this.parent.children.indexOf(this);\n if (index !== -1) {\n this.parent.children.splice(index, 1);\n }\n }\n this._parentNode = parent;\n if (this.parent) {\n this.parent.children.push(this);\n }\n if (updateAbsoluteBindMatrices) {\n this._updateAbsoluteBindMatrices();\n }\n this.markAsDirty();\n }\n /**\n * Gets the local matrix\n * @returns the local matrix\n */\n getLocalMatrix() {\n this._compose();\n return this._localMatrix;\n }\n /**\n * Gets the bind matrix\n * @returns the bind matrix\n */\n getBindMatrix() {\n return this._bindMatrix;\n }\n /**\n * Gets the bind matrix.\n * @returns the bind matrix\n * @deprecated Please use getBindMatrix instead\n */\n getBaseMatrix() {\n return this.getBindMatrix();\n }\n /**\n * Gets the rest matrix\n * @returns the rest matrix\n */\n getRestMatrix() {\n return this._restMatrix;\n }\n /**\n * Gets the rest matrix\n * @returns the rest matrix\n * @deprecated Please use getRestMatrix instead\n */\n getRestPose() {\n return this.getRestMatrix();\n }\n /**\n * Sets the rest matrix\n * @param matrix the local-space rest matrix to set for this bone\n */\n setRestMatrix(matrix) {\n this._restMatrix.copyFrom(matrix);\n }\n /**\n * Sets the rest matrix\n * @param matrix the local-space rest to set for this bone\n * @deprecated Please use setRestMatrix instead\n */\n setRestPose(matrix) {\n this.setRestMatrix(matrix);\n }\n /**\n * Gets the bind matrix\n * @returns the bind matrix\n * @deprecated Please use getBindMatrix instead\n */\n getBindPose() {\n return this.getBindMatrix();\n }\n /**\n * Sets the bind matrix\n * This will trigger a recomputation of the absolute bind and absolute inverse bind matrices for this bone and its children\n * Note that the local matrix will also be set with the matrix passed in parameter!\n * @param matrix the local-space bind matrix to set for this bone\n */\n setBindMatrix(matrix) {\n this.updateMatrix(matrix);\n }\n /**\n * Sets the bind matrix\n * @param matrix the local-space bind to set for this bone\n * @deprecated Please use setBindMatrix instead\n */\n setBindPose(matrix) {\n this.setBindMatrix(matrix);\n }\n /**\n * Gets the matrix used to store the final world transformation of the bone (ie. the matrix sent to shaders)\n */\n getFinalMatrix() {\n return this._finalMatrix;\n }\n /**\n * Gets the matrix used to store the final world transformation of the bone (ie. the matrix sent to shaders)\n * @deprecated Please use getFinalMatrix instead\n */\n getWorldMatrix() {\n return this.getFinalMatrix();\n }\n /**\n * Sets the local matrix to the rest matrix\n */\n returnToRest() {\n var _a;\n if (this._linkedTransformNode) {\n const localScaling = TmpVectors.Vector3[0];\n const localRotation = TmpVectors.Quaternion[0];\n const localPosition = TmpVectors.Vector3[1];\n this.getRestMatrix().decompose(localScaling, localRotation, localPosition);\n this._linkedTransformNode.position.copyFrom(localPosition);\n this._linkedTransformNode.rotationQuaternion = (_a = this._linkedTransformNode.rotationQuaternion) !== null && _a !== void 0 ? _a : Quaternion.Identity();\n this._linkedTransformNode.rotationQuaternion.copyFrom(localRotation);\n this._linkedTransformNode.scaling.copyFrom(localScaling);\n }\n else {\n this._matrix = this._restMatrix;\n }\n }\n /**\n * Gets the inverse of the bind matrix, in world space (relative to the skeleton root)\n * @returns the inverse bind matrix, in world space\n */\n getAbsoluteInverseBindMatrix() {\n return this._absoluteInverseBindMatrix;\n }\n /**\n * Gets the inverse of the bind matrix, in world space (relative to the skeleton root)\n * @returns the inverse bind matrix, in world space\n * @deprecated Please use getAbsoluteInverseBindMatrix instead\n */\n getInvertedAbsoluteTransform() {\n return this.getAbsoluteInverseBindMatrix();\n }\n /**\n * Gets the bone matrix, in world space (relative to the skeleton root)\n * @returns the bone matrix, in world space\n */\n getAbsoluteMatrix() {\n return this._absoluteMatrix;\n }\n /**\n * Gets the bone matrix, in world space (relative to the skeleton root)\n * @returns the bone matrix, in world space\n * @deprecated Please use getAbsoluteMatrix instead\n */\n getAbsoluteTransform() {\n return this._absoluteMatrix;\n }\n /**\n * Links with the given transform node.\n * The local matrix of this bone is overwritten by the transform of the node every frame.\n * @param transformNode defines the transform node to link to\n */\n linkTransformNode(transformNode) {\n if (this._linkedTransformNode) {\n this._skeleton._numBonesWithLinkedTransformNode--;\n }\n this._linkedTransformNode = transformNode;\n if (this._linkedTransformNode) {\n this._skeleton._numBonesWithLinkedTransformNode++;\n }\n }\n // Properties (matches TransformNode properties)\n /**\n * Gets the node used to drive the bone's transformation\n * @returns a transform node or null\n */\n getTransformNode() {\n return this._linkedTransformNode;\n }\n /** Gets or sets current position (in local space) */\n get position() {\n this._decompose();\n return this._localPosition;\n }\n set position(newPosition) {\n this._decompose();\n this._localPosition.copyFrom(newPosition);\n this._markAsDirtyAndCompose();\n }\n /** Gets or sets current rotation (in local space) */\n get rotation() {\n return this.getRotation();\n }\n set rotation(newRotation) {\n this.setRotation(newRotation);\n }\n /** Gets or sets current rotation quaternion (in local space) */\n get rotationQuaternion() {\n this._decompose();\n return this._localRotation;\n }\n set rotationQuaternion(newRotation) {\n this.setRotationQuaternion(newRotation);\n }\n /** Gets or sets current scaling (in local space) */\n get scaling() {\n return this.getScale();\n }\n set scaling(newScaling) {\n this.setScale(newScaling);\n }\n /**\n * Gets the animation properties override\n */\n get animationPropertiesOverride() {\n return this._skeleton.animationPropertiesOverride;\n }\n // Methods\n _decompose() {\n if (!this._needToDecompose) {\n return;\n }\n this._needToDecompose = false;\n if (!this._localScaling) {\n this._localScaling = Vector3.Zero();\n this._localRotation = Quaternion.Zero();\n this._localPosition = Vector3.Zero();\n }\n this._localMatrix.decompose(this._localScaling, this._localRotation, this._localPosition);\n }\n _compose() {\n if (!this._needToCompose) {\n return;\n }\n if (!this._localScaling) {\n this._needToCompose = false;\n return;\n }\n this._needToCompose = false;\n Matrix.ComposeToRef(this._localScaling, this._localRotation, this._localPosition, this._localMatrix);\n }\n /**\n * Update the bind (and optionally the local) matrix\n * @param bindMatrix defines the new matrix to set to the bind/local matrix, in local space\n * @param updateAbsoluteBindMatrices defines if the absolute bind and absolute inverse bind matrices must be recomputed (default: true)\n * @param updateLocalMatrix defines if the local matrix should also be updated with the matrix passed in parameter (default: true)\n */\n updateMatrix(bindMatrix, updateAbsoluteBindMatrices = true, updateLocalMatrix = true) {\n this._bindMatrix.copyFrom(bindMatrix);\n if (updateAbsoluteBindMatrices) {\n this._updateAbsoluteBindMatrices();\n }\n if (updateLocalMatrix) {\n this._matrix = bindMatrix;\n }\n else {\n this.markAsDirty();\n }\n }\n /**\n * @internal\n */\n _updateAbsoluteBindMatrices(bindMatrix, updateChildren = true) {\n if (!bindMatrix) {\n bindMatrix = this._bindMatrix;\n }\n if (this.parent) {\n bindMatrix.multiplyToRef(this.parent._absoluteBindMatrix, this._absoluteBindMatrix);\n }\n else {\n this._absoluteBindMatrix.copyFrom(bindMatrix);\n }\n this._absoluteBindMatrix.invertToRef(this._absoluteInverseBindMatrix);\n if (updateChildren) {\n for (let index = 0; index < this.children.length; index++) {\n this.children[index]._updateAbsoluteBindMatrices();\n }\n }\n this._scalingDeterminant = this._absoluteBindMatrix.determinant() < 0 ? -1 : 1;\n }\n /**\n * Flag the bone as dirty (Forcing it to update everything)\n * @returns this bone\n */\n markAsDirty() {\n this._currentRenderId++;\n this._childUpdateId++;\n this._skeleton._markAsDirty();\n return this;\n }\n /** @internal */\n _markAsDirtyAndCompose() {\n this.markAsDirty();\n this._needToCompose = true;\n }\n _markAsDirtyAndDecompose() {\n this.markAsDirty();\n this._needToDecompose = true;\n }\n _updatePosition(vec, space = Space.LOCAL, tNode, translationMode = true) {\n const lm = this.getLocalMatrix();\n if (space == Space.LOCAL) {\n if (translationMode) {\n lm.addAtIndex(12, vec.x);\n lm.addAtIndex(13, vec.y);\n lm.addAtIndex(14, vec.z);\n }\n else {\n lm.setTranslationFromFloats(vec.x, vec.y, vec.z);\n }\n }\n else {\n let wm = null;\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\n if (tNode) {\n wm = tNode.getWorldMatrix();\n }\n this._skeleton.computeAbsoluteMatrices();\n const tmat = Bone._TmpMats[0];\n const tvec = Bone._TmpVecs[0];\n if (this.parent) {\n if (tNode && wm) {\n tmat.copyFrom(this.parent.getAbsoluteMatrix());\n tmat.multiplyToRef(wm, tmat);\n }\n else {\n tmat.copyFrom(this.parent.getAbsoluteMatrix());\n }\n }\n else {\n Matrix.IdentityToRef(tmat);\n }\n if (translationMode) {\n tmat.setTranslationFromFloats(0, 0, 0);\n }\n tmat.invert();\n Vector3.TransformCoordinatesToRef(vec, tmat, tvec);\n if (translationMode) {\n lm.addAtIndex(12, tvec.x);\n lm.addAtIndex(13, tvec.y);\n lm.addAtIndex(14, tvec.z);\n }\n else {\n lm.setTranslationFromFloats(tvec.x, tvec.y, tvec.z);\n }\n }\n this._markAsDirtyAndDecompose();\n }\n /**\n * Translate the bone in local or world space\n * @param vec The amount to translate the bone\n * @param space The space that the translation is in (default: Space.LOCAL)\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n translate(vec, space = Space.LOCAL, tNode) {\n this._updatePosition(vec, space, tNode, true);\n }\n /**\n * Set the position of the bone in local or world space\n * @param position The position to set the bone\n * @param space The space that the position is in (default: Space.LOCAL)\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setPosition(position, space = Space.LOCAL, tNode) {\n this._updatePosition(position, space, tNode, false);\n }\n /**\n * Set the absolute position of the bone (world space)\n * @param position The position to set the bone\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setAbsolutePosition(position, tNode) {\n this.setPosition(position, Space.WORLD, tNode);\n }\n /**\n * Scale the bone on the x, y and z axes (in local space)\n * @param x The amount to scale the bone on the x axis\n * @param y The amount to scale the bone on the y axis\n * @param z The amount to scale the bone on the z axis\n * @param scaleChildren sets this to true if children of the bone should be scaled as well (false by default)\n */\n scale(x, y, z, scaleChildren = false) {\n const locMat = this.getLocalMatrix();\n // Apply new scaling on top of current local matrix\n const scaleMat = Bone._TmpMats[0];\n Matrix.ScalingToRef(x, y, z, scaleMat);\n scaleMat.multiplyToRef(locMat, locMat);\n // Invert scaling matrix and apply the inverse to all children\n scaleMat.invert();\n for (const child of this.children) {\n const cm = child.getLocalMatrix();\n cm.multiplyToRef(scaleMat, cm);\n cm.multiplyAtIndex(12, x);\n cm.multiplyAtIndex(13, y);\n cm.multiplyAtIndex(14, z);\n child._markAsDirtyAndDecompose();\n }\n this._markAsDirtyAndDecompose();\n if (scaleChildren) {\n for (const child of this.children) {\n child.scale(x, y, z, scaleChildren);\n }\n }\n }\n /**\n * Set the bone scaling in local space\n * @param scale defines the scaling vector\n */\n setScale(scale) {\n this._decompose();\n this._localScaling.copyFrom(scale);\n this._markAsDirtyAndCompose();\n }\n /**\n * Gets the current scaling in local space\n * @returns the current scaling vector\n */\n getScale() {\n this._decompose();\n return this._localScaling;\n }\n /**\n * Gets the current scaling in local space and stores it in a target vector\n * @param result defines the target vector\n */\n getScaleToRef(result) {\n this._decompose();\n result.copyFrom(this._localScaling);\n }\n /**\n * Set the yaw, pitch, and roll of the bone in local or world space\n * @param yaw The rotation of the bone on the y axis\n * @param pitch The rotation of the bone on the x axis\n * @param roll The rotation of the bone on the z axis\n * @param space The space that the axes of rotation are in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setYawPitchRoll(yaw, pitch, roll, space = Space.LOCAL, tNode) {\n if (space === Space.LOCAL) {\n const quat = Bone._TmpQuat;\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, quat);\n this.setRotationQuaternion(quat, space, tNode);\n return;\n }\n const rotMatInv = Bone._TmpMats[0];\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\n return;\n }\n const rotMat = Bone._TmpMats[1];\n Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);\n rotMatInv.multiplyToRef(rotMat, rotMat);\n this._rotateWithMatrix(rotMat, space, tNode);\n }\n /**\n * Add a rotation to the bone on an axis in local or world space\n * @param axis The axis to rotate the bone on\n * @param amount The amount to rotate the bone\n * @param space The space that the axis is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n rotate(axis, amount, space = Space.LOCAL, tNode) {\n const rmat = Bone._TmpMats[0];\n rmat.setTranslationFromFloats(0, 0, 0);\n Matrix.RotationAxisToRef(axis, amount, rmat);\n this._rotateWithMatrix(rmat, space, tNode);\n }\n /**\n * Set the rotation of the bone to a particular axis angle in local or world space\n * @param axis The axis to rotate the bone on\n * @param angle The angle that the bone should be rotated to\n * @param space The space that the axis is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setAxisAngle(axis, angle, space = Space.LOCAL, tNode) {\n if (space === Space.LOCAL) {\n const quat = Bone._TmpQuat;\n Quaternion.RotationAxisToRef(axis, angle, quat);\n this.setRotationQuaternion(quat, space, tNode);\n return;\n }\n const rotMatInv = Bone._TmpMats[0];\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\n return;\n }\n const rotMat = Bone._TmpMats[1];\n Matrix.RotationAxisToRef(axis, angle, rotMat);\n rotMatInv.multiplyToRef(rotMat, rotMat);\n this._rotateWithMatrix(rotMat, space, tNode);\n }\n /**\n * Set the euler rotation of the bone in local or world space\n * @param rotation The euler rotation that the bone should be set to\n * @param space The space that the rotation is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setRotation(rotation, space = Space.LOCAL, tNode) {\n this.setYawPitchRoll(rotation.y, rotation.x, rotation.z, space, tNode);\n }\n /**\n * Set the quaternion rotation of the bone in local or world space\n * @param quat The quaternion rotation that the bone should be set to\n * @param space The space that the rotation is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setRotationQuaternion(quat, space = Space.LOCAL, tNode) {\n if (space === Space.LOCAL) {\n this._decompose();\n this._localRotation.copyFrom(quat);\n this._markAsDirtyAndCompose();\n return;\n }\n const rotMatInv = Bone._TmpMats[0];\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\n return;\n }\n const rotMat = Bone._TmpMats[1];\n Matrix.FromQuaternionToRef(quat, rotMat);\n rotMatInv.multiplyToRef(rotMat, rotMat);\n this._rotateWithMatrix(rotMat, space, tNode);\n }\n /**\n * Set the rotation matrix of the bone in local or world space\n * @param rotMat The rotation matrix that the bone should be set to\n * @param space The space that the rotation is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n */\n setRotationMatrix(rotMat, space = Space.LOCAL, tNode) {\n if (space === Space.LOCAL) {\n const quat = Bone._TmpQuat;\n Quaternion.FromRotationMatrixToRef(rotMat, quat);\n this.setRotationQuaternion(quat, space, tNode);\n return;\n }\n const rotMatInv = Bone._TmpMats[0];\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\n return;\n }\n const rotMat2 = Bone._TmpMats[1];\n rotMat2.copyFrom(rotMat);\n rotMatInv.multiplyToRef(rotMat, rotMat2);\n this._rotateWithMatrix(rotMat2, space, tNode);\n }\n _rotateWithMatrix(rmat, space = Space.LOCAL, tNode) {\n const lmat = this.getLocalMatrix();\n const lx = lmat.m[12];\n const ly = lmat.m[13];\n const lz = lmat.m[14];\n const parent = this.getParent();\n const parentScale = Bone._TmpMats[3];\n const parentScaleInv = Bone._TmpMats[4];\n if (parent && space == Space.WORLD) {\n if (tNode) {\n parentScale.copyFrom(tNode.getWorldMatrix());\n parent.getAbsoluteMatrix().multiplyToRef(parentScale, parentScale);\n }\n else {\n parentScale.copyFrom(parent.getAbsoluteMatrix());\n }\n parentScaleInv.copyFrom(parentScale);\n parentScaleInv.invert();\n lmat.multiplyToRef(parentScale, lmat);\n lmat.multiplyToRef(rmat, lmat);\n lmat.multiplyToRef(parentScaleInv, lmat);\n }\n else {\n if (space == Space.WORLD && tNode) {\n parentScale.copyFrom(tNode.getWorldMatrix());\n parentScaleInv.copyFrom(parentScale);\n parentScaleInv.invert();\n lmat.multiplyToRef(parentScale, lmat);\n lmat.multiplyToRef(rmat, lmat);\n lmat.multiplyToRef(parentScaleInv, lmat);\n }\n else {\n lmat.multiplyToRef(rmat, lmat);\n }\n }\n lmat.setTranslationFromFloats(lx, ly, lz);\n this.computeAbsoluteMatrices();\n this._markAsDirtyAndDecompose();\n }\n _getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode) {\n const scaleMatrix = Bone._TmpMats[2];\n rotMatInv.copyFrom(this.getAbsoluteMatrix());\n if (tNode) {\n rotMatInv.multiplyToRef(tNode.getWorldMatrix(), rotMatInv);\n Matrix.ScalingToRef(tNode.scaling.x, tNode.scaling.y, tNode.scaling.z, scaleMatrix);\n }\n else {\n Matrix.IdentityToRef(scaleMatrix);\n }\n rotMatInv.invert();\n if (isNaN(rotMatInv.m[0])) {\n // Matrix failed to invert.\n // This can happen if scale is zero for example.\n return false;\n }\n scaleMatrix.multiplyAtIndex(0, this._scalingDeterminant);\n rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);\n return true;\n }\n /**\n * Get the position of the bone in local or world space\n * @param space The space that the returned position is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The position of the bone\n */\n getPosition(space = Space.LOCAL, tNode = null) {\n const pos = Vector3.Zero();\n this.getPositionToRef(space, tNode, pos);\n return pos;\n }\n /**\n * Copy the position of the bone to a vector3 in local or world space\n * @param space The space that the returned position is in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The vector3 to copy the position to\n */\n getPositionToRef(space = Space.LOCAL, tNode, result) {\n if (space == Space.LOCAL) {\n const lm = this.getLocalMatrix();\n result.x = lm.m[12];\n result.y = lm.m[13];\n result.z = lm.m[14];\n }\n else {\n let wm = null;\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\n if (tNode) {\n wm = tNode.getWorldMatrix();\n }\n this._skeleton.computeAbsoluteMatrices();\n let tmat = Bone._TmpMats[0];\n if (tNode && wm) {\n tmat.copyFrom(this.getAbsoluteMatrix());\n tmat.multiplyToRef(wm, tmat);\n }\n else {\n tmat = this.getAbsoluteMatrix();\n }\n result.x = tmat.m[12];\n result.y = tmat.m[13];\n result.z = tmat.m[14];\n }\n }\n /**\n * Get the absolute position of the bone (world space)\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The absolute position of the bone\n */\n getAbsolutePosition(tNode = null) {\n const pos = Vector3.Zero();\n this.getPositionToRef(Space.WORLD, tNode, pos);\n return pos;\n }\n /**\n * Copy the absolute position of the bone (world space) to the result param\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The vector3 to copy the absolute position to\n */\n getAbsolutePositionToRef(tNode, result) {\n this.getPositionToRef(Space.WORLD, tNode, result);\n }\n /**\n * Compute the absolute matrices of this bone and its children\n */\n computeAbsoluteMatrices() {\n this._compose();\n if (this.parent) {\n this._localMatrix.multiplyToRef(this.parent._absoluteMatrix, this._absoluteMatrix);\n }\n else {\n this._absoluteMatrix.copyFrom(this._localMatrix);\n const poseMatrix = this._skeleton.getPoseMatrix();\n if (poseMatrix) {\n this._absoluteMatrix.multiplyToRef(poseMatrix, this._absoluteMatrix);\n }\n }\n const children = this.children;\n const len = children.length;\n for (let i = 0; i < len; i++) {\n children[i].computeAbsoluteMatrices();\n }\n }\n /**\n * Compute the absolute matrices of this bone and its children\n * @deprecated Please use computeAbsoluteMatrices instead\n */\n computeAbsoluteTransforms() {\n this.computeAbsoluteMatrices();\n }\n /**\n * Get the world direction from an axis that is in the local space of the bone\n * @param localAxis The local direction that is used to compute the world direction\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The world direction\n */\n getDirection(localAxis, tNode = null) {\n const result = Vector3.Zero();\n this.getDirectionToRef(localAxis, tNode, result);\n return result;\n }\n /**\n * Copy the world direction to a vector3 from an axis that is in the local space of the bone\n * @param localAxis The local direction that is used to compute the world direction\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The vector3 that the world direction will be copied to\n */\n getDirectionToRef(localAxis, tNode = null, result) {\n let wm = null;\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\n if (tNode) {\n wm = tNode.getWorldMatrix();\n }\n this._skeleton.computeAbsoluteMatrices();\n const mat = Bone._TmpMats[0];\n mat.copyFrom(this.getAbsoluteMatrix());\n if (tNode && wm) {\n mat.multiplyToRef(wm, mat);\n }\n Vector3.TransformNormalToRef(localAxis, mat, result);\n result.normalize();\n }\n /**\n * Get the euler rotation of the bone in local or world space\n * @param space The space that the rotation should be in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The euler rotation\n */\n getRotation(space = Space.LOCAL, tNode = null) {\n const result = Vector3.Zero();\n this.getRotationToRef(space, tNode, result);\n return result;\n }\n /**\n * Copy the euler rotation of the bone to a vector3. The rotation can be in either local or world space\n * @param space The space that the rotation should be in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The vector3 that the rotation should be copied to\n */\n getRotationToRef(space = Space.LOCAL, tNode = null, result) {\n const quat = Bone._TmpQuat;\n this.getRotationQuaternionToRef(space, tNode, quat);\n quat.toEulerAnglesToRef(result);\n }\n /**\n * Get the quaternion rotation of the bone in either local or world space\n * @param space The space that the rotation should be in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The quaternion rotation\n */\n getRotationQuaternion(space = Space.LOCAL, tNode = null) {\n const result = Quaternion.Identity();\n this.getRotationQuaternionToRef(space, tNode, result);\n return result;\n }\n /**\n * Copy the quaternion rotation of the bone to a quaternion. The rotation can be in either local or world space\n * @param space The space that the rotation should be in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The quaternion that the rotation should be copied to\n */\n getRotationQuaternionToRef(space = Space.LOCAL, tNode = null, result) {\n if (space == Space.LOCAL) {\n this._decompose();\n result.copyFrom(this._localRotation);\n }\n else {\n const mat = Bone._TmpMats[0];\n const amat = this.getAbsoluteMatrix();\n if (tNode) {\n amat.multiplyToRef(tNode.getWorldMatrix(), mat);\n }\n else {\n mat.copyFrom(amat);\n }\n mat.multiplyAtIndex(0, this._scalingDeterminant);\n mat.multiplyAtIndex(1, this._scalingDeterminant);\n mat.multiplyAtIndex(2, this._scalingDeterminant);\n mat.decompose(undefined, result, undefined);\n }\n }\n /**\n * Get the rotation matrix of the bone in local or world space\n * @param space The space that the rotation should be in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The rotation matrix\n */\n getRotationMatrix(space = Space.LOCAL, tNode) {\n const result = Matrix.Identity();\n this.getRotationMatrixToRef(space, tNode, result);\n return result;\n }\n /**\n * Copy the rotation matrix of the bone to a matrix. The rotation can be in either local or world space\n * @param space The space that the rotation should be in\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The quaternion that the rotation should be copied to\n */\n getRotationMatrixToRef(space = Space.LOCAL, tNode, result) {\n if (space == Space.LOCAL) {\n this.getLocalMatrix().getRotationMatrixToRef(result);\n }\n else {\n const mat = Bone._TmpMats[0];\n const amat = this.getAbsoluteMatrix();\n if (tNode) {\n amat.multiplyToRef(tNode.getWorldMatrix(), mat);\n }\n else {\n mat.copyFrom(amat);\n }\n mat.multiplyAtIndex(0, this._scalingDeterminant);\n mat.multiplyAtIndex(1, this._scalingDeterminant);\n mat.multiplyAtIndex(2, this._scalingDeterminant);\n mat.getRotationMatrixToRef(result);\n }\n }\n /**\n * Get the world position of a point that is in the local space of the bone\n * @param position The local position\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The world position\n */\n getAbsolutePositionFromLocal(position, tNode = null) {\n const result = Vector3.Zero();\n this.getAbsolutePositionFromLocalToRef(position, tNode, result);\n return result;\n }\n /**\n * Get the world position of a point that is in the local space of the bone and copy it to the result param\n * @param position The local position\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The vector3 that the world position should be copied to\n */\n getAbsolutePositionFromLocalToRef(position, tNode = null, result) {\n let wm = null;\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\n if (tNode) {\n wm = tNode.getWorldMatrix();\n }\n this._skeleton.computeAbsoluteMatrices();\n const tmat = Bone._TmpMats[0];\n tmat.copyFrom(this.getAbsoluteMatrix());\n if (tNode && wm) {\n tmat.multiplyToRef(wm, tmat);\n }\n Vector3.TransformCoordinatesToRef(position, tmat, result);\n }\n /**\n * Get the local position of a point that is in world space\n * @param position The world position\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @returns The local position\n */\n getLocalPositionFromAbsolute(position, tNode = null) {\n const result = Vector3.Zero();\n this.getLocalPositionFromAbsoluteToRef(position, tNode, result);\n return result;\n }\n /**\n * Get the local position of a point that is in world space and copy it to the result param\n * @param position The world position\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\n * @param result The vector3 that the local position should be copied to\n */\n getLocalPositionFromAbsoluteToRef(position, tNode = null, result) {\n let wm = null;\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\n if (tNode) {\n wm = tNode.getWorldMatrix();\n }\n this._skeleton.computeAbsoluteMatrices();\n const tmat = Bone._TmpMats[0];\n tmat.copyFrom(this.getAbsoluteMatrix());\n if (tNode && wm) {\n tmat.multiplyToRef(wm, tmat);\n }\n tmat.invert();\n Vector3.TransformCoordinatesToRef(position, tmat, result);\n }\n /**\n * Set the current local matrix as the restMatrix for this bone.\n */\n setCurrentPoseAsRest() {\n this.setRestMatrix(this.getLocalMatrix());\n }\n }\n Bone._TmpVecs = ArrayTools.BuildArray(2, Vector3.Zero);\n Bone._TmpQuat = Quaternion.Identity();\n Bone._TmpMats = ArrayTools.BuildArray(5, Matrix.Identity);\n\n /**\n * Class used to store an actual running animation\n */\n class Animatable {\n /**\n * Gets the root Animatable used to synchronize and normalize animations\n */\n get syncRoot() {\n return this._syncRoot;\n }\n /**\n * Gets the current frame of the first RuntimeAnimation\n * Used to synchronize Animatables\n */\n get masterFrame() {\n if (this._runtimeAnimations.length === 0) {\n return 0;\n }\n return this._runtimeAnimations[0].currentFrame;\n }\n /**\n * Gets or sets the animatable weight (-1.0 by default meaning not weighted)\n */\n get weight() {\n return this._weight;\n }\n set weight(value) {\n if (value === -1) {\n // -1 is ok and means no weight\n this._weight = -1;\n return;\n }\n // Else weight must be in [0, 1] range\n this._weight = Math.min(Math.max(value, 0), 1.0);\n }\n /**\n * Gets or sets the speed ratio to apply to the animatable (1.0 by default)\n */\n get speedRatio() {\n return this._speedRatio;\n }\n set speedRatio(value) {\n for (let index = 0; index < this._runtimeAnimations.length; index++) {\n const animation = this._runtimeAnimations[index];\n animation._prepareForSpeedRatioChange(value);\n }\n this._speedRatio = value;\n // Resync _manualJumpDelay in case goToFrame was called before speedRatio was set.\n if (this._goToFrame !== null) {\n this.goToFrame(this._goToFrame);\n }\n }\n /**\n * Creates a new Animatable\n * @param scene defines the hosting scene\n * @param target defines the target object\n * @param fromFrame defines the starting frame number (default is 0)\n * @param toFrame defines the ending frame number (default is 100)\n * @param loopAnimation defines if the animation must loop (default is false)\n * @param speedRatio defines the factor to apply to animation speed (default is 1)\n * @param onAnimationEnd defines a callback to call when animation ends if it is not looping\n * @param animations defines a group of animation to add to the new Animatable\n * @param onAnimationLoop defines a callback to call when animation loops\n * @param isAdditive defines whether the animation should be evaluated additively\n * @param playOrder defines the order in which this animatable should be processed in the list of active animatables (default: 0)\n */\n constructor(scene, \n /** defines the target object */\n target, \n /** defines the starting frame number (default is 0) */\n fromFrame = 0, \n /** defines the ending frame number (default is 100) */\n toFrame = 100, \n /** defines if the animation must loop (default is false) */\n loopAnimation = false, speedRatio = 1.0, \n /** defines a callback to call when animation ends if it is not looping */\n onAnimationEnd, animations, \n /** defines a callback to call when animation loops */\n onAnimationLoop, \n /** defines whether the animation should be evaluated additively */\n isAdditive = false, \n /** defines the order in which this animatable should be processed in the list of active animatables (default: 0) */\n playOrder = 0) {\n this.target = target;\n this.fromFrame = fromFrame;\n this.toFrame = toFrame;\n this.loopAnimation = loopAnimation;\n this.onAnimationEnd = onAnimationEnd;\n this.onAnimationLoop = onAnimationLoop;\n this.isAdditive = isAdditive;\n this.playOrder = playOrder;\n this._localDelayOffset = null;\n this._pausedDelay = null;\n this._manualJumpDelay = null;\n /** @hidden */\n this._runtimeAnimations = new Array();\n this._paused = false;\n this._speedRatio = 1;\n this._weight = -1.0;\n this._syncRoot = null;\n this._frameToSyncFromJump = null;\n this._goToFrame = null;\n /**\n * Gets or sets a boolean indicating if the animatable must be disposed and removed at the end of the animation.\n * This will only apply for non looping animation (default is true)\n */\n this.disposeOnEnd = true;\n /**\n * Gets a boolean indicating if the animation has started\n */\n this.animationStarted = false;\n /**\n * Observer raised when the animation ends\n */\n this.onAnimationEndObservable = new Observable$1();\n /**\n * Observer raised when the animation loops\n */\n this.onAnimationLoopObservable = new Observable$1();\n this._scene = scene;\n if (animations) {\n this.appendAnimations(target, animations);\n }\n this._speedRatio = speedRatio;\n scene._activeAnimatables.push(this);\n }\n // Methods\n /**\n * Synchronize and normalize current Animatable with a source Animatable\n * This is useful when using animation weights and when animations are not of the same length\n * @param root defines the root Animatable to synchronize with (null to stop synchronizing)\n * @returns the current Animatable\n */\n syncWith(root) {\n this._syncRoot = root;\n if (root) {\n // Make sure this animatable will animate after the root\n const index = this._scene._activeAnimatables.indexOf(this);\n if (index > -1) {\n this._scene._activeAnimatables.splice(index, 1);\n this._scene._activeAnimatables.push(this);\n }\n }\n return this;\n }\n /**\n * Gets the list of runtime animations\n * @returns an array of RuntimeAnimation\n */\n getAnimations() {\n return this._runtimeAnimations;\n }\n /**\n * Adds more animations to the current animatable\n * @param target defines the target of the animations\n * @param animations defines the new animations to add\n */\n appendAnimations(target, animations) {\n for (let index = 0; index < animations.length; index++) {\n const animation = animations[index];\n const newRuntimeAnimation = new RuntimeAnimation(target, animation, this._scene, this);\n newRuntimeAnimation._onLoop = () => {\n this.onAnimationLoopObservable.notifyObservers(this);\n if (this.onAnimationLoop) {\n this.onAnimationLoop();\n }\n };\n this._runtimeAnimations.push(newRuntimeAnimation);\n }\n }\n /**\n * Gets the source animation for a specific property\n * @param property defines the property to look for\n * @returns null or the source animation for the given property\n */\n getAnimationByTargetProperty(property) {\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = 0; index < runtimeAnimations.length; index++) {\n if (runtimeAnimations[index].animation.targetProperty === property) {\n return runtimeAnimations[index].animation;\n }\n }\n return null;\n }\n /**\n * Gets the runtime animation for a specific property\n * @param property defines the property to look for\n * @returns null or the runtime animation for the given property\n */\n getRuntimeAnimationByTargetProperty(property) {\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = 0; index < runtimeAnimations.length; index++) {\n if (runtimeAnimations[index].animation.targetProperty === property) {\n return runtimeAnimations[index];\n }\n }\n return null;\n }\n /**\n * Resets the animatable to its original state\n */\n reset() {\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = 0; index < runtimeAnimations.length; index++) {\n runtimeAnimations[index].reset(true);\n }\n this._localDelayOffset = null;\n this._pausedDelay = null;\n }\n /**\n * Allows the animatable to blend with current running animations\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending\n * @param blendingSpeed defines the blending speed to use\n */\n enableBlending(blendingSpeed) {\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = 0; index < runtimeAnimations.length; index++) {\n runtimeAnimations[index].animation.enableBlending = true;\n runtimeAnimations[index].animation.blendingSpeed = blendingSpeed;\n }\n }\n /**\n * Disable animation blending\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending\n */\n disableBlending() {\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = 0; index < runtimeAnimations.length; index++) {\n runtimeAnimations[index].animation.enableBlending = false;\n }\n }\n /**\n * Jump directly to a given frame\n * @param frame defines the frame to jump to\n */\n goToFrame(frame) {\n var _a;\n const runtimeAnimations = this._runtimeAnimations;\n if (runtimeAnimations[0]) {\n const fps = runtimeAnimations[0].animation.framePerSecond;\n this._frameToSyncFromJump = (_a = this._frameToSyncFromJump) !== null && _a !== void 0 ? _a : runtimeAnimations[0].currentFrame;\n const delay = this.speedRatio === 0 ? 0 : (((frame - this._frameToSyncFromJump) / fps) * 1000) / this.speedRatio;\n this._manualJumpDelay = -delay;\n }\n for (let index = 0; index < runtimeAnimations.length; index++) {\n runtimeAnimations[index].goToFrame(frame);\n }\n this._goToFrame = frame;\n }\n /**\n * Pause the animation\n */\n pause() {\n if (this._paused) {\n return;\n }\n this._paused = true;\n }\n /**\n * Restart the animation\n */\n restart() {\n this._paused = false;\n }\n _raiseOnAnimationEnd() {\n if (this.onAnimationEnd) {\n this.onAnimationEnd();\n }\n this.onAnimationEndObservable.notifyObservers(this);\n }\n /**\n * Stop and delete the current animation\n * @param animationName defines a string used to only stop some of the runtime animations instead of all\n * @param targetMask a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)\n * @param useGlobalSplice if true, the animatables will be removed by the caller of this function (false by default)\n */\n stop(animationName, targetMask, useGlobalSplice = false) {\n if (animationName || targetMask) {\n const idx = this._scene._activeAnimatables.indexOf(this);\n if (idx > -1) {\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = runtimeAnimations.length - 1; index >= 0; index--) {\n const runtimeAnimation = runtimeAnimations[index];\n if (animationName && runtimeAnimation.animation.name != animationName) {\n continue;\n }\n if (targetMask && !targetMask(runtimeAnimation.target)) {\n continue;\n }\n runtimeAnimation.dispose();\n runtimeAnimations.splice(index, 1);\n }\n if (runtimeAnimations.length == 0) {\n if (!useGlobalSplice) {\n this._scene._activeAnimatables.splice(idx, 1);\n }\n this._raiseOnAnimationEnd();\n }\n }\n }\n else {\n const index = this._scene._activeAnimatables.indexOf(this);\n if (index > -1) {\n if (!useGlobalSplice) {\n this._scene._activeAnimatables.splice(index, 1);\n }\n const runtimeAnimations = this._runtimeAnimations;\n for (let index = 0; index < runtimeAnimations.length; index++) {\n runtimeAnimations[index].dispose();\n }\n this._runtimeAnimations.length = 0;\n this._raiseOnAnimationEnd();\n }\n }\n }\n /**\n * Wait asynchronously for the animation to end\n * @returns a promise which will be fulfilled when the animation ends\n */\n waitAsync() {\n return new Promise((resolve) => {\n this.onAnimationEndObservable.add(() => {\n resolve(this);\n }, undefined, undefined, this, true);\n });\n }\n /**\n * @internal\n */\n _animate(delay) {\n if (this._paused) {\n this.animationStarted = false;\n if (this._pausedDelay === null) {\n this._pausedDelay = delay;\n }\n return true;\n }\n if (this._localDelayOffset === null) {\n this._localDelayOffset = delay;\n this._pausedDelay = null;\n }\n else if (this._pausedDelay !== null) {\n this._localDelayOffset += delay - this._pausedDelay;\n this._pausedDelay = null;\n }\n if (this._manualJumpDelay !== null) {\n this._localDelayOffset += this._manualJumpDelay;\n this._manualJumpDelay = null;\n this._frameToSyncFromJump = null;\n }\n this._goToFrame = null;\n if (this._weight === 0) {\n // We consider that an animation with a weight === 0 is \"actively\" paused\n return true;\n }\n // Animating\n let running = false;\n const runtimeAnimations = this._runtimeAnimations;\n let index;\n for (index = 0; index < runtimeAnimations.length; index++) {\n const animation = runtimeAnimations[index];\n const isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this._speedRatio, this._weight);\n running = running || isRunning;\n }\n this.animationStarted = running;\n if (!running) {\n if (this.disposeOnEnd) {\n // Remove from active animatables\n index = this._scene._activeAnimatables.indexOf(this);\n this._scene._activeAnimatables.splice(index, 1);\n // Dispose all runtime animations\n for (index = 0; index < runtimeAnimations.length; index++) {\n runtimeAnimations[index].dispose();\n }\n }\n this._raiseOnAnimationEnd();\n if (this.disposeOnEnd) {\n this.onAnimationEnd = null;\n this.onAnimationLoop = null;\n this.onAnimationLoopObservable.clear();\n this.onAnimationEndObservable.clear();\n }\n }\n return running;\n }\n }\n Scene.prototype._animate = function () {\n if (!this.animationsEnabled) {\n return;\n }\n // Getting time\n const now = PrecisionDate.Now;\n if (!this._animationTimeLast) {\n if (this._pendingData.length > 0) {\n return;\n }\n this._animationTimeLast = now;\n }\n this.deltaTime = this.useConstantAnimationDeltaTime ? 16.0 : (now - this._animationTimeLast) * this.animationTimeScale;\n this._animationTimeLast = now;\n const animatables = this._activeAnimatables;\n if (animatables.length === 0) {\n return;\n }\n this._animationTime += this.deltaTime;\n const animationTime = this._animationTime;\n for (let index = 0; index < animatables.length; index++) {\n const animatable = animatables[index];\n if (!animatable._animate(animationTime) && animatable.disposeOnEnd) {\n index--; // Array was updated\n }\n }\n // Late animation bindings\n this._processLateAnimationBindings();\n };\n Scene.prototype.sortActiveAnimatables = function () {\n this._activeAnimatables.sort((a, b) => {\n return a.playOrder - b.playOrder;\n });\n };\n Scene.prototype.beginWeightedAnimation = function (target, from, to, weight = 1.0, loop, speedRatio = 1.0, onAnimationEnd, animatable, targetMask, onAnimationLoop, isAdditive = false) {\n const returnedAnimatable = this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, false, targetMask, onAnimationLoop, isAdditive);\n returnedAnimatable.weight = weight;\n return returnedAnimatable;\n };\n Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio = 1.0, onAnimationEnd, animatable, stopCurrent = true, targetMask, onAnimationLoop, isAdditive = false) {\n if (from > to && speedRatio > 0) {\n speedRatio *= -1;\n }\n if (stopCurrent) {\n this.stopAnimation(target, undefined, targetMask);\n }\n if (!animatable) {\n animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, undefined, onAnimationLoop, isAdditive);\n }\n const shouldRunTargetAnimations = targetMask ? targetMask(target) : true;\n // Local animations\n if (target.animations && shouldRunTargetAnimations) {\n animatable.appendAnimations(target, target.animations);\n }\n // Children animations\n if (target.getAnimatables) {\n const animatables = target.getAnimatables();\n for (let index = 0; index < animatables.length; index++) {\n this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, onAnimationLoop);\n }\n }\n animatable.reset();\n return animatable;\n };\n Scene.prototype.beginHierarchyAnimation = function (target, directDescendantsOnly, from, to, loop, speedRatio = 1.0, onAnimationEnd, animatable, stopCurrent = true, targetMask, onAnimationLoop, isAdditive = false) {\n const children = target.getDescendants(directDescendantsOnly);\n const result = [];\n result.push(this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, undefined, isAdditive));\n for (const child of children) {\n result.push(this.beginAnimation(child, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, undefined, isAdditive));\n }\n return result;\n };\n Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive = false) {\n if (speedRatio === undefined) {\n speedRatio = 1.0;\n }\n if (from > to && speedRatio > 0) {\n speedRatio *= -1;\n }\n else if (to > from && speedRatio < 0) {\n const temp = to;\n to = from;\n from = temp;\n }\n const animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations, onAnimationLoop, isAdditive);\n return animatable;\n };\n Scene.prototype.beginDirectHierarchyAnimation = function (target, directDescendantsOnly, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive = false) {\n const children = target.getDescendants(directDescendantsOnly);\n const result = [];\n result.push(this.beginDirectAnimation(target, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive));\n for (const child of children) {\n result.push(this.beginDirectAnimation(child, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive));\n }\n return result;\n };\n Scene.prototype.getAnimatableByTarget = function (target) {\n for (let index = 0; index < this._activeAnimatables.length; index++) {\n if (this._activeAnimatables[index].target === target) {\n return this._activeAnimatables[index];\n }\n }\n return null;\n };\n Scene.prototype.getAllAnimatablesByTarget = function (target) {\n const result = [];\n for (let index = 0; index < this._activeAnimatables.length; index++) {\n if (this._activeAnimatables[index].target === target) {\n result.push(this._activeAnimatables[index]);\n }\n }\n return result;\n };\n /**\n * Will stop the animation of the given target\n * @param target - the target\n * @param animationName - the name of the animation to stop (all animations will be stopped if both this and targetMask are empty)\n * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)\n */\n Scene.prototype.stopAnimation = function (target, animationName, targetMask) {\n const animatables = this.getAllAnimatablesByTarget(target);\n for (const animatable of animatables) {\n animatable.stop(animationName, targetMask);\n }\n };\n /**\n * Stops and removes all animations that have been applied to the scene\n */\n Scene.prototype.stopAllAnimations = function () {\n if (this._activeAnimatables) {\n for (let i = 0; i < this._activeAnimatables.length; i++) {\n this._activeAnimatables[i].stop(undefined, undefined, true);\n }\n this._activeAnimatables.length = 0;\n }\n for (const group of this.animationGroups) {\n group.stop();\n }\n };\n Scene.prototype._registerTargetForLateAnimationBinding = function (runtimeAnimation, originalValue) {\n const target = runtimeAnimation.target;\n this._registeredForLateAnimationBindings.pushNoDuplicate(target);\n if (!target._lateAnimationHolders) {\n target._lateAnimationHolders = {};\n }\n if (!target._lateAnimationHolders[runtimeAnimation.targetPath]) {\n target._lateAnimationHolders[runtimeAnimation.targetPath] = {\n totalWeight: 0,\n totalAdditiveWeight: 0,\n animations: [],\n additiveAnimations: [],\n originalValue: originalValue,\n };\n }\n if (runtimeAnimation.isAdditive) {\n target._lateAnimationHolders[runtimeAnimation.targetPath].additiveAnimations.push(runtimeAnimation);\n target._lateAnimationHolders[runtimeAnimation.targetPath].totalAdditiveWeight += runtimeAnimation.weight;\n }\n else {\n target._lateAnimationHolders[runtimeAnimation.targetPath].animations.push(runtimeAnimation);\n target._lateAnimationHolders[runtimeAnimation.targetPath].totalWeight += runtimeAnimation.weight;\n }\n };\n Scene.prototype._processLateAnimationBindingsForMatrices = function (holder) {\n if (holder.totalWeight === 0 && holder.totalAdditiveWeight === 0) {\n return holder.originalValue;\n }\n let normalizer = 1.0;\n const finalPosition = TmpVectors.Vector3[0];\n const finalScaling = TmpVectors.Vector3[1];\n const finalQuaternion = TmpVectors.Quaternion[0];\n let startIndex = 0;\n const originalAnimation = holder.animations[0];\n const originalValue = holder.originalValue;\n let scale = 1;\n let skipOverride = false;\n if (holder.totalWeight < 1.0) {\n // We need to mix the original value in\n scale = 1.0 - holder.totalWeight;\n originalValue.decompose(finalScaling, finalQuaternion, finalPosition);\n }\n else {\n startIndex = 1;\n // We need to normalize the weights\n normalizer = holder.totalWeight;\n scale = originalAnimation.weight / normalizer;\n if (scale == 1) {\n if (holder.totalAdditiveWeight) {\n skipOverride = true;\n }\n else {\n return originalAnimation.currentValue;\n }\n }\n originalAnimation.currentValue.decompose(finalScaling, finalQuaternion, finalPosition);\n }\n // Add up the override animations\n if (!skipOverride) {\n finalScaling.scaleInPlace(scale);\n finalPosition.scaleInPlace(scale);\n finalQuaternion.scaleInPlace(scale);\n for (let animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {\n const runtimeAnimation = holder.animations[animIndex];\n if (runtimeAnimation.weight === 0) {\n continue;\n }\n scale = runtimeAnimation.weight / normalizer;\n const currentPosition = TmpVectors.Vector3[2];\n const currentScaling = TmpVectors.Vector3[3];\n const currentQuaternion = TmpVectors.Quaternion[1];\n runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);\n currentScaling.scaleAndAddToRef(scale, finalScaling);\n currentQuaternion.scaleAndAddToRef(Quaternion.Dot(finalQuaternion, currentQuaternion) > 0 ? scale : -scale, finalQuaternion);\n currentPosition.scaleAndAddToRef(scale, finalPosition);\n }\n finalQuaternion.normalize();\n }\n // Add up the additive animations\n for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {\n const runtimeAnimation = holder.additiveAnimations[animIndex];\n if (runtimeAnimation.weight === 0) {\n continue;\n }\n const currentPosition = TmpVectors.Vector3[2];\n const currentScaling = TmpVectors.Vector3[3];\n const currentQuaternion = TmpVectors.Quaternion[1];\n runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);\n currentScaling.multiplyToRef(finalScaling, currentScaling);\n Vector3.LerpToRef(finalScaling, currentScaling, runtimeAnimation.weight, finalScaling);\n finalQuaternion.multiplyToRef(currentQuaternion, currentQuaternion);\n Quaternion.SlerpToRef(finalQuaternion, currentQuaternion, runtimeAnimation.weight, finalQuaternion);\n currentPosition.scaleAndAddToRef(runtimeAnimation.weight, finalPosition);\n }\n const workValue = originalAnimation ? originalAnimation._animationState.workValue : TmpVectors.Matrix[0].clone();\n Matrix.ComposeToRef(finalScaling, finalQuaternion, finalPosition, workValue);\n return workValue;\n };\n Scene.prototype._processLateAnimationBindingsForQuaternions = function (holder, refQuaternion) {\n if (holder.totalWeight === 0 && holder.totalAdditiveWeight === 0) {\n return refQuaternion;\n }\n const originalAnimation = holder.animations[0];\n const originalValue = holder.originalValue;\n let cumulativeQuaternion = refQuaternion;\n if (holder.totalWeight === 0 && holder.totalAdditiveWeight > 0) {\n cumulativeQuaternion.copyFrom(originalValue);\n }\n else if (holder.animations.length === 1) {\n Quaternion.SlerpToRef(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight), cumulativeQuaternion);\n if (holder.totalAdditiveWeight === 0) {\n return cumulativeQuaternion;\n }\n }\n else if (holder.animations.length > 1) {\n // Add up the override animations\n let normalizer = 1.0;\n let quaternions;\n let weights;\n if (holder.totalWeight < 1.0) {\n const scale = 1.0 - holder.totalWeight;\n quaternions = [];\n weights = [];\n quaternions.push(originalValue);\n weights.push(scale);\n }\n else {\n if (holder.animations.length === 2) {\n // Slerp as soon as we can\n Quaternion.SlerpToRef(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight, refQuaternion);\n if (holder.totalAdditiveWeight === 0) {\n return refQuaternion;\n }\n }\n quaternions = [];\n weights = [];\n normalizer = holder.totalWeight;\n }\n for (let animIndex = 0; animIndex < holder.animations.length; animIndex++) {\n const runtimeAnimation = holder.animations[animIndex];\n quaternions.push(runtimeAnimation.currentValue);\n weights.push(runtimeAnimation.weight / normalizer);\n }\n // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions\n let cumulativeAmount = 0;\n for (let index = 0; index < quaternions.length;) {\n if (!index) {\n Quaternion.SlerpToRef(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]), refQuaternion);\n cumulativeQuaternion = refQuaternion;\n cumulativeAmount = weights[index] + weights[index + 1];\n index += 2;\n continue;\n }\n cumulativeAmount += weights[index];\n Quaternion.SlerpToRef(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount, cumulativeQuaternion);\n index++;\n }\n }\n // Add up the additive animations\n for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {\n const runtimeAnimation = holder.additiveAnimations[animIndex];\n if (runtimeAnimation.weight === 0) {\n continue;\n }\n cumulativeQuaternion.multiplyToRef(runtimeAnimation.currentValue, TmpVectors.Quaternion[0]);\n Quaternion.SlerpToRef(cumulativeQuaternion, TmpVectors.Quaternion[0], runtimeAnimation.weight, cumulativeQuaternion);\n }\n return cumulativeQuaternion;\n };\n Scene.prototype._processLateAnimationBindings = function () {\n if (!this._registeredForLateAnimationBindings.length) {\n return;\n }\n for (let index = 0; index < this._registeredForLateAnimationBindings.length; index++) {\n const target = this._registeredForLateAnimationBindings.data[index];\n for (const path in target._lateAnimationHolders) {\n const holder = target._lateAnimationHolders[path];\n const originalAnimation = holder.animations[0];\n const originalValue = holder.originalValue;\n if (originalValue === undefined || originalValue === null) {\n continue;\n }\n const matrixDecomposeMode = Animation.AllowMatrixDecomposeForInterpolation && originalValue.m; // ie. data is matrix\n let finalValue = target[path];\n if (matrixDecomposeMode) {\n finalValue = this._processLateAnimationBindingsForMatrices(holder);\n }\n else {\n const quaternionMode = originalValue.w !== undefined;\n if (quaternionMode) {\n finalValue = this._processLateAnimationBindingsForQuaternions(holder, finalValue || Quaternion.Identity());\n }\n else {\n let startIndex = 0;\n let normalizer = 1.0;\n if (holder.totalWeight < 1.0) {\n // We need to mix the original value in\n if (originalAnimation && originalValue.scale) {\n finalValue = originalValue.scale(1.0 - holder.totalWeight);\n }\n else if (originalAnimation) {\n finalValue = originalValue * (1.0 - holder.totalWeight);\n }\n else if (originalValue.clone) {\n finalValue = originalValue.clone();\n }\n else {\n finalValue = originalValue;\n }\n }\n else if (originalAnimation) {\n // We need to normalize the weights\n normalizer = holder.totalWeight;\n const scale = originalAnimation.weight / normalizer;\n if (scale !== 1) {\n if (originalAnimation.currentValue.scale) {\n finalValue = originalAnimation.currentValue.scale(scale);\n }\n else {\n finalValue = originalAnimation.currentValue * scale;\n }\n }\n else {\n finalValue = originalAnimation.currentValue;\n }\n startIndex = 1;\n }\n // Add up the override animations\n for (let animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {\n const runtimeAnimation = holder.animations[animIndex];\n const scale = runtimeAnimation.weight / normalizer;\n if (!scale) {\n continue;\n }\n else if (runtimeAnimation.currentValue.scaleAndAddToRef) {\n runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);\n }\n else {\n finalValue += runtimeAnimation.currentValue * scale;\n }\n }\n // Add up the additive animations\n for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {\n const runtimeAnimation = holder.additiveAnimations[animIndex];\n const scale = runtimeAnimation.weight;\n if (!scale) {\n continue;\n }\n else if (runtimeAnimation.currentValue.scaleAndAddToRef) {\n runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);\n }\n else {\n finalValue += runtimeAnimation.currentValue * scale;\n }\n }\n }\n }\n target[path] = finalValue;\n }\n target._lateAnimationHolders = {};\n }\n this._registeredForLateAnimationBindings.reset();\n };\n Bone.prototype.copyAnimationRange = function (source, rangeName, frameOffset, rescaleAsRequired = false, skelDimensionsRatio = null) {\n // all animation may be coming from a library skeleton, so may need to create animation\n if (this.animations.length === 0) {\n this.animations.push(new Animation(this.name, \"_matrix\", source.animations[0].framePerSecond, Animation.ANIMATIONTYPE_MATRIX, 0));\n this.animations[0].setKeys([]);\n }\n // get animation info / verify there is such a range from the source bone\n const sourceRange = source.animations[0].getRange(rangeName);\n if (!sourceRange) {\n return false;\n }\n const from = sourceRange.from;\n const to = sourceRange.to;\n const sourceKeys = source.animations[0].getKeys();\n // rescaling prep\n const sourceBoneLength = source.length;\n const sourceParent = source.getParent();\n const parent = this.getParent();\n const parentScalingReqd = rescaleAsRequired && sourceParent && sourceBoneLength && this.length && sourceBoneLength !== this.length;\n const parentRatio = parentScalingReqd && parent && sourceParent ? parent.length / sourceParent.length : 1;\n const dimensionsScalingReqd = rescaleAsRequired && !parent && skelDimensionsRatio && (skelDimensionsRatio.x !== 1 || skelDimensionsRatio.y !== 1 || skelDimensionsRatio.z !== 1);\n const destKeys = this.animations[0].getKeys();\n // loop vars declaration\n let orig;\n let origTranslation;\n let mat;\n for (let key = 0, nKeys = sourceKeys.length; key < nKeys; key++) {\n orig = sourceKeys[key];\n if (orig.frame >= from && orig.frame <= to) {\n if (rescaleAsRequired) {\n mat = orig.value.clone();\n // scale based on parent ratio, when bone has parent\n if (parentScalingReqd) {\n origTranslation = mat.getTranslation();\n mat.setTranslation(origTranslation.scaleInPlace(parentRatio));\n // scale based on skeleton dimension ratio when root bone, and value is passed\n }\n else if (dimensionsScalingReqd && skelDimensionsRatio) {\n origTranslation = mat.getTranslation();\n mat.setTranslation(origTranslation.multiplyInPlace(skelDimensionsRatio));\n // use original when root bone, and no data for skelDimensionsRatio\n }\n else {\n mat = orig.value;\n }\n }\n else {\n mat = orig.value;\n }\n destKeys.push({ frame: orig.frame + frameOffset, value: mat });\n }\n }\n this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);\n return true;\n };\n\n /**\n * Wrapper over subclasses of XRLayer.\n * @internal\n */\n class WebXRLayerWrapper {\n /**\n * Check if fixed foveation is supported on this device\n */\n get isFixedFoveationSupported() {\n return this.layerType == \"XRWebGLLayer\" && typeof this.layer.fixedFoveation == \"number\";\n }\n /**\n * Get the fixed foveation currently set, as specified by the webxr specs\n * If this returns null, then fixed foveation is not supported\n */\n get fixedFoveation() {\n if (this.isFixedFoveationSupported) {\n return this.layer.fixedFoveation;\n }\n return null;\n }\n /**\n * Set the fixed foveation to the specified value, as specified by the webxr specs\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\n */\n set fixedFoveation(value) {\n if (this.isFixedFoveationSupported) {\n const val = Math.max(0, Math.min(1, value || 0));\n this.layer.fixedFoveation = val;\n }\n }\n constructor(\n /** The width of the layer's framebuffer. */\n getWidth, \n /** The height of the layer's framebuffer. */\n getHeight, \n /** The XR layer that this WebXRLayerWrapper wraps. */\n layer, \n /** The type of XR layer that is being wrapped. */\n layerType, \n /** Create a render target provider for the wrapped layer. */\n createRenderTargetTextureProvider) {\n this.getWidth = getWidth;\n this.getHeight = getHeight;\n this.layer = layer;\n this.layerType = layerType;\n this.createRenderTargetTextureProvider = createRenderTargetTextureProvider;\n }\n }\n\n /**\n * Provides render target textures and other important rendering information for a given XRLayer.\n * @internal\n */\n class WebXRLayerRenderTargetTextureProvider {\n constructor(_scene, layerWrapper) {\n this._scene = _scene;\n this.layerWrapper = layerWrapper;\n this._renderTargetTextures = new Array();\n this._engine = _scene.getEngine();\n }\n _createInternalTexture(textureSize, texture) {\n const internalTexture = new InternalTexture(this._engine, InternalTextureSource.Unknown, true);\n internalTexture.width = textureSize.width;\n internalTexture.height = textureSize.height;\n internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, this._engine._gl);\n internalTexture.isReady = true;\n return internalTexture;\n }\n _createRenderTargetTexture(width, height, framebuffer, colorTexture, depthStencilTexture, multiview) {\n if (!this._engine) {\n throw new Error(\"Engine is disposed\");\n }\n const textureSize = { width, height };\n // Create render target texture from the internal texture\n const renderTargetTexture = multiview ? new MultiviewRenderTarget(this._scene, textureSize) : new RenderTargetTexture(\"XR renderTargetTexture\", textureSize, this._scene);\n const renderTargetWrapper = renderTargetTexture.renderTarget;\n renderTargetWrapper._samples = renderTargetTexture.samples;\n // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers\n if (framebuffer || !colorTexture) {\n renderTargetWrapper._framebuffer = framebuffer;\n }\n // Create internal texture\n if (colorTexture) {\n if (multiview) {\n renderTargetWrapper._colorTextureArray = colorTexture;\n }\n else {\n const internalTexture = this._createInternalTexture(textureSize, colorTexture);\n renderTargetWrapper.setTexture(internalTexture, 0);\n renderTargetTexture._texture = internalTexture;\n }\n }\n if (depthStencilTexture) {\n if (multiview) {\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\n }\n else {\n renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture);\n }\n }\n renderTargetTexture.disableRescaling();\n // Firefox reality fails if skipInitialClear is set to true, so make sure only modern XR implementations set it.\n if (typeof XRWebGLBinding !== \"undefined\") {\n // WebXR pre-clears textures\n renderTargetTexture.skipInitialClear = true;\n }\n this._renderTargetTextures.push(renderTargetTexture);\n return renderTargetTexture;\n }\n _destroyRenderTargetTexture(renderTargetTexture) {\n this._renderTargetTextures.splice(this._renderTargetTextures.indexOf(renderTargetTexture), 1);\n renderTargetTexture.dispose();\n }\n getFramebufferDimensions() {\n return this._framebufferDimensions;\n }\n dispose() {\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\n this._renderTargetTextures.length = 0;\n }\n }\n\n /**\n * Wraps xr webgl layers.\n * @internal\n */\n class WebXRWebGLLayerWrapper extends WebXRLayerWrapper {\n /**\n * @param layer is the layer to be wrapped.\n * @returns a new WebXRLayerWrapper wrapping the provided XRWebGLLayer.\n */\n constructor(layer) {\n super(() => layer.framebufferWidth, () => layer.framebufferHeight, layer, \"XRWebGLLayer\", (sessionManager) => new WebXRWebGLLayerRenderTargetTextureProvider(sessionManager.scene, this));\n this.layer = layer;\n }\n }\n /**\n * Provides render target textures and other important rendering information for a given XRWebGLLayer.\n * @internal\n */\n class WebXRWebGLLayerRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\n constructor(scene, layerWrapper) {\n super(scene, layerWrapper);\n this.layerWrapper = layerWrapper;\n this._layer = layerWrapper.layer;\n this._framebufferDimensions = {\n framebufferWidth: this._layer.framebufferWidth,\n framebufferHeight: this._layer.framebufferHeight,\n };\n }\n trySetViewportForView(viewport, view) {\n const xrViewport = this._layer.getViewport(view);\n if (!xrViewport) {\n return false;\n }\n const framebufferWidth = this._framebufferDimensions.framebufferWidth;\n const framebufferHeight = this._framebufferDimensions.framebufferHeight;\n viewport.x = xrViewport.x / framebufferWidth;\n viewport.y = xrViewport.y / framebufferHeight;\n viewport.width = xrViewport.width / framebufferWidth;\n viewport.height = xrViewport.height / framebufferHeight;\n return true;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getRenderTargetTextureForEye(eye) {\n const layerWidth = this._layer.framebufferWidth;\n const layerHeight = this._layer.framebufferHeight;\n const framebuffer = this._layer.framebuffer;\n if (!this._rtt ||\n layerWidth !== this._framebufferDimensions.framebufferWidth ||\n layerHeight !== this._framebufferDimensions.framebufferHeight ||\n framebuffer !== this._framebuffer) {\n this._rtt = this._createRenderTargetTexture(layerWidth, layerHeight, framebuffer);\n this._framebufferDimensions.framebufferWidth = layerWidth;\n this._framebufferDimensions.framebufferHeight = layerHeight;\n this._framebuffer = framebuffer;\n }\n return this._rtt;\n }\n getRenderTargetTextureForView(view) {\n return this.getRenderTargetTextureForEye(view.eye);\n }\n }\n\n /**\n * Configuration object for WebXR output canvas\n */\n class WebXRManagedOutputCanvasOptions {\n /**\n * Get the default values of the configuration object\n * @param engine defines the engine to use (can be null)\n * @returns default values of this configuration object\n */\n static GetDefaults(engine) {\n const defaults = new WebXRManagedOutputCanvasOptions();\n defaults.canvasOptions = {\n antialias: true,\n depth: true,\n stencil: engine ? engine.isStencilEnable : true,\n alpha: true,\n framebufferScaleFactor: 1,\n };\n defaults.newCanvasCssStyle = \"position:absolute; bottom:0px;right:0px;z-index:10;width:90%;height:100%;background-color: #000000;\";\n return defaults;\n }\n }\n /**\n * Creates a canvas that is added/removed from the webpage when entering/exiting XR\n */\n class WebXRManagedOutputCanvas {\n /**\n * Initializes the canvas to be added/removed upon entering/exiting xr\n * @param _xrSessionManager The XR Session manager\n * @param _options optional configuration for this canvas output. defaults will be used if not provided\n */\n constructor(_xrSessionManager, _options = WebXRManagedOutputCanvasOptions.GetDefaults()) {\n this._options = _options;\n this._canvas = null;\n this._engine = null;\n /**\n * xr layer for the canvas\n */\n this.xrLayer = null;\n this._xrLayerWrapper = null;\n /**\n * Observers registered here will be triggered when the xr layer was initialized\n */\n this.onXRLayerInitObservable = new Observable$1();\n this._engine = _xrSessionManager.scene.getEngine();\n this._engine.onDisposeObservable.addOnce(() => {\n this._engine = null;\n });\n if (!_options.canvasElement) {\n const canvas = document.createElement(\"canvas\");\n canvas.style.cssText = this._options.newCanvasCssStyle || \"position:absolute; bottom:0px;right:0px;\";\n this._setManagedOutputCanvas(canvas);\n }\n else {\n this._setManagedOutputCanvas(_options.canvasElement);\n }\n _xrSessionManager.onXRSessionInit.add(() => {\n this._addCanvas();\n });\n _xrSessionManager.onXRSessionEnded.add(() => {\n this._removeCanvas();\n });\n }\n /**\n * Disposes of the object\n */\n dispose() {\n this._removeCanvas();\n this._setManagedOutputCanvas(null);\n }\n /**\n * Initializes a XRWebGLLayer to be used as the session's baseLayer.\n * @param xrSession xr session\n * @returns a promise that will resolve once the XR Layer has been created\n */\n async initializeXRLayerAsync(xrSession) {\n const createLayer = () => {\n this.xrLayer = new XRWebGLLayer(xrSession, this.canvasContext, this._options.canvasOptions);\n this._xrLayerWrapper = new WebXRWebGLLayerWrapper(this.xrLayer);\n this.onXRLayerInitObservable.notifyObservers(this.xrLayer);\n return this.xrLayer;\n };\n // support canvases without makeXRCompatible\n if (!this.canvasContext.makeXRCompatible) {\n return Promise.resolve(createLayer());\n }\n return this.canvasContext\n .makeXRCompatible()\n .then(\n // catch any error and continue. When using the emulator is throws this error for no apparent reason.\n () => { }, () => {\n // log the error, continue nonetheless!\n Tools.Warn(\"Error executing makeXRCompatible. This does not mean that the session will work incorrectly.\");\n })\n .then(() => {\n return createLayer();\n });\n }\n _addCanvas() {\n if (this._canvas && this._engine && this._canvas !== this._engine.getRenderingCanvas()) {\n document.body.appendChild(this._canvas);\n }\n if (this.xrLayer) {\n this._setCanvasSize(true);\n }\n else {\n this.onXRLayerInitObservable.addOnce(() => {\n this._setCanvasSize(true);\n });\n }\n }\n _removeCanvas() {\n if (this._canvas && this._engine && document.body.contains(this._canvas) && this._canvas !== this._engine.getRenderingCanvas()) {\n document.body.removeChild(this._canvas);\n }\n this._setCanvasSize(false);\n }\n _setCanvasSize(init = true, xrLayer = this._xrLayerWrapper) {\n if (!this._canvas || !this._engine) {\n return;\n }\n if (init) {\n if (xrLayer) {\n if (this._canvas !== this._engine.getRenderingCanvas()) {\n this._canvas.style.width = xrLayer.getWidth() + \"px\";\n this._canvas.style.height = xrLayer.getHeight() + \"px\";\n }\n else {\n this._engine.setSize(xrLayer.getWidth(), xrLayer.getHeight());\n }\n }\n }\n else {\n if (this._originalCanvasSize) {\n if (this._canvas !== this._engine.getRenderingCanvas()) {\n this._canvas.style.width = this._originalCanvasSize.width + \"px\";\n this._canvas.style.height = this._originalCanvasSize.height + \"px\";\n }\n else {\n this._engine.setSize(this._originalCanvasSize.width, this._originalCanvasSize.height);\n }\n }\n }\n }\n _setManagedOutputCanvas(canvas) {\n this._removeCanvas();\n if (!canvas) {\n this._canvas = null;\n this.canvasContext = null;\n }\n else {\n this._originalCanvasSize = {\n width: canvas.offsetWidth,\n height: canvas.offsetHeight,\n };\n this._canvas = canvas;\n this.canvasContext = this._canvas.getContext(\"webgl2\");\n if (!this.canvasContext) {\n this.canvasContext = this._canvas.getContext(\"webgl\");\n }\n }\n }\n }\n\n /**\n * Wraps XRWebGLLayer's created by Babylon Native.\n * @internal\n */\n class NativeXRLayerWrapper extends WebXRLayerWrapper {\n constructor(layer) {\n super(() => layer.framebufferWidth, () => layer.framebufferHeight, layer, \"XRWebGLLayer\", (sessionManager) => new NativeXRLayerRenderTargetTextureProvider(sessionManager, this));\n this.layer = layer;\n }\n }\n /**\n * Provides render target textures for layers created by Babylon Native.\n * @internal\n */\n class NativeXRLayerRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\n constructor(sessionManager, layerWrapper) {\n super(sessionManager.scene, layerWrapper);\n this.layerWrapper = layerWrapper;\n this._nativeRTTProvider = navigator.xr.getNativeRenderTargetProvider(sessionManager.session, this._createRenderTargetTexture.bind(this), this._destroyRenderTargetTexture.bind(this));\n this._nativeLayer = layerWrapper.layer;\n }\n trySetViewportForView(viewport) {\n viewport.x = 0;\n viewport.y = 0;\n viewport.width = 1;\n viewport.height = 1;\n return true;\n }\n getRenderTargetTextureForEye(eye) {\n // TODO (rgerd): Update the contract on the BabylonNative side to call this \"getRenderTargetTextureForEye\"\n return this._nativeRTTProvider.getRenderTargetForEye(eye);\n }\n getRenderTargetTextureForView(view) {\n return this._nativeRTTProvider.getRenderTargetForEye(view.eye);\n }\n getFramebufferDimensions() {\n return {\n framebufferWidth: this._nativeLayer.framebufferWidth,\n framebufferHeight: this._nativeLayer.framebufferHeight,\n };\n }\n }\n /**\n * Creates the xr layer that will be used as the xr session's base layer.\n * @internal\n */\n class NativeXRRenderTarget {\n constructor(_xrSessionManager) {\n this._nativeRenderTarget = navigator.xr.getWebXRRenderTarget(_xrSessionManager.scene.getEngine());\n }\n async initializeXRLayerAsync(xrSession) {\n await this._nativeRenderTarget.initializeXRLayerAsync(xrSession);\n this.xrLayer = this._nativeRenderTarget.xrLayer;\n return this.xrLayer;\n }\n dispose() {\n /* empty */\n }\n }\n\n /**\n * Manages an XRSession to work with Babylon's engine\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRSessionManagers\n */\n class WebXRSessionManager {\n /**\n * Constructs a WebXRSessionManager, this must be initialized within a user action before usage\n * @param scene The scene which the session should be created for\n */\n constructor(\n /** The scene which the session should be created for */\n scene) {\n this.scene = scene;\n /** WebXR timestamp updated every frame */\n this.currentTimestamp = -1;\n /**\n * Used just in case of a failure to initialize an immersive session.\n * The viewer reference space is compensated using this height, creating a kind of \"viewer-floor\" reference space\n */\n this.defaultHeightCompensation = 1.7;\n /**\n * Fires every time a new xrFrame arrives which can be used to update the camera\n */\n this.onXRFrameObservable = new Observable$1();\n /**\n * Fires when the reference space changed\n */\n this.onXRReferenceSpaceChanged = new Observable$1();\n /**\n * Fires when the xr session is ended either by the device or manually done\n */\n this.onXRSessionEnded = new Observable$1();\n /**\n * Fires when the xr session is initialized: right after requestSession was called and returned with a successful result\n */\n this.onXRSessionInit = new Observable$1();\n /**\n * Are we currently in the XR loop?\n */\n this.inXRFrameLoop = false;\n /**\n * Are we in an XR session?\n */\n this.inXRSession = false;\n this._engine = scene.getEngine();\n this._onEngineDisposedObserver = this._engine.onDisposeObservable.addOnce(() => {\n this._engine = null;\n });\n scene.onDisposeObservable.addOnce(() => {\n this.dispose();\n });\n }\n /**\n * The current reference space used in this session. This reference space can constantly change!\n * It is mainly used to offset the camera's position.\n */\n get referenceSpace() {\n return this._referenceSpace;\n }\n /**\n * Set a new reference space and triggers the observable\n */\n set referenceSpace(newReferenceSpace) {\n this._referenceSpace = newReferenceSpace;\n this.onXRReferenceSpaceChanged.notifyObservers(this._referenceSpace);\n }\n /**\n * The mode for the managed XR session\n */\n get sessionMode() {\n return this._sessionMode;\n }\n /**\n * Disposes of the session manager\n * This should be called explicitly by the dev, if required.\n */\n dispose() {\n var _a;\n // disposing without leaving XR? Exit XR first\n if (this.inXRSession) {\n this.exitXRAsync();\n }\n this.onXRFrameObservable.clear();\n this.onXRSessionEnded.clear();\n this.onXRReferenceSpaceChanged.clear();\n this.onXRSessionInit.clear();\n (_a = this._engine) === null || _a === void 0 ? void 0 : _a.onDisposeObservable.remove(this._onEngineDisposedObserver);\n this._engine = null;\n }\n /**\n * Stops the xrSession and restores the render loop\n * @returns Promise which resolves after it exits XR\n */\n exitXRAsync() {\n if (this.session && this.inXRSession) {\n this.inXRSession = false;\n return this.session.end().catch(() => {\n Logger.Warn(\"Could not end XR session.\");\n });\n }\n return Promise.resolve();\n }\n /**\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\n * In the event of a failure, the supplied viewport is not updated.\n * @param viewport the viewport to which the view will be rendered\n * @param view the view for which to set the viewport\n * @returns whether the operation was successful\n */\n trySetViewportForView(viewport, view) {\n var _a;\n return ((_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.trySetViewportForView(viewport, view)) || false;\n }\n /**\n * Gets the correct render target texture to be rendered this frame for this eye\n * @param eye the eye for which to get the render target\n * @returns the render target for the specified eye or null if not available\n */\n getRenderTargetTextureForEye(eye) {\n var _a;\n return ((_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.getRenderTargetTextureForEye(eye)) || null;\n }\n /**\n * Gets the correct render target texture to be rendered this frame for this view\n * @param view the view for which to get the render target\n * @returns the render target for the specified view or null if not available\n */\n getRenderTargetTextureForView(view) {\n var _a;\n return ((_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.getRenderTargetTextureForView(view)) || null;\n }\n /**\n * Creates a WebXRRenderTarget object for the XR session\n * @param options optional options to provide when creating a new render target\n * @returns a WebXR render target to which the session can render\n */\n getWebXRRenderTarget(options) {\n const engine = this.scene.getEngine();\n if (this._xrNavigator.xr.native) {\n return new NativeXRRenderTarget(this);\n }\n else {\n options = options || WebXRManagedOutputCanvasOptions.GetDefaults(engine);\n options.canvasElement = options.canvasElement || engine.getRenderingCanvas() || undefined;\n return new WebXRManagedOutputCanvas(this, options);\n }\n }\n /**\n * Initializes the manager\n * After initialization enterXR can be called to start an XR session\n * @returns Promise which resolves after it is initialized\n */\n initializeAsync() {\n // Check if the browser supports webXR\n this._xrNavigator = navigator;\n if (!this._xrNavigator.xr) {\n return Promise.reject(\"WebXR not available\");\n }\n return Promise.resolve();\n }\n /**\n * Initializes an xr session\n * @param xrSessionMode mode to initialize\n * @param xrSessionInit defines optional and required values to pass to the session builder\n * @returns a promise which will resolve once the session has been initialized\n */\n initializeSessionAsync(xrSessionMode = \"immersive-vr\", xrSessionInit = {}) {\n return this._xrNavigator.xr.requestSession(xrSessionMode, xrSessionInit).then((session) => {\n this.session = session;\n this._sessionMode = xrSessionMode;\n this.onXRSessionInit.notifyObservers(session);\n this.inXRSession = true;\n // handle when the session is ended (By calling session.end or device ends its own session eg. pressing home button on phone)\n this.session.addEventListener(\"end\", () => {\n var _a;\n this.inXRSession = false;\n // Notify frame observers\n this.onXRSessionEnded.notifyObservers(null);\n if (this._engine) {\n // make sure dimensions object is restored\n this._engine.framebufferDimensionsObject = null;\n // Restore frame buffer to avoid clear on xr framebuffer after session end\n this._engine.restoreDefaultFramebuffer();\n // Need to restart render loop as after the session is ended the last request for new frame will never call callback\n this._engine.customAnimationFrameRequester = null;\n this._engine._renderLoop();\n }\n // Dispose render target textures.\n // Only dispose on native because we can't destroy opaque textures on browser.\n if (this.isNative) {\n (_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n this._baseLayerRTTProvider = null;\n this._baseLayerWrapper = null;\n }, { once: true });\n return this.session;\n });\n }\n /**\n * Checks if a session would be supported for the creation options specified\n * @param sessionMode session mode to check if supported eg. immersive-vr\n * @returns A Promise that resolves to true if supported and false if not\n */\n isSessionSupportedAsync(sessionMode) {\n return WebXRSessionManager.IsSessionSupportedAsync(sessionMode);\n }\n /**\n * Resets the reference space to the one started the session\n */\n resetReferenceSpace() {\n this.referenceSpace = this.baseReferenceSpace;\n }\n /**\n * Starts rendering to the xr layer\n */\n runXRRenderLoop() {\n var _a;\n if (!this.inXRSession || !this._engine) {\n return;\n }\n // Tell the engine's render loop to be driven by the xr session's refresh rate and provide xr pose information\n this._engine.customAnimationFrameRequester = {\n requestAnimationFrame: this.session.requestAnimationFrame.bind(this.session),\n renderFunction: (timestamp, xrFrame) => {\n var _a;\n if (!this.inXRSession || !this._engine) {\n return;\n }\n // Store the XR frame and timestamp in the session manager\n this.currentFrame = xrFrame;\n this.currentTimestamp = timestamp;\n if (xrFrame) {\n this.inXRFrameLoop = true;\n this._engine.framebufferDimensionsObject = ((_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.getFramebufferDimensions()) || null;\n this.onXRFrameObservable.notifyObservers(xrFrame);\n this._engine._renderLoop();\n this._engine.framebufferDimensionsObject = null;\n this.inXRFrameLoop = false;\n }\n },\n };\n this._engine.framebufferDimensionsObject = ((_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.getFramebufferDimensions()) || null;\n // Stop window's animation frame and trigger sessions animation frame\n if (typeof window !== \"undefined\" && window.cancelAnimationFrame) {\n window.cancelAnimationFrame(this._engine._frameHandler);\n }\n this._engine._renderLoop();\n }\n /**\n * Sets the reference space on the xr session\n * @param referenceSpaceType space to set\n * @returns a promise that will resolve once the reference space has been set\n */\n setReferenceSpaceTypeAsync(referenceSpaceType = \"local-floor\") {\n return this.session\n .requestReferenceSpace(referenceSpaceType)\n .then((referenceSpace) => {\n return referenceSpace;\n }, (rejectionReason) => {\n Logger.Error(\"XR.requestReferenceSpace failed for the following reason: \");\n Logger.Error(rejectionReason);\n Logger.Log('Defaulting to universally-supported \"viewer\" reference space type.');\n return this.session.requestReferenceSpace(\"viewer\").then((referenceSpace) => {\n const heightCompensation = new XRRigidTransform({ x: 0, y: -this.defaultHeightCompensation, z: 0 });\n return referenceSpace.getOffsetReferenceSpace(heightCompensation);\n }, (rejectionReason) => {\n Logger.Error(rejectionReason);\n throw 'XR initialization failed: required \"viewer\" reference space type not supported.';\n });\n })\n .then((referenceSpace) => {\n // create viewer reference space before setting the first reference space\n return this.session.requestReferenceSpace(\"viewer\").then((viewerReferenceSpace) => {\n this.viewerReferenceSpace = viewerReferenceSpace;\n return referenceSpace;\n });\n })\n .then((referenceSpace) => {\n // initialize the base and offset (currently the same)\n this.referenceSpace = this.baseReferenceSpace = referenceSpace;\n return this.referenceSpace;\n });\n }\n /**\n * Updates the render state of the session.\n * Note that this is deprecated in favor of WebXRSessionManager.updateRenderState().\n * @param state state to set\n * @returns a promise that resolves once the render state has been updated\n * @deprecated\n */\n updateRenderStateAsync(state) {\n return Promise.resolve(this.session.updateRenderState(state));\n }\n /**\n * @internal\n */\n _setBaseLayerWrapper(baseLayerWrapper) {\n var _a, _b;\n if (this.isNative) {\n (_a = this._baseLayerRTTProvider) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n this._baseLayerWrapper = baseLayerWrapper;\n this._baseLayerRTTProvider = ((_b = this._baseLayerWrapper) === null || _b === void 0 ? void 0 : _b.createRenderTargetTextureProvider(this)) || null;\n }\n /**\n * @internal\n */\n _getBaseLayerWrapper() {\n return this._baseLayerWrapper;\n }\n /**\n * Updates the render state of the session\n * @param state state to set\n */\n updateRenderState(state) {\n if (state.baseLayer) {\n this._setBaseLayerWrapper(this.isNative ? new NativeXRLayerWrapper(state.baseLayer) : new WebXRWebGLLayerWrapper(state.baseLayer));\n }\n this.session.updateRenderState(state);\n }\n /**\n * Returns a promise that resolves with a boolean indicating if the provided session mode is supported by this browser\n * @param sessionMode defines the session to test\n * @returns a promise with boolean as final value\n */\n static IsSessionSupportedAsync(sessionMode) {\n if (!navigator.xr) {\n return Promise.resolve(false);\n }\n // When the specs are final, remove supportsSession!\n const functionToUse = navigator.xr.isSessionSupported || navigator.xr.supportsSession;\n if (!functionToUse) {\n return Promise.resolve(false);\n }\n else {\n return functionToUse\n .call(navigator.xr, sessionMode)\n .then((result) => {\n const returnValue = typeof result === \"undefined\" ? true : result;\n return Promise.resolve(returnValue);\n })\n .catch((e) => {\n Logger.Warn(e);\n return Promise.resolve(false);\n });\n }\n }\n /**\n * Returns true if Babylon.js is using the BabylonNative backend, otherwise false\n */\n get isNative() {\n var _a;\n return (_a = this._xrNavigator.xr.native) !== null && _a !== void 0 ? _a : false;\n }\n /**\n * The current frame rate as reported by the device\n */\n get currentFrameRate() {\n var _a;\n return (_a = this.session) === null || _a === void 0 ? void 0 : _a.frameRate;\n }\n /**\n * A list of supported frame rates (only available in-session!\n */\n get supportedFrameRates() {\n var _a;\n return (_a = this.session) === null || _a === void 0 ? void 0 : _a.supportedFrameRates;\n }\n /**\n * Set the framerate of the session.\n * @param rate the new framerate. This value needs to be in the supportedFrameRates array\n * @returns a promise that resolves once the framerate has been set\n */\n updateTargetFrameRate(rate) {\n return this.session.updateTargetFrameRate(rate);\n }\n /**\n * Run a callback in the xr render loop\n * @param callback the callback to call when in XR Frame\n * @param ignoreIfNotInSession if no session is currently running, run it first thing on the next session\n */\n runInXRFrame(callback, ignoreIfNotInSession = true) {\n if (this.inXRFrameLoop) {\n callback();\n }\n else if (this.inXRSession || !ignoreIfNotInSession) {\n this.onXRFrameObservable.addOnce(callback);\n }\n }\n /**\n * Check if fixed foveation is supported on this device\n */\n get isFixedFoveationSupported() {\n var _a;\n return ((_a = this._baseLayerWrapper) === null || _a === void 0 ? void 0 : _a.isFixedFoveationSupported) || false;\n }\n /**\n * Get the fixed foveation currently set, as specified by the webxr specs\n * If this returns null, then fixed foveation is not supported\n */\n get fixedFoveation() {\n var _a;\n return ((_a = this._baseLayerWrapper) === null || _a === void 0 ? void 0 : _a.fixedFoveation) || null;\n }\n /**\n * Set the fixed foveation to the specified value, as specified by the webxr specs\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\n */\n set fixedFoveation(value) {\n const val = Math.max(0, Math.min(1, value || 0));\n if (this._baseLayerWrapper) {\n this._baseLayerWrapper.fixedFoveation = val;\n }\n }\n /**\n * Get the features enabled on the current session\n * This is only available in-session!\n * @see https://www.w3.org/TR/webxr/#dom-xrsession-enabledfeatures\n */\n get enabledFeatures() {\n var _a, _b;\n return (_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.enabledFeatures) !== null && _b !== void 0 ? _b : null;\n }\n }\n\n /**\n * States of the webXR experience\n */\n var WebXRState;\n (function (WebXRState) {\n /**\n * Transitioning to being in XR mode\n */\n WebXRState[WebXRState[\"ENTERING_XR\"] = 0] = \"ENTERING_XR\";\n /**\n * Transitioning to non XR mode\n */\n WebXRState[WebXRState[\"EXITING_XR\"] = 1] = \"EXITING_XR\";\n /**\n * In XR mode and presenting\n */\n WebXRState[WebXRState[\"IN_XR\"] = 2] = \"IN_XR\";\n /**\n * Not entered XR mode\n */\n WebXRState[WebXRState[\"NOT_IN_XR\"] = 3] = \"NOT_IN_XR\";\n })(WebXRState || (WebXRState = {}));\n /**\n * The state of the XR camera's tracking\n */\n var WebXRTrackingState;\n (function (WebXRTrackingState) {\n /**\n * No transformation received, device is not being tracked\n */\n WebXRTrackingState[WebXRTrackingState[\"NOT_TRACKING\"] = 0] = \"NOT_TRACKING\";\n /**\n * Tracking lost - using emulated position\n */\n WebXRTrackingState[WebXRTrackingState[\"TRACKING_LOST\"] = 1] = \"TRACKING_LOST\";\n /**\n * Transformation tracking works normally\n */\n WebXRTrackingState[WebXRTrackingState[\"TRACKING\"] = 2] = \"TRACKING\";\n })(WebXRTrackingState || (WebXRTrackingState = {}));\n\n /**\n * Creates the VertexData for a cylinder, cone or prism\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * height sets the height (y direction) of the cylinder, optional, default 2\n * * diameterTop sets the diameter of the top of the cone, overwrites diameter, optional, default diameter\n * * diameterBottom sets the diameter of the bottom of the cone, overwrites diameter, optional, default diameter\n * * diameter sets the diameter of the top and bottom of the cone, optional default 1\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\n * * subdivisions` the number of rings along the cylinder height, optional, default 1\n * * arc a number from 0 to 1, to create an unclosed cylinder based on the fraction of the circumference given by the arc value, optional, default 1\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * * hasRings when true makes each subdivision independently treated as a face for faceUV and faceColors, optional, default false\n * * enclose when true closes an open cylinder by adding extra flat faces between the height axis and vertical edges, think cut cake\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.height\n * @param options.diameterTop\n * @param options.diameterBottom\n * @param options.diameter\n * @param options.tessellation\n * @param options.subdivisions\n * @param options.arc\n * @param options.faceColors\n * @param options.faceUV\n * @param options.hasRings\n * @param options.enclose\n * @param options.cap\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the cylinder, cone or prism\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function CreateCylinderVertexData(options) {\n const height = options.height || 2;\n let diameterTop = options.diameterTop === 0 ? 0 : options.diameterTop || options.diameter || 1;\n let diameterBottom = options.diameterBottom === 0 ? 0 : options.diameterBottom || options.diameter || 1;\n diameterTop = diameterTop || 0.00001; // Prevent broken normals\n diameterBottom = diameterBottom || 0.00001; // Prevent broken normals\n const tessellation = (options.tessellation || 24) | 0;\n const subdivisions = (options.subdivisions || 1) | 0;\n const hasRings = options.hasRings ? true : false;\n const enclose = options.enclose ? true : false;\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.CAP_ALL;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const faceUV = options.faceUV || new Array(3);\n const faceColors = options.faceColors;\n // default face colors and UV if undefined\n const quadNb = arc !== 1 && enclose ? 2 : 0;\n const ringNb = hasRings ? subdivisions : 1;\n const surfaceNb = 2 + (1 + quadNb) * ringNb;\n let f;\n for (f = 0; f < surfaceNb; f++) {\n if (faceColors && faceColors[f] === undefined) {\n faceColors[f] = new Color4(1, 1, 1, 1);\n }\n }\n for (f = 0; f < surfaceNb; f++) {\n if (faceUV && faceUV[f] === undefined) {\n faceUV[f] = new Vector4(0, 0, 1, 1);\n }\n }\n const indices = new Array();\n const positions = new Array();\n const normals = new Array();\n const uvs = new Array();\n const colors = new Array();\n const angleStep = (Math.PI * 2 * arc) / tessellation;\n let angle;\n let h;\n let radius;\n const tan = (diameterBottom - diameterTop) / 2 / height;\n const ringVertex = Vector3.Zero();\n const ringNormal = Vector3.Zero();\n const ringFirstVertex = Vector3.Zero();\n const ringFirstNormal = Vector3.Zero();\n const quadNormal = Vector3.Zero();\n const Y = Axis.Y;\n // positions, normals, uvs\n let i;\n let j;\n let r;\n let ringIdx = 1;\n let s = 1; // surface index\n let cs = 0;\n let v = 0;\n for (i = 0; i <= subdivisions; i++) {\n h = i / subdivisions;\n radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;\n ringIdx = hasRings && i !== 0 && i !== subdivisions ? 2 : 1;\n for (r = 0; r < ringIdx; r++) {\n if (hasRings) {\n s += r;\n }\n if (enclose) {\n s += 2 * r;\n }\n for (j = 0; j <= tessellation; j++) {\n angle = j * angleStep;\n // position\n ringVertex.x = Math.cos(-angle) * radius;\n ringVertex.y = -height / 2 + h * height;\n ringVertex.z = Math.sin(-angle) * radius;\n // normal\n if (diameterTop === 0 && i === subdivisions) {\n // if no top cap, reuse former normals\n ringNormal.x = normals[normals.length - (tessellation + 1) * 3];\n ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];\n ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];\n }\n else {\n ringNormal.x = ringVertex.x;\n ringNormal.z = ringVertex.z;\n ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;\n ringNormal.normalize();\n }\n // keep first ring vertex values for enclose\n if (j === 0) {\n ringFirstVertex.copyFrom(ringVertex);\n ringFirstNormal.copyFrom(ringNormal);\n }\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\n normals.push(ringNormal.x, ringNormal.y, ringNormal.z);\n if (hasRings) {\n v = cs !== s ? faceUV[s].y : faceUV[s].w;\n }\n else {\n v = faceUV[s].y + (faceUV[s].w - faceUV[s].y) * h;\n }\n uvs.push(faceUV[s].x + ((faceUV[s].z - faceUV[s].x) * j) / tessellation, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n if (faceColors) {\n colors.push(faceColors[s].r, faceColors[s].g, faceColors[s].b, faceColors[s].a);\n }\n }\n // if enclose, add four vertices and their dedicated normals\n if (arc !== 1 && enclose) {\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\n positions.push(0, ringVertex.y, 0);\n positions.push(0, ringVertex.y, 0);\n positions.push(ringFirstVertex.x, ringFirstVertex.y, ringFirstVertex.z);\n Vector3.CrossToRef(Y, ringNormal, quadNormal);\n quadNormal.normalize();\n normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);\n Vector3.CrossToRef(ringFirstNormal, Y, quadNormal);\n quadNormal.normalize();\n normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);\n if (hasRings) {\n v = cs !== s ? faceUV[s + 1].y : faceUV[s + 1].w;\n }\n else {\n v = faceUV[s + 1].y + (faceUV[s + 1].w - faceUV[s + 1].y) * h;\n }\n uvs.push(faceUV[s + 1].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n uvs.push(faceUV[s + 1].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n if (hasRings) {\n v = cs !== s ? faceUV[s + 2].y : faceUV[s + 2].w;\n }\n else {\n v = faceUV[s + 2].y + (faceUV[s + 2].w - faceUV[s + 2].y) * h;\n }\n uvs.push(faceUV[s + 2].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n uvs.push(faceUV[s + 2].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n if (faceColors) {\n colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);\n colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);\n colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);\n colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);\n }\n }\n if (cs !== s) {\n cs = s;\n }\n }\n }\n // indices\n const e = arc !== 1 && enclose ? tessellation + 4 : tessellation; // correction of number of iteration if enclose\n i = 0;\n for (s = 0; s < subdivisions; s++) {\n let i0 = 0;\n let i1 = 0;\n let i2 = 0;\n let i3 = 0;\n for (j = 0; j < tessellation; j++) {\n i0 = i * (e + 1) + j;\n i1 = (i + 1) * (e + 1) + j;\n i2 = i * (e + 1) + (j + 1);\n i3 = (i + 1) * (e + 1) + (j + 1);\n indices.push(i0, i1, i2);\n indices.push(i3, i2, i1);\n }\n if (arc !== 1 && enclose) {\n // if enclose, add two quads\n indices.push(i0 + 2, i1 + 2, i2 + 2);\n indices.push(i3 + 2, i2 + 2, i1 + 2);\n indices.push(i0 + 4, i1 + 4, i2 + 4);\n indices.push(i3 + 4, i2 + 4, i1 + 4);\n }\n i = hasRings ? i + 2 : i + 1;\n }\n // Caps\n const createCylinderCap = (isTop) => {\n const radius = isTop ? diameterTop / 2 : diameterBottom / 2;\n if (radius === 0) {\n return;\n }\n // Cap positions, normals & uvs\n let angle;\n let circleVector;\n let i;\n const u = isTop ? faceUV[surfaceNb - 1] : faceUV[0];\n let c = null;\n if (faceColors) {\n c = isTop ? faceColors[surfaceNb - 1] : faceColors[0];\n }\n // cap center\n const vbase = positions.length / 3;\n const offset = isTop ? height / 2 : -height / 2;\n const center = new Vector3(0, offset, 0);\n positions.push(center.x, center.y, center.z);\n normals.push(0, isTop ? 1 : -1, 0);\n const v = u.y + (u.w - u.y) * 0.5;\n uvs.push(u.x + (u.z - u.x) * 0.5, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n if (c) {\n colors.push(c.r, c.g, c.b, c.a);\n }\n const textureScale = new Vector2(0.5, 0.5);\n for (i = 0; i <= tessellation; i++) {\n angle = (Math.PI * 2 * i * arc) / tessellation;\n const cos = Math.cos(-angle);\n const sin = Math.sin(-angle);\n circleVector = new Vector3(cos * radius, offset, sin * radius);\n const textureCoordinate = new Vector2(cos * textureScale.x + 0.5, sin * textureScale.y + 0.5);\n positions.push(circleVector.x, circleVector.y, circleVector.z);\n normals.push(0, isTop ? 1 : -1, 0);\n const v = u.y + (u.w - u.y) * textureCoordinate.y;\n uvs.push(u.x + (u.z - u.x) * textureCoordinate.x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n if (c) {\n colors.push(c.r, c.g, c.b, c.a);\n }\n }\n // Cap indices\n for (i = 0; i < tessellation; i++) {\n if (!isTop) {\n indices.push(vbase);\n indices.push(vbase + (i + 1));\n indices.push(vbase + (i + 2));\n }\n else {\n indices.push(vbase);\n indices.push(vbase + (i + 2));\n indices.push(vbase + (i + 1));\n }\n }\n };\n // add caps to geometry based on cap parameter\n if (cap === Mesh.CAP_START || cap === Mesh.CAP_ALL) {\n createCylinderCap(false);\n }\n if (cap === Mesh.CAP_END || cap === Mesh.CAP_ALL) {\n createCylinderCap(true);\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n if (faceColors) {\n vertexData.colors = colors;\n }\n return vertexData;\n }\n /**\n * Creates a cylinder or a cone mesh\n * * The parameter `height` sets the height size (float) of the cylinder/cone (float, default 2).\n * * The parameter `diameter` sets the diameter of the top and bottom cap at once (float, default 1).\n * * The parameters `diameterTop` and `diameterBottom` overwrite the parameter `diameter` and set respectively the top cap and bottom cap diameter (floats, default 1). The parameter \"diameterBottom\" can't be zero.\n * * The parameter `tessellation` sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance.\n * * The parameter `subdivisions` sets the number of rings along the cylinder height (positive integer, default 1).\n * * The parameter `hasRings` (boolean, default false) makes the subdivisions independent from each other, so they become different faces.\n * * The parameter `enclose` (boolean, default false) adds two extra faces per subdivision to a sliced cylinder to close it around its height axis.\n * * The parameter `cap` sets the way the cylinder is capped. Possible values : BABYLON.Mesh.NO_CAP, BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL (default).\n * * The parameter `arc` (float, default 1) is the ratio (max 1) to apply to the circumference to slice the cylinder.\n * * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of n Color3 elements) and `faceUV` (an array of n Vector4 elements).\n * * The value of n is the number of cylinder faces. If the cylinder has only 1 subdivisions, n equals : top face + cylinder surface + bottom face = 3\n * * Now, if the cylinder has 5 independent subdivisions (hasRings = true), n equals : top face + 5 stripe surfaces + bottom face = 2 + 5 = 7\n * * Finally, if the cylinder has 5 independent subdivisions and is enclose, n equals : top face + 5 x (stripe surface + 2 closing faces) + bottom face = 2 + 5 * 3 = 17\n * * Each array (color or UVs) is always ordered the same way : the first element is the bottom cap, the last element is the top cap. The other elements are each a ring surface.\n * * If `enclose` is false, a ring surface is one element.\n * * If `enclose` is true, a ring surface is 3 successive elements in the array : the tubular surface, then the two closing faces.\n * * Example how to set colors and textures on a sliced cylinder : https://www.html5gamedevs.com/topic/17945-creating-a-closed-slice-of-a-cylinder/#comment-106379\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.height\n * @param options.diameterTop\n * @param options.diameterBottom\n * @param options.diameter\n * @param options.tessellation\n * @param options.subdivisions\n * @param options.arc\n * @param options.faceColors\n * @param options.faceUV\n * @param options.updatable\n * @param options.hasRings\n * @param options.enclose\n * @param options.cap\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the cylinder mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#cylinder-or-cone\n */\n function CreateCylinder(name, options = {}, scene) {\n const cylinder = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n cylinder._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateCylinderVertexData(options);\n vertexData.applyToMesh(cylinder, options.updatable);\n return cylinder;\n }\n /**\n * Class containing static functions to help procedurally build meshes\n * @deprecated Please use CreateCylinder directly\n */\n const CylinderBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateCylinder,\n };\n VertexData.CreateCylinder = CreateCylinderVertexData;\n Mesh.CreateCylinder = (name, height, diameterTop, diameterBottom, tessellation, subdivisions, scene, updatable, sideOrientation) => {\n if (scene === undefined || !(scene instanceof Scene)) {\n if (scene !== undefined) {\n sideOrientation = updatable || Mesh.DEFAULTSIDE;\n updatable = scene;\n }\n scene = subdivisions;\n subdivisions = 1;\n }\n const options = {\n height,\n diameterTop,\n diameterBottom,\n tessellation,\n subdivisions,\n sideOrientation,\n updatable,\n };\n return CreateCylinder(name, options, scene);\n };\n\n /**\n * Creates the VertexData for a torus\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * diameter the diameter of the torus, optional default 1\n * * thickness the diameter of the tube forming the torus, optional default 0.5\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the torus\n */\n function CreateTorusVertexData(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n const diameter = options.diameter || 1;\n const thickness = options.thickness || 0.5;\n const tessellation = (options.tessellation || 16) | 0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const stride = tessellation + 1;\n for (let i = 0; i <= tessellation; i++) {\n const u = i / tessellation;\n const outerAngle = (i * Math.PI * 2.0) / tessellation - Math.PI / 2.0;\n const transform = Matrix.Translation(diameter / 2.0, 0, 0).multiply(Matrix.RotationY(outerAngle));\n for (let j = 0; j <= tessellation; j++) {\n const v = 1 - j / tessellation;\n const innerAngle = (j * Math.PI * 2.0) / tessellation + Math.PI;\n const dx = Math.cos(innerAngle);\n const dy = Math.sin(innerAngle);\n // Create a vertex.\n let normal = new Vector3(dx, dy, 0);\n let position = normal.scale(thickness / 2);\n const textureCoordinate = new Vector2(u, v);\n position = Vector3.TransformCoordinates(position, transform);\n normal = Vector3.TransformNormal(normal, transform);\n positions.push(position.x, position.y, position.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(textureCoordinate.x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - textureCoordinate.y : textureCoordinate.y);\n // And create indices for two triangles.\n const nextI = (i + 1) % stride;\n const nextJ = (j + 1) % stride;\n indices.push(i * stride + j);\n indices.push(i * stride + nextJ);\n indices.push(nextI * stride + j);\n indices.push(i * stride + nextJ);\n indices.push(nextI * stride + nextJ);\n indices.push(nextI * stride + j);\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (positive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus\n */\n function CreateTorus(name, options = {}, scene) {\n const torus = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n torus._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateTorusVertexData(options);\n vertexData.applyToMesh(torus, options.updatable);\n return torus;\n }\n VertexData.CreateTorus = CreateTorusVertexData;\n Mesh.CreateTorus = (name, diameter, thickness, tessellation, scene, updatable, sideOrientation) => {\n const options = {\n diameter,\n thickness,\n tessellation,\n sideOrientation,\n updatable,\n };\n return CreateTorus(name, options, scene);\n };\n\n class VRExperienceHelperGazer {\n constructor(scene, gazeTrackerToClone = null) {\n this.scene = scene;\n /** @internal */\n this._pointerDownOnMeshAsked = false;\n /** @internal */\n this._isActionableMesh = false;\n /** @internal */\n this._teleportationRequestInitiated = false;\n /** @internal */\n this._teleportationBackRequestInitiated = false;\n /** @internal */\n this._rotationRightAsked = false;\n /** @internal */\n this._rotationLeftAsked = false;\n /** @internal */\n this._dpadPressed = true;\n /** @internal */\n this._activePointer = false;\n this._id = VRExperienceHelperGazer._IdCounter++;\n // Gaze tracker\n if (!gazeTrackerToClone) {\n this._gazeTracker = CreateTorus(\"gazeTracker\", {\n diameter: 0.0035,\n thickness: 0.0025,\n tessellation: 20,\n updatable: false,\n }, scene);\n this._gazeTracker.bakeCurrentTransformIntoVertices();\n this._gazeTracker.isPickable = false;\n this._gazeTracker.isVisible = false;\n const targetMat = new StandardMaterial(\"targetMat\", scene);\n targetMat.specularColor = Color3.Black();\n targetMat.emissiveColor = new Color3(0.7, 0.7, 0.7);\n targetMat.backFaceCulling = false;\n this._gazeTracker.material = targetMat;\n }\n else {\n this._gazeTracker = gazeTrackerToClone.clone(\"gazeTracker\");\n }\n }\n /**\n * @internal\n */\n _getForwardRay(length) {\n return new Ray(Vector3.Zero(), new Vector3(0, 0, length));\n }\n /** @internal */\n _selectionPointerDown() {\n this._pointerDownOnMeshAsked = true;\n if (this._currentHit) {\n this.scene.simulatePointerDown(this._currentHit, { pointerId: this._id });\n }\n }\n /** @internal */\n _selectionPointerUp() {\n if (this._currentHit) {\n this.scene.simulatePointerUp(this._currentHit, { pointerId: this._id });\n }\n this._pointerDownOnMeshAsked = false;\n }\n /** @internal */\n _activatePointer() {\n this._activePointer = true;\n }\n /** @internal */\n _deactivatePointer() {\n this._activePointer = false;\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _updatePointerDistance(distance = 100) { }\n dispose() {\n this._interactionsEnabled = false;\n this._teleportationEnabled = false;\n if (this._gazeTracker) {\n this._gazeTracker.dispose();\n }\n }\n }\n VRExperienceHelperGazer._IdCounter = 0;\n class VRExperienceHelperControllerGazer extends VRExperienceHelperGazer {\n constructor(webVRController, scene, gazeTrackerToClone) {\n super(scene, gazeTrackerToClone);\n this.webVRController = webVRController;\n // Laser pointer\n this._laserPointer = CreateCylinder(\"laserPointer\", {\n updatable: false,\n height: 1,\n diameterTop: 0.004,\n diameterBottom: 0.0002,\n tessellation: 20,\n subdivisions: 1,\n }, scene);\n const laserPointerMaterial = new StandardMaterial(\"laserPointerMat\", scene);\n laserPointerMaterial.emissiveColor = new Color3(0.7, 0.7, 0.7);\n laserPointerMaterial.alpha = 0.6;\n this._laserPointer.material = laserPointerMaterial;\n this._laserPointer.rotation.x = Math.PI / 2;\n this._laserPointer.position.z = -0.5;\n this._laserPointer.isVisible = false;\n this._laserPointer.isPickable = false;\n if (!webVRController.mesh) {\n // Create an empty mesh that is used prior to loading the high quality model\n const preloadMesh = new Mesh(\"preloadControllerMesh\", scene);\n const preloadPointerPose = new Mesh(PoseEnabledController.POINTING_POSE, scene);\n preloadPointerPose.rotation.x = -0.7;\n preloadMesh.addChild(preloadPointerPose);\n webVRController.attachToMesh(preloadMesh);\n }\n this._setLaserPointerParent(webVRController.mesh);\n this._meshAttachedObserver = webVRController._meshAttachedObservable.add((mesh) => {\n this._setLaserPointerParent(mesh);\n });\n }\n _getForwardRay(length) {\n return this.webVRController.getForwardRay(length);\n }\n /** @internal */\n _activatePointer() {\n super._activatePointer();\n this._laserPointer.isVisible = true;\n }\n /** @internal */\n _deactivatePointer() {\n super._deactivatePointer();\n this._laserPointer.isVisible = false;\n }\n /**\n * @internal\n */\n _setLaserPointerColor(color) {\n this._laserPointer.material.emissiveColor = color;\n }\n /**\n * @internal\n */\n _setLaserPointerLightingDisabled(disabled) {\n this._laserPointer.material.disableLighting = disabled;\n }\n /**\n * @internal\n */\n _setLaserPointerParent(mesh) {\n const makeNotPick = (root) => {\n root.isPickable = false;\n root.getChildMeshes().forEach((c) => {\n makeNotPick(c);\n });\n };\n makeNotPick(mesh);\n const meshChildren = mesh.getChildren(undefined, false);\n let laserParent = mesh;\n this.webVRController._pointingPoseNode = null;\n for (let i = 0; i < meshChildren.length; i++) {\n if (meshChildren[i].name && meshChildren[i].name.indexOf(PoseEnabledController.POINTING_POSE) >= 0) {\n laserParent = meshChildren[i];\n this.webVRController._pointingPoseNode = laserParent;\n break;\n }\n }\n this._laserPointer.parent = laserParent;\n }\n _updatePointerDistance(distance = 100) {\n this._laserPointer.scaling.y = distance;\n this._laserPointer.position.z = -distance / 2;\n }\n dispose() {\n super.dispose();\n this._laserPointer.dispose();\n if (this._meshAttachedObserver) {\n this.webVRController._meshAttachedObservable.remove(this._meshAttachedObserver);\n }\n }\n }\n class VRExperienceHelperCameraGazer extends VRExperienceHelperGazer {\n constructor(_getCamera, scene) {\n super(scene);\n this._getCamera = _getCamera;\n }\n _getForwardRay(length) {\n const camera = this._getCamera();\n if (camera) {\n return camera.getForwardRay(length);\n }\n else {\n return new Ray(Vector3.Zero(), Vector3.Forward());\n }\n }\n }\n /**\n * Helps to quickly add VR support to an existing scene.\n * See https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRHelper\n * @deprecated\n */\n class VRExperienceHelper {\n /** Return this.onEnteringVRObservable\n * Note: This one is for backward compatibility. Please use onEnteringVRObservable directly\n */\n get onEnteringVR() {\n return this.onEnteringVRObservable;\n }\n /** Return this.onExitingVRObservable\n * Note: This one is for backward compatibility. Please use onExitingVRObservable directly\n */\n get onExitingVR() {\n return this.onExitingVRObservable;\n }\n /** Return this.onControllerMeshLoadedObservable\n * Note: This one is for backward compatibility. Please use onControllerMeshLoadedObservable directly\n */\n get onControllerMeshLoaded() {\n return this.onControllerMeshLoadedObservable;\n }\n /**\n * The mesh used to display where the user is going to teleport.\n */\n get teleportationTarget() {\n return this._teleportationTarget;\n }\n /**\n * Sets the mesh to be used to display where the user is going to teleport.\n */\n set teleportationTarget(value) {\n if (value) {\n value.name = \"teleportationTarget\";\n this._isDefaultTeleportationTarget = false;\n this._teleportationTarget = value;\n }\n }\n /**\n * The mesh used to display where the user is selecting, this mesh will be cloned and set as the gazeTracker for the left and right controller\n * when set bakeCurrentTransformIntoVertices will be called on the mesh.\n * See https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/bakingTransforms\n */\n get gazeTrackerMesh() {\n return this._cameraGazer._gazeTracker;\n }\n set gazeTrackerMesh(value) {\n if (value) {\n // Dispose of existing meshes\n if (this._cameraGazer._gazeTracker) {\n this._cameraGazer._gazeTracker.dispose();\n }\n if (this._leftController && this._leftController._gazeTracker) {\n this._leftController._gazeTracker.dispose();\n }\n if (this._rightController && this._rightController._gazeTracker) {\n this._rightController._gazeTracker.dispose();\n }\n // Set and create gaze trackers on head and controllers\n this._cameraGazer._gazeTracker = value;\n this._cameraGazer._gazeTracker.bakeCurrentTransformIntoVertices();\n this._cameraGazer._gazeTracker.isPickable = false;\n this._cameraGazer._gazeTracker.isVisible = false;\n this._cameraGazer._gazeTracker.name = \"gazeTracker\";\n if (this._leftController) {\n this._leftController._gazeTracker = this._cameraGazer._gazeTracker.clone(\"gazeTracker\");\n }\n if (this._rightController) {\n this._rightController._gazeTracker = this._cameraGazer._gazeTracker.clone(\"gazeTracker\");\n }\n }\n }\n /**\n * The gaze tracking mesh corresponding to the left controller\n */\n get leftControllerGazeTrackerMesh() {\n if (this._leftController) {\n return this._leftController._gazeTracker;\n }\n return null;\n }\n /**\n * The gaze tracking mesh corresponding to the right controller\n */\n get rightControllerGazeTrackerMesh() {\n if (this._rightController) {\n return this._rightController._gazeTracker;\n }\n return null;\n }\n /**\n * If the ray of the gaze should be displayed.\n */\n get displayGaze() {\n return this._displayGaze;\n }\n /**\n * Sets if the ray of the gaze should be displayed.\n */\n set displayGaze(value) {\n this._displayGaze = value;\n if (!value) {\n this._cameraGazer._gazeTracker.isVisible = false;\n if (this._leftController) {\n this._leftController._gazeTracker.isVisible = false;\n }\n if (this._rightController) {\n this._rightController._gazeTracker.isVisible = false;\n }\n }\n }\n /**\n * If the ray of the LaserPointer should be displayed.\n */\n get displayLaserPointer() {\n return this._displayLaserPointer;\n }\n /**\n * Sets if the ray of the LaserPointer should be displayed.\n */\n set displayLaserPointer(value) {\n this._displayLaserPointer = value;\n if (!value) {\n if (this._rightController) {\n this._rightController._deactivatePointer();\n this._rightController._gazeTracker.isVisible = false;\n }\n if (this._leftController) {\n this._leftController._deactivatePointer();\n this._leftController._gazeTracker.isVisible = false;\n }\n }\n else {\n if (this._rightController) {\n this._rightController._activatePointer();\n }\n if (this._leftController) {\n this._leftController._activatePointer();\n }\n }\n }\n /**\n * The deviceOrientationCamera used as the camera when not in VR.\n */\n get deviceOrientationCamera() {\n return this._deviceOrientationCamera;\n }\n /**\n * Based on the current WebVR support, returns the current VR camera used.\n */\n get currentVRCamera() {\n if (this._webVRready) {\n return this._webVRCamera;\n }\n else {\n return this._scene.activeCamera;\n }\n }\n /**\n * The webVRCamera which is used when in VR.\n */\n get webVRCamera() {\n return this._webVRCamera;\n }\n /**\n * The deviceOrientationCamera that is used as a fallback when vr device is not connected.\n */\n get vrDeviceOrientationCamera() {\n return this._vrDeviceOrientationCamera;\n }\n /**\n * The html button that is used to trigger entering into VR.\n */\n get vrButton() {\n return this._btnVR;\n }\n get _teleportationRequestInitiated() {\n const result = this._cameraGazer._teleportationRequestInitiated ||\n (this._leftController !== null && this._leftController._teleportationRequestInitiated) ||\n (this._rightController !== null && this._rightController._teleportationRequestInitiated);\n return result;\n }\n /**\n * Instantiates a VRExperienceHelper.\n * Helps to quickly add VR support to an existing scene.\n * @param scene The scene the VRExperienceHelper belongs to.\n * @param webVROptions Options to modify the vr experience helper's behavior.\n */\n constructor(scene, \n /** Options to modify the vr experience helper's behavior. */\n webVROptions = {}) {\n this.webVROptions = webVROptions;\n // Can the system support WebVR, even if a headset isn't plugged in?\n this._webVRsupported = false;\n // If WebVR is supported, is a headset plugged in and are we ready to present?\n this._webVRready = false;\n // Are we waiting for the requestPresent callback to complete?\n this._webVRrequesting = false;\n // Are we presenting to the headset right now? (this is the vrDevice state)\n this._webVRpresenting = false;\n // Are we presenting in the fullscreen fallback?\n this._fullscreenVRpresenting = false;\n /**\n * Gets or sets a boolean indicating that gaze can be enabled even if pointer lock is not engage (useful on iOS where fullscreen mode and pointer lock are not supported)\n */\n this.enableGazeEvenWhenNoPointerLock = false;\n /**\n * Gets or sets a boolean indicating that the VREXperienceHelper will exit VR if double tap is detected\n */\n this.exitVROnDoubleTap = true;\n /**\n * Observable raised right before entering VR.\n */\n this.onEnteringVRObservable = new Observable$1();\n /**\n * Observable raised when entering VR has completed.\n */\n this.onAfterEnteringVRObservable = new Observable$1();\n /**\n * Observable raised when exiting VR.\n */\n this.onExitingVRObservable = new Observable$1();\n /**\n * Observable raised when controller mesh is loaded.\n */\n this.onControllerMeshLoadedObservable = new Observable$1();\n this._useCustomVRButton = false;\n this._teleportationRequested = false;\n this._teleportActive = false;\n this._floorMeshesCollection = [];\n this._teleportationMode = VRExperienceHelper.TELEPORTATIONMODE_CONSTANTTIME;\n this._teleportationTime = 122;\n this._teleportationSpeed = 20;\n this._rotationAllowed = true;\n this._teleportBackwardsVector = new Vector3(0, -1, -1);\n this._isDefaultTeleportationTarget = true;\n this._teleportationFillColor = \"#444444\";\n this._teleportationBorderColor = \"#FFFFFF\";\n this._rotationAngle = 0;\n this._haloCenter = new Vector3(0, 0, 0);\n this._padSensibilityUp = 0.65;\n this._padSensibilityDown = 0.35;\n this._leftController = null;\n this._rightController = null;\n this._gazeColor = new Color3(0.7, 0.7, 0.7);\n this._laserColor = new Color3(0.7, 0.7, 0.7);\n this._pickedLaserColor = new Color3(0.2, 0.2, 1);\n this._pickedGazeColor = new Color3(0, 0, 1);\n /**\n * Observable raised when a new mesh is selected based on meshSelectionPredicate\n */\n this.onNewMeshSelected = new Observable$1();\n /**\n * Observable raised when a new mesh is selected based on meshSelectionPredicate.\n * This observable will provide the mesh and the controller used to select the mesh\n */\n this.onMeshSelectedWithController = new Observable$1();\n /**\n * Observable raised when a new mesh is picked based on meshSelectionPredicate\n */\n this.onNewMeshPicked = new Observable$1();\n /**\n * Observable raised before camera teleportation\n */\n this.onBeforeCameraTeleport = new Observable$1();\n /**\n * Observable raised after camera teleportation\n */\n this.onAfterCameraTeleport = new Observable$1();\n /**\n * Observable raised when current selected mesh gets unselected\n */\n this.onSelectedMeshUnselected = new Observable$1();\n /**\n * Set teleportation enabled. If set to false camera teleportation will be disabled but camera rotation will be kept.\n */\n this.teleportationEnabled = true;\n this._teleportationInitialized = false;\n this._interactionsEnabled = false;\n this._interactionsRequested = false;\n this._displayGaze = true;\n this._displayLaserPointer = true;\n /**\n * If the gaze trackers scale should be updated to be constant size when pointing at near/far meshes\n */\n this.updateGazeTrackerScale = true;\n /**\n * If the gaze trackers color should be updated when selecting meshes\n */\n this.updateGazeTrackerColor = true;\n /**\n * If the controller laser color should be updated when selecting meshes\n */\n this.updateControllerLaserColor = true;\n /**\n * Defines whether or not Pointer lock should be requested when switching to\n * full screen.\n */\n this.requestPointerLockOnFullScreen = true;\n /**\n * Was the XR test done already. If this is true AND this.xr exists, xr is initialized.\n * If this is true and no this.xr, xr exists but is not supported, using WebVR.\n */\n this.xrTestDone = false;\n this._onResize = () => {\n this._moveButtonToBottomRight();\n if (this._fullscreenVRpresenting && this._webVRready) {\n this.exitVR();\n }\n };\n this._onFullscreenChange = () => {\n this._fullscreenVRpresenting = !!document.fullscreenElement;\n if (!this._fullscreenVRpresenting && this._inputElement) {\n this.exitVR();\n if (!this._useCustomVRButton && this._btnVR) {\n this._btnVR.style.top = this._inputElement.offsetTop + this._inputElement.offsetHeight - 70 + \"px\";\n this._btnVR.style.left = this._inputElement.offsetLeft + this._inputElement.offsetWidth - 100 + \"px\";\n // make sure the button is visible after setting its position\n this._updateButtonVisibility();\n }\n }\n };\n this._cachedAngularSensibility = { angularSensibilityX: null, angularSensibilityY: null, angularSensibility: null };\n this._beforeRender = () => {\n if (this._leftController && this._leftController._activePointer) {\n this._castRayAndSelectObject(this._leftController);\n }\n if (this._rightController && this._rightController._activePointer) {\n this._castRayAndSelectObject(this._rightController);\n }\n if (this._noControllerIsActive && (this._scene.getEngine().isPointerLock || this.enableGazeEvenWhenNoPointerLock)) {\n this._castRayAndSelectObject(this._cameraGazer);\n }\n else {\n this._cameraGazer._gazeTracker.isVisible = false;\n }\n };\n this._onNewGamepadConnected = (gamepad) => {\n if (gamepad.type !== Gamepad.POSE_ENABLED) {\n if (gamepad.leftStick) {\n gamepad.onleftstickchanged((stickValues) => {\n if (this._teleportationInitialized && this.teleportationEnabled) {\n // Listening to classic/xbox gamepad only if no VR controller is active\n if ((!this._leftController && !this._rightController) ||\n (this._leftController && !this._leftController._activePointer && this._rightController && !this._rightController._activePointer)) {\n this._checkTeleportWithRay(stickValues, this._cameraGazer);\n this._checkTeleportBackwards(stickValues, this._cameraGazer);\n }\n }\n });\n }\n if (gamepad.rightStick) {\n gamepad.onrightstickchanged((stickValues) => {\n if (this._teleportationInitialized) {\n this._checkRotate(stickValues, this._cameraGazer);\n }\n });\n }\n if (gamepad.type === Gamepad.XBOX) {\n gamepad.onbuttondown((buttonPressed) => {\n if (this._interactionsEnabled && buttonPressed === Xbox360Button.A) {\n this._cameraGazer._selectionPointerDown();\n }\n });\n gamepad.onbuttonup((buttonPressed) => {\n if (this._interactionsEnabled && buttonPressed === Xbox360Button.A) {\n this._cameraGazer._selectionPointerUp();\n }\n });\n }\n }\n else {\n const webVRController = gamepad;\n const controller = new VRExperienceHelperControllerGazer(webVRController, this._scene, this._cameraGazer._gazeTracker);\n if (webVRController.hand === \"right\" || (this._leftController && this._leftController.webVRController != webVRController)) {\n this._rightController = controller;\n }\n else {\n this._leftController = controller;\n }\n this._tryEnableInteractionOnController(controller);\n }\n };\n // This only succeeds if the controller's mesh exists for the controller so this must be called whenever new controller is connected or when mesh is loaded\n this._tryEnableInteractionOnController = (controller) => {\n if (this._interactionsRequested && !controller._interactionsEnabled) {\n this._enableInteractionOnController(controller);\n }\n if (this._teleportationRequested && !controller._teleportationEnabled) {\n this._enableTeleportationOnController(controller);\n }\n };\n this._onNewGamepadDisconnected = (gamepad) => {\n if (gamepad instanceof WebVRController) {\n if (gamepad.hand === \"left\" && this._leftController != null) {\n this._leftController.dispose();\n this._leftController = null;\n }\n if (gamepad.hand === \"right\" && this._rightController != null) {\n this._rightController.dispose();\n this._rightController = null;\n }\n }\n };\n this._workingVector = Vector3.Zero();\n this._workingQuaternion = Quaternion.Identity();\n this._workingMatrix = Matrix.Identity();\n Logger.Warn(\"WebVR is deprecated. Please avoid using this experience helper and use the WebXR experience helper instead\");\n this._scene = scene;\n this._inputElement = scene.getEngine().getInputElement();\n // check for VR support:\n const vrSupported = \"getVRDisplays\" in navigator;\n // no VR support? force XR but only when it is not set because web vr can work without the getVRDisplays\n if (!vrSupported && webVROptions.useXR === undefined) {\n webVROptions.useXR = true;\n }\n // Parse options\n if (webVROptions.createFallbackVRDeviceOrientationFreeCamera === undefined) {\n webVROptions.createFallbackVRDeviceOrientationFreeCamera = true;\n }\n if (webVROptions.createDeviceOrientationCamera === undefined) {\n webVROptions.createDeviceOrientationCamera = true;\n }\n if (webVROptions.laserToggle === undefined) {\n webVROptions.laserToggle = true;\n }\n if (webVROptions.defaultHeight === undefined) {\n webVROptions.defaultHeight = 1.7;\n }\n if (webVROptions.useCustomVRButton) {\n this._useCustomVRButton = true;\n if (webVROptions.customVRButton) {\n this._btnVR = webVROptions.customVRButton;\n }\n }\n if (webVROptions.rayLength) {\n this._rayLength = webVROptions.rayLength;\n }\n this._defaultHeight = webVROptions.defaultHeight;\n if (webVROptions.positionScale) {\n this._rayLength *= webVROptions.positionScale;\n this._defaultHeight *= webVROptions.positionScale;\n }\n this._hasEnteredVR = false;\n // Set position\n if (this._scene.activeCamera) {\n this._position = this._scene.activeCamera.position.clone();\n }\n else {\n this._position = new Vector3(0, this._defaultHeight, 0);\n }\n // Set non-vr camera\n if (webVROptions.createDeviceOrientationCamera || !this._scene.activeCamera) {\n this._deviceOrientationCamera = new DeviceOrientationCamera(\"deviceOrientationVRHelper\", this._position.clone(), scene);\n // Copy data from existing camera\n if (this._scene.activeCamera) {\n this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;\n this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;\n // Set rotation from previous camera\n if (this._scene.activeCamera instanceof TargetCamera && this._scene.activeCamera.rotation) {\n const targetCamera = this._scene.activeCamera;\n if (targetCamera.rotationQuaternion) {\n this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);\n }\n else {\n this._deviceOrientationCamera.rotationQuaternion.copyFrom(Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z));\n }\n this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();\n }\n }\n this._scene.activeCamera = this._deviceOrientationCamera;\n if (this._inputElement) {\n this._scene.activeCamera.attachControl();\n }\n }\n else {\n this._existingCamera = this._scene.activeCamera;\n }\n if (this.webVROptions.useXR && navigator.xr) {\n // force-check XR session support\n WebXRSessionManager.IsSessionSupportedAsync(\"immersive-vr\").then((supported) => {\n if (supported) {\n Logger.Log(\"Using WebXR. It is recommended to use the WebXRDefaultExperience directly\");\n // it is possible to use XR, let's do it!\n scene\n .createDefaultXRExperienceAsync({\n floorMeshes: webVROptions.floorMeshes || [],\n })\n .then((xr) => {\n this.xr = xr;\n // connect observables\n this.xrTestDone = true;\n this._cameraGazer = new VRExperienceHelperCameraGazer(() => {\n return this.xr.baseExperience.camera;\n }, scene);\n this.xr.baseExperience.onStateChangedObservable.add((state) => {\n // support for entering / exiting\n switch (state) {\n case WebXRState.ENTERING_XR:\n this.onEnteringVRObservable.notifyObservers(this);\n if (!this._interactionsEnabled) {\n this.xr.pointerSelection.detach();\n }\n this.xr.pointerSelection.displayLaserPointer = this._displayLaserPointer;\n break;\n case WebXRState.EXITING_XR:\n this.onExitingVRObservable.notifyObservers(this);\n // resize to update width and height when exiting vr exits fullscreen\n this._scene.getEngine().resize();\n break;\n case WebXRState.IN_XR:\n this._hasEnteredVR = true;\n break;\n case WebXRState.NOT_IN_XR:\n this._hasEnteredVR = false;\n break;\n }\n });\n });\n }\n else {\n // XR not supported (thou exists), continue WebVR init\n this._completeVRInit(scene, webVROptions);\n }\n });\n }\n else {\n // no XR, continue init synchronous\n this._completeVRInit(scene, webVROptions);\n }\n }\n _completeVRInit(scene, webVROptions) {\n this.xrTestDone = true;\n // Create VR cameras\n if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {\n if (webVROptions.useMultiview) {\n if (!webVROptions.vrDeviceOrientationCameraMetrics) {\n webVROptions.vrDeviceOrientationCameraMetrics = VRCameraMetrics.GetDefault();\n }\n webVROptions.vrDeviceOrientationCameraMetrics.multiviewEnabled = true;\n }\n this._vrDeviceOrientationCamera = new VRDeviceOrientationFreeCamera(\"VRDeviceOrientationVRHelper\", this._position, this._scene, true, webVROptions.vrDeviceOrientationCameraMetrics);\n this._vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;\n }\n this._webVRCamera = new WebVRFreeCamera(\"WebVRHelper\", this._position, this._scene, webVROptions);\n this._webVRCamera.useStandingMatrix();\n this._cameraGazer = new VRExperienceHelperCameraGazer(() => {\n return this.currentVRCamera;\n }, scene);\n // Create default button\n if (!this._useCustomVRButton) {\n this._btnVR = document.createElement(\"BUTTON\");\n this._btnVR.className = \"babylonVRicon\";\n this._btnVR.id = \"babylonVRiconbtn\";\n this._btnVR.title = \"Click to switch to VR\";\n const url = !window.SVGSVGElement\n ? \"https://cdn.babylonjs.com/Assets/vrButton.png\"\n : \"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A\";\n let css = \".babylonVRicon { position: absolute; right: 20px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(\" +\n url +\n \"); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }\";\n css += \".babylonVRicon.vrdisplaypresenting { display: none; }\";\n // TODO: Add user feedback so that they know what state the VRDisplay is in (disconnected, connected, entering-VR)\n // css += \".babylonVRicon.vrdisplaysupported { }\";\n // css += \".babylonVRicon.vrdisplayready { }\";\n // css += \".babylonVRicon.vrdisplayrequesting { }\";\n const style = document.createElement(\"style\");\n style.appendChild(document.createTextNode(css));\n document.getElementsByTagName(\"head\")[0].appendChild(style);\n this._moveButtonToBottomRight();\n }\n // VR button click event\n if (this._btnVR) {\n this._btnVR.addEventListener(\"click\", () => {\n if (!this.isInVRMode) {\n this.enterVR();\n }\n else {\n this._scene.getEngine().disableVR();\n }\n });\n }\n // Window events\n const hostWindow = this._scene.getEngine().getHostWindow();\n if (!hostWindow) {\n return;\n }\n hostWindow.addEventListener(\"resize\", this._onResize);\n document.addEventListener(\"fullscreenchange\", this._onFullscreenChange, false);\n // Display vr button when headset is connected\n if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {\n this._displayVRButton();\n }\n else {\n this._scene.getEngine().onVRDisplayChangedObservable.add((e) => {\n if (e.vrDisplay) {\n this._displayVRButton();\n }\n });\n }\n // Exiting VR mode using 'ESC' key on desktop\n this._onKeyDown = (event) => {\n if (event.keyCode === 27 && this.isInVRMode) {\n this.exitVR();\n }\n };\n document.addEventListener(\"keydown\", this._onKeyDown);\n // Exiting VR mode double tapping the touch screen\n this._scene.onPrePointerObservable.add(() => {\n if (this._hasEnteredVR && this.exitVROnDoubleTap) {\n this.exitVR();\n if (this._fullscreenVRpresenting) {\n this._scene.getEngine().exitFullscreen();\n }\n }\n }, PointerEventTypes.POINTERDOUBLETAP, false);\n // Listen for WebVR display changes\n this._onVRDisplayChangedBind = (eventArgs) => this._onVRDisplayChanged(eventArgs);\n this._onVrDisplayPresentChangeBind = () => this._onVrDisplayPresentChange();\n this._onVRRequestPresentStart = () => {\n this._webVRrequesting = true;\n this._updateButtonVisibility();\n };\n this._onVRRequestPresentComplete = () => {\n this._webVRrequesting = false;\n this._updateButtonVisibility();\n };\n scene.getEngine().onVRDisplayChangedObservable.add(this._onVRDisplayChangedBind);\n scene.getEngine().onVRRequestPresentStart.add(this._onVRRequestPresentStart);\n scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);\n hostWindow.addEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChangeBind);\n scene.onDisposeObservable.add(() => {\n this.dispose();\n });\n // Gamepad connection events\n this._webVRCamera.onControllerMeshLoadedObservable.add((webVRController) => this._onDefaultMeshLoaded(webVRController));\n this._scene.gamepadManager.onGamepadConnectedObservable.add(this._onNewGamepadConnected);\n this._scene.gamepadManager.onGamepadDisconnectedObservable.add(this._onNewGamepadDisconnected);\n this._updateButtonVisibility();\n //create easing functions\n this._circleEase = new CircleEase();\n this._circleEase.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\n this._teleportationEasing = this._circleEase;\n // Allow clicking in the vrDeviceOrientationCamera\n scene.onPointerObservable.add((e) => {\n if (this._interactionsEnabled) {\n if (scene.activeCamera === this.vrDeviceOrientationCamera && e.event.pointerType === \"mouse\") {\n if (e.type === PointerEventTypes.POINTERDOWN) {\n this._cameraGazer._selectionPointerDown();\n }\n else if (e.type === PointerEventTypes.POINTERUP) {\n this._cameraGazer._selectionPointerUp();\n }\n }\n }\n });\n if (this.webVROptions.floorMeshes) {\n this.enableTeleportation({ floorMeshes: this.webVROptions.floorMeshes });\n }\n }\n // Raised when one of the controller has loaded successfully its associated default mesh\n _onDefaultMeshLoaded(webVRController) {\n if (this._leftController && this._leftController.webVRController == webVRController) {\n if (webVRController.mesh) {\n this._leftController._setLaserPointerParent(webVRController.mesh);\n }\n }\n if (this._rightController && this._rightController.webVRController == webVRController) {\n if (webVRController.mesh) {\n this._rightController._setLaserPointerParent(webVRController.mesh);\n }\n }\n try {\n this.onControllerMeshLoadedObservable.notifyObservers(webVRController);\n }\n catch (err) {\n Logger.Warn(\"Error in your custom logic onControllerMeshLoaded: \" + err);\n }\n }\n /**\n * Gets a value indicating if we are currently in VR mode.\n */\n get isInVRMode() {\n return (this.xr && this.webVROptions.useXR && this.xr.baseExperience.state === WebXRState.IN_XR) || this._webVRpresenting || this._fullscreenVRpresenting;\n }\n _onVrDisplayPresentChange() {\n const vrDisplay = this._scene.getEngine().getVRDevice();\n if (vrDisplay) {\n const wasPresenting = this._webVRpresenting;\n this._webVRpresenting = vrDisplay.isPresenting;\n if (wasPresenting && !this._webVRpresenting) {\n this.exitVR();\n }\n }\n else {\n Logger.Warn(\"Detected VRDisplayPresentChange on an unknown VRDisplay. Did you can enterVR on the vrExperienceHelper?\");\n }\n this._updateButtonVisibility();\n }\n _onVRDisplayChanged(eventArgs) {\n this._webVRsupported = eventArgs.vrSupported;\n this._webVRready = !!eventArgs.vrDisplay;\n this._webVRpresenting = eventArgs.vrDisplay && eventArgs.vrDisplay.isPresenting;\n this._updateButtonVisibility();\n }\n _moveButtonToBottomRight() {\n if (this._inputElement && !this._useCustomVRButton && this._btnVR) {\n const rect = this._inputElement.getBoundingClientRect();\n this._btnVR.style.top = rect.top + rect.height - 70 + \"px\";\n this._btnVR.style.left = rect.left + rect.width - 100 + \"px\";\n }\n }\n _displayVRButton() {\n if (!this._useCustomVRButton && !this._btnVRDisplayed && this._btnVR) {\n document.body.appendChild(this._btnVR);\n this._btnVRDisplayed = true;\n }\n }\n _updateButtonVisibility() {\n if (!this._btnVR || this._useCustomVRButton) {\n return;\n }\n this._btnVR.className = \"babylonVRicon\";\n if (this.isInVRMode) {\n this._btnVR.className += \" vrdisplaypresenting\";\n }\n else {\n if (this._webVRready) {\n this._btnVR.className += \" vrdisplayready\";\n }\n if (this._webVRsupported) {\n this._btnVR.className += \" vrdisplaysupported\";\n }\n if (this._webVRrequesting) {\n this._btnVR.className += \" vrdisplayrequesting\";\n }\n }\n }\n /**\n * Attempt to enter VR. If a headset is connected and ready, will request present on that.\n * Otherwise, will use the fullscreen API.\n */\n enterVR() {\n if (this.xr) {\n this.xr.baseExperience.enterXRAsync(\"immersive-vr\", \"local-floor\", this.xr.renderTarget);\n return;\n }\n if (this.onEnteringVRObservable) {\n try {\n this.onEnteringVRObservable.notifyObservers(this);\n }\n catch (err) {\n Logger.Warn(\"Error in your custom logic onEnteringVR: \" + err);\n }\n }\n if (this._scene.activeCamera) {\n this._position = this._scene.activeCamera.position.clone();\n if (this.vrDeviceOrientationCamera) {\n this.vrDeviceOrientationCamera.rotation = Quaternion.FromRotationMatrix(this._scene.activeCamera.getWorldMatrix().getRotationMatrix()).toEulerAngles();\n this.vrDeviceOrientationCamera.angularSensibility = 2000;\n }\n if (this.webVRCamera) {\n const currentYRotation = this.webVRCamera.deviceRotationQuaternion.toEulerAngles().y;\n const desiredYRotation = Quaternion.FromRotationMatrix(this._scene.activeCamera.getWorldMatrix().getRotationMatrix()).toEulerAngles().y;\n const delta = desiredYRotation - currentYRotation;\n const currentGlobalRotation = this.webVRCamera.rotationQuaternion.toEulerAngles().y;\n this.webVRCamera.rotationQuaternion = Quaternion.FromEulerAngles(0, currentGlobalRotation + delta, 0);\n }\n // make sure that we return to the last active camera\n this._existingCamera = this._scene.activeCamera;\n // Remove and cache angular sensability to avoid camera rotation when in VR\n if (this._existingCamera.angularSensibilityX) {\n this._cachedAngularSensibility.angularSensibilityX = this._existingCamera.angularSensibilityX;\n this._existingCamera.angularSensibilityX = Number.MAX_VALUE;\n }\n if (this._existingCamera.angularSensibilityY) {\n this._cachedAngularSensibility.angularSensibilityY = this._existingCamera.angularSensibilityY;\n this._existingCamera.angularSensibilityY = Number.MAX_VALUE;\n }\n if (this._existingCamera.angularSensibility) {\n this._cachedAngularSensibility.angularSensibility = this._existingCamera.angularSensibility;\n this._existingCamera.angularSensibility = Number.MAX_VALUE;\n }\n }\n if (this._webVRrequesting) {\n return;\n }\n // If WebVR is supported and a headset is connected\n if (this._webVRready) {\n if (!this._webVRpresenting) {\n this._scene.getEngine().onVRRequestPresentComplete.addOnce((result) => {\n this.onAfterEnteringVRObservable.notifyObservers({ success: result });\n });\n this._webVRCamera.position = this._position;\n this._scene.activeCamera = this._webVRCamera;\n }\n }\n else if (this._vrDeviceOrientationCamera) {\n this._vrDeviceOrientationCamera.position = this._position;\n if (this._scene.activeCamera) {\n this._vrDeviceOrientationCamera.minZ = this._scene.activeCamera.minZ;\n }\n this._scene.activeCamera = this._vrDeviceOrientationCamera;\n this._scene.getEngine().enterFullscreen(this.requestPointerLockOnFullScreen);\n this._updateButtonVisibility();\n this._vrDeviceOrientationCamera.onViewMatrixChangedObservable.addOnce(() => {\n this.onAfterEnteringVRObservable.notifyObservers({ success: true });\n });\n }\n if (this._scene.activeCamera && this._inputElement) {\n this._scene.activeCamera.attachControl();\n }\n if (this._interactionsEnabled) {\n this._scene.registerBeforeRender(this._beforeRender);\n }\n if (this._displayLaserPointer) {\n [this._leftController, this._rightController].forEach((controller) => {\n if (controller) {\n controller._activatePointer();\n }\n });\n }\n this._hasEnteredVR = true;\n }\n /**\n * Attempt to exit VR, or fullscreen.\n */\n exitVR() {\n if (this.xr) {\n this.xr.baseExperience.exitXRAsync();\n return;\n }\n if (this._hasEnteredVR) {\n if (this.onExitingVRObservable) {\n try {\n this.onExitingVRObservable.notifyObservers(this);\n }\n catch (err) {\n Logger.Warn(\"Error in your custom logic onExitingVR: \" + err);\n }\n }\n if (this._webVRpresenting) {\n this._scene.getEngine().disableVR();\n }\n if (this._scene.activeCamera) {\n this._position = this._scene.activeCamera.position.clone();\n }\n if (this.vrDeviceOrientationCamera) {\n this.vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;\n }\n if (this._deviceOrientationCamera) {\n this._deviceOrientationCamera.position = this._position;\n this._scene.activeCamera = this._deviceOrientationCamera;\n // Restore angular sensibility\n if (this._cachedAngularSensibility.angularSensibilityX) {\n this._deviceOrientationCamera.angularSensibilityX = this._cachedAngularSensibility.angularSensibilityX;\n this._cachedAngularSensibility.angularSensibilityX = null;\n }\n if (this._cachedAngularSensibility.angularSensibilityY) {\n this._deviceOrientationCamera.angularSensibilityY = this._cachedAngularSensibility.angularSensibilityY;\n this._cachedAngularSensibility.angularSensibilityY = null;\n }\n if (this._cachedAngularSensibility.angularSensibility) {\n this._deviceOrientationCamera.angularSensibility = this._cachedAngularSensibility.angularSensibility;\n this._cachedAngularSensibility.angularSensibility = null;\n }\n }\n else if (this._existingCamera) {\n this._existingCamera.position = this._position;\n this._scene.activeCamera = this._existingCamera;\n if (this._inputElement) {\n this._scene.activeCamera.attachControl();\n }\n // Restore angular sensibility\n if (this._cachedAngularSensibility.angularSensibilityX) {\n this._existingCamera.angularSensibilityX = this._cachedAngularSensibility.angularSensibilityX;\n this._cachedAngularSensibility.angularSensibilityX = null;\n }\n if (this._cachedAngularSensibility.angularSensibilityY) {\n this._existingCamera.angularSensibilityY = this._cachedAngularSensibility.angularSensibilityY;\n this._cachedAngularSensibility.angularSensibilityY = null;\n }\n if (this._cachedAngularSensibility.angularSensibility) {\n this._existingCamera.angularSensibility = this._cachedAngularSensibility.angularSensibility;\n this._cachedAngularSensibility.angularSensibility = null;\n }\n }\n this._updateButtonVisibility();\n if (this._interactionsEnabled) {\n this._scene.unregisterBeforeRender(this._beforeRender);\n this._cameraGazer._gazeTracker.isVisible = false;\n if (this._leftController) {\n this._leftController._gazeTracker.isVisible = false;\n }\n if (this._rightController) {\n this._rightController._gazeTracker.isVisible = false;\n }\n }\n // resize to update width and height when exiting vr exits fullscreen\n this._scene.getEngine().resize();\n [this._leftController, this._rightController].forEach((controller) => {\n if (controller) {\n controller._deactivatePointer();\n }\n });\n this._hasEnteredVR = false;\n // Update engine state to re enable non-vr camera input\n const engine = this._scene.getEngine();\n if (engine._onVrDisplayPresentChange) {\n engine._onVrDisplayPresentChange();\n }\n }\n }\n /**\n * The position of the vr experience helper.\n */\n get position() {\n return this._position;\n }\n /**\n * Sets the position of the vr experience helper.\n */\n set position(value) {\n this._position = value;\n if (this._scene.activeCamera) {\n this._scene.activeCamera.position = value;\n }\n }\n /**\n * Enables controllers and user interactions such as selecting and object or clicking on an object.\n */\n enableInteractions() {\n if (!this._interactionsEnabled) {\n this._interactionsRequested = true;\n // in XR it is enabled by default, but just to make sure, re-attach\n if (this.xr) {\n if (this.xr.baseExperience.state === WebXRState.IN_XR) {\n this.xr.pointerSelection.attach();\n }\n return;\n }\n if (this._leftController) {\n this._enableInteractionOnController(this._leftController);\n }\n if (this._rightController) {\n this._enableInteractionOnController(this._rightController);\n }\n this.raySelectionPredicate = (mesh) => {\n return mesh.isVisible && (mesh.isPickable || mesh.name === this._floorMeshName);\n };\n this.meshSelectionPredicate = () => {\n return true;\n };\n this._raySelectionPredicate = (mesh) => {\n if (this._isTeleportationFloor(mesh) ||\n (mesh.name.indexOf(\"gazeTracker\") === -1 && mesh.name.indexOf(\"teleportationTarget\") === -1 && mesh.name.indexOf(\"torusTeleportation\") === -1)) {\n return this.raySelectionPredicate(mesh);\n }\n return false;\n };\n this._interactionsEnabled = true;\n }\n }\n get _noControllerIsActive() {\n return !(this._leftController && this._leftController._activePointer) && !(this._rightController && this._rightController._activePointer);\n }\n _isTeleportationFloor(mesh) {\n for (let i = 0; i < this._floorMeshesCollection.length; i++) {\n if (this._floorMeshesCollection[i].id === mesh.id) {\n return true;\n }\n }\n if (this._floorMeshName && mesh.name === this._floorMeshName) {\n return true;\n }\n return false;\n }\n /**\n * Adds a floor mesh to be used for teleportation.\n * @param floorMesh the mesh to be used for teleportation.\n */\n addFloorMesh(floorMesh) {\n if (!this._floorMeshesCollection) {\n return;\n }\n if (this._floorMeshesCollection.indexOf(floorMesh) > -1) {\n return;\n }\n this._floorMeshesCollection.push(floorMesh);\n }\n /**\n * Removes a floor mesh from being used for teleportation.\n * @param floorMesh the mesh to be removed.\n */\n removeFloorMesh(floorMesh) {\n if (!this._floorMeshesCollection) {\n return;\n }\n const meshIndex = this._floorMeshesCollection.indexOf(floorMesh);\n if (meshIndex !== -1) {\n this._floorMeshesCollection.splice(meshIndex, 1);\n }\n }\n /**\n * Enables interactions and teleportation using the VR controllers and gaze.\n * @param vrTeleportationOptions options to modify teleportation behavior.\n */\n enableTeleportation(vrTeleportationOptions = {}) {\n if (!this._teleportationInitialized) {\n this._teleportationRequested = true;\n this.enableInteractions();\n if (this.webVROptions.useXR && (vrTeleportationOptions.floorMeshes || vrTeleportationOptions.floorMeshName)) {\n const floorMeshes = vrTeleportationOptions.floorMeshes || [];\n if (!floorMeshes.length) {\n const floorMesh = this._scene.getMeshByName(vrTeleportationOptions.floorMeshName);\n if (floorMesh) {\n floorMeshes.push(floorMesh);\n }\n }\n if (this.xr) {\n floorMeshes.forEach((mesh) => {\n this.xr.teleportation.addFloorMesh(mesh);\n });\n if (!this.xr.teleportation.attached) {\n this.xr.teleportation.attach();\n }\n return;\n }\n else if (!this.xrTestDone) {\n const waitForXr = () => {\n if (this.xrTestDone) {\n this._scene.unregisterBeforeRender(waitForXr);\n if (this.xr) {\n if (!this.xr.teleportation.attached) {\n this.xr.teleportation.attach();\n }\n }\n else {\n this.enableTeleportation(vrTeleportationOptions);\n }\n }\n };\n this._scene.registerBeforeRender(waitForXr);\n return;\n }\n }\n if (vrTeleportationOptions.floorMeshName) {\n this._floorMeshName = vrTeleportationOptions.floorMeshName;\n }\n if (vrTeleportationOptions.floorMeshes) {\n this._floorMeshesCollection = vrTeleportationOptions.floorMeshes;\n }\n if (vrTeleportationOptions.teleportationMode) {\n this._teleportationMode = vrTeleportationOptions.teleportationMode;\n }\n if (vrTeleportationOptions.teleportationTime && vrTeleportationOptions.teleportationTime > 0) {\n this._teleportationTime = vrTeleportationOptions.teleportationTime;\n }\n if (vrTeleportationOptions.teleportationSpeed && vrTeleportationOptions.teleportationSpeed > 0) {\n this._teleportationSpeed = vrTeleportationOptions.teleportationSpeed;\n }\n if (vrTeleportationOptions.easingFunction !== undefined) {\n this._teleportationEasing = vrTeleportationOptions.easingFunction;\n }\n if (this._leftController != null) {\n this._enableTeleportationOnController(this._leftController);\n }\n if (this._rightController != null) {\n this._enableTeleportationOnController(this._rightController);\n }\n // Creates an image processing post process for the vignette not relying\n // on the main scene configuration for image processing to reduce setup and spaces\n // (gamma/linear) conflicts.\n const imageProcessingConfiguration = new ImageProcessingConfiguration();\n imageProcessingConfiguration.vignetteColor = new Color4(0, 0, 0, 0);\n imageProcessingConfiguration.vignetteEnabled = true;\n this._postProcessMove = new ImageProcessingPostProcess(\"postProcessMove\", 1.0, this._webVRCamera, undefined, undefined, undefined, undefined, imageProcessingConfiguration);\n this._webVRCamera.detachPostProcess(this._postProcessMove);\n this._teleportationInitialized = true;\n if (this._isDefaultTeleportationTarget) {\n this._createTeleportationCircles();\n this._teleportationTarget.scaling.scaleInPlace(this._webVRCamera.deviceScaleFactor);\n }\n }\n }\n _enableInteractionOnController(controller) {\n const controllerMesh = controller.webVRController.mesh;\n if (controllerMesh) {\n controller._interactionsEnabled = true;\n if (this.isInVRMode && this._displayLaserPointer) {\n controller._activatePointer();\n }\n if (this.webVROptions.laserToggle) {\n controller.webVRController.onMainButtonStateChangedObservable.add((stateObject) => {\n // Enabling / disabling laserPointer\n if (this._displayLaserPointer && stateObject.value === 1) {\n if (controller._activePointer) {\n controller._deactivatePointer();\n }\n else {\n controller._activatePointer();\n }\n if (this.displayGaze) {\n controller._gazeTracker.isVisible = controller._activePointer;\n }\n }\n });\n }\n controller.webVRController.onTriggerStateChangedObservable.add((stateObject) => {\n let gazer = controller;\n if (this._noControllerIsActive) {\n gazer = this._cameraGazer;\n }\n if (!gazer._pointerDownOnMeshAsked) {\n if (stateObject.value > this._padSensibilityUp) {\n gazer._selectionPointerDown();\n }\n }\n else if (stateObject.value < this._padSensibilityDown) {\n gazer._selectionPointerUp();\n }\n });\n }\n }\n _checkTeleportWithRay(stateObject, gazer) {\n // Dont teleport if another gaze already requested teleportation\n if (this._teleportationRequestInitiated && !gazer._teleportationRequestInitiated) {\n return;\n }\n if (!gazer._teleportationRequestInitiated) {\n if (stateObject.y < -this._padSensibilityUp && gazer._dpadPressed) {\n gazer._activatePointer();\n gazer._teleportationRequestInitiated = true;\n }\n }\n else {\n // Listening to the proper controller values changes to confirm teleportation\n if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {\n if (this._teleportActive) {\n this.teleportCamera(this._haloCenter);\n }\n gazer._teleportationRequestInitiated = false;\n }\n }\n }\n _checkRotate(stateObject, gazer) {\n // Only rotate when user is not currently selecting a teleportation location\n if (gazer._teleportationRequestInitiated) {\n return;\n }\n if (!gazer._rotationLeftAsked) {\n if (stateObject.x < -this._padSensibilityUp && gazer._dpadPressed) {\n gazer._rotationLeftAsked = true;\n if (this._rotationAllowed) {\n this._rotateCamera(false);\n }\n }\n }\n else {\n if (stateObject.x > -this._padSensibilityDown) {\n gazer._rotationLeftAsked = false;\n }\n }\n if (!gazer._rotationRightAsked) {\n if (stateObject.x > this._padSensibilityUp && gazer._dpadPressed) {\n gazer._rotationRightAsked = true;\n if (this._rotationAllowed) {\n this._rotateCamera(true);\n }\n }\n }\n else {\n if (stateObject.x < this._padSensibilityDown) {\n gazer._rotationRightAsked = false;\n }\n }\n }\n _checkTeleportBackwards(stateObject, gazer) {\n // Only teleport backwards when user is not currently selecting a teleportation location\n if (gazer._teleportationRequestInitiated) {\n return;\n }\n // Teleport backwards\n if (stateObject.y > this._padSensibilityUp && gazer._dpadPressed) {\n if (!gazer._teleportationBackRequestInitiated) {\n if (!this.currentVRCamera) {\n return;\n }\n // Get rotation and position of the current camera\n let rotation = Quaternion.FromRotationMatrix(this.currentVRCamera.getWorldMatrix().getRotationMatrix());\n let position = this.currentVRCamera.position;\n // If the camera has device position, use that instead\n if (this.currentVRCamera.devicePosition && this.currentVRCamera.deviceRotationQuaternion) {\n rotation = this.currentVRCamera.deviceRotationQuaternion;\n position = this.currentVRCamera.devicePosition;\n }\n // Get matrix with only the y rotation of the device rotation\n rotation.toEulerAnglesToRef(this._workingVector);\n this._workingVector.z = 0;\n this._workingVector.x = 0;\n Quaternion.RotationYawPitchRollToRef(this._workingVector.y, this._workingVector.x, this._workingVector.z, this._workingQuaternion);\n this._workingQuaternion.toRotationMatrix(this._workingMatrix);\n // Rotate backwards ray by device rotation to cast at the ground behind the user\n Vector3.TransformCoordinatesToRef(this._teleportBackwardsVector, this._workingMatrix, this._workingVector);\n // Teleport if ray hit the ground and is not to far away eg. backwards off a cliff\n const ray = new Ray(position, this._workingVector);\n const hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);\n if (hit && hit.pickedPoint && hit.pickedMesh && this._isTeleportationFloor(hit.pickedMesh) && hit.distance < 5) {\n this.teleportCamera(hit.pickedPoint);\n }\n gazer._teleportationBackRequestInitiated = true;\n }\n }\n else {\n gazer._teleportationBackRequestInitiated = false;\n }\n }\n _enableTeleportationOnController(controller) {\n const controllerMesh = controller.webVRController.mesh;\n if (controllerMesh) {\n if (!controller._interactionsEnabled) {\n this._enableInteractionOnController(controller);\n }\n controller._interactionsEnabled = true;\n controller._teleportationEnabled = true;\n if (controller.webVRController.controllerType === PoseEnabledControllerType.VIVE) {\n controller._dpadPressed = false;\n controller.webVRController.onPadStateChangedObservable.add((stateObject) => {\n controller._dpadPressed = stateObject.pressed;\n if (!controller._dpadPressed) {\n controller._rotationLeftAsked = false;\n controller._rotationRightAsked = false;\n controller._teleportationBackRequestInitiated = false;\n }\n });\n }\n controller.webVRController.onPadValuesChangedObservable.add((stateObject) => {\n if (this.teleportationEnabled) {\n this._checkTeleportBackwards(stateObject, controller);\n this._checkTeleportWithRay(stateObject, controller);\n }\n this._checkRotate(stateObject, controller);\n });\n }\n }\n _createTeleportationCircles() {\n this._teleportationTarget = CreateGround(\"teleportationTarget\", { width: 2, height: 2, subdivisions: 2 }, this._scene);\n this._teleportationTarget.isPickable = false;\n const length = 512;\n const dynamicTexture = new DynamicTexture(\"DynamicTexture\", length, this._scene, true);\n dynamicTexture.hasAlpha = true;\n const context = dynamicTexture.getContext();\n const centerX = length / 2;\n const centerY = length / 2;\n const radius = 200;\n context.beginPath();\n context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);\n context.fillStyle = this._teleportationFillColor;\n context.fill();\n context.lineWidth = 10;\n context.strokeStyle = this._teleportationBorderColor;\n context.stroke();\n context.closePath();\n dynamicTexture.update();\n const teleportationCircleMaterial = new StandardMaterial(\"TextPlaneMaterial\", this._scene);\n teleportationCircleMaterial.diffuseTexture = dynamicTexture;\n this._teleportationTarget.material = teleportationCircleMaterial;\n const torus = CreateTorus(\"torusTeleportation\", {\n diameter: 0.75,\n thickness: 0.1,\n tessellation: 25,\n updatable: false,\n }, this._scene);\n torus.isPickable = false;\n torus.parent = this._teleportationTarget;\n const animationInnerCircle = new Animation(\"animationInnerCircle\", \"position.y\", 30, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);\n const keys = [];\n keys.push({\n frame: 0,\n value: 0,\n });\n keys.push({\n frame: 30,\n value: 0.4,\n });\n keys.push({\n frame: 60,\n value: 0,\n });\n animationInnerCircle.setKeys(keys);\n const easingFunction = new SineEase();\n easingFunction.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\n animationInnerCircle.setEasingFunction(easingFunction);\n torus.animations = [];\n torus.animations.push(animationInnerCircle);\n this._scene.beginAnimation(torus, 0, 60, true);\n this._hideTeleportationTarget();\n }\n _displayTeleportationTarget() {\n this._teleportActive = true;\n if (this._teleportationInitialized) {\n this._teleportationTarget.isVisible = true;\n if (this._isDefaultTeleportationTarget) {\n this._teleportationTarget.getChildren()[0].isVisible = true;\n }\n }\n }\n _hideTeleportationTarget() {\n this._teleportActive = false;\n if (this._teleportationInitialized) {\n this._teleportationTarget.isVisible = false;\n if (this._isDefaultTeleportationTarget) {\n this._teleportationTarget.getChildren()[0].isVisible = false;\n }\n }\n }\n _rotateCamera(right) {\n if (!(this.currentVRCamera instanceof FreeCamera)) {\n return;\n }\n if (right) {\n this._rotationAngle++;\n }\n else {\n this._rotationAngle--;\n }\n this.currentVRCamera.animations = [];\n const target = Quaternion.FromRotationMatrix(Matrix.RotationY((Math.PI / 4) * this._rotationAngle));\n const animationRotation = new Animation(\"animationRotation\", \"rotationQuaternion\", 90, Animation.ANIMATIONTYPE_QUATERNION, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const animationRotationKeys = [];\n animationRotationKeys.push({\n frame: 0,\n value: this.currentVRCamera.rotationQuaternion,\n });\n animationRotationKeys.push({\n frame: 6,\n value: target,\n });\n animationRotation.setKeys(animationRotationKeys);\n animationRotation.setEasingFunction(this._circleEase);\n this.currentVRCamera.animations.push(animationRotation);\n this._postProcessMove.animations = [];\n const animationPP = new Animation(\"animationPP\", \"vignetteWeight\", 90, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const vignetteWeightKeys = [];\n vignetteWeightKeys.push({\n frame: 0,\n value: 0,\n });\n vignetteWeightKeys.push({\n frame: 3,\n value: 4,\n });\n vignetteWeightKeys.push({\n frame: 6,\n value: 0,\n });\n animationPP.setKeys(vignetteWeightKeys);\n animationPP.setEasingFunction(this._circleEase);\n this._postProcessMove.animations.push(animationPP);\n const animationPP2 = new Animation(\"animationPP2\", \"vignetteStretch\", 90, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const vignetteStretchKeys = [];\n vignetteStretchKeys.push({\n frame: 0,\n value: 0,\n });\n vignetteStretchKeys.push({\n frame: 3,\n value: 10,\n });\n vignetteStretchKeys.push({\n frame: 6,\n value: 0,\n });\n animationPP2.setKeys(vignetteStretchKeys);\n animationPP2.setEasingFunction(this._circleEase);\n this._postProcessMove.animations.push(animationPP2);\n this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;\n this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;\n this._postProcessMove.samples = 4;\n this._webVRCamera.attachPostProcess(this._postProcessMove);\n this._scene.beginAnimation(this._postProcessMove, 0, 6, false, 1, () => {\n this._webVRCamera.detachPostProcess(this._postProcessMove);\n });\n this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);\n }\n _moveTeleportationSelectorTo(hit, gazer, ray) {\n if (hit.pickedPoint) {\n if (gazer._teleportationRequestInitiated) {\n this._displayTeleportationTarget();\n this._haloCenter.copyFrom(hit.pickedPoint);\n this._teleportationTarget.position.copyFrom(hit.pickedPoint);\n }\n const pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(true, false), ray);\n if (pickNormal) {\n const axis1 = Vector3.Cross(Axis.Y, pickNormal);\n const axis2 = Vector3.Cross(pickNormal, axis1);\n Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, this._teleportationTarget.rotation);\n }\n this._teleportationTarget.position.y += 0.1;\n }\n }\n /**\n * Teleports the users feet to the desired location\n * @param location The location where the user's feet should be placed\n */\n teleportCamera(location) {\n if (!(this.currentVRCamera instanceof FreeCamera)) {\n return;\n }\n // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the\n // offset of the headset from the anchor.\n if (this.webVRCamera.leftCamera) {\n this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);\n this._workingVector.subtractInPlace(this.webVRCamera.position);\n location.subtractToRef(this._workingVector, this._workingVector);\n }\n else {\n this._workingVector.copyFrom(location);\n }\n // Add height to account for user's height offset\n if (this.isInVRMode) {\n this._workingVector.y += this.webVRCamera.deviceDistanceToRoomGround() * this._webVRCamera.deviceScaleFactor;\n }\n else {\n this._workingVector.y += this._defaultHeight;\n }\n this.onBeforeCameraTeleport.notifyObservers(this._workingVector);\n // Animations FPS\n const FPS = 90;\n let speedRatio, lastFrame;\n if (this._teleportationMode == VRExperienceHelper.TELEPORTATIONMODE_CONSTANTSPEED) {\n lastFrame = FPS;\n const dist = Vector3.Distance(this.currentVRCamera.position, this._workingVector);\n speedRatio = this._teleportationSpeed / dist;\n }\n else {\n // teleportationMode is TELEPORTATIONMODE_CONSTANTTIME\n lastFrame = Math.round((this._teleportationTime * FPS) / 1000);\n speedRatio = 1;\n }\n // Create animation from the camera's position to the new location\n this.currentVRCamera.animations = [];\n const animationCameraTeleportation = new Animation(\"animationCameraTeleportation\", \"position\", FPS, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const animationCameraTeleportationKeys = [\n {\n frame: 0,\n value: this.currentVRCamera.position,\n },\n {\n frame: lastFrame,\n value: this._workingVector,\n },\n ];\n animationCameraTeleportation.setKeys(animationCameraTeleportationKeys);\n animationCameraTeleportation.setEasingFunction(this._teleportationEasing);\n this.currentVRCamera.animations.push(animationCameraTeleportation);\n this._postProcessMove.animations = [];\n // Calculate the mid frame for vignette animations\n const midFrame = Math.round(lastFrame / 2);\n const animationPP = new Animation(\"animationPP\", \"vignetteWeight\", FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const vignetteWeightKeys = [];\n vignetteWeightKeys.push({\n frame: 0,\n value: 0,\n });\n vignetteWeightKeys.push({\n frame: midFrame,\n value: 8,\n });\n vignetteWeightKeys.push({\n frame: lastFrame,\n value: 0,\n });\n animationPP.setKeys(vignetteWeightKeys);\n this._postProcessMove.animations.push(animationPP);\n const animationPP2 = new Animation(\"animationPP2\", \"vignetteStretch\", FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const vignetteStretchKeys = [];\n vignetteStretchKeys.push({\n frame: 0,\n value: 0,\n });\n vignetteStretchKeys.push({\n frame: midFrame,\n value: 10,\n });\n vignetteStretchKeys.push({\n frame: lastFrame,\n value: 0,\n });\n animationPP2.setKeys(vignetteStretchKeys);\n this._postProcessMove.animations.push(animationPP2);\n this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;\n this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;\n this._webVRCamera.attachPostProcess(this._postProcessMove);\n this._scene.beginAnimation(this._postProcessMove, 0, lastFrame, false, speedRatio, () => {\n this._webVRCamera.detachPostProcess(this._postProcessMove);\n });\n this._scene.beginAnimation(this.currentVRCamera, 0, lastFrame, false, speedRatio, () => {\n this.onAfterCameraTeleport.notifyObservers(this._workingVector);\n });\n this._hideTeleportationTarget();\n }\n _convertNormalToDirectionOfRay(normal, ray) {\n if (normal) {\n const angle = Math.acos(Vector3.Dot(normal, ray.direction));\n if (angle < Math.PI / 2) {\n normal.scaleInPlace(-1);\n }\n }\n return normal;\n }\n _castRayAndSelectObject(gazer) {\n if (!(this.currentVRCamera instanceof FreeCamera)) {\n return;\n }\n const ray = gazer._getForwardRay(this._rayLength);\n const hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);\n if (hit) {\n this._scene.simulatePointerMove(hit, { pointerId: gazer._id });\n }\n gazer._currentHit = hit;\n // Moving the gazeTracker on the mesh face targetted\n if (hit && hit.pickedPoint) {\n if (this._displayGaze) {\n let multiplier = 1;\n gazer._gazeTracker.isVisible = true;\n if (gazer._isActionableMesh) {\n multiplier = 3;\n }\n if (this.updateGazeTrackerScale) {\n gazer._gazeTracker.scaling.x = hit.distance * multiplier;\n gazer._gazeTracker.scaling.y = hit.distance * multiplier;\n gazer._gazeTracker.scaling.z = hit.distance * multiplier;\n }\n const pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);\n // To avoid z-fighting\n const deltaFighting = 0.002;\n if (pickNormal) {\n const axis1 = Vector3.Cross(Axis.Y, pickNormal);\n const axis2 = Vector3.Cross(pickNormal, axis1);\n Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, gazer._gazeTracker.rotation);\n }\n gazer._gazeTracker.position.copyFrom(hit.pickedPoint);\n if (gazer._gazeTracker.position.x < 0) {\n gazer._gazeTracker.position.x += deltaFighting;\n }\n else {\n gazer._gazeTracker.position.x -= deltaFighting;\n }\n if (gazer._gazeTracker.position.y < 0) {\n gazer._gazeTracker.position.y += deltaFighting;\n }\n else {\n gazer._gazeTracker.position.y -= deltaFighting;\n }\n if (gazer._gazeTracker.position.z < 0) {\n gazer._gazeTracker.position.z += deltaFighting;\n }\n else {\n gazer._gazeTracker.position.z -= deltaFighting;\n }\n }\n // Changing the size of the laser pointer based on the distance from the targetted point\n gazer._updatePointerDistance(hit.distance);\n }\n else {\n gazer._updatePointerDistance();\n gazer._gazeTracker.isVisible = false;\n }\n if (hit && hit.pickedMesh) {\n // The object selected is the floor, we're in a teleportation scenario\n if (this._teleportationInitialized && this._isTeleportationFloor(hit.pickedMesh) && hit.pickedPoint) {\n // Moving the teleportation area to this targetted point\n //Raise onSelectedMeshUnselected observable if ray collided floor mesh/meshes and a non floor mesh was previously selected\n if (gazer._currentMeshSelected && !this._isTeleportationFloor(gazer._currentMeshSelected)) {\n this._notifySelectedMeshUnselected(gazer._currentMeshSelected);\n }\n gazer._currentMeshSelected = null;\n if (gazer._teleportationRequestInitiated) {\n this._moveTeleportationSelectorTo(hit, gazer, ray);\n }\n return;\n }\n // If not, we're in a selection scenario\n //this._teleportationAllowed = false;\n if (hit.pickedMesh !== gazer._currentMeshSelected) {\n if (this.meshSelectionPredicate(hit.pickedMesh)) {\n this.onNewMeshPicked.notifyObservers(hit);\n gazer._currentMeshSelected = hit.pickedMesh;\n if (hit.pickedMesh.isPickable && hit.pickedMesh.actionManager) {\n this.changeGazeColor(this._pickedGazeColor);\n this.changeLaserColor(this._pickedLaserColor);\n gazer._isActionableMesh = true;\n }\n else {\n this.changeGazeColor(this._gazeColor);\n this.changeLaserColor(this._laserColor);\n gazer._isActionableMesh = false;\n }\n try {\n this.onNewMeshSelected.notifyObservers(hit.pickedMesh);\n const gazerAsControllerGazer = gazer;\n if (gazerAsControllerGazer.webVRController) {\n this.onMeshSelectedWithController.notifyObservers({ mesh: hit.pickedMesh, controller: gazerAsControllerGazer.webVRController });\n }\n }\n catch (err) {\n Logger.Warn(\"Error while raising onNewMeshSelected or onMeshSelectedWithController: \" + err);\n }\n }\n else {\n this._notifySelectedMeshUnselected(gazer._currentMeshSelected);\n gazer._currentMeshSelected = null;\n this.changeGazeColor(this._gazeColor);\n this.changeLaserColor(this._laserColor);\n }\n }\n }\n else {\n this._notifySelectedMeshUnselected(gazer._currentMeshSelected);\n gazer._currentMeshSelected = null;\n //this._teleportationAllowed = false;\n this.changeGazeColor(this._gazeColor);\n this.changeLaserColor(this._laserColor);\n }\n }\n _notifySelectedMeshUnselected(mesh) {\n if (mesh) {\n this.onSelectedMeshUnselected.notifyObservers(mesh);\n }\n }\n /**\n * Permanently set new colors for the laser pointer\n * @param color the new laser color\n * @param pickedColor the new laser color when picked mesh detected\n */\n setLaserColor(color, pickedColor = this._pickedLaserColor) {\n this._laserColor = color;\n this._pickedLaserColor = pickedColor;\n }\n /**\n * Set lighting enabled / disabled on the laser pointer of both controllers\n * @param enabled should the lighting be enabled on the laser pointer\n */\n setLaserLightingState(enabled = true) {\n if (this._leftController) {\n this._leftController._setLaserPointerLightingDisabled(!enabled);\n }\n if (this._rightController) {\n this._rightController._setLaserPointerLightingDisabled(!enabled);\n }\n }\n /**\n * Permanently set new colors for the gaze pointer\n * @param color the new gaze color\n * @param pickedColor the new gaze color when picked mesh detected\n */\n setGazeColor(color, pickedColor = this._pickedGazeColor) {\n this._gazeColor = color;\n this._pickedGazeColor = pickedColor;\n }\n /**\n * Sets the color of the laser ray from the vr controllers.\n * @param color new color for the ray.\n */\n changeLaserColor(color) {\n if (!this.updateControllerLaserColor) {\n return;\n }\n if (this._leftController) {\n this._leftController._setLaserPointerColor(color);\n }\n if (this._rightController) {\n this._rightController._setLaserPointerColor(color);\n }\n }\n /**\n * Sets the color of the ray from the vr headsets gaze.\n * @param color new color for the ray.\n */\n changeGazeColor(color) {\n if (!this.updateGazeTrackerColor) {\n return;\n }\n if (!this._cameraGazer._gazeTracker.material) {\n return;\n }\n this._cameraGazer._gazeTracker.material.emissiveColor = color;\n if (this._leftController) {\n this._leftController._gazeTracker.material.emissiveColor = color;\n }\n if (this._rightController) {\n this._rightController._gazeTracker.material.emissiveColor = color;\n }\n }\n /**\n * Exits VR and disposes of the vr experience helper\n */\n dispose() {\n if (this.isInVRMode) {\n this.exitVR();\n }\n if (this._postProcessMove) {\n this._postProcessMove.dispose();\n }\n if (this._webVRCamera) {\n this._webVRCamera.dispose();\n }\n if (this._vrDeviceOrientationCamera) {\n this._vrDeviceOrientationCamera.dispose();\n }\n if (!this._useCustomVRButton && this._btnVR && this._btnVR.parentNode) {\n document.body.removeChild(this._btnVR);\n }\n if (this._deviceOrientationCamera && this._scene.activeCamera != this._deviceOrientationCamera) {\n this._deviceOrientationCamera.dispose();\n }\n if (this._cameraGazer) {\n this._cameraGazer.dispose();\n }\n if (this._leftController) {\n this._leftController.dispose();\n }\n if (this._rightController) {\n this._rightController.dispose();\n }\n if (this._teleportationTarget) {\n this._teleportationTarget.dispose();\n }\n if (this.xr) {\n this.xr.dispose();\n }\n this._floorMeshesCollection.length = 0;\n document.removeEventListener(\"keydown\", this._onKeyDown);\n window.removeEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChangeBind);\n window.removeEventListener(\"resize\", this._onResize);\n document.removeEventListener(\"fullscreenchange\", this._onFullscreenChange);\n this._scene.getEngine().onVRDisplayChangedObservable.removeCallback(this._onVRDisplayChangedBind);\n this._scene.getEngine().onVRRequestPresentStart.removeCallback(this._onVRRequestPresentStart);\n this._scene.getEngine().onVRRequestPresentComplete.removeCallback(this._onVRRequestPresentComplete);\n this._scene.gamepadManager.onGamepadConnectedObservable.removeCallback(this._onNewGamepadConnected);\n this._scene.gamepadManager.onGamepadDisconnectedObservable.removeCallback(this._onNewGamepadDisconnected);\n this._scene.unregisterBeforeRender(this._beforeRender);\n }\n /**\n * Gets the name of the VRExperienceHelper class\n * @returns \"VRExperienceHelper\"\n */\n getClassName() {\n return \"VRExperienceHelper\";\n }\n }\n /**\n * Time Constant Teleportation Mode\n */\n VRExperienceHelper.TELEPORTATIONMODE_CONSTANTTIME = 0;\n /**\n * Speed Constant Teleportation Mode\n */\n VRExperienceHelper.TELEPORTATIONMODE_CONSTANTSPEED = 1;\n\n /* eslint-disable @typescript-eslint/naming-convention */\n // Based on demo done by Brandon Jones - http://media.tojicode.com/webgl-samples/dds.html\n // All values and structures referenced from:\n // http://msdn.microsoft.com/en-us/library/bb943991.aspx/\n const DDS_MAGIC = 0x20534444;\n const //DDSD_CAPS = 0x1,\n //DDSD_HEIGHT = 0x2,\n //DDSD_WIDTH = 0x4,\n //DDSD_PITCH = 0x8,\n //DDSD_PIXELFORMAT = 0x1000,\n DDSD_MIPMAPCOUNT = 0x20000;\n //DDSD_LINEARSIZE = 0x80000,\n //DDSD_DEPTH = 0x800000;\n // var DDSCAPS_COMPLEX = 0x8,\n // DDSCAPS_MIPMAP = 0x400000,\n // DDSCAPS_TEXTURE = 0x1000;\n const DDSCAPS2_CUBEMAP = 0x200;\n // DDSCAPS2_CUBEMAP_POSITIVEX = 0x400,\n // DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800,\n // DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000,\n // DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000,\n // DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000,\n // DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000,\n // DDSCAPS2_VOLUME = 0x200000;\n const //DDPF_ALPHAPIXELS = 0x1,\n //DDPF_ALPHA = 0x2,\n DDPF_FOURCC = 0x4, DDPF_RGB = 0x40, \n //DDPF_YUV = 0x200,\n DDPF_LUMINANCE = 0x20000;\n function FourCCToInt32(value) {\n return value.charCodeAt(0) + (value.charCodeAt(1) << 8) + (value.charCodeAt(2) << 16) + (value.charCodeAt(3) << 24);\n }\n function Int32ToFourCC(value) {\n return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff);\n }\n const FOURCC_DXT1 = FourCCToInt32(\"DXT1\");\n const FOURCC_DXT3 = FourCCToInt32(\"DXT3\");\n const FOURCC_DXT5 = FourCCToInt32(\"DXT5\");\n const FOURCC_DX10 = FourCCToInt32(\"DX10\");\n const FOURCC_D3DFMT_R16G16B16A16F = 113;\n const FOURCC_D3DFMT_R32G32B32A32F = 116;\n const DXGI_FORMAT_R32G32B32A32_FLOAT = 2;\n const DXGI_FORMAT_R16G16B16A16_FLOAT = 10;\n const DXGI_FORMAT_B8G8R8X8_UNORM = 88;\n const headerLengthInt = 31; // The header length in 32 bit ints\n // Offsets into the header array\n const off_magic = 0;\n const off_size = 1;\n const off_flags = 2;\n const off_height = 3;\n const off_width = 4;\n const off_mipmapCount = 7;\n const off_pfFlags = 20;\n const off_pfFourCC = 21;\n const off_RGBbpp = 22;\n const off_RMask = 23;\n const off_GMask = 24;\n const off_BMask = 25;\n const off_AMask = 26;\n // var off_caps1 = 27;\n const off_caps2 = 28;\n // var off_caps3 = 29;\n // var off_caps4 = 30;\n const off_dxgiFormat = 32;\n /**\n * Class used to provide DDS decompression tools\n */\n class DDSTools {\n /**\n * Gets DDS information from an array buffer\n * @param data defines the array buffer view to read data from\n * @returns the DDS information\n */\n static GetDDSInfo(data) {\n const header = new Int32Array(data.buffer, data.byteOffset, headerLengthInt);\n const extendedHeader = new Int32Array(data.buffer, data.byteOffset, headerLengthInt + 4);\n let mipmapCount = 1;\n if (header[off_flags] & DDSD_MIPMAPCOUNT) {\n mipmapCount = Math.max(1, header[off_mipmapCount]);\n }\n const fourCC = header[off_pfFourCC];\n const dxgiFormat = fourCC === FOURCC_DX10 ? extendedHeader[off_dxgiFormat] : 0;\n let textureType = 0;\n switch (fourCC) {\n case FOURCC_D3DFMT_R16G16B16A16F:\n textureType = 2;\n break;\n case FOURCC_D3DFMT_R32G32B32A32F:\n textureType = 1;\n break;\n case FOURCC_DX10:\n if (dxgiFormat === DXGI_FORMAT_R16G16B16A16_FLOAT) {\n textureType = 2;\n break;\n }\n if (dxgiFormat === DXGI_FORMAT_R32G32B32A32_FLOAT) {\n textureType = 1;\n break;\n }\n }\n return {\n width: header[off_width],\n height: header[off_height],\n mipmapCount: mipmapCount,\n isFourCC: (header[off_pfFlags] & DDPF_FOURCC) === DDPF_FOURCC,\n isRGB: (header[off_pfFlags] & DDPF_RGB) === DDPF_RGB,\n isLuminance: (header[off_pfFlags] & DDPF_LUMINANCE) === DDPF_LUMINANCE,\n isCube: (header[off_caps2] & DDSCAPS2_CUBEMAP) === DDSCAPS2_CUBEMAP,\n isCompressed: fourCC === FOURCC_DXT1 || fourCC === FOURCC_DXT3 || fourCC === FOURCC_DXT5,\n dxgiFormat: dxgiFormat,\n textureType: textureType,\n };\n }\n static _GetHalfFloatAsFloatRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, lod) {\n const destArray = new Float32Array(dataLength);\n const srcData = new Uint16Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 4;\n destArray[index] = FromHalfFloat(srcData[srcPos]);\n destArray[index + 1] = FromHalfFloat(srcData[srcPos + 1]);\n destArray[index + 2] = FromHalfFloat(srcData[srcPos + 2]);\n if (DDSTools.StoreLODInAlphaChannel) {\n destArray[index + 3] = lod;\n }\n else {\n destArray[index + 3] = FromHalfFloat(srcData[srcPos + 3]);\n }\n index += 4;\n }\n }\n return destArray;\n }\n static _GetHalfFloatRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, lod) {\n if (DDSTools.StoreLODInAlphaChannel) {\n const destArray = new Uint16Array(dataLength);\n const srcData = new Uint16Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 4;\n destArray[index] = srcData[srcPos];\n destArray[index + 1] = srcData[srcPos + 1];\n destArray[index + 2] = srcData[srcPos + 2];\n destArray[index + 3] = ToHalfFloat(lod);\n index += 4;\n }\n }\n return destArray;\n }\n return new Uint16Array(arrayBuffer, dataOffset, dataLength);\n }\n static _GetFloatRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, lod) {\n if (DDSTools.StoreLODInAlphaChannel) {\n const destArray = new Float32Array(dataLength);\n const srcData = new Float32Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 4;\n destArray[index] = srcData[srcPos];\n destArray[index + 1] = srcData[srcPos + 1];\n destArray[index + 2] = srcData[srcPos + 2];\n destArray[index + 3] = lod;\n index += 4;\n }\n }\n return destArray;\n }\n return new Float32Array(arrayBuffer, dataOffset, dataLength);\n }\n static _GetFloatAsHalfFloatRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, lod) {\n const destArray = new Uint16Array(dataLength);\n const srcData = new Float32Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n destArray[index] = ToHalfFloat(srcData[index]);\n destArray[index + 1] = ToHalfFloat(srcData[index + 1]);\n destArray[index + 2] = ToHalfFloat(srcData[index + 2]);\n if (DDSTools.StoreLODInAlphaChannel) {\n destArray[index + 3] = ToHalfFloat(lod);\n }\n else {\n destArray[index + 3] = ToHalfFloat(srcData[index + 3]);\n }\n index += 4;\n }\n }\n return destArray;\n }\n static _GetFloatAsUIntRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, lod) {\n const destArray = new Uint8Array(dataLength);\n const srcData = new Float32Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 4;\n destArray[index] = Scalar.Clamp(srcData[srcPos]) * 255;\n destArray[index + 1] = Scalar.Clamp(srcData[srcPos + 1]) * 255;\n destArray[index + 2] = Scalar.Clamp(srcData[srcPos + 2]) * 255;\n if (DDSTools.StoreLODInAlphaChannel) {\n destArray[index + 3] = lod;\n }\n else {\n destArray[index + 3] = Scalar.Clamp(srcData[srcPos + 3]) * 255;\n }\n index += 4;\n }\n }\n return destArray;\n }\n static _GetHalfFloatAsUIntRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, lod) {\n const destArray = new Uint8Array(dataLength);\n const srcData = new Uint16Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 4;\n destArray[index] = Scalar.Clamp(FromHalfFloat(srcData[srcPos])) * 255;\n destArray[index + 1] = Scalar.Clamp(FromHalfFloat(srcData[srcPos + 1])) * 255;\n destArray[index + 2] = Scalar.Clamp(FromHalfFloat(srcData[srcPos + 2])) * 255;\n if (DDSTools.StoreLODInAlphaChannel) {\n destArray[index + 3] = lod;\n }\n else {\n destArray[index + 3] = Scalar.Clamp(FromHalfFloat(srcData[srcPos + 3])) * 255;\n }\n index += 4;\n }\n }\n return destArray;\n }\n static _GetRGBAArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, rOffset, gOffset, bOffset, aOffset) {\n const byteArray = new Uint8Array(dataLength);\n const srcData = new Uint8Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 4;\n byteArray[index] = srcData[srcPos + rOffset];\n byteArray[index + 1] = srcData[srcPos + gOffset];\n byteArray[index + 2] = srcData[srcPos + bOffset];\n byteArray[index + 3] = srcData[srcPos + aOffset];\n index += 4;\n }\n }\n return byteArray;\n }\n static _ExtractLongWordOrder(value) {\n if (value === 0 || value === 255 || value === -16777216) {\n return 0;\n }\n return 1 + DDSTools._ExtractLongWordOrder(value >> 8);\n }\n static _GetRGBArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer, rOffset, gOffset, bOffset) {\n const byteArray = new Uint8Array(dataLength);\n const srcData = new Uint8Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = (x + y * width) * 3;\n byteArray[index] = srcData[srcPos + rOffset];\n byteArray[index + 1] = srcData[srcPos + gOffset];\n byteArray[index + 2] = srcData[srcPos + bOffset];\n index += 3;\n }\n }\n return byteArray;\n }\n static _GetLuminanceArrayBuffer(width, height, dataOffset, dataLength, arrayBuffer) {\n const byteArray = new Uint8Array(dataLength);\n const srcData = new Uint8Array(arrayBuffer, dataOffset);\n let index = 0;\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const srcPos = x + y * width;\n byteArray[index] = srcData[srcPos];\n index++;\n }\n }\n return byteArray;\n }\n /**\n * Uploads DDS Levels to a Babylon Texture\n * @internal\n */\n static UploadDDSLevels(engine, texture, data, info, loadMipmaps, faces, lodIndex = -1, currentFace, destTypeMustBeFilterable = true) {\n let sphericalPolynomialFaces = null;\n if (info.sphericalPolynomial) {\n sphericalPolynomialFaces = new Array();\n }\n const ext = !!engine.getCaps().s3tc;\n // TODO WEBGPU Once generateMipMaps is split into generateMipMaps + hasMipMaps in InternalTexture this line can be removed\n texture.generateMipMaps = loadMipmaps;\n const header = new Int32Array(data.buffer, data.byteOffset, headerLengthInt);\n let fourCC, width, height, dataLength = 0, dataOffset;\n let byteArray, mipmapCount, mip;\n let internalCompressedFormat = 0;\n let blockBytes = 1;\n if (header[off_magic] !== DDS_MAGIC) {\n Logger.Error(\"Invalid magic number in DDS header\");\n return;\n }\n if (!info.isFourCC && !info.isRGB && !info.isLuminance) {\n Logger.Error(\"Unsupported format, must contain a FourCC, RGB or LUMINANCE code\");\n return;\n }\n if (info.isCompressed && !ext) {\n Logger.Error(\"Compressed textures are not supported on this platform.\");\n return;\n }\n let bpp = header[off_RGBbpp];\n dataOffset = header[off_size] + 4;\n let computeFormats = false;\n if (info.isFourCC) {\n fourCC = header[off_pfFourCC];\n switch (fourCC) {\n case FOURCC_DXT1:\n blockBytes = 8;\n internalCompressedFormat = 33777;\n break;\n case FOURCC_DXT3:\n blockBytes = 16;\n internalCompressedFormat = 33778;\n break;\n case FOURCC_DXT5:\n blockBytes = 16;\n internalCompressedFormat = 33779;\n break;\n case FOURCC_D3DFMT_R16G16B16A16F:\n computeFormats = true;\n bpp = 64;\n break;\n case FOURCC_D3DFMT_R32G32B32A32F:\n computeFormats = true;\n bpp = 128;\n break;\n case FOURCC_DX10: {\n // There is an additionnal header so dataOffset need to be changed\n dataOffset += 5 * 4; // 5 uints\n let supported = false;\n switch (info.dxgiFormat) {\n case DXGI_FORMAT_R16G16B16A16_FLOAT:\n computeFormats = true;\n bpp = 64;\n supported = true;\n break;\n case DXGI_FORMAT_R32G32B32A32_FLOAT:\n computeFormats = true;\n bpp = 128;\n supported = true;\n break;\n case DXGI_FORMAT_B8G8R8X8_UNORM:\n info.isRGB = true;\n info.isFourCC = false;\n bpp = 32;\n supported = true;\n break;\n }\n if (supported) {\n break;\n }\n }\n // eslint-disable-next-line no-fallthrough\n default:\n console.error(\"Unsupported FourCC code:\", Int32ToFourCC(fourCC));\n return;\n }\n }\n const rOffset = DDSTools._ExtractLongWordOrder(header[off_RMask]);\n const gOffset = DDSTools._ExtractLongWordOrder(header[off_GMask]);\n const bOffset = DDSTools._ExtractLongWordOrder(header[off_BMask]);\n const aOffset = DDSTools._ExtractLongWordOrder(header[off_AMask]);\n if (computeFormats) {\n internalCompressedFormat = engine._getRGBABufferInternalSizedFormat(info.textureType);\n }\n mipmapCount = 1;\n if (header[off_flags] & DDSD_MIPMAPCOUNT && loadMipmaps !== false) {\n mipmapCount = Math.max(1, header[off_mipmapCount]);\n }\n const startFace = currentFace || 0;\n const caps = engine.getCaps();\n for (let face = startFace; face < faces; face++) {\n width = header[off_width];\n height = header[off_height];\n for (mip = 0; mip < mipmapCount; ++mip) {\n if (lodIndex === -1 || lodIndex === mip) {\n // In case of fixed LOD, if the lod has just been uploaded, early exit.\n const i = lodIndex === -1 ? mip : 0;\n if (!info.isCompressed && info.isFourCC) {\n texture.format = 5;\n dataLength = width * height * 4;\n let floatArray = null;\n if (engine._badOS || engine._badDesktopOS || (!caps.textureHalfFloat && !caps.textureFloat)) {\n // Required because iOS has many issues with float and half float generation\n if (bpp === 128) {\n floatArray = DDSTools._GetFloatAsUIntRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i);\n if (sphericalPolynomialFaces && i == 0) {\n sphericalPolynomialFaces.push(DDSTools._GetFloatRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i));\n }\n }\n else if (bpp === 64) {\n floatArray = DDSTools._GetHalfFloatAsUIntRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i);\n if (sphericalPolynomialFaces && i == 0) {\n sphericalPolynomialFaces.push(DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i));\n }\n }\n texture.type = 0;\n }\n else {\n const floatAvailable = caps.textureFloat && ((destTypeMustBeFilterable && caps.textureFloatLinearFiltering) || !destTypeMustBeFilterable);\n const halfFloatAvailable = caps.textureHalfFloat && ((destTypeMustBeFilterable && caps.textureHalfFloatLinearFiltering) || !destTypeMustBeFilterable);\n const destType = (bpp === 128 || (bpp === 64 && !halfFloatAvailable)) && floatAvailable\n ? 1\n : (bpp === 64 || (bpp === 128 && !floatAvailable)) && halfFloatAvailable\n ? 2\n : 0;\n let dataGetter;\n let dataGetterPolynomial = null;\n switch (bpp) {\n case 128: {\n switch (destType) {\n case 1:\n dataGetter = DDSTools._GetFloatRGBAArrayBuffer;\n dataGetterPolynomial = null;\n break;\n case 2:\n dataGetter = DDSTools._GetFloatAsHalfFloatRGBAArrayBuffer;\n dataGetterPolynomial = DDSTools._GetFloatRGBAArrayBuffer;\n break;\n case 0:\n dataGetter = DDSTools._GetFloatAsUIntRGBAArrayBuffer;\n dataGetterPolynomial = DDSTools._GetFloatRGBAArrayBuffer;\n break;\n }\n break;\n }\n default: {\n // 64 bpp\n switch (destType) {\n case 1:\n dataGetter = DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer;\n dataGetterPolynomial = null;\n break;\n case 2:\n dataGetter = DDSTools._GetHalfFloatRGBAArrayBuffer;\n dataGetterPolynomial = DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer;\n break;\n case 0:\n dataGetter = DDSTools._GetHalfFloatAsUIntRGBAArrayBuffer;\n dataGetterPolynomial = DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer;\n break;\n }\n break;\n }\n }\n texture.type = destType;\n floatArray = dataGetter(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i);\n if (sphericalPolynomialFaces && i == 0) {\n sphericalPolynomialFaces.push(dataGetterPolynomial ? dataGetterPolynomial(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i) : floatArray);\n }\n }\n if (floatArray) {\n engine._uploadDataToTextureDirectly(texture, floatArray, face, i);\n }\n }\n else if (info.isRGB) {\n texture.type = 0;\n if (bpp === 24) {\n texture.format = 4;\n dataLength = width * height * 3;\n byteArray = DDSTools._GetRGBArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, rOffset, gOffset, bOffset);\n engine._uploadDataToTextureDirectly(texture, byteArray, face, i);\n }\n else {\n // 32\n texture.format = 5;\n dataLength = width * height * 4;\n byteArray = DDSTools._GetRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, rOffset, gOffset, bOffset, aOffset);\n engine._uploadDataToTextureDirectly(texture, byteArray, face, i);\n }\n }\n else if (info.isLuminance) {\n const unpackAlignment = engine._getUnpackAlignement();\n const unpaddedRowSize = width;\n const paddedRowSize = Math.floor((width + unpackAlignment - 1) / unpackAlignment) * unpackAlignment;\n dataLength = paddedRowSize * (height - 1) + unpaddedRowSize;\n byteArray = DDSTools._GetLuminanceArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer);\n texture.format = 1;\n texture.type = 0;\n engine._uploadDataToTextureDirectly(texture, byteArray, face, i);\n }\n else {\n dataLength = (((Math.max(4, width) / 4) * Math.max(4, height)) / 4) * blockBytes;\n byteArray = new Uint8Array(data.buffer, data.byteOffset + dataOffset, dataLength);\n texture.type = 0;\n engine._uploadCompressedDataToTextureDirectly(texture, internalCompressedFormat, width, height, byteArray, face, i);\n }\n }\n dataOffset += bpp ? width * height * (bpp / 8) : dataLength;\n width *= 0.5;\n height *= 0.5;\n width = Math.max(1.0, width);\n height = Math.max(1.0, height);\n }\n if (currentFace !== undefined) {\n // Loading a single face\n break;\n }\n }\n if (sphericalPolynomialFaces && sphericalPolynomialFaces.length > 0) {\n info.sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial({\n size: header[off_width],\n right: sphericalPolynomialFaces[0],\n left: sphericalPolynomialFaces[1],\n up: sphericalPolynomialFaces[2],\n down: sphericalPolynomialFaces[3],\n front: sphericalPolynomialFaces[4],\n back: sphericalPolynomialFaces[5],\n format: 5,\n type: 1,\n gammaSpace: false,\n });\n }\n else {\n info.sphericalPolynomial = undefined;\n }\n }\n }\n /**\n * Gets or sets a boolean indicating that LOD info is stored in alpha channel (false by default)\n */\n DDSTools.StoreLODInAlphaChannel = false;\n /**\n * Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)\n * @param rootUrl defines the url where the file to load is located\n * @param scene defines the current scene\n * @param lodScale defines scale to apply to the mip map selection\n * @param lodOffset defines offset to apply to the mip map selection\n * @param onLoad defines an optional callback raised when the texture is loaded\n * @param onError defines an optional callback raised if there is an issue to load the texture\n * @param format defines the format of the data\n * @param forcedExtension defines the extension to use to pick the right loader\n * @param createPolynomials defines wheter or not to create polynomails harmonics for the texture\n * @returns the cube texture as an InternalTexture\n */\n ThinEngine.prototype.createPrefilteredCubeTexture = function (rootUrl, scene, lodScale, lodOffset, onLoad = null, onError = null, format, forcedExtension = null, createPolynomials = true) {\n const callback = (loadData) => {\n if (!loadData) {\n if (onLoad) {\n onLoad(null);\n }\n return;\n }\n const texture = loadData.texture;\n if (!createPolynomials) {\n texture._sphericalPolynomial = new SphericalPolynomial();\n }\n else if (loadData.info.sphericalPolynomial) {\n texture._sphericalPolynomial = loadData.info.sphericalPolynomial;\n }\n texture._source = InternalTextureSource.CubePrefiltered;\n if (this.getCaps().textureLOD) {\n // Do not add extra process if texture lod is supported.\n if (onLoad) {\n onLoad(texture);\n }\n return;\n }\n const mipSlices = 3;\n const gl = this._gl;\n const width = loadData.width;\n if (!width) {\n return;\n }\n const textures = [];\n for (let i = 0; i < mipSlices; i++) {\n //compute LOD from even spacing in smoothness (matching shader calculation)\n const smoothness = i / (mipSlices - 1);\n const roughness = 1 - smoothness;\n const minLODIndex = lodOffset; // roughness = 0\n const maxLODIndex = Scalar.Log2(width) * lodScale + lodOffset; // roughness = 1\n const lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;\n const mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));\n const glTextureFromLod = new InternalTexture(this, InternalTextureSource.Temp);\n glTextureFromLod.type = texture.type;\n glTextureFromLod.format = texture.format;\n glTextureFromLod.width = Math.pow(2, Math.max(Scalar.Log2(width) - mipmapIndex, 0));\n glTextureFromLod.height = glTextureFromLod.width;\n glTextureFromLod.isCube = true;\n glTextureFromLod._cachedWrapU = 0;\n glTextureFromLod._cachedWrapV = 0;\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod, true);\n glTextureFromLod.samplingMode = 2;\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n if (loadData.isDDS) {\n const info = loadData.info;\n const data = loadData.data;\n this._unpackFlipY(info.isCompressed);\n DDSTools.UploadDDSLevels(this, glTextureFromLod, data, info, true, 6, mipmapIndex);\n }\n else {\n Logger.Warn(\"DDS is the only prefiltered cube map supported so far.\");\n }\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n // Wrap in a base texture for easy binding.\n const lodTexture = new BaseTexture(scene);\n lodTexture._isCube = true;\n lodTexture._texture = glTextureFromLod;\n glTextureFromLod.isReady = true;\n textures.push(lodTexture);\n }\n texture._lodTextureHigh = textures[2];\n texture._lodTextureMid = textures[1];\n texture._lodTextureLow = textures[0];\n if (onLoad) {\n onLoad(texture);\n }\n };\n return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset);\n };\n\n /**\n * Implementation of the DDS Texture Loader.\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _DDSTextureLoader {\n constructor() {\n /**\n * Defines whether the loader supports cascade loading the different faces.\n */\n this.supportCascades = true;\n }\n /**\n * This returns if the loader support the current file information.\n * @param extension defines the file extension of the file being loaded\n * @returns true if the loader can load the specified file\n */\n canLoad(extension) {\n return extension.endsWith(\".dds\");\n }\n /**\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\n * @param imgs contains the cube maps\n * @param texture defines the BabylonJS internal texture\n * @param createPolynomials will be true if polynomials have been requested\n * @param onLoad defines the callback to trigger once the texture is ready\n */\n loadCubeData(imgs, texture, createPolynomials, onLoad) {\n const engine = texture.getEngine();\n let info;\n let loadMipmap = false;\n let maxLevel = 1000;\n if (Array.isArray(imgs)) {\n for (let index = 0; index < imgs.length; index++) {\n const data = imgs[index];\n info = DDSTools.GetDDSInfo(data);\n texture.width = info.width;\n texture.height = info.height;\n loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && texture.generateMipMaps;\n engine._unpackFlipY(info.isCompressed);\n DDSTools.UploadDDSLevels(engine, texture, data, info, loadMipmap, 6, -1, index);\n if (!info.isFourCC && info.mipmapCount === 1) {\n engine.generateMipMapsForCubemap(texture);\n }\n else {\n maxLevel = info.mipmapCount - 1;\n }\n }\n }\n else {\n const data = imgs;\n info = DDSTools.GetDDSInfo(data);\n texture.width = info.width;\n texture.height = info.height;\n if (createPolynomials) {\n info.sphericalPolynomial = new SphericalPolynomial();\n }\n loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && texture.generateMipMaps;\n engine._unpackFlipY(info.isCompressed);\n DDSTools.UploadDDSLevels(engine, texture, data, info, loadMipmap, 6);\n if (!info.isFourCC && info.mipmapCount === 1) {\n // Do not unbind as we still need to set the parameters.\n engine.generateMipMapsForCubemap(texture, false);\n }\n else {\n maxLevel = info.mipmapCount - 1;\n }\n }\n engine._setCubeMapTextureParams(texture, loadMipmap, maxLevel);\n texture.isReady = true;\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n if (onLoad) {\n onLoad({ isDDS: true, width: texture.width, info, data: imgs, texture });\n }\n }\n /**\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param callback defines the method to call once ready to upload\n */\n loadData(data, texture, callback) {\n const info = DDSTools.GetDDSInfo(data);\n const loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && texture.generateMipMaps && info.width >> (info.mipmapCount - 1) === 1;\n callback(info.width, info.height, loadMipmap, info.isFourCC, () => {\n DDSTools.UploadDDSLevels(texture.getEngine(), texture, data, info, loadMipmap, 1);\n });\n }\n }\n // Register the loader.\n Engine._TextureLoaders.push(new _DDSTextureLoader());\n\n // Do not edit.\n const name$1W = \"rgbdEncodePixelShader\";\n const shader$1W = `varying vec2 vUV;uniform sampler2D textureSampler;\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{gl_FragColor=toRGBD(texture2D(textureSampler,vUV).rgb);}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1W] = shader$1W;\n\n const DefaultEnvironmentTextureImageType = \"image/png\";\n const CurrentVersion = 2;\n /**\n * Magic number identifying the env file.\n */\n const MagicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];\n /**\n * Gets the environment info from an env file.\n * @param data The array buffer containing the .env bytes.\n * @returns the environment file info (the json header) if successfully parsed, normalized to the latest supported version.\n */\n function GetEnvInfo(data) {\n const dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);\n let pos = 0;\n for (let i = 0; i < MagicBytes.length; i++) {\n if (dataView.getUint8(pos++) !== MagicBytes[i]) {\n Logger.Error(\"Not a babylon environment map\");\n return null;\n }\n }\n // Read json manifest - collect characters up to null terminator\n let manifestString = \"\";\n let charCode = 0x00;\n while ((charCode = dataView.getUint8(pos++))) {\n manifestString += String.fromCharCode(charCode);\n }\n let manifest = JSON.parse(manifestString);\n manifest = normalizeEnvInfo(manifest);\n if (manifest.specular) {\n // Extend the header with the position of the payload.\n manifest.specular.specularDataPosition = pos;\n // Fallback to 0.8 exactly if lodGenerationScale is not defined for backward compatibility.\n manifest.specular.lodGenerationScale = manifest.specular.lodGenerationScale || 0.8;\n }\n return manifest;\n }\n /**\n * Normalizes any supported version of the environment file info to the latest version\n * @param info environment file info on any supported version\n * @returns environment file info in the latest supported version\n * @private\n */\n function normalizeEnvInfo(info) {\n if (info.version > CurrentVersion) {\n throw new Error(`Unsupported babylon environment map version \"${info.version}\". Latest supported version is \"${CurrentVersion}\".`);\n }\n if (info.version === 2) {\n return info;\n }\n // Migrate a v1 info to v2\n info = Object.assign(Object.assign({}, info), { version: 2, imageType: DefaultEnvironmentTextureImageType });\n return info;\n }\n /**\n * Creates an environment texture from a loaded cube texture.\n * @param texture defines the cube texture to convert in env file\n * @param options options for the conversion process\n * @param options.imageType the mime type for the encoded images, with support for \"image/png\" (default) and \"image/webp\"\n * @param options.imageQuality the image quality of encoded WebP images.\n * @returns a promise containing the environment data if successful.\n */\n async function CreateEnvTextureAsync(texture, options = {}) {\n var _a, _b;\n const internalTexture = texture.getInternalTexture();\n if (!internalTexture) {\n return Promise.reject(\"The cube texture is invalid.\");\n }\n const imageType = (_a = options.imageType) !== null && _a !== void 0 ? _a : DefaultEnvironmentTextureImageType;\n const engine = internalTexture.getEngine();\n if (texture.textureType !== 2 &&\n texture.textureType !== 1 &&\n texture.textureType !== 0 &&\n texture.textureType !== 0 &&\n texture.textureType !== 7 &&\n texture.textureType !== -1) {\n return Promise.reject(\"The cube texture should allow HDR (Full Float or Half Float).\");\n }\n let textureType = 1;\n if (!engine.getCaps().textureFloatRender) {\n textureType = 2;\n if (!engine.getCaps().textureHalfFloatRender) {\n return Promise.reject(\"Env texture can only be created when the browser supports half float or full float rendering.\");\n }\n }\n // sphericalPolynomial is lazy loaded so simply accessing it should trigger the computation.\n texture.sphericalPolynomial;\n // Lets keep track of the polynomial promise so we can wait for it to be ready before generating the pixels.\n const sphericalPolynomialPromise = (_b = texture.getInternalTexture()) === null || _b === void 0 ? void 0 : _b._sphericalPolynomialPromise;\n const cubeWidth = internalTexture.width;\n const hostingScene = new Scene(engine);\n const specularTextures = {};\n // As we are going to readPixels the faces of the cube, make sure the drawing/update commands for the cube texture are fully sent to the GPU in case it is drawn for the first time in this very frame!\n engine.flushFramebuffer();\n // Read and collect all mipmaps data from the cube.\n const mipmapsCount = Scalar.ILog2(internalTexture.width);\n for (let i = 0; i <= mipmapsCount; i++) {\n const faceWidth = Math.pow(2, mipmapsCount - i);\n // All faces of the cube.\n for (let face = 0; face < 6; face++) {\n let faceData = await texture.readPixels(face, i, undefined, false);\n if (faceData && faceData.byteLength === faceData.length) {\n const faceDataFloat = new Float32Array(faceData.byteLength * 4);\n for (let i = 0; i < faceData.byteLength; i++) {\n faceDataFloat[i] = faceData[i] / 255;\n // Gamma to linear\n faceDataFloat[i] = Math.pow(faceDataFloat[i], 2.2);\n }\n faceData = faceDataFloat;\n }\n else if (faceData && texture.gammaSpace) {\n const floatData = faceData;\n for (let i = 0; i < floatData.length; i++) {\n // Gamma to linear\n floatData[i] = Math.pow(floatData[i], 2.2);\n }\n }\n const tempTexture = engine.createRawTexture(faceData, faceWidth, faceWidth, 5, false, true, 1, null, textureType);\n await RGBDTextureTools.EncodeTextureToRGBD(tempTexture, hostingScene, textureType);\n const rgbdEncodedData = await engine._readTexturePixels(tempTexture, faceWidth, faceWidth);\n const imageEncodedData = await DumpTools.DumpDataAsync(faceWidth, faceWidth, rgbdEncodedData, imageType, undefined, false, true, options.imageQuality);\n specularTextures[i * 6 + face] = imageEncodedData;\n tempTexture.dispose();\n }\n }\n // We can delete the hosting scene keeping track of all the creation objects\n hostingScene.dispose();\n // Ensure completion of the polynomial creation promise.\n if (sphericalPolynomialPromise) {\n await sphericalPolynomialPromise;\n }\n // Creates the json header for the env texture\n const info = {\n version: CurrentVersion,\n width: cubeWidth,\n imageType,\n irradiance: _CreateEnvTextureIrradiance(texture),\n specular: {\n mipmaps: [],\n lodGenerationScale: texture.lodGenerationScale,\n },\n };\n // Sets the specular image data information\n let position = 0;\n for (let i = 0; i <= mipmapsCount; i++) {\n for (let face = 0; face < 6; face++) {\n const byteLength = specularTextures[i * 6 + face].byteLength;\n info.specular.mipmaps.push({\n length: byteLength,\n position: position,\n });\n position += byteLength;\n }\n }\n // Encode the JSON as an array buffer\n const infoString = JSON.stringify(info);\n const infoBuffer = new ArrayBuffer(infoString.length + 1);\n const infoView = new Uint8Array(infoBuffer); // Limited to ascii subset matching unicode.\n for (let i = 0, strLen = infoString.length; i < strLen; i++) {\n infoView[i] = infoString.charCodeAt(i);\n }\n // Ends up with a null terminator for easier parsing\n infoView[infoString.length] = 0x00;\n // Computes the final required size and creates the storage\n const totalSize = MagicBytes.length + position + infoBuffer.byteLength;\n const finalBuffer = new ArrayBuffer(totalSize);\n const finalBufferView = new Uint8Array(finalBuffer);\n const dataView = new DataView(finalBuffer);\n // Copy the magic bytes identifying the file in\n let pos = 0;\n for (let i = 0; i < MagicBytes.length; i++) {\n dataView.setUint8(pos++, MagicBytes[i]);\n }\n // Add the json info\n finalBufferView.set(new Uint8Array(infoBuffer), pos);\n pos += infoBuffer.byteLength;\n // Finally inserts the texture data\n for (let i = 0; i <= mipmapsCount; i++) {\n for (let face = 0; face < 6; face++) {\n const dataBuffer = specularTextures[i * 6 + face];\n finalBufferView.set(new Uint8Array(dataBuffer), pos);\n pos += dataBuffer.byteLength;\n }\n }\n // Voila\n return finalBuffer;\n }\n /**\n * Creates a JSON representation of the spherical data.\n * @param texture defines the texture containing the polynomials\n * @returns the JSON representation of the spherical info\n */\n function _CreateEnvTextureIrradiance(texture) {\n const polynmials = texture.sphericalPolynomial;\n if (polynmials == null) {\n return null;\n }\n return {\n x: [polynmials.x.x, polynmials.x.y, polynmials.x.z],\n y: [polynmials.y.x, polynmials.y.y, polynmials.y.z],\n z: [polynmials.z.x, polynmials.z.y, polynmials.z.z],\n xx: [polynmials.xx.x, polynmials.xx.y, polynmials.xx.z],\n yy: [polynmials.yy.x, polynmials.yy.y, polynmials.yy.z],\n zz: [polynmials.zz.x, polynmials.zz.y, polynmials.zz.z],\n yz: [polynmials.yz.x, polynmials.yz.y, polynmials.yz.z],\n zx: [polynmials.zx.x, polynmials.zx.y, polynmials.zx.z],\n xy: [polynmials.xy.x, polynmials.xy.y, polynmials.xy.z],\n };\n }\n /**\n * Creates the ArrayBufferViews used for initializing environment texture image data.\n * @param data the image data\n * @param info parameters that determine what views will be created for accessing the underlying buffer\n * @returns the views described by info providing access to the underlying buffer\n */\n function CreateImageDataArrayBufferViews(data, info) {\n info = normalizeEnvInfo(info);\n const specularInfo = info.specular;\n // Double checks the enclosed info\n let mipmapsCount = Scalar.Log2(info.width);\n mipmapsCount = Math.round(mipmapsCount) + 1;\n if (specularInfo.mipmaps.length !== 6 * mipmapsCount) {\n throw new Error(`Unsupported specular mipmaps number \"${specularInfo.mipmaps.length}\"`);\n }\n const imageData = new Array(mipmapsCount);\n for (let i = 0; i < mipmapsCount; i++) {\n imageData[i] = new Array(6);\n for (let face = 0; face < 6; face++) {\n const imageInfo = specularInfo.mipmaps[i * 6 + face];\n imageData[i][face] = new Uint8Array(data.buffer, data.byteOffset + specularInfo.specularDataPosition + imageInfo.position, imageInfo.length);\n }\n }\n return imageData;\n }\n /**\n * Uploads the texture info contained in the env file to the GPU.\n * @param texture defines the internal texture to upload to\n * @param data defines the data to load\n * @param info defines the texture info retrieved through the GetEnvInfo method\n * @returns a promise\n */\n function UploadEnvLevelsAsync(texture, data, info) {\n info = normalizeEnvInfo(info);\n const specularInfo = info.specular;\n if (!specularInfo) {\n // Nothing else parsed so far\n return Promise.resolve();\n }\n texture._lodGenerationScale = specularInfo.lodGenerationScale;\n const imageData = CreateImageDataArrayBufferViews(data, info);\n return UploadLevelsAsync(texture, imageData, info.imageType);\n }\n function _OnImageReadyAsync(image, engine, expandTexture, rgbdPostProcess, url, face, i, generateNonLODTextures, lodTextures, cubeRtt, texture) {\n return new Promise((resolve, reject) => {\n if (expandTexture) {\n const tempTexture = engine.createTexture(null, true, true, null, 1, null, (message) => {\n reject(message);\n }, image);\n rgbdPostProcess.getEffect().executeWhenCompiled(() => {\n // Uncompress the data to a RTT\n rgbdPostProcess.externalTextureSamplerBinding = true;\n rgbdPostProcess.onApply = (effect) => {\n effect._bindTexture(\"textureSampler\", tempTexture);\n effect.setFloat2(\"scale\", 1, engine._features.needsInvertingBitmap && image instanceof ImageBitmap ? -1 : 1);\n };\n if (!engine.scenes.length) {\n return;\n }\n engine.scenes[0].postProcessManager.directRender([rgbdPostProcess], cubeRtt, true, face, i);\n // Cleanup\n engine.restoreDefaultFramebuffer();\n tempTexture.dispose();\n URL.revokeObjectURL(url);\n resolve();\n });\n }\n else {\n engine._uploadImageToTexture(texture, image, face, i);\n // Upload the face to the non lod texture support\n if (generateNonLODTextures) {\n const lodTexture = lodTextures[i];\n if (lodTexture) {\n engine._uploadImageToTexture(lodTexture._texture, image, face, 0);\n }\n }\n resolve();\n }\n });\n }\n /**\n * Uploads the levels of image data to the GPU.\n * @param texture defines the internal texture to upload to\n * @param imageData defines the array buffer views of image data [mipmap][face]\n * @param imageType the mime type of the image data\n * @returns a promise\n */\n function UploadLevelsAsync(texture, imageData, imageType = DefaultEnvironmentTextureImageType) {\n if (!Tools.IsExponentOfTwo(texture.width)) {\n throw new Error(\"Texture size must be a power of two\");\n }\n const mipmapsCount = Scalar.ILog2(texture.width) + 1;\n // Gets everything ready.\n const engine = texture.getEngine();\n let expandTexture = false;\n let generateNonLODTextures = false;\n let rgbdPostProcess = null;\n let cubeRtt = null;\n let lodTextures = null;\n const caps = engine.getCaps();\n texture.format = 5;\n texture.type = 0;\n texture.generateMipMaps = true;\n texture._cachedAnisotropicFilteringLevel = null;\n engine.updateTextureSamplingMode(3, texture);\n // Add extra process if texture lod is not supported\n if (!caps.textureLOD) {\n expandTexture = false;\n generateNonLODTextures = true;\n lodTextures = {};\n }\n // in webgl 1 there are no ways to either render or copy lod level information for float textures.\n else if (!engine._features.supportRenderAndCopyToLodForFloatTextures) {\n expandTexture = false;\n }\n // If half float available we can uncompress the texture\n else if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\n expandTexture = true;\n texture.type = 2;\n }\n // If full float available we can uncompress the texture\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\n expandTexture = true;\n texture.type = 1;\n }\n // Expand the texture if possible\n if (expandTexture) {\n // Simply run through the decode PP\n rgbdPostProcess = new PostProcess(\"rgbdDecode\", \"rgbdDecode\", null, null, 1, null, 3, engine, false, undefined, texture.type, undefined, null, false);\n texture._isRGBD = false;\n texture.invertY = false;\n cubeRtt = engine.createRenderTargetCubeTexture(texture.width, {\n generateDepthBuffer: false,\n generateMipMaps: true,\n generateStencilBuffer: false,\n samplingMode: 3,\n type: texture.type,\n format: 5,\n });\n }\n else {\n texture._isRGBD = true;\n texture.invertY = true;\n // In case of missing support, applies the same patch than DDS files.\n if (generateNonLODTextures) {\n const mipSlices = 3;\n const scale = texture._lodGenerationScale;\n const offset = texture._lodGenerationOffset;\n for (let i = 0; i < mipSlices; i++) {\n //compute LOD from even spacing in smoothness (matching shader calculation)\n const smoothness = i / (mipSlices - 1);\n const roughness = 1 - smoothness;\n const minLODIndex = offset; // roughness = 0\n const maxLODIndex = (mipmapsCount - 1) * scale + offset; // roughness = 1 (mipmaps start from 0)\n const lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;\n const mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));\n const glTextureFromLod = new InternalTexture(engine, InternalTextureSource.Temp);\n glTextureFromLod.isCube = true;\n glTextureFromLod.invertY = true;\n glTextureFromLod.generateMipMaps = false;\n engine.updateTextureSamplingMode(2, glTextureFromLod);\n // Wrap in a base texture for easy binding.\n const lodTexture = new BaseTexture(null);\n lodTexture._isCube = true;\n lodTexture._texture = glTextureFromLod;\n lodTextures[mipmapIndex] = lodTexture;\n switch (i) {\n case 0:\n texture._lodTextureLow = lodTexture;\n break;\n case 1:\n texture._lodTextureMid = lodTexture;\n break;\n case 2:\n texture._lodTextureHigh = lodTexture;\n break;\n }\n }\n }\n }\n const promises = [];\n // All mipmaps up to provided number of images\n for (let i = 0; i < imageData.length; i++) {\n // All faces\n for (let face = 0; face < 6; face++) {\n // Constructs an image element from image data\n const bytes = imageData[i][face];\n const blob = new Blob([bytes], { type: imageType });\n const url = URL.createObjectURL(blob);\n let promise;\n if (typeof Image === \"undefined\" || engine._features.forceBitmapOverHTMLImageElement) {\n promise = engine.createImageBitmap(blob, { premultiplyAlpha: \"none\" }).then((img) => {\n return _OnImageReadyAsync(img, engine, expandTexture, rgbdPostProcess, url, face, i, generateNonLODTextures, lodTextures, cubeRtt, texture);\n });\n }\n else {\n const image = new Image();\n image.src = url;\n // Enqueue promise to upload to the texture.\n promise = new Promise((resolve, reject) => {\n image.onload = () => {\n _OnImageReadyAsync(image, engine, expandTexture, rgbdPostProcess, url, face, i, generateNonLODTextures, lodTextures, cubeRtt, texture)\n .then(() => resolve())\n .catch((reason) => {\n reject(reason);\n });\n };\n image.onerror = (error) => {\n reject(error);\n };\n });\n }\n promises.push(promise);\n }\n }\n // Fill remaining mipmaps with black textures.\n if (imageData.length < mipmapsCount) {\n let data;\n const size = Math.pow(2, mipmapsCount - 1 - imageData.length);\n const dataLength = size * size * 4;\n switch (texture.type) {\n case 0: {\n data = new Uint8Array(dataLength);\n break;\n }\n case 2: {\n data = new Uint16Array(dataLength);\n break;\n }\n case 1: {\n data = new Float32Array(dataLength);\n break;\n }\n }\n for (let i = imageData.length; i < mipmapsCount; i++) {\n for (let face = 0; face < 6; face++) {\n engine._uploadArrayBufferViewToTexture(texture, data, face, i);\n }\n }\n }\n // Once all done, finishes the cleanup and return\n return Promise.all(promises).then(() => {\n // Release temp RTT.\n if (cubeRtt) {\n engine._releaseTexture(texture);\n cubeRtt._swapAndDie(texture);\n }\n // Release temp Post Process.\n if (rgbdPostProcess) {\n rgbdPostProcess.dispose();\n }\n // Flag internal texture as ready in case they are in use.\n if (generateNonLODTextures) {\n if (texture._lodTextureHigh && texture._lodTextureHigh._texture) {\n texture._lodTextureHigh._texture.isReady = true;\n }\n if (texture._lodTextureMid && texture._lodTextureMid._texture) {\n texture._lodTextureMid._texture.isReady = true;\n }\n if (texture._lodTextureLow && texture._lodTextureLow._texture) {\n texture._lodTextureLow._texture.isReady = true;\n }\n }\n });\n }\n /**\n * Uploads spherical polynomials information to the texture.\n * @param texture defines the texture we are trying to upload the information to\n * @param info defines the environment texture info retrieved through the GetEnvInfo method\n */\n function UploadEnvSpherical(texture, info) {\n info = normalizeEnvInfo(info);\n const irradianceInfo = info.irradiance;\n if (!irradianceInfo) {\n return;\n }\n const sp = new SphericalPolynomial();\n Vector3.FromArrayToRef(irradianceInfo.x, 0, sp.x);\n Vector3.FromArrayToRef(irradianceInfo.y, 0, sp.y);\n Vector3.FromArrayToRef(irradianceInfo.z, 0, sp.z);\n Vector3.FromArrayToRef(irradianceInfo.xx, 0, sp.xx);\n Vector3.FromArrayToRef(irradianceInfo.yy, 0, sp.yy);\n Vector3.FromArrayToRef(irradianceInfo.zz, 0, sp.zz);\n Vector3.FromArrayToRef(irradianceInfo.yz, 0, sp.yz);\n Vector3.FromArrayToRef(irradianceInfo.zx, 0, sp.zx);\n Vector3.FromArrayToRef(irradianceInfo.xy, 0, sp.xy);\n texture._sphericalPolynomial = sp;\n }\n /**\n * Sets of helpers addressing the serialization and deserialization of environment texture\n * stored in a BabylonJS env file.\n * Those files are usually stored as .env files.\n */\n const EnvironmentTextureTools = {\n /**\n * Gets the environment info from an env file.\n * @param data The array buffer containing the .env bytes.\n * @returns the environment file info (the json header) if successfully parsed, normalized to the latest supported version.\n */\n GetEnvInfo,\n /**\n * Creates an environment texture from a loaded cube texture.\n * @param texture defines the cube texture to convert in env file\n * @param options options for the conversion process\n * @param options.imageType the mime type for the encoded images, with support for \"image/png\" (default) and \"image/webp\"\n * @param options.imageQuality the image quality of encoded WebP images.\n * @returns a promise containing the environment data if successful.\n */\n CreateEnvTextureAsync,\n /**\n * Creates the ArrayBufferViews used for initializing environment texture image data.\n * @param data the image data\n * @param info parameters that determine what views will be created for accessing the underlying buffer\n * @returns the views described by info providing access to the underlying buffer\n */\n CreateImageDataArrayBufferViews,\n /**\n * Uploads the texture info contained in the env file to the GPU.\n * @param texture defines the internal texture to upload to\n * @param data defines the data to load\n * @param info defines the texture info retrieved through the GetEnvInfo method\n * @returns a promise\n */\n UploadEnvLevelsAsync,\n /**\n * Uploads the levels of image data to the GPU.\n * @param texture defines the internal texture to upload to\n * @param imageData defines the array buffer views of image data [mipmap][face]\n * @param imageType the mime type of the image data\n * @returns a promise\n */\n UploadLevelsAsync,\n /**\n * Uploads spherical polynomials information to the texture.\n * @param texture defines the texture we are trying to upload the information to\n * @param info defines the environment texture info retrieved through the GetEnvInfo method\n */\n UploadEnvSpherical,\n };\n\n /**\n * Implementation of the ENV Texture Loader.\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _ENVTextureLoader {\n constructor() {\n /**\n * Defines whether the loader supports cascade loading the different faces.\n */\n this.supportCascades = false;\n }\n /**\n * This returns if the loader support the current file information.\n * @param extension defines the file extension of the file being loaded\n * @returns true if the loader can load the specified file\n */\n canLoad(extension) {\n return extension.endsWith(\".env\");\n }\n /**\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param createPolynomials will be true if polynomials have been requested\n * @param onLoad defines the callback to trigger once the texture is ready\n * @param onError defines the callback to trigger in case of error\n */\n loadCubeData(data, texture, createPolynomials, onLoad, onError) {\n if (Array.isArray(data)) {\n return;\n }\n const info = GetEnvInfo(data);\n if (info) {\n texture.width = info.width;\n texture.height = info.width;\n try {\n UploadEnvSpherical(texture, info);\n UploadEnvLevelsAsync(texture, data, info).then(() => {\n texture.isReady = true;\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n if (onLoad) {\n onLoad();\n }\n }, (reason) => {\n onError === null || onError === void 0 ? void 0 : onError(\"Can not upload environment levels\", reason);\n });\n }\n catch (e) {\n onError === null || onError === void 0 ? void 0 : onError(\"Can not upload environment file\", e);\n }\n }\n else if (onError) {\n onError(\"Can not parse the environment file\", null);\n }\n }\n /**\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\n */\n loadData() {\n throw \".env not supported in 2d.\";\n }\n }\n // Register the loader.\n Engine._TextureLoaders.push(new _ENVTextureLoader());\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * for description see https://www.khronos.org/opengles/sdk/tools/KTX/\n * for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/\n */\n class KhronosTextureContainer {\n /**\n * Creates a new KhronosTextureContainer\n * @param data contents of the KTX container file\n * @param facesExpected should be either 1 or 6, based whether a cube texture or or\n */\n constructor(\n /** contents of the KTX container file */\n data, facesExpected) {\n this.data = data;\n /**\n * If the container has been made invalid (eg. constructor failed to correctly load array buffer)\n */\n this.isInvalid = false;\n if (!KhronosTextureContainer.IsValid(data)) {\n this.isInvalid = true;\n Logger.Error(\"texture missing KTX identifier\");\n return;\n }\n // load the reset of the header in native 32 bit uint\n const dataSize = Uint32Array.BYTES_PER_ELEMENT;\n const headerDataView = new DataView(this.data.buffer, this.data.byteOffset + 12, 13 * dataSize);\n const endianness = headerDataView.getUint32(0, true);\n const littleEndian = endianness === 0x04030201;\n this.glType = headerDataView.getUint32(1 * dataSize, littleEndian); // must be 0 for compressed textures\n this.glTypeSize = headerDataView.getUint32(2 * dataSize, littleEndian); // must be 1 for compressed textures\n this.glFormat = headerDataView.getUint32(3 * dataSize, littleEndian); // must be 0 for compressed textures\n this.glInternalFormat = headerDataView.getUint32(4 * dataSize, littleEndian); // the value of arg passed to gl.compressedTexImage2D(,,x,,,,)\n this.glBaseInternalFormat = headerDataView.getUint32(5 * dataSize, littleEndian); // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only)\n this.pixelWidth = headerDataView.getUint32(6 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,)\n this.pixelHeight = headerDataView.getUint32(7 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,)\n this.pixelDepth = headerDataView.getUint32(8 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,)\n this.numberOfArrayElements = headerDataView.getUint32(9 * dataSize, littleEndian); // used for texture arrays\n this.numberOfFaces = headerDataView.getUint32(10 * dataSize, littleEndian); // used for cubemap textures, should either be 1 or 6\n this.numberOfMipmapLevels = headerDataView.getUint32(11 * dataSize, littleEndian); // number of levels; disregard possibility of 0 for compressed textures\n this.bytesOfKeyValueData = headerDataView.getUint32(12 * dataSize, littleEndian); // the amount of space after the header for meta-data\n // Make sure we have a compressed type. Not only reduces work, but probably better to let dev know they are not compressing.\n if (this.glType !== 0) {\n Logger.Error(\"only compressed formats currently supported\");\n this.isInvalid = true;\n return;\n }\n else {\n // value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.\n this.numberOfMipmapLevels = Math.max(1, this.numberOfMipmapLevels);\n }\n if (this.pixelHeight === 0 || this.pixelDepth !== 0) {\n Logger.Error(\"only 2D textures currently supported\");\n this.isInvalid = true;\n return;\n }\n if (this.numberOfArrayElements !== 0) {\n Logger.Error(\"texture arrays not currently supported\");\n this.isInvalid = true;\n return;\n }\n if (this.numberOfFaces !== facesExpected) {\n Logger.Error(\"number of faces expected\" + facesExpected + \", but found \" + this.numberOfFaces);\n this.isInvalid = true;\n return;\n }\n // we now have a completely validated file, so could use existence of loadType as success\n // would need to make this more elaborate & adjust checks above to support more than one load type\n this.loadType = KhronosTextureContainer.COMPRESSED_2D;\n }\n /**\n * Uploads KTX content to a Babylon Texture.\n * It is assumed that the texture has already been created & is currently bound\n * @internal\n */\n uploadLevels(texture, loadMipmaps) {\n switch (this.loadType) {\n case KhronosTextureContainer.COMPRESSED_2D:\n this._upload2DCompressedLevels(texture, loadMipmaps);\n break;\n }\n }\n _upload2DCompressedLevels(texture, loadMipmaps) {\n // initialize width & height for level 1\n let dataOffset = KhronosTextureContainer.HEADER_LEN + this.bytesOfKeyValueData;\n let width = this.pixelWidth;\n let height = this.pixelHeight;\n const mipmapCount = loadMipmaps ? this.numberOfMipmapLevels : 1;\n for (let level = 0; level < mipmapCount; level++) {\n const imageSize = new Int32Array(this.data.buffer, this.data.byteOffset + dataOffset, 1)[0]; // size per face, since not supporting array cubemaps\n dataOffset += 4; //image data starts from next multiple of 4 offset. Each face refers to same imagesize field above.\n for (let face = 0; face < this.numberOfFaces; face++) {\n const byteArray = new Uint8Array(this.data.buffer, this.data.byteOffset + dataOffset, imageSize);\n const engine = texture.getEngine();\n engine._uploadCompressedDataToTextureDirectly(texture, texture.format, width, height, byteArray, face, level);\n dataOffset += imageSize; // add size of the image for the next face/mipmap\n dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image\n }\n width = Math.max(1.0, width * 0.5);\n height = Math.max(1.0, height * 0.5);\n }\n }\n /**\n * Checks if the given data starts with a KTX file identifier.\n * @param data the data to check\n * @returns true if the data is a KTX file or false otherwise\n */\n static IsValid(data) {\n if (data.byteLength >= 12) {\n // '«', 'K', 'T', 'X', ' ', '1', '1', '»', '\\r', '\\n', '\\x1A', '\\n'\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\n if (identifier[0] === 0xab &&\n identifier[1] === 0x4b &&\n identifier[2] === 0x54 &&\n identifier[3] === 0x58 &&\n identifier[4] === 0x20 &&\n identifier[5] === 0x31 &&\n identifier[6] === 0x31 &&\n identifier[7] === 0xbb &&\n identifier[8] === 0x0d &&\n identifier[9] === 0x0a &&\n identifier[10] === 0x1a &&\n identifier[11] === 0x0a) {\n return true;\n }\n }\n return false;\n }\n }\n KhronosTextureContainer.HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)\n // load types\n KhronosTextureContainer.COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()\n KhronosTextureContainer.COMPRESSED_3D = 1; // uses a gl.compressedTexImage3D()\n KhronosTextureContainer.TEX_2D = 2; // uses a gl.texImage2D()\n KhronosTextureContainer.TEX_3D = 3; // uses a gl.texImage3D()\n\n /**\n * Helper class to push actions to a pool of workers.\n */\n class WorkerPool {\n /**\n * Constructor\n * @param workers Array of workers to use for actions\n */\n constructor(workers) {\n this._pendingActions = new Array();\n this._workerInfos = workers.map((worker) => ({\n workerPromise: Promise.resolve(worker),\n idle: true,\n }));\n }\n /**\n * Terminates all workers and clears any pending actions.\n */\n dispose() {\n for (const workerInfo of this._workerInfos) {\n workerInfo.workerPromise.then((worker) => {\n worker.terminate();\n });\n }\n this._workerInfos.length = 0;\n this._pendingActions.length = 0;\n }\n /**\n * Pushes an action to the worker pool. If all the workers are active, the action will be\n * pended until a worker has completed its action.\n * @param action The action to perform. Call onComplete when the action is complete.\n */\n push(action) {\n if (!this._executeOnIdleWorker(action)) {\n this._pendingActions.push(action);\n }\n }\n _executeOnIdleWorker(action) {\n for (const workerInfo of this._workerInfos) {\n if (workerInfo.idle) {\n this._execute(workerInfo, action);\n return true;\n }\n }\n return false;\n }\n _execute(workerInfo, action) {\n workerInfo.idle = false;\n workerInfo.workerPromise.then((worker) => {\n action(worker, () => {\n const nextAction = this._pendingActions.shift();\n if (nextAction) {\n this._execute(workerInfo, nextAction);\n }\n else {\n workerInfo.idle = true;\n }\n });\n });\n }\n }\n /**\n * Similar to the WorkerPool class except it creates and destroys workers automatically with a maximum of `maxWorkers` workers.\n * Workers are terminated when it is idle for at least `idleTimeElapsedBeforeRelease` milliseconds.\n */\n class AutoReleaseWorkerPool extends WorkerPool {\n constructor(maxWorkers, createWorkerAsync, options = AutoReleaseWorkerPool.DefaultOptions) {\n super([]);\n this._maxWorkers = maxWorkers;\n this._createWorkerAsync = createWorkerAsync;\n this._options = options;\n }\n push(action) {\n if (!this._executeOnIdleWorker(action)) {\n if (this._workerInfos.length < this._maxWorkers) {\n const workerInfo = {\n workerPromise: this._createWorkerAsync(),\n idle: false,\n };\n this._workerInfos.push(workerInfo);\n this._execute(workerInfo, action);\n }\n else {\n this._pendingActions.push(action);\n }\n }\n }\n _execute(workerInfo, action) {\n // Reset the idle timeout.\n if (workerInfo.timeoutId) {\n clearTimeout(workerInfo.timeoutId);\n delete workerInfo.timeoutId;\n }\n super._execute(workerInfo, (worker, onComplete) => {\n action(worker, () => {\n onComplete();\n if (workerInfo.idle) {\n // Schedule the worker to be terminated after the elapsed time.\n workerInfo.timeoutId = setTimeout(() => {\n workerInfo.workerPromise.then((worker) => {\n worker.terminate();\n });\n const indexOf = this._workerInfos.indexOf(workerInfo);\n if (indexOf !== -1) {\n this._workerInfos.splice(indexOf, 1);\n }\n }, this._options.idleTimeElapsedBeforeRelease);\n }\n });\n });\n }\n }\n /**\n * Default options for the constructor.\n * Override to change the defaults.\n */\n AutoReleaseWorkerPool.DefaultOptions = {\n idleTimeElapsedBeforeRelease: 1000,\n };\n\n var SourceTextureFormat;\n (function (SourceTextureFormat) {\n SourceTextureFormat[SourceTextureFormat[\"ETC1S\"] = 0] = \"ETC1S\";\n SourceTextureFormat[SourceTextureFormat[\"UASTC4x4\"] = 1] = \"UASTC4x4\";\n })(SourceTextureFormat || (SourceTextureFormat = {}));\n var TranscodeTarget;\n (function (TranscodeTarget) {\n TranscodeTarget[TranscodeTarget[\"ASTC_4X4_RGBA\"] = 0] = \"ASTC_4X4_RGBA\";\n TranscodeTarget[TranscodeTarget[\"BC7_RGBA\"] = 1] = \"BC7_RGBA\";\n TranscodeTarget[TranscodeTarget[\"BC3_RGBA\"] = 2] = \"BC3_RGBA\";\n TranscodeTarget[TranscodeTarget[\"BC1_RGB\"] = 3] = \"BC1_RGB\";\n TranscodeTarget[TranscodeTarget[\"PVRTC1_4_RGBA\"] = 4] = \"PVRTC1_4_RGBA\";\n TranscodeTarget[TranscodeTarget[\"PVRTC1_4_RGB\"] = 5] = \"PVRTC1_4_RGB\";\n TranscodeTarget[TranscodeTarget[\"ETC2_RGBA\"] = 6] = \"ETC2_RGBA\";\n TranscodeTarget[TranscodeTarget[\"ETC1_RGB\"] = 7] = \"ETC1_RGB\";\n TranscodeTarget[TranscodeTarget[\"RGBA32\"] = 8] = \"RGBA32\";\n TranscodeTarget[TranscodeTarget[\"R8\"] = 9] = \"R8\";\n TranscodeTarget[TranscodeTarget[\"RG8\"] = 10] = \"RG8\";\n })(TranscodeTarget || (TranscodeTarget = {}));\n var EngineFormat;\n (function (EngineFormat) {\n EngineFormat[EngineFormat[\"COMPRESSED_RGBA_BPTC_UNORM_EXT\"] = 36492] = \"COMPRESSED_RGBA_BPTC_UNORM_EXT\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGBA_ASTC_4X4_KHR\"] = 37808] = \"COMPRESSED_RGBA_ASTC_4X4_KHR\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGB_S3TC_DXT1_EXT\"] = 33776] = \"COMPRESSED_RGB_S3TC_DXT1_EXT\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGBA_S3TC_DXT5_EXT\"] = 33779] = \"COMPRESSED_RGBA_S3TC_DXT5_EXT\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGBA_PVRTC_4BPPV1_IMG\"] = 35842] = \"COMPRESSED_RGBA_PVRTC_4BPPV1_IMG\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGB_PVRTC_4BPPV1_IMG\"] = 35840] = \"COMPRESSED_RGB_PVRTC_4BPPV1_IMG\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGBA8_ETC2_EAC\"] = 37496] = \"COMPRESSED_RGBA8_ETC2_EAC\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGB8_ETC2\"] = 37492] = \"COMPRESSED_RGB8_ETC2\";\n EngineFormat[EngineFormat[\"COMPRESSED_RGB_ETC1_WEBGL\"] = 36196] = \"COMPRESSED_RGB_ETC1_WEBGL\";\n EngineFormat[EngineFormat[\"RGBA8Format\"] = 32856] = \"RGBA8Format\";\n EngineFormat[EngineFormat[\"R8Format\"] = 33321] = \"R8Format\";\n EngineFormat[EngineFormat[\"RG8Format\"] = 33323] = \"RG8Format\";\n })(EngineFormat || (EngineFormat = {}));\n\n function getAbsoluteUrlOrNull(url) {\n return url ? Tools.GetAbsoluteUrl(url) : null;\n }\n function applyConfig(urls) {\n if (urls.wasmUASTCToASTC !== null) {\n KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;\n }\n if (urls.wasmUASTCToBC7 !== null) {\n KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;\n }\n if (urls.wasmUASTCToRGBA_UNORM !== null) {\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = urls.wasmUASTCToRGBA_UNORM;\n }\n if (urls.wasmUASTCToRGBA_SRGB !== null) {\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = urls.wasmUASTCToRGBA_SRGB;\n }\n if (urls.wasmUASTCToR8_UNORM !== null) {\n KTX2DECODER.LiteTranscoder_UASTC_R8_UNORM.WasmModuleURL = urls.wasmUASTCToR8_UNORM;\n }\n if (urls.wasmUASTCToRG8_UNORM !== null) {\n KTX2DECODER.LiteTranscoder_UASTC_RG8_UNORM.WasmModuleURL = urls.wasmUASTCToRG8_UNORM;\n }\n if (urls.jsMSCTranscoder !== null) {\n KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;\n }\n if (urls.wasmMSCTranscoder !== null) {\n KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;\n }\n if (urls.wasmZSTDDecoder !== null) {\n KTX2DECODER.ZSTDDecoder.WasmModuleURL = urls.wasmZSTDDecoder;\n }\n }\n /**\n * Class that defines the default KTX2 decoder options.\n *\n * This class is useful for providing options to the KTX2 decoder to control how the source data is transcoded.\n */\n class DefaultKTX2DecoderOptions {\n constructor() {\n this._isDirty = true;\n this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC = true;\n this._ktx2DecoderOptions = {};\n }\n /**\n * Gets the dirty flag\n */\n get isDirty() {\n return this._isDirty;\n }\n /**\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and ASTC + BC7 are not available as a compressed transcoded format\n */\n get useRGBAIfASTCBC7NotAvailableWhenUASTC() {\n return this._useRGBAIfASTCBC7NotAvailableWhenUASTC;\n }\n set useRGBAIfASTCBC7NotAvailableWhenUASTC(value) {\n if (this._useRGBAIfASTCBC7NotAvailableWhenUASTC === value) {\n return;\n }\n this._useRGBAIfASTCBC7NotAvailableWhenUASTC = value;\n this._isDirty = true;\n }\n /**\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and only BC1 or BC3 are available as a compressed transcoded format.\n * This property is true by default to favor speed over memory, because currently transcoding from UASTC to BC1/3 is slow because the transcoder transcodes\n * to uncompressed and then recompresses the texture\n */\n get useRGBAIfOnlyBC1BC3AvailableWhenUASTC() {\n return this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC;\n }\n set useRGBAIfOnlyBC1BC3AvailableWhenUASTC(value) {\n if (this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC === value) {\n return;\n }\n this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC = value;\n this._isDirty = true;\n }\n /**\n * force to always use (uncompressed) RGBA for transcoded format\n */\n get forceRGBA() {\n return this._forceRGBA;\n }\n set forceRGBA(value) {\n if (this._forceRGBA === value) {\n return;\n }\n this._forceRGBA = value;\n this._isDirty = true;\n }\n /**\n * force to always use (uncompressed) R8 for transcoded format\n */\n get forceR8() {\n return this._forceR8;\n }\n set forceR8(value) {\n if (this._forceR8 === value) {\n return;\n }\n this._forceR8 = value;\n this._isDirty = true;\n }\n /**\n * force to always use (uncompressed) RG8 for transcoded format\n */\n get forceRG8() {\n return this._forceRG8;\n }\n set forceRG8(value) {\n if (this._forceRG8 === value) {\n return;\n }\n this._forceRG8 = value;\n this._isDirty = true;\n }\n /**\n * list of transcoders to bypass when looking for a suitable transcoder. The available transcoders are:\n * UniversalTranscoder_UASTC_ASTC\n * UniversalTranscoder_UASTC_BC7\n * UniversalTranscoder_UASTC_RGBA_UNORM\n * UniversalTranscoder_UASTC_RGBA_SRGB\n * UniversalTranscoder_UASTC_R8_UNORM\n * UniversalTranscoder_UASTC_RG8_UNORM\n * MSCTranscoder\n */\n get bypassTranscoders() {\n return this._bypassTranscoders;\n }\n set bypassTranscoders(value) {\n if (this._bypassTranscoders === value) {\n return;\n }\n this._bypassTranscoders = value;\n this._isDirty = true;\n }\n /** @internal */\n _getKTX2DecoderOptions() {\n if (!this._isDirty) {\n return this._ktx2DecoderOptions;\n }\n this._isDirty = false;\n const options = {\n useRGBAIfASTCBC7NotAvailableWhenUASTC: this._useRGBAIfASTCBC7NotAvailableWhenUASTC,\n forceRGBA: this._forceRGBA,\n forceR8: this._forceR8,\n forceRG8: this._forceRG8,\n bypassTranscoders: this._bypassTranscoders,\n };\n if (this.useRGBAIfOnlyBC1BC3AvailableWhenUASTC) {\n options.transcodeFormatDecisionTree = {\n UASTC: {\n transcodeFormat: [TranscodeTarget.BC1_RGB, TranscodeTarget.BC3_RGBA],\n yes: {\n transcodeFormat: TranscodeTarget.RGBA32,\n engineFormat: EngineFormat.RGBA8Format,\n roundToMultiple4: false,\n },\n },\n };\n }\n this._ktx2DecoderOptions = options;\n return options;\n }\n }\n /**\n * Class for loading KTX2 files\n */\n class KhronosTextureContainer2 {\n static GetDefaultNumWorkers() {\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\n return 1;\n }\n // Use 50% of the available logical processors but capped at 4.\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\n }\n static _Initialize(numWorkers) {\n if (KhronosTextureContainer2._WorkerPoolPromise || KhronosTextureContainer2._DecoderModulePromise) {\n return;\n }\n const urls = {\n jsDecoderModule: Tools.GetAbsoluteUrl(this.URLConfig.jsDecoderModule),\n wasmUASTCToASTC: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToASTC),\n wasmUASTCToBC7: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToBC7),\n wasmUASTCToRGBA_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_UNORM),\n wasmUASTCToRGBA_SRGB: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_SRGB),\n wasmUASTCToR8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToR8_UNORM),\n wasmUASTCToRG8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRG8_UNORM),\n jsMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.jsMSCTranscoder),\n wasmMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.wasmMSCTranscoder),\n wasmZSTDDecoder: getAbsoluteUrlOrNull(this.URLConfig.wasmZSTDDecoder),\n };\n if (numWorkers && typeof Worker === \"function\" && typeof URL !== \"undefined\") {\n KhronosTextureContainer2._WorkerPoolPromise = new Promise((resolve) => {\n const workerContent = `${applyConfig}(${workerFunc})()`;\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\n resolve(new AutoReleaseWorkerPool(numWorkers, () => new Promise((resolve, reject) => {\n const worker = new Worker(workerBlobUrl);\n const onError = (error) => {\n worker.removeEventListener(\"error\", onError);\n worker.removeEventListener(\"message\", onMessage);\n reject(error);\n };\n const onMessage = (message) => {\n if (message.data.action === \"init\") {\n worker.removeEventListener(\"error\", onError);\n worker.removeEventListener(\"message\", onMessage);\n resolve(worker);\n }\n };\n worker.addEventListener(\"error\", onError);\n worker.addEventListener(\"message\", onMessage);\n worker.postMessage({\n action: \"init\",\n urls: urls,\n });\n })));\n });\n }\n else if (typeof KTX2DECODER === \"undefined\") {\n KhronosTextureContainer2._DecoderModulePromise = Tools.LoadScriptAsync(urls.jsDecoderModule).then(() => {\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\n applyConfig(urls);\n return new KTX2DECODER.KTX2Decoder();\n });\n }\n else {\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\n KhronosTextureContainer2._DecoderModulePromise = Promise.resolve(new KTX2DECODER.KTX2Decoder());\n }\n }\n /**\n * Constructor\n * @param engine The engine to use\n * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\n */\n constructor(engine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {\n this._engine = engine;\n KhronosTextureContainer2._Initialize(numWorkers);\n }\n /**\n * @internal\n */\n uploadAsync(data, internalTexture, options) {\n const caps = this._engine.getCaps();\n const compressedTexturesCaps = {\n astc: !!caps.astc,\n bptc: !!caps.bptc,\n s3tc: !!caps.s3tc,\n pvrtc: !!caps.pvrtc,\n etc2: !!caps.etc2,\n etc1: !!caps.etc1,\n };\n if (KhronosTextureContainer2._WorkerPoolPromise) {\n return KhronosTextureContainer2._WorkerPoolPromise.then((workerPool) => {\n return new Promise((resolve, reject) => {\n workerPool.push((worker, onComplete) => {\n const onError = (error) => {\n worker.removeEventListener(\"error\", onError);\n worker.removeEventListener(\"message\", onMessage);\n reject(error);\n onComplete();\n };\n const onMessage = (message) => {\n if (message.data.action === \"decoded\") {\n worker.removeEventListener(\"error\", onError);\n worker.removeEventListener(\"message\", onMessage);\n if (!message.data.success) {\n reject({ message: message.data.msg });\n }\n else {\n try {\n this._createTexture(message.data.decodedData, internalTexture, options);\n resolve();\n }\n catch (err) {\n reject({ message: err });\n }\n }\n onComplete();\n }\n };\n worker.addEventListener(\"error\", onError);\n worker.addEventListener(\"message\", onMessage);\n worker.postMessage({ action: \"setDefaultDecoderOptions\", options: KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions() });\n const dataCopy = new Uint8Array(data.byteLength);\n dataCopy.set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\n worker.postMessage({ action: \"decode\", data: dataCopy, caps: compressedTexturesCaps, options }, [dataCopy.buffer]);\n });\n });\n });\n }\n else if (KhronosTextureContainer2._DecoderModulePromise) {\n return KhronosTextureContainer2._DecoderModulePromise.then((decoder) => {\n if (KhronosTextureContainer2.DefaultDecoderOptions.isDirty) {\n KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions();\n }\n return new Promise((resolve, reject) => {\n decoder\n .decode(data, caps)\n .then((data) => {\n this._createTexture(data, internalTexture);\n resolve();\n })\n .catch((reason) => {\n reject({ message: reason });\n });\n });\n });\n }\n throw new Error(\"KTX2 decoder module is not available\");\n }\n _createTexture(data, internalTexture, options) {\n const oglTexture2D = 3553; // gl.TEXTURE_2D\n this._engine._bindTextureDirectly(oglTexture2D, internalTexture);\n if (options) {\n // return back some information about the decoded data\n options.transcodedFormat = data.transcodedFormat;\n options.isInGammaSpace = data.isInGammaSpace;\n options.hasAlpha = data.hasAlpha;\n options.transcoderName = data.transcoderName;\n }\n let isUncompressedFormat = true;\n switch (data.transcodedFormat) {\n case 0x8058 /* RGBA8 */:\n internalTexture.type = 0;\n internalTexture.format = 5;\n break;\n case 0x8229 /* R8 */:\n internalTexture.type = 0;\n internalTexture.format = 6;\n break;\n case 0x822b /* RG8 */:\n internalTexture.type = 0;\n internalTexture.format = 7;\n break;\n default:\n internalTexture.format = data.transcodedFormat;\n isUncompressedFormat = false;\n break;\n }\n internalTexture._gammaSpace = data.isInGammaSpace;\n internalTexture.generateMipMaps = data.mipmaps.length > 1;\n if (data.errors) {\n throw new Error(\"KTX2 container - could not transcode the data. \" + data.errors);\n }\n for (let t = 0; t < data.mipmaps.length; ++t) {\n const mipmap = data.mipmaps[t];\n if (!mipmap || !mipmap.data) {\n throw new Error(\"KTX2 container - could not transcode one of the image\");\n }\n if (isUncompressedFormat) {\n // uncompressed RGBA / R8 / RG8\n internalTexture.width = mipmap.width; // need to set width/height so that the call to _uploadDataToTextureDirectly uses the right dimensions\n internalTexture.height = mipmap.height;\n this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);\n }\n else {\n this._engine._uploadCompressedDataToTextureDirectly(internalTexture, data.transcodedFormat, mipmap.width, mipmap.height, mipmap.data, 0, t);\n }\n }\n internalTexture._extension = \".ktx2\";\n internalTexture.width = data.mipmaps[0].width;\n internalTexture.height = data.mipmaps[0].height;\n internalTexture.isReady = true;\n this._engine._bindTextureDirectly(oglTexture2D, null);\n }\n /**\n * Checks if the given data starts with a KTX2 file identifier.\n * @param data the data to check\n * @returns true if the data is a KTX2 file or false otherwise\n */\n static IsValid(data) {\n if (data.byteLength >= 12) {\n // '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\\r', '\\n', '\\x1A', '\\n'\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\n if (identifier[0] === 0xab &&\n identifier[1] === 0x4b &&\n identifier[2] === 0x54 &&\n identifier[3] === 0x58 &&\n identifier[4] === 0x20 &&\n identifier[5] === 0x32 &&\n identifier[6] === 0x30 &&\n identifier[7] === 0xbb &&\n identifier[8] === 0x0d &&\n identifier[9] === 0x0a &&\n identifier[10] === 0x1a &&\n identifier[11] === 0x0a) {\n return true;\n }\n }\n return false;\n }\n }\n /**\n * URLs to use when loading the KTX2 decoder module as well as its dependencies\n * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)\n * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary\n * Urls you can change:\n * URLConfig.jsDecoderModule\n * URLConfig.wasmUASTCToASTC\n * URLConfig.wasmUASTCToBC7\n * URLConfig.wasmUASTCToRGBA_UNORM\n * URLConfig.wasmUASTCToRGBA_SRGB\n * URLConfig.wasmUASTCToR8_UNORM\n * URLConfig.wasmUASTCToRG8_UNORM\n * URLConfig.jsMSCTranscoder\n * URLConfig.wasmMSCTranscoder\n * URLConfig.wasmZSTDDecoder\n * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#29\n */\n KhronosTextureContainer2.URLConfig = {\n jsDecoderModule: \"https://preview.babylonjs.com/babylon.ktx2Decoder.js\",\n wasmUASTCToASTC: null,\n wasmUASTCToBC7: null,\n wasmUASTCToRGBA_UNORM: null,\n wasmUASTCToRGBA_SRGB: null,\n wasmUASTCToR8_UNORM: null,\n wasmUASTCToRG8_UNORM: null,\n jsMSCTranscoder: null,\n wasmMSCTranscoder: null,\n wasmZSTDDecoder: null,\n };\n /**\n * Default number of workers used to handle data decoding\n */\n KhronosTextureContainer2.DefaultNumWorkers = KhronosTextureContainer2.GetDefaultNumWorkers();\n /**\n * Default configuration for the KTX2 decoder.\n * The options defined in this way have priority over those passed when creating a KTX2 texture with new Texture(...).\n */\n KhronosTextureContainer2.DefaultDecoderOptions = new DefaultKTX2DecoderOptions();\n function workerFunc() {\n let ktx2Decoder;\n onmessage = (event) => {\n if (!event.data) {\n return;\n }\n switch (event.data.action) {\n case \"init\": {\n const urls = event.data.urls;\n importScripts(urls.jsDecoderModule);\n applyConfig(urls);\n ktx2Decoder = new KTX2DECODER.KTX2Decoder();\n postMessage({ action: \"init\" });\n break;\n }\n case \"setDefaultDecoderOptions\": {\n KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = event.data.options;\n break;\n }\n case \"decode\":\n ktx2Decoder\n .decode(event.data.data, event.data.caps, event.data.options)\n .then((data) => {\n const buffers = [];\n for (let mip = 0; mip < data.mipmaps.length; ++mip) {\n const mipmap = data.mipmaps[mip];\n if (mipmap && mipmap.data) {\n buffers.push(mipmap.data.buffer);\n }\n }\n postMessage({ action: \"decoded\", success: true, decodedData: data }, buffers);\n })\n .catch((reason) => {\n postMessage({ action: \"decoded\", success: false, msg: reason });\n });\n break;\n }\n };\n }\n\n function mapSRGBToLinear(format) {\n switch (format) {\n case 35916:\n return 33776;\n case 35918:\n return 33778;\n case 35919:\n return 33779;\n case 37493:\n return 37492;\n case 37497:\n return 37496;\n case 37495:\n return 37494;\n case 37840:\n return 37808;\n case 36493:\n return 36492;\n }\n return null;\n }\n /**\n * Implementation of the KTX Texture Loader.\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _KTXTextureLoader {\n constructor() {\n /**\n * Defines whether the loader supports cascade loading the different faces.\n */\n this.supportCascades = false;\n }\n /**\n * This returns if the loader support the current file information.\n * @param extension defines the file extension of the file being loaded\n * @param mimeType defines the optional mime type of the file being loaded\n * @returns true if the loader can load the specified file\n */\n canLoad(extension, mimeType) {\n // The \".ktx2\" file extension is still up for debate: https://github.com/KhronosGroup/KTX-Specification/issues/18\n return extension.endsWith(\".ktx\") || extension.endsWith(\".ktx2\") || mimeType === \"image/ktx\" || mimeType === \"image/ktx2\";\n }\n /**\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param createPolynomials will be true if polynomials have been requested\n * @param onLoad defines the callback to trigger once the texture is ready\n */\n loadCubeData(data, texture, createPolynomials, onLoad) {\n if (Array.isArray(data)) {\n return;\n }\n // Need to invert vScale as invertY via UNPACK_FLIP_Y_WEBGL is not supported by compressed texture\n texture._invertVScale = !texture.invertY;\n const engine = texture.getEngine();\n const ktx = new KhronosTextureContainer(data, 6);\n const loadMipmap = ktx.numberOfMipmapLevels > 1 && texture.generateMipMaps;\n engine._unpackFlipY(true);\n ktx.uploadLevels(texture, texture.generateMipMaps);\n texture.width = ktx.pixelWidth;\n texture.height = ktx.pixelHeight;\n engine._setCubeMapTextureParams(texture, loadMipmap, ktx.numberOfMipmapLevels - 1);\n texture.isReady = true;\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n if (onLoad) {\n onLoad();\n }\n }\n /**\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param callback defines the method to call once ready to upload\n * @param options\n */\n loadData(data, texture, callback, options) {\n if (KhronosTextureContainer.IsValid(data)) {\n // Need to invert vScale as invertY via UNPACK_FLIP_Y_WEBGL is not supported by compressed texture\n texture._invertVScale = !texture.invertY;\n const ktx = new KhronosTextureContainer(data, 1);\n const mappedFormat = mapSRGBToLinear(ktx.glInternalFormat);\n if (mappedFormat) {\n texture.format = mappedFormat;\n texture._useSRGBBuffer = texture.getEngine()._getUseSRGBBuffer(true, texture.generateMipMaps);\n texture._gammaSpace = true;\n }\n else {\n texture.format = ktx.glInternalFormat;\n }\n callback(ktx.pixelWidth, ktx.pixelHeight, texture.generateMipMaps, true, () => {\n ktx.uploadLevels(texture, texture.generateMipMaps);\n }, ktx.isInvalid);\n }\n else if (KhronosTextureContainer2.IsValid(data)) {\n const ktx2 = new KhronosTextureContainer2(texture.getEngine());\n ktx2.uploadAsync(data, texture, options).then(() => {\n callback(texture.width, texture.height, texture.generateMipMaps, true, () => { }, false);\n }, (error) => {\n Logger.Warn(`Failed to load KTX2 texture data: ${error.message}`);\n callback(0, 0, false, false, () => { }, true);\n });\n }\n else {\n Logger.Error(\"texture missing KTX identifier\");\n callback(0, 0, false, false, () => { }, true);\n }\n }\n }\n // Register the loader.\n Engine._TextureLoaders.unshift(new _KTXTextureLoader());\n\n /**\n * WebXR Camera which holds the views for the xrSession\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRCamera\n */\n class WebXRCamera extends FreeCamera {\n /**\n * Creates a new webXRCamera, this should only be set at the camera after it has been updated by the xrSessionManager\n * @param name the name of the camera\n * @param scene the scene to add the camera to\n * @param _xrSessionManager a constructed xr session manager\n */\n constructor(name, scene, _xrSessionManager) {\n super(name, Vector3.Zero(), scene);\n this._xrSessionManager = _xrSessionManager;\n this._firstFrame = false;\n this._referenceQuaternion = Quaternion.Identity();\n this._referencedPosition = new Vector3();\n this._trackingState = WebXRTrackingState.NOT_TRACKING;\n /**\n * Observable raised before camera teleportation\n */\n this.onBeforeCameraTeleport = new Observable$1();\n /**\n * Observable raised after camera teleportation\n */\n this.onAfterCameraTeleport = new Observable$1();\n /**\n * Notifies when the camera's tracking state has changed.\n * Notice - will also be triggered when tracking has started (at the beginning of the session)\n */\n this.onTrackingStateChanged = new Observable$1();\n /**\n * Should position compensation execute on first frame.\n * This is used when copying the position from a native (non XR) camera\n */\n this.compensateOnFirstFrame = true;\n this._rotate180 = new Quaternion(0, 1, 0, 0);\n // Initial camera configuration\n this.minZ = 0.1;\n this.rotationQuaternion = new Quaternion();\n this.cameraRigMode = Camera.RIG_MODE_CUSTOM;\n this.updateUpVectorFromRotation = true;\n this._updateNumberOfRigCameras(1);\n // freeze projection matrix, which will be copied later\n this.freezeProjectionMatrix();\n this._deferOnly = true;\n this._xrSessionManager.onXRSessionInit.add(() => {\n this._referencedPosition.copyFromFloats(0, 0, 0);\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\n // first frame - camera's y position should be 0 for the correct offset\n this._firstFrame = this.compensateOnFirstFrame;\n });\n // Check transformation changes on each frame. Callback is added to be first so that the transformation will be\n // applied to the rest of the elements using the referenceSpace object\n this._xrSessionManager.onXRFrameObservable.add(() => {\n if (this._firstFrame) {\n this._updateFromXRSession();\n }\n if (this._deferredUpdated) {\n this.position.copyFrom(this._deferredPositionUpdate);\n this.rotationQuaternion.copyFrom(this._deferredRotationQuaternionUpdate);\n }\n this._updateReferenceSpace();\n this._updateFromXRSession();\n }, undefined, true);\n }\n /**\n * Get the current XR tracking state of the camera\n */\n get trackingState() {\n return this._trackingState;\n }\n _setTrackingState(newState) {\n if (this._trackingState !== newState) {\n this._trackingState = newState;\n this.onTrackingStateChanged.notifyObservers(newState);\n }\n }\n /**\n * Return the user's height, unrelated to the current ground.\n * This will be the y position of this camera, when ground level is 0.\n */\n get realWorldHeight() {\n const basePose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.baseReferenceSpace);\n if (basePose && basePose.transform) {\n return basePose.transform.position.y;\n }\n else {\n return 0;\n }\n }\n /** @internal */\n _updateForDualEyeDebugging( /*pupilDistance = 0.01*/) {\n // Create initial camera rigs\n this._updateNumberOfRigCameras(2);\n this.rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\n // this.rigCameras[0].position.x = -pupilDistance / 2;\n this.rigCameras[0].outputRenderTarget = null;\n this.rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\n // this.rigCameras[1].position.x = pupilDistance / 2;\n this.rigCameras[1].outputRenderTarget = null;\n }\n /**\n * Sets this camera's transformation based on a non-vr camera\n * @param otherCamera the non-vr camera to copy the transformation from\n * @param resetToBaseReferenceSpace should XR reset to the base reference space\n */\n setTransformationFromNonVRCamera(otherCamera = this.getScene().activeCamera, resetToBaseReferenceSpace = true) {\n if (!otherCamera || otherCamera === this) {\n return;\n }\n const mat = otherCamera.computeWorldMatrix();\n mat.decompose(undefined, this.rotationQuaternion, this.position);\n // set the ground level\n this.position.y = 0;\n Quaternion.FromEulerAnglesToRef(0, this.rotationQuaternion.toEulerAngles().y, 0, this.rotationQuaternion);\n this._firstFrame = true;\n if (resetToBaseReferenceSpace) {\n this._xrSessionManager.resetReferenceSpace();\n }\n }\n /**\n * Gets the current instance class name (\"WebXRCamera\").\n * @returns the class name\n */\n getClassName() {\n return \"WebXRCamera\";\n }\n /**\n * Set the target for the camera to look at.\n * Note that this only rotates around the Y axis, as opposed to the default behavior of other cameras\n * @param target the target to set the camera to look at\n */\n setTarget(target) {\n // only rotate around the y axis!\n const tmpVector = TmpVectors.Vector3[1];\n target.subtractToRef(this.position, tmpVector);\n tmpVector.y = 0;\n tmpVector.normalize();\n const yRotation = Math.atan2(tmpVector.x, tmpVector.z);\n this.rotationQuaternion.toEulerAnglesToRef(tmpVector);\n Quaternion.FromEulerAnglesToRef(tmpVector.x, yRotation, tmpVector.z, this.rotationQuaternion);\n }\n dispose() {\n super.dispose();\n this._lastXRViewerPose = undefined;\n }\n _updateFromXRSession() {\n const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);\n this._lastXRViewerPose = pose || undefined;\n if (!pose) {\n this._setTrackingState(WebXRTrackingState.NOT_TRACKING);\n return;\n }\n // Set the tracking state. if it didn't change it is a no-op\n const trackingState = pose.emulatedPosition ? WebXRTrackingState.TRACKING_LOST : WebXRTrackingState.TRACKING;\n this._setTrackingState(trackingState);\n // check min/max Z and update if not the same as in cache\n if (this.minZ !== this._cache.minZ || this.maxZ !== this._cache.maxZ) {\n const xrRenderState = {\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\n depthFar: this.maxZ || 10000,\n depthNear: this.minZ,\n };\n this._xrSessionManager.updateRenderState(xrRenderState);\n this._cache.minZ = this.minZ;\n this._cache.maxZ = this.maxZ;\n }\n if (pose.transform) {\n const orientation = pose.transform.orientation;\n if (pose.transform.orientation.x === undefined) {\n // Babylon native polyfill can return an undefined orientation value\n // When not initialized\n return;\n }\n const pos = pose.transform.position;\n this._referencedPosition.set(pos.x, pos.y, pos.z);\n this._referenceQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\n if (!this._scene.useRightHandedSystem) {\n this._referencedPosition.z *= -1;\n this._referenceQuaternion.z *= -1;\n this._referenceQuaternion.w *= -1;\n }\n if (this._firstFrame) {\n this._firstFrame = false;\n // we have the XR reference, now use this to find the offset to get the camera to be\n // in the right position\n // set the height to correlate to the current height\n this.position.y += this._referencedPosition.y;\n // avoid using the head rotation on the first frame.\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\n }\n else {\n // update position and rotation as reference\n this.rotationQuaternion.copyFrom(this._referenceQuaternion);\n this.position.copyFrom(this._referencedPosition);\n }\n }\n // Update camera rigs\n if (this.rigCameras.length !== pose.views.length) {\n this._updateNumberOfRigCameras(pose.views.length);\n }\n pose.views.forEach((view, i) => {\n var _a;\n const currentRig = this.rigCameras[i];\n // update right and left, where applicable\n if (!currentRig.isLeftCamera && !currentRig.isRightCamera) {\n if (view.eye === \"right\") {\n currentRig._isRightCamera = true;\n }\n else if (view.eye === \"left\") {\n currentRig._isLeftCamera = true;\n }\n }\n // Update view/projection matrix\n const pos = view.transform.position;\n const orientation = view.transform.orientation;\n currentRig.parent = this.parent;\n currentRig.position.set(pos.x, pos.y, pos.z);\n currentRig.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\n if (!this._scene.useRightHandedSystem) {\n currentRig.position.z *= -1;\n currentRig.rotationQuaternion.z *= -1;\n currentRig.rotationQuaternion.w *= -1;\n }\n else {\n currentRig.rotationQuaternion.multiplyInPlace(this._rotate180);\n }\n Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, currentRig._projectionMatrix);\n if (!this._scene.useRightHandedSystem) {\n currentRig._projectionMatrix.toggleProjectionMatrixHandInPlace();\n }\n // first camera?\n if (i === 0) {\n this._projectionMatrix.copyFrom(currentRig._projectionMatrix);\n }\n const renderTargetTexture = this._xrSessionManager.getRenderTargetTextureForView(view);\n this._renderingMultiview = ((_a = renderTargetTexture === null || renderTargetTexture === void 0 ? void 0 : renderTargetTexture._texture) === null || _a === void 0 ? void 0 : _a.isMultiview) || false;\n if (this._renderingMultiview) {\n // For multiview, the render target texture is the same per-view (just the slice index is different),\n // so we only need to set the output render target once for the rig parent.\n if (i == 0) {\n this._xrSessionManager.trySetViewportForView(this.viewport, view);\n this.outputRenderTarget = renderTargetTexture;\n }\n }\n else {\n // Update viewport\n this._xrSessionManager.trySetViewportForView(currentRig.viewport, view);\n // Set cameras to render to the session's render target\n currentRig.outputRenderTarget = renderTargetTexture || this._xrSessionManager.getRenderTargetTextureForView(view);\n }\n // Replicate parent rig camera behavior\n currentRig.layerMask = this.layerMask;\n });\n }\n _updateNumberOfRigCameras(viewCount = 1) {\n while (this.rigCameras.length < viewCount) {\n const newCamera = new TargetCamera(\"XR-RigCamera: \" + this.rigCameras.length, Vector3.Zero(), this.getScene());\n newCamera.minZ = 0.1;\n newCamera.rotationQuaternion = new Quaternion();\n newCamera.updateUpVectorFromRotation = true;\n newCamera.isRigCamera = true;\n newCamera.rigParent = this;\n // do not compute projection matrix, provided by XR\n newCamera.freezeProjectionMatrix();\n this.rigCameras.push(newCamera);\n }\n while (this.rigCameras.length > viewCount) {\n const removedCamera = this.rigCameras.pop();\n if (removedCamera) {\n removedCamera.dispose();\n }\n }\n }\n _updateReferenceSpace() {\n // were position & rotation updated OUTSIDE of the xr update loop\n if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {\n const referencedMat = TmpVectors.Matrix[0];\n const poseMat = TmpVectors.Matrix[1];\n const transformMat = TmpVectors.Matrix[2];\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this._referenceQuaternion, this._referencedPosition, referencedMat);\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this.rotationQuaternion, this.position, poseMat);\n referencedMat.invert().multiplyToRef(poseMat, transformMat);\n transformMat.invert();\n if (!this._scene.useRightHandedSystem) {\n transformMat.toggleModelMatrixHandInPlace();\n }\n transformMat.decompose(undefined, this._referenceQuaternion, this._referencedPosition);\n const transform = new XRRigidTransform({\n x: this._referencedPosition.x,\n y: this._referencedPosition.y,\n z: this._referencedPosition.z,\n }, {\n x: this._referenceQuaternion.x,\n y: this._referenceQuaternion.y,\n z: this._referenceQuaternion.z,\n w: this._referenceQuaternion.w,\n });\n this._xrSessionManager.referenceSpace = this._xrSessionManager.referenceSpace.getOffsetReferenceSpace(transform);\n }\n }\n }\n WebXRCamera._ScaleReadOnly = Vector3.One();\n\n /**\n * A list of the currently available features without referencing them\n */\n class WebXRFeatureName {\n }\n /**\n * The name of the anchor system feature\n */\n WebXRFeatureName.ANCHOR_SYSTEM = \"xr-anchor-system\";\n /**\n * The name of the background remover feature\n */\n WebXRFeatureName.BACKGROUND_REMOVER = \"xr-background-remover\";\n /**\n * The name of the hit test feature\n */\n WebXRFeatureName.HIT_TEST = \"xr-hit-test\";\n /**\n * The name of the mesh detection feature\n */\n WebXRFeatureName.MESH_DETECTION = \"xr-mesh-detection\";\n /**\n * physics impostors for xr controllers feature\n */\n WebXRFeatureName.PHYSICS_CONTROLLERS = \"xr-physics-controller\";\n /**\n * The name of the plane detection feature\n */\n WebXRFeatureName.PLANE_DETECTION = \"xr-plane-detection\";\n /**\n * The name of the pointer selection feature\n */\n WebXRFeatureName.POINTER_SELECTION = \"xr-controller-pointer-selection\";\n /**\n * The name of the teleportation feature\n */\n WebXRFeatureName.TELEPORTATION = \"xr-controller-teleportation\";\n /**\n * The name of the feature points feature.\n */\n WebXRFeatureName.FEATURE_POINTS = \"xr-feature-points\";\n /**\n * The name of the hand tracking feature.\n */\n WebXRFeatureName.HAND_TRACKING = \"xr-hand-tracking\";\n /**\n * The name of the image tracking feature\n */\n WebXRFeatureName.IMAGE_TRACKING = \"xr-image-tracking\";\n /**\n * The name of the near interaction feature\n */\n WebXRFeatureName.NEAR_INTERACTION = \"xr-near-interaction\";\n /**\n * The name of the DOM overlay feature\n */\n WebXRFeatureName.DOM_OVERLAY = \"xr-dom-overlay\";\n /**\n * The name of the movement feature\n */\n WebXRFeatureName.MOVEMENT = \"xr-controller-movement\";\n /**\n * The name of the light estimation feature\n */\n WebXRFeatureName.LIGHT_ESTIMATION = \"xr-light-estimation\";\n /**\n * The name of the eye tracking feature\n */\n WebXRFeatureName.EYE_TRACKING = \"xr-eye-tracking\";\n /**\n * The name of the walking locomotion feature\n */\n WebXRFeatureName.WALKING_LOCOMOTION = \"xr-walking-locomotion\";\n /**\n * The name of the composition layers feature\n */\n WebXRFeatureName.LAYERS = \"xr-layers\";\n /**\n * The name of the depth sensing feature\n */\n WebXRFeatureName.DEPTH_SENSING = \"xr-depth-sensing\";\n /**\n * The name of the WebXR Space Warp feature\n */\n WebXRFeatureName.SPACE_WARP = \"xr-space-warp\";\n /**\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\n * It is mainly used in AR sessions.\n *\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\n */\n class WebXRFeaturesManager {\n /**\n * constructs a new features manages.\n *\n * @param _xrSessionManager an instance of WebXRSessionManager\n */\n constructor(_xrSessionManager) {\n this._xrSessionManager = _xrSessionManager;\n this._features = {};\n // when session starts / initialized - attach\n this._xrSessionManager.onXRSessionInit.add(() => {\n this.getEnabledFeatures().forEach((featureName) => {\n const feature = this._features[featureName];\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\n this.attachFeature(featureName);\n }\n });\n });\n // when session ends - detach\n this._xrSessionManager.onXRSessionEnded.add(() => {\n this.getEnabledFeatures().forEach((featureName) => {\n const feature = this._features[featureName];\n if (feature.enabled && feature.featureImplementation.attached) {\n // detach, but don't disable!\n this.detachFeature(featureName);\n }\n });\n });\n }\n /**\n * Used to register a module. After calling this function a developer can use this feature in the scene.\n * Mainly used internally.\n *\n * @param featureName the name of the feature to register\n * @param constructorFunction the function used to construct the module\n * @param version the (babylon) version of the module\n * @param stable is that a stable version of this module\n */\n static AddWebXRFeature(featureName, constructorFunction, version = 1, stable = false) {\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\n if (version > this._AvailableFeatures[featureName].latest) {\n this._AvailableFeatures[featureName].latest = version;\n }\n if (stable) {\n this._AvailableFeatures[featureName].stable = version;\n }\n this._AvailableFeatures[featureName][version] = constructorFunction;\n }\n /**\n * Returns a constructor of a specific feature.\n *\n * @param featureName the name of the feature to construct\n * @param version the version of the feature to load\n * @param xrSessionManager the xrSessionManager. Used to construct the module\n * @param options optional options provided to the module.\n * @returns a function that, when called, will return a new instance of this feature\n */\n static ConstructFeature(featureName, version = 1, xrSessionManager, options) {\n const constructorFunction = this._AvailableFeatures[featureName][version];\n if (!constructorFunction) {\n // throw an error? return nothing?\n throw new Error(\"feature not found\");\n }\n return constructorFunction(xrSessionManager, options);\n }\n /**\n * Can be used to return the list of features currently registered\n *\n * @returns an Array of available features\n */\n static GetAvailableFeatures() {\n return Object.keys(this._AvailableFeatures);\n }\n /**\n * Gets the versions available for a specific feature\n * @param featureName the name of the feature\n * @returns an array with the available versions\n */\n static GetAvailableVersions(featureName) {\n return Object.keys(this._AvailableFeatures[featureName]);\n }\n /**\n * Return the latest unstable version of this feature\n * @param featureName the name of the feature to search\n * @returns the version number. if not found will return -1\n */\n static GetLatestVersionOfFeature(featureName) {\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\n }\n /**\n * Return the latest stable version of this feature\n * @param featureName the name of the feature to search\n * @returns the version number. if not found will return -1\n */\n static GetStableVersionOfFeature(featureName) {\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\n }\n /**\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\n * Can be used during a session to start a feature\n * @param featureName the name of feature to attach\n */\n attachFeature(featureName) {\n const feature = this._features[featureName];\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\n feature.featureImplementation.attach();\n }\n }\n /**\n * Can be used inside a session or when the session ends to detach a specific feature\n * @param featureName the name of the feature to detach\n */\n detachFeature(featureName) {\n const feature = this._features[featureName];\n if (feature && feature.featureImplementation.attached) {\n feature.featureImplementation.detach();\n }\n }\n /**\n * Used to disable an already-enabled feature\n * The feature will be disposed and will be recreated once enabled.\n * @param featureName the feature to disable\n * @returns true if disable was successful\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n disableFeature(featureName) {\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\n const feature = this._features[name];\n if (feature && feature.enabled) {\n feature.enabled = false;\n this.detachFeature(name);\n feature.featureImplementation.dispose();\n delete this._features[name];\n return true;\n }\n return false;\n }\n /**\n * dispose this features manager\n */\n dispose() {\n this.getEnabledFeatures().forEach((feature) => {\n this.disableFeature(feature);\n });\n }\n /**\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\n *\n * @param featureName the name of the feature to load or the class of the feature\n * @param version optional version to load. if not provided the latest version will be enabled\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\n */\n enableFeature(\n // eslint-disable-next-line @typescript-eslint/naming-convention\n featureName, version = \"latest\", moduleOptions = {}, attachIfPossible = true, required = true) {\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\n let versionToLoad = 0;\n if (typeof version === \"string\") {\n if (!version) {\n throw new Error(`Error in provided version - ${name} (${version})`);\n }\n if (version === \"stable\") {\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\n }\n else if (version === \"latest\") {\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\n }\n else {\n // try loading the number the string represents\n versionToLoad = +version;\n }\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\n throw new Error(`feature not found - ${name} (${version})`);\n }\n }\n else {\n versionToLoad = version;\n }\n // check if there is a feature conflict\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\n }\n // check if already initialized\n const feature = this._features[name];\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\n if (!constructFunction) {\n // report error?\n throw new Error(`feature not found - ${name}`);\n }\n /* If the feature is already enabled, detach and dispose it, and create a new one */\n if (feature) {\n this.disableFeature(name);\n }\n const constructed = constructFunction();\n if (constructed.dependsOn) {\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\n if (!dependentsFound) {\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\n }\n }\n if (constructed.isCompatible()) {\n this._features[name] = {\n featureImplementation: constructed,\n enabled: true,\n version: versionToLoad,\n required,\n };\n if (attachIfPossible) {\n // if session started already, request and enable\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\n // enable feature\n this.attachFeature(name);\n }\n }\n else {\n // disable auto-attach when session starts\n this._features[name].featureImplementation.disableAutoAttach = true;\n }\n return this._features[name].featureImplementation;\n }\n else {\n if (required) {\n throw new Error(\"required feature not compatible\");\n }\n else {\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\n return constructed;\n }\n }\n }\n /**\n * get the implementation of an enabled feature.\n * @param featureName the name of the feature to load\n * @returns the feature class, if found\n */\n getEnabledFeature(featureName) {\n return this._features[featureName] && this._features[featureName].featureImplementation;\n }\n /**\n * Get the list of enabled features\n * @returns an array of enabled features\n */\n getEnabledFeatures() {\n return Object.keys(this._features);\n }\n /**\n * This function will extend the session creation configuration object with enabled features.\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\n * according to the defined \"required\" variable, provided during enableFeature call\n * @param xrSessionInit the xr Session init object to extend\n *\n * @returns an extended XRSessionInit object\n */\n async _extendXRSessionInitObject(xrSessionInit) {\n const enabledFeatures = this.getEnabledFeatures();\n for (const featureName of enabledFeatures) {\n const feature = this._features[featureName];\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\n if (nativeName) {\n if (feature.required) {\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\n xrSessionInit.requiredFeatures.push(nativeName);\n }\n }\n else {\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\n xrSessionInit.optionalFeatures.push(nativeName);\n }\n }\n }\n if (feature.featureImplementation.getXRSessionInitExtension) {\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\n xrSessionInit = Object.assign(Object.assign({}, xrSessionInit), extended);\n }\n }\n return xrSessionInit;\n }\n }\n WebXRFeaturesManager._AvailableFeatures = {};\n /**\n * The key is the feature to check and the value is the feature that conflicts.\n */\n WebXRFeaturesManager._ConflictingFeatures = {\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\n };\n\n Node.AddNodeConstructor(\"TouchCamera\", (name, scene) => {\n return () => new TouchCamera(name, Vector3.Zero(), scene);\n });\n /**\n * This represents a FPS type of camera controlled by touch.\n * This is like a universal camera minus the Gamepad controls.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\n */\n class TouchCamera extends FreeCamera {\n /**\n * Defines the touch sensibility for rotation.\n * The higher the faster.\n */\n get touchAngularSensibility() {\n const touch = this.inputs.attached[\"touch\"];\n if (touch) {\n return touch.touchAngularSensibility;\n }\n return 0;\n }\n set touchAngularSensibility(value) {\n const touch = this.inputs.attached[\"touch\"];\n if (touch) {\n touch.touchAngularSensibility = value;\n }\n }\n /**\n * Defines the touch sensibility for move.\n * The higher the faster.\n */\n get touchMoveSensibility() {\n const touch = this.inputs.attached[\"touch\"];\n if (touch) {\n return touch.touchMoveSensibility;\n }\n return 0;\n }\n set touchMoveSensibility(value) {\n const touch = this.inputs.attached[\"touch\"];\n if (touch) {\n touch.touchMoveSensibility = value;\n }\n }\n /**\n * Instantiates a new touch camera.\n * This represents a FPS type of camera controlled by touch.\n * This is like a universal camera minus the Gamepad controls.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\n * @param name Define the name of the camera in the scene\n * @param position Define the start position of the camera in the scene\n * @param scene Define the scene the camera belongs to\n */\n constructor(name, position, scene) {\n super(name, position, scene);\n this.inputs.addTouch();\n this._setupInputs();\n }\n /**\n * Gets the current object class name.\n * @returns the class name\n */\n getClassName() {\n return \"TouchCamera\";\n }\n /** @internal */\n _setupInputs() {\n const touch = this.inputs.attached[\"touch\"];\n const mouse = this.inputs.attached[\"mouse\"];\n if (mouse) {\n mouse.touchEnabled = false;\n }\n else {\n touch.allowMouse = true;\n }\n }\n }\n\n Node.AddNodeConstructor(\"FreeCamera\", (name, scene) => {\n // Forcing to use the Universal camera\n return () => new UniversalCamera(name, Vector3.Zero(), scene);\n });\n /**\n * The Universal Camera is the one to choose for first person shooter type games, and works with all the keyboard, mouse, touch and gamepads. This replaces the earlier Free Camera,\n * which still works and will still be found in many Playgrounds.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\n */\n class UniversalCamera extends TouchCamera {\n /**\n * Defines the gamepad rotation sensibility.\n * This is the threshold from when rotation starts to be accounted for to prevent jittering.\n */\n get gamepadAngularSensibility() {\n const gamepad = this.inputs.attached[\"gamepad\"];\n if (gamepad) {\n return gamepad.gamepadAngularSensibility;\n }\n return 0;\n }\n set gamepadAngularSensibility(value) {\n const gamepad = this.inputs.attached[\"gamepad\"];\n if (gamepad) {\n gamepad.gamepadAngularSensibility = value;\n }\n }\n /**\n * Defines the gamepad move sensibility.\n * This is the threshold from when moving starts to be accounted for to prevent jittering.\n */\n get gamepadMoveSensibility() {\n const gamepad = this.inputs.attached[\"gamepad\"];\n if (gamepad) {\n return gamepad.gamepadMoveSensibility;\n }\n return 0;\n }\n set gamepadMoveSensibility(value) {\n const gamepad = this.inputs.attached[\"gamepad\"];\n if (gamepad) {\n gamepad.gamepadMoveSensibility = value;\n }\n }\n /**\n * The Universal Camera is the one to choose for first person shooter type games, and works with all the keyboard, mouse, touch and gamepads. This replaces the earlier Free Camera,\n * which still works and will still be found in many Playgrounds.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\n * @param name Define the name of the camera in the scene\n * @param position Define the start position of the camera in the scene\n * @param scene Define the scene the camera belongs to\n */\n constructor(name, position, scene) {\n super(name, position, scene);\n this.inputs.addGamepad();\n }\n /**\n * Gets the current object class name.\n * @returns the class name\n */\n getClassName() {\n return \"UniversalCamera\";\n }\n }\n Camera._CreateDefaultParsedCamera = (name, scene) => {\n return new UniversalCamera(name, Vector3.Zero(), scene);\n };\n\n /**\n * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers\n */\n class WebXRExperienceHelper {\n /**\n * Creates a WebXRExperienceHelper\n * @param _scene The scene the helper should be created in\n */\n constructor(_scene) {\n this._scene = _scene;\n this._nonVRCamera = null;\n this._attachedToElement = false;\n this._spectatorCamera = null;\n this._originalSceneAutoClear = true;\n this._supported = false;\n this._spectatorMode = false;\n this._lastTimestamp = 0;\n /**\n * Observers registered here will be triggered after the camera's initial transformation is set\n * This can be used to set a different ground level or an extra rotation.\n *\n * Note that ground level is considered to be at 0. The height defined by the XR camera will be added\n * to the position set after this observable is done executing.\n */\n this.onInitialXRPoseSetObservable = new Observable$1();\n /**\n * Fires when the state of the experience helper has changed\n */\n this.onStateChangedObservable = new Observable$1();\n /**\n * The current state of the XR experience (eg. transitioning, in XR or not in XR)\n */\n this.state = WebXRState.NOT_IN_XR;\n this.sessionManager = new WebXRSessionManager(_scene);\n this.camera = new WebXRCamera(\"webxr\", _scene, this.sessionManager);\n this.featuresManager = new WebXRFeaturesManager(this.sessionManager);\n _scene.onDisposeObservable.addOnce(() => {\n this.dispose();\n });\n }\n /**\n * Creates the experience helper\n * @param scene the scene to attach the experience helper to\n * @returns a promise for the experience helper\n */\n static CreateAsync(scene) {\n const helper = new WebXRExperienceHelper(scene);\n return helper.sessionManager\n .initializeAsync()\n .then(() => {\n helper._supported = true;\n return helper;\n })\n .catch((e) => {\n helper._setState(WebXRState.NOT_IN_XR);\n helper.dispose();\n throw e;\n });\n }\n /**\n * Disposes of the experience helper\n */\n dispose() {\n var _a;\n this.exitXRAsync();\n this.camera.dispose();\n this.onStateChangedObservable.clear();\n this.onInitialXRPoseSetObservable.clear();\n this.sessionManager.dispose();\n (_a = this._spectatorCamera) === null || _a === void 0 ? void 0 : _a.dispose();\n if (this._nonVRCamera) {\n this._scene.activeCamera = this._nonVRCamera;\n }\n }\n /**\n * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)\n * @param sessionMode options for the XR session\n * @param referenceSpaceType frame of reference of the XR session\n * @param renderTarget the output canvas that will be used to enter XR mode\n * @param sessionCreationOptions optional XRSessionInit object to init the session with\n * @returns promise that resolves after xr mode has entered\n */\n async enterXRAsync(sessionMode, referenceSpaceType, renderTarget = this.sessionManager.getWebXRRenderTarget(), sessionCreationOptions = {}) {\n var _a, _b, _c;\n if (!this._supported) {\n throw \"WebXR not supported in this browser or environment\";\n }\n this._setState(WebXRState.ENTERING_XR);\n if (referenceSpaceType !== \"viewer\" && referenceSpaceType !== \"local\") {\n sessionCreationOptions.optionalFeatures = sessionCreationOptions.optionalFeatures || [];\n sessionCreationOptions.optionalFeatures.push(referenceSpaceType);\n }\n sessionCreationOptions = await this.featuresManager._extendXRSessionInitObject(sessionCreationOptions);\n // we currently recommend \"unbounded\" space in AR (#7959)\n if (sessionMode === \"immersive-ar\" && referenceSpaceType !== \"unbounded\") {\n Logger.Warn(\"We recommend using 'unbounded' reference space type when using 'immersive-ar' session mode\");\n }\n // make sure that the session mode is supported\n try {\n await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);\n await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);\n const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);\n const xrRenderState = {\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\n depthFar: this.camera.maxZ || 10000,\n depthNear: this.camera.minZ,\n };\n // The layers feature will have already initialized the xr session's layers on session init.\n if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {\n xrRenderState.baseLayer = baseLayer;\n }\n this.sessionManager.updateRenderState(xrRenderState);\n // run the render loop\n this.sessionManager.runXRRenderLoop();\n // Cache pre xr scene settings\n this._originalSceneAutoClear = this._scene.autoClear;\n this._nonVRCamera = this._scene.activeCamera;\n this._attachedToElement = !!((_b = (_a = this._nonVRCamera) === null || _a === void 0 ? void 0 : _a.inputs) === null || _b === void 0 ? void 0 : _b.attachedToElement);\n (_c = this._nonVRCamera) === null || _c === void 0 ? void 0 : _c.detachControl();\n this._scene.activeCamera = this.camera;\n // do not compensate when AR session is used\n if (sessionMode !== \"immersive-ar\") {\n this._nonXRToXRCamera();\n }\n else {\n // Kept here, TODO - check if needed\n this._scene.autoClear = false;\n this.camera.compensateOnFirstFrame = false;\n // reset the camera's position to the origin\n this.camera.position.set(0, 0, 0);\n this.camera.rotationQuaternion.set(0, 0, 0, 1);\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\n }\n this.sessionManager.onXRSessionEnded.addOnce(() => {\n // when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set\n if (this.state !== WebXRState.EXITING_XR) {\n this._setState(WebXRState.EXITING_XR);\n }\n // Reset camera rigs output render target to ensure sessions render target is not drawn after it ends\n this.camera.rigCameras.forEach((c) => {\n c.outputRenderTarget = null;\n });\n // Restore scene settings\n this._scene.autoClear = this._originalSceneAutoClear;\n this._scene.activeCamera = this._nonVRCamera;\n if (this._attachedToElement && this._nonVRCamera) {\n this._nonVRCamera.attachControl(!!this._nonVRCamera.inputs.noPreventDefault);\n }\n if (sessionMode !== \"immersive-ar\" && this.camera.compensateOnFirstFrame) {\n if (this._nonVRCamera.setPosition) {\n this._nonVRCamera.setPosition(this.camera.position);\n }\n else {\n this._nonVRCamera.position.copyFrom(this.camera.position);\n }\n }\n this._setState(WebXRState.NOT_IN_XR);\n });\n // Wait until the first frame arrives before setting state to in xr\n this.sessionManager.onXRFrameObservable.addOnce(() => {\n this._setState(WebXRState.IN_XR);\n });\n return this.sessionManager;\n }\n catch (e) {\n console.log(e);\n console.log(e.message);\n this._setState(WebXRState.NOT_IN_XR);\n throw e;\n }\n }\n /**\n * Exits XR mode and returns the scene to its original state\n * @returns promise that resolves after xr mode has exited\n */\n exitXRAsync() {\n // only exit if state is IN_XR\n if (this.state !== WebXRState.IN_XR) {\n return Promise.resolve();\n }\n this._setState(WebXRState.EXITING_XR);\n return this.sessionManager.exitXRAsync();\n }\n /**\n * Enable spectator mode for desktop VR experiences.\n * When spectator mode is enabled a camera will be attached to the desktop canvas and will\n * display the first rig camera's view on the desktop canvas.\n * Please note that this will degrade performance, as it requires another camera render.\n * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.\n * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.\n */\n enableSpectatorMode(options) {\n if (!this._spectatorMode) {\n this._spectatorMode = true;\n this._switchSpectatorMode(options);\n }\n }\n /**\n * Disable spectator mode for desktop VR experiences.\n */\n disableSpecatatorMode() {\n if (this._spectatorMode) {\n this._spectatorMode = false;\n this._switchSpectatorMode();\n }\n }\n _switchSpectatorMode(options) {\n const fps = (options === null || options === void 0 ? void 0 : options.fps) ? options.fps : 1000.0;\n const refreshRate = (1.0 / fps) * 1000.0;\n const cameraIndex = (options === null || options === void 0 ? void 0 : options.preferredCameraIndex) ? options === null || options === void 0 ? void 0 : options.preferredCameraIndex : 0;\n const updateSpectatorCamera = () => {\n if (this._spectatorCamera) {\n const delta = this.sessionManager.currentTimestamp - this._lastTimestamp;\n if (delta >= refreshRate) {\n this._lastTimestamp = this.sessionManager.currentTimestamp;\n this._spectatorCamera.position.copyFrom(this.camera.rigCameras[cameraIndex].globalPosition);\n this._spectatorCamera.rotationQuaternion.copyFrom(this.camera.rigCameras[cameraIndex].absoluteRotation);\n }\n }\n };\n if (this._spectatorMode) {\n if (cameraIndex >= this.camera.rigCameras.length) {\n throw new Error(\"the preferred camera index is beyond the length of rig camera array.\");\n }\n const onStateChanged = () => {\n if (this.state === WebXRState.IN_XR) {\n this._spectatorCamera = new UniversalCamera(\"webxr-spectator\", Vector3.Zero(), this._scene);\n this._spectatorCamera.rotationQuaternion = new Quaternion();\n this._scene.activeCameras = [this.camera, this._spectatorCamera];\n this.sessionManager.onXRFrameObservable.add(updateSpectatorCamera);\n this._scene.onAfterRenderCameraObservable.add((camera) => {\n if (camera === this.camera) {\n // reset the dimensions object for correct resizing\n this._scene.getEngine().framebufferDimensionsObject = null;\n }\n });\n }\n else if (this.state === WebXRState.EXITING_XR) {\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\n this._scene.activeCameras = null;\n }\n };\n this.onStateChangedObservable.add(onStateChanged);\n onStateChanged();\n }\n else {\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\n this._scene.activeCameras = [this.camera];\n }\n }\n _nonXRToXRCamera() {\n this.camera.setTransformationFromNonVRCamera(this._nonVRCamera);\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\n }\n _setState(val) {\n if (this.state === val) {\n return;\n }\n this.state = val;\n this.onStateChangedObservable.notifyObservers(this.state);\n }\n }\n\n /**\n * This class represents a single component (for example button or thumbstick) of a motion controller\n */\n class WebXRControllerComponent {\n /**\n * Creates a new component for a motion controller.\n * It is created by the motion controller itself\n *\n * @param id the id of this component\n * @param type the type of the component\n * @param _buttonIndex index in the buttons array of the gamepad\n * @param _axesIndices indices of the values in the axes array of the gamepad\n */\n constructor(\n /**\n * the id of this component\n */\n id, \n /**\n * the type of the component\n */\n type, _buttonIndex = -1, _axesIndices = []) {\n this.id = id;\n this.type = type;\n this._buttonIndex = _buttonIndex;\n this._axesIndices = _axesIndices;\n this._axes = {\n x: 0,\n y: 0,\n };\n this._changes = {};\n this._currentValue = 0;\n this._hasChanges = false;\n this._pressed = false;\n this._touched = false;\n /**\n * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when\n * the axes data changes\n */\n this.onAxisValueChangedObservable = new Observable$1();\n /**\n * Observers registered here will be triggered when the state of a button changes\n * State change is either pressed / touched / value\n */\n this.onButtonStateChangedObservable = new Observable$1();\n }\n /**\n * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }\n */\n get axes() {\n return this._axes;\n }\n /**\n * Get the changes. Elements will be populated only if they changed with their previous and current value\n */\n get changes() {\n return this._changes;\n }\n /**\n * Return whether or not the component changed the last frame\n */\n get hasChanges() {\n return this._hasChanges;\n }\n /**\n * is the button currently pressed\n */\n get pressed() {\n return this._pressed;\n }\n /**\n * is the button currently touched\n */\n get touched() {\n return this._touched;\n }\n /**\n * Get the current value of this component\n */\n get value() {\n return this._currentValue;\n }\n /**\n * Dispose this component\n */\n dispose() {\n this.onAxisValueChangedObservable.clear();\n this.onButtonStateChangedObservable.clear();\n }\n /**\n * Are there axes correlating to this component\n * @returns true is axes data is available\n */\n isAxes() {\n return this._axesIndices.length !== 0;\n }\n /**\n * Is this component a button (hence - pressable)\n * @returns true if can be pressed\n */\n isButton() {\n return this._buttonIndex !== -1;\n }\n /**\n * update this component using the gamepad object it is in. Called on every frame\n * @param nativeController the native gamepad controller object\n */\n update(nativeController) {\n let buttonUpdated = false;\n let axesUpdate = false;\n this._hasChanges = false;\n this._changes = {};\n if (this.isButton()) {\n const button = nativeController.buttons[this._buttonIndex];\n // defensive, in case a profile was forced\n if (!button) {\n return;\n }\n if (this._currentValue !== button.value) {\n this.changes.value = {\n current: button.value,\n previous: this._currentValue,\n };\n buttonUpdated = true;\n this._currentValue = button.value;\n }\n if (this._touched !== button.touched) {\n this.changes.touched = {\n current: button.touched,\n previous: this._touched,\n };\n buttonUpdated = true;\n this._touched = button.touched;\n }\n if (this._pressed !== button.pressed) {\n this.changes.pressed = {\n current: button.pressed,\n previous: this._pressed,\n };\n buttonUpdated = true;\n this._pressed = button.pressed;\n }\n }\n if (this.isAxes()) {\n if (this._axes.x !== nativeController.axes[this._axesIndices[0]]) {\n this.changes.axes = {\n current: {\n x: nativeController.axes[this._axesIndices[0]],\n y: this._axes.y,\n },\n previous: {\n x: this._axes.x,\n y: this._axes.y,\n },\n };\n this._axes.x = nativeController.axes[this._axesIndices[0]];\n axesUpdate = true;\n }\n if (this._axes.y !== nativeController.axes[this._axesIndices[1]]) {\n if (this.changes.axes) {\n this.changes.axes.current.y = nativeController.axes[this._axesIndices[1]];\n }\n else {\n this.changes.axes = {\n current: {\n x: this._axes.x,\n y: nativeController.axes[this._axesIndices[1]],\n },\n previous: {\n x: this._axes.x,\n y: this._axes.y,\n },\n };\n }\n this._axes.y = nativeController.axes[this._axesIndices[1]];\n axesUpdate = true;\n }\n }\n if (buttonUpdated) {\n this._hasChanges = true;\n this.onButtonStateChangedObservable.notifyObservers(this);\n }\n if (axesUpdate) {\n this._hasChanges = true;\n this.onAxisValueChangedObservable.notifyObservers(this._axes);\n }\n }\n }\n /**\n * button component type\n */\n WebXRControllerComponent.BUTTON_TYPE = \"button\";\n /**\n * squeeze component type\n */\n WebXRControllerComponent.SQUEEZE_TYPE = \"squeeze\";\n /**\n * Thumbstick component type\n */\n WebXRControllerComponent.THUMBSTICK_TYPE = \"thumbstick\";\n /**\n * Touchpad component type\n */\n WebXRControllerComponent.TOUCHPAD_TYPE = \"touchpad\";\n /**\n * trigger component type\n */\n WebXRControllerComponent.TRIGGER_TYPE = \"trigger\";\n\n /**\n * Mode that determines how to handle old animation groups before loading new ones.\n */\n var SceneLoaderAnimationGroupLoadingMode;\n (function (SceneLoaderAnimationGroupLoadingMode) {\n /**\n * Reset all old animations to initial state then dispose them.\n */\n SceneLoaderAnimationGroupLoadingMode[SceneLoaderAnimationGroupLoadingMode[\"Clean\"] = 0] = \"Clean\";\n /**\n * Stop all old animations.\n */\n SceneLoaderAnimationGroupLoadingMode[SceneLoaderAnimationGroupLoadingMode[\"Stop\"] = 1] = \"Stop\";\n /**\n * Restart old animations from first frame.\n */\n SceneLoaderAnimationGroupLoadingMode[SceneLoaderAnimationGroupLoadingMode[\"Sync\"] = 2] = \"Sync\";\n /**\n * Old animations remains untouched.\n */\n SceneLoaderAnimationGroupLoadingMode[SceneLoaderAnimationGroupLoadingMode[\"NoSync\"] = 3] = \"NoSync\";\n })(SceneLoaderAnimationGroupLoadingMode || (SceneLoaderAnimationGroupLoadingMode = {}));\n /**\n * Class used to load scene from various file formats using registered plugins\n * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes\n */\n class SceneLoader {\n /**\n * Gets or sets a boolean indicating if entire scene must be loaded even if scene contains incremental data\n */\n static get ForceFullSceneLoadingForIncremental() {\n return SceneLoaderFlags.ForceFullSceneLoadingForIncremental;\n }\n static set ForceFullSceneLoadingForIncremental(value) {\n SceneLoaderFlags.ForceFullSceneLoadingForIncremental = value;\n }\n /**\n * Gets or sets a boolean indicating if loading screen must be displayed while loading a scene\n */\n static get ShowLoadingScreen() {\n return SceneLoaderFlags.ShowLoadingScreen;\n }\n static set ShowLoadingScreen(value) {\n SceneLoaderFlags.ShowLoadingScreen = value;\n }\n /**\n * Defines the current logging level (while loading the scene)\n * @ignorenaming\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static get loggingLevel() {\n return SceneLoaderFlags.loggingLevel;\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static set loggingLevel(value) {\n SceneLoaderFlags.loggingLevel = value;\n }\n /**\n * Gets or set a boolean indicating if matrix weights must be cleaned upon loading\n */\n static get CleanBoneMatrixWeights() {\n return SceneLoaderFlags.CleanBoneMatrixWeights;\n }\n static set CleanBoneMatrixWeights(value) {\n SceneLoaderFlags.CleanBoneMatrixWeights = value;\n }\n /**\n * Gets the default plugin (used to load Babylon files)\n * @returns the .babylon plugin\n */\n static GetDefaultPlugin() {\n return SceneLoader._RegisteredPlugins[\".babylon\"];\n }\n static _GetPluginForExtension(extension) {\n const registeredPlugin = SceneLoader._RegisteredPlugins[extension];\n if (registeredPlugin) {\n return registeredPlugin;\n }\n Logger.Warn(\"Unable to find a plugin to load \" +\n extension +\n \" files. Trying to use .babylon default plugin. To load from a specific filetype (eg. gltf) see: https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes\");\n return SceneLoader.GetDefaultPlugin();\n }\n static _GetPluginForDirectLoad(data) {\n for (const extension in SceneLoader._RegisteredPlugins) {\n const plugin = SceneLoader._RegisteredPlugins[extension].plugin;\n if (plugin.canDirectLoad && plugin.canDirectLoad(data)) {\n return SceneLoader._RegisteredPlugins[extension];\n }\n }\n return SceneLoader.GetDefaultPlugin();\n }\n static _GetPluginForFilename(sceneFilename) {\n const queryStringPosition = sceneFilename.indexOf(\"?\");\n if (queryStringPosition !== -1) {\n sceneFilename = sceneFilename.substring(0, queryStringPosition);\n }\n const dotPosition = sceneFilename.lastIndexOf(\".\");\n const extension = sceneFilename.substring(dotPosition, sceneFilename.length).toLowerCase();\n return SceneLoader._GetPluginForExtension(extension);\n }\n static _GetDirectLoad(sceneFilename) {\n if (sceneFilename.substr(0, 5) === \"data:\") {\n return sceneFilename.substr(5);\n }\n return null;\n }\n static _FormatErrorMessage(fileInfo, message, exception) {\n const fromLoad = fileInfo.rawData ? \"binary data\" : fileInfo.url;\n let errorMessage = \"Unable to load from \" + fromLoad;\n if (message) {\n errorMessage += `: ${message}`;\n }\n else if (exception) {\n errorMessage += `: ${exception}`;\n }\n return errorMessage;\n }\n static _LoadData(fileInfo, scene, onSuccess, onProgress, onError, onDispose, pluginExtension, name) {\n const directLoad = SceneLoader._GetDirectLoad(fileInfo.url);\n if (fileInfo.rawData && !pluginExtension) {\n throw \"When using ArrayBufferView to load data the file extension must be provided.\";\n }\n const registeredPlugin = pluginExtension\n ? SceneLoader._GetPluginForExtension(pluginExtension)\n : directLoad\n ? SceneLoader._GetPluginForDirectLoad(fileInfo.url)\n : SceneLoader._GetPluginForFilename(fileInfo.url);\n if (fileInfo.rawData && !registeredPlugin.isBinary) {\n throw \"Loading from ArrayBufferView can not be used with plugins that don't support binary loading.\";\n }\n let plugin;\n if (registeredPlugin.plugin.createPlugin !== undefined) {\n plugin = registeredPlugin.plugin.createPlugin();\n }\n else {\n plugin = registeredPlugin.plugin;\n }\n if (!plugin) {\n throw \"The loader plugin corresponding to the file type you are trying to load has not been found. If using es6, please import the plugin you wish to use before.\";\n }\n SceneLoader.OnPluginActivatedObservable.notifyObservers(plugin);\n // Check if we have a direct load url. If the plugin is registered to handle\n // it or it's not a base64 data url, then pass it through the direct load path.\n if (directLoad && ((plugin.canDirectLoad && plugin.canDirectLoad(fileInfo.url)) || !IsBase64DataUrl(fileInfo.url))) {\n if (plugin.directLoad) {\n const result = plugin.directLoad(scene, directLoad);\n if (result.then) {\n result\n .then((data) => {\n onSuccess(plugin, data);\n })\n .catch((error) => {\n onError(\"Error in directLoad of _loadData: \" + error, error);\n });\n }\n else {\n onSuccess(plugin, result);\n }\n }\n else {\n onSuccess(plugin, directLoad);\n }\n return plugin;\n }\n const useArrayBuffer = registeredPlugin.isBinary;\n const dataCallback = (data, responseURL) => {\n if (scene.isDisposed) {\n onError(\"Scene has been disposed\");\n return;\n }\n onSuccess(plugin, data, responseURL);\n };\n let request = null;\n let pluginDisposed = false;\n const onDisposeObservable = plugin.onDisposeObservable;\n if (onDisposeObservable) {\n onDisposeObservable.add(() => {\n pluginDisposed = true;\n if (request) {\n request.abort();\n request = null;\n }\n onDispose();\n });\n }\n const manifestChecked = () => {\n if (pluginDisposed) {\n return;\n }\n const errorCallback = (request, exception) => {\n onError(request === null || request === void 0 ? void 0 : request.statusText, exception);\n };\n if (!plugin.loadFile && fileInfo.rawData) {\n throw \"Plugin does not support loading ArrayBufferView.\";\n }\n request = plugin.loadFile\n ? plugin.loadFile(scene, fileInfo.rawData || fileInfo.file || fileInfo.url, fileInfo.rootUrl, dataCallback, onProgress, useArrayBuffer, errorCallback, name)\n : scene._loadFile(fileInfo.file || fileInfo.url, dataCallback, onProgress, true, useArrayBuffer, errorCallback);\n };\n const engine = scene.getEngine();\n let canUseOfflineSupport = engine.enableOfflineSupport;\n if (canUseOfflineSupport) {\n // Also check for exceptions\n let exceptionFound = false;\n for (const regex of scene.disableOfflineSupportExceptionRules) {\n if (regex.test(fileInfo.url)) {\n exceptionFound = true;\n break;\n }\n }\n canUseOfflineSupport = !exceptionFound;\n }\n if (canUseOfflineSupport && Engine.OfflineProviderFactory) {\n // Checking if a manifest file has been set for this scene and if offline mode has been requested\n scene.offlineProvider = Engine.OfflineProviderFactory(fileInfo.url, manifestChecked, engine.disableManifestCheck);\n }\n else {\n manifestChecked();\n }\n return plugin;\n }\n static _GetFileInfo(rootUrl, sceneFilename) {\n let url;\n let name;\n let file = null;\n let rawData = null;\n if (!sceneFilename) {\n url = rootUrl;\n name = Tools.GetFilename(rootUrl);\n rootUrl = Tools.GetFolderPath(rootUrl);\n }\n else if (sceneFilename.name) {\n const sceneFile = sceneFilename;\n url = `file:${sceneFile.name}`;\n name = sceneFile.name;\n file = sceneFile;\n }\n else if (ArrayBuffer.isView(sceneFilename)) {\n url = \"\";\n name = \"arrayBuffer\";\n rawData = sceneFilename;\n }\n else if (typeof sceneFilename === \"string\" && sceneFilename.startsWith(\"data:\")) {\n url = sceneFilename;\n name = \"\";\n }\n else {\n const filename = sceneFilename;\n if (filename.substr(0, 1) === \"/\") {\n Tools.Error(\"Wrong sceneFilename parameter\");\n return null;\n }\n url = rootUrl + filename;\n name = filename;\n }\n return {\n url: url,\n rootUrl: rootUrl,\n name: name,\n file: file,\n rawData,\n };\n }\n // Public functions\n /**\n * Gets a plugin that can load the given extension\n * @param extension defines the extension to load\n * @returns a plugin or null if none works\n */\n static GetPluginForExtension(extension) {\n return SceneLoader._GetPluginForExtension(extension).plugin;\n }\n /**\n * Gets a boolean indicating that the given extension can be loaded\n * @param extension defines the extension to load\n * @returns true if the extension is supported\n */\n static IsPluginForExtensionAvailable(extension) {\n return !!SceneLoader._RegisteredPlugins[extension];\n }\n /**\n * Adds a new plugin to the list of registered plugins\n * @param plugin defines the plugin to add\n */\n static RegisterPlugin(plugin) {\n if (typeof plugin.extensions === \"string\") {\n const extension = plugin.extensions;\n SceneLoader._RegisteredPlugins[extension.toLowerCase()] = {\n plugin: plugin,\n isBinary: false,\n };\n }\n else {\n const extensions = plugin.extensions;\n Object.keys(extensions).forEach((extension) => {\n SceneLoader._RegisteredPlugins[extension.toLowerCase()] = {\n plugin: plugin,\n isBinary: extensions[extension].isBinary,\n };\n });\n }\n }\n /**\n * Import meshes into a scene\n * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene the instance of BABYLON.Scene to append to\n * @param onSuccess a callback with a list of imported meshes, particleSystems, skeletons, and animationGroups when import succeeds\n * @param onProgress a callback with a progress event for each file being loaded\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded plugin\n */\n static ImportMesh(meshNames, rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = \"\") {\n if (!scene) {\n Logger.Error(\"No scene available to import mesh to\");\n return null;\n }\n const fileInfo = SceneLoader._GetFileInfo(rootUrl, sceneFilename);\n if (!fileInfo) {\n return null;\n }\n const loadingToken = {};\n scene.addPendingData(loadingToken);\n const disposeHandler = () => {\n scene.removePendingData(loadingToken);\n };\n const errorHandler = (message, exception) => {\n const errorMessage = SceneLoader._FormatErrorMessage(fileInfo, message, exception);\n if (onError) {\n onError(scene, errorMessage, new RuntimeError(errorMessage, ErrorCodes.SceneLoaderError, exception));\n }\n else {\n Logger.Error(errorMessage);\n // should the exception be thrown?\n }\n disposeHandler();\n };\n const progressHandler = onProgress\n ? (event) => {\n try {\n onProgress(event);\n }\n catch (e) {\n errorHandler(\"Error in onProgress callback: \" + e, e);\n }\n }\n : undefined;\n const successHandler = (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights) => {\n scene.importedMeshesFiles.push(fileInfo.url);\n if (onSuccess) {\n try {\n onSuccess(meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights);\n }\n catch (e) {\n errorHandler(\"Error in onSuccess callback: \" + e, e);\n }\n }\n scene.removePendingData(loadingToken);\n };\n return SceneLoader._LoadData(fileInfo, scene, (plugin, data, responseURL) => {\n if (plugin.rewriteRootURL) {\n fileInfo.rootUrl = plugin.rewriteRootURL(fileInfo.rootUrl, responseURL);\n }\n if (plugin.importMesh) {\n const syncedPlugin = plugin;\n const meshes = new Array();\n const particleSystems = new Array();\n const skeletons = new Array();\n if (!syncedPlugin.importMesh(meshNames, scene, data, fileInfo.rootUrl, meshes, particleSystems, skeletons, errorHandler)) {\n return;\n }\n scene.loadingPluginName = plugin.name;\n successHandler(meshes, particleSystems, skeletons, [], [], [], []);\n }\n else {\n const asyncedPlugin = plugin;\n asyncedPlugin\n .importMeshAsync(meshNames, scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name)\n .then((result) => {\n scene.loadingPluginName = plugin.name;\n successHandler(result.meshes, result.particleSystems, result.skeletons, result.animationGroups, result.transformNodes, result.geometries, result.lights);\n })\n .catch((error) => {\n errorHandler(error.message, error);\n });\n }\n }, progressHandler, errorHandler, disposeHandler, pluginExtension, name);\n }\n /**\n * Import meshes into a scene\n * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene the instance of BABYLON.Scene to append to\n * @param onProgress a callback with a progress event for each file being loaded\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded list of imported meshes, particle systems, skeletons, and animation groups\n */\n static ImportMeshAsync(meshNames, rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, onProgress = null, pluginExtension = null, name = \"\") {\n return new Promise((resolve, reject) => {\n SceneLoader.ImportMesh(meshNames, rootUrl, sceneFilename, scene, (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights) => {\n resolve({\n meshes: meshes,\n particleSystems: particleSystems,\n skeletons: skeletons,\n animationGroups: animationGroups,\n transformNodes: transformNodes,\n geometries: geometries,\n lights: lights,\n });\n }, onProgress, (scene, message, exception) => {\n reject(exception || new Error(message));\n }, pluginExtension, name);\n });\n }\n /**\n * Load a scene\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param engine is the instance of BABYLON.Engine to use to create the scene\n * @param onSuccess a callback with the scene when import succeeds\n * @param onProgress a callback with a progress event for each file being loaded\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded plugin\n */\n static Load(rootUrl, sceneFilename = \"\", engine = EngineStore.LastCreatedEngine, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = \"\") {\n if (!engine) {\n Tools.Error(\"No engine available\");\n return null;\n }\n return SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension, name);\n }\n /**\n * Load a scene\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param engine is the instance of BABYLON.Engine to use to create the scene\n * @param onProgress a callback with a progress event for each file being loaded\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded scene\n */\n static LoadAsync(rootUrl, sceneFilename = \"\", engine = EngineStore.LastCreatedEngine, onProgress = null, pluginExtension = null, name = \"\") {\n return new Promise((resolve, reject) => {\n SceneLoader.Load(rootUrl, sceneFilename, engine, (scene) => {\n resolve(scene);\n }, onProgress, (scene, message, exception) => {\n reject(exception || new Error(message));\n }, pluginExtension, name);\n });\n }\n /**\n * Append a scene\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene is the instance of BABYLON.Scene to append to\n * @param onSuccess a callback with the scene when import succeeds\n * @param onProgress a callback with a progress event for each file being loaded\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded plugin\n */\n static Append(rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = \"\") {\n if (!scene) {\n Logger.Error(\"No scene available to append to\");\n return null;\n }\n const fileInfo = SceneLoader._GetFileInfo(rootUrl, sceneFilename);\n if (!fileInfo) {\n return null;\n }\n const loadingToken = {};\n scene.addPendingData(loadingToken);\n const disposeHandler = () => {\n scene.removePendingData(loadingToken);\n };\n if (SceneLoader.ShowLoadingScreen && !this._ShowingLoadingScreen) {\n this._ShowingLoadingScreen = true;\n scene.getEngine().displayLoadingUI();\n scene.executeWhenReady(() => {\n scene.getEngine().hideLoadingUI();\n this._ShowingLoadingScreen = false;\n });\n }\n const errorHandler = (message, exception) => {\n const errorMessage = SceneLoader._FormatErrorMessage(fileInfo, message, exception);\n if (onError) {\n onError(scene, errorMessage, new RuntimeError(errorMessage, ErrorCodes.SceneLoaderError, exception));\n }\n else {\n Logger.Error(errorMessage);\n // should the exception be thrown?\n }\n disposeHandler();\n };\n const progressHandler = onProgress\n ? (event) => {\n try {\n onProgress(event);\n }\n catch (e) {\n errorHandler(\"Error in onProgress callback\", e);\n }\n }\n : undefined;\n const successHandler = () => {\n if (onSuccess) {\n try {\n onSuccess(scene);\n }\n catch (e) {\n errorHandler(\"Error in onSuccess callback\", e);\n }\n }\n scene.removePendingData(loadingToken);\n };\n return SceneLoader._LoadData(fileInfo, scene, (plugin, data) => {\n if (plugin.load) {\n const syncedPlugin = plugin;\n if (!syncedPlugin.load(scene, data, fileInfo.rootUrl, errorHandler)) {\n return;\n }\n scene.loadingPluginName = plugin.name;\n successHandler();\n }\n else {\n const asyncedPlugin = plugin;\n asyncedPlugin\n .loadAsync(scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name)\n .then(() => {\n scene.loadingPluginName = plugin.name;\n successHandler();\n })\n .catch((error) => {\n errorHandler(error.message, error);\n });\n }\n }, progressHandler, errorHandler, disposeHandler, pluginExtension, name);\n }\n /**\n * Append a scene\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene is the instance of BABYLON.Scene to append to\n * @param onProgress a callback with a progress event for each file being loaded\n * @param pluginExtension the extension used to determine the plugin\n * @returns The given scene\n */\n static AppendAsync(rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, onProgress = null, pluginExtension = null, name = \"\") {\n return new Promise((resolve, reject) => {\n SceneLoader.Append(rootUrl, sceneFilename, scene, (scene) => {\n resolve(scene);\n }, onProgress, (scene, message, exception) => {\n reject(exception || new Error(message));\n }, pluginExtension, name);\n });\n }\n /**\n * Load a scene into an asset container\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)\n * @param onSuccess a callback with the scene when import succeeds\n * @param onProgress a callback with a progress event for each file being loaded\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded plugin\n */\n static LoadAssetContainer(rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = \"\") {\n if (!scene) {\n Logger.Error(\"No scene available to load asset container to\");\n return null;\n }\n const fileInfo = SceneLoader._GetFileInfo(rootUrl, sceneFilename);\n if (!fileInfo) {\n return null;\n }\n const loadingToken = {};\n scene.addPendingData(loadingToken);\n const disposeHandler = () => {\n scene.removePendingData(loadingToken);\n };\n const errorHandler = (message, exception) => {\n const errorMessage = SceneLoader._FormatErrorMessage(fileInfo, message, exception);\n if (onError) {\n onError(scene, errorMessage, new RuntimeError(errorMessage, ErrorCodes.SceneLoaderError, exception));\n }\n else {\n Logger.Error(errorMessage);\n // should the exception be thrown?\n }\n disposeHandler();\n };\n const progressHandler = onProgress\n ? (event) => {\n try {\n onProgress(event);\n }\n catch (e) {\n errorHandler(\"Error in onProgress callback\", e);\n }\n }\n : undefined;\n const successHandler = (assets) => {\n if (onSuccess) {\n try {\n onSuccess(assets);\n }\n catch (e) {\n errorHandler(\"Error in onSuccess callback\", e);\n }\n }\n scene.removePendingData(loadingToken);\n };\n return SceneLoader._LoadData(fileInfo, scene, (plugin, data) => {\n if (plugin.loadAssetContainer) {\n const syncedPlugin = plugin;\n const assetContainer = syncedPlugin.loadAssetContainer(scene, data, fileInfo.rootUrl, errorHandler);\n if (!assetContainer) {\n return;\n }\n assetContainer.populateRootNodes();\n scene.loadingPluginName = plugin.name;\n successHandler(assetContainer);\n }\n else if (plugin.loadAssetContainerAsync) {\n const asyncedPlugin = plugin;\n asyncedPlugin\n .loadAssetContainerAsync(scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name)\n .then((assetContainer) => {\n assetContainer.populateRootNodes();\n scene.loadingPluginName = plugin.name;\n successHandler(assetContainer);\n })\n .catch((error) => {\n errorHandler(error.message, error);\n });\n }\n else {\n errorHandler(\"LoadAssetContainer is not supported by this plugin. Plugin did not provide a loadAssetContainer or loadAssetContainerAsync method.\");\n }\n }, progressHandler, errorHandler, disposeHandler, pluginExtension, name);\n }\n /**\n * Load a scene into an asset container\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene (default: empty string)\n * @param scene is the instance of Scene to append to\n * @param onProgress a callback with a progress event for each file being loaded\n * @param pluginExtension the extension used to determine the plugin\n * @returns The loaded asset container\n */\n static LoadAssetContainerAsync(rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, onProgress = null, pluginExtension = null) {\n return new Promise((resolve, reject) => {\n SceneLoader.LoadAssetContainer(rootUrl, sceneFilename, scene, (assetContainer) => {\n resolve(assetContainer);\n }, onProgress, (scene, message, exception) => {\n reject(exception || new Error(message));\n }, pluginExtension);\n });\n }\n /**\n * Import animations from a file into a scene\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)\n * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise\n * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones\n * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)\n * @param onSuccess a callback with the scene when import succeeds\n * @param onProgress a callback with a progress event for each file being loaded\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\n * @param pluginExtension the extension used to determine the plugin\n */\n static ImportAnimations(rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = SceneLoaderAnimationGroupLoadingMode.Clean, targetConverter = null, onSuccess = null, onProgress = null, onError = null, pluginExtension = null) {\n if (!scene) {\n Logger.Error(\"No scene available to load animations to\");\n return;\n }\n if (overwriteAnimations) {\n // Reset, stop and dispose all animations before loading new ones\n for (const animatable of scene.animatables) {\n animatable.reset();\n }\n scene.stopAllAnimations();\n scene.animationGroups.slice().forEach((animationGroup) => {\n animationGroup.dispose();\n });\n const nodes = scene.getNodes();\n nodes.forEach((node) => {\n if (node.animations) {\n node.animations = [];\n }\n });\n }\n else {\n switch (animationGroupLoadingMode) {\n case SceneLoaderAnimationGroupLoadingMode.Clean:\n scene.animationGroups.slice().forEach((animationGroup) => {\n animationGroup.dispose();\n });\n break;\n case SceneLoaderAnimationGroupLoadingMode.Stop:\n scene.animationGroups.forEach((animationGroup) => {\n animationGroup.stop();\n });\n break;\n case SceneLoaderAnimationGroupLoadingMode.Sync:\n scene.animationGroups.forEach((animationGroup) => {\n animationGroup.reset();\n animationGroup.restart();\n });\n break;\n case SceneLoaderAnimationGroupLoadingMode.NoSync:\n // nothing to do\n break;\n default:\n Logger.Error(\"Unknown animation group loading mode value '\" + animationGroupLoadingMode + \"'\");\n return;\n }\n }\n const startingIndexForNewAnimatables = scene.animatables.length;\n const onAssetContainerLoaded = (container) => {\n container.mergeAnimationsTo(scene, scene.animatables.slice(startingIndexForNewAnimatables), targetConverter);\n container.dispose();\n scene.onAnimationFileImportedObservable.notifyObservers(scene);\n if (onSuccess) {\n onSuccess(scene);\n }\n };\n this.LoadAssetContainer(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError, pluginExtension);\n }\n /**\n * Import animations from a file into a scene\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\n * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)\n * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise\n * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones\n * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)\n * @param onSuccess a callback with the scene when import succeeds\n * @param onProgress a callback with a progress event for each file being loaded\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\n * @param pluginExtension the extension used to determine the plugin\n * @returns the updated scene with imported animations\n */\n static ImportAnimationsAsync(rootUrl, sceneFilename = \"\", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = SceneLoaderAnimationGroupLoadingMode.Clean, targetConverter = null, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onSuccess = null, onProgress = null, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onError = null, pluginExtension = null) {\n return new Promise((resolve, reject) => {\n SceneLoader.ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, (_scene) => {\n resolve(_scene);\n }, onProgress, (_scene, message, exception) => {\n reject(exception || new Error(message));\n }, pluginExtension);\n });\n }\n }\n /**\n * No logging while loading\n */\n SceneLoader.NO_LOGGING = 0;\n /**\n * Minimal logging while loading\n */\n SceneLoader.MINIMAL_LOGGING = 1;\n /**\n * Summary logging while loading\n */\n SceneLoader.SUMMARY_LOGGING = 2;\n /**\n * Detailed logging while loading\n */\n SceneLoader.DETAILED_LOGGING = 3;\n // Members\n /**\n * Event raised when a plugin is used to load a scene\n */\n SceneLoader.OnPluginActivatedObservable = new Observable$1();\n SceneLoader._RegisteredPlugins = {};\n SceneLoader._ShowingLoadingScreen = false;\n\n /**\n * An Abstract Motion controller\n * This class receives an xrInput and a profile layout and uses those to initialize the components\n * Each component has an observable to check for changes in value and state\n */\n class WebXRAbstractMotionController {\n /**\n * constructs a new abstract motion controller\n * @param scene the scene to which the model of the controller will be added\n * @param layout The profile layout to load\n * @param gamepadObject The gamepad object correlating to this controller\n * @param handedness handedness (left/right/none) of this controller\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\n * @param _controllerCache a cache holding controller models already loaded in this session\n */\n constructor(\n // eslint-disable-next-line @typescript-eslint/naming-convention\n scene, \n // eslint-disable-next-line @typescript-eslint/naming-convention\n layout, \n /**\n * The gamepad object correlating to this controller\n */\n gamepadObject, \n /**\n * handedness (left/right/none) of this controller\n */\n handedness, \n /**\n * @internal\n */\n _doNotLoadControllerMesh = false, _controllerCache) {\n this.scene = scene;\n this.layout = layout;\n this.gamepadObject = gamepadObject;\n this.handedness = handedness;\n this._doNotLoadControllerMesh = _doNotLoadControllerMesh;\n this._controllerCache = _controllerCache;\n this._initComponent = (id) => {\n if (!id) {\n return;\n }\n const componentDef = this.layout.components[id];\n const type = componentDef.type;\n const buttonIndex = componentDef.gamepadIndices.button;\n // search for axes\n const axes = [];\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\n }\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\n };\n this._modelReady = false;\n /**\n * A map of components (WebXRControllerComponent) in this motion controller\n * Components have a ComponentType and can also have both button and axis definitions\n */\n this.components = {};\n /**\n * Disable the model's animation. Can be set at any time.\n */\n this.disableAnimation = false;\n /**\n * Observers registered here will be triggered when the model of this controller is done loading\n */\n this.onModelLoadedObservable = new Observable$1();\n // initialize the components\n if (layout.components) {\n Object.keys(layout.components).forEach(this._initComponent);\n }\n // Model is loaded in WebXRInput\n }\n /**\n * Dispose this controller, the model mesh and all its components\n */\n dispose() {\n this.getComponentIds().forEach((id) => this.getComponent(id).dispose());\n if (this.rootMesh) {\n this.rootMesh.getChildren(undefined, true).forEach((node) => {\n node.setEnabled(false);\n });\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\n }\n }\n /**\n * Returns all components of specific type\n * @param type the type to search for\n * @returns an array of components with this type\n */\n getAllComponentsOfType(type) {\n return this.getComponentIds()\n .map((id) => this.components[id])\n .filter((component) => component.type === type);\n }\n /**\n * get a component based an its component id as defined in layout.components\n * @param id the id of the component\n * @returns the component correlates to the id or undefined if not found\n */\n getComponent(id) {\n return this.components[id];\n }\n /**\n * Get the list of components available in this motion controller\n * @returns an array of strings correlating to available components\n */\n getComponentIds() {\n return Object.keys(this.components);\n }\n /**\n * Get the first component of specific type\n * @param type type of component to find\n * @returns a controller component or null if not found\n */\n getComponentOfType(type) {\n return this.getAllComponentsOfType(type)[0] || null;\n }\n /**\n * Get the main (Select) component of this controller as defined in the layout\n * @returns the main component of this controller\n */\n getMainComponent() {\n return this.getComponent(this.layout.selectComponentId);\n }\n /**\n * Loads the model correlating to this controller\n * When the mesh is loaded, the onModelLoadedObservable will be triggered\n * @returns A promise fulfilled with the result of the model loading\n */\n async loadModel() {\n const useGeneric = !this._getModelLoadingConstraints();\n let loadingParams = this._getGenericFilenameAndPath();\n // Checking if GLB loader is present\n if (useGeneric) {\n Logger.Warn(\"Falling back to generic models\");\n }\n else {\n loadingParams = this._getFilenameAndPath();\n }\n return new Promise((resolve, reject) => {\n const meshesLoaded = (meshes) => {\n if (useGeneric) {\n this._getGenericParentMesh(meshes);\n }\n else {\n this._setRootMesh(meshes);\n }\n this._processLoadedModel(meshes);\n this._modelReady = true;\n this.onModelLoadedObservable.notifyObservers(this);\n resolve(true);\n };\n if (this._controllerCache) {\n // look for it in the cache\n const found = this._controllerCache.filter((c) => {\n return c.filename === loadingParams.filename && c.path === loadingParams.path;\n });\n if (found[0]) {\n found[0].meshes.forEach((mesh) => mesh.setEnabled(true));\n meshesLoaded(found[0].meshes);\n return;\n // found, don't continue to load\n }\n }\n SceneLoader.ImportMesh(\"\", loadingParams.path, loadingParams.filename, this.scene, (meshes) => {\n if (this._controllerCache) {\n this._controllerCache.push(Object.assign(Object.assign({}, loadingParams), { meshes }));\n }\n meshesLoaded(meshes);\n }, null, (_scene, message) => {\n Logger.Log(message);\n Logger.Warn(`Failed to retrieve controller model of type ${this.profileId} from the remote server: ${loadingParams.path}${loadingParams.filename}`);\n reject(message);\n });\n });\n }\n /**\n * Update this model using the current XRFrame\n * @param xrFrame the current xr frame to use and update the model\n */\n updateFromXRFrame(xrFrame) {\n this.getComponentIds().forEach((id) => this.getComponent(id).update(this.gamepadObject));\n this.updateModel(xrFrame);\n }\n /**\n * Backwards compatibility due to a deeply-integrated typo\n */\n get handness() {\n return this.handedness;\n }\n /**\n * Pulse (vibrate) this controller\n * If the controller does not support pulses, this function will fail silently and return Promise directly after called\n * Consecutive calls to this function will cancel the last pulse call\n *\n * @param value the strength of the pulse in 0.0...1.0 range\n * @param duration Duration of the pulse in milliseconds\n * @param hapticActuatorIndex optional index of actuator (will usually be 0)\n * @returns a promise that will send true when the pulse has ended and false if the device doesn't support pulse or an error accrued\n */\n pulse(value, duration, hapticActuatorIndex = 0) {\n if (this.gamepadObject.hapticActuators && this.gamepadObject.hapticActuators[hapticActuatorIndex]) {\n return this.gamepadObject.hapticActuators[hapticActuatorIndex].pulse(value, duration);\n }\n else {\n return Promise.resolve(false);\n }\n }\n // Look through all children recursively. This will return null if no mesh exists with the given name.\n _getChildByName(node, name) {\n return node.getChildren((n) => n.name === name, false)[0];\n }\n // Look through only immediate children. This will return null if no mesh exists with the given name.\n _getImmediateChildByName(node, name) {\n return node.getChildren((n) => n.name == name, true)[0];\n }\n /**\n * Moves the axis on the controller mesh based on its current state\n * @param axisMap\n * @param axisValue the value of the axis which determines the meshes new position\n * @internal\n */\n _lerpTransform(axisMap, axisValue, fixValueCoordinates) {\n if (!axisMap.minMesh || !axisMap.maxMesh || !axisMap.valueMesh) {\n return;\n }\n if (!axisMap.minMesh.rotationQuaternion || !axisMap.maxMesh.rotationQuaternion || !axisMap.valueMesh.rotationQuaternion) {\n return;\n }\n // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)\n const lerpValue = fixValueCoordinates ? axisValue * 0.5 + 0.5 : axisValue;\n Quaternion.SlerpToRef(axisMap.minMesh.rotationQuaternion, axisMap.maxMesh.rotationQuaternion, lerpValue, axisMap.valueMesh.rotationQuaternion);\n Vector3.LerpToRef(axisMap.minMesh.position, axisMap.maxMesh.position, lerpValue, axisMap.valueMesh.position);\n }\n /**\n * Update the model itself with the current frame data\n * @param xrFrame the frame to use for updating the model mesh\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n updateModel(xrFrame) {\n if (!this._modelReady) {\n return;\n }\n this._updateModel(xrFrame);\n }\n _getGenericFilenameAndPath() {\n return {\n filename: \"generic.babylon\",\n path: \"https://controllers.babylonjs.com/generic/\",\n };\n }\n _getGenericParentMesh(meshes) {\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\n meshes.forEach((mesh) => {\n if (!mesh.parent) {\n mesh.isPickable = false;\n mesh.setParent(this.rootMesh);\n }\n });\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\n }\n }\n\n /**\n * A generic trigger-only motion controller for WebXR\n */\n class WebXRGenericTriggerMotionController extends WebXRAbstractMotionController {\n constructor(scene, gamepadObject, handedness) {\n super(scene, GenericTriggerLayout[handedness], gamepadObject, handedness);\n this.profileId = WebXRGenericTriggerMotionController.ProfileId;\n }\n _getFilenameAndPath() {\n return {\n filename: \"generic.babylon\",\n path: \"https://controllers.babylonjs.com/generic/\",\n };\n }\n _getModelLoadingConstraints() {\n return true;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _processLoadedModel(meshes) {\n // nothing to do\n }\n _setRootMesh(meshes) {\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\n meshes.forEach((mesh) => {\n mesh.isPickable = false;\n if (!mesh.parent) {\n mesh.setParent(this.rootMesh);\n }\n });\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\n }\n _updateModel() {\n // no-op\n }\n }\n /**\n * Static version of the profile id of this controller\n */\n WebXRGenericTriggerMotionController.ProfileId = \"generic-trigger\";\n // https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/generic/generic-trigger-touchpad-thumbstick.json\n const GenericTriggerLayout = {\n left: {\n selectComponentId: \"xr-standard-trigger\",\n components: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n \"xr-standard-trigger\": {\n type: \"trigger\",\n gamepadIndices: {\n button: 0,\n },\n rootNodeName: \"xr_standard_trigger\",\n visualResponses: {},\n },\n },\n gamepadMapping: \"xr-standard\",\n rootNodeName: \"generic-trigger-left\",\n assetPath: \"left.glb\",\n },\n right: {\n selectComponentId: \"xr-standard-trigger\",\n components: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n \"xr-standard-trigger\": {\n type: \"trigger\",\n gamepadIndices: {\n button: 0,\n },\n rootNodeName: \"xr_standard_trigger\",\n visualResponses: {},\n },\n },\n gamepadMapping: \"xr-standard\",\n rootNodeName: \"generic-trigger-right\",\n assetPath: \"right.glb\",\n },\n none: {\n selectComponentId: \"xr-standard-trigger\",\n components: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n \"xr-standard-trigger\": {\n type: \"trigger\",\n gamepadIndices: {\n button: 0,\n },\n rootNodeName: \"xr_standard_trigger\",\n visualResponses: {},\n },\n },\n gamepadMapping: \"xr-standard\",\n rootNodeName: \"generic-trigger-none\",\n assetPath: \"none.glb\",\n },\n };\n\n /**\n * Creates the VertexData for an ellipsoid, defaults to a sphere\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * segments sets the number of horizontal strips optional, default 32\n * * diameter sets the axes dimensions, diameterX, diameterY and diameterZ to the value of diameter, optional default 1\n * * diameterX sets the diameterX (x direction) of the ellipsoid, overwrites the diameterX set by diameter, optional, default diameter\n * * diameterY sets the diameterY (y direction) of the ellipsoid, overwrites the diameterY set by diameter, optional, default diameter\n * * diameterZ sets the diameterZ (z direction) of the ellipsoid, overwrites the diameterZ set by diameter, optional, default diameter\n * * arc a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the circumference (latitude) given by the arc value, optional, default 1\n * * slice a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the height (latitude) given by the arc value, optional, default 1\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.segments\n * @param options.diameter\n * @param options.diameterX\n * @param options.diameterY\n * @param options.diameterZ\n * @param options.arc\n * @param options.slice\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.dedupTopBottomIndices\n * @returns the VertexData of the ellipsoid\n */\n function CreateSphereVertexData(options) {\n const segments = (options.segments || 32) | 0;\n const diameterX = options.diameterX || options.diameter || 1;\n const diameterY = options.diameterY || options.diameter || 1;\n const diameterZ = options.diameterZ || options.diameter || 1;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n const slice = options.slice && options.slice <= 0 ? 1.0 : options.slice || 1.0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const dedupTopBottomIndices = !!options.dedupTopBottomIndices;\n const radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);\n const totalZRotationSteps = 2 + segments;\n const totalYRotationSteps = 2 * totalZRotationSteps;\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {\n const normalizedZ = zRotationStep / totalZRotationSteps;\n const angleZ = normalizedZ * Math.PI * slice;\n for (let yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {\n const normalizedY = yRotationStep / totalYRotationSteps;\n const angleY = normalizedY * Math.PI * 2 * arc;\n const rotationZ = Matrix.RotationZ(-angleZ);\n const rotationY = Matrix.RotationY(angleY);\n const afterRotZ = Vector3.TransformCoordinates(Vector3.Up(), rotationZ);\n const complete = Vector3.TransformCoordinates(afterRotZ, rotationY);\n const vertex = complete.multiply(radius);\n const normal = complete.divide(radius).normalize();\n positions.push(vertex.x, vertex.y, vertex.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(normalizedY, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - normalizedZ : normalizedZ);\n }\n if (zRotationStep > 0) {\n const verticesCount = positions.length / 3;\n for (let firstIndex = verticesCount - 2 * (totalYRotationSteps + 1); firstIndex + totalYRotationSteps + 2 < verticesCount; firstIndex++) {\n if (dedupTopBottomIndices) {\n if (zRotationStep > 1) {\n indices.push(firstIndex);\n indices.push(firstIndex + 1);\n indices.push(firstIndex + totalYRotationSteps + 1);\n }\n if (zRotationStep < totalZRotationSteps || slice < 1.0) {\n indices.push(firstIndex + totalYRotationSteps + 1);\n indices.push(firstIndex + 1);\n indices.push(firstIndex + totalYRotationSteps + 2);\n }\n }\n else {\n indices.push(firstIndex);\n indices.push(firstIndex + 1);\n indices.push(firstIndex + totalYRotationSteps + 1);\n indices.push(firstIndex + totalYRotationSteps + 1);\n indices.push(firstIndex + 1);\n indices.push(firstIndex + totalYRotationSteps + 2);\n }\n }\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a sphere mesh\n * * The parameter `diameter` sets the diameter size (float) of the sphere (default 1)\n * * You can set some different sphere dimensions, for instance to build an ellipsoid, by using the parameters `diameterX`, `diameterY` and `diameterZ` (all by default have the same value of `diameter`)\n * * The parameter `segments` sets the sphere number of horizontal stripes (positive integer, default 32)\n * * You can create an unclosed sphere with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference (latitude) : 2 x PI x ratio\n * * You can create an unclosed sphere on its height with the parameter `slice` (positive float, default1), valued between 0 and 1, what is the height ratio (longitude)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.segments\n * @param options.diameter\n * @param options.diameterX\n * @param options.diameterY\n * @param options.diameterZ\n * @param options.arc\n * @param options.slice\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the sphere mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#sphere\n */\n function CreateSphere(name, options = {}, scene = null) {\n const sphere = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n sphere._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateSphereVertexData(options);\n vertexData.applyToMesh(sphere, options.updatable);\n return sphere;\n }\n /**\n * Class containing static functions to help procedurally build meshes\n * @deprecated use CreateSphere directly\n */\n const SphereBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateSphere,\n };\n VertexData.CreateSphere = CreateSphereVertexData;\n Mesh.CreateSphere = (name, segments, diameter, scene, updatable, sideOrientation) => {\n const options = {\n segments: segments,\n diameterX: diameter,\n diameterY: diameter,\n diameterZ: diameter,\n sideOrientation: sideOrientation,\n updatable: updatable,\n };\n return CreateSphere(name, options, scene);\n };\n\n /**\n * A profiled motion controller has its profile loaded from an online repository.\n * The class is responsible of loading the model, mapping the keys and enabling model-animations\n */\n class WebXRProfiledMotionController extends WebXRAbstractMotionController {\n constructor(scene, xrInput, _profile, _repositoryUrl, \n // eslint-disable-next-line @typescript-eslint/naming-convention\n controllerCache) {\n super(scene, _profile.layouts[xrInput.handedness || \"none\"], xrInput.gamepad, xrInput.handedness, undefined, controllerCache);\n this._repositoryUrl = _repositoryUrl;\n this.controllerCache = controllerCache;\n this._buttonMeshMapping = {};\n this._touchDots = {};\n this.profileId = _profile.profileId;\n }\n dispose() {\n super.dispose();\n if (!this.controllerCache) {\n Object.keys(this._touchDots).forEach((visResKey) => {\n this._touchDots[visResKey].dispose();\n });\n }\n }\n _getFilenameAndPath() {\n return {\n filename: this.layout.assetPath,\n path: `${this._repositoryUrl}/profiles/${this.profileId}/`,\n };\n }\n _getModelLoadingConstraints() {\n const glbLoaded = SceneLoader.IsPluginForExtensionAvailable(\".glb\");\n if (!glbLoaded) {\n Logger.Warn(\"glTF / glb loader was not registered, using generic controller instead\");\n }\n return glbLoaded;\n }\n _processLoadedModel(_meshes) {\n this.getComponentIds().forEach((type) => {\n const componentInLayout = this.layout.components[type];\n this._buttonMeshMapping[type] = {\n mainMesh: this._getChildByName(this.rootMesh, componentInLayout.rootNodeName),\n states: {},\n };\n Object.keys(componentInLayout.visualResponses).forEach((visualResponseKey) => {\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\n if (visResponse.valueNodeProperty === \"transform\") {\n this._buttonMeshMapping[type].states[visualResponseKey] = {\n valueMesh: this._getChildByName(this.rootMesh, visResponse.valueNodeName),\n minMesh: this._getChildByName(this.rootMesh, visResponse.minNodeName),\n maxMesh: this._getChildByName(this.rootMesh, visResponse.maxNodeName),\n };\n }\n else {\n // visibility, usually for touchpads\n const nameOfMesh = componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && componentInLayout.touchPointNodeName\n ? componentInLayout.touchPointNodeName\n : visResponse.valueNodeName;\n this._buttonMeshMapping[type].states[visualResponseKey] = {\n valueMesh: this._getChildByName(this.rootMesh, nameOfMesh),\n };\n if (componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && !this._touchDots[visualResponseKey]) {\n const dot = CreateSphere(visualResponseKey + \"dot\", {\n diameter: 0.0015,\n segments: 8,\n }, this.scene);\n dot.material = new StandardMaterial(visualResponseKey + \"mat\", this.scene);\n dot.material.diffuseColor = Color3.Red();\n dot.parent = this._buttonMeshMapping[type].states[visualResponseKey].valueMesh || null;\n dot.isVisible = false;\n this._touchDots[visualResponseKey] = dot;\n }\n }\n });\n });\n }\n _setRootMesh(meshes) {\n this.rootMesh = new Mesh(this.profileId + \"-\" + this.handedness, this.scene);\n this.rootMesh.isPickable = false;\n let rootMesh;\n // Find the root node in the loaded glTF scene, and attach it as a child of 'parentMesh'\n for (let i = 0; i < meshes.length; i++) {\n const mesh = meshes[i];\n mesh.isPickable = false;\n if (!mesh.parent) {\n // Handle root node, attach to the new parentMesh\n rootMesh = mesh;\n }\n }\n if (rootMesh) {\n rootMesh.setParent(this.rootMesh);\n }\n if (!this.scene.useRightHandedSystem) {\n this.rootMesh.rotate(Axis.Y, Math.PI, Space.WORLD);\n }\n }\n _updateModel(_xrFrame) {\n if (this.disableAnimation) {\n return;\n }\n this.getComponentIds().forEach((id) => {\n const component = this.getComponent(id);\n if (!component.hasChanges) {\n return;\n }\n const meshes = this._buttonMeshMapping[id];\n const componentInLayout = this.layout.components[id];\n Object.keys(componentInLayout.visualResponses).forEach((visualResponseKey) => {\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\n let value = component.value;\n if (visResponse.componentProperty === \"xAxis\") {\n value = component.axes.x;\n }\n else if (visResponse.componentProperty === \"yAxis\") {\n value = component.axes.y;\n }\n if (visResponse.valueNodeProperty === \"transform\") {\n this._lerpTransform(meshes.states[visualResponseKey], value, visResponse.componentProperty !== \"button\");\n }\n else {\n // visibility\n const valueMesh = meshes.states[visualResponseKey].valueMesh;\n if (valueMesh) {\n valueMesh.isVisible = component.touched || component.pressed;\n }\n if (this._touchDots[visualResponseKey]) {\n this._touchDots[visualResponseKey].isVisible = component.touched || component.pressed;\n }\n }\n });\n });\n }\n }\n\n /**\n * The MotionController Manager manages all registered motion controllers and loads the right one when needed.\n *\n * When this repository is complete: https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/assets\n * it should be replaced with auto-loaded controllers.\n *\n * When using a model try to stay as generic as possible. Eventually there will be no need in any of the controller classes\n */\n const controllerCache = [];\n /**\n * Motion controller manager is managing the different webxr profiles and makes sure the right\n * controller is being loaded.\n */\n class WebXRMotionControllerManager {\n /**\n * Clear the cache used for profile loading and reload when requested again\n */\n static ClearProfilesCache() {\n this._ProfilesList = null;\n this._ProfileLoadingPromises = {};\n }\n /**\n * Register the default fallbacks.\n * This function is called automatically when this file is imported.\n */\n static DefaultFallbacks() {\n this.RegisterFallbacksForProfileId(\"google-daydream\", [\"generic-touchpad\"]);\n this.RegisterFallbacksForProfileId(\"htc-vive-focus\", [\"generic-trigger-touchpad\"]);\n this.RegisterFallbacksForProfileId(\"htc-vive\", [\"generic-trigger-squeeze-touchpad\"]);\n this.RegisterFallbacksForProfileId(\"magicleap-one\", [\"generic-trigger-squeeze-touchpad\"]);\n this.RegisterFallbacksForProfileId(\"windows-mixed-reality\", [\"generic-trigger-squeeze-touchpad-thumbstick\"]);\n this.RegisterFallbacksForProfileId(\"microsoft-mixed-reality\", [\"windows-mixed-reality\", \"generic-trigger-squeeze-touchpad-thumbstick\"]);\n this.RegisterFallbacksForProfileId(\"oculus-go\", [\"generic-trigger-touchpad\"]);\n this.RegisterFallbacksForProfileId(\"oculus-touch-v2\", [\"oculus-touch\", \"generic-trigger-squeeze-thumbstick\"]);\n this.RegisterFallbacksForProfileId(\"oculus-touch\", [\"generic-trigger-squeeze-thumbstick\"]);\n this.RegisterFallbacksForProfileId(\"samsung-gearvr\", [\"windows-mixed-reality\", \"generic-trigger-squeeze-touchpad-thumbstick\"]);\n this.RegisterFallbacksForProfileId(\"samsung-odyssey\", [\"generic-touchpad\"]);\n this.RegisterFallbacksForProfileId(\"valve-index\", [\"generic-trigger-squeeze-touchpad-thumbstick\"]);\n this.RegisterFallbacksForProfileId(\"generic-hand-select\", [\"generic-trigger\"]);\n }\n /**\n * Find a fallback profile if the profile was not found. There are a few predefined generic profiles.\n * @param profileId the profile to which a fallback needs to be found\n * @returns an array with corresponding fallback profiles\n */\n static FindFallbackWithProfileId(profileId) {\n const returnArray = this._Fallbacks[profileId] || [];\n returnArray.unshift(profileId);\n return returnArray;\n }\n /**\n * When acquiring a new xrInput object (usually by the WebXRInput class), match it with the correct profile.\n * The order of search:\n *\n * 1) Iterate the profiles array of the xr input and try finding a corresponding motion controller\n * 2) (If not found) search in the gamepad id and try using it (legacy versions only)\n * 3) search for registered fallbacks (should be redundant, nonetheless it makes sense to check)\n * 4) return the generic trigger controller if none were found\n *\n * @param xrInput the xrInput to which a new controller is initialized\n * @param scene the scene to which the model will be added\n * @param forceProfile force a certain profile for this controller\n * @returns A promise that fulfils with the motion controller class for this profile id or the generic standard class if none was found\n */\n static GetMotionControllerWithXRInput(xrInput, scene, forceProfile) {\n const profileArray = [];\n if (forceProfile) {\n profileArray.push(forceProfile);\n }\n profileArray.push(...(xrInput.profiles || []));\n // emulator support\n if (profileArray.length && !profileArray[0]) {\n // remove the first \"undefined\" that the emulator is adding\n profileArray.pop();\n }\n // legacy support - try using the gamepad id\n if (xrInput.gamepad && xrInput.gamepad.id) {\n switch (xrInput.gamepad.id) {\n case xrInput.gamepad.id.match(/oculus touch/gi) ? xrInput.gamepad.id : undefined:\n // oculus in gamepad id\n profileArray.push(\"oculus-touch-v2\");\n break;\n }\n }\n // make sure microsoft/windows mixed reality works correctly\n const windowsMRIdx = profileArray.indexOf(\"windows-mixed-reality\");\n if (windowsMRIdx !== -1) {\n profileArray.splice(windowsMRIdx, 0, \"microsoft-mixed-reality\");\n }\n if (!profileArray.length) {\n profileArray.push(\"generic-trigger\");\n }\n if (this.UseOnlineRepository) {\n const firstFunction = this.PrioritizeOnlineRepository ? this._LoadProfileFromRepository : this._LoadProfilesFromAvailableControllers;\n const secondFunction = this.PrioritizeOnlineRepository ? this._LoadProfilesFromAvailableControllers : this._LoadProfileFromRepository;\n return firstFunction.call(this, profileArray, xrInput, scene).catch(() => {\n return secondFunction.call(this, profileArray, xrInput, scene);\n });\n }\n else {\n // use only available functions\n return this._LoadProfilesFromAvailableControllers(profileArray, xrInput, scene);\n }\n }\n /**\n * Register a new controller based on its profile. This function will be called by the controller classes themselves.\n *\n * If you are missing a profile, make sure it is imported in your source, otherwise it will not register.\n *\n * @param type the profile type to register\n * @param constructFunction the function to be called when loading this profile\n */\n static RegisterController(type, constructFunction) {\n this._AvailableControllers[type] = constructFunction;\n }\n /**\n * Register a fallback to a specific profile.\n * @param profileId the profileId that will receive the fallbacks\n * @param fallbacks A list of fallback profiles\n */\n static RegisterFallbacksForProfileId(profileId, fallbacks) {\n if (this._Fallbacks[profileId]) {\n this._Fallbacks[profileId].push(...fallbacks);\n }\n else {\n this._Fallbacks[profileId] = fallbacks;\n }\n }\n /**\n * Will update the list of profiles available in the repository\n * @returns a promise that resolves to a map of profiles available online\n */\n static UpdateProfilesList() {\n this._ProfilesList = Tools.LoadFileAsync(this.BaseRepositoryUrl + \"/profiles/profilesList.json\", false).then((data) => {\n return JSON.parse(data.toString());\n });\n return this._ProfilesList;\n }\n /**\n * Clear the controller's cache (usually happens at the end of a session)\n */\n static ClearControllerCache() {\n controllerCache.forEach((cacheItem) => {\n cacheItem.meshes.forEach((mesh) => {\n mesh.dispose(false, true);\n });\n });\n controllerCache.length = 0;\n }\n static _LoadProfileFromRepository(profileArray, xrInput, scene) {\n return Promise.resolve()\n .then(() => {\n if (!this._ProfilesList) {\n return this.UpdateProfilesList();\n }\n else {\n return this._ProfilesList;\n }\n })\n .then((profilesList) => {\n // load the right profile\n for (let i = 0; i < profileArray.length; ++i) {\n // defensive\n if (!profileArray[i]) {\n continue;\n }\n if (profilesList[profileArray[i]]) {\n return profileArray[i];\n }\n }\n throw new Error(`neither controller ${profileArray[0]} nor all fallbacks were found in the repository,`);\n })\n .then((profileToLoad) => {\n // load the profile\n if (!this._ProfileLoadingPromises[profileToLoad]) {\n this._ProfileLoadingPromises[profileToLoad] = Tools.LoadFileAsync(`${this.BaseRepositoryUrl}/profiles/${profileToLoad}/profile.json`, false).then((data) => JSON.parse(data));\n }\n return this._ProfileLoadingPromises[profileToLoad];\n })\n .then((profile) => {\n return new WebXRProfiledMotionController(scene, xrInput, profile, this.BaseRepositoryUrl, this.DisableControllerCache ? undefined : controllerCache);\n });\n }\n static _LoadProfilesFromAvailableControllers(profileArray, xrInput, scene) {\n // check fallbacks\n for (let i = 0; i < profileArray.length; ++i) {\n // defensive\n if (!profileArray[i]) {\n continue;\n }\n const fallbacks = this.FindFallbackWithProfileId(profileArray[i]);\n for (let j = 0; j < fallbacks.length; ++j) {\n const constructionFunction = this._AvailableControllers[fallbacks[j]];\n if (constructionFunction) {\n return Promise.resolve(constructionFunction(xrInput, scene));\n }\n }\n }\n throw new Error(`no controller requested was found in the available controllers list`);\n }\n }\n WebXRMotionControllerManager._AvailableControllers = {};\n WebXRMotionControllerManager._Fallbacks = {};\n // cache for loading\n WebXRMotionControllerManager._ProfileLoadingPromises = {};\n /**\n * The base URL of the online controller repository. Can be changed at any time.\n */\n WebXRMotionControllerManager.BaseRepositoryUrl = \"https://immersive-web.github.io/webxr-input-profiles/packages/viewer/dist\";\n /**\n * Which repository gets priority - local or online\n */\n WebXRMotionControllerManager.PrioritizeOnlineRepository = true;\n /**\n * Use the online repository, or use only locally-defined controllers\n */\n WebXRMotionControllerManager.UseOnlineRepository = true;\n /**\n * Disable the controller cache and load the models each time a new WebXRProfileMotionController is loaded.\n * Defaults to true.\n */\n WebXRMotionControllerManager.DisableControllerCache = true;\n // register the generic profile(s) here so we will at least have them\n WebXRMotionControllerManager.RegisterController(WebXRGenericTriggerMotionController.ProfileId, (xrInput, scene) => {\n return new WebXRGenericTriggerMotionController(scene, xrInput.gamepad, xrInput.handedness);\n });\n // register fallbacks\n WebXRMotionControllerManager.DefaultFallbacks();\n\n let idCount = 0;\n /**\n * Represents an XR controller\n */\n class WebXRInputSource {\n /**\n * Creates the input source object\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport\n * @param _scene the scene which the controller should be associated to\n * @param inputSource the underlying input source for the controller\n * @param _options options for this controller creation\n */\n constructor(_scene, \n /** The underlying input source for the controller */\n inputSource, _options = {}) {\n this._scene = _scene;\n this.inputSource = inputSource;\n this._options = _options;\n this._tmpVector = new Vector3();\n this._disposed = false;\n /**\n * Event that fires when the controller is removed/disposed.\n * The object provided as event data is this controller, after associated assets were disposed.\n * uniqueId is still available.\n */\n this.onDisposeObservable = new Observable$1();\n /**\n * Will be triggered when the mesh associated with the motion controller is done loading.\n * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh\n * A shortened version of controller -> motion controller -> on mesh loaded.\n */\n this.onMeshLoadedObservable = new Observable$1();\n /**\n * Observers registered here will trigger when a motion controller profile was assigned to this xr controller\n */\n this.onMotionControllerInitObservable = new Observable$1();\n this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;\n this.pointer = new AbstractMesh(`${this._uniqueId}-pointer`, _scene);\n this.pointer.rotationQuaternion = new Quaternion();\n if (this.inputSource.gripSpace) {\n this.grip = new AbstractMesh(`${this._uniqueId}-grip`, this._scene);\n this.grip.rotationQuaternion = new Quaternion();\n }\n this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);\n // for now only load motion controllers if gamepad object available\n if (this.inputSource.gamepad && this.inputSource.targetRayMode === \"tracked-pointer\") {\n WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then((motionController) => {\n this.motionController = motionController;\n this.onMotionControllerInitObservable.notifyObservers(motionController);\n // should the model be loaded?\n if (!this._options.doNotLoadControllerMesh && !this.motionController._doNotLoadControllerMesh) {\n this.motionController.loadModel().then((success) => {\n var _a;\n if (success && this.motionController && this.motionController.rootMesh) {\n if (this._options.renderingGroupId) {\n // anything other than 0?\n this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;\n this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => (mesh.renderingGroupId = this._options.renderingGroupId));\n }\n this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);\n this.motionController.rootMesh.parent = this.grip || this.pointer;\n this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;\n }\n // make sure to dispose is the controller is already disposed\n if (this._disposed) {\n (_a = this.motionController) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n });\n }\n }, () => {\n Tools.Warn(`Could not find a matching motion controller for the registered input source`);\n });\n }\n }\n /**\n * Get this controllers unique id\n */\n get uniqueId() {\n return this._uniqueId;\n }\n /**\n * Disposes of the object\n */\n dispose() {\n if (this.grip) {\n this.grip.dispose(true);\n }\n if (this.motionController) {\n this.motionController.dispose();\n }\n this.pointer.dispose(true);\n this.onMotionControllerInitObservable.clear();\n this.onMeshLoadedObservable.clear();\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n this._disposed = true;\n }\n /**\n * Gets a world space ray coming from the pointer or grip\n * @param result the resulting ray\n * @param gripIfAvailable use the grip mesh instead of the pointer, if available\n */\n getWorldPointerRayToRef(result, gripIfAvailable = false) {\n const object = gripIfAvailable && this.grip ? this.grip : this.pointer;\n Vector3.TransformNormalToRef(this._tmpVector, object.getWorldMatrix(), result.direction);\n result.direction.normalize();\n result.origin.copyFrom(object.absolutePosition);\n result.length = 1000;\n }\n /**\n * Updates the controller pose based on the given XRFrame\n * @param xrFrame xr frame to update the pose with\n * @param referenceSpace reference space to use\n * @param xrCamera the xr camera, used for parenting\n */\n updateFromXRFrame(xrFrame, referenceSpace, xrCamera) {\n const pose = xrFrame.getPose(this.inputSource.targetRaySpace, referenceSpace);\n this._lastXRPose = pose;\n // Update the pointer mesh\n if (pose) {\n const pos = pose.transform.position;\n this.pointer.position.set(pos.x, pos.y, pos.z);\n const orientation = pose.transform.orientation;\n this.pointer.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\n if (!this._scene.useRightHandedSystem) {\n this.pointer.position.z *= -1;\n this.pointer.rotationQuaternion.z *= -1;\n this.pointer.rotationQuaternion.w *= -1;\n }\n this.pointer.parent = xrCamera.parent;\n }\n // Update the grip mesh if it exists\n if (this.inputSource.gripSpace && this.grip) {\n const pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);\n if (pose) {\n const pos = pose.transform.position;\n const orientation = pose.transform.orientation;\n this.grip.position.set(pos.x, pos.y, pos.z);\n this.grip.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\n if (!this._scene.useRightHandedSystem) {\n this.grip.position.z *= -1;\n this.grip.rotationQuaternion.z *= -1;\n this.grip.rotationQuaternion.w *= -1;\n }\n }\n this.grip.parent = xrCamera.parent;\n }\n if (this.motionController) {\n // either update buttons only or also position, if in gamepad mode\n this.motionController.updateFromXRFrame(xrFrame);\n }\n }\n }\n\n /**\n * XR input used to track XR inputs such as controllers/rays\n */\n class WebXRInput {\n /**\n * Initializes the WebXRInput\n * @param xrSessionManager the xr session manager for this session\n * @param xrCamera the WebXR camera for this session. Mainly used for teleportation\n * @param _options = initialization options for this xr input\n */\n constructor(\n /**\n * the xr session manager for this session\n */\n xrSessionManager, \n /**\n * the WebXR camera for this session. Mainly used for teleportation\n */\n xrCamera, _options = {}) {\n this.xrSessionManager = xrSessionManager;\n this.xrCamera = xrCamera;\n this._options = _options;\n /**\n * XR controllers being tracked\n */\n this.controllers = [];\n /**\n * Event when a controller has been connected/added\n */\n this.onControllerAddedObservable = new Observable$1();\n /**\n * Event when a controller has been removed/disconnected\n */\n this.onControllerRemovedObservable = new Observable$1();\n this._onInputSourcesChange = (event) => {\n this._addAndRemoveControllers(event.added, event.removed);\n };\n // Remove controllers when exiting XR\n this._sessionEndedObserver = this.xrSessionManager.onXRSessionEnded.add(() => {\n this._addAndRemoveControllers([], this.controllers.map((c) => {\n return c.inputSource;\n }));\n });\n this._sessionInitObserver = this.xrSessionManager.onXRSessionInit.add((session) => {\n session.addEventListener(\"inputsourceschange\", this._onInputSourcesChange);\n });\n this._frameObserver = this.xrSessionManager.onXRFrameObservable.add((frame) => {\n // Update controller pose info\n this.controllers.forEach((controller) => {\n controller.updateFromXRFrame(frame, this.xrSessionManager.referenceSpace, this.xrCamera);\n });\n });\n if (this._options.customControllersRepositoryURL) {\n WebXRMotionControllerManager.BaseRepositoryUrl = this._options.customControllersRepositoryURL;\n }\n WebXRMotionControllerManager.UseOnlineRepository = !this._options.disableOnlineControllerRepository;\n if (WebXRMotionControllerManager.UseOnlineRepository) {\n // pre-load the profiles list to load the controllers quicker afterwards\n try {\n WebXRMotionControllerManager.UpdateProfilesList().catch(() => {\n WebXRMotionControllerManager.UseOnlineRepository = false;\n });\n }\n catch (e) {\n WebXRMotionControllerManager.UseOnlineRepository = false;\n }\n }\n }\n _addAndRemoveControllers(addInputs, removeInputs) {\n // Add controllers if they don't already exist\n const sources = this.controllers.map((c) => {\n return c.inputSource;\n });\n for (const input of addInputs) {\n if (sources.indexOf(input) === -1) {\n const controller = new WebXRInputSource(this.xrSessionManager.scene, input, Object.assign(Object.assign({}, (this._options.controllerOptions || {})), { forceControllerProfile: this._options.forceInputProfile, doNotLoadControllerMesh: this._options.doNotLoadControllerMeshes, disableMotionControllerAnimation: this._options.disableControllerAnimation }));\n this.controllers.push(controller);\n this.onControllerAddedObservable.notifyObservers(controller);\n }\n }\n // Remove and dispose of controllers to be disposed\n const keepControllers = [];\n const removedControllers = [];\n this.controllers.forEach((c) => {\n if (removeInputs.indexOf(c.inputSource) === -1) {\n keepControllers.push(c);\n }\n else {\n removedControllers.push(c);\n }\n });\n this.controllers = keepControllers;\n removedControllers.forEach((c) => {\n this.onControllerRemovedObservable.notifyObservers(c);\n c.dispose();\n });\n }\n /**\n * Disposes of the object\n */\n dispose() {\n this.controllers.forEach((c) => {\n c.dispose();\n });\n this.xrSessionManager.onXRFrameObservable.remove(this._frameObserver);\n this.xrSessionManager.onXRSessionInit.remove(this._sessionInitObserver);\n this.xrSessionManager.onXRSessionEnded.remove(this._sessionEndedObserver);\n this.onControllerAddedObservable.clear();\n this.onControllerRemovedObservable.clear();\n // clear the controller cache\n WebXRMotionControllerManager.ClearControllerCache();\n }\n }\n\n /**\n * This is the base class for all WebXR features.\n * Since most features require almost the same resources and callbacks, this class can be used to simplify the development\n * Note that since the features manager is using the `IWebXRFeature` you are in no way obligated to use this class\n */\n class WebXRAbstractFeature {\n /**\n * Construct a new (abstract) WebXR feature\n * @param _xrSessionManager the xr session manager for this feature\n */\n constructor(_xrSessionManager) {\n this._xrSessionManager = _xrSessionManager;\n this._attached = false;\n this._removeOnDetach = [];\n /**\n * Is this feature disposed?\n */\n this.isDisposed = false;\n /**\n * Should auto-attach be disabled?\n */\n this.disableAutoAttach = false;\n /**\n * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)\n */\n this.xrNativeFeatureName = \"\";\n }\n /**\n * Is this feature attached\n */\n get attached() {\n return this._attached;\n }\n /**\n * attach this feature\n *\n * @param force should attachment be forced (even when already attached)\n * @returns true if successful, false is failed or already attached\n */\n attach(force) {\n // do not attach a disposed feature\n if (this.isDisposed) {\n return false;\n }\n if (!force) {\n if (this.attached) {\n return false;\n }\n }\n else {\n if (this.attached) {\n // detach first, to be sure\n this.detach();\n }\n }\n this._attached = true;\n this._addNewAttachObserver(this._xrSessionManager.onXRFrameObservable, (frame) => this._onXRFrame(frame));\n return true;\n }\n /**\n * detach this feature.\n *\n * @returns true if successful, false if failed or already detached\n */\n detach() {\n if (!this._attached) {\n this.disableAutoAttach = true;\n return false;\n }\n this._attached = false;\n this._removeOnDetach.forEach((toRemove) => {\n toRemove.observable.remove(toRemove.observer);\n });\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n this.detach();\n this.isDisposed = true;\n }\n /**\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\n *\n * @returns whether or not the feature is compatible in this environment\n */\n isCompatible() {\n return true;\n }\n /**\n * This is used to register callbacks that will automatically be removed when detach is called.\n * @param observable the observable to which the observer will be attached\n * @param callback the callback to register\n */\n _addNewAttachObserver(observable, callback) {\n this._removeOnDetach.push({\n observable,\n observer: observable.add(callback),\n });\n }\n }\n\n /**\n * Renders a layer on top of an existing scene\n */\n class UtilityLayerRenderer {\n /**\n * Gets the camera that is used to render the utility layer (when not set, this will be the last active camera)\n * @param getRigParentIfPossible if the current active camera is a rig camera, should its parent camera be returned\n * @returns the camera that is used when rendering the utility layer\n */\n getRenderCamera(getRigParentIfPossible) {\n if (this._renderCamera) {\n return this._renderCamera;\n }\n else {\n let activeCam;\n if (this.originalScene.activeCameras && this.originalScene.activeCameras.length > 1) {\n activeCam = this.originalScene.activeCameras[this.originalScene.activeCameras.length - 1];\n }\n else {\n activeCam = this.originalScene.activeCamera;\n }\n if (getRigParentIfPossible && activeCam && activeCam.isRigCamera) {\n return activeCam.rigParent;\n }\n return activeCam;\n }\n }\n /**\n * Sets the camera that should be used when rendering the utility layer (If set to null the last active camera will be used)\n * @param cam the camera that should be used when rendering the utility layer\n */\n setRenderCamera(cam) {\n this._renderCamera = cam;\n }\n /**\n * @internal\n * Light which used by gizmos to get light shading\n */\n _getSharedGizmoLight() {\n if (!this._sharedGizmoLight) {\n this._sharedGizmoLight = new HemisphericLight(\"shared gizmo light\", new Vector3(0, 1, 0), this.utilityLayerScene);\n this._sharedGizmoLight.intensity = 2;\n this._sharedGizmoLight.groundColor = Color3.Gray();\n }\n return this._sharedGizmoLight;\n }\n /**\n * A shared utility layer that can be used to overlay objects into a scene (Depth map of the previous scene is cleared before drawing on top of it)\n */\n static get DefaultUtilityLayer() {\n if (UtilityLayerRenderer._DefaultUtilityLayer == null) {\n return UtilityLayerRenderer._CreateDefaultUtilityLayerFromScene(EngineStore.LastCreatedScene);\n }\n return UtilityLayerRenderer._DefaultUtilityLayer;\n }\n /**\n * Creates an utility layer, and set it as a default utility layer\n * @param scene associated scene\n * @internal\n */\n static _CreateDefaultUtilityLayerFromScene(scene) {\n UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(scene);\n UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\n UtilityLayerRenderer._DefaultUtilityLayer = null;\n });\n return UtilityLayerRenderer._DefaultUtilityLayer;\n }\n /**\n * A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)\n */\n static get DefaultKeepDepthUtilityLayer() {\n if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(EngineStore.LastCreatedScene);\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;\n });\n }\n return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;\n }\n /**\n * Instantiates a UtilityLayerRenderer\n * @param originalScene the original scene that will be rendered on top of\n * @param handleEvents boolean indicating if the utility layer should handle events\n */\n constructor(\n /** the original scene that will be rendered on top of */\n originalScene, handleEvents = true) {\n this.originalScene = originalScene;\n this._pointerCaptures = {};\n this._lastPointerEvents = {};\n this._sharedGizmoLight = null;\n this._renderCamera = null;\n /**\n * If the picking should be done on the utility layer prior to the actual scene (Default: true)\n */\n this.pickUtilitySceneFirst = true;\n /**\n * If the utility layer should automatically be rendered on top of existing scene\n */\n this.shouldRender = true;\n /**\n * If set to true, only pointer down onPointerObservable events will be blocked when picking is occluded by original scene\n */\n this.onlyCheckPointerDownEvents = true;\n /**\n * If set to false, only pointerUp, pointerDown and pointerMove will be sent to the utilityLayerScene (false by default)\n */\n this.processAllEvents = false;\n /**\n * Set to false to disable picking\n */\n this.pickingEnabled = true;\n /**\n * Observable raised when the pointer moves from the utility layer scene to the main scene\n */\n this.onPointerOutObservable = new Observable$1();\n // Create scene which will be rendered in the foreground and remove it from being referenced by engine to avoid interfering with existing app\n this.utilityLayerScene = new Scene(originalScene.getEngine(), { virtual: true });\n this.utilityLayerScene.useRightHandedSystem = originalScene.useRightHandedSystem;\n this.utilityLayerScene._allowPostProcessClearColor = false;\n // Deactivate post processes\n this.utilityLayerScene.postProcessesEnabled = false;\n // Detach controls on utility scene, events will be fired by logic below to handle picking priority\n this.utilityLayerScene.detachControl();\n if (handleEvents) {\n this._originalPointerObserver = originalScene.onPrePointerObservable.add((prePointerInfo) => {\n if (!this.utilityLayerScene.activeCamera) {\n return;\n }\n if (!this.pickingEnabled) {\n return;\n }\n if (!this.processAllEvents) {\n if (prePointerInfo.type !== PointerEventTypes.POINTERMOVE &&\n prePointerInfo.type !== PointerEventTypes.POINTERUP &&\n prePointerInfo.type !== PointerEventTypes.POINTERDOWN &&\n prePointerInfo.type !== PointerEventTypes.POINTERDOUBLETAP) {\n return;\n }\n }\n this.utilityLayerScene.pointerX = originalScene.pointerX;\n this.utilityLayerScene.pointerY = originalScene.pointerY;\n const pointerEvent = prePointerInfo.event;\n if (originalScene.isPointerCaptured(pointerEvent.pointerId)) {\n this._pointerCaptures[pointerEvent.pointerId] = false;\n return;\n }\n const getNearPickDataForScene = (scene) => {\n let scenePick = null;\n if (prePointerInfo.nearInteractionPickingInfo) {\n if (prePointerInfo.nearInteractionPickingInfo.pickedMesh.getScene() == scene) {\n scenePick = prePointerInfo.nearInteractionPickingInfo;\n }\n else {\n scenePick = new PickingInfo();\n }\n }\n else if (scene !== this.utilityLayerScene && prePointerInfo.originalPickingInfo) {\n scenePick = prePointerInfo.originalPickingInfo;\n }\n else {\n let previousActiveCamera = null;\n // If a camera is set for rendering with this layer\n // it will also be used for the ray computation\n // To preserve back compat and because scene.pick always use activeCamera\n // it's substituted temporarily and a new scenePick is forced.\n // otherwise, the ray with previously active camera is always used.\n // It's set back to previous activeCamera after operation.\n if (this._renderCamera) {\n previousActiveCamera = scene._activeCamera;\n scene._activeCamera = this._renderCamera;\n prePointerInfo.ray = null;\n }\n scenePick = prePointerInfo.ray ? scene.pickWithRay(prePointerInfo.ray) : scene.pick(originalScene.pointerX, originalScene.pointerY);\n if (previousActiveCamera) {\n scene._activeCamera = previousActiveCamera;\n }\n }\n return scenePick;\n };\n const utilityScenePick = getNearPickDataForScene(this.utilityLayerScene);\n if (!prePointerInfo.ray && utilityScenePick) {\n prePointerInfo.ray = utilityScenePick.ray;\n }\n // always fire the prepointer observable\n this.utilityLayerScene.onPrePointerObservable.notifyObservers(prePointerInfo);\n // allow every non pointer down event to flow to the utility layer\n if (this.onlyCheckPointerDownEvents && prePointerInfo.type != PointerEventTypes.POINTERDOWN) {\n if (!prePointerInfo.skipOnPointerObservable) {\n this.utilityLayerScene.onPointerObservable.notifyObservers(new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick), prePointerInfo.type);\n }\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\n this._pointerCaptures[pointerEvent.pointerId] = false;\n }\n return;\n }\n if (this.utilityLayerScene.autoClearDepthAndStencil || this.pickUtilitySceneFirst) {\n // If this layer is an overlay, check if this layer was hit and if so, skip pointer events for the main scene\n if (utilityScenePick && utilityScenePick.hit) {\n if (!prePointerInfo.skipOnPointerObservable) {\n this.utilityLayerScene.onPointerObservable.notifyObservers(new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick), prePointerInfo.type);\n }\n prePointerInfo.skipOnPointerObservable = true;\n }\n }\n else {\n const originalScenePick = getNearPickDataForScene(originalScene);\n const pointerEvent = prePointerInfo.event;\n // If the layer can be occluded by the original scene, only fire pointer events to the first layer that hit they ray\n if (originalScenePick && utilityScenePick) {\n // No pick in utility scene\n if (utilityScenePick.distance === 0 && originalScenePick.pickedMesh) {\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\n // We touched an utility mesh present in the main scene\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\n prePointerInfo.skipOnPointerObservable = true;\n }\n else if (prePointerInfo.type === PointerEventTypes.POINTERDOWN) {\n this._pointerCaptures[pointerEvent.pointerId] = true;\n }\n else if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\n delete this._lastPointerEvents[pointerEvent.pointerId];\n }\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\n }\n }\n else if (!this._pointerCaptures[pointerEvent.pointerId] && (utilityScenePick.distance < originalScenePick.distance || originalScenePick.distance === 0)) {\n // We pick something in utility scene or the pick in utility is closer than the one in main scene\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\n // If a previous utility layer set this, do not unset this\n if (!prePointerInfo.skipOnPointerObservable) {\n prePointerInfo.skipOnPointerObservable = utilityScenePick.distance > 0;\n }\n }\n else if (!this._pointerCaptures[pointerEvent.pointerId] && utilityScenePick.distance >= originalScenePick.distance) {\n // We have a pick in both scenes but main is closer than utility\n // We touched an utility mesh present in the main scene\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\n prePointerInfo.skipOnPointerObservable = true;\n }\n else {\n if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\n delete this._lastPointerEvents[pointerEvent.pointerId];\n }\n }\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\n }\n }\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\n this._pointerCaptures[pointerEvent.pointerId] = false;\n }\n }\n }\n });\n // As a newly added utility layer will be rendered over the screen last, it's pointer events should be processed first\n if (this._originalPointerObserver) {\n originalScene.onPrePointerObservable.makeObserverTopPriority(this._originalPointerObserver);\n }\n }\n // Render directly on top of existing scene without clearing\n this.utilityLayerScene.autoClear = false;\n this._afterRenderObserver = this.originalScene.onAfterRenderCameraObservable.add((camera) => {\n // Only render when the render camera finishes rendering\n if (this.shouldRender && camera == this.getRenderCamera()) {\n this.render();\n }\n });\n this._sceneDisposeObserver = this.originalScene.onDisposeObservable.add(() => {\n this.dispose();\n });\n this._updateCamera();\n }\n _notifyObservers(prePointerInfo, pickInfo, pointerEvent) {\n if (!prePointerInfo.skipOnPointerObservable) {\n this.utilityLayerScene.onPointerObservable.notifyObservers(new PointerInfo(prePointerInfo.type, prePointerInfo.event, pickInfo), prePointerInfo.type);\n this._lastPointerEvents[pointerEvent.pointerId] = true;\n }\n }\n /**\n * Renders the utility layers scene on top of the original scene\n */\n render() {\n this._updateCamera();\n if (this.utilityLayerScene.activeCamera) {\n // Set the camera's scene to utility layers scene\n const oldScene = this.utilityLayerScene.activeCamera.getScene();\n const camera = this.utilityLayerScene.activeCamera;\n camera._scene = this.utilityLayerScene;\n if (camera.leftCamera) {\n camera.leftCamera._scene = this.utilityLayerScene;\n }\n if (camera.rightCamera) {\n camera.rightCamera._scene = this.utilityLayerScene;\n }\n this.utilityLayerScene.render(false);\n // Reset camera's scene back to original\n camera._scene = oldScene;\n if (camera.leftCamera) {\n camera.leftCamera._scene = oldScene;\n }\n if (camera.rightCamera) {\n camera.rightCamera._scene = oldScene;\n }\n }\n }\n /**\n * Disposes of the renderer\n */\n dispose() {\n this.onPointerOutObservable.clear();\n if (this._afterRenderObserver) {\n this.originalScene.onAfterCameraRenderObservable.remove(this._afterRenderObserver);\n }\n if (this._sceneDisposeObserver) {\n this.originalScene.onDisposeObservable.remove(this._sceneDisposeObserver);\n }\n if (this._originalPointerObserver) {\n this.originalScene.onPrePointerObservable.remove(this._originalPointerObserver);\n }\n this.utilityLayerScene.dispose();\n }\n _updateCamera() {\n this.utilityLayerScene.cameraToUseForPointers = this.getRenderCamera();\n this.utilityLayerScene.activeCamera = this.getRenderCamera();\n }\n }\n /** @internal */\n UtilityLayerRenderer._DefaultUtilityLayer = null;\n /** @internal */\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;\n\n /**\n * A module that will enable pointer selection for motion controllers of XR Input Sources\n */\n class WebXRControllerPointerSelection extends WebXRAbstractFeature {\n /**\n * constructs a new background remover module\n * @param _xrSessionManager the session manager for this module\n * @param _options read-only options to be used in this module\n */\n constructor(_xrSessionManager, _options) {\n super(_xrSessionManager);\n this._options = _options;\n this._attachController = (xrController) => {\n if (this._controllers[xrController.uniqueId]) {\n // already attached\n return;\n }\n const { laserPointer, selectionMesh } = this._generateNewMeshPair(xrController.pointer);\n // get two new meshes\n this._controllers[xrController.uniqueId] = {\n xrController,\n laserPointer,\n selectionMesh,\n meshUnderPointer: null,\n pick: null,\n tmpRay: new Ray(new Vector3(), new Vector3()),\n disabledByNearInteraction: false,\n id: WebXRControllerPointerSelection._IdCounter++,\n };\n if (this._attachedController) {\n if (!this._options.enablePointerSelectionOnAllControllers &&\n this._options.preferredHandedness &&\n xrController.inputSource.handedness === this._options.preferredHandedness) {\n this._attachedController = xrController.uniqueId;\n }\n }\n else {\n if (!this._options.enablePointerSelectionOnAllControllers) {\n this._attachedController = xrController.uniqueId;\n }\n }\n switch (xrController.inputSource.targetRayMode) {\n case \"tracked-pointer\":\n return this._attachTrackedPointerRayMode(xrController);\n case \"gaze\":\n return this._attachGazeMode(xrController);\n case \"screen\":\n return this._attachScreenRayMode(xrController);\n }\n };\n this._controllers = {};\n this._tmpVectorForPickCompare = new Vector3();\n /**\n * Disable lighting on the laser pointer (so it will always be visible)\n */\n this.disablePointerLighting = true;\n /**\n * Disable lighting on the selection mesh (so it will always be visible)\n */\n this.disableSelectionMeshLighting = true;\n /**\n * Should the laser pointer be displayed\n */\n this.displayLaserPointer = true;\n /**\n * Should the selection mesh be displayed (The ring at the end of the laser pointer)\n */\n this.displaySelectionMesh = true;\n /**\n * This color will be set to the laser pointer when selection is triggered\n */\n this.laserPointerPickedColor = new Color3(0.9, 0.9, 0.9);\n /**\n * Default color of the laser pointer\n */\n this.laserPointerDefaultColor = new Color3(0.7, 0.7, 0.7);\n /**\n * default color of the selection ring\n */\n this.selectionMeshDefaultColor = new Color3(0.8, 0.8, 0.8);\n /**\n * This color will be applied to the selection ring when selection is triggered\n */\n this.selectionMeshPickedColor = new Color3(0.3, 0.3, 1.0);\n this._identityMatrix = Matrix.Identity();\n this._screenCoordinatesRef = Vector3.Zero();\n this._viewportRef = new Viewport(0, 0, 0, 0);\n this._scene = this._xrSessionManager.scene;\n }\n /**\n * attach this feature\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n attach() {\n if (!super.attach()) {\n return false;\n }\n this._options.xrInput.controllers.forEach(this._attachController);\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\n // REMOVE the controller\n this._detachController(controller.uniqueId);\n });\n this._scene.constantlyUpdateMeshUnderPointer = true;\n if (this._options.gazeCamera) {\n const webXRCamera = this._options.gazeCamera;\n const { laserPointer, selectionMesh } = this._generateNewMeshPair(webXRCamera);\n this._controllers[\"camera\"] = {\n webXRCamera,\n laserPointer,\n selectionMesh,\n meshUnderPointer: null,\n pick: null,\n tmpRay: new Ray(new Vector3(), new Vector3()),\n disabledByNearInteraction: false,\n id: WebXRControllerPointerSelection._IdCounter++,\n };\n this._attachGazeMode();\n }\n return true;\n }\n /**\n * detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n Object.keys(this._controllers).forEach((controllerId) => {\n this._detachController(controllerId);\n });\n return true;\n }\n /**\n * Will get the mesh under a specific pointer.\n * `scene.meshUnderPointer` will only return one mesh - either left or right.\n * @param controllerId the controllerId to check\n * @returns The mesh under pointer or null if no mesh is under the pointer\n */\n getMeshUnderPointer(controllerId) {\n if (this._controllers[controllerId]) {\n return this._controllers[controllerId].meshUnderPointer;\n }\n else {\n return null;\n }\n }\n /**\n * Get the xr controller that correlates to the pointer id in the pointer event\n *\n * @param id the pointer id to search for\n * @returns the controller that correlates to this id or null if not found\n */\n getXRControllerByPointerId(id) {\n const keys = Object.keys(this._controllers);\n for (let i = 0; i < keys.length; ++i) {\n if (this._controllers[keys[i]].id === id) {\n return this._controllers[keys[i]].xrController || null;\n }\n }\n return null;\n }\n /**\n * @internal\n */\n _getPointerSelectionDisabledByPointerId(id) {\n const keys = Object.keys(this._controllers);\n for (let i = 0; i < keys.length; ++i) {\n if (this._controllers[keys[i]].id === id) {\n return this._controllers[keys[i]].disabledByNearInteraction;\n }\n }\n return true;\n }\n /**\n * @internal\n */\n _setPointerSelectionDisabledByPointerId(id, state) {\n const keys = Object.keys(this._controllers);\n for (let i = 0; i < keys.length; ++i) {\n if (this._controllers[keys[i]].id === id) {\n this._controllers[keys[i]].disabledByNearInteraction = state;\n return;\n }\n }\n }\n _onXRFrame(_xrFrame) {\n Object.keys(this._controllers).forEach((id) => {\n // only do this for the selected pointer\n const controllerData = this._controllers[id];\n if ((!this._options.enablePointerSelectionOnAllControllers && id !== this._attachedController) || controllerData.disabledByNearInteraction) {\n controllerData.selectionMesh.isVisible = false;\n controllerData.laserPointer.isVisible = false;\n controllerData.pick = null;\n return;\n }\n controllerData.laserPointer.isVisible = this.displayLaserPointer;\n let controllerGlobalPosition;\n // Every frame check collisions/input\n if (controllerData.xrController) {\n controllerGlobalPosition = controllerData.xrController.pointer.position;\n controllerData.xrController.getWorldPointerRayToRef(controllerData.tmpRay);\n }\n else if (controllerData.webXRCamera) {\n controllerGlobalPosition = controllerData.webXRCamera.position;\n controllerData.webXRCamera.getForwardRayToRef(controllerData.tmpRay);\n }\n else {\n return;\n }\n if (this._options.maxPointerDistance) {\n controllerData.tmpRay.length = this._options.maxPointerDistance;\n }\n // update pointerX and pointerY of the scene. Only if the flag is set to true!\n if (!this._options.disableScenePointerVectorUpdate && controllerGlobalPosition) {\n const scene = this._xrSessionManager.scene;\n const camera = this._options.xrInput.xrCamera;\n if (camera) {\n camera.viewport.toGlobalToRef(scene.getEngine().getRenderWidth(), scene.getEngine().getRenderHeight(), this._viewportRef);\n Vector3.ProjectToRef(controllerGlobalPosition, this._identityMatrix, scene.getTransformMatrix(), this._viewportRef, this._screenCoordinatesRef);\n // stay safe\n if (typeof this._screenCoordinatesRef.x === \"number\" &&\n typeof this._screenCoordinatesRef.y === \"number\" &&\n !isNaN(this._screenCoordinatesRef.x) &&\n !isNaN(this._screenCoordinatesRef.y)) {\n scene.pointerX = this._screenCoordinatesRef.x;\n scene.pointerY = this._screenCoordinatesRef.y;\n controllerData.screenCoordinates = {\n x: this._screenCoordinatesRef.x,\n y: this._screenCoordinatesRef.y,\n };\n }\n }\n }\n let utilityScenePick = null;\n if (this._utilityLayerScene) {\n utilityScenePick = this._utilityLayerScene.pickWithRay(controllerData.tmpRay, this._utilityLayerScene.pointerMovePredicate || this.raySelectionPredicate);\n }\n const originalScenePick = this._scene.pickWithRay(controllerData.tmpRay, this._scene.pointerMovePredicate || this.raySelectionPredicate);\n if (!utilityScenePick || !utilityScenePick.hit) {\n // No hit in utility scene\n controllerData.pick = originalScenePick;\n }\n else if (!originalScenePick || !originalScenePick.hit) {\n // No hit in original scene\n controllerData.pick = utilityScenePick;\n }\n else if (utilityScenePick.distance < originalScenePick.distance) {\n // Hit is closer in utility scene\n controllerData.pick = utilityScenePick;\n }\n else {\n // Hit is closer in original scene\n controllerData.pick = originalScenePick;\n }\n if (controllerData.pick && controllerData.xrController) {\n controllerData.pick.aimTransform = controllerData.xrController.pointer;\n controllerData.pick.gripTransform = controllerData.xrController.grip || null;\n }\n const pick = controllerData.pick;\n if (pick && pick.pickedPoint && pick.hit) {\n // Update laser state\n this._updatePointerDistance(controllerData.laserPointer, pick.distance);\n // Update cursor state\n controllerData.selectionMesh.position.copyFrom(pick.pickedPoint);\n controllerData.selectionMesh.scaling.x = Math.sqrt(pick.distance);\n controllerData.selectionMesh.scaling.y = Math.sqrt(pick.distance);\n controllerData.selectionMesh.scaling.z = Math.sqrt(pick.distance);\n // To avoid z-fighting\n const pickNormal = this._convertNormalToDirectionOfRay(pick.getNormal(true), controllerData.tmpRay);\n const deltaFighting = 0.001;\n controllerData.selectionMesh.position.copyFrom(pick.pickedPoint);\n if (pickNormal) {\n const axis1 = Vector3.Cross(Axis.Y, pickNormal);\n const axis2 = Vector3.Cross(pickNormal, axis1);\n Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, controllerData.selectionMesh.rotation);\n controllerData.selectionMesh.position.addInPlace(pickNormal.scale(deltaFighting));\n }\n controllerData.selectionMesh.isVisible = this.displaySelectionMesh;\n controllerData.meshUnderPointer = pick.pickedMesh;\n }\n else {\n controllerData.selectionMesh.isVisible = false;\n this._updatePointerDistance(controllerData.laserPointer, 1);\n controllerData.meshUnderPointer = null;\n }\n });\n }\n get _utilityLayerScene() {\n return this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;\n }\n _attachGazeMode(xrController) {\n const controllerData = this._controllers[(xrController && xrController.uniqueId) || \"camera\"];\n // attached when touched, detaches when raised\n const timeToSelect = this._options.timeToSelect || 3000;\n const sceneToRenderTo = this._options.useUtilityLayer ? this._utilityLayerScene : this._scene;\n let oldPick = new PickingInfo();\n const discMesh = CreateTorus(\"selection\", {\n diameter: 0.0035 * 15,\n thickness: 0.0025 * 6,\n tessellation: 20,\n }, sceneToRenderTo);\n discMesh.isVisible = false;\n discMesh.isPickable = false;\n discMesh.parent = controllerData.selectionMesh;\n let timer = 0;\n let downTriggered = false;\n const pointerEventInit = {\n pointerId: controllerData.id,\n pointerType: \"xr\",\n };\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\n if (!controllerData.pick) {\n return;\n }\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n controllerData.laserPointer.material.alpha = 0;\n discMesh.isVisible = false;\n if (controllerData.pick.hit) {\n if (!this._pickingMoved(oldPick, controllerData.pick)) {\n if (timer > timeToSelect / 10) {\n discMesh.isVisible = true;\n }\n timer += this._scene.getEngine().getDeltaTime();\n if (timer >= timeToSelect) {\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n // this pointerdown event is not setting the controllerData.pointerDownTriggered to avoid a pointerUp event when this feature is detached\n downTriggered = true;\n // pointer up right after down, if disable on touch out\n if (this._options.disablePointerUpOnTouchOut) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n }\n discMesh.isVisible = false;\n }\n else {\n const scaleFactor = 1 - timer / timeToSelect;\n discMesh.scaling.set(scaleFactor, scaleFactor, scaleFactor);\n }\n }\n else {\n if (downTriggered) {\n if (!this._options.disablePointerUpOnTouchOut) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n }\n }\n downTriggered = false;\n timer = 0;\n }\n }\n else {\n downTriggered = false;\n timer = 0;\n }\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\n oldPick = controllerData.pick;\n });\n if (this._options.renderingGroupId !== undefined) {\n discMesh.renderingGroupId = this._options.renderingGroupId;\n }\n if (xrController) {\n xrController.onDisposeObservable.addOnce(() => {\n if (controllerData.pick && !this._options.disablePointerUpOnTouchOut && downTriggered) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n controllerData.finalPointerUpTriggered = true;\n }\n discMesh.dispose();\n });\n }\n }\n _attachScreenRayMode(xrController) {\n const controllerData = this._controllers[xrController.uniqueId];\n let downTriggered = false;\n const pointerEventInit = {\n pointerId: controllerData.id,\n pointerType: \"xr\",\n };\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n if (!controllerData.pick || (this._options.disablePointerUpOnTouchOut && downTriggered)) {\n return;\n }\n if (!downTriggered) {\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n controllerData.pointerDownTriggered = true;\n downTriggered = true;\n if (this._options.disablePointerUpOnTouchOut) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n }\n }\n else {\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\n }\n });\n xrController.onDisposeObservable.addOnce(() => {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n this._xrSessionManager.runInXRFrame(() => {\n if (controllerData.pick && !controllerData.finalPointerUpTriggered && downTriggered && !this._options.disablePointerUpOnTouchOut) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n controllerData.finalPointerUpTriggered = true;\n }\n });\n });\n }\n _attachTrackedPointerRayMode(xrController) {\n const controllerData = this._controllers[xrController.uniqueId];\n if (this._options.forceGazeMode) {\n return this._attachGazeMode(xrController);\n }\n const pointerEventInit = {\n pointerId: controllerData.id,\n pointerType: \"xr\",\n };\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\n controllerData.laserPointer.material.disableLighting = this.disablePointerLighting;\n controllerData.selectionMesh.material.disableLighting = this.disableSelectionMeshLighting;\n if (controllerData.pick) {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\n }\n });\n if (xrController.inputSource.gamepad) {\n const init = (motionController) => {\n if (this._options.overrideButtonId) {\n controllerData.selectionComponent = motionController.getComponent(this._options.overrideButtonId);\n }\n if (!controllerData.selectionComponent) {\n controllerData.selectionComponent = motionController.getMainComponent();\n }\n controllerData.onButtonChangedObserver = controllerData.selectionComponent.onButtonStateChangedObservable.add((component) => {\n if (component.changes.pressed) {\n const pressed = component.changes.pressed.current;\n if (controllerData.pick) {\n if (this._options.enablePointerSelectionOnAllControllers || xrController.uniqueId === this._attachedController) {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n if (pressed) {\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n controllerData.pointerDownTriggered = true;\n controllerData.selectionMesh.material.emissiveColor = this.selectionMeshPickedColor;\n controllerData.laserPointer.material.emissiveColor = this.laserPointerPickedColor;\n }\n else {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n controllerData.selectionMesh.material.emissiveColor = this.selectionMeshDefaultColor;\n controllerData.laserPointer.material.emissiveColor = this.laserPointerDefaultColor;\n }\n }\n }\n else {\n if (pressed && !this._options.enablePointerSelectionOnAllControllers && !this._options.disableSwitchOnClick) {\n this._attachedController = xrController.uniqueId;\n }\n }\n }\n });\n };\n if (xrController.motionController) {\n init(xrController.motionController);\n }\n else {\n xrController.onMotionControllerInitObservable.add(init);\n }\n }\n else {\n // use the select and squeeze events\n const selectStartListener = (event) => {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n if (controllerData.xrController && event.inputSource === controllerData.xrController.inputSource && controllerData.pick) {\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n controllerData.pointerDownTriggered = true;\n controllerData.selectionMesh.material.emissiveColor = this.selectionMeshPickedColor;\n controllerData.laserPointer.material.emissiveColor = this.laserPointerPickedColor;\n }\n };\n const selectEndListener = (event) => {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n if (controllerData.xrController && event.inputSource === controllerData.xrController.inputSource && controllerData.pick) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n controllerData.selectionMesh.material.emissiveColor = this.selectionMeshDefaultColor;\n controllerData.laserPointer.material.emissiveColor = this.laserPointerDefaultColor;\n }\n };\n controllerData.eventListeners = {\n selectend: selectEndListener,\n selectstart: selectStartListener,\n };\n this._xrSessionManager.session.addEventListener(\"selectstart\", selectStartListener);\n this._xrSessionManager.session.addEventListener(\"selectend\", selectEndListener);\n }\n }\n _convertNormalToDirectionOfRay(normal, ray) {\n if (normal) {\n const angle = Math.acos(Vector3.Dot(normal, ray.direction));\n if (angle < Math.PI / 2) {\n normal.scaleInPlace(-1);\n }\n }\n return normal;\n }\n _detachController(xrControllerUniqueId) {\n const controllerData = this._controllers[xrControllerUniqueId];\n if (!controllerData) {\n return;\n }\n if (controllerData.selectionComponent) {\n if (controllerData.onButtonChangedObserver) {\n controllerData.selectionComponent.onButtonStateChangedObservable.remove(controllerData.onButtonChangedObserver);\n }\n }\n if (controllerData.onFrameObserver) {\n this._xrSessionManager.onXRFrameObservable.remove(controllerData.onFrameObserver);\n }\n if (controllerData.eventListeners) {\n Object.keys(controllerData.eventListeners).forEach((eventName) => {\n const func = controllerData.eventListeners && controllerData.eventListeners[eventName];\n if (func) {\n // For future reference - this is an issue in the WebXR typings.\n this._xrSessionManager.session.removeEventListener(eventName, func);\n }\n });\n }\n if (!controllerData.finalPointerUpTriggered && controllerData.pointerDownTriggered) {\n // Stay safe and fire a pointerup, in case it wasn't already triggered\n const pointerEventInit = {\n pointerId: controllerData.id,\n pointerType: \"xr\",\n };\n this._xrSessionManager.runInXRFrame(() => {\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\n this._scene.simulatePointerUp(controllerData.pick || new PickingInfo(), pointerEventInit);\n controllerData.finalPointerUpTriggered = true;\n });\n }\n this._xrSessionManager.scene.onBeforeRenderObservable.addOnce(() => {\n try {\n controllerData.selectionMesh.dispose();\n controllerData.laserPointer.dispose();\n // remove from the map\n delete this._controllers[xrControllerUniqueId];\n if (this._attachedController === xrControllerUniqueId) {\n // check for other controllers\n const keys = Object.keys(this._controllers);\n if (keys.length) {\n this._attachedController = keys[0];\n }\n else {\n this._attachedController = \"\";\n }\n }\n }\n catch (e) {\n Tools.Warn(\"controller already detached.\");\n }\n });\n }\n _generateNewMeshPair(meshParent) {\n const sceneToRenderTo = this._options.useUtilityLayer ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene : this._scene;\n const laserPointer = this._options.customLasterPointerMeshGenerator\n ? this._options.customLasterPointerMeshGenerator()\n : CreateCylinder(\"laserPointer\", {\n height: 1,\n diameterTop: 0.0002,\n diameterBottom: 0.004,\n tessellation: 20,\n subdivisions: 1,\n }, sceneToRenderTo);\n laserPointer.parent = meshParent;\n const laserPointerMaterial = new StandardMaterial(\"laserPointerMat\", sceneToRenderTo);\n laserPointerMaterial.emissiveColor = this.laserPointerDefaultColor;\n laserPointerMaterial.alpha = 0.7;\n laserPointer.material = laserPointerMaterial;\n laserPointer.rotation.x = Math.PI / 2;\n this._updatePointerDistance(laserPointer, 1);\n laserPointer.isPickable = false;\n laserPointer.isVisible = false;\n // Create a gaze tracker for the XR controller\n const selectionMesh = this._options.customSelectionMeshGenerator\n ? this._options.customSelectionMeshGenerator()\n : CreateTorus(\"gazeTracker\", {\n diameter: 0.0035 * 3,\n thickness: 0.0025 * 3,\n tessellation: 20,\n }, sceneToRenderTo);\n selectionMesh.bakeCurrentTransformIntoVertices();\n selectionMesh.isPickable = false;\n selectionMesh.isVisible = false;\n const targetMat = new StandardMaterial(\"targetMat\", sceneToRenderTo);\n targetMat.specularColor = Color3.Black();\n targetMat.emissiveColor = this.selectionMeshDefaultColor;\n targetMat.backFaceCulling = false;\n selectionMesh.material = targetMat;\n if (this._options.renderingGroupId !== undefined) {\n laserPointer.renderingGroupId = this._options.renderingGroupId;\n selectionMesh.renderingGroupId = this._options.renderingGroupId;\n }\n return {\n laserPointer,\n selectionMesh,\n };\n }\n _pickingMoved(oldPick, newPick) {\n var _a;\n if (!oldPick.hit || !newPick.hit) {\n return true;\n }\n if (!oldPick.pickedMesh || !oldPick.pickedPoint || !newPick.pickedMesh || !newPick.pickedPoint) {\n return true;\n }\n if (oldPick.pickedMesh !== newPick.pickedMesh) {\n return true;\n }\n (_a = oldPick.pickedPoint) === null || _a === void 0 ? void 0 : _a.subtractToRef(newPick.pickedPoint, this._tmpVectorForPickCompare);\n this._tmpVectorForPickCompare.set(Math.abs(this._tmpVectorForPickCompare.x), Math.abs(this._tmpVectorForPickCompare.y), Math.abs(this._tmpVectorForPickCompare.z));\n const delta = (this._options.gazeModePointerMovedFactor || 1) * 0.01 * newPick.distance;\n const length = this._tmpVectorForPickCompare.length();\n if (length > delta) {\n return true;\n }\n return false;\n }\n _updatePointerDistance(_laserPointer, distance = 100) {\n _laserPointer.scaling.y = distance;\n // a bit of distance from the controller\n if (this._scene.useRightHandedSystem) {\n distance *= -1;\n }\n _laserPointer.position.z = distance / 2 + 0.05;\n }\n _augmentPointerInit(pointerEventInit, id, screenCoordinates) {\n pointerEventInit.pointerId = id;\n pointerEventInit.pointerType = \"xr\";\n if (screenCoordinates) {\n pointerEventInit.screenX = screenCoordinates.x;\n pointerEventInit.screenY = screenCoordinates.y;\n }\n }\n /** @internal */\n get lasterPointerDefaultColor() {\n // here due to a typo\n return this.laserPointerDefaultColor;\n }\n }\n WebXRControllerPointerSelection._IdCounter = 200;\n /**\n * The module's name\n */\n WebXRControllerPointerSelection.Name = WebXRFeatureName.POINTER_SELECTION;\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\n WebXRControllerPointerSelection.Version = 1;\n //register the plugin\n WebXRFeaturesManager.AddWebXRFeature(WebXRControllerPointerSelection.Name, (xrSessionManager, options) => {\n return () => new WebXRControllerPointerSelection(xrSessionManager, options);\n }, WebXRControllerPointerSelection.Version, true);\n\n /**\n * Defines the kind of connection point for node based material\n */\n var NodeMaterialBlockConnectionPointTypes;\n (function (NodeMaterialBlockConnectionPointTypes) {\n /** Float */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Float\"] = 1] = \"Float\";\n /** Int */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Int\"] = 2] = \"Int\";\n /** Vector2 */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Vector2\"] = 4] = \"Vector2\";\n /** Vector3 */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Vector3\"] = 8] = \"Vector3\";\n /** Vector4 */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Vector4\"] = 16] = \"Vector4\";\n /** Color3 */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Color3\"] = 32] = \"Color3\";\n /** Color4 */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Color4\"] = 64] = \"Color4\";\n /** Matrix */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Matrix\"] = 128] = \"Matrix\";\n /** Custom object */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"Object\"] = 256] = \"Object\";\n /** Detect type based on connection */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"AutoDetect\"] = 1024] = \"AutoDetect\";\n /** Output type that will be defined by input type */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"BasedOnInput\"] = 2048] = \"BasedOnInput\";\n /** Bitmask of all types */\n NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes[\"All\"] = 4095] = \"All\";\n })(NodeMaterialBlockConnectionPointTypes || (NodeMaterialBlockConnectionPointTypes = {}));\n\n /**\n * Enum used to define the target of a block\n */\n var NodeMaterialBlockTargets;\n (function (NodeMaterialBlockTargets) {\n /** Vertex shader */\n NodeMaterialBlockTargets[NodeMaterialBlockTargets[\"Vertex\"] = 1] = \"Vertex\";\n /** Fragment shader */\n NodeMaterialBlockTargets[NodeMaterialBlockTargets[\"Fragment\"] = 2] = \"Fragment\";\n /** Neutral */\n NodeMaterialBlockTargets[NodeMaterialBlockTargets[\"Neutral\"] = 4] = \"Neutral\";\n /** Vertex and Fragment */\n NodeMaterialBlockTargets[NodeMaterialBlockTargets[\"VertexAndFragment\"] = 3] = \"VertexAndFragment\";\n })(NodeMaterialBlockTargets || (NodeMaterialBlockTargets = {}));\n\n /**\n * Class used to store node based material build state\n */\n class NodeMaterialBuildState {\n constructor() {\n /** Gets or sets a boolean indicating if the current state can emit uniform buffers */\n this.supportUniformBuffers = false;\n /**\n * Gets the list of emitted attributes\n */\n this.attributes = new Array();\n /**\n * Gets the list of emitted uniforms\n */\n this.uniforms = new Array();\n /**\n * Gets the list of emitted constants\n */\n this.constants = new Array();\n /**\n * Gets the list of emitted samplers\n */\n this.samplers = new Array();\n /**\n * Gets the list of emitted functions\n */\n this.functions = {};\n /**\n * Gets the list of emitted extensions\n */\n this.extensions = {};\n /**\n * Gets the list of emitted counters\n */\n this.counters = {};\n /** @internal */\n this._attributeDeclaration = \"\";\n /** @internal */\n this._uniformDeclaration = \"\";\n /** @internal */\n this._constantDeclaration = \"\";\n /** @internal */\n this._samplerDeclaration = \"\";\n /** @internal */\n this._varyingTransfer = \"\";\n /** @internal */\n this._injectAtEnd = \"\";\n this._repeatableContentAnchorIndex = 0;\n /** @internal */\n this._builtCompilationString = \"\";\n /**\n * Gets the emitted compilation strings\n */\n this.compilationString = \"\";\n }\n /**\n * Finalize the compilation strings\n * @param state defines the current compilation state\n */\n finalize(state) {\n const emitComments = state.sharedData.emitComments;\n const isFragmentMode = this.target === NodeMaterialBlockTargets.Fragment;\n this.compilationString = `\\n${emitComments ? \"//Entry point\\n\" : \"\"}void main(void) {\\n${this.compilationString}`;\n if (this._constantDeclaration) {\n this.compilationString = `\\n${emitComments ? \"//Constants\\n\" : \"\"}${this._constantDeclaration}\\n${this.compilationString}`;\n }\n let functionCode = \"\";\n for (const functionName in this.functions) {\n functionCode += this.functions[functionName] + `\\n`;\n }\n this.compilationString = `\\n${functionCode}\\n${this.compilationString}`;\n if (!isFragmentMode && this._varyingTransfer) {\n this.compilationString = `${this.compilationString}\\n${this._varyingTransfer}`;\n }\n if (this._injectAtEnd) {\n this.compilationString = `${this.compilationString}\\n${this._injectAtEnd}`;\n }\n this.compilationString = `${this.compilationString}\\n}`;\n if (this.sharedData.varyingDeclaration) {\n this.compilationString = `\\n${emitComments ? \"//Varyings\\n\" : \"\"}${this.sharedData.varyingDeclaration}\\n${this.compilationString}`;\n }\n if (this._samplerDeclaration) {\n this.compilationString = `\\n${emitComments ? \"//Samplers\\n\" : \"\"}${this._samplerDeclaration}\\n${this.compilationString}`;\n }\n if (this._uniformDeclaration) {\n this.compilationString = `\\n${emitComments ? \"//Uniforms\\n\" : \"\"}${this._uniformDeclaration}\\n${this.compilationString}`;\n }\n if (this._attributeDeclaration && !isFragmentMode) {\n this.compilationString = `\\n${emitComments ? \"//Attributes\\n\" : \"\"}${this._attributeDeclaration}\\n${this.compilationString}`;\n }\n this.compilationString = \"precision highp float;\\n\" + this.compilationString;\n this.compilationString = \"#if defined(WEBGL2) || defines(WEBGPU)\\nprecision highp sampler2DArray;\\n#endif\\n\" + this.compilationString;\n for (const extensionName in this.extensions) {\n const extension = this.extensions[extensionName];\n this.compilationString = `\\n${extension}\\n${this.compilationString}`;\n }\n this._builtCompilationString = this.compilationString;\n }\n /** @internal */\n get _repeatableContentAnchor() {\n return `###___ANCHOR${this._repeatableContentAnchorIndex++}___###`;\n }\n /**\n * @internal\n */\n _getFreeVariableName(prefix) {\n prefix = prefix.replace(/[^a-zA-Z_]+/g, \"\");\n if (this.sharedData.variableNames[prefix] === undefined) {\n this.sharedData.variableNames[prefix] = 0;\n // Check reserved words\n if (prefix === \"output\" || prefix === \"texture\") {\n return prefix + this.sharedData.variableNames[prefix];\n }\n return prefix;\n }\n else {\n this.sharedData.variableNames[prefix]++;\n }\n return prefix + this.sharedData.variableNames[prefix];\n }\n /**\n * @internal\n */\n _getFreeDefineName(prefix) {\n if (this.sharedData.defineNames[prefix] === undefined) {\n this.sharedData.defineNames[prefix] = 0;\n }\n else {\n this.sharedData.defineNames[prefix]++;\n }\n return prefix + this.sharedData.defineNames[prefix];\n }\n /**\n * @internal\n */\n _excludeVariableName(name) {\n this.sharedData.variableNames[name] = 0;\n }\n /**\n * @internal\n */\n _emit2DSampler(name) {\n if (this.samplers.indexOf(name) < 0) {\n this._samplerDeclaration += `uniform sampler2D ${name};\\n`;\n this.samplers.push(name);\n }\n }\n /**\n * @internal\n */\n _emit2DArraySampler(name) {\n if (this.samplers.indexOf(name) < 0) {\n this._samplerDeclaration += `uniform sampler2DArray ${name};\\n`;\n this.samplers.push(name);\n }\n }\n /**\n * @internal\n */\n _getGLType(type) {\n switch (type) {\n case NodeMaterialBlockConnectionPointTypes.Float:\n return \"float\";\n case NodeMaterialBlockConnectionPointTypes.Int:\n return \"int\";\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n return \"vec2\";\n case NodeMaterialBlockConnectionPointTypes.Color3:\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n return \"vec3\";\n case NodeMaterialBlockConnectionPointTypes.Color4:\n case NodeMaterialBlockConnectionPointTypes.Vector4:\n return \"vec4\";\n case NodeMaterialBlockConnectionPointTypes.Matrix:\n return \"mat4\";\n }\n return \"\";\n }\n /**\n * @internal\n */\n _emitExtension(name, extension, define = \"\") {\n if (this.extensions[name]) {\n return;\n }\n if (define) {\n extension = `#if ${define}\\n${extension}\\n#endif`;\n }\n this.extensions[name] = extension;\n }\n /**\n * @internal\n */\n _emitFunction(name, code, comments) {\n if (this.functions[name]) {\n return;\n }\n if (this.sharedData.emitComments) {\n code = comments + `\\n` + code;\n }\n this.functions[name] = code;\n }\n /**\n * @internal\n */\n _emitCodeFromInclude(includeName, comments, options) {\n if (options && options.repeatKey) {\n return `#include<${includeName}>${options.substitutionVars ? \"(\" + options.substitutionVars + \")\" : \"\"}[0..${options.repeatKey}]\\n`;\n }\n let code = Effect.IncludesShadersStore[includeName] + \"\\n\";\n if (this.sharedData.emitComments) {\n code = comments + `\\n` + code;\n }\n if (!options) {\n return code;\n }\n if (options.replaceStrings) {\n for (let index = 0; index < options.replaceStrings.length; index++) {\n const replaceString = options.replaceStrings[index];\n code = code.replace(replaceString.search, replaceString.replace);\n }\n }\n return code;\n }\n /**\n * @internal\n */\n _emitFunctionFromInclude(includeName, comments, options, storeKey = \"\") {\n const key = includeName + storeKey;\n if (this.functions[key]) {\n return;\n }\n if (!options || (!options.removeAttributes && !options.removeUniforms && !options.removeVaryings && !options.removeIfDef && !options.replaceStrings)) {\n if (options && options.repeatKey) {\n this.functions[key] = `#include<${includeName}>${options.substitutionVars ? \"(\" + options.substitutionVars + \")\" : \"\"}[0..${options.repeatKey}]\\n`;\n }\n else {\n this.functions[key] = `#include<${includeName}>${(options === null || options === void 0 ? void 0 : options.substitutionVars) ? \"(\" + (options === null || options === void 0 ? void 0 : options.substitutionVars) + \")\" : \"\"}\\n`;\n }\n if (this.sharedData.emitComments) {\n this.functions[key] = comments + `\\n` + this.functions[key];\n }\n return;\n }\n this.functions[key] = Effect.IncludesShadersStore[includeName];\n if (this.sharedData.emitComments) {\n this.functions[key] = comments + `\\n` + this.functions[key];\n }\n if (options.removeIfDef) {\n this.functions[key] = this.functions[key].replace(/^\\s*?#ifdef.+$/gm, \"\");\n this.functions[key] = this.functions[key].replace(/^\\s*?#endif.*$/gm, \"\");\n this.functions[key] = this.functions[key].replace(/^\\s*?#else.*$/gm, \"\");\n this.functions[key] = this.functions[key].replace(/^\\s*?#elif.*$/gm, \"\");\n }\n if (options.removeAttributes) {\n this.functions[key] = this.functions[key].replace(/\\s*?attribute .+?;/g, \"\\n\");\n }\n if (options.removeUniforms) {\n this.functions[key] = this.functions[key].replace(/\\s*?uniform .*?;/g, \"\\n\");\n }\n if (options.removeVaryings) {\n this.functions[key] = this.functions[key].replace(/\\s*?(varying|in) .+?;/g, \"\\n\");\n }\n if (options.replaceStrings) {\n for (let index = 0; index < options.replaceStrings.length; index++) {\n const replaceString = options.replaceStrings[index];\n this.functions[key] = this.functions[key].replace(replaceString.search, replaceString.replace);\n }\n }\n }\n /**\n * @internal\n */\n _registerTempVariable(name) {\n if (this.sharedData.temps.indexOf(name) !== -1) {\n return false;\n }\n this.sharedData.temps.push(name);\n return true;\n }\n /**\n * @internal\n */\n _emitVaryingFromString(name, type, define = \"\", notDefine = false) {\n if (this.sharedData.varyings.indexOf(name) !== -1) {\n return false;\n }\n this.sharedData.varyings.push(name);\n if (define) {\n if (define.startsWith(\"defined(\")) {\n this.sharedData.varyingDeclaration += `#if ${define}\\n`;\n }\n else {\n this.sharedData.varyingDeclaration += `${notDefine ? \"#ifndef\" : \"#ifdef\"} ${define}\\n`;\n }\n }\n this.sharedData.varyingDeclaration += `varying ${type} ${name};\\n`;\n if (define) {\n this.sharedData.varyingDeclaration += `#endif\\n`;\n }\n return true;\n }\n /**\n * @internal\n */\n _emitUniformFromString(name, type, define = \"\", notDefine = false) {\n if (this.uniforms.indexOf(name) !== -1) {\n return;\n }\n this.uniforms.push(name);\n if (define) {\n if (define.startsWith(\"defined(\")) {\n this._uniformDeclaration += `#if ${define}\\n`;\n }\n else {\n this._uniformDeclaration += `${notDefine ? \"#ifndef\" : \"#ifdef\"} ${define}\\n`;\n }\n }\n this._uniformDeclaration += `uniform ${type} ${name};\\n`;\n if (define) {\n this._uniformDeclaration += `#endif\\n`;\n }\n }\n /**\n * @internal\n */\n _emitFloat(value) {\n if (value.toString() === value.toFixed(0)) {\n return `${value}.0`;\n }\n return value.toString();\n }\n }\n\n /**\n * Class used to store shared data between 2 NodeMaterialBuildState\n */\n class NodeMaterialBuildStateSharedData {\n /** Creates a new shared data */\n constructor() {\n /**\n * Gets the list of emitted varyings\n */\n this.temps = new Array();\n /**\n * Gets the list of emitted varyings\n */\n this.varyings = new Array();\n /**\n * Gets the varying declaration string\n */\n this.varyingDeclaration = \"\";\n /**\n * Input blocks\n */\n this.inputBlocks = new Array();\n /**\n * Input blocks\n */\n this.textureBlocks = new Array();\n /**\n * Bindable blocks (Blocks that need to set data to the effect)\n */\n this.bindableBlocks = new Array();\n /**\n * Bindable blocks (Blocks that need to set data to the effect) that will always be called (by bindForSubMesh), contrary to bindableBlocks that won't be called if _mustRebind() returns false\n */\n this.forcedBindableBlocks = new Array();\n /**\n * List of blocks that can provide a compilation fallback\n */\n this.blocksWithFallbacks = new Array();\n /**\n * List of blocks that can provide a define update\n */\n this.blocksWithDefines = new Array();\n /**\n * List of blocks that can provide a repeatable content\n */\n this.repeatableContentBlocks = new Array();\n /**\n * List of blocks that can provide a dynamic list of uniforms\n */\n this.dynamicUniformBlocks = new Array();\n /**\n * List of blocks that can block the isReady function for the material\n */\n this.blockingBlocks = new Array();\n /**\n * Gets the list of animated inputs\n */\n this.animatedInputs = new Array();\n /** List of emitted variables */\n this.variableNames = {};\n /** List of emitted defines */\n this.defineNames = {};\n /**\n * Gets the compilation hints emitted at compilation time\n */\n this.hints = {\n needWorldViewMatrix: false,\n needWorldViewProjectionMatrix: false,\n needAlphaBlending: false,\n needAlphaTesting: false,\n };\n /**\n * List of compilation checks\n */\n this.checks = {\n emitVertex: false,\n emitFragment: false,\n notConnectedNonOptionalInputs: new Array(),\n };\n /**\n * Is vertex program allowed to be empty?\n */\n this.allowEmptyVertexProgram = false;\n // Exclude usual attributes from free variable names\n this.variableNames[\"position\"] = 0;\n this.variableNames[\"normal\"] = 0;\n this.variableNames[\"tangent\"] = 0;\n this.variableNames[\"uv\"] = 0;\n this.variableNames[\"uv2\"] = 0;\n this.variableNames[\"uv3\"] = 0;\n this.variableNames[\"uv4\"] = 0;\n this.variableNames[\"uv5\"] = 0;\n this.variableNames[\"uv6\"] = 0;\n this.variableNames[\"color\"] = 0;\n this.variableNames[\"matricesIndices\"] = 0;\n this.variableNames[\"matricesWeights\"] = 0;\n this.variableNames[\"matricesIndicesExtra\"] = 0;\n this.variableNames[\"matricesWeightsExtra\"] = 0;\n this.variableNames[\"diffuseBase\"] = 0;\n this.variableNames[\"specularBase\"] = 0;\n this.variableNames[\"worldPos\"] = 0;\n this.variableNames[\"shadow\"] = 0;\n this.variableNames[\"view\"] = 0;\n // Exclude known varyings\n this.variableNames[\"vTBN\"] = 0;\n // Exclude defines\n this.defineNames[\"MAINUV0\"] = 0;\n this.defineNames[\"MAINUV1\"] = 0;\n this.defineNames[\"MAINUV2\"] = 0;\n this.defineNames[\"MAINUV3\"] = 0;\n this.defineNames[\"MAINUV4\"] = 0;\n this.defineNames[\"MAINUV5\"] = 0;\n this.defineNames[\"MAINUV6\"] = 0;\n this.defineNames[\"MAINUV7\"] = 0;\n }\n /**\n * Emits console errors and exceptions if there is a failing check\n */\n emitErrors() {\n let errorMessage = \"\";\n if (!this.checks.emitVertex && !this.allowEmptyVertexProgram) {\n errorMessage += \"NodeMaterial does not have a vertex output. You need to at least add a block that generates a glPosition value.\\n\";\n }\n if (!this.checks.emitFragment) {\n errorMessage += \"NodeMaterial does not have a fragment output. You need to at least add a block that generates a glFragColor value.\\n\";\n }\n for (const notConnectedInput of this.checks.notConnectedNonOptionalInputs) {\n errorMessage += `input ${notConnectedInput.name} from block ${notConnectedInput.ownerBlock.name}[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.\\n`;\n }\n if (errorMessage) {\n throw \"Build of NodeMaterial failed:\\n\" + errorMessage;\n }\n }\n }\n\n /**\n * Enum used to define the compatibility state between two connection points\n */\n var NodeMaterialConnectionPointCompatibilityStates;\n (function (NodeMaterialConnectionPointCompatibilityStates) {\n /** Points are compatibles */\n NodeMaterialConnectionPointCompatibilityStates[NodeMaterialConnectionPointCompatibilityStates[\"Compatible\"] = 0] = \"Compatible\";\n /** Points are incompatible because of their types */\n NodeMaterialConnectionPointCompatibilityStates[NodeMaterialConnectionPointCompatibilityStates[\"TypeIncompatible\"] = 1] = \"TypeIncompatible\";\n /** Points are incompatible because of their targets (vertex vs fragment) */\n NodeMaterialConnectionPointCompatibilityStates[NodeMaterialConnectionPointCompatibilityStates[\"TargetIncompatible\"] = 2] = \"TargetIncompatible\";\n /** Points are incompatible because they are in the same hierarchy **/\n NodeMaterialConnectionPointCompatibilityStates[NodeMaterialConnectionPointCompatibilityStates[\"HierarchyIssue\"] = 3] = \"HierarchyIssue\";\n })(NodeMaterialConnectionPointCompatibilityStates || (NodeMaterialConnectionPointCompatibilityStates = {}));\n /**\n * Defines the direction of a connection point\n */\n var NodeMaterialConnectionPointDirection;\n (function (NodeMaterialConnectionPointDirection) {\n /** Input */\n NodeMaterialConnectionPointDirection[NodeMaterialConnectionPointDirection[\"Input\"] = 0] = \"Input\";\n /** Output */\n NodeMaterialConnectionPointDirection[NodeMaterialConnectionPointDirection[\"Output\"] = 1] = \"Output\";\n })(NodeMaterialConnectionPointDirection || (NodeMaterialConnectionPointDirection = {}));\n /**\n * Defines a connection point for a block\n */\n class NodeMaterialConnectionPoint {\n /**\n * Checks if two types are equivalent\n * @param type1 type 1 to check\n * @param type2 type 2 to check\n * @returns true if both types are equivalent, else false\n */\n static AreEquivalentTypes(type1, type2) {\n switch (type1) {\n case NodeMaterialBlockConnectionPointTypes.Vector3: {\n if (type2 === NodeMaterialBlockConnectionPointTypes.Color3) {\n return true;\n }\n break;\n }\n case NodeMaterialBlockConnectionPointTypes.Vector4: {\n if (type2 === NodeMaterialBlockConnectionPointTypes.Color4) {\n return true;\n }\n break;\n }\n case NodeMaterialBlockConnectionPointTypes.Color3: {\n if (type2 === NodeMaterialBlockConnectionPointTypes.Vector3) {\n return true;\n }\n break;\n }\n case NodeMaterialBlockConnectionPointTypes.Color4: {\n if (type2 === NodeMaterialBlockConnectionPointTypes.Vector4) {\n return true;\n }\n break;\n }\n }\n return false;\n }\n /** Gets the direction of the point */\n get direction() {\n return this._direction;\n }\n /**\n * Gets or sets the associated variable name in the shader\n */\n get associatedVariableName() {\n if (this._ownerBlock.isInput) {\n return this._ownerBlock.associatedVariableName;\n }\n if ((!this._enforceAssociatedVariableName || !this._associatedVariableName) && this._connectedPoint) {\n return this._connectedPoint.associatedVariableName;\n }\n return this._associatedVariableName;\n }\n set associatedVariableName(value) {\n this._associatedVariableName = value;\n }\n /** Get the inner type (ie AutoDetect for instance instead of the inferred one) */\n get innerType() {\n if (this._linkedConnectionSource && this._linkedConnectionSource.isConnected) {\n return this.type;\n }\n return this._type;\n }\n /**\n * Gets or sets the connection point type (default is float)\n */\n get type() {\n if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {\n if (this._ownerBlock.isInput) {\n return this._ownerBlock.type;\n }\n if (this._connectedPoint) {\n return this._connectedPoint.type;\n }\n if (this._linkedConnectionSource && this._linkedConnectionSource.isConnected) {\n return this._linkedConnectionSource.type;\n }\n }\n if (this._type === NodeMaterialBlockConnectionPointTypes.BasedOnInput) {\n if (this._typeConnectionSource) {\n if (!this._typeConnectionSource.isConnected && this._defaultConnectionPointType) {\n return this._defaultConnectionPointType;\n }\n return this._typeConnectionSource.type;\n }\n else if (this._defaultConnectionPointType) {\n return this._defaultConnectionPointType;\n }\n }\n return this._type;\n }\n set type(value) {\n this._type = value;\n }\n /** Gets or sets the target of that connection point */\n get target() {\n if (!this._prioritizeVertex || !this._ownerBlock) {\n return this._target;\n }\n if (this._target !== NodeMaterialBlockTargets.VertexAndFragment) {\n return this._target;\n }\n if (this._ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\n return NodeMaterialBlockTargets.Fragment;\n }\n return NodeMaterialBlockTargets.Vertex;\n }\n set target(value) {\n this._target = value;\n }\n /**\n * Gets a boolean indicating that the current point is connected to another NodeMaterialBlock\n */\n get isConnected() {\n return this.connectedPoint !== null || this.hasEndpoints;\n }\n /**\n * Gets a boolean indicating that the current point is connected to an input block\n */\n get isConnectedToInputBlock() {\n return this.connectedPoint !== null && this.connectedPoint.ownerBlock.isInput;\n }\n /**\n * Gets a the connected input block (if any)\n */\n get connectInputBlock() {\n if (!this.isConnectedToInputBlock) {\n return null;\n }\n return this.connectedPoint.ownerBlock;\n }\n /** Get the other side of the connection (if any) */\n get connectedPoint() {\n return this._connectedPoint;\n }\n /** Get the block that owns this connection point */\n get ownerBlock() {\n return this._ownerBlock;\n }\n /** Get the block connected on the other side of this connection (if any) */\n get sourceBlock() {\n if (!this._connectedPoint) {\n return null;\n }\n return this._connectedPoint.ownerBlock;\n }\n /** Get the block connected on the endpoints of this connection (if any) */\n get connectedBlocks() {\n if (this._endpoints.length === 0) {\n return [];\n }\n return this._endpoints.map((e) => e.ownerBlock);\n }\n /** Gets the list of connected endpoints */\n get endpoints() {\n return this._endpoints;\n }\n /** Gets a boolean indicating if that output point is connected to at least one input */\n get hasEndpoints() {\n return this._endpoints && this._endpoints.length > 0;\n }\n /** Gets a boolean indicating that this connection has a path to the vertex output*/\n get isDirectlyConnectedToVertexOutput() {\n if (!this.hasEndpoints) {\n return false;\n }\n for (const endpoint of this._endpoints) {\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Vertex) {\n return true;\n }\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Neutral || endpoint.ownerBlock.target === NodeMaterialBlockTargets.VertexAndFragment) {\n if (endpoint.ownerBlock.outputs.some((o) => o.isDirectlyConnectedToVertexOutput)) {\n return true;\n }\n }\n }\n return false;\n }\n /** Gets a boolean indicating that this connection will be used in the vertex shader */\n get isConnectedInVertexShader() {\n if (this.target === NodeMaterialBlockTargets.Vertex) {\n return true;\n }\n if (!this.hasEndpoints) {\n return false;\n }\n for (const endpoint of this._endpoints) {\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Vertex) {\n return true;\n }\n if (endpoint.target === NodeMaterialBlockTargets.Vertex) {\n return true;\n }\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Neutral || endpoint.ownerBlock.target === NodeMaterialBlockTargets.VertexAndFragment) {\n if (endpoint.ownerBlock.outputs.some((o) => o.isConnectedInVertexShader)) {\n return true;\n }\n }\n }\n return false;\n }\n /** Gets a boolean indicating that this connection will be used in the fragment shader */\n get isConnectedInFragmentShader() {\n if (this.target === NodeMaterialBlockTargets.Fragment) {\n return true;\n }\n if (!this.hasEndpoints) {\n return false;\n }\n for (const endpoint of this._endpoints) {\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\n return true;\n }\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Neutral || endpoint.ownerBlock.target === NodeMaterialBlockTargets.VertexAndFragment) {\n if (endpoint.ownerBlock.isConnectedInFragmentShader()) {\n return true;\n }\n }\n }\n return false;\n }\n /**\n * Creates a block suitable to be used as an input for this input point.\n * If null is returned, a block based on the point type will be created.\n * @returns The returned string parameter is the name of the output point of NodeMaterialBlock (first parameter of the returned array) that can be connected to the input\n */\n createCustomInputBlock() {\n return null;\n }\n /**\n * Creates a new connection point\n * @param name defines the connection point name\n * @param ownerBlock defines the block hosting this connection point\n * @param direction defines the direction of the connection point\n */\n constructor(name, ownerBlock, direction) {\n /** @internal */\n this._connectedPoint = null;\n this._endpoints = new Array();\n /** @internal */\n this._typeConnectionSource = null;\n /** @internal */\n this._defaultConnectionPointType = null;\n /** @internal */\n this._linkedConnectionSource = null;\n /** @internal */\n this._acceptedConnectionPointType = null;\n this._type = NodeMaterialBlockConnectionPointTypes.Float;\n /** @internal */\n this._enforceAssociatedVariableName = false;\n /** Indicates that this connection point needs dual validation before being connected to another point */\n this.needDualDirectionValidation = false;\n /**\n * Gets or sets the additional types supported by this connection point\n */\n this.acceptedConnectionPointTypes = new Array();\n /**\n * Gets or sets the additional types excluded by this connection point\n */\n this.excludedConnectionPointTypes = new Array();\n /**\n * Observable triggered when this point is connected\n */\n this.onConnectionObservable = new Observable$1();\n /**\n * Gets or sets a boolean indicating that this connection point is exposed on a frame\n */\n this.isExposedOnFrame = false;\n /**\n * Gets or sets number indicating the position that the port is exposed to on a frame\n */\n this.exposedPortPosition = -1;\n /** @internal */\n this._prioritizeVertex = false;\n this._target = NodeMaterialBlockTargets.VertexAndFragment;\n this._ownerBlock = ownerBlock;\n this.name = name;\n this._direction = direction;\n }\n /**\n * Gets the current class name e.g. \"NodeMaterialConnectionPoint\"\n * @returns the class name\n */\n getClassName() {\n return \"NodeMaterialConnectionPoint\";\n }\n /**\n * Gets a boolean indicating if the current point can be connected to another point\n * @param connectionPoint defines the other connection point\n * @returns a boolean\n */\n canConnectTo(connectionPoint) {\n return this.checkCompatibilityState(connectionPoint) === NodeMaterialConnectionPointCompatibilityStates.Compatible;\n }\n /**\n * Gets a number indicating if the current point can be connected to another point\n * @param connectionPoint defines the other connection point\n * @returns a number defining the compatibility state\n */\n checkCompatibilityState(connectionPoint) {\n const ownerBlock = this._ownerBlock;\n const otherBlock = connectionPoint.ownerBlock;\n if (ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\n // Let's check we are not going reverse\n if (otherBlock.target === NodeMaterialBlockTargets.Vertex) {\n return NodeMaterialConnectionPointCompatibilityStates.TargetIncompatible;\n }\n for (const output of otherBlock.outputs) {\n if (output.ownerBlock.target != NodeMaterialBlockTargets.Neutral && output.isConnectedInVertexShader) {\n return NodeMaterialConnectionPointCompatibilityStates.TargetIncompatible;\n }\n }\n }\n if (this.type !== connectionPoint.type && connectionPoint.innerType !== NodeMaterialBlockConnectionPointTypes.AutoDetect) {\n // Equivalents\n if (NodeMaterialConnectionPoint.AreEquivalentTypes(this.type, connectionPoint.type)) {\n return NodeMaterialConnectionPointCompatibilityStates.Compatible;\n }\n // Accepted types\n if ((connectionPoint.acceptedConnectionPointTypes && connectionPoint.acceptedConnectionPointTypes.indexOf(this.type) !== -1) ||\n (connectionPoint._acceptedConnectionPointType && NodeMaterialConnectionPoint.AreEquivalentTypes(connectionPoint._acceptedConnectionPointType.type, this.type))) {\n return NodeMaterialConnectionPointCompatibilityStates.Compatible;\n }\n else {\n return NodeMaterialConnectionPointCompatibilityStates.TypeIncompatible;\n }\n }\n // Excluded\n if (connectionPoint.excludedConnectionPointTypes && connectionPoint.excludedConnectionPointTypes.indexOf(this.type) !== -1) {\n return NodeMaterialConnectionPointCompatibilityStates.TypeIncompatible;\n }\n // Check hierarchy\n let targetBlock = otherBlock;\n let sourceBlock = ownerBlock;\n if (this.direction === NodeMaterialConnectionPointDirection.Input) {\n targetBlock = ownerBlock;\n sourceBlock = otherBlock;\n }\n if (targetBlock.isAnAncestorOf(sourceBlock)) {\n return NodeMaterialConnectionPointCompatibilityStates.HierarchyIssue;\n }\n return NodeMaterialConnectionPointCompatibilityStates.Compatible;\n }\n /**\n * Connect this point to another connection point\n * @param connectionPoint defines the other connection point\n * @param ignoreConstraints defines if the system will ignore connection type constraints (default is false)\n * @returns the current connection point\n */\n connectTo(connectionPoint, ignoreConstraints = false) {\n if (!ignoreConstraints && !this.canConnectTo(connectionPoint)) {\n throw \"Cannot connect these two connectors.\";\n }\n this._endpoints.push(connectionPoint);\n connectionPoint._connectedPoint = this;\n this._enforceAssociatedVariableName = false;\n this.onConnectionObservable.notifyObservers(connectionPoint);\n connectionPoint.onConnectionObservable.notifyObservers(this);\n return this;\n }\n /**\n * Disconnect this point from one of his endpoint\n * @param endpoint defines the other connection point\n * @returns the current connection point\n */\n disconnectFrom(endpoint) {\n const index = this._endpoints.indexOf(endpoint);\n if (index === -1) {\n return this;\n }\n this._endpoints.splice(index, 1);\n endpoint._connectedPoint = null;\n this._enforceAssociatedVariableName = false;\n endpoint._enforceAssociatedVariableName = false;\n return this;\n }\n /**\n * Fill the list of excluded connection point types with all types other than those passed in the parameter\n * @param mask Types (ORed values of NodeMaterialBlockConnectionPointTypes) that are allowed, and thus will not be pushed to the excluded list\n */\n addExcludedConnectionPointFromAllowedTypes(mask) {\n let bitmask = 1;\n while (bitmask < NodeMaterialBlockConnectionPointTypes.All) {\n if (!(mask & bitmask)) {\n this.excludedConnectionPointTypes.push(bitmask);\n }\n bitmask = bitmask << 1;\n }\n }\n /**\n * Serializes this point in a JSON representation\n * @param isInput defines if the connection point is an input (default is true)\n * @returns the serialized point object\n */\n serialize(isInput = true) {\n const serializationObject = {};\n serializationObject.name = this.name;\n serializationObject.displayName = this.displayName;\n if (isInput && this.connectedPoint) {\n serializationObject.inputName = this.name;\n serializationObject.targetBlockId = this.connectedPoint.ownerBlock.uniqueId;\n serializationObject.targetConnectionName = this.connectedPoint.name;\n serializationObject.isExposedOnFrame = true;\n serializationObject.exposedPortPosition = this.exposedPortPosition;\n }\n if (this.isExposedOnFrame || this.exposedPortPosition >= 0) {\n serializationObject.isExposedOnFrame = true;\n serializationObject.exposedPortPosition = this.exposedPortPosition;\n }\n return serializationObject;\n }\n /**\n * Release resources\n */\n dispose() {\n this.onConnectionObservable.clear();\n }\n }\n\n /**\n * Defines a block that can be used inside a node based material\n */\n class NodeMaterialBlock {\n /**\n * Gets the name of the block\n */\n get name() {\n return this._name;\n }\n /**\n * Sets the name of the block. Will check if the name is valid.\n */\n set name(newName) {\n if (!this.validateBlockName(newName)) {\n return;\n }\n this._name = newName;\n }\n /**\n * Gets a boolean indicating that this block can only be used once per NodeMaterial\n */\n get isUnique() {\n return this._isUnique;\n }\n /**\n * Gets a boolean indicating that this block is an end block (e.g. it is generating a system value)\n */\n get isFinalMerger() {\n return this._isFinalMerger;\n }\n /**\n * Gets a boolean indicating that this block is an input (e.g. it sends data to the shader)\n */\n get isInput() {\n return this._isInput;\n }\n /**\n * Gets a boolean indicating if this block is a teleport out\n */\n get isTeleportOut() {\n return this._isTeleportOut;\n }\n /**\n * Gets a boolean indicating if this block is a teleport in\n */\n get isTeleportIn() {\n return this._isTeleportIn;\n }\n /**\n * Gets or sets the build Id\n */\n get buildId() {\n return this._buildId;\n }\n set buildId(value) {\n this._buildId = value;\n }\n /**\n * Gets or sets the target of the block\n */\n get target() {\n return this._target;\n }\n set target(value) {\n if ((this._target & value) !== 0) {\n return;\n }\n this._target = value;\n }\n /**\n * Gets the list of input points\n */\n get inputs() {\n return this._inputs;\n }\n /** Gets the list of output points */\n get outputs() {\n return this._outputs;\n }\n /**\n * Find an input by its name\n * @param name defines the name of the input to look for\n * @returns the input or null if not found\n */\n getInputByName(name) {\n const filter = this._inputs.filter((e) => e.name === name);\n if (filter.length) {\n return filter[0];\n }\n return null;\n }\n /**\n * Find an output by its name\n * @param name defines the name of the output to look for\n * @returns the output or null if not found\n */\n getOutputByName(name) {\n const filter = this._outputs.filter((e) => e.name === name);\n if (filter.length) {\n return filter[0];\n }\n return null;\n }\n /**\n * Creates a new NodeMaterialBlock\n * @param name defines the block name\n * @param target defines the target of that block (Vertex by default)\n * @param isFinalMerger defines a boolean indicating that this block is an end block (e.g. it is generating a system value). Default is false\n */\n constructor(name, target = NodeMaterialBlockTargets.Vertex, isFinalMerger = false) {\n this._isFinalMerger = false;\n this._isInput = false;\n this._isTeleportOut = false;\n this._isTeleportIn = false;\n this._name = \"\";\n this._isUnique = false;\n /** Gets or sets a boolean indicating that only one input can be connected at a time */\n this.inputsAreExclusive = false;\n /** @internal */\n this._codeVariableName = \"\";\n /** @internal */\n this._inputs = new Array();\n /** @internal */\n this._outputs = new Array();\n /**\n * Gets or sets the comments associated with this block\n */\n this.comments = \"\";\n /** Gets or sets a boolean indicating that this input can be edited in the Inspector (false by default) */\n this.visibleInInspector = false;\n /** Gets or sets a boolean indicating that this input can be edited from a collapsed frame */\n this.visibleOnFrame = false;\n this._target = target;\n this._originalTargetIsNeutral = target === NodeMaterialBlockTargets.Neutral;\n this._isFinalMerger = isFinalMerger;\n this._isInput = this.getClassName() === \"InputBlock\";\n this._isTeleportOut = this.getClassName() === \"NodeMaterialTeleportOutBlock\";\n this._isTeleportIn = this.getClassName() === \"NodeMaterialTeleportInBlock\";\n this._name = name;\n this.uniqueId = UniqueIdGenerator.UniqueId;\n }\n /** @internal */\n _setInitialTarget(target) {\n this._target = target;\n this._originalTargetIsNeutral = target === NodeMaterialBlockTargets.Neutral;\n }\n /**\n * Initialize the block and prepare the context for build\n * @param state defines the state that will be used for the build\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n initialize(state) {\n // Do nothing\n }\n /**\n * Bind data to effect. Will only be called for blocks with isBindable === true\n * @param effect defines the effect to bind data to\n * @param nodeMaterial defines the hosting NodeMaterial\n * @param mesh defines the mesh that will be rendered\n * @param subMesh defines the submesh that will be rendered\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n bind(effect, nodeMaterial, mesh, subMesh) {\n // Do nothing\n }\n _declareOutput(output, state) {\n return `${state._getGLType(output.type)} ${output.associatedVariableName}`;\n }\n _writeVariable(currentPoint) {\n const connectionPoint = currentPoint.connectedPoint;\n if (connectionPoint) {\n return `${currentPoint.associatedVariableName}`;\n }\n return `0.`;\n }\n _writeFloat(value) {\n let stringVersion = value.toString();\n if (stringVersion.indexOf(\".\") === -1) {\n stringVersion += \".0\";\n }\n return `${stringVersion}`;\n }\n /**\n * Gets the current class name e.g. \"NodeMaterialBlock\"\n * @returns the class name\n */\n getClassName() {\n return \"NodeMaterialBlock\";\n }\n /** Gets a boolean indicating that this connection will be used in the fragment shader */\n isConnectedInFragmentShader() {\n return this.outputs.some((o) => o.isConnectedInFragmentShader);\n }\n /**\n * Register a new input. Must be called inside a block constructor\n * @param name defines the connection point name\n * @param type defines the connection point type\n * @param isOptional defines a boolean indicating that this input can be omitted\n * @param target defines the target to use to limit the connection point (will be VertexAndFragment by default)\n * @param point an already created connection point. If not provided, create a new one\n * @returns the current block\n */\n registerInput(name, type, isOptional = false, target, point) {\n point = point !== null && point !== void 0 ? point : new NodeMaterialConnectionPoint(name, this, NodeMaterialConnectionPointDirection.Input);\n point.type = type;\n point.isOptional = isOptional;\n if (target) {\n point.target = target;\n }\n this._inputs.push(point);\n return this;\n }\n /**\n * Register a new output. Must be called inside a block constructor\n * @param name defines the connection point name\n * @param type defines the connection point type\n * @param target defines the target to use to limit the connection point (will be VertexAndFragment by default)\n * @param point an already created connection point. If not provided, create a new one\n * @returns the current block\n */\n registerOutput(name, type, target, point) {\n point = point !== null && point !== void 0 ? point : new NodeMaterialConnectionPoint(name, this, NodeMaterialConnectionPointDirection.Output);\n point.type = type;\n if (target) {\n point.target = target;\n }\n this._outputs.push(point);\n return this;\n }\n /**\n * Will return the first available input e.g. the first one which is not an uniform or an attribute\n * @param forOutput defines an optional connection point to check compatibility with\n * @returns the first available input or null\n */\n getFirstAvailableInput(forOutput = null) {\n for (const input of this._inputs) {\n if (!input.connectedPoint) {\n if (!forOutput || forOutput.type === input.type || input.type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {\n return input;\n }\n }\n }\n return null;\n }\n /**\n * Will return the first available output e.g. the first one which is not yet connected and not a varying\n * @param forBlock defines an optional block to check compatibility with\n * @returns the first available input or null\n */\n getFirstAvailableOutput(forBlock = null) {\n for (const output of this._outputs) {\n if (!forBlock || !forBlock.target || forBlock.target === NodeMaterialBlockTargets.Neutral || (forBlock.target & output.target) !== 0) {\n return output;\n }\n }\n return null;\n }\n /**\n * Gets the sibling of the given output\n * @param current defines the current output\n * @returns the next output in the list or null\n */\n getSiblingOutput(current) {\n const index = this._outputs.indexOf(current);\n if (index === -1 || index >= this._outputs.length) {\n return null;\n }\n return this._outputs[index + 1];\n }\n /**\n * Checks if the current block is an ancestor of a given block\n * @param block defines the potential descendant block to check\n * @returns true if block is a descendant\n */\n isAnAncestorOf(block) {\n for (const output of this._outputs) {\n if (!output.hasEndpoints) {\n continue;\n }\n for (const endpoint of output.endpoints) {\n if (endpoint.ownerBlock === block) {\n return true;\n }\n if (endpoint.ownerBlock.isAnAncestorOf(block)) {\n return true;\n }\n }\n }\n return false;\n }\n /**\n * Connect current block with another block\n * @param other defines the block to connect with\n * @param options define the various options to help pick the right connections\n * @param options.input\n * @param options.output\n * @param options.outputSwizzle\n * @returns the current block\n */\n connectTo(other, options) {\n if (this._outputs.length === 0) {\n return;\n }\n let output = options && options.output ? this.getOutputByName(options.output) : this.getFirstAvailableOutput(other);\n let notFound = true;\n while (notFound) {\n const input = options && options.input ? other.getInputByName(options.input) : other.getFirstAvailableInput(output);\n if (output && input && output.canConnectTo(input)) {\n output.connectTo(input);\n notFound = false;\n }\n else if (!output) {\n throw \"Unable to find a compatible match\";\n }\n else {\n output = this.getSiblingOutput(output);\n }\n }\n return this;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _buildBlock(state) {\n // Empty. Must be defined by child nodes\n }\n /**\n * Add uniforms, samplers and uniform buffers at compilation time\n * @param state defines the state to update\n * @param nodeMaterial defines the node material requesting the update\n * @param defines defines the material defines to update\n * @param uniformBuffers defines the list of uniform buffer names\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n updateUniformsAndSamples(state, nodeMaterial, defines, uniformBuffers) {\n // Do nothing\n }\n /**\n * Add potential fallbacks if shader compilation fails\n * @param mesh defines the mesh to be rendered\n * @param fallbacks defines the current prioritized list of fallbacks\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n provideFallbacks(mesh, fallbacks) {\n // Do nothing\n }\n /**\n * Initialize defines for shader compilation\n * @param mesh defines the mesh to be rendered\n * @param nodeMaterial defines the node material requesting the update\n * @param defines defines the material defines to update\n * @param useInstances specifies that instances should be used\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n initializeDefines(mesh, nodeMaterial, defines, useInstances = false) { }\n /**\n * Update defines for shader compilation\n * @param mesh defines the mesh to be rendered\n * @param nodeMaterial defines the node material requesting the update\n * @param defines defines the material defines to update\n * @param useInstances specifies that instances should be used\n * @param subMesh defines which submesh to render\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n prepareDefines(mesh, nodeMaterial, defines, useInstances = false, subMesh) {\n // Do nothing\n }\n /**\n * Lets the block try to connect some inputs automatically\n * @param material defines the hosting NodeMaterial\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n autoConfigure(material) {\n // Do nothing\n }\n /**\n * Function called when a block is declared as repeatable content generator\n * @param vertexShaderState defines the current compilation state for the vertex shader\n * @param fragmentShaderState defines the current compilation state for the fragment shader\n * @param mesh defines the mesh to be rendered\n * @param defines defines the material defines to update\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n replaceRepeatableContent(vertexShaderState, fragmentShaderState, mesh, defines) {\n // Do nothing\n }\n /** Gets a boolean indicating that the code of this block will be promoted to vertex shader even if connected to fragment output */\n get willBeGeneratedIntoVertexShaderFromFragmentShader() {\n if (this.isInput || this.isFinalMerger) {\n return false;\n }\n if (this._outputs.some((o) => o.isDirectlyConnectedToVertexOutput)) {\n return false;\n }\n if (this.target === NodeMaterialBlockTargets.Vertex) {\n return false;\n }\n if (this.target === NodeMaterialBlockTargets.VertexAndFragment || this.target === NodeMaterialBlockTargets.Neutral) {\n if (this._outputs.some((o) => o.isConnectedInVertexShader)) {\n return true;\n }\n }\n return false;\n }\n /**\n * Checks if the block is ready\n * @param mesh defines the mesh to be rendered\n * @param nodeMaterial defines the node material requesting the update\n * @param defines defines the material defines to update\n * @param useInstances specifies that instances should be used\n * @returns true if the block is ready\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isReady(mesh, nodeMaterial, defines, useInstances = false) {\n return true;\n }\n _linkConnectionTypes(inputIndex0, inputIndex1, looseCoupling = false) {\n if (looseCoupling) {\n this._inputs[inputIndex1]._acceptedConnectionPointType = this._inputs[inputIndex0];\n }\n else {\n this._inputs[inputIndex0]._linkedConnectionSource = this._inputs[inputIndex1];\n }\n this._inputs[inputIndex1]._linkedConnectionSource = this._inputs[inputIndex0];\n }\n _processBuild(block, state, input, activeBlocks) {\n block.build(state, activeBlocks);\n const localBlockIsFragment = state._vertexState != null;\n const otherBlockWasGeneratedInVertexShader = block._buildTarget === NodeMaterialBlockTargets.Vertex && block.target !== NodeMaterialBlockTargets.VertexAndFragment;\n if (localBlockIsFragment &&\n ((block.target & block._buildTarget) === 0 ||\n (block.target & input.target) === 0 ||\n (this.target !== NodeMaterialBlockTargets.VertexAndFragment && otherBlockWasGeneratedInVertexShader))) {\n // context switch! We need a varying\n if ((!block.isInput && state.target !== block._buildTarget) || // block was already emitted by vertex shader\n (block.isInput && block.isAttribute && !block._noContextSwitch) // block is an attribute\n ) {\n const connectedPoint = input.connectedPoint;\n if (state._vertexState._emitVaryingFromString(\"v_\" + connectedPoint.associatedVariableName, state._getGLType(connectedPoint.type))) {\n state._vertexState.compilationString += `${\"v_\" + connectedPoint.associatedVariableName} = ${connectedPoint.associatedVariableName};\\n`;\n }\n input.associatedVariableName = \"v_\" + connectedPoint.associatedVariableName;\n input._enforceAssociatedVariableName = true;\n }\n }\n }\n /**\n * Validates the new name for the block node.\n * @param newName the new name to be given to the node.\n * @returns false if the name is a reserve word, else true.\n */\n validateBlockName(newName) {\n const reservedNames = [\n \"position\",\n \"normal\",\n \"tangent\",\n \"particle_positionw\",\n \"uv\",\n \"uv2\",\n \"uv3\",\n \"uv4\",\n \"uv5\",\n \"uv6\",\n \"position2d\",\n \"particle_uv\",\n \"matricesIndices\",\n \"matricesWeights\",\n \"world0\",\n \"world1\",\n \"world2\",\n \"world3\",\n \"particle_color\",\n \"particle_texturemask\",\n ];\n for (const reservedName of reservedNames) {\n if (newName === reservedName) {\n return false;\n }\n }\n return true;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _customBuildStep(state, activeBlocks) {\n // Must be implemented by children\n }\n /**\n * Compile the current node and generate the shader code\n * @param state defines the current compilation state (uniforms, samplers, current string)\n * @param activeBlocks defines the list of active blocks (i.e. blocks to compile)\n * @returns true if already built\n */\n build(state, activeBlocks) {\n if (this._buildId === state.sharedData.buildId) {\n return true;\n }\n if (!this.isInput) {\n /** Prepare outputs */\n for (const output of this._outputs) {\n if (!output.associatedVariableName) {\n output.associatedVariableName = state._getFreeVariableName(output.name);\n }\n }\n }\n // Check if \"parent\" blocks are compiled\n for (const input of this._inputs) {\n if (!input.connectedPoint) {\n if (!input.isOptional) {\n // Emit a warning\n state.sharedData.checks.notConnectedNonOptionalInputs.push(input);\n }\n continue;\n }\n if (this.target !== NodeMaterialBlockTargets.Neutral) {\n if ((input.target & this.target) === 0) {\n continue;\n }\n if ((input.target & state.target) === 0) {\n continue;\n }\n }\n const block = input.connectedPoint.ownerBlock;\n if (block && block !== this) {\n this._processBuild(block, state, input, activeBlocks);\n }\n }\n this._customBuildStep(state, activeBlocks);\n if (this._buildId === state.sharedData.buildId) {\n return true; // Need to check again as inputs can be connected multiple time to this endpoint\n }\n // Logs\n if (state.sharedData.verbose) {\n console.log(`${state.target === NodeMaterialBlockTargets.Vertex ? \"Vertex shader\" : \"Fragment shader\"}: Building ${this.name} [${this.getClassName()}]`);\n }\n // Checks final outputs\n if (this.isFinalMerger) {\n switch (state.target) {\n case NodeMaterialBlockTargets.Vertex:\n state.sharedData.checks.emitVertex = true;\n break;\n case NodeMaterialBlockTargets.Fragment:\n state.sharedData.checks.emitFragment = true;\n break;\n }\n }\n if (!this.isInput && state.sharedData.emitComments) {\n state.compilationString += `\\n//${this.name}\\n`;\n }\n this._buildBlock(state);\n this._buildId = state.sharedData.buildId;\n this._buildTarget = state.target;\n // Compile connected blocks\n for (const output of this._outputs) {\n if ((output.target & state.target) === 0) {\n continue;\n }\n for (const endpoint of output.endpoints) {\n const block = endpoint.ownerBlock;\n if (block && (block.target & state.target) !== 0 && activeBlocks.indexOf(block) !== -1) {\n this._processBuild(block, state, endpoint, activeBlocks);\n }\n }\n }\n return false;\n }\n _inputRename(name) {\n return name;\n }\n _outputRename(name) {\n return name;\n }\n _dumpPropertiesCode() {\n const variableName = this._codeVariableName;\n return `${variableName}.visibleInInspector = ${this.visibleInInspector};\\n${variableName}.visibleOnFrame = ${this.visibleOnFrame};\\n${variableName}.target = ${this.target};\\n`;\n }\n /**\n * @internal\n */\n _dumpCode(uniqueNames, alreadyDumped) {\n alreadyDumped.push(this);\n // Get unique name\n const nameAsVariableName = this.name.replace(/[^A-Za-z_]+/g, \"\");\n this._codeVariableName = nameAsVariableName || `${this.getClassName()}_${this.uniqueId}`;\n if (uniqueNames.indexOf(this._codeVariableName) !== -1) {\n let index = 0;\n do {\n index++;\n this._codeVariableName = nameAsVariableName + index;\n } while (uniqueNames.indexOf(this._codeVariableName) !== -1);\n }\n uniqueNames.push(this._codeVariableName);\n // Declaration\n let codeString = `\\n// ${this.getClassName()}\\n`;\n if (this.comments) {\n codeString += `// ${this.comments}\\n`;\n }\n codeString += `var ${this._codeVariableName} = new BABYLON.${this.getClassName()}(\"${this.name}\");\\n`;\n // Properties\n codeString += this._dumpPropertiesCode();\n // Inputs\n for (const input of this.inputs) {\n if (!input.isConnected) {\n continue;\n }\n const connectedOutput = input.connectedPoint;\n const connectedBlock = connectedOutput.ownerBlock;\n if (alreadyDumped.indexOf(connectedBlock) === -1) {\n codeString += connectedBlock._dumpCode(uniqueNames, alreadyDumped);\n }\n }\n // Outputs\n for (const output of this.outputs) {\n if (!output.hasEndpoints) {\n continue;\n }\n for (const endpoint of output.endpoints) {\n const connectedBlock = endpoint.ownerBlock;\n if (connectedBlock && alreadyDumped.indexOf(connectedBlock) === -1) {\n codeString += connectedBlock._dumpCode(uniqueNames, alreadyDumped);\n }\n }\n }\n return codeString;\n }\n /**\n * @internal\n */\n _dumpCodeForOutputConnections(alreadyDumped) {\n let codeString = \"\";\n if (alreadyDumped.indexOf(this) !== -1) {\n return codeString;\n }\n alreadyDumped.push(this);\n for (const input of this.inputs) {\n if (!input.isConnected) {\n continue;\n }\n const connectedOutput = input.connectedPoint;\n const connectedBlock = connectedOutput.ownerBlock;\n codeString += connectedBlock._dumpCodeForOutputConnections(alreadyDumped);\n codeString += `${connectedBlock._codeVariableName}.${connectedBlock._outputRename(connectedOutput.name)}.connectTo(${this._codeVariableName}.${this._inputRename(input.name)});\\n`;\n }\n return codeString;\n }\n /**\n * Clone the current block to a new identical block\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a copy of the current block\n */\n clone(scene, rootUrl = \"\") {\n const serializationObject = this.serialize();\n const blockType = GetClass(serializationObject.customType);\n if (blockType) {\n const block = new blockType();\n block._deserialize(serializationObject, scene, rootUrl);\n return block;\n }\n return null;\n }\n /**\n * Serializes this block in a JSON representation\n * @returns the serialized block object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.customType = \"BABYLON.\" + this.getClassName();\n serializationObject.id = this.uniqueId;\n serializationObject.name = this.name;\n serializationObject.comments = this.comments;\n serializationObject.visibleInInspector = this.visibleInInspector;\n serializationObject.visibleOnFrame = this.visibleOnFrame;\n serializationObject.target = this.target;\n serializationObject.inputs = [];\n serializationObject.outputs = [];\n for (const input of this.inputs) {\n serializationObject.inputs.push(input.serialize());\n }\n for (const output of this.outputs) {\n serializationObject.outputs.push(output.serialize(false));\n }\n return serializationObject;\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _deserialize(serializationObject, scene, rootUrl) {\n var _a;\n this.name = serializationObject.name;\n this.comments = serializationObject.comments;\n this.visibleInInspector = !!serializationObject.visibleInInspector;\n this.visibleOnFrame = !!serializationObject.visibleOnFrame;\n this._target = (_a = serializationObject.target) !== null && _a !== void 0 ? _a : this.target;\n this._deserializePortDisplayNamesAndExposedOnFrame(serializationObject);\n }\n _deserializePortDisplayNamesAndExposedOnFrame(serializationObject) {\n const serializedInputs = serializationObject.inputs;\n const serializedOutputs = serializationObject.outputs;\n if (serializedInputs) {\n serializedInputs.forEach((port, i) => {\n if (port.displayName) {\n this.inputs[i].displayName = port.displayName;\n }\n if (port.isExposedOnFrame) {\n this.inputs[i].isExposedOnFrame = port.isExposedOnFrame;\n this.inputs[i].exposedPortPosition = port.exposedPortPosition;\n }\n });\n }\n if (serializedOutputs) {\n serializedOutputs.forEach((port, i) => {\n if (port.displayName) {\n this.outputs[i].displayName = port.displayName;\n }\n if (port.isExposedOnFrame) {\n this.outputs[i].isExposedOnFrame = port.isExposedOnFrame;\n this.outputs[i].exposedPortPosition = port.exposedPortPosition;\n }\n });\n }\n }\n /**\n * Release resources\n */\n dispose() {\n for (const input of this.inputs) {\n input.dispose();\n }\n for (const output of this.outputs) {\n output.dispose();\n }\n }\n }\n\n /**\n * Block used to transform a vector (2, 3 or 4) with a matrix. It will generate a Vector4\n */\n class TransformBlock extends NodeMaterialBlock {\n /**\n * Creates a new TransformBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n /**\n * Defines the value to use to complement W value to transform it to a Vector4\n */\n this.complementW = 1;\n /**\n * Defines the value to use to complement z value to transform it to a Vector4\n */\n this.complementZ = 0;\n this.target = NodeMaterialBlockTargets.Vertex;\n this.registerInput(\"vector\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\n this.registerInput(\"transform\", NodeMaterialBlockConnectionPointTypes.Matrix);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Vector4);\n this.registerOutput(\"xyz\", NodeMaterialBlockConnectionPointTypes.Vector3);\n this._inputs[0].onConnectionObservable.add((other) => {\n if (other.ownerBlock.isInput) {\n const otherAsInput = other.ownerBlock;\n if (otherAsInput.name === \"normal\" || otherAsInput.name === \"tangent\") {\n this.complementW = 0;\n }\n }\n });\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"TransformBlock\";\n }\n /**\n * Gets the vector input\n */\n get vector() {\n return this._inputs[0];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n /**\n * Gets the xyz output component\n */\n get xyz() {\n return this._outputs[1];\n }\n /**\n * Gets the matrix transform input\n */\n get transform() {\n return this._inputs[1];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const vector = this.vector;\n const transform = this.transform;\n if (vector.connectedPoint) {\n // None uniform scaling case.\n if (this.complementW === 0) {\n const comments = `//${this.name}`;\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\n state.sharedData.blocksWithDefines.push(this);\n const transformName = state._getFreeVariableName(`${transform.associatedVariableName}_NUS`);\n state.compilationString += `mat3 ${transformName} = mat3(${transform.associatedVariableName});\\n`;\n state.compilationString += `#ifdef NONUNIFORMSCALING\\n`;\n state.compilationString += `${transformName} = transposeMat3(inverseMat3(${transformName}));\\n`;\n state.compilationString += `#endif\\n`;\n switch (vector.connectedPoint.type) {\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n state.compilationString +=\n this._declareOutput(this.output, state) +\n ` = vec4(${transformName} * vec3(${vector.associatedVariableName}, ${this._writeFloat(this.complementZ)}), ${this._writeFloat(this.complementW)});\\n`;\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n case NodeMaterialBlockConnectionPointTypes.Color3:\n state.compilationString +=\n this._declareOutput(this.output, state) + ` = vec4(${transformName} * ${vector.associatedVariableName}, ${this._writeFloat(this.complementW)});\\n`;\n break;\n default:\n state.compilationString +=\n this._declareOutput(this.output, state) + ` = vec4(${transformName} * ${vector.associatedVariableName}.xyz, ${this._writeFloat(this.complementW)});\\n`;\n break;\n }\n }\n else {\n const transformName = transform.associatedVariableName;\n switch (vector.connectedPoint.type) {\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n state.compilationString +=\n this._declareOutput(this.output, state) +\n ` = ${transformName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementZ)}, ${this._writeFloat(this.complementW)});\\n`;\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n case NodeMaterialBlockConnectionPointTypes.Color3:\n state.compilationString +=\n this._declareOutput(this.output, state) + ` = ${transformName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementW)});\\n`;\n break;\n default:\n state.compilationString += this._declareOutput(this.output, state) + ` = ${transformName} * ${vector.associatedVariableName};\\n`;\n break;\n }\n }\n if (this.xyz.hasEndpoints) {\n state.compilationString += this._declareOutput(this.xyz, state) + ` = ${this.output.associatedVariableName}.xyz;\\n`;\n }\n }\n return this;\n }\n /**\n * Update defines for shader compilation\n * @param mesh defines the mesh to be rendered\n * @param nodeMaterial defines the node material requesting the update\n * @param defines defines the material defines to update\n */\n prepareDefines(mesh, nodeMaterial, defines) {\n // Do nothing\n if (mesh.nonUniformScaling) {\n defines.setValue(\"NONUNIFORMSCALING\", true);\n }\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.complementZ = this.complementZ;\n serializationObject.complementW = this.complementW;\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n super._deserialize(serializationObject, scene, rootUrl);\n this.complementZ = serializationObject.complementZ !== undefined ? serializationObject.complementZ : 0.0;\n this.complementW = serializationObject.complementW !== undefined ? serializationObject.complementW : 1.0;\n }\n _dumpPropertiesCode() {\n let codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.complementZ = ${this.complementZ};\\n`;\n codeString += `${this._codeVariableName}.complementW = ${this.complementW};\\n`;\n return codeString;\n }\n }\n RegisterClass(\"BABYLON.TransformBlock\", TransformBlock);\n\n /**\n * Block used to output the vertex position\n */\n class VertexOutputBlock extends NodeMaterialBlock {\n /**\n * Creates a new VertexOutputBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Vertex, true);\n this.registerInput(\"vector\", NodeMaterialBlockConnectionPointTypes.Vector4);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"VertexOutputBlock\";\n }\n /**\n * Gets the vector input component\n */\n get vector() {\n return this._inputs[0];\n }\n _isLogarithmicDepthEnabled(nodeList) {\n for (const node of nodeList) {\n if (node.useLogarithmicDepth) {\n return true;\n }\n }\n return false;\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const input = this.vector;\n state.compilationString += `gl_Position = ${input.associatedVariableName};\\n`;\n if (this._isLogarithmicDepthEnabled(state.sharedData.fragmentOutputNodes)) {\n state._emitUniformFromString(\"logarithmicDepthConstant\", \"float\");\n state._emitVaryingFromString(\"vFragmentDepth\", \"float\");\n state.compilationString += `vFragmentDepth = 1.0 + gl_Position.w;\\n`;\n state.compilationString += `gl_Position.z = log2(max(0.000001, vFragmentDepth)) * logarithmicDepthConstant;\\n`;\n }\n return this;\n }\n }\n RegisterClass(\"BABYLON.VertexOutputBlock\", VertexOutputBlock);\n\n /**\n * Enum defining the type of properties that can be edited in the property pages in the node editor\n */\n var PropertyTypeForEdition;\n (function (PropertyTypeForEdition) {\n /** property is a boolean */\n PropertyTypeForEdition[PropertyTypeForEdition[\"Boolean\"] = 0] = \"Boolean\";\n /** property is a float */\n PropertyTypeForEdition[PropertyTypeForEdition[\"Float\"] = 1] = \"Float\";\n /** property is a int */\n PropertyTypeForEdition[PropertyTypeForEdition[\"Int\"] = 2] = \"Int\";\n /** property is a Vector2 */\n PropertyTypeForEdition[PropertyTypeForEdition[\"Vector2\"] = 3] = \"Vector2\";\n /** property is a list of values */\n PropertyTypeForEdition[PropertyTypeForEdition[\"List\"] = 4] = \"List\";\n })(PropertyTypeForEdition || (PropertyTypeForEdition = {}));\n /**\n * Decorator that flags a property in a node block as being editable\n * @param displayName\n * @param propertyType\n * @param groupName\n * @param options\n */\n function editableInPropertyPage(displayName, propertyType = PropertyTypeForEdition.Boolean, groupName = \"PROPERTIES\", options) {\n return (target, propertyKey) => {\n let propStore = target._propStore;\n if (!propStore) {\n propStore = [];\n target._propStore = propStore;\n }\n propStore.push({\n propertyName: propertyKey,\n displayName: displayName,\n type: propertyType,\n groupName: groupName,\n options: options !== null && options !== void 0 ? options : {},\n });\n };\n }\n\n /**\n * Block used to output the final color\n */\n class FragmentOutputBlock extends NodeMaterialBlock {\n /**\n * Create a new FragmentOutputBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Fragment, true);\n /** Gets or sets a boolean indicating if content needs to be converted to gamma space */\n this.convertToGammaSpace = false;\n /** Gets or sets a boolean indicating if content needs to be converted to linear space */\n this.convertToLinearSpace = false;\n /** Gets or sets a boolean indicating if logarithmic depth should be used */\n this.useLogarithmicDepth = false;\n this.registerInput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, true);\n this.registerInput(\"rgb\", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);\n this.registerInput(\"a\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.rgb.addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Color3 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Float);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"FragmentOutputBlock\";\n }\n /**\n * Initialize the block and prepare the context for build\n * @param state defines the state that will be used for the build\n */\n initialize(state) {\n state._excludeVariableName(\"logarithmicDepthConstant\");\n state._excludeVariableName(\"vFragmentDepth\");\n }\n /**\n * Gets the rgba input component\n */\n get rgba() {\n return this._inputs[0];\n }\n /**\n * Gets the rgb input component\n */\n get rgb() {\n return this._inputs[1];\n }\n /**\n * Gets the a input component\n */\n get a() {\n return this._inputs[2];\n }\n prepareDefines(mesh, nodeMaterial, defines) {\n defines.setValue(this._linearDefineName, this.convertToLinearSpace, true);\n defines.setValue(this._gammaDefineName, this.convertToGammaSpace, true);\n }\n bind(effect, nodeMaterial, mesh) {\n if (this.useLogarithmicDepth && mesh) {\n MaterialHelper.BindLogDepth(undefined, effect, mesh.getScene());\n }\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const rgba = this.rgba;\n const rgb = this.rgb;\n const a = this.a;\n state.sharedData.hints.needAlphaBlending = rgba.isConnected || a.isConnected;\n state.sharedData.blocksWithDefines.push(this);\n if (this.useLogarithmicDepth) {\n state._emitUniformFromString(\"logarithmicDepthConstant\", \"float\");\n state._emitVaryingFromString(\"vFragmentDepth\", \"float\");\n state.sharedData.bindableBlocks.push(this);\n }\n this._linearDefineName = state._getFreeDefineName(\"CONVERTTOLINEAR\");\n this._gammaDefineName = state._getFreeDefineName(\"CONVERTTOGAMMA\");\n const comments = `//${this.name}`;\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\n if (rgba.connectedPoint) {\n if (a.isConnected) {\n state.compilationString += `gl_FragColor = vec4(${rgba.associatedVariableName}.rgb, ${a.associatedVariableName});\\n`;\n }\n else {\n state.compilationString += `gl_FragColor = ${rgba.associatedVariableName};\\n`;\n }\n }\n else if (rgb.connectedPoint) {\n let aValue = \"1.0\";\n if (a.connectedPoint) {\n aValue = a.associatedVariableName;\n }\n if (rgb.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Float) {\n state.compilationString += `gl_FragColor = vec4(${rgb.associatedVariableName}, ${rgb.associatedVariableName}, ${rgb.associatedVariableName}, ${aValue});\\n`;\n }\n else {\n state.compilationString += `gl_FragColor = vec4(${rgb.associatedVariableName}, ${aValue});\\n`;\n }\n }\n else {\n state.sharedData.checks.notConnectedNonOptionalInputs.push(rgba);\n }\n state.compilationString += `#ifdef ${this._linearDefineName}\\n`;\n state.compilationString += `gl_FragColor = toLinearSpace(gl_FragColor);\\n`;\n state.compilationString += `#endif\\n`;\n state.compilationString += `#ifdef ${this._gammaDefineName}\\n`;\n state.compilationString += `gl_FragColor = toGammaSpace(gl_FragColor);\\n`;\n state.compilationString += `#endif\\n`;\n if (this.useLogarithmicDepth) {\n state.compilationString += `gl_FragDepthEXT = log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;\\n`;\n }\n return this;\n }\n _dumpPropertiesCode() {\n let codeString = super._dumpPropertiesCode();\n codeString += `${this._codeVariableName}.convertToGammaSpace = ${this.convertToGammaSpace};\\n`;\n codeString += `${this._codeVariableName}.convertToLinearSpace = ${this.convertToLinearSpace};\\n`;\n codeString += `${this._codeVariableName}.useLogarithmicDepth = ${this.useLogarithmicDepth};\\n`;\n return codeString;\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\n serializationObject.useLogarithmicDepth = this.useLogarithmicDepth;\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n var _a;\n super._deserialize(serializationObject, scene, rootUrl);\n this.convertToGammaSpace = serializationObject.convertToGammaSpace;\n this.convertToLinearSpace = serializationObject.convertToLinearSpace;\n this.useLogarithmicDepth = (_a = serializationObject.useLogarithmicDepth) !== null && _a !== void 0 ? _a : false;\n }\n }\n __decorate$1([\n editableInPropertyPage(\"Convert to gamma space\", PropertyTypeForEdition.Boolean, \"PROPERTIES\", { notifiers: { update: true } })\n ], FragmentOutputBlock.prototype, \"convertToGammaSpace\", void 0);\n __decorate$1([\n editableInPropertyPage(\"Convert to linear space\", PropertyTypeForEdition.Boolean, \"PROPERTIES\", { notifiers: { update: true } })\n ], FragmentOutputBlock.prototype, \"convertToLinearSpace\", void 0);\n __decorate$1([\n editableInPropertyPage(\"Use logarithmic depth\", PropertyTypeForEdition.Boolean, \"PROPERTIES\")\n ], FragmentOutputBlock.prototype, \"useLogarithmicDepth\", void 0);\n RegisterClass(\"BABYLON.FragmentOutputBlock\", FragmentOutputBlock);\n\n /**\n * Enum defining the mode of a NodeMaterialBlockConnectionPoint\n */\n var NodeMaterialBlockConnectionPointMode;\n (function (NodeMaterialBlockConnectionPointMode) {\n /** Value is an uniform */\n NodeMaterialBlockConnectionPointMode[NodeMaterialBlockConnectionPointMode[\"Uniform\"] = 0] = \"Uniform\";\n /** Value is a mesh attribute */\n NodeMaterialBlockConnectionPointMode[NodeMaterialBlockConnectionPointMode[\"Attribute\"] = 1] = \"Attribute\";\n /** Value is a varying between vertex and fragment shaders */\n NodeMaterialBlockConnectionPointMode[NodeMaterialBlockConnectionPointMode[\"Varying\"] = 2] = \"Varying\";\n /** Mode is undefined */\n NodeMaterialBlockConnectionPointMode[NodeMaterialBlockConnectionPointMode[\"Undefined\"] = 3] = \"Undefined\";\n })(NodeMaterialBlockConnectionPointMode || (NodeMaterialBlockConnectionPointMode = {}));\n\n /**\n * Enum used to define system values e.g. values automatically provided by the system\n */\n var NodeMaterialSystemValues;\n (function (NodeMaterialSystemValues) {\n /** World */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"World\"] = 1] = \"World\";\n /** View */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"View\"] = 2] = \"View\";\n /** Projection */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"Projection\"] = 3] = \"Projection\";\n /** ViewProjection */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"ViewProjection\"] = 4] = \"ViewProjection\";\n /** WorldView */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"WorldView\"] = 5] = \"WorldView\";\n /** WorldViewProjection */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"WorldViewProjection\"] = 6] = \"WorldViewProjection\";\n /** CameraPosition */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"CameraPosition\"] = 7] = \"CameraPosition\";\n /** Fog Color */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"FogColor\"] = 8] = \"FogColor\";\n /** Delta time */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"DeltaTime\"] = 9] = \"DeltaTime\";\n /** Camera parameters */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"CameraParameters\"] = 10] = \"CameraParameters\";\n /** Material alpha */\n NodeMaterialSystemValues[NodeMaterialSystemValues[\"MaterialAlpha\"] = 11] = \"MaterialAlpha\";\n })(NodeMaterialSystemValues || (NodeMaterialSystemValues = {}));\n\n /**\n * Enum defining the type of animations supported by InputBlock\n */\n var AnimatedInputBlockTypes;\n (function (AnimatedInputBlockTypes) {\n /** No animation */\n AnimatedInputBlockTypes[AnimatedInputBlockTypes[\"None\"] = 0] = \"None\";\n /** Time based animation (is incremented by 0.6 each second). Will only work for floats */\n AnimatedInputBlockTypes[AnimatedInputBlockTypes[\"Time\"] = 1] = \"Time\";\n /** Time elapsed (in seconds) since the engine was initialized. Will only work for floats */\n AnimatedInputBlockTypes[AnimatedInputBlockTypes[\"RealTime\"] = 2] = \"RealTime\";\n })(AnimatedInputBlockTypes || (AnimatedInputBlockTypes = {}));\n\n /* eslint-disable @typescript-eslint/naming-convention */\n const remapAttributeName = {\n position2d: \"position\",\n particle_uv: \"vUV\",\n particle_color: \"vColor\",\n particle_texturemask: \"textureMask\",\n particle_positionw: \"vPositionW\",\n };\n const attributeInFragmentOnly = {\n particle_uv: true,\n particle_color: true,\n particle_texturemask: true,\n particle_positionw: true,\n };\n const attributeAsUniform = {\n particle_texturemask: true,\n };\n /**\n * Block used to expose an input value\n */\n class InputBlock extends NodeMaterialBlock {\n /**\n * Gets or sets the connection point type (default is float)\n */\n get type() {\n if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {\n if (this.isUniform && this.value != null) {\n if (!isNaN(this.value)) {\n this._type = NodeMaterialBlockConnectionPointTypes.Float;\n return this._type;\n }\n switch (this.value.getClassName()) {\n case \"Vector2\":\n this._type = NodeMaterialBlockConnectionPointTypes.Vector2;\n return this._type;\n case \"Vector3\":\n this._type = NodeMaterialBlockConnectionPointTypes.Vector3;\n return this._type;\n case \"Vector4\":\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\n return this._type;\n case \"Color3\":\n this._type = NodeMaterialBlockConnectionPointTypes.Color3;\n return this._type;\n case \"Color4\":\n this._type = NodeMaterialBlockConnectionPointTypes.Color4;\n return this._type;\n case \"Matrix\":\n this._type = NodeMaterialBlockConnectionPointTypes.Matrix;\n return this._type;\n }\n }\n if (this.isAttribute) {\n switch (this.name) {\n case \"position\":\n case \"normal\":\n case \"particle_positionw\":\n this._type = NodeMaterialBlockConnectionPointTypes.Vector3;\n return this._type;\n case \"uv\":\n case \"uv2\":\n case \"uv3\":\n case \"uv4\":\n case \"uv5\":\n case \"uv6\":\n case \"position2d\":\n case \"particle_uv\":\n this._type = NodeMaterialBlockConnectionPointTypes.Vector2;\n return this._type;\n case \"matricesIndices\":\n case \"matricesWeights\":\n case \"matricesIndicesExtra\":\n case \"matricesWeightsExtra\":\n case \"world0\":\n case \"world1\":\n case \"world2\":\n case \"world3\":\n case \"tangent\":\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\n return this._type;\n case \"color\":\n case \"instanceColor\":\n case \"particle_color\":\n case \"particle_texturemask\":\n this._type = NodeMaterialBlockConnectionPointTypes.Color4;\n return this._type;\n }\n }\n if (this.isSystemValue) {\n switch (this._systemValue) {\n case NodeMaterialSystemValues.World:\n case NodeMaterialSystemValues.WorldView:\n case NodeMaterialSystemValues.WorldViewProjection:\n case NodeMaterialSystemValues.View:\n case NodeMaterialSystemValues.ViewProjection:\n case NodeMaterialSystemValues.Projection:\n this._type = NodeMaterialBlockConnectionPointTypes.Matrix;\n return this._type;\n case NodeMaterialSystemValues.CameraPosition:\n this._type = NodeMaterialBlockConnectionPointTypes.Vector3;\n return this._type;\n case NodeMaterialSystemValues.FogColor:\n this._type = NodeMaterialBlockConnectionPointTypes.Color3;\n return this._type;\n case NodeMaterialSystemValues.DeltaTime:\n case NodeMaterialSystemValues.MaterialAlpha:\n this._type = NodeMaterialBlockConnectionPointTypes.Float;\n return this._type;\n case NodeMaterialSystemValues.CameraParameters:\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\n return this._type;\n }\n }\n }\n return this._type;\n }\n /**\n * Creates a new InputBlock\n * @param name defines the block name\n * @param target defines the target of that block (Vertex by default)\n * @param type defines the type of the input (can be set to NodeMaterialBlockConnectionPointTypes.AutoDetect)\n */\n constructor(name, target = NodeMaterialBlockTargets.Vertex, type = NodeMaterialBlockConnectionPointTypes.AutoDetect) {\n super(name, target, false);\n this._mode = NodeMaterialBlockConnectionPointMode.Undefined;\n this._animationType = AnimatedInputBlockTypes.None;\n /** Gets or set a value used to limit the range of float values */\n this.min = 0;\n /** Gets or set a value used to limit the range of float values */\n this.max = 0;\n /** Gets or set a value indicating that this input can only get 0 and 1 values */\n this.isBoolean = false;\n /** Gets or sets a value used by the Node Material editor to determine how to configure the current value if it is a matrix */\n this.matrixMode = 0;\n /** @internal */\n this._systemValue = null;\n /** Gets or sets a boolean indicating that the value of this input will not change after a build */\n this.isConstant = false;\n /** Gets or sets the group to use to display this block in the Inspector */\n this.groupInInspector = \"\";\n /** Gets an observable raised when the value is changed */\n this.onValueChangedObservable = new Observable$1();\n /** Gets or sets a boolean indicating if content needs to be converted to gamma space (for color3/4 only) */\n this.convertToGammaSpace = false;\n /** Gets or sets a boolean indicating if content needs to be converted to linear space (for color3/4 only) */\n this.convertToLinearSpace = false;\n this._type = type;\n this.setDefaultValue();\n this.registerOutput(\"output\", type);\n }\n /**\n * Validates if a name is a reserve word.\n * @param newName the new name to be given to the node.\n * @returns false if the name is a reserve word, else true.\n */\n validateBlockName(newName) {\n if (!this.isAttribute) {\n return super.validateBlockName(newName);\n }\n return true;\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n /**\n * Set the source of this connection point to a vertex attribute\n * @param attributeName defines the attribute name (position, uv, normal, etc...). If not specified it will take the connection point name\n * @returns the current connection point\n */\n setAsAttribute(attributeName) {\n this._mode = NodeMaterialBlockConnectionPointMode.Attribute;\n if (attributeName) {\n this.name = attributeName;\n }\n return this;\n }\n /**\n * Set the source of this connection point to a system value\n * @param value define the system value to use (world, view, etc...) or null to switch to manual value\n * @returns the current connection point\n */\n setAsSystemValue(value) {\n this.systemValue = value;\n return this;\n }\n /**\n * Gets or sets the value of that point.\n * Please note that this value will be ignored if valueCallback is defined\n */\n get value() {\n return this._storedValue;\n }\n set value(value) {\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\n if (this.isBoolean) {\n value = value ? 1 : 0;\n }\n else if (this.min !== this.max) {\n value = Math.max(this.min, value);\n value = Math.min(this.max, value);\n }\n }\n this._storedValue = value;\n this._mode = NodeMaterialBlockConnectionPointMode.Uniform;\n this.onValueChangedObservable.notifyObservers(this);\n }\n /**\n * Gets or sets a callback used to get the value of that point.\n * Please note that setting this value will force the connection point to ignore the value property\n */\n get valueCallback() {\n return this._valueCallback;\n }\n set valueCallback(value) {\n this._valueCallback = value;\n this._mode = NodeMaterialBlockConnectionPointMode.Uniform;\n }\n /**\n * Gets or sets the associated variable name in the shader\n */\n get associatedVariableName() {\n return this._associatedVariableName;\n }\n set associatedVariableName(value) {\n this._associatedVariableName = value;\n }\n /** Gets or sets the type of animation applied to the input */\n get animationType() {\n return this._animationType;\n }\n set animationType(value) {\n this._animationType = value;\n }\n /**\n * Gets a boolean indicating that this connection point not defined yet\n */\n get isUndefined() {\n return this._mode === NodeMaterialBlockConnectionPointMode.Undefined;\n }\n /**\n * Gets or sets a boolean indicating that this connection point is coming from an uniform.\n * In this case the connection point name must be the name of the uniform to use.\n * Can only be set on inputs\n */\n get isUniform() {\n return this._mode === NodeMaterialBlockConnectionPointMode.Uniform;\n }\n set isUniform(value) {\n this._mode = value ? NodeMaterialBlockConnectionPointMode.Uniform : NodeMaterialBlockConnectionPointMode.Undefined;\n this.associatedVariableName = \"\";\n }\n /**\n * Gets or sets a boolean indicating that this connection point is coming from an attribute.\n * In this case the connection point name must be the name of the attribute to use\n * Can only be set on inputs\n */\n get isAttribute() {\n return this._mode === NodeMaterialBlockConnectionPointMode.Attribute;\n }\n set isAttribute(value) {\n this._mode = value ? NodeMaterialBlockConnectionPointMode.Attribute : NodeMaterialBlockConnectionPointMode.Undefined;\n this.associatedVariableName = \"\";\n }\n /**\n * Gets or sets a boolean indicating that this connection point is generating a varying variable.\n * Can only be set on exit points\n */\n get isVarying() {\n return this._mode === NodeMaterialBlockConnectionPointMode.Varying;\n }\n set isVarying(value) {\n this._mode = value ? NodeMaterialBlockConnectionPointMode.Varying : NodeMaterialBlockConnectionPointMode.Undefined;\n this.associatedVariableName = \"\";\n }\n /**\n * Gets a boolean indicating that the current connection point is a system value\n */\n get isSystemValue() {\n return this._systemValue != null;\n }\n /**\n * Gets or sets the current well known value or null if not defined as a system value\n */\n get systemValue() {\n return this._systemValue;\n }\n set systemValue(value) {\n this._mode = NodeMaterialBlockConnectionPointMode.Uniform;\n this.associatedVariableName = \"\";\n this._systemValue = value;\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"InputBlock\";\n }\n /**\n * Animate the input if animationType !== None\n * @param scene defines the rendering scene\n */\n animate(scene) {\n switch (this._animationType) {\n case AnimatedInputBlockTypes.Time: {\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\n this.value += scene.getAnimationRatio() * 0.01;\n }\n break;\n }\n case AnimatedInputBlockTypes.RealTime: {\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\n this.value = (PrecisionDate.Now - scene.getEngine().startTime) / 1000;\n }\n break;\n }\n }\n }\n _emitDefine(define) {\n if (define[0] === \"!\") {\n return `#ifndef ${define.substring(1)}\\n`;\n }\n return `#ifdef ${define}\\n`;\n }\n initialize() {\n this.associatedVariableName = \"\";\n }\n /**\n * Set the input block to its default value (based on its type)\n */\n setDefaultValue() {\n switch (this.type) {\n case NodeMaterialBlockConnectionPointTypes.Float:\n this.value = 0;\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n this.value = Vector2.Zero();\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n this.value = Vector3.Zero();\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector4:\n this.value = Vector4.Zero();\n break;\n case NodeMaterialBlockConnectionPointTypes.Color3:\n this.value = Color3.White();\n break;\n case NodeMaterialBlockConnectionPointTypes.Color4:\n this.value = new Color4(1, 1, 1, 1);\n break;\n case NodeMaterialBlockConnectionPointTypes.Matrix:\n this.value = Matrix.Identity();\n break;\n }\n }\n _emitConstant(state) {\n switch (this.type) {\n case NodeMaterialBlockConnectionPointTypes.Float:\n return `${state._emitFloat(this.value)}`;\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n return `vec2(${this.value.x}, ${this.value.y})`;\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n return `vec3(${this.value.x}, ${this.value.y}, ${this.value.z})`;\n case NodeMaterialBlockConnectionPointTypes.Vector4:\n return `vec4(${this.value.x}, ${this.value.y}, ${this.value.z}, ${this.value.w})`;\n case NodeMaterialBlockConnectionPointTypes.Color3:\n TmpColors.Color3[0].set(this.value.r, this.value.g, this.value.b);\n if (this.convertToGammaSpace) {\n TmpColors.Color3[0].toGammaSpaceToRef(TmpColors.Color3[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\n }\n if (this.convertToLinearSpace) {\n TmpColors.Color3[0].toLinearSpaceToRef(TmpColors.Color3[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\n }\n return `vec3(${TmpColors.Color3[0].r}, ${TmpColors.Color3[0].g}, ${TmpColors.Color3[0].b})`;\n case NodeMaterialBlockConnectionPointTypes.Color4:\n TmpColors.Color4[0].set(this.value.r, this.value.g, this.value.b, this.value.a);\n if (this.convertToGammaSpace) {\n TmpColors.Color4[0].toGammaSpaceToRef(TmpColors.Color4[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\n }\n if (this.convertToLinearSpace) {\n TmpColors.Color4[0].toLinearSpaceToRef(TmpColors.Color4[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\n }\n return `vec4(${TmpColors.Color4[0].r}, ${TmpColors.Color4[0].g}, ${TmpColors.Color4[0].b}, ${TmpColors.Color4[0].a})`;\n }\n return \"\";\n }\n /** @internal */\n get _noContextSwitch() {\n return attributeInFragmentOnly[this.name];\n }\n _emit(state, define) {\n var _a;\n // Uniforms\n if (this.isUniform) {\n if (!this.associatedVariableName) {\n this.associatedVariableName = state._getFreeVariableName(\"u_\" + this.name);\n }\n if (this.isConstant) {\n if (state.constants.indexOf(this.associatedVariableName) !== -1) {\n return;\n }\n state.constants.push(this.associatedVariableName);\n state._constantDeclaration += this._declareOutput(this.output, state) + ` = ${this._emitConstant(state)};\\n`;\n return;\n }\n if (state.uniforms.indexOf(this.associatedVariableName) !== -1) {\n return;\n }\n state.uniforms.push(this.associatedVariableName);\n if (define) {\n state._uniformDeclaration += this._emitDefine(define);\n }\n state._uniformDeclaration += `uniform ${state._getGLType(this.type)} ${this.associatedVariableName};\\n`;\n if (define) {\n state._uniformDeclaration += `#endif\\n`;\n }\n // well known\n const hints = state.sharedData.hints;\n if (this._systemValue !== null && this._systemValue !== undefined) {\n switch (this._systemValue) {\n case NodeMaterialSystemValues.WorldView:\n hints.needWorldViewMatrix = true;\n break;\n case NodeMaterialSystemValues.WorldViewProjection:\n hints.needWorldViewProjectionMatrix = true;\n break;\n }\n }\n else {\n if (this._animationType !== AnimatedInputBlockTypes.None) {\n state.sharedData.animatedInputs.push(this);\n }\n }\n return;\n }\n // Attribute\n if (this.isAttribute) {\n this.associatedVariableName = (_a = remapAttributeName[this.name]) !== null && _a !== void 0 ? _a : this.name;\n if (this.target === NodeMaterialBlockTargets.Vertex && state._vertexState) {\n // Attribute for fragment need to be carried over by varyings\n if (attributeInFragmentOnly[this.name]) {\n if (attributeAsUniform[this.name]) {\n state._emitUniformFromString(this.associatedVariableName, state._getGLType(this.type), define);\n }\n else {\n state._emitVaryingFromString(this.associatedVariableName, state._getGLType(this.type), define);\n }\n }\n else {\n this._emit(state._vertexState, define);\n }\n return;\n }\n if (state.attributes.indexOf(this.associatedVariableName) !== -1) {\n return;\n }\n state.attributes.push(this.associatedVariableName);\n if (attributeInFragmentOnly[this.name]) {\n if (attributeAsUniform[this.name]) {\n state._emitUniformFromString(this.associatedVariableName, state._getGLType(this.type), define);\n }\n else {\n state._emitVaryingFromString(this.associatedVariableName, state._getGLType(this.type), define);\n }\n }\n else {\n if (define) {\n state._attributeDeclaration += this._emitDefine(define);\n }\n state._attributeDeclaration += `attribute ${state._getGLType(this.type)} ${this.associatedVariableName};\\n`;\n if (define) {\n state._attributeDeclaration += `#endif\\n`;\n }\n }\n }\n }\n /**\n * @internal\n */\n _transmitWorld(effect, world, worldView, worldViewProjection) {\n if (!this._systemValue) {\n return;\n }\n const variableName = this.associatedVariableName;\n switch (this._systemValue) {\n case NodeMaterialSystemValues.World:\n effect.setMatrix(variableName, world);\n break;\n case NodeMaterialSystemValues.WorldView:\n effect.setMatrix(variableName, worldView);\n break;\n case NodeMaterialSystemValues.WorldViewProjection:\n effect.setMatrix(variableName, worldViewProjection);\n break;\n }\n }\n /**\n * @internal\n */\n _transmit(effect, scene, material) {\n if (this.isAttribute) {\n return;\n }\n const variableName = this.associatedVariableName;\n if (this._systemValue) {\n switch (this._systemValue) {\n case NodeMaterialSystemValues.World:\n case NodeMaterialSystemValues.WorldView:\n case NodeMaterialSystemValues.WorldViewProjection:\n return;\n case NodeMaterialSystemValues.View:\n effect.setMatrix(variableName, scene.getViewMatrix());\n break;\n case NodeMaterialSystemValues.Projection:\n effect.setMatrix(variableName, scene.getProjectionMatrix());\n break;\n case NodeMaterialSystemValues.ViewProjection:\n effect.setMatrix(variableName, scene.getTransformMatrix());\n break;\n case NodeMaterialSystemValues.CameraPosition:\n scene.bindEyePosition(effect, variableName, true);\n break;\n case NodeMaterialSystemValues.FogColor:\n effect.setColor3(variableName, scene.fogColor);\n break;\n case NodeMaterialSystemValues.DeltaTime:\n effect.setFloat(variableName, scene.deltaTime / 1000.0);\n break;\n case NodeMaterialSystemValues.CameraParameters:\n if (scene.activeCamera) {\n effect.setFloat4(variableName, scene.getEngine().hasOriginBottomLeft ? -1 : 1, scene.activeCamera.minZ, scene.activeCamera.maxZ, 1 / scene.activeCamera.maxZ);\n }\n break;\n case NodeMaterialSystemValues.MaterialAlpha:\n effect.setFloat(variableName, material.alpha);\n break;\n }\n return;\n }\n const value = this._valueCallback ? this._valueCallback() : this._storedValue;\n if (value === null) {\n return;\n }\n switch (this.type) {\n case NodeMaterialBlockConnectionPointTypes.Float:\n effect.setFloat(variableName, value);\n break;\n case NodeMaterialBlockConnectionPointTypes.Int:\n effect.setInt(variableName, value);\n break;\n case NodeMaterialBlockConnectionPointTypes.Color3:\n TmpColors.Color3[0].set(this.value.r, this.value.g, this.value.b);\n if (this.convertToGammaSpace) {\n TmpColors.Color3[0].toGammaSpaceToRef(TmpColors.Color3[0], scene.getEngine().useExactSrgbConversions);\n }\n if (this.convertToLinearSpace) {\n TmpColors.Color3[0].toLinearSpaceToRef(TmpColors.Color3[0], scene.getEngine().useExactSrgbConversions);\n }\n effect.setColor3(variableName, TmpColors.Color3[0]);\n break;\n case NodeMaterialBlockConnectionPointTypes.Color4:\n TmpColors.Color4[0].set(this.value.r, this.value.g, this.value.b, this.value.a);\n if (this.convertToGammaSpace) {\n TmpColors.Color4[0].toGammaSpaceToRef(TmpColors.Color4[0], scene.getEngine().useExactSrgbConversions);\n }\n if (this.convertToLinearSpace) {\n TmpColors.Color4[0].toLinearSpaceToRef(TmpColors.Color4[0], scene.getEngine().useExactSrgbConversions);\n }\n effect.setDirectColor4(variableName, TmpColors.Color4[0]);\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n effect.setVector2(variableName, value);\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n effect.setVector3(variableName, value);\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector4:\n effect.setVector4(variableName, value);\n break;\n case NodeMaterialBlockConnectionPointTypes.Matrix:\n effect.setMatrix(variableName, value);\n break;\n }\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (this.isUniform || this.isSystemValue) {\n state.sharedData.inputBlocks.push(this);\n }\n this._emit(state);\n }\n _dumpPropertiesCode() {\n const variableName = this._codeVariableName;\n if (this.isAttribute) {\n return super._dumpPropertiesCode() + `${variableName}.setAsAttribute(\"${this.name}\");\\n`;\n }\n if (this.isSystemValue) {\n return super._dumpPropertiesCode() + `${variableName}.setAsSystemValue(BABYLON.NodeMaterialSystemValues.${NodeMaterialSystemValues[this._systemValue]});\\n`;\n }\n if (this.isUniform) {\n const codes = [];\n let valueString = \"\";\n switch (this.type) {\n case NodeMaterialBlockConnectionPointTypes.Float:\n valueString = `${this.value}`;\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector2:\n valueString = `new BABYLON.Vector2(${this.value.x}, ${this.value.y})`;\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector3:\n valueString = `new BABYLON.Vector3(${this.value.x}, ${this.value.y}, ${this.value.z})`;\n break;\n case NodeMaterialBlockConnectionPointTypes.Vector4:\n valueString = `new BABYLON.Vector4(${this.value.x}, ${this.value.y}, ${this.value.z}, ${this.value.w})`;\n break;\n case NodeMaterialBlockConnectionPointTypes.Color3:\n valueString = `new BABYLON.Color3(${this.value.r}, ${this.value.g}, ${this.value.b})`;\n if (this.convertToGammaSpace) {\n valueString += \".toGammaSpace()\";\n }\n if (this.convertToLinearSpace) {\n valueString += \".toLinearSpace()\";\n }\n break;\n case NodeMaterialBlockConnectionPointTypes.Color4:\n valueString = `new BABYLON.Color4(${this.value.r}, ${this.value.g}, ${this.value.b}, ${this.value.a})`;\n if (this.convertToGammaSpace) {\n valueString += \".toGammaSpace()\";\n }\n if (this.convertToLinearSpace) {\n valueString += \".toLinearSpace()\";\n }\n break;\n case NodeMaterialBlockConnectionPointTypes.Matrix:\n valueString = `BABYLON.Matrix.FromArray([${this.value.m}])`;\n break;\n }\n // Common Property \"Value\"\n codes.push(`${variableName}.value = ${valueString}`);\n // Float-Value-Specific Properties\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\n codes.push(`${variableName}.min = ${this.min}`, `${variableName}.max = ${this.max}`, `${variableName}.isBoolean = ${this.isBoolean}`, `${variableName}.matrixMode = ${this.matrixMode}`, `${variableName}.animationType = BABYLON.AnimatedInputBlockTypes.${AnimatedInputBlockTypes[this.animationType]}`);\n }\n // Common Property \"Type\"\n codes.push(`${variableName}.isConstant = ${this.isConstant}`);\n codes.push(\"\");\n return super._dumpPropertiesCode() + codes.join(\";\\n\");\n }\n return super._dumpPropertiesCode();\n }\n dispose() {\n this.onValueChangedObservable.clear();\n super.dispose();\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.type = this.type;\n serializationObject.mode = this._mode;\n serializationObject.systemValue = this._systemValue;\n serializationObject.animationType = this._animationType;\n serializationObject.min = this.min;\n serializationObject.max = this.max;\n serializationObject.isBoolean = this.isBoolean;\n serializationObject.matrixMode = this.matrixMode;\n serializationObject.isConstant = this.isConstant;\n serializationObject.groupInInspector = this.groupInInspector;\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\n if (this._storedValue != null && this._mode === NodeMaterialBlockConnectionPointMode.Uniform) {\n if (this._storedValue.asArray) {\n serializationObject.valueType = \"BABYLON.\" + this._storedValue.getClassName();\n serializationObject.value = this._storedValue.asArray();\n }\n else {\n serializationObject.valueType = \"number\";\n serializationObject.value = this._storedValue;\n }\n }\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n this._mode = serializationObject.mode;\n super._deserialize(serializationObject, scene, rootUrl);\n this._type = serializationObject.type;\n this._systemValue = serializationObject.systemValue || serializationObject.wellKnownValue;\n this._animationType = serializationObject.animationType;\n this.min = serializationObject.min || 0;\n this.max = serializationObject.max || 0;\n this.isBoolean = !!serializationObject.isBoolean;\n this.matrixMode = serializationObject.matrixMode || 0;\n this.isConstant = !!serializationObject.isConstant;\n this.groupInInspector = serializationObject.groupInInspector || \"\";\n this.convertToGammaSpace = !!serializationObject.convertToGammaSpace;\n this.convertToLinearSpace = !!serializationObject.convertToLinearSpace;\n // Tangents back compat\n if (serializationObject.name === \"tangent\" &&\n serializationObject.mode === NodeMaterialBlockConnectionPointMode.Attribute &&\n serializationObject.type === NodeMaterialBlockConnectionPointTypes.Vector3) {\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\n }\n if (!serializationObject.valueType) {\n return;\n }\n if (serializationObject.valueType === \"number\") {\n this._storedValue = serializationObject.value;\n }\n else {\n const valueType = GetClass(serializationObject.valueType);\n if (valueType) {\n this._storedValue = valueType.FromArray(serializationObject.value);\n }\n }\n }\n }\n RegisterClass(\"BABYLON.InputBlock\", InputBlock);\n\n /**\n * Base block used as input for post process\n */\n class CurrentScreenBlock extends NodeMaterialBlock {\n /**\n * Create a new CurrentScreenBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.VertexAndFragment);\n this._samplerName = \"textureSampler\";\n /**\n * Gets or sets a boolean indicating if content needs to be converted to gamma space\n */\n this.convertToGammaSpace = false;\n /**\n * Gets or sets a boolean indicating if content needs to be converted to linear space\n */\n this.convertToLinearSpace = false;\n this._isUnique = false;\n this.registerInput(\"uv\", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);\n this.registerOutput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"rgb\", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"r\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"g\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"b\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"a\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this._inputs[0].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);\n this._inputs[0]._prioritizeVertex = false;\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"CurrentScreenBlock\";\n }\n /**\n * Gets the uv input component\n */\n get uv() {\n return this._inputs[0];\n }\n /**\n * Gets the rgba output component\n */\n get rgba() {\n return this._outputs[0];\n }\n /**\n * Gets the rgb output component\n */\n get rgb() {\n return this._outputs[1];\n }\n /**\n * Gets the r output component\n */\n get r() {\n return this._outputs[2];\n }\n /**\n * Gets the g output component\n */\n get g() {\n return this._outputs[3];\n }\n /**\n * Gets the b output component\n */\n get b() {\n return this._outputs[4];\n }\n /**\n * Gets the a output component\n */\n get a() {\n return this._outputs[5];\n }\n /**\n * Initialize the block and prepare the context for build\n * @param state defines the state that will be used for the build\n */\n initialize(state) {\n state._excludeVariableName(\"textureSampler\");\n }\n get target() {\n if (!this.uv.isConnected) {\n return NodeMaterialBlockTargets.VertexAndFragment;\n }\n if (this.uv.sourceBlock.isInput) {\n return NodeMaterialBlockTargets.VertexAndFragment;\n }\n return NodeMaterialBlockTargets.Fragment;\n }\n prepareDefines(mesh, nodeMaterial, defines) {\n defines.setValue(this._linearDefineName, this.convertToGammaSpace, true);\n defines.setValue(this._gammaDefineName, this.convertToLinearSpace, true);\n }\n isReady() {\n if (this.texture && !this.texture.isReadyOrNotBlocking()) {\n return false;\n }\n return true;\n }\n _injectVertexCode(state) {\n const uvInput = this.uv;\n if (uvInput.connectedPoint.ownerBlock.isInput) {\n const uvInputOwnerBlock = uvInput.connectedPoint.ownerBlock;\n if (!uvInputOwnerBlock.isAttribute) {\n state._emitUniformFromString(uvInput.associatedVariableName, \"vec2\");\n }\n }\n this._mainUVName = \"vMain\" + uvInput.associatedVariableName;\n state._emitVaryingFromString(this._mainUVName, \"vec2\");\n state.compilationString += `${this._mainUVName} = ${uvInput.associatedVariableName}.xy;\\n`;\n if (!this._outputs.some((o) => o.isConnectedInVertexShader)) {\n return;\n }\n this._writeTextureRead(state, true);\n for (const output of this._outputs) {\n if (output.hasEndpoints) {\n this._writeOutput(state, output, output.name, true);\n }\n }\n }\n _writeTextureRead(state, vertexMode = false) {\n const uvInput = this.uv;\n if (vertexMode) {\n if (state.target === NodeMaterialBlockTargets.Fragment) {\n return;\n }\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${uvInput.associatedVariableName});\\n`;\n return;\n }\n if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${uvInput.associatedVariableName});\\n`;\n return;\n }\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${this._mainUVName});\\n`;\n }\n _writeOutput(state, output, swizzle, vertexMode = false) {\n if (vertexMode) {\n if (state.target === NodeMaterialBlockTargets.Fragment) {\n return;\n }\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\n return;\n }\n if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\n return;\n }\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\n state.compilationString += `#ifdef ${this._linearDefineName}\\n`;\n state.compilationString += `${output.associatedVariableName} = toGammaSpace(${output.associatedVariableName});\\n`;\n state.compilationString += `#endif\\n`;\n state.compilationString += `#ifdef ${this._gammaDefineName}\\n`;\n state.compilationString += `${output.associatedVariableName} = toLinearSpace(${output.associatedVariableName});\\n`;\n state.compilationString += `#endif\\n`;\n }\n _buildBlock(state) {\n super._buildBlock(state);\n this._tempTextureRead = state._getFreeVariableName(\"tempTextureRead\");\n if (state.sharedData.blockingBlocks.indexOf(this) < 0) {\n state.sharedData.blockingBlocks.push(this);\n }\n if (state.sharedData.textureBlocks.indexOf(this) < 0) {\n state.sharedData.textureBlocks.push(this);\n }\n if (state.sharedData.blocksWithDefines.indexOf(this) < 0) {\n state.sharedData.blocksWithDefines.push(this);\n }\n if (state.target !== NodeMaterialBlockTargets.Fragment) {\n // Vertex\n state._emit2DSampler(this._samplerName);\n this._injectVertexCode(state);\n return;\n }\n // Fragment\n if (!this._outputs.some((o) => o.isConnectedInFragmentShader)) {\n return;\n }\n state._emit2DSampler(this._samplerName);\n this._linearDefineName = state._getFreeDefineName(\"ISLINEAR\");\n this._gammaDefineName = state._getFreeDefineName(\"ISGAMMA\");\n const comments = `//${this.name}`;\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\n this._writeTextureRead(state);\n for (const output of this._outputs) {\n if (output.hasEndpoints) {\n this._writeOutput(state, output, output.name);\n }\n }\n return this;\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\n if (this.texture && !this.texture.isRenderTarget) {\n serializationObject.texture = this.texture.serialize();\n }\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n super._deserialize(serializationObject, scene, rootUrl);\n this.convertToGammaSpace = serializationObject.convertToGammaSpace;\n this.convertToLinearSpace = !!serializationObject.convertToLinearSpace;\n if (serializationObject.texture) {\n rootUrl = serializationObject.texture.url.indexOf(\"data:\") === 0 ? \"\" : rootUrl;\n this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl);\n }\n }\n }\n RegisterClass(\"BABYLON.CurrentScreenBlock\", CurrentScreenBlock);\n\n /**\n * Base block used for the particle texture\n */\n class ParticleTextureBlock extends NodeMaterialBlock {\n /**\n * Create a new ParticleTextureBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Fragment);\n this._samplerName = \"diffuseSampler\";\n /**\n * Gets or sets a boolean indicating if content needs to be converted to gamma space\n */\n this.convertToGammaSpace = false;\n /**\n * Gets or sets a boolean indicating if content needs to be converted to linear space\n */\n this.convertToLinearSpace = false;\n this._isUnique = false;\n this.registerInput(\"uv\", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);\n this.registerOutput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"rgb\", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"r\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"g\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"b\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this.registerOutput(\"a\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\n this._inputs[0].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"ParticleTextureBlock\";\n }\n /**\n * Gets the uv input component\n */\n get uv() {\n return this._inputs[0];\n }\n /**\n * Gets the rgba output component\n */\n get rgba() {\n return this._outputs[0];\n }\n /**\n * Gets the rgb output component\n */\n get rgb() {\n return this._outputs[1];\n }\n /**\n * Gets the r output component\n */\n get r() {\n return this._outputs[2];\n }\n /**\n * Gets the g output component\n */\n get g() {\n return this._outputs[3];\n }\n /**\n * Gets the b output component\n */\n get b() {\n return this._outputs[4];\n }\n /**\n * Gets the a output component\n */\n get a() {\n return this._outputs[5];\n }\n /**\n * Initialize the block and prepare the context for build\n * @param state defines the state that will be used for the build\n */\n initialize(state) {\n state._excludeVariableName(\"diffuseSampler\");\n }\n autoConfigure(material) {\n if (!this.uv.isConnected) {\n let uvInput = material.getInputBlockByPredicate((b) => b.isAttribute && b.name === \"particle_uv\");\n if (!uvInput) {\n uvInput = new InputBlock(\"uv\");\n uvInput.setAsAttribute(\"particle_uv\");\n }\n uvInput.output.connectTo(this.uv);\n }\n }\n prepareDefines(mesh, nodeMaterial, defines) {\n defines.setValue(this._linearDefineName, this.convertToGammaSpace, true);\n defines.setValue(this._gammaDefineName, this.convertToLinearSpace, true);\n }\n isReady() {\n if (this.texture && !this.texture.isReadyOrNotBlocking()) {\n return false;\n }\n return true;\n }\n _writeOutput(state, output, swizzle) {\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\n state.compilationString += `#ifdef ${this._linearDefineName}\\n`;\n state.compilationString += `${output.associatedVariableName} = toGammaSpace(${output.associatedVariableName});\\n`;\n state.compilationString += `#endif\\n`;\n state.compilationString += `#ifdef ${this._gammaDefineName}\\n`;\n state.compilationString += `${output.associatedVariableName} = toLinearSpace(${output.associatedVariableName});\\n`;\n state.compilationString += `#endif\\n`;\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (state.target === NodeMaterialBlockTargets.Vertex) {\n return;\n }\n this._tempTextureRead = state._getFreeVariableName(\"tempTextureRead\");\n state._emit2DSampler(this._samplerName);\n state.sharedData.blockingBlocks.push(this);\n state.sharedData.textureBlocks.push(this);\n state.sharedData.blocksWithDefines.push(this);\n this._linearDefineName = state._getFreeDefineName(\"ISLINEAR\");\n this._gammaDefineName = state._getFreeDefineName(\"ISGAMMA\");\n const comments = `//${this.name}`;\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${this.uv.associatedVariableName});\\n`;\n for (const output of this._outputs) {\n if (output.hasEndpoints) {\n this._writeOutput(state, output, output.name);\n }\n }\n return this;\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\n if (this.texture && !this.texture.isRenderTarget) {\n serializationObject.texture = this.texture.serialize();\n }\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n super._deserialize(serializationObject, scene, rootUrl);\n this.convertToGammaSpace = serializationObject.convertToGammaSpace;\n this.convertToLinearSpace = !!serializationObject.convertToLinearSpace;\n if (serializationObject.texture) {\n rootUrl = serializationObject.texture.url.indexOf(\"data:\") === 0 ? \"\" : rootUrl;\n this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl);\n }\n }\n }\n RegisterClass(\"BABYLON.ParticleTextureBlock\", ParticleTextureBlock);\n\n /**\n * Block used for the particle ramp gradient section\n */\n class ParticleRampGradientBlock extends NodeMaterialBlock {\n /**\n * Create a new ParticleRampGradientBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Fragment);\n this._isUnique = true;\n this.registerInput(\"color\", NodeMaterialBlockConnectionPointTypes.Color4, false, NodeMaterialBlockTargets.Fragment);\n this.registerOutput(\"rampColor\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Fragment);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"ParticleRampGradientBlock\";\n }\n /**\n * Gets the color input component\n */\n get color() {\n return this._inputs[0];\n }\n /**\n * Gets the rampColor output component\n */\n get rampColor() {\n return this._outputs[0];\n }\n /**\n * Initialize the block and prepare the context for build\n * @param state defines the state that will be used for the build\n */\n initialize(state) {\n state._excludeVariableName(\"remapRanges\");\n state._excludeVariableName(\"rampSampler\");\n state._excludeVariableName(\"baseColor\");\n state._excludeVariableName(\"alpha\");\n state._excludeVariableName(\"remappedColorIndex\");\n state._excludeVariableName(\"rampColor\");\n state._excludeVariableName(\"finalAlpha\");\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (state.target === NodeMaterialBlockTargets.Vertex) {\n return;\n }\n state._emit2DSampler(\"rampSampler\");\n state._emitVaryingFromString(\"remapRanges\", \"vec4\", \"RAMPGRADIENT\");\n state.compilationString += `\r\n #ifdef RAMPGRADIENT\r\n vec4 baseColor = ${this.color.associatedVariableName};\r\n float alpha = ${this.color.associatedVariableName}.a;\r\n\r\n float remappedColorIndex = clamp((alpha - remapRanges.x) / remapRanges.y, 0.0, 1.0);\r\n\r\n vec4 rampColor = texture2D(rampSampler, vec2(1.0 - remappedColorIndex, 0.));\r\n baseColor.rgb *= rampColor.rgb;\r\n\r\n // Remapped alpha\r\n float finalAlpha = baseColor.a;\r\n baseColor.a = clamp((alpha * rampColor.a - remapRanges.z) / remapRanges.w, 0.0, 1.0);\r\n\r\n ${this._declareOutput(this.rampColor, state)} = baseColor;\r\n #else\r\n ${this._declareOutput(this.rampColor, state)} = ${this.color.associatedVariableName};\r\n #endif\r\n `;\n return this;\n }\n }\n RegisterClass(\"BABYLON.ParticleRampGradientBlock\", ParticleRampGradientBlock);\n\n /**\n * Block used for the particle blend multiply section\n */\n class ParticleBlendMultiplyBlock extends NodeMaterialBlock {\n /**\n * Create a new ParticleBlendMultiplyBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Fragment);\n this._isUnique = true;\n this.registerInput(\"color\", NodeMaterialBlockConnectionPointTypes.Color4, false, NodeMaterialBlockTargets.Fragment);\n this.registerInput(\"alphaTexture\", NodeMaterialBlockConnectionPointTypes.Float, false, NodeMaterialBlockTargets.Fragment);\n this.registerInput(\"alphaColor\", NodeMaterialBlockConnectionPointTypes.Float, false, NodeMaterialBlockTargets.Fragment);\n this.registerOutput(\"blendColor\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Fragment);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"ParticleBlendMultiplyBlock\";\n }\n /**\n * Gets the color input component\n */\n get color() {\n return this._inputs[0];\n }\n /**\n * Gets the alphaTexture input component\n */\n get alphaTexture() {\n return this._inputs[1];\n }\n /**\n * Gets the alphaColor input component\n */\n get alphaColor() {\n return this._inputs[2];\n }\n /**\n * Gets the blendColor output component\n */\n get blendColor() {\n return this._outputs[0];\n }\n /**\n * Initialize the block and prepare the context for build\n * @param state defines the state that will be used for the build\n */\n initialize(state) {\n state._excludeVariableName(\"sourceAlpha\");\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (state.target === NodeMaterialBlockTargets.Vertex) {\n return;\n }\n state.compilationString += `\r\n #ifdef BLENDMULTIPLYMODE\r\n ${this._declareOutput(this.blendColor, state)};\r\n float sourceAlpha = ${this.alphaColor.associatedVariableName} * ${this.alphaTexture.associatedVariableName};\r\n ${this.blendColor.associatedVariableName}.rgb = ${this.color.associatedVariableName}.rgb * sourceAlpha + vec3(1.0) * (1.0 - sourceAlpha);\r\n ${this.blendColor.associatedVariableName}.a = ${this.color.associatedVariableName}.a;\r\n #else\r\n ${this._declareOutput(this.blendColor, state)} = ${this.color.associatedVariableName};\r\n #endif\r\n `;\n return this;\n }\n }\n RegisterClass(\"BABYLON.ParticleBlendMultiplyBlock\", ParticleBlendMultiplyBlock);\n\n /**\n * Block used to create a Vector2/3/4 out of individual inputs (one for each component)\n */\n class VectorMergerBlock extends NodeMaterialBlock {\n /**\n * Create a new VectorMergerBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n /**\n * Gets or sets the swizzle for x (meaning which component to affect to the output.x)\n */\n this.xSwizzle = \"x\";\n /**\n * Gets or sets the swizzle for y (meaning which component to affect to the output.y)\n */\n this.ySwizzle = \"y\";\n /**\n * Gets or sets the swizzle for z (meaning which component to affect to the output.z)\n */\n this.zSwizzle = \"z\";\n /**\n * Gets or sets the swizzle for w (meaning which component to affect to the output.w)\n */\n this.wSwizzle = \"w\";\n this.registerInput(\"xyzw \", NodeMaterialBlockConnectionPointTypes.Vector4, true);\n this.registerInput(\"xyz \", NodeMaterialBlockConnectionPointTypes.Vector3, true);\n this.registerInput(\"xy \", NodeMaterialBlockConnectionPointTypes.Vector2, true);\n this.registerInput(\"zw \", NodeMaterialBlockConnectionPointTypes.Vector2, true);\n this.registerInput(\"x\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerInput(\"y\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerInput(\"z\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerInput(\"w\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerOutput(\"xyzw\", NodeMaterialBlockConnectionPointTypes.Vector4);\n this.registerOutput(\"xyz\", NodeMaterialBlockConnectionPointTypes.Vector3);\n this.registerOutput(\"xy\", NodeMaterialBlockConnectionPointTypes.Vector2);\n this.registerOutput(\"zw\", NodeMaterialBlockConnectionPointTypes.Vector2);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"VectorMergerBlock\";\n }\n /**\n * Gets the xyzw component (input)\n */\n get xyzwIn() {\n return this._inputs[0];\n }\n /**\n * Gets the xyz component (input)\n */\n get xyzIn() {\n return this._inputs[1];\n }\n /**\n * Gets the xy component (input)\n */\n get xyIn() {\n return this._inputs[2];\n }\n /**\n * Gets the zw component (input)\n */\n get zwIn() {\n return this._inputs[3];\n }\n /**\n * Gets the x component (input)\n */\n get x() {\n return this._inputs[4];\n }\n /**\n * Gets the y component (input)\n */\n get y() {\n return this._inputs[5];\n }\n /**\n * Gets the z component (input)\n */\n get z() {\n return this._inputs[6];\n }\n /**\n * Gets the w component (input)\n */\n get w() {\n return this._inputs[7];\n }\n /**\n * Gets the xyzw component (output)\n */\n get xyzw() {\n return this._outputs[0];\n }\n /**\n * Gets the xyz component (output)\n */\n get xyzOut() {\n return this._outputs[1];\n }\n /**\n * Gets the xy component (output)\n */\n get xyOut() {\n return this._outputs[2];\n }\n /**\n * Gets the zw component (output)\n */\n get zwOut() {\n return this._outputs[3];\n }\n /**\n * Gets the xy component (output)\n * @deprecated Please use xyOut instead.\n */\n get xy() {\n return this.xyOut;\n }\n /**\n * Gets the xyz component (output)\n * @deprecated Please use xyzOut instead.\n */\n get xyz() {\n return this.xyzOut;\n }\n _inputRename(name) {\n if (name === \"xyzw \") {\n return \"xyzwIn\";\n }\n if (name === \"xyz \") {\n return \"xyzIn\";\n }\n if (name === \"xy \") {\n return \"xyIn\";\n }\n if (name === \"zw \") {\n return \"zwIn\";\n }\n return name;\n }\n _buildSwizzle(len) {\n const swizzle = this.xSwizzle + this.ySwizzle + this.zSwizzle + this.wSwizzle;\n return \".\" + swizzle.substr(0, len);\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const xInput = this.x;\n const yInput = this.y;\n const zInput = this.z;\n const wInput = this.w;\n const xyInput = this.xyIn;\n const zwInput = this.zwIn;\n const xyzInput = this.xyzIn;\n const xyzwInput = this.xyzwIn;\n const v4Output = this._outputs[0];\n const v3Output = this._outputs[1];\n const v2Output = this._outputs[2];\n const v2CompOutput = this._outputs[3];\n if (xyzwInput.isConnected) {\n if (v4Output.hasEndpoints) {\n state.compilationString += this._declareOutput(v4Output, state) + ` = ${xyzwInput.associatedVariableName}${this._buildSwizzle(4)};\\n`;\n }\n if (v3Output.hasEndpoints) {\n state.compilationString += this._declareOutput(v3Output, state) + ` = ${xyzwInput.associatedVariableName}${this._buildSwizzle(3)};\\n`;\n }\n if (v2Output.hasEndpoints) {\n state.compilationString += this._declareOutput(v2Output, state) + ` = ${xyzwInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\n }\n }\n else if (xyzInput.isConnected) {\n if (v4Output.hasEndpoints) {\n state.compilationString +=\n this._declareOutput(v4Output, state) +\n ` = vec4(${xyzInput.associatedVariableName}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(4)};\\n`;\n }\n if (v3Output.hasEndpoints) {\n state.compilationString += this._declareOutput(v3Output, state) + ` = ${xyzInput.associatedVariableName}${this._buildSwizzle(3)};\\n`;\n }\n if (v2Output.hasEndpoints) {\n state.compilationString += this._declareOutput(v2Output, state) + ` = ${xyzInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\n }\n }\n else if (xyInput.isConnected) {\n if (v4Output.hasEndpoints) {\n if (zwInput.isConnected) {\n state.compilationString +=\n this._declareOutput(v4Output, state) + ` = vec4(${xyInput.associatedVariableName}, ${zwInput.associatedVariableName})${this._buildSwizzle(4)};\\n`;\n }\n else {\n state.compilationString +=\n this._declareOutput(v4Output, state) +\n ` = vec4(${xyInput.associatedVariableName}, ${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(4)};\\n`;\n }\n }\n if (v3Output.hasEndpoints) {\n state.compilationString +=\n this._declareOutput(v3Output, state) +\n ` = vec3(${xyInput.associatedVariableName}, ${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"})${this._buildSwizzle(3)};\\n`;\n }\n if (v2Output.hasEndpoints) {\n state.compilationString += this._declareOutput(v2Output, state) + ` = ${xyInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\n }\n if (v2CompOutput.hasEndpoints) {\n if (zwInput.isConnected) {\n state.compilationString += this._declareOutput(v2CompOutput, state) + ` = ${zwInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\n }\n else {\n state.compilationString +=\n this._declareOutput(v2CompOutput, state) +\n ` = vec2(${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(2)};\\n`;\n }\n }\n }\n else {\n if (v4Output.hasEndpoints) {\n if (zwInput.isConnected) {\n state.compilationString +=\n this._declareOutput(v4Output, state) +\n ` = vec4(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"}, ${zwInput.associatedVariableName})${this._buildSwizzle(4)};\\n`;\n }\n else {\n state.compilationString +=\n this._declareOutput(v4Output, state) +\n ` = vec4(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"}, ${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(4)};\\n`;\n }\n }\n if (v3Output.hasEndpoints) {\n state.compilationString +=\n this._declareOutput(v3Output, state) +\n ` = vec3(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"}, ${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"})${this._buildSwizzle(3)};\\n`;\n }\n if (v2Output.hasEndpoints) {\n state.compilationString +=\n this._declareOutput(v2Output, state) +\n ` = vec2(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"})${this._buildSwizzle(2)};\\n`;\n }\n if (v2CompOutput.hasEndpoints) {\n if (zwInput.isConnected) {\n state.compilationString += this._declareOutput(v2CompOutput, state) + ` = ${zwInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\n }\n else {\n state.compilationString +=\n this._declareOutput(v2CompOutput, state) +\n ` = vec2(${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(2)};\\n`;\n }\n }\n }\n return this;\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.xSwizzle = this.xSwizzle;\n serializationObject.ySwizzle = this.ySwizzle;\n serializationObject.zSwizzle = this.zSwizzle;\n serializationObject.wSwizzle = this.wSwizzle;\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n var _a, _b, _c, _d;\n super._deserialize(serializationObject, scene, rootUrl);\n this.xSwizzle = (_a = serializationObject.xSwizzle) !== null && _a !== void 0 ? _a : \"x\";\n this.ySwizzle = (_b = serializationObject.ySwizzle) !== null && _b !== void 0 ? _b : \"y\";\n this.zSwizzle = (_c = serializationObject.zSwizzle) !== null && _c !== void 0 ? _c : \"z\";\n this.wSwizzle = (_d = serializationObject.wSwizzle) !== null && _d !== void 0 ? _d : \"w\";\n }\n _dumpPropertiesCode() {\n let codeString = super._dumpPropertiesCode();\n codeString += `${this._codeVariableName}.xSwizzle = \"${this.xSwizzle}\";\\n`;\n codeString += `${this._codeVariableName}.ySwizzle = \"${this.ySwizzle}\";\\n`;\n codeString += `${this._codeVariableName}.zSwizzle = \"${this.zSwizzle}\";\\n`;\n codeString += `${this._codeVariableName}.wSwizzle = \"${this.wSwizzle}\";\\n`;\n return codeString;\n }\n }\n RegisterClass(\"BABYLON.VectorMergerBlock\", VectorMergerBlock);\n\n /**\n * Block used to remap a float from a range to a new one\n */\n class RemapBlock extends NodeMaterialBlock {\n /**\n * Creates a new RemapBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n /**\n * Gets or sets the source range\n */\n this.sourceRange = new Vector2(-1, 1);\n /**\n * Gets or sets the target range\n */\n this.targetRange = new Vector2(0, 1);\n this.registerInput(\"input\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\n this.registerInput(\"sourceMin\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerInput(\"sourceMax\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerInput(\"targetMin\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerInput(\"targetMax\", NodeMaterialBlockConnectionPointTypes.Float, true);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.BasedOnInput);\n this._outputs[0]._typeConnectionSource = this._inputs[0];\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"RemapBlock\";\n }\n /**\n * Gets the input component\n */\n get input() {\n return this._inputs[0];\n }\n /**\n * Gets the source min input component\n */\n get sourceMin() {\n return this._inputs[1];\n }\n /**\n * Gets the source max input component\n */\n get sourceMax() {\n return this._inputs[2];\n }\n /**\n * Gets the target min input component\n */\n get targetMin() {\n return this._inputs[3];\n }\n /**\n * Gets the target max input component\n */\n get targetMax() {\n return this._inputs[4];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const output = this._outputs[0];\n const sourceMin = this.sourceMin.isConnected ? this.sourceMin.associatedVariableName : this._writeFloat(this.sourceRange.x);\n const sourceMax = this.sourceMax.isConnected ? this.sourceMax.associatedVariableName : this._writeFloat(this.sourceRange.y);\n const targetMin = this.targetMin.isConnected ? this.targetMin.associatedVariableName : this._writeFloat(this.targetRange.x);\n const targetMax = this.targetMax.isConnected ? this.targetMax.associatedVariableName : this._writeFloat(this.targetRange.y);\n state.compilationString +=\n this._declareOutput(output, state) +\n ` = ${targetMin} + (${this._inputs[0].associatedVariableName} - ${sourceMin}) * (${targetMax} - ${targetMin}) / (${sourceMax} - ${sourceMin});\\n`;\n return this;\n }\n _dumpPropertiesCode() {\n let codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.sourceRange = new BABYLON.Vector2(${this.sourceRange.x}, ${this.sourceRange.y});\\n`;\n codeString += `${this._codeVariableName}.targetRange = new BABYLON.Vector2(${this.targetRange.x}, ${this.targetRange.y});\\n`;\n return codeString;\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.sourceRange = this.sourceRange.asArray();\n serializationObject.targetRange = this.targetRange.asArray();\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n super._deserialize(serializationObject, scene, rootUrl);\n this.sourceRange = Vector2.FromArray(serializationObject.sourceRange);\n this.targetRange = Vector2.FromArray(serializationObject.targetRange);\n }\n }\n __decorate$1([\n editableInPropertyPage(\"From\", PropertyTypeForEdition.Vector2)\n ], RemapBlock.prototype, \"sourceRange\", void 0);\n __decorate$1([\n editableInPropertyPage(\"To\", PropertyTypeForEdition.Vector2)\n ], RemapBlock.prototype, \"targetRange\", void 0);\n RegisterClass(\"BABYLON.RemapBlock\", RemapBlock);\n\n /**\n * Block used to multiply 2 values\n */\n class MultiplyBlock extends NodeMaterialBlock {\n /**\n * Creates a new MultiplyBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n this.registerInput(\"left\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\n this.registerInput(\"right\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.BasedOnInput);\n this._outputs[0]._typeConnectionSource = this._inputs[0];\n this._linkConnectionTypes(0, 1);\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);\n this._inputs[1].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"MultiplyBlock\";\n }\n /**\n * Gets the left operand input component\n */\n get left() {\n return this._inputs[0];\n }\n /**\n * Gets the right operand input component\n */\n get right() {\n return this._inputs[1];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const output = this._outputs[0];\n state.compilationString += this._declareOutput(output, state) + ` = ${this.left.associatedVariableName} * ${this.right.associatedVariableName};\\n`;\n return this;\n }\n }\n RegisterClass(\"BABYLON.MultiplyBlock\", MultiplyBlock);\n\n /**\n * Enum used to define the material modes\n */\n var NodeMaterialModes;\n (function (NodeMaterialModes) {\n /** Regular material */\n NodeMaterialModes[NodeMaterialModes[\"Material\"] = 0] = \"Material\";\n /** For post process */\n NodeMaterialModes[NodeMaterialModes[\"PostProcess\"] = 1] = \"PostProcess\";\n /** For particle system */\n NodeMaterialModes[NodeMaterialModes[\"Particle\"] = 2] = \"Particle\";\n /** For procedural texture */\n NodeMaterialModes[NodeMaterialModes[\"ProceduralTexture\"] = 3] = \"ProceduralTexture\";\n })(NodeMaterialModes || (NodeMaterialModes = {}));\n\n /**\n * Particle emitter emitting particles from the inside of a box.\n * It emits the particles randomly between 2 given directions.\n */\n class BoxParticleEmitter {\n /**\n * Creates a new instance BoxParticleEmitter\n */\n constructor() {\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction1 = new Vector3(0, 1.0, 0);\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction2 = new Vector3(0, 1.0, 0);\n /**\n * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n */\n this.minEmitBox = new Vector3(-0.5, -0.5, -0.5);\n /**\n * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n */\n this.maxEmitBox = new Vector3(0.5, 0.5, 0.5);\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\n if (isLocal) {\n directionToUpdate.x = randX;\n directionToUpdate.y = randY;\n directionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const randX = Scalar.RandomRange(this.minEmitBox.x, this.maxEmitBox.x);\n const randY = Scalar.RandomRange(this.minEmitBox.y, this.maxEmitBox.y);\n const randZ = Scalar.RandomRange(this.minEmitBox.z, this.maxEmitBox.z);\n if (isLocal) {\n positionToUpdate.x = randX;\n positionToUpdate.y = randY;\n positionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new BoxParticleEmitter();\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n uboOrEffect.setVector3(\"minEmitBox\", this.minEmitBox);\n uboOrEffect.setVector3(\"maxEmitBox\", this.maxEmitBox);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n ubo.addUniform(\"minEmitBox\", 3);\n ubo.addUniform(\"maxEmitBox\", 3);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define BOXEMITTER\";\n }\n /**\n * Returns the string \"BoxParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"BoxParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n serializationObject.minEmitBox = this.minEmitBox.asArray();\n serializationObject.maxEmitBox = this.maxEmitBox.asArray();\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\n Vector3.FromArrayToRef(serializationObject.minEmitBox, 0, this.minEmitBox);\n Vector3.FromArrayToRef(serializationObject.maxEmitBox, 0, this.maxEmitBox);\n }\n }\n\n /**\n * Particle emitter emitting particles from the inside of a cone.\n * It emits the particles alongside the cone volume from the base to the particle.\n * The emission direction might be randomized.\n */\n class ConeParticleEmitter {\n /**\n * Gets or sets the radius of the emission cone\n */\n get radius() {\n return this._radius;\n }\n set radius(value) {\n this._radius = value;\n this._buildHeight();\n }\n /**\n * Gets or sets the angle of the emission cone\n */\n get angle() {\n return this._angle;\n }\n set angle(value) {\n this._angle = value;\n this._buildHeight();\n }\n _buildHeight() {\n if (this._angle !== 0) {\n this._height = this._radius / Math.tan(this._angle / 2);\n }\n else {\n this._height = 1;\n }\n }\n /**\n * Creates a new instance ConeParticleEmitter\n * @param radius the radius of the emission cone (1 by default)\n * @param angle the cone base angle (PI by default)\n * @param directionRandomizer defines how much to randomize the particle direction [0-1] (default is 0)\n */\n constructor(radius = 1, angle = Math.PI, \n /** defines how much to randomize the particle direction [0-1] (default is 0) */\n directionRandomizer = 0) {\n this.directionRandomizer = directionRandomizer;\n /**\n * Gets or sets a value indicating where on the radius the start position should be picked (1 = everywhere, 0 = only surface)\n */\n this.radiusRange = 1;\n /**\n * Gets or sets a value indicating where on the height the start position should be picked (1 = everywhere, 0 = only surface)\n */\n this.heightRange = 1;\n /**\n * Gets or sets a value indicating if all the particles should be emitted from the spawn point only (the base of the cone)\n */\n this.emitFromSpawnPointOnly = false;\n this.angle = angle;\n this.radius = radius;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n if (isLocal) {\n TmpVectors.Vector3[0].copyFrom(particle._localPosition).normalize();\n }\n else {\n particle.position.subtractToRef(worldMatrix.getTranslation(), TmpVectors.Vector3[0]).normalize();\n }\n const randX = Scalar.RandomRange(0, this.directionRandomizer);\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\n const randZ = Scalar.RandomRange(0, this.directionRandomizer);\n directionToUpdate.x = TmpVectors.Vector3[0].x + randX;\n directionToUpdate.y = TmpVectors.Vector3[0].y + randY;\n directionToUpdate.z = TmpVectors.Vector3[0].z + randZ;\n directionToUpdate.normalize();\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const s = Scalar.RandomRange(0, Math.PI * 2);\n let h;\n if (!this.emitFromSpawnPointOnly) {\n h = Scalar.RandomRange(0, this.heightRange);\n // Better distribution in a cone at normal angles.\n h = 1 - h * h;\n }\n else {\n h = 0.0001;\n }\n let radius = this._radius - Scalar.RandomRange(0, this._radius * this.radiusRange);\n radius = radius * h;\n const randX = radius * Math.sin(s);\n const randZ = radius * Math.cos(s);\n const randY = h * this._height;\n if (isLocal) {\n positionToUpdate.x = randX;\n positionToUpdate.y = randY;\n positionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new ConeParticleEmitter(this._radius, this._angle, this.directionRandomizer);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat2(\"radius\", this._radius, this.radiusRange);\n uboOrEffect.setFloat(\"coneAngle\", this._angle);\n uboOrEffect.setFloat2(\"height\", this._height, this.heightRange);\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 2);\n ubo.addUniform(\"coneAngle\", 1);\n ubo.addUniform(\"height\", 2);\n ubo.addUniform(\"directionRandomizer\", 1);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n let defines = \"#define CONEEMITTER\";\n if (this.emitFromSpawnPointOnly) {\n defines += \"\\n#define CONEEMITTERSPAWNPOINT\";\n }\n return defines;\n }\n /**\n * Returns the string \"ConeParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"ConeParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.radius = this._radius;\n serializationObject.angle = this._angle;\n serializationObject.directionRandomizer = this.directionRandomizer;\n serializationObject.radiusRange = this.radiusRange;\n serializationObject.heightRange = this.heightRange;\n serializationObject.emitFromSpawnPointOnly = this.emitFromSpawnPointOnly;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n this.radius = serializationObject.radius;\n this.angle = serializationObject.angle;\n this.directionRandomizer = serializationObject.directionRandomizer;\n this.radiusRange = serializationObject.radiusRange !== undefined ? serializationObject.radiusRange : 1;\n this.heightRange = serializationObject.radiusRange !== undefined ? serializationObject.heightRange : 1;\n this.emitFromSpawnPointOnly = serializationObject.emitFromSpawnPointOnly !== undefined ? serializationObject.emitFromSpawnPointOnly : false;\n }\n }\n\n /**\n * Particle emitter emitting particles from the inside of a cylinder.\n * It emits the particles alongside the cylinder radius. The emission direction might be randomized.\n */\n class CylinderParticleEmitter {\n /**\n * Creates a new instance CylinderParticleEmitter\n * @param radius the radius of the emission cylinder (1 by default)\n * @param height the height of the emission cylinder (1 by default)\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\n */\n constructor(\n /**\n * The radius of the emission cylinder.\n */\n radius = 1, \n /**\n * The height of the emission cylinder.\n */\n height = 1, \n /**\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\n */\n radiusRange = 1, \n /**\n * How much to randomize the particle direction [0-1].\n */\n directionRandomizer = 0) {\n this.radius = radius;\n this.height = height;\n this.radiusRange = radiusRange;\n this.directionRandomizer = directionRandomizer;\n this._tempVector = Vector3.Zero();\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n * @param inverseWorldMatrix defines the inverted world matrix to use if isLocal is false\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal, inverseWorldMatrix) {\n particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);\n this._tempVector.normalize();\n Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);\n const randY = Scalar.RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);\n let angle = Math.atan2(this._tempVector.x, this._tempVector.z);\n angle += Scalar.RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;\n this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface\n this._tempVector.x = Math.sin(angle);\n this._tempVector.z = Math.cos(angle);\n this._tempVector.normalize();\n if (isLocal) {\n directionToUpdate.copyFrom(this._tempVector);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(this._tempVector.x, this._tempVector.y, this._tempVector.z, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const yPos = Scalar.RandomRange(-this.height / 2, this.height / 2);\n const angle = Scalar.RandomRange(0, 2 * Math.PI);\n // Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html\n const radiusDistribution = Scalar.RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);\n const positionRadius = Math.sqrt(radiusDistribution) * this.radius;\n const xPos = positionRadius * Math.cos(angle);\n const zPos = positionRadius * Math.sin(angle);\n if (isLocal) {\n positionToUpdate.copyFromFloats(xPos, yPos, zPos);\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(xPos, yPos, zPos, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new CylinderParticleEmitter(this.radius, this.directionRandomizer);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"height\", this.height);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"height\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"directionRandomizer\", 1);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define CYLINDEREMITTER\";\n }\n /**\n * Returns the string \"CylinderParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"CylinderParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.radius = this.radius;\n serializationObject.height = this.height;\n serializationObject.radiusRange = this.radiusRange;\n serializationObject.directionRandomizer = this.directionRandomizer;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n this.radius = serializationObject.radius;\n this.height = serializationObject.height;\n this.radiusRange = serializationObject.radiusRange;\n this.directionRandomizer = serializationObject.directionRandomizer;\n }\n }\n /**\n * Particle emitter emitting particles from the inside of a cylinder.\n * It emits the particles randomly between two vectors.\n */\n class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {\n /**\n * Creates a new instance CylinderDirectedParticleEmitter\n * @param radius the radius of the emission cylinder (1 by default)\n * @param height the height of the emission cylinder (1 by default)\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param direction1 the min limit of the emission direction (up vector by default)\n * @param direction2 the max limit of the emission direction (up vector by default)\n */\n constructor(radius = 1, height = 1, radiusRange = 1, \n /**\n * The min limit of the emission direction.\n */\n direction1 = new Vector3(0, 1, 0), \n /**\n * The max limit of the emission direction.\n */\n direction2 = new Vector3(0, 1, 0)) {\n super(radius, height, radiusRange);\n this.direction1 = direction1;\n this.direction2 = direction2;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n */\n startDirectionFunction(worldMatrix, directionToUpdate) {\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, this.direction1, this.direction2);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"height\", this.height);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"height\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define CYLINDEREMITTER\\n#define DIRECTEDCYLINDEREMITTER\";\n }\n /**\n * Returns the string \"CylinderDirectedParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"CylinderDirectedParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n super.parse(serializationObject);\n this.direction1.copyFrom(serializationObject.direction1);\n this.direction2.copyFrom(serializationObject.direction2);\n }\n }\n\n /**\n * Particle emitter emitting particles from the inside of a hemisphere.\n * It emits the particles alongside the hemisphere radius. The emission direction might be randomized.\n */\n class HemisphericParticleEmitter {\n /**\n * Creates a new instance HemisphericParticleEmitter\n * @param radius the radius of the emission hemisphere (1 by default)\n * @param radiusRange the range of the emission hemisphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\n */\n constructor(\n /**\n * The radius of the emission hemisphere.\n */\n radius = 1, \n /**\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\n */\n radiusRange = 1, \n /**\n * How much to randomize the particle direction [0-1].\n */\n directionRandomizer = 0) {\n this.radius = radius;\n this.radiusRange = radiusRange;\n this.directionRandomizer = directionRandomizer;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\n const randX = Scalar.RandomRange(0, this.directionRandomizer);\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\n const randZ = Scalar.RandomRange(0, this.directionRandomizer);\n direction.x += randX;\n direction.y += randY;\n direction.z += randZ;\n direction.normalize();\n if (isLocal) {\n directionToUpdate.copyFrom(direction);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const randRadius = this.radius - Scalar.RandomRange(0, this.radius * this.radiusRange);\n const v = Scalar.RandomRange(0, 1.0);\n const phi = Scalar.RandomRange(0, 2 * Math.PI);\n const theta = Math.acos(2 * v - 1);\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\n const randY = randRadius * Math.cos(theta);\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\n if (isLocal) {\n positionToUpdate.copyFromFloats(randX, Math.abs(randY), randZ);\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, Math.abs(randY), randZ, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new HemisphericParticleEmitter(this.radius, this.directionRandomizer);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"directionRandomizer\", 1);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define HEMISPHERICEMITTER\";\n }\n /**\n * Returns the string \"HemisphericParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"HemisphericParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.radius = this.radius;\n serializationObject.radiusRange = this.radiusRange;\n serializationObject.directionRandomizer = this.directionRandomizer;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n this.radius = serializationObject.radius;\n this.radiusRange = serializationObject.radiusRange;\n this.directionRandomizer = serializationObject.directionRandomizer;\n }\n }\n\n /**\n * Particle emitter emitting particles from a point.\n * It emits the particles randomly between 2 given directions.\n */\n class PointParticleEmitter {\n /**\n * Creates a new instance PointParticleEmitter\n */\n constructor() {\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction1 = new Vector3(0, 1.0, 0);\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction2 = new Vector3(0, 1.0, 0);\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\n if (isLocal) {\n directionToUpdate.copyFromFloats(randX, randY, randZ);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n if (isLocal) {\n positionToUpdate.copyFromFloats(0, 0, 0);\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new PointParticleEmitter();\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define POINTEMITTER\";\n }\n /**\n * Returns the string \"PointParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"PointParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\n }\n }\n\n /**\n * Particle emitter emitting particles from the inside of a sphere.\n * It emits the particles alongside the sphere radius. The emission direction might be randomized.\n */\n class SphereParticleEmitter {\n /**\n * Creates a new instance SphereParticleEmitter\n * @param radius the radius of the emission sphere (1 by default)\n * @param radiusRange the range of the emission sphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\n */\n constructor(\n /**\n * The radius of the emission sphere.\n */\n radius = 1, \n /**\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\n */\n radiusRange = 1, \n /**\n * How much to randomize the particle direction [0-1].\n */\n directionRandomizer = 0) {\n this.radius = radius;\n this.radiusRange = radiusRange;\n this.directionRandomizer = directionRandomizer;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\n const randX = Scalar.RandomRange(0, this.directionRandomizer);\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\n const randZ = Scalar.RandomRange(0, this.directionRandomizer);\n direction.x += randX;\n direction.y += randY;\n direction.z += randZ;\n direction.normalize();\n if (isLocal) {\n directionToUpdate.copyFrom(direction);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const randRadius = this.radius - Scalar.RandomRange(0, this.radius * this.radiusRange);\n const v = Scalar.RandomRange(0, 1.0);\n const phi = Scalar.RandomRange(0, 2 * Math.PI);\n const theta = Math.acos(2 * v - 1);\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\n const randY = randRadius * Math.cos(theta);\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\n if (isLocal) {\n positionToUpdate.copyFromFloats(randX, randY, randZ);\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new SphereParticleEmitter(this.radius, this.directionRandomizer);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"directionRandomizer\", 1);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define SPHEREEMITTER\";\n }\n /**\n * Returns the string \"SphereParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"SphereParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.radius = this.radius;\n serializationObject.radiusRange = this.radiusRange;\n serializationObject.directionRandomizer = this.directionRandomizer;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n this.radius = serializationObject.radius;\n this.radiusRange = serializationObject.radiusRange;\n this.directionRandomizer = serializationObject.directionRandomizer;\n }\n }\n /**\n * Particle emitter emitting particles from the inside of a sphere.\n * It emits the particles randomly between two vectors.\n */\n class SphereDirectedParticleEmitter extends SphereParticleEmitter {\n /**\n * Creates a new instance SphereDirectedParticleEmitter\n * @param radius the radius of the emission sphere (1 by default)\n * @param direction1 the min limit of the emission direction (up vector by default)\n * @param direction2 the max limit of the emission direction (up vector by default)\n */\n constructor(radius = 1, \n /**\n * The min limit of the emission direction.\n */\n direction1 = new Vector3(0, 1, 0), \n /**\n * The max limit of the emission direction.\n */\n direction2 = new Vector3(0, 1, 0)) {\n super(radius);\n this.direction1 = direction1;\n this.direction2 = direction2;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n */\n startDirectionFunction(worldMatrix, directionToUpdate) {\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new SphereDirectedParticleEmitter(this.radius, this.direction1, this.direction2);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define SPHEREEMITTER\\n#define DIRECTEDSPHEREEMITTER\";\n }\n /**\n * Returns the string \"SphereDirectedParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"SphereDirectedParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n super.parse(serializationObject);\n this.direction1.copyFrom(serializationObject.direction1);\n this.direction2.copyFrom(serializationObject.direction2);\n }\n }\n\n /**\n * Particle emitter emitting particles from the inside of a box.\n * It emits the particles randomly between 2 given directions.\n */\n class MeshParticleEmitter {\n /** Defines the mesh to use as source */\n get mesh() {\n return this._mesh;\n }\n set mesh(value) {\n if (this._mesh === value) {\n return;\n }\n this._mesh = value;\n if (value) {\n this._indices = value.getIndices();\n this._positions = value.getVerticesData(VertexBuffer.PositionKind);\n this._normals = value.getVerticesData(VertexBuffer.NormalKind);\n }\n else {\n this._indices = null;\n this._positions = null;\n this._normals = null;\n }\n }\n /**\n * Creates a new instance MeshParticleEmitter\n * @param mesh defines the mesh to use as source\n */\n constructor(mesh = null) {\n this._indices = null;\n this._positions = null;\n this._normals = null;\n this._storedNormal = Vector3.Zero();\n this._mesh = null;\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction1 = new Vector3(0, 1.0, 0);\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction2 = new Vector3(0, 1.0, 0);\n /**\n * Gets or sets a boolean indicating that particle directions must be built from mesh face normals\n */\n this.useMeshNormalsForDirection = true;\n this.mesh = mesh;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n if (this.useMeshNormalsForDirection && this._normals) {\n Vector3.TransformNormalToRef(this._storedNormal, worldMatrix, directionToUpdate);\n return;\n }\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\n if (isLocal) {\n directionToUpdate.copyFromFloats(randX, randY, randZ);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n if (!this._indices || !this._positions) {\n return;\n }\n const randomFaceIndex = (3 * Math.random() * (this._indices.length / 3)) | 0;\n const bu = Math.random();\n const bv = Math.random() * (1.0 - bu);\n const bw = 1.0 - bu - bv;\n const faceIndexA = this._indices[randomFaceIndex];\n const faceIndexB = this._indices[randomFaceIndex + 1];\n const faceIndexC = this._indices[randomFaceIndex + 2];\n const vertexA = TmpVectors.Vector3[0];\n const vertexB = TmpVectors.Vector3[1];\n const vertexC = TmpVectors.Vector3[2];\n const randomVertex = TmpVectors.Vector3[3];\n Vector3.FromArrayToRef(this._positions, faceIndexA * 3, vertexA);\n Vector3.FromArrayToRef(this._positions, faceIndexB * 3, vertexB);\n Vector3.FromArrayToRef(this._positions, faceIndexC * 3, vertexC);\n randomVertex.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\n randomVertex.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\n randomVertex.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\n if (isLocal) {\n positionToUpdate.copyFromFloats(randomVertex.x, randomVertex.y, randomVertex.z);\n }\n else {\n Vector3.TransformCoordinatesFromFloatsToRef(randomVertex.x, randomVertex.y, randomVertex.z, worldMatrix, positionToUpdate);\n }\n if (this.useMeshNormalsForDirection && this._normals) {\n Vector3.FromArrayToRef(this._normals, faceIndexA * 3, vertexA);\n Vector3.FromArrayToRef(this._normals, faceIndexB * 3, vertexB);\n Vector3.FromArrayToRef(this._normals, faceIndexC * 3, vertexC);\n this._storedNormal.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\n this._storedNormal.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\n this._storedNormal.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\n }\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new MeshParticleEmitter(this.mesh);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"\";\n }\n /**\n * Returns the string \"BoxParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"MeshParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n var _a;\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n serializationObject.meshId = (_a = this.mesh) === null || _a === void 0 ? void 0 : _a.id;\n serializationObject.useMeshNormalsForDirection = this.useMeshNormalsForDirection;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n * @param scene defines the hosting scene\n */\n parse(serializationObject, scene) {\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\n if (serializationObject.meshId && scene) {\n this.mesh = scene.getLastMeshById(serializationObject.meshId);\n }\n this.useMeshNormalsForDirection = serializationObject.useMeshNormalsForDirection;\n }\n }\n\n /**\n * This represents the base class for particle system in Babylon.\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\n * Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.\n * @example https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro\n */\n class BaseParticleSystem {\n /**\n * Gets or sets a texture used to add random noise to particle positions\n */\n get noiseTexture() {\n return this._noiseTexture;\n }\n set noiseTexture(value) {\n if (this._noiseTexture === value) {\n return;\n }\n this._noiseTexture = value;\n this._reset();\n }\n /**\n * Gets or sets whether an animation sprite sheet is enabled or not on the particle system\n */\n get isAnimationSheetEnabled() {\n return this._isAnimationSheetEnabled;\n }\n set isAnimationSheetEnabled(value) {\n if (this._isAnimationSheetEnabled == value) {\n return;\n }\n this._isAnimationSheetEnabled = value;\n this._reset();\n }\n /**\n * Gets or sets a boolean enabling the use of logarithmic depth buffers, which is good for wide depth buffers.\n */\n get useLogarithmicDepth() {\n return this._useLogarithmicDepth;\n }\n set useLogarithmicDepth(value) {\n this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;\n }\n /**\n * Get hosting scene\n * @returns the scene\n */\n getScene() {\n return this._scene;\n }\n _hasTargetStopDurationDependantGradient() {\n return ((this._startSizeGradients && this._startSizeGradients.length > 0) ||\n (this._emitRateGradients && this._emitRateGradients.length > 0) ||\n (this._lifeTimeGradients && this._lifeTimeGradients.length > 0));\n }\n /**\n * Gets the current list of drag gradients.\n * You must use addDragGradient and removeDragGradient to update this list\n * @returns the list of drag gradients\n */\n getDragGradients() {\n return this._dragGradients;\n }\n /**\n * Gets the current list of limit velocity gradients.\n * You must use addLimitVelocityGradient and removeLimitVelocityGradient to update this list\n * @returns the list of limit velocity gradients\n */\n getLimitVelocityGradients() {\n return this._limitVelocityGradients;\n }\n /**\n * Gets the current list of color gradients.\n * You must use addColorGradient and removeColorGradient to update this list\n * @returns the list of color gradients\n */\n getColorGradients() {\n return this._colorGradients;\n }\n /**\n * Gets the current list of size gradients.\n * You must use addSizeGradient and removeSizeGradient to update this list\n * @returns the list of size gradients\n */\n getSizeGradients() {\n return this._sizeGradients;\n }\n /**\n * Gets the current list of color remap gradients.\n * You must use addColorRemapGradient and removeColorRemapGradient to update this list\n * @returns the list of color remap gradients\n */\n getColorRemapGradients() {\n return this._colorRemapGradients;\n }\n /**\n * Gets the current list of alpha remap gradients.\n * You must use addAlphaRemapGradient and removeAlphaRemapGradient to update this list\n * @returns the list of alpha remap gradients\n */\n getAlphaRemapGradients() {\n return this._alphaRemapGradients;\n }\n /**\n * Gets the current list of life time gradients.\n * You must use addLifeTimeGradient and removeLifeTimeGradient to update this list\n * @returns the list of life time gradients\n */\n getLifeTimeGradients() {\n return this._lifeTimeGradients;\n }\n /**\n * Gets the current list of angular speed gradients.\n * You must use addAngularSpeedGradient and removeAngularSpeedGradient to update this list\n * @returns the list of angular speed gradients\n */\n getAngularSpeedGradients() {\n return this._angularSpeedGradients;\n }\n /**\n * Gets the current list of velocity gradients.\n * You must use addVelocityGradient and removeVelocityGradient to update this list\n * @returns the list of velocity gradients\n */\n getVelocityGradients() {\n return this._velocityGradients;\n }\n /**\n * Gets the current list of start size gradients.\n * You must use addStartSizeGradient and removeStartSizeGradient to update this list\n * @returns the list of start size gradients\n */\n getStartSizeGradients() {\n return this._startSizeGradients;\n }\n /**\n * Gets the current list of emit rate gradients.\n * You must use addEmitRateGradient and removeEmitRateGradient to update this list\n * @returns the list of emit rate gradients\n */\n getEmitRateGradients() {\n return this._emitRateGradients;\n }\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n * This only works when particleEmitterTyps is a BoxParticleEmitter\n */\n get direction1() {\n if (this.particleEmitterType.direction1) {\n return this.particleEmitterType.direction1;\n }\n return Vector3.Zero();\n }\n set direction1(value) {\n if (this.particleEmitterType.direction1) {\n this.particleEmitterType.direction1 = value;\n }\n }\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n * This only works when particleEmitterTyps is a BoxParticleEmitter\n */\n get direction2() {\n if (this.particleEmitterType.direction2) {\n return this.particleEmitterType.direction2;\n }\n return Vector3.Zero();\n }\n set direction2(value) {\n if (this.particleEmitterType.direction2) {\n this.particleEmitterType.direction2 = value;\n }\n }\n /**\n * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n * This only works when particleEmitterTyps is a BoxParticleEmitter\n */\n get minEmitBox() {\n if (this.particleEmitterType.minEmitBox) {\n return this.particleEmitterType.minEmitBox;\n }\n return Vector3.Zero();\n }\n set minEmitBox(value) {\n if (this.particleEmitterType.minEmitBox) {\n this.particleEmitterType.minEmitBox = value;\n }\n }\n /**\n * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n * This only works when particleEmitterTyps is a BoxParticleEmitter\n */\n get maxEmitBox() {\n if (this.particleEmitterType.maxEmitBox) {\n return this.particleEmitterType.maxEmitBox;\n }\n return Vector3.Zero();\n }\n set maxEmitBox(value) {\n if (this.particleEmitterType.maxEmitBox) {\n this.particleEmitterType.maxEmitBox = value;\n }\n }\n /**\n * Gets or sets the billboard mode to use when isBillboardBased = true.\n * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED\n */\n get billboardMode() {\n return this._billboardMode;\n }\n set billboardMode(value) {\n if (this._billboardMode === value) {\n return;\n }\n this._billboardMode = value;\n this._reset();\n }\n /**\n * Gets or sets a boolean indicating if the particles must be rendered as billboard or aligned with the direction\n */\n get isBillboardBased() {\n return this._isBillboardBased;\n }\n set isBillboardBased(value) {\n if (this._isBillboardBased === value) {\n return;\n }\n this._isBillboardBased = value;\n this._reset();\n }\n /**\n * Gets the image processing configuration used either in this material.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Sets the Default image processing configuration used either in the this material.\n *\n * If sets to null, the scene one is in use.\n */\n set imageProcessingConfiguration(value) {\n this._attachImageProcessingConfiguration(value);\n }\n /**\n * Attaches a new image processing configuration to the Standard Material.\n * @param configuration\n */\n _attachImageProcessingConfiguration(configuration) {\n if (configuration === this._imageProcessingConfiguration) {\n return;\n }\n // Pick the scene configuration if needed.\n if (!configuration && this._scene) {\n this._imageProcessingConfiguration = this._scene.imageProcessingConfiguration;\n }\n else {\n this._imageProcessingConfiguration = configuration;\n }\n }\n /** @internal */\n _reset() { }\n /**\n * @internal\n */\n _removeGradientAndTexture(gradient, gradients, texture) {\n if (!gradients) {\n return this;\n }\n let index = 0;\n for (const valueGradient of gradients) {\n if (valueGradient.gradient === gradient) {\n gradients.splice(index, 1);\n break;\n }\n index++;\n }\n if (texture) {\n texture.dispose();\n }\n return this;\n }\n /**\n * Instantiates a particle system.\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\n * @param name The name of the particle system\n */\n constructor(name) {\n /**\n * List of animations used by the particle system.\n */\n this.animations = [];\n /**\n * The rendering group used by the Particle system to chose when to render.\n */\n this.renderingGroupId = 0;\n /**\n * The emitter represents the Mesh or position we are attaching the particle system to.\n */\n this.emitter = Vector3.Zero();\n /**\n * The maximum number of particles to emit per frame\n */\n this.emitRate = 10;\n /**\n * If you want to launch only a few particles at once, that can be done, as well.\n */\n this.manualEmitCount = -1;\n /**\n * The overall motion speed (0.01 is default update speed, faster updates = faster animation)\n */\n this.updateSpeed = 0.01;\n /**\n * The amount of time the particle system is running (depends of the overall update speed).\n */\n this.targetStopDuration = 0;\n /**\n * Specifies whether the particle system will be disposed once it reaches the end of the animation.\n */\n this.disposeOnStop = false;\n /**\n * Minimum power of emitting particles.\n */\n this.minEmitPower = 1;\n /**\n * Maximum power of emitting particles.\n */\n this.maxEmitPower = 1;\n /**\n * Minimum life time of emitting particles.\n */\n this.minLifeTime = 1;\n /**\n * Maximum life time of emitting particles.\n */\n this.maxLifeTime = 1;\n /**\n * Minimum Size of emitting particles.\n */\n this.minSize = 1;\n /**\n * Maximum Size of emitting particles.\n */\n this.maxSize = 1;\n /**\n * Minimum scale of emitting particles on X axis.\n */\n this.minScaleX = 1;\n /**\n * Maximum scale of emitting particles on X axis.\n */\n this.maxScaleX = 1;\n /**\n * Minimum scale of emitting particles on Y axis.\n */\n this.minScaleY = 1;\n /**\n * Maximum scale of emitting particles on Y axis.\n */\n this.maxScaleY = 1;\n /**\n * Gets or sets the minimal initial rotation in radians.\n */\n this.minInitialRotation = 0;\n /**\n * Gets or sets the maximal initial rotation in radians.\n */\n this.maxInitialRotation = 0;\n /**\n * Minimum angular speed of emitting particles (Z-axis rotation for each particle).\n */\n this.minAngularSpeed = 0;\n /**\n * Maximum angular speed of emitting particles (Z-axis rotation for each particle).\n */\n this.maxAngularSpeed = 0;\n /**\n * The layer mask we are rendering the particles through.\n */\n this.layerMask = 0x0fffffff;\n /**\n * This can help using your own shader to render the particle system.\n * The according effect will be created\n */\n this.customShader = null;\n /**\n * By default particle system starts as soon as they are created. This prevents the\n * automatic start to happen and let you decide when to start emitting particles.\n */\n this.preventAutoStart = false;\n /** @internal */\n this._wasDispatched = false;\n this._rootUrl = \"\";\n /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */\n this.noiseStrength = new Vector3(10, 10, 10);\n /**\n * Callback triggered when the particle animation is ending.\n */\n this.onAnimationEnd = null;\n /**\n * Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE or ParticleSystem.BLENDMODE_STANDARD.\n */\n this.blendMode = BaseParticleSystem.BLENDMODE_ONEONE;\n /**\n * Forces the particle to write their depth information to the depth buffer. This can help preventing other draw calls\n * to override the particles.\n */\n this.forceDepthWrite = false;\n /** Gets or sets a value indicating how many cycles (or frames) must be executed before first rendering (this value has to be set before starting the system). Default is 0 */\n this.preWarmCycles = 0;\n /** Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1) */\n this.preWarmStepOffset = 1;\n /**\n * If using a spritesheet (isAnimationSheetEnabled) defines the speed of the sprite loop (default is 1 meaning the animation will play once during the entire particle lifetime)\n */\n this.spriteCellChangeSpeed = 1;\n /**\n * If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display\n */\n this.startSpriteCellID = 0;\n /**\n * If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display\n */\n this.endSpriteCellID = 0;\n /**\n * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use\n */\n this.spriteCellWidth = 0;\n /**\n * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use\n */\n this.spriteCellHeight = 0;\n /**\n * If using a spritesheet (isAnimationSheetEnabled), defines wether the sprite animation is looping\n */\n this.spriteCellLoop = true;\n /**\n * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID\n */\n this.spriteRandomStartCell = false;\n /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */\n this.translationPivot = new Vector2(0, 0);\n /**\n * Gets or sets a boolean indicating that hosted animations (in the system.animations array) must be started when system.start() is called\n */\n this.beginAnimationOnStart = false;\n /**\n * Gets or sets the frame to start the animation from when beginAnimationOnStart is true\n */\n this.beginAnimationFrom = 0;\n /**\n * Gets or sets the frame to end the animation on when beginAnimationOnStart is true\n */\n this.beginAnimationTo = 60;\n /**\n * Gets or sets a boolean indicating if animations must loop when beginAnimationOnStart is true\n */\n this.beginAnimationLoop = false;\n /**\n * Gets or sets a world offset applied to all particles\n */\n this.worldOffset = new Vector3(0, 0, 0);\n this._useLogarithmicDepth = false;\n /**\n * You can use gravity if you want to give an orientation to your particles.\n */\n this.gravity = Vector3.Zero();\n this._colorGradients = null;\n this._sizeGradients = null;\n this._lifeTimeGradients = null;\n this._angularSpeedGradients = null;\n this._velocityGradients = null;\n this._limitVelocityGradients = null;\n this._dragGradients = null;\n this._emitRateGradients = null;\n this._startSizeGradients = null;\n this._rampGradients = null;\n this._colorRemapGradients = null;\n this._alphaRemapGradients = null;\n /**\n * Defines the delay in milliseconds before starting the system (0 by default)\n */\n this.startDelay = 0;\n /** Gets or sets a value indicating the damping to apply if the limit velocity factor is reached */\n this.limitVelocityDamping = 0.4;\n /**\n * Random color of each particle after it has been emitted, between color1 and color2 vectors\n */\n this.color1 = new Color4(1.0, 1.0, 1.0, 1.0);\n /**\n * Random color of each particle after it has been emitted, between color1 and color2 vectors\n */\n this.color2 = new Color4(1.0, 1.0, 1.0, 1.0);\n /**\n * Color the particle will have at the end of its lifetime\n */\n this.colorDead = new Color4(0, 0, 0, 1.0);\n /**\n * An optional mask to filter some colors out of the texture, or filter a part of the alpha channel\n */\n this.textureMask = new Color4(1.0, 1.0, 1.0, 1.0);\n /** @internal */\n this._isSubEmitter = false;\n /** @internal */\n this._billboardMode = 7;\n /** @internal */\n this._isBillboardBased = true;\n /**\n * Local cache of defines for image processing.\n */\n this._imageProcessingConfigurationDefines = new ImageProcessingConfigurationDefines();\n this.id = name;\n this.name = name;\n }\n /**\n * Creates a Point Emitter for the particle system (emits directly from the emitter position)\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the box\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the box\n * @returns the emitter\n */\n createPointEmitter(direction1, direction2) {\n const particleEmitter = new PointParticleEmitter();\n particleEmitter.direction1 = direction1;\n particleEmitter.direction2 = direction2;\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)\n * @param radius The radius of the hemisphere to emit from\n * @param radiusRange The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius\n * @returns the emitter\n */\n createHemisphericEmitter(radius = 1, radiusRange = 1) {\n const particleEmitter = new HemisphericParticleEmitter(radius, radiusRange);\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Sphere Emitter for the particle system (emits along the sphere radius)\n * @param radius The radius of the sphere to emit from\n * @param radiusRange The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius\n * @returns the emitter\n */\n createSphereEmitter(radius = 1, radiusRange = 1) {\n const particleEmitter = new SphereParticleEmitter(radius, radiusRange);\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)\n * @param radius The radius of the sphere to emit from\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the sphere\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the sphere\n * @returns the emitter\n */\n createDirectedSphereEmitter(radius = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)) {\n const particleEmitter = new SphereDirectedParticleEmitter(radius, direction1, direction2);\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)\n * @param radius The radius of the emission cylinder\n * @param height The height of the emission cylinder\n * @param radiusRange The range of emission [0-1] 0 Surface only, 1 Entire Radius\n * @param directionRandomizer How much to randomize the particle direction [0-1]\n * @returns the emitter\n */\n createCylinderEmitter(radius = 1, height = 1, radiusRange = 1, directionRandomizer = 0) {\n const particleEmitter = new CylinderParticleEmitter(radius, height, radiusRange, directionRandomizer);\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Directed Cylinder Emitter for the particle system (emits between direction1 and direction2)\n * @param radius The radius of the cylinder to emit from\n * @param height The height of the emission cylinder\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the cylinder\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the cylinder\n * @returns the emitter\n */\n createDirectedCylinderEmitter(radius = 1, height = 1, radiusRange = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)) {\n const particleEmitter = new CylinderDirectedParticleEmitter(radius, height, radiusRange, direction1, direction2);\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Cone Emitter for the particle system (emits from the cone to the particle position)\n * @param radius The radius of the cone to emit from\n * @param angle The base angle of the cone\n * @returns the emitter\n */\n createConeEmitter(radius = 1, angle = Math.PI / 4) {\n const particleEmitter = new ConeParticleEmitter(radius, angle);\n this.particleEmitterType = particleEmitter;\n return particleEmitter;\n }\n /**\n * Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the box\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the box\n * @param minEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox\n * @param maxEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox\n * @returns the emitter\n */\n createBoxEmitter(direction1, direction2, minEmitBox, maxEmitBox) {\n const particleEmitter = new BoxParticleEmitter();\n this.particleEmitterType = particleEmitter;\n this.direction1 = direction1;\n this.direction2 = direction2;\n this.minEmitBox = minEmitBox;\n this.maxEmitBox = maxEmitBox;\n return particleEmitter;\n }\n }\n /**\n * Source color is added to the destination color without alpha affecting the result\n */\n BaseParticleSystem.BLENDMODE_ONEONE = 0;\n /**\n * Blend current color and particle color using particle’s alpha\n */\n BaseParticleSystem.BLENDMODE_STANDARD = 1;\n /**\n * Add current color and particle color multiplied by particle’s alpha\n */\n BaseParticleSystem.BLENDMODE_ADD = 2;\n /**\n * Multiply current color with particle color\n */\n BaseParticleSystem.BLENDMODE_MULTIPLY = 3;\n /**\n * Multiply current color with particle color then add current color and particle color multiplied by particle’s alpha\n */\n BaseParticleSystem.BLENDMODE_MULTIPLYADD = 4;\n\n /**\n * Block used to expand a Color3/4 into 4 outputs (one for each component)\n */\n class ColorSplitterBlock extends NodeMaterialBlock {\n /**\n * Create a new ColorSplitterBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n this.registerInput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, true);\n this.registerInput(\"rgb \", NodeMaterialBlockConnectionPointTypes.Color3, true);\n this.registerOutput(\"rgb\", NodeMaterialBlockConnectionPointTypes.Color3);\n this.registerOutput(\"r\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"g\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"b\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"a\", NodeMaterialBlockConnectionPointTypes.Float);\n this.inputsAreExclusive = true;\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"ColorSplitterBlock\";\n }\n /**\n * Gets the rgba component (input)\n */\n get rgba() {\n return this._inputs[0];\n }\n /**\n * Gets the rgb component (input)\n */\n get rgbIn() {\n return this._inputs[1];\n }\n /**\n * Gets the rgb component (output)\n */\n get rgbOut() {\n return this._outputs[0];\n }\n /**\n * Gets the r component (output)\n */\n get r() {\n return this._outputs[1];\n }\n /**\n * Gets the g component (output)\n */\n get g() {\n return this._outputs[2];\n }\n /**\n * Gets the b component (output)\n */\n get b() {\n return this._outputs[3];\n }\n /**\n * Gets the a component (output)\n */\n get a() {\n return this._outputs[4];\n }\n _inputRename(name) {\n if (name === \"rgb \") {\n return \"rgbIn\";\n }\n return name;\n }\n _outputRename(name) {\n if (name === \"rgb\") {\n return \"rgbOut\";\n }\n return name;\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const input = this.rgba.isConnected ? this.rgba : this.rgbIn;\n if (!input.isConnected) {\n return;\n }\n const rgbOutput = this._outputs[0];\n const rOutput = this._outputs[1];\n const gOutput = this._outputs[2];\n const bOutput = this._outputs[3];\n const aOutput = this._outputs[4];\n if (rgbOutput.hasEndpoints) {\n state.compilationString += this._declareOutput(rgbOutput, state) + ` = ${input.associatedVariableName}.rgb;\\n`;\n }\n if (rOutput.hasEndpoints) {\n state.compilationString += this._declareOutput(rOutput, state) + ` = ${input.associatedVariableName}.r;\\n`;\n }\n if (gOutput.hasEndpoints) {\n state.compilationString += this._declareOutput(gOutput, state) + ` = ${input.associatedVariableName}.g;\\n`;\n }\n if (bOutput.hasEndpoints) {\n state.compilationString += this._declareOutput(bOutput, state) + ` = ${input.associatedVariableName}.b;\\n`;\n }\n if (aOutput.hasEndpoints) {\n state.compilationString += this._declareOutput(aOutput, state) + ` = ${input.associatedVariableName}.a;\\n`;\n }\n return this;\n }\n }\n RegisterClass(\"BABYLON.ColorSplitterBlock\", ColorSplitterBlock);\n\n /**\n * Defines the Procedural Texture scene component responsible to manage any Procedural Texture\n * in a given scene.\n */\n class ProceduralTextureSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_PROCEDURALTEXTURE;\n this.scene = scene;\n this.scene.proceduralTextures = new Array();\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._beforeClearStage.registerStep(SceneComponentConstants.STEP_BEFORECLEAR_PROCEDURALTEXTURE, this, this._beforeClear);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do here.\n }\n /**\n * Disposes the component and the associated resources.\n */\n dispose() {\n // Nothing to do here.\n }\n _beforeClear() {\n if (this.scene.proceduralTexturesEnabled) {\n Tools.StartPerformanceCounter(\"Procedural textures\", this.scene.proceduralTextures.length > 0);\n for (let proceduralIndex = 0; proceduralIndex < this.scene.proceduralTextures.length; proceduralIndex++) {\n const proceduralTexture = this.scene.proceduralTextures[proceduralIndex];\n if (proceduralTexture._shouldRender()) {\n proceduralTexture.render();\n }\n }\n Tools.EndPerformanceCounter(\"Procedural textures\", this.scene.proceduralTextures.length > 0);\n }\n }\n }\n\n // Do not edit.\n const name$1X = \"proceduralVertexShader\";\n const shader$1X = `attribute vec2 position;varying vec2 vPosition;varying vec2 vUV;const vec2 madd=vec2(0.5,0.5);\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvPosition=position;vUV=position*madd+madd;gl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1X] = shader$1X;\n\n /**\n * Procedural texturing is a way to programmatically create a texture. There are 2 types of procedural textures: code-only, and code that references some classic 2D images, sometimes calmpler' images.\n * This is the base class of any Procedural texture and contains most of the shareable code.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/proceduralTextures\n */\n class ProceduralTexture extends Texture {\n /**\n * Instantiates a new procedural texture.\n * Procedural texturing is a way to programmatically create a texture. There are 2 types of procedural textures: code-only, and code that references some classic 2D images, sometimes called 'refMaps' or 'sampler' images.\n * This is the base class of any Procedural texture and contains most of the shareable code.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/proceduralTextures\n * @param name Define the name of the texture\n * @param size Define the size of the texture to create\n * @param fragment Define the fragment shader to use to generate the texture or null if it is defined later\n * @param scene Define the scene the texture belongs to\n * @param fallbackTexture Define a fallback texture in case there were issues to create the custom texture\n * @param generateMipMaps Define if the texture should creates mip maps or not\n * @param isCube Define if the texture is a cube texture or not (this will render each faces of the cube)\n * @param textureType The FBO internal texture type\n */\n constructor(name, size, fragment, scene, fallbackTexture = null, generateMipMaps = true, isCube = false, textureType = 0) {\n super(null, scene, !generateMipMaps);\n /**\n * Define if the texture is enabled or not (disabled texture will not render)\n */\n this.isEnabled = true;\n /**\n * Define if the texture must be cleared before rendering (default is true)\n */\n this.autoClear = true;\n /**\n * Event raised when the texture is generated\n */\n this.onGeneratedObservable = new Observable$1();\n /**\n * Event raised before the texture is generated\n */\n this.onBeforeGenerationObservable = new Observable$1();\n /**\n * Gets or sets the node material used to create this texture (null if the texture was manually created)\n */\n this.nodeMaterialSource = null;\n /** @internal */\n this._textures = {};\n this._currentRefreshId = -1;\n this._frameId = -1;\n this._refreshRate = 1;\n this._vertexBuffers = {};\n this._uniforms = new Array();\n this._samplers = new Array();\n this._floats = {};\n this._ints = {};\n this._floatsArrays = {};\n this._colors3 = {};\n this._colors4 = {};\n this._vectors2 = {};\n this._vectors3 = {};\n this._matrices = {};\n this._fallbackTextureUsed = false;\n this._cachedDefines = null;\n this._contentUpdateId = -1;\n this._rtWrapper = null;\n scene = this.getScene() || EngineStore.LastCreatedScene;\n let component = scene._getComponent(SceneComponentConstants.NAME_PROCEDURALTEXTURE);\n if (!component) {\n component = new ProceduralTextureSceneComponent(scene);\n scene._addComponent(component);\n }\n scene.proceduralTextures.push(this);\n this._fullEngine = scene.getEngine();\n this.name = name;\n this.isRenderTarget = true;\n this._size = size;\n this._textureType = textureType;\n this._generateMipMaps = generateMipMaps;\n this._drawWrapper = new DrawWrapper(this._fullEngine);\n this.setFragment(fragment);\n this._fallbackTexture = fallbackTexture;\n const rtWrapper = this._createRtWrapper(isCube, size, generateMipMaps, textureType);\n this._texture = rtWrapper.texture;\n // VBO\n const vertices = [];\n vertices.push(1, 1);\n vertices.push(-1, 1);\n vertices.push(-1, -1);\n vertices.push(1, -1);\n this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(this._fullEngine, vertices, VertexBuffer.PositionKind, false, false, 2);\n this._createIndexBuffer();\n }\n _createRtWrapper(isCube, size, generateMipMaps, textureType) {\n if (isCube) {\n this._rtWrapper = this._fullEngine.createRenderTargetCubeTexture(size, {\n generateMipMaps: generateMipMaps,\n generateDepthBuffer: false,\n generateStencilBuffer: false,\n type: textureType,\n });\n this.setFloat(\"face\", 0);\n }\n else {\n this._rtWrapper = this._fullEngine.createRenderTargetTexture(size, {\n generateMipMaps: generateMipMaps,\n generateDepthBuffer: false,\n generateStencilBuffer: false,\n type: textureType,\n });\n }\n return this._rtWrapper;\n }\n /**\n * The effect that is created when initializing the post process.\n * @returns The created effect corresponding the the postprocess.\n */\n getEffect() {\n return this._drawWrapper.effect;\n }\n /**\n * @internal*\n */\n _setEffect(effect) {\n this._drawWrapper.effect = effect;\n }\n /**\n * Gets texture content (Use this function wisely as reading from a texture can be slow)\n * @returns an ArrayBufferView promise (Uint8Array or Float32Array)\n */\n getContent() {\n if (this._contentData && this._frameId === this._contentUpdateId) {\n return this._contentData;\n }\n if (this._contentData) {\n this._contentData.then((buffer) => {\n this._contentData = this.readPixels(0, 0, buffer);\n this._contentUpdateId = this._frameId;\n });\n }\n else {\n this._contentData = this.readPixels(0, 0);\n this._contentUpdateId = this._frameId;\n }\n return this._contentData;\n }\n _createIndexBuffer() {\n const engine = this._fullEngine;\n // Indices\n const indices = [];\n indices.push(0);\n indices.push(1);\n indices.push(2);\n indices.push(0);\n indices.push(2);\n indices.push(3);\n this._indexBuffer = engine.createIndexBuffer(indices);\n }\n /** @internal */\n _rebuild() {\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\n if (vb) {\n vb._rebuild();\n }\n this._createIndexBuffer();\n if (this.refreshRate === RenderTargetTexture.REFRESHRATE_RENDER_ONCE) {\n this.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;\n }\n }\n /**\n * Resets the texture in order to recreate its associated resources.\n * This can be called in case of context loss\n */\n reset() {\n var _a;\n (_a = this._drawWrapper.effect) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n _getDefines() {\n return \"\";\n }\n /**\n * Is the texture ready to be used ? (rendered at least once)\n * @returns true if ready, otherwise, false.\n */\n isReady() {\n const engine = this._fullEngine;\n let shaders;\n if (this.nodeMaterialSource) {\n return this._drawWrapper.effect.isReady();\n }\n if (!this._fragment) {\n return false;\n }\n if (this._fallbackTextureUsed) {\n return true;\n }\n if (!this._texture) {\n return false;\n }\n const defines = this._getDefines();\n if (this._drawWrapper.effect && defines === this._cachedDefines && this._drawWrapper.effect.isReady()) {\n return true;\n }\n if (this._fragment.fragmentElement !== undefined) {\n shaders = { vertex: \"procedural\", fragmentElement: this._fragment.fragmentElement };\n }\n else {\n shaders = { vertex: \"procedural\", fragment: this._fragment };\n }\n if (this._cachedDefines !== defines) {\n this._cachedDefines = defines;\n this._drawWrapper.effect = engine.createEffect(shaders, [VertexBuffer.PositionKind], this._uniforms, this._samplers, defines, undefined, undefined, () => {\n var _a;\n (_a = this._rtWrapper) === null || _a === void 0 ? void 0 : _a.dispose();\n this._rtWrapper = this._texture = null;\n if (this._fallbackTexture) {\n this._texture = this._fallbackTexture._texture;\n if (this._texture) {\n this._texture.incrementReferences();\n }\n }\n this._fallbackTextureUsed = true;\n });\n }\n return this._drawWrapper.effect.isReady();\n }\n /**\n * Resets the refresh counter of the texture and start bak from scratch.\n * Could be useful to regenerate the texture if it is setup to render only once.\n */\n resetRefreshCounter() {\n this._currentRefreshId = -1;\n }\n /**\n * Set the fragment shader to use in order to render the texture.\n * @param fragment This can be set to a path (into the shader store) or to a json object containing a fragmentElement property.\n */\n setFragment(fragment) {\n this._fragment = fragment;\n }\n /**\n * Define the refresh rate of the texture or the rendering frequency.\n * Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...\n */\n get refreshRate() {\n return this._refreshRate;\n }\n set refreshRate(value) {\n this._refreshRate = value;\n this.resetRefreshCounter();\n }\n /** @internal */\n _shouldRender() {\n if (!this.isEnabled || !this.isReady() || !this._texture) {\n if (this._texture) {\n this._texture.isReady = false;\n }\n return false;\n }\n if (this._fallbackTextureUsed) {\n return false;\n }\n if (this._currentRefreshId === -1) {\n // At least render once\n this._currentRefreshId = 1;\n this._frameId++;\n return true;\n }\n if (this.refreshRate === this._currentRefreshId) {\n this._currentRefreshId = 1;\n this._frameId++;\n return true;\n }\n this._currentRefreshId++;\n return false;\n }\n /**\n * Get the size the texture is rendering at.\n * @returns the size (on cube texture it is always squared)\n */\n getRenderSize() {\n return this._size;\n }\n /**\n * Resize the texture to new value.\n * @param size Define the new size the texture should have\n * @param generateMipMaps Define whether the new texture should create mip maps\n */\n resize(size, generateMipMaps) {\n if (this._fallbackTextureUsed || !this._rtWrapper || !this._texture) {\n return;\n }\n const isCube = this._texture.isCube;\n this._rtWrapper.dispose();\n const rtWrapper = this._createRtWrapper(isCube, size, generateMipMaps, this._textureType);\n this._texture = rtWrapper.texture;\n // Update properties\n this._size = size;\n this._generateMipMaps = generateMipMaps;\n }\n _checkUniform(uniformName) {\n if (this._uniforms.indexOf(uniformName) === -1) {\n this._uniforms.push(uniformName);\n }\n }\n /**\n * Set a texture in the shader program used to render.\n * @param name Define the name of the uniform samplers as defined in the shader\n * @param texture Define the texture to bind to this sampler\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setTexture(name, texture) {\n if (this._samplers.indexOf(name) === -1) {\n this._samplers.push(name);\n }\n this._textures[name] = texture;\n return this;\n }\n /**\n * Set a float in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setFloat(name, value) {\n this._checkUniform(name);\n this._floats[name] = value;\n return this;\n }\n /**\n * Set a int in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setInt(name, value) {\n this._checkUniform(name);\n this._ints[name] = value;\n return this;\n }\n /**\n * Set an array of floats in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setFloats(name, value) {\n this._checkUniform(name);\n this._floatsArrays[name] = value;\n return this;\n }\n /**\n * Set a vec3 in the shader from a Color3.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setColor3(name, value) {\n this._checkUniform(name);\n this._colors3[name] = value;\n return this;\n }\n /**\n * Set a vec4 in the shader from a Color4.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setColor4(name, value) {\n this._checkUniform(name);\n this._colors4[name] = value;\n return this;\n }\n /**\n * Set a vec2 in the shader from a Vector2.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setVector2(name, value) {\n this._checkUniform(name);\n this._vectors2[name] = value;\n return this;\n }\n /**\n * Set a vec3 in the shader from a Vector3.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setVector3(name, value) {\n this._checkUniform(name);\n this._vectors3[name] = value;\n return this;\n }\n /**\n * Set a mat4 in the shader from a MAtrix.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the texture itself allowing \"fluent\" like uniform updates\n */\n setMatrix(name, value) {\n this._checkUniform(name);\n this._matrices[name] = value;\n return this;\n }\n /**\n * Render the texture to its associated render target.\n * @param useCameraPostProcess Define if camera post process should be applied to the texture\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n render(useCameraPostProcess) {\n var _a, _b;\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n const engine = this._fullEngine;\n // Render\n engine.enableEffect(this._drawWrapper);\n this.onBeforeGenerationObservable.notifyObservers(this);\n engine.setState(false);\n if (!this.nodeMaterialSource) {\n // Texture\n for (const name in this._textures) {\n this._drawWrapper.effect.setTexture(name, this._textures[name]);\n }\n // Float\n for (const name in this._ints) {\n this._drawWrapper.effect.setInt(name, this._ints[name]);\n }\n // Float\n for (const name in this._floats) {\n this._drawWrapper.effect.setFloat(name, this._floats[name]);\n }\n // Floats\n for (const name in this._floatsArrays) {\n this._drawWrapper.effect.setArray(name, this._floatsArrays[name]);\n }\n // Color3\n for (const name in this._colors3) {\n this._drawWrapper.effect.setColor3(name, this._colors3[name]);\n }\n // Color4\n for (const name in this._colors4) {\n const color = this._colors4[name];\n this._drawWrapper.effect.setFloat4(name, color.r, color.g, color.b, color.a);\n }\n // Vector2\n for (const name in this._vectors2) {\n this._drawWrapper.effect.setVector2(name, this._vectors2[name]);\n }\n // Vector3\n for (const name in this._vectors3) {\n this._drawWrapper.effect.setVector3(name, this._vectors3[name]);\n }\n // Matrix\n for (const name in this._matrices) {\n this._drawWrapper.effect.setMatrix(name, this._matrices[name]);\n }\n }\n if (!this._texture || !this._rtWrapper) {\n return;\n }\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, `procedural texture generation for ${this.name}`, 1);\n const viewPort = engine.currentViewport;\n if (this.isCube) {\n for (let face = 0; face < 6; face++) {\n engine.bindFramebuffer(this._rtWrapper, face, undefined, undefined, true);\n // VBOs\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._drawWrapper.effect);\n this._drawWrapper.effect.setFloat(\"face\", face);\n // Clear\n if (this.autoClear) {\n engine.clear(scene.clearColor, true, false, false);\n }\n // Draw order\n engine.drawElementsType(Material.TriangleFillMode, 0, 6);\n }\n }\n else {\n engine.bindFramebuffer(this._rtWrapper, 0, undefined, undefined, true);\n // VBOs\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._drawWrapper.effect);\n // Clear\n if (this.autoClear) {\n engine.clear(scene.clearColor, true, false, false);\n }\n // Draw order\n engine.drawElementsType(Material.TriangleFillMode, 0, 6);\n }\n // Unbind and restore viewport\n engine.unBindFramebuffer(this._rtWrapper, this.isCube);\n if (viewPort) {\n engine.setViewport(viewPort);\n }\n // Mipmaps\n if (this.isCube) {\n engine.generateMipMapsForCubemap(this._texture);\n }\n (_b = engine._debugPopGroup) === null || _b === void 0 ? void 0 : _b.call(engine, 1);\n if (this.onGenerated) {\n this.onGenerated();\n }\n this.onGeneratedObservable.notifyObservers(this);\n }\n /**\n * Clone the texture.\n * @returns the cloned texture\n */\n clone() {\n const textureSize = this.getSize();\n const newTexture = new ProceduralTexture(this.name, textureSize.width, this._fragment, this.getScene(), this._fallbackTexture, this._generateMipMaps);\n // Base texture\n newTexture.hasAlpha = this.hasAlpha;\n newTexture.level = this.level;\n // RenderTarget Texture\n newTexture.coordinatesMode = this.coordinatesMode;\n return newTexture;\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n const scene = this.getScene();\n if (!scene) {\n return;\n }\n const index = scene.proceduralTextures.indexOf(this);\n if (index >= 0) {\n scene.proceduralTextures.splice(index, 1);\n }\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\n if (vertexBuffer) {\n vertexBuffer.dispose();\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\n }\n if (this._indexBuffer && this._fullEngine._releaseBuffer(this._indexBuffer)) {\n this._indexBuffer = null;\n }\n this.onGeneratedObservable.clear();\n this.onBeforeGenerationObservable.clear();\n super.dispose();\n }\n }\n __decorate$1([\n serialize()\n ], ProceduralTexture.prototype, \"isEnabled\", void 0);\n __decorate$1([\n serialize()\n ], ProceduralTexture.prototype, \"autoClear\", void 0);\n __decorate$1([\n serialize()\n ], ProceduralTexture.prototype, \"_generateMipMaps\", void 0);\n __decorate$1([\n serialize()\n ], ProceduralTexture.prototype, \"_size\", void 0);\n __decorate$1([\n serialize()\n ], ProceduralTexture.prototype, \"refreshRate\", null);\n RegisterClass(\"BABYLON.ProceduralTexture\", ProceduralTexture);\n\n /**\n * Operations supported by the Trigonometry block\n */\n var TrigonometryBlockOperations;\n (function (TrigonometryBlockOperations) {\n /** Cos */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Cos\"] = 0] = \"Cos\";\n /** Sin */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Sin\"] = 1] = \"Sin\";\n /** Abs */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Abs\"] = 2] = \"Abs\";\n /** Exp */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Exp\"] = 3] = \"Exp\";\n /** Exp2 */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Exp2\"] = 4] = \"Exp2\";\n /** Round */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Round\"] = 5] = \"Round\";\n /** Floor */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Floor\"] = 6] = \"Floor\";\n /** Ceiling */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Ceiling\"] = 7] = \"Ceiling\";\n /** Square root */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Sqrt\"] = 8] = \"Sqrt\";\n /** Log */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Log\"] = 9] = \"Log\";\n /** Tangent */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Tan\"] = 10] = \"Tan\";\n /** Arc tangent */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"ArcTan\"] = 11] = \"ArcTan\";\n /** Arc cosinus */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"ArcCos\"] = 12] = \"ArcCos\";\n /** Arc sinus */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"ArcSin\"] = 13] = \"ArcSin\";\n /** Fraction */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Fract\"] = 14] = \"Fract\";\n /** Sign */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Sign\"] = 15] = \"Sign\";\n /** To radians (from degrees) */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Radians\"] = 16] = \"Radians\";\n /** To degrees (from radians) */\n TrigonometryBlockOperations[TrigonometryBlockOperations[\"Degrees\"] = 17] = \"Degrees\";\n })(TrigonometryBlockOperations || (TrigonometryBlockOperations = {}));\n /**\n * Block used to apply trigonometry operation to floats\n */\n class TrigonometryBlock extends NodeMaterialBlock {\n /**\n * Creates a new TrigonometryBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n /**\n * Gets or sets the operation applied by the block\n */\n this.operation = TrigonometryBlockOperations.Cos;\n this.registerInput(\"input\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.BasedOnInput);\n this._outputs[0]._typeConnectionSource = this._inputs[0];\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"TrigonometryBlock\";\n }\n /**\n * Gets the input component\n */\n get input() {\n return this._inputs[0];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n const output = this._outputs[0];\n let operation = \"\";\n switch (this.operation) {\n case TrigonometryBlockOperations.Cos: {\n operation = \"cos\";\n break;\n }\n case TrigonometryBlockOperations.Sin: {\n operation = \"sin\";\n break;\n }\n case TrigonometryBlockOperations.Abs: {\n operation = \"abs\";\n break;\n }\n case TrigonometryBlockOperations.Exp: {\n operation = \"exp\";\n break;\n }\n case TrigonometryBlockOperations.Exp2: {\n operation = \"exp2\";\n break;\n }\n case TrigonometryBlockOperations.Round: {\n operation = \"round\";\n break;\n }\n case TrigonometryBlockOperations.Floor: {\n operation = \"floor\";\n break;\n }\n case TrigonometryBlockOperations.Ceiling: {\n operation = \"ceil\";\n break;\n }\n case TrigonometryBlockOperations.Sqrt: {\n operation = \"sqrt\";\n break;\n }\n case TrigonometryBlockOperations.Log: {\n operation = \"log\";\n break;\n }\n case TrigonometryBlockOperations.Tan: {\n operation = \"tan\";\n break;\n }\n case TrigonometryBlockOperations.ArcTan: {\n operation = \"atan\";\n break;\n }\n case TrigonometryBlockOperations.ArcCos: {\n operation = \"acos\";\n break;\n }\n case TrigonometryBlockOperations.ArcSin: {\n operation = \"asin\";\n break;\n }\n case TrigonometryBlockOperations.Fract: {\n operation = \"fract\";\n break;\n }\n case TrigonometryBlockOperations.Sign: {\n operation = \"sign\";\n break;\n }\n case TrigonometryBlockOperations.Radians: {\n operation = \"radians\";\n break;\n }\n case TrigonometryBlockOperations.Degrees: {\n operation = \"degrees\";\n break;\n }\n }\n state.compilationString += this._declareOutput(output, state) + ` = ${operation}(${this.input.associatedVariableName});\\n`;\n return this;\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.operation = this.operation;\n return serializationObject;\n }\n _deserialize(serializationObject, scene, rootUrl) {\n super._deserialize(serializationObject, scene, rootUrl);\n this.operation = serializationObject.operation;\n }\n _dumpPropertiesCode() {\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.operation = BABYLON.TrigonometryBlockOperations.${TrigonometryBlockOperations[this.operation]};\\n`;\n return codeString;\n }\n }\n RegisterClass(\"BABYLON.TrigonometryBlock\", TrigonometryBlock);\n\n const onCreatedEffectParameters$2 = { effect: null, subMesh: null };\n /** @internal */\n class NodeMaterialDefines extends MaterialDefines {\n constructor() {\n super();\n this.NORMAL = false;\n this.TANGENT = false;\n this.VERTEXCOLOR_NME = false;\n this.UV1 = false;\n this.UV2 = false;\n this.UV3 = false;\n this.UV4 = false;\n this.UV5 = false;\n this.UV6 = false;\n /** BONES */\n this.NUM_BONE_INFLUENCERS = 0;\n this.BonesPerMesh = 0;\n this.BONETEXTURE = false;\n /** MORPH TARGETS */\n this.MORPHTARGETS = false;\n this.MORPHTARGETS_NORMAL = false;\n this.MORPHTARGETS_TANGENT = false;\n this.MORPHTARGETS_UV = false;\n this.NUM_MORPH_INFLUENCERS = 0;\n this.MORPHTARGETS_TEXTURE = false;\n /** IMAGE PROCESSING */\n this.IMAGEPROCESSING = false;\n this.VIGNETTE = false;\n this.VIGNETTEBLENDMODEMULTIPLY = false;\n this.VIGNETTEBLENDMODEOPAQUE = false;\n this.TONEMAPPING = false;\n this.TONEMAPPING_ACES = false;\n this.CONTRAST = false;\n this.EXPOSURE = false;\n this.COLORCURVES = false;\n this.COLORGRADING = false;\n this.COLORGRADING3D = false;\n this.SAMPLER3DGREENDEPTH = false;\n this.SAMPLER3DBGRMAP = false;\n this.DITHER = false;\n this.IMAGEPROCESSINGPOSTPROCESS = false;\n this.SKIPFINALCOLORCLAMP = false;\n /** MISC. */\n this.BUMPDIRECTUV = 0;\n this.CAMERA_ORTHOGRAPHIC = false;\n this.CAMERA_PERSPECTIVE = false;\n this.rebuild();\n }\n setValue(name, value, markAsUnprocessedIfDirty = false) {\n if (this[name] === undefined) {\n this._keys.push(name);\n }\n if (markAsUnprocessedIfDirty && this[name] !== value) {\n this.markAsUnprocessed();\n }\n this[name] = value;\n }\n }\n /**\n * Class used to create a node based material built by assembling shader blocks\n */\n class NodeMaterial extends PushMaterial {\n /**\n * Checks if a block is a texture block\n * @param block The block to check\n * @returns True if the block is a texture block\n */\n static _BlockIsTextureBlock(block) {\n return (block.getClassName() === \"TextureBlock\" ||\n block.getClassName() === \"ReflectionTextureBaseBlock\" ||\n block.getClassName() === \"RefractionBlock\" ||\n block.getClassName() === \"CurrentScreenBlock\" ||\n block.getClassName() === \"ParticleTextureBlock\" ||\n block.getClassName() === \"ImageSourceBlock\" ||\n block.getClassName() === \"TriPlanarBlock\" ||\n block.getClassName() === \"BiPlanarBlock\");\n }\n /** Get the inspector from bundle or global */\n _getGlobalNodeMaterialEditor() {\n // UMD Global name detection from Webpack Bundle UMD Name.\n if (typeof NODEEDITOR !== \"undefined\") {\n return NODEEDITOR;\n }\n // In case of module let's check the global emitted from the editor entry point.\n if (typeof BABYLON !== \"undefined\" && typeof BABYLON.NodeEditor !== \"undefined\") {\n return BABYLON;\n }\n return undefined;\n }\n /** Gets or sets options to control the node material overall behavior */\n get options() {\n return this._options;\n }\n set options(options) {\n this._options = options;\n }\n /**\n * Gets the image processing configuration used either in this material.\n */\n get imageProcessingConfiguration() {\n return this._imageProcessingConfiguration;\n }\n /**\n * Sets the Default image processing configuration used either in the this material.\n *\n * If sets to null, the scene one is in use.\n */\n set imageProcessingConfiguration(value) {\n this._attachImageProcessingConfiguration(value);\n // Ensure the effect will be rebuilt.\n this._markAllSubMeshesAsTexturesDirty();\n }\n /**\n * Gets or sets the mode property\n */\n get mode() {\n return this._mode;\n }\n set mode(value) {\n this._mode = value;\n }\n /** Gets or sets the unique identifier used to identified the effect associated with the material */\n get buildId() {\n return this._buildId;\n }\n set buildId(value) {\n this._buildId = value;\n }\n /**\n * Create a new node based material\n * @param name defines the material name\n * @param scene defines the hosting scene\n * @param options defines creation option\n */\n constructor(name, scene, options = {}) {\n super(name, scene || EngineStore.LastCreatedScene);\n this._buildId = NodeMaterial._BuildIdGenerator++;\n this._buildWasSuccessful = false;\n this._cachedWorldViewMatrix = new Matrix();\n this._cachedWorldViewProjectionMatrix = new Matrix();\n this._optimizers = new Array();\n this._animationFrame = -1;\n this.BJSNODEMATERIALEDITOR = this._getGlobalNodeMaterialEditor();\n /**\n * Gets or sets data used by visual editor\n * @see https://nme.babylonjs.com\n */\n this.editorData = null;\n /**\n * Gets or sets a boolean indicating that alpha value must be ignored (This will turn alpha blending off even if an alpha value is produced by the material)\n */\n this.ignoreAlpha = false;\n /**\n * Defines the maximum number of lights that can be used in the material\n */\n this.maxSimultaneousLights = 4;\n /**\n * Observable raised when the material is built\n */\n this.onBuildObservable = new Observable$1();\n /**\n * Gets or sets the root nodes of the material vertex shader\n */\n this._vertexOutputNodes = new Array();\n /**\n * Gets or sets the root nodes of the material fragment (pixel) shader\n */\n this._fragmentOutputNodes = new Array();\n /**\n * Gets an array of blocks that needs to be serialized even if they are not yet connected\n */\n this.attachedBlocks = new Array();\n /**\n * Specifies the mode of the node material\n * @internal\n */\n this._mode = NodeMaterialModes.Material;\n /**\n * Gets or sets a boolean indicating that alpha blending must be enabled no matter what alpha value or alpha channel of the FragmentBlock are\n */\n this.forceAlphaBlending = false;\n this._options = Object.assign({ emitComments: false }, options);\n // Setup the default processing configuration to the scene.\n this._attachImageProcessingConfiguration(null);\n }\n /**\n * Gets the current class name of the material e.g. \"NodeMaterial\"\n * @returns the class name\n */\n getClassName() {\n return \"NodeMaterial\";\n }\n /**\n * Attaches a new image processing configuration to the Standard Material.\n * @param configuration\n */\n _attachImageProcessingConfiguration(configuration) {\n if (configuration === this._imageProcessingConfiguration) {\n return;\n }\n // Detaches observer.\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n }\n // Pick the scene configuration if needed.\n if (!configuration) {\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\n }\n else {\n this._imageProcessingConfiguration = configuration;\n }\n // Attaches observer.\n if (this._imageProcessingConfiguration) {\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\n this._markAllSubMeshesAsImageProcessingDirty();\n });\n }\n }\n /**\n * Get a block by its name\n * @param name defines the name of the block to retrieve\n * @returns the required block or null if not found\n */\n getBlockByName(name) {\n let result = null;\n for (const block of this.attachedBlocks) {\n if (block.name === name) {\n if (!result) {\n result = block;\n }\n else {\n Tools.Warn(\"More than one block was found with the name `\" + name + \"`\");\n return result;\n }\n }\n }\n return result;\n }\n /**\n * Get a block by its name\n * @param predicate defines the predicate used to find the good candidate\n * @returns the required block or null if not found\n */\n getBlockByPredicate(predicate) {\n for (const block of this.attachedBlocks) {\n if (predicate(block)) {\n return block;\n }\n }\n return null;\n }\n /**\n * Get an input block by its name\n * @param predicate defines the predicate used to find the good candidate\n * @returns the required input block or null if not found\n */\n getInputBlockByPredicate(predicate) {\n for (const block of this.attachedBlocks) {\n if (block.isInput && predicate(block)) {\n return block;\n }\n }\n return null;\n }\n /**\n * Gets the list of input blocks attached to this material\n * @returns an array of InputBlocks\n */\n getInputBlocks() {\n const blocks = [];\n for (const block of this.attachedBlocks) {\n if (block.isInput) {\n blocks.push(block);\n }\n }\n return blocks;\n }\n /**\n * Adds a new optimizer to the list of optimizers\n * @param optimizer defines the optimizers to add\n * @returns the current material\n */\n registerOptimizer(optimizer) {\n const index = this._optimizers.indexOf(optimizer);\n if (index > -1) {\n return;\n }\n this._optimizers.push(optimizer);\n return this;\n }\n /**\n * Remove an optimizer from the list of optimizers\n * @param optimizer defines the optimizers to remove\n * @returns the current material\n */\n unregisterOptimizer(optimizer) {\n const index = this._optimizers.indexOf(optimizer);\n if (index === -1) {\n return;\n }\n this._optimizers.splice(index, 1);\n return this;\n }\n /**\n * Add a new block to the list of output nodes\n * @param node defines the node to add\n * @returns the current material\n */\n addOutputNode(node) {\n if (node.target === null) {\n throw \"This node is not meant to be an output node. You may want to explicitly set its target value.\";\n }\n if ((node.target & NodeMaterialBlockTargets.Vertex) !== 0) {\n this._addVertexOutputNode(node);\n }\n if ((node.target & NodeMaterialBlockTargets.Fragment) !== 0) {\n this._addFragmentOutputNode(node);\n }\n return this;\n }\n /**\n * Remove a block from the list of root nodes\n * @param node defines the node to remove\n * @returns the current material\n */\n removeOutputNode(node) {\n if (node.target === null) {\n return this;\n }\n if ((node.target & NodeMaterialBlockTargets.Vertex) !== 0) {\n this._removeVertexOutputNode(node);\n }\n if ((node.target & NodeMaterialBlockTargets.Fragment) !== 0) {\n this._removeFragmentOutputNode(node);\n }\n return this;\n }\n _addVertexOutputNode(node) {\n if (this._vertexOutputNodes.indexOf(node) !== -1) {\n return;\n }\n node.target = NodeMaterialBlockTargets.Vertex;\n this._vertexOutputNodes.push(node);\n return this;\n }\n _removeVertexOutputNode(node) {\n const index = this._vertexOutputNodes.indexOf(node);\n if (index === -1) {\n return;\n }\n this._vertexOutputNodes.splice(index, 1);\n return this;\n }\n _addFragmentOutputNode(node) {\n if (this._fragmentOutputNodes.indexOf(node) !== -1) {\n return;\n }\n node.target = NodeMaterialBlockTargets.Fragment;\n this._fragmentOutputNodes.push(node);\n return this;\n }\n _removeFragmentOutputNode(node) {\n const index = this._fragmentOutputNodes.indexOf(node);\n if (index === -1) {\n return;\n }\n this._fragmentOutputNodes.splice(index, 1);\n return this;\n }\n /**\n * Specifies if the material will require alpha blending\n * @returns a boolean specifying if alpha blending is needed\n */\n needAlphaBlending() {\n if (this.ignoreAlpha) {\n return false;\n }\n return this.forceAlphaBlending || this.alpha < 1.0 || (this._sharedData && this._sharedData.hints.needAlphaBlending);\n }\n /**\n * Specifies if this material should be rendered in alpha test mode\n * @returns a boolean specifying if an alpha test is needed.\n */\n needAlphaTesting() {\n return this._sharedData && this._sharedData.hints.needAlphaTesting;\n }\n _processInitializeOnLink(block, state, nodesToProcessForOtherBuildState, autoConfigure = true) {\n if (block.target === NodeMaterialBlockTargets.VertexAndFragment) {\n nodesToProcessForOtherBuildState.push(block);\n }\n else if (state.target === NodeMaterialBlockTargets.Fragment && block.target === NodeMaterialBlockTargets.Vertex && block._preparationId !== this._buildId) {\n nodesToProcessForOtherBuildState.push(block);\n }\n this._initializeBlock(block, state, nodesToProcessForOtherBuildState, autoConfigure);\n }\n _initializeBlock(node, state, nodesToProcessForOtherBuildState, autoConfigure = true) {\n node.initialize(state);\n if (autoConfigure) {\n node.autoConfigure(this);\n }\n node._preparationId = this._buildId;\n if (this.attachedBlocks.indexOf(node) === -1) {\n if (node.isUnique) {\n const className = node.getClassName();\n for (const other of this.attachedBlocks) {\n if (other.getClassName() === className) {\n throw `Cannot have multiple blocks of type ${className} in the same NodeMaterial`;\n }\n }\n }\n this.attachedBlocks.push(node);\n }\n for (const input of node.inputs) {\n input.associatedVariableName = \"\";\n const connectedPoint = input.connectedPoint;\n if (connectedPoint) {\n const block = connectedPoint.ownerBlock;\n if (block !== node) {\n this._processInitializeOnLink(block, state, nodesToProcessForOtherBuildState, autoConfigure);\n }\n }\n }\n // Teleportation\n if (node.isTeleportOut) {\n const teleport = node;\n if (teleport.entryPoint) {\n this._processInitializeOnLink(teleport.entryPoint, state, nodesToProcessForOtherBuildState, autoConfigure);\n }\n }\n for (const output of node.outputs) {\n output.associatedVariableName = \"\";\n }\n }\n _resetDualBlocks(node, id) {\n if (node.target === NodeMaterialBlockTargets.VertexAndFragment) {\n node.buildId = id;\n }\n for (const inputs of node.inputs) {\n const connectedPoint = inputs.connectedPoint;\n if (connectedPoint) {\n const block = connectedPoint.ownerBlock;\n if (block !== node) {\n this._resetDualBlocks(block, id);\n }\n }\n }\n // If this is a teleport out, we need to reset the connected block\n if (node.isTeleportOut) {\n const teleportOut = node;\n if (teleportOut.entryPoint) {\n this._resetDualBlocks(teleportOut.entryPoint, id);\n }\n }\n }\n /**\n * Remove a block from the current node material\n * @param block defines the block to remove\n */\n removeBlock(block) {\n const attachedBlockIndex = this.attachedBlocks.indexOf(block);\n if (attachedBlockIndex > -1) {\n this.attachedBlocks.splice(attachedBlockIndex, 1);\n }\n if (block.isFinalMerger) {\n this.removeOutputNode(block);\n }\n }\n /**\n * Build the material and generates the inner effect\n * @param verbose defines if the build should log activity\n * @param updateBuildId defines if the internal build Id should be updated (default is true)\n * @param autoConfigure defines if the autoConfigure method should be called when initializing blocks (default is true)\n */\n build(verbose = false, updateBuildId = true, autoConfigure = true) {\n this._buildWasSuccessful = false;\n const engine = this.getScene().getEngine();\n const allowEmptyVertexProgram = this._mode === NodeMaterialModes.Particle;\n if (this._vertexOutputNodes.length === 0 && !allowEmptyVertexProgram) {\n throw \"You must define at least one vertexOutputNode\";\n }\n if (this._fragmentOutputNodes.length === 0) {\n throw \"You must define at least one fragmentOutputNode\";\n }\n // Compilation state\n this._vertexCompilationState = new NodeMaterialBuildState();\n this._vertexCompilationState.supportUniformBuffers = engine.supportsUniformBuffers;\n this._vertexCompilationState.target = NodeMaterialBlockTargets.Vertex;\n this._fragmentCompilationState = new NodeMaterialBuildState();\n this._fragmentCompilationState.supportUniformBuffers = engine.supportsUniformBuffers;\n this._fragmentCompilationState.target = NodeMaterialBlockTargets.Fragment;\n // Shared data\n this._sharedData = new NodeMaterialBuildStateSharedData();\n this._sharedData.fragmentOutputNodes = this._fragmentOutputNodes;\n this._vertexCompilationState.sharedData = this._sharedData;\n this._fragmentCompilationState.sharedData = this._sharedData;\n this._sharedData.buildId = this._buildId;\n this._sharedData.emitComments = this._options.emitComments;\n this._sharedData.verbose = verbose;\n this._sharedData.scene = this.getScene();\n this._sharedData.allowEmptyVertexProgram = allowEmptyVertexProgram;\n // Initialize blocks\n const vertexNodes = [];\n const fragmentNodes = [];\n for (const vertexOutputNode of this._vertexOutputNodes) {\n vertexNodes.push(vertexOutputNode);\n this._initializeBlock(vertexOutputNode, this._vertexCompilationState, fragmentNodes, autoConfigure);\n }\n for (const fragmentOutputNode of this._fragmentOutputNodes) {\n fragmentNodes.push(fragmentOutputNode);\n this._initializeBlock(fragmentOutputNode, this._fragmentCompilationState, vertexNodes, autoConfigure);\n }\n // Optimize\n this.optimize();\n // Vertex\n for (const vertexOutputNode of vertexNodes) {\n vertexOutputNode.build(this._vertexCompilationState, vertexNodes);\n }\n // Fragment\n this._fragmentCompilationState.uniforms = this._vertexCompilationState.uniforms.slice(0);\n this._fragmentCompilationState._uniformDeclaration = this._vertexCompilationState._uniformDeclaration;\n this._fragmentCompilationState._constantDeclaration = this._vertexCompilationState._constantDeclaration;\n this._fragmentCompilationState._vertexState = this._vertexCompilationState;\n for (const fragmentOutputNode of fragmentNodes) {\n this._resetDualBlocks(fragmentOutputNode, this._buildId - 1);\n }\n for (const fragmentOutputNode of fragmentNodes) {\n fragmentOutputNode.build(this._fragmentCompilationState, fragmentNodes);\n }\n // Finalize\n this._vertexCompilationState.finalize(this._vertexCompilationState);\n this._fragmentCompilationState.finalize(this._fragmentCompilationState);\n if (updateBuildId) {\n this._buildId = NodeMaterial._BuildIdGenerator++;\n }\n // Errors\n this._sharedData.emitErrors();\n if (verbose) {\n console.log(\"Vertex shader:\");\n console.log(this._vertexCompilationState.compilationString);\n console.log(\"Fragment shader:\");\n console.log(this._fragmentCompilationState.compilationString);\n }\n this._buildWasSuccessful = true;\n this.onBuildObservable.notifyObservers(this);\n // Wipe defines\n const meshes = this.getScene().meshes;\n for (const mesh of meshes) {\n if (!mesh.subMeshes) {\n continue;\n }\n for (const subMesh of mesh.subMeshes) {\n if (subMesh.getMaterial() !== this) {\n continue;\n }\n if (!subMesh.materialDefines) {\n continue;\n }\n const defines = subMesh.materialDefines;\n defines.markAllAsDirty();\n defines.reset();\n }\n }\n }\n /**\n * Runs an otpimization phase to try to improve the shader code\n */\n optimize() {\n for (const optimizer of this._optimizers) {\n optimizer.optimize(this._vertexOutputNodes, this._fragmentOutputNodes);\n }\n }\n _prepareDefinesForAttributes(mesh, defines) {\n const oldNormal = defines[\"NORMAL\"];\n const oldTangent = defines[\"TANGENT\"];\n const oldColor = defines[\"VERTEXCOLOR_NME\"];\n defines[\"NORMAL\"] = mesh.isVerticesDataPresent(VertexBuffer.NormalKind);\n defines[\"TANGENT\"] = mesh.isVerticesDataPresent(VertexBuffer.TangentKind);\n const hasVertexColors = mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind);\n defines[\"VERTEXCOLOR_NME\"] = hasVertexColors;\n let uvChanged = false;\n for (let i = 1; i <= 6; ++i) {\n const oldUV = defines[\"UV\" + i];\n defines[\"UV\" + i] = mesh.isVerticesDataPresent(`uv${i === 1 ? \"\" : i}`);\n uvChanged = uvChanged || defines[\"UV\" + i] !== oldUV;\n }\n if (oldNormal !== defines[\"NORMAL\"] || oldTangent !== defines[\"TANGENT\"] || oldColor !== defines[\"VERTEXCOLOR_NME\"] || uvChanged) {\n defines.markAsAttributesDirty();\n }\n }\n /**\n * Create a post process from the material\n * @param camera The camera to apply the render pass to.\n * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\n * @param engine The engine which the post process will be applied. (default: current engine)\n * @param reusable If the post process can be reused on the same frame. (default: false)\n * @param textureType Type of textures used when performing the post process. (default: 0)\n * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)\n * @returns the post process created\n */\n createPostProcess(camera, options = 1, samplingMode = 1, engine, reusable, textureType = 0, textureFormat = 5) {\n if (this.mode !== NodeMaterialModes.PostProcess) {\n console.log(\"Incompatible material mode\");\n return null;\n }\n return this._createEffectForPostProcess(null, camera, options, samplingMode, engine, reusable, textureType, textureFormat);\n }\n /**\n * Create the post process effect from the material\n * @param postProcess The post process to create the effect for\n */\n createEffectForPostProcess(postProcess) {\n this._createEffectForPostProcess(postProcess);\n }\n _createEffectForPostProcess(postProcess, camera, options = 1, samplingMode = 1, engine, reusable, textureType = 0, textureFormat = 5) {\n let tempName = this.name + this._buildId;\n const defines = new NodeMaterialDefines();\n const dummyMesh = new AbstractMesh(tempName + \"PostProcess\", this.getScene());\n let buildId = this._buildId;\n this._processDefines(dummyMesh, defines);\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\n if (!postProcess) {\n postProcess = new PostProcess(this.name + \"PostProcess\", tempName, this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, options, camera, samplingMode, engine, reusable, defines.toString(), textureType, tempName, { maxSimultaneousLights: this.maxSimultaneousLights }, false, textureFormat);\n }\n else {\n postProcess.updateEffect(defines.toString(), this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, { maxSimultaneousLights: this.maxSimultaneousLights }, undefined, undefined, tempName, tempName);\n }\n postProcess.nodeMaterialSource = this;\n postProcess.onApplyObservable.add((effect) => {\n if (buildId !== this._buildId) {\n delete Effect.ShadersStore[tempName + \"VertexShader\"];\n delete Effect.ShadersStore[tempName + \"PixelShader\"];\n tempName = this.name + this._buildId;\n defines.markAllAsDirty();\n buildId = this._buildId;\n }\n const result = this._processDefines(dummyMesh, defines);\n if (result) {\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\n TimingTools.SetImmediate(() => postProcess.updateEffect(defines.toString(), this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, { maxSimultaneousLights: this.maxSimultaneousLights }, undefined, undefined, tempName, tempName));\n }\n this._checkInternals(effect);\n });\n return postProcess;\n }\n /**\n * Create a new procedural texture based on this node material\n * @param size defines the size of the texture\n * @param scene defines the hosting scene\n * @returns the new procedural texture attached to this node material\n */\n createProceduralTexture(size, scene) {\n if (this.mode !== NodeMaterialModes.ProceduralTexture) {\n console.log(\"Incompatible material mode\");\n return null;\n }\n let tempName = this.name + this._buildId;\n const proceduralTexture = new ProceduralTexture(tempName, size, null, scene);\n const dummyMesh = new AbstractMesh(tempName + \"Procedural\", this.getScene());\n dummyMesh.reservedDataStore = {\n hidden: true,\n };\n const defines = new NodeMaterialDefines();\n const result = this._processDefines(dummyMesh, defines);\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\n let effect = this.getScene().getEngine().createEffect({\n vertexElement: tempName,\n fragmentElement: tempName,\n }, [VertexBuffer.PositionKind], this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, defines.toString(), result === null || result === void 0 ? void 0 : result.fallbacks, undefined);\n proceduralTexture.nodeMaterialSource = this;\n proceduralTexture._setEffect(effect);\n let buildId = this._buildId;\n proceduralTexture.onBeforeGenerationObservable.add(() => {\n if (buildId !== this._buildId) {\n delete Effect.ShadersStore[tempName + \"VertexShader\"];\n delete Effect.ShadersStore[tempName + \"PixelShader\"];\n tempName = this.name + this._buildId;\n defines.markAllAsDirty();\n buildId = this._buildId;\n }\n const result = this._processDefines(dummyMesh, defines);\n if (result) {\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\n TimingTools.SetImmediate(() => {\n effect = this.getScene().getEngine().createEffect({\n vertexElement: tempName,\n fragmentElement: tempName,\n }, [VertexBuffer.PositionKind], this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, defines.toString(), result === null || result === void 0 ? void 0 : result.fallbacks, undefined);\n proceduralTexture._setEffect(effect);\n });\n }\n this._checkInternals(effect);\n });\n return proceduralTexture;\n }\n _createEffectForParticles(particleSystem, blendMode, onCompiled, onError, effect, defines, dummyMesh, particleSystemDefinesJoined = \"\") {\n let tempName = this.name + this._buildId + \"_\" + blendMode;\n if (!defines) {\n defines = new NodeMaterialDefines();\n }\n if (!dummyMesh) {\n dummyMesh = this.getScene().getMeshByName(this.name + \"Particle\");\n if (!dummyMesh) {\n dummyMesh = new AbstractMesh(this.name + \"Particle\", this.getScene());\n dummyMesh.reservedDataStore = {\n hidden: true,\n };\n }\n }\n let buildId = this._buildId;\n const particleSystemDefines = [];\n let join = particleSystemDefinesJoined;\n if (!effect) {\n const result = this._processDefines(dummyMesh, defines);\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString);\n particleSystem.fillDefines(particleSystemDefines, blendMode);\n join = particleSystemDefines.join(\"\\n\");\n effect = this.getScene()\n .getEngine()\n .createEffectForParticles(tempName, this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, defines.toString() + \"\\n\" + join, result === null || result === void 0 ? void 0 : result.fallbacks, onCompiled, onError, particleSystem);\n particleSystem.setCustomEffect(effect, blendMode);\n }\n effect.onBindObservable.add((effect) => {\n if (buildId !== this._buildId) {\n delete Effect.ShadersStore[tempName + \"PixelShader\"];\n tempName = this.name + this._buildId + \"_\" + blendMode;\n defines.markAllAsDirty();\n buildId = this._buildId;\n }\n particleSystemDefines.length = 0;\n particleSystem.fillDefines(particleSystemDefines, blendMode);\n const particleSystemDefinesJoinedCurrent = particleSystemDefines.join(\"\\n\");\n if (particleSystemDefinesJoinedCurrent !== join) {\n defines.markAllAsDirty();\n join = particleSystemDefinesJoinedCurrent;\n }\n const result = this._processDefines(dummyMesh, defines);\n if (result) {\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString);\n effect = this.getScene()\n .getEngine()\n .createEffectForParticles(tempName, this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, defines.toString() + \"\\n\" + join, result === null || result === void 0 ? void 0 : result.fallbacks, onCompiled, onError, particleSystem);\n particleSystem.setCustomEffect(effect, blendMode);\n this._createEffectForParticles(particleSystem, blendMode, onCompiled, onError, effect, defines, dummyMesh, particleSystemDefinesJoined); // add the effect.onBindObservable observer\n return;\n }\n this._checkInternals(effect);\n });\n }\n _checkInternals(effect) {\n // Animated blocks\n if (this._sharedData.animatedInputs) {\n const scene = this.getScene();\n const frameId = scene.getFrameId();\n if (this._animationFrame !== frameId) {\n for (const input of this._sharedData.animatedInputs) {\n input.animate(scene);\n }\n this._animationFrame = frameId;\n }\n }\n // Bindable blocks\n for (const block of this._sharedData.bindableBlocks) {\n block.bind(effect, this);\n }\n // Connection points\n for (const inputBlock of this._sharedData.inputBlocks) {\n inputBlock._transmit(effect, this.getScene(), this);\n }\n }\n /**\n * Create the effect to be used as the custom effect for a particle system\n * @param particleSystem Particle system to create the effect for\n * @param onCompiled defines a function to call when the effect creation is successful\n * @param onError defines a function to call when the effect creation has failed\n */\n createEffectForParticles(particleSystem, onCompiled, onError) {\n if (this.mode !== NodeMaterialModes.Particle) {\n console.log(\"Incompatible material mode\");\n return;\n }\n this._createEffectForParticles(particleSystem, BaseParticleSystem.BLENDMODE_ONEONE, onCompiled, onError);\n this._createEffectForParticles(particleSystem, BaseParticleSystem.BLENDMODE_MULTIPLY, onCompiled, onError);\n }\n /**\n * Use this material as the shadow depth wrapper of a target material\n * @param targetMaterial defines the target material\n */\n createAsShadowDepthWrapper(targetMaterial) {\n if (this.mode !== NodeMaterialModes.Material) {\n console.log(\"Incompatible material mode\");\n return;\n }\n targetMaterial.shadowDepthWrapper = new BABYLON.ShadowDepthWrapper(this, this.getScene());\n }\n _processDefines(mesh, defines, useInstances = false, subMesh) {\n let result = null;\n // Global defines\n const scene = this.getScene();\n if (MaterialHelper.PrepareDefinesForCamera(scene, defines)) {\n defines.markAsMiscDirty();\n }\n // Shared defines\n this._sharedData.blocksWithDefines.forEach((b) => {\n b.initializeDefines(mesh, this, defines, useInstances);\n });\n this._sharedData.blocksWithDefines.forEach((b) => {\n b.prepareDefines(mesh, this, defines, useInstances, subMesh);\n });\n // Need to recompile?\n if (defines.isDirty) {\n const lightDisposed = defines._areLightsDisposed;\n defines.markAsProcessed();\n // Repeatable content generators\n this._vertexCompilationState.compilationString = this._vertexCompilationState._builtCompilationString;\n this._fragmentCompilationState.compilationString = this._fragmentCompilationState._builtCompilationString;\n this._sharedData.repeatableContentBlocks.forEach((b) => {\n b.replaceRepeatableContent(this._vertexCompilationState, this._fragmentCompilationState, mesh, defines);\n });\n // Uniforms\n const uniformBuffers = [];\n this._sharedData.dynamicUniformBlocks.forEach((b) => {\n b.updateUniformsAndSamples(this._vertexCompilationState, this, defines, uniformBuffers);\n });\n const mergedUniforms = this._vertexCompilationState.uniforms;\n this._fragmentCompilationState.uniforms.forEach((u) => {\n const index = mergedUniforms.indexOf(u);\n if (index === -1) {\n mergedUniforms.push(u);\n }\n });\n // Samplers\n const mergedSamplers = this._vertexCompilationState.samplers;\n this._fragmentCompilationState.samplers.forEach((s) => {\n const index = mergedSamplers.indexOf(s);\n if (index === -1) {\n mergedSamplers.push(s);\n }\n });\n const fallbacks = new EffectFallbacks();\n this._sharedData.blocksWithFallbacks.forEach((b) => {\n b.provideFallbacks(mesh, fallbacks);\n });\n result = {\n lightDisposed,\n uniformBuffers,\n mergedUniforms,\n mergedSamplers,\n fallbacks,\n };\n }\n return result;\n }\n /**\n * Get if the submesh is ready to be used and all its information available.\n * Child classes can use it to update shaders\n * @param mesh defines the mesh to check\n * @param subMesh defines which submesh to check\n * @param useInstances specifies that instances should be used\n * @returns a boolean indicating that the submesh is ready or not\n */\n isReadyForSubMesh(mesh, subMesh, useInstances = false) {\n if (!this._buildWasSuccessful) {\n return false;\n }\n const scene = this.getScene();\n if (this._sharedData.animatedInputs) {\n const frameId = scene.getFrameId();\n if (this._animationFrame !== frameId) {\n for (const input of this._sharedData.animatedInputs) {\n input.animate(scene);\n }\n this._animationFrame = frameId;\n }\n }\n if (subMesh.effect && this.isFrozen) {\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\n return true;\n }\n }\n if (!subMesh.materialDefines) {\n subMesh.materialDefines = new NodeMaterialDefines();\n }\n const defines = subMesh.materialDefines;\n if (this._isReadyForSubMesh(subMesh)) {\n return true;\n }\n const engine = scene.getEngine();\n this._prepareDefinesForAttributes(mesh, defines);\n // Check if blocks are ready\n if (this._sharedData.blockingBlocks.some((b) => !b.isReady(mesh, this, defines, useInstances))) {\n return false;\n }\n const result = this._processDefines(mesh, defines, useInstances, subMesh);\n if (result) {\n const previousEffect = subMesh.effect;\n // Compilation\n const join = defines.toString();\n let effect = engine.createEffect({\n vertex: \"nodeMaterial\" + this._buildId,\n fragment: \"nodeMaterial\" + this._buildId,\n vertexSource: this._vertexCompilationState.compilationString,\n fragmentSource: this._fragmentCompilationState.compilationString,\n }, {\n attributes: this._vertexCompilationState.attributes,\n uniformsNames: result.mergedUniforms,\n uniformBuffersNames: result.uniformBuffers,\n samplers: result.mergedSamplers,\n defines: join,\n fallbacks: result.fallbacks,\n onCompiled: this.onCompiled,\n onError: this.onError,\n indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS },\n }, engine);\n if (effect) {\n if (this._onEffectCreatedObservable) {\n onCreatedEffectParameters$2.effect = effect;\n onCreatedEffectParameters$2.subMesh = subMesh;\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters$2);\n }\n // Use previous effect while new one is compiling\n if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {\n effect = previousEffect;\n defines.markAsUnprocessed();\n if (result.lightDisposed) {\n // re register in case it takes more than one frame.\n defines._areLightsDisposed = true;\n return false;\n }\n }\n else {\n scene.resetCachedMaterial();\n subMesh.setEffect(effect, defines, this._materialContext);\n }\n }\n }\n if (!subMesh.effect || !subMesh.effect.isReady()) {\n return false;\n }\n defines._renderId = scene.getRenderId();\n subMesh.effect._wasPreviouslyReady = true;\n subMesh.effect._wasPreviouslyUsingInstances = useInstances;\n this._checkScenePerformancePriority();\n return true;\n }\n /**\n * Get a string representing the shaders built by the current node graph\n */\n get compiledShaders() {\n return `// Vertex shader\\n${this._vertexCompilationState.compilationString}\\n\\n// Fragment shader\\n${this._fragmentCompilationState.compilationString}`;\n }\n /**\n * Binds the world matrix to the material\n * @param world defines the world transformation matrix\n */\n bindOnlyWorldMatrix(world) {\n const scene = this.getScene();\n if (!this._activeEffect) {\n return;\n }\n const hints = this._sharedData.hints;\n if (hints.needWorldViewMatrix) {\n world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);\n }\n if (hints.needWorldViewProjectionMatrix) {\n world.multiplyToRef(scene.getTransformMatrix(), this._cachedWorldViewProjectionMatrix);\n }\n // Connection points\n for (const inputBlock of this._sharedData.inputBlocks) {\n inputBlock._transmitWorld(this._activeEffect, world, this._cachedWorldViewMatrix, this._cachedWorldViewProjectionMatrix);\n }\n }\n /**\n * Binds the submesh to this material by preparing the effect and shader to draw\n * @param world defines the world transformation matrix\n * @param mesh defines the mesh containing the submesh\n * @param subMesh defines the submesh to bind the material to\n */\n bindForSubMesh(world, mesh, subMesh) {\n const scene = this.getScene();\n const effect = subMesh.effect;\n if (!effect) {\n return;\n }\n this._activeEffect = effect;\n // Matrices\n this.bindOnlyWorldMatrix(world);\n const mustRebind = this._mustRebind(scene, effect, mesh.visibility);\n const sharedData = this._sharedData;\n if (mustRebind) {\n // Bindable blocks\n for (const block of sharedData.bindableBlocks) {\n block.bind(effect, this, mesh, subMesh);\n }\n for (const block of sharedData.forcedBindableBlocks) {\n block.bind(effect, this, mesh, subMesh);\n }\n // Connection points\n for (const inputBlock of sharedData.inputBlocks) {\n inputBlock._transmit(effect, scene, this);\n }\n }\n else if (!this.isFrozen) {\n for (const block of sharedData.forcedBindableBlocks) {\n block.bind(effect, this, mesh, subMesh);\n }\n }\n this._afterBind(mesh, this._activeEffect);\n }\n /**\n * Gets the active textures from the material\n * @returns an array of textures\n */\n getActiveTextures() {\n const activeTextures = super.getActiveTextures();\n if (this._sharedData) {\n activeTextures.push(...this._sharedData.textureBlocks.filter((tb) => tb.texture).map((tb) => tb.texture));\n }\n return activeTextures;\n }\n /**\n * Gets the list of texture blocks\n * Note that this method will only return blocks that are reachable from the final block(s) and only after the material has been built!\n * @returns an array of texture blocks\n */\n getTextureBlocks() {\n if (!this._sharedData) {\n return [];\n }\n return this._sharedData.textureBlocks;\n }\n /**\n * Gets the list of all texture blocks\n * Note that this method will scan all attachedBlocks and return blocks that are texture blocks\n * @returns\n */\n getAllTextureBlocks() {\n const textureBlocks = [];\n for (const block of this.attachedBlocks) {\n if (NodeMaterial._BlockIsTextureBlock(block)) {\n textureBlocks.push(block);\n }\n }\n return textureBlocks;\n }\n /**\n * Specifies if the material uses a texture\n * @param texture defines the texture to check against the material\n * @returns a boolean specifying if the material uses the texture\n */\n hasTexture(texture) {\n if (super.hasTexture(texture)) {\n return true;\n }\n if (!this._sharedData) {\n return false;\n }\n for (const t of this._sharedData.textureBlocks) {\n if (t.texture === texture) {\n return true;\n }\n }\n return false;\n }\n /**\n * Disposes the material\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\n * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh\n */\n dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh) {\n if (forceDisposeTextures) {\n for (const texture of this.getTextureBlocks()\n .filter((tb) => tb.texture)\n .map((tb) => tb.texture)) {\n texture.dispose();\n }\n }\n for (const block of this.attachedBlocks) {\n block.dispose();\n }\n this.attachedBlocks.length = 0;\n this._sharedData = null;\n this._vertexCompilationState = null;\n this._fragmentCompilationState = null;\n this.onBuildObservable.clear();\n if (this._imageProcessingObserver) {\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\n this._imageProcessingObserver = null;\n }\n super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);\n }\n /** Creates the node editor window. */\n _createNodeEditor(additionalConfig) {\n const nodeEditorConfig = Object.assign({ nodeMaterial: this }, additionalConfig);\n this.BJSNODEMATERIALEDITOR.NodeEditor.Show(nodeEditorConfig);\n }\n /**\n * Launch the node material editor\n * @param config Define the configuration of the editor\n * @returns a promise fulfilled when the node editor is visible\n */\n edit(config) {\n return new Promise((resolve) => {\n this.BJSNODEMATERIALEDITOR = this.BJSNODEMATERIALEDITOR || this._getGlobalNodeMaterialEditor();\n if (typeof this.BJSNODEMATERIALEDITOR == \"undefined\") {\n const editorUrl = config && config.editorURL ? config.editorURL : NodeMaterial.EditorURL;\n // Load editor and add it to the DOM\n Tools.LoadScript(editorUrl, () => {\n this.BJSNODEMATERIALEDITOR = this.BJSNODEMATERIALEDITOR || this._getGlobalNodeMaterialEditor();\n this._createNodeEditor(config === null || config === void 0 ? void 0 : config.nodeEditorConfig);\n resolve();\n });\n }\n else {\n // Otherwise creates the editor\n this._createNodeEditor(config === null || config === void 0 ? void 0 : config.nodeEditorConfig);\n resolve();\n }\n });\n }\n /**\n * Clear the current material\n */\n clear() {\n this._vertexOutputNodes.length = 0;\n this._fragmentOutputNodes.length = 0;\n this.attachedBlocks.length = 0;\n }\n /**\n * Clear the current material and set it to a default state\n */\n setToDefault() {\n this.clear();\n this.editorData = null;\n const positionInput = new InputBlock(\"Position\");\n positionInput.setAsAttribute(\"position\");\n const worldInput = new InputBlock(\"World\");\n worldInput.setAsSystemValue(NodeMaterialSystemValues.World);\n const worldPos = new TransformBlock(\"WorldPos\");\n positionInput.connectTo(worldPos);\n worldInput.connectTo(worldPos);\n const viewProjectionInput = new InputBlock(\"ViewProjection\");\n viewProjectionInput.setAsSystemValue(NodeMaterialSystemValues.ViewProjection);\n const worldPosdMultipliedByViewProjection = new TransformBlock(\"WorldPos * ViewProjectionTransform\");\n worldPos.connectTo(worldPosdMultipliedByViewProjection);\n viewProjectionInput.connectTo(worldPosdMultipliedByViewProjection);\n const vertexOutput = new VertexOutputBlock(\"VertexOutput\");\n worldPosdMultipliedByViewProjection.connectTo(vertexOutput);\n // Pixel\n const pixelColor = new InputBlock(\"color\");\n pixelColor.value = new Color4(0.8, 0.8, 0.8, 1);\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\n pixelColor.connectTo(fragmentOutput);\n // Add to nodes\n this.addOutputNode(vertexOutput);\n this.addOutputNode(fragmentOutput);\n this._mode = NodeMaterialModes.Material;\n }\n /**\n * Clear the current material and set it to a default state for post process\n */\n setToDefaultPostProcess() {\n this.clear();\n this.editorData = null;\n const position = new InputBlock(\"Position\");\n position.setAsAttribute(\"position2d\");\n const const1 = new InputBlock(\"Constant1\");\n const1.isConstant = true;\n const1.value = 1;\n const vmerger = new VectorMergerBlock(\"Position3D\");\n position.connectTo(vmerger);\n const1.connectTo(vmerger, { input: \"w\" });\n const vertexOutput = new VertexOutputBlock(\"VertexOutput\");\n vmerger.connectTo(vertexOutput);\n // Pixel\n const scale = new InputBlock(\"Scale\");\n scale.visibleInInspector = true;\n scale.value = new Vector2(1, 1);\n const uv0 = new RemapBlock(\"uv0\");\n position.connectTo(uv0);\n const uv = new MultiplyBlock(\"UV scale\");\n uv0.connectTo(uv);\n scale.connectTo(uv);\n const currentScreen = new CurrentScreenBlock(\"CurrentScreen\");\n uv.connectTo(currentScreen);\n currentScreen.texture = new Texture(\"https://assets.babylonjs.com/nme/currentScreenPostProcess.png\", this.getScene());\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\n currentScreen.connectTo(fragmentOutput, { output: \"rgba\" });\n // Add to nodes\n this.addOutputNode(vertexOutput);\n this.addOutputNode(fragmentOutput);\n this._mode = NodeMaterialModes.PostProcess;\n }\n /**\n * Clear the current material and set it to a default state for procedural texture\n */\n setToDefaultProceduralTexture() {\n this.clear();\n this.editorData = null;\n const position = new InputBlock(\"Position\");\n position.setAsAttribute(\"position2d\");\n const const1 = new InputBlock(\"Constant1\");\n const1.isConstant = true;\n const1.value = 1;\n const vmerger = new VectorMergerBlock(\"Position3D\");\n position.connectTo(vmerger);\n const1.connectTo(vmerger, { input: \"w\" });\n const vertexOutput = new VertexOutputBlock(\"VertexOutput\");\n vmerger.connectTo(vertexOutput);\n // Pixel\n const time = new InputBlock(\"Time\");\n time.value = 0;\n time.min = 0;\n time.max = 0;\n time.isBoolean = false;\n time.matrixMode = 0;\n time.animationType = AnimatedInputBlockTypes.Time;\n time.isConstant = false;\n const color = new InputBlock(\"Color3\");\n color.value = new Color3(1, 1, 1);\n color.isConstant = false;\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\n const vectorMerger = new VectorMergerBlock(\"VectorMerger\");\n vectorMerger.visibleInInspector = false;\n const cos = new TrigonometryBlock(\"Cos\");\n cos.operation = TrigonometryBlockOperations.Cos;\n position.connectTo(vectorMerger);\n time.output.connectTo(cos.input);\n cos.output.connectTo(vectorMerger.z);\n vectorMerger.xyzOut.connectTo(fragmentOutput.rgb);\n // Add to nodes\n this.addOutputNode(vertexOutput);\n this.addOutputNode(fragmentOutput);\n this._mode = NodeMaterialModes.ProceduralTexture;\n }\n /**\n * Clear the current material and set it to a default state for particle\n */\n setToDefaultParticle() {\n this.clear();\n this.editorData = null;\n // Pixel\n const uv = new InputBlock(\"uv\");\n uv.setAsAttribute(\"particle_uv\");\n const texture = new ParticleTextureBlock(\"ParticleTexture\");\n uv.connectTo(texture);\n const color = new InputBlock(\"Color\");\n color.setAsAttribute(\"particle_color\");\n const multiply = new MultiplyBlock(\"Texture * Color\");\n texture.connectTo(multiply);\n color.connectTo(multiply);\n const rampGradient = new ParticleRampGradientBlock(\"ParticleRampGradient\");\n multiply.connectTo(rampGradient);\n const cSplitter = new ColorSplitterBlock(\"ColorSplitter\");\n color.connectTo(cSplitter);\n const blendMultiply = new ParticleBlendMultiplyBlock(\"ParticleBlendMultiply\");\n rampGradient.connectTo(blendMultiply);\n texture.connectTo(blendMultiply, { output: \"a\" });\n cSplitter.connectTo(blendMultiply, { output: \"a\" });\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\n blendMultiply.connectTo(fragmentOutput);\n // Add to nodes\n this.addOutputNode(fragmentOutput);\n this._mode = NodeMaterialModes.Particle;\n }\n /**\n * Loads the current Node Material from a url pointing to a file save by the Node Material Editor\n * @deprecated Please use NodeMaterial.ParseFromFileAsync instead\n * @param url defines the url to load from\n * @param rootUrl defines the root URL for nested url in the node material\n * @returns a promise that will fulfil when the material is fully loaded\n */\n async loadAsync(url, rootUrl = \"\") {\n return NodeMaterial.ParseFromFileAsync(\"\", url, this.getScene(), rootUrl, true, this);\n }\n _gatherBlocks(rootNode, list) {\n if (list.indexOf(rootNode) !== -1) {\n return;\n }\n list.push(rootNode);\n for (const input of rootNode.inputs) {\n const connectedPoint = input.connectedPoint;\n if (connectedPoint) {\n const block = connectedPoint.ownerBlock;\n if (block !== rootNode) {\n this._gatherBlocks(block, list);\n }\n }\n }\n // Teleportation\n if (rootNode.isTeleportOut) {\n const block = rootNode;\n if (block.entryPoint) {\n this._gatherBlocks(block.entryPoint, list);\n }\n }\n }\n /**\n * Generate a string containing the code declaration required to create an equivalent of this material\n * @returns a string\n */\n generateCode() {\n let alreadyDumped = [];\n const vertexBlocks = [];\n const uniqueNames = [\"const\", \"var\", \"let\"];\n // Gets active blocks\n for (const outputNode of this._vertexOutputNodes) {\n this._gatherBlocks(outputNode, vertexBlocks);\n }\n const fragmentBlocks = [];\n for (const outputNode of this._fragmentOutputNodes) {\n this._gatherBlocks(outputNode, fragmentBlocks);\n }\n // Generate vertex shader\n let codeString = `var nodeMaterial = new BABYLON.NodeMaterial(\"${this.name || \"node material\"}\");\\n`;\n codeString += `nodeMaterial.mode = BABYLON.NodeMaterialModes.${NodeMaterialModes[this.mode]};\\n`;\n for (const node of vertexBlocks) {\n if (node.isInput && alreadyDumped.indexOf(node) === -1) {\n codeString += node._dumpCode(uniqueNames, alreadyDumped);\n }\n }\n // Generate fragment shader\n for (const node of fragmentBlocks) {\n if (node.isInput && alreadyDumped.indexOf(node) === -1) {\n codeString += node._dumpCode(uniqueNames, alreadyDumped);\n }\n }\n // Connections\n alreadyDumped = [];\n codeString += \"\\n// Connections\\n\";\n for (const node of this._vertexOutputNodes) {\n codeString += node._dumpCodeForOutputConnections(alreadyDumped);\n }\n for (const node of this._fragmentOutputNodes) {\n codeString += node._dumpCodeForOutputConnections(alreadyDumped);\n }\n // Output nodes\n codeString += \"\\n// Output nodes\\n\";\n for (const node of this._vertexOutputNodes) {\n codeString += `nodeMaterial.addOutputNode(${node._codeVariableName});\\n`;\n }\n for (const node of this._fragmentOutputNodes) {\n codeString += `nodeMaterial.addOutputNode(${node._codeVariableName});\\n`;\n }\n codeString += `nodeMaterial.build();\\n`;\n return codeString;\n }\n /**\n * Serializes this material in a JSON representation\n * @param selectedBlocks\n * @returns the serialized material object\n */\n serialize(selectedBlocks) {\n const serializationObject = selectedBlocks ? {} : SerializationHelper.Serialize(this);\n serializationObject.editorData = JSON.parse(JSON.stringify(this.editorData)); // Copy\n let blocks = [];\n if (selectedBlocks) {\n blocks = selectedBlocks;\n }\n else {\n serializationObject.customType = \"BABYLON.NodeMaterial\";\n serializationObject.outputNodes = [];\n // Outputs\n for (const outputNode of this._vertexOutputNodes) {\n this._gatherBlocks(outputNode, blocks);\n serializationObject.outputNodes.push(outputNode.uniqueId);\n }\n for (const outputNode of this._fragmentOutputNodes) {\n this._gatherBlocks(outputNode, blocks);\n if (serializationObject.outputNodes.indexOf(outputNode.uniqueId) === -1) {\n serializationObject.outputNodes.push(outputNode.uniqueId);\n }\n }\n }\n // Blocks\n serializationObject.blocks = [];\n for (const block of blocks) {\n serializationObject.blocks.push(block.serialize());\n }\n if (!selectedBlocks) {\n for (const block of this.attachedBlocks) {\n if (blocks.indexOf(block) !== -1) {\n continue;\n }\n serializationObject.blocks.push(block.serialize());\n }\n }\n return serializationObject;\n }\n _restoreConnections(block, source, map) {\n for (const outputPoint of block.outputs) {\n for (const candidate of source.blocks) {\n const target = map[candidate.id];\n if (!target) {\n continue;\n }\n for (const input of candidate.inputs) {\n if (map[input.targetBlockId] === block && input.targetConnectionName === outputPoint.name) {\n const inputPoint = target.getInputByName(input.inputName);\n if (!inputPoint || inputPoint.isConnected) {\n continue;\n }\n outputPoint.connectTo(inputPoint, true);\n this._restoreConnections(target, source, map);\n continue;\n }\n }\n }\n }\n }\n /**\n * Clear the current graph and load a new one from a serialization object\n * @param source defines the JSON representation of the material\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @param merge defines whether or not the source must be merged or replace the current content\n */\n parseSerializedObject(source, rootUrl = \"\", merge = false) {\n var _a;\n if (!merge) {\n this.clear();\n }\n const map = {};\n // Create blocks\n for (const parsedBlock of source.blocks) {\n const blockType = GetClass(parsedBlock.customType);\n if (blockType) {\n const block = new blockType();\n block._deserialize(parsedBlock, this.getScene(), rootUrl);\n map[parsedBlock.id] = block;\n this.attachedBlocks.push(block);\n }\n }\n // Reconnect teleportation\n for (const block of this.attachedBlocks) {\n if (block.isTeleportOut) {\n const teleportOut = block;\n const id = teleportOut._tempEntryPointUniqueId;\n if (id) {\n const source = map[id];\n source.attachToEndpoint(teleportOut);\n }\n }\n }\n // Connections - Starts with input blocks only (except if in \"merge\" mode where we scan all blocks)\n for (let blockIndex = 0; blockIndex < source.blocks.length; blockIndex++) {\n const parsedBlock = source.blocks[blockIndex];\n const block = map[parsedBlock.id];\n if (!block) {\n continue;\n }\n if (block.inputs.length && !merge) {\n continue;\n }\n this._restoreConnections(block, source, map);\n }\n // Outputs\n if (source.outputNodes) {\n for (const outputNodeId of source.outputNodes) {\n this.addOutputNode(map[outputNodeId]);\n }\n }\n // UI related info\n if (source.locations || (source.editorData && source.editorData.locations)) {\n const locations = source.locations || source.editorData.locations;\n for (const location of locations) {\n if (map[location.blockId]) {\n location.blockId = map[location.blockId].uniqueId;\n }\n }\n if (merge && this.editorData && this.editorData.locations) {\n locations.concat(this.editorData.locations);\n }\n if (source.locations) {\n this.editorData = {\n locations: locations,\n };\n }\n else {\n this.editorData = source.editorData;\n this.editorData.locations = locations;\n }\n const blockMap = [];\n for (const key in map) {\n blockMap[key] = map[key].uniqueId;\n }\n this.editorData.map = blockMap;\n }\n this.comment = source.comment;\n if (source.forceAlphaBlending !== undefined) {\n this.forceAlphaBlending = source.forceAlphaBlending;\n }\n if (!merge) {\n this._mode = (_a = source.mode) !== null && _a !== void 0 ? _a : NodeMaterialModes.Material;\n }\n }\n /**\n * Clear the current graph and load a new one from a serialization object\n * @param source defines the JSON representation of the material\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @param merge defines whether or not the source must be merged or replace the current content\n * @deprecated Please use the parseSerializedObject method instead\n */\n loadFromSerialization(source, rootUrl = \"\", merge = false) {\n this.parseSerializedObject(source, rootUrl, merge);\n }\n /**\n * Makes a duplicate of the current material.\n * @param name defines the name to use for the new material\n * @param shareEffect defines if the clone material should share the same effect (default is false)\n */\n clone(name, shareEffect = false) {\n const serializationObject = this.serialize();\n const clone = SerializationHelper.Clone(() => new NodeMaterial(name, this.getScene(), this.options), this);\n clone.id = name;\n clone.name = name;\n clone.parseSerializedObject(serializationObject);\n clone._buildId = this._buildId;\n clone.build(false, !shareEffect);\n return clone;\n }\n /**\n * Creates a node material from parsed material data\n * @param source defines the JSON representation of the material\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a new node material\n */\n static Parse(source, scene, rootUrl = \"\") {\n const nodeMaterial = SerializationHelper.Parse(() => new NodeMaterial(source.name, scene), source, scene, rootUrl);\n nodeMaterial.parseSerializedObject(source, rootUrl);\n nodeMaterial.build();\n return nodeMaterial;\n }\n /**\n * Creates a node material from a snippet saved in a remote file\n * @param name defines the name of the material to create\n * @param url defines the url to load from\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL for nested url in the node material\n * @param skipBuild defines whether to build the node material\n * @param targetMaterial defines a material to use instead of creating a new one\n * @returns a promise that will resolve to the new node material\n */\n static async ParseFromFileAsync(name, url, scene, rootUrl = \"\", skipBuild = false, targetMaterial) {\n const material = targetMaterial !== null && targetMaterial !== void 0 ? targetMaterial : new NodeMaterial(name, scene);\n const data = await scene._loadFileAsync(url);\n const serializationObject = JSON.parse(data);\n material.parseSerializedObject(serializationObject, rootUrl);\n if (!skipBuild) {\n material.build();\n }\n return material;\n }\n /**\n * Creates a node material from a snippet saved by the node material editor\n * @param snippetId defines the snippet to load\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @param nodeMaterial defines a node material to update (instead of creating a new one)\n * @param skipBuild defines whether to build the node material\n * @returns a promise that will resolve to the new node material\n */\n static ParseFromSnippetAsync(snippetId, scene = EngineStore.LastCreatedScene, rootUrl = \"\", nodeMaterial, skipBuild = false) {\n if (snippetId === \"_BLANK\") {\n return Promise.resolve(NodeMaterial.CreateDefault(\"blank\", scene));\n }\n return new Promise((resolve, reject) => {\n const request = new WebRequest();\n request.addEventListener(\"readystatechange\", () => {\n if (request.readyState == 4) {\n if (request.status == 200) {\n const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);\n const serializationObject = JSON.parse(snippet.nodeMaterial);\n if (!nodeMaterial) {\n nodeMaterial = SerializationHelper.Parse(() => new NodeMaterial(snippetId, scene), serializationObject, scene, rootUrl);\n nodeMaterial.uniqueId = scene.getUniqueId();\n }\n nodeMaterial.parseSerializedObject(serializationObject);\n nodeMaterial.snippetId = snippetId;\n try {\n if (!skipBuild) {\n nodeMaterial.build();\n }\n resolve(nodeMaterial);\n }\n catch (err) {\n reject(err);\n }\n }\n else {\n reject(\"Unable to load the snippet \" + snippetId);\n }\n }\n });\n request.open(\"GET\", this.SnippetUrl + \"/\" + snippetId.replace(/#/g, \"/\"));\n request.send();\n });\n }\n /**\n * Creates a new node material set to default basic configuration\n * @param name defines the name of the material\n * @param scene defines the hosting scene\n * @returns a new NodeMaterial\n */\n static CreateDefault(name, scene) {\n const newMaterial = new NodeMaterial(name, scene);\n newMaterial.setToDefault();\n newMaterial.build();\n return newMaterial;\n }\n }\n NodeMaterial._BuildIdGenerator = 0;\n /** Define the Url to load node editor script */\n NodeMaterial.EditorURL = `https://unpkg.com/babylonjs-node-editor@${Engine.Version}/babylon.nodeEditor.js`;\n /** Define the Url to load snippets */\n NodeMaterial.SnippetUrl = `https://snippet.babylonjs.com`;\n /** Gets or sets a boolean indicating that node materials should not deserialize textures from json / snippet content */\n NodeMaterial.IgnoreTexturesAtLoadTime = false;\n __decorate$1([\n serialize()\n ], NodeMaterial.prototype, \"ignoreAlpha\", void 0);\n __decorate$1([\n serialize()\n ], NodeMaterial.prototype, \"maxSimultaneousLights\", void 0);\n __decorate$1([\n serialize(\"mode\")\n ], NodeMaterial.prototype, \"_mode\", void 0);\n __decorate$1([\n serialize(\"comment\")\n ], NodeMaterial.prototype, \"comment\", void 0);\n __decorate$1([\n serialize()\n ], NodeMaterial.prototype, \"forceAlphaBlending\", void 0);\n RegisterClass(\"BABYLON.NodeMaterial\", NodeMaterial);\n\n /**\n * @internal\n */\n SubMesh.prototype._projectOnTrianglesToRef = function (vector, positions, indices, step, checkStopper, ref) {\n // Triangles test\n const proj = TmpVectors.Vector3[0];\n const tmp = TmpVectors.Vector3[1];\n let distance = +Infinity;\n for (let index = this.indexStart; index < this.indexStart + this.indexCount - (3 - step); index += step) {\n const indexA = indices[index];\n const indexB = indices[index + 1];\n const indexC = indices[index + 2];\n if (checkStopper && indexC === 0xffffffff) {\n index += 2;\n continue;\n }\n const p0 = positions[indexA];\n const p1 = positions[indexB];\n const p2 = positions[indexC];\n // stay defensive and don't check against undefined positions.\n if (!p0 || !p1 || !p2) {\n continue;\n }\n const tmpDist = Vector3.ProjectOnTriangleToRef(vector, p0, p1, p2, tmp);\n if (tmpDist < distance) {\n proj.copyFrom(tmp);\n distance = tmpDist;\n }\n }\n ref.copyFrom(proj);\n return distance;\n };\n /**\n * @internal\n */\n SubMesh.prototype._projectOnUnIndexedTrianglesToRef = function (vector, positions, indices, ref) {\n // Triangles test\n const proj = TmpVectors.Vector3[0];\n const tmp = TmpVectors.Vector3[1];\n let distance = +Infinity;\n for (let index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 3) {\n const p0 = positions[index];\n const p1 = positions[index + 1];\n const p2 = positions[index + 2];\n const tmpDist = Vector3.ProjectOnTriangleToRef(vector, p0, p1, p2, tmp);\n if (tmpDist < distance) {\n proj.copyFrom(tmp);\n distance = tmpDist;\n }\n }\n ref.copyFrom(proj);\n return distance;\n };\n SubMesh.prototype.projectToRef = function (vector, positions, indices, ref) {\n const material = this.getMaterial();\n if (!material) {\n return -1;\n }\n let step = 3;\n let checkStopper = false;\n switch (material.fillMode) {\n case 3:\n case 5:\n case 6:\n case 8:\n return -1;\n case 7:\n step = 1;\n checkStopper = true;\n break;\n }\n // LineMesh first as it's also a Mesh...\n if (material.fillMode === 4) {\n return -1;\n }\n else {\n // Check if mesh is unindexed\n if (!indices.length && this._mesh._unIndexed) {\n return this._projectOnUnIndexedTrianglesToRef(vector, positions, indices, ref);\n }\n return this._projectOnTrianglesToRef(vector, positions, indices, step, checkStopper, ref);\n }\n };\n\n // Tracks the interaction animation state when using a motion controller with a near interaction orb\n var ControllerOrbAnimationState;\n (function (ControllerOrbAnimationState) {\n /**\n * Orb is invisible\n */\n ControllerOrbAnimationState[ControllerOrbAnimationState[\"DEHYDRATED\"] = 0] = \"DEHYDRATED\";\n /**\n * Orb is visible and inside the hover range\n */\n ControllerOrbAnimationState[ControllerOrbAnimationState[\"HOVER\"] = 1] = \"HOVER\";\n /**\n * Orb is visible and touching a near interaction target\n */\n ControllerOrbAnimationState[ControllerOrbAnimationState[\"TOUCH\"] = 2] = \"TOUCH\";\n })(ControllerOrbAnimationState || (ControllerOrbAnimationState = {}));\n /**\n * Where should the near interaction mesh be attached to when using a motion controller for near interaction\n */\n var WebXRNearControllerMode;\n (function (WebXRNearControllerMode) {\n /**\n * Motion controllers will not support near interaction\n */\n WebXRNearControllerMode[WebXRNearControllerMode[\"DISABLED\"] = 0] = \"DISABLED\";\n /**\n * The interaction point for motion controllers will be inside of them\n */\n WebXRNearControllerMode[WebXRNearControllerMode[\"CENTERED_ON_CONTROLLER\"] = 1] = \"CENTERED_ON_CONTROLLER\";\n /**\n * The interaction point for motion controllers will be in front of the controller\n */\n WebXRNearControllerMode[WebXRNearControllerMode[\"CENTERED_IN_FRONT\"] = 2] = \"CENTERED_IN_FRONT\";\n })(WebXRNearControllerMode || (WebXRNearControllerMode = {}));\n /**\n * A module that will enable near interaction near interaction for hands and motion controllers of XR Input Sources\n */\n class WebXRNearInteraction extends WebXRAbstractFeature {\n /**\n * constructs a new background remover module\n * @param _xrSessionManager the session manager for this module\n * @param _options read-only options to be used in this module\n */\n constructor(_xrSessionManager, _options) {\n super(_xrSessionManager);\n this._options = _options;\n this._tmpRay = new Ray(new Vector3(), new Vector3());\n this._attachController = (xrController) => {\n if (this._controllers[xrController.uniqueId]) {\n // already attached\n return;\n }\n // get two new meshes\n const { touchCollisionMesh, touchCollisionMeshFunction, hydrateCollisionMeshFunction } = this._generateNewTouchPointMesh();\n const selectionMesh = this._generateVisualCue();\n this._controllers[xrController.uniqueId] = {\n xrController,\n meshUnderPointer: null,\n nearInteractionTargetMesh: null,\n pick: null,\n stalePick: null,\n touchCollisionMesh,\n touchCollisionMeshFunction: touchCollisionMeshFunction,\n hydrateCollisionMeshFunction: hydrateCollisionMeshFunction,\n currentAnimationState: ControllerOrbAnimationState.DEHYDRATED,\n grabRay: new Ray(new Vector3(), new Vector3()),\n hoverInteraction: false,\n nearInteraction: false,\n grabInteraction: false,\n id: WebXRNearInteraction._IdCounter++,\n pickedPointVisualCue: selectionMesh,\n };\n if (this._attachedController) {\n if (!this._options.enableNearInteractionOnAllControllers &&\n this._options.preferredHandedness &&\n xrController.inputSource.handedness === this._options.preferredHandedness) {\n this._attachedController = xrController.uniqueId;\n }\n }\n else {\n if (!this._options.enableNearInteractionOnAllControllers) {\n this._attachedController = xrController.uniqueId;\n }\n }\n switch (xrController.inputSource.targetRayMode) {\n case \"tracked-pointer\":\n return this._attachNearInteractionMode(xrController);\n case \"gaze\":\n return null;\n case \"screen\":\n return null;\n }\n };\n this._controllers = {};\n this._farInteractionFeature = null;\n /**\n * default color of the selection ring\n */\n this.selectionMeshDefaultColor = new Color3(0.8, 0.8, 0.8);\n /**\n * This color will be applied to the selection ring when selection is triggered\n */\n this.selectionMeshPickedColor = new Color3(0.3, 0.3, 1.0);\n this._hoverRadius = 0.1;\n this._pickRadius = 0.02;\n this._controllerPickRadius = 0.03; // The radius is slightly larger here to make it easier to manipulate since it's not tied to the hand position\n this._nearGrabLengthScale = 5;\n this._scene = this._xrSessionManager.scene;\n if (this._options.nearInteractionControllerMode === undefined) {\n this._options.nearInteractionControllerMode = WebXRNearControllerMode.CENTERED_IN_FRONT;\n }\n if (this._options.farInteractionFeature) {\n this._farInteractionFeature = this._options.farInteractionFeature;\n }\n }\n /**\n * Attach this feature\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n attach() {\n if (!super.attach()) {\n return false;\n }\n this._options.xrInput.controllers.forEach(this._attachController);\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\n // REMOVE the controller\n this._detachController(controller.uniqueId);\n });\n this._scene.constantlyUpdateMeshUnderPointer = true;\n return true;\n }\n /**\n * Detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n Object.keys(this._controllers).forEach((controllerId) => {\n this._detachController(controllerId);\n });\n return true;\n }\n /**\n * Will get the mesh under a specific pointer.\n * `scene.meshUnderPointer` will only return one mesh - either left or right.\n * @param controllerId the controllerId to check\n * @returns The mesh under pointer or null if no mesh is under the pointer\n */\n getMeshUnderPointer(controllerId) {\n if (this._controllers[controllerId]) {\n return this._controllers[controllerId].meshUnderPointer;\n }\n else {\n return null;\n }\n }\n /**\n * Get the xr controller that correlates to the pointer id in the pointer event\n *\n * @param id the pointer id to search for\n * @returns the controller that correlates to this id or null if not found\n */\n getXRControllerByPointerId(id) {\n const keys = Object.keys(this._controllers);\n for (let i = 0; i < keys.length; ++i) {\n if (this._controllers[keys[i]].id === id) {\n return this._controllers[keys[i]].xrController || null;\n }\n }\n return null;\n }\n /**\n * This function sets webXRControllerPointerSelection feature that will be disabled when\n * the hover range is reached for a mesh and will be reattached when not in hover range.\n * This is used to remove the selection rays when moving.\n * @param farInteractionFeature the feature to disable when finger is in hover range for a mesh\n */\n setFarInteractionFeature(farInteractionFeature) {\n this._farInteractionFeature = farInteractionFeature;\n }\n /**\n * Filter used for near interaction pick and hover\n * @param mesh\n */\n _nearPickPredicate(mesh) {\n return mesh.isEnabled() && mesh.isVisible && mesh.isPickable && mesh.isNearPickable;\n }\n /**\n * Filter used for near interaction grab\n * @param mesh\n */\n _nearGrabPredicate(mesh) {\n return mesh.isEnabled() && mesh.isVisible && mesh.isPickable && mesh.isNearGrabbable;\n }\n /**\n * Filter used for any near interaction\n * @param mesh\n */\n _nearInteractionPredicate(mesh) {\n return mesh.isEnabled() && mesh.isVisible && mesh.isPickable && (mesh.isNearPickable || mesh.isNearGrabbable);\n }\n _controllerAvailablePredicate(mesh, controllerId) {\n let parent = mesh;\n while (parent) {\n if (parent.reservedDataStore && parent.reservedDataStore.nearInteraction && parent.reservedDataStore.nearInteraction.excludedControllerId === controllerId) {\n return false;\n }\n parent = parent.parent;\n }\n return true;\n }\n _handleTransitionAnimation(controllerData, newState) {\n var _a;\n if (controllerData.currentAnimationState === newState ||\n this._options.nearInteractionControllerMode !== WebXRNearControllerMode.CENTERED_IN_FRONT ||\n !!((_a = controllerData.xrController) === null || _a === void 0 ? void 0 : _a.inputSource.hand)) {\n return;\n }\n // Don't always break to allow for animation fallthrough on rare cases of multi-transitions\n if (newState > controllerData.currentAnimationState) {\n switch (controllerData.currentAnimationState) {\n case ControllerOrbAnimationState.DEHYDRATED: {\n controllerData.hydrateCollisionMeshFunction(true);\n if (newState === ControllerOrbAnimationState.HOVER) {\n break;\n }\n }\n // eslint-disable-next-line no-fallthrough\n case ControllerOrbAnimationState.HOVER: {\n controllerData.touchCollisionMeshFunction(true);\n if (newState === ControllerOrbAnimationState.TOUCH) {\n break;\n }\n }\n }\n }\n else {\n switch (controllerData.currentAnimationState) {\n case ControllerOrbAnimationState.TOUCH: {\n controllerData.touchCollisionMeshFunction(false);\n if (newState === ControllerOrbAnimationState.HOVER) {\n break;\n }\n }\n // eslint-disable-next-line no-fallthrough\n case ControllerOrbAnimationState.HOVER: {\n controllerData.hydrateCollisionMeshFunction(false);\n if (newState === ControllerOrbAnimationState.DEHYDRATED) {\n break;\n }\n }\n }\n }\n controllerData.currentAnimationState = newState;\n }\n _processTouchPoint(id, position, orientation) {\n var _a;\n const controllerData = this._controllers[id];\n // Position and orientation could be temporary values, se we take care of them before calling any functions that use temporary vectors/quaternions\n controllerData.grabRay.origin.copyFrom(position);\n orientation.toEulerAnglesToRef(TmpVectors.Vector3[0]);\n controllerData.grabRay.direction.copyFrom(TmpVectors.Vector3[0]);\n if (this._options.nearInteractionControllerMode === WebXRNearControllerMode.CENTERED_IN_FRONT && !((_a = controllerData.xrController) === null || _a === void 0 ? void 0 : _a.inputSource.hand)) {\n // offset the touch point in the direction the transform is facing\n controllerData.xrController.getWorldPointerRayToRef(this._tmpRay);\n controllerData.grabRay.origin.addInPlace(this._tmpRay.direction.scale(0.05));\n }\n controllerData.grabRay.length = this._nearGrabLengthScale * this._hoverRadius;\n controllerData.touchCollisionMesh.position.copyFrom(controllerData.grabRay.origin);\n }\n _onXRFrame(_xrFrame) {\n Object.keys(this._controllers).forEach((id) => {\n var _a;\n // only do this for the selected pointer\n const controllerData = this._controllers[id];\n const handData = (_a = controllerData.xrController) === null || _a === void 0 ? void 0 : _a.inputSource.hand;\n // If near interaction is not enabled/available for this controller, return early\n if ((!this._options.enableNearInteractionOnAllControllers && id !== this._attachedController) ||\n !controllerData.xrController ||\n (!handData && (!this._options.nearInteractionControllerMode || !controllerData.xrController.inputSource.gamepad))) {\n controllerData.pick = null;\n return;\n }\n controllerData.hoverInteraction = false;\n controllerData.nearInteraction = false;\n // Every frame check collisions/input\n if (controllerData.xrController) {\n if (handData) {\n const xrIndexTip = handData.get(\"index-finger-tip\");\n if (xrIndexTip) {\n const indexTipPose = _xrFrame.getJointPose(xrIndexTip, this._xrSessionManager.referenceSpace);\n if (indexTipPose && indexTipPose.transform) {\n const axisRHSMultiplier = this._scene.useRightHandedSystem ? 1 : -1;\n TmpVectors.Vector3[0].set(indexTipPose.transform.position.x, indexTipPose.transform.position.y, indexTipPose.transform.position.z * axisRHSMultiplier);\n TmpVectors.Quaternion[0].set(indexTipPose.transform.orientation.x, indexTipPose.transform.orientation.y, indexTipPose.transform.orientation.z * axisRHSMultiplier, indexTipPose.transform.orientation.w * axisRHSMultiplier);\n this._processTouchPoint(id, TmpVectors.Vector3[0], TmpVectors.Quaternion[0]);\n }\n }\n }\n else if (controllerData.xrController.inputSource.gamepad && this._options.nearInteractionControllerMode !== WebXRNearControllerMode.DISABLED) {\n let controllerPose = controllerData.xrController.pointer;\n if (controllerData.xrController.grip && this._options.nearInteractionControllerMode === WebXRNearControllerMode.CENTERED_ON_CONTROLLER) {\n controllerPose = controllerData.xrController.grip;\n }\n this._processTouchPoint(id, controllerPose.position, controllerPose.rotationQuaternion);\n }\n }\n else {\n return;\n }\n const accuratePickInfo = (originalScenePick, utilityScenePick) => {\n let pick = null;\n if (!utilityScenePick || !utilityScenePick.hit) {\n // No hit in utility scene\n pick = originalScenePick;\n }\n else if (!originalScenePick || !originalScenePick.hit) {\n // No hit in original scene\n pick = utilityScenePick;\n }\n else if (utilityScenePick.distance < originalScenePick.distance) {\n // Hit is closer in utility scene\n pick = utilityScenePick;\n }\n else {\n // Hit is closer in original scene\n pick = originalScenePick;\n }\n return pick;\n };\n const populateNearInteractionInfo = (nearInteractionInfo) => {\n let result = new PickingInfo();\n let nearInteractionAtOrigin = false;\n const nearInteraction = nearInteractionInfo && nearInteractionInfo.pickedPoint && nearInteractionInfo.hit;\n if (nearInteractionInfo === null || nearInteractionInfo === void 0 ? void 0 : nearInteractionInfo.pickedPoint) {\n nearInteractionAtOrigin = nearInteractionInfo.pickedPoint.x === 0 && nearInteractionInfo.pickedPoint.y === 0 && nearInteractionInfo.pickedPoint.z === 0;\n }\n if (nearInteraction && !nearInteractionAtOrigin) {\n result = nearInteractionInfo;\n }\n return result;\n };\n // Don't perform touch logic while grabbing, to prevent triggering touch interactions while in the middle of a grab interaction\n // Dont update cursor logic either - the cursor should already be visible for the grab to be in range,\n // and in order to maintain its position on the target mesh it is parented for the duration of the grab.\n if (!controllerData.grabInteraction) {\n let pick = null;\n // near interaction hover\n let utilitySceneHoverPick = null;\n if (this._options.useUtilityLayer && this._utilityLayerScene) {\n utilitySceneHoverPick = this._pickWithSphere(controllerData, this._hoverRadius, this._utilityLayerScene, (mesh) => this._nearInteractionPredicate(mesh));\n }\n const originalSceneHoverPick = this._pickWithSphere(controllerData, this._hoverRadius, this._scene, (mesh) => this._nearInteractionPredicate(mesh));\n const hoverPickInfo = accuratePickInfo(originalSceneHoverPick, utilitySceneHoverPick);\n if (hoverPickInfo && hoverPickInfo.hit) {\n pick = populateNearInteractionInfo(hoverPickInfo);\n if (pick.hit) {\n controllerData.hoverInteraction = true;\n }\n }\n // near interaction pick\n if (controllerData.hoverInteraction) {\n let utilitySceneNearPick = null;\n const radius = handData ? this._pickRadius : this._controllerPickRadius;\n if (this._options.useUtilityLayer && this._utilityLayerScene) {\n utilitySceneNearPick = this._pickWithSphere(controllerData, radius, this._utilityLayerScene, (mesh) => this._nearPickPredicate(mesh));\n }\n const originalSceneNearPick = this._pickWithSphere(controllerData, radius, this._scene, (mesh) => this._nearPickPredicate(mesh));\n const pickInfo = accuratePickInfo(originalSceneNearPick, utilitySceneNearPick);\n const nearPick = populateNearInteractionInfo(pickInfo);\n if (nearPick.hit) {\n // Near pick takes precedence over hover interaction\n pick = nearPick;\n controllerData.nearInteraction = true;\n }\n }\n controllerData.stalePick = controllerData.pick;\n controllerData.pick = pick;\n // Update mesh under pointer\n if (controllerData.pick && controllerData.pick.pickedPoint && controllerData.pick.hit) {\n controllerData.meshUnderPointer = controllerData.pick.pickedMesh;\n controllerData.pickedPointVisualCue.position.copyFrom(controllerData.pick.pickedPoint);\n controllerData.pickedPointVisualCue.isVisible = true;\n if (this._farInteractionFeature && this._farInteractionFeature.attached) {\n this._farInteractionFeature._setPointerSelectionDisabledByPointerId(controllerData.id, true);\n }\n }\n else {\n controllerData.meshUnderPointer = null;\n controllerData.pickedPointVisualCue.isVisible = false;\n if (this._farInteractionFeature && this._farInteractionFeature.attached) {\n this._farInteractionFeature._setPointerSelectionDisabledByPointerId(controllerData.id, false);\n }\n }\n }\n // Update the interaction animation. Only updates if the visible touch mesh is active\n let state = ControllerOrbAnimationState.DEHYDRATED;\n if (controllerData.grabInteraction || controllerData.nearInteraction) {\n state = ControllerOrbAnimationState.TOUCH;\n }\n else if (controllerData.hoverInteraction) {\n state = ControllerOrbAnimationState.HOVER;\n }\n this._handleTransitionAnimation(controllerData, state);\n });\n }\n get _utilityLayerScene() {\n return this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;\n }\n _generateVisualCue() {\n const sceneToRenderTo = this._options.useUtilityLayer ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene : this._scene;\n const selectionMesh = CreateSphere(\"nearInteraction\", {\n diameter: 0.0035 * 3,\n }, sceneToRenderTo);\n selectionMesh.bakeCurrentTransformIntoVertices();\n selectionMesh.isPickable = false;\n selectionMesh.isVisible = false;\n selectionMesh.rotationQuaternion = Quaternion.Identity();\n const targetMat = new StandardMaterial(\"targetMat\", sceneToRenderTo);\n targetMat.specularColor = Color3.Black();\n targetMat.emissiveColor = this.selectionMeshDefaultColor;\n targetMat.backFaceCulling = false;\n selectionMesh.material = targetMat;\n return selectionMesh;\n }\n _isControllerReadyForNearInteraction(id) {\n if (this._farInteractionFeature) {\n return this._farInteractionFeature._getPointerSelectionDisabledByPointerId(id);\n }\n return true;\n }\n _attachNearInteractionMode(xrController) {\n const controllerData = this._controllers[xrController.uniqueId];\n const pointerEventInit = {\n pointerId: controllerData.id,\n pointerType: \"xr-near\",\n };\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\n if ((!this._options.enableNearInteractionOnAllControllers && xrController.uniqueId !== this._attachedController) ||\n !controllerData.xrController ||\n (!controllerData.xrController.inputSource.hand && (!this._options.nearInteractionControllerMode || !controllerData.xrController.inputSource.gamepad))) {\n return;\n }\n if (controllerData.pick) {\n controllerData.pick.ray = controllerData.grabRay;\n }\n if (controllerData.pick && this._isControllerReadyForNearInteraction(controllerData.id)) {\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\n }\n // Near pick pointer event\n if (controllerData.nearInteraction && controllerData.pick && controllerData.pick.hit) {\n if (!controllerData.nearInteractionTargetMesh) {\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n controllerData.nearInteractionTargetMesh = controllerData.meshUnderPointer;\n }\n }\n else if (controllerData.nearInteractionTargetMesh && controllerData.stalePick) {\n this._scene.simulatePointerUp(controllerData.stalePick, pointerEventInit);\n controllerData.nearInteractionTargetMesh = null;\n }\n });\n const grabCheck = (pressed) => {\n if (this._options.enableNearInteractionOnAllControllers ||\n (xrController.uniqueId === this._attachedController && this._isControllerReadyForNearInteraction(controllerData.id))) {\n if (controllerData.pick) {\n controllerData.pick.ray = controllerData.grabRay;\n }\n if (pressed && controllerData.pick && controllerData.meshUnderPointer && this._nearGrabPredicate(controllerData.meshUnderPointer)) {\n controllerData.grabInteraction = true;\n controllerData.pickedPointVisualCue.isVisible = false;\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n }\n else if (!pressed && controllerData.pick && controllerData.grabInteraction) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n controllerData.grabInteraction = false;\n controllerData.pickedPointVisualCue.isVisible = true;\n }\n }\n else {\n if (pressed && !this._options.enableNearInteractionOnAllControllers && !this._options.disableSwitchOnClick) {\n this._attachedController = xrController.uniqueId;\n }\n }\n };\n if (xrController.inputSource.gamepad) {\n const init = (motionController) => {\n controllerData.squeezeComponent = motionController.getComponent(\"grasp\");\n if (controllerData.squeezeComponent) {\n controllerData.onSqueezeButtonChangedObserver = controllerData.squeezeComponent.onButtonStateChangedObservable.add((component) => {\n if (component.changes.pressed) {\n const pressed = component.changes.pressed.current;\n grabCheck(pressed);\n }\n });\n }\n else {\n controllerData.selectionComponent = motionController.getMainComponent();\n controllerData.onButtonChangedObserver = controllerData.selectionComponent.onButtonStateChangedObservable.add((component) => {\n if (component.changes.pressed) {\n const pressed = component.changes.pressed.current;\n grabCheck(pressed);\n }\n });\n }\n };\n if (xrController.motionController) {\n init(xrController.motionController);\n }\n else {\n xrController.onMotionControllerInitObservable.add(init);\n }\n }\n else {\n // use the select and squeeze events\n const selectStartListener = (event) => {\n if (controllerData.xrController &&\n event.inputSource === controllerData.xrController.inputSource &&\n controllerData.pick &&\n this._isControllerReadyForNearInteraction(controllerData.id) &&\n controllerData.meshUnderPointer &&\n this._nearGrabPredicate(controllerData.meshUnderPointer)) {\n controllerData.grabInteraction = true;\n controllerData.pickedPointVisualCue.isVisible = false;\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\n }\n };\n const selectEndListener = (event) => {\n if (controllerData.xrController &&\n event.inputSource === controllerData.xrController.inputSource &&\n controllerData.pick &&\n this._isControllerReadyForNearInteraction(controllerData.id)) {\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\n controllerData.grabInteraction = false;\n controllerData.pickedPointVisualCue.isVisible = true;\n }\n };\n controllerData.eventListeners = {\n selectend: selectEndListener,\n selectstart: selectStartListener,\n };\n this._xrSessionManager.session.addEventListener(\"selectstart\", selectStartListener);\n this._xrSessionManager.session.addEventListener(\"selectend\", selectEndListener);\n }\n }\n _detachController(xrControllerUniqueId) {\n const controllerData = this._controllers[xrControllerUniqueId];\n if (!controllerData) {\n return;\n }\n if (controllerData.squeezeComponent) {\n if (controllerData.onSqueezeButtonChangedObserver) {\n controllerData.squeezeComponent.onButtonStateChangedObservable.remove(controllerData.onSqueezeButtonChangedObserver);\n }\n }\n if (controllerData.selectionComponent) {\n if (controllerData.onButtonChangedObserver) {\n controllerData.selectionComponent.onButtonStateChangedObservable.remove(controllerData.onButtonChangedObserver);\n }\n }\n if (controllerData.onFrameObserver) {\n this._xrSessionManager.onXRFrameObservable.remove(controllerData.onFrameObserver);\n }\n if (controllerData.eventListeners) {\n Object.keys(controllerData.eventListeners).forEach((eventName) => {\n const func = controllerData.eventListeners && controllerData.eventListeners[eventName];\n if (func) {\n this._xrSessionManager.session.removeEventListener(eventName, func);\n }\n });\n }\n controllerData.touchCollisionMesh.dispose();\n controllerData.pickedPointVisualCue.dispose();\n this._xrSessionManager.runInXRFrame(() => {\n // Fire a pointerup\n const pointerEventInit = {\n pointerId: controllerData.id,\n pointerType: \"xr-near\",\n };\n this._scene.simulatePointerUp(new PickingInfo(), pointerEventInit);\n });\n // remove from the map\n delete this._controllers[xrControllerUniqueId];\n if (this._attachedController === xrControllerUniqueId) {\n // check for other controllers\n const keys = Object.keys(this._controllers);\n if (keys.length) {\n this._attachedController = keys[0];\n }\n else {\n this._attachedController = \"\";\n }\n }\n }\n _generateNewTouchPointMesh() {\n // populate information for near hover, pick and pinch\n const meshCreationScene = this._options.useUtilityLayer ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene : this._scene;\n const touchCollisionMesh = CreateSphere(\"PickSphere\", { diameter: 1 }, meshCreationScene);\n touchCollisionMesh.isVisible = false;\n // Generate the material for the touch mesh visuals\n if (this._options.motionControllerOrbMaterial) {\n touchCollisionMesh.material = this._options.motionControllerOrbMaterial;\n }\n else {\n NodeMaterial.ParseFromSnippetAsync(\"8RUNKL#3\", meshCreationScene).then((nodeMaterial) => {\n touchCollisionMesh.material = nodeMaterial;\n });\n }\n const easingFunction = new QuadraticEase();\n easingFunction.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\n // Adjust the visual size based off of the size of the touch collision orb.\n // Having the size perfectly match for hover gives a more accurate tell for when the user will start interacting with the target\n // Sizes for other states are somewhat arbitrary, as they are based on what feels nice during an interaction\n const hoverSizeVec = new Vector3(this._controllerPickRadius, this._controllerPickRadius, this._controllerPickRadius);\n const touchSize = this._controllerPickRadius * (4 / 3);\n const touchSizeVec = new Vector3(touchSize, touchSize, touchSize);\n const hydrateTransitionSize = this._controllerPickRadius * (7 / 6);\n const hydrateTransitionSizeVec = new Vector3(hydrateTransitionSize, hydrateTransitionSize, hydrateTransitionSize);\n const touchHoverTransitionSize = this._controllerPickRadius * (4 / 5);\n const touchHoverTransitionSizeVec = new Vector3(touchHoverTransitionSize, touchHoverTransitionSize, touchHoverTransitionSize);\n const hoverTouchTransitionSize = this._controllerPickRadius * (3 / 2);\n const hoverTouchTransitionSizeVec = new Vector3(hoverTouchTransitionSize, hoverTouchTransitionSize, hoverTouchTransitionSize);\n const touchKeys = [\n { frame: 0, value: hoverSizeVec },\n { frame: 10, value: hoverTouchTransitionSizeVec },\n { frame: 18, value: touchSizeVec },\n ];\n const releaseKeys = [\n { frame: 0, value: touchSizeVec },\n { frame: 10, value: touchHoverTransitionSizeVec },\n { frame: 18, value: hoverSizeVec },\n ];\n const hydrateKeys = [\n { frame: 0, value: Vector3.ZeroReadOnly },\n { frame: 12, value: hydrateTransitionSizeVec },\n { frame: 15, value: hoverSizeVec },\n ];\n const dehydrateKeys = [\n { frame: 0, value: hoverSizeVec },\n { frame: 10, value: Vector3.ZeroReadOnly },\n { frame: 15, value: Vector3.ZeroReadOnly },\n ];\n const touchAction = new Animation(\"touch\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const releaseAction = new Animation(\"release\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const hydrateAction = new Animation(\"hydrate\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n const dehydrateAction = new Animation(\"dehydrate\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n touchAction.setEasingFunction(easingFunction);\n releaseAction.setEasingFunction(easingFunction);\n hydrateAction.setEasingFunction(easingFunction);\n dehydrateAction.setEasingFunction(easingFunction);\n touchAction.setKeys(touchKeys);\n releaseAction.setKeys(releaseKeys);\n hydrateAction.setKeys(hydrateKeys);\n dehydrateAction.setKeys(dehydrateKeys);\n const touchCollisionMeshFunction = (isTouch) => {\n const action = isTouch ? touchAction : releaseAction;\n meshCreationScene.beginDirectAnimation(touchCollisionMesh, [action], 0, 18, false, 1);\n };\n const hydrateCollisionMeshFunction = (isHydration) => {\n const action = isHydration ? hydrateAction : dehydrateAction;\n if (isHydration) {\n touchCollisionMesh.isVisible = true;\n }\n meshCreationScene.beginDirectAnimation(touchCollisionMesh, [action], 0, 15, false, 1, () => {\n if (!isHydration) {\n touchCollisionMesh.isVisible = false;\n }\n });\n };\n return { touchCollisionMesh, touchCollisionMeshFunction, hydrateCollisionMeshFunction };\n }\n _pickWithSphere(controllerData, radius, sceneToUse, predicate) {\n const pickingInfo = new PickingInfo();\n pickingInfo.distance = +Infinity;\n if (controllerData.touchCollisionMesh && controllerData.xrController) {\n const position = controllerData.touchCollisionMesh.position;\n const sphere = BoundingSphere.CreateFromCenterAndRadius(position, radius);\n for (let meshIndex = 0; meshIndex < sceneToUse.meshes.length; meshIndex++) {\n const mesh = sceneToUse.meshes[meshIndex];\n if (!predicate(mesh) || !this._controllerAvailablePredicate(mesh, controllerData.xrController.uniqueId)) {\n continue;\n }\n const result = WebXRNearInteraction.PickMeshWithSphere(mesh, sphere);\n if (result && result.hit && result.distance < pickingInfo.distance) {\n pickingInfo.hit = result.hit;\n pickingInfo.pickedMesh = mesh;\n pickingInfo.pickedPoint = result.pickedPoint;\n pickingInfo.aimTransform = controllerData.xrController.pointer;\n pickingInfo.gripTransform = controllerData.xrController.grip || null;\n pickingInfo.originMesh = controllerData.touchCollisionMesh;\n pickingInfo.distance = result.distance;\n }\n }\n }\n return pickingInfo;\n }\n /**\n * Picks a mesh with a sphere\n * @param mesh the mesh to pick\n * @param sphere picking sphere in world coordinates\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\n * @returns the picking info\n */\n static PickMeshWithSphere(mesh, sphere, skipBoundingInfo = false) {\n const subMeshes = mesh.subMeshes;\n const pi = new PickingInfo();\n const boundingInfo = mesh.getBoundingInfo();\n if (!mesh._generatePointsArray()) {\n return pi;\n }\n if (!mesh.subMeshes || !boundingInfo) {\n return pi;\n }\n if (!skipBoundingInfo && !BoundingSphere.Intersects(boundingInfo.boundingSphere, sphere)) {\n return pi;\n }\n const result = TmpVectors.Vector3[0];\n const tmpVec = TmpVectors.Vector3[1];\n let distance = +Infinity;\n let tmp, tmpDistanceSphereToCenter, tmpDistanceSurfaceToCenter;\n const center = TmpVectors.Vector3[2];\n const worldToMesh = TmpVectors.Matrix[0];\n worldToMesh.copyFrom(mesh.getWorldMatrix());\n worldToMesh.invert();\n Vector3.TransformCoordinatesToRef(sphere.center, worldToMesh, center);\n for (let index = 0; index < subMeshes.length; index++) {\n const subMesh = subMeshes[index];\n subMesh.projectToRef(center, mesh._positions, mesh.getIndices(), tmpVec);\n Vector3.TransformCoordinatesToRef(tmpVec, mesh.getWorldMatrix(), tmpVec);\n tmp = Vector3.Distance(tmpVec, sphere.center);\n // Check for finger inside of mesh\n tmpDistanceSurfaceToCenter = Vector3.Distance(tmpVec, mesh.getAbsolutePosition());\n tmpDistanceSphereToCenter = Vector3.Distance(sphere.center, mesh.getAbsolutePosition());\n if (tmpDistanceSphereToCenter !== -1 && tmpDistanceSurfaceToCenter !== -1 && tmpDistanceSurfaceToCenter > tmpDistanceSphereToCenter) {\n tmp = 0;\n tmpVec.copyFrom(sphere.center);\n }\n if (tmp !== -1 && tmp < distance) {\n distance = tmp;\n result.copyFrom(tmpVec);\n }\n }\n if (distance < sphere.radius) {\n pi.hit = true;\n pi.distance = distance;\n pi.pickedMesh = mesh;\n pi.pickedPoint = result.clone();\n }\n return pi;\n }\n }\n WebXRNearInteraction._IdCounter = 200;\n /**\n * The module's name\n */\n WebXRNearInteraction.Name = WebXRFeatureName.NEAR_INTERACTION;\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\n WebXRNearInteraction.Version = 1;\n //Register the plugin\n WebXRFeaturesManager.AddWebXRFeature(WebXRNearInteraction.Name, (xrSessionManager, options) => {\n return () => new WebXRNearInteraction(xrSessionManager, options);\n }, WebXRNearInteraction.Version, true);\n\n /**\n * Button which can be used to enter a different mode of XR\n */\n class WebXREnterExitUIButton {\n /**\n * Creates a WebXREnterExitUIButton\n * @param element button element\n * @param sessionMode XR initialization session mode\n * @param referenceSpaceType the type of reference space to be used\n */\n constructor(\n /** button element */\n element, \n /** XR initialization options for the button */\n sessionMode, \n /** Reference space type */\n referenceSpaceType) {\n this.element = element;\n this.sessionMode = sessionMode;\n this.referenceSpaceType = referenceSpaceType;\n }\n /**\n * Extendable function which can be used to update the button's visuals when the state changes\n * @param activeButton the current active button in the UI\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n update(activeButton) { }\n }\n /**\n * UI to allow the user to enter/exit XR mode\n */\n class WebXREnterExitUI {\n /**\n * Construct a new EnterExit UI class\n *\n * @param _scene babylon scene object to use\n * @param options (read-only) version of the options passed to this UI\n */\n constructor(_scene, \n /** version of the options passed to this UI */\n options) {\n this._scene = _scene;\n this.options = options;\n this._activeButton = null;\n this._buttons = [];\n /**\n * Fired every time the active button is changed.\n *\n * When xr is entered via a button that launches xr that button will be the callback parameter\n *\n * When exiting xr the callback parameter will be null)\n */\n this.activeButtonChangedObservable = new Observable$1();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this._onSessionGranted = (evt) => {\n // This section is for future reference.\n // As per specs, evt.session.mode should have the supported session mode, but no browser supports it for now.\n // // check if the session granted is the same as the one requested\n // const grantedMode = (evt.session as any).mode;\n // if (grantedMode) {\n // this._buttons.some((btn, idx) => {\n // if (btn.sessionMode === grantedMode) {\n // this._enterXRWithButtonIndex(idx);\n // return true;\n // }\n // return false;\n // });\n // } else\n if (this._helper) {\n this._enterXRWithButtonIndex(0);\n }\n };\n this.overlay = document.createElement(\"div\");\n this.overlay.classList.add(\"xr-button-overlay\");\n // prepare for session granted event\n if (!options.ignoreSessionGrantedEvent && navigator.xr) {\n navigator.xr.addEventListener(\"sessiongranted\", this._onSessionGranted);\n }\n // if served over HTTP, warn people.\n // Hopefully the browsers will catch up\n if (typeof window !== \"undefined\") {\n if (window.location && window.location.protocol === \"http:\" && window.location.hostname !== \"localhost\") {\n Tools.Warn(\"WebXR can only be served over HTTPS\");\n throw new Error(\"WebXR can only be served over HTTPS\");\n }\n }\n if (options.customButtons) {\n this._buttons = options.customButtons;\n }\n else {\n this.overlay.style.cssText = \"z-index:11;position: absolute; right: 20px;bottom: 50px;\";\n const sessionMode = options.sessionMode || \"immersive-vr\";\n const referenceSpaceType = options.referenceSpaceType || \"local-floor\";\n const url = typeof SVGSVGElement === \"undefined\"\n ? \"https://cdn.babylonjs.com/Assets/vrButton.png\"\n : \"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A\";\n let css = \".babylonVRicon { color: #868686; border-color: #868686; border-style: solid; margin-left: 10px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(\" +\n url +\n \"); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }\";\n css += '.babylonVRicon.vrdisplaypresenting { background-image: none;} .vrdisplaypresenting::after { content: \"EXIT\"} .xr-error::after { content: \"ERROR\"}';\n const style = document.createElement(\"style\");\n style.appendChild(document.createTextNode(css));\n document.getElementsByTagName(\"head\")[0].appendChild(style);\n const hmdBtn = document.createElement(\"button\");\n hmdBtn.className = \"babylonVRicon\";\n hmdBtn.title = `${sessionMode} - ${referenceSpaceType}`;\n this._buttons.push(new WebXREnterExitUIButton(hmdBtn, sessionMode, referenceSpaceType));\n this._buttons[this._buttons.length - 1].update = function (activeButton) {\n this.element.style.display = activeButton === null || activeButton === this ? \"\" : \"none\";\n hmdBtn.className = \"babylonVRicon\" + (activeButton === this ? \" vrdisplaypresenting\" : \"\");\n };\n this._updateButtons(null);\n }\n const renderCanvas = _scene.getEngine().getInputElement();\n if (renderCanvas && renderCanvas.parentNode) {\n renderCanvas.parentNode.appendChild(this.overlay);\n _scene.onDisposeObservable.addOnce(() => {\n this.dispose();\n });\n }\n }\n /**\n * Set the helper to be used with this UI component.\n * The UI is bound to an experience helper. If not provided the UI can still be used but the events should be registered by the developer.\n *\n * @param helper the experience helper to attach\n * @param renderTarget an optional render target (in case it is created outside of the helper scope)\n * @returns a promise that resolves when the ui is ready\n */\n async setHelperAsync(helper, renderTarget) {\n this._helper = helper;\n this._renderTarget = renderTarget;\n const supportedPromises = this._buttons.map((btn) => {\n return helper.sessionManager.isSessionSupportedAsync(btn.sessionMode);\n });\n helper.onStateChangedObservable.add((state) => {\n if (state == WebXRState.NOT_IN_XR) {\n this._updateButtons(null);\n }\n });\n const results = await Promise.all(supportedPromises);\n results.forEach((supported, i) => {\n if (supported) {\n this.overlay.appendChild(this._buttons[i].element);\n this._buttons[i].element.onclick = this._enterXRWithButtonIndex.bind(this, i);\n }\n else {\n Tools.Warn(`Session mode \"${this._buttons[i].sessionMode}\" not supported in browser`);\n }\n });\n }\n /**\n * Creates UI to allow the user to enter/exit XR mode\n * @param scene the scene to add the ui to\n * @param helper the xr experience helper to enter/exit xr with\n * @param options options to configure the UI\n * @returns the created ui\n */\n static async CreateAsync(scene, helper, options) {\n const ui = new WebXREnterExitUI(scene, options);\n await ui.setHelperAsync(helper, options.renderTarget || undefined);\n return ui;\n }\n async _enterXRWithButtonIndex(idx = 0) {\n if (this._helper.state == WebXRState.IN_XR) {\n await this._helper.exitXRAsync();\n this._updateButtons(null);\n }\n else if (this._helper.state == WebXRState.NOT_IN_XR) {\n try {\n await this._helper.enterXRAsync(this._buttons[idx].sessionMode, this._buttons[idx].referenceSpaceType, this._renderTarget, {\n optionalFeatures: this.options.optionalFeatures,\n requiredFeatures: this.options.requiredFeatures,\n });\n this._updateButtons(this._buttons[idx]);\n }\n catch (e) {\n // make sure button is visible\n this._updateButtons(null);\n const element = this._buttons[idx].element;\n const prevTitle = element.title;\n element.title = \"Error entering XR session : \" + prevTitle;\n element.classList.add(\"xr-error\");\n if (this.options.onError) {\n this.options.onError(e);\n }\n }\n }\n }\n /**\n * Disposes of the XR UI component\n */\n dispose() {\n const renderCanvas = this._scene.getEngine().getInputElement();\n if (renderCanvas && renderCanvas.parentNode && renderCanvas.parentNode.contains(this.overlay)) {\n renderCanvas.parentNode.removeChild(this.overlay);\n }\n this.activeButtonChangedObservable.clear();\n navigator.xr.removeEventListener(\"sessiongranted\", this._onSessionGranted);\n }\n _updateButtons(activeButton) {\n this._activeButton = activeButton;\n this._buttons.forEach((b) => {\n b.update(this._activeButton);\n });\n this.activeButtonChangedObservable.notifyObservers(this._activeButton);\n }\n }\n\n Mesh._instancedMeshFactory = (name, mesh) => {\n const instance = new InstancedMesh(name, mesh);\n if (mesh.instancedBuffers) {\n instance.instancedBuffers = {};\n for (const key in mesh.instancedBuffers) {\n instance.instancedBuffers[key] = mesh.instancedBuffers[key];\n }\n }\n return instance;\n };\n /**\n * Creates an instance based on a source mesh.\n */\n class InstancedMesh extends AbstractMesh {\n /**\n * Creates a new InstancedMesh object from the mesh source.\n * @param name defines the name of the instance\n * @param source the mesh to create the instance from\n */\n constructor(name, source) {\n super(name, source.getScene());\n /** @internal */\n this._indexInSourceMeshInstanceArray = -1;\n /** @internal */\n this._distanceToCamera = 0;\n source.addInstance(this);\n this._sourceMesh = source;\n this._unIndexed = source._unIndexed;\n this.position.copyFrom(source.position);\n this.rotation.copyFrom(source.rotation);\n this.scaling.copyFrom(source.scaling);\n if (source.rotationQuaternion) {\n this.rotationQuaternion = source.rotationQuaternion.clone();\n }\n this.animations = source.animations.slice();\n for (const range of source.getAnimationRanges()) {\n if (range != null) {\n this.createAnimationRange(range.name, range.from, range.to);\n }\n }\n this.infiniteDistance = source.infiniteDistance;\n this.setPivotMatrix(source.getPivotMatrix());\n this.refreshBoundingInfo(true, true);\n this._syncSubMeshes();\n }\n /**\n * Returns the string \"InstancedMesh\".\n */\n getClassName() {\n return \"InstancedMesh\";\n }\n /** Gets the list of lights affecting that mesh */\n get lightSources() {\n return this._sourceMesh._lightSources;\n }\n _resyncLightSources() {\n // Do nothing as all the work will be done by source mesh\n }\n _resyncLightSource() {\n // Do nothing as all the work will be done by source mesh\n }\n _removeLightSource() {\n // Do nothing as all the work will be done by source mesh\n }\n // Methods\n /**\n * If the source mesh receives shadows\n */\n get receiveShadows() {\n return this._sourceMesh.receiveShadows;\n }\n set receiveShadows(_value) {\n var _a;\n if (((_a = this._sourceMesh) === null || _a === void 0 ? void 0 : _a.receiveShadows) !== _value) {\n Tools.Warn(\"Setting receiveShadows on an instanced mesh has no effect\");\n }\n }\n /**\n * The material of the source mesh\n */\n get material() {\n return this._sourceMesh.material;\n }\n set material(_value) {\n var _a;\n if (((_a = this._sourceMesh) === null || _a === void 0 ? void 0 : _a.material) !== _value) {\n Tools.Warn(\"Setting material on an instanced mesh has no effect\");\n }\n }\n /**\n * Visibility of the source mesh\n */\n get visibility() {\n return this._sourceMesh.visibility;\n }\n set visibility(_value) {\n var _a;\n if (((_a = this._sourceMesh) === null || _a === void 0 ? void 0 : _a.visibility) !== _value) {\n Tools.Warn(\"Setting visibility on an instanced mesh has no effect\");\n }\n }\n /**\n * Skeleton of the source mesh\n */\n get skeleton() {\n return this._sourceMesh.skeleton;\n }\n set skeleton(_value) {\n var _a;\n if (((_a = this._sourceMesh) === null || _a === void 0 ? void 0 : _a.skeleton) !== _value) {\n Tools.Warn(\"Setting skeleton on an instanced mesh has no effect\");\n }\n }\n /**\n * Rendering ground id of the source mesh\n */\n get renderingGroupId() {\n return this._sourceMesh.renderingGroupId;\n }\n set renderingGroupId(value) {\n if (!this._sourceMesh || value === this._sourceMesh.renderingGroupId) {\n return;\n }\n //no-op with warning\n Logger.Warn(\"Note - setting renderingGroupId of an instanced mesh has no effect on the scene\");\n }\n /**\n * Returns the total number of vertices (integer).\n */\n getTotalVertices() {\n return this._sourceMesh ? this._sourceMesh.getTotalVertices() : 0;\n }\n /**\n * Returns a positive integer : the total number of indices in this mesh geometry.\n * @returns the number of indices or zero if the mesh has no geometry.\n */\n getTotalIndices() {\n return this._sourceMesh.getTotalIndices();\n }\n /**\n * The source mesh of the instance\n */\n get sourceMesh() {\n return this._sourceMesh;\n }\n /**\n * Creates a new InstancedMesh object from the mesh model.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\n * @param name defines the name of the new instance\n * @returns a new InstancedMesh\n */\n createInstance(name) {\n return this._sourceMesh.createInstance(name);\n }\n /**\n * Is this node ready to be used/rendered\n * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)\n * @returns {boolean} is it ready\n */\n isReady(completeCheck = false) {\n return this._sourceMesh.isReady(completeCheck, true);\n }\n /**\n * Returns an array of integers or a typed array (Int32Array, Uint32Array, Uint16Array) populated with the mesh indices.\n * @param kind kind of verticies to retrieve (eg. positions, normals, uvs, etc.)\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.\n * @param forceCopy defines a boolean forcing the copy of the buffer no matter what the value of copyWhenShared is\n * @returns a float array or a Float32Array of the requested kind of data : positions, normals, uvs, etc.\n */\n getVerticesData(kind, copyWhenShared, forceCopy) {\n return this._sourceMesh.getVerticesData(kind, copyWhenShared, forceCopy);\n }\n /**\n * Sets the vertex data of the mesh geometry for the requested `kind`.\n * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.\n * The `data` are either a numeric array either a Float32Array.\n * The parameter `updatable` is passed as is to the underlying Geometry object constructor (if initially none) or updater.\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).\n * Note that a new underlying VertexBuffer object is created each call.\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.\n *\n * Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n *\n * Returns the Mesh.\n * @param kind\n * @param data\n * @param updatable\n * @param stride\n */\n setVerticesData(kind, data, updatable, stride) {\n if (this.sourceMesh) {\n this.sourceMesh.setVerticesData(kind, data, updatable, stride);\n }\n return this.sourceMesh;\n }\n /**\n * Updates the existing vertex data of the mesh geometry for the requested `kind`.\n * If the mesh has no geometry, it is simply returned as it is.\n * The `data` are either a numeric array either a Float32Array.\n * No new underlying VertexBuffer object is created.\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.\n * If the parameter `makeItUnique` is true, a new global geometry is created from this positions and is set to the mesh.\n *\n * Possible `kind` values :\n * - VertexBuffer.PositionKind\n * - VertexBuffer.UVKind\n * - VertexBuffer.UV2Kind\n * - VertexBuffer.UV3Kind\n * - VertexBuffer.UV4Kind\n * - VertexBuffer.UV5Kind\n * - VertexBuffer.UV6Kind\n * - VertexBuffer.ColorKind\n * - VertexBuffer.MatricesIndicesKind\n * - VertexBuffer.MatricesIndicesExtraKind\n * - VertexBuffer.MatricesWeightsKind\n * - VertexBuffer.MatricesWeightsExtraKind\n *\n * Returns the Mesh.\n * @param kind\n * @param data\n * @param updateExtends\n * @param makeItUnique\n */\n updateVerticesData(kind, data, updateExtends, makeItUnique) {\n if (this.sourceMesh) {\n this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);\n }\n return this.sourceMesh;\n }\n /**\n * Sets the mesh indices.\n * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array).\n * If the mesh has no geometry, a new Geometry object is created and set to the mesh.\n * This method creates a new index buffer each call.\n * Returns the Mesh.\n * @param indices\n * @param totalVertices\n */\n setIndices(indices, totalVertices = null) {\n if (this.sourceMesh) {\n this.sourceMesh.setIndices(indices, totalVertices);\n }\n return this.sourceMesh;\n }\n /**\n * Boolean : True if the mesh owns the requested kind of data.\n * @param kind\n */\n isVerticesDataPresent(kind) {\n return this._sourceMesh.isVerticesDataPresent(kind);\n }\n /**\n * Returns an array of indices (IndicesArray).\n */\n getIndices() {\n return this._sourceMesh.getIndices();\n }\n get _positions() {\n return this._sourceMesh._positions;\n }\n /**\n * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.\n * This means the mesh underlying bounding box and sphere are recomputed.\n * @param applySkeleton defines whether to apply the skeleton before computing the bounding info\n * @param applyMorph defines whether to apply the morph target before computing the bounding info\n * @returns the current mesh\n */\n refreshBoundingInfo(applySkeleton = false, applyMorph = false) {\n if (this.hasBoundingInfo && this.getBoundingInfo().isLocked) {\n return this;\n }\n const bias = this._sourceMesh.geometry ? this._sourceMesh.geometry.boundingBias : null;\n this._refreshBoundingInfo(this._sourceMesh._getPositionData(applySkeleton, applyMorph), bias);\n return this;\n }\n /** @internal */\n _preActivate() {\n if (this._currentLOD) {\n this._currentLOD._preActivate();\n }\n return this;\n }\n /**\n * @internal\n */\n _activate(renderId, intermediateRendering) {\n super._activate(renderId, intermediateRendering);\n if (!this._sourceMesh.subMeshes) {\n Logger.Warn(\"Instances should only be created for meshes with geometry.\");\n }\n if (this._currentLOD) {\n const differentSign = this._currentLOD._getWorldMatrixDeterminant() >= 0 !== this._getWorldMatrixDeterminant() >= 0;\n if (differentSign) {\n this._internalAbstractMeshDataInfo._actAsRegularMesh = true;\n return true;\n }\n this._internalAbstractMeshDataInfo._actAsRegularMesh = false;\n this._currentLOD._registerInstanceForRenderId(this, renderId);\n if (intermediateRendering) {\n if (!this._currentLOD._internalAbstractMeshDataInfo._isActiveIntermediate) {\n this._currentLOD._internalAbstractMeshDataInfo._onlyForInstancesIntermediate = true;\n return true;\n }\n }\n else {\n if (!this._currentLOD._internalAbstractMeshDataInfo._isActive) {\n this._currentLOD._internalAbstractMeshDataInfo._onlyForInstances = true;\n return true;\n }\n }\n }\n return false;\n }\n /** @internal */\n _postActivate() {\n if (this._sourceMesh.edgesShareWithInstances && this._sourceMesh._edgesRenderer && this._sourceMesh._edgesRenderer.isEnabled && this._sourceMesh._renderingGroup) {\n // we are using the edge renderer of the source mesh\n this._sourceMesh._renderingGroup._edgesRenderers.pushNoDuplicate(this._sourceMesh._edgesRenderer);\n this._sourceMesh._edgesRenderer.customInstances.push(this.getWorldMatrix());\n }\n else if (this._edgesRenderer && this._edgesRenderer.isEnabled && this._sourceMesh._renderingGroup) {\n // we are using the edge renderer defined for this instance\n this._sourceMesh._renderingGroup._edgesRenderers.push(this._edgesRenderer);\n }\n }\n getWorldMatrix() {\n if (this._currentLOD && this._currentLOD.billboardMode !== TransformNode.BILLBOARDMODE_NONE && this._currentLOD._masterMesh !== this) {\n if (!this._billboardWorldMatrix) {\n this._billboardWorldMatrix = new Matrix();\n }\n const tempMaster = this._currentLOD._masterMesh;\n this._currentLOD._masterMesh = this;\n TmpVectors.Vector3[7].copyFrom(this._currentLOD.position);\n this._currentLOD.position.set(0, 0, 0);\n this._billboardWorldMatrix.copyFrom(this._currentLOD.computeWorldMatrix(true));\n this._currentLOD.position.copyFrom(TmpVectors.Vector3[7]);\n this._currentLOD._masterMesh = tempMaster;\n return this._billboardWorldMatrix;\n }\n return super.getWorldMatrix();\n }\n get isAnInstance() {\n return true;\n }\n /**\n * Returns the current associated LOD AbstractMesh.\n * @param camera\n */\n getLOD(camera) {\n if (!camera) {\n return this;\n }\n const sourceMeshLODLevels = this.sourceMesh.getLODLevels();\n if (!sourceMeshLODLevels || sourceMeshLODLevels.length === 0) {\n this._currentLOD = this.sourceMesh;\n }\n else {\n const boundingInfo = this.getBoundingInfo();\n this._currentLOD = this.sourceMesh.getLOD(camera, boundingInfo.boundingSphere);\n }\n return this._currentLOD;\n }\n /**\n * @internal\n */\n _preActivateForIntermediateRendering(renderId) {\n return this.sourceMesh._preActivateForIntermediateRendering(renderId);\n }\n /** @internal */\n _syncSubMeshes() {\n this.releaseSubMeshes();\n if (this._sourceMesh.subMeshes) {\n for (let index = 0; index < this._sourceMesh.subMeshes.length; index++) {\n this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);\n }\n }\n return this;\n }\n /** @internal */\n _generatePointsArray() {\n return this._sourceMesh._generatePointsArray();\n }\n /** @internal */\n _updateBoundingInfo() {\n if (this.hasBoundingInfo) {\n this.getBoundingInfo().update(this.worldMatrixFromCache);\n }\n else {\n this.buildBoundingInfo(this.absolutePosition, this.absolutePosition, this.worldMatrixFromCache);\n }\n this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\n return this;\n }\n /**\n * Creates a new InstancedMesh from the current mesh.\n *\n * Returns the clone.\n * @param name the cloned mesh name\n * @param newParent the optional Node to parent the clone to.\n * @param doNotCloneChildren if `true` the model children aren't cloned.\n * @param newSourceMesh if set this mesh will be used as the source mesh instead of ths instance's one\n * @returns the clone\n */\n clone(name, newParent = null, doNotCloneChildren, newSourceMesh) {\n const result = (newSourceMesh || this._sourceMesh).createInstance(name);\n // Deep copy\n DeepCopier.DeepCopy(this, result, [\n \"name\",\n \"subMeshes\",\n \"uniqueId\",\n \"parent\",\n \"lightSources\",\n \"receiveShadows\",\n \"material\",\n \"visibility\",\n \"skeleton\",\n \"sourceMesh\",\n \"isAnInstance\",\n \"facetNb\",\n \"isFacetDataEnabled\",\n \"isBlocked\",\n \"useBones\",\n \"hasInstances\",\n \"collider\",\n \"edgesRenderer\",\n \"forward\",\n \"up\",\n \"right\",\n \"absolutePosition\",\n \"absoluteScaling\",\n \"absoluteRotationQuaternion\",\n \"isWorldMatrixFrozen\",\n \"nonUniformScaling\",\n \"behaviors\",\n \"worldMatrixFromCache\",\n \"hasThinInstances\",\n \"hasBoundingInfo\",\n ], []);\n // Bounding info\n this.refreshBoundingInfo();\n // Parent\n if (newParent) {\n result.parent = newParent;\n }\n if (!doNotCloneChildren) {\n // Children\n for (let index = 0; index < this.getScene().meshes.length; index++) {\n const mesh = this.getScene().meshes[index];\n if (mesh.parent === this) {\n mesh.clone(mesh.name, result);\n }\n }\n }\n result.computeWorldMatrix(true);\n this.onClonedObservable.notifyObservers(result);\n return result;\n }\n /**\n * Disposes the InstancedMesh.\n * Returns nothing.\n * @param doNotRecurse\n * @param disposeMaterialAndTextures\n */\n dispose(doNotRecurse, disposeMaterialAndTextures = false) {\n // Remove from mesh\n this._sourceMesh.removeInstance(this);\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\n }\n /**\n * @internal\n */\n _serializeAsParent(serializationObject) {\n super._serializeAsParent(serializationObject);\n serializationObject.parentId = this._sourceMesh.uniqueId;\n serializationObject.parentInstanceIndex = this._indexInSourceMeshInstanceArray;\n }\n /**\n * Instantiate (when possible) or clone that node with its hierarchy\n * @param newParent defines the new parent to use for the instance (or clone)\n * @param options defines options to configure how copy is done\n * @param options.doNotInstantiate defines if the model must be instantiated or just cloned\n * @param options.newSourcedMesh newSourcedMesh the new source mesh for the instance (or clone)\n * @param onNewNodeCreated defines an option callback to call when a clone or an instance is created\n * @returns an instance (or a clone) of the current node with its hierarchy\n */\n instantiateHierarchy(newParent = null, options, onNewNodeCreated) {\n const clone = this.clone(\"Clone of \" + (this.name || this.id), newParent || this.parent, true, options && options.newSourcedMesh);\n if (clone) {\n if (onNewNodeCreated) {\n onNewNodeCreated(this, clone);\n }\n }\n for (const child of this.getChildTransformNodes(true)) {\n child.instantiateHierarchy(clone, options, onNewNodeCreated);\n }\n return clone;\n }\n }\n Mesh.prototype.registerInstancedBuffer = function (kind, stride) {\n var _a, _b;\n // Remove existing one\n (_b = (_a = this._userInstancedBuffersStorage) === null || _a === void 0 ? void 0 : _a.vertexBuffers[kind]) === null || _b === void 0 ? void 0 : _b.dispose();\n // Creates the instancedBuffer field if not present\n if (!this.instancedBuffers) {\n this.instancedBuffers = {};\n for (const instance of this.instances) {\n instance.instancedBuffers = {};\n }\n if (!this._userInstancedBuffersStorage) {\n this._userInstancedBuffersStorage = {\n data: {},\n vertexBuffers: {},\n strides: {},\n sizes: {},\n vertexArrayObjects: this.getEngine().getCaps().vertexArrayObject ? {} : undefined,\n };\n }\n }\n // Creates an empty property for this kind\n this.instancedBuffers[kind] = null;\n this._userInstancedBuffersStorage.strides[kind] = stride;\n this._userInstancedBuffersStorage.sizes[kind] = stride * 32; // Initial size\n this._userInstancedBuffersStorage.data[kind] = new Float32Array(this._userInstancedBuffersStorage.sizes[kind]);\n this._userInstancedBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), this._userInstancedBuffersStorage.data[kind], kind, true, false, stride, true);\n for (const instance of this.instances) {\n instance.instancedBuffers[kind] = null;\n }\n this._invalidateInstanceVertexArrayObject();\n this._markSubMeshesAsAttributesDirty();\n };\n Mesh.prototype._processInstancedBuffers = function (visibleInstances, renderSelf) {\n const instanceCount = visibleInstances ? visibleInstances.length : 0;\n for (const kind in this.instancedBuffers) {\n let size = this._userInstancedBuffersStorage.sizes[kind];\n const stride = this._userInstancedBuffersStorage.strides[kind];\n // Resize if required\n const expectedSize = (instanceCount + 1) * stride;\n while (size < expectedSize) {\n size *= 2;\n }\n if (this._userInstancedBuffersStorage.data[kind].length != size) {\n this._userInstancedBuffersStorage.data[kind] = new Float32Array(size);\n this._userInstancedBuffersStorage.sizes[kind] = size;\n if (this._userInstancedBuffersStorage.vertexBuffers[kind]) {\n this._userInstancedBuffersStorage.vertexBuffers[kind].dispose();\n this._userInstancedBuffersStorage.vertexBuffers[kind] = null;\n }\n }\n const data = this._userInstancedBuffersStorage.data[kind];\n // Update data buffer\n let offset = 0;\n if (renderSelf) {\n const value = this.instancedBuffers[kind];\n if (value.toArray) {\n value.toArray(data, offset);\n }\n else if (value.copyToArray) {\n value.copyToArray(data, offset);\n }\n else {\n data[offset] = value;\n }\n offset += stride;\n }\n for (let instanceIndex = 0; instanceIndex < instanceCount; instanceIndex++) {\n const instance = visibleInstances[instanceIndex];\n const value = instance.instancedBuffers[kind];\n if (value.toArray) {\n value.toArray(data, offset);\n }\n else if (value.copyToArray) {\n value.copyToArray(data, offset);\n }\n else {\n data[offset] = value;\n }\n offset += stride;\n }\n // Update vertex buffer\n if (!this._userInstancedBuffersStorage.vertexBuffers[kind]) {\n this._userInstancedBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), this._userInstancedBuffersStorage.data[kind], kind, true, false, stride, true);\n this._invalidateInstanceVertexArrayObject();\n }\n else {\n this._userInstancedBuffersStorage.vertexBuffers[kind].updateDirectly(data, 0);\n }\n }\n };\n Mesh.prototype._invalidateInstanceVertexArrayObject = function () {\n if (!this._userInstancedBuffersStorage || this._userInstancedBuffersStorage.vertexArrayObjects === undefined) {\n return;\n }\n for (const kind in this._userInstancedBuffersStorage.vertexArrayObjects) {\n this.getEngine().releaseVertexArrayObject(this._userInstancedBuffersStorage.vertexArrayObjects[kind]);\n }\n this._userInstancedBuffersStorage.vertexArrayObjects = {};\n };\n Mesh.prototype._disposeInstanceSpecificData = function () {\n if (this._instanceDataStorage.instancesBuffer) {\n this._instanceDataStorage.instancesBuffer.dispose();\n this._instanceDataStorage.instancesBuffer = null;\n }\n while (this.instances.length) {\n this.instances[0].dispose();\n }\n for (const kind in this.instancedBuffers) {\n if (this._userInstancedBuffersStorage.vertexBuffers[kind]) {\n this._userInstancedBuffersStorage.vertexBuffers[kind].dispose();\n }\n }\n this._invalidateInstanceVertexArrayObject();\n this.instancedBuffers = {};\n };\n\n const onCreatedEffectParameters$3 = { effect: null, subMesh: null };\n /**\n * The ShaderMaterial object has the necessary methods to pass data from your scene to the Vertex and Fragment Shaders and returns a material that can be applied to any mesh.\n *\n * This returned material effects how the mesh will look based on the code in the shaders.\n *\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial\n */\n class ShaderMaterial extends PushMaterial {\n /**\n * Instantiate a new shader material.\n * The ShaderMaterial object has the necessary methods to pass data from your scene to the Vertex and Fragment Shaders and returns a material that can be applied to any mesh.\n * This returned material effects how the mesh will look based on the code in the shaders.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial\n * @param name Define the name of the material in the scene\n * @param scene Define the scene the material belongs to\n * @param shaderPath Defines the route to the shader code in one of three ways:\n * * object: \\{ vertex: \"custom\", fragment: \"custom\" \\}, used with Effect.ShadersStore[\"customVertexShader\"] and Effect.ShadersStore[\"customFragmentShader\"]\n * * object: \\{ vertexElement: \"vertexShaderCode\", fragmentElement: \"fragmentShaderCode\" \\}, used with shader code in script tags\n * * object: \\{ vertexSource: \"vertex shader code string\", fragmentSource: \"fragment shader code string\" \\} using with strings containing the shaders code\n * * string: \"./COMMON_NAME\", used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.\n * @param options Define the options used to create the shader\n * @param storeEffectOnSubMeshes true to store effect on submeshes, false to store the effect directly in the material class.\n */\n constructor(name, scene, shaderPath, options = {}, storeEffectOnSubMeshes = true) {\n super(name, scene, storeEffectOnSubMeshes);\n this._textures = {};\n this._textureArrays = {};\n this._externalTextures = {};\n this._floats = {};\n this._ints = {};\n this._uints = {};\n this._floatsArrays = {};\n this._colors3 = {};\n this._colors3Arrays = {};\n this._colors4 = {};\n this._colors4Arrays = {};\n this._vectors2 = {};\n this._vectors3 = {};\n this._vectors4 = {};\n this._quaternions = {};\n this._quaternionsArrays = {};\n this._matrices = {};\n this._matrixArrays = {};\n this._matrices3x3 = {};\n this._matrices2x2 = {};\n this._vectors2Arrays = {};\n this._vectors3Arrays = {};\n this._vectors4Arrays = {};\n this._uniformBuffers = {};\n this._textureSamplers = {};\n this._storageBuffers = {};\n this._cachedWorldViewMatrix = new Matrix();\n this._cachedWorldViewProjectionMatrix = new Matrix();\n this._multiview = false;\n /**\n * @internal\n */\n this._materialHelperNeedsPreviousMatrices = false;\n this._shaderPath = shaderPath;\n this._options = Object.assign({ needAlphaBlending: false, needAlphaTesting: false, attributes: [\"position\", \"normal\", \"uv\"], uniforms: [\"worldViewProjection\"], uniformBuffers: [], samplers: [], externalTextures: [], samplerObjects: [], storageBuffers: [], defines: [], useClipPlane: false }, options);\n }\n /**\n * Gets the shader path used to define the shader code\n * It can be modified to trigger a new compilation\n */\n get shaderPath() {\n return this._shaderPath;\n }\n /**\n * Sets the shader path used to define the shader code\n * It can be modified to trigger a new compilation\n */\n set shaderPath(shaderPath) {\n this._shaderPath = shaderPath;\n }\n /**\n * Gets the options used to compile the shader.\n * They can be modified to trigger a new compilation\n */\n get options() {\n return this._options;\n }\n /**\n * is multiview set to true?\n */\n get isMultiview() {\n return this._multiview;\n }\n /**\n * Gets the current class name of the material e.g. \"ShaderMaterial\"\n * Mainly use in serialization.\n * @returns the class name\n */\n getClassName() {\n return \"ShaderMaterial\";\n }\n /**\n * Specifies if the material will require alpha blending\n * @returns a boolean specifying if alpha blending is needed\n */\n needAlphaBlending() {\n return this.alpha < 1.0 || this._options.needAlphaBlending;\n }\n /**\n * Specifies if this material should be rendered in alpha test mode\n * @returns a boolean specifying if an alpha test is needed.\n */\n needAlphaTesting() {\n return this._options.needAlphaTesting;\n }\n _checkUniform(uniformName) {\n if (this._options.uniforms.indexOf(uniformName) === -1) {\n this._options.uniforms.push(uniformName);\n }\n }\n /**\n * Set a texture in the shader.\n * @param name Define the name of the uniform samplers as defined in the shader\n * @param texture Define the texture to bind to this sampler\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setTexture(name, texture) {\n if (this._options.samplers.indexOf(name) === -1) {\n this._options.samplers.push(name);\n }\n this._textures[name] = texture;\n return this;\n }\n /**\n * Set a texture array in the shader.\n * @param name Define the name of the uniform sampler array as defined in the shader\n * @param textures Define the list of textures to bind to this sampler\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setTextureArray(name, textures) {\n if (this._options.samplers.indexOf(name) === -1) {\n this._options.samplers.push(name);\n }\n this._checkUniform(name);\n this._textureArrays[name] = textures;\n return this;\n }\n /**\n * Set an internal texture in the shader.\n * @param name Define the name of the uniform samplers as defined in the shader\n * @param texture Define the texture to bind to this sampler\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setExternalTexture(name, texture) {\n if (this._options.externalTextures.indexOf(name) === -1) {\n this._options.externalTextures.push(name);\n }\n this._externalTextures[name] = texture;\n return this;\n }\n /**\n * Set a float in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setFloat(name, value) {\n this._checkUniform(name);\n this._floats[name] = value;\n return this;\n }\n /**\n * Set a int in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setInt(name, value) {\n this._checkUniform(name);\n this._ints[name] = value;\n return this;\n }\n /**\n * Set a unsigned int in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setUInt(name, value) {\n this._checkUniform(name);\n this._uints[name] = value;\n return this;\n }\n /**\n * Set an array of floats in the shader.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setFloats(name, value) {\n this._checkUniform(name);\n this._floatsArrays[name] = value;\n return this;\n }\n /**\n * Set a vec3 in the shader from a Color3.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setColor3(name, value) {\n this._checkUniform(name);\n this._colors3[name] = value;\n return this;\n }\n /**\n * Set a vec3 array in the shader from a Color3 array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setColor3Array(name, value) {\n this._checkUniform(name);\n this._colors3Arrays[name] = value.reduce((arr, color) => {\n color.toArray(arr, arr.length);\n return arr;\n }, []);\n return this;\n }\n /**\n * Set a vec4 in the shader from a Color4.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setColor4(name, value) {\n this._checkUniform(name);\n this._colors4[name] = value;\n return this;\n }\n /**\n * Set a vec4 array in the shader from a Color4 array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setColor4Array(name, value) {\n this._checkUniform(name);\n this._colors4Arrays[name] = value.reduce((arr, color) => {\n color.toArray(arr, arr.length);\n return arr;\n }, []);\n return this;\n }\n /**\n * Set a vec2 in the shader from a Vector2.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setVector2(name, value) {\n this._checkUniform(name);\n this._vectors2[name] = value;\n return this;\n }\n /**\n * Set a vec3 in the shader from a Vector3.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setVector3(name, value) {\n this._checkUniform(name);\n this._vectors3[name] = value;\n return this;\n }\n /**\n * Set a vec4 in the shader from a Vector4.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setVector4(name, value) {\n this._checkUniform(name);\n this._vectors4[name] = value;\n return this;\n }\n /**\n * Set a vec4 in the shader from a Quaternion.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setQuaternion(name, value) {\n this._checkUniform(name);\n this._quaternions[name] = value;\n return this;\n }\n /**\n * Set a vec4 array in the shader from a Quaternion array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setQuaternionArray(name, value) {\n this._checkUniform(name);\n this._quaternionsArrays[name] = value.reduce((arr, quaternion) => {\n quaternion.toArray(arr, arr.length);\n return arr;\n }, []);\n return this;\n }\n /**\n * Set a mat4 in the shader from a Matrix.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setMatrix(name, value) {\n this._checkUniform(name);\n this._matrices[name] = value;\n return this;\n }\n /**\n * Set a float32Array in the shader from a matrix array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setMatrices(name, value) {\n this._checkUniform(name);\n const float32Array = new Float32Array(value.length * 16);\n for (let index = 0; index < value.length; index++) {\n const matrix = value[index];\n matrix.copyToArray(float32Array, index * 16);\n }\n this._matrixArrays[name] = float32Array;\n return this;\n }\n /**\n * Set a mat3 in the shader from a Float32Array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setMatrix3x3(name, value) {\n this._checkUniform(name);\n this._matrices3x3[name] = value;\n return this;\n }\n /**\n * Set a mat2 in the shader from a Float32Array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setMatrix2x2(name, value) {\n this._checkUniform(name);\n this._matrices2x2[name] = value;\n return this;\n }\n /**\n * Set a vec2 array in the shader from a number array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setArray2(name, value) {\n this._checkUniform(name);\n this._vectors2Arrays[name] = value;\n return this;\n }\n /**\n * Set a vec3 array in the shader from a number array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setArray3(name, value) {\n this._checkUniform(name);\n this._vectors3Arrays[name] = value;\n return this;\n }\n /**\n * Set a vec4 array in the shader from a number array.\n * @param name Define the name of the uniform as defined in the shader\n * @param value Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setArray4(name, value) {\n this._checkUniform(name);\n this._vectors4Arrays[name] = value;\n return this;\n }\n /**\n * Set a uniform buffer in the shader\n * @param name Define the name of the uniform as defined in the shader\n * @param buffer Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setUniformBuffer(name, buffer) {\n if (this._options.uniformBuffers.indexOf(name) === -1) {\n this._options.uniformBuffers.push(name);\n }\n this._uniformBuffers[name] = buffer;\n return this;\n }\n /**\n * Set a texture sampler in the shader\n * @param name Define the name of the uniform as defined in the shader\n * @param sampler Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setTextureSampler(name, sampler) {\n if (this._options.samplerObjects.indexOf(name) === -1) {\n this._options.samplerObjects.push(name);\n }\n this._textureSamplers[name] = sampler;\n return this;\n }\n /**\n * Set a storage buffer in the shader\n * @param name Define the name of the storage buffer as defined in the shader\n * @param buffer Define the value to give to the uniform\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setStorageBuffer(name, buffer) {\n if (this._options.storageBuffers.indexOf(name) === -1) {\n this._options.storageBuffers.push(name);\n }\n this._storageBuffers[name] = buffer;\n return this;\n }\n /**\n * Adds, removes, or replaces the specified shader define and value.\n * * setDefine(\"MY_DEFINE\", true); // enables a boolean define\n * * setDefine(\"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)\n * * setDefine(\"MY_DEFINE\", false); // disables and removes the define\n * Note if the active defines do change, the shader will be recompiled and this can be expensive.\n * @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.\n * @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\n * @returns the material itself allowing \"fluent\" like uniform updates\n */\n setDefine(define, value) {\n // First remove any existing define with this name.\n const defineName = define.trimEnd() + \" \";\n const existingDefineIdx = this.options.defines.findIndex((x) => x === define || x.startsWith(defineName));\n if (existingDefineIdx >= 0) {\n this.options.defines.splice(existingDefineIdx, 1);\n }\n // Then add the new define value. (If it's a boolean value and false, don't add it.)\n if (typeof value !== \"boolean\" || value) {\n this.options.defines.push(defineName + value);\n }\n return this;\n }\n /**\n * Specifies that the submesh is ready to be used\n * @param mesh defines the mesh to check\n * @param subMesh defines which submesh to check\n * @param useInstances specifies that instances should be used\n * @returns a boolean indicating that the submesh is ready or not\n */\n isReadyForSubMesh(mesh, subMesh, useInstances) {\n return this.isReady(mesh, useInstances, subMesh);\n }\n /**\n * Checks if the material is ready to render the requested mesh\n * @param mesh Define the mesh to render\n * @param useInstances Define whether or not the material is used with instances\n * @param subMesh defines which submesh to render\n * @returns true if ready, otherwise false\n */\n isReady(mesh, useInstances, subMesh) {\n var _a, _b, _c, _d;\n const storeEffectOnSubMeshes = subMesh && this._storeEffectOnSubMeshes;\n if (this.isFrozen) {\n if (storeEffectOnSubMeshes) {\n if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {\n return true;\n }\n }\n else {\n const effect = this._drawWrapper.effect;\n if (effect && effect._wasPreviouslyReady && effect._wasPreviouslyUsingInstances === useInstances) {\n return true;\n }\n }\n }\n const scene = this.getScene();\n const engine = scene.getEngine();\n // Instances\n const defines = [];\n const attribs = [];\n const fallbacks = new EffectFallbacks();\n let shaderName = this._shaderPath, uniforms = this._options.uniforms, uniformBuffers = this._options.uniformBuffers, samplers = this._options.samplers;\n // global multiview\n if (engine.getCaps().multiview && scene.activeCamera && scene.activeCamera.outputRenderTarget && scene.activeCamera.outputRenderTarget.getViewCount() > 1) {\n this._multiview = true;\n defines.push(\"#define MULTIVIEW\");\n if (this._options.uniforms.indexOf(\"viewProjection\") !== -1 && this._options.uniforms.indexOf(\"viewProjectionR\") === -1) {\n this._options.uniforms.push(\"viewProjectionR\");\n }\n }\n for (let index = 0; index < this._options.defines.length; index++) {\n const defineToAdd = this._options.defines[index].indexOf(\"#define\") === 0 ? this._options.defines[index] : `#define ${this._options.defines[index]}`;\n defines.push(defineToAdd);\n }\n for (let index = 0; index < this._options.attributes.length; index++) {\n attribs.push(this._options.attributes[index]);\n }\n if (mesh && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {\n attribs.push(VertexBuffer.ColorKind);\n defines.push(\"#define VERTEXCOLOR\");\n }\n if (useInstances) {\n defines.push(\"#define INSTANCES\");\n MaterialHelper.PushAttributesForInstances(attribs, this._materialHelperNeedsPreviousMatrices);\n if (mesh === null || mesh === void 0 ? void 0 : mesh.hasThinInstances) {\n defines.push(\"#define THIN_INSTANCES\");\n if (mesh && mesh.isVerticesDataPresent(VertexBuffer.ColorInstanceKind)) {\n attribs.push(VertexBuffer.ColorInstanceKind);\n defines.push(\"#define INSTANCESCOLOR\");\n }\n }\n }\n // Bones\n if (mesh && mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (mesh.numBoneInfluencers > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n const skeleton = mesh.skeleton;\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\n fallbacks.addCPUSkinningFallback(0, mesh);\n if (skeleton.isUsingTextureForMatrices) {\n defines.push(\"#define BONETEXTURE\");\n if (this._options.uniforms.indexOf(\"boneTextureWidth\") === -1) {\n this._options.uniforms.push(\"boneTextureWidth\");\n }\n if (this._options.samplers.indexOf(\"boneSampler\") === -1) {\n this._options.samplers.push(\"boneSampler\");\n }\n }\n else {\n defines.push(\"#define BonesPerMesh \" + (skeleton.bones.length + 1));\n if (this._options.uniforms.indexOf(\"mBones\") === -1) {\n this._options.uniforms.push(\"mBones\");\n }\n }\n }\n else {\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\n }\n // Morph\n let numInfluencers = 0;\n const manager = mesh ? mesh.morphTargetManager : null;\n if (manager) {\n const uv = manager.supportsUVs && defines.indexOf(\"#define UV1\") !== -1;\n const tangent = manager.supportsTangents && defines.indexOf(\"#define TANGENT\") !== -1;\n const normal = manager.supportsNormals && defines.indexOf(\"#define NORMAL\") !== -1;\n numInfluencers = manager.numInfluencers;\n if (uv) {\n defines.push(\"#define MORPHTARGETS_UV\");\n }\n if (tangent) {\n defines.push(\"#define MORPHTARGETS_TANGENT\");\n }\n if (normal) {\n defines.push(\"#define MORPHTARGETS_NORMAL\");\n }\n if (numInfluencers > 0) {\n defines.push(\"#define MORPHTARGETS\");\n }\n if (manager.isUsingTextureForTargets) {\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\n if (this._options.uniforms.indexOf(\"morphTargetTextureIndices\") === -1) {\n this._options.uniforms.push(\"morphTargetTextureIndices\");\n }\n if (this._options.samplers.indexOf(\"morphTargets\") === -1) {\n this._options.samplers.push(\"morphTargets\");\n }\n }\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numInfluencers);\n for (let index = 0; index < numInfluencers; index++) {\n attribs.push(VertexBuffer.PositionKind + index);\n if (normal) {\n attribs.push(VertexBuffer.NormalKind + index);\n }\n if (tangent) {\n attribs.push(VertexBuffer.TangentKind + index);\n }\n if (uv) {\n attribs.push(VertexBuffer.UVKind + \"_\" + index);\n }\n }\n if (numInfluencers > 0) {\n uniforms = uniforms.slice();\n uniforms.push(\"morphTargetInfluences\");\n uniforms.push(\"morphTargetTextureInfo\");\n uniforms.push(\"morphTargetTextureIndices\");\n }\n }\n else {\n defines.push(\"#define NUM_MORPH_INFLUENCERS 0\");\n }\n // Baked Vertex Animation\n if (mesh) {\n const bvaManager = mesh.bakedVertexAnimationManager;\n if (bvaManager && bvaManager.isEnabled) {\n defines.push(\"#define BAKED_VERTEX_ANIMATION_TEXTURE\");\n if (this._options.uniforms.indexOf(\"bakedVertexAnimationSettings\") === -1) {\n this._options.uniforms.push(\"bakedVertexAnimationSettings\");\n }\n if (this._options.uniforms.indexOf(\"bakedVertexAnimationTextureSizeInverted\") === -1) {\n this._options.uniforms.push(\"bakedVertexAnimationTextureSizeInverted\");\n }\n if (this._options.uniforms.indexOf(\"bakedVertexAnimationTime\") === -1) {\n this._options.uniforms.push(\"bakedVertexAnimationTime\");\n }\n if (this._options.samplers.indexOf(\"bakedVertexAnimationTexture\") === -1) {\n this._options.samplers.push(\"bakedVertexAnimationTexture\");\n }\n }\n MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\n }\n // Textures\n for (const name in this._textures) {\n if (!this._textures[name].isReady()) {\n return false;\n }\n }\n // Alpha test\n if (mesh && this._shouldTurnAlphaTestOn(mesh)) {\n defines.push(\"#define ALPHATEST\");\n }\n // Clip planes\n if (this._options.useClipPlane !== false) {\n addClipPlaneUniforms(uniforms);\n prepareStringDefinesForClipPlanes(this, scene, defines);\n }\n if (this.customShaderNameResolve) {\n uniforms = uniforms.slice();\n uniformBuffers = uniformBuffers.slice();\n samplers = samplers.slice();\n shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs);\n }\n const drawWrapper = storeEffectOnSubMeshes ? subMesh._getDrawWrapper() : this._drawWrapper;\n const previousEffect = (_a = drawWrapper === null || drawWrapper === void 0 ? void 0 : drawWrapper.effect) !== null && _a !== void 0 ? _a : null;\n const previousDefines = (_b = drawWrapper === null || drawWrapper === void 0 ? void 0 : drawWrapper.defines) !== null && _b !== void 0 ? _b : null;\n const join = defines.join(\"\\n\");\n let effect = previousEffect;\n if (previousDefines !== join) {\n effect = engine.createEffect(shaderName, {\n attributes: attribs,\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: join,\n fallbacks: fallbacks,\n onCompiled: this.onCompiled,\n onError: this.onError,\n indexParameters: { maxSimultaneousMorphTargets: numInfluencers },\n shaderLanguage: this._options.shaderLanguage,\n }, engine);\n if (storeEffectOnSubMeshes) {\n subMesh.setEffect(effect, join, this._materialContext);\n }\n else if (drawWrapper) {\n drawWrapper.setEffect(effect, join);\n }\n if (this._onEffectCreatedObservable) {\n onCreatedEffectParameters$3.effect = effect;\n onCreatedEffectParameters$3.subMesh = (_c = subMesh !== null && subMesh !== void 0 ? subMesh : mesh === null || mesh === void 0 ? void 0 : mesh.subMeshes[0]) !== null && _c !== void 0 ? _c : null;\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters$3);\n }\n }\n effect._wasPreviouslyUsingInstances = !!useInstances;\n if ((_d = !(effect === null || effect === void 0 ? void 0 : effect.isReady())) !== null && _d !== void 0 ? _d : true) {\n return false;\n }\n if (previousEffect !== effect) {\n scene.resetCachedMaterial();\n }\n effect._wasPreviouslyReady = true;\n return true;\n }\n /**\n * Binds the world matrix to the material\n * @param world defines the world transformation matrix\n * @param effectOverride - If provided, use this effect instead of internal effect\n */\n bindOnlyWorldMatrix(world, effectOverride) {\n const scene = this.getScene();\n const effect = effectOverride !== null && effectOverride !== void 0 ? effectOverride : this.getEffect();\n if (!effect) {\n return;\n }\n if (this._options.uniforms.indexOf(\"world\") !== -1) {\n effect.setMatrix(\"world\", world);\n }\n if (this._options.uniforms.indexOf(\"worldView\") !== -1) {\n world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);\n effect.setMatrix(\"worldView\", this._cachedWorldViewMatrix);\n }\n if (this._options.uniforms.indexOf(\"worldViewProjection\") !== -1) {\n world.multiplyToRef(scene.getTransformMatrix(), this._cachedWorldViewProjectionMatrix);\n effect.setMatrix(\"worldViewProjection\", this._cachedWorldViewProjectionMatrix);\n }\n }\n /**\n * Binds the submesh to this material by preparing the effect and shader to draw\n * @param world defines the world transformation matrix\n * @param mesh defines the mesh containing the submesh\n * @param subMesh defines the submesh to bind the material to\n */\n bindForSubMesh(world, mesh, subMesh) {\n var _a;\n this.bind(world, mesh, (_a = subMesh._drawWrapperOverride) === null || _a === void 0 ? void 0 : _a.effect, subMesh);\n }\n /**\n * Binds the material to the mesh\n * @param world defines the world transformation matrix\n * @param mesh defines the mesh to bind the material to\n * @param effectOverride - If provided, use this effect instead of internal effect\n * @param subMesh defines the submesh to bind the material to\n */\n bind(world, mesh, effectOverride, subMesh) {\n var _a;\n // Std values\n const storeEffectOnSubMeshes = subMesh && this._storeEffectOnSubMeshes;\n const effect = effectOverride !== null && effectOverride !== void 0 ? effectOverride : (storeEffectOnSubMeshes ? subMesh.effect : this.getEffect());\n if (!effect) {\n return;\n }\n this._activeEffect = effect;\n this.bindOnlyWorldMatrix(world, effectOverride);\n const uniformBuffers = this._options.uniformBuffers;\n let useSceneUBO = false;\n if (effect && uniformBuffers && uniformBuffers.length > 0 && this.getScene().getEngine().supportsUniformBuffers) {\n for (let i = 0; i < uniformBuffers.length; ++i) {\n const bufferName = uniformBuffers[i];\n switch (bufferName) {\n case \"Mesh\":\n if (mesh) {\n mesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\n mesh.transferToEffect(world);\n }\n break;\n case \"Scene\":\n MaterialHelper.BindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());\n this.getScene().finalizeSceneUbo();\n useSceneUBO = true;\n break;\n }\n }\n }\n const mustRebind = mesh && storeEffectOnSubMeshes ? this._mustRebind(this.getScene(), effect, mesh.visibility) : this.getScene().getCachedMaterial() !== this;\n if (effect && mustRebind) {\n if (!useSceneUBO && this._options.uniforms.indexOf(\"view\") !== -1) {\n effect.setMatrix(\"view\", this.getScene().getViewMatrix());\n }\n if (!useSceneUBO && this._options.uniforms.indexOf(\"projection\") !== -1) {\n effect.setMatrix(\"projection\", this.getScene().getProjectionMatrix());\n }\n if (!useSceneUBO && this._options.uniforms.indexOf(\"viewProjection\") !== -1) {\n effect.setMatrix(\"viewProjection\", this.getScene().getTransformMatrix());\n if (this._multiview) {\n effect.setMatrix(\"viewProjectionR\", this.getScene()._transformMatrixR);\n }\n }\n if (this.getScene().activeCamera && this._options.uniforms.indexOf(\"cameraPosition\") !== -1) {\n effect.setVector3(\"cameraPosition\", this.getScene().activeCamera.globalPosition);\n }\n // Bones\n MaterialHelper.BindBonesParameters(mesh, effect);\n // Clip plane\n bindClipPlane(effect, this, this.getScene());\n let name;\n // Texture\n for (name in this._textures) {\n effect.setTexture(name, this._textures[name]);\n }\n // Texture arrays\n for (name in this._textureArrays) {\n effect.setTextureArray(name, this._textureArrays[name]);\n }\n // External texture\n for (name in this._externalTextures) {\n effect.setExternalTexture(name, this._externalTextures[name]);\n }\n // Int\n for (name in this._ints) {\n effect.setInt(name, this._ints[name]);\n }\n // UInt\n for (name in this._uints) {\n effect.setUInt(name, this._uints[name]);\n }\n // Float\n for (name in this._floats) {\n effect.setFloat(name, this._floats[name]);\n }\n // Floats\n for (name in this._floatsArrays) {\n effect.setArray(name, this._floatsArrays[name]);\n }\n // Color3\n for (name in this._colors3) {\n effect.setColor3(name, this._colors3[name]);\n }\n // Color3Array\n for (name in this._colors3Arrays) {\n effect.setArray3(name, this._colors3Arrays[name]);\n }\n // Color4\n for (name in this._colors4) {\n const color = this._colors4[name];\n effect.setFloat4(name, color.r, color.g, color.b, color.a);\n }\n // Color4Array\n for (name in this._colors4Arrays) {\n effect.setArray4(name, this._colors4Arrays[name]);\n }\n // Vector2\n for (name in this._vectors2) {\n effect.setVector2(name, this._vectors2[name]);\n }\n // Vector3\n for (name in this._vectors3) {\n effect.setVector3(name, this._vectors3[name]);\n }\n // Vector4\n for (name in this._vectors4) {\n effect.setVector4(name, this._vectors4[name]);\n }\n // Quaternion\n for (name in this._quaternions) {\n effect.setQuaternion(name, this._quaternions[name]);\n }\n // Matrix\n for (name in this._matrices) {\n effect.setMatrix(name, this._matrices[name]);\n }\n // MatrixArray\n for (name in this._matrixArrays) {\n effect.setMatrices(name, this._matrixArrays[name]);\n }\n // Matrix 3x3\n for (name in this._matrices3x3) {\n effect.setMatrix3x3(name, this._matrices3x3[name]);\n }\n // Matrix 2x2\n for (name in this._matrices2x2) {\n effect.setMatrix2x2(name, this._matrices2x2[name]);\n }\n // Vector2Array\n for (name in this._vectors2Arrays) {\n effect.setArray2(name, this._vectors2Arrays[name]);\n }\n // Vector3Array\n for (name in this._vectors3Arrays) {\n effect.setArray3(name, this._vectors3Arrays[name]);\n }\n // Vector4Array\n for (name in this._vectors4Arrays) {\n effect.setArray4(name, this._vectors4Arrays[name]);\n }\n // QuaternionArray\n for (name in this._quaternionsArrays) {\n effect.setArray4(name, this._quaternionsArrays[name]);\n }\n // Uniform buffers\n for (name in this._uniformBuffers) {\n const buffer = this._uniformBuffers[name].getBuffer();\n if (buffer) {\n effect.bindUniformBuffer(buffer, name);\n }\n }\n // Samplers\n for (name in this._textureSamplers) {\n effect.setTextureSampler(name, this._textureSamplers[name]);\n }\n // Storage buffers\n for (name in this._storageBuffers) {\n effect.setStorageBuffer(name, this._storageBuffers[name]);\n }\n }\n if (effect && mesh && (mustRebind || !this.isFrozen)) {\n // Morph targets\n const manager = mesh.morphTargetManager;\n if (manager && manager.numInfluencers > 0) {\n MaterialHelper.BindMorphTargetParameters(mesh, effect);\n }\n const bvaManager = mesh.bakedVertexAnimationManager;\n if (bvaManager && bvaManager.isEnabled) {\n (_a = mesh.bakedVertexAnimationManager) === null || _a === void 0 ? void 0 : _a.bind(effect, !!effect._wasPreviouslyUsingInstances);\n }\n }\n this._afterBind(mesh, effect);\n }\n /**\n * Gets the active textures from the material\n * @returns an array of textures\n */\n getActiveTextures() {\n const activeTextures = super.getActiveTextures();\n for (const name in this._textures) {\n activeTextures.push(this._textures[name]);\n }\n for (const name in this._textureArrays) {\n const array = this._textureArrays[name];\n for (let index = 0; index < array.length; index++) {\n activeTextures.push(array[index]);\n }\n }\n return activeTextures;\n }\n /**\n * Specifies if the material uses a texture\n * @param texture defines the texture to check against the material\n * @returns a boolean specifying if the material uses the texture\n */\n hasTexture(texture) {\n if (super.hasTexture(texture)) {\n return true;\n }\n for (const name in this._textures) {\n if (this._textures[name] === texture) {\n return true;\n }\n }\n for (const name in this._textureArrays) {\n const array = this._textureArrays[name];\n for (let index = 0; index < array.length; index++) {\n if (array[index] === texture) {\n return true;\n }\n }\n }\n return false;\n }\n /**\n * Makes a duplicate of the material, and gives it a new name\n * @param name defines the new name for the duplicated material\n * @returns the cloned material\n */\n clone(name) {\n const result = SerializationHelper.Clone(() => new ShaderMaterial(name, this.getScene(), this._shaderPath, this._options, this._storeEffectOnSubMeshes), this);\n result.name = name;\n result.id = name;\n // Shader code path\n if (typeof result._shaderPath === \"object\") {\n result._shaderPath = Object.assign({}, result._shaderPath);\n }\n // Options\n this._options = Object.assign({}, this._options);\n Object.keys(this._options).forEach((propName) => {\n const propValue = this._options[propName];\n if (Array.isArray(propValue)) {\n this._options[propName] = propValue.slice(0);\n }\n });\n // Stencil\n this.stencil.copyTo(result.stencil);\n // Texture\n for (const key in this._textures) {\n result.setTexture(key, this._textures[key]);\n }\n // TextureArray\n for (const key in this._textureArrays) {\n result.setTextureArray(key, this._textureArrays[key]);\n }\n // External texture\n for (const key in this._externalTextures) {\n result.setExternalTexture(key, this._externalTextures[key]);\n }\n // Int\n for (const key in this._ints) {\n result.setInt(key, this._ints[key]);\n }\n // UInt\n for (const key in this._uints) {\n result.setUInt(key, this._uints[key]);\n }\n // Float\n for (const key in this._floats) {\n result.setFloat(key, this._floats[key]);\n }\n // Floats\n for (const key in this._floatsArrays) {\n result.setFloats(key, this._floatsArrays[key]);\n }\n // Color3\n for (const key in this._colors3) {\n result.setColor3(key, this._colors3[key]);\n }\n // Color3Array\n for (const key in this._colors3Arrays) {\n result._colors3Arrays[key] = this._colors3Arrays[key];\n }\n // Color4\n for (const key in this._colors4) {\n result.setColor4(key, this._colors4[key]);\n }\n // Color4Array\n for (const key in this._colors4Arrays) {\n result._colors4Arrays[key] = this._colors4Arrays[key];\n }\n // Vector2\n for (const key in this._vectors2) {\n result.setVector2(key, this._vectors2[key]);\n }\n // Vector3\n for (const key in this._vectors3) {\n result.setVector3(key, this._vectors3[key]);\n }\n // Vector4\n for (const key in this._vectors4) {\n result.setVector4(key, this._vectors4[key]);\n }\n // Quaternion\n for (const key in this._quaternions) {\n result.setQuaternion(key, this._quaternions[key]);\n }\n // QuaternionArray\n for (const key in this._quaternionsArrays) {\n result._quaternionsArrays[key] = this._quaternionsArrays[key];\n }\n // Matrix\n for (const key in this._matrices) {\n result.setMatrix(key, this._matrices[key]);\n }\n // MatrixArray\n for (const key in this._matrixArrays) {\n result._matrixArrays[key] = this._matrixArrays[key].slice();\n }\n // Matrix 3x3\n for (const key in this._matrices3x3) {\n result.setMatrix3x3(key, this._matrices3x3[key]);\n }\n // Matrix 2x2\n for (const key in this._matrices2x2) {\n result.setMatrix2x2(key, this._matrices2x2[key]);\n }\n // Vector2Array\n for (const key in this._vectors2Arrays) {\n result.setArray2(key, this._vectors2Arrays[key]);\n }\n // Vector3Array\n for (const key in this._vectors3Arrays) {\n result.setArray3(key, this._vectors3Arrays[key]);\n }\n // Vector4Array\n for (const key in this._vectors4Arrays) {\n result.setArray4(key, this._vectors4Arrays[key]);\n }\n // Uniform buffers\n for (const key in this._uniformBuffers) {\n result.setUniformBuffer(key, this._uniformBuffers[key]);\n }\n // Samplers\n for (const key in this._textureSamplers) {\n result.setTextureSampler(key, this._textureSamplers[key]);\n }\n // Storag buffers\n for (const key in this._storageBuffers) {\n result.setStorageBuffer(key, this._storageBuffers[key]);\n }\n return result;\n }\n /**\n * Disposes the material\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\n * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh\n */\n dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh) {\n if (forceDisposeTextures) {\n let name;\n for (name in this._textures) {\n this._textures[name].dispose();\n }\n for (name in this._textureArrays) {\n const array = this._textureArrays[name];\n for (let index = 0; index < array.length; index++) {\n array[index].dispose();\n }\n }\n }\n this._textures = {};\n super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);\n }\n /**\n * Serializes this material in a JSON representation\n * @returns the serialized material object\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this);\n serializationObject.customType = \"BABYLON.ShaderMaterial\";\n serializationObject.uniqueId = this.uniqueId;\n serializationObject.options = this._options;\n serializationObject.shaderPath = this._shaderPath;\n serializationObject.storeEffectOnSubMeshes = this._storeEffectOnSubMeshes;\n let name;\n // Stencil\n serializationObject.stencil = this.stencil.serialize();\n // Texture\n serializationObject.textures = {};\n for (name in this._textures) {\n serializationObject.textures[name] = this._textures[name].serialize();\n }\n // Texture arrays\n serializationObject.textureArrays = {};\n for (name in this._textureArrays) {\n serializationObject.textureArrays[name] = [];\n const array = this._textureArrays[name];\n for (let index = 0; index < array.length; index++) {\n serializationObject.textureArrays[name].push(array[index].serialize());\n }\n }\n // Int\n serializationObject.ints = {};\n for (name in this._ints) {\n serializationObject.ints[name] = this._ints[name];\n }\n // UInt\n serializationObject.uints = {};\n for (name in this._uints) {\n serializationObject.uints[name] = this._uints[name];\n }\n // Float\n serializationObject.floats = {};\n for (name in this._floats) {\n serializationObject.floats[name] = this._floats[name];\n }\n // Floats\n serializationObject.FloatArrays = {};\n for (name in this._floatsArrays) {\n serializationObject.FloatArrays[name] = this._floatsArrays[name];\n }\n // Color3\n serializationObject.colors3 = {};\n for (name in this._colors3) {\n serializationObject.colors3[name] = this._colors3[name].asArray();\n }\n // Color3 array\n serializationObject.colors3Arrays = {};\n for (name in this._colors3Arrays) {\n serializationObject.colors3Arrays[name] = this._colors3Arrays[name];\n }\n // Color4\n serializationObject.colors4 = {};\n for (name in this._colors4) {\n serializationObject.colors4[name] = this._colors4[name].asArray();\n }\n // Color4 array\n serializationObject.colors4Arrays = {};\n for (name in this._colors4Arrays) {\n serializationObject.colors4Arrays[name] = this._colors4Arrays[name];\n }\n // Vector2\n serializationObject.vectors2 = {};\n for (name in this._vectors2) {\n serializationObject.vectors2[name] = this._vectors2[name].asArray();\n }\n // Vector3\n serializationObject.vectors3 = {};\n for (name in this._vectors3) {\n serializationObject.vectors3[name] = this._vectors3[name].asArray();\n }\n // Vector4\n serializationObject.vectors4 = {};\n for (name in this._vectors4) {\n serializationObject.vectors4[name] = this._vectors4[name].asArray();\n }\n // Quaternion\n serializationObject.quaternions = {};\n for (name in this._quaternions) {\n serializationObject.quaternions[name] = this._quaternions[name].asArray();\n }\n // Matrix\n serializationObject.matrices = {};\n for (name in this._matrices) {\n serializationObject.matrices[name] = this._matrices[name].asArray();\n }\n // MatrixArray\n serializationObject.matrixArray = {};\n for (name in this._matrixArrays) {\n serializationObject.matrixArray[name] = this._matrixArrays[name];\n }\n // Matrix 3x3\n serializationObject.matrices3x3 = {};\n for (name in this._matrices3x3) {\n serializationObject.matrices3x3[name] = this._matrices3x3[name];\n }\n // Matrix 2x2\n serializationObject.matrices2x2 = {};\n for (name in this._matrices2x2) {\n serializationObject.matrices2x2[name] = this._matrices2x2[name];\n }\n // Vector2Array\n serializationObject.vectors2Arrays = {};\n for (name in this._vectors2Arrays) {\n serializationObject.vectors2Arrays[name] = this._vectors2Arrays[name];\n }\n // Vector3Array\n serializationObject.vectors3Arrays = {};\n for (name in this._vectors3Arrays) {\n serializationObject.vectors3Arrays[name] = this._vectors3Arrays[name];\n }\n // Vector4Array\n serializationObject.vectors4Arrays = {};\n for (name in this._vectors4Arrays) {\n serializationObject.vectors4Arrays[name] = this._vectors4Arrays[name];\n }\n // QuaternionArray\n serializationObject.quaternionsArrays = {};\n for (name in this._quaternionsArrays) {\n serializationObject.quaternionsArrays[name] = this._quaternionsArrays[name];\n }\n return serializationObject;\n }\n /**\n * Creates a shader material from parsed shader material data\n * @param source defines the JSON representation of the material\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a new material\n */\n static Parse(source, scene, rootUrl) {\n const material = SerializationHelper.Parse(() => new ShaderMaterial(source.name, scene, source.shaderPath, source.options, source.storeEffectOnSubMeshes), source, scene, rootUrl);\n let name;\n // Stencil\n if (source.stencil) {\n material.stencil.parse(source.stencil, scene, rootUrl);\n }\n // Texture\n for (name in source.textures) {\n material.setTexture(name, Texture.Parse(source.textures[name], scene, rootUrl));\n }\n // Texture arrays\n for (name in source.textureArrays) {\n const array = source.textureArrays[name];\n const textureArray = new Array();\n for (let index = 0; index < array.length; index++) {\n textureArray.push(Texture.Parse(array[index], scene, rootUrl));\n }\n material.setTextureArray(name, textureArray);\n }\n // Int\n for (name in source.ints) {\n material.setInt(name, source.ints[name]);\n }\n // UInt\n for (name in source.uints) {\n material.setUInt(name, source.uints[name]);\n }\n // Float\n for (name in source.floats) {\n material.setFloat(name, source.floats[name]);\n }\n // Floats\n for (name in source.floatsArrays) {\n material.setFloats(name, source.floatsArrays[name]);\n }\n // Color3\n for (name in source.colors3) {\n material.setColor3(name, Color3.FromArray(source.colors3[name]));\n }\n // Color3 arrays\n for (name in source.colors3Arrays) {\n const colors = source.colors3Arrays[name]\n .reduce((arr, num, i) => {\n if (i % 3 === 0) {\n arr.push([num]);\n }\n else {\n arr[arr.length - 1].push(num);\n }\n return arr;\n }, [])\n .map((color) => Color3.FromArray(color));\n material.setColor3Array(name, colors);\n }\n // Color4\n for (name in source.colors4) {\n material.setColor4(name, Color4.FromArray(source.colors4[name]));\n }\n // Color4 arrays\n for (name in source.colors4Arrays) {\n const colors = source.colors4Arrays[name]\n .reduce((arr, num, i) => {\n if (i % 4 === 0) {\n arr.push([num]);\n }\n else {\n arr[arr.length - 1].push(num);\n }\n return arr;\n }, [])\n .map((color) => Color4.FromArray(color));\n material.setColor4Array(name, colors);\n }\n // Vector2\n for (name in source.vectors2) {\n material.setVector2(name, Vector2.FromArray(source.vectors2[name]));\n }\n // Vector3\n for (name in source.vectors3) {\n material.setVector3(name, Vector3.FromArray(source.vectors3[name]));\n }\n // Vector4\n for (name in source.vectors4) {\n material.setVector4(name, Vector4.FromArray(source.vectors4[name]));\n }\n // Quaternion\n for (name in source.quaternions) {\n material.setQuaternion(name, Quaternion.FromArray(source.quaternions[name]));\n }\n // Matrix\n for (name in source.matrices) {\n material.setMatrix(name, Matrix.FromArray(source.matrices[name]));\n }\n // MatrixArray\n for (name in source.matrixArray) {\n material._matrixArrays[name] = new Float32Array(source.matrixArray[name]);\n }\n // Matrix 3x3\n for (name in source.matrices3x3) {\n material.setMatrix3x3(name, source.matrices3x3[name]);\n }\n // Matrix 2x2\n for (name in source.matrices2x2) {\n material.setMatrix2x2(name, source.matrices2x2[name]);\n }\n // Vector2Array\n for (name in source.vectors2Arrays) {\n material.setArray2(name, source.vectors2Arrays[name]);\n }\n // Vector3Array\n for (name in source.vectors3Arrays) {\n material.setArray3(name, source.vectors3Arrays[name]);\n }\n // Vector4Array\n for (name in source.vectors4Arrays) {\n material.setArray4(name, source.vectors4Arrays[name]);\n }\n // QuaternionArray\n for (name in source.quaternionsArrays) {\n material.setArray4(name, source.quaternionsArrays[name]);\n }\n return material;\n }\n /**\n * Creates a new ShaderMaterial from a snippet saved in a remote file\n * @param name defines the name of the ShaderMaterial to create (can be null or empty to use the one from the json data)\n * @param url defines the url to load from\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a promise that will resolve to the new ShaderMaterial\n */\n static ParseFromFileAsync(name, url, scene, rootUrl = \"\") {\n return new Promise((resolve, reject) => {\n const request = new WebRequest();\n request.addEventListener(\"readystatechange\", () => {\n if (request.readyState == 4) {\n if (request.status == 200) {\n const serializationObject = JSON.parse(request.responseText);\n const output = this.Parse(serializationObject, scene || EngineStore.LastCreatedScene, rootUrl);\n if (name) {\n output.name = name;\n }\n resolve(output);\n }\n else {\n reject(\"Unable to load the ShaderMaterial\");\n }\n }\n });\n request.open(\"GET\", url);\n request.send();\n });\n }\n /**\n * Creates a ShaderMaterial from a snippet saved by the Inspector\n * @param snippetId defines the snippet to load\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a promise that will resolve to the new ShaderMaterial\n */\n static ParseFromSnippetAsync(snippetId, scene, rootUrl = \"\") {\n return new Promise((resolve, reject) => {\n const request = new WebRequest();\n request.addEventListener(\"readystatechange\", () => {\n if (request.readyState == 4) {\n if (request.status == 200) {\n const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);\n const serializationObject = JSON.parse(snippet.shaderMaterial);\n const output = this.Parse(serializationObject, scene || EngineStore.LastCreatedScene, rootUrl);\n output.snippetId = snippetId;\n resolve(output);\n }\n else {\n reject(\"Unable to load the snippet \" + snippetId);\n }\n }\n });\n request.open(\"GET\", this.SnippetUrl + \"/\" + snippetId.replace(/#/g, \"/\"));\n request.send();\n });\n }\n }\n /** Define the Url to load snippets */\n ShaderMaterial.SnippetUrl = `https://snippet.babylonjs.com`;\n /**\n * Creates a ShaderMaterial from a snippet saved by the Inspector\n * @deprecated Please use ParseFromSnippetAsync instead\n * @param snippetId defines the snippet to load\n * @param scene defines the hosting scene\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\n * @returns a promise that will resolve to the new ShaderMaterial\n */\n ShaderMaterial.CreateFromSnippetAsync = ShaderMaterial.ParseFromSnippetAsync;\n RegisterClass(\"BABYLON.ShaderMaterial\", ShaderMaterial);\n\n // Do not edit.\n const name$1Y = \"colorPixelShader\";\n const shader$1Y = `#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\n#define VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1Y] = shader$1Y;\n\n // Do not edit.\n const name$1Z = \"colorVertexShader\";\n const shader$1Z = `attribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n#include\n#include\nuniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(position,1.0);\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1Z] = shader$1Z;\n\n Mesh._LinesMeshParser = (parsedMesh, scene) => {\n return LinesMesh.Parse(parsedMesh, scene);\n };\n /**\n * Line mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n */\n class LinesMesh extends Mesh {\n _isShaderMaterial(shader) {\n return shader.getClassName() === \"ShaderMaterial\";\n }\n /**\n * Creates a new LinesMesh\n * @param name defines the name\n * @param scene defines the hosting scene\n * @param parent defines the parent mesh if any\n * @param source defines the optional source LinesMesh used to clone data from\n * @param doNotCloneChildren When cloning, skip cloning child meshes of source, default False.\n * When false, achieved by calling a clone(), also passing False.\n * This will make creation of children, recursive.\n * @param useVertexColor defines if this LinesMesh supports vertex color\n * @param useVertexAlpha defines if this LinesMesh supports vertex alpha\n * @param material material to use to draw the line. If not provided, will create a new one\n */\n constructor(name, scene = null, parent = null, source = null, doNotCloneChildren, \n /**\n * If vertex color should be applied to the mesh\n */\n useVertexColor, \n /**\n * If vertex alpha should be applied to the mesh\n */\n useVertexAlpha, material) {\n super(name, scene, parent, source, doNotCloneChildren);\n this.useVertexColor = useVertexColor;\n this.useVertexAlpha = useVertexAlpha;\n /**\n * Color of the line (Default: White)\n */\n this.color = new Color3(1, 1, 1);\n /**\n * Alpha of the line (Default: 1)\n */\n this.alpha = 1;\n if (source) {\n this.color = source.color.clone();\n this.alpha = source.alpha;\n this.useVertexColor = source.useVertexColor;\n this.useVertexAlpha = source.useVertexAlpha;\n }\n this.intersectionThreshold = 0.1;\n const defines = [];\n const options = {\n attributes: [VertexBuffer.PositionKind],\n uniforms: [\"world\", \"viewProjection\"],\n needAlphaBlending: true,\n defines: defines,\n useClipPlane: null,\n };\n if (useVertexAlpha === false) {\n options.needAlphaBlending = false;\n }\n else {\n options.defines.push(\"#define VERTEXALPHA\");\n }\n if (!useVertexColor) {\n options.uniforms.push(\"color\");\n this._color4 = new Color4();\n }\n else {\n options.defines.push(\"#define VERTEXCOLOR\");\n options.attributes.push(VertexBuffer.ColorKind);\n }\n if (material) {\n this.material = material;\n }\n else {\n this.material = new ShaderMaterial(\"colorShader\", this.getScene(), \"color\", options, false);\n this.material.doNotSerialize = true;\n }\n }\n isReady() {\n if (!this._lineMaterial.isReady(this, !!this._userInstancedBuffersStorage)) {\n return false;\n }\n return super.isReady();\n }\n /**\n * Returns the string \"LineMesh\"\n */\n getClassName() {\n return \"LinesMesh\";\n }\n /**\n * @internal\n */\n get material() {\n return this._lineMaterial;\n }\n /**\n * @internal\n */\n set material(value) {\n this._lineMaterial = value;\n this._lineMaterial.fillMode = Material.LineListDrawMode;\n }\n /**\n * @internal\n */\n get checkCollisions() {\n return false;\n }\n set checkCollisions(value) {\n // Just ignore it\n }\n /**\n * @internal\n */\n _bind(_subMesh, colorEffect) {\n if (!this._geometry) {\n return this;\n }\n // VBOs\n const indexToBind = this.isUnIndexed ? null : this._geometry.getIndexBuffer();\n if (!this._userInstancedBuffersStorage) {\n this._geometry._bind(colorEffect, indexToBind);\n }\n else {\n this._geometry._bind(colorEffect, indexToBind, this._userInstancedBuffersStorage.vertexBuffers, this._userInstancedBuffersStorage.vertexArrayObjects);\n }\n // Color\n if (!this.useVertexColor && this._isShaderMaterial(this._lineMaterial)) {\n const { r, g, b } = this.color;\n this._color4.set(r, g, b, this.alpha);\n this._lineMaterial.setColor4(\"color\", this._color4);\n }\n return this;\n }\n /**\n * @internal\n */\n _draw(subMesh, fillMode, instancesCount) {\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\n return this;\n }\n const engine = this.getScene().getEngine();\n // Draw order\n if (this._unIndexed) {\n engine.drawArraysType(Material.LineListDrawMode, subMesh.verticesStart, subMesh.verticesCount, instancesCount);\n }\n else {\n engine.drawElementsType(Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount, instancesCount);\n }\n return this;\n }\n /**\n * Disposes of the line mesh\n * @param doNotRecurse If children should be disposed\n * @param disposeMaterialAndTextures This parameter is not used by the LineMesh class\n * @param doNotDisposeMaterial If the material should not be disposed (default: false, meaning the material is disposed)\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dispose(doNotRecurse, disposeMaterialAndTextures = false, doNotDisposeMaterial) {\n if (!doNotDisposeMaterial) {\n this._lineMaterial.dispose(false, false, true);\n }\n super.dispose(doNotRecurse);\n }\n /**\n * Returns a new LineMesh object cloned from the current one.\n * @param name\n * @param newParent\n * @param doNotCloneChildren\n */\n clone(name, newParent = null, doNotCloneChildren) {\n return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);\n }\n /**\n * Creates a new InstancedLinesMesh object from the mesh model.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\n * @param name defines the name of the new instance\n * @returns a new InstancedLinesMesh\n */\n createInstance(name) {\n const instance = new InstancedLinesMesh(name, this);\n if (this.instancedBuffers) {\n instance.instancedBuffers = {};\n for (const key in this.instancedBuffers) {\n instance.instancedBuffers[key] = this.instancedBuffers[key];\n }\n }\n return instance;\n }\n /**\n * Serializes this ground mesh\n * @param serializationObject object to write serialization to\n */\n serialize(serializationObject) {\n super.serialize(serializationObject);\n serializationObject.color = this.color.asArray();\n serializationObject.alpha = this.alpha;\n }\n /**\n * Parses a serialized ground mesh\n * @param parsedMesh the serialized mesh\n * @param scene the scene to create the ground mesh in\n * @returns the created ground mesh\n */\n static Parse(parsedMesh, scene) {\n const result = new LinesMesh(parsedMesh.name, scene);\n result.color = Color3.FromArray(parsedMesh.color);\n result.alpha = parsedMesh.alpha;\n return result;\n }\n }\n /**\n * Creates an instance based on a source LinesMesh\n */\n class InstancedLinesMesh extends InstancedMesh {\n constructor(name, source) {\n super(name, source);\n this.intersectionThreshold = source.intersectionThreshold;\n }\n /**\n * Returns the string \"InstancedLinesMesh\".\n */\n getClassName() {\n return \"InstancedLinesMesh\";\n }\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * Creates the VertexData of the LineSystem\n * @param options an object used to set the following optional parameters for the LineSystem, required but can be empty\n * - lines an array of lines, each line being an array of successive Vector3\n * - colors an array of line colors, each of the line colors being an array of successive Color4, one per line point\n * @param options.lines\n * @param options.colors\n * @returns the VertexData of the LineSystem\n */\n function CreateLineSystemVertexData(options) {\n const indices = [];\n const positions = [];\n const lines = options.lines;\n const colors = options.colors;\n const vertexColors = [];\n let idx = 0;\n for (let l = 0; l < lines.length; l++) {\n const points = lines[l];\n for (let index = 0; index < points.length; index++) {\n positions.push(points[index].x, points[index].y, points[index].z);\n if (colors) {\n const color = colors[l];\n vertexColors.push(color[index].r, color[index].g, color[index].b, color[index].a);\n }\n if (index > 0) {\n indices.push(idx - 1);\n indices.push(idx);\n }\n idx++;\n }\n }\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n if (colors) {\n vertexData.colors = vertexColors;\n }\n return vertexData;\n }\n /**\n * Create the VertexData for a DashedLines\n * @param options an object used to set the following optional parameters for the DashedLines, required but can be empty\n * - points an array successive Vector3\n * - dashSize the size of the dashes relative to the dash number, optional, default 3\n * - gapSize the size of the gap between two successive dashes relative to the dash number, optional, default 1\n * - dashNb the intended total number of dashes, optional, default 200\n * @param options.points\n * @param options.dashSize\n * @param options.gapSize\n * @param options.dashNb\n * @returns the VertexData for the DashedLines\n */\n function CreateDashedLinesVertexData(options) {\n const dashSize = options.dashSize || 3;\n const gapSize = options.gapSize || 1;\n const dashNb = options.dashNb || 200;\n const points = options.points;\n const positions = new Array();\n const indices = new Array();\n const curvect = Vector3.Zero();\n let lg = 0;\n let nb = 0;\n let shft = 0;\n let dashshft = 0;\n let curshft = 0;\n let idx = 0;\n let i = 0;\n for (i = 0; i < points.length - 1; i++) {\n points[i + 1].subtractToRef(points[i], curvect);\n lg += curvect.length();\n }\n shft = lg / dashNb;\n dashshft = (dashSize * shft) / (dashSize + gapSize);\n for (i = 0; i < points.length - 1; i++) {\n points[i + 1].subtractToRef(points[i], curvect);\n nb = Math.floor(curvect.length() / shft);\n curvect.normalize();\n for (let j = 0; j < nb; j++) {\n curshft = shft * j;\n positions.push(points[i].x + curshft * curvect.x, points[i].y + curshft * curvect.y, points[i].z + curshft * curvect.z);\n positions.push(points[i].x + (curshft + dashshft) * curvect.x, points[i].y + (curshft + dashshft) * curvect.y, points[i].z + (curshft + dashshft) * curvect.z);\n indices.push(idx, idx + 1);\n idx += 2;\n }\n }\n // Result\n const vertexData = new VertexData();\n vertexData.positions = positions;\n vertexData.indices = indices;\n return vertexData;\n }\n /**\n * Creates a line system mesh. A line system is a pool of many lines gathered in a single mesh\n * * A line system mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of lines as an input parameter\n * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineSystem to this static function\n * * The parameter `lines` is an array of lines, each line being an array of successive Vector3\n * * The optional parameter `instance` is an instance of an existing LineSystem object to be updated with the passed `lines` parameter\n * * The optional parameter `colors` is an array of line colors, each line colors being an array of successive Color4, one per line point\n * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need the alpha blending (faster)\n * * The optional parameter `material` is the material to use to draw the lines if provided. If not, a default material will be created\n * * Updating a simple Line mesh, you just need to update every line in the `lines` array : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#lines-and-dashedlines\n * * When updating an instance, remember that only line point positions can change, not the number of points, neither the number of lines\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#line-system\n * @param name defines the name of the new line system\n * @param options defines the options used to create the line system\n * @param options.lines\n * @param options.updatable\n * @param options.instance\n * @param options.colors\n * @param options.useVertexAlpha\n * @param options.material\n * @param scene defines the hosting scene\n * @returns a new line system mesh\n */\n function CreateLineSystem(name, options, scene = null) {\n const instance = options.instance;\n const lines = options.lines;\n const colors = options.colors;\n if (instance) {\n // lines update\n const positions = instance.getVerticesData(VertexBuffer.PositionKind);\n let vertexColor;\n let lineColors;\n if (colors) {\n vertexColor = instance.getVerticesData(VertexBuffer.ColorKind);\n }\n let i = 0;\n let c = 0;\n for (let l = 0; l < lines.length; l++) {\n const points = lines[l];\n for (let p = 0; p < points.length; p++) {\n positions[i] = points[p].x;\n positions[i + 1] = points[p].y;\n positions[i + 2] = points[p].z;\n if (colors && vertexColor) {\n lineColors = colors[l];\n vertexColor[c] = lineColors[p].r;\n vertexColor[c + 1] = lineColors[p].g;\n vertexColor[c + 2] = lineColors[p].b;\n vertexColor[c + 3] = lineColors[p].a;\n c += 4;\n }\n i += 3;\n }\n }\n instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\n if (colors && vertexColor) {\n instance.updateVerticesData(VertexBuffer.ColorKind, vertexColor, false, false);\n }\n return instance;\n }\n // line system creation\n const useVertexColor = colors ? true : false;\n const lineSystem = new LinesMesh(name, scene, null, undefined, undefined, useVertexColor, options.useVertexAlpha, options.material);\n const vertexData = CreateLineSystemVertexData(options);\n vertexData.applyToMesh(lineSystem, options.updatable);\n return lineSystem;\n }\n /**\n * Creates a line mesh\n * A line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter\n * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function\n * * The parameter `points` is an array successive Vector3\n * * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#lines-and-dashedlines\n * * The optional parameter `colors` is an array of successive Color4, one per line point\n * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need alpha blending (faster)\n * * The optional parameter `material` is the material to use to draw the lines if provided. If not, a default material will be created\n * * When updating an instance, remember that only point positions can change, not the number of points\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#lines\n * @param name defines the name of the new line system\n * @param options defines the options used to create the line system\n * @param options.points\n * @param options.updatable\n * @param options.instance\n * @param options.colors\n * @param options.useVertexAlpha\n * @param options.material\n * @param scene defines the hosting scene\n * @returns a new line mesh\n */\n function CreateLines(name, options, scene = null) {\n const colors = options.colors ? [options.colors] : null;\n const lines = CreateLineSystem(name, { lines: [options.points], updatable: options.updatable, instance: options.instance, colors: colors, useVertexAlpha: options.useVertexAlpha, material: options.material }, scene);\n return lines;\n }\n /**\n * Creates a dashed line mesh\n * * A dashed line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter\n * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function\n * * The parameter `points` is an array successive Vector3\n * * The parameter `dashNb` is the intended total number of dashes (positive integer, default 200)\n * * The parameter `dashSize` is the size of the dashes relatively the dash number (positive float, default 3)\n * * The parameter `gapSize` is the size of the gap between two successive dashes relatively the dash number (positive float, default 1)\n * * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#lines-and-dashedlines\n * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need the alpha blending (faster)\n * * The optional parameter `material` is the material to use to draw the lines if provided. If not, a default material will be created\n * * When updating an instance, remember that only point positions can change, not the number of points\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.points\n * @param options.dashSize\n * @param options.gapSize\n * @param options.dashNb\n * @param options.updatable\n * @param options.instance\n * @param options.useVertexAlpha\n * @param options.material\n * @param scene defines the hosting scene\n * @returns the dashed line mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#dashed-lines\n */\n function CreateDashedLines(name, options, scene = null) {\n const points = options.points;\n const instance = options.instance;\n const gapSize = options.gapSize || 1;\n const dashSize = options.dashSize || 3;\n if (instance) {\n // dashed lines update\n const positionFunction = (positions) => {\n const curvect = Vector3.Zero();\n const nbSeg = positions.length / 6;\n let lg = 0;\n let nb = 0;\n let shft = 0;\n let dashshft = 0;\n let curshft = 0;\n let p = 0;\n let i = 0;\n let j = 0;\n for (i = 0; i < points.length - 1; i++) {\n points[i + 1].subtractToRef(points[i], curvect);\n lg += curvect.length();\n }\n shft = lg / nbSeg;\n const dashSize = instance._creationDataStorage.dashSize;\n const gapSize = instance._creationDataStorage.gapSize;\n dashshft = (dashSize * shft) / (dashSize + gapSize);\n for (i = 0; i < points.length - 1; i++) {\n points[i + 1].subtractToRef(points[i], curvect);\n nb = Math.floor(curvect.length() / shft);\n curvect.normalize();\n j = 0;\n while (j < nb && p < positions.length) {\n curshft = shft * j;\n positions[p] = points[i].x + curshft * curvect.x;\n positions[p + 1] = points[i].y + curshft * curvect.y;\n positions[p + 2] = points[i].z + curshft * curvect.z;\n positions[p + 3] = points[i].x + (curshft + dashshft) * curvect.x;\n positions[p + 4] = points[i].y + (curshft + dashshft) * curvect.y;\n positions[p + 5] = points[i].z + (curshft + dashshft) * curvect.z;\n p += 6;\n j++;\n }\n }\n while (p < positions.length) {\n positions[p] = points[i].x;\n positions[p + 1] = points[i].y;\n positions[p + 2] = points[i].z;\n p += 3;\n }\n };\n if (options.dashNb || options.dashSize || options.gapSize || options.useVertexAlpha || options.material) {\n Logger.Warn(\"You have used an option other than points with the instance option. Please be aware that these other options will be ignored.\");\n }\n instance.updateMeshPositions(positionFunction, false);\n return instance;\n }\n // dashed lines creation\n const dashedLines = new LinesMesh(name, scene, null, undefined, undefined, undefined, options.useVertexAlpha, options.material);\n const vertexData = CreateDashedLinesVertexData(options);\n vertexData.applyToMesh(dashedLines, options.updatable);\n dashedLines._creationDataStorage = new _CreationDataStorage();\n dashedLines._creationDataStorage.dashSize = dashSize;\n dashedLines._creationDataStorage.gapSize = gapSize;\n return dashedLines;\n }\n VertexData.CreateLineSystem = CreateLineSystemVertexData;\n VertexData.CreateDashedLines = CreateDashedLinesVertexData;\n Mesh.CreateLines = (name, points, scene = null, updatable = false, instance = null) => {\n const options = {\n points,\n updatable,\n instance,\n };\n return CreateLines(name, options, scene);\n };\n Mesh.CreateDashedLines = (name, points, dashSize, gapSize, dashNb, scene = null, updatable, instance) => {\n const options = {\n points,\n dashSize,\n gapSize,\n dashNb,\n updatable,\n instance,\n };\n return CreateDashedLines(name, options, scene);\n };\n\n /**\n * The current state of the timer\n */\n var TimerState;\n (function (TimerState) {\n /**\n * Timer initialized, not yet started\n */\n TimerState[TimerState[\"INIT\"] = 0] = \"INIT\";\n /**\n * Timer started and counting\n */\n TimerState[TimerState[\"STARTED\"] = 1] = \"STARTED\";\n /**\n * Timer ended (whether aborted or time reached)\n */\n TimerState[TimerState[\"ENDED\"] = 2] = \"ENDED\";\n })(TimerState || (TimerState = {}));\n /**\n * A simple version of the timer. Will take options and start the timer immediately after calling it\n *\n * @param options options with which to initialize this timer\n */\n function setAndStartTimer(options) {\n var _a;\n let timer = 0;\n const startTime = Date.now();\n options.observableParameters = (_a = options.observableParameters) !== null && _a !== void 0 ? _a : {};\n const observer = options.contextObservable.add((payload) => {\n const now = Date.now();\n timer = now - startTime;\n const data = {\n startTime,\n currentTime: now,\n deltaTime: timer,\n completeRate: timer / options.timeout,\n payload,\n };\n options.onTick && options.onTick(data);\n if (options.breakCondition && options.breakCondition()) {\n options.contextObservable.remove(observer);\n options.onAborted && options.onAborted(data);\n }\n if (timer >= options.timeout) {\n options.contextObservable.remove(observer);\n options.onEnded && options.onEnded(data);\n }\n }, options.observableParameters.mask, options.observableParameters.insertFirst, options.observableParameters.scope);\n return observer;\n }\n\n /**\n * This is a teleportation feature to be used with WebXR-enabled motion controllers.\n * When enabled and attached, the feature will allow a user to move around and rotate in the scene using\n * the input of the attached controllers.\n */\n class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {\n /**\n * Is rotation enabled when moving forward?\n * Disabling this feature will prevent the user from deciding the direction when teleporting\n */\n get rotationEnabled() {\n return this._rotationEnabled;\n }\n /**\n * Sets whether rotation is enabled or not\n * @param enabled is rotation enabled when teleportation is shown\n */\n set rotationEnabled(enabled) {\n this._rotationEnabled = enabled;\n if (this._options.teleportationTargetMesh) {\n const children = this._options.teleportationTargetMesh.getChildMeshes(false, (node) => node.name === \"rotationCone\");\n if (children[0]) {\n children[0].setEnabled(enabled);\n }\n }\n }\n /**\n * Exposes the currently set teleportation target mesh.\n */\n get teleportationTargetMesh() {\n return this._options.teleportationTargetMesh || null;\n }\n /**\n * constructs a new teleportation system\n * @param _xrSessionManager an instance of WebXRSessionManager\n * @param _options configuration object for this feature\n */\n constructor(_xrSessionManager, _options) {\n super(_xrSessionManager);\n this._options = _options;\n this._controllers = {};\n this._snappedToPoint = false;\n this._cachedColor4White = new Color4(1, 1, 1, 1);\n this._tmpRay = new Ray(new Vector3(), new Vector3());\n this._tmpVector = new Vector3();\n this._tmpQuaternion = new Quaternion();\n /**\n * Skip the next teleportation. This can be controlled by the user to prevent the user from teleportation\n * to sections that are not yet \"unlocked\", but should still show the teleportation mesh.\n */\n this.skipNextTeleportation = false;\n /**\n * Is movement backwards enabled\n */\n this.backwardsMovementEnabled = true;\n /**\n * Distance to travel when moving backwards\n */\n this.backwardsTeleportationDistance = 0.7;\n /**\n * The distance from the user to the inspection point in the direction of the controller\n * A higher number will allow the user to move further\n * defaults to 5 (meters, in xr units)\n */\n this.parabolicCheckRadius = 5;\n /**\n * Should the module support parabolic ray on top of direct ray\n * If enabled, the user will be able to point \"at the sky\" and move according to predefined radius distance\n * Very helpful when moving between floors / different heights\n */\n this.parabolicRayEnabled = true;\n /**\n * The second type of ray - straight line.\n * Should it be enabled or should the parabolic line be the only one.\n */\n this.straightRayEnabled = true;\n /**\n * How much rotation should be applied when rotating right and left\n */\n this.rotationAngle = Math.PI / 8;\n /**\n * This observable will notify when the target mesh position was updated.\n * The picking info it provides contains the point to which the target mesh will move ()\n */\n this.onTargetMeshPositionUpdatedObservable = new Observable$1();\n /**\n * Is teleportation enabled. Can be used to allow rotation only.\n */\n this.teleportationEnabled = true;\n this._rotationEnabled = true;\n this._attachController = (xrController) => {\n if (this._controllers[xrController.uniqueId] || (this._options.forceHandedness && xrController.inputSource.handedness !== this._options.forceHandedness)) {\n // already attached\n return;\n }\n this._controllers[xrController.uniqueId] = {\n xrController,\n teleportationState: {\n forward: false,\n backwards: false,\n rotating: false,\n currentRotation: 0,\n baseRotation: 0,\n blocked: false,\n },\n };\n const controllerData = this._controllers[xrController.uniqueId];\n // motion controller only available to gamepad-enabled input sources.\n if (controllerData.xrController.inputSource.targetRayMode === \"tracked-pointer\" && controllerData.xrController.inputSource.gamepad) {\n // motion controller support\n const initMotionController = () => {\n if (xrController.motionController) {\n const movementController = xrController.motionController.getComponentOfType(WebXRControllerComponent.THUMBSTICK_TYPE) ||\n xrController.motionController.getComponentOfType(WebXRControllerComponent.TOUCHPAD_TYPE);\n if (!movementController || this._options.useMainComponentOnly) {\n // use trigger to move on long press\n const mainComponent = xrController.motionController.getMainComponent();\n if (!mainComponent) {\n return;\n }\n controllerData.teleportationComponent = mainComponent;\n controllerData.onButtonChangedObserver = mainComponent.onButtonStateChangedObservable.add(() => {\n if (!this.teleportationEnabled) {\n return;\n }\n // did \"pressed\" changed?\n if (mainComponent.changes.pressed) {\n if (mainComponent.changes.pressed.current) {\n // simulate \"forward\" thumbstick push\n controllerData.teleportationState.forward = true;\n this._currentTeleportationControllerId = controllerData.xrController.uniqueId;\n controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;\n controllerData.teleportationState.currentRotation = 0;\n const timeToSelect = this._options.timeToTeleport || 3000;\n setAndStartTimer({\n timeout: timeToSelect,\n contextObservable: this._xrSessionManager.onXRFrameObservable,\n breakCondition: () => !mainComponent.pressed,\n onEnded: () => {\n if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {\n this._teleportForward(xrController.uniqueId);\n }\n },\n });\n }\n else {\n controllerData.teleportationState.forward = false;\n this._currentTeleportationControllerId = \"\";\n }\n }\n });\n }\n else {\n controllerData.teleportationComponent = movementController;\n // use thumbstick (or touchpad if thumbstick not available)\n controllerData.onAxisChangedObserver = movementController.onAxisValueChangedObservable.add((axesData) => {\n if (axesData.y <= 0.7 && controllerData.teleportationState.backwards) {\n controllerData.teleportationState.backwards = false;\n }\n if (axesData.y > 0.7 && !controllerData.teleportationState.forward && this.backwardsMovementEnabled && !this.snapPointsOnly) {\n // teleport backwards\n // General gist: Go Back N units, cast a ray towards the floor. If collided, move.\n if (!controllerData.teleportationState.backwards) {\n controllerData.teleportationState.backwards = true;\n // teleport backwards ONCE\n this._tmpQuaternion.copyFrom(this._options.xrInput.xrCamera.rotationQuaternion);\n this._tmpQuaternion.toEulerAnglesToRef(this._tmpVector);\n // get only the y rotation\n this._tmpVector.x = 0;\n this._tmpVector.z = 0;\n // get the quaternion\n Quaternion.FromEulerVectorToRef(this._tmpVector, this._tmpQuaternion);\n this._tmpVector.set(0, 0, this.backwardsTeleportationDistance * (this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0));\n this._tmpVector.rotateByQuaternionToRef(this._tmpQuaternion, this._tmpVector);\n this._tmpVector.addInPlace(this._options.xrInput.xrCamera.position);\n this._tmpRay.origin.copyFrom(this._tmpVector);\n // This will prevent the user from \"falling\" to a lower platform!\n // TODO - should this be a flag? 'allow falling to lower platforms'?\n this._tmpRay.length = this._options.xrInput.xrCamera.realWorldHeight + 0.1;\n // Right handed system had here \"1\" instead of -1. This is unneeded.\n this._tmpRay.direction.set(0, -1, 0);\n const pick = this._xrSessionManager.scene.pickWithRay(this._tmpRay, (o) => {\n return this._floorMeshes.indexOf(o) !== -1;\n });\n // pick must exist, but stay safe\n if (pick && pick.pickedPoint) {\n // Teleport the users feet to where they targeted. Ignore the Y axis.\n // If the \"falling to lower platforms\" feature is implemented the Y axis should be set here as well\n this._options.xrInput.xrCamera.position.x = pick.pickedPoint.x;\n this._options.xrInput.xrCamera.position.z = pick.pickedPoint.z;\n }\n }\n }\n if (axesData.y < -0.7 && !this._currentTeleportationControllerId && !controllerData.teleportationState.rotating && this.teleportationEnabled) {\n controllerData.teleportationState.forward = true;\n this._currentTeleportationControllerId = controllerData.xrController.uniqueId;\n controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;\n }\n if (axesData.x) {\n if (!controllerData.teleportationState.forward) {\n if (!controllerData.teleportationState.rotating && Math.abs(axesData.x) > 0.7) {\n // rotate in the right direction positive is right\n controllerData.teleportationState.rotating = true;\n const rotation = this.rotationAngle * (axesData.x > 0 ? 1 : -1) * (this._xrSessionManager.scene.useRightHandedSystem ? -1 : 1);\n Quaternion.FromEulerAngles(0, rotation, 0).multiplyToRef(this._options.xrInput.xrCamera.rotationQuaternion, this._options.xrInput.xrCamera.rotationQuaternion);\n }\n }\n else {\n if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId) {\n // set the rotation of the forward movement\n if (this.rotationEnabled) {\n setTimeout(() => {\n controllerData.teleportationState.currentRotation = Math.atan2(axesData.x, axesData.y * (this._xrSessionManager.scene.useRightHandedSystem ? 1 : -1));\n });\n }\n else {\n controllerData.teleportationState.currentRotation = 0;\n }\n }\n }\n }\n else {\n controllerData.teleportationState.rotating = false;\n }\n if (axesData.x === 0 && axesData.y === 0) {\n if (controllerData.teleportationState.blocked) {\n controllerData.teleportationState.blocked = false;\n this._setTargetMeshVisibility(false);\n }\n if (controllerData.teleportationState.forward) {\n this._teleportForward(xrController.uniqueId);\n }\n }\n });\n }\n }\n };\n if (xrController.motionController) {\n initMotionController();\n }\n else {\n xrController.onMotionControllerInitObservable.addOnce(() => {\n initMotionController();\n });\n }\n }\n else {\n this._xrSessionManager.scene.onPointerObservable.add((pointerInfo) => {\n if (pointerInfo.type === PointerEventTypes.POINTERDOWN) {\n controllerData.teleportationState.forward = true;\n this._currentTeleportationControllerId = controllerData.xrController.uniqueId;\n controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;\n controllerData.teleportationState.currentRotation = 0;\n const timeToSelect = this._options.timeToTeleport || 3000;\n setAndStartTimer({\n timeout: timeToSelect,\n contextObservable: this._xrSessionManager.onXRFrameObservable,\n onEnded: () => {\n if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {\n this._teleportForward(xrController.uniqueId);\n }\n },\n });\n }\n else if (pointerInfo.type === PointerEventTypes.POINTERUP) {\n controllerData.teleportationState.forward = false;\n this._currentTeleportationControllerId = \"\";\n }\n });\n }\n };\n // create default mesh if not provided\n if (!this._options.teleportationTargetMesh) {\n this._createDefaultTargetMesh();\n }\n this._floorMeshes = this._options.floorMeshes || [];\n this._snapToPositions = this._options.snapPositions || [];\n this._blockedRayColor = this._options.blockedRayColor || new Color4(1, 0, 0, 0.75);\n this._setTargetMeshVisibility(false);\n }\n /**\n * Get the snapPointsOnly flag\n */\n get snapPointsOnly() {\n return !!this._options.snapPointsOnly;\n }\n /**\n * Sets the snapPointsOnly flag\n * @param snapToPoints should teleportation be exclusively to snap points\n */\n set snapPointsOnly(snapToPoints) {\n this._options.snapPointsOnly = snapToPoints;\n }\n /**\n * Add a new mesh to the floor meshes array\n * @param mesh the mesh to use as floor mesh\n */\n addFloorMesh(mesh) {\n this._floorMeshes.push(mesh);\n }\n /**\n * Add a mesh to the list of meshes blocking the teleportation ray\n * @param mesh The mesh to add to the teleportation-blocking meshes\n */\n addBlockerMesh(mesh) {\n this._options.pickBlockerMeshes = this._options.pickBlockerMeshes || [];\n this._options.pickBlockerMeshes.push(mesh);\n }\n /**\n * Add a new snap-to point to fix teleportation to this position\n * @param newSnapPoint The new Snap-To point\n */\n addSnapPoint(newSnapPoint) {\n this._snapToPositions.push(newSnapPoint);\n }\n attach() {\n if (!super.attach()) {\n return false;\n }\n // Safety reset\n this._currentTeleportationControllerId = \"\";\n this._options.xrInput.controllers.forEach(this._attachController);\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\n // REMOVE the controller\n this._detachController(controller.uniqueId);\n });\n return true;\n }\n detach() {\n if (!super.detach()) {\n return false;\n }\n Object.keys(this._controllers).forEach((controllerId) => {\n this._detachController(controllerId);\n });\n this._setTargetMeshVisibility(false);\n this._currentTeleportationControllerId = \"\";\n this._controllers = {};\n return true;\n }\n dispose() {\n super.dispose();\n this._options.teleportationTargetMesh && this._options.teleportationTargetMesh.dispose(false, true);\n }\n /**\n * Remove a mesh from the floor meshes array\n * @param mesh the mesh to remove\n */\n removeFloorMesh(mesh) {\n const index = this._floorMeshes.indexOf(mesh);\n if (index !== -1) {\n this._floorMeshes.splice(index, 1);\n }\n }\n /**\n * Remove a mesh from the blocker meshes array\n * @param mesh the mesh to remove\n */\n removeBlockerMesh(mesh) {\n this._options.pickBlockerMeshes = this._options.pickBlockerMeshes || [];\n const index = this._options.pickBlockerMeshes.indexOf(mesh);\n if (index !== -1) {\n this._options.pickBlockerMeshes.splice(index, 1);\n }\n }\n /**\n * Remove a mesh from the floor meshes array using its name\n * @param name the mesh name to remove\n */\n removeFloorMeshByName(name) {\n const mesh = this._xrSessionManager.scene.getMeshByName(name);\n if (mesh) {\n this.removeFloorMesh(mesh);\n }\n }\n /**\n * This function will iterate through the array, searching for this point or equal to it. It will then remove it from the snap-to array\n * @param snapPointToRemove the point (or a clone of it) to be removed from the array\n * @returns was the point found and removed or not\n */\n removeSnapPoint(snapPointToRemove) {\n // check if the object is in the array\n let index = this._snapToPositions.indexOf(snapPointToRemove);\n // if not found as an object, compare to the points\n if (index === -1) {\n for (let i = 0; i < this._snapToPositions.length; ++i) {\n // equals? index is i, break the loop\n if (this._snapToPositions[i].equals(snapPointToRemove)) {\n index = i;\n break;\n }\n }\n }\n // index is not -1? remove the object\n if (index !== -1) {\n this._snapToPositions.splice(index, 1);\n return true;\n }\n return false;\n }\n /**\n * This function sets a selection feature that will be disabled when\n * the forward ray is shown and will be reattached when hidden.\n * This is used to remove the selection rays when moving.\n * @param selectionFeature the feature to disable when forward movement is enabled\n */\n setSelectionFeature(selectionFeature) {\n this._selectionFeature = selectionFeature;\n }\n _onXRFrame(_xrFrame) {\n const frame = this._xrSessionManager.currentFrame;\n const scene = this._xrSessionManager.scene;\n if (!this.attach || !frame) {\n return;\n }\n // render target if needed\n const targetMesh = this._options.teleportationTargetMesh;\n if (this._currentTeleportationControllerId) {\n if (!targetMesh) {\n return;\n }\n targetMesh.rotationQuaternion = targetMesh.rotationQuaternion || new Quaternion();\n const controllerData = this._controllers[this._currentTeleportationControllerId];\n if (controllerData && controllerData.teleportationState.forward) {\n // set the rotation\n Quaternion.RotationYawPitchRollToRef(controllerData.teleportationState.currentRotation + controllerData.teleportationState.baseRotation, 0, 0, targetMesh.rotationQuaternion);\n // set the ray and position\n let hitPossible = false;\n controllerData.xrController.getWorldPointerRayToRef(this._tmpRay);\n if (this.straightRayEnabled) {\n // first check if direct ray possible\n // pick grounds that are LOWER only. upper will use parabolic path\n const pick = scene.pickWithRay(this._tmpRay, (o) => {\n // check for mesh-blockers\n if (this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(o) !== -1) {\n return true;\n }\n const index = this._floorMeshes.indexOf(o);\n if (index === -1) {\n return false;\n }\n return this._floorMeshes[index].absolutePosition.y < this._options.xrInput.xrCamera.globalPosition.y;\n });\n if (pick && pick.pickedMesh && this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(pick.pickedMesh) !== -1) {\n controllerData.teleportationState.blocked = true;\n this._setTargetMeshVisibility(false);\n this._showParabolicPath(pick);\n return;\n }\n else if (pick && pick.pickedPoint) {\n controllerData.teleportationState.blocked = false;\n hitPossible = true;\n this._setTargetMeshPosition(pick);\n this._setTargetMeshVisibility(true);\n this._showParabolicPath(pick);\n }\n }\n // straight ray is still the main ray, but disabling the straight line will force parabolic line.\n if (this.parabolicRayEnabled && !hitPossible) {\n // radius compensation according to pointer rotation around X\n const xRotation = controllerData.xrController.pointer.rotationQuaternion.toEulerAngles().x;\n const compensation = 1 + (Math.PI / 2 - Math.abs(xRotation));\n // check parabolic ray\n const radius = this.parabolicCheckRadius * compensation;\n this._tmpRay.origin.addToRef(this._tmpRay.direction.scale(radius * 2), this._tmpVector);\n this._tmpVector.y = this._tmpRay.origin.y;\n this._tmpRay.origin.addInPlace(this._tmpRay.direction.scale(radius));\n this._tmpVector.subtractToRef(this._tmpRay.origin, this._tmpRay.direction);\n this._tmpRay.direction.normalize();\n const pick = scene.pickWithRay(this._tmpRay, (o) => {\n // check for mesh-blockers\n if (this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(o) !== -1) {\n return true;\n }\n return this._floorMeshes.indexOf(o) !== -1;\n });\n if (pick && pick.pickedMesh && this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(pick.pickedMesh) !== -1) {\n controllerData.teleportationState.blocked = true;\n this._setTargetMeshVisibility(false);\n this._showParabolicPath(pick);\n return;\n }\n else if (pick && pick.pickedPoint) {\n controllerData.teleportationState.blocked = false;\n hitPossible = true;\n this._setTargetMeshPosition(pick);\n this._setTargetMeshVisibility(true);\n this._showParabolicPath(pick);\n }\n }\n // if needed, set visible:\n this._setTargetMeshVisibility(hitPossible);\n }\n else {\n this._setTargetMeshVisibility(false);\n }\n }\n else {\n this._disposeBezierCurve();\n this._setTargetMeshVisibility(false);\n }\n }\n _createDefaultTargetMesh() {\n // set defaults\n this._options.defaultTargetMeshOptions = this._options.defaultTargetMeshOptions || {};\n const sceneToRenderTo = this._options.useUtilityLayer\n ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene\n : this._xrSessionManager.scene;\n const teleportationTarget = CreateGround(\"teleportationTarget\", { width: 2, height: 2, subdivisions: 2 }, sceneToRenderTo);\n teleportationTarget.isPickable = false;\n if (this._options.defaultTargetMeshOptions.teleportationCircleMaterial) {\n teleportationTarget.material = this._options.defaultTargetMeshOptions.teleportationCircleMaterial;\n }\n else {\n const length = 512;\n const dynamicTexture = new DynamicTexture(\"teleportationPlaneDynamicTexture\", length, sceneToRenderTo, true);\n dynamicTexture.hasAlpha = true;\n const context = dynamicTexture.getContext();\n const centerX = length / 2;\n const centerY = length / 2;\n const radius = 200;\n context.beginPath();\n context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);\n context.fillStyle = this._options.defaultTargetMeshOptions.teleportationFillColor || \"#444444\";\n context.fill();\n context.lineWidth = 10;\n context.strokeStyle = this._options.defaultTargetMeshOptions.teleportationBorderColor || \"#FFFFFF\";\n context.stroke();\n context.closePath();\n dynamicTexture.update();\n const teleportationCircleMaterial = new StandardMaterial(\"teleportationPlaneMaterial\", sceneToRenderTo);\n teleportationCircleMaterial.diffuseTexture = dynamicTexture;\n teleportationTarget.material = teleportationCircleMaterial;\n }\n const torus = CreateTorus(\"torusTeleportation\", {\n diameter: 0.75,\n thickness: 0.1,\n tessellation: 20,\n }, sceneToRenderTo);\n torus.isPickable = false;\n torus.parent = teleportationTarget;\n if (!this._options.defaultTargetMeshOptions.disableAnimation) {\n const animationInnerCircle = new Animation(\"animationInnerCircle\", \"position.y\", 30, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);\n const keys = [];\n keys.push({\n frame: 0,\n value: 0,\n });\n keys.push({\n frame: 30,\n value: 0.4,\n });\n keys.push({\n frame: 60,\n value: 0,\n });\n animationInnerCircle.setKeys(keys);\n const easingFunction = new SineEase();\n easingFunction.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\n animationInnerCircle.setEasingFunction(easingFunction);\n torus.animations = [];\n torus.animations.push(animationInnerCircle);\n sceneToRenderTo.beginAnimation(torus, 0, 60, true);\n }\n const cone = CreateCylinder(\"rotationCone\", { diameterTop: 0, tessellation: 4 }, sceneToRenderTo);\n cone.isPickable = false;\n cone.scaling.set(0.5, 0.12, 0.2);\n cone.rotate(Axis.X, Math.PI / 2);\n cone.position.z = 0.6;\n cone.parent = torus;\n if (this._options.defaultTargetMeshOptions.torusArrowMaterial) {\n torus.material = this._options.defaultTargetMeshOptions.torusArrowMaterial;\n cone.material = this._options.defaultTargetMeshOptions.torusArrowMaterial;\n }\n else {\n const torusConeMaterial = new StandardMaterial(\"torusConsMat\", sceneToRenderTo);\n torusConeMaterial.disableLighting = !!this._options.defaultTargetMeshOptions.disableLighting;\n if (torusConeMaterial.disableLighting) {\n torusConeMaterial.emissiveColor = new Color3(0.3, 0.3, 1.0);\n }\n else {\n torusConeMaterial.diffuseColor = new Color3(0.3, 0.3, 1.0);\n }\n torusConeMaterial.alpha = 0.9;\n torus.material = torusConeMaterial;\n cone.material = torusConeMaterial;\n this._teleportationRingMaterial = torusConeMaterial;\n }\n if (this._options.renderingGroupId !== undefined) {\n teleportationTarget.renderingGroupId = this._options.renderingGroupId;\n torus.renderingGroupId = this._options.renderingGroupId;\n cone.renderingGroupId = this._options.renderingGroupId;\n }\n this._options.teleportationTargetMesh = teleportationTarget;\n // hide the teleportation target mesh right after creating it.\n this._setTargetMeshVisibility(false);\n }\n _detachController(xrControllerUniqueId) {\n const controllerData = this._controllers[xrControllerUniqueId];\n if (!controllerData) {\n return;\n }\n if (controllerData.teleportationComponent) {\n if (controllerData.onAxisChangedObserver) {\n controllerData.teleportationComponent.onAxisValueChangedObservable.remove(controllerData.onAxisChangedObserver);\n }\n if (controllerData.onButtonChangedObserver) {\n controllerData.teleportationComponent.onButtonStateChangedObservable.remove(controllerData.onButtonChangedObserver);\n }\n }\n // remove from the map\n delete this._controllers[xrControllerUniqueId];\n }\n _findClosestSnapPointWithRadius(realPosition, radius = this._options.snapToPositionRadius || 0.8) {\n let closestPoint = null;\n let closestDistance = Number.MAX_VALUE;\n if (this._snapToPositions.length) {\n const radiusSquared = radius * radius;\n this._snapToPositions.forEach((position) => {\n const dist = Vector3.DistanceSquared(position, realPosition);\n if (dist <= radiusSquared && dist < closestDistance) {\n closestDistance = dist;\n closestPoint = position;\n }\n });\n }\n return closestPoint;\n }\n _setTargetMeshPosition(pickInfo) {\n const newPosition = pickInfo.pickedPoint;\n if (!this._options.teleportationTargetMesh || !newPosition) {\n return;\n }\n const snapPosition = this._findClosestSnapPointWithRadius(newPosition);\n this._snappedToPoint = !!snapPosition;\n if (this.snapPointsOnly && !this._snappedToPoint && this._teleportationRingMaterial) {\n this._teleportationRingMaterial.diffuseColor.set(1.0, 0.3, 0.3);\n }\n else if (this.snapPointsOnly && this._snappedToPoint && this._teleportationRingMaterial) {\n this._teleportationRingMaterial.diffuseColor.set(0.3, 0.3, 1.0);\n }\n this._options.teleportationTargetMesh.position.copyFrom(snapPosition || newPosition);\n this._options.teleportationTargetMesh.position.y += 0.01;\n this.onTargetMeshPositionUpdatedObservable.notifyObservers(pickInfo);\n }\n _setTargetMeshVisibility(visible, force) {\n if (!this._options.teleportationTargetMesh) {\n return;\n }\n if (this._options.teleportationTargetMesh.isVisible === visible && !force) {\n return;\n }\n this._options.teleportationTargetMesh.isVisible = visible;\n this._options.teleportationTargetMesh.getChildren(undefined, false).forEach((m) => {\n m.isVisible = visible;\n });\n if (!visible) {\n if (this._quadraticBezierCurve) {\n this._quadraticBezierCurve.dispose();\n this._quadraticBezierCurve = null;\n }\n if (this._selectionFeature) {\n this._selectionFeature.attach();\n }\n }\n else {\n if (this._selectionFeature) {\n this._selectionFeature.detach();\n }\n }\n }\n _disposeBezierCurve() {\n if (this._quadraticBezierCurve) {\n this._quadraticBezierCurve.dispose();\n this._quadraticBezierCurve = null;\n }\n }\n _showParabolicPath(pickInfo) {\n if (!pickInfo.pickedPoint || !this._currentTeleportationControllerId) {\n return;\n }\n const sceneToRenderTo = this._options.useUtilityLayer\n ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene\n : this._xrSessionManager.scene;\n const controllerData = this._controllers[this._currentTeleportationControllerId];\n const quadraticBezierVectors = Curve3.CreateQuadraticBezier(controllerData.xrController.pointer.absolutePosition, pickInfo.ray.origin, pickInfo.pickedPoint, 25);\n const color = controllerData.teleportationState.blocked ? this._blockedRayColor : undefined;\n const colorsArray = new Array(26).fill(color || this._cachedColor4White);\n if (!this._options.generateRayPathMesh) {\n this._quadraticBezierCurve = CreateLines(\"teleportation path line\", { points: quadraticBezierVectors.getPoints(), instance: this._quadraticBezierCurve, updatable: true, colors: colorsArray }, sceneToRenderTo);\n }\n else {\n this._quadraticBezierCurve = this._options.generateRayPathMesh(quadraticBezierVectors.getPoints(), pickInfo);\n }\n this._quadraticBezierCurve.isPickable = false;\n if (this._options.renderingGroupId !== undefined) {\n this._quadraticBezierCurve.renderingGroupId = this._options.renderingGroupId;\n }\n }\n _teleportForward(controllerId) {\n const controllerData = this._controllers[controllerId];\n if (!controllerData || !controllerData.teleportationState.forward || !this.teleportationEnabled) {\n return;\n }\n controllerData.teleportationState.forward = false;\n this._currentTeleportationControllerId = \"\";\n if (this.snapPointsOnly && !this._snappedToPoint) {\n return;\n }\n if (this.skipNextTeleportation) {\n this.skipNextTeleportation = false;\n return;\n }\n // do the movement forward here\n if (this._options.teleportationTargetMesh && this._options.teleportationTargetMesh.isVisible) {\n const height = this._options.xrInput.xrCamera.realWorldHeight;\n this._options.xrInput.xrCamera.onBeforeCameraTeleport.notifyObservers(this._options.xrInput.xrCamera.position);\n this._options.xrInput.xrCamera.position.copyFrom(this._options.teleportationTargetMesh.position);\n this._options.xrInput.xrCamera.position.y += height;\n Quaternion.FromEulerAngles(0, controllerData.teleportationState.currentRotation - (this._xrSessionManager.scene.useRightHandedSystem ? Math.PI : 0), 0).multiplyToRef(this._options.xrInput.xrCamera.rotationQuaternion, this._options.xrInput.xrCamera.rotationQuaternion);\n this._options.xrInput.xrCamera.onAfterCameraTeleport.notifyObservers(this._options.xrInput.xrCamera.position);\n }\n }\n }\n /**\n * The module's name\n */\n WebXRMotionControllerTeleportation.Name = WebXRFeatureName.TELEPORTATION;\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the webxr specs version\n */\n WebXRMotionControllerTeleportation.Version = 1;\n WebXRFeaturesManager.AddWebXRFeature(WebXRMotionControllerTeleportation.Name, (xrSessionManager, options) => {\n return () => new WebXRMotionControllerTeleportation(xrSessionManager, options);\n }, WebXRMotionControllerTeleportation.Version, true);\n\n /**\n * Default experience which provides a similar setup to the previous webVRExperience\n */\n class WebXRDefaultExperience {\n constructor() { }\n /**\n * Creates the default xr experience\n * @param scene scene\n * @param options options for basic configuration\n * @returns resulting WebXRDefaultExperience\n */\n static CreateAsync(scene, options = {}) {\n const result = new WebXRDefaultExperience();\n scene.onDisposeObservable.addOnce(() => {\n result.dispose();\n });\n // init the UI right after construction\n if (!options.disableDefaultUI) {\n const uiOptions = Object.assign({ renderTarget: result.renderTarget }, (options.uiOptions || {}));\n if (options.optionalFeatures) {\n if (typeof options.optionalFeatures === \"boolean\") {\n uiOptions.optionalFeatures = [\"hit-test\", \"anchors\", \"plane-detection\", \"hand-tracking\"];\n }\n else {\n uiOptions.optionalFeatures = options.optionalFeatures;\n }\n }\n result.enterExitUI = new WebXREnterExitUI(scene, uiOptions);\n }\n // Create base experience\n return WebXRExperienceHelper.CreateAsync(scene)\n .then((xrHelper) => {\n result.baseExperience = xrHelper;\n if (options.ignoreNativeCameraTransformation) {\n result.baseExperience.camera.compensateOnFirstFrame = false;\n }\n // Add controller support\n result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, Object.assign({ controllerOptions: {\n renderingGroupId: options.renderingGroupId,\n } }, (options.inputOptions || {})));\n if (!options.disablePointerSelection) {\n // Add default pointer selection\n const pointerSelectionOptions = Object.assign(Object.assign({}, options.pointerSelectionOptions), { xrInput: result.input, renderingGroupId: options.renderingGroupId });\n result.pointerSelection = (result.baseExperience.featuresManager.enableFeature(WebXRControllerPointerSelection.Name, options.useStablePlugins ? \"stable\" : \"latest\", pointerSelectionOptions));\n if (!options.disableTeleportation) {\n // Add default teleportation, including rotation\n result.teleportation = result.baseExperience.featuresManager.enableFeature(WebXRMotionControllerTeleportation.Name, options.useStablePlugins ? \"stable\" : \"latest\", Object.assign({ floorMeshes: options.floorMeshes, xrInput: result.input, renderingGroupId: options.renderingGroupId }, options.teleportationOptions));\n result.teleportation.setSelectionFeature(result.pointerSelection);\n }\n }\n if (!options.disableNearInteraction) {\n // Add default pointer selection\n result.nearInteraction = result.baseExperience.featuresManager.enableFeature(WebXRNearInteraction.Name, options.useStablePlugins ? \"stable\" : \"latest\", Object.assign({ xrInput: result.input, farInteractionFeature: result.pointerSelection, renderingGroupId: options.renderingGroupId, useUtilityLayer: true, enableNearInteractionOnAllControllers: true }, options.nearInteractionOptions));\n }\n // Create the WebXR output target\n result.renderTarget = result.baseExperience.sessionManager.getWebXRRenderTarget(options.outputCanvasOptions);\n if (!options.disableDefaultUI) {\n // Create ui for entering/exiting xr\n return result.enterExitUI.setHelperAsync(result.baseExperience, result.renderTarget);\n }\n else {\n return;\n }\n })\n .then(() => {\n return result;\n })\n .catch((error) => {\n Logger.Error(\"Error initializing XR\");\n Logger.Error(error);\n return result;\n });\n }\n /**\n * Disposes of the experience helper\n */\n dispose() {\n if (this.baseExperience) {\n this.baseExperience.dispose();\n }\n if (this.input) {\n this.input.dispose();\n }\n if (this.enterExitUI) {\n this.enterExitUI.dispose();\n }\n if (this.renderTarget) {\n this.renderTarget.dispose();\n }\n }\n }\n\n Scene.prototype.createDefaultLight = function (replace = false) {\n // Dispose existing light in replace mode.\n if (replace) {\n if (this.lights) {\n for (let i = 0; i < this.lights.length; i++) {\n this.lights[i].dispose();\n }\n }\n }\n // Light\n if (this.lights.length === 0) {\n new HemisphericLight(\"default light\", Vector3.Up(), this);\n }\n };\n Scene.prototype.createDefaultCamera = function (createArcRotateCamera = false, replace = false, attachCameraControls = false) {\n // Dispose existing camera in replace mode.\n if (replace) {\n if (this.activeCamera) {\n this.activeCamera.dispose();\n this.activeCamera = null;\n }\n }\n // Camera\n if (!this.activeCamera) {\n const worldExtends = this.getWorldExtends((mesh) => mesh.isVisible && mesh.isEnabled());\n const worldSize = worldExtends.max.subtract(worldExtends.min);\n const worldCenter = worldExtends.min.add(worldSize.scale(0.5));\n let camera;\n let radius = worldSize.length() * 1.5;\n // empty scene scenario!\n if (!isFinite(radius)) {\n radius = 1;\n worldCenter.copyFromFloats(0, 0, 0);\n }\n if (createArcRotateCamera) {\n const arcRotateCamera = new ArcRotateCamera(\"default camera\", -(Math.PI / 2), Math.PI / 2, radius, worldCenter, this);\n arcRotateCamera.lowerRadiusLimit = radius * 0.01;\n arcRotateCamera.wheelPrecision = 100 / radius;\n camera = arcRotateCamera;\n }\n else {\n const freeCamera = new FreeCamera(\"default camera\", new Vector3(worldCenter.x, worldCenter.y, -radius), this);\n freeCamera.setTarget(worldCenter);\n camera = freeCamera;\n }\n camera.minZ = radius * 0.01;\n camera.maxZ = radius * 1000;\n camera.speed = radius * 0.2;\n this.activeCamera = camera;\n if (attachCameraControls) {\n camera.attachControl();\n }\n }\n };\n Scene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera = false, replace = false, attachCameraControls = false) {\n this.createDefaultLight(replace);\n this.createDefaultCamera(createArcRotateCamera, replace, attachCameraControls);\n };\n Scene.prototype.createDefaultSkybox = function (environmentTexture, pbr = false, scale = 1000, blur = 0, setGlobalEnvTexture = true) {\n if (!environmentTexture) {\n Logger.Warn(\"Can not create default skybox without environment texture.\");\n return null;\n }\n if (setGlobalEnvTexture) {\n if (environmentTexture) {\n this.environmentTexture = environmentTexture;\n }\n }\n // Skybox\n const hdrSkybox = CreateBox(\"hdrSkyBox\", { size: scale }, this);\n if (pbr) {\n const hdrSkyboxMaterial = new PBRMaterial(\"skyBox\", this);\n hdrSkyboxMaterial.backFaceCulling = false;\n hdrSkyboxMaterial.reflectionTexture = environmentTexture.clone();\n if (hdrSkyboxMaterial.reflectionTexture) {\n hdrSkyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;\n }\n hdrSkyboxMaterial.microSurface = 1.0 - blur;\n hdrSkyboxMaterial.disableLighting = true;\n hdrSkyboxMaterial.twoSidedLighting = true;\n hdrSkybox.material = hdrSkyboxMaterial;\n }\n else {\n const skyboxMaterial = new StandardMaterial(\"skyBox\", this);\n skyboxMaterial.backFaceCulling = false;\n skyboxMaterial.reflectionTexture = environmentTexture.clone();\n if (skyboxMaterial.reflectionTexture) {\n skyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;\n }\n skyboxMaterial.disableLighting = true;\n hdrSkybox.material = skyboxMaterial;\n }\n hdrSkybox.isPickable = false;\n hdrSkybox.infiniteDistance = true;\n hdrSkybox.ignoreCameraMaxZ = true;\n return hdrSkybox;\n };\n Scene.prototype.createDefaultEnvironment = function (options) {\n if (EnvironmentHelper) {\n return new EnvironmentHelper(options, this);\n }\n return null;\n };\n Scene.prototype.createDefaultVRExperience = function (webVROptions = {}) {\n return new VRExperienceHelper(this, webVROptions);\n };\n Scene.prototype.createDefaultXRExperienceAsync = function (options = {}) {\n return WebXRDefaultExperience.CreateAsync(this, options).then((helper) => {\n return helper;\n });\n };\n\n // Do not edit.\n const name$1_ = \"glowMapGenerationPixelShader\";\n const shader$1_ = `#if defined(DIFFUSE_ISLINEAR) || defined(EMISSIVE_ISLINEAR)\n#include\n#endif\n#ifdef DIFFUSE\nvarying vec2 vUVDiffuse;uniform sampler2D diffuseSampler;\n#endif\n#ifdef OPACITY\nvarying vec2 vUVOpacity;uniform sampler2D opacitySampler;uniform float opacityIntensity;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;uniform sampler2D emissiveSampler;\n#endif\n#ifdef VERTEXALPHA\nvarying vec4 vColor;\n#endif\nuniform vec4 glowColor;uniform float glowIntensity;\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#include\nvec4 finalColor=glowColor;\n#ifdef DIFFUSE\nvec4 albedoTexture=texture2D(diffuseSampler,vUVDiffuse);\n#ifdef DIFFUSE_ISLINEAR\nalbedoTexture=toGammaSpace(albedoTexture);\n#endif\n#ifdef GLOW\nfinalColor.a*=albedoTexture.a;\n#endif\n#ifdef HIGHLIGHT\nfinalColor.a=albedoTexture.a;\n#endif\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vUVOpacity);\n#ifdef OPACITYRGB\nfinalColor.a*=getLuminance(opacityMap.rgb);\n#else\nfinalColor.a*=opacityMap.a;\n#endif\nfinalColor.a*=opacityIntensity;\n#endif\n#ifdef VERTEXALPHA\nfinalColor.a*=vColor.a;\n#endif\n#ifdef ALPHATEST\nif (finalColor.a\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\nuniform mat4 viewProjection;varying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef DIFFUSE\nvarying vec2 vUVDiffuse;uniform mat4 diffuseMatrix;\n#endif\n#ifdef OPACITY\nvarying vec2 vUVOpacity;uniform mat4 opacityMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;uniform mat4 emissiveMatrix;\n#endif\n#ifdef VERTEXALPHA\nattribute vec4 color;varying vec4 vColor;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#ifdef CUBEMAP\nvPosition=worldPos;gl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*worldPos;gl_Position=vPosition;\n#endif\n#ifdef DIFFUSE\n#ifdef DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef OPACITY\n#ifdef OPACITYUV1\nvUVOpacity=vec2(opacityMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef OPACITYUV2\nvUVOpacity=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef VERTEXALPHA\nvColor=color;\n#endif\n#include\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$1$] = shader$1$;\n\n /**\n * The effect layer Helps adding post process effect blended with the main pass.\n *\n * This can be for instance use to generate glow or highlight effects on the scene.\n *\n * The effect layer class can not be used directly and is intented to inherited from to be\n * customized per effects.\n */\n class EffectLayer {\n /**\n * Gets the camera attached to the layer.\n */\n get camera() {\n return this._effectLayerOptions.camera;\n }\n /**\n * Gets the rendering group id the layer should render in.\n */\n get renderingGroupId() {\n return this._effectLayerOptions.renderingGroupId;\n }\n set renderingGroupId(renderingGroupId) {\n this._effectLayerOptions.renderingGroupId = renderingGroupId;\n }\n /**\n * Gets the main texture where the effect is rendered\n */\n get mainTexture() {\n return this._mainTexture;\n }\n /**\n * Sets a specific material to be used to render a mesh/a list of meshes in the layer\n * @param mesh mesh or array of meshes\n * @param material material to use by the layer when rendering the mesh(es). If undefined is passed, the specific material created by the layer will be used.\n */\n setMaterialForRendering(mesh, material) {\n this._mainTexture.setMaterialForRendering(mesh, material);\n if (Array.isArray(mesh)) {\n for (let i = 0; i < mesh.length; ++i) {\n const currentMesh = mesh[i];\n if (!material) {\n delete this._materialForRendering[currentMesh.uniqueId];\n }\n else {\n this._materialForRendering[currentMesh.uniqueId] = [currentMesh, material];\n }\n }\n }\n else {\n if (!material) {\n delete this._materialForRendering[mesh.uniqueId];\n }\n else {\n this._materialForRendering[mesh.uniqueId] = [mesh, material];\n }\n }\n }\n /**\n * Gets the intensity of the effect for a specific mesh.\n * @param mesh The mesh to get the effect intensity for\n * @returns The intensity of the effect for the mesh\n */\n getEffectIntensity(mesh) {\n var _a;\n return (_a = this._effectIntensity[mesh.uniqueId]) !== null && _a !== void 0 ? _a : 1;\n }\n /**\n * Sets the intensity of the effect for a specific mesh.\n * @param mesh The mesh to set the effect intensity for\n * @param intensity The intensity of the effect for the mesh\n */\n setEffectIntensity(mesh, intensity) {\n this._effectIntensity[mesh.uniqueId] = intensity;\n }\n /**\n * Instantiates a new effect Layer and references it in the scene.\n * @param name The name of the layer\n * @param scene The scene to use the layer in\n */\n constructor(\n /** The Friendly of the effect in the scene */\n name, scene) {\n this._vertexBuffers = {};\n this._maxSize = 0;\n this._mainTextureDesiredSize = { width: 0, height: 0 };\n this._shouldRender = true;\n this._postProcesses = [];\n this._textures = [];\n this._emissiveTextureAndColor = { texture: null, color: new Color4() };\n this._effectIntensity = {};\n /**\n * The clear color of the texture used to generate the glow map.\n */\n this.neutralColor = new Color4();\n /**\n * Specifies whether the highlight layer is enabled or not.\n */\n this.isEnabled = true;\n /**\n * Specifies if the bounding boxes should be rendered normally or if they should undergo the effect of the layer\n */\n this.disableBoundingBoxesFromEffectLayer = false;\n /**\n * An event triggered when the effect layer has been disposed.\n */\n this.onDisposeObservable = new Observable$1();\n /**\n * An event triggered when the effect layer is about rendering the main texture with the glowy parts.\n */\n this.onBeforeRenderMainTextureObservable = new Observable$1();\n /**\n * An event triggered when the generated texture is being merged in the scene.\n */\n this.onBeforeComposeObservable = new Observable$1();\n /**\n * An event triggered when the mesh is rendered into the effect render target.\n */\n this.onBeforeRenderMeshToEffect = new Observable$1();\n /**\n * An event triggered after the mesh has been rendered into the effect render target.\n */\n this.onAfterRenderMeshToEffect = new Observable$1();\n /**\n * An event triggered when the generated texture has been merged in the scene.\n */\n this.onAfterComposeObservable = new Observable$1();\n /**\n * An event triggered when the effect layer changes its size.\n */\n this.onSizeChangedObservable = new Observable$1();\n this._materialForRendering = {};\n this.name = name;\n this._scene = scene || EngineStore.LastCreatedScene;\n EffectLayer._SceneComponentInitialization(this._scene);\n this._engine = this._scene.getEngine();\n this._maxSize = this._engine.getCaps().maxTextureSize;\n this._scene.effectLayers.push(this);\n this._mergeDrawWrapper = [];\n // Generate Buffers\n this._generateIndexBuffer();\n this._generateVertexBuffer();\n }\n /**\n * Number of times _internalRender will be called. Some effect layers need to render the mesh several times, so they should override this method with the number of times the mesh should be rendered\n * @returns Number of times a mesh must be rendered in the layer\n */\n _numInternalDraws() {\n return 1;\n }\n /**\n * Initializes the effect layer with the required options.\n * @param options Sets of none mandatory options to use with the layer (see IEffectLayerOptions for more information)\n */\n _init(options) {\n // Adapt options\n this._effectLayerOptions = Object.assign({ mainTextureRatio: 0.5, alphaBlendingMode: 2, camera: null, renderingGroupId: -1, mainTextureType: 0, generateStencilBuffer: false }, options);\n this._setMainTextureSize();\n this._createMainTexture();\n this._createTextureAndPostProcesses();\n }\n /**\n * Generates the index buffer of the full screen quad blending to the main canvas.\n */\n _generateIndexBuffer() {\n // Indices\n const indices = [];\n indices.push(0);\n indices.push(1);\n indices.push(2);\n indices.push(0);\n indices.push(2);\n indices.push(3);\n this._indexBuffer = this._engine.createIndexBuffer(indices);\n }\n /**\n * Generates the vertex buffer of the full screen quad blending to the main canvas.\n */\n _generateVertexBuffer() {\n // VBO\n const vertices = [];\n vertices.push(1, 1);\n vertices.push(-1, 1);\n vertices.push(-1, -1);\n vertices.push(1, -1);\n const vertexBuffer = new VertexBuffer(this._engine, vertices, VertexBuffer.PositionKind, false, false, 2);\n this._vertexBuffers[VertexBuffer.PositionKind] = vertexBuffer;\n }\n /**\n * Sets the main texture desired size which is the closest power of two\n * of the engine canvas size.\n */\n _setMainTextureSize() {\n if (this._effectLayerOptions.mainTextureFixedSize) {\n this._mainTextureDesiredSize.width = this._effectLayerOptions.mainTextureFixedSize;\n this._mainTextureDesiredSize.height = this._effectLayerOptions.mainTextureFixedSize;\n }\n else {\n this._mainTextureDesiredSize.width = this._engine.getRenderWidth() * this._effectLayerOptions.mainTextureRatio;\n this._mainTextureDesiredSize.height = this._engine.getRenderHeight() * this._effectLayerOptions.mainTextureRatio;\n this._mainTextureDesiredSize.width = this._engine.needPOTTextures\n ? Engine.GetExponentOfTwo(this._mainTextureDesiredSize.width, this._maxSize)\n : this._mainTextureDesiredSize.width;\n this._mainTextureDesiredSize.height = this._engine.needPOTTextures\n ? Engine.GetExponentOfTwo(this._mainTextureDesiredSize.height, this._maxSize)\n : this._mainTextureDesiredSize.height;\n }\n this._mainTextureDesiredSize.width = Math.floor(this._mainTextureDesiredSize.width);\n this._mainTextureDesiredSize.height = Math.floor(this._mainTextureDesiredSize.height);\n }\n /**\n * Creates the main texture for the effect layer.\n */\n _createMainTexture() {\n this._mainTexture = new RenderTargetTexture(\"EffectLayerMainRTT\", {\n width: this._mainTextureDesiredSize.width,\n height: this._mainTextureDesiredSize.height,\n }, this._scene, false, true, this._effectLayerOptions.mainTextureType, false, Texture.TRILINEAR_SAMPLINGMODE, true, this._effectLayerOptions.generateStencilBuffer);\n this._mainTexture.activeCamera = this._effectLayerOptions.camera;\n this._mainTexture.wrapU = Texture.CLAMP_ADDRESSMODE;\n this._mainTexture.wrapV = Texture.CLAMP_ADDRESSMODE;\n this._mainTexture.anisotropicFilteringLevel = 1;\n this._mainTexture.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\n this._mainTexture.renderParticles = false;\n this._mainTexture.renderList = null;\n this._mainTexture.ignoreCameraViewport = true;\n for (const id in this._materialForRendering) {\n const [mesh, material] = this._materialForRendering[id];\n this._mainTexture.setMaterialForRendering(mesh, material);\n }\n this._mainTexture.customIsReadyFunction = (mesh, refreshRate, preWarm) => {\n if ((preWarm || refreshRate === 0) && mesh.subMeshes) {\n for (let i = 0; i < mesh.subMeshes.length; ++i) {\n const subMesh = mesh.subMeshes[i];\n const material = subMesh.getMaterial();\n const renderingMesh = subMesh.getRenderingMesh();\n if (!material) {\n continue;\n }\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\n const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] || renderingMesh.hasThinInstances;\n this._setEmissiveTextureAndColor(renderingMesh, subMesh, material);\n if (!this._isReady(subMesh, hardwareInstancedRendering, this._emissiveTextureAndColor.texture)) {\n return false;\n }\n }\n }\n return true;\n };\n // Custom render function\n this._mainTexture.customRenderFunction = (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) => {\n this.onBeforeRenderMainTextureObservable.notifyObservers(this);\n let index;\n const engine = this._scene.getEngine();\n if (depthOnlySubMeshes.length) {\n engine.setColorWrite(false);\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\n this._renderSubMesh(depthOnlySubMeshes.data[index]);\n }\n engine.setColorWrite(true);\n }\n for (index = 0; index < opaqueSubMeshes.length; index++) {\n this._renderSubMesh(opaqueSubMeshes.data[index]);\n }\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\n this._renderSubMesh(alphaTestSubMeshes.data[index]);\n }\n const previousAlphaMode = engine.getAlphaMode();\n for (index = 0; index < transparentSubMeshes.length; index++) {\n this._renderSubMesh(transparentSubMeshes.data[index], true);\n }\n engine.setAlphaMode(previousAlphaMode);\n };\n this._mainTexture.onClearObservable.add((engine) => {\n engine.clear(this.neutralColor, true, true, true);\n });\n // Prevent package size in es6 (getBoundingBoxRenderer might not be present)\n if (this._scene.getBoundingBoxRenderer) {\n const boundingBoxRendererEnabled = this._scene.getBoundingBoxRenderer().enabled;\n this._mainTexture.onBeforeBindObservable.add(() => {\n this._scene.getBoundingBoxRenderer().enabled = !this.disableBoundingBoxesFromEffectLayer && boundingBoxRendererEnabled;\n });\n this._mainTexture.onAfterUnbindObservable.add(() => {\n this._scene.getBoundingBoxRenderer().enabled = boundingBoxRendererEnabled;\n });\n }\n }\n /**\n * Adds specific effects defines.\n * @param defines The defines to add specifics to.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _addCustomEffectDefines(defines) {\n // Nothing to add by default.\n }\n /**\n * Checks for the readiness of the element composing the layer.\n * @param subMesh the mesh to check for\n * @param useInstances specify whether or not to use instances to render the mesh\n * @param emissiveTexture the associated emissive texture used to generate the glow\n * @returns true if ready otherwise, false\n */\n _isReady(subMesh, useInstances, emissiveTexture) {\n var _a;\n const engine = this._scene.getEngine();\n const mesh = subMesh.getMesh();\n const renderingMaterial = (_a = mesh._internalAbstractMeshDataInfo._materialForRenderPass) === null || _a === void 0 ? void 0 : _a[engine.currentRenderPassId];\n if (renderingMaterial) {\n return renderingMaterial.isReadyForSubMesh(mesh, subMesh, useInstances);\n }\n const material = subMesh.getMaterial();\n if (!material) {\n return false;\n }\n if (this._useMeshMaterial(subMesh.getRenderingMesh())) {\n return material.isReadyForSubMesh(subMesh.getMesh(), subMesh, useInstances);\n }\n const defines = [];\n const attribs = [VertexBuffer.PositionKind];\n let uv1 = false;\n let uv2 = false;\n // Diffuse\n if (material) {\n const needAlphaTest = material.needAlphaTesting();\n const diffuseTexture = material.getAlphaTestTexture();\n const needAlphaBlendFromDiffuse = diffuseTexture && diffuseTexture.hasAlpha && (material.useAlphaFromDiffuseTexture || material._useAlphaFromAlbedoTexture);\n if (diffuseTexture && (needAlphaTest || needAlphaBlendFromDiffuse)) {\n defines.push(\"#define DIFFUSE\");\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && diffuseTexture.coordinatesIndex === 1) {\n defines.push(\"#define DIFFUSEUV2\");\n uv2 = true;\n }\n else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n defines.push(\"#define DIFFUSEUV1\");\n uv1 = true;\n }\n if (needAlphaTest) {\n defines.push(\"#define ALPHATEST\");\n defines.push(\"#define ALPHATESTVALUE 0.4\");\n }\n if (!diffuseTexture.gammaSpace) {\n defines.push(\"#define DIFFUSE_ISLINEAR\");\n }\n }\n const opacityTexture = material.opacityTexture;\n if (opacityTexture) {\n defines.push(\"#define OPACITY\");\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && opacityTexture.coordinatesIndex === 1) {\n defines.push(\"#define OPACITYUV2\");\n uv2 = true;\n }\n else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n defines.push(\"#define OPACITYUV1\");\n uv1 = true;\n }\n }\n }\n // Emissive\n if (emissiveTexture) {\n defines.push(\"#define EMISSIVE\");\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && emissiveTexture.coordinatesIndex === 1) {\n defines.push(\"#define EMISSIVEUV2\");\n uv2 = true;\n }\n else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n defines.push(\"#define EMISSIVEUV1\");\n uv1 = true;\n }\n if (!emissiveTexture.gammaSpace) {\n defines.push(\"#define EMISSIVE_ISLINEAR\");\n }\n }\n // Vertex\n if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind) && mesh.hasVertexAlpha && material.transparencyMode !== Material.MATERIAL_OPAQUE) {\n attribs.push(VertexBuffer.ColorKind);\n defines.push(\"#define VERTEXALPHA\");\n }\n if (uv1) {\n attribs.push(VertexBuffer.UVKind);\n defines.push(\"#define UV1\");\n }\n if (uv2) {\n attribs.push(VertexBuffer.UV2Kind);\n defines.push(\"#define UV2\");\n }\n // Bones\n const fallbacks = new EffectFallbacks();\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (mesh.numBoneInfluencers > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\n const skeleton = mesh.skeleton;\n if (skeleton && skeleton.isUsingTextureForMatrices) {\n defines.push(\"#define BONETEXTURE\");\n }\n else {\n defines.push(\"#define BonesPerMesh \" + (skeleton ? skeleton.bones.length + 1 : 0));\n }\n if (mesh.numBoneInfluencers > 0) {\n fallbacks.addCPUSkinningFallback(0, mesh);\n }\n }\n else {\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\n }\n // Morph targets\n const manager = mesh.morphTargetManager;\n let morphInfluencers = 0;\n if (manager) {\n if (manager.numInfluencers > 0) {\n defines.push(\"#define MORPHTARGETS\");\n morphInfluencers = manager.numInfluencers;\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + morphInfluencers);\n if (manager.isUsingTextureForTargets) {\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\n }\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, morphInfluencers);\n }\n }\n // Instances\n if (useInstances) {\n defines.push(\"#define INSTANCES\");\n MaterialHelper.PushAttributesForInstances(attribs);\n if (subMesh.getRenderingMesh().hasThinInstances) {\n defines.push(\"#define THIN_INSTANCES\");\n }\n }\n // ClipPlanes\n prepareStringDefinesForClipPlanes(material, this._scene, defines);\n this._addCustomEffectDefines(defines);\n // Get correct effect\n const drawWrapper = subMesh._getDrawWrapper(undefined, true);\n const cachedDefines = drawWrapper.defines;\n const join = defines.join(\"\\n\");\n if (cachedDefines !== join) {\n const uniforms = [\n \"world\",\n \"mBones\",\n \"viewProjection\",\n \"glowColor\",\n \"morphTargetInfluences\",\n \"boneTextureWidth\",\n \"diffuseMatrix\",\n \"emissiveMatrix\",\n \"opacityMatrix\",\n \"opacityIntensity\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n \"glowIntensity\",\n ];\n addClipPlaneUniforms(uniforms);\n drawWrapper.setEffect(this._engine.createEffect(\"glowMapGeneration\", attribs, uniforms, [\"diffuseSampler\", \"emissiveSampler\", \"opacitySampler\", \"boneSampler\", \"morphTargets\"], join, fallbacks, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers }), join);\n }\n return drawWrapper.effect.isReady();\n }\n /**\n * Renders the glowing part of the scene by blending the blurred glowing meshes on top of the rendered scene.\n */\n render() {\n for (let i = 0; i < this._postProcesses.length; i++) {\n if (!this._postProcesses[i].isReady()) {\n return;\n }\n }\n const engine = this._scene.getEngine();\n const numDraws = this._numInternalDraws();\n // Check\n let isReady = true;\n for (let i = 0; i < numDraws; ++i) {\n let currentEffect = this._mergeDrawWrapper[i];\n if (!currentEffect) {\n currentEffect = this._mergeDrawWrapper[i] = new DrawWrapper(this._engine);\n currentEffect.setEffect(this._createMergeEffect());\n }\n isReady = isReady && currentEffect.effect.isReady();\n }\n if (!isReady) {\n return;\n }\n this.onBeforeComposeObservable.notifyObservers(this);\n const previousAlphaMode = engine.getAlphaMode();\n for (let i = 0; i < numDraws; ++i) {\n const currentEffect = this._mergeDrawWrapper[i];\n // Render\n engine.enableEffect(currentEffect);\n engine.setState(false);\n // VBOs\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, currentEffect.effect);\n // Go Blend.\n engine.setAlphaMode(this._effectLayerOptions.alphaBlendingMode);\n // Blends the map on the main canvas.\n this._internalRender(currentEffect.effect, i);\n }\n // Restore Alpha\n engine.setAlphaMode(previousAlphaMode);\n this.onAfterComposeObservable.notifyObservers(this);\n // Handle size changes.\n const size = this._mainTexture.getSize();\n this._setMainTextureSize();\n if ((size.width !== this._mainTextureDesiredSize.width || size.height !== this._mainTextureDesiredSize.height) &&\n this._mainTextureDesiredSize.width !== 0 &&\n this._mainTextureDesiredSize.height !== 0) {\n // Recreate RTT and post processes on size change.\n this.onSizeChangedObservable.notifyObservers(this);\n this._disposeTextureAndPostProcesses();\n this._createMainTexture();\n this._createTextureAndPostProcesses();\n }\n }\n /**\n * Determine if a given mesh will be used in the current effect.\n * @param mesh mesh to test\n * @returns true if the mesh will be used\n */\n hasMesh(mesh) {\n if (this.renderingGroupId === -1 || mesh.renderingGroupId === this.renderingGroupId) {\n return true;\n }\n return false;\n }\n /**\n * Returns true if the layer contains information to display, otherwise false.\n * @returns true if the glow layer should be rendered\n */\n shouldRender() {\n return this.isEnabled && this._shouldRender;\n }\n /**\n * Returns true if the mesh should render, otherwise false.\n * @param mesh The mesh to render\n * @returns true if it should render otherwise false\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _shouldRenderMesh(mesh) {\n return true;\n }\n /**\n * Returns true if the mesh can be rendered, otherwise false.\n * @param mesh The mesh to render\n * @param material The material used on the mesh\n * @returns true if it can be rendered otherwise false\n */\n _canRenderMesh(mesh, material) {\n return !material.needAlphaBlendingForMesh(mesh);\n }\n /**\n * Returns true if the mesh should render, otherwise false.\n * @returns true if it should render otherwise false\n */\n _shouldRenderEmissiveTextureForMesh() {\n return true;\n }\n /**\n * Renders the submesh passed in parameter to the generation map.\n * @param subMesh\n * @param enableAlphaMode\n */\n _renderSubMesh(subMesh, enableAlphaMode = false) {\n var _a, _b;\n if (!this.shouldRender()) {\n return;\n }\n const material = subMesh.getMaterial();\n const ownerMesh = subMesh.getMesh();\n const replacementMesh = subMesh.getReplacementMesh();\n const renderingMesh = subMesh.getRenderingMesh();\n const effectiveMesh = subMesh.getEffectiveMesh();\n const scene = this._scene;\n const engine = scene.getEngine();\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n if (!material) {\n return;\n }\n // Do not block in blend mode.\n if (!this._canRenderMesh(renderingMesh, material)) {\n return;\n }\n // Culling\n let sideOrientation = (_a = renderingMesh.overrideMaterialSideOrientation) !== null && _a !== void 0 ? _a : material.sideOrientation;\n const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();\n if (mainDeterminant < 0) {\n sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;\n }\n const reverse = sideOrientation === Material.ClockWiseSideOrientation;\n engine.setState(material.backFaceCulling, material.zOffset, undefined, reverse, material.cullBackFaces, undefined, material.zOffsetUnits);\n // Managing instances\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!replacementMesh);\n if (batch.mustReturn) {\n return;\n }\n // Early Exit per mesh\n if (!this._shouldRenderMesh(renderingMesh)) {\n return;\n }\n const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] || renderingMesh.hasThinInstances;\n this._setEmissiveTextureAndColor(renderingMesh, subMesh, material);\n this.onBeforeRenderMeshToEffect.notifyObservers(ownerMesh);\n if (this._useMeshMaterial(renderingMesh)) {\n renderingMesh.render(subMesh, enableAlphaMode, replacementMesh || undefined);\n }\n else if (this._isReady(subMesh, hardwareInstancedRendering, this._emissiveTextureAndColor.texture)) {\n const renderingMaterial = (_b = effectiveMesh._internalAbstractMeshDataInfo._materialForRenderPass) === null || _b === void 0 ? void 0 : _b[engine.currentRenderPassId];\n let drawWrapper = subMesh._getDrawWrapper();\n if (!drawWrapper && renderingMaterial) {\n drawWrapper = renderingMaterial._getDrawWrapper();\n }\n if (!drawWrapper) {\n return;\n }\n const effect = drawWrapper.effect;\n engine.enableEffect(drawWrapper);\n if (!hardwareInstancedRendering) {\n renderingMesh._bind(subMesh, effect, material.fillMode);\n }\n if (!renderingMaterial) {\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\n effect.setMatrix(\"world\", effectiveMesh.getWorldMatrix());\n effect.setFloat4(\"glowColor\", this._emissiveTextureAndColor.color.r, this._emissiveTextureAndColor.color.g, this._emissiveTextureAndColor.color.b, this._emissiveTextureAndColor.color.a);\n }\n else {\n renderingMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), effectiveMesh, subMesh);\n }\n if (!renderingMaterial) {\n const needAlphaTest = material.needAlphaTesting();\n const diffuseTexture = material.getAlphaTestTexture();\n const needAlphaBlendFromDiffuse = diffuseTexture && diffuseTexture.hasAlpha && (material.useAlphaFromDiffuseTexture || material._useAlphaFromAlbedoTexture);\n if (diffuseTexture && (needAlphaTest || needAlphaBlendFromDiffuse)) {\n effect.setTexture(\"diffuseSampler\", diffuseTexture);\n const textureMatrix = diffuseTexture.getTextureMatrix();\n if (textureMatrix) {\n effect.setMatrix(\"diffuseMatrix\", textureMatrix);\n }\n }\n const opacityTexture = material.opacityTexture;\n if (opacityTexture) {\n effect.setTexture(\"opacitySampler\", opacityTexture);\n effect.setFloat(\"opacityIntensity\", opacityTexture.level);\n const textureMatrix = opacityTexture.getTextureMatrix();\n if (textureMatrix) {\n effect.setMatrix(\"opacityMatrix\", textureMatrix);\n }\n }\n // Glow emissive only\n if (this._emissiveTextureAndColor.texture) {\n effect.setTexture(\"emissiveSampler\", this._emissiveTextureAndColor.texture);\n effect.setMatrix(\"emissiveMatrix\", this._emissiveTextureAndColor.texture.getTextureMatrix());\n }\n // Bones\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\n const skeleton = renderingMesh.skeleton;\n if (skeleton.isUsingTextureForMatrices) {\n const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);\n if (!boneTexture) {\n return;\n }\n effect.setTexture(\"boneSampler\", boneTexture);\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\n }\n else {\n effect.setMatrices(\"mBones\", skeleton.getTransformMatrices(renderingMesh));\n }\n }\n // Morph targets\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\n renderingMesh.morphTargetManager._bind(effect);\n }\n // Alpha mode\n if (enableAlphaMode) {\n engine.setAlphaMode(material.alphaMode);\n }\n // Intensity of effect\n effect.setFloat(\"glowIntensity\", this.getEffectIntensity(renderingMesh));\n // Clip planes\n bindClipPlane(effect, material, scene);\n }\n // Draw\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) => effect.setMatrix(\"world\", world));\n }\n else {\n // Need to reset refresh rate of the main map\n this._mainTexture.resetRefreshCounter();\n }\n this.onAfterRenderMeshToEffect.notifyObservers(ownerMesh);\n }\n /**\n * Defines whether the current material of the mesh should be use to render the effect.\n * @param mesh defines the current mesh to render\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _useMeshMaterial(mesh) {\n return false;\n }\n /**\n * Rebuild the required buffers.\n * @internal Internal use only.\n */\n _rebuild() {\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\n if (vb) {\n vb._rebuild();\n }\n this._generateIndexBuffer();\n }\n /**\n * Dispose only the render target textures and post process.\n */\n _disposeTextureAndPostProcesses() {\n this._mainTexture.dispose();\n for (let i = 0; i < this._postProcesses.length; i++) {\n if (this._postProcesses[i]) {\n this._postProcesses[i].dispose();\n }\n }\n this._postProcesses = [];\n for (let i = 0; i < this._textures.length; i++) {\n if (this._textures[i]) {\n this._textures[i].dispose();\n }\n }\n this._textures = [];\n }\n /**\n * Dispose the highlight layer and free resources.\n */\n dispose() {\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\n if (vertexBuffer) {\n vertexBuffer.dispose();\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\n }\n if (this._indexBuffer) {\n this._scene.getEngine()._releaseBuffer(this._indexBuffer);\n this._indexBuffer = null;\n }\n for (const drawWrapper of this._mergeDrawWrapper) {\n drawWrapper.dispose();\n }\n this._mergeDrawWrapper = [];\n // Clean textures and post processes\n this._disposeTextureAndPostProcesses();\n // Remove from scene\n const index = this._scene.effectLayers.indexOf(this, 0);\n if (index > -1) {\n this._scene.effectLayers.splice(index, 1);\n }\n // Callback\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n this.onBeforeRenderMainTextureObservable.clear();\n this.onBeforeComposeObservable.clear();\n this.onBeforeRenderMeshToEffect.clear();\n this.onAfterRenderMeshToEffect.clear();\n this.onAfterComposeObservable.clear();\n this.onSizeChangedObservable.clear();\n }\n /**\n * Gets the class name of the effect layer\n * @returns the string with the class name of the effect layer\n */\n getClassName() {\n return \"EffectLayer\";\n }\n /**\n * Creates an effect layer from parsed effect layer data\n * @param parsedEffectLayer defines effect layer data\n * @param scene defines the current scene\n * @param rootUrl defines the root URL containing the effect layer information\n * @returns a parsed effect Layer\n */\n static Parse(parsedEffectLayer, scene, rootUrl) {\n const effectLayerType = Tools.Instantiate(parsedEffectLayer.customType);\n return effectLayerType.Parse(parsedEffectLayer, scene, rootUrl);\n }\n }\n /**\n * @internal\n */\n EffectLayer._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"EffectLayerSceneComponent\");\n };\n __decorate$1([\n serialize()\n ], EffectLayer.prototype, \"name\", void 0);\n __decorate$1([\n serializeAsColor4()\n ], EffectLayer.prototype, \"neutralColor\", void 0);\n __decorate$1([\n serialize()\n ], EffectLayer.prototype, \"isEnabled\", void 0);\n __decorate$1([\n serializeAsCameraReference()\n ], EffectLayer.prototype, \"camera\", null);\n __decorate$1([\n serialize()\n ], EffectLayer.prototype, \"renderingGroupId\", null);\n __decorate$1([\n serialize()\n ], EffectLayer.prototype, \"disableBoundingBoxesFromEffectLayer\", void 0);\n\n // Adds the parser to the scene parsers.\n AbstractScene.AddParser(SceneComponentConstants.NAME_EFFECTLAYER, (parsedData, scene, container, rootUrl) => {\n if (parsedData.effectLayers) {\n if (!container.effectLayers) {\n container.effectLayers = new Array();\n }\n for (let index = 0; index < parsedData.effectLayers.length; index++) {\n const effectLayer = EffectLayer.Parse(parsedData.effectLayers[index], scene, rootUrl);\n container.effectLayers.push(effectLayer);\n }\n }\n });\n AbstractScene.prototype.removeEffectLayer = function (toRemove) {\n const index = this.effectLayers.indexOf(toRemove);\n if (index !== -1) {\n this.effectLayers.splice(index, 1);\n }\n return index;\n };\n AbstractScene.prototype.addEffectLayer = function (newEffectLayer) {\n this.effectLayers.push(newEffectLayer);\n };\n /**\n * Defines the layer scene component responsible to manage any effect layers\n * in a given scene.\n */\n class EffectLayerSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_EFFECTLAYER;\n this._renderEffects = false;\n this._needStencil = false;\n this._previousStencilState = false;\n this.scene = scene || EngineStore.LastCreatedScene;\n if (!this.scene) {\n return;\n }\n this._engine = this.scene.getEngine();\n this.scene.effectLayers = new Array();\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._isReadyForMeshStage.registerStep(SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER, this, this._isReadyForMesh);\n this.scene._cameraDrawRenderTargetStage.registerStep(SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER, this, this._renderMainTexture);\n this.scene._beforeCameraDrawStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER, this, this._setStencil);\n this.scene._afterRenderingGroupDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW, this, this._drawRenderingGroup);\n this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER, this, this._setStencilBack);\n this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW, this, this._drawCamera);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n const layers = this.scene.effectLayers;\n for (const effectLayer of layers) {\n effectLayer._rebuild();\n }\n }\n /**\n * Serializes the component data to the specified json object\n * @param serializationObject The object to serialize to\n */\n serialize(serializationObject) {\n // Effect layers\n serializationObject.effectLayers = [];\n const layers = this.scene.effectLayers;\n for (const effectLayer of layers) {\n if (effectLayer.serialize) {\n serializationObject.effectLayers.push(effectLayer.serialize());\n }\n }\n }\n /**\n * Adds all the elements from the container to the scene\n * @param container the container holding the elements\n */\n addFromContainer(container) {\n if (!container.effectLayers) {\n return;\n }\n container.effectLayers.forEach((o) => {\n this.scene.addEffectLayer(o);\n });\n }\n /**\n * Removes all the elements in the container from the scene\n * @param container contains the elements to remove\n * @param dispose if the removed element should be disposed (default: false)\n */\n removeFromContainer(container, dispose) {\n if (!container.effectLayers) {\n return;\n }\n container.effectLayers.forEach((o) => {\n this.scene.removeEffectLayer(o);\n if (dispose) {\n o.dispose();\n }\n });\n }\n /**\n * Disposes the component and the associated resources.\n */\n dispose() {\n const layers = this.scene.effectLayers;\n while (layers.length) {\n layers[0].dispose();\n }\n }\n _isReadyForMesh(mesh, hardwareInstancedRendering) {\n const currentRenderPassId = this._engine.currentRenderPassId;\n const layers = this.scene.effectLayers;\n for (const layer of layers) {\n if (!layer.hasMesh(mesh)) {\n continue;\n }\n const renderTarget = layer._mainTexture;\n this._engine.currentRenderPassId = renderTarget.renderPassId;\n for (const subMesh of mesh.subMeshes) {\n if (!layer.isReady(subMesh, hardwareInstancedRendering)) {\n this._engine.currentRenderPassId = currentRenderPassId;\n return false;\n }\n }\n }\n this._engine.currentRenderPassId = currentRenderPassId;\n return true;\n }\n _renderMainTexture(camera) {\n this._renderEffects = false;\n this._needStencil = false;\n let needRebind = false;\n const layers = this.scene.effectLayers;\n if (layers && layers.length > 0) {\n this._previousStencilState = this._engine.getStencilBuffer();\n for (const effectLayer of layers) {\n if (effectLayer.shouldRender() &&\n (!effectLayer.camera ||\n (effectLayer.camera.cameraRigMode === Camera.RIG_MODE_NONE && camera === effectLayer.camera) ||\n (effectLayer.camera.cameraRigMode !== Camera.RIG_MODE_NONE && effectLayer.camera._rigCameras.indexOf(camera) > -1))) {\n this._renderEffects = true;\n this._needStencil = this._needStencil || effectLayer.needStencil();\n const renderTarget = effectLayer._mainTexture;\n if (renderTarget._shouldRender()) {\n this.scene.incrementRenderId();\n renderTarget.render(false, false);\n needRebind = true;\n }\n }\n }\n this.scene.incrementRenderId();\n }\n return needRebind;\n }\n _setStencil() {\n // Activate effect Layer stencil\n if (this._needStencil) {\n this._engine.setStencilBuffer(true);\n }\n }\n _setStencilBack() {\n // Restore effect Layer stencil\n if (this._needStencil) {\n this._engine.setStencilBuffer(this._previousStencilState);\n }\n }\n _draw(renderingGroupId) {\n if (this._renderEffects) {\n this._engine.setDepthBuffer(false);\n const layers = this.scene.effectLayers;\n for (let i = 0; i < layers.length; i++) {\n const effectLayer = layers[i];\n if (effectLayer.renderingGroupId === renderingGroupId) {\n if (effectLayer.shouldRender()) {\n effectLayer.render();\n }\n }\n }\n this._engine.setDepthBuffer(true);\n }\n }\n _drawCamera() {\n if (this._renderEffects) {\n this._draw(-1);\n }\n }\n _drawRenderingGroup(index) {\n if (!this.scene._isInIntermediateRendering() && this._renderEffects) {\n this._draw(index);\n }\n }\n }\n EffectLayer._SceneComponentInitialization = (scene) => {\n let component = scene._getComponent(SceneComponentConstants.NAME_EFFECTLAYER);\n if (!component) {\n component = new EffectLayerSceneComponent(scene);\n scene._addComponent(component);\n }\n };\n\n /**\n * Base implementation IShadowLight\n * It groups all the common behaviour in order to reduce duplication and better follow the DRY pattern.\n */\n class ShadowLight extends Light {\n constructor() {\n super(...arguments);\n this._needProjectionMatrixCompute = true;\n }\n _setPosition(value) {\n this._position = value;\n }\n /**\n * Sets the position the shadow will be casted from. Also use as the light position for both\n * point and spot lights.\n */\n get position() {\n return this._position;\n }\n /**\n * Sets the position the shadow will be casted from. Also use as the light position for both\n * point and spot lights.\n */\n set position(value) {\n this._setPosition(value);\n }\n _setDirection(value) {\n this._direction = value;\n }\n /**\n * In 2d mode (needCube being false), gets the direction used to cast the shadow.\n * Also use as the light direction on spot and directional lights.\n */\n get direction() {\n return this._direction;\n }\n /**\n * In 2d mode (needCube being false), sets the direction used to cast the shadow.\n * Also use as the light direction on spot and directional lights.\n */\n set direction(value) {\n this._setDirection(value);\n }\n /**\n * Gets the shadow projection clipping minimum z value.\n */\n get shadowMinZ() {\n return this._shadowMinZ;\n }\n /**\n * Sets the shadow projection clipping minimum z value.\n */\n set shadowMinZ(value) {\n this._shadowMinZ = value;\n this.forceProjectionMatrixCompute();\n }\n /**\n * Sets the shadow projection clipping maximum z value.\n */\n get shadowMaxZ() {\n return this._shadowMaxZ;\n }\n /**\n * Gets the shadow projection clipping maximum z value.\n */\n set shadowMaxZ(value) {\n this._shadowMaxZ = value;\n this.forceProjectionMatrixCompute();\n }\n /**\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\n * @returns true if the information has been computed, false if it does not need to (no parenting)\n */\n computeTransformedInformation() {\n if (this.parent && this.parent.getWorldMatrix) {\n if (!this.transformedPosition) {\n this.transformedPosition = Vector3.Zero();\n }\n Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);\n // In case the direction is present.\n if (this.direction) {\n if (!this.transformedDirection) {\n this.transformedDirection = Vector3.Zero();\n }\n Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this.transformedDirection);\n }\n return true;\n }\n return false;\n }\n /**\n * Return the depth scale used for the shadow map.\n * @returns the depth scale.\n */\n getDepthScale() {\n return 50.0;\n }\n /**\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\n * @param faceIndex The index of the face we are computed the direction to generate shadow\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getShadowDirection(faceIndex) {\n return this.transformedDirection ? this.transformedDirection : this.direction;\n }\n /**\n * Returns the ShadowLight absolute position in the World.\n * @returns the position vector in world space\n */\n getAbsolutePosition() {\n return this.transformedPosition ? this.transformedPosition : this.position;\n }\n /**\n * Sets the ShadowLight direction toward the passed target.\n * @param target The point to target in local space\n * @returns the updated ShadowLight direction\n */\n setDirectionToTarget(target) {\n this.direction = Vector3.Normalize(target.subtract(this.position));\n return this.direction;\n }\n /**\n * Returns the light rotation in euler definition.\n * @returns the x y z rotation in local space.\n */\n getRotation() {\n this.direction.normalize();\n const xaxis = Vector3.Cross(this.direction, Axis.Y);\n const yaxis = Vector3.Cross(xaxis, this.direction);\n return Vector3.RotationFromAxis(xaxis, yaxis, this.direction);\n }\n /**\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\n * @returns true if a cube texture needs to be use\n */\n needCube() {\n return false;\n }\n /**\n * Detects if the projection matrix requires to be recomputed this frame.\n * @returns true if it requires to be recomputed otherwise, false.\n */\n needProjectionMatrixCompute() {\n return this._needProjectionMatrixCompute;\n }\n /**\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\n */\n forceProjectionMatrixCompute() {\n this._needProjectionMatrixCompute = true;\n }\n /** @internal */\n _initCache() {\n super._initCache();\n this._cache.position = Vector3.Zero();\n }\n /** @internal */\n _isSynchronized() {\n if (!this._cache.position.equals(this.position)) {\n return false;\n }\n return true;\n }\n /**\n * Computes the world matrix of the node\n * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\n * @returns the world matrix\n */\n computeWorldMatrix(force) {\n if (!force && this.isSynchronized()) {\n this._currentRenderId = this.getScene().getRenderId();\n return this._worldMatrix;\n }\n this._updateCache();\n this._cache.position.copyFrom(this.position);\n if (!this._worldMatrix) {\n this._worldMatrix = Matrix.Identity();\n }\n Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);\n if (this.parent && this.parent.getWorldMatrix) {\n this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);\n this._markSyncedWithParent();\n }\n // Cache the determinant\n this._worldMatrixDeterminantIsDirty = true;\n return this._worldMatrix;\n }\n /**\n * Gets the minZ used for shadow according to both the scene and the light.\n * @param activeCamera The camera we are returning the min for\n * @returns the depth min z\n */\n getDepthMinZ(activeCamera) {\n return this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\n }\n /**\n * Gets the maxZ used for shadow according to both the scene and the light.\n * @param activeCamera The camera we are returning the max for\n * @returns the depth max z\n */\n getDepthMaxZ(activeCamera) {\n return this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\n }\n /**\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\n * @param matrix The matrix to updated with the projection information\n * @param viewMatrix The transform matrix of the light\n * @param renderList The list of mesh to render in the map\n * @returns The current light\n */\n setShadowProjectionMatrix(matrix, viewMatrix, renderList) {\n if (this.customProjectionMatrixBuilder) {\n this.customProjectionMatrixBuilder(viewMatrix, renderList, matrix);\n }\n else {\n this._setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList);\n }\n return this;\n }\n /** @internal */\n _syncParentEnabledState() {\n super._syncParentEnabledState();\n if (!this.parent || !this.parent.getWorldMatrix) {\n this.transformedPosition = null;\n this.transformedDirection = null;\n }\n }\n }\n __decorate$1([\n serializeAsVector3()\n ], ShadowLight.prototype, \"position\", null);\n __decorate$1([\n serializeAsVector3()\n ], ShadowLight.prototype, \"direction\", null);\n __decorate$1([\n serialize()\n ], ShadowLight.prototype, \"shadowMinZ\", null);\n __decorate$1([\n serialize()\n ], ShadowLight.prototype, \"shadowMaxZ\", null);\n\n // Do not edit.\n const name$20 = \"bayerDitherFunctions\";\n const shader$20 = `float bayerDither2(vec2 _P) {return mod(2.0*_P.y+_P.x+1.0,4.0);}\nfloat bayerDither4(vec2 _P) {vec2 P1=mod(_P,2.0); \nvec2 P2=floor(0.5*mod(_P,4.0)); \nreturn 4.0*bayerDither2(P1)+bayerDither2(P2);}\nfloat bayerDither8(vec2 _P) {vec2 P1=mod(_P,2.0); \nvec2 P2=floor(0.5 *mod(_P,4.0)); \nvec2 P4=floor(0.25*mod(_P,8.0)); \nreturn 4.0*(4.0*bayerDither2(P1)+bayerDither2(P2))+bayerDither2(P4);}\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$20] = shader$20;\n\n // Do not edit.\n const name$21 = \"shadowMapFragmentExtraDeclaration\";\n const shader$21 = `#if SM_FLOAT==0\n#include\n#endif\n#if SM_SOFTTRANSPARENTSHADOW==1\n#include\nuniform float softTransparentShadowSM;\n#endif\nvarying float vDepthMetricSM;\n#if SM_USEDISTANCE==1\nuniform vec3 lightDataSM;varying vec3 vPositionWSM;\n#endif\nuniform vec3 biasAndScaleSM;uniform vec2 depthValuesSM;\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\nvarying float zSM;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$21] = shader$21;\n\n // Do not edit.\n const name$22 = \"shadowMapFragment\";\n const shader$22 = `float depthSM=vDepthMetricSM;\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\n#if SM_USEDISTANCE==1\ndepthSM=(length(vPositionWSM-lightDataSM)+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#else\n#ifdef USE_REVERSE_DEPTHBUFFER\ndepthSM=(-zSM+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#else\ndepthSM=(zSM+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#endif\n#endif\n#ifdef USE_REVERSE_DEPTHBUFFER\ngl_FragDepth=clamp(1.0-depthSM,0.0,1.0);\n#else\ngl_FragDepth=clamp(depthSM,0.0,1.0); \n#endif\n#elif SM_USEDISTANCE==1\ndepthSM=(length(vPositionWSM-lightDataSM)+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#endif\n#if SM_ESM==1\ndepthSM=clamp(exp(-min(87.,biasAndScaleSM.z*depthSM)),0.,1.);\n#endif\n#if SM_FLOAT==1\ngl_FragColor=vec4(depthSM,1.0,1.0,1.0);\n#else\ngl_FragColor=pack(depthSM);\n#endif\nreturn;`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$22] = shader$22;\n\n // Do not edit.\n const name$23 = \"shadowMapPixelShader\";\n const shader$23 = `#include\n#ifdef ALPHATEXTURE\nvarying vec2 vUV;uniform sampler2D diffuseSampler;\n#endif\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#include\n#ifdef ALPHATEXTURE\nfloat alphaFromAlphaTexture=texture2D(diffuseSampler,vUV).a;\n#ifdef ALPHATESTVALUE\nif (alphaFromAlphaTexture=softTransparentShadowSM*alphaFromAlphaTexture) discard;\n#else\nif ((bayerDither8(floor(mod(gl_FragCoord.xy,8.0))))/64.0>=softTransparentShadowSM) discard;\n#endif\n#endif\n#include\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$23] = shader$23;\n\n // Do not edit.\n const name$24 = \"sceneVertexDeclaration\";\n const shader$24 = `uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\nuniform mat4 view;uniform mat4 projection;uniform vec4 vEyePosition;\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$24] = shader$24;\n\n // Do not edit.\n const name$25 = \"meshVertexDeclaration\";\n const shader$25 = `uniform mat4 world;uniform float visibility;\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$25] = shader$25;\n\n // Do not edit.\n const name$26 = \"shadowMapVertexDeclaration\";\n const shader$26 = `#include\n#include\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$26] = shader$26;\n\n // Do not edit.\n const name$27 = \"shadowMapUboDeclaration\";\n const shader$27 = `layout(std140,column_major) uniform;\n#include\n#include\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$27] = shader$27;\n\n // Do not edit.\n const name$28 = \"shadowMapVertexExtraDeclaration\";\n const shader$28 = `#if SM_NORMALBIAS==1\nuniform vec3 lightDataSM;\n#endif\nuniform vec3 biasAndScaleSM;uniform vec2 depthValuesSM;varying float vDepthMetricSM;\n#if SM_USEDISTANCE==1\nvarying vec3 vPositionWSM;\n#endif\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\nvarying float zSM;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$28] = shader$28;\n\n // Do not edit.\n const name$29 = \"shadowMapVertexNormalBias\";\n const shader$29 = `#if SM_NORMALBIAS==1\n#if SM_DIRECTIONINLIGHTDATA==1\nvec3 worldLightDirSM=normalize(-lightDataSM.xyz);\n#else\nvec3 directionToLightSM=lightDataSM.xyz-worldPos.xyz;vec3 worldLightDirSM=normalize(directionToLightSM);\n#endif\nfloat ndlSM=dot(vNormalW,worldLightDirSM);float sinNLSM=sqrt(1.0-ndlSM*ndlSM);float normalBiasSM=biasAndScaleSM.y*sinNLSM;worldPos.xyz-=vNormalW*normalBiasSM;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$29] = shader$29;\n\n // Do not edit.\n const name$2a = \"shadowMapVertexMetric\";\n const shader$2a = `#if SM_USEDISTANCE==1\nvPositionWSM=worldPos.xyz;\n#endif\n#if SM_DEPTHTEXTURE==1\n#ifdef IS_NDC_HALF_ZRANGE\n#define BIASFACTOR 0.5\n#else\n#define BIASFACTOR 1.0\n#endif\n#ifdef USE_REVERSE_DEPTHBUFFER\ngl_Position.z-=biasAndScaleSM.x*gl_Position.w*BIASFACTOR;\n#else\ngl_Position.z+=biasAndScaleSM.x*gl_Position.w*BIASFACTOR;\n#endif\n#endif\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\nzSM=gl_Position.z;gl_Position.z=0.0;\n#elif SM_USEDISTANCE==0\n#ifdef USE_REVERSE_DEPTHBUFFER\nvDepthMetricSM=(-gl_Position.z+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#else\nvDepthMetricSM=(gl_Position.z+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#endif\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2a] = shader$2a;\n\n // Do not edit.\n const name$2b = \"shadowMapVertexShader\";\n const shader$2b = `attribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef INSTANCES\nattribute vec4 world0;attribute vec4 world1;attribute vec4 world2;attribute vec4 world3;\n#endif\n#include\n#include<__decl__shadowMapVertex>\n#ifdef ALPHATEXTURE\nvarying vec2 vUV;uniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#ifdef NORMAL\nmat3 normWorldSM=mat3(finalWorld);\n#if defined(INSTANCES) && defined(THIN_INSTANCES)\nvec3 vNormalW=normalUpdated/vec3(dot(normWorldSM[0],normWorldSM[0]),dot(normWorldSM[1],normWorldSM[1]),dot(normWorldSM[2],normWorldSM[2]));vNormalW=normalize(normWorldSM*vNormalW);\n#else\n#ifdef NONUNIFORMSCALING\nnormWorldSM=transposeMat3(inverseMat3(normWorldSM));\n#endif\nvec3 vNormalW=normalize(normWorldSM*normalUpdated);\n#endif\n#endif\n#include\ngl_Position=viewProjection*worldPos;\n#include\n#ifdef ALPHATEXTURE\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2b] = shader$2b;\n\n // Do not edit.\n const name$2c = \"depthBoxBlurPixelShader\";\n const shader$2c = `varying vec2 vUV;uniform sampler2D textureSampler;uniform vec2 screenSize;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec4 colorDepth=vec4(0.0);for (int x=-OFFSET; x<=OFFSET; x++)\nfor (int y=-OFFSET; y<=OFFSET; y++)\ncolorDepth+=texture2D(textureSampler,vUV+vec2(x,y)/screenSize);gl_FragColor=(colorDepth/float((OFFSET*2+1)*(OFFSET*2+1)));}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2c] = shader$2c;\n\n // Do not edit.\n const name$2d = \"shadowMapFragmentSoftTransparentShadow\";\n const shader$2d = `#if SM_SOFTTRANSPARENTSHADOW==1\nif ((bayerDither8(floor(mod(gl_FragCoord.xy,8.0))))/64.0>=softTransparentShadowSM*alpha) discard;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2d] = shader$2d;\n\n /**\n * Default implementation IShadowGenerator.\n * This is the main object responsible of generating shadows in the framework.\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\n */\n class ShadowGenerator {\n /**\n * Gets the bias: offset applied on the depth preventing acnea (in light direction).\n */\n get bias() {\n return this._bias;\n }\n /**\n * Sets the bias: offset applied on the depth preventing acnea (in light direction).\n */\n set bias(bias) {\n this._bias = bias;\n }\n /**\n * Gets the normalBias: offset applied on the depth preventing acnea (along side the normal direction and proportional to the light/normal angle).\n */\n get normalBias() {\n return this._normalBias;\n }\n /**\n * Sets the normalBias: offset applied on the depth preventing acnea (along side the normal direction and proportional to the light/normal angle).\n */\n set normalBias(normalBias) {\n this._normalBias = normalBias;\n }\n /**\n * Gets the blur box offset: offset applied during the blur pass.\n * Only useful if useKernelBlur = false\n */\n get blurBoxOffset() {\n return this._blurBoxOffset;\n }\n /**\n * Sets the blur box offset: offset applied during the blur pass.\n * Only useful if useKernelBlur = false\n */\n set blurBoxOffset(value) {\n if (this._blurBoxOffset === value) {\n return;\n }\n this._blurBoxOffset = value;\n this._disposeBlurPostProcesses();\n }\n /**\n * Gets the blur scale: scale of the blurred texture compared to the main shadow map.\n * 2 means half of the size.\n */\n get blurScale() {\n return this._blurScale;\n }\n /**\n * Sets the blur scale: scale of the blurred texture compared to the main shadow map.\n * 2 means half of the size.\n */\n set blurScale(value) {\n if (this._blurScale === value) {\n return;\n }\n this._blurScale = value;\n this._disposeBlurPostProcesses();\n }\n /**\n * Gets the blur kernel: kernel size of the blur pass.\n * Only useful if useKernelBlur = true\n */\n get blurKernel() {\n return this._blurKernel;\n }\n /**\n * Sets the blur kernel: kernel size of the blur pass.\n * Only useful if useKernelBlur = true\n */\n set blurKernel(value) {\n if (this._blurKernel === value) {\n return;\n }\n this._blurKernel = value;\n this._disposeBlurPostProcesses();\n }\n /**\n * Gets whether the blur pass is a kernel blur (if true) or box blur.\n * Only useful in filtered mode (useBlurExponentialShadowMap...)\n */\n get useKernelBlur() {\n return this._useKernelBlur;\n }\n /**\n * Sets whether the blur pass is a kernel blur (if true) or box blur.\n * Only useful in filtered mode (useBlurExponentialShadowMap...)\n */\n set useKernelBlur(value) {\n if (this._useKernelBlur === value) {\n return;\n }\n this._useKernelBlur = value;\n this._disposeBlurPostProcesses();\n }\n /**\n * Gets the depth scale used in ESM mode.\n */\n get depthScale() {\n return this._depthScale !== undefined ? this._depthScale : this._light.getDepthScale();\n }\n /**\n * Sets the depth scale used in ESM mode.\n * This can override the scale stored on the light.\n */\n set depthScale(value) {\n this._depthScale = value;\n }\n _validateFilter(filter) {\n return filter;\n }\n /**\n * Gets the current mode of the shadow generator (normal, PCF, ESM...).\n * The returned value is a number equal to one of the available mode defined in ShadowMap.FILTER_x like _FILTER_NONE\n */\n get filter() {\n return this._filter;\n }\n /**\n * Sets the current mode of the shadow generator (normal, PCF, ESM...).\n * The returned value is a number equal to one of the available mode defined in ShadowMap.FILTER_x like _FILTER_NONE\n */\n set filter(value) {\n value = this._validateFilter(value);\n // Blurring the cubemap is going to be too expensive. Reverting to unblurred version\n if (this._light.needCube()) {\n if (value === ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP) {\n this.useExponentialShadowMap = true;\n return;\n }\n else if (value === ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP) {\n this.useCloseExponentialShadowMap = true;\n return;\n }\n // PCF on cubemap would also be expensive\n else if (value === ShadowGenerator.FILTER_PCF || value === ShadowGenerator.FILTER_PCSS) {\n this.usePoissonSampling = true;\n return;\n }\n }\n // Weblg1 fallback for PCF.\n if (value === ShadowGenerator.FILTER_PCF || value === ShadowGenerator.FILTER_PCSS) {\n if (!this._scene.getEngine()._features.supportShadowSamplers) {\n this.usePoissonSampling = true;\n return;\n }\n }\n if (this._filter === value) {\n return;\n }\n this._filter = value;\n this._disposeBlurPostProcesses();\n this._applyFilterValues();\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets if the current filter is set to Poisson Sampling.\n */\n get usePoissonSampling() {\n return this.filter === ShadowGenerator.FILTER_POISSONSAMPLING;\n }\n /**\n * Sets the current filter to Poisson Sampling.\n */\n set usePoissonSampling(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_POISSONSAMPLING);\n if (!value && this.filter !== ShadowGenerator.FILTER_POISSONSAMPLING) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets if the current filter is set to ESM.\n */\n get useExponentialShadowMap() {\n return this.filter === ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP;\n }\n /**\n * Sets the current filter is to ESM.\n */\n set useExponentialShadowMap(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP);\n if (!value && this.filter !== ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets if the current filter is set to filtered ESM.\n */\n get useBlurExponentialShadowMap() {\n return this.filter === ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP;\n }\n /**\n * Gets if the current filter is set to filtered ESM.\n */\n set useBlurExponentialShadowMap(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP);\n if (!value && this.filter !== ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets if the current filter is set to \"close ESM\" (using the inverse of the\n * exponential to prevent steep falloff artifacts).\n */\n get useCloseExponentialShadowMap() {\n return this.filter === ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP;\n }\n /**\n * Sets the current filter to \"close ESM\" (using the inverse of the\n * exponential to prevent steep falloff artifacts).\n */\n set useCloseExponentialShadowMap(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP);\n if (!value && this.filter !== ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets if the current filter is set to filtered \"close ESM\" (using the inverse of the\n * exponential to prevent steep falloff artifacts).\n */\n get useBlurCloseExponentialShadowMap() {\n return this.filter === ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP;\n }\n /**\n * Sets the current filter to filtered \"close ESM\" (using the inverse of the\n * exponential to prevent steep falloff artifacts).\n */\n set useBlurCloseExponentialShadowMap(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP);\n if (!value && this.filter !== ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets if the current filter is set to \"PCF\" (percentage closer filtering).\n */\n get usePercentageCloserFiltering() {\n return this.filter === ShadowGenerator.FILTER_PCF;\n }\n /**\n * Sets the current filter to \"PCF\" (percentage closer filtering).\n */\n set usePercentageCloserFiltering(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_PCF);\n if (!value && this.filter !== ShadowGenerator.FILTER_PCF) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets the PCF or PCSS Quality.\n * Only valid if usePercentageCloserFiltering or usePercentageCloserFiltering is true.\n */\n get filteringQuality() {\n return this._filteringQuality;\n }\n /**\n * Sets the PCF or PCSS Quality.\n * Only valid if usePercentageCloserFiltering or usePercentageCloserFiltering is true.\n */\n set filteringQuality(filteringQuality) {\n if (this._filteringQuality === filteringQuality) {\n return;\n }\n this._filteringQuality = filteringQuality;\n this._disposeBlurPostProcesses();\n this._applyFilterValues();\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets if the current filter is set to \"PCSS\" (contact hardening).\n */\n get useContactHardeningShadow() {\n return this.filter === ShadowGenerator.FILTER_PCSS;\n }\n /**\n * Sets the current filter to \"PCSS\" (contact hardening).\n */\n set useContactHardeningShadow(value) {\n const filter = this._validateFilter(ShadowGenerator.FILTER_PCSS);\n if (!value && this.filter !== ShadowGenerator.FILTER_PCSS) {\n return;\n }\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets the Light Size (in shadow map uv unit) used in PCSS to determine the blocker search area and the penumbra size.\n * Using a ratio helps keeping shape stability independently of the map size.\n *\n * It does not account for the light projection as it was having too much\n * instability during the light setup or during light position changes.\n *\n * Only valid if useContactHardeningShadow is true.\n */\n get contactHardeningLightSizeUVRatio() {\n return this._contactHardeningLightSizeUVRatio;\n }\n /**\n * Sets the Light Size (in shadow map uv unit) used in PCSS to determine the blocker search area and the penumbra size.\n * Using a ratio helps keeping shape stability independently of the map size.\n *\n * It does not account for the light projection as it was having too much\n * instability during the light setup or during light position changes.\n *\n * Only valid if useContactHardeningShadow is true.\n */\n set contactHardeningLightSizeUVRatio(contactHardeningLightSizeUVRatio) {\n this._contactHardeningLightSizeUVRatio = contactHardeningLightSizeUVRatio;\n }\n /** Gets or sets the actual darkness of a shadow */\n get darkness() {\n return this._darkness;\n }\n set darkness(value) {\n this.setDarkness(value);\n }\n /**\n * Returns the darkness value (float). This can only decrease the actual darkness of a shadow.\n * 0 means strongest and 1 would means no shadow.\n * @returns the darkness.\n */\n getDarkness() {\n return this._darkness;\n }\n /**\n * Sets the darkness value (float). This can only decrease the actual darkness of a shadow.\n * @param darkness The darkness value 0 means strongest and 1 would means no shadow.\n * @returns the shadow generator allowing fluent coding.\n */\n setDarkness(darkness) {\n if (darkness >= 1.0) {\n this._darkness = 1.0;\n }\n else if (darkness <= 0.0) {\n this._darkness = 0.0;\n }\n else {\n this._darkness = darkness;\n }\n return this;\n }\n /** Gets or sets the ability to have transparent shadow */\n get transparencyShadow() {\n return this._transparencyShadow;\n }\n set transparencyShadow(value) {\n this.setTransparencyShadow(value);\n }\n /**\n * Sets the ability to have transparent shadow (boolean).\n * @param transparent True if transparent else False\n * @returns the shadow generator allowing fluent coding\n */\n setTransparencyShadow(transparent) {\n this._transparencyShadow = transparent;\n return this;\n }\n /**\n * Gets the main RTT containing the shadow map (usually storing depth from the light point of view).\n * @returns The render target texture if present otherwise, null\n */\n getShadowMap() {\n return this._shadowMap;\n }\n /**\n * Gets the RTT used during rendering (can be a blurred version of the shadow map or the shadow map itself).\n * @returns The render target texture if the shadow map is present otherwise, null\n */\n getShadowMapForRendering() {\n if (this._shadowMap2) {\n return this._shadowMap2;\n }\n return this._shadowMap;\n }\n /**\n * Gets the class name of that object\n * @returns \"ShadowGenerator\"\n */\n getClassName() {\n return ShadowGenerator.CLASSNAME;\n }\n /**\n * Helper function to add a mesh and its descendants to the list of shadow casters.\n * @param mesh Mesh to add\n * @param includeDescendants boolean indicating if the descendants should be added. Default to true\n * @returns the Shadow Generator itself\n */\n addShadowCaster(mesh, includeDescendants = true) {\n if (!this._shadowMap) {\n return this;\n }\n if (!this._shadowMap.renderList) {\n this._shadowMap.renderList = [];\n }\n if (this._shadowMap.renderList.indexOf(mesh) === -1) {\n this._shadowMap.renderList.push(mesh);\n }\n if (includeDescendants) {\n for (const childMesh of mesh.getChildMeshes()) {\n if (this._shadowMap.renderList.indexOf(childMesh) === -1) {\n this._shadowMap.renderList.push(childMesh);\n }\n }\n }\n return this;\n }\n /**\n * Helper function to remove a mesh and its descendants from the list of shadow casters\n * @param mesh Mesh to remove\n * @param includeDescendants boolean indicating if the descendants should be removed. Default to true\n * @returns the Shadow Generator itself\n */\n removeShadowCaster(mesh, includeDescendants = true) {\n if (!this._shadowMap || !this._shadowMap.renderList) {\n return this;\n }\n const index = this._shadowMap.renderList.indexOf(mesh);\n if (index !== -1) {\n this._shadowMap.renderList.splice(index, 1);\n }\n if (includeDescendants) {\n for (const child of mesh.getChildren()) {\n this.removeShadowCaster(child);\n }\n }\n return this;\n }\n /**\n * Returns the associated light object.\n * @returns the light generating the shadow\n */\n getLight() {\n return this._light;\n }\n _getCamera() {\n var _a;\n return (_a = this._camera) !== null && _a !== void 0 ? _a : this._scene.activeCamera;\n }\n /**\n * Gets or sets the size of the texture what stores the shadows\n */\n get mapSize() {\n return this._mapSize;\n }\n set mapSize(size) {\n this._mapSize = size;\n this._light._markMeshesAsLightDirty();\n this.recreateShadowMap();\n }\n /**\n * Creates a ShadowGenerator object.\n * A ShadowGenerator is the required tool to use the shadows.\n * Each light casting shadows needs to use its own ShadowGenerator.\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\n * @param mapSize The size of the texture what stores the shadows. Example : 1024.\n * @param light The light object generating the shadows.\n * @param usefullFloatFirst By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.\n * @param camera Camera associated with this shadow generator (default: null). If null, takes the scene active camera at the time we need to access it\n * @param useRedTextureType Forces the generator to use a Red instead of a RGBA type for the shadow map texture format (default: false)\n */\n constructor(mapSize, light, usefullFloatFirst, camera, useRedTextureType) {\n /**\n * Observable triggered before the shadow is rendered. Can be used to update internal effect state\n */\n this.onBeforeShadowMapRenderObservable = new Observable$1();\n /**\n * Observable triggered after the shadow is rendered. Can be used to restore internal effect state\n */\n this.onAfterShadowMapRenderObservable = new Observable$1();\n /**\n * Observable triggered before a mesh is rendered in the shadow map.\n * Can be used to update internal effect state (that you can get from the onBeforeShadowMapRenderObservable)\n */\n this.onBeforeShadowMapRenderMeshObservable = new Observable$1();\n /**\n * Observable triggered after a mesh is rendered in the shadow map.\n * Can be used to update internal effect state (that you can get from the onAfterShadowMapRenderObservable)\n */\n this.onAfterShadowMapRenderMeshObservable = new Observable$1();\n this._bias = 0.00005;\n this._normalBias = 0;\n this._blurBoxOffset = 1;\n this._blurScale = 2;\n this._blurKernel = 1;\n this._useKernelBlur = false;\n this._filter = ShadowGenerator.FILTER_NONE;\n this._filteringQuality = ShadowGenerator.QUALITY_HIGH;\n this._contactHardeningLightSizeUVRatio = 0.1;\n this._darkness = 0;\n this._transparencyShadow = false;\n /**\n * Enables or disables shadows with varying strength based on the transparency\n * When it is enabled, the strength of the shadow is taken equal to mesh.visibility\n * If you enabled an alpha texture on your material, the alpha value red from the texture is also combined to compute the strength:\n * mesh.visibility * alphaTexture.a\n * The texture used is the diffuse by default, but it can be set to the opacity by setting useOpacityTextureForTransparentShadow\n * Note that by definition transparencyShadow must be set to true for enableSoftTransparentShadow to work!\n */\n this.enableSoftTransparentShadow = false;\n /**\n * If this is true, use the opacity texture's alpha channel for transparent shadows instead of the diffuse one\n */\n this.useOpacityTextureForTransparentShadow = false;\n /**\n * Controls the extent to which the shadows fade out at the edge of the frustum\n */\n this.frustumEdgeFalloff = 0;\n /**\n * If true the shadow map is generated by rendering the back face of the mesh instead of the front face.\n * This can help with self-shadowing as the geometry making up the back of objects is slightly offset.\n * It might on the other hand introduce peter panning.\n */\n this.forceBackFacesOnly = false;\n this._lightDirection = Vector3.Zero();\n this._viewMatrix = Matrix.Zero();\n this._projectionMatrix = Matrix.Zero();\n this._transformMatrix = Matrix.Zero();\n this._cachedPosition = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cachedDirection = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._currentFaceIndex = 0;\n this._currentFaceIndexCache = 0;\n this._defaultTextureMatrix = Matrix.Identity();\n this._mapSize = mapSize;\n this._light = light;\n this._scene = light.getScene();\n this._camera = camera !== null && camera !== void 0 ? camera : null;\n this._useRedTextureType = !!useRedTextureType;\n let shadowGenerators = light._shadowGenerators;\n if (!shadowGenerators) {\n shadowGenerators = light._shadowGenerators = new Map();\n }\n shadowGenerators.set(this._camera, this);\n this.id = light.id;\n this._useUBO = this._scene.getEngine().supportsUniformBuffers;\n if (this._useUBO) {\n this._sceneUBOs = [];\n this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for Shadow Generator (light \"${this._light.name}\")`));\n }\n ShadowGenerator._SceneComponentInitialization(this._scene);\n // Texture type fallback from float to int if not supported.\n const caps = this._scene.getEngine().getCaps();\n if (!usefullFloatFirst) {\n if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\n this._textureType = 2;\n }\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\n this._textureType = 1;\n }\n else {\n this._textureType = 0;\n }\n }\n else {\n if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\n this._textureType = 1;\n }\n else if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\n this._textureType = 2;\n }\n else {\n this._textureType = 0;\n }\n }\n this._initializeGenerator();\n this._applyFilterValues();\n }\n _initializeGenerator() {\n this._light._markMeshesAsLightDirty();\n this._initializeShadowMap();\n }\n _createTargetRenderTexture() {\n const engine = this._scene.getEngine();\n if (engine._features.supportDepthStencilTexture) {\n this._shadowMap = new RenderTargetTexture(this._light.name + \"_shadowMap\", this._mapSize, this._scene, false, true, this._textureType, this._light.needCube(), undefined, false, false, undefined, this._useRedTextureType ? 6 : 5);\n this._shadowMap.createDepthStencilTexture(engine.useReverseDepthBuffer ? 516 : 513, true);\n }\n else {\n this._shadowMap = new RenderTargetTexture(this._light.name + \"_shadowMap\", this._mapSize, this._scene, false, true, this._textureType, this._light.needCube());\n }\n this._shadowMap.noPrePassRenderer = true;\n }\n _initializeShadowMap() {\n this._createTargetRenderTexture();\n if (this._shadowMap === null) {\n return;\n }\n this._shadowMap.wrapU = Texture.CLAMP_ADDRESSMODE;\n this._shadowMap.wrapV = Texture.CLAMP_ADDRESSMODE;\n this._shadowMap.anisotropicFilteringLevel = 1;\n this._shadowMap.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\n this._shadowMap.renderParticles = false;\n this._shadowMap.ignoreCameraViewport = true;\n if (this._storedUniqueId) {\n this._shadowMap.uniqueId = this._storedUniqueId;\n }\n // Custom render function.\n this._shadowMap.customRenderFunction = this._renderForShadowMap.bind(this);\n // Force the mesh is ready function to true as we are double checking it\n // in the custom render function. Also it prevents side effects and useless\n // shader variations in DEPTHPREPASS mode.\n this._shadowMap.customIsReadyFunction = () => {\n return true;\n };\n const engine = this._scene.getEngine();\n this._shadowMap.onBeforeBindObservable.add(() => {\n var _a;\n this._currentSceneUBO = this._scene.getSceneUniformBuffer();\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, `shadow map generation for pass id ${engine.currentRenderPassId}`, 1);\n });\n // Record Face Index before render.\n this._shadowMap.onBeforeRenderObservable.add((faceIndex) => {\n if (this._sceneUBOs) {\n this._scene.setSceneUniformBuffer(this._sceneUBOs[0]);\n }\n this._currentFaceIndex = faceIndex;\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n engine.setColorWrite(false);\n }\n this.getTransformMatrix(); // generate the view/projection matrix\n this._scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);\n if (this._useUBO) {\n this._scene.getSceneUniformBuffer().unbindEffect();\n this._scene.finalizeSceneUbo();\n }\n });\n // Blur if required after render.\n this._shadowMap.onAfterUnbindObservable.add(() => {\n var _a, _b;\n if (this._sceneUBOs) {\n this._scene.setSceneUniformBuffer(this._currentSceneUBO);\n }\n this._scene.updateTransformMatrix(); // restore the view/projection matrices of the active camera\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n engine.setColorWrite(true);\n }\n if (!this.useBlurExponentialShadowMap && !this.useBlurCloseExponentialShadowMap) {\n (_a = engine._debugPopGroup) === null || _a === void 0 ? void 0 : _a.call(engine, 1);\n return;\n }\n const shadowMap = this.getShadowMapForRendering();\n if (shadowMap) {\n this._scene.postProcessManager.directRender(this._blurPostProcesses, shadowMap.renderTarget, true);\n engine.unBindFramebuffer(shadowMap.renderTarget, true);\n (_b = engine._debugPopGroup) === null || _b === void 0 ? void 0 : _b.call(engine, 1);\n }\n });\n // Clear according to the chosen filter.\n const clearZero = new Color4(0, 0, 0, 0);\n const clearOne = new Color4(1.0, 1.0, 1.0, 1.0);\n this._shadowMap.onClearObservable.add((engine) => {\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n engine.clear(clearOne, false, true, false);\n }\n else if (this.useExponentialShadowMap || this.useBlurExponentialShadowMap) {\n engine.clear(clearZero, true, true, false);\n }\n else {\n engine.clear(clearOne, true, true, false);\n }\n });\n // Recreate on resize.\n this._shadowMap.onResizeObservable.add((rtt) => {\n this._storedUniqueId = this._shadowMap.uniqueId;\n this._mapSize = rtt.getRenderSize();\n this._light._markMeshesAsLightDirty();\n this.recreateShadowMap();\n });\n // Ensures rendering groupids do not erase the depth buffer\n // or we would lose the shadows information.\n for (let i = RenderingManager.MIN_RENDERINGGROUPS; i < RenderingManager.MAX_RENDERINGGROUPS; i++) {\n this._shadowMap.setRenderingAutoClearDepthStencil(i, false);\n }\n }\n _initializeBlurRTTAndPostProcesses() {\n const engine = this._scene.getEngine();\n const targetSize = this._mapSize / this.blurScale;\n if (!this.useKernelBlur || this.blurScale !== 1.0) {\n this._shadowMap2 = new RenderTargetTexture(this._light.name + \"_shadowMap2\", targetSize, this._scene, false, true, this._textureType, undefined, undefined, false);\n this._shadowMap2.wrapU = Texture.CLAMP_ADDRESSMODE;\n this._shadowMap2.wrapV = Texture.CLAMP_ADDRESSMODE;\n this._shadowMap2.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\n }\n if (this.useKernelBlur) {\n this._kernelBlurXPostprocess = new BlurPostProcess(this._light.name + \"KernelBlurX\", new Vector2(1, 0), this.blurKernel, 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._textureType);\n this._kernelBlurXPostprocess.width = targetSize;\n this._kernelBlurXPostprocess.height = targetSize;\n this._kernelBlurXPostprocess.externalTextureSamplerBinding = true;\n this._kernelBlurXPostprocess.onApplyObservable.add((effect) => {\n effect.setTexture(\"textureSampler\", this._shadowMap);\n });\n this._kernelBlurYPostprocess = new BlurPostProcess(this._light.name + \"KernelBlurY\", new Vector2(0, 1), this.blurKernel, 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._textureType);\n this._kernelBlurXPostprocess.autoClear = false;\n this._kernelBlurYPostprocess.autoClear = false;\n if (this._textureType === 0) {\n this._kernelBlurXPostprocess.packedFloat = true;\n this._kernelBlurYPostprocess.packedFloat = true;\n }\n this._blurPostProcesses = [this._kernelBlurXPostprocess, this._kernelBlurYPostprocess];\n }\n else {\n this._boxBlurPostprocess = new PostProcess(this._light.name + \"DepthBoxBlur\", \"depthBoxBlur\", [\"screenSize\", \"boxOffset\"], [], 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, \"#define OFFSET \" + this._blurBoxOffset, this._textureType);\n this._boxBlurPostprocess.externalTextureSamplerBinding = true;\n this._boxBlurPostprocess.onApplyObservable.add((effect) => {\n effect.setFloat2(\"screenSize\", targetSize, targetSize);\n effect.setTexture(\"textureSampler\", this._shadowMap);\n });\n this._boxBlurPostprocess.autoClear = false;\n this._blurPostProcesses = [this._boxBlurPostprocess];\n }\n }\n _renderForShadowMap(opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) {\n let index;\n if (depthOnlySubMeshes.length) {\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\n this._renderSubMeshForShadowMap(depthOnlySubMeshes.data[index]);\n }\n }\n for (index = 0; index < opaqueSubMeshes.length; index++) {\n this._renderSubMeshForShadowMap(opaqueSubMeshes.data[index]);\n }\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\n this._renderSubMeshForShadowMap(alphaTestSubMeshes.data[index]);\n }\n if (this._transparencyShadow) {\n for (index = 0; index < transparentSubMeshes.length; index++) {\n this._renderSubMeshForShadowMap(transparentSubMeshes.data[index], true);\n }\n }\n else {\n for (index = 0; index < transparentSubMeshes.length; index++) {\n transparentSubMeshes.data[index].getEffectiveMesh()._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n }\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _bindCustomEffectForRenderSubMeshForShadowMap(subMesh, effect, mesh) {\n effect.setMatrix(\"viewProjection\", this.getTransformMatrix());\n }\n _renderSubMeshForShadowMap(subMesh, isTransparent = false) {\n var _a, _b;\n const renderingMesh = subMesh.getRenderingMesh();\n const effectiveMesh = subMesh.getEffectiveMesh();\n const scene = this._scene;\n const engine = scene.getEngine();\n const material = subMesh.getMaterial();\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n if (!material || subMesh.verticesCount === 0 || subMesh._renderId === scene.getRenderId()) {\n return;\n }\n // Culling\n const detNeg = effectiveMesh._getWorldMatrixDeterminant() < 0;\n let sideOrientation = (_a = renderingMesh.overrideMaterialSideOrientation) !== null && _a !== void 0 ? _a : material.sideOrientation;\n if (detNeg) {\n sideOrientation =\n sideOrientation === 0 ? 1 : 0;\n }\n const reverseSideOrientation = sideOrientation === 0;\n engine.setState(material.backFaceCulling, undefined, undefined, reverseSideOrientation, material.cullBackFaces);\n // Managing instances\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\n if (batch.mustReturn) {\n return;\n }\n const hardwareInstancedRendering = engine.getCaps().instancedArrays &&\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || renderingMesh.hasThinInstances);\n if (this.customAllowRendering && !this.customAllowRendering(subMesh)) {\n return;\n }\n if (this.isReady(subMesh, hardwareInstancedRendering, isTransparent)) {\n subMesh._renderId = scene.getRenderId();\n const shadowDepthWrapper = material.shadowDepthWrapper;\n const drawWrapper = (_b = shadowDepthWrapper === null || shadowDepthWrapper === void 0 ? void 0 : shadowDepthWrapper.getEffect(subMesh, this, engine.currentRenderPassId)) !== null && _b !== void 0 ? _b : subMesh._getDrawWrapper();\n const effect = DrawWrapper.GetEffect(drawWrapper);\n engine.enableEffect(drawWrapper);\n if (!hardwareInstancedRendering) {\n renderingMesh._bind(subMesh, effect, material.fillMode);\n }\n this.getTransformMatrix(); // make sure _cachedDirection et _cachedPosition are up to date\n effect.setFloat3(\"biasAndScaleSM\", this.bias, this.normalBias, this.depthScale);\n if (this.getLight().getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {\n effect.setVector3(\"lightDataSM\", this._cachedDirection);\n }\n else {\n effect.setVector3(\"lightDataSM\", this._cachedPosition);\n }\n const camera = this._getCamera();\n if (camera) {\n effect.setFloat2(\"depthValuesSM\", this.getLight().getDepthMinZ(camera), this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera));\n }\n if (isTransparent && this.enableSoftTransparentShadow) {\n effect.setFloat(\"softTransparentShadowSM\", effectiveMesh.visibility * material.alpha);\n }\n if (shadowDepthWrapper) {\n subMesh._setMainDrawWrapperOverride(drawWrapper);\n if (shadowDepthWrapper.standalone) {\n shadowDepthWrapper.baseMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);\n }\n else {\n material.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);\n }\n subMesh._setMainDrawWrapperOverride(null);\n }\n else {\n // Alpha test\n if (this._opacityTexture) {\n effect.setTexture(\"diffuseSampler\", this._opacityTexture);\n effect.setMatrix(\"diffuseMatrix\", this._opacityTexture.getTextureMatrix() || this._defaultTextureMatrix);\n }\n // Bones\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\n const skeleton = renderingMesh.skeleton;\n if (skeleton.isUsingTextureForMatrices) {\n const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);\n if (!boneTexture) {\n return;\n }\n effect.setTexture(\"boneSampler\", boneTexture);\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\n }\n else {\n effect.setMatrices(\"mBones\", skeleton.getTransformMatrices(renderingMesh));\n }\n }\n // Morph targets\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\n renderingMesh.morphTargetManager._bind(effect);\n }\n // Clip planes\n bindClipPlane(effect, material, scene);\n }\n if (!this._useUBO && !shadowDepthWrapper) {\n this._bindCustomEffectForRenderSubMeshForShadowMap(subMesh, effect, effectiveMesh);\n }\n MaterialHelper.BindSceneUniformBuffer(effect, this._scene.getSceneUniformBuffer());\n this._scene.getSceneUniformBuffer().bindUniformBuffer();\n const world = effectiveMesh.getWorldMatrix();\n // In the non hardware instanced mode, the Mesh ubo update is done by the callback passed to renderingMesh._processRendering (see below)\n if (hardwareInstancedRendering) {\n effectiveMesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\n effectiveMesh.transferToEffect(world);\n }\n if (this.forceBackFacesOnly) {\n engine.setState(true, 0, false, true, material.cullBackFaces);\n }\n // Observables\n this.onBeforeShadowMapRenderMeshObservable.notifyObservers(renderingMesh);\n this.onBeforeShadowMapRenderObservable.notifyObservers(effect);\n // Draw\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, worldOverride) => {\n if (effectiveMesh !== renderingMesh && !isInstance) {\n renderingMesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\n renderingMesh.transferToEffect(worldOverride);\n }\n else {\n effectiveMesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\n effectiveMesh.transferToEffect(isInstance ? worldOverride : world);\n }\n });\n if (this.forceBackFacesOnly) {\n engine.setState(true, 0, false, false, material.cullBackFaces);\n }\n // Observables\n this.onAfterShadowMapRenderObservable.notifyObservers(effect);\n this.onAfterShadowMapRenderMeshObservable.notifyObservers(renderingMesh);\n }\n else {\n // Need to reset refresh rate of the shadowMap\n if (this._shadowMap) {\n this._shadowMap.resetRefreshCounter();\n }\n }\n }\n _applyFilterValues() {\n if (!this._shadowMap) {\n return;\n }\n if (this.filter === ShadowGenerator.FILTER_NONE || this.filter === ShadowGenerator.FILTER_PCSS) {\n this._shadowMap.updateSamplingMode(Texture.NEAREST_SAMPLINGMODE);\n }\n else {\n this._shadowMap.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\n }\n }\n /**\n * Forces all the attached effect to compile to enable rendering only once ready vs. lazily compiling effects.\n * @param onCompiled Callback triggered at the and of the effects compilation\n * @param options Sets of optional options forcing the compilation with different modes\n */\n forceCompilation(onCompiled, options) {\n const localOptions = Object.assign({ useInstances: false }, options);\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n if (onCompiled) {\n onCompiled(this);\n }\n return;\n }\n const renderList = shadowMap.renderList;\n if (!renderList) {\n if (onCompiled) {\n onCompiled(this);\n }\n return;\n }\n const subMeshes = new Array();\n for (const mesh of renderList) {\n subMeshes.push(...mesh.subMeshes);\n }\n if (subMeshes.length === 0) {\n if (onCompiled) {\n onCompiled(this);\n }\n return;\n }\n let currentIndex = 0;\n const checkReady = () => {\n var _a, _b;\n if (!this._scene || !this._scene.getEngine()) {\n return;\n }\n while (this.isReady(subMeshes[currentIndex], localOptions.useInstances, (_b = (_a = subMeshes[currentIndex].getMaterial()) === null || _a === void 0 ? void 0 : _a.needAlphaBlendingForMesh(subMeshes[currentIndex].getMesh())) !== null && _b !== void 0 ? _b : false)) {\n currentIndex++;\n if (currentIndex >= subMeshes.length) {\n if (onCompiled) {\n onCompiled(this);\n }\n return;\n }\n }\n setTimeout(checkReady, 16);\n };\n checkReady();\n }\n /**\n * Forces all the attached effect to compile to enable rendering only once ready vs. lazily compiling effects.\n * @param options Sets of optional options forcing the compilation with different modes\n * @returns A promise that resolves when the compilation completes\n */\n forceCompilationAsync(options) {\n return new Promise((resolve) => {\n this.forceCompilation(() => {\n resolve();\n }, options);\n });\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _isReadyCustomDefines(defines, subMesh, useInstances) { }\n _prepareShadowDefines(subMesh, useInstances, defines, isTransparent) {\n defines.push(\"#define SM_LIGHTTYPE_\" + this._light.getClassName().toUpperCase());\n defines.push(\"#define SM_FLOAT \" + (this._textureType !== 0 ? \"1\" : \"0\"));\n defines.push(\"#define SM_ESM \" + (this.useExponentialShadowMap || this.useBlurExponentialShadowMap ? \"1\" : \"0\"));\n defines.push(\"#define SM_DEPTHTEXTURE \" + (this.usePercentageCloserFiltering || this.useContactHardeningShadow ? \"1\" : \"0\"));\n const mesh = subMesh.getMesh();\n // Normal bias.\n defines.push(\"#define SM_NORMALBIAS \" + (this.normalBias && mesh.isVerticesDataPresent(VertexBuffer.NormalKind) ? \"1\" : \"0\"));\n defines.push(\"#define SM_DIRECTIONINLIGHTDATA \" + (this.getLight().getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT ? \"1\" : \"0\"));\n // Point light\n defines.push(\"#define SM_USEDISTANCE \" + (this._light.needCube() ? \"1\" : \"0\"));\n // Soft transparent shadows\n defines.push(\"#define SM_SOFTTRANSPARENTSHADOW \" + (this.enableSoftTransparentShadow && isTransparent ? \"1\" : \"0\"));\n this._isReadyCustomDefines(defines, subMesh, useInstances);\n return defines;\n }\n /**\n * Determine whether the shadow generator is ready or not (mainly all effects and related post processes needs to be ready).\n * @param subMesh The submesh we want to render in the shadow map\n * @param useInstances Defines whether will draw in the map using instances\n * @param isTransparent Indicates that isReady is called for a transparent subMesh\n * @returns true if ready otherwise, false\n */\n isReady(subMesh, useInstances, isTransparent) {\n var _a;\n const material = subMesh.getMaterial(), shadowDepthWrapper = material === null || material === void 0 ? void 0 : material.shadowDepthWrapper;\n this._opacityTexture = null;\n if (!material) {\n return false;\n }\n const defines = [];\n this._prepareShadowDefines(subMesh, useInstances, defines, isTransparent);\n if (shadowDepthWrapper) {\n if (!shadowDepthWrapper.isReadyForSubMesh(subMesh, defines, this, useInstances, this._scene.getEngine().currentRenderPassId)) {\n return false;\n }\n }\n else {\n const subMeshEffect = subMesh._getDrawWrapper(undefined, true);\n let effect = subMeshEffect.effect;\n let cachedDefines = subMeshEffect.defines;\n const attribs = [VertexBuffer.PositionKind];\n const mesh = subMesh.getMesh();\n // Normal bias.\n if (this.normalBias && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n attribs.push(VertexBuffer.NormalKind);\n defines.push(\"#define NORMAL\");\n if (mesh.nonUniformScaling) {\n defines.push(\"#define NONUNIFORMSCALING\");\n }\n }\n // Alpha test\n const needAlphaTesting = material.needAlphaTesting();\n if (needAlphaTesting || material.needAlphaBlending()) {\n if (this.useOpacityTextureForTransparentShadow) {\n this._opacityTexture = material.opacityTexture;\n }\n else {\n this._opacityTexture = material.getAlphaTestTexture();\n }\n if (this._opacityTexture) {\n if (!this._opacityTexture.isReady()) {\n return false;\n }\n const alphaCutOff = (_a = material.alphaCutOff) !== null && _a !== void 0 ? _a : ShadowGenerator.DEFAULT_ALPHA_CUTOFF;\n defines.push(\"#define ALPHATEXTURE\");\n if (needAlphaTesting) {\n defines.push(`#define ALPHATESTVALUE ${alphaCutOff}${alphaCutOff % 1 === 0 ? \".\" : \"\"}`);\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n attribs.push(VertexBuffer.UVKind);\n defines.push(\"#define UV1\");\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\n if (this._opacityTexture.coordinatesIndex === 1) {\n attribs.push(VertexBuffer.UV2Kind);\n defines.push(\"#define UV2\");\n }\n }\n }\n }\n // Bones\n const fallbacks = new EffectFallbacks();\n if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (mesh.numBoneInfluencers > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n const skeleton = mesh.skeleton;\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\n if (mesh.numBoneInfluencers > 0) {\n fallbacks.addCPUSkinningFallback(0, mesh);\n }\n if (skeleton.isUsingTextureForMatrices) {\n defines.push(\"#define BONETEXTURE\");\n }\n else {\n defines.push(\"#define BonesPerMesh \" + (skeleton.bones.length + 1));\n }\n }\n else {\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\n }\n // Morph targets\n const manager = mesh.morphTargetManager;\n let morphInfluencers = 0;\n if (manager) {\n if (manager.numInfluencers > 0) {\n defines.push(\"#define MORPHTARGETS\");\n morphInfluencers = manager.numInfluencers;\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + morphInfluencers);\n if (manager.isUsingTextureForTargets) {\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\n }\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, morphInfluencers);\n }\n }\n // ClipPlanes\n prepareStringDefinesForClipPlanes(material, this._scene, defines);\n // Instances\n if (useInstances) {\n defines.push(\"#define INSTANCES\");\n MaterialHelper.PushAttributesForInstances(attribs);\n if (subMesh.getRenderingMesh().hasThinInstances) {\n defines.push(\"#define THIN_INSTANCES\");\n }\n }\n if (this.customShaderOptions) {\n if (this.customShaderOptions.defines) {\n for (const define of this.customShaderOptions.defines) {\n if (defines.indexOf(define) === -1) {\n defines.push(define);\n }\n }\n }\n }\n // Get correct effect\n const join = defines.join(\"\\n\");\n if (cachedDefines !== join) {\n cachedDefines = join;\n let shaderName = \"shadowMap\";\n const uniforms = [\n \"world\",\n \"mBones\",\n \"viewProjection\",\n \"diffuseMatrix\",\n \"lightDataSM\",\n \"depthValuesSM\",\n \"biasAndScaleSM\",\n \"morphTargetInfluences\",\n \"boneTextureWidth\",\n \"softTransparentShadowSM\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n ];\n const samplers = [\"diffuseSampler\", \"boneSampler\", \"morphTargets\"];\n const uniformBuffers = [\"Scene\", \"Mesh\"];\n addClipPlaneUniforms(uniforms);\n // Custom shader?\n if (this.customShaderOptions) {\n shaderName = this.customShaderOptions.shaderName;\n if (this.customShaderOptions.attributes) {\n for (const attrib of this.customShaderOptions.attributes) {\n if (attribs.indexOf(attrib) === -1) {\n attribs.push(attrib);\n }\n }\n }\n if (this.customShaderOptions.uniforms) {\n for (const uniform of this.customShaderOptions.uniforms) {\n if (uniforms.indexOf(uniform) === -1) {\n uniforms.push(uniform);\n }\n }\n }\n if (this.customShaderOptions.samplers) {\n for (const sampler of this.customShaderOptions.samplers) {\n if (samplers.indexOf(sampler) === -1) {\n samplers.push(sampler);\n }\n }\n }\n }\n const engine = this._scene.getEngine();\n effect = engine.createEffect(shaderName, {\n attributes: attribs,\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: join,\n fallbacks: fallbacks,\n onCompiled: null,\n onError: null,\n indexParameters: { maxSimultaneousMorphTargets: morphInfluencers },\n }, engine);\n subMeshEffect.setEffect(effect, cachedDefines);\n }\n if (!effect.isReady()) {\n return false;\n }\n }\n if (this.useBlurExponentialShadowMap || this.useBlurCloseExponentialShadowMap) {\n if (!this._blurPostProcesses || !this._blurPostProcesses.length) {\n this._initializeBlurRTTAndPostProcesses();\n }\n }\n if (this._kernelBlurXPostprocess && !this._kernelBlurXPostprocess.isReady()) {\n return false;\n }\n if (this._kernelBlurYPostprocess && !this._kernelBlurYPostprocess.isReady()) {\n return false;\n }\n if (this._boxBlurPostprocess && !this._boxBlurPostprocess.isReady()) {\n return false;\n }\n return true;\n }\n /**\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\n * @param defines Defines of the material we want to update\n * @param lightIndex Index of the light in the enabled light list of the material\n */\n prepareDefines(defines, lightIndex) {\n const scene = this._scene;\n const light = this._light;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n defines[\"SHADOW\" + lightIndex] = true;\n if (this.useContactHardeningShadow) {\n defines[\"SHADOWPCSS\" + lightIndex] = true;\n if (this._filteringQuality === ShadowGenerator.QUALITY_LOW) {\n defines[\"SHADOWLOWQUALITY\" + lightIndex] = true;\n }\n else if (this._filteringQuality === ShadowGenerator.QUALITY_MEDIUM) {\n defines[\"SHADOWMEDIUMQUALITY\" + lightIndex] = true;\n }\n // else default to high.\n }\n else if (this.usePercentageCloserFiltering) {\n defines[\"SHADOWPCF\" + lightIndex] = true;\n if (this._filteringQuality === ShadowGenerator.QUALITY_LOW) {\n defines[\"SHADOWLOWQUALITY\" + lightIndex] = true;\n }\n else if (this._filteringQuality === ShadowGenerator.QUALITY_MEDIUM) {\n defines[\"SHADOWMEDIUMQUALITY\" + lightIndex] = true;\n }\n // else default to high.\n }\n else if (this.usePoissonSampling) {\n defines[\"SHADOWPOISSON\" + lightIndex] = true;\n }\n else if (this.useExponentialShadowMap || this.useBlurExponentialShadowMap) {\n defines[\"SHADOWESM\" + lightIndex] = true;\n }\n else if (this.useCloseExponentialShadowMap || this.useBlurCloseExponentialShadowMap) {\n defines[\"SHADOWCLOSEESM\" + lightIndex] = true;\n }\n if (light.needCube()) {\n defines[\"SHADOWCUBE\" + lightIndex] = true;\n }\n }\n /**\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\n * defined in the generator but impacting the effect).\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\n * @param effect The effect we are binding the information for\n */\n bindShadowLight(lightIndex, effect) {\n const light = this._light;\n const scene = this._scene;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return;\n }\n if (!light.needCube()) {\n effect.setMatrix(\"lightMatrix\" + lightIndex, this.getTransformMatrix());\n }\n // Only PCF uses depth stencil texture.\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, this.getShadowMapForRendering());\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), shadowMap.getSize().width, 1 / shadowMap.getSize().width, this.frustumEdgeFalloff, lightIndex);\n }\n else if (this._filter === ShadowGenerator.FILTER_PCSS) {\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, this.getShadowMapForRendering());\n effect.setTexture(\"depthSampler\" + lightIndex, this.getShadowMapForRendering());\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), 1 / shadowMap.getSize().width, this._contactHardeningLightSizeUVRatio * shadowMap.getSize().width, this.frustumEdgeFalloff, lightIndex);\n }\n else {\n effect.setTexture(\"shadowSampler\" + lightIndex, this.getShadowMapForRendering());\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), this.blurScale / shadowMap.getSize().width, this.depthScale, this.frustumEdgeFalloff, lightIndex);\n }\n light._uniformBuffer.updateFloat2(\"depthValues\", this.getLight().getDepthMinZ(camera), this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera), lightIndex);\n }\n /**\n * Gets the transformation matrix used to project the meshes into the map from the light point of view.\n * (eq to shadow projection matrix * light transform matrix)\n * @returns The transform matrix used to create the shadow map\n */\n getTransformMatrix() {\n const scene = this._scene;\n if (this._currentRenderId === scene.getRenderId() && this._currentFaceIndexCache === this._currentFaceIndex) {\n return this._transformMatrix;\n }\n this._currentRenderId = scene.getRenderId();\n this._currentFaceIndexCache = this._currentFaceIndex;\n let lightPosition = this._light.position;\n if (this._light.computeTransformedInformation()) {\n lightPosition = this._light.transformedPosition;\n }\n Vector3.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex), this._lightDirection);\n if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {\n this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\n }\n if (this._light.needProjectionMatrixCompute() ||\n !this._cachedPosition ||\n !this._cachedDirection ||\n !lightPosition.equals(this._cachedPosition) ||\n !this._lightDirection.equals(this._cachedDirection)) {\n this._cachedPosition.copyFrom(lightPosition);\n this._cachedDirection.copyFrom(this._lightDirection);\n Matrix.LookAtLHToRef(lightPosition, lightPosition.add(this._lightDirection), Vector3.Up(), this._viewMatrix);\n const shadowMap = this.getShadowMap();\n if (shadowMap) {\n const renderList = shadowMap.renderList;\n if (renderList) {\n this._light.setShadowProjectionMatrix(this._projectionMatrix, this._viewMatrix, renderList);\n }\n }\n this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);\n }\n return this._transformMatrix;\n }\n /**\n * Recreates the shadow map dependencies like RTT and post processes. This can be used during the switch between\n * Cube and 2D textures for instance.\n */\n recreateShadowMap() {\n const shadowMap = this._shadowMap;\n if (!shadowMap) {\n return;\n }\n // Track render list.\n const renderList = shadowMap.renderList;\n // Clean up existing data.\n this._disposeRTTandPostProcesses();\n // Reinitializes.\n this._initializeGenerator();\n // Reaffect the filter to ensure a correct fallback if necessary.\n this.filter = this._filter;\n // Reaffect the filter.\n this._applyFilterValues();\n // Reaffect Render List.\n if (renderList) {\n // Note: don't do this._shadowMap!.renderList = renderList;\n // The renderList hooked array is accessing the old RenderTargetTexture (see RenderTargetTexture._hookArray), which is disposed at this point (by the call to _disposeRTTandPostProcesses)\n if (!this._shadowMap.renderList) {\n this._shadowMap.renderList = [];\n }\n for (const mesh of renderList) {\n this._shadowMap.renderList.push(mesh);\n }\n }\n else {\n this._shadowMap.renderList = null;\n }\n }\n _disposeBlurPostProcesses() {\n if (this._shadowMap2) {\n this._shadowMap2.dispose();\n this._shadowMap2 = null;\n }\n if (this._boxBlurPostprocess) {\n this._boxBlurPostprocess.dispose();\n this._boxBlurPostprocess = null;\n }\n if (this._kernelBlurXPostprocess) {\n this._kernelBlurXPostprocess.dispose();\n this._kernelBlurXPostprocess = null;\n }\n if (this._kernelBlurYPostprocess) {\n this._kernelBlurYPostprocess.dispose();\n this._kernelBlurYPostprocess = null;\n }\n this._blurPostProcesses = [];\n }\n _disposeRTTandPostProcesses() {\n if (this._shadowMap) {\n this._shadowMap.dispose();\n this._shadowMap = null;\n }\n this._disposeBlurPostProcesses();\n }\n _disposeSceneUBOs() {\n if (this._sceneUBOs) {\n for (const ubo of this._sceneUBOs) {\n ubo.dispose();\n }\n this._sceneUBOs = [];\n }\n }\n /**\n * Disposes the ShadowGenerator.\n * Returns nothing.\n */\n dispose() {\n this._disposeRTTandPostProcesses();\n this._disposeSceneUBOs();\n if (this._light) {\n if (this._light._shadowGenerators) {\n const iterator = this._light._shadowGenerators.entries();\n for (let entry = iterator.next(); entry.done !== true; entry = iterator.next()) {\n const [camera, shadowGenerator] = entry.value;\n if (shadowGenerator === this) {\n this._light._shadowGenerators.delete(camera);\n }\n }\n if (this._light._shadowGenerators.size === 0) {\n this._light._shadowGenerators = null;\n }\n }\n this._light._markMeshesAsLightDirty();\n }\n this.onBeforeShadowMapRenderMeshObservable.clear();\n this.onBeforeShadowMapRenderObservable.clear();\n this.onAfterShadowMapRenderMeshObservable.clear();\n this.onAfterShadowMapRenderObservable.clear();\n }\n /**\n * Serializes the shadow generator setup to a json object.\n * @returns The serialized JSON object\n */\n serialize() {\n var _a;\n const serializationObject = {};\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return serializationObject;\n }\n serializationObject.className = this.getClassName();\n serializationObject.lightId = this._light.id;\n serializationObject.cameraId = (_a = this._camera) === null || _a === void 0 ? void 0 : _a.id;\n serializationObject.id = this.id;\n serializationObject.mapSize = shadowMap.getRenderSize();\n serializationObject.forceBackFacesOnly = this.forceBackFacesOnly;\n serializationObject.darkness = this.getDarkness();\n serializationObject.transparencyShadow = this._transparencyShadow;\n serializationObject.frustumEdgeFalloff = this.frustumEdgeFalloff;\n serializationObject.bias = this.bias;\n serializationObject.normalBias = this.normalBias;\n serializationObject.usePercentageCloserFiltering = this.usePercentageCloserFiltering;\n serializationObject.useContactHardeningShadow = this.useContactHardeningShadow;\n serializationObject.contactHardeningLightSizeUVRatio = this.contactHardeningLightSizeUVRatio;\n serializationObject.filteringQuality = this.filteringQuality;\n serializationObject.useExponentialShadowMap = this.useExponentialShadowMap;\n serializationObject.useBlurExponentialShadowMap = this.useBlurExponentialShadowMap;\n serializationObject.useCloseExponentialShadowMap = this.useBlurExponentialShadowMap;\n serializationObject.useBlurCloseExponentialShadowMap = this.useBlurExponentialShadowMap;\n serializationObject.usePoissonSampling = this.usePoissonSampling;\n serializationObject.depthScale = this.depthScale;\n serializationObject.blurBoxOffset = this.blurBoxOffset;\n serializationObject.blurKernel = this.blurKernel;\n serializationObject.blurScale = this.blurScale;\n serializationObject.useKernelBlur = this.useKernelBlur;\n serializationObject.renderList = [];\n if (shadowMap.renderList) {\n for (let meshIndex = 0; meshIndex < shadowMap.renderList.length; meshIndex++) {\n const mesh = shadowMap.renderList[meshIndex];\n serializationObject.renderList.push(mesh.id);\n }\n }\n return serializationObject;\n }\n /**\n * Parses a serialized ShadowGenerator and returns a new ShadowGenerator.\n * @param parsedShadowGenerator The JSON object to parse\n * @param scene The scene to create the shadow map for\n * @param constr A function that builds a shadow generator or undefined to create an instance of the default shadow generator\n * @returns The parsed shadow generator\n */\n static Parse(parsedShadowGenerator, scene, constr) {\n const light = scene.getLightById(parsedShadowGenerator.lightId);\n const camera = parsedShadowGenerator.cameraId !== undefined ? scene.getCameraById(parsedShadowGenerator.cameraId) : null;\n const shadowGenerator = constr ? constr(parsedShadowGenerator.mapSize, light, camera) : new ShadowGenerator(parsedShadowGenerator.mapSize, light, undefined, camera);\n const shadowMap = shadowGenerator.getShadowMap();\n for (let meshIndex = 0; meshIndex < parsedShadowGenerator.renderList.length; meshIndex++) {\n const meshes = scene.getMeshesById(parsedShadowGenerator.renderList[meshIndex]);\n meshes.forEach(function (mesh) {\n if (!shadowMap) {\n return;\n }\n if (!shadowMap.renderList) {\n shadowMap.renderList = [];\n }\n shadowMap.renderList.push(mesh);\n });\n }\n if (parsedShadowGenerator.id !== undefined) {\n shadowGenerator.id = parsedShadowGenerator.id;\n }\n shadowGenerator.forceBackFacesOnly = !!parsedShadowGenerator.forceBackFacesOnly;\n if (parsedShadowGenerator.darkness !== undefined) {\n shadowGenerator.setDarkness(parsedShadowGenerator.darkness);\n }\n if (parsedShadowGenerator.transparencyShadow) {\n shadowGenerator.setTransparencyShadow(true);\n }\n if (parsedShadowGenerator.frustumEdgeFalloff !== undefined) {\n shadowGenerator.frustumEdgeFalloff = parsedShadowGenerator.frustumEdgeFalloff;\n }\n if (parsedShadowGenerator.bias !== undefined) {\n shadowGenerator.bias = parsedShadowGenerator.bias;\n }\n if (parsedShadowGenerator.normalBias !== undefined) {\n shadowGenerator.normalBias = parsedShadowGenerator.normalBias;\n }\n if (parsedShadowGenerator.usePercentageCloserFiltering) {\n shadowGenerator.usePercentageCloserFiltering = true;\n }\n else if (parsedShadowGenerator.useContactHardeningShadow) {\n shadowGenerator.useContactHardeningShadow = true;\n }\n else if (parsedShadowGenerator.usePoissonSampling) {\n shadowGenerator.usePoissonSampling = true;\n }\n else if (parsedShadowGenerator.useExponentialShadowMap) {\n shadowGenerator.useExponentialShadowMap = true;\n }\n else if (parsedShadowGenerator.useBlurExponentialShadowMap) {\n shadowGenerator.useBlurExponentialShadowMap = true;\n }\n else if (parsedShadowGenerator.useCloseExponentialShadowMap) {\n shadowGenerator.useCloseExponentialShadowMap = true;\n }\n else if (parsedShadowGenerator.useBlurCloseExponentialShadowMap) {\n shadowGenerator.useBlurCloseExponentialShadowMap = true;\n }\n // Backward compat\n else if (parsedShadowGenerator.useVarianceShadowMap) {\n shadowGenerator.useExponentialShadowMap = true;\n }\n else if (parsedShadowGenerator.useBlurVarianceShadowMap) {\n shadowGenerator.useBlurExponentialShadowMap = true;\n }\n if (parsedShadowGenerator.contactHardeningLightSizeUVRatio !== undefined) {\n shadowGenerator.contactHardeningLightSizeUVRatio = parsedShadowGenerator.contactHardeningLightSizeUVRatio;\n }\n if (parsedShadowGenerator.filteringQuality !== undefined) {\n shadowGenerator.filteringQuality = parsedShadowGenerator.filteringQuality;\n }\n if (parsedShadowGenerator.depthScale) {\n shadowGenerator.depthScale = parsedShadowGenerator.depthScale;\n }\n if (parsedShadowGenerator.blurScale) {\n shadowGenerator.blurScale = parsedShadowGenerator.blurScale;\n }\n if (parsedShadowGenerator.blurBoxOffset) {\n shadowGenerator.blurBoxOffset = parsedShadowGenerator.blurBoxOffset;\n }\n if (parsedShadowGenerator.useKernelBlur) {\n shadowGenerator.useKernelBlur = parsedShadowGenerator.useKernelBlur;\n }\n if (parsedShadowGenerator.blurKernel) {\n shadowGenerator.blurKernel = parsedShadowGenerator.blurKernel;\n }\n return shadowGenerator;\n }\n }\n /**\n * Name of the shadow generator class\n */\n ShadowGenerator.CLASSNAME = \"ShadowGenerator\";\n /**\n * Shadow generator mode None: no filtering applied.\n */\n ShadowGenerator.FILTER_NONE = 0;\n /**\n * Shadow generator mode ESM: Exponential Shadow Mapping.\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\n */\n ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP = 1;\n /**\n * Shadow generator mode Poisson Sampling: Percentage Closer Filtering.\n * (Multiple Tap around evenly distributed around the pixel are used to evaluate the shadow strength)\n */\n ShadowGenerator.FILTER_POISSONSAMPLING = 2;\n /**\n * Shadow generator mode ESM: Blurred Exponential Shadow Mapping.\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\n */\n ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP = 3;\n /**\n * Shadow generator mode ESM: Exponential Shadow Mapping using the inverse of the exponential preventing\n * edge artifacts on steep falloff.\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\n */\n ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP = 4;\n /**\n * Shadow generator mode ESM: Blurred Exponential Shadow Mapping using the inverse of the exponential preventing\n * edge artifacts on steep falloff.\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\n */\n ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP = 5;\n /**\n * Shadow generator mode PCF: Percentage Closer Filtering\n * benefits from Webgl 2 shadow samplers. Fallback to Poisson Sampling in Webgl 1\n * (https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch11.html)\n */\n ShadowGenerator.FILTER_PCF = 6;\n /**\n * Shadow generator mode PCSS: Percentage Closering Soft Shadow.\n * benefits from Webgl 2 shadow samplers. Fallback to Poisson Sampling in Webgl 1\n * Contact Hardening\n */\n ShadowGenerator.FILTER_PCSS = 7;\n /**\n * Reserved for PCF and PCSS\n * Highest Quality.\n *\n * Execute PCF on a 5*5 kernel improving a lot the shadow aliasing artifacts.\n *\n * Execute PCSS with 32 taps blocker search and 64 taps PCF.\n */\n ShadowGenerator.QUALITY_HIGH = 0;\n /**\n * Reserved for PCF and PCSS\n * Good tradeoff for quality/perf cross devices\n *\n * Execute PCF on a 3*3 kernel.\n *\n * Execute PCSS with 16 taps blocker search and 32 taps PCF.\n */\n ShadowGenerator.QUALITY_MEDIUM = 1;\n /**\n * Reserved for PCF and PCSS\n * The lowest quality but the fastest.\n *\n * Execute PCF on a 1*1 kernel.\n *\n * Execute PCSS with 16 taps blocker search and 16 taps PCF.\n */\n ShadowGenerator.QUALITY_LOW = 2;\n /**\n * Defines the default alpha cutoff value used for transparent alpha tested materials.\n */\n ShadowGenerator.DEFAULT_ALPHA_CUTOFF = 0.5;\n /**\n * @internal\n */\n ShadowGenerator._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"ShadowGeneratorSceneComponent\");\n };\n\n // Do not edit.\n const name$2e = \"depthPixelShader\";\n const shader$2e = `#ifdef ALPHATEST\nvarying vec2 vUV;uniform sampler2D diffuseSampler;\n#endif\n#include\nvarying float vDepthMetric;\n#ifdef PACKED\n#include\n#endif\n#ifdef STORE_CAMERASPACE_Z\nvarying vec4 vViewPos;\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#include\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#ifdef STORE_CAMERASPACE_Z\n#ifdef PACKED\ngl_FragColor=pack(vViewPos.z);\n#else\ngl_FragColor=vec4(vViewPos.z,0.0,0.0,1.0);\n#endif\n#else\n#ifdef NONLINEARDEPTH\n#ifdef PACKED\ngl_FragColor=pack(gl_FragCoord.z);\n#else\ngl_FragColor=vec4(gl_FragCoord.z,0.0,0.0,0.0);\n#endif\n#else\n#ifdef PACKED\ngl_FragColor=pack(vDepthMetric);\n#else\ngl_FragColor=vec4(vDepthMetric,0.0,0.0,1.0);\n#endif\n#endif\n#endif\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2e] = shader$2e;\n\n // Do not edit.\n const name$2f = \"depthVertexShader\";\n const shader$2f = `attribute vec3 position;\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\nuniform mat4 viewProjection;uniform vec2 depthValues;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;uniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#ifdef STORE_CAMERASPACE_Z\nuniform mat4 view;varying vec4 vViewPos;\n#endif\nvarying float vDepthMetric;\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#include\ngl_Position=viewProjection*worldPos;\n#ifdef STORE_CAMERASPACE_Z\nvViewPos=view*worldPos;\n#else\n#ifdef USE_REVERSE_DEPTHBUFFER\nvDepthMetric=((-gl_Position.z+depthValues.x)/(depthValues.y));\n#else\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));\n#endif\n#endif\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2f] = shader$2f;\n\n /**\n * This represents a depth renderer in Babylon.\n * A depth renderer will render to it's depth map every frame which can be displayed or used in post processing\n */\n class DepthRenderer {\n /**\n * Sets a specific material to be used to render a mesh/a list of meshes by the depth renderer\n * @param mesh mesh or array of meshes\n * @param material material to use by the depth render when rendering the mesh(es). If undefined is passed, the specific material created by the depth renderer will be used.\n */\n setMaterialForRendering(mesh, material) {\n this._depthMap.setMaterialForRendering(mesh, material);\n }\n /**\n * Instantiates a depth renderer\n * @param scene The scene the renderer belongs to\n * @param type The texture type of the depth map (default: Engine.TEXTURETYPE_FLOAT)\n * @param camera The camera to be used to render the depth map (default: scene's active camera)\n * @param storeNonLinearDepth Defines whether the depth is stored linearly like in Babylon Shadows or directly like glFragCoord.z\n * @param samplingMode The sampling mode to be used with the render target (Linear, Nearest...) (default: TRILINEAR_SAMPLINGMODE)\n * @param storeCameraSpaceZ Defines whether the depth stored is the Z coordinate in camera space. If true, storeNonLinearDepth has no effect. (Default: false)\n * @param name Name of the render target (default: DepthRenderer)\n */\n constructor(scene, type = 1, camera = null, storeNonLinearDepth = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, storeCameraSpaceZ = false, name) {\n /** Enable or disable the depth renderer. When disabled, the depth texture is not updated */\n this.enabled = true;\n /** Force writing the transparent objects into the depth map */\n this.forceDepthWriteTransparentMeshes = false;\n /**\n * Specifies that the depth renderer will only be used within\n * the camera it is created for.\n * This can help forcing its rendering during the camera processing.\n */\n this.useOnlyInActiveCamera = false;\n /** If true, reverse the culling of materials before writing to the depth texture.\n * So, basically, when \"true\", back facing instead of front facing faces are rasterized into the texture\n */\n this.reverseCulling = false;\n this._scene = scene;\n this._storeNonLinearDepth = storeNonLinearDepth;\n this._storeCameraSpaceZ = storeCameraSpaceZ;\n this.isPacked = type === 0;\n if (this.isPacked) {\n this.clearColor = new Color4(1.0, 1.0, 1.0, 1.0);\n }\n else {\n this.clearColor = new Color4(storeCameraSpaceZ ? 1e8 : 1.0, 0.0, 0.0, 1.0);\n }\n DepthRenderer._SceneComponentInitialization(this._scene);\n const engine = scene.getEngine();\n this._camera = camera;\n if (samplingMode !== Texture.NEAREST_SAMPLINGMODE) {\n if (type === 1 && !engine._caps.textureFloatLinearFiltering) {\n samplingMode = Texture.NEAREST_SAMPLINGMODE;\n }\n if (type === 2 && !engine._caps.textureHalfFloatLinearFiltering) {\n samplingMode = Texture.NEAREST_SAMPLINGMODE;\n }\n }\n // Render target\n const format = this.isPacked || !engine._features.supportExtendedTextureFormats ? 5 : 6;\n this._depthMap = new RenderTargetTexture(name !== null && name !== void 0 ? name : \"DepthRenderer\", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this._scene, false, true, type, false, samplingMode, undefined, undefined, undefined, format);\n this._depthMap.wrapU = Texture.CLAMP_ADDRESSMODE;\n this._depthMap.wrapV = Texture.CLAMP_ADDRESSMODE;\n this._depthMap.refreshRate = 1;\n this._depthMap.renderParticles = false;\n this._depthMap.renderList = null;\n this._depthMap.noPrePassRenderer = true;\n // Camera to get depth map from to support multiple concurrent cameras\n this._depthMap.activeCamera = this._camera;\n this._depthMap.ignoreCameraViewport = true;\n this._depthMap.useCameraPostProcesses = false;\n // set default depth value to 1.0 (far away)\n this._depthMap.onClearObservable.add((engine) => {\n engine.clear(this.clearColor, true, true, true);\n });\n this._depthMap.onBeforeBindObservable.add(() => {\n var _a;\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, \"depth renderer\", 1);\n });\n this._depthMap.onAfterUnbindObservable.add(() => {\n var _a;\n (_a = engine._debugPopGroup) === null || _a === void 0 ? void 0 : _a.call(engine, 1);\n });\n this._depthMap.customIsReadyFunction = (mesh, refreshRate, preWarm) => {\n if ((preWarm || refreshRate === 0) && mesh.subMeshes) {\n for (let i = 0; i < mesh.subMeshes.length; ++i) {\n const subMesh = mesh.subMeshes[i];\n const renderingMesh = subMesh.getRenderingMesh();\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\n const hardwareInstancedRendering = engine.getCaps().instancedArrays &&\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || renderingMesh.hasThinInstances);\n if (!this.isReady(subMesh, hardwareInstancedRendering)) {\n return false;\n }\n }\n }\n return true;\n };\n // Custom render function\n const renderSubMesh = (subMesh) => {\n var _a, _b;\n const renderingMesh = subMesh.getRenderingMesh();\n const effectiveMesh = subMesh.getEffectiveMesh();\n const scene = this._scene;\n const engine = scene.getEngine();\n const material = subMesh.getMaterial();\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n if (!material || effectiveMesh.infiniteDistance || material.disableDepthWrite || subMesh.verticesCount === 0 || subMesh._renderId === scene.getRenderId()) {\n return;\n }\n // Culling\n const detNeg = effectiveMesh._getWorldMatrixDeterminant() < 0;\n let sideOrientation = (_a = renderingMesh.overrideMaterialSideOrientation) !== null && _a !== void 0 ? _a : material.sideOrientation;\n if (detNeg) {\n sideOrientation =\n sideOrientation === 0\n ? 1\n : 0;\n }\n const reverseSideOrientation = sideOrientation === 0;\n engine.setState(material.backFaceCulling, 0, false, reverseSideOrientation, this.reverseCulling ? !material.cullBackFaces : material.cullBackFaces);\n // Managing instances\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\n if (batch.mustReturn) {\n return;\n }\n const hardwareInstancedRendering = engine.getCaps().instancedArrays &&\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || renderingMesh.hasThinInstances);\n const camera = this._camera || scene.activeCamera;\n if (this.isReady(subMesh, hardwareInstancedRendering) && camera) {\n subMesh._renderId = scene.getRenderId();\n const renderingMaterial = (_b = effectiveMesh._internalAbstractMeshDataInfo._materialForRenderPass) === null || _b === void 0 ? void 0 : _b[engine.currentRenderPassId];\n let drawWrapper = subMesh._getDrawWrapper();\n if (!drawWrapper && renderingMaterial) {\n drawWrapper = renderingMaterial._getDrawWrapper();\n }\n const cameraIsOrtho = camera.mode === Camera.ORTHOGRAPHIC_CAMERA;\n if (!drawWrapper) {\n return;\n }\n const effect = drawWrapper.effect;\n engine.enableEffect(drawWrapper);\n if (!hardwareInstancedRendering) {\n renderingMesh._bind(subMesh, effect, material.fillMode);\n }\n if (!renderingMaterial) {\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\n effect.setMatrix(\"world\", effectiveMesh.getWorldMatrix());\n if (this._storeCameraSpaceZ) {\n effect.setMatrix(\"view\", scene.getViewMatrix());\n }\n }\n else {\n renderingMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), effectiveMesh, subMesh);\n }\n let minZ, maxZ;\n if (cameraIsOrtho) {\n minZ = !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\n maxZ = engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\n }\n else {\n minZ = engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? camera.minZ : engine.isNDCHalfZRange ? 0 : camera.minZ;\n maxZ = engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : camera.maxZ;\n }\n effect.setFloat2(\"depthValues\", minZ, minZ + maxZ);\n if (!renderingMaterial) {\n // Alpha test\n if (material.needAlphaTesting()) {\n const alphaTexture = material.getAlphaTestTexture();\n if (alphaTexture) {\n effect.setTexture(\"diffuseSampler\", alphaTexture);\n effect.setMatrix(\"diffuseMatrix\", alphaTexture.getTextureMatrix());\n }\n }\n // Bones\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\n const skeleton = renderingMesh.skeleton;\n if (skeleton.isUsingTextureForMatrices) {\n const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);\n if (!boneTexture) {\n return;\n }\n effect.setTexture(\"boneSampler\", boneTexture);\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\n }\n else {\n effect.setMatrices(\"mBones\", skeleton.getTransformMatrices(renderingMesh));\n }\n }\n // Clip planes\n bindClipPlane(effect, material, scene);\n // Morph targets\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\n renderingMesh.morphTargetManager._bind(effect);\n }\n }\n // Draw\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) => effect.setMatrix(\"world\", world));\n }\n };\n this._depthMap.customRenderFunction = (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) => {\n let index;\n if (depthOnlySubMeshes.length) {\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\n renderSubMesh(depthOnlySubMeshes.data[index]);\n }\n }\n for (index = 0; index < opaqueSubMeshes.length; index++) {\n renderSubMesh(opaqueSubMeshes.data[index]);\n }\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\n renderSubMesh(alphaTestSubMeshes.data[index]);\n }\n if (this.forceDepthWriteTransparentMeshes) {\n for (index = 0; index < transparentSubMeshes.length; index++) {\n renderSubMesh(transparentSubMeshes.data[index]);\n }\n }\n else {\n for (index = 0; index < transparentSubMeshes.length; index++) {\n transparentSubMeshes.data[index].getEffectiveMesh()._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n }\n }\n };\n }\n /**\n * Creates the depth rendering effect and checks if the effect is ready.\n * @param subMesh The submesh to be used to render the depth map of\n * @param useInstances If multiple world instances should be used\n * @returns if the depth renderer is ready to render the depth map\n */\n isReady(subMesh, useInstances) {\n var _a;\n const engine = this._scene.getEngine();\n const mesh = subMesh.getMesh();\n const scene = mesh.getScene();\n const renderingMaterial = (_a = mesh._internalAbstractMeshDataInfo._materialForRenderPass) === null || _a === void 0 ? void 0 : _a[engine.currentRenderPassId];\n if (renderingMaterial) {\n return renderingMaterial.isReadyForSubMesh(mesh, subMesh, useInstances);\n }\n const material = subMesh.getMaterial();\n if (!material || material.disableDepthWrite) {\n return false;\n }\n const defines = [];\n const attribs = [VertexBuffer.PositionKind];\n // Alpha test\n if (material && material.needAlphaTesting() && material.getAlphaTestTexture()) {\n defines.push(\"#define ALPHATEST\");\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n attribs.push(VertexBuffer.UVKind);\n defines.push(\"#define UV1\");\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\n attribs.push(VertexBuffer.UV2Kind);\n defines.push(\"#define UV2\");\n }\n }\n // Bones\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (mesh.numBoneInfluencers > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\n defines.push(\"#define BonesPerMesh \" + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));\n const skeleton = subMesh.getRenderingMesh().skeleton;\n if (skeleton === null || skeleton === void 0 ? void 0 : skeleton.isUsingTextureForMatrices) {\n defines.push(\"#define BONETEXTURE\");\n }\n }\n else {\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\n }\n // Morph targets\n const morphTargetManager = mesh.morphTargetManager;\n let numMorphInfluencers = 0;\n if (morphTargetManager) {\n if (morphTargetManager.numInfluencers > 0) {\n numMorphInfluencers = morphTargetManager.numInfluencers;\n defines.push(\"#define MORPHTARGETS\");\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numMorphInfluencers);\n if (morphTargetManager.isUsingTextureForTargets) {\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\n }\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, numMorphInfluencers);\n }\n }\n // Instances\n if (useInstances) {\n defines.push(\"#define INSTANCES\");\n MaterialHelper.PushAttributesForInstances(attribs);\n if (subMesh.getRenderingMesh().hasThinInstances) {\n defines.push(\"#define THIN_INSTANCES\");\n }\n }\n // None linear depth\n if (this._storeNonLinearDepth) {\n defines.push(\"#define NONLINEARDEPTH\");\n }\n // Store camera space Z coordinate instead of NDC Z\n if (this._storeCameraSpaceZ) {\n defines.push(\"#define STORE_CAMERASPACE_Z\");\n }\n // Float Mode\n if (this.isPacked) {\n defines.push(\"#define PACKED\");\n }\n // Clip planes\n prepareStringDefinesForClipPlanes(material, scene, defines);\n // Get correct effect\n const drawWrapper = subMesh._getDrawWrapper(undefined, true);\n const cachedDefines = drawWrapper.defines;\n const join = defines.join(\"\\n\");\n if (cachedDefines !== join) {\n const uniforms = [\n \"world\",\n \"mBones\",\n \"boneTextureWidth\",\n \"viewProjection\",\n \"view\",\n \"diffuseMatrix\",\n \"depthValues\",\n \"morphTargetInfluences\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n ];\n addClipPlaneUniforms(uniforms);\n drawWrapper.setEffect(engine.createEffect(\"depth\", attribs, uniforms, [\"diffuseSampler\", \"morphTargets\", \"boneSampler\"], join, undefined, undefined, undefined, {\n maxSimultaneousMorphTargets: numMorphInfluencers,\n }), join);\n }\n return drawWrapper.effect.isReady();\n }\n /**\n * Gets the texture which the depth map will be written to.\n * @returns The depth map texture\n */\n getDepthMap() {\n return this._depthMap;\n }\n /**\n * Disposes of the depth renderer.\n */\n dispose() {\n const keysToDelete = [];\n for (const key in this._scene._depthRenderer) {\n const depthRenderer = this._scene._depthRenderer[key];\n if (depthRenderer === this) {\n keysToDelete.push(key);\n }\n }\n if (keysToDelete.length > 0) {\n this._depthMap.dispose();\n for (const key of keysToDelete) {\n delete this._scene._depthRenderer[key];\n }\n }\n }\n }\n /**\n * @internal\n */\n DepthRenderer._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"DepthRendererSceneComponent\");\n };\n\n // Do not edit.\n const name$2g = \"minmaxReduxPixelShader\";\n const shader$2g = `varying vec2 vUV;uniform sampler2D textureSampler;\n#if defined(INITIAL)\nuniform sampler2D sourceTexture;uniform vec2 texSize;void main(void)\n{ivec2 coord=ivec2(vUV*(texSize-1.0));float f1=texelFetch(sourceTexture,coord,0).r;float f2=texelFetch(sourceTexture,coord+ivec2(1,0),0).r;float f3=texelFetch(sourceTexture,coord+ivec2(1,1),0).r;float f4=texelFetch(sourceTexture,coord+ivec2(0,1),0).r;float minz=min(min(min(f1,f2),f3),f4);\n#ifdef DEPTH_REDUX\nfloat maxz=max(max(max(sign(1.0-f1)*f1,sign(1.0-f2)*f2),sign(1.0-f3)*f3),sign(1.0-f4)*f4);\n#else\nfloat maxz=max(max(max(f1,f2),f3),f4);\n#endif\nglFragColor=vec4(minz,maxz,0.,0.);}\n#elif defined(MAIN)\nuniform vec2 texSize;void main(void)\n{ivec2 coord=ivec2(vUV*(texSize-1.0));vec2 f1=texelFetch(textureSampler,coord,0).rg;vec2 f2=texelFetch(textureSampler,coord+ivec2(1,0),0).rg;vec2 f3=texelFetch(textureSampler,coord+ivec2(1,1),0).rg;vec2 f4=texelFetch(textureSampler,coord+ivec2(0,1),0).rg;float minz=min(min(min(f1.x,f2.x),f3.x),f4.x);float maxz=max(max(max(f1.y,f2.y),f3.y),f4.y);glFragColor=vec4(minz,maxz,0.,0.);}\n#elif defined(ONEBEFORELAST)\nuniform ivec2 texSize;void main(void)\n{ivec2 coord=ivec2(vUV*vec2(texSize-1));vec2 f1=texelFetch(textureSampler,coord % texSize,0).rg;vec2 f2=texelFetch(textureSampler,(coord+ivec2(1,0)) % texSize,0).rg;vec2 f3=texelFetch(textureSampler,(coord+ivec2(1,1)) % texSize,0).rg;vec2 f4=texelFetch(textureSampler,(coord+ivec2(0,1)) % texSize,0).rg;float minz=min(f1.x,f2.x);float maxz=max(f1.y,f2.y);glFragColor=vec4(minz,maxz,0.,0.);}\n#elif defined(LAST)\nvoid main(void)\n{glFragColor=vec4(0.);if (true) { \ndiscard;}}\n#endif\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2g] = shader$2g;\n\n /**\n * This class computes a min/max reduction from a texture: it means it computes the minimum\n * and maximum values from all values of the texture.\n * It is performed on the GPU for better performances, thanks to a succession of post processes.\n * The source values are read from the red channel of the texture.\n */\n class MinMaxReducer {\n /**\n * Creates a min/max reducer\n * @param camera The camera to use for the post processes\n */\n constructor(camera) {\n /**\n * Observable triggered when the computation has been performed\n */\n this.onAfterReductionPerformed = new Observable$1();\n this._forceFullscreenViewport = true;\n this._activated = false;\n this._camera = camera;\n this._postProcessManager = new PostProcessManager(camera.getScene());\n this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {\n this._postProcessManager._rebuild();\n });\n }\n /**\n * Gets the texture used to read the values from.\n */\n get sourceTexture() {\n return this._sourceTexture;\n }\n /**\n * Sets the source texture to read the values from.\n * One must indicate if the texture is a depth texture or not through the depthRedux parameter\n * because in such textures '1' value must not be taken into account to compute the maximum\n * as this value is used to clear the texture.\n * Note that the computation is not activated by calling this function, you must call activate() for that!\n * @param sourceTexture The texture to read the values from. The values should be in the red channel.\n * @param depthRedux Indicates if the texture is a depth texture or not\n * @param type The type of the textures created for the reduction (defaults to TEXTURETYPE_HALF_FLOAT)\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\n */\n setSourceTexture(sourceTexture, depthRedux, type = 2, forceFullscreenViewport = true) {\n if (sourceTexture === this._sourceTexture) {\n return;\n }\n this.dispose(false);\n this._sourceTexture = sourceTexture;\n this._reductionSteps = [];\n this._forceFullscreenViewport = forceFullscreenViewport;\n const scene = this._camera.getScene();\n // create the first step\n const reductionInitial = new PostProcess(\"Initial reduction phase\", \"minmaxRedux\", // shader\n [\"texSize\"], [\"sourceTexture\"], // textures\n 1.0, // options\n null, // camera\n 1, // sampling\n scene.getEngine(), // engine\n false, // reusable\n \"#define INITIAL\" + (depthRedux ? \"\\n#define DEPTH_REDUX\" : \"\"), // defines\n type, undefined, undefined, undefined, 7);\n reductionInitial.autoClear = false;\n reductionInitial.forceFullscreenViewport = forceFullscreenViewport;\n let w = this._sourceTexture.getRenderWidth(), h = this._sourceTexture.getRenderHeight();\n reductionInitial.onApply = ((w, h) => {\n return (effect) => {\n effect.setTexture(\"sourceTexture\", this._sourceTexture);\n effect.setFloat2(\"texSize\", w, h);\n };\n })(w, h);\n this._reductionSteps.push(reductionInitial);\n let index = 1;\n // create the additional steps\n while (w > 1 || h > 1) {\n w = Math.max(Math.round(w / 2), 1);\n h = Math.max(Math.round(h / 2), 1);\n const reduction = new PostProcess(\"Reduction phase \" + index, \"minmaxRedux\", // shader\n [\"texSize\"], null, { width: w, height: h }, // options\n null, // camera\n 1, // sampling\n scene.getEngine(), // engine\n false, // reusable\n \"#define \" + (w == 1 && h == 1 ? \"LAST\" : w == 1 || h == 1 ? \"ONEBEFORELAST\" : \"MAIN\"), // defines\n type, undefined, undefined, undefined, 7);\n reduction.autoClear = false;\n reduction.forceFullscreenViewport = forceFullscreenViewport;\n reduction.onApply = ((w, h) => {\n return (effect) => {\n if (w == 1 || h == 1) {\n effect.setInt2(\"texSize\", w, h);\n }\n else {\n effect.setFloat2(\"texSize\", w, h);\n }\n };\n })(w, h);\n this._reductionSteps.push(reduction);\n index++;\n if (w == 1 && h == 1) {\n const func = (w, h, reduction) => {\n const buffer = new Float32Array(4 * w * h), minmax = { min: 0, max: 0 };\n return () => {\n scene.getEngine()._readTexturePixels(reduction.inputTexture.texture, w, h, -1, 0, buffer, false);\n minmax.min = buffer[0];\n minmax.max = buffer[1];\n this.onAfterReductionPerformed.notifyObservers(minmax);\n };\n };\n reduction.onAfterRenderObservable.add(func(w, h, reduction));\n }\n }\n }\n /**\n * Defines the refresh rate of the computation.\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\n */\n get refreshRate() {\n return this._sourceTexture ? this._sourceTexture.refreshRate : -1;\n }\n set refreshRate(value) {\n if (this._sourceTexture) {\n this._sourceTexture.refreshRate = value;\n }\n }\n /**\n * Gets the activation status of the reducer\n */\n get activated() {\n return this._activated;\n }\n /**\n * Activates the reduction computation.\n * When activated, the observers registered in onAfterReductionPerformed are\n * called after the computation is performed\n */\n activate() {\n if (this._onAfterUnbindObserver || !this._sourceTexture) {\n return;\n }\n this._onAfterUnbindObserver = this._sourceTexture.onAfterUnbindObservable.add(() => {\n var _a, _b;\n const engine = this._camera.getScene().getEngine();\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, `min max reduction`, 1);\n this._reductionSteps[0].activate(this._camera);\n this._postProcessManager.directRender(this._reductionSteps, this._reductionSteps[0].inputTexture, this._forceFullscreenViewport);\n engine.unBindFramebuffer(this._reductionSteps[0].inputTexture, false);\n (_b = engine._debugPopGroup) === null || _b === void 0 ? void 0 : _b.call(engine, 1);\n });\n this._activated = true;\n }\n /**\n * Deactivates the reduction computation.\n */\n deactivate() {\n if (!this._onAfterUnbindObserver || !this._sourceTexture) {\n return;\n }\n this._sourceTexture.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\n this._onAfterUnbindObserver = null;\n this._activated = false;\n }\n /**\n * Disposes the min/max reducer\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\n */\n dispose(disposeAll = true) {\n if (disposeAll) {\n this.onAfterReductionPerformed.clear();\n if (this._onContextRestoredObserver) {\n this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\n this._onContextRestoredObserver = null;\n }\n }\n this.deactivate();\n if (this._reductionSteps) {\n for (let i = 0; i < this._reductionSteps.length; ++i) {\n this._reductionSteps[i].dispose();\n }\n this._reductionSteps = null;\n }\n if (this._postProcessManager && disposeAll) {\n this._postProcessManager.dispose();\n }\n this._sourceTexture = null;\n }\n }\n\n /**\n * This class is a small wrapper around the MinMaxReducer class to compute the min/max values of a depth texture\n */\n class DepthReducer extends MinMaxReducer {\n /**\n * Gets the depth renderer used for the computation.\n * Note that the result is null if you provide your own renderer when calling setDepthRenderer.\n */\n get depthRenderer() {\n return this._depthRenderer;\n }\n /**\n * Creates a depth reducer\n * @param camera The camera used to render the depth texture\n */\n constructor(camera) {\n super(camera);\n }\n /**\n * Sets the depth renderer to use to generate the depth map\n * @param depthRenderer The depth renderer to use. If not provided, a new one will be created automatically\n * @param type The texture type of the depth map (default: TEXTURETYPE_HALF_FLOAT)\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\n */\n setDepthRenderer(depthRenderer = null, type = 2, forceFullscreenViewport = true) {\n const scene = this._camera.getScene();\n if (this._depthRenderer) {\n delete scene._depthRenderer[this._depthRendererId];\n this._depthRenderer.dispose();\n this._depthRenderer = null;\n }\n if (depthRenderer === null) {\n if (!scene._depthRenderer) {\n scene._depthRenderer = {};\n }\n depthRenderer = this._depthRenderer = new DepthRenderer(scene, type, this._camera, false, 1);\n depthRenderer.enabled = false;\n this._depthRendererId = \"minmax\" + this._camera.id;\n scene._depthRenderer[this._depthRendererId] = depthRenderer;\n }\n super.setSourceTexture(depthRenderer.getDepthMap(), true, type, forceFullscreenViewport);\n }\n /**\n * @internal\n */\n setSourceTexture(sourceTexture, depthRedux, type = 2, forceFullscreenViewport = true) {\n super.setSourceTexture(sourceTexture, depthRedux, type, forceFullscreenViewport);\n }\n /**\n * Activates the reduction computation.\n * When activated, the observers registered in onAfterReductionPerformed are\n * called after the computation is performed\n */\n activate() {\n if (this._depthRenderer) {\n this._depthRenderer.enabled = true;\n }\n super.activate();\n }\n /**\n * Deactivates the reduction computation.\n */\n deactivate() {\n super.deactivate();\n if (this._depthRenderer) {\n this._depthRenderer.enabled = false;\n }\n }\n /**\n * Disposes the depth reducer\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\n */\n dispose(disposeAll = true) {\n super.dispose(disposeAll);\n if (this._depthRenderer && disposeAll) {\n const scene = this._depthRenderer.getDepthMap().getScene();\n if (scene) {\n delete scene._depthRenderer[this._depthRendererId];\n }\n this._depthRenderer.dispose();\n this._depthRenderer = null;\n }\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UpDir = Vector3.Up();\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const ZeroVec = Vector3.Zero();\n const tmpv1 = new Vector3(), tmpv2 = new Vector3(), tmpMatrix = new Matrix();\n /**\n * A CSM implementation allowing casting shadows on large scenes.\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\n * Based on: https://github.com/TheRealMJP/Shadows and https://johanmedestrom.wordpress.com/2016/03/18/opengl-cascaded-shadow-maps/\n */\n class CascadedShadowGenerator extends ShadowGenerator {\n _validateFilter(filter) {\n if (filter === ShadowGenerator.FILTER_NONE || filter === ShadowGenerator.FILTER_PCF || filter === ShadowGenerator.FILTER_PCSS) {\n return filter;\n }\n console.error('Unsupported filter \"' + filter + '\"!');\n return ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets or set the number of cascades used by the CSM.\n */\n get numCascades() {\n return this._numCascades;\n }\n set numCascades(value) {\n value = Math.min(Math.max(value, CascadedShadowGenerator.MIN_CASCADES_COUNT), CascadedShadowGenerator.MAX_CASCADES_COUNT);\n if (value === this._numCascades) {\n return;\n }\n this._numCascades = value;\n this.recreateShadowMap();\n this._recreateSceneUBOs();\n }\n /**\n * Enables or disables the shadow casters bounding info computation.\n * If your shadow casters don't move, you can disable this feature.\n * If it is enabled, the bounding box computation is done every frame.\n */\n get freezeShadowCastersBoundingInfo() {\n return this._freezeShadowCastersBoundingInfo;\n }\n set freezeShadowCastersBoundingInfo(freeze) {\n if (this._freezeShadowCastersBoundingInfoObservable && freeze) {\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\n this._freezeShadowCastersBoundingInfoObservable = null;\n }\n if (!this._freezeShadowCastersBoundingInfoObservable && !freeze) {\n this._freezeShadowCastersBoundingInfoObservable = this._scene.onBeforeRenderObservable.add(this._computeShadowCastersBoundingInfo.bind(this));\n }\n this._freezeShadowCastersBoundingInfo = freeze;\n if (freeze) {\n this._computeShadowCastersBoundingInfo();\n }\n }\n _computeShadowCastersBoundingInfo() {\n this._scbiMin.copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._scbiMax.copyFromFloats(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);\n if (this._shadowMap && this._shadowMap.renderList) {\n const renderList = this._shadowMap.renderList;\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\n const mesh = renderList[meshIndex];\n if (!mesh) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo(), boundingBox = boundingInfo.boundingBox;\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\n }\n const meshes = this._scene.meshes;\n for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {\n const mesh = meshes[meshIndex];\n if (!mesh || !mesh.isVisible || !mesh.isEnabled || !mesh.receiveShadows) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo(), boundingBox = boundingInfo.boundingBox;\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\n }\n }\n this._shadowCastersBoundingInfo.reConstruct(this._scbiMin, this._scbiMax);\n }\n /**\n * Gets or sets the shadow casters bounding info.\n * If you provide your own shadow casters bounding info, first enable freezeShadowCastersBoundingInfo\n * so that the system won't overwrite the bounds you provide\n */\n get shadowCastersBoundingInfo() {\n return this._shadowCastersBoundingInfo;\n }\n set shadowCastersBoundingInfo(boundingInfo) {\n this._shadowCastersBoundingInfo = boundingInfo;\n }\n /**\n * Sets the minimal and maximal distances to use when computing the cascade breaks.\n *\n * The values of min / max are typically the depth zmin and zmax values of your scene, for a given frame.\n * If you don't know these values, simply leave them to their defaults and don't call this function.\n * @param min minimal distance for the breaks (default to 0.)\n * @param max maximal distance for the breaks (default to 1.)\n */\n setMinMaxDistance(min, max) {\n if (this._minDistance === min && this._maxDistance === max) {\n return;\n }\n if (min > max) {\n min = 0;\n max = 1;\n }\n if (min < 0) {\n min = 0;\n }\n if (max > 1) {\n max = 1;\n }\n this._minDistance = min;\n this._maxDistance = max;\n this._breaksAreDirty = true;\n }\n /** Gets the minimal distance used in the cascade break computation */\n get minDistance() {\n return this._minDistance;\n }\n /** Gets the maximal distance used in the cascade break computation */\n get maxDistance() {\n return this._maxDistance;\n }\n /**\n * Gets the class name of that object\n * @returns \"CascadedShadowGenerator\"\n */\n getClassName() {\n return CascadedShadowGenerator.CLASSNAME;\n }\n /**\n * Gets a cascade minimum extents\n * @param cascadeIndex index of the cascade\n * @returns the minimum cascade extents\n */\n getCascadeMinExtents(cascadeIndex) {\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMinExtents[cascadeIndex] : null;\n }\n /**\n * Gets a cascade maximum extents\n * @param cascadeIndex index of the cascade\n * @returns the maximum cascade extents\n */\n getCascadeMaxExtents(cascadeIndex) {\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMaxExtents[cascadeIndex] : null;\n }\n /**\n * Gets the shadow max z distance. It's the limit beyond which shadows are not displayed.\n * It defaults to camera.maxZ\n */\n get shadowMaxZ() {\n if (!this._getCamera()) {\n return 0;\n }\n return this._shadowMaxZ;\n }\n /**\n * Sets the shadow max z distance.\n */\n set shadowMaxZ(value) {\n const camera = this._getCamera();\n if (!camera) {\n this._shadowMaxZ = value;\n return;\n }\n if (this._shadowMaxZ === value || value < camera.minZ || value > camera.maxZ) {\n return;\n }\n this._shadowMaxZ = value;\n this._light._markMeshesAsLightDirty();\n this._breaksAreDirty = true;\n }\n /**\n * Gets or sets the debug flag.\n * When enabled, the cascades are materialized by different colors on the screen.\n */\n get debug() {\n return this._debug;\n }\n set debug(dbg) {\n this._debug = dbg;\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets or sets the depth clamping value.\n *\n * When enabled, it improves the shadow quality because the near z plane of the light frustum don't need to be adjusted\n * to account for the shadow casters far away.\n *\n * Note that this property is incompatible with PCSS filtering, so it won't be used in that case.\n */\n get depthClamp() {\n return this._depthClamp;\n }\n set depthClamp(value) {\n this._depthClamp = value;\n }\n /**\n * Gets or sets the percentage of blending between two cascades (value between 0. and 1.).\n * It defaults to 0.1 (10% blending).\n */\n get cascadeBlendPercentage() {\n return this._cascadeBlendPercentage;\n }\n set cascadeBlendPercentage(value) {\n this._cascadeBlendPercentage = value;\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets or set the lambda parameter.\n * This parameter is used to split the camera frustum and create the cascades.\n * It's a value between 0. and 1.: If 0, the split is a uniform split of the frustum, if 1 it is a logarithmic split.\n * For all values in-between, it's a linear combination of the uniform and logarithm split algorithm.\n */\n get lambda() {\n return this._lambda;\n }\n set lambda(value) {\n const lambda = Math.min(Math.max(value, 0), 1);\n if (this._lambda == lambda) {\n return;\n }\n this._lambda = lambda;\n this._breaksAreDirty = true;\n }\n /**\n * Gets the view matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the view matrix from\n * @returns the cascade view matrix\n */\n getCascadeViewMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._viewMatrices[cascadeNum] : null;\n }\n /**\n * Gets the projection matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the projection matrix from\n * @returns the cascade projection matrix\n */\n getCascadeProjectionMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._projectionMatrices[cascadeNum] : null;\n }\n /**\n * Gets the transformation matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the transformation matrix from\n * @returns the cascade transformation matrix\n */\n getCascadeTransformMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._transformMatrices[cascadeNum] : null;\n }\n /**\n * Sets the depth renderer to use when autoCalcDepthBounds is enabled.\n *\n * Note that if no depth renderer is set, a new one will be automatically created internally when necessary.\n *\n * You should call this function if you already have a depth renderer enabled in your scene, to avoid\n * doing multiple depth rendering each frame. If you provide your own depth renderer, make sure it stores linear depth!\n * @param depthRenderer The depth renderer to use when autoCalcDepthBounds is enabled. If you pass null or don't call this function at all, a depth renderer will be automatically created\n */\n setDepthRenderer(depthRenderer) {\n this._depthRenderer = depthRenderer;\n if (this._depthReducer) {\n this._depthReducer.setDepthRenderer(this._depthRenderer);\n }\n }\n /**\n * Gets or sets the autoCalcDepthBounds property.\n *\n * When enabled, a depth rendering pass is first performed (with an internally created depth renderer or with the one\n * you provide by calling setDepthRenderer). Then, a min/max reducing is applied on the depth map to compute the\n * minimal and maximal depth of the map and those values are used as inputs for the setMinMaxDistance() function.\n * It can greatly enhance the shadow quality, at the expense of more GPU works.\n * When using this option, you should increase the value of the lambda parameter, and even set it to 1 for best results.\n */\n get autoCalcDepthBounds() {\n return this._autoCalcDepthBounds;\n }\n set autoCalcDepthBounds(value) {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n this._autoCalcDepthBounds = value;\n if (!value) {\n if (this._depthReducer) {\n this._depthReducer.deactivate();\n }\n this.setMinMaxDistance(0, 1);\n return;\n }\n if (!this._depthReducer) {\n this._depthReducer = new DepthReducer(camera);\n this._depthReducer.onAfterReductionPerformed.add((minmax) => {\n let min = minmax.min, max = minmax.max;\n if (min >= max) {\n min = 0;\n max = 1;\n }\n if (min != this._minDistance || max != this._maxDistance) {\n this.setMinMaxDistance(min, max);\n }\n });\n this._depthReducer.setDepthRenderer(this._depthRenderer);\n }\n this._depthReducer.activate();\n }\n /**\n * Defines the refresh rate of the min/max computation used when autoCalcDepthBounds is set to true\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\n * Note that if you provided your own depth renderer through a call to setDepthRenderer, you are responsible\n * for setting the refresh rate on the renderer yourself!\n */\n get autoCalcDepthBoundsRefreshRate() {\n var _a, _b, _c;\n return (_c = (_b = (_a = this._depthReducer) === null || _a === void 0 ? void 0 : _a.depthRenderer) === null || _b === void 0 ? void 0 : _b.getDepthMap().refreshRate) !== null && _c !== void 0 ? _c : -1;\n }\n set autoCalcDepthBoundsRefreshRate(value) {\n var _a;\n if ((_a = this._depthReducer) === null || _a === void 0 ? void 0 : _a.depthRenderer) {\n this._depthReducer.depthRenderer.getDepthMap().refreshRate = value;\n }\n }\n /**\n * Create the cascade breaks according to the lambda, shadowMaxZ and min/max distance properties, as well as the camera near and far planes.\n * This function is automatically called when updating lambda, shadowMaxZ and min/max distances, however you should call it yourself if\n * you change the camera near/far planes!\n */\n splitFrustum() {\n this._breaksAreDirty = true;\n }\n _splitFrustum() {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const near = camera.minZ, far = camera.maxZ || this._shadowMaxZ, // account for infinite far plane (ie. maxZ = 0)\n cameraRange = far - near, minDistance = this._minDistance, maxDistance = this._shadowMaxZ < far && this._shadowMaxZ >= near ? Math.min((this._shadowMaxZ - near) / (far - near), this._maxDistance) : this._maxDistance;\n const minZ = near + minDistance * cameraRange, maxZ = near + maxDistance * cameraRange;\n const range = maxZ - minZ, ratio = maxZ / minZ;\n for (let cascadeIndex = 0; cascadeIndex < this._cascades.length; ++cascadeIndex) {\n const p = (cascadeIndex + 1) / this._numCascades, log = minZ * ratio ** p, uniform = minZ + range * p;\n const d = this._lambda * (log - uniform) + uniform;\n this._cascades[cascadeIndex].prevBreakDistance = cascadeIndex === 0 ? minDistance : this._cascades[cascadeIndex - 1].breakDistance;\n this._cascades[cascadeIndex].breakDistance = (d - near) / cameraRange;\n this._viewSpaceFrustumsZ[cascadeIndex] = d;\n this._frustumLengths[cascadeIndex] = (this._cascades[cascadeIndex].breakDistance - this._cascades[cascadeIndex].prevBreakDistance) * cameraRange;\n }\n this._breaksAreDirty = false;\n }\n _computeMatrices() {\n const scene = this._scene;\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n Vector3.NormalizeToRef(this._light.getShadowDirection(0), this._lightDirection);\n if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {\n this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\n }\n this._cachedDirection.copyFrom(this._lightDirection);\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._computeFrustumInWorldSpace(cascadeIndex);\n this._computeCascadeFrustum(cascadeIndex);\n this._cascadeMaxExtents[cascadeIndex].subtractToRef(this._cascadeMinExtents[cascadeIndex], tmpv1); // tmpv1 = cascadeExtents\n // Get position of the shadow camera\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection.scale(this._cascadeMinExtents[cascadeIndex].z), this._shadowCameraPos[cascadeIndex]);\n // Come up with a new orthographic camera for the shadow caster\n Matrix.LookAtLHToRef(this._shadowCameraPos[cascadeIndex], this._frustumCenter[cascadeIndex], UpDir, this._viewMatrices[cascadeIndex]);\n let minZ = 0, maxZ = tmpv1.z;\n // Try to tighten minZ and maxZ based on the bounding box of the shadow casters\n const boundingInfo = this._shadowCastersBoundingInfo;\n boundingInfo.update(this._viewMatrices[cascadeIndex]);\n maxZ = Math.min(maxZ, boundingInfo.boundingBox.maximumWorld.z);\n if (!this._depthClamp || this.filter === ShadowGenerator.FILTER_PCSS) {\n // If we don't use depth clamping, we must set minZ so that all shadow casters are in the light frustum\n minZ = Math.min(minZ, boundingInfo.boundingBox.minimumWorld.z);\n }\n else {\n // If using depth clamping, we can adjust minZ to reduce the [minZ, maxZ] range (and get some additional precision in the shadow map)\n minZ = Math.max(minZ, boundingInfo.boundingBox.minimumWorld.z);\n }\n Matrix.OrthoOffCenterLHToRef(this._cascadeMinExtents[cascadeIndex].x, this._cascadeMaxExtents[cascadeIndex].x, this._cascadeMinExtents[cascadeIndex].y, this._cascadeMaxExtents[cascadeIndex].y, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, this._projectionMatrices[cascadeIndex], scene.getEngine().isNDCHalfZRange);\n this._cascadeMinExtents[cascadeIndex].z = minZ;\n this._cascadeMaxExtents[cascadeIndex].z = maxZ;\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\n // Create the rounding matrix, by projecting the world-space origin and determining\n // the fractional offset in texel space\n Vector3.TransformCoordinatesToRef(ZeroVec, this._transformMatrices[cascadeIndex], tmpv1); // tmpv1 = shadowOrigin\n tmpv1.scaleInPlace(this._mapSize / 2);\n tmpv2.copyFromFloats(Math.round(tmpv1.x), Math.round(tmpv1.y), Math.round(tmpv1.z)); // tmpv2 = roundedOrigin\n tmpv2.subtractInPlace(tmpv1).scaleInPlace(2 / this._mapSize); // tmpv2 = roundOffset\n Matrix.TranslationToRef(tmpv2.x, tmpv2.y, 0.0, tmpMatrix);\n this._projectionMatrices[cascadeIndex].multiplyToRef(tmpMatrix, this._projectionMatrices[cascadeIndex]);\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\n this._transformMatrices[cascadeIndex].copyToArray(this._transformMatricesAsArray, cascadeIndex * 16);\n }\n }\n // Get the 8 points of the view frustum in world space\n _computeFrustumInWorldSpace(cascadeIndex) {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const prevSplitDist = this._cascades[cascadeIndex].prevBreakDistance, splitDist = this._cascades[cascadeIndex].breakDistance;\n const isNDCHalfZRange = this._scene.getEngine().isNDCHalfZRange;\n camera.getViewMatrix(); // make sure the transformation matrix we get when calling 'getTransformationMatrix()' is calculated with an up to date view matrix\n const cameraInfiniteFarPlane = camera.maxZ === 0;\n const saveCameraMaxZ = camera.maxZ;\n if (cameraInfiniteFarPlane) {\n camera.maxZ = this._shadowMaxZ;\n camera.getProjectionMatrix(true);\n }\n const invViewProj = Matrix.Invert(camera.getTransformationMatrix());\n if (cameraInfiniteFarPlane) {\n camera.maxZ = saveCameraMaxZ;\n camera.getProjectionMatrix(true);\n }\n const cornerIndexOffset = this._scene.getEngine().useReverseDepthBuffer ? 4 : 0;\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++cornerIndex) {\n tmpv1.copyFrom(CascadedShadowGenerator._FrustumCornersNDCSpace[(cornerIndex + cornerIndexOffset) % CascadedShadowGenerator._FrustumCornersNDCSpace.length]);\n if (isNDCHalfZRange && tmpv1.z === -1) {\n tmpv1.z = 0;\n }\n Vector3.TransformCoordinatesToRef(tmpv1, invViewProj, this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n }\n // Get the corners of the current cascade slice of the view frustum\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length / 2; ++cornerIndex) {\n tmpv1.copyFrom(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4]).subtractInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n tmpv2.copyFrom(tmpv1).scaleInPlace(prevSplitDist); // near corner ray\n tmpv1.scaleInPlace(splitDist); // far corner ray\n tmpv1.addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4].copyFrom(tmpv1);\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].addInPlace(tmpv2);\n }\n }\n _computeCascadeFrustum(cascadeIndex) {\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);\n this._frustumCenter[cascadeIndex].copyFromFloats(0, 0, 0);\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n // Calculate the centroid of the view frustum slice\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n this._frustumCenter[cascadeIndex].addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n }\n this._frustumCenter[cascadeIndex].scaleInPlace(1 / this._frustumCornersWorldSpace[cascadeIndex].length);\n if (this.stabilizeCascades) {\n // Calculate the radius of a bounding sphere surrounding the frustum corners\n let sphereRadius = 0;\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n const dist = this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].subtractToRef(this._frustumCenter[cascadeIndex], tmpv1).length();\n sphereRadius = Math.max(sphereRadius, dist);\n }\n sphereRadius = Math.ceil(sphereRadius * 16) / 16;\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(sphereRadius, sphereRadius, sphereRadius);\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(-sphereRadius, -sphereRadius, -sphereRadius);\n }\n else {\n // Create a temporary view matrix for the light\n const lightCameraPos = this._frustumCenter[cascadeIndex];\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection, tmpv1); // tmpv1 = look at\n Matrix.LookAtLHToRef(lightCameraPos, tmpv1, UpDir, tmpMatrix); // matrix = lightView\n // Calculate an AABB around the frustum corners\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n Vector3.TransformCoordinatesToRef(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex], tmpMatrix, tmpv1);\n this._cascadeMinExtents[cascadeIndex].minimizeInPlace(tmpv1);\n this._cascadeMaxExtents[cascadeIndex].maximizeInPlace(tmpv1);\n }\n }\n }\n _recreateSceneUBOs() {\n this._disposeSceneUBOs();\n if (this._sceneUBOs) {\n for (let i = 0; i < this._numCascades; ++i) {\n this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for CSM Shadow Generator (light \"${this._light.name}\" cascade #${i})`));\n }\n }\n }\n /**\n * Support test.\n */\n static get IsSupported() {\n const engine = EngineStore.LastCreatedEngine;\n if (!engine) {\n return false;\n }\n return engine._features.supportCSM;\n }\n /**\n * Creates a Cascaded Shadow Generator object.\n * A ShadowGenerator is the required tool to use the shadows.\n * Each directional light casting shadows needs to use its own ShadowGenerator.\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\n * @param mapSize The size of the texture what stores the shadows. Example : 1024.\n * @param light The directional light object generating the shadows.\n * @param usefulFloatFirst By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.\n * @param camera Camera associated with this shadow generator (default: null). If null, takes the scene active camera at the time we need to access it\n * @param useRedTextureType Forces the generator to use a Red instead of a RGBA type for the shadow map texture format (default: true)\n */\n constructor(mapSize, light, usefulFloatFirst, camera, useRedTextureType = true) {\n if (!CascadedShadowGenerator.IsSupported) {\n Logger.Error(\"CascadedShadowMap is not supported by the current engine.\");\n return;\n }\n super(mapSize, light, usefulFloatFirst, camera, useRedTextureType);\n this.usePercentageCloserFiltering = true;\n }\n _initializeGenerator() {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;\n this.penumbraDarkness = (_a = this.penumbraDarkness) !== null && _a !== void 0 ? _a : 1.0;\n this._numCascades = (_b = this._numCascades) !== null && _b !== void 0 ? _b : CascadedShadowGenerator.DEFAULT_CASCADES_COUNT;\n this.stabilizeCascades = (_c = this.stabilizeCascades) !== null && _c !== void 0 ? _c : false;\n this._freezeShadowCastersBoundingInfoObservable = (_d = this._freezeShadowCastersBoundingInfoObservable) !== null && _d !== void 0 ? _d : null;\n this.freezeShadowCastersBoundingInfo = (_e = this.freezeShadowCastersBoundingInfo) !== null && _e !== void 0 ? _e : false;\n this._scbiMin = (_f = this._scbiMin) !== null && _f !== void 0 ? _f : new Vector3(0, 0, 0);\n this._scbiMax = (_g = this._scbiMax) !== null && _g !== void 0 ? _g : new Vector3(0, 0, 0);\n this._shadowCastersBoundingInfo = (_h = this._shadowCastersBoundingInfo) !== null && _h !== void 0 ? _h : new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0));\n this._breaksAreDirty = (_j = this._breaksAreDirty) !== null && _j !== void 0 ? _j : true;\n this._minDistance = (_k = this._minDistance) !== null && _k !== void 0 ? _k : 0;\n this._maxDistance = (_l = this._maxDistance) !== null && _l !== void 0 ? _l : 1;\n this._currentLayer = (_m = this._currentLayer) !== null && _m !== void 0 ? _m : 0;\n this._shadowMaxZ = (_q = (_o = this._shadowMaxZ) !== null && _o !== void 0 ? _o : (_p = this._getCamera()) === null || _p === void 0 ? void 0 : _p.maxZ) !== null && _q !== void 0 ? _q : 10000;\n this._debug = (_r = this._debug) !== null && _r !== void 0 ? _r : false;\n this._depthClamp = (_s = this._depthClamp) !== null && _s !== void 0 ? _s : true;\n this._cascadeBlendPercentage = (_t = this._cascadeBlendPercentage) !== null && _t !== void 0 ? _t : 0.1;\n this._lambda = (_u = this._lambda) !== null && _u !== void 0 ? _u : 0.5;\n this._autoCalcDepthBounds = (_v = this._autoCalcDepthBounds) !== null && _v !== void 0 ? _v : false;\n this._recreateSceneUBOs();\n super._initializeGenerator();\n }\n _createTargetRenderTexture() {\n const engine = this._scene.getEngine();\n const size = { width: this._mapSize, height: this._mapSize, layers: this.numCascades };\n this._shadowMap = new RenderTargetTexture(this._light.name + \"_CSMShadowMap\", size, this._scene, false, true, this._textureType, false, undefined, false, false, undefined, this._useRedTextureType ? 6 : 5);\n this._shadowMap.createDepthStencilTexture(engine.useReverseDepthBuffer ? 516 : 513, true);\n this._shadowMap.noPrePassRenderer = true;\n }\n _initializeShadowMap() {\n super._initializeShadowMap();\n if (this._shadowMap === null) {\n return;\n }\n this._transformMatricesAsArray = new Float32Array(this._numCascades * 16);\n this._viewSpaceFrustumsZ = new Array(this._numCascades);\n this._frustumLengths = new Array(this._numCascades);\n this._lightSizeUVCorrection = new Array(this._numCascades * 2);\n this._depthCorrection = new Array(this._numCascades);\n this._cascades = [];\n this._viewMatrices = [];\n this._projectionMatrices = [];\n this._transformMatrices = [];\n this._cascadeMinExtents = [];\n this._cascadeMaxExtents = [];\n this._frustumCenter = [];\n this._shadowCameraPos = [];\n this._frustumCornersWorldSpace = [];\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._cascades[cascadeIndex] = {\n prevBreakDistance: 0,\n breakDistance: 0,\n };\n this._viewMatrices[cascadeIndex] = Matrix.Zero();\n this._projectionMatrices[cascadeIndex] = Matrix.Zero();\n this._transformMatrices[cascadeIndex] = Matrix.Zero();\n this._cascadeMinExtents[cascadeIndex] = new Vector3();\n this._cascadeMaxExtents[cascadeIndex] = new Vector3();\n this._frustumCenter[cascadeIndex] = new Vector3();\n this._shadowCameraPos[cascadeIndex] = new Vector3();\n this._frustumCornersWorldSpace[cascadeIndex] = new Array(CascadedShadowGenerator._FrustumCornersNDCSpace.length);\n for (let i = 0; i < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++i) {\n this._frustumCornersWorldSpace[cascadeIndex][i] = new Vector3();\n }\n }\n const engine = this._scene.getEngine();\n this._shadowMap.onBeforeBindObservable.clear();\n this._shadowMap.onBeforeRenderObservable.clear();\n this._shadowMap.onBeforeRenderObservable.add((layer) => {\n if (this._sceneUBOs) {\n this._scene.setSceneUniformBuffer(this._sceneUBOs[layer]);\n }\n this._currentLayer = layer;\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n engine.setColorWrite(false);\n }\n this._scene.setTransformMatrix(this.getCascadeViewMatrix(layer), this.getCascadeProjectionMatrix(layer));\n if (this._useUBO) {\n this._scene.getSceneUniformBuffer().unbindEffect();\n this._scene.finalizeSceneUbo();\n }\n });\n this._shadowMap.onBeforeBindObservable.add(() => {\n var _a;\n this._currentSceneUBO = this._scene.getSceneUniformBuffer();\n (_a = engine._debugPushGroup) === null || _a === void 0 ? void 0 : _a.call(engine, `cascaded shadow map generation for pass id ${engine.currentRenderPassId}`, 1);\n if (this._breaksAreDirty) {\n this._splitFrustum();\n }\n this._computeMatrices();\n });\n this._splitFrustum();\n }\n _bindCustomEffectForRenderSubMeshForShadowMap(subMesh, effect) {\n effect.setMatrix(\"viewProjection\", this.getCascadeTransformMatrix(this._currentLayer));\n }\n _isReadyCustomDefines(defines) {\n defines.push(\"#define SM_DEPTHCLAMP \" + (this._depthClamp && this._filter !== ShadowGenerator.FILTER_PCSS ? \"1\" : \"0\"));\n }\n /**\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\n * @param defines Defines of the material we want to update\n * @param lightIndex Index of the light in the enabled light list of the material\n */\n prepareDefines(defines, lightIndex) {\n super.prepareDefines(defines, lightIndex);\n const scene = this._scene;\n const light = this._light;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n defines[\"SHADOWCSM\" + lightIndex] = true;\n defines[\"SHADOWCSMDEBUG\" + lightIndex] = this.debug;\n defines[\"SHADOWCSMNUM_CASCADES\" + lightIndex] = this.numCascades;\n defines[\"SHADOWCSM_RIGHTHANDED\" + lightIndex] = scene.useRightHandedSystem;\n const camera = this._getCamera();\n if (camera && this._shadowMaxZ <= (camera.maxZ || this._shadowMaxZ)) {\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + lightIndex] = true;\n }\n if (this.cascadeBlendPercentage === 0) {\n defines[\"SHADOWCSMNOBLEND\" + lightIndex] = true;\n }\n }\n /**\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\n * defined in the generator but impacting the effect).\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\n * @param effect The effect we are binfing the information for\n */\n bindShadowLight(lightIndex, effect) {\n const light = this._light;\n const scene = this._scene;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return;\n }\n const width = shadowMap.getSize().width;\n effect.setMatrices(\"lightMatrix\" + lightIndex, this._transformMatricesAsArray);\n effect.setArray(\"viewFrustumZ\" + lightIndex, this._viewSpaceFrustumsZ);\n effect.setFloat(\"cascadeBlendFactor\" + lightIndex, this.cascadeBlendPercentage === 0 ? 10000 : 1 / this.cascadeBlendPercentage);\n effect.setArray(\"frustumLengths\" + lightIndex, this._frustumLengths);\n // Only PCF uses depth stencil texture.\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, shadowMap);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\n }\n else if (this._filter === ShadowGenerator.FILTER_PCSS) {\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._lightSizeUVCorrection[cascadeIndex * 2 + 0] =\n cascadeIndex === 0\n ? 1\n : (this._cascadeMaxExtents[0].x - this._cascadeMinExtents[0].x) / (this._cascadeMaxExtents[cascadeIndex].x - this._cascadeMinExtents[cascadeIndex].x); // x correction\n this._lightSizeUVCorrection[cascadeIndex * 2 + 1] =\n cascadeIndex === 0\n ? 1\n : (this._cascadeMaxExtents[0].y - this._cascadeMinExtents[0].y) / (this._cascadeMaxExtents[cascadeIndex].y - this._cascadeMinExtents[cascadeIndex].y); // y correction\n this._depthCorrection[cascadeIndex] =\n cascadeIndex === 0\n ? 1\n : (this._cascadeMaxExtents[cascadeIndex].z - this._cascadeMinExtents[cascadeIndex].z) / (this._cascadeMaxExtents[0].z - this._cascadeMinExtents[0].z);\n }\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, shadowMap);\n effect.setTexture(\"depthSampler\" + lightIndex, shadowMap);\n effect.setArray2(\"lightSizeUVCorrection\" + lightIndex, this._lightSizeUVCorrection);\n effect.setArray(\"depthCorrection\" + lightIndex, this._depthCorrection);\n effect.setFloat(\"penumbraDarkness\" + lightIndex, this.penumbraDarkness);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), 1 / width, this._contactHardeningLightSizeUVRatio * width, this.frustumEdgeFalloff, lightIndex);\n }\n else {\n effect.setTexture(\"shadowSampler\" + lightIndex, shadowMap);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\n }\n light._uniformBuffer.updateFloat2(\"depthValues\", this.getLight().getDepthMinZ(camera), this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera), lightIndex);\n }\n /**\n * Gets the transformation matrix of the first cascade used to project the meshes into the map from the light point of view.\n * (eq to view projection * shadow projection matrices)\n * @returns The transform matrix used to create the shadow map\n */\n getTransformMatrix() {\n return this.getCascadeTransformMatrix(0);\n }\n /**\n * Disposes the ShadowGenerator.\n * Returns nothing.\n */\n dispose() {\n super.dispose();\n if (this._freezeShadowCastersBoundingInfoObservable) {\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\n this._freezeShadowCastersBoundingInfoObservable = null;\n }\n if (this._depthReducer) {\n this._depthReducer.dispose();\n this._depthReducer = null;\n }\n }\n /**\n * Serializes the shadow generator setup to a json object.\n * @returns The serialized JSON object\n */\n serialize() {\n const serializationObject = super.serialize();\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return serializationObject;\n }\n serializationObject.numCascades = this._numCascades;\n serializationObject.debug = this._debug;\n serializationObject.stabilizeCascades = this.stabilizeCascades;\n serializationObject.lambda = this._lambda;\n serializationObject.cascadeBlendPercentage = this.cascadeBlendPercentage;\n serializationObject.depthClamp = this._depthClamp;\n serializationObject.autoCalcDepthBounds = this.autoCalcDepthBounds;\n serializationObject.shadowMaxZ = this._shadowMaxZ;\n serializationObject.penumbraDarkness = this.penumbraDarkness;\n serializationObject.freezeShadowCastersBoundingInfo = this._freezeShadowCastersBoundingInfo;\n serializationObject.minDistance = this.minDistance;\n serializationObject.maxDistance = this.maxDistance;\n serializationObject.renderList = [];\n if (shadowMap.renderList) {\n for (let meshIndex = 0; meshIndex < shadowMap.renderList.length; meshIndex++) {\n const mesh = shadowMap.renderList[meshIndex];\n serializationObject.renderList.push(mesh.id);\n }\n }\n return serializationObject;\n }\n /**\n * Parses a serialized ShadowGenerator and returns a new ShadowGenerator.\n * @param parsedShadowGenerator The JSON object to parse\n * @param scene The scene to create the shadow map for\n * @returns The parsed shadow generator\n */\n static Parse(parsedShadowGenerator, scene) {\n const shadowGenerator = ShadowGenerator.Parse(parsedShadowGenerator, scene, (mapSize, light, camera) => new CascadedShadowGenerator(mapSize, light, undefined, camera));\n if (parsedShadowGenerator.numCascades !== undefined) {\n shadowGenerator.numCascades = parsedShadowGenerator.numCascades;\n }\n if (parsedShadowGenerator.debug !== undefined) {\n shadowGenerator.debug = parsedShadowGenerator.debug;\n }\n if (parsedShadowGenerator.stabilizeCascades !== undefined) {\n shadowGenerator.stabilizeCascades = parsedShadowGenerator.stabilizeCascades;\n }\n if (parsedShadowGenerator.lambda !== undefined) {\n shadowGenerator.lambda = parsedShadowGenerator.lambda;\n }\n if (parsedShadowGenerator.cascadeBlendPercentage !== undefined) {\n shadowGenerator.cascadeBlendPercentage = parsedShadowGenerator.cascadeBlendPercentage;\n }\n if (parsedShadowGenerator.depthClamp !== undefined) {\n shadowGenerator.depthClamp = parsedShadowGenerator.depthClamp;\n }\n if (parsedShadowGenerator.autoCalcDepthBounds !== undefined) {\n shadowGenerator.autoCalcDepthBounds = parsedShadowGenerator.autoCalcDepthBounds;\n }\n if (parsedShadowGenerator.shadowMaxZ !== undefined) {\n shadowGenerator.shadowMaxZ = parsedShadowGenerator.shadowMaxZ;\n }\n if (parsedShadowGenerator.penumbraDarkness !== undefined) {\n shadowGenerator.penumbraDarkness = parsedShadowGenerator.penumbraDarkness;\n }\n if (parsedShadowGenerator.freezeShadowCastersBoundingInfo !== undefined) {\n shadowGenerator.freezeShadowCastersBoundingInfo = parsedShadowGenerator.freezeShadowCastersBoundingInfo;\n }\n if (parsedShadowGenerator.minDistance !== undefined && parsedShadowGenerator.maxDistance !== undefined) {\n shadowGenerator.setMinMaxDistance(parsedShadowGenerator.minDistance, parsedShadowGenerator.maxDistance);\n }\n return shadowGenerator;\n }\n }\n CascadedShadowGenerator._FrustumCornersNDCSpace = [\n new Vector3(-1.0, +1.0, -1.0),\n new Vector3(+1.0, +1.0, -1.0),\n new Vector3(+1.0, -1.0, -1.0),\n new Vector3(-1.0, -1.0, -1.0),\n new Vector3(-1.0, +1.0, +1.0),\n new Vector3(+1.0, +1.0, +1.0),\n new Vector3(+1.0, -1.0, +1.0),\n new Vector3(-1.0, -1.0, +1.0),\n ];\n /**\n * Name of the CSM class\n */\n CascadedShadowGenerator.CLASSNAME = \"CascadedShadowGenerator\";\n /**\n * Defines the default number of cascades used by the CSM.\n */\n CascadedShadowGenerator.DEFAULT_CASCADES_COUNT = 4;\n /**\n * Defines the minimum number of cascades used by the CSM.\n */\n CascadedShadowGenerator.MIN_CASCADES_COUNT = 2;\n /**\n * Defines the maximum number of cascades used by the CSM.\n */\n CascadedShadowGenerator.MAX_CASCADES_COUNT = 4;\n /**\n * @internal\n */\n CascadedShadowGenerator._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"ShadowGeneratorSceneComponent\");\n };\n\n // Adds the parser to the scene parsers.\n AbstractScene.AddParser(SceneComponentConstants.NAME_SHADOWGENERATOR, (parsedData, scene) => {\n // Shadows\n if (parsedData.shadowGenerators !== undefined && parsedData.shadowGenerators !== null) {\n for (let index = 0, cache = parsedData.shadowGenerators.length; index < cache; index++) {\n const parsedShadowGenerator = parsedData.shadowGenerators[index];\n if (parsedShadowGenerator.className === CascadedShadowGenerator.CLASSNAME) {\n CascadedShadowGenerator.Parse(parsedShadowGenerator, scene);\n }\n else {\n ShadowGenerator.Parse(parsedShadowGenerator, scene);\n }\n // SG would be available on their associated lights\n }\n }\n });\n /**\n * Defines the shadow generator component responsible to manage any shadow generators\n * in a given scene.\n */\n class ShadowGeneratorSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_SHADOWGENERATOR;\n this.scene = scene;\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_SHADOWGENERATOR, this, this._gatherRenderTargets);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing To Do Here.\n }\n /**\n * Serializes the component data to the specified json object\n * @param serializationObject The object to serialize to\n */\n serialize(serializationObject) {\n // Shadows\n serializationObject.shadowGenerators = [];\n const lights = this.scene.lights;\n for (const light of lights) {\n const shadowGenerators = light.getShadowGenerators();\n if (shadowGenerators) {\n const iterator = shadowGenerators.values();\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\n const shadowGenerator = key.value;\n serializationObject.shadowGenerators.push(shadowGenerator.serialize());\n }\n }\n }\n }\n /**\n * Adds all the elements from the container to the scene\n * @param container the container holding the elements\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n addFromContainer(container) {\n // Nothing To Do Here. (directly attached to a light)\n }\n /**\n * Removes all the elements in the container from the scene\n * @param container contains the elements to remove\n * @param dispose if the removed element should be disposed (default: false)\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n removeFromContainer(container, dispose) {\n // Nothing To Do Here. (directly attached to a light)\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n dispose() {\n // Nothing To Do Here.\n }\n _gatherRenderTargets(renderTargets) {\n // Shadows\n const scene = this.scene;\n if (this.scene.shadowsEnabled) {\n for (let lightIndex = 0; lightIndex < scene.lights.length; lightIndex++) {\n const light = scene.lights[lightIndex];\n const shadowGenerators = light.getShadowGenerators();\n if (light.isEnabled() && light.shadowEnabled && shadowGenerators) {\n const iterator = shadowGenerators.values();\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\n const shadowGenerator = key.value;\n const shadowMap = shadowGenerator.getShadowMap();\n if (scene.textures.indexOf(shadowMap) !== -1) {\n renderTargets.push(shadowMap);\n }\n }\n }\n }\n }\n }\n }\n ShadowGenerator._SceneComponentInitialization = (scene) => {\n let component = scene._getComponent(SceneComponentConstants.NAME_SHADOWGENERATOR);\n if (!component) {\n component = new ShadowGeneratorSceneComponent(scene);\n scene._addComponent(component);\n }\n };\n\n Node.AddNodeConstructor(\"Light_Type_1\", (name, scene) => {\n return () => new DirectionalLight(name, Vector3.Zero(), scene);\n });\n /**\n * A directional light is defined by a direction (what a surprise!).\n * The light is emitted from everywhere in the specified direction, and has an infinite range.\n * An example of a directional light is when a distance planet is lit by the apparently parallel lines of light from its sun. Light in a downward direction will light the top of an object.\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n */\n class DirectionalLight extends ShadowLight {\n /**\n * Fix frustum size for the shadow generation. This is disabled if the value is 0.\n */\n get shadowFrustumSize() {\n return this._shadowFrustumSize;\n }\n /**\n * Specifies a fix frustum size for the shadow generation.\n */\n set shadowFrustumSize(value) {\n this._shadowFrustumSize = value;\n this.forceProjectionMatrixCompute();\n }\n /**\n * Gets the shadow projection scale against the optimal computed one.\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\n */\n get shadowOrthoScale() {\n return this._shadowOrthoScale;\n }\n /**\n * Sets the shadow projection scale against the optimal computed one.\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\n */\n set shadowOrthoScale(value) {\n this._shadowOrthoScale = value;\n this.forceProjectionMatrixCompute();\n }\n /**\n * Gets or sets the orthoLeft property used to build the light frustum\n */\n get orthoLeft() {\n return this._orthoLeft;\n }\n set orthoLeft(left) {\n this._orthoLeft = left;\n }\n /**\n * Gets or sets the orthoRight property used to build the light frustum\n */\n get orthoRight() {\n return this._orthoRight;\n }\n set orthoRight(right) {\n this._orthoRight = right;\n }\n /**\n * Gets or sets the orthoTop property used to build the light frustum\n */\n get orthoTop() {\n return this._orthoTop;\n }\n set orthoTop(top) {\n this._orthoTop = top;\n }\n /**\n * Gets or sets the orthoBottom property used to build the light frustum\n */\n get orthoBottom() {\n return this._orthoBottom;\n }\n set orthoBottom(bottom) {\n this._orthoBottom = bottom;\n }\n /**\n * Creates a DirectionalLight object in the scene, oriented towards the passed direction (Vector3).\n * The directional light is emitted from everywhere in the given direction.\n * It can cast shadows.\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n * @param name The friendly name of the light\n * @param direction The direction of the light\n * @param scene The scene the light belongs to\n */\n constructor(name, direction, scene) {\n super(name, scene);\n this._shadowFrustumSize = 0;\n this._shadowOrthoScale = 0.1;\n /**\n * Automatically compute the projection matrix to best fit (including all the casters)\n * on each frame.\n */\n this.autoUpdateExtends = true;\n /**\n * Automatically compute the shadowMinZ and shadowMaxZ for the projection matrix to best fit (including all the casters)\n * on each frame. autoUpdateExtends must be set to true for this to work\n */\n this.autoCalcShadowZBounds = false;\n // Cache\n this._orthoLeft = Number.MAX_VALUE;\n this._orthoRight = Number.MIN_VALUE;\n this._orthoTop = Number.MIN_VALUE;\n this._orthoBottom = Number.MAX_VALUE;\n this.position = direction.scale(-1.0);\n this.direction = direction;\n }\n /**\n * Returns the string \"DirectionalLight\".\n * @returns The class name\n */\n getClassName() {\n return \"DirectionalLight\";\n }\n /**\n * Returns the integer 1.\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\n */\n getTypeID() {\n return Light.LIGHTTYPEID_DIRECTIONALLIGHT;\n }\n /**\n * Sets the passed matrix \"matrix\" as projection matrix for the shadows cast by the light according to the passed view matrix.\n * Returns the DirectionalLight Shadow projection matrix.\n * @param matrix\n * @param viewMatrix\n * @param renderList\n */\n _setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList) {\n if (this.shadowFrustumSize > 0) {\n this._setDefaultFixedFrustumShadowProjectionMatrix(matrix);\n }\n else {\n this._setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList);\n }\n }\n /**\n * Sets the passed matrix \"matrix\" as fixed frustum projection matrix for the shadows cast by the light according to the passed view matrix.\n * Returns the DirectionalLight Shadow projection matrix.\n * @param matrix\n */\n _setDefaultFixedFrustumShadowProjectionMatrix(matrix) {\n const activeCamera = this.getScene().activeCamera;\n if (!activeCamera) {\n return;\n }\n Matrix.OrthoLHToRef(this.shadowFrustumSize, this.shadowFrustumSize, this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix, this.getScene().getEngine().isNDCHalfZRange);\n }\n /**\n * Sets the passed matrix \"matrix\" as auto extend projection matrix for the shadows cast by the light according to the passed view matrix.\n * Returns the DirectionalLight Shadow projection matrix.\n * @param matrix\n * @param viewMatrix\n * @param renderList\n */\n _setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList) {\n const activeCamera = this.getScene().activeCamera;\n if (!activeCamera) {\n return;\n }\n // Check extends\n if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {\n const tempVector3 = Vector3.Zero();\n this._orthoLeft = Number.MAX_VALUE;\n this._orthoRight = Number.MIN_VALUE;\n this._orthoTop = Number.MIN_VALUE;\n this._orthoBottom = Number.MAX_VALUE;\n let shadowMinZ = Number.MAX_VALUE;\n let shadowMaxZ = Number.MIN_VALUE;\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\n const mesh = renderList[meshIndex];\n if (!mesh) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo();\n const boundingBox = boundingInfo.boundingBox;\n for (let index = 0; index < boundingBox.vectorsWorld.length; index++) {\n Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);\n if (tempVector3.x < this._orthoLeft) {\n this._orthoLeft = tempVector3.x;\n }\n if (tempVector3.y < this._orthoBottom) {\n this._orthoBottom = tempVector3.y;\n }\n if (tempVector3.x > this._orthoRight) {\n this._orthoRight = tempVector3.x;\n }\n if (tempVector3.y > this._orthoTop) {\n this._orthoTop = tempVector3.y;\n }\n if (this.autoCalcShadowZBounds) {\n if (tempVector3.z < shadowMinZ) {\n shadowMinZ = tempVector3.z;\n }\n if (tempVector3.z > shadowMaxZ) {\n shadowMaxZ = tempVector3.z;\n }\n }\n }\n }\n if (this.autoCalcShadowZBounds) {\n this._shadowMinZ = shadowMinZ;\n this._shadowMaxZ = shadowMaxZ;\n }\n }\n const xOffset = this._orthoRight - this._orthoLeft;\n const yOffset = this._orthoTop - this._orthoBottom;\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\n Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale, this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, matrix, this.getScene().getEngine().isNDCHalfZRange);\n }\n _buildUniformLayout() {\n this._uniformBuffer.addUniform(\"vLightData\", 4);\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\n this._uniformBuffer.addUniform(\"depthValues\", 2);\n this._uniformBuffer.create();\n }\n /**\n * Sets the passed Effect object with the DirectionalLight transformed position (or position if not parented) and the passed name.\n * @param effect The effect to update\n * @param lightIndex The index of the light in the effect to update\n * @returns The directional light\n */\n transferToEffect(effect, lightIndex) {\n if (this.computeTransformedInformation()) {\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z, 1, lightIndex);\n return this;\n }\n this._uniformBuffer.updateFloat4(\"vLightData\", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);\n return this;\n }\n transferToNodeMaterialEffect(effect, lightDataUniformName) {\n if (this.computeTransformedInformation()) {\n effect.setFloat3(lightDataUniformName, this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z);\n return this;\n }\n effect.setFloat3(lightDataUniformName, this.direction.x, this.direction.y, this.direction.z);\n return this;\n }\n /**\n * Gets the minZ used for shadow according to both the scene and the light.\n *\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\n * (when not using reverse depth buffer / NDC half Z range)\n * @param activeCamera The camera we are returning the min for\n * @returns the depth min z\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getDepthMinZ(activeCamera) {\n const engine = this._scene.getEngine();\n return !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\n }\n /**\n * Gets the maxZ used for shadow according to both the scene and the light.\n *\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\n * (when not using reverse depth buffer / NDC half Z range)\n * @param activeCamera The camera we are returning the max for\n * @returns the depth max z\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getDepthMaxZ(activeCamera) {\n const engine = this._scene.getEngine();\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\n }\n /**\n * Prepares the list of defines specific to the light type.\n * @param defines the list of defines\n * @param lightIndex defines the index of the light for the effect\n */\n prepareLightSpecificDefines(defines, lightIndex) {\n defines[\"DIRLIGHT\" + lightIndex] = true;\n }\n }\n __decorate$1([\n serialize()\n ], DirectionalLight.prototype, \"shadowFrustumSize\", null);\n __decorate$1([\n serialize()\n ], DirectionalLight.prototype, \"shadowOrthoScale\", null);\n __decorate$1([\n serialize()\n ], DirectionalLight.prototype, \"autoUpdateExtends\", void 0);\n __decorate$1([\n serialize()\n ], DirectionalLight.prototype, \"autoCalcShadowZBounds\", void 0);\n __decorate$1([\n serialize(\"orthoLeft\")\n ], DirectionalLight.prototype, \"_orthoLeft\", void 0);\n __decorate$1([\n serialize(\"orthoRight\")\n ], DirectionalLight.prototype, \"_orthoRight\", void 0);\n __decorate$1([\n serialize(\"orthoTop\")\n ], DirectionalLight.prototype, \"_orthoTop\", void 0);\n __decorate$1([\n serialize(\"orthoBottom\")\n ], DirectionalLight.prototype, \"_orthoBottom\", void 0);\n\n Node.AddNodeConstructor(\"Light_Type_0\", (name, scene) => {\n return () => new PointLight(name, Vector3.Zero(), scene);\n });\n /**\n * A point light is a light defined by an unique point in world space.\n * The light is emitted in every direction from this point.\n * A good example of a point light is a standard light bulb.\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n */\n class PointLight extends ShadowLight {\n /**\n * Getter: In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\n * This specifies what angle the shadow will use to be created.\n *\n * It default to 90 degrees to work nicely with the cube texture generation for point lights shadow maps.\n */\n get shadowAngle() {\n return this._shadowAngle;\n }\n /**\n * Setter: In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\n * This specifies what angle the shadow will use to be created.\n *\n * It default to 90 degrees to work nicely with the cube texture generation for point lights shadow maps.\n */\n set shadowAngle(value) {\n this._shadowAngle = value;\n this.forceProjectionMatrixCompute();\n }\n /**\n * Gets the direction if it has been set.\n * In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\n */\n get direction() {\n return this._direction;\n }\n /**\n * In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\n */\n set direction(value) {\n const previousNeedCube = this.needCube();\n this._direction = value;\n if (this.needCube() !== previousNeedCube && this._shadowGenerators) {\n const iterator = this._shadowGenerators.values();\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\n const shadowGenerator = key.value;\n shadowGenerator.recreateShadowMap();\n }\n }\n }\n /**\n * Creates a PointLight object from the passed name and position (Vector3) and adds it in the scene.\n * A PointLight emits the light in every direction.\n * It can cast shadows.\n * If the scene camera is already defined and you want to set your PointLight at the camera position, just set it :\n * ```javascript\n * var pointLight = new PointLight(\"pl\", camera.position, scene);\n * ```\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n * @param name The light friendly name\n * @param position The position of the point light in the scene\n * @param scene The scene the lights belongs to\n */\n constructor(name, position, scene) {\n super(name, scene);\n this._shadowAngle = Math.PI / 2;\n this.position = position;\n }\n /**\n * Returns the string \"PointLight\"\n * @returns the class name\n */\n getClassName() {\n return \"PointLight\";\n }\n /**\n * Returns the integer 0.\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\n */\n getTypeID() {\n return Light.LIGHTTYPEID_POINTLIGHT;\n }\n /**\n * Specifies whether or not the shadowmap should be a cube texture.\n * @returns true if the shadowmap needs to be a cube texture.\n */\n needCube() {\n return !this.direction;\n }\n /**\n * Returns a new Vector3 aligned with the PointLight cube system according to the passed cube face index (integer).\n * @param faceIndex The index of the face we are computed the direction to generate shadow\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\n */\n getShadowDirection(faceIndex) {\n if (this.direction) {\n return super.getShadowDirection(faceIndex);\n }\n else {\n switch (faceIndex) {\n case 0:\n return new Vector3(1.0, 0.0, 0.0);\n case 1:\n return new Vector3(-1.0, 0.0, 0.0);\n case 2:\n return new Vector3(0.0, -1.0, 0.0);\n case 3:\n return new Vector3(0.0, 1.0, 0.0);\n case 4:\n return new Vector3(0.0, 0.0, 1.0);\n case 5:\n return new Vector3(0.0, 0.0, -1.0);\n }\n }\n return Vector3.Zero();\n }\n /**\n * Sets the passed matrix \"matrix\" as a left-handed perspective projection matrix with the following settings :\n * - fov = PI / 2\n * - aspect ratio : 1.0\n * - z-near and far equal to the active camera minZ and maxZ.\n * Returns the PointLight.\n * @param matrix\n * @param viewMatrix\n * @param renderList\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList) {\n const activeCamera = this.getScene().activeCamera;\n if (!activeCamera) {\n return;\n }\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\n Matrix.PerspectiveFovLHToRef(this.shadowAngle, 1.0, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, matrix, true, this._scene.getEngine().isNDCHalfZRange, undefined, useReverseDepthBuffer);\n }\n _buildUniformLayout() {\n this._uniformBuffer.addUniform(\"vLightData\", 4);\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\n this._uniformBuffer.addUniform(\"vLightFalloff\", 4);\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\n this._uniformBuffer.addUniform(\"depthValues\", 2);\n this._uniformBuffer.create();\n }\n /**\n * Sets the passed Effect \"effect\" with the PointLight transformed position (or position, if none) and passed name (string).\n * @param effect The effect to update\n * @param lightIndex The index of the light in the effect to update\n * @returns The point light\n */\n transferToEffect(effect, lightIndex) {\n if (this.computeTransformedInformation()) {\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, 0.0, lightIndex);\n }\n else {\n this._uniformBuffer.updateFloat4(\"vLightData\", this.position.x, this.position.y, this.position.z, 0, lightIndex);\n }\n this._uniformBuffer.updateFloat4(\"vLightFalloff\", this.range, this._inverseSquaredRange, 0, 0, lightIndex);\n return this;\n }\n transferToNodeMaterialEffect(effect, lightDataUniformName) {\n if (this.computeTransformedInformation()) {\n effect.setFloat3(lightDataUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z);\n }\n else {\n effect.setFloat3(lightDataUniformName, this.position.x, this.position.y, this.position.z);\n }\n return this;\n }\n /**\n * Prepares the list of defines specific to the light type.\n * @param defines the list of defines\n * @param lightIndex defines the index of the light for the effect\n */\n prepareLightSpecificDefines(defines, lightIndex) {\n defines[\"POINTLIGHT\" + lightIndex] = true;\n }\n }\n __decorate$1([\n serialize()\n ], PointLight.prototype, \"shadowAngle\", null);\n\n Node.AddNodeConstructor(\"Light_Type_2\", (name, scene) => {\n return () => new SpotLight(name, Vector3.Zero(), Vector3.Zero(), 0, 0, scene);\n });\n /**\n * A spot light is defined by a position, a direction, an angle, and an exponent.\n * These values define a cone of light starting from the position, emitting toward the direction.\n * The angle, in radians, defines the size (field of illumination) of the spotlight's conical beam,\n * and the exponent defines the speed of the decay of the light with distance (reach).\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n */\n class SpotLight extends ShadowLight {\n /**\n * Gets the cone angle of the spot light in Radians.\n */\n get angle() {\n return this._angle;\n }\n /**\n * Sets the cone angle of the spot light in Radians.\n */\n set angle(value) {\n this._angle = value;\n this._cosHalfAngle = Math.cos(value * 0.5);\n this._projectionTextureProjectionLightDirty = true;\n this.forceProjectionMatrixCompute();\n this._computeAngleValues();\n }\n /**\n * Only used in gltf falloff mode, this defines the angle where\n * the directional falloff will start before cutting at angle which could be seen\n * as outer angle.\n */\n get innerAngle() {\n return this._innerAngle;\n }\n /**\n * Only used in gltf falloff mode, this defines the angle where\n * the directional falloff will start before cutting at angle which could be seen\n * as outer angle.\n */\n set innerAngle(value) {\n this._innerAngle = value;\n this._computeAngleValues();\n }\n /**\n * Allows scaling the angle of the light for shadow generation only.\n */\n get shadowAngleScale() {\n return this._shadowAngleScale;\n }\n /**\n * Allows scaling the angle of the light for shadow generation only.\n */\n set shadowAngleScale(value) {\n this._shadowAngleScale = value;\n this.forceProjectionMatrixCompute();\n }\n /**\n * Allows reading the projection texture\n */\n get projectionTextureMatrix() {\n return this._projectionTextureMatrix;\n }\n /**\n * Gets the near clip of the Spotlight for texture projection.\n */\n get projectionTextureLightNear() {\n return this._projectionTextureLightNear;\n }\n /**\n * Sets the near clip of the Spotlight for texture projection.\n */\n set projectionTextureLightNear(value) {\n this._projectionTextureLightNear = value;\n this._projectionTextureProjectionLightDirty = true;\n }\n /**\n * Gets the far clip of the Spotlight for texture projection.\n */\n get projectionTextureLightFar() {\n return this._projectionTextureLightFar;\n }\n /**\n * Sets the far clip of the Spotlight for texture projection.\n */\n set projectionTextureLightFar(value) {\n this._projectionTextureLightFar = value;\n this._projectionTextureProjectionLightDirty = true;\n }\n /**\n * Gets the Up vector of the Spotlight for texture projection.\n */\n get projectionTextureUpDirection() {\n return this._projectionTextureUpDirection;\n }\n /**\n * Sets the Up vector of the Spotlight for texture projection.\n */\n set projectionTextureUpDirection(value) {\n this._projectionTextureUpDirection = value;\n this._projectionTextureProjectionLightDirty = true;\n }\n /**\n * Gets the projection texture of the light.\n */\n get projectionTexture() {\n return this._projectionTexture;\n }\n /**\n * Sets the projection texture of the light.\n */\n set projectionTexture(value) {\n if (this._projectionTexture === value) {\n return;\n }\n this._projectionTexture = value;\n this._projectionTextureDirty = true;\n if (this._projectionTexture && !this._projectionTexture.isReady()) {\n if (SpotLight._IsProceduralTexture(this._projectionTexture)) {\n this._projectionTexture.getEffect().executeWhenCompiled(() => {\n this._markMeshesAsLightDirty();\n });\n }\n else if (SpotLight._IsTexture(this._projectionTexture)) {\n this._projectionTexture.onLoadObservable.addOnce(() => {\n this._markMeshesAsLightDirty();\n });\n }\n }\n }\n static _IsProceduralTexture(texture) {\n return texture.onGeneratedObservable !== undefined;\n }\n static _IsTexture(texture) {\n return texture.onLoadObservable !== undefined;\n }\n /**\n * Gets or sets the light projection matrix as used by the projection texture\n */\n get projectionTextureProjectionLightMatrix() {\n return this._projectionTextureProjectionLightMatrix;\n }\n set projectionTextureProjectionLightMatrix(projection) {\n this._projectionTextureProjectionLightMatrix = projection;\n this._projectionTextureProjectionLightDirty = false;\n this._projectionTextureDirty = true;\n }\n /**\n * Creates a SpotLight object in the scene. A spot light is a simply light oriented cone.\n * It can cast shadows.\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\n * @param name The light friendly name\n * @param position The position of the spot light in the scene\n * @param direction The direction of the light in the scene\n * @param angle The cone angle of the light in Radians\n * @param exponent The light decay speed with the distance from the emission spot\n * @param scene The scene the lights belongs to\n */\n constructor(name, position, direction, angle, exponent, scene) {\n super(name, scene);\n this._innerAngle = 0;\n this._projectionTextureMatrix = Matrix.Zero();\n this._projectionTextureLightNear = 1e-6;\n this._projectionTextureLightFar = 1000.0;\n this._projectionTextureUpDirection = Vector3.Up();\n this._projectionTextureViewLightDirty = true;\n this._projectionTextureProjectionLightDirty = true;\n this._projectionTextureDirty = true;\n this._projectionTextureViewTargetVector = Vector3.Zero();\n this._projectionTextureViewLightMatrix = Matrix.Zero();\n this._projectionTextureProjectionLightMatrix = Matrix.Zero();\n this._projectionTextureScalingMatrix = Matrix.FromValues(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);\n this.position = position;\n this.direction = direction;\n this.angle = angle;\n this.exponent = exponent;\n }\n /**\n * Returns the string \"SpotLight\".\n * @returns the class name\n */\n getClassName() {\n return \"SpotLight\";\n }\n /**\n * Returns the integer 2.\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\n */\n getTypeID() {\n return Light.LIGHTTYPEID_SPOTLIGHT;\n }\n /**\n * Overrides the direction setter to recompute the projection texture view light Matrix.\n * @param value\n */\n _setDirection(value) {\n super._setDirection(value);\n this._projectionTextureViewLightDirty = true;\n }\n /**\n * Overrides the position setter to recompute the projection texture view light Matrix.\n * @param value\n */\n _setPosition(value) {\n super._setPosition(value);\n this._projectionTextureViewLightDirty = true;\n }\n /**\n * Sets the passed matrix \"matrix\" as perspective projection matrix for the shadows and the passed view matrix with the fov equal to the SpotLight angle and and aspect ratio of 1.0.\n * Returns the SpotLight.\n * @param matrix\n * @param viewMatrix\n * @param renderList\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList) {\n const activeCamera = this.getScene().activeCamera;\n if (!activeCamera) {\n return;\n }\n this._shadowAngleScale = this._shadowAngleScale || 1;\n const angle = this._shadowAngleScale * this._angle;\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\n Matrix.PerspectiveFovLHToRef(angle, 1.0, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, matrix, true, this._scene.getEngine().isNDCHalfZRange, undefined, useReverseDepthBuffer);\n }\n _computeProjectionTextureViewLightMatrix() {\n this._projectionTextureViewLightDirty = false;\n this._projectionTextureDirty = true;\n this.getAbsolutePosition().addToRef(this.direction, this._projectionTextureViewTargetVector);\n Matrix.LookAtLHToRef(this.getAbsolutePosition(), this._projectionTextureViewTargetVector, this._projectionTextureUpDirection, this._projectionTextureViewLightMatrix);\n }\n _computeProjectionTextureProjectionLightMatrix() {\n this._projectionTextureProjectionLightDirty = false;\n this._projectionTextureDirty = true;\n const lightFar = this.projectionTextureLightFar;\n const lightNear = this.projectionTextureLightNear;\n const P = lightFar / (lightFar - lightNear);\n const Q = -P * lightNear;\n const S = 1.0 / Math.tan(this._angle / 2.0);\n const A = 1.0;\n Matrix.FromValuesToRef(S / A, 0.0, 0.0, 0.0, 0.0, S, 0.0, 0.0, 0.0, 0.0, P, 1.0, 0.0, 0.0, Q, 0.0, this._projectionTextureProjectionLightMatrix);\n }\n /**\n * Main function for light texture projection matrix computing.\n */\n _computeProjectionTextureMatrix() {\n this._projectionTextureDirty = false;\n this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix, this._projectionTextureMatrix);\n if (this._projectionTexture instanceof Texture) {\n const u = this._projectionTexture.uScale / 2.0;\n const v = this._projectionTexture.vScale / 2.0;\n Matrix.FromValuesToRef(u, 0.0, 0.0, 0.0, 0.0, v, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, this._projectionTextureScalingMatrix);\n }\n this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix, this._projectionTextureMatrix);\n }\n _buildUniformLayout() {\n this._uniformBuffer.addUniform(\"vLightData\", 4);\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\n this._uniformBuffer.addUniform(\"vLightDirection\", 3);\n this._uniformBuffer.addUniform(\"vLightFalloff\", 4);\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\n this._uniformBuffer.addUniform(\"depthValues\", 2);\n this._uniformBuffer.create();\n }\n _computeAngleValues() {\n this._lightAngleScale = 1.0 / Math.max(0.001, Math.cos(this._innerAngle * 0.5) - this._cosHalfAngle);\n this._lightAngleOffset = -this._cosHalfAngle * this._lightAngleScale;\n }\n /**\n * Sets the passed Effect \"effect\" with the Light textures.\n * @param effect The effect to update\n * @param lightIndex The index of the light in the effect to update\n * @returns The light\n */\n transferTexturesToEffect(effect, lightIndex) {\n if (this.projectionTexture && this.projectionTexture.isReady()) {\n if (this._projectionTextureViewLightDirty) {\n this._computeProjectionTextureViewLightMatrix();\n }\n if (this._projectionTextureProjectionLightDirty) {\n this._computeProjectionTextureProjectionLightMatrix();\n }\n if (this._projectionTextureDirty) {\n this._computeProjectionTextureMatrix();\n }\n effect.setMatrix(\"textureProjectionMatrix\" + lightIndex, this._projectionTextureMatrix);\n effect.setTexture(\"projectionLightSampler\" + lightIndex, this.projectionTexture);\n }\n return this;\n }\n /**\n * Sets the passed Effect object with the SpotLight transformed position (or position if not parented) and normalized direction.\n * @param effect The effect to update\n * @param lightIndex The index of the light in the effect to update\n * @returns The spot light\n */\n transferToEffect(effect, lightIndex) {\n let normalizeDirection;\n if (this.computeTransformedInformation()) {\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent, lightIndex);\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\n }\n else {\n this._uniformBuffer.updateFloat4(\"vLightData\", this.position.x, this.position.y, this.position.z, this.exponent, lightIndex);\n normalizeDirection = Vector3.Normalize(this.direction);\n }\n this._uniformBuffer.updateFloat4(\"vLightDirection\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, this._cosHalfAngle, lightIndex);\n this._uniformBuffer.updateFloat4(\"vLightFalloff\", this.range, this._inverseSquaredRange, this._lightAngleScale, this._lightAngleOffset, lightIndex);\n return this;\n }\n transferToNodeMaterialEffect(effect, lightDataUniformName) {\n let normalizeDirection;\n if (this.computeTransformedInformation()) {\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\n }\n else {\n normalizeDirection = Vector3.Normalize(this.direction);\n }\n if (this.getScene().useRightHandedSystem) {\n effect.setFloat3(lightDataUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z);\n }\n else {\n effect.setFloat3(lightDataUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z);\n }\n return this;\n }\n /**\n * Disposes the light and the associated resources.\n */\n dispose() {\n super.dispose();\n if (this._projectionTexture) {\n this._projectionTexture.dispose();\n }\n }\n /**\n * Gets the minZ used for shadow according to both the scene and the light.\n * @param activeCamera The camera we are returning the min for\n * @returns the depth min z\n */\n getDepthMinZ(activeCamera) {\n const engine = this._scene.getEngine();\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? minZ : this._scene.getEngine().isNDCHalfZRange ? 0 : minZ;\n }\n /**\n * Gets the maxZ used for shadow according to both the scene and the light.\n * @param activeCamera The camera we are returning the max for\n * @returns the depth max z\n */\n getDepthMaxZ(activeCamera) {\n const engine = this._scene.getEngine();\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : maxZ;\n }\n /**\n * Prepares the list of defines specific to the light type.\n * @param defines the list of defines\n * @param lightIndex defines the index of the light for the effect\n */\n prepareLightSpecificDefines(defines, lightIndex) {\n defines[\"SPOTLIGHT\" + lightIndex] = true;\n defines[\"PROJECTEDLIGHTTEXTURE\" + lightIndex] = this.projectionTexture && this.projectionTexture.isReady() ? true : false;\n }\n }\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"angle\", null);\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"innerAngle\", null);\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"shadowAngleScale\", null);\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"exponent\", void 0);\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"projectionTextureLightNear\", null);\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"projectionTextureLightFar\", null);\n __decorate$1([\n serialize()\n ], SpotLight.prototype, \"projectionTextureUpDirection\", null);\n __decorate$1([\n serializeAsTexture(\"projectedLightTexture\")\n ], SpotLight.prototype, \"_projectionTexture\", void 0);\n\n /**\n * Defines the root class used to create scene optimization to use with SceneOptimizer\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n return true;\n }\n /**\n * Creates the SceneOptimization object\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\n */\n constructor(\n /**\n * Defines the priority of this optimization (0 by default which means first in the list)\n */\n priority = 0) {\n this.priority = priority;\n }\n }\n /**\n * Defines an optimization used to reduce the size of render target textures\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class TextureOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Reducing render target texture size to \" + this.maximumSize;\n }\n /**\n * Creates the TextureOptimization object\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\n * @param maximumSize defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter\n * @param step defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.\n */\n constructor(\n /**\n * Defines the priority of this optimization (0 by default which means first in the list)\n */\n priority = 0, \n /**\n * Defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter\n */\n maximumSize = 1024, \n /**\n * Defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.\n */\n step = 0.5) {\n super(priority);\n this.priority = priority;\n this.maximumSize = maximumSize;\n this.step = step;\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n let allDone = true;\n for (let index = 0; index < scene.textures.length; index++) {\n const texture = scene.textures[index];\n if (!texture.canRescale || texture.getContext) {\n continue;\n }\n const currentSize = texture.getSize();\n const maxDimension = Math.max(currentSize.width, currentSize.height);\n if (maxDimension > this.maximumSize) {\n texture.scale(this.step);\n allDone = false;\n }\n }\n return allDone;\n }\n }\n /**\n * Defines an optimization used to increase or decrease the rendering resolution\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class HardwareScalingOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Setting hardware scaling level to \" + this._currentScale;\n }\n /**\n * Creates the HardwareScalingOptimization object\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\n * @param maximumScale defines the maximum scale to use (2 by default)\n * @param step defines the step to use between two passes (0.5 by default)\n */\n constructor(\n /**\n * Defines the priority of this optimization (0 by default which means first in the list)\n */\n priority = 0, \n /**\n * Defines the maximum scale to use (2 by default)\n */\n maximumScale = 2, \n /**\n * Defines the step to use between two passes (0.5 by default)\n */\n step = 0.25) {\n super(priority);\n this.priority = priority;\n this.maximumScale = maximumScale;\n this.step = step;\n this._currentScale = -1;\n this._directionOffset = 1;\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n if (this._currentScale === -1) {\n this._currentScale = scene.getEngine().getHardwareScalingLevel();\n if (this._currentScale > this.maximumScale) {\n this._directionOffset = -1;\n }\n }\n this._currentScale += this._directionOffset * this.step;\n scene.getEngine().setHardwareScalingLevel(this._currentScale);\n return this._directionOffset === 1 ? this._currentScale >= this.maximumScale : this._currentScale <= this.maximumScale;\n }\n }\n /**\n * Defines an optimization used to remove shadows\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class ShadowsOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Turning shadows on/off\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n scene.shadowsEnabled = optimizer.isInImprovementMode;\n return true;\n }\n }\n /**\n * Defines an optimization used to turn post-processes off\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class PostProcessesOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Turning post-processes on/off\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n scene.postProcessesEnabled = optimizer.isInImprovementMode;\n return true;\n }\n }\n /**\n * Defines an optimization used to turn lens flares off\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class LensFlaresOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Turning lens flares on/off\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n scene.lensFlaresEnabled = optimizer.isInImprovementMode;\n return true;\n }\n }\n /**\n * Defines an optimization based on user defined callback.\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class CustomOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n if (this.onGetDescription) {\n return this.onGetDescription();\n }\n return \"Running user defined callback\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n if (this.onApply) {\n return this.onApply(scene, optimizer);\n }\n return true;\n }\n }\n /**\n * Defines an optimization used to turn particles off\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class ParticlesOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Turning particles on/off\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n scene.particlesEnabled = optimizer.isInImprovementMode;\n return true;\n }\n }\n /**\n * Defines an optimization used to turn render targets off\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class RenderTargetsOptimization extends SceneOptimization {\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Turning render targets off\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer) {\n scene.renderTargetsEnabled = optimizer.isInImprovementMode;\n return true;\n }\n }\n /**\n * Defines an optimization used to merge meshes with compatible materials\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class MergeMeshesOptimization extends SceneOptimization {\n constructor() {\n super(...arguments);\n this._canBeMerged = (abstractMesh) => {\n if (!(abstractMesh instanceof Mesh)) {\n return false;\n }\n const mesh = abstractMesh;\n if (mesh.isDisposed()) {\n return false;\n }\n if (!mesh.isVisible || !mesh.isEnabled()) {\n return false;\n }\n if (mesh.instances.length > 0) {\n return false;\n }\n if (mesh.skeleton || mesh.hasLODLevels) {\n return false;\n }\n if (mesh.getTotalVertices() === 0) {\n return false;\n }\n return true;\n };\n }\n /**\n * Gets or sets a boolean which defines if optimization octree has to be updated\n */\n static get UpdateSelectionTree() {\n return MergeMeshesOptimization._UpdateSelectionTree;\n }\n /**\n * Gets or sets a boolean which defines if optimization octree has to be updated\n */\n static set UpdateSelectionTree(value) {\n MergeMeshesOptimization._UpdateSelectionTree = value;\n }\n /**\n * Gets a string describing the action executed by the current optimization\n * @returns description string\n */\n getDescription() {\n return \"Merging similar meshes together\";\n }\n /**\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\n * @param scene defines the current scene where to apply this optimization\n * @param optimizer defines the current optimizer\n * @param updateSelectionTree defines that the selection octree has to be updated (false by default)\n * @returns true if everything that can be done was applied\n */\n apply(scene, optimizer, updateSelectionTree) {\n const globalPool = scene.meshes.slice(0);\n let globalLength = globalPool.length;\n for (let index = 0; index < globalLength; index++) {\n const currentPool = new Array();\n const current = globalPool[index];\n // Checks\n if (!this._canBeMerged(current)) {\n continue;\n }\n currentPool.push(current);\n // Find compatible meshes\n for (let subIndex = index + 1; subIndex < globalLength; subIndex++) {\n const otherMesh = globalPool[subIndex];\n if (!this._canBeMerged(otherMesh)) {\n continue;\n }\n if (otherMesh.material !== current.material) {\n continue;\n }\n if (otherMesh.checkCollisions !== current.checkCollisions) {\n continue;\n }\n currentPool.push(otherMesh);\n globalLength--;\n globalPool.splice(subIndex, 1);\n subIndex--;\n }\n if (currentPool.length < 2) {\n continue;\n }\n // Merge meshes\n Mesh.MergeMeshes(currentPool, undefined, true);\n }\n // Call the octree system optimization if it is defined.\n const sceneAsAny = scene;\n if (sceneAsAny.createOrUpdateSelectionOctree) {\n if (updateSelectionTree != undefined) {\n if (updateSelectionTree) {\n sceneAsAny.createOrUpdateSelectionOctree();\n }\n }\n else if (MergeMeshesOptimization.UpdateSelectionTree) {\n sceneAsAny.createOrUpdateSelectionOctree();\n }\n }\n return true;\n }\n }\n MergeMeshesOptimization._UpdateSelectionTree = false;\n /**\n * Defines a list of options used by SceneOptimizer\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class SceneOptimizerOptions {\n /**\n * Creates a new list of options used by SceneOptimizer\n * @param targetFrameRate defines the target frame rate to reach (60 by default)\n * @param trackerDuration defines the interval between two checks (2000ms by default)\n */\n constructor(\n /**\n * Defines the target frame rate to reach (60 by default)\n */\n targetFrameRate = 60, \n /**\n * Defines the interval between two checks (2000ms by default)\n */\n trackerDuration = 2000) {\n this.targetFrameRate = targetFrameRate;\n this.trackerDuration = trackerDuration;\n /**\n * Gets the list of optimizations to apply\n */\n this.optimizations = new Array();\n }\n /**\n * Add a new optimization\n * @param optimization defines the SceneOptimization to add to the list of active optimizations\n * @returns the current SceneOptimizerOptions\n */\n addOptimization(optimization) {\n this.optimizations.push(optimization);\n return this;\n }\n /**\n * Add a new custom optimization\n * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)\n * @param onGetDescription defines the callback called to get the description attached with the optimization.\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\n * @returns the current SceneOptimizerOptions\n */\n addCustomOptimization(onApply, onGetDescription, priority = 0) {\n const optimization = new CustomOptimization(priority);\n optimization.onApply = onApply;\n optimization.onGetDescription = onGetDescription;\n this.optimizations.push(optimization);\n return this;\n }\n /**\n * Creates a list of pre-defined optimizations aimed to reduce the visual impact on the scene\n * @param targetFrameRate defines the target frame rate (60 by default)\n * @returns a SceneOptimizerOptions object\n */\n static LowDegradationAllowed(targetFrameRate) {\n const result = new SceneOptimizerOptions(targetFrameRate);\n let priority = 0;\n result.addOptimization(new MergeMeshesOptimization(priority));\n result.addOptimization(new ShadowsOptimization(priority));\n result.addOptimization(new LensFlaresOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new PostProcessesOptimization(priority));\n result.addOptimization(new ParticlesOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new TextureOptimization(priority, 1024));\n return result;\n }\n /**\n * Creates a list of pre-defined optimizations aimed to have a moderate impact on the scene visual\n * @param targetFrameRate defines the target frame rate (60 by default)\n * @returns a SceneOptimizerOptions object\n */\n static ModerateDegradationAllowed(targetFrameRate) {\n const result = new SceneOptimizerOptions(targetFrameRate);\n let priority = 0;\n result.addOptimization(new MergeMeshesOptimization(priority));\n result.addOptimization(new ShadowsOptimization(priority));\n result.addOptimization(new LensFlaresOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new PostProcessesOptimization(priority));\n result.addOptimization(new ParticlesOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new TextureOptimization(priority, 512));\n // Next priority\n priority++;\n result.addOptimization(new RenderTargetsOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new HardwareScalingOptimization(priority, 2));\n return result;\n }\n /**\n * Creates a list of pre-defined optimizations aimed to have a big impact on the scene visual\n * @param targetFrameRate defines the target frame rate (60 by default)\n * @returns a SceneOptimizerOptions object\n */\n static HighDegradationAllowed(targetFrameRate) {\n const result = new SceneOptimizerOptions(targetFrameRate);\n let priority = 0;\n result.addOptimization(new MergeMeshesOptimization(priority));\n result.addOptimization(new ShadowsOptimization(priority));\n result.addOptimization(new LensFlaresOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new PostProcessesOptimization(priority));\n result.addOptimization(new ParticlesOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new TextureOptimization(priority, 256));\n // Next priority\n priority++;\n result.addOptimization(new RenderTargetsOptimization(priority));\n // Next priority\n priority++;\n result.addOptimization(new HardwareScalingOptimization(priority, 4));\n return result;\n }\n }\n /**\n * Class used to run optimizations in order to reach a target frame rate\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\n */\n class SceneOptimizer {\n /**\n * Gets or sets a boolean indicating if the optimizer is in improvement mode\n */\n get isInImprovementMode() {\n return this._improvementMode;\n }\n set isInImprovementMode(value) {\n this._improvementMode = value;\n }\n /**\n * Gets the current priority level (0 at start)\n */\n get currentPriorityLevel() {\n return this._currentPriorityLevel;\n }\n /**\n * Gets the current frame rate checked by the SceneOptimizer\n */\n get currentFrameRate() {\n return this._currentFrameRate;\n }\n /**\n * Gets or sets the current target frame rate (60 by default)\n */\n get targetFrameRate() {\n return this._targetFrameRate;\n }\n /**\n * Gets or sets the current target frame rate (60 by default)\n */\n set targetFrameRate(value) {\n this._targetFrameRate = value;\n }\n /**\n * Gets or sets the current interval between two checks (every 2000ms by default)\n */\n get trackerDuration() {\n return this._trackerDuration;\n }\n /**\n * Gets or sets the current interval between two checks (every 2000ms by default)\n */\n set trackerDuration(value) {\n this._trackerDuration = value;\n }\n /**\n * Gets the list of active optimizations\n */\n get optimizations() {\n return this._options.optimizations;\n }\n /**\n * Creates a new SceneOptimizer\n * @param scene defines the scene to work on\n * @param options defines the options to use with the SceneOptimizer\n * @param autoGeneratePriorities defines if priorities must be generated and not read from SceneOptimization property (true by default)\n * @param improvementMode defines if the scene optimizer must run the maximum optimization while staying over a target frame instead of trying to reach the target framerate (false by default)\n */\n constructor(scene, options, autoGeneratePriorities = true, improvementMode = false) {\n this._isRunning = false;\n this._currentPriorityLevel = 0;\n this._targetFrameRate = 60;\n this._trackerDuration = 2000;\n this._currentFrameRate = 0;\n this._improvementMode = false;\n /**\n * Defines an observable called when the optimizer reaches the target frame rate\n */\n this.onSuccessObservable = new Observable$1();\n /**\n * Defines an observable called when the optimizer enables an optimization\n */\n this.onNewOptimizationAppliedObservable = new Observable$1();\n /**\n * Defines an observable called when the optimizer is not able to reach the target frame rate\n */\n this.onFailureObservable = new Observable$1();\n if (!options) {\n this._options = new SceneOptimizerOptions();\n }\n else {\n this._options = options;\n }\n if (this._options.targetFrameRate) {\n this._targetFrameRate = this._options.targetFrameRate;\n }\n if (this._options.trackerDuration) {\n this._trackerDuration = this._options.trackerDuration;\n }\n if (autoGeneratePriorities) {\n let priority = 0;\n for (const optim of this._options.optimizations) {\n optim.priority = priority++;\n }\n }\n this._improvementMode = improvementMode;\n this._scene = scene || EngineStore.LastCreatedScene;\n this._sceneDisposeObserver = this._scene.onDisposeObservable.add(() => {\n this._sceneDisposeObserver = null;\n this.dispose();\n });\n }\n /**\n * Stops the current optimizer\n */\n stop() {\n this._isRunning = false;\n }\n /**\n * Reset the optimizer to initial step (current priority level = 0)\n */\n reset() {\n this._currentPriorityLevel = 0;\n }\n /**\n * Start the optimizer. By default it will try to reach a specific framerate\n * but if the optimizer is set with improvementMode === true then it will run all optimization while frame rate is above the target frame rate\n */\n start() {\n if (this._isRunning) {\n return;\n }\n this._isRunning = true;\n // Let's wait for the scene to be ready before running our check\n this._scene.executeWhenReady(() => {\n setTimeout(() => {\n this._checkCurrentState();\n }, this._trackerDuration);\n });\n }\n _checkCurrentState() {\n if (!this._isRunning) {\n return;\n }\n const scene = this._scene;\n const options = this._options;\n this._currentFrameRate = Math.round(scene.getEngine().getFps());\n if ((this._improvementMode && this._currentFrameRate <= this._targetFrameRate) || (!this._improvementMode && this._currentFrameRate >= this._targetFrameRate)) {\n this._isRunning = false;\n this.onSuccessObservable.notifyObservers(this);\n return;\n }\n // Apply current level of optimizations\n let allDone = true;\n let noOptimizationApplied = true;\n for (let index = 0; index < options.optimizations.length; index++) {\n const optimization = options.optimizations[index];\n if (optimization.priority === this._currentPriorityLevel) {\n noOptimizationApplied = false;\n allDone = allDone && optimization.apply(scene, this);\n this.onNewOptimizationAppliedObservable.notifyObservers(optimization);\n }\n }\n // If no optimization was applied, this is a failure :(\n if (noOptimizationApplied) {\n this._isRunning = false;\n this.onFailureObservable.notifyObservers(this);\n return;\n }\n // If all optimizations were done, move to next level\n if (allDone) {\n this._currentPriorityLevel++;\n }\n // Let's the system running for a specific amount of time before checking FPS\n scene.executeWhenReady(() => {\n setTimeout(() => {\n this._checkCurrentState();\n }, this._trackerDuration);\n });\n }\n /**\n * Release all resources\n */\n dispose() {\n this.stop();\n this.onSuccessObservable.clear();\n this.onFailureObservable.clear();\n this.onNewOptimizationAppliedObservable.clear();\n if (this._sceneDisposeObserver) {\n this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);\n }\n }\n /**\n * Helper function to create a SceneOptimizer with one single line of code\n * @param scene defines the scene to work on\n * @param options defines the options to use with the SceneOptimizer\n * @param onSuccess defines a callback to call on success\n * @param onFailure defines a callback to call on failure\n * @returns the new SceneOptimizer object\n */\n static OptimizeAsync(scene, options, onSuccess, onFailure) {\n const optimizer = new SceneOptimizer(scene, options || SceneOptimizerOptions.ModerateDegradationAllowed(), false);\n if (onSuccess) {\n optimizer.onSuccessObservable.add(() => {\n onSuccess();\n });\n }\n if (onFailure) {\n optimizer.onFailureObservable.add(() => {\n onFailure();\n });\n }\n optimizer.start();\n return optimizer;\n }\n }\n\n let serializedGeometries = [];\n const SerializeGeometry = (geometry, serializationGeometries) => {\n if (geometry.doNotSerialize) {\n return;\n }\n serializationGeometries.vertexData.push(geometry.serializeVerticeData());\n serializedGeometries[geometry.id] = true;\n };\n const SerializeMesh = (mesh, serializationScene) => {\n const serializationObject = {};\n // Geometry\n const geometry = mesh._geometry;\n if (geometry) {\n if (!mesh.getScene().getGeometryById(geometry.id)) {\n // Geometry was in the memory but not added to the scene, nevertheless it's better to serialize to be able to reload the mesh with its geometry\n SerializeGeometry(geometry, serializationScene.geometries);\n }\n }\n // Custom\n if (mesh.serialize) {\n mesh.serialize(serializationObject);\n }\n return serializationObject;\n };\n const FinalizeSingleNode = (node, serializationObject) => {\n if (node._isMesh) {\n const mesh = node;\n //only works if the mesh is already loaded\n if (mesh.delayLoadState === 1 || mesh.delayLoadState === 0) {\n const serializeMaterial = (material) => {\n serializationObject.materials = serializationObject.materials || [];\n if (mesh.material && !serializationObject.materials.some((mat) => mat.id === mesh.material.id)) {\n serializationObject.materials.push(material.serialize());\n }\n };\n //serialize material\n if (mesh.material && !mesh.material.doNotSerialize) {\n if (mesh.material instanceof MultiMaterial) {\n serializationObject.multiMaterials = serializationObject.multiMaterials || [];\n if (!serializationObject.multiMaterials.some((mat) => mat.id === mesh.material.id)) {\n serializationObject.multiMaterials.push(mesh.material.serialize());\n for (const submaterial of mesh.material.subMaterials) {\n if (submaterial) {\n serializeMaterial(submaterial);\n }\n }\n }\n }\n else {\n serializeMaterial(mesh.material);\n }\n }\n else if (!mesh.material) {\n serializeMaterial(mesh.getScene().defaultMaterial);\n }\n //serialize geometry\n const geometry = mesh._geometry;\n if (geometry) {\n if (!serializationObject.geometries) {\n serializationObject.geometries = {};\n serializationObject.geometries.boxes = [];\n serializationObject.geometries.spheres = [];\n serializationObject.geometries.cylinders = [];\n serializationObject.geometries.toruses = [];\n serializationObject.geometries.grounds = [];\n serializationObject.geometries.planes = [];\n serializationObject.geometries.torusKnots = [];\n serializationObject.geometries.vertexData = [];\n }\n SerializeGeometry(geometry, serializationObject.geometries);\n }\n // Skeletons\n if (mesh.skeleton && !mesh.skeleton.doNotSerialize) {\n serializationObject.skeletons = serializationObject.skeletons || [];\n serializationObject.skeletons.push(mesh.skeleton.serialize());\n }\n //serialize the actual mesh\n serializationObject.meshes = serializationObject.meshes || [];\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\n }\n }\n else if (node.getClassName() === \"TransformNode\") {\n const transformNode = node;\n serializationObject.transformNodes.push(transformNode.serialize());\n }\n else if (node.getClassName().indexOf(\"Camera\") !== -1) {\n const camera = node;\n serializationObject.cameras.push(camera.serialize());\n }\n else if (node.getClassName().indexOf(\"Light\") !== -1) {\n const light = node;\n serializationObject.lights.push(light.serialize());\n }\n };\n /**\n * Class used to serialize a scene into a string\n */\n class SceneSerializer {\n /**\n * Clear cache used by a previous serialization\n */\n static ClearCache() {\n serializedGeometries = [];\n }\n /**\n * Serialize a scene into a JSON compatible object\n * Note that if the current engine does not support synchronous texture reading (like WebGPU), you should use SerializeAsync instead\n * as else you may not retrieve the proper base64 encoded texture data (when using the Texture.ForceSerializeBuffers flag)\n * @param scene defines the scene to serialize\n * @returns a JSON compatible object\n */\n static Serialize(scene) {\n return SceneSerializer._Serialize(scene);\n }\n static _Serialize(scene, checkSyncReadSupported = true) {\n const serializationObject = {};\n if (checkSyncReadSupported && !scene.getEngine()._features.supportSyncTextureRead && Texture.ForceSerializeBuffers) {\n console.warn(\"The serialization object may not contain the proper base64 encoded texture data! You should use the SerializeAsync method instead.\");\n }\n SceneSerializer.ClearCache();\n // Scene\n serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;\n serializationObject.autoClear = scene.autoClear;\n serializationObject.clearColor = scene.clearColor.asArray();\n serializationObject.ambientColor = scene.ambientColor.asArray();\n serializationObject.gravity = scene.gravity.asArray();\n serializationObject.collisionsEnabled = scene.collisionsEnabled;\n serializationObject.useRightHandedSystem = scene.useRightHandedSystem;\n // Fog\n if (scene.fogMode && scene.fogMode !== 0) {\n serializationObject.fogMode = scene.fogMode;\n serializationObject.fogColor = scene.fogColor.asArray();\n serializationObject.fogStart = scene.fogStart;\n serializationObject.fogEnd = scene.fogEnd;\n serializationObject.fogDensity = scene.fogDensity;\n }\n //Physics\n if (scene.isPhysicsEnabled && scene.isPhysicsEnabled()) {\n const physicEngine = scene.getPhysicsEngine();\n if (physicEngine) {\n serializationObject.physicsEnabled = true;\n serializationObject.physicsGravity = physicEngine.gravity.asArray();\n serializationObject.physicsEngine = physicEngine.getPhysicsPluginName();\n }\n }\n // Metadata\n if (scene.metadata) {\n serializationObject.metadata = scene.metadata;\n }\n // Morph targets\n serializationObject.morphTargetManagers = [];\n for (const abstractMesh of scene.meshes) {\n const manager = abstractMesh.morphTargetManager;\n if (manager) {\n serializationObject.morphTargetManagers.push(manager.serialize());\n }\n }\n // Lights\n serializationObject.lights = [];\n let index;\n let light;\n for (index = 0; index < scene.lights.length; index++) {\n light = scene.lights[index];\n if (!light.doNotSerialize) {\n serializationObject.lights.push(light.serialize());\n }\n }\n // Cameras\n serializationObject.cameras = [];\n for (index = 0; index < scene.cameras.length; index++) {\n const camera = scene.cameras[index];\n if (!camera.doNotSerialize) {\n serializationObject.cameras.push(camera.serialize());\n }\n }\n if (scene.activeCamera) {\n serializationObject.activeCameraID = scene.activeCamera.id;\n }\n // Animations\n SerializationHelper.AppendSerializedAnimations(scene, serializationObject);\n // Animation Groups\n if (scene.animationGroups && scene.animationGroups.length > 0) {\n serializationObject.animationGroups = [];\n for (let animationGroupIndex = 0; animationGroupIndex < scene.animationGroups.length; animationGroupIndex++) {\n const animationGroup = scene.animationGroups[animationGroupIndex];\n serializationObject.animationGroups.push(animationGroup.serialize());\n }\n }\n // Reflection probes\n if (scene.reflectionProbes && scene.reflectionProbes.length > 0) {\n serializationObject.reflectionProbes = [];\n for (index = 0; index < scene.reflectionProbes.length; index++) {\n const reflectionProbe = scene.reflectionProbes[index];\n serializationObject.reflectionProbes.push(reflectionProbe.serialize());\n }\n }\n // Materials\n serializationObject.materials = [];\n serializationObject.multiMaterials = [];\n let material;\n for (index = 0; index < scene.materials.length; index++) {\n material = scene.materials[index];\n if (!material.doNotSerialize) {\n serializationObject.materials.push(material.serialize());\n }\n }\n // MultiMaterials\n serializationObject.multiMaterials = [];\n for (index = 0; index < scene.multiMaterials.length; index++) {\n const multiMaterial = scene.multiMaterials[index];\n serializationObject.multiMaterials.push(multiMaterial.serialize());\n }\n // Environment texture\n if (scene.environmentTexture) {\n if (scene.environmentTexture._files) {\n serializationObject.environmentTexture = scene.environmentTexture.serialize();\n }\n else {\n serializationObject.environmentTexture = scene.environmentTexture.name;\n serializationObject.environmentTextureRotationY = scene.environmentTexture.rotationY;\n }\n }\n // Environment Intensity\n serializationObject.environmentIntensity = scene.environmentIntensity;\n // Skeletons\n serializationObject.skeletons = [];\n for (index = 0; index < scene.skeletons.length; index++) {\n const skeleton = scene.skeletons[index];\n if (!skeleton.doNotSerialize) {\n serializationObject.skeletons.push(skeleton.serialize());\n }\n }\n // Transform nodes\n serializationObject.transformNodes = [];\n for (index = 0; index < scene.transformNodes.length; index++) {\n if (!scene.transformNodes[index].doNotSerialize) {\n serializationObject.transformNodes.push(scene.transformNodes[index].serialize());\n }\n }\n // Geometries\n serializationObject.geometries = {};\n serializationObject.geometries.boxes = [];\n serializationObject.geometries.spheres = [];\n serializationObject.geometries.cylinders = [];\n serializationObject.geometries.toruses = [];\n serializationObject.geometries.grounds = [];\n serializationObject.geometries.planes = [];\n serializationObject.geometries.torusKnots = [];\n serializationObject.geometries.vertexData = [];\n serializedGeometries = [];\n const geometries = scene.getGeometries();\n for (index = 0; index < geometries.length; index++) {\n const geometry = geometries[index];\n if (geometry.isReady()) {\n SerializeGeometry(geometry, serializationObject.geometries);\n }\n }\n // Meshes\n serializationObject.meshes = [];\n for (index = 0; index < scene.meshes.length; index++) {\n const abstractMesh = scene.meshes[index];\n if (abstractMesh instanceof Mesh) {\n const mesh = abstractMesh;\n if (!mesh.doNotSerialize) {\n if (mesh.delayLoadState === 1 || mesh.delayLoadState === 0) {\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\n }\n }\n }\n }\n // Particles Systems\n serializationObject.particleSystems = [];\n for (index = 0; index < scene.particleSystems.length; index++) {\n serializationObject.particleSystems.push(scene.particleSystems[index].serialize(false));\n }\n // Post processes\n serializationObject.postProcesses = [];\n for (index = 0; index < scene.postProcesses.length; index++) {\n serializationObject.postProcesses.push(scene.postProcesses[index].serialize());\n }\n // Action Manager\n if (scene.actionManager) {\n serializationObject.actions = scene.actionManager.serialize(\"scene\");\n }\n // Components\n for (const component of scene._serializableComponents) {\n component.serialize(serializationObject);\n }\n return serializationObject;\n }\n /**\n * Serialize a scene into a JSON compatible object\n * @param scene defines the scene to serialize\n * @returns a JSON promise compatible object\n */\n static SerializeAsync(scene) {\n const serializationObject = SceneSerializer._Serialize(scene, false);\n const promises = [];\n this._CollectPromises(serializationObject, promises);\n return Promise.all(promises).then(() => serializationObject);\n }\n static _CollectPromises(obj, promises) {\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; ++i) {\n const o = obj[i];\n if (o instanceof Promise) {\n promises.push(o.then((res) => (obj[i] = res)));\n }\n else if (o instanceof Object || Array.isArray(o)) {\n this._CollectPromises(o, promises);\n }\n }\n }\n else if (obj instanceof Object) {\n for (const name in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, name)) {\n const o = obj[name];\n if (o instanceof Promise) {\n promises.push(o.then((res) => (obj[name] = res)));\n }\n else if (o instanceof Object || Array.isArray(o)) {\n this._CollectPromises(o, promises);\n }\n }\n }\n }\n }\n /**\n * Serialize a mesh into a JSON compatible object\n * @param toSerialize defines the mesh to serialize\n * @param withParents defines if parents must be serialized as well\n * @param withChildren defines if children must be serialized as well\n * @returns a JSON compatible object\n */\n static SerializeMesh(toSerialize /* Mesh || Mesh[] */, withParents = false, withChildren = false) {\n const serializationObject = {};\n serializationObject.meshes = [];\n serializationObject.transformNodes = [];\n serializationObject.cameras = [];\n serializationObject.lights = [];\n SceneSerializer.ClearCache();\n toSerialize = toSerialize instanceof Array ? toSerialize : [toSerialize];\n if (withParents || withChildren) {\n //deliberate for loop! not for each, appended should be processed as well.\n for (let i = 0; i < toSerialize.length; ++i) {\n if (withChildren) {\n toSerialize[i].getDescendants().forEach((node) => {\n if (toSerialize.indexOf(node) < 0 && !node.doNotSerialize) {\n toSerialize.push(node);\n }\n });\n }\n //make sure the array doesn't contain the object already\n if (withParents && toSerialize[i].parent && toSerialize.indexOf(toSerialize[i].parent) < 0 && !toSerialize[i].parent.doNotSerialize) {\n toSerialize.push(toSerialize[i].parent);\n }\n }\n }\n toSerialize.forEach((mesh) => {\n FinalizeSingleNode(mesh, serializationObject);\n });\n return serializationObject;\n }\n }\n\n Scene.prototype.enableDepthRenderer = function (camera, storeNonLinearDepth = false, force32bitsFloat = false, samplingMode = 3, storeCameraSpaceZ = false) {\n camera = camera || this.activeCamera;\n if (!camera) {\n throw \"No camera available to enable depth renderer\";\n }\n if (!this._depthRenderer) {\n this._depthRenderer = {};\n }\n if (!this._depthRenderer[camera.id]) {\n const supportFullfloat = !!this.getEngine().getCaps().textureFloatRender;\n let textureType = 0;\n if (this.getEngine().getCaps().textureHalfFloatRender && (!force32bitsFloat || !supportFullfloat)) {\n textureType = 2;\n }\n else if (supportFullfloat) {\n textureType = 1;\n }\n else {\n textureType = 0;\n }\n this._depthRenderer[camera.id] = new DepthRenderer(this, textureType, camera, storeNonLinearDepth, samplingMode, storeCameraSpaceZ);\n }\n return this._depthRenderer[camera.id];\n };\n Scene.prototype.disableDepthRenderer = function (camera) {\n camera = camera || this.activeCamera;\n if (!camera || !this._depthRenderer || !this._depthRenderer[camera.id]) {\n return;\n }\n this._depthRenderer[camera.id].dispose();\n };\n /**\n * Defines the Depth Renderer scene component responsible to manage a depth buffer useful\n * in several rendering techniques.\n */\n class DepthRendererSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_DEPTHRENDERER;\n this.scene = scene;\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_DEPTHRENDERER, this, this._gatherRenderTargets);\n this.scene._gatherActiveCameraRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER, this, this._gatherActiveCameraRenderTargets);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do for this component\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n for (const key in this.scene._depthRenderer) {\n this.scene._depthRenderer[key].dispose();\n }\n }\n _gatherRenderTargets(renderTargets) {\n if (this.scene._depthRenderer) {\n for (const key in this.scene._depthRenderer) {\n const depthRenderer = this.scene._depthRenderer[key];\n if (depthRenderer.enabled && !depthRenderer.useOnlyInActiveCamera) {\n renderTargets.push(depthRenderer.getDepthMap());\n }\n }\n }\n }\n _gatherActiveCameraRenderTargets(renderTargets) {\n if (this.scene._depthRenderer) {\n for (const key in this.scene._depthRenderer) {\n const depthRenderer = this.scene._depthRenderer[key];\n if (depthRenderer.enabled && depthRenderer.useOnlyInActiveCamera && this.scene.activeCamera.id === key) {\n renderTargets.push(depthRenderer.getDepthMap());\n }\n }\n }\n }\n }\n DepthRenderer._SceneComponentInitialization = (scene) => {\n // Register the G Buffer component to the scene.\n let component = scene._getComponent(SceneComponentConstants.NAME_DEPTHRENDERER);\n if (!component) {\n component = new DepthRendererSceneComponent(scene);\n scene._addComponent(component);\n }\n };\n\n // Do not edit.\n const name$2h = \"linePixelShader\";\n const shader$2h = `#include\nuniform vec4 color;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2h] = shader$2h;\n\n // Do not edit.\n const name$2i = \"lineVertexShader\";\n const shader$2i = `#include\n#include\nattribute vec3 position;attribute vec4 normal;uniform mat4 viewProjection;uniform float width;uniform float aspectRatio;\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include\nmat4 worldViewProjection=viewProjection*finalWorld;vec4 viewPosition=worldViewProjection*vec4(position,1.0);vec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);vec2 currentScreen=viewPosition.xy/viewPosition.w;vec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;currentScreen.x*=aspectRatio;nextScreen.x*=aspectRatio;vec2 dir=normalize(nextScreen-currentScreen);vec2 normalDir=vec2(-dir.y,dir.x);normalDir*=width/2.0;normalDir.x/=aspectRatio;vec4 offset=vec4(normalDir*normal.w,0.0,0.0);gl_Position=viewPosition+offset;\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)\nvec4 worldPos=finalWorld*vec4(position,1.0);\n#include\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2i] = shader$2i;\n\n AbstractMesh.prototype.disableEdgesRendering = function () {\n if (this._edgesRenderer) {\n this._edgesRenderer.dispose();\n this._edgesRenderer = null;\n }\n return this;\n };\n AbstractMesh.prototype.enableEdgesRendering = function (epsilon = 0.95, checkVerticesInsteadOfIndices = false, options) {\n this.disableEdgesRendering();\n this._edgesRenderer = new EdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices, true, options);\n return this;\n };\n Object.defineProperty(AbstractMesh.prototype, \"edgesRenderer\", {\n get: function () {\n return this._edgesRenderer;\n },\n enumerable: true,\n configurable: true,\n });\n LinesMesh.prototype.enableEdgesRendering = function (epsilon = 0.95, checkVerticesInsteadOfIndices = false) {\n this.disableEdgesRendering();\n this._edgesRenderer = new LineEdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices);\n return this;\n };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n InstancedLinesMesh.prototype.enableEdgesRendering = function (epsilon = 0.95, checkVerticesInsteadOfIndices = false) {\n LinesMesh.prototype.enableEdgesRendering.apply(this, arguments);\n return this;\n };\n /**\n * FaceAdjacencies Helper class to generate edges\n */\n class FaceAdjacencies {\n constructor() {\n this.edges = new Array();\n this.edgesConnectedCount = 0;\n }\n }\n /**\n * This class is used to generate edges of the mesh that could then easily be rendered in a scene.\n */\n class EdgesRenderer {\n /** Gets the vertices generated by the edge renderer */\n get linesPositions() {\n return this._linesPositions;\n }\n /** Gets the normals generated by the edge renderer */\n get linesNormals() {\n return this._linesNormals;\n }\n /** Gets the indices generated by the edge renderer */\n get linesIndices() {\n return this._linesIndices;\n }\n /**\n * Gets or sets the shader used to draw the lines\n */\n get lineShader() {\n return this._lineShader;\n }\n set lineShader(shader) {\n this._lineShader = shader;\n }\n static _GetShader(scene) {\n if (!scene._edgeRenderLineShader) {\n const shader = new ShaderMaterial(\"lineShader\", scene, \"line\", {\n attributes: [\"position\", \"normal\"],\n uniforms: [\"world\", \"viewProjection\", \"color\", \"width\", \"aspectRatio\"],\n }, false);\n shader.disableDepthWrite = true;\n shader.backFaceCulling = false;\n shader.checkReadyOnEveryCall = scene.getEngine().isWebGPU;\n scene._edgeRenderLineShader = shader;\n }\n return scene._edgeRenderLineShader;\n }\n /**\n * Creates an instance of the EdgesRenderer. It is primarily use to display edges of a mesh.\n * Beware when you use this class with complex objects as the adjacencies computation can be really long\n * @param source Mesh used to create edges\n * @param epsilon sum of angles in adjacency to check for edge\n * @param checkVerticesInsteadOfIndices bases the edges detection on vertices vs indices. Note that this parameter is not used if options.useAlternateEdgeFinder = true\n * @param generateEdgesLines - should generate Lines or only prepare resources.\n * @param options The options to apply when generating the edges\n */\n constructor(source, epsilon = 0.95, checkVerticesInsteadOfIndices = false, generateEdgesLines = true, options) {\n var _a;\n /**\n * Define the size of the edges with an orthographic camera\n */\n this.edgesWidthScalerForOrthographic = 1000.0;\n /**\n * Define the size of the edges with a perspective camera\n */\n this.edgesWidthScalerForPerspective = 50.0;\n this._linesPositions = new Array();\n this._linesNormals = new Array();\n this._linesIndices = new Array();\n this._buffers = {};\n this._buffersForInstances = {};\n this._checkVerticesInsteadOfIndices = false;\n /** Gets or sets a boolean indicating if the edgesRenderer is active */\n this.isEnabled = true;\n /**\n * List of instances to render in case the source mesh has instances\n */\n this.customInstances = new SmartArray(32);\n this._source = source;\n this._checkVerticesInsteadOfIndices = checkVerticesInsteadOfIndices;\n this._options = options !== null && options !== void 0 ? options : null;\n this._epsilon = epsilon;\n if (this._source.getScene().getEngine().isWebGPU) {\n this._drawWrapper = new DrawWrapper(source.getEngine());\n }\n this._prepareRessources();\n if (generateEdgesLines) {\n if ((_a = options === null || options === void 0 ? void 0 : options.useAlternateEdgeFinder) !== null && _a !== void 0 ? _a : true) {\n this._generateEdgesLinesAlternate();\n }\n else {\n this._generateEdgesLines();\n }\n }\n this._meshRebuildObserver = this._source.onRebuildObservable.add(() => {\n this._rebuild();\n });\n this._meshDisposeObserver = this._source.onDisposeObservable.add(() => {\n this.dispose();\n });\n }\n _prepareRessources() {\n if (this._lineShader) {\n return;\n }\n this._lineShader = EdgesRenderer._GetShader(this._source.getScene());\n }\n /** @internal */\n _rebuild() {\n let buffer = this._buffers[VertexBuffer.PositionKind];\n if (buffer) {\n buffer._rebuild();\n }\n buffer = this._buffers[VertexBuffer.NormalKind];\n if (buffer) {\n buffer._rebuild();\n }\n const scene = this._source.getScene();\n const engine = scene.getEngine();\n this._ib = engine.createIndexBuffer(this._linesIndices);\n }\n /**\n * Releases the required resources for the edges renderer\n */\n dispose() {\n var _a;\n this._source.onRebuildObservable.remove(this._meshRebuildObserver);\n this._source.onDisposeObservable.remove(this._meshDisposeObserver);\n let buffer = this._buffers[VertexBuffer.PositionKind];\n if (buffer) {\n buffer.dispose();\n this._buffers[VertexBuffer.PositionKind] = null;\n }\n buffer = this._buffers[VertexBuffer.NormalKind];\n if (buffer) {\n buffer.dispose();\n this._buffers[VertexBuffer.NormalKind] = null;\n }\n if (this._ib) {\n this._source.getScene().getEngine()._releaseBuffer(this._ib);\n }\n this._lineShader.dispose();\n (_a = this._drawWrapper) === null || _a === void 0 ? void 0 : _a.dispose();\n }\n _processEdgeForAdjacencies(pa, pb, p0, p1, p2) {\n if ((pa === p0 && pb === p1) || (pa === p1 && pb === p0)) {\n return 0;\n }\n if ((pa === p1 && pb === p2) || (pa === p2 && pb === p1)) {\n return 1;\n }\n if ((pa === p2 && pb === p0) || (pa === p0 && pb === p2)) {\n return 2;\n }\n return -1;\n }\n _processEdgeForAdjacenciesWithVertices(pa, pb, p0, p1, p2) {\n const eps = 1e-10;\n if ((pa.equalsWithEpsilon(p0, eps) && pb.equalsWithEpsilon(p1, eps)) || (pa.equalsWithEpsilon(p1, eps) && pb.equalsWithEpsilon(p0, eps))) {\n return 0;\n }\n if ((pa.equalsWithEpsilon(p1, eps) && pb.equalsWithEpsilon(p2, eps)) || (pa.equalsWithEpsilon(p2, eps) && pb.equalsWithEpsilon(p1, eps))) {\n return 1;\n }\n if ((pa.equalsWithEpsilon(p2, eps) && pb.equalsWithEpsilon(p0, eps)) || (pa.equalsWithEpsilon(p0, eps) && pb.equalsWithEpsilon(p2, eps))) {\n return 2;\n }\n return -1;\n }\n /**\n * Checks if the pair of p0 and p1 is en edge\n * @param faceIndex\n * @param edge\n * @param faceNormals\n * @param p0\n * @param p1\n * @private\n */\n _checkEdge(faceIndex, edge, faceNormals, p0, p1) {\n let needToCreateLine;\n if (edge === undefined) {\n needToCreateLine = true;\n }\n else {\n const dotProduct = Vector3.Dot(faceNormals[faceIndex], faceNormals[edge]);\n needToCreateLine = dotProduct < this._epsilon;\n }\n if (needToCreateLine) {\n this.createLine(p0, p1, this._linesPositions.length / 3);\n }\n }\n /**\n * push line into the position, normal and index buffer\n * @param p0\n * @param p1\n * @param offset\n * @protected\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n createLine(p0, p1, offset) {\n // Positions\n this._linesPositions.push(p0.x, p0.y, p0.z, p0.x, p0.y, p0.z, p1.x, p1.y, p1.z, p1.x, p1.y, p1.z);\n // Normals\n this._linesNormals.push(p1.x, p1.y, p1.z, -1, p1.x, p1.y, p1.z, 1, p0.x, p0.y, p0.z, -1, p0.x, p0.y, p0.z, 1);\n // Indices\n this._linesIndices.push(offset, offset + 1, offset + 2, offset, offset + 2, offset + 3);\n }\n /**\n * See https://playground.babylonjs.com/#R3JR6V#1 for a visual display of the algorithm\n * @param edgePoints\n * @param indexTriangle\n * @param indices\n * @param remapVertexIndices\n */\n _tessellateTriangle(edgePoints, indexTriangle, indices, remapVertexIndices) {\n const makePointList = (edgePoints, pointIndices, firstIndex) => {\n if (firstIndex >= 0) {\n pointIndices.push(firstIndex);\n }\n for (let i = 0; i < edgePoints.length; ++i) {\n pointIndices.push(edgePoints[i][0]);\n }\n };\n let startEdge = 0;\n if (edgePoints[1].length >= edgePoints[0].length && edgePoints[1].length >= edgePoints[2].length) {\n startEdge = 1;\n }\n else if (edgePoints[2].length >= edgePoints[0].length && edgePoints[2].length >= edgePoints[1].length) {\n startEdge = 2;\n }\n for (let e = 0; e < 3; ++e) {\n if (e === startEdge) {\n edgePoints[e].sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));\n }\n else {\n edgePoints[e].sort((a, b) => (a[1] > b[1] ? -1 : a[1] < b[1] ? 1 : 0));\n }\n }\n const mainPointIndices = [], otherPointIndices = [];\n makePointList(edgePoints[startEdge], mainPointIndices, -1);\n const numMainPoints = mainPointIndices.length;\n for (let i = startEdge + 2; i >= startEdge + 1; --i) {\n makePointList(edgePoints[i % 3], otherPointIndices, i !== startEdge + 2 ? remapVertexIndices[indices[indexTriangle + ((i + 1) % 3)]] : -1);\n }\n const numOtherPoints = otherPointIndices.length;\n const idxMain = 0;\n const idxOther = 0;\n indices.push(remapVertexIndices[indices[indexTriangle + startEdge]], mainPointIndices[0], otherPointIndices[0]);\n indices.push(remapVertexIndices[indices[indexTriangle + ((startEdge + 1) % 3)]], otherPointIndices[numOtherPoints - 1], mainPointIndices[numMainPoints - 1]);\n const bucketIsMain = numMainPoints <= numOtherPoints;\n const bucketStep = bucketIsMain ? numMainPoints : numOtherPoints;\n const bucketLimit = bucketIsMain ? numOtherPoints : numMainPoints;\n const bucketIdxLimit = bucketIsMain ? numMainPoints - 1 : numOtherPoints - 1;\n const winding = bucketIsMain ? 0 : 1;\n let numTris = numMainPoints + numOtherPoints - 2;\n let bucketIdx = bucketIsMain ? idxMain : idxOther;\n let nbucketIdx = bucketIsMain ? idxOther : idxMain;\n const bucketPoints = bucketIsMain ? mainPointIndices : otherPointIndices;\n const nbucketPoints = bucketIsMain ? otherPointIndices : mainPointIndices;\n let bucket = 0;\n while (numTris-- > 0) {\n if (winding) {\n indices.push(bucketPoints[bucketIdx], nbucketPoints[nbucketIdx]);\n }\n else {\n indices.push(nbucketPoints[nbucketIdx], bucketPoints[bucketIdx]);\n }\n bucket += bucketStep;\n let lastIdx;\n if (bucket >= bucketLimit && bucketIdx < bucketIdxLimit) {\n lastIdx = bucketPoints[++bucketIdx];\n bucket -= bucketLimit;\n }\n else {\n lastIdx = nbucketPoints[++nbucketIdx];\n }\n indices.push(lastIdx);\n }\n indices[indexTriangle + 0] = indices[indices.length - 3];\n indices[indexTriangle + 1] = indices[indices.length - 2];\n indices[indexTriangle + 2] = indices[indices.length - 1];\n indices.length = indices.length - 3;\n }\n _generateEdgesLinesAlternate() {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;\n const positions = this._source.getVerticesData(VertexBuffer.PositionKind);\n let indices = this._source.getIndices();\n if (!indices || !positions) {\n return;\n }\n if (!Array.isArray(indices)) {\n indices = Array.from(indices);\n }\n /**\n * Find all vertices that are at the same location (with an epsilon) and remapp them on the same vertex\n */\n const useFastVertexMerger = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.useFastVertexMerger) !== null && _b !== void 0 ? _b : true;\n const epsVertexMerge = useFastVertexMerger ? Math.round(-Math.log((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.epsilonVertexMerge) !== null && _d !== void 0 ? _d : 1e-6) / Math.log(10)) : (_f = (_e = this._options) === null || _e === void 0 ? void 0 : _e.epsilonVertexMerge) !== null && _f !== void 0 ? _f : 1e-6;\n const remapVertexIndices = [];\n const uniquePositions = []; // list of unique index of vertices - needed for tessellation\n if (useFastVertexMerger) {\n const mapVertices = {};\n for (let v1 = 0; v1 < positions.length; v1 += 3) {\n const x1 = positions[v1 + 0], y1 = positions[v1 + 1], z1 = positions[v1 + 2];\n const key = x1.toFixed(epsVertexMerge) + \"|\" + y1.toFixed(epsVertexMerge) + \"|\" + z1.toFixed(epsVertexMerge);\n if (mapVertices[key] !== undefined) {\n remapVertexIndices.push(mapVertices[key]);\n }\n else {\n const idx = v1 / 3;\n mapVertices[key] = idx;\n remapVertexIndices.push(idx);\n uniquePositions.push(idx);\n }\n }\n }\n else {\n for (let v1 = 0; v1 < positions.length; v1 += 3) {\n const x1 = positions[v1 + 0], y1 = positions[v1 + 1], z1 = positions[v1 + 2];\n let found = false;\n for (let v2 = 0; v2 < v1 && !found; v2 += 3) {\n const x2 = positions[v2 + 0], y2 = positions[v2 + 1], z2 = positions[v2 + 2];\n if (Math.abs(x1 - x2) < epsVertexMerge && Math.abs(y1 - y2) < epsVertexMerge && Math.abs(z1 - z2) < epsVertexMerge) {\n remapVertexIndices.push(v2 / 3);\n found = true;\n break;\n }\n }\n if (!found) {\n remapVertexIndices.push(v1 / 3);\n uniquePositions.push(v1 / 3);\n }\n }\n }\n if ((_g = this._options) === null || _g === void 0 ? void 0 : _g.applyTessellation) {\n /**\n * Tessellate triangles if necessary:\n *\n * A\n * +\n * |\\\n * | \\\n * | \\\n * E + \\\n * /| \\\n * / | \\\n * / | \\\n * +---+-------+ B\n * D C\n *\n * For the edges to be rendered correctly, the ABC triangle has to be split into ABE and BCE, else AC is considered to be an edge, whereas only AE should be.\n *\n * The tessellation process looks for the vertices like E that are in-between two other vertices making of an edge and create new triangles as necessary\n */\n // First step: collect the triangles to tessellate\n const epsVertexAligned = (_j = (_h = this._options) === null || _h === void 0 ? void 0 : _h.epsilonVertexAligned) !== null && _j !== void 0 ? _j : 1e-6;\n const mustTesselate = []; // liste of triangles that must be tessellated\n for (let index = 0; index < indices.length; index += 3) {\n // loop over all triangles\n let triangleToTessellate;\n for (let i = 0; i < 3; ++i) {\n // loop over the 3 edges of the triangle\n const p0Index = remapVertexIndices[indices[index + i]];\n const p1Index = remapVertexIndices[indices[index + ((i + 1) % 3)]];\n const p2Index = remapVertexIndices[indices[index + ((i + 2) % 3)]];\n if (p0Index === p1Index) {\n continue;\n } // degenerated triangle - don't process\n const p0x = positions[p0Index * 3 + 0], p0y = positions[p0Index * 3 + 1], p0z = positions[p0Index * 3 + 2];\n const p1x = positions[p1Index * 3 + 0], p1y = positions[p1Index * 3 + 1], p1z = positions[p1Index * 3 + 2];\n const p0p1 = Math.sqrt((p1x - p0x) * (p1x - p0x) + (p1y - p0y) * (p1y - p0y) + (p1z - p0z) * (p1z - p0z));\n for (let v = 0; v < uniquePositions.length - 1; v++) {\n // loop over all (unique) vertices and look for the ones that would be in-between p0 and p1\n const vIndex = uniquePositions[v];\n if (vIndex === p0Index || vIndex === p1Index || vIndex === p2Index) {\n continue;\n } // don't handle the vertex if it is a vertex of the current triangle\n const x = positions[vIndex * 3 + 0], y = positions[vIndex * 3 + 1], z = positions[vIndex * 3 + 2];\n const p0p = Math.sqrt((x - p0x) * (x - p0x) + (y - p0y) * (y - p0y) + (z - p0z) * (z - p0z));\n const pp1 = Math.sqrt((x - p1x) * (x - p1x) + (y - p1y) * (y - p1y) + (z - p1z) * (z - p1z));\n if (Math.abs(p0p + pp1 - p0p1) < epsVertexAligned) {\n // vertices are aligned and p in-between p0 and p1 if distance(p0, p) + distance (p, p1) ~ distance(p0, p1)\n if (!triangleToTessellate) {\n triangleToTessellate = {\n index: index,\n edgesPoints: [[], [], []],\n };\n mustTesselate.push(triangleToTessellate);\n }\n triangleToTessellate.edgesPoints[i].push([vIndex, p0p]);\n }\n }\n }\n }\n // Second step: tesselate the triangles\n for (let t = 0; t < mustTesselate.length; ++t) {\n const triangle = mustTesselate[t];\n this._tessellateTriangle(triangle.edgesPoints, triangle.index, indices, remapVertexIndices);\n }\n mustTesselate.length = 0;\n }\n /**\n * Collect the edges to render\n */\n const edges = {};\n for (let index = 0; index < indices.length; index += 3) {\n let faceNormal;\n for (let i = 0; i < 3; ++i) {\n let p0Index = remapVertexIndices[indices[index + i]];\n let p1Index = remapVertexIndices[indices[index + ((i + 1) % 3)]];\n const p2Index = remapVertexIndices[indices[index + ((i + 2) % 3)]];\n if (p0Index === p1Index || ((p0Index === p2Index || p1Index === p2Index) && ((_k = this._options) === null || _k === void 0 ? void 0 : _k.removeDegeneratedTriangles))) {\n continue;\n }\n TmpVectors.Vector3[0].copyFromFloats(positions[p0Index * 3 + 0], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);\n TmpVectors.Vector3[1].copyFromFloats(positions[p1Index * 3 + 0], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);\n TmpVectors.Vector3[2].copyFromFloats(positions[p2Index * 3 + 0], positions[p2Index * 3 + 1], positions[p2Index * 3 + 2]);\n if (!faceNormal) {\n TmpVectors.Vector3[1].subtractToRef(TmpVectors.Vector3[0], TmpVectors.Vector3[3]);\n TmpVectors.Vector3[2].subtractToRef(TmpVectors.Vector3[1], TmpVectors.Vector3[4]);\n faceNormal = Vector3.Cross(TmpVectors.Vector3[3], TmpVectors.Vector3[4]);\n faceNormal.normalize();\n }\n if (p0Index > p1Index) {\n const tmp = p0Index;\n p0Index = p1Index;\n p1Index = tmp;\n }\n const key = p0Index + \"_\" + p1Index;\n const ei = edges[key];\n if (ei) {\n if (!ei.done) {\n const dotProduct = Vector3.Dot(faceNormal, ei.normal);\n if (dotProduct < this._epsilon) {\n this.createLine(TmpVectors.Vector3[0], TmpVectors.Vector3[1], this._linesPositions.length / 3);\n }\n ei.done = true;\n }\n }\n else {\n edges[key] = { normal: faceNormal, done: false, index: index, i: i };\n }\n }\n }\n for (const key in edges) {\n const ei = edges[key];\n if (!ei.done) {\n // Orphaned edge - we must display it\n const p0Index = remapVertexIndices[indices[ei.index + ei.i]];\n const p1Index = remapVertexIndices[indices[ei.index + ((ei.i + 1) % 3)]];\n TmpVectors.Vector3[0].copyFromFloats(positions[p0Index * 3 + 0], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);\n TmpVectors.Vector3[1].copyFromFloats(positions[p1Index * 3 + 0], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);\n this.createLine(TmpVectors.Vector3[0], TmpVectors.Vector3[1], this._linesPositions.length / 3);\n }\n }\n /**\n * Merge into a single mesh\n */\n const engine = this._source.getScene().getEngine();\n this._buffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, this._linesPositions, VertexBuffer.PositionKind, false);\n this._buffers[VertexBuffer.NormalKind] = new VertexBuffer(engine, this._linesNormals, VertexBuffer.NormalKind, false, false, 4);\n this._buffersForInstances[VertexBuffer.PositionKind] = this._buffers[VertexBuffer.PositionKind];\n this._buffersForInstances[VertexBuffer.NormalKind] = this._buffers[VertexBuffer.NormalKind];\n this._ib = engine.createIndexBuffer(this._linesIndices);\n this._indicesCount = this._linesIndices.length;\n }\n /**\n * Generates lines edges from adjacencjes\n * @private\n */\n _generateEdgesLines() {\n const positions = this._source.getVerticesData(VertexBuffer.PositionKind);\n const indices = this._source.getIndices();\n if (!indices || !positions) {\n return;\n }\n // First let's find adjacencies\n const adjacencies = new Array();\n const faceNormals = new Array();\n let index;\n let faceAdjacencies;\n // Prepare faces\n for (index = 0; index < indices.length; index += 3) {\n faceAdjacencies = new FaceAdjacencies();\n const p0Index = indices[index];\n const p1Index = indices[index + 1];\n const p2Index = indices[index + 2];\n faceAdjacencies.p0 = new Vector3(positions[p0Index * 3], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);\n faceAdjacencies.p1 = new Vector3(positions[p1Index * 3], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);\n faceAdjacencies.p2 = new Vector3(positions[p2Index * 3], positions[p2Index * 3 + 1], positions[p2Index * 3 + 2]);\n const faceNormal = Vector3.Cross(faceAdjacencies.p1.subtract(faceAdjacencies.p0), faceAdjacencies.p2.subtract(faceAdjacencies.p1));\n faceNormal.normalize();\n faceNormals.push(faceNormal);\n adjacencies.push(faceAdjacencies);\n }\n // Scan\n for (index = 0; index < adjacencies.length; index++) {\n faceAdjacencies = adjacencies[index];\n for (let otherIndex = index + 1; otherIndex < adjacencies.length; otherIndex++) {\n const otherFaceAdjacencies = adjacencies[otherIndex];\n if (faceAdjacencies.edgesConnectedCount === 3) {\n // Full\n break;\n }\n if (otherFaceAdjacencies.edgesConnectedCount === 3) {\n // Full\n continue;\n }\n const otherP0 = indices[otherIndex * 3];\n const otherP1 = indices[otherIndex * 3 + 1];\n const otherP2 = indices[otherIndex * 3 + 2];\n for (let edgeIndex = 0; edgeIndex < 3; edgeIndex++) {\n let otherEdgeIndex = 0;\n if (faceAdjacencies.edges[edgeIndex] !== undefined) {\n continue;\n }\n switch (edgeIndex) {\n case 0:\n if (this._checkVerticesInsteadOfIndices) {\n otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(faceAdjacencies.p0, faceAdjacencies.p1, otherFaceAdjacencies.p0, otherFaceAdjacencies.p1, otherFaceAdjacencies.p2);\n }\n else {\n otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3], indices[index * 3 + 1], otherP0, otherP1, otherP2);\n }\n break;\n case 1:\n if (this._checkVerticesInsteadOfIndices) {\n otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(faceAdjacencies.p1, faceAdjacencies.p2, otherFaceAdjacencies.p0, otherFaceAdjacencies.p1, otherFaceAdjacencies.p2);\n }\n else {\n otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3 + 1], indices[index * 3 + 2], otherP0, otherP1, otherP2);\n }\n break;\n case 2:\n if (this._checkVerticesInsteadOfIndices) {\n otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(faceAdjacencies.p2, faceAdjacencies.p0, otherFaceAdjacencies.p0, otherFaceAdjacencies.p1, otherFaceAdjacencies.p2);\n }\n else {\n otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3 + 2], indices[index * 3], otherP0, otherP1, otherP2);\n }\n break;\n }\n if (otherEdgeIndex === -1) {\n continue;\n }\n faceAdjacencies.edges[edgeIndex] = otherIndex;\n otherFaceAdjacencies.edges[otherEdgeIndex] = index;\n faceAdjacencies.edgesConnectedCount++;\n otherFaceAdjacencies.edgesConnectedCount++;\n if (faceAdjacencies.edgesConnectedCount === 3) {\n break;\n }\n }\n }\n }\n // Create lines\n for (index = 0; index < adjacencies.length; index++) {\n // We need a line when a face has no adjacency on a specific edge or if all the adjacencies has an angle greater than epsilon\n const current = adjacencies[index];\n this._checkEdge(index, current.edges[0], faceNormals, current.p0, current.p1);\n this._checkEdge(index, current.edges[1], faceNormals, current.p1, current.p2);\n this._checkEdge(index, current.edges[2], faceNormals, current.p2, current.p0);\n }\n // Merge into a single mesh\n const engine = this._source.getScene().getEngine();\n this._buffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, this._linesPositions, VertexBuffer.PositionKind, false);\n this._buffers[VertexBuffer.NormalKind] = new VertexBuffer(engine, this._linesNormals, VertexBuffer.NormalKind, false, false, 4);\n this._buffersForInstances[VertexBuffer.PositionKind] = this._buffers[VertexBuffer.PositionKind];\n this._buffersForInstances[VertexBuffer.NormalKind] = this._buffers[VertexBuffer.NormalKind];\n this._ib = engine.createIndexBuffer(this._linesIndices);\n this._indicesCount = this._linesIndices.length;\n }\n /**\n * Checks whether or not the edges renderer is ready to render.\n * @returns true if ready, otherwise false.\n */\n isReady() {\n return this._lineShader.isReady(this._source, (this._source.hasInstances && this.customInstances.length > 0) || this._source.hasThinInstances);\n }\n /**\n * Renders the edges of the attached mesh,\n */\n render() {\n const scene = this._source.getScene();\n const currentDrawWrapper = this._lineShader._getDrawWrapper();\n if (this._drawWrapper) {\n this._lineShader._setDrawWrapper(this._drawWrapper);\n }\n if (!this.isReady() || !scene.activeCamera) {\n this._lineShader._setDrawWrapper(currentDrawWrapper);\n return;\n }\n const hasInstances = this._source.hasInstances && this.customInstances.length > 0;\n const useBuffersWithInstances = hasInstances || this._source.hasThinInstances;\n let instanceCount = 0;\n if (useBuffersWithInstances) {\n this._buffersForInstances[\"world0\"] = this._source.getVertexBuffer(\"world0\");\n this._buffersForInstances[\"world1\"] = this._source.getVertexBuffer(\"world1\");\n this._buffersForInstances[\"world2\"] = this._source.getVertexBuffer(\"world2\");\n this._buffersForInstances[\"world3\"] = this._source.getVertexBuffer(\"world3\");\n if (hasInstances) {\n const instanceStorage = this._source._instanceDataStorage;\n instanceCount = this.customInstances.length;\n if (!instanceStorage.instancesData) {\n if (!this._source.getScene()._activeMeshesFrozen) {\n this.customInstances.reset();\n }\n return;\n }\n if (!instanceStorage.isFrozen) {\n let offset = 0;\n for (let i = 0; i < instanceCount; ++i) {\n this.customInstances.data[i].copyToArray(instanceStorage.instancesData, offset);\n offset += 16;\n }\n instanceStorage.instancesBuffer.updateDirectly(instanceStorage.instancesData, 0, instanceCount);\n }\n }\n else {\n instanceCount = this._source.thinInstanceCount;\n }\n }\n const engine = scene.getEngine();\n this._lineShader._preBind();\n if (this._source.edgesColor.a !== 1) {\n engine.setAlphaMode(2);\n }\n else {\n engine.setAlphaMode(0);\n }\n // VBOs\n engine.bindBuffers(useBuffersWithInstances ? this._buffersForInstances : this._buffers, this._ib, this._lineShader.getEffect());\n scene.resetCachedMaterial();\n this._lineShader.setColor4(\"color\", this._source.edgesColor);\n if (scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n this._lineShader.setFloat(\"width\", this._source.edgesWidth / this.edgesWidthScalerForOrthographic);\n }\n else {\n this._lineShader.setFloat(\"width\", this._source.edgesWidth / this.edgesWidthScalerForPerspective);\n }\n this._lineShader.setFloat(\"aspectRatio\", engine.getAspectRatio(scene.activeCamera));\n this._lineShader.bind(this._source.getWorldMatrix());\n // Draw order\n engine.drawElementsType(Material.TriangleFillMode, 0, this._indicesCount, instanceCount);\n this._lineShader.unbind();\n if (useBuffersWithInstances) {\n engine.unbindInstanceAttributes();\n }\n if (!this._source.getScene()._activeMeshesFrozen) {\n this.customInstances.reset();\n }\n this._lineShader._setDrawWrapper(currentDrawWrapper);\n }\n }\n /**\n * LineEdgesRenderer for LineMeshes to remove unnecessary triangulation\n */\n class LineEdgesRenderer extends EdgesRenderer {\n /**\n * This constructor turns off auto generating edges line in Edges Renderer to make it here.\n * @param source LineMesh used to generate edges\n * @param epsilon not important (specified angle for edge detection)\n * @param checkVerticesInsteadOfIndices not important for LineMesh\n */\n constructor(source, epsilon = 0.95, checkVerticesInsteadOfIndices = false) {\n super(source, epsilon, checkVerticesInsteadOfIndices, false);\n this._generateEdgesLines();\n }\n /**\n * Generate edges for each line in LinesMesh. Every Line should be rendered as edge.\n */\n _generateEdgesLines() {\n const positions = this._source.getVerticesData(VertexBuffer.PositionKind);\n const indices = this._source.getIndices();\n if (!indices || !positions) {\n return;\n }\n const p0 = TmpVectors.Vector3[0];\n const p1 = TmpVectors.Vector3[1];\n const len = indices.length - 1;\n for (let i = 0, offset = 0; i < len; i += 2, offset += 4) {\n Vector3.FromArrayToRef(positions, 3 * indices[i], p0);\n Vector3.FromArrayToRef(positions, 3 * indices[i + 1], p1);\n this.createLine(p0, p1, offset);\n }\n // Merge into a single mesh\n const engine = this._source.getScene().getEngine();\n this._buffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, this._linesPositions, VertexBuffer.PositionKind, false);\n this._buffers[VertexBuffer.NormalKind] = new VertexBuffer(engine, this._linesNormals, VertexBuffer.NormalKind, false, false, 4);\n this._ib = engine.createIndexBuffer(this._linesIndices);\n this._indicesCount = this._linesIndices.length;\n }\n }\n\n ThinEngine.prototype.restoreSingleAttachment = function () {\n const gl = this._gl;\n this.bindAttachments([gl.BACK]);\n };\n ThinEngine.prototype.restoreSingleAttachmentForRenderTarget = function () {\n const gl = this._gl;\n this.bindAttachments([gl.COLOR_ATTACHMENT0]);\n };\n ThinEngine.prototype.buildTextureLayout = function (textureStatus) {\n const gl = this._gl;\n const result = [];\n for (let i = 0; i < textureStatus.length; i++) {\n if (textureStatus[i]) {\n result.push(gl[\"COLOR_ATTACHMENT\" + i]);\n }\n else {\n result.push(gl.NONE);\n }\n }\n return result;\n };\n ThinEngine.prototype.bindAttachments = function (attachments) {\n const gl = this._gl;\n gl.drawBuffers(attachments);\n };\n ThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function (rtWrapper, disableGenerateMipMaps = false, onBeforeUnbind) {\n this._currentRenderTarget = null;\n // If MSAA, we need to bitblt back to main texture\n const gl = this._gl;\n const attachments = rtWrapper._attachments;\n const count = attachments.length;\n if (rtWrapper._MSAAFramebuffer) {\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, rtWrapper._MSAAFramebuffer);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, rtWrapper._framebuffer);\n for (let i = 0; i < count; i++) {\n const texture = rtWrapper.textures[i];\n for (let j = 0; j < count; j++) {\n attachments[j] = gl.NONE;\n }\n attachments[i] = gl[this.webGLVersion > 1 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\n gl.readBuffer(attachments[i]);\n gl.drawBuffers(attachments);\n gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);\n }\n for (let i = 0; i < count; i++) {\n attachments[i] = gl[this.webGLVersion > 1 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\n }\n gl.drawBuffers(attachments);\n }\n for (let i = 0; i < count; i++) {\n const texture = rtWrapper.textures[i];\n if ((texture === null || texture === void 0 ? void 0 : texture.generateMipMaps) && !disableGenerateMipMaps && !texture.isCube) {\n this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);\n gl.generateMipmap(gl.TEXTURE_2D);\n this._bindTextureDirectly(gl.TEXTURE_2D, null);\n }\n }\n if (onBeforeUnbind) {\n if (rtWrapper._MSAAFramebuffer) {\n // Bind the correct framebuffer\n this._bindUnboundFramebuffer(rtWrapper._framebuffer);\n }\n onBeforeUnbind();\n }\n this._bindUnboundFramebuffer(null);\n };\n ThinEngine.prototype.createMultipleRenderTarget = function (size, options, initializeBuffers = true) {\n var _a;\n let generateMipMaps = false;\n let generateDepthBuffer = true;\n let generateStencilBuffer = false;\n let generateDepthTexture = false;\n let depthTextureFormat = 15;\n let textureCount = 1;\n const defaultType = 0;\n const defaultSamplingMode = 3;\n const defaultUseSRGBBuffer = false;\n const defaultFormat = 5;\n const defaultTarget = 3553;\n let types = new Array();\n let samplingModes = new Array();\n let useSRGBBuffers = new Array();\n let formats = new Array();\n let targets = new Array();\n let faceIndex = new Array();\n let layerIndex = new Array();\n let layers = new Array();\n const rtWrapper = this._createHardwareRenderTargetWrapper(true, false, size);\n if (options !== undefined) {\n generateMipMaps = options.generateMipMaps === undefined ? false : options.generateMipMaps;\n generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;\n generateStencilBuffer = options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;\n generateDepthTexture = options.generateDepthTexture === undefined ? false : options.generateDepthTexture;\n textureCount = options.textureCount || 1;\n if (options.types) {\n types = options.types;\n }\n if (options.samplingModes) {\n samplingModes = options.samplingModes;\n }\n if (options.useSRGBBuffers) {\n useSRGBBuffers = options.useSRGBBuffers;\n }\n if (options.formats) {\n formats = options.formats;\n }\n if (options.targetTypes) {\n targets = options.targetTypes;\n }\n if (options.faceIndex) {\n faceIndex = options.faceIndex;\n }\n if (options.layerIndex) {\n layerIndex = options.layerIndex;\n }\n if (options.layerCounts) {\n layers = options.layerCounts;\n }\n if (this.webGLVersion > 1 &&\n (options.depthTextureFormat === 13 ||\n options.depthTextureFormat === 17 ||\n options.depthTextureFormat === 16 ||\n options.depthTextureFormat === 14 ||\n options.depthTextureFormat === 18)) {\n depthTextureFormat = options.depthTextureFormat;\n }\n }\n const gl = this._gl;\n // Create the framebuffer\n const framebuffer = gl.createFramebuffer();\n this._bindUnboundFramebuffer(framebuffer);\n const width = size.width || size;\n const height = size.height || size;\n const textures = [];\n const attachments = [];\n const useStencilTexture = this.webGLVersion > 1 &&\n generateDepthTexture &&\n (options.depthTextureFormat === 13 ||\n options.depthTextureFormat === 17 ||\n options.depthTextureFormat === 18);\n const depthStencilBuffer = this._setupFramebufferDepthAttachments(!useStencilTexture && generateStencilBuffer, !generateDepthTexture && generateDepthBuffer, width, height);\n rtWrapper._framebuffer = framebuffer;\n rtWrapper._depthStencilBuffer = depthStencilBuffer;\n rtWrapper._generateDepthBuffer = !generateDepthTexture && generateDepthBuffer;\n rtWrapper._generateStencilBuffer = !useStencilTexture && generateStencilBuffer;\n rtWrapper._attachments = attachments;\n for (let i = 0; i < textureCount; i++) {\n let samplingMode = samplingModes[i] || defaultSamplingMode;\n let type = types[i] || defaultType;\n let useSRGBBuffer = useSRGBBuffers[i] || defaultUseSRGBBuffer;\n const format = formats[i] || defaultFormat;\n const target = targets[i] || defaultTarget;\n const layerCount = (_a = layers[i]) !== null && _a !== void 0 ? _a : 1;\n if (type === 1 && !this._caps.textureFloatLinearFiltering) {\n // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE\n samplingMode = 1;\n }\n else if (type === 2 && !this._caps.textureHalfFloatLinearFiltering) {\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\n samplingMode = 1;\n }\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\n if (type === 1 && !this._caps.textureFloat) {\n type = 0;\n Logger.Warn(\"Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type\");\n }\n useSRGBBuffer = useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU);\n const isWebGL2 = this.webGLVersion > 1;\n const attachment = gl[isWebGL2 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\n attachments.push(attachment);\n if (target === -1) {\n continue;\n }\n const texture = new InternalTexture(this, InternalTextureSource.MultiRenderTarget);\n textures[i] = texture;\n gl.activeTexture(gl[\"TEXTURE\" + i]);\n gl.bindTexture(target, texture._hardwareTexture.underlyingResource);\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, filters.mag);\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, filters.min);\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n const internalSizedFormat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);\n const internalFormat = this._getInternalFormat(format);\n const webGLTextureType = this._getWebGLTextureType(type);\n if (isWebGL2 && (target === 35866 || target === 32879)) {\n if (target === 35866) {\n texture.is2DArray = true;\n }\n else {\n texture.is3D = true;\n }\n texture.baseDepth = texture.depth = layerCount;\n gl.texImage3D(target, 0, internalSizedFormat, width, height, layerCount, 0, internalFormat, webGLTextureType, null);\n }\n else if (target === 34067) {\n // We have to generate all faces to complete the framebuffer\n for (let i = 0; i < 6; i++) {\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalSizedFormat, width, height, 0, internalFormat, webGLTextureType, null);\n }\n texture.isCube = true;\n }\n else {\n gl.texImage2D(gl.TEXTURE_2D, 0, internalSizedFormat, width, height, 0, internalFormat, webGLTextureType, null);\n }\n if (generateMipMaps) {\n gl.generateMipmap(target);\n }\n // Unbind\n this._bindTextureDirectly(target, null);\n texture.baseWidth = width;\n texture.baseHeight = height;\n texture.width = width;\n texture.height = height;\n texture.isReady = true;\n texture.samples = 1;\n texture.generateMipMaps = generateMipMaps;\n texture.samplingMode = samplingMode;\n texture.type = type;\n texture._useSRGBBuffer = useSRGBBuffer;\n texture.format = format;\n this._internalTexturesCache.push(texture);\n }\n if (generateDepthTexture && this._caps.depthTextureExtension) {\n // Depth texture\n const depthTexture = new InternalTexture(this, InternalTextureSource.Depth);\n let depthTextureType = 5;\n let glDepthTextureInternalFormat = gl.DEPTH_COMPONENT16;\n let glDepthTextureFormat = gl.DEPTH_COMPONENT;\n let glDepthTextureType = gl.UNSIGNED_SHORT;\n let glDepthTextureAttachment = gl.DEPTH_ATTACHMENT;\n if (this.webGLVersion < 2) {\n glDepthTextureInternalFormat = gl.DEPTH_COMPONENT;\n }\n else {\n if (depthTextureFormat === 14) {\n depthTextureType = 1;\n glDepthTextureType = gl.FLOAT;\n glDepthTextureInternalFormat = gl.DEPTH_COMPONENT32F;\n }\n else if (depthTextureFormat === 18) {\n depthTextureType = 0;\n glDepthTextureType = gl.FLOAT_32_UNSIGNED_INT_24_8_REV;\n glDepthTextureInternalFormat = gl.DEPTH32F_STENCIL8;\n glDepthTextureFormat = gl.DEPTH_STENCIL;\n glDepthTextureAttachment = gl.DEPTH_STENCIL_ATTACHMENT;\n }\n else if (depthTextureFormat === 16) {\n depthTextureType = 0;\n glDepthTextureType = gl.UNSIGNED_INT;\n glDepthTextureInternalFormat = gl.DEPTH_COMPONENT24;\n glDepthTextureAttachment = gl.DEPTH_ATTACHMENT;\n }\n else if (depthTextureFormat === 13 || depthTextureFormat === 17) {\n depthTextureType = 12;\n glDepthTextureType = gl.UNSIGNED_INT_24_8;\n glDepthTextureInternalFormat = gl.DEPTH24_STENCIL8;\n glDepthTextureFormat = gl.DEPTH_STENCIL;\n glDepthTextureAttachment = gl.DEPTH_STENCIL_ATTACHMENT;\n }\n }\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, depthTexture._hardwareTexture.underlyingResource);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texImage2D(gl.TEXTURE_2D, 0, glDepthTextureInternalFormat, width, height, 0, glDepthTextureFormat, glDepthTextureType, null);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, glDepthTextureAttachment, gl.TEXTURE_2D, depthTexture._hardwareTexture.underlyingResource, 0);\n depthTexture.baseWidth = width;\n depthTexture.baseHeight = height;\n depthTexture.width = width;\n depthTexture.height = height;\n depthTexture.isReady = true;\n depthTexture.samples = 1;\n depthTexture.generateMipMaps = generateMipMaps;\n depthTexture.samplingMode = 1;\n depthTexture.format = depthTextureFormat;\n depthTexture.type = depthTextureType;\n textures[textureCount] = depthTexture;\n this._internalTexturesCache.push(depthTexture);\n }\n rtWrapper.setTextures(textures);\n if (initializeBuffers) {\n gl.drawBuffers(attachments);\n }\n this._bindUnboundFramebuffer(null);\n rtWrapper.setLayerAndFaceIndices(layerIndex, faceIndex);\n this.resetTextureCache();\n return rtWrapper;\n };\n ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function (rtWrapper, samples, initializeBuffers = true) {\n if (this.webGLVersion < 2 || !rtWrapper || !rtWrapper.texture) {\n return 1;\n }\n if (rtWrapper.samples === samples) {\n return samples;\n }\n const count = rtWrapper._attachments.length;\n if (count === 0) {\n return 1;\n }\n const gl = this._gl;\n samples = Math.min(samples, this.getCaps().maxMSAASamples);\n // Dispose previous render buffers\n const useDepthStencil = !!rtWrapper._depthStencilBuffer;\n if (useDepthStencil) {\n gl.deleteRenderbuffer(rtWrapper._depthStencilBuffer);\n rtWrapper._depthStencilBuffer = null;\n }\n if (rtWrapper._MSAAFramebuffer) {\n gl.deleteFramebuffer(rtWrapper._MSAAFramebuffer);\n rtWrapper._MSAAFramebuffer = null;\n }\n if (samples > 1 && typeof gl.renderbufferStorageMultisample === \"function\") {\n const framebuffer = gl.createFramebuffer();\n if (!framebuffer) {\n throw new Error(\"Unable to create multi sampled framebuffer\");\n }\n rtWrapper._MSAAFramebuffer = framebuffer;\n this._bindUnboundFramebuffer(framebuffer);\n const attachments = [];\n for (let i = 0; i < count; i++) {\n const texture = rtWrapper.textures[i];\n const hardwareTexture = texture._hardwareTexture;\n hardwareTexture.releaseMSAARenderBuffers();\n }\n for (let i = 0; i < count; i++) {\n const texture = rtWrapper.textures[i];\n const hardwareTexture = texture._hardwareTexture;\n const attachment = gl[this.webGLVersion > 1 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\n const colorRenderbuffer = this._createRenderBuffer(texture.width, texture.height, samples, -1 /* not used */, this._getRGBAMultiSampleBufferFormat(texture.type, texture.format), attachment);\n if (!colorRenderbuffer) {\n throw new Error(\"Unable to create multi sampled framebuffer\");\n }\n hardwareTexture.addMSAARenderBuffer(colorRenderbuffer);\n texture.samples = samples;\n attachments.push(attachment);\n }\n if (initializeBuffers) {\n gl.drawBuffers(attachments);\n }\n }\n else {\n this._bindUnboundFramebuffer(rtWrapper._framebuffer);\n }\n if (useDepthStencil) {\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(rtWrapper._generateStencilBuffer, rtWrapper._generateDepthBuffer, rtWrapper.texture.width, rtWrapper.texture.height, samples);\n }\n this._bindUnboundFramebuffer(null);\n return samples;\n };\n\n /**\n * A multi render target, like a render target provides the ability to render to a texture.\n * Unlike the render target, it can render to several draw buffers in one draw.\n * This is specially interesting in deferred rendering or for any effects requiring more than\n * just one color from a single pass.\n */\n class MultiRenderTarget extends RenderTargetTexture {\n /**\n * Get if draw buffers are currently supported by the used hardware and browser.\n */\n get isSupported() {\n var _a, _b;\n return (_b = (_a = this._engine) === null || _a === void 0 ? void 0 : _a.getCaps().drawBuffersExtension) !== null && _b !== void 0 ? _b : false;\n }\n /**\n * Get the list of textures generated by the multi render target.\n */\n get textures() {\n return this._textures;\n }\n /**\n * Gets the number of textures in this MRT. This number can be different from `_textures.length` in case a depth texture is generated.\n */\n get count() {\n return this._count;\n }\n /**\n * Get the depth texture generated by the multi render target if options.generateDepthTexture has been set\n */\n get depthTexture() {\n return this._textures[this._textures.length - 1];\n }\n /**\n * Set the wrapping mode on U of all the textures we are rendering to.\n * Can be any of the Texture. (CLAMP_ADDRESSMODE, MIRROR_ADDRESSMODE or WRAP_ADDRESSMODE)\n */\n set wrapU(wrap) {\n if (this._textures) {\n for (let i = 0; i < this._textures.length; i++) {\n this._textures[i].wrapU = wrap;\n }\n }\n }\n /**\n * Set the wrapping mode on V of all the textures we are rendering to.\n * Can be any of the Texture. (CLAMP_ADDRESSMODE, MIRROR_ADDRESSMODE or WRAP_ADDRESSMODE)\n */\n set wrapV(wrap) {\n if (this._textures) {\n for (let i = 0; i < this._textures.length; i++) {\n this._textures[i].wrapV = wrap;\n }\n }\n }\n /**\n * Instantiate a new multi render target texture.\n * A multi render target, like a render target provides the ability to render to a texture.\n * Unlike the render target, it can render to several draw buffers in one draw.\n * This is specially interesting in deferred rendering or for any effects requiring more than\n * just one color from a single pass.\n * @param name Define the name of the texture\n * @param size Define the size of the buffers to render to\n * @param count Define the number of target we are rendering into\n * @param scene Define the scene the texture belongs to\n * @param options Define the options used to create the multi render target\n * @param textureNames Define the names to set to the textures (if count > 0 - optional)\n */\n constructor(name, size, count, scene, options, textureNames) {\n const generateMipMaps = options && options.generateMipMaps ? options.generateMipMaps : false;\n const generateDepthTexture = options && options.generateDepthTexture ? options.generateDepthTexture : false;\n const depthTextureFormat = options && options.depthTextureFormat ? options.depthTextureFormat : 15;\n const doNotChangeAspectRatio = !options || options.doNotChangeAspectRatio === undefined ? true : options.doNotChangeAspectRatio;\n const drawOnlyOnFirstAttachmentByDefault = options && options.drawOnlyOnFirstAttachmentByDefault ? options.drawOnlyOnFirstAttachmentByDefault : false;\n super(name, size, scene, generateMipMaps, doNotChangeAspectRatio, undefined, undefined, undefined, undefined, undefined, undefined, undefined, true);\n if (!this.isSupported) {\n this.dispose();\n return;\n }\n this._textureNames = textureNames;\n const types = [];\n const samplingModes = [];\n const useSRGBBuffers = [];\n const formats = [];\n const targetTypes = [];\n const faceIndex = [];\n const layerIndex = [];\n const layerCounts = [];\n this._initTypes(count, types, samplingModes, useSRGBBuffers, formats, targetTypes, faceIndex, layerIndex, layerCounts, options);\n const generateDepthBuffer = !options || options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;\n const generateStencilBuffer = !options || options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;\n this._multiRenderTargetOptions = {\n samplingModes: samplingModes,\n generateMipMaps: generateMipMaps,\n generateDepthBuffer: generateDepthBuffer,\n generateStencilBuffer: generateStencilBuffer,\n generateDepthTexture: generateDepthTexture,\n depthTextureFormat: depthTextureFormat,\n types: types,\n textureCount: count,\n useSRGBBuffers: useSRGBBuffers,\n formats: formats,\n targetTypes: targetTypes,\n faceIndex: faceIndex,\n layerIndex: layerIndex,\n layerCounts: layerCounts,\n };\n this._count = count;\n this._drawOnlyOnFirstAttachmentByDefault = drawOnlyOnFirstAttachmentByDefault;\n if (count > 0) {\n this._createInternalTextures();\n this._createTextures(textureNames);\n }\n }\n _initTypes(count, types, samplingModes, useSRGBBuffers, formats, targets, faceIndex, layerIndex, layerCounts, options) {\n for (let i = 0; i < count; i++) {\n if (options && options.types && options.types[i] !== undefined) {\n types.push(options.types[i]);\n }\n else {\n types.push(options && options.defaultType ? options.defaultType : 0);\n }\n if (options && options.samplingModes && options.samplingModes[i] !== undefined) {\n samplingModes.push(options.samplingModes[i]);\n }\n else {\n samplingModes.push(Texture.BILINEAR_SAMPLINGMODE);\n }\n if (options && options.useSRGBBuffers && options.useSRGBBuffers[i] !== undefined) {\n useSRGBBuffers.push(options.useSRGBBuffers[i]);\n }\n else {\n useSRGBBuffers.push(false);\n }\n if (options && options.formats && options.formats[i] !== undefined) {\n formats.push(options.formats[i]);\n }\n else {\n formats.push(5);\n }\n if (options && options.targetTypes && options.targetTypes[i] !== undefined) {\n targets.push(options.targetTypes[i]);\n }\n else {\n targets.push(3553);\n }\n if (options && options.faceIndex && options.faceIndex[i] !== undefined) {\n faceIndex.push(options.faceIndex[i]);\n }\n else {\n faceIndex.push(0);\n }\n if (options && options.layerIndex && options.layerIndex[i] !== undefined) {\n layerIndex.push(options.layerIndex[i]);\n }\n else {\n layerIndex.push(0);\n }\n if (options && options.layerCounts && options.layerCounts[i] !== undefined) {\n layerCounts.push(options.layerCounts[i]);\n }\n else {\n layerCounts.push(1);\n }\n }\n }\n _createInternaTextureIndexMapping() {\n const mapMainInternalTexture2Index = {};\n const mapInternalTexture2MainIndex = [];\n if (!this._renderTarget) {\n return mapInternalTexture2MainIndex;\n }\n const internalTextures = this._renderTarget.textures;\n for (let i = 0; i < internalTextures.length; i++) {\n const texture = internalTextures[i];\n if (!texture) {\n continue;\n }\n const mainIndex = mapMainInternalTexture2Index[texture.uniqueId];\n if (mainIndex !== undefined) {\n mapInternalTexture2MainIndex[i] = mainIndex;\n }\n else {\n mapMainInternalTexture2Index[texture.uniqueId] = i;\n }\n }\n return mapInternalTexture2MainIndex;\n }\n /**\n * @internal\n */\n _rebuild(forceFullRebuild = false, textureNames) {\n if (this._count < 1) {\n return;\n }\n const mapInternalTexture2MainIndex = this._createInternaTextureIndexMapping();\n this.releaseInternalTextures();\n this._createInternalTextures();\n if (forceFullRebuild) {\n this._releaseTextures();\n this._createTextures(textureNames);\n }\n const internalTextures = this._renderTarget.textures;\n for (let i = 0; i < internalTextures.length; i++) {\n const texture = this._textures[i];\n if (mapInternalTexture2MainIndex[i] !== undefined) {\n this._renderTarget.setTexture(internalTextures[mapInternalTexture2MainIndex[i]], i);\n }\n texture._texture = internalTextures[i];\n if (texture._texture) {\n texture._noMipmap = !texture._texture.useMipMaps;\n texture._useSRGBBuffer = texture._texture._useSRGBBuffer;\n }\n }\n if (this.samples !== 1) {\n this._renderTarget.setSamples(this.samples, !this._drawOnlyOnFirstAttachmentByDefault, true);\n }\n }\n _createInternalTextures() {\n this._renderTarget = this._getEngine().createMultipleRenderTarget(this._size, this._multiRenderTargetOptions, !this._drawOnlyOnFirstAttachmentByDefault);\n this._texture = this._renderTarget.texture;\n }\n _releaseTextures() {\n if (this._textures) {\n for (let i = 0; i < this._textures.length; i++) {\n this._textures[i]._texture = null; // internal textures are released by a call to releaseInternalTextures()\n this._textures[i].dispose();\n }\n }\n }\n _createTextures(textureNames) {\n const internalTextures = this._renderTarget.textures;\n this._textures = [];\n for (let i = 0; i < internalTextures.length; i++) {\n const texture = new Texture(null, this.getScene());\n if (textureNames === null || textureNames === void 0 ? void 0 : textureNames[i]) {\n texture.name = textureNames[i];\n }\n texture._texture = internalTextures[i];\n if (texture._texture) {\n texture._noMipmap = !texture._texture.useMipMaps;\n texture._useSRGBBuffer = texture._texture._useSRGBBuffer;\n }\n this._textures.push(texture);\n }\n }\n /**\n * Replaces an internal texture within the MRT. Useful to share textures between MultiRenderTarget.\n * @param texture The new texture to set in the MRT\n * @param index The index of the texture to replace\n * @param disposePrevious Set to true if the previous internal texture should be disposed\n */\n setInternalTexture(texture, index, disposePrevious = true) {\n var _a, _b;\n if (!this.renderTarget) {\n return;\n }\n if (index === 0) {\n this._texture = texture;\n }\n this.renderTarget.setTexture(texture, index, disposePrevious);\n if (!this.textures[index]) {\n this.textures[index] = new Texture(null, this.getScene());\n this.textures[index].name = (_b = (_a = this._textureNames) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : this.textures[index].name;\n }\n this.textures[index]._texture = texture;\n this.textures[index]._noMipmap = !texture.useMipMaps;\n this.textures[index]._useSRGBBuffer = texture._useSRGBBuffer;\n this._count = this.renderTarget.textures ? this.renderTarget.textures.length : 0;\n if (this._multiRenderTargetOptions.types) {\n this._multiRenderTargetOptions.types[index] = texture.type;\n }\n if (this._multiRenderTargetOptions.samplingModes) {\n this._multiRenderTargetOptions.samplingModes[index] = texture.samplingMode;\n }\n if (this._multiRenderTargetOptions.useSRGBBuffers) {\n this._multiRenderTargetOptions.useSRGBBuffers[index] = texture._useSRGBBuffer;\n }\n if (this._multiRenderTargetOptions.targetTypes && this._multiRenderTargetOptions.targetTypes[index] !== -1) {\n let target = 0;\n if (texture.is2DArray) {\n target = 35866;\n }\n else if (texture.isCube) {\n target = 34067;\n } /*else if (texture.isCubeArray) {\n target = 3735928559;\n }*/\n else if (texture.is3D) {\n target = 32879;\n }\n else {\n target = 3553;\n }\n this._multiRenderTargetOptions.targetTypes[index] = target;\n }\n }\n /**\n * Changes an attached texture's face index or layer.\n * @param index The index of the texture to modify the attachment of\n * @param layerIndex The layer index of the texture to be attached to the framebuffer\n * @param faceIndex The face index of the texture to be attached to the framebuffer\n */\n setLayerAndFaceIndex(index, layerIndex = -1, faceIndex = -1) {\n if (!this.textures[index] || !this.renderTarget) {\n return;\n }\n if (this._multiRenderTargetOptions.layerIndex) {\n this._multiRenderTargetOptions.layerIndex[index] = layerIndex;\n }\n if (this._multiRenderTargetOptions.faceIndex) {\n this._multiRenderTargetOptions.faceIndex[index] = faceIndex;\n }\n this.renderTarget.setLayerAndFaceIndex(index, layerIndex, faceIndex);\n }\n /**\n * Changes every attached texture's face index or layer.\n * @param layerIndices The layer indices of the texture to be attached to the framebuffer\n * @param faceIndices The face indices of the texture to be attached to the framebuffer\n */\n setLayerAndFaceIndices(layerIndices, faceIndices) {\n if (!this.renderTarget) {\n return;\n }\n this._multiRenderTargetOptions.layerIndex = layerIndices;\n this._multiRenderTargetOptions.faceIndex = faceIndices;\n this.renderTarget.setLayerAndFaceIndices(layerIndices, faceIndices);\n }\n /**\n * Define the number of samples used if MSAA is enabled.\n */\n get samples() {\n return this._samples;\n }\n set samples(value) {\n if (this._renderTarget) {\n this._samples = this._renderTarget.setSamples(value);\n }\n else {\n // In case samples are set with 0 textures created, we must save the desired samples value\n this._samples = value;\n }\n }\n /**\n * Resize all the textures in the multi render target.\n * Be careful as it will recreate all the data in the new texture.\n * @param size Define the new size\n */\n resize(size) {\n this._processSizeParameter(size, false);\n this._rebuild(undefined, this._textureNames);\n }\n /**\n * Changes the number of render targets in this MRT\n * Be careful as it will recreate all the data in the new texture.\n * @param count new texture count\n * @param options Specifies texture types and sampling modes for new textures\n * @param textureNames Specifies the names of the textures (optional)\n */\n updateCount(count, options, textureNames) {\n this._multiRenderTargetOptions.textureCount = count;\n this._count = count;\n const types = [];\n const samplingModes = [];\n const useSRGBBuffers = [];\n const formats = [];\n const targetTypes = [];\n const faceIndex = [];\n const layerIndex = [];\n const layerCounts = [];\n this._textureNames = textureNames;\n this._initTypes(count, types, samplingModes, useSRGBBuffers, formats, targetTypes, faceIndex, layerIndex, layerCounts, options);\n this._multiRenderTargetOptions.types = types;\n this._multiRenderTargetOptions.samplingModes = samplingModes;\n this._multiRenderTargetOptions.useSRGBBuffers = useSRGBBuffers;\n this._multiRenderTargetOptions.formats = formats;\n this._multiRenderTargetOptions.targetTypes = targetTypes;\n this._multiRenderTargetOptions.faceIndex = faceIndex;\n this._multiRenderTargetOptions.layerIndex = layerIndex;\n this._multiRenderTargetOptions.layerCounts = layerCounts;\n this._rebuild(true, textureNames);\n }\n _unbindFrameBuffer(engine, faceIndex) {\n if (this._renderTarget) {\n engine.unBindMultiColorAttachmentFramebuffer(this._renderTarget, this.isCube, () => {\n this.onAfterRenderObservable.notifyObservers(faceIndex);\n });\n }\n }\n /**\n * Dispose the render targets and their associated resources\n * @param doNotDisposeInternalTextures\n */\n dispose(doNotDisposeInternalTextures = false) {\n this._releaseTextures();\n if (!doNotDisposeInternalTextures) {\n this.releaseInternalTextures();\n }\n else {\n // Prevent internal texture dispose in super.dispose\n this._texture = null;\n }\n super.dispose();\n }\n /**\n * Release all the underlying texture used as draw buffers.\n */\n releaseInternalTextures() {\n var _a, _b;\n const internalTextures = (_a = this._renderTarget) === null || _a === void 0 ? void 0 : _a.textures;\n if (!internalTextures) {\n return;\n }\n for (let i = internalTextures.length - 1; i >= 0; i--) {\n this._textures[i]._texture = null;\n }\n (_b = this._renderTarget) === null || _b === void 0 ? void 0 : _b.dispose();\n this._renderTarget = null;\n }\n }\n\n // Do not edit.\n const name$2j = \"mrtFragmentDeclaration\";\n const shader$2j = `#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nlayout(location=0) out vec4 glFragData[{X}];\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2j] = shader$2j;\n\n // Do not edit.\n const name$2k = \"geometryPixelShader\";\n const shader$2k = `#extension GL_EXT_draw_buffers : require\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\nprecision highp float;\n#ifdef BUMP\nvarying mat4 vWorldView;varying vec3 vNormalW;\n#else\nvarying vec3 vNormalV;\n#endif\nvarying vec4 vViewPos;\n#if defined(POSITION) || defined(BUMP)\nvarying vec3 vPositionW;\n#endif\n#ifdef VELOCITY\nvarying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#ifdef NEED_UV\nvarying vec2 vUV;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIVITY)\n#if defined(ORMTEXTURE) || defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)\nuniform sampler2D reflectivitySampler;varying vec2 vReflectivityUV;\n#endif\n#ifdef ALBEDOTEXTURE\nvarying vec2 vAlbedoUV;uniform sampler2D albedoSampler;\n#endif\n#ifdef REFLECTIVITYCOLOR\nuniform vec3 reflectivityColor;\n#endif\n#ifdef ALBEDOCOLOR\nuniform vec3 albedoColor;\n#endif\n#ifdef METALLIC\nuniform float metallic;\n#endif\n#if defined(ROUGHNESS) || defined(GLOSSINESS)\nuniform float glossiness;\n#endif\n#endif\n#if defined(ALPHATEST) && defined(NEED_UV)\nuniform sampler2D diffuseSampler;\n#endif\n#include\n#include[RENDER_TARGET_COUNT]\n#include\n#include\n#include\nvoid main() {\n#include\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nvec3 normalOutput;\n#ifdef BUMP\nvec3 normalW=normalize(vNormalW);\n#include\nnormalOutput=normalize(vec3(vWorldView*vec4(normalW,0.0)));\n#else\nnormalOutput=normalize(vNormalV);\n#endif\n#ifdef PREPASS\n#ifdef PREPASS_DEPTH\ngl_FragData[DEPTH_INDEX]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n#endif\n#ifdef PREPASS_NORMAL\ngl_FragData[NORMAL_INDEX]=vec4(normalOutput,1.0);\n#endif\n#else\ngl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);gl_FragData[1]=vec4(normalOutput,1.0);\n#endif\n#ifdef POSITION\ngl_FragData[POSITION_INDEX]=vec4(vPositionW,1.0);\n#endif\n#ifdef VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[VELOCITY_INDEX]=vec4(velocity,0.0,1.0);\n#endif\n#ifdef REFLECTIVITY\nvec4 reflectivity=vec4(0.0,0.0,0.0,1.0);\n#ifdef METALLICWORKFLOW\nfloat metal=1.0;float roughness=1.0;\n#ifdef ORMTEXTURE\nmetal*=texture2D(reflectivitySampler,vReflectivityUV).b;roughness*=texture2D(reflectivitySampler,vReflectivityUV).g;\n#endif\n#ifdef METALLIC\nmetal*=metallic;\n#endif\n#ifdef ROUGHNESS\nroughness*=(1.0-glossiness); \n#endif\nreflectivity.a-=roughness;vec3 color=vec3(1.0);\n#ifdef ALBEDOTEXTURE\ncolor=texture2D(albedoSampler,vAlbedoUV).rgb;\n#ifdef GAMMAALBEDO\ncolor=toLinearSpace(color);\n#endif\n#endif\n#ifdef ALBEDOCOLOR\ncolor*=albedoColor.xyz;\n#endif\nreflectivity.rgb=mix(vec3(0.04),color,metal);\n#else\n#if defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)\nreflectivity=texture2D(reflectivitySampler,vReflectivityUV);\n#ifdef GAMMAREFLECTIVITYTEXTURE\nreflectivity.rgb=toLinearSpace(reflectivity.rgb);\n#endif\n#else \n#ifdef REFLECTIVITYCOLOR\nreflectivity.rgb=toLinearSpace(reflectivityColor.xyz);reflectivity.a=1.0;\n#endif\n#endif\n#ifdef GLOSSINESSS\nreflectivity.a*=glossiness; \n#endif\n#endif\ngl_FragData[REFLECTIVITY_INDEX]=reflectivity;\n#endif\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2k] = shader$2k;\n\n // Do not edit.\n const name$2l = \"geometryVertexDeclaration\";\n const shader$2l = `uniform mat4 viewProjection;uniform mat4 view;`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2l] = shader$2l;\n\n // Do not edit.\n const name$2m = \"geometryUboDeclaration\";\n const shader$2m = `#include\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2m] = shader$2m;\n\n // Do not edit.\n const name$2n = \"geometryVertexShader\";\n const shader$2n = `precision highp float;\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include<__decl__geometryVertex>\n#include\nattribute vec3 position;attribute vec3 normal;\n#ifdef NEED_UV\nvarying vec2 vUV;\n#ifdef ALPHATEST\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef BUMP\nuniform mat4 bumpMatrix;varying vec2 vBumpUV;\n#endif\n#ifdef REFLECTIVITY\nuniform mat4 reflectivityMatrix;uniform mat4 albedoMatrix;varying vec2 vReflectivityUV;varying vec2 vAlbedoUV;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#ifdef BUMP\nvarying mat4 vWorldView;\n#endif\n#ifdef BUMP\nvarying vec3 vNormalW;\n#else\nvarying vec3 vNormalV;\n#endif\nvarying vec4 vViewPos;\n#if defined(POSITION) || defined(BUMP)\nvarying vec3 vPositionW;\n#endif\n#ifdef VELOCITY\nuniform mat4 previousViewProjection;varying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;vec3 normalUpdated=normal;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#if defined(VELOCITY) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include\n#include\nvec4 worldPos=vec4(finalWorld*vec4(positionUpdated,1.0));\n#ifdef BUMP\nvWorldView=view*finalWorld;vNormalW=normalUpdated;\n#else\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normalUpdated,0.0)));\n#endif\nvViewPos=view*worldPos;\n#if defined(VELOCITY) && defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n#if NUM_BONE_INFLUENCERS>0\nmat4 previousInfluence;previousInfluence=mPreviousBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\npreviousInfluence+=mPreviousBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\npreviousInfluence+=mPreviousBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\npreviousInfluence+=mPreviousBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\nvPreviousPosition=previousViewProjection*finalPreviousWorld*previousInfluence*vec4(positionUpdated,1.0);\n#else\nvPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#endif\n#if defined(POSITION) || defined(BUMP)\nvPositionW=worldPos.xyz/worldPos.w;\n#endif\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n#include\n#ifdef NEED_UV\n#ifdef UV1\n#if defined(ALPHATEST) && defined(ALPHATEST_UV1)\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#else\nvUV=uv;\n#endif\n#ifdef BUMP_UV1\nvBumpUV=vec2(bumpMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef REFLECTIVITY_UV1\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef ALBEDO_UV1\nvAlbedoUV=vec2(albedoMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#endif\n#ifdef UV2\n#if defined(ALPHATEST) && defined(ALPHATEST_UV2)\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#else\nvUV=uv2;\n#endif\n#ifdef BUMP_UV2\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n#endif\n#ifdef REFLECTIVITY_UV2\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n#endif\n#ifdef ALBEDO_UV2\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#endif\n#include\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2n] = shader$2n;\n\n /** list the uniforms used by the geometry renderer */\n const uniforms = [\n \"world\",\n \"mBones\",\n \"viewProjection\",\n \"diffuseMatrix\",\n \"view\",\n \"previousWorld\",\n \"previousViewProjection\",\n \"mPreviousBones\",\n \"bumpMatrix\",\n \"reflectivityMatrix\",\n \"albedoMatrix\",\n \"reflectivityColor\",\n \"albedoColor\",\n \"metallic\",\n \"glossiness\",\n \"vTangentSpaceParams\",\n \"vBumpInfos\",\n \"morphTargetInfluences\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n ];\n addClipPlaneUniforms(uniforms);\n /**\n * This renderer is helpful to fill one of the render target with a geometry buffer.\n */\n class GeometryBufferRenderer {\n /**\n * @internal\n * Sets up internal structures to share outputs with PrePassRenderer\n * This method should only be called by the PrePassRenderer itself\n */\n _linkPrePassRenderer(prePassRenderer) {\n this._linkedWithPrePass = true;\n this._prePassRenderer = prePassRenderer;\n if (this._multiRenderTarget) {\n // prevents clearing of the RT since it's done by prepass\n this._multiRenderTarget.onClearObservable.clear();\n this._multiRenderTarget.onClearObservable.add(() => {\n // pass\n });\n }\n }\n /**\n * @internal\n * Separates internal structures from PrePassRenderer so the geometry buffer can now operate by itself.\n * This method should only be called by the PrePassRenderer itself\n */\n _unlinkPrePassRenderer() {\n this._linkedWithPrePass = false;\n this._createRenderTargets();\n }\n /**\n * @internal\n * Resets the geometry buffer layout\n */\n _resetLayout() {\n this._enablePosition = false;\n this._enableReflectivity = false;\n this._enableVelocity = false;\n this._attachmentsFromPrePass = [];\n }\n /**\n * @internal\n * Replaces a texture in the geometry buffer renderer\n * Useful when linking textures of the prepass renderer\n */\n _forceTextureType(geometryBufferType, index) {\n if (geometryBufferType === GeometryBufferRenderer.POSITION_TEXTURE_TYPE) {\n this._positionIndex = index;\n this._enablePosition = true;\n }\n else if (geometryBufferType === GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE) {\n this._velocityIndex = index;\n this._enableVelocity = true;\n }\n else if (geometryBufferType === GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE) {\n this._reflectivityIndex = index;\n this._enableReflectivity = true;\n }\n else if (geometryBufferType === GeometryBufferRenderer.DEPTH_TEXTURE_TYPE) {\n this._depthIndex = index;\n }\n else if (geometryBufferType === GeometryBufferRenderer.NORMAL_TEXTURE_TYPE) {\n this._normalIndex = index;\n }\n }\n /**\n * @internal\n * Sets texture attachments\n * Useful when linking textures of the prepass renderer\n */\n _setAttachments(attachments) {\n this._attachmentsFromPrePass = attachments;\n }\n /**\n * @internal\n * Replaces the first texture which is hard coded as a depth texture in the geometry buffer\n * Useful when linking textures of the prepass renderer\n */\n _linkInternalTexture(internalTexture) {\n this._multiRenderTarget.setInternalTexture(internalTexture, 0, false);\n }\n /**\n * Gets the render list (meshes to be rendered) used in the G buffer.\n */\n get renderList() {\n return this._multiRenderTarget.renderList;\n }\n /**\n * Set the render list (meshes to be rendered) used in the G buffer.\n */\n set renderList(meshes) {\n this._multiRenderTarget.renderList = meshes;\n }\n /**\n * Gets whether or not G buffer are supported by the running hardware.\n * This requires draw buffer supports\n */\n get isSupported() {\n return this._multiRenderTarget.isSupported;\n }\n /**\n * Returns the index of the given texture type in the G-Buffer textures array\n * @param textureType The texture type constant. For example GeometryBufferRenderer.POSITION_TEXTURE_INDEX\n * @returns the index of the given texture type in the G-Buffer textures array\n */\n getTextureIndex(textureType) {\n switch (textureType) {\n case GeometryBufferRenderer.POSITION_TEXTURE_TYPE:\n return this._positionIndex;\n case GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE:\n return this._velocityIndex;\n case GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE:\n return this._reflectivityIndex;\n default:\n return -1;\n }\n }\n /**\n * Gets a boolean indicating if objects positions are enabled for the G buffer.\n */\n get enablePosition() {\n return this._enablePosition;\n }\n /**\n * Sets whether or not objects positions are enabled for the G buffer.\n */\n set enablePosition(enable) {\n this._enablePosition = enable;\n // PrePass handles index and texture links\n if (!this._linkedWithPrePass) {\n this.dispose();\n this._createRenderTargets();\n }\n }\n /**\n * Gets a boolean indicating if objects velocities are enabled for the G buffer.\n */\n get enableVelocity() {\n return this._enableVelocity;\n }\n /**\n * Sets whether or not objects velocities are enabled for the G buffer.\n */\n set enableVelocity(enable) {\n this._enableVelocity = enable;\n if (!enable) {\n this._previousTransformationMatrices = {};\n }\n if (!this._linkedWithPrePass) {\n this.dispose();\n this._createRenderTargets();\n }\n this._scene.needsPreviousWorldMatrices = enable;\n }\n /**\n * Gets a boolean indicating if objects reflectivity are enabled in the G buffer.\n */\n get enableReflectivity() {\n return this._enableReflectivity;\n }\n /**\n * Sets whether or not objects reflectivity are enabled for the G buffer.\n * For Metallic-Roughness workflow with ORM texture, we assume that ORM texture is defined according to the default layout:\n * pbr.useRoughnessFromMetallicTextureAlpha = false;\n * pbr.useRoughnessFromMetallicTextureGreen = true;\n * pbr.useMetallnessFromMetallicTextureBlue = true;\n */\n set enableReflectivity(enable) {\n this._enableReflectivity = enable;\n if (!this._linkedWithPrePass) {\n this.dispose();\n this._createRenderTargets();\n }\n }\n /**\n * Gets the scene associated with the buffer.\n */\n get scene() {\n return this._scene;\n }\n /**\n * Gets the ratio used by the buffer during its creation.\n * How big is the buffer related to the main canvas.\n */\n get ratio() {\n return this._ratio;\n }\n /**\n * Creates a new G Buffer for the scene\n * @param scene The scene the buffer belongs to\n * @param ratio How big is the buffer related to the main canvas (default: 1)\n * @param depthFormat Format of the depth texture (default: 15)\n */\n constructor(scene, ratio = 1, depthFormat = 15) {\n /**\n * Dictionary used to store the previous transformation matrices of each rendered mesh\n * in order to compute objects velocities when enableVelocity is set to \"true\"\n * @internal\n */\n this._previousTransformationMatrices = {};\n /**\n * Dictionary used to store the previous bones transformation matrices of each rendered mesh\n * in order to compute objects velocities when enableVelocity is set to \"true\"\n * @internal\n */\n this._previousBonesTransformationMatrices = {};\n /**\n * Array used to store the ignored skinned meshes while computing velocity map (typically used by the motion blur post-process).\n * Avoids computing bones velocities and computes only mesh's velocity itself (position, rotation, scaling).\n */\n this.excludedSkinnedMeshesFromVelocity = [];\n /** Gets or sets a boolean indicating if transparent meshes should be rendered */\n this.renderTransparentMeshes = true;\n this._resizeObserver = null;\n this._enablePosition = false;\n this._enableVelocity = false;\n this._enableReflectivity = false;\n this._clearColor = new Color4(0, 0, 0, 0);\n this._clearDepthColor = new Color4(1e8, 0, 0, 1); // \"infinity\" value - depth in the depth texture is view.z, not a 0..1 value!\n this._positionIndex = -1;\n this._velocityIndex = -1;\n this._reflectivityIndex = -1;\n this._depthIndex = -1;\n this._normalIndex = -1;\n this._linkedWithPrePass = false;\n /**\n * If set to true (default: false), the depth texture will be cleared with the depth value corresponding to the far plane (1 in normal mode, 0 in reverse depth buffer mode)\n * If set to false, the depth texture is always cleared with 0.\n */\n this.useSpecificClearForDepthTexture = false;\n this._scene = scene;\n this._ratio = ratio;\n this._useUbo = scene.getEngine().supportsUniformBuffers;\n this._depthFormat = depthFormat;\n GeometryBufferRenderer._SceneComponentInitialization(this._scene);\n // Render target\n this._createRenderTargets();\n }\n /**\n * Checks whether everything is ready to render a submesh to the G buffer.\n * @param subMesh the submesh to check readiness for\n * @param useInstances is the mesh drawn using instance or not\n * @returns true if ready otherwise false\n */\n isReady(subMesh, useInstances) {\n const material = subMesh.getMaterial();\n if (material && material.disableDepthWrite) {\n return false;\n }\n const defines = [];\n const attribs = [VertexBuffer.PositionKind, VertexBuffer.NormalKind];\n const mesh = subMesh.getMesh();\n // Alpha test\n if (material) {\n let needUv = false;\n if (material.needAlphaTesting() && material.getAlphaTestTexture()) {\n defines.push(\"#define ALPHATEST\");\n defines.push(`#define ALPHATEST_UV${material.getAlphaTestTexture().coordinatesIndex + 1}`);\n needUv = true;\n }\n if (material.bumpTexture && MaterialFlags.BumpTextureEnabled) {\n defines.push(\"#define BUMP\");\n defines.push(`#define BUMP_UV${material.bumpTexture.coordinatesIndex + 1}`);\n needUv = true;\n }\n if (this._enableReflectivity) {\n let metallicWorkflow = false;\n // for PBR materials: cf. https://doc.babylonjs.com/features/featuresDeepDive/materials/using/masterPBR\n if (material.getClassName() === \"PBRMetallicRoughnessMaterial\") {\n // if it is a PBR material in MetallicRoughness Mode:\n if (material.metallicRoughnessTexture !== null) {\n defines.push(\"#define ORMTEXTURE\");\n defines.push(`#define REFLECTIVITY_UV${material.metallicRoughnessTexture.coordinatesIndex + 1}`);\n defines.push(\"#define METALLICWORKFLOW\");\n needUv = true;\n metallicWorkflow = true;\n }\n if (material.metallic !== null) {\n defines.push(\"#define METALLIC\");\n defines.push(\"#define METALLICWORKFLOW\");\n metallicWorkflow = true;\n }\n if (material.roughness !== null) {\n defines.push(\"#define ROUGHNESS\");\n defines.push(\"#define METALLICWORKFLOW\");\n metallicWorkflow = true;\n }\n if (metallicWorkflow) {\n if (material.baseTexture !== null) {\n defines.push(\"#define ALBEDOTEXTURE\");\n defines.push(`#define ALBEDO_UV${material.baseTexture.coordinatesIndex + 1}`);\n if (material.baseTexture.gammaSpace) {\n defines.push(\"#define GAMMAALBEDO\");\n }\n needUv = true;\n }\n if (material.baseColor !== null) {\n defines.push(\"#define ALBEDOCOLOR\");\n }\n }\n }\n else if (material.getClassName() === \"PBRSpecularGlossinessMaterial\") {\n // if it is a PBR material in Specular/Glossiness Mode:\n if (material.specularGlossinessTexture !== null) {\n defines.push(\"#define SPECULARGLOSSINESSTEXTURE\");\n defines.push(`#define REFLECTIVITY_UV${material.specularGlossinessTexture.coordinatesIndex + 1}`);\n needUv = true;\n if (material.specularGlossinessTexture.gammaSpace) {\n defines.push(\"#define GAMMAREFLECTIVITYTEXTURE\");\n }\n }\n else {\n if (material.specularColor !== null) {\n defines.push(\"#define REFLECTIVITYCOLOR\");\n }\n }\n if (material.glossiness !== null) {\n defines.push(\"#define GLOSSINESS\");\n }\n }\n else if (material.getClassName() === \"PBRMaterial\") {\n // if it is the bigger PBRMaterial\n if (material.metallicTexture !== null) {\n defines.push(\"#define ORMTEXTURE\");\n defines.push(`#define REFLECTIVITY_UV${material.metallicTexture.coordinatesIndex + 1}`);\n defines.push(\"#define METALLICWORKFLOW\");\n needUv = true;\n metallicWorkflow = true;\n }\n if (material.metallic !== null) {\n defines.push(\"#define METALLIC\");\n defines.push(\"#define METALLICWORKFLOW\");\n metallicWorkflow = true;\n }\n if (material.roughness !== null) {\n defines.push(\"#define ROUGHNESS\");\n defines.push(\"#define METALLICWORKFLOW\");\n metallicWorkflow = true;\n }\n if (metallicWorkflow) {\n if (material.albedoTexture !== null) {\n defines.push(\"#define ALBEDOTEXTURE\");\n defines.push(`#define ALBEDO_UV${material.albedoTexture.coordinatesIndex + 1}`);\n if (material.albedoTexture.gammaSpace) {\n defines.push(\"#define GAMMAALBEDO\");\n }\n needUv = true;\n }\n if (material.albedoColor !== null) {\n defines.push(\"#define ALBEDOCOLOR\");\n }\n }\n else {\n // SpecularGlossiness Model\n if (material.reflectivityTexture !== null) {\n defines.push(\"#define SPECULARGLOSSINESSTEXTURE\");\n defines.push(`#define REFLECTIVITY_UV${material.reflectivityTexture.coordinatesIndex + 1}`);\n if (material.reflectivityTexture.gammaSpace) {\n defines.push(\"#define GAMMAREFLECTIVITYTEXTURE\");\n }\n needUv = true;\n }\n else if (material.reflectivityColor !== null) {\n defines.push(\"#define REFLECTIVITYCOLOR\");\n }\n if (material.microSurface !== null) {\n defines.push(\"#define GLOSSINESS\");\n }\n }\n }\n else if (material.getClassName() === \"StandardMaterial\") {\n // if StandardMaterial:\n if (material.specularTexture !== null) {\n defines.push(\"#define REFLECTIVITYTEXTURE\");\n defines.push(`#define REFLECTIVITY_UV${material.specularTexture.coordinatesIndex + 1}`);\n if (material.specularTexture.gammaSpace) {\n defines.push(\"#define GAMMAREFLECTIVITYTEXTURE\");\n }\n needUv = true;\n }\n if (material.specularColor !== null) {\n defines.push(\"#define REFLECTIVITYCOLOR\");\n }\n }\n }\n if (needUv) {\n defines.push(\"#define NEED_UV\");\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n attribs.push(VertexBuffer.UVKind);\n defines.push(\"#define UV1\");\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\n attribs.push(VertexBuffer.UV2Kind);\n defines.push(\"#define UV2\");\n }\n }\n }\n // PrePass\n if (this._linkedWithPrePass) {\n defines.push(\"#define PREPASS\");\n if (this._depthIndex !== -1) {\n defines.push(\"#define DEPTH_INDEX \" + this._depthIndex);\n defines.push(\"#define PREPASS_DEPTH\");\n }\n if (this._normalIndex !== -1) {\n defines.push(\"#define NORMAL_INDEX \" + this._normalIndex);\n defines.push(\"#define PREPASS_NORMAL\");\n }\n }\n // Buffers\n if (this._enablePosition) {\n defines.push(\"#define POSITION\");\n defines.push(\"#define POSITION_INDEX \" + this._positionIndex);\n }\n if (this._enableVelocity) {\n defines.push(\"#define VELOCITY\");\n defines.push(\"#define VELOCITY_INDEX \" + this._velocityIndex);\n if (this.excludedSkinnedMeshesFromVelocity.indexOf(mesh) === -1) {\n defines.push(\"#define BONES_VELOCITY_ENABLED\");\n }\n }\n if (this._enableReflectivity) {\n defines.push(\"#define REFLECTIVITY\");\n defines.push(\"#define REFLECTIVITY_INDEX \" + this._reflectivityIndex);\n }\n // Bones\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (mesh.numBoneInfluencers > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\n defines.push(\"#define BonesPerMesh \" + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));\n }\n else {\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\n }\n // Morph targets\n const morphTargetManager = mesh.morphTargetManager;\n let numMorphInfluencers = 0;\n if (morphTargetManager) {\n if (morphTargetManager.numInfluencers > 0) {\n numMorphInfluencers = morphTargetManager.numInfluencers;\n defines.push(\"#define MORPHTARGETS\");\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numMorphInfluencers);\n if (morphTargetManager.isUsingTextureForTargets) {\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\n }\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, numMorphInfluencers);\n }\n }\n // Instances\n if (useInstances) {\n defines.push(\"#define INSTANCES\");\n MaterialHelper.PushAttributesForInstances(attribs, this._enableVelocity);\n if (subMesh.getRenderingMesh().hasThinInstances) {\n defines.push(\"#define THIN_INSTANCES\");\n }\n }\n // Setup textures count\n if (this._linkedWithPrePass) {\n defines.push(\"#define RENDER_TARGET_COUNT \" + this._attachmentsFromPrePass.length);\n }\n else {\n defines.push(\"#define RENDER_TARGET_COUNT \" + this._multiRenderTarget.textures.length);\n }\n prepareStringDefinesForClipPlanes(material, this._scene, defines);\n // Get correct effect\n const engine = this._scene.getEngine();\n const drawWrapper = subMesh._getDrawWrapper(undefined, true);\n const cachedDefines = drawWrapper.defines;\n const join = defines.join(\"\\n\");\n if (cachedDefines !== join) {\n drawWrapper.setEffect(engine.createEffect(\"geometry\", {\n attributes: attribs,\n uniformsNames: uniforms,\n samplers: [\"diffuseSampler\", \"bumpSampler\", \"reflectivitySampler\", \"albedoSampler\", \"morphTargets\"],\n defines: join,\n onCompiled: null,\n fallbacks: null,\n onError: null,\n uniformBuffersNames: [\"Scene\"],\n indexParameters: { buffersCount: this._multiRenderTarget.textures.length - 1, maxSimultaneousMorphTargets: numMorphInfluencers },\n }, engine), join);\n }\n return drawWrapper.effect.isReady();\n }\n /**\n * Gets the current underlying G Buffer.\n * @returns the buffer\n */\n getGBuffer() {\n return this._multiRenderTarget;\n }\n /**\n * Gets the number of samples used to render the buffer (anti aliasing).\n */\n get samples() {\n return this._multiRenderTarget.samples;\n }\n /**\n * Sets the number of samples used to render the buffer (anti aliasing).\n */\n set samples(value) {\n this._multiRenderTarget.samples = value;\n }\n /**\n * Disposes the renderer and frees up associated resources.\n */\n dispose() {\n if (this._resizeObserver) {\n const engine = this._scene.getEngine();\n engine.onResizeObservable.remove(this._resizeObserver);\n this._resizeObserver = null;\n }\n this.getGBuffer().dispose();\n }\n _assignRenderTargetIndices() {\n const textureNames = [];\n let count = 2;\n textureNames.push(\"gBuffer_Depth\", \"gBuffer_Normal\");\n if (this._enablePosition) {\n this._positionIndex = count;\n count++;\n textureNames.push(\"gBuffer_Position\");\n }\n if (this._enableVelocity) {\n this._velocityIndex = count;\n count++;\n textureNames.push(\"gBuffer_Velocity\");\n }\n if (this._enableReflectivity) {\n this._reflectivityIndex = count;\n count++;\n textureNames.push(\"gBuffer_Reflectivity\");\n }\n return [count, textureNames];\n }\n _createRenderTargets() {\n const engine = this._scene.getEngine();\n const [count, textureNames] = this._assignRenderTargetIndices();\n let type = 0;\n if (engine._caps.textureFloat && engine._caps.textureFloatLinearFiltering) {\n type = 1;\n }\n else if (engine._caps.textureHalfFloat && engine._caps.textureHalfFloatLinearFiltering) {\n type = 2;\n }\n this._multiRenderTarget = new MultiRenderTarget(\"gBuffer\", { width: engine.getRenderWidth() * this._ratio, height: engine.getRenderHeight() * this._ratio }, count, this._scene, { generateMipMaps: false, generateDepthTexture: true, defaultType: type, depthTextureFormat: this._depthFormat }, textureNames.concat(\"gBuffer_DepthBuffer\"));\n if (!this.isSupported) {\n return;\n }\n this._multiRenderTarget.wrapU = Texture.CLAMP_ADDRESSMODE;\n this._multiRenderTarget.wrapV = Texture.CLAMP_ADDRESSMODE;\n this._multiRenderTarget.refreshRate = 1;\n this._multiRenderTarget.renderParticles = false;\n this._multiRenderTarget.renderList = null;\n // Depth is always the first texture in the geometry buffer renderer!\n const layoutAttachmentsAll = [true];\n const layoutAttachmentsAllButDepth = [false];\n const layoutAttachmentsDepthOnly = [true];\n for (let i = 1; i < count; ++i) {\n layoutAttachmentsAll.push(true);\n layoutAttachmentsDepthOnly.push(false);\n layoutAttachmentsAllButDepth.push(true);\n }\n const attachmentsAll = engine.buildTextureLayout(layoutAttachmentsAll);\n const attachmentsAllButDepth = engine.buildTextureLayout(layoutAttachmentsAllButDepth);\n const attachmentsDepthOnly = engine.buildTextureLayout(layoutAttachmentsDepthOnly);\n this._multiRenderTarget.onClearObservable.add((engine) => {\n engine.bindAttachments(this.useSpecificClearForDepthTexture ? attachmentsAllButDepth : attachmentsAll);\n engine.clear(this._clearColor, true, true, true);\n if (this.useSpecificClearForDepthTexture) {\n engine.bindAttachments(attachmentsDepthOnly);\n engine.clear(this._clearDepthColor, true, true, true);\n }\n engine.bindAttachments(attachmentsAll);\n });\n this._resizeObserver = engine.onResizeObservable.add(() => {\n if (this._multiRenderTarget) {\n this._multiRenderTarget.resize({ width: engine.getRenderWidth() * this._ratio, height: engine.getRenderHeight() * this._ratio });\n }\n });\n // Custom render function\n const renderSubMesh = (subMesh) => {\n const renderingMesh = subMesh.getRenderingMesh();\n const effectiveMesh = subMesh.getEffectiveMesh();\n const scene = this._scene;\n const engine = scene.getEngine();\n const material = subMesh.getMaterial();\n if (!material) {\n return;\n }\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\n // Velocity\n if (this._enableVelocity && !this._previousTransformationMatrices[effectiveMesh.uniqueId]) {\n this._previousTransformationMatrices[effectiveMesh.uniqueId] = {\n world: Matrix.Identity(),\n viewProjection: scene.getTransformMatrix(),\n };\n if (renderingMesh.skeleton) {\n const bonesTransformations = renderingMesh.skeleton.getTransformMatrices(renderingMesh);\n this._previousBonesTransformationMatrices[renderingMesh.uniqueId] = this._copyBonesTransformationMatrices(bonesTransformations, new Float32Array(bonesTransformations.length));\n }\n }\n // Managing instances\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\n if (batch.mustReturn) {\n return;\n }\n const hardwareInstancedRendering = engine.getCaps().instancedArrays && (batch.visibleInstances[subMesh._id] !== null || renderingMesh.hasThinInstances);\n const world = effectiveMesh.getWorldMatrix();\n if (this.isReady(subMesh, hardwareInstancedRendering)) {\n const drawWrapper = subMesh._getDrawWrapper();\n if (!drawWrapper) {\n return;\n }\n const effect = drawWrapper.effect;\n engine.enableEffect(drawWrapper);\n if (!hardwareInstancedRendering) {\n renderingMesh._bind(subMesh, effect, material.fillMode);\n }\n if (!this._useUbo) {\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\n effect.setMatrix(\"view\", scene.getViewMatrix());\n }\n else {\n MaterialHelper.BindSceneUniformBuffer(effect, this._scene.getSceneUniformBuffer());\n this._scene.finalizeSceneUbo();\n }\n let sideOrientation;\n const instanceDataStorage = renderingMesh._instanceDataStorage;\n if (!instanceDataStorage.isFrozen && (material.backFaceCulling || renderingMesh.overrideMaterialSideOrientation !== null)) {\n const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();\n sideOrientation = renderingMesh.overrideMaterialSideOrientation;\n if (sideOrientation === null) {\n sideOrientation = material.sideOrientation;\n }\n if (mainDeterminant < 0) {\n sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;\n }\n }\n else {\n sideOrientation = instanceDataStorage.sideOrientation;\n }\n material._preBind(drawWrapper, sideOrientation);\n // Alpha test\n if (material.needAlphaTesting()) {\n const alphaTexture = material.getAlphaTestTexture();\n if (alphaTexture) {\n effect.setTexture(\"diffuseSampler\", alphaTexture);\n effect.setMatrix(\"diffuseMatrix\", alphaTexture.getTextureMatrix());\n }\n }\n // Bump\n if (material.bumpTexture && scene.getEngine().getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled) {\n effect.setFloat3(\"vBumpInfos\", material.bumpTexture.coordinatesIndex, 1.0 / material.bumpTexture.level, material.parallaxScaleBias);\n effect.setMatrix(\"bumpMatrix\", material.bumpTexture.getTextureMatrix());\n effect.setTexture(\"bumpSampler\", material.bumpTexture);\n effect.setFloat2(\"vTangentSpaceParams\", material.invertNormalMapX ? -1.0 : 1.0, material.invertNormalMapY ? -1.0 : 1.0);\n }\n // Reflectivity\n if (this._enableReflectivity) {\n // for PBR materials: cf. https://doc.babylonjs.com/features/featuresDeepDive/materials/using/masterPBR\n if (material.getClassName() === \"PBRMetallicRoughnessMaterial\") {\n // if it is a PBR material in MetallicRoughness Mode:\n if (material.metallicRoughnessTexture !== null) {\n effect.setTexture(\"reflectivitySampler\", material.metallicRoughnessTexture);\n effect.setMatrix(\"reflectivityMatrix\", material.metallicRoughnessTexture.getTextureMatrix());\n }\n if (material.metallic !== null) {\n effect.setFloat(\"metallic\", material.metallic);\n }\n if (material.roughness !== null) {\n effect.setFloat(\"glossiness\", 1.0 - material.roughness);\n }\n if (material.baseTexture !== null) {\n effect.setTexture(\"albedoSampler\", material.baseTexture);\n effect.setMatrix(\"albedoMatrix\", material.baseTexture.getTextureMatrix());\n }\n if (material.baseColor !== null) {\n effect.setColor3(\"albedoColor\", material.baseColor);\n }\n }\n else if (material.getClassName() === \"PBRSpecularGlossinessMaterial\") {\n // if it is a PBR material in Specular/Glossiness Mode:\n if (material.specularGlossinessTexture !== null) {\n effect.setTexture(\"reflectivitySampler\", material.specularGlossinessTexture);\n effect.setMatrix(\"reflectivityMatrix\", material.specularGlossinessTexture.getTextureMatrix());\n }\n else {\n if (material.specularColor !== null) {\n effect.setColor3(\"reflectivityColor\", material.specularColor);\n }\n }\n if (material.glossiness !== null) {\n effect.setFloat(\"glossiness\", material.glossiness);\n }\n }\n else if (material.getClassName() === \"PBRMaterial\") {\n // if it is the bigger PBRMaterial\n if (material.metallicTexture !== null) {\n effect.setTexture(\"reflectivitySampler\", material.metallicTexture);\n effect.setMatrix(\"reflectivityMatrix\", material.metallicTexture.getTextureMatrix());\n }\n if (material.metallic !== null) {\n effect.setFloat(\"metallic\", material.metallic);\n }\n if (material.roughness !== null) {\n effect.setFloat(\"glossiness\", 1.0 - material.roughness);\n }\n if (material.roughness !== null || material.metallic !== null || material.metallicTexture !== null) {\n // MetallicRoughness Model\n if (material.albedoTexture !== null) {\n effect.setTexture(\"albedoSampler\", material.albedoTexture);\n effect.setMatrix(\"albedoMatrix\", material.albedoTexture.getTextureMatrix());\n }\n if (material.albedoColor !== null) {\n effect.setColor3(\"albedoColor\", material.albedoColor);\n }\n }\n else {\n // SpecularGlossiness Model\n if (material.reflectivityTexture !== null) {\n effect.setTexture(\"reflectivitySampler\", material.reflectivityTexture);\n effect.setMatrix(\"reflectivityMatrix\", material.reflectivityTexture.getTextureMatrix());\n }\n else if (material.reflectivityColor !== null) {\n effect.setColor3(\"reflectivityColor\", material.reflectivityColor);\n }\n if (material.microSurface !== null) {\n effect.setFloat(\"glossiness\", material.microSurface);\n }\n }\n }\n else if (material.getClassName() === \"StandardMaterial\") {\n // if StandardMaterial:\n if (material.specularTexture !== null) {\n effect.setTexture(\"reflectivitySampler\", material.specularTexture);\n effect.setMatrix(\"reflectivityMatrix\", material.specularTexture.getTextureMatrix());\n }\n if (material.specularColor !== null) {\n effect.setColor3(\"reflectivityColor\", material.specularColor);\n }\n }\n }\n // Clip plane\n bindClipPlane(effect, material, this._scene);\n // Bones\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\n effect.setMatrices(\"mBones\", renderingMesh.skeleton.getTransformMatrices(renderingMesh));\n if (this._enableVelocity) {\n effect.setMatrices(\"mPreviousBones\", this._previousBonesTransformationMatrices[renderingMesh.uniqueId]);\n }\n }\n // Morph targets\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\n renderingMesh.morphTargetManager._bind(effect);\n }\n // Velocity\n if (this._enableVelocity) {\n effect.setMatrix(\"previousWorld\", this._previousTransformationMatrices[effectiveMesh.uniqueId].world);\n effect.setMatrix(\"previousViewProjection\", this._previousTransformationMatrices[effectiveMesh.uniqueId].viewProjection);\n }\n if (hardwareInstancedRendering && renderingMesh.hasThinInstances) {\n effect.setMatrix(\"world\", world);\n }\n // Draw\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, w) => {\n if (!isInstance) {\n effect.setMatrix(\"world\", w);\n }\n });\n }\n // Velocity\n if (this._enableVelocity) {\n this._previousTransformationMatrices[effectiveMesh.uniqueId].world = world.clone();\n this._previousTransformationMatrices[effectiveMesh.uniqueId].viewProjection = this._scene.getTransformMatrix().clone();\n if (renderingMesh.skeleton) {\n this._copyBonesTransformationMatrices(renderingMesh.skeleton.getTransformMatrices(renderingMesh), this._previousBonesTransformationMatrices[effectiveMesh.uniqueId]);\n }\n }\n };\n this._multiRenderTarget.customIsReadyFunction = (mesh, refreshRate, preWarm) => {\n if ((preWarm || refreshRate === 0) && mesh.subMeshes) {\n for (let i = 0; i < mesh.subMeshes.length; ++i) {\n const subMesh = mesh.subMeshes[i];\n const material = subMesh.getMaterial();\n const renderingMesh = subMesh.getRenderingMesh();\n if (!material) {\n continue;\n }\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\n const hardwareInstancedRendering = engine.getCaps().instancedArrays && (batch.visibleInstances[subMesh._id] !== null || renderingMesh.hasThinInstances);\n if (!this.isReady(subMesh, hardwareInstancedRendering)) {\n return false;\n }\n }\n }\n return true;\n };\n this._multiRenderTarget.customRenderFunction = (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) => {\n let index;\n if (this._linkedWithPrePass) {\n if (!this._prePassRenderer.enabled) {\n return;\n }\n this._scene.getEngine().bindAttachments(this._attachmentsFromPrePass);\n }\n if (depthOnlySubMeshes.length) {\n engine.setColorWrite(false);\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\n renderSubMesh(depthOnlySubMeshes.data[index]);\n }\n engine.setColorWrite(true);\n }\n for (index = 0; index < opaqueSubMeshes.length; index++) {\n renderSubMesh(opaqueSubMeshes.data[index]);\n }\n engine.setDepthWrite(false);\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\n renderSubMesh(alphaTestSubMeshes.data[index]);\n }\n if (this.renderTransparentMeshes) {\n for (index = 0; index < transparentSubMeshes.length; index++) {\n renderSubMesh(transparentSubMeshes.data[index]);\n }\n }\n engine.setDepthWrite(true);\n };\n }\n // Copies the bones transformation matrices into the target array and returns the target's reference\n _copyBonesTransformationMatrices(source, target) {\n for (let i = 0; i < source.length; i++) {\n target[i] = source[i];\n }\n return target;\n }\n }\n /**\n * Constant used to retrieve the depth texture index in the G-Buffer textures array\n * using getIndex(GeometryBufferRenderer.DEPTH_TEXTURE_INDEX)\n */\n GeometryBufferRenderer.DEPTH_TEXTURE_TYPE = 0;\n /**\n * Constant used to retrieve the normal texture index in the G-Buffer textures array\n * using getIndex(GeometryBufferRenderer.NORMAL_TEXTURE_INDEX)\n */\n GeometryBufferRenderer.NORMAL_TEXTURE_TYPE = 1;\n /**\n * Constant used to retrieve the position texture index in the G-Buffer textures array\n * using getIndex(GeometryBufferRenderer.POSITION_TEXTURE_INDEX)\n */\n GeometryBufferRenderer.POSITION_TEXTURE_TYPE = 2;\n /**\n * Constant used to retrieve the velocity texture index in the G-Buffer textures array\n * using getIndex(GeometryBufferRenderer.VELOCITY_TEXTURE_INDEX)\n */\n GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE = 3;\n /**\n * Constant used to retrieve the reflectivity texture index in the G-Buffer textures array\n * using the getIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE)\n */\n GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE = 4;\n /**\n * @internal\n */\n GeometryBufferRenderer._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"GeometryBufferRendererSceneComponent\");\n };\n\n Object.defineProperty(Scene.prototype, \"geometryBufferRenderer\", {\n get: function () {\n return this._geometryBufferRenderer;\n },\n set: function (value) {\n if (value && value.isSupported) {\n this._geometryBufferRenderer = value;\n }\n },\n enumerable: true,\n configurable: true,\n });\n Scene.prototype.enableGeometryBufferRenderer = function (ratio = 1, depthFormat = 15) {\n if (this._geometryBufferRenderer) {\n return this._geometryBufferRenderer;\n }\n this._geometryBufferRenderer = new GeometryBufferRenderer(this, ratio, depthFormat);\n if (!this._geometryBufferRenderer.isSupported) {\n this._geometryBufferRenderer = null;\n }\n return this._geometryBufferRenderer;\n };\n Scene.prototype.disableGeometryBufferRenderer = function () {\n if (!this._geometryBufferRenderer) {\n return;\n }\n this._geometryBufferRenderer.dispose();\n this._geometryBufferRenderer = null;\n };\n /**\n * Defines the Geometry Buffer scene component responsible to manage a G-Buffer useful\n * in several rendering techniques.\n */\n class GeometryBufferRendererSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER;\n this.scene = scene;\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER, this, this._gatherRenderTargets);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do for this component\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n // Nothing to do for this component\n }\n _gatherRenderTargets(renderTargets) {\n if (this.scene._geometryBufferRenderer) {\n renderTargets.push(this.scene._geometryBufferRenderer.getGBuffer());\n }\n }\n }\n GeometryBufferRenderer._SceneComponentInitialization = (scene) => {\n // Register the G Buffer component to the scene.\n let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER);\n if (!component) {\n component = new GeometryBufferRendererSceneComponent(scene);\n scene._addComponent(component);\n }\n };\n\n // Do not edit.\n const name$2o = \"outlinePixelShader\";\n const shader$2o = `#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;uniform sampler2D diffuseSampler;\n#endif\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2o] = shader$2o;\n\n // Do not edit.\n const name$2p = \"outlineVertexShader\";\n const shader$2p = `attribute vec3 position;attribute vec3 normal;\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\nuniform float offset;\n#include\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;uniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;vec3 normalUpdated=normal;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\nvec3 offsetPosition=positionUpdated+(normalUpdated*offset);\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(offsetPosition,1.0);gl_Position=viewProjection*worldPos;\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include\n#include\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2p] = shader$2p;\n\n /**\n * Gets the outline renderer associated with the scene\n * @returns a OutlineRenderer\n */\n Scene.prototype.getOutlineRenderer = function () {\n if (!this._outlineRenderer) {\n this._outlineRenderer = new OutlineRenderer(this);\n }\n return this._outlineRenderer;\n };\n Object.defineProperty(Mesh.prototype, \"renderOutline\", {\n get: function () {\n return this._renderOutline;\n },\n set: function (value) {\n if (value) {\n // Lazy Load the component.\n this.getScene().getOutlineRenderer();\n }\n this._renderOutline = value;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(Mesh.prototype, \"renderOverlay\", {\n get: function () {\n return this._renderOverlay;\n },\n set: function (value) {\n if (value) {\n // Lazy Load the component.\n this.getScene().getOutlineRenderer();\n }\n this._renderOverlay = value;\n },\n enumerable: true,\n configurable: true,\n });\n /**\n * This class is responsible to draw the outline/overlay of meshes.\n * It should not be used directly but through the available method on mesh.\n */\n class OutlineRenderer {\n /**\n * Instantiates a new outline renderer. (There could be only one per scene).\n * @param scene Defines the scene it belongs to\n */\n constructor(scene) {\n /**\n * The name of the component. Each component must have a unique name.\n */\n this.name = SceneComponentConstants.NAME_OUTLINERENDERER;\n /**\n * Defines a zOffset default Factor to prevent zFighting between the overlay and the mesh.\n */\n this.zOffset = 1;\n /**\n * Defines a zOffset default Unit to prevent zFighting between the overlay and the mesh.\n */\n this.zOffsetUnits = 4; // 4 to account for projection a bit by default\n this.scene = scene;\n this._engine = scene.getEngine();\n this.scene._addComponent(this);\n this._passIdForDrawWrapper = [];\n for (let i = 0; i < 4; ++i) {\n this._passIdForDrawWrapper[i] = this._engine.createRenderPassId(`Outline Renderer (${i})`);\n }\n }\n /**\n * Register the component to one instance of a scene.\n */\n register() {\n this.scene._beforeRenderingMeshStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERINGMESH_OUTLINE, this, this._beforeRenderingMesh);\n this.scene._afterRenderingMeshStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGMESH_OUTLINE, this, this._afterRenderingMesh);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Nothing to do here.\n }\n /**\n * Disposes the component and the associated resources.\n */\n dispose() {\n for (let i = 0; i < this._passIdForDrawWrapper.length; ++i) {\n this._engine.releaseRenderPassId(this._passIdForDrawWrapper[i]);\n }\n }\n /**\n * Renders the outline in the canvas.\n * @param subMesh Defines the sumesh to render\n * @param batch Defines the batch of meshes in case of instances\n * @param useOverlay Defines if the rendering is for the overlay or the outline\n * @param renderPassId Render pass id to use to render the mesh\n */\n render(subMesh, batch, useOverlay = false, renderPassId) {\n renderPassId = renderPassId !== null && renderPassId !== void 0 ? renderPassId : this._passIdForDrawWrapper[0];\n const scene = this.scene;\n const engine = scene.getEngine();\n const hardwareInstancedRendering = engine.getCaps().instancedArrays &&\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || subMesh.getRenderingMesh().hasThinInstances);\n if (!this.isReady(subMesh, hardwareInstancedRendering, renderPassId)) {\n return;\n }\n const ownerMesh = subMesh.getMesh();\n const replacementMesh = ownerMesh._internalAbstractMeshDataInfo._actAsRegularMesh ? ownerMesh : null;\n const renderingMesh = subMesh.getRenderingMesh();\n const effectiveMesh = replacementMesh ? replacementMesh : renderingMesh;\n const material = subMesh.getMaterial();\n if (!material || !scene.activeCamera) {\n return;\n }\n const drawWrapper = subMesh._getDrawWrapper(renderPassId);\n const effect = DrawWrapper.GetEffect(drawWrapper);\n engine.enableEffect(drawWrapper);\n // Logarithmic depth\n if (material.useLogarithmicDepth) {\n effect.setFloat(\"logarithmicDepthConstant\", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));\n }\n effect.setFloat(\"offset\", useOverlay ? 0 : renderingMesh.outlineWidth);\n effect.setColor4(\"color\", useOverlay ? renderingMesh.overlayColor : renderingMesh.outlineColor, useOverlay ? renderingMesh.overlayAlpha : material.alpha);\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\n effect.setMatrix(\"world\", effectiveMesh.getWorldMatrix());\n // Bones\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\n effect.setMatrices(\"mBones\", renderingMesh.skeleton.getTransformMatrices(renderingMesh));\n }\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\n renderingMesh.morphTargetManager._bind(effect);\n }\n // Morph targets\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\n if (!hardwareInstancedRendering) {\n renderingMesh._bind(subMesh, effect, material.fillMode);\n }\n // Alpha test\n if (material && material.needAlphaTesting()) {\n const alphaTexture = material.getAlphaTestTexture();\n if (alphaTexture) {\n effect.setTexture(\"diffuseSampler\", alphaTexture);\n effect.setMatrix(\"diffuseMatrix\", alphaTexture.getTextureMatrix());\n }\n }\n // Clip plane\n bindClipPlane(effect, material, scene);\n engine.setZOffset(-this.zOffset);\n engine.setZOffsetUnits(-this.zOffsetUnits);\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) => {\n effect.setMatrix(\"world\", world);\n });\n engine.setZOffset(0);\n engine.setZOffsetUnits(0);\n }\n /**\n * Returns whether or not the outline renderer is ready for a given submesh.\n * All the dependencies e.g. submeshes, texture, effect... mus be ready\n * @param subMesh Defines the submesh to check readiness for\n * @param useInstances Defines whether wee are trying to render instances or not\n * @param renderPassId Render pass id to use to render the mesh\n * @returns true if ready otherwise false\n */\n isReady(subMesh, useInstances, renderPassId) {\n renderPassId = renderPassId !== null && renderPassId !== void 0 ? renderPassId : this._passIdForDrawWrapper[0];\n const defines = [];\n const attribs = [VertexBuffer.PositionKind, VertexBuffer.NormalKind];\n const mesh = subMesh.getMesh();\n const material = subMesh.getMaterial();\n if (!material) {\n return false;\n }\n const scene = mesh.getScene();\n // Alpha test\n if (material.needAlphaTesting()) {\n defines.push(\"#define ALPHATEST\");\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n attribs.push(VertexBuffer.UVKind);\n defines.push(\"#define UV1\");\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\n attribs.push(VertexBuffer.UV2Kind);\n defines.push(\"#define UV2\");\n }\n }\n //Logarithmic depth\n if (material.useLogarithmicDepth) {\n defines.push(\"#define LOGARITHMICDEPTH\");\n }\n // Clip planes\n prepareStringDefinesForClipPlanes(material, scene, defines);\n // Bones\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\n attribs.push(VertexBuffer.MatricesIndicesKind);\n attribs.push(VertexBuffer.MatricesWeightsKind);\n if (mesh.numBoneInfluencers > 4) {\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\n }\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\n defines.push(\"#define BonesPerMesh \" + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));\n }\n else {\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\n }\n // Morph targets\n const morphTargetManager = mesh.morphTargetManager;\n let numMorphInfluencers = 0;\n if (morphTargetManager) {\n if (morphTargetManager.numInfluencers > 0) {\n numMorphInfluencers = morphTargetManager.numInfluencers;\n defines.push(\"#define MORPHTARGETS\");\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numMorphInfluencers);\n if (morphTargetManager.isUsingTextureForTargets) {\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\n }\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, numMorphInfluencers);\n }\n }\n // Instances\n if (useInstances) {\n defines.push(\"#define INSTANCES\");\n MaterialHelper.PushAttributesForInstances(attribs);\n if (subMesh.getRenderingMesh().hasThinInstances) {\n defines.push(\"#define THIN_INSTANCES\");\n }\n }\n // Get correct effect\n const drawWrapper = subMesh._getDrawWrapper(renderPassId, true);\n const cachedDefines = drawWrapper.defines;\n const join = defines.join(\"\\n\");\n if (cachedDefines !== join) {\n const uniforms = [\n \"world\",\n \"mBones\",\n \"viewProjection\",\n \"diffuseMatrix\",\n \"offset\",\n \"color\",\n \"logarithmicDepthConstant\",\n \"morphTargetInfluences\",\n \"morphTargetTextureInfo\",\n \"morphTargetTextureIndices\",\n ];\n addClipPlaneUniforms(uniforms);\n drawWrapper.setEffect(this.scene.getEngine().createEffect(\"outline\", attribs, uniforms, [\"diffuseSampler\", \"morphTargets\"], join, undefined, undefined, undefined, {\n maxSimultaneousMorphTargets: numMorphInfluencers,\n }), join);\n }\n return drawWrapper.effect.isReady();\n }\n _beforeRenderingMesh(mesh, subMesh, batch) {\n // Outline - step 1\n this._savedDepthWrite = this._engine.getDepthWrite();\n if (mesh.renderOutline) {\n const material = subMesh.getMaterial();\n if (material && material.needAlphaBlendingForMesh(mesh)) {\n this._engine.cacheStencilState();\n // Draw only to stencil buffer for the original mesh\n // The resulting stencil buffer will be used so the outline is not visible inside the mesh when the mesh is transparent\n this._engine.setDepthWrite(false);\n this._engine.setColorWrite(false);\n this._engine.setStencilBuffer(true);\n this._engine.setStencilOperationPass(7681);\n this._engine.setStencilFunction(519);\n this._engine.setStencilMask(OutlineRenderer._StencilReference);\n this._engine.setStencilFunctionReference(OutlineRenderer._StencilReference);\n this._engine.stencilStateComposer.useStencilGlobalOnly = true;\n this.render(subMesh, batch, /* This sets offset to 0 */ true, this._passIdForDrawWrapper[1]);\n this._engine.setColorWrite(true);\n this._engine.setStencilFunction(517);\n }\n // Draw the outline using the above stencil if needed to avoid drawing within the mesh\n this._engine.setDepthWrite(false);\n this.render(subMesh, batch, false, this._passIdForDrawWrapper[0]);\n this._engine.setDepthWrite(this._savedDepthWrite);\n if (material && material.needAlphaBlendingForMesh(mesh)) {\n this._engine.stencilStateComposer.useStencilGlobalOnly = false;\n this._engine.restoreStencilState();\n }\n }\n }\n _afterRenderingMesh(mesh, subMesh, batch) {\n // Overlay\n if (mesh.renderOverlay) {\n const currentMode = this._engine.getAlphaMode();\n const alphaBlendState = this._engine.alphaState.alphaBlend;\n this._engine.setAlphaMode(2);\n this.render(subMesh, batch, true, this._passIdForDrawWrapper[3]);\n this._engine.setAlphaMode(currentMode);\n this._engine.setDepthWrite(this._savedDepthWrite);\n this._engine.alphaState.alphaBlend = alphaBlendState;\n }\n // Outline - step 2\n if (mesh.renderOutline && this._savedDepthWrite) {\n this._engine.setDepthWrite(true);\n this._engine.setColorWrite(false);\n this.render(subMesh, batch, false, this._passIdForDrawWrapper[2]);\n this._engine.setColorWrite(true);\n }\n }\n }\n /**\n * Stencil value used to avoid outline being seen within the mesh when the mesh is transparent\n */\n OutlineRenderer._StencilReference = 0x04;\n\n /**\n * A multi render target designed to render the prepass.\n * Prepass is a scene component used to render information in multiple textures\n * alongside with the scene materials rendering.\n * Note : This is an internal class, and you should NOT need to instanciate this.\n * Only the `PrePassRenderer` should instanciate this class.\n * It is more likely that you need a regular `MultiRenderTarget`\n * @internal\n */\n class PrePassRenderTarget extends MultiRenderTarget {\n constructor(name, renderTargetTexture, size, count, scene, options) {\n super(name, size, count, scene, options);\n /**\n * @internal\n */\n this._beforeCompositionPostProcesses = [];\n /**\n * @internal\n */\n this._internalTextureDirty = false;\n /**\n * Is this render target enabled for prepass rendering\n */\n this.enabled = false;\n /**\n * Render target associated with this prePassRenderTarget\n * If this is `null`, it means this prePassRenderTarget is associated with the scene\n */\n this.renderTargetTexture = null;\n this.renderTargetTexture = renderTargetTexture;\n }\n /**\n * Creates a composition effect for this RT\n * @internal\n */\n _createCompositionEffect() {\n this.imageProcessingPostProcess = new ImageProcessingPostProcess(\"prePassComposition\", 1, null, undefined, this._engine);\n this.imageProcessingPostProcess._updateParameters();\n }\n /**\n * Checks that the size of this RT is still adapted to the desired render size.\n * @internal\n */\n _checkSize() {\n const requiredWidth = this._engine.getRenderWidth(true);\n const requiredHeight = this._engine.getRenderHeight(true);\n const width = this.getRenderWidth();\n const height = this.getRenderHeight();\n if (width !== requiredWidth || height !== requiredHeight) {\n this.resize({ width: requiredWidth, height: requiredHeight });\n this._internalTextureDirty = true;\n }\n }\n /**\n * Changes the number of render targets in this MRT\n * Be careful as it will recreate all the data in the new texture.\n * @param count new texture count\n * @param options Specifies texture types and sampling modes for new textures\n * @param textureNames Specifies the names of the textures (optional)\n */\n updateCount(count, options, textureNames) {\n super.updateCount(count, options, textureNames);\n this._internalTextureDirty = true;\n }\n /**\n * Resets the post processes chains applied to this RT.\n * @internal\n */\n _resetPostProcessChain() {\n this._beforeCompositionPostProcesses.length = 0;\n }\n /**\n * Diposes this render target\n */\n dispose() {\n const scene = this._scene;\n super.dispose();\n if (scene && scene.prePassRenderer) {\n const index = scene.prePassRenderer.renderTargets.indexOf(this);\n if (index !== -1) {\n scene.prePassRenderer.renderTargets.splice(index, 1);\n }\n }\n if (this.imageProcessingPostProcess) {\n this.imageProcessingPostProcess.dispose();\n }\n if (this.renderTargetTexture) {\n this.renderTargetTexture._prePassRenderTarget = null;\n }\n if (this._outputPostProcess) {\n this._outputPostProcess.autoClear = true;\n this._outputPostProcess.restoreDefaultInputTexture();\n }\n }\n }\n\n /**\n * Renders a pre pass of the scene\n * This means every mesh in the scene will be rendered to a render target texture\n * And then this texture will be composited to the rendering canvas with post processes\n * It is necessary for effects like subsurface scattering or deferred shading\n */\n class PrePassRenderer {\n /**\n * Returns the index of a texture in the multi render target texture array.\n * @param type Texture type\n * @returns The index\n */\n getIndex(type) {\n return this._textureIndices[type];\n }\n /**\n * How many samples are used for MSAA of the scene render target\n */\n get samples() {\n return this.defaultRT.samples;\n }\n set samples(n) {\n this.defaultRT.samples = n;\n }\n /**\n * If set to true (default: false), the depth texture will be cleared with the depth value corresponding to the far plane (1 in normal mode, 0 in reverse depth buffer mode)\n * If set to false, the depth texture is always cleared with 0.\n */\n get useSpecificClearForDepthTexture() {\n return this._useSpecificClearForDepthTexture;\n }\n set useSpecificClearForDepthTexture(value) {\n if (this._useSpecificClearForDepthTexture === value) {\n return;\n }\n this._useSpecificClearForDepthTexture = value;\n this._isDirty = true;\n }\n /**\n * @returns the prepass render target for the rendering pass.\n * If we are currently rendering a render target, it returns the PrePassRenderTarget\n * associated with that render target. Otherwise, it returns the scene default PrePassRenderTarget\n */\n getRenderTarget() {\n return this._currentTarget;\n }\n /**\n * @internal\n * Managed by the scene component\n * @param prePassRenderTarget\n */\n _setRenderTarget(prePassRenderTarget) {\n var _a, _b;\n if (prePassRenderTarget) {\n this._currentTarget = prePassRenderTarget;\n }\n else {\n this._currentTarget = this.defaultRT;\n this._engine.currentRenderPassId = (_b = (_a = this._scene.activeCamera) === null || _a === void 0 ? void 0 : _a.renderPassId) !== null && _b !== void 0 ? _b : this._currentTarget.renderPassId;\n }\n }\n /**\n * Returns true if the currently rendered prePassRenderTarget is the one\n * associated with the scene.\n */\n get currentRTisSceneRT() {\n return this._currentTarget === this.defaultRT;\n }\n _refreshGeometryBufferRendererLink() {\n if (!this.doNotUseGeometryRendererFallback) {\n this._geometryBuffer = this._scene.enableGeometryBufferRenderer();\n if (!this._geometryBuffer) {\n // Not supported\n this.doNotUseGeometryRendererFallback = true;\n return;\n }\n this._geometryBuffer._linkPrePassRenderer(this);\n }\n else {\n if (this._geometryBuffer) {\n this._geometryBuffer._unlinkPrePassRenderer();\n }\n this._geometryBuffer = null;\n this._scene.disableGeometryBufferRenderer();\n }\n }\n /**\n * Indicates if the prepass is enabled\n */\n get enabled() {\n return this._enabled;\n }\n /**\n * Instantiates a prepass renderer\n * @param scene The scene\n */\n constructor(scene) {\n /**\n * To save performance, we can excluded skinned meshes from the prepass\n */\n this.excludedSkinnedMesh = [];\n /**\n * Force material to be excluded from the prepass\n * Can be useful when `useGeometryBufferFallback` is set to `true`\n * and you don't want a material to show in the effect.\n */\n this.excludedMaterials = [];\n /**\n * Number of textures in the multi render target texture where the scene is directly rendered\n */\n this.mrtCount = 0;\n this._mrtTypes = [];\n this._mrtFormats = [];\n this._mrtLayout = [];\n this._mrtNames = [];\n this._textureIndices = [];\n this._useSpecificClearForDepthTexture = false;\n this._isDirty = true;\n /**\n * Configuration for prepass effects\n */\n this._effectConfigurations = [];\n /**\n * Prevents the PrePassRenderer from using the GeometryBufferRenderer as a fallback\n */\n this.doNotUseGeometryRendererFallback = true;\n /**\n * All the render targets generated by prepass\n */\n this.renderTargets = [];\n this._clearColor = new Color4(0, 0, 0, 0);\n this._clearDepthColor = new Color4(1e8, 0, 0, 1); // \"infinity\" value - depth in the depth texture is view.z, not a 0..1 value!\n this._enabled = false;\n this._needsCompositionForThisPass = false;\n /**\n * Set to true to disable gamma transform in PrePass.\n * Can be useful in case you already proceed to gamma transform on a material level\n * and your post processes don't need to be in linear color space.\n */\n this.disableGammaTransform = false;\n this._scene = scene;\n this._engine = scene.getEngine();\n let type = 0;\n if (this._engine._caps.textureFloat && this._engine._caps.textureFloatLinearFiltering) {\n type = 1;\n }\n else if (this._engine._caps.textureHalfFloat && this._engine._caps.textureHalfFloatLinearFiltering) {\n type = 2;\n }\n if (type !== 1) {\n for (let i = 0; i < PrePassRenderer.TextureFormats.length; ++i) {\n if (PrePassRenderer.TextureFormats[i].type === 1) {\n PrePassRenderer.TextureFormats[5].type = type;\n }\n }\n }\n PrePassRenderer._SceneComponentInitialization(this._scene);\n this.defaultRT = this._createRenderTarget(\"sceneprePassRT\", null);\n this._currentTarget = this.defaultRT;\n }\n /**\n * Creates a new PrePassRenderTarget\n * This should be the only way to instantiate a `PrePassRenderTarget`\n * @param name Name of the `PrePassRenderTarget`\n * @param renderTargetTexture RenderTarget the `PrePassRenderTarget` will be attached to.\n * Can be `null` if the created `PrePassRenderTarget` is attached to the scene (default framebuffer).\n * @internal\n */\n _createRenderTarget(name, renderTargetTexture) {\n const rt = new PrePassRenderTarget(name, renderTargetTexture, { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, 0, this._scene, {\n generateMipMaps: false,\n generateStencilBuffer: this._engine.isStencilEnable,\n defaultType: 0,\n types: [],\n drawOnlyOnFirstAttachmentByDefault: true,\n });\n this.renderTargets.push(rt);\n if (this._enabled) {\n // The pre-pass renderer is already enabled, so make sure we create the render target with the correct number of textures\n this._update();\n }\n return rt;\n }\n /**\n * Indicates if rendering a prepass is supported\n */\n get isSupported() {\n return this._scene.getEngine().getCaps().drawBuffersExtension;\n }\n /**\n * Sets the proper output textures to draw in the engine.\n * @param effect The effect that is drawn. It can be or not be compatible with drawing to several output textures.\n * @param subMesh Submesh on which the effect is applied\n */\n bindAttachmentsForEffect(effect, subMesh) {\n const material = subMesh.getMaterial();\n const isPrePassCapable = material && material.isPrePassCapable;\n const excluded = material && this.excludedMaterials.indexOf(material) !== -1;\n if (this.enabled && this._currentTarget.enabled) {\n if (effect._multiTarget && isPrePassCapable && !excluded) {\n this._engine.bindAttachments(this._multiRenderAttachments);\n }\n else {\n if (this._engine._currentRenderTarget) {\n this._engine.bindAttachments(this._defaultAttachments);\n }\n else {\n this._engine.restoreSingleAttachment();\n }\n if (this._geometryBuffer && this.currentRTisSceneRT && !excluded) {\n this._geometryBuffer.renderList.push(subMesh.getRenderingMesh());\n }\n }\n }\n }\n _reinitializeAttachments() {\n const multiRenderLayout = [];\n const clearLayout = [false];\n const clearDepthLayout = [false];\n const defaultLayout = [true];\n for (let i = 0; i < this.mrtCount; i++) {\n multiRenderLayout.push(true);\n if (i > 0) {\n if (this._useSpecificClearForDepthTexture && this._mrtLayout[i] === 5) {\n clearLayout.push(false);\n clearDepthLayout.push(true);\n }\n else {\n clearLayout.push(true);\n clearDepthLayout.push(false);\n }\n defaultLayout.push(false);\n }\n }\n this._multiRenderAttachments = this._engine.buildTextureLayout(multiRenderLayout);\n this._clearAttachments = this._engine.buildTextureLayout(clearLayout);\n this._clearDepthAttachments = this._engine.buildTextureLayout(clearDepthLayout);\n this._defaultAttachments = this._engine.buildTextureLayout(defaultLayout);\n }\n _resetLayout() {\n for (let i = 0; i < PrePassRenderer.TextureFormats.length; i++) {\n this._textureIndices[PrePassRenderer.TextureFormats[i].purpose] = -1;\n }\n this._textureIndices[4] = 0;\n this._mrtLayout = [4];\n this._mrtTypes = [PrePassRenderer.TextureFormats[4].type];\n this._mrtFormats = [PrePassRenderer.TextureFormats[4].format];\n this._mrtNames = [PrePassRenderer.TextureFormats[4].name];\n this.mrtCount = 1;\n }\n _updateGeometryBufferLayout() {\n this._refreshGeometryBufferRendererLink();\n if (this._geometryBuffer) {\n this._geometryBuffer._resetLayout();\n const texturesActivated = [];\n for (let i = 0; i < this._mrtLayout.length; i++) {\n texturesActivated.push(false);\n }\n this._geometryBuffer._linkInternalTexture(this.defaultRT.getInternalTexture());\n const matches = [\n {\n prePassConstant: 5,\n geometryBufferConstant: GeometryBufferRenderer.DEPTH_TEXTURE_TYPE,\n },\n {\n prePassConstant: 6,\n geometryBufferConstant: GeometryBufferRenderer.NORMAL_TEXTURE_TYPE,\n },\n {\n prePassConstant: 1,\n geometryBufferConstant: GeometryBufferRenderer.POSITION_TEXTURE_TYPE,\n },\n {\n prePassConstant: 3,\n geometryBufferConstant: GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE,\n },\n {\n prePassConstant: 2,\n geometryBufferConstant: GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE,\n },\n ];\n // replace textures in the geometryBuffer RT\n for (let i = 0; i < matches.length; i++) {\n const index = this._mrtLayout.indexOf(matches[i].prePassConstant);\n if (index !== -1) {\n this._geometryBuffer._forceTextureType(matches[i].geometryBufferConstant, index);\n texturesActivated[index] = true;\n }\n }\n this._geometryBuffer._setAttachments(this._engine.buildTextureLayout(texturesActivated));\n }\n }\n /**\n * Restores attachments for single texture draw.\n */\n restoreAttachments() {\n if (this.enabled && this._currentTarget.enabled && this._defaultAttachments) {\n if (this._engine._currentRenderTarget) {\n this._engine.bindAttachments(this._defaultAttachments);\n }\n else {\n this._engine.restoreSingleAttachment();\n }\n }\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _beforeDraw(camera, faceIndex, layer) {\n // const previousEnabled = this._enabled && this._currentTarget.enabled;\n if (this._isDirty) {\n this._update();\n }\n if (!this._enabled || !this._currentTarget.enabled) {\n return;\n }\n if (this._geometryBuffer) {\n this._geometryBuffer.renderList = [];\n }\n this._setupOutputForThisPass(this._currentTarget, camera);\n }\n _prepareFrame(prePassRenderTarget, faceIndex, layer) {\n if (prePassRenderTarget.renderTargetTexture) {\n prePassRenderTarget.renderTargetTexture._prepareFrame(this._scene, faceIndex, layer, prePassRenderTarget.renderTargetTexture.useCameraPostProcesses);\n }\n else if (this._postProcessesSourceForThisPass.length) {\n this._scene.postProcessManager._prepareFrame();\n }\n else {\n this._engine.restoreDefaultFramebuffer();\n }\n }\n /**\n * Sets an intermediary texture between prepass and postprocesses. This texture\n * will be used as input for post processes\n * @param rt\n * @returns true if there are postprocesses that will use this texture,\n * false if there is no postprocesses - and the function has no effect\n */\n setCustomOutput(rt) {\n const firstPP = this._postProcessesSourceForThisPass[0];\n if (!firstPP) {\n return false;\n }\n firstPP.inputTexture = rt.renderTarget;\n return true;\n }\n _renderPostProcesses(prePassRenderTarget, faceIndex) {\n var _a;\n const firstPP = this._postProcessesSourceForThisPass[0];\n const outputTexture = firstPP ? firstPP.inputTexture : prePassRenderTarget.renderTargetTexture ? prePassRenderTarget.renderTargetTexture.renderTarget : null;\n // Build post process chain for this prepass post draw\n let postProcessChain = this._currentTarget._beforeCompositionPostProcesses;\n if (this._needsCompositionForThisPass) {\n postProcessChain = postProcessChain.concat([this._currentTarget.imageProcessingPostProcess]);\n }\n // Activates and renders the chain\n if (postProcessChain.length) {\n this._scene.postProcessManager._prepareFrame((_a = this._currentTarget.renderTarget) === null || _a === void 0 ? void 0 : _a.texture, postProcessChain);\n this._scene.postProcessManager.directRender(postProcessChain, outputTexture, false, faceIndex);\n }\n }\n /**\n * @internal\n */\n _afterDraw(faceIndex, layer) {\n if (this._enabled && this._currentTarget.enabled) {\n this._prepareFrame(this._currentTarget, faceIndex, layer);\n this._renderPostProcesses(this._currentTarget, faceIndex);\n }\n }\n /**\n * Clears the current prepass render target (in the sense of settings pixels to the scene clear color value)\n * @internal\n */\n _clear() {\n if (this._enabled && this._currentTarget.enabled) {\n this._bindFrameBuffer(this._currentTarget);\n // Clearing other attachment with 0 on all other attachments\n this._engine.bindAttachments(this._clearAttachments);\n this._engine.clear(this._clearColor, true, false, false);\n if (this._useSpecificClearForDepthTexture) {\n this._engine.bindAttachments(this._clearDepthAttachments);\n this._engine.clear(this._clearDepthColor, true, false, false);\n }\n // Regular clear color with the scene clear color of the 1st attachment\n this._engine.bindAttachments(this._defaultAttachments);\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _bindFrameBuffer(prePassRenderTarget) {\n if (this._enabled && this._currentTarget.enabled) {\n this._currentTarget._checkSize();\n const internalTexture = this._currentTarget.renderTarget;\n if (internalTexture) {\n this._engine.bindFramebuffer(internalTexture);\n }\n }\n }\n _setEnabled(enabled) {\n this._enabled = enabled;\n }\n _setRenderTargetEnabled(prePassRenderTarget, enabled) {\n prePassRenderTarget.enabled = enabled;\n if (!enabled) {\n this._unlinkInternalTexture(prePassRenderTarget);\n }\n }\n /**\n * Adds an effect configuration to the prepass render target.\n * If an effect has already been added, it won't add it twice and will return the configuration\n * already present.\n * @param cfg the effect configuration\n * @returns the effect configuration now used by the prepass\n */\n addEffectConfiguration(cfg) {\n // Do not add twice\n for (let i = 0; i < this._effectConfigurations.length; i++) {\n if (this._effectConfigurations[i].name === cfg.name) {\n return this._effectConfigurations[i];\n }\n }\n this._effectConfigurations.push(cfg);\n return cfg;\n }\n _enable() {\n const previousMrtCount = this.mrtCount;\n for (let i = 0; i < this._effectConfigurations.length; i++) {\n if (this._effectConfigurations[i].enabled) {\n this._enableTextures(this._effectConfigurations[i].texturesRequired);\n }\n }\n for (let i = 0; i < this.renderTargets.length; i++) {\n if (this.mrtCount !== previousMrtCount || this.renderTargets[i].count !== this.mrtCount) {\n this.renderTargets[i].updateCount(this.mrtCount, { types: this._mrtTypes, formats: this._mrtFormats }, this._mrtNames.concat(\"prePass_DepthBuffer\"));\n }\n this.renderTargets[i]._resetPostProcessChain();\n for (let j = 0; j < this._effectConfigurations.length; j++) {\n if (this._effectConfigurations[j].enabled) {\n // TODO : subsurface scattering has 1 scene-wide effect configuration\n // solution : do not stock postProcess on effectConfiguration, but in the prepassRenderTarget (hashmap configuration => postProcess)\n // And call createPostProcess whenever the post process does not exist in the RT\n if (!this._effectConfigurations[j].postProcess && this._effectConfigurations[j].createPostProcess) {\n this._effectConfigurations[j].createPostProcess();\n }\n if (this._effectConfigurations[j].postProcess) {\n this.renderTargets[i]._beforeCompositionPostProcesses.push(this._effectConfigurations[j].postProcess);\n }\n }\n }\n }\n this._reinitializeAttachments();\n this._setEnabled(true);\n this._updateGeometryBufferLayout();\n }\n _disable() {\n this._setEnabled(false);\n for (let i = 0; i < this.renderTargets.length; i++) {\n this._setRenderTargetEnabled(this.renderTargets[i], false);\n }\n this._resetLayout();\n for (let i = 0; i < this._effectConfigurations.length; i++) {\n this._effectConfigurations[i].enabled = false;\n }\n }\n _getPostProcessesSource(prePassRenderTarget, camera) {\n if (camera) {\n return camera._postProcesses;\n }\n else if (prePassRenderTarget.renderTargetTexture) {\n if (prePassRenderTarget.renderTargetTexture.useCameraPostProcesses) {\n const camera = prePassRenderTarget.renderTargetTexture.activeCamera ? prePassRenderTarget.renderTargetTexture.activeCamera : this._scene.activeCamera;\n return camera ? camera._postProcesses : [];\n }\n else if (prePassRenderTarget.renderTargetTexture.postProcesses) {\n return prePassRenderTarget.renderTargetTexture.postProcesses;\n }\n else {\n return [];\n }\n }\n else {\n return this._scene.activeCamera ? this._scene.activeCamera._postProcesses : [];\n }\n }\n _setupOutputForThisPass(prePassRenderTarget, camera) {\n // Order is : draw ===> prePassRenderTarget._postProcesses ==> ipp ==> camera._postProcesses\n const secondaryCamera = camera && this._scene.activeCameras && !!this._scene.activeCameras.length && this._scene.activeCameras.indexOf(camera) !== 0;\n this._postProcessesSourceForThisPass = this._getPostProcessesSource(prePassRenderTarget, camera);\n this._postProcessesSourceForThisPass = this._postProcessesSourceForThisPass.filter((pp) => {\n return pp != null;\n });\n this._scene.autoClear = true;\n const cameraHasImageProcessing = this._hasImageProcessing(this._postProcessesSourceForThisPass);\n this._needsCompositionForThisPass = !cameraHasImageProcessing && !this.disableGammaTransform && this._needsImageProcessing() && !secondaryCamera;\n const firstCameraPP = this._getFirstPostProcess(this._postProcessesSourceForThisPass);\n const firstPrePassPP = prePassRenderTarget._beforeCompositionPostProcesses && prePassRenderTarget._beforeCompositionPostProcesses[0];\n let firstPP = null;\n // Setting the scene-wide post process configuration\n this._scene.imageProcessingConfiguration.applyByPostProcess = this._needsCompositionForThisPass || cameraHasImageProcessing;\n // Create composition effect if needed\n if (this._needsCompositionForThisPass && !prePassRenderTarget.imageProcessingPostProcess) {\n prePassRenderTarget._createCompositionEffect();\n }\n // Setting the prePassRenderTarget as input texture of the first PP\n if (firstPrePassPP) {\n firstPP = firstPrePassPP;\n }\n else if (this._needsCompositionForThisPass) {\n firstPP = prePassRenderTarget.imageProcessingPostProcess;\n }\n else if (firstCameraPP) {\n firstPP = firstCameraPP;\n }\n this._bindFrameBuffer(prePassRenderTarget);\n this._linkInternalTexture(prePassRenderTarget, firstPP);\n }\n _linkInternalTexture(prePassRenderTarget, postProcess) {\n if (postProcess) {\n postProcess.autoClear = false;\n postProcess.inputTexture = prePassRenderTarget.renderTarget;\n }\n if (prePassRenderTarget._outputPostProcess !== postProcess) {\n if (prePassRenderTarget._outputPostProcess) {\n this._unlinkInternalTexture(prePassRenderTarget);\n }\n prePassRenderTarget._outputPostProcess = postProcess;\n }\n if (prePassRenderTarget._internalTextureDirty) {\n this._updateGeometryBufferLayout();\n prePassRenderTarget._internalTextureDirty = false;\n }\n }\n /**\n * @internal\n */\n _unlinkInternalTexture(prePassRenderTarget) {\n if (prePassRenderTarget._outputPostProcess) {\n prePassRenderTarget._outputPostProcess.autoClear = true;\n prePassRenderTarget._outputPostProcess.restoreDefaultInputTexture();\n prePassRenderTarget._outputPostProcess = null;\n }\n }\n _needsImageProcessing() {\n for (let i = 0; i < this._effectConfigurations.length; i++) {\n if (this._effectConfigurations[i].enabled && this._effectConfigurations[i].needsImageProcessing) {\n return true;\n }\n }\n return false;\n }\n _hasImageProcessing(postProcesses) {\n var _a;\n let isIPPAlreadyPresent = false;\n if (postProcesses) {\n for (let i = 0; i < postProcesses.length; i++) {\n if (((_a = postProcesses[i]) === null || _a === void 0 ? void 0 : _a.getClassName()) === \"ImageProcessingPostProcess\") {\n isIPPAlreadyPresent = true;\n break;\n }\n }\n }\n return isIPPAlreadyPresent;\n }\n /**\n * Internal, gets the first post proces.\n * @param postProcesses\n * @returns the first post process to be run on this camera.\n */\n _getFirstPostProcess(postProcesses) {\n for (let ppIndex = 0; ppIndex < postProcesses.length; ppIndex++) {\n if (postProcesses[ppIndex] !== null) {\n return postProcesses[ppIndex];\n }\n }\n return null;\n }\n /**\n * Marks the prepass renderer as dirty, triggering a check if the prepass is necessary for the next rendering.\n */\n markAsDirty() {\n this._isDirty = true;\n }\n /**\n * Enables a texture on the MultiRenderTarget for prepass\n * @param types\n */\n _enableTextures(types) {\n // For velocity : enable storage of previous matrices for instances\n this._scene.needsPreviousWorldMatrices = false;\n for (let i = 0; i < types.length; i++) {\n const type = types[i];\n if (this._textureIndices[type] === -1) {\n this._textureIndices[type] = this._mrtLayout.length;\n this._mrtLayout.push(type);\n this._mrtTypes.push(PrePassRenderer.TextureFormats[type].type);\n this._mrtFormats.push(PrePassRenderer.TextureFormats[type].format);\n this._mrtNames.push(PrePassRenderer.TextureFormats[type].name);\n this.mrtCount++;\n }\n if (type === 2) {\n this._scene.needsPreviousWorldMatrices = true;\n }\n }\n }\n /**\n * Makes sure that the prepass renderer is up to date if it has been dirtified.\n */\n update() {\n if (this._isDirty) {\n this._update();\n }\n }\n _update() {\n this._disable();\n let enablePrePass = false;\n this._scene.imageProcessingConfiguration.applyByPostProcess = false;\n if (this._scene._depthPeelingRenderer && this._scene.useOrderIndependentTransparency) {\n this._scene._depthPeelingRenderer.setPrePassRenderer(this);\n enablePrePass = true;\n }\n for (let i = 0; i < this._scene.materials.length; i++) {\n if (this._scene.materials[i].setPrePassRenderer(this)) {\n enablePrePass = true;\n }\n }\n if (enablePrePass) {\n this._setRenderTargetEnabled(this.defaultRT, true);\n }\n let postProcesses;\n for (let i = 0; i < this.renderTargets.length; i++) {\n if (this.renderTargets[i].renderTargetTexture) {\n postProcesses = this._getPostProcessesSource(this.renderTargets[i]);\n }\n else {\n const camera = this._scene.activeCamera;\n if (!camera) {\n continue;\n }\n postProcesses = camera._postProcesses;\n }\n if (!postProcesses) {\n continue;\n }\n postProcesses = postProcesses.filter((pp) => {\n return pp != null;\n });\n if (postProcesses) {\n for (let j = 0; j < postProcesses.length; j++) {\n if (postProcesses[j].setPrePassRenderer(this)) {\n this._setRenderTargetEnabled(this.renderTargets[i], true);\n enablePrePass = true;\n }\n }\n if (this._hasImageProcessing(postProcesses)) {\n this._scene.imageProcessingConfiguration.applyByPostProcess = true;\n }\n }\n }\n this._markAllMaterialsAsPrePassDirty();\n this._isDirty = false;\n if (enablePrePass) {\n this._enable();\n }\n }\n _markAllMaterialsAsPrePassDirty() {\n const materials = this._scene.materials;\n for (let i = 0; i < materials.length; i++) {\n materials[i].markAsDirty(Material.PrePassDirtyFlag);\n }\n }\n /**\n * Disposes the prepass renderer.\n */\n dispose() {\n for (let i = this.renderTargets.length - 1; i >= 0; i--) {\n this.renderTargets[i].dispose();\n }\n for (let i = 0; i < this._effectConfigurations.length; i++) {\n if (this._effectConfigurations[i].dispose) {\n this._effectConfigurations[i].dispose();\n }\n }\n }\n }\n /**\n * @internal\n */\n PrePassRenderer._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"PrePassRendererSceneComponent\");\n };\n /**\n * Describes the types and formats of the textures used by the pre-pass renderer\n */\n PrePassRenderer.TextureFormats = [\n {\n purpose: 0,\n type: 2,\n format: 5,\n name: \"prePass_Irradiance\",\n },\n {\n purpose: 1,\n type: 2,\n format: 5,\n name: \"prePass_Position\",\n },\n {\n purpose: 2,\n type: 0,\n format: 5,\n name: \"prePass_Velocity\",\n },\n {\n purpose: 3,\n type: 0,\n format: 5,\n name: \"prePass_Reflectivity\",\n },\n {\n purpose: 4,\n type: 2,\n format: 5,\n name: \"prePass_Color\",\n },\n {\n purpose: 5,\n type: 1,\n format: 6,\n name: \"prePass_Depth\",\n },\n {\n purpose: 6,\n type: 2,\n format: 5,\n name: \"prePass_Normal\",\n },\n {\n purpose: 7,\n type: 0,\n format: 5,\n name: \"prePass_Albedo\",\n },\n ];\n\n Object.defineProperty(Scene.prototype, \"prePassRenderer\", {\n get: function () {\n return this._prePassRenderer;\n },\n set: function (value) {\n if (value && value.isSupported) {\n this._prePassRenderer = value;\n }\n },\n enumerable: true,\n configurable: true,\n });\n Scene.prototype.enablePrePassRenderer = function () {\n if (this._prePassRenderer) {\n return this._prePassRenderer;\n }\n this._prePassRenderer = new PrePassRenderer(this);\n if (!this._prePassRenderer.isSupported) {\n this._prePassRenderer = null;\n Logger.Error(\"PrePassRenderer needs WebGL 2 support.\\n\" + \"Maybe you tried to use the following features that need the PrePassRenderer :\\n\" + \" + Subsurface Scattering\");\n }\n return this._prePassRenderer;\n };\n Scene.prototype.disablePrePassRenderer = function () {\n if (!this._prePassRenderer) {\n return;\n }\n this._prePassRenderer.dispose();\n this._prePassRenderer = null;\n };\n /**\n * Defines the Geometry Buffer scene component responsible to manage a G-Buffer useful\n * in several rendering techniques.\n */\n class PrePassRendererSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_PREPASSRENDERER;\n this.scene = scene;\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._beforeCameraDrawStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERADRAW_PREPASS, this, this._beforeCameraDraw);\n this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_PREPASS, this, this._afterCameraDraw);\n this.scene._beforeRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERTARGETDRAW_PREPASS, this, this._beforeRenderTargetDraw);\n this.scene._afterRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_PREPASS, this, this._afterRenderTargetDraw);\n this.scene._beforeClearStage.registerStep(SceneComponentConstants.STEP_BEFORECLEAR_PREPASS, this, this._beforeClearStage);\n this.scene._beforeRenderTargetClearStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERTARGETCLEAR_PREPASS, this, this._beforeRenderTargetClearStage);\n this.scene._beforeRenderingMeshStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERINGMESH_PREPASS, this, this._beforeRenderingMeshStage);\n this.scene._afterRenderingMeshStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGMESH_PREPASS, this, this._afterRenderingMeshStage);\n }\n _beforeRenderTargetDraw(renderTarget, faceIndex, layer) {\n if (this.scene.prePassRenderer && !renderTarget.noPrePassRenderer) {\n this.scene.prePassRenderer._setRenderTarget(renderTarget._prePassRenderTarget);\n this.scene.prePassRenderer._beforeDraw(undefined, faceIndex, layer);\n }\n }\n _afterRenderTargetDraw(renderTarget, faceIndex, layer) {\n if (this.scene.prePassRenderer && !renderTarget.noPrePassRenderer) {\n this.scene.prePassRenderer._afterDraw(faceIndex, layer);\n }\n }\n _beforeRenderTargetClearStage(renderTarget) {\n if (this.scene.prePassRenderer && !renderTarget.noPrePassRenderer) {\n if (!renderTarget._prePassRenderTarget) {\n renderTarget._prePassRenderTarget = this.scene.prePassRenderer._createRenderTarget(renderTarget.name + \"_prePassRTT\", renderTarget);\n }\n this.scene.prePassRenderer._setRenderTarget(renderTarget._prePassRenderTarget);\n this.scene.prePassRenderer._clear();\n }\n }\n _beforeCameraDraw(camera) {\n if (this.scene.prePassRenderer) {\n this.scene.prePassRenderer._setRenderTarget(null);\n this.scene.prePassRenderer._beforeDraw(camera);\n }\n }\n _afterCameraDraw() {\n if (this.scene.prePassRenderer) {\n this.scene.prePassRenderer._afterDraw();\n }\n }\n _beforeClearStage() {\n if (this.scene.prePassRenderer) {\n this.scene.prePassRenderer._setRenderTarget(null);\n this.scene.prePassRenderer._clear();\n }\n }\n _beforeRenderingMeshStage(mesh, subMesh, batch, effect) {\n if (!effect) {\n return;\n }\n // Render to MRT\n const scene = mesh.getScene();\n if (scene.prePassRenderer) {\n scene.prePassRenderer.bindAttachmentsForEffect(effect, subMesh);\n }\n }\n _afterRenderingMeshStage(mesh) {\n const scene = mesh.getScene();\n if (scene.prePassRenderer) {\n scene.prePassRenderer.restoreAttachments();\n }\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n // Release textures first\n this.scene.disablePrePassRenderer();\n // Re-enable\n this.scene.enablePrePassRenderer();\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n this.scene.disablePrePassRenderer();\n }\n }\n PrePassRenderer._SceneComponentInitialization = (scene) => {\n // Register the G Buffer component to the scene.\n let component = scene._getComponent(SceneComponentConstants.NAME_PREPASSRENDERER);\n if (!component) {\n component = new PrePassRendererSceneComponent(scene);\n scene._addComponent(component);\n }\n };\n\n const settingDefaults = {\n parentChangeBehavior: exports.eParentChangeBehavior.PRESERVE_POSITION,\n };\n const settingsKey = 'KBVIEWER_SETTINGS';\n const savedSettings = localStorage.getItem(settingsKey);\n const settings = savedSettings\n ? { ...settingDefaults, ...JSON.parse(savedSettings) }\n : { ...settingDefaults };\n class SettingsManagerService {\n static get(name) {\n return settings[name];\n }\n static set(name, value) {\n settings[name] = value;\n localStorage.setItem(settingsKey, JSON.stringify(settings));\n }\n }\n\n /**\n * Creates the VertexData for a Ribbon\n * @param options an object used to set the following optional parameters for the ribbon, required but can be empty\n * * pathArray array of paths, each of which an array of successive Vector3\n * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false\n * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false\n * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false\n * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional\n * * colors a linear array, of length 4 * number of vertices, of custom color values, optional\n * @param options.pathArray\n * @param options.closeArray\n * @param options.closePath\n * @param options.offset\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.invertUV\n * @param options.uvs\n * @param options.colors\n * @returns the VertexData of the ribbon\n */\n function CreateRibbonVertexData(options) {\n let pathArray = options.pathArray;\n const closeArray = options.closeArray || false;\n const closePath = options.closePath || false;\n const invertUV = options.invertUV || false;\n const defaultOffset = Math.floor(pathArray[0].length / 2);\n let offset = options.offset || defaultOffset;\n offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const customUV = options.uvs;\n const customColors = options.colors;\n const positions = [];\n const indices = [];\n const normals = [];\n const uvs = [];\n const us = []; // us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id\n const vs = []; // vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutive paths from pathArray\n const uTotalDistance = []; // uTotalDistance[p] : total distance of path p\n const vTotalDistance = []; // vTotalDistance[i] : total distance between points i of first and last path from pathArray\n let minlg; // minimal length among all paths from pathArray\n const lg = []; // array of path lengths : nb of vertex per path\n const idx = []; // array of path indexes : index of each path (first vertex) in the total vertex number\n let p; // path iterator\n let i; // point iterator\n let j; // point iterator\n // if single path in pathArray\n if (pathArray.length < 2) {\n const ar1 = [];\n const ar2 = [];\n for (i = 0; i < pathArray[0].length - offset; i++) {\n ar1.push(pathArray[0][i]);\n ar2.push(pathArray[0][i + offset]);\n }\n pathArray = [ar1, ar2];\n }\n // positions and horizontal distances (u)\n let idc = 0;\n const closePathCorr = closePath ? 1 : 0; // the final index will be +1 if closePath\n let path;\n let l;\n minlg = pathArray[0].length;\n let vectlg;\n let dist;\n for (p = 0; p < pathArray.length; p++) {\n uTotalDistance[p] = 0;\n us[p] = [0];\n path = pathArray[p];\n l = path.length;\n minlg = minlg < l ? minlg : l;\n j = 0;\n while (j < l) {\n positions.push(path[j].x, path[j].y, path[j].z);\n if (j > 0) {\n vectlg = path[j].subtract(path[j - 1]).length();\n dist = vectlg + uTotalDistance[p];\n us[p].push(dist);\n uTotalDistance[p] = dist;\n }\n j++;\n }\n if (closePath) {\n // an extra hidden vertex is added in the \"positions\" array\n j--;\n positions.push(path[0].x, path[0].y, path[0].z);\n vectlg = path[j].subtract(path[0]).length();\n dist = vectlg + uTotalDistance[p];\n us[p].push(dist);\n uTotalDistance[p] = dist;\n }\n lg[p] = l + closePathCorr;\n idx[p] = idc;\n idc += l + closePathCorr;\n }\n // vertical distances (v)\n let path1;\n let path2;\n let vertex1 = null;\n let vertex2 = null;\n for (i = 0; i < minlg + closePathCorr; i++) {\n vTotalDistance[i] = 0;\n vs[i] = [0];\n for (p = 0; p < pathArray.length - 1; p++) {\n path1 = pathArray[p];\n path2 = pathArray[p + 1];\n if (i === minlg) {\n // closePath\n vertex1 = path1[0];\n vertex2 = path2[0];\n }\n else {\n vertex1 = path1[i];\n vertex2 = path2[i];\n }\n vectlg = vertex2.subtract(vertex1).length();\n dist = vectlg + vTotalDistance[i];\n vs[i].push(dist);\n vTotalDistance[i] = dist;\n }\n if (closeArray && vertex2 && vertex1) {\n path1 = pathArray[p];\n path2 = pathArray[0];\n if (i === minlg) {\n // closePath\n vertex2 = path2[0];\n }\n vectlg = vertex2.subtract(vertex1).length();\n dist = vectlg + vTotalDistance[i];\n vTotalDistance[i] = dist;\n }\n }\n // uvs\n let u;\n let v;\n if (customUV) {\n for (p = 0; p < customUV.length; p++) {\n uvs.push(customUV[p].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - customUV[p].y : customUV[p].y);\n }\n }\n else {\n for (p = 0; p < pathArray.length; p++) {\n for (i = 0; i < minlg + closePathCorr; i++) {\n u = uTotalDistance[p] != 0.0 ? us[p][i] / uTotalDistance[p] : 0.0;\n v = vTotalDistance[i] != 0.0 ? vs[i][p] / vTotalDistance[i] : 0.0;\n if (invertUV) {\n uvs.push(v, u);\n }\n else {\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - v : v);\n }\n }\n }\n }\n // indices\n p = 0; // path index\n let pi = 0; // positions array index\n let l1 = lg[p] - 1; // path1 length\n let l2 = lg[p + 1] - 1; // path2 length\n let min = l1 < l2 ? l1 : l2; // current path stop index\n let shft = idx[1] - idx[0]; // shift\n const path1nb = closeArray ? lg.length : lg.length - 1; // number of path1 to iterate\ton\n while (pi <= min && p < path1nb) {\n // stay under min and don't go over next to last path\n // draw two triangles between path1 (p1) and path2 (p2) : (p1.pi, p2.pi, p1.pi+1) and (p2.pi+1, p1.pi+1, p2.pi) clockwise\n indices.push(pi, pi + shft, pi + 1);\n indices.push(pi + shft + 1, pi + 1, pi + shft);\n pi += 1;\n if (pi === min) {\n // if end of one of two consecutive paths reached, go to next existing path\n p++;\n if (p === lg.length - 1) {\n // last path of pathArray reached <=> closeArray == true\n shft = idx[0] - idx[p];\n l1 = lg[p] - 1;\n l2 = lg[0] - 1;\n }\n else {\n shft = idx[p + 1] - idx[p];\n l1 = lg[p] - 1;\n l2 = lg[p + 1] - 1;\n }\n pi = idx[p];\n min = l1 < l2 ? l1 + pi : l2 + pi;\n }\n }\n // normals\n VertexData.ComputeNormals(positions, indices, normals);\n if (closePath) {\n // update both the first and last vertex normals to their average value\n let indexFirst = 0;\n let indexLast = 0;\n for (p = 0; p < pathArray.length; p++) {\n indexFirst = idx[p] * 3;\n if (p + 1 < pathArray.length) {\n indexLast = (idx[p + 1] - 1) * 3;\n }\n else {\n indexLast = normals.length - 3;\n }\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\n normals[indexLast] = normals[indexFirst];\n normals[indexLast + 1] = normals[indexFirst + 1];\n normals[indexLast + 2] = normals[indexFirst + 2];\n }\n }\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Colors\n let colors = null;\n if (customColors) {\n colors = new Float32Array(customColors.length * 4);\n for (let c = 0; c < customColors.length; c++) {\n colors[c * 4] = customColors[c].r;\n colors[c * 4 + 1] = customColors[c].g;\n colors[c * 4 + 2] = customColors[c].b;\n colors[c * 4 + 3] = customColors[c].a;\n }\n }\n // Result\n const vertexData = new VertexData();\n const positions32 = new Float32Array(positions);\n const normals32 = new Float32Array(normals);\n const uvs32 = new Float32Array(uvs);\n vertexData.indices = indices;\n vertexData.positions = positions32;\n vertexData.normals = normals32;\n vertexData.uvs = uvs32;\n if (colors) {\n vertexData.set(colors, VertexBuffer.ColorKind);\n }\n if (closePath) {\n vertexData._idx = idx;\n }\n return vertexData;\n }\n /**\n * Creates a ribbon mesh. The ribbon is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters\n * * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry\n * * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array\n * * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array\n * * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path\n * * It's the offset to join the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11\n * * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#ribbon\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\n * * The parameter `uvs` is an optional flat array of `Vector2` to update/set each ribbon vertex with its own custom UV values instead of the computed ones\n * * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values\n * * Note that if you use the parameters `uvs` or `colors`, the passed arrays must be populated with the right number of elements, it is to say the number of ribbon vertices. Remember that if you set `closePath` to `true`, there's one extra vertex per path in the geometry\n * * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.pathArray\n * @param options.closeArray\n * @param options.closePath\n * @param options.offset\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.instance\n * @param options.invertUV\n * @param options.uvs\n * @param options.colors\n * @param scene defines the hosting scene\n * @returns the ribbon mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/ribbon_extra\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n */\n function CreateRibbon(name, options, scene = null) {\n const pathArray = options.pathArray;\n const closeArray = options.closeArray;\n const closePath = options.closePath;\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const instance = options.instance;\n const updatable = options.updatable;\n if (instance) {\n // existing ribbon instance update\n // positionFunction : ribbon case\n // only pathArray and sideOrientation parameters are taken into account for positions update\n const minimum = TmpVectors.Vector3[0].setAll(Number.MAX_VALUE);\n const maximum = TmpVectors.Vector3[1].setAll(-Number.MAX_VALUE);\n const positionFunction = (positions) => {\n let minlg = pathArray[0].length;\n const mesh = instance;\n let i = 0;\n const ns = mesh._originalBuilderSideOrientation === Mesh.DOUBLESIDE ? 2 : 1;\n for (let si = 1; si <= ns; ++si) {\n for (let p = 0; p < pathArray.length; ++p) {\n const path = pathArray[p];\n const l = path.length;\n minlg = minlg < l ? minlg : l;\n for (let j = 0; j < minlg; ++j) {\n const pathPoint = path[j];\n positions[i] = pathPoint.x;\n positions[i + 1] = pathPoint.y;\n positions[i + 2] = pathPoint.z;\n minimum.minimizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\n maximum.maximizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\n i += 3;\n }\n if (mesh._creationDataStorage && mesh._creationDataStorage.closePath) {\n const pathPoint = path[0];\n positions[i] = pathPoint.x;\n positions[i + 1] = pathPoint.y;\n positions[i + 2] = pathPoint.z;\n i += 3;\n }\n }\n }\n };\n const positions = instance.getVerticesData(VertexBuffer.PositionKind);\n positionFunction(positions);\n if (instance.hasBoundingInfo) {\n instance.getBoundingInfo().reConstruct(minimum, maximum, instance._worldMatrix);\n }\n else {\n instance.buildBoundingInfo(minimum, maximum, instance._worldMatrix);\n }\n instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\n if (options.colors) {\n const colors = instance.getVerticesData(VertexBuffer.ColorKind);\n for (let c = 0, colorIndex = 0; c < options.colors.length; c++, colorIndex += 4) {\n const color = options.colors[c];\n colors[colorIndex] = color.r;\n colors[colorIndex + 1] = color.g;\n colors[colorIndex + 2] = color.b;\n colors[colorIndex + 3] = color.a;\n }\n instance.updateVerticesData(VertexBuffer.ColorKind, colors, false, false);\n }\n if (options.uvs) {\n const uvs = instance.getVerticesData(VertexBuffer.UVKind);\n for (let i = 0; i < options.uvs.length; i++) {\n uvs[i * 2] = options.uvs[i].x;\n uvs[i * 2 + 1] = CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - options.uvs[i].y : options.uvs[i].y;\n }\n instance.updateVerticesData(VertexBuffer.UVKind, uvs, false, false);\n }\n if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {\n const indices = instance.getIndices();\n const normals = instance.getVerticesData(VertexBuffer.NormalKind);\n const params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;\n VertexData.ComputeNormals(positions, indices, normals, params);\n if (instance._creationDataStorage && instance._creationDataStorage.closePath) {\n let indexFirst = 0;\n let indexLast = 0;\n for (let p = 0; p < pathArray.length; p++) {\n indexFirst = instance._creationDataStorage.idx[p] * 3;\n if (p + 1 < pathArray.length) {\n indexLast = (instance._creationDataStorage.idx[p + 1] - 1) * 3;\n }\n else {\n indexLast = normals.length - 3;\n }\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\n normals[indexLast] = normals[indexFirst];\n normals[indexLast + 1] = normals[indexFirst + 1];\n normals[indexLast + 2] = normals[indexFirst + 2];\n }\n }\n if (!instance.areNormalsFrozen) {\n instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);\n }\n }\n return instance;\n }\n else {\n // new ribbon creation\n const ribbon = new Mesh(name, scene);\n ribbon._originalBuilderSideOrientation = sideOrientation;\n ribbon._creationDataStorage = new _CreationDataStorage();\n const vertexData = CreateRibbonVertexData(options);\n if (closePath) {\n ribbon._creationDataStorage.idx = vertexData._idx;\n }\n ribbon._creationDataStorage.closePath = closePath;\n ribbon._creationDataStorage.closeArray = closeArray;\n vertexData.applyToMesh(ribbon, updatable);\n return ribbon;\n }\n }\n VertexData.CreateRibbon = CreateRibbonVertexData;\n Mesh.CreateRibbon = (name, pathArray, closeArray = false, closePath, offset, scene, updatable = false, sideOrientation, instance) => {\n return CreateRibbon(name, {\n pathArray: pathArray,\n closeArray: closeArray,\n closePath: closePath,\n offset: offset,\n updatable: updatable,\n sideOrientation: sideOrientation,\n instance: instance,\n }, scene);\n };\n\n /**\n * Creates the VertexData of the Disc or regular Polygon\n * @param options an object used to set the following optional parameters for the disc, required but can be empty\n * * radius the radius of the disc, optional default 0.5\n * * tessellation the number of polygon sides, optional, default 64\n * * arc a number from 0 to 1, to create an unclosed polygon based on the fraction of the circumference given by the arc value, optional, default 1\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.radius\n * @param options.tessellation\n * @param options.arc\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the box\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function CreateDiscVertexData(options) {\n const positions = new Array();\n const indices = new Array();\n const normals = new Array();\n const uvs = new Array();\n const radius = options.radius || 0.5;\n const tessellation = options.tessellation || 64;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // positions and uvs\n positions.push(0, 0, 0); // disc center first\n uvs.push(0.5, 0.5);\n const theta = Math.PI * 2 * arc;\n const step = arc === 1 ? theta / tessellation : theta / (tessellation - 1);\n let a = 0;\n for (let t = 0; t < tessellation; t++) {\n const x = Math.cos(a);\n const y = Math.sin(a);\n const u = (x + 1) / 2;\n const v = (1 - y) / 2;\n positions.push(radius * x, radius * y, 0);\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n a += step;\n }\n if (arc === 1) {\n positions.push(positions[3], positions[4], positions[5]); // close the circle\n uvs.push(uvs[2], CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - uvs[3] : uvs[3]);\n }\n //indices\n const vertexNb = positions.length / 3;\n for (let i = 1; i < vertexNb - 1; i++) {\n indices.push(i + 1, 0, i);\n }\n // result\n VertexData.ComputeNormals(positions, indices, normals);\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a plane polygonal mesh. By default, this is a disc\n * * The parameter `radius` sets the radius size (float) of the polygon (default 0.5)\n * * The parameter `tessellation` sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc\n * * You can create an unclosed polygon with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference : 2 x PI x ratio\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.radius\n * @param options.tessellation\n * @param options.arc\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the plane polygonal mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#disc-or-regular-polygon\n */\n function CreateDisc(name, options = {}, scene = null) {\n const disc = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n disc._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateDiscVertexData(options);\n vertexData.applyToMesh(disc, options.updatable);\n return disc;\n }\n VertexData.CreateDisc = CreateDiscVertexData;\n Mesh.CreateDisc = (name, radius, tessellation, scene = null, updatable, sideOrientation) => {\n const options = {\n radius,\n tessellation,\n sideOrientation,\n updatable,\n };\n return CreateDisc(name, options, scene);\n };\n\n /**\n * Creates the VertexData for a tiled plane\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_plane\n * @param options an object used to set the following optional parameters for the tiled plane, required but can be empty\n * * pattern a limited pattern arrangement depending on the number\n * * size of the box\n * * width of the box, overwrites size\n * * height of the box, overwrites size\n * * tileSize sets the width, height and depth of the tile to the value of size, optional default 1\n * * tileWidth sets the width (x direction) of the tile, overwrites the width set by size, optional, default size\n * * tileHeight sets the height (y direction) of the tile, overwrites the height set by size, optional, default size\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\n * * alignVertical places whole tiles aligned to the center, left or right of a column\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * @param options.pattern\n * @param options.tileSize\n * @param options.tileWidth\n * @param options.tileHeight\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.alignHorizontal\n * @param options.alignVertical\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @returns the VertexData of the tiled plane\n */\n function CreateTiledPlaneVertexData(options) {\n const flipTile = options.pattern || Mesh.NO_FLIP;\n const tileWidth = options.tileWidth || options.tileSize || 1;\n const tileHeight = options.tileHeight || options.tileSize || 1;\n const alignH = options.alignHorizontal || 0;\n const alignV = options.alignVertical || 0;\n const width = options.width || options.size || 1;\n const tilesX = Math.floor(width / tileWidth);\n let offsetX = width - tilesX * tileWidth;\n const height = options.height || options.size || 1;\n const tilesY = Math.floor(height / tileHeight);\n let offsetY = height - tilesY * tileHeight;\n const halfWidth = (tileWidth * tilesX) / 2;\n const halfHeight = (tileHeight * tilesY) / 2;\n let adjustX = 0;\n let adjustY = 0;\n let startX = 0;\n let startY = 0;\n let endX = 0;\n let endY = 0;\n //Part Tiles\n if (offsetX > 0 || offsetY > 0) {\n startX = -halfWidth;\n startY = -halfHeight;\n endX = halfWidth;\n endY = halfHeight;\n switch (alignH) {\n case Mesh.CENTER:\n offsetX /= 2;\n startX -= offsetX;\n endX += offsetX;\n break;\n case Mesh.LEFT:\n endX += offsetX;\n adjustX = -offsetX / 2;\n break;\n case Mesh.RIGHT:\n startX -= offsetX;\n adjustX = offsetX / 2;\n break;\n }\n switch (alignV) {\n case Mesh.CENTER:\n offsetY /= 2;\n startY -= offsetY;\n endY += offsetY;\n break;\n case Mesh.BOTTOM:\n endY += offsetY;\n adjustY = -offsetY / 2;\n break;\n case Mesh.TOP:\n startY -= offsetY;\n adjustY = offsetY / 2;\n break;\n }\n }\n const positions = [];\n const normals = [];\n const uvBase = [];\n uvBase[0] = [0, 0, 1, 0, 1, 1, 0, 1];\n uvBase[1] = [0, 0, 1, 0, 1, 1, 0, 1];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBase[1] = [1, 1, 0, 1, 0, 0, 1, 0];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBase[1] = [1, 0, 0, 0, 0, 1, 1, 1];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBase[1] = [0, 1, 1, 1, 1, 0, 0, 0];\n }\n let uvs = [];\n const colors = [];\n const indices = [];\n let index = 0;\n for (let y = 0; y < tilesY; y++) {\n for (let x = 0; x < tilesX; x++) {\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs = uvs.concat(uvBase[((x % 2) + (y % 2)) % 2]);\n }\n else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs = uvs.concat(uvBase[y % 2]);\n }\n else {\n uvs = uvs.concat(uvBase[0]);\n }\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n index += 4;\n }\n }\n //Part Tiles\n if (offsetX > 0 || offsetY > 0) {\n const partialBottomRow = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.TOP);\n const partialTopRow = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.BOTTOM);\n const partialLeftCol = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.RIGHT);\n const partialRightCol = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.LEFT);\n let uvPart = [];\n let a, b, c, d;\n //corners\n if (partialBottomRow && partialLeftCol) {\n //bottom left corner\n positions.push(startX + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + adjustX, startY + offsetY + adjustY, 0);\n positions.push(startX + adjustX, startY + offsetY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 1 - offsetX / tileWidth;\n b = 1 - offsetY / tileHeight;\n c = 1;\n d = 1;\n uvPart = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_ROW) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_ROW) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs = uvs.concat(uvPart);\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n if (partialBottomRow && partialRightCol) {\n //bottom right corner\n positions.push(halfWidth + adjustX, startY + adjustY, 0);\n positions.push(endX + adjustX, startY + adjustY, 0);\n positions.push(endX + adjustX, startY + offsetY + adjustY, 0);\n positions.push(halfWidth + adjustX, startY + offsetY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 0;\n b = 1 - offsetY / tileHeight;\n c = offsetX / tileWidth;\n d = 1;\n uvPart = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_ROW || (flipTile === Mesh.ROTATE_TILE && tilesX % 2 === 0)) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_ROW || (flipTile === Mesh.FLIP_TILE && tilesX % 2 === 0)) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW || (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesX % 2 === 0)) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs = uvs.concat(uvPart);\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n if (partialTopRow && partialLeftCol) {\n //top left corner\n positions.push(startX + adjustX, halfHeight + adjustY, 0);\n positions.push(-halfWidth + adjustX, halfHeight + adjustY, 0);\n positions.push(-halfWidth + adjustX, endY + adjustY, 0);\n positions.push(startX + adjustX, endY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 1 - offsetX / tileWidth;\n b = 0;\n c = 1;\n d = offsetY / tileHeight;\n uvPart = [a, b, c, b, c, d, a, d];\n if ((flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.ROTATE_TILE && tilesY % 1 === 0)) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if ((flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_TILE && tilesY % 2 === 0)) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if ((flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesY % 2 === 0)) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs = uvs.concat(uvPart);\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n if (partialTopRow && partialRightCol) {\n //top right corner\n positions.push(halfWidth + adjustX, halfHeight + adjustY, 0);\n positions.push(endX + adjustX, halfHeight + adjustY, 0);\n positions.push(endX + adjustX, endY + adjustY, 0);\n positions.push(halfWidth + adjustX, endY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 0;\n b = 0;\n c = offsetX / tileWidth;\n d = offsetY / tileHeight;\n uvPart = [a, b, c, b, c, d, a, d];\n if ((flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.ROTATE_TILE && (tilesY + tilesX) % 2 === 1)) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if ((flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_TILE && (tilesY + tilesX) % 2 === 1)) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if ((flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_N_ROTATE_TILE && (tilesY + tilesX) % 2 === 1)) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs = uvs.concat(uvPart);\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n //part rows\n if (partialBottomRow) {\n const uvBaseBR = [];\n a = 0;\n b = 1 - offsetY / tileHeight;\n c = 1;\n d = 1;\n uvBaseBR[0] = [a, b, c, b, c, d, a, d];\n uvBaseBR[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseBR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseBR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseBR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let x = 0; x < tilesX; x++) {\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + offsetY + adjustY, 0);\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + offsetY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs = uvs.concat(uvBaseBR[(x + 1) % 2]);\n }\n else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs = uvs.concat(uvBaseBR[1]);\n }\n else {\n uvs = uvs.concat(uvBaseBR[0]);\n }\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n }\n if (partialTopRow) {\n const uvBaseTR = [];\n a = 0;\n b = 0;\n c = 1;\n d = offsetY / tileHeight;\n uvBaseTR[0] = [a, b, c, b, c, d, a, d];\n uvBaseTR[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseTR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseTR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseTR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let x = 0; x < tilesX; x++) {\n positions.push(-halfWidth + x * tileWidth + adjustX, endY - offsetY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY - offsetY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY + adjustY, 0);\n positions.push(-halfWidth + x * tileWidth + adjustX, endY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs = uvs.concat(uvBaseTR[(x + tilesY) % 2]);\n }\n else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs = uvs.concat(uvBaseTR[tilesY % 2]);\n }\n else {\n uvs = uvs.concat(uvBaseTR[0]);\n }\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n }\n if (partialLeftCol) {\n const uvBaseLC = [];\n a = 1 - offsetX / tileWidth;\n b = 0;\n c = 1;\n d = 1;\n uvBaseLC[0] = [a, b, c, b, c, d, a, d];\n uvBaseLC[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseLC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseLC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseLC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let y = 0; y < tilesY; y++) {\n positions.push(startX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(startX + offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(startX + offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n positions.push(startX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs = uvs.concat(uvBaseLC[(y + 1) % 2]);\n }\n else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs = uvs.concat(uvBaseLC[y % 2]);\n }\n else {\n uvs = uvs.concat(uvBaseLC[0]);\n }\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n }\n if (partialRightCol) {\n const uvBaseRC = [];\n a = 0;\n b = 0;\n c = offsetX / tileHeight;\n d = 1;\n uvBaseRC[0] = [a, b, c, b, c, d, a, d];\n uvBaseRC[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseRC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseRC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseRC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let y = 0; y < tilesY; y++) {\n positions.push(endX - offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(endX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(endX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n positions.push(endX - offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs = uvs.concat(uvBaseRC[(y + tilesX) % 2]);\n }\n else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs = uvs.concat(uvBaseRC[y % 2]);\n }\n else {\n uvs = uvs.concat(uvBaseRC[0]);\n }\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\n }\n }\n }\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\n vertexData.colors = totalColors;\n return vertexData;\n }\n /**\n * Creates a tiled plane mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_plane\n * @param name defines the name of the mesh\n * @param options an object used to set the following optional parameters for the tiled plane, required but can be empty\n * * pattern a limited pattern arrangement depending on the number\n * * size of the box\n * * width of the box, overwrites size\n * * height of the box, overwrites size\n * * tileSize sets the width, height and depth of the tile to the value of size, optional default 1\n * * tileWidth sets the width (x direction) of the tile, overwrites the width set by size, optional, default size\n * * tileHeight sets the height (y direction) of the tile, overwrites the height set by size, optional, default size\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\n * * alignVertical places whole tiles aligned to the center, left or right of a column\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.pattern\n * @param options.tileSize\n * @param options.tileWidth\n * @param options.tileHeight\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.alignHorizontal\n * @param options.alignVertical\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the box mesh\n */\n function CreateTiledPlane(name, options, scene = null) {\n const plane = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n plane._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateTiledPlaneVertexData(options);\n vertexData.applyToMesh(plane, options.updatable);\n return plane;\n }\n VertexData.CreateTiledPlane = CreateTiledPlaneVertexData;\n\n /**\n * Creates the VertexData for a tiled box\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_box\n * @param options an object used to set the following optional parameters for the tiled box, required but can be empty\n * * pattern sets the rotation or reflection pattern for the tiles,\n * * size of the box\n * * width of the box, overwrites size\n * * height of the box, overwrites size\n * * depth of the box, overwrites size\n * * tileSize sets the size of a tile\n * * tileWidth sets the tile width and overwrites tileSize\n * * tileHeight sets the tile width and overwrites tileSize\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\n * * alignVertical places whole tiles aligned to the center, left or right of a column\n * @param options.pattern\n * @param options.size\n * @param options.width\n * @param options.height\n * @param options.depth\n * @param options.tileSize\n * @param options.tileWidth\n * @param options.tileHeight\n * @param options.faceUV\n * @param options.faceColors\n * @param options.alignHorizontal\n * @param options.alignVertical\n * @param options.sideOrientation\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * @returns the VertexData of the TiledBox\n */\n function CreateTiledBoxVertexData(options) {\n const nbFaces = 6;\n const faceUV = options.faceUV || new Array(6);\n const faceColors = options.faceColors;\n const flipTile = options.pattern || Mesh.NO_FLIP;\n const width = options.width || options.size || 1;\n const height = options.height || options.size || 1;\n const depth = options.depth || options.size || 1;\n const tileWidth = options.tileWidth || options.tileSize || 1;\n const tileHeight = options.tileHeight || options.tileSize || 1;\n const alignH = options.alignHorizontal || 0;\n const alignV = options.alignVertical || 0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // default face colors and UV if undefined\n for (let f = 0; f < nbFaces; f++) {\n if (faceUV[f] === undefined) {\n faceUV[f] = new Vector4(0, 0, 1, 1);\n }\n if (faceColors && faceColors[f] === undefined) {\n faceColors[f] = new Color4(1, 1, 1, 1);\n }\n }\n const halfWidth = width / 2;\n const halfHeight = height / 2;\n const halfDepth = depth / 2;\n const faceVertexData = [];\n for (let f = 0; f < 2; f++) {\n //front and back\n faceVertexData[f] = CreateTiledPlaneVertexData({\n pattern: flipTile,\n tileWidth: tileWidth,\n tileHeight: tileHeight,\n width: width,\n height: height,\n alignVertical: alignV,\n alignHorizontal: alignH,\n sideOrientation: sideOrientation,\n });\n }\n for (let f = 2; f < 4; f++) {\n //sides\n faceVertexData[f] = CreateTiledPlaneVertexData({\n pattern: flipTile,\n tileWidth: tileWidth,\n tileHeight: tileHeight,\n width: depth,\n height: height,\n alignVertical: alignV,\n alignHorizontal: alignH,\n sideOrientation: sideOrientation,\n });\n }\n let baseAlignV = alignV;\n if (alignV === Mesh.BOTTOM) {\n baseAlignV = Mesh.TOP;\n }\n else if (alignV === Mesh.TOP) {\n baseAlignV = Mesh.BOTTOM;\n }\n for (let f = 4; f < 6; f++) {\n //top and bottom\n faceVertexData[f] = CreateTiledPlaneVertexData({\n pattern: flipTile,\n tileWidth: tileWidth,\n tileHeight: tileHeight,\n width: width,\n height: depth,\n alignVertical: baseAlignV,\n alignHorizontal: alignH,\n sideOrientation: sideOrientation,\n });\n }\n let positions = [];\n let normals = [];\n let uvs = [];\n let indices = [];\n const colors = [];\n const facePositions = [];\n const faceNormals = [];\n const newFaceUV = [];\n let lu = 0;\n let li = 0;\n for (let f = 0; f < nbFaces; f++) {\n const len = faceVertexData[f].positions.length;\n facePositions[f] = [];\n faceNormals[f] = [];\n for (let p = 0; p < len / 3; p++) {\n facePositions[f].push(new Vector3(faceVertexData[f].positions[3 * p], faceVertexData[f].positions[3 * p + 1], faceVertexData[f].positions[3 * p + 2]));\n faceNormals[f].push(new Vector3(faceVertexData[f].normals[3 * p], faceVertexData[f].normals[3 * p + 1], faceVertexData[f].normals[3 * p + 2]));\n }\n // uvs\n lu = faceVertexData[f].uvs.length;\n newFaceUV[f] = [];\n for (let i = 0; i < lu; i += 2) {\n newFaceUV[f][i] = faceUV[f].x + (faceUV[f].z - faceUV[f].x) * faceVertexData[f].uvs[i];\n newFaceUV[f][i + 1] = faceUV[f].y + (faceUV[f].w - faceUV[f].y) * faceVertexData[f].uvs[i + 1];\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n newFaceUV[f][i + 1] = 1.0 - newFaceUV[f][i + 1];\n }\n }\n uvs = uvs.concat(newFaceUV[f]);\n indices = indices.concat(faceVertexData[f].indices.map((x) => x + li));\n li += facePositions[f].length;\n if (faceColors) {\n for (let c = 0; c < 4; c++) {\n colors.push(faceColors[f].r, faceColors[f].g, faceColors[f].b, faceColors[f].a);\n }\n }\n }\n const vec0 = new Vector3(0, 0, halfDepth);\n const mtrx0 = Matrix.RotationY(Math.PI);\n positions = facePositions[0]\n .map((entry) => Vector3.TransformNormal(entry, mtrx0).add(vec0))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);\n normals = faceNormals[0]\n .map((entry) => Vector3.TransformNormal(entry, mtrx0))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);\n positions = positions.concat(facePositions[1]\n .map((entry) => entry.subtract(vec0))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n normals = normals.concat(faceNormals[1].map((entry) => [entry.x, entry.y, entry.z]).reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n const vec2 = new Vector3(halfWidth, 0, 0);\n const mtrx2 = Matrix.RotationY(-Math.PI / 2);\n positions = positions.concat(facePositions[2]\n .map((entry) => Vector3.TransformNormal(entry, mtrx2).add(vec2))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n normals = normals.concat(faceNormals[2]\n .map((entry) => Vector3.TransformNormal(entry, mtrx2))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n const mtrx3 = Matrix.RotationY(Math.PI / 2);\n positions = positions.concat(facePositions[3]\n .map((entry) => Vector3.TransformNormal(entry, mtrx3).subtract(vec2))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n normals = normals.concat(faceNormals[3]\n .map((entry) => Vector3.TransformNormal(entry, mtrx3))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n const vec4 = new Vector3(0, halfHeight, 0);\n const mtrx4 = Matrix.RotationX(Math.PI / 2);\n positions = positions.concat(facePositions[4]\n .map((entry) => Vector3.TransformNormal(entry, mtrx4).add(vec4))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n normals = normals.concat(faceNormals[4]\n .map((entry) => Vector3.TransformNormal(entry, mtrx4))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n const mtrx5 = Matrix.RotationX(-Math.PI / 2);\n positions = positions.concat(facePositions[5]\n .map((entry) => Vector3.TransformNormal(entry, mtrx5).subtract(vec4))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n normals = normals.concat(faceNormals[5]\n .map((entry) => Vector3.TransformNormal(entry, mtrx5))\n .map((entry) => [entry.x, entry.y, entry.z])\n .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []));\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n if (faceColors) {\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\n vertexData.colors = totalColors;\n }\n return vertexData;\n }\n /**\n * Creates a tiled box mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_box\n * @param name defines the name of the mesh\n * @param options an object used to set the following optional parameters for the tiled box, required but can be empty\n * * pattern sets the rotation or reflection pattern for the tiles,\n * * size of the box\n * * width of the box, overwrites size\n * * height of the box, overwrites size\n * * depth of the box, overwrites size\n * * tileSize sets the size of a tile\n * * tileWidth sets the tile width and overwrites tileSize\n * * tileHeight sets the tile width and overwrites tileSize\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\n * * alignVertical places whole tiles aligned to the center, left or right of a column\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * @param options.pattern\n * @param options.width\n * @param options.height\n * @param options.depth\n * @param options.tileSize\n * @param options.tileWidth\n * @param options.tileHeight\n * @param options.alignHorizontal\n * @param options.alignVertical\n * @param options.faceUV\n * @param options.faceColors\n * @param options.sideOrientation\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the box mesh\n */\n function CreateTiledBox(name, options, scene = null) {\n const box = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n box._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateTiledBoxVertexData(options);\n vertexData.applyToMesh(box, options.updatable);\n return box;\n }\n VertexData.CreateTiledBox = CreateTiledBoxVertexData;\n\n // based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473\n /**\n * Creates the VertexData for a TorusKnot\n * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty\n * * radius the radius of the torus knot, optional, default 2\n * * tube the thickness of the tube, optional, default 0.5\n * * radialSegments the number of sides on each tube segments, optional, default 32\n * * tubularSegments the number of tubes to decompose the knot into, optional, default 32\n * * p the number of windings around the z axis, optional, default 2\n * * q the number of windings around the x axis, optional, default 3\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.radius\n * @param options.tube\n * @param options.radialSegments\n * @param options.tubularSegments\n * @param options.p\n * @param options.q\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the Torus Knot\n */\n function CreateTorusKnotVertexData(options) {\n const indices = new Array();\n const positions = new Array();\n const normals = new Array();\n const uvs = new Array();\n const radius = options.radius || 2;\n const tube = options.tube || 0.5;\n const radialSegments = options.radialSegments || 32;\n const tubularSegments = options.tubularSegments || 32;\n const p = options.p || 2;\n const q = options.q || 3;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // Helper\n const getPos = (angle) => {\n const cu = Math.cos(angle);\n const su = Math.sin(angle);\n const quOverP = (q / p) * angle;\n const cs = Math.cos(quOverP);\n const tx = radius * (2 + cs) * 0.5 * cu;\n const ty = radius * (2 + cs) * su * 0.5;\n const tz = radius * Math.sin(quOverP) * 0.5;\n return new Vector3(tx, ty, tz);\n };\n // Vertices\n let i;\n let j;\n for (i = 0; i <= radialSegments; i++) {\n const modI = i % radialSegments;\n const u = (modI / radialSegments) * 2 * p * Math.PI;\n const p1 = getPos(u);\n const p2 = getPos(u + 0.01);\n const tang = p2.subtract(p1);\n let n = p2.add(p1);\n const bitan = Vector3.Cross(tang, n);\n n = Vector3.Cross(bitan, tang);\n bitan.normalize();\n n.normalize();\n for (j = 0; j < tubularSegments; j++) {\n const modJ = j % tubularSegments;\n const v = (modJ / tubularSegments) * 2 * Math.PI;\n const cx = -tube * Math.cos(v);\n const cy = tube * Math.sin(v);\n positions.push(p1.x + cx * n.x + cy * bitan.x);\n positions.push(p1.y + cx * n.y + cy * bitan.y);\n positions.push(p1.z + cx * n.z + cy * bitan.z);\n uvs.push(i / radialSegments);\n uvs.push(CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - j / tubularSegments : j / tubularSegments);\n }\n }\n for (i = 0; i < radialSegments; i++) {\n for (j = 0; j < tubularSegments; j++) {\n const jNext = (j + 1) % tubularSegments;\n const a = i * tubularSegments + j;\n const b = (i + 1) * tubularSegments + j;\n const c = (i + 1) * tubularSegments + jNext;\n const d = i * tubularSegments + jNext;\n indices.push(d);\n indices.push(b);\n indices.push(a);\n indices.push(d);\n indices.push(c);\n indices.push(b);\n }\n }\n // Normals\n VertexData.ComputeNormals(positions, indices, normals);\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a torus knot mesh\n * * The parameter `radius` sets the global radius size (float) of the torus knot (default 2)\n * * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32)\n * * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32)\n * * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.radius\n * @param options.tube\n * @param options.radialSegments\n * @param options.tubularSegments\n * @param options.p\n * @param options.q\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the torus knot mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus-knot\n */\n function CreateTorusKnot(name, options = {}, scene) {\n const torusKnot = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n torusKnot._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateTorusKnotVertexData(options);\n vertexData.applyToMesh(torusKnot, options.updatable);\n return torusKnot;\n }\n VertexData.CreateTorusKnot = CreateTorusKnotVertexData;\n Mesh.CreateTorusKnot = (name, radius, tube, radialSegments, tubularSegments, p, q, scene, updatable, sideOrientation) => {\n const options = {\n radius,\n tube,\n radialSegments,\n tubularSegments,\n p,\n q,\n sideOrientation,\n updatable,\n };\n return CreateTorusKnot(name, options, scene);\n };\n\n /**\n * Vector2 wth index property\n */\n class IndexedVector2 extends Vector2 {\n constructor(original, \n /** Index of the vector2 */\n index) {\n super(original.x, original.y);\n this.index = index;\n }\n }\n /**\n * Defines points to create a polygon\n */\n class PolygonPoints {\n constructor() {\n this.elements = new Array();\n }\n add(originalPoints) {\n const result = new Array();\n originalPoints.forEach((point) => {\n const newPoint = new IndexedVector2(point, this.elements.length);\n result.push(newPoint);\n this.elements.push(newPoint);\n });\n return result;\n }\n computeBounds() {\n const lmin = new Vector2(this.elements[0].x, this.elements[0].y);\n const lmax = new Vector2(this.elements[0].x, this.elements[0].y);\n this.elements.forEach((point) => {\n // x\n if (point.x < lmin.x) {\n lmin.x = point.x;\n }\n else if (point.x > lmax.x) {\n lmax.x = point.x;\n }\n // y\n if (point.y < lmin.y) {\n lmin.y = point.y;\n }\n else if (point.y > lmax.y) {\n lmax.y = point.y;\n }\n });\n return {\n min: lmin,\n max: lmax,\n width: lmax.x - lmin.x,\n height: lmax.y - lmin.y,\n };\n }\n }\n /**\n * Builds a polygon\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/polyMeshBuilder\n */\n class PolygonMeshBuilder {\n _addToepoint(points) {\n for (const p of points) {\n this._epoints.push(p.x, p.y);\n }\n }\n /**\n * Creates a PolygonMeshBuilder\n * @param name name of the builder\n * @param contours Path of the polygon\n * @param scene scene to add to when creating the mesh\n * @param earcutInjection can be used to inject your own earcut reference\n */\n constructor(name, contours, scene, earcutInjection = earcut) {\n this._points = new PolygonPoints();\n this._outlinepoints = new PolygonPoints();\n this._holes = new Array();\n this._epoints = new Array();\n this._eholes = new Array();\n this.bjsEarcut = earcutInjection;\n this._name = name;\n this._scene = scene || EngineStore.LastCreatedScene;\n let points;\n if (contours instanceof Path2) {\n points = contours.getPoints();\n }\n else {\n points = contours;\n }\n this._addToepoint(points);\n this._points.add(points);\n this._outlinepoints.add(points);\n if (typeof this.bjsEarcut === \"undefined\") {\n Logger.Warn(\"Earcut was not found, the polygon will not be built.\");\n }\n }\n /**\n * Adds a hole within the polygon\n * @param hole Array of points defining the hole\n * @returns this\n */\n addHole(hole) {\n this._points.add(hole);\n const holepoints = new PolygonPoints();\n holepoints.add(hole);\n this._holes.push(holepoints);\n this._eholes.push(this._epoints.length / 2);\n this._addToepoint(hole);\n return this;\n }\n /**\n * Creates the polygon\n * @param updatable If the mesh should be updatable\n * @param depth The depth of the mesh created\n * @param smoothingThreshold Dot product threshold for smoothed normals\n * @returns the created mesh\n */\n build(updatable = false, depth = 0, smoothingThreshold = 2) {\n const result = new Mesh(this._name, this._scene);\n const vertexData = this.buildVertexData(depth, smoothingThreshold);\n result.setVerticesData(VertexBuffer.PositionKind, vertexData.positions, updatable);\n result.setVerticesData(VertexBuffer.NormalKind, vertexData.normals, updatable);\n result.setVerticesData(VertexBuffer.UVKind, vertexData.uvs, updatable);\n result.setIndices(vertexData.indices);\n return result;\n }\n /**\n * Creates the polygon\n * @param depth The depth of the mesh created\n * @param smoothingThreshold Dot product threshold for smoothed normals\n * @returns the created VertexData\n */\n buildVertexData(depth = 0, smoothingThreshold = 2) {\n const result = new VertexData();\n const normals = new Array();\n const positions = new Array();\n const uvs = new Array();\n const bounds = this._points.computeBounds();\n this._points.elements.forEach((p) => {\n normals.push(0, 1.0, 0);\n positions.push(p.x, 0, p.y);\n uvs.push((p.x - bounds.min.x) / bounds.width, (p.y - bounds.min.y) / bounds.height);\n });\n const indices = new Array();\n const res = this.bjsEarcut(this._epoints, this._eholes, 2);\n for (let i = 0; i < res.length; i++) {\n indices.push(res[i]);\n }\n if (depth > 0) {\n const positionscount = positions.length / 3; //get the current pointcount\n this._points.elements.forEach((p) => {\n //add the elements at the depth\n normals.push(0, -1.0, 0);\n positions.push(p.x, -depth, p.y);\n uvs.push(1 - (p.x - bounds.min.x) / bounds.width, 1 - (p.y - bounds.min.y) / bounds.height);\n });\n const totalCount = indices.length;\n for (let i = 0; i < totalCount; i += 3) {\n const i0 = indices[i + 0];\n const i1 = indices[i + 1];\n const i2 = indices[i + 2];\n indices.push(i2 + positionscount);\n indices.push(i1 + positionscount);\n indices.push(i0 + positionscount);\n }\n //Add the sides\n this._addSide(positions, normals, uvs, indices, bounds, this._outlinepoints, depth, false, smoothingThreshold);\n this._holes.forEach((hole) => {\n this._addSide(positions, normals, uvs, indices, bounds, hole, depth, true, smoothingThreshold);\n });\n }\n result.indices = indices;\n result.positions = positions;\n result.normals = normals;\n result.uvs = uvs;\n return result;\n }\n /**\n * Adds a side to the polygon\n * @param positions points that make the polygon\n * @param normals normals of the polygon\n * @param uvs uvs of the polygon\n * @param indices indices of the polygon\n * @param bounds bounds of the polygon\n * @param points points of the polygon\n * @param depth depth of the polygon\n * @param flip flip of the polygon\n * @param smoothingThreshold\n */\n _addSide(positions, normals, uvs, indices, bounds, points, depth, flip, smoothingThreshold) {\n let startIndex = positions.length / 3;\n let ulength = 0;\n for (let i = 0; i < points.elements.length; i++) {\n const p = points.elements[i];\n const p1 = points.elements[(i + 1) % points.elements.length];\n positions.push(p.x, 0, p.y);\n positions.push(p.x, -depth, p.y);\n positions.push(p1.x, 0, p1.y);\n positions.push(p1.x, -depth, p1.y);\n const p0 = points.elements[(i + points.elements.length - 1) % points.elements.length];\n const p2 = points.elements[(i + 2) % points.elements.length];\n let vc = new Vector3(-(p1.y - p.y), 0, p1.x - p.x);\n let vp = new Vector3(-(p.y - p0.y), 0, p.x - p0.x);\n let vn = new Vector3(-(p2.y - p1.y), 0, p2.x - p1.x);\n if (!flip) {\n vc = vc.scale(-1);\n vp = vp.scale(-1);\n vn = vn.scale(-1);\n }\n const vc_norm = vc.normalizeToNew();\n let vp_norm = vp.normalizeToNew();\n let vn_norm = vn.normalizeToNew();\n const dotp = Vector3.Dot(vp_norm, vc_norm);\n if (dotp > smoothingThreshold) {\n if (dotp < Epsilon - 1) {\n vp_norm = new Vector3(p.x, 0, p.y).subtract(new Vector3(p1.x, 0, p1.y)).normalize();\n }\n else {\n // cheap average weighed by side length\n vp_norm = vp.add(vc).normalize();\n }\n }\n else {\n vp_norm = vc_norm;\n }\n const dotn = Vector3.Dot(vn, vc);\n if (dotn > smoothingThreshold) {\n if (dotn < Epsilon - 1) {\n // back to back\n vn_norm = new Vector3(p1.x, 0, p1.y).subtract(new Vector3(p.x, 0, p.y)).normalize();\n }\n else {\n // cheap average weighed by side length\n vn_norm = vn.add(vc).normalize();\n }\n }\n else {\n vn_norm = vc_norm;\n }\n uvs.push(ulength / bounds.width, 0);\n uvs.push(ulength / bounds.width, 1);\n ulength += vc.length();\n uvs.push(ulength / bounds.width, 0);\n uvs.push(ulength / bounds.width, 1);\n normals.push(vp_norm.x, vp_norm.y, vp_norm.z);\n normals.push(vp_norm.x, vp_norm.y, vp_norm.z);\n normals.push(vn_norm.x, vn_norm.y, vn_norm.z);\n normals.push(vn_norm.x, vn_norm.y, vn_norm.z);\n if (!flip) {\n indices.push(startIndex);\n indices.push(startIndex + 1);\n indices.push(startIndex + 2);\n indices.push(startIndex + 1);\n indices.push(startIndex + 3);\n indices.push(startIndex + 2);\n }\n else {\n indices.push(startIndex);\n indices.push(startIndex + 2);\n indices.push(startIndex + 1);\n indices.push(startIndex + 1);\n indices.push(startIndex + 2);\n indices.push(startIndex + 3);\n }\n startIndex += 4;\n }\n }\n }\n\n /**\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\n * All parameters are provided by CreatePolygon as needed\n * @param polygon a mesh built from polygonTriangulation.build()\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param wrp a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\n * @returns the VertexData of the Polygon\n */\n function CreatePolygonVertexData(polygon, sideOrientation, fUV, fColors, frontUVs, backUVs, wrp) {\n const faceUV = fUV || new Array(3);\n const faceColors = fColors;\n const colors = [];\n const wrap = wrp || false;\n // default face colors and UV if undefined\n for (let f = 0; f < 3; f++) {\n if (faceUV[f] === undefined) {\n faceUV[f] = new Vector4(0, 0, 1, 1);\n }\n if (faceColors && faceColors[f] === undefined) {\n faceColors[f] = new Color4(1, 1, 1, 1);\n }\n }\n const positions = polygon.getVerticesData(VertexBuffer.PositionKind);\n const normals = polygon.getVerticesData(VertexBuffer.NormalKind);\n const uvs = polygon.getVerticesData(VertexBuffer.UVKind);\n const indices = polygon.getIndices();\n const startIndex = positions.length / 9;\n let disp = 0;\n let distX = 0;\n let distZ = 0;\n let dist = 0;\n let totalLen = 0;\n const cumulate = [0];\n if (wrap) {\n for (let idx = startIndex; idx < positions.length / 3; idx += 4) {\n distX = positions[3 * (idx + 2)] - positions[3 * idx];\n distZ = positions[3 * (idx + 2) + 2] - positions[3 * idx + 2];\n dist = Math.sqrt(distX * distX + distZ * distZ);\n totalLen += dist;\n cumulate.push(totalLen);\n }\n }\n // set face colours and textures\n let idx = 0;\n let face = 0;\n for (let index = 0; index < normals.length; index += 3) {\n //Edge Face no. 1\n if (Math.abs(normals[index + 1]) < 0.001) {\n face = 1;\n }\n //Top Face no. 0\n if (Math.abs(normals[index + 1] - 1) < 0.001) {\n face = 0;\n }\n //Bottom Face no. 2\n if (Math.abs(normals[index + 1] + 1) < 0.001) {\n face = 2;\n }\n idx = index / 3;\n if (face === 1) {\n disp = idx - startIndex;\n if (disp % 4 < 1.5) {\n if (wrap) {\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4)]) / totalLen;\n }\n else {\n uvs[2 * idx] = faceUV[face].x;\n }\n }\n else {\n if (wrap) {\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4) + 1]) / totalLen;\n }\n else {\n uvs[2 * idx] = faceUV[face].z;\n }\n }\n if (disp % 2 === 0) {\n uvs[2 * idx + 1] = CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[face].w : faceUV[face].w;\n }\n else {\n uvs[2 * idx + 1] = CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[face].y : faceUV[face].y;\n }\n }\n else {\n uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;\n uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\n uvs[2 * idx + 1] = 1.0 - uvs[2 * idx + 1];\n }\n }\n if (faceColors) {\n colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);\n }\n }\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n if (faceColors) {\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\n vertexData.colors = totalColors;\n }\n return vertexData;\n }\n /**\n * Creates a polygon mesh\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh\n * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\n * * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)\n * * Remember you can only change the shape positions, not their number when updating a polygon\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.shape\n * @param options.holes\n * @param options.depth\n * @param options.smoothingThreshold\n * @param options.faceUV\n * @param options.faceColors\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.wrap\n * @param scene defines the hosting scene\n * @param earcutInjection can be used to inject your own earcut reference\n * @returns the polygon mesh\n */\n function CreatePolygon(name, options, scene = null, earcutInjection = earcut) {\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const shape = options.shape;\n const holes = options.holes || [];\n const depth = options.depth || 0;\n const smoothingThreshold = options.smoothingThreshold || 2;\n const contours = [];\n let hole = [];\n for (let i = 0; i < shape.length; i++) {\n contours[i] = new Vector2(shape[i].x, shape[i].z);\n }\n const epsilon = 0.00000001;\n if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {\n contours.pop();\n }\n const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene, earcutInjection);\n for (let hNb = 0; hNb < holes.length; hNb++) {\n hole = [];\n for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {\n hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));\n }\n polygonTriangulation.addHole(hole);\n }\n //updatability is set during applyToMesh; setting to true in triangulation build produces errors\n const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);\n polygon._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\n vertexData.applyToMesh(polygon, options.updatable);\n return polygon;\n }\n /**\n * Creates an extruded polygon mesh, with depth in the Y direction.\n * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.shape\n * @param options.holes\n * @param options.depth\n * @param options.faceUV\n * @param options.faceColors\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.wrap\n * @param scene defines the hosting scene\n * @param earcutInjection can be used to inject your own earcut reference\n * @returns the polygon mesh\n */\n function ExtrudePolygon(name, options, scene = null, earcutInjection = earcut) {\n return CreatePolygon(name, options, scene, earcutInjection);\n }\n VertexData.CreatePolygon = CreatePolygonVertexData;\n Mesh.CreatePolygon = (name, shape, scene, holes, updatable, sideOrientation, earcutInjection = earcut) => {\n const options = {\n shape: shape,\n holes: holes,\n updatable: updatable,\n sideOrientation: sideOrientation,\n };\n return CreatePolygon(name, options, scene, earcutInjection);\n };\n Mesh.ExtrudePolygon = (name, shape, depth, scene, holes, updatable, sideOrientation, earcutInjection = earcut) => {\n const options = {\n shape: shape,\n holes: holes,\n depth: depth,\n updatable: updatable,\n sideOrientation: sideOrientation,\n };\n return ExtrudePolygon(name, options, scene, earcutInjection);\n };\n\n /**\n * Creates an extruded shape mesh. The extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.\n * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis.\n * * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.\n * * The parameter `rotation` (float, default 0 radians) is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve.\n * * The parameter `scale` (float, default 1) is the value to scale the shape.\n * * The parameter `closeShape` (boolean, default false) closes the shape when true, since v5.0.0.\n * * The parameter `closePath` (boolean, default false) closes the path when true and no caps, since v5.0.0.\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\n * * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#extruded-shape\n * * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * * The optional parameter `firstNormal` (Vector3) defines the direction of the first normal of the supplied path. Consider using this for any path that is straight, and particular for paths in the xy plane.\n * * The optional `adjustFrame` (boolean, default false) will cause the internally generated Path3D tangents, normals, and binormals to be adjusted so that a) they are always well-defined, and b) they do not reverse from one path point to the next. This prevents the extruded shape from being flipped and/or rotated with resulting mesh self-intersections. This is primarily useful for straight paths that can reverse direction.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.shape\n * @param options.path\n * @param options.scale\n * @param options.rotation\n * @param options.closeShape\n * @param options.closePath\n * @param options.cap\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.instance\n * @param options.invertUV\n * @param options.firstNormal\n * @param options.adjustFrame\n * @param scene defines the hosting scene\n * @returns the extruded shape mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\n */\n function ExtrudeShape(name, options, scene = null) {\n const path = options.path;\n const shape = options.shape;\n const scale = options.scale || 1;\n const rotation = options.rotation || 0;\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.NO_CAP;\n const updatable = options.updatable;\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const instance = options.instance || null;\n const invertUV = options.invertUV || false;\n const closeShape = options.closeShape || false;\n const closePath = options.closePath || false;\n return _ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, closePath, closeShape, cap, false, scene, updatable ? true : false, sideOrientation, instance, invertUV, options.frontUVs || null, options.backUVs || null, options.firstNormal || null, options.adjustFrame ? true : false);\n }\n /**\n * Creates an custom extruded shape mesh.\n * The custom extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.\n * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis.\n * * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.\n * * The parameter `rotationFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path and the distance of this point from the beginning of the path\n * * It must returns a float value that will be the rotation in radians applied to the shape on each path point.\n * * The parameter `scaleFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path and the distance of this point from the beginning of the path\n * * It must returns a float value that will be the scale value applied to the shape on each path point\n * * The parameter `closeShape` (boolean, default false) closes the shape when true, since v5.0.0.\n * * The parameter `closePath` (boolean, default false) closes the path when true and no caps, since v5.0.0.\n * * The parameter `ribbonClosePath` (boolean, default false) forces the extrusion underlying ribbon to close all the paths in its `pathArray` - depreciated in favor of closeShape\n * * The parameter `ribbonCloseArray` (boolean, default false) forces the extrusion underlying ribbon to close its `pathArray` - depreciated in favor of closePath\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\n * * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#extruded-shape\n * * Remember you can only change the shape or path point positions, not their number when updating an extruded shape\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * * The optional parameter `firstNormal` (Vector3) defines the direction of the first normal of the supplied path. It should be supplied when the path is in the xy plane, and particularly if these sections are straight, because the underlying Path3D object will pick a normal in the xy plane that causes the extrusion to be collapsed into the plane. This should be used for any path that is straight.\n * * The optional `adjustFrame` (boolean, default false) will cause the internally generated Path3D tangents, normals, and binormals to be adjusted so that a) they are always well-defined, and b) they do not reverse from one path point to the next. This prevents the extruded shape from being flipped and/or rotated with resulting mesh self-intersections. This is primarily useful for straight paths that can reverse direction.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.shape\n * @param options.path\n * @param options.scaleFunction\n * @param options.rotationFunction\n * @param options.ribbonCloseArray\n * @param options.ribbonClosePath\n * @param options.closeShape\n * @param options.closePath\n * @param options.cap\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.instance\n * @param options.invertUV\n * @param options.firstNormal\n * @param options.adjustFrame\n * @param scene defines the hosting scene\n * @returns the custom extruded shape mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#custom-extruded-shapes\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\n */\n function ExtrudeShapeCustom(name, options, scene = null) {\n const path = options.path;\n const shape = options.shape;\n const scaleFunction = options.scaleFunction ||\n (() => {\n return 1;\n });\n const rotationFunction = options.rotationFunction ||\n (() => {\n return 0;\n });\n const ribbonCloseArray = options.closePath || options.ribbonCloseArray || false;\n const ribbonClosePath = options.closeShape || options.ribbonClosePath || false;\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.NO_CAP;\n const updatable = options.updatable;\n const firstNormal = options.firstNormal || null;\n const adjustFrame = options.adjustFrame || false;\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const instance = options.instance;\n const invertUV = options.invertUV || false;\n return _ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable ? true : false, sideOrientation, instance || null, invertUV, options.frontUVs || null, options.backUVs || null, firstNormal, adjustFrame);\n }\n function _ExtrudeShapeGeneric(name, shape, curve, scale, rotation, scaleFunction, rotateFunction, rbCA, rbCP, cap, custom, scene, updtbl, side, instance, invertUV, frontUVs, backUVs, firstNormal, adjustFrame) {\n // extrusion geometry\n const extrusionPathArray = (shape, curve, path3D, shapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom, adjustFrame) => {\n const tangents = path3D.getTangents();\n const normals = path3D.getNormals();\n const binormals = path3D.getBinormals();\n const distances = path3D.getDistances();\n if (adjustFrame) {\n /* fix tangents,normals, binormals */\n for (let i = 0; i < tangents.length; i++) {\n if (tangents[i].x == 0 && tangents[i].y == 0 && tangents[i].z == 0) {\n tangents[i].copyFrom(tangents[i - 1]);\n }\n if (normals[i].x == 0 && normals[i].y == 0 && normals[i].z == 0) {\n normals[i].copyFrom(normals[i - 1]);\n }\n if (binormals[i].x == 0 && binormals[i].y == 0 && binormals[i].z == 0) {\n binormals[i].copyFrom(binormals[i - 1]);\n }\n if (i > 0) {\n let v = tangents[i - 1];\n if (Vector3.Dot(v, tangents[i]) < 0) {\n tangents[i].scaleInPlace(-1);\n }\n v = normals[i - 1];\n if (Vector3.Dot(v, normals[i]) < 0) {\n normals[i].scaleInPlace(-1);\n }\n v = binormals[i - 1];\n if (Vector3.Dot(v, binormals[i]) < 0) {\n binormals[i].scaleInPlace(-1);\n }\n }\n }\n }\n let angle = 0;\n const returnScale = () => {\n return scale !== null ? scale : 1;\n };\n const returnRotation = () => {\n return rotation !== null ? rotation : 0;\n };\n const rotate = custom && rotateFunction ? rotateFunction : returnRotation;\n const scl = custom && scaleFunction ? scaleFunction : returnScale;\n let index = cap === Mesh.NO_CAP || cap === Mesh.CAP_END ? 0 : 2;\n const rotationMatrix = TmpVectors.Matrix[0];\n for (let i = 0; i < curve.length; i++) {\n const shapePath = new Array();\n const angleStep = rotate(i, distances[i]);\n const scaleRatio = scl(i, distances[i]);\n Matrix.RotationAxisToRef(tangents[i], angle, rotationMatrix);\n for (let p = 0; p < shape.length; p++) {\n const planed = tangents[i].scale(shape[p].z).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y));\n const rotated = Vector3.Zero();\n Vector3.TransformCoordinatesToRef(planed, rotationMatrix, rotated);\n rotated.scaleInPlace(scaleRatio).addInPlace(curve[i]);\n shapePath[p] = rotated;\n }\n shapePaths[index] = shapePath;\n angle += angleStep;\n index++;\n }\n // cap\n const capPath = (shapePath) => {\n const pointCap = Array();\n const barycenter = Vector3.Zero();\n let i;\n for (i = 0; i < shapePath.length; i++) {\n barycenter.addInPlace(shapePath[i]);\n }\n barycenter.scaleInPlace(1.0 / shapePath.length);\n for (i = 0; i < shapePath.length; i++) {\n pointCap.push(barycenter);\n }\n return pointCap;\n };\n switch (cap) {\n case Mesh.NO_CAP:\n break;\n case Mesh.CAP_START:\n shapePaths[0] = capPath(shapePaths[2]);\n shapePaths[1] = shapePaths[2];\n break;\n case Mesh.CAP_END:\n shapePaths[index] = shapePaths[index - 1];\n shapePaths[index + 1] = capPath(shapePaths[index - 1]);\n break;\n case Mesh.CAP_ALL:\n shapePaths[0] = capPath(shapePaths[2]);\n shapePaths[1] = shapePaths[2];\n shapePaths[index] = shapePaths[index - 1];\n shapePaths[index + 1] = capPath(shapePaths[index - 1]);\n break;\n }\n return shapePaths;\n };\n let path3D;\n let pathArray;\n if (instance) {\n // instance update\n const storage = instance._creationDataStorage;\n path3D = firstNormal ? storage.path3D.update(curve, firstNormal) : storage.path3D.update(curve);\n pathArray = extrusionPathArray(shape, curve, storage.path3D, storage.pathArray, scale, rotation, scaleFunction, rotateFunction, storage.cap, custom, adjustFrame);\n instance = CreateRibbon(\"\", { pathArray, closeArray: false, closePath: false, offset: 0, updatable: false, sideOrientation: 0, instance }, scene || undefined);\n return instance;\n }\n // extruded shape creation\n path3D = firstNormal ? new Path3D(curve, firstNormal) : new Path3D(curve);\n const newShapePaths = new Array();\n cap = cap < 0 || cap > 3 ? 0 : cap;\n pathArray = extrusionPathArray(shape, curve, path3D, newShapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom, adjustFrame);\n const extrudedGeneric = CreateRibbon(name, {\n pathArray: pathArray,\n closeArray: rbCA,\n closePath: rbCP,\n updatable: updtbl,\n sideOrientation: side,\n invertUV: invertUV,\n frontUVs: frontUVs || undefined,\n backUVs: backUVs || undefined,\n }, scene);\n extrudedGeneric._creationDataStorage.pathArray = pathArray;\n extrudedGeneric._creationDataStorage.path3D = path3D;\n extrudedGeneric._creationDataStorage.cap = cap;\n return extrudedGeneric;\n }\n Mesh.ExtrudeShape = (name, shape, path, scale, rotation, cap, scene = null, updatable, sideOrientation, instance) => {\n const options = {\n shape: shape,\n path: path,\n scale: scale,\n rotation: rotation,\n cap: cap === 0 ? 0 : cap || Mesh.NO_CAP,\n sideOrientation: sideOrientation,\n instance: instance,\n updatable: updatable,\n };\n return ExtrudeShape(name, options, scene);\n };\n Mesh.ExtrudeShapeCustom = (name, shape, path, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, scene, updatable, sideOrientation, instance) => {\n const options = {\n shape: shape,\n path: path,\n scaleFunction: scaleFunction,\n rotationFunction: rotationFunction,\n ribbonCloseArray: ribbonCloseArray,\n ribbonClosePath: ribbonClosePath,\n cap: cap === 0 ? 0 : cap || Mesh.NO_CAP,\n sideOrientation: sideOrientation,\n instance: instance,\n updatable: updatable,\n };\n return ExtrudeShapeCustom(name, options, scene);\n };\n\n /**\n * Creates lathe mesh.\n * The lathe is a shape with a symmetry axis : a 2D model shape is rotated around this axis to design the lathe\n * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero\n * * The parameter `radius` (positive float, default 1) is the radius value of the lathe\n * * The parameter `tessellation` (positive integer, default 64) is the side number of the lathe\n * * The parameter `clip` (positive integer, default 0) is the number of sides to not create without effecting the general shape of the sides\n * * The parameter `arc` (positive float, default 1) is the ratio of the lathe. 0.5 builds for instance half a lathe, so an opened shape\n * * The parameter `closed` (boolean, default true) opens/closes the lathe circumference. This should be set to false when used with the parameter \"arc\"\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.shape\n * @param options.radius\n * @param options.tessellation\n * @param options.clip\n * @param options.arc\n * @param options.closed\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.cap\n * @param options.invertUV\n * @param scene defines the hosting scene\n * @returns the lathe mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#lathe\n */\n function CreateLathe(name, options, scene = null) {\n const arc = options.arc ? (options.arc <= 0 || options.arc > 1 ? 1.0 : options.arc) : 1.0;\n const closed = options.closed === undefined ? true : options.closed;\n const shape = options.shape;\n const radius = options.radius || 1;\n const tessellation = options.tessellation || 64;\n const clip = options.clip || 0;\n const updatable = options.updatable;\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const cap = options.cap || Mesh.NO_CAP;\n const pi2 = Math.PI * 2;\n const paths = new Array();\n const invertUV = options.invertUV || false;\n let i = 0;\n let p = 0;\n const step = (pi2 / tessellation) * arc;\n let rotated;\n let path;\n for (i = 0; i <= tessellation - clip; i++) {\n path = [];\n if (cap == Mesh.CAP_START || cap == Mesh.CAP_ALL) {\n path.push(new Vector3(0, shape[0].y, 0));\n path.push(new Vector3(Math.cos(i * step) * shape[0].x * radius, shape[0].y, Math.sin(i * step) * shape[0].x * radius));\n }\n for (p = 0; p < shape.length; p++) {\n rotated = new Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y, Math.sin(i * step) * shape[p].x * radius);\n path.push(rotated);\n }\n if (cap == Mesh.CAP_END || cap == Mesh.CAP_ALL) {\n path.push(new Vector3(Math.cos(i * step) * shape[shape.length - 1].x * radius, shape[shape.length - 1].y, Math.sin(i * step) * shape[shape.length - 1].x * radius));\n path.push(new Vector3(0, shape[shape.length - 1].y, 0));\n }\n paths.push(path);\n }\n // lathe ribbon\n const lathe = CreateRibbon(name, { pathArray: paths, closeArray: closed, sideOrientation: sideOrientation, updatable: updatable, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);\n return lathe;\n }\n Mesh.CreateLathe = (name, shape, radius, tessellation, scene, updatable, sideOrientation) => {\n const options = {\n shape: shape,\n radius: radius,\n tessellation: tessellation,\n sideOrientation: sideOrientation,\n updatable: updatable,\n };\n return CreateLathe(name, options, scene);\n };\n\n /**\n * Creates a tube mesh.\n * The tube is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters\n * * The parameter `path` is a required array of successive Vector3. It is the curve used as the axis of the tube\n * * The parameter `radius` (positive float, default 1) sets the tube radius size\n * * The parameter `tessellation` (positive float, default 64) is the number of sides on the tubular surface\n * * The parameter `radiusFunction` (javascript function, default null) is a vanilla javascript function. If it is not null, it overrides the parameter `radius`\n * * This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path. It must return a radius value (positive float)\n * * The parameter `arc` (positive float, maximum 1, default 1) is the ratio to apply to the tube circumference : 2 x PI x arc\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\n * * The optional parameter `instance` is an instance of an existing Tube object to be updated with the passed `pathArray` parameter. The `path`Array HAS to have the SAME number of points as the previous one: https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#tube\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created. The NUMBER of points CAN'T CHANGE, only their positions.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.path\n * @param options.radius\n * @param options.tessellation\n * @param options.radiusFunction\n * @param options.cap\n * @param options.arc\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.instance\n * @param options.invertUV\n * @param scene defines the hosting scene\n * @returns the tube mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#tube\n */\n function CreateTube(name, options, scene = null) {\n const path = options.path;\n let instance = options.instance;\n let radius = 1.0;\n if (options.radius !== undefined) {\n radius = options.radius;\n }\n else if (instance) {\n radius = instance._creationDataStorage.radius;\n }\n const tessellation = options.tessellation || 64 | 0;\n const radiusFunction = options.radiusFunction || null;\n let cap = options.cap || Mesh.NO_CAP;\n const invertUV = options.invertUV || false;\n const updatable = options.updatable;\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n options.arc = options.arc && (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;\n // tube geometry\n const tubePathArray = (path, path3D, circlePaths, radius, tessellation, radiusFunction, cap, arc) => {\n const tangents = path3D.getTangents();\n const normals = path3D.getNormals();\n const distances = path3D.getDistances();\n const pi2 = Math.PI * 2;\n const step = (pi2 / tessellation) * arc;\n const returnRadius = () => radius;\n const radiusFunctionFinal = radiusFunction || returnRadius;\n let circlePath;\n let rad;\n let normal;\n let rotated;\n const rotationMatrix = TmpVectors.Matrix[0];\n let index = cap === Mesh.NO_CAP || cap === Mesh.CAP_END ? 0 : 2;\n for (let i = 0; i < path.length; i++) {\n rad = radiusFunctionFinal(i, distances[i]); // current radius\n circlePath = Array(); // current circle array\n normal = normals[i]; // current normal\n for (let t = 0; t < tessellation; t++) {\n Matrix.RotationAxisToRef(tangents[i], step * t, rotationMatrix);\n rotated = circlePath[t] ? circlePath[t] : Vector3.Zero();\n Vector3.TransformCoordinatesToRef(normal, rotationMatrix, rotated);\n rotated.scaleInPlace(rad).addInPlace(path[i]);\n circlePath[t] = rotated;\n }\n circlePaths[index] = circlePath;\n index++;\n }\n // cap\n const capPath = (nbPoints, pathIndex) => {\n const pointCap = Array();\n for (let i = 0; i < nbPoints; i++) {\n pointCap.push(path[pathIndex]);\n }\n return pointCap;\n };\n switch (cap) {\n case Mesh.NO_CAP:\n break;\n case Mesh.CAP_START:\n circlePaths[0] = capPath(tessellation, 0);\n circlePaths[1] = circlePaths[2].slice(0);\n break;\n case Mesh.CAP_END:\n circlePaths[index] = circlePaths[index - 1].slice(0);\n circlePaths[index + 1] = capPath(tessellation, path.length - 1);\n break;\n case Mesh.CAP_ALL:\n circlePaths[0] = capPath(tessellation, 0);\n circlePaths[1] = circlePaths[2].slice(0);\n circlePaths[index] = circlePaths[index - 1].slice(0);\n circlePaths[index + 1] = capPath(tessellation, path.length - 1);\n break;\n }\n return circlePaths;\n };\n let path3D;\n let pathArray;\n if (instance) {\n // tube update\n const storage = instance._creationDataStorage;\n const arc = options.arc || storage.arc;\n path3D = storage.path3D.update(path);\n pathArray = tubePathArray(path, path3D, storage.pathArray, radius, storage.tessellation, radiusFunction, storage.cap, arc);\n instance = CreateRibbon(\"\", { pathArray: pathArray, instance: instance });\n // Update mode, no need to recreate the storage.\n storage.path3D = path3D;\n storage.pathArray = pathArray;\n storage.arc = arc;\n storage.radius = radius;\n return instance;\n }\n // tube creation\n path3D = new Path3D(path);\n const newPathArray = new Array();\n cap = cap < 0 || cap > 3 ? 0 : cap;\n pathArray = tubePathArray(path, path3D, newPathArray, radius, tessellation, radiusFunction, cap, options.arc);\n const tube = CreateRibbon(name, {\n pathArray: pathArray,\n closePath: true,\n closeArray: false,\n updatable: updatable,\n sideOrientation: sideOrientation,\n invertUV: invertUV,\n frontUVs: options.frontUVs,\n backUVs: options.backUVs,\n }, scene);\n tube._creationDataStorage.pathArray = pathArray;\n tube._creationDataStorage.path3D = path3D;\n tube._creationDataStorage.tessellation = tessellation;\n tube._creationDataStorage.cap = cap;\n tube._creationDataStorage.arc = options.arc;\n tube._creationDataStorage.radius = radius;\n return tube;\n }\n Mesh.CreateTube = (name, path, radius, tessellation, radiusFunction, cap, scene, updatable, sideOrientation, instance) => {\n const options = {\n path: path,\n radius: radius,\n tessellation: tessellation,\n radiusFunction: radiusFunction,\n arc: 1,\n cap: cap,\n updatable: updatable,\n sideOrientation: sideOrientation,\n instance: instance,\n };\n return CreateTube(name, options, scene);\n };\n\n // inspired from // http://stemkoski.github.io/Three.js/Polyhedra.html\n /**\n * Creates the VertexData for a Polyhedron\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\n * * type provided types are:\n * * 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)\n * * 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)\n * * size the size of the IcoSphere, optional default 1\n * * sizeX allows stretching in the x direction, optional, default size\n * * sizeY allows stretching in the y direction, optional, default size\n * * sizeZ allows stretching in the z direction, optional, default size\n * * custom a number that overwrites the type to create from an extended set of polyhedron from https://www.babylonjs-playground.com/#21QRSK#15 with minimised editor\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * * flat when true creates a flat shaded mesh, optional, default true\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.type\n * @param options.size\n * @param options.sizeX\n * @param options.sizeY\n * @param options.sizeZ\n * @param options.custom\n * @param options.faceUV\n * @param options.faceColors\n * @param options.flat\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the Polyhedron\n */\n function CreatePolyhedronVertexData(options) {\n // provided polyhedron types :\n // 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)\n // 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)\n const polyhedra = [];\n polyhedra[0] = {\n vertex: [\n [0, 0, 1.732051],\n [1.632993, 0, -0.5773503],\n [-0.8164966, 1.414214, -0.5773503],\n [-0.8164966, -1.414214, -0.5773503],\n ],\n face: [\n [0, 1, 2],\n [0, 2, 3],\n [0, 3, 1],\n [1, 3, 2],\n ],\n };\n polyhedra[1] = {\n vertex: [\n [0, 0, 1.414214],\n [1.414214, 0, 0],\n [0, 1.414214, 0],\n [-1.414214, 0, 0],\n [0, -1.414214, 0],\n [0, 0, -1.414214],\n ],\n face: [\n [0, 1, 2],\n [0, 2, 3],\n [0, 3, 4],\n [0, 4, 1],\n [1, 4, 5],\n [1, 5, 2],\n [2, 5, 3],\n [3, 5, 4],\n ],\n };\n polyhedra[2] = {\n vertex: [\n [0, 0, 1.070466],\n [0.7136442, 0, 0.7978784],\n [-0.3568221, 0.618034, 0.7978784],\n [-0.3568221, -0.618034, 0.7978784],\n [0.7978784, 0.618034, 0.3568221],\n [0.7978784, -0.618034, 0.3568221],\n [-0.9341724, 0.381966, 0.3568221],\n [0.1362939, 1, 0.3568221],\n [0.1362939, -1, 0.3568221],\n [-0.9341724, -0.381966, 0.3568221],\n [0.9341724, 0.381966, -0.3568221],\n [0.9341724, -0.381966, -0.3568221],\n [-0.7978784, 0.618034, -0.3568221],\n [-0.1362939, 1, -0.3568221],\n [-0.1362939, -1, -0.3568221],\n [-0.7978784, -0.618034, -0.3568221],\n [0.3568221, 0.618034, -0.7978784],\n [0.3568221, -0.618034, -0.7978784],\n [-0.7136442, 0, -0.7978784],\n [0, 0, -1.070466],\n ],\n face: [\n [0, 1, 4, 7, 2],\n [0, 2, 6, 9, 3],\n [0, 3, 8, 5, 1],\n [1, 5, 11, 10, 4],\n [2, 7, 13, 12, 6],\n [3, 9, 15, 14, 8],\n [4, 10, 16, 13, 7],\n [5, 8, 14, 17, 11],\n [6, 12, 18, 15, 9],\n [10, 11, 17, 19, 16],\n [12, 13, 16, 19, 18],\n [14, 15, 18, 19, 17],\n ],\n };\n polyhedra[3] = {\n vertex: [\n [0, 0, 1.175571],\n [1.051462, 0, 0.5257311],\n [0.3249197, 1, 0.5257311],\n [-0.8506508, 0.618034, 0.5257311],\n [-0.8506508, -0.618034, 0.5257311],\n [0.3249197, -1, 0.5257311],\n [0.8506508, 0.618034, -0.5257311],\n [0.8506508, -0.618034, -0.5257311],\n [-0.3249197, 1, -0.5257311],\n [-1.051462, 0, -0.5257311],\n [-0.3249197, -1, -0.5257311],\n [0, 0, -1.175571],\n ],\n face: [\n [0, 1, 2],\n [0, 2, 3],\n [0, 3, 4],\n [0, 4, 5],\n [0, 5, 1],\n [1, 5, 7],\n [1, 7, 6],\n [1, 6, 2],\n [2, 6, 8],\n [2, 8, 3],\n [3, 8, 9],\n [3, 9, 4],\n [4, 9, 10],\n [4, 10, 5],\n [5, 10, 7],\n [6, 7, 11],\n [6, 11, 8],\n [7, 10, 11],\n [8, 11, 9],\n [9, 11, 10],\n ],\n };\n polyhedra[4] = {\n vertex: [\n [0, 0, 1.070722],\n [0.7148135, 0, 0.7971752],\n [-0.104682, 0.7071068, 0.7971752],\n [-0.6841528, 0.2071068, 0.7971752],\n [-0.104682, -0.7071068, 0.7971752],\n [0.6101315, 0.7071068, 0.5236279],\n [1.04156, 0.2071068, 0.1367736],\n [0.6101315, -0.7071068, 0.5236279],\n [-0.3574067, 1, 0.1367736],\n [-0.7888348, -0.5, 0.5236279],\n [-0.9368776, 0.5, 0.1367736],\n [-0.3574067, -1, 0.1367736],\n [0.3574067, 1, -0.1367736],\n [0.9368776, -0.5, -0.1367736],\n [0.7888348, 0.5, -0.5236279],\n [0.3574067, -1, -0.1367736],\n [-0.6101315, 0.7071068, -0.5236279],\n [-1.04156, -0.2071068, -0.1367736],\n [-0.6101315, -0.7071068, -0.5236279],\n [0.104682, 0.7071068, -0.7971752],\n [0.6841528, -0.2071068, -0.7971752],\n [0.104682, -0.7071068, -0.7971752],\n [-0.7148135, 0, -0.7971752],\n [0, 0, -1.070722],\n ],\n face: [\n [0, 2, 3],\n [1, 6, 5],\n [4, 9, 11],\n [7, 15, 13],\n [8, 16, 10],\n [12, 14, 19],\n [17, 22, 18],\n [20, 21, 23],\n [0, 1, 5, 2],\n [0, 3, 9, 4],\n [0, 4, 7, 1],\n [1, 7, 13, 6],\n [2, 5, 12, 8],\n [2, 8, 10, 3],\n [3, 10, 17, 9],\n [4, 11, 15, 7],\n [5, 6, 14, 12],\n [6, 13, 20, 14],\n [8, 12, 19, 16],\n [9, 17, 18, 11],\n [10, 16, 22, 17],\n [11, 18, 21, 15],\n [13, 15, 21, 20],\n [14, 20, 23, 19],\n [16, 19, 23, 22],\n [18, 22, 23, 21],\n ],\n };\n polyhedra[5] = {\n vertex: [\n [0, 0, 1.322876],\n [1.309307, 0, 0.1889822],\n [-0.9819805, 0.8660254, 0.1889822],\n [0.1636634, -1.299038, 0.1889822],\n [0.3273268, 0.8660254, -0.9449112],\n [-0.8183171, -0.4330127, -0.9449112],\n ],\n face: [\n [0, 3, 1],\n [2, 4, 5],\n [0, 1, 4, 2],\n [0, 2, 5, 3],\n [1, 3, 5, 4],\n ],\n };\n polyhedra[6] = {\n vertex: [\n [0, 0, 1.159953],\n [1.013464, 0, 0.5642542],\n [-0.3501431, 0.9510565, 0.5642542],\n [-0.7715208, -0.6571639, 0.5642542],\n [0.6633206, 0.9510565, -0.03144481],\n [0.8682979, -0.6571639, -0.3996071],\n [-1.121664, 0.2938926, -0.03144481],\n [-0.2348831, -1.063314, -0.3996071],\n [0.5181548, 0.2938926, -0.9953061],\n [-0.5850262, -0.112257, -0.9953061],\n ],\n face: [\n [0, 1, 4, 2],\n [0, 2, 6, 3],\n [1, 5, 8, 4],\n [3, 6, 9, 7],\n [5, 7, 9, 8],\n [0, 3, 7, 5, 1],\n [2, 4, 8, 9, 6],\n ],\n };\n polyhedra[7] = {\n vertex: [\n [0, 0, 1.118034],\n [0.8944272, 0, 0.6708204],\n [-0.2236068, 0.8660254, 0.6708204],\n [-0.7826238, -0.4330127, 0.6708204],\n [0.6708204, 0.8660254, 0.2236068],\n [1.006231, -0.4330127, -0.2236068],\n [-1.006231, 0.4330127, 0.2236068],\n [-0.6708204, -0.8660254, -0.2236068],\n [0.7826238, 0.4330127, -0.6708204],\n [0.2236068, -0.8660254, -0.6708204],\n [-0.8944272, 0, -0.6708204],\n [0, 0, -1.118034],\n ],\n face: [\n [0, 1, 4, 2],\n [0, 2, 6, 3],\n [1, 5, 8, 4],\n [3, 6, 10, 7],\n [5, 9, 11, 8],\n [7, 10, 11, 9],\n [0, 3, 7, 9, 5, 1],\n [2, 4, 8, 11, 10, 6],\n ],\n };\n polyhedra[8] = {\n vertex: [\n [-0.729665, 0.670121, 0.319155],\n [-0.655235, -0.29213, -0.754096],\n [-0.093922, -0.607123, 0.537818],\n [0.702196, 0.595691, 0.485187],\n [0.776626, -0.36656, -0.588064],\n ],\n face: [\n [1, 4, 2],\n [0, 1, 2],\n [3, 0, 2],\n [4, 3, 2],\n [4, 1, 0, 3],\n ],\n };\n polyhedra[9] = {\n vertex: [\n [-0.868849, -0.100041, 0.61257],\n [-0.329458, 0.976099, 0.28078],\n [-0.26629, -0.013796, -0.477654],\n [-0.13392, -1.034115, 0.229829],\n [0.738834, 0.707117, -0.307018],\n [0.859683, -0.535264, -0.338508],\n ],\n face: [\n [3, 0, 2],\n [5, 3, 2],\n [4, 5, 2],\n [1, 4, 2],\n [0, 1, 2],\n [0, 3, 5, 4, 1],\n ],\n };\n polyhedra[10] = {\n vertex: [\n [-0.610389, 0.243975, 0.531213],\n [-0.187812, -0.48795, -0.664016],\n [-0.187812, 0.9759, -0.664016],\n [0.187812, -0.9759, 0.664016],\n [0.798201, 0.243975, 0.132803],\n ],\n face: [\n [1, 3, 0],\n [3, 4, 0],\n [3, 1, 4],\n [0, 2, 1],\n [0, 4, 2],\n [2, 4, 1],\n ],\n };\n polyhedra[11] = {\n vertex: [\n [-1.028778, 0.392027, -0.048786],\n [-0.640503, -0.646161, 0.621837],\n [-0.125162, -0.395663, -0.540059],\n [0.004683, 0.888447, -0.651988],\n [0.125161, 0.395663, 0.540059],\n [0.632925, -0.791376, 0.433102],\n [1.031672, 0.157063, -0.354165],\n ],\n face: [\n [3, 2, 0],\n [2, 1, 0],\n [2, 5, 1],\n [0, 4, 3],\n [0, 1, 4],\n [4, 1, 5],\n [2, 3, 6],\n [3, 4, 6],\n [5, 2, 6],\n [4, 5, 6],\n ],\n };\n polyhedra[12] = {\n vertex: [\n [-0.669867, 0.334933, -0.529576],\n [-0.669867, 0.334933, 0.529577],\n [-0.4043, 1.212901, 0],\n [-0.334933, -0.669867, -0.529576],\n [-0.334933, -0.669867, 0.529577],\n [0.334933, 0.669867, -0.529576],\n [0.334933, 0.669867, 0.529577],\n [0.4043, -1.212901, 0],\n [0.669867, -0.334933, -0.529576],\n [0.669867, -0.334933, 0.529577],\n ],\n face: [\n [8, 9, 7],\n [6, 5, 2],\n [3, 8, 7],\n [5, 0, 2],\n [4, 3, 7],\n [0, 1, 2],\n [9, 4, 7],\n [1, 6, 2],\n [9, 8, 5, 6],\n [8, 3, 0, 5],\n [3, 4, 1, 0],\n [4, 9, 6, 1],\n ],\n };\n polyhedra[13] = {\n vertex: [\n [-0.931836, 0.219976, -0.264632],\n [-0.636706, 0.318353, 0.692816],\n [-0.613483, -0.735083, -0.264632],\n [-0.326545, 0.979634, 0],\n [-0.318353, -0.636706, 0.692816],\n [-0.159176, 0.477529, -0.856368],\n [0.159176, -0.477529, -0.856368],\n [0.318353, 0.636706, 0.692816],\n [0.326545, -0.979634, 0],\n [0.613482, 0.735082, -0.264632],\n [0.636706, -0.318353, 0.692816],\n [0.931835, -0.219977, -0.264632],\n ],\n face: [\n [11, 10, 8],\n [7, 9, 3],\n [6, 11, 8],\n [9, 5, 3],\n [2, 6, 8],\n [5, 0, 3],\n [4, 2, 8],\n [0, 1, 3],\n [10, 4, 8],\n [1, 7, 3],\n [10, 11, 9, 7],\n [11, 6, 5, 9],\n [6, 2, 0, 5],\n [2, 4, 1, 0],\n [4, 10, 7, 1],\n ],\n };\n polyhedra[14] = {\n vertex: [\n [-0.93465, 0.300459, -0.271185],\n [-0.838689, -0.260219, -0.516017],\n [-0.711319, 0.717591, 0.128359],\n [-0.710334, -0.156922, 0.080946],\n [-0.599799, 0.556003, -0.725148],\n [-0.503838, -0.004675, -0.969981],\n [-0.487004, 0.26021, 0.48049],\n [-0.460089, -0.750282, -0.512622],\n [-0.376468, 0.973135, -0.325605],\n [-0.331735, -0.646985, 0.084342],\n [-0.254001, 0.831847, 0.530001],\n [-0.125239, -0.494738, -0.966586],\n [0.029622, 0.027949, 0.730817],\n [0.056536, -0.982543, -0.262295],\n [0.08085, 1.087391, 0.076037],\n [0.125583, -0.532729, 0.485984],\n [0.262625, 0.599586, 0.780328],\n [0.391387, -0.726999, -0.716259],\n [0.513854, -0.868287, 0.139347],\n [0.597475, 0.85513, 0.326364],\n [0.641224, 0.109523, 0.783723],\n [0.737185, -0.451155, 0.538891],\n [0.848705, -0.612742, -0.314616],\n [0.976075, 0.365067, 0.32976],\n [1.072036, -0.19561, 0.084927],\n ],\n face: [\n [15, 18, 21],\n [12, 20, 16],\n [6, 10, 2],\n [3, 0, 1],\n [9, 7, 13],\n [2, 8, 4, 0],\n [0, 4, 5, 1],\n [1, 5, 11, 7],\n [7, 11, 17, 13],\n [13, 17, 22, 18],\n [18, 22, 24, 21],\n [21, 24, 23, 20],\n [20, 23, 19, 16],\n [16, 19, 14, 10],\n [10, 14, 8, 2],\n [15, 9, 13, 18],\n [12, 15, 21, 20],\n [6, 12, 16, 10],\n [3, 6, 2, 0],\n [9, 3, 1, 7],\n [9, 15, 12, 6, 3],\n [22, 17, 11, 5, 4, 8, 14, 19, 23, 24],\n ],\n };\n const type = options.type && (options.type < 0 || options.type >= polyhedra.length) ? 0 : options.type || 0;\n const size = options.size;\n const sizeX = options.sizeX || size || 1;\n const sizeY = options.sizeY || size || 1;\n const sizeZ = options.sizeZ || size || 1;\n const data = options.custom || polyhedra[type];\n const nbfaces = data.face.length;\n const faceUV = options.faceUV || new Array(nbfaces);\n const faceColors = options.faceColors;\n const flat = options.flat === undefined ? true : options.flat;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const positions = new Array();\n const indices = new Array();\n const normals = new Array();\n const uvs = new Array();\n const colors = new Array();\n let index = 0;\n let faceIdx = 0; // face cursor in the array \"indexes\"\n const indexes = new Array();\n let i = 0;\n let f = 0;\n let u, v, ang, x, y, tmp;\n // default face colors and UV if undefined\n if (flat) {\n for (f = 0; f < nbfaces; f++) {\n if (faceColors && faceColors[f] === undefined) {\n faceColors[f] = new Color4(1, 1, 1, 1);\n }\n if (faceUV && faceUV[f] === undefined) {\n faceUV[f] = new Vector4(0, 0, 1, 1);\n }\n }\n }\n if (!flat) {\n for (i = 0; i < data.vertex.length; i++) {\n positions.push(data.vertex[i][0] * sizeX, data.vertex[i][1] * sizeY, data.vertex[i][2] * sizeZ);\n uvs.push(0, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 : 0);\n }\n for (f = 0; f < nbfaces; f++) {\n for (i = 0; i < data.face[f].length - 2; i++) {\n indices.push(data.face[f][0], data.face[f][i + 2], data.face[f][i + 1]);\n }\n }\n }\n else {\n for (f = 0; f < nbfaces; f++) {\n const fl = data.face[f].length; // number of vertices of the current face\n ang = (2 * Math.PI) / fl;\n x = 0.5 * Math.tan(ang / 2);\n y = 0.5;\n // positions, uvs, colors\n for (i = 0; i < fl; i++) {\n // positions\n positions.push(data.vertex[data.face[f][i]][0] * sizeX, data.vertex[data.face[f][i]][1] * sizeY, data.vertex[data.face[f][i]][2] * sizeZ);\n indexes.push(index);\n index++;\n // uvs\n u = faceUV[f].x + (faceUV[f].z - faceUV[f].x) * (0.5 + x);\n v = faceUV[f].y + (faceUV[f].w - faceUV[f].y) * (y - 0.5);\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - v : v);\n tmp = x * Math.cos(ang) - y * Math.sin(ang);\n y = x * Math.sin(ang) + y * Math.cos(ang);\n x = tmp;\n // colors\n if (faceColors) {\n colors.push(faceColors[f].r, faceColors[f].g, faceColors[f].b, faceColors[f].a);\n }\n }\n // indices from indexes\n for (i = 0; i < fl - 2; i++) {\n indices.push(indexes[0 + faceIdx], indexes[i + 2 + faceIdx], indexes[i + 1 + faceIdx]);\n }\n faceIdx += fl;\n }\n }\n VertexData.ComputeNormals(positions, indices, normals);\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n const vertexData = new VertexData();\n vertexData.positions = positions;\n vertexData.indices = indices;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n if (faceColors && flat) {\n vertexData.colors = colors;\n }\n return vertexData;\n }\n /**\n * Creates a polyhedron mesh\n * * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embbeded types. Please refer to the type sheet in the tutorial to choose the wanted type\n * * The parameter `size` (positive float, default 1) sets the polygon size\n * * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value)\n * * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overrides the parameter `type`\n * * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron\n * * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`)\n * * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\n * * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.type\n * @param options.size\n * @param options.sizeX\n * @param options.sizeY\n * @param options.sizeZ\n * @param options.custom\n * @param options.faceUV\n * @param options.faceColors\n * @param options.flat\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the polyhedron mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra\n */\n function CreatePolyhedron(name, options = {}, scene = null) {\n const polyhedron = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n polyhedron._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreatePolyhedronVertexData(options);\n vertexData.applyToMesh(polyhedron, options.updatable);\n return polyhedron;\n }\n /**\n * Class containing static functions to help procedurally build meshes\n * @deprecated use the function directly from the module\n */\n const PolyhedronBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreatePolyhedron,\n };\n VertexData.CreatePolyhedron = CreatePolyhedronVertexData;\n Mesh.CreatePolyhedron = (name, options, scene) => {\n return CreatePolyhedron(name, options, scene);\n };\n\n /**\n * Creates the VertexData of the IcoSphere\n * @param options an object used to set the following optional parameters for the IcoSphere, required but can be empty\n * * radius the radius of the IcoSphere, optional default 1\n * * radiusX allows stretching in the x direction, optional, default radius\n * * radiusY allows stretching in the y direction, optional, default radius\n * * radiusZ allows stretching in the z direction, optional, default radius\n * * flat when true creates a flat shaded mesh, optional, default true\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.radius\n * @param options.radiusX\n * @param options.radiusY\n * @param options.radiusZ\n * @param options.flat\n * @param options.subdivisions\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the IcoSphere\n */\n function CreateIcoSphereVertexData(options) {\n const sideOrientation = options.sideOrientation || VertexData.DEFAULTSIDE;\n const radius = options.radius || 1;\n const flat = options.flat === undefined ? true : options.flat;\n const subdivisions = (options.subdivisions || 4) | 0;\n const radiusX = options.radiusX || radius;\n const radiusY = options.radiusY || radius;\n const radiusZ = options.radiusZ || radius;\n const t = (1 + Math.sqrt(5)) / 2;\n // 12 vertex x,y,z\n const icoVertices = [\n -1,\n t,\n -0,\n 1,\n t,\n 0,\n -1,\n -t,\n 0,\n 1,\n -t,\n 0,\n 0,\n -1,\n -t,\n 0,\n 1,\n -t,\n 0,\n -1,\n t,\n 0,\n 1,\n t,\n t,\n 0,\n 1,\n t,\n 0,\n -1,\n -t,\n 0,\n 1,\n -t,\n 0,\n -1, // v8-11\n ];\n // index of 3 vertex makes a face of icopshere\n const ico_indices = [\n 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 12, 22, 23, 1, 5, 20, 5, 11, 4, 23, 22, 13, 22, 18, 6, 7, 1, 8, 14, 21, 4, 14, 4, 2, 16, 13, 6, 15, 6, 19, 3, 8, 9, 4, 21, 5, 13, 17,\n 23, 6, 13, 22, 19, 6, 18, 9, 8, 1,\n ];\n // vertex for uv have aliased position, not for UV\n const vertices_unalias_id = [\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10,\n 11,\n // vertex alias\n 0,\n 2,\n 3,\n 3,\n 3,\n 4,\n 7,\n 8,\n 9,\n 9,\n 10,\n 11, // 23: B + 12\n ];\n // uv as integer step (not pixels !)\n const ico_vertexuv = [\n 5,\n 1,\n 3,\n 1,\n 6,\n 4,\n 0,\n 0,\n 5,\n 3,\n 4,\n 2,\n 2,\n 2,\n 4,\n 0,\n 2,\n 0,\n 1,\n 1,\n 6,\n 0,\n 6,\n 2,\n // vertex alias (for same vertex on different faces)\n 0,\n 4,\n 3,\n 3,\n 4,\n 4,\n 3,\n 1,\n 4,\n 2,\n 4,\n 4,\n 0,\n 2,\n 1,\n 1,\n 2,\n 2,\n 3,\n 3,\n 1,\n 3,\n 2,\n 4, // 23: B + 12\n ];\n // Vertices[0, 1, ...9, A, B] : position on UV plane\n // '+' indicate duplicate position to be fixed (3,9:0,2,3,4,7,8,A,B)\n // First island of uv mapping\n // v = 4h 3+ 2\n // v = 3h 9+ 4\n // v = 2h 9+ 5 B\n // v = 1h 9 1 0\n // v = 0h 3 8 7 A\n // u = 0 1 2 3 4 5 6 *a\n // Second island of uv mapping\n // v = 4h 0+ B+ 4+\n // v = 3h A+ 2+\n // v = 2h 7+ 6 3+\n // v = 1h 8+ 3+\n // v = 0h\n // u = 0 1 2 3 4 5 6 *a\n // Face layout on texture UV mapping\n // ============\n // \\ 4 /\\ 16 / ======\n // \\ / \\ / /\\ 11 /\n // \\/ 7 \\/ / \\ /\n // ======= / 10 \\/\n // /\\ 17 /\\ =======\n // / \\ / \\ \\ 15 /\\\n // / 8 \\/ 12 \\ \\ / \\\n // ============ \\/ 6 \\\n // \\ 18 /\\ ============\n // \\ / \\ \\ 5 /\\ 0 /\n // \\/ 13 \\ \\ / \\ /\n // ======= \\/ 1 \\/\n // =============\n // /\\ 19 /\\ 2 /\\\n // / \\ / \\ / \\\n // / 14 \\/ 9 \\/ 3 \\\n // ===================\n // uv step is u:1 or 0.5, v:cos(30)=sqrt(3)/2, ratio approx is 84/97\n const ustep = 138 / 1024;\n const vstep = 239 / 1024;\n const uoffset = 60 / 1024;\n const voffset = 26 / 1024;\n // Second island should have margin, not to touch the first island\n // avoid any borderline artefact in pixel rounding\n const island_u_offset = -40 / 1024;\n const island_v_offset = +20 / 1024;\n // face is either island 0 or 1 :\n // second island is for faces : [4, 7, 8, 12, 13, 16, 17, 18]\n const island = [\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 1,\n 0, // 15 - 19\n ];\n const indices = new Array();\n const positions = new Array();\n const normals = new Array();\n const uvs = new Array();\n let current_indice = 0;\n // prepare array of 3 vector (empty) (to be worked in place, shared for each face)\n const face_vertex_pos = new Array(3);\n const face_vertex_uv = new Array(3);\n let v012;\n for (v012 = 0; v012 < 3; v012++) {\n face_vertex_pos[v012] = Vector3.Zero();\n face_vertex_uv[v012] = Vector2.Zero();\n }\n // create all with normals\n for (let face = 0; face < 20; face++) {\n // 3 vertex per face\n for (v012 = 0; v012 < 3; v012++) {\n // look up vertex 0,1,2 to its index in 0 to 11 (or 23 including alias)\n const v_id = ico_indices[3 * face + v012];\n // vertex have 3D position (x,y,z)\n face_vertex_pos[v012].copyFromFloats(icoVertices[3 * vertices_unalias_id[v_id]], icoVertices[3 * vertices_unalias_id[v_id] + 1], icoVertices[3 * vertices_unalias_id[v_id] + 2]);\n // Normalize to get normal\n face_vertex_pos[v012].normalize();\n // uv Coordinates from vertex ID\n face_vertex_uv[v012].copyFromFloats(ico_vertexuv[2 * v_id] * ustep + uoffset + island[face] * island_u_offset, ico_vertexuv[2 * v_id + 1] * vstep + voffset + island[face] * island_v_offset);\n }\n // Subdivide the face (interpolate pos, norm, uv)\n // - pos is linear interpolation, then projected to sphere (converge polyhedron to sphere)\n // - norm is linear interpolation of vertex corner normal\n // (to be checked if better to re-calc from face vertex, or if approximation is OK ??? )\n // - uv is linear interpolation\n //\n // Topology is as below for sub-divide by 2\n // vertex shown as v0,v1,v2\n // interp index is i1 to progress in range [v0,v1[\n // interp index is i2 to progress in range [v0,v2[\n // face index as (i1,i2) for /\\ : (i1,i2),(i1+1,i2),(i1,i2+1)\n // and (i1,i2)' for \\/ : (i1+1,i2),(i1+1,i2+1),(i1,i2+1)\n //\n //\n // i2 v2\n // ^ ^\n // / / \\\n // / / \\\n // / / \\\n // / / (0,1) \\\n // / #---------\\\n // / / \\ (0,0)'/ \\\n // / / \\ / \\\n // / / \\ / \\\n // / / (0,0) \\ / (1,0) \\\n // / #---------#---------\\\n // v0 v1\n //\n // --------------------> i1\n //\n // interp of (i1,i2):\n // along i2 : x0=lerp(v0,v2, i2/S) <---> x1=lerp(v1,v2, i2/S)\n // along i1 : lerp(x0,x1, i1/(S-i2))\n //\n // centroid of triangle is needed to get help normal computation\n // (c1,c2) are used for centroid location\n const interp_vertex = (i1, i2, c1, c2) => {\n // vertex is interpolated from\n // - face_vertex_pos[0..2]\n // - face_vertex_uv[0..2]\n const pos_x0 = Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], i2 / subdivisions);\n const pos_x1 = Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], i2 / subdivisions);\n const pos_interp = subdivisions === i2 ? face_vertex_pos[2] : Vector3.Lerp(pos_x0, pos_x1, i1 / (subdivisions - i2));\n pos_interp.normalize();\n let vertex_normal;\n if (flat) {\n // in flat mode, recalculate normal as face centroid normal\n const centroid_x0 = Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], c2 / subdivisions);\n const centroid_x1 = Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], c2 / subdivisions);\n vertex_normal = Vector3.Lerp(centroid_x0, centroid_x1, c1 / (subdivisions - c2));\n }\n else {\n // in smooth mode, recalculate normal from each single vertex position\n vertex_normal = new Vector3(pos_interp.x, pos_interp.y, pos_interp.z);\n }\n // Vertex normal need correction due to X,Y,Z radius scaling\n vertex_normal.x /= radiusX;\n vertex_normal.y /= radiusY;\n vertex_normal.z /= radiusZ;\n vertex_normal.normalize();\n const uv_x0 = Vector2.Lerp(face_vertex_uv[0], face_vertex_uv[2], i2 / subdivisions);\n const uv_x1 = Vector2.Lerp(face_vertex_uv[1], face_vertex_uv[2], i2 / subdivisions);\n const uv_interp = subdivisions === i2 ? face_vertex_uv[2] : Vector2.Lerp(uv_x0, uv_x1, i1 / (subdivisions - i2));\n positions.push(pos_interp.x * radiusX, pos_interp.y * radiusY, pos_interp.z * radiusZ);\n normals.push(vertex_normal.x, vertex_normal.y, vertex_normal.z);\n uvs.push(uv_interp.x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - uv_interp.y : uv_interp.y);\n // push each vertex has member of a face\n // Same vertex can belong to multiple face, it is pushed multiple time (duplicate vertex are present)\n indices.push(current_indice);\n current_indice++;\n };\n for (let i2 = 0; i2 < subdivisions; i2++) {\n for (let i1 = 0; i1 + i2 < subdivisions; i1++) {\n // face : (i1,i2) for /\\ :\n // interp for : (i1,i2),(i1+1,i2),(i1,i2+1)\n interp_vertex(i1, i2, i1 + 1.0 / 3, i2 + 1.0 / 3);\n interp_vertex(i1 + 1, i2, i1 + 1.0 / 3, i2 + 1.0 / 3);\n interp_vertex(i1, i2 + 1, i1 + 1.0 / 3, i2 + 1.0 / 3);\n if (i1 + i2 + 1 < subdivisions) {\n // face : (i1,i2)' for \\/ :\n // interp for (i1+1,i2),(i1+1,i2+1),(i1,i2+1)\n interp_vertex(i1 + 1, i2, i1 + 2.0 / 3, i2 + 2.0 / 3);\n interp_vertex(i1 + 1, i2 + 1, i1 + 2.0 / 3, i2 + 2.0 / 3);\n interp_vertex(i1, i2 + 1, i1 + 2.0 / 3, i2 + 2.0 / 3);\n }\n }\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided\n * * The parameter `radius` sets the radius size (float) of the icosphere (default 1)\n * * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value of `radius`)\n * * The parameter `subdivisions` sets the number of subdivisions (positive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size\n * * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.radius\n * @param options.radiusX\n * @param options.radiusY\n * @param options.radiusZ\n * @param options.flat\n * @param options.subdivisions\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.updatable\n * @param scene defines the hosting scene\n * @returns the icosahedron mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra#icosphere\n */\n function CreateIcoSphere(name, options = {}, scene = null) {\n const sphere = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n sphere._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateIcoSphereVertexData(options);\n vertexData.applyToMesh(sphere, options.updatable);\n return sphere;\n }\n VertexData.CreateIcoSphere = CreateIcoSphereVertexData;\n Mesh.CreateIcoSphere = (name, options, scene) => {\n return CreateIcoSphere(name, options, scene);\n };\n\n const xpAxis = new Vector3(1, 0, 0);\n const xnAxis = new Vector3(-1, 0, 0);\n const ypAxis = new Vector3(0, 1, 0);\n const ynAxis = new Vector3(0, -1, 0);\n const zpAxis = new Vector3(0, 0, 1);\n const znAxis = new Vector3(0, 0, -1);\n /** @internal */\n class DecalVertex {\n constructor(position = Vector3.Zero(), normal = Vector3.Up(), uv = Vector2.Zero(), vertexIdx = 0, vertexIdxForBones = 0, localPositionOverride = null, localNormalOverride = null, matrixIndicesOverride = null, matrixWeightsOverride = null) {\n this.position = position;\n this.normal = normal;\n this.uv = uv;\n this.vertexIdx = vertexIdx;\n this.vertexIdxForBones = vertexIdxForBones;\n this.localPositionOverride = localPositionOverride;\n this.localNormalOverride = localNormalOverride;\n this.matrixIndicesOverride = matrixIndicesOverride;\n this.matrixWeightsOverride = matrixWeightsOverride;\n }\n clone() {\n var _a, _b, _c, _d;\n return new DecalVertex(this.position.clone(), this.normal.clone(), this.uv.clone(), this.vertexIdx, this.vertexIdxForBones, (_a = this.localPositionOverride) === null || _a === void 0 ? void 0 : _a.slice(), (_b = this.localNormalOverride) === null || _b === void 0 ? void 0 : _b.slice(), (_c = this.matrixIndicesOverride) === null || _c === void 0 ? void 0 : _c.slice(), (_d = this.matrixWeightsOverride) === null || _d === void 0 ? void 0 : _d.slice());\n }\n }\n /**\n * Creates a decal mesh.\n * A decal is a mesh usually applied as a model onto the surface of another mesh. So don't forget the parameter `sourceMesh` depicting the decal\n * * The parameter `position` (Vector3, default `(0, 0, 0)`) sets the position of the decal in World coordinates\n * * The parameter `normal` (Vector3, default `Vector3.Up`) sets the normal of the mesh where the decal is applied onto in World coordinates\n * * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling\n * * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal\n * * The parameter `captureUVS` defines if we need to capture the uvs or compute them\n * * The parameter `cullBackFaces` defines if the back faces should be removed from the decal mesh\n * * The parameter `localMode` defines that the computations should be done with the local mesh coordinates instead of the world space coordinates.\n * * Use this mode if you want the decal to be parented to the sourceMesh and move/rotate with it.\n * Note: Meshes with morph targets are not supported!\n * @param name defines the name of the mesh\n * @param sourceMesh defines the mesh where the decal must be applied\n * @param options defines the options used to create the mesh\n * @param options.position\n * @param options.normal\n * @param options.size\n * @param options.angle\n * @param options.captureUVS\n * @param options.cullBackFaces\n * @param options.localMode\n * @returns the decal mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/decals\n */\n function CreateDecal(name, sourceMesh, options) {\n var _a, _b, _c, _d;\n const hasSkeleton = !!sourceMesh.skeleton;\n const useLocalComputation = options.localMode || hasSkeleton;\n const meshHasOverridenMaterial = sourceMesh.overrideMaterialSideOrientation !== null && sourceMesh.overrideMaterialSideOrientation !== undefined;\n const indices = sourceMesh.getIndices();\n const positions = hasSkeleton ? sourceMesh.getPositionData(true, true) : sourceMesh.getVerticesData(VertexBuffer.PositionKind);\n const normals = hasSkeleton ? sourceMesh.getNormalsData(true, true) : sourceMesh.getVerticesData(VertexBuffer.NormalKind);\n const localPositions = useLocalComputation ? (hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.PositionKind) : positions) : null;\n const localNormals = useLocalComputation ? (hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.NormalKind) : normals) : null;\n const uvs = sourceMesh.getVerticesData(VertexBuffer.UVKind);\n const matIndices = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesIndicesKind) : null;\n const matWeights = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesWeightsKind) : null;\n const matIndicesExtra = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;\n const matWeightsExtra = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;\n const position = options.position || Vector3.Zero();\n let normal = options.normal || Vector3.Up();\n const size = options.size || Vector3.One();\n const angle = options.angle || 0;\n // Getting correct rotation\n if (!normal) {\n const target = new Vector3(0, 0, 1);\n const camera = sourceMesh.getScene().activeCamera;\n const cameraWorldTarget = Vector3.TransformCoordinates(target, camera.getWorldMatrix());\n normal = camera.globalPosition.subtract(cameraWorldTarget);\n }\n const yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;\n const len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);\n const pitch = Math.atan2(normal.y, len);\n const vertexData = new VertexData();\n vertexData.indices = [];\n vertexData.positions = [];\n vertexData.normals = [];\n vertexData.uvs = [];\n vertexData.matricesIndices = hasSkeleton ? [] : null;\n vertexData.matricesWeights = hasSkeleton ? [] : null;\n vertexData.matricesIndicesExtra = matIndicesExtra ? [] : null;\n vertexData.matricesWeightsExtra = matWeightsExtra ? [] : null;\n let currentVertexDataIndex = 0;\n const extractDecalVector3 = (indexId, transformMatrix) => {\n const result = new DecalVertex();\n if (!indices || !positions || !normals) {\n return result;\n }\n const vertexId = indices[indexId];\n result.vertexIdx = vertexId * 3;\n result.vertexIdxForBones = vertexId * 4;\n // Send vector to decal local world\n result.position = new Vector3(positions[vertexId * 3], positions[vertexId * 3 + 1], positions[vertexId * 3 + 2]);\n Vector3.TransformCoordinatesToRef(result.position, transformMatrix, result.position);\n // Get normal\n result.normal = new Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);\n Vector3.TransformNormalToRef(result.normal, transformMatrix, result.normal);\n if (options.captureUVS && uvs) {\n const v = uvs[vertexId * 2 + 1];\n result.uv = new Vector2(uvs[vertexId * 2], CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n }\n return result;\n };\n const emptyArray = [0, 0, 0, 0];\n // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js\n const clip = (vertices, axis) => {\n if (vertices.length === 0) {\n return vertices;\n }\n const clipSize = 0.5 * Math.abs(Vector3.Dot(size, axis));\n const indexOf = (arr, val, start, num) => {\n for (let i = 0; i < num; ++i) {\n if (arr[start + i] === val) {\n return start + i;\n }\n }\n return -1;\n };\n const clipVertices = (v0, v1) => {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;\n const clipFactor = Vector3.GetClipFactor(v0.position, v1.position, axis, clipSize);\n let indices = emptyArray;\n let weights = emptyArray;\n if (matIndices && matWeights) {\n const mat0Index = v0.matrixIndicesOverride ? 0 : v0.vertexIdxForBones;\n const v0Indices = (_a = v0.matrixIndicesOverride) !== null && _a !== void 0 ? _a : matIndices;\n const v0Weights = (_b = v0.matrixWeightsOverride) !== null && _b !== void 0 ? _b : matWeights;\n const mat1Index = v1.matrixIndicesOverride ? 0 : v1.vertexIdxForBones;\n const v1Indices = (_c = v1.matrixIndicesOverride) !== null && _c !== void 0 ? _c : matIndices;\n const v1Weights = (_d = v1.matrixWeightsOverride) !== null && _d !== void 0 ? _d : matWeights;\n indices = [0, 0, 0, 0];\n weights = [0, 0, 0, 0];\n let index = 0;\n for (let i = 0; i < 4; ++i) {\n if (v0Weights[mat0Index + i] > 0) {\n const idx = indexOf(v1Indices, v0Indices[mat0Index + i], mat1Index, 4);\n indices[index] = v0Indices[mat0Index + i];\n weights[index] = Scalar.Lerp(v0Weights[mat0Index + i], idx >= 0 ? v1Weights[idx] : 0, clipFactor);\n index++;\n }\n }\n for (let i = 0; i < 4 && index < 4; ++i) {\n const ind = v1Indices[mat1Index + i];\n if (indexOf(v0Indices, ind, mat0Index, 4) !== -1)\n continue;\n indices[index] = ind;\n weights[index] = Scalar.Lerp(0, v1Weights[mat1Index + i], clipFactor);\n index++;\n }\n const sumw = weights[0] + weights[1] + weights[2] + weights[3];\n weights[0] /= sumw;\n weights[1] /= sumw;\n weights[2] /= sumw;\n weights[3] /= sumw;\n }\n const v0LocalPositionX = v0.localPositionOverride ? v0.localPositionOverride[0] : (_e = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v0.vertexIdx]) !== null && _e !== void 0 ? _e : 0;\n const v0LocalPositionY = v0.localPositionOverride ? v0.localPositionOverride[1] : (_f = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v0.vertexIdx + 1]) !== null && _f !== void 0 ? _f : 0;\n const v0LocalPositionZ = v0.localPositionOverride ? v0.localPositionOverride[2] : (_g = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v0.vertexIdx + 2]) !== null && _g !== void 0 ? _g : 0;\n const v1LocalPositionX = v1.localPositionOverride ? v1.localPositionOverride[0] : (_h = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v1.vertexIdx]) !== null && _h !== void 0 ? _h : 0;\n const v1LocalPositionY = v1.localPositionOverride ? v1.localPositionOverride[1] : (_j = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v1.vertexIdx + 1]) !== null && _j !== void 0 ? _j : 0;\n const v1LocalPositionZ = v1.localPositionOverride ? v1.localPositionOverride[2] : (_k = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v1.vertexIdx + 2]) !== null && _k !== void 0 ? _k : 0;\n const v0LocalNormalX = v0.localNormalOverride ? v0.localNormalOverride[0] : (_l = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v0.vertexIdx]) !== null && _l !== void 0 ? _l : 0;\n const v0LocalNormalY = v0.localNormalOverride ? v0.localNormalOverride[1] : (_m = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v0.vertexIdx + 1]) !== null && _m !== void 0 ? _m : 0;\n const v0LocalNormalZ = v0.localNormalOverride ? v0.localNormalOverride[2] : (_o = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v0.vertexIdx + 2]) !== null && _o !== void 0 ? _o : 0;\n const v1LocalNormalX = v1.localNormalOverride ? v1.localNormalOverride[0] : (_p = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v1.vertexIdx]) !== null && _p !== void 0 ? _p : 0;\n const v1LocalNormalY = v1.localNormalOverride ? v1.localNormalOverride[1] : (_q = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v1.vertexIdx + 1]) !== null && _q !== void 0 ? _q : 0;\n const v1LocalNormalZ = v1.localNormalOverride ? v1.localNormalOverride[2] : (_r = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v1.vertexIdx + 2]) !== null && _r !== void 0 ? _r : 0;\n const interpNormalX = v0LocalNormalX + (v1LocalNormalX - v0LocalNormalX) * clipFactor;\n const interpNormalY = v0LocalNormalY + (v1LocalNormalY - v0LocalNormalY) * clipFactor;\n const interpNormalZ = v0LocalNormalZ + (v1LocalNormalZ - v0LocalNormalZ) * clipFactor;\n const norm = Math.sqrt(interpNormalX * interpNormalX + interpNormalY * interpNormalY + interpNormalZ * interpNormalZ);\n return new DecalVertex(Vector3.Lerp(v0.position, v1.position, clipFactor), Vector3.Lerp(v0.normal, v1.normal, clipFactor).normalize(), Vector2.Lerp(v0.uv, v1.uv, clipFactor), -1, -1, localPositions\n ? [\n v0LocalPositionX + (v1LocalPositionX - v0LocalPositionX) * clipFactor,\n v0LocalPositionY + (v1LocalPositionY - v0LocalPositionY) * clipFactor,\n v0LocalPositionZ + (v1LocalPositionZ - v0LocalPositionZ) * clipFactor,\n ]\n : null, localNormals ? [interpNormalX / norm, interpNormalY / norm, interpNormalZ / norm] : null, indices, weights);\n };\n let clipResult = null;\n if (vertices.length > 3) {\n clipResult = new Array();\n }\n for (let index = 0; index < vertices.length; index += 3) {\n let total = 0;\n let nV1 = null;\n let nV2 = null;\n let nV3 = null;\n let nV4 = null;\n const d1 = Vector3.Dot(vertices[index].position, axis) - clipSize;\n const d2 = Vector3.Dot(vertices[index + 1].position, axis) - clipSize;\n const d3 = Vector3.Dot(vertices[index + 2].position, axis) - clipSize;\n const v1Out = d1 > 0;\n const v2Out = d2 > 0;\n const v3Out = d3 > 0;\n total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);\n switch (total) {\n case 0:\n if (vertices.length > 3) {\n clipResult.push(vertices[index]);\n clipResult.push(vertices[index + 1]);\n clipResult.push(vertices[index + 2]);\n }\n else {\n clipResult = vertices;\n }\n break;\n case 1:\n clipResult = clipResult !== null && clipResult !== void 0 ? clipResult : new Array();\n if (v1Out) {\n nV1 = vertices[index + 1];\n nV2 = vertices[index + 2];\n nV3 = clipVertices(vertices[index], nV1);\n nV4 = clipVertices(vertices[index], nV2);\n }\n if (v2Out) {\n nV1 = vertices[index];\n nV2 = vertices[index + 2];\n nV3 = clipVertices(vertices[index + 1], nV1);\n nV4 = clipVertices(vertices[index + 1], nV2);\n clipResult.push(nV3);\n clipResult.push(nV2.clone());\n clipResult.push(nV1.clone());\n clipResult.push(nV2.clone());\n clipResult.push(nV3.clone());\n clipResult.push(nV4);\n break;\n }\n if (v3Out) {\n nV1 = vertices[index];\n nV2 = vertices[index + 1];\n nV3 = clipVertices(vertices[index + 2], nV1);\n nV4 = clipVertices(vertices[index + 2], nV2);\n }\n if (nV1 && nV2 && nV3 && nV4) {\n clipResult.push(nV1.clone());\n clipResult.push(nV2.clone());\n clipResult.push(nV3);\n clipResult.push(nV4);\n clipResult.push(nV3.clone());\n clipResult.push(nV2.clone());\n }\n break;\n case 2:\n clipResult = clipResult !== null && clipResult !== void 0 ? clipResult : new Array();\n if (!v1Out) {\n nV1 = vertices[index].clone();\n nV2 = clipVertices(nV1, vertices[index + 1]);\n nV3 = clipVertices(nV1, vertices[index + 2]);\n clipResult.push(nV1);\n clipResult.push(nV2);\n clipResult.push(nV3);\n }\n if (!v2Out) {\n nV1 = vertices[index + 1].clone();\n nV2 = clipVertices(nV1, vertices[index + 2]);\n nV3 = clipVertices(nV1, vertices[index]);\n clipResult.push(nV1);\n clipResult.push(nV2);\n clipResult.push(nV3);\n }\n if (!v3Out) {\n nV1 = vertices[index + 2].clone();\n nV2 = clipVertices(nV1, vertices[index]);\n nV3 = clipVertices(nV1, vertices[index + 1]);\n clipResult.push(nV1);\n clipResult.push(nV2);\n clipResult.push(nV3);\n }\n break;\n }\n }\n return clipResult;\n };\n const sourceMeshAsMesh = sourceMesh instanceof Mesh ? sourceMesh : null;\n const matrixData = sourceMeshAsMesh === null || sourceMeshAsMesh === void 0 ? void 0 : sourceMeshAsMesh._thinInstanceDataStorage.matrixData;\n const numMatrices = (sourceMeshAsMesh === null || sourceMeshAsMesh === void 0 ? void 0 : sourceMeshAsMesh.thinInstanceCount) || 1;\n const thinInstanceMatrix = TmpVectors.Matrix[0];\n thinInstanceMatrix.copyFrom(Matrix.IdentityReadOnly);\n for (let m = 0; m < numMatrices; ++m) {\n if ((sourceMeshAsMesh === null || sourceMeshAsMesh === void 0 ? void 0 : sourceMeshAsMesh.hasThinInstances) && matrixData) {\n const ofst = m * 16;\n thinInstanceMatrix.setRowFromFloats(0, matrixData[ofst + 0], matrixData[ofst + 1], matrixData[ofst + 2], matrixData[ofst + 3]);\n thinInstanceMatrix.setRowFromFloats(1, matrixData[ofst + 4], matrixData[ofst + 5], matrixData[ofst + 6], matrixData[ofst + 7]);\n thinInstanceMatrix.setRowFromFloats(2, matrixData[ofst + 8], matrixData[ofst + 9], matrixData[ofst + 10], matrixData[ofst + 11]);\n thinInstanceMatrix.setRowFromFloats(3, matrixData[ofst + 12], matrixData[ofst + 13], matrixData[ofst + 14], matrixData[ofst + 15]);\n }\n // Matrix\n const decalWorldMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(Matrix.Translation(position.x, position.y, position.z));\n const inverseDecalWorldMatrix = Matrix.Invert(decalWorldMatrix);\n const meshWorldMatrix = sourceMesh.getWorldMatrix();\n const transformMatrix = thinInstanceMatrix.multiply(meshWorldMatrix).multiply(inverseDecalWorldMatrix);\n const oneFaceVertices = new Array(3);\n for (let index = 0; index < indices.length; index += 3) {\n let faceVertices = oneFaceVertices;\n faceVertices[0] = extractDecalVector3(index, transformMatrix);\n if (meshHasOverridenMaterial && useLocalComputation) {\n faceVertices[1] = extractDecalVector3(index + 2, transformMatrix);\n faceVertices[2] = extractDecalVector3(index + 1, transformMatrix);\n }\n else {\n faceVertices[1] = extractDecalVector3(index + 1, transformMatrix);\n faceVertices[2] = extractDecalVector3(index + 2, transformMatrix);\n }\n if (options.cullBackFaces) {\n // If all the normals of the vertices of the face are pointing away from the view direction we discard the face.\n // As computations are done in the decal coordinate space, the viewDirection is (0,0,1), so when dot(vertexNormal, -viewDirection) <= 0 the vertex is culled\n if (-faceVertices[0].normal.z <= 0 && -faceVertices[1].normal.z <= 0 && -faceVertices[2].normal.z <= 0) {\n continue;\n }\n }\n // Clip\n faceVertices = clip(faceVertices, xpAxis);\n if (!faceVertices)\n continue;\n faceVertices = clip(faceVertices, xnAxis);\n if (!faceVertices)\n continue;\n faceVertices = clip(faceVertices, ypAxis);\n if (!faceVertices)\n continue;\n faceVertices = clip(faceVertices, ynAxis);\n if (!faceVertices)\n continue;\n faceVertices = clip(faceVertices, zpAxis);\n if (!faceVertices)\n continue;\n faceVertices = clip(faceVertices, znAxis);\n if (!faceVertices)\n continue;\n // Add UVs and get back to world\n for (let vIndex = 0; vIndex < faceVertices.length; vIndex++) {\n const vertex = faceVertices[vIndex];\n //TODO check for Int32Array | Uint32Array | Uint16Array\n vertexData.indices.push(currentVertexDataIndex);\n if (useLocalComputation) {\n if (vertex.localPositionOverride) {\n vertexData.positions[currentVertexDataIndex * 3] = vertex.localPositionOverride[0];\n vertexData.positions[currentVertexDataIndex * 3 + 1] = vertex.localPositionOverride[1];\n vertexData.positions[currentVertexDataIndex * 3 + 2] = vertex.localPositionOverride[2];\n }\n else if (localPositions) {\n vertexData.positions[currentVertexDataIndex * 3] = localPositions[vertex.vertexIdx];\n vertexData.positions[currentVertexDataIndex * 3 + 1] = localPositions[vertex.vertexIdx + 1];\n vertexData.positions[currentVertexDataIndex * 3 + 2] = localPositions[vertex.vertexIdx + 2];\n }\n if (vertex.localNormalOverride) {\n vertexData.normals[currentVertexDataIndex * 3] = vertex.localNormalOverride[0];\n vertexData.normals[currentVertexDataIndex * 3 + 1] = vertex.localNormalOverride[1];\n vertexData.normals[currentVertexDataIndex * 3 + 2] = vertex.localNormalOverride[2];\n }\n else if (localNormals) {\n vertexData.normals[currentVertexDataIndex * 3] = localNormals[vertex.vertexIdx];\n vertexData.normals[currentVertexDataIndex * 3 + 1] = localNormals[vertex.vertexIdx + 1];\n vertexData.normals[currentVertexDataIndex * 3 + 2] = localNormals[vertex.vertexIdx + 2];\n }\n }\n else {\n vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);\n vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);\n }\n if (vertexData.matricesIndices && vertexData.matricesWeights) {\n if (vertex.matrixIndicesOverride) {\n vertexData.matricesIndices[currentVertexDataIndex * 4] = vertex.matrixIndicesOverride[0];\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 1] = vertex.matrixIndicesOverride[1];\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 2] = vertex.matrixIndicesOverride[2];\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 3] = vertex.matrixIndicesOverride[3];\n }\n else {\n if (matIndices) {\n vertexData.matricesIndices[currentVertexDataIndex * 4] = matIndices[vertex.vertexIdxForBones];\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 1] = matIndices[vertex.vertexIdxForBones + 1];\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 2] = matIndices[vertex.vertexIdxForBones + 2];\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 3] = matIndices[vertex.vertexIdxForBones + 3];\n }\n if (matIndicesExtra && vertexData.matricesIndicesExtra) {\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4] = matIndicesExtra[vertex.vertexIdxForBones];\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 1] = matIndicesExtra[vertex.vertexIdxForBones + 1];\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 2] = matIndicesExtra[vertex.vertexIdxForBones + 2];\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 3] = matIndicesExtra[vertex.vertexIdxForBones + 3];\n }\n }\n if (vertex.matrixWeightsOverride) {\n vertexData.matricesWeights[currentVertexDataIndex * 4] = vertex.matrixWeightsOverride[0];\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 1] = vertex.matrixWeightsOverride[1];\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 2] = vertex.matrixWeightsOverride[2];\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 3] = vertex.matrixWeightsOverride[3];\n }\n else {\n if (matWeights) {\n vertexData.matricesWeights[currentVertexDataIndex * 4] = matWeights[vertex.vertexIdxForBones];\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 1] = matWeights[vertex.vertexIdxForBones + 1];\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 2] = matWeights[vertex.vertexIdxForBones + 2];\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 3] = matWeights[vertex.vertexIdxForBones + 3];\n }\n if (matWeightsExtra && vertexData.matricesWeightsExtra) {\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4] = matWeightsExtra[vertex.vertexIdxForBones];\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 1] = matWeightsExtra[vertex.vertexIdxForBones + 1];\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 2] = matWeightsExtra[vertex.vertexIdxForBones + 2];\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 3] = matWeightsExtra[vertex.vertexIdxForBones + 3];\n }\n }\n }\n if (!options.captureUVS) {\n vertexData.uvs.push(0.5 + vertex.position.x / size.x);\n const v = 0.5 + vertex.position.y / size.y;\n vertexData.uvs.push(CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\n }\n else {\n vertex.uv.toArray(vertexData.uvs, currentVertexDataIndex * 2);\n }\n currentVertexDataIndex++;\n }\n }\n }\n // Avoid the \"Setting vertex data kind 'XXX' with an empty array\" warning when calling vertexData.applyToMesh\n if (vertexData.indices.length === 0)\n vertexData.indices = null;\n if (vertexData.positions.length === 0)\n vertexData.positions = null;\n if (vertexData.normals.length === 0)\n vertexData.normals = null;\n if (vertexData.uvs.length === 0)\n vertexData.uvs = null;\n if (((_a = vertexData.matricesIndices) === null || _a === void 0 ? void 0 : _a.length) === 0)\n vertexData.matricesIndices = null;\n if (((_b = vertexData.matricesWeights) === null || _b === void 0 ? void 0 : _b.length) === 0)\n vertexData.matricesWeights = null;\n if (((_c = vertexData.matricesIndicesExtra) === null || _c === void 0 ? void 0 : _c.length) === 0)\n vertexData.matricesIndicesExtra = null;\n if (((_d = vertexData.matricesWeightsExtra) === null || _d === void 0 ? void 0 : _d.length) === 0)\n vertexData.matricesWeightsExtra = null;\n // Return mesh\n const decal = new Mesh(name, sourceMesh.getScene());\n vertexData.applyToMesh(decal);\n if (useLocalComputation) {\n decal.skeleton = sourceMesh.skeleton;\n decal.parent = sourceMesh;\n }\n else {\n decal.position = position.clone();\n decal.rotation = new Vector3(pitch, yaw, angle);\n }\n decal.computeWorldMatrix(true);\n decal.refreshBoundingInfo(true, true);\n return decal;\n }\n Mesh.CreateDecal = (name, sourceMesh, position, normal, size, angle) => {\n const options = {\n position,\n normal,\n size,\n angle,\n };\n return CreateDecal(name, sourceMesh, options);\n };\n\n /**\n * Scripts based off of https://github.com/maximeq/three-js-capsule-geometry/blob/master/src/CapsuleBufferGeometry.js\n * @param options the constructors options used to shape the mesh.\n * @returns the capsule VertexData\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/capsule\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function CreateCapsuleVertexData(options = {\n subdivisions: 2,\n tessellation: 16,\n height: 1,\n radius: 0.25,\n capSubdivisions: 6,\n }) {\n const subdivisions = Math.max(options.subdivisions ? options.subdivisions : 2, 1) | 0;\n const tessellation = Math.max(options.tessellation ? options.tessellation : 16, 3) | 0;\n const height = Math.max(options.height ? options.height : 1, 0);\n const radius = Math.max(options.radius ? options.radius : 0.25, 0);\n const capDetail = Math.max(options.capSubdivisions ? options.capSubdivisions : 6, 1) | 0;\n const radialSegments = tessellation;\n const heightSegments = subdivisions;\n const radiusTop = Math.max(options.radiusTop ? options.radiusTop : radius, 0);\n const radiusBottom = Math.max(options.radiusBottom ? options.radiusBottom : radius, 0);\n const heightMinusCaps = height - (radiusTop + radiusBottom);\n const thetaStart = 0.0;\n const thetaLength = 2.0 * Math.PI;\n const capsTopSegments = Math.max(options.topCapSubdivisions ? options.topCapSubdivisions : capDetail, 1);\n const capsBottomSegments = Math.max(options.bottomCapSubdivisions ? options.bottomCapSubdivisions : capDetail, 1);\n const alpha = Math.acos((radiusBottom - radiusTop) / height);\n let indices = [];\n const vertices = [];\n const normals = [];\n const uvs = [];\n let index = 0;\n const indexArray = [], halfHeight = heightMinusCaps * 0.5;\n const pi2 = Math.PI * 0.5;\n let x, y;\n const normal = Vector3.Zero();\n const vertex = Vector3.Zero();\n const cosAlpha = Math.cos(alpha);\n const sinAlpha = Math.sin(alpha);\n const coneLength = new Vector2(radiusTop * sinAlpha, halfHeight + radiusTop * cosAlpha)\n .subtract(new Vector2(radiusBottom * sinAlpha, -halfHeight + radiusBottom * cosAlpha))\n .length();\n // Total length for v texture coord\n const vl = radiusTop * alpha + coneLength + radiusBottom * (pi2 - alpha);\n let v = 0;\n for (y = 0; y <= capsTopSegments; y++) {\n const indexRow = [];\n const a = pi2 - alpha * (y / capsTopSegments);\n v += (radiusTop * alpha) / capsTopSegments;\n const cosA = Math.cos(a);\n const sinA = Math.sin(a);\n // calculate the radius of the current row\n const _radius = cosA * radiusTop;\n for (x = 0; x <= radialSegments; x++) {\n const u = x / radialSegments;\n const theta = u * thetaLength + thetaStart;\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n // vertex\n vertex.x = _radius * sinTheta;\n vertex.y = halfHeight + sinA * radiusTop;\n vertex.z = _radius * cosTheta;\n vertices.push(vertex.x, vertex.y, vertex.z);\n // normal\n normal.set(cosA * sinTheta, sinA, cosA * cosTheta);\n normals.push(normal.x, normal.y, normal.z);\n // uv\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? v / vl : 1 - v / vl);\n // save index of vertex in respective row\n indexRow.push(index);\n // increase index\n index++;\n }\n // now save vertices of the row in our index array\n indexArray.push(indexRow);\n }\n const coneHeight = height - radiusTop - radiusBottom + cosAlpha * radiusTop - cosAlpha * radiusBottom;\n const slope = (sinAlpha * (radiusBottom - radiusTop)) / coneHeight;\n for (y = 1; y <= heightSegments; y++) {\n const indexRow = [];\n v += coneLength / heightSegments;\n // calculate the radius of the current row\n const _radius = sinAlpha * ((y * (radiusBottom - radiusTop)) / heightSegments + radiusTop);\n for (x = 0; x <= radialSegments; x++) {\n const u = x / radialSegments;\n const theta = u * thetaLength + thetaStart;\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n // vertex\n vertex.x = _radius * sinTheta;\n vertex.y = halfHeight + cosAlpha * radiusTop - (y * coneHeight) / heightSegments;\n vertex.z = _radius * cosTheta;\n vertices.push(vertex.x, vertex.y, vertex.z);\n // normal\n normal.set(sinTheta, slope, cosTheta).normalize();\n normals.push(normal.x, normal.y, normal.z);\n // uv\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? v / vl : 1 - v / vl);\n // save index of vertex in respective row\n indexRow.push(index);\n // increase index\n index++;\n }\n // now save vertices of the row in our index array\n indexArray.push(indexRow);\n }\n for (y = 1; y <= capsBottomSegments; y++) {\n const indexRow = [];\n const a = pi2 - alpha - (Math.PI - alpha) * (y / capsBottomSegments);\n v += (radiusBottom * alpha) / capsBottomSegments;\n const cosA = Math.cos(a);\n const sinA = Math.sin(a);\n // calculate the radius of the current row\n const _radius = cosA * radiusBottom;\n for (x = 0; x <= radialSegments; x++) {\n const u = x / radialSegments;\n const theta = u * thetaLength + thetaStart;\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n // vertex\n vertex.x = _radius * sinTheta;\n vertex.y = -halfHeight + sinA * radiusBottom;\n vertex.z = _radius * cosTheta;\n vertices.push(vertex.x, vertex.y, vertex.z);\n // normal\n normal.set(cosA * sinTheta, sinA, cosA * cosTheta);\n normals.push(normal.x, normal.y, normal.z);\n // uv\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? v / vl : 1 - v / vl);\n // save index of vertex in respective row\n indexRow.push(index);\n // increase index\n index++;\n }\n // now save vertices of the row in our index array\n indexArray.push(indexRow);\n }\n // generate indices\n for (x = 0; x < radialSegments; x++) {\n for (y = 0; y < capsTopSegments + heightSegments + capsBottomSegments; y++) {\n // we use the index array to access the correct indices\n const i1 = indexArray[y][x];\n const i2 = indexArray[y + 1][x];\n const i3 = indexArray[y + 1][x + 1];\n const i4 = indexArray[y][x + 1];\n // face one\n indices.push(i1);\n indices.push(i2);\n indices.push(i4);\n // face two\n indices.push(i2);\n indices.push(i3);\n indices.push(i4);\n }\n }\n indices = indices.reverse();\n if (options.orientation && !options.orientation.equals(Vector3.Up())) {\n const m = new Matrix();\n options.orientation\n .clone()\n .scale(Math.PI * 0.5)\n .cross(Vector3.Up())\n .toQuaternion()\n .toRotationMatrix(m);\n const v = Vector3.Zero();\n for (let i = 0; i < vertices.length; i += 3) {\n v.set(vertices[i], vertices[i + 1], vertices[i + 2]);\n Vector3.TransformCoordinatesToRef(v.clone(), m, v);\n vertices[i] = v.x;\n vertices[i + 1] = v.y;\n vertices[i + 2] = v.z;\n }\n }\n const vDat = new VertexData();\n vDat.positions = vertices;\n vDat.normals = normals;\n vDat.uvs = uvs;\n vDat.indices = indices;\n return vDat;\n }\n /**\n * Creates a capsule or a pill mesh\n * @param name defines the name of the mesh\n * @param options The constructors options.\n * @param scene The scene the mesh is scoped to.\n * @returns Capsule Mesh\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function CreateCapsule(name, options = {\n orientation: Vector3.Up(),\n subdivisions: 2,\n tessellation: 16,\n height: 1,\n radius: 0.25,\n capSubdivisions: 6,\n updatable: false,\n }, scene = null) {\n const capsule = new Mesh(name, scene);\n const vertexData = CreateCapsuleVertexData(options);\n vertexData.applyToMesh(capsule, options.updatable);\n return capsule;\n }\n /**\n * Creates a capsule or a pill mesh\n * @param name defines the name of the mesh.\n * @param options the constructors options used to shape the mesh.\n * @param scene defines the scene the mesh is scoped to.\n * @returns the capsule mesh\n * @see https://doc.babylonjs.com/how_to/capsule_shape\n */\n Mesh.CreateCapsule = (name, options, scene) => {\n return CreateCapsule(name, options, scene);\n };\n VertexData.CreateCapsule = CreateCapsuleVertexData;\n\n /**\n * Class representing an isovector a vector containing 2 INTEGER coordinates\n * x axis is horizontal\n * y axis is 60 deg counter clockwise from positive y axis\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _IsoVector {\n /**\n * Creates a new isovector from the given x and y coordinates\n * @param x defines the first coordinate, must be an integer\n * @param y defines the second coordinate, must be an integer\n */\n constructor(\n /** defines the first coordinate */\n x = 0, \n /** defines the second coordinate */\n y = 0) {\n this.x = x;\n this.y = y;\n if (x !== Math.floor(x)) {\n Logger.Warn(\"x is not an integer, floor(x) used\");\n }\n if (y !== Math.floor(y)) {\n Logger.Warn(\"y is not an integer, floor(y) used\");\n }\n }\n // Operators\n /**\n * Gets a new IsoVector copied from the IsoVector\n * @returns a new IsoVector\n */\n clone() {\n return new _IsoVector(this.x, this.y);\n }\n /**\n * Rotates one IsoVector 60 degrees counter clockwise about another\n * Please note that this is an in place operation\n * @param other an IsoVector a center of rotation\n * @returns the rotated IsoVector\n */\n rotate60About(other) {\n //other IsoVector\n const x = this.x;\n this.x = other.x + other.y - this.y;\n this.y = x + this.y - other.x;\n return this;\n }\n /**\n * Rotates one IsoVector 60 degrees clockwise about another\n * Please note that this is an in place operation\n * @param other an IsoVector as center of rotation\n * @returns the rotated IsoVector\n */\n rotateNeg60About(other) {\n const x = this.x;\n this.x = x + this.y - other.y;\n this.y = other.x + other.y - x;\n return this;\n }\n /**\n * For an equilateral triangle OAB with O at isovector (0, 0) and A at isovector (m, n)\n * Rotates one IsoVector 120 degrees counter clockwise about the center of the triangle\n * Please note that this is an in place operation\n * @param m integer a measure a Primary triangle of order (m, n) m > n\n * @param n >= 0 integer a measure for a Primary triangle of order (m, n)\n * @returns the rotated IsoVector\n */\n rotate120(m, n) {\n //m, n integers\n if (m !== Math.floor(m)) {\n Logger.Warn(\"m not an integer only floor(m) used\");\n }\n if (n !== Math.floor(n)) {\n Logger.Warn(\"n not an integer only floor(n) used\");\n }\n const x = this.x;\n this.x = m - x - this.y;\n this.y = n + x;\n return this;\n }\n /**\n * For an equilateral triangle OAB with O at isovector (0, 0) and A at isovector (m, n)\n * Rotates one IsoVector 120 degrees clockwise about the center of the triangle\n * Please note that this is an in place operation\n * @param m integer a measure a Primary triangle of order (m, n) m > n\n * @param n >= 0 integer a measure for a Primary triangle of order (m, n)\n * @returns the rotated IsoVector\n */\n rotateNeg120(m, n) {\n //m, n integers\n if (m !== Math.floor(m)) {\n Logger.Warn(\"m is not an integer, floor(m) used\");\n }\n if (n !== Math.floor(n)) {\n Logger.Warn(\"n is not an integer, floor(n) used\");\n }\n const x = this.x;\n this.x = this.y - n;\n this.y = m + n - x - this.y;\n return this;\n }\n /**\n * Transforms an IsoVector to one in Cartesian 3D space based on an isovector\n * @param origin an IsoVector\n * @param isoGridSize\n * @returns Point as a Vector3\n */\n toCartesianOrigin(origin, isoGridSize) {\n const point = Vector3.Zero();\n point.x = origin.x + 2 * this.x * isoGridSize + this.y * isoGridSize;\n point.y = origin.y + Math.sqrt(3) * this.y * isoGridSize;\n return point;\n }\n // Statics\n /**\n * Gets a new IsoVector(0, 0)\n * @returns a new IsoVector\n */\n static Zero() {\n return new _IsoVector(0, 0);\n }\n }\n\n /**\n * Class representing data for one face OAB of an equilateral icosahedron\n * When O is the isovector (0, 0), A is isovector (m, n)\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _PrimaryIsoTriangle {\n constructor() {\n this.cartesian = [];\n this.vertices = [];\n this.max = [];\n this.min = [];\n this.closestTo = [];\n this.innerFacets = [];\n this.isoVecsABOB = [];\n this.isoVecsOBOA = [];\n this.isoVecsBAOA = [];\n this.vertexTypes = [];\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.IDATA = new PolyhedronData(\"icosahedron\", \"Regular\", [\n [0, PHI, -1],\n [-PHI, 1, 0],\n [-1, 0, -PHI],\n [1, 0, -PHI],\n [PHI, 1, 0],\n [0, PHI, 1],\n [-1, 0, PHI],\n [-PHI, -1, 0],\n [0, -PHI, -1],\n [PHI, -1, 0],\n [1, 0, PHI],\n [0, -PHI, 1],\n ], [\n [0, 2, 1],\n [0, 3, 2],\n [0, 4, 3],\n [0, 5, 4],\n [0, 1, 5],\n [7, 6, 1],\n [8, 7, 2],\n [9, 8, 3],\n [10, 9, 4],\n [6, 10, 5],\n [2, 7, 1],\n [3, 8, 2],\n [4, 9, 3],\n [5, 10, 4],\n [1, 6, 5],\n [11, 6, 7],\n [11, 7, 8],\n [11, 8, 9],\n [11, 9, 10],\n [11, 10, 6],\n ]);\n }\n /**\n * Creates the PrimaryIsoTriangle Triangle OAB\n * @param m an integer\n * @param n an integer\n */\n //operators\n setIndices() {\n let indexCount = 12; // 12 vertices already assigned\n const vecToidx = {}; //maps iso-vectors to indexCount;\n const m = this.m;\n const n = this.n;\n let g = m; // hcf of m, n when n != 0\n let m1 = 1;\n let n1 = 0;\n if (n !== 0) {\n g = Scalar.HCF(m, n);\n }\n m1 = m / g;\n n1 = n / g;\n let fr; //face to the right of current face\n let rot; //rotation about which vertex for fr\n let O;\n let A;\n let B;\n const oVec = _IsoVector.Zero();\n const aVec = new _IsoVector(m, n);\n const bVec = new _IsoVector(-n, m + n);\n const oaVec = _IsoVector.Zero();\n const abVec = _IsoVector.Zero();\n const obVec = _IsoVector.Zero();\n let verts = [];\n let idx;\n let idxR;\n let isoId;\n let isoIdR;\n const closestTo = [];\n const vDist = this.vertByDist;\n const matchIdx = (f, fr, isoId, isoIdR) => {\n idx = f + \"|\" + isoId;\n idxR = fr + \"|\" + isoIdR;\n if (!(idx in vecToidx || idxR in vecToidx)) {\n vecToidx[idx] = indexCount;\n vecToidx[idxR] = indexCount;\n indexCount++;\n }\n else if (idx in vecToidx && !(idxR in vecToidx)) {\n vecToidx[idxR] = vecToidx[idx];\n }\n else if (idxR in vecToidx && !(idx in vecToidx)) {\n vecToidx[idx] = vecToidx[idxR];\n }\n if (vDist[isoId][0] > 2) {\n closestTo[vecToidx[idx]] = [-vDist[isoId][0], vDist[isoId][1], vecToidx[idx]];\n }\n else {\n closestTo[vecToidx[idx]] = [verts[vDist[isoId][0]], vDist[isoId][1], vecToidx[idx]];\n }\n };\n this.IDATA.edgematch = [\n [1, \"B\"],\n [2, \"B\"],\n [3, \"B\"],\n [4, \"B\"],\n [0, \"B\"],\n [10, \"O\", 14, \"A\"],\n [11, \"O\", 10, \"A\"],\n [12, \"O\", 11, \"A\"],\n [13, \"O\", 12, \"A\"],\n [14, \"O\", 13, \"A\"],\n [0, \"O\"],\n [1, \"O\"],\n [2, \"O\"],\n [3, \"O\"],\n [4, \"O\"],\n [19, \"B\", 5, \"A\"],\n [15, \"B\", 6, \"A\"],\n [16, \"B\", 7, \"A\"],\n [17, \"B\", 8, \"A\"],\n [18, \"B\", 9, \"A\"],\n ];\n /***edges AB to OB***** rotation about B*/\n for (let f = 0; f < 20; f++) {\n //f current face\n verts = this.IDATA.face[f];\n O = verts[2];\n A = verts[1];\n B = verts[0];\n isoId = oVec.x + \"|\" + oVec.y;\n idx = f + \"|\" + isoId;\n if (!(idx in vecToidx)) {\n vecToidx[idx] = O;\n closestTo[O] = [verts[vDist[isoId][0]], vDist[isoId][1]];\n }\n isoId = aVec.x + \"|\" + aVec.y;\n idx = f + \"|\" + isoId;\n if (!(idx in vecToidx)) {\n vecToidx[idx] = A;\n closestTo[A] = [verts[vDist[isoId][0]], vDist[isoId][1]];\n }\n isoId = bVec.x + \"|\" + bVec.y;\n idx = f + \"|\" + isoId;\n if (!(idx in vecToidx)) {\n vecToidx[idx] = B;\n closestTo[B] = [verts[vDist[isoId][0]], vDist[isoId][1]];\n }\n //for edge vertices\n fr = this.IDATA.edgematch[f][0];\n rot = this.IDATA.edgematch[f][1];\n if (rot === \"B\") {\n for (let i = 1; i < g; i++) {\n abVec.x = m - i * (m1 + n1);\n abVec.y = n + i * m1;\n obVec.x = -i * n1;\n obVec.y = i * (m1 + n1);\n isoId = abVec.x + \"|\" + abVec.y;\n isoIdR = obVec.x + \"|\" + obVec.y;\n matchIdx(f, fr, isoId, isoIdR);\n }\n }\n if (rot === \"O\") {\n for (let i = 1; i < g; i++) {\n obVec.x = -i * n1;\n obVec.y = i * (m1 + n1);\n oaVec.x = i * m1;\n oaVec.y = i * n1;\n isoId = obVec.x + \"|\" + obVec.y;\n isoIdR = oaVec.x + \"|\" + oaVec.y;\n matchIdx(f, fr, isoId, isoIdR);\n }\n }\n fr = this.IDATA.edgematch[f][2];\n rot = this.IDATA.edgematch[f][3];\n if (rot && rot === \"A\") {\n for (let i = 1; i < g; i++) {\n oaVec.x = i * m1;\n oaVec.y = i * n1;\n abVec.x = m - (g - i) * (m1 + n1); //reversed for BA\n abVec.y = n + (g - i) * m1; //reversed for BA\n isoId = oaVec.x + \"|\" + oaVec.y;\n isoIdR = abVec.x + \"|\" + abVec.y;\n matchIdx(f, fr, isoId, isoIdR);\n }\n }\n for (let i = 0; i < this.vertices.length; i++) {\n isoId = this.vertices[i].x + \"|\" + this.vertices[i].y;\n idx = f + \"|\" + isoId;\n if (!(idx in vecToidx)) {\n vecToidx[idx] = indexCount++;\n if (vDist[isoId][0] > 2) {\n closestTo[vecToidx[idx]] = [-vDist[isoId][0], vDist[isoId][1], vecToidx[idx]];\n }\n else {\n closestTo[vecToidx[idx]] = [verts[vDist[isoId][0]], vDist[isoId][1], vecToidx[idx]];\n }\n }\n }\n }\n this.closestTo = closestTo;\n this.vecToidx = vecToidx;\n }\n calcCoeffs() {\n const m = this.m;\n const n = this.n;\n const thirdR3 = Math.sqrt(3) / 3;\n const LSQD = m * m + n * n + m * n;\n this.coau = (m + n) / LSQD;\n this.cobu = -n / LSQD;\n this.coav = (-thirdR3 * (m - n)) / LSQD;\n this.cobv = (thirdR3 * (2 * m + n)) / LSQD;\n }\n createInnerFacets() {\n const m = this.m;\n const n = this.n;\n for (let y = 0; y < n + m + 1; y++) {\n for (let x = this.min[y]; x < this.max[y] + 1; x++) {\n if (x < this.max[y] && x < this.max[y + 1] + 1) {\n this.innerFacets.push([\"|\" + x + \"|\" + y, \"|\" + x + \"|\" + (y + 1), \"|\" + (x + 1) + \"|\" + y]);\n }\n if (y > 0 && x < this.max[y - 1] && x + 1 < this.max[y] + 1) {\n this.innerFacets.push([\"|\" + x + \"|\" + y, \"|\" + (x + 1) + \"|\" + y, \"|\" + (x + 1) + \"|\" + (y - 1)]);\n }\n }\n }\n }\n edgeVecsABOB() {\n const m = this.m;\n const n = this.n;\n const B = new _IsoVector(-n, m + n);\n for (let y = 1; y < m + n; y++) {\n const point = new _IsoVector(this.min[y], y);\n const prev = new _IsoVector(this.min[y - 1], y - 1);\n const next = new _IsoVector(this.min[y + 1], y + 1);\n const pointR = point.clone();\n const prevR = prev.clone();\n const nextR = next.clone();\n pointR.rotate60About(B);\n prevR.rotate60About(B);\n nextR.rotate60About(B);\n const maxPoint = new _IsoVector(this.max[pointR.y], pointR.y);\n const maxPrev = new _IsoVector(this.max[pointR.y - 1], pointR.y - 1);\n const maxLeftPrev = new _IsoVector(this.max[pointR.y - 1] - 1, pointR.y - 1);\n if (pointR.x !== maxPoint.x || pointR.y !== maxPoint.y) {\n if (pointR.x !== maxPrev.x) {\n // type2\n //up\n this.vertexTypes.push([1, 0, 0]);\n this.isoVecsABOB.push([point, maxPrev, maxLeftPrev]);\n //down\n this.vertexTypes.push([1, 0, 0]);\n this.isoVecsABOB.push([point, maxLeftPrev, maxPoint]);\n }\n else if (pointR.y === nextR.y) {\n // type1\n //up\n this.vertexTypes.push([1, 1, 0]);\n this.isoVecsABOB.push([point, prev, maxPrev]);\n //down\n this.vertexTypes.push([1, 0, 1]);\n this.isoVecsABOB.push([point, maxPrev, next]);\n }\n else {\n // type 0\n //up\n this.vertexTypes.push([1, 1, 0]);\n this.isoVecsABOB.push([point, prev, maxPrev]);\n //down\n this.vertexTypes.push([1, 0, 0]);\n this.isoVecsABOB.push([point, maxPrev, maxPoint]);\n }\n }\n }\n }\n mapABOBtoOBOA() {\n const point = new _IsoVector(0, 0);\n for (let i = 0; i < this.isoVecsABOB.length; i++) {\n const temp = [];\n for (let j = 0; j < 3; j++) {\n point.x = this.isoVecsABOB[i][j].x;\n point.y = this.isoVecsABOB[i][j].y;\n if (this.vertexTypes[i][j] === 0) {\n point.rotateNeg120(this.m, this.n);\n }\n temp.push(point.clone());\n }\n this.isoVecsOBOA.push(temp);\n }\n }\n mapABOBtoBAOA() {\n const point = new _IsoVector(0, 0);\n for (let i = 0; i < this.isoVecsABOB.length; i++) {\n const temp = [];\n for (let j = 0; j < 3; j++) {\n point.x = this.isoVecsABOB[i][j].x;\n point.y = this.isoVecsABOB[i][j].y;\n if (this.vertexTypes[i][j] === 1) {\n point.rotate120(this.m, this.n);\n }\n temp.push(point.clone());\n }\n this.isoVecsBAOA.push(temp);\n }\n }\n // eslint-disable-next-line @typescript-eslint/naming-convention\n MapToFace(faceNb, geodesicData) {\n const F = this.IDATA.face[faceNb];\n const oidx = F[2];\n const aidx = F[1];\n const bidx = F[0];\n const O = Vector3.FromArray(this.IDATA.vertex[oidx]);\n const A = Vector3.FromArray(this.IDATA.vertex[aidx]);\n const B = Vector3.FromArray(this.IDATA.vertex[bidx]);\n const OA = A.subtract(O);\n const OB = B.subtract(O);\n const x = OA.scale(this.coau).add(OB.scale(this.cobu));\n const y = OA.scale(this.coav).add(OB.scale(this.cobv));\n const mapped = [];\n let idx;\n let tempVec = TmpVectors.Vector3[0];\n for (let i = 0; i < this.cartesian.length; i++) {\n tempVec = x.scale(this.cartesian[i].x).add(y.scale(this.cartesian[i].y)).add(O);\n mapped[i] = [tempVec.x, tempVec.y, tempVec.z];\n idx = faceNb + \"|\" + this.vertices[i].x + \"|\" + this.vertices[i].y;\n geodesicData.vertex[this.vecToidx[idx]] = [tempVec.x, tempVec.y, tempVec.z];\n }\n }\n //statics\n /**Creates a primary triangle\n * @internal\n */\n build(m, n) {\n const vertices = new Array();\n const O = _IsoVector.Zero();\n const A = new _IsoVector(m, n);\n const B = new _IsoVector(-n, m + n);\n vertices.push(O, A, B);\n //max internal isoceles triangle vertices\n for (let y = n; y < m + 1; y++) {\n for (let x = 0; x < m + 1 - y; x++) {\n vertices.push(new _IsoVector(x, y));\n }\n }\n //shared vertices along edges when needed\n if (n > 0) {\n const g = Scalar.HCF(m, n);\n const m1 = m / g;\n const n1 = n / g;\n for (let i = 1; i < g; i++) {\n vertices.push(new _IsoVector(i * m1, i * n1)); //OA\n vertices.push(new _IsoVector(-i * n1, i * (m1 + n1))); //OB\n vertices.push(new _IsoVector(m - i * (m1 + n1), n + i * m1)); // AB\n }\n //lower rows vertices and their rotations\n const ratio = m / n;\n for (let y = 1; y < n; y++) {\n for (let x = 0; x < y * ratio; x++) {\n vertices.push(new _IsoVector(x, y));\n vertices.push(new _IsoVector(x, y).rotate120(m, n));\n vertices.push(new _IsoVector(x, y).rotateNeg120(m, n));\n }\n }\n }\n //order vertices by x and then y\n vertices.sort((a, b) => {\n return a.x - b.x;\n });\n vertices.sort((a, b) => {\n return a.y - b.y;\n });\n const min = new Array(m + n + 1);\n const max = new Array(m + n + 1);\n for (let i = 0; i < min.length; i++) {\n min[i] = Infinity;\n max[i] = -Infinity;\n }\n let y = 0;\n let x = 0;\n const len = vertices.length;\n for (let i = 0; i < len; i++) {\n x = vertices[i].x;\n y = vertices[i].y;\n min[y] = Math.min(x, min[y]);\n max[y] = Math.max(x, max[y]);\n }\n //calculates the distance of a vertex from a given primary vertex\n const distFrom = (vert, primVert) => {\n const v = vert.clone();\n if (primVert === \"A\") {\n v.rotateNeg120(m, n);\n }\n if (primVert === \"B\") {\n v.rotate120(m, n);\n }\n if (v.x < 0) {\n return v.y;\n }\n return v.x + v.y;\n };\n const cartesian = [];\n const distFromO = [];\n const distFromA = [];\n const distFromB = [];\n const vertByDist = {};\n const vertData = [];\n let closest = -1;\n let dist = -1;\n for (let i = 0; i < len; i++) {\n cartesian[i] = vertices[i].toCartesianOrigin(new _IsoVector(0, 0), 0.5);\n distFromO[i] = distFrom(vertices[i], \"O\");\n distFromA[i] = distFrom(vertices[i], \"A\");\n distFromB[i] = distFrom(vertices[i], \"B\");\n if (distFromO[i] === distFromA[i] && distFromA[i] === distFromB[i]) {\n closest = 3;\n dist = distFromO[i];\n }\n else if (distFromO[i] === distFromA[i]) {\n closest = 4;\n dist = distFromO[i];\n }\n else if (distFromA[i] === distFromB[i]) {\n closest = 5;\n dist = distFromA[i];\n }\n else if (distFromB[i] === distFromO[i]) {\n closest = 6;\n dist = distFromO[i];\n }\n if (distFromO[i] < distFromA[i] && distFromO[i] < distFromB[i]) {\n closest = 2;\n dist = distFromO[i];\n }\n if (distFromA[i] < distFromO[i] && distFromA[i] < distFromB[i]) {\n closest = 1;\n dist = distFromA[i];\n }\n if (distFromB[i] < distFromA[i] && distFromB[i] < distFromO[i]) {\n closest = 0;\n dist = distFromB[i];\n }\n vertData.push([closest, dist, vertices[i].x, vertices[i].y]);\n }\n vertData.sort((a, b) => {\n return a[2] - b[2];\n });\n vertData.sort((a, b) => {\n return a[3] - b[3];\n });\n vertData.sort((a, b) => {\n return a[1] - b[1];\n });\n vertData.sort((a, b) => {\n return a[0] - b[0];\n });\n for (let v = 0; v < vertData.length; v++) {\n vertByDist[vertData[v][2] + \"|\" + vertData[v][3]] = [vertData[v][0], vertData[v][1], v];\n }\n this.m = m;\n this.n = n;\n this.vertices = vertices;\n this.vertByDist = vertByDist;\n this.cartesian = cartesian;\n this.min = min;\n this.max = max;\n return this;\n }\n }\n /** Builds Polyhedron Data\n * @internal\n */\n class PolyhedronData {\n constructor(name, category, vertex, face) {\n this.name = name;\n this.category = category;\n this.vertex = vertex;\n this.face = face;\n }\n }\n /**\n * This class Extends the PolyhedronData Class to provide measures for a Geodesic Polyhedron\n */\n class GeodesicData extends PolyhedronData {\n /**\n * @internal\n */\n innerToData(face, primTri) {\n for (let i = 0; i < primTri.innerFacets.length; i++) {\n this.face.push(primTri.innerFacets[i].map((el) => primTri.vecToidx[face + el]));\n }\n }\n /**\n * @internal\n */\n mapABOBtoDATA(faceNb, primTri) {\n const fr = primTri.IDATA.edgematch[faceNb][0];\n for (let i = 0; i < primTri.isoVecsABOB.length; i++) {\n const temp = [];\n for (let j = 0; j < 3; j++) {\n if (primTri.vertexTypes[i][j] === 0) {\n temp.push(faceNb + \"|\" + primTri.isoVecsABOB[i][j].x + \"|\" + primTri.isoVecsABOB[i][j].y);\n }\n else {\n temp.push(fr + \"|\" + primTri.isoVecsABOB[i][j].x + \"|\" + primTri.isoVecsABOB[i][j].y);\n }\n }\n this.face.push([primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]]]);\n }\n }\n /**\n * @internal\n */\n mapOBOAtoDATA(faceNb, primTri) {\n const fr = primTri.IDATA.edgematch[faceNb][0];\n for (let i = 0; i < primTri.isoVecsOBOA.length; i++) {\n const temp = [];\n for (let j = 0; j < 3; j++) {\n if (primTri.vertexTypes[i][j] === 1) {\n temp.push(faceNb + \"|\" + primTri.isoVecsOBOA[i][j].x + \"|\" + primTri.isoVecsOBOA[i][j].y);\n }\n else {\n temp.push(fr + \"|\" + primTri.isoVecsOBOA[i][j].x + \"|\" + primTri.isoVecsOBOA[i][j].y);\n }\n }\n this.face.push([primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]]]);\n }\n }\n /**\n * @internal\n */\n mapBAOAtoDATA(faceNb, primTri) {\n const fr = primTri.IDATA.edgematch[faceNb][2];\n for (let i = 0; i < primTri.isoVecsBAOA.length; i++) {\n const temp = [];\n for (let j = 0; j < 3; j++) {\n if (primTri.vertexTypes[i][j] === 1) {\n temp.push(faceNb + \"|\" + primTri.isoVecsBAOA[i][j].x + \"|\" + primTri.isoVecsBAOA[i][j].y);\n }\n else {\n temp.push(fr + \"|\" + primTri.isoVecsBAOA[i][j].x + \"|\" + primTri.isoVecsBAOA[i][j].y);\n }\n }\n this.face.push([primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]]]);\n }\n }\n /**\n * @internal\n */\n orderData(primTri) {\n const nearTo = [];\n for (let i = 0; i < 13; i++) {\n nearTo[i] = [];\n }\n const close = primTri.closestTo;\n for (let i = 0; i < close.length; i++) {\n if (close[i][0] > -1) {\n if (close[i][1] > 0) {\n nearTo[close[i][0]].push([i, close[i][1]]);\n }\n }\n else {\n nearTo[12].push([i, close[i][0]]);\n }\n }\n const near = [];\n for (let i = 0; i < 12; i++) {\n near[i] = i;\n }\n let nearIndex = 12;\n for (let i = 0; i < 12; i++) {\n nearTo[i].sort((a, b) => {\n return a[1] - b[1];\n });\n for (let j = 0; j < nearTo[i].length; j++) {\n near[nearTo[i][j][0]] = nearIndex++;\n }\n }\n for (let j = 0; j < nearTo[12].length; j++) {\n near[nearTo[12][j][0]] = nearIndex++;\n }\n for (let i = 0; i < this.vertex.length; i++) {\n this.vertex[i].push(near[i]);\n }\n this.vertex.sort((a, b) => {\n return a[3] - b[3];\n });\n for (let i = 0; i < this.vertex.length; i++) {\n this.vertex[i].pop();\n }\n for (let i = 0; i < this.face.length; i++) {\n for (let j = 0; j < this.face[i].length; j++) {\n this.face[i][j] = near[this.face[i][j]];\n }\n }\n this.sharedNodes = nearTo[12].length;\n this.poleNodes = this.vertex.length - this.sharedNodes;\n }\n /**\n * @internal\n */\n setOrder(m, faces) {\n const adjVerts = [];\n const dualFaces = [];\n let face = faces.pop();\n dualFaces.push(face);\n let index = this.face[face].indexOf(m);\n index = (index + 2) % 3;\n let v = this.face[face][index];\n adjVerts.push(v);\n let f = 0;\n while (faces.length > 0) {\n face = faces[f];\n if (this.face[face].indexOf(v) > -1) {\n // v is a vertex of face f\n index = (this.face[face].indexOf(v) + 1) % 3;\n v = this.face[face][index];\n adjVerts.push(v);\n dualFaces.push(face);\n faces.splice(f, 1);\n f = 0;\n }\n else {\n f++;\n }\n }\n this.adjacentFaces.push(adjVerts);\n return dualFaces;\n }\n /**\n * @internal\n */\n toGoldbergPolyhedronData() {\n const goldbergPolyhedronData = new PolyhedronData(\"GeoDual\", \"Goldberg\", [], []);\n goldbergPolyhedronData.name = \"GD dual\";\n const verticesNb = this.vertex.length;\n const map = new Array(verticesNb);\n for (let v = 0; v < verticesNb; v++) {\n map[v] = [];\n }\n for (let f = 0; f < this.face.length; f++) {\n for (let i = 0; i < 3; i++) {\n map[this.face[f][i]].push(f);\n }\n }\n let cx = 0;\n let cy = 0;\n let cz = 0;\n let face = [];\n let vertex = [];\n this.adjacentFaces = [];\n for (let m = 0; m < map.length; m++) {\n goldbergPolyhedronData.face[m] = this.setOrder(m, map[m].concat([]));\n map[m].forEach((el) => {\n cx = 0;\n cy = 0;\n cz = 0;\n face = this.face[el];\n for (let i = 0; i < 3; i++) {\n vertex = this.vertex[face[i]];\n cx += vertex[0];\n cy += vertex[1];\n cz += vertex[2];\n }\n goldbergPolyhedronData.vertex[el] = [cx / 3, cy / 3, cz / 3];\n });\n }\n return goldbergPolyhedronData;\n }\n //statics\n /**Builds the data for a Geodesic Polyhedron from a primary triangle\n * @param primTri the primary triangle\n * @internal\n */\n static BuildGeodesicData(primTri) {\n const geodesicData = new GeodesicData(\"Geodesic-m-n\", \"Geodesic\", [\n [0, PHI, -1],\n [-PHI, 1, 0],\n [-1, 0, -PHI],\n [1, 0, -PHI],\n [PHI, 1, 0],\n [0, PHI, 1],\n [-1, 0, PHI],\n [-PHI, -1, 0],\n [0, -PHI, -1],\n [PHI, -1, 0],\n [1, 0, PHI],\n [0, -PHI, 1],\n ], []);\n primTri.setIndices();\n primTri.calcCoeffs();\n primTri.createInnerFacets();\n primTri.edgeVecsABOB();\n primTri.mapABOBtoOBOA();\n primTri.mapABOBtoBAOA();\n for (let f = 0; f < primTri.IDATA.face.length; f++) {\n primTri.MapToFace(f, geodesicData);\n geodesicData.innerToData(f, primTri);\n if (primTri.IDATA.edgematch[f][1] === \"B\") {\n geodesicData.mapABOBtoDATA(f, primTri);\n }\n if (primTri.IDATA.edgematch[f][1] === \"O\") {\n geodesicData.mapOBOAtoDATA(f, primTri);\n }\n if (primTri.IDATA.edgematch[f][3] === \"A\") {\n geodesicData.mapBAOAtoDATA(f, primTri);\n }\n }\n geodesicData.orderData(primTri);\n const radius = 1;\n geodesicData.vertex = geodesicData.vertex.map(function (el) {\n const a = el[0];\n const b = el[1];\n const c = el[2];\n const d = Math.sqrt(a * a + b * b + c * c);\n el[0] *= radius / d;\n el[1] *= radius / d;\n el[2] *= radius / d;\n return el;\n });\n return geodesicData;\n }\n }\n\n /**\n * Creates the Mesh for a Geodesic Polyhedron\n * @see https://en.wikipedia.org/wiki/Geodesic_polyhedron\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra/geodesic_poly\n * @param name defines the name of the mesh\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\n * * m number of horizontal steps along an isogrid\n * * n number of angled steps along an isogrid\n * * size the size of the Geodesic, optional default 1\n * * sizeX allows stretching in the x direction, optional, default size\n * * sizeY allows stretching in the y direction, optional, default size\n * * sizeZ allows stretching in the z direction, optional, default size\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\n * * flat when true creates a flat shaded mesh, optional, default true\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * @param options.n\n * @param options.size\n * @param options.sizeX\n * @param options.sizeY\n * @param options.sizeZ\n * @param options.faceUV\n * @param options.faceColors\n * @param options.flat\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param options.m\n * @param scene defines the hosting scene\n * @returns Geodesic mesh\n */\n function CreateGeodesic(name, options, scene = null) {\n let m = options.m || 1;\n if (m !== Math.floor(m)) {\n Logger.Warn(\"m not an integer only floor(m) used\");\n }\n let n = options.n || 0;\n if (n !== Math.floor(n)) {\n Logger.Warn(\"n not an integer only floor(n) used\");\n }\n if (n > m) {\n const temp = n;\n n = m;\n m = temp;\n Logger.Warn(\"n > m therefore m and n swapped\");\n }\n const primTri = new _PrimaryIsoTriangle();\n primTri.build(m, n);\n const geodesicData = GeodesicData.BuildGeodesicData(primTri);\n const geoOptions = {\n custom: geodesicData,\n size: options.size,\n sizeX: options.sizeX,\n sizeY: options.sizeY,\n sizeZ: options.sizeZ,\n faceUV: options.faceUV,\n faceColors: options.faceColors,\n flat: options.flat,\n updatable: options.updatable,\n sideOrientation: options.sideOrientation,\n frontUVs: options.frontUVs,\n backUVs: options.backUVs,\n };\n const geodesic = CreatePolyhedron(name, geoOptions, scene);\n return geodesic;\n }\n\n Mesh._GoldbergMeshParser = (parsedMesh, scene) => {\n return GoldbergMesh.Parse(parsedMesh, scene);\n };\n /**\n * Mesh for a Goldberg Polyhedron which is made from 12 pentagonal and the rest hexagonal faces\n * @see https://en.wikipedia.org/wiki/Goldberg_polyhedron\n */\n class GoldbergMesh extends Mesh {\n constructor() {\n super(...arguments);\n /**\n * Defines the specific Goldberg data used in this mesh construction.\n */\n this.goldbergData = {\n faceColors: [],\n faceCenters: [],\n faceZaxis: [],\n faceXaxis: [],\n faceYaxis: [],\n nbSharedFaces: 0,\n nbUnsharedFaces: 0,\n nbFaces: 0,\n nbFacesAtPole: 0,\n adjacentFaces: [],\n };\n }\n /**\n * Gets the related Goldberg face from pole infos\n * @param poleOrShared Defines the pole index or the shared face index if the fromPole parameter is passed in\n * @param fromPole Defines an optional pole index to find the related info from\n * @returns the goldberg face number\n */\n relatedGoldbergFace(poleOrShared, fromPole) {\n if (fromPole === void 0) {\n if (poleOrShared > this.goldbergData.nbUnsharedFaces - 1) {\n Logger.Warn(\"Maximum number of unshared faces used\");\n poleOrShared = this.goldbergData.nbUnsharedFaces - 1;\n }\n return this.goldbergData.nbUnsharedFaces + poleOrShared;\n }\n if (poleOrShared > 11) {\n Logger.Warn(\"Last pole used\");\n poleOrShared = 11;\n }\n if (fromPole > this.goldbergData.nbFacesAtPole - 1) {\n Logger.Warn(\"Maximum number of faces at a pole used\");\n fromPole = this.goldbergData.nbFacesAtPole - 1;\n }\n return 12 + poleOrShared * this.goldbergData.nbFacesAtPole + fromPole;\n }\n _changeGoldbergFaceColors(colorRange) {\n for (let i = 0; i < colorRange.length; i++) {\n const min = colorRange[i][0];\n const max = colorRange[i][1];\n const col = colorRange[i][2];\n for (let f = min; f < max + 1; f++) {\n this.goldbergData.faceColors[f] = col;\n }\n }\n const newCols = [];\n for (let f = 0; f < 12; f++) {\n for (let i = 0; i < 5; i++) {\n newCols.push(this.goldbergData.faceColors[f].r, this.goldbergData.faceColors[f].g, this.goldbergData.faceColors[f].b, this.goldbergData.faceColors[f].a);\n }\n }\n for (let f = 12; f < this.goldbergData.faceColors.length; f++) {\n for (let i = 0; i < 6; i++) {\n newCols.push(this.goldbergData.faceColors[f].r, this.goldbergData.faceColors[f].g, this.goldbergData.faceColors[f].b, this.goldbergData.faceColors[f].a);\n }\n }\n return newCols;\n }\n /**\n * Set new goldberg face colors\n * @param colorRange the new color to apply to the mesh\n */\n setGoldbergFaceColors(colorRange) {\n const newCols = this._changeGoldbergFaceColors(colorRange);\n this.setVerticesData(VertexBuffer.ColorKind, newCols);\n }\n /**\n * Updates new goldberg face colors\n * @param colorRange the new color to apply to the mesh\n */\n updateGoldbergFaceColors(colorRange) {\n const newCols = this._changeGoldbergFaceColors(colorRange);\n this.updateVerticesData(VertexBuffer.ColorKind, newCols);\n }\n _changeGoldbergFaceUVs(uvRange) {\n const uvs = this.getVerticesData(VertexBuffer.UVKind);\n for (let i = 0; i < uvRange.length; i++) {\n const min = uvRange[i][0];\n const max = uvRange[i][1];\n const center = uvRange[i][2];\n const radius = uvRange[i][3];\n const angle = uvRange[i][4];\n const points5 = [];\n const points6 = [];\n let u;\n let v;\n for (let p = 0; p < 5; p++) {\n u = center.x + radius * Math.cos(angle + (p * Math.PI) / 2.5);\n v = center.y + radius * Math.sin(angle + (p * Math.PI) / 2.5);\n if (u < 0) {\n u = 0;\n }\n if (u > 1) {\n u = 1;\n }\n points5.push(u, v);\n }\n for (let p = 0; p < 6; p++) {\n u = center.x + radius * Math.cos(angle + (p * Math.PI) / 3);\n v = center.y + radius * Math.sin(angle + (p * Math.PI) / 3);\n if (u < 0) {\n u = 0;\n }\n if (u > 1) {\n u = 1;\n }\n points6.push(u, v);\n }\n for (let f = min; f < Math.min(12, max + 1); f++) {\n for (let p = 0; p < 5; p++) {\n uvs[10 * f + 2 * p] = points5[2 * p];\n uvs[10 * f + 2 * p + 1] = points5[2 * p + 1];\n }\n }\n for (let f = Math.max(12, min); f < max + 1; f++) {\n for (let p = 0; p < 6; p++) {\n //120 + 12 * (f - 12) = 12 * f - 24\n uvs[12 * f - 24 + 2 * p] = points6[2 * p];\n uvs[12 * f - 23 + 2 * p] = points6[2 * p + 1];\n }\n }\n }\n return uvs;\n }\n /**\n * set new goldberg face UVs\n * @param uvRange the new UVs to apply to the mesh\n */\n setGoldbergFaceUVs(uvRange) {\n const newUVs = this._changeGoldbergFaceUVs(uvRange);\n this.setVerticesData(VertexBuffer.UVKind, newUVs);\n }\n /**\n * Updates new goldberg face UVs\n * @param uvRange the new UVs to apply to the mesh\n */\n updateGoldbergFaceUVs(uvRange) {\n const newUVs = this._changeGoldbergFaceUVs(uvRange);\n this.updateVerticesData(VertexBuffer.UVKind, newUVs);\n }\n /**\n * Places a mesh on a particular face of the goldberg polygon\n * @param mesh Defines the mesh to position\n * @param face Defines the face to position onto\n * @param position Defines the position relative to the face we are positioning the mesh onto\n */\n placeOnGoldbergFaceAt(mesh, face, position) {\n const orientation = Vector3.RotationFromAxis(this.goldbergData.faceXaxis[face], this.goldbergData.faceYaxis[face], this.goldbergData.faceZaxis[face]);\n mesh.rotation = orientation;\n mesh.position = this.goldbergData.faceCenters[face]\n .add(this.goldbergData.faceXaxis[face].scale(position.x))\n .add(this.goldbergData.faceYaxis[face].scale(position.y))\n .add(this.goldbergData.faceZaxis[face].scale(position.z));\n }\n /**\n * Serialize current mesh\n * @param serializationObject defines the object which will receive the serialization data\n */\n serialize(serializationObject) {\n super.serialize(serializationObject);\n serializationObject.type = \"GoldbergMesh\";\n const goldbergData = {};\n goldbergData.adjacentFaces = this.goldbergData.adjacentFaces;\n goldbergData.nbSharedFaces = this.goldbergData.nbSharedFaces;\n goldbergData.nbUnsharedFaces = this.goldbergData.nbUnsharedFaces;\n goldbergData.nbFaces = this.goldbergData.nbFaces;\n goldbergData.nbFacesAtPole = this.goldbergData.nbFacesAtPole;\n if (this.goldbergData.faceColors) {\n goldbergData.faceColors = [];\n for (const color of this.goldbergData.faceColors) {\n goldbergData.faceColors.push(color.asArray());\n }\n }\n if (this.goldbergData.faceCenters) {\n goldbergData.faceCenters = [];\n for (const vector of this.goldbergData.faceCenters) {\n goldbergData.faceCenters.push(vector.asArray());\n }\n }\n if (this.goldbergData.faceZaxis) {\n goldbergData.faceZaxis = [];\n for (const vector of this.goldbergData.faceZaxis) {\n goldbergData.faceZaxis.push(vector.asArray());\n }\n }\n if (this.goldbergData.faceYaxis) {\n goldbergData.faceYaxis = [];\n for (const vector of this.goldbergData.faceYaxis) {\n goldbergData.faceYaxis.push(vector.asArray());\n }\n }\n if (this.goldbergData.faceXaxis) {\n goldbergData.faceXaxis = [];\n for (const vector of this.goldbergData.faceXaxis) {\n goldbergData.faceXaxis.push(vector.asArray());\n }\n }\n serializationObject.goldbergData = goldbergData;\n }\n /**\n * Parses a serialized goldberg mesh\n * @param parsedMesh the serialized mesh\n * @param scene the scene to create the goldberg mesh in\n * @returns the created goldberg mesh\n */\n static Parse(parsedMesh, scene) {\n const goldbergData = parsedMesh.goldbergData;\n goldbergData.faceColors = goldbergData.faceColors.map((el) => Color4.FromArray(el));\n goldbergData.faceCenters = goldbergData.faceCenters.map((el) => Vector3.FromArray(el));\n goldbergData.faceZaxis = goldbergData.faceZaxis.map((el) => Vector3.FromArray(el));\n goldbergData.faceXaxis = goldbergData.faceXaxis.map((el) => Vector3.FromArray(el));\n goldbergData.faceYaxis = goldbergData.faceYaxis.map((el) => Vector3.FromArray(el));\n const goldberg = new GoldbergMesh(parsedMesh.name, scene);\n goldberg.goldbergData = goldbergData;\n return goldberg;\n }\n }\n\n /**\n * Creates the Mesh for a Goldberg Polyhedron\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\n * @param goldbergData polyhedronData defining the Goldberg polyhedron\n * @returns GoldbergSphere mesh\n */\n function CreateGoldbergVertexData(options, goldbergData) {\n const size = options.size;\n const sizeX = options.sizeX || size || 1;\n const sizeY = options.sizeY || size || 1;\n const sizeZ = options.sizeZ || size || 1;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const positions = new Array();\n const indices = new Array();\n const normals = new Array();\n const uvs = new Array();\n let minX = Infinity;\n let maxX = -Infinity;\n let minY = Infinity;\n let maxY = -Infinity;\n for (let v = 0; v < goldbergData.vertex.length; v++) {\n minX = Math.min(minX, goldbergData.vertex[v][0] * sizeX);\n maxX = Math.max(maxX, goldbergData.vertex[v][0] * sizeX);\n minY = Math.min(minY, goldbergData.vertex[v][1] * sizeY);\n maxY = Math.max(maxY, goldbergData.vertex[v][1] * sizeY);\n }\n let index = 0;\n for (let f = 0; f < goldbergData.face.length; f++) {\n const verts = goldbergData.face[f];\n const a = Vector3.FromArray(goldbergData.vertex[verts[0]]);\n const b = Vector3.FromArray(goldbergData.vertex[verts[2]]);\n const c = Vector3.FromArray(goldbergData.vertex[verts[1]]);\n const ba = b.subtract(a);\n const ca = c.subtract(a);\n const norm = Vector3.Cross(ca, ba).normalize();\n for (let v = 0; v < verts.length; v++) {\n normals.push(norm.x, norm.y, norm.z);\n const pdata = goldbergData.vertex[verts[v]];\n positions.push(pdata[0] * sizeX, pdata[1] * sizeY, pdata[2] * sizeZ);\n const vCoord = (pdata[1] * sizeY - minY) / (maxY - minY);\n uvs.push((pdata[0] * sizeX - minX) / (maxX - minX), CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - vCoord : vCoord);\n }\n for (let v = 0; v < verts.length - 2; v++) {\n indices.push(index, index + v + 2, index + v + 1);\n }\n index += verts.length;\n }\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs);\n const vertexData = new VertexData();\n vertexData.positions = positions;\n vertexData.indices = indices;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n /**\n * Creates the Mesh for a Goldberg Polyhedron which is made from 12 pentagonal and the rest hexagonal faces\n * @see https://en.wikipedia.org/wiki/Goldberg_polyhedron\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra/goldberg_poly\n * @param name defines the name of the mesh\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\n * @param scene defines the hosting scene\n * @returns Goldberg mesh\n */\n function CreateGoldberg(name, options, scene = null) {\n const size = options.size;\n const sizeX = options.sizeX || size || 1;\n const sizeY = options.sizeY || size || 1;\n const sizeZ = options.sizeZ || size || 1;\n let m = options.m || 1;\n if (m !== Math.floor(m)) {\n Logger.Warn(\"m not an integer only floor(m) used\");\n }\n let n = options.n || 0;\n if (n !== Math.floor(n)) {\n Logger.Warn(\"n not an integer only floor(n) used\");\n }\n if (n > m) {\n const temp = n;\n n = m;\n m = temp;\n Logger.Warn(\"n > m therefore m and n swapped\");\n }\n const primTri = new _PrimaryIsoTriangle();\n primTri.build(m, n);\n const geodesicData = GeodesicData.BuildGeodesicData(primTri);\n const goldbergData = geodesicData.toGoldbergPolyhedronData();\n const goldberg = new GoldbergMesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n goldberg._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateGoldbergVertexData(options, goldbergData);\n vertexData.applyToMesh(goldberg, options.updatable);\n goldberg.goldbergData.nbSharedFaces = geodesicData.sharedNodes;\n goldberg.goldbergData.nbUnsharedFaces = geodesicData.poleNodes;\n goldberg.goldbergData.adjacentFaces = geodesicData.adjacentFaces;\n goldberg.goldbergData.nbFaces = goldberg.goldbergData.nbSharedFaces + goldberg.goldbergData.nbUnsharedFaces;\n goldberg.goldbergData.nbFacesAtPole = (goldberg.goldbergData.nbUnsharedFaces - 12) / 12;\n for (let f = 0; f < geodesicData.vertex.length; f++) {\n goldberg.goldbergData.faceCenters.push(Vector3.FromArray(geodesicData.vertex[f]));\n goldberg.goldbergData.faceCenters[f].x *= sizeX;\n goldberg.goldbergData.faceCenters[f].y *= sizeY;\n goldberg.goldbergData.faceCenters[f].z *= sizeZ;\n goldberg.goldbergData.faceColors.push(new Color4(1, 1, 1, 1));\n }\n for (let f = 0; f < goldbergData.face.length; f++) {\n const verts = goldbergData.face[f];\n const a = Vector3.FromArray(goldbergData.vertex[verts[0]]);\n const b = Vector3.FromArray(goldbergData.vertex[verts[2]]);\n const c = Vector3.FromArray(goldbergData.vertex[verts[1]]);\n const ba = b.subtract(a);\n const ca = c.subtract(a);\n const norm = Vector3.Cross(ca, ba).normalize();\n const z = Vector3.Cross(ca, norm).normalize();\n goldberg.goldbergData.faceXaxis.push(ca.normalize());\n goldberg.goldbergData.faceYaxis.push(norm);\n goldberg.goldbergData.faceZaxis.push(z);\n }\n return goldberg;\n }\n\n // Shape functions\n class ShapePath {\n /** Create the ShapePath used to support glyphs */\n constructor(resolution) {\n this._paths = [];\n this._tempPaths = [];\n this._holes = [];\n this._resolution = resolution;\n }\n /** Move the virtual cursor to a coordinate */\n moveTo(x, y) {\n this._currentPath = new Path2(x, y);\n this._tempPaths.push(this._currentPath);\n }\n /** Draw a line from the virtual cursor to a given coordinate */\n lineTo(x, y) {\n this._currentPath.addLineTo(x, y);\n }\n /** Create a quadratic curve from the virtual cursor to a given coordinate */\n quadraticCurveTo(cpx, cpy, x, y) {\n this._currentPath.addQuadraticCurveTo(cpx, cpy, x, y, this._resolution);\n }\n /** Create a bezier curve from the virtual cursor to a given coordinate */\n bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {\n this._currentPath.addBezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y, this._resolution);\n }\n /** Extract holes based on CW / CCW */\n extractHoles() {\n for (const path of this._tempPaths) {\n if (path.area() > 0) {\n this._holes.push(path);\n }\n else {\n this._paths.push(path);\n }\n }\n if (!this._paths.length && this._holes.length) {\n const temp = this._holes;\n this._holes = this._paths;\n this._paths = temp;\n }\n this._tempPaths.length = 0;\n }\n /** Gets the list of paths */\n get paths() {\n return this._paths;\n }\n /** Gets the list of holes */\n get holes() {\n return this._holes;\n }\n }\n // Utility functions\n function CreateShapePath(char, scale, offsetX, offsetY, resolution, fontData) {\n const glyph = fontData.glyphs[char] || fontData.glyphs[\"?\"];\n if (!glyph) {\n // return if there is no glyph data\n return null;\n }\n const shapePath = new ShapePath(resolution);\n if (glyph.o) {\n const outline = glyph.o.split(\" \");\n for (let i = 0, l = outline.length; i < l;) {\n const action = outline[i++];\n switch (action) {\n case \"m\": {\n // moveTo\n const x = parseInt(outline[i++]) * scale + offsetX;\n const y = parseInt(outline[i++]) * scale + offsetY;\n shapePath.moveTo(x, y);\n break;\n }\n case \"l\": {\n // lineTo\n const x = parseInt(outline[i++]) * scale + offsetX;\n const y = parseInt(outline[i++]) * scale + offsetY;\n shapePath.lineTo(x, y);\n break;\n }\n case \"q\": {\n // quadraticCurveTo\n const cpx = parseInt(outline[i++]) * scale + offsetX;\n const cpy = parseInt(outline[i++]) * scale + offsetY;\n const cpx1 = parseInt(outline[i++]) * scale + offsetX;\n const cpy1 = parseInt(outline[i++]) * scale + offsetY;\n shapePath.quadraticCurveTo(cpx1, cpy1, cpx, cpy);\n break;\n }\n case \"b\": {\n // bezierCurveTo\n const cpx = parseInt(outline[i++]) * scale + offsetX;\n const cpy = parseInt(outline[i++]) * scale + offsetY;\n const cpx1 = parseInt(outline[i++]) * scale + offsetX;\n const cpy1 = parseInt(outline[i++]) * scale + offsetY;\n const cpx2 = parseInt(outline[i++]) * scale + offsetX;\n const cpy2 = parseInt(outline[i++]) * scale + offsetY;\n shapePath.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);\n break;\n }\n }\n }\n }\n // Extract holes (based on clockwise data)\n shapePath.extractHoles();\n return { offsetX: glyph.ha * scale, shapePath: shapePath };\n }\n /**\n * Creates shape paths from a text and font\n * @param text the text\n * @param size size of the font\n * @param resolution resolution of the font\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\n * @returns array of ShapePath objects\n */\n function CreateTextShapePaths(text, size, resolution, fontData) {\n const chars = Array.from(text);\n const scale = size / fontData.resolution;\n const line_height = (fontData.boundingBox.yMax - fontData.boundingBox.yMin + fontData.underlineThickness) * scale;\n const shapePaths = [];\n let offsetX = 0, offsetY = 0;\n for (let i = 0; i < chars.length; i++) {\n const char = chars[i];\n if (char === \"\\n\") {\n offsetX = 0;\n offsetY -= line_height;\n }\n else {\n const ret = CreateShapePath(char, scale, offsetX, offsetY, resolution, fontData);\n if (ret) {\n offsetX += ret.offsetX;\n shapePaths.push(ret.shapePath);\n }\n }\n }\n return shapePaths;\n }\n /**\n * Create a text mesh\n * @param name defines the name of the mesh\n * @param text defines the text to use to build the mesh\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\n * @param options defines options used to create the mesh\n * @param scene defines the hosting scene\n * @param earcutInjection can be used to inject your own earcut reference\n * @returns a new Mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/text\n */\n function CreateText(name, text, fontData, options = {\n size: 50,\n resolution: 8,\n depth: 1.0,\n }, scene = null, earcutInjection = earcut) {\n // First we need to generate the paths\n const shapePaths = CreateTextShapePaths(text, options.size || 50, options.resolution || 8, fontData);\n // And extrude them\n const meshes = [];\n for (const shapePath of shapePaths) {\n if (!shapePath.paths.length) {\n continue;\n }\n const holes = shapePath.holes.slice(); // Copy it as we will update the copy\n for (const path of shapePath.paths) {\n const holeVectors = [];\n const shapeVectors = [];\n const points = path.getPoints();\n for (const point of points) {\n shapeVectors.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\n }\n // Holes\n const localHolesCopy = holes.slice();\n for (const hole of localHolesCopy) {\n const points = hole.getPoints();\n let found = false;\n for (const point of points) {\n if (path.isPointInside(point)) {\n found = true;\n break;\n }\n }\n if (!found) {\n continue;\n }\n const holePoints = [];\n for (const point of points) {\n holePoints.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\n }\n holeVectors.push(holePoints);\n // Remove the hole as it was already used\n holes.splice(holes.indexOf(hole), 1);\n }\n // There is at least a hole but it was unaffected\n if (!holeVectors.length && holes.length) {\n for (const hole of holes) {\n const points = hole.getPoints();\n const holePoints = [];\n for (const point of points) {\n holePoints.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\n }\n holeVectors.push(holePoints);\n }\n }\n // Extrusion!\n const mesh = ExtrudePolygon(name, {\n shape: shapeVectors,\n holes: holeVectors.length ? holeVectors : undefined,\n depth: options.depth || 1.0,\n sideOrientation: Mesh._GetDefaultSideOrientation(options.sideOrientation || Mesh.DOUBLESIDE),\n }, scene, earcutInjection);\n meshes.push(mesh);\n }\n }\n // Then we can merge everyone into one single mesh\n const newMesh = Mesh.MergeMeshes(meshes, true, true);\n if (newMesh) {\n // Move pivot to center\n const bbox = newMesh === null || newMesh === void 0 ? void 0 : newMesh.getBoundingInfo();\n newMesh.position.x = -(bbox === null || bbox === void 0 ? void 0 : bbox.boundingBox.extendSizeWorld._x);\n newMesh.position.y = -(bbox === null || bbox === void 0 ? void 0 : bbox.boundingBox.extendSizeWorld._y);\n newMesh.position.z = -(bbox === null || bbox === void 0 ? void 0 : bbox.boundingBox.extendSizeWorld._z);\n newMesh.name = name;\n newMesh.rotation.x = -Math.PI / 2;\n newMesh.bakeCurrentTransformIntoVertices();\n }\n return newMesh;\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /**\n * Class containing static functions to help procedurally build meshes\n */\n const MeshBuilder = {\n CreateBox,\n CreateTiledBox,\n CreateSphere,\n CreateDisc,\n CreateIcoSphere,\n CreateRibbon,\n CreateCylinder,\n CreateTorus,\n CreateTorusKnot,\n CreateLineSystem,\n CreateLines,\n CreateDashedLines,\n ExtrudeShape,\n ExtrudeShapeCustom,\n CreateLathe,\n CreateTiledPlane,\n CreatePlane,\n CreateGround,\n CreateTiledGround,\n CreateGroundFromHeightMap,\n CreatePolygon,\n ExtrudePolygon,\n CreateTube,\n CreatePolyhedron,\n CreateGeodesic,\n CreateGoldberg,\n CreateDecal,\n CreateCapsule,\n CreateText,\n };\n\n class GuiHelper {\n constructor(scene, highlighter) {\n this.scene = scene;\n this.highlighter = highlighter;\n this.textLabelMap = new Map();\n this.gridSettings = {};\n const cameraPosition = new Vector3();\n scene.registerBeforeRender(() => {\n if (scene.activeCamera && this.textLabelMap.size > 0) {\n this.textLabelMap.forEach(mesh => {\n const camera = scene.activeCamera;\n cameraPosition.copyFrom(getCameraPositionWithOffset(camera));\n mesh.lookAt(cameraPosition);\n if (camera.mode !== Camera.ORTHOGRAPHIC_CAMERA) {\n const size = cameraPosition.subtractInPlace(mesh.position).length() * 0.05;\n mesh.scaling = mesh.scaling.copyFromFloats(size, size, size);\n }\n });\n }\n });\n }\n enableGrid(sceneNode, skipOrigin = false) {\n if (this.gridSettings.gridMesh) {\n return;\n }\n const bgColor = sceneNode === null || sceneNode === void 0 ? void 0 : sceneNode.backgroundColor;\n let bgColor3;\n if (!bgColor) {\n bgColor3 = new Color3(this.scene.clearColor.r, this.scene.clearColor.g, this.scene.clearColor.b);\n }\n else {\n bgColor3 = bgColor.a === 0 ? Color3.Black() : new Color3(bgColor.r, bgColor.g, bgColor.b);\n }\n const gridStepSize = sceneNode.gridStepSize || 1;\n const gridSize = sceneNode.gridSize || 10;\n const gridNormal = sceneNode.gridNormal;\n const gridMajorInterval = sceneNode.gridMajorInterval || 0;\n const strongLineColor = Color4.FromColor3(bgColor3.toLuminance() > 0.5 ? Color3.Black() : Color3.White());\n const lightLineColor = strongLineColor.scale(0.4).add(Color4.FromColor3(bgColor3.scale(0.6)));\n const points = this.calculateGridPoints(gridStepSize, gridSize, gridNormal);\n const pointColors = [];\n const linesPerSide = points.length / 2;\n for (let s = 0; s < 2; s++) {\n for (let i = 0; i < linesPerSide; i++) {\n if (gridMajorInterval === 0) {\n pointColors.push([lightLineColor, lightLineColor]);\n }\n else if (Math.ceil(i / 2) % gridMajorInterval === 0) {\n pointColors.push([strongLineColor, strongLineColor]);\n }\n else {\n pointColors.push([lightLineColor, lightLineColor]);\n }\n }\n }\n if (skipOrigin) {\n points.splice(linesPerSide, 1);\n points.splice(0, 1);\n pointColors.splice(linesPerSide, 1);\n pointColors.splice(0, 1);\n }\n const gridMesh = MeshBuilder.CreateLineSystem('grid', {\n lines: points,\n colors: pointColors,\n updatable: false,\n }, this.scene);\n // gridMesh.color = lineColor.scale(0.4).add(bgColor3.scale(0.6));\n gridMesh.isPickable = false;\n this.gridSettings.gridMesh = gridMesh;\n }\n disableGrid() {\n if (this.gridSettings.gridMesh) {\n this.gridSettings.gridMesh.dispose();\n delete this.gridSettings.gridMesh;\n }\n }\n enableGridAxes(sceneNode) {\n if (this.gridSettings.gridAxesMesh) {\n return;\n }\n // const bgColor = sceneNode.backgroundColor;\n // let bgColor3: Color3;\n // if (!bgColor) {\n // bgColor3 = new Color3(this.scene.clearColor.r, this.scene.clearColor.g, this.scene.clearColor.b);\n // } else {\n // bgColor3 = bgColor.a === 0 ? Color3.Black() : new Color3(bgColor.r, bgColor.g, bgColor.b);\n // }\n // const lineColor = bgColor3.toLuminance() > 0.5 ? Color3.Black() : Color3.White();\n const gridStepSize = sceneNode.gridStepSize || 1;\n const gridSize = (sceneNode.gridSize || 10) * gridStepSize;\n const colors = [\n Color4.FromColor3(Color3.Red()),\n Color4.FromColor3(Color3.Green()),\n Color4.FromColor3(Color3.Blue()),\n ];\n const pointsAxes = [\n [new Vector3(-gridSize, 0, 0), new Vector3(gridSize, 0, 0)],\n [new Vector3(0, -gridSize, 0), new Vector3(0, gridSize, 0)],\n [new Vector3(0, 0, -gridSize), new Vector3(0, 0, gridSize)],\n ];\n const pointColors = [\n [colors[0], colors[0]],\n [colors[1], colors[1]],\n [colors[2], colors[2]],\n ];\n const gridMeshAxes = MeshBuilder.CreateLineSystem('gridAxes', {\n lines: pointsAxes,\n updatable: false,\n colors: pointColors,\n }, this.scene);\n gridMeshAxes.isPickable = false;\n this.gridSettings.gridAxesMesh = gridMeshAxes;\n this.createTextLabels([\n { text: 'x', position: new exports.KbVector(gridSize, 0.5, 0), color: colors[0] },\n { text: 'y', position: new exports.KbVector(0.5, gridSize, 0), color: colors[1] },\n { text: 'z', position: new exports.KbVector(0, 0.5, gridSize), color: colors[2] },\n ]);\n }\n disableGridAxes() {\n if (this.gridSettings.gridAxesMesh) {\n this.gridSettings.gridAxesMesh.dispose();\n delete this.gridSettings.gridAxesMesh;\n }\n }\n createTextLabels(items, style = {}) {\n if (!style.font) {\n style.font = 'bold 32px sans-serif';\n }\n items.forEach(label => {\n const font = label.style && label.style.font ? label.style.font : style.font;\n if (!label.id) {\n label.id = label.text;\n }\n if (this.textLabelMap.has(label.id)) {\n const labelMesh = this.textLabelMap.get(label.id);\n labelMesh.position = label.position.toVec3();\n }\n else {\n // Set height for plane\n const fontSize = parseInt(font.replace(/\\D+(\\d+)px.*/, '$1')) || 32;\n const planeHeight = fontSize / 32;\n const textureHeight = 2 * fontSize;\n const ratio = planeHeight / textureHeight;\n // Use a temporay canvas to calculate the length of the text\n const temp = document.createElement('canvas');\n temp.width = 64;\n temp.height = 64;\n const tmpctx = temp.getContext('2d');\n if (tmpctx) {\n tmpctx.font = font;\n const textureWidth = tmpctx.measureText(label.text).width + 8;\n temp.width = 0;\n temp.height = 0;\n // Create dynamic texture and write the text\n const dynamicId = `axisLabel${label.id}`;\n const planeWidth = textureWidth * ratio;\n const dynamicTexture = new DynamicTexture(dynamicId + '-labelTexture', { width: textureWidth, height: textureHeight }, this.scene, false);\n const mat = new StandardMaterial(dynamicId + '-labelMaterial', this.scene);\n mat.emissiveTexture = dynamicTexture;\n mat.diffuseTexture = dynamicTexture;\n mat.sideOrientation = Mesh.BACKSIDE;\n dynamicTexture.hasAlpha = true;\n dynamicTexture.drawText(label.text, null, null, font, label.color.toHexString(), 'rgba(0,0,0,0)', true);\n // Create plane and set dynamic texture as material\n const plane = MeshBuilder.CreatePlane(dynamicId, { width: planeWidth, height: planeHeight }, this.scene);\n plane.material = mat;\n plane.position = label.position.toVec3();\n plane.isPickable = false;\n this.textLabelMap.set(label.id, plane);\n }\n }\n });\n }\n calculateGridPoints(stepSize, gridCount, normal, gridFullSize) {\n const points = [];\n const wV1 = new Vector3(), wV2 = new Vector3(), vStep = new Vector3();\n if (gridFullSize === undefined) {\n gridFullSize = gridCount;\n }\n let uVec;\n let vVec;\n switch (normal) {\n case exports.eAxis.x:\n uVec = new Vector3(0, stepSize, 0);\n vVec = new Vector3(0, 0, stepSize);\n break;\n case exports.eAxis.y:\n uVec = new Vector3(stepSize, 0, 0);\n vVec = new Vector3(0, 0, stepSize);\n break;\n case exports.eAxis.z:\n uVec = new Vector3(stepSize, 0, 0);\n vVec = new Vector3(0, stepSize, 0);\n break;\n }\n wV1.setAll(0).addInPlace(vVec).scaleInPlace(-1).scaleInPlace(gridFullSize);\n wV2.setAll(0).scaleInPlace(-1).addInPlace(vVec).scaleInPlace(gridFullSize);\n for (let i = 0; i < gridCount * 2 + 1; i++) {\n const d = (2 * (i % 2) - 1) * Math.ceil(i / 2);\n vStep.copyFrom(uVec).scaleInPlace(d);\n points.push([wV1.add(vStep), wV2.add(vStep)]);\n }\n wV1.setAll(0).addInPlace(uVec).scaleInPlace(-1).scaleInPlace(gridFullSize);\n wV2.setAll(0).scaleInPlace(-1).addInPlace(uVec).scaleInPlace(gridFullSize);\n for (let i = 0; i < gridCount * 2 + 1; i++) {\n const d = (2 * (i % 2) - 1) * Math.ceil(i / 2);\n vStep.copyFrom(vVec).scaleInPlace(d);\n points.push([wV1.add(vStep), wV2.add(vStep)]);\n }\n return points;\n }\n }\n\n /*\n * Polyfill for createImageBitmap\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap\n *\n * Supports CanvasImageSource (img, video, canvas) sources, Blobs, and ImageData.\n *\n * From:\n * - https://dev.to/nektro/createimagebitmap-polyfill-for-safari-and-edge-228\n * - https://gist.github.com/MonsieurV/fb640c29084c171b4444184858a91bc7\n * Updated by:\n * - Yoan Tournade \n * - diachedelic, https://gist.github.com/diachedelic\n * - Paul Ellis, https://pseudosavant.com\n */\n (function createImageBitmapIIFE(global) {\n function isCanvasImageSource(el) {\n const validElements = ['img', 'video', 'canvas'];\n return el && el.tagName && validElements.includes(el.tagName.toLowerCase());\n }\n function idealSize(currentValue, newValue, numerator, denominator) {\n if (typeof newValue === 'number')\n return newValue;\n if (typeof numerator !== 'number' || typeof denominator !== 'number')\n return currentValue;\n return (numerator / denominator) * currentValue;\n }\n if (!('createImageBitmap' in global)) {\n global.createImageBitmap = async function polyfillCreateImageBitmap(data, opts) {\n return new Promise((resolve, reject) => {\n opts = opts || {};\n let dataURL;\n const canvas = document.createElement('canvas');\n try {\n const ctx = canvas.getContext('2d');\n if (data instanceof Blob) {\n dataURL = URL.createObjectURL(data);\n }\n else if (isCanvasImageSource(data)) {\n const width = data.naturalWidth || data.videoWidth || data.clientWidth || data.width;\n const height = data.naturalHeight || data.videoHeight || data.clientHeight || data.height;\n canvas.width = idealSize(width, opts.resizeWidth, opts.resizeHeight, height);\n canvas.height = idealSize(height, opts.resizeHeight, opts.resizeWidth, width);\n ctx.drawImage(data, 0, 0, canvas.width, canvas.height);\n dataURL = canvas.toDataURL();\n }\n else if (data instanceof ImageData) {\n canvas.width = idealSize(data.width, opts.resizeWidth, opts.resizeHeight, data.height);\n canvas.height = idealSize(data.height, opts.resizeHeight, opts.resizeWidth, data.width);\n ctx.putImageData(data, 0, 0);\n dataURL = canvas.toDataURL();\n }\n else {\n reject('createImageBitmap does not handle the provided image source type');\n }\n const img = new Image();\n img.onerror = reject;\n img.onload = () => resolve(img);\n img.src = dataURL;\n }\n finally {\n // avoid memory leaks on iOS Safari, see https://stackoverflow.com/a/52586606\n canvas.width = 0;\n canvas.height = 0;\n }\n });\n };\n }\n })(window);\n\n /**\n * Generic utilities for the babylon scene\n */\n /** returns the x,y pixel position of the node on the canvas */\n function nodeToScreen(bNode, camera) {\n camera = getCamera(camera);\n const nodeWorldPos = bNode.getAbsolutePosition(); // Vector3.TransformCoordinates(bNode.position, bNode.getWorldMatrix());\n return toScreen(nodeWorldPos, camera);\n }\n /** converts screen units */\n function toPixels(viewportUnits, camera) {\n camera = getCamera(camera);\n const canvasRect = camera.getEngine().getRenderingCanvasClientRect();\n return {\n x: viewportUnits.x * canvasRect.width,\n y: viewportUnits.y * canvasRect.height,\n };\n }\n /** returns the screen position as normalized device units a ratio from 0 to 1 */\n function toNDC(worldPos, camera) {\n camera = getCamera(camera);\n const pos = Vector3.Project(worldPos, Matrix.IdentityReadOnly, camera.getTransformationMatrix(), camera.viewport);\n return {\n x: pos.x,\n y: pos.y,\n };\n }\n function toScreen(worldPos, camera) {\n camera = getCamera(camera);\n const scene = camera.getScene();\n const engine = scene.getEngine();\n const pos = Vector3.Project(worldPos, Matrix.IdentityReadOnly, scene.getTransformMatrix(), camera.viewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight()));\n return {\n x: pos.x,\n y: pos.y,\n };\n }\n function getScreenBoundingBox(node, camera, includeDescendants = true) {\n camera = getCamera(camera);\n const bv = getHierarchyBoundingVectors(node, includeDescendants);\n return boundingVectorsToScreen(bv, camera);\n }\n // export function getBoundingVectors(bNode: AbstractMesh | TransformNode | undefined, scene: Scene, includeDescendants = true) {\n // let bv: { min: Vector3, max: Vector3 } | undefined;\n // if (!bNode) {\n // bv = scene.getWorldExtends();\n // } else {\n // bv = bNode.getHierarchyBoundingVectors(true);\n // if (bv.min.x == Number.MAX_VALUE && bv.min.y == Number.MAX_VALUE && bv.min.z == Number.MAX_VALUE && bv.max.x == -Number.MAX_VALUE && bv.max.y == -Number.MAX_VALUE && bv.max.z == -Number.MAX_VALUE) {\n // bv = {\n // min: bNode.absolutePosition.clone(),\n // max: bNode.absolutePosition.clone()\n // }\n // }\n // }\n // return bv;\n // }\n /**\n * Babylon's getHierarchyBoundingVectors has a bug that surfaces when called on a transformNode that has no real meshes in it's child hierarchy.\n * Use this wrapper instead\n * @param bNode\n * @param includeDescendants\n */\n function getHierarchyBoundingVectors(bNode, includeDescendants = true) {\n let bv = bNode.getHierarchyBoundingVectors(includeDescendants);\n //to handle a babylon bug that returns maxvalues when the node is an empty transformnode\n if (bv.min.x == Number.MAX_VALUE &&\n bv.min.y == Number.MAX_VALUE &&\n bv.min.z == Number.MAX_VALUE &&\n bv.max.x == -Number.MAX_VALUE &&\n bv.max.y == -Number.MAX_VALUE &&\n bv.max.z == -Number.MAX_VALUE) {\n bv = {\n min: bNode.absolutePosition.clone(),\n max: bNode.absolutePosition.clone(),\n };\n }\n return bv;\n }\n function boundingVectorsToScreen(boundingVectors, camera) {\n camera = getCamera(camera);\n const bv = boundingVectors;\n const xs = new Array();\n const ys = new Array();\n for (let i = 0; i < 8; i++) {\n const x = bv[Math.floor(i / 4) ? 'max' : 'min'].x;\n const y = bv[Math.floor(i / 2) % 2 ? 'max' : 'min'].y;\n const z = bv[i % 2 ? 'max' : 'min'].z;\n const v = new Vector3(x, y, z);\n const sp = toNDC(v, camera);\n xs.push(sp.x);\n ys.push(sp.y);\n }\n const minx = Math.min(...xs);\n const maxx = Math.max(...xs);\n const miny = Math.min(...ys);\n const maxy = Math.max(...ys);\n const width = maxx - minx;\n const height = maxy - miny;\n const x = minx + width / 2;\n const y = miny + height / 2;\n const engine = camera.getEngine();\n const canvas = engine.getRenderingCanvas();\n const canvasWidth = canvas.width * engine.getHardwareScalingLevel();\n const canvasHeight = canvas.height * engine.getHardwareScalingLevel();\n return {\n x: x * canvasWidth,\n y: y * canvasHeight,\n top: miny * canvasHeight,\n left: minx * canvasWidth,\n width: width * canvasWidth,\n height: height * canvasHeight,\n };\n }\n function updateMatrixOfAncestorChain(ancestor, child) {\n while (child != ancestor && child instanceof TransformNode) {\n child.computeWorldMatrix(true);\n child = child.parent;\n }\n if (child) {\n child.computeWorldMatrix(true);\n }\n }\n function getCamera(camera) {\n if (camera instanceof WebXRCamera) {\n return camera.rigCameras[0];\n }\n return camera;\n }\n\n (function (eWorkerTasks) {\n eWorkerTasks[\"usdConvertGeometry\"] = \"usdConvertGeometry\";\n eWorkerTasks[\"usdPackage\"] = \"usdPackageStart\";\n })(exports.eWorkerTasks || (exports.eWorkerTasks = {}));\n (function (eKB3DMessageType) {\n eKB3DMessageType[\"taskStart\"] = \"taskStart\";\n eKB3DMessageType[\"taskError\"] = \"taskError\";\n eKB3DMessageType[\"taskProgress\"] = \"taskProgress\";\n eKB3DMessageType[\"taskComplete\"] = \"taskComplete\";\n })(exports.eKB3DMessageType || (exports.eKB3DMessageType = {}));\n const THREAD_COUNT = 2;\n class Kb3dWorker {\n constructor() {\n this.workerPool = [];\n this.toggle = 0;\n this.requestsInFlight = new Map();\n if (!Kb3dWorker.workerPath) {\n throw Error('Worker Script path not set');\n }\n const workerPath = Kb3dWorker.workerPath;\n const content = `importScripts( \"${workerPath}\" );`;\n const workerBlobUrl = URL.createObjectURL(new Blob([content], { type: 'text/javascript' }));\n const workerReturnMessage = (event) => {\n if ('task' in event.data) {\n const data = event.data;\n const sub = this.requestsInFlight.get(data.taskId);\n if (sub) {\n // We have to remove the request from the inflight map first because the sub.next can trigger the dispose\n // But the sub.complete has to be after the sub.next\n if (data.type === exports.eKB3DMessageType.taskComplete) {\n this.requestsInFlight.delete(data.taskId);\n }\n if (data.type === exports.eKB3DMessageType.taskError) {\n sub.error(data.payload);\n }\n else {\n sub.next(data);\n }\n if (data.type === exports.eKB3DMessageType.taskComplete) {\n sub.complete();\n }\n }\n }\n };\n for (let i = 0; i < THREAD_COUNT; i++) {\n const newWorker = new Worker(workerBlobUrl);\n newWorker.onmessage = workerReturnMessage;\n this.workerPool.push(newWorker);\n }\n URL.revokeObjectURL(workerBlobUrl);\n }\n startTask(task, taskPayload, transfer) {\n const messagePayload = {\n type: exports.eKB3DMessageType.taskStart,\n task,\n taskId: UUID.generate(),\n payload: taskPayload,\n };\n this.workerPool[this.toggle].postMessage(messagePayload, transfer ? { transfer } : undefined);\n const sub = new Subject();\n this.requestsInFlight.set(messagePayload.taskId, sub);\n this.toggle = (this.toggle + 1) % THREAD_COUNT;\n return sub;\n }\n dispose() {\n this.workerPool.forEach(worker => {\n worker.terminate();\n });\n this.requestsInFlight.forEach(sub => {\n sub.error('Worker Terminated');\n sub.complete();\n });\n this.requestsInFlight.clear();\n }\n }\n Kb3dWorker.workerPath = '';\n\n var version = '18.5.0';\n\n /**\n * Tween.js - Licensed under the MIT license\n * https://github.com/tweenjs/tween.js\n * ----------------------------------------------\n *\n * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.\n * Thank you all, you're awesome!\n */\n\n\n var _Group = function () {\n \tthis._tweens = {};\n \tthis._tweensAddedDuringUpdate = {};\n };\n\n _Group.prototype = {\n \tgetAll: function () {\n\n \t\treturn Object.keys(this._tweens).map(function (tweenId) {\n \t\t\treturn this._tweens[tweenId];\n \t\t}.bind(this));\n\n \t},\n\n \tremoveAll: function () {\n\n \t\tthis._tweens = {};\n\n \t},\n\n \tadd: function (tween) {\n\n \t\tthis._tweens[tween.getId()] = tween;\n \t\tthis._tweensAddedDuringUpdate[tween.getId()] = tween;\n\n \t},\n\n \tremove: function (tween) {\n\n \t\tdelete this._tweens[tween.getId()];\n \t\tdelete this._tweensAddedDuringUpdate[tween.getId()];\n\n \t},\n\n \tupdate: function (time, preserve) {\n\n \t\tvar tweenIds = Object.keys(this._tweens);\n\n \t\tif (tweenIds.length === 0) {\n \t\t\treturn false;\n \t\t}\n\n \t\ttime = time !== undefined ? time : TWEEN.now();\n\n \t\t// Tweens are updated in \"batches\". If you add a new tween during an\n \t\t// update, then the new tween will be updated in the next batch.\n \t\t// If you remove a tween during an update, it may or may not be updated.\n \t\t// However, if the removed tween was added during the current batch,\n \t\t// then it will not be updated.\n \t\twhile (tweenIds.length > 0) {\n \t\t\tthis._tweensAddedDuringUpdate = {};\n\n \t\t\tfor (var i = 0; i < tweenIds.length; i++) {\n\n \t\t\t\tvar tween = this._tweens[tweenIds[i]];\n\n \t\t\t\tif (tween && tween.update(time) === false) {\n \t\t\t\t\ttween._isPlaying = false;\n\n \t\t\t\t\tif (!preserve) {\n \t\t\t\t\t\tdelete this._tweens[tweenIds[i]];\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n\n \t\t\ttweenIds = Object.keys(this._tweensAddedDuringUpdate);\n \t\t}\n\n \t\treturn true;\n\n \t}\n };\n\n var TWEEN = new _Group();\n\n TWEEN.Group = _Group;\n TWEEN._nextId = 0;\n TWEEN.nextId = function () {\n \treturn TWEEN._nextId++;\n };\n\n\n // Include a performance.now polyfill.\n // In node.js, use process.hrtime.\n if (typeof (self) === 'undefined' && typeof (process) !== 'undefined' && process.hrtime) {\n \tTWEEN.now = function () {\n \t\tvar time = process.hrtime();\n\n \t\t// Convert [seconds, nanoseconds] to milliseconds.\n \t\treturn time[0] * 1000 + time[1] / 1000000;\n \t};\n }\n // In a browser, use self.performance.now if it is available.\n else if (typeof (self) !== 'undefined' &&\n self.performance !== undefined &&\n \t\t self.performance.now !== undefined) {\n \t// This must be bound, because directly assigning this function\n \t// leads to an invocation exception in Chrome.\n \tTWEEN.now = self.performance.now.bind(self.performance);\n }\n // Use Date.now if it is available.\n else if (Date.now !== undefined) {\n \tTWEEN.now = Date.now;\n }\n // Otherwise, use 'new Date().getTime()'.\n else {\n \tTWEEN.now = function () {\n \t\treturn new Date().getTime();\n \t};\n }\n\n\n TWEEN.Tween = function (object, group) {\n \tthis._isPaused = false;\n \tthis._pauseStart = null;\n \tthis._object = object;\n \tthis._valuesStart = {};\n \tthis._valuesEnd = {};\n \tthis._valuesStartRepeat = {};\n \tthis._duration = 1000;\n \tthis._repeat = 0;\n \tthis._repeatDelayTime = undefined;\n \tthis._yoyo = false;\n \tthis._isPlaying = false;\n \tthis._reversed = false;\n \tthis._delayTime = 0;\n \tthis._startTime = null;\n \tthis._easingFunction = TWEEN.Easing.Linear.None;\n \tthis._interpolationFunction = TWEEN.Interpolation.Linear;\n \tthis._chainedTweens = [];\n \tthis._onStartCallback = null;\n \tthis._onStartCallbackFired = false;\n \tthis._onUpdateCallback = null;\n \tthis._onRepeatCallback = null;\n \tthis._onCompleteCallback = null;\n \tthis._onStopCallback = null;\n \tthis._group = group || TWEEN;\n \tthis._id = TWEEN.nextId();\n\n };\n\n TWEEN.Tween.prototype = {\n \tgetId: function () {\n \t\treturn this._id;\n \t},\n\n \tisPlaying: function () {\n \t\treturn this._isPlaying;\n \t},\n\n \tisPaused: function () {\n \t\treturn this._isPaused;\n \t},\n\n \tto: function (properties, duration) {\n\n \t\tthis._valuesEnd = Object.create(properties);\n\n \t\tif (duration !== undefined) {\n \t\t\tthis._duration = duration;\n \t\t}\n\n \t\treturn this;\n\n \t},\n\n \tduration: function duration(d) {\n \t\tthis._duration = d;\n \t\treturn this;\n \t},\n\n \tstart: function (time) {\n\n \t\tthis._group.add(this);\n\n \t\tthis._isPlaying = true;\n\n \t\tthis._isPaused = false;\n\n \t\tthis._onStartCallbackFired = false;\n\n \t\tthis._startTime = time !== undefined ? typeof time === 'string' ? TWEEN.now() + parseFloat(time) : time : TWEEN.now();\n \t\tthis._startTime += this._delayTime;\n\n \t\tfor (var property in this._valuesEnd) {\n\n \t\t\t// Check if an Array was provided as property value\n \t\t\tif (this._valuesEnd[property] instanceof Array) {\n\n \t\t\t\tif (this._valuesEnd[property].length === 0) {\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n\n \t\t\t\t// Create a local copy of the Array with the start value at the front\n \t\t\t\tthis._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]);\n\n \t\t\t}\n\n \t\t\t// If `to()` specifies a property that doesn't exist in the source object,\n \t\t\t// we should not set that property in the object\n \t\t\tif (this._object[property] === undefined) {\n \t\t\t\tcontinue;\n \t\t\t}\n\n \t\t\t// Save the starting value, but only once.\n \t\t\tif (typeof(this._valuesStart[property]) === 'undefined') {\n \t\t\t\tthis._valuesStart[property] = this._object[property];\n \t\t\t}\n\n \t\t\tif ((this._valuesStart[property] instanceof Array) === false) {\n \t\t\t\tthis._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings\n \t\t\t}\n\n \t\t\tthis._valuesStartRepeat[property] = this._valuesStart[property] || 0;\n\n \t\t}\n\n \t\treturn this;\n\n \t},\n\n \tstop: function () {\n\n \t\tif (!this._isPlaying) {\n \t\t\treturn this;\n \t\t}\n\n \t\tthis._group.remove(this);\n\n \t\tthis._isPlaying = false;\n\n \t\tthis._isPaused = false;\n\n \t\tif (this._onStopCallback !== null) {\n \t\t\tthis._onStopCallback(this._object);\n \t\t}\n\n \t\tthis.stopChainedTweens();\n \t\treturn this;\n\n \t},\n\n \tend: function () {\n\n \t\tthis.update(Infinity);\n \t\treturn this;\n\n \t},\n\n \tpause: function(time) {\n\n \t\tif (this._isPaused || !this._isPlaying) {\n \t\t\treturn this;\n \t\t}\n\n \t\tthis._isPaused = true;\n\n \t\tthis._pauseStart = time === undefined ? TWEEN.now() : time;\n\n \t\tthis._group.remove(this);\n\n \t\treturn this;\n\n \t},\n\n \tresume: function(time) {\n\n \t\tif (!this._isPaused || !this._isPlaying) {\n \t\t\treturn this;\n \t\t}\n\n \t\tthis._isPaused = false;\n\n \t\tthis._startTime += (time === undefined ? TWEEN.now() : time)\n \t\t\t- this._pauseStart;\n\n \t\tthis._pauseStart = 0;\n\n \t\tthis._group.add(this);\n\n \t\treturn this;\n\n \t},\n\n \tstopChainedTweens: function () {\n\n \t\tfor (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {\n \t\t\tthis._chainedTweens[i].stop();\n \t\t}\n\n \t},\n\n \tgroup: function (group) {\n \t\tthis._group = group;\n \t\treturn this;\n \t},\n\n \tdelay: function (amount) {\n\n \t\tthis._delayTime = amount;\n \t\treturn this;\n\n \t},\n\n \trepeat: function (times) {\n\n \t\tthis._repeat = times;\n \t\treturn this;\n\n \t},\n\n \trepeatDelay: function (amount) {\n\n \t\tthis._repeatDelayTime = amount;\n \t\treturn this;\n\n \t},\n\n \tyoyo: function (yoyo) {\n\n \t\tthis._yoyo = yoyo;\n \t\treturn this;\n\n \t},\n\n \teasing: function (easingFunction) {\n\n \t\tthis._easingFunction = easingFunction;\n \t\treturn this;\n\n \t},\n\n \tinterpolation: function (interpolationFunction) {\n\n \t\tthis._interpolationFunction = interpolationFunction;\n \t\treturn this;\n\n \t},\n\n \tchain: function () {\n\n \t\tthis._chainedTweens = arguments;\n \t\treturn this;\n\n \t},\n\n \tonStart: function (callback) {\n\n \t\tthis._onStartCallback = callback;\n \t\treturn this;\n\n \t},\n\n \tonUpdate: function (callback) {\n\n \t\tthis._onUpdateCallback = callback;\n \t\treturn this;\n\n \t},\n\n \tonRepeat: function onRepeat(callback) {\n\n \t\tthis._onRepeatCallback = callback;\n \t\treturn this;\n\n \t},\n\n \tonComplete: function (callback) {\n\n \t\tthis._onCompleteCallback = callback;\n \t\treturn this;\n\n \t},\n\n \tonStop: function (callback) {\n\n \t\tthis._onStopCallback = callback;\n \t\treturn this;\n\n \t},\n\n \tupdate: function (time) {\n\n \t\tvar property;\n \t\tvar elapsed;\n \t\tvar value;\n\n \t\tif (time < this._startTime) {\n \t\t\treturn true;\n \t\t}\n\n \t\tif (this._onStartCallbackFired === false) {\n\n \t\t\tif (this._onStartCallback !== null) {\n \t\t\t\tthis._onStartCallback(this._object);\n \t\t\t}\n\n \t\t\tthis._onStartCallbackFired = true;\n \t\t}\n\n \t\telapsed = (time - this._startTime) / this._duration;\n \t\telapsed = (this._duration === 0 || elapsed > 1) ? 1 : elapsed;\n\n \t\tvalue = this._easingFunction(elapsed);\n\n \t\tfor (property in this._valuesEnd) {\n\n \t\t\t// Don't update properties that do not exist in the source object\n \t\t\tif (this._valuesStart[property] === undefined) {\n \t\t\t\tcontinue;\n \t\t\t}\n\n \t\t\tvar start = this._valuesStart[property] || 0;\n \t\t\tvar end = this._valuesEnd[property];\n\n \t\t\tif (end instanceof Array) {\n\n \t\t\t\tthis._object[property] = this._interpolationFunction(end, value);\n\n \t\t\t} else {\n\n \t\t\t\t// Parses relative end values with start as base (e.g.: +10, -3)\n \t\t\t\tif (typeof (end) === 'string') {\n\n \t\t\t\t\tif (end.charAt(0) === '+' || end.charAt(0) === '-') {\n \t\t\t\t\t\tend = start + parseFloat(end);\n \t\t\t\t\t} else {\n \t\t\t\t\t\tend = parseFloat(end);\n \t\t\t\t\t}\n \t\t\t\t}\n\n \t\t\t\t// Protect against non numeric properties.\n \t\t\t\tif (typeof (end) === 'number') {\n \t\t\t\t\tthis._object[property] = start + (end - start) * value;\n \t\t\t\t}\n\n \t\t\t}\n\n \t\t}\n\n \t\tif (this._onUpdateCallback !== null) {\n \t\t\tthis._onUpdateCallback(this._object, elapsed);\n \t\t}\n\n \t\tif (elapsed === 1) {\n\n \t\t\tif (this._repeat > 0) {\n\n \t\t\t\tif (isFinite(this._repeat)) {\n \t\t\t\t\tthis._repeat--;\n \t\t\t\t}\n\n \t\t\t\t// Reassign starting values, restart by making startTime = now\n \t\t\t\tfor (property in this._valuesStartRepeat) {\n\n \t\t\t\t\tif (typeof (this._valuesEnd[property]) === 'string') {\n \t\t\t\t\t\tthis._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);\n \t\t\t\t\t}\n\n \t\t\t\t\tif (this._yoyo) {\n \t\t\t\t\t\tvar tmp = this._valuesStartRepeat[property];\n\n \t\t\t\t\t\tthis._valuesStartRepeat[property] = this._valuesEnd[property];\n \t\t\t\t\t\tthis._valuesEnd[property] = tmp;\n \t\t\t\t\t}\n\n \t\t\t\t\tthis._valuesStart[property] = this._valuesStartRepeat[property];\n\n \t\t\t\t}\n\n \t\t\t\tif (this._yoyo) {\n \t\t\t\t\tthis._reversed = !this._reversed;\n \t\t\t\t}\n\n \t\t\t\tif (this._repeatDelayTime !== undefined) {\n \t\t\t\t\tthis._startTime = time + this._repeatDelayTime;\n \t\t\t\t} else {\n \t\t\t\t\tthis._startTime = time + this._delayTime;\n \t\t\t\t}\n\n \t\t\t\tif (this._onRepeatCallback !== null) {\n \t\t\t\t\tthis._onRepeatCallback(this._object);\n \t\t\t\t}\n\n \t\t\t\treturn true;\n\n \t\t\t} else {\n\n \t\t\t\tif (this._onCompleteCallback !== null) {\n\n \t\t\t\t\tthis._onCompleteCallback(this._object);\n \t\t\t\t}\n\n \t\t\t\tfor (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {\n \t\t\t\t\t// Make the chained tweens start exactly at the time they should,\n \t\t\t\t\t// even if the `update()` method was called way past the duration of the tween\n \t\t\t\t\tthis._chainedTweens[i].start(this._startTime + this._duration);\n \t\t\t\t}\n\n \t\t\t\treturn false;\n\n \t\t\t}\n\n \t\t}\n\n \t\treturn true;\n\n \t}\n };\n\n\n TWEEN.Easing = {\n\n \tLinear: {\n\n \t\tNone: function (k) {\n\n \t\t\treturn k;\n\n \t\t}\n\n \t},\n\n \tQuadratic: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn k * k;\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn k * (2 - k);\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn 0.5 * k * k;\n \t\t\t}\n\n \t\t\treturn - 0.5 * (--k * (k - 2) - 1);\n\n \t\t}\n\n \t},\n\n \tCubic: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn k * k * k;\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn --k * k * k + 1;\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn 0.5 * k * k * k;\n \t\t\t}\n\n \t\t\treturn 0.5 * ((k -= 2) * k * k + 2);\n\n \t\t}\n\n \t},\n\n \tQuartic: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn k * k * k * k;\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn 1 - (--k * k * k * k);\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn 0.5 * k * k * k * k;\n \t\t\t}\n\n \t\t\treturn - 0.5 * ((k -= 2) * k * k * k - 2);\n\n \t\t}\n\n \t},\n\n \tQuintic: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn k * k * k * k * k;\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn --k * k * k * k * k + 1;\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn 0.5 * k * k * k * k * k;\n \t\t\t}\n\n \t\t\treturn 0.5 * ((k -= 2) * k * k * k * k + 2);\n\n \t\t}\n\n \t},\n\n \tSinusoidal: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn 1 - Math.cos(k * Math.PI / 2);\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn Math.sin(k * Math.PI / 2);\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\treturn 0.5 * (1 - Math.cos(Math.PI * k));\n\n \t\t}\n\n \t},\n\n \tExponential: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn k === 0 ? 0 : Math.pow(1024, k - 1);\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn k === 1 ? 1 : 1 - Math.pow(2, - 10 * k);\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif (k === 0) {\n \t\t\t\treturn 0;\n \t\t\t}\n\n \t\t\tif (k === 1) {\n \t\t\t\treturn 1;\n \t\t\t}\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn 0.5 * Math.pow(1024, k - 1);\n \t\t\t}\n\n \t\t\treturn 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2);\n\n \t\t}\n\n \t},\n\n \tCircular: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn 1 - Math.sqrt(1 - k * k);\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\treturn Math.sqrt(1 - (--k * k));\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn - 0.5 * (Math.sqrt(1 - k * k) - 1);\n \t\t\t}\n\n \t\t\treturn 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);\n\n \t\t}\n\n \t},\n\n \tElastic: {\n\n \t\tIn: function (k) {\n\n \t\t\tif (k === 0) {\n \t\t\t\treturn 0;\n \t\t\t}\n\n \t\t\tif (k === 1) {\n \t\t\t\treturn 1;\n \t\t\t}\n\n \t\t\treturn -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\tif (k === 0) {\n \t\t\t\treturn 0;\n \t\t\t}\n\n \t\t\tif (k === 1) {\n \t\t\t\treturn 1;\n \t\t\t}\n\n \t\t\treturn Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1;\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif (k === 0) {\n \t\t\t\treturn 0;\n \t\t\t}\n\n \t\t\tif (k === 1) {\n \t\t\t\treturn 1;\n \t\t\t}\n\n \t\t\tk *= 2;\n\n \t\t\tif (k < 1) {\n \t\t\t\treturn -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);\n \t\t\t}\n\n \t\t\treturn 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1;\n\n \t\t}\n\n \t},\n\n \tBack: {\n\n \t\tIn: function (k) {\n\n \t\t\tvar s = 1.70158;\n\n \t\t\treturn k * k * ((s + 1) * k - s);\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\tvar s = 1.70158;\n\n \t\t\treturn --k * k * ((s + 1) * k + s) + 1;\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tvar s = 1.70158 * 1.525;\n\n \t\t\tif ((k *= 2) < 1) {\n \t\t\t\treturn 0.5 * (k * k * ((s + 1) * k - s));\n \t\t\t}\n\n \t\t\treturn 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);\n\n \t\t}\n\n \t},\n\n \tBounce: {\n\n \t\tIn: function (k) {\n\n \t\t\treturn 1 - TWEEN.Easing.Bounce.Out(1 - k);\n\n \t\t},\n\n \t\tOut: function (k) {\n\n \t\t\tif (k < (1 / 2.75)) {\n \t\t\t\treturn 7.5625 * k * k;\n \t\t\t} else if (k < (2 / 2.75)) {\n \t\t\t\treturn 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;\n \t\t\t} else if (k < (2.5 / 2.75)) {\n \t\t\t\treturn 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;\n \t\t\t} else {\n \t\t\t\treturn 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;\n \t\t\t}\n\n \t\t},\n\n \t\tInOut: function (k) {\n\n \t\t\tif (k < 0.5) {\n \t\t\t\treturn TWEEN.Easing.Bounce.In(k * 2) * 0.5;\n \t\t\t}\n\n \t\t\treturn TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;\n\n \t\t}\n\n \t}\n\n };\n\n TWEEN.Interpolation = {\n\n \tLinear: function (v, k) {\n\n \t\tvar m = v.length - 1;\n \t\tvar f = m * k;\n \t\tvar i = Math.floor(f);\n \t\tvar fn = TWEEN.Interpolation.Utils.Linear;\n\n \t\tif (k < 0) {\n \t\t\treturn fn(v[0], v[1], f);\n \t\t}\n\n \t\tif (k > 1) {\n \t\t\treturn fn(v[m], v[m - 1], m - f);\n \t\t}\n\n \t\treturn fn(v[i], v[i + 1 > m ? m : i + 1], f - i);\n\n \t},\n\n \tBezier: function (v, k) {\n\n \t\tvar b = 0;\n \t\tvar n = v.length - 1;\n \t\tvar pw = Math.pow;\n \t\tvar bn = TWEEN.Interpolation.Utils.Bernstein;\n\n \t\tfor (var i = 0; i <= n; i++) {\n \t\t\tb += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);\n \t\t}\n\n \t\treturn b;\n\n \t},\n\n \tCatmullRom: function (v, k) {\n\n \t\tvar m = v.length - 1;\n \t\tvar f = m * k;\n \t\tvar i = Math.floor(f);\n \t\tvar fn = TWEEN.Interpolation.Utils.CatmullRom;\n\n \t\tif (v[0] === v[m]) {\n\n \t\t\tif (k < 0) {\n \t\t\t\ti = Math.floor(f = m * (1 + k));\n \t\t\t}\n\n \t\t\treturn fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);\n\n \t\t} else {\n\n \t\t\tif (k < 0) {\n \t\t\t\treturn v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);\n \t\t\t}\n\n \t\t\tif (k > 1) {\n \t\t\t\treturn v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);\n \t\t\t}\n\n \t\t\treturn fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);\n\n \t\t}\n\n \t},\n\n \tUtils: {\n\n \t\tLinear: function (p0, p1, t) {\n\n \t\t\treturn (p1 - p0) * t + p0;\n\n \t\t},\n\n \t\tBernstein: function (n, i) {\n\n \t\t\tvar fc = TWEEN.Interpolation.Utils.Factorial;\n\n \t\t\treturn fc(n) / fc(i) / fc(n - i);\n\n \t\t},\n\n \t\tFactorial: (function () {\n\n \t\t\tvar a = [1];\n\n \t\t\treturn function (n) {\n\n \t\t\t\tvar s = 1;\n\n \t\t\t\tif (a[n]) {\n \t\t\t\t\treturn a[n];\n \t\t\t\t}\n\n \t\t\t\tfor (var i = n; i > 1; i--) {\n \t\t\t\t\ts *= i;\n \t\t\t\t}\n\n \t\t\t\ta[n] = s;\n \t\t\t\treturn s;\n\n \t\t\t};\n\n \t\t})(),\n\n \t\tCatmullRom: function (p0, p1, p2, p3, t) {\n\n \t\t\tvar v0 = (p2 - p0) * 0.5;\n \t\t\tvar v1 = (p3 - p1) * 0.5;\n \t\t\tvar t2 = t * t;\n \t\t\tvar t3 = t * t2;\n\n \t\t\treturn (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;\n\n \t\t}\n\n \t}\n\n };\n TWEEN.version = version;\n\n class AnimationModule {\n constructor(kbViewer, scene) {\n this.kbViewer = kbViewer;\n this.scene = scene;\n this.activeAnimations = new Set();\n }\n get animationsAreRunning() {\n return this.activeAnimations.size > 0;\n }\n queue(a) {\n if (!a.node)\n throw 'node required';\n if (a.toValue == null)\n throw 'value required';\n a = this.applyDefaults(a);\n return new Promise(resolve => {\n const origValue = a.node[a.prop];\n const origValueType = origValue === null || origValue === void 0 ? void 0 : origValue.$type;\n const val = this.valueIn(origValue);\n const toVal = this.valueIn(a.toValue);\n const tween = new TWEEN.Tween(val)\n .to(toVal, a.duration)\n .delay(a.delay)\n .repeat(a.iterations < 0 ? Infinity : a.iterations - 1)\n .easing(this.getTweenEasingFn(a.easing))\n .onUpdate(() => {\n a.node[a.prop] = this.valueOut(val, origValueType);\n })\n .onComplete(() => {\n this.activeAnimations.delete(activeAnim);\n resolve();\n })\n .start();\n const activeAnim = { animation: a, tween };\n this.activeAnimations.add(activeAnim);\n this.kbViewer.animationWarningsNeedsUpdate.next(this.activeAnimations.size);\n });\n }\n stop(name) {\n if (name != null) {\n const anims = [...this.activeAnimations.values()];\n for (const t of anims.filter(a => name.isEqual(a.animation.name))) {\n t.tween.stop();\n this.activeAnimations.delete(t);\n }\n }\n }\n stopAll() {\n for (const a of this.activeAnimations) {\n a.tween.stop();\n }\n this.activeAnimations.clear();\n }\n /** should be called by the render loop */\n update() {\n TWEEN.update(); //update all animations\n }\n applyDefaults(a) {\n return {\n duration: 1000,\n easing: exports.eEasing.linear,\n iterations: 1,\n delay: 0,\n ...a,\n };\n }\n valueIn(val) {\n if (val instanceof exports.KbVector) {\n return val.toObject();\n }\n else if (val instanceof exports.KbColor) {\n return val.toObject();\n }\n else if (val instanceof exports.KbQuaternion) {\n return val.toObject();\n }\n else {\n return { value: val };\n }\n }\n valueOut(val, $type) {\n if (!$type) {\n return val.value;\n }\n else {\n if ($type == Token.KbVector.key) {\n return exports.KbVector.From(val);\n }\n else if ($type == Token.KbColor.key) {\n return exports.KbColor.From(val);\n }\n else if ($type == Token.KbQuaternion.key) {\n return exports.KbQuaternion.From(val);\n }\n else {\n throw 'unrecognized type';\n }\n }\n }\n getTweenEasingFn(e) {\n const split = e.splitWords().map(s => s.capitalize());\n const inOut = split.length == 3 ? split[1] + split[2] : split.length == 2 ? split[1] : 'None';\n return TWEEN.Easing[split[0]][inOut];\n }\n }\n\n let anchorIdProvider = 0;\n /**\n * An implementation of the anchor system for WebXR.\n * For further information see https://github.com/immersive-web/anchors/\n */\n class WebXRAnchorSystem extends WebXRAbstractFeature {\n /**\n * Set the reference space to use for anchor creation, when not using a hit test.\n * Will default to the session's reference space if not defined\n */\n set referenceSpaceForFrameAnchors(referenceSpace) {\n this._referenceSpaceForFrameAnchors = referenceSpace;\n }\n /**\n * constructs a new anchor system\n * @param _xrSessionManager an instance of WebXRSessionManager\n * @param _options configuration object for this feature\n */\n constructor(_xrSessionManager, _options = {}) {\n super(_xrSessionManager);\n this._options = _options;\n this._lastFrameDetected = new Set();\n this._trackedAnchors = [];\n this._futureAnchors = [];\n /**\n * Observers registered here will be executed when a new anchor was added to the session\n */\n this.onAnchorAddedObservable = new Observable$1();\n /**\n * Observers registered here will be executed when an anchor was removed from the session\n */\n this.onAnchorRemovedObservable = new Observable$1();\n /**\n * Observers registered here will be executed when an existing anchor updates\n * This can execute N times every frame\n */\n this.onAnchorUpdatedObservable = new Observable$1();\n this._tmpVector = new Vector3();\n this._tmpQuaternion = new Quaternion();\n this.xrNativeFeatureName = \"anchors\";\n }\n _populateTmpTransformation(position, rotationQuaternion) {\n this._tmpVector.copyFrom(position);\n this._tmpQuaternion.copyFrom(rotationQuaternion);\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\n this._tmpVector.z *= -1;\n this._tmpQuaternion.z *= -1;\n this._tmpQuaternion.w *= -1;\n }\n return {\n position: this._tmpVector,\n rotationQuaternion: this._tmpQuaternion,\n };\n }\n /**\n * Create a new anchor point using a hit test result at a specific point in the scene\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\n *\n * @param hitTestResult The hit test result to use for this anchor creation\n * @param position an optional position offset for this anchor\n * @param rotationQuaternion an optional rotation offset for this anchor\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\n */\n async addAnchorPointUsingHitTestResultAsync(hitTestResult, position = new Vector3(), rotationQuaternion = new Quaternion()) {\n // convert to XR space (right handed) if needed\n this._populateTmpTransformation(position, rotationQuaternion);\n // the matrix that we'll use\n const m = new XRRigidTransform({ x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z }, { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w });\n if (!hitTestResult.xrHitResult.createAnchor) {\n this.detach();\n throw new Error(\"Anchors not enabled in this environment/browser\");\n }\n else {\n try {\n const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\n return new Promise((resolve, reject) => {\n this._futureAnchors.push({\n nativeAnchor,\n resolved: false,\n submitted: true,\n xrTransformation: m,\n resolve,\n reject,\n });\n });\n }\n catch (error) {\n throw new Error(error);\n }\n }\n }\n /**\n * Add a new anchor at a specific position and rotation\n * This function will add a new anchor per default in the next available frame. Unless forced, the createAnchor function\n * will be called in the next xrFrame loop to make sure that the anchor can be created correctly.\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\n *\n * @param position the position in which to add an anchor\n * @param rotationQuaternion an optional rotation for the anchor transformation\n * @param forceCreateInCurrentFrame force the creation of this anchor in the current frame. Must be called inside xrFrame loop!\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\n */\n async addAnchorAtPositionAndRotationAsync(position, rotationQuaternion = new Quaternion(), forceCreateInCurrentFrame = false) {\n // convert to XR space (right handed) if needed\n this._populateTmpTransformation(position, rotationQuaternion);\n // the matrix that we'll use\n const xrTransformation = new XRRigidTransform({ x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z }, { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w });\n const xrAnchor = forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame\n ? await this._createAnchorAtTransformation(xrTransformation, this._xrSessionManager.currentFrame)\n : undefined;\n // add the transformation to the future anchors list\n return new Promise((resolve, reject) => {\n this._futureAnchors.push({\n nativeAnchor: xrAnchor,\n resolved: false,\n submitted: false,\n xrTransformation,\n resolve,\n reject,\n });\n });\n }\n /**\n * Get the list of anchors currently being tracked by the system\n */\n get anchors() {\n return this._trackedAnchors;\n }\n /**\n * detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n if (!this._options.doNotRemoveAnchorsOnSessionEnded) {\n while (this._trackedAnchors.length) {\n const toRemove = this._trackedAnchors.pop();\n if (toRemove) {\n try {\n // try to natively remove it as well\n toRemove.remove();\n }\n catch (e) {\n // no-op\n }\n // as the xr frame loop is removed, we need to notify manually\n this.onAnchorRemovedObservable.notifyObservers(toRemove);\n }\n }\n }\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n this._futureAnchors.length = 0;\n super.dispose();\n this.onAnchorAddedObservable.clear();\n this.onAnchorRemovedObservable.clear();\n this.onAnchorUpdatedObservable.clear();\n }\n _onXRFrame(frame) {\n if (!this.attached || !frame) {\n return;\n }\n const trackedAnchors = frame.trackedAnchors;\n if (trackedAnchors) {\n const toRemove = this._trackedAnchors\n .filter((anchor) => !trackedAnchors.has(anchor.xrAnchor))\n .map((anchor) => {\n const index = this._trackedAnchors.indexOf(anchor);\n return index;\n });\n let idxTracker = 0;\n toRemove.forEach((index) => {\n const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];\n this.onAnchorRemovedObservable.notifyObservers(anchor);\n idxTracker++;\n });\n // now check for new ones\n trackedAnchors.forEach((xrAnchor) => {\n if (!this._lastFrameDetected.has(xrAnchor)) {\n const newAnchor = {\n id: anchorIdProvider++,\n xrAnchor: xrAnchor,\n remove: () => xrAnchor.delete(),\n };\n const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);\n this._trackedAnchors.push(anchor);\n this.onAnchorAddedObservable.notifyObservers(anchor);\n // search for the future anchor promise that matches this\n const results = this._futureAnchors.filter((futureAnchor) => futureAnchor.nativeAnchor === xrAnchor);\n const result = results[0];\n if (result) {\n result.resolve(anchor);\n result.resolved = true;\n }\n }\n else {\n const index = this._findIndexInAnchorArray(xrAnchor);\n const anchor = this._trackedAnchors[index];\n try {\n // anchors update every frame\n this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);\n if (anchor.attachedNode) {\n anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();\n anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);\n }\n this.onAnchorUpdatedObservable.notifyObservers(anchor);\n }\n catch (e) {\n Tools.Warn(`Anchor could not be updated`);\n }\n }\n });\n this._lastFrameDetected = trackedAnchors;\n }\n // process future anchors\n this._futureAnchors.forEach((futureAnchor) => {\n if (!futureAnchor.resolved && !futureAnchor.submitted) {\n this._createAnchorAtTransformation(futureAnchor.xrTransformation, frame).then((nativeAnchor) => {\n futureAnchor.nativeAnchor = nativeAnchor;\n }, (error) => {\n futureAnchor.resolved = true;\n futureAnchor.reject(error);\n });\n futureAnchor.submitted = true;\n }\n });\n }\n /**\n * avoiding using Array.find for global support.\n * @param xrAnchor the plane to find in the array\n */\n _findIndexInAnchorArray(xrAnchor) {\n for (let i = 0; i < this._trackedAnchors.length; ++i) {\n if (this._trackedAnchors[i].xrAnchor === xrAnchor) {\n return i;\n }\n }\n return -1;\n }\n _updateAnchorWithXRFrame(xrAnchor, anchor, xrFrame) {\n // matrix\n const pose = xrFrame.getPose(xrAnchor.anchorSpace, this._xrSessionManager.referenceSpace);\n if (pose) {\n const mat = anchor.transformationMatrix || new Matrix();\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\n mat.toggleModelMatrixHandInPlace();\n }\n anchor.transformationMatrix = mat;\n if (!this._options.worldParentNode) ;\n else {\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\n }\n }\n return anchor;\n }\n async _createAnchorAtTransformation(xrTransformation, xrFrame) {\n var _a;\n if (xrFrame.createAnchor) {\n try {\n return xrFrame.createAnchor(xrTransformation, (_a = this._referenceSpaceForFrameAnchors) !== null && _a !== void 0 ? _a : this._xrSessionManager.referenceSpace);\n }\n catch (error) {\n throw new Error(error);\n }\n }\n else {\n this.detach();\n throw new Error(\"Anchors are not enabled in your browser\");\n }\n }\n }\n /**\n * The module's name\n */\n WebXRAnchorSystem.Name = WebXRFeatureName.ANCHOR_SYSTEM;\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\n WebXRAnchorSystem.Version = 1;\n // register the plugin\n WebXRFeaturesManager.AddWebXRFeature(WebXRAnchorSystem.Name, (xrSessionManager, options) => {\n return () => new WebXRAnchorSystem(xrSessionManager, options);\n }, WebXRAnchorSystem.Version);\n\n /**\n * The currently-working hit-test module.\n * Hit test (or Ray-casting) is used to interact with the real world.\n * For further information read here - https://github.com/immersive-web/hit-test\n *\n * Tested on chrome (mobile) 80.\n */\n class WebXRHitTest extends WebXRAbstractFeature {\n /**\n * Creates a new instance of the hit test feature\n * @param _xrSessionManager an instance of WebXRSessionManager\n * @param options options to use when constructing this feature\n */\n constructor(_xrSessionManager, \n /**\n * options to use when constructing this feature\n */\n options = {}) {\n super(_xrSessionManager);\n this.options = options;\n this._tmpMat = new Matrix();\n this._tmpPos = new Vector3();\n this._tmpQuat = new Quaternion();\n this._initHitTestSource = (referenceSpace) => {\n if (!referenceSpace) {\n return;\n }\n const offsetRay = new XRRay(this.options.offsetRay || {});\n const hitTestOptions = {\n space: this.options.useReferenceSpace ? referenceSpace : this._xrSessionManager.viewerReferenceSpace,\n offsetRay: offsetRay,\n };\n if (this.options.entityTypes) {\n hitTestOptions.entityTypes = this.options.entityTypes;\n }\n if (!hitTestOptions.space) {\n Tools.Warn(\"waiting for viewer reference space to initialize\");\n return;\n }\n this._xrSessionManager.session.requestHitTestSource(hitTestOptions).then((hitTestSource) => {\n if (this._xrHitTestSource) {\n this._xrHitTestSource.cancel();\n }\n this._xrHitTestSource = hitTestSource;\n });\n };\n /**\n * When set to true, each hit test will have its own position/rotation objects\n * When set to false, position and rotation objects will be reused for each hit test. It is expected that\n * the developers will clone them or copy them as they see fit.\n */\n this.autoCloneTransformation = false;\n /**\n * Triggered when new babylon (transformed) hit test results are available\n * Note - this will be called when results come back from the device. It can be an empty array!!\n */\n this.onHitTestResultObservable = new Observable$1();\n /**\n * Use this to temporarily pause hit test checks.\n */\n this.paused = false;\n this.xrNativeFeatureName = \"hit-test\";\n Tools.Warn(\"Hit test is an experimental and unstable feature.\");\n }\n /**\n * attach this feature\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n attach() {\n if (!super.attach()) {\n return false;\n }\n // Feature enabled, but not available\n if (!this._xrSessionManager.session.requestHitTestSource) {\n return false;\n }\n if (!this.options.disablePermanentHitTest) {\n if (this._xrSessionManager.referenceSpace) {\n this._initHitTestSource(this._xrSessionManager.referenceSpace);\n }\n this._xrSessionManager.onXRReferenceSpaceChanged.add(this._initHitTestSource);\n }\n if (this.options.enableTransientHitTest) {\n const offsetRay = new XRRay(this.options.transientOffsetRay || {});\n this._xrSessionManager.session.requestHitTestSourceForTransientInput({\n profile: this.options.transientHitTestProfile || \"generic-touchscreen\",\n offsetRay,\n entityTypes: this.options.entityTypes,\n }).then((hitSource) => {\n this._transientXrHitTestSource = hitSource;\n });\n }\n return true;\n }\n /**\n * detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n if (this._xrHitTestSource) {\n this._xrHitTestSource.cancel();\n this._xrHitTestSource = null;\n }\n this._xrSessionManager.onXRReferenceSpaceChanged.removeCallback(this._initHitTestSource);\n if (this._transientXrHitTestSource) {\n this._transientXrHitTestSource.cancel();\n this._transientXrHitTestSource = null;\n }\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n super.dispose();\n this.onHitTestResultObservable.clear();\n }\n _onXRFrame(frame) {\n // make sure we do nothing if (async) not attached\n if (!this.attached || this.paused) {\n return;\n }\n if (this._xrHitTestSource) {\n const results = frame.getHitTestResults(this._xrHitTestSource);\n this._processWebXRHitTestResult(results);\n }\n if (this._transientXrHitTestSource) {\n const hitTestResultsPerInputSource = frame.getHitTestResultsForTransientInput(this._transientXrHitTestSource);\n hitTestResultsPerInputSource.forEach((resultsPerInputSource) => {\n this._processWebXRHitTestResult(resultsPerInputSource.results, resultsPerInputSource.inputSource);\n });\n }\n }\n _processWebXRHitTestResult(hitTestResults, inputSource) {\n const results = [];\n hitTestResults.forEach((hitTestResult) => {\n const pose = hitTestResult.getPose(this._xrSessionManager.referenceSpace);\n if (!pose) {\n return;\n }\n const pos = pose.transform.position;\n const quat = pose.transform.orientation;\n this._tmpPos.set(pos.x, pos.y, pos.z);\n this._tmpQuat.set(quat.x, quat.y, quat.z, quat.w);\n Matrix.FromFloat32ArrayToRefScaled(pose.transform.matrix, 0, 1, this._tmpMat);\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\n this._tmpPos.z *= -1;\n this._tmpQuat.z *= -1;\n this._tmpQuat.w *= -1;\n this._tmpMat.toggleModelMatrixHandInPlace();\n }\n const result = {\n position: this.autoCloneTransformation ? this._tmpPos.clone() : this._tmpPos,\n rotationQuaternion: this.autoCloneTransformation ? this._tmpQuat.clone() : this._tmpQuat,\n transformationMatrix: this.autoCloneTransformation ? this._tmpMat.clone() : this._tmpMat,\n inputSource: inputSource,\n isTransient: !!inputSource,\n xrHitResult: hitTestResult,\n };\n results.push(result);\n });\n this.onHitTestResultObservable.notifyObservers(results);\n }\n }\n /**\n * The module's name\n */\n WebXRHitTest.Name = WebXRFeatureName.HIT_TEST;\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\n WebXRHitTest.Version = 2;\n //register the plugin versions\n WebXRFeaturesManager.AddWebXRFeature(WebXRHitTest.Name, (xrSessionManager, options) => {\n return () => new WebXRHitTest(xrSessionManager, options);\n }, WebXRHitTest.Version, false);\n\n let planeIdProvider = 0;\n /**\n * The plane detector is used to detect planes in the real world when in AR\n * For more information see https://github.com/immersive-web/real-world-geometry/\n */\n class WebXRPlaneDetector extends WebXRAbstractFeature {\n /**\n * construct a new Plane Detector\n * @param _xrSessionManager an instance of xr Session manager\n * @param _options configuration to use when constructing this feature\n */\n constructor(_xrSessionManager, _options = {}) {\n super(_xrSessionManager);\n this._options = _options;\n this._detectedPlanes = [];\n this._enabled = false;\n this._lastFrameDetected = new Set();\n /**\n * Observers registered here will be executed when a new plane was added to the session\n */\n this.onPlaneAddedObservable = new Observable$1();\n /**\n * Observers registered here will be executed when a plane is no longer detected in the session\n */\n this.onPlaneRemovedObservable = new Observable$1();\n /**\n * Observers registered here will be executed when an existing plane updates (for example - expanded)\n * This can execute N times every frame\n */\n this.onPlaneUpdatedObservable = new Observable$1();\n this.xrNativeFeatureName = \"plane-detection\";\n if (this._xrSessionManager.session) {\n this._init();\n }\n else {\n this._xrSessionManager.onXRSessionInit.addOnce(() => {\n this._init();\n });\n }\n }\n /**\n * detach this feature.\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n detach() {\n if (!super.detach()) {\n return false;\n }\n if (!this._options.doNotRemovePlanesOnSessionEnded) {\n while (this._detectedPlanes.length) {\n const toRemove = this._detectedPlanes.pop();\n if (toRemove) {\n this.onPlaneRemovedObservable.notifyObservers(toRemove);\n }\n }\n }\n return true;\n }\n /**\n * Dispose this feature and all of the resources attached\n */\n dispose() {\n super.dispose();\n this.onPlaneAddedObservable.clear();\n this.onPlaneRemovedObservable.clear();\n this.onPlaneUpdatedObservable.clear();\n }\n /**\n * Check if the needed objects are defined.\n * This does not mean that the feature is enabled, but that the objects needed are well defined.\n */\n isCompatible() {\n return typeof XRPlane !== \"undefined\";\n }\n _onXRFrame(frame) {\n var _a;\n if (!this.attached || !this._enabled || !frame) {\n return;\n }\n const detectedPlanes = frame.detectedPlanes || ((_a = frame.worldInformation) === null || _a === void 0 ? void 0 : _a.detectedPlanes);\n if (detectedPlanes) {\n // remove all planes that are not currently detected in the frame\n for (let planeIdx = 0; planeIdx < this._detectedPlanes.length; planeIdx++) {\n const plane = this._detectedPlanes[planeIdx];\n if (!detectedPlanes.has(plane.xrPlane)) {\n this._detectedPlanes.splice(planeIdx--, 1);\n this.onPlaneRemovedObservable.notifyObservers(plane);\n }\n }\n // now check for new ones\n detectedPlanes.forEach((xrPlane) => {\n if (!this._lastFrameDetected.has(xrPlane)) {\n const newPlane = {\n id: planeIdProvider++,\n xrPlane: xrPlane,\n polygonDefinition: [],\n };\n const plane = this._updatePlaneWithXRPlane(xrPlane, newPlane, frame);\n this._detectedPlanes.push(plane);\n this.onPlaneAddedObservable.notifyObservers(plane);\n }\n else {\n // updated?\n if (xrPlane.lastChangedTime === this._xrSessionManager.currentTimestamp) {\n const index = this._findIndexInPlaneArray(xrPlane);\n const plane = this._detectedPlanes[index];\n this._updatePlaneWithXRPlane(xrPlane, plane, frame);\n this.onPlaneUpdatedObservable.notifyObservers(plane);\n }\n }\n });\n this._lastFrameDetected = detectedPlanes;\n }\n }\n _init() {\n const internalInit = () => {\n this._enabled = true;\n if (this._detectedPlanes.length) {\n this._detectedPlanes.length = 0;\n }\n };\n // Only supported by BabylonNative\n if (!!this._xrSessionManager.isNative && !!this._options.preferredDetectorOptions && !!this._xrSessionManager.session.trySetPreferredPlaneDetectorOptions) {\n this._xrSessionManager.session.trySetPreferredPlaneDetectorOptions(this._options.preferredDetectorOptions);\n }\n if (!this._xrSessionManager.session.updateWorldTrackingState) {\n internalInit();\n return;\n }\n this._xrSessionManager.session.updateWorldTrackingState({ planeDetectionState: { enabled: true } });\n internalInit();\n }\n _updatePlaneWithXRPlane(xrPlane, plane, xrFrame) {\n plane.polygonDefinition = xrPlane.polygon.map((xrPoint) => {\n const rightHandedSystem = this._xrSessionManager.scene.useRightHandedSystem ? 1 : -1;\n return new Vector3(xrPoint.x, xrPoint.y, xrPoint.z * rightHandedSystem);\n });\n // matrix\n const pose = xrFrame.getPose(xrPlane.planeSpace, this._xrSessionManager.referenceSpace);\n if (pose) {\n const mat = plane.transformationMatrix || new Matrix();\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\n mat.toggleModelMatrixHandInPlace();\n }\n plane.transformationMatrix = mat;\n if (this._options.worldParentNode) {\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\n }\n }\n return plane;\n }\n /**\n * avoiding using Array.find for global support.\n * @param xrPlane the plane to find in the array\n */\n _findIndexInPlaneArray(xrPlane) {\n for (let i = 0; i < this._detectedPlanes.length; ++i) {\n if (this._detectedPlanes[i].xrPlane === xrPlane) {\n return i;\n }\n }\n return -1;\n }\n }\n /**\n * The module's name\n */\n WebXRPlaneDetector.Name = WebXRFeatureName.PLANE_DETECTION;\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\n WebXRPlaneDetector.Version = 1;\n //register the plugin\n WebXRFeaturesManager.AddWebXRFeature(WebXRPlaneDetector.Name, (xrSessionManager, options) => {\n return () => new WebXRPlaneDetector(xrSessionManager, options);\n }, WebXRPlaneDetector.Version);\n\n /**\n * Defines a target to use with MorphTargetManager\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets\n */\n class MorphTarget {\n /**\n * Gets or sets the influence of this target (ie. its weight in the overall morphing)\n */\n get influence() {\n return this._influence;\n }\n set influence(influence) {\n if (this._influence === influence) {\n return;\n }\n const previous = this._influence;\n this._influence = influence;\n if (this.onInfluenceChanged.hasObservers()) {\n this.onInfluenceChanged.notifyObservers(previous === 0 || influence === 0);\n }\n }\n /**\n * Gets or sets the animation properties override\n */\n get animationPropertiesOverride() {\n if (!this._animationPropertiesOverride && this._scene) {\n return this._scene.animationPropertiesOverride;\n }\n return this._animationPropertiesOverride;\n }\n set animationPropertiesOverride(value) {\n this._animationPropertiesOverride = value;\n }\n /**\n * Creates a new MorphTarget\n * @param name defines the name of the target\n * @param influence defines the influence to use\n * @param scene defines the scene the morphtarget belongs to\n */\n constructor(\n /** defines the name of the target */\n name, influence = 0, scene = null) {\n this.name = name;\n /**\n * Gets or sets the list of animations\n */\n this.animations = new Array();\n this._positions = null;\n this._normals = null;\n this._tangents = null;\n this._uvs = null;\n this._uniqueId = 0;\n /**\n * Observable raised when the influence changes\n */\n this.onInfluenceChanged = new Observable$1();\n /** @internal */\n this._onDataLayoutChanged = new Observable$1();\n this._animationPropertiesOverride = null;\n this._scene = scene || EngineStore.LastCreatedScene;\n this.influence = influence;\n if (this._scene) {\n this._uniqueId = this._scene.getUniqueId();\n }\n }\n /**\n * Gets the unique ID of this manager\n */\n get uniqueId() {\n return this._uniqueId;\n }\n /**\n * Gets a boolean defining if the target contains position data\n */\n get hasPositions() {\n return !!this._positions;\n }\n /**\n * Gets a boolean defining if the target contains normal data\n */\n get hasNormals() {\n return !!this._normals;\n }\n /**\n * Gets a boolean defining if the target contains tangent data\n */\n get hasTangents() {\n return !!this._tangents;\n }\n /**\n * Gets a boolean defining if the target contains texture coordinates data\n */\n get hasUVs() {\n return !!this._uvs;\n }\n /**\n * Affects position data to this target\n * @param data defines the position data to use\n */\n setPositions(data) {\n const hadPositions = this.hasPositions;\n this._positions = data;\n if (hadPositions !== this.hasPositions) {\n this._onDataLayoutChanged.notifyObservers(undefined);\n }\n }\n /**\n * Gets the position data stored in this target\n * @returns a FloatArray containing the position data (or null if not present)\n */\n getPositions() {\n return this._positions;\n }\n /**\n * Affects normal data to this target\n * @param data defines the normal data to use\n */\n setNormals(data) {\n const hadNormals = this.hasNormals;\n this._normals = data;\n if (hadNormals !== this.hasNormals) {\n this._onDataLayoutChanged.notifyObservers(undefined);\n }\n }\n /**\n * Gets the normal data stored in this target\n * @returns a FloatArray containing the normal data (or null if not present)\n */\n getNormals() {\n return this._normals;\n }\n /**\n * Affects tangent data to this target\n * @param data defines the tangent data to use\n */\n setTangents(data) {\n const hadTangents = this.hasTangents;\n this._tangents = data;\n if (hadTangents !== this.hasTangents) {\n this._onDataLayoutChanged.notifyObservers(undefined);\n }\n }\n /**\n * Gets the tangent data stored in this target\n * @returns a FloatArray containing the tangent data (or null if not present)\n */\n getTangents() {\n return this._tangents;\n }\n /**\n * Affects texture coordinates data to this target\n * @param data defines the texture coordinates data to use\n */\n setUVs(data) {\n const hadUVs = this.hasUVs;\n this._uvs = data;\n if (hadUVs !== this.hasUVs) {\n this._onDataLayoutChanged.notifyObservers(undefined);\n }\n }\n /**\n * Gets the texture coordinates data stored in this target\n * @returns a FloatArray containing the texture coordinates data (or null if not present)\n */\n getUVs() {\n return this._uvs;\n }\n /**\n * Clone the current target\n * @returns a new MorphTarget\n */\n clone() {\n const newOne = SerializationHelper.Clone(() => new MorphTarget(this.name, this.influence, this._scene), this);\n newOne._positions = this._positions;\n newOne._normals = this._normals;\n newOne._tangents = this._tangents;\n newOne._uvs = this._uvs;\n return newOne;\n }\n /**\n * Serializes the current target into a Serialization object\n * @returns the serialized object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.name = this.name;\n serializationObject.influence = this.influence;\n serializationObject.positions = Array.prototype.slice.call(this.getPositions());\n if (this.id != null) {\n serializationObject.id = this.id;\n }\n if (this.hasNormals) {\n serializationObject.normals = Array.prototype.slice.call(this.getNormals());\n }\n if (this.hasTangents) {\n serializationObject.tangents = Array.prototype.slice.call(this.getTangents());\n }\n if (this.hasUVs) {\n serializationObject.uvs = Array.prototype.slice.call(this.getUVs());\n }\n // Animations\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\n return serializationObject;\n }\n /**\n * Returns the string \"MorphTarget\"\n * @returns \"MorphTarget\"\n */\n getClassName() {\n return \"MorphTarget\";\n }\n // Statics\n /**\n * Creates a new target from serialized data\n * @param serializationObject defines the serialized data to use\n * @param scene defines the hosting scene\n * @returns a new MorphTarget\n */\n static Parse(serializationObject, scene) {\n const result = new MorphTarget(serializationObject.name, serializationObject.influence);\n result.setPositions(serializationObject.positions);\n if (serializationObject.id != null) {\n result.id = serializationObject.id;\n }\n if (serializationObject.normals) {\n result.setNormals(serializationObject.normals);\n }\n if (serializationObject.tangents) {\n result.setTangents(serializationObject.tangents);\n }\n if (serializationObject.uvs) {\n result.setUVs(serializationObject.uvs);\n }\n // Animations\n if (serializationObject.animations) {\n for (let animationIndex = 0; animationIndex < serializationObject.animations.length; animationIndex++) {\n const parsedAnimation = serializationObject.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n result.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n if (serializationObject.autoAnimate && scene) {\n scene.beginAnimation(result, serializationObject.autoAnimateFrom, serializationObject.autoAnimateTo, serializationObject.autoAnimateLoop, serializationObject.autoAnimateSpeed || 1.0);\n }\n }\n return result;\n }\n /**\n * Creates a MorphTarget from mesh data\n * @param mesh defines the source mesh\n * @param name defines the name to use for the new target\n * @param influence defines the influence to attach to the target\n * @returns a new MorphTarget\n */\n static FromMesh(mesh, name, influence) {\n if (!name) {\n name = mesh.name;\n }\n const result = new MorphTarget(name, influence, mesh.getScene());\n result.setPositions(mesh.getVerticesData(VertexBuffer.PositionKind));\n if (mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\n result.setNormals(mesh.getVerticesData(VertexBuffer.NormalKind));\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {\n result.setTangents(mesh.getVerticesData(VertexBuffer.TangentKind));\n }\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\n result.setUVs(mesh.getVerticesData(VertexBuffer.UVKind));\n }\n return result;\n }\n }\n __decorate$1([\n serialize()\n ], MorphTarget.prototype, \"id\", void 0);\n\n /**\n * @internal\n */\n class _GLTFUtilities {\n /**\n * Creates a buffer view based on the supplied arguments\n * @param bufferIndex index value of the specified buffer\n * @param byteOffset byte offset value\n * @param byteLength byte length of the bufferView\n * @param byteStride byte distance between conequential elements\n * @param name name of the buffer view\n * @returns bufferView for glTF\n */\n static _CreateBufferView(bufferIndex, byteOffset, byteLength, byteStride, name) {\n const bufferview = { buffer: bufferIndex, byteLength: byteLength };\n if (byteOffset) {\n bufferview.byteOffset = byteOffset;\n }\n if (name) {\n bufferview.name = name;\n }\n if (byteStride) {\n bufferview.byteStride = byteStride;\n }\n return bufferview;\n }\n /**\n * Creates an accessor based on the supplied arguments\n * @param bufferviewIndex The index of the bufferview referenced by this accessor\n * @param name The name of the accessor\n * @param type The type of the accessor\n * @param componentType The datatype of components in the attribute\n * @param count The number of attributes referenced by this accessor\n * @param byteOffset The offset relative to the start of the bufferView in bytes\n * @param min Minimum value of each component in this attribute\n * @param max Maximum value of each component in this attribute\n * @returns accessor for glTF\n */\n static _CreateAccessor(bufferviewIndex, name, type, componentType, count, byteOffset, min, max) {\n const accessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };\n if (min != null) {\n accessor.min = min;\n }\n if (max != null) {\n accessor.max = max;\n }\n if (byteOffset != null) {\n accessor.byteOffset = byteOffset;\n }\n return accessor;\n }\n /**\n * Calculates the minimum and maximum values of an array of position floats\n * @param positions Positions array of a mesh\n * @param vertexStart Starting vertex offset to calculate min and max values\n * @param vertexCount Number of vertices to check for min and max values\n * @returns min number array and max number array\n */\n static _CalculateMinMaxPositions(positions, vertexStart, vertexCount) {\n const min = [Infinity, Infinity, Infinity];\n const max = [-Infinity, -Infinity, -Infinity];\n const positionStrideSize = 3;\n let indexOffset;\n let position;\n let vector;\n if (vertexCount) {\n for (let i = vertexStart, length = vertexStart + vertexCount; i < length; ++i) {\n indexOffset = positionStrideSize * i;\n position = Vector3.FromArray(positions, indexOffset);\n vector = position.asArray();\n for (let j = 0; j < positionStrideSize; ++j) {\n const num = vector[j];\n if (num < min[j]) {\n min[j] = num;\n }\n if (num > max[j]) {\n max[j] = num;\n }\n ++indexOffset;\n }\n }\n }\n return { min, max };\n }\n static _NormalizeTangentFromRef(tangent) {\n const length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);\n if (length > 0) {\n tangent.x /= length;\n tangent.y /= length;\n tangent.z /= length;\n }\n }\n static _GetDataAccessorElementCount(accessorType) {\n switch (accessorType) {\n case \"MAT2\" /* AccessorType.MAT2 */:\n return 4;\n case \"MAT3\" /* AccessorType.MAT3 */:\n return 9;\n case \"MAT4\" /* AccessorType.MAT4 */:\n return 16;\n case \"SCALAR\" /* AccessorType.SCALAR */:\n return 1;\n case \"VEC2\" /* AccessorType.VEC2 */:\n return 2;\n case \"VEC3\" /* AccessorType.VEC3 */:\n return 3;\n case \"VEC4\" /* AccessorType.VEC4 */:\n return 4;\n }\n }\n }\n\n /**\n * @internal\n * Enum for handling in tangent and out tangent.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n var _TangentType;\n (function (_TangentType) {\n /**\n * Specifies that input tangents are used.\n */\n _TangentType[_TangentType[\"INTANGENT\"] = 0] = \"INTANGENT\";\n /**\n * Specifies that output tangents are used.\n */\n _TangentType[_TangentType[\"OUTTANGENT\"] = 1] = \"OUTTANGENT\";\n })(_TangentType || (_TangentType = {}));\n /**\n * @internal\n * Utility class for generating glTF animation data from BabylonJS.\n */\n class _GLTFAnimation {\n /**\n * Determine if a node is transformable - ie has properties it should be part of animation of transformation.\n * @param babylonNode the node to test\n * @returns true if can be animated, false otherwise. False if the parameter is null or undefined.\n */\n static _IsTransformable(babylonNode) {\n return babylonNode && (babylonNode instanceof TransformNode || babylonNode instanceof Camera || babylonNode instanceof Light);\n }\n /**\n * @ignore\n *\n * Creates glTF channel animation from BabylonJS animation.\n * @param babylonTransformNode - BabylonJS mesh.\n * @param animation - animation.\n * @param animationChannelTargetPath - The target animation channel.\n * @param useQuaternion - Specifies if quaternions are used.\n * @returns nullable IAnimationData\n */\n static _CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, useQuaternion, animationSampleRate) {\n if (this._IsTransformable(babylonTransformNode)) {\n const inputs = [];\n const outputs = [];\n const keyFrames = animation.getKeys();\n const minMaxKeyFrames = _GLTFAnimation._CalculateMinMaxKeyFrames(keyFrames);\n const interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);\n const interpolation = interpolationOrBake.interpolationType;\n const shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;\n if (shouldBakeAnimation) {\n _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, useQuaternion);\n }\n else {\n if (interpolation === \"LINEAR\" /* AnimationSamplerInterpolation.LINEAR */ || interpolation === \"STEP\" /* AnimationSamplerInterpolation.STEP */) {\n _GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion);\n }\n else if (interpolation === \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */) {\n _GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion);\n }\n else {\n _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, useQuaternion);\n }\n }\n if (inputs.length && outputs.length) {\n const result = {\n inputs: inputs,\n outputs: outputs,\n samplerInterpolation: interpolation,\n inputsMin: shouldBakeAnimation ? minMaxKeyFrames.min : Tools.FloatRound(minMaxKeyFrames.min / animation.framePerSecond),\n inputsMax: shouldBakeAnimation ? minMaxKeyFrames.max : Tools.FloatRound(minMaxKeyFrames.max / animation.framePerSecond),\n };\n return result;\n }\n }\n return null;\n }\n static _DeduceAnimationInfo(animation) {\n let animationChannelTargetPath = null;\n let dataAccessorType = \"VEC3\" /* AccessorType.VEC3 */;\n let useQuaternion = false;\n const property = animation.targetProperty.split(\".\");\n switch (property[0]) {\n case \"scaling\": {\n animationChannelTargetPath = \"scale\" /* AnimationChannelTargetPath.SCALE */;\n break;\n }\n case \"position\": {\n animationChannelTargetPath = \"translation\" /* AnimationChannelTargetPath.TRANSLATION */;\n break;\n }\n case \"rotation\": {\n dataAccessorType = \"VEC4\" /* AccessorType.VEC4 */;\n animationChannelTargetPath = \"rotation\" /* AnimationChannelTargetPath.ROTATION */;\n break;\n }\n case \"rotationQuaternion\": {\n dataAccessorType = \"VEC4\" /* AccessorType.VEC4 */;\n useQuaternion = true;\n animationChannelTargetPath = \"rotation\" /* AnimationChannelTargetPath.ROTATION */;\n break;\n }\n case \"influence\": {\n dataAccessorType = \"SCALAR\" /* AccessorType.SCALAR */;\n animationChannelTargetPath = \"weights\" /* AnimationChannelTargetPath.WEIGHTS */;\n break;\n }\n default: {\n Tools.Error(`Unsupported animatable property ${property[0]}`);\n }\n }\n if (animationChannelTargetPath) {\n return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };\n }\n else {\n Tools.Error(\"animation channel target path and data accessor type could be deduced\");\n }\n return null;\n }\n /**\n * @ignore\n * Create node animations from the transform node animations\n * @param babylonNode\n * @param runtimeGLTFAnimation\n * @param idleGLTFAnimations\n * @param nodeMap\n * @param nodes\n * @param binaryWriter\n * @param bufferViews\n * @param accessors\n * @param animationSampleRate\n */\n static _CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, animationSampleRate, shouldExportAnimation) {\n let glTFAnimation;\n if (_GLTFAnimation._IsTransformable(babylonNode)) {\n if (babylonNode.animations) {\n for (const animation of babylonNode.animations) {\n if (shouldExportAnimation && !shouldExportAnimation(animation)) {\n continue;\n }\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);\n if (animationInfo) {\n glTFAnimation = {\n name: animation.name,\n samplers: [],\n channels: [],\n };\n _GLTFAnimation._AddAnimation(`${animation.name}`, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate);\n if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {\n idleGLTFAnimations.push(glTFAnimation);\n }\n }\n }\n }\n }\n }\n /**\n * @ignore\n * Create individual morph animations from the mesh's morph target animation tracks\n * @param babylonNode\n * @param runtimeGLTFAnimation\n * @param idleGLTFAnimations\n * @param nodeMap\n * @param nodes\n * @param binaryWriter\n * @param bufferViews\n * @param accessors\n * @param animationSampleRate\n */\n static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, animationSampleRate, shouldExportAnimation) {\n let glTFAnimation;\n if (babylonNode instanceof Mesh) {\n const morphTargetManager = babylonNode.morphTargetManager;\n if (morphTargetManager) {\n for (let i = 0; i < morphTargetManager.numTargets; ++i) {\n const morphTarget = morphTargetManager.getTarget(i);\n for (const animation of morphTarget.animations) {\n if (shouldExportAnimation && !shouldExportAnimation(animation)) {\n continue;\n }\n const combinedAnimation = new Animation(`${animation.name}`, \"influence\", animation.framePerSecond, animation.dataType, animation.loopMode, animation.enableBlending);\n const combinedAnimationKeys = [];\n const animationKeys = animation.getKeys();\n for (let j = 0; j < animationKeys.length; ++j) {\n const animationKey = animationKeys[j];\n for (let k = 0; k < morphTargetManager.numTargets; ++k) {\n if (k == i) {\n combinedAnimationKeys.push(animationKey);\n }\n else {\n combinedAnimationKeys.push({ frame: animationKey.frame, value: 0 });\n }\n }\n }\n combinedAnimation.setKeys(combinedAnimationKeys);\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimation);\n if (animationInfo) {\n glTFAnimation = {\n name: combinedAnimation.name,\n samplers: [],\n channels: [],\n };\n _GLTFAnimation._AddAnimation(animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, combinedAnimation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, morphTargetManager.numTargets);\n if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {\n idleGLTFAnimations.push(glTFAnimation);\n }\n }\n }\n }\n }\n }\n }\n /**\n * @ignore\n * Create node and morph animations from the animation groups\n * @param babylonScene\n * @param glTFAnimations\n * @param nodeMap\n * @param nodes\n * @param binaryWriter\n * @param bufferViews\n * @param accessors\n * @param animationSampleRate\n */\n static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene, glTFAnimations, nodeMap, binaryWriter, bufferViews, accessors, animationSampleRate, shouldExportAnimation) {\n var _a;\n let glTFAnimation;\n if (babylonScene.animationGroups) {\n const animationGroups = babylonScene.animationGroups;\n for (const animationGroup of animationGroups) {\n const morphAnimations = new Map();\n const sampleAnimations = new Map();\n const morphAnimationMeshes = new Set();\n const animationGroupFrameDiff = animationGroup.to - animationGroup.from;\n glTFAnimation = {\n name: animationGroup.name,\n channels: [],\n samplers: [],\n };\n for (let i = 0; i < animationGroup.targetedAnimations.length; ++i) {\n const targetAnimation = animationGroup.targetedAnimations[i];\n const target = targetAnimation.target;\n const animation = targetAnimation.animation;\n if (shouldExportAnimation && !shouldExportAnimation(animation)) {\n continue;\n }\n if (this._IsTransformable(target) || (target.length === 1 && this._IsTransformable(target[0]))) {\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);\n if (animationInfo) {\n const babylonTransformNode = this._IsTransformable(target) ? target : this._IsTransformable(target[0]) ? target[0] : null;\n if (babylonTransformNode) {\n _GLTFAnimation._AddAnimation(`${animation.name}`, glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate);\n }\n }\n }\n else if (target instanceof MorphTarget || (target.length === 1 && target[0] instanceof MorphTarget)) {\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);\n if (animationInfo) {\n const babylonMorphTarget = target instanceof MorphTarget ? target : target[0];\n if (babylonMorphTarget) {\n const babylonMorphTargetManager = babylonScene.morphTargetManagers.find((morphTargetManager) => {\n for (let j = 0; j < morphTargetManager.numTargets; ++j) {\n if (morphTargetManager.getTarget(j) === babylonMorphTarget) {\n return true;\n }\n }\n return false;\n });\n if (babylonMorphTargetManager) {\n const babylonMesh = babylonScene.meshes.find((mesh) => {\n return mesh.morphTargetManager === babylonMorphTargetManager;\n });\n if (babylonMesh) {\n if (!morphAnimations.has(babylonMesh)) {\n morphAnimations.set(babylonMesh, new Map());\n }\n (_a = morphAnimations.get(babylonMesh)) === null || _a === void 0 ? void 0 : _a.set(babylonMorphTarget, animation);\n morphAnimationMeshes.add(babylonMesh);\n sampleAnimations.set(babylonMesh, animation);\n }\n }\n }\n }\n }\n else ;\n }\n morphAnimationMeshes.forEach((mesh) => {\n const morphTargetManager = mesh.morphTargetManager;\n let combinedAnimationGroup = null;\n const animationKeys = [];\n const sampleAnimation = sampleAnimations.get(mesh);\n const sampleAnimationKeys = sampleAnimation.getKeys();\n const numAnimationKeys = sampleAnimationKeys.length;\n /*\n Due to how glTF expects morph target animation data to be formatted, we need to rearrange the individual morph target animation tracks,\n such that we have a single animation, where a given keyframe input value has successive output values for each morph target belonging to the manager.\n See: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations\n\n We do this via constructing a new Animation track, and interleaving the frames of each morph target animation track in the current Animation Group\n We reuse the Babylon Animation data structure for ease of handling export of cubic spline animation keys, and to reuse the\n existing _GLTFAnimation.AddAnimation codepath with minimal modification, however the constructed Babylon Animation is NOT intended for use in-engine.\n */\n for (let i = 0; i < numAnimationKeys; ++i) {\n for (let j = 0; j < morphTargetManager.numTargets; ++j) {\n const morphTarget = morphTargetManager.getTarget(j);\n const animationsByMorphTarget = morphAnimations.get(mesh);\n if (animationsByMorphTarget) {\n const morphTargetAnimation = animationsByMorphTarget.get(morphTarget);\n if (morphTargetAnimation) {\n if (!combinedAnimationGroup) {\n combinedAnimationGroup = new Animation(`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`, \"influence\", morphTargetAnimation.framePerSecond, Animation.ANIMATIONTYPE_FLOAT, morphTargetAnimation.loopMode, morphTargetAnimation.enableBlending);\n }\n animationKeys.push(morphTargetAnimation.getKeys()[i]);\n }\n else {\n animationKeys.push({\n frame: animationGroup.from + (animationGroupFrameDiff / numAnimationKeys) * i,\n value: morphTarget.influence,\n inTangent: sampleAnimationKeys[0].inTangent ? 0 : undefined,\n outTangent: sampleAnimationKeys[0].outTangent ? 0 : undefined,\n });\n }\n }\n }\n }\n combinedAnimationGroup.setKeys(animationKeys);\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup);\n if (animationInfo) {\n _GLTFAnimation._AddAnimation(`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`, glTFAnimation, mesh, combinedAnimationGroup, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, morphTargetManager === null || morphTargetManager === void 0 ? void 0 : morphTargetManager.numTargets);\n }\n });\n if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {\n glTFAnimations.push(glTFAnimation);\n }\n }\n }\n }\n static _AddAnimation(name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, useQuaternion, animationSampleRate, morphAnimationChannels) {\n const animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, useQuaternion, animationSampleRate);\n let bufferView;\n let accessor;\n let keyframeAccessorIndex;\n let dataAccessorIndex;\n let outputLength;\n let animationSampler;\n let animationChannel;\n if (animationData) {\n /*\n * Now that we have the glTF converted morph target animation data,\n * we can remove redundant input data so that we have n input frames,\n * and morphAnimationChannels * n output frames\n */\n if (morphAnimationChannels) {\n let index = 0;\n let currentInput = 0;\n const newInputs = [];\n while (animationData.inputs.length > 0) {\n currentInput = animationData.inputs.shift();\n if (index % morphAnimationChannels == 0) {\n newInputs.push(currentInput);\n }\n index++;\n }\n animationData.inputs = newInputs;\n }\n const nodeIndex = nodeMap[babylonTransformNode.uniqueId];\n // Creates buffer view and accessor for key frames.\n let byteLength = animationData.inputs.length * 4;\n bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} keyframe data view`);\n bufferViews.push(bufferView);\n animationData.inputs.forEach(function (input) {\n binaryWriter.setFloat32(input);\n });\n accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} keyframes`, \"SCALAR\" /* AccessorType.SCALAR */, 5126 /* AccessorComponentType.FLOAT */, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);\n accessors.push(accessor);\n keyframeAccessorIndex = accessors.length - 1;\n // create bufferview and accessor for keyed values.\n outputLength = animationData.outputs.length;\n byteLength = _GLTFUtilities._GetDataAccessorElementCount(dataAccessorType) * 4 * animationData.outputs.length;\n // check for in and out tangents\n bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} data view`);\n bufferViews.push(bufferView);\n animationData.outputs.forEach(function (output) {\n output.forEach(function (entry) {\n binaryWriter.setFloat32(entry);\n });\n });\n accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} data`, dataAccessorType, 5126 /* AccessorComponentType.FLOAT */, outputLength, null, null, null);\n accessors.push(accessor);\n dataAccessorIndex = accessors.length - 1;\n // create sampler\n animationSampler = {\n interpolation: animationData.samplerInterpolation,\n input: keyframeAccessorIndex,\n output: dataAccessorIndex,\n };\n glTFAnimation.samplers.push(animationSampler);\n // create channel\n animationChannel = {\n sampler: glTFAnimation.samplers.length - 1,\n target: {\n node: nodeIndex,\n path: animationChannelTargetPath,\n },\n };\n glTFAnimation.channels.push(animationChannel);\n }\n }\n /**\n * Create a baked animation\n * @param babylonTransformNode BabylonJS mesh\n * @param animation BabylonJS animation corresponding to the BabylonJS mesh\n * @param animationChannelTargetPath animation target channel\n * @param minFrame minimum animation frame\n * @param maxFrame maximum animation frame\n * @param fps frames per second of the animation\n * @param sampleRate\n * @param inputs input key frames of the animation\n * @param outputs output key frame data of the animation\n * @param minMaxFrames\n * @param minMaxFrames.min\n * @param minMaxFrames.max\n * @param useQuaternion specifies if quaternions should be used\n */\n static _CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, useQuaternion) {\n let value;\n const quaternionCache = Quaternion.Identity();\n let previousTime = null;\n let time;\n let maxUsedFrame = null;\n let currKeyFrame = null;\n let nextKeyFrame = null;\n let prevKeyFrame = null;\n let endFrame = null;\n minMaxFrames.min = Tools.FloatRound(minFrame / fps);\n const keyFrames = animation.getKeys();\n for (let i = 0, length = keyFrames.length; i < length; ++i) {\n endFrame = null;\n currKeyFrame = keyFrames[i];\n if (i + 1 < length) {\n nextKeyFrame = keyFrames[i + 1];\n if ((currKeyFrame.value.equals && currKeyFrame.value.equals(nextKeyFrame.value)) || currKeyFrame.value === nextKeyFrame.value) {\n if (i === 0) {\n // set the first frame to itself\n endFrame = currKeyFrame.frame;\n }\n else {\n continue;\n }\n }\n else {\n endFrame = nextKeyFrame.frame;\n }\n }\n else {\n // at the last key frame\n prevKeyFrame = keyFrames[i - 1];\n if ((currKeyFrame.value.equals && currKeyFrame.value.equals(prevKeyFrame.value)) || currKeyFrame.value === prevKeyFrame.value) {\n continue;\n }\n else {\n endFrame = maxFrame;\n }\n }\n if (endFrame) {\n for (let f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {\n time = Tools.FloatRound(f / fps);\n if (time === previousTime) {\n continue;\n }\n previousTime = time;\n maxUsedFrame = time;\n const state = {\n key: 0,\n repeatCount: 0,\n loopMode: animation.loopMode,\n };\n value = animation._interpolate(f, state);\n _GLTFAnimation._SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, useQuaternion);\n }\n }\n }\n if (maxUsedFrame) {\n minMaxFrames.max = maxUsedFrame;\n }\n }\n static _ConvertFactorToVector3OrQuaternion(factor, babylonTransformNode, animation, animationChannelTargetPath, useQuaternion) {\n const basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, useQuaternion);\n // handles single component x, y, z or w component animation by using a base property and animating over a component.\n const property = animation.targetProperty.split(\".\");\n const componentName = property ? property[1] : \"\"; // x, y, z, or w component\n const value = useQuaternion ? Quaternion.FromArray(basePositionRotationOrScale).normalize() : Vector3.FromArray(basePositionRotationOrScale);\n switch (componentName) {\n case \"x\":\n case \"y\":\n case \"z\": {\n value[componentName] = factor;\n break;\n }\n case \"w\": {\n value.w = factor;\n break;\n }\n default: {\n Tools.Error(`glTFAnimation: Unsupported component name \"${componentName}\"!`);\n }\n }\n return value;\n }\n static _SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, useQuaternion) {\n let cacheValue;\n inputs.push(time);\n if (animationChannelTargetPath === \"weights\" /* AnimationChannelTargetPath.WEIGHTS */) {\n outputs.push([value]);\n return;\n }\n if (animation.dataType === Animation.ANIMATIONTYPE_FLOAT) {\n value = this._ConvertFactorToVector3OrQuaternion(value, babylonTransformNode, animation, animationChannelTargetPath, useQuaternion);\n }\n if (animationChannelTargetPath === \"rotation\" /* AnimationChannelTargetPath.ROTATION */) {\n if (useQuaternion) {\n quaternionCache = value;\n }\n else {\n cacheValue = value;\n Quaternion.RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);\n }\n outputs.push(quaternionCache.asArray());\n }\n else {\n // scaling and position animation\n cacheValue = value;\n outputs.push(cacheValue.asArray());\n }\n }\n /**\n * Creates linear animation from the animation key frames\n * @param babylonTransformNode BabylonJS mesh\n * @param animation BabylonJS animation\n * @param animationChannelTargetPath The target animation channel\n * @param inputs Array to store the key frame times\n * @param outputs Array to store the key frame data\n * @param useQuaternion Specifies if quaternions are used in the animation\n */\n static _CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion) {\n for (const keyFrame of animation.getKeys()) {\n inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.\n _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, useQuaternion);\n }\n }\n /**\n * Creates cubic spline animation from the animation key frames\n * @param babylonTransformNode BabylonJS mesh\n * @param animation BabylonJS animation\n * @param animationChannelTargetPath The target animation channel\n * @param frameDelta The difference between the last and first frame of the animation\n * @param inputs Array to store the key frame times\n * @param outputs Array to store the key frame data\n * @param useQuaternion Specifies if quaternions are used in the animation\n */\n static _CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion) {\n animation.getKeys().forEach(function (keyFrame) {\n inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.\n _GLTFAnimation._AddSplineTangent(_TangentType.INTANGENT, outputs, animationChannelTargetPath, \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */, keyFrame, useQuaternion);\n _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, useQuaternion);\n _GLTFAnimation._AddSplineTangent(_TangentType.OUTTANGENT, outputs, animationChannelTargetPath, \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */, keyFrame, useQuaternion);\n });\n }\n static _GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, useQuaternion) {\n let basePositionRotationOrScale;\n if (animationChannelTargetPath === \"rotation\" /* AnimationChannelTargetPath.ROTATION */) {\n if (useQuaternion) {\n const q = babylonTransformNode.rotationQuaternion;\n basePositionRotationOrScale = (q !== null && q !== void 0 ? q : Quaternion.Identity()).asArray();\n }\n else {\n const r = babylonTransformNode.rotation;\n basePositionRotationOrScale = (r !== null && r !== void 0 ? r : Vector3.Zero()).asArray();\n }\n }\n else if (animationChannelTargetPath === \"translation\" /* AnimationChannelTargetPath.TRANSLATION */) {\n const p = babylonTransformNode.position;\n basePositionRotationOrScale = (p !== null && p !== void 0 ? p : Vector3.Zero()).asArray();\n }\n else {\n // scale\n const s = babylonTransformNode.scaling;\n basePositionRotationOrScale = (s !== null && s !== void 0 ? s : Vector3.One()).asArray();\n }\n return basePositionRotationOrScale;\n }\n /**\n * Adds a key frame value\n * @param keyFrame\n * @param animation\n * @param outputs\n * @param animationChannelTargetPath\n * @param babylonTransformNode\n * @param useQuaternion\n */\n static _AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, useQuaternion) {\n let newPositionRotationOrScale;\n const animationType = animation.dataType;\n if (animationType === Animation.ANIMATIONTYPE_VECTOR3) {\n let value = keyFrame.value.asArray();\n if (animationChannelTargetPath === \"rotation\" /* AnimationChannelTargetPath.ROTATION */) {\n const array = Vector3.FromArray(value);\n const rotationQuaternion = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z);\n value = rotationQuaternion.asArray();\n }\n outputs.push(value); // scale vector.\n }\n else if (animationType === Animation.ANIMATIONTYPE_FLOAT) {\n if (animationChannelTargetPath === \"weights\" /* AnimationChannelTargetPath.WEIGHTS */) {\n outputs.push([keyFrame.value]);\n }\n else {\n // handles single component x, y, z or w component animation by using a base property and animating over a component.\n newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationChannelTargetPath, useQuaternion);\n if (newPositionRotationOrScale) {\n if (animationChannelTargetPath === \"rotation\" /* AnimationChannelTargetPath.ROTATION */) {\n const posRotScale = useQuaternion\n ? newPositionRotationOrScale\n : Quaternion.RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();\n outputs.push(posRotScale.asArray());\n }\n outputs.push(newPositionRotationOrScale.asArray());\n }\n }\n }\n else if (animationType === Animation.ANIMATIONTYPE_QUATERNION) {\n outputs.push(keyFrame.value.normalize().asArray());\n }\n else {\n Tools.Error(\"glTFAnimation: Unsupported key frame values for animation!\");\n }\n }\n /**\n * Determine the interpolation based on the key frames\n * @param keyFrames\n * @param animationChannelTargetPath\n * @param useQuaternion\n */\n static _DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion) {\n let interpolationType;\n let shouldBakeAnimation = false;\n let key;\n if (animationChannelTargetPath === \"rotation\" /* AnimationChannelTargetPath.ROTATION */ && !useQuaternion) {\n return { interpolationType: \"LINEAR\" /* AnimationSamplerInterpolation.LINEAR */, shouldBakeAnimation: true };\n }\n for (let i = 0, length = keyFrames.length; i < length; ++i) {\n key = keyFrames[i];\n if (key.inTangent || key.outTangent) {\n if (interpolationType) {\n if (interpolationType !== \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */) {\n interpolationType = \"LINEAR\" /* AnimationSamplerInterpolation.LINEAR */;\n shouldBakeAnimation = true;\n break;\n }\n }\n else {\n interpolationType = \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */;\n }\n }\n else {\n if (interpolationType) {\n if (interpolationType === \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */ ||\n (key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP && interpolationType !== \"STEP\" /* AnimationSamplerInterpolation.STEP */)) {\n interpolationType = \"LINEAR\" /* AnimationSamplerInterpolation.LINEAR */;\n shouldBakeAnimation = true;\n break;\n }\n }\n else {\n if (key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP) {\n interpolationType = \"STEP\" /* AnimationSamplerInterpolation.STEP */;\n }\n else {\n interpolationType = \"LINEAR\" /* AnimationSamplerInterpolation.LINEAR */;\n }\n }\n }\n }\n if (!interpolationType) {\n interpolationType = \"LINEAR\" /* AnimationSamplerInterpolation.LINEAR */;\n }\n return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };\n }\n /**\n * Adds an input tangent or output tangent to the output data\n * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion\n * @param babylonTransformNode\n * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)\n * @param outputs The animation data by keyframe\n * @param animationChannelTargetPath The target animation channel\n * @param interpolation The interpolation type\n * @param keyFrame The key frame with the animation data\n * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta\n * @param useQuaternion Specifies if quaternions are used\n */\n static _AddSplineTangent(tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, useQuaternion) {\n let tangent;\n const tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;\n if (interpolation === \"CUBICSPLINE\" /* AnimationSamplerInterpolation.CUBICSPLINE */) {\n if (animationChannelTargetPath === \"rotation\" /* AnimationChannelTargetPath.ROTATION */) {\n if (tangentValue) {\n if (useQuaternion) {\n tangent = tangentValue.asArray();\n }\n else {\n const array = tangentValue;\n tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();\n }\n }\n else {\n tangent = [0, 0, 0, 0];\n }\n }\n else if (animationChannelTargetPath === \"weights\" /* AnimationChannelTargetPath.WEIGHTS */) {\n if (tangentValue) {\n tangent = [tangentValue];\n }\n else {\n tangent = [0];\n }\n }\n else {\n if (tangentValue) {\n tangent = tangentValue.asArray();\n }\n else {\n tangent = [0, 0, 0];\n }\n }\n outputs.push(tangent);\n }\n }\n /**\n * Get the minimum and maximum key frames' frame values\n * @param keyFrames animation key frames\n * @returns the minimum and maximum key frame value\n */\n static _CalculateMinMaxKeyFrames(keyFrames) {\n let min = Infinity;\n let max = -Infinity;\n keyFrames.forEach(function (keyFrame) {\n min = Math.min(min, keyFrame.frame);\n max = Math.max(max, keyFrame.frame);\n });\n return { min: min, max: max };\n }\n }\n\n /**\n * Class for holding and downloading glTF file data\n */\n class GLTFData {\n /**\n * Initializes the glTF file object\n */\n constructor() {\n this.glTFFiles = {};\n }\n /**\n * Downloads the glTF data as files based on their names and data\n */\n downloadFiles() {\n /**\n * Checks for a matching suffix at the end of a string (for ES5 and lower)\n * @param str Source string\n * @param suffix Suffix to search for in the source string\n * @returns Boolean indicating whether the suffix was found (true) or not (false)\n */\n function endsWith(str, suffix) {\n return str.indexOf(suffix, str.length - suffix.length) !== -1;\n }\n for (const key in this.glTFFiles) {\n const link = document.createElement(\"a\");\n document.body.appendChild(link);\n link.setAttribute(\"type\", \"hidden\");\n link.download = key;\n const blob = this.glTFFiles[key];\n let mimeType;\n if (endsWith(key, \".glb\")) {\n mimeType = { type: \"model/gltf-binary\" };\n }\n else if (endsWith(key, \".bin\")) {\n mimeType = { type: \"application/octet-stream\" };\n }\n else if (endsWith(key, \".gltf\")) {\n mimeType = { type: \"model/gltf+json\" };\n }\n else if (endsWith(key, \".jpeg\") || endsWith(key, \".jpg\")) {\n mimeType = { type: \"image/jpeg\" /* ImageMimeType.JPEG */ };\n }\n else if (endsWith(key, \".png\")) {\n mimeType = { type: \"image/png\" /* ImageMimeType.PNG */ };\n }\n link.href = window.URL.createObjectURL(new Blob([blob], mimeType));\n link.click();\n }\n }\n }\n\n ThinEngine.prototype.updateRawTexture = function (texture, data, format, invertY, compression = null, type = 0, useSRGBBuffer = false) {\n if (!texture) {\n return;\n }\n // Babylon's internalSizedFomat but gl's texImage2D internalFormat\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);\n // Babylon's internalFormat but gl's texImage2D format\n const internalFormat = this._getInternalFormat(format);\n const textureType = this._getWebGLTextureType(type);\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\n if (!this._doNotHandleContextLost) {\n texture._bufferView = data;\n texture.format = format;\n texture.type = type;\n texture.invertY = invertY;\n texture._compression = compression;\n }\n if (texture.width % 4 !== 0) {\n this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);\n }\n if (compression && data) {\n this._gl.compressedTexImage2D(this._gl.TEXTURE_2D, 0, this.getCaps().s3tc[compression], texture.width, texture.height, 0, data);\n }\n else {\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, data);\n }\n if (texture.generateMipMaps) {\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\n }\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n // this.resetTextureCache();\n texture.isReady = true;\n };\n ThinEngine.prototype.createRawTexture = function (data, width, height, format, generateMipMaps, invertY, samplingMode, compression = null, type = 0, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n creationFlags = 0, useSRGBBuffer = false) {\n const texture = new InternalTexture(this, InternalTextureSource.Raw);\n texture.baseWidth = width;\n texture.baseHeight = height;\n texture.width = width;\n texture.height = height;\n texture.format = format;\n texture.generateMipMaps = generateMipMaps;\n texture.samplingMode = samplingMode;\n texture.invertY = invertY;\n texture._compression = compression;\n texture.type = type;\n texture._useSRGBBuffer = this._getUseSRGBBuffer(useSRGBBuffer, !generateMipMaps);\n if (!this._doNotHandleContextLost) {\n texture._bufferView = data;\n }\n this.updateRawTexture(texture, data, format, invertY, compression, type, texture._useSRGBBuffer);\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\n // Filters\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);\n if (generateMipMaps) {\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\n }\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n this._internalTexturesCache.push(texture);\n return texture;\n };\n ThinEngine.prototype.createRawCubeTexture = function (data, size, format, type, generateMipMaps, invertY, samplingMode, compression = null) {\n const gl = this._gl;\n const texture = new InternalTexture(this, InternalTextureSource.CubeRaw);\n texture.isCube = true;\n texture.format = format;\n texture.type = type;\n if (!this._doNotHandleContextLost) {\n texture._bufferViewArray = data;\n }\n const textureType = this._getWebGLTextureType(type);\n let internalFormat = this._getInternalFormat(format);\n if (internalFormat === gl.RGB) {\n internalFormat = gl.RGBA;\n }\n // Mipmap generation needs a sized internal format that is both color-renderable and texture-filterable\n if (textureType === gl.FLOAT && !this._caps.textureFloatLinearFiltering) {\n generateMipMaps = false;\n samplingMode = 1;\n Logger.Warn(\"Float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.\");\n }\n else if (textureType === this._gl.HALF_FLOAT_OES && !this._caps.textureHalfFloatLinearFiltering) {\n generateMipMaps = false;\n samplingMode = 1;\n Logger.Warn(\"Half float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.\");\n }\n else if (textureType === gl.FLOAT && !this._caps.textureFloatRender) {\n generateMipMaps = false;\n Logger.Warn(\"Render to float textures is not supported. Mipmap generation forced to false.\");\n }\n else if (textureType === gl.HALF_FLOAT && !this._caps.colorBufferFloat) {\n generateMipMaps = false;\n Logger.Warn(\"Render to half float textures is not supported. Mipmap generation forced to false.\");\n }\n const width = size;\n const height = width;\n texture.width = width;\n texture.height = height;\n texture.invertY = invertY;\n texture._compression = compression;\n // Double check on POT to generate Mips.\n const isPot = !this.needPOTTextures || (Tools.IsExponentOfTwo(texture.width) && Tools.IsExponentOfTwo(texture.height));\n if (!isPot) {\n generateMipMaps = false;\n }\n // Upload data if needed. The texture won't be ready until then.\n if (data) {\n this.updateRawCubeTexture(texture, data, format, type, invertY, compression);\n }\n else {\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);\n const level = 0;\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\n if (compression) {\n gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, this.getCaps().s3tc[compression], texture.width, texture.height, 0, undefined);\n }\n else {\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, null);\n }\n }\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\n }\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);\n // Filters\n if (data && generateMipMaps) {\n this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);\n }\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n texture.generateMipMaps = generateMipMaps;\n texture.samplingMode = samplingMode;\n texture.isReady = true;\n return texture;\n };\n ThinEngine.prototype.updateRawCubeTexture = function (texture, data, format, type, invertY, compression = null, level = 0) {\n texture._bufferViewArray = data;\n texture.format = format;\n texture.type = type;\n texture.invertY = invertY;\n texture._compression = compression;\n const gl = this._gl;\n const textureType = this._getWebGLTextureType(type);\n let internalFormat = this._getInternalFormat(format);\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);\n let needConversion = false;\n if (internalFormat === gl.RGB) {\n internalFormat = gl.RGBA;\n needConversion = true;\n }\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\n if (texture.width % 4 !== 0) {\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);\n }\n // Data are known to be in +X +Y +Z -X -Y -Z\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\n let faceData = data[faceIndex];\n if (compression) {\n gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, this.getCaps().s3tc[compression], texture.width, texture.height, 0, faceData);\n }\n else {\n if (needConversion) {\n faceData = _convertRGBtoRGBATextureData(faceData, texture.width, texture.height, type);\n }\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, faceData);\n }\n }\n const isPot = !this.needPOTTextures || (Tools.IsExponentOfTwo(texture.width) && Tools.IsExponentOfTwo(texture.height));\n if (isPot && texture.generateMipMaps && level === 0) {\n this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);\n }\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\n // this.resetTextureCache();\n texture.isReady = true;\n };\n ThinEngine.prototype.createRawCubeTextureFromUrl = function (url, scene, size, format, type, noMipmap, callback, mipmapGenerator, onLoad = null, onError = null, samplingMode = 3, invertY = false) {\n const gl = this._gl;\n const texture = this.createRawCubeTexture(null, size, format, type, !noMipmap, invertY, samplingMode, null);\n scene === null || scene === void 0 ? void 0 : scene.addPendingData(texture);\n texture.url = url;\n texture.isReady = false;\n this._internalTexturesCache.push(texture);\n const onerror = (request, exception) => {\n scene === null || scene === void 0 ? void 0 : scene.removePendingData(texture);\n if (onError && request) {\n onError(request.status + \" \" + request.statusText, exception);\n }\n };\n const internalCallback = (data) => {\n const width = texture.width;\n const faceDataArrays = callback(data);\n if (!faceDataArrays) {\n return;\n }\n if (mipmapGenerator) {\n const textureType = this._getWebGLTextureType(type);\n let internalFormat = this._getInternalFormat(format);\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);\n let needConversion = false;\n if (internalFormat === gl.RGB) {\n internalFormat = gl.RGBA;\n needConversion = true;\n }\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\n this._unpackFlipY(false);\n const mipData = mipmapGenerator(faceDataArrays);\n for (let level = 0; level < mipData.length; level++) {\n const mipSize = width >> level;\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\n let mipFaceData = mipData[level][faceIndex];\n if (needConversion) {\n mipFaceData = _convertRGBtoRGBATextureData(mipFaceData, mipSize, mipSize, type);\n }\n gl.texImage2D(faceIndex, level, internalSizedFomat, mipSize, mipSize, 0, internalFormat, textureType, mipFaceData);\n }\n }\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\n }\n else {\n this.updateRawCubeTexture(texture, faceDataArrays, format, type, invertY);\n }\n texture.isReady = true;\n // this.resetTextureCache();\n scene === null || scene === void 0 ? void 0 : scene.removePendingData(texture);\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n if (onLoad) {\n onLoad();\n }\n };\n this._loadFile(url, (data) => {\n internalCallback(data);\n }, undefined, scene === null || scene === void 0 ? void 0 : scene.offlineProvider, true, onerror);\n return texture;\n };\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function _convertRGBtoRGBATextureData(rgbData, width, height, textureType) {\n // Create new RGBA data container.\n let rgbaData;\n let val1 = 1;\n if (textureType === 1) {\n rgbaData = new Float32Array(width * height * 4);\n }\n else if (textureType === 2) {\n rgbaData = new Uint16Array(width * height * 4);\n val1 = 15360; // 15360 is the encoding of 1 in half float\n }\n else if (textureType === 7) {\n rgbaData = new Uint32Array(width * height * 4);\n }\n else {\n rgbaData = new Uint8Array(width * height * 4);\n }\n // Convert each pixel.\n for (let x = 0; x < width; x++) {\n for (let y = 0; y < height; y++) {\n const index = (y * width + x) * 3;\n const newIndex = (y * width + x) * 4;\n // Map Old Value to new value.\n rgbaData[newIndex + 0] = rgbData[index + 0];\n rgbaData[newIndex + 1] = rgbData[index + 1];\n rgbaData[newIndex + 2] = rgbData[index + 2];\n // Add fully opaque alpha channel.\n rgbaData[newIndex + 3] = val1;\n }\n }\n return rgbaData;\n }\n /**\n * Create a function for createRawTexture3D/createRawTexture2DArray\n * @param is3D true for TEXTURE_3D and false for TEXTURE_2D_ARRAY\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function _makeCreateRawTextureFunction(is3D) {\n return function (data, width, height, depth, format, generateMipMaps, invertY, samplingMode, compression = null, textureType = 0) {\n const target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;\n const source = is3D ? InternalTextureSource.Raw3D : InternalTextureSource.Raw2DArray;\n const texture = new InternalTexture(this, source);\n texture.baseWidth = width;\n texture.baseHeight = height;\n texture.baseDepth = depth;\n texture.width = width;\n texture.height = height;\n texture.depth = depth;\n texture.format = format;\n texture.type = textureType;\n texture.generateMipMaps = generateMipMaps;\n texture.samplingMode = samplingMode;\n if (is3D) {\n texture.is3D = true;\n }\n else {\n texture.is2DArray = true;\n }\n if (!this._doNotHandleContextLost) {\n texture._bufferView = data;\n }\n if (is3D) {\n this.updateRawTexture3D(texture, data, format, invertY, compression, textureType);\n }\n else {\n this.updateRawTexture2DArray(texture, data, format, invertY, compression, textureType);\n }\n this._bindTextureDirectly(target, texture, true);\n // Filters\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\n this._gl.texParameteri(target, this._gl.TEXTURE_MAG_FILTER, filters.mag);\n this._gl.texParameteri(target, this._gl.TEXTURE_MIN_FILTER, filters.min);\n if (generateMipMaps) {\n this._gl.generateMipmap(target);\n }\n this._bindTextureDirectly(target, null);\n this._internalTexturesCache.push(texture);\n return texture;\n };\n }\n ThinEngine.prototype.createRawTexture2DArray = _makeCreateRawTextureFunction(false);\n ThinEngine.prototype.createRawTexture3D = _makeCreateRawTextureFunction(true);\n /**\n * Create a function for updateRawTexture3D/updateRawTexture2DArray\n * @param is3D true for TEXTURE_3D and false for TEXTURE_2D_ARRAY\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n function _makeUpdateRawTextureFunction(is3D) {\n return function (texture, data, format, invertY, compression = null, textureType = 0) {\n const target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;\n const internalType = this._getWebGLTextureType(textureType);\n const internalFormat = this._getInternalFormat(format);\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(textureType, format);\n this._bindTextureDirectly(target, texture, true);\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\n if (!this._doNotHandleContextLost) {\n texture._bufferView = data;\n texture.format = format;\n texture.invertY = invertY;\n texture._compression = compression;\n }\n if (texture.width % 4 !== 0) {\n this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);\n }\n if (compression && data) {\n this._gl.compressedTexImage3D(target, 0, this.getCaps().s3tc[compression], texture.width, texture.height, texture.depth, 0, data);\n }\n else {\n this._gl.texImage3D(target, 0, internalSizedFomat, texture.width, texture.height, texture.depth, 0, internalFormat, internalType, data);\n }\n if (texture.generateMipMaps) {\n this._gl.generateMipmap(target);\n }\n this._bindTextureDirectly(target, null);\n // this.resetTextureCache();\n texture.isReady = true;\n };\n }\n ThinEngine.prototype.updateRawTexture2DArray = _makeUpdateRawTextureFunction(false);\n ThinEngine.prototype.updateRawTexture3D = _makeUpdateRawTextureFunction(true);\n\n /**\n * Raw texture can help creating a texture directly from an array of data.\n * This can be super useful if you either get the data from an uncompressed source or\n * if you wish to create your texture pixel by pixel.\n */\n class RawTexture extends Texture {\n /**\n * Instantiates a new RawTexture.\n * Raw texture can help creating a texture directly from an array of data.\n * This can be super useful if you either get the data from an uncompressed source or\n * if you wish to create your texture pixel by pixel.\n * @param data define the array of data to use to create the texture (null to create an empty texture)\n * @param width define the width of the texture\n * @param height define the height of the texture\n * @param format define the format of the data (RGB, RGBA... Engine.TEXTUREFORMAT_xxx)\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps define whether mip maps should be generated or not\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\n */\n constructor(data, width, height, \n /**\n * Define the format of the data (RGB, RGBA... Engine.TEXTUREFORMAT_xxx)\n */\n format, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3, type = 0, creationFlags, useSRGBBuffer) {\n super(null, sceneOrEngine, !generateMipMaps, invertY, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, creationFlags);\n this.format = format;\n if (!this._engine) {\n return;\n }\n if (!this._engine._caps.textureFloatLinearFiltering && type === 1) {\n samplingMode = 1;\n }\n if (!this._engine._caps.textureHalfFloatLinearFiltering && type === 2) {\n samplingMode = 1;\n }\n this._texture = this._engine.createRawTexture(data, width, height, format, generateMipMaps, invertY, samplingMode, null, type, creationFlags !== null && creationFlags !== void 0 ? creationFlags : 0, useSRGBBuffer !== null && useSRGBBuffer !== void 0 ? useSRGBBuffer : false);\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\n }\n /**\n * Updates the texture underlying data.\n * @param data Define the new data of the texture\n */\n update(data) {\n this._getEngine().updateRawTexture(this._texture, data, this._texture.format, this._texture.invertY, null, this._texture.type, this._texture._useSRGBBuffer);\n }\n /**\n * Creates a luminance texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @returns the luminance texture\n */\n static CreateLuminanceTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3) {\n return new RawTexture(data, width, height, 1, sceneOrEngine, generateMipMaps, invertY, samplingMode);\n }\n /**\n * Creates a luminance alpha texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @returns the luminance alpha texture\n */\n static CreateLuminanceAlphaTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3) {\n return new RawTexture(data, width, height, 2, sceneOrEngine, generateMipMaps, invertY, samplingMode);\n }\n /**\n * Creates an alpha texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @returns the alpha texture\n */\n static CreateAlphaTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3) {\n return new RawTexture(data, width, height, 0, sceneOrEngine, generateMipMaps, invertY, samplingMode);\n }\n /**\n * Creates a RGB texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\n * @returns the RGB alpha texture\n */\n static CreateRGBTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3, type = 0, creationFlags = 0, useSRGBBuffer = false) {\n return new RawTexture(data, width, height, 4, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, creationFlags, useSRGBBuffer);\n }\n /**\n * Creates a RGBA texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\n * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\n * @returns the RGBA texture\n */\n static CreateRGBATexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3, type = 0, creationFlags = 0, useSRGBBuffer = false) {\n return new RawTexture(data, width, height, 5, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, creationFlags, useSRGBBuffer);\n }\n /**\n * Creates a RGBA storage texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\n * @returns the RGBA texture\n */\n static CreateRGBAStorageTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = 3, type = 0, useSRGBBuffer = false) {\n return new RawTexture(data, width, height, 5, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, 1, useSRGBBuffer);\n }\n /**\n * Creates a R texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\n * @returns the R texture\n */\n static CreateRTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, type = 1) {\n return new RawTexture(data, width, height, 6, sceneOrEngine, generateMipMaps, invertY, samplingMode, type);\n }\n /**\n * Creates a R storage texture from some data.\n * @param data Define the texture data\n * @param width Define the width of the texture\n * @param height Define the height of the texture\n * @param sceneOrEngine defines the scene or engine the texture will belong to\n * @param generateMipMaps Define whether or not to create mip maps for the texture\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\n * @returns the R texture\n */\n static CreateRStorageTexture(data, width, height, sceneOrEngine, generateMipMaps = true, invertY = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, type = 1) {\n return new RawTexture(data, width, height, 6, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, 1);\n }\n }\n\n /* eslint-disable @typescript-eslint/naming-convention */\n /** Defines the cross module used constants to avoid circular dependencies */\n class Constants {\n }\n /** Defines that alpha blending is disabled */\n Constants.ALPHA_DISABLE = 0;\n /** Defines that alpha blending is SRC ALPHA * SRC + DEST */\n Constants.ALPHA_ADD = 1;\n /** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */\n Constants.ALPHA_COMBINE = 2;\n /** Defines that alpha blending is DEST - SRC * DEST */\n Constants.ALPHA_SUBTRACT = 3;\n /** Defines that alpha blending is SRC * DEST */\n Constants.ALPHA_MULTIPLY = 4;\n /** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC) * DEST */\n Constants.ALPHA_MAXIMIZED = 5;\n /** Defines that alpha blending is SRC + DEST */\n Constants.ALPHA_ONEONE = 6;\n /** Defines that alpha blending is SRC + (1 - SRC ALPHA) * DEST */\n Constants.ALPHA_PREMULTIPLIED = 7;\n /**\n * Defines that alpha blending is SRC + (1 - SRC ALPHA) * DEST\n * Alpha will be set to (1 - SRC ALPHA) * DEST ALPHA\n */\n Constants.ALPHA_PREMULTIPLIED_PORTERDUFF = 8;\n /** Defines that alpha blending is CST * SRC + (1 - CST) * DEST */\n Constants.ALPHA_INTERPOLATE = 9;\n /**\n * Defines that alpha blending is SRC + (1 - SRC) * DEST\n * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DEST ALPHA\n */\n Constants.ALPHA_SCREENMODE = 10;\n /**\n * Defines that alpha blending is SRC + DST\n * Alpha will be set to SRC ALPHA + DST ALPHA\n */\n Constants.ALPHA_ONEONE_ONEONE = 11;\n /**\n * Defines that alpha blending is SRC * DST ALPHA + DST\n * Alpha will be set to 0\n */\n Constants.ALPHA_ALPHATOCOLOR = 12;\n /**\n * Defines that alpha blending is SRC * (1 - DST) + DST * (1 - SRC)\n */\n Constants.ALPHA_REVERSEONEMINUS = 13;\n /**\n * Defines that alpha blending is SRC + DST * (1 - SRC ALPHA)\n * Alpha will be set to SRC ALPHA + DST ALPHA * (1 - SRC ALPHA)\n */\n Constants.ALPHA_SRC_DSTONEMINUSSRCALPHA = 14;\n /**\n * Defines that alpha blending is SRC + DST\n * Alpha will be set to SRC ALPHA\n */\n Constants.ALPHA_ONEONE_ONEZERO = 15;\n /**\n * Defines that alpha blending is SRC * (1 - DST) + DST * (1 - SRC)\n * Alpha will be set to DST ALPHA\n */\n Constants.ALPHA_EXCLUSION = 16;\n /**\n * Defines that alpha blending is SRC * SRC ALPHA + DST * (1 - SRC ALPHA)\n * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DST ALPHA\n */\n Constants.ALPHA_LAYER_ACCUMULATE = 17;\n /** Defines that alpha blending equation a SUM */\n Constants.ALPHA_EQUATION_ADD = 0;\n /** Defines that alpha blending equation a SUBSTRACTION */\n Constants.ALPHA_EQUATION_SUBSTRACT = 1;\n /** Defines that alpha blending equation a REVERSE SUBSTRACTION */\n Constants.ALPHA_EQUATION_REVERSE_SUBTRACT = 2;\n /** Defines that alpha blending equation a MAX operation */\n Constants.ALPHA_EQUATION_MAX = 3;\n /** Defines that alpha blending equation a MIN operation */\n Constants.ALPHA_EQUATION_MIN = 4;\n /**\n * Defines that alpha blending equation a DARKEN operation:\n * It takes the min of the src and sums the alpha channels.\n */\n Constants.ALPHA_EQUATION_DARKEN = 5;\n /** Defines that the resource is not delayed*/\n Constants.DELAYLOADSTATE_NONE = 0;\n /** Defines that the resource was successfully delay loaded */\n Constants.DELAYLOADSTATE_LOADED = 1;\n /** Defines that the resource is currently delay loading */\n Constants.DELAYLOADSTATE_LOADING = 2;\n /** Defines that the resource is delayed and has not started loading */\n Constants.DELAYLOADSTATE_NOTLOADED = 4;\n // Depth or Stencil test Constants.\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn */\n Constants.NEVER = 0x0200;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */\n Constants.ALWAYS = 0x0207;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value */\n Constants.LESS = 0x0201;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value */\n Constants.EQUAL = 0x0202;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value */\n Constants.LEQUAL = 0x0203;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value */\n Constants.GREATER = 0x0204;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value */\n Constants.GEQUAL = 0x0206;\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value */\n Constants.NOTEQUAL = 0x0205;\n // Stencil Actions Constants.\n /** Passed to stencilOperation to specify that stencil value must be kept */\n Constants.KEEP = 0x1e00;\n /** Passed to stencilOperation to specify that stencil value must be zero */\n Constants.ZERO = 0x0000;\n /** Passed to stencilOperation to specify that stencil value must be replaced */\n Constants.REPLACE = 0x1e01;\n /** Passed to stencilOperation to specify that stencil value must be incremented */\n Constants.INCR = 0x1e02;\n /** Passed to stencilOperation to specify that stencil value must be decremented */\n Constants.DECR = 0x1e03;\n /** Passed to stencilOperation to specify that stencil value must be inverted */\n Constants.INVERT = 0x150a;\n /** Passed to stencilOperation to specify that stencil value must be incremented with wrapping */\n Constants.INCR_WRAP = 0x8507;\n /** Passed to stencilOperation to specify that stencil value must be decremented with wrapping */\n Constants.DECR_WRAP = 0x8508;\n /** Texture is not repeating outside of 0..1 UVs */\n Constants.TEXTURE_CLAMP_ADDRESSMODE = 0;\n /** Texture is repeating outside of 0..1 UVs */\n Constants.TEXTURE_WRAP_ADDRESSMODE = 1;\n /** Texture is repeating and mirrored */\n Constants.TEXTURE_MIRROR_ADDRESSMODE = 2;\n /** Flag to create a storage texture */\n Constants.TEXTURE_CREATIONFLAG_STORAGE = 1;\n /** ALPHA */\n Constants.TEXTUREFORMAT_ALPHA = 0;\n /** LUMINANCE */\n Constants.TEXTUREFORMAT_LUMINANCE = 1;\n /** LUMINANCE_ALPHA */\n Constants.TEXTUREFORMAT_LUMINANCE_ALPHA = 2;\n /** RGB */\n Constants.TEXTUREFORMAT_RGB = 4;\n /** RGBA */\n Constants.TEXTUREFORMAT_RGBA = 5;\n /** RED */\n Constants.TEXTUREFORMAT_RED = 6;\n /** RED (2nd reference) */\n Constants.TEXTUREFORMAT_R = 6;\n /** RG */\n Constants.TEXTUREFORMAT_RG = 7;\n /** RED_INTEGER */\n Constants.TEXTUREFORMAT_RED_INTEGER = 8;\n /** RED_INTEGER (2nd reference) */\n Constants.TEXTUREFORMAT_R_INTEGER = 8;\n /** RG_INTEGER */\n Constants.TEXTUREFORMAT_RG_INTEGER = 9;\n /** RGB_INTEGER */\n Constants.TEXTUREFORMAT_RGB_INTEGER = 10;\n /** RGBA_INTEGER */\n Constants.TEXTUREFORMAT_RGBA_INTEGER = 11;\n /** BGRA */\n Constants.TEXTUREFORMAT_BGRA = 12;\n /** Depth 24 bits + Stencil 8 bits */\n Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 = 13;\n /** Depth 32 bits float */\n Constants.TEXTUREFORMAT_DEPTH32_FLOAT = 14;\n /** Depth 16 bits */\n Constants.TEXTUREFORMAT_DEPTH16 = 15;\n /** Depth 24 bits */\n Constants.TEXTUREFORMAT_DEPTH24 = 16;\n /** Depth 24 bits unorm + Stencil 8 bits */\n Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 = 17;\n /** Depth 32 bits float + Stencil 8 bits */\n Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8 = 18;\n /** Stencil 8 bits */\n Constants.TEXTUREFORMAT_STENCIL8 = 19;\n /** Compressed BC7 */\n Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM = 36492;\n /** Compressed BC7 (SRGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 36493;\n /** Compressed BC6 unsigned float */\n Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT = 36495;\n /** Compressed BC6 signed float */\n Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT = 36494;\n /** Compressed BC3 */\n Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5 = 33779;\n /** Compressed BC3 (SRGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 35919;\n /** Compressed BC2 */\n Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3 = 33778;\n /** Compressed BC2 (SRGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 35918;\n /** Compressed BC1 (RGBA) */\n Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1 = 33777;\n /** Compressed BC1 (RGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1 = 33776;\n /** Compressed BC1 (SRGB+A) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 35917;\n /** Compressed BC1 (SRGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT = 35916;\n /** Compressed ASTC 4x4 */\n Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4 = 37808;\n /** Compressed ASTC 4x4 (SRGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 37840;\n /** Compressed ETC1 (RGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL = 36196;\n /** Compressed ETC2 (RGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2 = 37492;\n /** Compressed ETC2 (SRGB) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2 = 37493;\n /** Compressed ETC2 (RGB+A1) */\n Constants.TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37494;\n /** Compressed ETC2 (SRGB+A1)*/\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37495;\n /** Compressed ETC2 (RGB+A) */\n Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC = 37496;\n /** Compressed ETC2 (SRGB+1) */\n Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 37497;\n /** UNSIGNED_BYTE */\n Constants.TEXTURETYPE_UNSIGNED_BYTE = 0;\n /** UNSIGNED_BYTE (2nd reference) */\n Constants.TEXTURETYPE_UNSIGNED_INT = 0;\n /** FLOAT */\n Constants.TEXTURETYPE_FLOAT = 1;\n /** HALF_FLOAT */\n Constants.TEXTURETYPE_HALF_FLOAT = 2;\n /** BYTE */\n Constants.TEXTURETYPE_BYTE = 3;\n /** SHORT */\n Constants.TEXTURETYPE_SHORT = 4;\n /** UNSIGNED_SHORT */\n Constants.TEXTURETYPE_UNSIGNED_SHORT = 5;\n /** INT */\n Constants.TEXTURETYPE_INT = 6;\n /** UNSIGNED_INT */\n Constants.TEXTURETYPE_UNSIGNED_INTEGER = 7;\n /** UNSIGNED_SHORT_4_4_4_4 */\n Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4 = 8;\n /** UNSIGNED_SHORT_5_5_5_1 */\n Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1 = 9;\n /** UNSIGNED_SHORT_5_6_5 */\n Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5 = 10;\n /** UNSIGNED_INT_2_10_10_10_REV */\n Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV = 11;\n /** UNSIGNED_INT_24_8 */\n Constants.TEXTURETYPE_UNSIGNED_INT_24_8 = 12;\n /** UNSIGNED_INT_10F_11F_11F_REV */\n Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV = 13;\n /** UNSIGNED_INT_5_9_9_9_REV */\n Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV = 14;\n /** FLOAT_32_UNSIGNED_INT_24_8_REV */\n Constants.TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV = 15;\n /** UNDEFINED */\n Constants.TEXTURETYPE_UNDEFINED = 16;\n /** 2D Texture target*/\n Constants.TEXTURE_2D = 3553;\n /** 2D Array Texture target */\n Constants.TEXTURE_2D_ARRAY = 35866;\n /** Cube Map Texture target */\n Constants.TEXTURE_CUBE_MAP = 34067;\n /** Cube Map Array Texture target */\n Constants.TEXTURE_CUBE_MAP_ARRAY = 0xdeadbeef;\n /** 3D Texture target */\n Constants.TEXTURE_3D = 32879;\n /** nearest is mag = nearest and min = nearest and no mip */\n Constants.TEXTURE_NEAREST_SAMPLINGMODE = 1;\n /** mag = nearest and min = nearest and mip = none */\n Constants.TEXTURE_NEAREST_NEAREST = 1;\n /** Bilinear is mag = linear and min = linear and no mip */\n Constants.TEXTURE_BILINEAR_SAMPLINGMODE = 2;\n /** mag = linear and min = linear and mip = none */\n Constants.TEXTURE_LINEAR_LINEAR = 2;\n /** Trilinear is mag = linear and min = linear and mip = linear */\n Constants.TEXTURE_TRILINEAR_SAMPLINGMODE = 3;\n /** Trilinear is mag = linear and min = linear and mip = linear */\n Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR = 3;\n /** mag = nearest and min = nearest and mip = nearest */\n Constants.TEXTURE_NEAREST_NEAREST_MIPNEAREST = 4;\n /** mag = nearest and min = linear and mip = nearest */\n Constants.TEXTURE_NEAREST_LINEAR_MIPNEAREST = 5;\n /** mag = nearest and min = linear and mip = linear */\n Constants.TEXTURE_NEAREST_LINEAR_MIPLINEAR = 6;\n /** mag = nearest and min = linear and mip = none */\n Constants.TEXTURE_NEAREST_LINEAR = 7;\n /** nearest is mag = nearest and min = nearest and mip = linear */\n Constants.TEXTURE_NEAREST_NEAREST_MIPLINEAR = 8;\n /** mag = linear and min = nearest and mip = nearest */\n Constants.TEXTURE_LINEAR_NEAREST_MIPNEAREST = 9;\n /** mag = linear and min = nearest and mip = linear */\n Constants.TEXTURE_LINEAR_NEAREST_MIPLINEAR = 10;\n /** Bilinear is mag = linear and min = linear and mip = nearest */\n Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST = 11;\n /** mag = linear and min = nearest and mip = none */\n Constants.TEXTURE_LINEAR_NEAREST = 12;\n /** Explicit coordinates mode */\n Constants.TEXTURE_EXPLICIT_MODE = 0;\n /** Spherical coordinates mode */\n Constants.TEXTURE_SPHERICAL_MODE = 1;\n /** Planar coordinates mode */\n Constants.TEXTURE_PLANAR_MODE = 2;\n /** Cubic coordinates mode */\n Constants.TEXTURE_CUBIC_MODE = 3;\n /** Projection coordinates mode */\n Constants.TEXTURE_PROJECTION_MODE = 4;\n /** Skybox coordinates mode */\n Constants.TEXTURE_SKYBOX_MODE = 5;\n /** Inverse Cubic coordinates mode */\n Constants.TEXTURE_INVCUBIC_MODE = 6;\n /** Equirectangular coordinates mode */\n Constants.TEXTURE_EQUIRECTANGULAR_MODE = 7;\n /** Equirectangular Fixed coordinates mode */\n Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MODE = 8;\n /** Equirectangular Fixed Mirrored coordinates mode */\n Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;\n /** Offline (baking) quality for texture filtering */\n Constants.TEXTURE_FILTERING_QUALITY_OFFLINE = 4096;\n /** High quality for texture filtering */\n Constants.TEXTURE_FILTERING_QUALITY_HIGH = 64;\n /** Medium quality for texture filtering */\n Constants.TEXTURE_FILTERING_QUALITY_MEDIUM = 16;\n /** Low quality for texture filtering */\n Constants.TEXTURE_FILTERING_QUALITY_LOW = 8;\n // Texture rescaling mode\n /** Defines that texture rescaling will use a floor to find the closer power of 2 size */\n Constants.SCALEMODE_FLOOR = 1;\n /** Defines that texture rescaling will look for the nearest power of 2 size */\n Constants.SCALEMODE_NEAREST = 2;\n /** Defines that texture rescaling will use a ceil to find the closer power of 2 size */\n Constants.SCALEMODE_CEILING = 3;\n /**\n * The dirty texture flag value\n */\n Constants.MATERIAL_TextureDirtyFlag = 1;\n /**\n * The dirty light flag value\n */\n Constants.MATERIAL_LightDirtyFlag = 2;\n /**\n * The dirty fresnel flag value\n */\n Constants.MATERIAL_FresnelDirtyFlag = 4;\n /**\n * The dirty attribute flag value\n */\n Constants.MATERIAL_AttributesDirtyFlag = 8;\n /**\n * The dirty misc flag value\n */\n Constants.MATERIAL_MiscDirtyFlag = 16;\n /**\n * The dirty prepass flag value\n */\n Constants.MATERIAL_PrePassDirtyFlag = 32;\n /**\n * The all dirty flag value\n */\n Constants.MATERIAL_AllDirtyFlag = 63;\n /**\n * Returns the triangle fill mode\n */\n Constants.MATERIAL_TriangleFillMode = 0;\n /**\n * Returns the wireframe mode\n */\n Constants.MATERIAL_WireFrameFillMode = 1;\n /**\n * Returns the point fill mode\n */\n Constants.MATERIAL_PointFillMode = 2;\n /**\n * Returns the point list draw mode\n */\n Constants.MATERIAL_PointListDrawMode = 3;\n /**\n * Returns the line list draw mode\n */\n Constants.MATERIAL_LineListDrawMode = 4;\n /**\n * Returns the line loop draw mode\n */\n Constants.MATERIAL_LineLoopDrawMode = 5;\n /**\n * Returns the line strip draw mode\n */\n Constants.MATERIAL_LineStripDrawMode = 6;\n /**\n * Returns the triangle strip draw mode\n */\n Constants.MATERIAL_TriangleStripDrawMode = 7;\n /**\n * Returns the triangle fan draw mode\n */\n Constants.MATERIAL_TriangleFanDrawMode = 8;\n /**\n * Stores the clock-wise side orientation\n */\n Constants.MATERIAL_ClockWiseSideOrientation = 0;\n /**\n * Stores the counter clock-wise side orientation\n */\n Constants.MATERIAL_CounterClockWiseSideOrientation = 1;\n /**\n * Nothing\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_NothingTrigger = 0;\n /**\n * On pick\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnPickTrigger = 1;\n /**\n * On left pick\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnLeftPickTrigger = 2;\n /**\n * On right pick\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnRightPickTrigger = 3;\n /**\n * On center pick\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnCenterPickTrigger = 4;\n /**\n * On pick down\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnPickDownTrigger = 5;\n /**\n * On double pick\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnDoublePickTrigger = 6;\n /**\n * On pick up\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnPickUpTrigger = 7;\n /**\n * On pick out.\n * This trigger will only be raised if you also declared a OnPickDown\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnPickOutTrigger = 16;\n /**\n * On long press\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnLongPressTrigger = 8;\n /**\n * On pointer over\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnPointerOverTrigger = 9;\n /**\n * On pointer out\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnPointerOutTrigger = 10;\n /**\n * On every frame\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnEveryFrameTrigger = 11;\n /**\n * On intersection enter\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnIntersectionEnterTrigger = 12;\n /**\n * On intersection exit\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnIntersectionExitTrigger = 13;\n /**\n * On key down\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnKeyDownTrigger = 14;\n /**\n * On key up\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\n */\n Constants.ACTION_OnKeyUpTrigger = 15;\n /**\n * Billboard mode will only apply to Y axis\n */\n Constants.PARTICLES_BILLBOARDMODE_Y = 2;\n /**\n * Billboard mode will apply to all axes\n */\n Constants.PARTICLES_BILLBOARDMODE_ALL = 7;\n /**\n * Special billboard mode where the particle will be biilboard to the camera but rotated to align with direction\n */\n Constants.PARTICLES_BILLBOARDMODE_STRETCHED = 8;\n /**\n * Special billboard mode where the particle will be billboard to the camera but only around the axis of the direction of particle emission\n */\n Constants.PARTICLES_BILLBOARDMODE_STRETCHED_LOCAL = 9;\n /** Default culling strategy : this is an exclusion test and it's the more accurate.\n * Test order :\n * Is the bounding sphere outside the frustum ?\n * If not, are the bounding box vertices outside the frustum ?\n * It not, then the cullable object is in the frustum.\n */\n Constants.MESHES_CULLINGSTRATEGY_STANDARD = 0;\n /** Culling strategy : Bounding Sphere Only.\n * This is an exclusion test. It's faster than the standard strategy because the bounding box is not tested.\n * It's also less accurate than the standard because some not visible objects can still be selected.\n * Test : is the bounding sphere outside the frustum ?\n * If not, then the cullable object is in the frustum.\n */\n Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = 1;\n /** Culling strategy : Optimistic Inclusion.\n * This in an inclusion test first, then the standard exclusion test.\n * This can be faster when a cullable object is expected to be almost always in the camera frustum.\n * This could also be a little slower than the standard test when the tested object center is not the frustum but one of its bounding box vertex is still inside.\n * Anyway, it's as accurate as the standard strategy.\n * Test :\n * Is the cullable object bounding sphere center in the frustum ?\n * If not, apply the default culling strategy.\n */\n Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = 2;\n /** Culling strategy : Optimistic Inclusion then Bounding Sphere Only.\n * This in an inclusion test first, then the bounding sphere only exclusion test.\n * This can be the fastest test when a cullable object is expected to be almost always in the camera frustum.\n * This could also be a little slower than the BoundingSphereOnly strategy when the tested object center is not in the frustum but its bounding sphere still intersects it.\n * It's less accurate than the standard strategy and as accurate as the BoundingSphereOnly strategy.\n * Test :\n * Is the cullable object bounding sphere center in the frustum ?\n * If not, apply the Bounding Sphere Only strategy. No Bounding Box is tested here.\n */\n Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = 3;\n /**\n * No logging while loading\n */\n Constants.SCENELOADER_NO_LOGGING = 0;\n /**\n * Minimal logging while loading\n */\n Constants.SCENELOADER_MINIMAL_LOGGING = 1;\n /**\n * Summary logging while loading\n */\n Constants.SCENELOADER_SUMMARY_LOGGING = 2;\n /**\n * Detailed logging while loading\n */\n Constants.SCENELOADER_DETAILED_LOGGING = 3;\n /**\n * Constant used to retrieve the irradiance texture index in the textures array in the prepass\n * using getIndex(Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE)\n */\n Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE = 0;\n /**\n * Constant used to retrieve the position texture index in the textures array in the prepass\n * using getIndex(Constants.PREPASS_POSITION_TEXTURE_INDEX)\n */\n Constants.PREPASS_POSITION_TEXTURE_TYPE = 1;\n /**\n * Constant used to retrieve the velocity texture index in the textures array in the prepass\n * using getIndex(Constants.PREPASS_VELOCITY_TEXTURE_INDEX)\n */\n Constants.PREPASS_VELOCITY_TEXTURE_TYPE = 2;\n /**\n * Constant used to retrieve the reflectivity texture index in the textures array in the prepass\n * using the getIndex(Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE)\n */\n Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE = 3;\n /**\n * Constant used to retrieve the lit color texture index in the textures array in the prepass\n * using the getIndex(Constants.PREPASS_COLOR_TEXTURE_TYPE)\n */\n Constants.PREPASS_COLOR_TEXTURE_TYPE = 4;\n /**\n * Constant used to retrieve depth index in the textures array in the prepass\n * using the getIndex(Constants.PREPASS_DEPTH_TEXTURE_TYPE)\n */\n Constants.PREPASS_DEPTH_TEXTURE_TYPE = 5;\n /**\n * Constant used to retrieve normal index in the textures array in the prepass\n * using the getIndex(Constants.PREPASS_NORMAL_TEXTURE_TYPE)\n */\n Constants.PREPASS_NORMAL_TEXTURE_TYPE = 6;\n /**\n * Constant used to retrieve albedo index in the textures array in the prepass\n * using the getIndex(Constants.PREPASS_ALBEDO_SQRT_TEXTURE_TYPE)\n */\n Constants.PREPASS_ALBEDO_SQRT_TEXTURE_TYPE = 7;\n /** Flag to create a readable buffer (the buffer can be the source of a copy) */\n Constants.BUFFER_CREATIONFLAG_READ = 1;\n /** Flag to create a writable buffer (the buffer can be the destination of a copy) */\n Constants.BUFFER_CREATIONFLAG_WRITE = 2;\n /** Flag to create a readable and writable buffer */\n Constants.BUFFER_CREATIONFLAG_READWRITE = 3;\n /** Flag to create a buffer suitable to be used as a uniform buffer */\n Constants.BUFFER_CREATIONFLAG_UNIFORM = 4;\n /** Flag to create a buffer suitable to be used as a vertex buffer */\n Constants.BUFFER_CREATIONFLAG_VERTEX = 8;\n /** Flag to create a buffer suitable to be used as an index buffer */\n Constants.BUFFER_CREATIONFLAG_INDEX = 16;\n /** Flag to create a buffer suitable to be used as a storage buffer */\n Constants.BUFFER_CREATIONFLAG_STORAGE = 32;\n /**\n * Prefixes used by the engine for sub mesh draw wrappers\n */\n /** @internal */\n Constants.RENDERPASS_MAIN = 0;\n /**\n * Constant used as key code for Alt key\n */\n Constants.INPUT_ALT_KEY = 18;\n /**\n * Constant used as key code for Ctrl key\n */\n Constants.INPUT_CTRL_KEY = 17;\n /**\n * Constant used as key code for Meta key (Left Win, Left Cmd)\n */\n Constants.INPUT_META_KEY1 = 91;\n /**\n * Constant used as key code for Meta key (Right Win)\n */\n Constants.INPUT_META_KEY2 = 92;\n /**\n * Constant used as key code for Meta key (Right Win, Right Cmd)\n */\n Constants.INPUT_META_KEY3 = 93;\n /**\n * Constant used as key code for Shift key\n */\n Constants.INPUT_SHIFT_KEY = 16;\n /** Standard snapshot rendering. In this mode, some form of dynamic behavior is possible (for eg, uniform buffers are still updated) */\n Constants.SNAPSHOTRENDERING_STANDARD = 0;\n /** Fast snapshot rendering. In this mode, everything is static and only some limited form of dynamic behaviour is possible */\n Constants.SNAPSHOTRENDERING_FAST = 1;\n /**\n * This is the default projection mode used by the cameras.\n * It helps recreating a feeling of perspective and better appreciate depth.\n * This is the best way to simulate real life cameras.\n */\n Constants.PERSPECTIVE_CAMERA = 0;\n /**\n * This helps creating camera with an orthographic mode.\n * Orthographic is commonly used in engineering as a means to produce object specifications that communicate dimensions unambiguously, each line of 1 unit length (cm, meter..whatever) will appear to have the same length everywhere on the drawing. This allows the drafter to dimension only a subset of lines and let the reader know that other lines of that length on the drawing are also that length in reality. Every parallel line in the drawing is also parallel in the object.\n */\n Constants.ORTHOGRAPHIC_CAMERA = 1;\n /**\n * This is the default FOV mode for perspective cameras.\n * This setting aligns the upper and lower bounds of the viewport to the upper and lower bounds of the camera frustum.\n */\n Constants.FOVMODE_VERTICAL_FIXED = 0;\n /**\n * This setting aligns the left and right bounds of the viewport to the left and right bounds of the camera frustum.\n */\n Constants.FOVMODE_HORIZONTAL_FIXED = 1;\n /**\n * This specifies there is no need for a camera rig.\n * Basically only one eye is rendered corresponding to the camera.\n */\n Constants.RIG_MODE_NONE = 0;\n /**\n * Simulates a camera Rig with one blue eye and one red eye.\n * This can be use with 3d blue and red glasses.\n */\n Constants.RIG_MODE_STEREOSCOPIC_ANAGLYPH = 10;\n /**\n * Defines that both eyes of the camera will be rendered side by side with a parallel target.\n */\n Constants.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = 11;\n /**\n * Defines that both eyes of the camera will be rendered side by side with a none parallel target.\n */\n Constants.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;\n /**\n * Defines that both eyes of the camera will be rendered over under each other.\n */\n Constants.RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;\n /**\n * Defines that both eyes of the camera will be rendered on successive lines interlaced for passive 3d monitors.\n */\n Constants.RIG_MODE_STEREOSCOPIC_INTERLACED = 14;\n /**\n * Defines that both eyes of the camera should be renderered in a VR mode (carbox).\n */\n Constants.RIG_MODE_VR = 20;\n /**\n * Defines that both eyes of the camera should be renderered in a VR mode (webVR).\n */\n Constants.RIG_MODE_WEBVR = 21;\n /**\n * Custom rig mode allowing rig cameras to be populated manually with any number of cameras\n */\n Constants.RIG_MODE_CUSTOM = 22;\n /**\n * Maximum number of uv sets supported\n */\n Constants.MAX_SUPPORTED_UV_SETS = 6;\n /**\n * GL constants\n */\n /** Alpha blend equation: ADD */\n Constants.GL_ALPHA_EQUATION_ADD = 0x8006;\n /** Alpha equation: MIN */\n Constants.GL_ALPHA_EQUATION_MIN = 0x8007;\n /** Alpha equation: MAX */\n Constants.GL_ALPHA_EQUATION_MAX = 0x8008;\n /** Alpha equation: SUBTRACT */\n Constants.GL_ALPHA_EQUATION_SUBTRACT = 0x800a;\n /** Alpha equation: REVERSE_SUBTRACT */\n Constants.GL_ALPHA_EQUATION_REVERSE_SUBTRACT = 0x800b;\n /** Alpha blend function: SRC */\n Constants.GL_ALPHA_FUNCTION_SRC = 0x0300;\n /** Alpha blend function: ONE_MINUS_SRC */\n Constants.GL_ALPHA_FUNCTION_ONE_MINUS_SRC_COLOR = 0x0301;\n /** Alpha blend function: SRC_ALPHA */\n Constants.GL_ALPHA_FUNCTION_SRC_ALPHA = 0x0302;\n /** Alpha blend function: ONE_MINUS_SRC_ALPHA */\n Constants.GL_ALPHA_FUNCTION_ONE_MINUS_SRC_ALPHA = 0x0303;\n /** Alpha blend function: DST_ALPHA */\n Constants.GL_ALPHA_FUNCTION_DST_ALPHA = 0x0304;\n /** Alpha blend function: ONE_MINUS_DST_ALPHA */\n Constants.GL_ALPHA_FUNCTION_ONE_MINUS_DST_ALPHA = 0x0305;\n /** Alpha blend function: ONE_MINUS_DST */\n Constants.GL_ALPHA_FUNCTION_DST_COLOR = 0x0306;\n /** Alpha blend function: ONE_MINUS_DST */\n Constants.GL_ALPHA_FUNCTION_ONE_MINUS_DST_COLOR = 0x0307;\n /** Alpha blend function: SRC_ALPHA_SATURATED */\n Constants.GL_ALPHA_FUNCTION_SRC_ALPHA_SATURATED = 0x0308;\n /** Alpha blend function: CONSTANT */\n Constants.GL_ALPHA_FUNCTION_CONSTANT_COLOR = 0x8001;\n /** Alpha blend function: ONE_MINUS_CONSTANT */\n Constants.GL_ALPHA_FUNCTION_ONE_MINUS_CONSTANT_COLOR = 0x8002;\n /** Alpha blend function: CONSTANT_ALPHA */\n Constants.GL_ALPHA_FUNCTION_CONSTANT_ALPHA = 0x8003;\n /** Alpha blend function: ONE_MINUS_CONSTANT_ALPHA */\n Constants.GL_ALPHA_FUNCTION_ONE_MINUS_CONSTANT_ALPHA = 0x8004;\n /** URL to the snippet server. Points to the public snippet server by default */\n Constants.SnippetUrl = \"https://snippet.babylonjs.com\";\n\n function getFileExtensionFromMimeType(mimeType) {\n switch (mimeType) {\n case \"image/jpeg\" /* ImageMimeType.JPEG */:\n return \".jpg\";\n case \"image/png\" /* ImageMimeType.PNG */:\n return \".png\";\n case \"image/webp\" /* ImageMimeType.WEBP */:\n return \".webp\";\n }\n }\n /**\n * Utility methods for working with glTF material conversion properties. This class should only be used internally\n * @internal\n */\n class _GLTFMaterialExporter {\n constructor(exporter) {\n /**\n * Mapping to store textures\n */\n this._textureMap = {};\n // Mapping of internal textures to images to avoid exporting duplicate images.\n this._internalTextureToImage = {};\n this._textureMap = {};\n this._exporter = exporter;\n }\n /**\n * Specifies if two colors are approximately equal in value\n * @param color1 first color to compare to\n * @param color2 second color to compare to\n * @param epsilon threshold value\n */\n static _FuzzyEquals(color1, color2, epsilon) {\n return Scalar.WithinEpsilon(color1.r, color2.r, epsilon) && Scalar.WithinEpsilon(color1.g, color2.g, epsilon) && Scalar.WithinEpsilon(color1.b, color2.b, epsilon);\n }\n /**\n * Gets the materials from a Babylon scene and converts them to glTF materials\n * @param exportMaterials\n * @param mimeType texture mime type\n * @param hasTextureCoords specifies if texture coordinates are present on the material\n */\n _convertMaterialsToGLTFAsync(exportMaterials, mimeType, hasTextureCoords) {\n const promises = [];\n exportMaterials.forEach((material) => {\n if (material.getClassName() === \"StandardMaterial\") {\n promises.push(this._convertStandardMaterialAsync(material, mimeType, hasTextureCoords));\n }\n else if (material.getClassName().indexOf(\"PBR\") !== -1) {\n promises.push(this._convertPBRMaterialAsync(material, mimeType, hasTextureCoords));\n }\n else {\n Tools.Warn(`Unsupported material type: ${material.name}`);\n }\n });\n return Promise.all(promises).then(() => {\n /* do nothing */\n });\n }\n /**\n * Makes a copy of the glTF material without the texture parameters\n * @param originalMaterial original glTF material\n * @returns glTF material without texture parameters\n */\n _stripTexturesFromMaterial(originalMaterial) {\n const newMaterial = {};\n if (originalMaterial) {\n newMaterial.name = originalMaterial.name;\n newMaterial.doubleSided = originalMaterial.doubleSided;\n newMaterial.alphaMode = originalMaterial.alphaMode;\n newMaterial.alphaCutoff = originalMaterial.alphaCutoff;\n newMaterial.emissiveFactor = originalMaterial.emissiveFactor;\n const originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;\n if (originalPBRMetallicRoughness) {\n newMaterial.pbrMetallicRoughness = {};\n newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;\n newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;\n newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;\n }\n }\n return newMaterial;\n }\n /**\n * Specifies if the material has any texture parameters present\n * @param material glTF Material\n * @returns boolean specifying if texture parameters are present\n */\n _hasTexturesPresent(material) {\n var _a;\n if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {\n return true;\n }\n const pbrMat = material.pbrMetallicRoughness;\n if (pbrMat) {\n if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {\n return true;\n }\n }\n if (material.extensions) {\n for (const extension in material.extensions) {\n const extensionObject = material.extensions[extension];\n if (extensionObject) {\n return (_a = extensionObject.hasTextures) === null || _a === void 0 ? void 0 : _a.call(extensionObject);\n }\n }\n }\n return false;\n }\n _getTextureInfo(babylonTexture) {\n if (babylonTexture) {\n const textureUid = babylonTexture.uid;\n if (textureUid in this._textureMap) {\n return this._textureMap[textureUid];\n }\n }\n return null;\n }\n /**\n * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material\n * @param babylonStandardMaterial\n * @returns glTF Metallic Roughness Material representation\n */\n _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial) {\n // Defines a cubic bezier curve where x is specular power and y is roughness\n const P0 = new Vector2(0, 1);\n const P1 = new Vector2(0, 0.1);\n const P2 = new Vector2(0, 0.1);\n const P3 = new Vector2(1300, 0.1);\n /**\n * Given the control points, solve for x based on a given t for a cubic bezier curve\n * @param t a value between 0 and 1\n * @param p0 first control point\n * @param p1 second control point\n * @param p2 third control point\n * @param p3 fourth control point\n * @returns number result of cubic bezier curve at the specified t\n */\n function cubicBezierCurve(t, p0, p1, p2, p3) {\n return (1 - t) * (1 - t) * (1 - t) * p0 + 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t * p3;\n }\n /**\n * Evaluates a specified specular power value to determine the appropriate roughness value,\n * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)\n * and roughness on the ordinant axis (y-axis)\n * @param specularPower specular power of standard material\n * @returns Number representing the roughness value\n */\n function solveForRoughness(specularPower) {\n // Given P0.x = 0, P1.x = 0, P2.x = 0\n // x = t * t * t * P3.x\n // t = (x / P3.x)^(1/3)\n const t = Math.pow(specularPower / P3.x, 0.333333);\n return cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);\n }\n const diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace(babylonStandardMaterial.getScene().getEngine().useExactSrgbConversions).scale(0.5);\n const opacity = babylonStandardMaterial.alpha;\n const specularPower = Scalar.Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);\n const roughness = solveForRoughness(specularPower);\n const glTFPbrMetallicRoughness = {\n baseColorFactor: [diffuse.r, diffuse.g, diffuse.b, opacity],\n metallicFactor: 0,\n roughnessFactor: roughness,\n };\n return glTFPbrMetallicRoughness;\n }\n /**\n * Computes the metallic factor\n * @param diffuse diffused value\n * @param specular specular value\n * @param oneMinusSpecularStrength one minus the specular strength\n * @returns metallic value\n */\n static _SolveMetallic(diffuse, specular, oneMinusSpecularStrength) {\n if (specular < this._DielectricSpecular.r) {\n this._DielectricSpecular;\n return 0;\n }\n const a = this._DielectricSpecular.r;\n const b = (diffuse * oneMinusSpecularStrength) / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;\n const c = this._DielectricSpecular.r - specular;\n const D = b * b - 4.0 * a * c;\n return Scalar.Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);\n }\n /**\n * Sets the glTF alpha mode to a glTF material from the Babylon Material\n * @param glTFMaterial glTF material\n * @param babylonMaterial Babylon material\n */\n static _SetAlphaMode(glTFMaterial, babylonMaterial) {\n if (babylonMaterial.needAlphaBlending()) {\n glTFMaterial.alphaMode = \"BLEND\" /* MaterialAlphaMode.BLEND */;\n }\n else if (babylonMaterial.needAlphaTesting()) {\n glTFMaterial.alphaMode = \"MASK\" /* MaterialAlphaMode.MASK */;\n glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;\n }\n }\n /**\n * Converts a Babylon Standard Material to a glTF Material\n * @param babylonStandardMaterial BJS Standard Material\n * @param mimeType mime type to use for the textures\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\n */\n _convertStandardMaterialAsync(babylonStandardMaterial, mimeType, hasTextureCoords) {\n const materialMap = this._exporter._materialMap;\n const materials = this._exporter._materials;\n const promises = [];\n const pbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);\n const material = { name: babylonStandardMaterial.name };\n if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {\n if (!babylonStandardMaterial.twoSidedLighting) {\n Tools.Warn(babylonStandardMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\n }\n material.doubleSided = true;\n }\n if (hasTextureCoords) {\n if (babylonStandardMaterial.diffuseTexture) {\n promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then((textureInfo) => {\n if (textureInfo) {\n pbrMetallicRoughness.baseColorTexture = textureInfo;\n }\n }));\n }\n const bumpTexture = babylonStandardMaterial.bumpTexture;\n if (bumpTexture) {\n promises.push(this._exportTextureAsync(bumpTexture, mimeType).then((textureInfo) => {\n if (textureInfo) {\n material.normalTexture = textureInfo;\n if (bumpTexture.level !== 1) {\n material.normalTexture.scale = bumpTexture.level;\n }\n }\n }));\n }\n if (babylonStandardMaterial.emissiveTexture) {\n material.emissiveFactor = [1.0, 1.0, 1.0];\n promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then((textureInfo) => {\n if (textureInfo) {\n material.emissiveTexture = textureInfo;\n }\n }));\n }\n if (babylonStandardMaterial.ambientTexture) {\n promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then((textureInfo) => {\n if (textureInfo) {\n const occlusionTexture = {\n index: textureInfo.index,\n };\n material.occlusionTexture = occlusionTexture;\n }\n }));\n }\n }\n if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {\n if (babylonStandardMaterial.alphaMode === Constants.ALPHA_COMBINE) {\n material.alphaMode = \"BLEND\" /* MaterialAlphaMode.BLEND */;\n }\n else {\n Tools.Warn(babylonStandardMaterial.name + \": glTF 2.0 does not support alpha mode: \" + babylonStandardMaterial.alphaMode.toString());\n }\n }\n if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter._FuzzyEquals(babylonStandardMaterial.emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\n material.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();\n }\n material.pbrMetallicRoughness = pbrMetallicRoughness;\n _GLTFMaterialExporter._SetAlphaMode(material, babylonStandardMaterial);\n materials.push(material);\n materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;\n return this._finishMaterial(promises, material, babylonStandardMaterial, mimeType);\n }\n _finishMaterial(promises, glTFMaterial, babylonMaterial, mimeType) {\n return Promise.all(promises).then(() => {\n const textures = this._exporter._extensionsPostExportMaterialAdditionalTextures(\"exportMaterial\", glTFMaterial, babylonMaterial);\n let tasks = null;\n for (const texture of textures) {\n if (!tasks) {\n tasks = [];\n }\n tasks.push(this._exportTextureAsync(texture, mimeType));\n }\n if (!tasks) {\n tasks = [Promise.resolve(null)];\n }\n return Promise.all(tasks).then(() => {\n const extensionWork = this._exporter._extensionsPostExportMaterialAsync(\"exportMaterial\", glTFMaterial, babylonMaterial);\n if (!extensionWork) {\n return glTFMaterial;\n }\n return extensionWork.then(() => glTFMaterial);\n });\n });\n }\n /**\n * Converts an image typed array buffer to a base64 image\n * @param buffer typed array buffer\n * @param width width of the image\n * @param height height of the image\n * @param mimeType mimetype of the image\n * @returns base64 image string\n */\n async _getImageDataAsync(buffer, width, height, mimeType) {\n const textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\n const hostingScene = this._exporter._babylonScene;\n const engine = hostingScene.getEngine();\n // Create a temporary texture with the texture buffer data\n const tempTexture = engine.createRawTexture(buffer, width, height, Constants.TEXTUREFORMAT_RGBA, false, true, Texture.NEAREST_SAMPLINGMODE, null, textureType);\n await TextureTools.ApplyPostProcess(\"pass\", tempTexture, hostingScene, textureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\n const data = await engine._readTexturePixels(tempTexture, width, height);\n return (await DumpTools.DumpDataAsync(width, height, data, mimeType, undefined, true, true));\n }\n /**\n * Generates a white texture based on the specified width and height\n * @param width width of the texture in pixels\n * @param height height of the texture in pixels\n * @param scene babylonjs scene\n * @returns white texture\n */\n _createWhiteTexture(width, height, scene) {\n const data = new Uint8Array(width * height * 4);\n for (let i = 0; i < data.length; i = i + 4) {\n data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xff;\n }\n const rawTexture = RawTexture.CreateRGBATexture(data, width, height, scene);\n return rawTexture;\n }\n /**\n * Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null\n * @param texture1 first texture to resize\n * @param texture2 second texture to resize\n * @param scene babylonjs scene\n * @returns resized textures or null\n */\n _resizeTexturesToSameDimensions(texture1, texture2, scene) {\n const texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };\n const texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };\n let resizedTexture1;\n let resizedTexture2;\n if (texture1Size.width < texture2Size.width) {\n if (texture1 && texture1 instanceof Texture) {\n resizedTexture1 = TextureTools.CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);\n }\n else {\n resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);\n }\n resizedTexture2 = texture2;\n }\n else if (texture1Size.width > texture2Size.width) {\n if (texture2 && texture2 instanceof Texture) {\n resizedTexture2 = TextureTools.CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);\n }\n else {\n resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);\n }\n resizedTexture1 = texture1;\n }\n else {\n resizedTexture1 = texture1;\n resizedTexture2 = texture2;\n }\n return {\n texture1: resizedTexture1,\n texture2: resizedTexture2,\n };\n }\n /**\n * Converts an array of pixels to a Float32Array\n * Throws an error if the pixel format is not supported\n * @param pixels - array buffer containing pixel values\n * @returns Float32 of pixels\n */\n _convertPixelArrayToFloat32(pixels) {\n if (pixels instanceof Uint8Array) {\n const length = pixels.length;\n const buffer = new Float32Array(pixels.length);\n for (let i = 0; i < length; ++i) {\n buffer[i] = pixels[i] / 255;\n }\n return buffer;\n }\n else if (pixels instanceof Float32Array) {\n return pixels;\n }\n else {\n throw new Error(\"Unsupported pixel format!\");\n }\n }\n /**\n * Convert Specular Glossiness Textures to Metallic Roughness\n * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness\n * @link https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-.js/babylon.pbrUtilities.js\n * @param diffuseTexture texture used to store diffuse information\n * @param specularGlossinessTexture texture used to store specular and glossiness information\n * @param factors specular glossiness material factors\n * @param mimeType the mime type to use for the texture\n * @returns pbr metallic roughness interface or null\n */\n async _convertSpecularGlossinessTexturesToMetallicRoughnessAsync(diffuseTexture, specularGlossinessTexture, factors, mimeType) {\n var _a;\n const promises = new Array();\n if (!(diffuseTexture || specularGlossinessTexture)) {\n return Promise.reject(\"_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!\");\n }\n const scene = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;\n if (scene) {\n const resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);\n const diffuseSize = (_a = resizedTextures.texture1) === null || _a === void 0 ? void 0 : _a.getSize();\n let diffuseBuffer;\n let specularGlossinessBuffer;\n const width = diffuseSize.width;\n const height = diffuseSize.height;\n const diffusePixels = await resizedTextures.texture1.readPixels();\n const specularPixels = await resizedTextures.texture2.readPixels();\n if (diffusePixels) {\n diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);\n }\n else {\n return Promise.reject(\"Failed to retrieve pixels from diffuse texture!\");\n }\n if (specularPixels) {\n specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);\n }\n else {\n return Promise.reject(\"Failed to retrieve pixels from specular glossiness texture!\");\n }\n const byteLength = specularGlossinessBuffer.byteLength;\n const metallicRoughnessBuffer = new Uint8Array(byteLength);\n const baseColorBuffer = new Uint8Array(byteLength);\n const strideSize = 4;\n const maxBaseColor = Color3.Black();\n let maxMetallic = 0;\n let maxRoughness = 0;\n for (let h = 0; h < height; ++h) {\n for (let w = 0; w < width; ++w) {\n const offset = (width * h + w) * strideSize;\n const diffuseColor = new Color3(diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2])\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\n .multiply(factors.diffuseColor);\n const specularColor = new Color3(specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2])\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\n .multiply(factors.specularColor);\n const glossiness = specularGlossinessBuffer[offset + 3] * factors.glossiness;\n const specularGlossiness = {\n diffuseColor: diffuseColor,\n specularColor: specularColor,\n glossiness: glossiness,\n };\n const metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);\n maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);\n maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);\n maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);\n maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic);\n maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness);\n baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;\n baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;\n baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;\n baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;\n metallicRoughnessBuffer[offset] = 0;\n metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness * 255;\n metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic * 255;\n metallicRoughnessBuffer[offset + 3] = 255;\n }\n }\n // Retrieves the metallic roughness factors from the maximum texture values.\n const metallicRoughnessFactors = {\n baseColor: maxBaseColor,\n metallic: maxMetallic,\n roughness: maxRoughness,\n };\n let writeOutMetallicRoughnessTexture = false;\n let writeOutBaseColorTexture = false;\n for (let h = 0; h < height; ++h) {\n for (let w = 0; w < width; ++w) {\n const destinationOffset = (width * h + w) * strideSize;\n baseColorBuffer[destinationOffset] /= metallicRoughnessFactors.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.r : 1;\n baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.g : 1;\n baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.b : 1;\n const linearBaseColorPixel = Color3.FromInts(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);\n const sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace(scene.getEngine().useExactSrgbConversions);\n baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;\n baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;\n baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;\n if (!_GLTFMaterialExporter._FuzzyEquals(sRGBBaseColorPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\n writeOutBaseColorTexture = true;\n }\n metallicRoughnessBuffer[destinationOffset + 1] /=\n metallicRoughnessFactors.roughness > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.roughness : 1;\n metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors.metallic > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.metallic : 1;\n const metallicRoughnessPixel = Color3.FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);\n if (!_GLTFMaterialExporter._FuzzyEquals(metallicRoughnessPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\n writeOutMetallicRoughnessTexture = true;\n }\n }\n }\n if (writeOutMetallicRoughnessTexture) {\n promises.push(this._getImageDataAsync(metallicRoughnessBuffer, width, height, mimeType).then((data) => {\n metallicRoughnessFactors.metallicRoughnessTextureData = data;\n }));\n }\n if (writeOutBaseColorTexture) {\n promises.push(this._getImageDataAsync(baseColorBuffer, width, height, mimeType).then((data) => {\n metallicRoughnessFactors.baseColorTextureData = data;\n }));\n }\n return Promise.all(promises).then(() => {\n return metallicRoughnessFactors;\n });\n }\n else {\n return Promise.reject(\"_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!\");\n }\n }\n /**\n * Converts specular glossiness material properties to metallic roughness\n * @param specularGlossiness interface with specular glossiness material properties\n * @returns interface with metallic roughness material properties\n */\n _convertSpecularGlossinessToMetallicRoughness(specularGlossiness) {\n const diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);\n const specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);\n const oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);\n const metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);\n const baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon));\n const baseColorFromSpecular = specularGlossiness.specularColor\n .subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic))\n .scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));\n let baseColor = Color3.Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);\n baseColor = baseColor.clampToRef(0, 1, baseColor);\n const metallicRoughness = {\n baseColor: baseColor,\n metallic: metallic,\n roughness: 1 - specularGlossiness.glossiness,\n };\n return metallicRoughness;\n }\n /**\n * Calculates the surface reflectance, independent of lighting conditions\n * @param color Color source to calculate brightness from\n * @returns number representing the perceived brightness, or zero if color is undefined\n */\n _getPerceivedBrightness(color) {\n if (color) {\n return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);\n }\n return 0;\n }\n /**\n * Returns the maximum color component value\n * @param color\n * @returns maximum color component value, or zero if color is null or undefined\n */\n _getMaxComponent(color) {\n if (color) {\n return Math.max(color.r, Math.max(color.g, color.b));\n }\n return 0;\n }\n /**\n * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\n * @param mimeType mime type to use for the textures\n * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\n * @returns glTF PBR Metallic Roughness factors\n */\n _convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {\n const promises = [];\n const baseColor = babylonPBRMaterial._albedoColor;\n const metallic = babylonPBRMaterial._metallic;\n const roughness = babylonPBRMaterial._roughness;\n const metallicRoughness = {\n baseColor: baseColor,\n metallic: metallic,\n roughness: roughness,\n };\n if (hasTextureCoords) {\n const albedoTexture = babylonPBRMaterial._albedoTexture;\n if (albedoTexture) {\n promises.push(this._exportTextureAsync(babylonPBRMaterial._albedoTexture, mimeType).then((glTFTexture) => {\n if (glTFTexture) {\n glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;\n }\n }));\n }\n const metallicTexture = babylonPBRMaterial._metallicTexture;\n if (metallicTexture) {\n promises.push(this._exportTextureAsync(metallicTexture, mimeType).then((glTFTexture) => {\n if (glTFTexture) {\n glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;\n }\n }));\n }\n }\n return Promise.all(promises).then(() => {\n return metallicRoughness;\n });\n }\n _getTextureSampler(texture) {\n const sampler = {};\n if (!texture || !(texture instanceof Texture)) {\n return sampler;\n }\n const wrapS = this._getGLTFTextureWrapMode(texture.wrapU);\n if (wrapS !== 10497 /* TextureWrapMode.REPEAT */) {\n sampler.wrapS = wrapS;\n }\n const wrapT = this._getGLTFTextureWrapMode(texture.wrapV);\n if (wrapT !== 10497 /* TextureWrapMode.REPEAT */) {\n sampler.wrapT = wrapT;\n }\n switch (texture.samplingMode) {\n case Texture.LINEAR_LINEAR: {\n sampler.magFilter = 9729 /* TextureMagFilter.LINEAR */;\n sampler.minFilter = 9729 /* TextureMinFilter.LINEAR */;\n break;\n }\n case Texture.LINEAR_NEAREST: {\n sampler.magFilter = 9729 /* TextureMagFilter.LINEAR */;\n sampler.minFilter = 9728 /* TextureMinFilter.NEAREST */;\n break;\n }\n case Texture.NEAREST_LINEAR: {\n sampler.magFilter = 9728 /* TextureMagFilter.NEAREST */;\n sampler.minFilter = 9729 /* TextureMinFilter.LINEAR */;\n break;\n }\n case Texture.NEAREST_LINEAR_MIPLINEAR: {\n sampler.magFilter = 9728 /* TextureMagFilter.NEAREST */;\n sampler.minFilter = 9987 /* TextureMinFilter.LINEAR_MIPMAP_LINEAR */;\n break;\n }\n case Texture.NEAREST_NEAREST: {\n sampler.magFilter = 9728 /* TextureMagFilter.NEAREST */;\n sampler.minFilter = 9728 /* TextureMinFilter.NEAREST */;\n break;\n }\n case Texture.NEAREST_LINEAR_MIPNEAREST: {\n sampler.magFilter = 9728 /* TextureMagFilter.NEAREST */;\n sampler.minFilter = 9985 /* TextureMinFilter.LINEAR_MIPMAP_NEAREST */;\n break;\n }\n case Texture.LINEAR_NEAREST_MIPNEAREST: {\n sampler.magFilter = 9729 /* TextureMagFilter.LINEAR */;\n sampler.minFilter = 9984 /* TextureMinFilter.NEAREST_MIPMAP_NEAREST */;\n break;\n }\n case Texture.LINEAR_NEAREST_MIPLINEAR: {\n sampler.magFilter = 9729 /* TextureMagFilter.LINEAR */;\n sampler.minFilter = 9986 /* TextureMinFilter.NEAREST_MIPMAP_LINEAR */;\n break;\n }\n case Texture.NEAREST_NEAREST_MIPLINEAR: {\n sampler.magFilter = 9728 /* TextureMagFilter.NEAREST */;\n sampler.minFilter = 9986 /* TextureMinFilter.NEAREST_MIPMAP_LINEAR */;\n break;\n }\n case Texture.LINEAR_LINEAR_MIPLINEAR: {\n sampler.magFilter = 9729 /* TextureMagFilter.LINEAR */;\n sampler.minFilter = 9987 /* TextureMinFilter.LINEAR_MIPMAP_LINEAR */;\n break;\n }\n case Texture.LINEAR_LINEAR_MIPNEAREST: {\n sampler.magFilter = 9729 /* TextureMagFilter.LINEAR */;\n sampler.minFilter = 9985 /* TextureMinFilter.LINEAR_MIPMAP_NEAREST */;\n break;\n }\n case Texture.NEAREST_NEAREST_MIPNEAREST: {\n sampler.magFilter = 9728 /* TextureMagFilter.NEAREST */;\n sampler.minFilter = 9984 /* TextureMinFilter.NEAREST_MIPMAP_NEAREST */;\n break;\n }\n }\n return sampler;\n }\n _getGLTFTextureWrapMode(wrapMode) {\n switch (wrapMode) {\n case Texture.WRAP_ADDRESSMODE: {\n return 10497 /* TextureWrapMode.REPEAT */;\n }\n case Texture.CLAMP_ADDRESSMODE: {\n return 33071 /* TextureWrapMode.CLAMP_TO_EDGE */;\n }\n case Texture.MIRROR_ADDRESSMODE: {\n return 33648 /* TextureWrapMode.MIRRORED_REPEAT */;\n }\n default: {\n Tools.Error(`Unsupported Texture Wrap Mode ${wrapMode}!`);\n return 10497 /* TextureWrapMode.REPEAT */;\n }\n }\n }\n /**\n * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\n * @param mimeType mime type to use for the textures\n * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\n * @returns glTF PBR Metallic Roughness factors\n */\n _convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, pbrMetallicRoughness, hasTextureCoords) {\n return Promise.resolve().then(() => {\n const specGloss = {\n diffuseColor: babylonPBRMaterial._albedoColor,\n specularColor: babylonPBRMaterial._reflectivityColor,\n glossiness: babylonPBRMaterial._microSurface,\n };\n const albedoTexture = babylonPBRMaterial._albedoTexture;\n const reflectivityTexture = babylonPBRMaterial._reflectivityTexture;\n const useMicrosurfaceFromReflectivityMapAlpha = babylonPBRMaterial._useMicroSurfaceFromReflectivityMapAlpha;\n if (reflectivityTexture && !useMicrosurfaceFromReflectivityMapAlpha) {\n return Promise.reject(\"_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported\");\n }\n if ((albedoTexture || reflectivityTexture) && hasTextureCoords) {\n const samplerIndex = this._exportTextureSampler(albedoTexture || reflectivityTexture);\n return this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(albedoTexture, reflectivityTexture, specGloss, mimeType).then((metallicRoughnessFactors) => {\n const textures = this._exporter._textures;\n if (metallicRoughnessFactors.baseColorTextureData) {\n const imageIndex = this._exportImage(`baseColor${textures.length}`, mimeType, metallicRoughnessFactors.baseColorTextureData);\n pbrMetallicRoughness.baseColorTexture = this._exportTextureInfo(imageIndex, samplerIndex, albedoTexture === null || albedoTexture === void 0 ? void 0 : albedoTexture.coordinatesIndex);\n }\n if (metallicRoughnessFactors.metallicRoughnessTextureData) {\n const imageIndex = this._exportImage(`metallicRoughness${textures.length}`, mimeType, metallicRoughnessFactors.metallicRoughnessTextureData);\n pbrMetallicRoughness.metallicRoughnessTexture = this._exportTextureInfo(imageIndex, samplerIndex, reflectivityTexture === null || reflectivityTexture === void 0 ? void 0 : reflectivityTexture.coordinatesIndex);\n }\n return metallicRoughnessFactors;\n });\n }\n else {\n return this._convertSpecularGlossinessToMetallicRoughness(specGloss);\n }\n });\n }\n /**\n * Converts a Babylon PBR Base Material to a glTF Material\n * @param babylonPBRMaterial BJS PBR Base Material\n * @param mimeType mime type to use for the textures\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\n */\n _convertPBRMaterialAsync(babylonPBRMaterial, mimeType, hasTextureCoords) {\n const glTFPbrMetallicRoughness = {};\n const glTFMaterial = {\n name: babylonPBRMaterial.name,\n };\n const useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();\n if (useMetallicRoughness) {\n const albedoColor = babylonPBRMaterial._albedoColor;\n const alpha = babylonPBRMaterial.alpha;\n if (albedoColor) {\n glTFPbrMetallicRoughness.baseColorFactor = [albedoColor.r, albedoColor.g, albedoColor.b, alpha];\n }\n return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\n });\n }\n else {\n return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\n });\n }\n }\n _setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords) {\n const materialMap = this._exporter._materialMap;\n const materials = this._exporter._materials;\n const promises = [];\n if (metallicRoughness) {\n _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial);\n if (!(_GLTFMaterialExporter._FuzzyEquals(metallicRoughness.baseColor, Color3.White(), _GLTFMaterialExporter._Epsilon) &&\n babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon)) {\n glTFPbrMetallicRoughness.baseColorFactor = [metallicRoughness.baseColor.r, metallicRoughness.baseColor.g, metallicRoughness.baseColor.b, babylonPBRMaterial.alpha];\n }\n if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {\n glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;\n }\n if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {\n glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;\n }\n if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {\n if (!babylonPBRMaterial._twoSidedLighting) {\n Tools.Warn(babylonPBRMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\n }\n glTFMaterial.doubleSided = true;\n }\n if (hasTextureCoords) {\n const bumpTexture = babylonPBRMaterial._bumpTexture;\n if (bumpTexture) {\n const promise = this._exportTextureAsync(bumpTexture, mimeType).then((glTFTexture) => {\n if (glTFTexture) {\n glTFMaterial.normalTexture = glTFTexture;\n if (bumpTexture.level !== 1) {\n glTFMaterial.normalTexture.scale = bumpTexture.level;\n }\n }\n });\n promises.push(promise);\n }\n const ambientTexture = babylonPBRMaterial._ambientTexture;\n if (ambientTexture) {\n const promise = this._exportTextureAsync(ambientTexture, mimeType).then((glTFTexture) => {\n if (glTFTexture) {\n const occlusionTexture = {\n index: glTFTexture.index,\n texCoord: glTFTexture.texCoord,\n extensions: glTFTexture.extensions,\n };\n glTFMaterial.occlusionTexture = occlusionTexture;\n const ambientTextureStrength = babylonPBRMaterial._ambientTextureStrength;\n if (ambientTextureStrength) {\n occlusionTexture.strength = ambientTextureStrength;\n }\n }\n });\n promises.push(promise);\n }\n const emissiveTexture = babylonPBRMaterial._emissiveTexture;\n if (emissiveTexture) {\n const promise = this._exportTextureAsync(emissiveTexture, mimeType).then((glTFTexture) => {\n if (glTFTexture) {\n glTFMaterial.emissiveTexture = glTFTexture;\n }\n });\n promises.push(promise);\n }\n }\n const emissiveColor = babylonPBRMaterial._emissiveColor;\n if (!_GLTFMaterialExporter._FuzzyEquals(emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\n glTFMaterial.emissiveFactor = emissiveColor.asArray();\n }\n glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;\n materials.push(glTFMaterial);\n materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;\n }\n return this._finishMaterial(promises, glTFMaterial, babylonPBRMaterial, mimeType);\n }\n _getPixelsFromTexture(babylonTexture) {\n const pixels = babylonTexture.textureType === Constants.TEXTURETYPE_UNSIGNED_INT\n ? babylonTexture.readPixels()\n : babylonTexture.readPixels();\n return pixels;\n }\n /**\n * Extracts a texture from a Babylon texture into file data and glTF data\n * @param babylonTexture Babylon texture to extract\n * @param mimeType Mime Type of the babylonTexture\n * @returns glTF texture info, or null if the texture format is not supported\n */\n _exportTextureAsync(babylonTexture, mimeType) {\n const extensionPromise = this._exporter._extensionsPreExportTextureAsync(\"exporter\", babylonTexture, mimeType);\n if (!extensionPromise) {\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\n }\n return extensionPromise.then((texture) => {\n if (!texture) {\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\n }\n return this._exportTextureInfoAsync(texture, mimeType);\n });\n }\n async _exportTextureInfoAsync(babylonTexture, mimeType) {\n const textureUid = babylonTexture.uid;\n if (!(textureUid in this._textureMap)) {\n const pixels = await this._getPixelsFromTexture(babylonTexture);\n if (!pixels) {\n return null;\n }\n const samplerIndex = this._exportTextureSampler(babylonTexture);\n // Preserve texture mime type if defined\n const textureMimeType = babylonTexture.mimeType;\n if (textureMimeType) {\n switch (textureMimeType) {\n case \"image/jpeg\":\n case \"image/png\":\n case \"image/webp\":\n mimeType = textureMimeType;\n break;\n default:\n Tools.Warn(`Unsupported media type: ${textureMimeType}`);\n break;\n }\n }\n const internalTextureToImage = this._internalTextureToImage;\n const internalTextureUniqueId = babylonTexture.getInternalTexture().uniqueId;\n internalTextureToImage[internalTextureUniqueId] || (internalTextureToImage[internalTextureUniqueId] = {});\n let imageIndexPromise = internalTextureToImage[internalTextureUniqueId][mimeType];\n if (imageIndexPromise === undefined) {\n const size = babylonTexture.getSize();\n imageIndexPromise = (async () => {\n const data = await this._getImageDataAsync(pixels, size.width, size.height, mimeType);\n return this._exportImage(babylonTexture.name, mimeType, data);\n })();\n internalTextureToImage[internalTextureUniqueId][mimeType] = imageIndexPromise;\n }\n const textureInfo = this._exportTextureInfo(await imageIndexPromise, samplerIndex, babylonTexture.coordinatesIndex);\n this._textureMap[textureUid] = textureInfo;\n this._exporter._extensionsPostExportTextures(\"exporter\", this._textureMap[textureUid], babylonTexture);\n }\n return this._textureMap[textureUid];\n }\n _exportImage(name, mimeType, data) {\n const imageData = this._exporter._imageData;\n const baseName = name.replace(/\\.\\/|\\/|\\.\\\\|\\\\/g, \"_\");\n const extension = getFileExtensionFromMimeType(mimeType);\n let fileName = baseName + extension;\n if (fileName in imageData) {\n fileName = `${baseName}_${Tools.RandomId()}${extension}`;\n }\n imageData[fileName] = {\n data: data,\n mimeType: mimeType,\n };\n const images = this._exporter._images;\n images.push({\n name: name,\n uri: fileName,\n });\n return images.length - 1;\n }\n _exportTextureInfo(imageIndex, samplerIndex, coordinatesIndex) {\n const textures = this._exporter._textures;\n let textureIndex = textures.findIndex((t) => t.sampler == samplerIndex && t.source === imageIndex);\n if (textureIndex === -1) {\n textureIndex = textures.length;\n textures.push({\n source: imageIndex,\n sampler: samplerIndex,\n });\n }\n const textureInfo = { index: textureIndex };\n if (coordinatesIndex) {\n textureInfo.texCoord = coordinatesIndex;\n }\n return textureInfo;\n }\n _exportTextureSampler(texture) {\n const sampler = this._getTextureSampler(texture);\n // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler\n const samplers = this._exporter._samplers;\n const samplerIndex = samplers.findIndex((s) => s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter && s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT);\n if (samplerIndex !== -1) {\n return samplerIndex;\n }\n samplers.push(sampler);\n return samplers.length - 1;\n }\n }\n /**\n * Represents the dielectric specular values for R, G and B\n */\n _GLTFMaterialExporter._DielectricSpecular = new Color3(0.04, 0.04, 0.04);\n /**\n * Allows the maximum specular power to be defined for material calculations\n */\n _GLTFMaterialExporter._MaxSpecularPower = 1024;\n /**\n * Numeric tolerance value\n */\n _GLTFMaterialExporter._Epsilon = 1e-6;\n\n // Matrix that converts handedness on the X-axis.\n const convertHandednessMatrix = Matrix.Compose(new Vector3(-1, 1, 1), Quaternion.Identity(), Vector3.Zero());\n function isNoopNode(node, useRightHandedSystem) {\n if (!(node instanceof TransformNode)) {\n return false;\n }\n // Transform\n if (useRightHandedSystem) {\n const matrix = node.getWorldMatrix();\n if (!matrix.isIdentity()) {\n return false;\n }\n }\n else {\n const matrix = node.getWorldMatrix().multiplyToRef(convertHandednessMatrix, TmpVectors.Matrix[0]);\n if (!matrix.isIdentity()) {\n return false;\n }\n }\n // Geometry\n if ((node instanceof Mesh && node.geometry) || (node instanceof InstancedMesh && node.sourceMesh.geometry)) {\n return false;\n }\n return true;\n }\n function convertNodeHandedness(node) {\n const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);\n const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);\n const scale = Vector3.FromArrayToRef(node.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);\n const matrix = Matrix.ComposeToRef(scale, rotation, translation, TmpVectors.Matrix[0]).multiplyToRef(convertHandednessMatrix, TmpVectors.Matrix[0]);\n matrix.decompose(scale, rotation, translation);\n if (translation.equalsToFloats(0, 0, 0)) {\n delete node.translation;\n }\n else {\n node.translation = translation.asArray();\n }\n if (Quaternion.IsIdentity(rotation)) {\n delete node.rotation;\n }\n else {\n node.rotation = rotation.asArray();\n }\n if (scale.equalsToFloats(1, 1, 1)) {\n delete node.scale;\n }\n else {\n node.scale = scale.asArray();\n }\n }\n /**\n * Converts Babylon Scene into glTF 2.0.\n * @internal\n */\n class _Exporter {\n _applyExtension(node, extensions, index, actionAsync) {\n if (index >= extensions.length) {\n return Promise.resolve(node);\n }\n const currentPromise = actionAsync(extensions[index], node);\n if (!currentPromise) {\n return this._applyExtension(node, extensions, index + 1, actionAsync);\n }\n return currentPromise.then((newNode) => this._applyExtension(newNode, extensions, index + 1, actionAsync));\n }\n _applyExtensions(node, actionAsync) {\n const extensions = [];\n for (const name of _Exporter._ExtensionNames) {\n extensions.push(this._extensions[name]);\n }\n return this._applyExtension(node, extensions, 0, actionAsync);\n }\n _extensionsPreExportTextureAsync(context, babylonTexture, mimeType) {\n return this._applyExtensions(babylonTexture, (extension, node) => extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType));\n }\n _extensionsPostExportMeshPrimitiveAsync(context, meshPrimitive, babylonSubMesh, binaryWriter) {\n return this._applyExtensions(meshPrimitive, (extension, node) => extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter));\n }\n _extensionsPostExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter) {\n return this._applyExtensions(node, (extension, node) => extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter));\n }\n _extensionsPostExportMaterialAsync(context, material, babylonMaterial) {\n return this._applyExtensions(material, (extension, node) => extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial));\n }\n _extensionsPostExportMaterialAdditionalTextures(context, material, babylonMaterial) {\n const output = [];\n for (const name of _Exporter._ExtensionNames) {\n const extension = this._extensions[name];\n if (extension.postExportMaterialAdditionalTextures) {\n output.push(...extension.postExportMaterialAdditionalTextures(context, material, babylonMaterial));\n }\n }\n return output;\n }\n _extensionsPostExportTextures(context, textureInfo, babylonTexture) {\n for (const name of _Exporter._ExtensionNames) {\n const extension = this._extensions[name];\n if (extension.postExportTexture) {\n extension.postExportTexture(context, textureInfo, babylonTexture);\n }\n }\n }\n _forEachExtensions(action) {\n for (const name of _Exporter._ExtensionNames) {\n const extension = this._extensions[name];\n if (extension.enabled) {\n action(extension);\n }\n }\n }\n _extensionsOnExporting() {\n this._forEachExtensions((extension) => {\n if (extension.wasUsed) {\n if (this._glTF.extensionsUsed == null) {\n this._glTF.extensionsUsed = [];\n }\n if (this._glTF.extensionsUsed.indexOf(extension.name) === -1) {\n this._glTF.extensionsUsed.push(extension.name);\n }\n if (extension.required) {\n if (this._glTF.extensionsRequired == null) {\n this._glTF.extensionsRequired = [];\n }\n if (this._glTF.extensionsRequired.indexOf(extension.name) === -1) {\n this._glTF.extensionsRequired.push(extension.name);\n }\n }\n if (this._glTF.extensions == null) {\n this._glTF.extensions = {};\n }\n if (extension.onExporting) {\n extension.onExporting();\n }\n }\n });\n }\n /**\n * Load glTF serializer extensions\n */\n _loadExtensions() {\n for (const name of _Exporter._ExtensionNames) {\n const extension = _Exporter._ExtensionFactories[name](this);\n this._extensions[name] = extension;\n }\n }\n /**\n * Creates a glTF Exporter instance, which can accept optional exporter options\n * @param babylonScene Babylon scene object\n * @param options Options to modify the behavior of the exporter\n */\n constructor(babylonScene, options) {\n this._extensions = {};\n this._glTF = {\n asset: { generator: `Babylon.js v${Engine.Version}`, version: \"2.0\" },\n };\n babylonScene = babylonScene || EngineStore.LastCreatedScene;\n if (!babylonScene) {\n return;\n }\n this._babylonScene = babylonScene;\n this._bufferViews = [];\n this._accessors = [];\n this._meshes = [];\n this._scenes = [];\n this._cameras = [];\n this._nodes = [];\n this._images = [];\n this._materials = [];\n this._materialMap = [];\n this._textures = [];\n this._samplers = [];\n this._skins = [];\n this._animations = [];\n this._imageData = {};\n this._orderedImageData = [];\n this._options = options || {};\n this._animationSampleRate = this._options.animationSampleRate || 1 / 60;\n this._glTFMaterialExporter = new _GLTFMaterialExporter(this);\n this._loadExtensions();\n }\n dispose() {\n for (const extensionKey in this._extensions) {\n const extension = this._extensions[extensionKey];\n extension.dispose();\n }\n }\n get options() {\n return this._options;\n }\n /**\n * Registers a glTF exporter extension\n * @param name Name of the extension to export\n * @param factory The factory function that creates the exporter extension\n */\n static RegisterExtension(name, factory) {\n if (_Exporter.UnregisterExtension(name)) {\n Tools.Warn(`Extension with the name ${name} already exists`);\n }\n _Exporter._ExtensionFactories[name] = factory;\n _Exporter._ExtensionNames.push(name);\n }\n /**\n * Un-registers an exporter extension\n * @param name The name fo the exporter extension\n * @returns A boolean indicating whether the extension has been un-registered\n */\n static UnregisterExtension(name) {\n if (!_Exporter._ExtensionFactories[name]) {\n return false;\n }\n delete _Exporter._ExtensionFactories[name];\n const index = _Exporter._ExtensionNames.indexOf(name);\n if (index !== -1) {\n _Exporter._ExtensionNames.splice(index, 1);\n }\n return true;\n }\n _reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter) {\n switch (primitiveMode) {\n case Material.TriangleFillMode: {\n if (!byteOffset) {\n byteOffset = 0;\n }\n for (let i = submesh.indexStart, length = submesh.indexStart + submesh.indexCount; i < length; i = i + 3) {\n const index = byteOffset + i * 4;\n // swap the second and third indices\n const secondIndex = binaryWriter.getUInt32(index + 4);\n const thirdIndex = binaryWriter.getUInt32(index + 8);\n binaryWriter.setUInt32(thirdIndex, index + 4);\n binaryWriter.setUInt32(secondIndex, index + 8);\n }\n break;\n }\n case Material.TriangleFanDrawMode: {\n for (let i = submesh.indexStart + submesh.indexCount - 1, start = submesh.indexStart; i >= start; --i) {\n binaryWriter.setUInt32(babylonIndices[i], byteOffset);\n byteOffset += 4;\n }\n break;\n }\n case Material.TriangleStripDrawMode: {\n if (submesh.indexCount >= 3) {\n binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 2], byteOffset + 4);\n binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 1], byteOffset + 8);\n }\n break;\n }\n }\n }\n /**\n * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is\n * clock-wise during export to glTF\n * @param submesh BabylonJS submesh\n * @param primitiveMode Primitive mode of the mesh\n * @param vertexBufferKind The type of vertex attribute\n * @param meshAttributeArray The vertex attribute data\n * @param byteOffset The offset to the binary data\n * @param binaryWriter The binary data for the glTF file\n */\n _reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {\n switch (primitiveMode) {\n case Material.TriangleFillMode: {\n this._reorderTriangleFillMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);\n break;\n }\n case Material.TriangleStripDrawMode: {\n this._reorderTriangleStripDrawMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);\n break;\n }\n case Material.TriangleFanDrawMode: {\n this._reorderTriangleFanMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);\n break;\n }\n }\n }\n /**\n * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is\n * clock-wise during export to glTF\n * @param submesh BabylonJS submesh\n * @param vertexBufferKind The type of vertex attribute\n * @param meshAttributeArray The vertex attribute data\n * @param byteOffset The offset to the binary data\n * @param binaryWriter The binary data for the glTF file\n */\n _reorderTriangleFillMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {\n const vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());\n if (vertexBuffer) {\n const stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);\n if (submesh.verticesCount % 3 !== 0) {\n Tools.Error(\"The submesh vertices for the triangle fill mode is not divisible by 3!\");\n }\n else {\n const vertexData = [];\n let index = 0;\n switch (vertexBufferKind) {\n case VertexBuffer.PositionKind:\n case VertexBuffer.NormalKind: {\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {\n index = x * stride;\n vertexData.push(Vector3.FromArray(meshAttributeArray, index));\n vertexData.push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));\n vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));\n }\n break;\n }\n case VertexBuffer.TangentKind: {\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {\n index = x * stride;\n vertexData.push(Vector4.FromArray(meshAttributeArray, index));\n vertexData.push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));\n vertexData.push(Vector4.FromArray(meshAttributeArray, index + stride));\n }\n break;\n }\n case VertexBuffer.ColorKind: {\n const size = vertexBuffer.getSize();\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {\n index = x * stride;\n if (size === 4) {\n vertexData.push(Vector4.FromArray(meshAttributeArray, index));\n vertexData.push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));\n vertexData.push(Vector4.FromArray(meshAttributeArray, index + stride));\n }\n else {\n vertexData.push(Vector3.FromArray(meshAttributeArray, index));\n vertexData.push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));\n vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));\n }\n }\n break;\n }\n case VertexBuffer.UVKind:\n case VertexBuffer.UV2Kind: {\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {\n index = x * stride;\n vertexData.push(Vector2.FromArray(meshAttributeArray, index));\n vertexData.push(Vector2.FromArray(meshAttributeArray, index + 2 * stride));\n vertexData.push(Vector2.FromArray(meshAttributeArray, index + stride));\n }\n break;\n }\n default: {\n Tools.Error(`Unsupported Vertex Buffer type: ${vertexBufferKind}`);\n }\n }\n this._writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, binaryWriter);\n }\n }\n else {\n Tools.Warn(`reorderTriangleFillMode: Vertex Buffer Kind ${vertexBufferKind} not present!`);\n }\n }\n /**\n * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is\n * clock-wise during export to glTF\n * @param submesh BabylonJS submesh\n * @param vertexBufferKind The type of vertex attribute\n * @param meshAttributeArray The vertex attribute data\n * @param byteOffset The offset to the binary data\n * @param binaryWriter The binary data for the glTF file\n */\n _reorderTriangleStripDrawMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {\n const vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());\n if (vertexBuffer) {\n const stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);\n const vertexData = [];\n let index = 0;\n switch (vertexBufferKind) {\n case VertexBuffer.PositionKind:\n case VertexBuffer.NormalKind: {\n index = submesh.verticesStart;\n vertexData.push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));\n vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));\n break;\n }\n case VertexBuffer.TangentKind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexData.push(Vector4.FromArray(meshAttributeArray, index));\n }\n break;\n }\n case VertexBuffer.ColorKind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexBuffer.getSize() === 4\n ? vertexData.push(Vector4.FromArray(meshAttributeArray, index))\n : vertexData.push(Vector3.FromArray(meshAttributeArray, index));\n }\n break;\n }\n case VertexBuffer.UVKind:\n case VertexBuffer.UV2Kind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexData.push(Vector2.FromArray(meshAttributeArray, index));\n }\n break;\n }\n default: {\n Tools.Error(`Unsupported Vertex Buffer type: ${vertexBufferKind}`);\n }\n }\n this._writeVertexAttributeData(vertexData, byteOffset + 12, vertexBufferKind, binaryWriter);\n }\n else {\n Tools.Warn(`reorderTriangleStripDrawMode: Vertex buffer kind ${vertexBufferKind} not present!`);\n }\n }\n /**\n * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is\n * clock-wise during export to glTF\n * @param submesh BabylonJS submesh\n * @param vertexBufferKind The type of vertex attribute\n * @param meshAttributeArray The vertex attribute data\n * @param byteOffset The offset to the binary data\n * @param binaryWriter The binary data for the glTF file\n */\n _reorderTriangleFanMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {\n const vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());\n if (vertexBuffer) {\n const stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);\n const vertexData = [];\n let index = 0;\n switch (vertexBufferKind) {\n case VertexBuffer.PositionKind:\n case VertexBuffer.NormalKind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexData.push(Vector3.FromArray(meshAttributeArray, index));\n }\n break;\n }\n case VertexBuffer.TangentKind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexData.push(Vector4.FromArray(meshAttributeArray, index));\n }\n break;\n }\n case VertexBuffer.ColorKind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexData.push(Vector4.FromArray(meshAttributeArray, index));\n vertexBuffer.getSize() === 4\n ? vertexData.push(Vector4.FromArray(meshAttributeArray, index))\n : vertexData.push(Vector3.FromArray(meshAttributeArray, index));\n }\n break;\n }\n case VertexBuffer.UVKind:\n case VertexBuffer.UV2Kind: {\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\n index = x * stride;\n vertexData.push(Vector2.FromArray(meshAttributeArray, index));\n }\n break;\n }\n default: {\n Tools.Error(`Unsupported Vertex Buffer type: ${vertexBufferKind}`);\n }\n }\n this._writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, binaryWriter);\n }\n else {\n Tools.Warn(`reorderTriangleFanMode: Vertex buffer kind ${vertexBufferKind} not present!`);\n }\n }\n /**\n * Writes the vertex attribute data to binary\n * @param vertices The vertices to write to the binary writer\n * @param byteOffset The offset into the binary writer to overwrite binary data\n * @param vertexAttributeKind The vertex attribute type\n * @param binaryWriter The writer containing the binary data\n */\n _writeVertexAttributeData(vertices, byteOffset, vertexAttributeKind, binaryWriter) {\n for (const vertex of vertices) {\n if (vertexAttributeKind === VertexBuffer.NormalKind) {\n vertex.normalize();\n }\n else if (vertexAttributeKind === VertexBuffer.TangentKind && vertex instanceof Vector4) {\n _GLTFUtilities._NormalizeTangentFromRef(vertex);\n }\n for (const component of vertex.asArray()) {\n binaryWriter.setFloat32(component, byteOffset);\n byteOffset += 4;\n }\n }\n }\n /**\n * Writes mesh attribute data to a data buffer\n * Returns the bytelength of the data\n * @param vertexBufferKind Indicates what kind of vertex data is being passed in\n * @param attributeComponentKind\n * @param meshAttributeArray Array containing the attribute data\n * @param stride Specifies the space between data\n * @param binaryWriter The buffer to write the binary data to\n * @param babylonTransformNode\n */\n _writeAttributeData(vertexBufferKind, attributeComponentKind, meshAttributeArray, stride, binaryWriter, babylonTransformNode) {\n let vertexAttributes = [];\n let index;\n switch (vertexBufferKind) {\n case VertexBuffer.PositionKind: {\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n const vertexData = Vector3.FromArray(meshAttributeArray, index);\n vertexAttributes.push(vertexData.asArray());\n }\n break;\n }\n case VertexBuffer.NormalKind: {\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n const vertexData = Vector3.FromArray(meshAttributeArray, index);\n vertexAttributes.push(vertexData.normalize().asArray());\n }\n break;\n }\n case VertexBuffer.TangentKind: {\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\n _GLTFUtilities._NormalizeTangentFromRef(vertexData);\n vertexAttributes.push(vertexData.asArray());\n }\n break;\n }\n case VertexBuffer.ColorKind: {\n const meshMaterial = babylonTransformNode.material;\n const convertToLinear = meshMaterial ? meshMaterial.getClassName() === \"StandardMaterial\" : true;\n const vertexData = stride === 3 ? new Color3() : new Color4();\n const useExactSrgbConversions = this._babylonScene.getEngine().useExactSrgbConversions;\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n if (stride === 3) {\n Color3.FromArrayToRef(meshAttributeArray, index, vertexData);\n if (convertToLinear) {\n vertexData.toLinearSpaceToRef(vertexData, useExactSrgbConversions);\n }\n }\n else {\n Color4.FromArrayToRef(meshAttributeArray, index, vertexData);\n if (convertToLinear) {\n vertexData.toLinearSpaceToRef(vertexData, useExactSrgbConversions);\n }\n }\n vertexAttributes.push(vertexData.asArray());\n }\n break;\n }\n case VertexBuffer.UVKind:\n case VertexBuffer.UV2Kind: {\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n const vertexData = Vector2.FromArray(meshAttributeArray, index);\n vertexAttributes.push(vertexData.asArray());\n }\n break;\n }\n case VertexBuffer.MatricesIndicesKind:\n case VertexBuffer.MatricesIndicesExtraKind: {\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\n vertexAttributes.push(vertexData.asArray());\n }\n break;\n }\n case VertexBuffer.MatricesWeightsKind:\n case VertexBuffer.MatricesWeightsExtraKind: {\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\n index = k * stride;\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\n vertexAttributes.push(vertexData.asArray());\n }\n break;\n }\n default: {\n Tools.Warn(\"Unsupported Vertex Buffer Type: \" + vertexBufferKind);\n vertexAttributes = [];\n }\n }\n let writeBinaryFunc;\n switch (attributeComponentKind) {\n case 5121 /* AccessorComponentType.UNSIGNED_BYTE */: {\n writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);\n break;\n }\n case 5123 /* AccessorComponentType.UNSIGNED_SHORT */: {\n writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);\n break;\n }\n case 5125 /* AccessorComponentType.UNSIGNED_INT */: {\n writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);\n break;\n }\n case 5126 /* AccessorComponentType.FLOAT */: {\n writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);\n break;\n }\n default: {\n Tools.Warn(\"Unsupported Attribute Component kind: \" + attributeComponentKind);\n return;\n }\n }\n for (const vertexAttribute of vertexAttributes) {\n for (const component of vertexAttribute) {\n writeBinaryFunc(component);\n }\n }\n }\n /**\n * Writes mesh attribute data to a data buffer\n * Returns the bytelength of the data\n * @param vertexBufferKind Indicates what kind of vertex data is being passed in\n * @param attributeComponentKind\n * @param meshPrimitive\n * @param morphTarget\n * @param meshAttributeArray Array containing the attribute data\n * @param morphTargetAttributeArray\n * @param stride Specifies the space between data\n * @param binaryWriter The buffer to write the binary data to\n * @param minMax\n */\n writeMorphTargetAttributeData(vertexBufferKind, attributeComponentKind, meshPrimitive, meshAttributeArray, morphTargetAttributeArray, stride, binaryWriter, minMax) {\n let vertexAttributes = [];\n let index;\n let difference = new Vector3();\n let difference4 = new Vector4(0, 0, 0, 0);\n switch (vertexBufferKind) {\n case VertexBuffer.PositionKind: {\n for (let k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {\n index = meshPrimitive.indexStart + k * stride;\n const vertexData = Vector3.FromArray(meshAttributeArray, index);\n const morphData = Vector3.FromArray(morphTargetAttributeArray, index);\n difference = morphData.subtractToRef(vertexData, difference);\n if (minMax) {\n minMax.min.copyFromFloats(Math.min(difference.x, minMax.min.x), Math.min(difference.y, minMax.min.y), Math.min(difference.z, minMax.min.z));\n minMax.max.copyFromFloats(Math.max(difference.x, minMax.max.x), Math.max(difference.y, minMax.max.y), Math.max(difference.z, minMax.max.z));\n }\n vertexAttributes.push(difference.asArray());\n }\n break;\n }\n case VertexBuffer.NormalKind: {\n for (let k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {\n index = meshPrimitive.indexStart + k * stride;\n const vertexData = Vector3.FromArray(meshAttributeArray, index).normalize();\n const morphData = Vector3.FromArray(morphTargetAttributeArray, index).normalize();\n difference = morphData.subtractToRef(vertexData, difference);\n vertexAttributes.push(difference.asArray());\n }\n break;\n }\n case VertexBuffer.TangentKind: {\n for (let k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {\n index = meshPrimitive.indexStart + k * (stride + 1);\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\n _GLTFUtilities._NormalizeTangentFromRef(vertexData);\n const morphData = Vector4.FromArray(morphTargetAttributeArray, index);\n _GLTFUtilities._NormalizeTangentFromRef(morphData);\n difference4 = morphData.subtractToRef(vertexData, difference4);\n vertexAttributes.push([difference4.x, difference4.y, difference4.z]);\n }\n break;\n }\n default: {\n Tools.Warn(\"Unsupported Vertex Buffer Type: \" + vertexBufferKind);\n vertexAttributes = [];\n }\n }\n let writeBinaryFunc;\n switch (attributeComponentKind) {\n case 5121 /* AccessorComponentType.UNSIGNED_BYTE */: {\n writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);\n break;\n }\n case 5123 /* AccessorComponentType.UNSIGNED_SHORT */: {\n writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);\n break;\n }\n case 5125 /* AccessorComponentType.UNSIGNED_INT */: {\n writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);\n break;\n }\n case 5126 /* AccessorComponentType.FLOAT */: {\n writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);\n break;\n }\n default: {\n Tools.Warn(\"Unsupported Attribute Component kind: \" + attributeComponentKind);\n return;\n }\n }\n for (const vertexAttribute of vertexAttributes) {\n for (const component of vertexAttribute) {\n writeBinaryFunc(component);\n }\n }\n }\n /**\n * Generates glTF json data\n * @param shouldUseGlb Indicates whether the json should be written for a glb file\n * @param glTFPrefix Text to use when prefixing a glTF file\n * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)\n * @returns json data as string\n */\n _generateJSON(shouldUseGlb, glTFPrefix, prettyPrint) {\n const buffer = { byteLength: this._totalByteLength };\n let imageName;\n let imageData;\n let bufferView;\n let byteOffset = this._totalByteLength;\n if (buffer.byteLength) {\n this._glTF.buffers = [buffer];\n }\n if (this._nodes && this._nodes.length) {\n this._glTF.nodes = this._nodes;\n }\n if (this._meshes && this._meshes.length) {\n this._glTF.meshes = this._meshes;\n }\n if (this._scenes && this._scenes.length) {\n this._glTF.scenes = this._scenes;\n this._glTF.scene = 0;\n }\n if (this._cameras && this._cameras.length) {\n this._glTF.cameras = this._cameras;\n }\n if (this._bufferViews && this._bufferViews.length) {\n this._glTF.bufferViews = this._bufferViews;\n }\n if (this._accessors && this._accessors.length) {\n this._glTF.accessors = this._accessors;\n }\n if (this._animations && this._animations.length) {\n this._glTF.animations = this._animations;\n }\n if (this._materials && this._materials.length) {\n this._glTF.materials = this._materials;\n }\n if (this._textures && this._textures.length) {\n this._glTF.textures = this._textures;\n }\n if (this._samplers && this._samplers.length) {\n this._glTF.samplers = this._samplers;\n }\n if (this._skins && this._skins.length) {\n this._glTF.skins = this._skins;\n }\n if (this._images && this._images.length) {\n if (!shouldUseGlb) {\n this._glTF.images = this._images;\n }\n else {\n this._glTF.images = [];\n this._images.forEach((image) => {\n if (image.uri) {\n imageData = this._imageData[image.uri];\n this._orderedImageData.push(imageData);\n imageName = image.uri.split(\".\")[0] + \" image\";\n bufferView = _GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.byteLength, undefined, imageName);\n byteOffset += imageData.data.byteLength;\n this._bufferViews.push(bufferView);\n image.bufferView = this._bufferViews.length - 1;\n image.name = imageName;\n image.mimeType = imageData.mimeType;\n image.uri = undefined;\n if (!this._glTF.images) {\n this._glTF.images = [];\n }\n this._glTF.images.push(image);\n }\n });\n // Replace uri with bufferview and mime type for glb\n buffer.byteLength = byteOffset;\n }\n }\n if (!shouldUseGlb) {\n buffer.uri = glTFPrefix + \".bin\";\n }\n const jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);\n return jsonText;\n }\n /**\n * Generates data for .gltf and .bin files based on the glTF prefix string\n * @param glTFPrefix Text to use when prefixing a glTF file\n * @param dispose Dispose the exporter\n * @returns GLTFData with glTF file data\n */\n _generateGLTFAsync(glTFPrefix, dispose = true) {\n return this._generateBinaryAsync().then((binaryBuffer) => {\n this._extensionsOnExporting();\n const jsonText = this._generateJSON(false, glTFPrefix, true);\n const bin = new Blob([binaryBuffer], { type: \"application/octet-stream\" });\n const glTFFileName = glTFPrefix + \".gltf\";\n const glTFBinFile = glTFPrefix + \".bin\";\n const container = new GLTFData();\n container.glTFFiles[glTFFileName] = jsonText;\n container.glTFFiles[glTFBinFile] = bin;\n if (this._imageData) {\n for (const image in this._imageData) {\n container.glTFFiles[image] = new Blob([this._imageData[image].data], { type: this._imageData[image].mimeType });\n }\n }\n if (dispose) {\n this.dispose();\n }\n return container;\n });\n }\n /**\n * Creates a binary buffer for glTF\n * @returns array buffer for binary data\n */\n _generateBinaryAsync() {\n const binaryWriter = new _BinaryWriter(4);\n return this._createSceneAsync(binaryWriter).then(() => {\n if (this._localEngine) {\n this._localEngine.dispose();\n }\n return binaryWriter.getArrayBuffer();\n });\n }\n /**\n * Pads the number to a multiple of 4\n * @param num number to pad\n * @returns padded number\n */\n _getPadding(num) {\n const remainder = num % 4;\n const padding = remainder === 0 ? remainder : 4 - remainder;\n return padding;\n }\n /**\n * @internal\n */\n _generateGLBAsync(glTFPrefix, dispose = true) {\n return this._generateBinaryAsync().then((binaryBuffer) => {\n this._extensionsOnExporting();\n const jsonText = this._generateJSON(true);\n const glbFileName = glTFPrefix + \".glb\";\n const headerLength = 12;\n const chunkLengthPrefix = 8;\n let jsonLength = jsonText.length;\n let encodedJsonText;\n let imageByteLength = 0;\n // make use of TextEncoder when available\n if (typeof TextEncoder !== \"undefined\") {\n const encoder = new TextEncoder();\n encodedJsonText = encoder.encode(jsonText);\n jsonLength = encodedJsonText.length;\n }\n for (let i = 0; i < this._orderedImageData.length; ++i) {\n imageByteLength += this._orderedImageData[i].data.byteLength;\n }\n const jsonPadding = this._getPadding(jsonLength);\n const binPadding = this._getPadding(binaryBuffer.byteLength);\n const imagePadding = this._getPadding(imageByteLength);\n const byteLength = headerLength + 2 * chunkLengthPrefix + jsonLength + jsonPadding + binaryBuffer.byteLength + binPadding + imageByteLength + imagePadding;\n //header\n const headerBuffer = new ArrayBuffer(headerLength);\n const headerBufferView = new DataView(headerBuffer);\n headerBufferView.setUint32(0, 0x46546c67, true); //glTF\n headerBufferView.setUint32(4, 2, true); // version\n headerBufferView.setUint32(8, byteLength, true); // total bytes in file\n //json chunk\n const jsonChunkBuffer = new ArrayBuffer(chunkLengthPrefix + jsonLength + jsonPadding);\n const jsonChunkBufferView = new DataView(jsonChunkBuffer);\n jsonChunkBufferView.setUint32(0, jsonLength + jsonPadding, true);\n jsonChunkBufferView.setUint32(4, 0x4e4f534a, true);\n //json chunk bytes\n const jsonData = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix);\n // if TextEncoder was available, we can simply copy the encoded array\n if (encodedJsonText) {\n jsonData.set(encodedJsonText);\n }\n else {\n const blankCharCode = \"_\".charCodeAt(0);\n for (let i = 0; i < jsonLength; ++i) {\n const charCode = jsonText.charCodeAt(i);\n // if the character doesn't fit into a single UTF-16 code unit, just put a blank character\n if (charCode != jsonText.codePointAt(i)) {\n jsonData[i] = blankCharCode;\n }\n else {\n jsonData[i] = charCode;\n }\n }\n }\n //json padding\n const jsonPaddingView = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix + jsonLength);\n for (let i = 0; i < jsonPadding; ++i) {\n jsonPaddingView[i] = 0x20;\n }\n //binary chunk\n const binaryChunkBuffer = new ArrayBuffer(chunkLengthPrefix);\n const binaryChunkBufferView = new DataView(binaryChunkBuffer);\n binaryChunkBufferView.setUint32(0, binaryBuffer.byteLength + imageByteLength + imagePadding, true);\n binaryChunkBufferView.setUint32(4, 0x004e4942, true);\n // binary padding\n const binPaddingBuffer = new ArrayBuffer(binPadding);\n const binPaddingView = new Uint8Array(binPaddingBuffer);\n for (let i = 0; i < binPadding; ++i) {\n binPaddingView[i] = 0;\n }\n const imagePaddingBuffer = new ArrayBuffer(imagePadding);\n const imagePaddingView = new Uint8Array(imagePaddingBuffer);\n for (let i = 0; i < imagePadding; ++i) {\n imagePaddingView[i] = 0;\n }\n const glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];\n // binary data\n for (let i = 0; i < this._orderedImageData.length; ++i) {\n glbData.push(this._orderedImageData[i].data);\n }\n glbData.push(binPaddingBuffer);\n glbData.push(imagePaddingBuffer);\n const glbFile = new Blob(glbData, { type: \"application/octet-stream\" });\n const container = new GLTFData();\n container.glTFFiles[glbFileName] = glbFile;\n if (this._localEngine != null) {\n this._localEngine.dispose();\n }\n if (dispose) {\n this.dispose();\n }\n return container;\n });\n }\n /**\n * Sets the TRS for each node\n * @param node glTF Node for storing the transformation data\n * @param babylonTransformNode Babylon mesh used as the source for the transformation data\n */\n _setNodeTransformation(node, babylonTransformNode) {\n if (!babylonTransformNode.getPivotPoint().equalsToFloats(0, 0, 0)) {\n Tools.Warn(\"Pivot points are not supported in the glTF serializer\");\n }\n if (!babylonTransformNode.position.equalsToFloats(0, 0, 0)) {\n node.translation = babylonTransformNode.position.asArray();\n }\n if (!babylonTransformNode.scaling.equalsToFloats(1, 1, 1)) {\n node.scale = babylonTransformNode.scaling.asArray();\n }\n const rotationQuaternion = Quaternion.RotationYawPitchRoll(babylonTransformNode.rotation.y, babylonTransformNode.rotation.x, babylonTransformNode.rotation.z);\n if (babylonTransformNode.rotationQuaternion) {\n rotationQuaternion.multiplyInPlace(babylonTransformNode.rotationQuaternion);\n }\n if (!Quaternion.IsIdentity(rotationQuaternion)) {\n node.rotation = rotationQuaternion.normalize().asArray();\n }\n }\n _setCameraTransformation(node, babylonCamera) {\n if (!babylonCamera.position.equalsToFloats(0, 0, 0)) {\n node.translation = babylonCamera.position.asArray();\n }\n const rotationQuaternion = babylonCamera.rotationQuaternion; // we target the local transformation if one.\n if (rotationQuaternion && !Quaternion.IsIdentity(rotationQuaternion)) {\n node.rotation = rotationQuaternion.normalize().asArray();\n }\n }\n _getVertexBufferFromMesh(attributeKind, bufferMesh) {\n if (bufferMesh.isVerticesDataPresent(attributeKind, true)) {\n const vertexBuffer = bufferMesh.getVertexBuffer(attributeKind, true);\n if (vertexBuffer) {\n return vertexBuffer;\n }\n }\n return null;\n }\n /**\n * Creates a bufferview based on the vertices type for the Babylon mesh\n * @param kind Indicates the type of vertices data\n * @param attributeComponentKind Indicates the numerical type used to store the data\n * @param babylonTransformNode The Babylon mesh to get the vertices data from\n * @param binaryWriter The buffer to write the bufferview data to\n * @param byteStride\n */\n _createBufferViewKind(kind, attributeComponentKind, babylonTransformNode, binaryWriter, byteStride) {\n const bufferMesh = babylonTransformNode instanceof Mesh\n ? babylonTransformNode\n : babylonTransformNode instanceof InstancedMesh\n ? babylonTransformNode.sourceMesh\n : null;\n if (bufferMesh) {\n const vertexBuffer = bufferMesh.getVertexBuffer(kind, true);\n const vertexData = bufferMesh.getVerticesData(kind, undefined, undefined, true);\n if (vertexBuffer && vertexData) {\n const typeByteLength = VertexBuffer.GetTypeByteLength(attributeComponentKind);\n const byteLength = vertexData.length * typeByteLength;\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, kind + \" - \" + bufferMesh.name);\n this._bufferViews.push(bufferView);\n this._writeAttributeData(kind, attributeComponentKind, vertexData, byteStride / typeByteLength, binaryWriter, babylonTransformNode);\n }\n }\n }\n /**\n * Creates a bufferview based on the vertices type for the Babylon mesh\n * @param babylonSubMesh The Babylon submesh that the morph target is applied to\n * @param meshPrimitive\n * @param babylonMorphTarget the morph target to be exported\n * @param binaryWriter The buffer to write the bufferview data to\n */\n _setMorphTargetAttributes(babylonSubMesh, meshPrimitive, babylonMorphTarget, binaryWriter) {\n if (babylonMorphTarget) {\n if (!meshPrimitive.targets) {\n meshPrimitive.targets = [];\n }\n const target = {};\n const mesh = babylonSubMesh.getMesh();\n if (babylonMorphTarget.hasNormals) {\n const vertexNormals = mesh.getVerticesData(VertexBuffer.NormalKind, undefined, undefined, true);\n const morphNormals = babylonMorphTarget.getNormals();\n const count = babylonSubMesh.verticesCount;\n const byteStride = 12; // 3 x 4 byte floats\n const byteLength = count * byteStride;\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + \"_NORMAL\");\n this._bufferViews.push(bufferView);\n const bufferViewIndex = this._bufferViews.length - 1;\n const accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + \" - \" + \"NORMAL\", \"VEC3\" /* AccessorType.VEC3 */, 5126 /* AccessorComponentType.FLOAT */, count, 0, null, null);\n this._accessors.push(accessor);\n target.NORMAL = this._accessors.length - 1;\n this.writeMorphTargetAttributeData(VertexBuffer.NormalKind, 5126 /* AccessorComponentType.FLOAT */, babylonSubMesh, vertexNormals, morphNormals, byteStride / 4, binaryWriter);\n }\n if (babylonMorphTarget.hasPositions) {\n const vertexPositions = mesh.getVerticesData(VertexBuffer.PositionKind, undefined, undefined, true);\n const morphPositions = babylonMorphTarget.getPositions();\n const count = babylonSubMesh.verticesCount;\n const byteStride = 12; // 3 x 4 byte floats\n const byteLength = count * byteStride;\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + \"_POSITION\");\n this._bufferViews.push(bufferView);\n const bufferViewIndex = this._bufferViews.length - 1;\n const minMax = { min: new Vector3(Infinity, Infinity, Infinity), max: new Vector3(-Infinity, -Infinity, -Infinity) };\n const accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + \" - \" + \"POSITION\", \"VEC3\" /* AccessorType.VEC3 */, 5126 /* AccessorComponentType.FLOAT */, count, 0, null, null);\n this._accessors.push(accessor);\n target.POSITION = this._accessors.length - 1;\n this.writeMorphTargetAttributeData(VertexBuffer.PositionKind, 5126 /* AccessorComponentType.FLOAT */, babylonSubMesh, vertexPositions, morphPositions, byteStride / 4, binaryWriter, minMax);\n accessor.min = minMax.min.asArray();\n accessor.max = minMax.max.asArray();\n }\n if (babylonMorphTarget.hasTangents) {\n const vertexTangents = mesh.getVerticesData(VertexBuffer.TangentKind, undefined, undefined, true);\n const morphTangents = babylonMorphTarget.getTangents();\n const count = babylonSubMesh.verticesCount;\n const byteStride = 12; // 3 x 4 byte floats\n const byteLength = count * byteStride;\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + \"_NORMAL\");\n this._bufferViews.push(bufferView);\n const bufferViewIndex = this._bufferViews.length - 1;\n const accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + \" - \" + \"TANGENT\", \"VEC3\" /* AccessorType.VEC3 */, 5126 /* AccessorComponentType.FLOAT */, count, 0, null, null);\n this._accessors.push(accessor);\n target.TANGENT = this._accessors.length - 1;\n this.writeMorphTargetAttributeData(VertexBuffer.TangentKind, 5126 /* AccessorComponentType.FLOAT */, babylonSubMesh, vertexTangents, morphTangents, byteStride / 4, binaryWriter);\n }\n meshPrimitive.targets.push(target);\n }\n }\n /**\n * The primitive mode of the Babylon mesh\n * @param babylonMesh The BabylonJS mesh\n */\n _getMeshPrimitiveMode(babylonMesh) {\n if (babylonMesh instanceof LinesMesh) {\n return Material.LineListDrawMode;\n }\n if (babylonMesh instanceof InstancedMesh || babylonMesh instanceof Mesh) {\n const baseMesh = babylonMesh instanceof Mesh ? babylonMesh : babylonMesh.sourceMesh;\n if (typeof baseMesh.overrideRenderingFillMode === \"number\") {\n return baseMesh.overrideRenderingFillMode;\n }\n }\n return babylonMesh.material ? babylonMesh.material.fillMode : Material.TriangleFillMode;\n }\n /**\n * Sets the primitive mode of the glTF mesh primitive\n * @param meshPrimitive glTF mesh primitive\n * @param primitiveMode The primitive mode\n */\n _setPrimitiveMode(meshPrimitive, primitiveMode) {\n switch (primitiveMode) {\n case Material.TriangleFillMode: {\n // glTF defaults to using Triangle Mode\n break;\n }\n case Material.TriangleStripDrawMode: {\n meshPrimitive.mode = 5 /* MeshPrimitiveMode.TRIANGLE_STRIP */;\n break;\n }\n case Material.TriangleFanDrawMode: {\n meshPrimitive.mode = 6 /* MeshPrimitiveMode.TRIANGLE_FAN */;\n break;\n }\n case Material.PointListDrawMode: {\n meshPrimitive.mode = 0 /* MeshPrimitiveMode.POINTS */;\n break;\n }\n case Material.PointFillMode: {\n meshPrimitive.mode = 0 /* MeshPrimitiveMode.POINTS */;\n break;\n }\n case Material.LineLoopDrawMode: {\n meshPrimitive.mode = 2 /* MeshPrimitiveMode.LINE_LOOP */;\n break;\n }\n case Material.LineListDrawMode: {\n meshPrimitive.mode = 1 /* MeshPrimitiveMode.LINES */;\n break;\n }\n case Material.LineStripDrawMode: {\n meshPrimitive.mode = 3 /* MeshPrimitiveMode.LINE_STRIP */;\n break;\n }\n }\n }\n /**\n * Sets the vertex attribute accessor based of the glTF mesh primitive\n * @param meshPrimitive glTF mesh primitive\n * @param attributeKind vertex attribute\n * @returns boolean specifying if uv coordinates are present\n */\n _setAttributeKind(meshPrimitive, attributeKind) {\n switch (attributeKind) {\n case VertexBuffer.PositionKind: {\n meshPrimitive.attributes.POSITION = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.NormalKind: {\n meshPrimitive.attributes.NORMAL = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.ColorKind: {\n meshPrimitive.attributes.COLOR_0 = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.TangentKind: {\n meshPrimitive.attributes.TANGENT = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.UVKind: {\n meshPrimitive.attributes.TEXCOORD_0 = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.UV2Kind: {\n meshPrimitive.attributes.TEXCOORD_1 = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.MatricesIndicesKind: {\n meshPrimitive.attributes.JOINTS_0 = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.MatricesIndicesExtraKind: {\n meshPrimitive.attributes.JOINTS_1 = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.MatricesWeightsKind: {\n meshPrimitive.attributes.WEIGHTS_0 = this._accessors.length - 1;\n break;\n }\n case VertexBuffer.MatricesWeightsExtraKind: {\n meshPrimitive.attributes.WEIGHTS_1 = this._accessors.length - 1;\n break;\n }\n default: {\n Tools.Warn(\"Unsupported Vertex Buffer Type: \" + attributeKind);\n }\n }\n }\n /**\n * Sets data for the primitive attributes of each submesh\n * @param mesh glTF Mesh object to store the primitive attribute information\n * @param babylonTransformNode Babylon mesh to get the primitive attribute data from\n * @param binaryWriter Buffer to write the attribute data to\n */\n _setPrimitiveAttributesAsync(mesh, babylonTransformNode, binaryWriter) {\n const promises = [];\n let bufferMesh = null;\n let bufferView;\n let minMax;\n if (babylonTransformNode instanceof Mesh) {\n bufferMesh = babylonTransformNode;\n }\n else if (babylonTransformNode instanceof InstancedMesh) {\n bufferMesh = babylonTransformNode.sourceMesh;\n }\n const attributeData = [\n { kind: VertexBuffer.PositionKind, accessorType: \"VEC3\" /* AccessorType.VEC3 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 12 },\n { kind: VertexBuffer.NormalKind, accessorType: \"VEC3\" /* AccessorType.VEC3 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 12 },\n { kind: VertexBuffer.ColorKind, accessorType: \"VEC4\" /* AccessorType.VEC4 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 16 },\n { kind: VertexBuffer.TangentKind, accessorType: \"VEC4\" /* AccessorType.VEC4 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 16 },\n { kind: VertexBuffer.UVKind, accessorType: \"VEC2\" /* AccessorType.VEC2 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 8 },\n { kind: VertexBuffer.UV2Kind, accessorType: \"VEC2\" /* AccessorType.VEC2 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 8 },\n { kind: VertexBuffer.MatricesIndicesKind, accessorType: \"VEC4\" /* AccessorType.VEC4 */, accessorComponentType: 5123 /* AccessorComponentType.UNSIGNED_SHORT */, byteStride: 8 },\n { kind: VertexBuffer.MatricesIndicesExtraKind, accessorType: \"VEC4\" /* AccessorType.VEC4 */, accessorComponentType: 5123 /* AccessorComponentType.UNSIGNED_SHORT */, byteStride: 8 },\n { kind: VertexBuffer.MatricesWeightsKind, accessorType: \"VEC4\" /* AccessorType.VEC4 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 16 },\n { kind: VertexBuffer.MatricesWeightsExtraKind, accessorType: \"VEC4\" /* AccessorType.VEC4 */, accessorComponentType: 5126 /* AccessorComponentType.FLOAT */, byteStride: 16 },\n ];\n if (bufferMesh) {\n let indexBufferViewIndex = null;\n const primitiveMode = this._getMeshPrimitiveMode(bufferMesh);\n const vertexAttributeBufferViews = {};\n const morphTargetManager = bufferMesh.morphTargetManager;\n // For each BabylonMesh, create bufferviews for each 'kind'\n for (const attribute of attributeData) {\n const attributeKind = attribute.kind;\n const attributeComponentKind = attribute.accessorComponentType;\n if (bufferMesh.isVerticesDataPresent(attributeKind, true)) {\n const vertexBuffer = this._getVertexBufferFromMesh(attributeKind, bufferMesh);\n attribute.byteStride = vertexBuffer\n ? vertexBuffer.getSize() * VertexBuffer.GetTypeByteLength(attribute.accessorComponentType)\n : VertexBuffer.DeduceStride(attributeKind) * 4;\n if (attribute.byteStride === 12) {\n attribute.accessorType = \"VEC3\" /* AccessorType.VEC3 */;\n }\n this._createBufferViewKind(attributeKind, attributeComponentKind, babylonTransformNode, binaryWriter, attribute.byteStride);\n attribute.bufferViewIndex = this._bufferViews.length - 1;\n vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;\n }\n }\n if (bufferMesh.getTotalIndices()) {\n const indices = bufferMesh.getIndices();\n if (indices) {\n const byteLength = indices.length * 4;\n bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, \"Indices - \" + bufferMesh.name);\n this._bufferViews.push(bufferView);\n indexBufferViewIndex = this._bufferViews.length - 1;\n for (let k = 0, length = indices.length; k < length; ++k) {\n binaryWriter.setUInt32(indices[k]);\n }\n }\n }\n if (bufferMesh.subMeshes) {\n // go through all mesh primitives (submeshes)\n for (const submesh of bufferMesh.subMeshes) {\n let babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;\n let materialIndex = null;\n if (babylonMaterial) {\n if (bufferMesh instanceof LinesMesh) {\n // get the color from the lines mesh and set it in the material\n const material = {\n name: bufferMesh.name + \" material\",\n };\n if (!bufferMesh.color.equals(Color3.White()) || bufferMesh.alpha < 1) {\n material.pbrMetallicRoughness = {\n baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha]),\n };\n }\n this._materials.push(material);\n materialIndex = this._materials.length - 1;\n }\n else if (babylonMaterial instanceof MultiMaterial) {\n const subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];\n if (subMaterial) {\n babylonMaterial = subMaterial;\n materialIndex = this._materialMap[babylonMaterial.uniqueId];\n }\n }\n else {\n materialIndex = this._materialMap[babylonMaterial.uniqueId];\n }\n }\n const glTFMaterial = materialIndex != null ? this._materials[materialIndex] : null;\n const meshPrimitive = { attributes: {} };\n this._setPrimitiveMode(meshPrimitive, primitiveMode);\n for (const attribute of attributeData) {\n const attributeKind = attribute.kind;\n if ((attributeKind === VertexBuffer.UVKind || attributeKind === VertexBuffer.UV2Kind) && !this._options.exportUnusedUVs) {\n if (!glTFMaterial || !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {\n continue;\n }\n }\n const vertexData = bufferMesh.getVerticesData(attributeKind, undefined, undefined, true);\n if (vertexData) {\n const vertexBuffer = this._getVertexBufferFromMesh(attributeKind, bufferMesh);\n if (vertexBuffer) {\n const stride = vertexBuffer.getSize();\n const bufferViewIndex = attribute.bufferViewIndex;\n if (bufferViewIndex != undefined) {\n // check to see if bufferviewindex has a numeric value assigned.\n minMax = { min: null, max: null };\n if (attributeKind == VertexBuffer.PositionKind) {\n minMax = _GLTFUtilities._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride);\n }\n const accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, attributeKind + \" - \" + babylonTransformNode.name, attribute.accessorType, attribute.accessorComponentType, vertexData.length / stride, 0, minMax.min, minMax.max);\n this._accessors.push(accessor);\n this._setAttributeKind(meshPrimitive, attributeKind);\n }\n }\n }\n }\n if (indexBufferViewIndex) {\n // Create accessor\n const accessor = _GLTFUtilities._CreateAccessor(indexBufferViewIndex, \"indices - \" + babylonTransformNode.name, \"SCALAR\" /* AccessorType.SCALAR */, 5125 /* AccessorComponentType.UNSIGNED_INT */, submesh.indexCount, submesh.indexStart * 4, null, null);\n this._accessors.push(accessor);\n meshPrimitive.indices = this._accessors.length - 1;\n }\n if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {\n const sideOrientation = bufferMesh.overrideMaterialSideOrientation !== null ? bufferMesh.overrideMaterialSideOrientation : babylonMaterial.sideOrientation;\n if (sideOrientation === (this._babylonScene.useRightHandedSystem ? Material.ClockWiseSideOrientation : Material.CounterClockWiseSideOrientation)) {\n let byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;\n if (byteOffset == null) {\n byteOffset = 0;\n }\n let babylonIndices = null;\n if (indexBufferViewIndex != null) {\n babylonIndices = bufferMesh.getIndices();\n }\n if (babylonIndices) {\n this._reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);\n }\n else {\n for (const attribute of attributeData) {\n const vertexData = bufferMesh.getVerticesData(attribute.kind, undefined, undefined, true);\n if (vertexData) {\n const byteOffset = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset || 0;\n this._reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, attribute.kind, vertexData, byteOffset, binaryWriter);\n }\n }\n }\n }\n meshPrimitive.material = materialIndex;\n }\n if (morphTargetManager) {\n let target;\n for (let i = 0; i < morphTargetManager.numTargets; ++i) {\n target = morphTargetManager.getTarget(i);\n this._setMorphTargetAttributes(submesh, meshPrimitive, target, binaryWriter);\n }\n }\n mesh.primitives.push(meshPrimitive);\n this._extensionsPostExportMeshPrimitiveAsync(\"postExport\", meshPrimitive, submesh, binaryWriter);\n promises.push();\n }\n }\n }\n return Promise.all(promises).then(() => {\n /* do nothing */\n });\n }\n /**\n * Creates a glTF scene based on the array of meshes\n * Returns the the total byte offset\n * @param babylonScene Babylon scene to get the mesh data from\n * @param binaryWriter Buffer to write binary data to\n */\n _createSceneAsync(binaryWriter) {\n var _a;\n const scene = { nodes: [] };\n let glTFNodeIndex;\n let glTFNode;\n let directDescendents;\n const nodes = [...this._babylonScene.transformNodes, ...this._babylonScene.meshes, ...this._babylonScene.lights, ...this._babylonScene.cameras];\n const removedRootNodes = new Set();\n // Scene metadata\n if (this._babylonScene.metadata) {\n if (this._options.metadataSelector) {\n scene.extras = this._options.metadataSelector(this._babylonScene.metadata);\n }\n else if (this._babylonScene.metadata.gltf) {\n scene.extras = this._babylonScene.metadata.gltf.extras;\n }\n }\n // Remove no-op root nodes\n if (((_a = this._options.removeNoopRootNodes) !== null && _a !== void 0 ? _a : true) && !this._options.includeCoordinateSystemConversionNodes) {\n for (const rootNode of this._babylonScene.rootNodes) {\n if (isNoopNode(rootNode, this._babylonScene.useRightHandedSystem)) {\n removedRootNodes.add(rootNode);\n // Exclude the node from list of nodes to export\n nodes.splice(nodes.indexOf(rootNode), 1);\n }\n }\n }\n // Export babylon cameras to glTFCamera\n const cameraMap = new Map();\n this._babylonScene.cameras.forEach((camera) => {\n if (!this._options.shouldExportNode || this._options.shouldExportNode(camera)) {\n const glTFCamera = {\n type: camera.mode === Camera.PERSPECTIVE_CAMERA ? \"perspective\" /* CameraType.PERSPECTIVE */ : \"orthographic\" /* CameraType.ORTHOGRAPHIC */,\n };\n if (camera.name) {\n glTFCamera.name = camera.name;\n }\n if (glTFCamera.type === \"perspective\" /* CameraType.PERSPECTIVE */) {\n glTFCamera.perspective = {\n aspectRatio: camera.getEngine().getAspectRatio(camera),\n yfov: camera.fovMode === Camera.FOVMODE_VERTICAL_FIXED ? camera.fov : camera.fov * camera.getEngine().getAspectRatio(camera),\n znear: camera.minZ,\n zfar: camera.maxZ,\n };\n }\n else if (glTFCamera.type === \"orthographic\" /* CameraType.ORTHOGRAPHIC */) {\n const halfWidth = camera.orthoLeft && camera.orthoRight ? 0.5 * (camera.orthoRight - camera.orthoLeft) : camera.getEngine().getRenderWidth() * 0.5;\n const halfHeight = camera.orthoBottom && camera.orthoTop ? 0.5 * (camera.orthoTop - camera.orthoBottom) : camera.getEngine().getRenderHeight() * 0.5;\n glTFCamera.orthographic = {\n xmag: halfWidth,\n ymag: halfHeight,\n znear: camera.minZ,\n zfar: camera.maxZ,\n };\n }\n cameraMap.set(camera, this._cameras.length);\n this._cameras.push(glTFCamera);\n }\n });\n const [exportNodes, exportMaterials] = this._getExportNodes(nodes);\n return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(exportMaterials, \"image/png\" /* ImageMimeType.PNG */, true).then(() => {\n return this._createNodeMapAndAnimationsAsync(exportNodes, binaryWriter).then((nodeMap) => {\n return this._createSkinsAsync(nodeMap, binaryWriter).then((skinMap) => {\n this._nodeMap = nodeMap;\n this._totalByteLength = binaryWriter.getByteOffset();\n if (this._totalByteLength == undefined) {\n throw new Error(\"undefined byte length!\");\n }\n // Build Hierarchy with the node map.\n for (const babylonNode of nodes) {\n glTFNodeIndex = this._nodeMap[babylonNode.uniqueId];\n if (glTFNodeIndex !== undefined) {\n glTFNode = this._nodes[glTFNodeIndex];\n if (babylonNode.metadata) {\n if (this._options.metadataSelector) {\n glTFNode.extras = this._options.metadataSelector(babylonNode.metadata);\n }\n else if (babylonNode.metadata.gltf) {\n glTFNode.extras = babylonNode.metadata.gltf.extras;\n }\n }\n if (babylonNode instanceof Camera) {\n glTFNode.camera = cameraMap.get(babylonNode);\n }\n if (this._options.shouldExportNode && !this._options.shouldExportNode(babylonNode)) {\n Tools.Log(\"Omitting \" + babylonNode.name + \" from scene.\");\n }\n else {\n if (!babylonNode.parent && !this._babylonScene.useRightHandedSystem) {\n convertNodeHandedness(glTFNode);\n }\n if (!babylonNode.parent || removedRootNodes.has(babylonNode.parent)) {\n scene.nodes.push(glTFNodeIndex);\n }\n }\n if (babylonNode instanceof Mesh) {\n if (babylonNode.skeleton) {\n glTFNode.skin = skinMap[babylonNode.skeleton.uniqueId];\n }\n }\n directDescendents = babylonNode.getDescendants(true);\n if (!glTFNode.children && directDescendents && directDescendents.length) {\n const children = [];\n for (const descendent of directDescendents) {\n if (this._nodeMap[descendent.uniqueId] != null) {\n children.push(this._nodeMap[descendent.uniqueId]);\n }\n }\n if (children.length) {\n glTFNode.children = children;\n }\n }\n }\n }\n if (scene.nodes.length) {\n this._scenes.push(scene);\n }\n });\n });\n });\n }\n /**\n * Getting the nodes and materials that would be exported.\n * @param nodes Babylon transform nodes\n * @returns Array of nodes which would be exported.\n * @returns Set of materials which would be exported.\n */\n _getExportNodes(nodes) {\n const exportNodes = [];\n const exportMaterials = new Set();\n for (const babylonNode of nodes) {\n if (!this._options.shouldExportNode || this._options.shouldExportNode(babylonNode)) {\n exportNodes.push(babylonNode);\n const babylonMesh = babylonNode;\n if (babylonMesh.subMeshes && babylonMesh.subMeshes.length > 0) {\n const material = babylonMesh.material || babylonMesh.getScene().defaultMaterial;\n if (material instanceof MultiMaterial) {\n for (const subMaterial of material.subMaterials) {\n if (subMaterial) {\n exportMaterials.add(subMaterial);\n }\n }\n }\n else {\n exportMaterials.add(material);\n }\n }\n }\n else {\n `Excluding node ${babylonNode.name}`;\n }\n }\n return [exportNodes, exportMaterials];\n }\n /**\n * Creates a mapping of Node unique id to node index and handles animations\n * @param nodes Babylon transform nodes\n * @param binaryWriter Buffer to write binary data to\n * @returns Node mapping of unique id to index\n */\n _createNodeMapAndAnimationsAsync(nodes, binaryWriter) {\n let promiseChain = Promise.resolve();\n const nodeMap = {};\n let nodeIndex;\n const runtimeGLTFAnimation = {\n name: \"runtime animations\",\n channels: [],\n samplers: [],\n };\n const idleGLTFAnimations = [];\n for (const babylonNode of nodes) {\n promiseChain = promiseChain.then(() => {\n return this._createNodeAsync(babylonNode, binaryWriter).then((node) => {\n const promise = this._extensionsPostExportNodeAsync(\"createNodeAsync\", node, babylonNode, nodeMap, binaryWriter);\n if (promise == null) {\n Tools.Warn(`Not exporting node ${babylonNode.name}`);\n return Promise.resolve();\n }\n else {\n return promise.then((node) => {\n if (!node) {\n return;\n }\n this._nodes.push(node);\n nodeIndex = this._nodes.length - 1;\n nodeMap[babylonNode.uniqueId] = nodeIndex;\n if (!this._babylonScene.animationGroups.length) {\n _GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, this._nodes, binaryWriter, this._bufferViews, this._accessors, this._animationSampleRate, this._options.shouldExportAnimation);\n if (babylonNode.animations.length) {\n _GLTFAnimation._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, this._nodes, binaryWriter, this._bufferViews, this._accessors, this._animationSampleRate, this._options.shouldExportAnimation);\n }\n }\n });\n }\n });\n });\n }\n return promiseChain.then(() => {\n if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {\n this._animations.push(runtimeGLTFAnimation);\n }\n idleGLTFAnimations.forEach((idleGLTFAnimation) => {\n if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {\n this._animations.push(idleGLTFAnimation);\n }\n });\n if (this._babylonScene.animationGroups.length) {\n _GLTFAnimation._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene, this._animations, nodeMap, binaryWriter, this._bufferViews, this._accessors, this._animationSampleRate, this._options.shouldExportAnimation);\n }\n return nodeMap;\n });\n }\n /**\n * Creates a glTF node from a Babylon mesh\n * @param babylonNode Source Babylon mesh\n * @param binaryWriter Buffer for storing geometry data\n * @returns glTF node\n */\n _createNodeAsync(babylonNode, binaryWriter) {\n return Promise.resolve().then(() => {\n // create node to hold translation/rotation/scale and the mesh\n const node = {};\n // create mesh\n const mesh = { primitives: [] };\n if (babylonNode.name) {\n node.name = babylonNode.name;\n }\n if (babylonNode instanceof TransformNode) {\n // Set transformation\n this._setNodeTransformation(node, babylonNode);\n if (babylonNode instanceof Mesh) {\n const morphTargetManager = babylonNode.morphTargetManager;\n if (morphTargetManager && morphTargetManager.numTargets > 0) {\n mesh.weights = [];\n for (let i = 0; i < morphTargetManager.numTargets; ++i) {\n mesh.weights.push(morphTargetManager.getTarget(i).influence);\n }\n }\n }\n return this._setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(() => {\n if (mesh.primitives.length) {\n this._meshes.push(mesh);\n node.mesh = this._meshes.length - 1;\n }\n return node;\n });\n }\n else if (babylonNode instanceof Camera) {\n this._setCameraTransformation(node, babylonNode);\n return node;\n }\n else {\n return node;\n }\n });\n }\n /**\n * Creates a glTF skin from a Babylon skeleton\n * @param babylonScene Babylon Scene\n * @param nodeMap Babylon transform nodes\n * @param binaryWriter Buffer to write binary data to\n * @returns Node mapping of unique id to index\n */\n _createSkinsAsync(nodeMap, binaryWriter) {\n var _a;\n const promiseChain = Promise.resolve();\n const skinMap = {};\n for (const skeleton of this._babylonScene.skeletons) {\n if (skeleton.bones.length <= 0) {\n continue;\n }\n // create skin\n const skin = { joints: [] };\n const inverseBindMatrices = [];\n const boneIndexMap = {};\n let maxBoneIndex = -1;\n for (let i = 0; i < skeleton.bones.length; ++i) {\n const bone = skeleton.bones[i];\n const boneIndex = (_a = bone.getIndex()) !== null && _a !== void 0 ? _a : i;\n if (boneIndex !== -1) {\n boneIndexMap[boneIndex] = bone;\n if (boneIndex > maxBoneIndex) {\n maxBoneIndex = boneIndex;\n }\n }\n }\n for (let boneIndex = 0; boneIndex <= maxBoneIndex; ++boneIndex) {\n const bone = boneIndexMap[boneIndex];\n inverseBindMatrices.push(bone.getInvertedAbsoluteTransform());\n const transformNode = bone.getTransformNode();\n if (transformNode && nodeMap[transformNode.uniqueId] !== null && nodeMap[transformNode.uniqueId] !== undefined) {\n skin.joints.push(nodeMap[transformNode.uniqueId]);\n }\n else {\n Tools.Warn(\"Exporting a bone without a linked transform node is currently unsupported\");\n }\n }\n if (skin.joints.length > 0) {\n // create buffer view for inverse bind matrices\n const byteStride = 64; // 4 x 4 matrix of 32 bit float\n const byteLength = inverseBindMatrices.length * byteStride;\n const bufferViewOffset = binaryWriter.getByteOffset();\n const bufferView = _GLTFUtilities._CreateBufferView(0, bufferViewOffset, byteLength, undefined, \"InverseBindMatrices\" + \" - \" + skeleton.name);\n this._bufferViews.push(bufferView);\n const bufferViewIndex = this._bufferViews.length - 1;\n const bindMatrixAccessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, \"InverseBindMatrices\" + \" - \" + skeleton.name, \"MAT4\" /* AccessorType.MAT4 */, 5126 /* AccessorComponentType.FLOAT */, inverseBindMatrices.length, null, null, null);\n const inverseBindAccessorIndex = this._accessors.push(bindMatrixAccessor) - 1;\n skin.inverseBindMatrices = inverseBindAccessorIndex;\n this._skins.push(skin);\n skinMap[skeleton.uniqueId] = this._skins.length - 1;\n inverseBindMatrices.forEach((mat) => {\n mat.m.forEach((cell) => {\n binaryWriter.setFloat32(cell);\n });\n });\n }\n }\n return promiseChain.then(() => {\n return skinMap;\n });\n }\n }\n _Exporter._ExtensionNames = new Array();\n _Exporter._ExtensionFactories = {};\n /**\n * @internal\n *\n * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically\n */\n class _BinaryWriter {\n /**\n * Initialize binary writer with an initial byte length\n * @param byteLength Initial byte length of the array buffer\n */\n constructor(byteLength) {\n this._arrayBuffer = new ArrayBuffer(byteLength);\n this._dataView = new DataView(this._arrayBuffer);\n this._byteOffset = 0;\n }\n /**\n * Resize the array buffer to the specified byte length\n * @param byteLength\n */\n _resizeBuffer(byteLength) {\n const newBuffer = new ArrayBuffer(byteLength);\n const copyOldBufferSize = Math.min(this._arrayBuffer.byteLength, byteLength);\n const oldUint8Array = new Uint8Array(this._arrayBuffer, 0, copyOldBufferSize);\n const newUint8Array = new Uint8Array(newBuffer);\n newUint8Array.set(oldUint8Array, 0);\n this._arrayBuffer = newBuffer;\n this._dataView = new DataView(this._arrayBuffer);\n return newBuffer;\n }\n /**\n * Get an array buffer with the length of the byte offset\n * @returns ArrayBuffer resized to the byte offset\n */\n getArrayBuffer() {\n return this._resizeBuffer(this.getByteOffset());\n }\n /**\n * Get the byte offset of the array buffer\n * @returns byte offset\n */\n getByteOffset() {\n if (this._byteOffset == undefined) {\n throw new Error(\"Byte offset is undefined!\");\n }\n return this._byteOffset;\n }\n /**\n * Stores an UInt8 in the array buffer\n * @param entry\n * @param byteOffset If defined, specifies where to set the value as an offset.\n */\n setUInt8(entry, byteOffset) {\n if (byteOffset != null) {\n if (byteOffset < this._byteOffset) {\n this._dataView.setUint8(byteOffset, entry);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n }\n }\n else {\n if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\n }\n this._dataView.setUint8(this._byteOffset, entry);\n this._byteOffset += 1;\n }\n }\n /**\n * Stores an UInt16 in the array buffer\n * @param entry\n * @param byteOffset If defined, specifies where to set the value as an offset.\n */\n setUInt16(entry, byteOffset) {\n if (byteOffset != null) {\n if (byteOffset < this._byteOffset) {\n this._dataView.setUint16(byteOffset, entry, true);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n }\n }\n else {\n if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\n }\n this._dataView.setUint16(this._byteOffset, entry, true);\n this._byteOffset += 2;\n }\n }\n /**\n * Gets an UInt32 in the array buffer\n * @param byteOffset If defined, specifies where to set the value as an offset.\n */\n getUInt32(byteOffset) {\n if (byteOffset < this._byteOffset) {\n return this._dataView.getUint32(byteOffset, true);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n throw new Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n }\n }\n getVector3Float32FromRef(vector3, byteOffset) {\n if (byteOffset + 8 > this._byteOffset) {\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\n }\n else {\n vector3.x = this._dataView.getFloat32(byteOffset, true);\n vector3.y = this._dataView.getFloat32(byteOffset + 4, true);\n vector3.z = this._dataView.getFloat32(byteOffset + 8, true);\n }\n }\n setVector3Float32FromRef(vector3, byteOffset) {\n if (byteOffset + 8 > this._byteOffset) {\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\n }\n else {\n this._dataView.setFloat32(byteOffset, vector3.x, true);\n this._dataView.setFloat32(byteOffset + 4, vector3.y, true);\n this._dataView.setFloat32(byteOffset + 8, vector3.z, true);\n }\n }\n getVector4Float32FromRef(vector4, byteOffset) {\n if (byteOffset + 12 > this._byteOffset) {\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\n }\n else {\n vector4.x = this._dataView.getFloat32(byteOffset, true);\n vector4.y = this._dataView.getFloat32(byteOffset + 4, true);\n vector4.z = this._dataView.getFloat32(byteOffset + 8, true);\n vector4.w = this._dataView.getFloat32(byteOffset + 12, true);\n }\n }\n setVector4Float32FromRef(vector4, byteOffset) {\n if (byteOffset + 12 > this._byteOffset) {\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\n }\n else {\n this._dataView.setFloat32(byteOffset, vector4.x, true);\n this._dataView.setFloat32(byteOffset + 4, vector4.y, true);\n this._dataView.setFloat32(byteOffset + 8, vector4.z, true);\n this._dataView.setFloat32(byteOffset + 12, vector4.w, true);\n }\n }\n /**\n * Stores a Float32 in the array buffer\n * @param entry\n * @param byteOffset\n */\n setFloat32(entry, byteOffset) {\n if (isNaN(entry)) {\n Tools.Error(\"Invalid data being written!\");\n }\n if (byteOffset != null) {\n if (byteOffset < this._byteOffset) {\n this._dataView.setFloat32(byteOffset, entry, true);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary length!\");\n }\n }\n if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\n }\n this._dataView.setFloat32(this._byteOffset, entry, true);\n this._byteOffset += 4;\n }\n /**\n * Stores an UInt32 in the array buffer\n * @param entry\n * @param byteOffset If defined, specifies where to set the value as an offset.\n */\n setUInt32(entry, byteOffset) {\n if (byteOffset != null) {\n if (byteOffset < this._byteOffset) {\n this._dataView.setUint32(byteOffset, entry, true);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n }\n }\n else {\n if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\n }\n this._dataView.setUint32(this._byteOffset, entry, true);\n this._byteOffset += 4;\n }\n }\n /**\n * Stores an Int16 in the array buffer\n * @param entry\n * @param byteOffset If defined, specifies where to set the value as an offset.\n */\n setInt16(entry, byteOffset) {\n if (byteOffset != null) {\n if (byteOffset < this._byteOffset) {\n this._dataView.setInt16(byteOffset, entry, true);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n }\n }\n else {\n if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\n }\n this._dataView.setInt16(this._byteOffset, entry, true);\n this._byteOffset += 2;\n }\n }\n /**\n * Stores a byte in the array buffer\n * @param entry\n * @param byteOffset If defined, specifies where to set the value as an offset.\n */\n setByte(entry, byteOffset) {\n if (byteOffset != null) {\n if (byteOffset < this._byteOffset) {\n this._dataView.setInt8(byteOffset, entry);\n }\n else {\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\n }\n }\n else {\n if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\n }\n this._dataView.setInt8(this._byteOffset, entry);\n this._byteOffset++;\n }\n }\n }\n\n /**\n * Class for generating glTF data from a Babylon scene.\n */\n class GLTF2Export {\n /**\n * Exports the geometry of the scene to .gltf file format asynchronously\n * @param scene Babylon scene with scene hierarchy information\n * @param filePrefix File prefix to use when generating the glTF file\n * @param options Exporter options\n * @returns Returns an object with a .gltf file and associates texture names\n * as keys and their data and paths as values\n */\n static GLTFAsync(scene, filePrefix, options) {\n return scene.whenReadyAsync().then(() => {\n const glTFPrefix = filePrefix.replace(/\\.[^/.]+$/, \"\");\n const gltfGenerator = new _Exporter(scene, options);\n return gltfGenerator._generateGLTFAsync(glTFPrefix);\n });\n }\n static _PreExportAsync(scene, options) {\n return Promise.resolve().then(() => {\n if (options && options.exportWithoutWaitingForScene) {\n return Promise.resolve();\n }\n else {\n return scene.whenReadyAsync();\n }\n });\n }\n static _PostExportAsync(scene, glTFData, options) {\n return Promise.resolve().then(() => {\n if (options && options.exportWithoutWaitingForScene) {\n return glTFData;\n }\n else {\n return glTFData;\n }\n });\n }\n /**\n * Exports the geometry of the scene to .glb file format asychronously\n * @param scene Babylon scene with scene hierarchy information\n * @param filePrefix File prefix to use when generating glb file\n * @param options Exporter options\n * @returns Returns an object with a .glb filename as key and data as value\n */\n static GLBAsync(scene, filePrefix, options) {\n return this._PreExportAsync(scene, options).then(() => {\n const glTFPrefix = filePrefix.replace(/\\.[^/.]+$/, \"\");\n const gltfGenerator = new _Exporter(scene, options);\n return gltfGenerator._generateGLBAsync(glTFPrefix).then((glTFData) => {\n return this._PostExportAsync(scene, glTFData, options);\n });\n });\n }\n }\n\n const NAME = \"KHR_texture_transform\";\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_texture_transform {\n constructor() {\n /** Name of this extension */\n this.name = NAME;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n /** Reference to the glTF exporter */\n this._wasUsed = false;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportTexture(context, textureInfo, babylonTexture) {\n const canUseExtension = babylonTexture &&\n ((babylonTexture.uAng === 0 && babylonTexture.wAng === 0 && babylonTexture.vAng === 0) ||\n (babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0));\n if (canUseExtension) {\n const textureTransform = {};\n let transformIsRequired = false;\n if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {\n textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];\n transformIsRequired = true;\n }\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\n textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];\n transformIsRequired = true;\n }\n if (babylonTexture.wAng !== 0) {\n textureTransform.rotation = -babylonTexture.wAng;\n transformIsRequired = true;\n }\n if (babylonTexture.coordinatesIndex !== 0) {\n textureTransform.texCoord = babylonTexture.coordinatesIndex;\n transformIsRequired = true;\n }\n if (!transformIsRequired) {\n return;\n }\n this._wasUsed = true;\n if (!textureInfo.extensions) {\n textureInfo.extensions = {};\n }\n textureInfo.extensions[NAME] = textureTransform;\n }\n }\n preExportTextureAsync(context, babylonTexture) {\n return new Promise((resolve, reject) => {\n const scene = babylonTexture.getScene();\n if (!scene) {\n reject(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}!`);\n return;\n }\n /*\n * The KHR_texture_transform schema only supports w rotation around the origin.\n * See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.\n */\n if (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);\n resolve(null);\n }\n else if (babylonTexture.wAng !== 0 && (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)) {\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin cannot be exported with ${NAME}`);\n resolve(null);\n }\n else {\n resolve(babylonTexture);\n }\n });\n }\n }\n _Exporter.RegisterExtension(NAME, () => new KHR_texture_transform());\n\n const NAME$1 = \"KHR_lights_punctual\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_lights_punctual {\n /**\n * @internal\n */\n constructor(exporter) {\n /** The name of this extension. */\n this.name = NAME$1;\n /** Defines whether this extension is enabled. */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._exporter = exporter;\n }\n /** @internal */\n dispose() {\n this._lights = null;\n }\n /** @internal */\n get wasUsed() {\n return !!this._lights;\n }\n /** @internal */\n onExporting() {\n this._exporter._glTF.extensions[NAME$1] = this._lights;\n }\n /**\n * Define this method to modify the default behavior when exporting a node\n * @param context The context when exporting the node\n * @param node glTF node\n * @param babylonNode BabylonJS node\n * @param nodeMap Node mapping of unique id to glTF node index\n * @returns nullable INode promise\n */\n postExportNodeAsync(context, node, babylonNode, nodeMap) {\n return new Promise((resolve) => {\n if (node && babylonNode instanceof ShadowLight) {\n let light;\n const lightType = babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\n ? \"point\" /* KHRLightsPunctual_LightType.POINT */\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\n ? \"directional\" /* KHRLightsPunctual_LightType.DIRECTIONAL */\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\n ? \"spot\" /* KHRLightsPunctual_LightType.SPOT */\n : null;\n if (lightType == null) {\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME$1}`);\n }\n else {\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\n node.translation = babylonNode.position.asArray();\n }\n if (lightType !== \"point\" /* KHRLightsPunctual_LightType.POINT */) {\n const localAxis = babylonNode.direction;\n const yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\n const pitch = -Math.atan2(localAxis.y, len);\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw + Math.PI, pitch, 0);\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\n node.rotation = lightRotationQuaternion.asArray();\n }\n }\n if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {\n Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME$1} specification!`);\n }\n light = {\n type: lightType,\n };\n if (!babylonNode.diffuse.equals(Color3.White())) {\n light.color = babylonNode.diffuse.asArray();\n }\n if (babylonNode.intensity !== 1.0) {\n light.intensity = babylonNode.intensity;\n }\n if (babylonNode.range !== Number.MAX_VALUE) {\n light.range = babylonNode.range;\n }\n if (lightType === \"spot\" /* KHRLightsPunctual_LightType.SPOT */) {\n const babylonSpotLight = babylonNode;\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\n if (light.spot == null) {\n light.spot = {};\n }\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\n }\n if (babylonSpotLight.innerAngle !== 0) {\n if (light.spot == null) {\n light.spot = {};\n }\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\n }\n }\n this._lights || (this._lights = {\n lights: [],\n });\n this._lights.lights.push(light);\n const lightReference = {\n light: this._lights.lights.length - 1,\n };\n // Avoid duplicating the Light's parent node if possible.\n const parentBabylonNode = babylonNode.parent;\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\n const parentNode = this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];\n if (parentNode) {\n const parentTranslation = Vector3.FromArrayToRef(parentNode.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);\n const parentRotation = Quaternion.FromArrayToRef(parentNode.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);\n const parentScale = Vector3.FromArrayToRef(parentNode.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);\n const parentMatrix = Matrix.ComposeToRef(parentScale, parentRotation, parentTranslation, TmpVectors.Matrix[0]);\n const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[2]);\n const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]);\n const matrix = Matrix.ComposeToRef(Vector3.OneReadOnly, rotation, translation, TmpVectors.Matrix[1]);\n parentMatrix.multiplyToRef(matrix, matrix);\n matrix.decompose(parentScale, parentRotation, parentTranslation);\n if (parentTranslation.equalsToFloats(0, 0, 0)) {\n delete parentNode.translation;\n }\n else {\n parentNode.translation = parentTranslation.asArray();\n }\n if (Quaternion.IsIdentity(parentRotation)) {\n delete parentNode.rotation;\n }\n else {\n parentNode.rotation = parentRotation.asArray();\n }\n if (parentScale.equalsToFloats(1, 1, 1)) {\n delete parentNode.scale;\n }\n else {\n parentNode.scale = parentScale.asArray();\n }\n parentNode.extensions || (parentNode.extensions = {});\n parentNode.extensions[NAME$1] = lightReference;\n // Do not export the original node\n resolve(null);\n return;\n }\n }\n node.extensions || (node.extensions = {});\n node.extensions[NAME$1] = lightReference;\n }\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$1, (exporter) => new KHR_lights_punctual(exporter));\n\n const NAME$2 = \"KHR_materials_clearcoat\";\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_clearcoat {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$2;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n const additionalTextures = [];\n if (babylonMaterial instanceof PBRBaseMaterial) {\n if (babylonMaterial.clearCoat.isEnabled) {\n if (babylonMaterial.clearCoat.texture) {\n additionalTextures.push(babylonMaterial.clearCoat.texture);\n }\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\n }\n if (babylonMaterial.clearCoat.bumpTexture) {\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\n }\n return additionalTextures;\n }\n }\n return [];\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n if (babylonMaterial instanceof PBRBaseMaterial) {\n if (!babylonMaterial.clearCoat.isEnabled) {\n resolve(node);\n return;\n }\n this._wasUsed = true;\n node.extensions = node.extensions || {};\n const clearCoatTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);\n let clearCoatTextureRoughnessInfo;\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\n clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);\n }\n else {\n clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\n }\n if (babylonMaterial.clearCoat.isTintEnabled) {\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\n }\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\n }\n const clearCoatNormalTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\n const clearCoatInfo = {\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\n clearcoatTexture: clearCoatTextureInfo !== null && clearCoatTextureInfo !== void 0 ? clearCoatTextureInfo : undefined,\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo !== null && clearCoatTextureRoughnessInfo !== void 0 ? clearCoatTextureRoughnessInfo : undefined,\n clearcoatNormalTexture: clearCoatNormalTextureInfo !== null && clearCoatNormalTextureInfo !== void 0 ? clearCoatNormalTextureInfo : undefined,\n hasTextures: () => {\n return clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null;\n },\n };\n node.extensions[NAME$2] = clearCoatInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$2, (exporter) => new KHR_materials_clearcoat(exporter));\n\n const NAME$3 = \"KHR_materials_iridescence\";\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_iridescence {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$3;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n const additionalTextures = [];\n if (babylonMaterial instanceof PBRBaseMaterial) {\n if (babylonMaterial.iridescence.isEnabled) {\n if (babylonMaterial.iridescence.texture) {\n additionalTextures.push(babylonMaterial.iridescence.texture);\n }\n if (babylonMaterial.iridescence.thicknessTexture && babylonMaterial.iridescence.thicknessTexture !== babylonMaterial.iridescence.texture) {\n additionalTextures.push(babylonMaterial.iridescence.thicknessTexture);\n }\n return additionalTextures;\n }\n }\n return [];\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n if (babylonMaterial instanceof PBRBaseMaterial) {\n if (!babylonMaterial.iridescence.isEnabled) {\n resolve(node);\n return;\n }\n this._wasUsed = true;\n node.extensions = node.extensions || {};\n const iridescenceTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.iridescence.texture);\n const iridescenceThicknessTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.iridescence.thicknessTexture);\n const iridescenceInfo = {\n iridescenceFactor: babylonMaterial.iridescence.intensity,\n iridescenceIor: babylonMaterial.iridescence.indexOfRefraction,\n iridescenceThicknessMinimum: babylonMaterial.iridescence.minimumThickness,\n iridescenceThicknessMaximum: babylonMaterial.iridescence.maximumThickness,\n iridescenceTexture: iridescenceTextureInfo !== null && iridescenceTextureInfo !== void 0 ? iridescenceTextureInfo : undefined,\n iridescenceThicknessTexture: iridescenceThicknessTextureInfo !== null && iridescenceThicknessTextureInfo !== void 0 ? iridescenceThicknessTextureInfo : undefined,\n hasTextures: () => {\n return iridescenceInfo.iridescenceTexture !== null || iridescenceInfo.iridescenceThicknessTexture !== null;\n },\n };\n node.extensions[NAME$3] = iridescenceInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$3, (exporter) => new KHR_materials_iridescence(exporter));\n\n const NAME$4 = \"KHR_materials_anisotropy\";\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_anisotropy {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$4;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n const additionalTextures = [];\n if (babylonMaterial instanceof PBRBaseMaterial) {\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\n if (babylonMaterial.anisotropy.texture) {\n additionalTextures.push(babylonMaterial.anisotropy.texture);\n }\n return additionalTextures;\n }\n }\n return [];\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n if (babylonMaterial instanceof PBRBaseMaterial) {\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\n resolve(node);\n return;\n }\n this._wasUsed = true;\n node.extensions = node.extensions || {};\n const anisotropyTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.anisotropy.texture);\n const anisotropyInfo = {\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\n anisotropyRotation: babylonMaterial.anisotropy.angle,\n anisotropyTexture: anisotropyTextureInfo !== null && anisotropyTextureInfo !== void 0 ? anisotropyTextureInfo : undefined,\n hasTextures: () => {\n return anisotropyInfo.anisotropyTexture !== null;\n },\n };\n node.extensions[NAME$4] = anisotropyInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$4, (exporter) => new KHR_materials_anisotropy(exporter));\n\n const NAME$5 = \"KHR_materials_sheen\";\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_sheen {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$5;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n if (babylonMaterial instanceof PBRMaterial) {\n if (babylonMaterial.sheen.isEnabled && babylonMaterial.sheen.texture) {\n return [babylonMaterial.sheen.texture];\n }\n }\n return [];\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n var _a, _b, _c, _d;\n if (babylonMaterial instanceof PBRMaterial) {\n if (!babylonMaterial.sheen.isEnabled) {\n resolve(node);\n return;\n }\n this._wasUsed = true;\n if (node.extensions == null) {\n node.extensions = {};\n }\n const sheenInfo = {\n sheenColorFactor: babylonMaterial.sheen.color.asArray(),\n sheenRoughnessFactor: (_a = babylonMaterial.sheen.roughness) !== null && _a !== void 0 ? _a : 0,\n hasTextures: () => {\n return sheenInfo.sheenColorTexture !== null || sheenInfo.sheenRoughnessTexture !== null;\n },\n };\n if (babylonMaterial.sheen.texture) {\n sheenInfo.sheenColorTexture = (_b = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture)) !== null && _b !== void 0 ? _b : undefined;\n }\n if (babylonMaterial.sheen.textureRoughness && !babylonMaterial.sheen.useRoughnessFromMainTexture) {\n sheenInfo.sheenRoughnessTexture = (_c = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.textureRoughness)) !== null && _c !== void 0 ? _c : undefined;\n }\n else if (babylonMaterial.sheen.texture && babylonMaterial.sheen.useRoughnessFromMainTexture) {\n sheenInfo.sheenRoughnessTexture = (_d = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture)) !== null && _d !== void 0 ? _d : undefined;\n }\n node.extensions[NAME$5] = sheenInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$5, (exporter) => new KHR_materials_sheen(exporter));\n\n const NAME$6 = \"KHR_materials_unlit\";\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_unlit {\n constructor() {\n /** Name of this extension */\n this.name = NAME$6;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n dispose() { }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n let unlitMaterial = false;\n if (babylonMaterial instanceof PBRMaterial) {\n unlitMaterial = babylonMaterial.unlit;\n }\n else if (babylonMaterial instanceof StandardMaterial) {\n unlitMaterial = babylonMaterial.disableLighting;\n }\n if (unlitMaterial) {\n this._wasUsed = true;\n if (node.extensions == null) {\n node.extensions = {};\n }\n node.extensions[NAME$6] = {};\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$6, () => new KHR_materials_unlit());\n\n const NAME$7 = \"KHR_materials_ior\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_ior/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_ior {\n constructor() {\n /** Name of this extension */\n this.name = NAME$7;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n _isExtensionEnabled(mat) {\n // This extension must not be used on a material that also uses KHR_materials_unlit\n if (mat.unlit) {\n return false;\n }\n return mat.indexOfRefraction != undefined && mat.indexOfRefraction != 1.5; // 1.5 is normative default value.\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\n this._wasUsed = true;\n const iorInfo = {\n ior: babylonMaterial.indexOfRefraction,\n };\n node.extensions = node.extensions || {};\n node.extensions[NAME$7] = iorInfo;\n }\n resolve(node);\n });\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _Exporter.RegisterExtension(NAME$7, (exporter) => new KHR_materials_ior());\n\n const NAME$8 = \"KHR_materials_specular\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_specular {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$8;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n const additionalTextures = [];\n if (babylonMaterial instanceof PBRMaterial) {\n if (this._isExtensionEnabled(babylonMaterial)) {\n if (babylonMaterial.metallicReflectanceTexture) {\n additionalTextures.push(babylonMaterial.metallicReflectanceTexture);\n }\n if (babylonMaterial.reflectanceTexture) {\n additionalTextures.push(babylonMaterial.reflectanceTexture);\n }\n return additionalTextures;\n }\n }\n return additionalTextures;\n }\n _isExtensionEnabled(mat) {\n // This extension must not be used on a material that also uses KHR_materials_unlit\n if (mat.unlit) {\n return false;\n }\n return ((mat.metallicF0Factor != undefined && mat.metallicF0Factor != 1.0) ||\n (mat.metallicReflectanceColor != undefined && !mat.metallicReflectanceColor.equalsFloats(1.0, 1.0, 1.0)) ||\n this._hasTexturesExtension(mat));\n }\n _hasTexturesExtension(mat) {\n return mat.metallicReflectanceTexture != null || mat.reflectanceTexture != null;\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n var _a, _b;\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\n this._wasUsed = true;\n node.extensions = node.extensions || {};\n const metallicReflectanceTexture = (_a = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.metallicReflectanceTexture)) !== null && _a !== void 0 ? _a : undefined;\n const reflectanceTexture = (_b = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.reflectanceTexture)) !== null && _b !== void 0 ? _b : undefined;\n const metallicF0Factor = babylonMaterial.metallicF0Factor == 1.0 ? undefined : babylonMaterial.metallicF0Factor;\n const metallicReflectanceColor = babylonMaterial.metallicReflectanceColor.equalsFloats(1.0, 1.0, 1.0)\n ? undefined\n : babylonMaterial.metallicReflectanceColor.asArray();\n const specularInfo = {\n specularFactor: metallicF0Factor,\n specularTexture: metallicReflectanceTexture,\n specularColorFactor: metallicReflectanceColor,\n specularColorTexture: reflectanceTexture,\n hasTextures: () => {\n return this._hasTexturesExtension(babylonMaterial);\n },\n };\n node.extensions[NAME$8] = specularInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$8, (exporter) => new KHR_materials_specular(exporter));\n\n const NAME$9 = \"KHR_materials_volume\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_volume {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$9;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n const additionalTextures = [];\n if (babylonMaterial instanceof PBRMaterial) {\n if (this._isExtensionEnabled(babylonMaterial)) {\n if (babylonMaterial.subSurface.thicknessTexture) {\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\n }\n return additionalTextures;\n }\n }\n return additionalTextures;\n }\n _isExtensionEnabled(mat) {\n // This extension must not be used on a material that also uses KHR_materials_unlit\n if (mat.unlit) {\n return false;\n }\n const subs = mat.subSurface;\n // this extension requires either the KHR_materials_transmission or KHR_materials_translucency extensions.\n if (!subs.isRefractionEnabled && !subs.isTranslucencyEnabled) {\n return false;\n }\n return ((subs.maximumThickness != undefined && subs.maximumThickness != 0) ||\n (subs.tintColorAtDistance != undefined && subs.tintColorAtDistance != Number.POSITIVE_INFINITY) ||\n (subs.tintColor != undefined && subs.tintColor != Color3.White()) ||\n this._hasTexturesExtension(mat));\n }\n _hasTexturesExtension(mat) {\n return mat.subSurface.thicknessTexture != null;\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n var _a;\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\n this._wasUsed = true;\n const subs = babylonMaterial.subSurface;\n const thicknessFactor = subs.maximumThickness == 0 ? undefined : subs.maximumThickness;\n const thicknessTexture = (_a = this._exporter._glTFMaterialExporter._getTextureInfo(subs.thicknessTexture)) !== null && _a !== void 0 ? _a : undefined;\n const attenuationDistance = subs.tintColorAtDistance == Number.POSITIVE_INFINITY ? undefined : subs.tintColorAtDistance;\n const attenuationColor = subs.tintColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.tintColor.asArray();\n const volumeInfo = {\n thicknessFactor: thicknessFactor,\n thicknessTexture: thicknessTexture,\n attenuationDistance: attenuationDistance,\n attenuationColor: attenuationColor,\n hasTextures: () => {\n return this._hasTexturesExtension(babylonMaterial);\n },\n };\n node.extensions = node.extensions || {};\n node.extensions[NAME$9] = volumeInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$9, (exporter) => new KHR_materials_volume(exporter));\n\n const NAME$a = \"KHR_materials_transmission\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_transmission {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$a;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAdditionalTextures(context, node, babylonMaterial) {\n const additionalTextures = [];\n if (babylonMaterial instanceof PBRMaterial) {\n if (this._isExtensionEnabled(babylonMaterial)) {\n if (babylonMaterial.subSurface.thicknessTexture) {\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\n }\n return additionalTextures;\n }\n }\n return additionalTextures;\n }\n _isExtensionEnabled(mat) {\n // This extension must not be used on a material that also uses KHR_materials_unlit\n if (mat.unlit) {\n return false;\n }\n const subs = mat.subSurface;\n return (subs.isRefractionEnabled && subs.refractionIntensity != undefined && subs.refractionIntensity != 0) || this._hasTexturesExtension(mat);\n }\n _hasTexturesExtension(mat) {\n return mat.subSurface.refractionIntensityTexture != null;\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n var _a;\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\n this._wasUsed = true;\n const subs = babylonMaterial.subSurface;\n const transmissionFactor = subs.refractionIntensity === 0 ? undefined : subs.refractionIntensity;\n const transmissionTexture = (_a = this._exporter._glTFMaterialExporter._getTextureInfo(subs.refractionIntensityTexture)) !== null && _a !== void 0 ? _a : undefined;\n const volumeInfo = {\n transmissionFactor: transmissionFactor,\n transmissionTexture: transmissionTexture,\n hasTextures: () => {\n return this._hasTexturesExtension(babylonMaterial);\n },\n };\n node.extensions = node.extensions || {};\n node.extensions[NAME$a] = volumeInfo;\n }\n resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$a, (exporter) => new KHR_materials_transmission(exporter));\n\n Mesh.prototype.thinInstanceAdd = function (matrix, refresh = true) {\n if (!this.getScene().getEngine().getCaps().instancedArrays) {\n Logger.Error(\"Thin Instances are not supported on this device as Instanced Array extension not supported\");\n return -1;\n }\n this._thinInstanceUpdateBufferSize(\"matrix\", Array.isArray(matrix) ? matrix.length : 1);\n const index = this._thinInstanceDataStorage.instancesCount;\n if (Array.isArray(matrix)) {\n for (let i = 0; i < matrix.length; ++i) {\n this.thinInstanceSetMatrixAt(this._thinInstanceDataStorage.instancesCount++, matrix[i], i === matrix.length - 1 && refresh);\n }\n }\n else {\n this.thinInstanceSetMatrixAt(this._thinInstanceDataStorage.instancesCount++, matrix, refresh);\n }\n return index;\n };\n Mesh.prototype.thinInstanceAddSelf = function (refresh = true) {\n return this.thinInstanceAdd(Matrix.IdentityReadOnly, refresh);\n };\n Mesh.prototype.thinInstanceRegisterAttribute = function (kind, stride) {\n // preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n this.removeVerticesData(kind);\n this._thinInstanceInitializeUserStorage();\n this._userThinInstanceBuffersStorage.strides[kind] = stride;\n this._userThinInstanceBuffersStorage.sizes[kind] = stride * Math.max(32, this._thinInstanceDataStorage.instancesCount); // Initial size\n this._userThinInstanceBuffersStorage.data[kind] = new Float32Array(this._userThinInstanceBuffersStorage.sizes[kind]);\n this._userThinInstanceBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), this._userThinInstanceBuffersStorage.data[kind], kind, true, false, stride, true);\n this.setVerticesBuffer(this._userThinInstanceBuffersStorage.vertexBuffers[kind]);\n };\n Mesh.prototype.thinInstanceSetMatrixAt = function (index, matrix, refresh = true) {\n if (!this._thinInstanceDataStorage.matrixData || index >= this._thinInstanceDataStorage.instancesCount) {\n return false;\n }\n const matrixData = this._thinInstanceDataStorage.matrixData;\n matrix.copyToArray(matrixData, index * 16);\n if (this._thinInstanceDataStorage.worldMatrices) {\n this._thinInstanceDataStorage.worldMatrices[index] = matrix;\n }\n if (refresh) {\n this.thinInstanceBufferUpdated(\"matrix\");\n if (!this.doNotSyncBoundingInfo) {\n this.thinInstanceRefreshBoundingInfo(false);\n }\n }\n return true;\n };\n Mesh.prototype.thinInstanceSetAttributeAt = function (kind, index, value, refresh = true) {\n // preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n if (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.data[kind] || index >= this._thinInstanceDataStorage.instancesCount) {\n return false;\n }\n this._thinInstanceUpdateBufferSize(kind, 0); // make sur the buffer for the kind attribute is big enough\n this._userThinInstanceBuffersStorage.data[kind].set(value, index * this._userThinInstanceBuffersStorage.strides[kind]);\n if (refresh) {\n this.thinInstanceBufferUpdated(kind);\n }\n return true;\n };\n Object.defineProperty(Mesh.prototype, \"thinInstanceCount\", {\n get: function () {\n return this._thinInstanceDataStorage.instancesCount;\n },\n set: function (value) {\n var _a, _b;\n const matrixData = (_a = this._thinInstanceDataStorage.matrixData) !== null && _a !== void 0 ? _a : (_b = this.source) === null || _b === void 0 ? void 0 : _b._thinInstanceDataStorage.matrixData;\n const numMaxInstances = matrixData ? matrixData.length / 16 : 0;\n if (value <= numMaxInstances) {\n this._thinInstanceDataStorage.instancesCount = value;\n }\n },\n enumerable: true,\n configurable: true,\n });\n Mesh.prototype._thinInstanceCreateMatrixBuffer = function (kind, buffer, staticBuffer = false) {\n // preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n const matrixBuffer = new Buffer$1(this.getEngine(), buffer, !staticBuffer, 16, false, true);\n for (let i = 0; i < 4; i++) {\n this.setVerticesBuffer(matrixBuffer.createVertexBuffer(kind + i, i * 4, 4));\n }\n return matrixBuffer;\n };\n Mesh.prototype.thinInstanceSetBuffer = function (kind, buffer, stride = 0, staticBuffer = false) {\n var _a, _b, _c;\n stride = stride || 16;\n if (kind === \"matrix\") {\n (_a = this._thinInstanceDataStorage.matrixBuffer) === null || _a === void 0 ? void 0 : _a.dispose();\n this._thinInstanceDataStorage.matrixBuffer = null;\n this._thinInstanceDataStorage.matrixBufferSize = buffer ? buffer.length : 32 * stride;\n this._thinInstanceDataStorage.matrixData = buffer;\n this._thinInstanceDataStorage.worldMatrices = null;\n if (buffer !== null) {\n this._thinInstanceDataStorage.instancesCount = buffer.length / stride;\n this._thinInstanceDataStorage.matrixBuffer = this._thinInstanceCreateMatrixBuffer(\"world\", buffer, staticBuffer);\n if (!this.doNotSyncBoundingInfo) {\n this.thinInstanceRefreshBoundingInfo(false);\n }\n }\n else {\n this._thinInstanceDataStorage.instancesCount = 0;\n if (!this.doNotSyncBoundingInfo) {\n // mesh has no more thin instances, so need to recompute the bounding box because it's the regular mesh that will now be displayed\n this.refreshBoundingInfo();\n }\n }\n }\n else if (kind === \"previousMatrix\") {\n (_b = this._thinInstanceDataStorage.previousMatrixBuffer) === null || _b === void 0 ? void 0 : _b.dispose();\n this._thinInstanceDataStorage.previousMatrixBuffer = null;\n this._thinInstanceDataStorage.previousMatrixData = buffer;\n if (buffer !== null) {\n this._thinInstanceDataStorage.previousMatrixBuffer = this._thinInstanceCreateMatrixBuffer(\"previousWorld\", buffer, staticBuffer);\n }\n }\n else {\n // color for instanced mesh is ColorInstanceKind and not ColorKind because of native that needs to do the differenciation\n // hot switching kind here to preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n if (buffer === null) {\n if ((_c = this._userThinInstanceBuffersStorage) === null || _c === void 0 ? void 0 : _c.data[kind]) {\n this.removeVerticesData(kind);\n delete this._userThinInstanceBuffersStorage.data[kind];\n delete this._userThinInstanceBuffersStorage.strides[kind];\n delete this._userThinInstanceBuffersStorage.sizes[kind];\n delete this._userThinInstanceBuffersStorage.vertexBuffers[kind];\n }\n }\n else {\n this._thinInstanceInitializeUserStorage();\n this._userThinInstanceBuffersStorage.data[kind] = buffer;\n this._userThinInstanceBuffersStorage.strides[kind] = stride;\n this._userThinInstanceBuffersStorage.sizes[kind] = buffer.length;\n this._userThinInstanceBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), buffer, kind, !staticBuffer, false, stride, true);\n this.setVerticesBuffer(this._userThinInstanceBuffersStorage.vertexBuffers[kind]);\n }\n }\n };\n Mesh.prototype.thinInstanceBufferUpdated = function (kind) {\n var _a, _b, _c;\n if (kind === \"matrix\") {\n (_a = this._thinInstanceDataStorage.matrixBuffer) === null || _a === void 0 ? void 0 : _a.updateDirectly(this._thinInstanceDataStorage.matrixData, 0, this._thinInstanceDataStorage.instancesCount);\n }\n else if (kind === \"previousMatrix\") {\n (_b = this._thinInstanceDataStorage.previousMatrixBuffer) === null || _b === void 0 ? void 0 : _b.updateDirectly(this._thinInstanceDataStorage.previousMatrixData, 0, this._thinInstanceDataStorage.instancesCount);\n }\n else {\n // preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n if ((_c = this._userThinInstanceBuffersStorage) === null || _c === void 0 ? void 0 : _c.vertexBuffers[kind]) {\n this._userThinInstanceBuffersStorage.vertexBuffers[kind].updateDirectly(this._userThinInstanceBuffersStorage.data[kind], 0);\n }\n }\n };\n Mesh.prototype.thinInstancePartialBufferUpdate = function (kind, data, offset) {\n var _a;\n if (kind === \"matrix\") {\n if (this._thinInstanceDataStorage.matrixBuffer) {\n this._thinInstanceDataStorage.matrixBuffer.updateDirectly(data, offset);\n }\n }\n else {\n // preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n if ((_a = this._userThinInstanceBuffersStorage) === null || _a === void 0 ? void 0 : _a.vertexBuffers[kind]) {\n this._userThinInstanceBuffersStorage.vertexBuffers[kind].updateDirectly(data, offset);\n }\n }\n };\n Mesh.prototype.thinInstanceGetWorldMatrices = function () {\n if (!this._thinInstanceDataStorage.matrixData || !this._thinInstanceDataStorage.matrixBuffer) {\n return [];\n }\n const matrixData = this._thinInstanceDataStorage.matrixData;\n if (!this._thinInstanceDataStorage.worldMatrices) {\n this._thinInstanceDataStorage.worldMatrices = new Array();\n for (let i = 0; i < this._thinInstanceDataStorage.instancesCount; ++i) {\n this._thinInstanceDataStorage.worldMatrices[i] = Matrix.FromArray(matrixData, i * 16);\n }\n }\n return this._thinInstanceDataStorage.worldMatrices;\n };\n Mesh.prototype.thinInstanceRefreshBoundingInfo = function (forceRefreshParentInfo = false, applySkeleton = false, applyMorph = false) {\n if (!this._thinInstanceDataStorage.matrixData || !this._thinInstanceDataStorage.matrixBuffer) {\n return;\n }\n const vectors = this._thinInstanceDataStorage.boundingVectors;\n if (forceRefreshParentInfo || !this.rawBoundingInfo) {\n vectors.length = 0;\n this.refreshBoundingInfo(applySkeleton, applyMorph);\n const boundingInfo = this.getBoundingInfo();\n this.rawBoundingInfo = new BoundingInfo(boundingInfo.minimum, boundingInfo.maximum);\n }\n const boundingInfo = this.getBoundingInfo();\n const matrixData = this._thinInstanceDataStorage.matrixData;\n if (vectors.length === 0) {\n for (let v = 0; v < boundingInfo.boundingBox.vectors.length; ++v) {\n vectors.push(boundingInfo.boundingBox.vectors[v].clone());\n }\n }\n TmpVectors.Vector3[0].setAll(Number.POSITIVE_INFINITY); // min\n TmpVectors.Vector3[1].setAll(Number.NEGATIVE_INFINITY); // max\n for (let i = 0; i < this._thinInstanceDataStorage.instancesCount; ++i) {\n Matrix.FromArrayToRef(matrixData, i * 16, TmpVectors.Matrix[0]);\n for (let v = 0; v < vectors.length; ++v) {\n Vector3.TransformCoordinatesToRef(vectors[v], TmpVectors.Matrix[0], TmpVectors.Vector3[2]);\n TmpVectors.Vector3[0].minimizeInPlace(TmpVectors.Vector3[2]);\n TmpVectors.Vector3[1].maximizeInPlace(TmpVectors.Vector3[2]);\n }\n }\n boundingInfo.reConstruct(TmpVectors.Vector3[0], TmpVectors.Vector3[1]);\n this._updateBoundingInfo();\n };\n Mesh.prototype._thinInstanceUpdateBufferSize = function (kind, numInstances = 1) {\n var _a, _b, _c;\n // preserve backward compatibility\n if (kind === VertexBuffer.ColorKind) {\n kind = VertexBuffer.ColorInstanceKind;\n }\n const kindIsMatrix = kind === \"matrix\";\n if (!kindIsMatrix && (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.strides[kind])) {\n return;\n }\n const stride = kindIsMatrix ? 16 : this._userThinInstanceBuffersStorage.strides[kind];\n const currentSize = kindIsMatrix ? this._thinInstanceDataStorage.matrixBufferSize : this._userThinInstanceBuffersStorage.sizes[kind];\n let data = kindIsMatrix ? this._thinInstanceDataStorage.matrixData : this._userThinInstanceBuffersStorage.data[kind];\n const bufferSize = (this._thinInstanceDataStorage.instancesCount + numInstances) * stride;\n let newSize = currentSize;\n while (newSize < bufferSize) {\n newSize *= 2;\n }\n if (!data || currentSize != newSize) {\n if (!data) {\n data = new Float32Array(newSize);\n }\n else {\n const newData = new Float32Array(newSize);\n newData.set(data, 0);\n data = newData;\n }\n if (kindIsMatrix) {\n (_a = this._thinInstanceDataStorage.matrixBuffer) === null || _a === void 0 ? void 0 : _a.dispose();\n this._thinInstanceDataStorage.matrixBuffer = this._thinInstanceCreateMatrixBuffer(\"world\", data, false);\n this._thinInstanceDataStorage.matrixData = data;\n this._thinInstanceDataStorage.matrixBufferSize = newSize;\n if (this._scene.needsPreviousWorldMatrices && !this._thinInstanceDataStorage.previousMatrixData) {\n (_b = this._thinInstanceDataStorage.previousMatrixBuffer) === null || _b === void 0 ? void 0 : _b.dispose();\n this._thinInstanceDataStorage.previousMatrixBuffer = this._thinInstanceCreateMatrixBuffer(\"previousWorld\", data, false);\n }\n }\n else {\n (_c = this._userThinInstanceBuffersStorage.vertexBuffers[kind]) === null || _c === void 0 ? void 0 : _c.dispose();\n this._userThinInstanceBuffersStorage.data[kind] = data;\n this._userThinInstanceBuffersStorage.sizes[kind] = newSize;\n this._userThinInstanceBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), data, kind, true, false, stride, true);\n this.setVerticesBuffer(this._userThinInstanceBuffersStorage.vertexBuffers[kind]);\n }\n }\n };\n Mesh.prototype._thinInstanceInitializeUserStorage = function () {\n if (!this._userThinInstanceBuffersStorage) {\n this._userThinInstanceBuffersStorage = {\n data: {},\n sizes: {},\n vertexBuffers: {},\n strides: {},\n };\n }\n };\n Mesh.prototype._disposeThinInstanceSpecificData = function () {\n var _a;\n if ((_a = this._thinInstanceDataStorage) === null || _a === void 0 ? void 0 : _a.matrixBuffer) {\n this._thinInstanceDataStorage.matrixBuffer.dispose();\n this._thinInstanceDataStorage.matrixBuffer = null;\n }\n };\n\n const NAME$b = \"EXT_mesh_gpu_instancing\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class EXT_mesh_gpu_instancing {\n constructor(exporter) {\n /** Name of this extension */\n this.name = NAME$b;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n this._exporter = exporter;\n }\n dispose() { }\n /** @internal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter) {\n return new Promise((resolve) => {\n if (node && babylonNode instanceof Mesh) {\n if (babylonNode.hasThinInstances && binaryWriter) {\n this._wasUsed = true;\n const noTranslation = Vector3.Zero();\n const noRotation = Quaternion.Identity();\n const noScale = Vector3.One();\n // retreive all the instance world matrix\n const matrix = babylonNode.thinInstanceGetWorldMatrices();\n const iwt = TmpVectors.Vector3[2];\n const iwr = TmpVectors.Quaternion[1];\n const iws = TmpVectors.Vector3[3];\n let hasAnyInstanceWorldTranslation = false;\n let hasAnyInstanceWorldRotation = false;\n let hasAnyInstanceWorldScale = false;\n // prepare temp buffers\n const translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\n const rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);\n const scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\n let i = 0;\n for (const m of matrix) {\n m.decompose(iws, iwr, iwt);\n // fill the temp buffer\n translationBuffer.set(iwt.asArray(), i * 3);\n rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized\n scaleBuffer.set(iws.asArray(), i * 3);\n // this is where we decide if there is any transformation\n hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);\n hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);\n hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);\n i++;\n }\n const extension = {\n attributes: {},\n };\n // do we need to write TRANSLATION ?\n if (hasAnyInstanceWorldTranslation) {\n extension.attributes[\"TRANSLATION\"] = this._buildAccessor(translationBuffer, \"VEC3\" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* AccessorComponentType.FLOAT */);\n }\n // do we need to write ROTATION ?\n if (hasAnyInstanceWorldRotation) {\n const componentType = 5126 /* AccessorComponentType.FLOAT */; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495\n extension.attributes[\"ROTATION\"] = this._buildAccessor(rotationBuffer, \"VEC4\" /* AccessorType.VEC4 */, babylonNode.thinInstanceCount, binaryWriter, componentType);\n }\n // do we need to write SCALE ?\n if (hasAnyInstanceWorldScale) {\n extension.attributes[\"SCALE\"] = this._buildAccessor(scaleBuffer, \"VEC3\" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* AccessorComponentType.FLOAT */);\n }\n /* eslint-enable @typescript-eslint/naming-convention*/\n node.extensions = node.extensions || {};\n node.extensions[NAME$b] = extension;\n }\n }\n resolve(node);\n });\n }\n _buildAccessor(buffer, type, count, binaryWriter, componentType) {\n // write the buffer\n const bufferOffset = binaryWriter.getByteOffset();\n switch (componentType) {\n case 5126 /* AccessorComponentType.FLOAT */: {\n for (let i = 0; i != buffer.length; i++) {\n binaryWriter.setFloat32(buffer[i]);\n }\n break;\n }\n case 5120 /* AccessorComponentType.BYTE */: {\n for (let i = 0; i != buffer.length; i++) {\n binaryWriter.setByte(buffer[i] * 127);\n }\n break;\n }\n case 5122 /* AccessorComponentType.SHORT */: {\n for (let i = 0; i != buffer.length; i++) {\n binaryWriter.setInt16(buffer[i] * 32767);\n }\n break;\n }\n }\n // build the buffer view\n const bv = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };\n const bufferViewIndex = this._exporter._bufferViews.length;\n this._exporter._bufferViews.push(bv);\n // finally build the accessor\n const accessorIndex = this._exporter._accessors.length;\n const accessor = {\n bufferView: bufferViewIndex,\n componentType: componentType,\n count: count,\n type: type,\n normalized: componentType == 5120 /* AccessorComponentType.BYTE */ || componentType == 5122 /* AccessorComponentType.SHORT */,\n };\n this._exporter._accessors.push(accessor);\n return accessorIndex;\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _Exporter.RegisterExtension(NAME$b, (exporter) => new EXT_mesh_gpu_instancing(exporter));\n\n const NAME$c = \"KHR_materials_emissive_strength\";\n /**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class KHR_materials_emissive_strength {\n constructor() {\n /** Name of this extension */\n this.name = NAME$c;\n /** Defines whether this extension is enabled */\n this.enabled = true;\n /** Defines whether this extension is required */\n this.required = false;\n this._wasUsed = false;\n }\n dispose() { }\n /** @interal */\n get wasUsed() {\n return this._wasUsed;\n }\n postExportMaterialAsync(context, node, babylonMaterial) {\n return new Promise((resolve) => {\n if (!(babylonMaterial instanceof PBRMaterial)) {\n return resolve(node);\n }\n const emissiveColor = babylonMaterial.emissiveColor.asArray();\n const tempEmissiveStrength = Math.max(...emissiveColor);\n if (tempEmissiveStrength > 1) {\n this._wasUsed = true;\n node.extensions || (node.extensions = {});\n const emissiveStrengthInfo = {\n emissiveStrength: tempEmissiveStrength,\n };\n // Normalize each value of the emissive factor to have a max value of 1\n const newEmissiveFactor = babylonMaterial.emissiveColor.scale(1 / emissiveStrengthInfo.emissiveStrength);\n node.emissiveFactor = newEmissiveFactor.asArray();\n node.extensions[NAME$c] = emissiveStrengthInfo;\n }\n return resolve(node);\n });\n }\n }\n _Exporter.RegisterExtension(NAME$c, (exporter) => new KHR_materials_emissive_strength());\n\n class GLTFKb3dExporter {\n constructor(scene) {\n this.scene = scene;\n this._glbExportOptions = {\n shouldExportNode: n => this.shouldExportNode(n),\n };\n }\n /** generates the current scene into a glb file and returns an object url for it */\n generateGlb(filename = 'scene') {\n return GLTF2Export.GLBAsync(this.scene, filename, this._glbExportOptions).then(glbData => {\n return this.createGlbBlob(glbData);\n });\n }\n exportGlb(filename = 'scene') {\n return GLTF2Export.GLBAsync(this.scene, filename, this._glbExportOptions).then(glbData => {\n const dispose = this.downloadBlob(`${filename}.glb`, this.createGlbBlob(glbData));\n setTimeout(() => dispose());\n });\n }\n exportGltf(filename = 'scene') {\n return GLTF2Export.GLTFAsync(this.scene, filename, this._glbExportOptions).then(glbData => {\n const disposeFuncs = [];\n for (const key in glbData.glTFFiles) {\n const blob = glbData.glTFFiles[key];\n let mimeType;\n if (endsWith(key, '.glb')) {\n mimeType = { type: 'model/gltf-binary' };\n }\n else if (endsWith(key, '.bin')) {\n mimeType = { type: 'application/octet-stream' };\n }\n else if (endsWith(key, '.gltf')) {\n mimeType = { type: 'model/gltf+json' };\n }\n else if (endsWith(key, '.jpeg') || endsWith(key, '.jpg')) {\n mimeType = { type: 'image/jpeg' /* ImageMimeType.JPEG */ };\n }\n else if (endsWith(key, '.png')) {\n mimeType = { type: 'image/png' /* ImageMimeType.PNG */ };\n }\n disposeFuncs.push(this.downloadBlob(key, new Blob([blob], mimeType)));\n }\n setTimeout(() => disposeFuncs.forEach(dispose => dispose()));\n });\n function endsWith(str, suffix) {\n return str.indexOf(suffix, str.length - suffix.length) !== -1;\n }\n }\n shouldExportNode(node) {\n const kb3dNode = getByDynamicId(node.id);\n if (kb3dNode instanceof exports.Connector) {\n return false;\n }\n else if (kb3dNode instanceof exports.ViewpointNode) {\n return false;\n }\n return kb3dNode != null;\n }\n createGlbBlob(glbData) {\n //we're expecting one file since it's a GLB\n const key = Object.keys(glbData.glTFFiles)[0];\n const blob = glbData.glTFFiles[key];\n const mimeType = { type: 'model/gltf-binary' };\n return new Blob([blob], mimeType);\n }\n downloadBlob(fileName, blob) {\n const link = document.createElement('a');\n document.body.appendChild(link);\n link.setAttribute('type', 'hidden');\n link.download = fileName;\n link.href = window.URL.createObjectURL(blob);\n link.click();\n return dispose;\n function dispose() {\n window.URL.revokeObjectURL(link.href);\n link.remove();\n }\n }\n }\n\n /**\n * This represents a color grading texture. This acts as a lookup table LUT, useful during post process\n * It can help converting any input color in a desired output one. This can then be used to create effects\n * from sepia, black and white to sixties or futuristic rendering...\n *\n * The only supported format is currently 3dl.\n * More information on LUT: https://en.wikipedia.org/wiki/3D_lookup_table\n */\n class ColorGradingTexture extends BaseTexture {\n /**\n * Instantiates a ColorGradingTexture from the following parameters.\n *\n * @param url The location of the color grading data (currently only supporting 3dl)\n * @param sceneOrEngine The scene or engine the texture will be used in\n * @param onLoad defines a callback triggered when the texture has been loaded\n */\n constructor(url, sceneOrEngine, onLoad = null) {\n super(sceneOrEngine);\n if (!url) {\n return;\n }\n this._textureMatrix = Matrix.Identity();\n this.name = url;\n this.url = url;\n this._onLoad = onLoad;\n this._texture = this._getFromCache(url, true);\n if (!this._texture) {\n const scene = this.getScene();\n if (scene) {\n if (!scene.useDelayedTextureLoading) {\n this._loadTexture();\n }\n else {\n this.delayLoadState = 4;\n }\n }\n else {\n this._loadTexture();\n }\n }\n else {\n this._triggerOnLoad();\n }\n }\n /**\n * Fires the onload event from the constructor if requested.\n */\n _triggerOnLoad() {\n if (this._onLoad) {\n this._onLoad();\n }\n }\n /**\n * Returns the texture matrix used in most of the material.\n * This is not used in color grading but keep for troubleshooting purpose (easily swap diffuse by colorgrading to look in).\n */\n getTextureMatrix() {\n return this._textureMatrix;\n }\n /**\n * Occurs when the file being loaded is a .3dl LUT file.\n */\n _load3dlTexture() {\n const engine = this._getEngine();\n let texture;\n if (!engine._features.support3DTextures) {\n texture = engine.createRawTexture(null, 1, 1, 5, false, false, 2, null, 0);\n }\n else {\n texture = engine.createRawTexture3D(null, 1, 1, 1, 5, false, false, 2, null, 0);\n }\n this._texture = texture;\n this._texture.isReady = false;\n this.isCube = false;\n this.is3D = engine._features.support3DTextures;\n this.wrapU = 0;\n this.wrapV = 0;\n this.wrapR = 0;\n this.anisotropicFilteringLevel = 1;\n const callback = (text) => {\n if (typeof text !== \"string\") {\n return;\n }\n let data = null;\n let tempData = null;\n let line;\n const lines = text.split(\"\\n\");\n let size = 0, pixelIndexW = 0, pixelIndexH = 0, pixelIndexSlice = 0;\n let maxColor = 0;\n for (let i = 0; i < lines.length; i++) {\n line = lines[i];\n if (!ColorGradingTexture._NoneEmptyLineRegex.test(line)) {\n continue;\n }\n if (line.indexOf(\"#\") === 0) {\n continue;\n }\n const words = line.split(\" \");\n if (size === 0) {\n // Number of space + one\n size = words.length;\n data = new Uint8Array(size * size * size * 4); // volume texture of side size and rgb 8\n tempData = new Float32Array(size * size * size * 4);\n continue;\n }\n if (size != 0) {\n const r = Math.max(parseInt(words[0]), 0);\n const g = Math.max(parseInt(words[1]), 0);\n const b = Math.max(parseInt(words[2]), 0);\n maxColor = Math.max(r, maxColor);\n maxColor = Math.max(g, maxColor);\n maxColor = Math.max(b, maxColor);\n const pixelStorageIndex = (pixelIndexW + pixelIndexSlice * size + pixelIndexH * size * size) * 4;\n if (tempData) {\n tempData[pixelStorageIndex + 0] = r;\n tempData[pixelStorageIndex + 1] = g;\n tempData[pixelStorageIndex + 2] = b;\n }\n // Keep for reference in case of back compat problems.\n // pixelIndexSlice++;\n // if (pixelIndexSlice % size == 0) {\n // pixelIndexH++;\n // pixelIndexSlice = 0;\n // if (pixelIndexH % size == 0) {\n // pixelIndexW++;\n // pixelIndexH = 0;\n // }\n // }\n pixelIndexH++;\n if (pixelIndexH % size == 0) {\n pixelIndexSlice++;\n pixelIndexH = 0;\n if (pixelIndexSlice % size == 0) {\n pixelIndexW++;\n pixelIndexSlice = 0;\n }\n }\n }\n }\n if (tempData && data) {\n for (let i = 0; i < tempData.length; i++) {\n if (i > 0 && (i + 1) % 4 === 0) {\n data[i] = 255;\n }\n else {\n const value = tempData[i];\n data[i] = (value / maxColor) * 255;\n }\n }\n }\n if (texture.is3D) {\n texture.updateSize(size, size, size);\n engine.updateRawTexture3D(texture, data, 5, false);\n }\n else {\n texture.updateSize(size * size, size);\n engine.updateRawTexture(texture, data, 5, false);\n }\n texture.isReady = true;\n this._triggerOnLoad();\n };\n const scene = this.getScene();\n if (scene) {\n scene._loadFile(this.url, callback);\n }\n else {\n engine._loadFile(this.url, callback);\n }\n return this._texture;\n }\n /**\n * Starts the loading process of the texture.\n */\n _loadTexture() {\n if (this.url && this.url.toLocaleLowerCase().indexOf(\".3dl\") == this.url.length - 4) {\n this._load3dlTexture();\n }\n }\n /**\n * Clones the color grading texture.\n */\n clone() {\n const newTexture = new ColorGradingTexture(this.url, this.getScene() || this._getEngine());\n // Base texture\n newTexture.level = this.level;\n return newTexture;\n }\n /**\n * Called during delayed load for textures.\n */\n delayLoad() {\n if (this.delayLoadState !== 4) {\n return;\n }\n this.delayLoadState = 1;\n this._texture = this._getFromCache(this.url, true);\n if (!this._texture) {\n this._loadTexture();\n }\n }\n /**\n * Parses a color grading texture serialized by Babylon.\n * @param parsedTexture The texture information being parsedTexture\n * @param scene The scene to load the texture in\n * @returns A color grading texture\n */\n static Parse(parsedTexture, scene) {\n let texture = null;\n if (parsedTexture.name && !parsedTexture.isRenderTarget) {\n texture = new ColorGradingTexture(parsedTexture.name, scene);\n texture.name = parsedTexture.name;\n texture.level = parsedTexture.level;\n }\n return texture;\n }\n /**\n * Serializes the LUT texture to json format.\n */\n serialize() {\n if (!this.name) {\n return null;\n }\n const serializationObject = {};\n serializationObject.name = this.name;\n serializationObject.level = this.level;\n serializationObject.customType = \"BABYLON.ColorGradingTexture\";\n return serializationObject;\n }\n }\n /**\n * Empty line regex stored for GC.\n */\n ColorGradingTexture._NoneEmptyLineRegex = /\\S+/;\n RegisterClass(\"BABYLON.ColorGradingTexture\", ColorGradingTexture);\n\n /**\n * Helper class useful to convert panorama picture to their cubemap representation in 6 faces.\n */\n class PanoramaToCubeMapTools {\n /**\n * Converts a panorama stored in RGB right to left up to down format into a cubemap (6 faces).\n *\n * @param float32Array The source data.\n * @param inputWidth The width of the input panorama.\n * @param inputHeight The height of the input panorama.\n * @param size The willing size of the generated cubemap (each faces will be size * size pixels)\n * @returns The cubemap data\n */\n static ConvertPanoramaToCubemap(float32Array, inputWidth, inputHeight, size, supersample = false) {\n if (!float32Array) {\n throw \"ConvertPanoramaToCubemap: input cannot be null\";\n }\n if (float32Array.length != inputWidth * inputHeight * 3) {\n throw \"ConvertPanoramaToCubemap: input size is wrong\";\n }\n const textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight, supersample);\n const textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight, supersample);\n const textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight, supersample);\n const textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight, supersample);\n const textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight, supersample);\n const textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight, supersample);\n return {\n front: textureFront,\n back: textureBack,\n left: textureLeft,\n right: textureRight,\n up: textureUp,\n down: textureDown,\n size: size,\n type: 1,\n format: 4,\n gammaSpace: false,\n };\n }\n static CreateCubemapTexture(texSize, faceData, float32Array, inputWidth, inputHeight, supersample = false) {\n const buffer = new ArrayBuffer(texSize * texSize * 4 * 3);\n const textureArray = new Float32Array(buffer);\n // If supersampling, determine number of samples needed when source texture width is divided for 4 cube faces\n const samples = supersample ? Math.max(1, Math.round(inputWidth / 4 / texSize)) : 1;\n const sampleFactor = 1 / samples;\n const sampleFactorSqr = sampleFactor * sampleFactor;\n const rotDX1 = faceData[1].subtract(faceData[0]).scale(sampleFactor / texSize);\n const rotDX2 = faceData[3].subtract(faceData[2]).scale(sampleFactor / texSize);\n const dy = 1 / texSize;\n let fy = 0;\n for (let y = 0; y < texSize; y++) {\n for (let sy = 0; sy < samples; sy++) {\n let xv1 = faceData[0];\n let xv2 = faceData[2];\n for (let x = 0; x < texSize; x++) {\n for (let sx = 0; sx < samples; sx++) {\n const v = xv2.subtract(xv1).scale(fy).add(xv1);\n v.normalize();\n const color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);\n // 3 channels per pixels\n textureArray[y * texSize * 3 + x * 3 + 0] += color.r * sampleFactorSqr;\n textureArray[y * texSize * 3 + x * 3 + 1] += color.g * sampleFactorSqr;\n textureArray[y * texSize * 3 + x * 3 + 2] += color.b * sampleFactorSqr;\n xv1 = xv1.add(rotDX1);\n xv2 = xv2.add(rotDX2);\n }\n }\n fy += dy * sampleFactor;\n }\n }\n return textureArray;\n }\n static CalcProjectionSpherical(vDir, float32Array, inputWidth, inputHeight) {\n let theta = Math.atan2(vDir.z, vDir.x);\n const phi = Math.acos(vDir.y);\n while (theta < -Math.PI) {\n theta += 2 * Math.PI;\n }\n while (theta > Math.PI) {\n theta -= 2 * Math.PI;\n }\n let dx = theta / Math.PI;\n const dy = phi / Math.PI;\n // recenter.\n dx = dx * 0.5 + 0.5;\n let px = Math.round(dx * inputWidth);\n if (px < 0) {\n px = 0;\n }\n else if (px >= inputWidth) {\n px = inputWidth - 1;\n }\n let py = Math.round(dy * inputHeight);\n if (py < 0) {\n py = 0;\n }\n else if (py >= inputHeight) {\n py = inputHeight - 1;\n }\n const inputY = inputHeight - py - 1;\n const r = float32Array[inputY * inputWidth * 3 + px * 3 + 0];\n const g = float32Array[inputY * inputWidth * 3 + px * 3 + 1];\n const b = float32Array[inputY * inputWidth * 3 + px * 3 + 2];\n return {\n r: r,\n g: g,\n b: b,\n };\n }\n }\n PanoramaToCubeMapTools.FACE_LEFT = [new Vector3(-1.0, -1.0, -1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(1.0, 1.0, -1.0)];\n PanoramaToCubeMapTools.FACE_RIGHT = [new Vector3(1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, 1.0)];\n PanoramaToCubeMapTools.FACE_FRONT = [new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0), new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0)];\n PanoramaToCubeMapTools.FACE_BACK = [new Vector3(-1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0)];\n PanoramaToCubeMapTools.FACE_DOWN = [new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(-1.0, 1.0, 1.0)];\n PanoramaToCubeMapTools.FACE_UP = [new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0)];\n\n // Do not edit.\n const name$2q = \"hdrFilteringVertexShader\";\n const shader$2q = `attribute vec2 position;varying vec3 direction;uniform vec3 up;uniform vec3 right;uniform vec3 front;\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nmat3 view=mat3(up,right,front);direction=view*vec3(position,1.0);gl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2q] = shader$2q;\n\n // Do not edit.\n const name$2r = \"hdrFilteringPixelShader\";\n const shader$2r = `#include\n#include\n#include\n#include\nuniform float alphaG;uniform samplerCube inputTexture;uniform vec2 vFilteringInfo;uniform float hdrScale;varying vec3 direction;void main() {vec3 color=radiance(alphaG,inputTexture,direction,vFilteringInfo);gl_FragColor=vec4(color*hdrScale,1.0);}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2r] = shader$2r;\n\n /**\n * Filters HDR maps to get correct renderings of PBR reflections\n */\n class HDRFiltering {\n /**\n * Instantiates HDR filter for reflection maps\n *\n * @param engine Thin engine\n * @param options Options\n */\n constructor(engine, options = {}) {\n this._lodGenerationOffset = 0;\n this._lodGenerationScale = 0.8;\n /**\n * Quality switch for prefiltering. Should be set to `4096` unless\n * you care about baking speed.\n */\n this.quality = 4096;\n /**\n * Scales pixel intensity for the input HDR map.\n */\n this.hdrScale = 1;\n // pass\n this._engine = engine;\n this.hdrScale = options.hdrScale || this.hdrScale;\n this.quality = options.quality || this.quality;\n }\n _createRenderTarget(size) {\n let textureType = 0;\n if (this._engine.getCaps().textureHalfFloatRender) {\n textureType = 2;\n }\n else if (this._engine.getCaps().textureFloatRender) {\n textureType = 1;\n }\n const rtWrapper = this._engine.createRenderTargetCubeTexture(size, {\n format: 5,\n type: textureType,\n createMipMaps: true,\n generateMipMaps: false,\n generateDepthBuffer: false,\n generateStencilBuffer: false,\n samplingMode: 1,\n });\n this._engine.updateTextureWrappingMode(rtWrapper.texture, 0, 0, 0);\n this._engine.updateTextureSamplingMode(3, rtWrapper.texture, true);\n return rtWrapper;\n }\n _prefilterInternal(texture) {\n const width = texture.getSize().width;\n const mipmapsCount = Scalar.ILog2(width) + 1;\n const effect = this._effectWrapper.effect;\n const outputTexture = this._createRenderTarget(width);\n this._effectRenderer.saveStates();\n this._effectRenderer.setViewport();\n const intTexture = texture.getInternalTexture();\n if (intTexture) {\n // Just in case generate fresh clean mips.\n this._engine.updateTextureSamplingMode(3, intTexture, true);\n }\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\n const directions = [\n [new Vector3(0, 0, -1), new Vector3(0, -1, 0), new Vector3(1, 0, 0)],\n [new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector3(-1, 0, 0)],\n [new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)],\n [new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)],\n [new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1)],\n [new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, -1)], // NegativeZ\n ];\n effect.setFloat(\"hdrScale\", this.hdrScale);\n effect.setFloat2(\"vFilteringInfo\", texture.getSize().width, mipmapsCount);\n effect.setTexture(\"inputTexture\", texture);\n for (let face = 0; face < 6; face++) {\n effect.setVector3(\"up\", directions[face][0]);\n effect.setVector3(\"right\", directions[face][1]);\n effect.setVector3(\"front\", directions[face][2]);\n for (let lod = 0; lod < mipmapsCount; lod++) {\n this._engine.bindFramebuffer(outputTexture, face, undefined, undefined, true, lod);\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\n let alpha = Math.pow(2, (lod - this._lodGenerationOffset) / this._lodGenerationScale) / width;\n if (lod === 0) {\n alpha = 0;\n }\n effect.setFloat(\"alphaG\", alpha);\n this._effectRenderer.draw();\n }\n }\n // Cleanup\n this._effectRenderer.restoreStates();\n this._engine.restoreDefaultFramebuffer();\n this._engine._releaseTexture(texture._texture);\n // Internal Swap\n const type = outputTexture.texture.type;\n const format = outputTexture.texture.format;\n outputTexture._swapAndDie(texture._texture);\n texture._texture.type = type;\n texture._texture.format = format;\n // New settings\n texture.gammaSpace = false;\n texture.lodGenerationOffset = this._lodGenerationOffset;\n texture.lodGenerationScale = this._lodGenerationScale;\n texture._prefiltered = true;\n return texture;\n }\n _createEffect(texture, onCompiled) {\n const defines = [];\n if (texture.gammaSpace) {\n defines.push(\"#define GAMMA_INPUT\");\n }\n defines.push(\"#define NUM_SAMPLES \" + this.quality + \"u\"); // unsigned int\n const effectWrapper = new EffectWrapper({\n engine: this._engine,\n name: \"hdrFiltering\",\n vertexShader: \"hdrFiltering\",\n fragmentShader: \"hdrFiltering\",\n samplerNames: [\"inputTexture\"],\n uniformNames: [\"vSampleDirections\", \"vWeights\", \"up\", \"right\", \"front\", \"vFilteringInfo\", \"hdrScale\", \"alphaG\"],\n useShaderStore: true,\n defines,\n onCompiled: onCompiled,\n });\n return effectWrapper;\n }\n /**\n * Get a value indicating if the filter is ready to be used\n * @param texture Texture to filter\n * @returns true if the filter is ready\n */\n isReady(texture) {\n return texture.isReady() && this._effectWrapper.effect.isReady();\n }\n /**\n * Prefilters a cube texture to have mipmap levels representing roughness values.\n * Prefiltering will be invoked at the end of next rendering pass.\n * This has to be done once the map is loaded, and has not been prefiltered by a third party software.\n * See http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf for more information\n * @param texture Texture to filter\n * @param onFinished Callback when filtering is done\n * @returns Promise called when prefiltering is done\n */\n prefilter(texture, onFinished = null) {\n if (!this._engine._features.allowTexturePrefiltering) {\n Logger.Warn(\"HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.\");\n return Promise.reject(\"HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.\");\n }\n return new Promise((resolve) => {\n this._effectRenderer = new EffectRenderer(this._engine);\n this._effectWrapper = this._createEffect(texture);\n this._effectWrapper.effect.executeWhenCompiled(() => {\n this._prefilterInternal(texture);\n this._effectRenderer.dispose();\n this._effectWrapper.dispose();\n resolve();\n if (onFinished) {\n onFinished();\n }\n });\n });\n }\n }\n\n /**\n * This groups tools to convert HDR texture to native colors array.\n */\n class HDRTools {\n static _Ldexp(mantissa, exponent) {\n if (exponent > 1023) {\n return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);\n }\n if (exponent < -1074) {\n return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);\n }\n return mantissa * Math.pow(2, exponent);\n }\n static _Rgbe2float(float32array, red, green, blue, exponent, index) {\n if (exponent > 0) {\n /*nonzero pixel*/\n exponent = this._Ldexp(1.0, exponent - (128 + 8));\n float32array[index + 0] = red * exponent;\n float32array[index + 1] = green * exponent;\n float32array[index + 2] = blue * exponent;\n }\n else {\n float32array[index + 0] = 0;\n float32array[index + 1] = 0;\n float32array[index + 2] = 0;\n }\n }\n static _ReadStringLine(uint8array, startIndex) {\n let line = \"\";\n let character = \"\";\n for (let i = startIndex; i < uint8array.length - startIndex; i++) {\n character = String.fromCharCode(uint8array[i]);\n if (character == \"\\n\") {\n break;\n }\n line += character;\n }\n return line;\n }\n /**\n * Reads header information from an RGBE texture stored in a native array.\n * More information on this format are available here:\n * https://en.wikipedia.org/wiki/RGBE_image_format\n *\n * @param uint8array The binary file stored in native array.\n * @returns The header information.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static RGBE_ReadHeader(uint8array) {\n let height = 0;\n let width = 0;\n let line = this._ReadStringLine(uint8array, 0);\n if (line[0] != \"#\" || line[1] != \"?\") {\n throw \"Bad HDR Format.\";\n }\n let endOfHeader = false;\n let findFormat = false;\n let lineIndex = 0;\n do {\n lineIndex += line.length + 1;\n line = this._ReadStringLine(uint8array, lineIndex);\n if (line == \"FORMAT=32-bit_rle_rgbe\") {\n findFormat = true;\n }\n else if (line.length == 0) {\n endOfHeader = true;\n }\n } while (!endOfHeader);\n if (!findFormat) {\n throw \"HDR Bad header format, unsupported FORMAT\";\n }\n lineIndex += line.length + 1;\n line = this._ReadStringLine(uint8array, lineIndex);\n const sizeRegexp = /^-Y (.*) \\+X (.*)$/g;\n const match = sizeRegexp.exec(line);\n // TODO. Support +Y and -X if needed.\n if (!match || match.length < 3) {\n throw \"HDR Bad header format, no size\";\n }\n width = parseInt(match[2]);\n height = parseInt(match[1]);\n if (width < 8 || width > 0x7fff) {\n throw \"HDR Bad header format, unsupported size\";\n }\n lineIndex += line.length + 1;\n return {\n height: height,\n width: width,\n dataPosition: lineIndex,\n };\n }\n /**\n * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.\n * This RGBE texture needs to store the information as a panorama.\n *\n * More information on this format are available here:\n * https://en.wikipedia.org/wiki/RGBE_image_format\n *\n * @param buffer The binary file stored in an array buffer.\n * @param size The expected size of the extracted cubemap.\n * @returns The Cube Map information.\n */\n static GetCubeMapTextureData(buffer, size, supersample = false) {\n const uint8array = new Uint8Array(buffer);\n const hdrInfo = this.RGBE_ReadHeader(uint8array);\n const data = this.RGBE_ReadPixels(uint8array, hdrInfo);\n const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);\n return cubeMapData;\n }\n /**\n * Returns the pixels data extracted from an RGBE texture.\n * This pixels will be stored left to right up to down in the R G B order in one array.\n *\n * More information on this format are available here:\n * https://en.wikipedia.org/wiki/RGBE_image_format\n *\n * @param uint8array The binary file stored in an array buffer.\n * @param hdrInfo The header information of the file.\n * @returns The pixels data in RGB right to left up to down order.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static RGBE_ReadPixels(uint8array, hdrInfo) {\n return this._RGBEReadPixelsRLE(uint8array, hdrInfo);\n }\n static _RGBEReadPixelsRLE(uint8array, hdrInfo) {\n let num_scanlines = hdrInfo.height;\n const scanline_width = hdrInfo.width;\n let a, b, c, d, count;\n let dataIndex = hdrInfo.dataPosition;\n let index = 0, endIndex = 0, i = 0;\n const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E\n const scanLineArray = new Uint8Array(scanLineArrayBuffer);\n // 3 channels of 4 bytes per pixel in float.\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\n const resultArray = new Float32Array(resultBuffer);\n // read in each successive scanline\n while (num_scanlines > 0) {\n a = uint8array[dataIndex++];\n b = uint8array[dataIndex++];\n c = uint8array[dataIndex++];\n d = uint8array[dataIndex++];\n if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {\n return this._RGBEReadPixelsNOTRLE(uint8array, hdrInfo);\n }\n if (((c << 8) | d) != scanline_width) {\n throw \"HDR Bad header format, wrong scan line width\";\n }\n index = 0;\n // read each of the four channels for the scanline into the buffer\n for (i = 0; i < 4; i++) {\n endIndex = (i + 1) * scanline_width;\n while (index < endIndex) {\n a = uint8array[dataIndex++];\n b = uint8array[dataIndex++];\n if (a > 128) {\n // a run of the same value\n count = a - 128;\n if (count == 0 || count > endIndex - index) {\n throw \"HDR Bad Format, bad scanline data (run)\";\n }\n while (count-- > 0) {\n scanLineArray[index++] = b;\n }\n }\n else {\n // a non-run\n count = a;\n if (count == 0 || count > endIndex - index) {\n throw \"HDR Bad Format, bad scanline data (non-run)\";\n }\n scanLineArray[index++] = b;\n if (--count > 0) {\n for (let j = 0; j < count; j++) {\n scanLineArray[index++] = uint8array[dataIndex++];\n }\n }\n }\n }\n }\n // now convert data from buffer into floats\n for (i = 0; i < scanline_width; i++) {\n a = scanLineArray[i];\n b = scanLineArray[i + scanline_width];\n c = scanLineArray[i + 2 * scanline_width];\n d = scanLineArray[i + 3 * scanline_width];\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\n }\n num_scanlines--;\n }\n return resultArray;\n }\n static _RGBEReadPixelsNOTRLE(uint8array, hdrInfo) {\n // this file is not run length encoded\n // read values sequentially\n let num_scanlines = hdrInfo.height;\n const scanline_width = hdrInfo.width;\n let a, b, c, d, i;\n let dataIndex = hdrInfo.dataPosition;\n // 3 channels of 4 bytes per pixel in float.\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\n const resultArray = new Float32Array(resultBuffer);\n // read in each successive scanline\n while (num_scanlines > 0) {\n for (i = 0; i < hdrInfo.width; i++) {\n a = uint8array[dataIndex++];\n b = uint8array[dataIndex++];\n c = uint8array[dataIndex++];\n d = uint8array[dataIndex++];\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\n }\n num_scanlines--;\n }\n return resultArray;\n }\n }\n\n /**\n * This represents a texture coming from an HDR input.\n *\n * The only supported format is currently panorama picture stored in RGBE format.\n * Example of such files can be found on Poly Haven: https://polyhaven.com/hdris\n */\n class HDRCubeTexture extends BaseTexture {\n /**\n * Sets whether or not the texture is blocking during loading.\n */\n set isBlocking(value) {\n this._isBlocking = value;\n }\n /**\n * Gets whether or not the texture is blocking during loading.\n */\n get isBlocking() {\n return this._isBlocking;\n }\n /**\n * Sets texture matrix rotation angle around Y axis in radians.\n */\n set rotationY(value) {\n this._rotationY = value;\n this.setReflectionTextureMatrix(Matrix.RotationY(this._rotationY));\n }\n /**\n * Gets texture matrix rotation angle around Y axis radians.\n */\n get rotationY() {\n return this._rotationY;\n }\n /**\n * Gets or sets the size of the bounding box associated with the cube texture\n * When defined, the cubemap will switch to local mode\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\n * @example https://www.babylonjs-playground.com/#RNASML\n */\n set boundingBoxSize(value) {\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\n return;\n }\n this._boundingBoxSize = value;\n const scene = this.getScene();\n if (scene) {\n scene.markAllMaterialsAsDirty(1);\n }\n }\n get boundingBoxSize() {\n return this._boundingBoxSize;\n }\n /**\n * Instantiates an HDRTexture from the following parameters.\n *\n * @param url The location of the HDR raw data (Panorama stored in RGBE format)\n * @param sceneOrEngine The scene or engine the texture will be used in\n * @param size The cubemap desired size (the more it increases the longer the generation will be)\n * @param noMipmap Forces to not generate the mipmap if true\n * @param generateHarmonics Specifies whether you want to extract the polynomial harmonics during the generation process\n * @param gammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)\n * @param prefilterOnLoad Prefilters HDR texture to allow use of this texture as a PBR reflection texture.\n * @param onLoad\n * @param onError\n */\n constructor(url, sceneOrEngine, size, noMipmap = false, generateHarmonics = true, gammaSpace = false, prefilterOnLoad = false, onLoad = null, onError = null, supersample = false) {\n var _a;\n super(sceneOrEngine);\n this._generateHarmonics = true;\n this._onError = null;\n this._isBlocking = true;\n this._rotationY = 0;\n /**\n * Gets or sets the center of the bounding box associated with the cube texture\n * It must define where the camera used to render the texture was set\n */\n this.boundingBoxPosition = Vector3.Zero();\n /**\n * Observable triggered once the texture has been loaded.\n */\n this.onLoadObservable = new Observable$1();\n if (!url) {\n return;\n }\n this._coordinatesMode = Texture.CUBIC_MODE;\n this.name = url;\n this.url = url;\n this.hasAlpha = false;\n this.isCube = true;\n this._textureMatrix = Matrix.Identity();\n this._prefilterOnLoad = prefilterOnLoad;\n this._onLoad = () => {\n this.onLoadObservable.notifyObservers(this);\n if (onLoad) {\n onLoad();\n }\n };\n this._onError = onError;\n this.gammaSpace = gammaSpace;\n this._noMipmap = noMipmap;\n this._size = size;\n this._supersample = supersample;\n this._generateHarmonics = generateHarmonics;\n this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);\n if (!this._texture) {\n if (!((_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.useDelayedTextureLoading)) {\n this._loadTexture();\n }\n else {\n this.delayLoadState = 4;\n }\n }\n else {\n if (this._texture.isReady) {\n Tools.SetImmediate(() => this._onLoad());\n }\n else {\n this._texture.onLoadedObservable.add(this._onLoad);\n }\n }\n }\n /**\n * Get the current class name of the texture useful for serialization or dynamic coding.\n * @returns \"HDRCubeTexture\"\n */\n getClassName() {\n return \"HDRCubeTexture\";\n }\n /**\n * Occurs when the file is raw .hdr file.\n */\n _loadTexture() {\n const engine = this._getEngine();\n const caps = engine.getCaps();\n let textureType = 0;\n if (caps.textureFloat && caps.textureFloatLinearFiltering) {\n textureType = 1;\n }\n else if (caps.textureHalfFloat && caps.textureHalfFloatLinearFiltering) {\n textureType = 2;\n }\n const callback = (buffer) => {\n this.lodGenerationOffset = 0.0;\n this.lodGenerationScale = 0.8;\n // Extract the raw linear data.\n const data = HDRTools.GetCubeMapTextureData(buffer, this._size, this._supersample);\n // Generate harmonics if needed.\n if (this._generateHarmonics) {\n const sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);\n this.sphericalPolynomial = sphericalPolynomial;\n }\n const results = [];\n let byteArray = null;\n let shortArray = null;\n // Push each faces.\n for (let j = 0; j < 6; j++) {\n // Create fallback array\n if (textureType === 2) {\n shortArray = new Uint16Array(this._size * this._size * 3);\n }\n else if (textureType === 0) {\n // 3 channels of 1 bytes per pixel in bytes.\n byteArray = new Uint8Array(this._size * this._size * 3);\n }\n const dataFace = data[HDRCubeTexture._FacesMapping[j]];\n // If special cases.\n if (this.gammaSpace || shortArray || byteArray) {\n for (let i = 0; i < this._size * this._size; i++) {\n // Put in gamma space if requested.\n if (this.gammaSpace) {\n dataFace[i * 3 + 0] = Math.pow(dataFace[i * 3 + 0], ToGammaSpace);\n dataFace[i * 3 + 1] = Math.pow(dataFace[i * 3 + 1], ToGammaSpace);\n dataFace[i * 3 + 2] = Math.pow(dataFace[i * 3 + 2], ToGammaSpace);\n }\n // Convert to half float texture for fallback.\n if (shortArray) {\n shortArray[i * 3 + 0] = ToHalfFloat(dataFace[i * 3 + 0]);\n shortArray[i * 3 + 1] = ToHalfFloat(dataFace[i * 3 + 1]);\n shortArray[i * 3 + 2] = ToHalfFloat(dataFace[i * 3 + 2]);\n }\n // Convert to int texture for fallback.\n if (byteArray) {\n let r = Math.max(dataFace[i * 3 + 0] * 255, 0);\n let g = Math.max(dataFace[i * 3 + 1] * 255, 0);\n let b = Math.max(dataFace[i * 3 + 2] * 255, 0);\n // May use luminance instead if the result is not accurate.\n const max = Math.max(Math.max(r, g), b);\n if (max > 255) {\n const scale = 255 / max;\n r *= scale;\n g *= scale;\n b *= scale;\n }\n byteArray[i * 3 + 0] = r;\n byteArray[i * 3 + 1] = g;\n byteArray[i * 3 + 2] = b;\n }\n }\n }\n if (shortArray) {\n results.push(shortArray);\n }\n else if (byteArray) {\n results.push(byteArray);\n }\n else {\n results.push(dataFace);\n }\n }\n return results;\n };\n if (engine._features.allowTexturePrefiltering && this._prefilterOnLoad) {\n const previousOnLoad = this._onLoad;\n const hdrFiltering = new HDRFiltering(engine);\n this._onLoad = () => {\n hdrFiltering.prefilter(this, previousOnLoad);\n };\n }\n this._texture = engine.createRawCubeTextureFromUrl(this.url, this.getScene(), this._size, 4, textureType, this._noMipmap, callback, null, this._onLoad, this._onError);\n }\n clone() {\n const newTexture = new HDRCubeTexture(this.url, this.getScene() || this._getEngine(), this._size, this._noMipmap, this._generateHarmonics, this.gammaSpace);\n // Base texture\n newTexture.level = this.level;\n newTexture.wrapU = this.wrapU;\n newTexture.wrapV = this.wrapV;\n newTexture.coordinatesIndex = this.coordinatesIndex;\n newTexture.coordinatesMode = this.coordinatesMode;\n return newTexture;\n }\n // Methods\n delayLoad() {\n if (this.delayLoadState !== 4) {\n return;\n }\n this.delayLoadState = 1;\n this._texture = this._getFromCache(this.url, this._noMipmap);\n if (!this._texture) {\n this._loadTexture();\n }\n }\n /**\n * Get the texture reflection matrix used to rotate/transform the reflection.\n * @returns the reflection matrix\n */\n getReflectionTextureMatrix() {\n return this._textureMatrix;\n }\n /**\n * Set the texture reflection matrix used to rotate/transform the reflection.\n * @param value Define the reflection matrix to set\n */\n setReflectionTextureMatrix(value) {\n var _a;\n this._textureMatrix = value;\n if (value.updateFlag === this._textureMatrix.updateFlag) {\n return;\n }\n if (value.isIdentity() !== this._textureMatrix.isIdentity()) {\n (_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.markAllMaterialsAsDirty(1, (mat) => mat.getActiveTextures().indexOf(this) !== -1);\n }\n }\n /**\n * Dispose the texture and release its associated resources.\n */\n dispose() {\n this.onLoadObservable.clear();\n super.dispose();\n }\n /**\n * Parses a JSON representation of an HDR Texture in order to create the texture\n * @param parsedTexture Define the JSON representation\n * @param scene Define the scene the texture should be created in\n * @param rootUrl Define the root url in case we need to load relative dependencies\n * @returns the newly created texture after parsing\n */\n static Parse(parsedTexture, scene, rootUrl) {\n let texture = null;\n if (parsedTexture.name && !parsedTexture.isRenderTarget) {\n texture = new HDRCubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.size, parsedTexture.noMipmap, parsedTexture.generateHarmonics, parsedTexture.useInGammaSpace);\n texture.name = parsedTexture.name;\n texture.hasAlpha = parsedTexture.hasAlpha;\n texture.level = parsedTexture.level;\n texture.coordinatesMode = parsedTexture.coordinatesMode;\n texture.isBlocking = parsedTexture.isBlocking;\n }\n if (texture) {\n if (parsedTexture.boundingBoxPosition) {\n texture.boundingBoxPosition = Vector3.FromArray(parsedTexture.boundingBoxPosition);\n }\n if (parsedTexture.boundingBoxSize) {\n texture.boundingBoxSize = Vector3.FromArray(parsedTexture.boundingBoxSize);\n }\n if (parsedTexture.rotationY) {\n texture.rotationY = parsedTexture.rotationY;\n }\n }\n return texture;\n }\n serialize() {\n if (!this.name) {\n return null;\n }\n const serializationObject = {};\n serializationObject.name = this.name;\n serializationObject.hasAlpha = this.hasAlpha;\n serializationObject.isCube = true;\n serializationObject.level = this.level;\n serializationObject.size = this._size;\n serializationObject.coordinatesMode = this.coordinatesMode;\n serializationObject.useInGammaSpace = this.gammaSpace;\n serializationObject.generateHarmonics = this._generateHarmonics;\n serializationObject.customType = \"BABYLON.HDRCubeTexture\";\n serializationObject.noMipmap = this._noMipmap;\n serializationObject.isBlocking = this._isBlocking;\n serializationObject.rotationY = this._rotationY;\n return serializationObject;\n }\n }\n HDRCubeTexture._FacesMapping = [\"right\", \"left\", \"up\", \"down\", \"front\", \"back\"];\n RegisterClass(\"BABYLON.HDRCubeTexture\", HDRCubeTexture);\n\n ThinEngine.prototype.updateVideoTexture = function (texture, video, invertY) {\n if (!texture || texture._isDisabled) {\n return;\n }\n const glformat = this._getInternalFormat(texture.format);\n const internalFormat = this._getRGBABufferInternalSizedFormat(0, texture.format);\n const wasPreviouslyBound = this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\n this._unpackFlipY(!invertY); // Video are upside down by default\n try {\n // Testing video texture support\n if (this._videoTextureSupported === undefined) {\n // clear old errors just in case.\n this._gl.getError();\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, glformat, this._gl.UNSIGNED_BYTE, video);\n if (this._gl.getError() !== 0) {\n this._videoTextureSupported = false;\n }\n else {\n this._videoTextureSupported = true;\n }\n }\n // Copy video through the current working canvas if video texture is not supported\n if (!this._videoTextureSupported) {\n if (!texture._workingCanvas) {\n texture._workingCanvas = this.createCanvas(texture.width, texture.height);\n const context = texture._workingCanvas.getContext(\"2d\");\n if (!context) {\n throw new Error(\"Unable to get 2d context\");\n }\n texture._workingContext = context;\n texture._workingCanvas.width = texture.width;\n texture._workingCanvas.height = texture.height;\n }\n texture._workingContext.clearRect(0, 0, texture.width, texture.height);\n texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture.width, texture.height);\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, glformat, this._gl.UNSIGNED_BYTE, texture._workingCanvas);\n }\n else {\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, glformat, this._gl.UNSIGNED_BYTE, video);\n }\n if (texture.generateMipMaps) {\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\n }\n if (!wasPreviouslyBound) {\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\n }\n // this.resetTextureCache();\n texture.isReady = true;\n }\n catch (ex) {\n // Something unexpected\n // Let's disable the texture\n texture._isDisabled = true;\n }\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ThinEngine.prototype.createExternalTexture = function (video) {\n return null;\n };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ThinEngine.prototype.setExternalTexture = function (name, texture) {\n throw new Error(\"setExternalTexture: This engine does not support external textures!\");\n };\n\n //private static _TYPE_NO_DATA = 0;\n const _TYPE_INDEXED = 1;\n const _TYPE_RGB = 2;\n const _TYPE_GREY = 3;\n const _TYPE_RLE_INDEXED = 9;\n const _TYPE_RLE_RGB = 10;\n const _TYPE_RLE_GREY = 11;\n const _ORIGIN_MASK = 0x30;\n const _ORIGIN_SHIFT = 0x04;\n const _ORIGIN_BL = 0x00;\n const _ORIGIN_BR = 0x01;\n const _ORIGIN_UL = 0x02;\n const _ORIGIN_UR = 0x03;\n /**\n * Gets the header of a TGA file\n * @param data defines the TGA data\n * @returns the header\n */\n function GetTGAHeader(data) {\n let offset = 0;\n const header = {\n id_length: data[offset++],\n colormap_type: data[offset++],\n image_type: data[offset++],\n colormap_index: data[offset++] | (data[offset++] << 8),\n colormap_length: data[offset++] | (data[offset++] << 8),\n colormap_size: data[offset++],\n origin: [data[offset++] | (data[offset++] << 8), data[offset++] | (data[offset++] << 8)],\n width: data[offset++] | (data[offset++] << 8),\n height: data[offset++] | (data[offset++] << 8),\n pixel_size: data[offset++],\n flags: data[offset++],\n };\n return header;\n }\n /**\n * Uploads TGA content to a Babylon Texture\n * @internal\n */\n function UploadContent(texture, data) {\n // Not enough data to contain header ?\n if (data.length < 19) {\n Logger.Error(\"Unable to load TGA file - Not enough data to contain header\");\n return;\n }\n // Read Header\n let offset = 18;\n const header = GetTGAHeader(data);\n // Assume it's a valid Targa file.\n if (header.id_length + offset > data.length) {\n Logger.Error(\"Unable to load TGA file - Not enough data\");\n return;\n }\n // Skip not needed data\n offset += header.id_length;\n let use_rle = false;\n let use_pal = false;\n let use_grey = false;\n // Get some informations.\n switch (header.image_type) {\n case _TYPE_RLE_INDEXED:\n use_rle = true;\n // eslint-disable-next-line no-fallthrough\n case _TYPE_INDEXED:\n use_pal = true;\n break;\n case _TYPE_RLE_RGB:\n use_rle = true;\n // eslint-disable-next-line no-fallthrough\n case _TYPE_RGB:\n // use_rgb = true;\n break;\n case _TYPE_RLE_GREY:\n use_rle = true;\n // eslint-disable-next-line no-fallthrough\n case _TYPE_GREY:\n use_grey = true;\n break;\n }\n let pixel_data;\n // var numAlphaBits = header.flags & 0xf;\n const pixel_size = header.pixel_size >> 3;\n const pixel_total = header.width * header.height * pixel_size;\n // Read palettes\n let palettes;\n if (use_pal) {\n palettes = data.subarray(offset, (offset += header.colormap_length * (header.colormap_size >> 3)));\n }\n // Read LRE\n if (use_rle) {\n pixel_data = new Uint8Array(pixel_total);\n let c, count, i;\n let localOffset = 0;\n const pixels = new Uint8Array(pixel_size);\n while (offset < pixel_total && localOffset < pixel_total) {\n c = data[offset++];\n count = (c & 0x7f) + 1;\n // RLE pixels\n if (c & 0x80) {\n // Bind pixel tmp array\n for (i = 0; i < pixel_size; ++i) {\n pixels[i] = data[offset++];\n }\n // Copy pixel array\n for (i = 0; i < count; ++i) {\n pixel_data.set(pixels, localOffset + i * pixel_size);\n }\n localOffset += pixel_size * count;\n }\n // Raw pixels\n else {\n count *= pixel_size;\n for (i = 0; i < count; ++i) {\n pixel_data[localOffset + i] = data[offset++];\n }\n localOffset += count;\n }\n }\n }\n // RAW Pixels\n else {\n pixel_data = data.subarray(offset, (offset += use_pal ? header.width * header.height : pixel_total));\n }\n // Load to texture\n let x_start, y_start, x_step, y_step, y_end, x_end;\n switch ((header.flags & _ORIGIN_MASK) >> _ORIGIN_SHIFT) {\n default:\n case _ORIGIN_UL:\n x_start = 0;\n x_step = 1;\n x_end = header.width;\n y_start = 0;\n y_step = 1;\n y_end = header.height;\n break;\n case _ORIGIN_BL:\n x_start = 0;\n x_step = 1;\n x_end = header.width;\n y_start = header.height - 1;\n y_step = -1;\n y_end = -1;\n break;\n case _ORIGIN_UR:\n x_start = header.width - 1;\n x_step = -1;\n x_end = -1;\n y_start = 0;\n y_step = 1;\n y_end = header.height;\n break;\n case _ORIGIN_BR:\n x_start = header.width - 1;\n x_step = -1;\n x_end = -1;\n y_start = header.height - 1;\n y_step = -1;\n y_end = -1;\n break;\n }\n // Load the specify method\n const func = \"_getImageData\" + (use_grey ? \"Grey\" : \"\") + header.pixel_size + \"bits\";\n const imageData = TGATools[func](header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end);\n const engine = texture.getEngine();\n engine._uploadDataToTextureDirectly(texture, imageData);\n }\n /**\n * @internal\n */\n function _getImageData8bits(header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end) {\n const image = pixel_data, colormap = palettes;\n const width = header.width, height = header.height;\n let color, i = 0, x, y;\n const imageData = new Uint8Array(width * height * 4);\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i++) {\n color = image[i];\n imageData[(x + width * y) * 4 + 3] = 255;\n imageData[(x + width * y) * 4 + 2] = colormap[color * 3 + 0];\n imageData[(x + width * y) * 4 + 1] = colormap[color * 3 + 1];\n imageData[(x + width * y) * 4 + 0] = colormap[color * 3 + 2];\n }\n }\n return imageData;\n }\n /**\n * @internal\n */\n function _getImageData16bits(header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end) {\n const image = pixel_data;\n const width = header.width, height = header.height;\n let color, i = 0, x, y;\n const imageData = new Uint8Array(width * height * 4);\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i += 2) {\n color = image[i + 0] + (image[i + 1] << 8); // Inversed ?\n const r = ((((color & 0x7c00) >> 10) * 255) / 0x1f) | 0;\n const g = ((((color & 0x03e0) >> 5) * 255) / 0x1f) | 0;\n const b = (((color & 0x001f) * 255) / 0x1f) | 0;\n imageData[(x + width * y) * 4 + 0] = r;\n imageData[(x + width * y) * 4 + 1] = g;\n imageData[(x + width * y) * 4 + 2] = b;\n imageData[(x + width * y) * 4 + 3] = color & 0x8000 ? 0 : 255;\n }\n }\n return imageData;\n }\n /**\n * @internal\n */\n function _getImageData24bits(header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end) {\n const image = pixel_data;\n const width = header.width, height = header.height;\n let i = 0, x, y;\n const imageData = new Uint8Array(width * height * 4);\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i += 3) {\n imageData[(x + width * y) * 4 + 3] = 255;\n imageData[(x + width * y) * 4 + 2] = image[i + 0];\n imageData[(x + width * y) * 4 + 1] = image[i + 1];\n imageData[(x + width * y) * 4 + 0] = image[i + 2];\n }\n }\n return imageData;\n }\n /**\n * @internal\n */\n function _getImageData32bits(header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end) {\n const image = pixel_data;\n const width = header.width, height = header.height;\n let i = 0, x, y;\n const imageData = new Uint8Array(width * height * 4);\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i += 4) {\n imageData[(x + width * y) * 4 + 2] = image[i + 0];\n imageData[(x + width * y) * 4 + 1] = image[i + 1];\n imageData[(x + width * y) * 4 + 0] = image[i + 2];\n imageData[(x + width * y) * 4 + 3] = image[i + 3];\n }\n }\n return imageData;\n }\n /**\n * @internal\n */\n function _getImageDataGrey8bits(header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end) {\n const image = pixel_data;\n const width = header.width, height = header.height;\n let color, i = 0, x, y;\n const imageData = new Uint8Array(width * height * 4);\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i++) {\n color = image[i];\n imageData[(x + width * y) * 4 + 0] = color;\n imageData[(x + width * y) * 4 + 1] = color;\n imageData[(x + width * y) * 4 + 2] = color;\n imageData[(x + width * y) * 4 + 3] = 255;\n }\n }\n return imageData;\n }\n /**\n * @internal\n */\n function _getImageDataGrey16bits(header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end) {\n const image = pixel_data;\n const width = header.width, height = header.height;\n let i = 0, x, y;\n const imageData = new Uint8Array(width * height * 4);\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i += 2) {\n imageData[(x + width * y) * 4 + 0] = image[i + 0];\n imageData[(x + width * y) * 4 + 1] = image[i + 0];\n imageData[(x + width * y) * 4 + 2] = image[i + 0];\n imageData[(x + width * y) * 4 + 3] = image[i + 1];\n }\n }\n return imageData;\n }\n /**\n * Based on jsTGALoader - Javascript loader for TGA file\n * By Vincent Thibault\n * @see http://blog.robrowser.com/javascript-tga-loader.html\n */\n const TGATools = {\n /**\n * Gets the header of a TGA file\n * @param data defines the TGA data\n * @returns the header\n */\n GetTGAHeader,\n /**\n * Uploads TGA content to a Babylon Texture\n * @internal\n */\n UploadContent,\n /** @internal */\n _getImageData8bits,\n /** @internal */\n _getImageData16bits,\n /** @internal */\n _getImageData24bits,\n /** @internal */\n _getImageData32bits,\n /** @internal */\n _getImageDataGrey8bits,\n /** @internal */\n _getImageDataGrey16bits,\n };\n\n /**\n * Implementation of the TGA Texture Loader.\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _TGATextureLoader {\n constructor() {\n /**\n * Defines whether the loader supports cascade loading the different faces.\n */\n this.supportCascades = false;\n }\n /**\n * This returns if the loader support the current file information.\n * @param extension defines the file extension of the file being loaded\n * @returns true if the loader can load the specified file\n */\n canLoad(extension) {\n return extension.endsWith(\".tga\");\n }\n /**\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\n */\n loadCubeData() {\n throw \".env not supported in Cube.\";\n }\n /**\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param callback defines the method to call once ready to upload\n */\n loadData(data, texture, callback) {\n const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n const header = GetTGAHeader(bytes);\n callback(header.width, header.height, texture.generateMipMaps, false, () => {\n UploadContent(texture, bytes);\n });\n }\n }\n // Register the loader.\n Engine._TextureLoaders.push(new _TGATextureLoader());\n\n /**\n * Implementation of the HDR Texture Loader.\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _HDRTextureLoader {\n constructor() {\n /**\n * Defines whether the loader supports cascade loading the different faces.\n */\n this.supportCascades = false;\n }\n /**\n * This returns if the loader support the current file information.\n * @param extension defines the file extension of the file being loaded\n * @returns true if the loader can load the specified file\n */\n canLoad(extension) {\n return extension.endsWith(\".hdr\");\n }\n /**\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\n */\n loadCubeData() {\n throw \".env not supported in Cube.\";\n }\n /**\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param callback defines the method to call once ready to upload\n */\n loadData(data, texture, callback) {\n const uint8array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n const hdrInfo = HDRTools.RGBE_ReadHeader(uint8array);\n const pixelsDataRGB32 = HDRTools.RGBE_ReadPixels(uint8array, hdrInfo);\n const pixels = hdrInfo.width * hdrInfo.height;\n const pixelsDataRGBA32 = new Float32Array(pixels * 4);\n for (let i = 0; i < pixels; i += 1) {\n pixelsDataRGBA32[i * 4] = pixelsDataRGB32[i * 3];\n pixelsDataRGBA32[i * 4 + 1] = pixelsDataRGB32[i * 3 + 1];\n pixelsDataRGBA32[i * 4 + 2] = pixelsDataRGB32[i * 3 + 2];\n pixelsDataRGBA32[i * 4 + 3] = 1;\n }\n callback(hdrInfo.width, hdrInfo.height, texture.generateMipMaps, false, () => {\n const engine = texture.getEngine();\n texture.type = 1;\n texture.format = 5;\n texture._gammaSpace = false;\n engine._uploadDataToTextureDirectly(texture, pixelsDataRGBA32);\n });\n }\n }\n // Register the loader.\n Engine._TextureLoaders.push(new _HDRTextureLoader());\n\n /**\n * @internal\n * Enum of basis transcoder formats\n */\n var BASIS_FORMATS;\n (function (BASIS_FORMATS) {\n BASIS_FORMATS[BASIS_FORMATS[\"cTFETC1\"] = 0] = \"cTFETC1\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFETC2\"] = 1] = \"cTFETC2\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFBC1\"] = 2] = \"cTFBC1\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFBC3\"] = 3] = \"cTFBC3\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFBC4\"] = 4] = \"cTFBC4\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFBC5\"] = 5] = \"cTFBC5\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFBC7\"] = 6] = \"cTFBC7\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFPVRTC1_4_RGB\"] = 8] = \"cTFPVRTC1_4_RGB\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFPVRTC1_4_RGBA\"] = 9] = \"cTFPVRTC1_4_RGBA\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFASTC_4x4\"] = 10] = \"cTFASTC_4x4\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFATC_RGB\"] = 11] = \"cTFATC_RGB\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFATC_RGBA_INTERPOLATED_ALPHA\"] = 12] = \"cTFATC_RGBA_INTERPOLATED_ALPHA\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFRGBA32\"] = 13] = \"cTFRGBA32\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFRGB565\"] = 14] = \"cTFRGB565\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFBGR565\"] = 15] = \"cTFBGR565\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFRGBA4444\"] = 16] = \"cTFRGBA4444\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFFXT1_RGB\"] = 17] = \"cTFFXT1_RGB\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFPVRTC2_4_RGB\"] = 18] = \"cTFPVRTC2_4_RGB\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFPVRTC2_4_RGBA\"] = 19] = \"cTFPVRTC2_4_RGBA\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFETC2_EAC_R11\"] = 20] = \"cTFETC2_EAC_R11\";\n BASIS_FORMATS[BASIS_FORMATS[\"cTFETC2_EAC_RG11\"] = 21] = \"cTFETC2_EAC_RG11\";\n })(BASIS_FORMATS || (BASIS_FORMATS = {}));\n /**\n * Used to load .Basis files\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\n */\n const BasisToolsOptions = {\n /**\n * URL to use when loading the basis transcoder\n */\n JSModuleURL: \"https://cdn.babylonjs.com/basisTranscoder/1/basis_transcoder.js\",\n /**\n * URL to use when loading the wasm module for the transcoder\n */\n WasmModuleURL: \"https://cdn.babylonjs.com/basisTranscoder/1/basis_transcoder.wasm\",\n };\n /**\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\n * @param engine\n * @returns internal format corresponding to the Basis format\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const GetInternalFormatFromBasisFormat = (basisFormat, engine) => {\n let format;\n switch (basisFormat) {\n case BASIS_FORMATS.cTFETC1:\n format = 36196;\n break;\n case BASIS_FORMATS.cTFBC1:\n format = 33776;\n break;\n case BASIS_FORMATS.cTFBC4:\n format = 33779;\n break;\n case BASIS_FORMATS.cTFASTC_4x4:\n format = 37808;\n break;\n case BASIS_FORMATS.cTFETC2:\n format = 37496;\n break;\n case BASIS_FORMATS.cTFBC7:\n format = 36492;\n break;\n }\n if (format === undefined) {\n throw \"The chosen Basis transcoder format is not currently supported\";\n }\n return format;\n };\n let _WorkerPromise = null;\n let _Worker = null;\n let _actionId = 0;\n const _IgnoreSupportedFormats = false;\n const _CreateWorkerAsync = () => {\n if (!_WorkerPromise) {\n _WorkerPromise = new Promise((res, reject) => {\n if (_Worker) {\n res(_Worker);\n }\n else {\n Tools.LoadFileAsync(BasisToolsOptions.WasmModuleURL)\n .then((wasmBinary) => {\n if (typeof URL !== \"function\") {\n return reject(\"Basis transcoder requires an environment with a URL constructor\");\n }\n const workerBlobUrl = URL.createObjectURL(new Blob([`(${workerFunc$1})()`], { type: \"application/javascript\" }));\n _Worker = new Worker(workerBlobUrl);\n const initHandler = (msg) => {\n if (msg.data.action === \"init\") {\n _Worker.removeEventListener(\"message\", initHandler);\n res(_Worker);\n }\n else if (msg.data.action === \"error\") {\n reject(msg.data.error || \"error initializing worker\");\n }\n };\n _Worker.addEventListener(\"message\", initHandler);\n _Worker.postMessage({ action: \"init\", url: BasisToolsOptions.JSModuleURL, wasmBinary: wasmBinary });\n })\n .catch(reject);\n }\n });\n }\n return _WorkerPromise;\n };\n /**\n * Transcodes a loaded image file to compressed pixel data\n * @param data image data to transcode\n * @param config configuration options for the transcoding\n * @returns a promise resulting in the transcoded image\n */\n const TranscodeAsync = (data, config) => {\n const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;\n return new Promise((res, rej) => {\n _CreateWorkerAsync().then(() => {\n const actionId = _actionId++;\n const messageHandler = (msg) => {\n if (msg.data.action === \"transcode\" && msg.data.id === actionId) {\n _Worker.removeEventListener(\"message\", messageHandler);\n if (!msg.data.success) {\n rej(\"Transcode is not supported on this device\");\n }\n else {\n res(msg.data);\n }\n }\n };\n _Worker.addEventListener(\"message\", messageHandler);\n const dataViewCopy = new Uint8Array(dataView.byteLength);\n dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));\n _Worker.postMessage({ action: \"transcode\", id: actionId, imageData: dataViewCopy, config: config, ignoreSupportedFormats: _IgnoreSupportedFormats }, [\n dataViewCopy.buffer,\n ]);\n }, (error) => {\n rej(error);\n });\n });\n };\n /**\n * Binds a texture according to its underlying target.\n * @param texture texture to bind\n * @param engine the engine to bind the texture in\n */\n const BindTexture = (texture, engine) => {\n var _a, _b;\n let target = (_a = engine._gl) === null || _a === void 0 ? void 0 : _a.TEXTURE_2D;\n if (texture.isCube) {\n target = (_b = engine._gl) === null || _b === void 0 ? void 0 : _b.TEXTURE_CUBE_MAP;\n }\n engine._bindTextureDirectly(target, texture, true);\n };\n /**\n * Loads a texture from the transcode result\n * @param texture texture load to\n * @param transcodeResult the result of transcoding the basis file to load from\n */\n const LoadTextureFromTranscodeResult = (texture, transcodeResult) => {\n const engine = texture.getEngine();\n for (let i = 0; i < transcodeResult.fileInfo.images.length; i++) {\n const rootImage = transcodeResult.fileInfo.images[i].levels[0];\n texture._invertVScale = texture.invertY;\n if (transcodeResult.format === -1 || transcodeResult.format === BASIS_FORMATS.cTFRGB565) {\n // No compatable compressed format found, fallback to RGB\n texture.type = 10;\n texture.format = 4;\n if (engine._features.basisNeedsPOT && (Scalar.Log2(rootImage.width) % 1 !== 0 || Scalar.Log2(rootImage.height) % 1 !== 0)) {\n // Create non power of two texture\n const source = new InternalTexture(engine, InternalTextureSource.Temp);\n texture._invertVScale = texture.invertY;\n source.type = 10;\n source.format = 4;\n // Fallback requires aligned width/height\n source.width = (rootImage.width + 3) & ~3;\n source.height = (rootImage.height + 3) & ~3;\n BindTexture(source, engine);\n engine._uploadDataToTextureDirectly(source, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, 4, true);\n // Resize to power of two\n engine._rescaleTexture(source, texture, engine.scenes[0], engine._getInternalFormat(4), () => {\n engine._releaseTexture(source);\n BindTexture(texture, engine);\n });\n }\n else {\n // Fallback is already inverted\n texture._invertVScale = !texture.invertY;\n // Upload directly\n texture.width = (rootImage.width + 3) & ~3;\n texture.height = (rootImage.height + 3) & ~3;\n texture.samplingMode = 2;\n BindTexture(texture, engine);\n engine._uploadDataToTextureDirectly(texture, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, 4, true);\n }\n }\n else {\n texture.width = rootImage.width;\n texture.height = rootImage.height;\n texture.generateMipMaps = transcodeResult.fileInfo.images[i].levels.length > 1;\n const format = BasisTools.GetInternalFormatFromBasisFormat(transcodeResult.format, engine);\n texture.format = format;\n BindTexture(texture, engine);\n // Upload all mip levels in the file\n transcodeResult.fileInfo.images[i].levels.forEach((level, index) => {\n engine._uploadCompressedDataToTextureDirectly(texture, format, level.width, level.height, level.transcodedPixels, i, index);\n });\n if (engine._features.basisNeedsPOT && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)) {\n Tools.Warn(\"Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.\");\n texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;\n texture._cachedWrapV = Texture.CLAMP_ADDRESSMODE;\n }\n }\n }\n };\n /**\n * Used to load .Basis files\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\n */\n const BasisTools = {\n /**\n * URL to use when loading the basis transcoder\n */\n JSModuleURL: BasisToolsOptions.JSModuleURL,\n /**\n * URL to use when loading the wasm module for the transcoder\n */\n WasmModuleURL: BasisToolsOptions.WasmModuleURL,\n /**\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\n * @returns internal format corresponding to the Basis format\n */\n GetInternalFormatFromBasisFormat,\n /**\n * Transcodes a loaded image file to compressed pixel data\n * @param data image data to transcode\n * @param config configuration options for the transcoding\n * @returns a promise resulting in the transcoded image\n */\n TranscodeAsync,\n /**\n * Loads a texture from the transcode result\n * @param texture texture load to\n * @param transcodeResult the result of transcoding the basis file to load from\n */\n LoadTextureFromTranscodeResult,\n };\n function workerFunc$1() {\n const _BASIS_FORMAT = {\n cTFETC1: 0,\n cTFETC2: 1,\n cTFBC1: 2,\n cTFBC3: 3,\n cTFBC4: 4,\n cTFBC5: 5,\n cTFBC7: 6,\n cTFPVRTC1_4_RGB: 8,\n cTFPVRTC1_4_RGBA: 9,\n cTFASTC_4x4: 10,\n cTFATC_RGB: 11,\n cTFATC_RGBA_INTERPOLATED_ALPHA: 12,\n cTFRGBA32: 13,\n cTFRGB565: 14,\n cTFBGR565: 15,\n cTFRGBA4444: 16,\n cTFFXT1_RGB: 17,\n cTFPVRTC2_4_RGB: 18,\n cTFPVRTC2_4_RGBA: 19,\n cTFETC2_EAC_R11: 20,\n cTFETC2_EAC_RG11: 21,\n };\n let transcoderModulePromise = null;\n onmessage = (event) => {\n if (event.data.action === \"init\") {\n // Load the transcoder if it hasn't been yet\n if (!transcoderModulePromise) {\n // make sure we loaded the script correctly\n try {\n importScripts(event.data.url);\n }\n catch (e) {\n postMessage({ action: \"error\", error: e });\n }\n transcoderModulePromise = BASIS({\n // Override wasm binary\n wasmBinary: event.data.wasmBinary,\n });\n }\n if (transcoderModulePromise !== null) {\n transcoderModulePromise.then((m) => {\n BASIS = m;\n m.initializeBasis();\n postMessage({ action: \"init\" });\n });\n }\n }\n else if (event.data.action === \"transcode\") {\n // Transcode the basis image and return the resulting pixels\n const config = event.data.config;\n const imgData = event.data.imageData;\n const loadedFile = new BASIS.BasisFile(imgData);\n const fileInfo = GetFileInfo(loadedFile);\n let format = event.data.ignoreSupportedFormats ? null : GetSupportedTranscodeFormat(event.data.config, fileInfo);\n let needsConversion = false;\n if (format === null) {\n needsConversion = true;\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;\n }\n // Begin transcode\n let success = true;\n if (!loadedFile.startTranscoding()) {\n success = false;\n }\n const buffers = [];\n for (let imageIndex = 0; imageIndex < fileInfo.images.length; imageIndex++) {\n if (!success) {\n break;\n }\n const image = fileInfo.images[imageIndex];\n if (config.loadSingleImage === undefined || config.loadSingleImage === imageIndex) {\n let mipCount = image.levels.length;\n if (config.loadMipmapLevels === false) {\n mipCount = 1;\n }\n for (let levelIndex = 0; levelIndex < mipCount; levelIndex++) {\n const levelInfo = image.levels[levelIndex];\n const pixels = TranscodeLevel(loadedFile, imageIndex, levelIndex, format, needsConversion);\n if (!pixels) {\n success = false;\n break;\n }\n levelInfo.transcodedPixels = pixels;\n buffers.push(levelInfo.transcodedPixels.buffer);\n }\n }\n }\n // Close file\n loadedFile.close();\n loadedFile.delete();\n if (needsConversion) {\n format = -1;\n }\n if (!success) {\n postMessage({ action: \"transcode\", success: success, id: event.data.id });\n }\n else {\n postMessage({ action: \"transcode\", success: success, id: event.data.id, fileInfo: fileInfo, format: format }, buffers);\n }\n }\n };\n /**\n * Detects the supported transcode format for the file\n * @param config transcode config\n * @param fileInfo info about the file\n * @returns the chosed format or null if none are supported\n */\n function GetSupportedTranscodeFormat(config, fileInfo) {\n let format = null;\n if (config.supportedCompressionFormats) {\n if (config.supportedCompressionFormats.astc) {\n format = _BASIS_FORMAT.cTFASTC_4x4;\n }\n else if (config.supportedCompressionFormats.bc7) {\n format = _BASIS_FORMAT.cTFBC7;\n }\n else if (config.supportedCompressionFormats.s3tc) {\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;\n }\n else if (config.supportedCompressionFormats.pvrtc) {\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFPVRTC1_4_RGBA : _BASIS_FORMAT.cTFPVRTC1_4_RGB;\n }\n else if (config.supportedCompressionFormats.etc2) {\n format = _BASIS_FORMAT.cTFETC2;\n }\n else if (config.supportedCompressionFormats.etc1) {\n format = _BASIS_FORMAT.cTFETC1;\n }\n else {\n format = _BASIS_FORMAT.cTFRGB565;\n }\n }\n return format;\n }\n /**\n * Retrieves information about the basis file eg. dimensions\n * @param basisFile the basis file to get the info from\n * @returns information about the basis file\n */\n function GetFileInfo(basisFile) {\n const hasAlpha = basisFile.getHasAlpha();\n const imageCount = basisFile.getNumImages();\n const images = [];\n for (let i = 0; i < imageCount; i++) {\n const imageInfo = {\n levels: [],\n };\n const levelCount = basisFile.getNumLevels(i);\n for (let level = 0; level < levelCount; level++) {\n const levelInfo = {\n width: basisFile.getImageWidth(i, level),\n height: basisFile.getImageHeight(i, level),\n };\n imageInfo.levels.push(levelInfo);\n }\n images.push(imageInfo);\n }\n const info = { hasAlpha, images };\n return info;\n }\n function TranscodeLevel(loadedFile, imageIndex, levelIndex, format, convertToRgb565) {\n const dstSize = loadedFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, format);\n let dst = new Uint8Array(dstSize);\n if (!loadedFile.transcodeImage(dst, imageIndex, levelIndex, format, 1, 0)) {\n return null;\n }\n // If no supported format is found, load as dxt and convert to rgb565\n if (convertToRgb565) {\n const alignedWidth = (loadedFile.getImageWidth(imageIndex, levelIndex) + 3) & ~3;\n const alignedHeight = (loadedFile.getImageHeight(imageIndex, levelIndex) + 3) & ~3;\n dst = ConvertDxtToRgb565(dst, 0, alignedWidth, alignedHeight);\n }\n return dst;\n }\n /**\n * From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js\n * An unoptimized version of dxtToRgb565. Also, the floating\n * point math used to compute the colors actually results in\n * slightly different colors compared to hardware DXT decoders.\n * @param src dxt src pixels\n * @param srcByteOffset offset for the start of src\n * @param width aligned width of the image\n * @param height aligned height of the image\n * @returns the converted pixels\n */\n function ConvertDxtToRgb565(src, srcByteOffset, width, height) {\n const c = new Uint16Array(4);\n const dst = new Uint16Array(width * height);\n const blockWidth = width / 4;\n const blockHeight = height / 4;\n for (let blockY = 0; blockY < blockHeight; blockY++) {\n for (let blockX = 0; blockX < blockWidth; blockX++) {\n const i = srcByteOffset + 8 * (blockY * blockWidth + blockX);\n c[0] = src[i] | (src[i + 1] << 8);\n c[1] = src[i + 2] | (src[i + 3] << 8);\n c[2] =\n ((2 * (c[0] & 0x1f) + 1 * (c[1] & 0x1f)) / 3) |\n (((2 * (c[0] & 0x7e0) + 1 * (c[1] & 0x7e0)) / 3) & 0x7e0) |\n (((2 * (c[0] & 0xf800) + 1 * (c[1] & 0xf800)) / 3) & 0xf800);\n c[3] =\n ((2 * (c[1] & 0x1f) + 1 * (c[0] & 0x1f)) / 3) |\n (((2 * (c[1] & 0x7e0) + 1 * (c[0] & 0x7e0)) / 3) & 0x7e0) |\n (((2 * (c[1] & 0xf800) + 1 * (c[0] & 0xf800)) / 3) & 0xf800);\n for (let row = 0; row < 4; row++) {\n const m = src[i + 4 + row];\n let dstI = (blockY * 4 + row) * width + blockX * 4;\n dst[dstI++] = c[m & 0x3];\n dst[dstI++] = c[(m >> 2) & 0x3];\n dst[dstI++] = c[(m >> 4) & 0x3];\n dst[dstI++] = c[(m >> 6) & 0x3];\n }\n }\n }\n return dst;\n }\n }\n Object.defineProperty(BasisTools, \"JSModuleURL\", {\n get: function () {\n return BasisToolsOptions.JSModuleURL;\n },\n set: function (value) {\n BasisToolsOptions.JSModuleURL = value;\n },\n });\n Object.defineProperty(BasisTools, \"WasmModuleURL\", {\n get: function () {\n return BasisToolsOptions.WasmModuleURL;\n },\n set: function (value) {\n BasisToolsOptions.WasmModuleURL = value;\n },\n });\n\n /**\n * Loader for .basis file format\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n class _BasisTextureLoader {\n constructor() {\n /**\n * Defines whether the loader supports cascade loading the different faces.\n */\n this.supportCascades = false;\n }\n /**\n * This returns if the loader support the current file information.\n * @param extension defines the file extension of the file being loaded\n * @returns true if the loader can load the specified file\n */\n canLoad(extension) {\n return extension.endsWith(\".basis\");\n }\n /**\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param createPolynomials will be true if polynomials have been requested\n * @param onLoad defines the callback to trigger once the texture is ready\n * @param onError defines the callback to trigger in case of error\n */\n loadCubeData(data, texture, createPolynomials, onLoad, onError) {\n if (Array.isArray(data)) {\n return;\n }\n const caps = texture.getEngine().getCaps();\n const transcodeConfig = {\n supportedCompressionFormats: {\n etc1: caps.etc1 ? true : false,\n s3tc: caps.s3tc ? true : false,\n pvrtc: caps.pvrtc ? true : false,\n etc2: caps.etc2 ? true : false,\n astc: caps.astc ? true : false,\n bc7: caps.bptc ? true : false,\n },\n };\n TranscodeAsync(data, transcodeConfig)\n .then((result) => {\n const hasMipmap = result.fileInfo.images[0].levels.length > 1 && texture.generateMipMaps;\n LoadTextureFromTranscodeResult(texture, result);\n texture.getEngine()._setCubeMapTextureParams(texture, hasMipmap);\n texture.isReady = true;\n texture.onLoadedObservable.notifyObservers(texture);\n texture.onLoadedObservable.clear();\n if (onLoad) {\n onLoad();\n }\n })\n .catch((err) => {\n const errorMessage = \"Failed to transcode Basis file, transcoding may not be supported on this device\";\n Tools.Warn(errorMessage);\n texture.isReady = true;\n if (onError) {\n onError(err);\n }\n });\n }\n /**\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\n * @param data contains the texture data\n * @param texture defines the BabylonJS internal texture\n * @param callback defines the method to call once ready to upload\n */\n loadData(data, texture, callback) {\n const caps = texture.getEngine().getCaps();\n const transcodeConfig = {\n supportedCompressionFormats: {\n etc1: caps.etc1 ? true : false,\n s3tc: caps.s3tc ? true : false,\n pvrtc: caps.pvrtc ? true : false,\n etc2: caps.etc2 ? true : false,\n astc: caps.astc ? true : false,\n bc7: caps.bptc ? true : false,\n },\n };\n TranscodeAsync(data, transcodeConfig)\n .then((result) => {\n const rootImage = result.fileInfo.images[0].levels[0];\n const hasMipmap = result.fileInfo.images[0].levels.length > 1 && texture.generateMipMaps;\n callback(rootImage.width, rootImage.height, hasMipmap, result.format !== -1, () => {\n LoadTextureFromTranscodeResult(texture, result);\n });\n })\n .catch((err) => {\n Tools.Warn(\"Failed to transcode Basis file, transcoding may not be supported on this device\");\n Tools.Warn(`Failed to transcode Basis file: ${err}`);\n callback(0, 0, false, false, () => { }, true);\n });\n }\n }\n // Register the loader.\n Engine._TextureLoaders.push(new _BasisTextureLoader());\n\n // Do not edit.\n const name$2s = \"noisePixelShader\";\n const shader$2s = `uniform float brightness;uniform float persistence;uniform float timeScale;varying vec2 vUV;vec2 hash22(vec2 p)\n{p=p*mat2(127.1,311.7,269.5,183.3);p=-1.0+2.0*fract(sin(p)*43758.5453123);return sin(p*6.283+timeScale);}\nfloat interpolationNoise(vec2 p)\n{vec2 pi=floor(p);vec2 pf=p-pi;vec2 w=pf*pf*(3.-2.*pf);float f00=dot(hash22(pi+vec2(.0,.0)),pf-vec2(.0,.0));float f01=dot(hash22(pi+vec2(.0,1.)),pf-vec2(.0,1.));float f10=dot(hash22(pi+vec2(1.0,0.)),pf-vec2(1.0,0.));float f11=dot(hash22(pi+vec2(1.0,1.)),pf-vec2(1.0,1.));float xm1=mix(f00,f10,w.x);float xm2=mix(f01,f11,w.x);float ym=mix(xm1,xm2,w.y); \nreturn ym;}\nfloat perlinNoise2D(float x,float y)\n{float sum=0.0;float frequency=0.0;float amplitude=0.0;for(int i=0; i {\n this.getScene().clipPlane = this.refractionPlane;\n });\n this.onAfterRenderObservable.add(() => {\n this.getScene().clipPlane = null;\n });\n }\n /**\n * Clone the refraction texture.\n * @returns the cloned texture\n */\n clone() {\n const scene = this.getScene();\n if (!scene) {\n return this;\n }\n const textureSize = this.getSize();\n const newTexture = new RefractionTexture(this.name, textureSize.width, scene, this._generateMipMaps);\n // Base texture\n newTexture.hasAlpha = this.hasAlpha;\n newTexture.level = this.level;\n // Refraction Texture\n newTexture.refractionPlane = this.refractionPlane.clone();\n if (this.renderList) {\n newTexture.renderList = this.renderList.slice(0);\n }\n newTexture.depth = this.depth;\n return newTexture;\n }\n /**\n * Serialize the texture to a JSON representation you could use in Parse later on\n * @returns the serialized JSON representation\n */\n serialize() {\n if (!this.name) {\n return null;\n }\n const serializationObject = super.serialize();\n serializationObject.mirrorPlane = this.refractionPlane.asArray();\n serializationObject.depth = this.depth;\n return serializationObject;\n }\n }\n\n // DEFLATE is a complex format; to read this code, you should probably check the RFC first:\n // https://tools.ietf.org/html/rfc1951\n // You may also wish to take a look at the guide I made about this program:\n // https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad\n // Some of the following code is similar to that of UZIP.js:\n // https://github.com/photopea/UZIP.js\n // However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.\n // Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint\n // is better for memory in most engines (I *think*).\n var ch2 = {};\n var wk = (function (c, id, msg, transfer, cb) {\n var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([\n c + ';addEventListener(\"error\",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'\n ], { type: 'text/javascript' }))));\n w.onmessage = function (e) {\n var d = e.data, ed = d.$e$;\n if (ed) {\n var err = new Error(ed[0]);\n err['code'] = ed[1];\n err.stack = ed[2];\n cb(err, null);\n }\n else\n cb(null, d);\n };\n w.postMessage(msg, transfer);\n return w;\n });\n\n // aliases for shorter compressed code (most minifers don't do this)\n var u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;\n // fixed length extra bits\n var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);\n // fixed distance extra bits\n // see fleb note\n var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);\n // code length index map\n var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);\n // get base, reverse index map from extra bits\n var freb = function (eb, start) {\n var b = new u16(31);\n for (var i = 0; i < 31; ++i) {\n b[i] = start += 1 << eb[i - 1];\n }\n // numbers here are at max 18 bits\n var r = new u32(b[30]);\n for (var i = 1; i < 30; ++i) {\n for (var j = b[i]; j < b[i + 1]; ++j) {\n r[j] = ((j - b[i]) << 5) | i;\n }\n }\n return [b, r];\n };\n var _a = freb(fleb, 2), fl = _a[0], revfl = _a[1];\n // we can ignore the fact that the other numbers are wrong; they never happen anyway\n fl[28] = 258, revfl[258] = 28;\n var _b = freb(fdeb, 0), revfd = _b[1];\n // map of value to reverse (assuming 16 bits)\n var rev = new u16(32768);\n for (var i = 0; i < 32768; ++i) {\n // reverse table algorithm from SO\n var x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);\n x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);\n x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);\n rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;\n }\n // create huffman tree from u8 \"map\": index -> code length for code index\n // mb (max bits) must be at most 15\n // TODO: optimize/split up?\n var hMap = (function (cd, mb, r) {\n var s = cd.length;\n // index\n var i = 0;\n // u16 \"map\": index -> # of codes with bit length = index\n var l = new u16(mb);\n // length of cd must be 288 (total # of codes)\n for (; i < s; ++i) {\n if (cd[i])\n ++l[cd[i] - 1];\n }\n // u16 \"map\": index -> minimum code for bit length = index\n var le = new u16(mb);\n for (i = 0; i < mb; ++i) {\n le[i] = (le[i - 1] + l[i - 1]) << 1;\n }\n var co;\n if (r) {\n // u16 \"map\": index -> number of actual bits, symbol for code\n co = new u16(1 << mb);\n // bits to remove for reverser\n var rvb = 15 - mb;\n for (i = 0; i < s; ++i) {\n // ignore 0 lengths\n if (cd[i]) {\n // num encoding both symbol and bits read\n var sv = (i << 4) | cd[i];\n // free bits\n var r_1 = mb - cd[i];\n // start value\n var v = le[cd[i] - 1]++ << r_1;\n // m is end value\n for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {\n // every 16 bit value starting with the code yields the same result\n co[rev[v] >>> rvb] = sv;\n }\n }\n }\n }\n else {\n co = new u16(s);\n for (i = 0; i < s; ++i) {\n if (cd[i]) {\n co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);\n }\n }\n }\n return co;\n });\n // fixed length tree\n var flt = new u8(288);\n for (var i = 0; i < 144; ++i)\n flt[i] = 8;\n for (var i = 144; i < 256; ++i)\n flt[i] = 9;\n for (var i = 256; i < 280; ++i)\n flt[i] = 7;\n for (var i = 280; i < 288; ++i)\n flt[i] = 8;\n // fixed distance tree\n var fdt = new u8(32);\n for (var i = 0; i < 32; ++i)\n fdt[i] = 5;\n // fixed length map\n var flm = /*#__PURE__*/ hMap(flt, 9, 0);\n // fixed distance map\n var fdm = /*#__PURE__*/ hMap(fdt, 5, 0);\n // get end of byte\n var shft = function (p) { return ((p + 7) / 8) | 0; };\n // typed array slice - allows garbage collector to free original reference,\n // while being more compatible than .slice\n var slc = function (v, s, e) {\n if (s == null || s < 0)\n s = 0;\n if (e == null || e > v.length)\n e = v.length;\n // can't use .constructor in case user-supplied\n var n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s);\n n.set(v.subarray(s, e));\n return n;\n };\n // error codes\n var ec = [\n 'unexpected EOF',\n 'invalid block type',\n 'invalid length/literal',\n 'invalid distance',\n 'stream finished',\n 'no stream handler',\n ,\n 'no callback',\n 'invalid UTF-8 data',\n 'extra field too long',\n 'date not in range 1980-2099',\n 'filename too long',\n 'stream finishing',\n 'invalid zip data'\n // determined by unknown compression method\n ];\n var err = function (ind, msg, nt) {\n var e = new Error(msg || ec[ind]);\n e.code = ind;\n if (Error.captureStackTrace)\n Error.captureStackTrace(e, err);\n if (!nt)\n throw e;\n return e;\n };\n // starting at p, write the minimum number of bits that can hold v to d\n var wbits = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n };\n // starting at p, write the minimum number of bits (>8) that can hold v to d\n var wbits16 = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n d[o + 2] |= v >>> 16;\n };\n // creates code lengths from a frequency table\n var hTree = function (d, mb) {\n // Need extra info to make a tree\n var t = [];\n for (var i = 0; i < d.length; ++i) {\n if (d[i])\n t.push({ s: i, f: d[i] });\n }\n var s = t.length;\n var t2 = t.slice();\n if (!s)\n return [et, 0];\n if (s == 1) {\n var v = new u8(t[0].s + 1);\n v[t[0].s] = 1;\n return [v, 1];\n }\n t.sort(function (a, b) { return a.f - b.f; });\n // after i2 reaches last ind, will be stopped\n // freq must be greater than largest possible number of symbols\n t.push({ s: -1, f: 25001 });\n var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;\n t[0] = { s: -1, f: l.f + r.f, l: l, r: r };\n // efficient algorithm from UZIP.js\n // i0 is lookbehind, i2 is lookahead - after processing two low-freq\n // symbols that combined have high freq, will start processing i2 (high-freq,\n // non-composite) symbols instead\n // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/\n while (i1 != s - 1) {\n l = t[t[i0].f < t[i2].f ? i0++ : i2++];\n r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];\n t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };\n }\n var maxSym = t2[0].s;\n for (var i = 1; i < s; ++i) {\n if (t2[i].s > maxSym)\n maxSym = t2[i].s;\n }\n // code lengths\n var tr = new u16(maxSym + 1);\n // max bits in tree\n var mbt = ln(t[i1 - 1], tr, 0);\n if (mbt > mb) {\n // more algorithms from UZIP.js\n // TODO: find out how this code works (debt)\n // ind debt\n var i = 0, dt = 0;\n // left cost\n var lft = mbt - mb, cst = 1 << lft;\n t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });\n for (; i < s; ++i) {\n var i2_1 = t2[i].s;\n if (tr[i2_1] > mb) {\n dt += cst - (1 << (mbt - tr[i2_1]));\n tr[i2_1] = mb;\n }\n else\n break;\n }\n dt >>>= lft;\n while (dt > 0) {\n var i2_2 = t2[i].s;\n if (tr[i2_2] < mb)\n dt -= 1 << (mb - tr[i2_2]++ - 1);\n else\n ++i;\n }\n for (; i >= 0 && dt; --i) {\n var i2_3 = t2[i].s;\n if (tr[i2_3] == mb) {\n --tr[i2_3];\n ++dt;\n }\n }\n mbt = mb;\n }\n return [new u8(tr), mbt];\n };\n // get the max length and assign length codes\n var ln = function (n, l, d) {\n return n.s == -1\n ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))\n : (l[n.s] = d);\n };\n // length codes generation\n var lc = function (c) {\n var s = c.length;\n // Note that the semicolon was intentional\n while (s && !c[--s])\n ;\n var cl = new u16(++s);\n // ind num streak\n var cli = 0, cln = c[0], cls = 1;\n var w = function (v) { cl[cli++] = v; };\n for (var i = 1; i <= s; ++i) {\n if (c[i] == cln && i != s)\n ++cls;\n else {\n if (!cln && cls > 2) {\n for (; cls > 138; cls -= 138)\n w(32754);\n if (cls > 2) {\n w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);\n cls = 0;\n }\n }\n else if (cls > 3) {\n w(cln), --cls;\n for (; cls > 6; cls -= 6)\n w(8304);\n if (cls > 2)\n w(((cls - 3) << 5) | 8208), cls = 0;\n }\n while (cls--)\n w(cln);\n cls = 1;\n cln = c[i];\n }\n }\n return [cl.subarray(0, cli), s];\n };\n // calculate the length of output from tree, code lengths\n var clen = function (cf, cl) {\n var l = 0;\n for (var i = 0; i < cl.length; ++i)\n l += cf[i] * cl[i];\n return l;\n };\n // writes a fixed block\n // returns the new bit pos\n var wfblk = function (out, pos, dat) {\n // no need to write 00 as type: TypedArray defaults to 0\n var s = dat.length;\n var o = shft(pos + 2);\n out[o] = s & 255;\n out[o + 1] = s >>> 8;\n out[o + 2] = out[o] ^ 255;\n out[o + 3] = out[o + 1] ^ 255;\n for (var i = 0; i < s; ++i)\n out[o + i + 4] = dat[i];\n return (o + 4 + s) * 8;\n };\n // writes a block\n var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {\n wbits(out, p++, final);\n ++lf[256];\n var _a = hTree(lf, 15), dlt = _a[0], mlb = _a[1];\n var _b = hTree(df, 15), ddt = _b[0], mdb = _b[1];\n var _c = lc(dlt), lclt = _c[0], nlc = _c[1];\n var _d = lc(ddt), lcdt = _d[0], ndc = _d[1];\n var lcfreq = new u16(19);\n for (var i = 0; i < lclt.length; ++i)\n lcfreq[lclt[i] & 31]++;\n for (var i = 0; i < lcdt.length; ++i)\n lcfreq[lcdt[i] & 31]++;\n var _e = hTree(lcfreq, 7), lct = _e[0], mlcb = _e[1];\n var nlcc = 19;\n for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)\n ;\n var flen = (bl + 5) << 3;\n var ftlen = clen(lf, flt) + clen(df, fdt) + eb;\n var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + (2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18]);\n if (flen <= ftlen && flen <= dtlen)\n return wfblk(out, p, dat.subarray(bs, bs + bl));\n var lm, ll, dm, dl;\n wbits(out, p, 1 + (dtlen < ftlen)), p += 2;\n if (dtlen < ftlen) {\n lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;\n var llm = hMap(lct, mlcb, 0);\n wbits(out, p, nlc - 257);\n wbits(out, p + 5, ndc - 1);\n wbits(out, p + 10, nlcc - 4);\n p += 14;\n for (var i = 0; i < nlcc; ++i)\n wbits(out, p + 3 * i, lct[clim[i]]);\n p += 3 * nlcc;\n var lcts = [lclt, lcdt];\n for (var it = 0; it < 2; ++it) {\n var clct = lcts[it];\n for (var i = 0; i < clct.length; ++i) {\n var len = clct[i] & 31;\n wbits(out, p, llm[len]), p += lct[len];\n if (len > 15)\n wbits(out, p, (clct[i] >>> 5) & 127), p += clct[i] >>> 12;\n }\n }\n }\n else {\n lm = flm, ll = flt, dm = fdm, dl = fdt;\n }\n for (var i = 0; i < li; ++i) {\n if (syms[i] > 255) {\n var len = (syms[i] >>> 18) & 31;\n wbits16(out, p, lm[len + 257]), p += ll[len + 257];\n if (len > 7)\n wbits(out, p, (syms[i] >>> 23) & 31), p += fleb[len];\n var dst = syms[i] & 31;\n wbits16(out, p, dm[dst]), p += dl[dst];\n if (dst > 3)\n wbits16(out, p, (syms[i] >>> 5) & 8191), p += fdeb[dst];\n }\n else {\n wbits16(out, p, lm[syms[i]]), p += ll[syms[i]];\n }\n }\n wbits16(out, p, lm[256]);\n return p + ll[256];\n };\n // deflate options (nice << 13) | chain\n var deo = /*#__PURE__*/ new u32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);\n // empty\n var et = /*#__PURE__*/ new u8(0);\n // compresses data into a raw DEFLATE buffer\n var dflt = function (dat, lvl, plvl, pre, post, lst) {\n var s = dat.length;\n var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);\n // writing to this writes to the output buffer\n var w = o.subarray(pre, o.length - post);\n var pos = 0;\n if (!lvl || s < 8) {\n for (var i = 0; i <= s; i += 65535) {\n // end\n var e = i + 65535;\n if (e >= s) {\n // write final block\n w[pos >> 3] = lst;\n }\n pos = wfblk(w, pos + 1, dat.subarray(i, e));\n }\n }\n else {\n var opt = deo[lvl - 1];\n var n = opt >>> 13, c = opt & 8191;\n var msk_1 = (1 << plvl) - 1;\n // prev 2-byte val map curr 2-byte val map\n var prev = new u16(32768), head = new u16(msk_1 + 1);\n var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;\n var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };\n // 24576 is an arbitrary number of maximum symbols per block\n // 424 buffer for last block\n var syms = new u32(25000);\n // length/literal freq distance freq\n var lf = new u16(288), df = new u16(32);\n // l/lcnt exbits index l/lind waitdx bitpos\n var lc_1 = 0, eb = 0, i = 0, li = 0, wi = 0, bs = 0;\n for (; i < s; ++i) {\n // hash value\n // deopt when i > s - 3 - at end, deopt acceptable\n var hv = hsh(i);\n // index mod 32768 previous index mod\n var imod = i & 32767, pimod = head[hv];\n prev[imod] = pimod;\n head[hv] = imod;\n // We always should modify head and prev, but only add symbols if\n // this data is not yet processed (\"wait\" for wait index)\n if (wi <= i) {\n // bytes remaining\n var rem = s - i;\n if ((lc_1 > 7000 || li > 24576) && rem > 423) {\n pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);\n li = lc_1 = eb = 0, bs = i;\n for (var j = 0; j < 286; ++j)\n lf[j] = 0;\n for (var j = 0; j < 30; ++j)\n df[j] = 0;\n }\n // len dist chain\n var l = 2, d = 0, ch_1 = c, dif = (imod - pimod) & 32767;\n if (rem > 2 && hv == hsh(i - dif)) {\n var maxn = Math.min(n, rem) - 1;\n var maxd = Math.min(32767, i);\n // max possible length\n // not capped at dif because decompressors implement \"rolling\" index population\n var ml = Math.min(258, rem);\n while (dif <= maxd && --ch_1 && imod != pimod) {\n if (dat[i + l] == dat[i + l - dif]) {\n var nl = 0;\n for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)\n ;\n if (nl > l) {\n l = nl, d = dif;\n // break out early when we reach \"nice\" (we are satisfied enough)\n if (nl > maxn)\n break;\n // now, find the rarest 2-byte sequence within this\n // length of literals and search for that instead.\n // Much faster than just using the start\n var mmd = Math.min(dif, nl - 2);\n var md = 0;\n for (var j = 0; j < mmd; ++j) {\n var ti = (i - dif + j + 32768) & 32767;\n var pti = prev[ti];\n var cd = (ti - pti + 32768) & 32767;\n if (cd > md)\n md = cd, pimod = ti;\n }\n }\n }\n // check the previous match\n imod = pimod, pimod = prev[imod];\n dif += (imod - pimod + 32768) & 32767;\n }\n }\n // d will be nonzero only when a match was found\n if (d) {\n // store both dist and len data in one Uint32\n // Make sure this is recognized as a len/dist with 28th bit (2^28)\n syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];\n var lin = revfl[l] & 31, din = revfd[d] & 31;\n eb += fleb[lin] + fdeb[din];\n ++lf[257 + lin];\n ++df[din];\n wi = i + l;\n ++lc_1;\n }\n else {\n syms[li++] = dat[i];\n ++lf[dat[i]];\n }\n }\n }\n pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);\n // this is the easiest way to avoid needing to maintain state\n if (!lst && pos & 7)\n pos = wfblk(w, pos + 1, et);\n }\n return slc(o, 0, pre + shft(pos) + post);\n };\n // CRC32 table\n var crct = /*#__PURE__*/ (function () {\n var t = new Int32Array(256);\n for (var i = 0; i < 256; ++i) {\n var c = i, k = 9;\n while (--k)\n c = ((c & 1) && -306674912) ^ (c >>> 1);\n t[i] = c;\n }\n return t;\n })();\n // CRC32\n var crc = function () {\n var c = -1;\n return {\n p: function (d) {\n // closures have awful performance\n var cr = c;\n for (var i = 0; i < d.length; ++i)\n cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);\n c = cr;\n },\n d: function () { return ~c; }\n };\n };\n // deflate with opts\n var dopt = function (dat, opt, pre, post, st) {\n return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : (12 + opt.mem), pre, post, !st);\n };\n // Walmart object spread\n var mrg = function (a, b) {\n var o = {};\n for (var k in a)\n o[k] = a[k];\n for (var k in b)\n o[k] = b[k];\n return o;\n };\n // worker clone\n // This is possibly the craziest part of the entire codebase, despite how simple it may seem.\n // The only parameter to this function is a closure that returns an array of variables outside of the function scope.\n // We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.\n // We will return an object mapping of true variable name to value (basically, the current scope as a JS object).\n // The reason we can't just use the original variable names is minifiers mangling the toplevel scope.\n // This took me three weeks to figure out how to do.\n var wcln = function (fn, fnStr, td) {\n var dt = fn();\n var st = fn.toString();\n var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/ /g, '').split(',');\n for (var i = 0; i < dt.length; ++i) {\n var v = dt[i], k = ks[i];\n if (typeof v == 'function') {\n fnStr += ';' + k + '=';\n var st_1 = v.toString();\n if (v.prototype) {\n // for global objects\n if (st_1.indexOf('[native code]') != -1) {\n var spInd = st_1.indexOf(' ', 8) + 1;\n fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));\n }\n else {\n fnStr += st_1;\n for (var t in v.prototype)\n fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();\n }\n }\n else\n fnStr += st_1;\n }\n else\n td[k] = v;\n }\n return [fnStr, td];\n };\n var ch = [];\n // clone bufs\n var cbfs = function (v) {\n var tl = [];\n for (var k in v) {\n if (v[k] instanceof u8 || v[k] instanceof u16 || v[k] instanceof u32)\n tl.push((v[k] = new v[k].constructor(v[k])).buffer);\n }\n return tl;\n };\n // use a worker to execute code\n var wrkr = function (fns, init, id, cb) {\n var _a;\n if (!ch[id]) {\n var fnStr = '', td_1 = {}, m = fns.length - 1;\n for (var i = 0; i < m; ++i)\n _a = wcln(fns[i], fnStr, td_1), fnStr = _a[0], td_1 = _a[1];\n ch[id] = wcln(fns[m], fnStr, td_1);\n }\n var td = mrg({}, ch[id][1]);\n return wk(ch[id][0] + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);\n };\n var bDflt = function () { return [u8, u16, u32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; };\n // post buf\n var pbf = function (msg) { return postMessage(msg, [msg.buffer]); };\n // async helper\n var cbify = function (dat, opts, fns, init, id, cb) {\n var w = wrkr(fns, init, id, function (err, dat) {\n w.terminate();\n cb(err, dat);\n });\n w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);\n return function () { w.terminate(); };\n };\n // write bytes\n var wbytes = function (d, b, v) {\n for (; v; ++b)\n d[b] = v, v >>>= 8;\n };\n function deflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);\n }\n /**\n * Compresses data with DEFLATE without any wrapper\n * @param data The data to compress\n * @param opts The compression options\n * @returns The deflated version of the data\n */\n function deflateSync(data, opts) {\n return dopt(data, opts || {}, 0, 0);\n }\n // flatten a directory structure\n var fltn = function (d, p, t, o) {\n for (var k in d) {\n var val = d[k], n = p + k;\n if (val instanceof u8)\n t[n] = [val, o];\n else if (Array.isArray(val))\n t[n] = [val[0], mrg(o, val[1])];\n else\n fltn(val, n + '/', t, o);\n }\n };\n // text encoder\n var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();\n // text decoder\n var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();\n // text decoder stream\n var tds = 0;\n try {\n td.decode(et, { stream: true });\n tds = 1;\n }\n catch (e) { }\n /**\n * Converts a string into a Uint8Array for use with compression/decompression methods\n * @param str The string to encode\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless decoding a binary string.\n * @returns The string encoded in UTF-8/Latin-1 binary\n */\n function strToU8(str, latin1) {\n if (latin1) {\n var ar_1 = new u8(str.length);\n for (var i = 0; i < str.length; ++i)\n ar_1[i] = str.charCodeAt(i);\n return ar_1;\n }\n if (te)\n return te.encode(str);\n var l = str.length;\n var ar = new u8(str.length + (str.length >> 1));\n var ai = 0;\n var w = function (v) { ar[ai++] = v; };\n for (var i = 0; i < l; ++i) {\n if (ai + 5 > ar.length) {\n var n = new u8(ai + 8 + ((l - i) << 1));\n n.set(ar);\n ar = n;\n }\n var c = str.charCodeAt(i);\n if (c < 128 || latin1)\n w(c);\n else if (c < 2048)\n w(192 | (c >> 6)), w(128 | (c & 63));\n else if (c > 55295 && c < 57344)\n c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),\n w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n else\n w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n }\n return slc(ar, 0, ai);\n }\n // extra field length\n var exfl = function (ex) {\n var le = 0;\n if (ex) {\n for (var k in ex) {\n var l = ex[k].length;\n if (l > 65535)\n err(9);\n le += l + 4;\n }\n }\n return le;\n };\n // write zip header\n var wzh = function (d, b, f, fn, u, c, ce, co) {\n var fl = fn.length, ex = f.extra, col = co && co.length;\n var exl = exfl(ex);\n wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;\n if (ce != null)\n d[b++] = 20, d[b++] = f.os;\n d[b] = 20, b += 2; // spec compliance? what's that?\n d[b++] = (f.flag << 1) | (c == null && 8), d[b++] = u && 8;\n d[b++] = f.compression & 255, d[b++] = f.compression >> 8;\n var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;\n if (y < 0 || y > 119)\n err(10);\n wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >>> 1)), b += 4;\n if (c != null) {\n wbytes(d, b, f.crc);\n wbytes(d, b + 4, c);\n wbytes(d, b + 8, f.size);\n }\n wbytes(d, b + 12, fl);\n wbytes(d, b + 14, exl), b += 16;\n if (ce != null) {\n wbytes(d, b, col);\n wbytes(d, b + 6, f.attrs);\n wbytes(d, b + 10, ce), b += 14;\n }\n d.set(fn, b);\n b += fl;\n if (exl) {\n for (var k in ex) {\n var exf = ex[k], l = exf.length;\n wbytes(d, b, +k);\n wbytes(d, b + 2, l);\n d.set(exf, b + 4), b += 4 + l;\n }\n }\n if (col)\n d.set(co, b), b += col;\n return b;\n };\n // write zip footer (end of central directory)\n var wzf = function (o, b, c, d, e) {\n wbytes(o, b, 0x6054B50); // skip disk\n wbytes(o, b + 8, c);\n wbytes(o, b + 10, c);\n wbytes(o, b + 12, d);\n wbytes(o, b + 16, e);\n };\n function zip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var r = {};\n fltn(data, '', r, opts);\n var k = Object.keys(r);\n var lft = k.length, o = 0, tot = 0;\n var slft = lft, files = new Array(lft);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var cbf = function () {\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n tot = 0;\n for (var i = 0; i < slft; ++i) {\n var f = files[i];\n try {\n var l = f.c.length;\n wzh(out, tot, f, f.f, f.u, l);\n var badd = 30 + f.f.length + exfl(f.extra);\n var loc = tot + badd;\n out.set(f.c, loc);\n wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;\n }\n catch (e) {\n return cbd(e, null);\n }\n }\n wzf(out, o, files.length, cdl, oe);\n cbd(null, out);\n };\n if (!lft)\n cbf();\n var _loop_1 = function (i) {\n var fn = k[i];\n var _a = r[fn], file = _a[0], p = _a[1];\n var c = crc(), size = file.length;\n c.p(file);\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n var compression = p.level == 0 ? 0 : 8;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n var l = d.length;\n files[i] = mrg(p, {\n size: size,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n compression: compression\n });\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n if (!--lft)\n cbf();\n }\n };\n if (s > 65535)\n cbl(err(11, 0, 1), null);\n if (!compression)\n cbl(null, file);\n else if (size < 160000) {\n try {\n cbl(null, deflateSync(file, p));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(deflate(file, p, cbl));\n };\n // Cannot use lft because it can decrease\n for (var i = 0; i < slft; ++i) {\n _loop_1(i);\n }\n return tAll;\n }\n var mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };\n\n class USDZConverter {\n parse(scene, sceneNode, useWorker = false) {\n return Promise.reject();\n }\n convertGeometry(payload) {\n const meshObject = this.buildGeometryFromBuffers(payload);\n return buildUSDAFile(payload.options, meshObject);\n }\n zipUSDZFiles(files) {\n return new Promise((resolve, reject) => {\n zip(files, {\n level: 0,\n }, (err, res) => {\n if (err) {\n reject(err);\n }\n else {\n const blob = new Blob([res.buffer], { type: 'model/vnd.usdz+zip' });\n resolve(blob);\n }\n });\n });\n }\n buildGeometryFromBuffers(payload) {\n const positions = payload.vertexBuffers[VertexBuffer.PositionKind];\n if (!positions) {\n throw 'No indices in geometry';\n }\n const vertexCount = Math.floor(positions.length / 3);\n return buildGeometryFromData(payload.indices, vertexCount, positions, payload.vertexBuffers[VertexBuffer.NormalKind], payload.vertexBuffers[VertexBuffer.UVKind]);\n }\n buildGeometryFromObject(geometry) {\n const indices = geometry.getIndices();\n const vertexCount = geometry.getTotalVertices();\n const positions = geometry.getVerticesData(VertexBuffer.PositionKind);\n if (!indices) {\n throw 'No indices in geometry';\n }\n if (!positions) {\n throw 'No indices in geometry';\n }\n return buildGeometryFromData(indices, vertexCount, positions, geometry.getVerticesData(VertexBuffer.NormalKind), geometry.getVerticesData(VertexBuffer.UVKind));\n }\n }\n const PRECISION = 7;\n function buildHeader(opts) {\n return `#usda 1.0\r\n(\r\n customLayerData = {\r\n string creator = \"KB3D USDZConverter\"\r\n }\r\n metersPerUnit = ${1 / opts.unitsPerMeter}\r\n upAxis = \"Y\"\r\n)\r\n`;\n }\n function buildUSDAFile(opts, dataToInsert) {\n let output = buildHeader(opts);\n output += dataToInsert;\n return strToU8(output);\n }\n // Xform\n function buildXform(object, geometry, material, appendFileName = '') {\n const name = 'Object__' + escapeGUID(object.id) + appendFileName;\n const worldMatrix = object.computeWorldMatrix(true);\n const transform = buildMatrix(worldMatrix);\n if (worldMatrix.determinant() < 0) {\n console.warn('USDZConverter: USDZ does not support negative scales', object);\n }\n return `def Xform \"${name}\" (\r\n prepend references = @./geometries/Geometry__${escapeGUID(geometry.id)}${appendFileName}.usd@\r\n)\r\n{\r\n matrix4d xformOp:transform = ${transform}\r\n uniform token[] xformOpOrder = [\"xformOp:transform\"]\r\n rel material:binding = \r\n}\r\n`;\n }\n function buildMatrix(matrix) {\n const array = matrix.toArray();\n return `( ${buildMatrixRow(array, 0)}, ${buildMatrixRow(array, 4)}, ${buildMatrixRow(array, 8)}, ${buildMatrixRow(array, 12)} )`;\n }\n function buildMatrixRow(array, offset) {\n return `(${array[offset + 0]}, ${array[offset + 1]}, ${array[offset + 2]}, ${array[offset + 3]})`;\n } // Mesh\n function buildGeometryFromData(indices, verticesCount, positions, normals, uvs) {\n const vertexCounts = Array(Math.floor(indices.length / 3))\n .fill(3)\n .join(', ');\n const name = 'Geometry';\n return `\r\ndef \"Geometry\"\r\n{\r\n def Mesh \"${name}\"\r\n {\r\n int[] faceVertexCounts = [${vertexCounts}]\r\n int[] faceVertexIndices = [${stringifyIntArray(indices)}]\r\n normal3f[] normals = [${buildVector3Array(normals, verticesCount)}] (\r\n interpolation = \"vertex\"\r\n )\r\n point3f[] points = [${buildVector3Array(positions, verticesCount)}]\r\n float2[] primvars:st = [${buildVector2Array(uvs, verticesCount)}] (\r\n interpolation = \"vertex\"\r\n )\r\n uniform token subdivisionScheme = \"none\"\r\n uniform token orientation = \"leftHanded\"\r\n }\r\n}\r\n`;\n }\n function buildVector3Array(data, count) {\n let res = '';\n if (!data) {\n console.warn('USDZConverter: Data missing.');\n for (let i = 0; i < count; i++) {\n res += '(0, 0, 0), ';\n }\n return res;\n }\n return stringifyFloatArray(data, count, 3);\n }\n function buildVector2Array(data, count) {\n let res = '';\n if (!data) {\n console.warn('USDZConverter: Data missing.');\n for (let i = 0; i < count; i++) {\n res += '(0, 0), ';\n }\n return res;\n }\n return stringifyFloatArray(data, count, 2);\n }\n function stringifyIntArray(data) {\n const count = data.length;\n let res = '';\n for (let i = 0; i < count; i++) {\n res += `${data[i]}, `;\n }\n return res.slice(0, -2);\n }\n function stringifyFloatArray(data, count, perStruc) {\n let res = '';\n if (perStruc === 2) {\n for (let i = 0; i < count; i++) {\n res += `(${data[i * 2].toPrecision(PRECISION)}, ${data[i * 2 + 1].toPrecision(PRECISION)}), `;\n }\n }\n else if (perStruc === 3) {\n for (let i = 0; i < count; i++) {\n res += `(${data[i * 3].toPrecision(PRECISION)}, ${data[i * 3 + 1].toPrecision(PRECISION)}, ${data[i * 3 + 2].toPrecision(PRECISION)}), `;\n }\n }\n else {\n throw Error('Not supported');\n }\n return res.slice(0, -2);\n }\n function escapeGUID(guid) {\n return guid.replace(/[-\\s]+/g, '_');\n }\n\n const canvasResize = document.createElement('canvas');\n class USDZBabylonConverter extends USDZConverter {\n parse(scene, sceneNode, useWorker = false) {\n const toCleanup = [];\n const files = {};\n const modelFileName = 'model.usda'; // model file should be first in USDZ archive so we init it here\n files[modelFileName] = new Uint8Array(0);\n let output = buildHeader(sceneNode);\n const materials = {};\n const textures = {};\n const conversionWorker = useWorker ? new Kb3dWorker() : null;\n const asyncGenerators = [];\n scene.meshes.forEach(mesh => {\n if (mesh instanceof Mesh &&\n mesh.isEnabled() &&\n mesh.visibility > 0 &&\n mesh.geometry &&\n !(mesh instanceof LinesMesh) &&\n // for filtering out skyboxes\n !mesh.infiniteDistance) {\n let subMeshes;\n let geometries;\n let meshMaterials;\n const baseGeometry = mesh.geometry;\n if (mesh.subMeshes && mesh.subMeshes.length > 1) {\n const splitGeometryByMaterialId = new Map();\n const baseVertexData = VertexData.ExtractFromGeometry(baseGeometry);\n mesh.subMeshes.forEach((subMesh, index) => {\n const subMeshMaterial = subMesh.getMaterial();\n if (subMeshMaterial) {\n let vertexData = splitGeometryByMaterialId.get(subMeshMaterial);\n if (!vertexData) {\n vertexData = { indices: [], positions: [], normals: [], uvs: [] };\n splitGeometryByMaterialId.set(subMeshMaterial, vertexData);\n }\n // Add polygons from this submesh to the mesh for this material\n let newIdx = vertexData.indices.length;\n const endIndex = subMesh.indexStart + subMesh.indexCount;\n for (let i = subMesh.indexStart; i < endIndex; i++) {\n if (baseVertexData.indices && baseVertexData.indices[i] !== undefined) {\n const oldIdx = baseVertexData.indices[i];\n vertexData.indices.push(newIdx);\n const i2 = oldIdx * 2;\n const i3 = oldIdx * 3;\n if (baseVertexData.positions &&\n typeof baseVertexData.positions[i3] !== 'undefined') {\n vertexData.positions.push(baseVertexData.positions[i3], baseVertexData.positions[i3 + 1], baseVertexData.positions[i3 + 2]);\n }\n if (baseVertexData.normals && typeof baseVertexData.normals[i3] !== 'undefined') {\n vertexData.normals.push(baseVertexData.normals[i3], baseVertexData.normals[i3 + 1], baseVertexData.normals[i3 + 2]);\n }\n if (baseVertexData.uvs && typeof baseVertexData.uvs[i2] !== 'undefined') {\n vertexData.uvs.push(baseVertexData.uvs[i2], baseVertexData.uvs[i2 + 1]);\n }\n newIdx++;\n }\n }\n }\n return null;\n });\n subMeshes = [];\n geometries = [];\n meshMaterials = [];\n splitGeometryByMaterialId.forEach((vertexData, material) => {\n if (material instanceof PBRMaterial) {\n const newMesh = mesh.clone();\n newMesh.id = mesh.id + '__' + material.id;\n newMesh.material = material;\n const newVertexData = new VertexData();\n newVertexData.indices = vertexData.indices;\n newVertexData.positions = vertexData.positions;\n newVertexData.normals = vertexData.normals;\n newVertexData.uvs = vertexData.uvs;\n const newGeometry = Geometry.CreateGeometryForMesh(newMesh);\n newGeometry.id = `sub-${newMesh.id}`;\n newVertexData.applyToGeometry(newGeometry);\n subMeshes.push(newMesh);\n geometries.push(newGeometry);\n meshMaterials.push(material);\n toCleanup.push(newGeometry, newMesh);\n }\n else {\n console.warn(`USDZExporter: No PBR material on submesh`);\n }\n });\n }\n else {\n subMeshes = [mesh];\n geometries = [baseGeometry];\n if (mesh.material instanceof PBRMaterial) {\n meshMaterials = [mesh.material];\n }\n else {\n meshMaterials = [];\n console.warn('USDZExporter: No PBR material on mesh');\n }\n }\n for (let i = 0; i < geometries.length; i++) {\n const subMesh = subMeshes[i];\n const geometry = geometries[i];\n const meshMaterial = meshMaterials[i];\n if (!subMesh || !geometry || !meshMaterial) {\n continue;\n }\n // const appendFileName = `__${i}`;\n const geometryFileName = 'geometries/Geometry__' + escapeGUID(geometry.id) + '.usd';\n if (!(geometryFileName in files)) {\n if (conversionWorker) {\n const geometryData = buildGeometryTransferrable({ unitsPerMeter: sceneNode.unitsPerMeter, xrAllowScaling: sceneNode.xrAllowScaling }, geometry);\n if (geometryData) {\n asyncGenerators.push(conversionWorker\n .startTask(exports.eWorkerTasks.usdConvertGeometry, geometryData.payload, geometryData.transfer)\n .pipe(take(1), map(res => {\n files[geometryFileName] = res.payload.file;\n }))\n .toPromise());\n }\n }\n else {\n const meshObject = this.buildGeometryFromObject(geometry);\n files[geometryFileName] = buildUSDAFile(sceneNode, meshObject);\n }\n }\n if (!(meshMaterial.id in meshMaterial)) {\n materials[meshMaterial.id] = meshMaterial;\n }\n output += buildXform(subMesh, geometry, meshMaterial);\n }\n }\n });\n output += buildMaterials(materials, textures);\n files[modelFileName] = strToU8(output);\n const textureGenerators = [];\n for (const id in textures) {\n const texture = textures[id];\n const color = id.match(/[0-9A-F]{6}$/);\n const color3 = color && color.length === 1 ? Color3.FromHexString(`#${color[0]}`) : undefined;\n const isRGBA = texture.hasAlpha;\n textureGenerators.push(() => processImageData(texture, isRGBA ? 'image/png' : 'image/jpeg', color3)\n .then(blob => {\n if (blob) {\n return blob.arrayBuffer();\n }\n })\n .then(buffer => {\n if (buffer) {\n files[`textures/Texture__${id}.${isRGBA ? 'png' : 'jpg'}`] = new Uint8Array(buffer);\n }\n }));\n } // 64 byte alignment\n // https://github.com/101arrowz/fflate/issues/39#issuecomment-777263109\n return Promise.all([processSequentially(asyncGenerators), processSequentially(textureGenerators)])\n .then(() => {\n let offset = 0;\n for (const filename in files) {\n const file = files[filename];\n const headerSize = 34 + filename.length;\n offset += headerSize;\n const offsetMod64 = offset & 63;\n if (offsetMod64 !== 4) {\n const padLength = 64 - offsetMod64;\n const padding = new Uint8Array(padLength);\n files[filename] = [\n file,\n {\n extra: {\n 12345: padding,\n },\n },\n ];\n }\n offset = file.length;\n }\n if (conversionWorker) {\n const transfer = [];\n for (const fileName in files) {\n const file = files[fileName];\n if (file instanceof Uint8Array) {\n transfer.push(file.buffer);\n }\n else {\n transfer.push(file[0].buffer);\n }\n }\n return conversionWorker\n .startTask(exports.eWorkerTasks.usdPackage, files, transfer)\n .pipe(take(1), map(res => {\n canvasResize.width = 0;\n canvasResize.height = 0;\n conversionWorker.dispose();\n return res.payload;\n }))\n .toPromise();\n }\n else {\n return this.zipUSDZFiles(files);\n }\n })\n .then(res => {\n toCleanup.forEach(item => item.dispose());\n return res;\n });\n }\n }\n async function processSequentially(cbs) {\n const result = [];\n for (const cb of cbs) {\n if (cb instanceof Promise) {\n result.push(await cb);\n }\n else {\n result.push(await cb());\n }\n }\n return result;\n }\n function processImageData(texture, mimeType, color) {\n if (texture instanceof DynamicTexture) {\n const context = texture.getContext();\n const targetTexureSize = getBinClampedSize(context.canvas.width, context.canvas.height);\n canvasResize.width = targetTexureSize;\n canvasResize.height = targetTexureSize;\n const resizeContext = canvasResize.getContext('2d');\n const canvas = context.canvas;\n if (!(canvas instanceof HTMLCanvasElement)) {\n throw Error('texture does not have a canvas');\n }\n resizeContext.drawImage(canvas, 0, 0, targetTexureSize, targetTexureSize);\n if (color) {\n const imagedata = resizeContext.getImageData(0, 0, targetTexureSize, targetTexureSize);\n const data = imagedata.data;\n for (let i = 0; i < data.length; i += 4) {\n data[i + 0] = data[i + 0] * color.r;\n data[i + 1] = data[i + 1] * color.g;\n data[i + 2] = data[i + 2] * color.b;\n }\n resizeContext.putImageData(imagedata, 0, 0);\n }\n return canvasToBlob(canvasResize, mimeType);\n }\n else {\n const size = texture.getSize();\n const dataPromise = texture.readPixels();\n if (!dataPromise) {\n return Promise.resolve(undefined);\n }\n return dataPromise.then(data => {\n if (data instanceof Float32Array || data instanceof Float64Array) {\n for (let i = 0; i < data.length; i += 4) {\n data[i + 0] = data[i + 0] * 255;\n data[i + 1] = data[i + 1] * 255;\n data[i + 2] = data[i + 2] * 255;\n data[i + 3] = data[i + 3] * 255;\n }\n }\n let targetTexureSize = getBinClampedSize(size.width, size.height);\n if (targetTexureSize > 1024) {\n targetTexureSize = 1024;\n }\n canvasResize.width = targetTexureSize;\n canvasResize.height = targetTexureSize;\n const pxLength = targetTexureSize * targetTexureSize;\n const resizedData = new Uint8ClampedArray(pxLength * 4);\n if (targetTexureSize !== size.width || targetTexureSize !== size.height) {\n const widthRatio = size.width / targetTexureSize;\n const heightRatio = size.height / targetTexureSize;\n // in the interest of speed, just downscale with nearest neighbor algorithm instead of averaging pixels.\n for (let i = 0; i < pxLength; i++) {\n const x = i % targetTexureSize;\n // Y must be flipped for USDZ output\n const y = Math.floor(targetTexureSize - i / targetTexureSize);\n const targetIndex = (Math.floor(x * widthRatio) + Math.floor(y * heightRatio) * size.width) * 4;\n const destIndex = i * 4;\n resizedData[destIndex + 0] = data[targetIndex + 0];\n resizedData[destIndex + 1] = data[targetIndex + 1];\n resizedData[destIndex + 2] = data[targetIndex + 2];\n resizedData[destIndex + 3] = data[targetIndex + 3];\n }\n }\n else {\n const lastLineOffset = (targetTexureSize - 1) * targetTexureSize;\n for (let y = 0; y < targetTexureSize / 2; y++) {\n const yOffset = y * targetTexureSize;\n const yOffsetTarget = lastLineOffset - yOffset;\n for (let x = 0; x < targetTexureSize; x++) {\n const offset = (yOffset + x) * 4;\n const offsetTarget = (yOffsetTarget + x) * 4;\n resizedData[offset] = data[offsetTarget];\n resizedData[offset + 1] = data[offsetTarget + 1];\n resizedData[offset + 2] = data[offsetTarget + 2];\n resizedData[offset + 3] = data[offsetTarget + 3];\n resizedData[offsetTarget] = data[offset];\n resizedData[offsetTarget + 1] = data[offset + 1];\n resizedData[offsetTarget + 2] = data[offset + 2];\n resizedData[offsetTarget + 3] = data[offset + 3];\n }\n }\n }\n if (color) {\n for (let i = 0; i < resizedData.length; i += 4) {\n resizedData[i + 0] = resizedData[i + 0] * color.r;\n resizedData[i + 1] = resizedData[i + 1] * color.g;\n resizedData[i + 2] = resizedData[i + 2] * color.b;\n }\n }\n const imageData = new ImageData(resizedData, targetTexureSize, targetTexureSize);\n const resizeContext = canvasResize.getContext('2d');\n resizeContext.putImageData(imageData, 0, 0);\n return canvasToBlob(canvasResize, mimeType);\n });\n }\n }\n function canvasToBlob(canvasResize, mimeType) {\n return new Promise((resolve, reject) => {\n canvasResize.toBlob(result => {\n if (result) {\n resolve(result);\n }\n reject('Could not generate texture');\n }, mimeType, 1);\n });\n }\n function buildMaterials(materials, textures) {\n const array = [];\n for (const uuid in materials) {\n const material = materials[uuid];\n array.push(buildMaterial(material, textures));\n }\n return `def \"Materials\"\r\n{\r\n${array.join('')}\r\n}\r\n`;\n }\n function buildMaterial(material, textures) {\n // https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html\n const pad = ' ';\n const inputs = [];\n const samplers = [];\n const materialId = escapeGUID(material.id);\n const newV = new Vector3();\n const tMatrix = new Matrix();\n const t2Matrix = new Matrix();\n const t3Matrix = new Matrix();\n function buildTexture(texture, mapType, color) {\n if (texture instanceof Texture) {\n const textureName = escapeGUID(texture.name);\n const parsedTextureId = textureName + (color ? '__' + color.toHexString().substring(1) : '');\n textures[parsedTextureId] = texture;\n const angleDeg = (texture.wAng * 180) / Math.PI;\n // USD doesn't seem to have a good way to apply a matrix to a texture. But we can use the rotation and scale straight,\n // and grab the translation off of the babylon texture matrix. The matrix includes the rotation pivot related translation\n // which is nasty to calculate without a matrix and USD doesn't support UV Pivot\n const textureMatrix = texture.getTextureMatrix().m;\n Matrix.RotationYawPitchRollToRef(texture.vAng, texture.uAng, texture.wAng, tMatrix);\n Matrix.ScalingToRef(texture.uScale, texture.vScale, 1, t2Matrix);\n tMatrix.multiplyToRef(t2Matrix, t3Matrix);\n t3Matrix.invert();\n Vector3.TransformCoordinatesFromFloatsToRef(textureMatrix[8], textureMatrix[9], 0, t3Matrix, newV);\n return `\r\n def Shader \"Transform2d_${mapType}\" (\r\n sdrMetadata = {\r\n string role = \"math\"\r\n }\r\n )\r\n {\r\n uniform token info:id = \"UsdTransform2d\"\r\n float2 inputs:in.connect = \r\n float2 inputs:scale = (${texture.uScale}, ${texture.vScale})\r\n float2 inputs:translation = (${newV.x}, ${newV.y})\r\n float inputs:rotation = ${angleDeg.toPrecision(PRECISION)}\r\n float2 outputs:result\r\n }\r\n def Shader \"Texture__${textureName}_${mapType}\"\r\n {\r\n uniform token info:id = \"UsdUVTexture\"\r\n asset inputs:file = @./textures/Texture__${parsedTextureId}.${texture.hasAlpha ? 'png' : 'jpg'}@\r\n float2 inputs:st.connect = \r\n token inputs:wrapS = \"repeat\"\r\n token inputs:wrapT = \"repeat\"\r\n float outputs:r\r\n float outputs:g\r\n float outputs:b\r\n ${texture.hasAlpha ? 'float outputs:a' : ''}\r\n float3 outputs:rgb\r\n }`;\n }\n return '';\n }\n if (material.albedoTexture) {\n inputs.push(`${pad}color3f inputs:diffuseColor.connect = `);\n samplers.push(buildTexture(material.albedoTexture, 'diffuse', material.albedoColor));\n }\n else {\n inputs.push(`${pad}color3f inputs:diffuseColor = ${buildColor(material.albedoColor)}`);\n }\n if (material.emissiveTexture) {\n inputs.push(`${pad}color3f inputs:emissiveColor.connect = `);\n samplers.push(buildTexture(material.emissiveTexture, 'emissive'));\n }\n else if (material.emissiveColor.toLuminance() > 0) {\n inputs.push(`${pad}color3f inputs:emissiveColor = ${buildColor(material.emissiveColor)}`);\n }\n if (material.bumpTexture) {\n inputs.push(`${pad}normal3f inputs:normal.connect = `);\n samplers.push(buildTexture(material.bumpTexture, 'normal'));\n }\n if (material.ambientTexture !== null) {\n inputs.push(`${pad}float inputs:occlusion.connect = `);\n samplers.push(buildTexture(material.ambientTexture, 'occlusion'));\n }\n if (material.microSurfaceTexture !== null && material.roughness === 1) {\n inputs.push(`${pad}float inputs:roughness.connect = `);\n samplers.push(buildTexture(material.microSurfaceTexture, 'roughness'));\n }\n else {\n inputs.push(`${pad}float inputs:roughness = ${material.roughness}`);\n }\n if (material.metallicTexture !== null && material.metallic === 1) {\n inputs.push(`${pad}float inputs:metallic.connect = `);\n samplers.push(buildTexture(material.metallicTexture, 'metallic'));\n }\n else {\n inputs.push(`${pad}float inputs:metallic = ${material.metallic}`);\n }\n if (material.opacityTexture !== null) {\n inputs.push(`${pad}float inputs:opacity.connect = `);\n inputs.push(`${pad}float inputs:opacityThreshold = 0.0001`);\n samplers.push(buildTexture(material.opacityTexture, 'opacity'));\n }\n else if (material.albedoTexture && material.albedoTexture.hasAlpha) {\n inputs.push(`${pad}float inputs:opacity.connect = `);\n inputs.push(`${pad}float inputs:opacityThreshold = 0.0001`);\n }\n else {\n inputs.push(`${pad}float inputs:opacity = ${material.alpha}`);\n }\n if (material.clearCoat && material.clearCoat.isEnabled) {\n inputs.push(`${pad}float inputs:clearcoat = ${material.clearCoat.intensity}`);\n inputs.push(`${pad}float inputs:clearcoatRoughness = ${material.clearCoat.roughness}`);\n // TODO More properties?\n }\n inputs.push(`${pad}float inputs:ior = ${material.indexOfRefraction}`);\n // TODO More properties?\n return `\r\n def Material \"Material__${materialId}\"\r\n {\r\n def Shader \"PreviewSurface\"\r\n {\r\n uniform token info:id = \"UsdPreviewSurface\"\r\n${inputs.join('\\n')}\r\n int inputs:useSpecularWorkflow = 0\r\n token outputs:surface\r\n }\r\n token outputs:surface.connect = \r\n token inputs:frame:stPrimvarName = \"st\"\r\n def Shader \"uvReader_st\"\r\n {\r\n uniform token info:id = \"UsdPrimvarReader_float2\"\r\n token inputs:varname.connect = \r\n float2 inputs:fallback = (0.0, 0.0)\r\n float2 outputs:result\r\n }\r\n${samplers.join('\\n')}\r\n }\r\n`;\n }\n function buildGeometryTransferrable(options, geometry) {\n const transfer = [];\n const geometryBuffers = geometry.getVertexBuffers();\n const indices = geometry.getIndices();\n if (geometryBuffers && indices) {\n const vertexBuffers = Object.keys(geometryBuffers).reduce((res, type) => {\n const data = geometryBuffers[type].getData();\n if ('buffer' in data) {\n res[type] = data;\n transfer.push(res[type].slice().buffer);\n }\n else if (data instanceof ArrayBuffer || 'length' in data) {\n res[type] = new Float32Array(data);\n transfer.push(res[type].buffer);\n }\n else {\n console.warn('Unsupported geometry');\n }\n return res;\n }, {});\n const indexBuffer = Array.isArray(indices) ? new Uint32Array(indices) : indices;\n transfer.push(indexBuffer.slice().buffer);\n const result = {\n payload: {\n options,\n id: geometry.id,\n indices: indexBuffer,\n vertexBuffers,\n },\n transfer,\n };\n return result;\n }\n }\n function buildColor(color) {\n return `(${color.r}, ${color.g}, ${color.b})`;\n }\n\n class XrHitTester {\n constructor(sessionMgr) {\n this.sessionMgr = sessionMgr;\n /** temp variables for saving memory while processing hit results */\n this._tmpPos = new Vector3();\n this._tmpMat = new Matrix();\n this._tmpQuat = new Quaternion();\n }\n initialize(offsetRay) {\n const session = this.sessionMgr.session;\n //setup initial hit testing source\n if (session) {\n return session.requestHitTestSource({\n space: this.sessionMgr.viewerReferenceSpace,\n offsetRay: offsetRay,\n }).then(hitSource => {\n return (this.source = hitSource);\n });\n }\n }\n getHitResult(frame) {\n if (!this.source)\n return;\n const hits = frame.getHitTestResults(this.source);\n if (!hits.length)\n return;\n const hit = hits[0]; //only concentrate on the first hit... might want to reconsider this later\n return XrHitTester.FromXRHitTestResult(hit, this.sessionMgr.referenceSpace);\n // // Check that the y-coordinate of the normal is large enough that the normal\n // // is pointing up.\n // return hitMatrix hitMatrix.elements[5] > 0.75 ?\n // hitPosition.setFromMatrixPosition(hitMatrix) :\n // null;\n }\n static FromXRHitTestResult(hit, refSpace) {\n const pose = hit.getPose(refSpace);\n if (pose == null)\n return;\n const xrpos = pose.transform.position;\n const xrquat = pose.transform.orientation;\n const mat = new Matrix();\n Matrix.FromFloat32ArrayToRefScaled(pose.transform.matrix, 0, 1, mat);\n return {\n position: new Vector3(xrpos.x, xrpos.y, xrpos.z),\n rotation: new Quaternion(xrquat.x, xrquat.y, xrquat.z, xrquat.w),\n matrix: mat,\n xrResult: hit,\n };\n }\n dispose() {\n if (this.source) {\n this.source.cancel();\n this.source = undefined;\n }\n }\n }\n\n /**\n * Manages shadow generators and their association with lights and meshes that participate\n */\n class ShadowManager {\n constructor(_bbCache) {\n this._bbCache = _bbCache;\n this.generatorMap = new Map();\n /** the meshes that are casting shadows. The mesh renderer adds and removes them from this list as their boolean flag is changed */\n this.casters = new Set();\n /** the meshes that are receiving shadows. The mesh renderer adds and removes them from this list as their boolean flag is changed */\n this.receivers = new Set();\n /**\n * Stores the calculated shadow projection matrix for directional lights. This cache is invalidated when\n * the root scene bounding box has changed or meshes change their casting / receiving flags.\n *\n * By default, babylon calculates the projection matrix of the shadows on every frame.\n * To be more efficient, we cache the projection matrix until something that warrants updating it happens.\n */\n this.projectionMatrixCache = new Map();\n this._bbCache.rootBoundingBoxChanged.subscribe(bbInfo => {\n //invalidate our projection matrix cache\n this.projectionMatrixCache.clear();\n });\n }\n /**\n * Add a shadow generator for the given light. Should only be called when the light.generatesShadows is set to true\n * @param light\n */\n add(light, shadowResolution) {\n let sg = this.get(light);\n if (!sg) {\n sg = new ShadowGenerator(ShadowManager.convertShadowResultion(shadowResolution), light);\n this.generatorMap.set(light, sg);\n this.addAllCastersToGenerator(sg);\n if (light instanceof DirectionalLight) {\n /**\n * Directional lights are tricky, as their light shadow fulstrum needs to be the optimal size for the shadows to look good.\n * The built-in calculation of the projection matrix does not account for meshes that are receiving shadows. So we override\n * the calculation here. It also gives us a way to cache and increase performance.\n */\n light.autoUpdateExtends = false;\n light.autoCalcShadowZBounds = false;\n light.customProjectionMatrixBuilder = (viewMatrix, renderList, matrix) => {\n return this.customProjectionMatrixBuilder(light, viewMatrix, renderList, matrix);\n };\n }\n }\n return sg;\n }\n /**\n * Get the shadow generator for a specific light (if it has one)\n * @param light\n */\n get(light) {\n return this.generatorMap.get(light);\n }\n /** Remove the shadow generator for the given light */\n remove(light) {\n const sg = this.get(light);\n light.customProjectionMatrixBuilder = undefined;\n if (sg) {\n this.generatorMap.delete(light);\n sg.dispose();\n }\n }\n /**\n * Adds a mesh as a shadow caster. Should only be called by the mesh renderer when the meshNode.castShadows flag is changed to true\n */\n addCaster(mesh) {\n if (!this.casters.has(mesh)) {\n this.casters.add(mesh);\n for (const sg of this.generatorMap.values()) {\n sg.addShadowCaster(mesh);\n }\n this.projectionMatrixCache.clear();\n }\n }\n /**\n * Removes a mesh as a shadow caster. Should only be called by the mesh renderer when the meshNode.castShadows flag is changed to false\n */\n removeCaster(mesh) {\n if (this.casters.has(mesh)) {\n this.casters.delete(mesh);\n for (const sg of this.generatorMap.values()) {\n sg.removeShadowCaster(mesh);\n }\n this.projectionMatrixCache.clear();\n }\n }\n /**\n * Adds/removes the mesh as a shadow caster\n * @param mesh\n * @param value\n */\n toggleCaster(mesh, value) {\n if (value) {\n this.addCaster(mesh);\n }\n else {\n this.removeCaster(mesh);\n }\n }\n addAllCastersToGenerator(sg) {\n for (const c of this.casters.values()) {\n sg.addShadowCaster(c);\n }\n }\n addReceiver(mesh) {\n if (!this.receivers.has(mesh)) {\n this.receivers.add(mesh);\n this.projectionMatrixCache.clear();\n }\n }\n removeReceiver(mesh) {\n if (this.receivers.has(mesh)) {\n this.receivers.delete(mesh);\n this.projectionMatrixCache.clear();\n }\n }\n toggleReceiver(mesh, value) {\n if (value) {\n this.addReceiver(mesh);\n }\n else {\n this.removeReceiver(mesh);\n }\n }\n dispose() {\n this.projectionMatrixCache.clear();\n for (const light of this.generatorMap.keys()) {\n this.remove(light);\n }\n }\n clearProjectMatrixCache() {\n this.projectionMatrixCache.clear();\n }\n /**\n * Directional lights are tricky, as their light shadow fulstrum needs to be the optimal size for the shadows to look good.\n * The built-in calculation of the projection matrix does not account for meshes that are receiving shadows. So we override\n * the calculation here. It also gives us a way to cache and increase performance.\n *\n * This is based on the built-in DirectionalLight.prototype._setDefaultAutoExtendShadowProjectionMatrix\n * but with these additions:\n * * caching of the projection matrix\n * * inclusion of shadow receivers in the box calculation so shadows are not chopped off with PCSS\n * * uses the shadowOrthoScale of the light to increase the minZ/maxZ range to avoid z-fighting on planes at one of the extents of the box\n */\n customProjectionMatrixBuilder(light, viewMatrix, renderList, matrix) {\n if (this.projectionMatrixCache.has(light)) {\n matrix.copyFrom(this.projectionMatrixCache.get(light));\n }\n else {\n const allMeshes = new Set([...this.casters, ...this.receivers]);\n const shadowOrthoScale = light.shadowOrthoScale;\n let orthoLeft = Number.MAX_VALUE;\n let orthoRight = Number.MIN_VALUE;\n let orthoTop = Number.MIN_VALUE;\n let orthoBottom = Number.MAX_VALUE;\n let shadowMinZ = Number.MAX_VALUE;\n let shadowMaxZ = Number.MIN_VALUE;\n const tempVector3 = Vector3.Zero();\n //loop through each caster/reciever to build up the fulstrum box\n for (const m of allMeshes) {\n if (m.isEnabled(true)) {\n const node = getByDynamicId(m.id);\n let bbInfo;\n if (node) {\n bbInfo = this._bbCache.get(node);\n }\n if (bbInfo) {\n const boundingBox = bbInfo.boundingInfo.boundingBox;\n for (let index = 0; index < boundingBox.vectorsWorld.length; index++) {\n Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);\n if (tempVector3.x < orthoLeft) {\n orthoLeft = tempVector3.x;\n }\n if (tempVector3.y < orthoBottom) {\n orthoBottom = tempVector3.y;\n }\n if (tempVector3.x > orthoRight) {\n orthoRight = tempVector3.x;\n }\n if (tempVector3.y > orthoTop) {\n orthoTop = tempVector3.y;\n }\n if (tempVector3.z < shadowMinZ) {\n shadowMinZ = tempVector3.z;\n }\n if (tempVector3.z > shadowMaxZ) {\n shadowMaxZ = tempVector3.z;\n }\n }\n }\n }\n }\n const xOffset = orthoRight - orthoLeft;\n const yOffset = orthoTop - orthoBottom;\n /** for exponential blur, it works way better when the max z is alot larger than the scene to get soft shadows */\n const sg = this.get(light);\n if (sg.filter == ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP) {\n shadowMaxZ = shadowMaxZ * 50;\n }\n const zOffset = shadowMaxZ - shadowMinZ;\n Matrix.OrthoOffCenterLHToRef(orthoLeft - xOffset * shadowOrthoScale, orthoRight + xOffset * shadowOrthoScale, orthoBottom - yOffset * shadowOrthoScale, orthoTop + yOffset * shadowOrthoScale, \n /**\n * Babylon does not account for the orthoScale when calculating minZ/maxZ, which leads to shadow z fighting on planes receiving shadows.\n * So here we change this behavior to offset by the scale just like left/right/top/bottom\n */\n shadowMinZ - zOffset * shadowOrthoScale, shadowMaxZ + zOffset * shadowOrthoScale, matrix);\n this.projectionMatrixCache.set(light, matrix);\n // console.count(\"shadow manager processed\");\n }\n }\n static convertShadowResultion(r) {\n switch (r) {\n case exports.eShadowResolution.low:\n return 512;\n case exports.eShadowResolution.medium:\n return 1024;\n case exports.eShadowResolution.high:\n return 2048;\n }\n }\n static convertShadowFilter(f) {\n switch (f) {\n case exports.eShadowFilter.none:\n return ShadowGenerator.FILTER_NONE;\n case exports.eShadowFilter.simple:\n return ShadowGenerator.FILTER_PCF;\n case exports.eShadowFilter.advanced:\n return ShadowGenerator.FILTER_PCSS;\n }\n }\n }\n\n class XrLight extends DirectionalLight {\n constructor(v, scene) {\n super('xrLight', new Vector3(0, -3, 0), scene);\n this.v = v;\n this.scene = scene;\n this._originalLightEnabledMap = new Map();\n //turn all existing lights off and save their setting\n for (const l of scene.lights) {\n if (l !== this) {\n this._originalLightEnabledMap.set(l, l.isEnabled(false));\n l.setEnabled(false);\n }\n }\n this.position = this.direction.negate();\n this.intensity = 0.5;\n this._shadowManager = new ShadowManager(this.v.bbCache);\n this._sg = this._shadowManager.add(this, exports.eShadowResolution.low);\n this._sg.setDarkness(0.3);\n this._sg.filter = ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP;\n // this._sg.blurBoxOffset = 10;\n // this._sg.blurScale = 2;\n this._sg.useKernelBlur = true;\n this._sg.blurKernel = 64; //64;\n this._sg.blurScale = 2;\n /**\n * Add all meshes from the scene to the shadow caster.\n * This includes the shadow plane so that extents are auto calculated to include it\n */\n const rootNode = this.v.rendererManager.sceneRenderer.get3d(this.v.sceneNode);\n for (const m of rootNode.getChildMeshes(false)) {\n if (m.name == 'xrShadowPlane') {\n this._shadowManager.addReceiver(m);\n }\n else {\n this._shadowManager.addCaster(m);\n }\n // console.log(`adding mesh '${m.name}' to shadow generator`);\n }\n }\n setDirection(x, y, z) {\n this.direction.set(x, y, z);\n this.position = this.direction.negate();\n this._shadowManager.clearProjectMatrixCache();\n }\n dispose() {\n for (const [l, e] of this._originalLightEnabledMap) {\n l.setEnabled(e);\n }\n this._originalLightEnabledMap.clear();\n if (this._shadowManager)\n this._shadowManager.dispose();\n this._shadowManager = undefined;\n this._sg = undefined;\n super.dispose();\n }\n }\n\n const SEGMENTS = 12;\n const RADIUS = 0.05;\n const DELTA_PHI = Math.PI / (2 * SEGMENTS);\n const LINE_WIDTH = 0.02;\n const FRAME_RATE = 1 / 0.3;\n class XrMarker extends Mesh {\n constructor(v, scene, naturalScale) {\n super('xrMarker', scene);\n this.v = v;\n this.scene = scene;\n this.naturalScale = naturalScale;\n this.subscription = new Subscription();\n if (!XrMarker.MarkerMaterial) {\n const m = (XrMarker.MarkerMaterial = new StandardMaterial('xrMarkerMaterial', this.scene));\n m.emissiveColor = Color3.White();\n m.disableLighting = true;\n m.backFaceCulling = false;\n m.alpha = 0.5;\n }\n this.material = XrMarker.MarkerMaterial;\n this.resize();\n }\n place(rootNode) {\n this.setParent(rootNode);\n this.rotation.set(0, 0, 0);\n this._placed = true;\n this.resize();\n this.hide();\n this.subscription.add(this.v.bbCache.rootBoundingBoxChanged.subscribe(bb => {\n this.resizeToBoundingBox(this.v.bbCache.getWorld(this.v.sceneNode));\n }));\n }\n show() {\n this.animateVisibility(1, EasingFunction.EASINGMODE_EASEIN);\n }\n hide() {\n this.animateVisibility(0, EasingFunction.EASINGMODE_EASEOUT);\n }\n animateVisibility(to, easingFunction) {\n const a = new Animation('hide', 'visibility', FRAME_RATE, Animation.ANIMATIONTYPE_FLOAT);\n a.setKeys([\n {\n frame: 0,\n value: this.visibility,\n },\n {\n frame: 1,\n value: to,\n },\n ]);\n const easing = new SineEase();\n easing.setEasingMode(easingFunction);\n a.setEasingFunction(easing);\n this.scene.stopAnimation(this);\n this.scene.beginDirectAnimation(this, [a], 0, 1, false);\n }\n resize() {\n const bb = this.v.bbCache.get(this.v.sceneNode);\n if (bb) {\n this.resizeToBoundingBox(bb);\n }\n }\n resizeToBoundingBox(bb) {\n let deltaZ;\n let deltaX;\n if (!this._placed) {\n deltaX = (bb.max.x - bb.min.x) * this.naturalScale;\n deltaZ = (bb.max.z - bb.min.z) * this.naturalScale;\n this._lineWidth = LINE_WIDTH;\n this._radius = RADIUS;\n }\n else {\n deltaX = bb.max.x - bb.min.x;\n deltaZ = bb.max.z - bb.min.z;\n this._lineWidth = LINE_WIDTH / this.naturalScale;\n this._radius = RADIUS / this.naturalScale;\n }\n const vertexData = this.getVertexData(deltaX, deltaZ);\n vertexData.applyToMesh(this, true);\n if (this._placed) {\n //it's in the root node now, so center to the root node local bb\n this.position.set(bb.center.x, 0, bb.center.z);\n }\n }\n getVertexData(xSize, zSize) {\n const vertices = [];\n const indices = [];\n const normals = [];\n const x = xSize / 2;\n const z = zSize / 2;\n this.addCorner(vertices, x, z);\n this.addCorner(vertices, -x, z);\n this.addCorner(vertices, -x, -z);\n this.addCorner(vertices, x, -z);\n const numVertices = vertices.length / 3;\n for (let i = 0; i < numVertices - 2; i += 2) {\n indices.push(i, i + 1, i + 3, i, i + 3, i + 2);\n }\n const i = numVertices - 2;\n indices.push(i, i + 1, 1, i, 1, 0);\n VertexData.ComputeNormals(vertices, indices, normals);\n const vdata = new VertexData();\n vdata.indices = indices;\n vdata.positions = vertices;\n vdata.normals = normals;\n return vdata;\n }\n addCorner(vertices, cornerX, cornerZ) {\n let phi = cornerX > 0 ? (cornerZ > 0 ? 0 : -Math.PI / 2) : cornerZ > 0 ? Math.PI / 2 : Math.PI;\n for (let i = 0; i <= SEGMENTS; ++i) {\n vertices.push(cornerX + (this._radius - this._lineWidth) * Math.cos(phi), 0, cornerZ + (this._radius - this._lineWidth) * Math.sin(phi), cornerX + this._radius * Math.cos(phi), 0, cornerZ + this._radius * Math.sin(phi));\n phi += DELTA_PHI;\n }\n }\n dispose() {\n this.subscription.unsubscribe();\n super.dispose();\n }\n }\n\n // Do not edit.\n const name$2t = \"imageProcessingCompatibility\";\n const shader$2t = `#ifdef IMAGEPROCESSINGPOSTPROCESS\ngl_FragColor.rgb=pow(gl_FragColor.rgb,vec3(2.2));\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2t] = shader$2t;\n\n // Do not edit.\n const name$2u = \"shadowOnlyPixelShader\";\n const shader$2u = `precision highp float;uniform vec4 vEyePosition;uniform float alpha;uniform vec3 shadowColor;varying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;float shadow=1.;float glossiness=0.;\n#include[0..1]\nvec4 color=vec4(shadowColor,(1.0-clamp(shadow,0.,1.))*alpha);\n#include\ngl_FragColor=color;\n#include\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2u] = shader$2u;\n\n // Do not edit.\n const name$2v = \"shadowOnlyVertexShader\";\n const shader$2v = `precision highp float;attribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n#include\n#include\nuniform mat4 view;uniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(position,1.0);gl_Position=viewProjection*worldPos;vPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#include\n#include\n#include[0..maxSimultaneousLights]\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2v] = shader$2v;\n\n class ShadowOnlyMaterialDefines extends MaterialDefines {\n constructor() {\n super();\n this.CLIPPLANE = false;\n this.CLIPPLANE2 = false;\n this.CLIPPLANE3 = false;\n this.CLIPPLANE4 = false;\n this.CLIPPLANE5 = false;\n this.CLIPPLANE6 = false;\n this.POINTSIZE = false;\n this.FOG = false;\n this.NORMAL = false;\n this.NUM_BONE_INFLUENCERS = 0;\n this.BonesPerMesh = 0;\n this.INSTANCES = false;\n this.IMAGEPROCESSINGPOSTPROCESS = false;\n this.SKIPFINALCOLORCLAMP = false;\n this.rebuild();\n }\n }\n class ShadowOnlyMaterial extends PushMaterial {\n constructor(name, scene) {\n super(name, scene);\n this._needAlphaBlending = true;\n this.shadowColor = Color3.Black();\n }\n needAlphaBlending() {\n return this._needAlphaBlending;\n }\n needAlphaTesting() {\n return false;\n }\n getAlphaTestTexture() {\n return null;\n }\n get activeLight() {\n return this._activeLight;\n }\n set activeLight(light) {\n this._activeLight = light;\n }\n _getFirstShadowLightForMesh(mesh) {\n for (const light of mesh.lightSources) {\n if (light.shadowEnabled) {\n return light;\n }\n }\n return null;\n }\n // Methods\n isReadyForSubMesh(mesh, subMesh, useInstances) {\n var _a;\n if (this.isFrozen) {\n if (subMesh.effect && subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\n return true;\n }\n }\n if (!subMesh.materialDefines) {\n subMesh.materialDefines = new ShadowOnlyMaterialDefines();\n }\n const defines = subMesh.materialDefines;\n const scene = this.getScene();\n if (this._isReadyForSubMesh(subMesh)) {\n return true;\n }\n const engine = scene.getEngine();\n // Ensure that active light is the first shadow light\n if (this._activeLight) {\n for (const light of mesh.lightSources) {\n if (light.shadowEnabled) {\n if (this._activeLight === light) {\n break; // We are good\n }\n const lightPosition = mesh.lightSources.indexOf(this._activeLight);\n if (lightPosition !== -1) {\n mesh.lightSources.splice(lightPosition, 1);\n mesh.lightSources.splice(0, 0, this._activeLight);\n }\n break;\n }\n }\n }\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false);\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);\n defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);\n const shadowGenerator = (_a = this._getFirstShadowLightForMesh(mesh)) === null || _a === void 0 ? void 0 : _a.getShadowGenerator();\n this._needAlphaBlending = true;\n if (shadowGenerator && shadowGenerator.getClassName && shadowGenerator.getClassName() === \"CascadedShadowGenerator\") {\n const csg = shadowGenerator;\n this._needAlphaBlending = !csg.autoCalcDepthBounds;\n }\n // Attribs\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);\n // Get correct effect\n if (defines.isDirty) {\n defines.markAsProcessed();\n scene.resetCachedMaterial();\n // Fallbacks\n const fallbacks = new EffectFallbacks();\n if (defines.FOG) {\n fallbacks.addFallback(1, \"FOG\");\n }\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);\n if (defines.NUM_BONE_INFLUENCERS > 0) {\n fallbacks.addCPUSkinningFallback(0, mesh);\n }\n defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;\n //Attributes\n const attribs = [VertexBuffer.PositionKind];\n if (defines.NORMAL) {\n attribs.push(VertexBuffer.NormalKind);\n }\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\n const shaderName = \"shadowOnly\";\n const join = defines.toString();\n const uniforms = [\"world\", \"view\", \"viewProjection\", \"vEyePosition\", \"vLightsType\", \"vFogInfos\", \"vFogColor\", \"pointSize\", \"alpha\", \"shadowColor\", \"mBones\"];\n const samplers = new Array();\n const uniformBuffers = new Array();\n addClipPlaneUniforms(uniforms);\n MaterialHelper.PrepareUniformsAndSamplersList({\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: defines,\n maxSimultaneousLights: 1,\n });\n subMesh.setEffect(scene.getEngine().createEffect(shaderName, {\n attributes: attribs,\n uniformsNames: uniforms,\n uniformBuffersNames: uniformBuffers,\n samplers: samplers,\n defines: join,\n fallbacks: fallbacks,\n onCompiled: this.onCompiled,\n onError: this.onError,\n indexParameters: { maxSimultaneousLights: 1 },\n }, engine), defines, this._materialContext);\n }\n if (!subMesh.effect || !subMesh.effect.isReady()) {\n return false;\n }\n defines._renderId = scene.getRenderId();\n subMesh.effect._wasPreviouslyReady = true;\n subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;\n return true;\n }\n bindForSubMesh(world, mesh, subMesh) {\n const scene = this.getScene();\n const defines = subMesh.materialDefines;\n if (!defines) {\n return;\n }\n const effect = subMesh.effect;\n if (!effect) {\n return;\n }\n this._activeEffect = effect;\n // Matrices\n this.bindOnlyWorldMatrix(world);\n this._activeEffect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\n // Bones\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect);\n if (this._mustRebind(scene, effect)) {\n // Clip plane\n bindClipPlane(effect, this, scene);\n // Point size\n if (this.pointsCloud) {\n this._activeEffect.setFloat(\"pointSize\", this.pointSize);\n }\n this._activeEffect.setFloat(\"alpha\", this.alpha);\n this._activeEffect.setColor3(\"shadowColor\", this.shadowColor);\n scene.bindEyePosition(effect);\n }\n // Lights\n if (scene.lightsEnabled) {\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);\n const light = this._getFirstShadowLightForMesh(mesh);\n if (light) {\n // Make sure the uniforms for this light will be rebound for other materials using this light when rendering the current frame.\n // Indeed, there is an optimization in Light that binds the light uniforms only once per frame for a given light (if using ubo).\n // Doing this way assumes that all uses of this light are the same, meaning all parameters passed to Light._bindLlight\n // are the same, notably useSpecular. However, isReadyForSubMesh (see above) is passing false for this parameter, which may not be\n // the value the other materials may pass.\n light._renderId = -1;\n }\n }\n // View\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || defines[\"SHADOWCSM0\"]) {\n this._activeEffect.setMatrix(\"view\", scene.getViewMatrix());\n }\n // Fog\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);\n this._afterBind(mesh, this._activeEffect);\n }\n clone(name) {\n return SerializationHelper.Clone(() => new ShadowOnlyMaterial(name, this.getScene()), this);\n }\n serialize() {\n const serializationObject = super.serialize();\n serializationObject.customType = \"BABYLON.ShadowOnlyMaterial\";\n return serializationObject;\n }\n getClassName() {\n return \"ShadowOnlyMaterial\";\n }\n // Statics\n static Parse(source, scene, rootUrl) {\n return SerializationHelper.Parse(() => new ShadowOnlyMaterial(source.name, scene), source, scene, rootUrl);\n }\n }\n RegisterClass(\"BABYLON.ShadowOnlyMaterial\", ShadowOnlyMaterial);\n\n /** padding in size to make enough space for shadow blur */\n const SIZE_RATIO = 4;\n class XrShadowPlane extends Mesh {\n constructor(v, scene) {\n super('xrShadowPlane', scene);\n this.v = v;\n this.scene = scene;\n this.subscription = new Subscription();\n this.receiveShadows = true;\n this.isPickable = false;\n this.shadowMaterial = new ShadowOnlyMaterial('xrShadowMaterial', scene);\n this.shadowMaterial.alpha = 0.4;\n this.material = this.shadowMaterial;\n // this.material = v.rendererManager.material.defaultMaterial;\n this.setEnabled(false);\n }\n place(rootNode) {\n this.setParent(rootNode);\n const bbCache = this.v.bbCache;\n const bb = bbCache.get(this.v.sceneNode);\n if (bb) {\n this.resize(bb);\n this.setEnabled(true);\n this.subscription.add(bbCache.rootBoundingBoxChanged.subscribe(newBb => {\n this.resize(bb);\n }));\n }\n }\n resize(bb) {\n const width = (bb.max.x - bb.min.x) * SIZE_RATIO;\n const height = (bb.max.z - bb.min.z) * SIZE_RATIO;\n const vertexData = VertexData.CreatePlane({\n width,\n height,\n sideOrientation: 0,\n });\n //bake in a 90 degree rotation so it's flat on the ground\n const rotMatrix = new Matrix();\n Quaternion.FromEulerAngles(Math.PI / 2, 0, 0).toRotationMatrix(rotMatrix);\n vertexData.transform(rotMatrix);\n vertexData.applyToMesh(this, true);\n this.position.set(bb.center.x, 0, bb.center.z);\n }\n dispose() {\n this.subscription.unsubscribe();\n super.dispose();\n if (this.shadowMaterial)\n this.shadowMaterial.dispose();\n }\n }\n\n class XrTransientHitTester {\n constructor(sessionMgr) {\n this.sessionMgr = sessionMgr;\n }\n initialize(offsetRay) {\n const session = this.sessionMgr.session;\n return session.requestHitTestSourceForTransientInput({\n profile: 'generic-touchscreen',\n offsetRay: offsetRay,\n }).then(hitSource => {\n return (this.source = hitSource);\n });\n }\n getFingers(frame) {\n if (!this.source)\n return [];\n const fingers = frame.getHitTestResultsForTransientInput(this.source);\n if (!fingers.length)\n return [];\n const convertedFingers = new Array();\n for (const f of fingers) {\n const r = {\n inputSource: f.inputSource,\n results: [],\n };\n convertedFingers.push(r);\n for (const hit of f.results) {\n const convertedHit = XrHitTester.FromXRHitTestResult(hit, this.sessionMgr.referenceSpace);\n if (convertedHit)\n r.results.push(convertedHit);\n }\n }\n return convertedFingers;\n }\n dispose() {\n if (this.source) {\n this.source.cancel();\n this.source = undefined;\n }\n }\n }\n\n // interface XRSystem extends EventTarget {\n // requestSession(mode: XRSessionMode, options?: XRSessionInit): Promise;\n // isSessionSupported(mode: XRSessionMode): Promise;\n // }\n // declare global {\n // interface Navigator {\n // xr?: XRSystem;\n // }\n // }\n var eXrState;\n (function (eXrState) {\n eXrState[eXrState[\"searchingForHit\"] = 0] = \"searchingForHit\";\n eXrState[eXrState[\"initialPlacement\"] = 1] = \"initialPlacement\";\n eXrState[eXrState[\"placed\"] = 2] = \"placed\";\n })(eXrState || (eXrState = {}));\n const ROTATION_RATE = 1.5;\n const SCALE_SNAP = 1.2;\n class Xr {\n constructor(v, scene) {\n this.v = v;\n this.scene = scene;\n this.onSessionEnd = new Subject();\n this._state = eXrState.searchingForHit;\n this._goalScale = 0;\n this._goalYaw = 0;\n this._lastScalar = 0;\n this._scaleSnapHigh = SCALE_SNAP;\n this._scaleSnapLow = 1 / SCALE_SNAP;\n this._naturalScale = 1;\n this._wasJustPlaced = false;\n this._lightingEstimationCount = 0;\n this.onSelectStart = (event) => {\n var _a;\n if (this._state == eXrState.initialPlacement) {\n this.placeModel();\n this._state = eXrState.placed;\n this._initialHitTester.dispose();\n this._initialHitTester = undefined;\n this._transientHitTester = new XrTransientHitTester(this._sessionMgr);\n this._transientHitTester.initialize();\n this._wasJustPlaced = true;\n }\n else if (this._state == eXrState.placed) {\n const fingers = (_a = this._transientHitTester) === null || _a === void 0 ? void 0 : _a.getFingers(this._lastFrame);\n if ((fingers === null || fingers === void 0 ? void 0 : fingers.length) === 1) {\n /** for one finger we do a hit test on kb3d to see if they pressed the model */\n this._selectStartScreenPos = this.screenNdcToPixels(event.inputSource.gamepad.axes); //get the screen coordinates of the finger press\n const pickInfo = this.pick(this._selectStartScreenPos);\n if (pickInfo) {\n // console.log({ pickInfo });\n this._isTranslating = true;\n this._dragNodeStartPos = this._rootNode.position.clone();\n // this._dragNodeStartScreenPos = toScreen(this._rootNode.absolutePosition, this.getRigCamera());\n // this._fingerStartScreenPos = this.screenNdcToPixels(fingers[0].inputSource.gamepad!.axes);\n const dragHitTester = new XrTransientHitTester(this._sessionMgr);\n const offset = this._dragNodeStartPos.subtract(pickInfo.pickedPoint.toVec3());\n // console.log({nodePos: this._dragNodeStartPos, pickedPoint: pickInfo.pickedPoint});\n const offsetRay = new XRRay(offset);\n dragHitTester.initialize(offsetRay).then(() => {\n this._dragHitTester = dragHitTester;\n });\n }\n else {\n this._isRotating = true;\n this._goalYaw = this._rootNode.rotation.y;\n this._lastScalar = event.inputSource.gamepad.axes[0];\n }\n //simulate pointer down observable\n const args = this.v.interaction.getKb3dPointerArgs({\n type: PointerEventTypes.POINTERDOWN,\n event: new PointerEvent('pointerdown', { pointerId: event.inputSource.gamepad.id }),\n pickInfo: pickInfo,\n });\n this.v.interaction.handlePointerDown(args);\n this._marker.show();\n }\n else if ((fingers === null || fingers === void 0 ? void 0 : fingers.length) === 2 && this.v.sceneNode.xrAllowScaling) {\n this._isScaling = true;\n this._lastScalar = this.getFingerSeparation(fingers) / this._rootNode.scaling.x;\n this._marker.show();\n }\n }\n };\n this.onSelectEnd = (event) => {\n var _a;\n this._isTranslating = false;\n this._isRotating = false;\n this._isScaling = false;\n if (this._dragHitTester) {\n this._dragHitTester.dispose();\n }\n this._dragHitTester = undefined;\n this._fingerStartPos = undefined;\n //simulate pointer up observable\n const fingers = (_a = this._transientHitTester) === null || _a === void 0 ? void 0 : _a.getFingers(this._lastFrame);\n const screenCoord = this.screenNdcToPixels(event.inputSource.gamepad.axes); //get the screen coordinates of the finger press\n const pickInfo = this.pick(screenCoord);\n const args = this.v.interaction.getKb3dPointerArgs({\n type: PointerEventTypes.POINTERUP,\n event: new PointerEvent('pointerup', { pointerId: event.inputSource.gamepad.id }),\n pickInfo: pickInfo,\n });\n this.v.interaction.handlePointerUp(args);\n //simulate the pointer tap observable if the input hasn't moved much\n if (this._state == eXrState.placed) {\n if ((fingers === null || fingers === void 0 ? void 0 : fingers.length) === 1 && !this._wasJustPlaced) {\n const deltaScreen = Vector2.Distance(this._selectStartScreenPos || screenCoord, screenCoord);\n if (deltaScreen < 5) {\n const args = this.v.interaction.getKb3dPointerArgs({\n type: PointerEventTypes.POINTERTAP,\n event: new PointerEvent('pointertap', { pointerId: event.inputSource.gamepad.id }),\n pickInfo: pickInfo,\n });\n this.v.interaction.handleClick(args);\n }\n }\n this._marker.hide();\n this._wasJustPlaced = false;\n }\n };\n }\n startSession(mode, refSpaceType, overlayElem) {\n var _a, _b;\n const xrInitOptions = {\n optionalFeatures: ['light-estimation'],\n requiredFeatures: ['hit-test'],\n };\n if (overlayElem) {\n overlayElem.addEventListener('beforexrselect', ev => {\n if (ev.target != overlayElem) {\n ev.preventDefault();\n }\n });\n (_a = xrInitOptions.optionalFeatures) === null || _a === void 0 ? void 0 : _a.push('dom-overlay');\n xrInitOptions.domOverlay = {\n root: overlayElem,\n };\n }\n if (refSpaceType !== 'viewer' && refSpaceType !== 'local') {\n (_b = xrInitOptions.optionalFeatures) === null || _b === void 0 ? void 0 : _b.push(refSpaceType);\n }\n this._naturalScale = 1 / this.v.sceneNode.unitsPerMeter;\n this._sessionMgr = new WebXRSessionManager(this.scene);\n this._sessionMgr.onXRSessionEnded.addOnce(() => this.sessionEnded());\n this._xrCamera = new WebXRCamera('', this.scene, this._sessionMgr);\n return this._sessionMgr\n .initializeAsync()\n .then(() => {\n this._renderTarget = this._sessionMgr.getWebXRRenderTarget();\n return this._sessionMgr.initializeSessionAsync(mode, xrInitOptions).then(() => {\n this._session = this._sessionMgr.session;\n });\n })\n .then(() => {\n return this._sessionMgr.setReferenceSpaceTypeAsync(refSpaceType).then(refSpace => {\n this._refSpace = refSpace;\n });\n })\n .then(() => {\n return this._renderTarget.initializeXRLayerAsync(this._sessionMgr.session);\n })\n .then(() => {\n return this._sessionMgr.updateRenderState({\n depthFar: this._xrCamera.maxZ,\n depthNear: this._xrCamera.minZ,\n baseLayer: this._renderTarget.xrLayer,\n });\n })\n .then(() => {\n this._rootNode = this.v.rendererManager.sceneRenderer.get3d(this.v.sceneNode); //get the root transform node for our scene... this is what we will move to position the scene in AR\n this._rootNode.setEnabled(false);\n //subscribe to render loop\n this._sessionMgr.onXRFrameObservable.add((frame) => this.onXRFrame(frame));\n this._sessionMgr.runXRRenderLoop(); //start the render loop\n this._originalSceneCamera = this.scene.activeCamera;\n this.scene.activeCamera = this._xrCamera; //this line is important\n this.scene.autoClear = false;\n this._xrCamera.compensateOnFirstFrame = false;\n this._originalBackground = this.v.sceneNode.background;\n this.v.sceneNode.background = exports.eBackground.transparent;\n //add xr input handlers\n this._session.addEventListener('selectstart', this.onSelectStart);\n this._session.addEventListener('selectend', this.onSelectEnd);\n this._initialHitTester = new XrHitTester(this._sessionMgr);\n return this._initialHitTester.initialize();\n });\n }\n endSession() {\n if (this._sessionMgr) {\n this.sessionEndingPromise = this._sessionMgr.exitXRAsync();\n return this.sessionEndingPromise;\n }\n else {\n return Promise.resolve();\n }\n }\n sessionEnded() {\n if (this.sessionEndingPromise) {\n this.sessionEndingPromise.then(() => {\n this.sessionEndingPromise = undefined;\n this.sessionEnded();\n });\n }\n else {\n this._session.removeEventListener('selectstart', this.onSelectStart);\n this._session.removeEventListener('selectend', this.onSelectEnd);\n if (this._xrCamera)\n this._xrCamera.dispose();\n if (this._sessionMgr)\n this._sessionMgr.dispose();\n if (this._renderTarget)\n this._renderTarget.dispose();\n if (this._initialHitTester)\n this._initialHitTester.dispose();\n if (this._marker)\n this._marker.dispose();\n if (this._light)\n this._light.dispose();\n if (this._shadow)\n this._shadow.dispose();\n if (this._originalSceneCamera) {\n this.scene.activeCamera = this._originalSceneCamera;\n }\n this.scene.autoClear = true;\n this.v.sceneNode.background = this._originalBackground || exports.eBackground.transparent;\n this._rootNode.scaling = Vector3.One();\n this._rootNode.rotation = Vector3.Zero();\n this._rootNode.position = Vector3.Zero();\n this._rootNode.setEnabled(true);\n this.onSessionEnd.next();\n }\n }\n onXRFrame(frame) {\n this._lastFrame = frame;\n //console.log(`user height: ${this._xrCamera.realWorldHeight}`);\n this._viewerPose = frame.getViewerPose(this._sessionMgr.referenceSpace);\n this.placeInitialMarker(frame);\n this.processInput(frame);\n this.setSceneTransform();\n this.runLightingEstimation(frame);\n }\n runLightingEstimation(frame) {\n if (this._lightProbe) {\n this._lightingEstimationCount++;\n if (this._lightingEstimationCount == 30) {\n this._lightingEstimationCount = 0;\n const estimate = frame.getLightEstimate(this._lightProbe);\n // const probePose = frame.getPose(this._lightProbe.probeSpace, this._refSpace);\n // console.log({probePose});\n // console.log({ lightEstimate: estimate });\n if (estimate && this._light) {\n const direction = new Vector3(estimate.primaryLightDirection.x, estimate.primaryLightDirection.y, estimate.primaryLightDirection.z);\n direction.negateInPlace();\n this._light.setDirection(direction.x, direction.y, direction.z);\n const intensity = Math.max(1.0, Math.max(estimate.primaryLightIntensity.x, Math.max(estimate.primaryLightIntensity.y, estimate.primaryLightIntensity.z)));\n this._light.specular.set(estimate.primaryLightIntensity.x / intensity, estimate.primaryLightIntensity.y / intensity, estimate.primaryLightIntensity.z / intensity);\n this._light.diffuse.set(estimate.primaryLightIntensity.x / intensity, estimate.primaryLightIntensity.y / intensity, estimate.primaryLightIntensity.z / intensity);\n this._light.intensity = intensity;\n }\n }\n }\n }\n placeInitialMarker(frame) {\n if (this._state == eXrState.searchingForHit || this._state == eXrState.initialPlacement) {\n const hit = this._initialHitTester.getHitResult(frame);\n if (!hit)\n return;\n if (this._state == eXrState.searchingForHit) {\n if (!this._marker) {\n this._marker = new XrMarker(this.v, this.scene, this._naturalScale);\n this._marker.setEnabled(true);\n }\n this._state = eXrState.initialPlacement; //we got our first hit so we change state\n }\n if (this._state == eXrState.initialPlacement) {\n const quat = new Quaternion();\n hit.matrix.decompose(this._marker.scaling, quat, this._marker.position);\n this._marker.rotation = quat.toEulerAngles();\n // console.log(JSON.stringify({ markerPosition: this._marker.position }));\n }\n }\n }\n processInput(frame) {\n if (this._state == eXrState.placed && (this._isTranslating || this._isRotating || this._isScaling)) {\n const fingers = this._transientHitTester.getFingers(frame);\n if (this._isScaling) {\n if (fingers.length < 2) {\n //the user removed their 2nd finger, so the scale is cancelled\n this._isScaling = false;\n }\n else {\n const separation = this.getFingerSeparation(fingers);\n const scale = separation / this._lastScalar;\n this._goalScale =\n scale < this._scaleSnapHigh && scale > this._scaleSnapLow ? this._naturalScale : scale;\n }\n }\n else if (fingers.length === 2 && this.v.sceneNode.xrAllowScaling) {\n // happens when translating or rotating and another finger was added. We switch to scaling in this instance\n this._isTranslating = false;\n this._isRotating = false;\n this._isScaling = true;\n const scale = this._rootNode.scaling.x;\n this._lastScalar = this.getFingerSeparation(fingers) / scale;\n }\n else if (this._isRotating) {\n const inputSource = fingers[0].inputSource;\n const dragX = inputSource.gamepad.axes[0];\n this._goalYaw += (dragX - this._lastScalar) * ROTATION_RATE;\n this._lastScalar = dragX;\n }\n else if (this._isTranslating) {\n if (fingers.length > 0 && this._dragHitTester) {\n const dragFingers = this._dragHitTester.getFingers(frame);\n if (dragFingers.length && dragFingers[0].results.length) {\n const dragFinger = dragFingers[0];\n const dragFingerResult = dragFinger.results[0];\n if (!this._fingerStartPos)\n this._fingerStartPos = dragFingerResult.position;\n const deltaPos = dragFingerResult.position.subtract(this._fingerStartPos);\n this._goalPosition = this._dragNodeStartPos.add(deltaPos);\n }\n }\n }\n }\n }\n placeModel() {\n this._goalPosition = this._marker.position.clone();\n this._goalYaw = this._marker.rotation.y;\n this._goalScale = this._naturalScale;\n this._scaleSnapHigh = this._naturalScale * SCALE_SNAP;\n this._scaleSnapLow = this._naturalScale / SCALE_SNAP;\n //we now add the marker to the root node so it can scale and move with the model\n this._marker.place(this._rootNode);\n if (this.v.sceneNode.xrAddShadow) {\n this._shadow = new XrShadowPlane(this.v, this.scene);\n this._shadow.place(this._rootNode);\n this._light = new XrLight(this.v, this.scene);\n if (this.v.sceneNode.xrLightingEstimation && this._session.requestLightProbe) {\n this._session.requestLightProbe().then(lp => (this._lightProbe = lp));\n }\n }\n this._rootNode.setEnabled(true);\n //this._marker.setEnabled(false);\n this._state = eXrState.placed;\n }\n /** does a pick of the kb3d scene (NOT a webxr hit test). Accepts x/y as screen pixel coordinates */\n pick(screenCoord) {\n /**\n * The WebXRCamera in babylon appears to be for reference only, and it's position/rotation\n * are updated on each frame to be the same as the viewer pose from XR.\n *\n * However, the forward ray from the WebXRCamera is not what we would expect, it's pointing\n * in exactly the opposite direction. However, inside the WebXRCamera are rig cameras (only 1\n * in the case of AR) who are responsible for actually doing the babylon rendering. The rig\n * camera direction is what we would expect. For now we are using the rig camera to do\n * the picking, but we should keep an eye on this part as new babylon/webxr releases come out,\n * as something seems amiss.\n */\n const hardwareScale = this.scene.getEngine().getHardwareScalingLevel();\n /** adjust by hardware scale as webxr does not support it, but the pick routine uses it */\n const pickInfo = this.v.interaction.pick(screenCoord.x * hardwareScale, screenCoord.y * hardwareScale, this.getRigCamera());\n return pickInfo;\n }\n getFingerSeparation(fingers) {\n const firstFinger = fingers[0].inputSource.gamepad.axes;\n const secondFinger = fingers[1].inputSource.gamepad.axes;\n const deltaX = secondFinger[0] - firstFinger[0];\n const deltaY = secondFinger[1] - firstFinger[1];\n return Math.sqrt(deltaX * deltaX + deltaY * deltaY);\n }\n /** set's the transforms of the scene to the goal values */\n setSceneTransform() {\n if (this._state == eXrState.placed) {\n let invalidateRootBoundingBox = false;\n if (this._rootNode.scaling.x != this._goalScale) {\n this._rootNode.scaling = new Vector3(this._goalScale, this._goalScale, this._goalScale);\n invalidateRootBoundingBox = true;\n }\n if (this._rootNode.rotation.y != this._goalYaw) {\n this._rootNode.rotation.y = this._goalYaw; // = Quaternion.FromEulerAngles(0, this._goalYaw, 0);\n // this._marker.rotation.y = this._goalYaw;\n invalidateRootBoundingBox = true;\n }\n if (this._goalPosition &&\n !this._goalPosition.equalsToFloats(this._rootNode.position.x, this._rootNode.position.y, this._rootNode.position.z)) {\n this._rootNode.position.set(this._goalPosition.x, this._goalPosition.y, this._goalPosition.z);\n //this._marker.position.set(this._goalPosition.x, this._goalPosition.y, this._goalPosition.z);\n invalidateRootBoundingBox = true;\n }\n if (invalidateRootBoundingBox) {\n this.v.bbCache.invalidate(this.v.sceneNode);\n }\n }\n }\n getRigCamera() {\n const rigCamera = this._xrCamera.rigCameras[0];\n return rigCamera;\n }\n screenNdcToPixels(axes) {\n const canvas = this.scene.getEngine().getRenderingCanvas();\n //need to convert NDC units to pixels\n const x = (axes[0] + 1) * (canvas.width / 2);\n const y = (axes[1] + 1) * (canvas.height / 2);\n return new Vector2(x, y);\n }\n screenPixelsToNdc(pos) {\n const canvas = this.scene.getEngine().getRenderingCanvas();\n return {\n x: pos.x / (canvas.width / 2) - 1,\n y: pos.y / (canvas.height / 2) - 2,\n };\n }\n }\n\n const IS_IOS = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); //https://stackoverflow.com/a/58065241\n const IS_ANDROID = /android/i.test(navigator.userAgent);\n class AR {\n constructor(v, scene) {\n this.v = v;\n this.scene = scene;\n this.isDebug = false;\n this.xrActive = false;\n this.xrLoading = false;\n this.onSessionEnd = new Subject();\n this.isDebug = !!v.options.debugMode;\n this.gltfExporter = new GLTFKb3dExporter(scene);\n }\n toggle() {\n if (this.xrActive) {\n return this.end();\n }\n else {\n return this.start();\n }\n }\n start(overlayElem, onEnterFunc) {\n // Have to use a callback because android should run this after entering XR, but ios must run it before entering XR\n if (!onEnterFunc) {\n onEnterFunc = () => Promise.resolve();\n }\n const _onEnterFunc = onEnterFunc;\n if (IS_ANDROID) {\n return this.startWebXR(overlayElem).then(() => _onEnterFunc());\n }\n else if (IS_IOS || this.isDebug) {\n const usdz = new USDZBabylonConverter();\n if (this.v.sceneNode) {\n const self = this;\n return this.v\n .whenAssetsLoaded()\n .then(() => _onEnterFunc())\n .then(() => this.v.forceAndWaitForNextRender())\n .then(() => usdz.parse(this.scene, this.v.sceneNode, true))\n .then(res => {\n const a = document.createElement('a');\n if (a.relList.supports('ar') || this.isDebug) {\n if (self.currentObjectUrl) {\n window.URL.revokeObjectURL(self.currentObjectUrl);\n self.currentObjectUrl = undefined;\n }\n self.currentObjectUrl = window.URL.createObjectURL(res);\n const img = document.createElement('img');\n img.src = '/images/ar_ios.png';\n a.appendChild(img);\n document.body.appendChild(a);\n a.href = self.currentObjectUrl;\n a.download = 'test.usdz';\n a.rel = 'ar';\n // Fire XR Exit right away on iOS since the USDZ is already generated and static now\n // So, whatever scene changes they want when the user exits AR should already be in the browser\n this.xrActive = false;\n this.xrLoading = false;\n this.onSessionEnd.next();\n setTimeout(() => {\n a.click();\n setTimeout(() => {\n document.body.removeChild(a);\n }, 0);\n }, 50);\n return undefined;\n }\n return Promise.reject('Your device does not support AR.');\n });\n }\n else {\n return Promise.reject('Scene not initialized');\n }\n }\n return Promise.reject('Your device does not support AR.');\n }\n end() {\n if (IS_ANDROID) {\n return this.endWebXr();\n }\n else if (IS_IOS) {\n if (this.currentObjectUrl) {\n URL.revokeObjectURL(this.currentObjectUrl);\n }\n //TODO usdz\n }\n return Promise.resolve();\n }\n startWebXR(overlayElem) {\n this._xr = new Xr(this.v, this.scene);\n this._xr.onSessionEnd.pipe(first()).subscribe(() => {\n this.xrActive = false;\n this.xrLoading = false;\n this.onSessionEnd.next();\n });\n this.xrLoading = true;\n return this._xr.startSession('immersive-ar', 'local-floor', overlayElem).then(() => {\n this.xrActive = true;\n this.xrLoading = false;\n });\n }\n endWebXr() {\n if (this._xr) {\n return this._xr.endSession();\n }\n else {\n return Promise.resolve();\n }\n }\n /**\n * Takes a URL to a USDZ file and sets the appropriate fields so that Safari\n * iOS can intent to their AR Quick Look.\n */\n startIosQuickLook(usdzSrc, canScale) {\n const anchor = document.createElement('a');\n anchor.setAttribute('rel', 'ar');\n anchor.appendChild(document.createElement('img'));\n const modelUrl = new URL(usdzSrc, self.location.toString());\n if (!canScale) {\n modelUrl.hash = 'allowsContentScaling=0';\n }\n anchor.setAttribute('href', modelUrl.toString());\n anchor.click();\n }\n }\n\n function toBoundingBoxInfo(binfo) {\n return {\n boundingInfo: binfo,\n min: exports.KbVector.FromVec3(binfo.minimum),\n max: exports.KbVector.FromVec3(binfo.maximum),\n center: exports.KbVector.FromVec3(binfo.boundingBox.center),\n };\n }\n const MAX_DIGESTS = 30;\n class BoundingBoxCache {\n constructor(v) {\n this.v = v;\n this.boundingBoxInvalidated = new Subject();\n this.rootBoundingBoxChanged = new Subject();\n this._digestCount = 0;\n this._db = new Map();\n this._watchedNodes = new Map();\n this._changedNodes = new Set(); //stored dynamic id's of changed nodes\n }\n watchForChanges(node) {\n let subject = this._watchedNodes.get(node._dynamicId);\n if (!subject) {\n subject = new BehaviorSubject(undefined);\n this._watchedNodes.set(node._dynamicId, subject);\n }\n const _subject = subject;\n // This is using an internal implementation of rxjs, hence the any. But this is the only way we can add teardown logic.\n const observable = new Observable(s => {\n s.next();\n return () => {\n setTimeout(() => {\n if (_subject.observers.length === 0) {\n _subject.complete();\n this._watchedNodes.delete(node._dynamicId);\n }\n });\n };\n });\n return observable.pipe(mergeMap(() => _subject));\n }\n refreshAndGet(node) {\n this._db.delete(node._dynamicId);\n return this.get(node);\n }\n get(node) {\n if (node && node.visible) {\n let bb = this._db.get(node._dynamicId);\n if (!bb) {\n let bbInfo;\n const bnode = this.v.rendererManager.mesh.get3d(node);\n if (node instanceof exports.MeshNode) {\n if (bnode) {\n bbInfo = bnode.getBoundingInfo();\n }\n }\n else {\n const childNodes = node.getSpaceChildren();\n const min = {};\n const max = {};\n let empty = true;\n for (const c of childNodes) {\n const cbb = this.get(c);\n // If cbb is undefined, that means the child node is not visible or doesn't exist\n if (cbb) {\n empty = false;\n const parentMin = cbb.min.toVec3();\n const parentMax = cbb.max.toVec3();\n const childBNode = this.v.rendererManager.mesh.get3d(c);\n if (childBNode) {\n const mat = Matrix.Compose(childBNode.scaling, childBNode.rotationQuaternion, childBNode.position);\n Vector3.TransformCoordinatesToRef(parentMin, mat, parentMin);\n Vector3.TransformCoordinatesToRef(parentMax, mat, parentMax);\n }\n if (min.x == null)\n min.x = parentMin.x;\n if (min.y == null)\n min.y = parentMin.y;\n if (min.z == null)\n min.z = parentMin.z;\n if (max.x == null)\n max.x = parentMax.x;\n if (max.y == null)\n max.y = parentMax.y;\n if (max.z == null)\n max.z = parentMax.z;\n min.x = Math.min(min.x, parentMin.x, parentMax.x);\n min.y = Math.min(min.y, parentMin.y, parentMax.y);\n min.z = Math.min(min.z, parentMin.z, parentMax.z);\n max.x = Math.max(max.x, parentMin.x, parentMax.x);\n max.y = Math.max(max.y, parentMin.y, parentMax.y);\n max.z = Math.max(max.z, parentMin.z, parentMax.z);\n }\n }\n if (empty) {\n return undefined; //don't consider empty groups\n }\n bbInfo = new BoundingInfo(new Vector3(min.x || 0, min.y || 0, min.z || 0), new Vector3(max.x || 0, max.y || 0, max.z || 0));\n }\n if (bbInfo) {\n bb = toBoundingBoxInfo(bbInfo);\n this._db.set(node._dynamicId, bb);\n }\n }\n return bb;\n }\n else {\n return undefined;\n }\n }\n invalidate(node) {\n if (node) {\n //when a node is invalidated, all of it's ancestors need to be invalidated\n let n = node;\n while (n && n instanceof exports.SpaceNode) {\n this._changedNodes.add(n._dynamicId);\n n = n._parent;\n }\n }\n }\n update() {\n var _a, _b;\n let boundingBoxesStable = true;\n if (this._changedNodes.size === 0) {\n return;\n }\n if (!this.v.userIsInteracting()) {\n this._digestCount++;\n }\n const watchersToUpdateAndClear = new Map();\n for (const dynamicId of this._changedNodes) {\n const n = getByDynamicId(dynamicId);\n if (!n) {\n continue;\n }\n const externalWatchers = (_a = n._manager) === null || _a === void 0 ? void 0 : _a.boundingboxChangeHandlers.getByKey(n);\n const hasRootWatchers = this.v.sceneNode._dynamicId === n._dynamicId && this.rootBoundingBoxChanged.observers.length > 0;\n const hasWatchers = this._watchedNodes.has(n._dynamicId) || (externalWatchers !== undefined && externalWatchers.length > 0);\n const oldBoundingBox = this._db.get(n._dynamicId);\n this._db.delete(n._dynamicId);\n this.boundingBoxInvalidated.next(n);\n if (!hasWatchers && !hasRootWatchers) {\n continue;\n }\n const bbInfo = this.get(n);\n const boundingBoxChanged = !boundingBoxesMatch(bbInfo, oldBoundingBox);\n const bbWatchersSubject = this._watchedNodes.get(n._dynamicId);\n if (boundingBoxChanged) {\n boundingBoxesStable = false;\n }\n if (bbWatchersSubject) {\n bbWatchersSubject.next(bbInfo);\n }\n if (externalWatchers && bbInfo) {\n for (const w of externalWatchers) {\n const once = w.mode === 'once';\n // Always call the handler if the mode is 'once', because it will be expecting an update regardless of whether it changed or not.\n // For persistent watchers, only call it if the bb actually changed.\n if (boundingBoxChanged && !once) {\n w.handler(bbInfo);\n }\n if (once) {\n watchersToUpdateAndClear.set(n, w);\n }\n }\n }\n if (hasRootWatchers && bbInfo && boundingBoxChanged) {\n this.rootBoundingBoxChanged.next(bbInfo);\n }\n }\n if (boundingBoxesStable && this._digestCount > 3) {\n this._changedNodes.clear();\n for (const [node, watcher] of watchersToUpdateAndClear.entries()) {\n const bbInfo = this.get(node);\n if (bbInfo) {\n watcher.handler(bbInfo);\n }\n (_b = node._manager) === null || _b === void 0 ? void 0 : _b.boundingboxChangeHandlers.deleteByKeyValue(node, watcher);\n }\n watchersToUpdateAndClear.clear();\n this._digestCount = 0;\n }\n else if (!boundingBoxesStable && this._digestCount > MAX_DIGESTS) {\n console.error('Bounding box digest cycle exceeded, but the meshes are not consistent');\n this._changedNodes.clear();\n watchersToUpdateAndClear.clear();\n this._digestCount = 0;\n }\n }\n /**\n * Gets the world bounding box for the specified node.\n * Be aware that this call is not cached, so use accordingly for performance reasons\n * @param node\n */\n getWorld(node) {\n if (node && node.visible) {\n const bb = this.get(node);\n if (!bb) {\n return null;\n }\n const bnode = this.v.rendererManager.mesh.get3d(node);\n const bbInfo = new BoundingInfo(new Vector3(bb.min.x || 0, bb.min.y || 0, bb.min.z || 0), new Vector3(bb.max.x || 0, bb.max.y || 0, bb.max.z || 0), bnode === null || bnode === void 0 ? void 0 : bnode.getWorldMatrix());\n return {\n boundingInfo: bbInfo,\n min: exports.KbVector.FromVec3(bbInfo.boundingBox.minimumWorld),\n max: exports.KbVector.FromVec3(bbInfo.boundingBox.maximumWorld),\n center: exports.KbVector.FromVec3(bbInfo.boundingBox.centerWorld),\n };\n }\n return null;\n }\n dispose() {\n this._db.clear();\n this._watchedNodes.forEach(subject => {\n subject.complete();\n });\n this._watchedNodes.clear();\n }\n }\n function boundingBoxesMatch(a, b) {\n if (!a && !b) {\n return true;\n }\n if (!a || !b) {\n return false;\n }\n return a.center.equal(b.center) && a.min.equal(b.min) && a.max.equal(b.max);\n }\n\n Object.defineProperty(exports.KbVector.prototype, 'toVec3', {\n enumerable: false,\n writable: true,\n value: function (ref) {\n // add ref option\n if (!ref) {\n ref = new Vector3();\n }\n return this ? ref.copyFromFloats(this.x, this.y, this.z) : ref.setAll(0);\n },\n });\n Object.defineProperty(exports.KbVector, 'FromVec3', {\n enumerable: false,\n writable: true,\n value: function (vector) {\n return new exports.KbVector(vector.x, vector.y, vector.z);\n },\n });\n Object.defineProperty(exports.KbQuaternion.prototype, 'toQuat', {\n enumerable: false,\n writable: true,\n value: function () {\n return this ? new Quaternion(this.x, this.y, this.z, this.w) : new Quaternion(0, 0, 0, 1);\n },\n });\n Object.defineProperty(exports.KbQuaternion, 'FromQuat', {\n enumerable: false,\n writable: true,\n value: function (q) {\n return new exports.KbQuaternion(q.x, q.y, q.z, q.w);\n },\n });\n Object.defineProperty(exports.KbColor.prototype, 'toColor3', {\n enumerable: false,\n writable: true,\n value: function () {\n return this ? new Color3(this.r, this.g, this.b) : Color3.Black();\n },\n });\n Object.defineProperty(exports.KbColor.prototype, 'toColor4', {\n enumerable: false,\n writable: true,\n value: function () {\n return this ? new Color4(this.r, this.g, this.b, this.a) : new Color4(0, 0, 0, 0);\n },\n });\n\n class BoundingBoxRelativeHelper {\n static convertRelativeToAbsolute(c, bb, position) {\n if (!position) {\n position = c.position;\n }\n if (isSketchControlPoint(c)) {\n return new Vector3(((position.x + 1) / 2) * bb.max.x + bb.min.x, ((position.y + 1) / 2) * bb.max.y + bb.min.y, ((position.z + 1) / 2) * bb.max.z + bb.min.z);\n }\n else {\n return new Vector3(bb.center.x + (position.x * Math.abs(bb.max.x - bb.min.x)) / 2, bb.center.y + (position.y * Math.abs(bb.max.y - bb.min.y)) / 2, bb.center.z + (position.z * Math.abs(bb.max.z - bb.min.z)) / 2);\n }\n }\n static convertAbsoluteToRelative(c, bb, position) {\n if (!position) {\n position = c.position;\n }\n if (isSketchControlPoint(c)) {\n return new Vector3(((position.x - bb.min.x) / bb.max.x) * 2 - 1, ((position.y - bb.min.y) / bb.max.y) * 2 - 1, ((position.z - bb.min.z) / bb.max.z) * 2 - 1);\n }\n else {\n return new Vector3(((position.x - bb.center.x) * 2) / Math.abs(bb.max.x - bb.min.x), ((position.y - bb.center.y) * 2) / Math.abs(bb.max.y - bb.min.y), ((position.z - bb.center.z) * 2) / Math.abs(bb.max.z - bb.min.z));\n }\n }\n static convertRelativeDirectionToAbsolute(c, direction, bb) {\n if (isSketchControlPoint(c)) {\n return new Vector3(direction.x * (bb.min.x - bb.max.x), direction.y * (bb.min.y - bb.max.y), direction.z * (bb.min.z - bb.max.z));\n }\n else {\n return new Vector3(direction.x, direction.y, direction.z);\n }\n }\n static convertAbsoluteDirectionToRelative(c, direction, bb) {\n if (isSketchControlPoint(c)) {\n return new Vector3(direction.x / (bb.min.x - bb.max.x), direction.y / (bb.min.y - bb.max.y), direction.z / (bb.min.z - bb.max.z));\n }\n else {\n return new Vector3(direction.x, direction.y, direction.z);\n }\n }\n }\n class BoundingBoxRelativeHelperKbVector {\n static convertRelativeToAbsolute(c, bb, position) {\n return exports.KbVector.FromVec3(BoundingBoxRelativeHelper.convertRelativeToAbsolute(c, bb, position));\n }\n static convertAbsoluteToRelative(c, bb, position) {\n return exports.KbVector.FromVec3(BoundingBoxRelativeHelper.convertAbsoluteToRelative(c, bb, position));\n }\n static convertRelativeDirectionToAbsolute(c, direction, bb) {\n return exports.KbVector.FromVec3(BoundingBoxRelativeHelper.convertRelativeDirectionToAbsolute(c, direction, bb));\n }\n static convertAbsoluteDirectionToRelative(c, direction, bb) {\n return exports.KbVector.FromVec3(BoundingBoxRelativeHelper.convertAbsoluteDirectionToRelative(c, direction, bb));\n }\n }\n\n (function (eSideOrientationBabylonMap) {\n eSideOrientationBabylonMap[eSideOrientationBabylonMap[\"frontSide\"] = 0] = \"frontSide\";\n eSideOrientationBabylonMap[eSideOrientationBabylonMap[\"backSide\"] = 1] = \"backSide\";\n eSideOrientationBabylonMap[eSideOrientationBabylonMap[\"doubleSide\"] = 2] = \"doubleSide\";\n })(exports.eSideOrientationBabylonMap || (exports.eSideOrientationBabylonMap = {}));\n (function (eUvMapAxisBabylonMap) {\n eUvMapAxisBabylonMap[eUvMapAxisBabylonMap[\"x\"] = 0] = \"x\";\n eUvMapAxisBabylonMap[eUvMapAxisBabylonMap[\"y\"] = 1] = \"y\";\n eUvMapAxisBabylonMap[eUvMapAxisBabylonMap[\"z\"] = 2] = \"z\";\n })(exports.eUvMapAxisBabylonMap || (exports.eUvMapAxisBabylonMap = {}));\n (function (eUvModeBabylonMap) {\n eUvModeBabylonMap[eUvModeBabylonMap[\"planar\"] = 0] = \"planar\";\n eUvModeBabylonMap[eUvModeBabylonMap[\"box\"] = 1] = \"box\";\n eUvModeBabylonMap[eUvModeBabylonMap[\"cylindrical\"] = 2] = \"cylindrical\";\n eUvModeBabylonMap[eUvModeBabylonMap[\"spherical\"] = 3] = \"spherical\";\n })(exports.eUvModeBabylonMap || (exports.eUvModeBabylonMap = {}));\n (function (eAlphaModeBabylonMap) {\n eAlphaModeBabylonMap[eAlphaModeBabylonMap[\"disable\"] = 0] = \"disable\";\n eAlphaModeBabylonMap[eAlphaModeBabylonMap[\"add\"] = 1] = \"add\";\n eAlphaModeBabylonMap[eAlphaModeBabylonMap[\"combine\"] = 2] = \"combine\";\n eAlphaModeBabylonMap[eAlphaModeBabylonMap[\"subtract\"] = 3] = \"subtract\";\n eAlphaModeBabylonMap[eAlphaModeBabylonMap[\"multiply\"] = 4] = \"multiply\";\n })(exports.eAlphaModeBabylonMap || (exports.eAlphaModeBabylonMap = {}));\n\n function convertHdrToEnv(hdrFile, hdrSize) {\n return new Observable(subject => {\n const dataUri = URL.createObjectURL(hdrFile);\n const canvas = document.createElement('canvas');\n const dummyEngine = new Engine(canvas, true, {\n premultipliedAlpha: false,\n });\n const env = new HDRCubeTexture(dataUri, dummyEngine, hdrSize, false, true, false, true, () => {\n EnvironmentTextureTools.CreateEnvTextureAsync(env).then(buffer => {\n URL.revokeObjectURL(dataUri);\n dummyEngine.dispose();\n subject.next(new Blob([buffer]));\n subject.complete();\n });\n });\n });\n // return new Promise((resolve, reject) => {\n // const env = new HDRCubeTexture(\n // \"textures/environment.hdr\",\n // scene,\n // hdrSize,\n // false,\n // true,\n // false,\n // true,\n // () => {\n // console.log(\"environment loaded\");\n // EnvironmentTextureTools\n // .CreateEnvTextureAsync(env)\n // .then((buffer) => {\n // console.log(buffer);\n // console.log('success');\n // resolve(new Blob([buffer]));\n // })\n // }\n // );\n // });\n }\n\n function createLightVisualization(light, scene, color) {\n let lightPositionGizmo;\n if (!color) {\n color = Color3.Yellow();\n }\n if (light instanceof HemisphericLight) {\n lightPositionGizmo = SphereBuilder.CreateSphere('lightPositionMarker', { diameter: 0.75, slice: 0.5, segments: 6 }, scene);\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n lightPositionGizmo.material = coloredMaterial;\n }\n else if (light instanceof SpotLight) {\n lightPositionGizmo = CylinderBuilder.CreateCylinder('lightPositionCone', { diameterTop: 0.5, height: 0.5, diameterBottom: 0, tessellation: 12 }, scene);\n lightPositionGizmo.position.y = 0.25;\n lightPositionGizmo.bakeCurrentTransformIntoVertices();\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n lightPositionGizmo.material = coloredMaterial;\n }\n else if (light instanceof DirectionalLight) {\n const gizmoOffset = 1;\n lightPositionGizmo = GroundBuilder.CreateGround('lightPositionPlane', {\n height: 1.5,\n width: 1.5,\n subdivisions: 1,\n }, scene);\n const cone = CylinderBuilder.CreateCylinder('cylinder', { diameterTop: 0, height: 0.075, diameterBottom: 0.0375, tessellation: 96 }, scene);\n const line = CylinderBuilder.CreateCylinder('cylinder', { diameterTop: 0.005, height: 0.5, diameterBottom: 0.005, tessellation: 96 }, scene);\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n lightPositionGizmo.material = coloredMaterial;\n cone.material = coloredMaterial;\n line.material = coloredMaterial;\n //cone.rotation.x = Math.PI / 2;\n lightPositionGizmo.position.y = -gizmoOffset;\n lightPositionGizmo.bakeCurrentTransformIntoVertices();\n cone.parent = lightPositionGizmo;\n line.parent = lightPositionGizmo;\n cone.position.y = 0.275 - gizmoOffset;\n line.position.y = -gizmoOffset;\n //line.rotation.x = Math.PI / 2;\n }\n else {\n // PointLight\n lightPositionGizmo = SphereBuilder.CreateSphere('lightPositionMarker', { diameter: 0.1 }, scene);\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.emissiveColor = color;\n lightPositionGizmo.material = coloredMaterial;\n }\n lightPositionGizmo.isPickable = false;\n lightPositionGizmo.setEnabled(true);\n return lightPositionGizmo;\n }\n\n class Quad {\n constructor(capacity = 4) {\n this.capacity = capacity;\n this.points = new Array();\n }\n }\n class Boundary {\n constructor(xmin, xmax, ymin, ymax) {\n this.xmin = xmin;\n this.xmax = xmax;\n this.ymin = ymin;\n this.ymax = ymax;\n }\n boundaryContains(point) {\n return this.xmin <= point.x && this.xmax >= point.x && this.ymin <= point.y && this.ymax >= point.y;\n }\n intersects(b) {\n if (this.xmin >= b.xmax || b.xmin >= this.xmax || this.ymin >= b.ymax || b.ymin >= this.ymax) {\n return false;\n }\n return true;\n }\n get halfPoint() {\n return {\n x: this.xmin + this.width / 2,\n y: this.ymin + this.height / 2,\n };\n }\n get width() {\n return this.xmax - this.xmin;\n }\n get height() {\n return this.ymax - this.ymin;\n }\n }\n class QuadTree extends Boundary {\n constructor(o) {\n super(o.xmin, o.xmax, o.ymin, o.ymax);\n this.o = o;\n this.items = new Array();\n this.size = 0;\n this.duplicatesMap = {};\n this._divided = false;\n this.xSelector = o.xSelector;\n this.ySelector = o.ySelector;\n this.capacity = o.capacity;\n if (o.items) {\n for (const item of o.items)\n this.add(item);\n }\n }\n get divided() {\n return this._divided;\n }\n get quads() {\n const arr = Array();\n if (this.nw)\n arr.push(this.nw);\n if (this.ne)\n arr.push(this.ne);\n if (this.sw)\n arr.push(this.sw);\n if (this.se)\n arr.push(this.se);\n return arr;\n }\n find(point, radius) {\n const b = new Boundary(point.x - radius, point.x + radius, point.y - radius, point.y + radius);\n const results = this.findByBoundary(b);\n //sort by proximity\n results.sortBy(r => r.proximity);\n return results;\n }\n findByBoundary(boundary) {\n const results = new Array();\n if (!this.intersects(boundary)) {\n return results;\n }\n if (this.divided) {\n for (const q of this.quads) {\n results.push(...q.findByBoundary(boundary));\n }\n }\n else {\n //check items at this level\n for (const i of this.items) {\n if (boundary.boundaryContains(this.itemPoint(i))) {\n results.push(this.getWithProximity(i, boundary.halfPoint));\n }\n }\n }\n return results;\n }\n getWithProximity(item, searchPoint) {\n const itemPoint = this.itemPoint(item);\n return {\n item: item,\n proximity: Math.sqrt(Math.pow(searchPoint.x - itemPoint.x, 2) + Math.pow(searchPoint.y - itemPoint.y, 2)),\n };\n }\n positionKey(point) {\n return point.x + ',' + point.y;\n }\n add(item) {\n const point = this.itemPoint(item);\n const key = this.positionKey(point);\n if (!this.boundaryContains(point)) {\n return false;\n }\n // If there is another point in this quad with the **exact** same position, add it to this quad as well.\n // This may result in overfilling the quad but there's no other way to handle exact duplicate points\n if (this.duplicatesMap[key]) {\n this.items.push(item);\n return true;\n }\n //if there is space for it, and no sub-divisions, add it to this quad\n if (this.size < this.o.capacity && !this.divided) {\n this.items.push(item);\n this.duplicatesMap[key] = item;\n this.size++;\n return true;\n }\n if (!this.divided) {\n this.subdivide();\n }\n for (const q of this.quads) {\n if (q.add(item))\n return true;\n }\n throw Error('unexpected error creating quadtree');\n }\n subdivide() {\n // No need to check y, if x is infinitesimally small then y is as well\n if (this.xmax - this.xmin <= Number.EPSILON * 2) {\n throw Error('unexpected error creating quadtree. Not enough granularity');\n }\n this.nw = this.createDivision({\n items: this.items,\n xmin: this.xmin,\n xmax: this.halfPoint.x,\n ymin: this.ymin,\n ymax: this.halfPoint.y,\n });\n this.ne = this.createDivision({\n items: this.items,\n xmin: this.halfPoint.x + Number.EPSILON,\n xmax: this.xmax,\n ymin: this.ymin,\n ymax: this.halfPoint.y,\n });\n this.sw = this.createDivision({\n items: this.items,\n xmin: this.xmin,\n xmax: this.halfPoint.x,\n ymin: this.halfPoint.y + Number.EPSILON,\n ymax: this.ymax,\n });\n this.se = this.createDivision({\n items: this.items,\n xmin: this.halfPoint.x + Number.EPSILON,\n xmax: this.xmax,\n ymin: this.halfPoint.y + Number.EPSILON,\n ymax: this.ymax,\n });\n this.items.clear();\n this.size = 0;\n this._divided = true;\n }\n itemPoint(item) {\n return {\n x: this.xSelector(item),\n y: this.ySelector(item),\n };\n }\n createDivision(options) {\n return new QuadTree({\n ...this.o,\n ...options,\n });\n }\n }\n\n // @ts-nocheck third party library\n /* eslint-disable */\n function earcut$1(data, holeIndices, dim) {\n dim = dim || 2;\n var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = linkedList(data, 0, outerLen, dim, true), triangles = [];\n if (!outerNode || outerNode.next === outerNode.prev)\n return triangles;\n var minX, minY, maxX, maxY, x, y, invSize;\n if (hasHoles)\n outerNode = eliminateHoles(data, holeIndices, outerNode, dim);\n // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox\n if (data.length > 80 * dim) {\n minX = maxX = data[0];\n minY = maxY = data[1];\n for (var i = dim; i < outerLen; i += dim) {\n x = data[i];\n y = data[i + 1];\n if (x < minX)\n minX = x;\n if (y < minY)\n minY = y;\n if (x > maxX)\n maxX = x;\n if (y > maxY)\n maxY = y;\n }\n // minX, minY and invSize are later used to transform coords into integers for z-order calculation\n invSize = Math.max(maxX - minX, maxY - minY);\n invSize = invSize !== 0 ? 32767 / invSize : 0;\n }\n earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);\n return triangles;\n }\n // create a circular doubly linked list from polygon points in the specified winding order\n function linkedList(data, start, end, dim, clockwise) {\n var i, last;\n if (clockwise === signedArea(data, start, end, dim) > 0) {\n for (i = start; i < end; i += dim)\n last = insertNode(i, data[i], data[i + 1], last);\n }\n else {\n for (i = end - dim; i >= start; i -= dim)\n last = insertNode(i, data[i], data[i + 1], last);\n }\n if (last && equals(last, last.next)) {\n removeNode(last);\n last = last.next;\n }\n return last;\n }\n // eliminate colinear or duplicate points\n function filterPoints(start, end) {\n if (!start)\n return start;\n if (!end)\n end = start;\n var p = start, again;\n do {\n again = false;\n if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {\n removeNode(p);\n p = end = p.prev;\n if (p === p.next)\n break;\n again = true;\n }\n else {\n p = p.next;\n }\n } while (again || p !== end);\n return end;\n }\n // main ear slicing loop which triangulates a polygon (given as a linked list)\n function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {\n if (!ear)\n return;\n // interlink polygon nodes in z-order\n if (!pass && invSize)\n indexCurve(ear, minX, minY, invSize);\n var stop = ear, prev, next;\n // iterate through ears, slicing them one by one\n while (ear.prev !== ear.next) {\n prev = ear.prev;\n next = ear.next;\n if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {\n // cut off the triangle\n triangles.push((prev.i / dim) | 0);\n triangles.push((ear.i / dim) | 0);\n triangles.push((next.i / dim) | 0);\n removeNode(ear);\n // skipping the next vertex leads to less sliver triangles\n ear = next.next;\n stop = next.next;\n continue;\n }\n ear = next;\n // if we looped through the whole remaining polygon and can't find any more ears\n if (ear === stop) {\n // try filtering points and slicing again\n if (!pass) {\n earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);\n // if this didn't work, try curing all small self-intersections locally\n }\n else if (pass === 1) {\n ear = cureLocalIntersections(filterPoints(ear), triangles, dim);\n earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);\n // as a last resort, try splitting the remaining polygon into two\n }\n else if (pass === 2) {\n splitEarcut(ear, triangles, dim, minX, minY, invSize);\n }\n break;\n }\n }\n }\n // check whether a polygon node forms a valid ear with adjacent nodes\n function isEar(ear) {\n var a = ear.prev, b = ear, c = ear.next;\n if (area(a, b, c) >= 0)\n return false; // reflex, can't be an ear\n // now make sure we don't have other points inside the potential ear\n var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;\n // triangle bbox; min & max are calculated like this for speed\n var x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx, y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy, x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx, y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;\n var p = c.next;\n while (p !== a) {\n if (p.x >= x0 &&\n p.x <= x1 &&\n p.y >= y0 &&\n p.y <= y1 &&\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\n area(p.prev, p, p.next) >= 0)\n return false;\n p = p.next;\n }\n return true;\n }\n function isEarHashed(ear, minX, minY, invSize) {\n var a = ear.prev, b = ear, c = ear.next;\n if (area(a, b, c) >= 0)\n return false; // reflex, can't be an ear\n var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;\n // triangle bbox; min & max are calculated like this for speed\n var x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx, y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy, x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx, y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;\n // z-order range for the current triangle bbox;\n var minZ = zOrder(x0, y0, minX, minY, invSize), maxZ = zOrder(x1, y1, minX, minY, invSize);\n var p = ear.prevZ, n = ear.nextZ;\n // look for points inside the triangle in both directions\n while (p && p.z >= minZ && n && n.z <= maxZ) {\n if (p.x >= x0 &&\n p.x <= x1 &&\n p.y >= y0 &&\n p.y <= y1 &&\n p !== a &&\n p !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\n area(p.prev, p, p.next) >= 0)\n return false;\n p = p.prevZ;\n if (n.x >= x0 &&\n n.x <= x1 &&\n n.y >= y0 &&\n n.y <= y1 &&\n n !== a &&\n n !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&\n area(n.prev, n, n.next) >= 0)\n return false;\n n = n.nextZ;\n }\n // look for remaining points in decreasing z-order\n while (p && p.z >= minZ) {\n if (p.x >= x0 &&\n p.x <= x1 &&\n p.y >= y0 &&\n p.y <= y1 &&\n p !== a &&\n p !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\n area(p.prev, p, p.next) >= 0)\n return false;\n p = p.prevZ;\n }\n // look for remaining points in increasing z-order\n while (n && n.z <= maxZ) {\n if (n.x >= x0 &&\n n.x <= x1 &&\n n.y >= y0 &&\n n.y <= y1 &&\n n !== a &&\n n !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&\n area(n.prev, n, n.next) >= 0)\n return false;\n n = n.nextZ;\n }\n return true;\n }\n // go through all polygon nodes and cure small local self-intersections\n function cureLocalIntersections(start, triangles, dim) {\n var p = start;\n do {\n var a = p.prev, b = p.next.next;\n if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {\n triangles.push((a.i / dim) | 0);\n triangles.push((p.i / dim) | 0);\n triangles.push((b.i / dim) | 0);\n // remove two nodes involved\n removeNode(p);\n removeNode(p.next);\n p = start = b;\n }\n p = p.next;\n } while (p !== start);\n return filterPoints(p);\n }\n // try splitting polygon into two and triangulate them independently\n function splitEarcut(start, triangles, dim, minX, minY, invSize) {\n // look for a valid diagonal that divides the polygon into two\n var a = start;\n do {\n var b = a.next.next;\n while (b !== a.prev) {\n if (a.i !== b.i && isValidDiagonal(a, b)) {\n // split the polygon in two by the diagonal\n var c = splitPolygon(a, b);\n // filter colinear points around the cuts\n a = filterPoints(a, a.next);\n c = filterPoints(c, c.next);\n // run earcut on each half\n earcutLinked(a, triangles, dim, minX, minY, invSize, 0);\n earcutLinked(c, triangles, dim, minX, minY, invSize, 0);\n return;\n }\n b = b.next;\n }\n a = a.next;\n } while (a !== start);\n }\n // link every hole into the outer loop, producing a single-ring polygon without holes\n function eliminateHoles(data, holeIndices, outerNode, dim) {\n var queue = [], i, len, start, end, list;\n for (i = 0, len = holeIndices.length; i < len; i++) {\n start = holeIndices[i] * dim;\n end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\n list = linkedList(data, start, end, dim, false);\n if (list === list.next)\n list.steiner = true;\n queue.push(getLeftmost(list));\n }\n queue.sort(compareX);\n // process holes from left to right\n for (i = 0; i < queue.length; i++) {\n outerNode = eliminateHole(queue[i], outerNode);\n }\n return outerNode;\n }\n function compareX(a, b) {\n return a.x - b.x;\n }\n // find a bridge between vertices that connects hole with an outer ring and and link it\n function eliminateHole(hole, outerNode) {\n var bridge = findHoleBridge(hole, outerNode);\n if (!bridge) {\n return outerNode;\n }\n var bridgeReverse = splitPolygon(bridge, hole);\n // filter collinear points around the cuts\n filterPoints(bridgeReverse, bridgeReverse.next);\n return filterPoints(bridge, bridge.next);\n }\n // David Eberly's algorithm for finding a bridge between hole and outer polygon\n function findHoleBridge(hole, outerNode) {\n var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m;\n // find a segment intersected by a ray from the hole's leftmost point to the left;\n // segment's endpoint with lesser x will be potential connection point\n do {\n if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {\n var x = p.x + ((hy - p.y) * (p.next.x - p.x)) / (p.next.y - p.y);\n if (x <= hx && x > qx) {\n qx = x;\n m = p.x < p.next.x ? p : p.next;\n if (x === hx)\n return m; // hole touches outer segment; pick leftmost endpoint\n }\n }\n p = p.next;\n } while (p !== outerNode);\n if (!m)\n return null;\n // look for points inside the triangle of hole point, segment intersection and endpoint;\n // if there are no points found, we have a valid connection;\n // otherwise choose the point of the minimum angle with the ray as connection point\n var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan;\n p = m;\n do {\n if (hx >= p.x &&\n p.x >= mx &&\n hx !== p.x &&\n pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {\n tan = Math.abs(hy - p.y) / (hx - p.x); // tangential\n if (locallyInside(p, hole) &&\n (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {\n m = p;\n tanMin = tan;\n }\n }\n p = p.next;\n } while (p !== stop);\n return m;\n }\n // whether sector in vertex m contains sector in vertex p in the same coordinates\n function sectorContainsSector(m, p) {\n return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;\n }\n // interlink polygon nodes in z-order\n function indexCurve(start, minX, minY, invSize) {\n var p = start;\n do {\n if (p.z === 0)\n p.z = zOrder(p.x, p.y, minX, minY, invSize);\n p.prevZ = p.prev;\n p.nextZ = p.next;\n p = p.next;\n } while (p !== start);\n p.prevZ.nextZ = null;\n p.prevZ = null;\n sortLinked(p);\n }\n // Simon Tatham's linked list merge sort algorithm\n // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html\n function sortLinked(list) {\n var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;\n do {\n p = list;\n list = null;\n tail = null;\n numMerges = 0;\n while (p) {\n numMerges++;\n q = p;\n pSize = 0;\n for (i = 0; i < inSize; i++) {\n pSize++;\n q = q.nextZ;\n if (!q)\n break;\n }\n qSize = inSize;\n while (pSize > 0 || (qSize > 0 && q)) {\n if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {\n e = p;\n p = p.nextZ;\n pSize--;\n }\n else {\n e = q;\n q = q.nextZ;\n qSize--;\n }\n if (tail)\n tail.nextZ = e;\n else\n list = e;\n e.prevZ = tail;\n tail = e;\n }\n p = q;\n }\n tail.nextZ = null;\n inSize *= 2;\n } while (numMerges > 1);\n return list;\n }\n // z-order of a point given coords and inverse of the longer side of data bbox\n function zOrder(x, y, minX, minY, invSize) {\n // coords are transformed into non-negative 15-bit integer range\n x = ((x - minX) * invSize) | 0;\n y = ((y - minY) * invSize) | 0;\n x = (x | (x << 8)) & 0x00ff00ff;\n x = (x | (x << 4)) & 0x0f0f0f0f;\n x = (x | (x << 2)) & 0x33333333;\n x = (x | (x << 1)) & 0x55555555;\n y = (y | (y << 8)) & 0x00ff00ff;\n y = (y | (y << 4)) & 0x0f0f0f0f;\n y = (y | (y << 2)) & 0x33333333;\n y = (y | (y << 1)) & 0x55555555;\n return x | (y << 1);\n }\n // find the leftmost node of a polygon ring\n function getLeftmost(start) {\n var p = start, leftmost = start;\n do {\n if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y))\n leftmost = p;\n p = p.next;\n } while (p !== start);\n return leftmost;\n }\n // check if a point lies within a convex triangle\n function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {\n return ((cx - px) * (ay - py) >= (ax - px) * (cy - py) &&\n (ax - px) * (by - py) >= (bx - px) * (ay - py) &&\n (bx - px) * (cy - py) >= (cx - px) * (by - py));\n }\n // check if a diagonal between two polygon nodes is valid (lies in polygon interior)\n function isValidDiagonal(a, b) {\n return (a.next.i !== b.i &&\n a.prev.i !== b.i &&\n !intersectsPolygon(a, b) && // dones't intersect other edges\n ((locallyInside(a, b) &&\n locallyInside(b, a) &&\n middleInside(a, b) && // locally visible\n (area(a.prev, a, b.prev) || area(a, b.prev, b))) || // does not create opposite-facing sectors\n (equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0))); // special zero-length case\n }\n // signed area of a triangle\n function area(p, q, r) {\n return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);\n }\n // check if two points are equal\n function equals(p1, p2) {\n return p1.x === p2.x && p1.y === p2.y;\n }\n // check if two segments intersect\n function intersects(p1, q1, p2, q2) {\n var o1 = sign(area(p1, q1, p2));\n var o2 = sign(area(p1, q1, q2));\n var o3 = sign(area(p2, q2, p1));\n var o4 = sign(area(p2, q2, q1));\n if (o1 !== o2 && o3 !== o4)\n return true; // general case\n if (o1 === 0 && onSegment(p1, p2, q1))\n return true; // p1, q1 and p2 are collinear and p2 lies on p1q1\n if (o2 === 0 && onSegment(p1, q2, q1))\n return true; // p1, q1 and q2 are collinear and q2 lies on p1q1\n if (o3 === 0 && onSegment(p2, p1, q2))\n return true; // p2, q2 and p1 are collinear and p1 lies on p2q2\n if (o4 === 0 && onSegment(p2, q1, q2))\n return true; // p2, q2 and q1 are collinear and q1 lies on p2q2\n return false;\n }\n // for collinear points p, q, r, check if point q lies on segment pr\n function onSegment(p, q, r) {\n return (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y));\n }\n function sign(num) {\n return num > 0 ? 1 : num < 0 ? -1 : 0;\n }\n // check if a polygon diagonal intersects any polygon segments\n function intersectsPolygon(a, b) {\n var p = a;\n do {\n if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))\n return true;\n p = p.next;\n } while (p !== a);\n return false;\n }\n // check if a polygon diagonal is locally inside the polygon\n function locallyInside(a, b) {\n return area(a.prev, a, a.next) < 0\n ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0\n : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;\n }\n // check if the middle point of a polygon diagonal is inside the polygon\n function middleInside(a, b) {\n var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;\n do {\n if (p.y > py !== p.next.y > py &&\n p.next.y !== p.y &&\n px < ((p.next.x - p.x) * (py - p.y)) / (p.next.y - p.y) + p.x)\n inside = !inside;\n p = p.next;\n } while (p !== a);\n return inside;\n }\n // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;\n // if one belongs to the outer ring and another to a hole, it merges it into a single ring\n function splitPolygon(a, b) {\n var a2 = new Node$1(a.i, a.x, a.y), b2 = new Node$1(b.i, b.x, b.y), an = a.next, bp = b.prev;\n a.next = b;\n b.prev = a;\n a2.next = an;\n an.prev = a2;\n b2.next = a2;\n a2.prev = b2;\n bp.next = b2;\n b2.prev = bp;\n return b2;\n }\n // create a node and optionally link it with previous one (in a circular doubly linked list)\n function insertNode(i, x, y, last) {\n var p = new Node$1(i, x, y);\n if (!last) {\n p.prev = p;\n p.next = p;\n }\n else {\n p.next = last.next;\n p.prev = last;\n last.next.prev = p;\n last.next = p;\n }\n return p;\n }\n function removeNode(p) {\n p.next.prev = p.prev;\n p.prev.next = p.next;\n if (p.prevZ)\n p.prevZ.nextZ = p.nextZ;\n if (p.nextZ)\n p.nextZ.prevZ = p.prevZ;\n }\n function Node$1(i, x, y) {\n // vertex index in coordinates array\n this.i = i;\n // vertex coordinates\n this.x = x;\n this.y = y;\n // previous and next vertex nodes in a polygon ring\n this.prev = null;\n this.next = null;\n // z-order curve value\n this.z = 0;\n // previous and next nodes in z-order\n this.prevZ = null;\n this.nextZ = null;\n // indicates whether this is a steiner point\n this.steiner = false;\n }\n // return a percentage difference between the polygon area and its triangulation area;\n // used to verify correctness of triangulation\n earcut$1.deviation = function (data, holeIndices, dim, triangles) {\n var hasHoles = holeIndices && holeIndices.length;\n var outerLen = hasHoles ? holeIndices[0] * dim : data.length;\n var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));\n if (hasHoles) {\n for (var i = 0, len = holeIndices.length; i < len; i++) {\n var start = holeIndices[i] * dim;\n var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\n polygonArea -= Math.abs(signedArea(data, start, end, dim));\n }\n }\n var trianglesArea = 0;\n for (i = 0; i < triangles.length; i += 3) {\n var a = triangles[i] * dim;\n var b = triangles[i + 1] * dim;\n var c = triangles[i + 2] * dim;\n trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));\n }\n return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);\n };\n function signedArea(data, start, end, dim) {\n var sum = 0;\n for (var i = start, j = end - dim; i < end; i += dim) {\n sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);\n j = i;\n }\n return sum;\n }\n // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts\n earcut$1.flatten = function (data) {\n var dim = data[0][0].length, result = { vertices: [], holes: [], dimensions: dim }, holeIndex = 0;\n for (var i = 0; i < data.length; i++) {\n for (var j = 0; j < data[i].length; j++) {\n for (var d = 0; d < dim; d++)\n result.vertices.push(data[i][j][d]);\n }\n if (i > 0) {\n holeIndex += data[i - 1].length;\n result.holes.push(holeIndex);\n }\n }\n return result;\n };\n\n class SubmeshVertexData extends VertexData {\n constructor() {\n super();\n this.indices = null;\n this.positions = null;\n this.normals = null;\n this.tangents = null;\n this.submeshData = null;\n }\n /**\n * @param kbGeometry the kbGeometry to copy the vertex data from.\n * Note that this copipes the vertex data by reference, so mutating the data WILL modify the kbGeometry.\n */\n static FromGeometry(kbGeometry) {\n const result = new SubmeshVertexData();\n result.indices = kbGeometry.indices || null;\n result.positions = kbGeometry.positions || null;\n result.normals = kbGeometry.normals || null;\n result.tangents = kbGeometry.tangents || null;\n result.uvs = kbGeometry.uvs || null;\n result.submeshData = [\n {\n materialIndex: 0,\n verticesStart: 0,\n verticesCount: kbGeometry.positions ? kbGeometry.positions.length / 3 : 0,\n indexStart: 0,\n indexCount: kbGeometry.indices ? kbGeometry.indices.length : 0,\n },\n ];\n return result;\n }\n static ExtractFromMesh(mesh, copyWhenShared, forceCopy) {\n const result = new SubmeshVertexData();\n const vertexData = super.ExtractFromMesh(mesh, copyWhenShared, forceCopy);\n SubmeshVertexData.CopyToRef(vertexData, result);\n if (mesh.subMeshes) {\n result.submeshData = extractSubmeshData(mesh.subMeshes);\n }\n if (mesh.metadata && mesh.metadata['paths']) {\n result.paths = copyWhenShared ? mesh.metadata['paths'].slice() : mesh.metadata['paths'];\n }\n if (mesh.metadata && mesh.metadata['holes']) {\n result.holes = copyWhenShared ? mesh.metadata['holes'].slice() : mesh.metadata['holes'];\n }\n return result;\n }\n static CopyToRef(source, target) {\n target.positions = source.positions || null;\n if ('paths' in source) {\n target.paths = source.paths || null;\n }\n if ('holes' in source) {\n target.holes = source.holes || null;\n }\n target.normals = source.normals || null;\n target.tangents = source.tangents || null;\n target.uvs = source.uvs || null;\n target.uvs2 = source.uvs2 || null;\n target.uvs3 = source.uvs3 || null;\n target.uvs4 = source.uvs4 || null;\n target.uvs5 = source.uvs5 || null;\n target.uvs6 = source.uvs6 || null;\n target.colors = source.colors || null;\n target.matricesIndices = source.matricesIndices || null;\n target.matricesWeights = source.matricesWeights || null;\n target.matricesIndicesExtra = source.matricesIndicesExtra || null;\n target.matricesWeightsExtra = source.matricesWeightsExtra || null;\n target.indices = source.indices || null;\n target.submeshData = source.submeshData;\n }\n static ExtendToRef(source, target) {\n if (source.positions !== undefined)\n target.positions = source.positions;\n if ('paths' in source && source.paths !== undefined)\n target.paths = source.paths;\n if ('holes' in source && source.holes !== undefined)\n target.holes = source.holes;\n if (source.normals !== undefined)\n target.normals = source.normals;\n if (source.tangents !== undefined)\n target.tangents = source.tangents;\n if (source.uvs !== undefined)\n target.uvs = source.uvs;\n if (source.uvs2 !== undefined)\n target.uvs2 = source.uvs2;\n if (source.uvs3 !== undefined)\n target.uvs3 = source.uvs3;\n if (source.uvs4 !== undefined)\n target.uvs4 = source.uvs4;\n if (source.uvs5 !== undefined)\n target.uvs5 = source.uvs5;\n if (source.uvs6 !== undefined)\n target.uvs6 = source.uvs6;\n if (source.colors !== undefined)\n target.colors = source.colors;\n if (source.matricesIndices !== undefined)\n target.matricesIndices = source.matricesIndices;\n if (source.matricesWeights !== undefined)\n target.matricesWeights = source.matricesWeights;\n if (source.matricesIndicesExtra !== undefined)\n target.matricesIndicesExtra = source.matricesIndicesExtra;\n if (source.matricesWeightsExtra !== undefined)\n target.matricesWeightsExtra = source.matricesWeightsExtra;\n if (source.indices !== undefined)\n target.indices = source.indices;\n if (source.submeshData !== undefined) {\n target.submeshData = source.submeshData;\n }\n }\n deepClone() {\n const result = new SubmeshVertexData();\n result.indices = this.indices ? this.indices.slice() : null;\n result.positions = this.positions ? this.positions.slice() : null;\n result.paths = this.paths ? this.paths.slice() : null;\n result.holes = this.holes ? this.holes.slice() : null;\n result.normals = this.normals ? this.normals.slice() : null;\n result.tangents = this.tangents ? this.tangents.slice() : null;\n result.uvs = this.uvs ? this.uvs.slice() : null;\n result.submeshData = this.submeshData ? JSON.parse(JSON.stringify(this.submeshData)) : undefined;\n return result;\n }\n shallowClone() {\n const result = new SubmeshVertexData();\n SubmeshVertexData.CopyToRef(this, result);\n return result;\n }\n copyFrom(source) {\n SubmeshVertexData.CopyToRef(source, this);\n }\n merge(others, use32BitsIndices, forceCloneIndices, mergeMaterialIds, enableCompletion) {\n if (!Array.isArray(others)) {\n others = [others];\n }\n let pathIdxOffset = this.paths ? this.paths.length : 0;\n let segmentIdxOffset = 0;\n let vertexIdxOffset = this.positions ? this.positions.length / 3 : 0;\n const newPaths = [];\n const newHoles = [];\n if (this.paths) {\n for (let i = 2; i < this.paths.length; i += 2) {\n if (this.paths[i] !== this.paths[i - 1]) {\n segmentIdxOffset++;\n }\n }\n if (this.holes) {\n segmentIdxOffset -= this.holes.length / 2;\n }\n segmentIdxOffset++;\n }\n others.map(other => {\n if (other.holes) {\n for (let i = 0; i < other.holes.length; i += 2) {\n newHoles.push(other.holes[i] + segmentIdxOffset, other.holes[i + 1] + pathIdxOffset);\n }\n segmentIdxOffset -= other.holes.length / 2;\n }\n if (other.paths) {\n for (let i = 0; i < other.paths.length; i++) {\n newPaths.push(other.paths[i] + vertexIdxOffset);\n }\n for (let i = 2; i < other.paths.length; i += 2) {\n if (other.paths[i] !== other.paths[i - 1]) {\n segmentIdxOffset++;\n }\n }\n segmentIdxOffset++;\n }\n vertexIdxOffset += other.positions ? other.positions.length / 3 : 0;\n pathIdxOffset += other.paths ? other.paths.length : 0;\n });\n super.merge(others, use32BitsIndices, true, mergeMaterialIds, enableCompletion);\n if (newHoles.length) {\n if (!this.holes) {\n this.holes = new Int32Array();\n }\n if ('push' in this.holes) {\n for (let i = 0; i < newHoles.length; i++) {\n this.holes.push(newHoles[i]);\n }\n }\n else {\n const newArr = new Int32Array(this.holes.length + newHoles.length);\n newArr.set(this.holes);\n newArr.set(newHoles, this.holes.length);\n this.holes = newArr;\n }\n }\n if (newPaths.length) {\n if (!this.paths) {\n this.paths = new Int32Array();\n }\n if ('push' in this.paths) {\n for (let i = 0; i < newPaths.length; i++) {\n this.paths.push(newPaths[i]);\n }\n }\n else {\n const newArr = new Int32Array(this.paths.length + newPaths.length);\n newArr.set(this.paths);\n newArr.set(newPaths, this.paths.length);\n this.paths = newArr;\n }\n }\n return this;\n }\n applyToMesh(mesh, updatable = true, writeSubmeshes = true) {\n if (!this.submeshData && writeSubmeshes && mesh.subMeshes && mesh.subMeshes.length > 1) {\n this.submeshData = extractSubmeshData(mesh.subMeshes);\n }\n const result = super.applyToMesh(mesh, updatable);\n if (this.paths) {\n if (!mesh.metadata) {\n mesh.metadata = {};\n }\n mesh.metadata['paths'] = this.paths.slice();\n }\n if (this.holes) {\n if (!mesh.metadata) {\n mesh.metadata = {};\n }\n mesh.metadata['holes'] = this.holes.slice();\n }\n if (mesh.geometry) {\n // Applying geometry doesn't remove vertex types if they are unset so remove them manually\n if (!this.normals) {\n mesh.geometry.removeVerticesData(VertexBuffer.NormalKind);\n }\n if (!this.uvs) {\n mesh.geometry.removeVerticesData(VertexBuffer.UVKind);\n }\n }\n if (writeSubmeshes) {\n if (this.submeshData) {\n mesh.subMeshes = [];\n this.submeshData.forEach(submesh => {\n // SubMeshes add themselves to the mesh\n new SubMesh(submesh.materialIndex, submesh.verticesStart, submesh.verticesCount, submesh.indexStart, submesh.indexCount, mesh);\n });\n }\n }\n else {\n this.submeshData = extractSubmeshData(mesh.subMeshes);\n }\n return result;\n }\n }\n function extractSubmeshData(subMeshes) {\n return subMeshes.map(submesh => {\n return {\n materialIndex: submesh.materialIndex,\n verticesStart: submesh.verticesStart,\n verticesCount: submesh.verticesCount,\n indexStart: submesh.indexStart,\n indexCount: submesh.indexCount,\n };\n });\n }\n /**\n * @param vertexData\n * @returns null if geometry is valid, string if invalid\n */\n function verifyGeometry(vertexData) {\n let outputError = null;\n if (vertexData.indices && vertexData.positions && vertexData.indices.length > 0) {\n const indicesCount = vertexData.indices.length;\n const vertexCount = vertexData.positions.length / 3;\n if (vertexData.submeshData) {\n vertexData.submeshData.forEach(submesh => {\n if (submesh.indexStart + submesh.indexCount > indicesCount ||\n submesh.verticesStart + submesh.verticesCount > vertexCount) {\n outputError = 'submeshes';\n }\n });\n }\n if (!outputError) {\n const c = vertexData.indices.length;\n let maxVertex = -1;\n for (let i = 0; i < c; i++) {\n maxVertex = Math.max(maxVertex, vertexData.indices[i]);\n }\n if (maxVertex > vertexData.positions.length / 3) {\n outputError = 'vertices';\n }\n }\n }\n return outputError;\n }\n function getPolygonNormal(_points) {\n const normal = Vector3.Zero();\n if (!_points) {\n return normal;\n }\n if (typeof _points[0] === 'number') {\n const points = _points;\n if (points.length < 9) {\n return normal;\n }\n const p1 = Vector3.Zero();\n const p2 = Vector3.Zero();\n let i = 0;\n while (p1.length() === 0 && points.length > i + 5) {\n p1.set(points[i + 3], points[i + 4], points[i + 5]);\n p1.subtractFromFloatsToRef(points[i], points[i + 1], points[i + 2], p1);\n i += 3;\n }\n p2.set(points[i], points[i + 1], points[i + 2]);\n while (normal.length() === 0 && points.length > i + 3) {\n p2.set(points[i + 3], points[i + 4], points[i + 5]);\n p2.subtractFromFloatsToRef(points[i], points[i + 1], points[i + 2], p2);\n Vector3.CrossToRef(p1, p2, normal);\n i += 3;\n }\n }\n else {\n const points = _points;\n if (points.length < 3) {\n return normal;\n }\n const p1 = Vector3.Zero();\n const p2 = Vector3.Zero();\n let i = 0;\n while (p1.length() === 0 && points.length > i + 1) {\n p1.copyFrom(points[i + 1]);\n p1.subtractInPlace(points[i]);\n i++;\n }\n while (normal.length() === 0 && points.length > i + 1) {\n p2.copyFrom(points[i + 1]);\n p2.subtractInPlace(points[i]);\n Vector3.CrossToRef(p1, p2, normal);\n i++;\n }\n }\n return normal.normalize();\n }\n\n const MAX_BEZIER_STEPS = 10;\n const BEZIER_STEP_SIZE = 20.0;\n const GLYPH_COORDS_SCALE = 0.0005;\n const IDENTITY_Q = Quaternion.Identity();\n // class for converting path commands into point data\n class TextMeshPolygon {\n constructor() {\n this.points = [];\n this.children = [];\n this.area = 0.0;\n }\n distance(p1, p2) {\n const dx = p1.x - p2.x, dy = p1.y - p2.y;\n return Math.sqrt(dx * dx + dy * dy);\n }\n lerp(p1, p2, t) {\n return { x: (1 - t) * p1.x + t * p2.x, y: (1 - t) * p1.y + t * p2.y };\n }\n cross(p1, p2) {\n return p1.x * p2.y - p1.y * p2.x;\n }\n moveTo(p) {\n this.points.push(p);\n }\n lineTo(p) {\n this.points.push(p);\n }\n close() {\n let cur = this.points[this.points.length - 1];\n this.points.forEach(next => {\n this.area += 0.5 * this.cross(cur, next);\n cur = next;\n });\n }\n conicTo(p, p1) {\n const p0 = this.points[this.points.length - 1];\n const dist = this.distance(p0, p1) + this.distance(p1, p);\n const steps = Math.max(2, Math.min(MAX_BEZIER_STEPS, dist / BEZIER_STEP_SIZE));\n for (let i = 1; i <= steps; ++i) {\n const t = i / steps;\n this.points.push(this.lerp(this.lerp(p0, p1, t), this.lerp(p1, p, t), t));\n }\n }\n cubicTo(p, p1, p2) {\n const p0 = this.points[this.points.length - 1];\n const dist = this.distance(p0, p1) + this.distance(p1, p2) + this.distance(p2, p);\n const steps = Math.max(2, Math.min(MAX_BEZIER_STEPS, dist / BEZIER_STEP_SIZE));\n for (let i = 1; i <= steps; ++i) {\n const t = i / steps;\n const a = this.lerp(this.lerp(p0, p1, t), this.lerp(p1, p2, t), t);\n const b = this.lerp(this.lerp(p1, p2, t), this.lerp(p2, p, t), t);\n this.points.push(this.lerp(a, b, t));\n }\n }\n inside(p) {\n const epsilon = 1e-6;\n let count = 0, cur = this.points[this.points.length - 1];\n this.points.forEach(next => {\n const p0 = cur.y < next.y ? cur : next;\n const p1 = cur.y < next.y ? next : cur;\n if (p0.y < p.y + epsilon && p1.y > p.y + epsilon) {\n if ((p1.x - p0.x) * (p.y - p0.y) > (p.x - p0.x) * (p1.y - p0.y)) {\n count++;\n }\n }\n cur = next;\n });\n return count % 2 !== 0;\n }\n }\n class TextMeshFont {\n constructor(name, font, scene) {\n this.font = font;\n this.scene = scene;\n this.glyphs = {};\n this.font = font;\n this.glyphsParent = new Mesh(name, scene);\n }\n createGlyph(ch) {\n if (this.glyphs[ch]) {\n return this.glyphs[ch];\n }\n const glyph = this.font.charToGlyph(ch);\n if (!glyph || !glyph.advanceWidth) {\n return undefined;\n }\n this.glyphs[ch] = {\n index: glyph.index,\n advanceWidth: glyph.advanceWidth,\n boundingBox: glyph.getBoundingBox(),\n };\n const glyphDef = this.glyphs[ch];\n if (!glyph.path || !glyph.path.commands || !glyph.path.commands.length) {\n return glyphDef;\n }\n const polys = [];\n glyph.path.commands.forEach(command => {\n const { type, x, y, x1, y1, x2, y2 } = command;\n switch (type) {\n case 'M':\n polys.push(new TextMeshPolygon());\n polys[polys.length - 1].moveTo({ x, y });\n break;\n case 'L':\n polys[polys.length - 1].moveTo({ x, y });\n break;\n case 'C':\n polys[polys.length - 1].cubicTo({ x, y }, { x: x1, y: y1 }, { x: x2, y: y2 });\n break;\n case 'Q':\n polys[polys.length - 1].conicTo({ x, y }, { x: x1, y: y1 });\n break;\n case 'Z':\n polys[polys.length - 1].close();\n break;\n }\n });\n // sort contours by descending area\n polys.sort((a, b) => Math.abs(b.area) - Math.abs(a.area));\n // classify contours to find holes and their 'parents'\n const root = [];\n for (let i = 0; i < polys.length; ++i) {\n let parent = null;\n for (let j = i - 1; j >= 0; --j) {\n // a contour is a hole if it is inside its parent and has different winding\n if (polys[j].inside(polys[i].points[0]) && polys[i].area * polys[j].area < 0) {\n parent = polys[j];\n break;\n }\n }\n if (parent) {\n parent.children.push(polys[i]);\n }\n else {\n root.push(polys[i]);\n }\n }\n const totalPoints = polys.reduce((sum, p) => sum + p.points.length, 0);\n const vertexData = new Float32Array(totalPoints * 2);\n let vertexCount = 0;\n let pathSegmentCount = 0;\n const indices = [];\n const paths = [];\n const holePaths = [];\n function process(poly) {\n // construct input for earcut\n const coords = [];\n const holes = [];\n const n = poly.points.length - 1;\n for (let i = 0; i < n; ++i) {\n const { x, y } = poly.points[n - i];\n if (i > 0) {\n const idx = coords.length / 2;\n paths.push(vertexCount + idx - 1, vertexCount + idx);\n }\n coords.push(x, y);\n }\n const parentSegmentIdx = pathSegmentCount;\n poly.children.forEach((child, i) => {\n // children's children are new, separate shapes\n child.children.forEach(process);\n // idx 0 of a hole is the segment index of the segment the hole is inside. each separate poly is a separate segment\n holePaths.push(parentSegmentIdx, paths.length);\n holes.push(coords.length / 2);\n const n = child.points.length - 1;\n for (let i = 0; i < n; ++i) {\n const { x, y } = child.points[i];\n if (i > 0) {\n const idx = coords.length / 2;\n paths.push(idx - 1, idx);\n }\n coords.push(x, y);\n }\n pathSegmentCount++;\n });\n // add vertex data\n vertexData.set(coords, vertexCount * 2);\n // add index data\n earcut$1(coords, holes).forEach(i => {\n indices.push(i + vertexCount);\n });\n vertexCount += coords.length / 2;\n pathSegmentCount++;\n }\n root.forEach(process);\n const meshdata = new SubmeshVertexData();\n const vertices = [];\n const normals = [];\n for (let i = 0; i < vertexCount; i++) {\n vertices.push(vertexData[i * 2] * GLYPH_COORDS_SCALE);\n vertices.push(vertexData[i * 2 + 1] * GLYPH_COORDS_SCALE);\n vertices.push(0);\n normals.push(0);\n normals.push(0);\n normals.push(1);\n }\n const flipIndices = [];\n for (let i = 0; i < indices.length; i += 3) {\n flipIndices.push(indices[i], indices[i + 2], indices[i + 1]);\n }\n meshdata.positions = vertices;\n meshdata.indices = flipIndices;\n meshdata.normals = normals;\n meshdata.paths = paths;\n meshdata.holes = holePaths;\n glyphDef.vertexData = meshdata;\n return glyphDef;\n }\n }\n class TextMeshVertexData {\n constructor(textMeshFont) {\n this.textMeshFont = textMeshFont;\n this.instances = {};\n }\n getText(text, fontSize = 1, charSpacing = 1, radius = 0) {\n radius = radius / fontSize;\n const scaleMatrix = Matrix.Compose(new Vector3(fontSize, fontSize, 1), IDENTITY_Q, Vector3.ZeroReadOnly);\n const vertexData = new SubmeshVertexData();\n const pos = Vector3.Zero();\n const transformMatrix = Matrix.Identity();\n const generatedVertices = [];\n for (let i = 0; i < text.length; i++) {\n const ch1 = text[i];\n if (ch1 === '\\n') {\n pos.x = 0;\n pos.y -= 1.1;\n continue;\n }\n transformMatrix.setTranslation(pos);\n const ch2 = text[i + 1];\n const g = this.textMeshFont.createGlyph(ch1);\n if (!g) {\n continue;\n }\n let advance = g.advanceWidth;\n if (g.vertexData) {\n generatedVertices.push({\n data: g.vertexData.deepClone(),\n transform: transformMatrix.clone(),\n center: (advance / 2 + g.boundingBox.x1) * GLYPH_COORDS_SCALE,\n });\n }\n if (advance) {\n if (ch2 && this.textMeshFont.glyphs[ch2]) {\n const kern = this.textMeshFont.font.getKerningValue(g.index, this.textMeshFont.glyphs[ch2].index);\n if (kern) {\n advance += kern;\n }\n }\n pos.x += (advance - g.boundingBox.x2 + g.boundingBox.x2 * charSpacing) * GLYPH_COORDS_SCALE;\n }\n }\n if (generatedVertices.length > 0) {\n const centerTransform = Matrix.Compose(Vector3.OneReadOnly, IDENTITY_Q, pos.scale(-0.5));\n for (const generatedVertexData of generatedVertices) {\n const transform = generatedVertexData.transform;\n transform.multiplyToRef(centerTransform, transform);\n // Add curve to text\n if (radius !== 0) {\n const baseOffset = transform.getTranslation();\n const angle = (baseOffset.x + generatedVertexData.center) / radius;\n const pivotMatrix = Matrix.Compose(Vector3.OneReadOnly, IDENTITY_Q, new Vector3(generatedVertexData.center, -radius, 0));\n const rotMatrix = Matrix.Compose(Vector3.OneReadOnly, Quaternion.RotationAxis(new Vector3(0, 0, -1), angle), Vector3.ZeroReadOnly);\n const curveTransform = pivotMatrix.clone().invert();\n curveTransform.multiplyToRef(rotMatrix, curveTransform);\n curveTransform.multiplyToRef(pivotMatrix, curveTransform);\n curveTransform.setTranslation(curveTransform.getTranslation().addInPlaceFromFloats(-generatedVertexData.center, 0, 0));\n transform.copyFrom(curveTransform);\n }\n transform.multiplyToRef(scaleMatrix, transform);\n generatedVertexData.data.transform(transform);\n }\n vertexData.copyFrom(generatedVertices[0].data);\n if (generatedVertices.length > 1) {\n vertexData.merge(generatedVertices.slice(1).map(generatedVertexData => generatedVertexData.data));\n }\n }\n // const calcW = this.textMeshFont.font.getAdvanceWidth(text) * GLYPH_COORDS_SCALE;\n // if (vertexData.positions) {\n // const max = Vector3.Zero();\n // for (let i = 0; i < vertexData.positions.length; i += 3) {\n // const p = vertexData.positions;\n // max.x = Math.max(max.x, p[i]);\n // max.y = Math.max(max.y, p[i + 1]);\n // max.z = Math.max(max.z, p[i + 2]);\n // }\n // const centerTransform = Matrix.Compose(Vector3.OneReadOnly, Quaternion.Identity(), max.scale(-0.5));\n // vertexData.transform(centerTransform);\n // }\n return vertexData;\n }\n }\n\n /**\n * Creates a hemisphere mesh\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.segments\n * @param options.diameter\n * @param options.sideOrientation\n * @param scene defines the hosting scene\n * @returns the hemisphere mesh\n */\n function CreateHemisphere(name, options = {}, scene) {\n if (!options.diameter) {\n options.diameter = 1;\n }\n if (!options.segments) {\n options.segments = 16;\n }\n const halfSphere = CreateSphere(\"\", { slice: 0.5, diameter: options.diameter, segments: options.segments }, scene);\n const disc = CreateDisc(\"\", { radius: options.diameter / 2, tessellation: options.segments * 3 + (4 - options.segments) }, scene);\n disc.rotation.x = -Math.PI / 2;\n disc.parent = halfSphere;\n const merged = Mesh.MergeMeshes([disc, halfSphere], true);\n merged.name = name;\n return merged;\n }\n /**\n * Creates a hemispheric light\n * @param name\n * @param segments\n * @param diameter\n * @param scene\n */\n Mesh.CreateHemisphere = (name, segments, diameter, scene) => {\n const options = {\n segments: segments,\n diameter: diameter,\n };\n return CreateHemisphere(name, options, scene);\n };\n\n /**\n * Material types for GreasedLine\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#materialtype}\n */\n var GreasedLineMeshMaterialType;\n (function (GreasedLineMeshMaterialType) {\n /**\n * StandardMaterial\n */\n GreasedLineMeshMaterialType[GreasedLineMeshMaterialType[\"MATERIAL_TYPE_STANDARD\"] = 0] = \"MATERIAL_TYPE_STANDARD\";\n /**\n * PBR Material\n */\n GreasedLineMeshMaterialType[GreasedLineMeshMaterialType[\"MATERIAL_TYPE_PBR\"] = 1] = \"MATERIAL_TYPE_PBR\";\n })(GreasedLineMeshMaterialType || (GreasedLineMeshMaterialType = {}));\n /**\n * Color blending mode of the @see GreasedLineMaterial and the base material\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#colormode}\n */\n var GreasedLineMeshColorMode;\n (function (GreasedLineMeshColorMode) {\n /**\n * Color blending mode SET\n */\n GreasedLineMeshColorMode[GreasedLineMeshColorMode[\"COLOR_MODE_SET\"] = 0] = \"COLOR_MODE_SET\";\n /**\n * Color blending mode ADD\n */\n GreasedLineMeshColorMode[GreasedLineMeshColorMode[\"COLOR_MODE_ADD\"] = 1] = \"COLOR_MODE_ADD\";\n /**\n * Color blending mode ADD\n */\n GreasedLineMeshColorMode[GreasedLineMeshColorMode[\"COLOR_MODE_MULTIPLY\"] = 2] = \"COLOR_MODE_MULTIPLY\";\n })(GreasedLineMeshColorMode || (GreasedLineMeshColorMode = {}));\n /**\n * Color distribution type of the @see colors.\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#colordistributiontype}\n *\n */\n var GreasedLineMeshColorDistributionType;\n (function (GreasedLineMeshColorDistributionType) {\n /**\n * Colors distributed between segments of the line\n */\n GreasedLineMeshColorDistributionType[GreasedLineMeshColorDistributionType[\"COLOR_DISTRIBUTION_TYPE_SEGMENT\"] = 0] = \"COLOR_DISTRIBUTION_TYPE_SEGMENT\";\n /**\n * Colors distributed along the line ingoring the segments\n */\n GreasedLineMeshColorDistributionType[GreasedLineMeshColorDistributionType[\"COLOR_DISTRIBUTION_TYPE_LINE\"] = 1] = \"COLOR_DISTRIBUTION_TYPE_LINE\";\n })(GreasedLineMeshColorDistributionType || (GreasedLineMeshColorDistributionType = {}));\n /**\n * @internal\n */\n class MaterialGreasedLineDefines extends MaterialDefines {\n constructor() {\n super(...arguments);\n /**\n * The material has a color option specified\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.GREASED_LINE_HAS_COLOR = false;\n /**\n * The material's size attenuation optiom\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.GREASED_LINE_SIZE_ATTENUATION = false;\n /**\n * The type of color distribution is set to line this value equals to true.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE = false;\n /**\n * True if scene is in right handed coordinate system.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM = false;\n }\n }\n /**\n * GreasedLinePluginMaterial for GreasedLineMesh\n */\n class GreasedLinePluginMaterial extends MaterialPluginBase {\n constructor(material, _scene, options) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;\n options = options || {\n color: GreasedLinePluginMaterial.DEFAULT_COLOR,\n };\n const defines = new MaterialGreasedLineDefines();\n defines.GREASED_LINE_HAS_COLOR = !!options.color;\n defines.GREASED_LINE_SIZE_ATTENUATION = (_a = options.sizeAttenuation) !== null && _a !== void 0 ? _a : false;\n defines.GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE = options.colorDistributionType === GreasedLineMeshColorDistributionType.COLOR_DISTRIBUTION_TYPE_LINE;\n defines.GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM = _scene.useRightHandedSystem;\n super(material, GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME, 200, defines);\n this._scene = _scene;\n this._scene = (_b = this._scene) !== null && _b !== void 0 ? _b : material.getScene();\n this._engine = this._scene.getEngine();\n this.visibility = (_c = options.visibility) !== null && _c !== void 0 ? _c : 1;\n this.useDash = (_d = options.useDash) !== null && _d !== void 0 ? _d : false;\n this.dashRatio = (_e = options.dashRatio) !== null && _e !== void 0 ? _e : 0.5;\n this.dashOffset = (_f = options.dashOffset) !== null && _f !== void 0 ? _f : 0;\n this.width = options.width ? options.width : options.sizeAttenuation ? GreasedLinePluginMaterial.DEFAULT_WIDTH_ATTENUATED : GreasedLinePluginMaterial.DEFAULT_WIDTH;\n this._sizeAttenuation = (_g = options.sizeAttenuation) !== null && _g !== void 0 ? _g : false;\n this.colorMode = (_h = options.colorMode) !== null && _h !== void 0 ? _h : GreasedLineMeshColorMode.COLOR_MODE_SET;\n this._color = (_j = options.color) !== null && _j !== void 0 ? _j : null;\n this.useColors = (_k = options.useColors) !== null && _k !== void 0 ? _k : false;\n this._colorsDistributionType = (_l = options.colorDistributionType) !== null && _l !== void 0 ? _l : GreasedLineMeshColorDistributionType.COLOR_DISTRIBUTION_TYPE_SEGMENT;\n this.colorsSampling = (_m = options.colorsSampling) !== null && _m !== void 0 ? _m : RawTexture.NEAREST_NEAREST;\n this._colors = (_o = options.colors) !== null && _o !== void 0 ? _o : null;\n this.dashCount = (_p = options.dashCount) !== null && _p !== void 0 ? _p : 1; // calculate the _dashArray value, call the setter\n this.resolution = (_q = options.resolution) !== null && _q !== void 0 ? _q : new Vector2(this._engine.getRenderWidth(), this._engine.getRenderHeight()); // calculate aspect call the setter\n if (this._colors) {\n this._createColorsTexture(`${material.name}-colors-texture`, this._colors);\n }\n else {\n this._color = (_r = this._color) !== null && _r !== void 0 ? _r : GreasedLinePluginMaterial.DEFAULT_COLOR;\n GreasedLinePluginMaterial._PrepareEmptyColorsTexture(_scene);\n }\n this._enable(true); // always enabled\n }\n /**\n * Get the shader attributes\n * @param attributes array which will be filled with the attributes\n */\n getAttributes(attributes) {\n attributes.push(\"grl_offsets\");\n attributes.push(\"grl_previousAndSide\");\n attributes.push(\"grl_nextAndCounters\");\n attributes.push(\"grl_widths\");\n attributes.push(\"grl_colorPointers\");\n }\n /**\n * Get the shader samplers\n * @param samplers\n */\n getSamplers(samplers) {\n samplers.push(\"grl_colors\");\n }\n /**\n * Get the shader textures\n * @param activeTextures\n */\n getActiveTextures(activeTextures) {\n if (this._colorsTexture) {\n activeTextures.push(this._colorsTexture);\n }\n }\n /**\n * Get the shader uniforms\n * @returns uniforms\n */\n getUniforms() {\n const ubo = [\n { name: \"grl_projection\", size: 16, type: \"mat4\" },\n { name: \"grl_singleColor\", size: 3, type: \"vec3\" },\n { name: \"grl_aspect_resolution_lineWidth\", size: 4, type: \"vec4\" },\n { name: \"grl_dashOptions\", size: 4, type: \"vec4\" },\n { name: \"grl_colorMode_visibility_colorsWidth_useColors\", size: 4, type: \"vec4\" },\n ];\n return {\n ubo,\n vertex: `\r\n uniform vec4 grl_aspect_resolution_lineWidth;\r\n uniform mat4 grl_projection;\r\n `,\n fragment: `\r\n uniform vec4 grl_dashOptions;\r\n uniform vec4 grl_colorMode_visibility_colorsWidth_useColors;\r\n uniform vec3 grl_singleColor;\r\n `,\n };\n }\n // only getter, it doesn't make sense to use this plugin on a mesh other than GreasedLineMesh\n // and it doesn't make sense to disable it on the mesh\n get isEnabled() {\n return true;\n }\n /**\n * Bind the uniform buffer\n * @param uniformBuffer\n */\n bindForSubMesh(uniformBuffer) {\n var _a;\n const activeCamera = this._scene.activeCamera;\n if (activeCamera) {\n const projection = activeCamera.getProjectionMatrix();\n uniformBuffer.updateMatrix(\"grl_projection\", projection);\n }\n else {\n throw Error(\"GreasedLinePluginMaterial requires an active camera.\");\n }\n const resolutionLineWidth = TmpVectors.Vector4[0];\n resolutionLineWidth.x = this._aspect;\n resolutionLineWidth.y = this._resolution.x;\n resolutionLineWidth.z = this._resolution.y;\n resolutionLineWidth.w = this.width;\n uniformBuffer.updateVector4(\"grl_aspect_resolution_lineWidth\", resolutionLineWidth);\n const dashOptions = TmpVectors.Vector4[0];\n dashOptions.x = GreasedLinePluginMaterial._BooleanToNumber(this.useDash);\n dashOptions.y = this._dashArray;\n dashOptions.z = this.dashOffset;\n dashOptions.w = this.dashRatio;\n uniformBuffer.updateVector4(\"grl_dashOptions\", dashOptions);\n const colorModeVisibilityColorsWidthUseColors = TmpVectors.Vector4[1];\n colorModeVisibilityColorsWidthUseColors.x = this.colorMode;\n colorModeVisibilityColorsWidthUseColors.y = this.visibility;\n colorModeVisibilityColorsWidthUseColors.z = this._colorsTexture ? this._colorsTexture.getSize().width : 0;\n colorModeVisibilityColorsWidthUseColors.w = GreasedLinePluginMaterial._BooleanToNumber(this.useColors);\n uniformBuffer.updateVector4(\"grl_colorMode_visibility_colorsWidth_useColors\", colorModeVisibilityColorsWidthUseColors);\n if (this._color) {\n uniformBuffer.updateColor3(\"grl_singleColor\", this._color);\n }\n uniformBuffer.setTexture(\"grl_colors\", (_a = this._colorsTexture) !== null && _a !== void 0 ? _a : GreasedLinePluginMaterial._EmptyColorsTexture);\n }\n /**\n * Prepare the defines\n * @param defines\n * @param _scene\n * @param _mesh\n */\n prepareDefines(defines, _scene, _mesh) {\n var _a;\n defines.GREASED_LINE_HAS_COLOR = !!this._color;\n defines.GREASED_LINE_SIZE_ATTENUATION = (_a = this._sizeAttenuation) !== null && _a !== void 0 ? _a : false;\n defines.GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE = this._colorsDistributionType === GreasedLineMeshColorDistributionType.COLOR_DISTRIBUTION_TYPE_LINE;\n defines.GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM = _scene.useRightHandedSystem;\n }\n /**\n * Get the class name\n * @returns class name\n */\n getClassName() {\n return GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME;\n }\n /**\n * Get shader code\n * @param shaderType vertex/fragment\n * @returns shader code\n */\n getCustomCode(shaderType) {\n if (shaderType === \"vertex\") {\n return {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CUSTOM_VERTEX_DEFINITIONS: `\r\n attribute vec4 grl_previousAndSide;\r\n attribute vec4 grl_nextAndCounters;\r\n attribute float grl_widths;\r\n attribute vec3 grl_offsets;\r\n attribute float grl_colorPointers;\r\n\r\n varying float grlCounters;\r\n varying float grlColorPointer;\r\n\r\n vec2 grlFix( vec4 i, float aspect ) {\r\n vec2 res = i.xy / i.w;\r\n res.x *= aspect;\r\n return res;\r\n }\r\n `,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CUSTOM_VERTEX_UPDATE_POSITION: `\r\n vec3 grlPositionOffset = grl_offsets;\r\n positionUpdated += grlPositionOffset;\r\n `,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CUSTOM_VERTEX_MAIN_END: `\r\n\r\n float grlAspect = grl_aspect_resolution_lineWidth.x;\r\n float grlBaseWidth = grl_aspect_resolution_lineWidth.w;\r\n\r\n grlColorPointer = grl_colorPointers;\r\n\r\n vec3 grlPrevious = grl_previousAndSide.xyz;\r\n float grlSide = grl_previousAndSide.w;\r\n\r\n vec3 grlNext = grl_nextAndCounters.xyz;\r\n grlCounters = grl_nextAndCounters.w;\r\n\r\n\r\n mat4 grlMatrix = viewProjection * world;\r\n vec4 grlFinalPosition = grlMatrix * vec4( positionUpdated , 1.0 );\r\n vec4 grlPrevPos = grlMatrix * vec4( grlPrevious + grlPositionOffset, 1.0 );\r\n vec4 grlNextPos = grlMatrix * vec4( grlNext + grlPositionOffset, 1.0 );\r\n\r\n vec2 grlCurrentP = grlFix( grlFinalPosition, grlAspect );\r\n vec2 grlPrevP = grlFix( grlPrevPos, grlAspect );\r\n vec2 grlNextP = grlFix( grlNextPos, grlAspect );\r\n\r\n float grlWidth = grlBaseWidth * grl_widths;\r\n\r\n vec2 grlDir;\r\n if( grlNextP == grlCurrentP ) grlDir = normalize( grlCurrentP - grlPrevP );\r\n else if( grlPrevP == grlCurrentP ) grlDir = normalize( grlNextP - grlCurrentP );\r\n else {\r\n vec2 grlDir1 = normalize( grlCurrentP - grlPrevP );\r\n vec2 grlDir2 = normalize( grlNextP - grlCurrentP );\r\n grlDir = normalize( grlDir1 + grlDir2 );\r\n }\r\n vec4 grlNormal = vec4( -grlDir.y, grlDir.x, 0., 1. );\r\n #ifdef GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM\r\n grlNormal.xy *= -.5 * grlWidth;\r\n #else\r\n grlNormal.xy *= .5 * grlWidth;\r\n #endif\r\n grlNormal *= grl_projection;\r\n #ifdef GREASED_LINE_SIZE_ATTENUATION\r\n grlNormal.xy *= grlFinalPosition.w;\r\n grlNormal.xy /= ( vec4( grl_aspect_resolution_lineWidth.yz, 0., 1. ) * grl_projection ).xy;\r\n #endif\r\n grlFinalPosition.xy += grlNormal.xy * grlSide;\r\n gl_Position = grlFinalPosition;\r\n\r\n vPositionW = vec3(grlFinalPosition);\r\n\r\n `,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n \"!gl_Position\\\\=viewProjection\\\\*worldPos;\": \"//\", // remove\n };\n }\n if (shaderType === \"fragment\") {\n return {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n varying float grlCounters;\r\n varying float grlColorPointer;\r\n uniform sampler2D grl_colors;\r\n `,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CUSTOM_FRAGMENT_MAIN_END: `\r\n float grlColorMode = grl_colorMode_visibility_colorsWidth_useColors.x;\r\n float grlVisibility = grl_colorMode_visibility_colorsWidth_useColors.y;\r\n float grlColorsWidth = grl_colorMode_visibility_colorsWidth_useColors.z;\r\n float grlUseColors = grl_colorMode_visibility_colorsWidth_useColors.w;\r\n\r\n float grlUseDash = grl_dashOptions.x;\r\n float grlDashArray = grl_dashOptions.y;\r\n float grlDashOffset = grl_dashOptions.z;\r\n float grlDashRatio = grl_dashOptions.w;\r\n\r\n gl_FragColor.a *= step(grlCounters, grlVisibility);\r\n if( gl_FragColor.a == 0. ) discard;\r\n\r\n if(grlUseDash == 1.){\r\n gl_FragColor.a *= ceil(mod(grlCounters + grlDashOffset, grlDashArray) - (grlDashArray * grlDashRatio));\r\n if (gl_FragColor.a == 0.) discard;\r\n }\r\n\r\n #ifdef GREASED_LINE_HAS_COLOR\r\n if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_SET}.) {\r\n gl_FragColor.rgb = grl_singleColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_ADD}.) {\r\n gl_FragColor.rgb += grl_singleColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_MULTIPLY}.) {\r\n gl_FragColor.rgb *= grl_singleColor;\r\n }\r\n #else\r\n if (grlUseColors == 1.) {\r\n #ifdef GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE\r\n vec4 grlColor = texture2D(grl_colors, vec2(grlCounters, 0.), 0.);\r\n #else\r\n vec4 grlColor = texture2D(grl_colors, vec2(grlColorPointer/grlColorsWidth, 0.), 0.);\r\n #endif\r\n if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_SET}.) {\r\n gl_FragColor = grlColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_ADD}.) {\r\n gl_FragColor += grlColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_MULTIPLY}.) {\r\n gl_FragColor *= grlColor;\r\n }\r\n }\r\n #endif\r\n `,\n };\n }\n return null;\n }\n /**\n * Converts boolean to number.\n * @param bool\n * @returns 1 if true, 0 if false.\n */\n static _BooleanToNumber(bool) {\n return bool ? 1 : 0;\n }\n /**\n * Converts an array of Color3 to Uint8Array\n * @param colors Arrray of Color3\n * @returns Uin8Array of colors [r, g, b, a, r, g, b, a, ...]\n */\n static _Color3toRGBAUint8(colors) {\n const colorTable = new Uint8Array(colors.length * 4);\n for (let i = 0, j = 0; i < colors.length; i++) {\n colorTable[j++] = colors[i].r * 255;\n colorTable[j++] = colors[i].g * 255;\n colorTable[j++] = colors[i].b * 255;\n colorTable[j++] = 255;\n }\n return colorTable;\n }\n /**\n * Creates a RawTexture from an RGBA color array and sets it on the plugin material instance.\n * @param name name of the texture\n * @param colors Uint8Array of colors\n */\n _createColorsTexture(name, colors) {\n const colorsArray = GreasedLinePluginMaterial._Color3toRGBAUint8(colors);\n this._colorsTexture = new RawTexture(colorsArray, colors.length, 1, Engine.TEXTUREFORMAT_RGBA, this._scene, false, true, this.colorsSampling);\n this._colorsTexture.name = name;\n }\n /**\n * Disposes the plugin material.\n */\n dispose() {\n var _a;\n (_a = this._colorsTexture) === null || _a === void 0 ? void 0 : _a.dispose();\n super.dispose();\n }\n /**\n * Returns the colors used to colorize the line\n */\n get colors() {\n return this._colors;\n }\n /**\n * Sets the colors used to colorize the line\n */\n set colors(value) {\n this.setColors(value);\n }\n /**\n * Creates or updates the colors texture\n * @param colors color table RGBA\n * @param lazy if lazy, the colors are not updated\n * @param forceUpdate force creation of a new texture\n * @returns\n */\n setColors(colors, lazy = false, forceUpdate = false) {\n var _a, _b, _c, _d;\n const origColorsCount = (_b = (_a = this._colors) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;\n this._colors = colors;\n if (colors === null || colors.length === 0) {\n (_c = this._colorsTexture) === null || _c === void 0 ? void 0 : _c.dispose();\n return;\n }\n if (lazy && !forceUpdate) {\n return;\n }\n if (this._colorsTexture && origColorsCount === colors.length && !forceUpdate) {\n const colorArray = GreasedLinePluginMaterial._Color3toRGBAUint8(colors);\n this._colorsTexture.update(colorArray);\n }\n else {\n (_d = this._colorsTexture) === null || _d === void 0 ? void 0 : _d.dispose();\n this._createColorsTexture(`${this._material.name}-colors-texture`, colors);\n }\n }\n /**\n * Updates the material. Use when material created in lazy mode.\n */\n updateLazy() {\n if (this._colors) {\n this.setColors(this._colors, false, true);\n }\n }\n /**\n * Gets the number of dashes in the line\n */\n get dashCount() {\n return this._dashCount;\n }\n /**\n * Sets the number of dashes in the line\n * @param value dash\n */\n set dashCount(value) {\n this._dashCount = value;\n this._dashArray = 1 / value;\n }\n /**\n * False means 1 unit in width = 1 unit on scene, true means 1 unit in width is reduced on the screen to make better looking lines\n */\n get sizeAttenuation() {\n return this._sizeAttenuation;\n }\n /**\n * Turn on/off attenuation of the width option and widths array.\n * @param value false means 1 unit in width = 1 unit on scene, true means 1 unit in width is reduced on the screen to make better looking lines\n */\n set sizeAttenuation(value) {\n this._sizeAttenuation = value;\n this.markAllDefinesAsDirty();\n }\n /**\n * Gets the color of the line\n */\n get color() {\n return this.color;\n }\n /**\n * Sets the color of the line\n * @param value Color3 or null to clear the color. You need to clear the color if you use colors and useColors = true\n */\n set color(value) {\n this.setColor(value);\n }\n /**\n * Sets the color of the line. If set the whole line will be mixed with this color according to the colorMode option.\n * @param value color\n */\n setColor(value, doNotMarkDirty = false) {\n if ((this._color === null && value !== null) || (this._color !== null && value === null)) {\n this._color = value;\n !doNotMarkDirty && this.markAllDefinesAsDirty();\n }\n else {\n this._color = value;\n }\n }\n /**\n * Gets the color distributiopn type\n */\n get colorsDistributionType() {\n return this._colorsDistributionType;\n }\n /**\n * Sets the color distribution type\n * @see GreasedLineMeshColorDistributionType\n * @param value color distribution type\n */\n set colorsDistributionType(value) {\n this._colorsDistributionType = value;\n this.markAllDefinesAsDirty();\n }\n /**\n * Gets the resolution\n */\n get resolution() {\n return this._resolution;\n }\n /**\n * Sets the resolution\n * @param value resolution of the screen for GreasedLine\n */\n set resolution(value) {\n this._aspect = value.x / value.y;\n this._resolution = value;\n }\n /**\n * Serializes this plugin material\n * @returns serializationObjec\n */\n serialize() {\n const serializationObject = super.serialize();\n const greasedLineMaterialOptions = {\n colorDistributionType: this._colorsDistributionType,\n colorsSampling: this.colorsSampling,\n colorMode: this.colorMode,\n dashCount: this._dashCount,\n dashOffset: this.dashOffset,\n dashRatio: this.dashRatio,\n resolution: this._resolution,\n sizeAttenuation: this._sizeAttenuation,\n useColors: this.useColors,\n useDash: this.useDash,\n visibility: this.visibility,\n width: this.width,\n };\n this._colors && (greasedLineMaterialOptions.colors = this._colors);\n this._color && (greasedLineMaterialOptions.color = this._color);\n serializationObject.greasedLineMaterialOptions = greasedLineMaterialOptions;\n return serializationObject;\n }\n /**\n * Parses a serialized objects\n * @param source serialized object\n * @param scene scene\n * @param rootUrl root url for textures\n */\n parse(source, scene, rootUrl) {\n var _a;\n super.parse(source, scene, rootUrl);\n const greasedLineMaterialOptions = source.greasedLineMaterialOptions;\n (_a = this._colorsTexture) === null || _a === void 0 ? void 0 : _a.dispose();\n if (greasedLineMaterialOptions.colors) {\n this._createColorsTexture(`${this._material.name}-colors-texture`, greasedLineMaterialOptions.colors);\n }\n else {\n GreasedLinePluginMaterial._PrepareEmptyColorsTexture(scene);\n }\n greasedLineMaterialOptions.color && this.setColor(greasedLineMaterialOptions.color, true);\n greasedLineMaterialOptions.colorDistributionType && (this.colorsDistributionType = greasedLineMaterialOptions.colorDistributionType);\n greasedLineMaterialOptions.colorsSampling && (this.colorsSampling = greasedLineMaterialOptions.colorsSampling);\n greasedLineMaterialOptions.colorMode && (this.colorMode = greasedLineMaterialOptions.colorMode);\n greasedLineMaterialOptions.useColors && (this.useColors = greasedLineMaterialOptions.useColors);\n greasedLineMaterialOptions.visibility && (this.visibility = greasedLineMaterialOptions.visibility);\n greasedLineMaterialOptions.useDash && (this.useDash = greasedLineMaterialOptions.useDash);\n greasedLineMaterialOptions.dashCount && (this.dashCount = greasedLineMaterialOptions.dashCount);\n greasedLineMaterialOptions.dashRatio && (this.dashRatio = greasedLineMaterialOptions.dashRatio);\n greasedLineMaterialOptions.dashOffset && (this.dashOffset = greasedLineMaterialOptions.dashOffset);\n greasedLineMaterialOptions.width && (this.width = greasedLineMaterialOptions.width);\n greasedLineMaterialOptions.sizeAttenuation && (this.sizeAttenuation = greasedLineMaterialOptions.sizeAttenuation);\n greasedLineMaterialOptions.resolution && (this.resolution = greasedLineMaterialOptions.resolution);\n this.markAllDefinesAsDirty();\n }\n /**\n * A minimum size texture for the colors sampler2D when there is no colors texture defined yet.\n * For fast switching using the useColors property without the need to use defines.\n * @param scene Scene\n */\n static _PrepareEmptyColorsTexture(scene) {\n if (!this._EmptyColorsTexture) {\n const colorsArray = new Uint8Array(4);\n this._EmptyColorsTexture = new RawTexture(colorsArray, 1, 1, Engine.TEXTUREFORMAT_RGBA, scene, false, false, RawTexture.NEAREST_NEAREST);\n this._EmptyColorsTexture.name = \"grlEmptyColorsTexture\";\n }\n }\n }\n /**\n * Plugin name\n */\n GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME = \"GreasedLinePluginMaterial\";\n /**\n * Default line color for newly created lines\n */\n GreasedLinePluginMaterial.DEFAULT_COLOR = Color3.White();\n /**\n * Default line width when sizeAttenuation is true\n */\n GreasedLinePluginMaterial.DEFAULT_WIDTH_ATTENUATED = 1;\n /**\n * Defaule line width\n */\n GreasedLinePluginMaterial.DEFAULT_WIDTH = 0.1;\n RegisterClass(`BABYLON.${GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME}`, GreasedLinePluginMaterial);\n\n /**\n * Tool functions for GreasedLine\n */\n class GreasedLineTools {\n /**\n * Omit zero length lines predicate for the MeshesToLines function\n * @param p1 point1 position of the face\n * @param p2 point2 position of the face\n * @param p3 point3 position of the face\n * @returns\n */\n static OmitZeroLengthPredicate(p1, p2, p3) {\n return p1.lengthSquared() === 0 && p2.lengthSquared() === 0 && p3.lengthSquared() === 0;\n }\n /**\n * Gets mesh triangles as line positions\n * @param meshes array of meshes\n * @param omitZeroLengthLines do not generate a line when the distance if the vertices in the triangle equals to zero\n * @returns array of arrays of points\n */\n static MeshesToLines(meshes, predicate) {\n const points = [];\n meshes.forEach((m, meshIndex) => {\n const vertices = m.getVerticesData(VertexBuffer.PositionKind);\n const indices = m.getIndices();\n if (vertices && indices) {\n for (let i = 0, ii = 0; i < indices.length; i++) {\n const vi1 = indices[ii++] * 3;\n const vi2 = indices[ii++] * 3;\n const vi3 = indices[ii++] * 3;\n const p1 = new Vector3(vertices[vi1], vertices[vi1 + 1], vertices[vi1 + 2]);\n const p2 = new Vector3(vertices[vi2], vertices[vi2 + 1], vertices[vi2 + 2]);\n const p3 = new Vector3(vertices[vi3], vertices[vi3 + 1], vertices[vi3 + 2]);\n if (predicate) {\n const pointsFromPredicate = predicate(p1, p2, p3, i, vi1, m, meshIndex, vertices, indices);\n pointsFromPredicate && points.push(pointsFromPredicate);\n }\n else {\n points.push([p1, p2, p3, p1]);\n }\n }\n }\n });\n return points;\n }\n /**\n * Converts number coordinates to Vector3s\n * @param points number array of x, y, z, x, y z, ... coordinates\n * @returns Vector3 array\n */\n static ToVector3Array(points) {\n const array = [];\n for (let i = 0; i < points.length; i += 3) {\n array.push(new Vector3(points[i], points[i + 1], points[i + 2]));\n }\n return array;\n }\n /**\n * Gets a number array from a Vector3 array.\n * You can you for example to convert your Vector3[] offsets to the required number[] for the offsets option.\n * @param points Vector3 array\n * @returns an array of x, y, z coordinates as numbers [x, y, z, x, y, z, x, y, z, ....]\n */\n static ToNumberArray(points) {\n return points.flatMap((v) => [v.x, v.y, v.z]);\n }\n /**\n * Calculates the sum of points of every line and the number of points in each line.\n * This function is useful when you are drawing multiple lines in one mesh and you want\n * to know the counts. For example for creating an offsets table.\n * @param points point array\n * @returns points count info\n */\n static GetPointsCountInfo(points) {\n const counts = new Array(points.length);\n let total = 0;\n for (let n = points.length; n--;) {\n counts[n] = points[n].length / 3;\n total += counts[n];\n }\n return { total, counts };\n }\n /**\n * Gets the length of the line counting all it's segments length\n * @param data array of line points\n * @returns length of the line\n */\n static GetLineLength(data) {\n if (data.length === 0) {\n return 0;\n }\n let points;\n if (typeof data[0] === \"number\") {\n points = GreasedLineTools.ToVector3Array(data);\n }\n else {\n points = data;\n }\n const tmp = TmpVectors.Vector3[0];\n let length = 0;\n for (let index = 0; index < points.length - 1; index++) {\n const point1 = points[index];\n const point2 = points[index + 1];\n length += point2.subtractToRef(point1, tmp).length();\n }\n return length;\n }\n /**\n * Divides a segment into smaller segments.\n * A segment is a part of the line between it's two points.\n * @param point1 first point of the line\n * @param point2 second point of the line\n * @param segmentCount number of segments we want to have in the divided line\n * @returns\n */\n static SegmentizeSegmentByCount(point1, point2, segmentCount) {\n const dividedLinePoints = [];\n const diff = point2.subtract(point1);\n const divisor = TmpVectors.Vector3[0];\n divisor.setAll(segmentCount);\n const segmentVector = TmpVectors.Vector3[1];\n diff.divideToRef(divisor, segmentVector);\n let nextPoint = point1.clone();\n dividedLinePoints.push(nextPoint);\n for (let index = 0; index < segmentCount; index++) {\n nextPoint = nextPoint.clone();\n dividedLinePoints.push(nextPoint.addInPlace(segmentVector));\n }\n return dividedLinePoints;\n }\n /**\n * Divides a line into segments.\n * A segment is a part of the line between it's two points.\n * @param what line points\n * @param segmentLength length of each segment of the resulting line (distance between two line points)\n * @returns line point\n */\n static SegmentizeLineBySegmentLength(what, segmentLength) {\n const subLines = what[0] instanceof Vector3 ? GreasedLineTools.GetLineSegments(what) : what;\n const points = [];\n subLines.forEach((s) => {\n if (s.length > segmentLength) {\n const segments = GreasedLineTools.SegmentizeSegmentByCount(s.point1, s.point2, Math.ceil(s.length / segmentLength));\n segments.forEach((seg) => {\n points.push(seg);\n });\n }\n else {\n points.push(s.point1);\n points.push(s.point2);\n }\n });\n return points;\n }\n /**\n * Divides a line into segments.\n * A segment is a part of the line between it's two points.\n * @param what line points\n * @param segmentCount number of segments\n * @returns line point\n */\n static SegmentizeLineBySegmentCount(what, segmentCount) {\n const segmentLength = GreasedLineTools.GetLineLength(what) / segmentCount;\n return GreasedLineTools.SegmentizeLineBySegmentLength(what, segmentLength);\n }\n /**\n * Gets line segments.\n * A segment is a part of the line between it's two points.\n * @param points line points\n * @returns segments information of the line segment including starting point, ending point and the distance between them\n */\n static GetLineSegments(points) {\n const segments = [];\n for (let index = 0; index < points.length - 1; index++) {\n const point1 = points[index];\n const point2 = points[index + 1];\n const length = point2.subtract(point1).length();\n segments.push({ point1, point2, length });\n }\n return segments;\n }\n /**\n * Gets the minimum and the maximum length of a line segment in the line.\n * A segment is a part of the line between it's two points.\n * @param points line points\n * @returns\n */\n static GetMinMaxSegmentLength(points) {\n const subLines = GreasedLineTools.GetLineSegments(points);\n const sorted = subLines.sort((s) => s.length);\n return {\n min: sorted[0].length,\n max: sorted[sorted.length - 1].length,\n };\n }\n /**\n * Finds the last visible position in world space of the line according to the visibility parameter\n * @param lineSegments segments of the line\n * @param lineLength total length of the line\n * @param visbility normalized value of visibility\n * @returns world space coordinate of the last visible piece of the line\n */\n static GetPositionOnLineByVisibility(lineSegments, lineLength, visbility, localSpace = false) {\n const lengthVisibilityRatio = lineLength * visbility;\n let sumSegmentLengths = 0;\n let segmentIndex = 0;\n const lineSegmentsLength = lineSegments.length;\n for (let i = 0; i < lineSegmentsLength; i++) {\n if (lengthVisibilityRatio <= sumSegmentLengths + lineSegments[i].length) {\n segmentIndex = i;\n break;\n }\n sumSegmentLengths += lineSegments[i].length;\n }\n const s = (lengthVisibilityRatio - sumSegmentLengths) / lineSegments[segmentIndex].length;\n lineSegments[segmentIndex].point2.subtractToRef(lineSegments[segmentIndex].point1, TmpVectors.Vector3[0]);\n TmpVectors.Vector3[1] = TmpVectors.Vector3[0].multiplyByFloats(s, s, s);\n if (!localSpace) {\n TmpVectors.Vector3[1].addInPlace(lineSegments[segmentIndex].point1);\n }\n return TmpVectors.Vector3[1].clone();\n }\n /**\n * Creates lines in a shape of circle/arc.\n * A segment is a part of the line between it's two points.\n * @param radiusX radiusX of the circle\n * @param segments number of segments in the circle\n * @param z z coordinate of the points. Defaults to 0.\n * @param radiusY radiusY of the circle - you can draw an oval if using different values\n * @param segmentAngle angle offset of the segments. Defaults to Math.PI * 2 / segments. Change this value to draw a part of the circle.\n * @returns line points\n */\n static GetCircleLinePoints(radiusX, segments, z = 0, radiusY = radiusX, segmentAngle = (Math.PI * 2) / segments) {\n const points = [];\n for (let i = 0; i <= segments; i++) {\n points.push(new Vector3(Math.cos(i * segmentAngle) * radiusX, Math.sin(i * segmentAngle) * radiusY, z));\n }\n return points;\n }\n /**\n * Gets line points in a shape of a bezier curve\n * @param p0 bezier point0\n * @param p1 bezier point1\n * @param p2 bezier point2\n * @param segments number of segments in the curve\n * @returns\n */\n static GetBezierLinePoints(p0, p1, p2, segments) {\n return Curve3.CreateQuadraticBezier(p0, p1, p2, segments)\n .getPoints()\n .flatMap((v) => [v.x, v.y, v.z]);\n }\n /**\n *\n * @param position position of the arrow cap (mainly you want to create a triangle, set widthUp and widthDown to the same value and omit widthStartUp and widthStartDown)\n * @param direction direction which the arrow points to\n * @param length length (size) of the arrow cap itself\n * @param widthUp the arrow width above the line\n * @param widthDown the arrow width belove the line\n * @param widthStartUp the arrow width at the start of the arrow above the line. In most scenarios this is 0.\n * @param widthStartDown the arrow width at the start of the arrow below the line. In most scenarios this is 0.\n * @returns\n */\n static GetArrowCap(position, direction, length, widthUp, widthDown, widthStartUp = 0, widthStartDown = 0) {\n const points = [position.clone(), position.add(direction.multiplyByFloats(length, length, length))];\n const widths = [widthUp, widthDown, widthStartUp, widthStartDown];\n return {\n points,\n widths,\n };\n }\n /**\n * Gets 3D positions of points from a text and font\n * @param text Text\n * @param size Size of the font\n * @param resolution Resolution of the font\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\n * @param z z coordinate\n * @param includeInner include the inner parts of the font in the result. Default true. If false, only the outlines will be returned.\n * @returns number[][] of 3D positions\n */\n static GetPointsFromText(text, size, resolution, fontData, z = 0, includeInner = true) {\n const allPoints = [];\n const shapePaths = CreateTextShapePaths(text, size, resolution, fontData);\n for (const sp of shapePaths) {\n for (const p of sp.paths) {\n const points = [];\n const points2d = p.getPoints();\n for (const p2d of points2d) {\n points.push(p2d.x, p2d.y, z);\n }\n allPoints.push(points);\n }\n if (includeInner) {\n for (const h of sp.holes) {\n const holes = [];\n const points2d = h.getPoints();\n for (const p2d of points2d) {\n holes.push(p2d.x, p2d.y, z);\n }\n allPoints.push(holes);\n }\n }\n }\n return allPoints;\n }\n }\n\n Mesh._GreasedLineMeshParser = (parsedMesh, scene) => {\n return GreasedLineMesh.Parse(parsedMesh, scene);\n };\n /**\n * GreasedLine\n */\n class GreasedLineMesh extends Mesh {\n constructor(name, scene, _options) {\n var _a, _b, _c, _d;\n super(name, scene, null, null, false, false);\n this.name = name;\n this._options = _options;\n this._lazy = false;\n this._updatable = false;\n /**\n * Treshold used to pick the mesh\n */\n this.intersectionThreshold = 0.1;\n this._lazy = (_a = _options.lazy) !== null && _a !== void 0 ? _a : false;\n this._updatable = (_b = _options.updatable) !== null && _b !== void 0 ? _b : false;\n this._vertexPositions = [];\n this._indices = [];\n this._uvs = [];\n this._points = [];\n this._colorPointers = (_c = _options.colorPointers) !== null && _c !== void 0 ? _c : [];\n this._widths = (_d = _options.widths) !== null && _d !== void 0 ? _d : new Array(_options.points.length).fill(1);\n this._previousAndSide = [];\n this._nextAndCounters = [];\n if (_options.points) {\n this.addPoints(GreasedLineMesh.ConvertPoints(_options.points));\n }\n }\n /**\n * \"GreasedLineMesh\"\n * @returns \"GreasedLineMesh\"\n */\n getClassName() {\n return \"GreasedLineMesh\";\n }\n /**\n * Converts GreasedLinePoints to number[][]\n * @param points GreasedLinePoints\n * @returns number[][] with x, y, z coordinates of the points, like [[x, y, z, x, y, z, ...], [x, y, z, ...]]\n */\n static ConvertPoints(points) {\n if (points.length && Array.isArray(points) && typeof points[0] === \"number\") {\n return [points];\n }\n else if (points.length && Array.isArray(points[0]) && typeof points[0][0] === \"number\") {\n return points;\n }\n else if (points.length && !Array.isArray(points[0]) && points[0] instanceof Vector3) {\n const positions = [];\n for (let j = 0; j < points.length; j++) {\n const p = points[j];\n positions.push(p.x, p.y, p.z);\n }\n return [positions];\n }\n else if (points.length > 0 && Array.isArray(points[0]) && points[0].length > 0 && points[0][0] instanceof Vector3) {\n const positions = [];\n const vectorPoints = points;\n vectorPoints.forEach((p) => {\n positions.push(p.flatMap((p2) => [p2.x, p2.y, p2.z]));\n });\n return positions;\n }\n else if (points instanceof Float32Array) {\n return [Array.from(points)];\n }\n else if (points.length && points[0] instanceof Float32Array) {\n const positions = [];\n points.forEach((p) => {\n positions.push(Array.from(p));\n });\n return positions;\n }\n return [];\n }\n /**\n * Updated a lazy line. Rerenders the line and updates boundinfo as well.\n */\n updateLazy() {\n var _a;\n this.setPoints(this._points);\n if (!this._options.colorPointers) {\n this._updateColorPointers();\n }\n this._createVertexBuffers();\n this.refreshBoundingInfo();\n (_a = this.greasedLineMaterial) === null || _a === void 0 ? void 0 : _a.updateLazy();\n }\n /**\n * Dispose the line and it's resources\n */\n dispose() {\n super.dispose();\n }\n /**\n *\n * @returns true if the mesh was created in lazy mode\n */\n isLazy() {\n return this._lazy;\n }\n /**\n * Return the the points offsets\n */\n get offsets() {\n return this._offsets;\n }\n /**\n * Sets point offests\n * @param offsets offset table [x,y,z, x,y,z, ....]\n */\n set offsets(offsets) {\n this._offsets = offsets;\n if (!this._offsetsBuffer) {\n this._createOffsetsBuffer(offsets);\n }\n else {\n this._offsetsBuffer && this._offsetsBuffer.update(offsets);\n }\n }\n /**\n * Gets widths at each line point like [widthLower, widthUpper, widthLower, widthUpper, ...]\n */\n get widths() {\n return this._widths;\n }\n /**\n * Sets widths at each line point\n * @param widths width table [widthLower, widthUpper, widthLower, widthUpper ...]\n */\n set widths(widths) {\n this._widths = widths;\n if (!this._lazy) {\n this._widthsBuffer && this._widthsBuffer.update(widths);\n }\n }\n /**\n * Gets the color pointer. Each vertex need a color pointer. These color pointers points to the colors in the color table @see colors\n */\n get colorPointers() {\n return this._colorPointers;\n }\n /**\n * Sets the color pointer\n * @param colorPointers array of color pointer in the colors array. One pointer for every vertex is needed.\n */\n set colorPointers(colorPointers) {\n this._colorPointers = colorPointers;\n if (!this._lazy) {\n this._colorPointersBuffer && this._colorPointersBuffer.update(colorPointers);\n }\n }\n /**\n * Gets the pluginMaterial associated with line\n */\n get greasedLineMaterial() {\n var _a, _b;\n return (_b = (_a = this.material) === null || _a === void 0 ? void 0 : _a.pluginManager) === null || _b === void 0 ? void 0 : _b.getPlugin(GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME);\n }\n /**\n * Return copy the points.\n */\n get points() {\n const pointsCopy = [];\n DeepCopier.DeepCopy(this._points, pointsCopy);\n return pointsCopy;\n }\n /**\n * Adds new points to the line. It doesn't rerenders the line if in lazy mode.\n * @param points points table\n */\n addPoints(points) {\n for (const p of points) {\n this._points.push(p);\n }\n if (!this._lazy) {\n this.setPoints(this._points);\n }\n }\n _updateColorPointers() {\n let colorPointer = 0;\n this._colorPointers = [];\n this._points.forEach((p) => {\n for (let jj = 0; jj < p.length; jj += 3) {\n this._colorPointers.push(colorPointer);\n this._colorPointers.push(colorPointer++);\n }\n });\n }\n /**\n * Sets line points and rerenders the line.\n * @param points points table\n */\n setPoints(points) {\n this._points = points;\n this._options.points = points;\n this._initGreasedLine();\n let indiceOffset = 0;\n points.forEach((p) => {\n var _a;\n const counters = [];\n const positions = [];\n const indices = [];\n const totalLength = GreasedLineTools.GetLineLength(p);\n for (let j = 0, jj = 0; jj < p.length; j++, jj += 3) {\n const partialLine = p.slice(0, jj + 3);\n const partialLineLength = GreasedLineTools.GetLineLength(partialLine);\n const c = partialLineLength / totalLength;\n positions.push(p[jj], p[jj + 1], p[jj + 2]);\n positions.push(p[jj], p[jj + 1], p[jj + 2]);\n counters.push(c);\n counters.push(c);\n if (jj < p.length - 3) {\n const n = j * 2 + indiceOffset;\n indices.push(n, n + 1, n + 2);\n indices.push(n + 2, n + 1, n + 3);\n }\n }\n indiceOffset += (p.length / 3) * 2;\n const previous = [];\n const next = [];\n const side = [];\n let uvs = [];\n this._preprocess(positions, previous, next, side, uvs);\n for (const vp of positions) {\n this._vertexPositions.push(vp);\n }\n for (const i of indices) {\n this._indices.push(i);\n }\n for (let i = 0; i < side.length; i++) {\n this._previousAndSide.push(previous[i * 3], previous[i * 3 + 1], previous[i * 3 + 2], side[i]);\n this._nextAndCounters.push(next[i * 3], next[i * 3 + 1], next[i * 3 + 2], counters[i]);\n }\n uvs = (_a = this._options.uvs) !== null && _a !== void 0 ? _a : uvs;\n for (const uv of uvs) {\n this._uvs.push(uv);\n }\n });\n if (!this._lazy) {\n if (!this._options.colorPointers) {\n this._updateColorPointers();\n }\n this._createVertexBuffers();\n this.refreshBoundingInfo();\n }\n }\n _createLineOptions() {\n const lineOptions = {\n points: this._points,\n colorPointers: this._colorPointers,\n lazy: this._lazy,\n updatable: this._updatable,\n uvs: this._uvs,\n widths: this._widths,\n };\n return lineOptions;\n }\n /**\n * Clones the GreasedLineMesh.\n * @param name new line name\n * @param newParent new parent node\n * @returns cloned line\n */\n clone(name = `${this.name}-cloned`, newParent) {\n const lineOptions = this._createLineOptions();\n const deepCopiedLineOptions = {};\n DeepCopier.DeepCopy(lineOptions, deepCopiedLineOptions, [\"instance\"]);\n const cloned = new GreasedLineMesh(name, this._scene, deepCopiedLineOptions);\n if (newParent) {\n cloned.parent = newParent;\n }\n cloned.material = this.material;\n return cloned;\n }\n /**\n * Serializes this GreasedLineMesh\n * @param serializationObject object to write serialization to\n */\n serialize(serializationObject) {\n super.serialize(serializationObject);\n serializationObject.type = this.getClassName();\n serializationObject.lineOptions = this._createLineOptions();\n }\n /**\n * Parses a serialized GreasedLineMesh\n * @param parsedMesh the serialized GreasedLineMesh\n * @param scene the scene to create the GreasedLineMesh in\n * @returns the created GreasedLineMesh\n */\n static Parse(parsedMesh, scene) {\n const lineOptions = parsedMesh.lineOptions;\n const name = parsedMesh.name;\n const result = new GreasedLineMesh(name, scene, lineOptions);\n return result;\n }\n /**\n * Checks whether a ray is intersecting this GreasedLineMesh\n * @param ray ray to check the intersection of this mesh with\n * @param fastCheck not supported\n * @param trianglePredicate not supported\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\n * @param worldToUse not supported\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\n * @returns the picking info\n */\n intersects(ray, fastCheck, trianglePredicate, onlyBoundingInfo = false, worldToUse, skipBoundingInfo = false) {\n const pickingInfo = new PickingInfo();\n const intersections = this.findAllIntersections(ray, fastCheck, trianglePredicate, onlyBoundingInfo, worldToUse, skipBoundingInfo, true);\n if ((intersections === null || intersections === void 0 ? void 0 : intersections.length) === 1) {\n const intersection = intersections[0];\n pickingInfo.hit = true;\n pickingInfo.distance = intersection.distance;\n pickingInfo.ray = ray;\n pickingInfo.pickedMesh = this;\n pickingInfo.pickedPoint = intersection.point;\n }\n return pickingInfo;\n }\n /**\n * Gets all intersections of a ray and the line\n * @param ray Ray to check the intersection of this mesh with\n * @param _fastCheck not supported\n * @param _trianglePredicate not supported\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\n * @param _worldToUse not supported\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\n * @param firstOnly If true, the first and only intersection is immediatelly returned if found\n * @returns intersection(s)\n */\n findAllIntersections(ray, _fastCheck, _trianglePredicate, onlyBoundingInfo = false, _worldToUse, skipBoundingInfo = false, firstOnly = false) {\n var _a, _b;\n if (onlyBoundingInfo && !skipBoundingInfo && ray.intersectsSphere(this._boundingSphere, this.intersectionThreshold) === false) {\n return;\n }\n const indices = this.getIndices();\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\n const widths = this._widths;\n const lineWidth = (_b = (_a = this.greasedLineMaterial) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1;\n const intersects = [];\n if (indices && positions && widths) {\n let i = 0, l = 0;\n for (i = 0, l = indices.length - 1; i < l; i += 3) {\n const a = indices[i];\n const b = indices[i + 1];\n GreasedLineMesh._V_START.fromArray(positions, a * 3);\n GreasedLineMesh._V_END.fromArray(positions, b * 3);\n if (this._offsets) {\n GreasedLineMesh._V_OFFSET_START.fromArray(this._offsets, a * 3);\n GreasedLineMesh._V_OFFSET_END.fromArray(this._offsets, b * 3);\n GreasedLineMesh._V_START.addInPlace(GreasedLineMesh._V_OFFSET_START);\n GreasedLineMesh._V_END.addInPlace(GreasedLineMesh._V_OFFSET_END);\n }\n const iFloored = Math.floor(i / 3);\n const width = widths[iFloored] !== undefined ? widths[iFloored] : 1;\n const precision = (this.intersectionThreshold * (lineWidth * width)) / 2;\n const distance = ray.intersectionSegment(GreasedLineMesh._V_START, GreasedLineMesh._V_END, precision);\n if (distance !== -1) {\n intersects.push({\n distance: distance,\n point: ray.direction.normalize().multiplyByFloats(distance, distance, distance).add(ray.origin),\n });\n if (firstOnly) {\n return intersects;\n }\n }\n }\n i = l;\n }\n return intersects;\n }\n _initGreasedLine() {\n this._vertexPositions = [];\n this._previousAndSide = [];\n this._nextAndCounters = [];\n this._indices = [];\n this._uvs = [];\n }\n get _boundingSphere() {\n return this.getBoundingInfo().boundingSphere;\n }\n static _CompareV3(positionIdx1, positionIdx2, positions) {\n const arrayIdx1 = positionIdx1 * 6;\n const arrayIdx2 = positionIdx2 * 6;\n return positions[arrayIdx1] === positions[arrayIdx2] && positions[arrayIdx1 + 1] === positions[arrayIdx2 + 1] && positions[arrayIdx1 + 2] === positions[arrayIdx2 + 2];\n }\n static _CopyV3(positionIdx, positions) {\n const arrayIdx = positionIdx * 6;\n return [positions[arrayIdx], positions[arrayIdx + 1], positions[arrayIdx + 2]];\n }\n _preprocess(positions, previous, next, side, uvs) {\n const l = positions.length / 6;\n let v = [];\n if (GreasedLineMesh._CompareV3(0, l - 1, positions)) {\n v = GreasedLineMesh._CopyV3(l - 2, positions);\n }\n else {\n v = GreasedLineMesh._CopyV3(0, positions);\n }\n previous.push(v[0], v[1], v[2]);\n previous.push(v[0], v[1], v[2]);\n for (let j = 0; j < l; j++) {\n side.push(1);\n side.push(-1);\n // uvs\n if (!this._options.uvs) {\n uvs.push(j / (l - 1), 0);\n uvs.push(j / (l - 1), 1);\n }\n if (j < l - 1) {\n v = GreasedLineMesh._CopyV3(j, positions);\n previous.push(v[0], v[1], v[2]);\n previous.push(v[0], v[1], v[2]);\n }\n if (j > 0) {\n v = GreasedLineMesh._CopyV3(j, positions);\n next.push(v[0], v[1], v[2]);\n next.push(v[0], v[1], v[2]);\n }\n }\n if (GreasedLineMesh._CompareV3(l - 1, 0, positions)) {\n v = GreasedLineMesh._CopyV3(1, positions);\n }\n else {\n v = GreasedLineMesh._CopyV3(l - 1, positions);\n }\n next.push(v[0], v[1], v[2]);\n next.push(v[0], v[1], v[2]);\n return {\n previous,\n next,\n uvs,\n side,\n };\n }\n _createVertexBuffers() {\n const vertexData = new VertexData();\n vertexData.positions = this._vertexPositions;\n vertexData.indices = this._indices;\n vertexData.uvs = this._uvs;\n vertexData.applyToMesh(this, this._options.updatable);\n const engine = this._scene.getEngine();\n const previousAndSideBuffer = new Buffer$1(engine, this._previousAndSide, false, 4);\n this.setVerticesBuffer(previousAndSideBuffer.createVertexBuffer(\"grl_previousAndSide\", 0, 4));\n const nextAndCountersBuffer = new Buffer$1(engine, this._nextAndCounters, false, 4);\n this.setVerticesBuffer(nextAndCountersBuffer.createVertexBuffer(\"grl_nextAndCounters\", 0, 4));\n const widthBuffer = new Buffer$1(engine, this._widths, this._updatable, 1);\n this.setVerticesBuffer(widthBuffer.createVertexBuffer(\"grl_widths\", 0, 1));\n this._widthsBuffer = widthBuffer;\n const colorPointersBuffer = new Buffer$1(engine, this._colorPointers, this._updatable, 1);\n this.setVerticesBuffer(colorPointersBuffer.createVertexBuffer(\"grl_colorPointers\", 0, 1));\n this._colorPointersBuffer = colorPointersBuffer;\n }\n _createOffsetsBuffer(offsets) {\n const engine = this._scene.getEngine();\n const offsetBuffer = new Buffer$1(engine, offsets, this._updatable, 3);\n this.setVerticesBuffer(offsetBuffer.createVertexBuffer(\"grl_offsets\", 0, 3));\n this._offsetsBuffer = offsetBuffer;\n }\n }\n GreasedLineMesh._V_START = new Vector3();\n GreasedLineMesh._V_END = new Vector3();\n GreasedLineMesh._V_OFFSET_START = new Vector3();\n GreasedLineMesh._V_OFFSET_END = new Vector3();\n\n /**\n * How are the colors distributed along the color table\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#colors-and-colordistribution}\n */\n var GreasedLineMeshColorDistribution;\n (function (GreasedLineMeshColorDistribution) {\n /**\n * Do no modify the color table\n */\n GreasedLineMeshColorDistribution[GreasedLineMeshColorDistribution[\"COLOR_DISTRIBUTION_NONE\"] = 0] = \"COLOR_DISTRIBUTION_NONE\";\n /**\n * Repeat the colors until the color table is full\n */\n GreasedLineMeshColorDistribution[GreasedLineMeshColorDistribution[\"COLOR_DISTRIBUTION_REPEAT\"] = 1] = \"COLOR_DISTRIBUTION_REPEAT\";\n /**\n * Distribute the colors evenly through the color table\n */\n GreasedLineMeshColorDistribution[GreasedLineMeshColorDistribution[\"COLOR_DISTRIBUTION_EVEN\"] = 2] = \"COLOR_DISTRIBUTION_EVEN\";\n /**\n * Put the colors to start of the color table a fill the rest with the default color\n */\n GreasedLineMeshColorDistribution[GreasedLineMeshColorDistribution[\"COLOR_DISTRIBUTION_START\"] = 3] = \"COLOR_DISTRIBUTION_START\";\n /**\n * Put the colors to the end of the color table and fill the rest with the default color\n */\n GreasedLineMeshColorDistribution[GreasedLineMeshColorDistribution[\"COLOR_DISTRIBUTION_END\"] = 4] = \"COLOR_DISTRIBUTION_END\";\n /**\n * Put the colors to start and to the end of the color table and fill the gap between with the default color\n */\n GreasedLineMeshColorDistribution[GreasedLineMeshColorDistribution[\"COLOR_DISTRIBUTION_START_END\"] = 5] = \"COLOR_DISTRIBUTION_START_END\";\n })(GreasedLineMeshColorDistribution || (GreasedLineMeshColorDistribution = {}));\n /**\n * How are the widths distributed along the width table\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#widths-and-widthdistribution}\n */\n var GreasedLineMeshWidthDistribution;\n (function (GreasedLineMeshWidthDistribution) {\n /**\n * Do no modify the width table\n */\n GreasedLineMeshWidthDistribution[GreasedLineMeshWidthDistribution[\"WIDTH_DISTRIBUTION_NONE\"] = 0] = \"WIDTH_DISTRIBUTION_NONE\";\n /**\n * Repeat the widths until the width table is full\n */\n GreasedLineMeshWidthDistribution[GreasedLineMeshWidthDistribution[\"WIDTH_DISTRIBUTION_REPEAT\"] = 1] = \"WIDTH_DISTRIBUTION_REPEAT\";\n /**\n * Distribute the widths evenly through the width table\n */\n GreasedLineMeshWidthDistribution[GreasedLineMeshWidthDistribution[\"WIDTH_DISTRIBUTION_EVEN\"] = 2] = \"WIDTH_DISTRIBUTION_EVEN\";\n /**\n * Put the widths to start of the width table a fill the rest with the default width\n */\n GreasedLineMeshWidthDistribution[GreasedLineMeshWidthDistribution[\"WIDTH_DISTRIBUTION_START\"] = 3] = \"WIDTH_DISTRIBUTION_START\";\n /**\n * Put the widths to the end of the width table and fill the rest with the default width\n */\n GreasedLineMeshWidthDistribution[GreasedLineMeshWidthDistribution[\"WIDTH_DISTRIBUTION_END\"] = 4] = \"WIDTH_DISTRIBUTION_END\";\n /**\n * Put the widths to start and to the end of the width table and fill the gap between with the default width\n */\n GreasedLineMeshWidthDistribution[GreasedLineMeshWidthDistribution[\"WIDTH_DISTRIBUTION_START_END\"] = 5] = \"WIDTH_DISTRIBUTION_START_END\";\n })(GreasedLineMeshWidthDistribution || (GreasedLineMeshWidthDistribution = {}));\n\n const pWorking = new Vector3();\n const p1 = new Vector3();\n const p2 = new Vector3();\n const p3 = new Vector3();\n const uv1 = new Vector2();\n const uv2 = new Vector2();\n const uv3 = new Vector2();\n const workingUv = new Vector2();\n const workingUv2 = new Vector2();\n const working1 = new Vector3();\n class UVMapHelper {\n generateUVMapInPlace(vertexData, feature, indexList) {\n const newControlPointMap = {};\n const axis = feature.projectionAxis.toVec3();\n const rotation = rotationToVector(axis, new Vector3(0, 1, 0));\n rotation.multiplyInPlace(Quaternion.RotationAxis(new Vector3(0, 1, 0), (feature.angle / 180) * Math.PI));\n // const matrixRotation = new Matrix();\n // Matrix.FromQuaternionToRef(rotation, matrixRotation);\n const transformMatrix = Matrix.Compose(feature.scale ? feature.scale.toVec3() : Vector3.One(), rotation, Vector3.Zero());\n const transformMatrixInv = Matrix.Invert(transformMatrix);\n if (!vertexData.positions) {\n throw Error('No vertex positions on mesh');\n }\n if (!vertexData.indices) {\n throw Error('No vertex indices on mesh');\n }\n const geometryPositions = vertexData.positions;\n const geometryIndices = vertexData.indices;\n const controlPointCount = geometryPositions.length / 3;\n const newUvs = vertexData.uvs && vertexData.uvs.length === controlPointCount * 2\n ? new Float32Array(vertexData.uvs)\n : new Float32Array(controlPointCount * 2);\n const appendVertexData = {\n positions: [],\n normals: [],\n uvs: [],\n };\n const nbFaces = indexList ? indexList.length / 3 : geometryIndices.length / 3;\n const touchedControlPoints = new Int8Array(controlPointCount);\n if (indexList) {\n indexList.forEach(index => {\n touchedControlPoints[geometryIndices[index]] = 1;\n });\n }\n const outputUvs = [uv1, uv2, uv3];\n for (let i = 0; i < nbFaces; i++) {\n /** here we generate the new UVs */\n let i1;\n let i2;\n let i3;\n if (indexList) {\n i1 = indexList[i * 3];\n i2 = indexList[i * 3 + 1];\n i3 = indexList[i * 3 + 2];\n }\n else {\n i1 = i * 3;\n i2 = i * 3 + 1;\n i3 = i * 3 + 2;\n }\n const v1 = geometryIndices[i1];\n const v2 = geometryIndices[i2];\n const v3 = geometryIndices[i3];\n if (feature.mode === exports.eUvMode.useExisting) {\n if (vertexData.uvs) {\n const angle = (feature.angle / 180) * Math.PI;\n const vertices = [v1, v2, v3];\n for (let i = 0; i < 3; i++) {\n const uvIdx = vertices[i] * 2;\n const u = vertexData.uvs[uvIdx] - 0.5;\n const v = vertexData.uvs[uvIdx + 1] - 0.5;\n let newU = u * Math.cos(angle) - v * Math.sin(angle) + 0.5;\n let newV = u * Math.sin(angle) + v * Math.cos(angle) + 0.5;\n newU = newU * feature.uTile + feature.uOffset;\n newV = newV * feature.vTile + feature.vOffset;\n outputUvs[i].copyFromFloats(newU, newV);\n }\n }\n }\n else {\n const start = v1 * 3;\n p1.copyFromFloats(geometryPositions[start], geometryPositions[start + 1], geometryPositions[start + 2]);\n const start2 = v2 * 3;\n p2.copyFromFloats(geometryPositions[start2], geometryPositions[start2 + 1], geometryPositions[start2 + 2]);\n const start3 = v3 * 3;\n p3.copyFromFloats(geometryPositions[start3], geometryPositions[start3 + 1], geometryPositions[start3 + 2]);\n const normal = computeNormal([p1, p2, p3]);\n applyMatrix4(normal, transformMatrixInv);\n if (feature.center) {\n const center = feature.center.toVec3();\n p1.subtractInPlace(center);\n p2.subtractInPlace(center);\n p3.subtractInPlace(center);\n }\n this.updateFaceUVMapToRef(normal, p1, feature, transformMatrixInv, uv1);\n this.updateFaceUVMapToRef(normal, p2, feature, transformMatrixInv, uv2);\n this.updateFaceUVMapToRef(normal, p3, feature, transformMatrixInv, uv3);\n /**\n * Find the UV at the midpoint position between each edge of the polygon.\n * This should closely match the midpoints of the generated vertex UVs.If it does not, we must wrap the UVs at that edge to avoid a UV seam.\n * The tolerance is an arbitrary number to avoid artifacts. If wrapping is occuring when it shouldn't, increase this number.\n * If wrapping is not occurring when it should, reduce it.\n * As you try to wrap a uv on polygons that are not arranged in a good way to accept them (i.e wrap a sphere onto a 8-vertex cube), the error will become significant.\n */\n const tolerance = 0.05;\n working1.copyFrom(p1);\n this.updateFaceUVMapToRef(normal, working1.addInPlace(p2).scaleInPlace(0.5), feature, transformMatrixInv, workingUv);\n workingUv2.copyFrom(uv1);\n workingUv2.addInPlace(uv2).scaleInPlace(0.5);\n workingUv.subtractInPlace(workingUv2);\n if (Math.abs(workingUv.x % 1) > tolerance) {\n if (uv1.x > uv2.x)\n uv1.x -= 1;\n else\n uv2.x -= 1;\n }\n if (Math.abs(workingUv.y % 1) > tolerance) {\n if (uv1.y > uv2.y)\n uv1.y -= 1;\n else\n uv2.y -= 1;\n }\n if (uv2.x >= 0 && uv2.y >= 0) {\n working1.copyFrom(p2);\n this.updateFaceUVMapToRef(normal, working1.addInPlace(p3).scaleInPlace(0.5), feature, transformMatrixInv, workingUv);\n workingUv2.copyFrom(uv2);\n workingUv2.addInPlace(uv3).scaleInPlace(0.5);\n workingUv.subtractInPlace(workingUv2);\n if (Math.abs(workingUv.x % 1) > tolerance) {\n if (uv2.x > uv3.x)\n uv2.x -= 1;\n else\n uv3.x -= 1;\n }\n if (Math.abs(workingUv.y % 1) > tolerance) {\n if (uv2.y > uv3.y)\n uv2.y -= 1;\n else\n uv3.y -= 1;\n }\n }\n if (uv1.x >= 0 && uv1.y >= 0 && uv3.x >= 0 && uv3.y >= 0) {\n working1.copyFrom(p1);\n this.updateFaceUVMapToRef(normal, working1.addInPlace(p3).scaleInPlace(0.5), feature, transformMatrixInv, workingUv);\n workingUv2.copyFrom(uv1);\n workingUv2.addInPlace(uv3).scaleInPlace(0.5);\n workingUv.subtractInPlace(workingUv2);\n if (Math.abs(workingUv.x % 1) > tolerance) {\n if (uv1.x > uv3.x)\n uv1.x -= 1;\n else\n uv3.x -= 1;\n }\n if (Math.abs(workingUv.y % 1) > tolerance) {\n if (uv1.y > uv3.y)\n uv1.y -= 1;\n else\n uv3.y -= 1;\n }\n }\n }\n /** Done generating the new UVs, stored in uv1, uv2 and uv3 for this polygon */\n if (touchedControlPoints[v1]) {\n expandControlPoints(i1, v1, uv1);\n }\n else {\n newUvs[v1 * 2] = uv1.x;\n newUvs[v1 * 2 + 1] = uv1.y;\n }\n if (touchedControlPoints[v2]) {\n expandControlPoints(i2, v2, uv2);\n }\n else {\n newUvs[v2 * 2] = uv2.x;\n newUvs[v2 * 2 + 1] = uv2.y;\n }\n if (touchedControlPoints[v3]) {\n expandControlPoints(i3, v3, uv3);\n }\n else {\n newUvs[v3 * 2] = uv3.x;\n newUvs[v3 * 2 + 1] = uv3.y;\n }\n touchedControlPoints[v1] = 1;\n touchedControlPoints[v2] = 1;\n touchedControlPoints[v3] = 1;\n }\n if (appendVertexData.positions.length > 0) {\n const newPositions = new Float32Array(vertexData.positions.length + appendVertexData.positions.length);\n newPositions.set(vertexData.positions);\n newPositions.set(appendVertexData.positions, vertexData.positions.length);\n vertexData.positions = newPositions;\n }\n if (vertexData.normals && appendVertexData.normals.length > 0) {\n const newNormals = new Float32Array(vertexData.normals.length + appendVertexData.normals.length);\n newNormals.set(vertexData.normals);\n newNormals.set(appendVertexData.normals, vertexData.normals.length);\n vertexData.normals = newNormals;\n }\n if (appendVertexData.uvs.length > 0) {\n const newUvsTyped = new Float32Array(newUvs.length + appendVertexData.uvs.length);\n newUvsTyped.set(newUvs);\n newUvsTyped.set(appendVertexData.uvs, newUvs.length);\n vertexData.uvs = newUvsTyped;\n }\n else {\n vertexData.uvs = new Float32Array(newUvs);\n }\n return vertexData;\n function expandControlPoints(index, vertexIndex, newUv) {\n if (newUvs[vertexIndex * 2] !== newUv.x || newUvs[vertexIndex * 2 + 1] !== newUv.y) {\n if (!vertexData.positions || !vertexData.indices) {\n throw Error('Invalid geometry: positions or indices are null');\n }\n const indices = vertexData.indices;\n const positions = vertexData.positions;\n const normals = vertexData.normals;\n const key = positions[vertexIndex * 3].toPrecision(6) +\n ',' +\n positions[vertexIndex * 3 + 1].toPrecision(6) +\n ',' +\n positions[vertexIndex * 3 + 2].toPrecision(6) +\n '_' +\n (normals\n ? normals[vertexIndex * 3].toPrecision(6) +\n ',' +\n normals[vertexIndex * 3 + 1].toPrecision(6) +\n ',' +\n normals[vertexIndex * 3 + 2].toPrecision(6) +\n '_'\n : '') +\n newUv.x.toPrecision(6) +\n ',' +\n newUv.y.toPrecision(6);\n if (newControlPointMap[key]) {\n indices[index] = newControlPointMap[key];\n }\n else {\n const newVertexIndex = (positions.length + appendVertexData.positions.length) / 3;\n indices[index] = newVertexIndex;\n appendVertexData.positions.push(...positions.slice(vertexIndex * 3, vertexIndex * 3 + 3));\n if (vertexData.normals) {\n appendVertexData.normals.push(...vertexData.normals.slice(vertexIndex * 3, vertexIndex * 3 + 3));\n }\n appendVertexData.uvs.push(newUv.x, newUv.y);\n if (vertexData.submeshData) {\n for (let i = 0; i < vertexData.submeshData.length; i++) {\n const submeshData = vertexData.submeshData[i];\n if (submeshData.verticesStart <= vertexIndex &&\n submeshData.verticesStart + submeshData.verticesCount > vertexIndex) {\n submeshData.verticesCount += 1;\n }\n else if (submeshData.verticesStart > vertexIndex) {\n submeshData.verticesStart += 1;\n }\n }\n }\n newControlPointMap[key] = newVertexIndex;\n }\n }\n }\n }\n computeAutoFitSize(mesh) {\n const boundingBox = mesh.getBoundingInfo().boundingBox;\n //const center = boundingBox.center;\n const max = boundingBox.maximum;\n const min = boundingBox.minimum;\n return new exports.KbVector(max.x - min.x, max.y - min.y, max.z - min.z);\n }\n updateFaceUVMapToRef(faceNormal, position, feat, transformMatrixInv, uv) {\n pWorking.copyFrom(position);\n applyMatrix4(pWorking, transformMatrixInv);\n switch (feat.mode) {\n case exports.eUvMode.planar:\n this.planarUVMap(pWorking, uv);\n break;\n case exports.eUvMode.box:\n this.boxUVMap(pWorking, faceNormal, uv);\n break;\n case exports.eUvMode.cylindrical:\n this.cylindricalUVMap(pWorking, uv);\n break;\n case exports.eUvMode.spherical:\n this.sphericalUVMap(pWorking, uv);\n break;\n case exports.eUvMode.useExisting:\n //don't do anything so that existing UVs of mesh are being used instead\n break;\n default:\n uv.set(0, 0);\n break;\n }\n if (feat.uTile && feat.uTile !== 1) {\n uv.x *= feat.uTile;\n }\n if (feat.vTile && feat.vTile !== 1) {\n uv.y *= feat.vTile;\n }\n return uv;\n }\n planarUVMap(vertex, uv) {\n let u = vertex.x;\n let v = -vertex.z;\n u = u + 0.5;\n v = v + 0.5;\n uv.set(u, v);\n return uv;\n }\n cylindricalUVMap(vertex, uv) {\n let lon;\n if (vertex.x === 0 && vertex.z === 0) {\n lon = 0;\n }\n else {\n lon = Math.atan2(vertex.x, vertex.z);\n if (lon < 0) {\n lon += Math.PI * 2;\n }\n }\n const t = vertex.y + 0.5;\n lon = lon / (Math.PI * 2);\n uv.set(lon, t);\n return uv;\n }\n boxUVMap(vertex, normal, uv) {\n let s = 0, t = 0;\n const x = vertex.x, y = vertex.y, z = vertex.z;\n const nx = Math.abs(normal.x), ny = Math.abs(normal.y), nz = Math.abs(normal.z);\n if (nx >= ny && nx >= nz) {\n s = -z + 0.5;\n t = y + 0.5;\n }\n if (ny >= nx && ny >= nz) {\n s = x + 0.5;\n t = -z + 0.5;\n }\n if (nz >= nx && nz >= ny) {\n s = x + 0.5;\n t = y + 0.5;\n }\n // not sure what this is for but it screws up the mapping and flips the uv's halfway through\n // if (normal.x < 0) {\n // s = -s + 1\n // }\n // if (normal.y < 0) {\n // s = -s + 1\n // }\n // if (normal.z < 0) {\n // s = -s + 1\n // }\n uv.set(s, t);\n return uv;\n }\n sphericalUVMap(vertex, uv) {\n const newVertex = vertex.clone();\n const lonlat = xyzToLongitudeLatitude(newVertex.x, -newVertex.y, newVertex.z);\n const lon = lonlat.lon / (Math.PI * 2);\n const lat = 0.5 - lonlat.lat / Math.PI;\n uv.set(lon, lat);\n return uv;\n function xyzToLongitudeLatitude(x, y, z) {\n let lo, la;\n const EPSILON = 1e-6;\n if (Math.abs(x) < EPSILON && Math.abs(z) < EPSILON) {\n lo = 0;\n if (Math.abs(y) < EPSILON) {\n la = 0;\n }\n else {\n la = y < 0 ? -(Math.PI / 2) : Math.PI / 2;\n }\n }\n else {\n lo = Math.atan2(x, z);\n if (lo < 0) {\n lo += Math.PI * 2;\n }\n const h = Math.sqrt(x * x + z * z);\n la = Math.atan2(y, h);\n }\n return {\n lon: lo,\n lat: la,\n };\n }\n }\n }\n function createUvMapVisualization(uvMap, scene, color) {\n let uvMapVisualization;\n if (!color) {\n color = Color3.Yellow();\n }\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n if (uvMap.mode === exports.eUvMode.spherical) {\n uvMapVisualization = CreateSphere('UvMapSphere', { segments: 6 }, scene);\n }\n else if (uvMap.mode === exports.eUvMode.cylindrical) {\n uvMapVisualization = CreateCylinder('UvMapCylinder', { tessellation: 10 }, scene);\n }\n else if (uvMap.mode === exports.eUvMode.box) {\n uvMapVisualization = CreateBox('UvBox', {}, scene);\n }\n else if (uvMap.mode === exports.eUvMode.planar) {\n uvMapVisualization = CreatePlane('mirrorPlane', {}, scene);\n uvMapVisualization.rotation = new Vector3(Math.PI / 2, 0, 0);\n uvMapVisualization.bakeCurrentTransformIntoVertices();\n }\n else {\n uvMapVisualization = CreatePlane('mirrorPlane', {}, scene);\n uvMapVisualization.bakeCurrentTransformIntoVertices();\n uvMapVisualization.setEnabled(false);\n }\n uvMapVisualization.material = coloredMaterial;\n return uvMapVisualization;\n }\n\n function removeVerticesFromAll(vertexGroups, startIndex, endIndex) {\n for (let i = 0; i < vertexGroups.length; i++) {\n const vertexGroup = vertexGroups[i];\n if (vertexGroupsIntersect(vertexGroup, startIndex, endIndex)) {\n const result = excludeVertices(vertexGroup, startIndex, endIndex);\n vertexGroups.splice(i, 1, ...result);\n }\n }\n }\n function mergeVerticesIntoAll(vertexGroups, newVertex) {\n vertexGroups.push(newVertex);\n vertexGroups.sort((a, b) => a.startIndex - b.startIndex);\n for (let i = 0; i < vertexGroups.length; i++) {\n const vertexGroup = vertexGroups[i];\n const nextVertexGroup = vertexGroups[i + 1];\n if (nextVertexGroup && nextVertexGroup.startIndex < vertexGroup.endIndex) {\n const mergedVertexGroup = { ...vertexGroup, endIndex: nextVertexGroup.endIndex };\n vertexGroups.splice(i, 2, mergedVertexGroup);\n i--;\n }\n }\n }\n function excludeVertices(vertexGroup, startIndex, endIndex) {\n if (vertexGroupsIntersect(vertexGroup, startIndex, endIndex)) {\n const result = [];\n // Maintain the selections of either side of the current vertex\n if (startIndex > vertexGroup.startIndex) {\n result.push({\n ...vertexGroup,\n endIndex: startIndex,\n });\n }\n if (endIndex < vertexGroup.endIndex) {\n result.push({\n ...vertexGroup,\n startIndex: endIndex,\n });\n }\n return result;\n }\n else {\n return [vertexGroup];\n }\n }\n function mergeVertices(vertexGroup, newVertex) {\n const result = [];\n const newVertexGroup = { ...vertexGroup };\n const startIndex = newVertex.startIndex;\n const endIndex = newVertex.endIndex;\n if (vertexGroupsIntersect(vertexGroup, startIndex, endIndex)) {\n // Maintain the selections of either side of the current vertex\n if (startIndex < vertexGroup.startIndex) {\n newVertexGroup.startIndex = startIndex;\n }\n if (endIndex > vertexGroup.endIndex) {\n newVertexGroup.endIndex = endIndex;\n }\n result.push(newVertexGroup);\n }\n else {\n if (startIndex > vertexGroup.startIndex) {\n result.push(newVertexGroup, newVertex);\n }\n else {\n result.push(newVertex, newVertexGroup);\n }\n }\n return result;\n }\n function vertexGroupsIntersect(vertexGroup, startIndex, endIndex) {\n return startIndex <= vertexGroup.endIndex && endIndex >= vertexGroup.startIndex;\n }\n\n function createViewpointVisualization(viewpoint, scene, color) {\n if (!color) {\n color = Color3.Green();\n }\n let targetPositionMarker;\n const viewpointPositionGizmo = MeshBuilder.CreateCylinder('cameraGizmoLens', { diameterTop: 0.3, height: 0.2, diameterBottom: 0.2, tessellation: 8 }, scene);\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n viewpointPositionGizmo.material = coloredMaterial;\n const lightPositionGizmoBox = MeshBuilder.CreateBox('cameraGizmoBody', { size: 0.4 }, scene);\n lightPositionGizmoBox.setParent(viewpointPositionGizmo);\n lightPositionGizmoBox.position = new Vector3(0, -0.3, 0);\n lightPositionGizmoBox.material = coloredMaterial;\n viewpointPositionGizmo.isPickable = false;\n viewpointPositionGizmo.setEnabled(true);\n if (viewpoint.type === exports.eViewpointType.orbit && viewpoint.targetMode === exports.eViewpointTargetMode.point) {\n targetPositionMarker = MeshBuilder.CreateSphere('viewpointTargetMarker', { diameter: 0.15 }, scene);\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.emissiveColor = color;\n targetPositionMarker.material = coloredMaterial;\n targetPositionMarker.isPickable = false;\n targetPositionMarker.setEnabled(true);\n }\n return { viewpointPositionGizmo, targetPositionMarker };\n }\n\n /** The maxiumum amount of allowed time to spend in a single render cycle, to avoid locking the browser */\n const MAX_RENDER_TIME = 20000;\n class Renderer {\n constructor(viewer, scene) {\n this.viewer = viewer;\n this.scene = scene;\n this.babylonMap = new Map();\n }\n /**\n * Determines whether the given node should be handled by this renderer. Can be\n * overriden for special behavior\n */\n handlesNode(node) {\n return instanceOf(node, this.modelToken);\n }\n update3d(node) {\n this.update3dInternal(node);\n if (this.viewer.options.validator) {\n this.viewer.options.validator.validateNode(node);\n }\n }\n delete3d(node) {\n const o = this.babylonMap.get(node._dynamicId);\n if (o) {\n if (o instanceof Material) {\n o.dispose(true, true);\n }\n else {\n o.dispose();\n }\n }\n this.babylonMap.delete(node._dynamicId);\n SyncService.nodeDeletionProcessed(node);\n }\n get3d(node) {\n return this.babylonMap.get(node._dynamicId);\n }\n set3d(node, babylonObject) {\n this.babylonMap.set(node._dynamicId, babylonObject);\n }\n getChanges(node) {\n const isNew = this.get3d(node) == null;\n const changes = new Map(node.changes);\n if (isNew) {\n for (const prop in node) {\n changes.set(prop, node[prop]);\n }\n }\n return changes;\n }\n dispose() {\n this.babylonMap.clear();\n }\n }\n\n const TEXT_RESOLUTION = 128;\n class AnnotationRenderer extends Renderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene);\n this.viewer = viewer;\n this.scene = scene;\n this.rendererManager = rendererManager;\n this.modelToken = Token.AnnotationNode;\n this.annotationStore = new Map();\n this.billboards = new Map();\n this.utilityLayer = viewer.utilityLayer;\n scene.registerBeforeRender(() => {\n if (scene.activeCamera && this.billboards.size > 0) {\n this.billboards.forEach(meshInfo => {\n const camera = scene.activeCamera;\n meshInfo.rootMesh.lookAt(getCameraPositionWithOffset(camera), 0, Math.PI / 2);\n if (meshInfo.rootMesh.parent) {\n if (!meshInfo.rootMesh.rotationQuaternion) {\n meshInfo.rootMesh.rotationQuaternion = Quaternion.Identity();\n }\n const parentRotation = meshInfo.rootMesh.parent.computeWorldMatrix().getRotationMatrix();\n parentRotation.invert();\n const parentRotationQuat = Quaternion.FromRotationMatrix(parentRotation);\n meshInfo.rootMesh.rotationQuaternion = parentRotationQuat.multiplyInPlace(meshInfo.rootMesh.rotationQuaternion);\n }\n });\n }\n });\n }\n update3dInternal(node) {\n var _a, _b, _c, _d;\n let annotationInfo = this.annotationStore.get(node._dynamicId);\n if (!annotationInfo) {\n annotationInfo = {\n positionNeedsUpdate: false,\n textNeedsUpdate: false,\n lineNeedsUpdate: false,\n };\n this.annotationStore.set(node._dynamicId, annotationInfo);\n }\n if (annotationInfo.meshInfo && node.changes.has('keepOnTop')) {\n this.delete3d(node, true);\n annotationInfo.meshInfo = undefined;\n annotationInfo.positionNeedsUpdate = true;\n annotationInfo.textNeedsUpdate = true;\n annotationInfo.lineNeedsUpdate = true;\n }\n const scene = node.keepOnTop ? this.utilityLayer.utilityLayerScene : this.scene;\n if ((!annotationInfo.meshInfo && node.enabled && node.targetId) ||\n (node.changes.hasAny('isPickable') && node.enabled && node.targetId)) {\n if (annotationInfo.meshInfo) {\n annotationInfo.meshInfo = undefined;\n }\n annotationInfo.meshInfo = createAnnotationTextModels(node, scene);\n // Put the annotation on the parent scene so the scene visibility affects the node\n if (node._parentScene) {\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\n annotationInfo.meshInfo.rootMesh.setParent(parentSceneMesh);\n }\n this.set3d(node, annotationInfo.meshInfo.rootMesh);\n }\n const meshInfo = annotationInfo.meshInfo;\n // Set position of annotation\n if (node.changes.hasAny('targetId', 'offset', 'billboard', 'horizontalBoxAlign', 'verticalBoxAlign')) {\n annotationInfo.positionNeedsUpdate = true;\n }\n if (node.changes.hasAny('color', 'lineStyle')) {\n annotationInfo.lineNeedsUpdate = true;\n }\n if (node.changes.hasAny('fontFamily', 'fontSize', 'lineSpacing', 'label', 'color', 'preloadFontStylesheet', 'horizontalTextAlign')) {\n annotationInfo.textNeedsUpdate = true;\n }\n if (meshInfo) {\n if (node.changes.hasAny('enabled', 'billboard', 'keepOnTop')) {\n if (node.enabled && node.billboard) {\n this.billboards.set(node._dynamicId, meshInfo);\n }\n else {\n this.billboards.delete(node._dynamicId);\n }\n }\n let needsFont = false;\n if (node.preloadFontStylesheet && node.fontFamily) {\n const fontService = node._manager.getService(Token.FontService);\n if (!fontService.readyFonts.has(node.fontFamily)) {\n needsFont = true;\n fontService.loadFont(node.preloadFontStylesheet, [node.fontFamily]).then(resultFonts => {\n if (resultFonts.length > 0) {\n node.setPropertyIsModified('fontFamily', true);\n }\n });\n }\n }\n if (node.enabled && node.targetId && !needsFont) {\n const color = node.color.toColor4();\n if (annotationInfo.positionNeedsUpdate) {\n let targetNode;\n if (node.targetId && node._manager) {\n const manager = node._manager;\n targetNode = manager.getById(node.targetId);\n }\n if (annotationInfo.boundingInfo &&\n annotationInfo.boundingInfo.targetNode._dynamicId !== (targetNode === null || targetNode === void 0 ? void 0 : targetNode._dynamicId)) {\n annotationInfo.boundingInfo.subscription.unsubscribe();\n }\n if (targetNode) {\n if (targetNode instanceof exports.Connector) {\n // Only supporting connectors for now\n if (targetNode._parent) {\n annotationInfo.boundingInfo = {\n targetNode: targetNode,\n subscription: this.viewer.bbCache\n .watchForChanges(targetNode._parent)\n .subscribe(() => {\n node.setPropertyIsModified('targetId', true);\n }),\n };\n }\n }\n const transform = this.updatePositionFromAnnotation(node, targetNode, meshInfo);\n if (transform) {\n meshInfo.rootMesh.position = transform.position;\n // The annotation plane mesh position doesn't update in certain situations when the parent transform is moved,\n // so we have to manually update the world matrix\n meshInfo.rootMesh.getChildMeshes().forEach(mesh => mesh.computeWorldMatrix(true));\n meshInfo.textContainer.rotationQuaternion = transform.textRotation;\n if (!node.billboard) {\n meshInfo.rootMesh.rotationQuaternion = transform.rotation;\n }\n if (transform && transform.offset && transform.lineOffset && node.offset.length() > 0) {\n const basePoint = transform.position.subtract(transform.offset);\n meshInfo.line = {\n points: [basePoint, basePoint.add(transform.lineOffset)],\n updatable: true,\n colors: [color, color],\n instance: (_a = meshInfo.line) === null || _a === void 0 ? void 0 : _a.instance,\n };\n // If the line is not getting rebuilt, then just update the line position\n if (!annotationInfo.lineNeedsUpdate) {\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\n }\n }\n else {\n if ((_b = meshInfo.line) === null || _b === void 0 ? void 0 : _b.instance) {\n meshInfo.line.instance.dispose();\n }\n meshInfo.line = undefined;\n }\n }\n annotationInfo.positionNeedsUpdate = false;\n }\n }\n if (annotationInfo.lineNeedsUpdate) {\n if (meshInfo.line) {\n if (meshInfo.line.instance) {\n meshInfo.line.instance.dispose();\n meshInfo.line.instance = undefined;\n }\n meshInfo.line.colors = [];\n for (let i = 0; i < meshInfo.line.points.length; i++) {\n meshInfo.line.colors.push(color);\n }\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\n if (meshInfo.line.instance && node._parentScene) {\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\n meshInfo.line.instance.parent = parentSceneMesh;\n }\n annotationInfo.lineNeedsUpdate = false;\n }\n }\n if (annotationInfo.textNeedsUpdate) {\n updateAnnotationText(node, meshInfo.textMesh, meshInfo.textMaterial, this.scene.getEngine().webGLVersion < 2);\n annotationInfo.textNeedsUpdate = false;\n }\n }\n const enabled = node.enabled && !!node.targetId;\n if (meshInfo.rootMesh.isEnabled() !== enabled) {\n meshInfo.rootMesh.setEnabled(enabled);\n (_d = (_c = meshInfo.line) === null || _c === void 0 ? void 0 : _c.instance) === null || _d === void 0 ? void 0 : _d.setEnabled(enabled);\n }\n }\n }\n dispose() {\n this.billboards.clear();\n this.annotationStore.clear();\n super.dispose();\n }\n delete3d(node, keepInStore = false) {\n var _a;\n const annotationModels = this.annotationStore.get(node._dynamicId);\n if (annotationModels && annotationModels.meshInfo) {\n annotationModels.meshInfo.rootMesh.dispose();\n if ((_a = annotationModels.meshInfo.line) === null || _a === void 0 ? void 0 : _a.instance) {\n annotationModels.meshInfo.line.instance.dispose();\n }\n }\n if (!keepInStore) {\n this.annotationStore.delete(node._dynamicId);\n this.billboards.delete(node._dynamicId);\n }\n super.delete3d(node);\n }\n updatePositionFromAnnotation(node, targetNode, meshInfo) {\n let newPosition;\n let newDirection;\n let newAngle;\n // Only supporting connectors for now, but could support direct mesh targets in the future\n if (targetNode instanceof exports.Connector) {\n newPosition = getPositionFromConnnector(targetNode, this.rendererManager, node._parentScene);\n newDirection = targetNode.direction.toVec3();\n newAngle = targetNode.angle;\n }\n if (newPosition && newDirection && newAngle !== undefined) {\n const newOffset = node.offset.toVec3();\n if (meshInfo) {\n const newPivot = new Vector3(0, 0, 0);\n if (node.horizontalBoxAlign == 'left') {\n meshInfo.rootMesh.getPivotPoint();\n newOffset.x += meshInfo.textMesh.scaling.x / 2;\n newPivot.x -= meshInfo.textMesh.scaling.x / 2;\n }\n else if (node.horizontalBoxAlign == 'right') {\n newOffset.x -= meshInfo.textMesh.scaling.x / 2;\n newPivot.x += meshInfo.textMesh.scaling.x / 2;\n }\n if (node.verticalBoxAlign == 'top') {\n newOffset.z += meshInfo.textMesh.scaling.z / 2;\n newPivot.z -= meshInfo.textMesh.scaling.z / 2;\n }\n else if (node.verticalBoxAlign == 'bottom') {\n newOffset.z -= meshInfo.textMesh.scaling.z / 2;\n newPivot.z += meshInfo.textMesh.scaling.z / 2;\n }\n meshInfo.rootMesh.setPivotPoint(newPivot);\n }\n const transform = calculateTransform(newPosition, newDirection, newAngle, newOffset, node.offset.toVec3());\n return transform;\n }\n }\n }\n function createAnnotationTextModels(node, scene, isPickable = false) {\n const containerMesh = new TransformNode(node._dynamicId, scene);\n //Create plane\n const plane = PlaneBuilder.CreatePlane(`${node._dynamicId}_plane`, {\n width: 1,\n height: 1,\n frontUVs: new Vector4(1, 0, 0, 1),\n backUVs: new Vector4(0, 0, 1, 1),\n sideOrientation: Mesh.DOUBLESIDE,\n sourcePlane: new Plane(0, 1, 0, 0),\n }, scene);\n const planeContainer = new TransformNode(`${node._dynamicId}_planeContainer`);\n const dynamicTexture = new DynamicTexture(`${node._dynamicId}_planeTexture`, { width: TEXT_RESOLUTION, height: TEXT_RESOLUTION }, scene, true);\n dynamicTexture.isBlocking = false;\n dynamicTexture.hasAlpha = true;\n //create material\n const mat = new PBRMaterial(`${node._dynamicId}_mat`, scene);\n if (node.keepOnTop) {\n mat.emissiveColor = Color3.White();\n }\n mat.albedoTexture = dynamicTexture;\n mat.useAlphaFromAlbedoTexture = true;\n mat.backFaceCulling = true;\n mat.zOffset = -1;\n mat.albedoColor = Color3.White();\n mat.roughness = 1;\n mat.metallic = 0;\n //apply material\n plane.material = mat;\n plane.parent = planeContainer;\n planeContainer.parent = containerMesh;\n plane.isPickable = isPickable || node.isPickable;\n const annotationModels = {\n textMesh: plane,\n textContainer: planeContainer,\n textMaterial: mat,\n rootMesh: containerMesh,\n billboard: node.billboard,\n positionNeedsUpdate: false,\n textNeedsUpdate: false,\n };\n return annotationModels;\n }\n function updateAnnotationText(node, mesh, textMaterial, webgl1Context, defaultValue = ' ', values = {}) {\n const mat = textMaterial;\n const dynamicTexture = mat.albedoTexture;\n const fontFamily = node.fontFamily || 'Arial';\n const labelSize = node.fontSize;\n const labelText = evalHandlebarString(node.label || defaultValue, values);\n const textGap = node.lineSpacing;\n const textColor = node.color.toColor3().toLinearSpace();\n if (node.keepOnTop) {\n mat.emissiveColor = textColor;\n }\n // Determine the space needed for the text\n const ctx = dynamicTexture.getContext();\n ctx.font = TEXT_RESOLUTION + 'px ' + fontFamily;\n const labelStats = getMultiLineStats(labelText, ctx);\n const textWidth = labelStats.maximumWidth;\n const textHeight = labelStats.maximumHeight;\n const labelArray = labelStats.labelArray;\n const lineWidths = labelStats.lineWidths;\n labelArray.reverse();\n lineWidths.reverse();\n const totalCanvasHeight = (textHeight + textGap) * labelArray.length - textGap;\n ctx.clearRect(0 - textWidth / 2, 0, textWidth / 2, totalCanvasHeight);\n //ctx.clearRect(0, 0, textWidth, totalCanvasHeight);\n let heightRatioChange = 1;\n if (labelArray.length > 1) {\n heightRatioChange = totalCanvasHeight / textHeight;\n }\n mesh.scaling = new Vector3((textWidth / textHeight) * labelSize, labelSize * heightRatioChange, 1);\n let textBaseline = 'bottom';\n if (labelStats.maximumDescent > 0) {\n textBaseline = 'alphabetic';\n }\n let drawFont;\n if (webgl1Context) {\n let textureSize = getBinClampedSize(textWidth, totalCanvasHeight, 'ceil');\n if (textureSize > 2048) {\n textureSize = 2048;\n }\n dynamicTexture.scaleTo(textureSize, textureSize);\n ctx.scale(textureSize / textWidth, textureSize / totalCanvasHeight);\n drawFont = TEXT_RESOLUTION + 'px ' + fontFamily;\n }\n else {\n dynamicTexture.scaleTo(textWidth, totalCanvasHeight);\n drawFont = TEXT_RESOLUTION + 'px ' + fontFamily;\n }\n ctx.font = drawFont;\n if (ctx instanceof CanvasRenderingContext2D) {\n ctx.textBaseline = textBaseline;\n }\n ctx.fillStyle = textColor.toHexString();\n let drawHeight = totalCanvasHeight;\n for (let i = 0; i < labelArray.length; i++) {\n const lineWidth = lineWidths[i];\n //ctx.fillStyle = 'rgb(132,244,235, 0.3)';\n //ctx.fillRect(0, 0, textWidth, (textHeight + textGap) * labelArray.length - textGap);\n //rightAllign\n if (node.horizontalTextAlign === 'right') {\n ctx.fillText(labelArray[i], textWidth - lineWidth, drawHeight - labelStats.maximumDescent);\n }\n //leftAllign\n else if (node.horizontalTextAlign === 'left') {\n ctx.fillText(labelArray[i], 0, drawHeight - labelStats.maximumDescent);\n }\n else {\n //centered:\n ctx.fillText(labelArray[i], textWidth / 2 - lineWidth / 2, drawHeight - labelStats.maximumDescent);\n }\n drawHeight = drawHeight - textHeight - textGap;\n }\n // reset the context\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n dynamicTexture.update(true);\n }\n function getPositionFromConnnector(targetNode, rendererManager, relativeToScene) {\n const targetMesh = rendererManager.connector.get3d(targetNode);\n if (targetMesh) {\n targetMesh.computeWorldMatrix(true);\n const result = targetMesh.absolutePosition.clone();\n if (relativeToScene) {\n const sceneMesh = rendererManager.viewer.getRendererNode(relativeToScene);\n if (sceneMesh) {\n // console.log('pre', newPosition, newDirection, newAngle);\n const transform = sceneMesh.getWorldMatrix().clone();\n transform.invert();\n return Vector3.TransformCoordinates(result, transform);\n }\n }\n return result;\n }\n return Vector3.Zero();\n }\n function calculateTransform(position, direction, angle, offset, lineOffset) {\n const newPosition = position.clone();\n const newRotation = rotationToVector(direction);\n const textRotation = Quaternion.RotationAxis(Vector3.Up(), (angle - 90) * (Math.PI / 180));\n let offsetWithTransform;\n let lineOffsetWithTransform;\n if (offset) {\n offsetWithTransform = transformVectorWithQuat(offset, newRotation);\n newPosition.addInPlace(offsetWithTransform);\n }\n if (lineOffset) {\n lineOffsetWithTransform = transformVectorWithQuat(lineOffset, newRotation);\n }\n return {\n position: newPosition,\n rotation: newRotation,\n textRotation: textRotation,\n offset: offsetWithTransform,\n lineOffset: lineOffsetWithTransform,\n };\n }\n function drawLine(node, lineInfo, lineLength, scene, distance) {\n if (lineInfo && node.lineStyle !== exports.eAnnotationLineStyle.none) {\n let linesMesh;\n if (node.lineStyle === exports.eAnnotationLineStyle.solid) {\n linesMesh = MeshBuilder.CreateLines(`${node._dynamicId}_line`, lineInfo, scene);\n }\n else {\n lineInfo.dashNb = lineLength * 30;\n if (node.lineStyle === exports.eAnnotationLineStyle.dashed) {\n lineInfo.gapSize = 4;\n lineInfo.dashSize = 6;\n if (distance) {\n // lineInfo.gapSize *= distance;\n // lineInfo.dashSize *= distance;\n lineInfo.dashNb = (lineInfo.dashNb / distance) * 1.5;\n }\n }\n else {\n lineInfo.gapSize = 6;\n lineInfo.dashSize = 1;\n }\n linesMesh = MeshBuilder.CreateDashedLines(`${node._dynamicId}_line`, lineInfo, scene);\n linesMesh.color = node.color.toColor3();\n }\n lineInfo.instance = linesMesh;\n lineInfo.instance.isPickable = false;\n return linesMesh;\n }\n }\n function evalHandlebarString(label, values) {\n if (!label.match(/\\{.*\\}/)) {\n return label;\n }\n const array = label.matchAll(/\\{([\\d\\w+\\-*/]+)\\}/g);\n let exp = array.next();\n while (!exp.done) {\n let mathExp = exp.value[1];\n for (const key in values) {\n mathExp = mathExp.replace(key, values[key]);\n }\n if (mathExp.match(/\\d/)) {\n // Strip all invalid math expression characters\n mathExp = mathExp.replace(/[^0-9.+*/-]/g, '');\n const numberVal = mathEval(mathExp);\n label = label.replace(exp.value[0], roundToPlaces(numberVal, 0.01).toString(10));\n }\n else {\n label = label.replace(exp.value[0], mathExp);\n }\n exp = array.next();\n }\n return label;\n }\n function getMultiLineStats(label, ctx) {\n // 402 is a florin and 96 is a backtick, generally the tallest and highest characters.\n const fullStringTextSize = ctx.measureText(label + String.fromCharCode(402, 71, 95, 96, 103));\n const substrings = label.split('\\\\n').map(label => label.trim());\n const lineWidths = [];\n let maximumWidth = 0;\n let maximumHeight = 0;\n let maximumDescent = 0;\n substrings.forEach(string => {\n if (string.length > maximumWidth) {\n maximumWidth = string.length;\n }\n const textSize = ctx.measureText(string);\n if (textSize.actualBoundingBoxLeft !== undefined && textSize.actualBoundingBoxRight !== undefined) {\n const textWidth = Math.abs(textSize.actualBoundingBoxLeft) + Math.abs(textSize.actualBoundingBoxRight);\n if (textWidth > maximumWidth) {\n maximumWidth = textWidth;\n }\n lineWidths.push(textWidth);\n }\n else {\n if (textSize.width > maximumWidth) {\n maximumWidth = textSize.width;\n }\n lineWidths.push(textSize.width);\n }\n });\n // The render puppetteer browser does not have fontBoundingBoxAscent or Descent.\n // That would be a better way to measure text for consistency. When upgrading puppeteer see if we can use fontBoundingBoxAscent\n if (fullStringTextSize.actualBoundingBoxAscent !== undefined &&\n fullStringTextSize.actualBoundingBoxDescent !== undefined) {\n maximumHeight =\n Math.abs(fullStringTextSize.actualBoundingBoxAscent) +\n Math.abs(fullStringTextSize.actualBoundingBoxDescent);\n maximumDescent = fullStringTextSize.actualBoundingBoxDescent;\n }\n if (maximumHeight === 0) {\n maximumHeight = TEXT_RESOLUTION;\n }\n const result = {\n labelArray: substrings,\n lineWidths,\n maximumHeight,\n maximumWidth,\n maximumDescent,\n };\n return result;\n }\n let loopCount = 0;\n function mathEval(exp) {\n loopCount++;\n if (loopCount > 1000) {\n console.warn('escaped infinite loop in math evaluator');\n return NaN;\n }\n if (!exp.match(/\\D/)) {\n return parseFloat(exp);\n }\n let result;\n if (exp.match(/\\+/)) {\n const parts = exp.split('+').reverse();\n result = mathEval(parts.pop());\n while (parts.length > 0) {\n result += mathEval(parts.pop());\n }\n }\n else if (exp.match(/-/)) {\n const parts = exp.split('-').reverse();\n result = mathEval(parts.pop());\n while (parts.length > 0) {\n result -= mathEval(parts.pop());\n }\n }\n else if (exp.match(/\\*/)) {\n const parts = exp.split('*').reverse();\n result = mathEval(parts.pop());\n while (parts.length > 0) {\n result *= mathEval(parts.pop());\n }\n }\n else if (exp.match(/\\//)) {\n const parts = exp.split('/').reverse();\n result = mathEval(parts.pop());\n while (parts.length > 0) {\n result /= mathEval(parts.pop());\n }\n }\n else {\n result = parseFloat(exp);\n }\n return result;\n }\n\n /**\n * Move line position calculation to private function so it can be called from bbSubscription\n * Move text font family creation stuff to common function and call it from here with midpoint of line\n * Store the line mesh in annotationStore, just recreate it from the private function when something changes\n */\n class DimensionRenderer extends Renderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene);\n this.viewer = viewer;\n this.scene = scene;\n this.rendererManager = rendererManager;\n this.modelToken = Token.DimensionNode;\n this.watchPosition = new Map();\n this.dimensionStore = new Map();\n this.billboards = new Map();\n this.utilityLayer = viewer.utilityLayer;\n scene.registerBeforeRender(() => {\n if (scene.activeCamera && this.dimensionStore.size > 0) {\n this.billboards.forEach(meshInfo => {\n const camera = scene.activeCamera;\n meshInfo.rootMesh.lookAt(getCameraPositionWithOffset(camera), 0, Math.PI / 2);\n });\n }\n });\n }\n update3dInternal(node) {\n var _a, _b, _c;\n let dimensionInfo = this.dimensionStore.get(node._dynamicId);\n if (!dimensionInfo) {\n dimensionInfo = {\n positionNeedsUpdate: false,\n textNeedsUpdate: false,\n lineNeedsUpdate: false,\n canCreate: false,\n };\n this.dimensionStore.set(node._dynamicId, dimensionInfo);\n }\n const rootMesh = (_a = dimensionInfo.meshInfo) === null || _a === void 0 ? void 0 : _a.rootMesh;\n if (rootMesh && node.scaleWithCamera) {\n if (!node.scaleWithCamera) {\n this.viewer.camera.clearMaintainedNodeScreenSize(rootMesh);\n }\n else {\n this.viewer.camera.maintainNodeScreenSize(rootMesh, (dist, mode) => {\n if (dimensionInfo && dimensionInfo.meshInfo && node.lineStyle === exports.eAnnotationLineStyle.dashed) {\n this.updateLineFromCamera(node, dimensionInfo.meshInfo, scene, dist);\n }\n });\n }\n }\n if (dimensionInfo.meshInfo && node.changes.has('keepOnTop')) {\n this.delete3d(node, true);\n dimensionInfo.meshInfo = undefined;\n dimensionInfo.positionNeedsUpdate = true;\n dimensionInfo.textNeedsUpdate = true;\n dimensionInfo.lineNeedsUpdate = true;\n }\n const scene = node.keepOnTop ? this.utilityLayer.utilityLayerScene : this.scene;\n if (!dimensionInfo.meshInfo && node.enabled && node.targetId) {\n dimensionInfo.meshInfo = {\n ...createAnnotationTextModels(node, scene, this.viewer.options.editorMode),\n line: {\n points: [],\n colors: [],\n updatable: true,\n },\n lineCap: {\n lines: [],\n colors: [],\n updatable: true,\n },\n distance: 0,\n };\n // Put the dimensions on the parent scene so the scene visibility affects the node\n if (node._parentScene) {\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\n dimensionInfo.meshInfo.rootMesh.setParent(parentSceneMesh);\n }\n this.set3d(node, dimensionInfo.meshInfo.rootMesh);\n }\n const meshInfo = dimensionInfo.meshInfo;\n // Set position of annotation\n if (node.changes.hasAny('enabled', 'targetId', 'target2Id', 'offset', 'billboard', 'labelOffset', 'axis', 'dimensionGap')) {\n dimensionInfo.positionNeedsUpdate = true;\n }\n if (node.changes.hasAny('color', 'lineStyle', 'lineCapStyle')) {\n dimensionInfo.lineNeedsUpdate = true;\n }\n if (node.changes.hasAny('fontFamily', 'fontSize', 'label', 'color', 'targetId', 'target2Id', 'dimensionUnitPrecision')) {\n dimensionInfo.textNeedsUpdate = true;\n }\n if (meshInfo) {\n if (node.changes.hasAny('enabled', 'billboard', 'keepOnTop')) {\n if (node.enabled && node.billboard) {\n this.billboards.set(node._dynamicId, meshInfo);\n }\n else {\n this.billboards.delete(node._dynamicId);\n }\n }\n if (node.enabled) {\n if (dimensionInfo.positionNeedsUpdate || dimensionInfo.lineNeedsUpdate) {\n dimensionInfo.canCreate = this.updateDimensionControlPoints(node, dimensionInfo);\n // If the line is not getting rebuilt, then just update the line position\n if (dimensionInfo.canCreate && !dimensionInfo.lineNeedsUpdate) {\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\n meshInfo.lineCap.instance = MeshBuilder.CreateLineSystem(`${node._dynamicId}_lineCap`, meshInfo.lineCap, scene);\n }\n dimensionInfo.positionNeedsUpdate = false;\n }\n if (dimensionInfo.canCreate) {\n if (dimensionInfo.lineNeedsUpdate) {\n if (meshInfo.line.instance) {\n meshInfo.line.instance.dispose();\n delete meshInfo.line.instance;\n }\n if (meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance.dispose();\n delete meshInfo.lineCap.instance;\n }\n this.updateDimensionLineColor(node, meshInfo.line, meshInfo.lineCap);\n meshInfo.line.instance = drawLine(node, meshInfo.line, meshInfo.distance, scene);\n if (node.lineCapStyle !== exports.eDimensionLineCapStyle.none) {\n const lineCapsMesh = MeshBuilder.CreateLineSystem(`${node._dynamicId}_lineCap`, meshInfo.lineCap, scene);\n if (!meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance = lineCapsMesh;\n }\n }\n // Put the lines on the parent scene so they get it's visibility properties\n if (node._parentScene) {\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\n if (meshInfo.line.instance) {\n meshInfo.line.instance.parent = parentSceneMesh;\n }\n if (meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance.parent = parentSceneMesh;\n }\n }\n dimensionInfo.lineNeedsUpdate = false;\n }\n if (dimensionInfo.textNeedsUpdate) {\n let distanceDefaultVal;\n if (node._parentScene &&\n node._parentScene.dimensionUnitScalar &&\n node.dimensionUnitPrecision !== undefined) {\n let distance = node._parentScene.dimensionUnitScalar * meshInfo.distance;\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\n distance =\n Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\n distanceDefaultVal = distance + (node._parentScene.dimensionUnitSymbol || '');\n }\n else {\n let distance = meshInfo.distance;\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\n distance =\n Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\n distanceDefaultVal = distance.toString(10);\n }\n updateAnnotationText(node, meshInfo.textMesh, meshInfo.textMaterial, this.scene.getEngine().webGLVersion < 2, distanceDefaultVal, { v: meshInfo.distance });\n dimensionInfo.textNeedsUpdate = false;\n }\n }\n }\n if (meshInfo.rootMesh.isEnabled() !== node.enabled) {\n meshInfo.rootMesh.setEnabled(node.enabled);\n (_b = meshInfo.line.instance) === null || _b === void 0 ? void 0 : _b.setEnabled(node.enabled);\n (_c = meshInfo.lineCap.instance) === null || _c === void 0 ? void 0 : _c.setEnabled(node.enabled);\n }\n }\n }\n delete3d(node, keepInStore = false) {\n const dimensionModels = this.dimensionStore.get(node._dynamicId);\n if (dimensionModels === null || dimensionModels === void 0 ? void 0 : dimensionModels.meshInfo) {\n this.deleteLine(dimensionModels.meshInfo);\n }\n if (!keepInStore) {\n this.dimensionStore.delete(node._dynamicId);\n this.billboards.delete(node._dynamicId);\n }\n super.delete3d(node);\n }\n dispose() {\n this.billboards.clear();\n this.dimensionStore.clear();\n super.dispose();\n }\n deleteLine(dimensionModels) {\n if (dimensionModels.line.instance) {\n dimensionModels.line.instance.dispose();\n delete dimensionModels.line.instance;\n }\n if (dimensionModels.lineCap.instance) {\n dimensionModels.lineCap.instance.dispose();\n delete dimensionModels.lineCap.instance;\n }\n }\n updateLine(dimensionInfo, node, meshInfo, scene) {\n dimensionInfo.canCreate = this.updateDimensionControlPoints(node, dimensionInfo);\n // If the line is not getting rebuilt, then just update the line position\n if (dimensionInfo.canCreate && !dimensionInfo.lineNeedsUpdate) {\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\n meshInfo.lineCap.instance = MeshBuilder.CreateLineSystem(`${node._dynamicId}_lineCap`, meshInfo.lineCap, scene);\n }\n dimensionInfo.positionNeedsUpdate = false;\n if (dimensionInfo.canCreate) {\n if (dimensionInfo.lineNeedsUpdate) {\n if (meshInfo.line.instance) {\n meshInfo.line.instance.dispose();\n delete meshInfo.line.instance;\n }\n if (meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance.dispose();\n delete meshInfo.lineCap.instance;\n }\n this.updateDimensionLineColor(node, meshInfo.line, meshInfo.lineCap);\n meshInfo.line.instance = drawLine(node, meshInfo.line, meshInfo.distance, scene);\n if (node.lineCapStyle !== exports.eDimensionLineCapStyle.none) {\n const lineCapsMesh = MeshBuilder.CreateLineSystem(`${node._dynamicId}_lineCap`, meshInfo.lineCap, scene);\n if (!meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance = lineCapsMesh;\n }\n }\n // Put the lines on the parent scene so they get it's visibility properties\n if (node._parentScene) {\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\n if (meshInfo.line.instance) {\n meshInfo.line.instance.parent = parentSceneMesh;\n }\n if (meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance.parent = parentSceneMesh;\n }\n }\n dimensionInfo.lineNeedsUpdate = false;\n }\n if (dimensionInfo.textNeedsUpdate) {\n let distanceDefaultVal;\n if (node._parentScene &&\n node._parentScene.dimensionUnitScalar &&\n node.dimensionUnitPrecision !== undefined) {\n let distance = node._parentScene.dimensionUnitScalar * meshInfo.distance;\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\n distance = Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\n distanceDefaultVal = distance + (node._parentScene.dimensionUnitSymbol || '');\n }\n else {\n let distance = meshInfo.distance;\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\n distance = Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\n distanceDefaultVal = distance.toString(10);\n }\n updateAnnotationText(node, meshInfo.textMesh, meshInfo.textMaterial, this.scene.getEngine().webGLVersion < 2, distanceDefaultVal, { v: meshInfo.distance });\n dimensionInfo.textNeedsUpdate = false;\n }\n }\n }\n updateLineFromCamera(node, meshInfo, scene, distance) {\n if (meshInfo.line.instance) {\n meshInfo.line.instance.dispose();\n delete meshInfo.line.instance;\n }\n this.updateDimensionLineColor(node, meshInfo.line, meshInfo.lineCap);\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene, distance); //CreateDashedLines('lines', meshInfo.line);\n if (node._parentScene) {\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\n if (meshInfo.line.instance) {\n meshInfo.line.instance.parent = parentSceneMesh;\n }\n if (meshInfo.lineCap.instance) {\n meshInfo.lineCap.instance.parent = parentSceneMesh;\n }\n }\n }\n updateDimensionControlPoints(node, dimensionInfo) {\n if (!dimensionInfo.meshInfo) {\n return false;\n }\n const dimensionModel = dimensionInfo.meshInfo;\n const lineOptions = dimensionModel.line;\n const annotationMesh = dimensionModel.rootMesh;\n let target1;\n let target2;\n if (node.targetId && node.target2Id && node._manager) {\n const manager = node._manager;\n target1 = manager.getById(node.targetId);\n target2 = manager.getById(node.target2Id);\n }\n if (dimensionInfo.boundingInfo &&\n (dimensionInfo.boundingInfo.targetNode._dynamicId !== (target1 === null || target1 === void 0 ? void 0 : target1._dynamicId) ||\n dimensionInfo.boundingInfo.targetNode2._dynamicId !== (target2 === null || target2 === void 0 ? void 0 : target2._dynamicId))) {\n dimensionInfo.boundingInfo.subscription.unsubscribe();\n dimensionInfo.boundingInfo = undefined;\n }\n if (target1 && target2) {\n let position1;\n let position2;\n let direction;\n let angleAdjustment = 0;\n // Only supporting connectors for now, but could support direct mesh targets in the future\n if (target1 instanceof exports.Connector && target2 instanceof exports.Connector) {\n position1 = getPositionFromConnnector(target1, this.rendererManager, node._parentScene);\n position2 = getPositionFromConnnector(target2, this.rendererManager, node._parentScene);\n direction = target1.direction.toVec3().normalize();\n angleAdjustment = target1.angle;\n if (target1._parent && target2._parent) {\n dimensionInfo.boundingInfo = {\n targetNode: target1,\n targetNode2: target2,\n subscription: merge(this.viewer.bbCache.watchForChanges(target1._parent), this.viewer.bbCache.watchForChanges(target2._parent)).subscribe(() => {\n node.setPropertyIsModified('targetId', true);\n node.setPropertyIsModified('target2Id', true);\n }),\n };\n }\n }\n if (position1 && position2 && direction) {\n /** Calculate the dimension line */\n const offset = node.offset.toVec3();\n const startConnector = calculateTransform(position1, direction, angleAdjustment, offset);\n const endConnector = calculateTransform(position2, direction, angleAdjustment, offset);\n const dimensionLine = endConnector.position.subtract(startConnector.position);\n const startPostion = startConnector.position;\n // Depending on the dimension axis, just use the\n let endPosition;\n if (node.axis === exports.eDimensionAxis.free) {\n endPosition = endConnector.position;\n }\n else {\n if (node.axis === exports.eDimensionAxis.x) {\n endPosition = startPostion.add(dimensionLine.multiply(new Vector3(1, 0, 0)));\n }\n else if (node.axis === exports.eDimensionAxis.y) {\n endPosition = startPostion.add(dimensionLine.multiply(new Vector3(0, 1, 0)));\n }\n else {\n endPosition = startPostion.add(dimensionLine.multiply(new Vector3(0, 0, 1)));\n }\n }\n const rectifiedDimensionLine = endPosition.subtract(startPostion);\n const lineDirectionCross = Vector3.Cross(rectifiedDimensionLine, direction).normalize();\n lineOptions.points = [startPostion, endPosition];\n dimensionModel.distance = rectifiedDimensionLine.length();\n annotationMesh.position = startPostion.add(endPosition).scaleInPlace(0.5);\n annotationMesh.position.addInPlace(transformVectorWithQuat(node.labelOffset.toVec3(), startConnector.rotation));\n dimensionModel.textContainer.rotationQuaternion = startConnector.textRotation;\n if (!node.billboard) {\n annotationMesh.rotationQuaternion = rotationToVector(lineDirectionCross);\n }\n /** Calculate the line caps */\n const capSize = direction.scale(node.fontSize / 3);\n const lineToStartConnector = direction.scale(Vector3.Dot(transformVectorWithQuat(offset, startConnector.rotation), direction) *\n (1 - node.dimensionGap));\n const endOffset = node.axis === exports.eDimensionAxis.free\n ? transformVectorWithQuat(offset, startConnector.rotation)\n : endPosition.subtract(position2);\n const lineToEndConnector = direction.scale(Vector3.Dot(endOffset, direction) * (1 - node.dimensionGap));\n dimensionModel.lineCap.lines = [];\n if (node.lineCapStyle !== exports.eDimensionLineCapStyle.none) {\n dimensionModel.lineCap.lines = [\n [startPostion.subtract(lineToStartConnector), startPostion, startPostion.add(capSize)],\n [endPosition.subtract(lineToEndConnector), endPosition, endPosition.add(capSize)],\n ];\n }\n if (node.lineCapStyle === exports.eDimensionLineCapStyle.arrow) {\n const capArrowOffset = rectifiedDimensionLine.normalizeToNew().scaleInPlace(capSize.length());\n dimensionModel.lineCap.lines.push([\n startPostion.subtract(capSize).addInPlace(capArrowOffset),\n startPostion,\n startPostion.add(capSize).addInPlace(capArrowOffset),\n ], [\n endPosition.subtract(capSize).subtractInPlace(capArrowOffset),\n endPosition,\n endPosition.add(capSize).subtractInPlace(capArrowOffset),\n ]);\n }\n return true;\n }\n }\n return false;\n }\n updateDimensionLineColor(node, lineOptions, lineCapOptions) {\n const color = node.color.toColor4();\n lineOptions.colors = [];\n for (let i = 0; i < lineOptions.points.length; i++) {\n lineOptions.colors.push(color);\n }\n lineCapOptions.colors = [];\n for (let i = 0; i < 4; i++) {\n const lineColor = [];\n lineCapOptions.colors.push(lineColor);\n for (let j = 0; j < 3; j++) {\n lineColor.push(color);\n }\n }\n }\n }\n function getDimensionLinePoints(node, rendererManager) {\n if (node.targetId && node.target2Id && node._manager) {\n const manager = node._manager;\n const target1 = manager.getById(node.targetId);\n const target2 = manager.getById(node.target2Id);\n let position1;\n let position2;\n let direction;\n if (target1 instanceof exports.Connector && target2 instanceof exports.Connector) {\n position1 = getPositionFromConnnector(target1, rendererManager, node._parentScene);\n position2 = getPositionFromConnnector(target2, rendererManager, node._parentScene);\n direction = target1.direction.toVec3();\n }\n if (position1 && position2 && direction) {\n const lineStart = calculateTransform(position1, direction, 0, node.offset.toVec3());\n const lineEnd = calculateTransform(position2, direction, 0, node.offset.toVec3());\n return [lineStart.position, lineEnd.position];\n }\n }\n return undefined;\n }\n\n const CONNECTOR_DIAM = 0.1;\n class ConnectorRenderer extends Renderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene);\n this.rendererManager = rendererManager;\n this.layers = new Map();\n this.subscriptionMap = new Map();\n this.controlPointScaleRatio = 0.24;\n this.modelToken = Token.Connector;\n this.layers.set('real', {\n template: null,\n map: this.babylonMap,\n scene,\n withArrows: !!viewer.options.editorMode,\n visibility: 1.0,\n pickable: !!viewer.options.editorMode,\n parts: new Map(),\n });\n this.layers.set('utility', {\n template: null,\n map: new Map(),\n scene: viewer.utilityLayer.utilityLayerScene,\n withArrows: !!viewer.options.editorMode,\n visibility: 0.3,\n pickable: false,\n parts: new Map(),\n });\n }\n handlesNode(node) {\n return instanceOf(node, Token.Connector);\n }\n update3dInternal(c, forceScreenScale = false) {\n /**\n * enabled, but not visible\n * enabled and visible\n * not enabled\n */\n const mesh = this.getMesh(c, this.layers.get('real'));\n const realLayer = this.layers.get('real');\n const utilityLayer = this.layers.get('utility');\n const utilityMesh = this.getMesh(c, this.layers.get('utility'));\n const realParts = realLayer.parts.get(c._dynamicId);\n const utilityParts = utilityLayer.parts.get(c._dynamicId);\n if (this.viewer.options.editorMode) {\n this.viewer.camera.maintainNodeScreenSize(mesh, dist => {\n var _a, _b, _c, _d, _e, _f;\n const scaledSize = dist * this.controlPointScaleRatio;\n realParts === null || realParts === void 0 ? void 0 : realParts.mesh.scaling.set(scaledSize, scaledSize, scaledSize);\n (_a = realParts === null || realParts === void 0 ? void 0 : realParts.handleContainer) === null || _a === void 0 ? void 0 : _a.scaling.set(1 / scaledSize, 1 / scaledSize, 1 / scaledSize);\n (_b = realParts === null || realParts === void 0 ? void 0 : realParts.directionHandle1) === null || _b === void 0 ? void 0 : _b.scaling.set(scaledSize, scaledSize, scaledSize);\n (_c = realParts === null || realParts === void 0 ? void 0 : realParts.directionHandle2) === null || _c === void 0 ? void 0 : _c.scaling.set(scaledSize, scaledSize, scaledSize);\n utilityParts === null || utilityParts === void 0 ? void 0 : utilityParts.mesh.scaling.set(scaledSize, scaledSize, scaledSize);\n (_d = utilityParts === null || utilityParts === void 0 ? void 0 : utilityParts.handleContainer) === null || _d === void 0 ? void 0 : _d.scaling.set(1 / scaledSize, 1 / scaledSize, 1 / scaledSize);\n (_e = utilityParts === null || utilityParts === void 0 ? void 0 : utilityParts.directionHandle1) === null || _e === void 0 ? void 0 : _e.scaling.set(scaledSize, scaledSize, scaledSize);\n (_f = utilityParts === null || utilityParts === void 0 ? void 0 : utilityParts.directionHandle2) === null || _f === void 0 ? void 0 : _f.scaling.set(scaledSize, scaledSize, scaledSize);\n });\n }\n const changes = this.getChanges(c);\n if (changes.has('_isPickable')) {\n mesh.isPickable = c._isPickable;\n }\n if (changes.has('positionZeroToOne') || changes.has('_sketchControlPoints')) {\n if (c.positionMode === exports.eConnectorPositionMode.moveAlongSketch) {\n if (c instanceof exports.Connector) {\n //this.updatePositionMoveAlongSketch(c);\n this.updatePosition(c);\n this.updateDirection(c);\n }\n }\n }\n if (changes.has('position') || changes.has('positionMode')) {\n const bb = c._parent instanceof exports.SpaceNode ? this.viewer.bbCache.get(c._parent) : undefined;\n this.updatePosition(c, bb);\n /**\n * subscribe to bounding box changes of the parent to know that\n * we need to invalidate the position of the connector if applicable\n */\n if (changes.has('positionMode')) {\n if (c.positionMode == exports.eConnectorPositionMode.boundingBox) {\n this.addSubscription(c);\n }\n else {\n this.removeSubscription(c);\n }\n }\n }\n if (changes.hasAny('direction', 'angle')) {\n this.updateDirection(c);\n this.updatePosition(c);\n }\n if (changes.hasAny('enabled', '_visible')) {\n if (c.enabled && c._visible) {\n mesh.setEnabled(true);\n utilityMesh.setEnabled(true);\n }\n else {\n mesh.setEnabled(false);\n utilityMesh.setEnabled(false);\n }\n }\n if (changes.has('_selected')) {\n if (c._selected) {\n mesh.material = this.getSelectedMaterial(this.layers.get('real').withArrows);\n }\n else {\n mesh.material = this.getConnectorMaterial(this.layers.get('real').withArrows);\n }\n utilityMesh.material = mesh.material;\n }\n return { mesh, utilityMesh };\n }\n addSubscription(c) {\n if (c._parent instanceof exports.SpaceNode) {\n const mesh = c._parent;\n if (!this.subscriptionMap.has(c)) {\n this.subscriptionMap.set(c, this.viewer.bbCache.watchForChanges(mesh).subscribe(bbInfo => {\n c.setPropertyIsModified('position', true); // Trigger changes on mates and everything using that connector\n this.updatePosition(c, bbInfo);\n this.updateScale(c);\n }));\n }\n }\n }\n removeSubscription(c) {\n const s = this.subscriptionMap.get(c);\n if (s) {\n s.unsubscribe();\n this.subscriptionMap.delete(c);\n }\n }\n updatePosition(c, bb) {\n const mesh = this.getMesh(c, this.layers.get('real'));\n const utilityMesh = this.getMesh(c, this.layers.get('utility'));\n if (c.positionMode == exports.eConnectorPositionMode.moveAlongSketch) {\n if (c instanceof exports.Connector) {\n const newPosition = this.updatePositionMoveAlongSketch(c);\n if (newPosition) {\n mesh.position = utilityMesh.position = newPosition;\n }\n }\n }\n else if (c.positionMode == exports.eConnectorPositionMode.absolute) {\n mesh.position = utilityMesh.position = c.position.toVec3();\n }\n else if (c.positionMode == exports.eConnectorPositionMode.boundingBox) {\n if (!bb) {\n bb = c._parent instanceof exports.SpaceNode ? this.viewer.bbCache.get(c._parent) : undefined;\n }\n if (bb) {\n mesh.position = BoundingBoxRelativeHelper.convertRelativeToAbsolute(c, bb);\n }\n else {\n mesh.position = new Vector3(c.position.x, c.position.y, c.position.z);\n }\n utilityMesh.position = mesh.position;\n }\n if (isTrackedClass(c)) {\n this.rendererManager.referenceProcessor.triggerChangesOnReferencers(c);\n }\n }\n updateDirection(c) {\n const mesh = this.getMesh(c, this.layers.get('real'));\n const utilityMesh = this.getMesh(c, this.layers.get('utility'));\n if (c.positionMode === exports.eConnectorPositionMode.moveAlongSketch) {\n if (c instanceof exports.Connector) {\n let newDirection = this.updateDirectionMoveAlongSketch(c);\n if (newDirection) {\n newDirection = newDirection.normalize();\n if (c._parent instanceof exports.SketchNode) {\n const normal = c._parent.normal;\n const normalVector = new Vector3(1, 0, 0);\n if (normal === exports.eAxis.y) {\n normalVector.set(0, 1, 0);\n }\n else if (normal === exports.eAxis.z) {\n normalVector.set(0, 0, 1);\n }\n if (mesh.parent instanceof TransformNode) {\n const connectorDirection = newDirection;\n const angleRot = Quaternion.RotationAxis(connectorDirection, toRadians(c.angle));\n const angleRotMatrix = new Matrix();\n angleRot.toRotationMatrix(angleRotMatrix);\n const parentDirection = Vector3.TransformCoordinates(normalVector, angleRotMatrix);\n const crossProduct = Vector3.Cross(connectorDirection, parentDirection);\n // prettier-ignore\n const matrix = Matrix.FromArray([connectorDirection.x, connectorDirection.y, connectorDirection.z, 0,\n parentDirection.x, parentDirection.y, parentDirection.z, 0,\n crossProduct.x, crossProduct.y, crossProduct.z, 0,\n 0, 0, 0, 1,\n ]);\n const newQuaternion = Quaternion.FromRotationMatrix(matrix);\n mesh.rotationQuaternion = utilityMesh.rotationQuaternion = newQuaternion;\n }\n }\n }\n }\n }\n else {\n /**\n * treat the positive x axis as the direction vector,\n * and the angle around that axis defined by the y axis.\n *\n * See Dragger.connect for a more in depth explanation\n */\n const deltaBtwXaxisAndDirection = getRotationBtwVectors(Axis.X, c.direction.toVec3().normalize());\n const angleRot = Quaternion.RotationAxis(Axis.X, toRadians(c.angle));\n mesh.rotationQuaternion = utilityMesh.rotationQuaternion = deltaBtwXaxisAndDirection.multiply(angleRot);\n }\n this.updateScale(c);\n }\n /**\n * connector meshes are children of their parent mesh, meaning they will scale\n * with any of their ancestor meshes or groups.\n * To counteract this we inverse their world scale.\n * WARNING! this technique does not work well when an ancestor has a non-uniform scale\n * @param c\n */\n updateScale(c) {\n if (this.layers.get('real').map.get(c._dynamicId)) {\n //this could get called at any time, make sure the mesh already exists\n const mesh = this.getMesh(c, this.layers.get('real'));\n const utilityMesh = this.getMesh(c, this.layers.get('utility'));\n mesh.scaling = Vector3.One();\n mesh.computeWorldMatrix(true);\n if (mesh.parent instanceof TransformNode) {\n const worldScale = mesh.parent.absoluteScaling;\n const numerator = (this.viewer.sceneNode.connectorSize || CONNECTOR_DIAM) / CONNECTOR_DIAM;\n const transformMatrix = Matrix.Scaling(numerator / worldScale.x, numerator / worldScale.y, numerator / worldScale.z);\n mesh.setPreTransformMatrix(transformMatrix);\n utilityMesh.setPreTransformMatrix(transformMatrix);\n if (isTrackedClass(c)) {\n this.rendererManager.referenceProcessor.triggerChangesOnReferencers(c);\n }\n }\n }\n }\n updatePositionMoveAlongSketch(connector) {\n const node = connector._parent;\n const result = new Vector3(0, 0, 0);\n if (node instanceof exports.SketchNode) {\n const sketchLength = node.getSketchLength();\n const posZeroToOne = connector.positionZeroToOne;\n let trackedLength = 0;\n let targetNotFound = true;\n node.paths.forEach(path => {\n let lastPosition = null;\n let lastLength = 0;\n path._points.forEach(point => {\n if (!lastPosition) {\n lastPosition = point;\n }\n else {\n const currentPos = point;\n const distance = Math.sqrt(Math.pow(lastPosition.x - currentPos.x, 2) +\n Math.pow(lastPosition.y - currentPos.y, 2) +\n Math.pow(lastPosition.z - currentPos.z, 2));\n lastLength = trackedLength;\n trackedLength += distance;\n const distanceBetweenPoints = trackedLength - lastLength;\n const distanceFromP1toTarget = posZeroToOne * sketchLength - lastLength;\n const percentageBetween2Points = distanceFromP1toTarget / distanceBetweenPoints;\n const vectorBetween2Points = new exports.KbVector(currentPos.x - lastPosition.x, currentPos.y - lastPosition.y, currentPos.z - lastPosition.z);\n if (trackedLength > posZeroToOne * sketchLength && targetNotFound) {\n const calculatedPosition = vectorBetween2Points\n .scale(percentageBetween2Points)\n .add(lastPosition);\n result.set(calculatedPosition.x, calculatedPosition.y, calculatedPosition.z);\n targetNotFound = false;\n }\n lastPosition = currentPos;\n }\n });\n if (posZeroToOne === 1) {\n const path = node.paths[node.paths.length - 1];\n const controlPoint = path._points[path._points.length - 1];\n result.set(controlPoint.x, controlPoint.y, controlPoint.z);\n }\n });\n }\n return result;\n }\n updateDirectionMoveAlongSketch(connector) {\n const node = connector._parent;\n const result = new Vector3(0, 0, 0);\n if (node instanceof exports.SketchNode) {\n const sketchLength = node.getSketchLength();\n const posZeroToOne = connector.positionZeroToOne;\n let trackedLength = 0;\n let targetNotFound = true;\n let lastPathVector = null;\n let nextPathVector = null;\n node.paths.forEach(path => {\n let lastPosition = null;\n let lastLength = 0;\n path._points.forEach(point => {\n if (!lastPosition) {\n lastPosition = point;\n }\n else {\n const currentPos = point;\n if (lastPosition) {\n const index = path._points.indexOf(lastPosition) + 1;\n const index2 = index + 1;\n if (index !== path._points.length) {\n const nextPosition = path._points[index];\n if (index2 !== path._points.length) {\n const nextNextPosition = path._points[index2];\n nextPathVector = new exports.KbVector(nextNextPosition.x - nextPosition.x, nextNextPosition.y - nextPosition.y, nextNextPosition.z - nextPosition.z).normalize();\n }\n }\n }\n const distance = Math.sqrt(Math.pow(lastPosition.x - currentPos.x, 2) +\n Math.pow(lastPosition.y - currentPos.y, 2) +\n Math.pow(lastPosition.z - currentPos.z, 2));\n lastLength = trackedLength;\n trackedLength += distance;\n const distanceBetweenPoints = trackedLength - lastLength;\n const distanceFromP1toTarget = posZeroToOne * sketchLength - lastLength;\n const percentageBetween2Points = distanceFromP1toTarget / distanceBetweenPoints;\n const vectorBetween2Points = new exports.KbVector(currentPos.x - lastPosition.x, currentPos.y - lastPosition.y, currentPos.z - lastPosition.z);\n if (trackedLength > posZeroToOne * sketchLength && targetNotFound) {\n let calculatedDirection = null;\n if (!connector.interpolateDirection) {\n calculatedDirection = vectorBetween2Points.normalize();\n }\n else {\n if (!lastPathVector) {\n if (nextPathVector) {\n calculatedDirection = vectorBetween2Points\n .normalize()\n .scale(1 - percentageBetween2Points)\n .add(nextPathVector\n .normalize()\n .add(vectorBetween2Points.normalize())\n .normalize()\n .scale(percentageBetween2Points))\n .normalize();\n }\n else {\n calculatedDirection = vectorBetween2Points.normalize();\n }\n }\n else if (!nextPathVector) {\n calculatedDirection = lastPathVector\n .scale(1 - percentageBetween2Points)\n .add(vectorBetween2Points.scale(1 + percentageBetween2Points))\n .scale(1 / 2)\n .normalize();\n }\n else {\n if (percentageBetween2Points <= 0.5) {\n calculatedDirection = lastPathVector\n .normalize()\n .add(vectorBetween2Points.normalize())\n .normalize()\n .scale(1 - percentageBetween2Points * 2)\n .add(vectorBetween2Points.scale(percentageBetween2Points * 2))\n .normalize();\n }\n else {\n calculatedDirection = vectorBetween2Points\n .normalize()\n .scale(1 - (percentageBetween2Points - 0.5) * 2)\n .add(nextPathVector\n .normalize()\n .add(vectorBetween2Points.normalize())\n .normalize()\n .scale((percentageBetween2Points - 0.5) * 2))\n .normalize();\n }\n }\n }\n targetNotFound = false;\n result.set(calculatedDirection.x, calculatedDirection.y, calculatedDirection.z);\n }\n lastPathVector = vectorBetween2Points;\n lastPosition = currentPos;\n }\n });\n });\n if (posZeroToOne === 1) {\n if (posZeroToOne === 1) {\n const path = node.paths[node.paths.length - 1];\n const currentPos = path._points[path._points.length - 1];\n const lastPosition = path._points[path._points.length - 2];\n const vectorBetween2Points = new exports.KbVector(currentPos.x - lastPosition.x, currentPos.y - lastPosition.y, currentPos.z - lastPosition.z).normalize();\n result.set(vectorBetween2Points.x, vectorBetween2Points.y, vectorBetween2Points.z);\n }\n }\n }\n return result;\n }\n getMesh(c, layer) {\n let mesh = layer.map.get(c._dynamicId);\n if (!mesh) {\n if (!layer.template) {\n layer.template = this.createMeshTemplate(layer);\n }\n mesh = layer.template.clone(c._dynamicId); // layer.template.createInstance(c._dynamicId);\n mesh.id = c._dynamicId;\n const parentNode = c._parent;\n if (parentNode && parentNode instanceof exports.SpaceNode) {\n const parent3d = this.viewer.getRendererNode(parentNode);\n if (parent3d) {\n mesh.setParent(parent3d);\n }\n else {\n console.warn(`mesh not found for ${parentNode.name}`);\n }\n }\n mesh.isPickable = layer.pickable;\n mesh.position = Vector3.Zero();\n mesh.rotationQuaternion = Quaternion.Identity();\n layer.map.set(c._dynamicId, mesh);\n layer.parts.set(c._dynamicId, {\n mesh,\n });\n }\n return mesh;\n }\n createMeshTemplate(layer) {\n const ball = CreateSphereVertexData({\n segments: 8,\n diameter: CONNECTOR_DIAM,\n });\n if (layer.withArrows) {\n const arrowHead = CreateCylinderVertexData({\n diameterTop: 0,\n height: CONNECTOR_DIAM / 2,\n diameterBottom: CONNECTOR_DIAM / 4,\n tessellation: 6,\n });\n arrowHead.transform(Matrix.Compose(Vector3.One(), Quaternion.FromEulerAngles(Math.PI / 2, 0, 0), new Vector3(0, 0, CONNECTOR_DIAM * 1.75)));\n const arrowShaft = CreateCylinderVertexData({\n diameterTop: CONNECTOR_DIAM / 10,\n height: CONNECTOR_DIAM,\n diameterBottom: CONNECTOR_DIAM / 10,\n tessellation: 6,\n });\n arrowShaft.transform(Matrix.Compose(Vector3.One(), Quaternion.FromEulerAngles(Math.PI / 2, 0, 0), new Vector3(0, 0, CONNECTOR_DIAM)));\n ball.merge(arrowHead).merge(arrowShaft);\n }\n const mesh = new Mesh('', layer.scene);\n ball.applyToMesh(mesh, false); //updateable false\n if (layer.withArrows) {\n //let ballHalf1 = new SubMesh(0, 0, 231, 0, 600, mesh);\n new SubMesh(1, 0, 231, 0, 600, mesh); // ball half 2\n }\n mesh.rotation.y = Math.PI / 2;\n mesh.bakeCurrentTransformIntoVertices();\n mesh.position = Vector3.Zero();\n mesh.material = this.getConnectorMaterial(layer.withArrows);\n mesh.visibility = layer.visibility;\n mesh.setEnabled(false);\n return mesh;\n }\n delete3d(c) {\n const utilityLayer = this.layers.get('utility');\n const utilityMesh = utilityLayer.map.get(c._dynamicId);\n if (utilityMesh) {\n utilityMesh.dispose();\n utilityLayer.map.delete(c._dynamicId);\n }\n this.removeSubscription(c);\n super.delete3d(c);\n }\n getConnectorMaterial(twoTone) {\n if (!this.connectorMaterial) {\n if (twoTone) {\n const m1 = new StandardMaterial('connectorMaterial0', this.scene);\n m1.emissiveColor = exports.KbColor.KbmaxOrange().toColor3();\n m1.disableLighting = true;\n const m2 = new StandardMaterial('connectorMaterial1', this.scene);\n m2.emissiveColor = new Color3(0, 101 / 255, 1); //new Color3(226/255, 101/255, 29/255);// KbColor.KbmaxBlue().toColor3();\n m2.disableLighting = true;\n const m = new MultiMaterial('connectorMaterial', this.scene);\n m.subMaterials.push(m1, m2);\n this.connectorMaterial = m;\n }\n else {\n const m = new StandardMaterial('connectorMaterial', this.scene);\n m.emissiveColor = this.viewer.highlightColor.toColor3();\n m.disableLighting = true;\n this.connectorMaterial = m;\n }\n }\n return this.connectorMaterial;\n }\n getSelectedMaterial(withArrows) {\n if (!this.selectedMaterial) {\n this.selectedMaterial = this.getConnectorMaterial(withArrows);\n if (withArrows) {\n const m1 = new StandardMaterial('connectorSelectedMaterial0', this.scene);\n m1.emissiveColor = new Color3(254 / 255, 233 / 255, 7 / 255);\n m1.disableLighting = true;\n const m2 = new StandardMaterial('connectorSelectedMaterial1', this.scene);\n m2.emissiveColor = new Color3(2 / 255, 251 / 255, 248 / 255);\n m2.disableLighting = true;\n const m = new MultiMaterial('connectorSelectedMaterial', this.scene);\n m.subMaterials.push(m1, m2);\n this.selectedMaterial = m;\n }\n else {\n const m = new StandardMaterial('connectorSelectedMaterial', this.scene);\n m.emissiveColor = this.viewer.options.highlightColor.toColor3();\n m.disableLighting = true;\n this.selectedMaterial = m;\n }\n }\n return this.selectedMaterial;\n }\n dispose() {\n super.dispose();\n for (const [, layer] of this.layers) {\n if (layer.template) {\n layer.template.dispose();\n }\n layer.map.clear();\n }\n if (this.connectorMaterial) {\n this.connectorMaterial.dispose();\n }\n }\n }\n\n class FeatureRenderer extends Renderer {\n constructor() {\n super(...arguments);\n this.vertexDataCache = new Map();\n }\n updateMeshGeometryCache(feature, vertexData, vertexDataChanges) {\n const self = this;\n const newVertexData = {};\n // Grab the properties in the mesh vertex that are needed for the feature\n // Only swap out the properties in the old vertex data with the stored copy if they have NOT been affected by another vertex\n if (feature.affectedBy) {\n const cachedData = this.vertexDataCache.get(feature._dynamicId);\n feature.affectedBy.forEach(affectedBy => {\n var _a, _b, _c, _d, _e, _f;\n if (affectedBy === exports.eMeshChangeTypes.VertexIndices) {\n if (vertexDataChanges.indices === null) {\n newVertexData.indices = null;\n clearVertexDataCache('indices');\n }\n else if (vertexDataChanges.indices) {\n newVertexData.indices = vertexDataChanges.indices.slice();\n updateVertexDataCache('indices', vertexDataChanges.indices);\n }\n else if (cachedData) {\n newVertexData.indices = (_a = cachedData.indices) === null || _a === void 0 ? void 0 : _a.slice();\n }\n else {\n newVertexData.indices = vertexData.indices.slice();\n updateVertexDataCache('indices', vertexData.indices);\n }\n if (vertexDataChanges.paths === null) {\n newVertexData.paths = null;\n clearVertexDataCache('paths');\n }\n else if (vertexDataChanges.paths) {\n newVertexData.paths = vertexDataChanges.paths.slice();\n updateVertexDataCache('paths', vertexDataChanges.paths);\n }\n else if (cachedData) {\n newVertexData.paths = (_b = cachedData.paths) === null || _b === void 0 ? void 0 : _b.slice();\n }\n else {\n if (vertexData.paths) {\n newVertexData.paths = vertexData.paths.slice();\n updateVertexDataCache('paths', vertexData.paths);\n }\n else {\n newVertexData.paths = null;\n }\n }\n if (vertexDataChanges.holes === null) {\n newVertexData.holes = null;\n clearVertexDataCache('holes');\n }\n else if (vertexDataChanges.holes) {\n newVertexData.holes = vertexDataChanges.holes.slice();\n updateVertexDataCache('holes', vertexDataChanges.holes);\n }\n else if (cachedData) {\n newVertexData.holes = (_c = cachedData.holes) === null || _c === void 0 ? void 0 : _c.slice();\n }\n else {\n if (vertexData.holes) {\n newVertexData.holes = vertexData.holes.slice();\n updateVertexDataCache('holes', vertexData.holes);\n }\n else {\n newVertexData.holes = null;\n }\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.VertexPositions) {\n if (vertexDataChanges.positions === null) {\n newVertexData.positions = null;\n clearVertexDataCache('positions');\n }\n else if (vertexDataChanges.positions) {\n newVertexData.positions = vertexDataChanges.positions.slice();\n updateVertexDataCache('positions', vertexDataChanges.positions);\n }\n else if (cachedData) {\n newVertexData.positions = (_d = cachedData.positions) === null || _d === void 0 ? void 0 : _d.slice(); // compiler complains about the slice generic type for some reason\n }\n else {\n if (!vertexData.positions) {\n throw Error('Invalid geometry: positions is null');\n }\n newVertexData.positions = vertexData.positions.slice();\n updateVertexDataCache('positions', vertexData.positions);\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.VertexNormals) {\n if (vertexDataChanges.normals === null) {\n newVertexData.normals = null;\n clearVertexDataCache('normals');\n }\n else if (vertexDataChanges.normals) {\n newVertexData.normals = vertexDataChanges.normals.slice();\n updateVertexDataCache('normals', vertexDataChanges.normals);\n }\n else if (cachedData) {\n newVertexData.normals = (_e = cachedData.normals) === null || _e === void 0 ? void 0 : _e.slice();\n }\n else {\n if (vertexData.normals) {\n newVertexData.normals = vertexData.normals.slice();\n updateVertexDataCache('normals', vertexData.normals);\n }\n else {\n newVertexData.normals = null;\n }\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.VertexUvs) {\n if (vertexDataChanges.uvs === null) {\n newVertexData.uvs = null;\n clearVertexDataCache('uvs');\n }\n else if (vertexDataChanges.uvs) {\n newVertexData.uvs = vertexDataChanges.uvs.slice();\n updateVertexDataCache('uvs', vertexDataChanges.uvs);\n }\n else if (cachedData) {\n newVertexData.uvs = (_f = cachedData.uvs) === null || _f === void 0 ? void 0 : _f.slice();\n }\n else {\n if (vertexData.uvs) {\n newVertexData.uvs = vertexData.uvs.slice();\n updateVertexDataCache('uvs', vertexData.uvs);\n }\n else {\n newVertexData.uvs = null;\n }\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.Submeshes) {\n if (vertexDataChanges.submeshData === null) {\n newVertexData.submeshData = null;\n clearVertexDataCache('submeshData');\n }\n else if (vertexDataChanges.submeshData) {\n newVertexData.submeshData = JSON.parse(JSON.stringify(vertexDataChanges.submeshData));\n updateVertexDataCache('submeshData', JSON.parse(JSON.stringify(vertexDataChanges.submeshData)));\n }\n else if (cachedData) {\n const cachedSubmeshes = cachedData.submeshData;\n newVertexData.submeshData = cachedSubmeshes\n ? JSON.parse(JSON.stringify(cachedSubmeshes))\n : undefined;\n }\n else {\n if (vertexData.submeshData) {\n newVertexData.submeshData = JSON.parse(JSON.stringify(vertexData.submeshData));\n updateVertexDataCache('submeshData', JSON.parse(JSON.stringify(vertexData.submeshData)));\n }\n else {\n newVertexData.submeshData = null;\n }\n }\n }\n });\n }\n function clearVertexDataCache(prop) {\n const vertexDataCache = self.vertexDataCache.get(feature._dynamicId);\n if (vertexDataCache) {\n delete vertexDataCache[prop];\n }\n }\n function updateVertexDataCache(prop, value) {\n if (!value) {\n throw Error('invalid geometry does not have ' + prop);\n }\n let vertexDataCache = self.vertexDataCache.get(feature._dynamicId);\n if (!vertexDataCache) {\n vertexDataCache = {};\n self.vertexDataCache.set(feature._dynamicId, vertexDataCache);\n }\n if (typeof value.slice !== 'function') {\n throw Error('fixme: how do I clone this property?');\n }\n vertexDataCache[prop] = value.slice(); // Need to make sure everything is cloned when inserted into the cache\n }\n return newVertexData;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n return this.updateMeshGeometryCache(feature, vertexData, vertexDataChanges);\n }\n delete3d(node, preserveCache) {\n if (!preserveCache) {\n this.vertexDataCache.delete(node._dynamicId);\n }\n const t3d = this.get3d(node);\n if (t3d) {\n super.delete3d(node);\n }\n else {\n SyncService.nodeDeletionProcessed(node);\n }\n }\n clearCache(features) {\n if (features) {\n features.forEach(feature => {\n this.vertexDataCache.delete(feature._dynamicId);\n });\n }\n else {\n this.vertexDataCache.clear();\n }\n }\n dispose() {\n super.dispose();\n this.clearCache();\n }\n }\n\n class MoveVerticesRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.MoveVerticesFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const parentMesh = feature._parent;\n if (parentMesh && newVertexData.positions && newVertexData.positions.length > 0) {\n const newMeshVertexPositions = newVertexData.positions;\n if (feature.vertexIndices && feature.vertexIndices.length > 0) {\n let pivot;\n let rotationQuaternion;\n let scaleVector;\n if (feature.rotationAngle !== 0 && !feature.rotationAxis.equal({ x: 0, y: 0, z: 0 })) {\n rotationQuaternion = Quaternion.RotationAxis(feature.rotationAxis.toVec3(), (feature.rotationAngle / 180) * Math.PI);\n }\n if (!feature.scale.equal({ x: 1, y: 1, z: 1 })) {\n scaleVector = feature.scale.toVec3();\n }\n // Calculate vertex center if needed\n if (rotationQuaternion || scaleVector) {\n if (feature.center === exports.eFeatureCenter.meshPivotPoint) {\n pivot = parentMesh.pivot.toVec3();\n }\n else {\n // Calculate vertices barycenter\n pivot = Vector3.Zero();\n const currentMeshVertexPositions = newVertexData.positions;\n if (currentMeshVertexPositions) {\n feature.vertexIndices.forEach(idx => {\n pivot.x += currentMeshVertexPositions[idx * 3];\n pivot.y += currentMeshVertexPositions[idx * 3 + 1];\n pivot.z += currentMeshVertexPositions[idx * 3 + 2];\n });\n pivot.scaleInPlace(1 / feature.vertexIndices.length);\n }\n }\n }\n const vertexPosition = new Vector3();\n feature.vertexIndices.forEach(index => {\n newMeshVertexPositions[index * 3] += feature.translation.x;\n newMeshVertexPositions[index * 3 + 1] += feature.translation.y;\n newMeshVertexPositions[index * 3 + 2] += feature.translation.z;\n if (pivot && (rotationQuaternion || scaleVector)) {\n vertexPosition.copyFromFloats(newMeshVertexPositions[index * 3] - pivot.x, newMeshVertexPositions[index * 3 + 1] - pivot.y, newMeshVertexPositions[index * 3 + 2] - pivot.z);\n if (rotationQuaternion) {\n vertexPosition.rotateByQuaternionToRef(rotationQuaternion, vertexPosition);\n }\n if (scaleVector) {\n vertexPosition.multiplyInPlace(scaleVector);\n }\n vertexPosition.addInPlace(pivot);\n newMeshVertexPositions[index * 3] = vertexPosition.x;\n newMeshVertexPositions[index * 3 + 1] = vertexPosition.y;\n newMeshVertexPositions[index * 3 + 2] = vertexPosition.z;\n }\n });\n }\n }\n return newVertexData;\n }\n update3dInternal() { }\n }\n\n class NormalSmoothingRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.NormalSmoothingFeature;\n this.vertexNeighbors = new Map();\n this.planeNormals = new Map();\n this.vectorA = new Vector3();\n this.vectorB = new Vector3();\n this.vectorC = new Vector3();\n this.normalVector = new Vector3();\n this.totalSelectedIndices = 0;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n let vertexGroups = [];\n //if no faces are selected, select all faces to smooth entire mesh.\n if (feature.vertexGroups.length === 0 && newVertexData.indices) {\n for (let i = 0; i < newVertexData.indices.length; i += 6) {\n vertexGroups.push({ startIndex: i, endIndex: i + 6 });\n }\n }\n else {\n vertexGroups = feature.vertexGroups.sort((groupA, groupB) => groupA.startIndex - groupB.startIndex);\n }\n if (newVertexData.indices) {\n const planeNormal = new Vector3();\n let normals;\n let positions;\n let uvs;\n let indices;\n const newPositions = [];\n const newNormals = [];\n const newUvs = [];\n const submeshDataArray = [];\n if (newVertexData.normals) {\n normals = newVertexData.normals;\n }\n else if (vertexData.normals) {\n normals = Array.from(vertexData.normals);\n }\n else {\n normals = [];\n }\n if (newVertexData.positions) {\n positions = newVertexData.positions;\n }\n else if (vertexData.positions) {\n positions = Array.from(vertexData.positions);\n }\n else {\n positions = [];\n }\n if (newVertexData.uvs) {\n uvs = newVertexData.uvs;\n }\n else if (vertexData.uvs) {\n uvs = Array.from(vertexData.uvs);\n }\n else {\n uvs = [];\n }\n if (newVertexData.indices) {\n indices = newVertexData.indices;\n }\n else if (vertexData.indices) {\n indices = Array.from(vertexData.indices);\n }\n else {\n indices = [];\n }\n this.vertexNeighbors.clear();\n this.planeNormals.clear();\n this.totalSelectedIndices = 0;\n vertexGroups.forEach(vertexGroup => {\n this.totalSelectedIndices += vertexGroup.endIndex - vertexGroup.startIndex;\n });\n if (feature.smooth) {\n //looping through the vertex groups and finding all the neighboring faces\n vertexGroups.forEach(vertexGroup => {\n const planeCoordinates = [];\n const planePositions = [];\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\n if (positions && indices) {\n let key = '';\n for (let j = 0; j < 3; j++) {\n const vertexIndex = indices[i];\n const coordinate = positions[vertexIndex * 3 + j];\n planePositions.push(coordinate);\n if (j == 2) {\n planeCoordinates.push([...planePositions]);\n planePositions.clear();\n }\n key += String(coordinate);\n }\n if (planeCoordinates.length == 3) {\n this.calculateNormalToRef(planeCoordinates, planeNormal);\n this.planeNormals.set(Math.floor(i / 3), planeNormal.asArray());\n planeCoordinates.clear();\n }\n let neighbor = this.vertexNeighbors.get(key);\n if (neighbor) {\n neighbor.push(i);\n this.vertexNeighbors.set(key, neighbor);\n }\n else {\n neighbor = [];\n neighbor.push(i);\n this.vertexNeighbors.set(key, neighbor);\n }\n }\n }\n });\n this.vertexNeighbors.forEach(position => {\n const newNormal = this.calculateSmoothedUnitVector(position);\n position.forEach(index => {\n if (normals && indices) {\n for (let i = 0; i < 3; i++) {\n normals[indices[index] * 3 + i] = newNormal[i];\n }\n }\n });\n });\n }\n else {\n //looping through the selected faces to get the face normals\n vertexGroups.forEach(vertexGroup => {\n const planeCoordinates = [];\n const planePositions = [];\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\n if (positions && indices) {\n for (let j = 0; j < 3; j++) {\n const vertexIndex = indices[i];\n const coordinate = positions[vertexIndex * 3 + j];\n planePositions.push(coordinate);\n if (j == 2) {\n planeCoordinates.push([...planePositions]);\n planePositions.clear();\n }\n }\n if (planeCoordinates.length == 3) {\n this.calculateNormalToRef(planeCoordinates, planeNormal);\n const planeNormalArray = this.calculateUnitVector(planeNormal.asArray());\n this.planeNormals.set(i, planeNormalArray);\n this.planeNormals.set(i - 1, planeNormalArray);\n this.planeNormals.set(i - 2, planeNormalArray);\n planeCoordinates.clear();\n }\n }\n }\n });\n //looping through it again to change/add the normals\n let totalVertices = 0;\n if (positions) {\n totalVertices = positions.length / 3;\n }\n const visitedVertices = [];\n vertexGroups.forEach(vertexGroup => {\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\n const vertex = indices[i];\n const planeNormal = this.planeNormals.get(i);\n const currentNormal = [];\n const currentPosition = [];\n const currentUv = [];\n for (let i = 0; i < 3; i++) {\n currentNormal.push(normals[vertex * 3 + i]);\n currentPosition.push(positions[vertex * 3 + i]);\n }\n for (let i = 0; i < 2; i++) {\n currentUv.push(uvs[vertex * 2 + i]);\n }\n //vertex is already visited, therefor we add a new one.\n //else: replace the existing vertex\n if (visitedVertices[vertex]) {\n for (let i = 0; i < 3; i++) {\n if (planeNormal) {\n newNormals.push(planeNormal[i]);\n newPositions.push(currentPosition[i]);\n }\n }\n for (let i = 0; i < 2; i++) {\n newUvs.push(currentUv[i]);\n }\n indices[i] = totalVertices;\n totalVertices += 1;\n //handling submesh data\n if (vertexData.submeshData) {\n for (let i = 0; i < vertexData.submeshData.length; i++) {\n const submeshData = vertexData.submeshData[i];\n if (submeshData.verticesStart <= vertex &&\n submeshData.verticesStart + submeshData.verticesCount > vertex) {\n submeshData.verticesCount += 1;\n }\n else if (submeshData.verticesStart > vertex) {\n submeshData.verticesStart += 1;\n }\n submeshData.indexCount = (positions.length + newPositions.length) / 3;\n submeshDataArray[i] = submeshData;\n }\n }\n }\n else {\n visitedVertices[vertex] = true;\n if (planeNormal) {\n for (let i = 0; i < 3; i++) {\n normals[vertex * 3 + i] = planeNormal[i];\n }\n }\n }\n }\n });\n const resultPositions = new Float32Array(positions.length + newPositions.length);\n resultPositions.set(positions);\n resultPositions.set(newPositions, positions.length);\n const resultNormals = new Float32Array(normals.length + newNormals.length);\n resultNormals.set(normals);\n resultNormals.set(newNormals, normals.length);\n const resultUvs = new Float32Array(uvs.length + newUvs.length);\n resultUvs.set(uvs);\n resultUvs.set(newUvs, uvs.length);\n newVertexData.positions = resultPositions;\n newVertexData.normals = resultNormals;\n newVertexData.uvs = resultUvs;\n newVertexData.indices = indices;\n newVertexData.submeshData = submeshDataArray;\n }\n }\n this.viewer.updateNormalSmoothingWarnings(feature, this.totalSelectedIndices / 3, false);\n return newVertexData;\n }\n update3dInternal() { }\n delete3d(node, preserveCache) {\n this.viewer.updateNormalSmoothingWarnings(node, 0, true);\n super.delete3d(node);\n }\n //Formula for normal of a plane: (vectorA-VectorB) x (VectorB-VectorC)\n calculateNormalToRef(coordinates, normalVector) {\n Vector3.FromArrayToRef(coordinates[0], 0, this.vectorA);\n Vector3.FromArrayToRef(coordinates[1], 0, this.vectorB);\n Vector3.FromArrayToRef(coordinates[2], 0, this.vectorC);\n this.vectorA.subtractInPlace(this.vectorB);\n this.vectorB.subtractInPlace(this.vectorC);\n return Vector3.CrossToRef(this.vectorB, this.vectorA, normalVector);\n }\n calculateSmoothedUnitVector(vertices) {\n let result = [];\n vertices.forEach(vertex => {\n const normalVector = this.planeNormals.get(Math.floor(vertex / 3));\n if (normalVector) {\n result = addArrays(result, normalVector);\n }\n });\n return this.calculateUnitVector(result);\n }\n calculateUnitVector(vector) {\n let divider = 0;\n const result = [];\n vector.forEach(element => {\n divider += element * element;\n });\n divider = Math.sqrt(divider);\n vector.forEach(element => {\n result.push(element / divider);\n });\n return result;\n }\n }\n\n /**\n * Represents one particle of a solid particle system.\n */\n class SolidParticle {\n /**\n * Particle BoundingInfo object\n * @returns a BoundingInfo\n */\n getBoundingInfo() {\n return this._boundingInfo;\n }\n /**\n * Returns true if there is already a bounding info\n */\n get hasBoundingInfo() {\n return this._boundingInfo !== null;\n }\n /**\n * Creates a Solid Particle object.\n * Don't create particles manually, use instead the Solid Particle System internal tools like _addParticle()\n * @param particleIndex (integer) is the particle index in the Solid Particle System pool.\n * @param particleId (integer) is the particle identifier. Unless some particles are removed from the SPS, it's the same value than the particle idx.\n * @param positionIndex (integer) is the starting index of the particle vertices in the SPS \"positions\" array.\n * @param indiceIndex (integer) is the starting index of the particle indices in the SPS \"indices\" array.\n * @param model (ModelShape) is a reference to the model shape on what the particle is designed.\n * @param shapeId (integer) is the model shape identifier in the SPS.\n * @param idxInShape (integer) is the index of the particle in the current model (ex: the 10th box of addShape(box, 30))\n * @param sps defines the sps it is associated to\n * @param modelBoundingInfo is the reference to the model BoundingInfo used for intersection computations.\n * @param materialIndex is the particle material identifier (integer) when the MultiMaterials are enabled in the SPS.\n */\n constructor(particleIndex, particleId, positionIndex, indiceIndex, model, shapeId, idxInShape, sps, modelBoundingInfo = null, materialIndex = null) {\n /**\n * particle global index\n */\n this.idx = 0;\n /**\n * particle identifier\n */\n this.id = 0;\n /**\n * The color of the particle\n */\n this.color = new Color4(1.0, 1.0, 1.0, 1.0);\n /**\n * The world space position of the particle.\n */\n this.position = Vector3.Zero();\n /**\n * The world space rotation of the particle. (Not use if rotationQuaternion is set)\n */\n this.rotation = Vector3.Zero();\n /**\n * The scaling of the particle.\n */\n this.scaling = Vector3.One();\n /**\n * The uvs of the particle.\n */\n this.uvs = new Vector4(0.0, 0.0, 1.0, 1.0);\n /**\n * The current speed of the particle.\n */\n this.velocity = Vector3.Zero();\n /**\n * The pivot point in the particle local space.\n */\n this.pivot = Vector3.Zero();\n /**\n * Must the particle be translated from its pivot point in its local space ?\n * In this case, the pivot point is set at the origin of the particle local space and the particle is translated.\n * Default : false\n */\n this.translateFromPivot = false;\n /**\n * Is the particle active or not ?\n */\n this.alive = true;\n /**\n * Is the particle visible or not ?\n */\n this.isVisible = true;\n /**\n * Index of this particle in the global \"positions\" array (Internal use)\n * @internal\n */\n this._pos = 0;\n /**\n * @internal Index of this particle in the global \"indices\" array (Internal use)\n */\n this._ind = 0;\n /**\n * ModelShape id of this particle\n */\n this.shapeId = 0;\n /**\n * Index of the particle in its shape id\n */\n this.idxInShape = 0;\n /**\n * @internal Still set as invisible in order to skip useless computations (Internal use)\n */\n this._stillInvisible = false;\n /**\n * @internal Last computed particle rotation matrix\n */\n this._rotationMatrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];\n /**\n * Parent particle Id, if any.\n * Default null.\n */\n this.parentId = null;\n /**\n * The particle material identifier (integer) when MultiMaterials are enabled in the SPS.\n */\n this.materialIndex = null;\n /**\n * Custom object or properties.\n */\n this.props = null;\n /**\n * The culling strategy to use to check whether the solid particle must be culled or not when using isInFrustum().\n * The possible values are :\n * - AbstractMesh.CULLINGSTRATEGY_STANDARD\n * - AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\n * The default value for solid particles is AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\n * Please read each static variable documentation in the class AbstractMesh to get details about the culling process.\n * */\n this.cullingStrategy = AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY;\n /**\n * @internal Internal global position in the SPS.\n */\n this._globalPosition = Vector3.Zero();\n this.idx = particleIndex;\n this.id = particleId;\n this._pos = positionIndex;\n this._ind = indiceIndex;\n this._model = model;\n this.shapeId = shapeId;\n this.idxInShape = idxInShape;\n this._sps = sps;\n if (modelBoundingInfo) {\n this._modelBoundingInfo = modelBoundingInfo;\n this._boundingInfo = new BoundingInfo(modelBoundingInfo.minimum, modelBoundingInfo.maximum);\n }\n if (materialIndex !== null) {\n this.materialIndex = materialIndex;\n }\n }\n /**\n * Copies the particle property values into the existing target : position, rotation, scaling, uvs, colors, pivot, parent, visibility, alive\n * @param target the particle target\n * @returns the current particle\n */\n copyToRef(target) {\n target.position.copyFrom(this.position);\n target.rotation.copyFrom(this.rotation);\n if (this.rotationQuaternion) {\n if (target.rotationQuaternion) {\n target.rotationQuaternion.copyFrom(this.rotationQuaternion);\n }\n else {\n target.rotationQuaternion = this.rotationQuaternion.clone();\n }\n }\n target.scaling.copyFrom(this.scaling);\n if (this.color) {\n if (target.color) {\n target.color.copyFrom(this.color);\n }\n else {\n target.color = this.color.clone();\n }\n }\n target.uvs.copyFrom(this.uvs);\n target.velocity.copyFrom(this.velocity);\n target.pivot.copyFrom(this.pivot);\n target.translateFromPivot = this.translateFromPivot;\n target.alive = this.alive;\n target.isVisible = this.isVisible;\n target.parentId = this.parentId;\n target.cullingStrategy = this.cullingStrategy;\n if (this.materialIndex !== null) {\n target.materialIndex = this.materialIndex;\n }\n return this;\n }\n /**\n * Legacy support, changed scale to scaling\n */\n get scale() {\n return this.scaling;\n }\n /**\n * Legacy support, changed scale to scaling\n */\n set scale(scale) {\n this.scaling = scale;\n }\n /**\n * Legacy support, changed quaternion to rotationQuaternion\n */\n get quaternion() {\n return this.rotationQuaternion;\n }\n /**\n * Legacy support, changed quaternion to rotationQuaternion\n */\n set quaternion(q) {\n this.rotationQuaternion = q;\n }\n /**\n * Returns a boolean. True if the particle intersects another particle or another mesh, else false.\n * The intersection is computed on the particle bounding sphere and Axis Aligned Bounding Box (AABB)\n * @param target is the object (solid particle or mesh) what the intersection is computed against.\n * @returns true if it intersects\n */\n intersectsMesh(target) {\n if (!this._boundingInfo || !target.hasBoundingInfo) {\n return false;\n }\n if (this._sps._bSphereOnly) {\n return BoundingSphere.Intersects(this._boundingInfo.boundingSphere, target.getBoundingInfo().boundingSphere);\n }\n return this._boundingInfo.intersects(target.getBoundingInfo(), false);\n }\n /**\n * Returns `true` if the solid particle is within the frustum defined by the passed array of planes.\n * A particle is in the frustum if its bounding box intersects the frustum\n * @param frustumPlanes defines the frustum to test\n * @returns true if the particle is in the frustum planes\n */\n isInFrustum(frustumPlanes) {\n return this._boundingInfo !== null && this._boundingInfo.isInFrustum(frustumPlanes, this.cullingStrategy);\n }\n /**\n * get the rotation matrix of the particle\n * @internal\n */\n getRotationMatrix(m) {\n let quaternion;\n if (this.rotationQuaternion) {\n quaternion = this.rotationQuaternion;\n }\n else {\n quaternion = TmpVectors.Quaternion[0];\n const rotation = this.rotation;\n Quaternion.RotationYawPitchRollToRef(rotation.y, rotation.x, rotation.z, quaternion);\n }\n quaternion.toRotationMatrix(m);\n }\n }\n /**\n * Represents the shape of the model used by one particle of a solid particle system.\n * SPS internal tool, don't use it manually.\n */\n class ModelShape {\n /**\n * Get or set the shapeId\n * @deprecated Please use shapeId instead\n */\n get shapeID() {\n return this.shapeId;\n }\n set shapeID(shapeID) {\n this.shapeId = shapeID;\n }\n /**\n * Creates a ModelShape object. This is an internal simplified reference to a mesh used as for a model to replicate particles from by the SPS.\n * SPS internal tool, don't use it manually.\n * @internal\n */\n constructor(id, shape, indices, normals, colors, shapeUV, posFunction, vtxFunction, material) {\n /**\n * length of the shape in the model indices array (internal use)\n * @internal\n */\n this._indicesLength = 0;\n this.shapeId = id;\n this._shape = shape;\n this._indices = indices;\n this._indicesLength = indices.length;\n this._shapeUV = shapeUV;\n this._shapeColors = colors;\n this._normals = normals;\n this._positionFunction = posFunction;\n this._vertexFunction = vtxFunction;\n this._material = material;\n }\n }\n /**\n * Represents a Depth Sorted Particle in the solid particle system.\n * @internal\n */\n class DepthSortedParticle {\n /**\n * Creates a new sorted particle\n * @param idx\n * @param ind\n * @param indLength\n * @param materialIndex\n */\n constructor(idx, ind, indLength, materialIndex) {\n /**\n * Particle index\n */\n this.idx = 0;\n /**\n * Index of the particle in the \"indices\" array\n */\n this.ind = 0;\n /**\n * Length of the particle shape in the \"indices\" array\n */\n this.indicesLength = 0;\n /**\n * Squared distance from the particle to the camera\n */\n this.sqDistance = 0.0;\n /**\n * Material index when used with MultiMaterials\n */\n this.materialIndex = 0;\n this.idx = idx;\n this.ind = ind;\n this.indicesLength = indLength;\n this.materialIndex = materialIndex;\n }\n }\n /**\n * Represents a solid particle vertex\n */\n class SolidParticleVertex {\n /**\n * Creates a new solid particle vertex\n */\n constructor() {\n this.position = Vector3.Zero();\n this.color = new Color4(1.0, 1.0, 1.0, 1.0);\n this.uv = Vector2.Zero();\n }\n // Getters and Setters for back-compatibility\n /** Vertex x coordinate */\n get x() {\n return this.position.x;\n }\n set x(val) {\n this.position.x = val;\n }\n /** Vertex y coordinate */\n get y() {\n return this.position.y;\n }\n set y(val) {\n this.position.y = val;\n }\n /** Vertex z coordinate */\n get z() {\n return this.position.z;\n }\n set z(val) {\n this.position.z = val;\n }\n }\n\n /**\n * The SPS is a single updatable mesh. The solid particles are simply separate parts or faces of this big mesh.\n *As it is just a mesh, the SPS has all the same properties than any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.\n\n * The SPS is also a particle system. It provides some methods to manage the particles.\n * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.\n *\n * Full documentation here : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_intro\n */\n class SolidParticleSystem {\n /**\n * Creates a SPS (Solid Particle System) object.\n * @param name (String) is the SPS name, this will be the underlying mesh name.\n * @param scene (Scene) is the scene in which the SPS is added.\n * @param options defines the options of the sps e.g.\n * * updatable (optional boolean, default true) : if the SPS must be updatable or immutable.\n * * isPickable (optional boolean, default false) : if the solid particles must be pickable.\n * * enableDepthSort (optional boolean, default false) : if the solid particles must be sorted in the geometry according to their distance to the camera.\n * * useModelMaterial (optional boolean, default false) : if the model materials must be used to create the SPS multimaterial. This enables the multimaterial supports of the SPS.\n * * enableMultiMaterial (optional boolean, default false) : if the solid particles can be given different materials.\n * * expandable (optional boolean, default false) : if particles can still be added after the initial SPS mesh creation.\n * * particleIntersection (optional boolean, default false) : if the solid particle intersections must be computed.\n * * boundingSphereOnly (optional boolean, default false) : if the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster).\n * * bSphereRadiusFactor (optional float, default 1.0) : a number to multiply the bounding sphere radius by in order to reduce it for instance.\n * * computeBoundingBox (optional boolean, default false): if the bounding box of the entire SPS will be computed (for occlusion detection, for example). If it is false, the bounding box will be the bounding box of the first particle.\n * * autoFixFaceOrientation (optional boolean, default false): if the particle face orientations will be flipped for transformations that change orientation (scale (-1, 1, 1), for example)\n * @param options.updatable\n * @param options.isPickable\n * @param options.enableDepthSort\n * @param options.particleIntersection\n * @param options.boundingSphereOnly\n * @param options.bSphereRadiusFactor\n * @param options.expandable\n * @param options.useModelMaterial\n * @param options.enableMultiMaterial\n * @param options.computeBoundingBox\n * @param options.autoFixFaceOrientation\n * @example bSphereRadiusFactor = 1.0 / Math.sqrt(3.0) => the bounding sphere exactly matches a spherical mesh.\n */\n constructor(name, scene, options) {\n /**\n * The SPS array of Solid Particle objects. Just access each particle as with any classic array.\n * Example : var p = SPS.particles[i];\n */\n this.particles = new Array();\n /**\n * The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.\n */\n this.nbParticles = 0;\n /**\n * If the particles must ever face the camera (default false). Useful for planar particles.\n */\n this.billboard = false;\n /**\n * Recompute normals when adding a shape\n */\n this.recomputeNormals = false;\n /**\n * This a counter ofr your own usage. It's not set by any SPS functions.\n */\n this.counter = 0;\n /**\n * This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity.\n * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/optimize_sps#limit-garbage-collection\n */\n this.vars = {};\n /**\n * If the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster). (Internal use only)\n * @internal\n */\n this._bSphereOnly = false;\n /**\n * A number to multiply the bounding sphere radius by in order to reduce it for instance. (Internal use only)\n * @internal\n */\n this._bSphereRadiusFactor = 1.0;\n this._positions = new Array();\n this._indices = new Array();\n this._normals = new Array();\n this._colors = new Array();\n this._uvs = new Array();\n this._index = 0; // indices index\n this._updatable = true;\n this._pickable = false;\n this._isVisibilityBoxLocked = false;\n this._alwaysVisible = false;\n this._depthSort = false;\n this._expandable = false;\n this._shapeCounter = 0;\n this._copy = new SolidParticle(0, 0, 0, 0, null, 0, 0, this);\n this._color = new Color4(0, 0, 0, 0);\n this._computeParticleColor = true;\n this._computeParticleTexture = true;\n this._computeParticleRotation = true;\n this._computeParticleVertex = false;\n this._computeBoundingBox = false;\n this._autoFixFaceOrientation = false;\n this._depthSortParticles = true;\n this._mustUnrotateFixedNormals = false;\n this._particlesIntersect = false;\n this._needs32Bits = false;\n this._isNotBuilt = true;\n this._lastParticleId = 0;\n this._idxOfId = []; // array : key = particle.id / value = particle.idx\n this._multimaterialEnabled = false;\n this._useModelMaterial = false;\n this._depthSortFunction = (p1, p2) => p2.sqDistance - p1.sqDistance;\n this._materialSortFunction = (p1, p2) => p1.materialIndex - p2.materialIndex;\n this._autoUpdateSubMeshes = false;\n this._recomputeInvisibles = false;\n this.name = name;\n this._scene = scene || EngineStore.LastCreatedScene;\n this._camera = scene.activeCamera;\n this._pickable = options ? options.isPickable : false;\n this._depthSort = options ? options.enableDepthSort : false;\n this._multimaterialEnabled = options ? options.enableMultiMaterial : false;\n this._useModelMaterial = options ? options.useModelMaterial : false;\n this._multimaterialEnabled = this._useModelMaterial ? true : this._multimaterialEnabled;\n this._expandable = options ? options.expandable : false;\n this._particlesIntersect = options ? options.particleIntersection : false;\n this._bSphereOnly = options ? options.boundingSphereOnly : false;\n this._bSphereRadiusFactor = options && options.bSphereRadiusFactor ? options.bSphereRadiusFactor : 1.0;\n this._computeBoundingBox = (options === null || options === void 0 ? void 0 : options.computeBoundingBox) ? options.computeBoundingBox : false;\n this._autoFixFaceOrientation = (options === null || options === void 0 ? void 0 : options.autoFixFaceOrientation) ? options.autoFixFaceOrientation : false;\n if (options && options.updatable !== undefined) {\n this._updatable = options.updatable;\n }\n else {\n this._updatable = true;\n }\n if (this._pickable) {\n this.pickedBySubMesh = [[]];\n this.pickedParticles = this.pickedBySubMesh[0];\n }\n if (this._depthSort || this._multimaterialEnabled) {\n this.depthSortedParticles = [];\n }\n if (this._multimaterialEnabled) {\n this._multimaterial = new MultiMaterial(this.name + \"MultiMaterial\", this._scene);\n this._materials = [];\n this._materialIndexesById = {};\n }\n this._tmpVertex = new SolidParticleVertex();\n }\n /**\n * Builds the SPS underlying mesh. Returns a standard Mesh.\n * If no model shape was added to the SPS, the returned mesh is just a single triangular plane.\n * @returns the created mesh\n */\n buildMesh() {\n if (!this._isNotBuilt && this.mesh) {\n return this.mesh;\n }\n if (this.nbParticles === 0 && !this.mesh) {\n const triangle = CreateDisc(\"\", { radius: 1, tessellation: 3 }, this._scene);\n this.addShape(triangle, 1);\n triangle.dispose();\n }\n this._indices32 = this._needs32Bits ? new Uint32Array(this._indices) : new Uint16Array(this._indices);\n this._positions32 = new Float32Array(this._positions);\n this._uvs32 = new Float32Array(this._uvs);\n this._colors32 = new Float32Array(this._colors);\n if (!this.mesh) {\n // in case it's already expanded\n const mesh = new Mesh(this.name, this._scene);\n this.mesh = mesh;\n }\n if (!this._updatable && this._multimaterialEnabled) {\n this._sortParticlesByMaterial(); // this may reorder the indices32\n }\n if (this.recomputeNormals) {\n VertexData.ComputeNormals(this._positions32, this._indices32, this._normals);\n }\n this._normals32 = new Float32Array(this._normals);\n this._fixedNormal32 = new Float32Array(this._normals);\n if (this._mustUnrotateFixedNormals) {\n // the particles could be created already rotated in the mesh with a positionFunction\n this._unrotateFixedNormals();\n }\n const vertexData = new VertexData();\n vertexData.indices = this._depthSort ? this._indices : this._indices32;\n vertexData.set(this._positions32, VertexBuffer.PositionKind);\n vertexData.set(this._normals32, VertexBuffer.NormalKind);\n if (this._uvs32.length > 0) {\n vertexData.set(this._uvs32, VertexBuffer.UVKind);\n }\n if (this._colors32.length > 0) {\n vertexData.set(this._colors32, VertexBuffer.ColorKind);\n }\n vertexData.applyToMesh(this.mesh, this._updatable);\n this.mesh.isPickable = this._pickable;\n if (this._pickable) {\n let faceId = 0;\n for (let p = 0; p < this.nbParticles; p++) {\n const part = this.particles[p];\n const lind = part._model._indicesLength;\n for (let i = 0; i < lind; i++) {\n const f = i % 3;\n if (f == 0) {\n const pickedData = { idx: part.idx, faceId: faceId };\n this.pickedParticles[faceId] = pickedData;\n faceId++;\n }\n }\n }\n }\n if (this._multimaterialEnabled) {\n this.setMultiMaterial(this._materials);\n }\n if (!this._expandable) {\n // free memory\n if (!this._depthSort && !this._multimaterialEnabled && !this._autoFixFaceOrientation) {\n this._indices = null;\n }\n this._positions = null;\n this._normals = null;\n this._uvs = null;\n this._colors = null;\n if (!this._updatable) {\n this.particles.length = 0;\n }\n }\n this._isNotBuilt = false;\n this.recomputeNormals = false;\n this._recomputeInvisibles = true;\n return this.mesh;\n }\n /**\n * Digests the mesh and generates as many solid particles in the system as wanted. Returns the SPS.\n * These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places.\n * Thus the particles generated from `digest()` have their property `position` set yet.\n * @param mesh ( Mesh ) is the mesh to be digested\n * @param options {facetNb} (optional integer, default 1) is the number of mesh facets per particle, this parameter is overridden by the parameter `number` if any\n * {delta} (optional integer, default 0) is the random extra number of facets per particle , each particle will have between `facetNb` and `facetNb + delta` facets\n * {number} (optional positive integer) is the wanted number of particles : each particle is built with `mesh_total_facets / number` facets\n * {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.\n * @param options.facetNb\n * @param options.number\n * @param options.delta\n * @param options.storage\n * @returns the current SPS\n */\n digest(mesh, options) {\n let size = (options && options.facetNb) || 1;\n let number = (options && options.number) || 0;\n let delta = (options && options.delta) || 0;\n const meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);\n const meshInd = mesh.getIndices();\n const meshUV = mesh.getVerticesData(VertexBuffer.UVKind);\n const meshCol = mesh.getVerticesData(VertexBuffer.ColorKind);\n const meshNor = mesh.getVerticesData(VertexBuffer.NormalKind);\n const storage = options && options.storage ? options.storage : null;\n let f = 0; // facet counter\n const totalFacets = meshInd.length / 3; // a facet is a triangle, so 3 indices\n // compute size from number\n if (number) {\n number = number > totalFacets ? totalFacets : number;\n size = Math.round(totalFacets / number);\n delta = 0;\n }\n else {\n size = size > totalFacets ? totalFacets : size;\n }\n const facetPos = []; // submesh positions\n const facetNor = [];\n const facetInd = []; // submesh indices\n const facetUV = []; // submesh UV\n const facetCol = []; // submesh colors\n const barycenter = Vector3.Zero();\n const sizeO = size;\n while (f < totalFacets) {\n size = sizeO + Math.floor((1 + delta) * Math.random());\n if (f > totalFacets - size) {\n size = totalFacets - f;\n }\n // reset temp arrays\n facetPos.length = 0;\n facetNor.length = 0;\n facetInd.length = 0;\n facetUV.length = 0;\n facetCol.length = 0;\n // iterate over \"size\" facets\n let fi = 0;\n for (let j = f * 3; j < (f + size) * 3; j++) {\n facetInd.push(fi);\n const i = meshInd[j];\n const i3 = i * 3;\n facetPos.push(meshPos[i3], meshPos[i3 + 1], meshPos[i3 + 2]);\n facetNor.push(meshNor[i3], meshNor[i3 + 1], meshNor[i3 + 2]);\n if (meshUV) {\n const i2 = i * 2;\n facetUV.push(meshUV[i2], meshUV[i2 + 1]);\n }\n if (meshCol) {\n const i4 = i * 4;\n facetCol.push(meshCol[i4], meshCol[i4 + 1], meshCol[i4 + 2], meshCol[i4 + 3]);\n }\n fi++;\n }\n // create a model shape for each single particle\n let idx = this.nbParticles;\n const shape = this._posToShape(facetPos);\n const shapeUV = this._uvsToShapeUV(facetUV);\n const shapeInd = facetInd.slice();\n const shapeCol = facetCol.slice();\n const shapeNor = facetNor.slice();\n // compute the barycenter of the shape\n barycenter.copyFromFloats(0, 0, 0);\n let v;\n for (v = 0; v < shape.length; v++) {\n barycenter.addInPlace(shape[v]);\n }\n barycenter.scaleInPlace(1 / shape.length);\n // shift the shape from its barycenter to the origin\n // and compute the BBox required for intersection.\n const minimum = new Vector3(Infinity, Infinity, Infinity);\n const maximum = new Vector3(-Infinity, -Infinity, -Infinity);\n for (v = 0; v < shape.length; v++) {\n shape[v].subtractInPlace(barycenter);\n minimum.minimizeInPlaceFromFloats(shape[v].x, shape[v].y, shape[v].z);\n maximum.maximizeInPlaceFromFloats(shape[v].x, shape[v].y, shape[v].z);\n }\n let bInfo;\n if (this._particlesIntersect) {\n bInfo = new BoundingInfo(minimum, maximum);\n }\n let material = null;\n if (this._useModelMaterial) {\n material = mesh.material ? mesh.material : this._setDefaultMaterial();\n }\n const modelShape = new ModelShape(this._shapeCounter, shape, shapeInd, shapeNor, shapeCol, shapeUV, null, null, material);\n // add the particle in the SPS\n const currentPos = this._positions.length;\n const currentInd = this._indices.length;\n this._meshBuilder(this._index, currentInd, shape, this._positions, shapeInd, this._indices, facetUV, this._uvs, shapeCol, this._colors, shapeNor, this._normals, idx, 0, null, modelShape);\n this._addParticle(idx, this._lastParticleId, currentPos, currentInd, modelShape, this._shapeCounter, 0, bInfo, storage);\n // initialize the particle position\n this.particles[this.nbParticles].position.addInPlace(barycenter);\n if (!storage) {\n this._index += shape.length;\n idx++;\n this.nbParticles++;\n this._lastParticleId++;\n }\n this._shapeCounter++;\n f += size;\n }\n this._isNotBuilt = true; // buildMesh() is now expected for setParticles() to work\n return this;\n }\n /**\n * Unrotate the fixed normals in case the mesh was built with pre-rotated particles, ex : use of positionFunction in addShape()\n * @internal\n */\n _unrotateFixedNormals() {\n let index = 0;\n let idx = 0;\n const tmpNormal = TmpVectors.Vector3[0];\n const quaternion = TmpVectors.Quaternion[0];\n const invertedRotMatrix = TmpVectors.Matrix[0];\n for (let p = 0; p < this.particles.length; p++) {\n const particle = this.particles[p];\n const shape = particle._model._shape;\n // computing the inverse of the rotation matrix from the quaternion\n // is equivalent to computing the matrix of the inverse quaternion, i.e of the conjugate quaternion\n if (particle.rotationQuaternion) {\n particle.rotationQuaternion.conjugateToRef(quaternion);\n }\n else {\n const rotation = particle.rotation;\n Quaternion.RotationYawPitchRollToRef(rotation.y, rotation.x, rotation.z, quaternion);\n quaternion.conjugateInPlace();\n }\n quaternion.toRotationMatrix(invertedRotMatrix);\n for (let pt = 0; pt < shape.length; pt++) {\n idx = index + pt * 3;\n Vector3.TransformNormalFromFloatsToRef(this._normals32[idx], this._normals32[idx + 1], this._normals32[idx + 2], invertedRotMatrix, tmpNormal);\n tmpNormal.toArray(this._fixedNormal32, idx);\n }\n index = idx + 3;\n }\n }\n /**\n * Resets the temporary working copy particle\n * @internal\n */\n _resetCopy() {\n const copy = this._copy;\n copy.position.setAll(0);\n copy.rotation.setAll(0);\n copy.rotationQuaternion = null;\n copy.scaling.setAll(1);\n copy.uvs.copyFromFloats(0.0, 0.0, 1.0, 1.0);\n copy.color = null;\n copy.translateFromPivot = false;\n copy.shapeId = 0;\n copy.materialIndex = null;\n }\n /**\n * Inserts the shape model geometry in the global SPS mesh by updating the positions, indices, normals, colors, uvs arrays\n * @param p the current index in the positions array to be updated\n * @param ind the current index in the indices array\n * @param shape a Vector3 array, the shape geometry\n * @param positions the positions array to be updated\n * @param meshInd the shape indices array\n * @param indices the indices array to be updated\n * @param meshUV the shape uv array\n * @param uvs the uv array to be updated\n * @param meshCol the shape color array\n * @param colors the color array to be updated\n * @param meshNor the shape normals array\n * @param normals the normals array to be updated\n * @param idx the particle index\n * @param idxInShape the particle index in its shape\n * @param options the addShape() method passed options\n * @param model\n * @model the particle model\n * @internal\n */\n _meshBuilder(p, ind, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, meshNor, normals, idx, idxInShape, options, model) {\n let i;\n let u = 0;\n let c = 0;\n let n = 0;\n this._resetCopy();\n const copy = this._copy;\n const storeApart = options && options.storage ? true : false;\n copy.idx = idx;\n copy.idxInShape = idxInShape;\n copy.shapeId = model.shapeId;\n if (this._useModelMaterial) {\n const materialId = model._material.uniqueId;\n const materialIndexesById = this._materialIndexesById;\n if (!Object.prototype.hasOwnProperty.call(materialIndexesById, materialId)) {\n materialIndexesById[materialId] = this._materials.length;\n this._materials.push(model._material);\n }\n const matIdx = materialIndexesById[materialId];\n copy.materialIndex = matIdx;\n }\n if (options && options.positionFunction) {\n // call to custom positionFunction\n options.positionFunction(copy, idx, idxInShape);\n this._mustUnrotateFixedNormals = true;\n }\n // in case the particle geometry must NOT be inserted in the SPS mesh geometry\n if (storeApart) {\n return copy;\n }\n const rotMatrix = TmpVectors.Matrix[0];\n const tmpVertex = this._tmpVertex;\n const tmpVector = tmpVertex.position;\n const tmpColor = tmpVertex.color;\n const tmpUV = tmpVertex.uv;\n const tmpRotated = TmpVectors.Vector3[1];\n const pivotBackTranslation = TmpVectors.Vector3[2];\n const scaledPivot = TmpVectors.Vector3[3];\n Matrix.IdentityToRef(rotMatrix);\n copy.getRotationMatrix(rotMatrix);\n copy.pivot.multiplyToRef(copy.scaling, scaledPivot);\n if (copy.translateFromPivot) {\n pivotBackTranslation.setAll(0.0);\n }\n else {\n pivotBackTranslation.copyFrom(scaledPivot);\n }\n const someVertexFunction = options && options.vertexFunction;\n for (i = 0; i < shape.length; i++) {\n tmpVector.copyFrom(shape[i]);\n if (copy.color) {\n tmpColor.copyFrom(copy.color);\n }\n if (meshUV) {\n tmpUV.copyFromFloats(meshUV[u], meshUV[u + 1]);\n }\n if (someVertexFunction) {\n options.vertexFunction(copy, tmpVertex, i);\n }\n tmpVector.multiplyInPlace(copy.scaling).subtractInPlace(scaledPivot);\n Vector3.TransformCoordinatesToRef(tmpVector, rotMatrix, tmpRotated);\n tmpRotated.addInPlace(pivotBackTranslation).addInPlace(copy.position);\n positions.push(tmpRotated.x, tmpRotated.y, tmpRotated.z);\n if (meshUV) {\n const copyUvs = copy.uvs;\n uvs.push((copyUvs.z - copyUvs.x) * tmpUV.x + copyUvs.x, (copyUvs.w - copyUvs.y) * tmpUV.y + copyUvs.y);\n u += 2;\n }\n if (copy.color) {\n this._color.copyFrom(tmpColor);\n }\n else {\n const color = this._color;\n if (meshCol && meshCol[c] !== undefined) {\n color.r = meshCol[c];\n color.g = meshCol[c + 1];\n color.b = meshCol[c + 2];\n color.a = meshCol[c + 3];\n }\n else {\n color.r = 1.0;\n color.g = 1.0;\n color.b = 1.0;\n color.a = 1.0;\n }\n }\n colors.push(this._color.r, this._color.g, this._color.b, this._color.a);\n c += 4;\n if (!this.recomputeNormals && meshNor) {\n Vector3.TransformNormalFromFloatsToRef(meshNor[n], meshNor[n + 1], meshNor[n + 2], rotMatrix, tmpVector);\n normals.push(tmpVector.x, tmpVector.y, tmpVector.z);\n n += 3;\n }\n }\n for (i = 0; i < meshInd.length; i++) {\n const current_ind = p + meshInd[i];\n indices.push(current_ind);\n if (current_ind > 65535) {\n this._needs32Bits = true;\n }\n }\n if (this._depthSort || this._multimaterialEnabled) {\n const matIndex = copy.materialIndex !== null ? copy.materialIndex : 0;\n this.depthSortedParticles.push(new DepthSortedParticle(idx, ind, meshInd.length, matIndex));\n }\n return copy;\n }\n /**\n * Returns a shape Vector3 array from positions float array\n * @param positions float array\n * @returns a vector3 array\n * @internal\n */\n _posToShape(positions) {\n const shape = [];\n for (let i = 0; i < positions.length; i += 3) {\n shape.push(Vector3.FromArray(positions, i));\n }\n return shape;\n }\n /**\n * Returns a shapeUV array from a float uvs (array deep copy)\n * @param uvs as a float array\n * @returns a shapeUV array\n * @internal\n */\n _uvsToShapeUV(uvs) {\n const shapeUV = [];\n if (uvs) {\n for (let i = 0; i < uvs.length; i++) {\n shapeUV.push(uvs[i]);\n }\n }\n return shapeUV;\n }\n /**\n * Adds a new particle object in the particles array\n * @param idx particle index in particles array\n * @param id particle id\n * @param idxpos positionIndex : the starting index of the particle vertices in the SPS \"positions\" array\n * @param idxind indiceIndex : he starting index of the particle indices in the SPS \"indices\" array\n * @param model particle ModelShape object\n * @param shapeId model shape identifier\n * @param idxInShape index of the particle in the current model\n * @param bInfo model bounding info object\n * @param storage target storage array, if any\n * @internal\n */\n _addParticle(idx, id, idxpos, idxind, model, shapeId, idxInShape, bInfo = null, storage = null) {\n const sp = new SolidParticle(idx, id, idxpos, idxind, model, shapeId, idxInShape, this, bInfo);\n const target = storage ? storage : this.particles;\n target.push(sp);\n return sp;\n }\n /**\n * Adds some particles to the SPS from the model shape. Returns the shape id.\n * Please read the doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/immutable_sps\n * @param mesh is any Mesh object that will be used as a model for the solid particles.\n * @param nb (positive integer) the number of particles to be created from this model\n * @param options {positionFunction} is an optional javascript function to called for each particle on SPS creation.\n * {vertexFunction} is an optional javascript function to called for each vertex of each particle on SPS creation\n * {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.\n * @param options.positionFunction\n * @param options.vertexFunction\n * @param options.storage\n * @returns the number of shapes in the system\n */\n addShape(mesh, nb, options) {\n const meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);\n const meshInd = mesh.getIndices();\n const meshUV = mesh.getVerticesData(VertexBuffer.UVKind);\n const meshCol = mesh.getVerticesData(VertexBuffer.ColorKind);\n const meshNor = mesh.getVerticesData(VertexBuffer.NormalKind);\n this.recomputeNormals = meshNor ? false : true;\n const indices = Array.from(meshInd);\n const shapeNormals = Array.from(meshNor);\n const shapeColors = meshCol ? Array.from(meshCol) : [];\n const storage = options && options.storage ? options.storage : null;\n let bbInfo = null;\n if (this._particlesIntersect) {\n bbInfo = mesh.getBoundingInfo();\n }\n const shape = this._posToShape(meshPos);\n const shapeUV = this._uvsToShapeUV(meshUV);\n const posfunc = options ? options.positionFunction : null;\n const vtxfunc = options ? options.vertexFunction : null;\n let material = null;\n if (this._useModelMaterial) {\n material = mesh.material ? mesh.material : this._setDefaultMaterial();\n }\n const modelShape = new ModelShape(this._shapeCounter, shape, indices, shapeNormals, shapeColors, shapeUV, posfunc, vtxfunc, material);\n // particles\n for (let i = 0; i < nb; i++) {\n this._insertNewParticle(this.nbParticles, i, modelShape, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, storage, options);\n }\n this._shapeCounter++;\n this._isNotBuilt = true; // buildMesh() call is now expected for setParticles() to work\n return this._shapeCounter - 1;\n }\n /**\n * Rebuilds a particle back to its just built status : if needed, recomputes the custom positions and vertices\n * @internal\n */\n _rebuildParticle(particle, reset = false) {\n this._resetCopy();\n const copy = this._copy;\n if (particle._model._positionFunction) {\n // recall to stored custom positionFunction\n particle._model._positionFunction(copy, particle.idx, particle.idxInShape);\n }\n const rotMatrix = TmpVectors.Matrix[0];\n const tmpVertex = TmpVectors.Vector3[0];\n const tmpRotated = TmpVectors.Vector3[1];\n const pivotBackTranslation = TmpVectors.Vector3[2];\n const scaledPivot = TmpVectors.Vector3[3];\n copy.getRotationMatrix(rotMatrix);\n particle.pivot.multiplyToRef(particle.scaling, scaledPivot);\n if (copy.translateFromPivot) {\n pivotBackTranslation.copyFromFloats(0.0, 0.0, 0.0);\n }\n else {\n pivotBackTranslation.copyFrom(scaledPivot);\n }\n const shape = particle._model._shape;\n for (let pt = 0; pt < shape.length; pt++) {\n tmpVertex.copyFrom(shape[pt]);\n if (particle._model._vertexFunction) {\n particle._model._vertexFunction(copy, tmpVertex, pt); // recall to stored vertexFunction\n }\n tmpVertex.multiplyInPlace(copy.scaling).subtractInPlace(scaledPivot);\n Vector3.TransformCoordinatesToRef(tmpVertex, rotMatrix, tmpRotated);\n tmpRotated\n .addInPlace(pivotBackTranslation)\n .addInPlace(copy.position)\n .toArray(this._positions32, particle._pos + pt * 3);\n }\n if (reset) {\n particle.position.setAll(0.0);\n particle.rotation.setAll(0.0);\n particle.rotationQuaternion = null;\n particle.scaling.setAll(1.0);\n particle.uvs.setAll(0.0);\n particle.pivot.setAll(0.0);\n particle.translateFromPivot = false;\n particle.parentId = null;\n }\n }\n /**\n * Rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed.\n * @param reset boolean, default false : if the particles must be reset at position and rotation zero, scaling 1, color white, initial UVs and not parented.\n * @returns the SPS.\n */\n rebuildMesh(reset = false) {\n for (let p = 0; p < this.particles.length; p++) {\n this._rebuildParticle(this.particles[p], reset);\n }\n this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions32, false, false);\n return this;\n }\n /** Removes the particles from the start-th to the end-th included from an expandable SPS (required).\n * Returns an array with the removed particles.\n * If the number of particles to remove is lower than zero or greater than the global remaining particle number, then an empty array is returned.\n * The SPS can't be empty so at least one particle needs to remain in place.\n * Under the hood, the VertexData array, so the VBO buffer, is recreated each call.\n * @param start index of the first particle to remove\n * @param end index of the last particle to remove (included)\n * @returns an array populated with the removed particles\n */\n removeParticles(start, end) {\n const nb = end - start + 1;\n if (!this._expandable || nb <= 0 || nb >= this.nbParticles || !this._updatable) {\n return [];\n }\n const particles = this.particles;\n const currentNb = this.nbParticles;\n if (end < currentNb - 1) {\n // update the particle indexes in the positions array in case they're remaining particles after the last removed\n const firstRemaining = end + 1;\n const shiftPos = particles[firstRemaining]._pos - particles[start]._pos;\n const shifInd = particles[firstRemaining]._ind - particles[start]._ind;\n for (let i = firstRemaining; i < currentNb; i++) {\n const part = particles[i];\n part._pos -= shiftPos;\n part._ind -= shifInd;\n }\n }\n const removed = particles.splice(start, nb);\n this._positions.length = 0;\n this._indices.length = 0;\n this._colors.length = 0;\n this._uvs.length = 0;\n this._normals.length = 0;\n this._index = 0;\n this._idxOfId.length = 0;\n if (this._depthSort || this._multimaterialEnabled) {\n this.depthSortedParticles = [];\n }\n let ind = 0;\n const particlesLength = particles.length;\n for (let p = 0; p < particlesLength; p++) {\n const particle = particles[p];\n const model = particle._model;\n const shape = model._shape;\n const modelIndices = model._indices;\n const modelNormals = model._normals;\n const modelColors = model._shapeColors;\n const modelUVs = model._shapeUV;\n particle.idx = p;\n this._idxOfId[particle.id] = p;\n this._meshBuilder(this._index, ind, shape, this._positions, modelIndices, this._indices, modelUVs, this._uvs, modelColors, this._colors, modelNormals, this._normals, particle.idx, particle.idxInShape, null, model);\n this._index += shape.length;\n ind += modelIndices.length;\n }\n this.nbParticles -= nb;\n this._isNotBuilt = true; // buildMesh() call is now expected for setParticles() to work\n return removed;\n }\n /**\n * Inserts some pre-created particles in the solid particle system so that they can be managed by setParticles().\n * @param solidParticleArray an array populated with Solid Particles objects\n * @returns the SPS\n */\n insertParticlesFromArray(solidParticleArray) {\n if (!this._expandable) {\n return this;\n }\n let idxInShape = 0;\n let currentShapeId = solidParticleArray[0].shapeId;\n const nb = solidParticleArray.length;\n for (let i = 0; i < nb; i++) {\n const sp = solidParticleArray[i];\n const model = sp._model;\n const shape = model._shape;\n const meshInd = model._indices;\n const meshUV = model._shapeUV;\n const meshCol = model._shapeColors;\n const meshNor = model._normals;\n const noNor = meshNor ? false : true;\n this.recomputeNormals = noNor || this.recomputeNormals;\n const bbInfo = sp.getBoundingInfo();\n const newPart = this._insertNewParticle(this.nbParticles, idxInShape, model, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, null, null);\n sp.copyToRef(newPart);\n idxInShape++;\n if (currentShapeId != sp.shapeId) {\n currentShapeId = sp.shapeId;\n idxInShape = 0;\n }\n }\n this._isNotBuilt = true; // buildMesh() call is now expected for setParticles() to work\n return this;\n }\n /**\n * Creates a new particle and modifies the SPS mesh geometry :\n * - calls _meshBuilder() to increase the SPS mesh geometry step by step\n * - calls _addParticle() to populate the particle array\n * factorized code from addShape() and insertParticlesFromArray()\n * @param idx particle index in the particles array\n * @param i particle index in its shape\n * @param modelShape particle ModelShape object\n * @param shape shape vertex array\n * @param meshInd shape indices array\n * @param meshUV shape uv array\n * @param meshCol shape color array\n * @param meshNor shape normals array\n * @param bbInfo shape bounding info\n * @param storage target particle storage\n * @param options\n * @options addShape() passed options\n * @internal\n */\n _insertNewParticle(idx, i, modelShape, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, storage, options) {\n const currentPos = this._positions.length;\n const currentInd = this._indices.length;\n const currentCopy = this._meshBuilder(this._index, currentInd, shape, this._positions, meshInd, this._indices, meshUV, this._uvs, meshCol, this._colors, meshNor, this._normals, idx, i, options, modelShape);\n let sp = null;\n if (this._updatable) {\n sp = this._addParticle(this.nbParticles, this._lastParticleId, currentPos, currentInd, modelShape, this._shapeCounter, i, bbInfo, storage);\n sp.position.copyFrom(currentCopy.position);\n sp.rotation.copyFrom(currentCopy.rotation);\n if (currentCopy.rotationQuaternion) {\n if (sp.rotationQuaternion) {\n sp.rotationQuaternion.copyFrom(currentCopy.rotationQuaternion);\n }\n else {\n sp.rotationQuaternion = currentCopy.rotationQuaternion.clone();\n }\n }\n if (currentCopy.color) {\n if (sp.color) {\n sp.color.copyFrom(currentCopy.color);\n }\n else {\n sp.color = currentCopy.color.clone();\n }\n }\n sp.scaling.copyFrom(currentCopy.scaling);\n sp.uvs.copyFrom(currentCopy.uvs);\n if (currentCopy.materialIndex !== null) {\n sp.materialIndex = currentCopy.materialIndex;\n }\n if (this.expandable) {\n this._idxOfId[sp.id] = sp.idx;\n }\n }\n if (!storage) {\n this._index += shape.length;\n this.nbParticles++;\n this._lastParticleId++;\n }\n return sp;\n }\n /**\n * Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.\n * This method calls `updateParticle()` for each particle of the SPS.\n * For an animated SPS, it is usually called within the render loop.\n * This methods does nothing if called on a non updatable or not yet built SPS. Example : buildMesh() not called after having added or removed particles from an expandable SPS.\n * @param start The particle index in the particle array where to start to compute the particle property values _(default 0)_\n * @param end The particle index in the particle array where to stop to compute the particle property values _(default nbParticle - 1)_\n * @param update If the mesh must be finally updated on this call after all the particle computations _(default true)_\n * @returns the SPS.\n */\n setParticles(start = 0, end = this.nbParticles - 1, update = true) {\n if (!this._updatable || this._isNotBuilt) {\n return this;\n }\n // custom beforeUpdate\n this.beforeUpdateParticles(start, end, update);\n const rotMatrix = TmpVectors.Matrix[0];\n const invertedMatrix = TmpVectors.Matrix[1];\n const mesh = this.mesh;\n const colors32 = this._colors32;\n const positions32 = this._positions32;\n const normals32 = this._normals32;\n const uvs32 = this._uvs32;\n const indices32 = this._indices32;\n const indices = this._indices;\n const fixedNormal32 = this._fixedNormal32;\n const depthSortParticles = this._depthSort && this._depthSortParticles;\n const tempVectors = TmpVectors.Vector3;\n const camAxisX = tempVectors[5].copyFromFloats(1.0, 0.0, 0.0);\n const camAxisY = tempVectors[6].copyFromFloats(0.0, 1.0, 0.0);\n const camAxisZ = tempVectors[7].copyFromFloats(0.0, 0.0, 1.0);\n const minimum = tempVectors[8].setAll(Number.MAX_VALUE);\n const maximum = tempVectors[9].setAll(-Number.MAX_VALUE);\n const camInvertedPosition = tempVectors[10].setAll(0);\n const tmpVertex = this._tmpVertex;\n const tmpVector = tmpVertex.position;\n const tmpColor = tmpVertex.color;\n const tmpUV = tmpVertex.uv;\n // cases when the World Matrix is to be computed first\n if (this.billboard || this._depthSort) {\n this.mesh.computeWorldMatrix(true);\n this.mesh._worldMatrix.invertToRef(invertedMatrix);\n }\n // if the particles will always face the camera\n if (this.billboard) {\n // compute the camera position and un-rotate it by the current mesh rotation\n const tmpVector0 = tempVectors[0];\n this._camera.getDirectionToRef(Axis.Z, tmpVector0);\n Vector3.TransformNormalToRef(tmpVector0, invertedMatrix, camAxisZ);\n camAxisZ.normalize();\n // same for camera up vector extracted from the cam view matrix\n const view = this._camera.getViewMatrix(true);\n Vector3.TransformNormalFromFloatsToRef(view.m[1], view.m[5], view.m[9], invertedMatrix, camAxisY);\n Vector3.CrossToRef(camAxisY, camAxisZ, camAxisX);\n camAxisY.normalize();\n camAxisX.normalize();\n }\n // if depthSort, compute the camera global position in the mesh local system\n if (this._depthSort) {\n Vector3.TransformCoordinatesToRef(this._camera.globalPosition, invertedMatrix, camInvertedPosition); // then un-rotate the camera\n }\n Matrix.IdentityToRef(rotMatrix);\n let idx = 0; // current position index in the global array positions32\n let index = 0; // position start index in the global array positions32 of the current particle\n let colidx = 0; // current color index in the global array colors32\n let colorIndex = 0; // color start index in the global array colors32 of the current particle\n let uvidx = 0; // current uv index in the global array uvs32\n let uvIndex = 0; // uv start index in the global array uvs32 of the current particle\n let pt = 0; // current index in the particle model shape\n if (this.mesh.isFacetDataEnabled) {\n this._computeBoundingBox = true;\n }\n end = end >= this.nbParticles ? this.nbParticles - 1 : end;\n if (this._computeBoundingBox) {\n if (start != 0 || end != this.nbParticles - 1) {\n // only some particles are updated, then use the current existing BBox basis. Note : it can only increase.\n const boundingInfo = this.mesh.getBoundingInfo();\n if (boundingInfo) {\n minimum.copyFrom(boundingInfo.minimum);\n maximum.copyFrom(boundingInfo.maximum);\n }\n }\n }\n // particle loop\n index = this.particles[start]._pos;\n const vpos = (index / 3) | 0;\n colorIndex = vpos * 4;\n uvIndex = vpos * 2;\n for (let p = start; p <= end; p++) {\n const particle = this.particles[p];\n // call to custom user function to update the particle properties\n this.updateParticle(particle);\n const shape = particle._model._shape;\n const shapeUV = particle._model._shapeUV;\n const particleRotationMatrix = particle._rotationMatrix;\n const particlePosition = particle.position;\n const particleRotation = particle.rotation;\n const particleScaling = particle.scaling;\n const particleGlobalPosition = particle._globalPosition;\n // camera-particle distance for depth sorting\n if (depthSortParticles) {\n const dsp = this.depthSortedParticles[p];\n dsp.idx = particle.idx;\n dsp.ind = particle._ind;\n dsp.indicesLength = particle._model._indicesLength;\n dsp.sqDistance = Vector3.DistanceSquared(particle.position, camInvertedPosition);\n }\n // skip the computations for inactive or already invisible particles\n if (!particle.alive || (particle._stillInvisible && !particle.isVisible && !this._recomputeInvisibles)) {\n // increment indexes for the next particle\n pt = shape.length;\n index += pt * 3;\n colorIndex += pt * 4;\n uvIndex += pt * 2;\n continue;\n }\n if (particle.isVisible) {\n particle._stillInvisible = false; // un-mark permanent invisibility\n const scaledPivot = tempVectors[12];\n particle.pivot.multiplyToRef(particleScaling, scaledPivot);\n // particle rotation matrix\n if (this.billboard) {\n particleRotation.x = 0.0;\n particleRotation.y = 0.0;\n }\n if (this._computeParticleRotation || this.billboard) {\n particle.getRotationMatrix(rotMatrix);\n }\n const particleHasParent = particle.parentId !== null;\n if (particleHasParent) {\n const parent = this.getParticleById(particle.parentId);\n if (parent) {\n const parentRotationMatrix = parent._rotationMatrix;\n const parentGlobalPosition = parent._globalPosition;\n const rotatedY = particlePosition.x * parentRotationMatrix[1] + particlePosition.y * parentRotationMatrix[4] + particlePosition.z * parentRotationMatrix[7];\n const rotatedX = particlePosition.x * parentRotationMatrix[0] + particlePosition.y * parentRotationMatrix[3] + particlePosition.z * parentRotationMatrix[6];\n const rotatedZ = particlePosition.x * parentRotationMatrix[2] + particlePosition.y * parentRotationMatrix[5] + particlePosition.z * parentRotationMatrix[8];\n particleGlobalPosition.x = parentGlobalPosition.x + rotatedX;\n particleGlobalPosition.y = parentGlobalPosition.y + rotatedY;\n particleGlobalPosition.z = parentGlobalPosition.z + rotatedZ;\n if (this._computeParticleRotation || this.billboard) {\n const rotMatrixValues = rotMatrix.m;\n particleRotationMatrix[0] =\n rotMatrixValues[0] * parentRotationMatrix[0] + rotMatrixValues[1] * parentRotationMatrix[3] + rotMatrixValues[2] * parentRotationMatrix[6];\n particleRotationMatrix[1] =\n rotMatrixValues[0] * parentRotationMatrix[1] + rotMatrixValues[1] * parentRotationMatrix[4] + rotMatrixValues[2] * parentRotationMatrix[7];\n particleRotationMatrix[2] =\n rotMatrixValues[0] * parentRotationMatrix[2] + rotMatrixValues[1] * parentRotationMatrix[5] + rotMatrixValues[2] * parentRotationMatrix[8];\n particleRotationMatrix[3] =\n rotMatrixValues[4] * parentRotationMatrix[0] + rotMatrixValues[5] * parentRotationMatrix[3] + rotMatrixValues[6] * parentRotationMatrix[6];\n particleRotationMatrix[4] =\n rotMatrixValues[4] * parentRotationMatrix[1] + rotMatrixValues[5] * parentRotationMatrix[4] + rotMatrixValues[6] * parentRotationMatrix[7];\n particleRotationMatrix[5] =\n rotMatrixValues[4] * parentRotationMatrix[2] + rotMatrixValues[5] * parentRotationMatrix[5] + rotMatrixValues[6] * parentRotationMatrix[8];\n particleRotationMatrix[6] =\n rotMatrixValues[8] * parentRotationMatrix[0] + rotMatrixValues[9] * parentRotationMatrix[3] + rotMatrixValues[10] * parentRotationMatrix[6];\n particleRotationMatrix[7] =\n rotMatrixValues[8] * parentRotationMatrix[1] + rotMatrixValues[9] * parentRotationMatrix[4] + rotMatrixValues[10] * parentRotationMatrix[7];\n particleRotationMatrix[8] =\n rotMatrixValues[8] * parentRotationMatrix[2] + rotMatrixValues[9] * parentRotationMatrix[5] + rotMatrixValues[10] * parentRotationMatrix[8];\n }\n }\n else {\n // in case the parent were removed at some moment\n particle.parentId = null;\n }\n }\n else {\n particleGlobalPosition.x = particlePosition.x;\n particleGlobalPosition.y = particlePosition.y;\n particleGlobalPosition.z = particlePosition.z;\n if (this._computeParticleRotation || this.billboard) {\n const rotMatrixValues = rotMatrix.m;\n particleRotationMatrix[0] = rotMatrixValues[0];\n particleRotationMatrix[1] = rotMatrixValues[1];\n particleRotationMatrix[2] = rotMatrixValues[2];\n particleRotationMatrix[3] = rotMatrixValues[4];\n particleRotationMatrix[4] = rotMatrixValues[5];\n particleRotationMatrix[5] = rotMatrixValues[6];\n particleRotationMatrix[6] = rotMatrixValues[8];\n particleRotationMatrix[7] = rotMatrixValues[9];\n particleRotationMatrix[8] = rotMatrixValues[10];\n }\n }\n const pivotBackTranslation = tempVectors[11];\n if (particle.translateFromPivot) {\n pivotBackTranslation.setAll(0.0);\n }\n else {\n pivotBackTranslation.copyFrom(scaledPivot);\n }\n // particle vertex loop\n for (pt = 0; pt < shape.length; pt++) {\n idx = index + pt * 3;\n colidx = colorIndex + pt * 4;\n uvidx = uvIndex + pt * 2;\n const iu = 2 * pt;\n const iv = iu + 1;\n tmpVector.copyFrom(shape[pt]);\n if (this._computeParticleColor && particle.color) {\n tmpColor.copyFrom(particle.color);\n }\n if (this._computeParticleTexture) {\n tmpUV.copyFromFloats(shapeUV[iu], shapeUV[iv]);\n }\n if (this._computeParticleVertex) {\n this.updateParticleVertex(particle, tmpVertex, pt);\n }\n // positions\n const vertexX = tmpVector.x * particleScaling.x - scaledPivot.x;\n const vertexY = tmpVector.y * particleScaling.y - scaledPivot.y;\n const vertexZ = tmpVector.z * particleScaling.z - scaledPivot.z;\n let rotatedX = vertexX * particleRotationMatrix[0] + vertexY * particleRotationMatrix[3] + vertexZ * particleRotationMatrix[6];\n let rotatedY = vertexX * particleRotationMatrix[1] + vertexY * particleRotationMatrix[4] + vertexZ * particleRotationMatrix[7];\n let rotatedZ = vertexX * particleRotationMatrix[2] + vertexY * particleRotationMatrix[5] + vertexZ * particleRotationMatrix[8];\n rotatedX += pivotBackTranslation.x;\n rotatedY += pivotBackTranslation.y;\n rotatedZ += pivotBackTranslation.z;\n const px = (positions32[idx] = particleGlobalPosition.x + camAxisX.x * rotatedX + camAxisY.x * rotatedY + camAxisZ.x * rotatedZ);\n const py = (positions32[idx + 1] = particleGlobalPosition.y + camAxisX.y * rotatedX + camAxisY.y * rotatedY + camAxisZ.y * rotatedZ);\n const pz = (positions32[idx + 2] = particleGlobalPosition.z + camAxisX.z * rotatedX + camAxisY.z * rotatedY + camAxisZ.z * rotatedZ);\n if (this._computeBoundingBox) {\n minimum.minimizeInPlaceFromFloats(px, py, pz);\n maximum.maximizeInPlaceFromFloats(px, py, pz);\n }\n // normals : if the particles can't be morphed then just rotate the normals, what is much more faster than ComputeNormals()\n if (!this._computeParticleVertex) {\n const normalx = fixedNormal32[idx];\n const normaly = fixedNormal32[idx + 1];\n const normalz = fixedNormal32[idx + 2];\n const rotatedx = normalx * particleRotationMatrix[0] + normaly * particleRotationMatrix[3] + normalz * particleRotationMatrix[6];\n const rotatedy = normalx * particleRotationMatrix[1] + normaly * particleRotationMatrix[4] + normalz * particleRotationMatrix[7];\n const rotatedz = normalx * particleRotationMatrix[2] + normaly * particleRotationMatrix[5] + normalz * particleRotationMatrix[8];\n normals32[idx] = camAxisX.x * rotatedx + camAxisY.x * rotatedy + camAxisZ.x * rotatedz;\n normals32[idx + 1] = camAxisX.y * rotatedx + camAxisY.y * rotatedy + camAxisZ.y * rotatedz;\n normals32[idx + 2] = camAxisX.z * rotatedx + camAxisY.z * rotatedy + camAxisZ.z * rotatedz;\n }\n if (this._computeParticleColor && particle.color) {\n const colors32 = this._colors32;\n colors32[colidx] = tmpColor.r;\n colors32[colidx + 1] = tmpColor.g;\n colors32[colidx + 2] = tmpColor.b;\n colors32[colidx + 3] = tmpColor.a;\n }\n if (this._computeParticleTexture) {\n const uvs = particle.uvs;\n uvs32[uvidx] = tmpUV.x * (uvs.z - uvs.x) + uvs.x;\n uvs32[uvidx + 1] = tmpUV.y * (uvs.w - uvs.y) + uvs.y;\n }\n }\n }\n // particle just set invisible : scaled to zero and positioned at the origin\n else {\n particle._stillInvisible = true; // mark the particle as invisible\n for (pt = 0; pt < shape.length; pt++) {\n idx = index + pt * 3;\n colidx = colorIndex + pt * 4;\n uvidx = uvIndex + pt * 2;\n positions32[idx] = positions32[idx + 1] = positions32[idx + 2] = 0;\n normals32[idx] = normals32[idx + 1] = normals32[idx + 2] = 0;\n if (this._computeParticleColor && particle.color) {\n const color = particle.color;\n colors32[colidx] = color.r;\n colors32[colidx + 1] = color.g;\n colors32[colidx + 2] = color.b;\n colors32[colidx + 3] = color.a;\n }\n if (this._computeParticleTexture) {\n const uvs = particle.uvs;\n uvs32[uvidx] = shapeUV[pt * 2] * (uvs.z - uvs.x) + uvs.x;\n uvs32[uvidx + 1] = shapeUV[pt * 2 + 1] * (uvs.w - uvs.y) + uvs.y;\n }\n }\n }\n // if the particle intersections must be computed : update the bbInfo\n if (this._particlesIntersect) {\n const bInfo = particle.getBoundingInfo();\n const bBox = bInfo.boundingBox;\n const bSphere = bInfo.boundingSphere;\n const modelBoundingInfo = particle._modelBoundingInfo;\n if (!this._bSphereOnly) {\n // place, scale and rotate the particle bbox within the SPS local system, then update it\n const modelBoundingInfoVectors = modelBoundingInfo.boundingBox.vectors;\n const tempMin = tempVectors[1];\n const tempMax = tempVectors[2];\n tempMin.setAll(Number.MAX_VALUE);\n tempMax.setAll(-Number.MAX_VALUE);\n for (let b = 0; b < 8; b++) {\n const scaledX = modelBoundingInfoVectors[b].x * particleScaling.x;\n const scaledY = modelBoundingInfoVectors[b].y * particleScaling.y;\n const scaledZ = modelBoundingInfoVectors[b].z * particleScaling.z;\n const rotatedX = scaledX * particleRotationMatrix[0] + scaledY * particleRotationMatrix[3] + scaledZ * particleRotationMatrix[6];\n const rotatedY = scaledX * particleRotationMatrix[1] + scaledY * particleRotationMatrix[4] + scaledZ * particleRotationMatrix[7];\n const rotatedZ = scaledX * particleRotationMatrix[2] + scaledY * particleRotationMatrix[5] + scaledZ * particleRotationMatrix[8];\n const x = particlePosition.x + camAxisX.x * rotatedX + camAxisY.x * rotatedY + camAxisZ.x * rotatedZ;\n const y = particlePosition.y + camAxisX.y * rotatedX + camAxisY.y * rotatedY + camAxisZ.y * rotatedZ;\n const z = particlePosition.z + camAxisX.z * rotatedX + camAxisY.z * rotatedY + camAxisZ.z * rotatedZ;\n tempMin.minimizeInPlaceFromFloats(x, y, z);\n tempMax.maximizeInPlaceFromFloats(x, y, z);\n }\n bBox.reConstruct(tempMin, tempMax, mesh._worldMatrix);\n }\n // place and scale the particle bouding sphere in the SPS local system, then update it\n const minBbox = modelBoundingInfo.minimum.multiplyToRef(particleScaling, tempVectors[1]);\n const maxBbox = modelBoundingInfo.maximum.multiplyToRef(particleScaling, tempVectors[2]);\n const bSphereCenter = maxBbox.addToRef(minBbox, tempVectors[3]).scaleInPlace(0.5).addInPlace(particleGlobalPosition);\n const halfDiag = maxBbox.subtractToRef(minBbox, tempVectors[4]).scaleInPlace(0.5 * this._bSphereRadiusFactor);\n const bSphereMinBbox = bSphereCenter.subtractToRef(halfDiag, tempVectors[1]);\n const bSphereMaxBbox = bSphereCenter.addToRef(halfDiag, tempVectors[2]);\n bSphere.reConstruct(bSphereMinBbox, bSphereMaxBbox, mesh._worldMatrix);\n }\n // increment indexes for the next particle\n index = idx + 3;\n colorIndex = colidx + 4;\n uvIndex = uvidx + 2;\n }\n // if the VBO must be updated\n if (update) {\n if (this._computeParticleColor) {\n const vb = mesh.getVertexBuffer(VertexBuffer.ColorKind);\n if (vb && !mesh.isPickable) {\n vb.updateDirectly(colors32, 0);\n }\n else {\n mesh.updateVerticesData(VertexBuffer.ColorKind, colors32, false, false);\n }\n }\n if (this._computeParticleTexture) {\n const vb = mesh.getVertexBuffer(VertexBuffer.UVKind);\n if (vb && !mesh.isPickable) {\n vb.updateDirectly(uvs32, 0);\n }\n else {\n mesh.updateVerticesData(VertexBuffer.UVKind, uvs32, false, false);\n }\n }\n const vbp = mesh.getVertexBuffer(VertexBuffer.PositionKind);\n if (vbp && !mesh.isPickable) {\n vbp.updateDirectly(positions32, 0);\n }\n else {\n mesh.updateVerticesData(VertexBuffer.PositionKind, positions32, false, false);\n }\n if (!mesh.areNormalsFrozen || mesh.isFacetDataEnabled) {\n if (this._computeParticleVertex || mesh.isFacetDataEnabled) {\n // recompute the normals only if the particles can be morphed, update then also the normal reference array _fixedNormal32[]\n const params = mesh.isFacetDataEnabled ? mesh.getFacetDataParameters() : null;\n VertexData.ComputeNormals(positions32, indices32, normals32, params);\n for (let i = 0; i < normals32.length; i++) {\n fixedNormal32[i] = normals32[i];\n }\n }\n if (!mesh.areNormalsFrozen) {\n const vb = mesh.getVertexBuffer(VertexBuffer.NormalKind);\n if (vb && !mesh.isPickable) {\n vb.updateDirectly(normals32, 0);\n }\n else {\n mesh.updateVerticesData(VertexBuffer.NormalKind, normals32, false, false);\n }\n }\n }\n if (depthSortParticles) {\n const depthSortedParticles = this.depthSortedParticles;\n depthSortedParticles.sort(this._depthSortFunction);\n const dspl = depthSortedParticles.length;\n let sid = 0;\n let faceId = 0;\n for (let sorted = 0; sorted < dspl; sorted++) {\n const sortedParticle = depthSortedParticles[sorted];\n const lind = sortedParticle.indicesLength;\n const sind = sortedParticle.ind;\n for (let i = 0; i < lind; i++) {\n indices32[sid] = indices[sind + i];\n sid++;\n if (this._pickable) {\n const f = i % 3;\n if (f == 0) {\n const pickedData = this.pickedParticles[faceId];\n pickedData.idx = sortedParticle.idx;\n pickedData.faceId = faceId;\n faceId++;\n }\n }\n }\n }\n }\n if (this._autoFixFaceOrientation) {\n let particleInd = 0;\n for (let particleIdx = 0; particleIdx < this.particles.length; particleIdx++) {\n const particle = depthSortParticles ? this.particles[this.depthSortedParticles[particleIdx].idx] : this.particles[particleIdx];\n const flipFaces = particle.scale.x * particle.scale.y * particle.scale.z < 0;\n if (flipFaces) {\n for (let faceInd = 0; faceInd < particle._model._indicesLength; faceInd += 3) {\n const tmp = indices[particle._ind + faceInd];\n indices32[particleInd + faceInd] = indices[particle._ind + faceInd + 1];\n indices32[particleInd + faceInd + 1] = tmp;\n }\n }\n particleInd += particle._model._indicesLength;\n }\n }\n if (depthSortParticles || this._autoFixFaceOrientation) {\n mesh.updateIndices(indices32);\n }\n }\n if (this._computeBoundingBox) {\n if (mesh.hasBoundingInfo) {\n mesh.getBoundingInfo().reConstruct(minimum, maximum, mesh._worldMatrix);\n }\n else {\n mesh.buildBoundingInfo(minimum, maximum, mesh._worldMatrix);\n }\n }\n if (this._autoUpdateSubMeshes) {\n this.computeSubMeshes();\n }\n this._recomputeInvisibles = false;\n this.afterUpdateParticles(start, end, update);\n return this;\n }\n /**\n * Disposes the SPS.\n */\n dispose() {\n this.mesh.dispose();\n this.vars = null;\n // drop references to internal big arrays for the GC\n this._positions = null;\n this._indices = null;\n this._normals = null;\n this._uvs = null;\n this._colors = null;\n this._indices32 = null;\n this._positions32 = null;\n this._normals32 = null;\n this._fixedNormal32 = null;\n this._uvs32 = null;\n this._colors32 = null;\n this.pickedParticles = null;\n this.pickedBySubMesh = null;\n this._materials = null;\n this._materialIndexes = null;\n this._indicesByMaterial = null;\n this._idxOfId = null;\n }\n /** Returns an object {idx: number faceId: number} for the picked particle from the passed pickingInfo object.\n * idx is the particle index in the SPS\n * faceId is the picked face index counted within this particle.\n * Returns null if the pickInfo can't identify a picked particle.\n * @param pickingInfo (PickingInfo object)\n * @returns {idx: number, faceId: number} or null\n */\n pickedParticle(pickingInfo) {\n if (pickingInfo.hit) {\n const subMesh = pickingInfo.subMeshId;\n const faceId = pickingInfo.faceId - this.mesh.subMeshes[subMesh].indexStart / 3;\n const picked = this.pickedBySubMesh;\n if (picked[subMesh] && picked[subMesh][faceId]) {\n return picked[subMesh][faceId];\n }\n }\n return null;\n }\n /**\n * Returns a SolidParticle object from its identifier : particle.id\n * @param id (integer) the particle Id\n * @returns the searched particle or null if not found in the SPS.\n */\n getParticleById(id) {\n const p = this.particles[id];\n if (p && p.id == id) {\n return p;\n }\n const particles = this.particles;\n const idx = this._idxOfId[id];\n if (idx !== undefined) {\n return particles[idx];\n }\n let i = 0;\n const nb = this.nbParticles;\n while (i < nb) {\n const particle = particles[i];\n if (particle.id == id) {\n return particle;\n }\n i++;\n }\n return null;\n }\n /**\n * Returns a new array populated with the particles having the passed shapeId.\n * @param shapeId (integer) the shape identifier\n * @returns a new solid particle array\n */\n getParticlesByShapeId(shapeId) {\n const ref = [];\n this.getParticlesByShapeIdToRef(shapeId, ref);\n return ref;\n }\n /**\n * Populates the passed array \"ref\" with the particles having the passed shapeId.\n * @param shapeId the shape identifier\n * @returns the SPS\n * @param ref\n */\n getParticlesByShapeIdToRef(shapeId, ref) {\n ref.length = 0;\n for (let i = 0; i < this.nbParticles; i++) {\n const p = this.particles[i];\n if (p.shapeId == shapeId) {\n ref.push(p);\n }\n }\n return this;\n }\n /**\n * Computes the required SubMeshes according the materials assigned to the particles.\n * @returns the solid particle system.\n * Does nothing if called before the SPS mesh is built.\n */\n computeSubMeshes() {\n if (!this.mesh || !this._multimaterialEnabled) {\n return this;\n }\n const depthSortedParticles = this.depthSortedParticles;\n if (this.particles.length > 0) {\n for (let p = 0; p < this.particles.length; p++) {\n const part = this.particles[p];\n if (!part.materialIndex) {\n part.materialIndex = 0;\n }\n const sortedPart = depthSortedParticles[p];\n sortedPart.materialIndex = part.materialIndex;\n sortedPart.ind = part._ind;\n sortedPart.indicesLength = part._model._indicesLength;\n sortedPart.idx = part.idx;\n }\n }\n this._sortParticlesByMaterial();\n const indicesByMaterial = this._indicesByMaterial;\n const materialIndexes = this._materialIndexes;\n const mesh = this.mesh;\n mesh.subMeshes = [];\n const vcount = mesh.getTotalVertices();\n for (let m = 0; m < materialIndexes.length; m++) {\n const start = indicesByMaterial[m];\n const count = indicesByMaterial[m + 1] - start;\n const matIndex = materialIndexes[m];\n new SubMesh(matIndex, 0, vcount, start, count, mesh);\n }\n return this;\n }\n /**\n * Sorts the solid particles by material when MultiMaterial is enabled.\n * Updates the indices32 array.\n * Updates the indicesByMaterial array.\n * Updates the mesh indices array.\n * @returns the SPS\n * @internal\n */\n _sortParticlesByMaterial() {\n const indicesByMaterial = [0];\n this._indicesByMaterial = indicesByMaterial;\n const materialIndexes = [];\n this._materialIndexes = materialIndexes;\n const depthSortedParticles = this.depthSortedParticles;\n depthSortedParticles.sort(this._materialSortFunction);\n const length = depthSortedParticles.length;\n const indices32 = this._indices32;\n const indices = this._indices;\n let subMeshIndex = 0;\n let subMeshFaceId = 0;\n let sid = 0;\n let lastMatIndex = depthSortedParticles[0].materialIndex;\n materialIndexes.push(lastMatIndex);\n if (this._pickable) {\n this.pickedBySubMesh = [[]];\n this.pickedParticles = this.pickedBySubMesh[0];\n }\n for (let sorted = 0; sorted < length; sorted++) {\n const sortedPart = depthSortedParticles[sorted];\n const lind = sortedPart.indicesLength;\n const sind = sortedPart.ind;\n if (sortedPart.materialIndex !== lastMatIndex) {\n lastMatIndex = sortedPart.materialIndex;\n indicesByMaterial.push(sid);\n materialIndexes.push(lastMatIndex);\n if (this._pickable) {\n subMeshIndex++;\n this.pickedBySubMesh[subMeshIndex] = [];\n subMeshFaceId = 0;\n }\n }\n let faceId = 0;\n for (let i = 0; i < lind; i++) {\n indices32[sid] = indices[sind + i];\n if (this._pickable) {\n const f = i % 3;\n if (f == 0) {\n const pickedData = this.pickedBySubMesh[subMeshIndex][subMeshFaceId];\n if (pickedData) {\n pickedData.idx = sortedPart.idx;\n pickedData.faceId = faceId;\n }\n else {\n this.pickedBySubMesh[subMeshIndex][subMeshFaceId] = { idx: sortedPart.idx, faceId: faceId };\n }\n subMeshFaceId++;\n faceId++;\n }\n }\n sid++;\n }\n }\n indicesByMaterial.push(indices32.length); // add the last number to ease the indices start/count values for subMeshes creation\n if (this._updatable) {\n this.mesh.updateIndices(indices32);\n }\n return this;\n }\n /**\n * Sets the material indexes by id materialIndexesById[id] = materialIndex\n * @internal\n */\n _setMaterialIndexesById() {\n this._materialIndexesById = {};\n for (let i = 0; i < this._materials.length; i++) {\n const id = this._materials[i].uniqueId;\n this._materialIndexesById[id] = i;\n }\n }\n /**\n * Returns an array with unique values of Materials from the passed array\n * @param array the material array to be checked and filtered\n * @internal\n */\n _filterUniqueMaterialId(array) {\n const filtered = array.filter(function (value, index, self) {\n return self.indexOf(value) === index;\n });\n return filtered;\n }\n /**\n * Sets a new Standard Material as _defaultMaterial if not already set.\n * @internal\n */\n _setDefaultMaterial() {\n if (!this._defaultMaterial) {\n this._defaultMaterial = new StandardMaterial(this.name + \"DefaultMaterial\", this._scene);\n }\n return this._defaultMaterial;\n }\n /**\n * Visibility helper : Recomputes the visible size according to the mesh bounding box\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\n * @returns the SPS.\n */\n refreshVisibleSize() {\n if (!this._isVisibilityBoxLocked) {\n this.mesh.refreshBoundingInfo();\n }\n return this;\n }\n /**\n * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.\n * @param size the size (float) of the visibility box\n * note : this doesn't lock the SPS mesh bounding box.\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\n */\n setVisibilityBox(size) {\n const vis = size / 2;\n this.mesh.buildBoundingInfo(new Vector3(-vis, -vis, -vis), new Vector3(vis, vis, vis));\n }\n /**\n * Gets whether the SPS as always visible or not\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\n */\n get isAlwaysVisible() {\n return this._alwaysVisible;\n }\n /**\n * Sets the SPS as always visible or not\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\n */\n set isAlwaysVisible(val) {\n this._alwaysVisible = val;\n this.mesh.alwaysSelectAsActiveMesh = val;\n }\n /**\n * Sets the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\n */\n set isVisibilityBoxLocked(val) {\n this._isVisibilityBoxLocked = val;\n const boundingInfo = this.mesh.getBoundingInfo();\n boundingInfo.isLocked = val;\n }\n /**\n * Gets if the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\n */\n get isVisibilityBoxLocked() {\n return this._isVisibilityBoxLocked;\n }\n /**\n * Tells to `setParticles()` to compute the particle rotations or not.\n * Default value : true. The SPS is faster when it's set to false.\n * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.\n */\n set computeParticleRotation(val) {\n this._computeParticleRotation = val;\n }\n /**\n * Tells to `setParticles()` to compute the particle colors or not.\n * Default value : true. The SPS is faster when it's set to false.\n * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.\n */\n set computeParticleColor(val) {\n this._computeParticleColor = val;\n }\n set computeParticleTexture(val) {\n this._computeParticleTexture = val;\n }\n /**\n * Tells to `setParticles()` to call the vertex function for each vertex of each particle, or not.\n * Default value : false. The SPS is faster when it's set to false.\n * Note : the particle custom vertex positions aren't stored values.\n */\n set computeParticleVertex(val) {\n this._computeParticleVertex = val;\n }\n /**\n * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.\n */\n set computeBoundingBox(val) {\n this._computeBoundingBox = val;\n }\n /**\n * Tells to `setParticles()` to sort or not the distance between each particle and the camera.\n * Skipped when `enableDepthSort` is set to `false` (default) at construction time.\n * Default : `true`\n */\n set depthSortParticles(val) {\n this._depthSortParticles = val;\n }\n /**\n * Gets if `setParticles()` computes the particle rotations or not.\n * Default value : true. The SPS is faster when it's set to false.\n * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.\n */\n get computeParticleRotation() {\n return this._computeParticleRotation;\n }\n /**\n * Gets if `setParticles()` computes the particle colors or not.\n * Default value : true. The SPS is faster when it's set to false.\n * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.\n */\n get computeParticleColor() {\n return this._computeParticleColor;\n }\n /**\n * Gets if `setParticles()` computes the particle textures or not.\n * Default value : true. The SPS is faster when it's set to false.\n * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.\n */\n get computeParticleTexture() {\n return this._computeParticleTexture;\n }\n /**\n * Gets if `setParticles()` calls the vertex function for each vertex of each particle, or not.\n * Default value : false. The SPS is faster when it's set to false.\n * Note : the particle custom vertex positions aren't stored values.\n */\n get computeParticleVertex() {\n return this._computeParticleVertex;\n }\n /**\n * Gets if `setParticles()` computes or not the mesh bounding box when computing the particle positions.\n */\n get computeBoundingBox() {\n return this._computeBoundingBox;\n }\n /**\n * Gets if `setParticles()` sorts or not the distance between each particle and the camera.\n * Skipped when `enableDepthSort` is set to `false` (default) at construction time.\n * Default : `true`\n */\n get depthSortParticles() {\n return this._depthSortParticles;\n }\n /**\n * Gets if the SPS is created as expandable at construction time.\n * Default : `false`\n */\n get expandable() {\n return this._expandable;\n }\n /**\n * Gets if the SPS supports the Multi Materials\n */\n get multimaterialEnabled() {\n return this._multimaterialEnabled;\n }\n /**\n * Gets if the SPS uses the model materials for its own multimaterial.\n */\n get useModelMaterial() {\n return this._useModelMaterial;\n }\n /**\n * The SPS used material array.\n */\n get materials() {\n return this._materials;\n }\n /**\n * Sets the SPS MultiMaterial from the passed materials.\n * Note : the passed array is internally copied and not used then by reference.\n * @param materials an array of material objects. This array indexes are the materialIndex values of the particles.\n */\n setMultiMaterial(materials) {\n this._materials = this._filterUniqueMaterialId(materials);\n this._setMaterialIndexesById();\n if (this._multimaterial) {\n this._multimaterial.dispose();\n }\n this._multimaterial = new MultiMaterial(this.name + \"MultiMaterial\", this._scene);\n for (let m = 0; m < this._materials.length; m++) {\n this._multimaterial.subMaterials.push(this._materials[m]);\n }\n this.computeSubMeshes();\n this.mesh.material = this._multimaterial;\n }\n /**\n * The SPS computed multimaterial object\n */\n get multimaterial() {\n return this._multimaterial;\n }\n set multimaterial(mm) {\n this._multimaterial = mm;\n }\n /**\n * If the subMeshes must be updated on the next call to setParticles()\n */\n get autoUpdateSubMeshes() {\n return this._autoUpdateSubMeshes;\n }\n set autoUpdateSubMeshes(val) {\n this._autoUpdateSubMeshes = val;\n }\n // =======================================================================\n // Particle behavior logic\n // these following methods may be overwritten by the user to fit his needs\n /**\n * This function does nothing. It may be overwritten to set all the particle first values.\n * The SPS doesn't call this function, you may have to call it by your own.\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles\n */\n initParticles() { }\n /**\n * This function does nothing. It may be overwritten to recycle a particle.\n * The SPS doesn't call this function, you may have to call it by your own.\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles\n * @param particle The particle to recycle\n * @returns the recycled particle\n */\n recycleParticle(particle) {\n return particle;\n }\n /**\n * Updates a particle : this function should be overwritten by the user.\n * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles\n * @example : just set a particle position or velocity and recycle conditions\n * @param particle The particle to update\n * @returns the updated particle\n */\n updateParticle(particle) {\n return particle;\n }\n /**\n * Updates a vertex of a particle : it can be overwritten by the user.\n * This will be called on each vertex particle by `setParticles()` if `computeParticleVertex` is set to true only.\n * @param particle the current particle\n * @param vertex the current vertex of the current particle : a SolidParticleVertex object\n * @param pt the index of the current vertex in the particle shape\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_vertices\n * @example : just set a vertex particle position or color\n * @returns the sps\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n updateParticleVertex(particle, vertex, pt) {\n return this;\n }\n /**\n * This will be called before any other treatment by `setParticles()` and will be passed three parameters.\n * This does nothing and may be overwritten by the user.\n * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\n * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\n * @param update the boolean update value actually passed to setParticles()\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n beforeUpdateParticles(start, stop, update) { }\n /**\n * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.\n * This will be passed three parameters.\n * This does nothing and may be overwritten by the user.\n * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\n * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\n * @param update the boolean update value actually passed to setParticles()\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n afterUpdateParticles(start, stop, update) { }\n }\n\n /** This will mutate the mesh geometry. Only use this on temp/intermediate mesh data */\n function ensureNormalsExist(mesh) {\n if (!mesh.getVerticesData(VertexBuffer.NormalKind)) {\n mesh.createNormals(true);\n mesh.convertToFlatShadedMesh();\n }\n }\n\n const patternStore = new Map();\n const identityRotation = Quaternion.Identity();\n class PatternRenderer extends FeatureRenderer {\n update3dInternal() { }\n updateMeshGeometry(feature, vertexData, vertexDataChanges, setParticlePositionFunc) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const meshNode = feature._parent;\n const mesh = this.viewer.getRendererNode(meshNode);\n if (mesh) {\n /** See line 156 */\n // let _pattern = patternStore.get(meshNode._dynamicId);\n let _pattern = null;\n // If there are no enabled pattern features before this one, update the pattern shape as some geometry may have changed\n if (!_pattern) {\n const meshUpdated = new Mesh('patternTempGeometry');\n meshUpdated.setEnabled(false);\n const tempVertexData = new SubmeshVertexData();\n tempVertexData.copyFrom(newVertexData);\n tempVertexData.applyToMesh(meshUpdated, false);\n ensureNormalsExist(meshUpdated);\n const sps = new SolidParticleSystem(`${mesh.id}_${feature._dynamicId}`, this.scene, {\n enableDepthSort: true,\n enableMultiMaterial: true,\n expandable: true,\n });\n if (feature) {\n if (feature.meshId) {\n const sketchNode = this.viewer.getNode(feature.meshId);\n if (sketchNode instanceof exports.SketchNode) {\n let distance = feature.distance;\n if (distance <= 0) {\n distance = 1;\n }\n const positionArray = this.getPositionArray(sketchNode, feature.distance, feature.addEndMesh);\n sps.addShape(meshUpdated, positionArray.length);\n sps.counter = positionArray.length;\n feature.count = positionArray.length;\n const sketchPosition = sketchNode.position.toVec3();\n sps.initParticles = () => {\n for (let p = 0; p < sps.counter; p++) {\n const particle = sps.particles[p];\n particle.position = positionArray[p].add(sketchPosition);\n }\n };\n }\n }\n else {\n sps.addShape(meshUpdated, feature.count + 1);\n sps.initParticles = () => {\n for (let p = 0; p < sps.nbParticles; p++) {\n const particle = sps.particles[p];\n if (particle.rotationQuaternion) {\n particle.rotationQuaternion.copyFrom(identityRotation);\n }\n else {\n particle.rotationQuaternion = Quaternion.Identity();\n }\n particle.position.setAll(0);\n }\n };\n }\n }\n const newPattern = {\n sps,\n size: 1,\n featureUpdaters: new Map(),\n sourceNode: meshNode,\n needsUpdate: true,\n needsRebuild: true,\n needsSubmeshRebuild: true,\n shape: meshUpdated,\n };\n sps.updateParticle = particle => {\n // Process the last update function as it will call the prior ones recursively\n const updates = newPattern.featureUpdaters.values();\n const update = updates.next().value;\n update(particle, updates);\n // Do we need this?\n // particle.scaling.copyFrom(mesh.scaling);\n return particle;\n };\n patternStore.set(meshNode._dynamicId, newPattern);\n _pattern = newPattern;\n }\n const pattern = _pattern;\n pattern.needsUpdate = true;\n pattern.featureUpdaters.set(feature._dynamicId, (particle, iterator, index) => {\n if (feature.enabled) {\n const particleIndex = particle.idx;\n if (particleIndex >= pattern.size) {\n particle.isVisible = false;\n return;\n }\n if (!particle.isVisible) {\n particle.isVisible = true;\n }\n const featureItemIndex = index !== undefined ? index : particleIndex;\n const i = featureItemIndex % feature.count;\n if (i > 0 && setParticlePositionFunc) {\n setParticlePositionFunc(i, particle);\n }\n const nextUpdateFunction = iterator.next().value;\n if (nextUpdateFunction) {\n nextUpdateFunction(particle, iterator, Math.floor(featureItemIndex / feature.count));\n }\n }\n });\n pattern.size = Array.from(pattern.featureUpdaters.keys()).reduce((result, featureId) => {\n const feature = meshNode.features.find(feature => feature._dynamicId === featureId);\n return result * feature.count;\n }, 1);\n if (!pattern.needsRebuild &&\n (vertexDataChanges.indices || vertexDataChanges.positions || vertexDataChanges.uvs)) {\n /**\n * If the shape of the mesh changed, then we have to remove and re-add every particle to recompute the geometry.\n * Potential optimization here is to only recompute vertex positions if the vertex count is the same,\n * and only do the following expensive operation if the vertex count (indices?) changes.\n */\n const currentSize = pattern.sps.nbParticles;\n pattern.sps.addShape(pattern.shape, Math.max(pattern.size, pattern.sps.nbParticles));\n pattern.sps.removeParticles(0, currentSize - 1);\n pattern.needsRebuild = true;\n }\n else if (pattern.sps.nbParticles < pattern.size) {\n // If we don't have enough particles to complete the pattern, expand the SPS as needed\n pattern.sps.addShape(pattern.shape, pattern.size - pattern.sps.nbParticles);\n pattern.needsRebuild = true;\n }\n if (vertexDataChanges.submeshData) {\n pattern.needsSubmeshRebuild = true;\n }\n /**\n * We are removing the pattern feature combination system because it was causing a lot of issues around the cache, with enabling/disabling and reordering features.\n * In the future we will just add multi-direction properties into the pattern feature instead.\n */\n // const nextFeature = meshNode.features[thisIndex + 1];\n // if (!nextFeature || !(nextFeature instanceof PatternFeature)) {\n this.processParticleSystem(pattern, newVertexData); // mutates newVertexData\n patternStore.delete(meshNode._dynamicId); // Delete the pattern since we are done processing it\n // }\n }\n return newVertexData;\n }\n processParticleSystem(pattern, resultVertexData) {\n if (!pattern.needsUpdate) {\n return;\n }\n // Shrink the particle system if there are way too many particles (more than 50% too many)\n // We don't want to shrink unless necessary beca use there's a performance hit to rebuilding the mesh\n if (pattern.sps.nbParticles - pattern.size > pattern.size / 2) {\n pattern.sps.removeParticles(pattern.size, pattern.sps.nbParticles - 1);\n pattern.needsRebuild = true;\n }\n pattern.sps.initParticles();\n if (!pattern.resultMesh || pattern.needsRebuild) {\n pattern.resultMesh = pattern.sps.buildMesh();\n pattern.needsRebuild = false;\n pattern.needsSubmeshRebuild = true;\n pattern.resultMesh.setEnabled(false);\n }\n pattern.sps.computeBoundingBox = true;\n pattern.sps.setParticles();\n const totalIndicesSourceCount = resultVertexData.indices.length;\n const totalVerticesSourceCount = resultVertexData.positions.length / 3;\n const newVertexData = VertexData.ExtractFromMesh(pattern.resultMesh);\n resultVertexData.indices = newVertexData.indices;\n resultVertexData.positions = newVertexData.positions;\n if (newVertexData.normals) {\n resultVertexData.normals = newVertexData.normals;\n }\n if (resultVertexData.uvs && newVertexData.uvs) {\n // Don't add UVs if UVs never existed\n resultVertexData.uvs = newVertexData.uvs;\n }\n // If the source mesh has submeshes, then we need to update them\n if (resultVertexData.submeshData) {\n const submeshesToClone = resultVertexData.submeshData.slice(1);\n const totalIndicesResultCount = resultVertexData.indices.length;\n const totalVerticesResultCount = resultVertexData.positions.length / 3;\n // resultMeshCsg.dispose();\n const baseMaterialIndex = resultVertexData.submeshData[0].materialIndex;\n resultVertexData.submeshData = [];\n resultVertexData.submeshData.push({\n materialIndex: baseMaterialIndex,\n verticesStart: 0,\n verticesCount: totalVerticesResultCount,\n indexStart: 0,\n indexCount: totalIndicesResultCount,\n });\n const spsPatternSize = totalVerticesResultCount / totalVerticesSourceCount;\n if (submeshesToClone.length > 0) {\n submeshesToClone.forEach(subMesh => {\n for (let i = 0; i < spsPatternSize; i++) {\n resultVertexData.submeshData.push({\n materialIndex: subMesh.materialIndex,\n verticesStart: subMesh.verticesStart + i * totalVerticesSourceCount,\n verticesCount: subMesh.verticesCount,\n indexStart: subMesh.indexStart + i * totalIndicesSourceCount,\n indexCount: subMesh.indexCount,\n });\n }\n });\n }\n }\n }\n getPositionArray(node, distance, addEndMesh) {\n const result = [];\n const sketchLength = node.getSketchLength();\n const numberOfMeshes = sketchLength / distance;\n const percentagePoints = [];\n for (let i = 0; i < numberOfMeshes; i++) {\n percentagePoints.push((1 / numberOfMeshes) * i);\n }\n percentagePoints.forEach(point => {\n result.push(this.getIntervalPosition(node, point));\n });\n if (addEndMesh) {\n const lastPath = node.paths[node.paths.length - 1];\n const lastPoint = lastPath._points[lastPath._points.length - 1];\n const lastPointVec3 = new Vector3(lastPoint.x, lastPoint.y, lastPoint.z);\n result.push(lastPointVec3);\n }\n return result;\n }\n getIntervalPosition(node, posZeroToOne) {\n const result = new Vector3(0, 0, 0);\n const sketchLength = node.getSketchLength();\n let trackedLength = 0;\n let targetNotFound = true;\n node.paths.forEach(path => {\n let lastPosition = null;\n let lastLength = 0;\n path._points.forEach(point => {\n if (!lastPosition) {\n lastPosition = point;\n }\n else {\n const currentPos = point;\n const distance = Math.sqrt(Math.pow(lastPosition.x - currentPos.x, 2) +\n Math.pow(lastPosition.y - currentPos.y, 2) +\n Math.pow(lastPosition.z - currentPos.z, 2));\n lastLength = trackedLength;\n trackedLength += distance;\n const distanceBetweenPoints = trackedLength - lastLength;\n const distanceFromP1toTarget = posZeroToOne * sketchLength - lastLength;\n const percentageBetween2Points = distanceFromP1toTarget / distanceBetweenPoints;\n const vectorBetween2Points = new exports.KbVector(currentPos.x - lastPosition.x, currentPos.y - lastPosition.y, currentPos.z - lastPosition.z);\n if (trackedLength > posZeroToOne * sketchLength && targetNotFound) {\n const calculatedPosition = vectorBetween2Points\n .scale(percentageBetween2Points)\n .add(lastPosition);\n result.set(calculatedPosition.x, calculatedPosition.y, calculatedPosition.z);\n targetNotFound = false;\n }\n lastPosition = currentPos;\n }\n });\n if (posZeroToOne === 1) {\n const path = node.paths[node.paths.length - 1];\n const controlPoint = path._points[path._points.length - 1];\n result.set(controlPoint.x, controlPoint.y, controlPoint.z);\n }\n });\n return result;\n }\n delete3d(feature, preserveCache) {\n patternStore.forEach((pattern, meshNode) => {\n if (pattern.featureUpdaters.has(feature._dynamicId)) {\n pattern.featureUpdaters.delete(feature._dynamicId);\n }\n if (pattern.featureUpdaters.size === 0) {\n patternStore.delete(meshNode);\n }\n });\n super.delete3d(feature, preserveCache);\n }\n dispose() {\n super.dispose();\n patternStore.clear();\n }\n }\n\n const uvHelper = new UVMapHelper();\n const multiMaterialUseCount = new Map();\n const featureMappings = new Map();\n class SubmeshRenderer extends FeatureRenderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene);\n this.rendererManager = rendererManager;\n this.modelToken = Token.SubmeshFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const submeshFeatureMapping = featureMappings.get(feature._dynamicId);\n if (!submeshFeatureMapping) {\n console.warn(`INFO: Submesh mapping not found for ${feature.name}`);\n return newVertexData;\n }\n if (!newVertexData.submeshData) {\n newVertexData.submeshData = [];\n }\n if (submeshFeatureMapping.multiMaterialIndex) {\n const verticesCount = (vertexDataChanges.positions || newVertexData.positions).length / 3;\n const indicesCount = (vertexDataChanges.indices || newVertexData.indices).length;\n for (let i = 0; i < feature.vertexGroups.length; i++) {\n const vertexGroup = feature.vertexGroups[i];\n const newSubmesh = {\n materialIndex: submeshFeatureMapping.multiMaterialIndex,\n verticesStart: 0,\n verticesCount: verticesCount,\n indexStart: vertexGroup.startIndex,\n indexCount: Math.min(vertexGroup.endIndex, indicesCount) - vertexGroup.startIndex,\n };\n const existingIndex = newVertexData.submeshData.findIndex(existingSubmesh => existingSubmesh.materialIndex === newSubmesh.materialIndex &&\n existingSubmesh.verticesStart === newSubmesh.verticesStart &&\n existingSubmesh.verticesCount === newSubmesh.verticesCount &&\n existingSubmesh.indexStart === newSubmesh.indexStart &&\n existingSubmesh.indexCount === newSubmesh.indexCount);\n if (existingIndex >= 0) {\n newVertexData.submeshData.splice(existingIndex, 1);\n }\n newVertexData.submeshData.push(newSubmesh);\n }\n }\n // Calculate UV maps if that is enabled on this feature\n if (feature.uvMapping) {\n const uvMapVertexes = [];\n for (let i = 0; i < feature.vertexGroups.length; i++) {\n const vertexGroup = feature.vertexGroups[i];\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\n uvMapVertexes.push(i);\n }\n }\n if (uvMapVertexes.length > 0) {\n let existingUvs = [];\n if (newVertexData.uvs) {\n existingUvs = [...newVertexData.uvs];\n }\n uvHelper.generateUVMapInPlace(newVertexData, feature, uvMapVertexes);\n // for projection mode \"use existing\", only apply the new uvs to the selected faces of the submesh\n if (feature.mode === exports.eUvMode.useExisting) {\n feature.vertexGroups.forEach(vertexGroup => {\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\n if (newVertexData.indices && newVertexData.uvs) {\n existingUvs[newVertexData.indices[i] * 2] =\n newVertexData.uvs[newVertexData.indices[i] * 2];\n existingUvs[newVertexData.indices[i] * 2 + 1] =\n newVertexData.uvs[newVertexData.indices[i] * 2 + 1];\n }\n }\n });\n newVertexData.uvs = existingUvs;\n }\n }\n }\n return newVertexData;\n }\n update3dInternal(feature) {\n let _submeshFeatureMapping = featureMappings.get(feature._dynamicId);\n if (feature.changes.has('materialId') || !_submeshFeatureMapping) {\n const meshNode = feature._parent;\n const mesh = this.viewer.getRendererNode(meshNode);\n if (!mesh) {\n return;\n }\n if (!_submeshFeatureMapping) {\n _submeshFeatureMapping = {};\n featureMappings.set(feature._dynamicId, _submeshFeatureMapping);\n }\n const submeshFeatureMapping = _submeshFeatureMapping;\n if (feature.materialId) {\n if (!(mesh.material instanceof MultiMaterial)) {\n const multiMaterial = new MultiMaterial(meshNode._dynamicId, this.scene);\n if (mesh.material) {\n multiMaterial.subMaterials[0] = mesh.material;\n }\n else if (!mesh.material) {\n // If a submesh multimaterial has a null material at index 0, it causes shadows to not work\n multiMaterial.subMaterials[0] = this.rendererManager.material.defaultMaterial;\n }\n submeshFeatureMapping.multiMaterial = multiMaterial;\n multiMaterialUseCount.set(multiMaterial, 0);\n mesh.material = multiMaterial;\n }\n else {\n submeshFeatureMapping.multiMaterial = mesh.material;\n }\n this.rendererManager.mesh.fetchMaterialNode(meshNode, feature.materialId).then(materialNode => {\n // The material may have changed on the mesh, so we have to re-fetch the reference just in case.\n if (!(mesh.material instanceof MultiMaterial)) {\n throw Error('Another script has removed the multimaterial on a mesh');\n }\n const multiMaterial = mesh.material;\n if (multiMaterial !== submeshFeatureMapping.multiMaterial) {\n console.warn(`Submesh feature ${feature.name} lost reference to a multimaterial. Possible memory leak?`);\n submeshFeatureMapping.multiMaterial = multiMaterial;\n }\n // If the material is already part of the submaterials, do nothing\n const existingSubmaterialIndex = multiMaterial.subMaterials.findIndex(material => (material === null || material === void 0 ? void 0 : material.id) === materialNode._dynamicId);\n if ((submeshFeatureMapping === null || submeshFeatureMapping === void 0 ? void 0 : submeshFeatureMapping.multiMaterialIndex) === existingSubmaterialIndex) {\n return;\n }\n else if (existingSubmaterialIndex > -1) {\n submeshFeatureMapping.multiMaterialIndex = existingSubmaterialIndex;\n // Triggers change on this feature so the feature stack refreshes with the material index on this submesh\n feature.setPropertyIsModified('vertexGroups', true);\n }\n else {\n // init the material if the node is showing\n if (meshNode.visible) {\n materialNode.init();\n }\n const material = this.viewer.getRendererNode(materialNode);\n if (!material) {\n throw Error('Material could not be found in renderer. Has the material been created?');\n }\n submeshFeatureMapping.multiMaterialIndex = multiMaterial.subMaterials.length;\n multiMaterial.subMaterials.push(material);\n multiMaterialUseCount.set(multiMaterial, (multiMaterialUseCount.get(multiMaterial) || 0) + 1);\n // Triggers change on this feature so the feature stack refreshes with the material index on this submesh\n feature.setPropertyIsModified('vertexGroups', true);\n }\n }, err => {\n feature.materialId = '';\n });\n }\n }\n }\n delete3d(feature, preserveCache) {\n if (!preserveCache) {\n const submeshFeatureMapping = featureMappings.get(feature._dynamicId);\n if (submeshFeatureMapping && submeshFeatureMapping.multiMaterial) {\n const multiMaterial = submeshFeatureMapping.multiMaterial;\n const count = multiMaterialUseCount.get(multiMaterial);\n if (count !== undefined) {\n if (count <= 1) {\n const meshNode = feature._parent;\n const mesh = this.viewer.getRendererNode(meshNode);\n if (mesh) {\n mesh.material = multiMaterial.getSubMaterial(0);\n }\n multiMaterialUseCount.delete(multiMaterial);\n multiMaterial.dispose(true, true, false);\n }\n else {\n multiMaterialUseCount.set(multiMaterial, count - 1);\n }\n }\n }\n featureMappings.delete(feature._dynamicId);\n }\n super.delete3d(feature, preserveCache);\n }\n }\n\n const uvHelper$1 = new UVMapHelper();\n class UvMapRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.UvMapFeature;\n this.babylonUvPreviewsMap = new Map();\n this.previewLayer = this.viewer.utilityLayer;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n uvHelper$1.generateUVMapInPlace(newVertexData, feature);\n return newVertexData;\n }\n updatePreviewMesh(feature) {\n let visualizationMesh = this.babylonUvPreviewsMap.get(feature.id);\n const scene = this.previewLayer.utilityLayerScene;\n if (!visualizationMesh) {\n visualizationMesh = createUvMapVisualization(feature, scene, Color3.Yellow());\n visualizationMesh.isPickable = false;\n this.babylonUvPreviewsMap.set(feature.id, visualizationMesh);\n }\n else {\n this.deletePreview3d(feature);\n visualizationMesh = createUvMapVisualization(feature, scene, Color3.Yellow());\n visualizationMesh.isPickable = false;\n this.babylonUvPreviewsMap.set(feature.id, visualizationMesh);\n }\n let meshPosition = visualizationMesh.getAbsolutePosition();\n if (feature._parent) {\n const featureParent = this.viewer.getRendererNode(feature._parent);\n meshPosition = featureParent.getAbsolutePosition();\n }\n meshPosition.add(feature.center.toVec3());\n meshPosition.addInPlace(feature.center.toVec3());\n visualizationMesh.position.set(meshPosition.x, meshPosition.y, meshPosition.z);\n //visualizationMesh.project;\n const newNormal = new Vector3();\n newNormal.set(feature.projectionAxis.x, feature.projectionAxis.y, feature.projectionAxis.z);\n visualizationMesh.rotationQuaternion = Quaternion.RotationAxis(newNormal, (feature.angle / 180) * Math.PI);\n visualizationMesh.rotationQuaternion = visualizationMesh.rotationQuaternion.multiply(rotationToVector(newNormal));\n visualizationMesh.scaling.set(feature.scale.x, feature.scale.y, feature.scale.z);\n }\n update3dInternal(feature) {\n const visualizationMesh = this.babylonUvPreviewsMap.get(feature.id);\n visualizationMesh === null || visualizationMesh === void 0 ? void 0 : visualizationMesh.setEnabled(feature._previewMaterialVisible);\n // change visibility here\n if (feature._previewMaterialVisible) {\n this.updatePreviewMesh(feature);\n }\n }\n delete3d(feature) {\n this.deletePreview3d(feature);\n super.delete3d(feature);\n }\n deletePreview3d(feature) {\n const previewMesh = this.babylonUvPreviewsMap.get(feature.id);\n if (previewMesh) {\n previewMesh.dispose();\n }\n this.babylonUvPreviewsMap.delete(feature.id);\n }\n }\n\n class LightRenderer extends Renderer {\n set showPreviews(show) {\n this.showAllLightPreviews = show;\n this.babylonMap.forEach(light => {\n this.updatePreviewMesh(light);\n });\n }\n constructor(viewer, scene, shadowManager) {\n super(viewer, scene);\n this.shadowManager = shadowManager;\n this.babylonLightPreviewsMap = new Map();\n this.modelToken = Token.LightNode;\n this.showAllLightPreviews = false;\n this.gizmoLayer = this.viewer.utilityLayer;\n }\n update3dInternal(node) {\n var _a;\n if (!node._parent && ((_a = node._parentScene) === null || _a === void 0 ? void 0 : _a.isNested())) {\n //don't render global lights in nested scenes\n return;\n }\n let light = this.get3d(node);\n const changes = this.getChanges(node);\n if (!light) {\n if (node instanceof exports.PointLightNode) {\n light = new PointLight(node._dynamicId, node.position.toVec3(), this.scene);\n }\n else if (node instanceof exports.HemisphericLightNode) {\n light = new HemisphericLight(node._dynamicId, node.direction.toVec3(), this.scene);\n }\n else if (node instanceof exports.SpotLightNode) {\n light = new SpotLight(node._dynamicId, node.position.toVec3(), node.direction.toVec3(), (node.coneAngle * Math.PI) / 180, 2, this.scene);\n light.exponent = 2;\n }\n else if (node instanceof exports.DirectionalLightNode) {\n light = new DirectionalLight(node._dynamicId, node.direction.toVec3(), this.scene);\n }\n this.set3d(node, light);\n }\n const pLight = light;\n if (changes.has('visible')) {\n // Can be falsy so need to check the map\n pLight.setEnabled(node.visible);\n }\n if (changes.has('intensity')) {\n // Can be falsy so need to check the map\n pLight.intensity = node.intensity;\n }\n if (changes.has('color')) {\n pLight.specular = node.color.toColor3();\n pLight.diffuse = node.color.toColor3();\n }\n if (changes.has('_parent')) {\n if (node._parent) {\n pLight.parent = this.viewer.getRendererNode(node._parent);\n }\n else {\n pLight.parent = null;\n }\n }\n let lightRotation;\n if (node.useEuler) {\n lightRotation = Quaternion.FromEulerAngles(toRadians(node.eulerRotation.x), toRadians(node.eulerRotation.y), toRadians(node.eulerRotation.z));\n }\n else {\n lightRotation = Quaternion.RotationAxis(node.rotationAxis.toVec3(), toRadians(node.rotationAngle));\n }\n const rotationChanged = changes.hasAny('useEuler', 'eulerRotation', 'rotationAxis', 'rotationAngle');\n if (node instanceof exports.PointLightNode) {\n const pLight = light;\n if (changes.has('position')) {\n pLight.position = node.position.toVec3();\n }\n }\n else if (node instanceof exports.HemisphericLightNode) {\n const pLight = light;\n if (changes.has('direction') || rotationChanged) {\n pLight.direction = this.rotateDirection(node.direction.toVec3(), lightRotation);\n }\n if (changes.has('groundColor')) {\n pLight.groundColor = node.groundColor.toColor3();\n }\n }\n else if (node instanceof exports.SpotLightNode) {\n const pLight = light;\n if (changes.has('position')) {\n pLight.position = node.position.toVec3();\n }\n if (changes.has('direction') || rotationChanged) {\n pLight.direction = this.rotateDirection(node.direction.toVec3(), lightRotation);\n }\n if (changes.has('coneAngle')) {\n pLight.angle = (node.coneAngle * Math.PI) / 180;\n }\n }\n else if (node instanceof exports.DirectionalLightNode) {\n const pLight = light;\n // pLight.position = new Vector3(0, 5, 0);\n if (changes.has('direction') || rotationChanged) {\n pLight.direction = this.rotateDirection(node.direction.toVec3(), lightRotation);\n //for directional lights, we hardcode the position to be negative direction for shadows\n pLight.position = pLight.direction.clone().negate();\n }\n }\n if (node instanceof ShadowLightNode) {\n const shadowLightNode = node;\n const shadowLight = light;\n let sg = this.shadowManager.get(shadowLight);\n let justCreated = false;\n if (changes.has('generatesShadows')) {\n if (shadowLightNode.generatesShadows) {\n sg = this.shadowManager.add(shadowLight, shadowLightNode.shadowResolution);\n shadowLight.shadowEnabled = true;\n justCreated = true;\n changes.set('shadowFilter', shadowLightNode.shadowFilter);\n changes.set('shadowQuality', shadowLightNode.shadowQuality);\n }\n else {\n if (sg) {\n shadowLight.shadowEnabled = false;\n this.shadowManager.remove(shadowLight);\n sg = undefined;\n }\n }\n }\n //if the resolution is changed, and the shadow generator wasn't just created, we need to recreate it\n if (changes.has('shadowResolution') && sg && !justCreated) {\n this.shadowManager.remove(shadowLight);\n sg = this.shadowManager.add(shadowLight, shadowLightNode.shadowResolution);\n changes.set('shadowFilter', shadowLightNode.shadowFilter);\n changes.set('shadowQuality', shadowLightNode.shadowQuality);\n changes.set('processTransparency', shadowLightNode.processTransparency);\n }\n if (sg) {\n if (changes.has('shadowFilter')) {\n sg.filter = ShadowManager.convertShadowFilter(shadowLightNode.shadowFilter);\n }\n if (changes.has('processTransparency')) {\n sg.transparencyShadow = shadowLightNode.processTransparency;\n sg.enableSoftTransparentShadow = shadowLightNode.processTransparency;\n }\n if (changes.has('shadowQuality')) {\n sg.filteringQuality = ShadowGenerator[`QUALITY_${shadowLightNode.shadowQuality.toUpperCase()}`];\n }\n //need to update projection matrix if direction has been changed\n if (changes.hasAny('direction', 'position')) {\n this.shadowManager.clearProjectMatrixCache();\n }\n }\n }\n if (changes.has('_selected')) {\n if (!pLight.metadata) {\n pLight.metadata = {};\n }\n pLight.metadata.selected = node._selected;\n }\n this.viewer.updateLightWarnings();\n this.updatePreviewMesh(pLight);\n }\n delete3d(node) {\n if (this.babylonLightPreviewsMap) {\n const lightPositionGizmo = this.babylonLightPreviewsMap.get(node._dynamicId);\n if (!lightPositionGizmo) {\n throw Error('Light gizmo not found for light ' + node.id);\n }\n lightPositionGizmo.dispose();\n this.babylonLightPreviewsMap.delete(node._dynamicId);\n }\n this.shadowManager.remove(this.get3d(node)); //remove also disposes the shadow generator if it exists\n super.delete3d(node);\n this.viewer.updateLightWarnings();\n }\n updatePreviewMesh(light) {\n let lightPositionGizmo = this.babylonLightPreviewsMap.get(light.id);\n const scene = this.gizmoLayer.utilityLayerScene;\n if (!lightPositionGizmo) {\n lightPositionGizmo = createLightVisualization(light, scene, Color3.Yellow());\n lightPositionGizmo.isPickable = false;\n this.babylonLightPreviewsMap.set(light.id, lightPositionGizmo);\n }\n if (this.showAllLightPreviews) {\n lightPositionGizmo.setEnabled(light.metadata.selected || light.isEnabled());\n }\n else {\n lightPositionGizmo.setEnabled(light.metadata.selected);\n }\n if (light instanceof HemisphericLight) {\n lightPositionGizmo.rotationQuaternion = rotationToVector(light.direction);\n }\n else if (light instanceof SpotLight) {\n lightPositionGizmo.position = this.getLightPosition(light);\n lightPositionGizmo.rotationQuaternion = rotationToVector(light.direction);\n lightPositionGizmo.scaling.set(Math.sin(light.angle / 2), Math.cos(light.angle / 2), Math.sin(light.angle / 2));\n }\n else if (light instanceof DirectionalLight) {\n lightPositionGizmo.rotationQuaternion = rotationToVector(light.direction);\n }\n else if (light instanceof PointLight) {\n lightPositionGizmo.position = this.getLightPosition(light);\n }\n }\n rotateDirection(direction, rotation) {\n direction.rotateByQuaternionToRef(rotation, direction);\n return direction;\n }\n getLightPosition(light) {\n return light.parent\n ? Vector3.TransformCoordinates(light.position, light.parent.computeWorldMatrix(true).clone())\n : light.position;\n }\n }\n\n class MateRenderer extends Renderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.MateNode;\n }\n update3dInternal(node) { }\n delete3d(node) {\n SyncService.nodeDeletionProcessed(node);\n }\n }\n\n AbstractScene.prototype.removeReflectionProbe = function (toRemove) {\n if (!this.reflectionProbes) {\n return -1;\n }\n const index = this.reflectionProbes.indexOf(toRemove);\n if (index !== -1) {\n this.reflectionProbes.splice(index, 1);\n }\n return index;\n };\n AbstractScene.prototype.addReflectionProbe = function (newReflectionProbe) {\n if (!this.reflectionProbes) {\n this.reflectionProbes = [];\n }\n this.reflectionProbes.push(newReflectionProbe);\n };\n /**\n * Class used to generate realtime reflection / refraction cube textures\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes\n */\n class ReflectionProbe {\n /**\n * Creates a new reflection probe\n * @param name defines the name of the probe\n * @param size defines the texture resolution (for each face)\n * @param scene defines the hosting scene\n * @param generateMipMaps defines if mip maps should be generated automatically (true by default)\n * @param useFloat defines if HDR data (float data) should be used to store colors (false by default)\n * @param linearSpace defines if the probe should be generated in linear space or not (false by default)\n */\n constructor(\n /** defines the name of the probe */\n name, size, scene, generateMipMaps = true, useFloat = false, linearSpace = false) {\n this.name = name;\n this._viewMatrix = Matrix.Identity();\n this._target = Vector3.Zero();\n this._add = Vector3.Zero();\n this._invertYAxis = false;\n /** Gets or sets probe position (center of the cube map) */\n this.position = Vector3.Zero();\n /**\n * Gets or sets an object used to store user defined information for the reflection probe.\n */\n this.metadata = null;\n /** @internal */\n this._parentContainer = null;\n this._scene = scene;\n if (scene.getEngine().supportsUniformBuffers) {\n this._sceneUBOs = [];\n for (let i = 0; i < 6; ++i) {\n this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name \"${name}\") face #${i}`));\n }\n }\n // Create the scene field if not exist.\n if (!this._scene.reflectionProbes) {\n this._scene.reflectionProbes = new Array();\n }\n this._scene.reflectionProbes.push(this);\n let textureType = 0;\n if (useFloat) {\n const caps = this._scene.getEngine().getCaps();\n if (caps.textureHalfFloatRender) {\n textureType = 2;\n }\n else if (caps.textureFloatRender) {\n textureType = 1;\n }\n }\n this._renderTargetTexture = new RenderTargetTexture(name, size, scene, generateMipMaps, true, textureType, true);\n this._renderTargetTexture.gammaSpace = !linearSpace;\n this._renderTargetTexture.invertZ = scene.useRightHandedSystem;\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\n this._renderTargetTexture.onBeforeRenderObservable.add((faceIndex) => {\n if (this._sceneUBOs) {\n scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);\n scene.getSceneUniformBuffer().unbindEffect();\n }\n switch (faceIndex) {\n case 0:\n this._add.copyFromFloats(1, 0, 0);\n break;\n case 1:\n this._add.copyFromFloats(-1, 0, 0);\n break;\n case 2:\n this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);\n break;\n case 3:\n this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);\n break;\n case 4:\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);\n break;\n case 5:\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);\n break;\n }\n if (this._attachedMesh) {\n this.position.copyFrom(this._attachedMesh.getAbsolutePosition());\n }\n this.position.addToRef(this._add, this._target);\n const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;\n const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;\n lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);\n if (scene.activeCamera) {\n this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this._scene.getEngine().isNDCHalfZRange);\n scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);\n if (scene.activeCamera.isRigCamera && !this._renderTargetTexture.activeCamera) {\n this._renderTargetTexture.activeCamera = scene.activeCamera.rigParent || null;\n }\n }\n scene._forcedViewPosition = this.position;\n });\n let currentApplyByPostProcess;\n this._renderTargetTexture.onBeforeBindObservable.add(() => {\n var _a, _b;\n this._currentSceneUBO = scene.getSceneUniformBuffer();\n (_b = (_a = scene.getEngine())._debugPushGroup) === null || _b === void 0 ? void 0 : _b.call(_a, `reflection probe generation for ${name}`, 1);\n currentApplyByPostProcess = this._scene.imageProcessingConfiguration.applyByPostProcess;\n if (linearSpace) {\n scene.imageProcessingConfiguration.applyByPostProcess = true;\n }\n });\n this._renderTargetTexture.onAfterUnbindObservable.add(() => {\n var _a, _b;\n scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;\n scene._forcedViewPosition = null;\n if (this._sceneUBOs) {\n scene.setSceneUniformBuffer(this._currentSceneUBO);\n }\n scene.updateTransformMatrix(true);\n (_b = (_a = scene.getEngine())._debugPopGroup) === null || _b === void 0 ? void 0 : _b.call(_a, 1);\n });\n }\n /** Gets or sets the number of samples to use for multi-sampling (0 by default). Required WebGL2 */\n get samples() {\n return this._renderTargetTexture.samples;\n }\n set samples(value) {\n this._renderTargetTexture.samples = value;\n }\n /** Gets or sets the refresh rate to use (on every frame by default) */\n get refreshRate() {\n return this._renderTargetTexture.refreshRate;\n }\n set refreshRate(value) {\n this._renderTargetTexture.refreshRate = value;\n }\n /**\n * Gets the hosting scene\n * @returns a Scene\n */\n getScene() {\n return this._scene;\n }\n /** Gets the internal CubeTexture used to render to */\n get cubeTexture() {\n return this._renderTargetTexture;\n }\n /** Gets the list of meshes to render */\n get renderList() {\n return this._renderTargetTexture.renderList;\n }\n /**\n * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)\n * @param mesh defines the mesh to attach to\n */\n attachToMesh(mesh) {\n this._attachedMesh = mesh;\n }\n /**\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups\n * @param renderingGroupId The rendering group id corresponding to its index\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\n */\n setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil) {\n this._renderTargetTexture.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);\n }\n /**\n * Clean all associated resources\n */\n dispose() {\n const index = this._scene.reflectionProbes.indexOf(this);\n if (index !== -1) {\n // Remove from the scene if found\n this._scene.reflectionProbes.splice(index, 1);\n }\n if (this._parentContainer) {\n const index = this._parentContainer.reflectionProbes.indexOf(this);\n if (index > -1) {\n this._parentContainer.reflectionProbes.splice(index, 1);\n }\n this._parentContainer = null;\n }\n if (this._renderTargetTexture) {\n this._renderTargetTexture.dispose();\n this._renderTargetTexture = null;\n }\n if (this._sceneUBOs) {\n for (const ubo of this._sceneUBOs) {\n ubo.dispose();\n }\n this._sceneUBOs = [];\n }\n }\n /**\n * Converts the reflection probe information to a readable string for debug purpose.\n * @param fullDetails Supports for multiple levels of logging within scene loading\n * @returns the human readable reflection probe info\n */\n toString(fullDetails) {\n let ret = \"Name: \" + this.name;\n if (fullDetails) {\n ret += \", position: \" + this.position.toString();\n if (this._attachedMesh) {\n ret += \", attached mesh: \" + this._attachedMesh.name;\n }\n }\n return ret;\n }\n /**\n * Get the class name of the refection probe.\n * @returns \"ReflectionProbe\"\n */\n getClassName() {\n return \"ReflectionProbe\";\n }\n /**\n * Serialize the reflection probe to a JSON representation we can easily use in the respective Parse function.\n * @returns The JSON representation of the texture\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this, this._renderTargetTexture.serialize());\n serializationObject.isReflectionProbe = true;\n serializationObject.metadata = this.metadata;\n return serializationObject;\n }\n /**\n * Parse the JSON representation of a reflection probe in order to recreate the reflection probe in the given scene.\n * @param parsedReflectionProbe Define the JSON representation of the reflection probe\n * @param scene Define the scene the parsed reflection probe should be instantiated in\n * @param rootUrl Define the root url of the parsing sequence in the case of relative dependencies\n * @returns The parsed reflection probe if successful\n */\n static Parse(parsedReflectionProbe, scene, rootUrl) {\n let reflectionProbe = null;\n if (scene.reflectionProbes) {\n for (let index = 0; index < scene.reflectionProbes.length; index++) {\n const rp = scene.reflectionProbes[index];\n if (rp.name === parsedReflectionProbe.name) {\n reflectionProbe = rp;\n break;\n }\n }\n }\n reflectionProbe = SerializationHelper.Parse(() => reflectionProbe || new ReflectionProbe(parsedReflectionProbe.name, parsedReflectionProbe.renderTargetSize, scene, parsedReflectionProbe._generateMipMaps), parsedReflectionProbe, scene, rootUrl);\n reflectionProbe.cubeTexture._waitingRenderList = parsedReflectionProbe.renderList;\n if (parsedReflectionProbe._attachedMesh) {\n reflectionProbe.attachToMesh(scene.getMeshById(parsedReflectionProbe._attachedMesh));\n }\n if (parsedReflectionProbe.metadata) {\n reflectionProbe.metadata = parsedReflectionProbe.metadata;\n }\n return reflectionProbe;\n }\n }\n __decorate$1([\n serializeAsMeshReference()\n ], ReflectionProbe.prototype, \"_attachedMesh\", void 0);\n __decorate$1([\n serializeAsVector3()\n ], ReflectionProbe.prototype, \"position\", void 0);\n\n // Performance Code from Babylon 5.0. Remove once upgrade to Babylon 5.0 is merged\n Object.defineProperty(BaseTexture.prototype, 'hasAlpha', {\n get: function () {\n return this._hasAlpha;\n },\n set: function (value) {\n const self = this;\n if (this._hasAlpha === value) {\n return;\n }\n this._hasAlpha = value;\n if (this._scene) {\n this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, function (mat) {\n return mat.hasTexture(self);\n });\n }\n },\n enumerable: false,\n configurable: true,\n });\n class MaterialRenderer extends Renderer {\n get defaultMaterial() {\n return this._defaultMaterial;\n }\n constructor(viewer, scene, textureRenderer) {\n super(viewer, scene);\n this.textureRenderer = textureRenderer;\n this._globalMaterialCache = new Map();\n this.orphanedMeshes = new Map();\n //keyed by the connector id of which the reflection probe is attached to\n this.reflectionProbeMap = new Map();\n this.reflectedMeshes = new Map();\n //key is the ConnectorId of the reflection probe, String[] is the ids of the meshes using the material;\n this.meshesUsingReflectionMaterial = new Map();\n this.modelToken = Token.MaterialNode;\n this._defaultMaterial = new PBRMaterial('default material', scene);\n this._defaultMaterial.albedoColor = new Color3(0.5, 0.5, 0.5);\n this._defaultMaterial.alphaMode = Engine.ALPHA_COMBINE;\n this._defaultMaterial.metallic = 0;\n this._defaultMaterial.roughness = 1;\n }\n get renderMode() {\n return this._renderMode;\n }\n set renderMode(mode) {\n this._renderMode = mode;\n this.babylonMap.forEach(material => {\n this.setRenderModeOnMaterial(material, mode);\n });\n this.setRenderModeOnMaterial(this._defaultMaterial, mode);\n }\n getAllDefinedMaterials() {\n return Array.from(this.babylonMap.values());\n }\n getGlobalMaterial(dynamicId) {\n if (!this._globalMaterialManager) {\n return undefined;\n }\n else {\n return this._globalMaterialManager.getById(dynamicId);\n }\n }\n delete3d(node) {\n this.textureRenderer.materialDeleted(node);\n const material = this.get3d(node);\n if (material instanceof PBRMaterial) {\n const orphanedMeshes = material.getBindedMeshes();\n this.orphanedMeshes.set(node.id, orphanedMeshes);\n }\n this.viewer.materialWarningsNeedsUpdate.next();\n return super.delete3d(node);\n }\n loadGlobalMaterial(materialId, managerServices) {\n if (!this._globalMaterialManager) {\n this._globalMaterialManager = new Kb3dManager({ services: managerServices });\n }\n const matService = this._globalMaterialManager.getService(Token.MaterialService);\n if (this._globalMaterialCache.has(materialId)) {\n return this._globalMaterialCache.get(materialId);\n }\n else {\n const obs = matService\n .getMaterialById(materialId)\n .pipe(map(imaterial => {\n if (imaterial) {\n let matNode = this._globalMaterialManager.getById(materialId);\n const newMatNode = this._globalMaterialManager.deserialize(imaterial.data);\n // If the material has already been added to the scene, just update it.\n if (matNode) {\n this._globalMaterialManager.assign(matNode, newMatNode);\n // We have to re-initialize the material to reload the texture\n if (matNode._initialized) {\n matNode._initialized = false;\n matNode.init();\n }\n }\n else {\n matNode = newMatNode;\n matNode._dynamicId = matNode.id; // Each global material is unique\n this._globalMaterialManager.register(matNode);\n //now create the material in babylon by rendering it\n this.update3d(matNode);\n }\n return matNode;\n }\n return undefined;\n }))\n .pipe(shareReplay(1));\n this._globalMaterialCache.set(materialId, obs);\n return obs;\n }\n }\n update3dInternal(node) {\n let material = this.get3d(node);\n let _changes = node.changes;\n // since the texture are nested in the material we have to refresh the texture in the material individually\n if (instanceOf(node, Token.AdvancedMaterialNode)) {\n let changes = _changes;\n let pbrAdvMaterial = material;\n if (!pbrAdvMaterial) {\n material = pbrAdvMaterial = new PBRMaterial(node._dynamicId, this.scene);\n material.name = node.name;\n material.id = node._dynamicId;\n const meshesToBind = this.orphanedMeshes.get(node.id);\n if (meshesToBind) {\n const _pbrAdvMaterial = pbrAdvMaterial;\n meshesToBind.forEach(mesh => {\n mesh.material = _pbrAdvMaterial;\n });\n }\n changes = _changes = new Map(Object.entries(node));\n changes.set('textures', node.textures);\n /** hardcode the alphaMode because the material always overrides the engine setting and we need proper alpha for dragging effects */\n material.alphaMode = Engine.ALPHA_COMBINE;\n material.useParallax = false;\n // Logarithmic depth is a good concept but is buggy. Maybe try again later.\n // material.useLogarithmicDepth = true;\n material.useLightmapAsShadowmap = true;\n material.enableSpecularAntiAliasing = true;\n material.forceDepthWrite = true;\n pbrAdvMaterial.transparencyMode = Material.MATERIAL_ALPHABLEND;\n material.useMetallnessFromMetallicTextureBlue = false;\n material.useMicroSurfaceFromReflectivityMapAlpha = false;\n material.useRoughnessFromMetallicTextureGreen = false;\n this.setRenderModeOnMaterial(material, this.renderMode);\n this.set3d(node, pbrAdvMaterial);\n }\n if (changes.has('probePositionTargetId')) {\n this.updateReflectionProbes();\n }\n if (changes.hasAny('probePositionTargetId', 'subsurfaceReflectionEnabled', 'reflectionType')) {\n //if (node.reflectionType === eReflectionType.probe) {\n if (!node.probePositionTargetId || !node.subsurfaceReflectionEnabled) {\n if (pbrAdvMaterial) {\n pbrAdvMaterial.reflectionTexture = null;\n }\n }\n else {\n if (node.reflectionType === exports.eReflectionType.probe) {\n if (node.probePositionTargetId && pbrAdvMaterial) {\n let reflectionProbe = this.reflectionProbeMap.get(node.probePositionTargetId);\n if (!reflectionProbe || reflectionProbe instanceof MirrorTexture) {\n reflectionProbe = new ReflectionProbe(node.probePositionTargetId, 512, this.scene);\n this.reflectionProbeMap.set(node.probePositionTargetId, reflectionProbe);\n const exceptions = this.meshesUsingReflectionMaterial.get(node.probePositionTargetId);\n this.reflectedMeshes.forEach(mesh => {\n var _a;\n if (reflectionProbe && reflectionProbe.renderList) {\n if (!(exceptions === null || exceptions === void 0 ? void 0 : exceptions.contains(mesh.id))) {\n (_a = reflectionProbe.renderList) === null || _a === void 0 ? void 0 : _a.push(mesh);\n }\n }\n });\n const sceneBackground = this.scene.meshes.find(obj => {\n return obj.id === 'hdrSkyBox';\n });\n if (reflectionProbe && reflectionProbe.renderList && sceneBackground) {\n reflectionProbe.renderList.push(sceneBackground);\n }\n }\n const connector = this.viewer.getNode(node.probePositionTargetId);\n if (connector instanceof exports.Connector) {\n const connectorMesh = this.viewer.getRendererNode(connector);\n reflectionProbe.attachToMesh(connectorMesh);\n }\n if (pbrAdvMaterial) {\n reflectionProbe.cubeTexture.invertZ = false;\n pbrAdvMaterial.reflectionTexture = reflectionProbe.cubeTexture;\n }\n }\n }\n else {\n if (node.probePositionTargetId && pbrAdvMaterial) {\n let reflectionProbe = this.reflectionProbeMap.get(node.probePositionTargetId);\n let noPlane = false;\n if (reflectionProbe && reflectionProbe instanceof MirrorTexture) {\n if (!reflectionProbe.mirrorPlane) {\n noPlane = true;\n }\n }\n if (!reflectionProbe || reflectionProbe instanceof MirrorTexture || noPlane) {\n reflectionProbe = new ReflectionProbe(node.probePositionTargetId, 512, this.scene);\n this.reflectionProbeMap.set(node.probePositionTargetId, reflectionProbe);\n const exceptions = this.meshesUsingReflectionMaterial.get(node.probePositionTargetId);\n this.reflectedMeshes.forEach(mesh => {\n var _a;\n if (reflectionProbe && reflectionProbe.renderList) {\n if (!(exceptions === null || exceptions === void 0 ? void 0 : exceptions.contains(mesh.id))) {\n (_a = reflectionProbe.renderList) === null || _a === void 0 ? void 0 : _a.push(mesh);\n }\n }\n });\n const sceneBackground = this.scene.meshes.find(obj => {\n return obj.id === 'hdrSkyBox';\n });\n if (reflectionProbe && reflectionProbe.renderList && sceneBackground) {\n reflectionProbe.renderList.push(sceneBackground);\n }\n }\n const mirrorTexture = new MirrorTexture('mirrorTexture', 1024, this.scene);\n const connector = this.viewer.getNode(node.probePositionTargetId);\n let position = new Vector3(0, 0, 0);\n if (connector &&\n connector instanceof exports.Connector &&\n connector._parent &&\n connector._parent instanceof exports.SpaceNode) {\n const connectorMesh = this.viewer.getRendererNode(connector._parent);\n if (connectorMesh) {\n const normal = Vector3.TransformCoordinates(connector.direction.toVec3().scale(-1), connectorMesh.getWorldMatrix().getRotationMatrix());\n position = connectorMesh.absolutePosition;\n const reflector = Plane.FromPositionAndNormal(position, normal);\n mirrorTexture.mirrorPlane = reflector;\n mirrorTexture.renderList = reflectionProbe.renderList;\n }\n }\n if (pbrAdvMaterial) {\n mirrorTexture.invertZ = false;\n mirrorTexture.adaptiveBlurKernel = node.roughness * 100;\n pbrAdvMaterial.reflectionTexture = mirrorTexture;\n }\n }\n }\n }\n }\n if (changes.has('hasTransparency')) {\n pbrAdvMaterial.useAlphaFromAlbedoTexture = node.hasTransparency;\n this.textureRenderer.setTransparency(node, node.hasTransparency);\n }\n if (changes.has('directIntensity'))\n pbrAdvMaterial.directIntensity = node.directIntensity;\n if (changes.has('emissiveIntensity'))\n pbrAdvMaterial.emissiveIntensity = node.emissiveIntensity;\n if (changes.has('environmentIntensity'))\n pbrAdvMaterial.environmentIntensity = node.environmentIntensity;\n if (changes.has('specularIntensity'))\n pbrAdvMaterial.specularIntensity = node.specularIntensity;\n if (changes.has('ambientTextureStrength')) {\n pbrAdvMaterial.ambientTextureStrength = node.ambientTextureStrength || 1;\n }\n if (changes.has('ambientColor')) {\n pbrAdvMaterial.ambientColor = new Color3(node.ambientColor.r, node.ambientColor.g, node.ambientColor.b).toLinearSpace();\n }\n if (changes.has('albedoColor')) {\n pbrAdvMaterial.albedoColor = new Color3(node.albedoColor.r, node.albedoColor.g, node.albedoColor.b).toLinearSpace();\n }\n if (changes.has('specularColor')) {\n pbrAdvMaterial.reflectivityColor = new Color3(node.specularColor.r, node.specularColor.g, node.specularColor.b).toLinearSpace();\n }\n if (changes.has('reflectionColor')) {\n pbrAdvMaterial.reflectionColor = new Color3(node.reflectionColor.r, node.reflectionColor.g, node.reflectionColor.b).toLinearSpace();\n }\n if (changes.has('microSurface'))\n pbrAdvMaterial.microSurface = node.microSurface;\n if (changes.has('useSpecularOverAlpha'))\n pbrAdvMaterial.useSpecularOverAlpha = node.useSpecularOverAlpha;\n if (changes.has('useRadianceOverAlpha'))\n pbrAdvMaterial.useRadianceOverAlpha = node.useRadianceOverAlpha;\n if (changes.has('textures') || changes.has('doubleSided') || changes.has('hasTransparency')) {\n // Only enable the material transparency handling if necessary\n if ((node.hasTransparency && node.doubleSided) ||\n node.textures.find(texture => texture.channel === exports.eTextureChannel.opacity)) {\n // These properties are necessary to ensure that partial transparency self-blending works correctly. There is a performace impact.\n pbrAdvMaterial.separateCullingPass = true;\n pbrAdvMaterial.transparencyMode = Material.MATERIAL_ALPHABLEND;\n // Refraction test\n // let renderTarget = new RefractionTexture(\"rt\", 1024, this.scene, true);\n // renderTarget.renderListPredicate = (mesh) => {\n // return mesh.name === 'hdrSkyBox'; // mesh.material === pbrAdvMaterial && mesh.isEnabled();\n // }\n // renderTarget.lodGenerationScale = 0.5;\n // renderTarget.depth = 1;\n // pbrAdvMaterial.refractionTexture = renderTarget;\n // renderTarget.refractionPlane = new Plane(0, 0, 0, 0);\n // pbrAdvMaterial.subSurface.useAlbedoToTintRefraction = true\n // pbrAdvMaterial.subSurface.indexOfRefraction = 1.5;\n // pbrAdvMaterial.subSurface.isTranslucencyEnabled = true;\n // pbrAdvMaterial.subSurface.linkRefractionWithTransparency = true;\n }\n else {\n pbrAdvMaterial.separateCullingPass = false;\n pbrAdvMaterial.transparencyMode = null;\n }\n }\n if (changes.has('anisotropicIntensity'))\n pbrAdvMaterial.anisotropy.intensity = node.anisotropicIntensity;\n if (changes.has('anisotropicDirection')) {\n pbrAdvMaterial.anisotropy.direction = new Vector2(node.anisotropicDirection.x, node.anisotropicDirection.y);\n }\n if (changes.has('anisotropyEnabled')) {\n pbrAdvMaterial.anisotropy.isEnabled = node.anisotropyEnabled;\n if (node.anisotropyEnabled) {\n const tangentTexture = node.textures.find(texture => texture.channel === exports.eTextureChannel.anisotropyTangent);\n if (tangentTexture && isTrackedClass(tangentTexture)) {\n tangentTexture.isModified = true;\n }\n }\n else {\n pbrAdvMaterial.anisotropy.texture = null;\n }\n }\n if (changes.has('clearcoatIntensity'))\n pbrAdvMaterial.clearCoat.intensity = node.clearcoatIntensity;\n if (changes.has('clearcoatTintEnabled'))\n pbrAdvMaterial.clearCoat.isTintEnabled = node.clearcoatTintEnabled;\n if (changes.has('clearcoatTintIntensity')) {\n pbrAdvMaterial.clearCoat.tintThickness = node.clearcoatTintIntensity;\n }\n if (changes.has('clearcoatTintColor')) {\n pbrAdvMaterial.clearCoat.tintColor = node.clearcoatTintColor.toColor3();\n }\n if (changes.has('clearcoatEnabled')) {\n pbrAdvMaterial.clearCoat.isEnabled = node.clearcoatEnabled;\n if (node.clearcoatEnabled) {\n const clearcoatNormalTexture = node.textures.find(texture => texture.channel === exports.eTextureChannel.clearCoatNormal);\n if (clearcoatNormalTexture && isTrackedClass(clearcoatNormalTexture)) {\n clearcoatNormalTexture.isModified = true;\n }\n }\n else {\n pbrAdvMaterial.clearCoat.bumpTexture = null;\n }\n }\n if (changes.has('subsurfaceThickness')) {\n pbrAdvMaterial.subSurface.minimumThickness = node.subsurfaceThickness;\n }\n if (changes.has('subsurfaceTintColor')) {\n pbrAdvMaterial.subSurface.tintColor = node.subsurfaceTintColor.toColor3();\n }\n if (changes.has('subsurfaceUseAlbedoForTintColor')) {\n pbrAdvMaterial.subSurface.useAlbedoToTintRefraction = node.subsurfaceUseAlbedoForTintColor;\n }\n if (changes.has('subsurfaceRefractionEnabled')) {\n pbrAdvMaterial.subSurface.isRefractionEnabled = node.subsurfaceRefractionEnabled;\n }\n if (changes.has('subsurfaceRefractionIntensity')) {\n pbrAdvMaterial.subSurface.refractionIntensity = node.subsurfaceRefractionIntensity;\n }\n if (changes.has('subsurfaceRefractionIndex')) {\n pbrAdvMaterial.subSurface.indexOfRefraction = node.subsurfaceRefractionIndex;\n }\n if (changes.has('subsurfaceRefractionLinkTransparency')) {\n pbrAdvMaterial.subSurface.linkRefractionWithTransparency = node.subsurfaceRefractionLinkTransparency;\n }\n if (changes.has('subsurfaceTranslucencyEnabled')) {\n pbrAdvMaterial.subSurface.isTranslucencyEnabled = node.subsurfaceTranslucencyEnabled;\n }\n if (changes.has('subsurfaceTranslucencyIntensity')) {\n pbrAdvMaterial.subSurface.translucencyIntensity = node.subsurfaceTranslucencyIntensity;\n }\n if (changes.hasAny('subsurfaceRefractionEnabled', 'subsurfaceTranslucencyEnabled', 'probePositionTargetId')) {\n if (!node.probePositionTargetId || !node.subsurfaceRefractionEnabled) {\n pbrAdvMaterial.refractionTexture = null;\n }\n else {\n let refractionProbe = this.reflectionProbeMap.get(node.probePositionTargetId);\n if (!refractionProbe) {\n refractionProbe = new ReflectionProbe(node.probePositionTargetId, 512, this.scene);\n const connector = this.viewer.getNode(node.probePositionTargetId);\n if (connector instanceof exports.Connector) {\n const connectorMesh = this.viewer.getRendererNode(connector);\n refractionProbe.attachToMesh(connectorMesh);\n this.reflectionProbeMap.set(node.probePositionTargetId, refractionProbe);\n }\n const exceptions = this.meshesUsingReflectionMaterial.get(node.probePositionTargetId);\n this.reflectedMeshes.forEach(mesh => {\n var _a;\n if (refractionProbe && refractionProbe.renderList) {\n if (!(exceptions === null || exceptions === void 0 ? void 0 : exceptions.contains(mesh.id))) {\n (_a = refractionProbe.renderList) === null || _a === void 0 ? void 0 : _a.push(mesh);\n }\n }\n });\n const sceneBackground = this.scene.meshes.find(obj => {\n return obj.id === 'hdrSkyBox';\n });\n if (refractionProbe && refractionProbe.renderList && sceneBackground) {\n refractionProbe.renderList.push(sceneBackground);\n }\n }\n const refractionTexture = new RefractionTexture('refractionTexture', 1024, this.scene);\n const connector = this.viewer.getNode(node.probePositionTargetId);\n let position = new Vector3(0, 0, 0);\n if (connector &&\n connector instanceof exports.Connector &&\n connector._parent &&\n connector._parent instanceof exports.SpaceNode) {\n const connectorMesh = this.viewer.getRendererNode(connector._parent);\n if (connectorMesh) {\n const normal = Vector3.TransformCoordinates(connector.direction.toVec3(), connectorMesh.getWorldMatrix().getRotationMatrix());\n position = connectorMesh.absolutePosition;\n const reflector = Plane.FromPositionAndNormal(position, normal);\n refractionTexture.refractionPlane = reflector;\n refractionTexture.renderList = refractionProbe.renderList;\n refractionTexture.depth = node.subsurfaceRefractionIndex;\n }\n }\n if (pbrAdvMaterial) {\n refractionTexture.invertZ = false;\n pbrAdvMaterial.refractionTexture = refractionTexture;\n }\n }\n if (node.subsurfaceRefractionEnabled || node.subsurfaceTranslucencyEnabled) {\n if (!pbrAdvMaterial.subSurface.thicknessTexture) {\n const subsurfaceThicknessTexture = node.textures.find(texture => texture.channel === exports.eTextureChannel.subsurfaceThickness);\n if (subsurfaceThicknessTexture && isTrackedClass(subsurfaceThicknessTexture)) {\n subsurfaceThicknessTexture.isModified = true;\n }\n }\n }\n else {\n pbrAdvMaterial.subSurface.thicknessTexture = null;\n }\n }\n if (changes.has('workflowMode')) {\n if (node.workflowMode === exports.eMaterialWorkflow.metallicRoughness) {\n pbrAdvMaterial.metallic = node.metallic;\n pbrAdvMaterial.roughness = node.roughness;\n }\n else {\n /* Remove the metallic texture if workflow is not metallic-roughness, otherwise metallic-roughness gets used */\n pbrAdvMaterial.metallicTexture = undefined;\n pbrAdvMaterial.metallic = null;\n pbrAdvMaterial.roughness = null;\n }\n if (pbrAdvMaterial.reflectionTexture && pbrAdvMaterial.reflectionTexture instanceof MirrorTexture) {\n if (node.roughness !== 0) {\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = node.roughness * 100;\n }\n else {\n //When setting the adaptiveBlurKernel to 0 we get very odd behavior.\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = 0.000001;\n }\n }\n }\n else if (node.workflowMode === exports.eMaterialWorkflow.metallicRoughness) {\n if (changes.has('metallic'))\n pbrAdvMaterial.metallic = node.metallic;\n if (changes.has('roughness')) {\n pbrAdvMaterial.roughness = node.roughness;\n if (pbrAdvMaterial.reflectionTexture && pbrAdvMaterial.reflectionTexture instanceof MirrorTexture) {\n if (node.roughness !== 0) {\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = node.roughness * 100;\n }\n else {\n //When setting the adaptiveBlurKernel to 0 we get very odd behavior.\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = 0.000001;\n }\n }\n }\n }\n }\n if (material) {\n const changes = _changes;\n if (changes.has('alpha'))\n material.alpha = node.alpha;\n if (changes.has('zOffset'))\n material.zOffset = node.zOffset || 0;\n if (changes.has('doubleSided')) {\n material.backFaceCulling = !node.doubleSided;\n material.twoSidedLighting = !!node.doubleSided;\n }\n if (changes.has('emissiveColor')) {\n if (node.emissiveColor) {\n material.emissiveColor = new Color3(node.emissiveColor.r, node.emissiveColor.g, node.emissiveColor.b);\n }\n else {\n material.emissiveColor = Color3.Black();\n }\n }\n // Wireframe mode for debugging geometry\n // if(true || node.viewMode === eMaterialViewMode.wireframe) {\n // material.wireframe = true;\n // material.emissiveColor = Color3.Red();\n // }\n }\n this.viewer.materialWarningsNeedsUpdate.next();\n }\n setRenderModeOnMaterial(material, mode) {\n if (mode === exports.eRenderMode.wireframe) {\n material.pointsCloud = false;\n material.wireframe = true;\n }\n else if (mode === exports.eRenderMode.hiddenEdges) {\n material.wireframe = false;\n material.pointsCloud = true;\n }\n else {\n material.pointsCloud = false;\n material.wireframe = false;\n }\n }\n getNumberOfMaterialRef(sceneNode, materialNode) {\n const allMeshes = sceneNode.filterByType(...Token.MeshTokens);\n let nrefs = 0;\n for (const m of allMeshes) {\n if (m.materialId == materialNode._dynamicId)\n nrefs++;\n }\n return nrefs;\n }\n updateReflectionProbes() {\n var _a, _b;\n this.meshesUsingReflectionMaterial.clear();\n (_a = this.viewer.sceneNode._manager) === null || _a === void 0 ? void 0 : _a.getAllNodes().forEach(mesh => {\n var _a;\n if (mesh instanceof exports.MeshNode) {\n if (mesh.materialId) {\n const material = (_a = mesh._manager) === null || _a === void 0 ? void 0 : _a.getById(mesh.materialId);\n if (material && material instanceof exports.MaterialNode && material.probePositionTargetId) {\n let exceptionList = this.meshesUsingReflectionMaterial.get(material.probePositionTargetId);\n if (!exceptionList) {\n exceptionList = [mesh._dynamicId];\n }\n else {\n exceptionList.push(mesh._dynamicId);\n }\n this.meshesUsingReflectionMaterial.set(material.probePositionTargetId, exceptionList);\n }\n }\n }\n });\n const sceneBackground = this.scene.meshes.filter(obj => {\n return obj.id === 'hdrSkyBox';\n });\n for (const keyValuePair of this.reflectionProbeMap) {\n const reflectionProbe = keyValuePair[1];\n const connectorId = keyValuePair[0];\n (_b = reflectionProbe.renderList) === null || _b === void 0 ? void 0 : _b.clear();\n const exceptions = this.meshesUsingReflectionMaterial.get(connectorId);\n this.reflectedMeshes.forEach(mesh => {\n var _a;\n if (!(exceptions === null || exceptions === void 0 ? void 0 : exceptions.contains(mesh.id))) {\n (_a = reflectionProbe.renderList) === null || _a === void 0 ? void 0 : _a.push(mesh);\n }\n });\n if (reflectionProbe && reflectionProbe.renderList) {\n reflectionProbe.renderList.push(sceneBackground[0]);\n }\n }\n }\n }\n\n /**\n * Class containing static functions to help procedurally build meshes\n */\n class CylinderBuilder$1 {\n /**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/Cylinderover_basic_elements#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\n */\n static CreateCylinder(name, options, scene) {\n const Cylinder = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n Cylinder._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = createCylinder(options);\n vertexData.applyToMesh(Cylinder, options.updatable);\n return Cylinder;\n function createCylinder(options) {\n const height = options.height || 2;\n let diameterTop = options.diameterTop === 0 ? 0 : options.diameterTop || options.diameter || 1;\n let diameterBottom = options.diameterBottom === 0 ? 0 : options.diameterBottom || options.diameter || 1;\n diameterTop = diameterTop || 0.00001; // Prevent broken normals\n diameterBottom = diameterBottom || 0.00001; // Prevent broken normals\n const tessellation = options.tessellation || 24;\n const subdivisions = options.subdivisions || 1;\n const hasRings = options.hasRings ? true : false;\n const enclose = options.enclose ? true : false;\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.CAP_ALL;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const faceUV = options.faceUV || new Array(3);\n const faceColors = options.faceColors;\n // default face colors and UV if undefined\n const quadNb = arc !== 1 && enclose ? 2 : 0;\n const ringNb = hasRings ? subdivisions : 1;\n const surfaceNb = 2 + (1 + quadNb) * ringNb;\n let f;\n for (f = 0; f < surfaceNb; f++) {\n if (faceColors && faceColors[f] === undefined) {\n faceColors[f] = new Color4(1, 1, 1, 1);\n }\n }\n for (f = 0; f < surfaceNb; f++) {\n if (faceUV && faceUV[f] === undefined) {\n faceUV[f] = new Vector4(0, 0, 1, 1);\n }\n }\n const indices = new Array();\n const positions = new Array();\n const normals = new Array();\n const uvs = new Array();\n const colors = new Array();\n const angle_step = (Math.PI * 2 * arc) / tessellation;\n let angle;\n let h;\n let radius;\n const tan = (diameterBottom - diameterTop) / 2 / height;\n const ringVertex = Vector3.Zero();\n const ringNormal = Vector3.Zero();\n const ringFirstVertex = Vector3.Zero();\n const ringFirstNormal = Vector3.Zero();\n const quadNormal = Vector3.Zero();\n const Y = Axis.Y;\n // positions, normals, uvs\n let i;\n let j;\n let r;\n let ringIdx = 1;\n let s = 1; // surface index\n let cs = 0;\n let v = 0;\n for (i = 0; i <= subdivisions; i++) {\n h = i / subdivisions;\n radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;\n ringIdx = hasRings && i !== 0 && i !== subdivisions ? 2 : 1;\n for (r = 0; r < ringIdx; r++) {\n if (hasRings) {\n s += r;\n }\n if (enclose) {\n s += 2 * r;\n }\n for (j = 0; j <= tessellation; j++) {\n angle = j * angle_step;\n // position\n ringVertex.x = Math.cos(-angle) * radius;\n ringVertex.y = -height / 2 + h * height;\n ringVertex.z = Math.sin(-angle) * radius;\n // normal\n if (diameterTop === 0 && i === subdivisions) {\n // if no top cap, reuse former normals\n ringNormal.x = normals[normals.length - (tessellation + 1) * 3];\n ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];\n ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];\n }\n else {\n ringNormal.x = ringVertex.x;\n ringNormal.z = ringVertex.z;\n ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;\n ringNormal.normalize();\n }\n // keep first ring vertex values for enclose\n if (j === 0) {\n ringFirstVertex.copyFrom(ringVertex);\n ringFirstNormal.copyFrom(ringNormal);\n }\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\n normals.push(ringNormal.x, ringNormal.y, ringNormal.z);\n if (hasRings) {\n v = cs !== s ? faceUV[s].y : faceUV[s].w;\n }\n else {\n v = faceUV[s].y + (faceUV[s].w - faceUV[s].y) * h;\n }\n uvs.push(faceUV[s].x + ((faceUV[s].z - faceUV[s].x) * j) / tessellation, v);\n if (faceColors) {\n colors.push(faceColors[s].r, faceColors[s].g, faceColors[s].b, faceColors[s].a);\n }\n }\n // if enclose, add four vertices and their dedicated normals\n if (arc !== 1 && enclose) {\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\n positions.push(0, ringVertex.y, 0);\n positions.push(0, ringVertex.y, 0);\n positions.push(ringFirstVertex.x, ringFirstVertex.y, ringFirstVertex.z);\n Vector3.CrossToRef(Y, ringNormal, quadNormal);\n quadNormal.normalize();\n normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);\n Vector3.CrossToRef(ringFirstNormal, Y, quadNormal);\n quadNormal.normalize();\n normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);\n if (hasRings) {\n v = cs !== s ? faceUV[s + 1].y : faceUV[s + 1].w;\n }\n else {\n v = faceUV[s + 1].y + (faceUV[s + 1].w - faceUV[s + 1].y) * h;\n }\n uvs.push(faceUV[s + 1].x, v);\n uvs.push(faceUV[s + 1].z, v);\n if (hasRings) {\n v = cs !== s ? faceUV[s + 2].y : faceUV[s + 2].w;\n }\n else {\n v = faceUV[s + 2].y + (faceUV[s + 2].w - faceUV[s + 2].y) * h;\n }\n uvs.push(faceUV[s + 2].x, v);\n uvs.push(faceUV[s + 2].z, v);\n if (faceColors) {\n colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);\n colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);\n colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);\n colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);\n }\n }\n if (cs !== s) {\n cs = s;\n }\n }\n }\n // indices\n const e = arc !== 1 && enclose ? tessellation + 4 : tessellation; // correction of number of iteration if enclose\n let sI;\n i = 0;\n for (sI = 0; sI < subdivisions; sI++) {\n let i0 = 0;\n let i1 = 0;\n let i2 = 0;\n let i3 = 0;\n for (j = 0; j < tessellation; j++) {\n i0 = i * (e + 1) + j; // top left\n i1 = (i + 1) * (e + 1) + j; // bottom left\n i2 = i * (e + 1) + (j + 1); // top right\n i3 = (i + 1) * (e + 1) + (j + 1); // bottom right\n indices.push(i0, i1, i2);\n indices.push(i3, i2, i1);\n }\n if (arc !== 1 && enclose) {\n // if enclose, add two quads\n indices.push(i0 + 2, i1 + 2, i2 + 2);\n indices.push(i3 + 2, i2 + 2, i1 + 2);\n indices.push(i0 + 4, i1 + 4, i2 + 4);\n indices.push(i3 + 4, i2 + 4, i1 + 4);\n }\n else if (arc === 1) {\n indices.push(i2, i3, i * (e + 1));\n indices.push((i + 1) * (e + 1), i * (e + 1), i3);\n }\n i = hasRings ? i + 2 : i + 1;\n }\n // Caps\n const createCylinderCap = (isTop) => {\n const radius = isTop ? diameterTop / 2 : diameterBottom / 2;\n if (radius === 0) {\n return;\n }\n // Cap positions, normals & uvs\n let angle;\n let circleVector;\n let i;\n const u = isTop ? faceUV[surfaceNb - 1] : faceUV[0];\n let c = null;\n if (faceColors) {\n c = isTop ? faceColors[surfaceNb - 1] : faceColors[0];\n }\n // cap center\n const vbase = positions.length / 3;\n const offset = isTop ? height / 2 : -height / 2;\n const center = new Vector3(0, offset, 0);\n positions.push(center.x, center.y, center.z);\n normals.push(0, isTop ? 1 : -1, 0);\n uvs.push(u.x + (u.z - u.x) * 0.5, u.y + (u.w - u.y) * 0.5);\n if (c) {\n colors.push(c.r, c.g, c.b, c.a);\n }\n const textureScale = new Vector2(0.5, 0.5);\n for (i = 0; i <= tessellation; i++) {\n angle = i * angle_step;\n const cos = Math.cos(-angle);\n const sin = Math.sin(-angle);\n circleVector = new Vector3(cos * radius, offset, sin * radius);\n const textureCoordinate = new Vector2(cos * textureScale.x + 0.5, sin * textureScale.y + 0.5);\n positions.push(circleVector.x, circleVector.y, circleVector.z);\n normals.push(0, isTop ? 1 : -1, 0);\n uvs.push(u.x + (u.z - u.x) * textureCoordinate.x, u.y + (u.w - u.y) * textureCoordinate.y);\n if (c) {\n colors.push(c.r, c.g, c.b, c.a);\n }\n }\n // Cap indices\n for (i = 0; i < tessellation; i++) {\n if (!isTop) {\n indices.push(vbase);\n indices.push(vbase + (i + 1));\n indices.push(vbase + (i + 2));\n }\n else {\n indices.push(vbase);\n indices.push(vbase + (i + 2));\n indices.push(vbase + (i + 1));\n }\n }\n // Close the loop\n if (arc === 1) {\n if (!isTop) {\n indices.push(vbase, vbase + tessellation + 1, vbase + 1);\n }\n else {\n indices.push(vbase, vbase + 1, vbase + tessellation + 1);\n }\n }\n };\n // add caps to geometry based on cap parameter\n if (cap === Mesh.CAP_START || cap === Mesh.CAP_ALL) {\n createCylinderCap(false);\n }\n if (cap === Mesh.CAP_END || cap === Mesh.CAP_ALL) {\n createCylinderCap(true);\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n if (faceColors) {\n vertexData.colors = colors;\n }\n return vertexData;\n }\n }\n }\n\n /**\n * Class containing static functions to help procedurally build meshes\n */\n class DiscBuilder {\n /**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\n */\n static CreateDisc(name, options, scene) {\n const disc = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n disc._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = createDisc(options);\n vertexData.applyToMesh(disc, options.updatable);\n return disc;\n function createDisc(options) {\n const positions = new Array();\n const indices = new Array();\n const normals = new Array();\n const uvs = new Array();\n const radius = options.radius || 0.5;\n const tessellation = options.tessellation || 64;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // positions and uvs\n positions.push(0, 0, 0); // disc center first\n uvs.push(0.5, 0.5);\n const theta = Math.PI * 2 * arc;\n const step = theta / tessellation;\n for (let a = 0; arc === 1 ? a < theta : a <= theta; a += step) {\n const x = Math.cos(a);\n const y = Math.sin(a);\n const u = (x + 1) / 2;\n const v = (1 - y) / 2;\n positions.push(radius * x, radius * y, 0);\n uvs.push(u, v);\n }\n //indices\n const vertexNb = positions.length / 3;\n for (let i = 1; i < vertexNb - 1; i++) {\n indices.push(i + 1, 0, i);\n }\n if (arc === 1) {\n indices.push(1, 0, vertexNb - 1); // close the circle\n }\n // result\n VertexData.ComputeNormals(positions, indices, normals);\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n }\n }\n\n /**\n * Class containing static functions to help procedurally build meshes\n */\n class PlaneBuilder$1 {\n /**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\n */\n static CreatePlane(name, options, scene) {\n const plane = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const flipTile = options.pattern || Mesh.NO_FLIP;\n const tileWidth = options.tileWidth || options.tileSize || 1;\n const tileHeight = options.tileHeight || options.tileSize || 1;\n const alignH = options.alignHorizontal || 0;\n const alignV = options.alignVertical || 0;\n const width = options.width || options.size || 1;\n const tilesX = Math.floor(width / tileWidth);\n let offsetX = width - tilesX * tileWidth;\n const height = options.height || options.size || 1;\n const tilesY = Math.floor(height / tileHeight);\n let offsetY = height - tilesY * tileHeight;\n const halfWidth = (tileWidth * tilesX) / 2;\n const halfHeight = (tileHeight * tilesY) / 2;\n const indices = [];\n const positions = [];\n const normals = new Float32Array(tilesX * tilesY * 12);\n const colorSetArray = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];\n const normalSetArray = [0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1];\n const colorSet = Float32Array.from(colorSetArray);\n const normalSet = Float32Array.from(normalSetArray);\n let adjustX = 0;\n let adjustY = 0;\n let startX = 0;\n let startY = 0;\n let endX = 0;\n let endY = 0;\n //Part Tiles\n if (offsetX > 0 || offsetY > 0) {\n startX = -halfWidth;\n startY = -halfHeight;\n endX = halfWidth;\n endY = halfHeight;\n switch (alignH) {\n case Mesh.CENTER:\n offsetX /= 2;\n startX -= offsetX;\n endX += offsetX;\n break;\n case Mesh.LEFT:\n endX += offsetX;\n adjustX = -offsetX / 2;\n break;\n case Mesh.RIGHT:\n startX -= offsetX;\n adjustX = offsetX / 2;\n break;\n }\n switch (alignV) {\n case Mesh.CENTER:\n offsetY /= 2;\n startY -= offsetY;\n endY += offsetY;\n break;\n case Mesh.BOTTOM:\n endY += offsetY;\n adjustY = -offsetY / 2;\n break;\n case Mesh.TOP:\n startY -= offsetY;\n adjustY = offsetY / 2;\n break;\n }\n }\n const uvBase = [];\n uvBase[0] = [0, 0, 1, 0, 1, 1, 0, 1];\n uvBase[1] = [0, 0, 1, 0, 1, 1, 0, 1];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBase[1] = [1, 1, 0, 1, 0, 0, 1, 0];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBase[1] = [1, 0, 0, 0, 0, 1, 1, 1];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBase[1] = [0, 1, 1, 1, 1, 0, 0, 0];\n }\n const uvs = new Float32Array(tilesY * tilesX * 8);\n const colors = new Float32Array(tilesY * tilesX * 16);\n let index = 0;\n for (let y = 0; y < tilesY; y++) {\n for (let x = 0; x < tilesX; x++) {\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n if (flipTile === Mesh.FLIP_TILE ||\n flipTile === Mesh.ROTATE_TILE ||\n flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs.set(uvBase[((x % 2) + (y % 2)) % 2], index * 2);\n }\n else if (flipTile === Mesh.FLIP_ROW ||\n flipTile === Mesh.ROTATE_ROW ||\n flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs.set(uvBase[y % 2], index * 2);\n }\n else {\n uvs.set(uvBase[0], index * 2);\n }\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n index += 4;\n }\n }\n //Part Tiles\n if (offsetX > 0 || offsetY > 0) {\n const partialBottomRow = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.TOP);\n const partialTopRow = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.BOTTOM);\n const partialLeftCol = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.RIGHT);\n const partialRightCol = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.LEFT);\n let uvPart = [];\n let a, b, c, d;\n //corners\n if (partialBottomRow && partialLeftCol) {\n //bottom left corner\n positions.push(startX + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + adjustX, startY + offsetY + adjustY, 0);\n positions.push(startX + adjustX, startY + offsetY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 1 - offsetX / tileWidth;\n b = 1 - offsetY / tileHeight;\n c = 1;\n d = 1;\n uvPart = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_ROW) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_ROW) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs.set(uvPart, index * 2);\n uvs.set(uvPart, index);\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n if (partialBottomRow && partialRightCol) {\n //bottom right corner\n positions.push(halfWidth + adjustX, startY + adjustY, 0);\n positions.push(endX + adjustX, startY + adjustY, 0);\n positions.push(endX + adjustX, startY + offsetY + adjustY, 0);\n positions.push(halfWidth + adjustX, startY + offsetY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 0;\n b = 1 - offsetY / tileHeight;\n c = offsetX / tileWidth;\n d = 1;\n uvPart = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_ROW || (flipTile === Mesh.ROTATE_TILE && tilesX % 2 === 0)) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_ROW || (flipTile === Mesh.FLIP_TILE && tilesX % 2 === 0)) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW || (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesX % 2 === 0)) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs.set(uvPart, index * 2);\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n if (partialTopRow && partialLeftCol) {\n //top left corner\n positions.push(startX + adjustX, halfHeight + adjustY, 0);\n positions.push(-halfWidth + adjustX, halfHeight + adjustY, 0);\n positions.push(-halfWidth + adjustX, endY + adjustY, 0);\n positions.push(startX + adjustX, endY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 1 - offsetX / tileWidth;\n b = 0;\n c = 1;\n d = offsetY / tileHeight;\n uvPart = [a, b, c, b, c, d, a, d];\n if ((flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) ||\n (flipTile === Mesh.ROTATE_TILE && tilesY % 1 === 0)) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if ((flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) ||\n (flipTile === Mesh.FLIP_TILE && tilesY % 2 === 0)) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if ((flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) ||\n (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesY % 2 === 0)) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs.set(uvPart, index * 2);\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n if (partialTopRow && partialRightCol) {\n //top right corner\n positions.push(halfWidth + adjustX, halfHeight + adjustY, 0);\n positions.push(endX + adjustX, halfHeight + adjustY, 0);\n positions.push(endX + adjustX, endY + adjustY, 0);\n positions.push(halfWidth + adjustX, endY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n a = 0;\n b = 0;\n c = offsetX / tileWidth;\n d = offsetY / tileHeight;\n uvPart = [a, b, c, b, c, d, a, d];\n if ((flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) ||\n (flipTile === Mesh.ROTATE_TILE && (tilesY + tilesX) % 2 === 1)) {\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if ((flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) ||\n (flipTile === Mesh.FLIP_TILE && (tilesY + tilesX) % 2 === 1)) {\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if ((flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) ||\n (flipTile === Mesh.FLIP_N_ROTATE_TILE && (tilesY + tilesX) % 2 === 1)) {\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n uvs.set(uvPart, index * 2);\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n //part rows\n if (partialBottomRow) {\n const uvBaseBR = [];\n a = 0;\n b = 1 - offsetY / tileHeight;\n c = 1;\n d = 1;\n uvBaseBR[0] = [a, b, c, b, c, d, a, d];\n uvBaseBR[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseBR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseBR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseBR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let x = 0; x < tilesX; x++) {\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + offsetY + adjustY, 0);\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + offsetY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE ||\n flipTile === Mesh.ROTATE_TILE ||\n flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs.set(uvBaseBR[(x + 1) % 2], index * 2);\n }\n else if (flipTile === Mesh.FLIP_ROW ||\n flipTile === Mesh.ROTATE_ROW ||\n flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs.set(uvBaseBR[1], index * 2);\n }\n else {\n uvs.set(uvBaseBR[0], index * 2);\n }\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n }\n if (partialTopRow) {\n const uvBaseTR = [];\n a = 0;\n b = 0;\n c = 1;\n d = offsetY / tileHeight;\n uvBaseTR[0] = [a, b, c, b, c, d, a, d];\n uvBaseTR[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseTR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseTR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseTR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let x = 0; x < tilesX; x++) {\n positions.push(-halfWidth + x * tileWidth + adjustX, endY - offsetY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY - offsetY + adjustY, 0);\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY + adjustY, 0);\n positions.push(-halfWidth + x * tileWidth + adjustX, endY + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE ||\n flipTile === Mesh.ROTATE_TILE ||\n flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs.set(uvBaseTR[(x + tilesY) % 2], index * 2);\n }\n else if (flipTile === Mesh.FLIP_ROW ||\n flipTile === Mesh.ROTATE_ROW ||\n flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs.set(uvBaseTR[tilesY % 2], index * 2);\n }\n else {\n uvs.set(uvBaseTR[0], index * 2);\n }\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n }\n if (partialLeftCol) {\n const uvBaseLC = [];\n a = 1 - offsetX / tileWidth;\n b = 0;\n c = 1;\n d = 1;\n uvBaseLC[0] = [a, b, c, b, c, d, a, d];\n uvBaseLC[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseLC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseLC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseLC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let y = 0; y < tilesY; y++) {\n positions.push(startX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(startX + offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(startX + offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n positions.push(startX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE ||\n flipTile === Mesh.ROTATE_TILE ||\n flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs.set(uvBaseLC[(y + 1) % 2], index * 2);\n }\n else if (flipTile === Mesh.FLIP_ROW ||\n flipTile === Mesh.ROTATE_ROW ||\n flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs.set(uvBaseLC[y % 2], index * 2);\n }\n else {\n uvs.set(uvBaseLC[0], index * 2);\n }\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n }\n if (partialRightCol) {\n const uvBaseRC = [];\n a = 0;\n b = 0;\n c = offsetX / tileHeight;\n d = 1;\n uvBaseRC[0] = [a, b, c, b, c, d, a, d];\n uvBaseRC[1] = [a, b, c, b, c, d, a, d];\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\n uvBaseRC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\n }\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\n uvBaseRC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\n }\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvBaseRC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\n }\n for (let y = 0; y < tilesY; y++) {\n positions.push(endX - offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(endX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\n positions.push(endX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n positions.push(endX - offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\n index += 4;\n if (flipTile === Mesh.FLIP_TILE ||\n flipTile === Mesh.ROTATE_TILE ||\n flipTile === Mesh.FLIP_N_ROTATE_TILE) {\n uvs.set(uvBaseRC[(y + tilesX) % 2], index * 2);\n }\n else if (flipTile === Mesh.FLIP_ROW ||\n flipTile === Mesh.ROTATE_ROW ||\n flipTile === Mesh.FLIP_N_ROTATE_ROW) {\n uvs.set(uvBaseRC[y % 2], index * 2);\n }\n else {\n uvs.set(uvBaseRC[0], index * 2);\n }\n colors.set(colorSet, index * 4);\n normals.set(normalSet, index * 3);\n }\n }\n }\n //reverse V values since old PlaneBuilder built them that way\n for (let i = 0; i < uvs.length / 2; i++) {\n uvs[i * 2 + 1] = 1 - uvs[i * 2 + 1];\n }\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n vertexData.applyToMesh(plane, options.updatable);\n return plane;\n }\n }\n\n /**\n * Class containing static functions to help procedurally build meshes\n */\n class SphereBuilder$1 {\n /**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\n */\n static CreateSphere(name, options, scene) {\n const sphere = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n sphere._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = createSphere(options);\n vertexData.applyToMesh(sphere, options.updatable);\n return sphere;\n function createSphere(options) {\n const segments = options.segments || 32;\n const diameterX = options.diameterX || options.diameter || 1;\n const diameterY = options.diameterY || options.diameter || 1;\n const diameterZ = options.diameterZ || options.diameter || 1;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n const sliceStart = options.sliceStart && (options.sliceStart < 0 || options.sliceStart > 1) ? 0 : options.sliceStart || 0;\n let slice = options.slice && options.slice <= 0 ? 1.0 : options.slice || 1.0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n if (slice + sliceStart > 1) {\n slice = 1 - sliceStart;\n }\n const radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);\n const totalZRotationSteps = 2 + segments;\n const totalYRotationSegments = 2 * totalZRotationSteps;\n const totalYRotationSteps = totalYRotationSegments + 1;\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {\n const normalizedZ = zRotationStep / totalZRotationSteps;\n const angleZ = normalizedZ * Math.PI * slice + sliceStart * Math.PI;\n for (let yRotationStep = 0; yRotationStep < totalYRotationSteps; yRotationStep++) {\n const normalizedY = yRotationStep / totalYRotationSegments;\n const angleY = normalizedY * Math.PI * 2 * arc;\n const rotationZ = Matrix.RotationZ(-angleZ);\n const rotationY = Matrix.RotationY(angleY);\n const afterRotZ = Vector3.TransformCoordinates(Vector3.Up(), rotationZ);\n const complete = Vector3.TransformCoordinates(afterRotZ, rotationY);\n const vertex = complete.multiply(radius);\n const normal = complete.divide(radius).normalize();\n positions.push(vertex.x, vertex.y, vertex.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(normalizedY, 1 - normalizedZ);\n if (yRotationStep < totalYRotationSegments || arc === 1) {\n const nextYStep = (yRotationStep + 1) % totalYRotationSteps;\n if (sliceStart === 0 && zRotationStep === 0) {\n indices.push(0); // C\n indices.push(nextYStep); // B\n indices.push(yRotationStep); // A\n }\n else if (zRotationStep > 0) {\n indices.push((zRotationStep - 1) * totalYRotationSteps + yRotationStep); // C\n indices.push(zRotationStep * totalYRotationSteps + nextYStep); // B\n indices.push(zRotationStep * totalYRotationSteps + yRotationStep); // A\n indices.push((zRotationStep - 1) * totalYRotationSteps + yRotationStep); // C\n indices.push((zRotationStep - 1) * totalYRotationSteps + nextYStep); // D\n indices.push(zRotationStep * totalYRotationSteps + nextYStep); // B\n }\n }\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n }\n }\n\n /**\n * Class containing static functions to help procedurally build meshes\n */\n class TorusBuilder {\n /**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\n */\n static CreateTorus(name, options, scene) {\n const torus = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n torus._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = createTorus(options);\n vertexData.applyToMesh(torus, options.updatable);\n return torus;\n function createTorus(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n const diameter = options.diameter || 1;\n const thickness = options.thickness || 0.5;\n const tessellation = options.tessellation || 12;\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\n let slice = options.slice && options.slice <= 0 ? 1.0 : options.slice || 1.0;\n const sliceStart = options.sliceStart && (options.sliceStart < 0 || options.sliceStart > 1) ? 0 : options.sliceStart || 0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n if (slice + sliceStart > 1) {\n slice = 1 - sliceStart;\n }\n const outerSegments = Math.ceil(tessellation * arc * Math.PI); // Need more segments for the torus circumference\n const innerSegments = Math.ceil(tessellation * slice);\n const closedRing = arc === 1; // handle float errors\n const closedTube = slice === 1;\n const lastOuterRing = outerSegments + 1;\n const lastTubeSection = innerSegments + 1;\n for (let i = 0; i < lastOuterRing; i++) {\n const u = i / outerSegments;\n const outerAngle = u * (arc * Math.PI * 2) - Math.PI / 2;\n const transform = Matrix.Translation(diameter / 2, 0, 0).multiply(Matrix.RotationY(outerAngle));\n for (let j = 0; j < lastTubeSection; j++) {\n const v = 1 - j / innerSegments;\n const innerAngle = (j / innerSegments) * (Math.PI * 2 * slice) + Math.PI * 2 * sliceStart;\n const dx = Math.cos(innerAngle);\n const dy = Math.sin(innerAngle);\n // Create a vertex.\n let normal = new Vector3(dx, dy, 0);\n let position = normal.scale(thickness / 2);\n const textureCoordinate = new Vector2(u, v);\n position = Vector3.TransformCoordinates(position, transform);\n normal = Vector3.TransformNormal(normal, transform);\n positions.push(position.x, position.y, position.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(textureCoordinate.x, textureCoordinate.y);\n if ((i < outerSegments || closedRing) && (j < innerSegments || closedTube)) {\n // And create indices for two triangles.\n const nextI = (i + 1) % lastOuterRing;\n const nextJ = (j + 1) % lastTubeSection;\n indices.push(i * lastTubeSection + j); // A\n indices.push(i * lastTubeSection + nextJ); // B\n indices.push(nextI * lastTubeSection + j); // C\n indices.push(i * lastTubeSection + nextJ); // B\n indices.push(nextI * lastTubeSection + nextJ); // D\n indices.push(nextI * lastTubeSection + j); // C\n }\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n }\n }\n }\n\n function parseSketchGeometry(vertexData) {\n const segments = [];\n const holes = new Map();\n if (vertexData && vertexData.positions && vertexData.paths) {\n const paths = vertexData.paths;\n const holeIndices = new Map();\n if (vertexData.holes) {\n for (let i = 0; i < vertexData.holes.length; i += 2) {\n holeIndices.set(vertexData.holes[i + 1], vertexData.holes[i]);\n }\n }\n let i = 0;\n let currentHole = null;\n while (i < paths.length) {\n const positions = vertexData.positions;\n const segmentPoints = [];\n currentHole = holeIndices.has(i) ? holeIndices.get(i) : null;\n for (; i < paths.length; i += 2) {\n segmentPoints.push(Vector3.FromArray(positions, paths[i] * 3));\n if (paths[i + 2] !== paths[i + 1]) {\n segmentPoints.push(Vector3.FromArray(positions, paths[i + 1] * 3));\n i += 2;\n break;\n }\n }\n if (segmentPoints.length > 1) {\n if (currentHole !== null) {\n let currentHolePoints = holes.get(currentHole);\n if (!currentHolePoints) {\n currentHolePoints = [];\n holes.set(currentHole, currentHolePoints);\n }\n currentHolePoints.push(segmentPoints);\n }\n else {\n segments.push(segmentPoints);\n }\n }\n }\n }\n return { segments, holes };\n }\n function createSketchPointForEditor(manager, path, insertIndex) {\n if (!path._parent) {\n throw new Error('Cannot create a sketch point for a path that has no parent sketch');\n }\n const sketch = path._parent;\n const c = manager.create(Token.SketchControlPoint);\n c.name = 'Control Point';\n while (path.controlPoints.find(ec => ec.name === c.name)) {\n c.name = appendOrIncrementNumber(c.name);\n }\n let previousControlPoint;\n if (!insertIndex) {\n // If insert index is zero or undefined, determine the previous control point and use its position for the new control point\n if (path.controlPoints.length > 0 && insertIndex === undefined) {\n previousControlPoint = path.controlPoints[path.controlPoints.length - 1];\n }\n else {\n const currentPathIndex = sketch.paths.findIndex(p => p._dynamicId === path._dynamicId);\n if (currentPathIndex > 0) {\n const previousPath = sketch.paths[currentPathIndex - 1];\n if (previousPath.controlPoints.length > 0) {\n previousControlPoint = previousPath.controlPoints[previousPath.controlPoints.length - 1];\n }\n }\n }\n }\n else {\n previousControlPoint = path.controlPoints[insertIndex];\n }\n const sketchNormal = getSketchNormalVector3(sketch.normal);\n // determine the axis making up the sketch plane so we can make sure the direction vectors are on the sketch plane\n let axis1;\n if (sketchNormal.equalsWithEpsilon(Vector3.Forward()) || sketchNormal.equalsWithEpsilon(Vector3.Backward())) {\n axis1 = Vector3.Up();\n }\n else {\n axis1 = Vector3.Cross(sketchNormal, Vector3.Forward());\n }\n const axis2 = Vector3.Cross(sketchNormal, axis1);\n if (previousControlPoint) {\n // if therre is a previous control point, project its direction onto the sketch plane\n c.position = previousControlPoint.position.clone();\n const rawDirection = previousControlPoint.direction.toVec3();\n const projectedDirection = axis1\n .scale(Vector3.Dot(axis1, rawDirection))\n .add(axis2.scale(Vector3.Dot(axis2, rawDirection)));\n c.direction = exports.KbVector.FromVec3(projectedDirection);\n }\n else {\n // if this is the first control point, just pick a direction vector on the sketch plane\n c.direction = exports.KbVector.FromVec3(axis1);\n }\n c.direction2 = c.direction.scale(-1);\n if (insertIndex === undefined) {\n path.controlPoints.push(c);\n }\n else {\n path.controlPoints.splice(insertIndex, 0, c);\n }\n for (const eC of path.controlPoints) {\n eC._expanded = false;\n }\n c._visible = true;\n c._expanded = true;\n return c;\n }\n function getSketchNormalVector3(normal) {\n let planeNormal;\n switch (normal) {\n case exports.eAxis.x:\n planeNormal = Vector3.Right();\n break;\n case exports.eAxis.y:\n planeNormal = Vector3.Up();\n break;\n case exports.eAxis.z:\n planeNormal = Vector3.Forward();\n break;\n default:\n planeNormal = normal.toVec3();\n }\n planeNormal.normalize();\n return planeNormal;\n }\n function projectOnNodeAxis(node, x, y) {\n switch (node.normal) {\n case exports.eAxis.y:\n return new exports.KbVector(x, 0, -y);\n case exports.eAxis.z:\n return new exports.KbVector(-x, y, 0);\n default:\n return new exports.KbVector(0, y, x);\n }\n }\n function axisToVector3(axis) {\n switch (axis) {\n case exports.eAxis.y:\n return Vector3.Up();\n case exports.eAxis.z:\n return Vector3.Forward();\n default:\n return Vector3.Right();\n }\n }\n /**\n * returns the vertices in the order of positionVectors in sequence, followed by holePositions in sequence!\n * Indices will have to be recalculated if the vertex data is replaced with the results of this function.\n */\n function fillSketchPolygon(positionVectors, flipNormals, sketchNativeNormal, holePositions) {\n const sketchNormal = getPolygonNormal(positionVectors);\n if (flipNormals) {\n sketchNormal.scaleInPlace(-1);\n }\n // const geometryNormal = sketchNormal.scale(-1);\n const segmentPositions = [];\n let segmentIndices = [];\n for (let i = 0; i < positionVectors.length; i++) {\n const point = positionVectors[i];\n segmentPositions.push(point.x, point.y, point.z);\n }\n const holes = [];\n if (holePositions) {\n for (let i = 0; i < holePositions.length; i++) {\n const hole = holePositions[i];\n holes.push(segmentPositions.length / 3);\n for (let i = 0; i < hole.length; i++) {\n const point = hole[i];\n segmentPositions.push(point.x, point.y, point.z);\n }\n }\n }\n if (Math.abs(Vector3.Dot(sketchNormal, Vector3.UpReadOnly)) > 0.95) {\n const flatPositions = new Float32Array((segmentPositions.length * 2) / 3);\n const xAxis = Vector3.Cross(sketchNormal, new Vector3(0, 0, 1));\n const yAxis = Vector3.Cross(sketchNormal, xAxis);\n const working = new Vector3();\n for (let i = 0; i < segmentPositions.length; i += 3) {\n working.set(segmentPositions[i], segmentPositions[i + 1], segmentPositions[i + 2]);\n flatPositions.set([Vector3.Dot(working, xAxis), Vector3.Dot(working, yAxis)], (i * 2) / 3);\n }\n const faceNormal = calculateFaceNormalFromFloats(flatPositions, 2);\n if (Vector3.Dot(faceNormal, Vector3.RightHandedForwardReadOnly) < 0) {\n for (let i = 0; i < flatPositions.length; i += 2) {\n const tmp = flatPositions[i];\n flatPositions[i] = flatPositions[i + 1];\n flatPositions[i + 1] = tmp;\n }\n // geometryNormal.scaleInPlace(-1);\n }\n segmentIndices = earcut$1(flatPositions, holes, 2);\n }\n else {\n segmentIndices = earcut$1(segmentPositions, holes, 3);\n // Flip the geometry if needed so that it faces the same direction as the faces because earcut isn't aware of the 3d space\n const faceNormal = calculateFaceNormal(positionVectors);\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\n if (Vector3.Dot(faceNormal, sketchNativeNormal) < 0) {\n for (let i = 0; i < segmentIndices.length; i += 3) {\n const tmp = segmentIndices[i];\n segmentIndices[i] = segmentIndices[i + 2];\n segmentIndices[i + 2] = tmp;\n }\n // geometryNormal.scaleInPlace(-1);\n }\n }\n const segmentNormals = [];\n const geometryNormal = calculateFaceNormal(positionVectors);\n if (flipNormals) {\n geometryNormal.scaleInPlace(-1);\n }\n let totalVectorCount = positionVectors.length;\n if (holePositions) {\n totalVectorCount += holePositions.flat().length;\n }\n for (let i = 0; i < totalVectorCount; i++) {\n segmentNormals.push(geometryNormal.x, geometryNormal.y, geometryNormal.z);\n }\n const segmentUvs = [];\n for (let i = 0; i < totalVectorCount; i++) {\n segmentUvs.push(0, 0);\n }\n return {\n normals: segmentNormals,\n positions: segmentPositions,\n indices: segmentIndices,\n uvs: segmentUvs,\n };\n }\n function calculateFaceNormal(positionVectors) {\n const v1 = Vector3.Zero();\n const v2 = Vector3.Zero();\n const barycenter = Vector3.Zero();\n for (let i = 0; i < positionVectors.length; i++) {\n barycenter.addInPlace(positionVectors[i]);\n }\n barycenter.scaleInPlace(1 / positionVectors.length);\n const pathHandedness = Vector3.Zero();\n if (positionVectors.length > 1) {\n for (let iP = 0; iP < positionVectors.length - 1; iP++) {\n const point1 = positionVectors[iP];\n v1.copyFromFloats(point1.x, point1.y, point1.z);\n v1.subtractInPlace(barycenter);\n const point2 = positionVectors[iP + 1];\n v2.copyFromFloats(point2.x, point2.y, point2.z);\n v2.subtractInPlace(barycenter);\n pathHandedness.addInPlace(Vector3.Cross(v1, v2));\n }\n return pathHandedness.normalize();\n }\n return Vector3.Zero();\n }\n function calculateFaceNormalFromFloats(points, dim) {\n const v1 = Vector3.Zero();\n const v2 = Vector3.Zero();\n const barycenter = Vector3.Zero();\n for (let i = 0; i < points.length; i += dim) {\n barycenter.addInPlaceFromFloats(points[i], points[i + 1], dim === 3 ? points[i + 2] : 0);\n }\n barycenter.scaleInPlace(3 / points.length);\n const pathHandedness = Vector3.Zero();\n if (points.length > 3) {\n for (let i = 0; i < points.length - dim; i += dim) {\n v1.copyFromFloats(points[i], points[i + 1], dim === 3 ? points[i + 2] : 0);\n v1.subtractInPlace(barycenter);\n v2.copyFromFloats(points[i + dim], points[i + dim + 1], dim === 3 ? points[i + dim + 2] : 0);\n v2.subtractInPlace(barycenter);\n pathHandedness.addInPlace(Vector3.Cross(v1, v2));\n }\n return pathHandedness.normalize();\n }\n return Vector3.Zero();\n }\n\n /**\n * https://opentype.js.org v1.3.4 | (c) Frederik De Bleser and other contributors | MIT License | Uses tiny-inflate by Devon Govett and string.prototype.codepointat polyfill by Mathias Bynens\n */\n\n /*! https://mths.be/codepointat v0.2.0 by @mathias */\n if (!String.prototype.codePointAt) {\n \t(function() {\n \t\tvar defineProperty = (function() {\n \t\t\t// IE 8 only supports `Object.defineProperty` on DOM elements\n \t\t\ttry {\n \t\t\t\tvar object = {};\n \t\t\t\tvar $defineProperty = Object.defineProperty;\n \t\t\t\tvar result = $defineProperty(object, object, object) && $defineProperty;\n \t\t\t} catch(error) {}\n \t\t\treturn result;\n \t\t}());\n \t\tvar codePointAt = function(position) {\n \t\t\tif (this == null) {\n \t\t\t\tthrow TypeError();\n \t\t\t}\n \t\t\tvar string = String(this);\n \t\t\tvar size = string.length;\n \t\t\t// `ToInteger`\n \t\t\tvar index = position ? Number(position) : 0;\n \t\t\tif (index != index) { // better `isNaN`\n \t\t\t\tindex = 0;\n \t\t\t}\n \t\t\t// Account for out-of-bounds indices:\n \t\t\tif (index < 0 || index >= size) {\n \t\t\t\treturn undefined;\n \t\t\t}\n \t\t\t// Get the first code unit\n \t\t\tvar first = string.charCodeAt(index);\n \t\t\tvar second;\n \t\t\tif ( // check if it’s the start of a surrogate pair\n \t\t\t\tfirst >= 0xD800 && first <= 0xDBFF && // high surrogate\n \t\t\t\tsize > index + 1 // there is a next code unit\n \t\t\t) {\n \t\t\t\tsecond = string.charCodeAt(index + 1);\n \t\t\t\tif (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate\n \t\t\t\t\t// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n \t\t\t\t\treturn (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;\n \t\t\t\t}\n \t\t\t}\n \t\t\treturn first;\n \t\t};\n \t\tif (defineProperty) {\n \t\t\tdefineProperty(String.prototype, 'codePointAt', {\n \t\t\t\t'value': codePointAt,\n \t\t\t\t'configurable': true,\n \t\t\t\t'writable': true\n \t\t\t});\n \t\t} else {\n \t\t\tString.prototype.codePointAt = codePointAt;\n \t\t}\n \t}());\n }\n\n var TINF_OK = 0;\n var TINF_DATA_ERROR = -3;\n\n function Tree() {\n this.table = new Uint16Array(16); /* table of code length counts */\n this.trans = new Uint16Array(288); /* code -> symbol translation table */\n }\n\n function Data(source, dest) {\n this.source = source;\n this.sourceIndex = 0;\n this.tag = 0;\n this.bitcount = 0;\n \n this.dest = dest;\n this.destLen = 0;\n \n this.ltree = new Tree(); /* dynamic length/symbol tree */\n this.dtree = new Tree(); /* dynamic distance tree */\n }\n\n /* --------------------------------------------------- *\n * -- uninitialized global data (static structures) -- *\n * --------------------------------------------------- */\n\n var sltree = new Tree();\n var sdtree = new Tree();\n\n /* extra bits and base tables for length codes */\n var length_bits = new Uint8Array(30);\n var length_base = new Uint16Array(30);\n\n /* extra bits and base tables for distance codes */\n var dist_bits = new Uint8Array(30);\n var dist_base = new Uint16Array(30);\n\n /* special ordering of code length codes */\n var clcidx = new Uint8Array([\n 16, 17, 18, 0, 8, 7, 9, 6,\n 10, 5, 11, 4, 12, 3, 13, 2,\n 14, 1, 15\n ]);\n\n /* used by tinf_decode_trees, avoids allocations every call */\n var code_tree = new Tree();\n var lengths = new Uint8Array(288 + 32);\n\n /* ----------------------- *\n * -- utility functions -- *\n * ----------------------- */\n\n /* build extra bits and base tables */\n function tinf_build_bits_base(bits, base, delta, first) {\n var i, sum;\n\n /* build bits table */\n for (i = 0; i < delta; ++i) { bits[i] = 0; }\n for (i = 0; i < 30 - delta; ++i) { bits[i + delta] = i / delta | 0; }\n\n /* build base table */\n for (sum = first, i = 0; i < 30; ++i) {\n base[i] = sum;\n sum += 1 << bits[i];\n }\n }\n\n /* build the fixed huffman trees */\n function tinf_build_fixed_trees(lt, dt) {\n var i;\n\n /* build fixed length tree */\n for (i = 0; i < 7; ++i) { lt.table[i] = 0; }\n\n lt.table[7] = 24;\n lt.table[8] = 152;\n lt.table[9] = 112;\n\n for (i = 0; i < 24; ++i) { lt.trans[i] = 256 + i; }\n for (i = 0; i < 144; ++i) { lt.trans[24 + i] = i; }\n for (i = 0; i < 8; ++i) { lt.trans[24 + 144 + i] = 280 + i; }\n for (i = 0; i < 112; ++i) { lt.trans[24 + 144 + 8 + i] = 144 + i; }\n\n /* build fixed distance tree */\n for (i = 0; i < 5; ++i) { dt.table[i] = 0; }\n\n dt.table[5] = 32;\n\n for (i = 0; i < 32; ++i) { dt.trans[i] = i; }\n }\n\n /* given an array of code lengths, build a tree */\n var offs = new Uint16Array(16);\n\n function tinf_build_tree(t, lengths, off, num) {\n var i, sum;\n\n /* clear code length count table */\n for (i = 0; i < 16; ++i) { t.table[i] = 0; }\n\n /* scan symbol lengths, and sum code length counts */\n for (i = 0; i < num; ++i) { t.table[lengths[off + i]]++; }\n\n t.table[0] = 0;\n\n /* compute offset table for distribution sort */\n for (sum = 0, i = 0; i < 16; ++i) {\n offs[i] = sum;\n sum += t.table[i];\n }\n\n /* create code->symbol translation table (symbols sorted by code) */\n for (i = 0; i < num; ++i) {\n if (lengths[off + i]) { t.trans[offs[lengths[off + i]]++] = i; }\n }\n }\n\n /* ---------------------- *\n * -- decode functions -- *\n * ---------------------- */\n\n /* get one bit from source stream */\n function tinf_getbit(d) {\n /* check if tag is empty */\n if (!d.bitcount--) {\n /* load next tag */\n d.tag = d.source[d.sourceIndex++];\n d.bitcount = 7;\n }\n\n /* shift bit out of tag */\n var bit = d.tag & 1;\n d.tag >>>= 1;\n\n return bit;\n }\n\n /* read a num bit value from a stream and add base */\n function tinf_read_bits(d, num, base) {\n if (!num)\n { return base; }\n\n while (d.bitcount < 24) {\n d.tag |= d.source[d.sourceIndex++] << d.bitcount;\n d.bitcount += 8;\n }\n\n var val = d.tag & (0xffff >>> (16 - num));\n d.tag >>>= num;\n d.bitcount -= num;\n return val + base;\n }\n\n /* given a data stream and a tree, decode a symbol */\n function tinf_decode_symbol(d, t) {\n while (d.bitcount < 24) {\n d.tag |= d.source[d.sourceIndex++] << d.bitcount;\n d.bitcount += 8;\n }\n \n var sum = 0, cur = 0, len = 0;\n var tag = d.tag;\n\n /* get more bits while code value is above sum */\n do {\n cur = 2 * cur + (tag & 1);\n tag >>>= 1;\n ++len;\n\n sum += t.table[len];\n cur -= t.table[len];\n } while (cur >= 0);\n \n d.tag = tag;\n d.bitcount -= len;\n\n return t.trans[sum + cur];\n }\n\n /* given a data stream, decode dynamic trees from it */\n function tinf_decode_trees(d, lt, dt) {\n var hlit, hdist, hclen;\n var i, num, length;\n\n /* get 5 bits HLIT (257-286) */\n hlit = tinf_read_bits(d, 5, 257);\n\n /* get 5 bits HDIST (1-32) */\n hdist = tinf_read_bits(d, 5, 1);\n\n /* get 4 bits HCLEN (4-19) */\n hclen = tinf_read_bits(d, 4, 4);\n\n for (i = 0; i < 19; ++i) { lengths[i] = 0; }\n\n /* read code lengths for code length alphabet */\n for (i = 0; i < hclen; ++i) {\n /* get 3 bits code length (0-7) */\n var clen = tinf_read_bits(d, 3, 0);\n lengths[clcidx[i]] = clen;\n }\n\n /* build code length tree */\n tinf_build_tree(code_tree, lengths, 0, 19);\n\n /* decode code lengths for the dynamic trees */\n for (num = 0; num < hlit + hdist;) {\n var sym = tinf_decode_symbol(d, code_tree);\n\n switch (sym) {\n case 16:\n /* copy previous code length 3-6 times (read 2 bits) */\n var prev = lengths[num - 1];\n for (length = tinf_read_bits(d, 2, 3); length; --length) {\n lengths[num++] = prev;\n }\n break;\n case 17:\n /* repeat code length 0 for 3-10 times (read 3 bits) */\n for (length = tinf_read_bits(d, 3, 3); length; --length) {\n lengths[num++] = 0;\n }\n break;\n case 18:\n /* repeat code length 0 for 11-138 times (read 7 bits) */\n for (length = tinf_read_bits(d, 7, 11); length; --length) {\n lengths[num++] = 0;\n }\n break;\n default:\n /* values 0-15 represent the actual code lengths */\n lengths[num++] = sym;\n break;\n }\n }\n\n /* build dynamic trees */\n tinf_build_tree(lt, lengths, 0, hlit);\n tinf_build_tree(dt, lengths, hlit, hdist);\n }\n\n /* ----------------------------- *\n * -- block inflate functions -- *\n * ----------------------------- */\n\n /* given a stream and two trees, inflate a block of data */\n function tinf_inflate_block_data(d, lt, dt) {\n while (1) {\n var sym = tinf_decode_symbol(d, lt);\n\n /* check for end of block */\n if (sym === 256) {\n return TINF_OK;\n }\n\n if (sym < 256) {\n d.dest[d.destLen++] = sym;\n } else {\n var length, dist, offs;\n var i;\n\n sym -= 257;\n\n /* possibly get more bits from length code */\n length = tinf_read_bits(d, length_bits[sym], length_base[sym]);\n\n dist = tinf_decode_symbol(d, dt);\n\n /* possibly get more bits from distance code */\n offs = d.destLen - tinf_read_bits(d, dist_bits[dist], dist_base[dist]);\n\n /* copy match */\n for (i = offs; i < offs + length; ++i) {\n d.dest[d.destLen++] = d.dest[i];\n }\n }\n }\n }\n\n /* inflate an uncompressed block of data */\n function tinf_inflate_uncompressed_block(d) {\n var length, invlength;\n var i;\n \n /* unread from bitbuffer */\n while (d.bitcount > 8) {\n d.sourceIndex--;\n d.bitcount -= 8;\n }\n\n /* get length */\n length = d.source[d.sourceIndex + 1];\n length = 256 * length + d.source[d.sourceIndex];\n\n /* get one's complement of length */\n invlength = d.source[d.sourceIndex + 3];\n invlength = 256 * invlength + d.source[d.sourceIndex + 2];\n\n /* check length */\n if (length !== (~invlength & 0x0000ffff))\n { return TINF_DATA_ERROR; }\n\n d.sourceIndex += 4;\n\n /* copy block */\n for (i = length; i; --i)\n { d.dest[d.destLen++] = d.source[d.sourceIndex++]; }\n\n /* make sure we start next block on a byte boundary */\n d.bitcount = 0;\n\n return TINF_OK;\n }\n\n /* inflate stream from source to dest */\n function tinf_uncompress(source, dest) {\n var d = new Data(source, dest);\n var bfinal, btype, res;\n\n do {\n /* read final block flag */\n bfinal = tinf_getbit(d);\n\n /* read block type (2 bits) */\n btype = tinf_read_bits(d, 2, 0);\n\n /* decompress block */\n switch (btype) {\n case 0:\n /* decompress uncompressed block */\n res = tinf_inflate_uncompressed_block(d);\n break;\n case 1:\n /* decompress block with fixed huffman trees */\n res = tinf_inflate_block_data(d, sltree, sdtree);\n break;\n case 2:\n /* decompress block with dynamic huffman trees */\n tinf_decode_trees(d, d.ltree, d.dtree);\n res = tinf_inflate_block_data(d, d.ltree, d.dtree);\n break;\n default:\n res = TINF_DATA_ERROR;\n }\n\n if (res !== TINF_OK)\n { throw new Error('Data error'); }\n\n } while (!bfinal);\n\n if (d.destLen < d.dest.length) {\n if (typeof d.dest.slice === 'function')\n { return d.dest.slice(0, d.destLen); }\n else\n { return d.dest.subarray(0, d.destLen); }\n }\n \n return d.dest;\n }\n\n /* -------------------- *\n * -- initialization -- *\n * -------------------- */\n\n /* build fixed huffman trees */\n tinf_build_fixed_trees(sltree, sdtree);\n\n /* build extra bits and base tables */\n tinf_build_bits_base(length_bits, length_base, 4, 3);\n tinf_build_bits_base(dist_bits, dist_base, 2, 1);\n\n /* fix a special case */\n length_bits[28] = 0;\n length_base[28] = 258;\n\n var tinyInflate = tinf_uncompress;\n\n // The Bounding Box object\n\n function derive(v0, v1, v2, v3, t) {\n return Math.pow(1 - t, 3) * v0 +\n 3 * Math.pow(1 - t, 2) * t * v1 +\n 3 * (1 - t) * Math.pow(t, 2) * v2 +\n Math.pow(t, 3) * v3;\n }\n /**\n * A bounding box is an enclosing box that describes the smallest measure within which all the points lie.\n * It is used to calculate the bounding box of a glyph or text path.\n *\n * On initialization, x1/y1/x2/y2 will be NaN. Check if the bounding box is empty using `isEmpty()`.\n *\n * @exports opentype.BoundingBox\n * @class\n * @constructor\n */\n function BoundingBox$1() {\n this.x1 = Number.NaN;\n this.y1 = Number.NaN;\n this.x2 = Number.NaN;\n this.y2 = Number.NaN;\n }\n\n /**\n * Returns true if the bounding box is empty, that is, no points have been added to the box yet.\n */\n BoundingBox$1.prototype.isEmpty = function() {\n return isNaN(this.x1) || isNaN(this.y1) || isNaN(this.x2) || isNaN(this.y2);\n };\n\n /**\n * Add the point to the bounding box.\n * The x1/y1/x2/y2 coordinates of the bounding box will now encompass the given point.\n * @param {number} x - The X coordinate of the point.\n * @param {number} y - The Y coordinate of the point.\n */\n BoundingBox$1.prototype.addPoint = function(x, y) {\n if (typeof x === 'number') {\n if (isNaN(this.x1) || isNaN(this.x2)) {\n this.x1 = x;\n this.x2 = x;\n }\n if (x < this.x1) {\n this.x1 = x;\n }\n if (x > this.x2) {\n this.x2 = x;\n }\n }\n if (typeof y === 'number') {\n if (isNaN(this.y1) || isNaN(this.y2)) {\n this.y1 = y;\n this.y2 = y;\n }\n if (y < this.y1) {\n this.y1 = y;\n }\n if (y > this.y2) {\n this.y2 = y;\n }\n }\n };\n\n /**\n * Add a X coordinate to the bounding box.\n * This extends the bounding box to include the X coordinate.\n * This function is used internally inside of addBezier.\n * @param {number} x - The X coordinate of the point.\n */\n BoundingBox$1.prototype.addX = function(x) {\n this.addPoint(x, null);\n };\n\n /**\n * Add a Y coordinate to the bounding box.\n * This extends the bounding box to include the Y coordinate.\n * This function is used internally inside of addBezier.\n * @param {number} y - The Y coordinate of the point.\n */\n BoundingBox$1.prototype.addY = function(y) {\n this.addPoint(null, y);\n };\n\n /**\n * Add a Bézier curve to the bounding box.\n * This extends the bounding box to include the entire Bézier.\n * @param {number} x0 - The starting X coordinate.\n * @param {number} y0 - The starting Y coordinate.\n * @param {number} x1 - The X coordinate of the first control point.\n * @param {number} y1 - The Y coordinate of the first control point.\n * @param {number} x2 - The X coordinate of the second control point.\n * @param {number} y2 - The Y coordinate of the second control point.\n * @param {number} x - The ending X coordinate.\n * @param {number} y - The ending Y coordinate.\n */\n BoundingBox$1.prototype.addBezier = function(x0, y0, x1, y1, x2, y2, x, y) {\n // This code is based on http://nishiohirokazu.blogspot.com/2009/06/how-to-calculate-bezier-curves-bounding.html\n // and https://github.com/icons8/svg-path-bounding-box\n\n var p0 = [x0, y0];\n var p1 = [x1, y1];\n var p2 = [x2, y2];\n var p3 = [x, y];\n\n this.addPoint(x0, y0);\n this.addPoint(x, y);\n\n for (var i = 0; i <= 1; i++) {\n var b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];\n var a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];\n var c = 3 * p1[i] - 3 * p0[i];\n\n if (a === 0) {\n if (b === 0) { continue; }\n var t = -c / b;\n if (0 < t && t < 1) {\n if (i === 0) { this.addX(derive(p0[i], p1[i], p2[i], p3[i], t)); }\n if (i === 1) { this.addY(derive(p0[i], p1[i], p2[i], p3[i], t)); }\n }\n continue;\n }\n\n var b2ac = Math.pow(b, 2) - 4 * c * a;\n if (b2ac < 0) { continue; }\n var t1 = (-b + Math.sqrt(b2ac)) / (2 * a);\n if (0 < t1 && t1 < 1) {\n if (i === 0) { this.addX(derive(p0[i], p1[i], p2[i], p3[i], t1)); }\n if (i === 1) { this.addY(derive(p0[i], p1[i], p2[i], p3[i], t1)); }\n }\n var t2 = (-b - Math.sqrt(b2ac)) / (2 * a);\n if (0 < t2 && t2 < 1) {\n if (i === 0) { this.addX(derive(p0[i], p1[i], p2[i], p3[i], t2)); }\n if (i === 1) { this.addY(derive(p0[i], p1[i], p2[i], p3[i], t2)); }\n }\n }\n };\n\n /**\n * Add a quadratic curve to the bounding box.\n * This extends the bounding box to include the entire quadratic curve.\n * @param {number} x0 - The starting X coordinate.\n * @param {number} y0 - The starting Y coordinate.\n * @param {number} x1 - The X coordinate of the control point.\n * @param {number} y1 - The Y coordinate of the control point.\n * @param {number} x - The ending X coordinate.\n * @param {number} y - The ending Y coordinate.\n */\n BoundingBox$1.prototype.addQuad = function(x0, y0, x1, y1, x, y) {\n var cp1x = x0 + 2 / 3 * (x1 - x0);\n var cp1y = y0 + 2 / 3 * (y1 - y0);\n var cp2x = cp1x + 1 / 3 * (x - x0);\n var cp2y = cp1y + 1 / 3 * (y - y0);\n this.addBezier(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y);\n };\n\n // Geometric objects\n\n /**\n * A bézier path containing a set of path commands similar to a SVG path.\n * Paths can be drawn on a context using `draw`.\n * @exports opentype.Path\n * @class\n * @constructor\n */\n function Path() {\n this.commands = [];\n this.fill = 'black';\n this.stroke = null;\n this.strokeWidth = 1;\n }\n\n /**\n * @param {number} x\n * @param {number} y\n */\n Path.prototype.moveTo = function(x, y) {\n this.commands.push({\n type: 'M',\n x: x,\n y: y\n });\n };\n\n /**\n * @param {number} x\n * @param {number} y\n */\n Path.prototype.lineTo = function(x, y) {\n this.commands.push({\n type: 'L',\n x: x,\n y: y\n });\n };\n\n /**\n * Draws cubic curve\n * @function\n * curveTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control 1\n * @param {number} y1 - y of control 1\n * @param {number} x2 - x of control 2\n * @param {number} y2 - y of control 2\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n */\n\n /**\n * Draws cubic curve\n * @function\n * bezierCurveTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control 1\n * @param {number} y1 - y of control 1\n * @param {number} x2 - x of control 2\n * @param {number} y2 - y of control 2\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n * @see curveTo\n */\n Path.prototype.curveTo = Path.prototype.bezierCurveTo = function(x1, y1, x2, y2, x, y) {\n this.commands.push({\n type: 'C',\n x1: x1,\n y1: y1,\n x2: x2,\n y2: y2,\n x: x,\n y: y\n });\n };\n\n /**\n * Draws quadratic curve\n * @function\n * quadraticCurveTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control\n * @param {number} y1 - y of control\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n */\n\n /**\n * Draws quadratic curve\n * @function\n * quadTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control\n * @param {number} y1 - y of control\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n */\n Path.prototype.quadTo = Path.prototype.quadraticCurveTo = function(x1, y1, x, y) {\n this.commands.push({\n type: 'Q',\n x1: x1,\n y1: y1,\n x: x,\n y: y\n });\n };\n\n /**\n * Closes the path\n * @function closePath\n * @memberof opentype.Path.prototype\n */\n\n /**\n * Close the path\n * @function close\n * @memberof opentype.Path.prototype\n */\n Path.prototype.close = Path.prototype.closePath = function() {\n this.commands.push({\n type: 'Z'\n });\n };\n\n /**\n * Add the given path or list of commands to the commands of this path.\n * @param {Array} pathOrCommands - another opentype.Path, an opentype.BoundingBox, or an array of commands.\n */\n Path.prototype.extend = function(pathOrCommands) {\n if (pathOrCommands.commands) {\n pathOrCommands = pathOrCommands.commands;\n } else if (pathOrCommands instanceof BoundingBox$1) {\n var box = pathOrCommands;\n this.moveTo(box.x1, box.y1);\n this.lineTo(box.x2, box.y1);\n this.lineTo(box.x2, box.y2);\n this.lineTo(box.x1, box.y2);\n this.close();\n return;\n }\n\n Array.prototype.push.apply(this.commands, pathOrCommands);\n };\n\n /**\n * Calculate the bounding box of the path.\n * @returns {opentype.BoundingBox}\n */\n Path.prototype.getBoundingBox = function() {\n var box = new BoundingBox$1();\n\n var startX = 0;\n var startY = 0;\n var prevX = 0;\n var prevY = 0;\n for (var i = 0; i < this.commands.length; i++) {\n var cmd = this.commands[i];\n switch (cmd.type) {\n case 'M':\n box.addPoint(cmd.x, cmd.y);\n startX = prevX = cmd.x;\n startY = prevY = cmd.y;\n break;\n case 'L':\n box.addPoint(cmd.x, cmd.y);\n prevX = cmd.x;\n prevY = cmd.y;\n break;\n case 'Q':\n box.addQuad(prevX, prevY, cmd.x1, cmd.y1, cmd.x, cmd.y);\n prevX = cmd.x;\n prevY = cmd.y;\n break;\n case 'C':\n box.addBezier(prevX, prevY, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);\n prevX = cmd.x;\n prevY = cmd.y;\n break;\n case 'Z':\n prevX = startX;\n prevY = startY;\n break;\n default:\n throw new Error('Unexpected path command ' + cmd.type);\n }\n }\n if (box.isEmpty()) {\n box.addPoint(0, 0);\n }\n return box;\n };\n\n /**\n * Draw the path to a 2D context.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context.\n */\n Path.prototype.draw = function(ctx) {\n ctx.beginPath();\n for (var i = 0; i < this.commands.length; i += 1) {\n var cmd = this.commands[i];\n if (cmd.type === 'M') {\n ctx.moveTo(cmd.x, cmd.y);\n } else if (cmd.type === 'L') {\n ctx.lineTo(cmd.x, cmd.y);\n } else if (cmd.type === 'C') {\n ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);\n } else if (cmd.type === 'Q') {\n ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y);\n } else if (cmd.type === 'Z') {\n ctx.closePath();\n }\n }\n\n if (this.fill) {\n ctx.fillStyle = this.fill;\n ctx.fill();\n }\n\n if (this.stroke) {\n ctx.strokeStyle = this.stroke;\n ctx.lineWidth = this.strokeWidth;\n ctx.stroke();\n }\n };\n\n /**\n * Convert the Path to a string of path data instructions\n * See http://www.w3.org/TR/SVG/paths.html#PathData\n * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values\n * @return {string}\n */\n Path.prototype.toPathData = function(decimalPlaces) {\n decimalPlaces = decimalPlaces !== undefined ? decimalPlaces : 2;\n\n function floatToString(v) {\n if (Math.round(v) === v) {\n return '' + Math.round(v);\n } else {\n return v.toFixed(decimalPlaces);\n }\n }\n\n function packValues() {\n var arguments$1 = arguments;\n\n var s = '';\n for (var i = 0; i < arguments.length; i += 1) {\n var v = arguments$1[i];\n if (v >= 0 && i > 0) {\n s += ' ';\n }\n\n s += floatToString(v);\n }\n\n return s;\n }\n\n var d = '';\n for (var i = 0; i < this.commands.length; i += 1) {\n var cmd = this.commands[i];\n if (cmd.type === 'M') {\n d += 'M' + packValues(cmd.x, cmd.y);\n } else if (cmd.type === 'L') {\n d += 'L' + packValues(cmd.x, cmd.y);\n } else if (cmd.type === 'C') {\n d += 'C' + packValues(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);\n } else if (cmd.type === 'Q') {\n d += 'Q' + packValues(cmd.x1, cmd.y1, cmd.x, cmd.y);\n } else if (cmd.type === 'Z') {\n d += 'Z';\n }\n }\n\n return d;\n };\n\n /**\n * Convert the path to an SVG element, as a string.\n * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values\n * @return {string}\n */\n Path.prototype.toSVG = function(decimalPlaces) {\n var svg = '= 0 && v <= 255, 'Byte value should be between 0 and 255.');\n return [v];\n };\n /**\n * @constant\n * @type {number}\n */\n sizeOf.BYTE = constant(1);\n\n /**\n * Convert a 8-bit signed integer to a list of 1 byte.\n * @param {string}\n * @returns {Array}\n */\n encode.CHAR = function(v) {\n return [v.charCodeAt(0)];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.CHAR = constant(1);\n\n /**\n * Convert an ASCII string to a list of bytes.\n * @param {string}\n * @returns {Array}\n */\n encode.CHARARRAY = function(v) {\n if (typeof v === 'undefined') {\n v = '';\n console.warn('Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name.');\n }\n var b = [];\n for (var i = 0; i < v.length; i += 1) {\n b[i] = v.charCodeAt(i);\n }\n\n return b;\n };\n\n /**\n * @param {Array}\n * @returns {number}\n */\n sizeOf.CHARARRAY = function(v) {\n if (typeof v === 'undefined') {\n return 0;\n }\n return v.length;\n };\n\n /**\n * Convert a 16-bit unsigned integer to a list of 2 bytes.\n * @param {number}\n * @returns {Array}\n */\n encode.USHORT = function(v) {\n return [(v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.USHORT = constant(2);\n\n /**\n * Convert a 16-bit signed integer to a list of 2 bytes.\n * @param {number}\n * @returns {Array}\n */\n encode.SHORT = function(v) {\n // Two's complement\n if (v >= LIMIT16) {\n v = -(2 * LIMIT16 - v);\n }\n\n return [(v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.SHORT = constant(2);\n\n /**\n * Convert a 24-bit unsigned integer to a list of 3 bytes.\n * @param {number}\n * @returns {Array}\n */\n encode.UINT24 = function(v) {\n return [(v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.UINT24 = constant(3);\n\n /**\n * Convert a 32-bit unsigned integer to a list of 4 bytes.\n * @param {number}\n * @returns {Array}\n */\n encode.ULONG = function(v) {\n return [(v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.ULONG = constant(4);\n\n /**\n * Convert a 32-bit unsigned integer to a list of 4 bytes.\n * @param {number}\n * @returns {Array}\n */\n encode.LONG = function(v) {\n // Two's complement\n if (v >= LIMIT32) {\n v = -(2 * LIMIT32 - v);\n }\n\n return [(v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.LONG = constant(4);\n\n encode.FIXED = encode.ULONG;\n sizeOf.FIXED = sizeOf.ULONG;\n\n encode.FWORD = encode.SHORT;\n sizeOf.FWORD = sizeOf.SHORT;\n\n encode.UFWORD = encode.USHORT;\n sizeOf.UFWORD = sizeOf.USHORT;\n\n /**\n * Convert a 32-bit Apple Mac timestamp integer to a list of 8 bytes, 64-bit timestamp.\n * @param {number}\n * @returns {Array}\n */\n encode.LONGDATETIME = function(v) {\n return [0, 0, 0, 0, (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.LONGDATETIME = constant(8);\n\n /**\n * Convert a 4-char tag to a list of 4 bytes.\n * @param {string}\n * @returns {Array}\n */\n encode.TAG = function(v) {\n check.argument(v.length === 4, 'Tag should be exactly 4 ASCII characters.');\n return [v.charCodeAt(0),\n v.charCodeAt(1),\n v.charCodeAt(2),\n v.charCodeAt(3)];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.TAG = constant(4);\n\n // CFF data types ///////////////////////////////////////////////////////////\n\n encode.Card8 = encode.BYTE;\n sizeOf.Card8 = sizeOf.BYTE;\n\n encode.Card16 = encode.USHORT;\n sizeOf.Card16 = sizeOf.USHORT;\n\n encode.OffSize = encode.BYTE;\n sizeOf.OffSize = sizeOf.BYTE;\n\n encode.SID = encode.USHORT;\n sizeOf.SID = sizeOf.USHORT;\n\n // Convert a numeric operand or charstring number to a variable-size list of bytes.\n /**\n * Convert a numeric operand or charstring number to a variable-size list of bytes.\n * @param {number}\n * @returns {Array}\n */\n encode.NUMBER = function(v) {\n if (v >= -107 && v <= 107) {\n return [v + 139];\n } else if (v >= 108 && v <= 1131) {\n v = v - 108;\n return [(v >> 8) + 247, v & 0xFF];\n } else if (v >= -1131 && v <= -108) {\n v = -v - 108;\n return [(v >> 8) + 251, v & 0xFF];\n } else if (v >= -32768 && v <= 32767) {\n return encode.NUMBER16(v);\n } else {\n return encode.NUMBER32(v);\n }\n };\n\n /**\n * @param {number}\n * @returns {number}\n */\n sizeOf.NUMBER = function(v) {\n return encode.NUMBER(v).length;\n };\n\n /**\n * Convert a signed number between -32768 and +32767 to a three-byte value.\n * This ensures we always use three bytes, but is not the most compact format.\n * @param {number}\n * @returns {Array}\n */\n encode.NUMBER16 = function(v) {\n return [28, (v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.NUMBER16 = constant(3);\n\n /**\n * Convert a signed number between -(2^31) and +(2^31-1) to a five-byte value.\n * This is useful if you want to be sure you always use four bytes,\n * at the expense of wasting a few bytes for smaller numbers.\n * @param {number}\n * @returns {Array}\n */\n encode.NUMBER32 = function(v) {\n return [29, (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n };\n\n /**\n * @constant\n * @type {number}\n */\n sizeOf.NUMBER32 = constant(5);\n\n /**\n * @param {number}\n * @returns {Array}\n */\n encode.REAL = function(v) {\n var value = v.toString();\n\n // Some numbers use an epsilon to encode the value. (e.g. JavaScript will store 0.0000001 as 1e-7)\n // This code converts it back to a number without the epsilon.\n var m = /\\.(\\d*?)(?:9{5,20}|0{5,20})\\d{0,2}(?:e(.+)|$)/.exec(value);\n if (m) {\n var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));\n value = (Math.round(v * epsilon) / epsilon).toString();\n }\n\n var nibbles = '';\n for (var i = 0, ii = value.length; i < ii; i += 1) {\n var c = value[i];\n if (c === 'e') {\n nibbles += value[++i] === '-' ? 'c' : 'b';\n } else if (c === '.') {\n nibbles += 'a';\n } else if (c === '-') {\n nibbles += 'e';\n } else {\n nibbles += c;\n }\n }\n\n nibbles += (nibbles.length & 1) ? 'f' : 'ff';\n var out = [30];\n for (var i$1 = 0, ii$1 = nibbles.length; i$1 < ii$1; i$1 += 2) {\n out.push(parseInt(nibbles.substr(i$1, 2), 16));\n }\n\n return out;\n };\n\n /**\n * @param {number}\n * @returns {number}\n */\n sizeOf.REAL = function(v) {\n return encode.REAL(v).length;\n };\n\n encode.NAME = encode.CHARARRAY;\n sizeOf.NAME = sizeOf.CHARARRAY;\n\n encode.STRING = encode.CHARARRAY;\n sizeOf.STRING = sizeOf.CHARARRAY;\n\n /**\n * @param {DataView} data\n * @param {number} offset\n * @param {number} numBytes\n * @returns {string}\n */\n decode.UTF8 = function(data, offset, numBytes) {\n var codePoints = [];\n var numChars = numBytes;\n for (var j = 0; j < numChars; j++, offset += 1) {\n codePoints[j] = data.getUint8(offset);\n }\n\n return String.fromCharCode.apply(null, codePoints);\n };\n\n /**\n * @param {DataView} data\n * @param {number} offset\n * @param {number} numBytes\n * @returns {string}\n */\n decode.UTF16 = function(data, offset, numBytes) {\n var codePoints = [];\n var numChars = numBytes / 2;\n for (var j = 0; j < numChars; j++, offset += 2) {\n codePoints[j] = data.getUint16(offset);\n }\n\n return String.fromCharCode.apply(null, codePoints);\n };\n\n /**\n * Convert a JavaScript string to UTF16-BE.\n * @param {string}\n * @returns {Array}\n */\n encode.UTF16 = function(v) {\n var b = [];\n for (var i = 0; i < v.length; i += 1) {\n var codepoint = v.charCodeAt(i);\n b[b.length] = (codepoint >> 8) & 0xFF;\n b[b.length] = codepoint & 0xFF;\n }\n\n return b;\n };\n\n /**\n * @param {string}\n * @returns {number}\n */\n sizeOf.UTF16 = function(v) {\n return v.length * 2;\n };\n\n // Data for converting old eight-bit Macintosh encodings to Unicode.\n // This representation is optimized for decoding; encoding is slower\n // and needs more memory. The assumption is that all opentype.js users\n // want to open fonts, but saving a font will be comparatively rare\n // so it can be more expensive. Keyed by IANA character set name.\n //\n // Python script for generating these strings:\n //\n // s = u''.join([chr(c).decode('mac_greek') for c in range(128, 256)])\n // print(s.encode('utf-8'))\n /**\n * @private\n */\n var eightBitMacEncodings = {\n 'x-mac-croatian': // Python: 'mac_croatian'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø' +\n '¿¡¬√ƒ≈Ć«Č… ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ',\n 'x-mac-cyrillic': // Python: 'mac_cyrillic'\n 'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњ' +\n 'јЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю',\n 'x-mac-gaelic': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæø' +\n 'ṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ',\n 'x-mac-greek': // Python: 'mac_greek'\n 'Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩ' +\n 'άΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ\\u00AD',\n 'x-mac-icelandic': // Python: 'mac_iceland'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüÝ°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',\n 'x-mac-inuit': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT\n 'ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗ' +\n 'ᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł',\n 'x-mac-ce': // Python: 'mac_latin2'\n 'ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅ' +\n 'ņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ',\n macintosh: // Python: 'mac_roman'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',\n 'x-mac-romanian': // Python: 'mac_romanian'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',\n 'x-mac-turkish': // Python: 'mac_turkish'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ'\n };\n\n /**\n * Decodes an old-style Macintosh string. Returns either a Unicode JavaScript\n * string, or 'undefined' if the encoding is unsupported. For example, we do\n * not support Chinese, Japanese or Korean because these would need large\n * mapping tables.\n * @param {DataView} dataView\n * @param {number} offset\n * @param {number} dataLength\n * @param {string} encoding\n * @returns {string}\n */\n decode.MACSTRING = function(dataView, offset, dataLength, encoding) {\n var table = eightBitMacEncodings[encoding];\n if (table === undefined) {\n return undefined;\n }\n\n var result = '';\n for (var i = 0; i < dataLength; i++) {\n var c = dataView.getUint8(offset + i);\n // In all eight-bit Mac encodings, the characters 0x00..0x7F are\n // mapped to U+0000..U+007F; we only need to look up the others.\n if (c <= 0x7F) {\n result += String.fromCharCode(c);\n } else {\n result += table[c & 0x7F];\n }\n }\n\n return result;\n };\n\n // Helper function for encode.MACSTRING. Returns a dictionary for mapping\n // Unicode character codes to their 8-bit MacOS equivalent. This table\n // is not exactly a super cheap data structure, but we do not care because\n // encoding Macintosh strings is only rarely needed in typical applications.\n var macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap();\n var macEncodingCacheKeys;\n var getMacEncodingTable = function (encoding) {\n // Since we use encoding as a cache key for WeakMap, it has to be\n // a String object and not a literal. And at least on NodeJS 2.10.1,\n // WeakMap requires that the same String instance is passed for cache hits.\n if (!macEncodingCacheKeys) {\n macEncodingCacheKeys = {};\n for (var e in eightBitMacEncodings) {\n /*jshint -W053 */ // Suppress \"Do not use String as a constructor.\"\n macEncodingCacheKeys[e] = new String(e);\n }\n }\n\n var cacheKey = macEncodingCacheKeys[encoding];\n if (cacheKey === undefined) {\n return undefined;\n }\n\n // We can't do \"if (cache.has(key)) {return cache.get(key)}\" here:\n // since garbage collection may run at any time, it could also kick in\n // between the calls to cache.has() and cache.get(). In that case,\n // we would return 'undefined' even though we do support the encoding.\n if (macEncodingTableCache) {\n var cachedTable = macEncodingTableCache.get(cacheKey);\n if (cachedTable !== undefined) {\n return cachedTable;\n }\n }\n\n var decodingTable = eightBitMacEncodings[encoding];\n if (decodingTable === undefined) {\n return undefined;\n }\n\n var encodingTable = {};\n for (var i = 0; i < decodingTable.length; i++) {\n encodingTable[decodingTable.charCodeAt(i)] = i + 0x80;\n }\n\n if (macEncodingTableCache) {\n macEncodingTableCache.set(cacheKey, encodingTable);\n }\n\n return encodingTable;\n };\n\n /**\n * Encodes an old-style Macintosh string. Returns a byte array upon success.\n * If the requested encoding is unsupported, or if the input string contains\n * a character that cannot be expressed in the encoding, the function returns\n * 'undefined'.\n * @param {string} str\n * @param {string} encoding\n * @returns {Array}\n */\n encode.MACSTRING = function(str, encoding) {\n var table = getMacEncodingTable(encoding);\n if (table === undefined) {\n return undefined;\n }\n\n var result = [];\n for (var i = 0; i < str.length; i++) {\n var c = str.charCodeAt(i);\n\n // In all eight-bit Mac encodings, the characters 0x00..0x7F are\n // mapped to U+0000..U+007F; we only need to look up the others.\n if (c >= 0x80) {\n c = table[c];\n if (c === undefined) {\n // str contains a Unicode character that cannot be encoded\n // in the requested encoding.\n return undefined;\n }\n }\n result[i] = c;\n // result.push(c);\n }\n\n return result;\n };\n\n /**\n * @param {string} str\n * @param {string} encoding\n * @returns {number}\n */\n sizeOf.MACSTRING = function(str, encoding) {\n var b = encode.MACSTRING(str, encoding);\n if (b !== undefined) {\n return b.length;\n } else {\n return 0;\n }\n };\n\n // Helper for encode.VARDELTAS\n function isByteEncodable(value) {\n return value >= -128 && value <= 127;\n }\n\n // Helper for encode.VARDELTAS\n function encodeVarDeltaRunAsZeroes(deltas, pos, result) {\n var runLength = 0;\n var numDeltas = deltas.length;\n while (pos < numDeltas && runLength < 64 && deltas[pos] === 0) {\n ++pos;\n ++runLength;\n }\n result.push(0x80 | (runLength - 1));\n return pos;\n }\n\n // Helper for encode.VARDELTAS\n function encodeVarDeltaRunAsBytes(deltas, offset, result) {\n var runLength = 0;\n var numDeltas = deltas.length;\n var pos = offset;\n while (pos < numDeltas && runLength < 64) {\n var value = deltas[pos];\n if (!isByteEncodable(value)) {\n break;\n }\n\n // Within a byte-encoded run of deltas, a single zero is best\n // stored literally as 0x00 value. However, if we have two or\n // more zeroes in a sequence, it is better to start a new run.\n // Fore example, the sequence of deltas [15, 15, 0, 15, 15]\n // becomes 6 bytes (04 0F 0F 00 0F 0F) when storing the zero\n // within the current run, but 7 bytes (01 0F 0F 80 01 0F 0F)\n // when starting a new run.\n if (value === 0 && pos + 1 < numDeltas && deltas[pos + 1] === 0) {\n break;\n }\n\n ++pos;\n ++runLength;\n }\n result.push(runLength - 1);\n for (var i = offset; i < pos; ++i) {\n result.push((deltas[i] + 256) & 0xff);\n }\n return pos;\n }\n\n // Helper for encode.VARDELTAS\n function encodeVarDeltaRunAsWords(deltas, offset, result) {\n var runLength = 0;\n var numDeltas = deltas.length;\n var pos = offset;\n while (pos < numDeltas && runLength < 64) {\n var value = deltas[pos];\n\n // Within a word-encoded run of deltas, it is easiest to start\n // a new run (with a different encoding) whenever we encounter\n // a zero value. For example, the sequence [0x6666, 0, 0x7777]\n // needs 7 bytes when storing the zero inside the current run\n // (42 66 66 00 00 77 77), and equally 7 bytes when starting a\n // new run (40 66 66 80 40 77 77).\n if (value === 0) {\n break;\n }\n\n // Within a word-encoded run of deltas, a single value in the\n // range (-128..127) should be encoded within the current run\n // because it is more compact. For example, the sequence\n // [0x6666, 2, 0x7777] becomes 7 bytes when storing the value\n // literally (42 66 66 00 02 77 77), but 8 bytes when starting\n // a new run (40 66 66 00 02 40 77 77).\n if (isByteEncodable(value) && pos + 1 < numDeltas && isByteEncodable(deltas[pos + 1])) {\n break;\n }\n\n ++pos;\n ++runLength;\n }\n result.push(0x40 | (runLength - 1));\n for (var i = offset; i < pos; ++i) {\n var val = deltas[i];\n result.push(((val + 0x10000) >> 8) & 0xff, (val + 0x100) & 0xff);\n }\n return pos;\n }\n\n /**\n * Encode a list of variation adjustment deltas.\n *\n * Variation adjustment deltas are used in ‘gvar’ and ‘cvar’ tables.\n * They indicate how points (in ‘gvar’) or values (in ‘cvar’) get adjusted\n * when generating instances of variation fonts.\n *\n * @see https://www.microsoft.com/typography/otspec/gvar.htm\n * @see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gvar.html\n * @param {Array}\n * @return {Array}\n */\n encode.VARDELTAS = function(deltas) {\n var pos = 0;\n var result = [];\n while (pos < deltas.length) {\n var value = deltas[pos];\n if (value === 0) {\n pos = encodeVarDeltaRunAsZeroes(deltas, pos, result);\n } else if (value >= -128 && value <= 127) {\n pos = encodeVarDeltaRunAsBytes(deltas, pos, result);\n } else {\n pos = encodeVarDeltaRunAsWords(deltas, pos, result);\n }\n }\n return result;\n };\n\n // Convert a list of values to a CFF INDEX structure.\n // The values should be objects containing name / type / value.\n /**\n * @param {Array} l\n * @returns {Array}\n */\n encode.INDEX = function(l) {\n //var offset, offsets, offsetEncoder, encodedOffsets, encodedOffset, data,\n // i, v;\n // Because we have to know which data type to use to encode the offsets,\n // we have to go through the values twice: once to encode the data and\n // calculate the offsets, then again to encode the offsets using the fitting data type.\n var offset = 1; // First offset is always 1.\n var offsets = [offset];\n var data = [];\n for (var i = 0; i < l.length; i += 1) {\n var v = encode.OBJECT(l[i]);\n Array.prototype.push.apply(data, v);\n offset += v.length;\n offsets.push(offset);\n }\n\n if (data.length === 0) {\n return [0, 0];\n }\n\n var encodedOffsets = [];\n var offSize = (1 + Math.floor(Math.log(offset) / Math.log(2)) / 8) | 0;\n var offsetEncoder = [undefined, encode.BYTE, encode.USHORT, encode.UINT24, encode.ULONG][offSize];\n for (var i$1 = 0; i$1 < offsets.length; i$1 += 1) {\n var encodedOffset = offsetEncoder(offsets[i$1]);\n Array.prototype.push.apply(encodedOffsets, encodedOffset);\n }\n\n return Array.prototype.concat(encode.Card16(l.length),\n encode.OffSize(offSize),\n encodedOffsets,\n data);\n };\n\n /**\n * @param {Array}\n * @returns {number}\n */\n sizeOf.INDEX = function(v) {\n return encode.INDEX(v).length;\n };\n\n /**\n * Convert an object to a CFF DICT structure.\n * The keys should be numeric.\n * The values should be objects containing name / type / value.\n * @param {Object} m\n * @returns {Array}\n */\n encode.DICT = function(m) {\n var d = [];\n var keys = Object.keys(m);\n var length = keys.length;\n\n for (var i = 0; i < length; i += 1) {\n // Object.keys() return string keys, but our keys are always numeric.\n var k = parseInt(keys[i], 0);\n var v = m[k];\n // Value comes before the key.\n d = d.concat(encode.OPERAND(v.value, v.type));\n d = d.concat(encode.OPERATOR(k));\n }\n\n return d;\n };\n\n /**\n * @param {Object}\n * @returns {number}\n */\n sizeOf.DICT = function(m) {\n return encode.DICT(m).length;\n };\n\n /**\n * @param {number}\n * @returns {Array}\n */\n encode.OPERATOR = function(v) {\n if (v < 1200) {\n return [v];\n } else {\n return [12, v - 1200];\n }\n };\n\n /**\n * @param {Array} v\n * @param {string}\n * @returns {Array}\n */\n encode.OPERAND = function(v, type) {\n var d = [];\n if (Array.isArray(type)) {\n for (var i = 0; i < type.length; i += 1) {\n check.argument(v.length === type.length, 'Not enough arguments given for type' + type);\n d = d.concat(encode.OPERAND(v[i], type[i]));\n }\n } else {\n if (type === 'SID') {\n d = d.concat(encode.NUMBER(v));\n } else if (type === 'offset') {\n // We make it easy for ourselves and always encode offsets as\n // 4 bytes. This makes offset calculation for the top dict easier.\n d = d.concat(encode.NUMBER32(v));\n } else if (type === 'number') {\n d = d.concat(encode.NUMBER(v));\n } else if (type === 'real') {\n d = d.concat(encode.REAL(v));\n } else {\n throw new Error('Unknown operand type ' + type);\n // FIXME Add support for booleans\n }\n }\n\n return d;\n };\n\n encode.OP = encode.BYTE;\n sizeOf.OP = sizeOf.BYTE;\n\n // memoize charstring encoding using WeakMap if available\n var wmm = typeof WeakMap === 'function' && new WeakMap();\n\n /**\n * Convert a list of CharString operations to bytes.\n * @param {Array}\n * @returns {Array}\n */\n encode.CHARSTRING = function(ops) {\n // See encode.MACSTRING for why we don't do \"if (wmm && wmm.has(ops))\".\n if (wmm) {\n var cachedValue = wmm.get(ops);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n }\n\n var d = [];\n var length = ops.length;\n\n for (var i = 0; i < length; i += 1) {\n var op = ops[i];\n d = d.concat(encode[op.type](op.value));\n }\n\n if (wmm) {\n wmm.set(ops, d);\n }\n\n return d;\n };\n\n /**\n * @param {Array}\n * @returns {number}\n */\n sizeOf.CHARSTRING = function(ops) {\n return encode.CHARSTRING(ops).length;\n };\n\n // Utility functions ////////////////////////////////////////////////////////\n\n /**\n * Convert an object containing name / type / value to bytes.\n * @param {Object}\n * @returns {Array}\n */\n encode.OBJECT = function(v) {\n var encodingFunction = encode[v.type];\n check.argument(encodingFunction !== undefined, 'No encoding function for type ' + v.type);\n return encodingFunction(v.value);\n };\n\n /**\n * @param {Object}\n * @returns {number}\n */\n sizeOf.OBJECT = function(v) {\n var sizeOfFunction = sizeOf[v.type];\n check.argument(sizeOfFunction !== undefined, 'No sizeOf function for type ' + v.type);\n return sizeOfFunction(v.value);\n };\n\n /**\n * Convert a table object to bytes.\n * A table contains a list of fields containing the metadata (name, type and default value).\n * The table itself has the field values set as attributes.\n * @param {opentype.Table}\n * @returns {Array}\n */\n encode.TABLE = function(table) {\n var d = [];\n var length = table.fields.length;\n var subtables = [];\n var subtableOffsets = [];\n\n for (var i = 0; i < length; i += 1) {\n var field = table.fields[i];\n var encodingFunction = encode[field.type];\n check.argument(encodingFunction !== undefined, 'No encoding function for field type ' + field.type + ' (' + field.name + ')');\n var value = table[field.name];\n if (value === undefined) {\n value = field.value;\n }\n\n var bytes = encodingFunction(value);\n\n if (field.type === 'TABLE') {\n subtableOffsets.push(d.length);\n d = d.concat([0, 0]);\n subtables.push(bytes);\n } else {\n d = d.concat(bytes);\n }\n }\n\n for (var i$1 = 0; i$1 < subtables.length; i$1 += 1) {\n var o = subtableOffsets[i$1];\n var offset = d.length;\n check.argument(offset < 65536, 'Table ' + table.tableName + ' too big.');\n d[o] = offset >> 8;\n d[o + 1] = offset & 0xff;\n d = d.concat(subtables[i$1]);\n }\n\n return d;\n };\n\n /**\n * @param {opentype.Table}\n * @returns {number}\n */\n sizeOf.TABLE = function(table) {\n var numBytes = 0;\n var length = table.fields.length;\n\n for (var i = 0; i < length; i += 1) {\n var field = table.fields[i];\n var sizeOfFunction = sizeOf[field.type];\n check.argument(sizeOfFunction !== undefined, 'No sizeOf function for field type ' + field.type + ' (' + field.name + ')');\n var value = table[field.name];\n if (value === undefined) {\n value = field.value;\n }\n\n numBytes += sizeOfFunction(value);\n\n // Subtables take 2 more bytes for offsets.\n if (field.type === 'TABLE') {\n numBytes += 2;\n }\n }\n\n return numBytes;\n };\n\n encode.RECORD = encode.TABLE;\n sizeOf.RECORD = sizeOf.TABLE;\n\n // Merge in a list of bytes.\n encode.LITERAL = function(v) {\n return v;\n };\n\n sizeOf.LITERAL = function(v) {\n return v.length;\n };\n\n // Table metadata\n\n /**\n * @exports opentype.Table\n * @class\n * @param {string} tableName\n * @param {Array} fields\n * @param {Object} options\n * @constructor\n */\n function Table(tableName, fields, options) {\n // For coverage tables with coverage format 2, we do not want to add the coverage data directly to the table object,\n // as this will result in wrong encoding order of the coverage data on serialization to bytes.\n // The fallback of using the field values directly when not present on the table is handled in types.encode.TABLE() already.\n if (fields.length && (fields[0].name !== 'coverageFormat' || fields[0].value === 1)) {\n for (var i = 0; i < fields.length; i += 1) {\n var field = fields[i];\n this[field.name] = field.value;\n }\n }\n\n this.tableName = tableName;\n this.fields = fields;\n if (options) {\n var optionKeys = Object.keys(options);\n for (var i$1 = 0; i$1 < optionKeys.length; i$1 += 1) {\n var k = optionKeys[i$1];\n var v = options[k];\n if (this[k] !== undefined) {\n this[k] = v;\n }\n }\n }\n }\n\n /**\n * Encodes the table and returns an array of bytes\n * @return {Array}\n */\n Table.prototype.encode = function() {\n return encode.TABLE(this);\n };\n\n /**\n * Get the size of the table.\n * @return {number}\n */\n Table.prototype.sizeOf = function() {\n return sizeOf.TABLE(this);\n };\n\n /**\n * @private\n */\n function ushortList(itemName, list, count) {\n if (count === undefined) {\n count = list.length;\n }\n var fields = new Array(list.length + 1);\n fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};\n for (var i = 0; i < list.length; i++) {\n fields[i + 1] = {name: itemName + i, type: 'USHORT', value: list[i]};\n }\n return fields;\n }\n\n /**\n * @private\n */\n function tableList(itemName, records, itemCallback) {\n var count = records.length;\n var fields = new Array(count + 1);\n fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};\n for (var i = 0; i < count; i++) {\n fields[i + 1] = {name: itemName + i, type: 'TABLE', value: itemCallback(records[i], i)};\n }\n return fields;\n }\n\n /**\n * @private\n */\n function recordList(itemName, records, itemCallback) {\n var count = records.length;\n var fields = [];\n fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};\n for (var i = 0; i < count; i++) {\n fields = fields.concat(itemCallback(records[i], i));\n }\n return fields;\n }\n\n // Common Layout Tables\n\n /**\n * @exports opentype.Coverage\n * @class\n * @param {opentype.Table}\n * @constructor\n * @extends opentype.Table\n */\n function Coverage(coverageTable) {\n if (coverageTable.format === 1) {\n Table.call(this, 'coverageTable',\n [{name: 'coverageFormat', type: 'USHORT', value: 1}]\n .concat(ushortList('glyph', coverageTable.glyphs))\n );\n } else if (coverageTable.format === 2) {\n Table.call(this, 'coverageTable',\n [{name: 'coverageFormat', type: 'USHORT', value: 2}]\n .concat(recordList('rangeRecord', coverageTable.ranges, function(RangeRecord) {\n return [\n {name: 'startGlyphID', type: 'USHORT', value: RangeRecord.start},\n {name: 'endGlyphID', type: 'USHORT', value: RangeRecord.end},\n {name: 'startCoverageIndex', type: 'USHORT', value: RangeRecord.index} ];\n }))\n );\n } else {\n check.assert(false, 'Coverage format must be 1 or 2.');\n }\n }\n Coverage.prototype = Object.create(Table.prototype);\n Coverage.prototype.constructor = Coverage;\n\n function ScriptList(scriptListTable) {\n Table.call(this, 'scriptListTable',\n recordList('scriptRecord', scriptListTable, function(scriptRecord, i) {\n var script = scriptRecord.script;\n var defaultLangSys = script.defaultLangSys;\n check.assert(!!defaultLangSys, 'Unable to write GSUB: script ' + scriptRecord.tag + ' has no default language system.');\n return [\n {name: 'scriptTag' + i, type: 'TAG', value: scriptRecord.tag},\n {name: 'script' + i, type: 'TABLE', value: new Table('scriptTable', [\n {name: 'defaultLangSys', type: 'TABLE', value: new Table('defaultLangSys', [\n {name: 'lookupOrder', type: 'USHORT', value: 0},\n {name: 'reqFeatureIndex', type: 'USHORT', value: defaultLangSys.reqFeatureIndex}]\n .concat(ushortList('featureIndex', defaultLangSys.featureIndexes)))}\n ].concat(recordList('langSys', script.langSysRecords, function(langSysRecord, i) {\n var langSys = langSysRecord.langSys;\n return [\n {name: 'langSysTag' + i, type: 'TAG', value: langSysRecord.tag},\n {name: 'langSys' + i, type: 'TABLE', value: new Table('langSys', [\n {name: 'lookupOrder', type: 'USHORT', value: 0},\n {name: 'reqFeatureIndex', type: 'USHORT', value: langSys.reqFeatureIndex}\n ].concat(ushortList('featureIndex', langSys.featureIndexes)))}\n ];\n })))}\n ];\n })\n );\n }\n ScriptList.prototype = Object.create(Table.prototype);\n ScriptList.prototype.constructor = ScriptList;\n\n /**\n * @exports opentype.FeatureList\n * @class\n * @param {opentype.Table}\n * @constructor\n * @extends opentype.Table\n */\n function FeatureList(featureListTable) {\n Table.call(this, 'featureListTable',\n recordList('featureRecord', featureListTable, function(featureRecord, i) {\n var feature = featureRecord.feature;\n return [\n {name: 'featureTag' + i, type: 'TAG', value: featureRecord.tag},\n {name: 'feature' + i, type: 'TABLE', value: new Table('featureTable', [\n {name: 'featureParams', type: 'USHORT', value: feature.featureParams} ].concat(ushortList('lookupListIndex', feature.lookupListIndexes)))}\n ];\n })\n );\n }\n FeatureList.prototype = Object.create(Table.prototype);\n FeatureList.prototype.constructor = FeatureList;\n\n /**\n * @exports opentype.LookupList\n * @class\n * @param {opentype.Table}\n * @param {Object}\n * @constructor\n * @extends opentype.Table\n */\n function LookupList(lookupListTable, subtableMakers) {\n Table.call(this, 'lookupListTable', tableList('lookup', lookupListTable, function(lookupTable) {\n var subtableCallback = subtableMakers[lookupTable.lookupType];\n check.assert(!!subtableCallback, 'Unable to write GSUB lookup type ' + lookupTable.lookupType + ' tables.');\n return new Table('lookupTable', [\n {name: 'lookupType', type: 'USHORT', value: lookupTable.lookupType},\n {name: 'lookupFlag', type: 'USHORT', value: lookupTable.lookupFlag}\n ].concat(tableList('subtable', lookupTable.subtables, subtableCallback)));\n }));\n }\n LookupList.prototype = Object.create(Table.prototype);\n LookupList.prototype.constructor = LookupList;\n\n // Record = same as Table, but inlined (a Table has an offset and its data is further in the stream)\n // Don't use offsets inside Records (probable bug), only in Tables.\n var table = {\n Table: Table,\n Record: Table,\n Coverage: Coverage,\n ScriptList: ScriptList,\n FeatureList: FeatureList,\n LookupList: LookupList,\n ushortList: ushortList,\n tableList: tableList,\n recordList: recordList,\n };\n\n // Parsing utility functions\n\n // Retrieve an unsigned byte from the DataView.\n function getByte(dataView, offset) {\n return dataView.getUint8(offset);\n }\n\n // Retrieve an unsigned 16-bit short from the DataView.\n // The value is stored in big endian.\n function getUShort(dataView, offset) {\n return dataView.getUint16(offset, false);\n }\n\n // Retrieve a signed 16-bit short from the DataView.\n // The value is stored in big endian.\n function getShort(dataView, offset) {\n return dataView.getInt16(offset, false);\n }\n\n // Retrieve an unsigned 32-bit long from the DataView.\n // The value is stored in big endian.\n function getULong(dataView, offset) {\n return dataView.getUint32(offset, false);\n }\n\n // Retrieve a 32-bit signed fixed-point number (16.16) from the DataView.\n // The value is stored in big endian.\n function getFixed(dataView, offset) {\n var decimal = dataView.getInt16(offset, false);\n var fraction = dataView.getUint16(offset + 2, false);\n return decimal + fraction / 65535;\n }\n\n // Retrieve a 4-character tag from the DataView.\n // Tags are used to identify tables.\n function getTag(dataView, offset) {\n var tag = '';\n for (var i = offset; i < offset + 4; i += 1) {\n tag += String.fromCharCode(dataView.getInt8(i));\n }\n\n return tag;\n }\n\n // Retrieve an offset from the DataView.\n // Offsets are 1 to 4 bytes in length, depending on the offSize argument.\n function getOffset(dataView, offset, offSize) {\n var v = 0;\n for (var i = 0; i < offSize; i += 1) {\n v <<= 8;\n v += dataView.getUint8(offset + i);\n }\n\n return v;\n }\n\n // Retrieve a number of bytes from start offset to the end offset from the DataView.\n function getBytes(dataView, startOffset, endOffset) {\n var bytes = [];\n for (var i = startOffset; i < endOffset; i += 1) {\n bytes.push(dataView.getUint8(i));\n }\n\n return bytes;\n }\n\n // Convert the list of bytes to a string.\n function bytesToString(bytes) {\n var s = '';\n for (var i = 0; i < bytes.length; i += 1) {\n s += String.fromCharCode(bytes[i]);\n }\n\n return s;\n }\n\n var typeOffsets = {\n byte: 1,\n uShort: 2,\n short: 2,\n uLong: 4,\n fixed: 4,\n longDateTime: 8,\n tag: 4\n };\n\n // A stateful parser that changes the offset whenever a value is retrieved.\n // The data is a DataView.\n function Parser(data, offset) {\n this.data = data;\n this.offset = offset;\n this.relativeOffset = 0;\n }\n\n Parser.prototype.parseByte = function() {\n var v = this.data.getUint8(this.offset + this.relativeOffset);\n this.relativeOffset += 1;\n return v;\n };\n\n Parser.prototype.parseChar = function() {\n var v = this.data.getInt8(this.offset + this.relativeOffset);\n this.relativeOffset += 1;\n return v;\n };\n\n Parser.prototype.parseCard8 = Parser.prototype.parseByte;\n\n Parser.prototype.parseUShort = function() {\n var v = this.data.getUint16(this.offset + this.relativeOffset);\n this.relativeOffset += 2;\n return v;\n };\n\n Parser.prototype.parseCard16 = Parser.prototype.parseUShort;\n Parser.prototype.parseSID = Parser.prototype.parseUShort;\n Parser.prototype.parseOffset16 = Parser.prototype.parseUShort;\n\n Parser.prototype.parseShort = function() {\n var v = this.data.getInt16(this.offset + this.relativeOffset);\n this.relativeOffset += 2;\n return v;\n };\n\n Parser.prototype.parseF2Dot14 = function() {\n var v = this.data.getInt16(this.offset + this.relativeOffset) / 16384;\n this.relativeOffset += 2;\n return v;\n };\n\n Parser.prototype.parseULong = function() {\n var v = getULong(this.data, this.offset + this.relativeOffset);\n this.relativeOffset += 4;\n return v;\n };\n\n Parser.prototype.parseOffset32 = Parser.prototype.parseULong;\n\n Parser.prototype.parseFixed = function() {\n var v = getFixed(this.data, this.offset + this.relativeOffset);\n this.relativeOffset += 4;\n return v;\n };\n\n Parser.prototype.parseString = function(length) {\n var dataView = this.data;\n var offset = this.offset + this.relativeOffset;\n var string = '';\n this.relativeOffset += length;\n for (var i = 0; i < length; i++) {\n string += String.fromCharCode(dataView.getUint8(offset + i));\n }\n\n return string;\n };\n\n Parser.prototype.parseTag = function() {\n return this.parseString(4);\n };\n\n // LONGDATETIME is a 64-bit integer.\n // JavaScript and unix timestamps traditionally use 32 bits, so we\n // only take the last 32 bits.\n // + Since until 2038 those bits will be filled by zeros we can ignore them.\n Parser.prototype.parseLongDateTime = function() {\n var v = getULong(this.data, this.offset + this.relativeOffset + 4);\n // Subtract seconds between 01/01/1904 and 01/01/1970\n // to convert Apple Mac timestamp to Standard Unix timestamp\n v -= 2082844800;\n this.relativeOffset += 8;\n return v;\n };\n\n Parser.prototype.parseVersion = function(minorBase) {\n var major = getUShort(this.data, this.offset + this.relativeOffset);\n\n // How to interpret the minor version is very vague in the spec. 0x5000 is 5, 0x1000 is 1\n // Default returns the correct number if minor = 0xN000 where N is 0-9\n // Set minorBase to 1 for tables that use minor = N where N is 0-9\n var minor = getUShort(this.data, this.offset + this.relativeOffset + 2);\n this.relativeOffset += 4;\n if (minorBase === undefined) { minorBase = 0x1000; }\n return major + minor / minorBase / 10;\n };\n\n Parser.prototype.skip = function(type, amount) {\n if (amount === undefined) {\n amount = 1;\n }\n\n this.relativeOffset += typeOffsets[type] * amount;\n };\n\n ///// Parsing lists and records ///////////////////////////////\n\n // Parse a list of 32 bit unsigned integers.\n Parser.prototype.parseULongList = function(count) {\n if (count === undefined) { count = this.parseULong(); }\n var offsets = new Array(count);\n var dataView = this.data;\n var offset = this.offset + this.relativeOffset;\n for (var i = 0; i < count; i++) {\n offsets[i] = dataView.getUint32(offset);\n offset += 4;\n }\n\n this.relativeOffset += count * 4;\n return offsets;\n };\n\n // Parse a list of 16 bit unsigned integers. The length of the list can be read on the stream\n // or provided as an argument.\n Parser.prototype.parseOffset16List =\n Parser.prototype.parseUShortList = function(count) {\n if (count === undefined) { count = this.parseUShort(); }\n var offsets = new Array(count);\n var dataView = this.data;\n var offset = this.offset + this.relativeOffset;\n for (var i = 0; i < count; i++) {\n offsets[i] = dataView.getUint16(offset);\n offset += 2;\n }\n\n this.relativeOffset += count * 2;\n return offsets;\n };\n\n // Parses a list of 16 bit signed integers.\n Parser.prototype.parseShortList = function(count) {\n var list = new Array(count);\n var dataView = this.data;\n var offset = this.offset + this.relativeOffset;\n for (var i = 0; i < count; i++) {\n list[i] = dataView.getInt16(offset);\n offset += 2;\n }\n\n this.relativeOffset += count * 2;\n return list;\n };\n\n // Parses a list of bytes.\n Parser.prototype.parseByteList = function(count) {\n var list = new Array(count);\n var dataView = this.data;\n var offset = this.offset + this.relativeOffset;\n for (var i = 0; i < count; i++) {\n list[i] = dataView.getUint8(offset++);\n }\n\n this.relativeOffset += count;\n return list;\n };\n\n /**\n * Parse a list of items.\n * Record count is optional, if omitted it is read from the stream.\n * itemCallback is one of the Parser methods.\n */\n Parser.prototype.parseList = function(count, itemCallback) {\n if (!itemCallback) {\n itemCallback = count;\n count = this.parseUShort();\n }\n var list = new Array(count);\n for (var i = 0; i < count; i++) {\n list[i] = itemCallback.call(this);\n }\n return list;\n };\n\n Parser.prototype.parseList32 = function(count, itemCallback) {\n if (!itemCallback) {\n itemCallback = count;\n count = this.parseULong();\n }\n var list = new Array(count);\n for (var i = 0; i < count; i++) {\n list[i] = itemCallback.call(this);\n }\n return list;\n };\n\n /**\n * Parse a list of records.\n * Record count is optional, if omitted it is read from the stream.\n * Example of recordDescription: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort }\n */\n Parser.prototype.parseRecordList = function(count, recordDescription) {\n // If the count argument is absent, read it in the stream.\n if (!recordDescription) {\n recordDescription = count;\n count = this.parseUShort();\n }\n var records = new Array(count);\n var fields = Object.keys(recordDescription);\n for (var i = 0; i < count; i++) {\n var rec = {};\n for (var j = 0; j < fields.length; j++) {\n var fieldName = fields[j];\n var fieldType = recordDescription[fieldName];\n rec[fieldName] = fieldType.call(this);\n }\n records[i] = rec;\n }\n return records;\n };\n\n Parser.prototype.parseRecordList32 = function(count, recordDescription) {\n // If the count argument is absent, read it in the stream.\n if (!recordDescription) {\n recordDescription = count;\n count = this.parseULong();\n }\n var records = new Array(count);\n var fields = Object.keys(recordDescription);\n for (var i = 0; i < count; i++) {\n var rec = {};\n for (var j = 0; j < fields.length; j++) {\n var fieldName = fields[j];\n var fieldType = recordDescription[fieldName];\n rec[fieldName] = fieldType.call(this);\n }\n records[i] = rec;\n }\n return records;\n };\n\n // Parse a data structure into an object\n // Example of description: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort }\n Parser.prototype.parseStruct = function(description) {\n if (typeof description === 'function') {\n return description.call(this);\n } else {\n var fields = Object.keys(description);\n var struct = {};\n for (var j = 0; j < fields.length; j++) {\n var fieldName = fields[j];\n var fieldType = description[fieldName];\n struct[fieldName] = fieldType.call(this);\n }\n return struct;\n }\n };\n\n /**\n * Parse a GPOS valueRecord\n * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record\n * valueFormat is optional, if omitted it is read from the stream.\n */\n Parser.prototype.parseValueRecord = function(valueFormat) {\n if (valueFormat === undefined) {\n valueFormat = this.parseUShort();\n }\n if (valueFormat === 0) {\n // valueFormat2 in kerning pairs is most often 0\n // in this case return undefined instead of an empty object, to save space\n return;\n }\n var valueRecord = {};\n\n if (valueFormat & 0x0001) { valueRecord.xPlacement = this.parseShort(); }\n if (valueFormat & 0x0002) { valueRecord.yPlacement = this.parseShort(); }\n if (valueFormat & 0x0004) { valueRecord.xAdvance = this.parseShort(); }\n if (valueFormat & 0x0008) { valueRecord.yAdvance = this.parseShort(); }\n\n // Device table (non-variable font) / VariationIndex table (variable font) not supported\n // https://docs.microsoft.com/fr-fr/typography/opentype/spec/chapter2#devVarIdxTbls\n if (valueFormat & 0x0010) { valueRecord.xPlaDevice = undefined; this.parseShort(); }\n if (valueFormat & 0x0020) { valueRecord.yPlaDevice = undefined; this.parseShort(); }\n if (valueFormat & 0x0040) { valueRecord.xAdvDevice = undefined; this.parseShort(); }\n if (valueFormat & 0x0080) { valueRecord.yAdvDevice = undefined; this.parseShort(); }\n\n return valueRecord;\n };\n\n /**\n * Parse a list of GPOS valueRecords\n * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record\n * valueFormat and valueCount are read from the stream.\n */\n Parser.prototype.parseValueRecordList = function() {\n var valueFormat = this.parseUShort();\n var valueCount = this.parseUShort();\n var values = new Array(valueCount);\n for (var i = 0; i < valueCount; i++) {\n values[i] = this.parseValueRecord(valueFormat);\n }\n return values;\n };\n\n Parser.prototype.parsePointer = function(description) {\n var structOffset = this.parseOffset16();\n if (structOffset > 0) {\n // NULL offset => return undefined\n return new Parser(this.data, this.offset + structOffset).parseStruct(description);\n }\n return undefined;\n };\n\n Parser.prototype.parsePointer32 = function(description) {\n var structOffset = this.parseOffset32();\n if (structOffset > 0) {\n // NULL offset => return undefined\n return new Parser(this.data, this.offset + structOffset).parseStruct(description);\n }\n return undefined;\n };\n\n /**\n * Parse a list of offsets to lists of 16-bit integers,\n * or a list of offsets to lists of offsets to any kind of items.\n * If itemCallback is not provided, a list of list of UShort is assumed.\n * If provided, itemCallback is called on each item and must parse the item.\n * See examples in tables/gsub.js\n */\n Parser.prototype.parseListOfLists = function(itemCallback) {\n var offsets = this.parseOffset16List();\n var count = offsets.length;\n var relativeOffset = this.relativeOffset;\n var list = new Array(count);\n for (var i = 0; i < count; i++) {\n var start = offsets[i];\n if (start === 0) {\n // NULL offset\n // Add i as owned property to list. Convenient with assert.\n list[i] = undefined;\n continue;\n }\n this.relativeOffset = start;\n if (itemCallback) {\n var subOffsets = this.parseOffset16List();\n var subList = new Array(subOffsets.length);\n for (var j = 0; j < subOffsets.length; j++) {\n this.relativeOffset = start + subOffsets[j];\n subList[j] = itemCallback.call(this);\n }\n list[i] = subList;\n } else {\n list[i] = this.parseUShortList();\n }\n }\n this.relativeOffset = relativeOffset;\n return list;\n };\n\n ///// Complex tables parsing //////////////////////////////////\n\n // Parse a coverage table in a GSUB, GPOS or GDEF table.\n // https://www.microsoft.com/typography/OTSPEC/chapter2.htm\n // parser.offset must point to the start of the table containing the coverage.\n Parser.prototype.parseCoverage = function() {\n var startOffset = this.offset + this.relativeOffset;\n var format = this.parseUShort();\n var count = this.parseUShort();\n if (format === 1) {\n return {\n format: 1,\n glyphs: this.parseUShortList(count)\n };\n } else if (format === 2) {\n var ranges = new Array(count);\n for (var i = 0; i < count; i++) {\n ranges[i] = {\n start: this.parseUShort(),\n end: this.parseUShort(),\n index: this.parseUShort()\n };\n }\n return {\n format: 2,\n ranges: ranges\n };\n }\n throw new Error('0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.');\n };\n\n // Parse a Class Definition Table in a GSUB, GPOS or GDEF table.\n // https://www.microsoft.com/typography/OTSPEC/chapter2.htm\n Parser.prototype.parseClassDef = function() {\n var startOffset = this.offset + this.relativeOffset;\n var format = this.parseUShort();\n if (format === 1) {\n return {\n format: 1,\n startGlyph: this.parseUShort(),\n classes: this.parseUShortList()\n };\n } else if (format === 2) {\n return {\n format: 2,\n ranges: this.parseRecordList({\n start: Parser.uShort,\n end: Parser.uShort,\n classId: Parser.uShort\n })\n };\n }\n throw new Error('0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.');\n };\n\n ///// Static methods ///////////////////////////////////\n // These convenience methods can be used as callbacks and should be called with \"this\" context set to a Parser instance.\n\n Parser.list = function(count, itemCallback) {\n return function() {\n return this.parseList(count, itemCallback);\n };\n };\n\n Parser.list32 = function(count, itemCallback) {\n return function() {\n return this.parseList32(count, itemCallback);\n };\n };\n\n Parser.recordList = function(count, recordDescription) {\n return function() {\n return this.parseRecordList(count, recordDescription);\n };\n };\n\n Parser.recordList32 = function(count, recordDescription) {\n return function() {\n return this.parseRecordList32(count, recordDescription);\n };\n };\n\n Parser.pointer = function(description) {\n return function() {\n return this.parsePointer(description);\n };\n };\n\n Parser.pointer32 = function(description) {\n return function() {\n return this.parsePointer32(description);\n };\n };\n\n Parser.tag = Parser.prototype.parseTag;\n Parser.byte = Parser.prototype.parseByte;\n Parser.uShort = Parser.offset16 = Parser.prototype.parseUShort;\n Parser.uShortList = Parser.prototype.parseUShortList;\n Parser.uLong = Parser.offset32 = Parser.prototype.parseULong;\n Parser.uLongList = Parser.prototype.parseULongList;\n Parser.struct = Parser.prototype.parseStruct;\n Parser.coverage = Parser.prototype.parseCoverage;\n Parser.classDef = Parser.prototype.parseClassDef;\n\n ///// Script, Feature, Lookup lists ///////////////////////////////////////////////\n // https://www.microsoft.com/typography/OTSPEC/chapter2.htm\n\n var langSysTable = {\n reserved: Parser.uShort,\n reqFeatureIndex: Parser.uShort,\n featureIndexes: Parser.uShortList\n };\n\n Parser.prototype.parseScriptList = function() {\n return this.parsePointer(Parser.recordList({\n tag: Parser.tag,\n script: Parser.pointer({\n defaultLangSys: Parser.pointer(langSysTable),\n langSysRecords: Parser.recordList({\n tag: Parser.tag,\n langSys: Parser.pointer(langSysTable)\n })\n })\n })) || [];\n };\n\n Parser.prototype.parseFeatureList = function() {\n return this.parsePointer(Parser.recordList({\n tag: Parser.tag,\n feature: Parser.pointer({\n featureParams: Parser.offset16,\n lookupListIndexes: Parser.uShortList\n })\n })) || [];\n };\n\n Parser.prototype.parseLookupList = function(lookupTableParsers) {\n return this.parsePointer(Parser.list(Parser.pointer(function() {\n var lookupType = this.parseUShort();\n check.argument(1 <= lookupType && lookupType <= 9, 'GPOS/GSUB lookup type ' + lookupType + ' unknown.');\n var lookupFlag = this.parseUShort();\n var useMarkFilteringSet = lookupFlag & 0x10;\n return {\n lookupType: lookupType,\n lookupFlag: lookupFlag,\n subtables: this.parseList(Parser.pointer(lookupTableParsers[lookupType])),\n markFilteringSet: useMarkFilteringSet ? this.parseUShort() : undefined\n };\n }))) || [];\n };\n\n Parser.prototype.parseFeatureVariationsList = function() {\n return this.parsePointer32(function() {\n var majorVersion = this.parseUShort();\n var minorVersion = this.parseUShort();\n check.argument(majorVersion === 1 && minorVersion < 1, 'GPOS/GSUB feature variations table unknown.');\n var featureVariations = this.parseRecordList32({\n conditionSetOffset: Parser.offset32,\n featureTableSubstitutionOffset: Parser.offset32\n });\n return featureVariations;\n }) || [];\n };\n\n var parse = {\n getByte: getByte,\n getCard8: getByte,\n getUShort: getUShort,\n getCard16: getUShort,\n getShort: getShort,\n getULong: getULong,\n getFixed: getFixed,\n getTag: getTag,\n getOffset: getOffset,\n getBytes: getBytes,\n bytesToString: bytesToString,\n Parser: Parser,\n };\n\n // The `cmap` table stores the mappings from characters to glyphs.\n\n function parseCmapTableFormat12(cmap, p) {\n //Skip reserved.\n p.parseUShort();\n\n // Length in bytes of the sub-tables.\n cmap.length = p.parseULong();\n cmap.language = p.parseULong();\n\n var groupCount;\n cmap.groupCount = groupCount = p.parseULong();\n cmap.glyphIndexMap = {};\n\n for (var i = 0; i < groupCount; i += 1) {\n var startCharCode = p.parseULong();\n var endCharCode = p.parseULong();\n var startGlyphId = p.parseULong();\n\n for (var c = startCharCode; c <= endCharCode; c += 1) {\n cmap.glyphIndexMap[c] = startGlyphId;\n startGlyphId++;\n }\n }\n }\n\n function parseCmapTableFormat4(cmap, p, data, start, offset) {\n // Length in bytes of the sub-tables.\n cmap.length = p.parseUShort();\n cmap.language = p.parseUShort();\n\n // segCount is stored x 2.\n var segCount;\n cmap.segCount = segCount = p.parseUShort() >> 1;\n\n // Skip searchRange, entrySelector, rangeShift.\n p.skip('uShort', 3);\n\n // The \"unrolled\" mapping from character codes to glyph indices.\n cmap.glyphIndexMap = {};\n var endCountParser = new parse.Parser(data, start + offset + 14);\n var startCountParser = new parse.Parser(data, start + offset + 16 + segCount * 2);\n var idDeltaParser = new parse.Parser(data, start + offset + 16 + segCount * 4);\n var idRangeOffsetParser = new parse.Parser(data, start + offset + 16 + segCount * 6);\n var glyphIndexOffset = start + offset + 16 + segCount * 8;\n for (var i = 0; i < segCount - 1; i += 1) {\n var glyphIndex = (void 0);\n var endCount = endCountParser.parseUShort();\n var startCount = startCountParser.parseUShort();\n var idDelta = idDeltaParser.parseShort();\n var idRangeOffset = idRangeOffsetParser.parseUShort();\n for (var c = startCount; c <= endCount; c += 1) {\n if (idRangeOffset !== 0) {\n // The idRangeOffset is relative to the current position in the idRangeOffset array.\n // Take the current offset in the idRangeOffset array.\n glyphIndexOffset = (idRangeOffsetParser.offset + idRangeOffsetParser.relativeOffset - 2);\n\n // Add the value of the idRangeOffset, which will move us into the glyphIndex array.\n glyphIndexOffset += idRangeOffset;\n\n // Then add the character index of the current segment, multiplied by 2 for USHORTs.\n glyphIndexOffset += (c - startCount) * 2;\n glyphIndex = parse.getUShort(data, glyphIndexOffset);\n if (glyphIndex !== 0) {\n glyphIndex = (glyphIndex + idDelta) & 0xFFFF;\n }\n } else {\n glyphIndex = (c + idDelta) & 0xFFFF;\n }\n\n cmap.glyphIndexMap[c] = glyphIndex;\n }\n }\n }\n\n // Parse the `cmap` table. This table stores the mappings from characters to glyphs.\n // There are many available formats, but we only support the Windows format 4 and 12.\n // This function returns a `CmapEncoding` object or null if no supported format could be found.\n function parseCmapTable(data, start) {\n var cmap = {};\n cmap.version = parse.getUShort(data, start);\n check.argument(cmap.version === 0, 'cmap table version should be 0.');\n\n // The cmap table can contain many sub-tables, each with their own format.\n // We're only interested in a \"platform 0\" (Unicode format) and \"platform 3\" (Windows format) table.\n cmap.numTables = parse.getUShort(data, start + 2);\n var offset = -1;\n for (var i = cmap.numTables - 1; i >= 0; i -= 1) {\n var platformId = parse.getUShort(data, start + 4 + (i * 8));\n var encodingId = parse.getUShort(data, start + 4 + (i * 8) + 2);\n if ((platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10)) ||\n (platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 2 || encodingId === 3 || encodingId === 4))) {\n offset = parse.getULong(data, start + 4 + (i * 8) + 4);\n break;\n }\n }\n\n if (offset === -1) {\n // There is no cmap table in the font that we support.\n throw new Error('No valid cmap sub-tables found.');\n }\n\n var p = new parse.Parser(data, start + offset);\n cmap.format = p.parseUShort();\n\n if (cmap.format === 12) {\n parseCmapTableFormat12(cmap, p);\n } else if (cmap.format === 4) {\n parseCmapTableFormat4(cmap, p, data, start, offset);\n } else {\n throw new Error('Only format 4 and 12 cmap tables are supported (found format ' + cmap.format + ').');\n }\n\n return cmap;\n }\n\n function addSegment(t, code, glyphIndex) {\n t.segments.push({\n end: code,\n start: code,\n delta: -(code - glyphIndex),\n offset: 0,\n glyphIndex: glyphIndex\n });\n }\n\n function addTerminatorSegment(t) {\n t.segments.push({\n end: 0xFFFF,\n start: 0xFFFF,\n delta: 1,\n offset: 0\n });\n }\n\n // Make cmap table, format 4 by default, 12 if needed only\n function makeCmapTable(glyphs) {\n // Plan 0 is the base Unicode Plan but emojis, for example are on another plan, and needs cmap 12 format (with 32bit)\n var isPlan0Only = true;\n var i;\n\n // Check if we need to add cmap format 12 or if format 4 only is fine\n for (i = glyphs.length - 1; i > 0; i -= 1) {\n var g = glyphs.get(i);\n if (g.unicode > 65535) {\n console.log('Adding CMAP format 12 (needed!)');\n isPlan0Only = false;\n break;\n }\n }\n\n var cmapTable = [\n {name: 'version', type: 'USHORT', value: 0},\n {name: 'numTables', type: 'USHORT', value: isPlan0Only ? 1 : 2},\n\n // CMAP 4 header\n {name: 'platformID', type: 'USHORT', value: 3},\n {name: 'encodingID', type: 'USHORT', value: 1},\n {name: 'offset', type: 'ULONG', value: isPlan0Only ? 12 : (12 + 8)}\n ];\n\n if (!isPlan0Only)\n { cmapTable = cmapTable.concat([\n // CMAP 12 header\n {name: 'cmap12PlatformID', type: 'USHORT', value: 3}, // We encode only for PlatformID = 3 (Windows) because it is supported everywhere\n {name: 'cmap12EncodingID', type: 'USHORT', value: 10},\n {name: 'cmap12Offset', type: 'ULONG', value: 0}\n ]); }\n\n cmapTable = cmapTable.concat([\n // CMAP 4 Subtable\n {name: 'format', type: 'USHORT', value: 4},\n {name: 'cmap4Length', type: 'USHORT', value: 0},\n {name: 'language', type: 'USHORT', value: 0},\n {name: 'segCountX2', type: 'USHORT', value: 0},\n {name: 'searchRange', type: 'USHORT', value: 0},\n {name: 'entrySelector', type: 'USHORT', value: 0},\n {name: 'rangeShift', type: 'USHORT', value: 0}\n ]);\n\n var t = new table.Table('cmap', cmapTable);\n\n t.segments = [];\n for (i = 0; i < glyphs.length; i += 1) {\n var glyph = glyphs.get(i);\n for (var j = 0; j < glyph.unicodes.length; j += 1) {\n addSegment(t, glyph.unicodes[j], i);\n }\n\n t.segments = t.segments.sort(function (a, b) {\n return a.start - b.start;\n });\n }\n\n addTerminatorSegment(t);\n\n var segCount = t.segments.length;\n var segCountToRemove = 0;\n\n // CMAP 4\n // Set up parallel segment arrays.\n var endCounts = [];\n var startCounts = [];\n var idDeltas = [];\n var idRangeOffsets = [];\n var glyphIds = [];\n\n // CMAP 12\n var cmap12Groups = [];\n\n // Reminder this loop is not following the specification at 100%\n // The specification -> find suites of characters and make a group\n // Here we're doing one group for each letter\n // Doing as the spec can save 8 times (or more) space\n for (i = 0; i < segCount; i += 1) {\n var segment = t.segments[i];\n\n // CMAP 4\n if (segment.end <= 65535 && segment.start <= 65535) {\n endCounts = endCounts.concat({name: 'end_' + i, type: 'USHORT', value: segment.end});\n startCounts = startCounts.concat({name: 'start_' + i, type: 'USHORT', value: segment.start});\n idDeltas = idDeltas.concat({name: 'idDelta_' + i, type: 'SHORT', value: segment.delta});\n idRangeOffsets = idRangeOffsets.concat({name: 'idRangeOffset_' + i, type: 'USHORT', value: segment.offset});\n if (segment.glyphId !== undefined) {\n glyphIds = glyphIds.concat({name: 'glyph_' + i, type: 'USHORT', value: segment.glyphId});\n }\n } else {\n // Skip Unicode > 65535 (16bit unsigned max) for CMAP 4, will be added in CMAP 12\n segCountToRemove += 1;\n }\n\n // CMAP 12\n // Skip Terminator Segment\n if (!isPlan0Only && segment.glyphIndex !== undefined) {\n cmap12Groups = cmap12Groups.concat({name: 'cmap12Start_' + i, type: 'ULONG', value: segment.start});\n cmap12Groups = cmap12Groups.concat({name: 'cmap12End_' + i, type: 'ULONG', value: segment.end});\n cmap12Groups = cmap12Groups.concat({name: 'cmap12Glyph_' + i, type: 'ULONG', value: segment.glyphIndex});\n }\n }\n\n // CMAP 4 Subtable\n t.segCountX2 = (segCount - segCountToRemove) * 2;\n t.searchRange = Math.pow(2, Math.floor(Math.log((segCount - segCountToRemove)) / Math.log(2))) * 2;\n t.entrySelector = Math.log(t.searchRange / 2) / Math.log(2);\n t.rangeShift = t.segCountX2 - t.searchRange;\n\n t.fields = t.fields.concat(endCounts);\n t.fields.push({name: 'reservedPad', type: 'USHORT', value: 0});\n t.fields = t.fields.concat(startCounts);\n t.fields = t.fields.concat(idDeltas);\n t.fields = t.fields.concat(idRangeOffsets);\n t.fields = t.fields.concat(glyphIds);\n\n t.cmap4Length = 14 + // Subtable header\n endCounts.length * 2 +\n 2 + // reservedPad\n startCounts.length * 2 +\n idDeltas.length * 2 +\n idRangeOffsets.length * 2 +\n glyphIds.length * 2;\n\n if (!isPlan0Only) {\n // CMAP 12 Subtable\n var cmap12Length = 16 + // Subtable header\n cmap12Groups.length * 4;\n\n t.cmap12Offset = 12 + (2 * 2) + 4 + t.cmap4Length;\n t.fields = t.fields.concat([\n {name: 'cmap12Format', type: 'USHORT', value: 12},\n {name: 'cmap12Reserved', type: 'USHORT', value: 0},\n {name: 'cmap12Length', type: 'ULONG', value: cmap12Length},\n {name: 'cmap12Language', type: 'ULONG', value: 0},\n {name: 'cmap12nGroups', type: 'ULONG', value: cmap12Groups.length / 3}\n ]);\n\n t.fields = t.fields.concat(cmap12Groups);\n }\n\n return t;\n }\n\n var cmap = { parse: parseCmapTable, make: makeCmapTable };\n\n // Glyph encoding\n\n var cffStandardStrings = [\n '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',\n 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two',\n 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater',\n 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',\n 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',\n 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent', 'sterling',\n 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle', 'quotedblleft', 'guillemotleft',\n 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl', 'periodcentered', 'paragraph',\n 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand',\n 'questiondown', 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', 'ring',\n 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE',\n 'ordmasculine', 'ae', 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',\n 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn',\n 'threequarters', 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',\n 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex',\n 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',\n 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute',\n 'Ydieresis', 'Zcaron', 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla', 'eacute',\n 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute',\n 'ocircumflex', 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis', 'ugrave',\n 'yacute', 'ydieresis', 'zcaron', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior',\n 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', '266 ff', 'onedotenleader',\n 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',\n 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior', 'threequartersemdash', 'periodsuperior',\n 'questionsmall', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',\n 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior', 'tsuperior', 'ff', 'ffi', 'ffl',\n 'parenleftinferior', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall',\n 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall',\n 'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',\n 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall',\n 'centoldstyle', 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',\n 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall',\n 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',\n 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',\n 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',\n 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',\n 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',\n 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',\n 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall',\n 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',\n 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall', '001.000',\n '001.001', '001.002', '001.003', 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'];\n\n var cffStandardEncoding = [\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n '', '', '', '', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',\n 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two',\n 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater',\n 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',\n 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',\n 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '', '', '', '', '', '', '', '',\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n 'exclamdown', 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle',\n 'quotedblleft', 'guillemotleft', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger',\n 'daggerdbl', 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright',\n 'guillemotright', 'ellipsis', 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex', 'tilde',\n 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla', '', 'hungarumlaut', 'ogonek', 'caron',\n 'emdash', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '', '',\n '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae', '', '', '', 'dotlessi', '', '',\n 'lslash', 'oslash', 'oe', 'germandbls'];\n\n var cffExpertEncoding = [\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n '', '', '', '', 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle', 'dollarsuperior',\n 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader', 'onedotenleader',\n 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',\n 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',\n 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior', 'questionsmall', '', 'asuperior',\n 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',\n 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior', '', 'ff', 'fi', 'fl', 'ffi', 'ffl',\n 'parenleftinferior', '', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall',\n 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall',\n 'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',\n 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '',\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n 'exclamdownsmall', 'centoldstyle', 'Lslashsmall', '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',\n 'Brevesmall', 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '', 'figuredash', 'hypheninferior',\n '', '', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',\n 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds', '',\n '', 'zerosuperior', 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',\n 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',\n 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',\n 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',\n 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',\n 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',\n 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall',\n 'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',\n 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall'];\n\n var standardNames = [\n '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',\n 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',\n 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',\n 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',\n 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',\n 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',\n 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',\n 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis', 'Udieresis', 'aacute', 'agrave',\n 'acircumflex', 'adieresis', 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',\n 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve', 'ocircumflex', 'odieresis',\n 'otilde', 'uacute', 'ugrave', 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section',\n 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute', 'dieresis', 'notequal',\n 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation',\n 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash', 'questiondown',\n 'exclamdown', 'logicalnot', 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft', 'guillemotright',\n 'ellipsis', 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash', 'emdash', 'quotedblleft',\n 'quotedblright', 'quoteleft', 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',\n 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered', 'quotesinglbase',\n 'quotedblbase', 'perthousand', 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',\n 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute', 'Ucircumflex',\n 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',\n 'ogonek', 'caron', 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar', 'Eth', 'eth',\n 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply', 'onesuperior', 'twosuperior', 'threesuperior',\n 'onehalf', 'onequarter', 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla', 'scedilla',\n 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];\n\n /**\n * This is the encoding used for fonts created from scratch.\n * It loops through all glyphs and finds the appropriate unicode value.\n * Since it's linear time, other encodings will be faster.\n * @exports opentype.DefaultEncoding\n * @class\n * @constructor\n * @param {opentype.Font}\n */\n function DefaultEncoding(font) {\n this.font = font;\n }\n\n DefaultEncoding.prototype.charToGlyphIndex = function(c) {\n var code = c.codePointAt(0);\n var glyphs = this.font.glyphs;\n if (glyphs) {\n for (var i = 0; i < glyphs.length; i += 1) {\n var glyph = glyphs.get(i);\n for (var j = 0; j < glyph.unicodes.length; j += 1) {\n if (glyph.unicodes[j] === code) {\n return i;\n }\n }\n }\n }\n return null;\n };\n\n /**\n * @exports opentype.CmapEncoding\n * @class\n * @constructor\n * @param {Object} cmap - a object with the cmap encoded data\n */\n function CmapEncoding(cmap) {\n this.cmap = cmap;\n }\n\n /**\n * @param {string} c - the character\n * @return {number} The glyph index.\n */\n CmapEncoding.prototype.charToGlyphIndex = function(c) {\n return this.cmap.glyphIndexMap[c.codePointAt(0)] || 0;\n };\n\n /**\n * @exports opentype.CffEncoding\n * @class\n * @constructor\n * @param {string} encoding - The encoding\n * @param {Array} charset - The character set.\n */\n function CffEncoding(encoding, charset) {\n this.encoding = encoding;\n this.charset = charset;\n }\n\n /**\n * @param {string} s - The character\n * @return {number} The index.\n */\n CffEncoding.prototype.charToGlyphIndex = function(s) {\n var code = s.codePointAt(0);\n var charName = this.encoding[code];\n return this.charset.indexOf(charName);\n };\n\n /**\n * @exports opentype.GlyphNames\n * @class\n * @constructor\n * @param {Object} post\n */\n function GlyphNames(post) {\n switch (post.version) {\n case 1:\n this.names = standardNames.slice();\n break;\n case 2:\n this.names = new Array(post.numberOfGlyphs);\n for (var i = 0; i < post.numberOfGlyphs; i++) {\n if (post.glyphNameIndex[i] < standardNames.length) {\n this.names[i] = standardNames[post.glyphNameIndex[i]];\n } else {\n this.names[i] = post.names[post.glyphNameIndex[i] - standardNames.length];\n }\n }\n\n break;\n case 2.5:\n this.names = new Array(post.numberOfGlyphs);\n for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) {\n this.names[i$1] = standardNames[i$1 + post.glyphNameIndex[i$1]];\n }\n\n break;\n case 3:\n this.names = [];\n break;\n default:\n this.names = [];\n break;\n }\n }\n\n /**\n * Gets the index of a glyph by name.\n * @param {string} name - The glyph name\n * @return {number} The index\n */\n GlyphNames.prototype.nameToGlyphIndex = function(name) {\n return this.names.indexOf(name);\n };\n\n /**\n * @param {number} gid\n * @return {string}\n */\n GlyphNames.prototype.glyphIndexToName = function(gid) {\n return this.names[gid];\n };\n\n function addGlyphNamesAll(font) {\n var glyph;\n var glyphIndexMap = font.tables.cmap.glyphIndexMap;\n var charCodes = Object.keys(glyphIndexMap);\n\n for (var i = 0; i < charCodes.length; i += 1) {\n var c = charCodes[i];\n var glyphIndex = glyphIndexMap[c];\n glyph = font.glyphs.get(glyphIndex);\n glyph.addUnicode(parseInt(c));\n }\n\n for (var i$1 = 0; i$1 < font.glyphs.length; i$1 += 1) {\n glyph = font.glyphs.get(i$1);\n if (font.cffEncoding) {\n if (font.isCIDFont) {\n glyph.name = 'gid' + i$1;\n } else {\n glyph.name = font.cffEncoding.charset[i$1];\n }\n } else if (font.glyphNames.names) {\n glyph.name = font.glyphNames.glyphIndexToName(i$1);\n }\n }\n }\n\n function addGlyphNamesToUnicodeMap(font) {\n font._IndexToUnicodeMap = {};\n\n var glyphIndexMap = font.tables.cmap.glyphIndexMap;\n var charCodes = Object.keys(glyphIndexMap);\n\n for (var i = 0; i < charCodes.length; i += 1) {\n var c = charCodes[i];\n var glyphIndex = glyphIndexMap[c];\n if (font._IndexToUnicodeMap[glyphIndex] === undefined) {\n font._IndexToUnicodeMap[glyphIndex] = {\n unicodes: [parseInt(c)]\n };\n } else {\n font._IndexToUnicodeMap[glyphIndex].unicodes.push(parseInt(c));\n }\n }\n }\n\n /**\n * @alias opentype.addGlyphNames\n * @param {opentype.Font}\n * @param {Object}\n */\n function addGlyphNames(font, opt) {\n if (opt.lowMemory) {\n addGlyphNamesToUnicodeMap(font);\n } else {\n addGlyphNamesAll(font);\n }\n }\n\n // Drawing utility functions.\n\n // Draw a line on the given context from point `x1,y1` to point `x2,y2`.\n function line(ctx, x1, y1, x2, y2) {\n ctx.beginPath();\n ctx.moveTo(x1, y1);\n ctx.lineTo(x2, y2);\n ctx.stroke();\n }\n\n var draw = { line: line };\n\n // The Glyph object\n // import glyf from './tables/glyf' Can't be imported here, because it's a circular dependency\n\n function getPathDefinition(glyph, path) {\n var _path = path || new Path();\n return {\n configurable: true,\n\n get: function() {\n if (typeof _path === 'function') {\n _path = _path();\n }\n\n return _path;\n },\n\n set: function(p) {\n _path = p;\n }\n };\n }\n /**\n * @typedef GlyphOptions\n * @type Object\n * @property {string} [name] - The glyph name\n * @property {number} [unicode]\n * @property {Array} [unicodes]\n * @property {number} [xMin]\n * @property {number} [yMin]\n * @property {number} [xMax]\n * @property {number} [yMax]\n * @property {number} [advanceWidth]\n */\n\n // A Glyph is an individual mark that often corresponds to a character.\n // Some glyphs, such as ligatures, are a combination of many characters.\n // Glyphs are the basic building blocks of a font.\n //\n // The `Glyph` class contains utility methods for drawing the path and its points.\n /**\n * @exports opentype.Glyph\n * @class\n * @param {GlyphOptions}\n * @constructor\n */\n function Glyph(options) {\n // By putting all the code on a prototype function (which is only declared once)\n // we reduce the memory requirements for larger fonts by some 2%\n this.bindConstructorValues(options);\n }\n\n /**\n * @param {GlyphOptions}\n */\n Glyph.prototype.bindConstructorValues = function(options) {\n this.index = options.index || 0;\n\n // These three values cannot be deferred for memory optimization:\n this.name = options.name || null;\n this.unicode = options.unicode || undefined;\n this.unicodes = options.unicodes || options.unicode !== undefined ? [options.unicode] : [];\n\n // But by binding these values only when necessary, we reduce can\n // the memory requirements by almost 3% for larger fonts.\n if ('xMin' in options) {\n this.xMin = options.xMin;\n }\n\n if ('yMin' in options) {\n this.yMin = options.yMin;\n }\n\n if ('xMax' in options) {\n this.xMax = options.xMax;\n }\n\n if ('yMax' in options) {\n this.yMax = options.yMax;\n }\n\n if ('advanceWidth' in options) {\n this.advanceWidth = options.advanceWidth;\n }\n\n // The path for a glyph is the most memory intensive, and is bound as a value\n // with a getter/setter to ensure we actually do path parsing only once the\n // path is actually needed by anything.\n Object.defineProperty(this, 'path', getPathDefinition(this, options.path));\n };\n\n /**\n * @param {number}\n */\n Glyph.prototype.addUnicode = function(unicode) {\n if (this.unicodes.length === 0) {\n this.unicode = unicode;\n }\n\n this.unicodes.push(unicode);\n };\n\n /**\n * Calculate the minimum bounding box for this glyph.\n * @return {opentype.BoundingBox}\n */\n Glyph.prototype.getBoundingBox = function() {\n return this.path.getBoundingBox();\n };\n\n /**\n * Convert the glyph to a Path we can draw on a drawing context.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {Object=} options - xScale, yScale to stretch the glyph.\n * @param {opentype.Font} if hinting is to be used, the font\n * @return {opentype.Path}\n */\n Glyph.prototype.getPath = function(x, y, fontSize, options, font) {\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 72;\n var commands;\n var hPoints;\n if (!options) { options = { }; }\n var xScale = options.xScale;\n var yScale = options.yScale;\n\n if (options.hinting && font && font.hinting) {\n // in case of hinting, the hinting engine takes care\n // of scaling the points (not the path) before hinting.\n hPoints = this.path && font.hinting.exec(this, fontSize);\n // in case the hinting engine failed hPoints is undefined\n // and thus reverts to plain rending\n }\n\n if (hPoints) {\n // Call font.hinting.getCommands instead of `glyf.getPath(hPoints).commands` to avoid a circular dependency\n commands = font.hinting.getCommands(hPoints);\n x = Math.round(x);\n y = Math.round(y);\n // TODO in case of hinting xyScaling is not yet supported\n xScale = yScale = 1;\n } else {\n commands = this.path.commands;\n var scale = 1 / (this.path.unitsPerEm || 1000) * fontSize;\n if (xScale === undefined) { xScale = scale; }\n if (yScale === undefined) { yScale = scale; }\n }\n\n var p = new Path();\n for (var i = 0; i < commands.length; i += 1) {\n var cmd = commands[i];\n if (cmd.type === 'M') {\n p.moveTo(x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'L') {\n p.lineTo(x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'Q') {\n p.quadraticCurveTo(x + (cmd.x1 * xScale), y + (-cmd.y1 * yScale),\n x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'C') {\n p.curveTo(x + (cmd.x1 * xScale), y + (-cmd.y1 * yScale),\n x + (cmd.x2 * xScale), y + (-cmd.y2 * yScale),\n x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'Z') {\n p.closePath();\n }\n }\n\n return p;\n };\n\n /**\n * Split the glyph into contours.\n * This function is here for backwards compatibility, and to\n * provide raw access to the TrueType glyph outlines.\n * @return {Array}\n */\n Glyph.prototype.getContours = function() {\n if (this.points === undefined) {\n return [];\n }\n\n var contours = [];\n var currentContour = [];\n for (var i = 0; i < this.points.length; i += 1) {\n var pt = this.points[i];\n currentContour.push(pt);\n if (pt.lastPointOfContour) {\n contours.push(currentContour);\n currentContour = [];\n }\n }\n\n check.argument(currentContour.length === 0, 'There are still points left in the current contour.');\n return contours;\n };\n\n /**\n * Calculate the xMin/yMin/xMax/yMax/lsb/rsb for a Glyph.\n * @return {Object}\n */\n Glyph.prototype.getMetrics = function() {\n var commands = this.path.commands;\n var xCoords = [];\n var yCoords = [];\n for (var i = 0; i < commands.length; i += 1) {\n var cmd = commands[i];\n if (cmd.type !== 'Z') {\n xCoords.push(cmd.x);\n yCoords.push(cmd.y);\n }\n\n if (cmd.type === 'Q' || cmd.type === 'C') {\n xCoords.push(cmd.x1);\n yCoords.push(cmd.y1);\n }\n\n if (cmd.type === 'C') {\n xCoords.push(cmd.x2);\n yCoords.push(cmd.y2);\n }\n }\n\n var metrics = {\n xMin: Math.min.apply(null, xCoords),\n yMin: Math.min.apply(null, yCoords),\n xMax: Math.max.apply(null, xCoords),\n yMax: Math.max.apply(null, yCoords),\n leftSideBearing: this.leftSideBearing\n };\n\n if (!isFinite(metrics.xMin)) {\n metrics.xMin = 0;\n }\n\n if (!isFinite(metrics.xMax)) {\n metrics.xMax = this.advanceWidth;\n }\n\n if (!isFinite(metrics.yMin)) {\n metrics.yMin = 0;\n }\n\n if (!isFinite(metrics.yMax)) {\n metrics.yMax = 0;\n }\n\n metrics.rightSideBearing = this.advanceWidth - metrics.leftSideBearing - (metrics.xMax - metrics.xMin);\n return metrics;\n };\n\n /**\n * Draw the glyph on the given context.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {Object=} options - xScale, yScale to stretch the glyph.\n */\n Glyph.prototype.draw = function(ctx, x, y, fontSize, options) {\n this.getPath(x, y, fontSize, options).draw(ctx);\n };\n\n /**\n * Draw the points of the glyph.\n * On-curve points will be drawn in blue, off-curve points will be drawn in red.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n */\n Glyph.prototype.drawPoints = function(ctx, x, y, fontSize) {\n function drawCircles(l, x, y, scale) {\n ctx.beginPath();\n for (var j = 0; j < l.length; j += 1) {\n ctx.moveTo(x + (l[j].x * scale), y + (l[j].y * scale));\n ctx.arc(x + (l[j].x * scale), y + (l[j].y * scale), 2, 0, Math.PI * 2, false);\n }\n\n ctx.closePath();\n ctx.fill();\n }\n\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 24;\n var scale = 1 / this.path.unitsPerEm * fontSize;\n\n var blueCircles = [];\n var redCircles = [];\n var path = this.path;\n for (var i = 0; i < path.commands.length; i += 1) {\n var cmd = path.commands[i];\n if (cmd.x !== undefined) {\n blueCircles.push({x: cmd.x, y: -cmd.y});\n }\n\n if (cmd.x1 !== undefined) {\n redCircles.push({x: cmd.x1, y: -cmd.y1});\n }\n\n if (cmd.x2 !== undefined) {\n redCircles.push({x: cmd.x2, y: -cmd.y2});\n }\n }\n\n ctx.fillStyle = 'blue';\n drawCircles(blueCircles, x, y, scale);\n ctx.fillStyle = 'red';\n drawCircles(redCircles, x, y, scale);\n };\n\n /**\n * Draw lines indicating important font measurements.\n * Black lines indicate the origin of the coordinate system (point 0,0).\n * Blue lines indicate the glyph bounding box.\n * Green line indicates the advance width of the glyph.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n */\n Glyph.prototype.drawMetrics = function(ctx, x, y, fontSize) {\n var scale;\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 24;\n scale = 1 / this.path.unitsPerEm * fontSize;\n ctx.lineWidth = 1;\n\n // Draw the origin\n ctx.strokeStyle = 'black';\n draw.line(ctx, x, -10000, x, 10000);\n draw.line(ctx, -10000, y, 10000, y);\n\n // This code is here due to memory optimization: by not using\n // defaults in the constructor, we save a notable amount of memory.\n var xMin = this.xMin || 0;\n var yMin = this.yMin || 0;\n var xMax = this.xMax || 0;\n var yMax = this.yMax || 0;\n var advanceWidth = this.advanceWidth || 0;\n\n // Draw the glyph box\n ctx.strokeStyle = 'blue';\n draw.line(ctx, x + (xMin * scale), -10000, x + (xMin * scale), 10000);\n draw.line(ctx, x + (xMax * scale), -10000, x + (xMax * scale), 10000);\n draw.line(ctx, -10000, y + (-yMin * scale), 10000, y + (-yMin * scale));\n draw.line(ctx, -10000, y + (-yMax * scale), 10000, y + (-yMax * scale));\n\n // Draw the advance width\n ctx.strokeStyle = 'green';\n draw.line(ctx, x + (advanceWidth * scale), -10000, x + (advanceWidth * scale), 10000);\n };\n\n // The GlyphSet object\n\n // Define a property on the glyph that depends on the path being loaded.\n function defineDependentProperty(glyph, externalName, internalName) {\n Object.defineProperty(glyph, externalName, {\n get: function() {\n // Request the path property to make sure the path is loaded.\n glyph.path; // jshint ignore:line\n return glyph[internalName];\n },\n set: function(newValue) {\n glyph[internalName] = newValue;\n },\n enumerable: true,\n configurable: true\n });\n }\n\n /**\n * A GlyphSet represents all glyphs available in the font, but modelled using\n * a deferred glyph loader, for retrieving glyphs only once they are absolutely\n * necessary, to keep the memory footprint down.\n * @exports opentype.GlyphSet\n * @class\n * @param {opentype.Font}\n * @param {Array}\n */\n function GlyphSet(font, glyphs) {\n this.font = font;\n this.glyphs = {};\n if (Array.isArray(glyphs)) {\n for (var i = 0; i < glyphs.length; i++) {\n var glyph = glyphs[i];\n glyph.path.unitsPerEm = font.unitsPerEm;\n this.glyphs[i] = glyph;\n }\n }\n\n this.length = (glyphs && glyphs.length) || 0;\n }\n\n /**\n * @param {number} index\n * @return {opentype.Glyph}\n */\n GlyphSet.prototype.get = function(index) {\n // this.glyphs[index] is 'undefined' when low memory mode is on. glyph is pushed on request only.\n if (this.glyphs[index] === undefined) {\n this.font._push(index);\n if (typeof this.glyphs[index] === 'function') {\n this.glyphs[index] = this.glyphs[index]();\n }\n\n var glyph = this.glyphs[index];\n var unicodeObj = this.font._IndexToUnicodeMap[index];\n\n if (unicodeObj) {\n for (var j = 0; j < unicodeObj.unicodes.length; j++)\n { glyph.addUnicode(unicodeObj.unicodes[j]); }\n }\n\n if (this.font.cffEncoding) {\n if (this.font.isCIDFont) {\n glyph.name = 'gid' + index;\n } else {\n glyph.name = this.font.cffEncoding.charset[index];\n }\n } else if (this.font.glyphNames.names) {\n glyph.name = this.font.glyphNames.glyphIndexToName(index);\n }\n\n this.glyphs[index].advanceWidth = this.font._hmtxTableData[index].advanceWidth;\n this.glyphs[index].leftSideBearing = this.font._hmtxTableData[index].leftSideBearing;\n } else {\n if (typeof this.glyphs[index] === 'function') {\n this.glyphs[index] = this.glyphs[index]();\n }\n }\n\n return this.glyphs[index];\n };\n\n /**\n * @param {number} index\n * @param {Object}\n */\n GlyphSet.prototype.push = function(index, loader) {\n this.glyphs[index] = loader;\n this.length++;\n };\n\n /**\n * @alias opentype.glyphLoader\n * @param {opentype.Font} font\n * @param {number} index\n * @return {opentype.Glyph}\n */\n function glyphLoader(font, index) {\n return new Glyph({index: index, font: font});\n }\n\n /**\n * Generate a stub glyph that can be filled with all metadata *except*\n * the \"points\" and \"path\" properties, which must be loaded only once\n * the glyph's path is actually requested for text shaping.\n * @alias opentype.ttfGlyphLoader\n * @param {opentype.Font} font\n * @param {number} index\n * @param {Function} parseGlyph\n * @param {Object} data\n * @param {number} position\n * @param {Function} buildPath\n * @return {opentype.Glyph}\n */\n function ttfGlyphLoader(font, index, parseGlyph, data, position, buildPath) {\n return function() {\n var glyph = new Glyph({index: index, font: font});\n\n glyph.path = function() {\n parseGlyph(glyph, data, position);\n var path = buildPath(font.glyphs, glyph);\n path.unitsPerEm = font.unitsPerEm;\n return path;\n };\n\n defineDependentProperty(glyph, 'xMin', '_xMin');\n defineDependentProperty(glyph, 'xMax', '_xMax');\n defineDependentProperty(glyph, 'yMin', '_yMin');\n defineDependentProperty(glyph, 'yMax', '_yMax');\n\n return glyph;\n };\n }\n /**\n * @alias opentype.cffGlyphLoader\n * @param {opentype.Font} font\n * @param {number} index\n * @param {Function} parseCFFCharstring\n * @param {string} charstring\n * @return {opentype.Glyph}\n */\n function cffGlyphLoader(font, index, parseCFFCharstring, charstring) {\n return function() {\n var glyph = new Glyph({index: index, font: font});\n\n glyph.path = function() {\n var path = parseCFFCharstring(font, glyph, charstring);\n path.unitsPerEm = font.unitsPerEm;\n return path;\n };\n\n return glyph;\n };\n }\n\n var glyphset = { GlyphSet: GlyphSet, glyphLoader: glyphLoader, ttfGlyphLoader: ttfGlyphLoader, cffGlyphLoader: cffGlyphLoader };\n\n // The `CFF` table contains the glyph outlines in PostScript format.\n\n // Custom equals function that can also check lists.\n function equals$1(a, b) {\n if (a === b) {\n return true;\n } else if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) {\n return false;\n }\n\n for (var i = 0; i < a.length; i += 1) {\n if (!equals$1(a[i], b[i])) {\n return false;\n }\n }\n\n return true;\n } else {\n return false;\n }\n }\n\n // Subroutines are encoded using the negative half of the number space.\n // See type 2 chapter 4.7 \"Subroutine operators\".\n function calcCFFSubroutineBias(subrs) {\n var bias;\n if (subrs.length < 1240) {\n bias = 107;\n } else if (subrs.length < 33900) {\n bias = 1131;\n } else {\n bias = 32768;\n }\n\n return bias;\n }\n\n // Parse a `CFF` INDEX array.\n // An index array consists of a list of offsets, then a list of objects at those offsets.\n function parseCFFIndex(data, start, conversionFn) {\n var offsets = [];\n var objects = [];\n var count = parse.getCard16(data, start);\n var objectOffset;\n var endOffset;\n if (count !== 0) {\n var offsetSize = parse.getByte(data, start + 2);\n objectOffset = start + ((count + 1) * offsetSize) + 2;\n var pos = start + 3;\n for (var i = 0; i < count + 1; i += 1) {\n offsets.push(parse.getOffset(data, pos, offsetSize));\n pos += offsetSize;\n }\n\n // The total size of the index array is 4 header bytes + the value of the last offset.\n endOffset = objectOffset + offsets[count];\n } else {\n endOffset = start + 2;\n }\n\n for (var i$1 = 0; i$1 < offsets.length - 1; i$1 += 1) {\n var value = parse.getBytes(data, objectOffset + offsets[i$1], objectOffset + offsets[i$1 + 1]);\n if (conversionFn) {\n value = conversionFn(value);\n }\n\n objects.push(value);\n }\n\n return {objects: objects, startOffset: start, endOffset: endOffset};\n }\n\n function parseCFFIndexLowMemory(data, start) {\n var offsets = [];\n var count = parse.getCard16(data, start);\n var objectOffset;\n var endOffset;\n if (count !== 0) {\n var offsetSize = parse.getByte(data, start + 2);\n objectOffset = start + ((count + 1) * offsetSize) + 2;\n var pos = start + 3;\n for (var i = 0; i < count + 1; i += 1) {\n offsets.push(parse.getOffset(data, pos, offsetSize));\n pos += offsetSize;\n }\n\n // The total size of the index array is 4 header bytes + the value of the last offset.\n endOffset = objectOffset + offsets[count];\n } else {\n endOffset = start + 2;\n }\n\n return {offsets: offsets, startOffset: start, endOffset: endOffset};\n }\n function getCffIndexObject(i, offsets, data, start, conversionFn) {\n var count = parse.getCard16(data, start);\n var objectOffset = 0;\n if (count !== 0) {\n var offsetSize = parse.getByte(data, start + 2);\n objectOffset = start + ((count + 1) * offsetSize) + 2;\n }\n\n var value = parse.getBytes(data, objectOffset + offsets[i], objectOffset + offsets[i + 1]);\n if (conversionFn) {\n value = conversionFn(value);\n }\n return value;\n }\n\n // Parse a `CFF` DICT real value.\n function parseFloatOperand(parser) {\n var s = '';\n var eof = 15;\n var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'E', 'E-', null, '-'];\n while (true) {\n var b = parser.parseByte();\n var n1 = b >> 4;\n var n2 = b & 15;\n\n if (n1 === eof) {\n break;\n }\n\n s += lookup[n1];\n\n if (n2 === eof) {\n break;\n }\n\n s += lookup[n2];\n }\n\n return parseFloat(s);\n }\n\n // Parse a `CFF` DICT operand.\n function parseOperand(parser, b0) {\n var b1;\n var b2;\n var b3;\n var b4;\n if (b0 === 28) {\n b1 = parser.parseByte();\n b2 = parser.parseByte();\n return b1 << 8 | b2;\n }\n\n if (b0 === 29) {\n b1 = parser.parseByte();\n b2 = parser.parseByte();\n b3 = parser.parseByte();\n b4 = parser.parseByte();\n return b1 << 24 | b2 << 16 | b3 << 8 | b4;\n }\n\n if (b0 === 30) {\n return parseFloatOperand(parser);\n }\n\n if (b0 >= 32 && b0 <= 246) {\n return b0 - 139;\n }\n\n if (b0 >= 247 && b0 <= 250) {\n b1 = parser.parseByte();\n return (b0 - 247) * 256 + b1 + 108;\n }\n\n if (b0 >= 251 && b0 <= 254) {\n b1 = parser.parseByte();\n return -(b0 - 251) * 256 - b1 - 108;\n }\n\n throw new Error('Invalid b0 ' + b0);\n }\n\n // Convert the entries returned by `parseDict` to a proper dictionary.\n // If a value is a list of one, it is unpacked.\n function entriesToObject(entries) {\n var o = {};\n for (var i = 0; i < entries.length; i += 1) {\n var key = entries[i][0];\n var values = entries[i][1];\n var value = (void 0);\n if (values.length === 1) {\n value = values[0];\n } else {\n value = values;\n }\n\n if (o.hasOwnProperty(key) && !isNaN(o[key])) {\n throw new Error('Object ' + o + ' already has key ' + key);\n }\n\n o[key] = value;\n }\n\n return o;\n }\n\n // Parse a `CFF` DICT object.\n // A dictionary contains key-value pairs in a compact tokenized format.\n function parseCFFDict(data, start, size) {\n start = start !== undefined ? start : 0;\n var parser = new parse.Parser(data, start);\n var entries = [];\n var operands = [];\n size = size !== undefined ? size : data.length;\n\n while (parser.relativeOffset < size) {\n var op = parser.parseByte();\n\n // The first byte for each dict item distinguishes between operator (key) and operand (value).\n // Values <= 21 are operators.\n if (op <= 21) {\n // Two-byte operators have an initial escape byte of 12.\n if (op === 12) {\n op = 1200 + parser.parseByte();\n }\n\n entries.push([op, operands]);\n operands = [];\n } else {\n // Since the operands (values) come before the operators (keys), we store all operands in a list\n // until we encounter an operator.\n operands.push(parseOperand(parser, op));\n }\n }\n\n return entriesToObject(entries);\n }\n\n // Given a String Index (SID), return the value of the string.\n // Strings below index 392 are standard CFF strings and are not encoded in the font.\n function getCFFString(strings, index) {\n if (index <= 390) {\n index = cffStandardStrings[index];\n } else {\n index = strings[index - 391];\n }\n\n return index;\n }\n\n // Interpret a dictionary and return a new dictionary with readable keys and values for missing entries.\n // This function takes `meta` which is a list of objects containing `operand`, `name` and `default`.\n function interpretDict(dict, meta, strings) {\n var newDict = {};\n var value;\n\n // Because we also want to include missing values, we start out from the meta list\n // and lookup values in the dict.\n for (var i = 0; i < meta.length; i += 1) {\n var m = meta[i];\n\n if (Array.isArray(m.type)) {\n var values = [];\n values.length = m.type.length;\n for (var j = 0; j < m.type.length; j++) {\n value = dict[m.op] !== undefined ? dict[m.op][j] : undefined;\n if (value === undefined) {\n value = m.value !== undefined && m.value[j] !== undefined ? m.value[j] : null;\n }\n if (m.type[j] === 'SID') {\n value = getCFFString(strings, value);\n }\n values[j] = value;\n }\n newDict[m.name] = values;\n } else {\n value = dict[m.op];\n if (value === undefined) {\n value = m.value !== undefined ? m.value : null;\n }\n\n if (m.type === 'SID') {\n value = getCFFString(strings, value);\n }\n newDict[m.name] = value;\n }\n }\n\n return newDict;\n }\n\n // Parse the CFF header.\n function parseCFFHeader(data, start) {\n var header = {};\n header.formatMajor = parse.getCard8(data, start);\n header.formatMinor = parse.getCard8(data, start + 1);\n header.size = parse.getCard8(data, start + 2);\n header.offsetSize = parse.getCard8(data, start + 3);\n header.startOffset = start;\n header.endOffset = start + 4;\n return header;\n }\n\n var TOP_DICT_META = [\n {name: 'version', op: 0, type: 'SID'},\n {name: 'notice', op: 1, type: 'SID'},\n {name: 'copyright', op: 1200, type: 'SID'},\n {name: 'fullName', op: 2, type: 'SID'},\n {name: 'familyName', op: 3, type: 'SID'},\n {name: 'weight', op: 4, type: 'SID'},\n {name: 'isFixedPitch', op: 1201, type: 'number', value: 0},\n {name: 'italicAngle', op: 1202, type: 'number', value: 0},\n {name: 'underlinePosition', op: 1203, type: 'number', value: -100},\n {name: 'underlineThickness', op: 1204, type: 'number', value: 50},\n {name: 'paintType', op: 1205, type: 'number', value: 0},\n {name: 'charstringType', op: 1206, type: 'number', value: 2},\n {\n name: 'fontMatrix',\n op: 1207,\n type: ['real', 'real', 'real', 'real', 'real', 'real'],\n value: [0.001, 0, 0, 0.001, 0, 0]\n },\n {name: 'uniqueId', op: 13, type: 'number'},\n {name: 'fontBBox', op: 5, type: ['number', 'number', 'number', 'number'], value: [0, 0, 0, 0]},\n {name: 'strokeWidth', op: 1208, type: 'number', value: 0},\n {name: 'xuid', op: 14, type: [], value: null},\n {name: 'charset', op: 15, type: 'offset', value: 0},\n {name: 'encoding', op: 16, type: 'offset', value: 0},\n {name: 'charStrings', op: 17, type: 'offset', value: 0},\n {name: 'private', op: 18, type: ['number', 'offset'], value: [0, 0]},\n {name: 'ros', op: 1230, type: ['SID', 'SID', 'number']},\n {name: 'cidFontVersion', op: 1231, type: 'number', value: 0},\n {name: 'cidFontRevision', op: 1232, type: 'number', value: 0},\n {name: 'cidFontType', op: 1233, type: 'number', value: 0},\n {name: 'cidCount', op: 1234, type: 'number', value: 8720},\n {name: 'uidBase', op: 1235, type: 'number'},\n {name: 'fdArray', op: 1236, type: 'offset'},\n {name: 'fdSelect', op: 1237, type: 'offset'},\n {name: 'fontName', op: 1238, type: 'SID'}\n ];\n\n var PRIVATE_DICT_META = [\n {name: 'subrs', op: 19, type: 'offset', value: 0},\n {name: 'defaultWidthX', op: 20, type: 'number', value: 0},\n {name: 'nominalWidthX', op: 21, type: 'number', value: 0}\n ];\n\n // Parse the CFF top dictionary. A CFF table can contain multiple fonts, each with their own top dictionary.\n // The top dictionary contains the essential metadata for the font, together with the private dictionary.\n function parseCFFTopDict(data, strings) {\n var dict = parseCFFDict(data, 0, data.byteLength);\n return interpretDict(dict, TOP_DICT_META, strings);\n }\n\n // Parse the CFF private dictionary. We don't fully parse out all the values, only the ones we need.\n function parseCFFPrivateDict(data, start, size, strings) {\n var dict = parseCFFDict(data, start, size);\n return interpretDict(dict, PRIVATE_DICT_META, strings);\n }\n\n // Returns a list of \"Top DICT\"s found using an INDEX list.\n // Used to read both the usual high-level Top DICTs and also the FDArray\n // discovered inside CID-keyed fonts. When a Top DICT has a reference to\n // a Private DICT that is read and saved into the Top DICT.\n //\n // In addition to the expected/optional values as outlined in TOP_DICT_META\n // the following values might be saved into the Top DICT.\n //\n // _subrs [] array of local CFF subroutines from Private DICT\n // _subrsBias bias value computed from number of subroutines\n // (see calcCFFSubroutineBias() and parseCFFCharstring())\n // _defaultWidthX default widths for CFF characters\n // _nominalWidthX bias added to width embedded within glyph description\n //\n // _privateDict saved copy of parsed Private DICT from Top DICT\n function gatherCFFTopDicts(data, start, cffIndex, strings) {\n var topDictArray = [];\n for (var iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) {\n var topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer);\n var topDict = parseCFFTopDict(topDictData, strings);\n topDict._subrs = [];\n topDict._subrsBias = 0;\n topDict._defaultWidthX = 0;\n topDict._nominalWidthX = 0;\n var privateSize = topDict.private[0];\n var privateOffset = topDict.private[1];\n if (privateSize !== 0 && privateOffset !== 0) {\n var privateDict = parseCFFPrivateDict(data, privateOffset + start, privateSize, strings);\n topDict._defaultWidthX = privateDict.defaultWidthX;\n topDict._nominalWidthX = privateDict.nominalWidthX;\n if (privateDict.subrs !== 0) {\n var subrOffset = privateOffset + privateDict.subrs;\n var subrIndex = parseCFFIndex(data, subrOffset + start);\n topDict._subrs = subrIndex.objects;\n topDict._subrsBias = calcCFFSubroutineBias(topDict._subrs);\n }\n topDict._privateDict = privateDict;\n }\n topDictArray.push(topDict);\n }\n return topDictArray;\n }\n\n // Parse the CFF charset table, which contains internal names for all the glyphs.\n // This function will return a list of glyph names.\n // See Adobe TN #5176 chapter 13, \"Charsets\".\n function parseCFFCharset(data, start, nGlyphs, strings) {\n var sid;\n var count;\n var parser = new parse.Parser(data, start);\n\n // The .notdef glyph is not included, so subtract 1.\n nGlyphs -= 1;\n var charset = ['.notdef'];\n\n var format = parser.parseCard8();\n if (format === 0) {\n for (var i = 0; i < nGlyphs; i += 1) {\n sid = parser.parseSID();\n charset.push(getCFFString(strings, sid));\n }\n } else if (format === 1) {\n while (charset.length <= nGlyphs) {\n sid = parser.parseSID();\n count = parser.parseCard8();\n for (var i$1 = 0; i$1 <= count; i$1 += 1) {\n charset.push(getCFFString(strings, sid));\n sid += 1;\n }\n }\n } else if (format === 2) {\n while (charset.length <= nGlyphs) {\n sid = parser.parseSID();\n count = parser.parseCard16();\n for (var i$2 = 0; i$2 <= count; i$2 += 1) {\n charset.push(getCFFString(strings, sid));\n sid += 1;\n }\n }\n } else {\n throw new Error('Unknown charset format ' + format);\n }\n\n return charset;\n }\n\n // Parse the CFF encoding data. Only one encoding can be specified per font.\n // See Adobe TN #5176 chapter 12, \"Encodings\".\n function parseCFFEncoding(data, start, charset) {\n var code;\n var enc = {};\n var parser = new parse.Parser(data, start);\n var format = parser.parseCard8();\n if (format === 0) {\n var nCodes = parser.parseCard8();\n for (var i = 0; i < nCodes; i += 1) {\n code = parser.parseCard8();\n enc[code] = i;\n }\n } else if (format === 1) {\n var nRanges = parser.parseCard8();\n code = 1;\n for (var i$1 = 0; i$1 < nRanges; i$1 += 1) {\n var first = parser.parseCard8();\n var nLeft = parser.parseCard8();\n for (var j = first; j <= first + nLeft; j += 1) {\n enc[j] = code;\n code += 1;\n }\n }\n } else {\n throw new Error('Unknown encoding format ' + format);\n }\n\n return new CffEncoding(enc, charset);\n }\n\n // Take in charstring code and return a Glyph object.\n // The encoding is described in the Type 2 Charstring Format\n // https://www.microsoft.com/typography/OTSPEC/charstr2.htm\n function parseCFFCharstring(font, glyph, code) {\n var c1x;\n var c1y;\n var c2x;\n var c2y;\n var p = new Path();\n var stack = [];\n var nStems = 0;\n var haveWidth = false;\n var open = false;\n var x = 0;\n var y = 0;\n var subrs;\n var subrsBias;\n var defaultWidthX;\n var nominalWidthX;\n if (font.isCIDFont) {\n var fdIndex = font.tables.cff.topDict._fdSelect[glyph.index];\n var fdDict = font.tables.cff.topDict._fdArray[fdIndex];\n subrs = fdDict._subrs;\n subrsBias = fdDict._subrsBias;\n defaultWidthX = fdDict._defaultWidthX;\n nominalWidthX = fdDict._nominalWidthX;\n } else {\n subrs = font.tables.cff.topDict._subrs;\n subrsBias = font.tables.cff.topDict._subrsBias;\n defaultWidthX = font.tables.cff.topDict._defaultWidthX;\n nominalWidthX = font.tables.cff.topDict._nominalWidthX;\n }\n var width = defaultWidthX;\n\n function newContour(x, y) {\n if (open) {\n p.closePath();\n }\n\n p.moveTo(x, y);\n open = true;\n }\n\n function parseStems() {\n var hasWidthArg;\n\n // The number of stem operators on the stack is always even.\n // If the value is uneven, that means a width is specified.\n hasWidthArg = stack.length % 2 !== 0;\n if (hasWidthArg && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n }\n\n nStems += stack.length >> 1;\n stack.length = 0;\n haveWidth = true;\n }\n\n function parse(code) {\n var b1;\n var b2;\n var b3;\n var b4;\n var codeIndex;\n var subrCode;\n var jpx;\n var jpy;\n var c3x;\n var c3y;\n var c4x;\n var c4y;\n\n var i = 0;\n while (i < code.length) {\n var v = code[i];\n i += 1;\n switch (v) {\n case 1: // hstem\n parseStems();\n break;\n case 3: // vstem\n parseStems();\n break;\n case 4: // vmoveto\n if (stack.length > 1 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n y += stack.pop();\n newContour(x, y);\n break;\n case 5: // rlineto\n while (stack.length > 0) {\n x += stack.shift();\n y += stack.shift();\n p.lineTo(x, y);\n }\n\n break;\n case 6: // hlineto\n while (stack.length > 0) {\n x += stack.shift();\n p.lineTo(x, y);\n if (stack.length === 0) {\n break;\n }\n\n y += stack.shift();\n p.lineTo(x, y);\n }\n\n break;\n case 7: // vlineto\n while (stack.length > 0) {\n y += stack.shift();\n p.lineTo(x, y);\n if (stack.length === 0) {\n break;\n }\n\n x += stack.shift();\n p.lineTo(x, y);\n }\n\n break;\n case 8: // rrcurveto\n while (stack.length > 0) {\n c1x = x + stack.shift();\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 10: // callsubr\n codeIndex = stack.pop() + subrsBias;\n subrCode = subrs[codeIndex];\n if (subrCode) {\n parse(subrCode);\n }\n\n break;\n case 11: // return\n return;\n case 12: // flex operators\n v = code[i];\n i += 1;\n switch (v) {\n case 35: // flex\n // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |-\n c1x = x + stack.shift(); // dx1\n c1y = y + stack.shift(); // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y + stack.shift(); // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = jpy + stack.shift(); // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = c3y + stack.shift(); // dy5\n x = c4x + stack.shift(); // dx6\n y = c4y + stack.shift(); // dy6\n stack.shift(); // flex depth\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n case 34: // hflex\n // |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |-\n c1x = x + stack.shift(); // dx1\n c1y = y; // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y; // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = c2y; // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = y; // dy5\n x = c4x + stack.shift(); // dx6\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n case 36: // hflex1\n // |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |-\n c1x = x + stack.shift(); // dx1\n c1y = y + stack.shift(); // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y; // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = c2y; // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = c3y + stack.shift(); // dy5\n x = c4x + stack.shift(); // dx6\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n case 37: // flex1\n // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |-\n c1x = x + stack.shift(); // dx1\n c1y = y + stack.shift(); // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y + stack.shift(); // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = jpy + stack.shift(); // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = c3y + stack.shift(); // dy5\n if (Math.abs(c4x - x) > Math.abs(c4y - y)) {\n x = c4x + stack.shift();\n } else {\n y = c4y + stack.shift();\n }\n\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n default:\n console.log('Glyph ' + glyph.index + ': unknown operator ' + 1200 + v);\n stack.length = 0;\n }\n break;\n case 14: // endchar\n if (stack.length > 0 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n if (open) {\n p.closePath();\n open = false;\n }\n\n break;\n case 18: // hstemhm\n parseStems();\n break;\n case 19: // hintmask\n case 20: // cntrmask\n parseStems();\n i += (nStems + 7) >> 3;\n break;\n case 21: // rmoveto\n if (stack.length > 2 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n y += stack.pop();\n x += stack.pop();\n newContour(x, y);\n break;\n case 22: // hmoveto\n if (stack.length > 1 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n x += stack.pop();\n newContour(x, y);\n break;\n case 23: // vstemhm\n parseStems();\n break;\n case 24: // rcurveline\n while (stack.length > 2) {\n c1x = x + stack.shift();\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n x += stack.shift();\n y += stack.shift();\n p.lineTo(x, y);\n break;\n case 25: // rlinecurve\n while (stack.length > 6) {\n x += stack.shift();\n y += stack.shift();\n p.lineTo(x, y);\n }\n\n c1x = x + stack.shift();\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n break;\n case 26: // vvcurveto\n if (stack.length % 2) {\n x += stack.shift();\n }\n\n while (stack.length > 0) {\n c1x = x;\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x;\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 27: // hhcurveto\n if (stack.length % 2) {\n y += stack.shift();\n }\n\n while (stack.length > 0) {\n c1x = x + stack.shift();\n c1y = y;\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y;\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 28: // shortint\n b1 = code[i];\n b2 = code[i + 1];\n stack.push(((b1 << 24) | (b2 << 16)) >> 16);\n i += 2;\n break;\n case 29: // callgsubr\n codeIndex = stack.pop() + font.gsubrsBias;\n subrCode = font.gsubrs[codeIndex];\n if (subrCode) {\n parse(subrCode);\n }\n\n break;\n case 30: // vhcurveto\n while (stack.length > 0) {\n c1x = x;\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n if (stack.length === 0) {\n break;\n }\n\n c1x = x + stack.shift();\n c1y = y;\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n y = c2y + stack.shift();\n x = c2x + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 31: // hvcurveto\n while (stack.length > 0) {\n c1x = x + stack.shift();\n c1y = y;\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n y = c2y + stack.shift();\n x = c2x + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n if (stack.length === 0) {\n break;\n }\n\n c1x = x;\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n default:\n if (v < 32) {\n console.log('Glyph ' + glyph.index + ': unknown operator ' + v);\n } else if (v < 247) {\n stack.push(v - 139);\n } else if (v < 251) {\n b1 = code[i];\n i += 1;\n stack.push((v - 247) * 256 + b1 + 108);\n } else if (v < 255) {\n b1 = code[i];\n i += 1;\n stack.push(-(v - 251) * 256 - b1 - 108);\n } else {\n b1 = code[i];\n b2 = code[i + 1];\n b3 = code[i + 2];\n b4 = code[i + 3];\n i += 4;\n stack.push(((b1 << 24) | (b2 << 16) | (b3 << 8) | b4) / 65536);\n }\n }\n }\n }\n\n parse(code);\n\n glyph.advanceWidth = width;\n return p;\n }\n\n function parseCFFFDSelect(data, start, nGlyphs, fdArrayCount) {\n var fdSelect = [];\n var fdIndex;\n var parser = new parse.Parser(data, start);\n var format = parser.parseCard8();\n if (format === 0) {\n // Simple list of nGlyphs elements\n for (var iGid = 0; iGid < nGlyphs; iGid++) {\n fdIndex = parser.parseCard8();\n if (fdIndex >= fdArrayCount) {\n throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')');\n }\n fdSelect.push(fdIndex);\n }\n } else if (format === 3) {\n // Ranges\n var nRanges = parser.parseCard16();\n var first = parser.parseCard16();\n if (first !== 0) {\n throw new Error('CFF Table CID Font FDSelect format 3 range has bad initial GID ' + first);\n }\n var next;\n for (var iRange = 0; iRange < nRanges; iRange++) {\n fdIndex = parser.parseCard8();\n next = parser.parseCard16();\n if (fdIndex >= fdArrayCount) {\n throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')');\n }\n if (next > nGlyphs) {\n throw new Error('CFF Table CID Font FDSelect format 3 range has bad GID ' + next);\n }\n for (; first < next; first++) {\n fdSelect.push(fdIndex);\n }\n first = next;\n }\n if (next !== nGlyphs) {\n throw new Error('CFF Table CID Font FDSelect format 3 range has bad final GID ' + next);\n }\n } else {\n throw new Error('CFF Table CID Font FDSelect table has unsupported format ' + format);\n }\n return fdSelect;\n }\n\n // Parse the `CFF` table, which contains the glyph outlines in PostScript format.\n function parseCFFTable(data, start, font, opt) {\n font.tables.cff = {};\n var header = parseCFFHeader(data, start);\n var nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString);\n var topDictIndex = parseCFFIndex(data, nameIndex.endOffset);\n var stringIndex = parseCFFIndex(data, topDictIndex.endOffset, parse.bytesToString);\n var globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset);\n font.gsubrs = globalSubrIndex.objects;\n font.gsubrsBias = calcCFFSubroutineBias(font.gsubrs);\n\n var topDictArray = gatherCFFTopDicts(data, start, topDictIndex.objects, stringIndex.objects);\n if (topDictArray.length !== 1) {\n throw new Error('CFF table has too many fonts in \\'FontSet\\' - count of fonts NameIndex.length = ' + topDictArray.length);\n }\n\n var topDict = topDictArray[0];\n font.tables.cff.topDict = topDict;\n\n if (topDict._privateDict) {\n font.defaultWidthX = topDict._privateDict.defaultWidthX;\n font.nominalWidthX = topDict._privateDict.nominalWidthX;\n }\n\n if (topDict.ros[0] !== undefined && topDict.ros[1] !== undefined) {\n font.isCIDFont = true;\n }\n\n if (font.isCIDFont) {\n var fdArrayOffset = topDict.fdArray;\n var fdSelectOffset = topDict.fdSelect;\n if (fdArrayOffset === 0 || fdSelectOffset === 0) {\n throw new Error('Font is marked as a CID font, but FDArray and/or FDSelect information is missing');\n }\n fdArrayOffset += start;\n var fdArrayIndex = parseCFFIndex(data, fdArrayOffset);\n var fdArray = gatherCFFTopDicts(data, start, fdArrayIndex.objects, stringIndex.objects);\n topDict._fdArray = fdArray;\n fdSelectOffset += start;\n topDict._fdSelect = parseCFFFDSelect(data, fdSelectOffset, font.numGlyphs, fdArray.length);\n }\n\n var privateDictOffset = start + topDict.private[1];\n var privateDict = parseCFFPrivateDict(data, privateDictOffset, topDict.private[0], stringIndex.objects);\n font.defaultWidthX = privateDict.defaultWidthX;\n font.nominalWidthX = privateDict.nominalWidthX;\n\n if (privateDict.subrs !== 0) {\n var subrOffset = privateDictOffset + privateDict.subrs;\n var subrIndex = parseCFFIndex(data, subrOffset);\n font.subrs = subrIndex.objects;\n font.subrsBias = calcCFFSubroutineBias(font.subrs);\n } else {\n font.subrs = [];\n font.subrsBias = 0;\n }\n\n // Offsets in the top dict are relative to the beginning of the CFF data, so add the CFF start offset.\n var charStringsIndex;\n if (opt.lowMemory) {\n charStringsIndex = parseCFFIndexLowMemory(data, start + topDict.charStrings);\n font.nGlyphs = charStringsIndex.offsets.length;\n } else {\n charStringsIndex = parseCFFIndex(data, start + topDict.charStrings);\n font.nGlyphs = charStringsIndex.objects.length;\n }\n\n var charset = parseCFFCharset(data, start + topDict.charset, font.nGlyphs, stringIndex.objects);\n if (topDict.encoding === 0) {\n // Standard encoding\n font.cffEncoding = new CffEncoding(cffStandardEncoding, charset);\n } else if (topDict.encoding === 1) {\n // Expert encoding\n font.cffEncoding = new CffEncoding(cffExpertEncoding, charset);\n } else {\n font.cffEncoding = parseCFFEncoding(data, start + topDict.encoding, charset);\n }\n\n // Prefer the CMAP encoding to the CFF encoding.\n font.encoding = font.encoding || font.cffEncoding;\n\n font.glyphs = new glyphset.GlyphSet(font);\n if (opt.lowMemory) {\n font._push = function(i) {\n var charString = getCffIndexObject(i, charStringsIndex.offsets, data, start + topDict.charStrings);\n font.glyphs.push(i, glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString));\n };\n } else {\n for (var i = 0; i < font.nGlyphs; i += 1) {\n var charString = charStringsIndex.objects[i];\n font.glyphs.push(i, glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString));\n }\n }\n }\n\n // Convert a string to a String ID (SID).\n // The list of strings is modified in place.\n function encodeString(s, strings) {\n var sid;\n\n // Is the string in the CFF standard strings?\n var i = cffStandardStrings.indexOf(s);\n if (i >= 0) {\n sid = i;\n }\n\n // Is the string already in the string index?\n i = strings.indexOf(s);\n if (i >= 0) {\n sid = i + cffStandardStrings.length;\n } else {\n sid = cffStandardStrings.length + strings.length;\n strings.push(s);\n }\n\n return sid;\n }\n\n function makeHeader() {\n return new table.Record('Header', [\n {name: 'major', type: 'Card8', value: 1},\n {name: 'minor', type: 'Card8', value: 0},\n {name: 'hdrSize', type: 'Card8', value: 4},\n {name: 'major', type: 'Card8', value: 1}\n ]);\n }\n\n function makeNameIndex(fontNames) {\n var t = new table.Record('Name INDEX', [\n {name: 'names', type: 'INDEX', value: []}\n ]);\n t.names = [];\n for (var i = 0; i < fontNames.length; i += 1) {\n t.names.push({name: 'name_' + i, type: 'NAME', value: fontNames[i]});\n }\n\n return t;\n }\n\n // Given a dictionary's metadata, create a DICT structure.\n function makeDict(meta, attrs, strings) {\n var m = {};\n for (var i = 0; i < meta.length; i += 1) {\n var entry = meta[i];\n var value = attrs[entry.name];\n if (value !== undefined && !equals$1(value, entry.value)) {\n if (entry.type === 'SID') {\n value = encodeString(value, strings);\n }\n\n m[entry.op] = {name: entry.name, type: entry.type, value: value};\n }\n }\n\n return m;\n }\n\n // The Top DICT houses the global font attributes.\n function makeTopDict(attrs, strings) {\n var t = new table.Record('Top DICT', [\n {name: 'dict', type: 'DICT', value: {}}\n ]);\n t.dict = makeDict(TOP_DICT_META, attrs, strings);\n return t;\n }\n\n function makeTopDictIndex(topDict) {\n var t = new table.Record('Top DICT INDEX', [\n {name: 'topDicts', type: 'INDEX', value: []}\n ]);\n t.topDicts = [{name: 'topDict_0', type: 'TABLE', value: topDict}];\n return t;\n }\n\n function makeStringIndex(strings) {\n var t = new table.Record('String INDEX', [\n {name: 'strings', type: 'INDEX', value: []}\n ]);\n t.strings = [];\n for (var i = 0; i < strings.length; i += 1) {\n t.strings.push({name: 'string_' + i, type: 'STRING', value: strings[i]});\n }\n\n return t;\n }\n\n function makeGlobalSubrIndex() {\n // Currently we don't use subroutines.\n return new table.Record('Global Subr INDEX', [\n {name: 'subrs', type: 'INDEX', value: []}\n ]);\n }\n\n function makeCharsets(glyphNames, strings) {\n var t = new table.Record('Charsets', [\n {name: 'format', type: 'Card8', value: 0}\n ]);\n for (var i = 0; i < glyphNames.length; i += 1) {\n var glyphName = glyphNames[i];\n var glyphSID = encodeString(glyphName, strings);\n t.fields.push({name: 'glyph_' + i, type: 'SID', value: glyphSID});\n }\n\n return t;\n }\n\n function glyphToOps(glyph) {\n var ops = [];\n var path = glyph.path;\n ops.push({name: 'width', type: 'NUMBER', value: glyph.advanceWidth});\n var x = 0;\n var y = 0;\n for (var i = 0; i < path.commands.length; i += 1) {\n var dx = (void 0);\n var dy = (void 0);\n var cmd = path.commands[i];\n if (cmd.type === 'Q') {\n // CFF only supports bézier curves, so convert the quad to a bézier.\n var _13 = 1 / 3;\n var _23 = 2 / 3;\n\n // We're going to create a new command so we don't change the original path.\n // Since all coordinates are relative, we round() them ASAP to avoid propagating errors.\n cmd = {\n type: 'C',\n x: cmd.x,\n y: cmd.y,\n x1: Math.round(_13 * x + _23 * cmd.x1),\n y1: Math.round(_13 * y + _23 * cmd.y1),\n x2: Math.round(_13 * cmd.x + _23 * cmd.x1),\n y2: Math.round(_13 * cmd.y + _23 * cmd.y1)\n };\n }\n\n if (cmd.type === 'M') {\n dx = Math.round(cmd.x - x);\n dy = Math.round(cmd.y - y);\n ops.push({name: 'dx', type: 'NUMBER', value: dx});\n ops.push({name: 'dy', type: 'NUMBER', value: dy});\n ops.push({name: 'rmoveto', type: 'OP', value: 21});\n x = Math.round(cmd.x);\n y = Math.round(cmd.y);\n } else if (cmd.type === 'L') {\n dx = Math.round(cmd.x - x);\n dy = Math.round(cmd.y - y);\n ops.push({name: 'dx', type: 'NUMBER', value: dx});\n ops.push({name: 'dy', type: 'NUMBER', value: dy});\n ops.push({name: 'rlineto', type: 'OP', value: 5});\n x = Math.round(cmd.x);\n y = Math.round(cmd.y);\n } else if (cmd.type === 'C') {\n var dx1 = Math.round(cmd.x1 - x);\n var dy1 = Math.round(cmd.y1 - y);\n var dx2 = Math.round(cmd.x2 - cmd.x1);\n var dy2 = Math.round(cmd.y2 - cmd.y1);\n dx = Math.round(cmd.x - cmd.x2);\n dy = Math.round(cmd.y - cmd.y2);\n ops.push({name: 'dx1', type: 'NUMBER', value: dx1});\n ops.push({name: 'dy1', type: 'NUMBER', value: dy1});\n ops.push({name: 'dx2', type: 'NUMBER', value: dx2});\n ops.push({name: 'dy2', type: 'NUMBER', value: dy2});\n ops.push({name: 'dx', type: 'NUMBER', value: dx});\n ops.push({name: 'dy', type: 'NUMBER', value: dy});\n ops.push({name: 'rrcurveto', type: 'OP', value: 8});\n x = Math.round(cmd.x);\n y = Math.round(cmd.y);\n }\n\n // Contours are closed automatically.\n }\n\n ops.push({name: 'endchar', type: 'OP', value: 14});\n return ops;\n }\n\n function makeCharStringsIndex(glyphs) {\n var t = new table.Record('CharStrings INDEX', [\n {name: 'charStrings', type: 'INDEX', value: []}\n ]);\n\n for (var i = 0; i < glyphs.length; i += 1) {\n var glyph = glyphs.get(i);\n var ops = glyphToOps(glyph);\n t.charStrings.push({name: glyph.name, type: 'CHARSTRING', value: ops});\n }\n\n return t;\n }\n\n function makePrivateDict(attrs, strings) {\n var t = new table.Record('Private DICT', [\n {name: 'dict', type: 'DICT', value: {}}\n ]);\n t.dict = makeDict(PRIVATE_DICT_META, attrs, strings);\n return t;\n }\n\n function makeCFFTable(glyphs, options) {\n var t = new table.Table('CFF ', [\n {name: 'header', type: 'RECORD'},\n {name: 'nameIndex', type: 'RECORD'},\n {name: 'topDictIndex', type: 'RECORD'},\n {name: 'stringIndex', type: 'RECORD'},\n {name: 'globalSubrIndex', type: 'RECORD'},\n {name: 'charsets', type: 'RECORD'},\n {name: 'charStringsIndex', type: 'RECORD'},\n {name: 'privateDict', type: 'RECORD'}\n ]);\n\n var fontScale = 1 / options.unitsPerEm;\n // We use non-zero values for the offsets so that the DICT encodes them.\n // This is important because the size of the Top DICT plays a role in offset calculation,\n // and the size shouldn't change after we've written correct offsets.\n var attrs = {\n version: options.version,\n fullName: options.fullName,\n familyName: options.familyName,\n weight: options.weightName,\n fontBBox: options.fontBBox || [0, 0, 0, 0],\n fontMatrix: [fontScale, 0, 0, fontScale, 0, 0],\n charset: 999,\n encoding: 0,\n charStrings: 999,\n private: [0, 999]\n };\n\n var privateAttrs = {};\n\n var glyphNames = [];\n var glyph;\n\n // Skip first glyph (.notdef)\n for (var i = 1; i < glyphs.length; i += 1) {\n glyph = glyphs.get(i);\n glyphNames.push(glyph.name);\n }\n\n var strings = [];\n\n t.header = makeHeader();\n t.nameIndex = makeNameIndex([options.postScriptName]);\n var topDict = makeTopDict(attrs, strings);\n t.topDictIndex = makeTopDictIndex(topDict);\n t.globalSubrIndex = makeGlobalSubrIndex();\n t.charsets = makeCharsets(glyphNames, strings);\n t.charStringsIndex = makeCharStringsIndex(glyphs);\n t.privateDict = makePrivateDict(privateAttrs, strings);\n\n // Needs to come at the end, to encode all custom strings used in the font.\n t.stringIndex = makeStringIndex(strings);\n\n var startOffset = t.header.sizeOf() +\n t.nameIndex.sizeOf() +\n t.topDictIndex.sizeOf() +\n t.stringIndex.sizeOf() +\n t.globalSubrIndex.sizeOf();\n attrs.charset = startOffset;\n\n // We use the CFF standard encoding; proper encoding will be handled in cmap.\n attrs.encoding = 0;\n attrs.charStrings = attrs.charset + t.charsets.sizeOf();\n attrs.private[1] = attrs.charStrings + t.charStringsIndex.sizeOf();\n\n // Recreate the Top DICT INDEX with the correct offsets.\n topDict = makeTopDict(attrs, strings);\n t.topDictIndex = makeTopDictIndex(topDict);\n\n return t;\n }\n\n var cff = { parse: parseCFFTable, make: makeCFFTable };\n\n // The `head` table contains global information about the font.\n\n // Parse the header `head` table\n function parseHeadTable(data, start) {\n var head = {};\n var p = new parse.Parser(data, start);\n head.version = p.parseVersion();\n head.fontRevision = Math.round(p.parseFixed() * 1000) / 1000;\n head.checkSumAdjustment = p.parseULong();\n head.magicNumber = p.parseULong();\n check.argument(head.magicNumber === 0x5F0F3CF5, 'Font header has wrong magic number.');\n head.flags = p.parseUShort();\n head.unitsPerEm = p.parseUShort();\n head.created = p.parseLongDateTime();\n head.modified = p.parseLongDateTime();\n head.xMin = p.parseShort();\n head.yMin = p.parseShort();\n head.xMax = p.parseShort();\n head.yMax = p.parseShort();\n head.macStyle = p.parseUShort();\n head.lowestRecPPEM = p.parseUShort();\n head.fontDirectionHint = p.parseShort();\n head.indexToLocFormat = p.parseShort();\n head.glyphDataFormat = p.parseShort();\n return head;\n }\n\n function makeHeadTable(options) {\n // Apple Mac timestamp epoch is 01/01/1904 not 01/01/1970\n var timestamp = Math.round(new Date().getTime() / 1000) + 2082844800;\n var createdTimestamp = timestamp;\n\n if (options.createdTimestamp) {\n createdTimestamp = options.createdTimestamp + 2082844800;\n }\n\n return new table.Table('head', [\n {name: 'version', type: 'FIXED', value: 0x00010000},\n {name: 'fontRevision', type: 'FIXED', value: 0x00010000},\n {name: 'checkSumAdjustment', type: 'ULONG', value: 0},\n {name: 'magicNumber', type: 'ULONG', value: 0x5F0F3CF5},\n {name: 'flags', type: 'USHORT', value: 0},\n {name: 'unitsPerEm', type: 'USHORT', value: 1000},\n {name: 'created', type: 'LONGDATETIME', value: createdTimestamp},\n {name: 'modified', type: 'LONGDATETIME', value: timestamp},\n {name: 'xMin', type: 'SHORT', value: 0},\n {name: 'yMin', type: 'SHORT', value: 0},\n {name: 'xMax', type: 'SHORT', value: 0},\n {name: 'yMax', type: 'SHORT', value: 0},\n {name: 'macStyle', type: 'USHORT', value: 0},\n {name: 'lowestRecPPEM', type: 'USHORT', value: 0},\n {name: 'fontDirectionHint', type: 'SHORT', value: 2},\n {name: 'indexToLocFormat', type: 'SHORT', value: 0},\n {name: 'glyphDataFormat', type: 'SHORT', value: 0}\n ], options);\n }\n\n var head = { parse: parseHeadTable, make: makeHeadTable };\n\n // The `hhea` table contains information for horizontal layout.\n\n // Parse the horizontal header `hhea` table\n function parseHheaTable(data, start) {\n var hhea = {};\n var p = new parse.Parser(data, start);\n hhea.version = p.parseVersion();\n hhea.ascender = p.parseShort();\n hhea.descender = p.parseShort();\n hhea.lineGap = p.parseShort();\n hhea.advanceWidthMax = p.parseUShort();\n hhea.minLeftSideBearing = p.parseShort();\n hhea.minRightSideBearing = p.parseShort();\n hhea.xMaxExtent = p.parseShort();\n hhea.caretSlopeRise = p.parseShort();\n hhea.caretSlopeRun = p.parseShort();\n hhea.caretOffset = p.parseShort();\n p.relativeOffset += 8;\n hhea.metricDataFormat = p.parseShort();\n hhea.numberOfHMetrics = p.parseUShort();\n return hhea;\n }\n\n function makeHheaTable(options) {\n return new table.Table('hhea', [\n {name: 'version', type: 'FIXED', value: 0x00010000},\n {name: 'ascender', type: 'FWORD', value: 0},\n {name: 'descender', type: 'FWORD', value: 0},\n {name: 'lineGap', type: 'FWORD', value: 0},\n {name: 'advanceWidthMax', type: 'UFWORD', value: 0},\n {name: 'minLeftSideBearing', type: 'FWORD', value: 0},\n {name: 'minRightSideBearing', type: 'FWORD', value: 0},\n {name: 'xMaxExtent', type: 'FWORD', value: 0},\n {name: 'caretSlopeRise', type: 'SHORT', value: 1},\n {name: 'caretSlopeRun', type: 'SHORT', value: 0},\n {name: 'caretOffset', type: 'SHORT', value: 0},\n {name: 'reserved1', type: 'SHORT', value: 0},\n {name: 'reserved2', type: 'SHORT', value: 0},\n {name: 'reserved3', type: 'SHORT', value: 0},\n {name: 'reserved4', type: 'SHORT', value: 0},\n {name: 'metricDataFormat', type: 'SHORT', value: 0},\n {name: 'numberOfHMetrics', type: 'USHORT', value: 0}\n ], options);\n }\n\n var hhea = { parse: parseHheaTable, make: makeHheaTable };\n\n // The `hmtx` table contains the horizontal metrics for all glyphs.\n\n function parseHmtxTableAll(data, start, numMetrics, numGlyphs, glyphs) {\n var advanceWidth;\n var leftSideBearing;\n var p = new parse.Parser(data, start);\n for (var i = 0; i < numGlyphs; i += 1) {\n // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.\n if (i < numMetrics) {\n advanceWidth = p.parseUShort();\n leftSideBearing = p.parseShort();\n }\n\n var glyph = glyphs.get(i);\n glyph.advanceWidth = advanceWidth;\n glyph.leftSideBearing = leftSideBearing;\n }\n }\n\n function parseHmtxTableOnLowMemory(font, data, start, numMetrics, numGlyphs) {\n font._hmtxTableData = {};\n\n var advanceWidth;\n var leftSideBearing;\n var p = new parse.Parser(data, start);\n for (var i = 0; i < numGlyphs; i += 1) {\n // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.\n if (i < numMetrics) {\n advanceWidth = p.parseUShort();\n leftSideBearing = p.parseShort();\n }\n\n font._hmtxTableData[i] = {\n advanceWidth: advanceWidth,\n leftSideBearing: leftSideBearing\n };\n }\n }\n\n // Parse the `hmtx` table, which contains the horizontal metrics for all glyphs.\n // This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph.\n function parseHmtxTable(font, data, start, numMetrics, numGlyphs, glyphs, opt) {\n if (opt.lowMemory)\n { parseHmtxTableOnLowMemory(font, data, start, numMetrics, numGlyphs); }\n else\n { parseHmtxTableAll(data, start, numMetrics, numGlyphs, glyphs); }\n }\n\n function makeHmtxTable(glyphs) {\n var t = new table.Table('hmtx', []);\n for (var i = 0; i < glyphs.length; i += 1) {\n var glyph = glyphs.get(i);\n var advanceWidth = glyph.advanceWidth || 0;\n var leftSideBearing = glyph.leftSideBearing || 0;\n t.fields.push({name: 'advanceWidth_' + i, type: 'USHORT', value: advanceWidth});\n t.fields.push({name: 'leftSideBearing_' + i, type: 'SHORT', value: leftSideBearing});\n }\n\n return t;\n }\n\n var hmtx = { parse: parseHmtxTable, make: makeHmtxTable };\n\n // The `ltag` table stores IETF BCP-47 language tags. It allows supporting\n\n function makeLtagTable(tags) {\n var result = new table.Table('ltag', [\n {name: 'version', type: 'ULONG', value: 1},\n {name: 'flags', type: 'ULONG', value: 0},\n {name: 'numTags', type: 'ULONG', value: tags.length}\n ]);\n\n var stringPool = '';\n var stringPoolOffset = 12 + tags.length * 4;\n for (var i = 0; i < tags.length; ++i) {\n var pos = stringPool.indexOf(tags[i]);\n if (pos < 0) {\n pos = stringPool.length;\n stringPool += tags[i];\n }\n\n result.fields.push({name: 'offset ' + i, type: 'USHORT', value: stringPoolOffset + pos});\n result.fields.push({name: 'length ' + i, type: 'USHORT', value: tags[i].length});\n }\n\n result.fields.push({name: 'stringPool', type: 'CHARARRAY', value: stringPool});\n return result;\n }\n\n function parseLtagTable(data, start) {\n var p = new parse.Parser(data, start);\n var tableVersion = p.parseULong();\n check.argument(tableVersion === 1, 'Unsupported ltag table version.');\n // The 'ltag' specification does not define any flags; skip the field.\n p.skip('uLong', 1);\n var numTags = p.parseULong();\n\n var tags = [];\n for (var i = 0; i < numTags; i++) {\n var tag = '';\n var offset = start + p.parseUShort();\n var length = p.parseUShort();\n for (var j = offset; j < offset + length; ++j) {\n tag += String.fromCharCode(data.getInt8(j));\n }\n\n tags.push(tag);\n }\n\n return tags;\n }\n\n var ltag = { make: makeLtagTable, parse: parseLtagTable };\n\n // The `maxp` table establishes the memory requirements for the font.\n\n // Parse the maximum profile `maxp` table.\n function parseMaxpTable(data, start) {\n var maxp = {};\n var p = new parse.Parser(data, start);\n maxp.version = p.parseVersion();\n maxp.numGlyphs = p.parseUShort();\n if (maxp.version === 1.0) {\n maxp.maxPoints = p.parseUShort();\n maxp.maxContours = p.parseUShort();\n maxp.maxCompositePoints = p.parseUShort();\n maxp.maxCompositeContours = p.parseUShort();\n maxp.maxZones = p.parseUShort();\n maxp.maxTwilightPoints = p.parseUShort();\n maxp.maxStorage = p.parseUShort();\n maxp.maxFunctionDefs = p.parseUShort();\n maxp.maxInstructionDefs = p.parseUShort();\n maxp.maxStackElements = p.parseUShort();\n maxp.maxSizeOfInstructions = p.parseUShort();\n maxp.maxComponentElements = p.parseUShort();\n maxp.maxComponentDepth = p.parseUShort();\n }\n\n return maxp;\n }\n\n function makeMaxpTable(numGlyphs) {\n return new table.Table('maxp', [\n {name: 'version', type: 'FIXED', value: 0x00005000},\n {name: 'numGlyphs', type: 'USHORT', value: numGlyphs}\n ]);\n }\n\n var maxp = { parse: parseMaxpTable, make: makeMaxpTable };\n\n // The `name` naming table.\n\n // NameIDs for the name table.\n var nameTableNames = [\n 'copyright', // 0\n 'fontFamily', // 1\n 'fontSubfamily', // 2\n 'uniqueID', // 3\n 'fullName', // 4\n 'version', // 5\n 'postScriptName', // 6\n 'trademark', // 7\n 'manufacturer', // 8\n 'designer', // 9\n 'description', // 10\n 'manufacturerURL', // 11\n 'designerURL', // 12\n 'license', // 13\n 'licenseURL', // 14\n 'reserved', // 15\n 'preferredFamily', // 16\n 'preferredSubfamily', // 17\n 'compatibleFullName', // 18\n 'sampleText', // 19\n 'postScriptFindFontName', // 20\n 'wwsFamily', // 21\n 'wwsSubfamily' // 22\n ];\n\n var macLanguages = {\n 0: 'en',\n 1: 'fr',\n 2: 'de',\n 3: 'it',\n 4: 'nl',\n 5: 'sv',\n 6: 'es',\n 7: 'da',\n 8: 'pt',\n 9: 'no',\n 10: 'he',\n 11: 'ja',\n 12: 'ar',\n 13: 'fi',\n 14: 'el',\n 15: 'is',\n 16: 'mt',\n 17: 'tr',\n 18: 'hr',\n 19: 'zh-Hant',\n 20: 'ur',\n 21: 'hi',\n 22: 'th',\n 23: 'ko',\n 24: 'lt',\n 25: 'pl',\n 26: 'hu',\n 27: 'es',\n 28: 'lv',\n 29: 'se',\n 30: 'fo',\n 31: 'fa',\n 32: 'ru',\n 33: 'zh',\n 34: 'nl-BE',\n 35: 'ga',\n 36: 'sq',\n 37: 'ro',\n 38: 'cz',\n 39: 'sk',\n 40: 'si',\n 41: 'yi',\n 42: 'sr',\n 43: 'mk',\n 44: 'bg',\n 45: 'uk',\n 46: 'be',\n 47: 'uz',\n 48: 'kk',\n 49: 'az-Cyrl',\n 50: 'az-Arab',\n 51: 'hy',\n 52: 'ka',\n 53: 'mo',\n 54: 'ky',\n 55: 'tg',\n 56: 'tk',\n 57: 'mn-CN',\n 58: 'mn',\n 59: 'ps',\n 60: 'ks',\n 61: 'ku',\n 62: 'sd',\n 63: 'bo',\n 64: 'ne',\n 65: 'sa',\n 66: 'mr',\n 67: 'bn',\n 68: 'as',\n 69: 'gu',\n 70: 'pa',\n 71: 'or',\n 72: 'ml',\n 73: 'kn',\n 74: 'ta',\n 75: 'te',\n 76: 'si',\n 77: 'my',\n 78: 'km',\n 79: 'lo',\n 80: 'vi',\n 81: 'id',\n 82: 'tl',\n 83: 'ms',\n 84: 'ms-Arab',\n 85: 'am',\n 86: 'ti',\n 87: 'om',\n 88: 'so',\n 89: 'sw',\n 90: 'rw',\n 91: 'rn',\n 92: 'ny',\n 93: 'mg',\n 94: 'eo',\n 128: 'cy',\n 129: 'eu',\n 130: 'ca',\n 131: 'la',\n 132: 'qu',\n 133: 'gn',\n 134: 'ay',\n 135: 'tt',\n 136: 'ug',\n 137: 'dz',\n 138: 'jv',\n 139: 'su',\n 140: 'gl',\n 141: 'af',\n 142: 'br',\n 143: 'iu',\n 144: 'gd',\n 145: 'gv',\n 146: 'ga',\n 147: 'to',\n 148: 'el-polyton',\n 149: 'kl',\n 150: 'az',\n 151: 'nn'\n };\n\n // MacOS language ID → MacOS script ID\n //\n // Note that the script ID is not sufficient to determine what encoding\n // to use in TrueType files. For some languages, MacOS used a modification\n // of a mainstream script. For example, an Icelandic name would be stored\n // with smRoman in the TrueType naming table, but the actual encoding\n // is a special Icelandic version of the normal Macintosh Roman encoding.\n // As another example, Inuktitut uses an 8-bit encoding for Canadian Aboriginal\n // Syllables but MacOS had run out of available script codes, so this was\n // done as a (pretty radical) \"modification\" of Ethiopic.\n //\n // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt\n var macLanguageToScript = {\n 0: 0, // langEnglish → smRoman\n 1: 0, // langFrench → smRoman\n 2: 0, // langGerman → smRoman\n 3: 0, // langItalian → smRoman\n 4: 0, // langDutch → smRoman\n 5: 0, // langSwedish → smRoman\n 6: 0, // langSpanish → smRoman\n 7: 0, // langDanish → smRoman\n 8: 0, // langPortuguese → smRoman\n 9: 0, // langNorwegian → smRoman\n 10: 5, // langHebrew → smHebrew\n 11: 1, // langJapanese → smJapanese\n 12: 4, // langArabic → smArabic\n 13: 0, // langFinnish → smRoman\n 14: 6, // langGreek → smGreek\n 15: 0, // langIcelandic → smRoman (modified)\n 16: 0, // langMaltese → smRoman\n 17: 0, // langTurkish → smRoman (modified)\n 18: 0, // langCroatian → smRoman (modified)\n 19: 2, // langTradChinese → smTradChinese\n 20: 4, // langUrdu → smArabic\n 21: 9, // langHindi → smDevanagari\n 22: 21, // langThai → smThai\n 23: 3, // langKorean → smKorean\n 24: 29, // langLithuanian → smCentralEuroRoman\n 25: 29, // langPolish → smCentralEuroRoman\n 26: 29, // langHungarian → smCentralEuroRoman\n 27: 29, // langEstonian → smCentralEuroRoman\n 28: 29, // langLatvian → smCentralEuroRoman\n 29: 0, // langSami → smRoman\n 30: 0, // langFaroese → smRoman (modified)\n 31: 4, // langFarsi → smArabic (modified)\n 32: 7, // langRussian → smCyrillic\n 33: 25, // langSimpChinese → smSimpChinese\n 34: 0, // langFlemish → smRoman\n 35: 0, // langIrishGaelic → smRoman (modified)\n 36: 0, // langAlbanian → smRoman\n 37: 0, // langRomanian → smRoman (modified)\n 38: 29, // langCzech → smCentralEuroRoman\n 39: 29, // langSlovak → smCentralEuroRoman\n 40: 0, // langSlovenian → smRoman (modified)\n 41: 5, // langYiddish → smHebrew\n 42: 7, // langSerbian → smCyrillic\n 43: 7, // langMacedonian → smCyrillic\n 44: 7, // langBulgarian → smCyrillic\n 45: 7, // langUkrainian → smCyrillic (modified)\n 46: 7, // langByelorussian → smCyrillic\n 47: 7, // langUzbek → smCyrillic\n 48: 7, // langKazakh → smCyrillic\n 49: 7, // langAzerbaijani → smCyrillic\n 50: 4, // langAzerbaijanAr → smArabic\n 51: 24, // langArmenian → smArmenian\n 52: 23, // langGeorgian → smGeorgian\n 53: 7, // langMoldavian → smCyrillic\n 54: 7, // langKirghiz → smCyrillic\n 55: 7, // langTajiki → smCyrillic\n 56: 7, // langTurkmen → smCyrillic\n 57: 27, // langMongolian → smMongolian\n 58: 7, // langMongolianCyr → smCyrillic\n 59: 4, // langPashto → smArabic\n 60: 4, // langKurdish → smArabic\n 61: 4, // langKashmiri → smArabic\n 62: 4, // langSindhi → smArabic\n 63: 26, // langTibetan → smTibetan\n 64: 9, // langNepali → smDevanagari\n 65: 9, // langSanskrit → smDevanagari\n 66: 9, // langMarathi → smDevanagari\n 67: 13, // langBengali → smBengali\n 68: 13, // langAssamese → smBengali\n 69: 11, // langGujarati → smGujarati\n 70: 10, // langPunjabi → smGurmukhi\n 71: 12, // langOriya → smOriya\n 72: 17, // langMalayalam → smMalayalam\n 73: 16, // langKannada → smKannada\n 74: 14, // langTamil → smTamil\n 75: 15, // langTelugu → smTelugu\n 76: 18, // langSinhalese → smSinhalese\n 77: 19, // langBurmese → smBurmese\n 78: 20, // langKhmer → smKhmer\n 79: 22, // langLao → smLao\n 80: 30, // langVietnamese → smVietnamese\n 81: 0, // langIndonesian → smRoman\n 82: 0, // langTagalog → smRoman\n 83: 0, // langMalayRoman → smRoman\n 84: 4, // langMalayArabic → smArabic\n 85: 28, // langAmharic → smEthiopic\n 86: 28, // langTigrinya → smEthiopic\n 87: 28, // langOromo → smEthiopic\n 88: 0, // langSomali → smRoman\n 89: 0, // langSwahili → smRoman\n 90: 0, // langKinyarwanda → smRoman\n 91: 0, // langRundi → smRoman\n 92: 0, // langNyanja → smRoman\n 93: 0, // langMalagasy → smRoman\n 94: 0, // langEsperanto → smRoman\n 128: 0, // langWelsh → smRoman (modified)\n 129: 0, // langBasque → smRoman\n 130: 0, // langCatalan → smRoman\n 131: 0, // langLatin → smRoman\n 132: 0, // langQuechua → smRoman\n 133: 0, // langGuarani → smRoman\n 134: 0, // langAymara → smRoman\n 135: 7, // langTatar → smCyrillic\n 136: 4, // langUighur → smArabic\n 137: 26, // langDzongkha → smTibetan\n 138: 0, // langJavaneseRom → smRoman\n 139: 0, // langSundaneseRom → smRoman\n 140: 0, // langGalician → smRoman\n 141: 0, // langAfrikaans → smRoman\n 142: 0, // langBreton → smRoman (modified)\n 143: 28, // langInuktitut → smEthiopic (modified)\n 144: 0, // langScottishGaelic → smRoman (modified)\n 145: 0, // langManxGaelic → smRoman (modified)\n 146: 0, // langIrishGaelicScript → smRoman (modified)\n 147: 0, // langTongan → smRoman\n 148: 6, // langGreekAncient → smRoman\n 149: 0, // langGreenlandic → smRoman\n 150: 0, // langAzerbaijanRoman → smRoman\n 151: 0 // langNynorsk → smRoman\n };\n\n // While Microsoft indicates a region/country for all its language\n // IDs, we omit the region code if it's equal to the \"most likely\n // region subtag\" according to Unicode CLDR. For scripts, we omit\n // the subtag if it is equal to the Suppress-Script entry in the\n // IANA language subtag registry for IETF BCP 47.\n //\n // For example, Microsoft states that its language code 0x041A is\n // Croatian in Croatia. We transform this to the BCP 47 language code 'hr'\n // and not 'hr-HR' because Croatia is the default country for Croatian,\n // according to Unicode CLDR. As another example, Microsoft states\n // that 0x101A is Croatian (Latin) in Bosnia-Herzegovina. We transform\n // this to 'hr-BA' and not 'hr-Latn-BA' because Latin is the default script\n // for the Croatian language, according to IANA.\n //\n // http://www.unicode.org/cldr/charts/latest/supplemental/likely_subtags.html\n // http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry\n var windowsLanguages = {\n 0x0436: 'af',\n 0x041C: 'sq',\n 0x0484: 'gsw',\n 0x045E: 'am',\n 0x1401: 'ar-DZ',\n 0x3C01: 'ar-BH',\n 0x0C01: 'ar',\n 0x0801: 'ar-IQ',\n 0x2C01: 'ar-JO',\n 0x3401: 'ar-KW',\n 0x3001: 'ar-LB',\n 0x1001: 'ar-LY',\n 0x1801: 'ary',\n 0x2001: 'ar-OM',\n 0x4001: 'ar-QA',\n 0x0401: 'ar-SA',\n 0x2801: 'ar-SY',\n 0x1C01: 'aeb',\n 0x3801: 'ar-AE',\n 0x2401: 'ar-YE',\n 0x042B: 'hy',\n 0x044D: 'as',\n 0x082C: 'az-Cyrl',\n 0x042C: 'az',\n 0x046D: 'ba',\n 0x042D: 'eu',\n 0x0423: 'be',\n 0x0845: 'bn',\n 0x0445: 'bn-IN',\n 0x201A: 'bs-Cyrl',\n 0x141A: 'bs',\n 0x047E: 'br',\n 0x0402: 'bg',\n 0x0403: 'ca',\n 0x0C04: 'zh-HK',\n 0x1404: 'zh-MO',\n 0x0804: 'zh',\n 0x1004: 'zh-SG',\n 0x0404: 'zh-TW',\n 0x0483: 'co',\n 0x041A: 'hr',\n 0x101A: 'hr-BA',\n 0x0405: 'cs',\n 0x0406: 'da',\n 0x048C: 'prs',\n 0x0465: 'dv',\n 0x0813: 'nl-BE',\n 0x0413: 'nl',\n 0x0C09: 'en-AU',\n 0x2809: 'en-BZ',\n 0x1009: 'en-CA',\n 0x2409: 'en-029',\n 0x4009: 'en-IN',\n 0x1809: 'en-IE',\n 0x2009: 'en-JM',\n 0x4409: 'en-MY',\n 0x1409: 'en-NZ',\n 0x3409: 'en-PH',\n 0x4809: 'en-SG',\n 0x1C09: 'en-ZA',\n 0x2C09: 'en-TT',\n 0x0809: 'en-GB',\n 0x0409: 'en',\n 0x3009: 'en-ZW',\n 0x0425: 'et',\n 0x0438: 'fo',\n 0x0464: 'fil',\n 0x040B: 'fi',\n 0x080C: 'fr-BE',\n 0x0C0C: 'fr-CA',\n 0x040C: 'fr',\n 0x140C: 'fr-LU',\n 0x180C: 'fr-MC',\n 0x100C: 'fr-CH',\n 0x0462: 'fy',\n 0x0456: 'gl',\n 0x0437: 'ka',\n 0x0C07: 'de-AT',\n 0x0407: 'de',\n 0x1407: 'de-LI',\n 0x1007: 'de-LU',\n 0x0807: 'de-CH',\n 0x0408: 'el',\n 0x046F: 'kl',\n 0x0447: 'gu',\n 0x0468: 'ha',\n 0x040D: 'he',\n 0x0439: 'hi',\n 0x040E: 'hu',\n 0x040F: 'is',\n 0x0470: 'ig',\n 0x0421: 'id',\n 0x045D: 'iu',\n 0x085D: 'iu-Latn',\n 0x083C: 'ga',\n 0x0434: 'xh',\n 0x0435: 'zu',\n 0x0410: 'it',\n 0x0810: 'it-CH',\n 0x0411: 'ja',\n 0x044B: 'kn',\n 0x043F: 'kk',\n 0x0453: 'km',\n 0x0486: 'quc',\n 0x0487: 'rw',\n 0x0441: 'sw',\n 0x0457: 'kok',\n 0x0412: 'ko',\n 0x0440: 'ky',\n 0x0454: 'lo',\n 0x0426: 'lv',\n 0x0427: 'lt',\n 0x082E: 'dsb',\n 0x046E: 'lb',\n 0x042F: 'mk',\n 0x083E: 'ms-BN',\n 0x043E: 'ms',\n 0x044C: 'ml',\n 0x043A: 'mt',\n 0x0481: 'mi',\n 0x047A: 'arn',\n 0x044E: 'mr',\n 0x047C: 'moh',\n 0x0450: 'mn',\n 0x0850: 'mn-CN',\n 0x0461: 'ne',\n 0x0414: 'nb',\n 0x0814: 'nn',\n 0x0482: 'oc',\n 0x0448: 'or',\n 0x0463: 'ps',\n 0x0415: 'pl',\n 0x0416: 'pt',\n 0x0816: 'pt-PT',\n 0x0446: 'pa',\n 0x046B: 'qu-BO',\n 0x086B: 'qu-EC',\n 0x0C6B: 'qu',\n 0x0418: 'ro',\n 0x0417: 'rm',\n 0x0419: 'ru',\n 0x243B: 'smn',\n 0x103B: 'smj-NO',\n 0x143B: 'smj',\n 0x0C3B: 'se-FI',\n 0x043B: 'se',\n 0x083B: 'se-SE',\n 0x203B: 'sms',\n 0x183B: 'sma-NO',\n 0x1C3B: 'sms',\n 0x044F: 'sa',\n 0x1C1A: 'sr-Cyrl-BA',\n 0x0C1A: 'sr',\n 0x181A: 'sr-Latn-BA',\n 0x081A: 'sr-Latn',\n 0x046C: 'nso',\n 0x0432: 'tn',\n 0x045B: 'si',\n 0x041B: 'sk',\n 0x0424: 'sl',\n 0x2C0A: 'es-AR',\n 0x400A: 'es-BO',\n 0x340A: 'es-CL',\n 0x240A: 'es-CO',\n 0x140A: 'es-CR',\n 0x1C0A: 'es-DO',\n 0x300A: 'es-EC',\n 0x440A: 'es-SV',\n 0x100A: 'es-GT',\n 0x480A: 'es-HN',\n 0x080A: 'es-MX',\n 0x4C0A: 'es-NI',\n 0x180A: 'es-PA',\n 0x3C0A: 'es-PY',\n 0x280A: 'es-PE',\n 0x500A: 'es-PR',\n\n // Microsoft has defined two different language codes for\n // “Spanish with modern sorting” and “Spanish with traditional\n // sorting”. This makes sense for collation APIs, and it would be\n // possible to express this in BCP 47 language tags via Unicode\n // extensions (eg., es-u-co-trad is Spanish with traditional\n // sorting). However, for storing names in fonts, the distinction\n // does not make sense, so we give “es” in both cases.\n 0x0C0A: 'es',\n 0x040A: 'es',\n\n 0x540A: 'es-US',\n 0x380A: 'es-UY',\n 0x200A: 'es-VE',\n 0x081D: 'sv-FI',\n 0x041D: 'sv',\n 0x045A: 'syr',\n 0x0428: 'tg',\n 0x085F: 'tzm',\n 0x0449: 'ta',\n 0x0444: 'tt',\n 0x044A: 'te',\n 0x041E: 'th',\n 0x0451: 'bo',\n 0x041F: 'tr',\n 0x0442: 'tk',\n 0x0480: 'ug',\n 0x0422: 'uk',\n 0x042E: 'hsb',\n 0x0420: 'ur',\n 0x0843: 'uz-Cyrl',\n 0x0443: 'uz',\n 0x042A: 'vi',\n 0x0452: 'cy',\n 0x0488: 'wo',\n 0x0485: 'sah',\n 0x0478: 'ii',\n 0x046A: 'yo'\n };\n\n // Returns a IETF BCP 47 language code, for example 'zh-Hant'\n // for 'Chinese in the traditional script'.\n function getLanguageCode(platformID, languageID, ltag) {\n switch (platformID) {\n case 0: // Unicode\n if (languageID === 0xFFFF) {\n return 'und';\n } else if (ltag) {\n return ltag[languageID];\n }\n\n break;\n\n case 1: // Macintosh\n return macLanguages[languageID];\n\n case 3: // Windows\n return windowsLanguages[languageID];\n }\n\n return undefined;\n }\n\n var utf16 = 'utf-16';\n\n // MacOS script ID → encoding. This table stores the default case,\n // which can be overridden by macLanguageEncodings.\n var macScriptEncodings = {\n 0: 'macintosh', // smRoman\n 1: 'x-mac-japanese', // smJapanese\n 2: 'x-mac-chinesetrad', // smTradChinese\n 3: 'x-mac-korean', // smKorean\n 6: 'x-mac-greek', // smGreek\n 7: 'x-mac-cyrillic', // smCyrillic\n 9: 'x-mac-devanagai', // smDevanagari\n 10: 'x-mac-gurmukhi', // smGurmukhi\n 11: 'x-mac-gujarati', // smGujarati\n 12: 'x-mac-oriya', // smOriya\n 13: 'x-mac-bengali', // smBengali\n 14: 'x-mac-tamil', // smTamil\n 15: 'x-mac-telugu', // smTelugu\n 16: 'x-mac-kannada', // smKannada\n 17: 'x-mac-malayalam', // smMalayalam\n 18: 'x-mac-sinhalese', // smSinhalese\n 19: 'x-mac-burmese', // smBurmese\n 20: 'x-mac-khmer', // smKhmer\n 21: 'x-mac-thai', // smThai\n 22: 'x-mac-lao', // smLao\n 23: 'x-mac-georgian', // smGeorgian\n 24: 'x-mac-armenian', // smArmenian\n 25: 'x-mac-chinesesimp', // smSimpChinese\n 26: 'x-mac-tibetan', // smTibetan\n 27: 'x-mac-mongolian', // smMongolian\n 28: 'x-mac-ethiopic', // smEthiopic\n 29: 'x-mac-ce', // smCentralEuroRoman\n 30: 'x-mac-vietnamese', // smVietnamese\n 31: 'x-mac-extarabic' // smExtArabic\n };\n\n // MacOS language ID → encoding. This table stores the exceptional\n // cases, which override macScriptEncodings. For writing MacOS naming\n // tables, we need to emit a MacOS script ID. Therefore, we cannot\n // merge macScriptEncodings into macLanguageEncodings.\n //\n // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt\n var macLanguageEncodings = {\n 15: 'x-mac-icelandic', // langIcelandic\n 17: 'x-mac-turkish', // langTurkish\n 18: 'x-mac-croatian', // langCroatian\n 24: 'x-mac-ce', // langLithuanian\n 25: 'x-mac-ce', // langPolish\n 26: 'x-mac-ce', // langHungarian\n 27: 'x-mac-ce', // langEstonian\n 28: 'x-mac-ce', // langLatvian\n 30: 'x-mac-icelandic', // langFaroese\n 37: 'x-mac-romanian', // langRomanian\n 38: 'x-mac-ce', // langCzech\n 39: 'x-mac-ce', // langSlovak\n 40: 'x-mac-ce', // langSlovenian\n 143: 'x-mac-inuit', // langInuktitut\n 146: 'x-mac-gaelic' // langIrishGaelicScript\n };\n\n function getEncoding(platformID, encodingID, languageID) {\n switch (platformID) {\n case 0: // Unicode\n return utf16;\n\n case 1: // Apple Macintosh\n return macLanguageEncodings[languageID] || macScriptEncodings[encodingID];\n\n case 3: // Microsoft Windows\n if (encodingID === 1 || encodingID === 10) {\n return utf16;\n }\n\n break;\n }\n\n return undefined;\n }\n\n // Parse the naming `name` table.\n // FIXME: Format 1 additional fields are not supported yet.\n // ltag is the content of the `ltag' table, such as ['en', 'zh-Hans', 'de-CH-1904'].\n function parseNameTable(data, start, ltag) {\n var name = {};\n var p = new parse.Parser(data, start);\n var format = p.parseUShort();\n var count = p.parseUShort();\n var stringOffset = p.offset + p.parseUShort();\n for (var i = 0; i < count; i++) {\n var platformID = p.parseUShort();\n var encodingID = p.parseUShort();\n var languageID = p.parseUShort();\n var nameID = p.parseUShort();\n var property = nameTableNames[nameID] || nameID;\n var byteLength = p.parseUShort();\n var offset = p.parseUShort();\n var language = getLanguageCode(platformID, languageID, ltag);\n var encoding = getEncoding(platformID, encodingID, languageID);\n if (encoding !== undefined && language !== undefined) {\n var text = (void 0);\n if (encoding === utf16) {\n text = decode.UTF16(data, stringOffset + offset, byteLength);\n } else {\n text = decode.MACSTRING(data, stringOffset + offset, byteLength, encoding);\n }\n\n if (text) {\n var translations = name[property];\n if (translations === undefined) {\n translations = name[property] = {};\n }\n\n translations[language] = text;\n }\n }\n }\n\n var langTagCount = 0;\n if (format === 1) {\n // FIXME: Also handle Microsoft's 'name' table 1.\n langTagCount = p.parseUShort();\n }\n\n return name;\n }\n\n // {23: 'foo'} → {'foo': 23}\n // ['bar', 'baz'] → {'bar': 0, 'baz': 1}\n function reverseDict(dict) {\n var result = {};\n for (var key in dict) {\n result[dict[key]] = parseInt(key);\n }\n\n return result;\n }\n\n function makeNameRecord(platformID, encodingID, languageID, nameID, length, offset) {\n return new table.Record('NameRecord', [\n {name: 'platformID', type: 'USHORT', value: platformID},\n {name: 'encodingID', type: 'USHORT', value: encodingID},\n {name: 'languageID', type: 'USHORT', value: languageID},\n {name: 'nameID', type: 'USHORT', value: nameID},\n {name: 'length', type: 'USHORT', value: length},\n {name: 'offset', type: 'USHORT', value: offset}\n ]);\n }\n\n // Finds the position of needle in haystack, or -1 if not there.\n // Like String.indexOf(), but for arrays.\n function findSubArray(needle, haystack) {\n var needleLength = needle.length;\n var limit = haystack.length - needleLength + 1;\n\n loop:\n for (var pos = 0; pos < limit; pos++) {\n for (; pos < limit; pos++) {\n for (var k = 0; k < needleLength; k++) {\n if (haystack[pos + k] !== needle[k]) {\n continue loop;\n }\n }\n\n return pos;\n }\n }\n\n return -1;\n }\n\n function addStringToPool(s, pool) {\n var offset = findSubArray(s, pool);\n if (offset < 0) {\n offset = pool.length;\n var i = 0;\n var len = s.length;\n for (; i < len; ++i) {\n pool.push(s[i]);\n }\n\n }\n\n return offset;\n }\n\n function makeNameTable(names, ltag) {\n var nameID;\n var nameIDs = [];\n\n var namesWithNumericKeys = {};\n var nameTableIds = reverseDict(nameTableNames);\n for (var key in names) {\n var id = nameTableIds[key];\n if (id === undefined) {\n id = key;\n }\n\n nameID = parseInt(id);\n\n if (isNaN(nameID)) {\n throw new Error('Name table entry \"' + key + '\" does not exist, see nameTableNames for complete list.');\n }\n\n namesWithNumericKeys[nameID] = names[key];\n nameIDs.push(nameID);\n }\n\n var macLanguageIds = reverseDict(macLanguages);\n var windowsLanguageIds = reverseDict(windowsLanguages);\n\n var nameRecords = [];\n var stringPool = [];\n\n for (var i = 0; i < nameIDs.length; i++) {\n nameID = nameIDs[i];\n var translations = namesWithNumericKeys[nameID];\n for (var lang in translations) {\n var text = translations[lang];\n\n // For MacOS, we try to emit the name in the form that was introduced\n // in the initial version of the TrueType spec (in the late 1980s).\n // However, this can fail for various reasons: the requested BCP 47\n // language code might not have an old-style Mac equivalent;\n // we might not have a codec for the needed character encoding;\n // or the name might contain characters that cannot be expressed\n // in the old-style Macintosh encoding. In case of failure, we emit\n // the name in a more modern fashion (Unicode encoding with BCP 47\n // language tags) that is recognized by MacOS 10.5, released in 2009.\n // If fonts were only read by operating systems, we could simply\n // emit all names in the modern form; this would be much easier.\n // However, there are many applications and libraries that read\n // 'name' tables directly, and these will usually only recognize\n // the ancient form (silently skipping the unrecognized names).\n var macPlatform = 1; // Macintosh\n var macLanguage = macLanguageIds[lang];\n var macScript = macLanguageToScript[macLanguage];\n var macEncoding = getEncoding(macPlatform, macScript, macLanguage);\n var macName = encode.MACSTRING(text, macEncoding);\n if (macName === undefined) {\n macPlatform = 0; // Unicode\n macLanguage = ltag.indexOf(lang);\n if (macLanguage < 0) {\n macLanguage = ltag.length;\n ltag.push(lang);\n }\n\n macScript = 4; // Unicode 2.0 and later\n macName = encode.UTF16(text);\n }\n\n var macNameOffset = addStringToPool(macName, stringPool);\n nameRecords.push(makeNameRecord(macPlatform, macScript, macLanguage,\n nameID, macName.length, macNameOffset));\n\n var winLanguage = windowsLanguageIds[lang];\n if (winLanguage !== undefined) {\n var winName = encode.UTF16(text);\n var winNameOffset = addStringToPool(winName, stringPool);\n nameRecords.push(makeNameRecord(3, 1, winLanguage,\n nameID, winName.length, winNameOffset));\n }\n }\n }\n\n nameRecords.sort(function(a, b) {\n return ((a.platformID - b.platformID) ||\n (a.encodingID - b.encodingID) ||\n (a.languageID - b.languageID) ||\n (a.nameID - b.nameID));\n });\n\n var t = new table.Table('name', [\n {name: 'format', type: 'USHORT', value: 0},\n {name: 'count', type: 'USHORT', value: nameRecords.length},\n {name: 'stringOffset', type: 'USHORT', value: 6 + nameRecords.length * 12}\n ]);\n\n for (var r = 0; r < nameRecords.length; r++) {\n t.fields.push({name: 'record_' + r, type: 'RECORD', value: nameRecords[r]});\n }\n\n t.fields.push({name: 'strings', type: 'LITERAL', value: stringPool});\n return t;\n }\n\n var _name = { parse: parseNameTable, make: makeNameTable };\n\n // The `OS/2` table contains metrics required in OpenType fonts.\n\n var unicodeRanges = [\n {begin: 0x0000, end: 0x007F}, // Basic Latin\n {begin: 0x0080, end: 0x00FF}, // Latin-1 Supplement\n {begin: 0x0100, end: 0x017F}, // Latin Extended-A\n {begin: 0x0180, end: 0x024F}, // Latin Extended-B\n {begin: 0x0250, end: 0x02AF}, // IPA Extensions\n {begin: 0x02B0, end: 0x02FF}, // Spacing Modifier Letters\n {begin: 0x0300, end: 0x036F}, // Combining Diacritical Marks\n {begin: 0x0370, end: 0x03FF}, // Greek and Coptic\n {begin: 0x2C80, end: 0x2CFF}, // Coptic\n {begin: 0x0400, end: 0x04FF}, // Cyrillic\n {begin: 0x0530, end: 0x058F}, // Armenian\n {begin: 0x0590, end: 0x05FF}, // Hebrew\n {begin: 0xA500, end: 0xA63F}, // Vai\n {begin: 0x0600, end: 0x06FF}, // Arabic\n {begin: 0x07C0, end: 0x07FF}, // NKo\n {begin: 0x0900, end: 0x097F}, // Devanagari\n {begin: 0x0980, end: 0x09FF}, // Bengali\n {begin: 0x0A00, end: 0x0A7F}, // Gurmukhi\n {begin: 0x0A80, end: 0x0AFF}, // Gujarati\n {begin: 0x0B00, end: 0x0B7F}, // Oriya\n {begin: 0x0B80, end: 0x0BFF}, // Tamil\n {begin: 0x0C00, end: 0x0C7F}, // Telugu\n {begin: 0x0C80, end: 0x0CFF}, // Kannada\n {begin: 0x0D00, end: 0x0D7F}, // Malayalam\n {begin: 0x0E00, end: 0x0E7F}, // Thai\n {begin: 0x0E80, end: 0x0EFF}, // Lao\n {begin: 0x10A0, end: 0x10FF}, // Georgian\n {begin: 0x1B00, end: 0x1B7F}, // Balinese\n {begin: 0x1100, end: 0x11FF}, // Hangul Jamo\n {begin: 0x1E00, end: 0x1EFF}, // Latin Extended Additional\n {begin: 0x1F00, end: 0x1FFF}, // Greek Extended\n {begin: 0x2000, end: 0x206F}, // General Punctuation\n {begin: 0x2070, end: 0x209F}, // Superscripts And Subscripts\n {begin: 0x20A0, end: 0x20CF}, // Currency Symbol\n {begin: 0x20D0, end: 0x20FF}, // Combining Diacritical Marks For Symbols\n {begin: 0x2100, end: 0x214F}, // Letterlike Symbols\n {begin: 0x2150, end: 0x218F}, // Number Forms\n {begin: 0x2190, end: 0x21FF}, // Arrows\n {begin: 0x2200, end: 0x22FF}, // Mathematical Operators\n {begin: 0x2300, end: 0x23FF}, // Miscellaneous Technical\n {begin: 0x2400, end: 0x243F}, // Control Pictures\n {begin: 0x2440, end: 0x245F}, // Optical Character Recognition\n {begin: 0x2460, end: 0x24FF}, // Enclosed Alphanumerics\n {begin: 0x2500, end: 0x257F}, // Box Drawing\n {begin: 0x2580, end: 0x259F}, // Block Elements\n {begin: 0x25A0, end: 0x25FF}, // Geometric Shapes\n {begin: 0x2600, end: 0x26FF}, // Miscellaneous Symbols\n {begin: 0x2700, end: 0x27BF}, // Dingbats\n {begin: 0x3000, end: 0x303F}, // CJK Symbols And Punctuation\n {begin: 0x3040, end: 0x309F}, // Hiragana\n {begin: 0x30A0, end: 0x30FF}, // Katakana\n {begin: 0x3100, end: 0x312F}, // Bopomofo\n {begin: 0x3130, end: 0x318F}, // Hangul Compatibility Jamo\n {begin: 0xA840, end: 0xA87F}, // Phags-pa\n {begin: 0x3200, end: 0x32FF}, // Enclosed CJK Letters And Months\n {begin: 0x3300, end: 0x33FF}, // CJK Compatibility\n {begin: 0xAC00, end: 0xD7AF}, // Hangul Syllables\n {begin: 0xD800, end: 0xDFFF}, // Non-Plane 0 *\n {begin: 0x10900, end: 0x1091F}, // Phoenicia\n {begin: 0x4E00, end: 0x9FFF}, // CJK Unified Ideographs\n {begin: 0xE000, end: 0xF8FF}, // Private Use Area (plane 0)\n {begin: 0x31C0, end: 0x31EF}, // CJK Strokes\n {begin: 0xFB00, end: 0xFB4F}, // Alphabetic Presentation Forms\n {begin: 0xFB50, end: 0xFDFF}, // Arabic Presentation Forms-A\n {begin: 0xFE20, end: 0xFE2F}, // Combining Half Marks\n {begin: 0xFE10, end: 0xFE1F}, // Vertical Forms\n {begin: 0xFE50, end: 0xFE6F}, // Small Form Variants\n {begin: 0xFE70, end: 0xFEFF}, // Arabic Presentation Forms-B\n {begin: 0xFF00, end: 0xFFEF}, // Halfwidth And Fullwidth Forms\n {begin: 0xFFF0, end: 0xFFFF}, // Specials\n {begin: 0x0F00, end: 0x0FFF}, // Tibetan\n {begin: 0x0700, end: 0x074F}, // Syriac\n {begin: 0x0780, end: 0x07BF}, // Thaana\n {begin: 0x0D80, end: 0x0DFF}, // Sinhala\n {begin: 0x1000, end: 0x109F}, // Myanmar\n {begin: 0x1200, end: 0x137F}, // Ethiopic\n {begin: 0x13A0, end: 0x13FF}, // Cherokee\n {begin: 0x1400, end: 0x167F}, // Unified Canadian Aboriginal Syllabics\n {begin: 0x1680, end: 0x169F}, // Ogham\n {begin: 0x16A0, end: 0x16FF}, // Runic\n {begin: 0x1780, end: 0x17FF}, // Khmer\n {begin: 0x1800, end: 0x18AF}, // Mongolian\n {begin: 0x2800, end: 0x28FF}, // Braille Patterns\n {begin: 0xA000, end: 0xA48F}, // Yi Syllables\n {begin: 0x1700, end: 0x171F}, // Tagalog\n {begin: 0x10300, end: 0x1032F}, // Old Italic\n {begin: 0x10330, end: 0x1034F}, // Gothic\n {begin: 0x10400, end: 0x1044F}, // Deseret\n {begin: 0x1D000, end: 0x1D0FF}, // Byzantine Musical Symbols\n {begin: 0x1D400, end: 0x1D7FF}, // Mathematical Alphanumeric Symbols\n {begin: 0xFF000, end: 0xFFFFD}, // Private Use (plane 15)\n {begin: 0xFE00, end: 0xFE0F}, // Variation Selectors\n {begin: 0xE0000, end: 0xE007F}, // Tags\n {begin: 0x1900, end: 0x194F}, // Limbu\n {begin: 0x1950, end: 0x197F}, // Tai Le\n {begin: 0x1980, end: 0x19DF}, // New Tai Lue\n {begin: 0x1A00, end: 0x1A1F}, // Buginese\n {begin: 0x2C00, end: 0x2C5F}, // Glagolitic\n {begin: 0x2D30, end: 0x2D7F}, // Tifinagh\n {begin: 0x4DC0, end: 0x4DFF}, // Yijing Hexagram Symbols\n {begin: 0xA800, end: 0xA82F}, // Syloti Nagri\n {begin: 0x10000, end: 0x1007F}, // Linear B Syllabary\n {begin: 0x10140, end: 0x1018F}, // Ancient Greek Numbers\n {begin: 0x10380, end: 0x1039F}, // Ugaritic\n {begin: 0x103A0, end: 0x103DF}, // Old Persian\n {begin: 0x10450, end: 0x1047F}, // Shavian\n {begin: 0x10480, end: 0x104AF}, // Osmanya\n {begin: 0x10800, end: 0x1083F}, // Cypriot Syllabary\n {begin: 0x10A00, end: 0x10A5F}, // Kharoshthi\n {begin: 0x1D300, end: 0x1D35F}, // Tai Xuan Jing Symbols\n {begin: 0x12000, end: 0x123FF}, // Cuneiform\n {begin: 0x1D360, end: 0x1D37F}, // Counting Rod Numerals\n {begin: 0x1B80, end: 0x1BBF}, // Sundanese\n {begin: 0x1C00, end: 0x1C4F}, // Lepcha\n {begin: 0x1C50, end: 0x1C7F}, // Ol Chiki\n {begin: 0xA880, end: 0xA8DF}, // Saurashtra\n {begin: 0xA900, end: 0xA92F}, // Kayah Li\n {begin: 0xA930, end: 0xA95F}, // Rejang\n {begin: 0xAA00, end: 0xAA5F}, // Cham\n {begin: 0x10190, end: 0x101CF}, // Ancient Symbols\n {begin: 0x101D0, end: 0x101FF}, // Phaistos Disc\n {begin: 0x102A0, end: 0x102DF}, // Carian\n {begin: 0x1F030, end: 0x1F09F} // Domino Tiles\n ];\n\n function getUnicodeRange(unicode) {\n for (var i = 0; i < unicodeRanges.length; i += 1) {\n var range = unicodeRanges[i];\n if (unicode >= range.begin && unicode < range.end) {\n return i;\n }\n }\n\n return -1;\n }\n\n // Parse the OS/2 and Windows metrics `OS/2` table\n function parseOS2Table(data, start) {\n var os2 = {};\n var p = new parse.Parser(data, start);\n os2.version = p.parseUShort();\n os2.xAvgCharWidth = p.parseShort();\n os2.usWeightClass = p.parseUShort();\n os2.usWidthClass = p.parseUShort();\n os2.fsType = p.parseUShort();\n os2.ySubscriptXSize = p.parseShort();\n os2.ySubscriptYSize = p.parseShort();\n os2.ySubscriptXOffset = p.parseShort();\n os2.ySubscriptYOffset = p.parseShort();\n os2.ySuperscriptXSize = p.parseShort();\n os2.ySuperscriptYSize = p.parseShort();\n os2.ySuperscriptXOffset = p.parseShort();\n os2.ySuperscriptYOffset = p.parseShort();\n os2.yStrikeoutSize = p.parseShort();\n os2.yStrikeoutPosition = p.parseShort();\n os2.sFamilyClass = p.parseShort();\n os2.panose = [];\n for (var i = 0; i < 10; i++) {\n os2.panose[i] = p.parseByte();\n }\n\n os2.ulUnicodeRange1 = p.parseULong();\n os2.ulUnicodeRange2 = p.parseULong();\n os2.ulUnicodeRange3 = p.parseULong();\n os2.ulUnicodeRange4 = p.parseULong();\n os2.achVendID = String.fromCharCode(p.parseByte(), p.parseByte(), p.parseByte(), p.parseByte());\n os2.fsSelection = p.parseUShort();\n os2.usFirstCharIndex = p.parseUShort();\n os2.usLastCharIndex = p.parseUShort();\n os2.sTypoAscender = p.parseShort();\n os2.sTypoDescender = p.parseShort();\n os2.sTypoLineGap = p.parseShort();\n os2.usWinAscent = p.parseUShort();\n os2.usWinDescent = p.parseUShort();\n if (os2.version >= 1) {\n os2.ulCodePageRange1 = p.parseULong();\n os2.ulCodePageRange2 = p.parseULong();\n }\n\n if (os2.version >= 2) {\n os2.sxHeight = p.parseShort();\n os2.sCapHeight = p.parseShort();\n os2.usDefaultChar = p.parseUShort();\n os2.usBreakChar = p.parseUShort();\n os2.usMaxContent = p.parseUShort();\n }\n\n return os2;\n }\n\n function makeOS2Table(options) {\n return new table.Table('OS/2', [\n {name: 'version', type: 'USHORT', value: 0x0003},\n {name: 'xAvgCharWidth', type: 'SHORT', value: 0},\n {name: 'usWeightClass', type: 'USHORT', value: 0},\n {name: 'usWidthClass', type: 'USHORT', value: 0},\n {name: 'fsType', type: 'USHORT', value: 0},\n {name: 'ySubscriptXSize', type: 'SHORT', value: 650},\n {name: 'ySubscriptYSize', type: 'SHORT', value: 699},\n {name: 'ySubscriptXOffset', type: 'SHORT', value: 0},\n {name: 'ySubscriptYOffset', type: 'SHORT', value: 140},\n {name: 'ySuperscriptXSize', type: 'SHORT', value: 650},\n {name: 'ySuperscriptYSize', type: 'SHORT', value: 699},\n {name: 'ySuperscriptXOffset', type: 'SHORT', value: 0},\n {name: 'ySuperscriptYOffset', type: 'SHORT', value: 479},\n {name: 'yStrikeoutSize', type: 'SHORT', value: 49},\n {name: 'yStrikeoutPosition', type: 'SHORT', value: 258},\n {name: 'sFamilyClass', type: 'SHORT', value: 0},\n {name: 'bFamilyType', type: 'BYTE', value: 0},\n {name: 'bSerifStyle', type: 'BYTE', value: 0},\n {name: 'bWeight', type: 'BYTE', value: 0},\n {name: 'bProportion', type: 'BYTE', value: 0},\n {name: 'bContrast', type: 'BYTE', value: 0},\n {name: 'bStrokeVariation', type: 'BYTE', value: 0},\n {name: 'bArmStyle', type: 'BYTE', value: 0},\n {name: 'bLetterform', type: 'BYTE', value: 0},\n {name: 'bMidline', type: 'BYTE', value: 0},\n {name: 'bXHeight', type: 'BYTE', value: 0},\n {name: 'ulUnicodeRange1', type: 'ULONG', value: 0},\n {name: 'ulUnicodeRange2', type: 'ULONG', value: 0},\n {name: 'ulUnicodeRange3', type: 'ULONG', value: 0},\n {name: 'ulUnicodeRange4', type: 'ULONG', value: 0},\n {name: 'achVendID', type: 'CHARARRAY', value: 'XXXX'},\n {name: 'fsSelection', type: 'USHORT', value: 0},\n {name: 'usFirstCharIndex', type: 'USHORT', value: 0},\n {name: 'usLastCharIndex', type: 'USHORT', value: 0},\n {name: 'sTypoAscender', type: 'SHORT', value: 0},\n {name: 'sTypoDescender', type: 'SHORT', value: 0},\n {name: 'sTypoLineGap', type: 'SHORT', value: 0},\n {name: 'usWinAscent', type: 'USHORT', value: 0},\n {name: 'usWinDescent', type: 'USHORT', value: 0},\n {name: 'ulCodePageRange1', type: 'ULONG', value: 0},\n {name: 'ulCodePageRange2', type: 'ULONG', value: 0},\n {name: 'sxHeight', type: 'SHORT', value: 0},\n {name: 'sCapHeight', type: 'SHORT', value: 0},\n {name: 'usDefaultChar', type: 'USHORT', value: 0},\n {name: 'usBreakChar', type: 'USHORT', value: 0},\n {name: 'usMaxContext', type: 'USHORT', value: 0}\n ], options);\n }\n\n var os2 = { parse: parseOS2Table, make: makeOS2Table, unicodeRanges: unicodeRanges, getUnicodeRange: getUnicodeRange };\n\n // The `post` table stores additional PostScript information, such as glyph names.\n\n // Parse the PostScript `post` table\n function parsePostTable(data, start) {\n var post = {};\n var p = new parse.Parser(data, start);\n post.version = p.parseVersion();\n post.italicAngle = p.parseFixed();\n post.underlinePosition = p.parseShort();\n post.underlineThickness = p.parseShort();\n post.isFixedPitch = p.parseULong();\n post.minMemType42 = p.parseULong();\n post.maxMemType42 = p.parseULong();\n post.minMemType1 = p.parseULong();\n post.maxMemType1 = p.parseULong();\n switch (post.version) {\n case 1:\n post.names = standardNames.slice();\n break;\n case 2:\n post.numberOfGlyphs = p.parseUShort();\n post.glyphNameIndex = new Array(post.numberOfGlyphs);\n for (var i = 0; i < post.numberOfGlyphs; i++) {\n post.glyphNameIndex[i] = p.parseUShort();\n }\n\n post.names = [];\n for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) {\n if (post.glyphNameIndex[i$1] >= standardNames.length) {\n var nameLength = p.parseChar();\n post.names.push(p.parseString(nameLength));\n }\n }\n\n break;\n case 2.5:\n post.numberOfGlyphs = p.parseUShort();\n post.offset = new Array(post.numberOfGlyphs);\n for (var i$2 = 0; i$2 < post.numberOfGlyphs; i$2++) {\n post.offset[i$2] = p.parseChar();\n }\n\n break;\n }\n return post;\n }\n\n function makePostTable() {\n return new table.Table('post', [\n {name: 'version', type: 'FIXED', value: 0x00030000},\n {name: 'italicAngle', type: 'FIXED', value: 0},\n {name: 'underlinePosition', type: 'FWORD', value: 0},\n {name: 'underlineThickness', type: 'FWORD', value: 0},\n {name: 'isFixedPitch', type: 'ULONG', value: 0},\n {name: 'minMemType42', type: 'ULONG', value: 0},\n {name: 'maxMemType42', type: 'ULONG', value: 0},\n {name: 'minMemType1', type: 'ULONG', value: 0},\n {name: 'maxMemType1', type: 'ULONG', value: 0}\n ]);\n }\n\n var post = { parse: parsePostTable, make: makePostTable };\n\n // The `GSUB` table contains ligatures, among other things.\n\n var subtableParsers = new Array(9); // subtableParsers[0] is unused\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#SS\n subtableParsers[1] = function parseLookup1() {\n var start = this.offset + this.relativeOffset;\n var substFormat = this.parseUShort();\n if (substFormat === 1) {\n return {\n substFormat: 1,\n coverage: this.parsePointer(Parser.coverage),\n deltaGlyphId: this.parseUShort()\n };\n } else if (substFormat === 2) {\n return {\n substFormat: 2,\n coverage: this.parsePointer(Parser.coverage),\n substitute: this.parseOffset16List()\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': lookup type 1 format must be 1 or 2.');\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#MS\n subtableParsers[2] = function parseLookup2() {\n var substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Multiple Substitution Subtable identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n sequences: this.parseListOfLists()\n };\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#AS\n subtableParsers[3] = function parseLookup3() {\n var substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Alternate Substitution Subtable identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n alternateSets: this.parseListOfLists()\n };\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#LS\n subtableParsers[4] = function parseLookup4() {\n var substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB ligature table identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n ligatureSets: this.parseListOfLists(function() {\n return {\n ligGlyph: this.parseUShort(),\n components: this.parseUShortList(this.parseUShort() - 1)\n };\n })\n };\n };\n\n var lookupRecordDesc = {\n sequenceIndex: Parser.uShort,\n lookupListIndex: Parser.uShort\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CSF\n subtableParsers[5] = function parseLookup5() {\n var start = this.offset + this.relativeOffset;\n var substFormat = this.parseUShort();\n\n if (substFormat === 1) {\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n ruleSets: this.parseListOfLists(function() {\n var glyphCount = this.parseUShort();\n var substCount = this.parseUShort();\n return {\n input: this.parseUShortList(glyphCount - 1),\n lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 2) {\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n classDef: this.parsePointer(Parser.classDef),\n classSets: this.parseListOfLists(function() {\n var glyphCount = this.parseUShort();\n var substCount = this.parseUShort();\n return {\n classes: this.parseUShortList(glyphCount - 1),\n lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 3) {\n var glyphCount = this.parseUShort();\n var substCount = this.parseUShort();\n return {\n substFormat: substFormat,\n coverages: this.parseList(glyphCount, Parser.pointer(Parser.coverage)),\n lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': lookup type 5 format must be 1, 2 or 3.');\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CC\n subtableParsers[6] = function parseLookup6() {\n var start = this.offset + this.relativeOffset;\n var substFormat = this.parseUShort();\n if (substFormat === 1) {\n return {\n substFormat: 1,\n coverage: this.parsePointer(Parser.coverage),\n chainRuleSets: this.parseListOfLists(function() {\n return {\n backtrack: this.parseUShortList(),\n input: this.parseUShortList(this.parseShort() - 1),\n lookahead: this.parseUShortList(),\n lookupRecords: this.parseRecordList(lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 2) {\n return {\n substFormat: 2,\n coverage: this.parsePointer(Parser.coverage),\n backtrackClassDef: this.parsePointer(Parser.classDef),\n inputClassDef: this.parsePointer(Parser.classDef),\n lookaheadClassDef: this.parsePointer(Parser.classDef),\n chainClassSet: this.parseListOfLists(function() {\n return {\n backtrack: this.parseUShortList(),\n input: this.parseUShortList(this.parseShort() - 1),\n lookahead: this.parseUShortList(),\n lookupRecords: this.parseRecordList(lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 3) {\n return {\n substFormat: 3,\n backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n inputCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n lookupRecords: this.parseRecordList(lookupRecordDesc)\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': lookup type 6 format must be 1, 2 or 3.');\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#ES\n subtableParsers[7] = function parseLookup7() {\n // Extension Substitution subtable\n var substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Extension Substitution subtable identifier-format must be 1');\n var extensionLookupType = this.parseUShort();\n var extensionParser = new Parser(this.data, this.offset + this.parseULong());\n return {\n substFormat: 1,\n lookupType: extensionLookupType,\n extension: subtableParsers[extensionLookupType].call(extensionParser)\n };\n };\n\n // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#RCCS\n subtableParsers[8] = function parseLookup8() {\n var substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n substitutes: this.parseUShortList()\n };\n };\n\n // https://www.microsoft.com/typography/OTSPEC/gsub.htm\n function parseGsubTable(data, start) {\n start = start || 0;\n var p = new Parser(data, start);\n var tableVersion = p.parseVersion(1);\n check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GSUB table version.');\n if (tableVersion === 1) {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers)\n };\n } else {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers),\n variations: p.parseFeatureVariationsList()\n };\n }\n\n }\n\n // GSUB Writing //////////////////////////////////////////////\n var subtableMakers = new Array(9);\n\n subtableMakers[1] = function makeLookup1(subtable) {\n if (subtable.substFormat === 1) {\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)},\n {name: 'deltaGlyphID', type: 'USHORT', value: subtable.deltaGlyphId}\n ]);\n } else {\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 2},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.ushortList('substitute', subtable.substitute)));\n }\n };\n\n subtableMakers[2] = function makeLookup2(subtable) {\n check.assert(subtable.substFormat === 1, 'Lookup type 2 substFormat must be 1.');\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('seqSet', subtable.sequences, function(sequenceSet) {\n return new table.Table('sequenceSetTable', table.ushortList('sequence', sequenceSet));\n })));\n };\n\n subtableMakers[3] = function makeLookup3(subtable) {\n check.assert(subtable.substFormat === 1, 'Lookup type 3 substFormat must be 1.');\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('altSet', subtable.alternateSets, function(alternateSet) {\n return new table.Table('alternateSetTable', table.ushortList('alternate', alternateSet));\n })));\n };\n\n subtableMakers[4] = function makeLookup4(subtable) {\n check.assert(subtable.substFormat === 1, 'Lookup type 4 substFormat must be 1.');\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('ligSet', subtable.ligatureSets, function(ligatureSet) {\n return new table.Table('ligatureSetTable', table.tableList('ligature', ligatureSet, function(ligature) {\n return new table.Table('ligatureTable',\n [{name: 'ligGlyph', type: 'USHORT', value: ligature.ligGlyph}]\n .concat(table.ushortList('component', ligature.components, ligature.components.length + 1))\n );\n }));\n })));\n };\n\n subtableMakers[6] = function makeLookup6(subtable) {\n if (subtable.substFormat === 1) {\n var returnTable = new table.Table('chainContextTable', [\n {name: 'substFormat', type: 'USHORT', value: subtable.substFormat},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('chainRuleSet', subtable.chainRuleSets, function(chainRuleSet) {\n return new table.Table('chainRuleSetTable', table.tableList('chainRule', chainRuleSet, function(chainRule) {\n var tableData = table.ushortList('backtrackGlyph', chainRule.backtrack, chainRule.backtrack.length)\n .concat(table.ushortList('inputGlyph', chainRule.input, chainRule.input.length + 1))\n .concat(table.ushortList('lookaheadGlyph', chainRule.lookahead, chainRule.lookahead.length))\n .concat(table.ushortList('substitution', [], chainRule.lookupRecords.length));\n\n chainRule.lookupRecords.forEach(function (record, i) {\n tableData = tableData\n .concat({name: 'sequenceIndex' + i, type: 'USHORT', value: record.sequenceIndex})\n .concat({name: 'lookupListIndex' + i, type: 'USHORT', value: record.lookupListIndex});\n });\n return new table.Table('chainRuleTable', tableData);\n }));\n })));\n return returnTable;\n } else if (subtable.substFormat === 2) {\n check.assert(false, 'lookup type 6 format 2 is not yet supported.');\n } else if (subtable.substFormat === 3) {\n var tableData = [\n {name: 'substFormat', type: 'USHORT', value: subtable.substFormat} ];\n\n tableData.push({name: 'backtrackGlyphCount', type: 'USHORT', value: subtable.backtrackCoverage.length});\n subtable.backtrackCoverage.forEach(function (coverage, i) {\n tableData.push({name: 'backtrackCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});\n });\n tableData.push({name: 'inputGlyphCount', type: 'USHORT', value: subtable.inputCoverage.length});\n subtable.inputCoverage.forEach(function (coverage, i) {\n tableData.push({name: 'inputCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});\n });\n tableData.push({name: 'lookaheadGlyphCount', type: 'USHORT', value: subtable.lookaheadCoverage.length});\n subtable.lookaheadCoverage.forEach(function (coverage, i) {\n tableData.push({name: 'lookaheadCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});\n });\n\n tableData.push({name: 'substitutionCount', type: 'USHORT', value: subtable.lookupRecords.length});\n subtable.lookupRecords.forEach(function (record, i) {\n tableData = tableData\n .concat({name: 'sequenceIndex' + i, type: 'USHORT', value: record.sequenceIndex})\n .concat({name: 'lookupListIndex' + i, type: 'USHORT', value: record.lookupListIndex});\n });\n\n var returnTable$1 = new table.Table('chainContextTable', tableData);\n\n return returnTable$1;\n }\n\n check.assert(false, 'lookup type 6 format must be 1, 2 or 3.');\n };\n\n function makeGsubTable(gsub) {\n return new table.Table('GSUB', [\n {name: 'version', type: 'ULONG', value: 0x10000},\n {name: 'scripts', type: 'TABLE', value: new table.ScriptList(gsub.scripts)},\n {name: 'features', type: 'TABLE', value: new table.FeatureList(gsub.features)},\n {name: 'lookups', type: 'TABLE', value: new table.LookupList(gsub.lookups, subtableMakers)}\n ]);\n }\n\n var gsub = { parse: parseGsubTable, make: makeGsubTable };\n\n // The `GPOS` table contains kerning pairs, among other things.\n\n // Parse the metadata `meta` table.\n // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html\n function parseMetaTable(data, start) {\n var p = new parse.Parser(data, start);\n var tableVersion = p.parseULong();\n check.argument(tableVersion === 1, 'Unsupported META table version.');\n p.parseULong(); // flags - currently unused and set to 0\n p.parseULong(); // tableOffset\n var numDataMaps = p.parseULong();\n\n var tags = {};\n for (var i = 0; i < numDataMaps; i++) {\n var tag = p.parseTag();\n var dataOffset = p.parseULong();\n var dataLength = p.parseULong();\n var text = decode.UTF8(data, start + dataOffset, dataLength);\n\n tags[tag] = text;\n }\n return tags;\n }\n\n function makeMetaTable(tags) {\n var numTags = Object.keys(tags).length;\n var stringPool = '';\n var stringPoolOffset = 16 + numTags * 12;\n\n var result = new table.Table('meta', [\n {name: 'version', type: 'ULONG', value: 1},\n {name: 'flags', type: 'ULONG', value: 0},\n {name: 'offset', type: 'ULONG', value: stringPoolOffset},\n {name: 'numTags', type: 'ULONG', value: numTags}\n ]);\n\n for (var tag in tags) {\n var pos = stringPool.length;\n stringPool += tags[tag];\n\n result.fields.push({name: 'tag ' + tag, type: 'TAG', value: tag});\n result.fields.push({name: 'offset ' + tag, type: 'ULONG', value: stringPoolOffset + pos});\n result.fields.push({name: 'length ' + tag, type: 'ULONG', value: tags[tag].length});\n }\n\n result.fields.push({name: 'stringPool', type: 'CHARARRAY', value: stringPool});\n\n return result;\n }\n\n var meta = { parse: parseMetaTable, make: makeMetaTable };\n\n // The `sfnt` wrapper provides organization for the tables in the font.\n\n function log2(v) {\n return Math.log(v) / Math.log(2) | 0;\n }\n\n function computeCheckSum(bytes) {\n while (bytes.length % 4 !== 0) {\n bytes.push(0);\n }\n\n var sum = 0;\n for (var i = 0; i < bytes.length; i += 4) {\n sum += (bytes[i] << 24) +\n (bytes[i + 1] << 16) +\n (bytes[i + 2] << 8) +\n (bytes[i + 3]);\n }\n\n sum %= Math.pow(2, 32);\n return sum;\n }\n\n function makeTableRecord(tag, checkSum, offset, length) {\n return new table.Record('Table Record', [\n {name: 'tag', type: 'TAG', value: tag !== undefined ? tag : ''},\n {name: 'checkSum', type: 'ULONG', value: checkSum !== undefined ? checkSum : 0},\n {name: 'offset', type: 'ULONG', value: offset !== undefined ? offset : 0},\n {name: 'length', type: 'ULONG', value: length !== undefined ? length : 0}\n ]);\n }\n\n function makeSfntTable(tables) {\n var sfnt = new table.Table('sfnt', [\n {name: 'version', type: 'TAG', value: 'OTTO'},\n {name: 'numTables', type: 'USHORT', value: 0},\n {name: 'searchRange', type: 'USHORT', value: 0},\n {name: 'entrySelector', type: 'USHORT', value: 0},\n {name: 'rangeShift', type: 'USHORT', value: 0}\n ]);\n sfnt.tables = tables;\n sfnt.numTables = tables.length;\n var highestPowerOf2 = Math.pow(2, log2(sfnt.numTables));\n sfnt.searchRange = 16 * highestPowerOf2;\n sfnt.entrySelector = log2(highestPowerOf2);\n sfnt.rangeShift = sfnt.numTables * 16 - sfnt.searchRange;\n\n var recordFields = [];\n var tableFields = [];\n\n var offset = sfnt.sizeOf() + (makeTableRecord().sizeOf() * sfnt.numTables);\n while (offset % 4 !== 0) {\n offset += 1;\n tableFields.push({name: 'padding', type: 'BYTE', value: 0});\n }\n\n for (var i = 0; i < tables.length; i += 1) {\n var t = tables[i];\n check.argument(t.tableName.length === 4, 'Table name' + t.tableName + ' is invalid.');\n var tableLength = t.sizeOf();\n var tableRecord = makeTableRecord(t.tableName, computeCheckSum(t.encode()), offset, tableLength);\n recordFields.push({name: tableRecord.tag + ' Table Record', type: 'RECORD', value: tableRecord});\n tableFields.push({name: t.tableName + ' table', type: 'RECORD', value: t});\n offset += tableLength;\n check.argument(!isNaN(offset), 'Something went wrong calculating the offset.');\n while (offset % 4 !== 0) {\n offset += 1;\n tableFields.push({name: 'padding', type: 'BYTE', value: 0});\n }\n }\n\n // Table records need to be sorted alphabetically.\n recordFields.sort(function(r1, r2) {\n if (r1.value.tag > r2.value.tag) {\n return 1;\n } else {\n return -1;\n }\n });\n\n sfnt.fields = sfnt.fields.concat(recordFields);\n sfnt.fields = sfnt.fields.concat(tableFields);\n return sfnt;\n }\n\n // Get the metrics for a character. If the string has more than one character\n // this function returns metrics for the first available character.\n // You can provide optional fallback metrics if no characters are available.\n function metricsForChar(font, chars, notFoundMetrics) {\n for (var i = 0; i < chars.length; i += 1) {\n var glyphIndex = font.charToGlyphIndex(chars[i]);\n if (glyphIndex > 0) {\n var glyph = font.glyphs.get(glyphIndex);\n return glyph.getMetrics();\n }\n }\n\n return notFoundMetrics;\n }\n\n function average(vs) {\n var sum = 0;\n for (var i = 0; i < vs.length; i += 1) {\n sum += vs[i];\n }\n\n return sum / vs.length;\n }\n\n // Convert the font object to a SFNT data structure.\n // This structure contains all the necessary tables and metadata to create a binary OTF file.\n function fontToSfntTable(font) {\n var xMins = [];\n var yMins = [];\n var xMaxs = [];\n var yMaxs = [];\n var advanceWidths = [];\n var leftSideBearings = [];\n var rightSideBearings = [];\n var firstCharIndex;\n var lastCharIndex = 0;\n var ulUnicodeRange1 = 0;\n var ulUnicodeRange2 = 0;\n var ulUnicodeRange3 = 0;\n var ulUnicodeRange4 = 0;\n\n for (var i = 0; i < font.glyphs.length; i += 1) {\n var glyph = font.glyphs.get(i);\n var unicode = glyph.unicode | 0;\n\n if (isNaN(glyph.advanceWidth)) {\n throw new Error('Glyph ' + glyph.name + ' (' + i + '): advanceWidth is not a number.');\n }\n\n if (firstCharIndex > unicode || firstCharIndex === undefined) {\n // ignore .notdef char\n if (unicode > 0) {\n firstCharIndex = unicode;\n }\n }\n\n if (lastCharIndex < unicode) {\n lastCharIndex = unicode;\n }\n\n var position = os2.getUnicodeRange(unicode);\n if (position < 32) {\n ulUnicodeRange1 |= 1 << position;\n } else if (position < 64) {\n ulUnicodeRange2 |= 1 << position - 32;\n } else if (position < 96) {\n ulUnicodeRange3 |= 1 << position - 64;\n } else if (position < 123) {\n ulUnicodeRange4 |= 1 << position - 96;\n } else {\n throw new Error('Unicode ranges bits > 123 are reserved for internal usage');\n }\n // Skip non-important characters.\n if (glyph.name === '.notdef') { continue; }\n var metrics = glyph.getMetrics();\n xMins.push(metrics.xMin);\n yMins.push(metrics.yMin);\n xMaxs.push(metrics.xMax);\n yMaxs.push(metrics.yMax);\n leftSideBearings.push(metrics.leftSideBearing);\n rightSideBearings.push(metrics.rightSideBearing);\n advanceWidths.push(glyph.advanceWidth);\n }\n\n var globals = {\n xMin: Math.min.apply(null, xMins),\n yMin: Math.min.apply(null, yMins),\n xMax: Math.max.apply(null, xMaxs),\n yMax: Math.max.apply(null, yMaxs),\n advanceWidthMax: Math.max.apply(null, advanceWidths),\n advanceWidthAvg: average(advanceWidths),\n minLeftSideBearing: Math.min.apply(null, leftSideBearings),\n maxLeftSideBearing: Math.max.apply(null, leftSideBearings),\n minRightSideBearing: Math.min.apply(null, rightSideBearings)\n };\n globals.ascender = font.ascender;\n globals.descender = font.descender;\n\n var headTable = head.make({\n flags: 3, // 00000011 (baseline for font at y=0; left sidebearing point at x=0)\n unitsPerEm: font.unitsPerEm,\n xMin: globals.xMin,\n yMin: globals.yMin,\n xMax: globals.xMax,\n yMax: globals.yMax,\n lowestRecPPEM: 3,\n createdTimestamp: font.createdTimestamp\n });\n\n var hheaTable = hhea.make({\n ascender: globals.ascender,\n descender: globals.descender,\n advanceWidthMax: globals.advanceWidthMax,\n minLeftSideBearing: globals.minLeftSideBearing,\n minRightSideBearing: globals.minRightSideBearing,\n xMaxExtent: globals.maxLeftSideBearing + (globals.xMax - globals.xMin),\n numberOfHMetrics: font.glyphs.length\n });\n\n var maxpTable = maxp.make(font.glyphs.length);\n\n var os2Table = os2.make(Object.assign({\n xAvgCharWidth: Math.round(globals.advanceWidthAvg),\n usFirstCharIndex: firstCharIndex,\n usLastCharIndex: lastCharIndex,\n ulUnicodeRange1: ulUnicodeRange1,\n ulUnicodeRange2: ulUnicodeRange2,\n ulUnicodeRange3: ulUnicodeRange3,\n ulUnicodeRange4: ulUnicodeRange4,\n // See http://typophile.com/node/13081 for more info on vertical metrics.\n // We get metrics for typical characters (such as \"x\" for xHeight).\n // We provide some fallback characters if characters are unavailable: their\n // ordering was chosen experimentally.\n sTypoAscender: globals.ascender,\n sTypoDescender: globals.descender,\n sTypoLineGap: 0,\n usWinAscent: globals.yMax,\n usWinDescent: Math.abs(globals.yMin),\n ulCodePageRange1: 1, // FIXME: hard-code Latin 1 support for now\n sxHeight: metricsForChar(font, 'xyvw', {yMax: Math.round(globals.ascender / 2)}).yMax,\n sCapHeight: metricsForChar(font, 'HIKLEFJMNTZBDPRAGOQSUVWXY', globals).yMax,\n usDefaultChar: font.hasChar(' ') ? 32 : 0, // Use space as the default character, if available.\n usBreakChar: font.hasChar(' ') ? 32 : 0, // Use space as the break character, if available.\n }, font.tables.os2));\n\n var hmtxTable = hmtx.make(font.glyphs);\n var cmapTable = cmap.make(font.glyphs);\n\n var englishFamilyName = font.getEnglishName('fontFamily');\n var englishStyleName = font.getEnglishName('fontSubfamily');\n var englishFullName = englishFamilyName + ' ' + englishStyleName;\n var postScriptName = font.getEnglishName('postScriptName');\n if (!postScriptName) {\n postScriptName = englishFamilyName.replace(/\\s/g, '') + '-' + englishStyleName;\n }\n\n var names = {};\n for (var n in font.names) {\n names[n] = font.names[n];\n }\n\n if (!names.uniqueID) {\n names.uniqueID = {en: font.getEnglishName('manufacturer') + ':' + englishFullName};\n }\n\n if (!names.postScriptName) {\n names.postScriptName = {en: postScriptName};\n }\n\n if (!names.preferredFamily) {\n names.preferredFamily = font.names.fontFamily;\n }\n\n if (!names.preferredSubfamily) {\n names.preferredSubfamily = font.names.fontSubfamily;\n }\n\n var languageTags = [];\n var nameTable = _name.make(names, languageTags);\n var ltagTable = (languageTags.length > 0 ? ltag.make(languageTags) : undefined);\n\n var postTable = post.make();\n var cffTable = cff.make(font.glyphs, {\n version: font.getEnglishName('version'),\n fullName: englishFullName,\n familyName: englishFamilyName,\n weightName: englishStyleName,\n postScriptName: postScriptName,\n unitsPerEm: font.unitsPerEm,\n fontBBox: [0, globals.yMin, globals.ascender, globals.advanceWidthMax]\n });\n\n var metaTable = (font.metas && Object.keys(font.metas).length > 0) ? meta.make(font.metas) : undefined;\n\n // The order does not matter because makeSfntTable() will sort them.\n var tables = [headTable, hheaTable, maxpTable, os2Table, nameTable, cmapTable, postTable, cffTable, hmtxTable];\n if (ltagTable) {\n tables.push(ltagTable);\n }\n // Optional tables\n if (font.tables.gsub) {\n tables.push(gsub.make(font.tables.gsub));\n }\n if (metaTable) {\n tables.push(metaTable);\n }\n\n var sfntTable = makeSfntTable(tables);\n\n // Compute the font's checkSum and store it in head.checkSumAdjustment.\n var bytes = sfntTable.encode();\n var checkSum = computeCheckSum(bytes);\n var tableFields = sfntTable.fields;\n var checkSumAdjusted = false;\n for (var i$1 = 0; i$1 < tableFields.length; i$1 += 1) {\n if (tableFields[i$1].name === 'head table') {\n tableFields[i$1].value.checkSumAdjustment = 0xB1B0AFBA - checkSum;\n checkSumAdjusted = true;\n break;\n }\n }\n\n if (!checkSumAdjusted) {\n throw new Error('Could not find head table with checkSum to adjust.');\n }\n\n return sfntTable;\n }\n\n var sfnt = { make: makeSfntTable, fontToTable: fontToSfntTable, computeCheckSum: computeCheckSum };\n\n // The Layout object is the prototype of Substitution objects, and provides\n\n function searchTag(arr, tag) {\n /* jshint bitwise: false */\n var imin = 0;\n var imax = arr.length - 1;\n while (imin <= imax) {\n var imid = (imin + imax) >>> 1;\n var val = arr[imid].tag;\n if (val === tag) {\n return imid;\n } else if (val < tag) {\n imin = imid + 1;\n } else { imax = imid - 1; }\n }\n // Not found: return -1-insertion point\n return -imin - 1;\n }\n\n function binSearch(arr, value) {\n /* jshint bitwise: false */\n var imin = 0;\n var imax = arr.length - 1;\n while (imin <= imax) {\n var imid = (imin + imax) >>> 1;\n var val = arr[imid];\n if (val === value) {\n return imid;\n } else if (val < value) {\n imin = imid + 1;\n } else { imax = imid - 1; }\n }\n // Not found: return -1-insertion point\n return -imin - 1;\n }\n\n // binary search in a list of ranges (coverage, class definition)\n function searchRange(ranges, value) {\n // jshint bitwise: false\n var range;\n var imin = 0;\n var imax = ranges.length - 1;\n while (imin <= imax) {\n var imid = (imin + imax) >>> 1;\n range = ranges[imid];\n var start = range.start;\n if (start === value) {\n return range;\n } else if (start < value) {\n imin = imid + 1;\n } else { imax = imid - 1; }\n }\n if (imin > 0) {\n range = ranges[imin - 1];\n if (value > range.end) { return 0; }\n return range;\n }\n }\n\n /**\n * @exports opentype.Layout\n * @class\n */\n function Layout(font, tableName) {\n this.font = font;\n this.tableName = tableName;\n }\n\n Layout.prototype = {\n\n /**\n * Binary search an object by \"tag\" property\n * @instance\n * @function searchTag\n * @memberof opentype.Layout\n * @param {Array} arr\n * @param {string} tag\n * @return {number}\n */\n searchTag: searchTag,\n\n /**\n * Binary search in a list of numbers\n * @instance\n * @function binSearch\n * @memberof opentype.Layout\n * @param {Array} arr\n * @param {number} value\n * @return {number}\n */\n binSearch: binSearch,\n\n /**\n * Get or create the Layout table (GSUB, GPOS etc).\n * @param {boolean} create - Whether to create a new one.\n * @return {Object} The GSUB or GPOS table.\n */\n getTable: function(create) {\n var layout = this.font.tables[this.tableName];\n if (!layout && create) {\n layout = this.font.tables[this.tableName] = this.createDefaultTable();\n }\n return layout;\n },\n\n /**\n * Returns all scripts in the substitution table.\n * @instance\n * @return {Array}\n */\n getScriptNames: function() {\n var layout = this.getTable();\n if (!layout) { return []; }\n return layout.scripts.map(function(script) {\n return script.tag;\n });\n },\n\n /**\n * Returns the best bet for a script name.\n * Returns 'DFLT' if it exists.\n * If not, returns 'latn' if it exists.\n * If neither exist, returns undefined.\n */\n getDefaultScriptName: function() {\n var layout = this.getTable();\n if (!layout) { return; }\n var hasLatn = false;\n for (var i = 0; i < layout.scripts.length; i++) {\n var name = layout.scripts[i].tag;\n if (name === 'DFLT') { return name; }\n if (name === 'latn') { hasLatn = true; }\n }\n if (hasLatn) { return 'latn'; }\n },\n\n /**\n * Returns all LangSysRecords in the given script.\n * @instance\n * @param {string} [script='DFLT']\n * @param {boolean} create - forces the creation of this script table if it doesn't exist.\n * @return {Object} An object with tag and script properties.\n */\n getScriptTable: function(script, create) {\n var layout = this.getTable(create);\n if (layout) {\n script = script || 'DFLT';\n var scripts = layout.scripts;\n var pos = searchTag(layout.scripts, script);\n if (pos >= 0) {\n return scripts[pos].script;\n } else if (create) {\n var scr = {\n tag: script,\n script: {\n defaultLangSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: []},\n langSysRecords: []\n }\n };\n scripts.splice(-1 - pos, 0, scr);\n return scr.script;\n }\n }\n },\n\n /**\n * Returns a language system table\n * @instance\n * @param {string} [script='DFLT']\n * @param {string} [language='dlft']\n * @param {boolean} create - forces the creation of this langSysTable if it doesn't exist.\n * @return {Object}\n */\n getLangSysTable: function(script, language, create) {\n var scriptTable = this.getScriptTable(script, create);\n if (scriptTable) {\n if (!language || language === 'dflt' || language === 'DFLT') {\n return scriptTable.defaultLangSys;\n }\n var pos = searchTag(scriptTable.langSysRecords, language);\n if (pos >= 0) {\n return scriptTable.langSysRecords[pos].langSys;\n } else if (create) {\n var langSysRecord = {\n tag: language,\n langSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: []}\n };\n scriptTable.langSysRecords.splice(-1 - pos, 0, langSysRecord);\n return langSysRecord.langSys;\n }\n }\n },\n\n /**\n * Get a specific feature table.\n * @instance\n * @param {string} [script='DFLT']\n * @param {string} [language='dlft']\n * @param {string} feature - One of the codes listed at https://www.microsoft.com/typography/OTSPEC/featurelist.htm\n * @param {boolean} create - forces the creation of the feature table if it doesn't exist.\n * @return {Object}\n */\n getFeatureTable: function(script, language, feature, create) {\n var langSysTable = this.getLangSysTable(script, language, create);\n if (langSysTable) {\n var featureRecord;\n var featIndexes = langSysTable.featureIndexes;\n var allFeatures = this.font.tables[this.tableName].features;\n // The FeatureIndex array of indices is in arbitrary order,\n // even if allFeatures is sorted alphabetically by feature tag.\n for (var i = 0; i < featIndexes.length; i++) {\n featureRecord = allFeatures[featIndexes[i]];\n if (featureRecord.tag === feature) {\n return featureRecord.feature;\n }\n }\n if (create) {\n var index = allFeatures.length;\n // Automatic ordering of features would require to shift feature indexes in the script list.\n check.assert(index === 0 || feature >= allFeatures[index - 1].tag, 'Features must be added in alphabetical order.');\n featureRecord = {\n tag: feature,\n feature: { params: 0, lookupListIndexes: [] }\n };\n allFeatures.push(featureRecord);\n featIndexes.push(index);\n return featureRecord.feature;\n }\n }\n },\n\n /**\n * Get the lookup tables of a given type for a script/language/feature.\n * @instance\n * @param {string} [script='DFLT']\n * @param {string} [language='dlft']\n * @param {string} feature - 4-letter feature code\n * @param {number} lookupType - 1 to 9\n * @param {boolean} create - forces the creation of the lookup table if it doesn't exist, with no subtables.\n * @return {Object[]}\n */\n getLookupTables: function(script, language, feature, lookupType, create) {\n var featureTable = this.getFeatureTable(script, language, feature, create);\n var tables = [];\n if (featureTable) {\n var lookupTable;\n var lookupListIndexes = featureTable.lookupListIndexes;\n var allLookups = this.font.tables[this.tableName].lookups;\n // lookupListIndexes are in no particular order, so use naive search.\n for (var i = 0; i < lookupListIndexes.length; i++) {\n lookupTable = allLookups[lookupListIndexes[i]];\n if (lookupTable.lookupType === lookupType) {\n tables.push(lookupTable);\n }\n }\n if (tables.length === 0 && create) {\n lookupTable = {\n lookupType: lookupType,\n lookupFlag: 0,\n subtables: [],\n markFilteringSet: undefined\n };\n var index = allLookups.length;\n allLookups.push(lookupTable);\n lookupListIndexes.push(index);\n return [lookupTable];\n }\n }\n return tables;\n },\n\n /**\n * Find a glyph in a class definition table\n * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table\n * @param {object} classDefTable - an OpenType Layout class definition table\n * @param {number} glyphIndex - the index of the glyph to find\n * @returns {number} -1 if not found\n */\n getGlyphClass: function(classDefTable, glyphIndex) {\n switch (classDefTable.format) {\n case 1:\n if (classDefTable.startGlyph <= glyphIndex && glyphIndex < classDefTable.startGlyph + classDefTable.classes.length) {\n return classDefTable.classes[glyphIndex - classDefTable.startGlyph];\n }\n return 0;\n case 2:\n var range = searchRange(classDefTable.ranges, glyphIndex);\n return range ? range.classId : 0;\n }\n },\n\n /**\n * Find a glyph in a coverage table\n * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table\n * @param {object} coverageTable - an OpenType Layout coverage table\n * @param {number} glyphIndex - the index of the glyph to find\n * @returns {number} -1 if not found\n */\n getCoverageIndex: function(coverageTable, glyphIndex) {\n switch (coverageTable.format) {\n case 1:\n var index = binSearch(coverageTable.glyphs, glyphIndex);\n return index >= 0 ? index : -1;\n case 2:\n var range = searchRange(coverageTable.ranges, glyphIndex);\n return range ? range.index + glyphIndex - range.start : -1;\n }\n },\n\n /**\n * Returns the list of glyph indexes of a coverage table.\n * Format 1: the list is stored raw\n * Format 2: compact list as range records.\n * @instance\n * @param {Object} coverageTable\n * @return {Array}\n */\n expandCoverage: function(coverageTable) {\n if (coverageTable.format === 1) {\n return coverageTable.glyphs;\n } else {\n var glyphs = [];\n var ranges = coverageTable.ranges;\n for (var i = 0; i < ranges.length; i++) {\n var range = ranges[i];\n var start = range.start;\n var end = range.end;\n for (var j = start; j <= end; j++) {\n glyphs.push(j);\n }\n }\n return glyphs;\n }\n }\n\n };\n\n // The Position object provides utility methods to manipulate\n\n /**\n * @exports opentype.Position\n * @class\n * @extends opentype.Layout\n * @param {opentype.Font}\n * @constructor\n */\n function Position(font) {\n Layout.call(this, font, 'gpos');\n }\n\n Position.prototype = Layout.prototype;\n\n /**\n * Init some data for faster and easier access later.\n */\n Position.prototype.init = function() {\n var script = this.getDefaultScriptName();\n this.defaultKerningTables = this.getKerningTables(script);\n };\n\n /**\n * Find a glyph pair in a list of lookup tables of type 2 and retrieve the xAdvance kerning value.\n *\n * @param {integer} leftIndex - left glyph index\n * @param {integer} rightIndex - right glyph index\n * @returns {integer}\n */\n Position.prototype.getKerningValue = function(kerningLookups, leftIndex, rightIndex) {\n for (var i = 0; i < kerningLookups.length; i++) {\n var subtables = kerningLookups[i].subtables;\n for (var j = 0; j < subtables.length; j++) {\n var subtable = subtables[j];\n var covIndex = this.getCoverageIndex(subtable.coverage, leftIndex);\n if (covIndex < 0) { continue; }\n switch (subtable.posFormat) {\n case 1:\n // Search Pair Adjustment Positioning Format 1\n var pairSet = subtable.pairSets[covIndex];\n for (var k = 0; k < pairSet.length; k++) {\n var pair = pairSet[k];\n if (pair.secondGlyph === rightIndex) {\n return pair.value1 && pair.value1.xAdvance || 0;\n }\n }\n break; // left glyph found, not right glyph - try next subtable\n case 2:\n // Search Pair Adjustment Positioning Format 2\n var class1 = this.getGlyphClass(subtable.classDef1, leftIndex);\n var class2 = this.getGlyphClass(subtable.classDef2, rightIndex);\n var pair$1 = subtable.classRecords[class1][class2];\n return pair$1.value1 && pair$1.value1.xAdvance || 0;\n }\n }\n }\n return 0;\n };\n\n /**\n * List all kerning lookup tables.\n *\n * @param {string} [script='DFLT'] - use font.position.getDefaultScriptName() for a better default value\n * @param {string} [language='dflt']\n * @return {object[]} The list of kerning lookup tables (may be empty), or undefined if there is no GPOS table (and we should use the kern table)\n */\n Position.prototype.getKerningTables = function(script, language) {\n if (this.font.tables.gpos) {\n return this.getLookupTables(script, language, 'kern', 2);\n }\n };\n\n // The Substitution object provides utility methods to manipulate\n\n /**\n * @exports opentype.Substitution\n * @class\n * @extends opentype.Layout\n * @param {opentype.Font}\n * @constructor\n */\n function Substitution(font) {\n Layout.call(this, font, 'gsub');\n }\n\n // Check if 2 arrays of primitives are equal.\n function arraysEqual(ar1, ar2) {\n var n = ar1.length;\n if (n !== ar2.length) { return false; }\n for (var i = 0; i < n; i++) {\n if (ar1[i] !== ar2[i]) { return false; }\n }\n return true;\n }\n\n // Find the first subtable of a lookup table in a particular format.\n function getSubstFormat(lookupTable, format, defaultSubtable) {\n var subtables = lookupTable.subtables;\n for (var i = 0; i < subtables.length; i++) {\n var subtable = subtables[i];\n if (subtable.substFormat === format) {\n return subtable;\n }\n }\n if (defaultSubtable) {\n subtables.push(defaultSubtable);\n return defaultSubtable;\n }\n return undefined;\n }\n\n Substitution.prototype = Layout.prototype;\n\n /**\n * Create a default GSUB table.\n * @return {Object} gsub - The GSUB table.\n */\n Substitution.prototype.createDefaultTable = function() {\n // Generate a default empty GSUB table with just a DFLT script and dflt lang sys.\n return {\n version: 1,\n scripts: [{\n tag: 'DFLT',\n script: {\n defaultLangSys: { reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: [] },\n langSysRecords: []\n }\n }],\n features: [],\n lookups: []\n };\n };\n\n /**\n * List all single substitutions (lookup type 1) for a given script, language, and feature.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @param {string} feature - 4-character feature name ('aalt', 'salt', 'ss01'...)\n * @return {Array} substitutions - The list of substitutions.\n */\n Substitution.prototype.getSingle = function(feature, script, language) {\n var substitutions = [];\n var lookupTables = this.getLookupTables(script, language, feature, 1);\n for (var idx = 0; idx < lookupTables.length; idx++) {\n var subtables = lookupTables[idx].subtables;\n for (var i = 0; i < subtables.length; i++) {\n var subtable = subtables[i];\n var glyphs = this.expandCoverage(subtable.coverage);\n var j = (void 0);\n if (subtable.substFormat === 1) {\n var delta = subtable.deltaGlyphId;\n for (j = 0; j < glyphs.length; j++) {\n var glyph = glyphs[j];\n substitutions.push({ sub: glyph, by: glyph + delta });\n }\n } else {\n var substitute = subtable.substitute;\n for (j = 0; j < glyphs.length; j++) {\n substitutions.push({ sub: glyphs[j], by: substitute[j] });\n }\n }\n }\n }\n return substitutions;\n };\n\n /**\n * List all multiple substitutions (lookup type 2) for a given script, language, and feature.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @param {string} feature - 4-character feature name ('ccmp', 'stch')\n * @return {Array} substitutions - The list of substitutions.\n */\n Substitution.prototype.getMultiple = function(feature, script, language) {\n var substitutions = [];\n var lookupTables = this.getLookupTables(script, language, feature, 2);\n for (var idx = 0; idx < lookupTables.length; idx++) {\n var subtables = lookupTables[idx].subtables;\n for (var i = 0; i < subtables.length; i++) {\n var subtable = subtables[i];\n var glyphs = this.expandCoverage(subtable.coverage);\n var j = (void 0);\n\n for (j = 0; j < glyphs.length; j++) {\n var glyph = glyphs[j];\n var replacements = subtable.sequences[j];\n substitutions.push({ sub: glyph, by: replacements });\n }\n }\n }\n return substitutions;\n };\n\n /**\n * List all alternates (lookup type 3) for a given script, language, and feature.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @param {string} feature - 4-character feature name ('aalt', 'salt'...)\n * @return {Array} alternates - The list of alternates\n */\n Substitution.prototype.getAlternates = function(feature, script, language) {\n var alternates = [];\n var lookupTables = this.getLookupTables(script, language, feature, 3);\n for (var idx = 0; idx < lookupTables.length; idx++) {\n var subtables = lookupTables[idx].subtables;\n for (var i = 0; i < subtables.length; i++) {\n var subtable = subtables[i];\n var glyphs = this.expandCoverage(subtable.coverage);\n var alternateSets = subtable.alternateSets;\n for (var j = 0; j < glyphs.length; j++) {\n alternates.push({ sub: glyphs[j], by: alternateSets[j] });\n }\n }\n }\n return alternates;\n };\n\n /**\n * List all ligatures (lookup type 4) for a given script, language, and feature.\n * The result is an array of ligature objects like { sub: [ids], by: id }\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @return {Array} ligatures - The list of ligatures.\n */\n Substitution.prototype.getLigatures = function(feature, script, language) {\n var ligatures = [];\n var lookupTables = this.getLookupTables(script, language, feature, 4);\n for (var idx = 0; idx < lookupTables.length; idx++) {\n var subtables = lookupTables[idx].subtables;\n for (var i = 0; i < subtables.length; i++) {\n var subtable = subtables[i];\n var glyphs = this.expandCoverage(subtable.coverage);\n var ligatureSets = subtable.ligatureSets;\n for (var j = 0; j < glyphs.length; j++) {\n var startGlyph = glyphs[j];\n var ligSet = ligatureSets[j];\n for (var k = 0; k < ligSet.length; k++) {\n var lig = ligSet[k];\n ligatures.push({\n sub: [startGlyph].concat(lig.components),\n by: lig.ligGlyph\n });\n }\n }\n }\n }\n return ligatures;\n };\n\n /**\n * Add or modify a single substitution (lookup type 1)\n * Format 2, more flexible, is always used.\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {Object} substitution - { sub: id, by: id } (format 1 is not supported)\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\n Substitution.prototype.addSingle = function(feature, substitution, script, language) {\n var lookupTable = this.getLookupTables(script, language, feature, 1, true)[0];\n var subtable = getSubstFormat(lookupTable, 2, { // lookup type 1 subtable, format 2, coverage format 1\n substFormat: 2,\n coverage: {format: 1, glyphs: []},\n substitute: []\n });\n check.assert(subtable.coverage.format === 1, 'Single: unable to modify coverage table format ' + subtable.coverage.format);\n var coverageGlyph = substitution.sub;\n var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos < 0) {\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.substitute.splice(pos, 0, 0);\n }\n subtable.substitute[pos] = substitution.by;\n };\n\n /**\n * Add or modify a multiple substitution (lookup type 2)\n * @param {string} feature - 4-letter feature name ('ccmp', 'stch')\n * @param {Object} substitution - { sub: id, by: [id] } for format 2.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\n Substitution.prototype.addMultiple = function(feature, substitution, script, language) {\n check.assert(substitution.by instanceof Array && substitution.by.length > 1, 'Multiple: \"by\" must be an array of two or more ids');\n var lookupTable = this.getLookupTables(script, language, feature, 2, true)[0];\n var subtable = getSubstFormat(lookupTable, 1, { // lookup type 2 subtable, format 1, coverage format 1\n substFormat: 1,\n coverage: {format: 1, glyphs: []},\n sequences: []\n });\n check.assert(subtable.coverage.format === 1, 'Multiple: unable to modify coverage table format ' + subtable.coverage.format);\n var coverageGlyph = substitution.sub;\n var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos < 0) {\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.sequences.splice(pos, 0, 0);\n }\n subtable.sequences[pos] = substitution.by;\n };\n\n /**\n * Add or modify an alternate substitution (lookup type 3)\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {Object} substitution - { sub: id, by: [ids] }\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\n Substitution.prototype.addAlternate = function(feature, substitution, script, language) {\n var lookupTable = this.getLookupTables(script, language, feature, 3, true)[0];\n var subtable = getSubstFormat(lookupTable, 1, { // lookup type 3 subtable, format 1, coverage format 1\n substFormat: 1,\n coverage: {format: 1, glyphs: []},\n alternateSets: []\n });\n check.assert(subtable.coverage.format === 1, 'Alternate: unable to modify coverage table format ' + subtable.coverage.format);\n var coverageGlyph = substitution.sub;\n var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos < 0) {\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.alternateSets.splice(pos, 0, 0);\n }\n subtable.alternateSets[pos] = substitution.by;\n };\n\n /**\n * Add a ligature (lookup type 4)\n * Ligatures with more components must be stored ahead of those with fewer components in order to be found\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {Object} ligature - { sub: [ids], by: id }\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\n Substitution.prototype.addLigature = function(feature, ligature, script, language) {\n var lookupTable = this.getLookupTables(script, language, feature, 4, true)[0];\n var subtable = lookupTable.subtables[0];\n if (!subtable) {\n subtable = { // lookup type 4 subtable, format 1, coverage format 1\n substFormat: 1,\n coverage: { format: 1, glyphs: [] },\n ligatureSets: []\n };\n lookupTable.subtables[0] = subtable;\n }\n check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);\n var coverageGlyph = ligature.sub[0];\n var ligComponents = ligature.sub.slice(1);\n var ligatureTable = {\n ligGlyph: ligature.by,\n components: ligComponents\n };\n var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos >= 0) {\n // ligatureSet already exists\n var ligatureSet = subtable.ligatureSets[pos];\n for (var i = 0; i < ligatureSet.length; i++) {\n // If ligature already exists, return.\n if (arraysEqual(ligatureSet[i].components, ligComponents)) {\n return;\n }\n }\n // ligature does not exist: add it.\n ligatureSet.push(ligatureTable);\n } else {\n // Create a new ligatureSet and add coverage for the first glyph.\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.ligatureSets.splice(pos, 0, [ligatureTable]);\n }\n };\n\n /**\n * List all feature data for a given script and language.\n * @param {string} feature - 4-letter feature name\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @return {Array} substitutions - The list of substitutions.\n */\n Substitution.prototype.getFeature = function(feature, script, language) {\n if (/ss\\d\\d/.test(feature)) {\n // ss01 - ss20\n return this.getSingle(feature, script, language);\n }\n switch (feature) {\n case 'aalt':\n case 'salt':\n return this.getSingle(feature, script, language)\n .concat(this.getAlternates(feature, script, language));\n case 'dlig':\n case 'liga':\n case 'rlig':\n return this.getLigatures(feature, script, language);\n case 'ccmp':\n return this.getMultiple(feature, script, language)\n .concat(this.getLigatures(feature, script, language));\n case 'stch':\n return this.getMultiple(feature, script, language);\n }\n return undefined;\n };\n\n /**\n * Add a substitution to a feature for a given script and language.\n * @param {string} feature - 4-letter feature name\n * @param {Object} sub - the substitution to add (an object like { sub: id or [ids], by: id or [ids] })\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\n Substitution.prototype.add = function(feature, sub, script, language) {\n if (/ss\\d\\d/.test(feature)) {\n // ss01 - ss20\n return this.addSingle(feature, sub, script, language);\n }\n switch (feature) {\n case 'aalt':\n case 'salt':\n if (typeof sub.by === 'number') {\n return this.addSingle(feature, sub, script, language);\n }\n return this.addAlternate(feature, sub, script, language);\n case 'dlig':\n case 'liga':\n case 'rlig':\n return this.addLigature(feature, sub, script, language);\n case 'ccmp':\n if (sub.by instanceof Array) {\n return this.addMultiple(feature, sub, script, language);\n }\n return this.addLigature(feature, sub, script, language);\n }\n return undefined;\n };\n\n function isBrowser() {\n return typeof window !== 'undefined';\n }\n\n function arrayBufferToNodeBuffer(ab) {\n var buffer = new Buffer(ab.byteLength);\n var view = new Uint8Array(ab);\n for (var i = 0; i < buffer.length; ++i) {\n buffer[i] = view[i];\n }\n\n return buffer;\n }\n\n function checkArgument(expression, message) {\n if (!expression) {\n throw message;\n }\n }\n\n // The `glyf` table describes the glyphs in TrueType outline format.\n\n // Parse the coordinate data for a glyph.\n function parseGlyphCoordinate(p, flag, previousValue, shortVectorBitMask, sameBitMask) {\n var v;\n if ((flag & shortVectorBitMask) > 0) {\n // The coordinate is 1 byte long.\n v = p.parseByte();\n // The `same` bit is re-used for short values to signify the sign of the value.\n if ((flag & sameBitMask) === 0) {\n v = -v;\n }\n\n v = previousValue + v;\n } else {\n // The coordinate is 2 bytes long.\n // If the `same` bit is set, the coordinate is the same as the previous coordinate.\n if ((flag & sameBitMask) > 0) {\n v = previousValue;\n } else {\n // Parse the coordinate as a signed 16-bit delta value.\n v = previousValue + p.parseShort();\n }\n }\n\n return v;\n }\n\n // Parse a TrueType glyph.\n function parseGlyph(glyph, data, start) {\n var p = new parse.Parser(data, start);\n glyph.numberOfContours = p.parseShort();\n glyph._xMin = p.parseShort();\n glyph._yMin = p.parseShort();\n glyph._xMax = p.parseShort();\n glyph._yMax = p.parseShort();\n var flags;\n var flag;\n\n if (glyph.numberOfContours > 0) {\n // This glyph is not a composite.\n var endPointIndices = glyph.endPointIndices = [];\n for (var i = 0; i < glyph.numberOfContours; i += 1) {\n endPointIndices.push(p.parseUShort());\n }\n\n glyph.instructionLength = p.parseUShort();\n glyph.instructions = [];\n for (var i$1 = 0; i$1 < glyph.instructionLength; i$1 += 1) {\n glyph.instructions.push(p.parseByte());\n }\n\n var numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1;\n flags = [];\n for (var i$2 = 0; i$2 < numberOfCoordinates; i$2 += 1) {\n flag = p.parseByte();\n flags.push(flag);\n // If bit 3 is set, we repeat this flag n times, where n is the next byte.\n if ((flag & 8) > 0) {\n var repeatCount = p.parseByte();\n for (var j = 0; j < repeatCount; j += 1) {\n flags.push(flag);\n i$2 += 1;\n }\n }\n }\n\n check.argument(flags.length === numberOfCoordinates, 'Bad flags.');\n\n if (endPointIndices.length > 0) {\n var points = [];\n var point;\n // X/Y coordinates are relative to the previous point, except for the first point which is relative to 0,0.\n if (numberOfCoordinates > 0) {\n for (var i$3 = 0; i$3 < numberOfCoordinates; i$3 += 1) {\n flag = flags[i$3];\n point = {};\n point.onCurve = !!(flag & 1);\n point.lastPointOfContour = endPointIndices.indexOf(i$3) >= 0;\n points.push(point);\n }\n\n var px = 0;\n for (var i$4 = 0; i$4 < numberOfCoordinates; i$4 += 1) {\n flag = flags[i$4];\n point = points[i$4];\n point.x = parseGlyphCoordinate(p, flag, px, 2, 16);\n px = point.x;\n }\n\n var py = 0;\n for (var i$5 = 0; i$5 < numberOfCoordinates; i$5 += 1) {\n flag = flags[i$5];\n point = points[i$5];\n point.y = parseGlyphCoordinate(p, flag, py, 4, 32);\n py = point.y;\n }\n }\n\n glyph.points = points;\n } else {\n glyph.points = [];\n }\n } else if (glyph.numberOfContours === 0) {\n glyph.points = [];\n } else {\n glyph.isComposite = true;\n glyph.points = [];\n glyph.components = [];\n var moreComponents = true;\n while (moreComponents) {\n flags = p.parseUShort();\n var component = {\n glyphIndex: p.parseUShort(),\n xScale: 1,\n scale01: 0,\n scale10: 0,\n yScale: 1,\n dx: 0,\n dy: 0\n };\n if ((flags & 1) > 0) {\n // The arguments are words\n if ((flags & 2) > 0) {\n // values are offset\n component.dx = p.parseShort();\n component.dy = p.parseShort();\n } else {\n // values are matched points\n component.matchedPoints = [p.parseUShort(), p.parseUShort()];\n }\n\n } else {\n // The arguments are bytes\n if ((flags & 2) > 0) {\n // values are offset\n component.dx = p.parseChar();\n component.dy = p.parseChar();\n } else {\n // values are matched points\n component.matchedPoints = [p.parseByte(), p.parseByte()];\n }\n }\n\n if ((flags & 8) > 0) {\n // We have a scale\n component.xScale = component.yScale = p.parseF2Dot14();\n } else if ((flags & 64) > 0) {\n // We have an X / Y scale\n component.xScale = p.parseF2Dot14();\n component.yScale = p.parseF2Dot14();\n } else if ((flags & 128) > 0) {\n // We have a 2x2 transformation\n component.xScale = p.parseF2Dot14();\n component.scale01 = p.parseF2Dot14();\n component.scale10 = p.parseF2Dot14();\n component.yScale = p.parseF2Dot14();\n }\n\n glyph.components.push(component);\n moreComponents = !!(flags & 32);\n }\n if (flags & 0x100) {\n // We have instructions\n glyph.instructionLength = p.parseUShort();\n glyph.instructions = [];\n for (var i$6 = 0; i$6 < glyph.instructionLength; i$6 += 1) {\n glyph.instructions.push(p.parseByte());\n }\n }\n }\n }\n\n // Transform an array of points and return a new array.\n function transformPoints(points, transform) {\n var newPoints = [];\n for (var i = 0; i < points.length; i += 1) {\n var pt = points[i];\n var newPt = {\n x: transform.xScale * pt.x + transform.scale01 * pt.y + transform.dx,\n y: transform.scale10 * pt.x + transform.yScale * pt.y + transform.dy,\n onCurve: pt.onCurve,\n lastPointOfContour: pt.lastPointOfContour\n };\n newPoints.push(newPt);\n }\n\n return newPoints;\n }\n\n function getContours(points) {\n var contours = [];\n var currentContour = [];\n for (var i = 0; i < points.length; i += 1) {\n var pt = points[i];\n currentContour.push(pt);\n if (pt.lastPointOfContour) {\n contours.push(currentContour);\n currentContour = [];\n }\n }\n\n check.argument(currentContour.length === 0, 'There are still points left in the current contour.');\n return contours;\n }\n\n // Convert the TrueType glyph outline to a Path.\n function getPath(points) {\n var p = new Path();\n if (!points) {\n return p;\n }\n\n var contours = getContours(points);\n\n for (var contourIndex = 0; contourIndex < contours.length; ++contourIndex) {\n var contour = contours[contourIndex];\n\n var prev = null;\n var curr = contour[contour.length - 1];\n var next = contour[0];\n\n if (curr.onCurve) {\n p.moveTo(curr.x, curr.y);\n } else {\n if (next.onCurve) {\n p.moveTo(next.x, next.y);\n } else {\n // If both first and last points are off-curve, start at their middle.\n var start = {x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5};\n p.moveTo(start.x, start.y);\n }\n }\n\n for (var i = 0; i < contour.length; ++i) {\n prev = curr;\n curr = next;\n next = contour[(i + 1) % contour.length];\n\n if (curr.onCurve) {\n // This is a straight line.\n p.lineTo(curr.x, curr.y);\n } else {\n var prev2 = prev;\n var next2 = next;\n\n if (!prev.onCurve) {\n prev2 = { x: (curr.x + prev.x) * 0.5, y: (curr.y + prev.y) * 0.5 };\n }\n\n if (!next.onCurve) {\n next2 = { x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5 };\n }\n\n p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y);\n }\n }\n\n p.closePath();\n }\n return p;\n }\n\n function buildPath(glyphs, glyph) {\n if (glyph.isComposite) {\n for (var j = 0; j < glyph.components.length; j += 1) {\n var component = glyph.components[j];\n var componentGlyph = glyphs.get(component.glyphIndex);\n // Force the ttfGlyphLoader to parse the glyph.\n componentGlyph.getPath();\n if (componentGlyph.points) {\n var transformedPoints = (void 0);\n if (component.matchedPoints === undefined) {\n // component positioned by offset\n transformedPoints = transformPoints(componentGlyph.points, component);\n } else {\n // component positioned by matched points\n if ((component.matchedPoints[0] > glyph.points.length - 1) ||\n (component.matchedPoints[1] > componentGlyph.points.length - 1)) {\n throw Error('Matched points out of range in ' + glyph.name);\n }\n var firstPt = glyph.points[component.matchedPoints[0]];\n var secondPt = componentGlyph.points[component.matchedPoints[1]];\n var transform = {\n xScale: component.xScale, scale01: component.scale01,\n scale10: component.scale10, yScale: component.yScale,\n dx: 0, dy: 0\n };\n secondPt = transformPoints([secondPt], transform)[0];\n transform.dx = firstPt.x - secondPt.x;\n transform.dy = firstPt.y - secondPt.y;\n transformedPoints = transformPoints(componentGlyph.points, transform);\n }\n glyph.points = glyph.points.concat(transformedPoints);\n }\n }\n }\n\n return getPath(glyph.points);\n }\n\n function parseGlyfTableAll(data, start, loca, font) {\n var glyphs = new glyphset.GlyphSet(font);\n\n // The last element of the loca table is invalid.\n for (var i = 0; i < loca.length - 1; i += 1) {\n var offset = loca[i];\n var nextOffset = loca[i + 1];\n if (offset !== nextOffset) {\n glyphs.push(i, glyphset.ttfGlyphLoader(font, i, parseGlyph, data, start + offset, buildPath));\n } else {\n glyphs.push(i, glyphset.glyphLoader(font, i));\n }\n }\n\n return glyphs;\n }\n\n function parseGlyfTableOnLowMemory(data, start, loca, font) {\n var glyphs = new glyphset.GlyphSet(font);\n\n font._push = function(i) {\n var offset = loca[i];\n var nextOffset = loca[i + 1];\n if (offset !== nextOffset) {\n glyphs.push(i, glyphset.ttfGlyphLoader(font, i, parseGlyph, data, start + offset, buildPath));\n } else {\n glyphs.push(i, glyphset.glyphLoader(font, i));\n }\n };\n\n return glyphs;\n }\n\n // Parse all the glyphs according to the offsets from the `loca` table.\n function parseGlyfTable(data, start, loca, font, opt) {\n if (opt.lowMemory)\n { return parseGlyfTableOnLowMemory(data, start, loca, font); }\n else\n { return parseGlyfTableAll(data, start, loca, font); }\n }\n\n var glyf = { getPath: getPath, parse: parseGlyfTable};\n\n /* A TrueType font hinting interpreter.\n *\n * (c) 2017 Axel Kittenberger\n *\n * This interpreter has been implemented according to this documentation:\n * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html\n *\n * According to the documentation F24DOT6 values are used for pixels.\n * That means calculation is 1/64 pixel accurate and uses integer operations.\n * However, Javascript has floating point operations by default and only\n * those are available. One could make a case to simulate the 1/64 accuracy\n * exactly by truncating after every division operation\n * (for example with << 0) to get pixel exactly results as other TrueType\n * implementations. It may make sense since some fonts are pixel optimized\n * by hand using DELTAP instructions. The current implementation doesn't\n * and rather uses full floating point precision.\n *\n * xScale, yScale and rotation is currently ignored.\n *\n * A few non-trivial instructions are missing as I didn't encounter yet\n * a font that used them to test a possible implementation.\n *\n * Some fonts seem to use undocumented features regarding the twilight zone.\n * Only some of them are implemented as they were encountered.\n *\n * The exports.DEBUG statements are removed on the minified distribution file.\n */\n\n var instructionTable;\n var exec;\n var execGlyph;\n var execComponent;\n\n /*\n * Creates a hinting object.\n *\n * There ought to be exactly one\n * for each truetype font that is used for hinting.\n */\n function Hinting(font) {\n // the font this hinting object is for\n this.font = font;\n\n this.getCommands = function (hPoints) {\n return glyf.getPath(hPoints).commands;\n };\n\n // cached states\n this._fpgmState =\n this._prepState =\n undefined;\n\n // errorState\n // 0 ... all okay\n // 1 ... had an error in a glyf,\n // continue working but stop spamming\n // the console\n // 2 ... error at prep, stop hinting at this ppem\n // 3 ... error at fpeg, stop hinting for this font at all\n this._errorState = 0;\n }\n\n /*\n * Not rounding.\n */\n function roundOff(v) {\n return v;\n }\n\n /*\n * Rounding to grid.\n */\n function roundToGrid(v) {\n //Rounding in TT is supposed to \"symmetrical around zero\"\n return Math.sign(v) * Math.round(Math.abs(v));\n }\n\n /*\n * Rounding to double grid.\n */\n function roundToDoubleGrid(v) {\n return Math.sign(v) * Math.round(Math.abs(v * 2)) / 2;\n }\n\n /*\n * Rounding to half grid.\n */\n function roundToHalfGrid(v) {\n return Math.sign(v) * (Math.round(Math.abs(v) + 0.5) - 0.5);\n }\n\n /*\n * Rounding to up to grid.\n */\n function roundUpToGrid(v) {\n return Math.sign(v) * Math.ceil(Math.abs(v));\n }\n\n /*\n * Rounding to down to grid.\n */\n function roundDownToGrid(v) {\n return Math.sign(v) * Math.floor(Math.abs(v));\n }\n\n /*\n * Super rounding.\n */\n var roundSuper = function (v) {\n var period = this.srPeriod;\n var phase = this.srPhase;\n var threshold = this.srThreshold;\n var sign = 1;\n\n if (v < 0) {\n v = -v;\n sign = -1;\n }\n\n v += threshold - phase;\n\n v = Math.trunc(v / period) * period;\n\n v += phase;\n\n // according to http://xgridfit.sourceforge.net/round.html\n if (v < 0) { return phase * sign; }\n\n return v * sign;\n };\n\n /*\n * Unit vector of x-axis.\n */\n var xUnitVector = {\n x: 1,\n\n y: 0,\n\n axis: 'x',\n\n // Gets the projected distance between two points.\n // o1/o2 ... if true, respective original position is used.\n distance: function (p1, p2, o1, o2) {\n return (o1 ? p1.xo : p1.x) - (o2 ? p2.xo : p2.x);\n },\n\n // Moves point p so the moved position has the same relative\n // position to the moved positions of rp1 and rp2 than the\n // original positions had.\n //\n // See APPENDIX on INTERPOLATE at the bottom of this file.\n interpolate: function (p, rp1, rp2, pv) {\n var do1;\n var do2;\n var doa1;\n var doa2;\n var dm1;\n var dm2;\n var dt;\n\n if (!pv || pv === this) {\n do1 = p.xo - rp1.xo;\n do2 = p.xo - rp2.xo;\n dm1 = rp1.x - rp1.xo;\n dm2 = rp2.x - rp2.xo;\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n p.x = p.xo + (dm1 + dm2) / 2;\n return;\n }\n\n p.x = p.xo + (dm1 * doa2 + dm2 * doa1) / dt;\n return;\n }\n\n do1 = pv.distance(p, rp1, true, true);\n do2 = pv.distance(p, rp2, true, true);\n dm1 = pv.distance(rp1, rp1, false, true);\n dm2 = pv.distance(rp2, rp2, false, true);\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n xUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true);\n return;\n }\n\n xUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);\n },\n\n // Slope of line normal to this\n normalSlope: Number.NEGATIVE_INFINITY,\n\n // Sets the point 'p' relative to point 'rp'\n // by the distance 'd'.\n //\n // See APPENDIX on SETRELATIVE at the bottom of this file.\n //\n // p ... point to set\n // rp ... reference point\n // d ... distance on projection vector\n // pv ... projection vector (undefined = this)\n // org ... if true, uses the original position of rp as reference.\n setRelative: function (p, rp, d, pv, org) {\n if (!pv || pv === this) {\n p.x = (org ? rp.xo : rp.x) + d;\n return;\n }\n\n var rpx = org ? rp.xo : rp.x;\n var rpy = org ? rp.yo : rp.y;\n var rpdx = rpx + d * pv.x;\n var rpdy = rpy + d * pv.y;\n\n p.x = rpdx + (p.y - rpdy) / pv.normalSlope;\n },\n\n // Slope of vector line.\n slope: 0,\n\n // Touches the point p.\n touch: function (p) {\n p.xTouched = true;\n },\n\n // Tests if a point p is touched.\n touched: function (p) {\n return p.xTouched;\n },\n\n // Untouches the point p.\n untouch: function (p) {\n p.xTouched = false;\n }\n };\n\n /*\n * Unit vector of y-axis.\n */\n var yUnitVector = {\n x: 0,\n\n y: 1,\n\n axis: 'y',\n\n // Gets the projected distance between two points.\n // o1/o2 ... if true, respective original position is used.\n distance: function (p1, p2, o1, o2) {\n return (o1 ? p1.yo : p1.y) - (o2 ? p2.yo : p2.y);\n },\n\n // Moves point p so the moved position has the same relative\n // position to the moved positions of rp1 and rp2 than the\n // original positions had.\n //\n // See APPENDIX on INTERPOLATE at the bottom of this file.\n interpolate: function (p, rp1, rp2, pv) {\n var do1;\n var do2;\n var doa1;\n var doa2;\n var dm1;\n var dm2;\n var dt;\n\n if (!pv || pv === this) {\n do1 = p.yo - rp1.yo;\n do2 = p.yo - rp2.yo;\n dm1 = rp1.y - rp1.yo;\n dm2 = rp2.y - rp2.yo;\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n p.y = p.yo + (dm1 + dm2) / 2;\n return;\n }\n\n p.y = p.yo + (dm1 * doa2 + dm2 * doa1) / dt;\n return;\n }\n\n do1 = pv.distance(p, rp1, true, true);\n do2 = pv.distance(p, rp2, true, true);\n dm1 = pv.distance(rp1, rp1, false, true);\n dm2 = pv.distance(rp2, rp2, false, true);\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n yUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true);\n return;\n }\n\n yUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);\n },\n\n // Slope of line normal to this.\n normalSlope: 0,\n\n // Sets the point 'p' relative to point 'rp'\n // by the distance 'd'\n //\n // See APPENDIX on SETRELATIVE at the bottom of this file.\n //\n // p ... point to set\n // rp ... reference point\n // d ... distance on projection vector\n // pv ... projection vector (undefined = this)\n // org ... if true, uses the original position of rp as reference.\n setRelative: function (p, rp, d, pv, org) {\n if (!pv || pv === this) {\n p.y = (org ? rp.yo : rp.y) + d;\n return;\n }\n\n var rpx = org ? rp.xo : rp.x;\n var rpy = org ? rp.yo : rp.y;\n var rpdx = rpx + d * pv.x;\n var rpdy = rpy + d * pv.y;\n\n p.y = rpdy + pv.normalSlope * (p.x - rpdx);\n },\n\n // Slope of vector line.\n slope: Number.POSITIVE_INFINITY,\n\n // Touches the point p.\n touch: function (p) {\n p.yTouched = true;\n },\n\n // Tests if a point p is touched.\n touched: function (p) {\n return p.yTouched;\n },\n\n // Untouches the point p.\n untouch: function (p) {\n p.yTouched = false;\n }\n };\n\n Object.freeze(xUnitVector);\n Object.freeze(yUnitVector);\n\n /*\n * Creates a unit vector that is not x- or y-axis.\n */\n function UnitVector(x, y) {\n this.x = x;\n this.y = y;\n this.axis = undefined;\n this.slope = y / x;\n this.normalSlope = -x / y;\n Object.freeze(this);\n }\n\n /*\n * Gets the projected distance between two points.\n * o1/o2 ... if true, respective original position is used.\n */\n UnitVector.prototype.distance = function(p1, p2, o1, o2) {\n return (\n this.x * xUnitVector.distance(p1, p2, o1, o2) +\n this.y * yUnitVector.distance(p1, p2, o1, o2)\n );\n };\n\n /*\n * Moves point p so the moved position has the same relative\n * position to the moved positions of rp1 and rp2 than the\n * original positions had.\n *\n * See APPENDIX on INTERPOLATE at the bottom of this file.\n */\n UnitVector.prototype.interpolate = function(p, rp1, rp2, pv) {\n var dm1;\n var dm2;\n var do1;\n var do2;\n var doa1;\n var doa2;\n var dt;\n\n do1 = pv.distance(p, rp1, true, true);\n do2 = pv.distance(p, rp2, true, true);\n dm1 = pv.distance(rp1, rp1, false, true);\n dm2 = pv.distance(rp2, rp2, false, true);\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n this.setRelative(p, p, (dm1 + dm2) / 2, pv, true);\n return;\n }\n\n this.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);\n };\n\n /*\n * Sets the point 'p' relative to point 'rp'\n * by the distance 'd'\n *\n * See APPENDIX on SETRELATIVE at the bottom of this file.\n *\n * p ... point to set\n * rp ... reference point\n * d ... distance on projection vector\n * pv ... projection vector (undefined = this)\n * org ... if true, uses the original position of rp as reference.\n */\n UnitVector.prototype.setRelative = function(p, rp, d, pv, org) {\n pv = pv || this;\n\n var rpx = org ? rp.xo : rp.x;\n var rpy = org ? rp.yo : rp.y;\n var rpdx = rpx + d * pv.x;\n var rpdy = rpy + d * pv.y;\n\n var pvns = pv.normalSlope;\n var fvs = this.slope;\n\n var px = p.x;\n var py = p.y;\n\n p.x = (fvs * px - pvns * rpdx + rpdy - py) / (fvs - pvns);\n p.y = fvs * (p.x - px) + py;\n };\n\n /*\n * Touches the point p.\n */\n UnitVector.prototype.touch = function(p) {\n p.xTouched = true;\n p.yTouched = true;\n };\n\n /*\n * Returns a unit vector with x/y coordinates.\n */\n function getUnitVector(x, y) {\n var d = Math.sqrt(x * x + y * y);\n\n x /= d;\n y /= d;\n\n if (x === 1 && y === 0) { return xUnitVector; }\n else if (x === 0 && y === 1) { return yUnitVector; }\n else { return new UnitVector(x, y); }\n }\n\n /*\n * Creates a point in the hinting engine.\n */\n function HPoint(\n x,\n y,\n lastPointOfContour,\n onCurve\n ) {\n this.x = this.xo = Math.round(x * 64) / 64; // hinted x value and original x-value\n this.y = this.yo = Math.round(y * 64) / 64; // hinted y value and original y-value\n\n this.lastPointOfContour = lastPointOfContour;\n this.onCurve = onCurve;\n this.prevPointOnContour = undefined;\n this.nextPointOnContour = undefined;\n this.xTouched = false;\n this.yTouched = false;\n\n Object.preventExtensions(this);\n }\n\n /*\n * Returns the next touched point on the contour.\n *\n * v ... unit vector to test touch axis.\n */\n HPoint.prototype.nextTouched = function(v) {\n var p = this.nextPointOnContour;\n\n while (!v.touched(p) && p !== this) { p = p.nextPointOnContour; }\n\n return p;\n };\n\n /*\n * Returns the previous touched point on the contour\n *\n * v ... unit vector to test touch axis.\n */\n HPoint.prototype.prevTouched = function(v) {\n var p = this.prevPointOnContour;\n\n while (!v.touched(p) && p !== this) { p = p.prevPointOnContour; }\n\n return p;\n };\n\n /*\n * The zero point.\n */\n var HPZero = Object.freeze(new HPoint(0, 0));\n\n /*\n * The default state of the interpreter.\n *\n * Note: Freezing the defaultState and then deriving from it\n * makes the V8 Javascript engine going awkward,\n * so this is avoided, albeit the defaultState shouldn't\n * ever change.\n */\n var defaultState = {\n cvCutIn: 17 / 16, // control value cut in\n deltaBase: 9,\n deltaShift: 0.125,\n loop: 1, // loops some instructions\n minDis: 1, // minimum distance\n autoFlip: true\n };\n\n /*\n * The current state of the interpreter.\n *\n * env ... 'fpgm' or 'prep' or 'glyf'\n * prog ... the program\n */\n function State(env, prog) {\n this.env = env;\n this.stack = [];\n this.prog = prog;\n\n switch (env) {\n case 'glyf' :\n this.zp0 = this.zp1 = this.zp2 = 1;\n this.rp0 = this.rp1 = this.rp2 = 0;\n /* fall through */\n case 'prep' :\n this.fv = this.pv = this.dpv = xUnitVector;\n this.round = roundToGrid;\n }\n }\n\n /*\n * Executes a glyph program.\n *\n * This does the hinting for each glyph.\n *\n * Returns an array of moved points.\n *\n * glyph: the glyph to hint\n * ppem: the size the glyph is rendered for\n */\n Hinting.prototype.exec = function(glyph, ppem) {\n if (typeof ppem !== 'number') {\n throw new Error('Point size is not a number!');\n }\n\n // Received a fatal error, don't do any hinting anymore.\n if (this._errorState > 2) { return; }\n\n var font = this.font;\n var prepState = this._prepState;\n\n if (!prepState || prepState.ppem !== ppem) {\n var fpgmState = this._fpgmState;\n\n if (!fpgmState) {\n // Executes the fpgm state.\n // This is used by fonts to define functions.\n State.prototype = defaultState;\n\n fpgmState =\n this._fpgmState =\n new State('fpgm', font.tables.fpgm);\n\n fpgmState.funcs = [ ];\n fpgmState.font = font;\n\n if (exports.DEBUG) {\n console.log('---EXEC FPGM---');\n fpgmState.step = -1;\n }\n\n try {\n exec(fpgmState);\n } catch (e) {\n console.log('Hinting error in FPGM:' + e);\n this._errorState = 3;\n return;\n }\n }\n\n // Executes the prep program for this ppem setting.\n // This is used by fonts to set cvt values\n // depending on to be rendered font size.\n\n State.prototype = fpgmState;\n prepState =\n this._prepState =\n new State('prep', font.tables.prep);\n\n prepState.ppem = ppem;\n\n // Creates a copy of the cvt table\n // and scales it to the current ppem setting.\n var oCvt = font.tables.cvt;\n if (oCvt) {\n var cvt = prepState.cvt = new Array(oCvt.length);\n var scale = ppem / font.unitsPerEm;\n for (var c = 0; c < oCvt.length; c++) {\n cvt[c] = oCvt[c] * scale;\n }\n } else {\n prepState.cvt = [];\n }\n\n if (exports.DEBUG) {\n console.log('---EXEC PREP---');\n prepState.step = -1;\n }\n\n try {\n exec(prepState);\n } catch (e) {\n if (this._errorState < 2) {\n console.log('Hinting error in PREP:' + e);\n }\n this._errorState = 2;\n }\n }\n\n if (this._errorState > 1) { return; }\n\n try {\n return execGlyph(glyph, prepState);\n } catch (e) {\n if (this._errorState < 1) {\n console.log('Hinting error:' + e);\n console.log('Note: further hinting errors are silenced');\n }\n this._errorState = 1;\n return undefined;\n }\n };\n\n /*\n * Executes the hinting program for a glyph.\n */\n execGlyph = function(glyph, prepState) {\n // original point positions\n var xScale = prepState.ppem / prepState.font.unitsPerEm;\n var yScale = xScale;\n var components = glyph.components;\n var contours;\n var gZone;\n var state;\n\n State.prototype = prepState;\n if (!components) {\n state = new State('glyf', glyph.instructions);\n if (exports.DEBUG) {\n console.log('---EXEC GLYPH---');\n state.step = -1;\n }\n execComponent(glyph, state, xScale, yScale);\n gZone = state.gZone;\n } else {\n var font = prepState.font;\n gZone = [];\n contours = [];\n for (var i = 0; i < components.length; i++) {\n var c = components[i];\n var cg = font.glyphs.get(c.glyphIndex);\n\n state = new State('glyf', cg.instructions);\n\n if (exports.DEBUG) {\n console.log('---EXEC COMP ' + i + '---');\n state.step = -1;\n }\n\n execComponent(cg, state, xScale, yScale);\n // appends the computed points to the result array\n // post processes the component points\n var dx = Math.round(c.dx * xScale);\n var dy = Math.round(c.dy * yScale);\n var gz = state.gZone;\n var cc = state.contours;\n for (var pi = 0; pi < gz.length; pi++) {\n var p = gz[pi];\n p.xTouched = p.yTouched = false;\n p.xo = p.x = p.x + dx;\n p.yo = p.y = p.y + dy;\n }\n\n var gLen = gZone.length;\n gZone.push.apply(gZone, gz);\n for (var j = 0; j < cc.length; j++) {\n contours.push(cc[j] + gLen);\n }\n }\n\n if (glyph.instructions && !state.inhibitGridFit) {\n // the composite has instructions on its own\n state = new State('glyf', glyph.instructions);\n\n state.gZone = state.z0 = state.z1 = state.z2 = gZone;\n\n state.contours = contours;\n\n // note: HPZero cannot be used here, since\n // the point might be modified\n gZone.push(\n new HPoint(0, 0),\n new HPoint(Math.round(glyph.advanceWidth * xScale), 0)\n );\n\n if (exports.DEBUG) {\n console.log('---EXEC COMPOSITE---');\n state.step = -1;\n }\n\n exec(state);\n\n gZone.length -= 2;\n }\n }\n\n return gZone;\n };\n\n /*\n * Executes the hinting program for a component of a multi-component glyph\n * or of the glyph itself for a non-component glyph.\n */\n execComponent = function(glyph, state, xScale, yScale)\n {\n var points = glyph.points || [];\n var pLen = points.length;\n var gZone = state.gZone = state.z0 = state.z1 = state.z2 = [];\n var contours = state.contours = [];\n\n // Scales the original points and\n // makes copies for the hinted points.\n var cp; // current point\n for (var i = 0; i < pLen; i++) {\n cp = points[i];\n\n gZone[i] = new HPoint(\n cp.x * xScale,\n cp.y * yScale,\n cp.lastPointOfContour,\n cp.onCurve\n );\n }\n\n // Chain links the contours.\n var sp; // start point\n var np; // next point\n\n for (var i$1 = 0; i$1 < pLen; i$1++) {\n cp = gZone[i$1];\n\n if (!sp) {\n sp = cp;\n contours.push(i$1);\n }\n\n if (cp.lastPointOfContour) {\n cp.nextPointOnContour = sp;\n sp.prevPointOnContour = cp;\n sp = undefined;\n } else {\n np = gZone[i$1 + 1];\n cp.nextPointOnContour = np;\n np.prevPointOnContour = cp;\n }\n }\n\n if (state.inhibitGridFit) { return; }\n\n if (exports.DEBUG) {\n console.log('PROCESSING GLYPH', state.stack);\n for (var i$2 = 0; i$2 < pLen; i$2++) {\n console.log(i$2, gZone[i$2].x, gZone[i$2].y);\n }\n }\n\n gZone.push(\n new HPoint(0, 0),\n new HPoint(Math.round(glyph.advanceWidth * xScale), 0)\n );\n\n exec(state);\n\n // Removes the extra points.\n gZone.length -= 2;\n\n if (exports.DEBUG) {\n console.log('FINISHED GLYPH', state.stack);\n for (var i$3 = 0; i$3 < pLen; i$3++) {\n console.log(i$3, gZone[i$3].x, gZone[i$3].y);\n }\n }\n };\n\n /*\n * Executes the program loaded in state.\n */\n exec = function(state) {\n var prog = state.prog;\n\n if (!prog) { return; }\n\n var pLen = prog.length;\n var ins;\n\n for (state.ip = 0; state.ip < pLen; state.ip++) {\n if (exports.DEBUG) { state.step++; }\n ins = instructionTable[prog[state.ip]];\n\n if (!ins) {\n throw new Error(\n 'unknown instruction: 0x' +\n Number(prog[state.ip]).toString(16)\n );\n }\n\n ins(state);\n\n // very extensive debugging for each step\n /*\n if (exports.DEBUG) {\n var da;\n if (state.gZone) {\n da = [];\n for (let i = 0; i < state.gZone.length; i++)\n {\n da.push(i + ' ' +\n state.gZone[i].x * 64 + ' ' +\n state.gZone[i].y * 64 + ' ' +\n (state.gZone[i].xTouched ? 'x' : '') +\n (state.gZone[i].yTouched ? 'y' : '')\n );\n }\n console.log('GZ', da);\n }\n\n if (state.tZone) {\n da = [];\n for (let i = 0; i < state.tZone.length; i++) {\n da.push(i + ' ' +\n state.tZone[i].x * 64 + ' ' +\n state.tZone[i].y * 64 + ' ' +\n (state.tZone[i].xTouched ? 'x' : '') +\n (state.tZone[i].yTouched ? 'y' : '')\n );\n }\n console.log('TZ', da);\n }\n\n if (state.stack.length > 10) {\n console.log(\n state.stack.length,\n '...', state.stack.slice(state.stack.length - 10)\n );\n } else {\n console.log(state.stack.length, state.stack);\n }\n }\n */\n }\n };\n\n /*\n * Initializes the twilight zone.\n *\n * This is only done if a SZPx instruction\n * refers to the twilight zone.\n */\n function initTZone(state)\n {\n var tZone = state.tZone = new Array(state.gZone.length);\n\n // no idea if this is actually correct...\n for (var i = 0; i < tZone.length; i++)\n {\n tZone[i] = new HPoint(0, 0);\n }\n }\n\n /*\n * Skips the instruction pointer ahead over an IF/ELSE block.\n * handleElse .. if true breaks on matching ELSE\n */\n function skip(state, handleElse)\n {\n var prog = state.prog;\n var ip = state.ip;\n var nesting = 1;\n var ins;\n\n do {\n ins = prog[++ip];\n if (ins === 0x58) // IF\n { nesting++; }\n else if (ins === 0x59) // EIF\n { nesting--; }\n else if (ins === 0x40) // NPUSHB\n { ip += prog[ip + 1] + 1; }\n else if (ins === 0x41) // NPUSHW\n { ip += 2 * prog[ip + 1] + 1; }\n else if (ins >= 0xB0 && ins <= 0xB7) // PUSHB\n { ip += ins - 0xB0 + 1; }\n else if (ins >= 0xB8 && ins <= 0xBF) // PUSHW\n { ip += (ins - 0xB8 + 1) * 2; }\n else if (handleElse && nesting === 1 && ins === 0x1B) // ELSE\n { break; }\n } while (nesting > 0);\n\n state.ip = ip;\n }\n\n /*----------------------------------------------------------*\n * And then a lot of instructions... *\n *----------------------------------------------------------*/\n\n // SVTCA[a] Set freedom and projection Vectors To Coordinate Axis\n // 0x00-0x01\n function SVTCA(v, state) {\n if (exports.DEBUG) { console.log(state.step, 'SVTCA[' + v.axis + ']'); }\n\n state.fv = state.pv = state.dpv = v;\n }\n\n // SPVTCA[a] Set Projection Vector to Coordinate Axis\n // 0x02-0x03\n function SPVTCA(v, state) {\n if (exports.DEBUG) { console.log(state.step, 'SPVTCA[' + v.axis + ']'); }\n\n state.pv = state.dpv = v;\n }\n\n // SFVTCA[a] Set Freedom Vector to Coordinate Axis\n // 0x04-0x05\n function SFVTCA(v, state) {\n if (exports.DEBUG) { console.log(state.step, 'SFVTCA[' + v.axis + ']'); }\n\n state.fv = v;\n }\n\n // SPVTL[a] Set Projection Vector To Line\n // 0x06-0x07\n function SPVTL(a, state) {\n var stack = state.stack;\n var p2i = stack.pop();\n var p1i = stack.pop();\n var p2 = state.z2[p2i];\n var p1 = state.z1[p1i];\n\n if (exports.DEBUG) { console.log('SPVTL[' + a + ']', p2i, p1i); }\n\n var dx;\n var dy;\n\n if (!a) {\n dx = p1.x - p2.x;\n dy = p1.y - p2.y;\n } else {\n dx = p2.y - p1.y;\n dy = p1.x - p2.x;\n }\n\n state.pv = state.dpv = getUnitVector(dx, dy);\n }\n\n // SFVTL[a] Set Freedom Vector To Line\n // 0x08-0x09\n function SFVTL(a, state) {\n var stack = state.stack;\n var p2i = stack.pop();\n var p1i = stack.pop();\n var p2 = state.z2[p2i];\n var p1 = state.z1[p1i];\n\n if (exports.DEBUG) { console.log('SFVTL[' + a + ']', p2i, p1i); }\n\n var dx;\n var dy;\n\n if (!a) {\n dx = p1.x - p2.x;\n dy = p1.y - p2.y;\n } else {\n dx = p2.y - p1.y;\n dy = p1.x - p2.x;\n }\n\n state.fv = getUnitVector(dx, dy);\n }\n\n // SPVFS[] Set Projection Vector From Stack\n // 0x0A\n function SPVFS(state) {\n var stack = state.stack;\n var y = stack.pop();\n var x = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SPVFS[]', y, x); }\n\n state.pv = state.dpv = getUnitVector(x, y);\n }\n\n // SFVFS[] Set Freedom Vector From Stack\n // 0x0B\n function SFVFS(state) {\n var stack = state.stack;\n var y = stack.pop();\n var x = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SPVFS[]', y, x); }\n\n state.fv = getUnitVector(x, y);\n }\n\n // GPV[] Get Projection Vector\n // 0x0C\n function GPV(state) {\n var stack = state.stack;\n var pv = state.pv;\n\n if (exports.DEBUG) { console.log(state.step, 'GPV[]'); }\n\n stack.push(pv.x * 0x4000);\n stack.push(pv.y * 0x4000);\n }\n\n // GFV[] Get Freedom Vector\n // 0x0C\n function GFV(state) {\n var stack = state.stack;\n var fv = state.fv;\n\n if (exports.DEBUG) { console.log(state.step, 'GFV[]'); }\n\n stack.push(fv.x * 0x4000);\n stack.push(fv.y * 0x4000);\n }\n\n // SFVTPV[] Set Freedom Vector To Projection Vector\n // 0x0E\n function SFVTPV(state) {\n state.fv = state.pv;\n\n if (exports.DEBUG) { console.log(state.step, 'SFVTPV[]'); }\n }\n\n // ISECT[] moves point p to the InterSECTion of two lines\n // 0x0F\n function ISECT(state)\n {\n var stack = state.stack;\n var pa0i = stack.pop();\n var pa1i = stack.pop();\n var pb0i = stack.pop();\n var pb1i = stack.pop();\n var pi = stack.pop();\n var z0 = state.z0;\n var z1 = state.z1;\n var pa0 = z0[pa0i];\n var pa1 = z0[pa1i];\n var pb0 = z1[pb0i];\n var pb1 = z1[pb1i];\n var p = state.z2[pi];\n\n if (exports.DEBUG) { console.log('ISECT[], ', pa0i, pa1i, pb0i, pb1i, pi); }\n\n // math from\n // en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line\n\n var x1 = pa0.x;\n var y1 = pa0.y;\n var x2 = pa1.x;\n var y2 = pa1.y;\n var x3 = pb0.x;\n var y3 = pb0.y;\n var x4 = pb1.x;\n var y4 = pb1.y;\n\n var div = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);\n var f1 = x1 * y2 - y1 * x2;\n var f2 = x3 * y4 - y3 * x4;\n\n p.x = (f1 * (x3 - x4) - f2 * (x1 - x2)) / div;\n p.y = (f1 * (y3 - y4) - f2 * (y1 - y2)) / div;\n }\n\n // SRP0[] Set Reference Point 0\n // 0x10\n function SRP0(state) {\n state.rp0 = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SRP0[]', state.rp0); }\n }\n\n // SRP1[] Set Reference Point 1\n // 0x11\n function SRP1(state) {\n state.rp1 = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SRP1[]', state.rp1); }\n }\n\n // SRP1[] Set Reference Point 2\n // 0x12\n function SRP2(state) {\n state.rp2 = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SRP2[]', state.rp2); }\n }\n\n // SZP0[] Set Zone Pointer 0\n // 0x13\n function SZP0(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SZP0[]', n); }\n\n state.zp0 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) { initTZone(state); }\n state.z0 = state.tZone;\n break;\n case 1 :\n state.z0 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n }\n\n // SZP1[] Set Zone Pointer 1\n // 0x14\n function SZP1(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SZP1[]', n); }\n\n state.zp1 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) { initTZone(state); }\n state.z1 = state.tZone;\n break;\n case 1 :\n state.z1 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n }\n\n // SZP2[] Set Zone Pointer 2\n // 0x15\n function SZP2(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SZP2[]', n); }\n\n state.zp2 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) { initTZone(state); }\n state.z2 = state.tZone;\n break;\n case 1 :\n state.z2 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n }\n\n // SZPS[] Set Zone PointerS\n // 0x16\n function SZPS(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SZPS[]', n); }\n\n state.zp0 = state.zp1 = state.zp2 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) { initTZone(state); }\n state.z0 = state.z1 = state.z2 = state.tZone;\n break;\n case 1 :\n state.z0 = state.z1 = state.z2 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n }\n\n // SLOOP[] Set LOOP variable\n // 0x17\n function SLOOP(state) {\n state.loop = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SLOOP[]', state.loop); }\n }\n\n // RTG[] Round To Grid\n // 0x18\n function RTG(state) {\n if (exports.DEBUG) { console.log(state.step, 'RTG[]'); }\n\n state.round = roundToGrid;\n }\n\n // RTHG[] Round To Half Grid\n // 0x19\n function RTHG(state) {\n if (exports.DEBUG) { console.log(state.step, 'RTHG[]'); }\n\n state.round = roundToHalfGrid;\n }\n\n // SMD[] Set Minimum Distance\n // 0x1A\n function SMD(state) {\n var d = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SMD[]', d); }\n\n state.minDis = d / 0x40;\n }\n\n // ELSE[] ELSE clause\n // 0x1B\n function ELSE(state) {\n // This instruction has been reached by executing a then branch\n // so it just skips ahead until matching EIF.\n //\n // In case the IF was negative the IF[] instruction already\n // skipped forward over the ELSE[]\n\n if (exports.DEBUG) { console.log(state.step, 'ELSE[]'); }\n\n skip(state, false);\n }\n\n // JMPR[] JuMP Relative\n // 0x1C\n function JMPR(state) {\n var o = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'JMPR[]', o); }\n\n // A jump by 1 would do nothing.\n state.ip += o - 1;\n }\n\n // SCVTCI[] Set Control Value Table Cut-In\n // 0x1D\n function SCVTCI(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SCVTCI[]', n); }\n\n state.cvCutIn = n / 0x40;\n }\n\n // DUP[] DUPlicate top stack element\n // 0x20\n function DUP(state) {\n var stack = state.stack;\n\n if (exports.DEBUG) { console.log(state.step, 'DUP[]'); }\n\n stack.push(stack[stack.length - 1]);\n }\n\n // POP[] POP top stack element\n // 0x21\n function POP(state) {\n if (exports.DEBUG) { console.log(state.step, 'POP[]'); }\n\n state.stack.pop();\n }\n\n // CLEAR[] CLEAR the stack\n // 0x22\n function CLEAR(state) {\n if (exports.DEBUG) { console.log(state.step, 'CLEAR[]'); }\n\n state.stack.length = 0;\n }\n\n // SWAP[] SWAP the top two elements on the stack\n // 0x23\n function SWAP(state) {\n var stack = state.stack;\n\n var a = stack.pop();\n var b = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SWAP[]'); }\n\n stack.push(a);\n stack.push(b);\n }\n\n // DEPTH[] DEPTH of the stack\n // 0x24\n function DEPTH(state) {\n var stack = state.stack;\n\n if (exports.DEBUG) { console.log(state.step, 'DEPTH[]'); }\n\n stack.push(stack.length);\n }\n\n // LOOPCALL[] LOOPCALL function\n // 0x2A\n function LOOPCALL(state) {\n var stack = state.stack;\n var fn = stack.pop();\n var c = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'LOOPCALL[]', fn, c); }\n\n // saves callers program\n var cip = state.ip;\n var cprog = state.prog;\n\n state.prog = state.funcs[fn];\n\n // executes the function\n for (var i = 0; i < c; i++) {\n exec(state);\n\n if (exports.DEBUG) { console.log(\n ++state.step,\n i + 1 < c ? 'next loopcall' : 'done loopcall',\n i\n ); }\n }\n\n // restores the callers program\n state.ip = cip;\n state.prog = cprog;\n }\n\n // CALL[] CALL function\n // 0x2B\n function CALL(state) {\n var fn = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'CALL[]', fn); }\n\n // saves callers program\n var cip = state.ip;\n var cprog = state.prog;\n\n state.prog = state.funcs[fn];\n\n // executes the function\n exec(state);\n\n // restores the callers program\n state.ip = cip;\n state.prog = cprog;\n\n if (exports.DEBUG) { console.log(++state.step, 'returning from', fn); }\n }\n\n // CINDEX[] Copy the INDEXed element to the top of the stack\n // 0x25\n function CINDEX(state) {\n var stack = state.stack;\n var k = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'CINDEX[]', k); }\n\n // In case of k == 1, it copies the last element after popping\n // thus stack.length - k.\n stack.push(stack[stack.length - k]);\n }\n\n // MINDEX[] Move the INDEXed element to the top of the stack\n // 0x26\n function MINDEX(state) {\n var stack = state.stack;\n var k = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'MINDEX[]', k); }\n\n stack.push(stack.splice(stack.length - k, 1)[0]);\n }\n\n // FDEF[] Function DEFinition\n // 0x2C\n function FDEF(state) {\n if (state.env !== 'fpgm') { throw new Error('FDEF not allowed here'); }\n var stack = state.stack;\n var prog = state.prog;\n var ip = state.ip;\n\n var fn = stack.pop();\n var ipBegin = ip;\n\n if (exports.DEBUG) { console.log(state.step, 'FDEF[]', fn); }\n\n while (prog[++ip] !== 0x2D){ }\n\n state.ip = ip;\n state.funcs[fn] = prog.slice(ipBegin + 1, ip);\n }\n\n // MDAP[a] Move Direct Absolute Point\n // 0x2E-0x2F\n function MDAP(round, state) {\n var pi = state.stack.pop();\n var p = state.z0[pi];\n var fv = state.fv;\n var pv = state.pv;\n\n if (exports.DEBUG) { console.log(state.step, 'MDAP[' + round + ']', pi); }\n\n var d = pv.distance(p, HPZero);\n\n if (round) { d = state.round(d); }\n\n fv.setRelative(p, HPZero, d, pv);\n fv.touch(p);\n\n state.rp0 = state.rp1 = pi;\n }\n\n // IUP[a] Interpolate Untouched Points through the outline\n // 0x30\n function IUP(v, state) {\n var z2 = state.z2;\n var pLen = z2.length - 2;\n var cp;\n var pp;\n var np;\n\n if (exports.DEBUG) { console.log(state.step, 'IUP[' + v.axis + ']'); }\n\n for (var i = 0; i < pLen; i++) {\n cp = z2[i]; // current point\n\n // if this point has been touched go on\n if (v.touched(cp)) { continue; }\n\n pp = cp.prevTouched(v);\n\n // no point on the contour has been touched?\n if (pp === cp) { continue; }\n\n np = cp.nextTouched(v);\n\n if (pp === np) {\n // only one point on the contour has been touched\n // so simply moves the point like that\n\n v.setRelative(cp, cp, v.distance(pp, pp, false, true), v, true);\n }\n\n v.interpolate(cp, pp, np, v);\n }\n }\n\n // SHP[] SHift Point using reference point\n // 0x32-0x33\n function SHP(a, state) {\n var stack = state.stack;\n var rpi = a ? state.rp1 : state.rp2;\n var rp = (a ? state.z0 : state.z1)[rpi];\n var fv = state.fv;\n var pv = state.pv;\n var loop = state.loop;\n var z2 = state.z2;\n\n while (loop--)\n {\n var pi = stack.pop();\n var p = z2[pi];\n\n var d = pv.distance(rp, rp, false, true);\n fv.setRelative(p, p, d, pv);\n fv.touch(p);\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ?\n 'loop ' + (state.loop - loop) + ': ' :\n ''\n ) +\n 'SHP[' + (a ? 'rp1' : 'rp2') + ']', pi\n );\n }\n }\n\n state.loop = 1;\n }\n\n // SHC[] SHift Contour using reference point\n // 0x36-0x37\n function SHC(a, state) {\n var stack = state.stack;\n var rpi = a ? state.rp1 : state.rp2;\n var rp = (a ? state.z0 : state.z1)[rpi];\n var fv = state.fv;\n var pv = state.pv;\n var ci = stack.pop();\n var sp = state.z2[state.contours[ci]];\n var p = sp;\n\n if (exports.DEBUG) { console.log(state.step, 'SHC[' + a + ']', ci); }\n\n var d = pv.distance(rp, rp, false, true);\n\n do {\n if (p !== rp) { fv.setRelative(p, p, d, pv); }\n p = p.nextPointOnContour;\n } while (p !== sp);\n }\n\n // SHZ[] SHift Zone using reference point\n // 0x36-0x37\n function SHZ(a, state) {\n var stack = state.stack;\n var rpi = a ? state.rp1 : state.rp2;\n var rp = (a ? state.z0 : state.z1)[rpi];\n var fv = state.fv;\n var pv = state.pv;\n\n var e = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SHZ[' + a + ']', e); }\n\n var z;\n switch (e) {\n case 0 : z = state.tZone; break;\n case 1 : z = state.gZone; break;\n default : throw new Error('Invalid zone');\n }\n\n var p;\n var d = pv.distance(rp, rp, false, true);\n var pLen = z.length - 2;\n for (var i = 0; i < pLen; i++)\n {\n p = z[i];\n fv.setRelative(p, p, d, pv);\n //if (p !== rp) fv.setRelative(p, p, d, pv);\n }\n }\n\n // SHPIX[] SHift point by a PIXel amount\n // 0x38\n function SHPIX(state) {\n var stack = state.stack;\n var loop = state.loop;\n var fv = state.fv;\n var d = stack.pop() / 0x40;\n var z2 = state.z2;\n\n while (loop--) {\n var pi = stack.pop();\n var p = z2[pi];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +\n 'SHPIX[]', pi, d\n );\n }\n\n fv.setRelative(p, p, d);\n fv.touch(p);\n }\n\n state.loop = 1;\n }\n\n // IP[] Interpolate Point\n // 0x39\n function IP(state) {\n var stack = state.stack;\n var rp1i = state.rp1;\n var rp2i = state.rp2;\n var loop = state.loop;\n var rp1 = state.z0[rp1i];\n var rp2 = state.z1[rp2i];\n var fv = state.fv;\n var pv = state.dpv;\n var z2 = state.z2;\n\n while (loop--) {\n var pi = stack.pop();\n var p = z2[pi];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +\n 'IP[]', pi, rp1i, '<->', rp2i\n );\n }\n\n fv.interpolate(p, rp1, rp2, pv);\n\n fv.touch(p);\n }\n\n state.loop = 1;\n }\n\n // MSIRP[a] Move Stack Indirect Relative Point\n // 0x3A-0x3B\n function MSIRP(a, state) {\n var stack = state.stack;\n var d = stack.pop() / 64;\n var pi = stack.pop();\n var p = state.z1[pi];\n var rp0 = state.z0[state.rp0];\n var fv = state.fv;\n var pv = state.pv;\n\n fv.setRelative(p, rp0, d, pv);\n fv.touch(p);\n\n if (exports.DEBUG) { console.log(state.step, 'MSIRP[' + a + ']', d, pi); }\n\n state.rp1 = state.rp0;\n state.rp2 = pi;\n if (a) { state.rp0 = pi; }\n }\n\n // ALIGNRP[] Align to reference point.\n // 0x3C\n function ALIGNRP(state) {\n var stack = state.stack;\n var rp0i = state.rp0;\n var rp0 = state.z0[rp0i];\n var loop = state.loop;\n var fv = state.fv;\n var pv = state.pv;\n var z1 = state.z1;\n\n while (loop--) {\n var pi = stack.pop();\n var p = z1[pi];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +\n 'ALIGNRP[]', pi\n );\n }\n\n fv.setRelative(p, rp0, 0, pv);\n fv.touch(p);\n }\n\n state.loop = 1;\n }\n\n // RTG[] Round To Double Grid\n // 0x3D\n function RTDG(state) {\n if (exports.DEBUG) { console.log(state.step, 'RTDG[]'); }\n\n state.round = roundToDoubleGrid;\n }\n\n // MIAP[a] Move Indirect Absolute Point\n // 0x3E-0x3F\n function MIAP(round, state) {\n var stack = state.stack;\n var n = stack.pop();\n var pi = stack.pop();\n var p = state.z0[pi];\n var fv = state.fv;\n var pv = state.pv;\n var cv = state.cvt[n];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n 'MIAP[' + round + ']',\n n, '(', cv, ')', pi\n );\n }\n\n var d = pv.distance(p, HPZero);\n\n if (round) {\n if (Math.abs(d - cv) < state.cvCutIn) { d = cv; }\n\n d = state.round(d);\n }\n\n fv.setRelative(p, HPZero, d, pv);\n\n if (state.zp0 === 0) {\n p.xo = p.x;\n p.yo = p.y;\n }\n\n fv.touch(p);\n\n state.rp0 = state.rp1 = pi;\n }\n\n // NPUSB[] PUSH N Bytes\n // 0x40\n function NPUSHB(state) {\n var prog = state.prog;\n var ip = state.ip;\n var stack = state.stack;\n\n var n = prog[++ip];\n\n if (exports.DEBUG) { console.log(state.step, 'NPUSHB[]', n); }\n\n for (var i = 0; i < n; i++) { stack.push(prog[++ip]); }\n\n state.ip = ip;\n }\n\n // NPUSHW[] PUSH N Words\n // 0x41\n function NPUSHW(state) {\n var ip = state.ip;\n var prog = state.prog;\n var stack = state.stack;\n var n = prog[++ip];\n\n if (exports.DEBUG) { console.log(state.step, 'NPUSHW[]', n); }\n\n for (var i = 0; i < n; i++) {\n var w = (prog[++ip] << 8) | prog[++ip];\n if (w & 0x8000) { w = -((w ^ 0xffff) + 1); }\n stack.push(w);\n }\n\n state.ip = ip;\n }\n\n // WS[] Write Store\n // 0x42\n function WS(state) {\n var stack = state.stack;\n var store = state.store;\n\n if (!store) { store = state.store = []; }\n\n var v = stack.pop();\n var l = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'WS', v, l); }\n\n store[l] = v;\n }\n\n // RS[] Read Store\n // 0x43\n function RS(state) {\n var stack = state.stack;\n var store = state.store;\n\n var l = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'RS', l); }\n\n var v = (store && store[l]) || 0;\n\n stack.push(v);\n }\n\n // WCVTP[] Write Control Value Table in Pixel units\n // 0x44\n function WCVTP(state) {\n var stack = state.stack;\n\n var v = stack.pop();\n var l = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'WCVTP', v, l); }\n\n state.cvt[l] = v / 0x40;\n }\n\n // RCVT[] Read Control Value Table entry\n // 0x45\n function RCVT(state) {\n var stack = state.stack;\n var cvte = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'RCVT', cvte); }\n\n stack.push(state.cvt[cvte] * 0x40);\n }\n\n // GC[] Get Coordinate projected onto the projection vector\n // 0x46-0x47\n function GC(a, state) {\n var stack = state.stack;\n var pi = stack.pop();\n var p = state.z2[pi];\n\n if (exports.DEBUG) { console.log(state.step, 'GC[' + a + ']', pi); }\n\n stack.push(state.dpv.distance(p, HPZero, a, false) * 0x40);\n }\n\n // MD[a] Measure Distance\n // 0x49-0x4A\n function MD(a, state) {\n var stack = state.stack;\n var pi2 = stack.pop();\n var pi1 = stack.pop();\n var p2 = state.z1[pi2];\n var p1 = state.z0[pi1];\n var d = state.dpv.distance(p1, p2, a, a);\n\n if (exports.DEBUG) { console.log(state.step, 'MD[' + a + ']', pi2, pi1, '->', d); }\n\n state.stack.push(Math.round(d * 64));\n }\n\n // MPPEM[] Measure Pixels Per EM\n // 0x4B\n function MPPEM(state) {\n if (exports.DEBUG) { console.log(state.step, 'MPPEM[]'); }\n state.stack.push(state.ppem);\n }\n\n // FLIPON[] set the auto FLIP Boolean to ON\n // 0x4D\n function FLIPON(state) {\n if (exports.DEBUG) { console.log(state.step, 'FLIPON[]'); }\n state.autoFlip = true;\n }\n\n // LT[] Less Than\n // 0x50\n function LT(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'LT[]', e2, e1); }\n\n stack.push(e1 < e2 ? 1 : 0);\n }\n\n // LTEQ[] Less Than or EQual\n // 0x53\n function LTEQ(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'LTEQ[]', e2, e1); }\n\n stack.push(e1 <= e2 ? 1 : 0);\n }\n\n // GTEQ[] Greater Than\n // 0x52\n function GT(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'GT[]', e2, e1); }\n\n stack.push(e1 > e2 ? 1 : 0);\n }\n\n // GTEQ[] Greater Than or EQual\n // 0x53\n function GTEQ(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'GTEQ[]', e2, e1); }\n\n stack.push(e1 >= e2 ? 1 : 0);\n }\n\n // EQ[] EQual\n // 0x54\n function EQ(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'EQ[]', e2, e1); }\n\n stack.push(e2 === e1 ? 1 : 0);\n }\n\n // NEQ[] Not EQual\n // 0x55\n function NEQ(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'NEQ[]', e2, e1); }\n\n stack.push(e2 !== e1 ? 1 : 0);\n }\n\n // ODD[] ODD\n // 0x56\n function ODD(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'ODD[]', n); }\n\n stack.push(Math.trunc(n) % 2 ? 1 : 0);\n }\n\n // EVEN[] EVEN\n // 0x57\n function EVEN(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'EVEN[]', n); }\n\n stack.push(Math.trunc(n) % 2 ? 0 : 1);\n }\n\n // IF[] IF test\n // 0x58\n function IF(state) {\n var test = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'IF[]', test); }\n\n // if test is true it just continues\n // if not the ip is skipped until matching ELSE or EIF\n if (!test) {\n skip(state, true);\n\n if (exports.DEBUG) { console.log(state.step, 'EIF[]'); }\n }\n }\n\n // EIF[] End IF\n // 0x59\n function EIF(state) {\n // this can be reached normally when\n // executing an else branch.\n // -> just ignore it\n\n if (exports.DEBUG) { console.log(state.step, 'EIF[]'); }\n }\n\n // AND[] logical AND\n // 0x5A\n function AND(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'AND[]', e2, e1); }\n\n stack.push(e2 && e1 ? 1 : 0);\n }\n\n // OR[] logical OR\n // 0x5B\n function OR(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'OR[]', e2, e1); }\n\n stack.push(e2 || e1 ? 1 : 0);\n }\n\n // NOT[] logical NOT\n // 0x5C\n function NOT(state) {\n var stack = state.stack;\n var e = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'NOT[]', e); }\n\n stack.push(e ? 0 : 1);\n }\n\n // DELTAP1[] DELTA exception P1\n // DELTAP2[] DELTA exception P2\n // DELTAP3[] DELTA exception P3\n // 0x5D, 0x71, 0x72\n function DELTAP123(b, state) {\n var stack = state.stack;\n var n = stack.pop();\n var fv = state.fv;\n var pv = state.pv;\n var ppem = state.ppem;\n var base = state.deltaBase + (b - 1) * 16;\n var ds = state.deltaShift;\n var z0 = state.z0;\n\n if (exports.DEBUG) { console.log(state.step, 'DELTAP[' + b + ']', n, stack); }\n\n for (var i = 0; i < n; i++) {\n var pi = stack.pop();\n var arg = stack.pop();\n var appem = base + ((arg & 0xF0) >> 4);\n if (appem !== ppem) { continue; }\n\n var mag = (arg & 0x0F) - 8;\n if (mag >= 0) { mag++; }\n if (exports.DEBUG) { console.log(state.step, 'DELTAPFIX', pi, 'by', mag * ds); }\n\n var p = z0[pi];\n fv.setRelative(p, p, mag * ds, pv);\n }\n }\n\n // SDB[] Set Delta Base in the graphics state\n // 0x5E\n function SDB(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SDB[]', n); }\n\n state.deltaBase = n;\n }\n\n // SDS[] Set Delta Shift in the graphics state\n // 0x5F\n function SDS(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SDS[]', n); }\n\n state.deltaShift = Math.pow(0.5, n);\n }\n\n // ADD[] ADD\n // 0x60\n function ADD(state) {\n var stack = state.stack;\n var n2 = stack.pop();\n var n1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'ADD[]', n2, n1); }\n\n stack.push(n1 + n2);\n }\n\n // SUB[] SUB\n // 0x61\n function SUB(state) {\n var stack = state.stack;\n var n2 = stack.pop();\n var n1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SUB[]', n2, n1); }\n\n stack.push(n1 - n2);\n }\n\n // DIV[] DIV\n // 0x62\n function DIV(state) {\n var stack = state.stack;\n var n2 = stack.pop();\n var n1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'DIV[]', n2, n1); }\n\n stack.push(n1 * 64 / n2);\n }\n\n // MUL[] MUL\n // 0x63\n function MUL(state) {\n var stack = state.stack;\n var n2 = stack.pop();\n var n1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'MUL[]', n2, n1); }\n\n stack.push(n1 * n2 / 64);\n }\n\n // ABS[] ABSolute value\n // 0x64\n function ABS(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'ABS[]', n); }\n\n stack.push(Math.abs(n));\n }\n\n // NEG[] NEGate\n // 0x65\n function NEG(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'NEG[]', n); }\n\n stack.push(-n);\n }\n\n // FLOOR[] FLOOR\n // 0x66\n function FLOOR(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'FLOOR[]', n); }\n\n stack.push(Math.floor(n / 0x40) * 0x40);\n }\n\n // CEILING[] CEILING\n // 0x67\n function CEILING(state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'CEILING[]', n); }\n\n stack.push(Math.ceil(n / 0x40) * 0x40);\n }\n\n // ROUND[ab] ROUND value\n // 0x68-0x6B\n function ROUND(dt, state) {\n var stack = state.stack;\n var n = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'ROUND[]'); }\n\n stack.push(state.round(n / 0x40) * 0x40);\n }\n\n // WCVTF[] Write Control Value Table in Funits\n // 0x70\n function WCVTF(state) {\n var stack = state.stack;\n var v = stack.pop();\n var l = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'WCVTF[]', v, l); }\n\n state.cvt[l] = v * state.ppem / state.font.unitsPerEm;\n }\n\n // DELTAC1[] DELTA exception C1\n // DELTAC2[] DELTA exception C2\n // DELTAC3[] DELTA exception C3\n // 0x73, 0x74, 0x75\n function DELTAC123(b, state) {\n var stack = state.stack;\n var n = stack.pop();\n var ppem = state.ppem;\n var base = state.deltaBase + (b - 1) * 16;\n var ds = state.deltaShift;\n\n if (exports.DEBUG) { console.log(state.step, 'DELTAC[' + b + ']', n, stack); }\n\n for (var i = 0; i < n; i++) {\n var c = stack.pop();\n var arg = stack.pop();\n var appem = base + ((arg & 0xF0) >> 4);\n if (appem !== ppem) { continue; }\n\n var mag = (arg & 0x0F) - 8;\n if (mag >= 0) { mag++; }\n\n var delta = mag * ds;\n\n if (exports.DEBUG) { console.log(state.step, 'DELTACFIX', c, 'by', delta); }\n\n state.cvt[c] += delta;\n }\n }\n\n // SROUND[] Super ROUND\n // 0x76\n function SROUND(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'SROUND[]', n); }\n\n state.round = roundSuper;\n\n var period;\n\n switch (n & 0xC0) {\n case 0x00:\n period = 0.5;\n break;\n case 0x40:\n period = 1;\n break;\n case 0x80:\n period = 2;\n break;\n default:\n throw new Error('invalid SROUND value');\n }\n\n state.srPeriod = period;\n\n switch (n & 0x30) {\n case 0x00:\n state.srPhase = 0;\n break;\n case 0x10:\n state.srPhase = 0.25 * period;\n break;\n case 0x20:\n state.srPhase = 0.5 * period;\n break;\n case 0x30:\n state.srPhase = 0.75 * period;\n break;\n default: throw new Error('invalid SROUND value');\n }\n\n n &= 0x0F;\n\n if (n === 0) { state.srThreshold = 0; }\n else { state.srThreshold = (n / 8 - 0.5) * period; }\n }\n\n // S45ROUND[] Super ROUND 45 degrees\n // 0x77\n function S45ROUND(state) {\n var n = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'S45ROUND[]', n); }\n\n state.round = roundSuper;\n\n var period;\n\n switch (n & 0xC0) {\n case 0x00:\n period = Math.sqrt(2) / 2;\n break;\n case 0x40:\n period = Math.sqrt(2);\n break;\n case 0x80:\n period = 2 * Math.sqrt(2);\n break;\n default:\n throw new Error('invalid S45ROUND value');\n }\n\n state.srPeriod = period;\n\n switch (n & 0x30) {\n case 0x00:\n state.srPhase = 0;\n break;\n case 0x10:\n state.srPhase = 0.25 * period;\n break;\n case 0x20:\n state.srPhase = 0.5 * period;\n break;\n case 0x30:\n state.srPhase = 0.75 * period;\n break;\n default:\n throw new Error('invalid S45ROUND value');\n }\n\n n &= 0x0F;\n\n if (n === 0) { state.srThreshold = 0; }\n else { state.srThreshold = (n / 8 - 0.5) * period; }\n }\n\n // ROFF[] Round Off\n // 0x7A\n function ROFF(state) {\n if (exports.DEBUG) { console.log(state.step, 'ROFF[]'); }\n\n state.round = roundOff;\n }\n\n // RUTG[] Round Up To Grid\n // 0x7C\n function RUTG(state) {\n if (exports.DEBUG) { console.log(state.step, 'RUTG[]'); }\n\n state.round = roundUpToGrid;\n }\n\n // RDTG[] Round Down To Grid\n // 0x7D\n function RDTG(state) {\n if (exports.DEBUG) { console.log(state.step, 'RDTG[]'); }\n\n state.round = roundDownToGrid;\n }\n\n // SCANCTRL[] SCAN conversion ConTRoL\n // 0x85\n function SCANCTRL(state) {\n var n = state.stack.pop();\n\n // ignored by opentype.js\n\n if (exports.DEBUG) { console.log(state.step, 'SCANCTRL[]', n); }\n }\n\n // SDPVTL[a] Set Dual Projection Vector To Line\n // 0x86-0x87\n function SDPVTL(a, state) {\n var stack = state.stack;\n var p2i = stack.pop();\n var p1i = stack.pop();\n var p2 = state.z2[p2i];\n var p1 = state.z1[p1i];\n\n if (exports.DEBUG) { console.log(state.step, 'SDPVTL[' + a + ']', p2i, p1i); }\n\n var dx;\n var dy;\n\n if (!a) {\n dx = p1.x - p2.x;\n dy = p1.y - p2.y;\n } else {\n dx = p2.y - p1.y;\n dy = p1.x - p2.x;\n }\n\n state.dpv = getUnitVector(dx, dy);\n }\n\n // GETINFO[] GET INFOrmation\n // 0x88\n function GETINFO(state) {\n var stack = state.stack;\n var sel = stack.pop();\n var r = 0;\n\n if (exports.DEBUG) { console.log(state.step, 'GETINFO[]', sel); }\n\n // v35 as in no subpixel hinting\n if (sel & 0x01) { r = 35; }\n\n // TODO rotation and stretch currently not supported\n // and thus those GETINFO are always 0.\n\n // opentype.js is always gray scaling\n if (sel & 0x20) { r |= 0x1000; }\n\n stack.push(r);\n }\n\n // ROLL[] ROLL the top three stack elements\n // 0x8A\n function ROLL(state) {\n var stack = state.stack;\n var a = stack.pop();\n var b = stack.pop();\n var c = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'ROLL[]'); }\n\n stack.push(b);\n stack.push(a);\n stack.push(c);\n }\n\n // MAX[] MAXimum of top two stack elements\n // 0x8B\n function MAX(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'MAX[]', e2, e1); }\n\n stack.push(Math.max(e1, e2));\n }\n\n // MIN[] MINimum of top two stack elements\n // 0x8C\n function MIN(state) {\n var stack = state.stack;\n var e2 = stack.pop();\n var e1 = stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'MIN[]', e2, e1); }\n\n stack.push(Math.min(e1, e2));\n }\n\n // SCANTYPE[] SCANTYPE\n // 0x8D\n function SCANTYPE(state) {\n var n = state.stack.pop();\n // ignored by opentype.js\n if (exports.DEBUG) { console.log(state.step, 'SCANTYPE[]', n); }\n }\n\n // INSTCTRL[] INSTCTRL\n // 0x8D\n function INSTCTRL(state) {\n var s = state.stack.pop();\n var v = state.stack.pop();\n\n if (exports.DEBUG) { console.log(state.step, 'INSTCTRL[]', s, v); }\n\n switch (s) {\n case 1 : state.inhibitGridFit = !!v; return;\n case 2 : state.ignoreCvt = !!v; return;\n default: throw new Error('invalid INSTCTRL[] selector');\n }\n }\n\n // PUSHB[abc] PUSH Bytes\n // 0xB0-0xB7\n function PUSHB(n, state) {\n var stack = state.stack;\n var prog = state.prog;\n var ip = state.ip;\n\n if (exports.DEBUG) { console.log(state.step, 'PUSHB[' + n + ']'); }\n\n for (var i = 0; i < n; i++) { stack.push(prog[++ip]); }\n\n state.ip = ip;\n }\n\n // PUSHW[abc] PUSH Words\n // 0xB8-0xBF\n function PUSHW(n, state) {\n var ip = state.ip;\n var prog = state.prog;\n var stack = state.stack;\n\n if (exports.DEBUG) { console.log(state.ip, 'PUSHW[' + n + ']'); }\n\n for (var i = 0; i < n; i++) {\n var w = (prog[++ip] << 8) | prog[++ip];\n if (w & 0x8000) { w = -((w ^ 0xffff) + 1); }\n stack.push(w);\n }\n\n state.ip = ip;\n }\n\n // MDRP[abcde] Move Direct Relative Point\n // 0xD0-0xEF\n // (if indirect is 0)\n //\n // and\n //\n // MIRP[abcde] Move Indirect Relative Point\n // 0xE0-0xFF\n // (if indirect is 1)\n\n function MDRP_MIRP(indirect, setRp0, keepD, ro, dt, state) {\n var stack = state.stack;\n var cvte = indirect && stack.pop();\n var pi = stack.pop();\n var rp0i = state.rp0;\n var rp = state.z0[rp0i];\n var p = state.z1[pi];\n\n var md = state.minDis;\n var fv = state.fv;\n var pv = state.dpv;\n var od; // original distance\n var d; // moving distance\n var sign; // sign of distance\n var cv;\n\n d = od = pv.distance(p, rp, true, true);\n sign = d >= 0 ? 1 : -1; // Math.sign would be 0 in case of 0\n\n // TODO consider autoFlip\n d = Math.abs(d);\n\n if (indirect) {\n cv = state.cvt[cvte];\n\n if (ro && Math.abs(d - cv) < state.cvCutIn) { d = cv; }\n }\n\n if (keepD && d < md) { d = md; }\n\n if (ro) { d = state.round(d); }\n\n fv.setRelative(p, rp, sign * d, pv);\n fv.touch(p);\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (indirect ? 'MIRP[' : 'MDRP[') +\n (setRp0 ? 'M' : 'm') +\n (keepD ? '>' : '_') +\n (ro ? 'R' : '_') +\n (dt === 0 ? 'Gr' : (dt === 1 ? 'Bl' : (dt === 2 ? 'Wh' : ''))) +\n ']',\n indirect ?\n cvte + '(' + state.cvt[cvte] + ',' + cv + ')' :\n '',\n pi,\n '(d =', od, '->', sign * d, ')'\n );\n }\n\n state.rp1 = state.rp0;\n state.rp2 = pi;\n if (setRp0) { state.rp0 = pi; }\n }\n\n /*\n * The instruction table.\n */\n instructionTable = [\n /* 0x00 */ SVTCA.bind(undefined, yUnitVector),\n /* 0x01 */ SVTCA.bind(undefined, xUnitVector),\n /* 0x02 */ SPVTCA.bind(undefined, yUnitVector),\n /* 0x03 */ SPVTCA.bind(undefined, xUnitVector),\n /* 0x04 */ SFVTCA.bind(undefined, yUnitVector),\n /* 0x05 */ SFVTCA.bind(undefined, xUnitVector),\n /* 0x06 */ SPVTL.bind(undefined, 0),\n /* 0x07 */ SPVTL.bind(undefined, 1),\n /* 0x08 */ SFVTL.bind(undefined, 0),\n /* 0x09 */ SFVTL.bind(undefined, 1),\n /* 0x0A */ SPVFS,\n /* 0x0B */ SFVFS,\n /* 0x0C */ GPV,\n /* 0x0D */ GFV,\n /* 0x0E */ SFVTPV,\n /* 0x0F */ ISECT,\n /* 0x10 */ SRP0,\n /* 0x11 */ SRP1,\n /* 0x12 */ SRP2,\n /* 0x13 */ SZP0,\n /* 0x14 */ SZP1,\n /* 0x15 */ SZP2,\n /* 0x16 */ SZPS,\n /* 0x17 */ SLOOP,\n /* 0x18 */ RTG,\n /* 0x19 */ RTHG,\n /* 0x1A */ SMD,\n /* 0x1B */ ELSE,\n /* 0x1C */ JMPR,\n /* 0x1D */ SCVTCI,\n /* 0x1E */ undefined, // TODO SSWCI\n /* 0x1F */ undefined, // TODO SSW\n /* 0x20 */ DUP,\n /* 0x21 */ POP,\n /* 0x22 */ CLEAR,\n /* 0x23 */ SWAP,\n /* 0x24 */ DEPTH,\n /* 0x25 */ CINDEX,\n /* 0x26 */ MINDEX,\n /* 0x27 */ undefined, // TODO ALIGNPTS\n /* 0x28 */ undefined,\n /* 0x29 */ undefined, // TODO UTP\n /* 0x2A */ LOOPCALL,\n /* 0x2B */ CALL,\n /* 0x2C */ FDEF,\n /* 0x2D */ undefined, // ENDF (eaten by FDEF)\n /* 0x2E */ MDAP.bind(undefined, 0),\n /* 0x2F */ MDAP.bind(undefined, 1),\n /* 0x30 */ IUP.bind(undefined, yUnitVector),\n /* 0x31 */ IUP.bind(undefined, xUnitVector),\n /* 0x32 */ SHP.bind(undefined, 0),\n /* 0x33 */ SHP.bind(undefined, 1),\n /* 0x34 */ SHC.bind(undefined, 0),\n /* 0x35 */ SHC.bind(undefined, 1),\n /* 0x36 */ SHZ.bind(undefined, 0),\n /* 0x37 */ SHZ.bind(undefined, 1),\n /* 0x38 */ SHPIX,\n /* 0x39 */ IP,\n /* 0x3A */ MSIRP.bind(undefined, 0),\n /* 0x3B */ MSIRP.bind(undefined, 1),\n /* 0x3C */ ALIGNRP,\n /* 0x3D */ RTDG,\n /* 0x3E */ MIAP.bind(undefined, 0),\n /* 0x3F */ MIAP.bind(undefined, 1),\n /* 0x40 */ NPUSHB,\n /* 0x41 */ NPUSHW,\n /* 0x42 */ WS,\n /* 0x43 */ RS,\n /* 0x44 */ WCVTP,\n /* 0x45 */ RCVT,\n /* 0x46 */ GC.bind(undefined, 0),\n /* 0x47 */ GC.bind(undefined, 1),\n /* 0x48 */ undefined, // TODO SCFS\n /* 0x49 */ MD.bind(undefined, 0),\n /* 0x4A */ MD.bind(undefined, 1),\n /* 0x4B */ MPPEM,\n /* 0x4C */ undefined, // TODO MPS\n /* 0x4D */ FLIPON,\n /* 0x4E */ undefined, // TODO FLIPOFF\n /* 0x4F */ undefined, // TODO DEBUG\n /* 0x50 */ LT,\n /* 0x51 */ LTEQ,\n /* 0x52 */ GT,\n /* 0x53 */ GTEQ,\n /* 0x54 */ EQ,\n /* 0x55 */ NEQ,\n /* 0x56 */ ODD,\n /* 0x57 */ EVEN,\n /* 0x58 */ IF,\n /* 0x59 */ EIF,\n /* 0x5A */ AND,\n /* 0x5B */ OR,\n /* 0x5C */ NOT,\n /* 0x5D */ DELTAP123.bind(undefined, 1),\n /* 0x5E */ SDB,\n /* 0x5F */ SDS,\n /* 0x60 */ ADD,\n /* 0x61 */ SUB,\n /* 0x62 */ DIV,\n /* 0x63 */ MUL,\n /* 0x64 */ ABS,\n /* 0x65 */ NEG,\n /* 0x66 */ FLOOR,\n /* 0x67 */ CEILING,\n /* 0x68 */ ROUND.bind(undefined, 0),\n /* 0x69 */ ROUND.bind(undefined, 1),\n /* 0x6A */ ROUND.bind(undefined, 2),\n /* 0x6B */ ROUND.bind(undefined, 3),\n /* 0x6C */ undefined, // TODO NROUND[ab]\n /* 0x6D */ undefined, // TODO NROUND[ab]\n /* 0x6E */ undefined, // TODO NROUND[ab]\n /* 0x6F */ undefined, // TODO NROUND[ab]\n /* 0x70 */ WCVTF,\n /* 0x71 */ DELTAP123.bind(undefined, 2),\n /* 0x72 */ DELTAP123.bind(undefined, 3),\n /* 0x73 */ DELTAC123.bind(undefined, 1),\n /* 0x74 */ DELTAC123.bind(undefined, 2),\n /* 0x75 */ DELTAC123.bind(undefined, 3),\n /* 0x76 */ SROUND,\n /* 0x77 */ S45ROUND,\n /* 0x78 */ undefined, // TODO JROT[]\n /* 0x79 */ undefined, // TODO JROF[]\n /* 0x7A */ ROFF,\n /* 0x7B */ undefined,\n /* 0x7C */ RUTG,\n /* 0x7D */ RDTG,\n /* 0x7E */ POP, // actually SANGW, supposed to do only a pop though\n /* 0x7F */ POP, // actually AA, supposed to do only a pop though\n /* 0x80 */ undefined, // TODO FLIPPT\n /* 0x81 */ undefined, // TODO FLIPRGON\n /* 0x82 */ undefined, // TODO FLIPRGOFF\n /* 0x83 */ undefined,\n /* 0x84 */ undefined,\n /* 0x85 */ SCANCTRL,\n /* 0x86 */ SDPVTL.bind(undefined, 0),\n /* 0x87 */ SDPVTL.bind(undefined, 1),\n /* 0x88 */ GETINFO,\n /* 0x89 */ undefined, // TODO IDEF\n /* 0x8A */ ROLL,\n /* 0x8B */ MAX,\n /* 0x8C */ MIN,\n /* 0x8D */ SCANTYPE,\n /* 0x8E */ INSTCTRL,\n /* 0x8F */ undefined,\n /* 0x90 */ undefined,\n /* 0x91 */ undefined,\n /* 0x92 */ undefined,\n /* 0x93 */ undefined,\n /* 0x94 */ undefined,\n /* 0x95 */ undefined,\n /* 0x96 */ undefined,\n /* 0x97 */ undefined,\n /* 0x98 */ undefined,\n /* 0x99 */ undefined,\n /* 0x9A */ undefined,\n /* 0x9B */ undefined,\n /* 0x9C */ undefined,\n /* 0x9D */ undefined,\n /* 0x9E */ undefined,\n /* 0x9F */ undefined,\n /* 0xA0 */ undefined,\n /* 0xA1 */ undefined,\n /* 0xA2 */ undefined,\n /* 0xA3 */ undefined,\n /* 0xA4 */ undefined,\n /* 0xA5 */ undefined,\n /* 0xA6 */ undefined,\n /* 0xA7 */ undefined,\n /* 0xA8 */ undefined,\n /* 0xA9 */ undefined,\n /* 0xAA */ undefined,\n /* 0xAB */ undefined,\n /* 0xAC */ undefined,\n /* 0xAD */ undefined,\n /* 0xAE */ undefined,\n /* 0xAF */ undefined,\n /* 0xB0 */ PUSHB.bind(undefined, 1),\n /* 0xB1 */ PUSHB.bind(undefined, 2),\n /* 0xB2 */ PUSHB.bind(undefined, 3),\n /* 0xB3 */ PUSHB.bind(undefined, 4),\n /* 0xB4 */ PUSHB.bind(undefined, 5),\n /* 0xB5 */ PUSHB.bind(undefined, 6),\n /* 0xB6 */ PUSHB.bind(undefined, 7),\n /* 0xB7 */ PUSHB.bind(undefined, 8),\n /* 0xB8 */ PUSHW.bind(undefined, 1),\n /* 0xB9 */ PUSHW.bind(undefined, 2),\n /* 0xBA */ PUSHW.bind(undefined, 3),\n /* 0xBB */ PUSHW.bind(undefined, 4),\n /* 0xBC */ PUSHW.bind(undefined, 5),\n /* 0xBD */ PUSHW.bind(undefined, 6),\n /* 0xBE */ PUSHW.bind(undefined, 7),\n /* 0xBF */ PUSHW.bind(undefined, 8),\n /* 0xC0 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 0),\n /* 0xC1 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 1),\n /* 0xC2 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 2),\n /* 0xC3 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 3),\n /* 0xC4 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 0),\n /* 0xC5 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 1),\n /* 0xC6 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 2),\n /* 0xC7 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 3),\n /* 0xC8 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 0),\n /* 0xC9 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 1),\n /* 0xCA */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 2),\n /* 0xCB */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 3),\n /* 0xCC */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 0),\n /* 0xCD */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 1),\n /* 0xCE */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 2),\n /* 0xCF */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 3),\n /* 0xD0 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 0),\n /* 0xD1 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 1),\n /* 0xD2 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 2),\n /* 0xD3 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 3),\n /* 0xD4 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 0),\n /* 0xD5 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 1),\n /* 0xD6 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 2),\n /* 0xD7 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 3),\n /* 0xD8 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 0),\n /* 0xD9 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 1),\n /* 0xDA */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 2),\n /* 0xDB */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 3),\n /* 0xDC */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 0),\n /* 0xDD */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 1),\n /* 0xDE */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 2),\n /* 0xDF */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 3),\n /* 0xE0 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 0),\n /* 0xE1 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 1),\n /* 0xE2 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 2),\n /* 0xE3 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 3),\n /* 0xE4 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 0),\n /* 0xE5 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 1),\n /* 0xE6 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 2),\n /* 0xE7 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 3),\n /* 0xE8 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 0),\n /* 0xE9 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 1),\n /* 0xEA */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 2),\n /* 0xEB */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 3),\n /* 0xEC */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 0),\n /* 0xED */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 1),\n /* 0xEE */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 2),\n /* 0xEF */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 3),\n /* 0xF0 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 0),\n /* 0xF1 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 1),\n /* 0xF2 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 2),\n /* 0xF3 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 3),\n /* 0xF4 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 0),\n /* 0xF5 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 1),\n /* 0xF6 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 2),\n /* 0xF7 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 3),\n /* 0xF8 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 0),\n /* 0xF9 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 1),\n /* 0xFA */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 2),\n /* 0xFB */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 3),\n /* 0xFC */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 0),\n /* 0xFD */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 1),\n /* 0xFE */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 2),\n /* 0xFF */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 3)\n ];\n\n /*****************************\n Mathematical Considerations\n ******************************\n\n fv ... refers to freedom vector\n pv ... refers to projection vector\n rp ... refers to reference point\n p ... refers to to point being operated on\n d ... refers to distance\n\n SETRELATIVE:\n ============\n\n case freedom vector == x-axis:\n ------------------------------\n\n (pv)\n .-'\n rpd .-'\n .-*\n d .-'90°'\n .-' '\n .-' '\n *-' ' b\n rp '\n '\n '\n p *----------*-------------- (fv)\n pm\n\n rpdx = rpx + d * pv.x\n rpdy = rpy + d * pv.y\n\n equation of line b\n\n y - rpdy = pvns * (x- rpdx)\n\n y = p.y\n\n x = rpdx + ( p.y - rpdy ) / pvns\n\n\n case freedom vector == y-axis:\n ------------------------------\n\n * pm\n |\\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\ b\n | \\\n | \\\n | \\ .-' (pv)\n | 90° \\.-'\n | .-'* rpd\n | .-'\n * *-' d\n p rp\n\n rpdx = rpx + d * pv.x\n rpdy = rpy + d * pv.y\n\n equation of line b:\n pvns ... normal slope to pv\n\n y - rpdy = pvns * (x - rpdx)\n\n x = p.x\n\n y = rpdy + pvns * (p.x - rpdx)\n\n\n\n generic case:\n -------------\n\n\n .'(fv)\n .'\n .* pm\n .' !\n .' .\n .' !\n .' . b\n .' !\n * .\n p !\n 90° . ... (pv)\n ...-*-'''\n ...---''' rpd\n ...---''' d\n *--'''\n rp\n\n rpdx = rpx + d * pv.x\n rpdy = rpy + d * pv.y\n\n equation of line b:\n pvns... normal slope to pv\n\n y - rpdy = pvns * (x - rpdx)\n\n equation of freedom vector line:\n fvs ... slope of freedom vector (=fy/fx)\n\n y - py = fvs * (x - px)\n\n\n on pm both equations are true for same x/y\n\n y - rpdy = pvns * (x - rpdx)\n\n y - py = fvs * (x - px)\n\n form to y and set equal:\n\n pvns * (x - rpdx) + rpdy = fvs * (x - px) + py\n\n expand:\n\n pvns * x - pvns * rpdx + rpdy = fvs * x - fvs * px + py\n\n switch:\n\n fvs * x - fvs * px + py = pvns * x - pvns * rpdx + rpdy\n\n solve for x:\n\n fvs * x - pvns * x = fvs * px - pvns * rpdx - py + rpdy\n\n\n\n fvs * px - pvns * rpdx + rpdy - py\n x = -----------------------------------\n fvs - pvns\n\n and:\n\n y = fvs * (x - px) + py\n\n\n\n INTERPOLATE:\n ============\n\n Examples of point interpolation.\n\n The weight of the movement of the reference point gets bigger\n the further the other reference point is away, thus the safest\n option (that is avoiding 0/0 divisions) is to weight the\n original distance of the other point by the sum of both distances.\n\n If the sum of both distances is 0, then move the point by the\n arithmetic average of the movement of both reference points.\n\n\n\n\n (+6)\n rp1o *---->*rp1\n . . (+12)\n . . rp2o *---------->* rp2\n . . . .\n . . . .\n . 10 20 . .\n |.........|...................| .\n . . .\n . . (+8) .\n po *------>*p .\n . . .\n . 12 . 24 .\n |...........|.......................|\n 36\n\n\n -------\n\n\n\n (+10)\n rp1o *-------->*rp1\n . . (-10)\n . . rp2 *<---------* rpo2\n . . . .\n . . . .\n . 10 . 30 . .\n |.........|.............................|\n . .\n . (+5) .\n po *--->* p .\n . . .\n . . 20 .\n |....|..............|\n 5 15\n\n\n -------\n\n\n (+10)\n rp1o *-------->*rp1\n . .\n . .\n rp2o *-------->*rp2\n\n\n (+10)\n po *-------->* p\n\n -------\n\n\n (+10)\n rp1o *-------->*rp1\n . .\n . .(+30)\n rp2o *---------------------------->*rp2\n\n\n (+25)\n po *----------------------->* p\n\n\n\n vim: set ts=4 sw=4 expandtab:\n *****/\n\n /**\n * Converts a string into a list of tokens.\n */\n\n /**\n * Create a new token\n * @param {string} char a single char\n */\n function Token$1(char) {\n this.char = char;\n this.state = {};\n this.activeState = null;\n }\n\n /**\n * Create a new context range\n * @param {number} startIndex range start index\n * @param {number} endOffset range end index offset\n * @param {string} contextName owner context name\n */\n function ContextRange(startIndex, endOffset, contextName) {\n this.contextName = contextName;\n this.startIndex = startIndex;\n this.endOffset = endOffset;\n }\n\n /**\n * Check context start and end\n * @param {string} contextName a unique context name\n * @param {function} checkStart a predicate function the indicates a context's start\n * @param {function} checkEnd a predicate function the indicates a context's end\n */\n function ContextChecker(contextName, checkStart, checkEnd) {\n this.contextName = contextName;\n this.openRange = null;\n this.ranges = [];\n this.checkStart = checkStart;\n this.checkEnd = checkEnd;\n }\n\n /**\n * @typedef ContextParams\n * @type Object\n * @property {array} context context items\n * @property {number} currentIndex current item index\n */\n\n /**\n * Create a context params\n * @param {array} context a list of items\n * @param {number} currentIndex current item index\n */\n function ContextParams(context, currentIndex) {\n this.context = context;\n this.index = currentIndex;\n this.length = context.length;\n this.current = context[currentIndex];\n this.backtrack = context.slice(0, currentIndex);\n this.lookahead = context.slice(currentIndex + 1);\n }\n\n /**\n * Create an event instance\n * @param {string} eventId event unique id\n */\n function Event(eventId) {\n this.eventId = eventId;\n this.subscribers = [];\n }\n\n /**\n * Initialize a core events and auto subscribe required event handlers\n * @param {any} events an object that enlists core events handlers\n */\n function initializeCoreEvents(events) {\n var this$1 = this;\n\n var coreEvents = [\n 'start', 'end', 'next', 'newToken', 'contextStart',\n 'contextEnd', 'insertToken', 'removeToken', 'removeRange',\n 'replaceToken', 'replaceRange', 'composeRUD', 'updateContextsRanges'\n ];\n\n coreEvents.forEach(function (eventId) {\n Object.defineProperty(this$1.events, eventId, {\n value: new Event(eventId)\n });\n });\n\n if (!!events) {\n coreEvents.forEach(function (eventId) {\n var event = events[eventId];\n if (typeof event === 'function') {\n this$1.events[eventId].subscribe(event);\n }\n });\n }\n var requiresContextUpdate = [\n 'insertToken', 'removeToken', 'removeRange',\n 'replaceToken', 'replaceRange', 'composeRUD'\n ];\n requiresContextUpdate.forEach(function (eventId) {\n this$1.events[eventId].subscribe(\n this$1.updateContextsRanges\n );\n });\n }\n\n /**\n * Converts a string into a list of tokens\n * @param {any} events tokenizer core events\n */\n function Tokenizer(events) {\n this.tokens = [];\n this.registeredContexts = {};\n this.contextCheckers = [];\n this.events = {};\n this.registeredModifiers = [];\n\n initializeCoreEvents.call(this, events);\n }\n\n /**\n * Sets the state of a token, usually called by a state modifier.\n * @param {string} key state item key\n * @param {any} value state item value\n */\n Token$1.prototype.setState = function(key, value) {\n this.state[key] = value;\n this.activeState = { key: key, value: this.state[key] };\n return this.activeState;\n };\n\n Token$1.prototype.getState = function (stateId) {\n return this.state[stateId] || null;\n };\n\n /**\n * Checks if an index exists in the tokens list.\n * @param {number} index token index\n */\n Tokenizer.prototype.inboundIndex = function(index) {\n return index >= 0 && index < this.tokens.length;\n };\n\n /**\n * Compose and apply a list of operations (replace, update, delete)\n * @param {array} RUDs replace, update and delete operations\n * TODO: Perf. Optimization (lengthBefore === lengthAfter ? dispatch once)\n */\n Tokenizer.prototype.composeRUD = function (RUDs) {\n var this$1 = this;\n\n var silent = true;\n var state = RUDs.map(function (RUD) { return (\n this$1[RUD[0]].apply(this$1, RUD.slice(1).concat(silent))\n ); });\n var hasFAILObject = function (obj) { return (\n typeof obj === 'object' &&\n obj.hasOwnProperty('FAIL')\n ); };\n if (state.every(hasFAILObject)) {\n return {\n FAIL: \"composeRUD: one or more operations hasn't completed successfully\",\n report: state.filter(hasFAILObject)\n };\n }\n this.dispatch('composeRUD', [state.filter(function (op) { return !hasFAILObject(op); })]);\n };\n\n /**\n * Replace a range of tokens with a list of tokens\n * @param {number} startIndex range start index\n * @param {number} offset range offset\n * @param {token} tokens a list of tokens to replace\n * @param {boolean} silent dispatch events and update context ranges\n */\n Tokenizer.prototype.replaceRange = function (startIndex, offset, tokens, silent) {\n offset = offset !== null ? offset : this.tokens.length;\n var isTokenType = tokens.every(function (token) { return token instanceof Token$1; });\n if (!isNaN(startIndex) && this.inboundIndex(startIndex) && isTokenType) {\n var replaced = this.tokens.splice.apply(\n this.tokens, [startIndex, offset].concat(tokens)\n );\n if (!silent) { this.dispatch('replaceToken', [startIndex, offset, tokens]); }\n return [replaced, tokens];\n } else {\n return { FAIL: 'replaceRange: invalid tokens or startIndex.' };\n }\n };\n\n /**\n * Replace a token with another token\n * @param {number} index token index\n * @param {token} token a token to replace\n * @param {boolean} silent dispatch events and update context ranges\n */\n Tokenizer.prototype.replaceToken = function (index, token, silent) {\n if (!isNaN(index) && this.inboundIndex(index) && token instanceof Token$1) {\n var replaced = this.tokens.splice(index, 1, token);\n if (!silent) { this.dispatch('replaceToken', [index, token]); }\n return [replaced[0], token];\n } else {\n return { FAIL: 'replaceToken: invalid token or index.' };\n }\n };\n\n /**\n * Removes a range of tokens\n * @param {number} startIndex range start index\n * @param {number} offset range offset\n * @param {boolean} silent dispatch events and update context ranges\n */\n Tokenizer.prototype.removeRange = function(startIndex, offset, silent) {\n offset = !isNaN(offset) ? offset : this.tokens.length;\n var tokens = this.tokens.splice(startIndex, offset);\n if (!silent) { this.dispatch('removeRange', [tokens, startIndex, offset]); }\n return tokens;\n };\n\n /**\n * Remove a token at a certain index\n * @param {number} index token index\n * @param {boolean} silent dispatch events and update context ranges\n */\n Tokenizer.prototype.removeToken = function(index, silent) {\n if (!isNaN(index) && this.inboundIndex(index)) {\n var token = this.tokens.splice(index, 1);\n if (!silent) { this.dispatch('removeToken', [token, index]); }\n return token;\n } else {\n return { FAIL: 'removeToken: invalid token index.' };\n }\n };\n\n /**\n * Insert a list of tokens at a certain index\n * @param {array} tokens a list of tokens to insert\n * @param {number} index insert the list of tokens at index\n * @param {boolean} silent dispatch events and update context ranges\n */\n Tokenizer.prototype.insertToken = function (tokens, index, silent) {\n var tokenType = tokens.every(\n function (token) { return token instanceof Token$1; }\n );\n if (tokenType) {\n this.tokens.splice.apply(\n this.tokens, [index, 0].concat(tokens)\n );\n if (!silent) { this.dispatch('insertToken', [tokens, index]); }\n return tokens;\n } else {\n return { FAIL: 'insertToken: invalid token(s).' };\n }\n };\n\n /**\n * A state modifier that is called on 'newToken' event\n * @param {string} modifierId state modifier id\n * @param {function} condition a predicate function that returns true or false\n * @param {function} modifier a function to update token state\n */\n Tokenizer.prototype.registerModifier = function(modifierId, condition, modifier) {\n this.events.newToken.subscribe(function(token, contextParams) {\n var conditionParams = [token, contextParams];\n var canApplyModifier = (\n condition === null ||\n condition.apply(this, conditionParams) === true\n );\n var modifierParams = [token, contextParams];\n if (canApplyModifier) {\n var newStateValue = modifier.apply(this, modifierParams);\n token.setState(modifierId, newStateValue);\n }\n });\n this.registeredModifiers.push(modifierId);\n };\n\n /**\n * Subscribe a handler to an event\n * @param {function} eventHandler an event handler function\n */\n Event.prototype.subscribe = function (eventHandler) {\n if (typeof eventHandler === 'function') {\n return ((this.subscribers.push(eventHandler)) - 1);\n } else {\n return { FAIL: (\"invalid '\" + (this.eventId) + \"' event handler\")};\n }\n };\n\n /**\n * Unsubscribe an event handler\n * @param {string} subsId subscription id\n */\n Event.prototype.unsubscribe = function (subsId) {\n this.subscribers.splice(subsId, 1);\n };\n\n /**\n * Sets context params current value index\n * @param {number} index context params current value index\n */\n ContextParams.prototype.setCurrentIndex = function(index) {\n this.index = index;\n this.current = this.context[index];\n this.backtrack = this.context.slice(0, index);\n this.lookahead = this.context.slice(index + 1);\n };\n\n /**\n * Get an item at an offset from the current value\n * example (current value is 3):\n * 1 2 [3] 4 5 | items values\n * -2 -1 0 1 2 | offset values\n * @param {number} offset an offset from current value index\n */\n ContextParams.prototype.get = function (offset) {\n switch (true) {\n case (offset === 0):\n return this.current;\n case (offset < 0 && Math.abs(offset) <= this.backtrack.length):\n return this.backtrack.slice(offset)[0];\n case (offset > 0 && offset <= this.lookahead.length):\n return this.lookahead[offset - 1];\n default:\n return null;\n }\n };\n\n /**\n * Converts a context range into a string value\n * @param {contextRange} range a context range\n */\n Tokenizer.prototype.rangeToText = function (range) {\n if (range instanceof ContextRange) {\n return (\n this.getRangeTokens(range)\n .map(function (token) { return token.char; }).join('')\n );\n }\n };\n\n /**\n * Converts all tokens into a string\n */\n Tokenizer.prototype.getText = function () {\n return this.tokens.map(function (token) { return token.char; }).join('');\n };\n\n /**\n * Get a context by name\n * @param {string} contextName context name to get\n */\n Tokenizer.prototype.getContext = function (contextName) {\n var context = this.registeredContexts[contextName];\n return !!context ? context : null;\n };\n\n /**\n * Subscribes a new event handler to an event\n * @param {string} eventName event name to subscribe to\n * @param {function} eventHandler a function to be invoked on event\n */\n Tokenizer.prototype.on = function(eventName, eventHandler) {\n var event = this.events[eventName];\n if (!!event) {\n return event.subscribe(eventHandler);\n } else {\n return null;\n }\n };\n\n /**\n * Dispatches an event\n * @param {string} eventName event name\n * @param {any} args event handler arguments\n */\n Tokenizer.prototype.dispatch = function(eventName, args) {\n var this$1 = this;\n\n var event = this.events[eventName];\n if (event instanceof Event) {\n event.subscribers.forEach(function (subscriber) {\n subscriber.apply(this$1, args || []);\n });\n }\n };\n\n /**\n * Register a new context checker\n * @param {string} contextName a unique context name\n * @param {function} contextStartCheck a predicate function that returns true on context start\n * @param {function} contextEndCheck a predicate function that returns true on context end\n * TODO: call tokenize on registration to update context ranges with the new context.\n */\n Tokenizer.prototype.registerContextChecker = function(contextName, contextStartCheck, contextEndCheck) {\n if (!!this.getContext(contextName)) { return {\n FAIL:\n (\"context name '\" + contextName + \"' is already registered.\")\n }; }\n if (typeof contextStartCheck !== 'function') { return {\n FAIL:\n \"missing context start check.\"\n }; }\n if (typeof contextEndCheck !== 'function') { return {\n FAIL:\n \"missing context end check.\"\n }; }\n var contextCheckers = new ContextChecker(\n contextName, contextStartCheck, contextEndCheck\n );\n this.registeredContexts[contextName] = contextCheckers;\n this.contextCheckers.push(contextCheckers);\n return contextCheckers;\n };\n\n /**\n * Gets a context range tokens\n * @param {contextRange} range a context range\n */\n Tokenizer.prototype.getRangeTokens = function(range) {\n var endIndex = range.startIndex + range.endOffset;\n return [].concat(\n this.tokens\n .slice(range.startIndex, endIndex)\n );\n };\n\n /**\n * Gets the ranges of a context\n * @param {string} contextName context name\n */\n Tokenizer.prototype.getContextRanges = function(contextName) {\n var context = this.getContext(contextName);\n if (!!context) {\n return context.ranges;\n } else {\n return { FAIL: (\"context checker '\" + contextName + \"' is not registered.\") };\n }\n };\n\n /**\n * Resets context ranges to run context update\n */\n Tokenizer.prototype.resetContextsRanges = function () {\n var registeredContexts = this.registeredContexts;\n for (var contextName in registeredContexts) {\n if (registeredContexts.hasOwnProperty(contextName)) {\n var context = registeredContexts[contextName];\n context.ranges = [];\n }\n }\n };\n\n /**\n * Updates context ranges\n */\n Tokenizer.prototype.updateContextsRanges = function () {\n this.resetContextsRanges();\n var chars = this.tokens.map(function (token) { return token.char; });\n for (var i = 0; i < chars.length; i++) {\n var contextParams = new ContextParams(chars, i);\n this.runContextCheck(contextParams);\n }\n this.dispatch('updateContextsRanges', [this.registeredContexts]);\n };\n\n /**\n * Sets the end offset of an open range\n * @param {number} offset range end offset\n * @param {string} contextName context name\n */\n Tokenizer.prototype.setEndOffset = function (offset, contextName) {\n var startIndex = this.getContext(contextName).openRange.startIndex;\n var range = new ContextRange(startIndex, offset, contextName);\n var ranges = this.getContext(contextName).ranges;\n range.rangeId = contextName + \".\" + (ranges.length);\n ranges.push(range);\n this.getContext(contextName).openRange = null;\n return range;\n };\n\n /**\n * Runs a context check on the current context\n * @param {contextParams} contextParams current context params\n */\n Tokenizer.prototype.runContextCheck = function(contextParams) {\n var this$1 = this;\n\n var index = contextParams.index;\n this.contextCheckers.forEach(function (contextChecker) {\n var contextName = contextChecker.contextName;\n var openRange = this$1.getContext(contextName).openRange;\n if (!openRange && contextChecker.checkStart(contextParams)) {\n openRange = new ContextRange(index, null, contextName);\n this$1.getContext(contextName).openRange = openRange;\n this$1.dispatch('contextStart', [contextName, index]);\n }\n if (!!openRange && contextChecker.checkEnd(contextParams)) {\n var offset = (index - openRange.startIndex) + 1;\n var range = this$1.setEndOffset(offset, contextName);\n this$1.dispatch('contextEnd', [contextName, range]);\n }\n });\n };\n\n /**\n * Converts a text into a list of tokens\n * @param {string} text a text to tokenize\n */\n Tokenizer.prototype.tokenize = function (text) {\n this.tokens = [];\n this.resetContextsRanges();\n var chars = Array.from(text);\n this.dispatch('start');\n for (var i = 0; i < chars.length; i++) {\n var char = chars[i];\n var contextParams = new ContextParams(chars, i);\n this.dispatch('next', [contextParams]);\n this.runContextCheck(contextParams);\n var token = new Token$1(char);\n this.tokens.push(token);\n this.dispatch('newToken', [token, contextParams]);\n }\n this.dispatch('end', [this.tokens]);\n return this.tokens;\n };\n\n // ╭─┄┄┄────────────────────────┄─────────────────────────────────────────────╮\n // ┊ Character Class Assertions ┊ Checks if a char belongs to a certain class ┊\n // ╰─╾──────────────────────────┄─────────────────────────────────────────────╯\n // jscs:disable maximumLineLength\n /**\n * Check if a char is Arabic\n * @param {string} c a single char\n */\n function isArabicChar(c) {\n return /[\\u0600-\\u065F\\u066A-\\u06D2\\u06FA-\\u06FF]/.test(c);\n }\n\n /**\n * Check if a char is an isolated arabic char\n * @param {string} c a single char\n */\n function isIsolatedArabicChar(char) {\n return /[\\u0630\\u0690\\u0621\\u0631\\u0661\\u0671\\u0622\\u0632\\u0672\\u0692\\u06C2\\u0623\\u0673\\u0693\\u06C3\\u0624\\u0694\\u06C4\\u0625\\u0675\\u0695\\u06C5\\u06E5\\u0676\\u0696\\u06C6\\u0627\\u0677\\u0697\\u06C7\\u0648\\u0688\\u0698\\u06C8\\u0689\\u0699\\u06C9\\u068A\\u06CA\\u066B\\u068B\\u06CB\\u068C\\u068D\\u06CD\\u06FD\\u068E\\u06EE\\u06FE\\u062F\\u068F\\u06CF\\u06EF]/.test(char);\n }\n\n /**\n * Check if a char is an Arabic Tashkeel char\n * @param {string} c a single char\n */\n function isTashkeelArabicChar(char) {\n return /[\\u0600-\\u0605\\u060C-\\u060E\\u0610-\\u061B\\u061E\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED]/.test(char);\n }\n\n /**\n * Check if a char is Latin\n * @param {string} c a single char\n */\n function isLatinChar(c) {\n return /[A-z]/.test(c);\n }\n\n /**\n * Check if a char is whitespace char\n * @param {string} c a single char\n */\n function isWhiteSpace(c) {\n return /\\s/.test(c);\n }\n\n /**\n * Query a feature by some of it's properties to lookup a glyph substitution.\n */\n\n /**\n * Create feature query instance\n * @param {Font} font opentype font instance\n */\n function FeatureQuery(font) {\n this.font = font;\n this.features = {};\n }\n\n /**\n * @typedef SubstitutionAction\n * @type Object\n * @property {number} id substitution type\n * @property {string} tag feature tag\n * @property {any} substitution substitution value(s)\n */\n\n /**\n * Create a substitution action instance\n * @param {SubstitutionAction} action\n */\n function SubstitutionAction(action) {\n this.id = action.id;\n this.tag = action.tag;\n this.substitution = action.substitution;\n }\n\n /**\n * Lookup a coverage table\n * @param {number} glyphIndex glyph index\n * @param {CoverageTable} coverage coverage table\n */\n function lookupCoverage(glyphIndex, coverage) {\n if (!glyphIndex) { return -1; }\n switch (coverage.format) {\n case 1:\n return coverage.glyphs.indexOf(glyphIndex);\n\n case 2:\n var ranges = coverage.ranges;\n for (var i = 0; i < ranges.length; i++) {\n var range = ranges[i];\n if (glyphIndex >= range.start && glyphIndex <= range.end) {\n var offset = glyphIndex - range.start;\n return range.index + offset;\n }\n }\n break;\n default:\n return -1; // not found\n }\n return -1;\n }\n\n /**\n * Handle a single substitution - format 1\n * @param {ContextParams} contextParams context params to lookup\n */\n function singleSubstitutionFormat1(glyphIndex, subtable) {\n var substituteIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (substituteIndex === -1) { return null; }\n return glyphIndex + subtable.deltaGlyphId;\n }\n\n /**\n * Handle a single substitution - format 2\n * @param {ContextParams} contextParams context params to lookup\n */\n function singleSubstitutionFormat2(glyphIndex, subtable) {\n var substituteIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (substituteIndex === -1) { return null; }\n return subtable.substitute[substituteIndex];\n }\n\n /**\n * Lookup a list of coverage tables\n * @param {any} coverageList a list of coverage tables\n * @param {ContextParams} contextParams context params to lookup\n */\n function lookupCoverageList(coverageList, contextParams) {\n var lookupList = [];\n for (var i = 0; i < coverageList.length; i++) {\n var coverage = coverageList[i];\n var glyphIndex = contextParams.current;\n glyphIndex = Array.isArray(glyphIndex) ? glyphIndex[0] : glyphIndex;\n var lookupIndex = lookupCoverage(glyphIndex, coverage);\n if (lookupIndex !== -1) {\n lookupList.push(lookupIndex);\n }\n }\n if (lookupList.length !== coverageList.length) { return -1; }\n return lookupList;\n }\n\n /**\n * Handle chaining context substitution - format 3\n * @param {ContextParams} contextParams context params to lookup\n */\n function chainingSubstitutionFormat3(contextParams, subtable) {\n var lookupsCount = (\n subtable.inputCoverage.length +\n subtable.lookaheadCoverage.length +\n subtable.backtrackCoverage.length\n );\n if (contextParams.context.length < lookupsCount) { return []; }\n // INPUT LOOKUP //\n var inputLookups = lookupCoverageList(\n subtable.inputCoverage, contextParams\n );\n if (inputLookups === -1) { return []; }\n // LOOKAHEAD LOOKUP //\n var lookaheadOffset = subtable.inputCoverage.length - 1;\n if (contextParams.lookahead.length < subtable.lookaheadCoverage.length) { return []; }\n var lookaheadContext = contextParams.lookahead.slice(lookaheadOffset);\n while (lookaheadContext.length && isTashkeelArabicChar(lookaheadContext[0].char)) {\n lookaheadContext.shift();\n }\n var lookaheadParams = new ContextParams(lookaheadContext, 0);\n var lookaheadLookups = lookupCoverageList(\n subtable.lookaheadCoverage, lookaheadParams\n );\n // BACKTRACK LOOKUP //\n var backtrackContext = [].concat(contextParams.backtrack);\n backtrackContext.reverse();\n while (backtrackContext.length && isTashkeelArabicChar(backtrackContext[0].char)) {\n backtrackContext.shift();\n }\n if (backtrackContext.length < subtable.backtrackCoverage.length) { return []; }\n var backtrackParams = new ContextParams(backtrackContext, 0);\n var backtrackLookups = lookupCoverageList(\n subtable.backtrackCoverage, backtrackParams\n );\n var contextRulesMatch = (\n inputLookups.length === subtable.inputCoverage.length &&\n lookaheadLookups.length === subtable.lookaheadCoverage.length &&\n backtrackLookups.length === subtable.backtrackCoverage.length\n );\n var substitutions = [];\n if (contextRulesMatch) {\n for (var i = 0; i < subtable.lookupRecords.length; i++) {\n var lookupRecord = subtable.lookupRecords[i];\n var lookupListIndex = lookupRecord.lookupListIndex;\n var lookupTable = this.getLookupByIndex(lookupListIndex);\n for (var s = 0; s < lookupTable.subtables.length; s++) {\n var subtable$1 = lookupTable.subtables[s];\n var lookup = this.getLookupMethod(lookupTable, subtable$1);\n var substitutionType = this.getSubstitutionType(lookupTable, subtable$1);\n if (substitutionType === '12') {\n for (var n = 0; n < inputLookups.length; n++) {\n var glyphIndex = contextParams.get(n);\n var substitution = lookup(glyphIndex);\n if (substitution) { substitutions.push(substitution); }\n }\n }\n }\n }\n }\n return substitutions;\n }\n\n /**\n * Handle ligature substitution - format 1\n * @param {ContextParams} contextParams context params to lookup\n */\n function ligatureSubstitutionFormat1(contextParams, subtable) {\n // COVERAGE LOOKUP //\n var glyphIndex = contextParams.current;\n var ligSetIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (ligSetIndex === -1) { return null; }\n // COMPONENTS LOOKUP\n // (!) note, components are ordered in the written direction.\n var ligature;\n var ligatureSet = subtable.ligatureSets[ligSetIndex];\n for (var s = 0; s < ligatureSet.length; s++) {\n ligature = ligatureSet[s];\n for (var l = 0; l < ligature.components.length; l++) {\n var lookaheadItem = contextParams.lookahead[l];\n var component = ligature.components[l];\n if (lookaheadItem !== component) { break; }\n if (l === ligature.components.length - 1) { return ligature; }\n }\n }\n return null;\n }\n\n /**\n * Handle decomposition substitution - format 1\n * @param {number} glyphIndex glyph index\n * @param {any} subtable subtable\n */\n function decompositionSubstitutionFormat1(glyphIndex, subtable) {\n var substituteIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (substituteIndex === -1) { return null; }\n return subtable.sequences[substituteIndex];\n }\n\n /**\n * Get default script features indexes\n */\n FeatureQuery.prototype.getDefaultScriptFeaturesIndexes = function () {\n var scripts = this.font.tables.gsub.scripts;\n for (var s = 0; s < scripts.length; s++) {\n var script = scripts[s];\n if (script.tag === 'DFLT') { return (\n script.script.defaultLangSys.featureIndexes\n ); }\n }\n return [];\n };\n\n /**\n * Get feature indexes of a specific script\n * @param {string} scriptTag script tag\n */\n FeatureQuery.prototype.getScriptFeaturesIndexes = function(scriptTag) {\n var tables = this.font.tables;\n if (!tables.gsub) { return []; }\n if (!scriptTag) { return this.getDefaultScriptFeaturesIndexes(); }\n var scripts = this.font.tables.gsub.scripts;\n for (var i = 0; i < scripts.length; i++) {\n var script = scripts[i];\n if (script.tag === scriptTag && script.script.defaultLangSys) {\n return script.script.defaultLangSys.featureIndexes;\n } else {\n var langSysRecords = script.langSysRecords;\n if (!!langSysRecords) {\n for (var j = 0; j < langSysRecords.length; j++) {\n var langSysRecord = langSysRecords[j];\n if (langSysRecord.tag === scriptTag) {\n var langSys = langSysRecord.langSys;\n return langSys.featureIndexes;\n }\n }\n }\n }\n }\n return this.getDefaultScriptFeaturesIndexes();\n };\n\n /**\n * Map a feature tag to a gsub feature\n * @param {any} features gsub features\n * @param {string} scriptTag script tag\n */\n FeatureQuery.prototype.mapTagsToFeatures = function (features, scriptTag) {\n var tags = {};\n for (var i = 0; i < features.length; i++) {\n var tag = features[i].tag;\n var feature = features[i].feature;\n tags[tag] = feature;\n }\n this.features[scriptTag].tags = tags;\n };\n\n /**\n * Get features of a specific script\n * @param {string} scriptTag script tag\n */\n FeatureQuery.prototype.getScriptFeatures = function (scriptTag) {\n var features = this.features[scriptTag];\n if (this.features.hasOwnProperty(scriptTag)) { return features; }\n var featuresIndexes = this.getScriptFeaturesIndexes(scriptTag);\n if (!featuresIndexes) { return null; }\n var gsub = this.font.tables.gsub;\n features = featuresIndexes.map(function (index) { return gsub.features[index]; });\n this.features[scriptTag] = features;\n this.mapTagsToFeatures(features, scriptTag);\n return features;\n };\n\n /**\n * Get substitution type\n * @param {any} lookupTable lookup table\n * @param {any} subtable subtable\n */\n FeatureQuery.prototype.getSubstitutionType = function(lookupTable, subtable) {\n var lookupType = lookupTable.lookupType.toString();\n var substFormat = subtable.substFormat.toString();\n return lookupType + substFormat;\n };\n\n /**\n * Get lookup method\n * @param {any} lookupTable lookup table\n * @param {any} subtable subtable\n */\n FeatureQuery.prototype.getLookupMethod = function(lookupTable, subtable) {\n var this$1 = this;\n\n var substitutionType = this.getSubstitutionType(lookupTable, subtable);\n switch (substitutionType) {\n case '11':\n return function (glyphIndex) { return singleSubstitutionFormat1.apply(\n this$1, [glyphIndex, subtable]\n ); };\n case '12':\n return function (glyphIndex) { return singleSubstitutionFormat2.apply(\n this$1, [glyphIndex, subtable]\n ); };\n case '63':\n return function (contextParams) { return chainingSubstitutionFormat3.apply(\n this$1, [contextParams, subtable]\n ); };\n case '41':\n return function (contextParams) { return ligatureSubstitutionFormat1.apply(\n this$1, [contextParams, subtable]\n ); };\n case '21':\n return function (glyphIndex) { return decompositionSubstitutionFormat1.apply(\n this$1, [glyphIndex, subtable]\n ); };\n default:\n throw new Error(\n \"lookupType: \" + (lookupTable.lookupType) + \" - \" +\n \"substFormat: \" + (subtable.substFormat) + \" \" +\n \"is not yet supported\"\n );\n }\n };\n\n /**\n * [ LOOKUP TYPES ]\n * -------------------------------\n * Single 1;\n * Multiple 2;\n * Alternate 3;\n * Ligature 4;\n * Context 5;\n * ChainingContext 6;\n * ExtensionSubstitution 7;\n * ReverseChainingContext 8;\n * -------------------------------\n *\n */\n\n /**\n * @typedef FQuery\n * @type Object\n * @param {string} tag feature tag\n * @param {string} script feature script\n * @param {ContextParams} contextParams context params\n */\n\n /**\n * Lookup a feature using a query parameters\n * @param {FQuery} query feature query\n */\n FeatureQuery.prototype.lookupFeature = function (query) {\n var contextParams = query.contextParams;\n var currentIndex = contextParams.index;\n var feature = this.getFeature({\n tag: query.tag, script: query.script\n });\n if (!feature) { return new Error(\n \"font '\" + (this.font.names.fullName.en) + \"' \" +\n \"doesn't support feature '\" + (query.tag) + \"' \" +\n \"for script '\" + (query.script) + \"'.\"\n ); }\n var lookups = this.getFeatureLookups(feature);\n var substitutions = [].concat(contextParams.context);\n for (var l = 0; l < lookups.length; l++) {\n var lookupTable = lookups[l];\n var subtables = this.getLookupSubtables(lookupTable);\n for (var s = 0; s < subtables.length; s++) {\n var subtable = subtables[s];\n var substType = this.getSubstitutionType(lookupTable, subtable);\n var lookup = this.getLookupMethod(lookupTable, subtable);\n var substitution = (void 0);\n switch (substType) {\n case '11':\n substitution = lookup(contextParams.current);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 11, tag: query.tag, substitution: substitution\n }));\n }\n break;\n case '12':\n substitution = lookup(contextParams.current);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 12, tag: query.tag, substitution: substitution\n }));\n }\n break;\n case '63':\n substitution = lookup(contextParams);\n if (Array.isArray(substitution) && substitution.length) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 63, tag: query.tag, substitution: substitution\n }));\n }\n break;\n case '41':\n substitution = lookup(contextParams);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 41, tag: query.tag, substitution: substitution\n }));\n }\n break;\n case '21':\n substitution = lookup(contextParams.current);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 21, tag: query.tag, substitution: substitution\n }));\n }\n break;\n }\n contextParams = new ContextParams(substitutions, currentIndex);\n if (Array.isArray(substitution) && !substitution.length) { continue; }\n substitution = null;\n }\n }\n return substitutions.length ? substitutions : null;\n };\n\n /**\n * Checks if a font supports a specific features\n * @param {FQuery} query feature query object\n */\n FeatureQuery.prototype.supports = function (query) {\n if (!query.script) { return false; }\n this.getScriptFeatures(query.script);\n var supportedScript = this.features.hasOwnProperty(query.script);\n if (!query.tag) { return supportedScript; }\n var supportedFeature = (\n this.features[query.script].some(function (feature) { return feature.tag === query.tag; })\n );\n return supportedScript && supportedFeature;\n };\n\n /**\n * Get lookup table subtables\n * @param {any} lookupTable lookup table\n */\n FeatureQuery.prototype.getLookupSubtables = function (lookupTable) {\n return lookupTable.subtables || null;\n };\n\n /**\n * Get lookup table by index\n * @param {number} index lookup table index\n */\n FeatureQuery.prototype.getLookupByIndex = function (index) {\n var lookups = this.font.tables.gsub.lookups;\n return lookups[index] || null;\n };\n\n /**\n * Get lookup tables for a feature\n * @param {string} feature\n */\n FeatureQuery.prototype.getFeatureLookups = function (feature) {\n // TODO: memoize\n return feature.lookupListIndexes.map(this.getLookupByIndex.bind(this));\n };\n\n /**\n * Query a feature by it's properties\n * @param {any} query an object that describes the properties of a query\n */\n FeatureQuery.prototype.getFeature = function getFeature(query) {\n if (!this.font) { return { FAIL: \"No font was found\"}; }\n if (!this.features.hasOwnProperty(query.script)) {\n this.getScriptFeatures(query.script);\n }\n var scriptFeatures = this.features[query.script];\n if (!scriptFeatures) { return (\n { FAIL: (\"No feature for script \" + (query.script))}\n ); }\n if (!scriptFeatures.tags[query.tag]) { return null; }\n return this.features[query.script].tags[query.tag];\n };\n\n /**\n * Arabic word context checkers\n */\n\n function arabicWordStartCheck(contextParams) {\n var char = contextParams.current;\n var prevChar = contextParams.get(-1);\n return (\n // ? arabic first char\n (prevChar === null && isArabicChar(char)) ||\n // ? arabic char preceded with a non arabic char\n (!isArabicChar(prevChar) && isArabicChar(char))\n );\n }\n\n function arabicWordEndCheck(contextParams) {\n var nextChar = contextParams.get(1);\n return (\n // ? last arabic char\n (nextChar === null) ||\n // ? next char is not arabic\n (!isArabicChar(nextChar))\n );\n }\n\n var arabicWordCheck = {\n startCheck: arabicWordStartCheck,\n endCheck: arabicWordEndCheck\n };\n\n /**\n * Arabic sentence context checkers\n */\n\n function arabicSentenceStartCheck(contextParams) {\n var char = contextParams.current;\n var prevChar = contextParams.get(-1);\n return (\n // ? an arabic char preceded with a non arabic char\n (isArabicChar(char) || isTashkeelArabicChar(char)) &&\n !isArabicChar(prevChar)\n );\n }\n\n function arabicSentenceEndCheck(contextParams) {\n var nextChar = contextParams.get(1);\n switch (true) {\n case nextChar === null:\n return true;\n case (!isArabicChar(nextChar) && !isTashkeelArabicChar(nextChar)):\n var nextIsWhitespace = isWhiteSpace(nextChar);\n if (!nextIsWhitespace) { return true; }\n if (nextIsWhitespace) {\n var arabicCharAhead = false;\n arabicCharAhead = (\n contextParams.lookahead.some(\n function (c) { return isArabicChar(c) || isTashkeelArabicChar(c); }\n )\n );\n if (!arabicCharAhead) { return true; }\n }\n break;\n default:\n return false;\n }\n }\n\n var arabicSentenceCheck = {\n startCheck: arabicSentenceStartCheck,\n endCheck: arabicSentenceEndCheck\n };\n\n /**\n * Apply single substitution format 1\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\n function singleSubstitutionFormat1$1(action, tokens, index) {\n tokens[index].setState(action.tag, action.substitution);\n }\n\n /**\n * Apply single substitution format 2\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\n function singleSubstitutionFormat2$1(action, tokens, index) {\n tokens[index].setState(action.tag, action.substitution);\n }\n\n /**\n * Apply chaining context substitution format 3\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\n function chainingSubstitutionFormat3$1(action, tokens, index) {\n action.substitution.forEach(function (subst, offset) {\n var token = tokens[index + offset];\n token.setState(action.tag, subst);\n });\n }\n\n /**\n * Apply ligature substitution format 1\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\n function ligatureSubstitutionFormat1$1(action, tokens, index) {\n var token = tokens[index];\n token.setState(action.tag, action.substitution.ligGlyph);\n var compsCount = action.substitution.components.length;\n for (var i = 0; i < compsCount; i++) {\n token = tokens[index + i + 1];\n token.setState('deleted', true);\n }\n }\n\n /**\n * Supported substitutions\n */\n var SUBSTITUTIONS = {\n 11: singleSubstitutionFormat1$1,\n 12: singleSubstitutionFormat2$1,\n 63: chainingSubstitutionFormat3$1,\n 41: ligatureSubstitutionFormat1$1\n };\n\n /**\n * Apply substitutions to a list of tokens\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\n function applySubstitution(action, tokens, index) {\n if (action instanceof SubstitutionAction && SUBSTITUTIONS[action.id]) {\n SUBSTITUTIONS[action.id](action, tokens, index);\n }\n }\n\n /**\n * Apply Arabic presentation forms to a range of tokens\n */\n\n /**\n * Check if a char can be connected to it's preceding char\n * @param {ContextParams} charContextParams context params of a char\n */\n function willConnectPrev(charContextParams) {\n var backtrack = [].concat(charContextParams.backtrack);\n for (var i = backtrack.length - 1; i >= 0; i--) {\n var prevChar = backtrack[i];\n var isolated = isIsolatedArabicChar(prevChar);\n var tashkeel = isTashkeelArabicChar(prevChar);\n if (!isolated && !tashkeel) { return true; }\n if (isolated) { return false; }\n }\n return false;\n }\n\n /**\n * Check if a char can be connected to it's proceeding char\n * @param {ContextParams} charContextParams context params of a char\n */\n function willConnectNext(charContextParams) {\n if (isIsolatedArabicChar(charContextParams.current)) { return false; }\n for (var i = 0; i < charContextParams.lookahead.length; i++) {\n var nextChar = charContextParams.lookahead[i];\n var tashkeel = isTashkeelArabicChar(nextChar);\n if (!tashkeel) { return true; }\n }\n return false;\n }\n\n /**\n * Apply arabic presentation forms to a list of tokens\n * @param {ContextRange} range a range of tokens\n */\n function arabicPresentationForms(range) {\n var this$1 = this;\n\n var script = 'arab';\n var tags = this.featuresTags[script];\n var tokens = this.tokenizer.getRangeTokens(range);\n if (tokens.length === 1) { return; }\n var contextParams = new ContextParams(\n tokens.map(function (token) { return token.getState('glyphIndex'); }\n ), 0);\n var charContextParams = new ContextParams(\n tokens.map(function (token) { return token.char; }\n ), 0);\n tokens.forEach(function (token, index) {\n if (isTashkeelArabicChar(token.char)) { return; }\n contextParams.setCurrentIndex(index);\n charContextParams.setCurrentIndex(index);\n var CONNECT = 0; // 2 bits 00 (10: can connect next) (01: can connect prev)\n if (willConnectPrev(charContextParams)) { CONNECT |= 1; }\n if (willConnectNext(charContextParams)) { CONNECT |= 2; }\n var tag;\n switch (CONNECT) {\n case 1: (tag = 'fina'); break;\n case 2: (tag = 'init'); break;\n case 3: (tag = 'medi'); break;\n }\n if (tags.indexOf(tag) === -1) { return; }\n var substitutions = this$1.query.lookupFeature({\n tag: tag, script: script, contextParams: contextParams\n });\n if (substitutions instanceof Error) { return console.info(substitutions.message); }\n substitutions.forEach(function (action, index) {\n if (action instanceof SubstitutionAction) {\n applySubstitution(action, tokens, index);\n contextParams.context[index] = action.substitution;\n }\n });\n });\n }\n\n /**\n * Apply Arabic required ligatures feature to a range of tokens\n */\n\n /**\n * Update context params\n * @param {any} tokens a list of tokens\n * @param {number} index current item index\n */\n function getContextParams(tokens, index) {\n var context = tokens.map(function (token) { return token.activeState.value; });\n return new ContextParams(context, index || 0);\n }\n\n /**\n * Apply Arabic required ligatures to a context range\n * @param {ContextRange} range a range of tokens\n */\n function arabicRequiredLigatures(range) {\n var this$1 = this;\n\n var script = 'arab';\n var tokens = this.tokenizer.getRangeTokens(range);\n var contextParams = getContextParams(tokens);\n contextParams.context.forEach(function (glyphIndex, index) {\n contextParams.setCurrentIndex(index);\n var substitutions = this$1.query.lookupFeature({\n tag: 'rlig', script: script, contextParams: contextParams\n });\n if (substitutions.length) {\n substitutions.forEach(\n function (action) { return applySubstitution(action, tokens, index); }\n );\n contextParams = getContextParams(tokens);\n }\n });\n }\n\n /**\n * Latin word context checkers\n */\n\n function latinWordStartCheck(contextParams) {\n var char = contextParams.current;\n var prevChar = contextParams.get(-1);\n return (\n // ? latin first char\n (prevChar === null && isLatinChar(char)) ||\n // ? latin char preceded with a non latin char\n (!isLatinChar(prevChar) && isLatinChar(char))\n );\n }\n\n function latinWordEndCheck(contextParams) {\n var nextChar = contextParams.get(1);\n return (\n // ? last latin char\n (nextChar === null) ||\n // ? next char is not latin\n (!isLatinChar(nextChar))\n );\n }\n\n var latinWordCheck = {\n startCheck: latinWordStartCheck,\n endCheck: latinWordEndCheck\n };\n\n /**\n * Apply Latin ligature feature to a range of tokens\n */\n\n /**\n * Update context params\n * @param {any} tokens a list of tokens\n * @param {number} index current item index\n */\n function getContextParams$1(tokens, index) {\n var context = tokens.map(function (token) { return token.activeState.value; });\n return new ContextParams(context, index || 0);\n }\n\n /**\n * Apply Arabic required ligatures to a context range\n * @param {ContextRange} range a range of tokens\n */\n function latinLigature(range) {\n var this$1 = this;\n\n var script = 'latn';\n var tokens = this.tokenizer.getRangeTokens(range);\n var contextParams = getContextParams$1(tokens);\n contextParams.context.forEach(function (glyphIndex, index) {\n contextParams.setCurrentIndex(index);\n var substitutions = this$1.query.lookupFeature({\n tag: 'liga', script: script, contextParams: contextParams\n });\n if (substitutions.length) {\n substitutions.forEach(\n function (action) { return applySubstitution(action, tokens, index); }\n );\n contextParams = getContextParams$1(tokens);\n }\n });\n }\n\n /**\n * Infer bidirectional properties for a given text and apply\n * the corresponding layout rules.\n */\n\n /**\n * Create Bidi. features\n * @param {string} baseDir text base direction. value either 'ltr' or 'rtl'\n */\n function Bidi(baseDir) {\n this.baseDir = baseDir || 'ltr';\n this.tokenizer = new Tokenizer();\n this.featuresTags = {};\n }\n\n /**\n * Sets Bidi text\n * @param {string} text a text input\n */\n Bidi.prototype.setText = function (text) {\n this.text = text;\n };\n\n /**\n * Store essential context checks:\n * arabic word check for applying gsub features\n * arabic sentence check for adjusting arabic layout\n */\n Bidi.prototype.contextChecks = ({\n latinWordCheck: latinWordCheck,\n arabicWordCheck: arabicWordCheck,\n arabicSentenceCheck: arabicSentenceCheck\n });\n\n /**\n * Register arabic word check\n */\n function registerContextChecker(checkId) {\n var check = this.contextChecks[(checkId + \"Check\")];\n return this.tokenizer.registerContextChecker(\n checkId, check.startCheck, check.endCheck\n );\n }\n\n /**\n * Perform pre tokenization procedure then\n * tokenize text input\n */\n function tokenizeText() {\n registerContextChecker.call(this, 'latinWord');\n registerContextChecker.call(this, 'arabicWord');\n registerContextChecker.call(this, 'arabicSentence');\n return this.tokenizer.tokenize(this.text);\n }\n\n /**\n * Reverse arabic sentence layout\n * TODO: check base dir before applying adjustments - priority low\n */\n function reverseArabicSentences() {\n var this$1 = this;\n\n var ranges = this.tokenizer.getContextRanges('arabicSentence');\n ranges.forEach(function (range) {\n var rangeTokens = this$1.tokenizer.getRangeTokens(range);\n this$1.tokenizer.replaceRange(\n range.startIndex,\n range.endOffset,\n rangeTokens.reverse()\n );\n });\n }\n\n /**\n * Register supported features tags\n * @param {script} script script tag\n * @param {Array} tags features tags list\n */\n Bidi.prototype.registerFeatures = function (script, tags) {\n var this$1 = this;\n\n var supportedTags = tags.filter(\n function (tag) { return this$1.query.supports({script: script, tag: tag}); }\n );\n if (!this.featuresTags.hasOwnProperty(script)) {\n this.featuresTags[script] = supportedTags;\n } else {\n this.featuresTags[script] =\n this.featuresTags[script].concat(supportedTags);\n }\n };\n\n /**\n * Apply GSUB features\n * @param {Array} tagsList a list of features tags\n * @param {string} script a script tag\n * @param {Font} font opentype font instance\n */\n Bidi.prototype.applyFeatures = function (font, features) {\n if (!font) { throw new Error(\n 'No valid font was provided to apply features'\n ); }\n if (!this.query) { this.query = new FeatureQuery(font); }\n for (var f = 0; f < features.length; f++) {\n var feature = features[f];\n if (!this.query.supports({script: feature.script})) { continue; }\n this.registerFeatures(feature.script, feature.tags);\n }\n };\n\n /**\n * Register a state modifier\n * @param {string} modifierId state modifier id\n * @param {function} condition a predicate function that returns true or false\n * @param {function} modifier a modifier function to set token state\n */\n Bidi.prototype.registerModifier = function (modifierId, condition, modifier) {\n this.tokenizer.registerModifier(modifierId, condition, modifier);\n };\n\n /**\n * Check if 'glyphIndex' is registered\n */\n function checkGlyphIndexStatus() {\n if (this.tokenizer.registeredModifiers.indexOf('glyphIndex') === -1) {\n throw new Error(\n 'glyphIndex modifier is required to apply ' +\n 'arabic presentation features.'\n );\n }\n }\n\n /**\n * Apply arabic presentation forms features\n */\n function applyArabicPresentationForms() {\n var this$1 = this;\n\n var script = 'arab';\n if (!this.featuresTags.hasOwnProperty(script)) { return; }\n checkGlyphIndexStatus.call(this);\n var ranges = this.tokenizer.getContextRanges('arabicWord');\n ranges.forEach(function (range) {\n arabicPresentationForms.call(this$1, range);\n });\n }\n\n /**\n * Apply required arabic ligatures\n */\n function applyArabicRequireLigatures() {\n var this$1 = this;\n\n var script = 'arab';\n if (!this.featuresTags.hasOwnProperty(script)) { return; }\n var tags = this.featuresTags[script];\n if (tags.indexOf('rlig') === -1) { return; }\n checkGlyphIndexStatus.call(this);\n var ranges = this.tokenizer.getContextRanges('arabicWord');\n ranges.forEach(function (range) {\n arabicRequiredLigatures.call(this$1, range);\n });\n }\n\n /**\n * Apply required arabic ligatures\n */\n function applyLatinLigatures() {\n var this$1 = this;\n\n var script = 'latn';\n if (!this.featuresTags.hasOwnProperty(script)) { return; }\n var tags = this.featuresTags[script];\n if (tags.indexOf('liga') === -1) { return; }\n checkGlyphIndexStatus.call(this);\n var ranges = this.tokenizer.getContextRanges('latinWord');\n ranges.forEach(function (range) {\n latinLigature.call(this$1, range);\n });\n }\n\n /**\n * Check if a context is registered\n * @param {string} contextId context id\n */\n Bidi.prototype.checkContextReady = function (contextId) {\n return !!this.tokenizer.getContext(contextId);\n };\n\n /**\n * Apply features to registered contexts\n */\n Bidi.prototype.applyFeaturesToContexts = function () {\n if (this.checkContextReady('arabicWord')) {\n applyArabicPresentationForms.call(this);\n applyArabicRequireLigatures.call(this);\n }\n if (this.checkContextReady('latinWord')) {\n applyLatinLigatures.call(this);\n }\n if (this.checkContextReady('arabicSentence')) {\n reverseArabicSentences.call(this);\n }\n };\n\n /**\n * process text input\n * @param {string} text an input text\n */\n Bidi.prototype.processText = function(text) {\n if (!this.text || this.text !== text) {\n this.setText(text);\n tokenizeText.call(this);\n this.applyFeaturesToContexts();\n }\n };\n\n /**\n * Process a string of text to identify and adjust\n * bidirectional text entities.\n * @param {string} text input text\n */\n Bidi.prototype.getBidiText = function (text) {\n this.processText(text);\n return this.tokenizer.getText();\n };\n\n /**\n * Get the current state index of each token\n * @param {text} text an input text\n */\n Bidi.prototype.getTextGlyphs = function (text) {\n this.processText(text);\n var indexes = [];\n for (var i = 0; i < this.tokenizer.tokens.length; i++) {\n var token = this.tokenizer.tokens[i];\n if (token.state.deleted) { continue; }\n var index = token.activeState.value;\n indexes.push(Array.isArray(index) ? index[0] : index);\n }\n return indexes;\n };\n\n // The Font object\n\n /**\n * @typedef FontOptions\n * @type Object\n * @property {Boolean} empty - whether to create a new empty font\n * @property {string} familyName\n * @property {string} styleName\n * @property {string=} fullName\n * @property {string=} postScriptName\n * @property {string=} designer\n * @property {string=} designerURL\n * @property {string=} manufacturer\n * @property {string=} manufacturerURL\n * @property {string=} license\n * @property {string=} licenseURL\n * @property {string=} version\n * @property {string=} description\n * @property {string=} copyright\n * @property {string=} trademark\n * @property {Number} unitsPerEm\n * @property {Number} ascender\n * @property {Number} descender\n * @property {Number} createdTimestamp\n * @property {string=} weightClass\n * @property {string=} widthClass\n * @property {string=} fsSelection\n */\n\n /**\n * A Font represents a loaded OpenType font file.\n * It contains a set of glyphs and methods to draw text on a drawing context,\n * or to get a path representing the text.\n * @exports opentype.Font\n * @class\n * @param {FontOptions}\n * @constructor\n */\n function Font(options) {\n options = options || {};\n options.tables = options.tables || {};\n\n if (!options.empty) {\n // Check that we've provided the minimum set of names.\n checkArgument(options.familyName, 'When creating a new Font object, familyName is required.');\n checkArgument(options.styleName, 'When creating a new Font object, styleName is required.');\n checkArgument(options.unitsPerEm, 'When creating a new Font object, unitsPerEm is required.');\n checkArgument(options.ascender, 'When creating a new Font object, ascender is required.');\n checkArgument(options.descender <= 0, 'When creating a new Font object, negative descender value is required.');\n\n // OS X will complain if the names are empty, so we put a single space everywhere by default.\n this.names = {\n fontFamily: {en: options.familyName || ' '},\n fontSubfamily: {en: options.styleName || ' '},\n fullName: {en: options.fullName || options.familyName + ' ' + options.styleName},\n // postScriptName may not contain any whitespace\n postScriptName: {en: options.postScriptName || (options.familyName + options.styleName).replace(/\\s/g, '')},\n designer: {en: options.designer || ' '},\n designerURL: {en: options.designerURL || ' '},\n manufacturer: {en: options.manufacturer || ' '},\n manufacturerURL: {en: options.manufacturerURL || ' '},\n license: {en: options.license || ' '},\n licenseURL: {en: options.licenseURL || ' '},\n version: {en: options.version || 'Version 0.1'},\n description: {en: options.description || ' '},\n copyright: {en: options.copyright || ' '},\n trademark: {en: options.trademark || ' '}\n };\n this.unitsPerEm = options.unitsPerEm || 1000;\n this.ascender = options.ascender;\n this.descender = options.descender;\n this.createdTimestamp = options.createdTimestamp;\n this.tables = Object.assign(options.tables, {\n os2: Object.assign({\n usWeightClass: options.weightClass || this.usWeightClasses.MEDIUM,\n usWidthClass: options.widthClass || this.usWidthClasses.MEDIUM,\n fsSelection: options.fsSelection || this.fsSelectionValues.REGULAR,\n }, options.tables.os2)\n });\n }\n\n this.supported = true; // Deprecated: parseBuffer will throw an error if font is not supported.\n this.glyphs = new glyphset.GlyphSet(this, options.glyphs || []);\n this.encoding = new DefaultEncoding(this);\n this.position = new Position(this);\n this.substitution = new Substitution(this);\n this.tables = this.tables || {};\n\n // needed for low memory mode only.\n this._push = null;\n this._hmtxTableData = {};\n\n Object.defineProperty(this, 'hinting', {\n get: function() {\n if (this._hinting) { return this._hinting; }\n if (this.outlinesFormat === 'truetype') {\n return (this._hinting = new Hinting(this));\n }\n }\n });\n }\n\n /**\n * Check if the font has a glyph for the given character.\n * @param {string}\n * @return {Boolean}\n */\n Font.prototype.hasChar = function(c) {\n return this.encoding.charToGlyphIndex(c) !== null;\n };\n\n /**\n * Convert the given character to a single glyph index.\n * Note that this function assumes that there is a one-to-one mapping between\n * the given character and a glyph; for complex scripts this might not be the case.\n * @param {string}\n * @return {Number}\n */\n Font.prototype.charToGlyphIndex = function(s) {\n return this.encoding.charToGlyphIndex(s);\n };\n\n /**\n * Convert the given character to a single Glyph object.\n * Note that this function assumes that there is a one-to-one mapping between\n * the given character and a glyph; for complex scripts this might not be the case.\n * @param {string}\n * @return {opentype.Glyph}\n */\n Font.prototype.charToGlyph = function(c) {\n var glyphIndex = this.charToGlyphIndex(c);\n var glyph = this.glyphs.get(glyphIndex);\n if (!glyph) {\n // .notdef\n glyph = this.glyphs.get(0);\n }\n\n return glyph;\n };\n\n /**\n * Update features\n * @param {any} options features options\n */\n Font.prototype.updateFeatures = function (options) {\n // TODO: update all features options not only 'latn'.\n return this.defaultRenderOptions.features.map(function (feature) {\n if (feature.script === 'latn') {\n return {\n script: 'latn',\n tags: feature.tags.filter(function (tag) { return options[tag]; })\n };\n } else {\n return feature;\n }\n });\n };\n\n /**\n * Convert the given text to a list of Glyph objects.\n * Note that there is no strict one-to-one mapping between characters and\n * glyphs, so the list of returned glyphs can be larger or smaller than the\n * length of the given string.\n * @param {string}\n * @param {GlyphRenderOptions} [options]\n * @return {opentype.Glyph[]}\n */\n Font.prototype.stringToGlyphs = function(s, options) {\n var this$1 = this;\n\n\n var bidi = new Bidi();\n\n // Create and register 'glyphIndex' state modifier\n var charToGlyphIndexMod = function (token) { return this$1.charToGlyphIndex(token.char); };\n bidi.registerModifier('glyphIndex', null, charToGlyphIndexMod);\n\n // roll-back to default features\n var features = options ?\n this.updateFeatures(options.features) :\n this.defaultRenderOptions.features;\n\n bidi.applyFeatures(this, features);\n\n var indexes = bidi.getTextGlyphs(s);\n\n var length = indexes.length;\n\n // convert glyph indexes to glyph objects\n var glyphs = new Array(length);\n var notdef = this.glyphs.get(0);\n for (var i = 0; i < length; i += 1) {\n glyphs[i] = this.glyphs.get(indexes[i]) || notdef;\n }\n return glyphs;\n };\n\n /**\n * @param {string}\n * @return {Number}\n */\n Font.prototype.nameToGlyphIndex = function(name) {\n return this.glyphNames.nameToGlyphIndex(name);\n };\n\n /**\n * @param {string}\n * @return {opentype.Glyph}\n */\n Font.prototype.nameToGlyph = function(name) {\n var glyphIndex = this.nameToGlyphIndex(name);\n var glyph = this.glyphs.get(glyphIndex);\n if (!glyph) {\n // .notdef\n glyph = this.glyphs.get(0);\n }\n\n return glyph;\n };\n\n /**\n * @param {Number}\n * @return {String}\n */\n Font.prototype.glyphIndexToName = function(gid) {\n if (!this.glyphNames.glyphIndexToName) {\n return '';\n }\n\n return this.glyphNames.glyphIndexToName(gid);\n };\n\n /**\n * Retrieve the value of the kerning pair between the left glyph (or its index)\n * and the right glyph (or its index). If no kerning pair is found, return 0.\n * The kerning value gets added to the advance width when calculating the spacing\n * between glyphs.\n * For GPOS kerning, this method uses the default script and language, which covers\n * most use cases. To have greater control, use font.position.getKerningValue .\n * @param {opentype.Glyph} leftGlyph\n * @param {opentype.Glyph} rightGlyph\n * @return {Number}\n */\n Font.prototype.getKerningValue = function(leftGlyph, rightGlyph) {\n leftGlyph = leftGlyph.index || leftGlyph;\n rightGlyph = rightGlyph.index || rightGlyph;\n var gposKerning = this.position.defaultKerningTables;\n if (gposKerning) {\n return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph);\n }\n // \"kern\" table\n return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0;\n };\n\n /**\n * @typedef GlyphRenderOptions\n * @type Object\n * @property {string} [script] - script used to determine which features to apply. By default, 'DFLT' or 'latn' is used.\n * See https://www.microsoft.com/typography/otspec/scripttags.htm\n * @property {string} [language='dflt'] - language system used to determine which features to apply.\n * See https://www.microsoft.com/typography/developers/opentype/languagetags.aspx\n * @property {boolean} [kerning=true] - whether to include kerning values\n * @property {object} [features] - OpenType Layout feature tags. Used to enable or disable the features of the given script/language system.\n * See https://www.microsoft.com/typography/otspec/featuretags.htm\n */\n Font.prototype.defaultRenderOptions = {\n kerning: true,\n features: [\n /**\n * these 4 features are required to render Arabic text properly\n * and shouldn't be turned off when rendering arabic text.\n */\n { script: 'arab', tags: ['init', 'medi', 'fina', 'rlig'] },\n { script: 'latn', tags: ['liga', 'rlig'] }\n ]\n };\n\n /**\n * Helper function that invokes the given callback for each glyph in the given text.\n * The callback gets `(glyph, x, y, fontSize, options)`.* @param {string} text\n * @param {string} text - The text to apply.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @param {Function} callback\n */\n Font.prototype.forEachGlyph = function(text, x, y, fontSize, options, callback) {\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 72;\n options = Object.assign({}, this.defaultRenderOptions, options);\n var fontScale = 1 / this.unitsPerEm * fontSize;\n var glyphs = this.stringToGlyphs(text, options);\n var kerningLookups;\n if (options.kerning) {\n var script = options.script || this.position.getDefaultScriptName();\n kerningLookups = this.position.getKerningTables(script, options.language);\n }\n for (var i = 0; i < glyphs.length; i += 1) {\n var glyph = glyphs[i];\n callback.call(this, glyph, x, y, fontSize, options);\n if (glyph.advanceWidth) {\n x += glyph.advanceWidth * fontScale;\n }\n\n if (options.kerning && i < glyphs.length - 1) {\n // We should apply position adjustment lookups in a more generic way.\n // Here we only use the xAdvance value.\n var kerningValue = kerningLookups ?\n this.position.getKerningValue(kerningLookups, glyph.index, glyphs[i + 1].index) :\n this.getKerningValue(glyph, glyphs[i + 1]);\n x += kerningValue * fontScale;\n }\n\n if (options.letterSpacing) {\n x += options.letterSpacing * fontSize;\n } else if (options.tracking) {\n x += (options.tracking / 1000) * fontSize;\n }\n }\n return x;\n };\n\n /**\n * Create a Path object that represents the given text.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @return {opentype.Path}\n */\n Font.prototype.getPath = function(text, x, y, fontSize, options) {\n var fullPath = new Path();\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);\n fullPath.extend(glyphPath);\n });\n return fullPath;\n };\n\n /**\n * Create an array of Path objects that represent the glyphs of a given text.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @return {opentype.Path[]}\n */\n Font.prototype.getPaths = function(text, x, y, fontSize, options) {\n var glyphPaths = [];\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);\n glyphPaths.push(glyphPath);\n });\n\n return glyphPaths;\n };\n\n /**\n * Returns the advance width of a text.\n *\n * This is something different than Path.getBoundingBox() as for example a\n * suffixed whitespace increases the advanceWidth but not the bounding box\n * or an overhanging letter like a calligraphic 'f' might have a quite larger\n * bounding box than its advance width.\n *\n * This corresponds to canvas2dContext.measureText(text).width\n *\n * @param {string} text - The text to create.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @return advance width\n */\n Font.prototype.getAdvanceWidth = function(text, fontSize, options) {\n return this.forEachGlyph(text, 0, 0, fontSize, options, function() {});\n };\n\n /**\n * Draw the text on the given drawing context.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n */\n Font.prototype.draw = function(ctx, text, x, y, fontSize, options) {\n this.getPath(text, x, y, fontSize, options).draw(ctx);\n };\n\n /**\n * Draw the points of all glyphs in the text.\n * On-curve points will be drawn in blue, off-curve points will be drawn in red.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n */\n Font.prototype.drawPoints = function(ctx, text, x, y, fontSize, options) {\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n glyph.drawPoints(ctx, gX, gY, gFontSize);\n });\n };\n\n /**\n * Draw lines indicating important font measurements for all glyphs in the text.\n * Black lines indicate the origin of the coordinate system (point 0,0).\n * Blue lines indicate the glyph bounding box.\n * Green line indicates the advance width of the glyph.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n */\n Font.prototype.drawMetrics = function(ctx, text, x, y, fontSize, options) {\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n glyph.drawMetrics(ctx, gX, gY, gFontSize);\n });\n };\n\n /**\n * @param {string}\n * @return {string}\n */\n Font.prototype.getEnglishName = function(name) {\n var translations = this.names[name];\n if (translations) {\n return translations.en;\n }\n };\n\n /**\n * Validate\n */\n Font.prototype.validate = function() {\n var _this = this;\n\n function assert(predicate, message) {\n }\n\n function assertNamePresent(name) {\n var englishName = _this.getEnglishName(name);\n assert(englishName && englishName.trim().length > 0);\n }\n\n // Identification information\n assertNamePresent('fontFamily');\n assertNamePresent('weightName');\n assertNamePresent('manufacturer');\n assertNamePresent('copyright');\n assertNamePresent('version');\n\n // Dimension information\n assert(this.unitsPerEm > 0);\n };\n\n /**\n * Convert the font object to a SFNT data structure.\n * This structure contains all the necessary tables and metadata to create a binary OTF file.\n * @return {opentype.Table}\n */\n Font.prototype.toTables = function() {\n return sfnt.fontToTable(this);\n };\n /**\n * @deprecated Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.\n */\n Font.prototype.toBuffer = function() {\n console.warn('Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.');\n return this.toArrayBuffer();\n };\n /**\n * Converts a `opentype.Font` into an `ArrayBuffer`\n * @return {ArrayBuffer}\n */\n Font.prototype.toArrayBuffer = function() {\n var sfntTable = this.toTables();\n var bytes = sfntTable.encode();\n var buffer = new ArrayBuffer(bytes.length);\n var intArray = new Uint8Array(buffer);\n for (var i = 0; i < bytes.length; i++) {\n intArray[i] = bytes[i];\n }\n\n return buffer;\n };\n\n /**\n * Initiate a download of the OpenType font.\n */\n Font.prototype.download = function(fileName) {\n var familyName = this.getEnglishName('fontFamily');\n var styleName = this.getEnglishName('fontSubfamily');\n fileName = fileName || familyName.replace(/\\s/g, '') + '-' + styleName + '.otf';\n var arrayBuffer = this.toArrayBuffer();\n\n if (isBrowser()) {\n window.URL = window.URL || window.webkitURL;\n\n if (window.URL) {\n var dataView = new DataView(arrayBuffer);\n var blob = new Blob([dataView], {type: 'font/opentype'});\n\n var link = document.createElement('a');\n link.href = window.URL.createObjectURL(blob);\n link.download = fileName;\n\n var event = document.createEvent('MouseEvents');\n event.initEvent('click', true, false);\n link.dispatchEvent(event);\n } else {\n console.warn('Font file could not be downloaded. Try using a different browser.');\n }\n } else {\n var fs = require('fs');\n var buffer = arrayBufferToNodeBuffer(arrayBuffer);\n fs.writeFileSync(fileName, buffer);\n }\n };\n /**\n * @private\n */\n Font.prototype.fsSelectionValues = {\n ITALIC: 0x001, //1\n UNDERSCORE: 0x002, //2\n NEGATIVE: 0x004, //4\n OUTLINED: 0x008, //8\n STRIKEOUT: 0x010, //16\n BOLD: 0x020, //32\n REGULAR: 0x040, //64\n USER_TYPO_METRICS: 0x080, //128\n WWS: 0x100, //256\n OBLIQUE: 0x200 //512\n };\n\n /**\n * @private\n */\n Font.prototype.usWidthClasses = {\n ULTRA_CONDENSED: 1,\n EXTRA_CONDENSED: 2,\n CONDENSED: 3,\n SEMI_CONDENSED: 4,\n MEDIUM: 5,\n SEMI_EXPANDED: 6,\n EXPANDED: 7,\n EXTRA_EXPANDED: 8,\n ULTRA_EXPANDED: 9\n };\n\n /**\n * @private\n */\n Font.prototype.usWeightClasses = {\n THIN: 100,\n EXTRA_LIGHT: 200,\n LIGHT: 300,\n NORMAL: 400,\n MEDIUM: 500,\n SEMI_BOLD: 600,\n BOLD: 700,\n EXTRA_BOLD: 800,\n BLACK: 900\n };\n\n // The `fvar` table stores font variation axes and instances.\n\n function addName(name, names) {\n var nameString = JSON.stringify(name);\n var nameID = 256;\n for (var nameKey in names) {\n var n = parseInt(nameKey);\n if (!n || n < 256) {\n continue;\n }\n\n if (JSON.stringify(names[nameKey]) === nameString) {\n return n;\n }\n\n if (nameID <= n) {\n nameID = n + 1;\n }\n }\n\n names[nameID] = name;\n return nameID;\n }\n\n function makeFvarAxis(n, axis, names) {\n var nameID = addName(axis.name, names);\n return [\n {name: 'tag_' + n, type: 'TAG', value: axis.tag},\n {name: 'minValue_' + n, type: 'FIXED', value: axis.minValue << 16},\n {name: 'defaultValue_' + n, type: 'FIXED', value: axis.defaultValue << 16},\n {name: 'maxValue_' + n, type: 'FIXED', value: axis.maxValue << 16},\n {name: 'flags_' + n, type: 'USHORT', value: 0},\n {name: 'nameID_' + n, type: 'USHORT', value: nameID}\n ];\n }\n\n function parseFvarAxis(data, start, names) {\n var axis = {};\n var p = new parse.Parser(data, start);\n axis.tag = p.parseTag();\n axis.minValue = p.parseFixed();\n axis.defaultValue = p.parseFixed();\n axis.maxValue = p.parseFixed();\n p.skip('uShort', 1); // reserved for flags; no values defined\n axis.name = names[p.parseUShort()] || {};\n return axis;\n }\n\n function makeFvarInstance(n, inst, axes, names) {\n var nameID = addName(inst.name, names);\n var fields = [\n {name: 'nameID_' + n, type: 'USHORT', value: nameID},\n {name: 'flags_' + n, type: 'USHORT', value: 0}\n ];\n\n for (var i = 0; i < axes.length; ++i) {\n var axisTag = axes[i].tag;\n fields.push({\n name: 'axis_' + n + ' ' + axisTag,\n type: 'FIXED',\n value: inst.coordinates[axisTag] << 16\n });\n }\n\n return fields;\n }\n\n function parseFvarInstance(data, start, axes, names) {\n var inst = {};\n var p = new parse.Parser(data, start);\n inst.name = names[p.parseUShort()] || {};\n p.skip('uShort', 1); // reserved for flags; no values defined\n\n inst.coordinates = {};\n for (var i = 0; i < axes.length; ++i) {\n inst.coordinates[axes[i].tag] = p.parseFixed();\n }\n\n return inst;\n }\n\n function makeFvarTable(fvar, names) {\n var result = new table.Table('fvar', [\n {name: 'version', type: 'ULONG', value: 0x10000},\n {name: 'offsetToData', type: 'USHORT', value: 0},\n {name: 'countSizePairs', type: 'USHORT', value: 2},\n {name: 'axisCount', type: 'USHORT', value: fvar.axes.length},\n {name: 'axisSize', type: 'USHORT', value: 20},\n {name: 'instanceCount', type: 'USHORT', value: fvar.instances.length},\n {name: 'instanceSize', type: 'USHORT', value: 4 + fvar.axes.length * 4}\n ]);\n result.offsetToData = result.sizeOf();\n\n for (var i = 0; i < fvar.axes.length; i++) {\n result.fields = result.fields.concat(makeFvarAxis(i, fvar.axes[i], names));\n }\n\n for (var j = 0; j < fvar.instances.length; j++) {\n result.fields = result.fields.concat(makeFvarInstance(j, fvar.instances[j], fvar.axes, names));\n }\n\n return result;\n }\n\n function parseFvarTable(data, start, names) {\n var p = new parse.Parser(data, start);\n var tableVersion = p.parseULong();\n check.argument(tableVersion === 0x00010000, 'Unsupported fvar table version.');\n var offsetToData = p.parseOffset16();\n // Skip countSizePairs.\n p.skip('uShort', 1);\n var axisCount = p.parseUShort();\n var axisSize = p.parseUShort();\n var instanceCount = p.parseUShort();\n var instanceSize = p.parseUShort();\n\n var axes = [];\n for (var i = 0; i < axisCount; i++) {\n axes.push(parseFvarAxis(data, start + offsetToData + i * axisSize, names));\n }\n\n var instances = [];\n var instanceStart = start + offsetToData + axisCount * axisSize;\n for (var j = 0; j < instanceCount; j++) {\n instances.push(parseFvarInstance(data, instanceStart + j * instanceSize, axes, names));\n }\n\n return {axes: axes, instances: instances};\n }\n\n var fvar = { make: makeFvarTable, parse: parseFvarTable };\n\n // The `GDEF` table contains various glyph properties\n\n var attachList = function() {\n return {\n coverage: this.parsePointer(Parser.coverage),\n attachPoints: this.parseList(Parser.pointer(Parser.uShortList))\n };\n };\n\n var caretValue = function() {\n var format = this.parseUShort();\n check.argument(format === 1 || format === 2 || format === 3,\n 'Unsupported CaretValue table version.');\n if (format === 1) {\n return { coordinate: this.parseShort() };\n } else if (format === 2) {\n return { pointindex: this.parseShort() };\n } else if (format === 3) {\n // Device / Variation Index tables unsupported\n return { coordinate: this.parseShort() };\n }\n };\n\n var ligGlyph = function() {\n return this.parseList(Parser.pointer(caretValue));\n };\n\n var ligCaretList = function() {\n return {\n coverage: this.parsePointer(Parser.coverage),\n ligGlyphs: this.parseList(Parser.pointer(ligGlyph))\n };\n };\n\n var markGlyphSets = function() {\n this.parseUShort(); // Version\n return this.parseList(Parser.pointer(Parser.coverage));\n };\n\n function parseGDEFTable(data, start) {\n start = start || 0;\n var p = new Parser(data, start);\n var tableVersion = p.parseVersion(1);\n check.argument(tableVersion === 1 || tableVersion === 1.2 || tableVersion === 1.3,\n 'Unsupported GDEF table version.');\n var gdef = {\n version: tableVersion,\n classDef: p.parsePointer(Parser.classDef),\n attachList: p.parsePointer(attachList),\n ligCaretList: p.parsePointer(ligCaretList),\n markAttachClassDef: p.parsePointer(Parser.classDef)\n };\n if (tableVersion >= 1.2) {\n gdef.markGlyphSets = p.parsePointer(markGlyphSets);\n }\n return gdef;\n }\n var gdef = { parse: parseGDEFTable };\n\n // The `GPOS` table contains kerning pairs, among other things.\n\n var subtableParsers$1 = new Array(10); // subtableParsers[0] is unused\n\n // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable\n // this = Parser instance\n subtableParsers$1[1] = function parseLookup1() {\n var start = this.offset + this.relativeOffset;\n var posformat = this.parseUShort();\n if (posformat === 1) {\n return {\n posFormat: 1,\n coverage: this.parsePointer(Parser.coverage),\n value: this.parseValueRecord()\n };\n } else if (posformat === 2) {\n return {\n posFormat: 2,\n coverage: this.parsePointer(Parser.coverage),\n values: this.parseValueRecordList()\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': GPOS lookup type 1 format must be 1 or 2.');\n };\n\n // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable\n subtableParsers$1[2] = function parseLookup2() {\n var start = this.offset + this.relativeOffset;\n var posFormat = this.parseUShort();\n check.assert(posFormat === 1 || posFormat === 2, '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.');\n var coverage = this.parsePointer(Parser.coverage);\n var valueFormat1 = this.parseUShort();\n var valueFormat2 = this.parseUShort();\n if (posFormat === 1) {\n // Adjustments for Glyph Pairs\n return {\n posFormat: posFormat,\n coverage: coverage,\n valueFormat1: valueFormat1,\n valueFormat2: valueFormat2,\n pairSets: this.parseList(Parser.pointer(Parser.list(function() {\n return { // pairValueRecord\n secondGlyph: this.parseUShort(),\n value1: this.parseValueRecord(valueFormat1),\n value2: this.parseValueRecord(valueFormat2)\n };\n })))\n };\n } else if (posFormat === 2) {\n var classDef1 = this.parsePointer(Parser.classDef);\n var classDef2 = this.parsePointer(Parser.classDef);\n var class1Count = this.parseUShort();\n var class2Count = this.parseUShort();\n return {\n // Class Pair Adjustment\n posFormat: posFormat,\n coverage: coverage,\n valueFormat1: valueFormat1,\n valueFormat2: valueFormat2,\n classDef1: classDef1,\n classDef2: classDef2,\n class1Count: class1Count,\n class2Count: class2Count,\n classRecords: this.parseList(class1Count, Parser.list(class2Count, function() {\n return {\n value1: this.parseValueRecord(valueFormat1),\n value2: this.parseValueRecord(valueFormat2)\n };\n }))\n };\n }\n };\n\n subtableParsers$1[3] = function parseLookup3() { return { error: 'GPOS Lookup 3 not supported' }; };\n subtableParsers$1[4] = function parseLookup4() { return { error: 'GPOS Lookup 4 not supported' }; };\n subtableParsers$1[5] = function parseLookup5() { return { error: 'GPOS Lookup 5 not supported' }; };\n subtableParsers$1[6] = function parseLookup6() { return { error: 'GPOS Lookup 6 not supported' }; };\n subtableParsers$1[7] = function parseLookup7() { return { error: 'GPOS Lookup 7 not supported' }; };\n subtableParsers$1[8] = function parseLookup8() { return { error: 'GPOS Lookup 8 not supported' }; };\n subtableParsers$1[9] = function parseLookup9() { return { error: 'GPOS Lookup 9 not supported' }; };\n\n // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos\n function parseGposTable(data, start) {\n start = start || 0;\n var p = new Parser(data, start);\n var tableVersion = p.parseVersion(1);\n check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GPOS table version ' + tableVersion);\n\n if (tableVersion === 1) {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers$1)\n };\n } else {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers$1),\n variations: p.parseFeatureVariationsList()\n };\n }\n\n }\n\n // GPOS Writing //////////////////////////////////////////////\n // NOT SUPPORTED\n var subtableMakers$1 = new Array(10);\n\n function makeGposTable(gpos) {\n return new table.Table('GPOS', [\n {name: 'version', type: 'ULONG', value: 0x10000},\n {name: 'scripts', type: 'TABLE', value: new table.ScriptList(gpos.scripts)},\n {name: 'features', type: 'TABLE', value: new table.FeatureList(gpos.features)},\n {name: 'lookups', type: 'TABLE', value: new table.LookupList(gpos.lookups, subtableMakers$1)}\n ]);\n }\n\n var gpos = { parse: parseGposTable, make: makeGposTable };\n\n // The `kern` table contains kerning pairs.\n\n function parseWindowsKernTable(p) {\n var pairs = {};\n // Skip nTables.\n p.skip('uShort');\n var subtableVersion = p.parseUShort();\n check.argument(subtableVersion === 0, 'Unsupported kern sub-table version.');\n // Skip subtableLength, subtableCoverage\n p.skip('uShort', 2);\n var nPairs = p.parseUShort();\n // Skip searchRange, entrySelector, rangeShift.\n p.skip('uShort', 3);\n for (var i = 0; i < nPairs; i += 1) {\n var leftIndex = p.parseUShort();\n var rightIndex = p.parseUShort();\n var value = p.parseShort();\n pairs[leftIndex + ',' + rightIndex] = value;\n }\n return pairs;\n }\n\n function parseMacKernTable(p) {\n var pairs = {};\n // The Mac kern table stores the version as a fixed (32 bits) but we only loaded the first 16 bits.\n // Skip the rest.\n p.skip('uShort');\n var nTables = p.parseULong();\n //check.argument(nTables === 1, 'Only 1 subtable is supported (got ' + nTables + ').');\n if (nTables > 1) {\n console.warn('Only the first kern subtable is supported.');\n }\n p.skip('uLong');\n var coverage = p.parseUShort();\n var subtableVersion = coverage & 0xFF;\n p.skip('uShort');\n if (subtableVersion === 0) {\n var nPairs = p.parseUShort();\n // Skip searchRange, entrySelector, rangeShift.\n p.skip('uShort', 3);\n for (var i = 0; i < nPairs; i += 1) {\n var leftIndex = p.parseUShort();\n var rightIndex = p.parseUShort();\n var value = p.parseShort();\n pairs[leftIndex + ',' + rightIndex] = value;\n }\n }\n return pairs;\n }\n\n // Parse the `kern` table which contains kerning pairs.\n function parseKernTable(data, start) {\n var p = new parse.Parser(data, start);\n var tableVersion = p.parseUShort();\n if (tableVersion === 0) {\n return parseWindowsKernTable(p);\n } else if (tableVersion === 1) {\n return parseMacKernTable(p);\n } else {\n throw new Error('Unsupported kern table version (' + tableVersion + ').');\n }\n }\n\n var kern = { parse: parseKernTable };\n\n // The `loca` table stores the offsets to the locations of the glyphs in the font.\n\n // Parse the `loca` table. This table stores the offsets to the locations of the glyphs in the font,\n // relative to the beginning of the glyphData table.\n // The number of glyphs stored in the `loca` table is specified in the `maxp` table (under numGlyphs)\n // The loca table has two versions: a short version where offsets are stored as uShorts, and a long\n // version where offsets are stored as uLongs. The `head` table specifies which version to use\n // (under indexToLocFormat).\n function parseLocaTable(data, start, numGlyphs, shortVersion) {\n var p = new parse.Parser(data, start);\n var parseFn = shortVersion ? p.parseUShort : p.parseULong;\n // There is an extra entry after the last index element to compute the length of the last glyph.\n // That's why we use numGlyphs + 1.\n var glyphOffsets = [];\n for (var i = 0; i < numGlyphs + 1; i += 1) {\n var glyphOffset = parseFn.call(p);\n if (shortVersion) {\n // The short table version stores the actual offset divided by 2.\n glyphOffset *= 2;\n }\n\n glyphOffsets.push(glyphOffset);\n }\n\n return glyphOffsets;\n }\n\n var loca = { parse: parseLocaTable };\n\n // Table Directory Entries //////////////////////////////////////////////\n /**\n * Parses OpenType table entries.\n * @param {DataView}\n * @param {Number}\n * @return {Object[]}\n */\n function parseOpenTypeTableEntries(data, numTables) {\n var tableEntries = [];\n var p = 12;\n for (var i = 0; i < numTables; i += 1) {\n var tag = parse.getTag(data, p);\n var checksum = parse.getULong(data, p + 4);\n var offset = parse.getULong(data, p + 8);\n var length = parse.getULong(data, p + 12);\n tableEntries.push({tag: tag, checksum: checksum, offset: offset, length: length, compression: false});\n p += 16;\n }\n\n return tableEntries;\n }\n\n /**\n * Parses WOFF table entries.\n * @param {DataView}\n * @param {Number}\n * @return {Object[]}\n */\n function parseWOFFTableEntries(data, numTables) {\n var tableEntries = [];\n var p = 44; // offset to the first table directory entry.\n for (var i = 0; i < numTables; i += 1) {\n var tag = parse.getTag(data, p);\n var offset = parse.getULong(data, p + 4);\n var compLength = parse.getULong(data, p + 8);\n var origLength = parse.getULong(data, p + 12);\n var compression = (void 0);\n if (compLength < origLength) {\n compression = 'WOFF';\n } else {\n compression = false;\n }\n\n tableEntries.push({tag: tag, offset: offset, compression: compression,\n compressedLength: compLength, length: origLength});\n p += 20;\n }\n\n return tableEntries;\n }\n\n /**\n * @typedef TableData\n * @type Object\n * @property {DataView} data - The DataView\n * @property {number} offset - The data offset.\n */\n\n /**\n * @param {DataView}\n * @param {Object}\n * @return {TableData}\n */\n function uncompressTable(data, tableEntry) {\n if (tableEntry.compression === 'WOFF') {\n var inBuffer = new Uint8Array(data.buffer, tableEntry.offset + 2, tableEntry.compressedLength - 2);\n var outBuffer = new Uint8Array(tableEntry.length);\n tinyInflate(inBuffer, outBuffer);\n if (outBuffer.byteLength !== tableEntry.length) {\n throw new Error('Decompression error: ' + tableEntry.tag + ' decompressed length doesn\\'t match recorded length');\n }\n\n var view = new DataView(outBuffer.buffer, 0);\n return {data: view, offset: 0};\n } else {\n return {data: data, offset: tableEntry.offset};\n }\n }\n\n // Public API ///////////////////////////////////////////////////////////\n\n /**\n * Parse the OpenType file data (as an ArrayBuffer) and return a Font object.\n * Throws an error if the font could not be parsed.\n * @param {ArrayBuffer}\n * @param {Object} opt - options for parsing\n * @return {opentype.Font}\n */\n function parseBuffer(buffer, opt) {\n opt = (opt === undefined || opt === null) ? {} : opt;\n\n var indexToLocFormat;\n var ltagTable;\n\n // Since the constructor can also be called to create new fonts from scratch, we indicate this\n // should be an empty font that we'll fill with our own data.\n var font = new Font({empty: true});\n\n // OpenType fonts use big endian byte ordering.\n // We can't rely on typed array view types, because they operate with the endianness of the host computer.\n // Instead we use DataViews where we can specify endianness.\n var data = new DataView(buffer, 0);\n var numTables;\n var tableEntries = [];\n var signature = parse.getTag(data, 0);\n if (signature === String.fromCharCode(0, 1, 0, 0) || signature === 'true' || signature === 'typ1') {\n font.outlinesFormat = 'truetype';\n numTables = parse.getUShort(data, 4);\n tableEntries = parseOpenTypeTableEntries(data, numTables);\n } else if (signature === 'OTTO') {\n font.outlinesFormat = 'cff';\n numTables = parse.getUShort(data, 4);\n tableEntries = parseOpenTypeTableEntries(data, numTables);\n } else if (signature === 'wOFF') {\n var flavor = parse.getTag(data, 4);\n if (flavor === String.fromCharCode(0, 1, 0, 0)) {\n font.outlinesFormat = 'truetype';\n } else if (flavor === 'OTTO') {\n font.outlinesFormat = 'cff';\n } else {\n throw new Error('Unsupported OpenType flavor ' + signature);\n }\n\n numTables = parse.getUShort(data, 12);\n tableEntries = parseWOFFTableEntries(data, numTables);\n } else {\n throw new Error('Unsupported OpenType signature ' + signature);\n }\n\n var cffTableEntry;\n var fvarTableEntry;\n var glyfTableEntry;\n var gdefTableEntry;\n var gposTableEntry;\n var gsubTableEntry;\n var hmtxTableEntry;\n var kernTableEntry;\n var locaTableEntry;\n var nameTableEntry;\n var metaTableEntry;\n var p;\n\n for (var i = 0; i < numTables; i += 1) {\n var tableEntry = tableEntries[i];\n var table = (void 0);\n switch (tableEntry.tag) {\n case 'cmap':\n table = uncompressTable(data, tableEntry);\n font.tables.cmap = cmap.parse(table.data, table.offset);\n font.encoding = new CmapEncoding(font.tables.cmap);\n break;\n case 'cvt ' :\n table = uncompressTable(data, tableEntry);\n p = new parse.Parser(table.data, table.offset);\n font.tables.cvt = p.parseShortList(tableEntry.length / 2);\n break;\n case 'fvar':\n fvarTableEntry = tableEntry;\n break;\n case 'fpgm' :\n table = uncompressTable(data, tableEntry);\n p = new parse.Parser(table.data, table.offset);\n font.tables.fpgm = p.parseByteList(tableEntry.length);\n break;\n case 'head':\n table = uncompressTable(data, tableEntry);\n font.tables.head = head.parse(table.data, table.offset);\n font.unitsPerEm = font.tables.head.unitsPerEm;\n indexToLocFormat = font.tables.head.indexToLocFormat;\n break;\n case 'hhea':\n table = uncompressTable(data, tableEntry);\n font.tables.hhea = hhea.parse(table.data, table.offset);\n font.ascender = font.tables.hhea.ascender;\n font.descender = font.tables.hhea.descender;\n font.numberOfHMetrics = font.tables.hhea.numberOfHMetrics;\n break;\n case 'hmtx':\n hmtxTableEntry = tableEntry;\n break;\n case 'ltag':\n table = uncompressTable(data, tableEntry);\n ltagTable = ltag.parse(table.data, table.offset);\n break;\n case 'maxp':\n table = uncompressTable(data, tableEntry);\n font.tables.maxp = maxp.parse(table.data, table.offset);\n font.numGlyphs = font.tables.maxp.numGlyphs;\n break;\n case 'name':\n nameTableEntry = tableEntry;\n break;\n case 'OS/2':\n table = uncompressTable(data, tableEntry);\n font.tables.os2 = os2.parse(table.data, table.offset);\n break;\n case 'post':\n table = uncompressTable(data, tableEntry);\n font.tables.post = post.parse(table.data, table.offset);\n font.glyphNames = new GlyphNames(font.tables.post);\n break;\n case 'prep' :\n table = uncompressTable(data, tableEntry);\n p = new parse.Parser(table.data, table.offset);\n font.tables.prep = p.parseByteList(tableEntry.length);\n break;\n case 'glyf':\n glyfTableEntry = tableEntry;\n break;\n case 'loca':\n locaTableEntry = tableEntry;\n break;\n case 'CFF ':\n cffTableEntry = tableEntry;\n break;\n case 'kern':\n kernTableEntry = tableEntry;\n break;\n case 'GDEF':\n gdefTableEntry = tableEntry;\n break;\n case 'GPOS':\n gposTableEntry = tableEntry;\n break;\n case 'GSUB':\n gsubTableEntry = tableEntry;\n break;\n case 'meta':\n metaTableEntry = tableEntry;\n break;\n }\n }\n\n var nameTable = uncompressTable(data, nameTableEntry);\n font.tables.name = _name.parse(nameTable.data, nameTable.offset, ltagTable);\n font.names = font.tables.name;\n\n if (glyfTableEntry && locaTableEntry) {\n var shortVersion = indexToLocFormat === 0;\n var locaTable = uncompressTable(data, locaTableEntry);\n var locaOffsets = loca.parse(locaTable.data, locaTable.offset, font.numGlyphs, shortVersion);\n var glyfTable = uncompressTable(data, glyfTableEntry);\n font.glyphs = glyf.parse(glyfTable.data, glyfTable.offset, locaOffsets, font, opt);\n } else if (cffTableEntry) {\n var cffTable = uncompressTable(data, cffTableEntry);\n cff.parse(cffTable.data, cffTable.offset, font, opt);\n } else {\n throw new Error('Font doesn\\'t contain TrueType or CFF outlines.');\n }\n\n var hmtxTable = uncompressTable(data, hmtxTableEntry);\n hmtx.parse(font, hmtxTable.data, hmtxTable.offset, font.numberOfHMetrics, font.numGlyphs, font.glyphs, opt);\n addGlyphNames(font, opt);\n\n if (kernTableEntry) {\n var kernTable = uncompressTable(data, kernTableEntry);\n font.kerningPairs = kern.parse(kernTable.data, kernTable.offset);\n } else {\n font.kerningPairs = {};\n }\n\n if (gdefTableEntry) {\n var gdefTable = uncompressTable(data, gdefTableEntry);\n font.tables.gdef = gdef.parse(gdefTable.data, gdefTable.offset);\n }\n\n if (gposTableEntry) {\n var gposTable = uncompressTable(data, gposTableEntry);\n font.tables.gpos = gpos.parse(gposTable.data, gposTable.offset);\n font.position.init();\n }\n\n if (gsubTableEntry) {\n var gsubTable = uncompressTable(data, gsubTableEntry);\n font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset);\n }\n\n if (fvarTableEntry) {\n var fvarTable = uncompressTable(data, fvarTableEntry);\n font.tables.fvar = fvar.parse(fvarTable.data, fvarTable.offset, font.names);\n }\n\n if (metaTableEntry) {\n var metaTable = uncompressTable(data, metaTableEntry);\n font.tables.meta = meta.parse(metaTable.data, metaTable.offset);\n font.metas = font.tables.meta;\n }\n\n return font;\n }\n\n const primitiveShapeProperties = new Set([\n 'height',\n 'width',\n 'depth',\n 'radius',\n 'radiusTop',\n 'radiusBottom',\n 'thickness',\n 'arc',\n 'latitudeStart',\n 'latitudeSlice',\n 'tessellation',\n 'subdivisions',\n 'capMode',\n 'segments',\n ]);\n const PIVOT_GIZMO_SCALE = 0.33;\n const capModeMap = {\n [exports.eCylinderCap.both]: Mesh.CAP_ALL,\n [exports.eCylinderCap.start]: Mesh.CAP_START,\n [exports.eCylinderCap.end]: Mesh.CAP_END,\n [exports.eCylinderCap.none]: Mesh.NO_CAP,\n };\n const textMeshFonts = new Map();\n // const lineColor = new Color4(1, 1, 1);\n // const selectedLineColor = new Color4(1, 0, 0);\n class MeshRenderer extends Renderer {\n constructor(viewer, scene, rendererManager, shadowManager) {\n super(viewer, scene);\n this.rendererManager = rendererManager;\n this.shadowManager = shadowManager;\n this.disposed = new Subject();\n this.pivotGizmos = new Map();\n this.sketchPreviews = new Map();\n this.sketchTracings = new Map();\n this.sketchPlanePreviews = new Map();\n this.modelToken = Token.SpaceNode;\n this.utilityLayer = viewer.utilityLayer;\n const tempVector = new Vector3();\n viewer.afterRender.pipe(takeUntil(this.disposed)).subscribe(() => {\n let dist;\n const camera = this.utilityLayer.utilityLayerScene.activeCamera;\n this.pivotGizmos.forEach(gizmo => {\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n dist = ((camera.orthoRight || 0) - (camera.orthoLeft || 0)) / 2;\n }\n else {\n const cameraPosition = camera.globalPosition;\n gizmo.position.subtractToRef(cameraPosition, tempVector);\n dist = tempVector.length() * PIVOT_GIZMO_SCALE;\n }\n gizmo.scaling.set(dist, dist, dist);\n });\n });\n }\n handlesNode(node) {\n return isMeshNode(node) || isMeshGroupNode(node) || (isSceneNode(node) && node.isNested());\n }\n setRenderMode(mode, sceneNode) {\n this.renderMode = mode;\n this.babylonMap.forEach(mesh => {\n if (mesh instanceof Mesh) {\n this.setRenderModeOnMesh(mesh, sceneNode);\n }\n });\n }\n dispose() {\n super.dispose();\n this.pivotGizmos.forEach(gizmo => {\n gizmo.dispose();\n });\n this.pivotGizmos.clear();\n this.disposed.next();\n }\n loadNewGeometry(node) {\n node._loading = node.geometryId;\n const meshService = node._manager.getService(Token.MeshService);\n meshService.hydrateGeometry(node).then(() => {\n node._loading = null;\n this.invalidateBoundingBox(node);\n });\n }\n parentsVisible(node) {\n while (node._parent && node._parent instanceof exports.SpaceNode) {\n if (!node._parent.visible) {\n return false;\n }\n node = node._parent;\n }\n return true;\n }\n update3dInternal(node) {\n const isNewMesh = !this.get3d(node);\n if (isCustomMeshNode(node)) {\n if (node.visible &&\n this.parentsVisible(node) &&\n node.hasGeometry &&\n !node._geometry &&\n !node.geometryLoaded &&\n !node._loading) {\n this.loadNewGeometry(node);\n }\n }\n const mesh = this.createOrUpdateMesh(node);\n const pivotGizmo = this.pivotGizmos.get(node._dynamicId);\n if (node._selected && mesh instanceof Mesh && !this.viewer.highlighter.has(node)) {\n this.viewer.highlighter.add(node, exports.KbColor.Red());\n if (pivotGizmo) {\n pivotGizmo.setEnabled(true);\n }\n }\n else if (!node._selected && mesh instanceof Mesh && this.viewer.highlighter.has(node)) {\n this.viewer.highlighter.remove(node);\n if (pivotGizmo) {\n pivotGizmo.setEnabled(false);\n }\n }\n if (node instanceof exports.SketchNode) {\n if (node._selected && node.visible) {\n const oldPreview = this.sketchPlanePreviews.get(node.id);\n if (oldPreview) {\n oldPreview.dispose();\n }\n const mesh = this.createSketchPlaneVisualization(node);\n if (node.visible && mesh) {\n this.sketchPlanePreviews.set(node.id, mesh);\n }\n else {\n mesh === null || mesh === void 0 ? void 0 : mesh.dispose();\n this.sketchPlanePreviews.delete(node.id);\n }\n }\n else if (!node._selected || !node.visible) {\n const SketchPlancePreviewMesh = this.sketchPlanePreviews.get(node.id);\n SketchPlancePreviewMesh === null || SketchPlancePreviewMesh === void 0 ? void 0 : SketchPlancePreviewMesh.dispose();\n this.sketchPlanePreviews.delete(node.id);\n }\n }\n if (!mesh) {\n throw Error('Could not create mesh');\n }\n if (isNewMesh || node.changes.has('_parent')) {\n this.updateParentMeshFromNode(node, mesh, isNewMesh);\n }\n }\n rebuildBaseGeometry(node, preTransformChanged = false) {\n const mesh = this.get3d(node);\n if (mesh && mesh instanceof Mesh) {\n let meshVertexData = null;\n if (isPrimitiveMeshNode(node)) {\n const newMesh = this.createPrimitiveMesh(node);\n meshVertexData = SubmeshVertexData.ExtractFromMesh(newMesh);\n newMesh.dispose();\n if (isDefined(node.uvOverrides)) {\n this.setBabylonUvData(node.uvOverrides, meshVertexData);\n }\n if (node instanceof exports.MeshNode && meshVertexData) {\n // Always pretransform primitives as they are always rebuilt from scratch\n this.preTransformVertices(meshVertexData, node);\n }\n }\n else if (isCustomMeshNode(node)) {\n // If custom geometry does not have a geometry, don't do anything. Return null.\n if (node._geometry && node._geometry.positions) {\n meshVertexData = this.getMeshVertexData(node);\n }\n }\n else if (isSketchNode(node)) {\n meshVertexData = this.buildSketchGeometry(node);\n }\n else if (isTextNode(node) && isTrackedClass(node)) {\n meshVertexData = this.buildTextGeometry(node);\n }\n else {\n throw Error('geometry needs to be recalculated but mesh is not a valid primitive or custom mesh');\n }\n return meshVertexData;\n }\n return null;\n }\n buildSketchGeometry(node) {\n const result = new SubmeshVertexData();\n const positionVectors = [];\n let pathSegmentIndices = [];\n // Keep track of the path groups so we can match the hole paths with the groups in the vertex data\n // The key is the path group key, and the value is the indices of the generated polygons that are part of that path\n // One connected path may have multiple sketch paths because it requires different types of curves\n const pathGroupKeys = new Map();\n const holePathsReferencingKeys = [];\n let currentPath;\n let lastPoint;\n for (let i = 0; i < node.paths.length; i++) {\n const path = node.paths[i];\n if (path._points && path._points.length > 0) {\n let thisPoint;\n for (let iP = 0; iP < path._points.length; iP++) {\n const { x, y, z } = path._points[iP];\n thisPoint = new Vector3(x, y, z);\n // Separate paths that don't have a shared start/end to different logical paths\n if (!lastPoint || !thisPoint.equals(lastPoint)) {\n if (iP === 0 || !currentPath) {\n if (!pathGroupKeys.has(path.pathGroupKey)) {\n pathGroupKeys.set(path.pathGroupKey, pathSegmentIndices.length);\n }\n if (path.holeForPathGroup) {\n holePathsReferencingKeys[pathSegmentIndices.length] = path.holeForPathGroup;\n }\n currentPath = [];\n pathSegmentIndices.push(currentPath);\n }\n currentPath.push(positionVectors.length);\n positionVectors.push(thisPoint);\n }\n lastPoint = thisPoint;\n }\n }\n }\n if (positionVectors.length === 0 || pathSegmentIndices.length === 0) {\n return null;\n }\n const positions = [];\n const indices = [];\n const normals = [];\n const paths = [];\n if (node.flipPath) {\n pathSegmentIndices.reverse();\n pathSegmentIndices.forEach(segment => segment.reverse());\n }\n const primaryNormal = axisToVector3(node.normal);\n // /**\n // * We want the sketch to always \"face\" in the positive direction of the axis for consistency\n // * Otherwise it's indeterminate which way the sketch will face and makes the sketch hard to manage\n // * because it depends on the handed-ness of the points (clockwise or counter-clockwise)\n // */\n pathSegmentIndices.forEach(segment => {\n const segmentPositions = [];\n for (let i = 0; i < segment.length; i++) {\n const point = positionVectors[segment[i]];\n segmentPositions.push(point);\n }\n // However, don't flip non-closed paths because it makes no sense and may be a drive curve\n const closedPath = (segmentPositions.length > 1 &&\n segmentPositions[0].equalsWithEpsilon(segmentPositions[segmentPositions.length - 1])) ||\n node.closePath;\n if (closedPath) {\n const faceNormal = calculateFaceNormal(segmentPositions);\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\n if (Vector3.Dot(faceNormal, primaryNormal) < 0) {\n segment.reverse();\n }\n }\n });\n // Parse the holes and match them to their parent polygons\n const holesByPathsWithIndices = [];\n pathSegmentIndices.forEach((segment, idx) => {\n if (!holePathsReferencingKeys[idx]) {\n return;\n }\n const parentPathIndex = pathGroupKeys.get(holePathsReferencingKeys[idx]);\n if (parentPathIndex === undefined) {\n return;\n }\n // This segment is a hole\n if (!holesByPathsWithIndices[parentPathIndex]) {\n holesByPathsWithIndices[parentPathIndex] = [];\n }\n holesByPathsWithIndices[parentPathIndex].push(segment);\n });\n if (node.addFace) {\n // We have to reorder the segment indices because the vertex position order gets modified by the face fill\n // Due to holes needing be be defined alongside the parent polygons\n const reorderedPathSegmentIndices = [];\n let positionPointer = 0;\n pathSegmentIndices.forEach((segment, idx) => {\n // Skip holes in the loop since they are processed with their parent polygons\n if (holePathsReferencingKeys[idx]) {\n return;\n }\n const segmentPositions = [];\n const segmentIndices = [];\n for (let i = 0; i < segment.length; i++) {\n const point = positionVectors[segment[i]];\n segmentPositions.push(point);\n segmentIndices.push(positionPointer);\n positionPointer++;\n }\n reorderedPathSegmentIndices.push(segmentIndices);\n const holesPositions = [];\n if (holesByPathsWithIndices[idx]) {\n for (let hi = 0; hi < holesByPathsWithIndices[idx].length; hi++) {\n const hole = holesByPathsWithIndices[idx][hi];\n const holeData = [];\n const holeIndices = [];\n for (let i = 0; i < hole.length; i++) {\n const point = positionVectors[hole[i]];\n holeData.push(point);\n holeIndices.push(positionPointer);\n positionPointer++;\n }\n holesPositions.push(holeData);\n reorderedPathSegmentIndices.push(holeIndices);\n }\n }\n const newMeshVertices = fillSketchPolygon(segmentPositions, node.flipPath, primaryNormal, holesPositions);\n // Fix the indices to point at the right vertices\n const startIndex = positions.length / 3;\n for (let i = 0; i < newMeshVertices.indices.length; i++) {\n newMeshVertices.indices[i] += startIndex;\n }\n indices.push(...newMeshVertices.indices);\n positions.push(...newMeshVertices.positions);\n normals.push(...newMeshVertices.normals);\n });\n //const normals = new Float32Array(positionVectors.length * 3);\n const uvs = new Float32Array(positionVectors.length * 2);\n uvs.fill(0);\n result.positions = new Float32Array(positions);\n result.indices = new Uint16Array(indices);\n result.normals = new Float32Array(normals);\n result.uvs = uvs;\n pathSegmentIndices = reorderedPathSegmentIndices;\n }\n else {\n const positions = new Float32Array(positionVectors.length * 3);\n for (let i = 0; i < positionVectors.length; i++) {\n const point = positionVectors[i];\n positions.set([point.x, point.y, point.z], i * 3);\n }\n result.positions = positions;\n }\n const indexMapToGrouped = [];\n let i = 0;\n pathSegmentIndices.forEach((segment, indexOfPath) => {\n // Skip holes since they are processed later\n if (holePathsReferencingKeys[indexOfPath]) {\n return;\n }\n indexMapToGrouped[indexOfPath] = i;\n for (let i = 1; i < segment.length; i++) {\n paths.push(segment[i - 1], segment[i]);\n }\n if (segment.length > 2 && node.closePath) {\n paths.push(segment[segment.length - 1], segment[0]);\n }\n i++;\n });\n const holes = [];\n pathSegmentIndices.forEach((segment, indexOfPath) => {\n // Add holes after the regular polys\n if (!holePathsReferencingKeys[indexOfPath]) {\n return;\n }\n const parentPathIndex = pathGroupKeys.get(holePathsReferencingKeys[indexOfPath]);\n if (parentPathIndex === undefined) {\n return;\n }\n holes.push(indexMapToGrouped[parentPathIndex], paths.length);\n for (let i = 1; i < segment.length; i++) {\n paths.push(segment[i - 1], segment[i]);\n }\n if (segment.length > 2 && node.closePath) {\n paths.push(segment[segment.length - 1], segment[0]);\n }\n });\n result.paths = new Uint16Array(paths);\n result.holes = new Uint16Array(holes);\n node._sketchPoints = new Float32Array(result.positions);\n let counter = -1;\n const startingPoints = [];\n //for loop building the starting points array which stores sketchControlPoints at the start of a line segment\n for (let i = 0; i < node.paths.length; i++) {\n const path = node.paths[i];\n let lastPoint;\n if (path._points && path._points.length > 0) {\n let thisPoint;\n for (let iP = 0; iP < path._points.length; iP++) {\n const { x, y, z } = path._points[iP];\n thisPoint = new Vector3(x, y, z);\n startingPoints.push(counter);\n if (!lastPoint || !thisPoint.equals(lastPoint)) {\n if (iP === 0 || !currentPath) {\n startingPoints.pop();\n }\n }\n lastPoint = thisPoint;\n counter++;\n }\n }\n }\n node._lineSegmentStartingPoints = startingPoints;\n node.calculatedBoundingBox = this.calculateSketchBoundingBox(node);\n return result;\n }\n updateSketchPreview(sketchNode, vertexData, mesh) {\n var _a;\n const previewMesh = this.sketchPreviews.get(sketchNode._dynamicId);\n const { segments } = parseSketchGeometry(vertexData);\n if (segments.length > 0) {\n const baseColor = ((_a = sketchNode._rootScene) === null || _a === void 0 ? void 0 : _a.edgeColor)\n ? sketchNode._rootScene.edgeColor.toColor4()\n : new Color4(1, 1, 1, 1);\n const colors = [];\n segments.forEach(segmentPoints => {\n const segmentColors = [];\n colors.push(segmentColors);\n segmentPoints.forEach(() => {\n segmentColors.push(baseColor);\n });\n });\n const lineColor = colors.length > 0 ? colors : undefined;\n if (previewMesh &&\n !sketchNode.changes.has('addFace') &&\n !sketchNode.changes.has('paths') &&\n !sketchNode.changes.has('closePath')) {\n MeshBuilder.CreateLineSystem(`${sketchNode._dynamicId}_preview`, {\n lines: segments,\n instance: previewMesh,\n colors: lineColor,\n updatable: true,\n }, this.scene);\n }\n else {\n if (previewMesh) {\n previewMesh.dispose();\n }\n const newPreviewMesh = MeshBuilder.CreateLineSystem(`${sketchNode._dynamicId}_preview`, {\n lines: segments,\n colors: lineColor,\n updatable: true,\n }, this.scene);\n this.sketchPreviews.set(sketchNode._dynamicId, newPreviewMesh);\n newPreviewMesh.parent = mesh;\n newPreviewMesh.enableEdgesRendering();\n newPreviewMesh.edgesColor = baseColor;\n this.viewer.camera.maintainNodeScreenSize(newPreviewMesh, (dist, mode) => {\n if (mode === Camera.PERSPECTIVE_CAMERA) {\n newPreviewMesh.edgesWidth = dist * 0.25;\n }\n else {\n newPreviewMesh.edgesWidth = 4;\n }\n });\n }\n }\n else if (previewMesh) {\n previewMesh.dispose();\n this.sketchPreviews.delete(sketchNode._dynamicId);\n }\n }\n updateSketchTracing(sketchNode, vertexData, mesh) {\n const previewMesh = this.sketchTracings.get(sketchNode._dynamicId);\n const sketchColor = sketchNode.pathColor.toColor4();\n if (sketchNode.tracePath) {\n if (previewMesh) {\n previewMesh.dispose();\n }\n //create/update drawings\n const linePoints = [];\n sketchNode.paths.forEach(path => {\n path._points.forEach(point => {\n linePoints.push(new Vector3(point.x, point.y, point.z));\n });\n });\n if (sketchNode.closePath) {\n const point = sketchNode.paths[0]._points[0];\n linePoints.push(new Vector3(point.x, point.y, point.z));\n }\n const lines = Mesh.CreateLines('lines', linePoints, this.scene, true);\n lines.enableEdgesRendering();\n lines.edgesWidth = sketchNode.lineThickness;\n lines.edgesColor = sketchColor;\n this.sketchTracings.set(sketchNode._dynamicId, lines);\n }\n else {\n if (previewMesh || (previewMesh && sketchNode.tracePath === false)) {\n previewMesh.dispose();\n this.sketchTracings.delete(sketchNode._dynamicId);\n }\n }\n }\n buildTextGeometry(node) {\n const fontService = node._manager.getService(Token.FontService);\n if (!node.fontFile || !node.text) {\n return null;\n }\n if (!fontService.readyFonts.has(node.fontFile)) {\n fontService.loadFontByFile(node.fontFile).then(resultData => {\n const fontBuffer = resultData;\n if (fontBuffer) {\n node.setPropertyIsModified('fontFile', true);\n }\n });\n return null;\n }\n else {\n let vertexDataBuilder = textMeshFonts.get(node.fontFile);\n if (!vertexDataBuilder) {\n const fontBuffer = fontService.readyFonts.get(node.fontFile);\n const openTypeFont = parseBuffer(fontBuffer);\n const font = new TextMeshFont(node.fontFile, openTypeFont, this.scene);\n vertexDataBuilder = new TextMeshVertexData(font);\n textMeshFonts.set(node.fontFile, vertexDataBuilder);\n }\n return vertexDataBuilder.getText(node.text, node.fontSize, node.charSpacing, node.curveRadius);\n }\n }\n getMeshGeometry(node) {\n const mesh = this.get3d(node);\n if (mesh && mesh instanceof Mesh && mesh._geometry) {\n const geometry = SubmeshVertexData.ExtractFromMesh(mesh);\n // // Make sure the geometry is valid and actually has some geometry in it so consumers of this function don't have to deep check.\n // if(!geometry.indices || !geometry.positions || geometry.indices.length === 0) {\n // return null;\n // }\n return geometry;\n }\n return null;\n }\n fetchMaterialNode(meshNode, materialId) {\n var _a;\n const localMaterial = (_a = meshNode._manager) === null || _a === void 0 ? void 0 : _a.getById(materialId); //find the material if it's local\n return new Promise((resolve, reject) => {\n if (localMaterial) {\n //it's a local material\n resolve(localMaterial);\n }\n else {\n // Not a local material, so it's a global or library material\n this.rendererManager.material\n .loadGlobalMaterial(materialId, meshNode._manager.services)\n .pipe(take(1))\n .subscribe(globalLibMaterial => {\n if (!globalLibMaterial) {\n console.warn(`Cannot find global material ${materialId} on node ${meshNode.name} (${meshNode.id})`);\n reject('could not load global material');\n }\n else {\n resolve(globalLibMaterial);\n }\n });\n }\n });\n }\n setRenderModeOnMesh(mesh, sceneNode) {\n const mode = this.renderMode;\n if (mesh.geometry) {\n if (mode === exports.eRenderMode.edge || mode === exports.eRenderMode.hiddenEdges) {\n mesh.enableEdgesRendering(sceneNode.edgeDisplayTolerance);\n mesh.renderOutline = true;\n mesh.edgesWidth = sceneNode.edgeWidth;\n mesh.edgesColor = sceneNode.edgeColor.toColor4();\n mesh.outlineWidth = sceneNode.edgeWidth / 100;\n mesh.outlineColor = sceneNode.edgeColor.toColor3();\n // Another option for the hidden edges renderer but results in render artifacts especially when meshes go on top of each other.\n // if (mode === eRenderMode.hiddenEdges) {\n // mesh.metadata = { ...mesh.metadata, visibility: mesh.visibility };\n // mesh.visibility = 0.001;\n // }\n }\n else {\n // mesh.visibility = mesh.metadata?.visibility || 1;\n mesh.renderOutline = false;\n mesh.disableEdgesRendering();\n }\n }\n }\n getMeshVertexData(node) {\n if (!node._geometry) {\n throw Error('Cannot get vertex data because mesh has no geometry');\n }\n let meshVertexData = SubmeshVertexData.FromGeometry(node._geometry);\n meshVertexData = this.preTransformVertices(meshVertexData, node, node._geometry);\n return meshVertexData;\n }\n preTransformVertices(meshVertexData, node, cachedGeometry) {\n if (node.preTransform && node.preTransform.length !== 16) {\n throw Error('invalid pretransform array ');\n }\n // If pretransform is not set on the node, the transform we want is the identity matrix (no change from original)\n const transform = node.preTransform ? Matrix.FromArray(node.preTransform) : Matrix.Identity();\n // Check if the geometry has a transform applied\n const existingTransform = cachedGeometry === null || cachedGeometry === void 0 ? void 0 : cachedGeometry._hasTransform;\n // If the geometry has already been transformed, then we have to undo that transform to get the correct transform\n // Starting with the invert matrix of the existing transform will cancel out the existing transform and result in the original mesh\n if (existingTransform) {\n Matrix.FromArray(existingTransform).invert().multiplyToRef(transform, transform);\n }\n // If the transform we want (taking the existing transform into account) is the identity matrix, do nothing and return the geometry\n if (!transform.isIdentity()) {\n if (existingTransform) {\n // If the geometry has already been transformed, don't overwrite the transform so we don't repeatedly transform it\n meshVertexData = meshVertexData.deepClone();\n }\n else if (cachedGeometry) {\n // If the geoemtry has no existing transform, set the hasTransform property since it will get mutated with the new transform.\n cachedGeometry._hasTransform = node.preTransform;\n }\n meshVertexData.transform(transform);\n }\n return meshVertexData;\n }\n updateParentMeshFromNode(node, targetNode, isNewMesh) {\n const parentNode = node._parent;\n if (parentNode && parentNode instanceof exports.SpaceNode) {\n const isRootScene = parentNode instanceof exports.SceneNode && !parentNode.isNested();\n const parent3d = isRootScene\n ? this.rendererManager.sceneRenderer.get3d(parentNode)\n : this.get3d(parentNode);\n if (parent3d) {\n if (targetNode instanceof Mesh) {\n targetNode.setParent(parent3d);\n }\n else {\n targetNode.parent = parent3d;\n }\n }\n else {\n console.error(`Could not find mesh by ID ${parentNode.id} in scene!`);\n }\n }\n else {\n return; // if the node has no parent, it's not part of the scene anymore\n }\n if (isNewMesh ||\n SettingsManagerService.get('parentChangeBehavior') === exports.eParentChangeBehavior.PRESERVE_PROPERTY) {\n this.updateMeshTransform(node, targetNode, null);\n }\n else {\n node.position = exports.KbVector.FromVec3(targetNode.position);\n if (targetNode.rotationQuaternion) {\n node.useEuler = false;\n node.setRotationQuaternion(new exports.KbQuaternion(targetNode.rotationQuaternion.x, targetNode.rotationQuaternion.y, targetNode.rotationQuaternion.z, targetNode.rotationQuaternion.w));\n }\n else if (node.eulerRotation) {\n node.useEuler = true;\n node.eulerRotation = new exports.KbVector(targetNode.rotation.x, targetNode.rotation.y, targetNode.rotation.z);\n }\n node.scaling = targetNode.scaling.x;\n }\n this.invalidateBoundingBox(parentNode); //invalidate parent node in the bounding box cache as now it has a new child\n }\n recursiveLoadChildMeshGeometry(node) {\n const children = node.getChildren();\n children.forEach(child => {\n if (child instanceof exports.SpaceNode && child.visible) {\n if (child instanceof exports.CustomMeshNode && isTrackedClass(child)) {\n if (child.hasGeometry && !child._geometry && !child.geometryLoaded && !child._loading) {\n this.loadNewGeometry(child);\n }\n }\n else {\n this.recursiveLoadChildMeshGeometry(child);\n }\n }\n });\n }\n createOrUpdateMesh(node, otherMesh) {\n let mesh;\n if (otherMesh) {\n mesh = otherMesh;\n }\n else {\n mesh = this.get3d(node);\n }\n const changes = node.changes;\n let allChanges = false;\n let meshVerticesNeedReset = false;\n if (!mesh) {\n // New Mesh\n allChanges = true;\n if (isMeshNode(node))\n changes.set('features', node.features);\n if (isMeshGroupNode(node) || isSceneNode(node)) {\n mesh = new TransformNode(node._dynamicId, this.scene);\n }\n else {\n const newMesh = (mesh = new Mesh(node._dynamicId, this.scene));\n if (isCustomMeshNode(node) && isTrackedClass(node) && node._geometry) {\n this.setBabylonVertexData(node, newMesh);\n }\n else {\n meshVerticesNeedReset = true;\n }\n }\n mesh.scaling = Vector3.One();\n mesh.name = node.name;\n mesh.id = node._dynamicId;\n this.set3d(node, mesh);\n }\n else if (isCustomMeshNode(node) && changes.has('geometryId') && node._loading !== node.geometryId) {\n // Only load new geometry if the geometry hasn't just changed\n this.loadNewGeometry(node);\n }\n else if (isCustomMeshNode(node) && isTrackedClass(node) && node._geometry && node.changes.has('_geometry')) {\n // If we're changing the geometry, we always need to (re)apply all mesh properties\n // to the mesh as the new geometry won't have the right properties\n allChanges = true;\n changes.set('features', node.features);\n }\n if (allChanges ||\n changes.hasAny('position', 'useEuler', 'eulerRotation', 'rotationAxis', 'rotationAngle', 'pivot', 'scaling', '_showPivot')) {\n this.updateMeshTransform(node, mesh, allChanges ? null : changes);\n if (isMeshNode(node)) {\n this.rendererManager.material.reflectedMeshes.set(node._dynamicId, mesh);\n }\n this.rendererManager.material.updateReflectionProbes();\n }\n if (changes.has('scaling')) {\n this.updateConnectorScaling(node);\n }\n const pivotGizmo = this.pivotGizmos.get(node._dynamicId);\n if (allChanges || changes.has('visible')) {\n mesh.setEnabled(!!node.visible);\n this.viewer.polygonTracker.next();\n this.viewer.warningTracker.next();\n if (pivotGizmo) {\n pivotGizmo.setEnabled(!!node.visible);\n }\n this.invalidateBoundingBox(node);\n // If a group node is made visible and it has a child node that has geometry load it now\n if (node.visible && node instanceof exports.MeshGroupNode) {\n let parentNode = node._parent;\n let allParentsVisible = true;\n while (parentNode) {\n if (!parentNode.visible) {\n allParentsVisible = false;\n break;\n }\n parentNode = parentNode._parent;\n }\n if (allParentsVisible) {\n this.recursiveLoadChildMeshGeometry(node);\n }\n }\n }\n if (mesh instanceof Mesh) {\n const meshNode = node;\n mesh.isBlocker = false;\n if (allChanges || changes.has('receiveShadows')) {\n mesh.receiveShadows = !!meshNode.receiveShadows;\n this.shadowManager.toggleReceiver(mesh, !!meshNode.receiveShadows);\n }\n if (changes.has('isPickable')) {\n if (meshNode.isPickable !== undefined) {\n mesh.isPickable = meshNode.isPickable;\n }\n else {\n mesh.isPickable = true;\n }\n }\n if (allChanges || changes.has('castShadows'))\n this.shadowManager.toggleCaster(mesh, !!meshNode.castShadows);\n if (allChanges || changes.has('checkCollisions'))\n mesh.checkCollisions = !!meshNode.checkCollisions;\n if (allChanges || changes.has('flipSurfaceOrientation')) {\n if (meshNode.flipSurfaceOrientation) {\n mesh.overrideMaterialSideOrientation = Mesh.BACKSIDE;\n }\n else {\n mesh.overrideMaterialSideOrientation = Mesh.FRONTSIDE;\n }\n }\n if (this.renderMode !== exports.eRenderMode.hiddenEdges) {\n if (allChanges || changes.has('opacity')) {\n mesh.visibility = meshNode.opacity == null ? 1 : meshNode.opacity;\n }\n }\n const warningTracker = {\n name: meshNode.name,\n isEnabled: meshNode.visible,\n castShadows: meshNode.castShadows || false,\n receiveShadows: meshNode.receiveShadows || false,\n polygonNumber: meshNode._polygonCount || 0,\n featureNumber: node.features.length,\n };\n this.viewer.MeshWarningTracker.set(mesh.id, warningTracker);\n // Material\n if (allChanges || changes.has('materialId') || changes.has('visible')) {\n const _mesh = mesh;\n // If the material is a multimaterial, make sure all the material nodes making it up are initialized\n if (meshNode.visible && mesh.material instanceof MultiMaterial) {\n mesh.material.subMaterials.forEach(material => {\n if (material) {\n const localMaterial = getByDynamicId(material.id, false);\n if (localMaterial) {\n localMaterial.init();\n }\n else {\n // Global material ?\n const globalMaterial = this.rendererManager.material.getGlobalMaterial(material.id);\n if (globalMaterial) {\n globalMaterial.init();\n }\n }\n }\n });\n }\n if (meshNode.materialId) {\n this.fetchMaterialNode(meshNode, meshNode.materialId).then(materialNode => {\n if (meshNode.visible) {\n this.setMaterialOnMesh(meshNode, _mesh, materialNode);\n }\n }, () => {\n meshNode.materialId = undefined;\n });\n }\n else {\n if (mesh.material instanceof MultiMaterial) {\n mesh.material.subMaterials[0] = this.rendererManager.material.defaultMaterial;\n mesh.material.forceCompilation(mesh); // If you don't do this webgl vomits errors because we invalidated the cache\n }\n else {\n mesh.material = this.rendererManager.material.defaultMaterial;\n }\n }\n if (isMeshNode(node)) {\n this.rendererManager.material.reflectedMeshes.set(node._dynamicId, mesh);\n }\n this.rendererManager.material.updateReflectionProbes();\n }\n let sketchNode;\n let updateSketchDrawing = false;\n // For primitives, recalculate the mesh if the shape properties changed\n if (isPrimitiveMeshNode(meshNode)) {\n if (allChanges) {\n meshVerticesNeedReset = true;\n }\n else {\n meshNode.changes.forEach((_, key) => {\n if (primitiveShapeProperties.has(key)) {\n meshVerticesNeedReset = true;\n }\n });\n }\n }\n else if (isCustomMeshNode(meshNode) && isTrackedClass(meshNode)) {\n meshVerticesNeedReset = meshNode.changes.has('_geometry') && !!meshNode._geometry;\n }\n else if (isSketchNode(meshNode) && isTrackedClass(meshNode)) {\n sketchNode = meshNode;\n meshVerticesNeedReset = sketchNode.changes.hasAny('paths', 'addFace', 'flipPath', 'clonePath', 'closePath', '_previewVisible');\n updateSketchDrawing = sketchNode.changes.hasAny('paths', 'addFace', 'flipPath', 'clonePath', 'closePath', '_previewVisible', 'lineThickness', 'pathColor', 'tracePath');\n if (sketchNode.changes.hasAny('boundingXOverride', 'boundingYOverride', 'boundingZOverride')) {\n sketchNode._boundingBoxChanges.next(sketchNode.getBoundingBox());\n }\n }\n else if (isTextNode(meshNode) && isTrackedClass(meshNode)) {\n meshVerticesNeedReset = meshNode.changes.hasAny('text', 'fontSize', 'curveRadius', 'charSpacing', 'fontFile');\n }\n let preTransformChanged = false;\n if (allChanges || changes.hasAny('features', 'preTransform')) {\n meshVerticesNeedReset = true;\n preTransformChanged = !(allChanges || changes.has('_geometry')); // If geometry has changed, then the geometry was just loaded\n }\n // Features or shape properties have been changed, we have to recalculate original geometry and reprocess features on top\n if (allChanges || changes.has('uvOverrides') || meshVerticesNeedReset || updateSketchDrawing) {\n const meshVertexData = this.rebuildBaseGeometry(node, preTransformChanged);\n if (meshVertexData) {\n // This call should also apply the new vertex data.\n this.rendererManager.features.resetMeshGeometry(meshNode, null, meshVertexData);\n }\n else {\n if (mesh.geometry) {\n // If mesh geometry is set, the mesh was previously initialized but now is being generated with no geometry so we should destroy the old geometry\n // Failing to do so will cause Babylon geometry issues\n mesh.dispose();\n this.delete3d(node);\n }\n }\n if (sketchNode && sketchNode._previewVisible) {\n this.updateSketchPreview(sketchNode, meshVertexData, mesh);\n }\n if (sketchNode && sketchNode.tracePath && updateSketchDrawing) {\n if (sketchNode) {\n this.updateSketchTracing(sketchNode, meshVertexData, mesh);\n }\n }\n }\n // If this is a sketch, see if we need to show a preview of it\n if (sketchNode && sketchNode.changes.has('_previewVisible')) {\n const previewMesh = this.sketchPreviews.get(meshNode._dynamicId);\n if (previewMesh) {\n previewMesh.setEnabled(sketchNode._previewVisible);\n }\n }\n this.viewer.meshWarningsNeedsUpdate.next();\n }\n return mesh;\n }\n updateMeshTransform(node, mesh, changes // null means all changes\n ) {\n const pivot = node.pivot.toVec3();\n const originOffset = pivot.scale(-1);\n const newPosition = node.position.toVec3();\n let newRotation;\n if (node.useEuler) {\n newRotation = Quaternion.FromEulerAngles(toRadians(node.eulerRotation.x), toRadians(node.eulerRotation.y), toRadians(node.eulerRotation.z));\n }\n else {\n newRotation = Quaternion.RotationAxis(node.rotationAxis.toVec3(), toRadians(node.rotationAngle));\n }\n const rotationMatrix = new Matrix();\n newRotation.toRotationMatrix(rotationMatrix);\n Vector3.TransformCoordinatesToRef(originOffset, rotationMatrix, originOffset);\n mesh.rotationQuaternion = newRotation;\n const scalingMatrix = Matrix.Scaling(node.scaling, node.scaling, node.scaling);\n Vector3.TransformCoordinatesToRef(originOffset, scalingMatrix, originOffset);\n mesh.scaling = new Vector3().setAll(node.scaling);\n newPosition.addInPlace(originOffset).addInPlace(pivot);\n if (!mesh.position.equals(newPosition)) {\n mesh.position = newPosition;\n }\n this.rendererManager.features.transformChanged(node);\n this.invalidateBoundingBox(!changes || changes.has('scaling') ? node : node._parent); //scaling, changes current node, but all others only change the parent\n if (node._showPivot) {\n let pivotGizmo = this.pivotGizmos.get(node._dynamicId);\n if (!pivotGizmo) {\n pivotGizmo = SphereBuilder.CreateSphere('pivotSphere', { diameter: 0.05 }, this.utilityLayer.utilityLayerScene);\n const coloredMaterial = new StandardMaterial('', this.utilityLayer.utilityLayerScene);\n coloredMaterial.emissiveColor = Color3.Red();\n pivotGizmo.material = coloredMaterial;\n this.pivotGizmos.set(node._dynamicId, pivotGizmo);\n }\n if (!pivotGizmo.isEnabled()) {\n pivotGizmo.setEnabled(true);\n }\n const worldPivot = pivot.add(node.position.toVec3());\n if (mesh.parent) {\n const transform = mesh.parent.computeWorldMatrix(true);\n Vector3.TransformCoordinatesToRef(worldPivot, transform, worldPivot);\n }\n pivotGizmo.position = worldPivot;\n }\n else {\n const pivotGizmo = this.pivotGizmos.get(node._dynamicId);\n if (pivotGizmo && pivotGizmo.isEnabled()) {\n pivotGizmo.setEnabled(false);\n }\n }\n return mesh;\n }\n createPrimitiveMesh(node) {\n if (!isPrimitiveMeshNode(node))\n throw Error('Primitive not set');\n if (isBoxMesh(node)) {\n if (node.tessellation <= 1) {\n return MeshBuilder.CreateBox(node._dynamicId, {\n height: node.height,\n width: node.width,\n depth: node.depth,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n updatable: true,\n }, this.scene);\n }\n else {\n return MeshBuilder.CreateTiledBox(node._dynamicId, {\n height: node.height,\n width: node.width,\n depth: node.depth,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n updatable: true,\n tileSize: 1 / node.tessellation,\n }, this.scene);\n }\n }\n else if (isSphereMesh(node)) {\n return SphereBuilder$1.CreateSphere(node._dynamicId, {\n segments: node.tessellation,\n diameter: node.radius * 2,\n arc: node.arc / 360,\n sliceStart: node.latitudeStart / 180,\n slice: node.latitudeSlice / 180,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n updatable: true,\n }, this.scene);\n }\n else if (isCylinderMesh(node)) {\n return CylinderBuilder$1.CreateCylinder(node._dynamicId, {\n height: node.height,\n diameter: node.radius * 2,\n tessellation: node.tessellation,\n subdivisions: node.subdivisions,\n hasRings: node.subdivisions > 1,\n cap: capModeMap[node.capMode],\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n arc: node.arc / 360,\n updatable: true,\n }, this.scene);\n }\n else if (isConeMesh(node)) {\n return MeshBuilder.CreateCylinder(node._dynamicId, {\n height: node.height,\n diameterTop: node.radiusTop * 2,\n diameterBottom: node.radiusBottom * 2,\n tessellation: node.tessellation,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n updatable: true,\n }, this.scene);\n }\n else if (isTorusMesh(node)) {\n return TorusBuilder.CreateTorus(node._dynamicId, {\n diameter: node.radius * 2,\n thickness: node.thickness,\n tessellation: node.tessellation,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n arc: node.arc / 360,\n sliceStart: node.latitudeStart / 360,\n slice: node.latitudeSlice / 360,\n updatable: true,\n }, this.scene);\n }\n else if (isPlaneMesh(node)) {\n const mesh = PlaneBuilder$1.CreatePlane(node._dynamicId, {\n width: node.width,\n height: node.depth,\n tileHeight: node.depth / node.segments,\n tileWidth: node.width / node.segments,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n updatable: true,\n }, this.scene);\n mesh.rotation.x = Math.PI / 2;\n mesh.bakeCurrentTransformIntoVertices();\n return mesh;\n }\n else if (isDiscMesh(node)) {\n return DiscBuilder.CreateDisc(node._dynamicId, {\n radius: node.radius,\n tessellation: node.tessellation,\n sideOrientation: exports.eSideOrientationBabylonMap[node.sideOrientation],\n updatable: true,\n }, this.scene);\n }\n else {\n throw Error('Mesh primitive not implemented');\n }\n }\n setBabylonVertexData(kbMesh, mesh, preserveSubmeshes = true) {\n if (!kbMesh._geometry) {\n return;\n }\n const vertexData = this.getMeshVertexData(kbMesh);\n const invalid = verifyGeometry(vertexData);\n if (invalid) {\n console.error(`Invalid or corrupted geometry in mesh ${kbMesh.name}. The ${invalid} are invalid.`);\n }\n else {\n vertexData.applyToMesh(mesh, true, preserveSubmeshes);\n kbMesh._polygonCount = mesh.getTotalIndices() / 3;\n kbMesh._verticesCount = mesh.getTotalVertices();\n this.viewer.polygonTracker.next();\n this.viewer.warningTracker.next();\n }\n this.setRenderModeOnMesh(mesh, kbMesh._rootScene);\n if (mesh.isFacetDataEnabled) {\n mesh.updateFacetData();\n }\n }\n setBabylonUvData(uvData, vertexData) {\n if (uvData.uvs) {\n vertexData.uvs = uvData.uvs;\n }\n if (uvData.uv2s) {\n vertexData.uvs2 = uvData.uv2s;\n }\n if (uvData.uv3s) {\n vertexData.uvs3 = uvData.uv3s;\n }\n if (uvData.uv4s) {\n vertexData.uvs4 = uvData.uv4s;\n }\n if (uvData.uv5s) {\n vertexData.uvs5 = uvData.uv5s;\n }\n if (uvData.uv6s) {\n vertexData.uvs6 = uvData.uv6s;\n }\n return vertexData;\n }\n setMaterialOnMesh(meshNode, babylonMesh, materialNode) {\n if (meshNode.visible) {\n materialNode.init();\n }\n const material = this.rendererManager.material.get3d(materialNode);\n if (!material) {\n throw Error('Material could not be found in renderer. Has the material been created?');\n }\n // If the mesh already has a material and it's a multimaterial, then update the material on index 0\n // Which is reserved for the \"base\" material.\n if (babylonMesh.material instanceof MultiMaterial) {\n babylonMesh.material.subMaterials[0] = material;\n babylonMesh.material.forceCompilation(babylonMesh);\n }\n else if (!babylonMesh.material || babylonMesh.material.id != materialNode._dynamicId) {\n babylonMesh.material = material;\n }\n }\n invalidateBoundingBox(node) {\n if (node) {\n this.viewer.bbCache.invalidate(node);\n }\n }\n delete3d(node) {\n if (isSketchNode(node)) {\n node._boundingBoxChanges.complete();\n }\n const bnode = this.get3d(node);\n if (bnode && bnode instanceof Mesh) {\n this.viewer.MeshWarningTracker.delete(bnode.id);\n this.shadowManager.removeCaster(bnode);\n this.shadowManager.removeReceiver(bnode);\n if (bnode.material instanceof MultiMaterial) {\n bnode.material.dispose(true, true, false); // multimaterials are 1:1 with meshes\n }\n }\n this.rendererManager.material.reflectedMeshes.delete(node._dynamicId);\n this.rendererManager.material.updateReflectionProbes();\n this.viewer.meshWarningsNeedsUpdate.next();\n super.delete3d(node);\n this.viewer.polygonTracker.next();\n this.viewer.warningTracker.next();\n }\n createSketchPlaneVisualization(sketch) {\n const color = Color3.Yellow();\n const boundingBox = sketch.calculatedBoundingBox;\n let squareSize = 3;\n let calculatedSize = 0;\n let boundingBoxCenter = new Vector3(0, 0, 0);\n if (boundingBox) {\n boundingBoxCenter = boundingBox.center.clone();\n calculatedSize = boundingBox.minimum.subtract(boundingBox.maximum).length();\n }\n if (calculatedSize > squareSize) {\n squareSize = calculatedSize * 1;\n }\n const coloredMaterial = new StandardMaterial('', this.scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n const sketchPlaneVisualization = CreatePlane('mirrorPlane', { size: squareSize }, this.scene);\n const sketchMesh = this.viewer.getRendererNode(sketch);\n if (sketchMesh) {\n const translation = sketchMesh.computeWorldMatrix();\n const position = Vector3.TransformCoordinates(boundingBoxCenter, translation);\n sketchPlaneVisualization.position = new Vector3(position.x, position.y, position.z);\n const sketchNormal = new Vector3(0, 0, 0);\n if (sketch.normal === exports.eAxis.x) {\n sketchNormal.set(1, 0, 0);\n }\n else if (sketch.normal === exports.eAxis.y) {\n sketchNormal.set(0, 1, 0);\n }\n else {\n sketchNormal.set(0, 0, 1);\n }\n const rotationVector = Vector3.TransformCoordinates(sketchNormal, sketchMesh.computeWorldMatrix().getRotationMatrix());\n rotationVector.z = rotationVector.z * -1;\n const resultQuaternion = new Quaternion();\n Quaternion.FromUnitVectorsToRef(rotationVector, new Vector3(0, 0, 1), resultQuaternion);\n sketchPlaneVisualization.rotationQuaternion = resultQuaternion;\n //uvMapVisualization.rotation = Vector3.RotationFromAxis()\n sketchPlaneVisualization.material = coloredMaterial;\n sketchPlaneVisualization.bakeCurrentTransformIntoVertices();\n return sketchPlaneVisualization;\n }\n else {\n console.warn('Sketch visualization plane cannot be generated, please check direction and position of sketchpoints.');\n return null;\n }\n }\n updateConnectorScaling(node) {\n if (node instanceof exports.SketchNode) {\n node.paths.forEach(path => {\n path.controlPoints.forEach(controlPoint => {\n this.viewer.rendererManager.controlPointRenderer.updateScale(controlPoint);\n });\n });\n }\n else {\n if (node.connectors) {\n node.connectors.forEach(connector => {\n this.viewer.rendererManager.connector.updateScale(connector);\n });\n }\n const childNodes = node.getChildren();\n if (childNodes) {\n childNodes.forEach(child => {\n if (child instanceof exports.SpaceNode) {\n this.updateConnectorScaling(child);\n }\n });\n }\n }\n }\n calculateSketchBoundingBox(node) {\n const firstPoint = node.paths[0]._points[0];\n const minVector = new Vector3(firstPoint.x, firstPoint.y, firstPoint.z);\n const maxVector = new Vector3(firstPoint.x, firstPoint.y, firstPoint.z);\n node.paths.forEach(path => {\n path._points.forEach(point => {\n if (point.x < minVector.x) {\n minVector.x = point.x;\n }\n if (point.y < minVector.y) {\n minVector.y = point.y;\n }\n if (point.z < minVector.z) {\n minVector.z = point.z;\n }\n if (point.x > maxVector.x) {\n maxVector.x = point.x;\n }\n if (point.y > maxVector.y) {\n maxVector.y = point.y;\n }\n if (point.z > maxVector.z) {\n maxVector.z = point.z;\n }\n });\n });\n return new BoundingBox(minVector, maxVector);\n }\n }\n\n class PathRenderer extends Renderer {\n constructor(viewer, scene) {\n super(viewer, scene);\n this.viewer = viewer;\n this.scene = scene;\n this.modelToken = Token.SketchPath;\n }\n update3dInternal(node) { }\n }\n\n // function limitFPE(val: number) {\n // return Math.round((val + Number.EPSILON) * 100000000) / 100000000;\n // }\n // function roundQuaterion(q: Quaternion) {\n // return new Quaternion(limitFPE(q.x), limitFPE(q.y), limitFPE(q.z), limitFPE(q.w));\n // }\n function mateControlPointToConnector(mate, c1Mesh, controlPointMesh) {\n let grandParentContainerWorldMatrixInv;\n if (controlPointMesh.parent) {\n grandParentContainerWorldMatrixInv = controlPointMesh.parent.computeWorldMatrix(true).clone().invert();\n }\n else {\n grandParentContainerWorldMatrixInv = Matrix.IdentityReadOnly;\n }\n const targetTransformMatrix = c1Mesh.computeWorldMatrix().clone();\n targetTransformMatrix.multiplyToRef(grandParentContainerWorldMatrixInv, targetTransformMatrix);\n const position = new Vector3();\n const direction = new Vector3();\n targetTransformMatrix.decompose(undefined, undefined, position);\n Vector3.TransformNormalFromFloatsToRef(-1.0, 0, 0, targetTransformMatrix, direction);\n if (!mate.flip) {\n direction.scaleInPlace(-1);\n }\n direction.normalize();\n return {\n position,\n direction,\n };\n }\n const flipMatrix = new Matrix();\n Quaternion.RotationAxis(Axis.Y, toRadians(180)).toRotationMatrix(flipMatrix);\n function mateConnectors(mate, followerMesh, c1Mesh, c2Mesh) {\n updateMatrixOfAncestorChain(followerMesh, c2Mesh);\n c1Mesh.computeWorldMatrix(true);\n let mateOffset = Vector3.Zero();\n let worldDelta = Vector3.Zero(); //the translation that c2 would need to make to get to it's new position\n if (mate.mateType == exports.eMateType.ball) {\n /**\n * Ball Mate\n * -move c2 until it's in the same position as c1\n * In the future this could be made more intelligent by rotating a node to satisfy this mate and another ball or slider mate\n */\n worldDelta = c1Mesh.getAbsolutePosition().subtract(c2Mesh.getAbsolutePosition());\n }\n else {\n /**\n * Aligning direction vectors\n * ------------------------------------------------\n * Easiest way to think about this:\n * Connectors have a direction vector, and an angle of rotation around the direction vector.\n * The connector meshes are rotated by the renderer such that the positive X axis is pointing\n * in the direction of the direction vector. And the angle vector will be pointing in the direction\n * of the y axis.\n *\n * We want the world transformation matrix of the second connector to match the world transform of the first connector (optionally flipped).\n * The math for calculating the world matrix of a connector can be written as:\n * * * \n * We are trying to solve for the local transform matrix of the connector parent so the full world transform matches the transform of the first connector,\n * so we can rewrite the equation as:\n * = * * \n *\n * Then we apply the result matrix to the connector parent.\n */\n const t = new Vector3();\n const r = new Quaternion();\n const s = new Vector3();\n c1Mesh.computeWorldMatrix(true).decompose(s, r, t);\n if (mate.offsetAngle && mate.offsetAngle !== 0) {\n const angleOffsetQ = Quaternion.RotationAxis(Axis.X, (mate.offsetAngle * Math.PI) / 180);\n r.multiplyInPlace(angleOffsetQ);\n }\n const targetWorldTransformMatrix = Matrix.Compose(followerMesh.scaling, r, t);\n const currentWorldTransformMatrix = c2Mesh.computeWorldMatrix(true).clone();\n if (!mate.flip) {\n flipMatrix.multiplyToRef(targetWorldTransformMatrix, targetWorldTransformMatrix);\n }\n const c2LocalTransform = Matrix.Compose(c2Mesh.scaling, c2Mesh.rotationQuaternion, c2Mesh.position);\n let grandParentContainerWorldMatrix;\n if (followerMesh.parent) {\n grandParentContainerWorldMatrix = followerMesh.parent.computeWorldMatrix(true).clone();\n }\n else {\n grandParentContainerWorldMatrix = Matrix.IdentityReadOnly;\n }\n const grandParentContainerWorldMatrixInv = grandParentContainerWorldMatrix.clone().invert();\n let calculatedTargetWorldTransform;\n if (mate.mateType.equalsAny(exports.eMateType.revolute, exports.eMateType.cylindrical)) {\n /**\n * For these types of mates, the objective is to match the direction vectors but allow the angle to float freely.\n * What this means in practice is that we have to split the quaternion into a swing and a twist component.\n * The swing component will rotate the direction vector to point the right way, along a rotation axis equal to the cross product of the X axis and the direction vector,\n * and the twist component will rotate the mesh around the direction vector to match the desired angles. We then throw away the \"new\" twist angle and use the original twist angle.\n * For this to work it's necessary to ensure that the same rotation axis is used for both the swing rotation of the target and the swing rotation of the current, if the directions match.\n * Otherwise the twist angles won't be referring to the same thing.\n */\n const targetQ = Quaternion.FromRotationMatrix(targetWorldTransformMatrix.getRotationMatrix());\n const currentQ = Quaternion.FromRotationMatrix(currentWorldTransformMatrix.getRotationMatrix());\n const targetDirection = Vector3.TransformNormal(Axis.X, targetWorldTransformMatrix).normalize();\n const currentDirection = c2Mesh.right;\n // At direction vectors close to or equal to the X axis, the twist angle becomes heavily affected by floating point errors, so we avoid loops by not updating the rotation if the direction vectors are close to each other.\n if (currentDirection.add(targetDirection).length() > 0.0001) {\n const targetST = decomposeSwingTwist(targetQ, targetDirection.scale(-1));\n const currentST = decomposeSwingTwist(currentQ, currentDirection);\n const targetRotationNew = targetST.swing.multiply(currentST.twist);\n calculatedTargetWorldTransform = Matrix.Compose(followerMesh.scaling, targetRotationNew, t);\n }\n }\n else if (mate.mateType.equalsAny(exports.eMateType.fastened, exports.eMateType.planar, exports.eMateType.slider)) {\n calculatedTargetWorldTransform = targetWorldTransformMatrix;\n }\n if (calculatedTargetWorldTransform) {\n const followerMeshTransformMatrix = c2LocalTransform.clone().invert();\n followerMeshTransformMatrix.multiplyToRef(calculatedTargetWorldTransform, followerMeshTransformMatrix);\n followerMeshTransformMatrix.multiplyToRef(grandParentContainerWorldMatrixInv, followerMeshTransformMatrix);\n const resultFollowerRotMatrix = followerMeshTransformMatrix.getRotationMatrix();\n {\n followerMesh.rotationQuaternion = Quaternion.FromRotationMatrix(resultFollowerRotMatrix);\n updateMatrixOfAncestorChain(followerMesh, c2Mesh); //update world matrix after having just rotated follower mesh\n }\n }\n if (mate.mateType == exports.eMateType.fastened || mate.mateType == exports.eMateType.revolute) {\n //translate so the connectors line up\n worldDelta = c1Mesh.getAbsolutePosition().subtract(c2Mesh.getAbsolutePosition());\n mateOffset = new Vector3(mate.offsetX, mate.offsetY, mate.offsetZ);\n }\n else if (mate.mateType == exports.eMateType.planar) {\n /**\n * Planar Mate\n * - define a plane at the position of c1, with a normal in the direction of c1\n * - make a ray from c2 in the direction of c2, and try to intersect the c1 plane\n * - if it doesn't intersect, flip it and try again\n * - the intersection of the ray and plane is the new position of c2 (not considering offset)\n */\n const c1PlaneNormal = Axis.X.rotateByQuaternionToRef(c1Mesh.absoluteRotationQuaternion, Vector3.Zero());\n const c1Plane = Plane.FromPositionAndNormal(c1Mesh.getAbsolutePosition(), c1PlaneNormal);\n const c2Direction = Axis.X.rotateByQuaternionToRef(c2Mesh.absoluteRotationQuaternion, Vector3.Zero());\n const ray = new Ray(c2Mesh.getAbsolutePosition(), c2Direction);\n let distance = ray.intersectsPlane(c1Plane);\n if (distance == null) {\n //if it doesn't intersect try flipping it\n ray.direction.negateInPlace();\n distance = ray.intersectsPlane(c1Plane);\n }\n worldDelta = ray.direction.scale(distance);\n mateOffset = new Vector3(mate.offsetX, 0, 0); //only use the x component for planar mates\n }\n else if (mate.mateType == exports.eMateType.slider || mate.mateType == exports.eMateType.cylindrical) {\n /**\n * Slider Mate\n * - define a plane at the position of c2, with a normal in the direction of c2\n * - make a ray from c1 in the direction of c1, and try to intersect the c2 plane\n * - if it doesn't intersect, flip it and try again\n * - the intersection of the ray and plane is the new position of c2 (not considering offset)\n */\n const c1Pos = c1Mesh.getAbsolutePosition();\n const c2Pos = c2Mesh.getAbsolutePosition();\n const c2PlaneNormal = c2Mesh.getDirection(Axis.X).normalize();\n const c2Plane = Plane.FromPositionAndNormal(c2Pos, c2PlaneNormal);\n const c1Direction = c1Mesh.getDirection(Axis.X).normalize();\n const ray = new Ray(c1Pos, c1Direction);\n let distance = ray.intersectsPlane(c2Plane);\n if (distance == null) {\n //if it doesn't intersect try flipping it\n ray.direction.negateInPlace();\n distance = ray.intersectsPlane(c2Plane);\n }\n worldDelta = ray.direction.scale(distance).add(c1Pos).subtract(c2Pos);\n mateOffset = new Vector3(0, mate.offsetY, mate.offsetZ); //don't use the x component for slider mates\n }\n else if (mate.mateType == exports.eMateType.parallel) ;\n }\n /**\n * now we process the offset and set the position of c2 parent node\n */\n if (!mate.flip)\n mateOffset.negateInPlace();\n if (mate._swap)\n mateOffset.y = -mateOffset.y;\n const worldOffset = mateOffset.rotateByQuaternionToRef(c1Mesh.absoluteRotationQuaternion, Vector3.Zero());\n const totalOffset = worldOffset.add(worldDelta);\n const newAbsPos = followerMesh.getAbsolutePosition().add(totalOffset);\n followerMesh.setAbsolutePosition(newAbsPos);\n followerMesh.computeWorldMatrix(true);\n }\n /**\n Decompose the rotation on to 2 parts.\n 1. Twist - rotation around the \"direction\" vector\n 2. Swing - rotation around axis that is perpendicular to \"direction\" vector\n The rotation can be composed back by\n rotation = swing * twist\n\n has singularity in case of swing_rotation close to 180 degrees rotation.\n if the input quaternion is of non-unit length, the outputs are non-unit as well\n otherwise, outputs are both unit\n */\n function decomposeSwingTwist(rotation, _direction) {\n // Ensure the direction vector is normalized\n const direction = _direction.clone().normalize();\n const twist = new Quaternion();\n const swing = new Quaternion();\n // Alternate code with indeterminate swing axis\n // const ra = new Vector3(rotation.x, rotation.y, rotation.z);\n // const p = direction.scale(Vector3.Dot(ra, direction));\n // twist.set(p.x, p.y, p.z, rotation.w);\n // twist.normalize();\n // rotation.multiplyToRef(twist.conjugate(), swing);\n rotationToVectorToRef(direction, Axis.X, swing);\n swing.conjugate().multiplyToRef(rotation, twist);\n return { twist, swing };\n }\n\n (function (ConstraintType) {\n ConstraintType[ConstraintType[\"Sphere\"] = 0] = \"Sphere\";\n ConstraintType[ConstraintType[\"Line\"] = 1] = \"Line\";\n ConstraintType[ConstraintType[\"Plane\"] = 2] = \"Plane\";\n ConstraintType[ConstraintType[\"Fixed\"] = 3] = \"Fixed\";\n ConstraintType[ConstraintType[\"None\"] = 4] = \"None\";\n })(exports.ConstraintType || (exports.ConstraintType = {}));\n function sortMates(validMates) {\n const fixed = new Set();\n const primes = new Set();\n const nodeMap = getNodeMap(validMates);\n //parent/child relationships are also a kind of edge in our graph, so add them\n for (const [node] of nodeMap) {\n if (node instanceof exports.SpaceNode) {\n if (node.fixed) {\n fixed.add(node);\n }\n else if (node._primeMover) {\n primes.add(node);\n }\n for (const ancestor of node.getAncestors()) {\n if (nodeMap.has(ancestor)) {\n nodeMap.add(node, {\n target: ancestor,\n constraint: { type: exports.ConstraintType.None, properties: undefined },\n });\n nodeMap.add(ancestor, {\n target: node,\n constraint: { type: exports.ConstraintType.Fixed, properties: undefined },\n });\n }\n }\n }\n }\n /**\n * * starting with primes, recurse through. Then move to non-primes, ignoring those already visited.\n */\n const visitedNodes = new Set();\n const visitedMates = new Set();\n const nodePath = new Set();\n const matePath = new Set();\n const sorted = new Set();\n const cycles = new Array();\n const overConstrained = new Array();\n for (const n of [...fixed, ...primes, ...nodeMap.keys()]) {\n recurseMateChain(nodeMap, visitedNodes, visitedMates, nodePath, matePath, sorted, cycles, overConstrained, n);\n }\n //remove overconstrained mates from sorted so they don't get processed\n for (const m of overConstrained) {\n sorted.delete(m);\n }\n return {\n sorted,\n cycles,\n overConstrained,\n };\n }\n /**\n * Gets the nodes that are connected to the given through a chain of mates\n */\n function getNodeChain(node, validMates) {\n const nodeMap = getNodeMap(validMates);\n const visitedNodes = new Set();\n const visitedMates = new Set();\n const nodePath = new Set();\n const matePath = new Set();\n const sorted = new Set();\n const cycles = new Array();\n const overConstrained = new Array();\n recurseMateChain(nodeMap, visitedNodes, visitedMates, nodePath, matePath, sorted, cycles, overConstrained, node);\n visitedNodes.delete(node);\n return visitedNodes;\n }\n function getNodeMap(validMates) {\n const nodeMap = new ArrayMap();\n for (const mate of validMates) {\n const c1 = mate.getC1();\n const c2 = mate.getC2();\n let c1Parent = c1 === null || c1 === void 0 ? void 0 : c1.getSpaceParent();\n let c2Parent = c2 === null || c2 === void 0 ? void 0 : c2.getSpaceParent();\n if (c1 && isSketchControlPoint(c1)) {\n c1Parent = c1;\n }\n if (c2 && isSketchControlPoint(c2)) {\n c2Parent = c2;\n }\n if (c1 && c2 && c1Parent && c2Parent) {\n const constraint = { type: exports.ConstraintType.Fixed, properties: undefined };\n // TODO [RO] - Later on we can add more constraint types here based on mate type (CPQ-3881)\n //if (isConstrainingConnector(c1) && isConstrainingConnector(c2)) {\n // constraint = { type: ConstraintType.Fixed, properties: undefined };\n // } else {\n // constraint = { type: ConstraintType.None, properties: undefined };\n // }\n nodeMap.add(c1Parent, { target: c2Parent, mate, constraint });\n nodeMap.add(c2Parent, { target: c1Parent, mate, constraint });\n }\n }\n return nodeMap;\n }\n function recurseMateChain(nodeMap, visitedNodes, visitedMates, nodePath, matePath, sorted, cycles, overConstrained, node, mate, sourceEdge, isOverconstrained = false) {\n if (!sourceEdge || sourceEdge.constraint.type === exports.ConstraintType.Fixed) {\n if (nodePath.has(node)) {\n const cycle = [...matePath];\n if (mate) {\n cycle.push(mate);\n }\n cycles.push(cycle);\n }\n if (visitedNodes.has(node)) {\n return;\n }\n }\n visitedNodes.add(node);\n nodePath.add(node);\n if (mate) {\n matePath.add(mate);\n visitedMates.add(mate);\n sorted.add(mate);\n const c1 = mate.getC1();\n const c2 = mate.getC2();\n /** Move along sketch connectors should always be the connector 1, because they can't be moved (they are read only) */\n if (c2.positionMode === exports.eConnectorPositionMode.moveAlongSketch) {\n mate._swap = true;\n }\n /** Control points are always follower meshes */\n else if (isConnector(c1) && isSketchControlPoint(c2)) {\n mate._swap = false;\n }\n else if (isConnector(c2) && isSketchControlPoint(c1)) {\n mate._swap = true;\n }\n else {\n /** mate needs to have c1/c2 swapped if we got here in the opposite direction */\n mate._swap = c1._parent === node;\n }\n }\n // If the source edge is fixed, we recurse through the node because all the node's connectors will be shifting.\n // If the source edge is not fixed, we stop here because only the mated connector will move\n // [RO] TODO eventually we will have to rethink this logic to support more constraint types (CPQ-3881)\n if (!sourceEdge || sourceEdge.constraint.type === exports.ConstraintType.Fixed) {\n for (const edge of nodeMap.get(node)) {\n if (!edge.mate || !visitedMates.has(edge.mate)) {\n if (edge.target instanceof exports.SpaceNode &&\n edge.target.fixed &&\n edge.constraint.type !== exports.ConstraintType.None) {\n isOverconstrained = true;\n }\n recurseMateChain(nodeMap, visitedNodes, visitedMates, nodePath, matePath, sorted, cycles, overConstrained, edge.target, edge.mate, edge, isOverconstrained);\n }\n }\n }\n nodePath.delete(node);\n if (mate) {\n matePath.delete(mate);\n if (isOverconstrained) {\n overConstrained.push(mate);\n }\n visitedMates.delete(mate);\n }\n }\n\n class Processor {\n constructor() {\n this.afterCleanupTasks = [];\n }\n beforeRender() { }\n beforeDeletions(deletions) { }\n afterDeletions(deletions) { }\n beforeUpdates(changes) { }\n afterUpdates(changes) { }\n afterCleanup(func) {\n this.afterCleanupTasks.push(func);\n }\n doAfterCleanup() {\n this.afterCleanupTasks.forEach(task => task());\n this.afterCleanupTasks.clear();\n }\n dispose() { }\n }\n\n const CYCLE_ERROR_START = 'Cycle detected: ';\n class MateProcessor extends Processor {\n constructor(viewer, scene, connectorRenderer, controlPointRenderer, referenceProcessor) {\n super();\n this.viewer = viewer;\n this.scene = scene;\n this.connectorRenderer = connectorRenderer;\n this.controlPointRenderer = controlPointRenderer;\n this.referenceProcessor = referenceProcessor;\n }\n beforeRender() {\n this.rebuildDependencies = false;\n }\n beforeDeletions(deletions) {\n const mateDeletions = deletions.get(Token.MateNode);\n const connectorDeletions = deletions.get(Token.Connector);\n this.rebuildDependencies =\n this.rebuildDependencies || mateDeletions.length > 0 || connectorDeletions.length > 0;\n }\n beforeUpdates(changes) {\n //determine if mate dependencies need to be rebuilt\n const mateChanges = changes.get(Token.MateNode);\n const connectorChanges = changes.get(Token.Connector);\n const meshChanges = changes.get(Token.SpaceNode);\n this.rebuildDependencies =\n this.rebuildDependencies ||\n mateChanges.some(m => m.changes.hasAny('connector1', 'connector2', 'enabled')) ||\n connectorChanges.some(c => c.changes.has('enabled')) ||\n meshChanges.some(c => c.changes.hasAny('fixed', '_primeMover'));\n /**\n * Mates need to be reprocessed if:\n * * the mate itself was changed\n * * connector1 of the node was changed\n * * parent node of connector1 was changed\n * * any ancestor space node of the parent node was changed\n * * any parent graph dependency node mate or it's parents were changed\n */\n }\n afterUpdates(changes) {\n if (this.rebuildDependencies) {\n this.buildDependencies();\n }\n if (this.sortedMates) {\n if (changes.has(Token.MateNode) ||\n changes.has(Token.SpaceNode) ||\n changes.has(Token.Connector) ||\n changes.has(Token.Feature)) {\n for (const mate of this.sortedMates) {\n //don't process the last mate in a cycle\n if (!this.cycles || !this.cycles.some(c => c.last() === mate)) {\n this.processMate(mate);\n }\n }\n }\n }\n }\n dispose() {\n if (this.sortedMates)\n this.sortedMates.clear();\n if (this.cycles)\n this.cycles.clear();\n }\n processMate(mate) {\n let c1 = mate.getC1();\n let c2 = mate.getC2();\n /**\n * If the sorter determined we need to swap the connectors.\n * */\n if (mate._swap || c2.positionMode === exports.eConnectorPositionMode.moveAlongSketch) {\n const temp = c1;\n c1 = c2;\n c2 = temp;\n }\n const c1Mesh = this.getConnectorMesh(c1);\n const c2Mesh = this.getConnectorMesh(c2);\n const followerNode = c2._parent;\n const followerMesh = this.viewer.rendererManager.mesh.get3d(followerNode);\n if (!c1Mesh || !c2Mesh)\n return;\n /**\n * Move along sketch connectors cannot be moved, because their position is being set by the sketch itself. They can only be used\n * to determine the position of other connectors. Moving them will cause an immediate overconstraint condition\n */\n if (c2.positionMode === exports.eConnectorPositionMode.moveAlongSketch) {\n return;\n }\n if (isSketchControlPoint(c2)) {\n const cp = c2;\n this.viewer.pauseRenderWhile(() => {\n const nodeWithTransform = mateControlPointToConnector(mate, c1Mesh, c2Mesh);\n const d1 = nodeWithTransform.direction.scale(cp.direction.length());\n const d2 = cp.direction2 ? nodeWithTransform.direction.scale(cp.direction2.length()) : undefined;\n if (!nodeWithTransform.position.equalsWithEpsilon(cp.position.toVec3()) ||\n !d1.equalsWithEpsilon(cp.direction.toVec3()) ||\n (cp.direction2 && d2 && !d2.equalsWithEpsilon(cp.direction2.toVec3()))) {\n this.afterCleanup(() => {\n cp.position = exports.KbVector.FromVec3(nodeWithTransform.position);\n cp.direction = exports.KbVector.FromVec3(d1);\n if (cp.direction2 && d2) {\n cp.direction2 = exports.KbVector.FromVec3(d2);\n }\n });\n }\n });\n }\n else if (followerMesh) {\n this.viewer.pauseRenderWhile(() => {\n const originalFollowerMeshAbsPos = followerMesh.getAbsolutePosition();\n const originalFollowerMeshAbsQuat = followerMesh.absoluteRotationQuaternion.clone();\n const originalFollowerMeshLocalPos = followerMesh.position.clone();\n const originalFollowerMeshLocalQuat = followerMesh.rotationQuaternion.clone();\n mateConnectors(mate, followerMesh, c1Mesh, c2Mesh);\n /** update real kb3d nodes with new transform info */\n if (!originalFollowerMeshLocalPos.equalsWithEpsilon(followerMesh.position) ||\n !originalFollowerMeshLocalQuat.equalsWithEpsilon(followerMesh.rotationQuaternion)) {\n followerNode.trackChanges(false);\n followerNode.setRotationQuaternion(exports.KbQuaternion.FromQuat(followerMesh.rotationQuaternion));\n followerNode.position = exports.KbVector.FromVec3(followerMesh.position);\n followerNode.trackChanges(true);\n this.referenceProcessor.triggerChangesOnReferencers(followerNode, new Map([['position', null]]));\n }\n /** invalidate bounding box of parent if follower mesh actually moved */\n if (!originalFollowerMeshAbsPos.equalsWithEpsilon(followerMesh.getAbsolutePosition()) ||\n !originalFollowerMeshAbsQuat.equalsWithEpsilon(followerMesh.absoluteRotationQuaternion)) {\n this.viewer.bbCache.invalidate(c2.getSpaceParent());\n }\n //console.log(`mate '${mate.name} processed`);\n });\n }\n }\n getConnectorMesh(c) {\n if (isSketchControlPoint(c)) {\n return this.controlPointRenderer.get3d(c);\n }\n else if (isConnector(c)) {\n return this.connectorRenderer.get3d(c);\n }\n }\n buildDependencies() {\n const mates = this.getValidMates();\n const sortResult = sortMates(mates);\n this.sortedMates = sortResult.sorted;\n this.cycles = sortResult.cycles;\n const validator = this.viewer.options.validator;\n for (const cycle of sortResult.cycles) {\n const err = `${CYCLE_ERROR_START}${cycle.map(n => n.name).join(' -> ')}`;\n if (validator) {\n for (const cm of cycle) {\n validator.addError(cm, '', err);\n }\n }\n else {\n console.warn(err);\n }\n }\n if (validator) {\n for (const om of sortResult.overConstrained) {\n validator.addError(om, '', `Cannot have more than one fixed node in the mate chain`);\n }\n }\n else {\n if (sortResult.overConstrained.length) {\n console.warn(`Mates overconstrained: [${sortResult.overConstrained.map(n => n.name).join(', ')}]`);\n }\n }\n }\n /**\n * gets all mates (including those in nested scenes)\n * that are enabled, and have valid references to connectors\n */\n getValidMates() {\n const rootScene = this.viewer.sceneNode;\n const mates = new Array();\n const validator = this.viewer.options.validator;\n rootScene.runOnAllScenes(s => {\n const sceneMates = s._manager.getByToken(Token.MateNode);\n for (const m of sceneMates) {\n if (m.isActive()) {\n mates.push(m);\n }\n //regardless, clear out cycle validation\n if (validator) {\n validator.clearProp(m, '');\n }\n }\n });\n return mates;\n }\n }\n\n class CircularPatternRenderer extends PatternRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.CircularPatternFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const featurePivot = feature.pivot.toVec3();\n const featureAxis = feature.axis.toVec3();\n // Don't allow a zero vector for an axis because it will blow up the math\n if (featureAxis.equalsToFloats(0, 0, 0)) {\n featureAxis.set(0, 1, 0);\n }\n const featureArc = (feature.arc * Math.PI) / 180 / feature.count;\n const workingQuaternion = Quaternion.Identity();\n return super.updateMeshGeometry(feature, vertexData, vertexDataChanges, (idx, particle) => {\n particle.pivot = featurePivot;\n Quaternion.RotationAxisToRef(featureAxis, featureArc * idx, workingQuaternion);\n particle.rotationQuaternion.multiplyInPlace(workingQuaternion);\n });\n }\n }\n\n class DeleteFacesRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.DeleteFacesFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n if (newVertexData.indices && feature.vertexGroups.length > 0) {\n const vertexGroups = feature.vertexGroups.sort((groupA, groupB) => groupA.startIndex - groupB.startIndex);\n const newIndices = new Int32Array(newVertexData.indices);\n let currReadIndex = 0;\n vertexGroups.forEach(vertexGroup => {\n for (let i = Math.max(vertexGroup.startIndex, currReadIndex); i < Math.min(vertexGroup.endIndex, newIndices.length); i++) {\n newIndices[i] = -1;\n }\n currReadIndex = vertexGroup.endIndex;\n });\n // We need to remove submeshes targetting the indices that are being removed as well\n if (newVertexData.submeshData) {\n newVertexData.submeshData.forEach(submeshData => {\n const indexStart = submeshData.indexStart;\n for (let i = 0; i < indexStart; i++) {\n if (newIndices[i] === -1) {\n submeshData.indexStart--;\n }\n }\n const indexCount = submeshData.indexCount;\n for (let i = 0; i < indexCount; i++) {\n const index = indexStart + i;\n if (newIndices[index] === -1) {\n submeshData.indexCount--;\n }\n }\n });\n }\n newVertexData.indices = newIndices.filter(index => index !== -1);\n }\n return newVertexData;\n }\n update3dInternal() { }\n }\n\n class DisplacementMapRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.DisplacementMapFeature;\n this.textureCanvas = document.createElement('canvas');\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const textureRenderer = this.viewer.rendererManager.textures;\n if (feature.textures && feature.textures.length > 0) {\n //create context\n const context = this.textureCanvas.getContext('2d', {\n willReadFrequently: true,\n });\n const strength = 1;\n const hasTransparency = false;\n const parameters = { strength, hasTransparency };\n const textureLayers = textureRenderer.getActiveLayers(feature, exports.eTextureChannel.albedo).filter(node => {\n const renderer = textureRenderer.getRenderer(node);\n return renderer.textureHasContent(node);\n });\n if (context) {\n const baseImageSize = textureRenderer\n .getRenderer(feature.textures[0])\n .getNativeSize(feature.textures[0]);\n if (this.scene.getEngine().webGLVersion < 2) {\n const clampedSize = getBinClampedSize(baseImageSize.width, baseImageSize.height);\n context.canvas.width = clampedSize;\n context.canvas.height = clampedSize;\n }\n else {\n if (feature.textures[0]) {\n context.canvas.width = baseImageSize.width;\n context.canvas.height = baseImageSize.height;\n }\n }\n context.clearRect(0, 0, context.canvas.width, context.canvas.height);\n const paintedImage = textureRenderer.paintTextureOnCanvas(textureLayers, context, parameters);\n const tempVertexData = new SubmeshVertexData();\n tempVertexData.copyFrom(newVertexData);\n if (tempVertexData.uvs) {\n const n = tempVertexData.uvs.length;\n for (let i = 1; i < n; i += 2) {\n tempVertexData.uvs[i] = 1 - tempVertexData.uvs[i];\n }\n const mesh = this.viewer.getRendererNode(feature._parent);\n const meshUpdated = new Mesh('ExistingMesh');\n tempVertexData.applyToMesh(meshUpdated, true);\n ensureNormalsExist(meshUpdated);\n const imageData = paintedImage === null || paintedImage === void 0 ? void 0 : paintedImage.getImageData(0, 0, this.textureCanvas.width, this.textureCanvas.height, mesh);\n if (imageData) {\n this.displace(imageData, feature.minDisplacement, feature.maxDisplacement, meshUpdated);\n }\n const meshVertexData = VertexData.ExtractFromMesh(meshUpdated);\n newVertexData.positions = meshVertexData.positions;\n newVertexData.normals = meshVertexData.normals;\n meshUpdated.dispose();\n }\n }\n }\n return newVertexData;\n }\n update3dInternal() { }\n displace(context, minDisplacement, maxDisplacement, parentMesh) {\n const uInt8Array = new Uint8Array(context.data);\n parentMesh.applyDisplacementMapFromBuffer(uInt8Array, context.width, context.height, minDisplacement, maxDisplacement);\n }\n }\n\n const xztoxy = Matrix.FromArray([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\n class ExtrudeRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.ExtrudeFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const parentMesh = feature._parent;\n if (parentMesh &&\n newVertexData.positions &&\n newVertexData.positions.length &&\n // paths are used by parseSketchGeometry\n newVertexData.paths &&\n newVertexData.paths.length > 0 &&\n feature.size !== 0) {\n const { segments, holes } = parseSketchGeometry(newVertexData);\n const extrudedMeshes = [];\n for (let i = 0; i < segments.length; i++) {\n const shape = segments[i];\n const shapeHoles = holes.get(i);\n const sketch = feature._parent && isSketchNode(feature._parent) ? feature._parent : undefined;\n const sketchNormal = sketch ? axisToVector3(sketch.normal) : Vector3.Zero();\n if (sketch && sketch.normal !== exports.eAxis.z) {\n sketchNormal.scaleInPlace(-1);\n }\n const rotToZ = rotationToVector(sketchNormal, new Vector3(0, 0, 1));\n const pathTransformToZ = new Matrix();\n const pathTransformToZInv = new Matrix();\n rotToZ.toRotationMatrix(pathTransformToZ);\n pathTransformToZ.invertToRef(pathTransformToZInv);\n for (let i = 0; i < shape.length; i++) {\n Vector3.TransformCoordinatesToRef(shape[i], pathTransformToZ, shape[i]);\n }\n const shape2d = shape.map(point => new Vector2(point.x, point.y));\n const builder = new PolygonMeshBuilder(feature._dynamicId, shape2d, this.scene, earcut$1);\n if (shapeHoles) {\n shapeHoles.forEach(holePoints => {\n for (let i = 0; i < holePoints.length; i++) {\n Vector3.TransformCoordinatesToRef(holePoints[i], pathTransformToZ, holePoints[i]);\n }\n const hole2d = holePoints.map(point => new Vector2(point.x, point.y));\n builder.addHole(hole2d);\n });\n }\n const extruded = builder.build(true, Math.abs(feature.size), 0.9);\n xztoxy.multiplyToRef(pathTransformToZInv, pathTransformToZInv);\n extruded.bakeTransformIntoVertices(pathTransformToZInv);\n extrudedMeshes.push(extruded);\n }\n const extrudedAll = Mesh.MergeMeshes(extrudedMeshes, true);\n if (extrudedAll) {\n applyExtrusion(newVertexData, extrudedAll, false);\n extrudedAll.dispose();\n }\n }\n return newVertexData;\n }\n getSketchShape(positions) {\n const shape = [];\n for (let i = 0; i < positions.length; i += 3) {\n const newPoint = new Vector3(positions[i], positions[i + 1], positions[i + 2]);\n if (shape.length === 0 || !shape[shape.length - 1].equals(newPoint)) {\n shape.push(newPoint);\n }\n }\n return shape;\n }\n update3dInternal() { }\n }\n function applyExtrusion(newVertexData, extruded, reverse = false) {\n if (extruded.geometry) {\n // Store the indices used for the extrude so that they can be merged into the new geometry\n const newIndices = extruded.geometry.getIndices(false, true);\n const newNormals = extruded.geometry.getVerticesData(VertexBuffer.NormalKind, false, true);\n const newUvs = extruded.geometry.getVerticesData(VertexBuffer.UVKind, false, true);\n const newPositions = extruded.geometry.getVerticesData(VertexBuffer.PositionKind, false, true);\n if (newPositions && reverse) {\n for (let i = 2; i < newPositions.length; i += 3) {\n newPositions[i] = -newPositions[i];\n }\n }\n normalizeGeometry(newVertexData);\n if (!newVertexData.indices) {\n newVertexData.indices = newIndices;\n }\n else if (newIndices) {\n const concatArr = new Int32Array(newVertexData.indices.length + newIndices.length);\n concatArr.set(newVertexData.indices);\n if (newVertexData.positions) {\n const pushAmount = newVertexData.positions.length / 3;\n for (let i = 0; i < newIndices.length; i++) {\n newIndices[i] += pushAmount;\n }\n }\n concatArr.set(newIndices, newVertexData.indices.length);\n newVertexData.indices = concatArr;\n }\n if (!newVertexData.positions) {\n newVertexData.positions = newPositions;\n }\n else if (newPositions) {\n const concatArr = new Float32Array(newVertexData.positions.length + newPositions.length);\n concatArr.set(newVertexData.positions);\n concatArr.set(newPositions, newVertexData.positions.length);\n newVertexData.positions = concatArr;\n }\n if (!newVertexData.normals) {\n newVertexData.normals = newNormals;\n }\n else if (newNormals) {\n const concatArr = new Float32Array(newVertexData.normals.length + newNormals.length);\n concatArr.set(newVertexData.normals);\n concatArr.set(newNormals, newVertexData.normals.length);\n newVertexData.normals = concatArr;\n }\n if (!newVertexData.uvs) {\n newVertexData.uvs = newUvs;\n }\n else if (newUvs) {\n const concatArr = new Float32Array(newVertexData.uvs.length + newUvs.length);\n concatArr.set(newVertexData.uvs);\n concatArr.set(newUvs, newVertexData.uvs.length);\n newVertexData.uvs = concatArr;\n }\n const baseMaterialIndex = newVertexData.submeshData ? newVertexData.submeshData[0].materialIndex : 0;\n const totalIndicesResultCount = newVertexData.indices.length;\n const totalVerticesResultCount = newVertexData.positions.length / 3;\n newVertexData.submeshData = [];\n newVertexData.submeshData.push({\n materialIndex: baseMaterialIndex,\n verticesStart: 0,\n verticesCount: totalVerticesResultCount,\n indexStart: 0,\n indexCount: totalIndicesResultCount,\n });\n }\n }\n function normalizeGeometry(newVertexData) {\n if (!newVertexData.indices) {\n // If there are no indices, throw away existing vertices because they won't be used\n newVertexData.positions = null;\n newVertexData.normals = null;\n newVertexData.uvs = null;\n }\n else {\n const indices = newVertexData.indices;\n let maxIdx = 0;\n for (let i = 0; i < indices.length; i++) {\n if (maxIdx < indices[i]) {\n maxIdx = indices[i];\n }\n }\n const usedVertexLength = maxIdx + 1;\n const positions = new Float32Array(usedVertexLength * 3);\n const normals = new Float32Array(usedVertexLength * 3);\n const uvs = new Float32Array(usedVertexLength * 2);\n if (newVertexData.positions) {\n if (Array.isArray(newVertexData.positions)) {\n positions.set(newVertexData.positions.slice(0, positions.length));\n }\n else {\n positions.set(newVertexData.positions.subarray(0, positions.length));\n }\n }\n if (newVertexData.normals) {\n if (Array.isArray(newVertexData.normals)) {\n normals.set(newVertexData.normals.slice(0, normals.length));\n }\n else {\n normals.set(newVertexData.normals.subarray(0, normals.length));\n }\n }\n if (newVertexData.uvs) {\n if (Array.isArray(newVertexData.uvs)) {\n uvs.set(newVertexData.uvs.slice(0, uvs.length));\n }\n else {\n uvs.set(newVertexData.uvs.subarray(0, uvs.length));\n }\n }\n newVertexData.positions = positions;\n newVertexData.normals = normals;\n newVertexData.uvs = uvs;\n }\n }\n\n /**\n * Unique ID when we import meshes from Babylon to CSG\n */\n let currentCSGMeshId = 0;\n /**\n * Represents a vertex of a polygon. Use your own vertex class instead of this\n * one to provide additional features like texture coordinates and vertex\n * colors. Custom vertex classes need to provide a `pos` property and `clone()`,\n * `flip()`, and `interpolate()` methods that behave analogous to the ones\n * defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience\n * functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`\n * is not used anywhere else.\n * Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes\n */\n class Vertex {\n /**\n * Initializes the vertex\n * @param pos The position of the vertex\n * @param normal The normal of the vertex\n * @param uv The texture coordinate of the vertex\n * @param vertColor The RGBA color of the vertex\n */\n constructor(\n /**\n * The position of the vertex\n */\n pos, \n /**\n * The normal of the vertex\n */\n normal, \n /**\n * The texture coordinate of the vertex\n */\n uv, \n /**\n * The texture coordinate of the vertex\n */\n vertColor) {\n this.pos = pos;\n this.normal = normal;\n this.uv = uv;\n this.vertColor = vertColor;\n }\n /**\n * Make a clone, or deep copy, of the vertex\n * @returns A new Vertex\n */\n clone() {\n var _a, _b;\n return new Vertex(this.pos.clone(), this.normal.clone(), (_a = this.uv) === null || _a === void 0 ? void 0 : _a.clone(), (_b = this.vertColor) === null || _b === void 0 ? void 0 : _b.clone());\n }\n /**\n * Invert all orientation-specific data (e.g. vertex normal). Called when the\n * orientation of a polygon is flipped.\n */\n flip() {\n this.normal = this.normal.scale(-1);\n }\n /**\n * Create a new vertex between this vertex and `other` by linearly\n * interpolating all properties using a parameter of `t`. Subclasses should\n * override this to interpolate additional properties.\n * @param other the vertex to interpolate against\n * @param t The factor used to linearly interpolate between the vertices\n */\n interpolate(other, t) {\n return new Vertex(Vector3.Lerp(this.pos, other.pos, t), Vector3.Lerp(this.normal, other.normal, t), this.uv && other.uv ? Vector2.Lerp(this.uv, other.uv, t) : undefined, this.vertColor && other.vertColor ? Color4.Lerp(this.vertColor, other.vertColor, t) : undefined);\n }\n }\n /**\n * Represents a plane in 3D space.\n */\n class Plane$1 {\n /**\n * Initializes the plane\n * @param normal The normal for the plane\n * @param w\n */\n constructor(normal, w) {\n this.normal = normal;\n this.w = w;\n }\n /**\n * Construct a plane from three points\n * @param a Point a\n * @param b Point b\n * @param c Point c\n */\n static FromPoints(a, b, c) {\n const v0 = c.subtract(a);\n const v1 = b.subtract(a);\n if (v0.lengthSquared() === 0 || v1.lengthSquared() === 0) {\n return null;\n }\n const n = Vector3.Normalize(Vector3.Cross(v0, v1));\n return new Plane$1(n, Vector3.Dot(n, a));\n }\n /**\n * Clone, or make a deep copy of the plane\n * @returns a new Plane\n */\n clone() {\n return new Plane$1(this.normal.clone(), this.w);\n }\n /**\n * Flip the face of the plane\n */\n flip() {\n this.normal.scaleInPlace(-1);\n this.w = -this.w;\n }\n /**\n * Split `polygon` by this plane if needed, then put the polygon or polygon\n * fragments in the appropriate lists. Coplanar polygons go into either\n `* coplanarFront` or `coplanarBack` depending on their orientation with\n * respect to this plane. Polygons in front or in back of this plane go into\n * either `front` or `back`\n * @param polygon The polygon to be split\n * @param coplanarFront Will contain polygons coplanar with the plane that are oriented to the front of the plane\n * @param coplanarBack Will contain polygons coplanar with the plane that are oriented to the back of the plane\n * @param front Will contain the polygons in front of the plane\n * @param back Will contain the polygons begind the plane\n */\n splitPolygon(polygon, coplanarFront, coplanarBack, front, back) {\n const COPLANAR = 0;\n const FRONT = 1;\n const BACK = 2;\n const SPANNING = 3;\n // Classify each point as well as the entire polygon into one of the above\n // four classes.\n let polygonType = 0;\n const types = [];\n let i;\n let t;\n for (i = 0; i < polygon.vertices.length; i++) {\n t = Vector3.Dot(this.normal, polygon.vertices[i].pos) - this.w;\n const type = t < -Plane$1.EPSILON ? BACK : t > Plane$1.EPSILON ? FRONT : COPLANAR;\n polygonType |= type;\n types.push(type);\n }\n // Put the polygon in the correct list, splitting it when necessary\n switch (polygonType) {\n case COPLANAR:\n (Vector3.Dot(this.normal, polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);\n break;\n case FRONT:\n front.push(polygon);\n break;\n case BACK:\n back.push(polygon);\n break;\n case SPANNING: {\n const f = [], b = [];\n for (i = 0; i < polygon.vertices.length; i++) {\n const j = (i + 1) % polygon.vertices.length;\n const ti = types[i], tj = types[j];\n const vi = polygon.vertices[i], vj = polygon.vertices[j];\n if (ti !== BACK) {\n f.push(vi);\n }\n if (ti !== FRONT) {\n b.push(ti !== BACK ? vi.clone() : vi);\n }\n if ((ti | tj) === SPANNING) {\n t = (this.w - Vector3.Dot(this.normal, vi.pos)) / Vector3.Dot(this.normal, vj.pos.subtract(vi.pos));\n const v = vi.interpolate(vj, t);\n f.push(v);\n b.push(v.clone());\n }\n }\n let poly;\n if (f.length >= 3) {\n poly = new Polygon(f, polygon.shared);\n if (poly.plane) {\n front.push(poly);\n }\n }\n if (b.length >= 3) {\n poly = new Polygon(b, polygon.shared);\n if (poly.plane) {\n back.push(poly);\n }\n }\n break;\n }\n }\n }\n }\n /**\n * `CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a\n * point is on the plane\n */\n Plane$1.EPSILON = 1e-5;\n /**\n * Represents a convex polygon. The vertices used to initialize a polygon must\n * be coplanar and form a convex loop.\n *\n * Each convex polygon has a `shared` property, which is shared between all\n * polygons that are clones of each other or were split from the same polygon.\n * This can be used to define per-polygon properties (such as surface color)\n */\n class Polygon {\n /**\n * Initializes the polygon\n * @param vertices The vertices of the polygon\n * @param shared The properties shared across all polygons\n */\n constructor(vertices, shared) {\n this.vertices = vertices;\n this.shared = shared;\n this.plane = Plane$1.FromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);\n }\n /**\n * Clones, or makes a deep copy, or the polygon\n */\n clone() {\n const vertices = this.vertices.map((v) => v.clone());\n return new Polygon(vertices, this.shared);\n }\n /**\n * Flips the faces of the polygon\n */\n flip() {\n this.vertices.reverse().map((v) => {\n v.flip();\n });\n this.plane.flip();\n }\n }\n /**\n * Holds a node in a BSP tree. A BSP tree is built from a collection of polygons\n * by picking a polygon to split along. That polygon (and all other coplanar\n * polygons) are added directly to that node and the other polygons are added to\n * the front and/or back subtrees. This is not a leafy BSP tree since there is\n * no distinction between internal and leaf nodes\n */\n class Node$2 {\n /**\n * Initializes the node\n * @param polygons A collection of polygons held in the node\n */\n constructor(polygons) {\n this._plane = null;\n this._front = null;\n this._back = null;\n this._polygons = new Array();\n if (polygons) {\n this.build(polygons);\n }\n }\n /**\n * Clones, or makes a deep copy, of the node\n * @returns The cloned node\n */\n clone() {\n const node = new Node$2();\n node._plane = this._plane && this._plane.clone();\n node._front = this._front && this._front.clone();\n node._back = this._back && this._back.clone();\n node._polygons = this._polygons.map((p) => p.clone());\n return node;\n }\n /**\n * Convert solid space to empty space and empty space to solid space\n */\n invert() {\n for (let i = 0; i < this._polygons.length; i++) {\n this._polygons[i].flip();\n }\n if (this._plane) {\n this._plane.flip();\n }\n if (this._front) {\n this._front.invert();\n }\n if (this._back) {\n this._back.invert();\n }\n const temp = this._front;\n this._front = this._back;\n this._back = temp;\n }\n /**\n * Recursively remove all polygons in `polygons` that are inside this BSP\n * tree.\n * @param polygons Polygons to remove from the BSP\n * @returns Polygons clipped from the BSP\n */\n clipPolygons(polygons) {\n if (!this._plane) {\n return polygons.slice();\n }\n let front = new Array(), back = new Array();\n for (let i = 0; i < polygons.length; i++) {\n this._plane.splitPolygon(polygons[i], front, back, front, back);\n }\n if (this._front) {\n front = this._front.clipPolygons(front);\n }\n if (this._back) {\n back = this._back.clipPolygons(back);\n }\n else {\n back = [];\n }\n return front.concat(back);\n }\n /**\n * Remove all polygons in this BSP tree that are inside the other BSP tree\n * `bsp`.\n * @param bsp BSP containing polygons to remove from this BSP\n */\n clipTo(bsp) {\n this._polygons = bsp.clipPolygons(this._polygons);\n if (this._front) {\n this._front.clipTo(bsp);\n }\n if (this._back) {\n this._back.clipTo(bsp);\n }\n }\n /**\n * Return a list of all polygons in this BSP tree\n * @returns List of all polygons in this BSP tree\n */\n allPolygons() {\n let polygons = this._polygons.slice();\n if (this._front) {\n polygons = polygons.concat(this._front.allPolygons());\n }\n if (this._back) {\n polygons = polygons.concat(this._back.allPolygons());\n }\n return polygons;\n }\n /**\n * Build a BSP tree out of `polygons`. When called on an existing tree, the\n * new polygons are filtered down to the bottom of the tree and become new\n * nodes there. Each set of polygons is partitioned using the first polygon\n * (no heuristic is used to pick a good split)\n * @param polygons Polygons used to construct the BSP tree\n */\n build(polygons) {\n if (!polygons.length) {\n return;\n }\n if (!this._plane) {\n this._plane = polygons[0].plane.clone();\n }\n const front = new Array(), back = new Array();\n for (let i = 0; i < polygons.length; i++) {\n this._plane.splitPolygon(polygons[i], this._polygons, this._polygons, front, back);\n }\n if (front.length) {\n if (!this._front) {\n this._front = new Node$2();\n }\n this._front.build(front);\n }\n if (back.length) {\n if (!this._back) {\n this._back = new Node$2();\n }\n this._back.build(back);\n }\n }\n }\n /**\n * Class for building Constructive Solid Geometry\n */\n class CSG {\n constructor() {\n this._polygons = new Array();\n }\n /**\n * Convert the Mesh to CSG\n * @param mesh The Mesh to convert to CSG\n * @param absolute If true, the final (local) matrix transformation is set to the identity and not to that of `mesh`. It can help when dealing with right-handed meshes (default: false)\n * @returns A new CSG from the Mesh\n */\n static FromMesh(mesh, absolute = false) {\n let vertex, normal, uv = undefined, position, vertColor = undefined, polygon, vertices;\n const polygons = new Array();\n let matrix, meshPosition, meshRotation, meshRotationQuaternion = null, meshScaling;\n let invertWinding = false;\n if (mesh instanceof Mesh) {\n mesh.computeWorldMatrix(true);\n matrix = mesh.getWorldMatrix();\n meshPosition = mesh.position.clone();\n meshRotation = mesh.rotation.clone();\n if (mesh.rotationQuaternion) {\n meshRotationQuaternion = mesh.rotationQuaternion.clone();\n }\n meshScaling = mesh.scaling.clone();\n if (mesh.material && absolute) {\n invertWinding = mesh.material.sideOrientation === 0;\n }\n }\n else {\n throw \"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh\";\n }\n const indices = mesh.getIndices(), positions = mesh.getVerticesData(VertexBuffer.PositionKind), normals = mesh.getVerticesData(VertexBuffer.NormalKind), uvs = mesh.getVerticesData(VertexBuffer.UVKind), vertColors = mesh.getVerticesData(VertexBuffer.ColorKind);\n const subMeshes = mesh.subMeshes;\n for (let sm = 0, sml = subMeshes.length; sm < sml; sm++) {\n for (let i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {\n vertices = [];\n for (let j = 0; j < 3; j++) {\n const indexIndices = j === 0 ? i + j : invertWinding ? i + 3 - j : i + j;\n const sourceNormal = new Vector3(normals[indices[indexIndices] * 3], normals[indices[indexIndices] * 3 + 1], normals[indices[indexIndices] * 3 + 2]);\n if (uvs) {\n uv = new Vector2(uvs[indices[indexIndices] * 2], uvs[indices[indexIndices] * 2 + 1]);\n }\n if (vertColors) {\n vertColor = new Color4(vertColors[indices[indexIndices] * 4], vertColors[indices[indexIndices] * 4 + 1], vertColors[indices[indexIndices] * 4 + 2], vertColors[indices[indexIndices] * 4 + 3]);\n }\n const sourcePosition = new Vector3(positions[indices[indexIndices] * 3], positions[indices[indexIndices] * 3 + 1], positions[indices[indexIndices] * 3 + 2]);\n position = Vector3.TransformCoordinates(sourcePosition, matrix);\n normal = Vector3.TransformNormal(sourceNormal, matrix);\n vertex = new Vertex(position, normal, uv, vertColor);\n vertices.push(vertex);\n }\n polygon = new Polygon(vertices, { subMeshId: sm, meshId: currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });\n // To handle the case of degenerated triangle\n // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated\n if (polygon.plane) {\n polygons.push(polygon);\n }\n }\n }\n const csg = CSG._FromPolygons(polygons);\n csg.matrix = absolute ? Matrix.Identity() : matrix;\n csg.position = absolute ? Vector3.Zero() : meshPosition;\n csg.rotation = absolute ? Vector3.Zero() : meshRotation;\n csg.scaling = absolute ? Vector3.One() : meshScaling;\n csg.rotationQuaternion = absolute && meshRotationQuaternion ? Quaternion.Identity() : meshRotationQuaternion;\n currentCSGMeshId++;\n return csg;\n }\n /**\n * Construct a CSG solid from a list of `CSG.Polygon` instances.\n * @param polygons Polygons used to construct a CSG solid\n */\n static _FromPolygons(polygons) {\n const csg = new CSG();\n csg._polygons = polygons;\n return csg;\n }\n /**\n * Clones, or makes a deep copy, of the CSG\n * @returns A new CSG\n */\n clone() {\n const csg = new CSG();\n csg._polygons = this._polygons.map((p) => p.clone());\n csg.copyTransformAttributes(this);\n return csg;\n }\n /**\n * Unions this CSG with another CSG\n * @param csg The CSG to union against this CSG\n * @returns The unioned CSG\n */\n union(csg) {\n const a = new Node$2(this.clone()._polygons);\n const b = new Node$2(csg.clone()._polygons);\n a.clipTo(b);\n b.clipTo(a);\n b.invert();\n b.clipTo(a);\n b.invert();\n a.build(b.allPolygons());\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\n }\n /**\n * Unions this CSG with another CSG in place\n * @param csg The CSG to union against this CSG\n */\n unionInPlace(csg) {\n const a = new Node$2(this._polygons);\n const b = new Node$2(csg._polygons);\n a.clipTo(b);\n b.clipTo(a);\n b.invert();\n b.clipTo(a);\n b.invert();\n a.build(b.allPolygons());\n this._polygons = a.allPolygons();\n }\n /**\n * Subtracts this CSG with another CSG\n * @param csg The CSG to subtract against this CSG\n * @returns A new CSG\n */\n subtract(csg) {\n const a = new Node$2(this.clone()._polygons);\n const b = new Node$2(csg.clone()._polygons);\n a.invert();\n a.clipTo(b);\n b.clipTo(a);\n b.invert();\n b.clipTo(a);\n b.invert();\n a.build(b.allPolygons());\n a.invert();\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\n }\n /**\n * Subtracts this CSG with another CSG in place\n * @param csg The CSG to subtract against this CSG\n */\n subtractInPlace(csg) {\n const a = new Node$2(this._polygons);\n const b = new Node$2(csg._polygons);\n a.invert();\n a.clipTo(b);\n b.clipTo(a);\n b.invert();\n b.clipTo(a);\n b.invert();\n a.build(b.allPolygons());\n a.invert();\n this._polygons = a.allPolygons();\n }\n /**\n * Intersect this CSG with another CSG\n * @param csg The CSG to intersect against this CSG\n * @returns A new CSG\n */\n intersect(csg) {\n const a = new Node$2(this.clone()._polygons);\n const b = new Node$2(csg.clone()._polygons);\n a.invert();\n b.clipTo(a);\n b.invert();\n a.clipTo(b);\n b.clipTo(a);\n a.build(b.allPolygons());\n a.invert();\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\n }\n /**\n * Intersects this CSG with another CSG in place\n * @param csg The CSG to intersect against this CSG\n */\n intersectInPlace(csg) {\n const a = new Node$2(this._polygons);\n const b = new Node$2(csg._polygons);\n a.invert();\n b.clipTo(a);\n b.invert();\n a.clipTo(b);\n b.clipTo(a);\n a.build(b.allPolygons());\n a.invert();\n this._polygons = a.allPolygons();\n }\n /**\n * Return a new CSG solid with solid and empty space switched. This solid is\n * not modified.\n * @returns A new CSG solid with solid and empty space switched\n */\n inverse() {\n const csg = this.clone();\n csg.inverseInPlace();\n return csg;\n }\n /**\n * Inverses the CSG in place\n */\n inverseInPlace() {\n this._polygons.map((p) => {\n p.flip();\n });\n }\n /**\n * This is used to keep meshes transformations so they can be restored\n * when we build back a Babylon Mesh\n * NB : All CSG operations are performed in world coordinates\n * @param csg The CSG to copy the transform attributes from\n * @returns This CSG\n */\n copyTransformAttributes(csg) {\n this.matrix = csg.matrix;\n this.position = csg.position;\n this.rotation = csg.rotation;\n this.scaling = csg.scaling;\n this.rotationQuaternion = csg.rotationQuaternion;\n return this;\n }\n /**\n * Build Raw mesh from CSG\n * Coordinates here are in world space\n * @param name The name of the mesh geometry\n * @param scene The Scene\n * @param keepSubMeshes Specifies if the submeshes should be kept\n * @returns A new Mesh\n */\n buildMeshGeometry(name, scene, keepSubMeshes) {\n const matrix = this.matrix.clone();\n matrix.invert();\n const mesh = new Mesh(name, scene);\n const vertices = [];\n const indices = [];\n const normals = [];\n let uvs = null;\n let vertColors = null;\n const vertex = Vector3.Zero();\n const normal = Vector3.Zero();\n const uv = Vector2.Zero();\n const vertColor = new Color4(0, 0, 0, 0);\n const polygons = this._polygons;\n const polygonIndices = [0, 0, 0];\n let polygon;\n const vertice_dict = {};\n let vertex_idx;\n let currentIndex = 0;\n const subMeshDict = {};\n let subMeshObj;\n if (keepSubMeshes) {\n // Sort Polygons, since subMeshes are indices range\n polygons.sort((a, b) => {\n if (a.shared.meshId === b.shared.meshId) {\n return a.shared.subMeshId - b.shared.subMeshId;\n }\n else {\n return a.shared.meshId - b.shared.meshId;\n }\n });\n }\n for (let i = 0, il = polygons.length; i < il; i++) {\n polygon = polygons[i];\n // Building SubMeshes\n if (!subMeshDict[polygon.shared.meshId]) {\n subMeshDict[polygon.shared.meshId] = {};\n }\n if (!subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId]) {\n subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId] = {\n indexStart: +Infinity,\n indexEnd: -Infinity,\n materialIndex: polygon.shared.materialIndex,\n };\n }\n subMeshObj = subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId];\n for (let j = 2, jl = polygon.vertices.length; j < jl; j++) {\n polygonIndices[0] = 0;\n polygonIndices[1] = j - 1;\n polygonIndices[2] = j;\n for (let k = 0; k < 3; k++) {\n vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);\n normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);\n if (polygon.vertices[polygonIndices[k]].uv) {\n if (!uvs) {\n uvs = [];\n }\n uv.copyFrom(polygon.vertices[polygonIndices[k]].uv);\n }\n if (polygon.vertices[polygonIndices[k]].vertColor) {\n if (!vertColors) {\n vertColors = [];\n }\n vertColor.copyFrom(polygon.vertices[polygonIndices[k]].vertColor);\n }\n const localVertex = Vector3.TransformCoordinates(vertex, matrix);\n const localNormal = Vector3.TransformNormal(normal, matrix);\n vertex_idx = vertice_dict[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z];\n let areUvsDifferent = false;\n if (uvs && !(uvs[vertex_idx * 2] === uv.x || uvs[vertex_idx * 2 + 1] === uv.y)) {\n areUvsDifferent = true;\n }\n let areColorsDifferent = false;\n if (vertColors &&\n !(vertColors[vertex_idx * 4] === vertColor.r ||\n vertColors[vertex_idx * 4 + 1] === vertColor.g ||\n vertColors[vertex_idx * 4 + 2] === vertColor.b ||\n vertColors[vertex_idx * 4 + 3] === vertColor.a)) {\n areColorsDifferent = true;\n }\n // Check if 2 points can be merged\n if (!(typeof vertex_idx !== \"undefined\" &&\n normals[vertex_idx * 3] === localNormal.x &&\n normals[vertex_idx * 3 + 1] === localNormal.y &&\n normals[vertex_idx * 3 + 2] === localNormal.z) ||\n areUvsDifferent ||\n areColorsDifferent) {\n vertices.push(localVertex.x, localVertex.y, localVertex.z);\n if (uvs) {\n uvs.push(uv.x, uv.y);\n }\n normals.push(normal.x, normal.y, normal.z);\n if (vertColors) {\n vertColors.push(vertColor.r, vertColor.g, vertColor.b, vertColor.a);\n }\n vertex_idx = vertice_dict[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z] = vertices.length / 3 - 1;\n }\n indices.push(vertex_idx);\n subMeshObj.indexStart = Math.min(currentIndex, subMeshObj.indexStart);\n subMeshObj.indexEnd = Math.max(currentIndex, subMeshObj.indexEnd);\n currentIndex++;\n }\n }\n }\n mesh.setVerticesData(VertexBuffer.PositionKind, vertices);\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\n if (uvs) {\n mesh.setVerticesData(VertexBuffer.UVKind, uvs);\n }\n if (vertColors) {\n mesh.setVerticesData(VertexBuffer.ColorKind, vertColors);\n }\n mesh.setIndices(indices, null);\n if (keepSubMeshes) {\n // We offset the materialIndex by the previous number of materials in the CSG mixed meshes\n let materialIndexOffset = 0, materialMaxIndex;\n mesh.subMeshes = new Array();\n for (const m in subMeshDict) {\n materialMaxIndex = -1;\n for (const sm in subMeshDict[m]) {\n subMeshObj = subMeshDict[m][sm];\n SubMesh.CreateFromIndices(subMeshObj.materialIndex + materialIndexOffset, subMeshObj.indexStart, subMeshObj.indexEnd - subMeshObj.indexStart + 1, mesh);\n materialMaxIndex = Math.max(subMeshObj.materialIndex, materialMaxIndex);\n }\n materialIndexOffset += ++materialMaxIndex;\n }\n }\n return mesh;\n }\n /**\n * Build Mesh from CSG taking material and transforms into account\n * @param name The name of the Mesh\n * @param material The material of the Mesh\n * @param scene The Scene\n * @param keepSubMeshes Specifies if submeshes should be kept\n * @returns The new Mesh\n */\n toMesh(name, material = null, scene, keepSubMeshes) {\n const mesh = this.buildMeshGeometry(name, scene, keepSubMeshes);\n mesh.material = material;\n mesh.position.copyFrom(this.position);\n mesh.rotation.copyFrom(this.rotation);\n if (this.rotationQuaternion) {\n mesh.rotationQuaternion = this.rotationQuaternion.clone();\n }\n mesh.scaling.copyFrom(this.scaling);\n mesh.computeWorldMatrix(true);\n return mesh;\n }\n }\n\n function createJoinGeometryVisualization(targetMesh, scene, color) {\n const visualization = targetMesh;\n if (!color) {\n color = Color3.Yellow();\n }\n const coloredMaterial = new StandardMaterial('', scene);\n //coloredMaterial.alpha = 0.5;\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n visualization.material = coloredMaterial;\n return visualization;\n }\n\n const joinedMeshes = new Map();\n class JoinGeometryRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.JoinGeometryFeature;\n this.bbSubscriptions = new Map();\n this.targetMeshVisualizationMap = new Map();\n this.parentMeshVisualizationMap = new Map();\n this.previewLayer = this.viewer.utilityLayer;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const targetMesh = joinedMeshes.get(feature._dynamicId);\n const thisMesh = this.viewer.getRendererNode(feature._parent);\n if (targetMesh instanceof Mesh &&\n thisMesh instanceof Mesh &&\n targetMesh.geometry &&\n targetMesh.geometry.getTotalIndices() > 0 &&\n targetMesh != thisMesh) {\n const workingVertexData = vertexData.shallowClone();\n const tempMesh = new Mesh('csg-temp');\n tempMesh.doNotSerialize = true;\n SubmeshVertexData.CopyToRef(newVertexData, workingVertexData);\n if (!workingVertexData.positions || !workingVertexData.indices) {\n throw 'Invalid geometry';\n }\n const targetTransform = thisMesh.computeWorldMatrix(true);\n workingVertexData.applyToMesh(tempMesh);\n let previewMesh = this.parentMeshVisualizationMap.get(feature.id);\n if (!previewMesh) {\n const newMeshInstance = new Mesh('preview-mesh');\n newMeshInstance.doNotSerialize = true;\n workingVertexData.applyToMesh(newMeshInstance);\n this.parentMeshVisualizationMap.set(feature.id, newMeshInstance);\n if (newMeshInstance instanceof Mesh) {\n previewMesh = createJoinGeometryVisualization(newMeshInstance, this.previewLayer.utilityLayerScene, Color3.Yellow());\n this.parentMeshVisualizationMap.set(feature.id, previewMesh);\n previewMesh.setEnabled(false);\n if (feature._parent) {\n const featureParentMesh = this.viewer.getRendererNode(feature._parent);\n newMeshInstance.position.addInPlace(featureParentMesh.absolutePosition);\n }\n }\n }\n ensureNormalsExist(tempMesh);\n const resultCsg = CSG.FromMesh(tempMesh);\n const targetMeshMatchTransform = targetMesh.clone();\n const targetMeshTransform = targetMeshMatchTransform.computeWorldMatrix(true);\n targetMeshMatchTransform.parent = null;\n targetTransform.invert();\n targetMeshTransform.multiplyToRef(targetTransform, targetMeshTransform);\n targetMeshMatchTransform.rotationQuaternion = new Quaternion();\n targetMeshTransform.decompose(targetMeshMatchTransform.scaling, targetMeshMatchTransform.rotationQuaternion, targetMeshMatchTransform.position);\n try {\n const opCsg = CSG.FromMesh(targetMeshMatchTransform);\n if (feature.joinType === exports.eJoinType.cut) {\n resultCsg.subtractInPlace(opCsg);\n }\n else if (feature.joinType === exports.eJoinType.intersect) {\n resultCsg.intersectInPlace(opCsg);\n }\n else if (feature.joinType === exports.eJoinType.union) {\n resultCsg.unionInPlace(opCsg);\n }\n }\n catch (e) {\n console.warn('Could not merge geometry for join ' + feature.name, e);\n return newVertexData;\n }\n if (resultCsg) {\n const resultMeshCsg = resultCsg.toMesh('temp2', null, undefined, true);\n const resultVertexData = SubmeshVertexData.ExtractFromMesh(resultMeshCsg);\n newVertexData.positions = resultVertexData.positions;\n if (newVertexData.normals) {\n newVertexData.normals = resultVertexData.normals;\n }\n if (newVertexData.uvs) {\n newVertexData.uvs = resultVertexData.uvs;\n }\n newVertexData.indices = resultVertexData.indices;\n // Sometimes the CSG will add another material to the multiMaterial to represent the cut face. Change that material to be the base material, otherwise it will be black.\n const existingMaterials = new Set();\n // get a list of all the materials that are already in the multiMaterial\n if (newVertexData.submeshData) {\n newVertexData.submeshData.forEach(submeshData => {\n existingMaterials.add(submeshData.materialIndex);\n });\n }\n if (resultVertexData.submeshData) {\n resultVertexData.submeshData.forEach(submeshData => {\n if (!existingMaterials.has(submeshData.materialIndex)) {\n submeshData.materialIndex = 0;\n }\n });\n }\n newVertexData.submeshData = resultVertexData.submeshData;\n resultMeshCsg.dispose();\n }\n tempMesh.dispose();\n targetMeshMatchTransform.dispose();\n }\n return newVertexData;\n }\n updatePreviewMesh(node) {\n let featureInstance = this.targetMeshVisualizationMap.get(node.id);\n const scene = this.previewLayer.utilityLayerScene;\n const targetMesh = joinedMeshes.get(node._dynamicId);\n if (targetMesh && !featureInstance) {\n featureInstance = createJoinGeometryVisualization(targetMesh.clone(), scene, Color3.Yellow());\n featureInstance.isPickable = false;\n featureInstance.setEnabled(false);\n this.targetMeshVisualizationMap.set(node.id, featureInstance);\n return featureInstance;\n }\n else if (targetMesh) {\n this.deleteTargetMeshVisualization(node);\n featureInstance = createJoinGeometryVisualization(targetMesh.clone(), scene, Color3.Yellow());\n featureInstance.isPickable = false;\n featureInstance.setEnabled(false);\n this.targetMeshVisualizationMap.set(node.id, featureInstance);\n return featureInstance;\n }\n }\n update3dInternal(feature) {\n var _a;\n if (feature.changes.hasAny('meshId', 'enabled')) {\n const existingSubscription = this.bbSubscriptions.get(feature._dynamicId);\n if (existingSubscription) {\n existingSubscription.unsubscribe();\n }\n if (feature.enabled) {\n const targetMeshNode = (_a = feature._manager) === null || _a === void 0 ? void 0 : _a.getById(feature.meshId);\n if (targetMeshNode && targetMeshNode instanceof exports.MeshNode) {\n // if this is a custom mesh node and the geometry isn't loaded, we have to load it\n if (targetMeshNode instanceof exports.CustomMeshNode &&\n targetMeshNode.hasGeometry &&\n !targetMeshNode.geometryLoaded) {\n this.viewer.rendererManager.mesh.loadNewGeometry(targetMeshNode);\n }\n const targetMesh = this.viewer.getRendererNode(targetMeshNode);\n if (targetMesh instanceof Mesh && feature._parent) {\n joinedMeshes.set(feature._dynamicId, targetMesh);\n this.bbSubscriptions.set(feature._dynamicId, \n // TODO This should also watch the parent group for positional changes, otherwise the join won't update when the feature's parent mesh moves.\n // But watch out for infinite loops\n this.viewer.bbCache.watchForChanges(targetMeshNode).subscribe(() => {\n feature.setPropertyIsModified('meshId', true);\n }));\n }\n else {\n console.warn('Could not create CSG for join geometry');\n }\n }\n }\n }\n let featureInstance = this.targetMeshVisualizationMap.get(feature.id);\n const originalMesh = this.parentMeshVisualizationMap.get(feature.id);\n if (feature._previewVisible) {\n featureInstance = this.updatePreviewMesh(feature);\n }\n if (feature._previewVisible && feature.enabled) {\n if (feature.joinType === exports.eJoinType.cut) {\n originalMesh === null || originalMesh === void 0 ? void 0 : originalMesh.setEnabled(false);\n featureInstance === null || featureInstance === void 0 ? void 0 : featureInstance.setEnabled(true);\n }\n else if (feature.joinType === exports.eJoinType.intersect) {\n originalMesh === null || originalMesh === void 0 ? void 0 : originalMesh.setEnabled(true);\n featureInstance === null || featureInstance === void 0 ? void 0 : featureInstance.setEnabled(true);\n }\n else {\n originalMesh === null || originalMesh === void 0 ? void 0 : originalMesh.setEnabled(false);\n featureInstance === null || featureInstance === void 0 ? void 0 : featureInstance.setEnabled(false);\n }\n }\n else {\n originalMesh === null || originalMesh === void 0 ? void 0 : originalMesh.setEnabled(false);\n featureInstance === null || featureInstance === void 0 ? void 0 : featureInstance.setEnabled(false);\n }\n }\n delete3d(feature, preserveCache) {\n var _a;\n if (!preserveCache) {\n joinedMeshes.delete(feature._dynamicId);\n }\n (_a = this.bbSubscriptions.get(feature._dynamicId)) === null || _a === void 0 ? void 0 : _a.unsubscribe();\n this.bbSubscriptions.delete(feature._dynamicId);\n this.deleteTargetMeshVisualization(feature);\n const targetMeshCopy = this.parentMeshVisualizationMap.get(feature.id);\n targetMeshCopy === null || targetMeshCopy === void 0 ? void 0 : targetMeshCopy.dispose(false, true);\n this.parentMeshVisualizationMap.delete(feature.id);\n super.delete3d(feature);\n }\n deleteTargetMeshVisualization(feature) {\n const previewMesh = this.targetMeshVisualizationMap.get(feature.id);\n previewMesh === null || previewMesh === void 0 ? void 0 : previewMesh.dispose(false, true);\n this.targetMeshVisualizationMap.delete(feature.id);\n }\n dispose() {\n this.bbSubscriptions.forEach(s => {\n s.unsubscribe();\n });\n this.bbSubscriptions.clear();\n joinedMeshes.clear();\n super.dispose();\n }\n }\n\n class LinearPatternRenderer extends PatternRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.LinearPatternFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const featureTranslation = feature.translation.toVec3();\n const workingVector = Vector3.Zero();\n return super.updateMeshGeometry(feature, vertexData, vertexDataChanges, (idx, particle) => {\n if (!feature.meshId) {\n workingVector.copyFrom(featureTranslation).scaleInPlace(idx);\n }\n particle.position.addInPlace(workingVector);\n });\n }\n }\n\n function createMirrorVisualization(mirror, scene, color) {\n if (!color) {\n color = Color3.Yellow();\n }\n const mirrorVisualization = MeshBuilder.CreatePlane('mirrorPlane', {}, scene);\n const coloredMaterial = new StandardMaterial('', scene);\n coloredMaterial.wireframe = true;\n coloredMaterial.emissiveColor = color;\n mirrorVisualization.material = coloredMaterial;\n mirrorVisualization.isPickable = false;\n mirrorVisualization.setEnabled(true);\n return mirrorVisualization;\n }\n\n class SliceFeatureRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.SliceFeature;\n this.previewLayer = this.viewer.utilityLayer;\n this.babylonMirrorPreviewsMap = new Map();\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n if (newVertexData.positions &&\n newVertexData.positions.length > 0 &&\n newVertexData.indices &&\n newVertexData.indices.length > 0) {\n const positions = newVertexData.positions;\n const normals = newVertexData.normals;\n const uvs = newVertexData.uvs;\n const indices = newVertexData.indices;\n const triCount = indices.length / 3;\n const positionsCount = positions.length / 3;\n const planeNormal = feature.normal.toVec3();\n const planePoint = feature.intersect.toVec3();\n const newPositions = [];\n const newNormals = [];\n const newUvs = [];\n const newIndices = [];\n const preSliceSubmeshes = newVertexData.submeshData;\n const newSubmeshes = preSliceSubmeshes.map(submesh => ({ ...submesh }));\n const edgeSplits = []; // which vertices are part of how many edges being split\n const edgeStart = Vector3.Zero();\n const edgeDir = Vector3.Zero();\n const workingVector = Vector3.Zero();\n let j;\n for (let i = 0; i < triCount; i++) {\n let hit = 0;\n let d = 0;\n let vertexIndex = -1;\n for (j = 0; j < 3; j++) {\n const iA = j, iB = (j + 1) % 3;\n const vA = indices[i * 3 + iA], vB = indices[i * 3 + iB];\n if (vertexIndex === -1) {\n vertexIndex = vA;\n }\n edgeStart.set(positions[vA * 3], positions[vA * 3 + 1], positions[vA * 3 + 2]);\n edgeStart.subtractFromFloatsToRef(positions[vB * 3], positions[vB * 3 + 1], positions[vB * 3 + 2], edgeDir);\n edgeDir.scaleInPlace(-1);\n const lnDot = Vector3.Dot(planeNormal, edgeDir);\n if (lnDot === 0) {\n continue;\n }\n planePoint.subtractToRef(edgeStart, workingVector);\n d = Vector3.Dot(workingVector, planeNormal) / lnDot;\n // Expect floating point errors. don't want unnecessary tiny triangles\n // If d is between 0 and 1, then the plane hit the edge\n if (d > 1e-12 && d < 1 - 1e-12) {\n hit++;\n edgeSplits[iA] = (edgeSplits[iA] || 0) + 1;\n edgeSplits[iB] = (edgeSplits[iB] || 0) + 1;\n edgeDir.scaleInPlace(d);\n edgeStart.addToRef(edgeDir, workingVector);\n newPositions.push(workingVector.x, workingVector.y, workingVector.z);\n if (normals) {\n workingVector.set(normals[vA * 3], normals[vA * 3 + 1], normals[vA * 3 + 2]);\n workingVector.scaleInPlace(1 - d);\n workingVector.addInPlaceFromFloats(normals[vB * 3] * d, normals[vB * 3 + 1] * d, normals[vB * 3 + 2] * d);\n newNormals.push(workingVector.x, workingVector.y, workingVector.z);\n }\n if (uvs) {\n workingVector.set(uvs[vA * 2], uvs[vA * 2 + 1], 0);\n workingVector.scaleInPlace(1 - d);\n workingVector.addInPlaceFromFloats(uvs[vB * 2] * d, uvs[vB * 2 + 1] * d, 0);\n newUvs.push(workingVector.x, workingVector.y);\n }\n }\n }\n if (hit) {\n // divide the triangle here\n if (hit === 1) {\n const split = positionsCount - 1 + newPositions.length / 3;\n if (!edgeSplits[0]) {\n newIndices.push(indices[i * 3], indices[i * 3 + 1], split, indices[i * 3], split, indices[i * 3 + 2]);\n }\n else if (!edgeSplits[1]) {\n newIndices.push(indices[i * 3], indices[i * 3 + 1], split, indices[i * 3 + 1], indices[i * 3 + 2], split);\n }\n else {\n newIndices.push(indices[i * 3], split, indices[i * 3 + 2], indices[i * 3 + 1], indices[i * 3 + 2], split);\n }\n newSubmeshes.forEach((submeshData, sI) => {\n const preSliceSubmesh = preSliceSubmeshes[sI];\n if (preSliceSubmesh.indexStart <= i * 3 &&\n preSliceSubmesh.indexStart + preSliceSubmesh.indexCount > i * 3) {\n submeshData.indexCount += 3;\n }\n else if (preSliceSubmesh.indexStart > i * 3) {\n submeshData.indexStart += 3;\n }\n });\n }\n if (hit === 2) {\n const aSplit = positionsCount - 1 + newPositions.length / 3 - 1, bSplit = positionsCount - 1 + newPositions.length / 3;\n newIndices.push(indices[i * 3]);\n newIndices.push(aSplit);\n newIndices.push(bSplit);\n if (edgeSplits[0] === 2) {\n newIndices.push(indices[i * 3 + 1], bSplit, aSplit, indices[i * 3 + 2], bSplit, indices[i * 3 + 1]);\n }\n else if (edgeSplits[1] === 2) {\n newIndices.push(indices[i * 3 + 2], indices[i * 3], bSplit, indices[i * 3 + 1], bSplit, aSplit);\n }\n else {\n newIndices.push(indices[i * 3 + 1], aSplit, indices[i * 3], indices[i * 3 + 2], bSplit, aSplit);\n }\n newSubmeshes.forEach((submeshData, sI) => {\n const preSliceSubmesh = preSliceSubmeshes[sI];\n if (preSliceSubmesh.indexStart <= i * 3 &&\n preSliceSubmesh.indexStart + preSliceSubmesh.indexCount > i * 3) {\n submeshData.indexCount += 6;\n }\n else if (preSliceSubmesh.indexStart > i * 3) {\n submeshData.indexStart += 6;\n }\n });\n }\n edgeSplits.clear();\n hit = 0;\n }\n else {\n // if(feature.removeGeometry && d > 1 - 1e-12) {\n // // If this face is in front of the face relative to the face normal, cull it\n // newSubmeshes.forEach(submeshData => {\n // if(submeshData.indexStart <= i && submeshData.indexStart + submeshData.indexCount > i) {\n // submeshData.indexCount -= 3;\n // } else if(submeshData.indexStart > i) {\n // submeshData.indexStart -= 3;\n // }\n // });\n // continue;\n // } else {\n // console.log(d);\n // }\n newIndices.push(indices[i * 3], indices[i * 3 + 1], indices[i * 3 + 2]);\n }\n // Update the vertices the submeshes are targetting\n if (vertexIndex !== -1 && hit > 0) {\n newSubmeshes.forEach(submeshData => {\n if (submeshData.verticesStart <= vertexIndex &&\n submeshData.verticesStart + submeshData.verticesCount > vertexIndex) {\n submeshData.verticesCount += hit;\n }\n else if (submeshData.verticesStart > vertexIndex) {\n submeshData.verticesStart += hit;\n }\n });\n }\n }\n newVertexData.indices = new Int32Array(newIndices);\n newVertexData.positions = new Float32Array(positions.length + newPositions.length);\n newVertexData.positions.set(positions);\n newVertexData.positions.set(newPositions, positions.length);\n if (normals) {\n newVertexData.normals = new Float32Array(normals.length + newNormals.length);\n newVertexData.normals.set(normals);\n newVertexData.normals.set(newNormals, normals.length);\n }\n if (uvs) {\n newVertexData.uvs = new Float32Array(uvs.length + newUvs.length);\n newVertexData.uvs.set(uvs);\n newVertexData.uvs.set(newUvs, uvs.length);\n }\n // Remove geometry on one side of the plane if the removeGeometry flag is true\n const baseGeometryVertexLength = positions.length / 3;\n if (feature.removeGeometry) {\n const indices = newVertexData.indices;\n const positions = newVertexData.positions;\n const normals = newVertexData.normals;\n const uvs = newVertexData.uvs;\n const newIndices = new Int32Array(indices.length);\n const newPositions = new Float32Array(positions.length);\n const newNormals = new Float32Array((normals === null || normals === void 0 ? void 0 : normals.length) || 0);\n const newUvs = new Float32Array((uvs === null || uvs === void 0 ? void 0 : uvs.length) || 0);\n const triCount = indices.length / 3;\n const vertexCount = positions.length / 3;\n const newPositionIndex = new Int32Array(vertexCount);\n // Keep track of how many positions we've used\n let position = 0;\n for (let i = 0; i < vertexCount; i++) {\n workingVector.set(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]);\n workingVector.subtractInPlace(planePoint);\n const d = Vector3.Dot(workingVector, planeNormal);\n // Don't remove new vertices that were created from the slice, those are guaranteed to be good\n if (i < baseGeometryVertexLength && d > 1e-12) {\n // Mark the original indices that have been removed so we can update the index array\n newPositionIndex[i] = -1;\n }\n else {\n // Copy over the vertex data we need and mark what new index they will have\n newPositionIndex[i] = position;\n newPositions[position * 3] = positions[i * 3];\n newPositions[position * 3 + 1] = positions[i * 3 + 1];\n newPositions[position * 3 + 2] = positions[i * 3 + 2];\n if (normals) {\n newNormals[position * 3] = normals[i * 3];\n newNormals[position * 3 + 1] = normals[i * 3 + 1];\n newNormals[position * 3 + 2] = normals[i * 3 + 2];\n }\n if (uvs) {\n newUvs[position * 2] = uvs[i * 2];\n newUvs[position * 2 + 1] = uvs[i * 2 + 1];\n }\n position++;\n }\n }\n // Trim off unused parts of the vertex arrays\n newVertexData.positions = newPositions.subarray(0, position * 3);\n if (normals) {\n newVertexData.normals = newNormals.subarray(0, position * 3);\n }\n if (uvs) {\n newVertexData.uvs = newUvs.subarray(0, position * 2);\n }\n position = 0;\n const originalSubmeshes = newSubmeshes.map(submesh => ({ ...submesh }));\n for (let i = 0; i < triCount; i++) {\n // If all of the positions in this triangle are being kept, add the triangle\n // The indices of the vertexes are changing so we need to use the value that we calculated prior\n if (newPositionIndex[indices[i * 3]] >= 0 &&\n newPositionIndex[indices[i * 3 + 1]] >= 0 &&\n newPositionIndex[indices[i * 3 + 2]] >= 0) {\n newIndices[position * 3] = newPositionIndex[indices[i * 3]];\n newIndices[position * 3 + 1] = newPositionIndex[indices[i * 3 + 1]];\n newIndices[position * 3 + 2] = newPositionIndex[indices[i * 3 + 2]];\n position++;\n }\n else {\n newSubmeshes.forEach((submeshData, sI) => {\n const originalSubmesh = originalSubmeshes[sI];\n if (originalSubmesh.indexStart <= i * 3 &&\n originalSubmesh.indexStart + originalSubmesh.indexCount > i * 3) {\n submeshData.indexCount -= 3;\n }\n else if (originalSubmesh.indexStart > i * 3) {\n submeshData.indexStart -= 3;\n }\n });\n }\n }\n // Update the vertex values on the submeshes as well\n for (let i = 0; i < newPositionIndex.length; i++) {\n if (newPositionIndex[i] === -1) {\n newSubmeshes.forEach(submeshData => {\n if (submeshData.verticesStart <= i &&\n submeshData.verticesStart + submeshData.verticesCount > i) {\n submeshData.verticesCount--;\n }\n else if (submeshData.verticesStart > i) {\n submeshData.verticesStart--;\n }\n });\n }\n }\n newVertexData.indices = newIndices.subarray(0, position * 3);\n }\n newVertexData.submeshData = newSubmeshes;\n }\n return newVertexData;\n }\n updatePreviewMesh(feature) {\n const scene = this.previewLayer.utilityLayerScene;\n let visualizationPlane = this.babylonMirrorPreviewsMap.get(feature.id);\n if (!visualizationPlane) {\n visualizationPlane = createMirrorVisualization(feature, scene);\n visualizationPlane.isPickable = false;\n this.babylonMirrorPreviewsMap.set(feature.id, visualizationPlane);\n }\n const currentNormal = new Vector3();\n currentNormal.set(0, 0, 1);\n const newNormal = new Vector3();\n newNormal.set(feature.normal.x, feature.normal.y, feature.normal.z);\n visualizationPlane.rotationQuaternion = rotationToVector(newNormal, currentNormal);\n let parentBoundingBox = undefined;\n if (feature._parent) {\n parentBoundingBox = this.viewer.getMeshBoundingBox(feature._parent);\n }\n if (parentBoundingBox) {\n const scale = parentBoundingBox.minWorld.subtract(parentBoundingBox.maxWorld).length();\n visualizationPlane.scaling.set(scale, scale, scale);\n }\n if (feature._parent) {\n const featureParent = this.viewer.getRendererNode(feature._parent);\n const meshPosition = featureParent.getAbsolutePosition();\n meshPosition.addInPlace(feature.intersect.toVec3());\n visualizationPlane.position.set(meshPosition.x, meshPosition.y, meshPosition.z);\n }\n }\n update3dInternal(node) {\n const visualizationPlane = this.babylonMirrorPreviewsMap.get(node.id);\n if (node._previewVisible) {\n this.updatePreviewMesh(node);\n if (node.enabled) {\n visualizationPlane === null || visualizationPlane === void 0 ? void 0 : visualizationPlane.setEnabled(true);\n }\n }\n else {\n visualizationPlane === null || visualizationPlane === void 0 ? void 0 : visualizationPlane.setEnabled(false);\n }\n }\n delete3d(node) {\n if (this.babylonMirrorPreviewsMap) {\n const featureInstance = this.babylonMirrorPreviewsMap.get(node.id);\n if (featureInstance) {\n featureInstance.dispose(false, true);\n }\n this.babylonMirrorPreviewsMap.delete(node.id);\n }\n super.delete3d(node);\n }\n }\n\n class MirrorFeatureRenderer extends SliceFeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.MirrorFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n if (newVertexData.positions &&\n newVertexData.positions.length > 0 &&\n newVertexData.indices &&\n newVertexData.indices.length > 0) {\n const positions = newVertexData.positions;\n const normals = newVertexData.normals;\n const uvs = newVertexData.uvs;\n const indices = newVertexData.indices;\n const newIndices = new Int32Array(indices.length);\n const newPositions = new Float32Array(positions.length);\n const newNormals = new Float32Array((normals === null || normals === void 0 ? void 0 : normals.length) || 0);\n const workingVector = Vector3.Zero();\n const planeNormal = feature.normal.toVec3().normalize();\n const planeIntersect = feature.intersect.toVec3();\n const vertexCount = positions.length / 3;\n for (let i = 0; i < vertexCount; i++) {\n const idx = i * 3;\n workingVector.set(positions[idx], positions[idx + 1], positions[idx + 2]);\n workingVector.subtractInPlace(planeIntersect);\n let d = Vector3.Dot(workingVector, planeNormal);\n planeNormal.scaleAndAddToRef(-2 * d, workingVector);\n newPositions[idx] = workingVector.x + planeIntersect.x;\n newPositions[idx + 1] = workingVector.y + planeIntersect.y;\n newPositions[idx + 2] = workingVector.z + planeIntersect.z;\n if (normals) {\n workingVector.set(normals[idx], normals[idx + 1], normals[idx + 2]);\n d = Vector3.Dot(workingVector, planeNormal);\n planeNormal.scaleAndAddToRef(-2 * d, workingVector);\n newNormals[idx] = workingVector.x;\n newNormals[idx + 1] = workingVector.y;\n newNormals[idx + 2] = workingVector.z;\n }\n }\n // Flip the direction of the triangles so that the normals face the right way\n const triCount = indices.length / 3;\n for (let i = 0; i < triCount; i++) {\n const idx = i * 3;\n if (feature.cloneGeometry) {\n newIndices[idx] = vertexCount + indices[idx + 2];\n newIndices[idx + 1] = vertexCount + indices[idx + 1];\n newIndices[idx + 2] = vertexCount + indices[idx];\n }\n else {\n newIndices[idx] = indices[idx + 2];\n newIndices[idx + 1] = indices[idx + 1];\n newIndices[idx + 2] = indices[idx];\n }\n }\n if (feature.cloneGeometry) {\n const combinedIndices = new Int32Array(indices.length * 2);\n const combinedPositions = new Float32Array(positions.length * 2);\n const combinedNormals = new Float32Array(((normals === null || normals === void 0 ? void 0 : normals.length) || 0) * 2);\n const combinedUvs = new Float32Array(((uvs === null || uvs === void 0 ? void 0 : uvs.length) || 0) * 2);\n const combinedSubmeshes = [];\n combinedIndices.set(indices);\n combinedIndices.set(newIndices, indices.length);\n combinedPositions.set(positions);\n combinedPositions.set(newPositions, positions.length);\n if (normals) {\n combinedNormals.set(normals);\n combinedNormals.set(newNormals, normals.length);\n }\n if (uvs) {\n combinedUvs.set(uvs);\n combinedUvs.set(uvs, uvs.length);\n }\n if (newVertexData.submeshData) {\n newVertexData.submeshData.forEach(submesh => {\n const newSubmesh = {\n ...submesh,\n verticesStart: submesh.verticesStart + vertexCount,\n indexStart: submesh.indexStart + indices.length,\n };\n combinedSubmeshes.push(submesh, newSubmesh);\n });\n }\n newVertexData.indices = combinedIndices;\n newVertexData.positions = combinedPositions;\n if (normals) {\n newVertexData.normals = combinedNormals;\n }\n if (uvs) {\n newVertexData.uvs = combinedUvs;\n }\n newVertexData.submeshData = combinedSubmeshes;\n }\n else {\n newVertexData.indices = newIndices;\n newVertexData.positions = newPositions;\n if (normals) {\n newVertexData.normals = newNormals;\n }\n }\n }\n return newVertexData;\n }\n }\n\n /*! *****************************************************************************\n Copyright (c) Microsoft Corporation.\n\n Permission to use, copy, modify, and/or distribute this software for any\n purpose with or without fee is hereby granted.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n PERFORMANCE OF THIS SOFTWARE.\n ***************************************************************************** */\n var t=function(r,e){return (t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r;}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e]);})(r,e)};function r(r,e){if(\"function\"!=typeof e&&null!==e)throw new TypeError(\"Class extends value \"+String(e)+\" is not a constructor or null\");function i(){this.constructor=r;}t(r,e),r.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i);}function e(t){var r=\"\";Array.isArray(t)||(t=[t]);for(var e=0;et.phi1&&(t.phi2-=2*n),1===t.sweepFlag&&t.phi2i)return [];if(0===i)return [[t*e/(t*t+r*r),r*e/(t*t+r*r)]];var n=Math.sqrt(i);return [[(t*e+r*n)/(t*t+r*r),(r*e-t*n)/(t*t+r*r)],[(t*e-r*n)/(t*t+r*r),(r*e+t*n)/(t*t+r*r)]]}var u,h=Math.PI/180;function c(t,r,e){return (1-e)*t+e*r}function y(t,r,e,i){return t+Math.cos(i/180*n)*r+Math.sin(i/180*n)*e}function p(t,r,e,i){var a=1e-6,n=r-t,o=e-r,s=3*n+3*(i-e)-6*o,u=6*(o-n),h=3*n;return Math.abs(s)T&&(a.sweepFlag=+!a.sweepFlag),a}))}function l(){return function(t){var r={};for(var e in t)r[e]=t[e];return r}}t.ROUND=function(t){function r(r){return Math.round(r*t)/t}return void 0===t&&(t=1e13),a(t),function(t){return void 0!==t.x1&&(t.x1=r(t.x1)),void 0!==t.y1&&(t.y1=r(t.y1)),void 0!==t.x2&&(t.x2=r(t.x2)),void 0!==t.y2&&(t.y2=r(t.y2)),void 0!==t.x&&(t.x=r(t.x)),void 0!==t.y&&(t.y=r(t.y)),void 0!==t.rX&&(t.rX=r(t.rX)),void 0!==t.rY&&(t.rY=r(t.rY)),t}},t.TO_ABS=r,t.TO_REL=function(){return u((function(t,r,e){return t.relative||(void 0!==t.x1&&(t.x1-=r),void 0!==t.y1&&(t.y1-=e),void 0!==t.x2&&(t.x2-=r),void 0!==t.y2&&(t.y2-=e),void 0!==t.x&&(t.x-=r),void 0!==t.y&&(t.y-=e),t.relative=!0),t}))},t.NORMALIZE_HVZ=function(t,r,e){return void 0===t&&(t=!0),void 0===r&&(r=!0),void 0===e&&(e=!0),u((function(i,a,n,o,s){if(isNaN(o)&&!(i.type&_.MOVE_TO))throw new Error(\"path must start with moveto\");return r&&i.type&_.HORIZ_LINE_TO&&(i.type=_.LINE_TO,i.y=i.relative?0:n),e&&i.type&_.VERT_LINE_TO&&(i.type=_.LINE_TO,i.x=i.relative?0:a),t&&i.type&_.CLOSE_PATH&&(i.type=_.LINE_TO,i.x=i.relative?o-a:o,i.y=i.relative?s-n:s),i.type&_.ARC&&(0===i.rX||0===i.rY)&&(i.type=_.LINE_TO,delete i.rX,delete i.rY,delete i.xRot,delete i.lArcFlag,delete i.sweepFlag),i}))},t.NORMALIZE_ST=e,t.QT_TO_C=n,t.INFO=u,t.SANITIZE=function(t){void 0===t&&(t=0),a(t);var r=NaN,e=NaN,i=NaN,n=NaN;return u((function(a,o,s,u,h){var c=Math.abs,y=!1,p=0,m=0;if(a.type&_.SMOOTH_CURVE_TO&&(p=isNaN(r)?0:o-r,m=isNaN(e)?0:s-e),a.type&(_.CURVE_TO|_.SMOOTH_CURVE_TO)?(r=a.relative?o+a.x2:a.x2,e=a.relative?s+a.y2:a.y2):(r=NaN,e=NaN),a.type&_.SMOOTH_QUAD_TO?(i=isNaN(i)?o:2*o-i,n=isNaN(n)?s:2*s-n):a.type&_.QUAD_TO?(i=a.relative?o+a.x1:a.x1,n=a.relative?s+a.y1:a.y2):(i=NaN,n=NaN),a.type&_.LINE_COMMANDS||a.type&_.ARC&&(0===a.rX||0===a.rY||!a.lArcFlag)||a.type&_.CURVE_TO||a.type&_.SMOOTH_CURVE_TO||a.type&_.QUAD_TO||a.type&_.SMOOTH_QUAD_TO){var O=void 0===a.x?0:a.relative?a.x:a.x-o,l=void 0===a.y?0:a.relative?a.y:a.y-s;p=isNaN(i)?void 0===a.x1?p:a.relative?a.x:a.x1-o:i-o,m=isNaN(n)?void 0===a.y1?m:a.relative?a.y:a.y1-s:n-s;var T=void 0===a.x2?0:a.relative?a.x:a.x2-o,v=void 0===a.y2?0:a.relative?a.y:a.y2-s;c(O)<=t&&c(l)<=t&&c(p)<=t&&c(m)<=t&&c(T)<=t&&c(v)<=t&&(y=!0);}return a.type&_.CLOSE_PATH&&c(o-u)<=t&&c(s-h)<=t&&(y=!0),y?[]:a}))},t.MATRIX=O,t.ROTATE=function(t,r,e){void 0===r&&(r=0),void 0===e&&(e=0),a(t,r,e);var i=Math.sin(t),n=Math.cos(t);return O(n,i,-i,n,r-r*n+e*i,e-r*i-e*n)},t.TRANSLATE=function(t,r){return void 0===r&&(r=0),a(t,r),O(1,0,0,1,t,r)},t.SCALE=function(t,r){return void 0===r&&(r=t),a(t,r),O(t,0,0,r,0,0)},t.SKEW_X=function(t){return a(t),O(1,0,Math.atan(t),1,0,0)},t.SKEW_Y=function(t){return a(t),O(1,Math.atan(t),0,1,0,0)},t.X_AXIS_SYMMETRY=function(t){return void 0===t&&(t=0),a(t),O(-1,0,0,1,t,0)},t.Y_AXIS_SYMMETRY=function(t){return void 0===t&&(t=0),a(t),O(1,0,0,-1,0,t)},t.A_TO_C=function(){return u((function(t,r,e){return _.ARC===t.type?function(t,r,e){var a,n,s,u;t.cX||o(t,r,e);for(var y=Math.min(t.phi1,t.phi2),p=Math.max(t.phi1,t.phi2)-y,m=Math.ceil(p/90),O=new Array(m),l=r,T=e,v=0;vc.maxX&&(c.maxX=t),tc.maxY&&(c.maxY=t),tw&&O(m(e,u.x1,u.x2,u.x,w));}for(var f=0,N=p(n,u.y1,u.y2,u.y);fw&&l(m(n,u.y1,u.y2,u.y,w));}}if(u.type&_.ARC){O(u.x),l(u.y),o(u,e,n);for(var x=u.xRot/180*Math.PI,d=Math.cos(x)*u.rX,E=Math.sin(x)*u.rX,A=-Math.sin(x)*u.rY,C=Math.cos(x)*u.rY,M=u.phi1u.phi2?[u.phi2+360,u.phi1+360]:[u.phi2,u.phi1],R=M[0],g=M[1],I=function(t){var r=t[0],e=t[1],i=180*Math.atan2(e,r)/Math.PI;return iR&&wR&&wu)throw new SyntaxError('Expected positive number, got \"'+u+'\" at index \"'+a+'\"')}else if((3===this.curArgs.length||4===this.curArgs.length)&&\"0\"!==this.curNumber&&\"1\"!==this.curNumber)throw new SyntaxError('Expected a flag, got \"'+this.curNumber+'\" at index \"'+a+'\"');this.curArgs.push(u),this.curArgs.length===N[this.curCommandType]&&(_.HORIZ_LINE_TO===this.curCommandType?i({type:_.HORIZ_LINE_TO,relative:this.curCommandRelative,x:u}):_.VERT_LINE_TO===this.curCommandType?i({type:_.VERT_LINE_TO,relative:this.curCommandRelative,y:u}):this.curCommandType===_.MOVE_TO||this.curCommandType===_.LINE_TO||this.curCommandType===_.SMOOTH_QUAD_TO?(i({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),_.MOVE_TO===this.curCommandType&&(this.curCommandType=_.LINE_TO)):this.curCommandType===_.CURVE_TO?i({type:_.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===_.SMOOTH_CURVE_TO?i({type:_.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===_.QUAD_TO?i({type:_.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===_.ARC&&i({type:_.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber=\"\",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0;}if(!T(n))if(\",\"===n&&this.canParseCommandOrComma)this.canParseCommandOrComma=!1;else if(\"+\"!==n&&\"-\"!==n&&\".\"!==n)if(s)this.curNumber=n,this.curNumberHasDecimal=!1;else {if(0!==this.curArgs.length)throw new SyntaxError(\"Unterminated command at index \"+a+\".\");if(!this.canParseCommandOrComma)throw new SyntaxError('Unexpected character \"'+n+'\" at index '+a+\". Command cannot follow comma\");if(this.canParseCommandOrComma=!1,\"z\"!==n&&\"Z\"!==n)if(\"h\"===n||\"H\"===n)this.curCommandType=_.HORIZ_LINE_TO,this.curCommandRelative=\"h\"===n;else if(\"v\"===n||\"V\"===n)this.curCommandType=_.VERT_LINE_TO,this.curCommandRelative=\"v\"===n;else if(\"m\"===n||\"M\"===n)this.curCommandType=_.MOVE_TO,this.curCommandRelative=\"m\"===n;else if(\"l\"===n||\"L\"===n)this.curCommandType=_.LINE_TO,this.curCommandRelative=\"l\"===n;else if(\"c\"===n||\"C\"===n)this.curCommandType=_.CURVE_TO,this.curCommandRelative=\"c\"===n;else if(\"s\"===n||\"S\"===n)this.curCommandType=_.SMOOTH_CURVE_TO,this.curCommandRelative=\"s\"===n;else if(\"q\"===n||\"Q\"===n)this.curCommandType=_.QUAD_TO,this.curCommandRelative=\"q\"===n;else if(\"t\"===n||\"T\"===n)this.curCommandType=_.SMOOTH_QUAD_TO,this.curCommandRelative=\"t\"===n;else {if(\"a\"!==n&&\"A\"!==n)throw new SyntaxError('Unexpected character \"'+n+'\" at index '+a+\".\");this.curCommandType=_.ARC,this.curCommandRelative=\"a\"===n;}else r.push({type:_.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;}else this.curNumber=n,this.curNumberHasDecimal=\".\"===n;}else this.curNumber+=n,this.curNumberHasDecimal=!0;else this.curNumber+=n;else this.curNumber+=n,this.curNumberHasExp=!0;else this.curNumber+=n,this.curNumberHasExpDigits=this.curNumberHasExp;}return r},e.prototype.transform=function(t){return Object.create(this,{parse:{value:function(r,e){void 0===e&&(e=[]);for(var i=0,a=Object.getPrototypeOf(this).parse.call(this,r);i= commands.length - 1;\n }\n next() {\n const command = this.commands[++this.i];\n this.previousCommand = this.command;\n this.command = command;\n return command;\n }\n getPoint(xProp = 'x', yProp = 'y') {\n if (this.command) {\n const x = parseInt(xProp);\n const y = parseInt(yProp);\n const point = new Vector2(x, y);\n return this.makeAbsolute(point);\n }\n }\n getAsControlPoint(xProp, yProp) {\n const point = this.getPoint(xProp, yProp);\n if (point) {\n this.control = point;\n }\n return point;\n }\n getAsCurrentPoint(xProp, yProp) {\n const point = this.getPoint(xProp, yProp);\n if (point) {\n this.current = point;\n }\n return point;\n }\n getReflectedControlPoint() {\n let previousCommand = null;\n if (this.previousCommand) {\n previousCommand = this.previousCommand.type;\n }\n if (previousCommand !== _.CURVE_TO &&\n previousCommand !== _.SMOOTH_CURVE_TO &&\n previousCommand !== _.QUAD_TO &&\n previousCommand !== _.SMOOTH_QUAD_TO) {\n return this.current;\n }\n // reflect point\n const { current: { x: cx, y: cy }, control: { x: ox, y: oy }, } = this;\n const point = new Vector2(2 * cx - ox, 2 * cy - oy);\n return point;\n }\n makeAbsolute(point) {\n if (this.command && 'relative' in this.command && this.command.relative) {\n const { x, y } = this.current;\n point.x += x;\n point.y += y;\n }\n return point;\n }\n addMarker(point, from, priorTo) {\n const { points, angles } = this;\n // if the last angle isn't filled in because we didn't have this point yet ...\n if (priorTo && angles.length > 0 && !angles[angles.length - 1]) {\n angles[angles.length - 1] = this.angleBetweenPoints(points[points.length - 1], priorTo);\n }\n this.addMarkerAngle(point, from ? this.angleBetweenPoints(from, point) : null);\n }\n addMarkerAngle(point, angle) {\n this.points.push(point);\n this.angles.push(angle);\n }\n angleBetweenPoints(point1, point2) {\n return Math.atan2(point2.y - point1.y, point2.x - point1.x);\n }\n getMarkerPoints() {\n return this.points;\n }\n getMarkerAngles() {\n const { angles } = this;\n const len = angles.length;\n for (let i = 0; i < len; i++) {\n if (!angles[i]) {\n for (let j = i + 1; j < len; j++) {\n if (angles[j]) {\n angles[i] = angles[j];\n break;\n }\n }\n }\n }\n return angles;\n }\n }\n\n class PathHandler {\n get currentPosition() {\n return this._currentPosition || this.initialPosition;\n }\n constructor(sketchNode, scaleDivider, nodeManager) {\n this.sketchNode = sketchNode;\n this.scaleDivider = scaleDivider;\n this.initialPosition = new exports.KbVector(0, 0, 0);\n this.stubPath = { id: 'stub' };\n this.nodeManager = nodeManager;\n }\n parseTrace(commands) {\n const newPaths = [];\n if (!this.sketchNode || commands.length === 0) {\n return [];\n }\n const first = commands[0];\n if (first.type !== 'M') {\n this.pathM(newPaths, {\n type: PathParser.MOVE_TO,\n relative: false,\n x: first.x1,\n y: first.y1,\n });\n }\n for (let i = 0; i < commands.length; i++) {\n const command = commands[i];\n const commonPathCommand = {\n relative: false,\n x: command.x2,\n y: command.y2,\n x1: command.x3 || -1,\n y1: command.y3 || -1,\n };\n switch (command.type) {\n case 'M': {\n const pathCommand = {\n ...commonPathCommand,\n type: PathParser.MOVE_TO,\n };\n this.pathM(newPaths, pathCommand);\n break;\n }\n case 'L': {\n const pathCommand = {\n ...commonPathCommand,\n type: PathParser.LINE_TO,\n };\n this.pathL(newPaths, pathCommand);\n break;\n }\n case 'Q': {\n if (!command.x3 || !command.y3) {\n console.warn('Q command without x3 or y3');\n }\n else {\n const pathCommand = {\n ...commonPathCommand,\n type: PathParser.QUAD_TO,\n x: command.x3,\n y: command.y3,\n x1: command.x2,\n y1: command.y2,\n };\n this.pathQ(newPaths, pathCommand);\n }\n break;\n }\n /** imagetracer does not return C, S, or T paths\n *\n case 'C': {\n const pathCommand: CommandC = {\n ...commonPathCommand,\n type: PathParser.CURVE_TO,\n };\n this.pathC(newPaths, pathCommand);\n break;\n }\n case 'S': {\n const pathCommand: CommandS = {\n ...commonPathCommand,\n type: PathParser.SMOOTH_CURVE_TO,\n };\n this.pathS(newPaths, pathCommand);\n break;\n }\n case 'T': {\n const pathCommand: CommandT = {\n ...commonPathCommand,\n type: PathParser.SMOOTH_QUAD_TO,\n };\n this.pathT(newPaths, pathCommand);\n break;\n }\n */\n case 'Z': {\n this.pathZ(newPaths);\n }\n }\n }\n return this.reprojectPaths(newPaths.filter(path => path !== this.stubPath));\n }\n parsePath(path) {\n this.pathParser = new PathParser(path);\n this.pathParser.reset();\n if (!this.sketchNode) {\n return [];\n }\n const newPaths = [];\n while (!this.pathParser.isEnd()) {\n switch (this.pathParser.next().type) {\n case PathParser.MOVE_TO:\n this.pathM(newPaths);\n break;\n case PathParser.LINE_TO:\n this.pathL(newPaths);\n break;\n case PathParser.HORIZ_LINE_TO:\n this.pathL(newPaths);\n break;\n case PathParser.VERT_LINE_TO:\n this.pathL(newPaths);\n break;\n case PathParser.CURVE_TO:\n this.pathC(newPaths);\n break;\n case PathParser.SMOOTH_CURVE_TO:\n this.pathS(newPaths);\n break;\n case PathParser.QUAD_TO:\n this.pathQ(newPaths);\n break;\n case PathParser.SMOOTH_QUAD_TO:\n this.pathT(newPaths);\n break;\n case PathParser.ARC:\n console.warn('ARC not implemented');\n this.pathA(newPaths);\n break;\n case PathParser.CLOSE_PATH:\n this.pathZ(newPaths);\n break;\n }\n }\n return this.reprojectPaths(newPaths.filter(path => path !== this.stubPath));\n }\n reprojectPaths(paths) {\n paths.forEach(path => {\n path.controlPoints.forEach(cp => {\n cp.position = projectOnNodeAxis(this.sketchNode, cp.position.x, cp.position.y);\n cp.direction = projectOnNodeAxis(this.sketchNode, cp.direction.x, cp.direction.y);\n if (cp.direction2) {\n cp.direction2 = projectOnNodeAxis(this.sketchNode, cp.direction2.x, cp.direction2.y);\n }\n });\n });\n return paths;\n }\n checkIfNewPathNeeded(paths, desiredPathType) {\n let activePath = paths[paths.length - 1];\n if (!activePath || activePath === this.stubPath || activePath.type !== desiredPathType) {\n if (activePath === this.stubPath) {\n paths.pop();\n }\n activePath = this.addNewPath(paths, desiredPathType);\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n if (!this._currentPosition) {\n console.warn('new path created with no moveto command');\n }\n newControlPoint.position = this.currentPosition;\n activePath.controlPoints.push(newControlPoint);\n newControlPoint.direction2 = new exports.KbVector(0, 0, 0);\n }\n return activePath;\n }\n pathM(paths, command) {\n const { pathParser } = this;\n let x = 0;\n let y = 0;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n x = command.x / this.scaleDivider;\n y = (command.y * -1) / this.scaleDivider;\n if (command.relative && this.currentPosition) {\n x = x + this.currentPosition.x;\n y = y + this.currentPosition.y;\n }\n this._currentPosition = new exports.KbVector(x, y, 0);\n this.initialPosition = this._currentPosition;\n paths.push(this.stubPath);\n }\n }\n pathL(paths, command) {\n const { pathParser } = this;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n let x;\n let y;\n //these 2 if checks need to happen because pathL could be a horizontal or vertical line and therefore not have one of the coordinates.\n if ('x' in command) {\n x = command.x / this.scaleDivider;\n }\n if ('y' in command) {\n y = (command.y * -1) / this.scaleDivider;\n }\n const activePath = this.checkIfNewPathNeeded(paths, exports.eSketchPathType.points);\n if (command.relative && activePath) {\n if (x !== undefined) {\n x = x + this.currentPosition.x;\n }\n if (y !== undefined) {\n y = y + this.currentPosition.y;\n }\n }\n if (x === undefined) {\n // V case\n x = this.currentPosition.x || 0;\n }\n if (y === undefined) {\n // H case\n y = this.currentPosition.y || 0;\n }\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(x, y, 0);\n this._currentPosition = newControlPoint.position;\n activePath.controlPoints.push(newControlPoint);\n }\n }\n pathC(paths, command) {\n const { pathParser } = this;\n let x = 0;\n let y = 0;\n let x1 = 0;\n let y1 = 0;\n let x2 = 0;\n let y2 = 0;\n let lastControlPoint = undefined;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n x = command.x / this.scaleDivider;\n y = (command.y * -1) / this.scaleDivider;\n x1 = command.x1 / this.scaleDivider;\n y1 = (command.y1 * -1) / this.scaleDivider;\n x2 = command.x2 / this.scaleDivider;\n y2 = (command.y2 * -1) / this.scaleDivider;\n const activePath = this.checkIfNewPathNeeded(paths, exports.eSketchPathType.cubicBezier);\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\n if (command.relative) {\n x = x + this.currentPosition.x;\n y = y + this.currentPosition.y;\n x1 = x1 + this.currentPosition.x;\n y1 = y1 + this.currentPosition.y;\n x2 = x2 + this.currentPosition.x;\n y2 = y2 + this.currentPosition.y;\n }\n if (lastControlPoint) {\n lastControlPoint.direction = new exports.KbVector(x1 - lastControlPoint.position.x, y1 - lastControlPoint.position.y, 0);\n }\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(x, y, 0);\n this._currentPosition = newControlPoint.position;\n newControlPoint.direction2 = new exports.KbVector(x2 - x, y2 - y, 0);\n activePath.controlPoints.push(newControlPoint);\n }\n }\n pathS(paths, command) {\n var _a;\n const { pathParser } = this;\n let x = 0;\n let y = 0;\n let x2 = 0;\n let y2 = 0;\n let lastControlPoint = undefined;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n x = command.x / this.scaleDivider;\n y = (command.y * -1) / this.scaleDivider;\n x2 = command.x2 / this.scaleDivider;\n y2 = (command.y2 * -1) / this.scaleDivider;\n const activePath = this.checkIfNewPathNeeded(paths, exports.eSketchPathType.cubicBezier);\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\n lastControlPoint.direction = new exports.KbVector(0, 0, 0);\n if (command.relative) {\n x = x + this.currentPosition.x;\n y = y + this.currentPosition.y;\n x2 = x2 + this.currentPosition.x;\n y2 = y2 + this.currentPosition.y;\n }\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(x, y, 0);\n if (lastControlPoint && lastControlPoint.direction2) {\n lastControlPoint.direction = (_a = lastControlPoint.direction2) === null || _a === void 0 ? void 0 : _a.scale(-1);\n newControlPoint.direction2 = new exports.KbVector(x2 - x, y2 - y, 0);\n }\n this._currentPosition = newControlPoint.position;\n activePath.controlPoints.push(newControlPoint);\n return activePath;\n }\n }\n pathQ(paths, command) {\n const { pathParser } = this;\n let x = 0;\n let y = 0;\n let x1 = 0;\n let y1 = 0;\n let lastControlPoint = undefined;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n x = command.x / this.scaleDivider;\n y = (command.y * -1) / this.scaleDivider;\n x1 = command.x1 / this.scaleDivider;\n y1 = (command.y1 * -1) / this.scaleDivider;\n const activePath = this.checkIfNewPathNeeded(paths, exports.eSketchPathType.quadraticBezier);\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\n if (command.relative) {\n x = x + this.currentPosition.x;\n y = y + this.currentPosition.y;\n x1 = x1 + this.currentPosition.x;\n y1 = y1 + this.currentPosition.y;\n }\n if (lastControlPoint) {\n lastControlPoint.direction = new exports.KbVector(x1 - lastControlPoint.position.x, y1 - lastControlPoint.position.y, 0);\n }\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(x, y, 0);\n this._currentPosition = newControlPoint.position;\n activePath.controlPoints.push(newControlPoint);\n }\n }\n pathT(paths, command) {\n const { pathParser } = this;\n let x = 0;\n let y = 0;\n let lastControlPoint = undefined;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n x = command.x / this.scaleDivider;\n y = (command.y * -1) / this.scaleDivider;\n const activePath = this.checkIfNewPathNeeded(paths, exports.eSketchPathType.quadraticBezier);\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\n lastControlPoint.direction = new exports.KbVector(0, 0, 0);\n if (command.relative) {\n x = x + this.currentPosition.x;\n y = y + this.currentPosition.y;\n }\n const secondLastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 2];\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(x, y, 0);\n this._currentPosition = newControlPoint.position;\n activePath.controlPoints.push(newControlPoint);\n if (lastControlPoint && secondLastControlPoint && secondLastControlPoint) {\n lastControlPoint.direction = this.calculateReflection(secondLastControlPoint.direction, secondLastControlPoint, lastControlPoint);\n }\n }\n }\n //Path A needs further implementing\n pathA(paths, command) {\n const { pathParser } = this;\n if (!command && pathParser.command) {\n command = pathParser.command;\n }\n if (command) {\n // const cX = command.cX;\n // const cY = command.cY;\n // const rX = command.rX;\n // const rY = command.rY;\n let x = command.x;\n let y = command.y;\n if (command.relative) {\n x = x + this.currentPosition.x;\n y = y + this.currentPosition.y;\n }\n // const xAxisRotation = command.xRot;\n // const largeArcFlag = command.lArcFlag;\n // const sweepFlag = command.sweepFlag;\n this._currentPosition = new exports.KbVector(x, y, 0);\n }\n }\n pathZ(paths) {\n const activePath = this.checkIfNewPathNeeded(paths, exports.eSketchPathType.points);\n const x = this.initialPosition.x;\n const y = this.initialPosition.y;\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(x, y, 0);\n this._currentPosition = undefined;\n activePath.controlPoints.push(newControlPoint);\n return activePath;\n }\n addNewPath(paths, pathType) {\n const newPath = this.nodeManager.create(Token.SketchPath);\n newPath.name = 'Path';\n newPath._expanded = true;\n paths.push(newPath);\n if (pathType) {\n newPath.type = pathType;\n }\n return newPath;\n }\n calculateReflection(vector, controlPoint, controlPoint2) {\n const n = controlPoint2.position.subtract(controlPoint.position).normalize();\n return vector.subtract(n.scale(2 * vector.dotProduct(n))).scale(-1);\n }\n }\n\n const VERSION_NUMBER = \"0.2.1\";\n const PATHSCAN_COMBINED_LOOKUP = [\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]],\n [[0, 1, 0, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [0, 2, -1, 0]],\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [0, 1, 0, -1], [0, 0, 1, 0]],\n [[0, 0, 1, 0], [-1, -1, -1, -1], [0, 2, -1, 0], [-1, -1, -1, -1]],\n [[-1, -1, -1, -1], [0, 0, 1, 0], [0, 3, 0, 1], [-1, -1, -1, -1]],\n [[13, 3, 0, 1], [13, 2, -1, 0], [7, 1, 0, -1], [7, 0, 1, 0]],\n [[-1, -1, -1, -1], [0, 1, 0, -1], [-1, -1, -1, -1], [0, 3, 0, 1]],\n [[0, 3, 0, 1], [0, 2, -1, 0], [-1, -1, -1, -1], [-1, -1, -1, -1]],\n [[0, 3, 0, 1], [0, 2, -1, 0], [-1, -1, -1, -1], [-1, -1, -1, -1]],\n [[-1, -1, -1, -1], [0, 1, 0, -1], [-1, -1, -1, -1], [0, 3, 0, 1]],\n [[11, 1, 0, -1], [14, 0, 1, 0], [14, 3, 0, 1], [11, 2, -1, 0]],\n [[-1, -1, -1, -1], [0, 0, 1, 0], [0, 3, 0, 1], [-1, -1, -1, -1]],\n [[0, 0, 1, 0], [-1, -1, -1, -1], [0, 2, -1, 0], [-1, -1, -1, -1]],\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [0, 1, 0, -1], [0, 0, 1, 0]],\n [[0, 1, 0, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [0, 2, -1, 0]],\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]]\n ];\n const SPECPALETTE = [\n { r: 0, g: 0, b: 0, a: 255 },\n { r: 128, g: 128, b: 128, a: 255 },\n { r: 0, g: 0, b: 128, a: 255 },\n { r: 64, g: 64, b: 128, a: 255 },\n { r: 192, g: 192, b: 192, a: 255 },\n { r: 255, g: 255, b: 255, a: 255 },\n { r: 128, g: 128, b: 192, a: 255 },\n { r: 0, g: 0, b: 192, a: 255 },\n { r: 128, g: 0, b: 0, a: 255 },\n { r: 128, g: 64, b: 64, a: 255 },\n { r: 128, g: 0, b: 128, a: 255 },\n { r: 168, g: 168, b: 168, a: 255 },\n { r: 192, g: 128, b: 128, a: 255 },\n { r: 192, g: 0, b: 0, a: 255 },\n { r: 255, g: 255, b: 255, a: 255 },\n { r: 0, g: 128, b: 0, a: 255 }\n ];\n const GKS = [\n [0.27901, 0.44198, 0.27901],\n [0.135336, 0.228569, 0.272192, 0.228569, 0.135336],\n [0.086776, 0.136394, 0.178908, 0.195843, 0.178908, 0.136394, 0.086776],\n [0.063327, 0.093095, 0.122589, 0.144599, 0.152781, 0.144599, 0.122589, 0.093095, 0.063327],\n [0.049692, 0.069304, 0.089767, 0.107988, 0.120651, 0.125194, 0.120651, 0.107988, 0.089767, 0.069304, 0.049692]\n ];\n\n const OPTION_PRESETS = {\n default: {\n corsenabled: false,\n ltres: 1,\n qtres: 1,\n pathomit: 8,\n rightangleenhance: true,\n colorsampling: 2,\n numberofcolors: 16,\n mincolorratio: 0,\n colorquantcycles: 3,\n layering: 0,\n strokewidth: 1,\n linefilter: false,\n scale: 1,\n roundcoords: 1,\n viewbox: false,\n desc: false,\n lcpr: 0,\n qcpr: 0,\n blurradius: 0,\n blurdelta: 20\n },\n posterized1: { colorsampling: 0, numberofcolors: 2 },\n posterized2: { numberofcolors: 4, blurradius: 5 },\n curvy: { ltres: 0.01, linefilter: true, rightangleenhance: false },\n sharp: { qtres: 0.01, linefilter: false },\n detailed: { pathomit: 0, roundcoords: 2, ltres: 0.5, qtres: 0.5, numberofcolors: 64 },\n smoothed: { blurradius: 5, blurdelta: 64 },\n grayscale: { colorsampling: 0, colorquantcycles: 1, numberofcolors: 7 },\n fixedpalette: { colorsampling: 0, colorquantcycles: 1, numberofcolors: 27 },\n randomsampling1: { colorsampling: 1, numberofcolors: 8 },\n randomsampling2: { colorsampling: 1, numberofcolors: 64 },\n artistic1: { colorsampling: 0, colorquantcycles: 1, pathomit: 0, blurradius: 5, blurdelta: 64, ltres: 0.01, linefilter: true, numberofcolors: 16, strokewidth: 2 },\n artistic2: { qtres: 0.01, colorsampling: 0, colorquantcycles: 1, numberofcolors: 4, strokewidth: 0 },\n artistic3: { qtres: 10, ltres: 10, numberofcolors: 8 },\n artistic4: { qtres: 10, ltres: 10, numberofcolors: 64, blurradius: 5, blurdelta: 256, strokewidth: 2 },\n posterized3: {\n ltres: 1,\n qtres: 1,\n pathomit: 20,\n rightangleenhance: true,\n colorsampling: 0,\n numberofcolors: 3,\n mincolorratio: 0,\n colorquantcycles: 3,\n blurradius: 3,\n blurdelta: 20,\n strokewidth: 0,\n linefilter: false,\n roundcoords: 1,\n pal: [{ r: 0, g: 0, b: 100, a: 255 }, { r: 255, g: 255, b: 255, a: 255 }]\n }\n };\n\n function generatePalette(numberOfColors) {\n const palette = [];\n let rcnt;\n let gcnt;\n let bcnt;\n if (numberOfColors < 8) {\n const graystep = Math.floor(255 / (numberOfColors - 1));\n for (let i = 0; i < numberOfColors; i++)\n palette.push({ r: i * graystep, g: i * graystep, b: i * graystep, a: 255 });\n } else {\n const colorqnum = Math.floor(Math.pow(numberOfColors, 1 / 3));\n const colorstep = Math.floor(255 / (colorqnum - 1));\n const rndnum = numberOfColors - colorqnum * colorqnum * colorqnum;\n for (rcnt = 0; rcnt < colorqnum; rcnt++) {\n for (gcnt = 0; gcnt < colorqnum; gcnt++) {\n for (bcnt = 0; bcnt < colorqnum; bcnt++)\n palette.push({ r: rcnt * colorstep, g: gcnt * colorstep, b: bcnt * colorstep, a: 255 });\n }\n }\n for (rcnt = 0; rcnt < rndnum; rcnt++)\n palette.push({ r: Math.floor(Math.random() * 255), g: Math.floor(Math.random() * 255), b: Math.floor(Math.random() * 255), a: Math.floor(Math.random() * 255) });\n }\n return palette;\n }\n function samplePalette(numberOfColors, imageData) {\n let idx;\n const palette = [];\n for (let i = 0; i < numberOfColors; i++) {\n idx = Math.floor(Math.random() * imageData.data.length / 4) * 4;\n palette.push({ r: imageData.data[idx], g: imageData.data[idx + 1], b: imageData.data[idx + 2], a: imageData.data[idx + 3] });\n }\n return palette;\n }\n function samplePaletteByGrid(numberOfColors, imageData) {\n let idx;\n const palette = [];\n const ni = Math.ceil(Math.sqrt(numberOfColors));\n const nj = Math.ceil(numberOfColors / ni);\n const vx = imageData.width / (ni + 1);\n const vy = imageData.height / (nj + 1);\n for (let j = 0; j < nj; j++) {\n for (let i = 0; i < ni; i++) {\n if (palette.length === numberOfColors) {\n break;\n } else {\n idx = Math.floor((j + 1) * vy * imageData.width + (i + 1) * vx) * 4;\n palette.push({ r: imageData.data[idx], g: imageData.data[idx + 1], b: imageData.data[idx + 2], a: imageData.data[idx + 3] });\n }\n }\n }\n return palette;\n }\n\n function blur(imageData, radius, delta) {\n let i, j, k, d, idx, racc, gacc, bacc, aacc, wacc;\n const imageData2 = new ImageData(imageData.width, imageData.height);\n radius = Math.floor(radius);\n if (radius < 1)\n return imageData;\n if (radius > 5)\n radius = 5;\n delta = Math.abs(delta);\n if (delta > 1024)\n delta = 1024;\n const thisgk = GKS[radius - 1];\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n racc = 0;\n gacc = 0;\n bacc = 0;\n aacc = 0;\n wacc = 0;\n for (k = -radius; k < radius + 1; k++) {\n if (i + k > 0 && i + k < imageData.width) {\n idx = (j * imageData.width + i + k) * 4;\n racc += imageData.data[idx] * thisgk[k + radius];\n gacc += imageData.data[idx + 1] * thisgk[k + radius];\n bacc += imageData.data[idx + 2] * thisgk[k + radius];\n aacc += imageData.data[idx + 3] * thisgk[k + radius];\n wacc += thisgk[k + radius];\n }\n }\n idx = (j * imageData.width + i) * 4;\n imageData2.data[idx] = Math.floor(racc / wacc);\n imageData2.data[idx + 1] = Math.floor(gacc / wacc);\n imageData2.data[idx + 2] = Math.floor(bacc / wacc);\n imageData2.data[idx + 3] = Math.floor(aacc / wacc);\n }\n }\n const himageData = new Uint8ClampedArray(imageData2.data);\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n racc = 0;\n gacc = 0;\n bacc = 0;\n aacc = 0;\n wacc = 0;\n for (k = -radius; k < radius + 1; k++) {\n if (j + k > 0 && j + k < imageData.height) {\n idx = ((j + k) * imageData.width + i) * 4;\n racc += himageData[idx] * thisgk[k + radius];\n gacc += himageData[idx + 1] * thisgk[k + radius];\n bacc += himageData[idx + 2] * thisgk[k + radius];\n aacc += himageData[idx + 3] * thisgk[k + radius];\n wacc += thisgk[k + radius];\n }\n }\n idx = (j * imageData.width + i) * 4;\n imageData2.data[idx] = Math.floor(racc / wacc);\n imageData2.data[idx + 1] = Math.floor(gacc / wacc);\n imageData2.data[idx + 2] = Math.floor(bacc / wacc);\n imageData2.data[idx + 3] = Math.floor(aacc / wacc);\n }\n }\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n idx = (j * imageData.width + i) * 4;\n d = Math.abs(imageData2.data[idx] - imageData.data[idx]) + Math.abs(imageData2.data[idx + 1] - imageData.data[idx + 1]) + Math.abs(imageData2.data[idx + 2] - imageData.data[idx + 2]) + Math.abs(imageData2.data[idx + 3] - imageData.data[idx + 3]);\n if (d > delta) {\n imageData2.data[idx] = imageData.data[idx];\n imageData2.data[idx + 1] = imageData.data[idx + 1];\n imageData2.data[idx + 2] = imageData.data[idx + 2];\n imageData2.data[idx + 3] = imageData.data[idx + 3];\n }\n }\n }\n return imageData2;\n }\n\n function getDirection(x1, y1, x2, y2) {\n let result = 8;\n if (x1 < x2) {\n if (y1 < y2)\n result = 1;\n else if (y1 > y2)\n result = 7;\n else\n result = 0;\n } else if (x1 > x2) {\n if (y1 < y2)\n result = 3;\n else if (y1 > y2)\n result = 5;\n else\n result = 4;\n } else {\n if (y1 < y2)\n result = 2;\n else if (y1 > y2)\n result = 6;\n else\n result = 8;\n }\n return result;\n }\n const roundToDec = (val, places = void 0) => +val.toFixed(places);\n function colorQuantization(imageData, options) {\n const arr = [];\n let idx = 0;\n let cd;\n let cdl;\n let ci;\n const paletteacc = [];\n const pixelnum = imageData.width * imageData.height;\n let i;\n let j;\n let k;\n let cnt;\n let palette;\n let imageDataCache = imageData.data;\n if (imageDataCache.length < pixelnum * 4) {\n const newImageData = new Uint8ClampedArray(pixelnum * 4);\n for (let pxcnt = 0; pxcnt < pixelnum; pxcnt++) {\n newImageData[pxcnt * 4] = imageDataCache[pxcnt * 3];\n newImageData[pxcnt * 4 + 1] = imageDataCache[pxcnt * 3 + 1];\n newImageData[pxcnt * 4 + 2] = imageDataCache[pxcnt * 3 + 2];\n newImageData[pxcnt * 4 + 3] = 255;\n }\n imageDataCache = newImageData;\n }\n for (j = 0; j < imageData.height + 2; j++) {\n arr[j] = [];\n for (i = 0; i < imageData.width + 2; i++)\n arr[j][i] = -1;\n }\n if (options.pal)\n palette = options.pal;\n else if (options.colorsampling === 0)\n palette = generatePalette(options.numberofcolors);\n else if (options.colorsampling === 1)\n palette = samplePalette(options.numberofcolors, imageData);\n else\n palette = samplePaletteByGrid(options.numberofcolors, imageData);\n if (options.blurradius > 0)\n imageData = blur(imageData, options.blurradius, options.blurdelta);\n for (cnt = 0; cnt < options.colorquantcycles; cnt++) {\n if (cnt > 0) {\n for (k = 0; k < palette.length; k++) {\n if (paletteacc[k].n > 0) {\n palette[k] = {\n r: Math.floor(paletteacc[k].r / paletteacc[k].n),\n g: Math.floor(paletteacc[k].g / paletteacc[k].n),\n b: Math.floor(paletteacc[k].b / paletteacc[k].n),\n a: Math.floor(paletteacc[k].a / paletteacc[k].n)\n };\n }\n if (paletteacc[k].n / pixelnum < options.mincolorratio && cnt < options.colorquantcycles - 1) {\n palette[k] = {\n r: Math.floor(Math.random() * 255),\n g: Math.floor(Math.random() * 255),\n b: Math.floor(Math.random() * 255),\n a: Math.floor(Math.random() * 255)\n };\n }\n }\n }\n for (i = 0; i < palette.length; i++)\n paletteacc[i] = { r: 0, g: 0, b: 0, a: 0, n: 0 };\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n idx = (j * imageData.width + i) * 4;\n ci = 0;\n cdl = 1024;\n for (k = 0; k < palette.length; k++) {\n cd = (palette[k].r > imageDataCache[idx] ? palette[k].r - imageDataCache[idx] : imageDataCache[idx] - palette[k].r) + (palette[k].g > imageDataCache[idx + 1] ? palette[k].g - imageDataCache[idx + 1] : imageDataCache[idx + 1] - palette[k].g) + (palette[k].b > imageDataCache[idx + 2] ? palette[k].b - imageDataCache[idx + 2] : imageDataCache[idx + 2] - palette[k].b) + (palette[k].a > imageDataCache[idx + 3] ? palette[k].a - imageDataCache[idx + 3] : imageDataCache[idx + 3] - palette[k].a);\n if (cd < cdl) {\n cdl = cd;\n ci = k;\n }\n }\n paletteacc[ci].r += imageDataCache[idx];\n paletteacc[ci].g += imageDataCache[idx + 1];\n paletteacc[ci].b += imageDataCache[idx + 2];\n paletteacc[ci].a += imageDataCache[idx + 3];\n paletteacc[ci].n++;\n arr[j + 1][i + 1] = ci;\n }\n }\n }\n return { array: arr, palette };\n }\n const toRgbaStr = (c) => `rgba(${c.r},${c.g},${c.b},${c.a})`;\n\n function svgPathString(tracedata, lnum, pathnum, options) {\n const layer = tracedata.layers[lnum];\n const smp = layer[pathnum];\n let str = \"\";\n let pcnt;\n if (options.linefilter && smp.segments.length < 3)\n return str;\n str = `= 0; pcnt--) {\n str += `${hsmp.segments[pcnt].type} `;\n if (hsmp.segments[pcnt].hasOwnProperty(\"x3\"))\n str += `${hsmp.segments[pcnt].x2 * options.scale} ${hsmp.segments[pcnt].y2 * options.scale} `;\n str += `${hsmp.segments[pcnt].x1 * options.scale} ${hsmp.segments[pcnt].y1 * options.scale} `;\n }\n } else {\n if (hsmp.segments[hsmp.segments.length - 1].hasOwnProperty(\"x3\"))\n str += `M ${roundToDec(hsmp.segments[hsmp.segments.length - 1].x3 * options.scale)} ${roundToDec(hsmp.segments[hsmp.segments.length - 1].y3 * options.scale)} `;\n else\n str += `M ${roundToDec(hsmp.segments[hsmp.segments.length - 1].x2 * options.scale)} ${roundToDec(hsmp.segments[hsmp.segments.length - 1].y2 * options.scale)} `;\n for (pcnt = hsmp.segments.length - 1; pcnt >= 0; pcnt--) {\n str += `${hsmp.segments[pcnt].type} `;\n if (hsmp.segments[pcnt].hasOwnProperty(\"x3\"))\n str += `${roundToDec(hsmp.segments[pcnt].x2 * options.scale)} ${roundToDec(hsmp.segments[pcnt].y2 * options.scale)} `;\n str += `${roundToDec(hsmp.segments[pcnt].x1 * options.scale)} ${roundToDec(hsmp.segments[pcnt].y1 * options.scale)} `;\n }\n }\n str += \"Z \";\n }\n str += '\" />';\n if (options.lcpr || options.qcpr) {\n for (pcnt = 0; pcnt < smp.segments.length; pcnt++) {\n if (smp.segments[pcnt].hasOwnProperty(\"x3\") && options.qcpr) {\n str += ``;\n str += ``;\n str += ``;\n str += ``;\n }\n if (!smp.segments[pcnt].hasOwnProperty(\"x3\") && options.lcpr)\n str += ``;\n }\n for (let hcnt = 0; hcnt < smp.holechildren.length; hcnt++) {\n const hsmp = layer[smp.holechildren[hcnt]];\n for (pcnt = 0; pcnt < hsmp.segments.length; pcnt++) {\n if (hsmp.segments[pcnt].hasOwnProperty(\"x3\") && options.qcpr) {\n str += ``;\n str += ``;\n str += ``;\n str += ``;\n }\n if (!hsmp.segments[pcnt].hasOwnProperty(\"x3\") && options.lcpr)\n str += ``;\n }\n }\n }\n return str;\n }\n function toSvgColorStr(c, options) {\n return `fill=\"rgb(${c.r},${c.g},${c.b})\" stroke=\"rgb(${c.r},${c.g},${c.b})\" stroke-width=\"${options.strokewidth}\" opacity=\"${c.a / 255}\" `;\n }\n function fitSeq(path, ltres, qtres, seqstart, seqend) {\n if (seqend > path.points.length || seqend < 0)\n return [];\n let errorpoint = seqstart;\n let errorval = 0;\n let curvepass = true;\n let px;\n let py;\n let dist2;\n let tl = seqend - seqstart;\n if (tl < 0)\n tl += path.points.length;\n const vx = (path.points[seqend].x - path.points[seqstart].x) / tl;\n const vy = (path.points[seqend].y - path.points[seqstart].y) / tl;\n let pcnt = (seqstart + 1) % path.points.length;\n let pl;\n while (pcnt !== seqend) {\n pl = pcnt - seqstart;\n if (pl < 0)\n pl += path.points.length;\n px = path.points[seqstart].x + vx * pl;\n py = path.points[seqstart].y + vy * pl;\n dist2 = (path.points[pcnt].x - px) * (path.points[pcnt].x - px) + (path.points[pcnt].y - py) * (path.points[pcnt].y - py);\n if (dist2 > ltres)\n curvepass = false;\n if (dist2 > errorval) {\n errorpoint = pcnt;\n errorval = dist2;\n }\n pcnt = (pcnt + 1) % path.points.length;\n }\n if (curvepass)\n return [{ type: \"L\", x1: path.points[seqstart].x, y1: path.points[seqstart].y, x2: path.points[seqend].x, y2: path.points[seqend].y }];\n const fitpoint = errorpoint;\n curvepass = true;\n errorval = 0;\n let t = (fitpoint - seqstart) / tl;\n let t1 = (1 - t) * (1 - t);\n let t2 = 2 * (1 - t) * t;\n let t3 = t * t;\n const cpx = (t1 * path.points[seqstart].x + t3 * path.points[seqend].x - path.points[fitpoint].x) / -t2;\n const cpy = (t1 * path.points[seqstart].y + t3 * path.points[seqend].y - path.points[fitpoint].y) / -t2;\n pcnt = seqstart + 1;\n while (pcnt !== seqend) {\n t = (pcnt - seqstart) / tl;\n t1 = (1 - t) * (1 - t);\n t2 = 2 * (1 - t) * t;\n t3 = t * t;\n px = t1 * path.points[seqstart].x + t2 * cpx + t3 * path.points[seqend].x;\n py = t1 * path.points[seqstart].y + t2 * cpy + t3 * path.points[seqend].y;\n dist2 = (path.points[pcnt].x - px) * (path.points[pcnt].x - px) + (path.points[pcnt].y - py) * (path.points[pcnt].y - py);\n if (dist2 > qtres)\n curvepass = false;\n if (dist2 > errorval) {\n errorpoint = pcnt;\n errorval = dist2;\n }\n pcnt = (pcnt + 1) % path.points.length;\n }\n if (curvepass)\n return [{ type: \"Q\", x1: path.points[seqstart].x, y1: path.points[seqstart].y, x2: cpx, y2: cpy, x3: path.points[seqend].x, y3: path.points[seqend].y }];\n const splitpoint = fitpoint;\n return fitSeq(path, ltres, qtres, seqstart, splitpoint).concat(fitSeq(path, ltres, qtres, splitpoint, seqend));\n }\n function boundingBoxIncludes(parentbbox, childbbox) {\n return parentbbox[0] < childbbox[0] && parentbbox[1] < childbbox[1] && parentbbox[2] > childbbox[2] && parentbbox[3] > childbbox[3];\n }\n function pointInPoly(p, pa) {\n let isin = false;\n for (let i = 0, j = pa.length - 1; i < pa.length; j = i++) {\n isin = pa[i].y > p.y !== pa[j].y > p.y && p.x < (pa[j].x - pa[i].x) * (p.y - pa[i].y) / (pa[j].y - pa[i].y) + pa[i].x ? !isin : isin;\n }\n return isin;\n }\n function getSvgString(tracedata, options) {\n const w = tracedata.width * options.scale;\n const h = tracedata.height * options.scale;\n let svgstr = ``;\n for (let lcnt = 0; lcnt < tracedata.layers.length; lcnt++) {\n for (let pcnt = 0; pcnt < tracedata.layers[lcnt].length; pcnt++) {\n if (!tracedata.layers[lcnt][pcnt].isholepath)\n svgstr += svgPathString(tracedata, lcnt, pcnt, options);\n }\n }\n svgstr += \"\";\n return svgstr;\n }\n\n function testRightAngle(path, idx1, idx2, idx3, idx4, idx5) {\n return path.points[idx3].x === path.points[idx1].x && path.points[idx3].x === path.points[idx2].x && path.points[idx3].y === path.points[idx4].y && path.points[idx3].y === path.points[idx5].y || path.points[idx3].y === path.points[idx1].y && path.points[idx3].y === path.points[idx2].y && path.points[idx3].x === path.points[idx4].x && path.points[idx3].x === path.points[idx5].x;\n }\n function pathScan(arr, pathomit) {\n const paths = [];\n let pacnt = 0;\n let pcnt = 0;\n let px = 0;\n let py = 0;\n const w = arr[0].length;\n const h = arr.length;\n let dir = 0;\n let pathfinished = true;\n let holepath = false;\n let lookuprow;\n for (let j = 0; j < h; j++) {\n for (let i = 0; i < w; i++) {\n if (arr[j][i] === 4 || arr[j][i] === 11) {\n px = i;\n py = j;\n paths[pacnt] = {};\n paths[pacnt].points = [];\n paths[pacnt].boundingbox = [px, py, px, py];\n paths[pacnt].holechildren = [];\n pathfinished = false;\n pcnt = 0;\n holepath = arr[j][i] === 11;\n dir = 1;\n while (!pathfinished) {\n paths[pacnt].points[pcnt] = {};\n paths[pacnt].points[pcnt].x = px - 1;\n paths[pacnt].points[pcnt].y = py - 1;\n paths[pacnt].points[pcnt].t = arr[py][px];\n if (px - 1 < paths[pacnt].boundingbox[0])\n paths[pacnt].boundingbox[0] = px - 1;\n if (px - 1 > paths[pacnt].boundingbox[2])\n paths[pacnt].boundingbox[2] = px - 1;\n if (py - 1 < paths[pacnt].boundingbox[1])\n paths[pacnt].boundingbox[1] = py - 1;\n if (py - 1 > paths[pacnt].boundingbox[3])\n paths[pacnt].boundingbox[3] = py - 1;\n lookuprow = PATHSCAN_COMBINED_LOOKUP[arr[py][px]][dir];\n arr[py][px] = lookuprow[0];\n dir = lookuprow[1];\n px += lookuprow[2];\n py += lookuprow[3];\n if (px - 1 === paths[pacnt].points[0].x && py - 1 === paths[pacnt].points[0].y) {\n pathfinished = true;\n if (paths[pacnt].points.length < pathomit) {\n paths.pop();\n } else {\n paths[pacnt].isholepath = !!holepath;\n if (holepath) {\n let parentidx = 0;\n let parentbbox = [-1, -1, w + 1, h + 1];\n for (let parentcnt = 0; parentcnt < pacnt; parentcnt++) {\n if (!paths[parentcnt].isholepath && boundingBoxIncludes(paths[parentcnt].boundingbox, paths[pacnt].boundingbox) && boundingBoxIncludes(parentbbox, paths[parentcnt].boundingbox) && pointInPoly(paths[pacnt].points[0], paths[parentcnt].points)) {\n parentidx = parentcnt;\n parentbbox = paths[parentcnt].boundingbox;\n }\n }\n paths[parentidx].holechildren.push(pacnt);\n }\n pacnt++;\n }\n }\n pcnt++;\n }\n }\n }\n }\n return paths;\n }\n function batchPathScan(layers, pathomit) {\n const bpaths = [];\n for (let k = 0; k < layers.length; k++)\n bpaths[k] = pathScan(layers[k], pathomit);\n return bpaths;\n }\n function tracePath(path, ltres, qtres) {\n let pcnt = 0;\n let segtype1;\n let segtype2;\n let seqend;\n const smp = {\n segments: [],\n boundingbox: path.boundingbox,\n holechildren: path.holechildren,\n isholepath: path.isholepath\n };\n while (pcnt < path.points.length) {\n segtype1 = path.points[pcnt].linesegment;\n segtype2 = -1;\n seqend = pcnt + 1;\n while ((path.points[seqend].linesegment === segtype1 || path.points[seqend].linesegment === segtype2 || segtype2 === -1) && seqend < path.points.length - 1) {\n if (path.points[seqend].linesegment !== segtype1 && segtype2 === -1)\n segtype2 = path.points[seqend].linesegment;\n seqend++;\n }\n if (seqend === path.points.length - 1)\n seqend = 0;\n smp.segments = smp.segments.concat(fitSeq(path, ltres, qtres, pcnt, seqend));\n if (seqend > 0)\n pcnt = seqend;\n else\n pcnt = path.points.length;\n }\n return smp;\n }\n function batchTracePaths(internodepaths, ltres, qtres) {\n const btracedpaths = [];\n for (let k = 0; k < internodepaths.length; k++)\n btracedpaths.push(tracePath(internodepaths[k], ltres, qtres));\n return btracedpaths;\n }\n\n function batchInterNodes(bpaths, options) {\n const binternodes = [];\n for (let k = 0; k < bpaths.length; k++)\n binternodes[k] = interNodes(bpaths[k], options);\n return binternodes;\n }\n function interNodes(paths, options) {\n const ins = [];\n let palen = 0;\n let nextidx = 0;\n let nextidx2 = 0;\n let previdx = 0;\n let previdx2 = 0;\n let pacnt;\n let pcnt;\n for (pacnt = 0; pacnt < paths.length; pacnt++) {\n ins[pacnt] = {};\n ins[pacnt].points = [];\n ins[pacnt].boundingbox = paths[pacnt].boundingbox;\n ins[pacnt].holechildren = paths[pacnt].holechildren;\n ins[pacnt].isholepath = paths[pacnt].isholepath;\n palen = paths[pacnt].points.length;\n for (pcnt = 0; pcnt < palen; pcnt++) {\n nextidx = (pcnt + 1) % palen;\n nextidx2 = (pcnt + 2) % palen;\n previdx = (pcnt - 1 + palen) % palen;\n previdx2 = (pcnt - 2 + palen) % palen;\n if (options.rightangleenhance && testRightAngle(paths[pacnt], previdx2, previdx, pcnt, nextidx, nextidx2)) {\n if (ins[pacnt].points.length > 0) {\n ins[pacnt].points[ins[pacnt].points.length - 1].linesegment = getDirection(ins[pacnt].points[ins[pacnt].points.length - 1].x, ins[pacnt].points[ins[pacnt].points.length - 1].y, paths[pacnt].points[pcnt].x, paths[pacnt].points[pcnt].y);\n }\n ins[pacnt].points.push({\n x: paths[pacnt].points[pcnt].x,\n y: paths[pacnt].points[pcnt].y,\n linesegment: getDirection(paths[pacnt].points[pcnt].x, paths[pacnt].points[pcnt].y, (paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2, (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2)\n });\n }\n ins[pacnt].points.push({\n x: (paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2,\n y: (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2,\n linesegment: getDirection((paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2, (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2, (paths[pacnt].points[nextidx].x + paths[pacnt].points[nextidx2].x) / 2, (paths[pacnt].points[nextidx].y + paths[pacnt].points[nextidx2].y) / 2)\n });\n }\n }\n return ins;\n }\n\n function batchTraceLayers(binternodes, ltres, qtres) {\n const btbis = [];\n for (let k = 0; k < binternodes.length; k++)\n btbis[k] = batchTracePaths(binternodes[k], ltres, qtres);\n return btbis;\n }\n function layering(ii) {\n const layers = [];\n let val = 0;\n const ah = ii.array.length;\n const aw = ii.array[0].length;\n let n1;\n let n2;\n let n3;\n let n4;\n let n5;\n let n6;\n let n7;\n let n8;\n let i;\n let j;\n let k;\n for (k = 0; k < ii.palette.length; k++) {\n layers[k] = [];\n for (j = 0; j < ah; j++) {\n layers[k][j] = [];\n for (i = 0; i < aw; i++)\n layers[k][j][i] = 0;\n }\n }\n for (j = 1; j < ah - 1; j++) {\n for (i = 1; i < aw - 1; i++) {\n val = ii.array[j][i];\n n1 = ii.array[j - 1][i - 1] === val ? 1 : 0;\n n2 = ii.array[j - 1][i] === val ? 1 : 0;\n n3 = ii.array[j - 1][i + 1] === val ? 1 : 0;\n n4 = ii.array[j][i - 1] === val ? 1 : 0;\n n5 = ii.array[j][i + 1] === val ? 1 : 0;\n n6 = ii.array[j + 1][i - 1] === val ? 1 : 0;\n n7 = ii.array[j + 1][i] === val ? 1 : 0;\n n8 = ii.array[j + 1][i + 1] === val ? 1 : 0;\n layers[val][j + 1][i + 1] = 1 + n5 * 2 + n8 * 4 + n7 * 8;\n if (!n4)\n layers[val][j + 1][i] = 0 + 2 + n7 * 4 + n6 * 8;\n if (!n2)\n layers[val][j][i + 1] = 0 + n3 * 2 + n5 * 4 + 8;\n if (!n1)\n layers[val][j][i] = 0 + n2 * 2 + 4 + n4 * 8;\n }\n }\n return layers;\n }\n function layeringStep(ii, cnum) {\n const layer = [];\n const ah = ii.array.length;\n const aw = ii.array[0].length;\n let i;\n let j;\n for (j = 0; j < ah; j++) {\n layer[j] = [];\n for (i = 0; i < aw; i++)\n layer[j][i] = 0;\n }\n for (j = 1; j < ah; j++) {\n for (i = 1; i < aw; i++) {\n layer[j][i] = (ii.array[j - 1][i - 1] === cnum ? 1 : 0) + (ii.array[j - 1][i] === cnum ? 2 : 0) + (ii.array[j][i - 1] === cnum ? 8 : 0) + (ii.array[j][i] === cnum ? 4 : 0);\n }\n }\n return layer;\n }\n function drawLayers(layers, palette, scale = 1, parentid) {\n let w, h, i, j;\n let div;\n if (parentid) {\n div = document.getElementById(parentid);\n if (!div) {\n div = document.createElement(\"div\");\n div.id = parentid;\n document.body.appendChild(div);\n }\n } else {\n div = document.createElement(\"div\");\n document.body.appendChild(div);\n }\n for (const layer of layers) {\n w = layer[0].length;\n h = layer.length;\n const canvas = document.createElement(\"canvas\");\n canvas.width = w * scale;\n canvas.height = h * scale;\n const context = canvas.getContext(\"2d\");\n for (j = 0; j < h; j++) {\n for (i = 0; i < w; i++) {\n context.fillStyle = toRgbaStr(palette[layer[j][i] % palette.length]);\n context.fillRect(i * scale, j * scale, scale, scale);\n }\n }\n div.appendChild(canvas);\n }\n }\n\n class ImageTracer {\n constructor() {\n this.versionnumber = VERSION_NUMBER;\n this.optionpresets = OPTION_PRESETS;\n }\n checkOptions(options) {\n if (options === void 0)\n return { ...this.optionpresets.default };\n if (typeof options === \"string\") {\n const presetName = options;\n const preset = this.optionpresets[presetName];\n return { ...this.optionpresets.default, ...preset || {} };\n }\n if (typeof options === \"object\") {\n return { ...this.optionpresets.default, ...options };\n }\n throw new Error(`Unknown Option Type: ${typeof options}`);\n }\n async imageToSVG(url, options) {\n options = this.checkOptions(options);\n const canvas = await this.loadImage(url, options);\n return this.imageDataToSVG(this.getImgdata(canvas), options);\n }\n getImgdata(canvas) {\n const context = canvas.getContext(\"2d\");\n return context.getImageData(0, 0, canvas.width, canvas.height);\n }\n loadImage(url, options) {\n return new Promise((resolve) => {\n const img = new Image();\n if (options && options.corsenabled)\n img.crossOrigin = \"Anonymous\";\n img.src = url;\n img.onload = function() {\n const canvas = document.createElement(\"canvas\");\n canvas.width = img.width;\n canvas.height = img.height;\n const context = canvas.getContext(\"2d\");\n context?.drawImage(img, 0, 0);\n resolve(canvas);\n };\n });\n }\n imageDataToSVG(imgd, options) {\n options = this.checkOptions(options);\n const td = this.imageDataToTracedata(imgd, options);\n return getSvgString(td, options);\n }\n async imageToTracedata(url, options) {\n options = this.checkOptions(options);\n const canvas = await this.loadImage(url, options);\n return this.imageDataToTracedata(this.getImgdata(canvas), options);\n }\n imageDataToTracedata(imgd, options) {\n options = this.checkOptions(options);\n let tracedata;\n const ii = colorQuantization(imgd, options);\n if (options.layering === 0) {\n tracedata = {\n layers: [],\n palette: ii.palette,\n width: ii.array[0].length - 2,\n height: ii.array.length - 2\n };\n for (let colornum = 0; colornum < ii.palette.length; colornum++) {\n const tracedlayer = batchTracePaths(interNodes(pathScan(layeringStep(ii, colornum), options.pathomit), options), options.ltres, options.qtres);\n tracedata.layers.push(tracedlayer);\n }\n } else {\n const ls = layering(ii);\n if (options.layercontainerid)\n drawLayers(ls, SPECPALETTE, options.scale, options.layercontainerid);\n const bps = batchPathScan(ls, options.pathomit);\n const bis = batchInterNodes(bps, options);\n tracedata = {\n layers: batchTraceLayers(bis, options.ltres, options.qtres),\n palette: ii.palette,\n width: imgd.width,\n height: imgd.height\n };\n }\n return tracedata;\n }\n appendSVGString(svgstr, parentid) {\n let div;\n if (parentid) {\n div = document.getElementById(parentid);\n if (!div) {\n div = document.createElement(\"div\");\n div.id = parentid;\n document.body.appendChild(div);\n }\n } else {\n div = document.createElement(\"div\");\n document.body.appendChild(div);\n }\n div.innerHTML += svgstr;\n }\n }\n const imageTracer = new ImageTracer();\n\n function getLocator(source, options) {\n if (options === void 0) { options = {}; }\n var offsetLine = options.offsetLine || 0;\n var offsetColumn = options.offsetColumn || 0;\n var originalLines = source.split('\\n');\n var start = 0;\n var lineRanges = originalLines.map(function (line, i) {\n var end = start + line.length + 1;\n var range = { start: start, end: end, line: i };\n start = end;\n return range;\n });\n var i = 0;\n function rangeContains(range, index) {\n return range.start <= index && index < range.end;\n }\n function getLocation(range, index) {\n return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };\n }\n function locate(search, startIndex) {\n if (typeof search === 'string') {\n search = source.indexOf(search, startIndex || 0);\n }\n var range = lineRanges[i];\n var d = search >= range.end ? 1 : -1;\n while (range) {\n if (rangeContains(range, search))\n return getLocation(range, search);\n i += d;\n range = lineRanges[i];\n }\n }\n return locate;\n }\n function locate(source, search, options) {\n if (typeof options === 'number') {\n throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');\n }\n return getLocator(source, options)(search, options && options.startIndex);\n }\n\n var validNameCharacters = /[a-zA-Z0-9:_-]/;\n var whitespace = /[\\s\\t\\r\\n]/;\n var quotemark = /['\"]/;\n\n function repeat(str, i) {\n \tvar result = '';\n \twhile (i--) { result += str; }\n \treturn result;\n }\n\n function parse$1(source) {\n \tvar header = '';\n \tvar stack = [];\n\n \tvar state = metadata;\n \tvar currentElement = null;\n \tvar root = null;\n\n \tfunction error(message) {\n \t\tvar ref = locate(source, i);\n \t\tvar line = ref.line;\n \t\tvar column = ref.column;\n \t\tvar before = source.slice(0, i);\n \t\tvar beforeLine = /(^|\\n).*$/.exec(before)[0].replace(/\\t/g, ' ');\n \t\tvar after = source.slice(i);\n \t\tvar afterLine = /.*(\\n|$)/.exec(after)[0];\n\n \t\tvar snippet = \"\" + beforeLine + afterLine + \"\\n\" + (repeat(' ', beforeLine.length)) + \"^\";\n\n \t\tthrow new Error(\n \t\t\t(message + \" (\" + line + \":\" + column + \"). If this is valid SVG, it's probably a bug in svg-parser. Please raise an issue at https://github.com/Rich-Harris/svg-parser/issues – thanks!\\n\\n\" + snippet)\n \t\t);\n \t}\n\n \tfunction metadata() {\n \t\twhile ((i < source.length && source[i] !== '<') || !validNameCharacters.test(source[i + 1])) {\n \t\t\theader += source[i++];\n \t\t}\n\n \t\treturn neutral();\n \t}\n\n \tfunction neutral() {\n \t\tvar text = '';\n \t\twhile (i < source.length && source[i] !== '<') { text += source[i++]; }\n\n \t\tif (/\\S/.test(text)) {\n \t\t\tcurrentElement.children.push({ type: 'text', value: text });\n \t\t}\n\n \t\tif (source[i] === '<') {\n \t\t\treturn tag;\n \t\t}\n\n \t\treturn neutral;\n \t}\n\n \tfunction tag() {\n \t\tvar char = source[i];\n\n \t\tif (char === '?') { return neutral; } // ') {\n \t\t\terror('Expected >');\n \t\t}\n\n \t\tif (!selfClosing) {\n \t\t\tcurrentElement = element;\n \t\t\tstack.push(element);\n \t\t}\n\n \t\treturn neutral;\n \t}\n\n \tfunction comment() {\n \t\tvar index = source.indexOf('-->', i);\n \t\tif (!~index) { error('expected -->'); }\n\n \t\ti = index + 2;\n \t\treturn neutral;\n \t}\n\n \tfunction cdata() {\n \t\tvar index = source.indexOf(']]>', i);\n \t\tif (!~index) { error('expected ]]>'); }\n\n \t\tcurrentElement.children.push(source.slice(i + 7, index));\n\n \t\ti = index + 2;\n \t\treturn neutral;\n \t}\n\n \tfunction closingTag() {\n \t\tvar tagName = getName();\n\n \t\tif (!tagName) { error('Expected tag name'); }\n\n \t\tif (tagName !== currentElement.tagName) {\n \t\t\terror((\"Expected closing tag to match opening tag <\" + (currentElement.tagName) + \">\"));\n \t\t}\n\n \t\tallowSpaces();\n\n \t\tif (source[i] !== '>') {\n \t\t\terror('Expected >');\n \t\t}\n\n \t\tstack.pop();\n \t\tcurrentElement = stack[stack.length - 1];\n\n \t\treturn neutral;\n \t}\n\n \tfunction getName() {\n \t\tvar name = '';\n \t\twhile (i < source.length && validNameCharacters.test(source[i])) { name += source[i++]; }\n\n \t\treturn name;\n \t}\n\n \tfunction getAttribute() {\n \t\tif (!whitespace.test(source[i])) { return null; }\n \t\tallowSpaces();\n\n \t\tvar name = getName();\n \t\tif (!name) { return null; }\n\n \t\tvar value = true;\n\n \t\tallowSpaces();\n \t\tif (source[i] === '=') {\n \t\t\ti += 1;\n \t\t\tallowSpaces();\n\n \t\t\tvalue = getAttributeValue();\n \t\t\tif (!isNaN(value) && value.trim() !== '') { value = +value; } // TODO whitelist numeric attributes?\n \t\t}\n\n \t\treturn { name: name, value: value };\n \t}\n\n \tfunction getAttributeValue() {\n \t\treturn quotemark.test(source[i]) ? getQuotedAttributeValue() : getUnquotedAttributeValue();\n \t}\n\n \tfunction getUnquotedAttributeValue() {\n \t\tvar value = '';\n \t\tdo {\n \t\t\tvar char = source[i];\n \t\t\tif (char === ' ' || char === '>' || char === '/') {\n \t\t\t\treturn value;\n \t\t\t}\n\n \t\t\tvalue += char;\n \t\t\ti += 1;\n \t\t} while (i < source.length);\n\n \t\treturn value;\n \t}\n\n \tfunction getQuotedAttributeValue() {\n \t\tvar quotemark = source[i++];\n\n \t\tvar value = '';\n \t\tvar escaped = false;\n\n \t\twhile (i < source.length) {\n \t\t\tvar char = source[i++];\n \t\t\tif (char === quotemark && !escaped) {\n \t\t\t\treturn value;\n \t\t\t}\n\n \t\t\tif (char === '\\\\' && !escaped) {\n \t\t\t\tescaped = true;\n \t\t\t}\n\n \t\t\tvalue += escaped ? (\"\\\\\" + char) : char;\n \t\t\tescaped = false;\n \t\t}\n \t}\n\n \tfunction allowSpaces() {\n \t\twhile (i < source.length && whitespace.test(source[i])) { i += 1; }\n \t}\n\n \tvar i = metadata.length;\n \twhile (i < source.length) {\n \t\tif (!state) { error('Unexpected character'); }\n \t\tstate = state();\n \t\ti += 1;\n \t}\n\n \tif (state !== neutral) {\n \t\terror('Unexpected end of input');\n \t}\n\n \tif (root.tagName === 'svg') { root.metadata = header; }\n \treturn {\n \t\ttype: 'root',\n \t\tchildren: [root]\n \t};\n }\n\n class SvgConverter {\n static overwriteSketchWithSvg(node, data) {\n const decover = new TextDecoder();\n node.paths.clear();\n const header = data.slice(0, 100);\n header.arrayBuffer().then(buffer => {\n const headerText = decover.decode(buffer);\n if (headerText.search(/JFIF/) !== -1 || headerText.search(/PNG/) !== -1) {\n // is raster\n const dataUrl = URL.createObjectURL(data);\n const options = {\n qtres: 0.1,\n pathomit: 16,\n numberofcolors: 2,\n };\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n imageTracer.imageToTracedata(dataUrl, options).then((trace) => {\n if (trace.palette && trace.palette.length > 1) {\n const pathParser = new PathHandler(node, SvgConverter.calculateScaleDivider([0, 0, trace.width, trace.height]), nodeManager);\n const paletteStrengths = trace.palette.map((color, idx) => ({\n idx,\n strength: getPaletteColorStrength(color),\n }));\n paletteStrengths.sort((a, b) => a.strength - b.strength);\n const bgIdx = paletteStrengths[0].idx;\n trace.layers.splice(bgIdx, 1);\n const primaryLayers = trace.layers.flat();\n const pathsCreated = [];\n // Convert layers to sketchPaths\n primaryLayers.forEach((layer, layerIndex) => {\n const newPaths = pathParser.parseTrace(layer.segments);\n const pathGroupKey = 'tracedPath' + layerIndex;\n pathsCreated[layerIndex] = newPaths;\n newPaths.forEach(path => {\n path.pathGroupKey = pathGroupKey;\n });\n node.paths.push(...newPaths);\n });\n // Convert layers to holes\n primaryLayers.forEach((layer, layerIndex) => {\n if (layer.holechildren) {\n layer.holechildren.forEach(holeLayerIdx => {\n const pathSet = pathsCreated[holeLayerIdx];\n if (pathSet) {\n pathSet.forEach(path => {\n path.holeForPathGroup = 'tracedPath' + layerIndex;\n });\n }\n });\n }\n });\n }\n });\n }\n else {\n data.text().then(svgText => {\n const parsedSVG = parse$1(svgText);\n SvgConverter.parseSvgRecursively(node, parsedSVG);\n });\n }\n });\n }\n static findSvgViewBox(svg) {\n for (let i = 0; i < svg.children.length; i++) {\n const child = svg.children[i];\n if (typeof child === 'string') {\n return undefined;\n }\n else if (child.tagName === 'svg' && 'properties' in child) {\n return getViewBoxFromSvgElement(child);\n }\n }\n function getViewBoxFromSvgElement(elem) {\n var _a, _b, _c;\n if (typeof ((_a = elem.properties) === null || _a === void 0 ? void 0 : _a.viewBox) === 'string' && elem.properties.viewBox) {\n return elem.properties.viewBox.split(' ').map(int => parseInt(int));\n }\n if (((_b = elem.properties) === null || _b === void 0 ? void 0 : _b.width) && ((_c = elem.properties) === null || _c === void 0 ? void 0 : _c.height)) {\n const width = elem.properties.width;\n const height = elem.properties.height;\n return [\n 0,\n 0,\n typeof width === 'string' ? parseInt(width) : width,\n typeof height === 'string' ? parseInt(height) : height,\n ];\n }\n }\n }\n static parseSvgRecursively(node, svg, viewBox) {\n if (!viewBox) {\n viewBox = SvgConverter.findSvgViewBox(svg) || [0, 0, 100, 100];\n }\n if (svg.children) {\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n for (let i = 0; i < svg.children.length; i++) {\n const child = svg.children[i];\n if (child.tagName === 'path' && child.properties) {\n const pathParser = new PathHandler(node, SvgConverter.calculateScaleDivider(viewBox), nodeManager);\n const newPaths = pathParser.parsePath(child.properties.d);\n node.paths.push(...newPaths);\n //call actual parser\n }\n else if (child.tagName === 'rect' && child.properties) {\n SvgConverter.createRectangle(node, child, viewBox);\n }\n else if (child.tagName === 'circle' && child.properties) {\n SvgConverter.createCircle(node, child, viewBox);\n }\n else if (child.tagName === 'polyline' && child.properties) {\n SvgConverter.createPolyLine(node, child, viewBox);\n }\n else if (child.tagName === 'line' && child.properties) {\n SvgConverter.createLine(node, child, viewBox);\n }\n else if (child.tagName === 'polygon' && child.properties) {\n SvgConverter.createPolyLine(node, child, viewBox, true);\n }\n SvgConverter.parseSvgRecursively(node, child, viewBox);\n nameGeneratedPaths(node);\n }\n }\n }\n static removeBackGroundOnConvertedSVG(children) {\n const parent = children[0];\n const newChildren = parent.children;\n const resultChildren = [];\n newChildren.forEach(child => {\n if (child && child.properties) {\n if ('opacity' in child.properties) {\n if (child.properties.opacity == 1) {\n resultChildren.push(child);\n }\n }\n }\n });\n newChildren.clear();\n resultChildren.forEach(child => {\n newChildren.push(child);\n });\n // if (svg.children) {\n // console.log(svg.children.length);\n // for (let i = 0; i < svg.children.length; i++) {\n // const child = svg.children[i] as ElementNode;\n // if (child.properties) {\n // if (child.properties.opacity) {\n // if (Number(child.properties.opacity) < 1) {\n // console.log('Not a valid path');\n // svg.children.remove(child);\n // } else {\n // console.log('valid path:', child);\n // }\n // }\n // }\n // this.removeBackGroundOnConvertedSVG(child);\n // }\n // }\n }\n // static projectSketchOnNormal(node: SketchNode) {\n // node.paths.forEach(path => {\n // path.controlPoints.forEach(point => {\n // if (node.normal === eAxis.y) {\n // point.position = new KbVector(point.position.x, 0, point.position.y);\n // point.direction = new KbVector(point.direction.x, 0, point.direction.y);\n // if (point.direction2) {\n // point.direction2 = new KbVector(point.direction2.x, 0, point.direction2.y);\n // }\n // } else if (node.normal === eAxis.x) {\n // point.position = new KbVector(0, point.position.y, point.position.x);\n // point.direction = new KbVector(0, point.direction.y, point.direction.x);\n // if (point.direction2) {\n // point.direction2 = new KbVector(0, point.direction2.y, point.direction2.x);\n // }\n // }\n // });\n // });\n // }\n static calculateScaleDivider(viewbox) {\n if (viewbox) {\n const width = viewbox[2];\n const height = viewbox[3];\n if (width > height) {\n return width;\n }\n else {\n return height;\n }\n }\n else {\n return 1;\n }\n }\n static addNewPath(node, pathType) {\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n const newPath = nodeManager.create(Token.SketchPath);\n if (newPath) {\n newPath.name = 'Path';\n newPath._expanded = true;\n if (pathType) {\n newPath.type = pathType;\n }\n node.paths.push(newPath);\n }\n return newPath;\n }\n static createRectangle(node, element, viewbox) {\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\n if (!element.properties) {\n return;\n }\n const x = element.properties.x / scaleDivider;\n const y = (element.properties.y / scaleDivider) * -1;\n const rx = element.properties.rx / scaleDivider;\n const ry = (element.properties.ry / scaleDivider) * -1;\n const width = element.properties.width / scaleDivider;\n const height = (element.properties.height / scaleDivider) * -1;\n let newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.points);\n if (rx && ry) {\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = projectOnNodeAxis(node, x, y + ry);\n newPath.controlPoints.push(newControlPoint);\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint2.position = projectOnNodeAxis(node, x, y + height - ry);\n newPath.controlPoints.push(newControlPoint2);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.quadraticBezier);\n const newControlPoint3 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint3.position = projectOnNodeAxis(node, x, y + height - ry);\n newControlPoint3.direction = projectOnNodeAxis(node, 0, ry);\n newPath.controlPoints.push(newControlPoint3);\n const newControlPoint4 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint4.position = projectOnNodeAxis(node, x + rx, y + height);\n newPath.controlPoints.push(newControlPoint4);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.points);\n const newControlPoint5 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint5.position = projectOnNodeAxis(node, x + rx, y + height);\n newPath.controlPoints.push(newControlPoint5);\n const newControlPoint6 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint6.position = projectOnNodeAxis(node, width + x - rx, y + height);\n newPath.controlPoints.push(newControlPoint6);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.quadraticBezier);\n const newControlPoint7 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint7.position = projectOnNodeAxis(node, width + x - rx, y + height);\n newControlPoint7.direction = projectOnNodeAxis(node, -ry, 0);\n newPath.controlPoints.push(newControlPoint7);\n const newControlPoint8 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint8.position = projectOnNodeAxis(node, width + x, y + height - ry);\n newPath.controlPoints.push(newControlPoint8);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.points);\n const newControlPoint9 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint9.position = projectOnNodeAxis(node, width + x, y + height - ry);\n newPath.controlPoints.push(newControlPoint9);\n const newControlPoint10 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint10.position = projectOnNodeAxis(node, width + x, y + ry);\n newPath.controlPoints.push(newControlPoint10);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.quadraticBezier);\n const newControlPoint11 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint11.position = projectOnNodeAxis(node, width + x, y + ry);\n newControlPoint11.direction = projectOnNodeAxis(node, 0, -ry);\n newPath.controlPoints.push(newControlPoint11);\n const newControlPoint12 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint12.position = projectOnNodeAxis(node, width + x - rx, y);\n newPath.controlPoints.push(newControlPoint12);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.points);\n const newControlPoint13 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint13.position = projectOnNodeAxis(node, width + x - rx, y);\n newPath.controlPoints.push(newControlPoint13);\n const newControlPoint14 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint14.position = projectOnNodeAxis(node, x + rx, y);\n newPath.controlPoints.push(newControlPoint14);\n newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.quadraticBezier);\n const newControlPoint15 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint15.position = projectOnNodeAxis(node, x + rx, y);\n newControlPoint15.direction = projectOnNodeAxis(node, ry, 0);\n newPath.controlPoints.push(newControlPoint15);\n const newControlPoint16 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint16.position = projectOnNodeAxis(node, x, y + ry);\n newPath.controlPoints.push(newControlPoint16);\n }\n else {\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = projectOnNodeAxis(node, x, y);\n newPath.controlPoints.push(newControlPoint);\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint2.position = projectOnNodeAxis(node, x, y + height);\n newPath.controlPoints.push(newControlPoint2);\n const newControlPoint3 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint3.position = projectOnNodeAxis(node, x + width, y + height);\n newPath.controlPoints.push(newControlPoint3);\n const newControlPoint4 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint4.position = projectOnNodeAxis(node, x + width, y);\n newPath.controlPoints.push(newControlPoint4);\n const newControlPoint5 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint5.position = projectOnNodeAxis(node, x, y);\n newPath.controlPoints.push(newControlPoint5);\n }\n }\n static createCircle(node, element, viewbox) {\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\n if (element.properties) {\n const cx = element.properties.cx / scaleDivider;\n const cy = (element.properties.cy / scaleDivider) * -1;\n const radius = element.properties.r / scaleDivider;\n const newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.centerRadiusCircle);\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = projectOnNodeAxis(node, cx, cy);\n newControlPoint.direction = new exports.KbVector(0, 0, 1);\n newPath.controlPoints.push(newControlPoint);\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint2.position = projectOnNodeAxis(node, cx + radius, cy);\n newPath.controlPoints.push(newControlPoint2);\n }\n }\n static createLine(node, element, viewbox) {\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\n if (element.properties) {\n const newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.points);\n const x1 = element.properties.x1 / scaleDivider;\n const y1 = (element.properties.y1 / scaleDivider) * -1;\n const x2 = element.properties.x2 / scaleDivider;\n const y2 = (element.properties.y2 / scaleDivider) * -1;\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = projectOnNodeAxis(node, x1, y1);\n newPath.controlPoints.push(newControlPoint);\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\n newControlPoint2.position = projectOnNodeAxis(node, x2, y2);\n newPath.controlPoints.push(newControlPoint2);\n }\n }\n static createPolyLine(node, element, viewbox, closePath = false) {\n const nodeManager = node._manager;\n if (!nodeManager) {\n throw Error('no node manager');\n }\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\n if (element.properties) {\n const newPath = SvgConverter.addNewPath(node, exports.eSketchPathType.points);\n const points = element.properties.points.replace(',', ' ').split(' ');\n for (let i = 0; i < points.length; i = i + 2) {\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(parseInt(points[i]) / scaleDivider, (parseInt(points[i + 1]) / scaleDivider) * -1, 0);\n newPath.controlPoints.push(newControlPoint);\n }\n if (closePath) {\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\n newControlPoint.position = new exports.KbVector(parseInt(points[0]) / scaleDivider, (parseInt(points[1]) / scaleDivider) * -1, 0);\n newPath.controlPoints.push(newControlPoint);\n }\n }\n }\n }\n function nameGeneratedPaths(node) {\n let counter = 0;\n node.paths.forEach(path => {\n if (counter > 0) {\n path.name = 'Path ' + counter.toString();\n }\n counter++;\n });\n }\n function getPaletteColorStrength(color) {\n const saturation = Math.max(color.r, color.g, color.b) - Math.min(color.r, color.g, color.b);\n return color.a * 255 + saturation;\n }\n\n class CompatibilityOptions$1 {\n }\n /**\n * Creates the VertexData for a Ribbon\n * @param options an object used to set the following optional parameters for the ribbon, required but can be empty\n * * pathArray array of paths, each of which an array of successive Vector3\n * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false\n * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false\n * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\n * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false\n * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional\n * * colors a linear array, of length 4 * number of vertices, of custom color values, optional\n * @returns the VertexData of the ribbon\n */\n function CreateRibbonVertexData$1(options) {\n let pathArray = options.pathArray;\n const closeArray = options.closeArray || false;\n const closePath = options.closePath || false;\n const invertUV = options.invertUV || false;\n const defaultOffset = Math.floor(pathArray[0].length / 2);\n let offset = options.offset || defaultOffset;\n offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const customUV = options.uvs;\n const customColors = options.colors;\n const positions = [];\n const indices = [];\n const normals = [];\n const uvs = [];\n const us = []; // us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id\n const vs = []; // vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutive paths from pathArray\n const uTotalDistance = []; // uTotalDistance[p] : total distance of path p\n const vTotalDistance = []; // vTotalDistance[i] : total distance between points i of first and last path from pathArray\n let minlg; // minimal length among all paths from pathArray\n const lg = []; // array of path lengths : nb of vertex per path\n const idx = []; // array of path indexes : index of each path (first vertex) in the total vertex number\n let p; // path iterator\n let i; // point iterator\n let j; // point iterator\n // if single path in pathArray\n if (pathArray.length < 2) {\n const ar1 = [];\n const ar2 = [];\n for (i = 0; i < pathArray[0].length - offset; i++) {\n ar1.push(pathArray[0][i]);\n ar2.push(pathArray[0][i + offset]);\n }\n pathArray = [ar1, ar2];\n }\n // positions and horizontal distances (u)\n let idc = 0;\n const closePathCorr = closePath ? 1 : 0; // the final index will be +1 if closePath\n const closeArrayCorr = closeArray ? 1 : 0;\n let path;\n let l;\n minlg = pathArray[0].length;\n let vectlg;\n let dist;\n for (p = 0; p < pathArray.length + closeArrayCorr; p++) {\n uTotalDistance[p] = 0;\n us[p] = [0];\n path = p === pathArray.length ? pathArray[0] : pathArray[p];\n l = path.length;\n minlg = minlg < l ? minlg : l;\n j = 0;\n while (j < l) {\n positions.push(path[j].x, path[j].y, path[j].z);\n if (j > 0) {\n vectlg = path[j].subtract(path[j - 1]).length();\n dist = vectlg + uTotalDistance[p];\n us[p].push(dist);\n uTotalDistance[p] = dist;\n }\n j++;\n }\n if (closePath) {\n // an extra hidden vertex is added in the \"positions\" array\n j--;\n positions.push(path[0].x, path[0].y, path[0].z);\n vectlg = path[j].subtract(path[0]).length();\n dist = vectlg + uTotalDistance[p];\n us[p].push(dist);\n uTotalDistance[p] = dist;\n }\n lg[p] = l + closePathCorr;\n idx[p] = idc;\n idc += l + closePathCorr;\n }\n // vertical distances (v)\n let path1;\n let path2;\n let vertex1 = null;\n let vertex2 = null;\n for (i = 0; i < minlg + closePathCorr; i++) {\n vTotalDistance[i] = 0;\n vs[i] = [0];\n for (p = 0; p < pathArray.length - 1 + closeArrayCorr; p++) {\n path1 = pathArray[p];\n path2 = p === pathArray.length - 1 ? pathArray[0] : pathArray[p + 1];\n if (i === minlg) {\n // closePath\n vertex1 = path1[0];\n vertex2 = path2[0];\n }\n else {\n vertex1 = path1[i];\n vertex2 = path2[i];\n }\n vectlg = vertex2.subtract(vertex1).length();\n dist = vectlg + vTotalDistance[i];\n vs[i].push(dist);\n vTotalDistance[i] = dist;\n }\n }\n // uvs\n let u;\n let v;\n if (customUV) {\n for (p = 0; p < customUV.length; p++) {\n uvs.push(customUV[p].x, CompatibilityOptions$1.useOpenGLOrientationForUV ? 1.0 - customUV[p].y : customUV[p].y);\n }\n }\n else {\n for (p = 0; p < pathArray.length + closeArrayCorr; p++) {\n for (i = 0; i < minlg + closePathCorr; i++) {\n u = uTotalDistance[p] != 0.0 ? us[p][i] / uTotalDistance[p] : 0.0;\n v = vTotalDistance[i] != 0.0 ? vs[i][p] / vTotalDistance[i] : 0.0;\n if (invertUV) {\n uvs.push(v, u);\n }\n else {\n uvs.push(u, CompatibilityOptions$1.useOpenGLOrientationForUV ? 1.0 - v : v);\n }\n }\n }\n }\n // indices\n p = 0; // path index\n let pi = 0; // positions array index\n let l1 = lg[p] - 1; // path1 length\n let l2 = lg[p + 1] - 1; // path2 length\n let min = l1 < l2 ? l1 : l2; // current path stop index\n let shft = idx[1] - idx[0]; // shift\n const path1nb = lg.length - 1; // number of path1 to iterate on\n while (pi <= min && p < path1nb) {\n // stay under min and don't go over next to last path\n // draw two triangles between path1 (p1) and path2 (p2) : (p1.pi, p2.pi, p1.pi+1) and (p2.pi+1, p1.pi+1, p2.pi) clockwise\n indices.push(pi, pi + shft, pi + 1);\n indices.push(pi + shft + 1, pi + 1, pi + shft);\n pi += 1;\n if (pi === min) {\n // if end of one of two consecutive paths reached, go to next existing path\n p++;\n shft = idx[p + 1] - idx[p];\n l1 = lg[p] - 1;\n l2 = lg[p + 1] - 1;\n pi = idx[p];\n min = l1 < l2 ? l1 + pi : l2 + pi;\n }\n }\n // normals\n VertexData.ComputeNormals(positions, indices, normals);\n if (closePath) {\n // update both the first and last vertex normals to their average value\n let indexFirst = 0;\n let indexLast = 0;\n for (p = 0; p < pathArray.length; p++) {\n indexFirst = idx[p] * 3;\n if (p + 1 < pathArray.length) {\n indexLast = (idx[p + 1] - 1) * 3;\n }\n else {\n indexLast = normals.length - 3;\n }\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\n const l = Math.sqrt(normals[indexFirst] * normals[indexFirst] +\n normals[indexFirst + 1] * normals[indexFirst + 1] +\n normals[indexFirst + 2] * normals[indexFirst + 2]);\n normals[indexFirst] /= l;\n normals[indexFirst + 1] /= l;\n normals[indexFirst + 2] /= l;\n normals[indexLast] = normals[indexFirst];\n normals[indexLast + 1] = normals[indexFirst + 1];\n normals[indexLast + 2] = normals[indexFirst + 2];\n }\n }\n if (closeArray) {\n let indexFirst = idx[0] * 3;\n let indexLast = idx[pathArray.length] * 3;\n for (i = 0; i < minlg + closePathCorr; i++) {\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\n const l = Math.sqrt(normals[indexFirst] * normals[indexFirst] +\n normals[indexFirst + 1] * normals[indexFirst + 1] +\n normals[indexFirst + 2] * normals[indexFirst + 2]);\n normals[indexFirst] /= l;\n normals[indexFirst + 1] /= l;\n normals[indexFirst + 2] /= l;\n normals[indexLast] = normals[indexFirst];\n normals[indexLast + 1] = normals[indexFirst + 1];\n normals[indexLast + 2] = normals[indexFirst + 2];\n indexFirst += 3;\n indexLast += 3;\n }\n }\n // sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Colors\n let colors = null;\n if (customColors) {\n colors = new Float32Array(customColors.length * 4);\n for (let c = 0; c < customColors.length; c++) {\n colors[c * 4] = customColors[c].r;\n colors[c * 4 + 1] = customColors[c].g;\n colors[c * 4 + 2] = customColors[c].b;\n colors[c * 4 + 3] = customColors[c].a;\n }\n }\n // Result\n const vertexData = new VertexData();\n const positions32 = new Float32Array(positions);\n const normals32 = new Float32Array(normals);\n const uvs32 = new Float32Array(uvs);\n vertexData.indices = indices;\n vertexData.positions = positions32;\n vertexData.normals = normals32;\n vertexData.uvs = uvs32;\n if (colors) {\n vertexData.set(colors, VertexBuffer.ColorKind);\n }\n if (closePath) {\n vertexData._idx = idx;\n }\n return vertexData;\n }\n /**\n * Creates a ribbon mesh. The ribbon is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters\n * * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry\n * * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array\n * * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array\n * * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path\n * * It's the offset to join the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11\n * * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#ribbon\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\n * * The parameter `uvs` is an optional flat array of `Vector2` to update/set each ribbon vertex with its own custom UV values instead of the computed ones\n * * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values\n * * Note that if you use the parameters `uvs` or `colors`, the passed arrays must be populated with the right number of elements, it is to say the number of ribbon vertices. Remember that if you set `closePath` to `true`, there's one extra vertex per path in the geometry\n * * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param scene defines the hosting scene\n * @returns the ribbon mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/ribbon_extra\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\n */\n function CreateMiteredRibbon(name, options, scene = null) {\n const pathArray = options.pathArray;\n const closeArray = options.closeArray;\n const closePath = options.closePath;\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.NO_CAP;\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n const instance = options.instance;\n const updatable = options.updatable;\n if (instance) {\n // existing ribbon instance update\n // positionFunction : ribbon case\n // only pathArray and sideOrientation parameters are taken into account for positions update\n const minimum = TmpVectors.Vector3[0].setAll(Number.MAX_VALUE);\n const maximum = TmpVectors.Vector3[1].setAll(-Number.MAX_VALUE);\n const positionFunction = (positions) => {\n let minlg = pathArray[0].length;\n const mesh = instance;\n let i = 0;\n const ns = mesh._originalBuilderSideOrientation === Mesh.DOUBLESIDE ? 2 : 1;\n for (let si = 1; si <= ns; ++si) {\n for (let p = 0; p < pathArray.length; ++p) {\n const path = pathArray[p];\n const l = path.length;\n minlg = minlg < l ? minlg : l;\n for (let j = 0; j < minlg; ++j) {\n const pathPoint = path[j];\n positions[i] = pathPoint.x;\n positions[i + 1] = pathPoint.y;\n positions[i + 2] = pathPoint.z;\n minimum.minimizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\n maximum.maximizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\n i += 3;\n }\n if (mesh._creationDataStorage && mesh._creationDataStorage.closePath) {\n const pathPoint = path[0];\n positions[i] = pathPoint.x;\n positions[i + 1] = pathPoint.y;\n positions[i + 2] = pathPoint.z;\n i += 3;\n }\n }\n }\n };\n const positions = instance.getVerticesData(VertexBuffer.PositionKind);\n positionFunction(positions);\n if (instance.hasBoundingInfo) {\n instance.getBoundingInfo().reConstruct(minimum, maximum, instance._worldMatrix);\n }\n else {\n instance.buildBoundingInfo(minimum, maximum, instance._worldMatrix);\n }\n instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\n if (options.colors) {\n const colors = instance.getVerticesData(VertexBuffer.ColorKind);\n for (let c = 0, colorIndex = 0; c < options.colors.length; c++, colorIndex += 4) {\n const color = options.colors[c];\n colors[colorIndex] = color.r;\n colors[colorIndex + 1] = color.g;\n colors[colorIndex + 2] = color.b;\n colors[colorIndex + 3] = color.a;\n }\n instance.updateVerticesData(VertexBuffer.ColorKind, colors, false, false);\n }\n if (options.uvs) {\n const uvs = instance.getVerticesData(VertexBuffer.UVKind);\n for (let i = 0; i < options.uvs.length; i++) {\n uvs[i * 2] = options.uvs[i].x;\n uvs[i * 2 + 1] = CompatibilityOptions$1.useOpenGLOrientationForUV\n ? 1.0 - options.uvs[i].y\n : options.uvs[i].y;\n }\n instance.updateVerticesData(VertexBuffer.UVKind, uvs, false, false);\n }\n if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {\n const indices = instance.getIndices();\n const normals = instance.getVerticesData(VertexBuffer.NormalKind);\n const params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;\n VertexData.ComputeNormals(positions, indices, normals, params);\n if (instance._creationDataStorage && instance._creationDataStorage.closePath) {\n let indexFirst = 0;\n let indexLast = 0;\n for (let p = 0; p < pathArray.length; p++) {\n indexFirst = instance._creationDataStorage.idx[p] * 3;\n if (p + 1 < pathArray.length) {\n indexLast = (instance._creationDataStorage.idx[p + 1] - 1) * 3;\n }\n else {\n indexLast = normals.length - 3;\n }\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\n normals[indexLast] = normals[indexFirst];\n normals[indexLast + 1] = normals[indexFirst + 1];\n normals[indexLast + 2] = normals[indexFirst + 2];\n }\n }\n if (!instance.areNormalsFrozen) {\n instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);\n }\n }\n return instance;\n }\n else {\n // new ribbon creation\n const ribbon = new Mesh(name, scene);\n ribbon._originalBuilderSideOrientation = sideOrientation;\n ribbon._creationDataStorage = new _CreationDataStorage();\n const vertexData = CreateRibbonVertexData$1(options);\n if (closePath) {\n ribbon._creationDataStorage.idx = vertexData._idx;\n }\n ribbon._creationDataStorage.closePath = closePath;\n ribbon._creationDataStorage.closeArray = closeArray;\n vertexData.applyToMesh(ribbon, updatable);\n createLineCaps(pathArray, cap, name, ribbon, vertexData);\n return ribbon;\n }\n }\n function createLineCaps(pathArray, cap, featureId, ribbon, vertexData) {\n const startCap = [];\n const endCap = [];\n let startCapVectors = [];\n let endCapVectors = [];\n const resultVectors = [];\n const resultCaps = [];\n pathArray.forEach(path => {\n if (path[0]) {\n const vector = path[0];\n startCapVectors.push(path[0]);\n startCap.push(vector.x, vector.y, vector.z);\n }\n if (path[path.length - 1]) {\n const vector = path[path.length - 1];\n endCapVectors.push(path[path.length - 1]);\n endCap.push(vector.x, vector.y, vector.z);\n }\n });\n //check to see if the handedness of the endCap is correct. Otherwise, flip it\n if (startCapVectors.length > 0) {\n const faceNormal = calculateFaceNormal(startCapVectors);\n const firstPath = pathArray[0];\n if (firstPath.length >= 2) {\n const firstPoint = firstPath[0];\n const secondPoint = firstPath[1];\n const sketchNativeNormal = secondPoint.subtract(firstPoint);\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\n if (Vector3.Dot(faceNormal, sketchNativeNormal) < 0) {\n startCapVectors = reverseHandednessOfPositions(startCapVectors);\n }\n }\n }\n //check to see if the handedness of the endCap is correct. Otherwise, flip it\n if (endCapVectors.length > 0) {\n const faceNormal = calculateFaceNormal(endCapVectors);\n const lastPath = pathArray[pathArray.length - 1];\n if (lastPath.length >= 2) {\n const lastPoint = lastPath[lastPath.length - 1];\n const secondLastPoint = lastPath[lastPath.length - 2];\n const sketchNativeNormal = lastPoint.subtract(secondLastPoint);\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\n if (Vector3.Dot(faceNormal, sketchNativeNormal) < 0) {\n endCapVectors = reverseHandednessOfPositions(endCapVectors);\n }\n }\n }\n if (cap === Mesh.CAP_START) {\n const startCapIndices = earcut$1(startCap, [], 3);\n resultCaps.push(startCapIndices);\n resultVectors.push(startCapVectors, []);\n }\n else if (cap === Mesh.CAP_END) {\n const endCapIndices = earcut$1(endCap, [], 3);\n resultCaps.push(endCapIndices);\n resultVectors.push([], endCapVectors);\n }\n else if (cap === Mesh.CAP_ALL) {\n const startCapIndices = earcut$1(startCap, [], 3);\n resultCaps.push(startCapIndices);\n const endCapIndices = earcut$1(endCap, [], 3);\n //offset the endCapIndices otherwise they are the same as the startCapIndices\n for (let i = 0; i < endCapIndices.length; i++) {\n endCapIndices[i] = endCapIndices[i] + startCapVectors.length;\n }\n resultCaps.push(endCapIndices);\n resultVectors.push(startCapVectors, endCapVectors);\n }\n const newVertexData = combineVertexDataWithCaps(vertexData, resultCaps, resultVectors);\n newVertexData.applyToMesh(ribbon, true);\n return resultCaps;\n }\n function combineVertexDataWithCaps(baseVertexData, capMeshIndices, capMeshPositions) {\n var _a, _b, _c, _d;\n const totalBasePositions = ((_a = baseVertexData.positions) === null || _a === void 0 ? void 0 : _a.length) || 0;\n const totalBaseNormals = ((_b = baseVertexData.normals) === null || _b === void 0 ? void 0 : _b.length) || 0;\n const totalBaseUvs = ((_c = baseVertexData.uvs) === null || _c === void 0 ? void 0 : _c.length) || 0;\n const totalBaseIndices = ((_d = baseVertexData.indices) === null || _d === void 0 ? void 0 : _d.length) || 0;\n const newPositions = [];\n const newNormals = [];\n const newUvs = [];\n const newIndices = [];\n const startCapPositions = capMeshPositions[0];\n const endCapPositions = capMeshPositions[1];\n capMeshIndices.forEach(meshIndices => {\n meshIndices.forEach(index => {\n const newIndex = index + totalBasePositions / 3;\n newIndices.push(newIndex);\n });\n });\n if (startCapPositions && startCapPositions.length !== 0) {\n const normal = calculateFaceNormal(startCapPositions);\n startCapPositions.forEach(position => {\n newPositions.push(position.x, position.y, position.z);\n newNormals.push(normal.x, normal.y, normal.z);\n });\n const generatedUvs = generateUvsForCaps(startCapPositions);\n newUvs.push(...generatedUvs);\n }\n if (endCapPositions && endCapPositions.length !== 0) {\n const normal = calculateFaceNormal(endCapPositions);\n endCapPositions.forEach(position => {\n newPositions.push(position.x, position.y, position.z);\n newNormals.push(normal.x, normal.y, normal.z);\n });\n const generatedUvs = generateUvsForCaps(endCapPositions);\n newUvs.push(...generatedUvs);\n }\n const newVertexData = new VertexData();\n newVertexData.positions = newPositions;\n newVertexData.normals = newNormals;\n newVertexData.indices = newIndices;\n const combinedPositionsArray = new Float32Array(totalBasePositions + newPositions.length);\n const combinedNormalsArray = new Float32Array(totalBaseNormals + newNormals.length);\n const combinedUvsArray = new Float32Array((combinedPositionsArray.length / 3) * 2);\n const combinedIndicesArray = new Uint16Array(totalBaseIndices + newIndices.length);\n if (baseVertexData.positions) {\n combinedPositionsArray.set(baseVertexData.positions);\n combinedPositionsArray.set(newPositions, totalBasePositions);\n baseVertexData.positions = combinedPositionsArray;\n }\n if (baseVertexData.normals) {\n combinedNormalsArray.set(baseVertexData.normals);\n combinedNormalsArray.set(newNormals, totalBaseNormals);\n baseVertexData.normals = combinedNormalsArray;\n }\n if (baseVertexData.uvs) {\n combinedUvsArray.set(baseVertexData.uvs);\n combinedUvsArray.set(newUvs, totalBaseUvs);\n baseVertexData.uvs = combinedUvsArray;\n }\n if (baseVertexData.indices) {\n combinedIndicesArray.set(baseVertexData.indices);\n combinedIndicesArray.set(newIndices, totalBaseIndices);\n baseVertexData.indices = combinedIndicesArray;\n }\n return baseVertexData;\n }\n function reverseHandednessOfPositions(positionsArray) {\n const reversedArray = [];\n positionsArray.forEach(position => {\n reversedArray.unshift(position);\n });\n return reversedArray;\n }\n function generateUvsForCaps(positions) {\n const newUvs = [];\n const operationVectors = findDistinctVectors(positions);\n if (operationVectors) {\n const vector1 = operationVectors[0];\n const vector2 = operationVectors[1];\n const vector3 = operationVectors[2];\n //xp1 is the capNormal\n if (vector1 && vector2 && vector3) {\n const xp1 = vector1.cross(vector2.subtract(vector3));\n const xp2 = vector1.subtract(vector2).cross(xp1);\n const normalizedXp3 = xp1.cross(xp2).normalize();\n const normalizedXp2 = xp2.normalize();\n positions.forEach(position => {\n const u = Vector3.Dot(position, normalizedXp2);\n const v = Vector3.Dot(position, normalizedXp3);\n newUvs.push(u, v);\n });\n }\n }\n else {\n positions.forEach(position => {\n newUvs.push(0, 0);\n });\n }\n return newUvs;\n }\n function findDistinctVectors(vectors) {\n let vector1 = Vector3.Zero();\n let vector2 = Vector3.Zero();\n let vector3 = Vector3.Zero();\n for (let i = 0; i < vectors.length; i++) {\n let isZeroVector = false;\n if (vectors[i].x === 0 && vectors[i].y === 0 && vectors[i].z === 0) {\n isZeroVector = true;\n }\n if (!isZeroVector) {\n vector1 = vectors[i];\n break;\n }\n }\n for (let i = 0; i < vectors.length; i++) {\n let isZeroVector = false;\n if (vectors[i].x === 0 && vectors[i].y === 0 && vectors[i].z === 0) {\n isZeroVector = true;\n }\n if (!isZeroVector && vectors[i] !== vector1) {\n vector2 = vectors[i];\n break;\n }\n }\n for (let i = 0; i < vectors.length; i++) {\n if (vectors[i] !== vector2 && vectors[i] !== vector1) {\n vector3 = vectors[i];\n break;\n }\n }\n return [vector1, vector2, vector3];\n }\n VertexData.CreateRibbon = CreateRibbonVertexData$1;\n Mesh.CreateRibbon = (name, pathArray, closeArray = false, closePath, offset, scene, updatable = false, sideOrientation, instance) => {\n return CreateMiteredRibbon(name, {\n pathArray: pathArray,\n closeArray: closeArray,\n closePath: closePath,\n offset: offset,\n updatable: updatable,\n sideOrientation: sideOrientation,\n instance: instance,\n }, scene);\n };\n\n //const capMap: Map = new Map();\n class SweepRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.SweepFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n var _a;\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n let parentMesh;\n if (feature._parent) {\n parentMesh = this.viewer.getRendererNode(feature._parent);\n }\n let pathPoints = [];\n let targetPathNode;\n let pathMesh;\n if (feature.path) {\n targetPathNode = (_a = feature._manager) === null || _a === void 0 ? void 0 : _a.getById(feature.path);\n }\n if (targetPathNode) {\n pathMesh = this.viewer.getRendererNode(targetPathNode);\n const pathVertexData = SubmeshVertexData.ExtractFromMesh(pathMesh);\n const { segments } = parseSketchGeometry(pathVertexData);\n if (segments.length > 0) {\n pathPoints = segments[0];\n }\n }\n if (parentMesh &&\n targetPathNode &&\n pathMesh &&\n newVertexData.positions &&\n newVertexData.positions.length > 0 &&\n pathPoints.length > 1) {\n const { segments } = parseSketchGeometry(newVertexData);\n const extrudedMeshes = [];\n for (let i = 0; i < segments.length; i++) {\n const shape = segments[i];\n // Transform the path and the profile sketch into world space so we can combine them without worrying about local transforms\n const pathTransform = pathMesh.computeWorldMatrix();\n const sketchTransform = parentMesh.computeWorldMatrix();\n for (let i = 0; i < pathPoints.length; i++) {\n Vector3.TransformCoordinatesToRef(pathPoints[i], pathTransform, pathPoints[i]);\n }\n for (let i = 0; i < shape.length; i++) {\n Vector3.TransformCoordinatesToRef(shape[i], sketchTransform, shape[i]);\n }\n // Determine the vector to use as the primary direction of the extrusion\n const pathPrimaryVector = Vector3.Zero();\n let j = 0;\n while (pathPrimaryVector.length() === 0) {\n j++;\n pathPrimaryVector.copyFrom(pathPoints[j]).subtractInPlace(pathPoints[0]);\n }\n // Calculate the matrix to move the sketch path primary direction to be perpindicular to the XY plane for consistent behavior\n const rotToZ = rotationToVector(new Vector3(0, 0, 1), pathPrimaryVector);\n const pathTransformToZ = new Matrix();\n const pathTransformToZInv = new Matrix();\n rotToZ.toRotationMatrix(pathTransformToZ);\n Matrix.Compose(Vector3.One(), Quaternion.Identity(), pathPoints[0].scale(-1)).multiplyToRef(pathTransformToZ, pathTransformToZ);\n pathTransformToZ.invertToRef(pathTransformToZInv);\n // Transform both the path and the extrusion shape with the same matrix so the\n // shape and the path are positioned the same as before in relation to each other\n // but oriented to be extruded out of the XY plane, in the Z direction\n for (let i = 0; i < pathPoints.length; i++) {\n Vector3.TransformCoordinatesToRef(pathPoints[i], pathTransformToZ, pathPoints[i]);\n }\n for (let i = 0; i < shape.length; i++) {\n Vector3.TransformCoordinatesToRef(shape[i], pathTransformToZ, shape[i]);\n // Project the extrude shape onto the XY plane so that it's perfecly perpindicular to the sweep path\n shape[i].set(shape[i].x, shape[i].y, 0);\n }\n const extrudeOptions = {\n shape,\n path: pathPoints,\n updatable: false,\n cap: Mesh.NO_CAP,\n closeShape: false,\n // firstNormal: sketchNormal, this property is added in a future version of babylon\n };\n if (feature.capEnd && feature.capStart) {\n extrudeOptions.cap = Mesh.CAP_ALL;\n extrudeOptions.closeShape = true;\n }\n else if (feature.capStart) {\n extrudeOptions.cap = Mesh.CAP_START;\n extrudeOptions.closeShape = true;\n }\n else if (feature.capEnd) {\n extrudeOptions.cap = Mesh.CAP_END;\n extrudeOptions.closeShape = true;\n }\n // Perform the extrusion of the shape defined along the XY plane, to the path oriented to coincide with the Z+ axis\n let extruded;\n if (feature.mitredExtrusion) {\n extrudeOptions.closeShape = false;\n extruded = this.mitredExtrude(feature._dynamicId, extrudeOptions, this.scene);\n }\n else {\n extruded = MeshBuilder.ExtrudeShape(feature._dynamicId, extrudeOptions, this.scene);\n }\n // Rotate the resulting extruded shape to match the orientation of the original shape profile\n sketchTransform.invert();\n pathTransformToZInv.multiplyToRef(sketchTransform, pathTransformToZInv);\n extruded.bakeTransformIntoVertices(pathTransformToZInv);\n extrudedMeshes.push(extruded);\n }\n const extrudedAll = Mesh.MergeMeshes(extrudedMeshes, true);\n if (extrudedAll) {\n applyExtrusion(newVertexData, extrudedAll, false);\n extrudedAll.dispose();\n }\n }\n return newVertexData;\n }\n update3dInternal() { }\n mitredExtrude(featureId, options, scene) {\n const shape = options.shape;\n const path = options.path;\n const closed = options.closeShape || false;\n const nbPoints = path.length;\n const line = Vector3.Zero();\n const nextLine = Vector3.Zero();\n let axisX = Vector3.Zero();\n let axisY = Vector3.Zero();\n let axisZ = Vector3.Zero();\n let nextAxisX = Vector3.Zero();\n let nextAxisY = Vector3.Zero();\n let nextAxisZ = Vector3.Zero();\n let startPoint = Vector3.Zero();\n const nextStartPoint = Vector3.Zero();\n const bisector = Vector3.Zero();\n let distance = 0;\n let ray;\n const allPaths = [];\n // Note that the sketch will always be rotated such that the profile is in the XY plane\n const up = Vector3.Up();\n for (let s = 0; s < shape.length; s++) {\n path[1].subtractToRef(path[0], line);\n axisZ = line.clone().normalize();\n axisX = Vector3.Cross(Vector3.Up(), axisZ).normalize();\n axisY = Vector3.Cross(axisZ, axisX);\n startPoint = path[0].add(axisX.scale(shape[s].x)).add(axisY.scale(shape[s].y));\n const ribbonPath = [startPoint.clone()];\n for (let p = 0; p < nbPoints - 2; p++) {\n path[p + 2].subtractToRef(path[p + 1], nextLine);\n nextAxisZ = nextLine.clone().normalize();\n nextAxisX = Vector3.Cross(up, nextAxisZ).normalize();\n nextAxisY = Vector3.Cross(nextAxisZ, nextAxisX);\n nextAxisZ.subtractToRef(axisZ, bisector);\n const planeParallel = Vector3.Cross(nextAxisZ, axisZ);\n const planeNormal = Vector3.Cross(planeParallel, bisector);\n const plane = Plane.FromPositionAndNormal(path[p + 1], planeNormal);\n ray = new Ray(startPoint, axisZ);\n distance = ray.intersectsPlane(plane) || 0;\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\n ribbonPath.push(nextStartPoint.clone());\n axisX = nextAxisX.clone();\n axisY = nextAxisY.clone();\n axisZ = nextAxisZ.clone();\n startPoint = nextStartPoint.clone();\n }\n // Last Point\n if (closed) {\n path[0].subtractToRef(path[nbPoints - 1], nextLine);\n nextAxisZ = nextLine.clone().normalize();\n nextAxisX = Vector3.Cross(up, nextAxisZ).normalize();\n nextAxisY = Vector3.Cross(nextAxisZ, nextAxisX);\n nextAxisZ.subtractToRef(axisZ, bisector);\n const closedPlaneParallel = Vector3.Cross(nextAxisZ, axisZ);\n const closedPlaneNormal = Vector3.Cross(closedPlaneParallel, bisector);\n const closedPlane = Plane.FromPositionAndNormal(path[nbPoints - 1], closedPlaneNormal);\n ray = new Ray(startPoint, axisZ);\n distance = ray.intersectsPlane(closedPlane) || 0;\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\n ribbonPath.push(nextStartPoint.clone());\n axisX = nextAxisX.clone();\n axisY = nextAxisY.clone();\n axisZ = nextAxisZ.clone();\n startPoint = nextStartPoint.clone();\n path[1].subtractToRef(path[0], nextLine);\n nextAxisZ = nextLine.clone().normalize();\n nextAxisX = Vector3.Cross(up, nextAxisZ).normalize();\n nextAxisY = Vector3.Cross(nextAxisZ, nextAxisX);\n nextAxisZ.subtractToRef(axisZ, bisector);\n const planeParallel = Vector3.Cross(nextAxisZ, axisZ);\n const planeNormal = Vector3.Cross(planeParallel, bisector);\n const plane = Plane.FromPositionAndNormal(path[0], planeNormal);\n ray = new Ray(startPoint, axisZ);\n distance = ray.intersectsPlane(plane) || 0;\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\n ribbonPath.shift();\n ribbonPath.unshift(nextStartPoint.clone());\n }\n else {\n const planeNormal = axisZ;\n const plane = Plane.FromPositionAndNormal(path[nbPoints - 1], planeNormal);\n ray = new Ray(startPoint, axisZ);\n const distance = ray.intersectsPlane(plane) || 0;\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\n ribbonPath.push(nextStartPoint.clone());\n }\n allPaths.push(ribbonPath);\n }\n const ribbon = CreateMiteredRibbon(featureId, {\n pathArray: allPaths,\n sideOrientation: Mesh.DOUBLESIDE,\n closeArray: false,\n closePath: false,\n cap: options.cap,\n }, scene);\n return ribbon;\n }\n }\n\n class TransformRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.TransformFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const parentMesh = feature._parent;\n if (parentMesh && newVertexData.positions && newVertexData.positions.length > 0) {\n const newMeshVertexPositions = newVertexData.positions;\n const indexCount = newMeshVertexPositions.length / 3;\n const pivot = parentMesh.pivot.toVec3();\n const vertexPosition = new Vector3();\n let scaleVector;\n if (!feature.scale.equal({ x: 1, y: 1, z: 1 })) {\n scaleVector = feature.scale.toVec3();\n }\n for (let i = 0; i < indexCount; i++) {\n if (pivot && scaleVector) {\n vertexPosition.copyFromFloats(newMeshVertexPositions[i * 3] - pivot.x, newMeshVertexPositions[i * 3 + 1] - pivot.y, newMeshVertexPositions[i * 3 + 2] - pivot.z);\n if (scaleVector) {\n vertexPosition.multiplyInPlace(scaleVector);\n }\n vertexPosition.addInPlace(pivot);\n newMeshVertexPositions[i * 3] = vertexPosition.x;\n newMeshVertexPositions[i * 3 + 1] = vertexPosition.y;\n newMeshVertexPositions[i * 3 + 2] = vertexPosition.z;\n }\n }\n }\n return newVertexData;\n }\n update3dInternal() { }\n }\n\n class WeldVerticesRenderer extends FeatureRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.WeldVerticesFeature;\n }\n updateMeshGeometry(feature, vertexData, vertexDataChanges) {\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\n const parentMesh = feature._parent;\n const indices = newVertexData.indices;\n let positions = newVertexData.positions;\n let normals = newVertexData.normals;\n let uvs = newVertexData.uvs;\n const positionAverage = [0, 0, 0];\n const normalsAverage = [0, 0, 0];\n const uvAverage = [0, 0];\n const selectedIndices = [];\n const selectedVertices = [];\n const selectedIndicesArray = [];\n const vertexVisited = [];\n const indicesResult = [];\n const submeshDataArray = [];\n if (parentMesh && newVertexData.positions && newVertexData.positions.length > 0) {\n if (newVertexData.positions) {\n positions = newVertexData.positions;\n }\n else if (vertexData.positions) {\n positions = Array.from(vertexData.positions);\n }\n else {\n positions = [];\n }\n if (newVertexData.normals) {\n normals = newVertexData.normals;\n }\n else if (vertexData.normals) {\n normals = Array.from(vertexData.normals);\n }\n if (newVertexData.uvs) {\n uvs = newVertexData.uvs;\n }\n else if (vertexData.uvs) {\n uvs = Array.from(vertexData.uvs);\n }\n if (feature.vertexIndices && feature.vertexIndices.length > 0) {\n //creating sparse array to see which vertices are selected\n for (let i = 0; i < feature.vertexIndices.length; i++) {\n selectedIndicesArray[feature.vertexIndices[i]] = true;\n }\n if (indices) {\n //Looping through indices and checking which indices are touched by the selected vertices\n for (let j = 0; j < (indices === null || indices === void 0 ? void 0 : indices.length); j++) {\n if (selectedIndicesArray[indices[j]]) {\n selectedIndices.push(j);\n if (!vertexVisited[indices[j]]) {\n selectedVertices.push(j);\n vertexVisited[indices[j]] = true;\n }\n }\n }\n }\n //averaging all selected positions of the vertex\n for (let i = 0; i < selectedVertices.length; i++) {\n if (indices) {\n const vertex = indices[selectedVertices[i]];\n for (let j = 0; j < 3; j++) {\n positionAverage[j] = positionAverage[j] + positions[vertex * 3 + j];\n if (normals) {\n normalsAverage[j] = normalsAverage[j] + normals[vertex * 3 + j];\n }\n if (j != 2 && uvs) {\n uvAverage[j] = uvAverage[j] + uvs[vertex * 2 + j];\n }\n }\n }\n }\n for (let i = 0; i < 3; i++) {\n positionAverage[i] = positionAverage[i] / selectedVertices.length;\n normalsAverage[i] = normalsAverage[i] / selectedVertices.length;\n if (i != 2) {\n uvAverage[i] = uvAverage[i] / selectedVertices.length;\n }\n }\n //setting one vertex to calculated average position\n if (indices) {\n const targetIndex = indices[selectedVertices[0]];\n for (let i = 0; i < 3; i++) {\n positions[targetIndex * 3 + i] = positionAverage[i];\n if (normals) {\n normals[targetIndex * 3 + i] = normalsAverage[i];\n }\n if (i != 2 && uvs) {\n uvs[targetIndex * 2 + i] = uvAverage[i];\n }\n }\n //setting all selectedIndices to targetIndex with new position\n for (let i = 0; i < selectedIndices.length; i++) {\n indices[selectedIndices[i]] = targetIndex;\n }\n //looping through indices and pruning out polygons that make up invalid geometry\n for (let i = 0; i < indices.length; i = i + 3) {\n if (indices[i] != indices[i + 1] &&\n indices[i] != indices[i + 2] &&\n indices[i + 1] != indices[i + 2]) {\n indicesResult.push(indices[i]);\n indicesResult.push(indices[i + 1]);\n indicesResult.push(indices[i + 2]);\n }\n }\n //handling submesh data\n if (vertexData.submeshData) {\n for (let i = 0; i < vertexData.submeshData.length; i++) {\n const submeshData = vertexData.submeshData[i];\n submeshData.indexCount = indicesResult.length;\n submeshDataArray[i] = submeshData;\n }\n }\n }\n }\n newVertexData.positions = positions;\n newVertexData.indices = indicesResult;\n newVertexData.uvs = uvs;\n newVertexData.normals = normals;\n newVertexData.submeshData = submeshDataArray;\n }\n return newVertexData;\n }\n update3dInternal() { }\n }\n\n class FeatureStackRenderer extends Renderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene);\n this.rendererManager = rendererManager;\n this.queuedGeometryToReset = new Map();\n this.queuedFeaturesToProcess = new Map(); // index of feature to start recalculation at\n this.processedFeatures = new Map();\n this.featureOrder = new Map();\n this.renderers = new Map();\n this.modelToken = Token.Feature;\n const moveVertices = new MoveVerticesRenderer(viewer, scene);\n this.renderers.set(Token.MoveVerticesFeature, moveVertices);\n const weldVertices = new WeldVerticesRenderer(viewer, scene);\n this.renderers.set(Token.WeldVerticesFeature, weldVertices);\n const displacementMap = new DisplacementMapRenderer(viewer, scene);\n this.renderers.set(Token.DisplacementMapFeature, displacementMap);\n const uvMaps = new UvMapRenderer(viewer, scene);\n this.renderers.set(Token.UvMapFeature, uvMaps);\n const submeshes = new SubmeshRenderer(viewer, scene, rendererManager);\n this.renderers.set(Token.SubmeshFeature, submeshes);\n const linearPatterns = new LinearPatternRenderer(viewer, scene);\n this.renderers.set(Token.LinearPatternFeature, linearPatterns);\n const circularPatterns = new CircularPatternRenderer(viewer, scene);\n this.renderers.set(Token.CircularPatternFeature, circularPatterns);\n const joinGeometry = new JoinGeometryRenderer(viewer, scene);\n this.renderers.set(Token.JoinGeometryFeature, joinGeometry);\n const deleteFaces = new DeleteFacesRenderer(viewer, scene);\n this.renderers.set(Token.DeleteFacesFeature, deleteFaces);\n const normalSmoothing = new NormalSmoothingRenderer(viewer, scene);\n this.renderers.set(Token.NormalSmoothingFeature, normalSmoothing);\n const slice = new SliceFeatureRenderer(viewer, scene);\n this.renderers.set(Token.SliceFeature, slice);\n const mirror = new MirrorFeatureRenderer(viewer, scene);\n this.renderers.set(Token.MirrorFeature, mirror);\n const transform = new TransformRenderer(viewer, scene);\n this.renderers.set(Token.TransformFeature, transform);\n const extrude = new ExtrudeRenderer(viewer, scene);\n this.renderers.set(Token.ExtrudeFeature, extrude);\n const sweep = new SweepRenderer(viewer, scene);\n this.renderers.set(Token.SweepFeature, sweep);\n }\n forceRebuildGeometry(meshNode, vertexData) {\n if (!this.processedFeatures.has(meshNode._dynamicId)) {\n if (vertexData) {\n this.applyNewVertexData(meshNode, {}, vertexData);\n }\n return;\n }\n if (!vertexData) {\n vertexData = this.rendererManager.mesh.rebuildBaseGeometry(meshNode);\n }\n this.queuedGeometryToReset.set(meshNode._dynamicId, vertexData);\n const allChanges = new Set(meshNode.features.map((_, i) => i));\n this.queuedFeaturesToProcess.set(meshNode, allChanges);\n const movedIndex = this.getMovedFeatureIndex(meshNode);\n this.updateFeatureOrder(meshNode);\n if (movedIndex !== undefined && movedIndex >= 0) {\n this.recursivelyUpdateFeatureVisibility([meshNode.features[movedIndex]], meshNode.features, []);\n }\n this.update3dGeometry(0, meshNode);\n this.renderers.forEach(renderer => {\n renderer.clearCache(meshNode.features);\n });\n }\n resetMeshGeometry(meshNode, dataTypes, vertexData, hasFeatureToUpdate = false) {\n var _a;\n if (!vertexData) {\n vertexData = this.rendererManager.mesh.rebuildBaseGeometry(meshNode);\n }\n if (vertexData) {\n let newGeometry;\n if (!dataTypes) {\n newGeometry = vertexData;\n }\n else {\n // If the feature that changed affects aspects of a geometry, reset those aspects so we can recalculate them with\n // this or any other features that affected that aspect\n newGeometry = this.queuedGeometryToReset.get(meshNode._dynamicId) || {};\n // Null means that the vertex data specifically doesn't have those geometries, so they will be cleared\n if (!newGeometry.positions && hasChange(dataTypes, exports.eMeshChangeTypes.VertexPositions)) {\n newGeometry.positions = vertexData.positions || null;\n }\n if (!newGeometry.normals && hasChange(dataTypes, exports.eMeshChangeTypes.VertexNormals)) {\n newGeometry.normals = vertexData.normals || null;\n }\n if (!newGeometry.uvs && hasChange(dataTypes, exports.eMeshChangeTypes.VertexUvs)) {\n newGeometry.uvs = vertexData.uvs || null;\n }\n if (!newGeometry.indices && hasChange(dataTypes, exports.eMeshChangeTypes.VertexIndices)) {\n newGeometry.indices = vertexData.indices || null;\n }\n if (!newGeometry.submeshData && hasChange(dataTypes, exports.eMeshChangeTypes.Submeshes)) {\n newGeometry.submeshData = vertexData.submeshData || null;\n }\n }\n this.queuedGeometryToReset.set(meshNode._dynamicId, newGeometry);\n // If a feature affects a geometry element that is being reset, then it will need to be recalculated\n for (let i = 0; i < meshNode.features.length; i++) {\n const feature = meshNode.features[i];\n // If this geometry hasn't been flagged for recalculation, see if it needs to be\n if (!((_a = this.queuedFeaturesToProcess.get(meshNode)) === null || _a === void 0 ? void 0 : _a.has(i)) &&\n feature.affects &&\n featureIsAffected(feature.affects, newGeometry)) {\n hasFeatureToUpdate = true;\n this.queueGeometryUpdate(meshNode, i);\n this.resetMeshGeometry(meshNode, feature.affects, vertexData, hasFeatureToUpdate);\n }\n }\n // If there are no features to be recalculated but we need to reset some mesh geometry, then do that directly.\n if (!hasFeatureToUpdate && Object.getOwnPropertyNames(newGeometry).length > 0) {\n const existingVertexData = this.rendererManager.mesh.getMeshGeometry(meshNode) || vertexData;\n this.queuedGeometryToReset.delete(meshNode._dynamicId);\n this.applyNewVertexData(meshNode, newGeometry, existingVertexData);\n }\n }\n this.updateFeatureOrder(meshNode);\n }\n transformChanged(meshNode) {\n // If the transform on a mesh changes, any features that depend on the transform need to be updated\n for (let i = 0; i < meshNode.features.length; i++) {\n const feature = meshNode.features[i];\n if (feature.affectedBy && feature.affectedBy.has(exports.eMeshChangeTypes.Transform)) {\n this.queueGeometryUpdate(meshNode, i);\n }\n }\n }\n queueGeometryUpdate(meshNode, index) {\n let currentChanges = this.queuedFeaturesToProcess.get(meshNode);\n if (!currentChanges) {\n currentChanges = new Set();\n this.queuedFeaturesToProcess.set(meshNode, currentChanges);\n }\n currentChanges.add(index === undefined ? 0 : index);\n }\n update3dInternal(feature) {\n if (isTrackedClass(feature)) {\n if (!feature.enabled || feature._suppressed) {\n if (feature.changes.has('enabled') || feature.changes.has('_suppressed')) {\n this.delete3d(feature, true);\n }\n return;\n }\n const index = this.getFeatureIndexOnParent(feature);\n if (index > -1) {\n this.queueGeometryUpdate(feature._parent, index);\n }\n // Process all of the feature's non-geometry effects\n const renderer = this.renderers.get(Token.withKey(feature.$type));\n if (!renderer) {\n throw Error('no renderer for feature');\n }\n renderer.update3d(feature);\n }\n }\n update3dGeometry(renderStartTime = 0, node) {\n if (!node) {\n for (const node of this.queuedFeaturesToProcess.keys()) {\n if (node instanceof exports.MeshNode) {\n this.update3dGeometry(renderStartTime || performance.now(), node);\n }\n }\n return;\n }\n if (this.queuedFeaturesToProcess.has(node) && (!(node instanceof exports.CustomMeshNode) || node.geometryLoaded)) {\n const queuedFeatureToProcess = this.queuedFeaturesToProcess.get(node);\n const startFeatureIndex = Math.min(...Array.from(queuedFeatureToProcess.values()));\n // There is a known issue here where the VertexData.ExtractFromMesh function does not contain the updated vertices from mesh.updateVerticesData yet.\n // There is probably some kind of cache that is not updated if VertexData.ExtractFromMesh runs in the same frame\n let vertexDataCurrent = this.rendererManager.mesh.getMeshGeometry(node);\n const vertexDataNew = this.queuedGeometryToReset.has(node._dynamicId)\n ? this.queuedGeometryToReset.get(node._dynamicId)\n : {};\n // If the whole mesh is being reset, it may be a new mesh without geometry, so we can use the entire vertexDataNew.\n // If the mesh renderer asks the feature renderer for updates, it will not apply the geometry on its own so we have to make sure it happens here.\n // This is done to prevent applying geometry to the mesh multiple times, which is expensive for very large geometry.\n if (!vertexDataCurrent && vertexDataNew instanceof SubmeshVertexData) {\n vertexDataCurrent = vertexDataNew.shallowClone();\n }\n if (!vertexDataCurrent) {\n this.queuedFeaturesToProcess.delete(node);\n this.queuedGeometryToReset.delete(node._dynamicId);\n return;\n }\n for (let i = startFeatureIndex; i < node.features.length; i++) {\n const renderTime = performance.now() - renderStartTime;\n if (renderTime > this.rendererManager.maxRenderTime) {\n // store the progress of this feature stack to continue processing next frame\n console.warn(`Feature processing time exceeded ${renderTime}ms, skipping ${this.queuedFeaturesToProcess.size} features this frame`);\n queuedFeatureToProcess.clear();\n queuedFeatureToProcess.add(i);\n this.queuedGeometryToReset.set(node._dynamicId, vertexDataNew);\n return;\n }\n const feature = node.features[i];\n const renderer = this.renderers.get(Token.withKey(feature.$type));\n if (!renderer) {\n throw Error('no renderer for feature');\n }\n if (!feature.enabled || feature._suppressed) {\n // If the feature is not enabled, then we don't process it, but we still want to update the feature's geometry cache\n // Otherwise when the feature is enabled later it might not have the right data.\n renderer.updateMeshGeometryCache(feature, vertexDataCurrent, vertexDataNew);\n continue;\n }\n // Always process the features that were modified\n let processThisFeature = queuedFeatureToProcess.has(i);\n // Figure out if a property this feature is affected by was modified this cycle\n if (!processThisFeature && feature.affectedBy) {\n processThisFeature = featureIsAffected(feature.affectedBy, vertexDataNew);\n }\n if (isTrackedClass(feature)) {\n if (processThisFeature) {\n // Process all of the features geometry effects\n const resultVertexData = renderer.updateMeshGeometry(feature, vertexDataCurrent, vertexDataNew);\n if (feature.affects) {\n feature.affects.forEach(affects => {\n if (affects === exports.eMeshChangeTypes.VertexPositions) {\n vertexDataNew.positions = resultVertexData.positions || null;\n }\n if (affects === exports.eMeshChangeTypes.VertexNormals) {\n vertexDataNew.normals = resultVertexData.normals || null;\n }\n if (affects === exports.eMeshChangeTypes.VertexUvs) {\n vertexDataNew.uvs = resultVertexData.uvs || null;\n }\n if (affects === exports.eMeshChangeTypes.VertexIndices) {\n vertexDataNew.indices = resultVertexData.indices || null;\n }\n if (affects === exports.eMeshChangeTypes.Submeshes) {\n vertexDataNew.submeshData = resultVertexData.submeshData || null;\n }\n });\n }\n }\n }\n }\n if (vertexDataNew.submeshData) {\n if (!vertexDataCurrent.positions) {\n throw Error('Invalid geometry: positions is null');\n }\n const submeshData = vertexDataNew.submeshData.filter(s => s.materialIndex !== 0);\n const baseSubmeshes = calculateBaseSubmeshes(vertexDataCurrent, vertexDataNew, submeshData);\n const verticesCount = (vertexDataNew.positions || vertexDataCurrent.positions).length / 3;\n submeshData.unshift(...baseSubmeshes.map(bs => ({\n materialIndex: 0,\n verticesStart: 0,\n verticesCount: verticesCount,\n indexStart: bs.indexStart,\n indexCount: bs.indexCount,\n })));\n vertexDataNew.submeshData = submeshData;\n }\n if (Object.getOwnPropertyNames(vertexDataNew).length > 0) {\n this.applyNewVertexData(node, vertexDataNew, vertexDataCurrent);\n }\n }\n this.queuedFeaturesToProcess.delete(node);\n this.queuedGeometryToReset.delete(node._dynamicId);\n this.processedFeatures.set(node._dynamicId, true);\n }\n getMovedFeatureIndex(mesh) {\n const oldArray = this.featureOrder.get(mesh._dynamicId);\n if (oldArray) {\n if (oldArray.length !== mesh.features.length) {\n return -1;\n }\n for (let i = 0; i < oldArray.length; i++) {\n const newArrayId = mesh.features[i]._dynamicId;\n if (oldArray[i] !== newArrayId) {\n return i;\n }\n }\n }\n else {\n return -1;\n }\n }\n updateFeatureOrder(mesh) {\n const features = [];\n mesh.features.forEach(feature => {\n features.push(feature._dynamicId);\n });\n this.featureOrder.set(mesh._dynamicId, features);\n }\n recursivelyUpdateFeatureVisibility(affectedFeatures, features, disabledFeatures) {\n if (affectedFeatures.length === 0) {\n disabledFeatures.forEach(feature => {\n console.warn('The feature named', feature.name, 'got disabled due to a possible breaking change in the feature stack.');\n });\n return;\n }\n const newAffectedFeatures = [];\n affectedFeatures.forEach(affectedFeature => {\n var _a;\n const featureIndex = getFeatureIndex(affectedFeature, features);\n if (featureIndex >= 0) {\n for (let i = featureIndex; i < features.length; i++) {\n const feature = features[i];\n if (feature.enabled) {\n (_a = affectedFeature.affects) === null || _a === void 0 ? void 0 : _a.forEach(affector => {\n if (feature.dependsOn && feature.dependsOn.has(affector)) {\n feature.enabled = false;\n disabledFeatures.push(feature);\n feature._disableFeatureStackChange = true;\n newAffectedFeatures.push(feature);\n }\n });\n }\n }\n }\n });\n this.recursivelyUpdateFeatureVisibility(newAffectedFeatures, features, disabledFeatures);\n function getFeatureIndex(feature, features) {\n for (let i = 0; i < features.length; i++) {\n if (features[i] === feature) {\n return i;\n }\n }\n return -1;\n }\n }\n applyNewVertexData(node, vertexDataNew, vertexDataCurrent) {\n const mesh = this.viewer.getRendererNode(node);\n SubmeshVertexData.ExtendToRef(vertexDataNew, vertexDataCurrent);\n const invalid = verifyGeometry(vertexDataCurrent);\n if (invalid) {\n console.error(`Invalid or corrupted geometry output after feature processing in mesh ${node.name}. The ${invalid} are invalid.`);\n }\n else {\n vertexDataCurrent.applyToMesh(mesh);\n node._polygonCount = mesh.getTotalIndices() / 3;\n node._verticesCount = mesh.getTotalVertices();\n this.viewer.polygonTracker.next();\n this.viewer.warningTracker.next();\n }\n this.rendererManager.mesh.setRenderModeOnMesh(mesh, node._rootScene);\n this.viewer.bbCache.invalidate(node);\n }\n delete3d(feature, preserveCache) {\n const meshNode = feature._parent;\n if (meshNode && feature.affects) {\n this.resetMeshGeometry(meshNode, feature.affects);\n }\n const renderer = this.renderers.get(Token.withKey(feature.$type));\n if (!renderer) {\n throw Error('no renderer for feature');\n }\n renderer.delete3d(feature, preserveCache);\n }\n dispose() {\n this.queuedFeaturesToProcess.clear();\n this.renderers.forEach(renderer => renderer.dispose());\n super.dispose();\n }\n getFeatureIndexOnParent(feature) {\n if (feature._parent) {\n const index = feature._parent.features.findIndex(f => f._dynamicId === feature._dynamicId);\n if (index > -1) {\n return index;\n }\n }\n return -1;\n }\n }\n function calculateBaseSubmeshes(vertexDataCurrent, vertexDataNew, submeshData) {\n submeshData.sort((a, b) => a.indexStart - b.indexStart);\n const indicesCount = (vertexDataNew.indices || vertexDataCurrent.indices).length;\n const baseSubmeshes = [\n {\n indexStart: 0,\n indexCount: indicesCount,\n },\n ];\n submeshData.forEach(submesh => {\n const lastSubmesh = baseSubmeshes[baseSubmeshes.length - 1];\n if (lastSubmesh) {\n if (submesh.indexStart <= lastSubmesh.indexStart &&\n submesh.indexStart + submesh.indexCount > lastSubmesh.indexStart) {\n lastSubmesh.indexStart = submesh.indexStart + submesh.indexCount;\n lastSubmesh.indexCount = indicesCount - lastSubmesh.indexStart;\n if (lastSubmesh.indexCount <= 0) {\n baseSubmeshes.splice(-1, 1);\n }\n }\n else if (submesh.indexStart > lastSubmesh.indexStart) {\n lastSubmesh.indexCount = submesh.indexStart - lastSubmesh.indexStart;\n const remainingIndexCount = indicesCount - (submesh.indexStart + submesh.indexCount);\n if (remainingIndexCount > 0) {\n baseSubmeshes.push({\n indexStart: submesh.indexStart + submesh.indexCount,\n indexCount: remainingIndexCount,\n });\n }\n }\n }\n });\n return baseSubmeshes;\n }\n function featureIsAffected(affected, vertexDataNew) {\n let result = false;\n affected.forEach(affectedBy => {\n if (affectedBy === exports.eMeshChangeTypes.VertexPositions) {\n if (vertexDataNew.positions) {\n result = true; // Process the feature if a property it's affected by was changed this cycle\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.VertexNormals) {\n if (vertexDataNew.normals) {\n result = true; // Process the feature if a property it's affected by was changed this cycle\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.VertexUvs) {\n if (vertexDataNew.uvs) {\n result = true; // See above\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.VertexIndices) {\n if (vertexDataNew.indices) {\n result = true; // See above\n }\n }\n if (affectedBy === exports.eMeshChangeTypes.Submeshes) {\n if (vertexDataNew.submeshData) {\n result = true; // See above\n }\n }\n });\n return result;\n }\n function hasChange(set, changeType) {\n return set.has(changeType);\n }\n\n const getMeshName = {\n handles: (dynamicId) => `${dynamicId}_handles`,\n handleBar: (dynamicId) => `${dynamicId}_handleBar`,\n directionHandle1: (dynamicId) => `${dynamicId}_directionHandle1`,\n directionHandle2: (dynamicId) => `${dynamicId}_directionHandle2`,\n };\n class SketchControlPointRenderer extends ConnectorRenderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene, rendererManager);\n this.controlPointScaleRatio = 0.12;\n this.modelToken = Token.SketchControlPoint;\n this.layers.forEach(layer => {\n layer.parts = new Map();\n });\n }\n handlesNode(node) {\n return instanceOf(node, Token.SketchControlPoint);\n }\n update3dInternal(c) {\n const realLayer = this.layers.get('real');\n const utilityLayer = this.layers.get('utility');\n const { mesh, utilityMesh } = super.update3dInternal(c, true);\n if (c._parent instanceof exports.SketchPath) {\n const realParts = realLayer.parts.get(c._dynamicId);\n const utilityParts = utilityLayer.parts.get(c._dynamicId);\n if (c.changes.hasAny('direction', 'direction2')) {\n if (realParts) {\n updateHandles(realParts, c, c._parent);\n }\n if (utilityParts) {\n updateHandles(utilityParts, c, c._parent);\n }\n }\n }\n return { mesh, utilityMesh };\n function updateHandles(parts, controlPoint, path) {\n var _a, _b;\n let enableHandle1, enableHandle2;\n switch (path.type) {\n case exports.eSketchPathType.arcThrough3Points:\n case exports.eSketchPathType.points:\n case exports.eSketchPathType.centerRadiusCircle:\n case exports.eSketchPathType.catmullRom:\n enableHandle1 = false;\n enableHandle2 = false;\n break;\n case exports.eSketchPathType.quadraticBezier:\n case exports.eSketchPathType.hermite:\n // Don't show handles on the ends of the path since that handle does nothing\n enableHandle1 =\n path.controlPoints.findIndex(cp => cp._dynamicId === controlPoint._dynamicId) <\n path.controlPoints.length - 1;\n enableHandle2 = false;\n break;\n default:\n // Don't show handles on the ends of the path since that handle does nothing\n enableHandle1 =\n path.controlPoints.findIndex(cp => cp._dynamicId === controlPoint._dynamicId) <\n path.controlPoints.length - 1;\n enableHandle2 = path.controlPoints.findIndex(cp => cp._dynamicId === controlPoint._dynamicId) > 0;\n }\n if (parts.directionHandle1 && c.direction.length() > 0) {\n parts.directionHandle1.position = c.direction.toVec3();\n }\n if (parts.directionHandle2 && c.direction2 && c.direction2.length() > 0) {\n parts.directionHandle2.position = c.direction2.toVec3();\n }\n (_a = parts.directionHandle1) === null || _a === void 0 ? void 0 : _a.setEnabled(enableHandle1);\n (_b = parts.directionHandle2) === null || _b === void 0 ? void 0 : _b.setEnabled(enableHandle2);\n if (parts.handleBar) {\n parts.handleBar.setEnabled(true);\n parts.handleBar = MeshBuilder.CreateDashedLines(getMeshName.handleBar(c._dynamicId), {\n points: [\n enableHandle1 ? c.direction.toVec3() : Vector3.Zero(),\n Vector3.Zero(),\n enableHandle2 && c.direction2 ? c.direction2.toVec3() : Vector3.Zero(),\n ],\n updatable: true,\n instance: parts.handleBar,\n });\n }\n }\n }\n delete3d(c) {\n const mesh = this.getMesh(c, this.layers.get('real'));\n const utilityMesh = this.getMesh(c, this.layers.get('utility'));\n this.viewer.camera.clearMaintainedNodeScreenSize(mesh);\n if (utilityMesh) {\n this.viewer.camera.clearMaintainedNodeScreenSize(utilityMesh);\n }\n super.delete3d(c);\n const sketchPath = c._parent;\n if (sketchPath && isTrackedClass(sketchPath)) {\n sketchPath.setPropertyIsModified('controlPoints', true);\n }\n }\n updateDirection(c) {\n const realLayer = this.layers.get('real');\n const utilityLayer = this.layers.get('utility');\n const mesh = this.getMesh(c, realLayer);\n const utilityMesh = this.getMesh(c, utilityLayer);\n const deltaBtwXaxisAndDirection = getRotationBtwVectors(Axis.X, this.getRelativeDirection(c, c.direction).normalize());\n const angleRot = Quaternion.RotationAxis(Axis.X, toRadians(c.angle));\n mesh.rotationQuaternion = utilityMesh.rotationQuaternion = deltaBtwXaxisAndDirection.multiply(angleRot);\n const realParts = realLayer.parts.get(c._dynamicId);\n const utilityParts = utilityLayer.parts.get(c._dynamicId);\n if (realParts === null || realParts === void 0 ? void 0 : realParts.handleContainer) {\n const invTransform = Matrix.Compose(Vector3.One(), mesh.rotationQuaternion, Vector3.Zero());\n invTransform.invert();\n invTransform.decomposeToTransformNode(realParts.handleContainer);\n if (utilityParts === null || utilityParts === void 0 ? void 0 : utilityParts.handleContainer) {\n invTransform.decomposeToTransformNode(utilityParts.handleContainer);\n }\n }\n this.updateScale(c);\n }\n updatePosition(c, bb) {\n const mesh = this.getMesh(c, this.layers.get('real'));\n const utilityMesh = this.getMesh(c, this.layers.get('utility'));\n mesh.position = this.getControlPointAbsPosition(c, bb);\n if (utilityMesh) {\n utilityMesh.position = mesh.position;\n }\n const sketchPath = c._parent;\n if (sketchPath && isTrackedClass(sketchPath)) {\n sketchPath.setPropertyIsModified('controlPoints', true);\n }\n }\n getControlPointAbsPosition(c, bb) {\n var _a;\n if (c.positionMode == exports.eConnectorPositionMode.boundingBox) {\n if (!bb) {\n bb = (_a = c.getSketch()) === null || _a === void 0 ? void 0 : _a.getBoundingBox();\n }\n if (bb) {\n return BoundingBoxRelativeHelper.convertRelativeToAbsolute(c, bb);\n }\n else {\n return new Vector3(c.position.x, c.position.y, c.position.z);\n }\n }\n else {\n return c.position.toVec3();\n }\n }\n getRelativeDirection(c, direction, bb) {\n var _a;\n if (c.positionMode === exports.eConnectorPositionMode.absolute) {\n return direction.toVec3();\n }\n else {\n if (!bb) {\n bb = (_a = c.getSketch()) === null || _a === void 0 ? void 0 : _a.getBoundingBox();\n }\n if (!bb) {\n return Vector3.Zero();\n }\n return BoundingBoxRelativeHelper.convertRelativeDirectionToAbsolute(c, direction, bb);\n }\n }\n getMesh(c, layer) {\n var _a;\n let mesh = layer.map.get(c._dynamicId);\n if (!mesh) {\n if (!layer.template) {\n layer.template = this.createMeshTemplate(layer);\n }\n mesh = layer.template.clone(c._dynamicId); // layer.template.createInstance(c._dynamicId);\n mesh.id = c._dynamicId;\n const [handleContainer] = mesh.getChildren();\n const [directionHandle1, directionHandle2, _handleBar] = handleContainer.getChildMeshes(true);\n const handleBar = _handleBar;\n handleBar.makeGeometryUnique();\n handleContainer.id = getMeshName.handles(c._dynamicId);\n directionHandle1.id = getMeshName.directionHandle1(c._dynamicId);\n directionHandle2.id = getMeshName.directionHandle2(c._dynamicId);\n const parentNode = (_a = c._parent) === null || _a === void 0 ? void 0 : _a._parent;\n if (parentNode && parentNode instanceof exports.SpaceNode) {\n const parent3d = this.viewer.getRendererNode(parentNode);\n if (parent3d) {\n mesh.setParent(parent3d);\n }\n }\n mesh.isPickable = layer.pickable;\n mesh.position = Vector3.Zero();\n mesh.rotationQuaternion = Quaternion.Identity();\n layer.map.set(c._dynamicId, mesh);\n layer.parts.set(c._dynamicId, {\n mesh,\n handleContainer: handleContainer,\n directionHandle1,\n directionHandle2,\n handleBar: handleBar,\n });\n }\n return mesh;\n }\n createMeshTemplate(layer) {\n var _a;\n const mesh = super.createMeshTemplate(layer);\n const handleContainer = new TransformNode('', this.scene);\n const handleBall = CreateSphere('handle1', {\n segments: 4,\n diameter: CONNECTOR_DIAM / 2,\n });\n handleBall.setParent(handleContainer);\n const m = new StandardMaterial('controlPointMaterial', this.scene);\n m.emissiveColor = this.viewer.highlightColor.toColor3();\n m.disableLighting = true;\n handleBall.material = m;\n const handle1 = handleBall;\n const handle2 = handleBall.clone('handle2', handleContainer, true);\n handle1.setEnabled(false);\n handle2.setEnabled(false);\n const baseColor = ((_a = this.viewer.sceneNode) === null || _a === void 0 ? void 0 : _a.edgeColor)\n ? this.viewer.sceneNode.edgeColor.toColor3()\n : Color3.White();\n const handleBar = MeshBuilder.CreateDashedLines('handleBar', {\n points: [Vector3.Up(), Vector3.Zero(), Vector3.Down()],\n updatable: true,\n dashSize: 1,\n gapSize: 1,\n dashNb: 30,\n });\n handleBar.color = baseColor;\n handleBar.isPickable = false;\n // const handleBarMaterial = new StandardMaterial('controlPointHandleBarMaterial', this.scene);\n // handleBarMaterial.emissiveColor = this.viewer.sceneNode?.edgeColor ? this.viewer.sceneNode.edgeColor.toColor3() : Color3.White();\n // handleBar.material = handleBarMaterial;\n handleBar.setParent(handleContainer);\n handleContainer.setParent(mesh);\n return mesh;\n }\n addSubscription(c) {\n const sketch = c.getSketch();\n if (sketch && !this.subscriptionMap.has(c)) {\n this.subscriptionMap.set(c, sketch._boundingBoxChanges.subscribe(bbInfo => {\n this.updatePosition(c, bbInfo);\n this.updateScale(c);\n }));\n }\n }\n }\n\n class ReferenceProcessor extends Processor {\n constructor(viewer) {\n super();\n this.viewer = viewer;\n /**\n * referencedNodeId => ( referencedByNodeId => referencedByNode )\n *\n * Any node that is in a nested scene will be keyed by the nested scene ID.\n * If the node is not in a nested scene (or there is no nesting), then the node will be keyed by the bare node id.\n * This applies to the referencedNodeId and the referencedByNodeId.\n * */\n this.referencesTo = new Map();\n this.orphanedReferences = new Map();\n }\n beforeDeletions(deletions) {\n const rootScene = this.viewer.sceneNode;\n if (!rootScene || !rootScene._manager) {\n return;\n }\n const rootManager = rootScene._manager;\n deletions.all().forEach(node => {\n var _a;\n if (!node._manager) {\n return;\n }\n let nodeId = node.id;\n if ((_a = node._parentScene) === null || _a === void 0 ? void 0 : _a.isNested()) {\n nodeId = rootScene.getNestedPathTo(node);\n }\n const referenceTo = this.referencesTo.get(nodeId);\n if (referenceTo && referenceTo.size > 0) {\n referenceTo.forEach((opts, referencedById) => {\n const referencedBy = rootManager.getById(referencedById);\n if (referencedBy && referencedBy[opts.referencePropertyName] === nodeId) {\n this.orphanedReferences.set(nodeId, {\n referencedBy,\n propName: opts.referencePropertyName,\n referenceId: referencedBy[opts.referencePropertyName],\n });\n referencedBy[opts.referencePropertyName] = undefined;\n }\n });\n }\n });\n }\n getReferencesTo() {\n return this.referencesTo;\n }\n beforeUpdates(changes) {\n const rootScene = this.viewer.sceneNode;\n if (!rootScene || !rootScene._manager) {\n return;\n }\n changes.all().forEach(node => {\n var _a;\n let nodeId = node.id;\n if ((_a = node._parentScene) === null || _a === void 0 ? void 0 : _a.isNested()) {\n nodeId = rootScene.getNestedPathTo(node);\n }\n const orphanedReference = this.orphanedReferences.get(nodeId);\n if (orphanedReference) {\n orphanedReference.referencedBy[orphanedReference.propName] = orphanedReference.referenceId;\n }\n });\n }\n afterUpdates(changes) {\n const rootScene = this.viewer.sceneNode;\n if (!rootScene || !rootScene._manager) {\n return;\n }\n changes.all().forEach(node => {\n var _a, _b, _c;\n if (!node._manager) {\n return;\n }\n const changedNodeManager = node._manager;\n // This block is for managing/updating the node reference\n // First, check nodes referencing other nodes for updates\n if (node.nodeReferences) {\n const targettingProperties = node.nodeReferences.keys();\n for (const _prop of targettingProperties) {\n const property = _prop;\n const referenceSettings = node.nodeReferences.get(_prop);\n // If a node's references were changed, update all the references.\n if (node.changes.has(property)) {\n if (node[property] && typeof node[property] !== 'string') {\n console.error(`Non-string id reference value found on ${node.name} property ${property}`);\n }\n // First, remove the node from the previous target node's referencing nodes set\n if (node.originalValues.has(property)) {\n const originalReferencedNodeId = node.originalValues.get(property);\n if (originalReferencedNodeId) {\n // Figure out the original target node's key\n let originalReferencedNodeKey = originalReferencedNodeId;\n const originalReferencedNode = changedNodeManager.getById(originalReferencedNodeId);\n if ((_a = originalReferencedNode === null || originalReferencedNode === void 0 ? void 0 : originalReferencedNode._parentScene) === null || _a === void 0 ? void 0 : _a.isNested()) {\n originalReferencedNodeKey = rootScene.getNestedPathTo(originalReferencedNode);\n }\n const referencedBy = this.referencesTo.get(originalReferencedNodeKey);\n if (referencedBy) {\n let nestedPathIdSource = node.id;\n if ((_b = node._parentScene) === null || _b === void 0 ? void 0 : _b.isNested()) {\n nestedPathIdSource = rootScene.getNestedPathTo(node);\n }\n referencedBy.delete(nestedPathIdSource);\n }\n }\n }\n // Set up the new references or delete the reference from entry if the reference was cleared\n if (node[property]) {\n const targetNode = node._manager.getById(node[property]);\n if (targetNode) {\n if (targetNode instanceof referenceSettings.classRef) {\n let nestedPathIdTarget = node[property];\n let nestedPathIdSource = node.id;\n const isNestedSource = ((_c = node._parentScene) === null || _c === void 0 ? void 0 : _c.isNested()) || false;\n if (nestedPathIdTarget.startsWith('@')) {\n const nestedTargetNode = changedNodeManager.getById(nestedPathIdTarget);\n if (nestedTargetNode) {\n nestedPathIdTarget = rootScene.getNestedPathTo(nestedTargetNode);\n }\n }\n else if (isNestedSource) {\n // If source node is in a nested scene and the target node id is not a nested path, that means that\n // the nested node is targetting a node in it's own scene. But we need to use\n // a nested path because there could be multiple instances of the nested node's scene\n nestedPathIdTarget = rootScene.getNestedPathTo(targetNode);\n }\n if (isNestedSource) {\n nestedPathIdSource = rootScene.getNestedPathTo(node);\n }\n let referencedBy = this.referencesTo.get(nestedPathIdTarget);\n if (!referencedBy) {\n referencedBy = new Map();\n this.referencesTo.set(nestedPathIdTarget, referencedBy);\n }\n referencedBy.set(nestedPathIdSource, {\n limitKeys: referenceSettings.limitKeys,\n ref: node,\n referencePropertyName: property,\n });\n }\n else {\n console.warn(`Node ${node.name} property ${property} is not referencing a ${referenceSettings.classRef}`);\n }\n }\n }\n }\n }\n }\n });\n // Next, check nodes being referenced by other nodes to see if the other nodes will need to be updated\n changes.all().forEach(node => {\n this.triggerChangesOnReferencers(node);\n });\n }\n triggerChangesOnReferencers(node, changes) {\n const changeMap = changes || new Map(node.changes);\n if (changeMap.size > 0) {\n this.afterCleanup(() => {\n this.triggerChangesOnReferencersSync(node, changeMap);\n });\n }\n }\n triggerChangesOnReferencersSync(node, changes, transformationPropagation) {\n var _a;\n const rootScene = this.viewer.sceneNode;\n if (!rootScene || !rootScene._manager) {\n return;\n }\n const rootManager = rootScene._manager;\n let nodeId = node.id;\n if ((_a = node._parentScene) === null || _a === void 0 ? void 0 : _a.isNested()) {\n nodeId = rootScene.getNestedPathTo(node);\n }\n const referenceTo = this.referencesTo.get(nodeId);\n if (referenceTo) {\n referenceTo.forEach((referenceSettings, referencedById) => {\n const referencedBy = rootManager.getById(referencedById);\n if (referencedBy && isTrackedClass(referencedBy)) {\n if (!referenceSettings.limitKeys ||\n transformationPropagation ||\n changes.hasAny(...referenceSettings.limitKeys)) {\n referencedBy.setPropertyIsModified(referenceSettings.referencePropertyName, true);\n }\n }\n });\n }\n // For transformation changes, propagate to the children because the children will also get moved without passing through the change tracker\n // This avoids needing a secondary watcher for node position\n if (node instanceof exports.SpaceNode &&\n changes.hasAny('position', 'eulerRotation', 'rotationAngle', 'rotationAxis', 'pivot', 'scaling')) {\n const children = node.getChildren();\n for (let i = 0; i < children.length; i++) {\n // Always trigger changes on children because they may have different property names\n this.triggerChangesOnReferencersSync(children[i], changes, true);\n }\n }\n }\n dispose() {\n this.referencesTo.clear();\n }\n }\n\n /**\n * Processor to calculate the bounding box of a sketch, since it is determined by the path defined within.\n * Must run after the mate processor because mates can move sketch points and change the bounding box.\n */\n class SketchProcessor extends Processor {\n constructor(controlPointRenderer) {\n super();\n this.controlPointRenderer = controlPointRenderer;\n }\n beforeRender() { }\n beforeDeletions(deletions) {\n // Update paths that need to be updated\n if (deletions.has(Token.SketchPath)) {\n const sketchPaths = deletions.get(Token.SketchPath);\n sketchPaths.forEach(p => this.updatePath(p));\n }\n if (deletions.has(Token.SketchControlPoint) || deletions.has(Token.SketchPath)) {\n const sketchPathChanges = deletions.get(Token.SketchPath);\n const sketchControlPointChanges = deletions.get(Token.SketchControlPoint);\n const sketchesToUpdate = new Map();\n sketchPathChanges.forEach(node => {\n const sketch = node._parent;\n if (sketch) {\n if (!sketchesToUpdate.has(sketch._dynamicId)) {\n sketchesToUpdate.set(sketch._dynamicId, sketch);\n }\n }\n });\n sketchControlPointChanges.forEach(node => {\n const sketch = node.getSketch();\n if (sketch) {\n if (!sketchesToUpdate.has(sketch._dynamicId)) {\n sketchesToUpdate.set(sketch._dynamicId, sketch);\n }\n }\n });\n sketchesToUpdate.forEach(this.calculateSketchBounds);\n }\n }\n beforeUpdates(changes) {\n // Update paths that need to be updated\n if (changes.has(Token.SketchPath)) {\n const sketchPaths = changes.get(Token.SketchPath);\n sketchPaths.forEach(p => this.updatePath(p));\n }\n // Update the sketch bounding box with the path control points within it that are absolute positioned\n if (changes.has(Token.SketchControlPoint)) {\n const sketchControlPointChanges = changes.get(Token.SketchControlPoint);\n const sketchesToUpdate = new Map();\n sketchControlPointChanges.forEach(node => {\n if (node.changes.hasAny('position', 'positionMode')) {\n const sketch = node.getSketch();\n if (sketch) {\n if (!sketchesToUpdate.has(sketch._dynamicId)) {\n sketchesToUpdate.set(sketch._dynamicId, sketch);\n }\n }\n }\n });\n sketchesToUpdate.forEach(this.calculateSketchBounds);\n }\n }\n afterUpdates(changes) {\n if (changes.has(Token.SketchControlPoint)) {\n const sketchControlPointChanges = changes.get(Token.SketchControlPoint);\n sketchControlPointChanges.forEach(node => {\n const sketch = node.getSketch();\n if (sketch) {\n this.afterCleanup(() => {\n sketch.paths.forEach(path => {\n if (isTrackedClass(path)) {\n this.updatePath(path, true);\n }\n });\n sketch.connectors.forEach(connector => {\n if (connector.positionMode === exports.eConnectorPositionMode.moveAlongSketch) {\n if (connector._parent instanceof exports.SketchNode) {\n connector._sketchControlPoints = this.getControlPoints(connector._parent);\n }\n }\n });\n });\n }\n });\n }\n }\n calculateSketchBounds(sketch) {\n const controlPoints = sketch.paths.flatMap(path => path.controlPoints);\n let min;\n let max;\n controlPoints.forEach(controlPoint => {\n if (controlPoint.positionMode === exports.eConnectorPositionMode.absolute) {\n const position = controlPoint.position;\n if (!min) {\n min = position.toVec3();\n }\n max = position.toVec3();\n }\n });\n if (min && max) {\n sketch._boundingBoxMin = exports.KbVector.FromVec3(min);\n sketch._boundingBoxMax = exports.KbVector.FromVec3(max);\n }\n else {\n sketch._boundingBoxMin = exports.KbVector.Zero();\n sketch._boundingBoxMax = exports.KbVector.Zero();\n }\n sketch._boundingBoxChanges.next(sketch.getBoundingBox());\n }\n updatePath(path, force) {\n var _a;\n let points;\n if (force ||\n path.changes.hasAny('controlPoints', 'tessellation', 'type', 'holeForPathGroup', 'pathGroupKey') ||\n !((_a = path._points) === null || _a === void 0 ? void 0 : _a.length)) {\n points = this.buildSketchPoints(path);\n path._points = points;\n const parent = path._parent;\n if (parent instanceof exports.SketchNode && isTrackedClass(parent)) {\n parent.setPropertyIsModified('paths', true);\n }\n }\n else if (path.changes.has('_selected')) {\n const parent = path._parent;\n if (parent instanceof exports.SketchNode && isTrackedClass(parent)) {\n parent.setPropertyIsModified('paths', true);\n }\n }\n }\n buildSketchPoints(path) {\n const points = [];\n if (!path._parent) {\n return points;\n }\n const bb = path._parent.getBoundingBox();\n switch (path.type) {\n case exports.eSketchPathType.catmullRom: {\n const positions = path.controlPoints.map(v => this.getPointPosition(v));\n if (positions.length > 2) {\n const curve = Curve3.CreateCatmullRomSpline(positions, path.tessellation, false);\n points.push(...curve.getPoints());\n }\n else {\n points.push(...positions);\n }\n break;\n }\n case exports.eSketchPathType.hermite: {\n for (let i = 0; i + 1 < path.controlPoints.length; i++) {\n const start = path.controlPoints[i], end = path.controlPoints[i + 1];\n const p0 = this.getPointPosition(start);\n const p1 = this.getPointPosition(end);\n const d0 = this.getPointDirection(start, bb);\n const d1 = this.getPointDirection(end, bb);\n const curve = Curve3.CreateHermiteSpline(p0, d0, p1, d1, path.tessellation);\n points.push(...curve.getPoints());\n }\n break;\n }\n case exports.eSketchPathType.cubicBezier: {\n for (let i = 0; i + 1 < path.controlPoints.length; i++) {\n const start = path.controlPoints[i], end = path.controlPoints[i + 1];\n const direction2 = this.getPointDirection2(end, bb);\n if (direction2) {\n const p0 = this.getPointPosition(start);\n const p3 = this.getPointPosition(end);\n if (p0.equals(p3)) {\n continue;\n }\n const p1 = p0.add(this.getPointDirection(start, bb));\n const p2 = p3.add(direction2);\n const curve = Curve3.CreateCubicBezier(p0, p1, p2, p3, path.tessellation);\n points.push(...curve.getPoints());\n }\n }\n break;\n }\n case exports.eSketchPathType.quadraticBezier: {\n const controlPoint = new Vector3();\n for (let i = 0; i + 1 < path.controlPoints.length; i++) {\n const start = path.controlPoints[i], end = path.controlPoints[i + 1];\n const p0 = this.getPointPosition(start);\n const p2 = this.getPointPosition(end);\n if (p0.equals(p2)) {\n continue;\n }\n p0.addToRef(this.getPointDirection(start, bb), controlPoint);\n const curve = Curve3.CreateQuadraticBezier(p0, controlPoint, p2, path.tessellation);\n points.push(...curve.getPoints());\n }\n break;\n }\n case exports.eSketchPathType.centerRadiusCircle: {\n if (path.controlPoints.length >= 2) {\n const [p0, p1] = path.controlPoints.slice(0, 2).map(cp => this.getPointPosition(cp));\n const normal = this.getPointDirection(path.controlPoints[0], bb).normalize();\n const p2 = Vector3.Cross(p0.subtract(p1), normal).addInPlace(p0);\n const curve = Curve3.ArcThru3Points(p0.scale(2).subtractInPlace(p1), p1, p2, path.tessellation * 2, false, true);\n points.push(...curve.getPoints());\n }\n break;\n }\n case exports.eSketchPathType.arcThrough3Points: {\n if (path.controlPoints.length >= 3) {\n const [p0, p1, p2] = path.controlPoints.slice(0, 3).map(cp => this.getPointPosition(cp));\n const curve = Curve3.ArcThru3Points(p0, p1, p2, path.tessellation, false, false);\n points.push(...curve.getPoints());\n }\n break;\n }\n default: {\n path.controlPoints.forEach(point => {\n points.push(this.getPointPosition(point));\n });\n }\n }\n // /**\n // * We want the sketch to always \"face\" in the positive direction of the axis for consistency\n // * Otherwise it's indeterminate which way the sketch will face and makes the sketch hard to manage\n // * because it depends on the handed-ness of the points (clockwise or counter-clockwise)\n // */\n // const primaryNormal = axisToVector3(path._parent.normal);\n // const faceNormal = calculateFaceNormal(points);\n // if (Vector3.Dot(faceNormal, primaryNormal) < 0) {\n // points.reverse();\n // }\n return points;\n }\n getPointPosition(point) {\n return this.controlPointRenderer.getControlPointAbsPosition(point);\n }\n getPointDirection(point, bb) {\n return this.controlPointRenderer.getRelativeDirection(point, point.direction, bb);\n }\n getPointDirection2(point, bb) {\n if (!point.direction2) {\n return undefined;\n }\n else {\n return this.controlPointRenderer.getRelativeDirection(point, point.direction2, bb);\n }\n }\n getControlPoints(node) {\n const controlPoints = [];\n node.paths.forEach(path => {\n path._points.forEach(point => {\n controlPoints.push(point);\n });\n });\n return controlPoints;\n }\n }\n\n /**\n * PostProcessRenderPipeline\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\n */\n class PostProcessRenderPipeline {\n /**\n * Gets pipeline name\n */\n get name() {\n return this._name;\n }\n /** Gets the list of attached cameras */\n get cameras() {\n return this._cameras;\n }\n /**\n * Initializes a PostProcessRenderPipeline\n * @param _engine engine to add the pipeline to\n * @param name name of the pipeline\n */\n constructor(_engine, name) {\n this._engine = _engine;\n this._name = name;\n this._renderEffects = {};\n this._renderEffectsForIsolatedPass = new Array();\n this._cameras = [];\n }\n /**\n * Gets the class name\n * @returns \"PostProcessRenderPipeline\"\n */\n getClassName() {\n return \"PostProcessRenderPipeline\";\n }\n /**\n * If all the render effects in the pipeline are supported\n */\n get isSupported() {\n for (const renderEffectName in this._renderEffects) {\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\n if (!this._renderEffects[renderEffectName].isSupported) {\n return false;\n }\n }\n }\n return true;\n }\n /**\n * Adds an effect to the pipeline\n * @param renderEffect the effect to add\n */\n addEffect(renderEffect) {\n this._renderEffects[renderEffect._name] = renderEffect;\n }\n // private\n /** @internal */\n _rebuild() { }\n /**\n * @internal\n */\n _enableEffect(renderEffectName, cameras) {\n const renderEffects = this._renderEffects[renderEffectName];\n if (!renderEffects) {\n return;\n }\n renderEffects._enable(Tools.MakeArray(cameras || this._cameras));\n }\n /**\n * @internal\n */\n _disableEffect(renderEffectName, cameras) {\n const renderEffects = this._renderEffects[renderEffectName];\n if (!renderEffects) {\n return;\n }\n renderEffects._disable(Tools.MakeArray(cameras || this._cameras));\n }\n /**\n * @internal\n */\n _attachCameras(cameras, unique) {\n const cams = Tools.MakeArray(cameras || this._cameras);\n if (!cams) {\n return;\n }\n const indicesToDelete = [];\n let i;\n for (i = 0; i < cams.length; i++) {\n const camera = cams[i];\n if (!camera) {\n continue;\n }\n if (this._cameras.indexOf(camera) === -1) {\n this._cameras.push(camera);\n }\n else if (unique) {\n indicesToDelete.push(i);\n }\n }\n for (i = 0; i < indicesToDelete.length; i++) {\n cams.splice(indicesToDelete[i], 1);\n }\n for (const renderEffectName in this._renderEffects) {\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\n this._renderEffects[renderEffectName]._attachCameras(cams);\n }\n }\n }\n /**\n * @internal\n */\n _detachCameras(cameras) {\n const cams = Tools.MakeArray(cameras || this._cameras);\n if (!cams) {\n return;\n }\n for (const renderEffectName in this._renderEffects) {\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\n this._renderEffects[renderEffectName]._detachCameras(cams);\n }\n }\n for (let i = 0; i < cams.length; i++) {\n this._cameras.splice(this._cameras.indexOf(cams[i]), 1);\n }\n }\n /** @internal */\n _update() {\n for (const renderEffectName in this._renderEffects) {\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\n this._renderEffects[renderEffectName]._update();\n }\n }\n for (let i = 0; i < this._cameras.length; i++) {\n if (!this._cameras[i]) {\n continue;\n }\n const cameraName = this._cameras[i].name;\n if (this._renderEffectsForIsolatedPass[cameraName]) {\n this._renderEffectsForIsolatedPass[cameraName]._update();\n }\n }\n }\n /** @internal */\n _reset() {\n this._renderEffects = {};\n this._renderEffectsForIsolatedPass = new Array();\n }\n _enableMSAAOnFirstPostProcess(sampleCount) {\n if (!this._engine._features.supportMSAA) {\n return false;\n }\n // Set samples of the very first post process to 4 to enable native anti-aliasing in browsers that support webGL 2.0 (See: https://github.com/BabylonJS/Babylon.js/issues/3754)\n const effectKeys = Object.keys(this._renderEffects);\n if (effectKeys.length > 0) {\n const postProcesses = this._renderEffects[effectKeys[0]].getPostProcesses();\n if (postProcesses) {\n postProcesses[0].samples = sampleCount;\n }\n }\n return true;\n }\n /**\n * Sets the required values to the prepass renderer.\n * @param prePassRenderer defines the prepass renderer to setup.\n * @returns true if the pre pass is needed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setPrePassRenderer(prePassRenderer) {\n // Do Nothing by default\n return false;\n }\n /**\n * Disposes of the pipeline\n */\n dispose() {\n // Must be implemented by children\n }\n }\n __decorate$1([\n serialize()\n ], PostProcessRenderPipeline.prototype, \"_name\", void 0);\n\n /**\n * This represents a set of one or more post processes in Babylon.\n * A post process can be used to apply a shader to a texture after it is rendered.\n * @example https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\n */\n class PostProcessRenderEffect {\n /**\n * Instantiates a post process render effect.\n * A post process can be used to apply a shader to a texture after it is rendered.\n * @param engine The engine the effect is tied to\n * @param name The name of the effect\n * @param getPostProcesses A function that returns a set of post processes which the effect will run in order to be run.\n * @param singleInstance False if this post process can be run on multiple cameras. (default: true)\n */\n constructor(engine, name, getPostProcesses, singleInstance) {\n this._name = name;\n this._singleInstance = singleInstance || true;\n this._getPostProcesses = getPostProcesses;\n this._cameras = {};\n this._indicesForCamera = {};\n this._postProcesses = {};\n }\n /**\n * Checks if all the post processes in the effect are supported.\n */\n get isSupported() {\n for (const index in this._postProcesses) {\n if (Object.prototype.hasOwnProperty.call(this._postProcesses, index)) {\n const pps = this._postProcesses[index];\n for (let ppIndex = 0; ppIndex < pps.length; ppIndex++) {\n if (!pps[ppIndex].isSupported) {\n return false;\n }\n }\n }\n }\n return true;\n }\n /**\n * Updates the current state of the effect\n * @internal\n */\n _update() { }\n /**\n * Attaches the effect on cameras\n * @param cameras The camera to attach to.\n * @internal\n */\n _attachCameras(cameras) {\n let cameraKey;\n const cams = Tools.MakeArray(cameras || this._cameras);\n if (!cams) {\n return;\n }\n for (let i = 0; i < cams.length; i++) {\n const camera = cams[i];\n if (!camera) {\n continue;\n }\n const cameraName = camera.name;\n if (this._singleInstance) {\n cameraKey = 0;\n }\n else {\n cameraKey = cameraName;\n }\n if (!this._postProcesses[cameraKey]) {\n const postProcess = this._getPostProcesses();\n if (postProcess) {\n this._postProcesses[cameraKey] = Array.isArray(postProcess) ? postProcess : [postProcess];\n }\n }\n if (!this._indicesForCamera[cameraName]) {\n this._indicesForCamera[cameraName] = [];\n }\n this._postProcesses[cameraKey].forEach((postProcess) => {\n const index = camera.attachPostProcess(postProcess);\n this._indicesForCamera[cameraName].push(index);\n });\n if (!this._cameras[cameraName]) {\n this._cameras[cameraName] = camera;\n }\n }\n }\n /**\n * Detaches the effect on cameras\n * @param cameras The camera to detach from.\n * @internal\n */\n _detachCameras(cameras) {\n const cams = Tools.MakeArray(cameras || this._cameras);\n if (!cams) {\n return;\n }\n for (let i = 0; i < cams.length; i++) {\n const camera = cams[i];\n const cameraName = camera.name;\n const postProcesses = this._postProcesses[this._singleInstance ? 0 : cameraName];\n if (postProcesses) {\n postProcesses.forEach((postProcess) => {\n camera.detachPostProcess(postProcess);\n });\n }\n if (this._cameras[cameraName]) {\n this._cameras[cameraName] = null;\n }\n delete this._indicesForCamera[cameraName];\n }\n }\n /**\n * Enables the effect on given cameras\n * @param cameras The camera to enable.\n * @internal\n */\n _enable(cameras) {\n const cams = Tools.MakeArray(cameras || this._cameras);\n if (!cams) {\n return;\n }\n for (let i = 0; i < cams.length; i++) {\n const camera = cams[i];\n const cameraName = camera.name;\n const cameraKey = this._singleInstance ? 0 : cameraName;\n for (let j = 0; j < this._indicesForCamera[cameraName].length; j++) {\n const index = this._indicesForCamera[cameraName][j];\n const postProcess = camera._postProcesses[index];\n if (postProcess === undefined || postProcess === null) {\n cams[i].attachPostProcess(this._postProcesses[cameraKey][j], index);\n }\n }\n }\n }\n /**\n * Disables the effect on the given cameras\n * @param cameras The camera to disable.\n * @internal\n */\n _disable(cameras) {\n const cams = Tools.MakeArray(cameras || this._cameras);\n if (!cams) {\n return;\n }\n for (let i = 0; i < cams.length; i++) {\n const camera = cams[i];\n const cameraName = camera.name;\n this._postProcesses[this._singleInstance ? 0 : cameraName].forEach((postProcess) => {\n camera.detachPostProcess(postProcess);\n });\n }\n }\n /**\n * Gets a list of the post processes contained in the effect.\n * @param camera The camera to get the post processes on.\n * @returns The list of the post processes in the effect.\n */\n getPostProcesses(camera) {\n if (this._singleInstance) {\n return this._postProcesses[0];\n }\n else {\n if (!camera) {\n return null;\n }\n return this._postProcesses[camera.name];\n }\n }\n }\n\n /**\n * PostProcessRenderPipelineManager class\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\n */\n class PostProcessRenderPipelineManager {\n /**\n * Initializes a PostProcessRenderPipelineManager\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\n */\n constructor() {\n this._renderPipelines = {};\n }\n /**\n * Gets the list of supported render pipelines\n */\n get supportedPipelines() {\n const result = [];\n for (const renderPipelineName in this._renderPipelines) {\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\n const pipeline = this._renderPipelines[renderPipelineName];\n if (pipeline.isSupported) {\n result.push(pipeline);\n }\n }\n }\n return result;\n }\n /**\n * Adds a pipeline to the manager\n * @param renderPipeline The pipeline to add\n */\n addPipeline(renderPipeline) {\n this._renderPipelines[renderPipeline._name] = renderPipeline;\n }\n /**\n * Remove the pipeline from the manager\n * @param renderPipelineName the name of the pipeline to remove\n */\n removePipeline(renderPipelineName) {\n delete this._renderPipelines[renderPipelineName];\n }\n /**\n * Attaches a camera to the pipeline\n * @param renderPipelineName The name of the pipeline to attach to\n * @param cameras the camera to attach\n * @param unique if the camera can be attached multiple times to the pipeline\n */\n attachCamerasToRenderPipeline(renderPipelineName, cameras, unique = false) {\n const renderPipeline = this._renderPipelines[renderPipelineName];\n if (!renderPipeline) {\n return;\n }\n renderPipeline._attachCameras(cameras, unique);\n }\n /**\n * Detaches a camera from the pipeline\n * @param renderPipelineName The name of the pipeline to detach from\n * @param cameras the camera to detach\n */\n detachCamerasFromRenderPipeline(renderPipelineName, cameras) {\n const renderPipeline = this._renderPipelines[renderPipelineName];\n if (!renderPipeline) {\n return;\n }\n renderPipeline._detachCameras(cameras);\n }\n /**\n * Enables an effect by name on a pipeline\n * @param renderPipelineName the name of the pipeline to enable the effect in\n * @param renderEffectName the name of the effect to enable\n * @param cameras the cameras that the effect should be enabled on\n */\n enableEffectInPipeline(renderPipelineName, renderEffectName, cameras) {\n const renderPipeline = this._renderPipelines[renderPipelineName];\n if (!renderPipeline) {\n return;\n }\n renderPipeline._enableEffect(renderEffectName, cameras);\n }\n /**\n * Disables an effect by name on a pipeline\n * @param renderPipelineName the name of the pipeline to disable the effect in\n * @param renderEffectName the name of the effect to disable\n * @param cameras the cameras that the effect should be disabled on\n */\n disableEffectInPipeline(renderPipelineName, renderEffectName, cameras) {\n const renderPipeline = this._renderPipelines[renderPipelineName];\n if (!renderPipeline) {\n return;\n }\n renderPipeline._disableEffect(renderEffectName, cameras);\n }\n /**\n * Updates the state of all contained render pipelines and disposes of any non supported pipelines\n */\n update() {\n for (const renderPipelineName in this._renderPipelines) {\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\n const pipeline = this._renderPipelines[renderPipelineName];\n if (!pipeline.isSupported) {\n pipeline.dispose();\n delete this._renderPipelines[renderPipelineName];\n }\n else {\n pipeline._update();\n }\n }\n }\n }\n /** @internal */\n _rebuild() {\n for (const renderPipelineName in this._renderPipelines) {\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\n const pipeline = this._renderPipelines[renderPipelineName];\n pipeline._rebuild();\n }\n }\n }\n /**\n * Disposes of the manager and pipelines\n */\n dispose() {\n for (const renderPipelineName in this._renderPipelines) {\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\n const pipeline = this._renderPipelines[renderPipelineName];\n pipeline.dispose();\n }\n }\n }\n }\n\n Object.defineProperty(Scene.prototype, \"postProcessRenderPipelineManager\", {\n get: function () {\n if (!this._postProcessRenderPipelineManager) {\n // Register the G Buffer component to the scene.\n let component = this._getComponent(SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER);\n if (!component) {\n component = new PostProcessRenderPipelineManagerSceneComponent(this);\n this._addComponent(component);\n }\n this._postProcessRenderPipelineManager = new PostProcessRenderPipelineManager();\n }\n return this._postProcessRenderPipelineManager;\n },\n enumerable: true,\n configurable: true,\n });\n /**\n * Defines the Render Pipeline scene component responsible to rendering pipelines\n */\n class PostProcessRenderPipelineManagerSceneComponent {\n /**\n * Creates a new instance of the component for the given scene\n * @param scene Defines the scene to register the component in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER;\n this.scene = scene;\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER, this, this._gatherRenderTargets);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n if (this.scene._postProcessRenderPipelineManager) {\n this.scene._postProcessRenderPipelineManager._rebuild();\n }\n }\n /**\n * Disposes the component and the associated resources\n */\n dispose() {\n if (this.scene._postProcessRenderPipelineManager) {\n this.scene._postProcessRenderPipelineManager.dispose();\n }\n }\n _gatherRenderTargets() {\n if (this.scene._postProcessRenderPipelineManager) {\n this.scene._postProcessRenderPipelineManager.update();\n }\n }\n }\n\n // Do not edit.\n const name$2w = \"chromaticAberrationPixelShader\";\n const shader$2w = `uniform sampler2D textureSampler; \nuniform float chromatic_aberration;uniform float radialIntensity;uniform vec2 direction;uniform vec2 centerPosition;uniform float screen_width;uniform float screen_height;varying vec2 vUV;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec2 centered_screen_pos=vec2(vUV.x-centerPosition.x,vUV.y-centerPosition.y);vec2 directionOfEffect=direction;if(directionOfEffect.x==0. && directionOfEffect.y==0.){directionOfEffect=normalize(centered_screen_pos);}\nfloat radius2=centered_screen_pos.x*centered_screen_pos.x\n+ centered_screen_pos.y*centered_screen_pos.y;float radius=sqrt(radius2);vec4 original=texture2D(textureSampler,vUV);vec3 ref_indices=vec3(-0.3,0.0,0.3);float ref_shiftX=chromatic_aberration*pow(radius,radialIntensity)*directionOfEffect.x/screen_width;float ref_shiftY=chromatic_aberration*pow(radius,radialIntensity)*directionOfEffect.y/screen_height;vec2 ref_coords_r=vec2(vUV.x+ref_indices.r*ref_shiftX,vUV.y+ref_indices.r*ref_shiftY*0.5);vec2 ref_coords_g=vec2(vUV.x+ref_indices.g*ref_shiftX,vUV.y+ref_indices.g*ref_shiftY*0.5);vec2 ref_coords_b=vec2(vUV.x+ref_indices.b*ref_shiftX,vUV.y+ref_indices.b*ref_shiftY*0.5);original.r=texture2D(textureSampler,ref_coords_r).r;original.g=texture2D(textureSampler,ref_coords_g).g;original.b=texture2D(textureSampler,ref_coords_b).b;original.a=clamp(texture2D(textureSampler,ref_coords_r).a+texture2D(textureSampler,ref_coords_g).a+texture2D(textureSampler,ref_coords_b).a,0.,1.);gl_FragColor=original;}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2w] = shader$2w;\n\n // Do not edit.\n const name$2x = \"lensHighlightsPixelShader\";\n const shader$2x = `uniform sampler2D textureSampler; \nuniform float gain;uniform float threshold;uniform float screen_width;uniform float screen_height;varying vec2 vUV;vec4 highlightColor(vec4 color) {vec4 highlight=color;float luminance=dot(highlight.rgb,vec3(0.2125,0.7154,0.0721));float lum_threshold;if (threshold>1.0) { lum_threshold=0.94+0.01*threshold; }\nelse { lum_threshold=0.5+0.44*threshold; }\nluminance=clamp((luminance-lum_threshold)*(1.0/(1.0-lum_threshold)),0.0,1.0);highlight*=luminance*gain;highlight.a=1.0;return highlight;}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec4 original=texture2D(textureSampler,vUV);if (gain==-1.0) {gl_FragColor=vec4(0.0,0.0,0.0,1.0);return;}\nfloat w=2.0/screen_width;float h=2.0/screen_height;float weight=1.0;vec4 blurred=vec4(0.0,0.0,0.0,0.0);\n#ifdef PENTAGON\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.84*w,0.43*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.48*w,-1.29*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.61*w,1.51*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.55*w,-0.74*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.71*w,-0.52*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.94*w,1.59*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.40*w,-1.87*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.62*w,1.16*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.09*w,0.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.46*w,-1.71*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.08*w,2.42*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.85*w,-1.89*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.89*w,0.16*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.29*w,1.88*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.40*w,-2.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.54*w,2.26*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.60*w,-0.61*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.31*w,-1.30*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.83*w,2.53*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.12*w,-2.48*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.60*w,1.11*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.99*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.50*w,-2.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.85*w,3.33*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.94*w,-1.92*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.27*w,-0.53*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.95*w,2.48*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.23*w,-3.04*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.17*w,2.05*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.97*w,-0.04*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.25*w,-2.00*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.31*w,3.08*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.94*w,-2.59*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.37*w,0.64*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.13*w,1.93*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.03*w,-3.65*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.60*w,3.17*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.14*w,-1.19*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.00*w,-1.19*h)));\n#else\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.85*w,0.36*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.52*w,-1.14*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.46*w,1.42*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.46*w,-0.83*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.79*w,-0.42*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.11*w,1.62*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.29*w,-2.07*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.69*w,1.39*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.28*w,0.12*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.65*w,-1.69*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.08*w,2.44*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.63*w,-1.90*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.55*w,0.31*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.13*w,1.52*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.56*w,-2.61*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.38*w,2.34*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.64*w,-0.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.53*w,-1.21*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.06*w,2.63*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.00*w,-2.69*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.59*w,1.32*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.78*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.57*w,-2.50*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.54*w,2.93*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.39*w,-1.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,-0.28*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.04*w,2.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.02*w,-3.05*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.09*w,2.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.07*w,-0.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.44*w,-1.90*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.52*w,3.05*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.68*w,-2.61*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,0.79*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.76*w,1.46*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.05*w,-2.94*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.21*w,2.88*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.84*w,-1.30*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.98*w,-0.96*h)));\n#endif\nblurred/=39.0;gl_FragColor=blurred;}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2x] = shader$2x;\n\n // Do not edit.\n const name$2y = \"depthOfFieldPixelShader\";\n const shader$2y = `uniform sampler2D textureSampler;uniform sampler2D highlightsSampler;uniform sampler2D depthSampler;uniform sampler2D grainSampler;uniform float grain_amount;uniform bool blur_noise;uniform float screen_width;uniform float screen_height;uniform float distortion;uniform bool dof_enabled;uniform float screen_distance; \nuniform float aperture;uniform float darken;uniform float edge_blur;uniform bool highlights;uniform float near;uniform float far;varying vec2 vUV;\n#define PI 3.14159265\n#define TWOPI 6.28318530\n#define inverse_focal_length 0.1 \nvec2 centered_screen_pos;vec2 distorted_coords;float radius2;float radius;vec2 rand(vec2 co)\n{float noise1=(fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453));float noise2=(fract(sin(dot(co,vec2(12.9898,78.233)*2.0))*43758.5453));return clamp(vec2(noise1,noise2),0.0,1.0);}\nvec2 getDistortedCoords(vec2 coords) {if (distortion==0.0) { return coords; }\nvec2 direction=1.0*normalize(centered_screen_pos);vec2 dist_coords=vec2(0.5,0.5);dist_coords.x=0.5+direction.x*radius2*1.0;dist_coords.y=0.5+direction.y*radius2*1.0;float dist_amount=clamp(distortion*0.23,0.0,1.0);dist_coords=mix(coords,dist_coords,dist_amount);return dist_coords;}\nfloat sampleScreen(inout vec4 color,in vec2 offset,in float weight) {vec2 coords=distorted_coords;float angle=rand(coords*100.0).x*TWOPI;coords+=vec2(offset.x*cos(angle)-offset.y*sin(angle),offset.x*sin(angle)+offset.y*cos(angle));color+=texture2D(textureSampler,coords)*weight;return weight;}\nfloat getBlurLevel(float size) {return min(3.0,ceil(size/1.0));}\nvec4 getBlurColor(float size) {vec4 col=texture2D(textureSampler,distorted_coords);float blur_level=getBlurLevel(size);float w=(size/screen_width);float h=(size/screen_height);float total_weight=1.0;vec2 sample_coords;total_weight+=sampleScreen(col,vec2(-0.50*w,0.24*h),0.93);total_weight+=sampleScreen(col,vec2(0.30*w,-0.75*h),0.90);total_weight+=sampleScreen(col,vec2(0.36*w,0.96*h),0.87);total_weight+=sampleScreen(col,vec2(-1.08*w,-0.55*h),0.85);total_weight+=sampleScreen(col,vec2(1.33*w,-0.37*h),0.83);total_weight+=sampleScreen(col,vec2(-0.82*w,1.31*h),0.80);total_weight+=sampleScreen(col,vec2(-0.31*w,-1.67*h),0.78);total_weight+=sampleScreen(col,vec2(1.47*w,1.11*h),0.76);total_weight+=sampleScreen(col,vec2(-1.97*w,0.19*h),0.74);total_weight+=sampleScreen(col,vec2(1.42*w,-1.57*h),0.72);if (blur_level>1.0) {total_weight+=sampleScreen(col,vec2(0.01*w,2.25*h),0.70);total_weight+=sampleScreen(col,vec2(-1.62*w,-1.74*h),0.67);total_weight+=sampleScreen(col,vec2(2.49*w,0.20*h),0.65);total_weight+=sampleScreen(col,vec2(-2.07*w,1.61*h),0.63);total_weight+=sampleScreen(col,vec2(0.46*w,-2.70*h),0.61);total_weight+=sampleScreen(col,vec2(1.55*w,2.40*h),0.59);total_weight+=sampleScreen(col,vec2(-2.88*w,-0.75*h),0.56);total_weight+=sampleScreen(col,vec2(2.73*w,-1.44*h),0.54);total_weight+=sampleScreen(col,vec2(-1.08*w,3.02*h),0.52);total_weight+=sampleScreen(col,vec2(-1.28*w,-3.05*h),0.49);}\nif (blur_level>2.0) {total_weight+=sampleScreen(col,vec2(3.11*w,1.43*h),0.46);total_weight+=sampleScreen(col,vec2(-3.36*w,1.08*h),0.44);total_weight+=sampleScreen(col,vec2(1.80*w,-3.16*h),0.41);total_weight+=sampleScreen(col,vec2(0.83*w,3.65*h),0.38);total_weight+=sampleScreen(col,vec2(-3.16*w,-2.19*h),0.34);total_weight+=sampleScreen(col,vec2(3.92*w,-0.53*h),0.31);total_weight+=sampleScreen(col,vec2(-2.59*w,3.12*h),0.26);total_weight+=sampleScreen(col,vec2(-0.20*w,-4.15*h),0.22);total_weight+=sampleScreen(col,vec2(3.02*w,3.00*h),0.15);}\ncol/=total_weight; \nif (darken>0.0) {col.rgb*=clamp(0.3,1.0,1.05-size*0.5*darken);}\nreturn col;}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{centered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);radius2=centered_screen_pos.x*centered_screen_pos.x+centered_screen_pos.y*centered_screen_pos.y;radius=sqrt(radius2);distorted_coords=getDistortedCoords(vUV); \nvec2 texels_coords=vec2(vUV.x*screen_width,vUV.y*screen_height); \nfloat depth=texture2D(depthSampler,distorted_coords).r; \nfloat distance=near+(far-near)*depth; \nvec4 color=texture2D(textureSampler,vUV); \nfloat coc=abs(aperture*(screen_distance*(inverse_focal_length-1.0/distance)-1.0));if (dof_enabled==false || coc<0.07) { coc=0.0; }\nfloat edge_blur_amount=0.0;if (edge_blur>0.0) {edge_blur_amount=clamp((radius*2.0-1.0+0.15*edge_blur)*1.5,0.0,1.0)*1.3;}\nfloat blur_amount=max(edge_blur_amount,coc);if (blur_amount==0.0) {gl_FragColor=texture2D(textureSampler,distorted_coords);}\nelse {gl_FragColor=getBlurColor(blur_amount*1.7);if (highlights) {gl_FragColor.rgb+=clamp(coc,0.0,1.0)*texture2D(highlightsSampler,distorted_coords).rgb;}\nif (blur_noise) {vec2 noise=rand(distorted_coords)*0.01*blur_amount;vec2 blurred_coord=vec2(distorted_coords.x+noise.x,distorted_coords.y+noise.y);gl_FragColor=0.04*texture2D(textureSampler,blurred_coord)+0.96*gl_FragColor;}}\nif (grain_amount>0.0) {vec4 grain_color=texture2D(grainSampler,texels_coords*0.003);gl_FragColor.rgb+=(-0.5+grain_color.rgb)*0.30*grain_amount;}}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2y] = shader$2y;\n\n /**\n * BABYLON.JS Chromatic Aberration GLSL Shader\n * Author: Olivier Guyot\n * Separates very slightly R, G and B colors on the edges of the screen\n * Inspired by Francois Tarlier & Martins Upitis\n */\n class LensRenderingPipeline extends PostProcessRenderPipeline {\n /**\n * @constructor\n *\n * Effect parameters are as follow:\n * {\n * chromatic_aberration: number; // from 0 to x (1 for realism)\n * edge_blur: number; // from 0 to x (1 for realism)\n * distortion: number; // from 0 to x (1 for realism), note that this will effect the pointer position precision\n * grain_amount: number; // from 0 to 1\n * grain_texture: BABYLON.Texture; // texture to use for grain effect; if unset, use random B&W noise\n * dof_focus_distance: number; // depth-of-field: focus distance; unset to disable (disabled by default)\n * dof_aperture: number; // depth-of-field: focus blur bias (default: 1)\n * dof_darken: number; // depth-of-field: darken that which is out of focus (from 0 to 1, disabled by default)\n * dof_pentagon: boolean; // depth-of-field: makes a pentagon-like \"bokeh\" effect\n * dof_gain: number; // depth-of-field: highlights gain; unset to disable (disabled by default)\n * dof_threshold: number; // depth-of-field: highlights threshold (default: 1)\n * blur_noise: boolean; // add a little bit of noise to the blur (default: true)\n * }\n * Note: if an effect parameter is unset, effect is disabled\n *\n * @param name The rendering pipeline name\n * @param parameters - An object containing all parameters (see above)\n * @param scene The scene linked to this pipeline\n * @param ratio The size of the postprocesses (0.5 means that your postprocess will have a width = canvas.width 0.5 and a height = canvas.height 0.5)\n * @param cameras The array of cameras that the rendering pipeline will be attached to\n */\n constructor(name, parameters, scene, ratio = 1.0, cameras) {\n super(scene.getEngine(), name);\n // Lens effects can be of the following:\n // - chromatic aberration (slight shift of RGB colors)\n // - blur on the edge of the lens\n // - lens distortion\n // - depth-of-field blur & highlights enhancing\n // - depth-of-field 'bokeh' effect (shapes appearing in blurred areas)\n // - grain effect (noise or custom texture)\n // Two additional texture samplers are needed:\n // - depth map (for depth-of-field)\n // - grain texture\n /**\n * @ignore\n * The chromatic aberration PostProcess id in the pipeline\n */\n this.LensChromaticAberrationEffect = \"LensChromaticAberrationEffect\";\n /**\n * @ignore\n * The highlights enhancing PostProcess id in the pipeline\n */\n this.HighlightsEnhancingEffect = \"HighlightsEnhancingEffect\";\n /**\n * @ignore\n * The depth-of-field PostProcess id in the pipeline\n */\n this.LensDepthOfFieldEffect = \"LensDepthOfFieldEffect\";\n this._pentagonBokehIsEnabled = false;\n this._scene = scene;\n // Fetch texture samplers\n this._depthTexture = scene.enableDepthRenderer().getDepthMap(); // Force depth renderer \"on\"\n if (parameters.grain_texture) {\n this._grainTexture = parameters.grain_texture;\n }\n else {\n this._createGrainTexture();\n }\n // save parameters\n this._edgeBlur = parameters.edge_blur ? parameters.edge_blur : 0;\n this._grainAmount = parameters.grain_amount ? parameters.grain_amount : 0;\n this._chromaticAberration = parameters.chromatic_aberration ? parameters.chromatic_aberration : 0;\n this._distortion = parameters.distortion ? parameters.distortion : 0;\n this._highlightsGain = parameters.dof_gain !== undefined ? parameters.dof_gain : -1;\n this._highlightsThreshold = parameters.dof_threshold ? parameters.dof_threshold : 1;\n this._dofDistance = parameters.dof_focus_distance !== undefined ? parameters.dof_focus_distance : -1;\n this._dofAperture = parameters.dof_aperture ? parameters.dof_aperture : 1;\n this._dofDarken = parameters.dof_darken ? parameters.dof_darken : 0;\n this._dofPentagon = parameters.dof_pentagon !== undefined ? parameters.dof_pentagon : true;\n this._blurNoise = parameters.blur_noise !== undefined ? parameters.blur_noise : true;\n // Create effects\n this._createChromaticAberrationPostProcess(ratio);\n this._createHighlightsPostProcess(ratio);\n this._createDepthOfFieldPostProcess(ratio / 4);\n // Set up pipeline\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.LensChromaticAberrationEffect, () => {\n return this._chromaticAberrationPostProcess;\n }, true));\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.HighlightsEnhancingEffect, () => {\n return this._highlightsPostProcess;\n }, true));\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.LensDepthOfFieldEffect, () => {\n return this._depthOfFieldPostProcess;\n }, true));\n if (this._highlightsGain === -1) {\n this._disableEffect(this.HighlightsEnhancingEffect, null);\n }\n // Finish\n scene.postProcessRenderPipelineManager.addPipeline(this);\n if (cameras) {\n scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(name, cameras);\n }\n }\n /**\n * Get the class name\n * @returns \"LensRenderingPipeline\"\n */\n getClassName() {\n return \"LensRenderingPipeline\";\n }\n // Properties\n /**\n * Gets associated scene\n */\n get scene() {\n return this._scene;\n }\n /**\n * Gets or sets the edge blur\n */\n get edgeBlur() {\n return this._edgeBlur;\n }\n set edgeBlur(value) {\n this.setEdgeBlur(value);\n }\n /**\n * Gets or sets the grain amount\n */\n get grainAmount() {\n return this._grainAmount;\n }\n set grainAmount(value) {\n this.setGrainAmount(value);\n }\n /**\n * Gets or sets the chromatic aberration amount\n */\n get chromaticAberration() {\n return this._chromaticAberration;\n }\n set chromaticAberration(value) {\n this.setChromaticAberration(value);\n }\n /**\n * Gets or sets the depth of field aperture\n */\n get dofAperture() {\n return this._dofAperture;\n }\n set dofAperture(value) {\n this.setAperture(value);\n }\n /**\n * Gets or sets the edge distortion\n */\n get edgeDistortion() {\n return this._distortion;\n }\n set edgeDistortion(value) {\n this.setEdgeDistortion(value);\n }\n /**\n * Gets or sets the depth of field distortion\n */\n get dofDistortion() {\n return this._dofDistance;\n }\n set dofDistortion(value) {\n this.setFocusDistance(value);\n }\n /**\n * Gets or sets the darken out of focus amount\n */\n get darkenOutOfFocus() {\n return this._dofDarken;\n }\n set darkenOutOfFocus(value) {\n this.setDarkenOutOfFocus(value);\n }\n /**\n * Gets or sets a boolean indicating if blur noise is enabled\n */\n get blurNoise() {\n return this._blurNoise;\n }\n set blurNoise(value) {\n this._blurNoise = value;\n }\n /**\n * Gets or sets a boolean indicating if pentagon bokeh is enabled\n */\n get pentagonBokeh() {\n return this._pentagonBokehIsEnabled;\n }\n set pentagonBokeh(value) {\n if (value) {\n this.enablePentagonBokeh();\n }\n else {\n this.disablePentagonBokeh();\n }\n }\n /**\n * Gets or sets the highlight grain amount\n */\n get highlightsGain() {\n return this._highlightsGain;\n }\n set highlightsGain(value) {\n this.setHighlightsGain(value);\n }\n /**\n * Gets or sets the highlight threshold\n */\n get highlightsThreshold() {\n return this._highlightsThreshold;\n }\n set highlightsThreshold(value) {\n this.setHighlightsThreshold(value);\n }\n // public methods (self explanatory)\n /**\n * Sets the amount of blur at the edges\n * @param amount blur amount\n */\n setEdgeBlur(amount) {\n this._edgeBlur = amount;\n }\n /**\n * Sets edge blur to 0\n */\n disableEdgeBlur() {\n this._edgeBlur = 0;\n }\n /**\n * Sets the amount of grain\n * @param amount Amount of grain\n */\n setGrainAmount(amount) {\n this._grainAmount = amount;\n }\n /**\n * Set grain amount to 0\n */\n disableGrain() {\n this._grainAmount = 0;\n }\n /**\n * Sets the chromatic aberration amount\n * @param amount amount of chromatic aberration\n */\n setChromaticAberration(amount) {\n this._chromaticAberration = amount;\n }\n /**\n * Sets chromatic aberration amount to 0\n */\n disableChromaticAberration() {\n this._chromaticAberration = 0;\n }\n /**\n * Sets the EdgeDistortion amount\n * @param amount amount of EdgeDistortion\n */\n setEdgeDistortion(amount) {\n this._distortion = amount;\n }\n /**\n * Sets edge distortion to 0\n */\n disableEdgeDistortion() {\n this._distortion = 0;\n }\n /**\n * Sets the FocusDistance amount\n * @param amount amount of FocusDistance\n */\n setFocusDistance(amount) {\n this._dofDistance = amount;\n }\n /**\n * Disables depth of field\n */\n disableDepthOfField() {\n this._dofDistance = -1;\n }\n /**\n * Sets the Aperture amount\n * @param amount amount of Aperture\n */\n setAperture(amount) {\n this._dofAperture = amount;\n }\n /**\n * Sets the DarkenOutOfFocus amount\n * @param amount amount of DarkenOutOfFocus\n */\n setDarkenOutOfFocus(amount) {\n this._dofDarken = amount;\n }\n /**\n * Creates a pentagon bokeh effect\n */\n enablePentagonBokeh() {\n this._highlightsPostProcess.updateEffect(\"#define PENTAGON\\n\");\n this._pentagonBokehIsEnabled = true;\n }\n /**\n * Disables the pentagon bokeh effect\n */\n disablePentagonBokeh() {\n this._pentagonBokehIsEnabled = false;\n this._highlightsPostProcess.updateEffect();\n }\n /**\n * Enables noise blur\n */\n enableNoiseBlur() {\n this._blurNoise = true;\n }\n /**\n * Disables noise blur\n */\n disableNoiseBlur() {\n this._blurNoise = false;\n }\n /**\n * Sets the HighlightsGain amount\n * @param amount amount of HighlightsGain\n */\n setHighlightsGain(amount) {\n this._highlightsGain = amount;\n }\n /**\n * Sets the HighlightsThreshold amount\n * @param amount amount of HighlightsThreshold\n */\n setHighlightsThreshold(amount) {\n if (this._highlightsGain === -1) {\n this._highlightsGain = 1.0;\n }\n this._highlightsThreshold = amount;\n }\n /**\n * Disables highlights\n */\n disableHighlights() {\n this._highlightsGain = -1;\n }\n /**\n * Removes the internal pipeline assets and detaches the pipeline from the scene cameras\n * @param disableDepthRender If the scene's depth rendering should be disabled (default: false)\n */\n dispose(disableDepthRender = false) {\n this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);\n this._chromaticAberrationPostProcess = null;\n this._highlightsPostProcess = null;\n this._depthOfFieldPostProcess = null;\n this._grainTexture.dispose();\n if (disableDepthRender) {\n this._scene.disableDepthRenderer();\n }\n }\n // colors shifting and distortion\n _createChromaticAberrationPostProcess(ratio) {\n this._chromaticAberrationPostProcess = new PostProcess(\"LensChromaticAberration\", \"chromaticAberration\", [\"chromatic_aberration\", \"screen_width\", \"screen_height\", \"direction\", \"radialIntensity\", \"centerPosition\"], // uniforms\n [], // samplers\n ratio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);\n this._chromaticAberrationPostProcess.onApply = (effect) => {\n effect.setFloat(\"chromatic_aberration\", this._chromaticAberration);\n effect.setFloat(\"screen_width\", this._scene.getEngine().getRenderWidth());\n effect.setFloat(\"screen_height\", this._scene.getEngine().getRenderHeight());\n effect.setFloat(\"radialIntensity\", 1);\n effect.setFloat2(\"direction\", 17, 17);\n effect.setFloat2(\"centerPosition\", 0.5, 0.5);\n };\n }\n // highlights enhancing\n _createHighlightsPostProcess(ratio) {\n this._highlightsPostProcess = new PostProcess(\"LensHighlights\", \"lensHighlights\", [\"gain\", \"threshold\", \"screen_width\", \"screen_height\"], // uniforms\n [], // samplers\n ratio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, this._dofPentagon ? \"#define PENTAGON\\n\" : \"\");\n this._highlightsPostProcess.externalTextureSamplerBinding = true;\n this._highlightsPostProcess.onApply = (effect) => {\n effect.setFloat(\"gain\", this._highlightsGain);\n effect.setFloat(\"threshold\", this._highlightsThreshold);\n effect.setTextureFromPostProcess(\"textureSampler\", this._chromaticAberrationPostProcess);\n effect.setFloat(\"screen_width\", this._scene.getEngine().getRenderWidth());\n effect.setFloat(\"screen_height\", this._scene.getEngine().getRenderHeight());\n };\n }\n // colors shifting and distortion\n _createDepthOfFieldPostProcess(ratio) {\n this._depthOfFieldPostProcess = new PostProcess(\"LensDepthOfField\", \"depthOfField\", [\n \"grain_amount\",\n \"blur_noise\",\n \"screen_width\",\n \"screen_height\",\n \"distortion\",\n \"dof_enabled\",\n \"screen_distance\",\n \"aperture\",\n \"darken\",\n \"edge_blur\",\n \"highlights\",\n \"near\",\n \"far\",\n ], [\"depthSampler\", \"grainSampler\", \"highlightsSampler\"], ratio, null, Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);\n this._depthOfFieldPostProcess.externalTextureSamplerBinding = true;\n this._depthOfFieldPostProcess.onApply = (effect) => {\n effect.setTexture(\"depthSampler\", this._depthTexture);\n effect.setTexture(\"grainSampler\", this._grainTexture);\n effect.setTextureFromPostProcess(\"textureSampler\", this._highlightsPostProcess);\n effect.setTextureFromPostProcess(\"highlightsSampler\", this._depthOfFieldPostProcess);\n effect.setFloat(\"grain_amount\", this._grainAmount);\n effect.setBool(\"blur_noise\", this._blurNoise);\n effect.setFloat(\"screen_width\", this._scene.getEngine().getRenderWidth());\n effect.setFloat(\"screen_height\", this._scene.getEngine().getRenderHeight());\n effect.setFloat(\"distortion\", this._distortion);\n effect.setBool(\"dof_enabled\", this._dofDistance !== -1);\n effect.setFloat(\"screen_distance\", 1.0 / (0.1 - 1.0 / this._dofDistance));\n effect.setFloat(\"aperture\", this._dofAperture);\n effect.setFloat(\"darken\", this._dofDarken);\n effect.setFloat(\"edge_blur\", this._edgeBlur);\n effect.setBool(\"highlights\", this._highlightsGain !== -1);\n if (this._scene.activeCamera) {\n effect.setFloat(\"near\", this._scene.activeCamera.minZ);\n effect.setFloat(\"far\", this._scene.activeCamera.maxZ);\n }\n };\n }\n // creates a black and white random noise texture, 512x512\n _createGrainTexture() {\n const size = 512;\n this._grainTexture = new DynamicTexture(\"LensNoiseTexture\", size, this._scene, false, Texture.BILINEAR_SAMPLINGMODE);\n this._grainTexture.wrapU = Texture.WRAP_ADDRESSMODE;\n this._grainTexture.wrapV = Texture.WRAP_ADDRESSMODE;\n const context = this._grainTexture.getContext();\n const rand = (min, max) => {\n return Math.random() * (max - min) + min;\n };\n let value;\n for (let x = 0; x < size; x++) {\n for (let y = 0; y < size; y++) {\n value = Math.floor(rand(0.42, 0.58) * 255);\n context.fillStyle = \"rgb(\" + value + \", \" + value + \", \" + value + \")\";\n context.fillRect(x, y, 1, 1);\n }\n }\n this._grainTexture.update(false);\n }\n }\n\n /**\n * Contains all parameters needed for the prepass to perform\n * screen space subsurface scattering\n */\n class SSAO2Configuration {\n constructor() {\n /**\n * Is subsurface enabled\n */\n this.enabled = false;\n /**\n * Name of the configuration\n */\n this.name = \"ssao2\";\n /**\n * Textures that should be present in the MRT for this effect to work\n */\n this.texturesRequired = [6, 5];\n }\n }\n\n // Do not edit.\n const name$2z = \"ssao2PixelShader\";\n const shader$2z = `precision highp float;uniform sampler2D textureSampler;varying vec2 vUV;\n#ifdef SSAO\nfloat scales[16]=float[16](\n0.1,\n0.11406250000000001,\n0.131640625,\n0.15625,\n0.187890625,\n0.2265625,\n0.272265625,\n0.325,\n0.384765625,\n0.4515625,\n0.525390625,\n0.60625,\n0.694140625,\n0.7890625,\n0.891015625,\n1.0\n);uniform float near;uniform float radius;uniform sampler2D depthSampler;uniform sampler2D randomSampler;uniform sampler2D normalSampler;uniform float randTextureTiles;uniform float samplesFactor;uniform vec3 sampleSphere[SAMPLES];uniform float totalStrength;uniform float base;uniform float xViewport;uniform float yViewport;uniform mat3 depthProjection;uniform float maxZ;uniform float minZAspect;uniform vec2 texelSize;uniform mat4 projection;void main()\n{vec3 random=textureLod(randomSampler,vUV*randTextureTiles,0.0).rgb;float depth=textureLod(depthSampler,vUV,0.0).r;float depthSign=depth/abs(depth);depth=depth*depthSign;vec3 normal=textureLod(normalSampler,vUV,0.0).rgb;float occlusion=0.0;float correctedRadius=min(radius,minZAspect*depth/near);vec3 vViewRay=vec3((vUV.x*2.0-1.0)*xViewport,(vUV.y*2.0-1.0)*yViewport,depthSign);vec3 vDepthFactor=depthProjection*vec3(1.0,1.0,depth);vec3 origin=vViewRay*vDepthFactor;vec3 rvec=random*2.0-1.0;rvec.z=0.0;float dotProduct=dot(rvec,normal);rvec=1.0-abs(dotProduct)>1e-2 ? rvec : vec3(-rvec.y,0.0,rvec.x);vec3 tangent=normalize(rvec-normal*dot(rvec,normal));vec3 bitangent=cross(normal,tangent);mat3 tbn=mat3(tangent,bitangent,normal);float difference;for (int i=0; i1.0 || offset.y>1.0) {continue;}\nfloat sampleDepth=abs(textureLod(depthSampler,offset.xy,0.0).r);difference=depthSign*samplePosition.z-sampleDepth;float rangeCheck=1.0-smoothstep(correctedRadius*0.5,correctedRadius,difference);occlusion+=step(EPSILON,difference)*rangeCheck;}\nocclusion=occlusion*(1.0-smoothstep(maxZ*0.75,maxZ,depth));float ao=1.0-totalStrength*occlusion*samplesFactor;float result=clamp(ao+base,0.0,1.0);gl_FragColor=vec4(vec3(result),1.0);}\n#endif\n#ifdef BLUR\nuniform float outSize;uniform float soften;uniform float tolerance;uniform int samples;\n#ifndef BLUR_BYPASS\nuniform sampler2D depthSampler;\n#ifdef BLUR_LEGACY\n#define inline\nfloat blur13Bilateral(sampler2D image,vec2 uv,vec2 step) {float result=0.0;vec2 off1=vec2(1.411764705882353)*step;vec2 off2=vec2(3.2941176470588234)*step;vec2 off3=vec2(5.176470588235294)*step;float compareDepth=abs(textureLod(depthSampler,uv,0.0).r);float sampleDepth;float weight;float weightSum=30.0;result+=textureLod(image,uv,0.0).r*30.0;sampleDepth=abs(textureLod(depthSampler,uv+off1,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+= weight;result+=textureLod(image,uv+off1,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv-off1,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+= weight;result+=textureLod(image,uv-off1,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv+off2,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv+off2,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv-off2,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv-off2,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv+off3,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv+off3,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv-off3,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv-off3,0.0).r*weight;return result/weightSum;}\n#endif\n#endif\nvoid main()\n{float result=0.0;\n#ifdef BLUR_BYPASS\nresult=textureLod(textureSampler,vUV,0.0).r;\n#else\n#ifdef BLUR_H\nvec2 step=vec2(1.0/outSize,0.0);\n#else\nvec2 step=vec2(0.0,1.0/outSize);\n#endif\n#ifdef BLUR_LEGACY\nresult=blur13Bilateral(textureSampler,vUV,step);\n#else\nfloat compareDepth=abs(textureLod(depthSampler,vUV,0.0).r);float weightSum=0.0;for (int i=-samples; i {\n return this._originalColorPostProcess;\n }, true));\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAORenderEffect, () => {\n return this._ssaoPostProcess;\n }, true));\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOBlurHRenderEffect, () => {\n return this._blurHPostProcess;\n }, true));\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOBlurVRenderEffect, () => {\n return this._blurVPostProcess;\n }, true));\n this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOCombineRenderEffect, () => {\n return this._ssaoCombinePostProcess;\n }, true));\n // Finish\n scene.postProcessRenderPipelineManager.addPipeline(this);\n if (cameras) {\n scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(name, cameras);\n }\n }\n // Public Methods\n /**\n * Get the class name\n * @returns \"SSAO2RenderingPipeline\"\n */\n getClassName() {\n return \"SSAO2RenderingPipeline\";\n }\n /**\n * Removes the internal pipeline assets and detaches the pipeline from the scene cameras\n * @param disableGeometryBufferRenderer\n */\n dispose(disableGeometryBufferRenderer = false) {\n for (let i = 0; i < this._scene.cameras.length; i++) {\n const camera = this._scene.cameras[i];\n this._originalColorPostProcess.dispose(camera);\n this._ssaoPostProcess.dispose(camera);\n this._blurHPostProcess.dispose(camera);\n this._blurVPostProcess.dispose(camera);\n this._ssaoCombinePostProcess.dispose(camera);\n }\n this._randomTexture.dispose();\n if (disableGeometryBufferRenderer) {\n this._scene.disableGeometryBufferRenderer();\n }\n this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);\n super.dispose();\n }\n // Private Methods\n /** @internal */\n _rebuild() {\n super._rebuild();\n }\n _getSamplersForBlur(disabled) {\n return disabled ? [\"textureSampler\"] : [\"textureSampler\", \"depthSampler\"];\n }\n _getDefinesForBlur(bilateral, disabled) {\n let define = \"#define BLUR\\n\";\n if (disabled) {\n define += \"#define BLUR_BYPASS\\n\";\n }\n if (!bilateral) {\n define += \"#define BLUR_LEGACY\\n\";\n }\n return { h: define + \"#define BLUR_H\\n\", v: define };\n }\n _createBlurPostProcess(ssaoRatio, blurRatio, textureType) {\n const defines = this._getDefinesForBlur(this.expensiveBlur, this.bypassBlur);\n const samplers = this._getSamplersForBlur(this.bypassBlur);\n this._blurHPostProcess = this._createBlurFilter(\"BlurH\", samplers, ssaoRatio, defines.h, textureType, true);\n this._blurVPostProcess = this._createBlurFilter(\"BlurV\", samplers, blurRatio, defines.v, textureType, false);\n }\n _createBlurFilter(name, samplers, ratio, defines, textureType, horizontal) {\n const blurFilter = new PostProcess(name, \"ssao2\", [\"outSize\", \"samples\", \"soften\", \"tolerance\"], samplers, ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, defines, textureType);\n blurFilter.onApply = (effect) => {\n if (!this._scene.activeCamera) {\n return;\n }\n const ssaoCombineSize = horizontal ? this._ssaoCombinePostProcess.width : this._ssaoCombinePostProcess.height;\n const originalColorSize = horizontal ? this._originalColorPostProcess.width : this._originalColorPostProcess.height;\n effect.setFloat(\"outSize\", ssaoCombineSize > 0 ? ssaoCombineSize : originalColorSize);\n effect.setInt(\"samples\", this.bilateralSamples);\n effect.setFloat(\"soften\", this.bilateralSoften);\n effect.setFloat(\"tolerance\", this.bilateralTolerance);\n if (this._geometryBufferRenderer) {\n effect.setTexture(\"depthSampler\", this._geometryBufferRenderer.getGBuffer().textures[0]);\n }\n else if (this._prePassRenderer) {\n effect.setTexture(\"depthSampler\", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(5)]);\n }\n };\n blurFilter.samples = this.textureSamples;\n return blurFilter;\n }\n //Van der Corput radical inverse\n _radicalInverse_VdC(i) {\n this._bits[0] = i;\n this._bits[0] = ((this._bits[0] << 16) | (this._bits[0] >> 16)) >>> 0;\n this._bits[0] = ((this._bits[0] & 0x55555555) << 1) | (((this._bits[0] & 0xaaaaaaaa) >>> 1) >>> 0);\n this._bits[0] = ((this._bits[0] & 0x33333333) << 2) | (((this._bits[0] & 0xcccccccc) >>> 2) >>> 0);\n this._bits[0] = ((this._bits[0] & 0x0f0f0f0f) << 4) | (((this._bits[0] & 0xf0f0f0f0) >>> 4) >>> 0);\n this._bits[0] = ((this._bits[0] & 0x00ff00ff) << 8) | (((this._bits[0] & 0xff00ff00) >>> 8) >>> 0);\n return this._bits[0] * 2.3283064365386963e-10; // / 0x100000000 or / 4294967296\n }\n _hammersley(i, n) {\n return [i / n, this._radicalInverse_VdC(i)];\n }\n _hemisphereSample_uniform(u, v) {\n const phi = v * 2.0 * Math.PI;\n // rejecting samples that are close to tangent plane to avoid z-fighting artifacts\n const cosTheta = 1.0 - u * 0.85;\n const sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);\n return new Vector3(Math.cos(phi) * sinTheta, Math.sin(phi) * sinTheta, cosTheta);\n }\n _generateHemisphere() {\n const numSamples = this.samples;\n const result = [];\n let vector;\n let i = 0;\n while (i < numSamples) {\n if (numSamples < 16) {\n vector = this._hemisphereSample_uniform(Math.random(), Math.random());\n }\n else {\n const rand = this._hammersley(i, numSamples);\n vector = this._hemisphereSample_uniform(rand[0], rand[1]);\n }\n result.push(vector.x, vector.y, vector.z);\n i++;\n }\n return result;\n }\n _getDefinesForSSAO() {\n const defines = `#define SSAO\\n#define SAMPLES ${this.samples}\\n#define EPSILON ${this.epsilon.toFixed(4)}`;\n return defines;\n }\n _createSSAOPostProcess(ratio, textureType) {\n this._sampleSphere = this._generateHemisphere();\n const defines = this._getDefinesForSSAO();\n const samplers = [\"randomSampler\", \"depthSampler\", \"normalSampler\"];\n this._ssaoPostProcess = new PostProcess(\"ssao2\", \"ssao2\", [\n \"sampleSphere\",\n \"samplesFactor\",\n \"randTextureTiles\",\n \"totalStrength\",\n \"radius\",\n \"base\",\n \"range\",\n \"projection\",\n \"near\",\n \"texelSize\",\n \"xViewport\",\n \"yViewport\",\n \"maxZ\",\n \"minZAspect\",\n \"depthProjection\",\n ], samplers, ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, defines, textureType);\n this._ssaoPostProcess.onApply = (effect) => {\n var _a, _b, _c, _d;\n if (!this._scene.activeCamera) {\n return;\n }\n effect.setArray3(\"sampleSphere\", this._sampleSphere);\n effect.setFloat(\"randTextureTiles\", 32.0);\n effect.setFloat(\"samplesFactor\", 1 / this.samples);\n effect.setFloat(\"totalStrength\", this.totalStrength);\n effect.setFloat2(\"texelSize\", 1 / this._ssaoPostProcess.width, 1 / this._ssaoPostProcess.height);\n effect.setFloat(\"radius\", this.radius);\n effect.setFloat(\"maxZ\", this.maxZ);\n effect.setFloat(\"minZAspect\", this.minZAspect);\n effect.setFloat(\"base\", this.base);\n effect.setFloat(\"near\", this._scene.activeCamera.minZ);\n if (this._scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA) {\n effect.setMatrix3x3(\"depthProjection\", SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION);\n effect.setFloat(\"xViewport\", Math.tan(this._scene.activeCamera.fov / 2) * this._scene.getEngine().getAspectRatio(this._scene.activeCamera, true));\n effect.setFloat(\"yViewport\", Math.tan(this._scene.activeCamera.fov / 2));\n }\n else {\n const halfWidth = this._scene.getEngine().getRenderWidth() / 2.0;\n const halfHeight = this._scene.getEngine().getRenderHeight() / 2.0;\n const orthoLeft = (_a = this._scene.activeCamera.orthoLeft) !== null && _a !== void 0 ? _a : -halfWidth;\n const orthoRight = (_b = this._scene.activeCamera.orthoRight) !== null && _b !== void 0 ? _b : halfWidth;\n const orthoBottom = (_c = this._scene.activeCamera.orthoBottom) !== null && _c !== void 0 ? _c : -halfHeight;\n const orthoTop = (_d = this._scene.activeCamera.orthoTop) !== null && _d !== void 0 ? _d : halfHeight;\n effect.setMatrix3x3(\"depthProjection\", SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION);\n effect.setFloat(\"xViewport\", (orthoRight - orthoLeft) * 0.5);\n effect.setFloat(\"yViewport\", (orthoTop - orthoBottom) * 0.5);\n }\n effect.setMatrix(\"projection\", this._scene.getProjectionMatrix());\n if (this._geometryBufferRenderer) {\n effect.setTexture(\"depthSampler\", this._geometryBufferRenderer.getGBuffer().textures[0]);\n effect.setTexture(\"normalSampler\", this._geometryBufferRenderer.getGBuffer().textures[1]);\n }\n else if (this._prePassRenderer) {\n effect.setTexture(\"depthSampler\", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(5)]);\n effect.setTexture(\"normalSampler\", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(6)]);\n }\n effect.setTexture(\"randomSampler\", this._randomTexture);\n };\n this._ssaoPostProcess.samples = this.textureSamples;\n if (!this._forceGeometryBuffer) {\n this._ssaoPostProcess._prePassEffectConfiguration = new SSAO2Configuration();\n }\n }\n _createSSAOCombinePostProcess(ratio, textureType) {\n this._ssaoCombinePostProcess = new PostProcess(\"ssaoCombine\", \"ssaoCombine\", [], [\"originalColor\", \"viewport\"], ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, undefined, textureType);\n this._ssaoCombinePostProcess.onApply = (effect) => {\n const viewport = this._scene.activeCamera.viewport;\n effect.setVector4(\"viewport\", TmpVectors.Vector4[0].copyFromFloats(viewport.x, viewport.y, viewport.width, viewport.height));\n effect.setTextureFromPostProcessOutput(\"originalColor\", this._originalColorPostProcess);\n };\n this._ssaoCombinePostProcess.samples = this.textureSamples;\n }\n _createRandomTexture() {\n const size = 128;\n this._randomTexture = new DynamicTexture(\"SSAORandomTexture\", size, this._scene, false, Texture.BILINEAR_SAMPLINGMODE);\n this._randomTexture.wrapU = Texture.WRAP_ADDRESSMODE;\n this._randomTexture.wrapV = Texture.WRAP_ADDRESSMODE;\n const context = this._randomTexture.getContext();\n const rand = (min, max) => {\n return Math.random() * (max - min) + min;\n };\n const randVector = Vector3.Zero();\n for (let x = 0; x < size; x++) {\n for (let y = 0; y < size; y++) {\n randVector.x = rand(0.0, 1.0);\n randVector.y = rand(0.0, 1.0);\n randVector.z = 0.0;\n randVector.normalize();\n randVector.scaleInPlace(255);\n randVector.x = Math.floor(randVector.x);\n randVector.y = Math.floor(randVector.y);\n context.fillStyle = \"rgb(\" + randVector.x + \", \" + randVector.y + \", \" + randVector.z + \")\";\n context.fillRect(x, y, 1, 1);\n }\n }\n this._randomTexture.update(false);\n }\n /**\n * Serialize the rendering pipeline (Used when exporting)\n * @returns the serialized object\n */\n serialize() {\n const serializationObject = SerializationHelper.Serialize(this);\n serializationObject.customType = \"SSAO2RenderingPipeline\";\n return serializationObject;\n }\n /**\n * Parse the serialized pipeline\n * @param source Source pipeline.\n * @param scene The scene to load the pipeline to.\n * @param rootUrl The URL of the serialized pipeline.\n * @returns An instantiated pipeline from the serialized object.\n */\n static Parse(source, scene, rootUrl) {\n return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio, undefined, source._forceGeometryBuffer, source._textureType), source, scene, rootUrl);\n }\n }\n SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION = [1, 0, 0, 0, 1, 0, 0, 0, 1];\n SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION = [0, 0, 0, 0, 0, 0, 1, 1, 1];\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"totalStrength\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"maxZ\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"minZAspect\", void 0);\n __decorate$1([\n serialize(\"epsilon\")\n ], SSAO2RenderingPipeline.prototype, \"_epsilon\", void 0);\n __decorate$1([\n serialize(\"samples\")\n ], SSAO2RenderingPipeline.prototype, \"_samples\", void 0);\n __decorate$1([\n serialize(\"textureSamples\")\n ], SSAO2RenderingPipeline.prototype, \"_textureSamples\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"_forceGeometryBuffer\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"_ratio\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"_textureType\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"radius\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"base\", void 0);\n __decorate$1([\n serialize(\"bypassBlur\")\n ], SSAO2RenderingPipeline.prototype, \"_bypassBlur\", void 0);\n __decorate$1([\n serialize(\"expensiveBlur\")\n ], SSAO2RenderingPipeline.prototype, \"_expensiveBlur\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"bilateralSamples\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"bilateralSoften\", void 0);\n __decorate$1([\n serialize()\n ], SSAO2RenderingPipeline.prototype, \"bilateralTolerance\", void 0);\n RegisterClass(\"BABYLON.SSAO2RenderingPipeline\", SSAO2RenderingPipeline);\n\n // Do not edit.\n const name$2B = \"fxaaPixelShader\";\n const shader$2B = `#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)\n#else\n#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)\n#endif\nuniform sampler2D textureSampler;uniform vec2 texelSize;varying vec2 vUV;varying vec2 sampleCoordS;varying vec2 sampleCoordE;varying vec2 sampleCoordN;varying vec2 sampleCoordW;varying vec2 sampleCoordNW;varying vec2 sampleCoordSE;varying vec2 sampleCoordNE;varying vec2 sampleCoordSW;const float fxaaQualitySubpix=1.0;const float fxaaQualityEdgeThreshold=0.166;const float fxaaQualityEdgeThresholdMin=0.0833;const vec3 kLumaCoefficients=vec3(0.2126,0.7152,0.0722);\n#define FxaaLuma(rgba) dot(rgba.rgb,kLumaCoefficients)\nvoid main(){vec2 posM;posM.x=vUV.x;posM.y=vUV.y;vec4 rgbyM=TEXTUREFUNC(textureSampler,vUV,0.0);float lumaM=FxaaLuma(rgbyM);float lumaS=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordS,0.0));float lumaE=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordE,0.0));float lumaN=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordN,0.0));float lumaW=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordW,0.0));float maxSM=max(lumaS,lumaM);float minSM=min(lumaS,lumaM);float maxESM=max(lumaE,maxSM);float minESM=min(lumaE,minSM);float maxWN=max(lumaN,lumaW);float minWN=min(lumaN,lumaW);float rangeMax=max(maxWN,maxESM);float rangeMin=min(minWN,minESM);float rangeMaxScaled=rangeMax*fxaaQualityEdgeThreshold;float range=rangeMax-rangeMin;float rangeMaxClamped=max(fxaaQualityEdgeThresholdMin,rangeMaxScaled);\n#ifndef MALI\nif(range=edgeVert;float subpixA=subpixNSWE*2.0+subpixNWSWNESE;if (!horzSpan)\n{lumaN=lumaW;}\nif (!horzSpan) \n{lumaS=lumaE;}\nif (horzSpan) \n{lengthSign=texelSize.y;}\nfloat subpixB=(subpixA*(1.0/12.0))-lumaM;float gradientN=lumaN-lumaM;float gradientS=lumaS-lumaM;float lumaNN=lumaN+lumaM;float lumaSS=lumaS+lumaM;bool pairN=abs(gradientN)>=abs(gradientS);float gradient=max(abs(gradientN),abs(gradientS));if (pairN)\n{lengthSign=-lengthSign;}\nfloat subpixC=clamp(abs(subpixB)*subpixRcpRange,0.0,1.0);vec2 posB;posB.x=posM.x;posB.y=posM.y;vec2 offNP;offNP.x=(!horzSpan) ? 0.0 : texelSize.x;offNP.y=(horzSpan) ? 0.0 : texelSize.y;if (!horzSpan) \n{posB.x+=lengthSign*0.5;}\nif (horzSpan)\n{posB.y+=lengthSign*0.5;}\nvec2 posN;posN.x=posB.x-offNP.x*1.5;posN.y=posB.y-offNP.y*1.5;vec2 posP;posP.x=posB.x+offNP.x*1.5;posP.y=posB.y+offNP.y*1.5;float subpixD=((-2.0)*subpixC)+3.0;float lumaEndN=FxaaLuma(TEXTUREFUNC(textureSampler,posN,0.0));float subpixE=subpixC*subpixC;float lumaEndP=FxaaLuma(TEXTUREFUNC(textureSampler,posP,0.0));if (!pairN) \n{lumaNN=lumaSS;}\nfloat gradientScaled=gradient*1.0/4.0;float lumaMM=lumaM-lumaNN*0.5;float subpixF=subpixD*subpixE;bool lumaMLTZero=lumaMM<0.0;lumaEndN-=lumaNN*0.5;lumaEndP-=lumaNN*0.5;bool doneN=abs(lumaEndN)>=gradientScaled;bool doneP=abs(lumaEndP)>=gradientScaled;if (!doneN) \n{posN.x-=offNP.x*3.0;}\nif (!doneN) \n{posN.y-=offNP.y*3.0;}\nbool doneNP=(!doneN) || (!doneP);if (!doneP) \n{posP.x+=offNP.x*3.0;}\nif (!doneP)\n{posP.y+=offNP.y*3.0;}\nif (doneNP)\n{if (!doneN) lumaEndN=FxaaLuma(TEXTUREFUNC(textureSampler,posN.xy,0.0));if (!doneP) lumaEndP=FxaaLuma(TEXTUREFUNC(textureSampler,posP.xy,0.0));if (!doneN) lumaEndN=lumaEndN-lumaNN*0.5;if (!doneP) lumaEndP=lumaEndP-lumaNN*0.5;doneN=abs(lumaEndN)>=gradientScaled;doneP=abs(lumaEndP)>=gradientScaled;if (!doneN) posN.x-=offNP.x*12.0;if (!doneN) posN.y-=offNP.y*12.0;doneNP=(!doneN) || (!doneP);if (!doneP) posP.x+=offNP.x*12.0;if (!doneP) posP.y+=offNP.y*12.0;}\nfloat dstN=posM.x-posN.x;float dstP=posP.x-posM.x;if (!horzSpan)\n{dstN=posM.y-posN.y;}\nif (!horzSpan) \n{dstP=posP.y-posM.y;}\nbool goodSpanN=(lumaEndN<0.0) != lumaMLTZero;float spanLength=(dstP+dstN);bool goodSpanP=(lumaEndP<0.0) != lumaMLTZero;float spanLengthRcp=1.0/spanLength;bool directionN=dstN {\n const texelSize = this.texelSize;\n effect.setFloat2(\"texelSize\", texelSize.x, texelSize.y);\n });\n }\n _getDefines() {\n const engine = this.getEngine();\n if (!engine) {\n return null;\n }\n const glInfo = engine.getGlInfo();\n if (glInfo && glInfo.renderer && glInfo.renderer.toLowerCase().indexOf(\"mali\") > -1) {\n return \"#define MALI 1\\n\";\n }\n return null;\n }\n /**\n * @internal\n */\n static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {\n return SerializationHelper.Parse(() => {\n return new FxaaPostProcess(parsedPostProcess.name, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, scene.getEngine(), parsedPostProcess.reusable);\n }, parsedPostProcess, scene, rootUrl);\n }\n }\n RegisterClass(\"BABYLON.FxaaPostProcess\", FxaaPostProcess);\n\n const SKYBOX_SIZE = 1000;\n const SamplingModeMap = {\n [exports.eTextureSamplingMode.nearest]: Texture.NEAREST_SAMPLINGMODE,\n [exports.eTextureSamplingMode.bilinear]: Texture.BILINEAR_SAMPLINGMODE,\n [exports.eTextureSamplingMode.trilinear]: Texture.TRILINEAR_SAMPLINGMODE,\n };\n class SceneRenderer extends Renderer {\n constructor(viewer, scene, gui, renderManager) {\n super(viewer, scene);\n this.gui = gui;\n this.renderManager = renderManager;\n this.yVector = new Vector3(0, 1, 0);\n this.modelToken = Token.SceneNode;\n }\n handlesNode(node) {\n return isSceneNode(node) && !node.isNested();\n }\n update3dInternal(node) {\n var _a;\n this.processEnvironment(node);\n //we create a transform node that ends up holding all space nodes in the scene\n //this creates parity with nested scenes and gives us something to transform in WebXR without re-parenting anything\n let tnode = this.get3d(node);\n if (!tnode) {\n tnode = new TransformNode(node._dynamicId, this.scene);\n this.set3d(node, tnode);\n if (!this.viewer.options.forceDisablePostProcess && this.scene.activeCamera) {\n if (node.enableFxaaPostProcess) {\n this.fxaaPostProcess = new FxaaPostProcess('fxaa', 1.0, this.scene.activeCamera, Texture.BILINEAR_SAMPLINGMODE, this.scene.getEngine());\n }\n if (node.enableLensEffectsPostProcess) {\n this.lensEffectPostProcess = new LensRenderingPipeline('lens', {\n edge_blur: 0.5,\n chromatic_aberration: 0.5,\n distortion: 0,\n dof_focus_distance: 200,\n dof_aperture: 5.0,\n grain_amount: 0.1,\n dof_pentagon: true,\n dof_gain: 1.0,\n dof_threshold: 1.0,\n dof_darken: 0,\n }, this.scene, 1.0, [this.scene.activeCamera]);\n }\n if (node.enableSSAOPostProcess) {\n this.ssaoPostProcess = new SSAO2RenderingPipeline('ssaopipeline', this.scene, 0.75);\n }\n }\n }\n if (node.changes.has('enableDeferredSceneUpdates')) {\n this.renderManager.maxRenderTime =\n node.enableDeferredSceneUpdates && !this.viewer.options.editorMode ? 20 : 20000;\n }\n if (node.changes.has('textureSamplingMode')) {\n const samplingMode = SamplingModeMap[node.textureSamplingMode];\n const materials = this.renderManager.material.getAllDefinedMaterials();\n materials.forEach(material => {\n material.getActiveTextures().forEach(texture => {\n if (texture) {\n texture.updateSamplingMode(samplingMode);\n }\n });\n });\n }\n if (node.changes.has('backgroundColor') || node.changes.has('background')) {\n if (node.background == exports.eBackground.color) {\n this.scene.clearColor = node.backgroundColor.toColor4();\n }\n else {\n this.scene.clearColor = new Color4(0, 0, 0, 0);\n }\n }\n if (node.changes.has('ambientColor')) {\n this.scene.ambientColor = node.ambientColor.toColor3();\n }\n if (node.changes.hasAny('renderMode', 'edgeWidth', 'edgeColor', 'edgeDisplayTolerance')) {\n this.viewer.setRenderMode(node.renderMode);\n }\n if (node.changes.has('enableHoverEffects')) {\n this.scene.constantlyUpdateMeshUnderPointer = node.enableHoverEffects;\n }\n if (node.changes.has('connectorSize')) {\n for (const c of node.getAllConnectors()) {\n this.viewer.rendererManager.connector.updateScale(c);\n }\n for (const c of node.getAllSketchControlPoints()) {\n this.viewer.rendererManager.controlPointRenderer.updateScale(c);\n }\n }\n if (node.changes.hasAny('dimensionUnitScalar', 'dimensionUnitSymbol')) {\n node.annotations.forEach(annotationNode => {\n if (isTrackedClass(annotationNode)) {\n annotationNode.isModified = true;\n }\n });\n }\n let gridNeedsRebuild = false;\n if (node.changes.hasAny('_forceGrid', 'gridSize', 'gridNormal', 'gridStepSize', 'gridMajorInterval', 'backgroundColor')) {\n if (node._forceGrid || node.enableGrid) {\n this.gui.disableGrid();\n gridNeedsRebuild = true;\n }\n if (node._forceGrid || node.enableGridAxes) {\n this.gui.disableGridAxes();\n gridNeedsRebuild = true;\n }\n }\n if (gridNeedsRebuild || node.changes.has('enableGrid')) {\n if (node._forceGrid || node.enableGrid) {\n this.gui.enableGrid(node, node._forceGrid || node.enableGridAxes);\n }\n else {\n this.gui.disableGrid();\n }\n }\n if (gridNeedsRebuild || node.changes.has('enableGridAxes')) {\n if (node._forceGrid || node.enableGridAxes) {\n this.gui.enableGridAxes(node);\n }\n else {\n this.gui.disableGridAxes();\n }\n }\n if (((_a = node._rootScene) === null || _a === void 0 ? void 0 : _a._dynamicId) === node._dynamicId) {\n const eventPayload = Object.fromEntries(node.changes);\n if (this.viewer.canvas) {\n this.viewer.canvas.dispatchEvent(new CustomEvent('kb3d.scenePropertyChange', { detail: eventPayload, bubbles: true }));\n }\n }\n }\n processEnvironment(node) {\n var _a;\n if (node.changes.has('environment') || node.changes.has('background') || node.changes.has('environmentBlur')) {\n const matService = (_a = node._manager) === null || _a === void 0 ? void 0 : _a.getService(Token.MaterialService);\n if (!matService) {\n throw Error('Cannot fetch environment material');\n }\n let path;\n if (node.background === exports.eBackground.environment) {\n if (node.environmentBlur < 0.15) {\n path = matService.getAbsoluteEnvironmentPath(node.environment, 3);\n }\n else {\n path = matService.getAbsoluteEnvironmentPath(node.environment, 1);\n }\n }\n else {\n path = matService.getAbsoluteEnvironmentPath(node.environment, 0);\n }\n if (path !== '' && this._envTexturePath !== path) {\n this._envTexturePath = path;\n if (this._envTexture) {\n this._envTexture.dispose();\n }\n let texture = undefined;\n if (path.match(/\\.dds(\\?.*)?$/) || path.match(/\\.env(\\?.*)?$/)) {\n texture = CubeTexture.CreateFromPrefilteredData(path, this.scene);\n }\n else if (path.match(/\\.hdr(\\?.*)?$/)) {\n texture = new HDRCubeTexture(path, this.scene, 128);\n }\n if (texture != null) {\n texture.gammaSpace = false;\n this.scene.environmentTexture = texture;\n this._envTexture = texture;\n }\n else {\n this.scene.environmentTexture = null;\n }\n }\n }\n if ((node.changes.has('background') || node.changes.has('environment')) &&\n node.background == exports.eBackground.environment &&\n this._envTexture) {\n if (!this.skybox) {\n this.skybox = this.scene.createDefaultSkybox(this._envTexture, true, SKYBOX_SIZE, node.environmentBlur);\n }\n else if (node.changes.has('environment')) {\n const skyMat = this.skybox.material;\n skyMat.reflectionTexture = this._envTexture.clone();\n skyMat.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;\n }\n }\n if (node.changes.has('background') && node.background != exports.eBackground.environment) {\n if (this.skybox) {\n this.skybox.dispose();\n this.skybox = null;\n }\n }\n if (node.changes.has('environmentBlur')) {\n if (this.skybox) {\n const skyMat = this.skybox.material;\n skyMat.microSurface = 1.0 - node.environmentBlur;\n }\n }\n if (node.changes.has('environmentIntensity')) {\n this.scene.environmentIntensity = node.environmentIntensity;\n }\n if (node.changes.has('environmentRotation') && this.scene.environmentTexture) {\n if (this.scene.environmentTexture instanceof CubeTexture ||\n this.scene.environmentTexture instanceof HDRCubeTexture) {\n this.scene.environmentTexture.rotationY = (node.environmentRotation * Math.PI) / 180;\n if (this.skybox) {\n this.skybox.rotationQuaternion = Quaternion.RotationAxis(this.yVector, (node.environmentRotation * Math.PI) / 180);\n }\n }\n }\n }\n dispose() {\n super.dispose();\n if (this._envTexture) {\n this._envTexture.dispose();\n }\n if (this.skybox) {\n this.skybox.dispose();\n }\n if (this.ssaoPostProcess) {\n this.ssaoPostProcess.dispose();\n }\n if (this.lensEffectPostProcess) {\n this.lensEffectPostProcess.dispose();\n }\n if (this.fxaaPostProcess) {\n this.fxaaPostProcess.dispose();\n }\n }\n getSkyBox() {\n return this.skybox;\n }\n }\n\n const blendModeMap = {\n [exports.eTextureBlendMode.normal]: 'source-over',\n [exports.eTextureBlendMode.multiply]: 'multiply',\n [exports.eTextureBlendMode.screen]: 'screen',\n [exports.eTextureBlendMode.overlay]: 'overlay',\n [exports.eTextureBlendMode.darken]: 'darken',\n [exports.eTextureBlendMode.lighten]: 'lighten',\n [exports.eTextureBlendMode.hue]: 'hue',\n [exports.eTextureBlendMode.saturation]: 'saturation',\n [exports.eTextureBlendMode.color]: 'color',\n [exports.eTextureBlendMode.luminosity]: 'luminosity',\n [exports.eTextureBlendMode.difference]: 'difference',\n [exports.eTextureBlendMode.mask]: 'destination-in',\n [exports.eTextureBlendMode.vector]: 'kb3d-vector', // special blending mode\n };\n const workingCanvases = [];\n /** Make sure to dispose the canvas after use! Otherwise you'll get a memory leak! */\n function getWorkingCanvas(width, height) {\n let canvas;\n for (let i = 0; i < workingCanvases.length; i++) {\n if (workingCanvases[i].width === 1) {\n canvas = workingCanvases[i];\n break;\n }\n }\n if (!canvas) {\n canvas = document.createElement('canvas');\n workingCanvases.push(canvas);\n }\n canvas.width = width;\n canvas.height = height;\n const context = canvas.getContext('2d', {\n willReadFrequently: true,\n });\n context.clearRect(0, 0, canvas.width, canvas.height);\n return canvas;\n }\n function disposeWorkingCanvas(canvas) {\n canvas.width = 1;\n canvas.height = 1;\n }\n class TextureLayerRenderer extends Renderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.TextureLayer;\n }\n paintTexture(texture, context, parameters, operations) { }\n getNativeSize(texture) {\n return { width: 1, height: 1 };\n }\n update3dInternal(node) {\n this.viewer.updateTextureWarnings();\n }\n textureHasContent(node) {\n return false;\n }\n calculateOffsetAndDimensions(texture, ctxWidth, ctxHeight, sourceWidth, sourceHeight) {\n let offsetX = texture.uOffset * ctxWidth, offsetY = texture.vOffset * ctxHeight, drawHeight = sourceHeight, drawWidth = sourceWidth;\n switch (texture.verticalFit) {\n case exports.eTextureFit.contain:\n if (sourceHeight < ctxHeight) {\n break;\n }\n // falls through\n case exports.eTextureFit.stretch:\n drawHeight = ctxHeight;\n }\n switch (texture.horizontalFit) {\n case exports.eTextureFit.contain:\n if (sourceWidth < ctxWidth) {\n break;\n }\n // falls through\n case exports.eTextureFit.stretch:\n drawWidth = ctxWidth;\n }\n if (texture.maintainAspect) {\n const minRatio = Math.min(drawWidth / sourceWidth, drawHeight / sourceHeight);\n drawWidth = minRatio * sourceWidth;\n drawHeight = minRatio * sourceHeight;\n }\n switch (texture.verticalAlign) {\n // left is offset with no adjustment\n case exports.eTextureVerticalAlign.bottom:\n offsetY += ctxHeight - drawHeight;\n break;\n case exports.eTextureVerticalAlign.middle:\n offsetY += (ctxHeight - drawHeight) / 2;\n break;\n }\n switch (texture.horizontalAlign) {\n // top is offset with no adjustment\n case exports.eTextureHorizontalAlign.right:\n offsetX += ctxWidth - drawWidth;\n break;\n case exports.eTextureHorizontalAlign.center:\n offsetX += (ctxWidth - drawWidth) / 2;\n break;\n }\n return {\n offsetX,\n offsetY,\n drawHeight,\n drawWidth,\n };\n }\n drawInBlendedContext(texture, context, parameters, cb, operations) {\n if (operations.mask) {\n const maskingCtx = operations.mask.context;\n delete operations.mask;\n // Transfer transform from context to masking context to mask what is drawn\n const transform = context.getTransform();\n maskingCtx.setTransform(transform);\n context.setTransform(1, 0, 0, 1, 0, 0);\n maskingCtx.globalCompositeOperation = 'source-in';\n cb(maskingCtx);\n maskingCtx.setTransform(1, 0, 0, 1, 0, 0);\n this.drawInBlendedContext(texture, context, parameters, ctx => {\n ctx.drawImage(maskingCtx.canvas, 0, 0, ctx.canvas.width, ctx.canvas.height);\n }, operations);\n }\n else if (Object.keys(operations).length > 0) {\n const tempCanvas = getWorkingCanvas(context.canvas.width, context.canvas.height);\n const tempContext = tempCanvas.getContext('2d');\n cb(tempContext);\n this.filterImageInPlace(tempCanvas, operations);\n this.drawInBlendedContext(texture, context, parameters, ctx => {\n ctx.drawImage(tempCanvas, 0, 0, ctx.canvas.width, ctx.canvas.height);\n disposeWorkingCanvas(tempCanvas);\n }, operations);\n }\n else {\n context.globalAlpha = texture.strength / parameters.strength;\n switch (texture.blendMode) {\n case exports.eTextureBlendMode.vector: {\n const tempCanvas = getWorkingCanvas(context.canvas.width, context.canvas.height);\n const tempContext = tempCanvas.getContext('2d');\n cb(tempContext);\n const srcData = tempContext.getImageData(0, 0, context.canvas.width, context.canvas.height).data;\n const dstImageData = context.getImageData(0, 0, context.canvas.width, context.canvas.height);\n const dstData = dstImageData.data;\n const v1 = Vector3.Zero();\n const v2 = Vector3.Zero();\n const alphaScale = context.globalAlpha / 255;\n for (let i = 0, n = srcData.length; i < n; i += 4) {\n v1.copyFromFloats(dstData[i] / 128 - 1, dstData[i + 1] / 128 - 1, dstData[i + 2] / 256 - 0.5);\n v2.copyFromFloats(srcData[i] / 128 - 1, srcData[i + 1] / 128 - 1, srcData[i + 2] / 256 - 0.5);\n v2.scaleInPlace(srcData[i + 3] * alphaScale);\n v1.addInPlace(v2);\n v1.normalize();\n dstData[i] = (v1.x + 1) * 128;\n dstData[i + 1] = (v1.y + 1) * 128;\n dstData[i + 2] = (v1.z + 1) * 128;\n dstData[i + 3] = 255;\n }\n tempContext.putImageData(dstImageData, 0, 0);\n context.drawImage(tempCanvas, 0, 0, context.canvas.width, context.canvas.height);\n disposeWorkingCanvas(tempCanvas);\n break;\n }\n default: {\n context.globalCompositeOperation = blendModeMap[texture.blendMode] || 'source-over';\n cb(context);\n context.globalCompositeOperation = 'source-over';\n }\n }\n context.globalAlpha = 1;\n }\n }\n filterImageInPlace(buffer, operations) {\n const ctx = buffer.getContext('2d');\n const width = buffer.width;\n const height = buffer.height;\n if (Object.keys(operations).length === 0) {\n return buffer;\n }\n if (operations.colorize) {\n const tempCanvas = getWorkingCanvas(width, height);\n const tmpCtx = tempCanvas.getContext('2d');\n const color = operations.colorize.color;\n delete operations.colorize;\n tmpCtx.globalCompositeOperation = 'source-over';\n tmpCtx.fillStyle = `rgb(${color.r * 255}, ${color.g * 255}, ${color.b * 255})`;\n tmpCtx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);\n tmpCtx.globalCompositeOperation = 'luminosity';\n tmpCtx.drawImage(buffer, 0, 0);\n tmpCtx.globalCompositeOperation = 'destination-in';\n tmpCtx.drawImage(buffer, 0, 0);\n ctx.drawImage(tempCanvas, 0, 0);\n disposeWorkingCanvas(tempCanvas);\n }\n if (Object.keys(operations).length === 0) {\n return buffer;\n }\n const imgData = ctx.getImageData(0, 0, width, height);\n const data = imgData.data;\n if (operations.normalRotate) {\n const rotateAngle = -1 * operations.normalRotate.angle;\n delete operations.normalRotate;\n const cosA = Math.cos((rotateAngle * Math.PI) / 180);\n const sinA = Math.sin((rotateAngle * Math.PI) / 180);\n for (let i = 0, n = data.length; i < n; i += 4) {\n const x1 = data[i] / 128 - 1;\n const y1 = data[i + 1] / 128 - 1;\n const x2 = cosA * x1 - sinA * y1;\n const y2 = sinA * x1 + cosA * y1;\n data[i] = (x2 + 1) * 128;\n data[i + 1] = (y2 + 1) * 128;\n }\n }\n if (operations.flipNormalsRg) {\n delete operations.flipNormalsRg;\n for (let i = 0, n = data.length; i < n; i += 4) {\n const r = data[i];\n data[i] = data[i + 1];\n data[i + 1] = r;\n }\n }\n ctx.putImageData(imgData, 0, 0);\n return buffer;\n }\n drawSourceToCanvas(texture, source, // | CanvasImageSource,\n context, parameters, operations) {\n var _a, _b;\n let width = source.width, height = source.height;\n const ctxWidth = context.canvas.width, ctxHeight = context.canvas.height;\n if (texture.colorize) {\n operations.colorize = { color: texture.colorize };\n }\n const firstTextureLayer = ((_a = texture._parent) === null || _a === void 0 ? void 0 : _a.textures.filter(t => t.channel === texture.channel && t.enabled).findIndex(t => t === texture)) === 0;\n if (texture.wAngle && texture.channel === exports.eTextureChannel.normal && !firstTextureLayer) {\n operations.normalRotate = { angle: texture.wAngle };\n }\n if (texture instanceof exports.FileTextureLayer &&\n texture.flipNormalsRg &&\n texture.channel === exports.eTextureChannel.normal) {\n operations.flipNormalsRg = true;\n }\n if (!firstTextureLayer) {\n const drawAt = this.calculateOffsetAndDimensions(texture, ctxWidth, ctxHeight, width, height);\n const pivotX = texture.uPivot * ctxWidth, pivotY = texture.vPivot * ctxHeight;\n if (texture.tile) {\n let patternCanvas;\n let patternAttempt;\n // In the case of stretch modes, the draw image size will differ from the native size so we have to redraw it first\n // iOS is unable to draw ImageBitmaps to patterns, so we have to try/catch for iOS\n if (drawAt.drawWidth === width && drawAt.drawHeight === height) {\n try {\n patternAttempt = context.createPattern(source, 'repeat');\n }\n catch (e) {\n // Do nothing, fallback below\n }\n }\n if (!patternAttempt) {\n patternCanvas = getWorkingCanvas(drawAt.drawWidth, drawAt.drawHeight);\n const patternContext = patternCanvas.getContext('2d');\n patternContext.drawImage(source, 0, 0, drawAt.drawWidth, drawAt.drawHeight);\n width = drawAt.drawWidth;\n height = drawAt.drawHeight;\n patternAttempt = context.createPattern(patternCanvas, 'repeat');\n }\n const pattern = patternAttempt;\n // Initial canvas transformations for angle and scaling\n context.translate(pivotX, pivotY);\n //if legacy mode enabled\n if (texture._parent &&\n texture._parent instanceof exports.MaterialNode &&\n texture._parent.legacyTextureStacking === false) {\n context.scale(texture.uScale, texture.vScale);\n context.rotate((texture.wAngle * Math.PI) / 180);\n }\n else {\n context.rotate((texture.wAngle * Math.PI) / 180);\n context.scale(texture.uScale, texture.vScale);\n if ((texture.uScale !== 1 || texture.vScale !== 1) && texture.wAngle !== 0) {\n console.warn(`Texture scale and angle are both altered on the texture layer \"${texture.name}\" with legacy mode enabled on the material \"${(_b = texture._parent) === null || _b === void 0 ? void 0 : _b.name}\". The order of operations for scale and angle are now reversed on new materials. Please disable legacy mode on this material and adjust the texture stack properties as needed to preserve the desired behavior when legacy mode is deprecated.`);\n }\n }\n // Remove extra offset since the image will be tiled anyways\n drawAt.offsetX = drawAt.offsetX % width;\n drawAt.offsetY = drawAt.offsetY % height;\n // Initially set the draw size to cover the canvas\n let drawWidth = (ctxWidth - drawAt.offsetX) / texture.uScale;\n let drawHeight = (ctxHeight - drawAt.offsetY) / texture.vScale;\n // If the offset is greater than zero there will be a gap on the top or the left so we have to move the context over one tile\n if (drawAt.offsetX > 0) {\n context.translate(-width, 0);\n drawWidth += width;\n }\n if (drawAt.offsetY > 0) {\n context.translate(0, -height);\n drawHeight += height;\n }\n // add the offset and remove the pivot from earlier that was used to get the correct rotation and scaling matrix parts\n context.translate(drawAt.offsetX - pivotX, drawAt.offsetY - pivotY);\n // If the texture was scaled with a pivot, we need to draw the image larger to make sure there are no gaps\n if ((texture.uPivot !== 0 || texture.vPivot !== 0) && (texture.uScale !== 1 || texture.vScale !== 1)) {\n const scaleOffsetU = Math.abs(Math.ceil(texture.uPivot / texture.uScale)) * width;\n const scaleOffsetV = Math.abs(Math.ceil(texture.vPivot / texture.vScale)) * height;\n if (scaleOffsetU !== 0 || scaleOffsetV !== 0) {\n context.translate(-scaleOffsetU, -scaleOffsetV);\n drawWidth += scaleOffsetU * 2;\n drawHeight += scaleOffsetV * 2;\n }\n }\n // If the texture was rotated, we need to draw the image larger to make sure there are no gaps\n if (texture.wAngle !== 0) {\n const rotateOffsetU = Math.ceil(texture.uPivot / texture.uScale) * width;\n const rotateOffsetV = Math.ceil(texture.vPivot / texture.vScale) * height;\n if (rotateOffsetU > 0 || rotateOffsetV > 0) {\n context.translate(-rotateOffsetU, -rotateOffsetV);\n drawWidth += rotateOffsetU * 2;\n drawHeight += rotateOffsetV * 2;\n }\n }\n this.drawInBlendedContext(texture, context, parameters, innerContext => {\n innerContext.fillStyle = pattern;\n // Note that any rectangle start point outside of the box will not be rendered so all image transforms must be done on the canvas context\n innerContext.fillRect(0, 0, drawWidth, drawHeight);\n if (patternCanvas) {\n disposeWorkingCanvas(patternCanvas);\n }\n }, operations);\n }\n else {\n context.translate(pivotX, pivotY);\n context.scale(texture.uScale, texture.vScale);\n context.rotate((texture.wAngle * Math.PI) / 180);\n context.translate(-pivotX, -pivotY);\n this.drawInBlendedContext(texture, context, parameters, innerContext => {\n innerContext.drawImage(source, drawAt.offsetX, drawAt.offsetY, drawAt.drawWidth, drawAt.drawHeight);\n }, operations);\n if (texture._visualize) {\n context.strokeStyle = '#00FF00';\n context.strokeRect(texture.uOffset * ctxWidth, texture.vOffset * ctxHeight, ctxWidth, ctxHeight);\n }\n }\n // reset the context\n context.setTransform(1, 0, 0, 1, 0, 0);\n }\n else {\n // this block will never need to be masked because the layers using a clipping mask will never be the first layer\n if (Object.keys(operations).length > 0) {\n if (source instanceof HTMLCanvasElement) {\n source = this.filterImageInPlace(source, operations);\n }\n else {\n const tempCanvas = getWorkingCanvas(width, height);\n const tempCtx = tempCanvas.getContext('2d');\n tempCtx.drawImage(source, 0, 0);\n source = this.filterImageInPlace(tempCanvas, operations);\n }\n }\n context.drawImage(source, 0, 0, ctxWidth, ctxHeight);\n }\n return context;\n }\n }\n\n class ColorFillTextureLayerRenderer extends TextureLayerRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.ColorFillTextureLayer;\n }\n paintTexture(texture, context, parameters, operations) {\n this.drawInBlendedContext(texture, context, parameters, innerContext => {\n innerContext.fillStyle = texture.color.cssString();\n innerContext.fillRect(0, 0, innerContext.canvas.width, innerContext.canvas.height);\n }, operations);\n }\n textureHasContent() {\n return true;\n }\n getNativeSize(texture) {\n const width = texture.width, height = texture.height;\n if (texture.wAngle !== 0) {\n return getRotatedDimensions(width, height, texture.wAngle);\n }\n else {\n return { width, height };\n }\n }\n update3dInternal(node) {\n super.update3dInternal(node);\n }\n }\n\n class FileTextureLayerRenderer extends TextureLayerRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.FileTextureLayer;\n }\n paintTexture(texture, context, parameters, operations) {\n if (texture._buffer) {\n return this.drawSourceToCanvas(texture, texture._buffer, context, parameters, operations);\n }\n }\n textureHasContent(node) {\n return node.path !== '';\n }\n getNativeSize(texture) {\n if (texture._buffer) {\n const width = Math.max(texture._buffer.width, 1), height = Math.max(texture._buffer.height, 1);\n if (texture.wAngle !== 0) {\n return getRotatedDimensions(width, height, texture.wAngle);\n }\n else {\n return { width, height };\n }\n }\n return { width: 1, height: 1 };\n }\n update3dInternal(node) {\n if (((node.changes.has('height') || node.changes.has('width')) && node.path.endsWith('.svg')) ||\n node.changes.has('path') ||\n (node.changes.has('enabled') && !node._buffer) ||\n node.changes.has('_init')) {\n node._needsImageUpdate = true;\n }\n if (node._needsImageUpdate && node.enabled && node.path && node._init) {\n this.loadTextureBuffer(node);\n }\n super.update3dInternal(node);\n }\n loadTextureBuffer(node) {\n if (node._parent instanceof exports.MaterialNode || node._parent instanceof exports.DisplacementMapFeature) {\n node._needsImageUpdate = false;\n if (node._buffer) {\n node.trackChanges(false);\n node._buffer = undefined; // Remove the buffer so the texture stack doesn't think the image is already loaded if the image was changed\n node.trackChanges(true);\n }\n node._parent._materialService.getTextureImage(node).subscribe(resp => {\n node._buffer = resp.bitmap;\n node._bufferSource = resp.url;\n });\n }\n else {\n console.warn('Texure is not attached to a material node. Cannot load texture image bitmap.');\n }\n }\n }\n\n function base64ArrayBuffer(arrayBuffer) {\n let base64 = '';\n const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n const bytes = new Uint8Array(arrayBuffer);\n const byteLength = bytes.byteLength;\n const byteRemainder = byteLength % 3;\n const mainLength = byteLength - byteRemainder;\n let a, b, c, d;\n let chunk;\n // Main loop deals with bytes in chunks of 3\n for (let i = 0; i < mainLength; i = i + 3) {\n // Combine the three bytes into a single integer\n chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];\n // Use bitmasks to extract 6-bit segments from the triplet\n a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18\n b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12\n c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6\n d = chunk & 63; // 63 = 2^6 - 1\n // Convert the raw binary segments to the appropriate ASCII encoding\n base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d];\n }\n // Deal with the remaining bytes and padding\n if (byteRemainder == 1) {\n chunk = bytes[mainLength];\n a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2\n // Set the 4 least significant bits to zero\n b = (chunk & 3) << 4; // 3 = 2^2 - 1\n base64 += encodings[a] + encodings[b] + '==';\n }\n else if (byteRemainder == 2) {\n chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1];\n a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10\n b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4\n // Set the 2 least significant bits to zero\n c = (chunk & 15) << 2; // 15 = 2^4 - 1\n base64 += encodings[a] + encodings[b] + encodings[c] + '=';\n }\n return base64;\n }\n\n class SvgTextureLayerRenderer extends TextureLayerRenderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.FileTextureLayer;\n this.imageElement = document.createElement('img');\n this.svgHelpers = new Map();\n }\n paintTexture(texture, context, parameters, operations) {\n const helper = this.svgHelpers.get(texture._dynamicId);\n if (texture._raster &&\n helper &&\n context.canvas.width === helper.renderedWidth &&\n context.canvas.height === helper.renderedHeight) {\n return this.drawSourceToCanvas(texture, texture._raster, context, parameters, operations);\n }\n else {\n let fontLoadPromise;\n if (texture.preloadFontStylesheet) {\n const fontFacesFound = [...texture.svgXml.matchAll(/font-family\\s*[=:]\\s*[\"'](.+?)[\"']/g)];\n const fontsToLoad = [];\n for (const match of fontFacesFound) {\n fontsToLoad.push(match[1]);\n }\n if (fontsToLoad.length > 0) {\n const manager = this.viewer.sceneNode._manager;\n const fontService = manager.getService(Token.FontService);\n fontLoadPromise = fontService.loadFontData(texture.preloadFontStylesheet, fontsToLoad);\n }\n else {\n fontLoadPromise = Promise.resolve();\n }\n }\n else {\n fontLoadPromise = Promise.resolve();\n }\n fontLoadPromise\n .then(result => this.generateSvg(texture, context.canvas.width, context.canvas.height, result || undefined))\n .then(bitmap => {\n if (bitmap) {\n texture._raster = bitmap;\n }\n })\n .catch(() => {\n // Don't need to do anything\n });\n }\n }\n textureHasContent(node) {\n return !!node.svgXml;\n }\n getNativeSize(texture) {\n const width = texture.width, height = texture.height;\n if (texture.wAngle !== 0) {\n return getRotatedDimensions(width, height, texture.wAngle);\n }\n else {\n return { width, height };\n }\n }\n update3dInternal(node) {\n if (node.changes.has('svgXml') ||\n node.changes.has('width') ||\n node.changes.has('height') ||\n node.changes.has('preloadFontStylesheet')) {\n node._raster = undefined;\n }\n super.update3dInternal(node);\n }\n generateSvg(texture, width, height, embedFonts) {\n if (texture.svgXml !== '' && width > 0 && height > 0) {\n let helper = this.svgHelpers.get(texture._dynamicId);\n if (!helper) {\n helper = {\n imgElement: document.createElement('img'),\n renderedHeight: height,\n renderedWidth: width,\n };\n this.svgHelpers.set(texture._dynamicId, helper);\n }\n else {\n helper.renderedHeight = height;\n helper.renderedWidth = width;\n }\n try {\n const imageElement = this.svgHelpers.get(texture._dynamicId).imgElement;\n let svgString = texture.svgXml;\n // Adding svg required tags\n if (!svgString.match(/` +\n svgString;\n }\n if (!svgString.match(/<\\?xml/)) {\n svgString = `` + svgString;\n }\n if (!svgString.match(/]*xmlns=[^>]*>/)) {\n svgString = svgString.replace(//m);\n if (!match) {\n console.warn('Invalid SVG');\n return Promise.reject();\n }\n else {\n if (embedFonts) {\n let fontStyles = '';\n for (const fontFamily in embedFonts) {\n const arrayBuffer = embedFonts[fontFamily];\n fontStyles += ` \r\n@font-face {\r\n font-family: \"${fontFamily}\";\r\n src: url(\"data:application/font-woff;charset=utf-8;base64,${base64ArrayBuffer(arrayBuffer)}\");\r\n}\r\n `;\n }\n const offset = (match.index || 0) + match[0].length;\n svgString =\n svgString.substring(0, offset) +\n `` +\n svgString.substring(offset);\n }\n const blobUrl = URL.createObjectURL(new Blob([svgString], { type: 'image/svg+xml;charset=utf-8' }));\n imageElement.src = blobUrl;\n const generateImagePromise = imageElement.decode().then(() => {\n // Don't use the img element from the closure so it can get garbage collected if this function isn't called!\n // There's no way to explicitly dispose of a DOM element\n const loadedImageElement = this.svgHelpers.get(texture._dynamicId).imgElement;\n // Figure out what resolution to actually draw the SVG at to fit within the envelope\n const scaled = scaleImagePreserveAspect(width, height, loadedImageElement.naturalWidth, loadedImageElement.naturalHeight);\n return createImageBitmap(loadedImageElement, {\n resizeWidth: scaled.drawWidth,\n resizeHeight: scaled.drawHeight,\n });\n }, err => {\n console.warn('Could not decode SVG XML: ', svgString);\n });\n this.viewer.deferSceneReady(generateImagePromise);\n return generateImagePromise;\n }\n }\n catch (e) {\n console.warn('Could not generate SVG Texture: ', e);\n Promise.reject(e);\n }\n }\n return Promise.reject();\n }\n delete3d(node) {\n const helper = this.svgHelpers.get(node._dynamicId);\n if (helper) {\n this.svgHelpers.delete(node._dynamicId);\n }\n super.delete3d(node);\n }\n }\n\n const textureChannelMap = {\n // General\n [exports.eTextureChannel.emissive]: 'emissiveTexture',\n [exports.eTextureChannel.ambientOcclusion]: 'lightmapTexture',\n // PBR\n [exports.eTextureChannel.albedo]: 'albedoTexture',\n [exports.eTextureChannel.normal]: 'bumpTexture',\n [exports.eTextureChannel.ambient]: 'ambientTexture',\n [exports.eTextureChannel.opacity]: 'opacityTexture',\n [exports.eTextureChannel.metallic]: 'metallicTexture',\n [exports.eTextureChannel.reflection]: 'reflectionTexture',\n [exports.eTextureChannel.specular]: 'reflectivityTexture',\n [exports.eTextureChannel.roughness]: 'microSurfaceTexture',\n [exports.eTextureChannel.glossiness]: 'microSurfaceTexture',\n [exports.eTextureChannel.anisotropyTangent]: ['anisotropy', 'texture'],\n [exports.eTextureChannel.clearCoatNormal]: ['clearCoat', 'bumpTexture'],\n [exports.eTextureChannel.subsurfaceThickness]: ['subSurface', 'thicknessTexture'],\n };\n const maskingCanvas = document.createElement('canvas');\n class TextureStackRenderer extends Renderer {\n constructor(viewer, scene, rendererManager) {\n super(viewer, scene);\n this.rendererManager = rendererManager;\n this.modelToken = Token.TextureLayer;\n this.queuedTexturesToProcess = new Map();\n this.queueSize = new Subject();\n this.renderers = new Map();\n this.noMipMapFallback = false;\n this.updateTextureStackRequest = new Subject();\n this.deferCalled = false;\n const fileTexture = new FileTextureLayerRenderer(viewer, scene);\n const svgTexture = new SvgTextureLayerRenderer(viewer, scene);\n const colorTexture = new ColorFillTextureLayerRenderer(viewer, scene);\n this.renderers.set(Token.FileTextureLayer, fileTexture);\n this.renderers.set(Token.SvgTextureLayer, svgTexture);\n this.renderers.set(Token.ColorFillTextureLayer, colorTexture);\n /**\n * See render.ts comment - this delay must be added to the render as a change can take up to this delay time to be displayed.\n * We don't want to repeatedly processes texture changes coming in quick succession, which often happens if there are many textures being loaded at once.\n * */\n const throttleDebounceTime = 800;\n merge(this.updateTextureStackRequest.pipe(throttleTime(throttleDebounceTime)), this.updateTextureStackRequest.pipe(debounceTime(throttleDebounceTime))).subscribe(() => {\n this.updateTextureStacksExec();\n });\n // This code works for forcing intel gpus to not use mipmaps, but some scenes don't have artifacting issues and need mipmaps. So\n // In the future we can introduce a scene setting to enable the intel fallback\n // if (this.viewer.glInfo.match(/Intel.*Iris.*Xe/)) {\n // this.noMipMapFallback = true;\n // }\n }\n materialDeleted(node) {\n for (const channel in exports.eTextureChannel) {\n const textureId = this.getTexture3dId(node, channel);\n const texture = this.babylonMap.get(textureId);\n if (texture) {\n this.disposeTexture(texture);\n this.babylonMap.delete(this.getTexture3dId(node, channel));\n }\n this.babylonMap.delete(textureId);\n }\n }\n /** This should only be called from the editor. Has a very heavy performance impact. */\n forceRebuildTexture(materialNode, channel) {\n if (channel) {\n this.resetTextureStack(materialNode, channel);\n }\n else {\n for (const channel in exports.eTextureChannel) {\n this.resetTextureStack(materialNode, channel);\n }\n }\n this.updateTextureStacksInternal(materialNode);\n }\n resetTextureStack(texturedNode, channel, setParameters) {\n let material;\n let materialNode;\n if (isMaterialNode(texturedNode)) {\n materialNode = texturedNode;\n if (!materialNode._initialized) {\n return;\n }\n material = this.rendererManager.material.get3d(materialNode);\n if (!material) {\n // There might not be a material in babylon if the material was deleted prior to this renderer running.\n // console.warn(`material not generated from ${materialNode.name}`);\n return;\n }\n }\n const hasTextureInChannel = !!texturedNode.textures.find(t => t.channel === channel);\n if (!hasTextureInChannel) {\n return;\n }\n let channelsToProcess = this.queuedTexturesToProcess.get(texturedNode);\n if (!channelsToProcess) {\n channelsToProcess = new Map();\n this.queuedTexturesToProcess.set(texturedNode, channelsToProcess);\n }\n // Here we don't want to filter out textures with no data because they cam still be used to set the canvas size\n const textureLayers = this.getActiveLayers(texturedNode, channel);\n // Register that the channel needs to be processed.\n // Figure out the highest strength among the texture layers so we can\n // calculate the strength of each one as a fraction of that.\n let channelStrength = 0;\n textureLayers.forEach(textureLayer => {\n channelStrength = Math.max(channelStrength, textureLayer.strength);\n });\n const existingProcess = channelsToProcess.get(channel);\n channelsToProcess.set(channel, {\n strength: channelStrength,\n hasTransparency: materialNode ? materialNode.hasTransparency : false,\n ...(existingProcess || {}),\n ...(setParameters || {}),\n });\n const propName3d = textureChannelMap[channel];\n if (material && materialNode) {\n // Reset the material to re-run the texture stack (or clear the texture if there are no textures anymore)\n if (textureLayers.length === 0) {\n // If no textures are using this channel anymore, then remove it from the material\n if (Array.isArray(propName3d)) {\n const res = getObjectPropertyAtPath(material, propName3d, false);\n if (res.obj && res.obj[res.prop]) {\n const texture = res.obj[res.prop];\n if (texture instanceof Texture) {\n this.disposeTexture(texture);\n res.obj[res.prop] = null;\n this.babylonMap.delete(this.getTexture3dId(materialNode, channel));\n }\n }\n }\n else {\n if (material && material[propName3d]) {\n material[propName3d].dispose();\n material[propName3d] = null;\n this.babylonMap.delete(this.getTexture3dId(materialNode, channel));\n }\n }\n }\n else {\n const texture = this.getTexture(materialNode, channel);\n if (texture instanceof DynamicTexture) {\n const baseImageSize = this.getRenderer(textureLayers[0]).getNativeSize(textureLayers[0]);\n const context = texture.getContext();\n if (this.scene.getEngine().webGLVersion < 2) {\n const clampedSize = getBinClampedSize(baseImageSize.width, baseImageSize.height);\n context.canvas.width = clampedSize;\n context.canvas.height = clampedSize;\n }\n else {\n context.canvas.width = baseImageSize.width;\n context.canvas.height = baseImageSize.height;\n }\n context.clearRect(0, 0, context.canvas.width, context.canvas.height);\n }\n }\n }\n }\n update3dInternal(feature) {\n if (isTrackedClass(feature)) {\n if (!feature.enabled || feature._suppressed) {\n if (feature.changes.has('enabled') || feature.changes.has('_suppressed')) {\n this.delete3d(feature);\n }\n return;\n }\n const renderer = this.renderers.get(Token.withKey(feature.$type));\n if (!renderer) {\n throw Error('no renderer for feature');\n }\n if (feature._parent && isFeatureNode(feature._parent)) {\n feature.init(feature._parent);\n }\n renderer.update3d(feature);\n if (feature._parent && isFeatureNode(feature._parent) && isTrackedClass(feature._parent)) {\n feature._parent.setPropertyIsModified('textures', true);\n }\n if (feature._parent) {\n this.resetTextureStack(feature._parent, feature.channel);\n }\n }\n }\n updateTextureStacks() {\n if (!this.deferCalled && this.queuedTexturesToProcess.size > 0) {\n const queueLive = this.queueSize.pipe(takeWhile(size => size > 0));\n const p = queueLive.toPromise();\n this.viewer.deferSceneReady(p);\n this.deferCalled = true;\n }\n for (const node of this.queuedTexturesToProcess.keys()) {\n if (isFeatureNode(node) || node._initialized) {\n for (const texture of node.textures) {\n if (!texture._init) {\n texture.init(node);\n }\n }\n }\n }\n this.updateTextureStackRequest.next();\n }\n updateTextureStacksExec() {\n this.queueSize.next(this.queuedTexturesToProcess.size);\n for (const node of this.queuedTexturesToProcess.keys()) {\n this.updateTextureStacksInternal(node);\n if (this.queuedTexturesToProcess.size > 0) {\n this.updateTextureStacks();\n }\n // Low perf code to prevent iOS from erroring out. Doesn't seem necessary for now\n // return;\n // End low perf code\n }\n this.queueSize.next(this.queuedTexturesToProcess.size);\n }\n updateTextureStacksInternal(node) {\n if (this.queuedTexturesToProcess.has(node)) {\n if (isMaterialNode(node)) {\n const channels = this.queuedTexturesToProcess.get(node);\n const material = this.rendererManager.material.get3d(node);\n if (!channels || !material) {\n return;\n }\n // Process texture stack\n channels.forEach((parameters, channel) => {\n // Put the texture in the right place on the material\n const propName3d = textureChannelMap[channel];\n if (instanceOf(node, Token.AdvancedMaterialNode)) {\n if (node.workflowMode === exports.eMaterialWorkflow.metallicRoughness &&\n channel === exports.eTextureChannel.glossiness) {\n return;\n }\n else if (node.workflowMode === exports.eMaterialWorkflow.specularGlossiness &&\n channel === exports.eTextureChannel.roughness) {\n return;\n }\n }\n const texture = this.getTexture(node, channel);\n // If texture is undefined, that means that there is a missing setting/layers that means we don't need a texture for this channel\n if (texture) {\n // Paint the image onto the texture\n // We don't want to count layers with no content in the stack, like file textures with no file or svg textures with no data\n const textureLayers = this.getActiveLayers(node, channel).filter(node => {\n const renderer = this.getRenderer(node);\n return renderer.textureHasContent(node);\n });\n if (textureLayers.length > 0) {\n // Put the texture in the right place on the material if it's not already\n if (Array.isArray(propName3d)) {\n const res = getObjectPropertyAtPath(material, propName3d);\n if (res.obj[res.prop] !== texture) {\n res.obj[res.prop] = texture;\n }\n }\n else {\n if (material[propName3d] !== texture) {\n material[propName3d] = texture;\n }\n }\n if (texture instanceof DynamicTexture) {\n const context = texture.getContext();\n if (!(context instanceof CanvasRenderingContext2D)) {\n throw Error('Unexpected rendering context');\n }\n if (channel !== exports.eTextureChannel.albedo) {\n // Fill texture with color that makes sense depending on the texture channel\n switch (channel) {\n case exports.eTextureChannel.normal: {\n context.fillStyle = 'rgb(128, 128, 255)';\n break;\n }\n case exports.eTextureChannel.opacity:\n case exports.eTextureChannel.ambient:\n case exports.eTextureChannel.ambientOcclusion: {\n context.fillStyle = 'rgb(255, 255, 255)';\n break;\n }\n default: {\n context.fillStyle = 'rgb(0, 0, 0)';\n break;\n }\n }\n context.fillRect(0, 0, context.canvas.width, context.canvas.height);\n }\n this.paintTextureOnCanvas(textureLayers, context, parameters);\n updateTextureProps(texture, parameters);\n texture.update(true); // invertY\n }\n else {\n // If texture is not a dynamic texture, then it's a basic texture and there is only one texture layer. We just have to make sure the path is correct\n const fileTextureLayer = textureLayers[0];\n if (!(fileTextureLayer instanceof exports.FileTextureLayer)) {\n throw Error('Unexpected texture type');\n }\n else {\n if (fileTextureLayer._parent instanceof exports.MaterialNode) {\n const path = fileTextureLayer._bufferSource || '';\n if (texture.url !== path && fileTextureLayer._buffer) {\n texture.updateURL(path, (fileTextureLayer._buffer || null));\n }\n }\n updateTextureProps(texture, parameters);\n }\n }\n }\n }\n });\n }\n else {\n if (isTrackedClass(node)) {\n node.setPropertyIsModified('textures', true);\n this.queuedTexturesToProcess.delete(node);\n return;\n }\n }\n }\n if (isMaterialNode(node) && isTrackedClass(node)) {\n this.applyUvProperties(node);\n }\n else {\n throw Error('Material is not being tracked');\n }\n this.queuedTexturesToProcess.delete(node);\n function updateTextureProps(texture, parameters) {\n texture.level = parameters.strength;\n texture.hasAlpha = parameters.hasTransparency;\n }\n }\n delete3d(feature) {\n if (feature._parent) {\n this.resetTextureStack(feature._parent, feature.channel);\n }\n const renderer = this.renderers.get(Token.withKey(feature.$type));\n if (!renderer) {\n throw Error('no renderer for feature');\n }\n renderer.delete3d(feature);\n }\n get3d(texture) {\n if (!texture._parent) {\n return undefined;\n }\n if (texture._parent instanceof exports.MaterialNode) {\n return this.babylonMap.get(this.getTexture3dId(texture._parent, texture.channel));\n }\n }\n set3d(texture, babylonObject) {\n if (texture._parent) {\n if (texture._parent instanceof exports.MaterialNode) {\n this.babylonMap.set(this.getTexture3dId(texture._parent, texture.channel), babylonObject);\n }\n }\n }\n dispose() {\n this.queuedTexturesToProcess.clear();\n this.renderers.forEach(renderer => renderer.dispose());\n this.updateTextureStackRequest.complete();\n super.dispose();\n }\n setTransparency(materialNode, hasTransparency) {\n // TODO: limit this to only albedo textures for now. Will need testing.\n this.resetTextureStack(materialNode, exports.eTextureChannel.albedo, { hasTransparency });\n }\n applyUvProperties(materialNode) {\n const material = this.rendererManager.material.get3d(materialNode);\n if (material) {\n for (const channel in textureChannelMap) {\n const firstTextureLayer = materialNode.textures.find(t => t.channel === channel);\n const propName3d = textureChannelMap[channel];\n let texture;\n if (Array.isArray(propName3d)) {\n const res = getObjectPropertyAtPath(material, propName3d);\n texture = res.obj[res.prop];\n }\n else {\n texture = material[propName3d];\n }\n if (texture && firstTextureLayer) {\n if (!(texture instanceof Texture)) {\n throw Error(propName3d.toString() + ' is not a texture');\n }\n texture.uOffset = firstTextureLayer.uOffset;\n texture.vOffset = firstTextureLayer.vOffset;\n texture.uScale = firstTextureLayer.uScale;\n texture.vScale = firstTextureLayer.vScale;\n texture.uAng = (firstTextureLayer.uAngle * Math.PI) / 180;\n texture.vAng = (firstTextureLayer.vAngle * Math.PI) / 180;\n texture.wAng = (firstTextureLayer.wAngle * Math.PI) / 180;\n texture.uRotationCenter = firstTextureLayer.uPivot;\n texture.vRotationCenter = firstTextureLayer.vPivot;\n texture.wRotationCenter = firstTextureLayer.wPivot;\n // if (firstTextureLayer.uWrap === eTextureWrapAddressMode.clamp) {\n // texture.wrapU = Texture.CLAMP_ADDRESSMODE;\n // } else {\n // texture.wrapU = Texture.WRAP_ADDRESSMODE;\n // }\n // if (firstTextureLayer.vWrap === eTextureWrapAddressMode.clamp) {\n // texture.wrapV = Texture.CLAMP_ADDRESSMODE;\n // } else {\n // texture.wrapV = Texture.WRAP_ADDRESSMODE;\n // }\n // For some reason wrap addressmode is not getting converted correctly. Repeat is the safer option so\n // Let's hardcode repeat for now\n texture.wrapU = Texture.WRAP_ADDRESSMODE;\n texture.wrapV = Texture.WRAP_ADDRESSMODE;\n if (!(texture instanceof DynamicTexture)) {\n texture.vScale *= -1;\n }\n }\n }\n }\n }\n paintTextureOnCanvas(textureLayers, context, parameters) {\n let clippingTexture = null;\n for (let i = 0; i < textureLayers.length; i++) {\n if (!textureLayers[i]._init) {\n continue;\n }\n const textureLayer = textureLayers[i];\n const renderer = this.getRenderer(textureLayer);\n // Continue clipping with the same texture as long as useClippingMask is true.\n // When there's a texture that's not clipping, that can potentially be a new clipping mask.\n if (!textureLayer.useClippingMask) {\n clippingTexture = null;\n }\n const maskingCtx = maskingCanvas.getContext('2d', {\n willReadFrequently: true,\n });\n if (textureLayers[i + 1] && textureLayers[i + 1].useClippingMask && !clippingTexture) {\n maskingCanvas.width = context.canvas.width;\n maskingCanvas.height = context.canvas.height;\n clippingTexture = textureLayer;\n }\n else if (textureLayer.useClippingMask && clippingTexture) {\n const clippingTextureRenderer = this.getRenderer(clippingTexture);\n maskingCtx.clearRect(0, 0, maskingCanvas.width, maskingCanvas.height);\n clippingTextureRenderer.paintTexture(clippingTexture, maskingCtx, { strength: 1, hasTransparency: true }, {});\n renderer.paintTexture(textureLayer, context, parameters, {\n mask: { context: maskingCtx },\n });\n }\n else {\n renderer.paintTexture(textureLayer, context, parameters, {});\n }\n }\n return context;\n }\n getActiveLayers(materialNode, channel, includeSupressed = false) {\n return materialNode.textures.filter(texture => texture.channel === channel && texture.enabled && (includeSupressed || !texture._suppressed));\n }\n getRenderer(textureLayer) {\n const renderer = this.renderers.get(Token.withKey(textureLayer.$type));\n if (!renderer) {\n throw Error('no renderer for texture layer');\n }\n return renderer;\n }\n canUseSimpleTexture(activeLayers) {\n if (activeLayers.length === 1) {\n const layer = activeLayers[0];\n return layer instanceof exports.FileTextureLayer;\n }\n return false;\n }\n disposeTexture(texture) {\n // Resizing textures before they are ready results in an error. Remove this code for now\n // if (texture instanceof DynamicTexture) {\n // texture.scaleTo(1, 1); // Prevent memory leaks in Safari\n // }\n texture.dispose();\n }\n getTexture3dId(node, channel) {\n return `${node._dynamicId}_${channel}`;\n }\n getTexture(node, channel) {\n const rootScene = this.viewer.sceneNode;\n const activeLayers = this.getActiveLayers(node, channel, true);\n const canUseSimpleTexture = this.canUseSimpleTexture(activeLayers);\n let texture = this.babylonMap.get(this.getTexture3dId(node, channel));\n const originalTexture = texture;\n if (originalTexture) {\n if (originalTexture instanceof DynamicTexture && canUseSimpleTexture) {\n this.disposeTexture(originalTexture);\n }\n else if (activeLayers.length > 1 && !(texture instanceof DynamicTexture)) {\n this.disposeTexture(originalTexture);\n }\n else {\n return originalTexture;\n }\n }\n if (canUseSimpleTexture) {\n const fileTexture = activeLayers[0];\n if (fileTexture.path && fileTexture._buffer && fileTexture._parent instanceof exports.MaterialNode) {\n texture = new Texture(fileTexture._bufferSource || '', this.scene, this.noMipMapFallback, false, SamplingModeMap[rootScene.textureSamplingMode], null, null, fileTexture._buffer);\n texture.name = this.getTexture3dId(node, channel);\n }\n else {\n return undefined;\n }\n }\n else {\n texture = new DynamicTexture(this.getTexture3dId(node, channel), 256, this.scene, !this.noMipMapFallback, SamplingModeMap[rootScene.textureSamplingMode]);\n }\n texture.homogeneousRotationInUVTransform = true;\n this.babylonMap.set(this.getTexture3dId(node, channel), texture);\n // set initial values\n if (originalTexture) {\n texture.hasAlpha = originalTexture.hasAlpha;\n texture.level = originalTexture.level;\n texture.getAlphaFromRGB = originalTexture.getAlphaFromRGB;\n }\n else {\n texture.hasAlpha = false;\n if (channel === exports.eTextureChannel.opacity) {\n texture.getAlphaFromRGB = true;\n }\n else {\n texture.getAlphaFromRGB = false;\n }\n texture.level = 1;\n }\n texture.coordinatesIndex = 0;\n texture.coordinatesMode = 0;\n texture.anisotropicFilteringLevel = 4;\n if (texture instanceof Texture) {\n texture.uOffset = 0; // Define an offset on the texture to offset the u coordinates of the UVs\n texture.vOffset = 0; // Define an offset on the texture to offset the v coordinates of the UVs\n texture.uScale = -1; // Define an offset on the texture to scale the u coordinates of the UVs\n texture.vScale = 1; // Define an offset on the texture to scale the v coordinates of the UVs\n texture.uAng = 0; // Define an offset on the texture to rotate around the u coordinates of the UVs\n texture.vAng = 0; // Define an offset on the texture to rotate around the v coordinates of the UVs\n texture.wAng = 0; // Define an offset on the texture to rotate around the w coordinates of the UVs (in case of 3d texture)\n texture.uRotationCenter = 0.5; // Defines the center of rotation (U)\n texture.vRotationCenter = 0.5; // Defines the center of rotation (V)\n texture.wRotationCenter = 0.5; // Defin\n texture.isBlocking = false;\n }\n return texture;\n }\n }\n function getObjectPropertyAtPath(_obj, path, throwOnNotFound = true) {\n let obj = _obj;\n const propPath = path.slice().reverse();\n while (propPath.length > 1 && obj) {\n const prop = propPath.pop();\n if (prop in obj) {\n obj = obj[prop];\n }\n else {\n obj = null;\n }\n }\n if (throwOnNotFound && !obj) {\n throw Error('Texture property not found for ' + path.toString());\n }\n return { obj, prop: propPath[0] };\n }\n\n class ViewpointRenderer extends Renderer {\n constructor() {\n super(...arguments);\n this.modelToken = Token.ViewpointNode;\n }\n update3dInternal(node) { }\n }\n\n let unprocessedChangesCount = 0;\n class ChangeMap extends ArrayMap {\n }\n class RendererManager {\n getRenderMode() {\n return this.material.renderMode;\n }\n /** Do not use this function directly. Call setRenderMode on the viewer instead so the correct sceneNode is used. */\n setRenderMode(mode, sceneNode, force) {\n if (force) {\n this.forcedRenderingMode = mode;\n }\n this.material.renderMode = this.forcedRenderingMode || mode;\n this.mesh.setRenderMode(this.forcedRenderingMode || mode, sceneNode);\n }\n constructor(viewer, scene) {\n this.viewer = viewer;\n this.scene = scene;\n this.deferredChanges = [];\n this.maxRenderTime = MAX_RENDER_TIME;\n this.processors = new Array();\n this.shadowManager = new ShadowManager(viewer.bbCache);\n this.sceneRenderer = new SceneRenderer(viewer, scene, viewer.gui, this);\n this.textures = new TextureStackRenderer(viewer, scene, this);\n this.material = new MaterialRenderer(viewer, scene, this.textures);\n this.light = new LightRenderer(viewer, scene, this.shadowManager);\n this.viewpoint = new ViewpointRenderer(viewer, scene);\n this.mesh = new MeshRenderer(viewer, scene, this, this.shadowManager);\n this.features = new FeatureStackRenderer(viewer, scene, this);\n this.connector = new ConnectorRenderer(viewer, scene, this);\n this.controlPointRenderer = new SketchControlPointRenderer(viewer, scene, this);\n this.annotation = new AnnotationRenderer(viewer, scene, this);\n this.dimension = new DimensionRenderer(viewer, scene, this);\n this.mate = new MateRenderer(viewer, scene);\n this.path = new PathRenderer(viewer, scene);\n // Order is important here, it defines the order in which renderers will be run\n this.renderers = new Set([\n this.sceneRenderer,\n this.material,\n this.textures,\n this.viewpoint,\n this.path,\n this.mesh,\n this.light,\n this.features,\n this.connector,\n this.controlPointRenderer,\n this.annotation,\n this.dimension,\n this.mate,\n ]);\n this.referenceProcessor = new ReferenceProcessor(viewer);\n this.mateProcessor = new MateProcessor(viewer, scene, this.connector, this.controlPointRenderer, this.referenceProcessor);\n this.sketchProcessor = new SketchProcessor(this.controlPointRenderer);\n this.processors.push(this.mateProcessor);\n this.processors.push(this.referenceProcessor);\n this.processors.push(this.sketchProcessor);\n }\n isStable() {\n return (!SyncService.hasChanges &&\n this.features.queuedFeaturesToProcess.size === 0 &&\n this.textures.queuedTexturesToProcess.size === 0);\n }\n render() {\n let changes;\n if (this.deferredChanges.length > 0) {\n changes = this.getChangeMap(this.deferredChanges);\n }\n else {\n for (const p of this.processors) {\n p.beforeRender();\n }\n // run deletions first\n const deletions = this.getChangeMap(SyncService.getDeletedNodes(), true);\n for (const p of this.processors) {\n p.beforeDeletions(deletions);\n }\n this.runChanges(deletions, (renderer, change) => renderer.delete3d(change));\n for (const p of this.processors) {\n p.afterDeletions(deletions);\n }\n //then run updates\n const newChanges = SyncService.getChangedNodes();\n changes = this.getChangeMap(newChanges);\n for (const p of this.processors) {\n p.beforeUpdates(changes);\n }\n changes = this.getChangeMap(SyncService.getChangedNodes()); //need to update changes in case processors added any\n }\n const allChangesByDid = new Map(changes.all().map(change => {\n return [change._dynamicId, change];\n }));\n const allChangeCount = allChangesByDid.size;\n const processedChangeMap = this.runChanges(changes, (renderer, change) => {\n renderer.update3d(change);\n });\n const processedChanges = processedChangeMap.all();\n processedChanges.forEach(change => {\n allChangesByDid.delete(change._dynamicId);\n });\n this.deferredChanges = Array.from(allChangesByDid.values());\n const skipCount = allChangeCount - processedChanges.length;\n // For now we are processing all changes becuase it causes unpredictable behavior.\n // The heaviest part of the render cycle is the geometry features processing.\n // if (processedChanges.length > 0 || skipCount > 0) {\n // console.log('processed ' + processedChanges.length + ' changes, skipped ' + skipCount + ' changes');\n // }\n // Don't run the geometry and texture stack processing until all changes have been processed\n if (skipCount === 0) {\n this.features.update3dGeometry();\n this.textures.updateTextureStacks();\n }\n for (const p of this.processors)\n p.afterUpdates(processedChangeMap);\n for (const n of processedChanges) {\n n.commitChanges();\n }\n for (const p of this.processors)\n p.doAfterCleanup();\n // Output a console warning if there are a lot of changes not being processed, as this could indicate a problem with changes not being processed.\n const unchangedNodes = SyncService.getChangedNodes();\n if (unchangedNodes.length > 0) {\n unprocessedChangesCount++;\n if (unprocessedChangesCount > 1000) {\n unprocessedChangesCount = 0;\n console.warn('Scene stabilization is taking longer than expected.');\n for (const n of unchangedNodes) {\n if (n._rootScene._dynamicId !== this.viewer.sceneNode._dynamicId) {\n n.commitChanges();\n console.warn(`node ${n.name} (${n.id}) is from a different, non-active scene instance. Clearing the change.`);\n }\n }\n }\n }\n }\n /** runs a change map in order */\n runChanges(changes, action) {\n const processedChanges = new ChangeMap();\n const renderStart = performance.now();\n for (const renderer of this.renderers) {\n const changeList = changes.get(renderer.modelToken);\n for (const change of changeList) {\n action(renderer, change);\n processedChanges.add(renderer.modelToken, change);\n }\n }\n const renderTime = performance.now() - renderStart;\n if (renderTime > 50) {\n console.warn(`Change cycle took ${renderTime}ms`);\n }\n return processedChanges;\n }\n getChangeMap(nodes, includeOrphaned = false) {\n var _a;\n const changes = new ChangeMap();\n for (const n of nodes) {\n if ((((_a = n._rootScene) === null || _a === void 0 ? void 0 : _a._dynamicId) === this.viewer.sceneNode._dynamicId && n._level > -1) ||\n includeOrphaned ||\n this.isGlobalMaterialOrTexture(n) //global/library material nodes held outside of graph\n ) {\n const renderer = this.renderers.find(r => r.handlesNode(n));\n if (!renderer)\n throw 'unknown node type';\n changes.add(renderer.modelToken, n);\n }\n else if (n._rootScene == null) {\n // Clear changes on nodes that are not in any scene tree\n n.commitChanges();\n }\n }\n changes.get(Token.SpaceNode).sortBy(m => m._level); //sort meshes by level first\n return changes;\n }\n disposeAll() {\n this.shadowManager.dispose();\n for (const processor of this.processors)\n processor.dispose();\n for (const renderer of this.renderers)\n renderer.dispose();\n }\n isGlobalMaterialOrTexture(n) {\n let mat = n;\n if (n instanceof exports.TextureLayer)\n mat = n._parent;\n return mat instanceof exports.MaterialNode && mat.location != exports.eMaterialLocation.local;\n }\n }\n\n /**\n * We are overriding the default mouse wheet input for the arc rotate camera here because\n * the default one does not act correctly when zoomed in close to the target: it\n * calculates the inertia based on the radius at the time the event happens. The result\n * is that zooming in is fast than zooming out. They had a misguided attempt at fixing\n * that here: https://github.com/BabylonJS/Babylon.js/issues/6215 but it is inadequate.\n * See comments below for where we changed the code\n */\n class KbArcRotateCameraMouseWheelInput {\n constructor() {\n this.wheelPrecision = 3.0;\n this.wheelDeltaPercentage = 0;\n }\n computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta, radius) {\n let delta = 0;\n const wheelDelta = mouseWheelDelta * 0.01 * this.wheelDeltaPercentage * radius;\n if (mouseWheelDelta > 0) {\n delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);\n }\n else {\n delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);\n }\n return delta;\n }\n attachControl(noPreventDefault) {\n this._wheel = (p, s) => {\n if (p.type !== PointerEventTypes.POINTERWHEEL) {\n return;\n }\n const event = p.event;\n let delta = 0;\n const mouseWheelLegacyEvent = event;\n let wheelDelta = 0;\n if (mouseWheelLegacyEvent.wheelDelta) {\n wheelDelta = mouseWheelLegacyEvent.wheelDelta;\n }\n else {\n wheelDelta = -(event.deltaY || event.detail || 0) * 60;\n }\n if (this.wheelDeltaPercentage) {\n delta = this.computeDeltaFromMouseWheelLegacyEvent(wheelDelta, this.camera.radius);\n // If zooming in, estimate the target radius and use that to compute the delta for inertia\n // this will stop multiple scroll events zooming in from adding too much inertia\n //if (delta > 0) { //KB Note: their misguided attempt at fixing the problem only affected zoom in, when it should affect both, so we commented this line out\n let estimatedTargetRadius = this.camera.radius;\n let targetInertia = this.camera.inertialRadiusOffset + delta;\n for (let i = 0; i < 20 && Math.abs(targetInertia) > this.camera.speed * Epsilon; i++) {\n //KB Note: fixed the lower limit where it opts out to match the camera's own intertial calculation\n estimatedTargetRadius -= targetInertia;\n targetInertia *= this.camera.inertia;\n }\n estimatedTargetRadius = Scalar.Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);\n delta = this.computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);\n //}\n }\n else {\n delta = wheelDelta / (this.wheelPrecision * 40);\n }\n if (delta) {\n this.camera.inertialRadiusOffset += delta;\n }\n if (event.preventDefault) {\n if (!noPreventDefault) {\n event.preventDefault();\n }\n }\n };\n this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, PointerEventTypes.POINTERWHEEL);\n }\n detachControl() {\n if (this._observer) {\n this.camera.getScene().onPointerObservable.remove(this._observer);\n this._observer = null;\n this._wheel = null;\n }\n }\n getClassName() {\n return 'KbArcRotateCameraMouseWheelInput';\n }\n getSimpleName() {\n return 'mousewheel';\n }\n }\n\n /** Arc Rotate Camera (orbit camera) modified to offset the screen position on pan and keep the orbit target in the same position */\n class KbArcRotateCamera extends ArcRotateCamera {\n constructor(name, alpha, beta, radius, target, scene, setActiveOnSceneIfNoneActive) {\n super(name, alpha, beta, radius, target, scene, setActiveOnSceneIfNoneActive);\n this.scene = scene;\n this.inertialOffsetPanningX = 0;\n this.inertialOffsetPanningY = 0;\n this.inertialOrthoZoom = 0;\n this.clientInfo = {\n mouseX: 0,\n mouseY: 0,\n screenLeft: 0,\n screenTop: 0,\n screenWidth: 0,\n screenHeight: 0,\n };\n this.lockRotation = false;\n this.lockPanning = false;\n this.lockZoom = false;\n this.limitMinimumTargetDistance = false;\n this._orthoWidth = 0;\n //replace the wheel input with our own\n this.inputs.removeByType('ArcRotateCameraMouseWheelInput');\n this.inputs.add(new KbArcRotateCameraMouseWheelInput());\n this.updateClient();\n }\n get orthoWidth() {\n return this._orthoWidth;\n }\n set orthoWidth(val) {\n this._orthoWidth = this.clampOrthoWidth(val);\n this.updateOrthographicPosition();\n }\n orthoFit(sizeX, sizeY) {\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n const ratio = this.clientInfo.screenHeight / this.clientInfo.screenWidth;\n if (sizeX * ratio < sizeY) {\n this.orthoWidth = sizeY / ratio;\n }\n else {\n this.orthoWidth = sizeX;\n }\n }\n }\n update() {\n if (this.scene.activeCamera !== this) {\n return;\n }\n let startZoomLevel;\n if (!this.targetScreenOffset) {\n this.targetScreenOffset = new Vector2(0, 0);\n }\n if (this.lockRotation && (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0)) {\n this.inertialPanningX = this.inertialAlphaOffset;\n this.inertialPanningY = -this.inertialBetaOffset;\n this.inertialAlphaOffset = this.inertialBetaOffset = 0;\n }\n if (this.inertialPanningX !== 0 || this.inertialPanningY !== 0) {\n if (!this.lockPanning) {\n this.inertialOffsetPanningX = this.inertialPanningX;\n this.inertialOffsetPanningY = this.inertialPanningY;\n }\n this.inertialPanningX = 0;\n this.inertialPanningY = 0;\n }\n if (this.lockZoom && this.inertialRadiusOffset !== 0) {\n this.inertialRadiusOffset = 0;\n }\n if (this.inertialRadiusOffset !== 0) {\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n this.inertialOrthoZoom = this.inertialRadiusOffset;\n this.inertialRadiusOffset = 0;\n }\n else {\n startZoomLevel = this.radius;\n //this.inertialRadiusOffset = 0; //override so we have full control over the zoom\n //if (this.inertialRadiusOffset < .001) this.inertialRadiusOffset = .001;\n }\n }\n if (this.inertialOrthoZoom !== 0) {\n startZoomLevel = this.orthoWidth;\n }\n super.update();\n if (this.inertialOffsetPanningX !== 0 || this.inertialOffsetPanningY !== 0) {\n let offset;\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n offset = new Vector2(this.inertialOffsetPanningX * this.orthoWidth, this.inertialOffsetPanningY * this.orthoWidth);\n }\n else {\n offset = new Vector2(this.inertialOffsetPanningX * this.radius, this.inertialOffsetPanningY * this.radius);\n }\n this.targetScreenOffset.subtractInPlace(offset);\n this.inertialOffsetPanningX *= this.panningInertia;\n this.inertialOffsetPanningY *= this.panningInertia;\n }\n if (this.inertialOrthoZoom !== 0) {\n this.orthoWidth = this.orthoWidth - this.inertialOrthoZoom * this.orthoWidth;\n this.inertialOrthoZoom *= this.panningInertia;\n }\n if (Math.abs(this.inertialOffsetPanningX) < this.speed * Epsilon) {\n this.inertialOffsetPanningX = 0;\n }\n if (Math.abs(this.inertialOffsetPanningY) < this.speed * Epsilon) {\n this.inertialOffsetPanningY = 0;\n }\n if (Math.abs(this.inertialOrthoZoom) < this.speed * Epsilon) {\n this.inertialOrthoZoom = 0;\n }\n // When zooming, adjust the camera pan so you zoom into your mouse position, as long as pan is enabled\n if (!this.lockPanning && startZoomLevel !== undefined) {\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n const zoomChange = (startZoomLevel - this.orthoWidth) / 2;\n this.targetScreenOffset.x -= zoomChange * this.clientInfo.mouseX;\n this.targetScreenOffset.y += zoomChange * this.clientInfo.mouseY;\n }\n else {\n const gamma = Math.tan(this.fov / 2);\n const zoomChange = startZoomLevel - this.radius;\n const shiftX = zoomChange * gamma * this.clientInfo.mouseX;\n const shiftY = zoomChange * gamma * this.clientInfo.mouseY;\n this.targetScreenOffset.x -= shiftX;\n this.targetScreenOffset.y += shiftY;\n }\n }\n }\n updateClient() {\n const canvas = this.getEngine().getRenderingCanvas();\n if (!canvas) {\n return;\n }\n const clientRect = canvas.getBoundingClientRect();\n this.clientInfo.screenWidth = clientRect.width;\n this.clientInfo.screenHeight = clientRect.height;\n this.clientInfo.screenLeft = clientRect.left;\n this.clientInfo.screenTop = clientRect.top;\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n this.updateOrthographicPosition();\n this.panningSensibility = clientRect.width;\n }\n else {\n const focalLength = clientRect.height / (2 * Math.tan(this.fov / 2));\n this.panningSensibility = focalLength;\n }\n return canvas;\n }\n attachControl(noPreventDefault = false) {\n super.attachControl(noPreventDefault, true);\n if (this.disposeListeners) {\n this.disposeListeners();\n }\n const updateMousePosition = (event) => {\n this.clientInfo.mouseX =\n ((event.clientX - this.clientInfo.screenLeft) * 2) / this.clientInfo.screenWidth - 1;\n this.clientInfo.mouseY =\n ((event.clientY - this.clientInfo.screenTop) * 2) / this.clientInfo.screenHeight - 1;\n };\n const canvas = this.updateClient();\n const updateClientWrap = () => this.updateClient();\n if (canvas) {\n window.addEventListener('resize', updateClientWrap);\n canvas.addEventListener('mousemove', updateMousePosition);\n this.disposeListeners = () => {\n window.removeEventListener('resize', updateClientWrap);\n canvas.removeEventListener('mousemove', updateMousePosition);\n this.disposeListeners = undefined;\n };\n }\n }\n _checkLimits() {\n super._checkLimits();\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n this.orthoWidth = this.clampOrthoWidth(this.orthoWidth);\n }\n }\n clampOrthoWidth(val) {\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n if (this.lowerRadiusLimit != null && val < this.lowerRadiusLimit) {\n val = this.lowerRadiusLimit;\n }\n if (this.upperRadiusLimit != null && val > this.upperRadiusLimit) {\n val = this.upperRadiusLimit;\n }\n }\n return val;\n }\n dispose() {\n super.dispose();\n if (this.disposeListeners) {\n this.disposeListeners();\n }\n }\n updateOrthographicPosition() {\n if (this.clientInfo) {\n const ratio = this.clientInfo.screenHeight / this.clientInfo.screenWidth;\n this.orthoRight = this.orthoWidth / 2;\n this.orthoLeft = -this.orthoWidth / 2;\n this.orthoTop = (this.orthoWidth * ratio) / 2;\n this.orthoBottom = (-this.orthoWidth * ratio) / 2;\n }\n }\n }\n\n const ANIMATION_FPS = 30;\n var eCameraType;\n (function (eCameraType) {\n eCameraType[eCameraType[\"Universal\"] = 0] = \"Universal\";\n eCameraType[eCameraType[\"ArcRotate\"] = 1] = \"ArcRotate\";\n })(eCameraType || (eCameraType = {}));\n (function (eCameraOrientation) {\n eCameraOrientation[\"perspective\"] = \"perspective\";\n eCameraOrientation[\"front\"] = \"front\";\n eCameraOrientation[\"left\"] = \"left\";\n eCameraOrientation[\"back\"] = \"back\";\n eCameraOrientation[\"right\"] = \"right\";\n eCameraOrientation[\"top\"] = \"top\";\n eCameraOrientation[\"bottom\"] = \"bottom\";\n })(exports.eCameraOrientation || (exports.eCameraOrientation = {}));\n class CameraTools {\n get cameraMoving() {\n const camera = this.scene.activeCamera;\n if (this._activeAnimation) {\n return true;\n }\n if (camera instanceof KbArcRotateCamera) {\n return (Math.abs(camera.inertialRadiusOffset) > 0 ||\n Math.abs(camera.inertialAlphaOffset) > 0 ||\n Math.abs(camera.inertialBetaOffset) > 0 ||\n Math.abs(camera.inertialOffsetPanningX) > 0 ||\n Math.abs(camera.inertialOffsetPanningY) > 0 ||\n Math.abs(camera.inertialOrthoZoom) > 0);\n }\n if (camera instanceof UniversalCamera) {\n return (Math.abs(camera.cameraDirection.x) > 0 ||\n Math.abs(camera.cameraDirection.y) > 0 ||\n Math.abs(camera.cameraDirection.z) > 0 ||\n Math.abs(camera.cameraRotation.x) > 0 ||\n Math.abs(camera.cameraRotation.y) > 0);\n }\n return false;\n }\n constructor(scene, canvas, kbViewer) {\n this.scene = scene;\n this.canvas = canvas;\n this.kbViewer = kbViewer;\n this._lastOrientation = exports.eCameraOrientation.perspective;\n this.minVector = new Vector3(0, 0, 0);\n this.maxVector = new Vector3(0, 0, 0);\n this.objectsToScaleWithDistance = new Map();\n this._beforeRender = () => {\n if (this._cameraSettingsChange && scene.activeCamera && this.cameraMoving) {\n const camera = scene.activeCamera;\n const changeList = {};\n copyCameraStateIntoViewpoint(changeList, camera);\n this._cameraSettingsChange.next(changeList);\n }\n };\n scene.registerBeforeRender(this._beforeRender);\n kbViewer.viewChanged.subscribe(() => {\n const camera = scene.activeCamera;\n if (camera) {\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n const dist = ((camera.orthoRight || 0) - (camera.orthoLeft || 0)) * 0.6;\n this.objectsToScaleWithDistance.forEach((param, item) => {\n if (item.isDisposed()) {\n this.objectsToScaleWithDistance.delete(item);\n return;\n }\n if (typeof param === 'function') {\n param(dist, camera.mode);\n }\n else {\n const scaledSize = param * dist;\n item.scaling.set(scaledSize, scaledSize, scaledSize);\n }\n });\n }\n else {\n let cameraPosition;\n if (camera instanceof WebXRCamera && camera.globalPosition) {\n cameraPosition = camera.globalPosition;\n }\n else if (camera instanceof ArcRotateCamera) {\n cameraPosition = getCameraPositionWithOffset(camera);\n }\n else {\n cameraPosition = camera.globalPosition;\n }\n this.objectsToScaleWithDistance.forEach((param, item) => {\n if (item.isDisposed()) {\n this.objectsToScaleWithDistance.delete(item);\n return;\n }\n const dist = item.absolutePosition.subtract(cameraPosition).length();\n if (typeof param === 'function') {\n param(dist, camera.mode);\n }\n else {\n const scaledSize = dist * param;\n item.scaling.set(scaledSize, scaledSize, scaledSize);\n }\n });\n }\n }\n });\n this.activeCamera = {\n get position() {\n return scene.activeCamera ? exports.KbVector.FromVec3(scene.activeCamera.position) : exports.KbVector.Zero();\n },\n set position(vector) {\n if (scene.activeCamera) {\n if (scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA &&\n scene.activeCamera instanceof ArcRotateCamera) {\n const target = scene.activeCamera.target;\n scene.activeCamera.position = vector\n .toVec3()\n .subtract(target)\n .normalize()\n .scale(5000)\n .add(target);\n }\n else {\n scene.activeCamera.position = vector.toVec3();\n }\n }\n },\n get targetPoint() {\n return scene.activeCamera instanceof ArcRotateCamera\n ? exports.KbVector.FromVec3(scene.activeCamera.target)\n : exports.KbVector.Zero();\n },\n set targetPoint(vector) {\n scene.activeCamera instanceof ArcRotateCamera && (scene.activeCamera.target = vector.toVec3());\n },\n get rotation() {\n return scene.activeCamera instanceof UniversalCamera\n ? exports.KbVector.FromVec3(scene.activeCamera.rotation)\n : exports.KbVector.Zero();\n },\n set rotation(vector) {\n scene.activeCamera instanceof UniversalCamera && (scene.activeCamera.rotation = vector.toVec3());\n },\n get offsetX() {\n return scene.activeCamera instanceof ArcRotateCamera ? scene.activeCamera.targetScreenOffset.x : 0;\n },\n set offsetX(offset) {\n scene.activeCamera instanceof ArcRotateCamera && (scene.activeCamera.targetScreenOffset.x = offset);\n },\n get offsetY() {\n return scene.activeCamera instanceof ArcRotateCamera ? scene.activeCamera.targetScreenOffset.y : 0;\n },\n set offsetY(offset) {\n scene.activeCamera instanceof ArcRotateCamera && (scene.activeCamera.targetScreenOffset.y = offset);\n },\n get projection() {\n if (!scene.activeCamera) {\n return undefined;\n }\n return scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA\n ? exports.eViewpointProjection.perspective\n : exports.eViewpointProjection.orthographic;\n },\n set projection(projection) {\n scene.activeCamera &&\n (scene.activeCamera.mode =\n projection === exports.eViewpointProjection.perspective\n ? Camera.PERSPECTIVE_CAMERA\n : Camera.ORTHOGRAPHIC_CAMERA);\n },\n get fov() {\n if (!scene.activeCamera) {\n return 50;\n }\n return scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA\n ? scene.activeCamera.orthoRight - scene.activeCamera.orthoLeft\n : (scene.activeCamera.fov * 180) / Math.PI;\n },\n set fov(fov) {\n if (!scene.activeCamera) {\n return;\n }\n if (scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA &&\n scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.orthoWidth = fov;\n }\n else {\n scene.activeCamera.fov = (fov * Math.PI) / 180;\n }\n },\n get allowOrbit() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return !scene.activeCamera.lockRotation;\n }\n else if (scene.activeCamera instanceof UniversalCamera) {\n return !!scene.activeCamera.inputs.attached.mouse;\n }\n return false;\n },\n set allowOrbit(allow) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.lockRotation = !allow;\n }\n else if (scene.activeCamera instanceof UniversalCamera) {\n scene.activeCamera.inputs.clear();\n enableFreeLook(scene.activeCamera);\n }\n },\n get allowPan() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return !scene.activeCamera.lockPanning;\n }\n else if (scene.activeCamera instanceof UniversalCamera) {\n return !!scene.activeCamera.inputs.attached.keyboard;\n }\n return false;\n },\n set allowPan(allow) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.lockPanning = !allow;\n }\n else if (scene.activeCamera instanceof UniversalCamera) {\n scene.activeCamera.inputs.clear();\n enableFreeMove(scene.activeCamera);\n }\n },\n get allowZoom() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return !scene.activeCamera.lockZoom;\n }\n return false;\n },\n set allowZoom(allow) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.lockZoom = !allow;\n }\n },\n get limitMinimumTargetDistance() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return scene.activeCamera.limitMinimumTargetDistance;\n }\n return false;\n },\n set limitMinimumTargetDistance(allow) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.limitMinimumTargetDistance = !allow;\n }\n },\n get minTargetDistance() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return scene.activeCamera.lowerRadiusLimit || defaults.ViewpointNode.minTargetDistance;\n }\n return defaults.ViewpointNode.minTargetDistance;\n },\n set minTargetDistance(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.lowerRadiusLimit = value;\n }\n },\n get maxTargetDistance() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return scene.activeCamera.upperRadiusLimit || defaults.ViewpointNode.maxTargetDistance;\n }\n return defaults.ViewpointNode.maxTargetDistance;\n },\n set maxTargetDistance(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.upperRadiusLimit = value;\n }\n },\n get orbitAxis() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return exports.KbVector.FromVec3(scene.activeCamera.upVector);\n }\n return exports.KbVector.From(defaults.ViewpointNode.orbitAxis);\n },\n set orbitAxis(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.upVector = value.toVec3();\n }\n },\n get limitMinLatitude() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return ((scene.activeCamera.lowerBetaLimit || 0) * 180) / Math.PI;\n }\n return defaults.ViewpointNode.limitMinLatitude;\n },\n set limitMinLatitude(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.lowerBetaLimit = (value * Math.PI) / 180;\n }\n },\n get limitMaxLatitude() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return (((typeof scene.activeCamera.upperBetaLimit === 'number'\n ? scene.activeCamera.upperBetaLimit\n : Math.PI) *\n 180) /\n Math.PI);\n }\n return defaults.ViewpointNode.limitMaxLatitude;\n },\n set limitMaxLatitude(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.upperBetaLimit = (value * Math.PI) / 180;\n }\n },\n get limitMinLongitude() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return scene.activeCamera.lowerAlphaLimit\n ? (scene.activeCamera.lowerAlphaLimit * 180) / Math.PI\n : defaults.ViewpointNode.limitMinLongitude;\n }\n return defaults.ViewpointNode.limitMinLongitude;\n },\n set limitMinLongitude(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.lowerAlphaLimit = (value * Math.PI) / 180;\n }\n },\n get limitMaxLongitude() {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n return scene.activeCamera.upperAlphaLimit\n ? (scene.activeCamera.upperAlphaLimit * 180) / Math.PI\n : defaults.ViewpointNode.limitMinLongitude;\n }\n return defaults.ViewpointNode.limitMinLongitude;\n },\n set limitMaxLongitude(value) {\n if (scene.activeCamera instanceof KbArcRotateCamera) {\n scene.activeCamera.upperAlphaLimit = (value * Math.PI) / 180;\n }\n },\n };\n }\n dispose() {\n this.scene.unregisterBeforeRender(this._beforeRender);\n }\n setPipeline(pipeline) {\n this.activePipeline = pipeline;\n if (this.scene.activeCamera) {\n this.applyScenePostProcesses(this.scene.activeCamera);\n }\n }\n /** Frames the current active camera to fit the provided mesh node\n * @param node The node to fit on the screen\n * @param padding If provided, pads the node by a percentage of the node's size.\n */\n frameCamera(node, options, camera) {\n const _options = {\n rotate: false,\n pan: true,\n padding: 1,\n zoom: true,\n ...(options || {}),\n };\n const activeCamera = camera || this.scene.activeCamera;\n if (!activeCamera) {\n throw Error('No active camera');\n }\n const bounding = this.kbViewer.bbCache.getWorld(node);\n if (!bounding || bounding.boundingInfo.diagonalLength === 0) {\n return; // no op if the bounding box doesn't exist\n }\n else {\n const childrenBounding = this.kbViewer.sceneNode.getChildren();\n const maxVector = bounding.boundingInfo.boundingBox.maximum;\n const minVector = bounding.boundingInfo.boundingBox.minimum;\n childrenBounding.forEach(element => {\n var _a, _b;\n if ((element instanceof exports.AnnotationNode && element.enabled) ||\n (element instanceof exports.DimensionNode && element.enabled)) {\n let nodeInfo;\n if (element instanceof exports.AnnotationNode) {\n nodeInfo = this.kbViewer.rendererManager.annotation.annotationStore.get(element._dynamicId);\n }\n if (element instanceof exports.DimensionNode) {\n nodeInfo = this.kbViewer.rendererManager.dimension.dimensionStore.get(element._dynamicId);\n }\n const minBoundingBox = (_a = nodeInfo === null || nodeInfo === void 0 ? void 0 : nodeInfo.meshInfo) === null || _a === void 0 ? void 0 : _a.textContainer.getHierarchyBoundingVectors().min;\n const maxBoundingBox = (_b = nodeInfo === null || nodeInfo === void 0 ? void 0 : nodeInfo.meshInfo) === null || _b === void 0 ? void 0 : _b.textContainer.getHierarchyBoundingVectors().max;\n if (minBoundingBox && minBoundingBox.x < minVector.x) {\n minVector.x = minBoundingBox.x;\n }\n if (minBoundingBox && minBoundingBox.y < minVector.y) {\n minVector.y = minBoundingBox.y;\n }\n if (minBoundingBox && minBoundingBox.z < minVector.z) {\n minVector.z = minBoundingBox.z;\n }\n if (maxBoundingBox && maxBoundingBox.x > maxVector.x) {\n maxVector.x = maxBoundingBox.x;\n }\n if (maxBoundingBox && maxBoundingBox.y > maxVector.y) {\n maxVector.y = maxBoundingBox.y;\n }\n if (maxBoundingBox && maxBoundingBox.z > maxVector.z) {\n maxVector.z = maxBoundingBox.z;\n }\n }\n });\n this.minVector.set(minVector.x, minVector.y, minVector.z);\n this.maxVector.set(maxVector.x, maxVector.y, maxVector.z);\n bounding.boundingInfo.boundingBox.reConstruct(this.minVector, this.maxVector, bounding.boundingInfo.boundingBox.getWorldMatrix());\n const bbCenter = bounding.center.toVec3();\n const bbCorners = bounding.boundingInfo.boundingBox.vectorsWorld;\n if (activeCamera instanceof UniversalCamera) {\n activeCamera.setTarget(bbCenter);\n }\n else if (activeCamera instanceof KbArcRotateCamera) {\n if (_options.rotate) {\n activeCamera.setTarget(bbCenter);\n if (_options.pan) {\n activeCamera.targetScreenOffset.set(0, 0);\n }\n }\n else if (_options.pan) {\n const cameraRay = activeCamera.getForwardRay();\n const cameraProjectionTargetPlane = Plane.FromPositionAndNormal(bbCenter, cameraRay.direction);\n const cameraDistance = cameraRay.intersectsPlane(cameraProjectionTargetPlane);\n const cameraProjectionTargetPoint = cameraRay.origin.add(cameraRay.direction.scale(cameraDistance));\n const cameraPositionWorldOffset = cameraProjectionTargetPoint.subtract(bbCenter);\n const planeProjectionX = Vector3.Cross(cameraRay.direction, Vector3.Up()).normalize();\n const planeProjectionY = Vector3.Cross(cameraRay.direction, planeProjectionX).normalize();\n const bbCenterOffset = new Vector2(Vector3.Dot(cameraPositionWorldOffset, planeProjectionX), -Vector3.Dot(cameraPositionWorldOffset, planeProjectionY));\n activeCamera.targetScreenOffset.copyFrom(bbCenterOffset);\n }\n if (_options.zoom) {\n const clientRect = this.canvas.getBoundingClientRect();\n const ratio = clientRect.height / clientRect.width;\n const cameraRay = activeCamera.getForwardRay();\n const xAxis = Vector3.Cross(cameraRay.direction, Vector3.Up()).normalize();\n const yAxis = Vector3.Cross(cameraRay.direction, xAxis).normalize();\n const cameraTruePosition = cameraRay.origin\n .add(xAxis.scale(-activeCamera.targetScreenOffset.x))\n .add(yAxis.scale(activeCamera.targetScreenOffset.y));\n const cameraTrueTarget = activeCamera.target\n .add(xAxis.scale(-activeCamera.targetScreenOffset.x))\n .add(yAxis.scale(activeCamera.targetScreenOffset.y));\n const xPlane = Plane.FromPositionAndNormal(cameraTruePosition, yAxis);\n const yPlane = Plane.FromPositionAndNormal(cameraTruePosition, xAxis);\n const padding = 1 + _options.padding / 100;\n if (activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n let maxX = 0, maxY = 0;\n bbCorners.forEach(bbCorner => {\n const xO = xPlane.signedDistanceTo(bbCorner) * padding;\n maxX = Math.max(maxX, Math.abs(xO));\n const yO = yPlane.signedDistanceTo(bbCorner) * padding;\n maxY = Math.max(maxY, Math.abs(yO));\n });\n // The calculated distance is the maximum distance from the centerline to the bounding box corner. So double it to get the total width/height\n activeCamera.orthoFit(maxY * 2, maxX * 2);\n }\n else {\n let desiredDistance = 0;\n const fovH = 2 * Math.atan(Math.tan(activeCamera.fov / 2) / ratio);\n const thV = Math.tan(activeCamera.fov / 2);\n const thH = Math.tan(fovH / 2);\n bbCorners.forEach(bbCorner => {\n const xO = xPlane.signedDistanceTo(bbCorner) * padding;\n const xP = bbCorner.subtract(cameraTrueTarget).subtract(yAxis.scale(xO));\n const xA = Math.abs(xO) / thV;\n const xR = Vector3.Dot(xP, cameraRay.direction.scale(-1)) + xA;\n desiredDistance = Math.max(desiredDistance, xR);\n const yO = yPlane.signedDistanceTo(bbCorner) * padding;\n const yP = bbCorner.subtract(cameraTrueTarget).subtract(xAxis.scale(yO));\n const yA = Math.abs(yO) / thH;\n const yR = Vector3.Dot(yP, cameraRay.direction.scale(-1)) + yA;\n desiredDistance = Math.max(desiredDistance, yR);\n });\n activeCamera.radius = Math.max(desiredDistance, 0.001);\n }\n }\n }\n this.kbViewer.fireViewChangedOnNextRender(); //render loop won't pick up that the view changed, because no kb3d nodes changes, so we must update it explicitly\n }\n }\n getScreenPositionOfNode(node) {\n if (!this.scene.activeCamera) {\n throw Error('No active camera');\n }\n const bNode = this.kbViewer.getRendererNode(node);\n if (bNode) {\n return nodeToScreen(bNode, this.scene.activeCamera);\n }\n }\n getScreenBoundingBoxOfNode(node) {\n if (!this.scene.activeCamera) {\n throw Error('No active camera');\n }\n const bNode = this.kbViewer.getRendererNode(node);\n if (bNode) {\n return getScreenBoundingBox(bNode, this.scene.activeCamera, true);\n }\n }\n moveCameraToViewpoint(viewpoint) {\n const newCamera = this.createCameraFromViewpoint(viewpoint);\n this._activateCamera(newCamera);\n }\n animateToViewpoint(viewpoint, options) {\n if (!this.scene.activeCamera) {\n throw Error('No active camera');\n }\n let activeCamera = this.scene.activeCamera;\n const _options = {\n duration: 1000,\n ...(options || {}),\n };\n const endFrame = 30 * (_options.duration / 1000);\n const animations = [];\n const ease = new SineEase();\n ease.setEasingMode(SineEase.EASINGMODE_EASEINOUT);\n const circEaseOut = new CircleEase();\n circEaseOut.setEasingMode(CircleEase.EASINGMODE_EASEOUT);\n // Create the new viewpoint converted to an arc rotate camera so we can tween arc rotate properties\n // The arc rotate cameras are easier to animate between nicely.\n const newCameraTarget = this.createCameraFromViewpoint(viewpoint, eCameraType.ArcRotate);\n const newCamera = this.createCameraFromViewpoint(viewpoint);\n if (_options.frame && newCamera instanceof ArcRotateCamera) {\n const target = _options.frameTarget || viewpoint._parentScene;\n if (!target) {\n throw Error('Cannot frame camera, no target node to frame');\n }\n else {\n this.frameCamera(target, _options.frameOptions || {}, newCameraTarget);\n this.frameCamera(target, _options.frameOptions || {}, newCamera);\n }\n }\n if (activeCamera instanceof ArcRotateCamera) {\n if (Math.abs(activeCamera.alpha) > Math.PI * 2) {\n activeCamera.alpha = activeCamera.alpha % (Math.PI * 2);\n }\n }\n if (activeCamera instanceof UniversalCamera && viewpoint.type != exports.eViewpointType.firstPerson) {\n const orbitRotation = activeCamera.rotationQuaternion\n ? activeCamera.rotationQuaternion.toEulerAngles()\n : activeCamera.rotation;\n const ray = activeCamera.getForwardRay(newCameraTarget.radius);\n // If the current camera is a universal camera, convert it to an arc rotate camera as well/\n // The arc rotate target position is placed from the camera at the same distance as the destination viewpoint's target\n activeCamera = new KbArcRotateCamera('temporaryCamera', -(orbitRotation.y + Math.PI / 2), Math.PI / 2 - orbitRotation.x, ray.length, ray.direction.scale(ray.length).add(ray.origin), this.scene);\n activeCamera.fov = this.scene.activeCamera.fov;\n this._activateCamera(activeCamera);\n }\n if (!newCameraTarget) {\n throw Error('Could not create new camera');\n }\n if (activeCamera instanceof UniversalCamera && viewpoint.type === exports.eViewpointType.firstPerson) {\n const targetRotation = new Vector3(0, 0, 0);\n const targetPosition = new Vector3(viewpoint.position.x, viewpoint.position.y, viewpoint.position.z);\n targetRotation.y = (viewpoint.rotation.y * Math.PI) / 180;\n targetRotation.x = (viewpoint.rotation.x * Math.PI) / 180;\n targetRotation.z = (viewpoint.rotation.z * Math.PI) / 180;\n let activeAlpha = activeCamera.rotation.y;\n let targetAlpha = (viewpoint.rotation.y * Math.PI) / 180;\n let arc = 0;\n //Normalizing values to be between -PI and PI\n activeAlpha = normalizeRotation(activeAlpha);\n targetAlpha = normalizeRotation(targetAlpha);\n //calculating shortest arc and seeing if it crosses zero\n //if it does, change the target vector to account for expected direction of animation\n if (activeAlpha > targetAlpha) {\n arc = activeAlpha - targetAlpha;\n }\n else {\n arc = targetAlpha - activeAlpha;\n }\n if (arc > Math.PI) {\n if (activeAlpha < targetAlpha) {\n targetRotation.y = targetRotation.y - 2 * Math.PI;\n }\n else {\n targetRotation.y = targetRotation.y + 2 * Math.PI;\n }\n }\n const translateRotation = new Animation('translateCameraRotation', 'rotation', ANIMATION_FPS, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateRotation.setKeys([\n { frame: 0, value: activeCamera.rotation },\n { frame: endFrame, value: targetRotation },\n ]);\n const translatePosition = new Animation('translateCameraPosition', 'position', ANIMATION_FPS, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translatePosition.setKeys([\n { frame: 0, value: activeCamera.position },\n { frame: endFrame, value: targetPosition },\n ]);\n const translateFov = new Animation('translateCameraFOV', 'fov', ANIMATION_FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateFov.setKeys([\n { frame: 0, value: activeCamera.fov },\n { frame: endFrame, value: (viewpoint.fov / 180) * Math.PI },\n ]);\n translateRotation.setEasingFunction(ease);\n translatePosition.setEasingFunction(ease);\n translateFov.setEasingFunction(ease);\n animations.push(translateRotation);\n animations.push(translatePosition);\n animations.push(translateFov);\n }\n else if (newCameraTarget instanceof ArcRotateCamera && activeCamera instanceof ArcRotateCamera) {\n // When rotating between two arc rotate cameras, rotate around the target while animating the target\n if (!activeCamera.target.equals(newCameraTarget.target)) {\n const translateTarget = new Animation('translateCameraTarget', 'target', ANIMATION_FPS, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateTarget.setKeys([\n { frame: 0, value: activeCamera.target },\n { frame: endFrame, value: newCameraTarget.target },\n ]);\n animations.push(translateTarget);\n }\n const translateA = new Animation('translateCameraA', 'alpha', ANIMATION_FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n let crossesZero = false;\n let arc = 0;\n let shortestArc = 0;\n //Normalizing values to be between -PI and PI\n activeCamera.alpha = normalizeRotation(activeCamera.alpha);\n newCameraTarget.alpha = normalizeRotation(newCameraTarget.alpha);\n //calculating shortest arc between two cameras\n if (activeCamera.alpha > newCameraTarget.alpha) {\n arc = activeCamera.alpha - newCameraTarget.alpha;\n }\n else {\n arc = newCameraTarget.alpha - activeCamera.alpha;\n }\n if (arc > Math.PI) {\n shortestArc = 2 * Math.PI - arc;\n crossesZero = true;\n }\n //altering newCameraTarget to take shortest path\n if (newCameraTarget.alpha > 0 && crossesZero) {\n newCameraTarget.alpha = activeCamera.alpha - shortestArc;\n }\n else if (newCameraTarget.alpha < 0 && crossesZero) {\n newCameraTarget.alpha = activeCamera.alpha + shortestArc;\n }\n translateA.setKeys([\n { frame: 0, value: activeCamera.alpha },\n { frame: endFrame, value: newCameraTarget.alpha },\n ]);\n const translateB = new Animation('translateCameraB', 'beta', ANIMATION_FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateB.setKeys([\n { frame: 0, value: activeCamera.beta },\n { frame: endFrame, value: newCameraTarget.beta },\n ]);\n const translateR = new Animation('translateCameraR', 'radius', ANIMATION_FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateR.setKeys([\n { frame: 0, value: activeCamera.radius },\n { frame: endFrame, value: newCameraTarget.radius },\n ]);\n const translateOffset = new Animation('translateCameraOffset', 'targetScreenOffset', ANIMATION_FPS, Animation.ANIMATIONTYPE_VECTOR2, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateOffset.setKeys([\n { frame: 0, value: activeCamera.targetScreenOffset },\n { frame: endFrame, value: newCameraTarget.targetScreenOffset },\n ]);\n const translateFov = new Animation('translateCameraFOV', 'fov', ANIMATION_FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateFov.setKeys([\n { frame: 0, value: activeCamera.fov },\n { frame: endFrame, value: newCameraTarget.fov },\n ]);\n if (activeCamera instanceof KbArcRotateCamera &&\n activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA &&\n newCameraTarget.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n const translateOrthoWidth = new Animation('translateOrthoWidth', 'orthoWidth', ANIMATION_FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\n translateOrthoWidth.setKeys([\n { frame: 0, value: activeCamera.orthoWidth },\n { frame: endFrame, value: newCameraTarget.orthoWidth },\n ]);\n translateOrthoWidth.setEasingFunction(ease);\n animations.push(translateOrthoWidth);\n }\n translateA.setEasingFunction(ease);\n translateB.setEasingFunction(ease);\n translateR.setEasingFunction(ease);\n translateOffset.setEasingFunction(ease);\n translateFov.setEasingFunction(circEaseOut);\n animations.push(translateA);\n animations.push(translateB);\n animations.push(translateR);\n animations.push(translateOffset);\n animations.push(translateFov);\n }\n animations.forEach(animation => {\n activeCamera.animations.push(animation);\n });\n return new Promise(resolve => {\n this._activeAnimation = this.scene.beginAnimation(activeCamera, 0, endFrame, false, 1, () => {\n // on end of animation\n delete this._activeAnimation;\n this._activateCamera(newCamera);\n resolve();\n });\n });\n }\n storeCameraSettings() {\n if (!this.scene.activeCamera) {\n throw Error('No active camera');\n }\n this._storedViewpoint = new exports.ViewpointNode();\n const camera = this.scene.activeCamera;\n copyCameraStateIntoViewpoint(this._storedViewpoint, camera);\n }\n restoreCameraSettings() {\n if (this._storedViewpoint) {\n this.moveCameraToViewpoint(this._storedViewpoint);\n }\n else {\n console.warn('No stored camera settings to restore');\n }\n }\n watch() {\n this._cameraSettingsChange = new Subject();\n return this._cameraSettingsChange.pipe(finalize(() => {\n delete this._cameraSettingsChange;\n }), share());\n }\n maintainNodeScreenSize(renderedNode, relativeSize) {\n this.objectsToScaleWithDistance.set(renderedNode, relativeSize);\n }\n clearMaintainedNodeScreenSize(renderedNode) {\n this.objectsToScaleWithDistance.delete(renderedNode);\n }\n _activateCamera(newCamera) {\n this.scene.cameras.forEach(camera => {\n if (camera !== newCamera) {\n /**\n * Don't dispose the whole camera because that goes too hard and disposes all the render target textures and\n * post processes which messes things up for the next camera that's reusing those things. Instead, just dispose the\n * parts of the camera we don't need.\n */\n camera.onViewMatrixChangedObservable.clear();\n camera.onProjectionMatrixChangedObservable.clear();\n camera.onAfterCheckInputsObservable.clear();\n camera.onRestoreStateObservable.clear();\n // Inputs\n if (camera.inputs) {\n camera.inputs.clear();\n }\n // Animations\n this.scene.stopAnimation(camera);\n // Remove from scene\n this.scene.removeCamera(camera);\n this.scene.getEngine().releaseRenderPassId(camera.renderPassId);\n }\n });\n this.scene.customRenderTargets.forEach(rtt => {\n rtt.activeCamera = newCamera;\n });\n this.applyScenePostProcesses(newCamera);\n newCamera.attachControl(false);\n this.scene.activeCamera = newCamera;\n }\n applyScenePostProcesses(camera) {\n if (this.activePipeline) {\n this.scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this.activePipeline.name, camera);\n }\n }\n createCameraFromViewpoint(viewpoint, convertToCameraType) {\n const viewer = this.kbViewer;\n const bbCache = this.kbViewer.bbCache;\n const sceneNode = this.kbViewer.sceneNode;\n if (this.disposePreviousCamera && !this.disposePreviousCamera.isStopped) {\n this.disposePreviousCamera.next();\n this.disposePreviousCamera.complete();\n }\n const dispose = (this.disposePreviousCamera = new Subject());\n switch (viewpoint.type) {\n case exports.eViewpointType.orbit:\n case exports.eViewpointType.overhead:\n if (convertToCameraType === eCameraType.Universal) {\n const universalCamera = new UniversalCamera(viewpoint.id, viewpoint.position.toVec3(), this.scene);\n // this should be set in the setCommonViewpointProperties\n // const direction = viewpoint.targetPoint!.subtract(viewpoint.position).toVec3();\n // universalCamera.rotation = rotationToVector(direction).toEulerAngles();\n applyViewpointProperties(viewpoint, universalCamera);\n return universalCamera;\n }\n else {\n const arcRotateCamera = new KbArcRotateCamera(viewpoint.id, 0, 0, 0, viewpoint.targetPoint ? viewpoint.targetPoint.toVec3() : Vector3.Zero(), this.scene);\n applyViewpointProperties(viewpoint, arcRotateCamera);\n // overhead camera overrides target\n if (viewpoint.type === exports.eViewpointType.overhead) {\n arcRotateCamera.lockRotation = true;\n arcRotateCamera.target = new Vector3(viewpoint.position.x, 0, viewpoint.position.z);\n }\n return arcRotateCamera;\n }\n case exports.eViewpointType.firstPerson:\n //case eViewpointType.fixedPosition:\n if (convertToCameraType === eCameraType.ArcRotate) {\n const arcRotateCamera = new KbArcRotateCamera(viewpoint.id, 0, 0, 0, viewpoint.position.toVec3(), this.scene);\n const orbitRotation = viewpoint.rotation.toVec3().scale(Math.PI / 180);\n applyViewpointProperties(viewpoint, arcRotateCamera);\n arcRotateCamera.alpha = orbitRotation.y - Math.PI / 2;\n arcRotateCamera.beta = Math.PI / 2 - orbitRotation.x;\n arcRotateCamera.radius = 0.0001;\n return arcRotateCamera;\n }\n else {\n const universalCamera = new UniversalCamera(viewpoint.id, viewpoint.position.toVec3(), this.scene);\n applyViewpointProperties(viewpoint, universalCamera);\n return universalCamera;\n }\n }\n return null;\n function applyViewpointProperties(viewpoint, camera) {\n if (viewpoint.projection === exports.eViewpointProjection.orthographic) {\n camera.mode = Camera.ORTHOGRAPHIC_CAMERA;\n camera.maxZ = 200000;\n if (camera instanceof ArcRotateCamera) {\n camera.orthoWidth = viewpoint.fov || 8;\n camera.wheelPrecision = 60;\n camera.pinchPrecision = 60;\n camera.setPosition(viewpoint.position.toVec3().subtract(camera.target).normalize().scale(5000).add(camera.target));\n }\n }\n else if (viewpoint.projection === exports.eViewpointProjection.perspective) {\n camera.mode = Camera.PERSPECTIVE_CAMERA;\n camera.fov = (viewpoint.fov * Math.PI) / 180;\n if (camera instanceof ArcRotateCamera) {\n camera.wheelDeltaPercentage = 0.01;\n //camera.wheelPrecision = 10;\n camera.speed = 0.0001;\n camera.lowerRadiusLimit = 0.0001;\n camera.pinchDeltaPercentage = 0.001;\n camera.setPosition(viewpoint.position.toVec3());\n }\n }\n if (camera instanceof ArcRotateCamera) {\n if (!viewpoint.allowOrbit) {\n camera.lockRotation = true;\n }\n if (!viewpoint.allowPan) {\n camera.lockPanning = true;\n }\n if (!viewpoint.allowZoom) {\n camera.lockZoom = true;\n }\n camera.useFramingBehavior = false;\n camera.targetScreenOffset.x = viewpoint.offsetX;\n camera.targetScreenOffset.y = viewpoint.offsetY;\n if (viewpoint.limitMinimumTargetDistance) {\n viewer.bbCache.rootBoundingBoxChanged\n .pipe(takeUntil(dispose))\n .pipe(startWith(null))\n .subscribe(() => {\n const bounding = viewer.bbCache.getWorld(sceneNode);\n if (bounding) {\n const minVector = new Vector3(bounding.min.x, bounding.min.y, bounding.min.z);\n const maxVector = new Vector3(bounding.max.x, bounding.max.y, bounding.max.z);\n const boundingSphere = new BoundingSphere(minVector, maxVector);\n camera.lowerRadiusLimit = boundingSphere.radiusWorld;\n }\n else {\n camera.lowerRadiusLimit = viewpoint.minTargetDistance;\n }\n });\n }\n else {\n camera.lowerRadiusLimit = viewpoint.minTargetDistance;\n }\n camera.upperRadiusLimit = viewpoint.maxTargetDistance;\n if (viewpoint.orbitAxis) {\n const upVector = viewpoint.orbitAxis.toVec3();\n if (upVector.length() === 0) {\n upVector.set(0, 1, 0);\n }\n camera.upVector = upVector;\n }\n if (viewpoint.limitLngOrbit) {\n camera.lowerAlphaLimit = (viewpoint.limitMinLongitude * Math.PI) / 180;\n camera.upperAlphaLimit = (viewpoint.limitMaxLongitude * Math.PI) / 180;\n }\n else {\n camera.lowerAlphaLimit = null;\n camera.upperAlphaLimit = null;\n }\n if (viewpoint.limitLatOrbit) {\n camera.lowerBetaLimit = (viewpoint.limitMinLatitude * Math.PI) / 180;\n camera.upperBetaLimit = (viewpoint.limitMaxLatitude * Math.PI) / 180;\n }\n else {\n camera.lowerBetaLimit = 0.001;\n camera.upperBetaLimit = Math.PI - 0.001;\n }\n }\n else if (camera instanceof UniversalCamera) {\n // // For fixed rotation, only allow targeting the camera with the mouse and disable movement.\n // if (viewpoint.type === eViewpointType.fixedPosition) {\n // camera.inputs.clear();\n // camera.inputs.addMouse();\n // }\n camera.inputs.clear();\n if (viewpoint.allowPan) {\n enableFreeMove(camera);\n }\n if (viewpoint.allowOrbit) {\n enableFreeLook(camera);\n }\n }\n if (viewpoint.targetMode === exports.eViewpointTargetMode.point) {\n camera.setTarget(viewpoint.targetPoint.toVec3());\n }\n else if (viewpoint.targetMode === exports.eViewpointTargetMode.mesh) {\n const targetMeshNode = viewpoint._manager.getById(viewpoint.targetMeshId);\n if (targetMeshNode) {\n // TODO: When updating to babylon 5.0, use targetHost property for targetting mesh\n bbCache.rootBoundingBoxChanged.pipe(takeUntil(dispose)).subscribe(() => {\n const bbInfo = bbCache.getWorld(targetMeshNode);\n if (bbInfo) {\n camera.setTarget(bbInfo.center.toVec3());\n }\n });\n }\n }\n else {\n // rotation\n if (camera instanceof ArcRotateCamera) {\n camera.alpha = (viewpoint.rotation.y * Math.PI) / 180; // yaw = longitude\n camera.beta = (viewpoint.rotation.x * Math.PI) / 180; // pitch = latitude\n }\n else {\n camera.rotation = viewpoint.rotation.toVec3().scale(Math.PI / 180);\n }\n }\n bbCache\n .watchForChanges(sceneNode)\n .pipe(takeUntil(dispose))\n .subscribe(bbInfo => {\n var _a;\n if (bbInfo && bbInfo.boundingInfo.diagonalLength > 0) {\n const cameraDistance = bbInfo.boundingInfo.diagonalLength * 2;\n /**\n * This piece of code is very important. if the maxZ is too small, things will disappear as you zoom out.\n * If the maxZ is too large, the camera will not have enough buffer and\n * all kinds of things get messed up - clicking doesn't work, you start getting z-fighting.\n * Smallest the maxZ should be \"10\" due to the grid.\n * However ortho camera should be double that because calculations are made from half of the frame\n * And perspective camera should also take the camera distance into account (but have some sane multiplier based on the mesh size)\n */\n // should we set the minZ here as well, or just hard code it?\n if (viewpoint.projection === exports.eViewpointProjection.orthographic &&\n camera instanceof ArcRotateCamera) {\n camera.setPosition(camera.position\n .subtract(camera.target)\n .normalize()\n .scale(cameraDistance)\n .add(camera.target));\n camera.maxZ = Math.max(cameraDistance, 10) * 2;\n }\n else if (camera instanceof ArcRotateCamera && camera.upperRadiusLimit) {\n camera.maxZ = Math.max(Math.max(cameraDistance, 10) * 16, camera.upperRadiusLimit + cameraDistance);\n }\n else {\n camera.maxZ = Math.max(cameraDistance, 10) * 16;\n }\n // If maxZ is too high then it breaks clicking because the unprojected rays start returning NaN/Infinity\n if (camera.maxZ > 200000) {\n camera.maxZ = 200000;\n }\n if ((_a = viewer.rendererManager.sceneRenderer) === null || _a === void 0 ? void 0 : _a.skybox) {\n // need to resize skybox if it exists, otherwise it will get clipped\n const scale = camera.maxZ / 2 / SKYBOX_SIZE;\n viewer.rendererManager.sceneRenderer.skybox.scaling = new Vector3(scale, scale, scale);\n }\n }\n });\n camera.onDisposeObservable.add(() => {\n dispose.next();\n dispose.complete();\n });\n camera.minZ = 0.01; // hack the camera minz until we have a more automated way to set it\n camera.doNotSerialize = true;\n }\n }\n orient(orientation) {\n const bbCache = this.kbViewer.bbCache;\n if (this._lastOrientation === exports.eCameraOrientation.perspective) {\n this._lastPerspectivePosition = exports.KbVector.From(this.scene.activeCamera.position);\n }\n //get a viewpoint representing the current camera settings\n const viewpoint = new exports.ViewpointNode();\n const camera = this.scene.activeCamera;\n copyCameraStateIntoViewpoint(viewpoint, camera);\n let targetPoint = exports.KbVector.Zero();\n if (viewpoint.targetMode == exports.eViewpointTargetMode.point) {\n targetPoint = viewpoint.targetPoint;\n }\n else if (viewpoint.targetMode == exports.eViewpointTargetMode.mesh) {\n const targetMeshNode = this.kbViewer.sceneNode._manager.getById(viewpoint.targetMeshId);\n if (targetMeshNode) {\n const bbInfo = bbCache.getWorld(targetMeshNode);\n if (bbInfo) {\n targetPoint = bbInfo.center;\n }\n }\n }\n let distance = viewpoint.position.subtract(targetPoint).length();\n let newPos = targetPoint.toObject();\n if (orientation == exports.eCameraOrientation.top) {\n newPos.y += distance;\n }\n else if (orientation == exports.eCameraOrientation.front) {\n newPos.z += distance;\n }\n else if (orientation == exports.eCameraOrientation.left) {\n newPos.x -= distance;\n }\n else if (orientation == exports.eCameraOrientation.back) {\n newPos.z -= distance;\n }\n else if (orientation == exports.eCameraOrientation.right) {\n newPos.x += distance;\n }\n else if (orientation == exports.eCameraOrientation.bottom) {\n newPos.y -= distance;\n }\n else if (orientation == exports.eCameraOrientation.perspective) {\n const lastLength = this._lastPerspectivePosition.length();\n const ratio = distance / lastLength;\n newPos = this._lastPerspectivePosition.scale(ratio);\n }\n viewpoint.position = exports.KbVector.From(newPos);\n if (orientation != exports.eCameraOrientation.perspective) {\n viewpoint.projection = exports.eViewpointProjection.orthographic;\n viewpoint.allowOrbit = false;\n }\n else {\n viewpoint.projection = exports.eViewpointProjection.perspective;\n viewpoint.allowOrbit = true;\n }\n if (this._lastOrientation === exports.eCameraOrientation.perspective &&\n orientation !== exports.eCameraOrientation.perspective) {\n //switching to orthographic so we need to deal with fov\n viewpoint.fov = 2 * distance * Math.tan(toRadians(viewpoint.fov / 2));\n }\n else if (this._lastOrientation !== exports.eCameraOrientation.perspective &&\n orientation === exports.eCameraOrientation.perspective) {\n const orthoWidth = viewpoint.fov; //in orthographic, fov is the ortho width\n distance = orthoWidth / (2 * Math.tan(toRadians(defaults.ViewpointNode.fov / 2)));\n viewpoint.position = this._lastPerspectivePosition.scale(distance / this._lastPerspectivePosition.length());\n viewpoint.fov = defaults.ViewpointNode.fov;\n }\n viewpoint.offsetX = 0;\n viewpoint.offsetY = 0;\n this.moveCameraToViewpoint(viewpoint);\n this.frameCamera(this.kbViewer.sceneNode, {\n rotate: false,\n pan: true,\n zoom: false,\n });\n this._lastOrientation = orientation;\n }\n }\n function enableFreeLook(camera) {\n camera.inputs.addMouse();\n }\n function enableFreeMove(camera) {\n camera.inputs.addKeyboard();\n camera.inputs.addTouch();\n }\n function copyCameraStateIntoViewpoint(viewpoint, camera) {\n let normalizedPosition = camera.position;\n // If this is an orthographic camera, the real position is set very far away to prevent clipping. So normalize the position so the biggest dimension is 5.\n if (camera instanceof ArcRotateCamera && camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n normalizedPosition = normalizedPosition.subtract(camera.position).normalize().add(camera.position);\n if (normalizedPosition.length() > 0) {\n const scale = Math.max(...normalizedPosition.asArray().map(dim => Math.abs(dim)));\n normalizedPosition = Vector3.FromArray(normalizedPosition.asArray().map(dim => Math.round((dim / scale) * 500) / 100));\n }\n }\n if (camera instanceof FreeCamera) {\n const rotDegrees = camera.rotation.scale(180 / Math.PI);\n viewpoint.rotation = exports.KbVector.FromVec3(rotDegrees);\n }\n viewpoint.position = exports.KbVector.FromVec3(normalizedPosition);\n viewpoint.offsetX = camera instanceof KbArcRotateCamera ? camera.targetScreenOffset.x : 0;\n viewpoint.offsetY = camera instanceof KbArcRotateCamera ? camera.targetScreenOffset.y : 0;\n viewpoint.fov =\n camera.mode === Camera.ORTHOGRAPHIC_CAMERA\n ? camera.orthoRight - camera.orthoLeft\n : (camera.fov * 180) / Math.PI;\n viewpoint.projection =\n camera.mode === Camera.ORTHOGRAPHIC_CAMERA\n ? exports.eViewpointProjection.orthographic\n : exports.eViewpointProjection.perspective;\n }\n function normalizeRotation(alpha) {\n const oneRotation = Math.PI * 2;\n const rotations = Math.floor(alpha / oneRotation);\n const radiansToRemove = rotations > 1 ? rotations * oneRotation : 0;\n const normalizedRotation = alpha - radiansToRemove;\n return normalizedRotation;\n }\n\n /**\n * Class used to store a cell in an octree\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\n */\n class OctreeBlock {\n /**\n * Creates a new block\n * @param minPoint defines the minimum vector (in world space) of the block's bounding box\n * @param maxPoint defines the maximum vector (in world space) of the block's bounding box\n * @param capacity defines the maximum capacity of this block (if capacity is reached the block will be split into sub blocks)\n * @param depth defines the current depth of this block in the octree\n * @param maxDepth defines the maximal depth allowed (beyond this value, the capacity is ignored)\n * @param creationFunc defines a callback to call when an element is added to the block\n */\n constructor(minPoint, maxPoint, capacity, depth, maxDepth, creationFunc) {\n /**\n * Gets the content of the current block\n */\n this.entries = new Array();\n this._boundingVectors = new Array();\n this._capacity = capacity;\n this._depth = depth;\n this._maxDepth = maxDepth;\n this._creationFunc = creationFunc;\n this._minPoint = minPoint;\n this._maxPoint = maxPoint;\n this._boundingVectors.push(minPoint.clone());\n this._boundingVectors.push(maxPoint.clone());\n this._boundingVectors.push(minPoint.clone());\n this._boundingVectors[2].x = maxPoint.x;\n this._boundingVectors.push(minPoint.clone());\n this._boundingVectors[3].y = maxPoint.y;\n this._boundingVectors.push(minPoint.clone());\n this._boundingVectors[4].z = maxPoint.z;\n this._boundingVectors.push(maxPoint.clone());\n this._boundingVectors[5].z = minPoint.z;\n this._boundingVectors.push(maxPoint.clone());\n this._boundingVectors[6].x = minPoint.x;\n this._boundingVectors.push(maxPoint.clone());\n this._boundingVectors[7].y = minPoint.y;\n }\n // Property\n /**\n * Gets the maximum capacity of this block (if capacity is reached the block will be split into sub blocks)\n */\n get capacity() {\n return this._capacity;\n }\n /**\n * Gets the minimum vector (in world space) of the block's bounding box\n */\n get minPoint() {\n return this._minPoint;\n }\n /**\n * Gets the maximum vector (in world space) of the block's bounding box\n */\n get maxPoint() {\n return this._maxPoint;\n }\n // Methods\n /**\n * Add a new element to this block\n * @param entry defines the element to add\n */\n addEntry(entry) {\n if (this.blocks) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.addEntry(entry);\n }\n return;\n }\n this._creationFunc(entry, this);\n if (this.entries.length > this.capacity && this._depth < this._maxDepth) {\n this.createInnerBlocks();\n }\n }\n /**\n * Remove an element from this block\n * @param entry defines the element to remove\n */\n removeEntry(entry) {\n if (this.blocks) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.removeEntry(entry);\n }\n return;\n }\n const entryIndex = this.entries.indexOf(entry);\n if (entryIndex > -1) {\n this.entries.splice(entryIndex, 1);\n }\n }\n /**\n * Add an array of elements to this block\n * @param entries defines the array of elements to add\n */\n addEntries(entries) {\n for (let index = 0; index < entries.length; index++) {\n const mesh = entries[index];\n this.addEntry(mesh);\n }\n }\n /**\n * Test if the current block intersects the frustum planes and if yes, then add its content to the selection array\n * @param frustumPlanes defines the frustum planes to test\n * @param selection defines the array to store current content if selection is positive\n * @param allowDuplicate defines if the selection array can contains duplicated entries\n */\n select(frustumPlanes, selection, allowDuplicate) {\n if (BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {\n if (this.blocks) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.select(frustumPlanes, selection, allowDuplicate);\n }\n return;\n }\n if (allowDuplicate) {\n selection.concat(this.entries);\n }\n else {\n selection.concatWithNoDuplicate(this.entries);\n }\n }\n }\n /**\n * Test if the current block intersect with the given bounding sphere and if yes, then add its content to the selection array\n * @param sphereCenter defines the bounding sphere center\n * @param sphereRadius defines the bounding sphere radius\n * @param selection defines the array to store current content if selection is positive\n * @param allowDuplicate defines if the selection array can contains duplicated entries\n */\n intersects(sphereCenter, sphereRadius, selection, allowDuplicate) {\n if (BoundingBox.IntersectsSphere(this._minPoint, this._maxPoint, sphereCenter, sphereRadius)) {\n if (this.blocks) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.intersects(sphereCenter, sphereRadius, selection, allowDuplicate);\n }\n return;\n }\n if (allowDuplicate) {\n selection.concat(this.entries);\n }\n else {\n selection.concatWithNoDuplicate(this.entries);\n }\n }\n }\n /**\n * Test if the current block intersect with the given ray and if yes, then add its content to the selection array\n * @param ray defines the ray to test with\n * @param selection defines the array to store current content if selection is positive\n */\n intersectsRay(ray, selection) {\n if (ray.intersectsBoxMinMax(this._minPoint, this._maxPoint)) {\n if (this.blocks) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.intersectsRay(ray, selection);\n }\n return;\n }\n selection.concatWithNoDuplicate(this.entries);\n }\n }\n /**\n * Subdivide the content into child blocks (this block will then be empty)\n */\n createInnerBlocks() {\n OctreeBlock._CreateBlocks(this._minPoint, this._maxPoint, this.entries, this._capacity, this._depth, this._maxDepth, this, this._creationFunc);\n this.entries.splice(0);\n }\n /**\n * @internal\n */\n static _CreateBlocks(worldMin, worldMax, entries, maxBlockCapacity, currentDepth, maxDepth, target, creationFunc) {\n target.blocks = new Array();\n const blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\n // Segmenting space\n for (let x = 0; x < 2; x++) {\n for (let y = 0; y < 2; y++) {\n for (let z = 0; z < 2; z++) {\n const localMin = worldMin.add(blockSize.multiplyByFloats(x, y, z));\n const localMax = worldMin.add(blockSize.multiplyByFloats(x + 1, y + 1, z + 1));\n const block = new OctreeBlock(localMin, localMax, maxBlockCapacity, currentDepth + 1, maxDepth, creationFunc);\n block.addEntries(entries);\n target.blocks.push(block);\n }\n }\n }\n }\n }\n\n /**\n * Octrees are a really powerful data structure that can quickly select entities based on space coordinates.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\n */\n class Octree {\n /**\n * Creates a octree\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\n * @param creationFunc function to be used to instantiate the octree\n * @param maxBlockCapacity defines the maximum number of meshes you want on your octree's leaves (default: 64)\n * @param maxDepth defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.)\n */\n constructor(creationFunc, maxBlockCapacity, \n /** Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.) */\n maxDepth = 2) {\n this.maxDepth = maxDepth;\n /**\n * Content stored in the octree\n */\n this.dynamicContent = new Array();\n this._maxBlockCapacity = maxBlockCapacity || 64;\n this._selectionContent = new SmartArrayNoDuplicate(1024);\n this._creationFunc = creationFunc;\n }\n // Methods\n /**\n * Updates the octree by adding blocks for the passed in meshes within the min and max world parameters\n * @param worldMin worldMin for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\n * @param worldMax worldMax for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\n * @param entries meshes to be added to the octree blocks\n */\n update(worldMin, worldMax, entries) {\n OctreeBlock._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);\n }\n /**\n * Adds a mesh to the octree\n * @param entry Mesh to add to the octree\n */\n addMesh(entry) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.addEntry(entry);\n }\n }\n /**\n * Remove an element from the octree\n * @param entry defines the element to remove\n */\n removeMesh(entry) {\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.removeEntry(entry);\n }\n }\n /**\n * Selects an array of meshes within the frustum\n * @param frustumPlanes The frustum planes to use which will select all meshes within it\n * @param allowDuplicate If duplicate objects are allowed in the resulting object array\n * @returns array of meshes within the frustum\n */\n select(frustumPlanes, allowDuplicate) {\n this._selectionContent.reset();\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.select(frustumPlanes, this._selectionContent, allowDuplicate);\n }\n if (allowDuplicate) {\n this._selectionContent.concat(this.dynamicContent);\n }\n else {\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\n }\n return this._selectionContent;\n }\n /**\n * Test if the octree intersect with the given bounding sphere and if yes, then add its content to the selection array\n * @param sphereCenter defines the bounding sphere center\n * @param sphereRadius defines the bounding sphere radius\n * @param allowDuplicate defines if the selection array can contains duplicated entries\n * @returns an array of objects that intersect the sphere\n */\n intersects(sphereCenter, sphereRadius, allowDuplicate) {\n this._selectionContent.reset();\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.intersects(sphereCenter, sphereRadius, this._selectionContent, allowDuplicate);\n }\n if (allowDuplicate) {\n this._selectionContent.concat(this.dynamicContent);\n }\n else {\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\n }\n return this._selectionContent;\n }\n /**\n * Test if the octree intersect with the given ray and if yes, then add its content to resulting array\n * @param ray defines the ray to test with\n * @returns array of intersected objects\n */\n intersectsRay(ray) {\n this._selectionContent.reset();\n for (let index = 0; index < this.blocks.length; index++) {\n const block = this.blocks[index];\n block.intersectsRay(ray, this._selectionContent);\n }\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\n return this._selectionContent;\n }\n }\n /**\n * Adds a mesh into the octree block if it intersects the block\n * @param entry\n * @param block\n */\n Octree.CreationFuncForMeshes = (entry, block) => {\n const boundingInfo = entry.getBoundingInfo();\n if (!entry.isBlocked && boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\n block.entries.push(entry);\n }\n };\n /**\n * Adds a submesh into the octree block if it intersects the block\n * @param entry\n * @param block\n */\n Octree.CreationFuncForSubMeshes = (entry, block) => {\n const boundingInfo = entry.getBoundingInfo();\n if (boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\n block.entries.push(entry);\n }\n };\n\n const CLICK_THRESHOLD = 8;\n class Dragger {\n constructor(viewer, scene) {\n this.viewer = viewer;\n this.scene = scene;\n this._externalConnectors = new Map(); //connectors out in the scene that are not part of what is being dragged\n this._dragConnectors = new Map(); //connectors that are children of what is being dragged\n this._dragConnectorsByDynamicId = new Map(); //the drag connectors stored by their dynamic id\n this._dropPreviewConnectors = new Map(); //the drop preview is a clone of the dragNode, this tracks the connector meshes in the drop preview\n this._dragFriends = new Set();\n this._dragFriendMeshes = new Array();\n this._dragFriendConnectors = new Set();\n this._matedConnectors = new Set();\n }\n startDrag(pointerArgs, draggable, onComplete) {\n var _a;\n let totalMoved = 0;\n let lastX;\n let lastY;\n this._pointerObserver = this.scene.onPointerObservable.add(p => {\n switch (p.type) {\n case PointerEventTypes.POINTERMOVE: {\n let movX = 0;\n let movY = 0;\n if (typeof lastX === 'undefined' || typeof lastY === 'undefined') {\n lastX = p.event.offsetX;\n lastY = p.event.offsetY;\n }\n else {\n movX = Math.abs(lastX - p.event.offsetX);\n movY = Math.abs(lastY - p.event.offsetY);\n }\n totalMoved += Math.sqrt(movX * movX + movY * movY);\n if (totalMoved > CLICK_THRESHOLD) {\n this.startDragCommit(pointerArgs, draggable, onComplete);\n this.dragging(p);\n }\n break;\n }\n case PointerEventTypes.POINTERUP: {\n if (totalMoved > CLICK_THRESHOLD) {\n this.dropped(p);\n }\n this.scene.onPointerObservable.remove(this._pointerObserver);\n this._pointerObserver = undefined;\n break;\n }\n }\n });\n (_a = this.scene.activeCamera) === null || _a === void 0 ? void 0 : _a.detachControl();\n }\n startDragCommit(pointerArgs, draggable, onComplete) {\n if (!this._draggable) {\n this._connectorRenderer = this.viewer.rendererManager.connector;\n this._dragNode = pointerArgs.sourceNode;\n this._dragNodeStartPosition = this._dragNode.position.clone();\n this._dragMesh = this.viewer.rendererManager.mesh.get3d(this._dragNode);\n if (this._dragMesh.parent) {\n this._dragNodeInverseTransform = this._dragMesh.parent\n .computeWorldMatrix(true)\n .clone()\n .setTranslation(Vector3.Zero())\n .invert();\n }\n this._draggable = draggable;\n if (this._draggable.connectionMode == null)\n this._draggable.connectionMode = exports.eConnectionMode.none;\n if (this._draggable.connectionType == null)\n this._draggable.connectionType = exports.eMateType.fastened;\n if (this._draggable.connectRadius == null) {\n if (this._draggable.connectionMode == exports.eConnectionMode.screen) {\n this._draggable.connectRadius = 5; //5 pixels\n }\n else {\n this._draggable.connectRadius = 0.3; //3d units\n }\n }\n if (this._draggable.dragOpacity == null)\n this._draggable.dragOpacity = 0.7;\n this._onComplete = onComplete;\n this.setupDragSurface(pointerArgs);\n if (this._draggable.dragStart) {\n this._draggable.dragStart(this.getDragArgs(pointerArgs, this._dragNodeStartPosition, this._dragMesh.rotationQuaternion));\n }\n this.setupDragFriends();\n this.setupConnectors();\n this.setOpacity(this._draggable.dragOpacity, this._dragMesh, ...this._dragFriendMeshes);\n }\n }\n dragging(p) {\n // this._dragNode._dragging = true;\n const newConnection = this.findConnection();\n //let connectionChanged = !this.connectionsAreEqual(newConnection, this._activeConnection);\n this._activeConnection = newConnection;\n if (this._activeConnection) {\n //if (connectionChanged) { //don't bother processing the connection if it's the same\n this.showDropPreview(this._activeConnection);\n //}\n }\n else {\n this.hideDropPreview();\n }\n this.processDragPosition(p, this._draggable.dragging);\n }\n applyDragResultToNode(node, dragArgs, applyEuler) {\n node.position = dragArgs.newPos;\n // If euler rotation was changed, apply the changed euler rotation. If not, then apply the quaternion rotation regardless of whether it was changed.\n if (applyEuler) {\n node.eulerRotation = dragArgs.newRotationEuler;\n const newKbQuat = exports.KbQuaternion.FromYawPitchRoll(dragArgs.newRotationEuler);\n dragArgs.newRotationAngle = newKbQuat.getAngle();\n dragArgs.newRotationAxis = newKbQuat.getAxis();\n node.rotationAxis = dragArgs.newRotationAxis;\n node.rotationAngle = dragArgs.newRotationAngle;\n }\n else {\n node.rotationAxis = dragArgs.newRotationAxis;\n node.rotationAngle = dragArgs.newRotationAngle;\n node.eulerRotation = exports.KbQuaternion.FromRotationAxis(dragArgs.newRotationAxis, dragArgs.newRotationAngle).toEuler();\n }\n }\n dropped(p) {\n this._dragNode._primeMover = false;\n const complete = new Promise(resolve => {\n if (this._activeConnection) {\n this._activeConnection.otherConnector._parent._primeMover = true;\n this.connect(this._activeConnection, this._dragMesh);\n // let newRotation = KbVector.FromVec3(this._dragMesh.rotation);\n const dragArgs = {\n ...this.getDragArgs(p, this._dragMesh.position, this._dragMesh.rotationQuaternion),\n connection: this._activeConnection,\n };\n if (this._draggable.withMates) {\n dragArgs.mate = this.viewer.sceneNode._manager.create(Token.MateNode, {\n connector1: this.viewer.sceneNode.getNestedPathTo(dragArgs.connection.otherConnector),\n connector2: this.viewer.sceneNode.getNestedPathTo(dragArgs.connection.dragConnector),\n mateType: this._draggable.connectionType,\n });\n }\n const previousEuler = dragArgs.newRotationEuler.clone();\n this.applyDragResultToNode(this._dragNode, dragArgs, !previousEuler.equal(dragArgs.newRotationEuler));\n if (dragArgs.mate) {\n this.viewer.sceneNode.mates.push(dragArgs.mate);\n }\n this.viewer.forceAndWaitForNextRender().then(() => {\n if (this._draggable.dropped) {\n this._draggable.dropped(dragArgs);\n if (!dragArgs.allow) {\n console.warn('Cannot disallow dropping when using connectors, use canConnect handler instead');\n }\n }\n resolve();\n });\n }\n else {\n this.processDragPosition(p, this._draggable.dragging);\n this.processDragPosition(p, this._draggable.dropped);\n resolve();\n }\n });\n complete.then(() => {\n var _a;\n this.toggleAllConnectors(false);\n this.resetOpacity(this._dragMesh, ...this._dragFriendMeshes);\n (_a = this.scene.activeCamera) === null || _a === void 0 ? void 0 : _a.attachControl(this.viewer.canvas);\n if (this._onComplete)\n this._onComplete();\n this.disposeDropPreview();\n this._onComplete = undefined;\n this._dragNode = undefined;\n this._dragMesh = undefined;\n this._draggable = undefined;\n this._dragPlane = undefined;\n this._dragSurfaces = undefined;\n this._onComplete = undefined;\n if (this._externalConnectors)\n this._externalConnectors.clear();\n if (this._dragConnectors)\n this._dragConnectors.clear();\n if (this._dragConnectorsByDynamicId)\n this._dragConnectorsByDynamicId.clear();\n if (this._dropPreviewConnectors)\n this._dropPreviewConnectors.clear();\n this._oct = undefined;\n this._quadTree = undefined;\n if (this._quadTree)\n this._quadTree.items;\n this._dropPreview = undefined;\n this._activeConnection = undefined;\n this._connectorRenderer = undefined;\n if (this._dragFriends)\n this._dragFriends.clear();\n if (this._dragFriendMeshes)\n this._dragFriendMeshes.clear();\n if (this._dragFriendConnectors)\n this._dragFriendConnectors.clear();\n if (this._matedConnectors)\n this._matedConnectors.clear();\n });\n }\n processDragPosition(p, event) {\n const newMouseIntersect = this.intersectPointerToDragSurface(p);\n if (newMouseIntersect) {\n let newPos;\n if (this._draggable.disableOffset || this._draggable.mode == exports.eDragMode.surface) {\n newPos = exports.KbVector.FromVec3(newMouseIntersect);\n }\n else {\n if (this._startMouseIntersect) {\n const delta = newMouseIntersect.subtract(this._startMouseIntersect);\n if (this._dragNodeInverseTransform) {\n Vector3.TransformCoordinatesToRef(delta, this._dragNodeInverseTransform, delta);\n }\n newPos = this._dragNodeStartPosition.add(delta);\n }\n else {\n newPos = this._dragNodeStartPosition;\n this._startMouseIntersect = newMouseIntersect;\n }\n }\n const dragArgs = this.getDragArgs(p, newPos, this._dragMesh.rotationQuaternion);\n const previousEuler = dragArgs.newRotationEuler.clone();\n if (event) {\n event(dragArgs);\n }\n if (dragArgs.allow) {\n this.applyDragResultToNode(this._dragNode, dragArgs, !previousEuler.equal(dragArgs.newRotationEuler));\n }\n return dragArgs;\n }\n return undefined;\n }\n setupDragSurface(p) {\n const d = this._draggable;\n const manager = this._dragNode._manager;\n if (d.mode == exports.eDragMode.plane) {\n // d.planeOrigin = p.pickedPoint!; // d.planeOrigin || this._dragNode.position;\n /** intersection plane is defined by the pickedPoint and the plane normal */\n d.planeNormal = d.planeNormal || new exports.KbVector(0, 1, 0);\n this._dragPlane = Plane.FromPositionAndNormal(p.pickInfo.pickedPoint, d.planeNormal.toVec3());\n }\n else if (d.mode == exports.eDragMode.free) {\n const cameraDirection = this.scene.activeCamera.position.subtract(this._dragMesh.getAbsolutePosition());\n this._dragPlane = Plane.FromPositionAndNormal(this._dragNode.position.toVec3(), cameraDirection);\n }\n else if (d.mode == exports.eDragMode.surface) {\n const surfaceIds = Array.isArray(d.surfaceNodes) ? d.surfaceNodes : [d.surfaceNodes];\n this._dragSurfaces =\n surfaceIds.map(sn => { var _a; return sn && ((_a = manager.getById(sn)) === null || _a === void 0 ? void 0 : _a._dynamicId); }).filter(sn => sn != null) ||\n [];\n }\n }\n intersectPointerToDragSurface(p) {\n return this.intersectDragSurface(p.pickInfo.ray);\n }\n intersectDragSurface(ray) {\n switch (this._draggable.mode) {\n case exports.eDragMode.plane:\n case exports.eDragMode.free: {\n const distance = ray.intersectsPlane(this._dragPlane);\n if (distance != null) {\n return ray.direction.scale(distance).add(ray.origin);\n }\n break;\n }\n case exports.eDragMode.surface: {\n const surfacePick = this.scene.pickWithRay(ray, mesh => {\n return this._dragSurfaces.some(sn => mesh.id == sn);\n });\n if (surfacePick && surfacePick.pickedPoint) {\n return surfacePick.pickedPoint;\n }\n break;\n }\n }\n return undefined;\n }\n getDragArgs(p, newPos, newRotation) {\n var _a, _b;\n const newKbRotation = exports.KbQuaternion.FromQuat(newRotation || Quaternion.Identity());\n return {\n dragNode: this._dragNode,\n startPos: this._dragNodeStartPosition,\n allow: true,\n u: ((_a = p.pickInfo) === null || _a === void 0 ? void 0 : _a.bu) || 0.5,\n v: ((_b = p.pickInfo) === null || _b === void 0 ? void 0 : _b.bv) || 0.5,\n newPos: newPos instanceof Vector3 ? exports.KbVector.FromVec3(newPos) : newPos,\n newRotationAxis: newKbRotation.getAxis(),\n newRotationAngle: newKbRotation.getAngle(),\n newRotationEuler: newKbRotation.toEuler(),\n };\n }\n findConnection() {\n if (this._draggable.connectionMode != exports.eConnectionMode.none) {\n const potentialConnectors = new Array();\n for (const [dragConnector, dragConnectorMesh] of this._dragConnectors) {\n const dragConPos = dragConnectorMesh.getAbsolutePosition();\n for (const p of this.intersectOctree(dragConPos)) {\n potentialConnectors.push({\n ...p,\n dragConnector,\n dragConnectorMesh,\n });\n }\n }\n if (this._draggable.connectionMode == exports.eConnectionMode.world) {\n potentialConnectors.sortBy(p => p.proximity);\n }\n else {\n potentialConnectors.sortBy(p => p.distanceToCamera);\n }\n for (const p of potentialConnectors) {\n const otherConnector = getByDynamicId(p.otherMesh.id);\n const a = {\n dragConnector: p.dragConnector,\n otherConnector: otherConnector,\n dragNode: p.dragConnector._parent,\n otherNode: otherConnector._parent,\n allow: true,\n // Private properties below, don't expose to Snap\n dragConnectorMesh: p.dragConnectorMesh,\n otherConnectorMesh: p.otherMesh,\n };\n if (this._draggable.canConnect) {\n this._draggable.canConnect(a);\n }\n if (a.allow) {\n return a;\n }\n }\n }\n }\n connectionsAreEqual(c1, c2) {\n return ((!c1 && !c2) || (c1 && c2 && c1.dragConnector == c2.dragConnector && c1.otherConnector == c2.otherConnector));\n }\n setupConnectors() {\n if (this._draggable.connectionMode != exports.eConnectionMode.none) {\n const externalConnectorMeshes = new Set();\n for (const c of this.viewer.sceneNode.getAllConnectors()) {\n if (!this._dragFriendConnectors.has(c) &&\n (!this._draggable.withMates || !this._matedConnectors.has(c)) &&\n this.parentsEnabled(c)) {\n let mesh = this.getConnectorMesh(c);\n if (!mesh) {\n this._connectorRenderer.update3d(c);\n mesh = this.getConnectorMesh(c);\n }\n externalConnectorMeshes.add(mesh);\n this._externalConnectors.set(c, mesh);\n }\n }\n const dragConnectors = this._dragNode\n .filterNodes(n => isSpaceNode(n) && n.visible, true, false)\n .selectMany(n => n.connectors);\n for (const c of dragConnectors) {\n //remove the drag connectors from the outside connectors\n if (this._externalConnectors.has(c)) {\n const mesh = this._externalConnectors.get(c);\n this._dragConnectors.set(c, mesh);\n this._dragConnectorsByDynamicId.set(c._dynamicId, c);\n this._externalConnectors.delete(c);\n externalConnectorMeshes.delete(mesh);\n }\n }\n this.toggleAllConnectors(true);\n if (this._draggable.connectionMode == exports.eConnectionMode.world) {\n //create an octree for holding the connectors\n this._oct = new Octree(Octree.CreationFuncForMeshes, 64, 2);\n //get the bounding extents of all the external connectors to contain the octree volume\n const boundingVectors = this.scene.getWorldExtends(m => externalConnectorMeshes.has(m));\n //update the octree with the connector meshes\n this._oct.update(boundingVectors.min, boundingVectors.max, [...externalConnectorMeshes]);\n }\n else {\n //screen mode\n const extConnectorPositions = new Array();\n externalConnectorMeshes.forEach(m => {\n extConnectorPositions.push({\n mesh: m,\n pos: toScreen(m.getAbsolutePosition(), this.scene.activeCamera),\n });\n });\n const engine = this.scene.getEngine();\n this._quadTree = new QuadTree({\n items: extConnectorPositions,\n xSelector: d => d.pos.x,\n ySelector: d => d.pos.y,\n capacity: 4,\n xmin: 0,\n xmax: engine.getRenderWidth(),\n ymin: 0,\n ymax: engine.getRenderHeight(),\n });\n }\n }\n }\n parentsEnabled(item) {\n while (item._parent && item._parent instanceof exports.SpaceNode) {\n if (!item._parent.visible) {\n return false;\n }\n item = item._parent;\n }\n return true;\n }\n setupDragFriends() {\n const activeMates = this.viewer.getActiveMates();\n for (const mate of activeMates) {\n const c1 = mate.getC1();\n if (c1 && isConnector(c1))\n this._matedConnectors.add(c1);\n const c2 = mate.getC2();\n if (c2 && isConnector(c2))\n this._matedConnectors.add(c2);\n }\n this._dragFriends = getNodeChain(this._dragNode, activeMates);\n this._dragFriends.forEach(friend => {\n if (!(friend instanceof exports.SpaceNode)) {\n this._dragFriends.delete(friend);\n }\n });\n for (const friendNode of this._dragFriends) {\n if (friendNode instanceof exports.SpaceNode) {\n friendNode._primeMover = false;\n const friendMesh = this.viewer.rendererManager.mesh.get3d(friendNode);\n if (friendMesh) {\n this._dragFriendMeshes.push(friendMesh);\n }\n const connectors = friendNode.filterByType(Token.Connector);\n for (const c of connectors)\n this._dragFriendConnectors.add(c);\n }\n }\n this._dragNode._primeMover = true;\n }\n getConnectorMesh(c) {\n return this._connectorRenderer.get3d(c);\n }\n toggleAllConnectors(show) {\n if (this._draggable.showConnectors) {\n for (const [c] of this._externalConnectors) {\n c._visible = show;\n }\n for (const [c] of this._dragConnectors) {\n c._visible = show;\n }\n }\n }\n intersectOctree(v) {\n let potentials = new Array();\n if (this._draggable.connectionMode == exports.eConnectionMode.world) {\n const bpotentials = this._oct.intersects(v, this._draggable.connectRadius, false);\n bpotentials.forEach(p => {\n const proximity = p.getAbsolutePosition().subtract(v).length();\n if (proximity < this._draggable.connectRadius) {\n potentials.push({ otherMesh: p, proximity });\n }\n });\n //potentials.sortBy(p => p.proximity);\n }\n else {\n //screen mode\n const screenPos = toScreen(v, this.scene.activeCamera);\n potentials = this._quadTree.find(screenPos, this._draggable.connectRadius).map(p => {\n return {\n otherMesh: p.item.mesh,\n proximity: p.proximity,\n distanceToCamera: Vector3.Distance(this.scene.activeCamera.position, p.item.mesh.getAbsolutePosition()),\n };\n });\n //potentials.sortBy(i => i.distanceToCamera);\n // let ray = this.scene.createPickingRay(screenPos.x, screenPos.y, Matrix.Identity(), this.scene.activeCamera);\n // let bpotentials = this._oct.intersectsRay(ray);\n // bpotentials.forEach(p => {\n // let potentialScreenPos = toScreen(p.getAbsolutePosition(), this.scene.activeCamera!);\n // let screenProximity = Math.sqrt(Math.pow(screenPos.x - potentialScreenPos.x, 2) + Math.pow(screenPos.y - potentialScreenPos.y, 2));\n // let realProximity = p.getAbsolutePosition().subtract(v).length();\n // console.log({ screenProximity, realProximity });\n // if (screenProximity < this._draggable.connectRadius!) {\n // potentials.push({ mesh: p, proximity: screenProximity });\n // }\n // });\n // potentials.sortBy(p => p.proximity);\n }\n return potentials;\n }\n showDropPreview(c) {\n if (!this._dropPreview) {\n /**\n * for the drop preview, we get the drag node and any other nodes that are connected to it through mates\n * and clone them, put them in a transformNode, and then that transform node becomes the drop preview\n */\n this._dropPreview = new TransformNode('_droppreview', this.viewer.scene);\n this._dropPreview.position = Vector3.Zero();\n this._dropPreview.rotationQuaternion = Quaternion.Identity();\n this._dropPreview.computeWorldMatrix(true);\n const dragMeshTransform = this._dragMesh.computeWorldMatrix(true).getRotationMatrix();\n dragMeshTransform.invert();\n for (const friendMesh of [this._dragMesh, ...this._dragFriendMeshes]) {\n createDragPreview(friendMesh, this._dropPreview, this);\n }\n this._dropPreview.setPreTransformMatrix(dragMeshTransform);\n }\n else {\n //line drop preview back up with the source models as they might have rotated\n if (this._draggable.connectionType != exports.eMateType.fastened) {\n this.connect({\n dragConnector: c.dragConnector,\n otherConnector: c.dragConnector,\n otherConnectorMesh: c.dragConnectorMesh,\n dragConnectorMesh: this._dropPreviewConnectors.get(c.dragConnector), //pass in the drop preview connector mesh\n }, this._dropPreview, exports.eMateType.fastened, true);\n }\n }\n this.connect({\n ...c,\n dragConnectorMesh: this._dropPreviewConnectors.get(c.dragConnector), //pass in the drop preview connector mesh\n }, this._dropPreview);\n this._dropPreview.setEnabled(true);\n //hide the drag node\n this._dragMesh.setEnabled(false);\n for (const friend of this._dragFriendMeshes)\n friend.setEnabled(false);\n function createDragPreview(mesh, parent, self) {\n const clonedMeshGroup = mesh.clone(mesh.id + '_dropPreview', mesh.parent, true);\n if (clonedMeshGroup) {\n clonedMeshGroup.setPivotMatrix(Matrix.Identity());\n // Cloning does not copy the pretransform matrix over so we have to do that manually\n // Otherwise the connector meshes scaling does not get applied to the preview meshes\n clonedMeshGroup.setEnabled(mesh.isEnabled());\n if (c instanceof Mesh && mesh instanceof Mesh) {\n c.setPreTransformMatrix(mesh.getPivotMatrix());\n }\n clonedMeshGroup.setParent(parent); // setting the parent with setParent will make the node stay in the same absolute position.\n const children = mesh.getChildren(child => child instanceof TransformNode, true);\n children.forEach(child => {\n createDragPreview(child, clonedMeshGroup, self);\n });\n clonedMeshGroup.metadata = {}; // babylon metadata refers to same instance of object after cloning so we clear it out\n const kbnode = getByDynamicId(mesh.id);\n if (kbnode && kbnode instanceof exports.Connector) {\n const connector = kbnode;\n self._dropPreviewConnectors.set(connector, clonedMeshGroup);\n clonedMeshGroup.setEnabled(connector._visible); //connector.enabled && !!this._draggable.showConnectors);\n }\n else {\n self.setOpacity(self._draggable.dragOpacity, clonedMeshGroup);\n }\n }\n }\n }\n connect(c, followerMesh, mateType = this._draggable.connectionType, flip = false) {\n this.viewer.pauseRenderWhile(() => {\n mateConnectors({\n mateType: mateType,\n flip: flip,\n offsetX: 0,\n offsetY: 0,\n offsetZ: 0,\n }, followerMesh, c.otherConnectorMesh, c.dragConnectorMesh);\n });\n }\n hideDropPreview() {\n if (this._dropPreview)\n this._dropPreview.setEnabled(false);\n this._dragMesh.setEnabled(true); //show the drag node again\n if (this._dragFriendMeshes) {\n for (const friend of this._dragFriendMeshes) {\n friend.setEnabled(getByDynamicId(friend.id).visible);\n }\n }\n }\n disposeDropPreview() {\n this.hideDropPreview();\n if (this._dropPreview)\n this._dropPreview.dispose();\n if (this._dragFriendMeshes)\n this._dragFriendMeshes.clear();\n if (this._dragFriends)\n this._dragFriends.clear();\n }\n getConnectorLocalPoint(connector) {\n if (connector.positionMode == exports.eConnectorPositionMode.absolute) {\n return connector.position;\n }\n }\n setOpacity(value, ...nodes) {\n if (this.shouldSetOpacity()) {\n for (const node of nodes) {\n for (const m of this.getAllMeshes(node, m => !(m instanceof InstancedMesh))) {\n //set opacity of all non-connector meshes being dragged\n if (!m.metadata) {\n m.metadata = {};\n }\n m.metadata.originalVisibility = m.visibility;\n m.visibility = value;\n }\n }\n }\n }\n resetOpacity(...nodes) {\n for (const node of nodes) {\n for (const m of this.getAllMeshes(node, m => !(m instanceof InstancedMesh))) {\n //set opacity of all non-connector meshes being dragged\n if (m.metadata && m.metadata.originalVisibility !== undefined) {\n m.visibility = m.metadata.originalVisibility;\n delete m.metadata.originalVisibility;\n }\n }\n }\n }\n shouldSetOpacity() {\n return this._draggable.connectionMode != exports.eConnectionMode.none && this._draggable.showConnectors; // && this._dragConnectors.size ;\n }\n /**get's all child meshes and includes the given node if it's a mesh */\n getAllMeshes(node, predicate) {\n const meshes = new Set(node.getChildMeshes(false, predicate));\n if (node instanceof AbstractMesh)\n meshes.add(node);\n return meshes;\n }\n }\n\n /**\n * Class for generating OBJ data from a Babylon scene.\n */\n class OBJExport {\n /**\n * Exports the geometry of a Mesh array in .OBJ file format (text)\n * @param mesh defines the list of meshes to serialize\n * @param materials defines if materials should be exported\n * @param matlibname defines the name of the associated mtl file\n * @param globalposition defines if the exported positions are globals or local to the exported mesh\n * @returns the OBJ content\n */\n static OBJ(mesh, materials, matlibname, globalposition) {\n const output = [];\n let v = 1;\n // keep track of uv index in case mixed meshes are passed in\n let textureV = 1;\n if (materials) {\n if (!matlibname) {\n matlibname = \"mat\";\n }\n output.push(\"mtllib \" + matlibname + \".mtl\");\n }\n for (let j = 0; j < mesh.length; j++) {\n output.push(\"g object\" + j);\n output.push(\"o object_\" + j);\n //Uses the position of the item in the scene, to the file (this back to normal in the end)\n let inverseTransform = null;\n if (globalposition) {\n const transform = mesh[j].computeWorldMatrix(true);\n inverseTransform = new Matrix();\n transform.invertToRef(inverseTransform);\n mesh[j].bakeTransformIntoVertices(transform);\n }\n //TODO: submeshes (groups)\n //TODO: smoothing groups (s 1, s off);\n if (materials) {\n const mat = mesh[j].material;\n if (mat) {\n output.push(\"usemtl \" + mat.id);\n }\n }\n const g = mesh[j].geometry;\n if (!g) {\n Tools.Warn(\"No geometry is present on the mesh\");\n continue;\n }\n const trunkVerts = g.getVerticesData(\"position\");\n const trunkNormals = g.getVerticesData(\"normal\");\n const trunkUV = g.getVerticesData(\"uv\");\n const trunkFaces = g.getIndices();\n let currentV = 0;\n let currentTextureV = 0;\n if (!trunkVerts || !trunkFaces) {\n Tools.Warn(\"There are no position vertices or indices on the mesh!\");\n continue;\n }\n for (let i = 0; i < trunkVerts.length; i += 3) {\n // Babylon.js default is left handed, while OBJ default is right handed\n // Need to invert Z vertices unless Babylon is set to use a right handed system\n if (mesh[0].getScene().useRightHandedSystem) {\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\n }\n else {\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + -trunkVerts[i + 2]);\n }\n currentV++;\n }\n if (trunkNormals != null) {\n for (let i = 0; i < trunkNormals.length; i += 3) {\n output.push(\"vn \" + trunkNormals[i] + \" \" + trunkNormals[i + 1] + \" \" + trunkNormals[i + 2]);\n }\n }\n if (trunkUV != null) {\n for (let i = 0; i < trunkUV.length; i += 2) {\n output.push(\"vt \" + trunkUV[i] + \" \" + trunkUV[i + 1]);\n currentTextureV++;\n }\n }\n for (let i = 0; i < trunkFaces.length; i += 3) {\n const indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];\n const textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];\n const blanks = [\"\", \"\", \"\"];\n const facePositions = indices;\n const faceUVs = trunkUV != null ? textureIndices : blanks;\n const faceNormals = trunkNormals != null ? indices : blanks;\n output.push(\"f \" +\n facePositions[0] +\n \"/\" +\n faceUVs[0] +\n \"/\" +\n faceNormals[0] +\n \" \" +\n facePositions[1] +\n \"/\" +\n faceUVs[1] +\n \"/\" +\n faceNormals[1] +\n \" \" +\n facePositions[2] +\n \"/\" +\n faceUVs[2] +\n \"/\" +\n faceNormals[2]);\n }\n //back de previous matrix, to not change the original mesh in the scene\n if (globalposition && inverseTransform) {\n mesh[j].bakeTransformIntoVertices(inverseTransform);\n }\n v += currentV;\n textureV += currentTextureV;\n }\n const text = output.join(\"\\n\");\n return text;\n }\n /**\n * Exports the material(s) of a mesh in .MTL file format (text)\n * @param mesh defines the mesh to extract the material from\n * @returns the mtl content\n */\n //TODO: Export the materials of mesh array\n static MTL(mesh) {\n const output = [];\n const m = mesh.material;\n output.push(\"newmtl mat1\");\n output.push(\" Ns \" + m.specularPower.toFixed(4));\n output.push(\" Ni 1.5000\");\n output.push(\" d \" + m.alpha.toFixed(4));\n output.push(\" Tr 0.0000\");\n output.push(\" Tf 1.0000 1.0000 1.0000\");\n output.push(\" illum 2\");\n output.push(\" Ka \" + m.ambientColor.r.toFixed(4) + \" \" + m.ambientColor.g.toFixed(4) + \" \" + m.ambientColor.b.toFixed(4));\n output.push(\" Kd \" + m.diffuseColor.r.toFixed(4) + \" \" + m.diffuseColor.g.toFixed(4) + \" \" + m.diffuseColor.b.toFixed(4));\n output.push(\" Ks \" + m.specularColor.r.toFixed(4) + \" \" + m.specularColor.g.toFixed(4) + \" \" + m.specularColor.b.toFixed(4));\n output.push(\" Ke \" + m.emissiveColor.r.toFixed(4) + \" \" + m.emissiveColor.g.toFixed(4) + \" \" + m.emissiveColor.b.toFixed(4));\n //TODO: uv scale, offset, wrap\n //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?\n const uvscale = \"\";\n if (m.ambientTexture) {\n output.push(\" map_Ka \" + uvscale + m.ambientTexture.name);\n }\n if (m.diffuseTexture) {\n output.push(\" map_Kd \" + uvscale + m.diffuseTexture.name);\n //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)\n }\n if (m.specularTexture) {\n output.push(\" map_Ks \" + uvscale + m.specularTexture.name);\n /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)\n if (m.useGlossinessFromSpecularMapAlpha) {\n output.push(\" map_Ns \"+uvscale + m.specularTexture.name);\n }\n */\n }\n /* TODO: emissive texture not in .MAT format (???)\n if (m.emissiveTexture) {\n output.push(\" map_d \"+uvscale+m.emissiveTexture.name);\n }\n */\n if (m.bumpTexture) {\n output.push(\" map_bump -imfchan z \" + uvscale + m.bumpTexture.name);\n }\n if (m.opacityTexture) {\n output.push(\" map_d \" + uvscale + m.opacityTexture.name);\n }\n const text = output.join(\"\\n\");\n return text;\n }\n }\n\n class ObjKb3dExporter {\n constructor(scene, rendererManager) {\n this.scene = scene;\n this.rendererManager = rendererManager;\n }\n /** generates the current scene into a glb file and returns an object url for it */\n generateObj(meshNode) {\n let meshes;\n if (!meshNode) {\n meshes = this.scene.meshes.filter(this.shouldExportMesh);\n }\n else {\n const mesh = this.rendererManager.mesh.get3d(meshNode);\n if (mesh && mesh instanceof Mesh) {\n meshes = [mesh];\n }\n else {\n return null;\n }\n }\n return OBJExport.OBJ(meshes, false, undefined, meshes.length > 1);\n }\n exportObj(filename = 'scene', meshNode) {\n const objData = this.generateObj(meshNode);\n if (objData) {\n const blob = this.createObjBlob(objData);\n const link = document.createElement('a');\n document.body.appendChild(link);\n link.setAttribute('type', 'hidden');\n link.download = `${filename}.obj`;\n link.href = window.URL.createObjectURL(blob);\n link.click();\n setTimeout(() => {\n window.URL.revokeObjectURL(link.href);\n link.remove();\n });\n }\n }\n shouldExportMesh(mesh) {\n return mesh instanceof Mesh && mesh.isVisible && mesh.isEnabled() && !!getByDynamicId(mesh.id);\n }\n createObjBlob(objData) {\n const mimeType = { type: 'text/plain' };\n return new Blob([objData], mimeType);\n }\n }\n\n // Do not edit.\n const name$2D = \"boundingBoxRendererFragmentDeclaration\";\n const shader$2D = `uniform vec4 color;\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2D] = shader$2D;\n\n // Do not edit.\n const name$2E = \"boundingBoxRendererUboDeclaration\";\n const shader$2E = `#ifdef WEBGL2\nuniform vec4 color;uniform mat4 world;uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\n#else\nlayout(std140,column_major) uniform;uniform BoundingBoxRenderer {vec4 color;mat4 world;mat4 viewProjection;mat4 viewProjectionR;};\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2E] = shader$2E;\n\n // Do not edit.\n const name$2F = \"boundingBoxRendererPixelShader\";\n const shader$2F = `#include<__decl__boundingBoxRendererFragment>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2F] = shader$2F;\n\n // Do not edit.\n const name$2G = \"boundingBoxRendererVertexDeclaration\";\n const shader$2G = `uniform mat4 world;uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\n`;\n // Sideeffect\n ShaderStore.IncludesShadersStore[name$2G] = shader$2G;\n\n // Do not edit.\n const name$2H = \"boundingBoxRendererVertexShader\";\n const shader$2H = `attribute vec3 position;\n#include<__decl__boundingBoxRendererVertex>\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec4 worldPos=world*vec4(position,1.0);\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2H] = shader$2H;\n\n Object.defineProperty(Scene.prototype, \"forceShowBoundingBoxes\", {\n get: function () {\n return this._forceShowBoundingBoxes || false;\n },\n set: function (value) {\n this._forceShowBoundingBoxes = value;\n // Lazyly creates a BB renderer if needed.\n if (value) {\n this.getBoundingBoxRenderer();\n }\n },\n enumerable: true,\n configurable: true,\n });\n Scene.prototype.getBoundingBoxRenderer = function () {\n if (!this._boundingBoxRenderer) {\n this._boundingBoxRenderer = new BoundingBoxRenderer(this);\n }\n return this._boundingBoxRenderer;\n };\n Object.defineProperty(AbstractMesh.prototype, \"showBoundingBox\", {\n get: function () {\n return this._showBoundingBox || false;\n },\n set: function (value) {\n this._showBoundingBox = value;\n // Lazyly creates a BB renderer if needed.\n if (value) {\n this.getScene().getBoundingBoxRenderer();\n }\n },\n enumerable: true,\n configurable: true,\n });\n /**\n * Component responsible of rendering the bounding box of the meshes in a scene.\n * This is usually used through the mesh.showBoundingBox or the scene.forceShowBoundingBoxes properties\n */\n class BoundingBoxRenderer {\n /**\n * Instantiates a new bounding box renderer in a scene.\n * @param scene the scene the renderer renders in\n */\n constructor(scene) {\n /**\n * The component name helpful to identify the component in the list of scene components.\n */\n this.name = SceneComponentConstants.NAME_BOUNDINGBOXRENDERER;\n /**\n * Color of the bounding box lines placed in front of an object\n */\n this.frontColor = new Color3(1, 1, 1);\n /**\n * Color of the bounding box lines placed behind an object\n */\n this.backColor = new Color3(0.1, 0.1, 0.1);\n /**\n * Defines if the renderer should show the back lines or not\n */\n this.showBackLines = true;\n /**\n * Observable raised before rendering a bounding box\n */\n this.onBeforeBoxRenderingObservable = new Observable$1();\n /**\n * Observable raised after rendering a bounding box\n */\n this.onAfterBoxRenderingObservable = new Observable$1();\n /**\n * Observable raised after resources are created\n */\n this.onResourcesReadyObservable = new Observable$1();\n /**\n * When false, no bounding boxes will be rendered\n */\n this.enabled = true;\n /**\n * @internal\n */\n this.renderList = new SmartArray(32);\n this._vertexBuffers = {};\n this._fillIndexBuffer = null;\n this._fillIndexData = null;\n this.scene = scene;\n scene._addComponent(this);\n this._uniformBufferFront = new UniformBuffer(this.scene.getEngine(), undefined, undefined, \"BoundingBoxRendererFront\", !this.scene.getEngine().isWebGPU);\n this._buildUniformLayout(this._uniformBufferFront);\n this._uniformBufferBack = new UniformBuffer(this.scene.getEngine(), undefined, undefined, \"BoundingBoxRendererBack\", !this.scene.getEngine().isWebGPU);\n this._buildUniformLayout(this._uniformBufferBack);\n }\n _buildUniformLayout(ubo) {\n ubo.addUniform(\"color\", 4);\n ubo.addUniform(\"world\", 16);\n ubo.addUniform(\"viewProjection\", 16);\n ubo.addUniform(\"viewProjectionR\", 16);\n ubo.create();\n }\n /**\n * Registers the component in a given scene\n */\n register() {\n this.scene._beforeEvaluateActiveMeshStage.registerStep(SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER, this, this.reset);\n this.scene._preActiveMeshStage.registerStep(SceneComponentConstants.STEP_PREACTIVEMESH_BOUNDINGBOXRENDERER, this, this._preActiveMesh);\n this.scene._evaluateSubMeshStage.registerStep(SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER, this, this._evaluateSubMesh);\n this.scene._afterRenderingGroupDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_BOUNDINGBOXRENDERER, this, this.render);\n }\n _evaluateSubMesh(mesh, subMesh) {\n if (mesh.showSubMeshesBoundingBox) {\n const boundingInfo = subMesh.getBoundingInfo();\n if (boundingInfo !== null && boundingInfo !== undefined) {\n boundingInfo.boundingBox._tag = mesh.renderingGroupId;\n this.renderList.push(boundingInfo.boundingBox);\n }\n }\n }\n _preActiveMesh(mesh) {\n if (mesh.showBoundingBox || this.scene.forceShowBoundingBoxes) {\n const boundingInfo = mesh.getBoundingInfo();\n boundingInfo.boundingBox._tag = mesh.renderingGroupId;\n this.renderList.push(boundingInfo.boundingBox);\n }\n }\n _prepareResources() {\n if (this._colorShader) {\n return;\n }\n this._colorShader = new ShaderMaterial(\"colorShader\", this.scene, \"boundingBoxRenderer\", {\n attributes: [VertexBuffer.PositionKind],\n uniforms: [\"world\", \"viewProjection\", \"viewProjectionR\", \"color\"],\n uniformBuffers: [\"BoundingBoxRenderer\"],\n }, false);\n this._colorShader.doNotSerialize = true;\n this._colorShader.reservedDataStore = {\n hidden: true,\n };\n this._colorShaderForOcclusionQuery = new ShaderMaterial(\"colorShaderOccQuery\", this.scene, \"boundingBoxRenderer\", {\n attributes: [VertexBuffer.PositionKind],\n uniforms: [\"world\", \"viewProjection\", \"viewProjectionR\", \"color\"],\n uniformBuffers: [\"BoundingBoxRenderer\"],\n }, true);\n this._colorShaderForOcclusionQuery.doNotSerialize = true;\n this._colorShaderForOcclusionQuery.reservedDataStore = {\n hidden: true,\n };\n const engine = this.scene.getEngine();\n const boxdata = CreateBoxVertexData({ size: 1.0 });\n this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);\n this._createIndexBuffer();\n this._fillIndexData = boxdata.indices;\n this.onResourcesReadyObservable.notifyObservers(this);\n }\n _createIndexBuffer() {\n const engine = this.scene.getEngine();\n this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);\n }\n /**\n * Rebuilds the elements related to this component in case of\n * context lost for instance.\n */\n rebuild() {\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\n if (vb) {\n vb._rebuild();\n }\n this._createIndexBuffer();\n }\n /**\n * @internal\n */\n reset() {\n this.renderList.reset();\n }\n /**\n * Render the bounding boxes of a specific rendering group\n * @param renderingGroupId defines the rendering group to render\n */\n render(renderingGroupId) {\n var _a, _b;\n if (this.renderList.length === 0 || !this.enabled) {\n return;\n }\n this._prepareResources();\n if (!this._colorShader.isReady()) {\n return;\n }\n const engine = this.scene.getEngine();\n engine.setDepthWrite(false);\n const transformMatrix = this.scene.getTransformMatrix();\n for (let boundingBoxIndex = 0; boundingBoxIndex < this.renderList.length; boundingBoxIndex++) {\n const boundingBox = this.renderList.data[boundingBoxIndex];\n if (boundingBox._tag !== renderingGroupId) {\n continue;\n }\n this._createWrappersForBoundingBox(boundingBox);\n this.onBeforeBoxRenderingObservable.notifyObservers(boundingBox);\n const min = boundingBox.minimum;\n const max = boundingBox.maximum;\n const diff = max.subtract(min);\n const median = min.add(diff.scale(0.5));\n const worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z).multiply(Matrix.Translation(median.x, median.y, median.z)).multiply(boundingBox.getWorldMatrix());\n const useReverseDepthBuffer = engine.useReverseDepthBuffer;\n if (this.showBackLines) {\n const drawWrapperBack = (_a = boundingBox._drawWrapperBack) !== null && _a !== void 0 ? _a : this._colorShader._getDrawWrapper();\n this._colorShader._preBind(drawWrapperBack);\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());\n // Back\n if (useReverseDepthBuffer) {\n engine.setDepthFunctionToLessOrEqual();\n }\n else {\n engine.setDepthFunctionToGreaterOrEqual();\n }\n this._uniformBufferBack.bindToEffect(drawWrapperBack.effect, \"BoundingBoxRenderer\");\n this._uniformBufferBack.updateColor4(\"color\", this.backColor, 1);\n this._uniformBufferBack.updateMatrix(\"world\", worldMatrix);\n this._uniformBufferBack.updateMatrix(\"viewProjection\", transformMatrix);\n this._uniformBufferBack.update();\n // Draw order\n engine.drawElementsType(Material.LineListDrawMode, 0, 24);\n }\n const drawWrapperFront = (_b = boundingBox._drawWrapperFront) !== null && _b !== void 0 ? _b : this._colorShader._getDrawWrapper();\n this._colorShader._preBind(drawWrapperFront);\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());\n // Front\n if (useReverseDepthBuffer) {\n engine.setDepthFunctionToGreater();\n }\n else {\n engine.setDepthFunctionToLess();\n }\n this._uniformBufferFront.bindToEffect(drawWrapperFront.effect, \"BoundingBoxRenderer\");\n this._uniformBufferFront.updateColor4(\"color\", this.frontColor, 1);\n this._uniformBufferFront.updateMatrix(\"world\", worldMatrix);\n this._uniformBufferFront.updateMatrix(\"viewProjection\", transformMatrix);\n this._uniformBufferFront.update();\n // Draw order\n engine.drawElementsType(Material.LineListDrawMode, 0, 24);\n this.onAfterBoxRenderingObservable.notifyObservers(boundingBox);\n }\n this._colorShader.unbind();\n engine.setDepthFunctionToLessOrEqual();\n engine.setDepthWrite(true);\n }\n _createWrappersForBoundingBox(boundingBox) {\n if (!boundingBox._drawWrapperFront) {\n const engine = this.scene.getEngine();\n boundingBox._drawWrapperFront = new DrawWrapper(engine);\n boundingBox._drawWrapperBack = new DrawWrapper(engine);\n boundingBox._drawWrapperFront.setEffect(this._colorShader.getEffect());\n boundingBox._drawWrapperBack.setEffect(this._colorShader.getEffect());\n }\n }\n /**\n * In case of occlusion queries, we can render the occlusion bounding box through this method\n * @param mesh Define the mesh to render the occlusion bounding box for\n */\n renderOcclusionBoundingBox(mesh) {\n const engine = this.scene.getEngine();\n if (this._renderPassIdForOcclusionQuery === undefined) {\n this._renderPassIdForOcclusionQuery = engine.createRenderPassId(`Render pass for occlusion query`);\n }\n const currentRenderPassId = engine.currentRenderPassId;\n engine.currentRenderPassId = this._renderPassIdForOcclusionQuery;\n this._prepareResources();\n const subMesh = mesh.subMeshes[0];\n if (!this._colorShaderForOcclusionQuery.isReady(mesh, undefined, subMesh) || !mesh.hasBoundingInfo) {\n engine.currentRenderPassId = currentRenderPassId;\n return;\n }\n if (!this._fillIndexBuffer) {\n this._fillIndexBuffer = engine.createIndexBuffer(this._fillIndexData);\n }\n const useReverseDepthBuffer = engine.useReverseDepthBuffer;\n engine.setDepthWrite(false);\n engine.setColorWrite(false);\n const boundingBox = mesh.getBoundingInfo().boundingBox;\n const min = boundingBox.minimum;\n const max = boundingBox.maximum;\n const diff = max.subtract(min);\n const median = min.add(diff.scale(0.5));\n const worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z).multiply(Matrix.Translation(median.x, median.y, median.z)).multiply(boundingBox.getWorldMatrix());\n const drawWrapper = subMesh._drawWrapper;\n this._colorShaderForOcclusionQuery._preBind(drawWrapper);\n engine.bindBuffers(this._vertexBuffers, this._fillIndexBuffer, drawWrapper.effect);\n if (useReverseDepthBuffer) {\n engine.setDepthFunctionToGreater();\n }\n else {\n engine.setDepthFunctionToLess();\n }\n this.scene.resetCachedMaterial();\n this._uniformBufferFront.bindToEffect(drawWrapper.effect, \"BoundingBoxRenderer\");\n this._uniformBufferFront.updateMatrix(\"world\", worldMatrix);\n this._uniformBufferFront.updateMatrix(\"viewProjection\", this.scene.getTransformMatrix());\n this._uniformBufferFront.update();\n engine.drawElementsType(Material.TriangleFillMode, 0, 36);\n this._colorShaderForOcclusionQuery.unbind();\n engine.setDepthFunctionToLessOrEqual();\n engine.setDepthWrite(true);\n engine.setColorWrite(true);\n engine.currentRenderPassId = currentRenderPassId;\n }\n /**\n * Dispose and release the resources attached to this renderer.\n */\n dispose() {\n if (this._renderPassIdForOcclusionQuery !== undefined) {\n this.scene.getEngine().releaseRenderPassId(this._renderPassIdForOcclusionQuery);\n this._renderPassIdForOcclusionQuery = undefined;\n }\n if (!this._colorShader) {\n return;\n }\n this.onBeforeBoxRenderingObservable.clear();\n this.onAfterBoxRenderingObservable.clear();\n this.onResourcesReadyObservable.clear();\n this.renderList.dispose();\n this._colorShader.dispose();\n this._colorShaderForOcclusionQuery.dispose();\n this._uniformBufferFront.dispose();\n this._uniformBufferBack.dispose();\n const buffer = this._vertexBuffers[VertexBuffer.PositionKind];\n if (buffer) {\n buffer.dispose();\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\n }\n this.scene.getEngine()._releaseBuffer(this._indexBuffer);\n if (this._fillIndexBuffer) {\n this.scene.getEngine()._releaseBuffer(this._fillIndexBuffer);\n this._fillIndexBuffer = null;\n }\n }\n }\n\n /**\n * Class containing a set of static utilities functions for managing Pivots\n * @internal\n */\n class PivotTools {\n /**\n * @internal\n */\n static _RemoveAndStorePivotPoint(mesh) {\n if (mesh && PivotTools._PivotCached === 0) {\n // Save old pivot and set pivot to 0,0,0\n mesh.getPivotPointToRef(PivotTools._OldPivotPoint);\n PivotTools._PivotPostMultiplyPivotMatrix = mesh._postMultiplyPivotMatrix;\n if (!PivotTools._OldPivotPoint.equalsToFloats(0, 0, 0)) {\n mesh.setPivotMatrix(Matrix.IdentityReadOnly);\n PivotTools._OldPivotPoint.subtractToRef(mesh.getPivotPoint(), PivotTools._PivotTranslation);\n PivotTools._PivotTmpVector.copyFromFloats(1, 1, 1);\n PivotTools._PivotTmpVector.subtractInPlace(mesh.scaling);\n PivotTools._PivotTmpVector.multiplyInPlace(PivotTools._PivotTranslation);\n mesh.position.addInPlace(PivotTools._PivotTmpVector);\n }\n }\n PivotTools._PivotCached++;\n }\n /**\n * @internal\n */\n static _RestorePivotPoint(mesh) {\n if (mesh && !PivotTools._OldPivotPoint.equalsToFloats(0, 0, 0) && PivotTools._PivotCached === 1) {\n mesh.setPivotPoint(PivotTools._OldPivotPoint);\n mesh._postMultiplyPivotMatrix = PivotTools._PivotPostMultiplyPivotMatrix;\n PivotTools._PivotTmpVector.copyFromFloats(1, 1, 1);\n PivotTools._PivotTmpVector.subtractInPlace(mesh.scaling);\n PivotTools._PivotTmpVector.multiplyInPlace(PivotTools._PivotTranslation);\n mesh.position.subtractInPlace(PivotTools._PivotTmpVector);\n }\n this._PivotCached--;\n }\n }\n // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)\n // store/remove pivot point should only be applied during their outermost calls\n PivotTools._PivotCached = 0;\n PivotTools._OldPivotPoint = new Vector3();\n PivotTools._PivotTranslation = new Vector3();\n PivotTools._PivotTmpVector = new Vector3();\n PivotTools._PivotPostMultiplyPivotMatrix = false;\n\n /**\n * A behavior that when attached to a mesh will allow the mesh to be dragged around the screen based on pointer events\n */\n class PointerDragBehavior {\n /**\n * Get or set the currentDraggingPointerId\n * @deprecated Please use currentDraggingPointerId instead\n */\n get currentDraggingPointerID() {\n return this.currentDraggingPointerId;\n }\n set currentDraggingPointerID(currentDraggingPointerID) {\n this.currentDraggingPointerId = currentDraggingPointerID;\n }\n /**\n * If the drag behavior will react to drag events (Default: true)\n */\n set enabled(value) {\n if (value != this._enabled) {\n this.onEnabledObservable.notifyObservers(value);\n }\n this._enabled = value;\n }\n get enabled() {\n return this._enabled;\n }\n /**\n * Gets the options used by the behavior\n */\n get options() {\n return this._options;\n }\n /**\n * Sets the options used by the behavior\n */\n set options(options) {\n this._options = options;\n }\n /**\n * Creates a pointer drag behavior that can be attached to a mesh\n * @param options The drag axis or normal of the plane that will be dragged across. If no options are specified the drag plane will always face the ray's origin (eg. camera)\n * @param options.dragAxis\n * @param options.dragPlaneNormal\n */\n constructor(options) {\n this._useAlternatePickedPointAboveMaxDragAngleDragSpeed = -1.1;\n this._activeDragButton = -1;\n /**\n * The maximum tolerated angle between the drag plane and dragging pointer rays to trigger pointer events. Set to 0 to allow any angle (default: 0)\n */\n this.maxDragAngle = 0;\n /**\n * Butttons that can be used to initiate a drag\n */\n this.dragButtons = [0, 1, 2];\n /**\n * @internal\n */\n this._useAlternatePickedPointAboveMaxDragAngle = false;\n /**\n * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)\n */\n this.currentDraggingPointerId = -1;\n /**\n * If the behavior is currently in a dragging state\n */\n this.dragging = false;\n /**\n * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)\n */\n this.dragDeltaRatio = 0.2;\n /**\n * If the drag plane orientation should be updated during the dragging (Default: true)\n */\n this.updateDragPlane = true;\n // Debug mode will display drag planes to help visualize behavior\n this._debugMode = false;\n this._moving = false;\n /**\n * Fires each time the attached mesh is dragged with the pointer\n * * delta between last drag position and current drag position in world space\n * * dragDistance along the drag axis\n * * dragPlaneNormal normal of the current drag plane used during the drag\n * * dragPlanePoint in world space where the drag intersects the drag plane\n *\n * (if validatedDrag is used, the position of the attached mesh might not equal dragPlanePoint)\n */\n this.onDragObservable = new Observable$1();\n /**\n * Fires each time a drag begins (eg. mouse down on mesh)\n * * dragPlanePoint in world space where the drag intersects the drag plane\n *\n * (if validatedDrag is used, the position of the attached mesh might not equal dragPlanePoint)\n */\n this.onDragStartObservable = new Observable$1();\n /**\n * Fires each time a drag ends (eg. mouse release after drag)\n * * dragPlanePoint in world space where the drag intersects the drag plane\n *\n * (if validatedDrag is used, the position of the attached mesh might not equal dragPlanePoint)\n */\n this.onDragEndObservable = new Observable$1();\n /**\n * Fires each time behavior enabled state changes\n */\n this.onEnabledObservable = new Observable$1();\n /**\n * If the attached mesh should be moved when dragged\n */\n this.moveAttached = true;\n this._enabled = true;\n /**\n * If pointer events should start and release the drag (Default: true)\n */\n this.startAndReleaseDragOnPointerEvents = true;\n /**\n * If camera controls should be detached during the drag\n */\n this.detachCameraControls = true;\n /**\n * If set, the drag plane/axis will be rotated based on the attached mesh's world rotation (Default: true)\n */\n this.useObjectOrientationForDragging = true;\n /**\n * Predicate to determine if it is valid to move the object to a new position when it is moved\n * @param targetPosition\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this.validateDrag = (targetPosition) => {\n return true;\n };\n this._tmpVector = new Vector3(0, 0, 0);\n this._alternatePickedPoint = new Vector3(0, 0, 0);\n this._worldDragAxis = new Vector3(0, 0, 0);\n this._targetPosition = new Vector3(0, 0, 0);\n this._attachedToElement = false;\n this._startDragRay = new Ray(new Vector3(), new Vector3());\n this._lastPointerRay = {};\n this._dragDelta = new Vector3();\n // Variables to avoid instantiation in the below method\n this._pointA = new Vector3(0, 0, 0);\n this._pointC = new Vector3(0, 0, 0);\n this._localAxis = new Vector3(0, 0, 0);\n this._lookAt = new Vector3(0, 0, 0);\n this._options = options ? options : {};\n let optionCount = 0;\n if (this._options.dragAxis) {\n optionCount++;\n }\n if (this._options.dragPlaneNormal) {\n optionCount++;\n }\n if (optionCount > 1) {\n throw \"Multiple drag modes specified in dragBehavior options. Only one expected\";\n }\n }\n /**\n * The name of the behavior\n */\n get name() {\n return \"PointerDrag\";\n }\n /**\n * Initializes the behavior\n */\n init() { }\n /**\n * Attaches the drag behavior the passed in mesh\n * @param ownerNode The mesh that will be dragged around once attached\n * @param predicate Predicate to use for pick filtering\n */\n attach(ownerNode, predicate) {\n this._scene = ownerNode.getScene();\n ownerNode.isNearGrabbable = true;\n this.attachedNode = ownerNode;\n // Initialize drag plane to not interfere with existing scene\n if (!PointerDragBehavior._PlaneScene) {\n if (this._debugMode) {\n PointerDragBehavior._PlaneScene = this._scene;\n }\n else {\n PointerDragBehavior._PlaneScene = new Scene(this._scene.getEngine(), { virtual: true });\n PointerDragBehavior._PlaneScene.detachControl();\n this._scene.onDisposeObservable.addOnce(() => {\n PointerDragBehavior._PlaneScene.dispose();\n PointerDragBehavior._PlaneScene = null;\n });\n }\n }\n this._dragPlane = CreatePlane(\"pointerDragPlane\", { size: this._debugMode ? 1 : 10000, updatable: false, sideOrientation: Mesh.DOUBLESIDE }, PointerDragBehavior._PlaneScene);\n // State of the drag\n this.lastDragPosition = new Vector3(0, 0, 0);\n const pickPredicate = predicate\n ? predicate\n : (m) => {\n return this.attachedNode == m || m.isDescendantOf(this.attachedNode);\n };\n this._pointerObserver = this._scene.onPointerObservable.add((pointerInfo) => {\n if (!this.enabled) {\n // If behavior is disabled before releaseDrag is ever called, call it now.\n if (this._attachedToElement) {\n this.releaseDrag();\n }\n return;\n }\n if (pointerInfo.type == PointerEventTypes.POINTERDOWN) {\n if (this.startAndReleaseDragOnPointerEvents &&\n !this.dragging &&\n pointerInfo.pickInfo &&\n pointerInfo.pickInfo.hit &&\n pointerInfo.pickInfo.pickedMesh &&\n pointerInfo.pickInfo.pickedPoint &&\n pointerInfo.pickInfo.ray &&\n pickPredicate(pointerInfo.pickInfo.pickedMesh)) {\n if (this._activeDragButton === -1 && this.dragButtons.indexOf(pointerInfo.event.button) !== -1) {\n this._activeDragButton = pointerInfo.event.button;\n this._activePointerInfo = pointerInfo;\n this._startDrag(pointerInfo.event.pointerId, pointerInfo.pickInfo.ray, pointerInfo.pickInfo.pickedPoint);\n }\n }\n }\n else if (pointerInfo.type == PointerEventTypes.POINTERUP) {\n if (this.startAndReleaseDragOnPointerEvents &&\n this.currentDraggingPointerId == pointerInfo.event.pointerId &&\n (this._activeDragButton === pointerInfo.event.button || this._activeDragButton === -1)) {\n this.releaseDrag();\n }\n }\n else if (pointerInfo.type == PointerEventTypes.POINTERMOVE) {\n const pointerId = pointerInfo.event.pointerId;\n // If drag was started with anyMouseID specified, set pointerID to the next mouse that moved\n if (this.currentDraggingPointerId === PointerDragBehavior._AnyMouseId && pointerId !== PointerDragBehavior._AnyMouseId) {\n const evt = pointerInfo.event;\n const isMouseEvent = evt.pointerType === \"mouse\" || (!this._scene.getEngine().hostInformation.isMobile && evt instanceof MouseEvent);\n if (isMouseEvent) {\n if (this._lastPointerRay[this.currentDraggingPointerId]) {\n this._lastPointerRay[pointerId] = this._lastPointerRay[this.currentDraggingPointerId];\n delete this._lastPointerRay[this.currentDraggingPointerId];\n }\n this.currentDraggingPointerId = pointerId;\n }\n }\n // Keep track of last pointer ray, this is used simulating the start of a drag in startDrag()\n if (!this._lastPointerRay[pointerId]) {\n this._lastPointerRay[pointerId] = new Ray(new Vector3(), new Vector3());\n }\n if (pointerInfo.pickInfo && pointerInfo.pickInfo.ray) {\n this._lastPointerRay[pointerId].origin.copyFrom(pointerInfo.pickInfo.ray.origin);\n this._lastPointerRay[pointerId].direction.copyFrom(pointerInfo.pickInfo.ray.direction);\n if (this.currentDraggingPointerId == pointerId && this.dragging) {\n this._moveDrag(pointerInfo.pickInfo.ray);\n }\n }\n }\n });\n this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(() => {\n if (this._moving && this.moveAttached) {\n let needMatrixUpdate = false;\n PivotTools._RemoveAndStorePivotPoint(this.attachedNode);\n // Slowly move mesh to avoid jitter\n this._targetPosition.subtractToRef(this.attachedNode.absolutePosition, this._tmpVector);\n this._tmpVector.scaleInPlace(this.dragDeltaRatio);\n this.attachedNode.getAbsolutePosition().addToRef(this._tmpVector, this._tmpVector);\n if (this.validateDrag(this._tmpVector)) {\n this.attachedNode.setAbsolutePosition(this._tmpVector);\n needMatrixUpdate = true;\n }\n PivotTools._RestorePivotPoint(this.attachedNode);\n if (needMatrixUpdate) {\n this.attachedNode.computeWorldMatrix();\n }\n }\n });\n }\n /**\n * Force release the drag action by code.\n */\n releaseDrag() {\n if (this.dragging) {\n this.dragging = false;\n this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerId, pointerInfo: this._activePointerInfo });\n }\n this.currentDraggingPointerId = -1;\n this._activeDragButton = -1;\n this._activePointerInfo = null;\n this._moving = false;\n // Reattach camera controls\n if (this.detachCameraControls && this._attachedToElement && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {\n if (this._scene.activeCamera.getClassName() === \"ArcRotateCamera\") {\n const arcRotateCamera = this._scene.activeCamera;\n arcRotateCamera.attachControl(arcRotateCamera.inputs ? arcRotateCamera.inputs.noPreventDefault : true, arcRotateCamera._useCtrlForPanning, arcRotateCamera._panningMouseButton);\n }\n else {\n this._scene.activeCamera.attachControl(this._scene.activeCamera.inputs ? this._scene.activeCamera.inputs.noPreventDefault : true);\n }\n this._attachedToElement = false;\n }\n }\n /**\n * Simulates the start of a pointer drag event on the behavior\n * @param pointerId pointerID of the pointer that should be simulated (Default: Any mouse pointer ID)\n * @param fromRay initial ray of the pointer to be simulated (Default: Ray from camera to attached mesh)\n * @param startPickedPoint picked point of the pointer to be simulated (Default: attached mesh position)\n */\n startDrag(pointerId = PointerDragBehavior._AnyMouseId, fromRay, startPickedPoint) {\n this._startDrag(pointerId, fromRay, startPickedPoint);\n let lastRay = this._lastPointerRay[pointerId];\n if (pointerId === PointerDragBehavior._AnyMouseId) {\n lastRay = this._lastPointerRay[Object.keys(this._lastPointerRay)[0]];\n }\n if (lastRay) {\n // if there was a last pointer ray drag the object there\n this._moveDrag(lastRay);\n }\n }\n _startDrag(pointerId, fromRay, startPickedPoint) {\n if (!this._scene.activeCamera || this.dragging || !this.attachedNode) {\n return;\n }\n PivotTools._RemoveAndStorePivotPoint(this.attachedNode);\n // Create start ray from the camera to the object\n if (fromRay) {\n this._startDragRay.direction.copyFrom(fromRay.direction);\n this._startDragRay.origin.copyFrom(fromRay.origin);\n }\n else {\n this._startDragRay.origin.copyFrom(this._scene.activeCamera.position);\n this.attachedNode.getWorldMatrix().getTranslationToRef(this._tmpVector);\n this._tmpVector.subtractToRef(this._scene.activeCamera.position, this._startDragRay.direction);\n }\n this._updateDragPlanePosition(this._startDragRay, startPickedPoint ? startPickedPoint : this._tmpVector);\n const pickedPoint = this._pickWithRayOnDragPlane(this._startDragRay);\n if (pickedPoint) {\n this.dragging = true;\n this.currentDraggingPointerId = pointerId;\n this.lastDragPosition.copyFrom(pickedPoint);\n this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerId, pointerInfo: this._activePointerInfo });\n this._targetPosition.copyFrom(this.attachedNode.getAbsolutePosition());\n // Detatch camera controls\n if (this.detachCameraControls && this._scene.activeCamera && this._scene.activeCamera.inputs && !this._scene.activeCamera.leftCamera) {\n if (this._scene.activeCamera.inputs.attachedToElement) {\n this._scene.activeCamera.detachControl();\n this._attachedToElement = true;\n }\n else {\n this._attachedToElement = false;\n }\n }\n }\n else {\n this.releaseDrag();\n }\n PivotTools._RestorePivotPoint(this.attachedNode);\n }\n _moveDrag(ray) {\n this._moving = true;\n const pickedPoint = this._pickWithRayOnDragPlane(ray);\n if (pickedPoint) {\n PivotTools._RemoveAndStorePivotPoint(this.attachedNode);\n if (this.updateDragPlane) {\n this._updateDragPlanePosition(ray, pickedPoint);\n }\n let dragLength = 0;\n // depending on the drag mode option drag accordingly\n if (this._options.dragAxis) {\n // Convert local drag axis to world if useObjectOrientationForDragging\n this.useObjectOrientationForDragging\n ? Vector3.TransformCoordinatesToRef(this._options.dragAxis, this.attachedNode.getWorldMatrix().getRotationMatrix(), this._worldDragAxis)\n : this._worldDragAxis.copyFrom(this._options.dragAxis);\n // Project delta drag from the drag plane onto the drag axis\n pickedPoint.subtractToRef(this.lastDragPosition, this._tmpVector);\n dragLength = Vector3.Dot(this._tmpVector, this._worldDragAxis);\n this._worldDragAxis.scaleToRef(dragLength, this._dragDelta);\n }\n else {\n dragLength = this._dragDelta.length();\n pickedPoint.subtractToRef(this.lastDragPosition, this._dragDelta);\n }\n this._targetPosition.addInPlace(this._dragDelta);\n this.onDragObservable.notifyObservers({\n dragDistance: dragLength,\n delta: this._dragDelta,\n dragPlanePoint: pickedPoint,\n dragPlaneNormal: this._dragPlane.forward,\n pointerId: this.currentDraggingPointerId,\n pointerInfo: this._activePointerInfo,\n });\n this.lastDragPosition.copyFrom(pickedPoint);\n PivotTools._RestorePivotPoint(this.attachedNode);\n }\n }\n _pickWithRayOnDragPlane(ray) {\n if (!ray) {\n return null;\n }\n // Calculate angle between plane normal and ray\n let angle = Math.acos(Vector3.Dot(this._dragPlane.forward, ray.direction));\n // Correct if ray is casted from oposite side\n if (angle > Math.PI / 2) {\n angle = Math.PI - angle;\n }\n // If the angle is too perpendicular to the plane pick another point on the plane where it is looking\n if (this.maxDragAngle > 0 && angle > this.maxDragAngle) {\n if (this._useAlternatePickedPointAboveMaxDragAngle) {\n // Invert ray direction along the towards object axis\n this._tmpVector.copyFrom(ray.direction);\n this.attachedNode.absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);\n this._alternatePickedPoint.normalize();\n this._alternatePickedPoint.scaleInPlace(this._useAlternatePickedPointAboveMaxDragAngleDragSpeed * Vector3.Dot(this._alternatePickedPoint, this._tmpVector));\n this._tmpVector.addInPlace(this._alternatePickedPoint);\n // Project resulting vector onto the drag plane and add it to the attached nodes absolute position to get a picked point\n const dot = Vector3.Dot(this._dragPlane.forward, this._tmpVector);\n this._dragPlane.forward.scaleToRef(-dot, this._alternatePickedPoint);\n this._alternatePickedPoint.addInPlace(this._tmpVector);\n this._alternatePickedPoint.addInPlace(this.attachedNode.absolutePosition);\n return this._alternatePickedPoint;\n }\n else {\n return null;\n }\n }\n const pickResult = PointerDragBehavior._PlaneScene.pickWithRay(ray, (m) => {\n return m == this._dragPlane;\n });\n if (pickResult && pickResult.hit && pickResult.pickedMesh && pickResult.pickedPoint) {\n return pickResult.pickedPoint;\n }\n else {\n return null;\n }\n }\n // Position the drag plane based on the attached mesh position, for single axis rotate the plane along the axis to face the camera\n _updateDragPlanePosition(ray, dragPlanePosition) {\n this._pointA.copyFrom(dragPlanePosition);\n if (this._options.dragAxis) {\n this.useObjectOrientationForDragging\n ? Vector3.TransformCoordinatesToRef(this._options.dragAxis, this.attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis)\n : this._localAxis.copyFrom(this._options.dragAxis);\n // Calculate plane normal that is the cross product of local axis and (eye-dragPlanePosition)\n ray.origin.subtractToRef(this._pointA, this._pointC);\n this._pointC.normalize();\n if (Math.abs(Vector3.Dot(this._localAxis, this._pointC)) > 0.999) {\n // the drag axis is colinear with the (eye to position) ray. The cross product will give jittered values.\n // A new axis vector need to be computed\n if (Math.abs(Vector3.Dot(Vector3.UpReadOnly, this._pointC)) > 0.999) {\n this._lookAt.copyFrom(Vector3.Right());\n }\n else {\n this._lookAt.copyFrom(Vector3.UpReadOnly);\n }\n }\n else {\n Vector3.CrossToRef(this._localAxis, this._pointC, this._lookAt);\n // Get perpendicular line from previous result and drag axis to adjust lineB to be perpendicular to camera\n Vector3.CrossToRef(this._localAxis, this._lookAt, this._lookAt);\n this._lookAt.normalize();\n }\n this._dragPlane.position.copyFrom(this._pointA);\n this._pointA.addToRef(this._lookAt, this._lookAt);\n this._dragPlane.lookAt(this._lookAt);\n }\n else if (this._options.dragPlaneNormal) {\n this.useObjectOrientationForDragging\n ? Vector3.TransformCoordinatesToRef(this._options.dragPlaneNormal, this.attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis)\n : this._localAxis.copyFrom(this._options.dragPlaneNormal);\n this._dragPlane.position.copyFrom(this._pointA);\n this._pointA.addToRef(this._localAxis, this._lookAt);\n this._dragPlane.lookAt(this._lookAt);\n }\n else {\n this._dragPlane.position.copyFrom(this._pointA);\n this._dragPlane.lookAt(ray.origin);\n }\n // Update the position of the drag plane so it doesn't get out of sync with the node (eg. when moving back and forth quickly)\n this._dragPlane.position.copyFrom(this.attachedNode.getAbsolutePosition());\n this._dragPlane.computeWorldMatrix(true);\n }\n /**\n * Detaches the behavior from the mesh\n */\n detach() {\n this._lastPointerRay = {};\n if (this.attachedNode) {\n this.attachedNode.isNearGrabbable = false;\n }\n if (this._pointerObserver) {\n this._scene.onPointerObservable.remove(this._pointerObserver);\n }\n if (this._beforeRenderObserver) {\n this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);\n }\n if (this._dragPlane) {\n this._dragPlane.dispose();\n }\n this.releaseDrag();\n }\n }\n PointerDragBehavior._AnyMouseId = -2;\n\n /**\n * Single plane rotation gizmo\n */\n class KbAxisMorphGizmo {\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n set scaleRatio(value) {\n this._scaleRatio = value;\n }\n get scaleRatio() {\n return this._scaleRatio;\n }\n set gizmoPosition(value) {\n this._rootMesh.position = value;\n }\n get gizmoPosition() {\n return this._rootMesh.position;\n }\n /**\n * Creates a PlaneRotationGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param color The color of the gizmo\n * @param tessellation Amount of tessellation to be used when creating rotation circles\n */\n constructor(color = Color3.Gray(), gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, tessellation = 24) {\n this.gizmoLayer = gizmoLayer;\n this.dragActive = false;\n this.direction = new Vector3();\n this._pointerObserver = null;\n this._tempVector = new Vector3();\n this._updateQuat = new Quaternion();\n this._scaleRatio = 1;\n /**\n * Rotation distance in radians that the gizmo will snap to (Default: 0)\n */\n this.snapDistance = 0;\n /**\n * Event that fires each time the gizmo snaps to a new location.\n * * snapDistance is the the change in distance\n */\n this.updateObservable = new Observable$1();\n this._rootMesh = new Mesh('gizmoRootNode', gizmoLayer.utilityLayerScene);\n // Create Material\n const coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n coloredMaterial.emissiveColor = color;\n const wireframeMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n wireframeMaterial.emissiveColor = color;\n wireframeMaterial.alpha = 0.4;\n // coloredMaterial.diffuseColor = color;\n // coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\n wireframeMaterial.alpha = 0.6;\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\n // Build mesh to hold axis line\n this.axisMesh = new AbstractMesh('', gizmoLayer.utilityLayerScene);\n this.axisMesh.rotationQuaternion = Quaternion.Identity();\n const line = CylinderBuilder.CreateCylinder('', { diameterTop: 0.01, height: 0.3, diameterBottom: 0.01, tessellation }, gizmoLayer.utilityLayerScene);\n line.material = coloredMaterial;\n line.position.y = 0.375;\n const line2 = CylinderBuilder.CreateCylinder('', { diameterTop: 0.005, height: 0.9, diameterBottom: 0.005, tessellation }, gizmoLayer.utilityLayerScene);\n line2.material = coloredMaterial;\n line2.position.y = -0.225;\n const sphereMesh = SphereBuilder.CreateSphere('', { segments: tessellation, diameter: 0.45 }, gizmoLayer.utilityLayerScene);\n sphereMesh.material = wireframeMaterial;\n this.axisMesh.isPickable = false;\n this.axisMesh.addChild(line);\n this.axisMesh.addChild(line2);\n sphereMesh.addChild(this.axisMesh);\n sphereMesh.scaling.scaleInPlace(1 / 3);\n this._rootMesh.addChild(sphereMesh);\n let lastDragPosition = null;\n // Add drag behavior to handle events when the gizmo is dragged\n this.dragBehavior = new PointerDragBehavior();\n this.dragBehavior.moveAttached = false;\n this.dragBehavior.onDragStartObservable.add(() => {\n this.dragActive = true;\n });\n this.dragBehavior.onDragObservable.add(event => {\n // activeCamera.getForwardRayToRef(forwardRay, 1);\n // const cameraDirection = forwardRay.direction;\n // cameraDirection.rotateByQuaternionToRef(parentMesh.rotationQuaternion!, cameraDirection);\n // cameraDirection.addToRef(event.delta, targetDirection);\n // rotationToVectorToRef(targetDirection, cameraDirection, this._updateQuat);\n // parentMesh.rotationQuaternion!.multiplyInPlace(this._updateQuat);\n // this.updateObservable.notifyObservers({ delta: this._updateQuat });\n });\n this.dragBehavior.onDragEndObservable.add(() => {\n this.dragActive = false;\n });\n this._rootMesh.addBehavior(this.dragBehavior);\n this.dragBehavior.enabled = true;\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\n const isHovered = pointerInfo.pickInfo &&\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\n sphereMesh.material = isHovered ? hoverMaterial : wireframeMaterial;\n if (pointerInfo.pickInfo && isHovered) {\n const point = pointerInfo.pickInfo.pickedPoint;\n if (point) {\n point.subtractInPlace(this._rootMesh.position);\n switch (pointerInfo.type) {\n case PointerEventTypes.POINTERDOWN:\n lastDragPosition = point.clone();\n break;\n case PointerEventTypes.POINTERMOVE:\n if (lastDragPosition && this.dragActive) {\n rotationToVectorToRef(point, lastDragPosition, this._updateQuat);\n lastDragPosition.copyFrom(point);\n // console.log(point, this._updateQuat);\n this.direction.rotateByQuaternionToRef(this._updateQuat, this.direction);\n this.updateObservable.notifyObservers({ delta: this._updateQuat });\n }\n break;\n }\n }\n }\n });\n // let light = gizmoLayer._getSharedGizmoLight();\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));\n this._beforeRenderObserver = this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.add(() => {\n this._update();\n });\n }\n _update() {\n var _a;\n if (this.direction) {\n this.axisMesh.rotationQuaternion = rotationToVector(this.direction);\n }\n const activeCamera = this.gizmoLayer.utilityLayerScene.activeCamera;\n let cameraPosition = activeCamera.globalPosition;\n if (activeCamera.devicePosition) {\n cameraPosition = activeCamera.devicePosition;\n }\n this._rootMesh.position.subtractToRef(cameraPosition, this._tempVector);\n const dist = this._tempVector.length() * this.scaleRatio;\n this._rootMesh.scaling.set(dist, dist, dist);\n // Account for handedness, similar to Matrix.decompose\n if (((_a = this.gizmoLayer.originalScene.meshes[0]) === null || _a === void 0 ? void 0 : _a._getWorldMatrixDeterminant()) < 0) {\n this._rootMesh.scaling.y *= -1;\n }\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\n this._rootMesh.dispose();\n this.dragBehavior.detach();\n if (this._beforeRenderObserver) {\n this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.remove(this._beforeRenderObserver);\n }\n }\n }\n\n /**\n * Anchor options where the Gizmo can be positioned in relation to its anchored node\n */\n var GizmoAnchorPoint;\n (function (GizmoAnchorPoint) {\n /** The origin of the attached node */\n GizmoAnchorPoint[GizmoAnchorPoint[\"Origin\"] = 0] = \"Origin\";\n /** The pivot point of the attached node*/\n GizmoAnchorPoint[GizmoAnchorPoint[\"Pivot\"] = 1] = \"Pivot\";\n })(GizmoAnchorPoint || (GizmoAnchorPoint = {}));\n /**\n * Coordinates mode: Local or World. Defines how axis is aligned: either on world axis or transform local axis\n */\n var GizmoCoordinatesMode;\n (function (GizmoCoordinatesMode) {\n GizmoCoordinatesMode[GizmoCoordinatesMode[\"World\"] = 0] = \"World\";\n GizmoCoordinatesMode[GizmoCoordinatesMode[\"Local\"] = 1] = \"Local\";\n })(GizmoCoordinatesMode || (GizmoCoordinatesMode = {}));\n /**\n * Renders gizmos on top of an existing scene which provide controls for position, rotation, etc.\n */\n class Gizmo {\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n set scaleRatio(value) {\n this._scaleRatio = value;\n }\n get scaleRatio() {\n return this._scaleRatio;\n }\n /**\n * True when the mouse pointer is hovered a gizmo mesh\n */\n get isHovered() {\n return this._isHovered;\n }\n /**\n * Mesh that the gizmo will be attached to. (eg. on a drag gizmo the mesh that will be dragged)\n * * When set, interactions will be enabled\n */\n get attachedMesh() {\n return this._attachedMesh;\n }\n set attachedMesh(value) {\n this._attachedMesh = value;\n if (value) {\n this._attachedNode = value;\n }\n this._rootMesh.setEnabled(value ? true : false);\n this._attachedNodeChanged(value);\n }\n /**\n * Node that the gizmo will be attached to. (eg. on a drag gizmo the mesh, bone or NodeTransform that will be dragged)\n * * When set, interactions will be enabled\n */\n get attachedNode() {\n return this._attachedNode;\n }\n set attachedNode(value) {\n this._attachedNode = value;\n this._attachedMesh = null;\n this._rootMesh.setEnabled(value ? true : false);\n this._attachedNodeChanged(value);\n }\n /**\n * Disposes and replaces the current meshes in the gizmo with the specified mesh\n * @param mesh The mesh to replace the default mesh of the gizmo\n */\n setCustomMesh(mesh) {\n if (mesh.getScene() != this.gizmoLayer.utilityLayerScene) {\n throw \"When setting a custom mesh on a gizmo, the custom meshes scene must be the same as the gizmos (eg. gizmo.gizmoLayer.utilityLayerScene)\";\n }\n this._rootMesh.getChildMeshes().forEach((c) => {\n c.dispose();\n });\n mesh.parent = this._rootMesh;\n this._customMeshSet = true;\n }\n /**\n * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)\n * NOTE: This is only possible for meshes with uniform scaling, as otherwise it's not possible to decompose the rotation\n */\n set updateGizmoRotationToMatchAttachedMesh(value) {\n this._updateGizmoRotationToMatchAttachedMesh = value;\n }\n get updateGizmoRotationToMatchAttachedMesh() {\n return this._updateGizmoRotationToMatchAttachedMesh;\n }\n /**\n * If set the gizmo's position will be updated to match the attached mesh each frame (Default: true)\n */\n set updateGizmoPositionToMatchAttachedMesh(value) {\n this._updateGizmoPositionToMatchAttachedMesh = value;\n }\n get updateGizmoPositionToMatchAttachedMesh() {\n return this._updateGizmoPositionToMatchAttachedMesh;\n }\n /**\n * Defines where the gizmo will be positioned if `updateGizmoPositionToMatchAttachedMesh` is enabled.\n * (Default: GizmoAnchorPoint.Origin)\n */\n set anchorPoint(value) {\n this._anchorPoint = value;\n }\n get anchorPoint() {\n return this._anchorPoint;\n }\n /**\n * Set the coordinate system to use. By default it's local.\n * But it's possible for a user to tweak so its local for translation and world for rotation.\n * In that case, setting the coordinate system will change `updateGizmoRotationToMatchAttachedMesh` and `updateGizmoPositionToMatchAttachedMesh`\n */\n set coordinatesMode(coordinatesMode) {\n this._coordinatesMode = coordinatesMode;\n const local = coordinatesMode == GizmoCoordinatesMode.Local;\n this.updateGizmoRotationToMatchAttachedMesh = local;\n this.updateGizmoPositionToMatchAttachedMesh = local;\n }\n get coordinatesMode() {\n return this._coordinatesMode;\n }\n /**\n * When set, the gizmo will always appear the same size no matter where the camera is (default: true)\n */\n set updateScale(value) {\n this._updateScale = value;\n }\n get updateScale() {\n return this._updateScale;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _attachedNodeChanged(value) { }\n /**\n * Creates a gizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n */\n constructor(\n /** The utility layer the gizmo will be added to */\n gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer) {\n this.gizmoLayer = gizmoLayer;\n this._attachedMesh = null;\n this._attachedNode = null;\n this._customRotationQuaternion = null;\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n this._scaleRatio = 1;\n /**\n * boolean updated by pointermove when a gizmo mesh is hovered\n */\n this._isHovered = false;\n /**\n * If a custom mesh has been set (Default: false)\n */\n this._customMeshSet = false;\n this._updateGizmoRotationToMatchAttachedMesh = true;\n this._updateGizmoPositionToMatchAttachedMesh = true;\n this._anchorPoint = GizmoAnchorPoint.Origin;\n this._updateScale = true;\n this._coordinatesMode = GizmoCoordinatesMode.Local;\n this._interactionsEnabled = true;\n this._rightHandtoLeftHandMatrix = Matrix.RotationY(Math.PI);\n this._rootMesh = new Mesh(\"gizmoRootNode\", gizmoLayer.utilityLayerScene);\n this._rootMesh.rotationQuaternion = Quaternion.Identity();\n this._beforeRenderObserver = this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.add(() => {\n this._update();\n });\n }\n /**\n * posture that the gizmo will be display\n * When set null, default value will be used (Quaternion(0, 0, 0, 1))\n */\n get customRotationQuaternion() {\n return this._customRotationQuaternion;\n }\n set customRotationQuaternion(customRotationQuaternion) {\n this._customRotationQuaternion = customRotationQuaternion;\n }\n /**\n * Updates the gizmo to match the attached mesh's position/rotation\n */\n _update() {\n if (this.attachedNode) {\n let effectiveNode = this.attachedNode;\n if (this.attachedMesh) {\n effectiveNode = this.attachedMesh || this.attachedNode;\n }\n // Position\n if (this.updateGizmoPositionToMatchAttachedMesh) {\n if (this.anchorPoint == GizmoAnchorPoint.Pivot && effectiveNode.getAbsolutePivotPoint) {\n const position = effectiveNode.getAbsolutePivotPoint();\n this._rootMesh.position.copyFrom(position);\n }\n else {\n const row = effectiveNode.getWorldMatrix().getRow(3);\n const position = row ? row.toVector3() : new Vector3(0, 0, 0);\n this._rootMesh.position.copyFrom(position);\n }\n }\n // Rotation\n if (this.updateGizmoRotationToMatchAttachedMesh) {\n const supportedNode = effectiveNode._isMesh ||\n effectiveNode.getClassName() === \"AbstractMesh\" ||\n effectiveNode.getClassName() === \"TransformNode\" ||\n effectiveNode.getClassName() === \"InstancedMesh\";\n const transformNode = supportedNode ? effectiveNode : undefined;\n effectiveNode.getWorldMatrix().decompose(undefined, this._rootMesh.rotationQuaternion, undefined, Gizmo.PreserveScaling ? transformNode : undefined);\n }\n else {\n if (this._customRotationQuaternion) {\n this._rootMesh.rotationQuaternion.copyFrom(this._customRotationQuaternion);\n }\n else {\n this._rootMesh.rotationQuaternion.set(0, 0, 0, 1);\n }\n }\n // Scale\n if (this.updateScale) {\n const activeCamera = this.gizmoLayer.utilityLayerScene.activeCamera;\n let cameraPosition = activeCamera.globalPosition;\n if (activeCamera.devicePosition) {\n cameraPosition = activeCamera.devicePosition;\n }\n this._rootMesh.position.subtractToRef(cameraPosition, TmpVectors.Vector3[0]);\n let scale = this.scaleRatio;\n if (activeCamera.mode == Camera.ORTHOGRAPHIC_CAMERA) {\n if (activeCamera.orthoTop && activeCamera.orthoBottom) {\n const orthoHeight = activeCamera.orthoTop - activeCamera.orthoBottom;\n scale *= orthoHeight;\n }\n }\n else {\n const camForward = activeCamera.getScene().useRightHandedSystem ? Vector3.RightHandedForwardReadOnly : Vector3.LeftHandedForwardReadOnly;\n const direction = activeCamera.getDirection(camForward);\n scale *= Vector3.Dot(TmpVectors.Vector3[0], direction);\n }\n this._rootMesh.scaling.setAll(scale);\n // Account for handedness, similar to Matrix.decompose\n if (effectiveNode._getWorldMatrixDeterminant() < 0 && !Gizmo.PreserveScaling) {\n this._rootMesh.scaling.y *= -1;\n }\n }\n else {\n this._rootMesh.scaling.setAll(this.scaleRatio);\n }\n }\n }\n /**\n * Handle position/translation when using an attached node using pivot\n */\n _handlePivot() {\n const attachedNodeTransform = this._attachedNode;\n // check there is an active pivot for the TransformNode attached\n if (attachedNodeTransform.isUsingPivotMatrix && attachedNodeTransform.isUsingPivotMatrix() && attachedNodeTransform.position) {\n // When a TransformNode has an active pivot, even without parenting,\n // translation from the world matrix is different from TransformNode.position.\n // Pivot works like a virtual parent that's using the node orientation.\n // As the world matrix is transformed by the gizmo and then decomposed to TRS\n // its translation part must be set to the Node's position.\n attachedNodeTransform.getWorldMatrix().setTranslation(attachedNodeTransform.position);\n }\n }\n /**\n * computes the rotation/scaling/position of the transform once the Node world matrix has changed.\n */\n _matrixChanged() {\n if (!this._attachedNode) {\n return;\n }\n if (this._attachedNode._isCamera) {\n const camera = this._attachedNode;\n let worldMatrix;\n let worldMatrixUC;\n if (camera.parent) {\n const parentInv = TmpVectors.Matrix[1];\n camera.parent._worldMatrix.invertToRef(parentInv);\n this._attachedNode._worldMatrix.multiplyToRef(parentInv, TmpVectors.Matrix[0]);\n worldMatrix = TmpVectors.Matrix[0];\n }\n else {\n worldMatrix = this._attachedNode._worldMatrix;\n }\n if (camera.getScene().useRightHandedSystem) {\n // avoid desync with RH matrix computation. Otherwise, rotation of PI around Y axis happens each frame resulting in axis flipped because worldMatrix is computed as inverse of viewMatrix.\n this._rightHandtoLeftHandMatrix.multiplyToRef(worldMatrix, TmpVectors.Matrix[1]);\n worldMatrixUC = TmpVectors.Matrix[1];\n }\n else {\n worldMatrixUC = worldMatrix;\n }\n worldMatrixUC.decompose(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0]);\n const inheritsTargetCamera = this._attachedNode.getClassName() === \"FreeCamera\" ||\n this._attachedNode.getClassName() === \"FlyCamera\" ||\n this._attachedNode.getClassName() === \"ArcFollowCamera\" ||\n this._attachedNode.getClassName() === \"TargetCamera\" ||\n this._attachedNode.getClassName() === \"TouchCamera\" ||\n this._attachedNode.getClassName() === \"UniversalCamera\";\n if (inheritsTargetCamera) {\n const targetCamera = this._attachedNode;\n targetCamera.rotation = TmpVectors.Quaternion[0].toEulerAngles();\n if (targetCamera.rotationQuaternion) {\n targetCamera.rotationQuaternion.copyFrom(TmpVectors.Quaternion[0]);\n targetCamera.rotationQuaternion.normalize();\n }\n }\n camera.position.copyFrom(TmpVectors.Vector3[0]);\n }\n else if (this._attachedNode._isMesh ||\n this._attachedNode.getClassName() === \"AbstractMesh\" ||\n this._attachedNode.getClassName() === \"TransformNode\" ||\n this._attachedNode.getClassName() === \"InstancedMesh\") {\n const transform = this._attachedNode;\n if (transform.parent) {\n const parentInv = TmpVectors.Matrix[0];\n const localMat = TmpVectors.Matrix[1];\n transform.parent.getWorldMatrix().invertToRef(parentInv);\n this._attachedNode.getWorldMatrix().multiplyToRef(parentInv, localMat);\n localMat.decompose(TmpVectors.Vector3[0], TmpVectors.Quaternion[0], transform.position, Gizmo.PreserveScaling ? transform : undefined);\n }\n else {\n this._attachedNode._worldMatrix.decompose(TmpVectors.Vector3[0], TmpVectors.Quaternion[0], transform.position, Gizmo.PreserveScaling ? transform : undefined);\n }\n TmpVectors.Vector3[0].scaleInPlace(1.0 / transform.scalingDeterminant);\n transform.scaling.copyFrom(TmpVectors.Vector3[0]);\n if (!transform.billboardMode) {\n if (transform.rotationQuaternion) {\n transform.rotationQuaternion.copyFrom(TmpVectors.Quaternion[0]);\n transform.rotationQuaternion.normalize();\n }\n else {\n transform.rotation = TmpVectors.Quaternion[0].toEulerAngles();\n }\n }\n }\n else if (this._attachedNode.getClassName() === \"Bone\") {\n const bone = this._attachedNode;\n const parent = bone.getParent();\n if (parent) {\n const invParent = TmpVectors.Matrix[0];\n const boneLocalMatrix = TmpVectors.Matrix[1];\n parent.getFinalMatrix().invertToRef(invParent);\n bone.getFinalMatrix().multiplyToRef(invParent, boneLocalMatrix);\n const lmat = bone.getLocalMatrix();\n lmat.copyFrom(boneLocalMatrix);\n }\n else {\n const lmat = bone.getLocalMatrix();\n lmat.copyFrom(bone.getFinalMatrix());\n }\n bone.markAsDirty();\n }\n else {\n const light = this._attachedNode;\n if (light.getTypeID) {\n const type = light.getTypeID();\n if (type === Light.LIGHTTYPEID_DIRECTIONALLIGHT || type === Light.LIGHTTYPEID_SPOTLIGHT || type === Light.LIGHTTYPEID_POINTLIGHT) {\n const parent = light.parent;\n if (parent) {\n const invParent = TmpVectors.Matrix[0];\n const nodeLocalMatrix = TmpVectors.Matrix[1];\n parent.getWorldMatrix().invertToRef(invParent);\n light.getWorldMatrix().multiplyToRef(invParent, nodeLocalMatrix);\n nodeLocalMatrix.decompose(undefined, TmpVectors.Quaternion[0], TmpVectors.Vector3[0]);\n }\n else {\n this._attachedNode._worldMatrix.decompose(undefined, TmpVectors.Quaternion[0], TmpVectors.Vector3[0]);\n }\n // setter doesn't copy values. Need a new Vector3\n light.position = new Vector3(TmpVectors.Vector3[0].x, TmpVectors.Vector3[0].y, TmpVectors.Vector3[0].z);\n if (light.direction) {\n light.direction = new Vector3(light.direction.x, light.direction.y, light.direction.z);\n }\n }\n }\n }\n }\n /**\n * refresh gizmo mesh material\n * @param gizmoMeshes\n * @param material material to apply\n */\n _setGizmoMeshMaterial(gizmoMeshes, material) {\n if (gizmoMeshes) {\n gizmoMeshes.forEach((m) => {\n m.material = material;\n if (m.color) {\n m.color = material.diffuseColor;\n }\n });\n }\n }\n /**\n * Subscribes to pointer up, down, and hover events. Used for responsive gizmos.\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param gizmoAxisCache Gizmo axis definition used for reactive gizmo UI\n * @returns {Observer} pointerObserver\n */\n static GizmoAxisPointerObserver(gizmoLayer, gizmoAxisCache) {\n let dragging = false;\n const pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {\n var _a, _b;\n if (pointerInfo.pickInfo) {\n // On Hover Logic\n if (pointerInfo.type === PointerEventTypes.POINTERMOVE) {\n if (dragging) {\n return;\n }\n gizmoAxisCache.forEach((cache) => {\n var _a, _b;\n if (cache.colliderMeshes && cache.gizmoMeshes) {\n const isHovered = ((_a = cache.colliderMeshes) === null || _a === void 0 ? void 0 : _a.indexOf((_b = pointerInfo === null || pointerInfo === void 0 ? void 0 : pointerInfo.pickInfo) === null || _b === void 0 ? void 0 : _b.pickedMesh)) != -1;\n const material = cache.dragBehavior.enabled ? (isHovered || cache.active ? cache.hoverMaterial : cache.material) : cache.disableMaterial;\n cache.gizmoMeshes.forEach((m) => {\n m.material = material;\n if (m.color) {\n m.color = material.diffuseColor;\n }\n });\n }\n });\n }\n // On Mouse Down\n if (pointerInfo.type === PointerEventTypes.POINTERDOWN) {\n // If user Clicked Gizmo\n if (gizmoAxisCache.has((_a = pointerInfo.pickInfo.pickedMesh) === null || _a === void 0 ? void 0 : _a.parent)) {\n dragging = true;\n const statusMap = gizmoAxisCache.get((_b = pointerInfo.pickInfo.pickedMesh) === null || _b === void 0 ? void 0 : _b.parent);\n statusMap.active = true;\n gizmoAxisCache.forEach((cache) => {\n var _a, _b;\n const isHovered = ((_a = cache.colliderMeshes) === null || _a === void 0 ? void 0 : _a.indexOf((_b = pointerInfo === null || pointerInfo === void 0 ? void 0 : pointerInfo.pickInfo) === null || _b === void 0 ? void 0 : _b.pickedMesh)) != -1;\n const material = (isHovered || cache.active) && cache.dragBehavior.enabled ? cache.hoverMaterial : cache.disableMaterial;\n cache.gizmoMeshes.forEach((m) => {\n m.material = material;\n if (m.color) {\n m.color = material.diffuseColor;\n }\n });\n });\n }\n }\n // On Mouse Up\n if (pointerInfo.type === PointerEventTypes.POINTERUP) {\n gizmoAxisCache.forEach((cache) => {\n cache.active = false;\n dragging = false;\n cache.gizmoMeshes.forEach((m) => {\n m.material = cache.dragBehavior.enabled ? cache.material : cache.disableMaterial;\n if (m.color) {\n m.color = cache.material.diffuseColor;\n }\n });\n });\n }\n }\n });\n return pointerObserver;\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n this._rootMesh.dispose();\n if (this._beforeRenderObserver) {\n this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.remove(this._beforeRenderObserver);\n }\n }\n }\n /**\n * When enabled, any gizmo operation will perserve scaling sign. Default is off.\n * Only valid for TransformNode derived classes (Mesh, AbstractMesh, ...)\n */\n Gizmo.PreserveScaling = false;\n\n /**\n * Renders gizmos on top of an existing scene which provide controls for position, rotation, etc.\n */\n const AUTO_MESH_NAME = '_autoGizmoMesh';\n class KbGizmo extends Gizmo {\n updateGizmoPosition() {\n this._update();\n }\n attachTo(node) { }\n get attachedMesh() {\n return super.attachedMesh;\n }\n set attachedMesh(m) {\n if (m) {\n super.attachedMesh = m;\n }\n }\n get visibility() {\n return this._rootMesh.visibility;\n }\n set visibility(visibility) {\n this._rootMesh.setEnabled(visibility === 1);\n }\n attachMeshAtNodeSpace(scene, target, positionSpaceTransform) {\n if (!this.attachedMesh) {\n this.attachedMesh = new Mesh(AUTO_MESH_NAME, scene);\n }\n let translation;\n const rotation = Quaternion.Identity();\n const scale = Vector3.One();\n translation = target instanceof exports.SpaceNode ? target.position.toVec3() : target.toVec3();\n if (positionSpaceTransform) {\n translation = Vector3.TransformCoordinates(translation, positionSpaceTransform);\n positionSpaceTransform.decompose(scale, rotation);\n }\n this.attachedMesh.position = translation;\n this.attachedMesh.rotationQuaternion = rotation;\n this.attachedMesh.scaling = scale;\n return this.attachedMesh;\n }\n _update() {\n if (this.attachedMesh) {\n const _tempVector = new Vector3();\n const _tmpMatrix = new Matrix();\n if (this.updateGizmoRotationToMatchAttachedMesh) {\n if (!this._rootMesh.rotationQuaternion) {\n this._rootMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._rootMesh.rotation.y, this._rootMesh.rotation.x, this._rootMesh.rotation.z);\n }\n // Remove scaling before getting rotation matrix to get rotation matrix unmodified by scale\n _tempVector.copyFrom(this.attachedMesh.scaling);\n if (this.attachedMesh.scaling.x < 0) {\n this.attachedMesh.scaling.x *= -1;\n }\n if (this.attachedMesh.scaling.y < 0) {\n this.attachedMesh.scaling.y *= -1;\n }\n if (this.attachedMesh.scaling.z < 0) {\n this.attachedMesh.scaling.z *= -1;\n }\n this.attachedMesh.computeWorldMatrix().getRotationMatrixToRef(_tmpMatrix);\n this.attachedMesh.scaling.copyFrom(_tempVector);\n this.attachedMesh.computeWorldMatrix();\n Quaternion.FromRotationMatrixToRef(_tmpMatrix, this._rootMesh.rotationQuaternion);\n }\n // else if (this._rootMesh.rotationQuaternion) {\n // this._rootMesh.rotationQuaternion.set(0, 0, 0, 1);\n // }\n if (this.updateGizmoPositionToMatchAttachedMesh) {\n this._rootMesh.position.copyFrom(this.attachedMesh.absolutePosition);\n }\n if (this.updateScale && this.gizmoLayer.utilityLayerScene.activeCamera && this.attachedMesh) {\n let dist;\n const camera = this.gizmoLayer.utilityLayerScene.activeCamera;\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n dist = ((camera.orthoRight || 0) - (camera.orthoLeft || 0)) / 2;\n }\n else {\n let cameraPosition;\n if (camera instanceof WebXRCamera && camera.globalPosition) {\n cameraPosition = camera.globalPosition;\n }\n else if (camera instanceof ArcRotateCamera) {\n cameraPosition = getCameraPositionWithOffset(camera);\n }\n else {\n cameraPosition = camera.globalPosition;\n }\n this._rootMesh.position.subtractToRef(cameraPosition, _tempVector);\n dist = _tempVector.length() * this.scaleRatio;\n }\n this._rootMesh.scaling.set(dist, dist, dist);\n }\n const pivot = this.attachedMesh.getPivotPoint();\n //let absolutePosition = this.attachedMesh.absolutePosition;\n // Absolute position is getting skewed because of the pivot point; need to get position without the rotation\n // if (pivot.length() > 0 && this.attachedMesh.rotationQuaternion) {\n // var m = new Matrix();\n // this.attachedMesh.rotationQuaternion.toRotationMatrix(m);\n // absolutePosition = Vector3.TransformCoordinates(absolutePosition, m)\n // }\n // if (pivot.length() > 0) {\n // absolutePosition = Vector3.Zero();\n // }\n this._rootMesh.position.copyFrom(Vector3.TransformCoordinates(pivot, this.attachedMesh.getWorldMatrix()));\n }\n }\n }\n\n /**\n * Single plane rotation gizmo\n */\n class KbPlaneRotationGizmo extends KbGizmo {\n /**\n * Creates a PlaneRotationGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param planeNormal The normal of the plane which the gizmo will be able to rotate on\n * @param color The color of the gizmo\n * @param tessellation Amount of tessellation to be used when creating rotation circles\n */\n constructor(planeNormal, color = Color3.Gray(), gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, tessellation = 32) {\n super(gizmoLayer);\n this._pointerObserver = null;\n /**\n * Rotation distance in radians that the gizmo will snap to (Default: 0)\n */\n this.snapDistance = 0;\n /**\n * Event that fires each time the gizmo snaps to a new location.\n * * snapDistance is the the change in distance\n */\n this.onSnapObservable = new Observable$1();\n this.updateObservable = new Observable$1();\n // Create Material\n const coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n coloredMaterial.emissiveColor = color;\n // coloredMaterial.diffuseColor = color;\n // coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\n // Build mesh on root node\n const parentMesh = new AbstractMesh('', gizmoLayer.utilityLayerScene);\n const drag = Mesh.CreateTorus('', 0.6, 0.045, tessellation, gizmoLayer.utilityLayerScene);\n drag.visibility = 0;\n const rotationMesh = Mesh.CreateTorus('', 0.6, 0.01, tessellation, gizmoLayer.utilityLayerScene);\n rotationMesh.material = coloredMaterial;\n // Position arrow pointing in its drag axis\n rotationMesh.rotation.x = Math.PI / 2;\n drag.rotation.x = Math.PI / 2;\n parentMesh.addChild(rotationMesh);\n parentMesh.addChild(drag);\n parentMesh.lookAt(this._rootMesh.position.add(planeNormal));\n this.rotationMesh = parentMesh;\n this._rootMesh.addChild(parentMesh);\n parentMesh.scaling.scaleInPlace(1 / 3);\n // Add drag behavior to handle events when the gizmo is dragged\n this.dragBehavior = new PointerDragBehavior({ dragPlaneNormal: planeNormal });\n this.dragBehavior.moveAttached = false;\n this.dragBehavior.maxDragAngle = (Math.PI * 9) / 20;\n this.dragBehavior._useAlternatePickedPointAboveMaxDragAngle = true;\n this._rootMesh.addBehavior(this.dragBehavior);\n const lastDragPosition = new Vector3();\n this.dragBehavior.onDragStartObservable.add(e => {\n if (this.attachedMesh) {\n lastDragPosition.copyFrom(e.dragPlanePoint);\n }\n });\n const rotationMatrix = new Matrix();\n const planeNormalTowardsCamera = new Vector3();\n let localPlaneNormalTowardsCamera = new Vector3();\n const tmpSnapEvent = { snapDistance: 0 };\n let currentSnapDragDistance = 0;\n const tmpMatrix = new Matrix();\n const tmpVector = new Vector3();\n const amountToRotate = new Quaternion();\n this.dragBehavior.onDragObservable.add(event => {\n if (this.attachedMesh) {\n if (!this.attachedMesh.rotationQuaternion) {\n this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.attachedMesh.rotation.y, this.attachedMesh.rotation.x, this.attachedMesh.rotation.z);\n }\n // Remove parent priort to rotating\n const attachedMeshParent = this.attachedMesh.parent;\n if (attachedMeshParent) {\n this.attachedMesh.setParent(null);\n }\n // Calc angle over full 360 degree (https://stackoverflow.com/questions/43493711/the-angle-between-two-3d-vectors-with-a-result-range-0-360)\n const pivot = this.attachedMesh.getPivotPoint();\n const attachedMeshPosition = this.attachedMesh.absolutePosition.add(pivot);\n const newVector = event.dragPlanePoint.subtract(attachedMeshPosition).normalize();\n const originalVector = lastDragPosition.subtract(attachedMeshPosition).normalize();\n const cross = Vector3.Cross(newVector, originalVector);\n const dot = Vector3.Dot(newVector, originalVector);\n let angle = Math.atan2(cross.length(), dot);\n planeNormalTowardsCamera.copyFrom(planeNormal);\n localPlaneNormalTowardsCamera.copyFrom(planeNormal);\n if (this.updateGizmoRotationToMatchAttachedMesh) {\n this.attachedMesh.rotationQuaternion.toRotationMatrix(rotationMatrix);\n localPlaneNormalTowardsCamera = Vector3.TransformCoordinates(planeNormalTowardsCamera, rotationMatrix);\n }\n // Flip up vector depending on which side the camera is on\n if (gizmoLayer.utilityLayerScene.activeCamera) {\n const camVec = gizmoLayer.utilityLayerScene.activeCamera.position.subtract(this.attachedMesh.position);\n if (Vector3.Dot(camVec, localPlaneNormalTowardsCamera) > 0) {\n planeNormalTowardsCamera.scaleInPlace(-1);\n localPlaneNormalTowardsCamera.scaleInPlace(-1);\n }\n }\n const halfCircleSide = Vector3.Dot(localPlaneNormalTowardsCamera, cross) > 0.0;\n if (halfCircleSide) {\n angle = -angle;\n }\n // Snapping logic\n let snapped = false;\n if (this.snapDistance != 0) {\n currentSnapDragDistance += angle;\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\n let dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\n if (currentSnapDragDistance < 0) {\n dragSteps *= -1;\n }\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\n angle = this.snapDistance * dragSteps;\n snapped = true;\n }\n else {\n angle = 0;\n }\n }\n // If the mesh has a parent, convert needed world rotation to local rotation\n tmpMatrix.reset();\n if (this.attachedMesh.parent) {\n this.attachedMesh.parent.computeWorldMatrix().invertToRef(tmpMatrix);\n tmpMatrix.getRotationMatrixToRef(tmpMatrix);\n Vector3.TransformCoordinatesToRef(planeNormalTowardsCamera, tmpMatrix, planeNormalTowardsCamera);\n }\n // Convert angle and axis to quaternion (http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm)\n const quaternionCoefficient = Math.sin(angle / 2);\n amountToRotate.set(planeNormalTowardsCamera.x * quaternionCoefficient, planeNormalTowardsCamera.y * quaternionCoefficient, planeNormalTowardsCamera.z * quaternionCoefficient, Math.cos(angle / 2));\n // If the meshes local scale is inverted (eg. loaded gltf file parent with z scale of -1) the rotation needs to be inverted on the y axis\n if (tmpMatrix.determinant() > 0) {\n amountToRotate.toEulerAnglesToRef(tmpVector);\n Quaternion.RotationYawPitchRollToRef(tmpVector.y, -tmpVector.x, -tmpVector.z, amountToRotate);\n }\n if (this.updateGizmoRotationToMatchAttachedMesh) {\n // Rotate selected mesh quaternion over fixed axis\n this.attachedMesh.rotationQuaternion.multiplyToRef(amountToRotate, this.attachedMesh.rotationQuaternion);\n }\n else {\n // Rotate selected mesh quaternion over rotated axis\n amountToRotate.multiplyToRef(this.attachedMesh.rotationQuaternion, this.attachedMesh.rotationQuaternion);\n }\n this.updateObservable.notifyObservers({ delta: amountToRotate, deltaAngle: angle });\n lastDragPosition.copyFrom(event.dragPlanePoint);\n if (snapped) {\n tmpSnapEvent.snapDistance = angle;\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\n }\n // Restore parent\n if (attachedMeshParent) {\n this.attachedMesh.setParent(attachedMeshParent);\n }\n }\n });\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\n if (this._customMeshSet) {\n return;\n }\n const isHovered = pointerInfo.pickInfo &&\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\n const material = isHovered ? hoverMaterial : coloredMaterial;\n this._rootMesh.getChildMeshes().forEach(m => {\n m.material = material;\n if (m.color) {\n m.color = material.diffuseColor;\n }\n });\n });\n // var light = gizmoLayer._getSharedGizmoLight();\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));\n }\n _attachedMeshChanged(value) {\n if (this.dragBehavior) {\n this.dragBehavior.enabled = value ? true : false;\n }\n // if (value) {\n // this.rotationMesh.setPivotPoint(Vector3.Zero(), Space.LOCAL);\n // }\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n this.onSnapObservable.clear();\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\n this.dragBehavior.detach();\n super.dispose();\n }\n }\n\n const tessellation = 32;\n /**\n * TODO\n * Copy in plane rotation gizmo code here and change it to use a sphere and click projection on the sphere\n * Convert it to return an axis\n * Edit code in here to return an axis and angle\n * update gizmo tools code to hook to this gizmo\n * remove the vector option from the original rotation gizmo (now the euler rotation gizmo), simplify code\n */\n /**\n * Gizmo that enables rotating a mesh along 3 axis\n */\n class KbAxisAngleGizmo extends KbGizmo {\n attachTo(target, positionSpace, placementOffset) {\n if (positionSpace) {\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\n }\n this._updateGizmoPosition(target, placementOffset);\n }\n updateGizmoPosition(changeTarget, placementOffset) {\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\n this.kbViewer.onNextFrame(() => {\n this._updateGizmoPosition(changeTarget, placementOffset);\n });\n }\n _updateGizmoPosition(changeTarget, placementOffset) {\n var _a;\n // Maintain the placement offset if it is not provided later, so this can be called from other contexts to update based on external changes\n if (!placementOffset && this.placementOffset) {\n placementOffset = this.placementOffset;\n }\n else if (placementOffset) {\n this.placementOffset = placementOffset;\n }\n const positionSpaceTransform = (_a = this._positionSpace) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n if (changeTarget) {\n changeTarget.toVec3(this.targetAxis);\n // If target is a vector, then we want to rotate it as a direction, so set the gizmo position to the origin to calculations are done from there\n // But store the position as the offset because we want the gizmo itself to be visually placed on the position space origin\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, placementOffset || exports.KbVector.Zero(), positionSpaceTransform);\n if (this.attachedMesh) {\n this.gizmoOffset = exports.KbVector.FromVec3(this.attachedMesh.position);\n this.attachedMesh.position = Vector3.Zero();\n this.attachedMesh.computeWorldMatrix(true);\n }\n const targetAxisTransformed = this.targetAxis.clone();\n if (positionSpaceTransform) {\n Vector3.TransformCoordinatesToRef(this.targetAxis, positionSpaceTransform.getRotationMatrix(), targetAxisTransformed);\n }\n this.axisGizmo.direction.copyFrom(targetAxisTransformed);\n }\n if (this.gizmoOffset && this.attachedMesh) {\n this.attachedMesh.position.copyFrom(this.gizmoOffset.toVec3());\n this.axisGizmo.gizmoPosition.copyFrom(this.gizmoOffset.toVec3());\n // if (placementOffset) {\n // this.axisGizmo.gizmoPosition.addInPlace(placementOffset.toVec3());\n // }\n }\n // if (positionSpaceTransform) {\n // Vector3.TransformCoordinatesToRef(this.axisGizmo.gizmoPosition, positionSpaceTransform, this.axisGizmo.gizmoPosition);\n // }\n super.updateGizmoPosition();\n }\n get attachedMesh() {\n return super.attachedMesh;\n }\n set attachedMesh(mesh) {\n super.attachedMesh = mesh;\n if (mesh) {\n const angleMesh = new Mesh('', this.gizmoLayer.utilityLayerScene);\n mesh.addChild(angleMesh);\n if (this.angleGizmo) {\n this.angleGizmo.attachedMesh = angleMesh;\n }\n angleMesh.lookAt(this.targetAxis);\n angleMesh.setPivotPoint(mesh.getPivotPoint(), Space.WORLD);\n }\n else if (this.angleGizmo) {\n this.angleGizmo.attachedMesh = null;\n }\n }\n /**\n * Creates a RotationGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param tessellation Amount of tessellation to be used when creating rotation circles\n */\n constructor(kbViewer, gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, disableAngle = false) {\n super(gizmoLayer);\n this.kbViewer = kbViewer;\n this.targetAxis = new Vector3();\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onDragStartObservable = new Observable$1();\n /** Fires an event when any of it's sub gizmos are released from dragging */\n this.onDragObservable = new Observable$1();\n this.onDragEndObservable = new Observable$1();\n this.updateGizmoRotationToMatchAttachedMesh = true;\n this.axisGizmo = new KbAxisMorphGizmo(Color3.Green().scale(0.5), gizmoLayer, tessellation);\n if (!disableAngle) {\n this.angleGizmo = new KbPlaneRotationGizmo(new Vector3(0, 0, 1), Color3.Green().scale(0.5), gizmoLayer, tessellation);\n this.angleGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n }\n const zeroVector = Vector3.Zero();\n const tempVector = Vector3.Zero();\n const tempVector2 = Vector3.Zero();\n let positionSpaceTransform;\n this.axisChange = Vector3.Zero();\n this.angleChange = 0;\n // Relay drag events\n [this.axisGizmo, this.angleGizmo].forEach(gizmo => {\n if (gizmo) {\n gizmo.dragBehavior.onDragStartObservable.add(() => {\n this.onDragStartObservable.notifyObservers();\n this.axisChange = Vector3.Zero();\n this.angleChange = 0;\n if (!positionSpaceTransform && this._positionSpace) {\n positionSpaceTransform = this._positionSpace\n .computeWorldMatrix(true)\n .getRotationMatrix()\n .clone()\n .invert();\n }\n });\n gizmo.dragBehavior.onDragEndObservable.add(() => {\n this.onDragEndObservable.notifyObservers({\n deltaAxis: this.axisChange,\n deltaAngle: this.angleChange,\n });\n });\n }\n });\n this.axisGizmo.updateObservable.add(event => {\n tempVector.copyFrom(this.targetAxis);\n // if (positionSpaceTransform) {\n // Vector3.TransformCoordinatesToRef(tempVector, positionSpaceTransform, tempVector);\n // }\n tempVector.rotateByQuaternionToRef(event.delta, tempVector2);\n // if (positionSpaceTransform) {\n // Vector3.TransformCoordinatesToRef(tempVector2, positionSpaceTransform.clone().invert(), tempVector2);\n // }\n tempVector2.subtractToRef(this.targetAxis, tempVector2);\n this.targetAxis.addInPlace(tempVector2);\n this.axisChange.addInPlace(tempVector2);\n this.onDragObservable.notifyObservers({ deltaAxis: tempVector2, deltaAngle: 0 });\n if (this.angleGizmo && this.angleGizmo.attachedMesh) {\n this.angleGizmo.attachedMesh.lookAt(positionSpaceTransform\n ? Vector3.TransformCoordinates(this.targetAxis, positionSpaceTransform)\n : this.targetAxis);\n }\n });\n if (this.angleGizmo) {\n this.angleGizmo.updateObservable.add(event => {\n this.angleChange -= event.deltaAngle;\n this.onDragObservable.notifyObservers({ deltaAxis: zeroVector, deltaAngle: -event.deltaAngle });\n });\n }\n this.attachedMesh = null;\n }\n /**\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\n */\n set snapDistance(value) {\n if (this.axisGizmo) {\n this.axisGizmo.snapDistance = value;\n }\n if (this.angleGizmo) {\n this.angleGizmo.snapDistance = value;\n }\n }\n get snapDistance() {\n return this.axisGizmo.snapDistance;\n }\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n set scaleRatio(value) {\n if (this.axisGizmo) {\n this.axisGizmo.scaleRatio = value;\n }\n if (this.angleGizmo) {\n this.angleGizmo.scaleRatio = value;\n }\n }\n get scaleRatio() {\n return this.axisGizmo.scaleRatio;\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n if (this.axisGizmo) {\n this.axisGizmo.dispose();\n }\n if (this.angleGizmo) {\n this.angleGizmo.dispose();\n }\n this.onDragStartObservable.clear();\n this.onDragEndObservable.clear();\n }\n /**\n * CustomMeshes are not supported by this gizmo\n * @param mesh The mesh to replace the default mesh of the gizmo\n */\n setCustomMesh(mesh) {\n Logger.Error('Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.angleGizmo, gizmo.zGizmo)');\n }\n }\n\n const meshFaceInfo = new Map();\n class MeshFaceEngine {\n constructor(kbViewer) {\n this.kbViewer = kbViewer;\n this.bbCache = kbViewer.bbCache;\n }\n initialize(node) {\n let meshNode;\n let mesh;\n if (node instanceof exports.Kb3dObject) {\n mesh = this.kbViewer.getRendererNode(node);\n meshNode = node;\n }\n else {\n mesh = node;\n meshNode = getByDynamicId(node.id);\n }\n if (mesh instanceof Mesh && mesh.geometry) {\n this.bbCache\n .watchForChanges(meshNode)\n .pipe(take(1))\n .subscribe(() => {\n meshFaceInfo.delete(meshNode._dynamicId);\n });\n return this.updateNodeGeometry(mesh);\n }\n }\n getMeshFaces(node) {\n let result = meshFaceInfo.get(node instanceof exports.Kb3dObject ? node._dynamicId : node.id);\n if (!result) {\n result = this.initialize(node);\n }\n return result;\n }\n /**\n * @param selection array of selected faces to expand from\n * @param limitAngle angle to limit selection to. If undefined, function will expand by 1 polygon\n */\n expandSelection(selection, node, limitAngle) {\n const faceInfo = this.getMeshFaces(node);\n const faceNormals = faceInfo.faceNormals;\n const selectedFaceIds = [];\n const newSelection = [];\n if (limitAngle !== undefined) {\n limitAngle = (limitAngle * Math.PI) / 180;\n }\n const v1 = new Vector3(), v2 = new Vector3();\n if (!faceInfo) {\n return selection;\n }\n for (let i = 0; i < selection.length; i++) {\n selectedFaceIds[selection[i]] = true;\n }\n for (let i = 0; i < selection.length; i++) {\n const faceId = selection[i];\n v1.copyFromFloats(faceNormals[faceId * 3], faceNormals[faceId * 3 + 1], faceNormals[faceId * 3 + 2]);\n recursiveExpandSelection(faceId, 1, v1);\n }\n for (const faceId in selectedFaceIds) {\n newSelection.push(parseInt(faceId, 10));\n }\n return newSelection;\n function recursiveExpandSelection(faceId, iterCount, normal) {\n const neighbors = faceInfo.faceNeighbors[faceId];\n if (limitAngle === undefined && iterCount <= 0) {\n return;\n }\n for (let i = 0; i < neighbors.length; i++) {\n const adjacentFaceId = neighbors[i];\n if (!selectedFaceIds[adjacentFaceId]) {\n if (limitAngle !== undefined) {\n v2.copyFromFloats(faceNormals[adjacentFaceId * 3], faceNormals[adjacentFaceId * 3 + 1], faceNormals[adjacentFaceId * 3 + 2]);\n if (Math.abs(Math.acos(Math.round(Vector3.Dot(normal, v2) * 1000000) / 1000000)) <= limitAngle) {\n // deal with FP Errors\n selectedFaceIds[adjacentFaceId] = true;\n recursiveExpandSelection(adjacentFaceId, iterCount - 1, normal);\n }\n }\n else {\n selectedFaceIds[adjacentFaceId] = true;\n recursiveExpandSelection(adjacentFaceId, iterCount - 1, normal);\n }\n }\n }\n }\n }\n updateNodeGeometry(mesh) {\n if (mesh.geometry) {\n const indices = mesh.geometry.getIndices();\n const positions = mesh.geometry.getVerticesData(VertexBuffer.PositionKind);\n const v1 = new Vector3();\n const v2 = new Vector3();\n const v3 = new Vector3();\n const v4 = new Vector3();\n if (indices && positions) {\n const facesByEdges = {};\n /** Sets of three faces by index adjacent to each face by index */\n const faceNeighbors = [];\n /** Sets of xyz scalars making up the face normals */\n const faceNormals = [];\n const facePositions = [];\n const trianglesCount = indices.length / 3;\n for (let triId = 0; triId < trianglesCount; triId++) {\n const triOffset = triId * 3;\n // Get the triangle position vertices\n v1.copyFromFloats(positions[indices[triOffset] * 3], positions[indices[triOffset] * 3 + 1], positions[indices[triOffset] * 3 + 2]);\n v2.copyFromFloats(positions[indices[triOffset + 1] * 3], positions[indices[triOffset + 1] * 3 + 1], positions[indices[triOffset + 1] * 3 + 2]);\n v3.copyFromFloats(positions[indices[triOffset + 2] * 3], positions[indices[triOffset + 2] * 3 + 1], positions[indices[triOffset + 2] * 3 + 2]);\n // Calculate the centroid of each face\n v4.setAll(0);\n v4.addInPlace(v1).addInPlace(v2).addInPlace(v3);\n v4.scaleInPlace(1 / 3);\n facePositions.push(v4.x, v4.y, v4.z);\n // Get two of the triangle edges\n v1.subtractInPlace(v2);\n v2.subtractInPlace(v3);\n // Get the triangle face normal with the two edges.\n // Note that this is not the geometry normal, but the position-based face normal\n Vector3.CrossToRef(v1, v2, v4);\n const faceNormal = v4;\n faceNormal.normalize();\n faceNormals.push(faceNormal.x, faceNormal.y, faceNormal.z);\n // Now we need to consolidate what triangles are next to each other by organizing them by edges\n for (let i = 0; i < 3; i++) {\n const idx1 = indices[triOffset + i];\n const idx2 = indices[triOffset + ((i + 1) % 3)];\n // This is not going to work for geometry seams like on cylinders.\n // Possibly change from index ids to a representation of the vertex position\n const edgeId = idx1 > idx2 ? `${idx1}-${idx2}` : `${idx2}-${idx1}`;\n if (!facesByEdges[edgeId]) {\n facesByEdges[edgeId] = [];\n }\n facesByEdges[edgeId].push(triId);\n }\n }\n // Now we go through the edges and register the neighbors for each triangle\n for (const edgeId in facesByEdges) {\n const faces = facesByEdges[edgeId];\n if (!faceNeighbors[faces[0]]) {\n faceNeighbors[faces[0]] = [];\n }\n // Some edges may only have one face if the face is on the edge of the geometry\n if (faces.length > 1) {\n if (!faceNeighbors[faces[1]]) {\n faceNeighbors[faces[1]] = [];\n }\n faceNeighbors[faces[0]].push(faces[1]);\n faceNeighbors[faces[1]].push(faces[0]);\n }\n }\n const result = {\n faceCount: trianglesCount,\n faceNeighbors,\n facePositions,\n faceNormals,\n };\n meshFaceInfo.set(mesh.id, result);\n return result;\n }\n }\n }\n }\n\n (function (eMarqueeSelectMode) {\n eMarqueeSelectMode[eMarqueeSelectMode[\"Facets\"] = 0] = \"Facets\";\n eMarqueeSelectMode[eMarqueeSelectMode[\"Vertices\"] = 1] = \"Vertices\";\n })(exports.eMarqueeSelectMode || (exports.eMarqueeSelectMode = {}));\n class Interaction {\n constructor(kbViewer, scene, highlighter) {\n this.kbViewer = kbViewer;\n this.scene = scene;\n this.highlighter = highlighter;\n this.onClick$ = new Subject();\n this.onFacetClick$ = new Subject();\n this.onDoubleClick$ = new Subject();\n this.onPointerMove$ = new Subject();\n this.onPointerDown$ = new Subject();\n this.onPointerUp$ = new Subject();\n this.onKeyboard$ = new Subject();\n this.onMarqueeSelect = null;\n this.pointerIsDown = false;\n this.dragInProgress = false;\n this.selectionTolerance = 0;\n this.cameraFacingDirection = new Vector3();\n this.meshFaceEngine = new MeshFaceEngine(kbViewer);\n this.onClick = this.onClick$.asObservable();\n this.onFacetClick = this.onFacetClick$.asObservable();\n this.onDoubleClick = this.onDoubleClick$.asObservable();\n this.onPointerMove = this.onPointerMove$.asObservable();\n this.onPointerDown = this.onPointerDown$.asObservable();\n this.onPointerUp = this.onPointerUp$.asObservable();\n this.onKeyboard = this.onKeyboard$.asObservable();\n this.attachScene(scene);\n }\n attachScene(scene, utilityLayer = false) {\n scene.onPointerObservable.add(p => {\n const args = this.getKb3dPointerArgs(p);\n switch (p.type) {\n case PointerEventTypes.POINTERDOWN:\n this.handlePointerDown(args);\n break;\n case PointerEventTypes.POINTERUP:\n this.handlePointerUp(args);\n break;\n case PointerEventTypes.POINTERMOVE:\n this.handleMove(args);\n break;\n // case PointerEventTypes.POINTERWHEEL:\n // console.log(\"POINTER WHEEL\");\n // break;\n // case PointerEventTypes.POINTERPICK:\n // console.log(\"POINTER PICK\");\n // break;\n case PointerEventTypes.POINTERTAP:\n this.handleClick(args);\n break;\n case PointerEventTypes.POINTERDOUBLETAP:\n this.handleDoubleClick(args);\n break;\n }\n });\n scene.onKeyboardObservable.add(k => {\n const args = this.getKeyboardArgs(k);\n switch (k.type) {\n case KeyboardEventTypes.KEYDOWN:\n this.handleKeyboard(args);\n }\n });\n }\n setSelectionTolerance(tolerance) {\n this.selectionTolerance = tolerance;\n }\n setSelectionCulling(enabled) {\n if (this.marqueeSelectOptions) {\n this.marqueeSelectOptions.cullSelection = enabled;\n }\n }\n enableMarqueeSelect(meshNode, mode, options) {\n const mesh = this.kbViewer.getRendererNode(meshNode);\n if (mesh instanceof Mesh) {\n this.onMarqueeSelect = new Subject();\n this.marqueeSelectOptions = {\n cullSelection: false,\n onlyOnShiftPress: true,\n startX: 0,\n startY: 0,\n mode,\n mesh,\n ...(options || {}),\n };\n return this.onMarqueeSelect.asObservable().pipe(distinctUntilChanged((prev, curr) => {\n if (prev.selectedFaces.length !== curr.selectedFaces.length ||\n prev.vertexList.length !== curr.vertexList.length) {\n return false;\n }\n for (let i = 0; i < curr.selectedFaces.length; i++) {\n if (curr.selectedFaces[i] !== prev.selectedFaces[i]) {\n return false;\n }\n }\n for (let i = 0; i < curr.vertexList.length; i++) {\n if (curr.vertexList[i] !== prev.vertexList[i]) {\n return false;\n }\n }\n return true;\n }));\n }\n return EMPTY;\n }\n disableMarqueeSelect() {\n if (this.onMarqueeSelect) {\n this.onMarqueeSelect.complete();\n }\n this.onMarqueeSelect = null;\n }\n /** Do a hit test of the scene using x,y screen pixel coordinates */\n pick(x, y, camera) {\n const pickInfo = this.scene.pick(x, y, undefined, undefined, camera);\n if (pickInfo && pickInfo.hit) {\n const info = { ...pickInfo };\n this.fillKb3dPickInfo(pickInfo, info);\n return info;\n }\n return undefined;\n }\n handleClickTypeEvent(args, handlerType) {\n // For debugging\n // if (args.pickInfo?.ray) {\n // RayHelper.CreateAndShow(args.pickInfo.ray, this.scene, new Color3(1, 1, 0.1));\n // }\n if (args.targetNode) {\n //bubble up event, calling any handlers that have been applied to the nodes\n let h = this.getNextNodeHandlers(args.targetNode, handlerType);\n while (h) {\n let propagate = false;\n args.sourceNode = h.node;\n for (const handler of h.handlers) {\n handler(args);\n if (args.propagate)\n propagate = true;\n }\n if (!propagate)\n break;\n h = this.getNextNodeHandlers(h.node._parent, handlerType);\n }\n }\n else {\n //there was no clicked mesh, but if there is a handler on the root scene node, we trigger that\n const handlers = this.getHandlerMap(this.kbViewer.sceneNode, handlerType).getByKey(this.kbViewer.sceneNode);\n if (handlers) {\n args.targetNode = args.sourceNode = this.kbViewer.sceneNode;\n for (const handler of handlers) {\n handler(args);\n }\n }\n }\n }\n handleClick(args) {\n var _a;\n this.handleClickTypeEvent(args, exports.eHandler.click);\n // trigger the normal generic observable\n this.onClick$.next(args);\n // if there is an observer on the facet click, then send the facet data there\n if (this.onFacetClick$.observers.length > 0) {\n if (((_a = args.pickInfo) === null || _a === void 0 ? void 0 : _a.pickedMesh) && args.pickInfo.pickedMesh instanceof Mesh) {\n const pickedMesh = args.pickInfo.pickedMesh;\n const selectedTriangle = args.pickInfo.faceId;\n const faceInfo = this.meshFaceEngine.getMeshFaces(pickedMesh);\n if (faceInfo) {\n let selection = [];\n if (this.selectionTolerance >= 0) {\n selection = this.meshFaceEngine.expandSelection([selectedTriangle], pickedMesh, this.selectionTolerance);\n }\n else {\n selection = [selectedTriangle];\n }\n const facetArgs = {\n ...args,\n altKey: args.event.altKey,\n selectedFaces: selection,\n };\n this.onFacetClick$.next(facetArgs);\n }\n }\n }\n }\n handleDoubleClick(args) {\n this.handleClickTypeEvent(args, exports.eHandler.doubleClick);\n //trigger the normal generic observable\n this.onDoubleClick$.next(args);\n }\n handleMove(args) {\n if (!this.pointerIsDown && this.kbViewer.sceneNode && this.kbViewer.sceneNode.enableHoverEffects) {\n if (args.targetNode) {\n const clicks = this.getNextClickHandlers(args.targetNode);\n const draggables = this.getNextDraggables(args.targetNode);\n if (clicks || draggables) {\n const n = (clicks === null || clicks === void 0 ? void 0 : clicks.node) || (draggables === null || draggables === void 0 ? void 0 : draggables.node);\n this.highlighter.hover(n);\n }\n }\n else {\n this.highlighter.clearHover();\n }\n }\n if (this.scene.activeCamera instanceof KbArcRotateCamera && this.pointerIsDown && this.onMarqueeSelect) {\n if (!this.marqueeSelectOptions.onlyOnShiftPress || args.shiftKey) {\n args.event.preventDefault();\n args.event.stopPropagation();\n this.handleMarquee(args, this.scene.activeCamera);\n }\n else {\n this.unlockCamera();\n }\n }\n this.onPointerMove$.next(args);\n }\n handlePointerDown(args) {\n var _a;\n this.pointerIsDown = true;\n if (this.onMarqueeSelect) {\n if (!this.marqueeSelectOptions.onlyOnShiftPress || args.shiftKey) {\n this.marqueeSelectOptions.startX = args.canvasX || 0;\n this.marqueeSelectOptions.startY = args.canvasY || 0;\n this.marqueeSelectOptions.startRay =\n ((_a = this.scene.pick(args.canvasX, args.canvasY, undefined, undefined, this.scene.activeCamera)) === null || _a === void 0 ? void 0 : _a.ray) ||\n undefined;\n if (this.kbViewer.uiOverlay) {\n const selectBox = document.createElement('div');\n selectBox.style.position = 'absolute';\n selectBox.style.border = '1px dashed white';\n selectBox.style.background = 'rgba(128, 128, 128, 0.1)';\n selectBox.style.opacity = '0.5';\n this.kbViewer.uiOverlay.appendChild(selectBox);\n this.marqueeSelectOptions.selectBox = selectBox;\n }\n this.cameraFacingDirection = this.scene.activeCamera.getForwardRay().direction;\n if (!this.marqueeSelectOptions.mesh.isFacetDataEnabled &&\n this.marqueeSelectOptions.mode === exports.eMarqueeSelectMode.Facets) {\n const normals = this.marqueeSelectOptions.mesh.getVerticesData(VertexBuffer.NormalKind);\n if (!normals) {\n this.marqueeSelectOptions.mesh.setVerticesData(VertexBuffer.NormalKind, new Float32Array(this.marqueeSelectOptions.mesh.getTotalVertices() * 3));\n }\n }\n }\n }\n else if (args.targetNode) {\n const d = this.getNextDraggables(args.targetNode);\n if (d) {\n this.highlighter.clearHover();\n args.sourceNode = d.node;\n const dragger = new Dragger(this.kbViewer, this.scene);\n this.dragInProgress = true;\n dragger.startDrag(args, d.handlers[0], () => {\n this.dragInProgress = false;\n });\n }\n }\n this.onPointerDown$.next(args);\n }\n unlockCamera() {\n var _a;\n (_a = this.scene.activeCamera) === null || _a === void 0 ? void 0 : _a.attachControl(this.kbViewer.canvas);\n }\n handlePointerUp(args) {\n var _a;\n this.pointerIsDown = false;\n if (this.marqueeSelectOptions && this.marqueeSelectOptions.selectBox) {\n (_a = this.kbViewer.uiOverlay) === null || _a === void 0 ? void 0 : _a.removeChild(this.marqueeSelectOptions.selectBox);\n delete this.marqueeSelectOptions.selectBox;\n }\n this.unlockCamera();\n this.onPointerUp$.next(args);\n }\n handleKeyboard(args) {\n this.onKeyboard$.next(args);\n }\n handleMarquee(args, activeCamera) {\n var _a;\n const mouseX = args.canvasX || 0;\n const mouseY = args.canvasY || 0;\n activeCamera.detachControl();\n if (this.marqueeSelectOptions.selectBox) {\n this.marqueeSelectOptions.selectBox.style.left = Math.min(this.marqueeSelectOptions.startX, mouseX) + 'px';\n this.marqueeSelectOptions.selectBox.style.top = Math.min(this.marqueeSelectOptions.startY, mouseY) + 'px';\n this.marqueeSelectOptions.selectBox.style.width =\n Math.abs(this.marqueeSelectOptions.startX - mouseX) + 'px';\n this.marqueeSelectOptions.selectBox.style.height =\n Math.abs(this.marqueeSelectOptions.startY - mouseY) + 'px';\n }\n let topOrigin;\n let leftOrigin;\n let rightOrigin;\n let bottomOrigin;\n let topNormal;\n let leftNormal;\n let rightNormal;\n let bottomNormal;\n const m = Matrix.Identity();\n const boxL = Math.min(this.marqueeSelectOptions.startX, mouseX);\n const boxR = Math.max(this.marqueeSelectOptions.startX, mouseX);\n const boxT = Math.min(this.marqueeSelectOptions.startY, mouseY);\n const boxB = Math.max(this.marqueeSelectOptions.startY, mouseY);\n if (activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\n // ORTHOGRAPHIC CAMERA\n const forwardDirection = activeCamera.getForwardRay().direction;\n const sideDirection = Vector3.Cross(forwardDirection, Vector3.Up());\n topNormal = Vector3.Cross(forwardDirection, sideDirection);\n leftNormal = sideDirection;\n rightNormal = sideDirection.scale(-1);\n bottomNormal = Vector3.Cross(sideDirection, forwardDirection);\n topOrigin = this.scene.createPickingRay(boxL, boxT, m, activeCamera).origin;\n leftOrigin = this.scene.createPickingRay(boxL, boxT, m, activeCamera).origin;\n rightOrigin = this.scene.createPickingRay(boxR, boxB, m, activeCamera).origin;\n bottomOrigin = this.scene.createPickingRay(boxR, boxB, m, activeCamera).origin;\n }\n else {\n // PERSPECTIVE CAMERA\n // Assemble the 4 planes of the marquee select\n const origin = ((_a = this.marqueeSelectOptions.startRay) === null || _a === void 0 ? void 0 : _a.origin) || activeCamera.position;\n topOrigin = origin;\n leftOrigin = origin;\n rightOrigin = origin;\n bottomOrigin = origin;\n const topLeft = this.scene.createPickingRay(boxL, boxT, m, activeCamera).direction;\n const topRight = this.scene.createPickingRay(boxR, boxT, m, activeCamera).direction;\n const botLeft = this.scene.createPickingRay(boxL, boxB, m, activeCamera).direction;\n const botRight = this.scene.createPickingRay(boxR, boxB, m, activeCamera).direction;\n if (topLeft && topRight && botLeft && botRight) {\n // Normals of the planes are equal to the cross product of the two vectors that define the plane\n topNormal = Vector3.Cross(topLeft, topRight);\n leftNormal = Vector3.Cross(botLeft, topLeft);\n rightNormal = Vector3.Cross(topRight, botRight);\n bottomNormal = Vector3.Cross(botRight, botLeft);\n }\n }\n if (topNormal && leftNormal && rightNormal && bottomNormal) {\n const mesh = this.marqueeSelectOptions.mesh;\n const fP = new Vector3();\n const fN = new Vector3();\n if (this.marqueeSelectOptions.mode === exports.eMarqueeSelectMode.Facets) {\n const faceInfo = this.meshFaceEngine.getMeshFaces(mesh);\n const transform = mesh.computeWorldMatrix();\n const n = faceInfo.faceCount;\n const res = [];\n for (let i = 0; i < n; i++) {\n Vector3.TransformCoordinatesFromFloatsToRef(faceInfo.facePositions[i * 3], faceInfo.facePositions[i * 3 + 1], faceInfo.facePositions[i * 3 + 2], transform, fP);\n if (this.marqueeSelectOptions.cullSelection) {\n Vector3.TransformCoordinatesFromFloatsToRef(faceInfo.faceNormals[i * 3], faceInfo.faceNormals[i * 3 + 1], faceInfo.faceNormals[i * 3 + 2], transform, fN);\n }\n if ((!this.marqueeSelectOptions.cullSelection || Vector3.Dot(this.cameraFacingDirection, fN) > 0) &&\n pointPlaneSizeToRef(topNormal, topOrigin, fP) >= 0 &&\n pointPlaneSizeToRef(leftNormal, leftOrigin, fP) >= 0 &&\n pointPlaneSizeToRef(rightNormal, rightOrigin, fP) >= 0 &&\n pointPlaneSizeToRef(bottomNormal, bottomOrigin, fP) >= 0) {\n res.push(i);\n }\n }\n this.onMarqueeSelect.next({\n ...args,\n altKey: args.event.altKey,\n vertexList: [],\n selectedFaces: res,\n });\n }\n else if (this.marqueeSelectOptions.mode === exports.eMarqueeSelectMode.Vertices) {\n const vertexPositions = mesh.getVerticesData(VertexBuffer.PositionKind);\n const transform = mesh.getWorldMatrix();\n const res = [];\n if (vertexPositions) {\n const n = vertexPositions.length / 3;\n for (let i = 0; i < n; i++) {\n fP.copyFromFloats(vertexPositions[i * 3], vertexPositions[i * 3 + 1], vertexPositions[i * 3 + 2]);\n Vector3.TransformCoordinatesToRef(fP, transform, fP);\n if ((!this.marqueeSelectOptions.cullSelection ||\n Vector3.Dot(this.cameraFacingDirection, mesh.getFacetNormal(i))) &&\n pointPlaneSizeToRef(topNormal, topOrigin, fP) >= 0 &&\n pointPlaneSizeToRef(leftNormal, leftOrigin, fP) >= 0 &&\n pointPlaneSizeToRef(rightNormal, rightOrigin, fP) >= 0 &&\n pointPlaneSizeToRef(bottomNormal, bottomOrigin, fP) >= 0) {\n res.push(i);\n }\n }\n mesh.getIndices();\n this.onMarqueeSelect.next({\n ...args,\n altKey: args.event.altKey,\n vertexList: res,\n selectedFaces: [],\n });\n }\n }\n }\n function pointPlaneSizeToRef(normal, origin, point) {\n return normal.x * (point.x - origin.x) + normal.y * (point.y - origin.y) + normal.z * (point.z - origin.z);\n }\n }\n getKb3dPointerArgs(p) {\n const args = {\n ...p,\n pickInfo: p.pickInfo,\n propagate: false,\n pointerType: p.event.pointerType,\n button: p.event.button,\n ctrlKey: p.event.ctrlKey || p.event.metaKey,\n shiftKey: p.event.shiftKey,\n canvasX: p.event.offsetX,\n canvasY: p.event.offsetY,\n getNormal: () => {\n if (p.pickInfo) {\n const normal = p.pickInfo.getNormal();\n return normal ? exports.KbVector.FromVec3(normal) : undefined;\n }\n return undefined;\n },\n };\n if (p.pickInfo) {\n this.fillKb3dPickInfo(p.pickInfo, args);\n }\n return args;\n }\n fillKb3dPickInfo(b, k) {\n k.u = b.bu;\n k.v = b.bv;\n if (b.pickedPoint)\n k.pickedPoint = exports.KbVector.FromVec3(b.pickedPoint);\n if (b.pickedMesh) {\n // recurse up the tree until we find something, or return undefined\n let pickedMesh = b.pickedMesh;\n k.targetNode = getByDynamicId(pickedMesh.id);\n while (!k.targetNode && pickedMesh.parent) {\n pickedMesh = pickedMesh.parent;\n k.targetNode = getByDynamicId(pickedMesh.id);\n }\n if (b.pickedPoint) {\n k.meshPoint = exports.KbVector.FromVec3(Vector3.TransformCoordinates(b.pickedPoint, b.pickedMesh.getWorldMatrix().clone().invert()));\n }\n }\n }\n getKeyboardArgs(k) {\n const event = k.event;\n const args = {\n ...k,\n key: event.key,\n keyCode: event.keyCode,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey || event.metaKey,\n shiftKey: event.shiftKey,\n repeat: event.repeat,\n };\n return args;\n }\n /**\n * scans the given node and ancestors to find the first node with a click handler and returns\n * the node and it's handlers\n */\n getNextNodeHandlers(node, handlerType) {\n //bubble up event, calling any handlers that have been applied to the nodes\n let handlers = new Array();\n while (node && node._manager) {\n const hmap = this.getHandlerMap(node, handlerType);\n handlers = hmap.getByKey(node);\n //if this is a scene node, then we also have to look in the parent scene manager for click events on this item\n if (instanceOf(node, Token.SceneNode) && node.isNested() && node._parent && node._parent._manager) {\n handlers.push(...this.getHandlerMap(node._parent, handlerType).getByKey(node));\n }\n if (handlers && handlers.length) {\n break;\n }\n node = node._parent;\n }\n return node ? { node, handlers } : undefined;\n }\n getHandlerMap(node, type) {\n const m = node._manager;\n if (type == exports.eHandler.click)\n return m.clickHandlers;\n else if (type == exports.eHandler.draggable)\n return m.draggables;\n else if (type == exports.eHandler.doubleClick)\n return m.doubleClickHandlers;\n else\n throw 'unrecognized handler type';\n }\n getNextClickHandlers(node) {\n return this.getNextNodeHandlers(node, exports.eHandler.click);\n }\n getNextDoubleClickHandlers(node) {\n return this.getNextNodeHandlers(node, exports.eHandler.doubleClick);\n }\n getNextDraggables(node) {\n return this.getNextNodeHandlers(node, exports.eHandler.draggable);\n }\n }\n\n const dbSubmeshes = new Map();\n /**\n * Gizmo that enables moving vertices on a mesh.\n */\n class KbFacetSelectGizmo extends KbGizmo {\n get attachedMesh() {\n return this.__attachedMesh;\n }\n set attachedMesh(mesh) {\n if (mesh && !(mesh instanceof Mesh)) {\n throw Error('facet select gizmo must be attached to a mesh with geometry');\n }\n this.__attachedMesh = mesh;\n }\n /**\n * Creates a PositionGizmo\n * @param camera The camera being used for the scene. Used for positioning the particles so they line up with the vertices\n * @param gizmoLayer The utility layer the gizmo will be added to\n */\n constructor(kbViewer, scene) {\n super(kbViewer.utilityLayer);\n this.kbViewer = kbViewer;\n this.scene = scene;\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onSelectionChange = new Observable$1();\n this.__attachedMesh = null;\n this.currentSelection = new Map();\n this.selectionsEnabled = false;\n this.highlightOpacity = 0.75;\n this.meshFaceEngine = new MeshFaceEngine(kbViewer);\n this.utilLayer = kbViewer.utilityLayer;\n this.attachedMesh = null;\n }\n attachTo(target) {\n this.__attachedNode = target;\n const aMesh = this.kbViewer.getRendererNode(target);\n if (!aMesh) {\n throw Error('Could not find mesh in scene to attach gizmo');\n }\n if (!(aMesh instanceof Mesh)) {\n throw Error('facet select gizmo must be attached to a mesh with geometry');\n }\n const mesh = aMesh;\n this.attachedMesh = mesh;\n // Clean up old marquee\n if (this.disposeSubject) {\n this.disposeSubject.next();\n this.disposeSubject.complete();\n }\n this.disposeSubject = new Subject();\n this.kbViewer.interaction.onFacetClick.pipe(takeUntil(this.disposeSubject)).subscribe(event => {\n if (!this.selectionsEnabled) {\n return;\n }\n event.selectedFaces.sort();\n if (event.ctrlKey) {\n // Add selections\n for (let i = 0; i < event.selectedFaces.length; i++) {\n this.currentSelection.set(event.selectedFaces[i], null);\n }\n }\n else if (event.altKey) {\n // Remove selections\n for (let i = 0; i < event.selectedFaces.length; i++) {\n this.currentSelection.delete(event.selectedFaces[i]);\n }\n }\n else {\n this.currentSelection.clear();\n for (let i = 0; i < event.selectedFaces.length; i++) {\n this.currentSelection.set(event.selectedFaces[i], null);\n }\n }\n const result = this.getVertexGroups(this.currentSelection.keys());\n this.visualizeSubmesh(mesh, result, exports.KbColor.Red());\n this.onSelectionChange.notifyObservers({ selectedFacets: result });\n });\n }\n updateGizmoPosition() {\n this.kbViewer.forceAndWaitForNextRender().then(() => {\n if (this.__attachedMesh) {\n const result = this.getVertexGroups(this.currentSelection.keys());\n this.visualizeSubmesh(this.__attachedMesh, result, exports.KbColor.Red(), true);\n }\n });\n }\n selectFacetGroups(selection) {\n selection.forEach(vertexGroup => {\n if (vertexGroup.startIndex === undefined || vertexGroup.endIndex === undefined) {\n throw Error('corrupt vertex group');\n }\n const startFacet = Math.round(vertexGroup.startIndex / 3);\n const endFacet = Math.ceil(vertexGroup.endIndex / 3);\n for (let i = startFacet; i < endFacet; i++) {\n this.currentSelection.set(i, null);\n }\n });\n this.updateGizmoPosition();\n }\n enableSelectionChange() {\n this.selectionsEnabled = true;\n if (this.__attachedNode) {\n this.kbViewer.interaction\n .enableMarqueeSelect(this.__attachedNode, exports.eMarqueeSelectMode.Facets)\n .pipe(takeUntil(this.disposeSubject))\n .subscribe(event => {\n if (this.selectionsEnabled &&\n this.__attachedMesh &&\n event.selectedFaces &&\n event.selectedFaces.length > 0) {\n if (event.ctrlKey) {\n // Add selections\n for (let i = 0; i < event.selectedFaces.length; i++) {\n this.currentSelection.set(event.selectedFaces[i], null);\n }\n }\n else if (event.altKey) {\n // Remove selections\n for (let i = 0; i < event.selectedFaces.length; i++) {\n this.currentSelection.delete(event.selectedFaces[i]);\n }\n }\n else {\n this.currentSelection.clear();\n for (let i = 0; i < event.selectedFaces.length; i++) {\n this.currentSelection.set(event.selectedFaces[i], null);\n }\n }\n const result = this.getVertexGroups(this.currentSelection.keys());\n this.visualizeSubmesh(this.__attachedMesh, result, exports.KbColor.Red());\n this.onSelectionChange.notifyObservers({ selectedFacets: result });\n }\n });\n }\n }\n disableSelectionChange() {\n this.selectionsEnabled = false;\n this.kbViewer.interaction.disableMarqueeSelect();\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n if (this.__attachedNode) {\n this.kbViewer.highlighter.remove(this.__attachedNode);\n }\n if (this.__attachedMesh) {\n const submeshInfo = dbSubmeshes.get(this.__attachedMesh.id);\n submeshInfo === null || submeshInfo === void 0 ? void 0 : submeshInfo.visualizationMesh.setEnabled(false);\n }\n }\n /**\n * CustomMeshes are not supported by this gizmo\n * @param mesh The mesh to replace the default mesh of the gizmo\n */\n setCustomMesh(mesh) {\n Logger.Error('Custom meshes are not supported on this gizmo.');\n }\n setBackfaceCulling(enable) {\n this.kbViewer.interaction.setSelectionCulling(enable);\n }\n setTolerance(tolerance) {\n this.kbViewer.interaction.setSelectionTolerance(tolerance);\n }\n expandSelection(tolerance) {\n if (this.attachedMesh instanceof Mesh) {\n const currentSelection = Array.from(this.currentSelection.keys());\n const newSelection = this.meshFaceEngine.expandSelection(currentSelection, this.attachedMesh, tolerance);\n for (let i = 0; i < newSelection.length; i++) {\n this.currentSelection.set(newSelection[i], null);\n }\n const result = this.getVertexGroups(this.currentSelection.keys());\n this.visualizeSubmesh(this.attachedMesh, result, exports.KbColor.Red());\n this.onSelectionChange.notifyObservers({ selectedFacets: result });\n }\n }\n setVisualization(opacity) {\n const submeshInfo = dbSubmeshes.get(this.attachedMesh.id);\n if (submeshInfo && submeshInfo.visualizationMesh.material instanceof MultiMaterial) {\n submeshInfo.highlightMaterial.alpha = opacity;\n }\n this.highlightOpacity = opacity;\n }\n getVertexGroups(faceIds) {\n const result = [];\n for (const faceId of faceIds) {\n if (result.length > 0 && result[result.length - 1].endIndex === faceId * 3) {\n result[result.length - 1].endIndex += 3;\n }\n else {\n result.push({\n startIndex: faceId * 3,\n endIndex: (faceId + 1) * 3,\n });\n }\n }\n return result;\n }\n visualizeSubmesh(node, vertices, color, geometryNeedsUpdate) {\n if (node instanceof Mesh && node.geometry) {\n let submeshInfo = dbSubmeshes.get(node.id);\n let highlightMaterial;\n const utilityLayerScene = this.utilLayer.utilityLayerScene;\n if (submeshInfo) {\n highlightMaterial = submeshInfo.highlightMaterial;\n }\n if (submeshInfo && geometryNeedsUpdate) {\n submeshInfo.visualizationMesh.dispose();\n submeshInfo = undefined;\n }\n if (!submeshInfo) {\n const multiMaterial = new MultiMaterial(`submeshVisualizationMat_${node.id}`, utilityLayerScene);\n const transparantMaterial = new StandardMaterial(`submeshVisualizationMat1_${node.id}`, utilityLayerScene);\n transparantMaterial.alpha = 0;\n multiMaterial.subMaterials.push(transparantMaterial);\n if (!highlightMaterial) {\n highlightMaterial = new StandardMaterial(`submeshVisualizationMat2_${node.id}`, utilityLayerScene);\n highlightMaterial.emissiveColor = (color === null || color === void 0 ? void 0 : color.toColor3()) || exports.KbColor.KbmaxOrange().toColor3();\n highlightMaterial.alpha = this.highlightOpacity;\n }\n multiMaterial.subMaterials.push(highlightMaterial);\n submeshInfo = {\n visualizationMesh: new Mesh(`submeshVisualization_${node.id}`, utilityLayerScene, null, node, true),\n highlightMaterial,\n vertices,\n };\n submeshInfo.visualizationMesh.makeGeometryUnique();\n submeshInfo.visualizationMesh.material = multiMaterial;\n submeshInfo.visualizationMesh.isPickable = false;\n dbSubmeshes.set(node.id, submeshInfo);\n }\n else {\n submeshInfo.visualizationMesh.setEnabled(true);\n }\n const vMesh = submeshInfo.visualizationMesh;\n const totalIndices = node.geometry.getTotalIndices();\n const totalVertices = node.geometry.getTotalVertices();\n vMesh.subMeshes = [];\n new SubMesh(0, 0, totalVertices, 0, totalIndices, vMesh);\n vertices.forEach(indexGroup => {\n if (indexGroup.startIndex === undefined || indexGroup.endIndex === undefined) {\n throw Error('Missing submesh information');\n }\n new SubMesh(1, 0, totalVertices, indexGroup.startIndex, indexGroup.endIndex - indexGroup.startIndex, vMesh);\n });\n }\n }\n }\n\n /**\n * Gizmo that enables dragging and rotating lights\n */\n class KbLightGizmo extends KbGizmo {\n attachTo(lightNode) {\n const light = this.kbViewer.getRendererNode(lightNode);\n if (!light) {\n console.warn('could not find light in scene');\n return;\n }\n this._attachedLight = lightNode;\n if (this.posGizmo) {\n this.posGizmo.dispose();\n }\n if (this.rotGizmo) {\n this.rotGizmo.dispose();\n }\n const _helperMesh = (this._helperMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene));\n _helperMesh.rotationQuaternion = Quaternion.Identity();\n const lightVisual = this.updatePreviewMesh(light);\n _helperMesh.addChild(lightVisual);\n }\n /**\n * Creates a PositionGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n */\n constructor(kbViewer, gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer) {\n super(gizmoLayer);\n this.kbViewer = kbViewer;\n this.attachedMesh = null;\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n if (this.posGizmo) {\n this.posGizmo.dispose();\n }\n if (this.rotGizmo) {\n this.rotGizmo.dispose();\n }\n if (this._helperMesh) {\n this._helperMesh.dispose();\n }\n if (this.lightPositionGizmo) {\n this.lightPositionGizmo.dispose();\n }\n delete this._attachedLight;\n }\n updateGizmoPosition(lightNode) {\n if (!lightNode) {\n return;\n }\n const light = this.kbViewer.getRendererNode(lightNode);\n if (light) {\n if (!this._attachedLight || lightNode._dynamicId !== this._attachedLight._dynamicId) {\n this.attachTo(lightNode);\n }\n else {\n this.updatePreviewMesh(light);\n }\n }\n }\n updatePreviewMesh(light) {\n const scene = this.gizmoLayer.utilityLayerScene;\n if (!this.lightPositionGizmo) {\n this.lightPositionGizmo = createLightVisualization(light, scene);\n }\n if (light instanceof SpotLight || light instanceof PointLight) {\n this.lightPositionGizmo.position = light.parent\n ? Vector3.TransformCoordinates(light.position, light.parent.computeWorldMatrix(true).clone().invert())\n : light.position;\n }\n return this.lightPositionGizmo;\n }\n }\n\n /**\n * Single axis drag gizmo\n */\n class KbAxisDragGizmo extends KbGizmo {\n /** @hidden */\n static _CreateArrow(scene, material) {\n const arrow = new TransformNode('arrow', scene);\n const cylinder = CylinderBuilder.CreateCylinder('cylinder', { diameterTop: 0, height: 0.075, diameterBottom: 0.0375, tessellation: 12 }, scene);\n const line = CylinderBuilder.CreateCylinder('cylinder', { diameterTop: 0.01, height: 0.275, diameterBottom: 0.01, tessellation: 6 }, scene);\n const drag = CylinderBuilder.CreateCylinder('cylinder', { diameterTop: 0.06, height: 0.4, diameterBottom: 0.06, tessellation: 6 }, scene);\n line.material = material;\n cylinder.parent = arrow;\n line.parent = arrow;\n drag.parent = arrow;\n // Position arrow pointing in its drag axis\n cylinder.material = material;\n cylinder.rotation.x = Math.PI / 2;\n cylinder.position.z += 0.3;\n line.position.z += 0.275 / 2;\n line.rotation.x = Math.PI / 2;\n drag.position.z += 0.4 / 2;\n drag.rotation = line.rotation;\n drag.visibility = 0;\n return arrow;\n }\n /** @hidden */\n static _CreateArrowInstance(scene, arrow) {\n const instance = new TransformNode('arrow', scene);\n for (const mesh of arrow.getChildMeshes()) {\n const childInstance = mesh.createInstance(mesh.name);\n childInstance.parent = instance;\n }\n return instance;\n }\n /**\n * Creates an AxisDragGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param dragAxis The axis which the gizmo will be able to drag on\n * @param color The color of the gizmo\n */\n constructor(dragAxis, color = Color3.Gray(), gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer) {\n super(gizmoLayer);\n this._pointerObserver = null;\n /**\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\n */\n this.snapDistance = 0;\n /**\n * Event that fires each time the gizmo snaps to a new location.\n * * snapDistance is the the change in distance\n */\n this.onSnapObservable = new Observable$1();\n this.updateObservable = new Observable$1();\n // Create Material\n const coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n coloredMaterial.emissiveColor = color;\n // coloredMaterial.diffuseColor = color;\n // coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\n // Build mesh on root node\n const arrow = KbAxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, coloredMaterial);\n arrow.lookAt(this._rootMesh.position.add(dragAxis));\n arrow.scaling.scaleInPlace(1 / 3);\n arrow.parent = this._rootMesh;\n let currentSnapDragDistance = 0;\n const tmpVector = new Vector3();\n const tmpSnapEvent = { snapDistance: 0 };\n // Add drag behavior to handle events when the gizmo is dragged\n this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });\n this.dragBehavior.moveAttached = false;\n this._rootMesh.addBehavior(this.dragBehavior);\n const localDelta = new Vector3();\n const tmpMatrix = new Matrix();\n this.dragBehavior.onDragObservable.add(event => {\n if (this.attachedMesh) {\n // Convert delta to local translation if it has a parent\n if (this.attachedMesh.parent) {\n this.attachedMesh.parent.computeWorldMatrix().invertToRef(tmpMatrix);\n tmpMatrix.setTranslationFromFloats(0, 0, 0);\n Vector3.TransformCoordinatesToRef(event.delta, tmpMatrix, localDelta);\n }\n else {\n localDelta.copyFrom(event.delta);\n }\n // Snapping logic\n if (this.snapDistance == 0) {\n this.attachedMesh.position.addInPlace(localDelta);\n this.updateObservable.notifyObservers({ delta: localDelta });\n }\n else {\n currentSnapDragDistance += event.dragDistance;\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\n const dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\n localDelta.normalizeToRef(tmpVector);\n tmpVector.scaleInPlace(this.snapDistance * dragSteps);\n this.attachedMesh.position.addInPlace(tmpVector);\n tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;\n this.updateObservable.notifyObservers({ delta: tmpVector });\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\n }\n }\n }\n });\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\n if (this._customMeshSet) {\n return;\n }\n const isHovered = pointerInfo.pickInfo &&\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\n const material = isHovered ? hoverMaterial : coloredMaterial;\n this._rootMesh.getChildMeshes().forEach(m => {\n m.material = material;\n if (m.color) {\n m.color = material.diffuseColor;\n }\n });\n });\n }\n _attachedMeshChanged(value) {\n if (this.dragBehavior) {\n this.dragBehavior.enabled = value ? true : false;\n }\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n this.onSnapObservable.clear();\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\n this.dragBehavior.detach();\n super.dispose();\n }\n }\n\n /**\n * Gizmo that enables dragging a mesh along 3 axis\n */\n class KbPositionGizmo extends KbGizmo {\n attachTo(target, positionSpace, orientGizmo) {\n if (orientGizmo) {\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = false;\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = false;\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = false;\n this.xGizmo._rootMesh.rotationQuaternion = orientGizmo;\n this.yGizmo._rootMesh.rotationQuaternion = orientGizmo;\n this.zGizmo._rootMesh.rotationQuaternion = orientGizmo;\n }\n if (!positionSpace && target instanceof exports.SpaceNode && target._parent) {\n positionSpace = target._parent;\n }\n if (positionSpace) {\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\n }\n if (target instanceof exports.SpaceNode) {\n this._attachedSpaceNode = target;\n this._updateGizmoPosition();\n }\n else {\n this._updateGizmoPosition(target);\n }\n }\n updateGizmoPosition(changeTarget) {\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\n this.kbViewer.onNextFrame(() => {\n this._updateGizmoPosition(changeTarget);\n });\n }\n _updateGizmoPosition(changeTarget) {\n var _a;\n const positionSpaceTransform = (_a = this._positionSpace) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n if (changeTarget) {\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, changeTarget, positionSpaceTransform);\n }\n else if (this._attachedSpaceNode) {\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, this._attachedSpaceNode, positionSpaceTransform);\n }\n super.updateGizmoPosition();\n }\n get attachedMesh() {\n if (this.xGizmo) {\n return this.xGizmo.attachedMesh;\n }\n else if (this.yGizmo) {\n return this.yGizmo.attachedMesh;\n }\n else {\n return this.zGizmo.attachedMesh;\n }\n }\n set attachedMesh(mesh) {\n if (this.xGizmo) {\n this.xGizmo.attachedMesh = mesh;\n }\n if (this.yGizmo) {\n this.yGizmo.attachedMesh = mesh;\n }\n if (this.zGizmo) {\n this.zGizmo.attachedMesh = mesh;\n }\n if (mesh) {\n this._rootMesh.rotationQuaternion = mesh.rotationQuaternion\n ? mesh.rotationQuaternion\n : mesh.rotation.toQuaternion();\n this._rootMesh.position = mesh.position;\n this._rootMesh.setPivotPoint(mesh.getPivotPoint(), Space.WORLD);\n }\n }\n get visibility() {\n return this.xGizmo.visibility;\n }\n set visibility(visibility) {\n if (this.xGizmo) {\n this.xGizmo.visibility = visibility;\n this.yGizmo.visibility = visibility;\n this.zGizmo.visibility = visibility;\n }\n }\n /**\n * Creates a PositionGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n */\n constructor(kbViewer, gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, axisVisibility) {\n super(gizmoLayer);\n this.kbViewer = kbViewer;\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onDragStartObservable = new Observable$1();\n /** Fires an event while any of it's sub gizmos are dragged */\n this.onDragObservable = new Observable$1();\n /** Fires an event when any of it's sub gizmos are released from dragging */\n this.onDragEndObservable = new Observable$1();\n this.positionChange = Vector3.Zero();\n let activeGizmos = [];\n if (axisVisibility) {\n if (axisVisibility[0]) {\n this.xGizmo = new KbAxisDragGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[0];\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[0];\n activeGizmos.push(this.xGizmo);\n }\n if (axisVisibility[1]) {\n this.yGizmo = new KbAxisDragGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[1];\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[1];\n activeGizmos.push(this.yGizmo);\n }\n if (axisVisibility[2]) {\n this.zGizmo = new KbAxisDragGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[2];\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[2];\n activeGizmos.push(this.zGizmo);\n }\n }\n else {\n this.xGizmo = new KbAxisDragGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);\n this.yGizmo = new KbAxisDragGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);\n this.zGizmo = new KbAxisDragGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = true;\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = true;\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = true;\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n activeGizmos = [this.xGizmo, this.yGizmo, this.zGizmo];\n }\n // Relay drag events\n activeGizmos.forEach(gizmo => {\n gizmo.dragBehavior.onDragStartObservable.add(() => {\n this.onDragStartObservable.notifyObservers();\n this.positionChange.setAll(0);\n });\n gizmo.updateObservable.add(event => {\n // transform the rotation to be in local space, the gizmos return global space movements\n const transform = new Matrix();\n this.attachedMesh.computeWorldMatrix(true).invertToRef(transform);\n transform.setTranslation(Vector3.Zero());\n const { delta } = event;\n const result = Vector3.TransformCoordinates(delta, transform);\n // squish floating point errors that look gross in the output\n if (Math.abs(result.x) < 0.00000001)\n result.x = 0;\n if (Math.abs(result.y) < 0.00000001)\n result.y = 0;\n if (Math.abs(result.z) < 0.00000001)\n result.z = 0;\n this.positionChange.addInPlace(result);\n this.onDragObservable.notifyObservers({ delta: result });\n });\n gizmo.dragBehavior.onDragEndObservable.add(() => {\n this.onDragEndObservable.notifyObservers({ delta: this.positionChange });\n });\n });\n this.attachedMesh = null;\n }\n /**\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\n */\n set snapDistance(value) {\n if (this.xGizmo) {\n this.xGizmo.snapDistance = value;\n }\n if (this.yGizmo) {\n this.yGizmo.snapDistance = value;\n }\n if (this.zGizmo) {\n this.zGizmo.snapDistance = value;\n }\n }\n get snapDistance() {\n if (this.xGizmo) {\n return this.xGizmo.snapDistance;\n }\n else if (this.yGizmo) {\n return this.yGizmo.snapDistance;\n }\n else {\n return this.zGizmo.snapDistance;\n }\n }\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n set scaleRatio(value) {\n if (this.xGizmo) {\n this.xGizmo.scaleRatio = value;\n }\n if (this.yGizmo) {\n this.yGizmo.scaleRatio = value;\n }\n if (this.zGizmo) {\n this.zGizmo.scaleRatio = value;\n }\n }\n get scaleRatio() {\n if (this.xGizmo) {\n return this.xGizmo.scaleRatio;\n }\n else if (this.yGizmo) {\n return this.yGizmo.scaleRatio;\n }\n else {\n return this.zGizmo.scaleRatio;\n }\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n if (this.xGizmo) {\n this.xGizmo.dispose();\n }\n if (this.yGizmo) {\n this.yGizmo.dispose();\n }\n if (this.zGizmo) {\n this.zGizmo.dispose();\n }\n this.onDragStartObservable.clear();\n this.onDragEndObservable.clear();\n if (this.attachedMesh && this.attachedMesh.name === AUTO_MESH_NAME) {\n this.attachedMesh.dispose();\n }\n }\n /**\n * CustomMeshes are not supported by this gizmo\n * @param mesh The mesh to replace the default mesh of the gizmo\n */\n setCustomMesh(mesh) {\n Logger.Error('Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.yGizmo, gizmo.zGizmo)');\n }\n }\n\n const tessellation$1 = 32;\n /**\n * Gizmo that enables rotating a mesh along 3 axis\n */\n class KbRotationGizmo extends KbGizmo {\n attachTo(target, positionSpace, placementOffset) {\n if (!positionSpace && target instanceof exports.SpaceNode && target._parent) {\n positionSpace = target._parent;\n }\n if (positionSpace) {\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\n }\n if (target instanceof exports.SpaceNode) {\n this._attachedSpaceNode = target;\n this._updateGizmoPosition();\n }\n else {\n this._updateGizmoPosition(target, placementOffset);\n }\n }\n updateGizmoPosition(changeTarget, placementOffset) {\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\n this.kbViewer.onNextFrame(() => {\n this._updateGizmoPosition(changeTarget, placementOffset);\n });\n }\n _updateGizmoPosition(changeTarget, placementOffset) {\n var _a, _b;\n const positionSpaceTransform = (_a = this._positionSpace) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n if (changeTarget) {\n // If target is a vector, then we want to rotate it as a direction, so set the gizmo position to the origin to calculations are done from there\n // But store the position as the offset because we want the gizmo itself to be visually placed on the position space origin\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, placementOffset || exports.KbVector.Zero(), positionSpaceTransform);\n const corr = rotationToVector(changeTarget.toVec3(), Vector3.Up());\n this.gizmoOffset = exports.KbVector.FromVec3(this.attachedMesh.position);\n this.attachedMesh.position = Vector3.Zero();\n (_b = this.attachedMesh.rotationQuaternion) === null || _b === void 0 ? void 0 : _b.multiplyInPlace(corr);\n this.attachedMesh.computeWorldMatrix(true);\n }\n else if (this._attachedSpaceNode) {\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, this._attachedSpaceNode.position.add(this._attachedSpaceNode.pivot), positionSpaceTransform);\n let currentRotation;\n // Rotation gizmo should be rotated to match the current rotation if the target is a node\n if (this._attachedSpaceNode.useEuler) {\n currentRotation = this._attachedSpaceNode.eulerRotation\n .toVec3()\n .scale(Math.PI / 180)\n .toQuaternion();\n }\n else {\n currentRotation = rotationToVector(this._attachedSpaceNode.rotationAxis.toVec3());\n }\n this.attachedMesh.rotationQuaternion = (positionSpaceTransform\n ? Quaternion.FromRotationMatrix(positionSpaceTransform.getRotationMatrix())\n : Quaternion.Identity()).multiply(currentRotation);\n }\n this.gizmoOffset && this.attachedMesh.position.addInPlace(this.gizmoOffset.toVec3());\n super.updateGizmoPosition();\n }\n get attachedMesh() {\n return (this.xGizmo || this.yGizmo || this.zGizmo).attachedMesh;\n }\n set attachedMesh(mesh) {\n if (this.xGizmo) {\n this.xGizmo.attachedMesh = mesh;\n }\n if (this.yGizmo) {\n this.yGizmo.attachedMesh = mesh;\n }\n if (this.zGizmo) {\n this.zGizmo.attachedMesh = mesh;\n }\n if (mesh) {\n this._rootMesh.setPivotPoint(mesh.getPivotPoint(), Space.WORLD);\n }\n }\n /**\n * Creates a RotationGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param tessellation Amount of tessellation to be used when creating rotation circles\n */\n constructor(kbViewer, gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, axes, axisVisibility) {\n super(gizmoLayer);\n this.kbViewer = kbViewer;\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onDragStartObservable = new Observable$1();\n /** Fires an event when any of it's sub gizmos are released from dragging */\n this.onDragObservable = new Observable$1();\n this.onDragEndObservable = new Observable$1();\n let activeGizmos = [];\n if (axisVisibility) {\n if (axisVisibility[0]) {\n this.xGizmo = new KbPlaneRotationGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer, tessellation$1);\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[0];\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[0];\n activeGizmos.push(this.xGizmo);\n }\n if (axisVisibility[1]) {\n this.yGizmo = new KbPlaneRotationGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer, tessellation$1);\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[1];\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[1];\n activeGizmos.push(this.yGizmo);\n }\n if (axisVisibility[2]) {\n this.zGizmo = new KbPlaneRotationGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer, tessellation$1);\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[2];\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[2];\n activeGizmos.push(this.zGizmo);\n }\n }\n else {\n this.updateGizmoRotationToMatchAttachedMesh = true;\n if (!axes || axes.x) {\n this.xGizmo = new KbPlaneRotationGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer, tessellation$1);\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = true;\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n }\n if (!axes || axes.y) {\n this.yGizmo = new KbPlaneRotationGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer, tessellation$1);\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = true;\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n }\n if (!axes || axes.z) {\n this.zGizmo = new KbPlaneRotationGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer, tessellation$1);\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = true;\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = true;\n }\n activeGizmos = [this.xGizmo, this.yGizmo, this.zGizmo];\n }\n this.rotationChange = Quaternion.Identity();\n // Relay drag events\n activeGizmos.forEach(gizmo => {\n if (gizmo) {\n gizmo.dragBehavior.onDragStartObservable.add(() => {\n this.onDragStartObservable.notifyObservers();\n this.rotationChange = Quaternion.Identity();\n });\n gizmo.updateObservable.add(event => {\n this.rotationChange.multiplyInPlace(event.delta);\n this.onDragObservable.notifyObservers({ delta: event.delta });\n });\n gizmo.dragBehavior.onDragEndObservable.add(() => {\n this.onDragEndObservable.notifyObservers({ delta: this.rotationChange });\n });\n }\n });\n this.attachedMesh = null;\n }\n /**\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\n */\n set snapDistance(value) {\n if (this.xGizmo) {\n this.xGizmo.snapDistance = value;\n }\n if (this.yGizmo) {\n this.yGizmo.snapDistance = value;\n }\n if (this.zGizmo) {\n this.zGizmo.snapDistance = value;\n }\n }\n get snapDistance() {\n return (this.xGizmo || this.yGizmo || this.zGizmo).snapDistance;\n }\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n set scaleRatio(value) {\n if (this.xGizmo) {\n this.xGizmo.scaleRatio = value;\n }\n if (this.yGizmo) {\n this.yGizmo.scaleRatio = value;\n }\n if (this.zGizmo) {\n this.zGizmo.scaleRatio = value;\n }\n }\n get scaleRatio() {\n return (this.xGizmo || this.yGizmo || this.zGizmo).scaleRatio;\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n if (this.xGizmo) {\n this.xGizmo.dispose();\n }\n if (this.yGizmo) {\n this.yGizmo.dispose();\n }\n if (this.zGizmo) {\n this.zGizmo.dispose();\n }\n this.onDragStartObservable.clear();\n this.onDragEndObservable.clear();\n }\n /**\n * CustomMeshes are not supported by this gizmo\n * @param mesh The mesh to replace the default mesh of the gizmo\n */\n setCustomMesh(mesh) {\n Logger.Error('Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.yGizmo, gizmo.zGizmo)');\n }\n }\n\n /**\n * Single axis scale gizmo\n */\n class KbAxisScaleGizmo extends KbGizmo {\n /**\n * Creates an AxisScaleGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n * @param dragAxis The axis which the gizmo will be able to scale on\n * @param color The color of the gizmo\n */\n constructor(dragAxis, color = Color3.Gray(), gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer) {\n super(gizmoLayer);\n this._pointerObserver = null;\n /**\n * Scale distance in babylon units that the gizmo will snap to when dragged (Default: 0)\n */\n this.snapDistance = 0;\n /**\n * Event that fires each time the gizmo snaps to a new location.\n * * snapDistance is the the change in distance\n */\n this.onSnapObservable = new Observable$1();\n this.updateObservable = new Observable$1();\n /**\n * If the scaling operation should be done on all axis (default: false)\n */\n this.uniformScaling = false;\n // Create Material\n this._coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n this._coloredMaterial.disableLighting = true;\n this._coloredMaterial.emissiveColor = color;\n // this._coloredMaterial.diffuseColor = color;\n // this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\n hoverMaterial.disableLighting = true;\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\n // Build mesh on root node\n const arrow = new AbstractMesh('', gizmoLayer.utilityLayerScene);\n const arrowMesh = BoxBuilder.CreateBox('yPosMesh', { size: 0.4 }, gizmoLayer.utilityLayerScene);\n const arrowTail = CylinderBuilder.CreateCylinder('cylinder', { diameterTop: 0.005, height: 0.275, diameterBottom: 0.005, tessellation: 96 }, gizmoLayer.utilityLayerScene);\n arrowTail.material = this._coloredMaterial;\n arrow.addChild(arrowMesh);\n arrow.addChild(arrowTail);\n // Position arrow pointing in its drag axis\n arrowMesh.scaling.scaleInPlace(0.1);\n arrowMesh.material = this._coloredMaterial;\n arrowMesh.rotation.x = Math.PI / 2;\n arrowMesh.position.z += 0.3;\n arrowTail.position.z += 0.275 / 2;\n arrowTail.rotation.x = Math.PI / 2;\n arrow.lookAt(this._rootMesh.position.add(dragAxis));\n this._rootMesh.addChild(arrow);\n arrow.scaling.scaleInPlace(1 / 3);\n // Add drag behavior to handle events when the gizmo is dragged\n this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });\n this.dragBehavior.moveAttached = false;\n this._rootMesh.addBehavior(this.dragBehavior);\n let currentSnapDragDistance = 0;\n const tmpVector = new Vector3();\n const tmpSnapEvent = { snapDistance: 0 };\n this.dragBehavior.onDragObservable.add(event => {\n if (this.attachedMesh) {\n // Drag strength is modified by the scale of the gizmo (eg. for small objects like boombox the strength will be increased to match the behavior of larger objects)\n const dragStrength = event.dragDistance * ((this.scaleRatio * 8) / this._rootMesh.scaling.length());\n // Snapping logic\n let snapped = false;\n let dragSteps = 0;\n if (this.uniformScaling) {\n this.attachedMesh.scaling.normalizeToRef(tmpVector);\n if (tmpVector.y < 0) {\n tmpVector.scaleInPlace(-1);\n }\n }\n else {\n tmpVector.copyFrom(dragAxis);\n }\n if (this.snapDistance == 0) {\n tmpVector.scaleToRef(dragStrength, tmpVector);\n }\n else {\n currentSnapDragDistance += dragStrength;\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\n dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\n if (currentSnapDragDistance < 0) {\n dragSteps *= -1;\n }\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\n tmpVector.scaleToRef(this.snapDistance * dragSteps, tmpVector);\n snapped = true;\n }\n else {\n tmpVector.scaleInPlace(0);\n }\n }\n this.attachedMesh.scaling.addInPlace(tmpVector);\n this.updateObservable.notifyObservers({ delta: tmpVector });\n if (snapped) {\n tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\n }\n }\n });\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\n if (this._customMeshSet) {\n return;\n }\n const isHovered = pointerInfo.pickInfo &&\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\n const material = isHovered ? hoverMaterial : this._coloredMaterial;\n this._rootMesh.getChildMeshes().forEach(m => {\n m.material = material;\n if (m.color) {\n m.color = material.diffuseColor;\n }\n });\n });\n // var light = gizmoLayer._getSharedGizmoLight();\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes());\n }\n _attachedMeshChanged(value) {\n if (this.dragBehavior) {\n this.dragBehavior.enabled = value ? true : false;\n }\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n this.onSnapObservable.clear();\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\n this.dragBehavior.detach();\n super.dispose();\n }\n /**\n * Disposes and replaces the current meshes in the gizmo with the specified mesh\n * @param mesh The mesh to replace the default mesh of the gizmo\n * @param useGizmoMaterial If the gizmo's default material should be used (default: false)\n */\n setCustomMesh(mesh, useGizmoMaterial = false) {\n super.setCustomMesh(mesh);\n if (useGizmoMaterial) {\n this._rootMesh.getChildMeshes().forEach(m => {\n m.material = this._coloredMaterial;\n if (m.color) {\n m.color = this._coloredMaterial.diffuseColor;\n }\n });\n this._customMeshSet = false;\n }\n }\n }\n\n /**\n * Gizmo that enables scaling a mesh along 3 axis\n */\n class KbScaleGizmo extends KbGizmo {\n attachTo(target, positionSpace) {\n if (!positionSpace && target instanceof exports.SpaceNode && target._parent) {\n positionSpace = target._parent;\n }\n if (positionSpace) {\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\n }\n if (target instanceof exports.SpaceNode) {\n this._attachedSpaceNode = target;\n this._updateGizmoPosition();\n }\n else {\n this._updateGizmoPosition(target);\n }\n }\n updateGizmoPosition(changeTarget) {\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\n this.kbViewer.onNextFrame(() => {\n this._updateGizmoPosition(changeTarget);\n });\n }\n _updateGizmoPosition(changeTarget) {\n var _a;\n const positionSpaceTransform = (_a = this._positionSpace) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n if (changeTarget) {\n // If target is a vector, then we want to rotate it as a direction, so set the gizmo position to the origin to calculations are done from there\n // But store the position as the offset because we want the gizmo itself to be visually placed on the position space origin\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, changeTarget, positionSpaceTransform);\n this.gizmoOffset = exports.KbVector.FromVec3(this.attachedMesh.position);\n }\n else if (this._attachedSpaceNode) {\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, this._attachedSpaceNode, positionSpaceTransform);\n // Put the gizmo in the same position as the pivot, in world space\n this.attachedMesh.position.addInPlace(this._attachedSpaceNode.pivot.toVec3());\n }\n super.updateGizmoPosition();\n }\n get attachedMesh() {\n return this.xGizmo.attachedMesh;\n }\n set attachedMesh(mesh) {\n if (this.xGizmo) {\n this.xGizmo.attachedMesh = mesh;\n this.yGizmo.attachedMesh = mesh;\n this.zGizmo.attachedMesh = mesh;\n this.uniformScaleGizmo.attachedMesh = mesh;\n }\n }\n /**\n * Creates a ScaleGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n */\n constructor(kbViewer, gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer) {\n super(gizmoLayer);\n this.kbViewer = kbViewer;\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onDragStartObservable = new Observable$1();\n /** Fires an event while any of it's sub gizmos are dragged */\n this.onDragObservable = new Observable$1();\n /** Fires an event when any of it's sub gizmos are released from dragging */\n this.onDragEndObservable = new Observable$1();\n this.scaleChange = Vector3.Zero();\n this.xGizmo = new KbAxisScaleGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);\n this.yGizmo = new KbAxisScaleGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);\n this.zGizmo = new KbAxisScaleGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);\n // Create uniform scale gizmo\n this.uniformScaleGizmo = new KbAxisScaleGizmo(new Vector3(0, 1, 0), Color3.Yellow().scale(0.5), gizmoLayer);\n this.uniformScaleGizmo.updateGizmoRotationToMatchAttachedMesh = false;\n this.uniformScaleGizmo.uniformScaling = true;\n const uniformScalingMesh = PolyhedronBuilder.CreatePolyhedron('', { type: 1 }, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);\n uniformScalingMesh.scaling.scaleInPlace(0.03);\n uniformScalingMesh.visibility = 0;\n const octahedron = PolyhedronBuilder.CreatePolyhedron('', { type: 1 }, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);\n octahedron.scaling.scaleInPlace(0.007);\n uniformScalingMesh.addChild(octahedron);\n this.uniformScaleGizmo.setCustomMesh(uniformScalingMesh, true);\n // var light = gizmoLayer._getSharedGizmoLight();\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(octahedron);\n // Relay drag events\n [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach(gizmo => {\n gizmo.dragBehavior.onDragStartObservable.add(() => {\n this.onDragStartObservable.notifyObservers();\n this.scaleChange.setAll(0);\n });\n gizmo.updateObservable.add(event => {\n this.scaleChange.addInPlace(event.delta);\n this.onDragObservable.notifyObservers({ delta: event.delta });\n });\n gizmo.dragBehavior.onDragEndObservable.add(() => {\n this.onDragEndObservable.notifyObservers({ delta: this.scaleChange });\n });\n });\n this.attachedMesh = null;\n }\n set updateGizmoRotationToMatchAttachedMesh(value) {\n if (!value) {\n Logger.Warn('Setting updateGizmoRotationToMatchAttachedMesh = false on scaling gizmo is not supported.');\n }\n if (this.xGizmo) {\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;\n }\n }\n get updateGizmoRotationToMatchAttachedMesh() {\n return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;\n }\n /**\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\n */\n set snapDistance(value) {\n if (this.xGizmo) {\n this.xGizmo.snapDistance = value;\n this.yGizmo.snapDistance = value;\n this.zGizmo.snapDistance = value;\n this.uniformScaleGizmo.snapDistance = value;\n }\n }\n get snapDistance() {\n return this.xGizmo.snapDistance;\n }\n /**\n * Ratio for the scale of the gizmo (Default: 1)\n */\n set scaleRatio(value) {\n if (this.xGizmo) {\n this.xGizmo.scaleRatio = value;\n this.yGizmo.scaleRatio = value;\n this.zGizmo.scaleRatio = value;\n this.uniformScaleGizmo.scaleRatio = value;\n }\n }\n get scaleRatio() {\n return this.xGizmo.scaleRatio;\n }\n /**\n * Disposes of the gizmo\n */\n dispose() {\n this.xGizmo.dispose();\n this.yGizmo.dispose();\n this.zGizmo.dispose();\n this.uniformScaleGizmo.dispose();\n this.onDragStartObservable.clear();\n this.onDragEndObservable.clear();\n }\n }\n\n /** Class used to store color4 gradient */\n class ColorGradient {\n /**\n * Creates a new color4 gradient\n * @param gradient gets or sets the gradient value (between 0 and 1)\n * @param color1 gets or sets first associated color\n * @param color2 gets or sets first second color\n */\n constructor(\n /**\n * Gets or sets the gradient value (between 0 and 1)\n */\n gradient, \n /**\n * Gets or sets first associated color\n */\n color1, \n /**\n * Gets or sets second associated color\n */\n color2) {\n this.gradient = gradient;\n this.color1 = color1;\n this.color2 = color2;\n }\n /**\n * Will get a color picked randomly between color1 and color2.\n * If color2 is undefined then color1 will be used\n * @param result defines the target Color4 to store the result in\n */\n getColorToRef(result) {\n if (!this.color2) {\n result.copyFrom(this.color1);\n return;\n }\n Color4.LerpToRef(this.color1, this.color2, Math.random(), result);\n }\n }\n /** Class used to store color 3 gradient */\n class Color3Gradient {\n /**\n * Creates a new color3 gradient\n * @param gradient gets or sets the gradient value (between 0 and 1)\n * @param color gets or sets associated color\n */\n constructor(\n /**\n * Gets or sets the gradient value (between 0 and 1)\n */\n gradient, \n /**\n * Gets or sets the associated color\n */\n color) {\n this.gradient = gradient;\n this.color = color;\n }\n }\n /** Class used to store factor gradient */\n class FactorGradient {\n /**\n * Creates a new factor gradient\n * @param gradient gets or sets the gradient value (between 0 and 1)\n * @param factor1 gets or sets first associated factor\n * @param factor2 gets or sets second associated factor\n */\n constructor(\n /**\n * Gets or sets the gradient value (between 0 and 1)\n */\n gradient, \n /**\n * Gets or sets first associated factor\n */\n factor1, \n /**\n * Gets or sets second associated factor\n */\n factor2) {\n this.gradient = gradient;\n this.factor1 = factor1;\n this.factor2 = factor2;\n }\n /**\n * Will get a number picked randomly between factor1 and factor2.\n * If factor2 is undefined then factor1 will be used\n * @returns the picked number\n */\n getFactor() {\n if (this.factor2 === undefined || this.factor2 === this.factor1) {\n return this.factor1;\n }\n return this.factor1 + (this.factor2 - this.factor1) * Math.random();\n }\n }\n /**\n * Helper used to simplify some generic gradient tasks\n */\n class GradientHelper {\n /**\n * Gets the current gradient from an array of IValueGradient\n * @param ratio defines the current ratio to get\n * @param gradients defines the array of IValueGradient\n * @param updateFunc defines the callback function used to get the final value from the selected gradients\n */\n static GetCurrentGradient(ratio, gradients, updateFunc) {\n // Use last index if over\n if (gradients[0].gradient > ratio) {\n updateFunc(gradients[0], gradients[0], 1.0);\n return;\n }\n for (let gradientIndex = 0; gradientIndex < gradients.length - 1; gradientIndex++) {\n const currentGradient = gradients[gradientIndex];\n const nextGradient = gradients[gradientIndex + 1];\n if (ratio >= currentGradient.gradient && ratio <= nextGradient.gradient) {\n const scale = (ratio - currentGradient.gradient) / (nextGradient.gradient - currentGradient.gradient);\n updateFunc(currentGradient, nextGradient, scale);\n return;\n }\n }\n // Use last index if over\n const lastIndex = gradients.length - 1;\n updateFunc(gradients[lastIndex], gradients[lastIndex], 1.0);\n }\n }\n\n /**\n * A particle represents one of the element emitted by a particle system.\n * This is mainly define by its coordinates, direction, velocity and age.\n */\n class Particle {\n /**\n * Creates a new instance Particle\n * @param particleSystem the particle system the particle belongs to\n */\n constructor(\n /**\n * The particle system the particle belongs to.\n */\n particleSystem) {\n this.particleSystem = particleSystem;\n /**\n * The world position of the particle in the scene.\n */\n this.position = Vector3.Zero();\n /**\n * The world direction of the particle in the scene.\n */\n this.direction = Vector3.Zero();\n /**\n * The color of the particle.\n */\n this.color = new Color4(0, 0, 0, 0);\n /**\n * The color change of the particle per step.\n */\n this.colorStep = new Color4(0, 0, 0, 0);\n /**\n * Defines how long will the life of the particle be.\n */\n this.lifeTime = 1.0;\n /**\n * The current age of the particle.\n */\n this.age = 0;\n /**\n * The current size of the particle.\n */\n this.size = 0;\n /**\n * The current scale of the particle.\n */\n this.scale = new Vector2(1, 1);\n /**\n * The current angle of the particle.\n */\n this.angle = 0;\n /**\n * Defines how fast is the angle changing.\n */\n this.angularSpeed = 0;\n /**\n * Defines the cell index used by the particle to be rendered from a sprite.\n */\n this.cellIndex = 0;\n /** @internal */\n this._attachedSubEmitters = null;\n /** @internal */\n this._currentColor1 = new Color4(0, 0, 0, 0);\n /** @internal */\n this._currentColor2 = new Color4(0, 0, 0, 0);\n /** @internal */\n this._currentSize1 = 0;\n /** @internal */\n this._currentSize2 = 0;\n /** @internal */\n this._currentAngularSpeed1 = 0;\n /** @internal */\n this._currentAngularSpeed2 = 0;\n /** @internal */\n this._currentVelocity1 = 0;\n /** @internal */\n this._currentVelocity2 = 0;\n /** @internal */\n this._currentLimitVelocity1 = 0;\n /** @internal */\n this._currentLimitVelocity2 = 0;\n /** @internal */\n this._currentDrag1 = 0;\n /** @internal */\n this._currentDrag2 = 0;\n this.id = Particle._Count++;\n if (!this.particleSystem.isAnimationSheetEnabled) {\n return;\n }\n this._updateCellInfoFromSystem();\n }\n _updateCellInfoFromSystem() {\n this.cellIndex = this.particleSystem.startSpriteCellID;\n }\n /**\n * Defines how the sprite cell index is updated for the particle\n */\n updateCellIndex() {\n let offsetAge = this.age;\n let changeSpeed = this.particleSystem.spriteCellChangeSpeed;\n if (this.particleSystem.spriteRandomStartCell) {\n if (this._randomCellOffset === undefined) {\n this._randomCellOffset = Math.random() * this.lifeTime;\n }\n if (changeSpeed === 0) {\n // Special case when speed = 0 meaning we want to stay on initial cell\n changeSpeed = 1;\n offsetAge = this._randomCellOffset;\n }\n else {\n offsetAge += this._randomCellOffset;\n }\n }\n const dist = this._initialEndSpriteCellID - this._initialStartSpriteCellID;\n let ratio;\n if (this._initialSpriteCellLoop) {\n ratio = Scalar.Clamp(((offsetAge * changeSpeed) % this.lifeTime) / this.lifeTime);\n }\n else {\n ratio = Scalar.Clamp((offsetAge * changeSpeed) / this.lifeTime);\n }\n this.cellIndex = (this._initialStartSpriteCellID + ratio * dist) | 0;\n }\n /**\n * @internal\n */\n _inheritParticleInfoToSubEmitter(subEmitter) {\n if (subEmitter.particleSystem.emitter.position) {\n const emitterMesh = subEmitter.particleSystem.emitter;\n emitterMesh.position.copyFrom(this.position);\n if (subEmitter.inheritDirection) {\n const temp = TmpVectors.Vector3[0];\n this.direction.normalizeToRef(temp);\n emitterMesh.setDirection(temp, 0, Math.PI / 2);\n }\n }\n else {\n const emitterPosition = subEmitter.particleSystem.emitter;\n emitterPosition.copyFrom(this.position);\n }\n // Set inheritedVelocityOffset to be used when new particles are created\n this.direction.scaleToRef(subEmitter.inheritedVelocityAmount / 2, TmpVectors.Vector3[0]);\n subEmitter.particleSystem._inheritedVelocityOffset.copyFrom(TmpVectors.Vector3[0]);\n }\n /** @internal */\n _inheritParticleInfoToSubEmitters() {\n if (this._attachedSubEmitters && this._attachedSubEmitters.length > 0) {\n this._attachedSubEmitters.forEach((subEmitter) => {\n this._inheritParticleInfoToSubEmitter(subEmitter);\n });\n }\n }\n /** @internal */\n _reset() {\n this.age = 0;\n this.id = Particle._Count++;\n this._currentColorGradient = null;\n this._currentSizeGradient = null;\n this._currentAngularSpeedGradient = null;\n this._currentVelocityGradient = null;\n this._currentLimitVelocityGradient = null;\n this._currentDragGradient = null;\n this.cellIndex = this.particleSystem.startSpriteCellID;\n this._randomCellOffset = undefined;\n }\n /**\n * Copy the properties of particle to another one.\n * @param other the particle to copy the information to.\n */\n copyTo(other) {\n other.position.copyFrom(this.position);\n if (this._initialDirection) {\n if (other._initialDirection) {\n other._initialDirection.copyFrom(this._initialDirection);\n }\n else {\n other._initialDirection = this._initialDirection.clone();\n }\n }\n else {\n other._initialDirection = null;\n }\n other.direction.copyFrom(this.direction);\n if (this._localPosition) {\n if (other._localPosition) {\n other._localPosition.copyFrom(this._localPosition);\n }\n else {\n other._localPosition = this._localPosition.clone();\n }\n }\n other.color.copyFrom(this.color);\n other.colorStep.copyFrom(this.colorStep);\n other.lifeTime = this.lifeTime;\n other.age = this.age;\n other._randomCellOffset = this._randomCellOffset;\n other.size = this.size;\n other.scale.copyFrom(this.scale);\n other.angle = this.angle;\n other.angularSpeed = this.angularSpeed;\n other.particleSystem = this.particleSystem;\n other.cellIndex = this.cellIndex;\n other.id = this.id;\n other._attachedSubEmitters = this._attachedSubEmitters;\n if (this._currentColorGradient) {\n other._currentColorGradient = this._currentColorGradient;\n other._currentColor1.copyFrom(this._currentColor1);\n other._currentColor2.copyFrom(this._currentColor2);\n }\n if (this._currentSizeGradient) {\n other._currentSizeGradient = this._currentSizeGradient;\n other._currentSize1 = this._currentSize1;\n other._currentSize2 = this._currentSize2;\n }\n if (this._currentAngularSpeedGradient) {\n other._currentAngularSpeedGradient = this._currentAngularSpeedGradient;\n other._currentAngularSpeed1 = this._currentAngularSpeed1;\n other._currentAngularSpeed2 = this._currentAngularSpeed2;\n }\n if (this._currentVelocityGradient) {\n other._currentVelocityGradient = this._currentVelocityGradient;\n other._currentVelocity1 = this._currentVelocity1;\n other._currentVelocity2 = this._currentVelocity2;\n }\n if (this._currentLimitVelocityGradient) {\n other._currentLimitVelocityGradient = this._currentLimitVelocityGradient;\n other._currentLimitVelocity1 = this._currentLimitVelocity1;\n other._currentLimitVelocity2 = this._currentLimitVelocity2;\n }\n if (this._currentDragGradient) {\n other._currentDragGradient = this._currentDragGradient;\n other._currentDrag1 = this._currentDrag1;\n other._currentDrag2 = this._currentDrag2;\n }\n if (this.particleSystem.isAnimationSheetEnabled) {\n other._initialStartSpriteCellID = this._initialStartSpriteCellID;\n other._initialEndSpriteCellID = this._initialEndSpriteCellID;\n other._initialSpriteCellLoop = this._initialSpriteCellLoop;\n }\n if (this.particleSystem.useRampGradients) {\n if (other.remapData && this.remapData) {\n other.remapData.copyFrom(this.remapData);\n }\n else {\n other.remapData = new Vector4(0, 0, 0, 0);\n }\n }\n if (this._randomNoiseCoordinates1) {\n if (other._randomNoiseCoordinates1) {\n other._randomNoiseCoordinates1.copyFrom(this._randomNoiseCoordinates1);\n other._randomNoiseCoordinates2.copyFrom(this._randomNoiseCoordinates2);\n }\n else {\n other._randomNoiseCoordinates1 = this._randomNoiseCoordinates1.clone();\n other._randomNoiseCoordinates2 = this._randomNoiseCoordinates2.clone();\n }\n }\n }\n }\n Particle._Count = 0;\n\n /**\n * Type of sub emitter\n */\n var SubEmitterType;\n (function (SubEmitterType) {\n /**\n * Attached to the particle over it's lifetime\n */\n SubEmitterType[SubEmitterType[\"ATTACHED\"] = 0] = \"ATTACHED\";\n /**\n * Created when the particle dies\n */\n SubEmitterType[SubEmitterType[\"END\"] = 1] = \"END\";\n })(SubEmitterType || (SubEmitterType = {}));\n /**\n * Sub emitter class used to emit particles from an existing particle\n */\n class SubEmitter {\n /**\n * Creates a sub emitter\n * @param particleSystem the particle system to be used by the sub emitter\n */\n constructor(\n /**\n * the particle system to be used by the sub emitter\n */\n particleSystem) {\n this.particleSystem = particleSystem;\n /**\n * Type of the submitter (Default: END)\n */\n this.type = SubEmitterType.END;\n /**\n * If the particle should inherit the direction from the particle it's attached to. (+Y will face the direction the particle is moving) (Default: false)\n * Note: This only is supported when using an emitter of type Mesh\n */\n this.inheritDirection = false;\n /**\n * How much of the attached particles speed should be added to the sub emitted particle (default: 0)\n */\n this.inheritedVelocityAmount = 0;\n // Create mesh as emitter to support rotation\n if (!particleSystem.emitter || !particleSystem.emitter.dispose) {\n const internalClass = GetClass(\"BABYLON.AbstractMesh\");\n particleSystem.emitter = new internalClass(\"SubemitterSystemEmitter\", particleSystem.getScene());\n particleSystem._disposeEmitterOnDispose = true;\n }\n }\n /**\n * Clones the sub emitter\n * @returns the cloned sub emitter\n */\n clone() {\n // Clone particle system\n let emitter = this.particleSystem.emitter;\n if (!emitter) {\n emitter = new Vector3();\n }\n else if (emitter instanceof Vector3) {\n emitter = emitter.clone();\n }\n else if (emitter.getClassName().indexOf(\"Mesh\") !== -1) {\n const internalClass = GetClass(\"BABYLON.Mesh\");\n emitter = new internalClass(\"\", emitter.getScene());\n emitter.isVisible = false;\n }\n const clone = new SubEmitter(this.particleSystem.clone(this.particleSystem.name, emitter));\n // Clone properties\n clone.particleSystem.name += \"Clone\";\n clone.type = this.type;\n clone.inheritDirection = this.inheritDirection;\n clone.inheritedVelocityAmount = this.inheritedVelocityAmount;\n clone.particleSystem._disposeEmitterOnDispose = true;\n clone.particleSystem.disposeOnStop = true;\n return clone;\n }\n /**\n * Serialize current object to a JSON object\n * @param serializeTexture defines if the texture must be serialized as well\n * @returns the serialized object\n */\n serialize(serializeTexture = false) {\n const serializationObject = {};\n serializationObject.type = this.type;\n serializationObject.inheritDirection = this.inheritDirection;\n serializationObject.inheritedVelocityAmount = this.inheritedVelocityAmount;\n serializationObject.particleSystem = this.particleSystem.serialize(serializeTexture);\n return serializationObject;\n }\n /**\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n static _ParseParticleSystem(system, sceneOrEngine, rootUrl, doNotStart = false) {\n throw _WarnImport(\"ParseParticle\");\n }\n /**\n * Creates a new SubEmitter from a serialized JSON version\n * @param serializationObject defines the JSON object to read from\n * @param sceneOrEngine defines the hosting scene or the hosting engine\n * @param rootUrl defines the rootUrl for data loading\n * @returns a new SubEmitter\n */\n static Parse(serializationObject, sceneOrEngine, rootUrl) {\n const system = serializationObject.particleSystem;\n const subEmitter = new SubEmitter(SubEmitter._ParseParticleSystem(system, sceneOrEngine, rootUrl, true));\n subEmitter.type = serializationObject.type;\n subEmitter.inheritDirection = serializationObject.inheritDirection;\n subEmitter.inheritedVelocityAmount = serializationObject.inheritedVelocityAmount;\n subEmitter.particleSystem._isSubEmitter = true;\n return subEmitter;\n }\n /** Release associated resources */\n dispose() {\n this.particleSystem.dispose();\n }\n }\n\n // Do not edit.\n const name$2I = \"particlesPixelShader\";\n const shader$2I = `#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nvarying vec2 vUV;varying vec4 vColor;uniform vec4 textureMask;uniform sampler2D diffuseSampler;\n#include\n#include\n#include\n#include\n#include\n#ifdef RAMPGRADIENT\nvarying vec4 remapRanges;uniform sampler2D rampSampler;\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec4 textureColor=texture2D(diffuseSampler,vUV);vec4 baseColor=(textureColor*textureMask+(vec4(1.,1.,1.,1.)-textureMask))*vColor;\n#ifdef RAMPGRADIENT\nfloat alpha=baseColor.a;float remappedColorIndex=clamp((alpha-remapRanges.x)/remapRanges.y,0.0,1.0);vec4 rampColor=texture2D(rampSampler,vec2(1.0-remappedColorIndex,0.));baseColor.rgb*=rampColor.rgb;float finalAlpha=baseColor.a;baseColor.a=clamp((alpha*rampColor.a-remapRanges.z)/remapRanges.w,0.0,1.0);\n#endif\n#ifdef BLENDMULTIPLYMODE\nfloat sourceAlpha=vColor.a*textureColor.a;baseColor.rgb=baseColor.rgb*sourceAlpha+vec3(1.0)*(1.0-sourceAlpha);\n#endif\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\nbaseColor.rgb=toLinearSpace(baseColor.rgb);\n#else\n#ifdef IMAGEPROCESSING\nbaseColor.rgb=toLinearSpace(baseColor.rgb);baseColor=applyImageProcessing(baseColor);\n#endif\n#endif\ngl_FragColor=baseColor;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2I] = shader$2I;\n\n // Do not edit.\n const name$2J = \"particlesVertexShader\";\n const shader$2J = `attribute vec3 position;attribute vec4 color;attribute float angle;attribute vec2 size;\n#ifdef ANIMATESHEET\nattribute float cellIndex;\n#endif\n#ifndef BILLBOARD\nattribute vec3 direction;\n#endif\n#ifdef BILLBOARDSTRETCHED\nattribute vec3 direction;\n#endif\n#ifdef RAMPGRADIENT\nattribute vec4 remapData;\n#endif\nattribute vec2 offset;uniform mat4 view;uniform mat4 projection;uniform vec2 translationPivot;\n#ifdef ANIMATESHEET\nuniform vec3 particlesInfos; \n#endif\nvarying vec2 vUV;varying vec4 vColor;varying vec3 vPositionW;\n#ifdef RAMPGRADIENT\nvarying vec4 remapRanges;\n#endif\n#if defined(BILLBOARD) && !defined(BILLBOARDY) && !defined(BILLBOARDSTRETCHED)\nuniform mat4 invView;\n#endif\n#include\n#include\n#ifdef BILLBOARD\nuniform vec3 eyePosition;\n#endif\nvec3 rotate(vec3 yaxis,vec3 rotatedCorner) {vec3 xaxis=normalize(cross(vec3(0.,1.0,0.),yaxis));vec3 zaxis=normalize(cross(yaxis,xaxis));vec3 row0=vec3(xaxis.x,xaxis.y,xaxis.z);vec3 row1=vec3(yaxis.x,yaxis.y,yaxis.z);vec3 row2=vec3(zaxis.x,zaxis.y,zaxis.z);mat3 rotMatrix= mat3(row0,row1,row2);vec3 alignedCorner=rotMatrix*rotatedCorner;return position+alignedCorner;}\n#ifdef BILLBOARDSTRETCHED\nvec3 rotateAlign(vec3 toCamera,vec3 rotatedCorner) {vec3 normalizedToCamera=normalize(toCamera);vec3 normalizedCrossDirToCamera=normalize(cross(normalize(direction),normalizedToCamera));vec3 row0=vec3(normalizedCrossDirToCamera.x,normalizedCrossDirToCamera.y,normalizedCrossDirToCamera.z);vec3 row2=vec3(normalizedToCamera.x,normalizedToCamera.y,normalizedToCamera.z);\n#ifdef BILLBOARDSTRETCHED_LOCAL\nvec3 row1=direction;\n#else\nvec3 crossProduct=normalize(cross(normalizedToCamera,normalizedCrossDirToCamera));vec3 row1=vec3(crossProduct.x,crossProduct.y,crossProduct.z);\n#endif\nmat3 rotMatrix= mat3(row0,row1,row2);vec3 alignedCorner=rotMatrix*rotatedCorner;return position+alignedCorner;}\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec2 cornerPos;cornerPos=(vec2(offset.x-0.5,offset.y -0.5)-translationPivot)*size+translationPivot;\n#ifdef BILLBOARD\nvec3 rotatedCorner;\n#ifdef BILLBOARDY\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.y=0.;vec3 yaxis=position-eyePosition;yaxis.y=0.;vPositionW=rotate(normalize(yaxis),rotatedCorner);vec3 viewPos=(view*vec4(vPositionW,1.0)).xyz;\n#elif defined(BILLBOARDSTRETCHED)\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.z=0.;vec3 toCamera=position-eyePosition;vPositionW=rotateAlign(toCamera,rotatedCorner);vec3 viewPos=(view*vec4(vPositionW,1.0)).xyz;\n#else\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.z=0.;vec3 viewPos=(view*vec4(position,1.0)).xyz+rotatedCorner;vPositionW=(invView*vec4(viewPos,1)).xyz;\n#endif\n#ifdef RAMPGRADIENT\nremapRanges=remapData;\n#endif\ngl_Position=projection*vec4(viewPos,1.0);\n#else\nvec3 rotatedCorner;rotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.y=0.;vec3 yaxis=normalize(direction);vPositionW=rotate(yaxis,rotatedCorner);gl_Position=projection*view*vec4(vPositionW,1.0);\n#endif\nvColor=color;\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex*particlesInfos.z);float columnOffset=cellIndex-rowOffset/particlesInfos.z;vec2 uvScale=particlesInfos.xy;vec2 uvOffset=vec2(offset.x ,1.0-offset.y);vUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else\nvUV=offset;\n#endif\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)\nvec4 worldPos=vec4(vPositionW,1.0);\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n // Sideeffect\n ShaderStore.ShadersStore[name$2J] = shader$2J;\n\n /**\n * This represents a particle system in Babylon.\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\n * Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.\n * @example https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro\n */\n class ParticleSystem extends BaseParticleSystem {\n /**\n * Sets a callback that will be triggered when the system is disposed\n */\n set onDispose(callback) {\n if (this._onDisposeObserver) {\n this.onDisposeObservable.remove(this._onDisposeObserver);\n }\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\n }\n /** Gets or sets a boolean indicating that ramp gradients must be used\n * @see https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro#ramp-gradients\n */\n get useRampGradients() {\n return this._useRampGradients;\n }\n set useRampGradients(value) {\n if (this._useRampGradients === value) {\n return;\n }\n this._useRampGradients = value;\n this._resetEffect();\n }\n //end of Sub-emitter\n /**\n * Gets the current list of active particles\n */\n get particles() {\n return this._particles;\n }\n /**\n * Gets the number of particles active at the same time.\n * @returns The number of active particles.\n */\n getActiveCount() {\n return this._particles.length;\n }\n /**\n * Returns the string \"ParticleSystem\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"ParticleSystem\";\n }\n /**\n * Gets a boolean indicating that the system is stopping\n * @returns true if the system is currently stopping\n */\n isStopping() {\n return this._stopped && this.isAlive();\n }\n /**\n * Gets the custom effect used to render the particles\n * @param blendMode Blend mode for which the effect should be retrieved\n * @returns The effect\n */\n getCustomEffect(blendMode = 0) {\n var _a, _b;\n return (_b = (_a = this._customWrappers[blendMode]) === null || _a === void 0 ? void 0 : _a.effect) !== null && _b !== void 0 ? _b : this._customWrappers[0].effect;\n }\n _getCustomDrawWrapper(blendMode = 0) {\n var _a;\n return (_a = this._customWrappers[blendMode]) !== null && _a !== void 0 ? _a : this._customWrappers[0];\n }\n /**\n * Sets the custom effect used to render the particles\n * @param effect The effect to set\n * @param blendMode Blend mode for which the effect should be set\n */\n setCustomEffect(effect, blendMode = 0) {\n this._customWrappers[blendMode] = new DrawWrapper(this._engine);\n this._customWrappers[blendMode].effect = effect;\n if (this._customWrappers[blendMode].drawContext) {\n this._customWrappers[blendMode].drawContext.useInstancing = this._useInstancing;\n }\n }\n /**\n * Observable that will be called just before the particles are drawn\n */\n get onBeforeDrawParticlesObservable() {\n if (!this._onBeforeDrawParticlesObservable) {\n this._onBeforeDrawParticlesObservable = new Observable$1();\n }\n return this._onBeforeDrawParticlesObservable;\n }\n /**\n * Gets the name of the particle vertex shader\n */\n get vertexShaderName() {\n return \"particles\";\n }\n /**\n * Gets the vertex buffers used by the particle system\n */\n get vertexBuffers() {\n return this._vertexBuffers;\n }\n /**\n * Gets the index buffer used by the particle system (or null if no index buffer is used (if _useInstancing=true))\n */\n get indexBuffer() {\n return this._indexBuffer;\n }\n /**\n * Instantiates a particle system.\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\n * @param name The name of the particle system\n * @param capacity The max number of particles alive at the same time\n * @param sceneOrEngine The scene the particle system belongs to or the engine to use if no scene\n * @param customEffect a custom effect used to change the way particles are rendered by default\n * @param isAnimationSheetEnabled Must be true if using a spritesheet to animate the particles texture\n * @param epsilon Offset used to render the particles\n */\n constructor(name, capacity, sceneOrEngine, customEffect = null, isAnimationSheetEnabled = false, epsilon = 0.01) {\n super(name);\n this._emitterInverseWorldMatrix = Matrix.Identity();\n /**\n * @internal\n */\n this._inheritedVelocityOffset = new Vector3();\n /**\n * An event triggered when the system is disposed\n */\n this.onDisposeObservable = new Observable$1();\n /**\n * An event triggered when the system is stopped\n */\n this.onStoppedObservable = new Observable$1();\n this._particles = new Array();\n this._stockParticles = new Array();\n this._newPartsExcess = 0;\n this._vertexBuffers = {};\n this._scaledColorStep = new Color4(0, 0, 0, 0);\n this._colorDiff = new Color4(0, 0, 0, 0);\n this._scaledDirection = Vector3.Zero();\n this._scaledGravity = Vector3.Zero();\n this._currentRenderId = -1;\n this._useInstancing = false;\n this._started = false;\n this._stopped = false;\n this._actualFrame = 0;\n /** @internal */\n this._currentEmitRate1 = 0;\n /** @internal */\n this._currentEmitRate2 = 0;\n /** @internal */\n this._currentStartSize1 = 0;\n /** @internal */\n this._currentStartSize2 = 0;\n /** Indicates that the update of particles is done in the animate function */\n this.updateInAnimate = true;\n this._rawTextureWidth = 256;\n this._useRampGradients = false;\n /**\n * @internal\n * If the particle systems emitter should be disposed when the particle system is disposed\n */\n this._disposeEmitterOnDispose = false;\n /**\n * Specifies if the particles are updated in emitter local space or world space\n */\n this.isLocal = false;\n /** Indicates that the particle system is CPU based */\n this.isGPU = false;\n /** @internal */\n this._onBeforeDrawParticlesObservable = null;\n // start of sub system methods\n /**\n * \"Recycles\" one of the particle by copying it back to the \"stock\" of particles and removing it from the active list.\n * Its lifetime will start back at 0.\n * @param particle\n */\n this.recycleParticle = (particle) => {\n // move particle from activeParticle list to stock particles\n const lastParticle = this._particles.pop();\n if (lastParticle !== particle) {\n lastParticle.copyTo(particle);\n }\n this._stockParticles.push(lastParticle);\n };\n this._createParticle = () => {\n let particle;\n if (this._stockParticles.length !== 0) {\n particle = this._stockParticles.pop();\n particle._reset();\n }\n else {\n particle = new Particle(this);\n }\n // Attach emitters\n if (this._subEmitters && this._subEmitters.length > 0) {\n const subEmitters = this._subEmitters[Math.floor(Math.random() * this._subEmitters.length)];\n particle._attachedSubEmitters = [];\n subEmitters.forEach((subEmitter) => {\n if (subEmitter.type === SubEmitterType.ATTACHED) {\n const newEmitter = subEmitter.clone();\n particle._attachedSubEmitters.push(newEmitter);\n newEmitter.particleSystem.start();\n }\n });\n }\n return particle;\n };\n this._emitFromParticle = (particle) => {\n if (!this._subEmitters || this._subEmitters.length === 0) {\n return;\n }\n const templateIndex = Math.floor(Math.random() * this._subEmitters.length);\n this._subEmitters[templateIndex].forEach((subEmitter) => {\n if (subEmitter.type === SubEmitterType.END) {\n const subSystem = subEmitter.clone();\n particle._inheritParticleInfoToSubEmitter(subSystem);\n subSystem.particleSystem._rootParticleSystem = this;\n this.activeSubSystems.push(subSystem.particleSystem);\n subSystem.particleSystem.start();\n }\n });\n };\n this._capacity = capacity;\n this._epsilon = epsilon;\n this._isAnimationSheetEnabled = isAnimationSheetEnabled;\n if (!sceneOrEngine || sceneOrEngine.getClassName() === \"Scene\") {\n this._scene = sceneOrEngine || EngineStore.LastCreatedScene;\n this._engine = this._scene.getEngine();\n this.uniqueId = this._scene.getUniqueId();\n this._scene.particleSystems.push(this);\n }\n else {\n this._engine = sceneOrEngine;\n this.defaultProjectionMatrix = Matrix.PerspectiveFovLH(0.8, 1, 0.1, 100, this._engine.isNDCHalfZRange);\n }\n if (this._engine.getCaps().vertexArrayObject) {\n this._vertexArrayObject = null;\n }\n // Setup the default processing configuration to the scene.\n this._attachImageProcessingConfiguration(null);\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this._customWrappers = { 0: new DrawWrapper(this._engine) };\n this._customWrappers[0].effect = customEffect;\n this._drawWrappers = [];\n this._useInstancing = this._engine.getCaps().instancedArrays;\n this._createIndexBuffer();\n this._createVertexBuffers();\n // Default emitter type\n this.particleEmitterType = new BoxParticleEmitter();\n let noiseTextureData = null;\n // Update\n this.updateFunction = (particles) => {\n var _a;\n let noiseTextureSize = null;\n if (this.noiseTexture) {\n // We need to get texture data back to CPU\n noiseTextureSize = this.noiseTexture.getSize();\n (_a = this.noiseTexture.getContent()) === null || _a === void 0 ? void 0 : _a.then((data) => {\n noiseTextureData = data;\n });\n }\n const sameParticleArray = particles === this._particles;\n for (let index = 0; index < particles.length; index++) {\n const particle = particles[index];\n let scaledUpdateSpeed = this._scaledUpdateSpeed;\n const previousAge = particle.age;\n particle.age += scaledUpdateSpeed;\n // Evaluate step to death\n if (particle.age > particle.lifeTime) {\n const diff = particle.age - previousAge;\n const oldDiff = particle.lifeTime - previousAge;\n scaledUpdateSpeed = (oldDiff * scaledUpdateSpeed) / diff;\n particle.age = particle.lifeTime;\n }\n const ratio = particle.age / particle.lifeTime;\n // Color\n if (this._colorGradients && this._colorGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._colorGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== particle._currentColorGradient) {\n particle._currentColor1.copyFrom(particle._currentColor2);\n nextGradient.getColorToRef(particle._currentColor2);\n particle._currentColorGradient = currentGradient;\n }\n Color4.LerpToRef(particle._currentColor1, particle._currentColor2, scale, particle.color);\n });\n }\n else {\n particle.colorStep.scaleToRef(scaledUpdateSpeed, this._scaledColorStep);\n particle.color.addInPlace(this._scaledColorStep);\n if (particle.color.a < 0) {\n particle.color.a = 0;\n }\n }\n // Angular speed\n if (this._angularSpeedGradients && this._angularSpeedGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._angularSpeedGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== particle._currentAngularSpeedGradient) {\n particle._currentAngularSpeed1 = particle._currentAngularSpeed2;\n particle._currentAngularSpeed2 = nextGradient.getFactor();\n particle._currentAngularSpeedGradient = currentGradient;\n }\n particle.angularSpeed = Scalar.Lerp(particle._currentAngularSpeed1, particle._currentAngularSpeed2, scale);\n });\n }\n particle.angle += particle.angularSpeed * scaledUpdateSpeed;\n // Direction\n let directionScale = scaledUpdateSpeed;\n /// Velocity\n if (this._velocityGradients && this._velocityGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._velocityGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== particle._currentVelocityGradient) {\n particle._currentVelocity1 = particle._currentVelocity2;\n particle._currentVelocity2 = nextGradient.getFactor();\n particle._currentVelocityGradient = currentGradient;\n }\n directionScale *= Scalar.Lerp(particle._currentVelocity1, particle._currentVelocity2, scale);\n });\n }\n particle.direction.scaleToRef(directionScale, this._scaledDirection);\n /// Limit velocity\n if (this._limitVelocityGradients && this._limitVelocityGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._limitVelocityGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== particle._currentLimitVelocityGradient) {\n particle._currentLimitVelocity1 = particle._currentLimitVelocity2;\n particle._currentLimitVelocity2 = nextGradient.getFactor();\n particle._currentLimitVelocityGradient = currentGradient;\n }\n const limitVelocity = Scalar.Lerp(particle._currentLimitVelocity1, particle._currentLimitVelocity2, scale);\n const currentVelocity = particle.direction.length();\n if (currentVelocity > limitVelocity) {\n particle.direction.scaleInPlace(this.limitVelocityDamping);\n }\n });\n }\n /// Drag\n if (this._dragGradients && this._dragGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._dragGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== particle._currentDragGradient) {\n particle._currentDrag1 = particle._currentDrag2;\n particle._currentDrag2 = nextGradient.getFactor();\n particle._currentDragGradient = currentGradient;\n }\n const drag = Scalar.Lerp(particle._currentDrag1, particle._currentDrag2, scale);\n this._scaledDirection.scaleInPlace(1.0 - drag);\n });\n }\n if (this.isLocal && particle._localPosition) {\n particle._localPosition.addInPlace(this._scaledDirection);\n Vector3.TransformCoordinatesToRef(particle._localPosition, this._emitterWorldMatrix, particle.position);\n }\n else {\n particle.position.addInPlace(this._scaledDirection);\n }\n // Noise\n if (noiseTextureData && noiseTextureSize && particle._randomNoiseCoordinates1) {\n const fetchedColorR = this._fetchR(particle._randomNoiseCoordinates1.x, particle._randomNoiseCoordinates1.y, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);\n const fetchedColorG = this._fetchR(particle._randomNoiseCoordinates1.z, particle._randomNoiseCoordinates2.x, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);\n const fetchedColorB = this._fetchR(particle._randomNoiseCoordinates2.y, particle._randomNoiseCoordinates2.z, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);\n const force = TmpVectors.Vector3[0];\n const scaledForce = TmpVectors.Vector3[1];\n force.copyFromFloats((2 * fetchedColorR - 1) * this.noiseStrength.x, (2 * fetchedColorG - 1) * this.noiseStrength.y, (2 * fetchedColorB - 1) * this.noiseStrength.z);\n force.scaleToRef(scaledUpdateSpeed, scaledForce);\n particle.direction.addInPlace(scaledForce);\n }\n // Gravity\n this.gravity.scaleToRef(scaledUpdateSpeed, this._scaledGravity);\n particle.direction.addInPlace(this._scaledGravity);\n // Size\n if (this._sizeGradients && this._sizeGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._sizeGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== particle._currentSizeGradient) {\n particle._currentSize1 = particle._currentSize2;\n particle._currentSize2 = nextGradient.getFactor();\n particle._currentSizeGradient = currentGradient;\n }\n particle.size = Scalar.Lerp(particle._currentSize1, particle._currentSize2, scale);\n });\n }\n // Remap data\n if (this._useRampGradients) {\n if (this._colorRemapGradients && this._colorRemapGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._colorRemapGradients, (currentGradient, nextGradient, scale) => {\n const min = Scalar.Lerp(currentGradient.factor1, nextGradient.factor1, scale);\n const max = Scalar.Lerp(currentGradient.factor2, nextGradient.factor2, scale);\n particle.remapData.x = min;\n particle.remapData.y = max - min;\n });\n }\n if (this._alphaRemapGradients && this._alphaRemapGradients.length > 0) {\n GradientHelper.GetCurrentGradient(ratio, this._alphaRemapGradients, (currentGradient, nextGradient, scale) => {\n const min = Scalar.Lerp(currentGradient.factor1, nextGradient.factor1, scale);\n const max = Scalar.Lerp(currentGradient.factor2, nextGradient.factor2, scale);\n particle.remapData.z = min;\n particle.remapData.w = max - min;\n });\n }\n }\n if (this._isAnimationSheetEnabled) {\n particle.updateCellIndex();\n }\n // Update the position of the attached sub-emitters to match their attached particle\n particle._inheritParticleInfoToSubEmitters();\n if (particle.age >= particle.lifeTime) {\n // Recycle by swapping with last particle\n this._emitFromParticle(particle);\n if (particle._attachedSubEmitters) {\n particle._attachedSubEmitters.forEach((subEmitter) => {\n subEmitter.particleSystem.disposeOnStop = true;\n subEmitter.particleSystem.stop();\n });\n particle._attachedSubEmitters = null;\n }\n this.recycleParticle(particle);\n if (sameParticleArray) {\n index--;\n }\n continue;\n }\n }\n };\n }\n _addFactorGradient(factorGradients, gradient, factor, factor2) {\n const newGradient = new FactorGradient(gradient, factor, factor2);\n factorGradients.push(newGradient);\n factorGradients.sort((a, b) => {\n if (a.gradient < b.gradient) {\n return -1;\n }\n else if (a.gradient > b.gradient) {\n return 1;\n }\n return 0;\n });\n }\n _removeFactorGradient(factorGradients, gradient) {\n if (!factorGradients) {\n return;\n }\n let index = 0;\n for (const factorGradient of factorGradients) {\n if (factorGradient.gradient === gradient) {\n factorGradients.splice(index, 1);\n break;\n }\n index++;\n }\n }\n /**\n * Adds a new life time gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the life time factor to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addLifeTimeGradient(gradient, factor, factor2) {\n if (!this._lifeTimeGradients) {\n this._lifeTimeGradients = [];\n }\n this._addFactorGradient(this._lifeTimeGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific life time gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeLifeTimeGradient(gradient) {\n this._removeFactorGradient(this._lifeTimeGradients, gradient);\n return this;\n }\n /**\n * Adds a new size gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the size factor to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addSizeGradient(gradient, factor, factor2) {\n if (!this._sizeGradients) {\n this._sizeGradients = [];\n }\n this._addFactorGradient(this._sizeGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific size gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeSizeGradient(gradient) {\n this._removeFactorGradient(this._sizeGradients, gradient);\n return this;\n }\n /**\n * Adds a new color remap gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param min defines the color remap minimal range\n * @param max defines the color remap maximal range\n * @returns the current particle system\n */\n addColorRemapGradient(gradient, min, max) {\n if (!this._colorRemapGradients) {\n this._colorRemapGradients = [];\n }\n this._addFactorGradient(this._colorRemapGradients, gradient, min, max);\n return this;\n }\n /**\n * Remove a specific color remap gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeColorRemapGradient(gradient) {\n this._removeFactorGradient(this._colorRemapGradients, gradient);\n return this;\n }\n /**\n * Adds a new alpha remap gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param min defines the alpha remap minimal range\n * @param max defines the alpha remap maximal range\n * @returns the current particle system\n */\n addAlphaRemapGradient(gradient, min, max) {\n if (!this._alphaRemapGradients) {\n this._alphaRemapGradients = [];\n }\n this._addFactorGradient(this._alphaRemapGradients, gradient, min, max);\n return this;\n }\n /**\n * Remove a specific alpha remap gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeAlphaRemapGradient(gradient) {\n this._removeFactorGradient(this._alphaRemapGradients, gradient);\n return this;\n }\n /**\n * Adds a new angular speed gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the angular speed to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addAngularSpeedGradient(gradient, factor, factor2) {\n if (!this._angularSpeedGradients) {\n this._angularSpeedGradients = [];\n }\n this._addFactorGradient(this._angularSpeedGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific angular speed gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeAngularSpeedGradient(gradient) {\n this._removeFactorGradient(this._angularSpeedGradients, gradient);\n return this;\n }\n /**\n * Adds a new velocity gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the velocity to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addVelocityGradient(gradient, factor, factor2) {\n if (!this._velocityGradients) {\n this._velocityGradients = [];\n }\n this._addFactorGradient(this._velocityGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific velocity gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeVelocityGradient(gradient) {\n this._removeFactorGradient(this._velocityGradients, gradient);\n return this;\n }\n /**\n * Adds a new limit velocity gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the limit velocity value to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addLimitVelocityGradient(gradient, factor, factor2) {\n if (!this._limitVelocityGradients) {\n this._limitVelocityGradients = [];\n }\n this._addFactorGradient(this._limitVelocityGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific limit velocity gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeLimitVelocityGradient(gradient) {\n this._removeFactorGradient(this._limitVelocityGradients, gradient);\n return this;\n }\n /**\n * Adds a new drag gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the drag value to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addDragGradient(gradient, factor, factor2) {\n if (!this._dragGradients) {\n this._dragGradients = [];\n }\n this._addFactorGradient(this._dragGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific drag gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeDragGradient(gradient) {\n this._removeFactorGradient(this._dragGradients, gradient);\n return this;\n }\n /**\n * Adds a new emit rate gradient (please note that this will only work if you set the targetStopDuration property)\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the emit rate value to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addEmitRateGradient(gradient, factor, factor2) {\n if (!this._emitRateGradients) {\n this._emitRateGradients = [];\n }\n this._addFactorGradient(this._emitRateGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific emit rate gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeEmitRateGradient(gradient) {\n this._removeFactorGradient(this._emitRateGradients, gradient);\n return this;\n }\n /**\n * Adds a new start size gradient (please note that this will only work if you set the targetStopDuration property)\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param factor defines the start size value to affect to the specified gradient\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\n * @returns the current particle system\n */\n addStartSizeGradient(gradient, factor, factor2) {\n if (!this._startSizeGradients) {\n this._startSizeGradients = [];\n }\n this._addFactorGradient(this._startSizeGradients, gradient, factor, factor2);\n return this;\n }\n /**\n * Remove a specific start size gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeStartSizeGradient(gradient) {\n this._removeFactorGradient(this._startSizeGradients, gradient);\n return this;\n }\n _createRampGradientTexture() {\n if (!this._rampGradients || !this._rampGradients.length || this._rampGradientsTexture || !this._scene) {\n return;\n }\n const data = new Uint8Array(this._rawTextureWidth * 4);\n const tmpColor = TmpColors.Color3[0];\n for (let x = 0; x < this._rawTextureWidth; x++) {\n const ratio = x / this._rawTextureWidth;\n GradientHelper.GetCurrentGradient(ratio, this._rampGradients, (currentGradient, nextGradient, scale) => {\n Color3.LerpToRef(currentGradient.color, nextGradient.color, scale, tmpColor);\n data[x * 4] = tmpColor.r * 255;\n data[x * 4 + 1] = tmpColor.g * 255;\n data[x * 4 + 2] = tmpColor.b * 255;\n data[x * 4 + 3] = 255;\n });\n }\n this._rampGradientsTexture = RawTexture.CreateRGBATexture(data, this._rawTextureWidth, 1, this._scene, false, false, 1);\n }\n /**\n * Gets the current list of ramp gradients.\n * You must use addRampGradient and removeRampGradient to update this list\n * @returns the list of ramp gradients\n */\n getRampGradients() {\n return this._rampGradients;\n }\n /** Force the system to rebuild all gradients that need to be resync */\n forceRefreshGradients() {\n this._syncRampGradientTexture();\n }\n _syncRampGradientTexture() {\n if (!this._rampGradients) {\n return;\n }\n this._rampGradients.sort((a, b) => {\n if (a.gradient < b.gradient) {\n return -1;\n }\n else if (a.gradient > b.gradient) {\n return 1;\n }\n return 0;\n });\n if (this._rampGradientsTexture) {\n this._rampGradientsTexture.dispose();\n this._rampGradientsTexture = null;\n }\n this._createRampGradientTexture();\n }\n /**\n * Adds a new ramp gradient used to remap particle colors\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param color defines the color to affect to the specified gradient\n * @returns the current particle system\n */\n addRampGradient(gradient, color) {\n if (!this._rampGradients) {\n this._rampGradients = [];\n }\n const rampGradient = new Color3Gradient(gradient, color);\n this._rampGradients.push(rampGradient);\n this._syncRampGradientTexture();\n return this;\n }\n /**\n * Remove a specific ramp gradient\n * @param gradient defines the gradient to remove\n * @returns the current particle system\n */\n removeRampGradient(gradient) {\n this._removeGradientAndTexture(gradient, this._rampGradients, this._rampGradientsTexture);\n this._rampGradientsTexture = null;\n if (this._rampGradients && this._rampGradients.length > 0) {\n this._createRampGradientTexture();\n }\n return this;\n }\n /**\n * Adds a new color gradient\n * @param gradient defines the gradient to use (between 0 and 1)\n * @param color1 defines the color to affect to the specified gradient\n * @param color2 defines an additional color used to define a range ([color, color2]) with main color to pick the final color from\n * @returns this particle system\n */\n addColorGradient(gradient, color1, color2) {\n if (!this._colorGradients) {\n this._colorGradients = [];\n }\n const colorGradient = new ColorGradient(gradient, color1, color2);\n this._colorGradients.push(colorGradient);\n this._colorGradients.sort((a, b) => {\n if (a.gradient < b.gradient) {\n return -1;\n }\n else if (a.gradient > b.gradient) {\n return 1;\n }\n return 0;\n });\n return this;\n }\n /**\n * Remove a specific color gradient\n * @param gradient defines the gradient to remove\n * @returns this particle system\n */\n removeColorGradient(gradient) {\n if (!this._colorGradients) {\n return this;\n }\n let index = 0;\n for (const colorGradient of this._colorGradients) {\n if (colorGradient.gradient === gradient) {\n this._colorGradients.splice(index, 1);\n break;\n }\n index++;\n }\n return this;\n }\n /**\n * Resets the draw wrappers cache\n */\n resetDrawCache() {\n for (const drawWrappers of this._drawWrappers) {\n if (drawWrappers) {\n for (const drawWrapper of drawWrappers) {\n drawWrapper === null || drawWrapper === void 0 ? void 0 : drawWrapper.dispose();\n }\n }\n }\n this._drawWrappers = [];\n }\n _fetchR(u, v, width, height, pixels) {\n u = Math.abs(u) * 0.5 + 0.5;\n v = Math.abs(v) * 0.5 + 0.5;\n const wrappedU = (u * width) % width | 0;\n const wrappedV = (v * height) % height | 0;\n const position = (wrappedU + wrappedV * width) * 4;\n return pixels[position] / 255;\n }\n _reset() {\n this._resetEffect();\n }\n _resetEffect() {\n if (this._vertexBuffer) {\n this._vertexBuffer.dispose();\n this._vertexBuffer = null;\n }\n if (this._spriteBuffer) {\n this._spriteBuffer.dispose();\n this._spriteBuffer = null;\n }\n if (this._vertexArrayObject) {\n this._engine.releaseVertexArrayObject(this._vertexArrayObject);\n this._vertexArrayObject = null;\n }\n this._createVertexBuffers();\n }\n _createVertexBuffers() {\n this._vertexBufferSize = this._useInstancing ? 10 : 12;\n if (this._isAnimationSheetEnabled) {\n this._vertexBufferSize += 1;\n }\n if (!this._isBillboardBased || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\n this._vertexBufferSize += 3;\n }\n if (this._useRampGradients) {\n this._vertexBufferSize += 4;\n }\n const engine = this._engine;\n const vertexSize = this._vertexBufferSize * (this._useInstancing ? 1 : 4);\n this._vertexData = new Float32Array(this._capacity * vertexSize);\n this._vertexBuffer = new Buffer$1(engine, this._vertexData, true, vertexSize);\n let dataOffset = 0;\n const positions = this._vertexBuffer.createVertexBuffer(VertexBuffer.PositionKind, dataOffset, 3, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[VertexBuffer.PositionKind] = positions;\n dataOffset += 3;\n const colors = this._vertexBuffer.createVertexBuffer(VertexBuffer.ColorKind, dataOffset, 4, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[VertexBuffer.ColorKind] = colors;\n dataOffset += 4;\n const options = this._vertexBuffer.createVertexBuffer(\"angle\", dataOffset, 1, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[\"angle\"] = options;\n dataOffset += 1;\n const size = this._vertexBuffer.createVertexBuffer(\"size\", dataOffset, 2, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[\"size\"] = size;\n dataOffset += 2;\n if (this._isAnimationSheetEnabled) {\n const cellIndexBuffer = this._vertexBuffer.createVertexBuffer(\"cellIndex\", dataOffset, 1, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[\"cellIndex\"] = cellIndexBuffer;\n dataOffset += 1;\n }\n if (!this._isBillboardBased || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\n const directionBuffer = this._vertexBuffer.createVertexBuffer(\"direction\", dataOffset, 3, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[\"direction\"] = directionBuffer;\n dataOffset += 3;\n }\n if (this._useRampGradients) {\n const rampDataBuffer = this._vertexBuffer.createVertexBuffer(\"remapData\", dataOffset, 4, this._vertexBufferSize, this._useInstancing);\n this._vertexBuffers[\"remapData\"] = rampDataBuffer;\n dataOffset += 4;\n }\n let offsets;\n if (this._useInstancing) {\n const spriteData = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);\n this._spriteBuffer = new Buffer$1(engine, spriteData, false, 2);\n offsets = this._spriteBuffer.createVertexBuffer(\"offset\", 0, 2);\n }\n else {\n offsets = this._vertexBuffer.createVertexBuffer(\"offset\", dataOffset, 2, this._vertexBufferSize, this._useInstancing);\n dataOffset += 2;\n }\n this._vertexBuffers[\"offset\"] = offsets;\n this.resetDrawCache();\n }\n _createIndexBuffer() {\n if (this._useInstancing) {\n return;\n }\n const indices = [];\n let index = 0;\n for (let count = 0; count < this._capacity; count++) {\n indices.push(index);\n indices.push(index + 1);\n indices.push(index + 2);\n indices.push(index);\n indices.push(index + 2);\n indices.push(index + 3);\n index += 4;\n }\n this._indexBuffer = this._engine.createIndexBuffer(indices);\n }\n /**\n * Gets the maximum number of particles active at the same time.\n * @returns The max number of active particles.\n */\n getCapacity() {\n return this._capacity;\n }\n /**\n * Gets whether there are still active particles in the system.\n * @returns True if it is alive, otherwise false.\n */\n isAlive() {\n return this._alive;\n }\n /**\n * Gets if the system has been started. (Note: this will still be true after stop is called)\n * @returns True if it has been started, otherwise false.\n */\n isStarted() {\n return this._started;\n }\n _prepareSubEmitterInternalArray() {\n this._subEmitters = new Array();\n if (this.subEmitters) {\n this.subEmitters.forEach((subEmitter) => {\n if (subEmitter instanceof ParticleSystem) {\n this._subEmitters.push([new SubEmitter(subEmitter)]);\n }\n else if (subEmitter instanceof SubEmitter) {\n this._subEmitters.push([subEmitter]);\n }\n else if (subEmitter instanceof Array) {\n this._subEmitters.push(subEmitter);\n }\n });\n }\n }\n /**\n * Starts the particle system and begins to emit\n * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)\n */\n start(delay = this.startDelay) {\n var _a;\n if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {\n throw \"Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set\";\n }\n if (delay) {\n setTimeout(() => {\n this.start(0);\n }, delay);\n return;\n }\n // Convert the subEmitters field to the constant type field _subEmitters\n this._prepareSubEmitterInternalArray();\n this._started = true;\n this._stopped = false;\n this._actualFrame = 0;\n if (this._subEmitters && this._subEmitters.length != 0) {\n this.activeSubSystems = new Array();\n }\n // Reset emit gradient so it acts the same on every start\n if (this._emitRateGradients) {\n if (this._emitRateGradients.length > 0) {\n this._currentEmitRateGradient = this._emitRateGradients[0];\n this._currentEmitRate1 = this._currentEmitRateGradient.getFactor();\n this._currentEmitRate2 = this._currentEmitRate1;\n }\n if (this._emitRateGradients.length > 1) {\n this._currentEmitRate2 = this._emitRateGradients[1].getFactor();\n }\n }\n // Reset start size gradient so it acts the same on every start\n if (this._startSizeGradients) {\n if (this._startSizeGradients.length > 0) {\n this._currentStartSizeGradient = this._startSizeGradients[0];\n this._currentStartSize1 = this._currentStartSizeGradient.getFactor();\n this._currentStartSize2 = this._currentStartSize1;\n }\n if (this._startSizeGradients.length > 1) {\n this._currentStartSize2 = this._startSizeGradients[1].getFactor();\n }\n }\n if (this.preWarmCycles) {\n if (((_a = this.emitter) === null || _a === void 0 ? void 0 : _a.getClassName().indexOf(\"Mesh\")) !== -1) {\n this.emitter.computeWorldMatrix(true);\n }\n const noiseTextureAsProcedural = this.noiseTexture;\n if (noiseTextureAsProcedural && noiseTextureAsProcedural.onGeneratedObservable) {\n noiseTextureAsProcedural.onGeneratedObservable.addOnce(() => {\n setTimeout(() => {\n for (let index = 0; index < this.preWarmCycles; index++) {\n this.animate(true);\n noiseTextureAsProcedural.render();\n }\n });\n });\n }\n else {\n for (let index = 0; index < this.preWarmCycles; index++) {\n this.animate(true);\n }\n }\n }\n // Animations\n if (this.beginAnimationOnStart && this.animations && this.animations.length > 0 && this._scene) {\n this._scene.beginAnimation(this, this.beginAnimationFrom, this.beginAnimationTo, this.beginAnimationLoop);\n }\n }\n /**\n * Stops the particle system.\n * @param stopSubEmitters if true it will stop the current system and all created sub-Systems if false it will stop the current root system only, this param is used by the root particle system only. the default value is true.\n */\n stop(stopSubEmitters = true) {\n if (this._stopped) {\n return;\n }\n this.onStoppedObservable.notifyObservers(this);\n this._stopped = true;\n if (stopSubEmitters) {\n this._stopSubEmitters();\n }\n }\n // animation sheet\n /**\n * Remove all active particles\n */\n reset() {\n this._stockParticles.length = 0;\n this._particles.length = 0;\n }\n /**\n * @internal (for internal use only)\n */\n _appendParticleVertex(index, particle, offsetX, offsetY) {\n let offset = index * this._vertexBufferSize;\n this._vertexData[offset++] = particle.position.x + this.worldOffset.x;\n this._vertexData[offset++] = particle.position.y + this.worldOffset.y;\n this._vertexData[offset++] = particle.position.z + this.worldOffset.z;\n this._vertexData[offset++] = particle.color.r;\n this._vertexData[offset++] = particle.color.g;\n this._vertexData[offset++] = particle.color.b;\n this._vertexData[offset++] = particle.color.a;\n this._vertexData[offset++] = particle.angle;\n this._vertexData[offset++] = particle.scale.x * particle.size;\n this._vertexData[offset++] = particle.scale.y * particle.size;\n if (this._isAnimationSheetEnabled) {\n this._vertexData[offset++] = particle.cellIndex;\n }\n if (!this._isBillboardBased) {\n if (particle._initialDirection) {\n let initialDirection = particle._initialDirection;\n if (this.isLocal) {\n Vector3.TransformNormalToRef(initialDirection, this._emitterWorldMatrix, TmpVectors.Vector3[0]);\n initialDirection = TmpVectors.Vector3[0];\n }\n if (initialDirection.x === 0 && initialDirection.z === 0) {\n initialDirection.x = 0.001;\n }\n this._vertexData[offset++] = initialDirection.x;\n this._vertexData[offset++] = initialDirection.y;\n this._vertexData[offset++] = initialDirection.z;\n }\n else {\n let direction = particle.direction;\n if (this.isLocal) {\n Vector3.TransformNormalToRef(direction, this._emitterWorldMatrix, TmpVectors.Vector3[0]);\n direction = TmpVectors.Vector3[0];\n }\n if (direction.x === 0 && direction.z === 0) {\n direction.x = 0.001;\n }\n this._vertexData[offset++] = direction.x;\n this._vertexData[offset++] = direction.y;\n this._vertexData[offset++] = direction.z;\n }\n }\n else if (this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\n this._vertexData[offset++] = particle.direction.x;\n this._vertexData[offset++] = particle.direction.y;\n this._vertexData[offset++] = particle.direction.z;\n }\n if (this._useRampGradients && particle.remapData) {\n this._vertexData[offset++] = particle.remapData.x;\n this._vertexData[offset++] = particle.remapData.y;\n this._vertexData[offset++] = particle.remapData.z;\n this._vertexData[offset++] = particle.remapData.w;\n }\n if (!this._useInstancing) {\n if (this._isAnimationSheetEnabled) {\n if (offsetX === 0) {\n offsetX = this._epsilon;\n }\n else if (offsetX === 1) {\n offsetX = 1 - this._epsilon;\n }\n if (offsetY === 0) {\n offsetY = this._epsilon;\n }\n else if (offsetY === 1) {\n offsetY = 1 - this._epsilon;\n }\n }\n this._vertexData[offset++] = offsetX;\n this._vertexData[offset++] = offsetY;\n }\n }\n _stopSubEmitters() {\n if (!this.activeSubSystems) {\n return;\n }\n this.activeSubSystems.forEach((subSystem) => {\n subSystem.stop(true);\n });\n this.activeSubSystems = new Array();\n }\n _removeFromRoot() {\n if (!this._rootParticleSystem) {\n return;\n }\n const index = this._rootParticleSystem.activeSubSystems.indexOf(this);\n if (index !== -1) {\n this._rootParticleSystem.activeSubSystems.splice(index, 1);\n }\n this._rootParticleSystem = null;\n }\n // End of sub system methods\n _update(newParticles) {\n // Update current\n this._alive = this._particles.length > 0;\n if (this.emitter.position) {\n const emitterMesh = this.emitter;\n this._emitterWorldMatrix = emitterMesh.getWorldMatrix();\n }\n else {\n const emitterPosition = this.emitter;\n this._emitterWorldMatrix = Matrix.Translation(emitterPosition.x, emitterPosition.y, emitterPosition.z);\n }\n this._emitterWorldMatrix.invertToRef(this._emitterInverseWorldMatrix);\n this.updateFunction(this._particles);\n // Add new ones\n let particle;\n for (let index = 0; index < newParticles; index++) {\n if (this._particles.length === this._capacity) {\n break;\n }\n particle = this._createParticle();\n this._particles.push(particle);\n // Life time\n if (this.targetStopDuration && this._lifeTimeGradients && this._lifeTimeGradients.length > 0) {\n const ratio = Scalar.Clamp(this._actualFrame / this.targetStopDuration);\n GradientHelper.GetCurrentGradient(ratio, this._lifeTimeGradients, (currentGradient, nextGradient) => {\n const factorGradient1 = currentGradient;\n const factorGradient2 = nextGradient;\n const lifeTime1 = factorGradient1.getFactor();\n const lifeTime2 = factorGradient2.getFactor();\n const gradient = (ratio - factorGradient1.gradient) / (factorGradient2.gradient - factorGradient1.gradient);\n particle.lifeTime = Scalar.Lerp(lifeTime1, lifeTime2, gradient);\n });\n }\n else {\n particle.lifeTime = Scalar.RandomRange(this.minLifeTime, this.maxLifeTime);\n }\n // Emitter\n const emitPower = Scalar.RandomRange(this.minEmitPower, this.maxEmitPower);\n if (this.startPositionFunction) {\n this.startPositionFunction(this._emitterWorldMatrix, particle.position, particle, this.isLocal);\n }\n else {\n this.particleEmitterType.startPositionFunction(this._emitterWorldMatrix, particle.position, particle, this.isLocal);\n }\n if (this.isLocal) {\n if (!particle._localPosition) {\n particle._localPosition = particle.position.clone();\n }\n else {\n particle._localPosition.copyFrom(particle.position);\n }\n Vector3.TransformCoordinatesToRef(particle._localPosition, this._emitterWorldMatrix, particle.position);\n }\n if (this.startDirectionFunction) {\n this.startDirectionFunction(this._emitterWorldMatrix, particle.direction, particle, this.isLocal);\n }\n else {\n this.particleEmitterType.startDirectionFunction(this._emitterWorldMatrix, particle.direction, particle, this.isLocal, this._emitterInverseWorldMatrix);\n }\n if (emitPower === 0) {\n if (!particle._initialDirection) {\n particle._initialDirection = particle.direction.clone();\n }\n else {\n particle._initialDirection.copyFrom(particle.direction);\n }\n }\n else {\n particle._initialDirection = null;\n }\n particle.direction.scaleInPlace(emitPower);\n // Size\n if (!this._sizeGradients || this._sizeGradients.length === 0) {\n particle.size = Scalar.RandomRange(this.minSize, this.maxSize);\n }\n else {\n particle._currentSizeGradient = this._sizeGradients[0];\n particle._currentSize1 = particle._currentSizeGradient.getFactor();\n particle.size = particle._currentSize1;\n if (this._sizeGradients.length > 1) {\n particle._currentSize2 = this._sizeGradients[1].getFactor();\n }\n else {\n particle._currentSize2 = particle._currentSize1;\n }\n }\n // Size and scale\n particle.scale.copyFromFloats(Scalar.RandomRange(this.minScaleX, this.maxScaleX), Scalar.RandomRange(this.minScaleY, this.maxScaleY));\n // Adjust scale by start size\n if (this._startSizeGradients && this._startSizeGradients[0] && this.targetStopDuration) {\n const ratio = this._actualFrame / this.targetStopDuration;\n GradientHelper.GetCurrentGradient(ratio, this._startSizeGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== this._currentStartSizeGradient) {\n this._currentStartSize1 = this._currentStartSize2;\n this._currentStartSize2 = nextGradient.getFactor();\n this._currentStartSizeGradient = currentGradient;\n }\n const value = Scalar.Lerp(this._currentStartSize1, this._currentStartSize2, scale);\n particle.scale.scaleInPlace(value);\n });\n }\n // Angle\n if (!this._angularSpeedGradients || this._angularSpeedGradients.length === 0) {\n particle.angularSpeed = Scalar.RandomRange(this.minAngularSpeed, this.maxAngularSpeed);\n }\n else {\n particle._currentAngularSpeedGradient = this._angularSpeedGradients[0];\n particle.angularSpeed = particle._currentAngularSpeedGradient.getFactor();\n particle._currentAngularSpeed1 = particle.angularSpeed;\n if (this._angularSpeedGradients.length > 1) {\n particle._currentAngularSpeed2 = this._angularSpeedGradients[1].getFactor();\n }\n else {\n particle._currentAngularSpeed2 = particle._currentAngularSpeed1;\n }\n }\n particle.angle = Scalar.RandomRange(this.minInitialRotation, this.maxInitialRotation);\n // Velocity\n if (this._velocityGradients && this._velocityGradients.length > 0) {\n particle._currentVelocityGradient = this._velocityGradients[0];\n particle._currentVelocity1 = particle._currentVelocityGradient.getFactor();\n if (this._velocityGradients.length > 1) {\n particle._currentVelocity2 = this._velocityGradients[1].getFactor();\n }\n else {\n particle._currentVelocity2 = particle._currentVelocity1;\n }\n }\n // Limit velocity\n if (this._limitVelocityGradients && this._limitVelocityGradients.length > 0) {\n particle._currentLimitVelocityGradient = this._limitVelocityGradients[0];\n particle._currentLimitVelocity1 = particle._currentLimitVelocityGradient.getFactor();\n if (this._limitVelocityGradients.length > 1) {\n particle._currentLimitVelocity2 = this._limitVelocityGradients[1].getFactor();\n }\n else {\n particle._currentLimitVelocity2 = particle._currentLimitVelocity1;\n }\n }\n // Drag\n if (this._dragGradients && this._dragGradients.length > 0) {\n particle._currentDragGradient = this._dragGradients[0];\n particle._currentDrag1 = particle._currentDragGradient.getFactor();\n if (this._dragGradients.length > 1) {\n particle._currentDrag2 = this._dragGradients[1].getFactor();\n }\n else {\n particle._currentDrag2 = particle._currentDrag1;\n }\n }\n // Color\n if (!this._colorGradients || this._colorGradients.length === 0) {\n const step = Scalar.RandomRange(0, 1.0);\n Color4.LerpToRef(this.color1, this.color2, step, particle.color);\n this.colorDead.subtractToRef(particle.color, this._colorDiff);\n this._colorDiff.scaleToRef(1.0 / particle.lifeTime, particle.colorStep);\n }\n else {\n particle._currentColorGradient = this._colorGradients[0];\n particle._currentColorGradient.getColorToRef(particle.color);\n particle._currentColor1.copyFrom(particle.color);\n if (this._colorGradients.length > 1) {\n this._colorGradients[1].getColorToRef(particle._currentColor2);\n }\n else {\n particle._currentColor2.copyFrom(particle.color);\n }\n }\n // Sheet\n if (this._isAnimationSheetEnabled) {\n particle._initialStartSpriteCellID = this.startSpriteCellID;\n particle._initialEndSpriteCellID = this.endSpriteCellID;\n particle._initialSpriteCellLoop = this.spriteCellLoop;\n }\n // Inherited Velocity\n particle.direction.addInPlace(this._inheritedVelocityOffset);\n // Ramp\n if (this._useRampGradients) {\n particle.remapData = new Vector4(0, 1, 0, 1);\n }\n // Noise texture coordinates\n if (this.noiseTexture) {\n if (particle._randomNoiseCoordinates1) {\n particle._randomNoiseCoordinates1.copyFromFloats(Math.random(), Math.random(), Math.random());\n particle._randomNoiseCoordinates2.copyFromFloats(Math.random(), Math.random(), Math.random());\n }\n else {\n particle._randomNoiseCoordinates1 = new Vector3(Math.random(), Math.random(), Math.random());\n particle._randomNoiseCoordinates2 = new Vector3(Math.random(), Math.random(), Math.random());\n }\n }\n // Update the position of the attached sub-emitters to match their attached particle\n particle._inheritParticleInfoToSubEmitters();\n }\n }\n /**\n * @internal\n */\n static _GetAttributeNamesOrOptions(isAnimationSheetEnabled = false, isBillboardBased = false, useRampGradients = false) {\n const attributeNamesOrOptions = [VertexBuffer.PositionKind, VertexBuffer.ColorKind, \"angle\", \"offset\", \"size\"];\n if (isAnimationSheetEnabled) {\n attributeNamesOrOptions.push(\"cellIndex\");\n }\n if (!isBillboardBased) {\n attributeNamesOrOptions.push(\"direction\");\n }\n if (useRampGradients) {\n attributeNamesOrOptions.push(\"remapData\");\n }\n return attributeNamesOrOptions;\n }\n /**\n * @internal\n */\n static _GetEffectCreationOptions(isAnimationSheetEnabled = false, useLogarithmicDepth = false) {\n const effectCreationOption = [\"invView\", \"view\", \"projection\", \"textureMask\", \"translationPivot\", \"eyePosition\"];\n addClipPlaneUniforms(effectCreationOption);\n if (isAnimationSheetEnabled) {\n effectCreationOption.push(\"particlesInfos\");\n }\n if (useLogarithmicDepth) {\n effectCreationOption.push(\"logarithmicDepthConstant\");\n }\n return effectCreationOption;\n }\n /**\n * Fill the defines array according to the current settings of the particle system\n * @param defines Array to be updated\n * @param blendMode blend mode to take into account when updating the array\n */\n fillDefines(defines, blendMode) {\n if (this._scene) {\n prepareStringDefinesForClipPlanes(this, this._scene, defines);\n }\n if (this._isAnimationSheetEnabled) {\n defines.push(\"#define ANIMATESHEET\");\n }\n if (this.useLogarithmicDepth) {\n defines.push(\"#define LOGARITHMICDEPTH\");\n }\n if (blendMode === ParticleSystem.BLENDMODE_MULTIPLY) {\n defines.push(\"#define BLENDMULTIPLYMODE\");\n }\n if (this._useRampGradients) {\n defines.push(\"#define RAMPGRADIENT\");\n }\n if (this._isBillboardBased) {\n defines.push(\"#define BILLBOARD\");\n switch (this.billboardMode) {\n case ParticleSystem.BILLBOARDMODE_Y:\n defines.push(\"#define BILLBOARDY\");\n break;\n case ParticleSystem.BILLBOARDMODE_STRETCHED:\n case ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL:\n defines.push(\"#define BILLBOARDSTRETCHED\");\n if (this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\n defines.push(\"#define BILLBOARDSTRETCHED_LOCAL\");\n }\n break;\n case ParticleSystem.BILLBOARDMODE_ALL:\n defines.push(\"#define BILLBOARDMODE_ALL\");\n break;\n }\n }\n if (this._imageProcessingConfiguration) {\n this._imageProcessingConfiguration.prepareDefines(this._imageProcessingConfigurationDefines);\n defines.push(this._imageProcessingConfigurationDefines.toString());\n }\n }\n /**\n * Fill the uniforms, attributes and samplers arrays according to the current settings of the particle system\n * @param uniforms Uniforms array to fill\n * @param attributes Attributes array to fill\n * @param samplers Samplers array to fill\n */\n fillUniformsAttributesAndSamplerNames(uniforms, attributes, samplers) {\n attributes.push(...ParticleSystem._GetAttributeNamesOrOptions(this._isAnimationSheetEnabled, this._isBillboardBased && this.billboardMode !== ParticleSystem.BILLBOARDMODE_STRETCHED && this.billboardMode !== ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL, this._useRampGradients));\n uniforms.push(...ParticleSystem._GetEffectCreationOptions(this._isAnimationSheetEnabled, this.useLogarithmicDepth));\n samplers.push(\"diffuseSampler\", \"rampSampler\");\n if (this._imageProcessingConfiguration) {\n ImageProcessingConfiguration.PrepareUniforms(uniforms, this._imageProcessingConfigurationDefines);\n ImageProcessingConfiguration.PrepareSamplers(samplers, this._imageProcessingConfigurationDefines);\n }\n }\n /**\n * @internal\n */\n _getWrapper(blendMode) {\n const customWrapper = this._getCustomDrawWrapper(blendMode);\n if (customWrapper === null || customWrapper === void 0 ? void 0 : customWrapper.effect) {\n return customWrapper;\n }\n const defines = [];\n this.fillDefines(defines, blendMode);\n // Effect\n const currentRenderPassId = this._engine._features.supportRenderPasses ? this._engine.currentRenderPassId : 0;\n let drawWrappers = this._drawWrappers[currentRenderPassId];\n if (!drawWrappers) {\n drawWrappers = this._drawWrappers[currentRenderPassId] = [];\n }\n let drawWrapper = drawWrappers[blendMode];\n if (!drawWrapper) {\n drawWrapper = new DrawWrapper(this._engine);\n if (drawWrapper.drawContext) {\n drawWrapper.drawContext.useInstancing = this._useInstancing;\n }\n drawWrappers[blendMode] = drawWrapper;\n }\n const join = defines.join(\"\\n\");\n if (drawWrapper.defines !== join) {\n const attributesNamesOrOptions = [];\n const effectCreationOption = [];\n const samplers = [];\n this.fillUniformsAttributesAndSamplerNames(effectCreationOption, attributesNamesOrOptions, samplers);\n drawWrapper.setEffect(this._engine.createEffect(\"particles\", attributesNamesOrOptions, effectCreationOption, samplers, join), join);\n }\n return drawWrapper;\n }\n /**\n * Animates the particle system for the current frame by emitting new particles and or animating the living ones.\n * @param preWarmOnly will prevent the system from updating the vertex buffer (default is false)\n */\n animate(preWarmOnly = false) {\n var _a;\n if (!this._started) {\n return;\n }\n if (!preWarmOnly && this._scene) {\n // Check\n if (!this.isReady()) {\n return;\n }\n if (this._currentRenderId === this._scene.getFrameId()) {\n return;\n }\n this._currentRenderId = this._scene.getFrameId();\n }\n this._scaledUpdateSpeed = this.updateSpeed * (preWarmOnly ? this.preWarmStepOffset : ((_a = this._scene) === null || _a === void 0 ? void 0 : _a.getAnimationRatio()) || 1);\n // Determine the number of particles we need to create\n let newParticles;\n if (this.manualEmitCount > -1) {\n newParticles = this.manualEmitCount;\n this._newPartsExcess = 0;\n this.manualEmitCount = 0;\n }\n else {\n let rate = this.emitRate;\n if (this._emitRateGradients && this._emitRateGradients.length > 0 && this.targetStopDuration) {\n const ratio = this._actualFrame / this.targetStopDuration;\n GradientHelper.GetCurrentGradient(ratio, this._emitRateGradients, (currentGradient, nextGradient, scale) => {\n if (currentGradient !== this._currentEmitRateGradient) {\n this._currentEmitRate1 = this._currentEmitRate2;\n this._currentEmitRate2 = nextGradient.getFactor();\n this._currentEmitRateGradient = currentGradient;\n }\n rate = Scalar.Lerp(this._currentEmitRate1, this._currentEmitRate2, scale);\n });\n }\n newParticles = (rate * this._scaledUpdateSpeed) >> 0;\n this._newPartsExcess += rate * this._scaledUpdateSpeed - newParticles;\n }\n if (this._newPartsExcess > 1.0) {\n newParticles += this._newPartsExcess >> 0;\n this._newPartsExcess -= this._newPartsExcess >> 0;\n }\n this._alive = false;\n if (!this._stopped) {\n this._actualFrame += this._scaledUpdateSpeed;\n if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration) {\n this.stop();\n }\n }\n else {\n newParticles = 0;\n }\n this._update(newParticles);\n // Stopped?\n if (this._stopped) {\n if (!this._alive) {\n this._started = false;\n if (this.onAnimationEnd) {\n this.onAnimationEnd();\n }\n if (this.disposeOnStop && this._scene) {\n this._scene._toBeDisposed.push(this);\n }\n }\n }\n if (!preWarmOnly) {\n // Update VBO\n let offset = 0;\n for (let index = 0; index < this._particles.length; index++) {\n const particle = this._particles[index];\n this._appendParticleVertices(offset, particle);\n offset += this._useInstancing ? 1 : 4;\n }\n if (this._vertexBuffer) {\n this._vertexBuffer.updateDirectly(this._vertexData, 0, this._particles.length);\n }\n }\n if (this.manualEmitCount === 0 && this.disposeOnStop) {\n this.stop();\n }\n }\n _appendParticleVertices(offset, particle) {\n this._appendParticleVertex(offset++, particle, 0, 0);\n if (!this._useInstancing) {\n this._appendParticleVertex(offset++, particle, 1, 0);\n this._appendParticleVertex(offset++, particle, 1, 1);\n this._appendParticleVertex(offset++, particle, 0, 1);\n }\n }\n /**\n * Rebuilds the particle system.\n */\n rebuild() {\n var _a, _b;\n if (this._engine.getCaps().vertexArrayObject) {\n this._vertexArrayObject = null;\n }\n this._createIndexBuffer();\n (_a = this._spriteBuffer) === null || _a === void 0 ? void 0 : _a._rebuild();\n (_b = this._vertexBuffer) === null || _b === void 0 ? void 0 : _b._rebuild();\n for (const key in this._vertexBuffers) {\n this._vertexBuffers[key]._rebuild();\n }\n this.resetDrawCache();\n }\n /**\n * Is this system ready to be used/rendered\n * @returns true if the system is ready\n */\n isReady() {\n if (!this.emitter || (this._imageProcessingConfiguration && !this._imageProcessingConfiguration.isReady()) || !this.particleTexture || !this.particleTexture.isReady()) {\n return false;\n }\n if (this.blendMode !== ParticleSystem.BLENDMODE_MULTIPLYADD) {\n if (!this._getWrapper(this.blendMode).effect.isReady()) {\n return false;\n }\n }\n else {\n if (!this._getWrapper(ParticleSystem.BLENDMODE_MULTIPLY).effect.isReady()) {\n return false;\n }\n if (!this._getWrapper(ParticleSystem.BLENDMODE_ADD).effect.isReady()) {\n return false;\n }\n }\n return true;\n }\n _render(blendMode) {\n var _a, _b;\n const drawWrapper = this._getWrapper(blendMode);\n const effect = drawWrapper.effect;\n const engine = this._engine;\n // Render\n engine.enableEffect(drawWrapper);\n const viewMatrix = (_a = this.defaultViewMatrix) !== null && _a !== void 0 ? _a : this._scene.getViewMatrix();\n effect.setTexture(\"diffuseSampler\", this.particleTexture);\n effect.setMatrix(\"view\", viewMatrix);\n effect.setMatrix(\"projection\", (_b = this.defaultProjectionMatrix) !== null && _b !== void 0 ? _b : this._scene.getProjectionMatrix());\n if (this._isAnimationSheetEnabled && this.particleTexture) {\n const baseSize = this.particleTexture.getBaseSize();\n effect.setFloat3(\"particlesInfos\", this.spriteCellWidth / baseSize.width, this.spriteCellHeight / baseSize.height, this.spriteCellWidth / baseSize.width);\n }\n effect.setVector2(\"translationPivot\", this.translationPivot);\n effect.setFloat4(\"textureMask\", this.textureMask.r, this.textureMask.g, this.textureMask.b, this.textureMask.a);\n if (this._isBillboardBased && this._scene) {\n const camera = this._scene.activeCamera;\n effect.setVector3(\"eyePosition\", camera.globalPosition);\n }\n if (this._rampGradientsTexture) {\n if (!this._rampGradients || !this._rampGradients.length) {\n this._rampGradientsTexture.dispose();\n this._rampGradientsTexture = null;\n }\n effect.setTexture(\"rampSampler\", this._rampGradientsTexture);\n }\n const defines = effect.defines;\n if (this._scene) {\n bindClipPlane(effect, this, this._scene);\n }\n if (defines.indexOf(\"#define BILLBOARDMODE_ALL\") >= 0) {\n viewMatrix.invertToRef(TmpVectors.Matrix[0]);\n effect.setMatrix(\"invView\", TmpVectors.Matrix[0]);\n }\n if (this._vertexArrayObject !== undefined) {\n if (!this._vertexArrayObject) {\n this._vertexArrayObject = this._engine.recordVertexArrayObject(this._vertexBuffers, this._indexBuffer, effect);\n }\n this._engine.bindVertexArrayObject(this._vertexArrayObject, this._indexBuffer);\n }\n else {\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\n }\n // Log. depth\n if (this.useLogarithmicDepth && this._scene) {\n MaterialHelper.BindLogDepth(defines, effect, this._scene);\n }\n // image processing\n if (this._imageProcessingConfiguration && !this._imageProcessingConfiguration.applyByPostProcess) {\n this._imageProcessingConfiguration.bind(effect);\n }\n // Draw order\n switch (blendMode) {\n case ParticleSystem.BLENDMODE_ADD:\n engine.setAlphaMode(1);\n break;\n case ParticleSystem.BLENDMODE_ONEONE:\n engine.setAlphaMode(6);\n break;\n case ParticleSystem.BLENDMODE_STANDARD:\n engine.setAlphaMode(2);\n break;\n case ParticleSystem.BLENDMODE_MULTIPLY:\n engine.setAlphaMode(4);\n break;\n }\n if (this._onBeforeDrawParticlesObservable) {\n this._onBeforeDrawParticlesObservable.notifyObservers(effect);\n }\n if (this._useInstancing) {\n engine.drawArraysType(7, 0, 4, this._particles.length);\n }\n else {\n engine.drawElementsType(0, 0, this._particles.length * 6);\n }\n return this._particles.length;\n }\n /**\n * Renders the particle system in its current state.\n * @returns the current number of particles\n */\n render() {\n // Check\n if (!this.isReady() || !this._particles.length) {\n return 0;\n }\n const engine = this._engine;\n if (engine.setState) {\n engine.setState(false);\n if (this.forceDepthWrite) {\n engine.setDepthWrite(true);\n }\n }\n let outparticles = 0;\n if (this.blendMode === ParticleSystem.BLENDMODE_MULTIPLYADD) {\n outparticles = this._render(ParticleSystem.BLENDMODE_MULTIPLY) + this._render(ParticleSystem.BLENDMODE_ADD);\n }\n else {\n outparticles = this._render(this.blendMode);\n }\n this._engine.unbindInstanceAttributes();\n this._engine.setAlphaMode(0);\n return outparticles;\n }\n /**\n * Disposes the particle system and free the associated resources\n * @param disposeTexture defines if the particle texture must be disposed as well (true by default)\n */\n dispose(disposeTexture = true) {\n this.resetDrawCache();\n if (this._vertexBuffer) {\n this._vertexBuffer.dispose();\n this._vertexBuffer = null;\n }\n if (this._spriteBuffer) {\n this._spriteBuffer.dispose();\n this._spriteBuffer = null;\n }\n if (this._indexBuffer) {\n this._engine._releaseBuffer(this._indexBuffer);\n this._indexBuffer = null;\n }\n if (this._vertexArrayObject) {\n this._engine.releaseVertexArrayObject(this._vertexArrayObject);\n this._vertexArrayObject = null;\n }\n if (disposeTexture && this.particleTexture) {\n this.particleTexture.dispose();\n this.particleTexture = null;\n }\n if (disposeTexture && this.noiseTexture) {\n this.noiseTexture.dispose();\n this.noiseTexture = null;\n }\n if (this._rampGradientsTexture) {\n this._rampGradientsTexture.dispose();\n this._rampGradientsTexture = null;\n }\n this._removeFromRoot();\n if (this.subEmitters && !this._subEmitters) {\n this._prepareSubEmitterInternalArray();\n }\n if (this._subEmitters && this._subEmitters.length) {\n for (let index = 0; index < this._subEmitters.length; index++) {\n for (const subEmitter of this._subEmitters[index]) {\n subEmitter.dispose();\n }\n }\n this._subEmitters = [];\n this.subEmitters = [];\n }\n if (this._disposeEmitterOnDispose && this.emitter && this.emitter.dispose) {\n this.emitter.dispose(true);\n }\n if (this._onBeforeDrawParticlesObservable) {\n this._onBeforeDrawParticlesObservable.clear();\n }\n // Remove from scene\n if (this._scene) {\n const index = this._scene.particleSystems.indexOf(this);\n if (index > -1) {\n this._scene.particleSystems.splice(index, 1);\n }\n this._scene._activeParticleSystems.dispose();\n }\n // Callback\n this.onDisposeObservable.notifyObservers(this);\n this.onDisposeObservable.clear();\n this.onStoppedObservable.clear();\n this.reset();\n }\n // Clone\n /**\n * Clones the particle system.\n * @param name The name of the cloned object\n * @param newEmitter The new emitter to use\n * @param cloneTexture Also clone the textures if true\n * @returns the cloned particle system\n */\n clone(name, newEmitter, cloneTexture = false) {\n const custom = Object.assign({}, this._customWrappers);\n let program = null;\n const engine = this._engine;\n if (engine.createEffectForParticles) {\n if (this.customShader != null) {\n program = this.customShader;\n const defines = program.shaderOptions.defines.length > 0 ? program.shaderOptions.defines.join(\"\\n\") : \"\";\n const effect = engine.createEffectForParticles(program.shaderPath.fragmentElement, program.shaderOptions.uniforms, program.shaderOptions.samplers, defines);\n if (!custom[0]) {\n this.setCustomEffect(effect, 0);\n }\n else {\n custom[0].effect = effect;\n }\n }\n }\n const serialization = this.serialize(cloneTexture);\n const result = ParticleSystem.Parse(serialization, this._scene || this._engine, this._rootUrl);\n result.name = name;\n result.customShader = program;\n result._customWrappers = custom;\n if (newEmitter === undefined) {\n newEmitter = this.emitter;\n }\n if (this.noiseTexture) {\n result.noiseTexture = this.noiseTexture.clone();\n }\n result.emitter = newEmitter;\n if (!this.preventAutoStart) {\n result.start();\n }\n return result;\n }\n /**\n * Serializes the particle system to a JSON object\n * @param serializeTexture defines if the texture must be serialized as well\n * @returns the JSON object\n */\n serialize(serializeTexture = false) {\n const serializationObject = {};\n ParticleSystem._Serialize(serializationObject, this, serializeTexture);\n serializationObject.textureMask = this.textureMask.asArray();\n serializationObject.customShader = this.customShader;\n serializationObject.preventAutoStart = this.preventAutoStart;\n // SubEmitters\n if (this.subEmitters) {\n serializationObject.subEmitters = [];\n if (!this._subEmitters) {\n this._prepareSubEmitterInternalArray();\n }\n for (const subs of this._subEmitters) {\n const cell = [];\n for (const sub of subs) {\n cell.push(sub.serialize(serializeTexture));\n }\n serializationObject.subEmitters.push(cell);\n }\n }\n return serializationObject;\n }\n /**\n * @internal\n */\n static _Serialize(serializationObject, particleSystem, serializeTexture) {\n serializationObject.name = particleSystem.name;\n serializationObject.id = particleSystem.id;\n serializationObject.capacity = particleSystem.getCapacity();\n serializationObject.disposeOnStop = particleSystem.disposeOnStop;\n serializationObject.manualEmitCount = particleSystem.manualEmitCount;\n // Emitter\n if (particleSystem.emitter.position) {\n const emitterMesh = particleSystem.emitter;\n serializationObject.emitterId = emitterMesh.id;\n }\n else {\n const emitterPosition = particleSystem.emitter;\n serializationObject.emitter = emitterPosition.asArray();\n }\n // Emitter\n if (particleSystem.particleEmitterType) {\n serializationObject.particleEmitterType = particleSystem.particleEmitterType.serialize();\n }\n if (particleSystem.particleTexture) {\n if (serializeTexture) {\n serializationObject.texture = particleSystem.particleTexture.serialize();\n }\n else {\n serializationObject.textureName = particleSystem.particleTexture.name;\n serializationObject.invertY = !!particleSystem.particleTexture._invertY;\n }\n }\n serializationObject.isLocal = particleSystem.isLocal;\n // Animations\n SerializationHelper.AppendSerializedAnimations(particleSystem, serializationObject);\n serializationObject.beginAnimationOnStart = particleSystem.beginAnimationOnStart;\n serializationObject.beginAnimationFrom = particleSystem.beginAnimationFrom;\n serializationObject.beginAnimationTo = particleSystem.beginAnimationTo;\n serializationObject.beginAnimationLoop = particleSystem.beginAnimationLoop;\n // Particle system\n serializationObject.startDelay = particleSystem.startDelay;\n serializationObject.renderingGroupId = particleSystem.renderingGroupId;\n serializationObject.isBillboardBased = particleSystem.isBillboardBased;\n serializationObject.billboardMode = particleSystem.billboardMode;\n serializationObject.minAngularSpeed = particleSystem.minAngularSpeed;\n serializationObject.maxAngularSpeed = particleSystem.maxAngularSpeed;\n serializationObject.minSize = particleSystem.minSize;\n serializationObject.maxSize = particleSystem.maxSize;\n serializationObject.minScaleX = particleSystem.minScaleX;\n serializationObject.maxScaleX = particleSystem.maxScaleX;\n serializationObject.minScaleY = particleSystem.minScaleY;\n serializationObject.maxScaleY = particleSystem.maxScaleY;\n serializationObject.minEmitPower = particleSystem.minEmitPower;\n serializationObject.maxEmitPower = particleSystem.maxEmitPower;\n serializationObject.minLifeTime = particleSystem.minLifeTime;\n serializationObject.maxLifeTime = particleSystem.maxLifeTime;\n serializationObject.emitRate = particleSystem.emitRate;\n serializationObject.gravity = particleSystem.gravity.asArray();\n serializationObject.noiseStrength = particleSystem.noiseStrength.asArray();\n serializationObject.color1 = particleSystem.color1.asArray();\n serializationObject.color2 = particleSystem.color2.asArray();\n serializationObject.colorDead = particleSystem.colorDead.asArray();\n serializationObject.updateSpeed = particleSystem.updateSpeed;\n serializationObject.targetStopDuration = particleSystem.targetStopDuration;\n serializationObject.blendMode = particleSystem.blendMode;\n serializationObject.preWarmCycles = particleSystem.preWarmCycles;\n serializationObject.preWarmStepOffset = particleSystem.preWarmStepOffset;\n serializationObject.minInitialRotation = particleSystem.minInitialRotation;\n serializationObject.maxInitialRotation = particleSystem.maxInitialRotation;\n serializationObject.startSpriteCellID = particleSystem.startSpriteCellID;\n serializationObject.spriteCellLoop = particleSystem.spriteCellLoop;\n serializationObject.endSpriteCellID = particleSystem.endSpriteCellID;\n serializationObject.spriteCellChangeSpeed = particleSystem.spriteCellChangeSpeed;\n serializationObject.spriteCellWidth = particleSystem.spriteCellWidth;\n serializationObject.spriteCellHeight = particleSystem.spriteCellHeight;\n serializationObject.spriteRandomStartCell = particleSystem.spriteRandomStartCell;\n serializationObject.isAnimationSheetEnabled = particleSystem.isAnimationSheetEnabled;\n serializationObject.useLogarithmicDepth = particleSystem.useLogarithmicDepth;\n const colorGradients = particleSystem.getColorGradients();\n if (colorGradients) {\n serializationObject.colorGradients = [];\n for (const colorGradient of colorGradients) {\n const serializedGradient = {\n gradient: colorGradient.gradient,\n color1: colorGradient.color1.asArray(),\n };\n if (colorGradient.color2) {\n serializedGradient.color2 = colorGradient.color2.asArray();\n }\n else {\n serializedGradient.color2 = colorGradient.color1.asArray();\n }\n serializationObject.colorGradients.push(serializedGradient);\n }\n }\n const rampGradients = particleSystem.getRampGradients();\n if (rampGradients) {\n serializationObject.rampGradients = [];\n for (const rampGradient of rampGradients) {\n const serializedGradient = {\n gradient: rampGradient.gradient,\n color: rampGradient.color.asArray(),\n };\n serializationObject.rampGradients.push(serializedGradient);\n }\n serializationObject.useRampGradients = particleSystem.useRampGradients;\n }\n const colorRemapGradients = particleSystem.getColorRemapGradients();\n if (colorRemapGradients) {\n serializationObject.colorRemapGradients = [];\n for (const colorRemapGradient of colorRemapGradients) {\n const serializedGradient = {\n gradient: colorRemapGradient.gradient,\n factor1: colorRemapGradient.factor1,\n };\n if (colorRemapGradient.factor2 !== undefined) {\n serializedGradient.factor2 = colorRemapGradient.factor2;\n }\n else {\n serializedGradient.factor2 = colorRemapGradient.factor1;\n }\n serializationObject.colorRemapGradients.push(serializedGradient);\n }\n }\n const alphaRemapGradients = particleSystem.getAlphaRemapGradients();\n if (alphaRemapGradients) {\n serializationObject.alphaRemapGradients = [];\n for (const alphaRemapGradient of alphaRemapGradients) {\n const serializedGradient = {\n gradient: alphaRemapGradient.gradient,\n factor1: alphaRemapGradient.factor1,\n };\n if (alphaRemapGradient.factor2 !== undefined) {\n serializedGradient.factor2 = alphaRemapGradient.factor2;\n }\n else {\n serializedGradient.factor2 = alphaRemapGradient.factor1;\n }\n serializationObject.alphaRemapGradients.push(serializedGradient);\n }\n }\n const sizeGradients = particleSystem.getSizeGradients();\n if (sizeGradients) {\n serializationObject.sizeGradients = [];\n for (const sizeGradient of sizeGradients) {\n const serializedGradient = {\n gradient: sizeGradient.gradient,\n factor1: sizeGradient.factor1,\n };\n if (sizeGradient.factor2 !== undefined) {\n serializedGradient.factor2 = sizeGradient.factor2;\n }\n else {\n serializedGradient.factor2 = sizeGradient.factor1;\n }\n serializationObject.sizeGradients.push(serializedGradient);\n }\n }\n const angularSpeedGradients = particleSystem.getAngularSpeedGradients();\n if (angularSpeedGradients) {\n serializationObject.angularSpeedGradients = [];\n for (const angularSpeedGradient of angularSpeedGradients) {\n const serializedGradient = {\n gradient: angularSpeedGradient.gradient,\n factor1: angularSpeedGradient.factor1,\n };\n if (angularSpeedGradient.factor2 !== undefined) {\n serializedGradient.factor2 = angularSpeedGradient.factor2;\n }\n else {\n serializedGradient.factor2 = angularSpeedGradient.factor1;\n }\n serializationObject.angularSpeedGradients.push(serializedGradient);\n }\n }\n const velocityGradients = particleSystem.getVelocityGradients();\n if (velocityGradients) {\n serializationObject.velocityGradients = [];\n for (const velocityGradient of velocityGradients) {\n const serializedGradient = {\n gradient: velocityGradient.gradient,\n factor1: velocityGradient.factor1,\n };\n if (velocityGradient.factor2 !== undefined) {\n serializedGradient.factor2 = velocityGradient.factor2;\n }\n else {\n serializedGradient.factor2 = velocityGradient.factor1;\n }\n serializationObject.velocityGradients.push(serializedGradient);\n }\n }\n const dragGradients = particleSystem.getDragGradients();\n if (dragGradients) {\n serializationObject.dragGradients = [];\n for (const dragGradient of dragGradients) {\n const serializedGradient = {\n gradient: dragGradient.gradient,\n factor1: dragGradient.factor1,\n };\n if (dragGradient.factor2 !== undefined) {\n serializedGradient.factor2 = dragGradient.factor2;\n }\n else {\n serializedGradient.factor2 = dragGradient.factor1;\n }\n serializationObject.dragGradients.push(serializedGradient);\n }\n }\n const emitRateGradients = particleSystem.getEmitRateGradients();\n if (emitRateGradients) {\n serializationObject.emitRateGradients = [];\n for (const emitRateGradient of emitRateGradients) {\n const serializedGradient = {\n gradient: emitRateGradient.gradient,\n factor1: emitRateGradient.factor1,\n };\n if (emitRateGradient.factor2 !== undefined) {\n serializedGradient.factor2 = emitRateGradient.factor2;\n }\n else {\n serializedGradient.factor2 = emitRateGradient.factor1;\n }\n serializationObject.emitRateGradients.push(serializedGradient);\n }\n }\n const startSizeGradients = particleSystem.getStartSizeGradients();\n if (startSizeGradients) {\n serializationObject.startSizeGradients = [];\n for (const startSizeGradient of startSizeGradients) {\n const serializedGradient = {\n gradient: startSizeGradient.gradient,\n factor1: startSizeGradient.factor1,\n };\n if (startSizeGradient.factor2 !== undefined) {\n serializedGradient.factor2 = startSizeGradient.factor2;\n }\n else {\n serializedGradient.factor2 = startSizeGradient.factor1;\n }\n serializationObject.startSizeGradients.push(serializedGradient);\n }\n }\n const lifeTimeGradients = particleSystem.getLifeTimeGradients();\n if (lifeTimeGradients) {\n serializationObject.lifeTimeGradients = [];\n for (const lifeTimeGradient of lifeTimeGradients) {\n const serializedGradient = {\n gradient: lifeTimeGradient.gradient,\n factor1: lifeTimeGradient.factor1,\n };\n if (lifeTimeGradient.factor2 !== undefined) {\n serializedGradient.factor2 = lifeTimeGradient.factor2;\n }\n else {\n serializedGradient.factor2 = lifeTimeGradient.factor1;\n }\n serializationObject.lifeTimeGradients.push(serializedGradient);\n }\n }\n const limitVelocityGradients = particleSystem.getLimitVelocityGradients();\n if (limitVelocityGradients) {\n serializationObject.limitVelocityGradients = [];\n for (const limitVelocityGradient of limitVelocityGradients) {\n const serializedGradient = {\n gradient: limitVelocityGradient.gradient,\n factor1: limitVelocityGradient.factor1,\n };\n if (limitVelocityGradient.factor2 !== undefined) {\n serializedGradient.factor2 = limitVelocityGradient.factor2;\n }\n else {\n serializedGradient.factor2 = limitVelocityGradient.factor1;\n }\n serializationObject.limitVelocityGradients.push(serializedGradient);\n }\n serializationObject.limitVelocityDamping = particleSystem.limitVelocityDamping;\n }\n if (particleSystem.noiseTexture) {\n serializationObject.noiseTexture = particleSystem.noiseTexture.serialize();\n }\n }\n /**\n * @internal\n */\n static _Parse(parsedParticleSystem, particleSystem, sceneOrEngine, rootUrl) {\n var _a, _b, _c;\n let scene;\n if (sceneOrEngine instanceof ThinEngine) {\n scene = null;\n }\n else {\n scene = sceneOrEngine;\n }\n const internalClass = GetClass(\"BABYLON.Texture\");\n if (internalClass && scene) {\n // Texture\n if (parsedParticleSystem.texture) {\n particleSystem.particleTexture = internalClass.Parse(parsedParticleSystem.texture, scene, rootUrl);\n }\n else if (parsedParticleSystem.textureName) {\n particleSystem.particleTexture = new internalClass(rootUrl + parsedParticleSystem.textureName, scene, false, parsedParticleSystem.invertY !== undefined ? parsedParticleSystem.invertY : true);\n particleSystem.particleTexture.name = parsedParticleSystem.textureName;\n }\n }\n // Emitter\n if (!parsedParticleSystem.emitterId && parsedParticleSystem.emitterId !== 0 && parsedParticleSystem.emitter === undefined) {\n particleSystem.emitter = Vector3.Zero();\n }\n else if (parsedParticleSystem.emitterId && scene) {\n particleSystem.emitter = scene.getLastMeshById(parsedParticleSystem.emitterId);\n }\n else {\n particleSystem.emitter = Vector3.FromArray(parsedParticleSystem.emitter);\n }\n particleSystem.isLocal = !!parsedParticleSystem.isLocal;\n // Misc.\n if (parsedParticleSystem.renderingGroupId !== undefined) {\n particleSystem.renderingGroupId = parsedParticleSystem.renderingGroupId;\n }\n if (parsedParticleSystem.isBillboardBased !== undefined) {\n particleSystem.isBillboardBased = parsedParticleSystem.isBillboardBased;\n }\n if (parsedParticleSystem.billboardMode !== undefined) {\n particleSystem.billboardMode = parsedParticleSystem.billboardMode;\n }\n if (parsedParticleSystem.useLogarithmicDepth !== undefined) {\n particleSystem.useLogarithmicDepth = parsedParticleSystem.useLogarithmicDepth;\n }\n // Animations\n if (parsedParticleSystem.animations) {\n for (let animationIndex = 0; animationIndex < parsedParticleSystem.animations.length; animationIndex++) {\n const parsedAnimation = parsedParticleSystem.animations[animationIndex];\n const internalClass = GetClass(\"BABYLON.Animation\");\n if (internalClass) {\n particleSystem.animations.push(internalClass.Parse(parsedAnimation));\n }\n }\n particleSystem.beginAnimationOnStart = parsedParticleSystem.beginAnimationOnStart;\n particleSystem.beginAnimationFrom = parsedParticleSystem.beginAnimationFrom;\n particleSystem.beginAnimationTo = parsedParticleSystem.beginAnimationTo;\n particleSystem.beginAnimationLoop = parsedParticleSystem.beginAnimationLoop;\n }\n if (parsedParticleSystem.autoAnimate && scene) {\n scene.beginAnimation(particleSystem, parsedParticleSystem.autoAnimateFrom, parsedParticleSystem.autoAnimateTo, parsedParticleSystem.autoAnimateLoop, parsedParticleSystem.autoAnimateSpeed || 1.0);\n }\n // Particle system\n particleSystem.startDelay = parsedParticleSystem.startDelay | 0;\n particleSystem.minAngularSpeed = parsedParticleSystem.minAngularSpeed;\n particleSystem.maxAngularSpeed = parsedParticleSystem.maxAngularSpeed;\n particleSystem.minSize = parsedParticleSystem.minSize;\n particleSystem.maxSize = parsedParticleSystem.maxSize;\n if (parsedParticleSystem.minScaleX) {\n particleSystem.minScaleX = parsedParticleSystem.minScaleX;\n particleSystem.maxScaleX = parsedParticleSystem.maxScaleX;\n particleSystem.minScaleY = parsedParticleSystem.minScaleY;\n particleSystem.maxScaleY = parsedParticleSystem.maxScaleY;\n }\n if (parsedParticleSystem.preWarmCycles !== undefined) {\n particleSystem.preWarmCycles = parsedParticleSystem.preWarmCycles;\n particleSystem.preWarmStepOffset = parsedParticleSystem.preWarmStepOffset;\n }\n if (parsedParticleSystem.minInitialRotation !== undefined) {\n particleSystem.minInitialRotation = parsedParticleSystem.minInitialRotation;\n particleSystem.maxInitialRotation = parsedParticleSystem.maxInitialRotation;\n }\n particleSystem.minLifeTime = parsedParticleSystem.minLifeTime;\n particleSystem.maxLifeTime = parsedParticleSystem.maxLifeTime;\n particleSystem.minEmitPower = parsedParticleSystem.minEmitPower;\n particleSystem.maxEmitPower = parsedParticleSystem.maxEmitPower;\n particleSystem.emitRate = parsedParticleSystem.emitRate;\n particleSystem.gravity = Vector3.FromArray(parsedParticleSystem.gravity);\n if (parsedParticleSystem.noiseStrength) {\n particleSystem.noiseStrength = Vector3.FromArray(parsedParticleSystem.noiseStrength);\n }\n particleSystem.color1 = Color4.FromArray(parsedParticleSystem.color1);\n particleSystem.color2 = Color4.FromArray(parsedParticleSystem.color2);\n particleSystem.colorDead = Color4.FromArray(parsedParticleSystem.colorDead);\n particleSystem.updateSpeed = parsedParticleSystem.updateSpeed;\n particleSystem.targetStopDuration = parsedParticleSystem.targetStopDuration;\n particleSystem.blendMode = parsedParticleSystem.blendMode;\n if (parsedParticleSystem.colorGradients) {\n for (const colorGradient of parsedParticleSystem.colorGradients) {\n particleSystem.addColorGradient(colorGradient.gradient, Color4.FromArray(colorGradient.color1), colorGradient.color2 ? Color4.FromArray(colorGradient.color2) : undefined);\n }\n }\n if (parsedParticleSystem.rampGradients) {\n for (const rampGradient of parsedParticleSystem.rampGradients) {\n particleSystem.addRampGradient(rampGradient.gradient, Color3.FromArray(rampGradient.color));\n }\n particleSystem.useRampGradients = parsedParticleSystem.useRampGradients;\n }\n if (parsedParticleSystem.colorRemapGradients) {\n for (const colorRemapGradient of parsedParticleSystem.colorRemapGradients) {\n particleSystem.addColorRemapGradient(colorRemapGradient.gradient, colorRemapGradient.factor1 !== undefined ? colorRemapGradient.factor1 : colorRemapGradient.factor, colorRemapGradient.factor2);\n }\n }\n if (parsedParticleSystem.alphaRemapGradients) {\n for (const alphaRemapGradient of parsedParticleSystem.alphaRemapGradients) {\n particleSystem.addAlphaRemapGradient(alphaRemapGradient.gradient, alphaRemapGradient.factor1 !== undefined ? alphaRemapGradient.factor1 : alphaRemapGradient.factor, alphaRemapGradient.factor2);\n }\n }\n if (parsedParticleSystem.sizeGradients) {\n for (const sizeGradient of parsedParticleSystem.sizeGradients) {\n particleSystem.addSizeGradient(sizeGradient.gradient, sizeGradient.factor1 !== undefined ? sizeGradient.factor1 : sizeGradient.factor, sizeGradient.factor2);\n }\n }\n if (parsedParticleSystem.angularSpeedGradients) {\n for (const angularSpeedGradient of parsedParticleSystem.angularSpeedGradients) {\n particleSystem.addAngularSpeedGradient(angularSpeedGradient.gradient, angularSpeedGradient.factor1 !== undefined ? angularSpeedGradient.factor1 : angularSpeedGradient.factor, angularSpeedGradient.factor2);\n }\n }\n if (parsedParticleSystem.velocityGradients) {\n for (const velocityGradient of parsedParticleSystem.velocityGradients) {\n particleSystem.addVelocityGradient(velocityGradient.gradient, velocityGradient.factor1 !== undefined ? velocityGradient.factor1 : velocityGradient.factor, velocityGradient.factor2);\n }\n }\n if (parsedParticleSystem.dragGradients) {\n for (const dragGradient of parsedParticleSystem.dragGradients) {\n particleSystem.addDragGradient(dragGradient.gradient, dragGradient.factor1 !== undefined ? dragGradient.factor1 : dragGradient.factor, dragGradient.factor2);\n }\n }\n if (parsedParticleSystem.emitRateGradients) {\n for (const emitRateGradient of parsedParticleSystem.emitRateGradients) {\n particleSystem.addEmitRateGradient(emitRateGradient.gradient, emitRateGradient.factor1 !== undefined ? emitRateGradient.factor1 : emitRateGradient.factor, emitRateGradient.factor2);\n }\n }\n if (parsedParticleSystem.startSizeGradients) {\n for (const startSizeGradient of parsedParticleSystem.startSizeGradients) {\n particleSystem.addStartSizeGradient(startSizeGradient.gradient, startSizeGradient.factor1 !== undefined ? startSizeGradient.factor1 : startSizeGradient.factor, startSizeGradient.factor2);\n }\n }\n if (parsedParticleSystem.lifeTimeGradients) {\n for (const lifeTimeGradient of parsedParticleSystem.lifeTimeGradients) {\n particleSystem.addLifeTimeGradient(lifeTimeGradient.gradient, lifeTimeGradient.factor1 !== undefined ? lifeTimeGradient.factor1 : lifeTimeGradient.factor, lifeTimeGradient.factor2);\n }\n }\n if (parsedParticleSystem.limitVelocityGradients) {\n for (const limitVelocityGradient of parsedParticleSystem.limitVelocityGradients) {\n particleSystem.addLimitVelocityGradient(limitVelocityGradient.gradient, limitVelocityGradient.factor1 !== undefined ? limitVelocityGradient.factor1 : limitVelocityGradient.factor, limitVelocityGradient.factor2);\n }\n particleSystem.limitVelocityDamping = parsedParticleSystem.limitVelocityDamping;\n }\n if (parsedParticleSystem.noiseTexture && scene) {\n const internalClass = GetClass(\"BABYLON.ProceduralTexture\");\n particleSystem.noiseTexture = internalClass.Parse(parsedParticleSystem.noiseTexture, scene, rootUrl);\n }\n // Emitter\n let emitterType;\n if (parsedParticleSystem.particleEmitterType) {\n switch (parsedParticleSystem.particleEmitterType.type) {\n case \"SphereParticleEmitter\":\n emitterType = new SphereParticleEmitter();\n break;\n case \"SphereDirectedParticleEmitter\":\n emitterType = new SphereDirectedParticleEmitter();\n break;\n case \"ConeEmitter\":\n case \"ConeParticleEmitter\":\n emitterType = new ConeParticleEmitter();\n break;\n case \"CylinderParticleEmitter\":\n emitterType = new CylinderParticleEmitter();\n break;\n case \"CylinderDirectedParticleEmitter\":\n emitterType = new CylinderDirectedParticleEmitter();\n break;\n case \"HemisphericParticleEmitter\":\n emitterType = new HemisphericParticleEmitter();\n break;\n case \"PointParticleEmitter\":\n emitterType = new PointParticleEmitter();\n break;\n case \"MeshParticleEmitter\":\n emitterType = new MeshParticleEmitter();\n break;\n case \"BoxEmitter\":\n case \"BoxParticleEmitter\":\n default:\n emitterType = new BoxParticleEmitter();\n break;\n }\n emitterType.parse(parsedParticleSystem.particleEmitterType, scene);\n }\n else {\n emitterType = new BoxParticleEmitter();\n emitterType.parse(parsedParticleSystem, scene);\n }\n particleSystem.particleEmitterType = emitterType;\n // Animation sheet\n particleSystem.startSpriteCellID = parsedParticleSystem.startSpriteCellID;\n particleSystem.endSpriteCellID = parsedParticleSystem.endSpriteCellID;\n particleSystem.spriteCellLoop = (_a = parsedParticleSystem.spriteCellLoop) !== null && _a !== void 0 ? _a : true;\n particleSystem.spriteCellWidth = parsedParticleSystem.spriteCellWidth;\n particleSystem.spriteCellHeight = parsedParticleSystem.spriteCellHeight;\n particleSystem.spriteCellChangeSpeed = parsedParticleSystem.spriteCellChangeSpeed;\n particleSystem.spriteRandomStartCell = parsedParticleSystem.spriteRandomStartCell;\n particleSystem.disposeOnStop = (_b = parsedParticleSystem.disposeOnStop) !== null && _b !== void 0 ? _b : false;\n particleSystem.manualEmitCount = (_c = parsedParticleSystem.manualEmitCount) !== null && _c !== void 0 ? _c : -1;\n }\n /**\n * Parses a JSON object to create a particle system.\n * @param parsedParticleSystem The JSON object to parse\n * @param sceneOrEngine The scene or the engine to create the particle system in\n * @param rootUrl The root url to use to load external dependencies like texture\n * @param doNotStart Ignore the preventAutoStart attribute and does not start\n * @param capacity defines the system capacity (if null or undefined the sotred capacity will be used)\n * @returns the Parsed particle system\n */\n static Parse(parsedParticleSystem, sceneOrEngine, rootUrl, doNotStart = false, capacity) {\n const name = parsedParticleSystem.name;\n let custom = null;\n let program = null;\n let engine;\n let scene;\n if (sceneOrEngine instanceof ThinEngine) {\n engine = sceneOrEngine;\n }\n else {\n scene = sceneOrEngine;\n engine = scene.getEngine();\n }\n if (parsedParticleSystem.customShader && engine.createEffectForParticles) {\n program = parsedParticleSystem.customShader;\n const defines = program.shaderOptions.defines.length > 0 ? program.shaderOptions.defines.join(\"\\n\") : \"\";\n custom = engine.createEffectForParticles(program.shaderPath.fragmentElement, program.shaderOptions.uniforms, program.shaderOptions.samplers, defines);\n }\n const particleSystem = new ParticleSystem(name, capacity || parsedParticleSystem.capacity, sceneOrEngine, custom, parsedParticleSystem.isAnimationSheetEnabled);\n particleSystem.customShader = program;\n particleSystem._rootUrl = rootUrl;\n if (parsedParticleSystem.id) {\n particleSystem.id = parsedParticleSystem.id;\n }\n // SubEmitters\n if (parsedParticleSystem.subEmitters) {\n particleSystem.subEmitters = [];\n for (const cell of parsedParticleSystem.subEmitters) {\n const cellArray = [];\n for (const sub of cell) {\n cellArray.push(SubEmitter.Parse(sub, sceneOrEngine, rootUrl));\n }\n particleSystem.subEmitters.push(cellArray);\n }\n }\n ParticleSystem._Parse(parsedParticleSystem, particleSystem, sceneOrEngine, rootUrl);\n if (parsedParticleSystem.textureMask) {\n particleSystem.textureMask = Color4.FromArray(parsedParticleSystem.textureMask);\n }\n // Auto start\n if (parsedParticleSystem.preventAutoStart) {\n particleSystem.preventAutoStart = parsedParticleSystem.preventAutoStart;\n }\n if (!doNotStart && !particleSystem.preventAutoStart) {\n particleSystem.start();\n }\n return particleSystem;\n }\n }\n /**\n * Billboard mode will only apply to Y axis\n */\n ParticleSystem.BILLBOARDMODE_Y = 2;\n /**\n * Billboard mode will apply to all axes\n */\n ParticleSystem.BILLBOARDMODE_ALL = 7;\n /**\n * Special billboard mode where the particle will be biilboard to the camera but rotated to align with direction\n */\n ParticleSystem.BILLBOARDMODE_STRETCHED = 8;\n /**\n * Special billboard mode where the particle will be billboard to the camera but only around the axis of the direction of particle emission\n */\n ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL = 9;\n SubEmitter._ParseParticleSystem = ParticleSystem.Parse;\n\n /**\n * Gizmo that enables moving vertices on a mesh.\n */\n class KbVertexSelectGizmo extends KbGizmo {\n get attachedMesh() {\n return this.__attachedMesh;\n }\n set attachedMesh(mesh) {\n this.__attachedMesh = mesh;\n if (this.particleSystem) {\n this.particleSystem.dispose();\n this.particleSystem = undefined;\n }\n if (mesh) {\n this.drawVertices(mesh);\n }\n }\n constructor(kbViewer, scene) {\n super(kbViewer.utilityLayer);\n this.kbViewer = kbViewer;\n this.scene = scene;\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onSelectionChange = new Observable$1();\n this.vertexTracker = new Subject();\n this.particleScale = 0.005;\n this.redrawVertices = false;\n this.__attachedMesh = null;\n this.selectedVertices = new Map();\n this.vertexSelectedColor = new Color4(0.4, 1, 0, 0.5);\n this.vertexUnSelectedColor = new Color4(0, 0.2, 1, 0.5);\n this.vertexTransparentColor = new Color4(0, 0, 0, 0);\n this.verticesUtilLayer = kbViewer.utilityLayer;\n this.attachedMesh = null;\n }\n attachTo(target) {\n const mesh = this.kbViewer.getRendererNode(target);\n if (!mesh) {\n throw Error('Could not find mesh in scene to attach gizmo');\n }\n this.attachedMesh = mesh;\n // Clean up old marquee\n if (this.disposeMarquee) {\n this.disposeMarquee.next();\n this.disposeMarquee.complete();\n }\n this.disposeMarquee = new Subject();\n let selectionMode = null;\n this.kbViewer.interaction\n .enableMarqueeSelect(target, exports.eMarqueeSelectMode.Vertices)\n .pipe(takeUntil(this.disposeMarquee))\n .subscribe(event => {\n if (selectionMode || event.vertexList.length > 0) {\n const vertices = event.vertexList;\n // If user is making a new selection, set the selection mode based on modifier keys\n if (selectionMode === null) {\n if (event.ctrlKey) {\n selectionMode = 'add';\n }\n else if (event.altKey) {\n selectionMode = 'remove';\n }\n else {\n selectionMode = 'new';\n }\n }\n if (selectionMode === 'new') {\n this.selectedVertices.clear();\n }\n if (selectionMode === 'remove') {\n vertices.forEach(vertex => this.selectedVertices.delete(vertex));\n }\n else {\n vertices.forEach(vertex => this.selectedVertices.set(vertex, null));\n }\n this.redraw();\n this.emitSelectionChange();\n }\n });\n this.kbViewer.interaction.onPointerUp.pipe(takeUntil(this.disposeMarquee)).subscribe(() => {\n selectionMode = null;\n });\n }\n updateParticleScale(scale) {\n this.particleScale = scale;\n this.redraw();\n }\n updateGizmoPosition() {\n this.kbViewer.forceAndWaitForNextRender().then(() => {\n var _a;\n if (this.__attachedMesh) {\n this.currentMeshVertexPositions = (_a = this.__attachedMesh\n .getVerticesData(VertexBuffer.PositionKind)) === null || _a === void 0 ? void 0 : _a.slice();\n if (!this.currentMeshVertexPositions) {\n return;\n }\n this.redraw();\n }\n });\n }\n dispose() {\n if (this.particleSystem) {\n this.particleSystem.dispose();\n this.particleSystem = undefined;\n }\n this.disposeMarquee.next();\n this.disposeMarquee.complete();\n this.kbViewer.interaction.disableMarqueeSelect();\n }\n setCustomMesh(mesh) {\n Logger.Error('Custom meshes are not supported on this gizmo.');\n }\n selectVertices(vertexIndices) {\n this.selectedVertices.clear();\n vertexIndices.forEach(vertex => this.selectedVertices.set(vertex, null));\n this.redraw();\n this.emitSelectionChange();\n }\n enableSelectionChange() {\n this.selectionsEnabled = true;\n this.redraw();\n }\n disableSelectionChange() {\n this.selectionsEnabled = false;\n this.redraw();\n this.vertexTracker.complete();\n }\n getBarycenter(indices) {\n let x = 0, y = 0, z = 0;\n const currentMeshVertexPositions = this.currentMeshVertexPositions;\n if (currentMeshVertexPositions) {\n indices.forEach(idx => {\n x += currentMeshVertexPositions[idx * 3];\n y += currentMeshVertexPositions[idx * 3 + 1];\n z += currentMeshVertexPositions[idx * 3 + 2];\n });\n }\n return new exports.KbVector(x / indices.length, y / indices.length, z / indices.length);\n }\n redraw() {\n this.vertexTracker.next(this.selectedVertices.size.toString());\n if (this.particleSystem && this.saveAnimate) {\n this.particleSystem.animate = this.saveAnimate;\n this.redrawVertices = true;\n }\n }\n emitSelectionChange() {\n this.onSelectionChange.notifyObservers({ selectedIndices: Array.from(this.selectedVertices.keys()) });\n }\n drawVertices(targetMesh) {\n var _a;\n if (!this.currentMeshVertexPositions) {\n this.currentMeshVertexPositions = (_a = targetMesh.getVerticesData(VertexBuffer.PositionKind)) === null || _a === void 0 ? void 0 : _a.slice();\n }\n if (!this.currentMeshVertexPositions) {\n return;\n }\n const vertexCount = this.currentMeshVertexPositions.length / 3;\n this.particleSystem = new ParticleSystem('vertexSelectParticleSystem', vertexCount, this.verticesUtilLayer.utilityLayerScene);\n const camera = this.scene.activeCamera instanceof ArcRotateCamera ? this.scene.activeCamera : null;\n const cameraDistance = Vector3.Zero();\n const cameraPosition = Vector3.Zero();\n this.saveAnimate = this.particleSystem.animate.bind(this.particleSystem);\n let particleIdx = 0;\n this.particleSystem.startPositionFunction = (worldMatrix, positionToUpdate, particle) => {\n particleIdx += 3;\n const vertexPositions = this.currentMeshVertexPositions;\n Vector3.TransformCoordinatesFromFloatsToRef(vertexPositions[particleIdx], vertexPositions[particleIdx + 1], vertexPositions[particleIdx + 2], worldMatrix, positionToUpdate);\n };\n const transform = targetMesh.computeWorldMatrix(true);\n this.particleSystem.updateFunction = particles => {\n let particlesToProcess = false;\n if (camera) {\n cameraPosition.copyFrom(getCameraPositionWithOffset(camera));\n }\n for (let i = 0; i < particles.length; i++) {\n const particle = particles[i];\n const vertexPositions = this.currentMeshVertexPositions;\n if (vertexPositions && (particle.age === 0 || this.redrawVertices)) {\n Vector3.TransformCoordinatesFromFloatsToRef(vertexPositions[i * 3], vertexPositions[i * 3 + 1], vertexPositions[i * 3 + 2], transform, particle.position);\n particle.age = 1;\n if (this.selectedVertices.has(i)) {\n particle.color = this.vertexSelectedColor;\n }\n else {\n if (this.selectionsEnabled) {\n particle.color = this.vertexUnSelectedColor;\n }\n else {\n particle.color = this.vertexTransparentColor;\n }\n }\n if (!particlesToProcess) {\n particlesToProcess = true;\n }\n }\n if (camera) {\n cameraPosition.subtractToRef(particle.position, cameraDistance);\n particle.size = (this.particleScale - 0.001) * cameraDistance.length();\n }\n else {\n particle.size = this.particleScale - 0.004;\n }\n }\n this.redrawVertices = false;\n // If there are a large number of particles, kill the updating function for performance\n if (particles.length && particles.length > 10000 && !particlesToProcess && this.particleSystem) {\n // stable\n this.particleSystem.stop();\n this.particleSystem.animate = () => void 0;\n }\n };\n const colorArray = new Uint8Array(3);\n for (let i = 0; i < colorArray.length; i += 3) {\n colorArray[i] = 225;\n colorArray[i + 1] = 225;\n colorArray[i + 2] = 225;\n }\n this.particleSystem.emitter = targetMesh;\n this.particleSystem.minSize = this.particleScale;\n this.particleSystem.maxSize = this.particleScale;\n this.particleSystem.disposeOnStop = false;\n this.particleSystem.particleTexture = RawTexture.CreateRGBTexture(colorArray, 1, 1, this.verticesUtilLayer.utilityLayerScene);\n this.particleSystem.manualEmitCount = vertexCount;\n // this.particleSystem.emitRate\n this.particleSystem.start();\n }\n }\n\n /**\n * Gizmo that enables dragging and rotating lights\n */\n class KbViewpointGizmo extends KbGizmo {\n attachTo(viewpoint) {\n var _a;\n // Get rid of any old gizmos\n if (this.posGizmo) {\n this.posGizmo.dispose();\n this.posGizmo = undefined;\n }\n if (this.targetGizmo) {\n this.targetGizmo.dispose();\n this.targetGizmo = undefined;\n }\n if (this.rotGizmo) {\n this.rotGizmo.dispose();\n this.rotGizmo = undefined;\n }\n // Create mesh to attach gizmos to, and the camera preview visualization attached to that mesh\n this._visualMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene);\n const { targetPositionMarker, viewpointPositionGizmo } = createViewpointVisualization(viewpoint, this.gizmoLayer.utilityLayerScene);\n this._visualMesh.addChild(viewpointPositionGizmo);\n // Always create the position gizmo\n this.posGizmo = new KbPositionGizmo(this.kbViewer, this.gizmoLayer);\n this.previousTargetMode = viewpoint.targetMode;\n // Determine which gizmos to show. No extra gizmos for overhead camera (only position)\n // For the target point type viewpoint, make a separate mesh to hold the position gizmo\n if (viewpoint.type === exports.eViewpointType.overhead) {\n viewpointPositionGizmo.scaling = new Vector3(1, -1, 1);\n viewpointPositionGizmo.bakeCurrentTransformIntoVertices();\n }\n else {\n if (viewpoint.targetMode === exports.eViewpointTargetMode.rotation) {\n this.rotGizmo = new KbRotationGizmo(this.kbViewer, this.gizmoLayer, { x: true, y: true, z: false });\n // The first person camera is oriented pointing parallel to the +Z axis\n if (viewpoint.type == exports.eViewpointType.firstPerson) {\n viewpointPositionGizmo.rotate(Vector3.Right(), Math.PI / 2);\n viewpointPositionGizmo.bakeCurrentTransformIntoVertices();\n }\n }\n else if (viewpoint.targetMode === exports.eViewpointTargetMode.point) {\n this._gizmoMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene);\n this._targetVisualMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene);\n if (targetPositionMarker) {\n (_a = this._targetVisualMesh) === null || _a === void 0 ? void 0 : _a.addChild(targetPositionMarker);\n }\n this.targetGizmo = new KbPositionGizmo(this.kbViewer, this.gizmoLayer);\n }\n }\n if (!this._gizmoMesh) {\n this._gizmoMesh = this._visualMesh;\n }\n else {\n this._visualMesh.isPickable = false;\n }\n this.updateHelperMeshes(viewpoint);\n // Set up event handlers on the gizmos\n if (this.posGizmo) {\n this.posGizmo.attachedMesh = this._gizmoMesh;\n const positionChange = Vector3.Zero();\n this.posGizmo.onDragStartObservable.add(event => {\n positionChange.setAll(0);\n this.onDragStartObservable.notifyObservers();\n });\n this.posGizmo.onDragObservable.add(event => {\n var _a;\n if (this._gizmoMesh !== this._visualMesh) {\n (_a = this._visualMesh) === null || _a === void 0 ? void 0 : _a.position.addInPlace(event.delta);\n }\n positionChange.addInPlace(event.delta);\n this.onDragObservable.notifyObservers({ deltaPos: event.delta });\n this.updateHelperMeshDirectionToRotation(this._attachedViewpoint);\n });\n this.posGizmo.onDragEndObservable.add(event => {\n this.onDragEndObservable.notifyObservers({ deltaPos: positionChange });\n });\n }\n if (this.targetGizmo) {\n this.targetGizmo.attachedMesh = this._targetVisualMesh;\n const targetChange = Vector3.Zero();\n this.targetGizmo.onDragStartObservable.add(event => {\n targetChange.setAll(0);\n this.onDragStartObservable.notifyObservers();\n });\n this.targetGizmo.onDragObservable.add(event => {\n targetChange.addInPlace(event.delta);\n this.onDragObservable.notifyObservers({ deltaTargetPos: event.delta });\n this.updateHelperMeshDirectionToRotation(this._attachedViewpoint);\n });\n this.targetGizmo.onDragEndObservable.add(event => {\n this.onDragEndObservable.notifyObservers({ deltaTargetPos: targetChange });\n });\n }\n if (this.rotGizmo) {\n this.rotGizmo.attachedMesh = this._visualMesh;\n let rotationChange = this._visualMesh.rotationQuaternion || Quaternion.Identity();\n this.rotGizmo.onDragStartObservable.add(event => {\n this.onDragStartObservable.notifyObservers();\n rotationChange = Quaternion.Identity();\n });\n this.rotGizmo.onDragObservable.add(event => {\n const { delta } = event;\n rotationChange.multiplyInPlace(delta);\n this.onDragObservable.notifyObservers({ deltaRotation: delta });\n });\n this.rotGizmo.onDragEndObservable.add(() => {\n this.onDragEndObservable.notifyObservers({ deltaRotation: rotationChange });\n });\n }\n this._attachedViewpoint = viewpoint;\n }\n updateGizmoPosition(viewpointNode) {\n if (viewpointNode && viewpointNode !== this._attachedViewpoint) {\n this._attachedViewpoint = viewpointNode;\n }\n // If the target mode changed, rebuild the gizmo\n if (this._attachedViewpoint && this.previousTargetMode !== this._attachedViewpoint.targetMode) {\n const viewpoint = this._attachedViewpoint;\n this.dispose(true);\n this.attachTo(viewpoint);\n }\n else {\n if (this._attachedViewpoint) {\n this.updateHelperMeshes(this._attachedViewpoint);\n }\n super.updateGizmoPosition();\n }\n }\n updateHelperMeshes(viewpoint) {\n if (!this._visualMesh || !this._gizmoMesh) {\n return;\n }\n this._visualMesh.position = viewpoint.position.toVec3();\n this._gizmoMesh.position = viewpoint.position.toVec3();\n if (this._targetVisualMesh) {\n this._targetVisualMesh.position = viewpoint.targetPoint.toVec3();\n }\n if (viewpoint.targetMode === exports.eViewpointTargetMode.rotation) {\n const eulerRot = viewpoint.rotation.toVec3().scale(Math.PI / 180);\n this._visualMesh.rotationQuaternion = Quaternion.FromEulerVector(eulerRot);\n }\n else {\n this.updateHelperMeshDirectionToRotation(viewpoint);\n }\n }\n updateHelperMeshDirectionToRotation(viewpoint, delta) {\n if (!this._visualMesh) {\n return;\n }\n if (!delta) {\n delta = Vector3.Zero();\n }\n const _visualMesh = this._visualMesh;\n if (viewpoint.targetMode !== exports.eViewpointTargetMode.rotation) {\n let direction;\n if (this._targetVisualMesh) {\n direction = this._targetVisualMesh.position.subtract(_visualMesh.position);\n }\n else {\n // mesh\n const targetMeshNode = viewpoint._manager.getById(viewpoint.targetMeshId);\n if (targetMeshNode) {\n direction = targetMeshNode.position.subtract(viewpoint.position).toVec3();\n }\n else {\n direction = Vector3.Zero();\n }\n }\n const rotation = rotationToVector(direction);\n _visualMesh.rotationQuaternion = rotation;\n // This code is for fixing the rotation of the camera gizmo so that the x axis is always in the XZ plane (keeping the camera model level with the horizon.)\n // But, it is not working quite right.\n // _visualMesh.computeWorldMatrix(true);\n // let newXAxis = _visualMesh.getDirection(Vector3.Right());\n // const correction = rotationToVector(direction.cross(Vector3.Up()), newXAxis);\n // _visualMesh.rotationQuaternion = _visualMesh.rotationQuaternion.multiply(correction);\n }\n }\n /**\n * Creates a PositionGizmo\n * @param gizmoLayer The utility layer the gizmo will be added to\n */\n constructor(kbViewer, gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer) {\n super(gizmoLayer);\n this.kbViewer = kbViewer;\n /** Fires an event when any of it's sub gizmos are dragged */\n this.onDragStartObservable = new Observable$1();\n /** Fires an event while any of it's sub gizmos are dragged */\n this.onDragObservable = new Observable$1();\n /** Fires an event when any of it's sub gizmos are released from dragging */\n this.onDragEndObservable = new Observable$1();\n this.attachedMesh = null;\n }\n /**\n * Disposes of the gizmo\n */\n dispose(recreate) {\n if (this.posGizmo) {\n this.posGizmo.dispose();\n }\n if (this.rotGizmo) {\n this.rotGizmo.dispose();\n }\n if (this.targetGizmo) {\n this.targetGizmo.dispose();\n }\n if (this._visualMesh) {\n this._visualMesh.dispose();\n }\n if (this._targetVisualMesh) {\n this._targetVisualMesh.dispose();\n }\n if (this.viewpointPositionGizmo) {\n this.viewpointPositionGizmo.dispose();\n }\n if (!recreate) {\n this.onDragStartObservable.clear();\n this.onDragEndObservable.clear();\n delete this._attachedViewpoint;\n }\n }\n }\n\n /**\n * Manages the various gizmos and their connections to the scene meshes.\n * Keeps track of what gizmo is active and the selected meshes to put the gizmos on.\n * @param scene The root scene on which the utility/gizmo layer will be placed.\n * @param camera The camera being used. Required by some gizmos for displaying them correctly\n */\n const PREVIEW_NAME = '__UV_PREVIEW_MATERIAL__';\n class GizmoTools {\n constructor(scene, kbViewer) {\n this.kbViewer = kbViewer;\n this.activeGizmoSettings = [];\n this.dragging = false;\n this.uvMapStoredMaterials = new Map();\n this.scene = scene;\n this.gizmoLayer = kbViewer.utilityLayer;\n this.gizmoLayer.utilityLayerScene.useRightHandedSystem = true;\n }\n selectLight(lightNode) {\n const lightGizmo = new KbLightGizmo(this.kbViewer, this.gizmoLayer);\n const updatePosition = new Subject();\n const updateDirection = new Subject();\n const totalDeltaPosition = new Subject();\n this.activeGizmoSettings.push({\n subjects: [updatePosition, updateDirection, totalDeltaPosition],\n gizmo: lightGizmo,\n });\n lightGizmo.attachTo(lightNode);\n this.dragging = false;\n return {\n updateLightGizmo: (node) => {\n lightGizmo.updateGizmoPosition(node);\n },\n };\n }\n selectViewpoint(viewpoint) {\n const viewpointGizmo = new KbViewpointGizmo(this.kbViewer, this.gizmoLayer);\n viewpointGizmo.attachTo(viewpoint);\n const updatePosition = new Subject();\n const updateTargetPosition = new Subject();\n const updateRotation = new Subject();\n const totalDeltaPosition = new Subject();\n const totalDeltaTargetPosition = new Subject();\n const totalDeltaRotation = new Subject();\n this.activeGizmoSettings.push({\n subjects: [\n updatePosition,\n updateTargetPosition,\n updateRotation,\n totalDeltaPosition,\n totalDeltaTargetPosition,\n totalDeltaRotation,\n ],\n gizmo: viewpointGizmo,\n });\n this.dragging = false;\n const totalDeltaPositionQueue = Vector3.Zero();\n const totalDeltaTargetPositionQueue = Vector3.Zero();\n const totalDeltaRotationQueue = Quaternion.Identity();\n viewpointGizmo.onDragStartObservable.add(() => {\n this.dragging = true;\n });\n viewpointGizmo.onDragObservable.add(event => {\n if (this.dragging) {\n if (event.deltaPos) {\n updatePosition.next(exports.KbVector.FromVec3(event.deltaPos));\n totalDeltaPositionQueue.addInPlace(event.deltaPos);\n }\n if (event.deltaTargetPos) {\n updateTargetPosition.next(exports.KbVector.FromVec3(event.deltaTargetPos));\n totalDeltaTargetPositionQueue.addInPlace(event.deltaTargetPos);\n }\n if (event.deltaRotation) {\n updateRotation.next(exports.KbVector.FromVec3(event.deltaRotation.toEulerAngles().scale(180 / Math.PI)));\n totalDeltaRotationQueue.multiplyInPlace(event.deltaRotation);\n }\n }\n });\n viewpointGizmo.onDragEndObservable.add(() => {\n if (this.dragging) {\n this.dragging = false;\n if (!totalDeltaPositionQueue.equalsToFloats(0, 0, 0)) {\n totalDeltaPosition.next(exports.KbVector.FromVec3(totalDeltaPositionQueue));\n totalDeltaPositionQueue.setAll(0);\n }\n else if (!totalDeltaTargetPositionQueue.equalsToFloats(0, 0, 0)) {\n totalDeltaTargetPosition.next(exports.KbVector.FromVec3(totalDeltaTargetPositionQueue));\n totalDeltaTargetPositionQueue.setAll(0);\n }\n else if (!totalDeltaRotationQueue.equals(Quaternion.Identity())) {\n totalDeltaRotation.next(exports.KbVector.FromVec3(totalDeltaRotationQueue.toEulerAngles().scale(180 / Math.PI)));\n totalDeltaRotationQueue.copyFrom(Quaternion.Identity());\n }\n }\n });\n return {\n updatePosition: updatePosition.asObservable(),\n updateTargetPosition: updateTargetPosition.asObservable(),\n updateRotation: updateRotation.asObservable(),\n totalDeltaPosition: totalDeltaPosition.asObservable(),\n totalDeltaTargetPosition: totalDeltaTargetPosition.asObservable(),\n totalDeltaRotation: totalDeltaRotation.asObservable(),\n updateViewpointGizmo: (node) => {\n viewpointGizmo.updateGizmoPosition(node);\n },\n };\n }\n position(target, positionSpace, axisVisibility, orientGizmo) {\n const positionGizmo = new KbPositionGizmo(this.kbViewer, this.gizmoLayer, axisVisibility);\n positionGizmo.attachTo(target, positionSpace, orientGizmo);\n const updatePosition = new Subject();\n const totalDelta = new Subject();\n this.activeGizmoSettings.push({\n subjects: [updatePosition, totalDelta],\n gizmo: positionGizmo,\n });\n this.dragging = false;\n let totalDeltaQueue = Vector3.Zero();\n positionGizmo.onDragStartObservable.add(() => {\n this.dragging = true;\n });\n positionGizmo.onDragObservable.add(event => {\n if (this.dragging) {\n totalDeltaQueue.addInPlace(event.delta);\n updatePosition.next(exports.KbVector.FromVec3(event.delta));\n }\n });\n positionGizmo.onDragEndObservable.add(() => {\n if (this.dragging) {\n totalDelta.next(exports.KbVector.FromVec3(totalDeltaQueue));\n totalDeltaQueue = Vector3.Zero();\n this.dragging = false;\n }\n });\n return {\n update: updatePosition.asObservable(),\n totalDelta: totalDelta.asObservable(),\n updateGizmoPosition: (update) => positionGizmo.updateGizmoPosition(update),\n dispose: () => this.clearGizmo(positionGizmo),\n };\n }\n rotateAxisAngle(target, positionSpace, options) {\n const updateAxisAngle = new Subject();\n const totalDelta = new Subject();\n const totalDeltaQueue = { axis: Vector3.Zero(), angle: 0 };\n const axisAngleGizmo = new KbAxisAngleGizmo(this.kbViewer, this.gizmoLayer, options === null || options === void 0 ? void 0 : options.disableAngle);\n axisAngleGizmo.attachTo(target, positionSpace, options === null || options === void 0 ? void 0 : options.placementOffset);\n this.activeGizmoSettings.push({\n subjects: [updateAxisAngle, totalDelta],\n gizmo: axisAngleGizmo,\n });\n this.dragging = false;\n axisAngleGizmo.onDragStartObservable.add(() => {\n this.dragging = true;\n });\n axisAngleGizmo.onDragObservable.add(event => {\n if (this.dragging) {\n const angle = (event.deltaAngle * 180) / Math.PI;\n totalDeltaQueue.axis.addInPlace(event.deltaAxis);\n totalDeltaQueue.angle += angle;\n updateAxisAngle.next({ axis: exports.KbVector.FromVec3(event.deltaAxis), angle });\n }\n });\n axisAngleGizmo.onDragEndObservable.add(() => {\n if (this.dragging) {\n totalDelta.next({ axis: exports.KbVector.FromVec3(totalDeltaQueue.axis), angle: totalDeltaQueue.angle });\n totalDeltaQueue.axis = Vector3.Zero();\n totalDeltaQueue.angle = 0;\n this.dragging = false;\n }\n });\n return {\n update: updateAxisAngle.asObservable(),\n totalDelta: totalDelta.asObservable(),\n updateGizmoPosition: (updateAxis, updatePosition) => axisAngleGizmo.updateGizmoPosition(updateAxis, updatePosition),\n dispose: () => this.clearGizmo(axisAngleGizmo),\n };\n }\n /**\n * Creates a rotation gizmo that can rotate many items\n * nodes will be rotated and repositioned in space if the center of rotation is not equal to the position\n * vectors will be repositioned in space as if each vector is the position of a point\n */\n rotate(targets, positionSpace, placementOffset, axisVisibility) {\n var _a, _b;\n let gizmoOffset = Vector3.Zero();\n // Get the transform matrix to get the world space rotation and coordinates of the node we are rotating\n let positionTransform;\n if (positionSpace) {\n positionTransform = (_a = this.kbViewer.getRendererNode(positionSpace)) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n }\n else if (targets[0] instanceof exports.SpaceNode && targets[0]._parent) {\n positionTransform = (_b = this.kbViewer.getRendererNode(targets[0]._parent)) === null || _b === void 0 ? void 0 : _b.computeWorldMatrix(true);\n }\n const rotationGizmo = new KbRotationGizmo(this.kbViewer, this.gizmoLayer, undefined, axisVisibility);\n if (targets.length === 1) {\n const target = targets[0];\n rotationGizmo.attachTo(target, positionSpace, placementOffset);\n }\n else {\n // If multiple targets are selected, put the pivot in the average of the positions\n // Maybe enhance this to use bounding box later, if that's important...\n const pivot = targets\n .reduce((result, current) => {\n return result.add(current instanceof exports.SpaceNode ? current.position : current);\n }, exports.KbVector.Zero())\n .scale(1 / targets.length);\n rotationGizmo.attachTo(exports.KbVector.Zero(), undefined, pivot);\n }\n const update = new Subject();\n const totalDelta = new Subject();\n this.activeGizmoSettings.push({\n subjects: [update, totalDelta],\n gizmo: rotationGizmo,\n });\n this.dragging = false;\n let totalDeltaQueue = {\n rotation: Quaternion.Identity(),\n position: Vector3.Zero(),\n axisTranslate: Vector3.Zero(),\n };\n // Set up caches for the positions and rotations of the nodes because it's not guaranteed that they will be updated by reference\n // And as you drag the nodes these values will change and the gizmos won't be dragging in the right direction anymore\n const positions = targets.map(target => target instanceof exports.SpaceNode ? target.position.toVec3() : target.toVec3());\n const axes = targets.map(target => (target instanceof exports.SpaceNode ? target.rotationAxis.toVec3() : null));\n const quaternionCache = targets.map(target => target instanceof exports.SpaceNode\n ? Quaternion.FromEulerVector(target.eulerRotation.toVec3().scale(Math.PI / 180))\n : Quaternion.Identity());\n // Get the current pivot which will always be where the gizmo is located (minus the offset which just visually offsets the gizmo position)\n let gizmoPosition = rotationGizmo.attachedMesh.position;\n rotationGizmo.onDragStartObservable.add(() => {\n this.dragging = true;\n if (rotationGizmo.gizmoOffset) {\n gizmoOffset = rotationGizmo.gizmoOffset.toVec3();\n }\n if (gizmoOffset) {\n gizmoPosition = gizmoPosition.subtract(gizmoOffset);\n }\n });\n rotationGizmo.onDragObservable.add(event => {\n if (this.dragging) {\n const result = [];\n const rotationMatrix = new Matrix();\n const gizmoRotation = rotationGizmo.attachedMesh.rotationQuaternion || Quaternion.Identity();\n // Get the true world space rotation in the case that the gizmo is rotated\n // The gizmos output their rotation deltas in local space\n const meshSpaceRotation = gizmoRotation.multiply(event.delta).multiply(gizmoRotation.conjugate());\n meshSpaceRotation.toRotationMatrix(rotationMatrix);\n const worldTransformMatrix = new Matrix();\n event.delta.toRotationMatrix(worldTransformMatrix);\n worldTransformMatrix.multiplyToRef(rotationGizmo.attachedMesh.computeWorldMatrix(), worldTransformMatrix);\n // Inverse the position transform to rotate the delta back into local \"positionSpace\" space\n const positionTransformInv = positionTransform === null || positionTransform === void 0 ? void 0 : positionTransform.clone().invert();\n positions.forEach((position, index) => {\n var _a;\n let positionDelta;\n let axisDelta;\n const target = targets[index];\n const axis = axes[index];\n // If the node is a space node, then rotate it around the pivot to get the updated position\n if (target instanceof exports.SpaceNode) {\n // Treat the pivot point as the center of the node so the node rotates around the pivot point\n let worldNodePivot = target.pivot.toVec3();\n const nodeTransform = (_a = this.kbViewer.getRendererNode(target)) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n if (nodeTransform) {\n worldNodePivot = Vector3.TransformCoordinates(worldNodePivot, nodeTransform);\n }\n positionDelta = Vector3.TransformCoordinates(worldNodePivot.subtract(gizmoPosition), rotationMatrix)\n .add(gizmoPosition)\n .subtract(worldNodePivot);\n // If the node is a vector, then it's a direction vector, so we want to rotate it as if the vector started from the origin.\n // So don't rotate around the pivot point. The updated position will actually be the updated direction.\n }\n else {\n positionDelta = Vector3.TransformCoordinates(position, rotationMatrix).subtract(position);\n }\n if (axis) {\n axisDelta = Vector3.TransformCoordinates(axis.length() === 0 ? new Vector3(0, 1, 0) : axis, rotationMatrix).subtract(axis);\n axis.addInPlace(axisDelta);\n }\n // Rotate the delta vector into local \"positionSpace\" space\n if (positionTransformInv) {\n positionDelta = Vector3.TransformCoordinates(positionDelta, positionTransformInv.getRotationMatrix());\n }\n // Update the position cache by reference (make sure this position variable isn't shadowed)\n position.addInPlace(positionDelta);\n totalDeltaQueue.position.addInPlace(positionDelta);\n if (axisDelta) {\n totalDeltaQueue.axisTranslate.addInPlace(axisDelta);\n }\n // Get the rotation delta by converting the previous quaternion rotation to euler, rotating to the new position, and getting euler angles of that.\n // This is necessary because it we output the plain quaternion delta euler, the euler rotation order could result\n // In an incorrect rotation if there are other euler angles being rotated first\n const previousAngle = quaternionCache[index].toEulerAngles();\n quaternionCache[index].multiplyInPlace(event.delta);\n const newAngle = quaternionCache[index].toEulerAngles();\n totalDeltaQueue.rotation.multiplyInPlace(event.delta);\n result.push({\n position: exports.KbVector.FromVec3(positionDelta),\n rotation: exports.KbVector.FromVec3(newAngle.subtract(previousAngle).scale(180 / Math.PI)),\n worldTransformMatrix: worldTransformMatrix,\n axisTranslate: axisDelta ? exports.KbVector.FromVec3(axisDelta) : exports.KbVector.Zero(),\n });\n });\n update.next(result);\n }\n });\n rotationGizmo.onDragEndObservable.add(() => {\n if (this.dragging) {\n totalDelta.next({\n rotation: exports.KbVector.FromVec3(totalDeltaQueue.rotation.toEulerAngles().scale(180 / Math.PI)),\n position: exports.KbVector.FromVec3(totalDeltaQueue.position),\n axisTranslate: exports.KbVector.FromVec3(totalDeltaQueue.axisTranslate),\n });\n totalDeltaQueue = {\n rotation: Quaternion.Identity(),\n position: Vector3.Zero(),\n axisTranslate: Vector3.Zero(),\n };\n this.dragging = false;\n }\n });\n return {\n update: update.asObservable(),\n totalDelta: totalDelta.asObservable(),\n updateGizmoPosition: (update, offset) => rotationGizmo.updateGizmoPosition(update, offset),\n dispose: () => this.clearGizmo(rotationGizmo),\n };\n }\n scale(targets, positionSpace) {\n // if (targets.length === 0) {\n // return {\n // update: empty(),\n // totalDelta: empty(),\n // };\n // }\n var _a, _b;\n const scaleGizmo = new KbScaleGizmo(this.kbViewer, this.gizmoLayer);\n if (targets.length === 1) {\n const target = targets[0];\n scaleGizmo.attachTo(target, positionSpace);\n }\n else {\n // If multiple targets are selected, put the pivot in the average of the positions\n // Maybe enhance this to use bounding box later, if that's important...\n const pivot = targets\n .reduce((result, current) => {\n return result.add(current instanceof exports.SpaceNode ? current.position : current);\n }, exports.KbVector.Zero())\n .scale(1 / targets.length);\n scaleGizmo.attachTo(pivot, positionSpace);\n }\n const update = new Subject();\n const totalDelta = new Subject();\n this.activeGizmoSettings.push({\n subjects: [update, totalDelta],\n gizmo: scaleGizmo,\n });\n this.dragging = false;\n let totalDeltaQueue = Vector3.Zero();\n let positionTransform;\n // Get the transform matrix to get the world space rotation and coordinates of the node we are scaling\n if (positionSpace) {\n positionTransform = (_a = this.kbViewer.getRendererNode(positionSpace)) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n }\n else if (targets[0] instanceof exports.SpaceNode && targets[0]._parent) {\n positionTransform = (_b = this.kbViewer.getRendererNode(targets[0]._parent)) === null || _b === void 0 ? void 0 : _b.computeWorldMatrix(true);\n }\n // Get the current pivot which will always be where the gizmo is located\n let gizmoPosition = scaleGizmo.attachedMesh.position;\n scaleGizmo.onDragStartObservable.add(() => {\n this.dragging = true;\n if (scaleGizmo.gizmoOffset) {\n gizmoPosition = gizmoPosition.subtract(scaleGizmo.gizmoOffset.toVec3());\n }\n });\n scaleGizmo.onDragObservable.add(event => {\n if (this.dragging) {\n const result = [];\n targets.forEach(target => {\n var _a;\n let positionDelta;\n // If the node is a space node, then rotate it around the pivot to get the updated position\n if (target instanceof exports.SpaceNode) {\n // Treat the pivot point as the center of the node so the node rotates around the pivot point\n let worldNodePivot = target.pivot.toVec3();\n const nodeTransform = (_a = this.kbViewer.getRendererNode(target)) === null || _a === void 0 ? void 0 : _a.computeWorldMatrix(true);\n if (nodeTransform) {\n worldNodePivot = Vector3.TransformCoordinates(worldNodePivot, nodeTransform);\n }\n positionDelta = worldNodePivot\n .subtract(gizmoPosition)\n .multiply(event.delta)\n .add(gizmoPosition)\n .subtract(worldNodePivot);\n // If the node is a vector, then it's a direction vector, so we want to rotate it as if the vector started from the origin.\n // So don't rotate around the pivot point. The updated position will actually be the updated direction.\n }\n else {\n // Transform the node position to world space because the pivot and gizmo will be in world space as well\n let worldPosition = target.toVec3();\n if (positionTransform) {\n worldPosition = Vector3.TransformCoordinates(worldPosition, positionTransform);\n }\n positionDelta = worldPosition.multiply(event.delta).subtract(worldPosition);\n }\n totalDeltaQueue.addInPlace(event.delta);\n result.push({\n position: exports.KbVector.FromVec3(positionDelta),\n scaling: exports.KbVector.FromVec3(event.delta),\n });\n });\n update.next(result);\n }\n });\n scaleGizmo.onDragEndObservable.add(() => {\n if (this.dragging) {\n totalDelta.next(exports.KbVector.FromVec3(totalDeltaQueue));\n totalDeltaQueue = Vector3.Zero();\n this.dragging = false;\n }\n });\n return {\n update: update.asObservable(),\n totalDelta: totalDelta.asObservable(),\n updateGizmoPosition: (update) => scaleGizmo.updateGizmoPosition(update),\n dispose: () => this.clearGizmo(scaleGizmo),\n };\n }\n selectVertices(target, selectedVertices) {\n const vertexSelectionGizmo = new KbVertexSelectGizmo(this.kbViewer, this.scene);\n vertexSelectionGizmo.attachTo(target);\n const update = new Subject();\n this.activeGizmoSettings.push({\n subjects: [update],\n gizmo: vertexSelectionGizmo,\n });\n if (selectedVertices) {\n vertexSelectionGizmo.selectVertices(selectedVertices);\n }\n this.dragging = false;\n vertexSelectionGizmo.onSelectionChange.add(result => {\n if (result) {\n update.next({\n vertexIndices: result.selectedIndices,\n });\n }\n });\n return {\n update: update.asObservable(),\n vertexTracker: vertexSelectionGizmo.vertexTracker,\n updateGizmoPositions: () => vertexSelectionGizmo.updateGizmoPosition(),\n updateParticleScale: (scale) => vertexSelectionGizmo.updateParticleScale(scale),\n disableSelectionChange: () => vertexSelectionGizmo.disableSelectionChange(),\n enableSelectionChange: () => vertexSelectionGizmo.enableSelectionChange(),\n getBarycenter: (indices) => vertexSelectionGizmo.getBarycenter(indices),\n dispose: () => this.clearGizmo(vertexSelectionGizmo),\n };\n }\n selectFacets(target, selectedVertices) {\n const facetSelectionGizmo = new KbFacetSelectGizmo(this.kbViewer, this.scene);\n facetSelectionGizmo.attachTo(target);\n const update = new Subject();\n this.activeGizmoSettings.push({\n subjects: [update],\n gizmo: facetSelectionGizmo,\n });\n if (selectedVertices) {\n facetSelectionGizmo.selectFacetGroups(selectedVertices);\n }\n this.dragging = false;\n facetSelectionGizmo.onSelectionChange.add(result => {\n if (result) {\n update.next({\n selectedFacets: result.selectedFacets,\n });\n }\n });\n return {\n update: update.asObservable(),\n updateGizmoPositions: () => facetSelectionGizmo.updateGizmoPosition(),\n disableSelectionChange: () => facetSelectionGizmo.disableSelectionChange(),\n enableSelectionChange: () => facetSelectionGizmo.enableSelectionChange(),\n dispose: () => this.clearGizmo(facetSelectionGizmo),\n setBackfaceCulling: (enabled) => facetSelectionGizmo.setBackfaceCulling(enabled),\n setTolerance: (tolerance) => facetSelectionGizmo.setTolerance(tolerance),\n setVisualization: (opacity) => facetSelectionGizmo.setVisualization(opacity),\n expandSelection: (tolerance) => facetSelectionGizmo.expandSelection(tolerance),\n };\n }\n clearGizmo(gizmo) {\n if (gizmo) {\n const index = this.activeGizmoSettings.findIndex(g => g.gizmo === gizmo);\n if (index >= 0) {\n const gizmoSettings = this.activeGizmoSettings[index];\n gizmoSettings.subjects.forEach(subject => subject.complete());\n gizmoSettings.gizmo.dispose();\n this.activeGizmoSettings.splice(index, 1);\n }\n }\n else {\n this.activeGizmoSettings.forEach(gizmoSettings => {\n gizmoSettings.subjects.forEach(subject => subject.complete());\n gizmoSettings.gizmo.dispose();\n });\n this.activeGizmoSettings = [];\n }\n }\n updateGizmoPositions() {\n if (!this.dragging) {\n this.activeGizmoSettings.forEach(gizmoSettings => {\n gizmoSettings.gizmo.updateGizmoPosition();\n });\n }\n }\n showUvMapMaterial(target) {\n if (target._showMaterial && target._previewMaterialVisible) {\n if (target._parent) {\n const mesh = this.kbViewer.getRendererNode(target._parent);\n if (mesh instanceof Mesh) {\n if (mesh.material != null && mesh.material.name != PREVIEW_NAME) {\n const previousMaterial = mesh.material;\n this.uvMapStoredMaterials.set(target.id, previousMaterial);\n }\n if (!this.previewMaterial) {\n this.previewMaterial = new PBRMaterial(PREVIEW_NAME, this.kbViewer.scene);\n const previewTexture = new Texture('/assets/images/uv_colorgrid.png', this.kbViewer.scene);\n this.previewMaterial.albedoTexture = previewTexture;\n this.previewMaterial.albedoColor = Color3.White();\n this.previewMaterial.metallic = 0;\n this.previewMaterial.roughness = 1;\n }\n mesh.material = this.previewMaterial;\n }\n }\n }\n else {\n if (target._parent) {\n const mesh = this.kbViewer.getRendererNode(target._parent);\n if (mesh instanceof Mesh) {\n const storedMaterial = this.uvMapStoredMaterials.get(target.id);\n if (storedMaterial) {\n mesh.material = storedMaterial;\n }\n }\n }\n }\n }\n // Bounding mesh code is not used right now, but it may be useful when we are doing mates\n // private calculateBoundingBox(nodes: TransformNode[]) {\n // const meshes = nodes.filter((node): node is Mesh => node instanceof Mesh);\n // meshes.forEach(mesh => mesh.computeWorldMatrix(true));\n // if (meshes.length === 0) {\n // return {\n // pivot: Vector3.Zero(),\n // boundingInfo: new BoundingInfo(Vector3.Zero(), Vector3.Zero())\n // };\n // }\n // let boundingInfo = meshes[0].getBoundingInfo();\n // let minimumWorld = boundingInfo.boundingBox.minimumWorld;\n // let maximumWorld = boundingInfo.boundingBox.maximumWorld;\n // for (let i = 1; i < meshes.length; i++) {\n // let boundingInfo = meshes[i].getBoundingInfo();\n // minimumWorld = Vector3.Minimize(minimumWorld, boundingInfo.boundingBox.minimumWorld);\n // maximumWorld = Vector3.Maximize(maximumWorld, boundingInfo.boundingBox.maximumWorld);\n // }\n // let bounding = new BoundingInfo(minimumWorld, maximumWorld);\n // let middlePivot = new Vector3(bounding.boundingBox.center.x, bounding.boundingBox.center.y, bounding.boundingBox.center.z);\n // return {\n // pivot: middlePivot,\n // boundingInfo: bounding\n // };\n // }\n // private displayKbBoundingBox(mesh: Mesh) {\n // let oMesh: Mesh & { kbBoundingBox?: boundingBoxGeometry };\n // oMesh = mesh;\n // var bbNode: boundingBoxGeometry;\n // if (this.currentSelectedMeshes.length === 0) {\n // if (oMesh.kbBoundingBox) {\n // oMesh.kbBoundingBox.wireFrame.dispose();\n // delete oMesh.kbBoundingBox;\n // }\n // return;\n // }\n // // if the mesh is resized/rotated/something we need to recalculate the bounding box\n // mesh.computeWorldMatrix(true);\n // mesh.refreshBoundingInfo();\n // mesh.refreshBoundingInfo = (applySkeleton?: boolean) => {\n // return mesh;\n // };\n // const center = mesh.getBoundingInfo().boundingBox.centerWorld.clone();\n // const diagonalLen = mesh.getBoundingInfo().diagonalLength;\n // const min = mesh.getBoundingInfo().boundingBox.minimumWorld;\n // const max = mesh.getBoundingInfo().boundingBox.maximumWorld;\n // const d = max.subtract(min);\n // const bOffset = 0.02;\n // d.x += bOffset;\n // d.y += bOffset;\n // d.z += bOffset;\n // // calculate the position of the bounding box vertices\n // const v1 = new Vector3(center.x - d.x / 2, center.y + d.y / 2, center.z + d.z / 2);\n // const v2 = new Vector3(center.x + d.x / 2, center.y + d.y / 2, center.z + d.z / 2);\n // const v3 = new Vector3(center.x - d.x / 2, center.y - d.y / 2, center.z + d.z / 2);\n // const v4 = new Vector3(center.x + d.x / 2, center.y - d.y / 2, center.z + d.z / 2);\n // const v5 = new Vector3(center.x - d.x / 2, center.y + d.y / 2, center.z - d.z / 2);\n // const v6 = new Vector3(center.x + d.x / 2, center.y + d.y / 2, center.z - d.z / 2);\n // const v7 = new Vector3(center.x - d.x / 2, center.y - d.y / 2, center.z - d.z / 2);\n // const v8 = new Vector3(center.x + d.x / 2, center.y - d.y / 2, center.z - d.z / 2);\n // const lines = Mesh.CreateLines(KBMAXPREFIX + \"boundingBox\", [\n // v1, v2,\n // v1, v3,\n // v3, v4,\n // v4, v2,\n // v2, v6,\n // v6, v5,\n // v5, v7,\n // v7, v8,\n // v8, v6,\n // v8, v4,\n // v3, v7,\n // v5, v1\n // ], this.gizmoLayer.utilityLayerScene);\n // lines.color = new Color3(1, 1, 1);\n // lines.isPickable = false;\n // if (oMesh.kbBoundingBox) {\n // // the bounding box exists so it must be recalculated and repositioned\n // bbNode = oMesh.kbBoundingBox;\n // bbNode.wireFrame.dispose(); // it is easier to recreate it then reposition it\n // bbNode.wireFrame = lines;\n // }\n // else {\n // // the bounding box does not exist, so it must be created\n // bbNode = new boundingBoxGeometry(lines);\n // }\n // oMesh.kbBoundingBox = bbNode; // force to attach the current boundingBox\n // }\n filterToChangedValues(vector) {\n return {\n x: vector.x ? vector.x : undefined,\n y: vector.y ? vector.y : undefined,\n z: vector.z ? vector.z : undefined,\n w: 'w' in vector ? vector.w : undefined,\n };\n }\n }\n // class boundingBoxGeometry {\n // mateHelper1?: Mesh;\n // mateHelper2?: Mesh;\n // mateHelper3?: Mesh;\n // mateHelper4?: Mesh;\n // mateHelper5?: Mesh;\n // mateHelper6?: Mesh;\n // wireFrame: Mesh;\n // constructor(wireFrame: Mesh) {\n // this.wireFrame = wireFrame;\n // }\n // }\n\n function bakeMeshTransform(node) {\n const newTransform = computeLocalTransform(node);\n if (node.preTransform) {\n if (node.preTransform.length !== 16) {\n throw Error('invalid pretransform array ');\n }\n const preTransform = Matrix.FromArray(node.preTransform);\n preTransform.multiplyToRef(newTransform, newTransform);\n }\n node.preTransform = Array.from(newTransform.toArray());\n node.pivot = exports.KbVector.Zero();\n node.position = exports.KbVector.Zero();\n node.scaling = 1;\n node.rotationAngle = 0;\n node.rotationAxis = new exports.KbVector(0, 1, 0);\n node.eulerRotation = exports.KbVector.Zero();\n return node;\n }\n\n const DefaultSketchOptions = {\n faceCamera: true,\n snapSize: 0.5,\n };\n let activeHitPoint;\n let sketchPlaneIntersect;\n class SketchEditor {\n constructor(kbViewer, scene, defaultHighlightColor) {\n this.kbViewer = kbViewer;\n this.scene = scene;\n this.defaultHighlightColor = defaultHighlightColor;\n this.mouseUp = new Subject();\n this.end = new Subject();\n this.sketchPoints = [];\n }\n updateActiveOptions(options) {\n if (this.currentOptions) {\n for (const prop in options) {\n // @ts-expect-error typing not smart enough to know that option objects are the same\n this.currentOptions[prop] = options[prop];\n }\n }\n }\n start(sketch) {\n let origin = exports.KbVector.Zero();\n for (let i = 0; i < sketch.paths.length; i++) {\n const path = sketch.paths[i];\n if (path.controlPoints.length > 0) {\n origin = path.controlPoints[0].position;\n break;\n }\n }\n return this.startOnPlane(sketch, {\n normal: sketch.normal,\n intersect: origin,\n }, undefined, true);\n }\n startOnPlane(sketch, plane, userOptions, useSketchNormal = false) {\n this.activeSketch = sketch;\n sketchPlaneIntersect = plane.intersect;\n const currentCanvas = this.kbViewer.canvas;\n const options = { ...DefaultSketchOptions, ...userOptions };\n this.currentOptions = options;\n this.sketchPoints = sketch.paths.reduce((result, path) => {\n for (const point of path.controlPoints) {\n point._visible = true;\n result.push(point);\n }\n return result;\n }, []);\n const previewVisibleOriginal = sketch._previewVisible;\n sketch._previewVisible = true;\n let planeNormal = getSketchNormalVector3(plane.normal);\n if (useSketchNormal) {\n const sketchNode = this.kbViewer.getRendererNode(sketch);\n if (sketchNode) {\n const matrix = sketchNode.getWorldMatrix().getRotationMatrix();\n planeNormal = Vector3.TransformCoordinates(planeNormal, matrix);\n }\n }\n const planeIntersect = plane.intersect.toVec3();\n const sketchPlane = Plane.FromPositionAndNormal(planeIntersect, planeNormal);\n const originalCamera = this.scene.activeCamera;\n let sketchCamera;\n if (options.faceCamera) {\n originalCamera.detachControl();\n // camera.storeCameraSettings();\n // const viewpoint = new ViewpointNode()\n // camera.moveCameraToViewpoint(viewpoint);\n sketchCamera = new KbArcRotateCamera('sketchEditorView', 0, 0, 10, planeIntersect, this.scene);\n sketchCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;\n sketchCamera.lockRotation = true;\n sketchCamera.wheelPrecision = 60;\n sketchCamera.pinchPrecision = 60;\n switch (plane.normal) {\n case exports.eAxis.x:\n case exports.eAxis.z:\n sketchCamera.upVector = Vector3.Up();\n break;\n case exports.eAxis.y:\n sketchCamera.upVector = Vector3.Backward();\n break;\n default:\n sketchCamera.upVector = Vector3.Cross(planeNormal, planeNormal.equalsToFloats(0, 1, 0) ? Vector3.Right() : Vector3.Up());\n }\n sketchCamera.setPosition(planeNormal.scale(5000).add(planeIntersect));\n sketchCamera.orthoFit(10, 10);\n this.scene.activeCamera = sketchCamera;\n currentCanvas.focus();\n sketchCamera.attachControl();\n this.kbViewer.viewChanged.next();\n }\n const currentCamera = this.scene.activeCamera;\n let dragObjects = [];\n let lastMousePosition = null;\n const sketchParent = sketch._parent ? this.kbViewer.getRendererNode(sketch._parent) : undefined;\n this.kbViewer.interaction.onPointerDown.pipe(takeUntil(this.end)).subscribe(e => {\n if (e.button === 0 && e.pickInfo && e.pickInfo.ray) {\n const deletedPoints = [];\n const ray = e.pickInfo.ray;\n lastMousePosition = getPointOnPlane(ray);\n if (lastMousePosition) {\n roundVectorToPlaces(lastMousePosition, options.snapSize);\n }\n const v1 = new Vector3(-1, -1, -1), v2 = new Vector3(1, 1, 1), collisionSphere = new BoundingSphere(v1, v2);\n const r = CONNECTOR_DIAM / 2;\n for (let i = 0; i < this.sketchPoints.length; i++) {\n const point = this.sketchPoints[i];\n const pointRendered = this.kbViewer.getRendererNode(point);\n if (!pointRendered || pointRendered.isDisposed()) {\n this.sketchPoints.splice(i, 1);\n i--;\n continue;\n }\n const cpCenter = pointRendered.position.clone();\n const cpHandle1 = cpCenter.add(point.direction.toVec3());\n const cpHandle2 = point.direction2 ? cpCenter.add(point.direction2.toVec3()) : undefined;\n if (sketchParent) {\n const matrix = sketchParent.computeWorldMatrix();\n Vector3.TransformCoordinatesToRef(cpCenter, matrix, cpCenter);\n Vector3.TransformCoordinatesToRef(cpHandle1, matrix, cpHandle1);\n if (cpHandle2) {\n Vector3.TransformCoordinatesToRef(cpHandle2, matrix, cpHandle2);\n }\n }\n v1.copyFrom(cpCenter).addInPlaceFromFloats(-r, -r, -r);\n v2.copyFrom(cpCenter).addInPlaceFromFloats(r, r, r);\n collisionSphere.reConstruct(v1, v2);\n let hit = ray.intersectsSphere(collisionSphere);\n let handle = 'position';\n if (!hit) {\n v1.copyFrom(cpHandle1).addInPlaceFromFloats(-r, -r, -r);\n v2.copyFrom(cpHandle1).addInPlaceFromFloats(r, r, r);\n collisionSphere.reConstruct(v1, v2);\n hit = ray.intersectsSphere(collisionSphere);\n handle = 'direction';\n }\n if (!hit && cpHandle2) {\n v1.copyFrom(cpHandle2).addInPlaceFromFloats(-r, -r, -r);\n v2.copyFrom(cpHandle2).addInPlaceFromFloats(r, r, r);\n collisionSphere.reConstruct(v1, v2);\n hit = ray.intersectsSphere(collisionSphere);\n handle = 'direction2';\n }\n if (hit) {\n dragObjects.push({ point, handle });\n // If ctrl key is held down, allow dragging just one point so you can separate paths\n if (e.ctrlKey) {\n break;\n }\n }\n }\n deletedPoints.forEach(point => {\n const index = this.sketchPoints.findIndex(ec => ec.id === point.id);\n this.sketchPoints.splice(index, 1);\n });\n // If both direction handles and positions are hit, only drag the positions and leave the handles alone\n if (dragObjects.find(d => d.handle === 'position')) {\n dragObjects = dragObjects.filter(d => d.handle === 'position');\n }\n if (dragObjects.length === 0) {\n activeHitPoint = undefined;\n }\n else {\n activeHitPoint = dragObjects[0].point;\n currentCamera.detachControl();\n }\n }\n });\n this.kbViewer.interaction.onPointerUp.pipe(takeUntil(this.end)).subscribe(e => {\n dragObjects = [];\n this.mouseUp.next();\n currentCamera.attachControl(currentCanvas);\n });\n this.kbViewer.interaction.onPointerMove.pipe(takeUntil(this.end)).subscribe(e => {\n if (dragObjects.length > 0 && e.pickInfo && e.pickInfo.ray) {\n const ray = e.pickInfo.ray;\n const intersect = getPointOnPlane(ray);\n if (intersect) {\n if (sketchParent) {\n const transformInv = sketchParent.computeWorldMatrix().clone().invert();\n Vector3.TransformCoordinatesToRef(intersect, transformInv, intersect);\n }\n roundVectorToPlaces(intersect, options.snapSize);\n dragObjects.forEach(dragObject => {\n if (dragObject.handle === 'position') {\n roundVectorToPlaces(intersect, options.snapSize);\n dragObject.point.position = exports.KbVector.FromVec3(intersect);\n }\n else {\n const movement = intersect.subtract(dragObject.point.position.toVec3());\n roundVectorToPlaces(intersect, options.snapSize);\n if (dragObject.handle === 'direction') {\n dragObject.point.direction = exports.KbVector.FromVec3(movement);\n }\n else if (dragObject.point.direction2) {\n dragObject.point.direction2 = exports.KbVector.FromVec3(movement);\n }\n }\n });\n }\n }\n });\n this.kbViewer.interaction.onClick.pipe(takeUntil(this.end)).subscribe(e => {\n if (dragObjects.length === 0 && e.pickInfo) {\n if (e.button === 2 && e.canvasX && e.canvasY) {\n if (e.pickInfo.pickedMesh instanceof LinesMesh && e.pickInfo.pickedPoint) {\n this.kbViewer.rightClickMenu.showContextMenu(e.canvasX, e.canvasY, this.getRightClickButtonsForLines(sketch, e.pickInfo.faceId, e.pickInfo.pickedPoint));\n }\n else if (e.pickInfo.pickedMesh instanceof Mesh) {\n const kb3dNode = getByDynamicId(e.pickInfo.pickedMesh.id);\n if (kb3dNode instanceof exports.SketchControlPoint) {\n activeHitPoint = kb3dNode;\n this.kbViewer.rightClickMenu.showContextMenu(e.canvasX, e.canvasY, this.getRightClickButtons());\n }\n }\n }\n else if (e.button === 0 && e.pickInfo.ray) {\n if (this.kbViewer.rightClickMenu.isOpen()) {\n this.kbViewer.rightClickMenu.hideContextMenu();\n return;\n }\n const ray = e.pickInfo.ray;\n const intersect = getPointOnPlane(ray);\n if (intersect) {\n const manager = sketch._manager;\n roundVectorToPlaces(intersect, options.snapSize);\n let lastPath = sketch.paths.length > 0 ? sketch.paths[sketch.paths.length - 1] : undefined;\n if (!lastPath) {\n lastPath = manager.create(Token.SketchPath);\n lastPath.name = 'Path';\n sketch.addChildren(lastPath);\n }\n const c = createSketchPointForEditor(manager, lastPath);\n if (sketch._parent instanceof exports.SpaceNode) {\n const rendererNode = this.kbViewer.getRendererNode(sketch);\n if (rendererNode) {\n Vector3.TransformCoordinatesToRef(intersect, rendererNode.computeWorldMatrix().clone().invert(), intersect);\n }\n c.position = exports.KbVector.FromVec3(intersect);\n }\n this.sketchPoints.push(c);\n }\n }\n }\n });\n this.end.pipe(take(1)).subscribe(() => {\n if (!previewVisibleOriginal) {\n sketch.paths.forEach(path => {\n for (const point of path.controlPoints) {\n point._visible = false;\n }\n });\n }\n originalCamera.attachControl(currentCanvas);\n this.scene.activeCamera = originalCamera;\n if (sketchCamera) {\n sketchCamera.dispose();\n }\n sketch._previewVisible = previewVisibleOriginal;\n });\n function getPointOnPlane(ray) {\n const d = ray.intersectsPlane(sketchPlane);\n if (typeof d === 'number') {\n return ray.origin.add(ray.direction.scale(d));\n }\n return null;\n }\n }\n clear() {\n this.end.next();\n this.kbViewer.rightClickMenu.hideContextMenu();\n this.currentOptions = undefined;\n this.activeSketch = undefined;\n }\n dispose() {\n this.kbViewer.rightClickMenu.hideContextMenu();\n this.end.next();\n this.end.complete();\n this.mouseUp.complete();\n this.activeSketch = undefined;\n }\n deleteSketchPoint() {\n if (this.kbViewer.sceneNode._manager && activeHitPoint) {\n const path = activeHitPoint._parent;\n const targetPoint = activeHitPoint;\n if (path instanceof exports.SketchPath) {\n const index = path.controlPoints.findIndex(ec => ec.id === targetPoint.id);\n path.controlPoints.splice(index, 1);\n }\n }\n }\n deleteSketchPath() {\n if (this.kbViewer.sceneNode._manager && activeHitPoint) {\n if (this.activeSketch) {\n const sketch = this.activeSketch;\n const targetPoint = activeHitPoint;\n sketch.paths.forEach(path => {\n if (path instanceof exports.SketchPath) {\n const index = path.controlPoints.findIndex(ec => { var _a; return ec._dynamicId === ((_a = targetPoint._parent) === null || _a === void 0 ? void 0 : _a._dynamicId); });\n sketch.paths.splice(index, 1);\n }\n });\n }\n }\n }\n separateSketchNode(sketchpathType) {\n var _a, _b;\n if (this.kbViewer.sceneNode._manager && activeHitPoint) {\n // let targetControlPoint: SketchControlPoint | undefined;\n const manager = this.kbViewer.sceneNode._manager;\n if (this.activeSketch) {\n const sketch = this.activeSketch;\n const targetPoint = activeHitPoint;\n for (let pathIndex = 0; pathIndex < sketch.paths.length; pathIndex++) {\n const path = sketch.paths[pathIndex];\n const cpIndex = path.controlPoints.findIndex(ec => ec._dynamicId === targetPoint._dynamicId);\n if (cpIndex === -1) {\n continue;\n }\n if (path.type === sketchpathType) {\n return;\n }\n if (path.controlPoints.length === 1 && sketchpathType === exports.eSketchPathType.arcThrough3Points) {\n const newControlPoint2 = createSketchPointForEditor(manager, path);\n const newControlPoint3 = createSketchPointForEditor(manager, path);\n let sketchNormal = new Vector3(1, 0, 0);\n if (sketch.normal === exports.eAxis.y) {\n sketchNormal = new Vector3(0, 1, 0);\n }\n else if (sketch.normal === exports.eAxis.z) {\n sketchNormal = new Vector3(0, 0, 1);\n }\n const controlPointMesh = this.kbViewer.getRendererNode(sketch.paths[pathIndex].controlPoints[0]);\n const pointOnePosition = sketchNormal.cross(sketchPlaneIntersect.toVec3().subtract(controlPointMesh.getAbsolutePosition()));\n newControlPoint2.position = new exports.KbVector(pointOnePosition.x, pointOnePosition.y, pointOnePosition.z);\n const pointTwoPosition = sketchNormal.cross(pointOnePosition.subtract(controlPointMesh.getAbsolutePosition()));\n newControlPoint3.position = new exports.KbVector(pointTwoPosition.x, pointTwoPosition.y, pointTwoPosition.z);\n path._expanded = true;\n path.type = sketchpathType;\n this.sketchPoints.push(newControlPoint2);\n this.sketchPoints.push(newControlPoint3);\n break;\n }\n else if (cpIndex === 0 && ((_a = sketch.paths[pathIndex - 1]) === null || _a === void 0 ? void 0 : _a.type) === sketchpathType) {\n // If an adjacent path has the same path type as the one we're making, we'll just add the control point to it\n // Previous path matching case\n const cp = path.controlPoints.shift();\n sketch.paths[pathIndex - 1].controlPoints.push(cp.clone());\n break;\n }\n else if (\n // Next path matching case\n cpIndex === path.controlPoints.length - 1 &&\n ((_b = sketch.paths[pathIndex + 1]) === null || _b === void 0 ? void 0 : _b.type) === sketchpathType) {\n const cp = path.controlPoints.pop();\n sketch.paths[pathIndex + 1].controlPoints.push(cp.clone());\n break;\n }\n else if (path.controlPoints.length > 1) {\n let selectedControlPoints;\n let previousPath;\n let selectedPath;\n let nextPath;\n if (cpIndex === 0) {\n selectedPath = path;\n }\n else {\n previousPath = path;\n selectedControlPoints = Array.from(previousPath.controlPoints.splice(cpIndex, path.controlPoints.length - cpIndex));\n selectedPath = manager.create(Token.SketchPath);\n sketch.paths.splice(pathIndex + 1, 0, selectedPath);\n selectedPath.name = 'Path';\n selectedControlPoints.reverse();\n while (selectedControlPoints.length > 0) {\n const cp = manager.clone(selectedControlPoints.pop());\n cp._visible = true;\n selectedPath.controlPoints.push(cp);\n this.sketchPoints.push(cp);\n }\n }\n if (selectedPath.controlPoints.length > 2) {\n let nextPathPoints;\n if (sketchpathType == exports.eSketchPathType.arcThrough3Points &&\n selectedPath.controlPoints.length > 3) {\n nextPathPoints = Array.from(selectedPath.controlPoints.splice(3, selectedPath.controlPoints.length - 3));\n }\n else {\n nextPathPoints = Array.from(selectedPath.controlPoints.splice(1, selectedPath.controlPoints.length - 1));\n }\n nextPath = manager.create(Token.SketchPath);\n sketch.paths.splice(pathIndex + 2, 0, nextPath);\n nextPath.name = 'Path';\n nextPathPoints.reverse();\n while (nextPathPoints.length > 0) {\n const cp = manager.clone(nextPathPoints.pop());\n cp._visible = true;\n nextPath.controlPoints.push(cp);\n this.sketchPoints.push(cp);\n }\n }\n selectedPath._expanded = true;\n selectedPath.type = sketchpathType;\n if (previousPath) {\n const match = manager.clone(selectedPath.controlPoints[0]);\n match._visible = true;\n previousPath.controlPoints.push(match);\n this.sketchPoints.push(match);\n }\n if (nextPath && nextPath.controlPoints.length > 0) {\n const match = manager.clone(nextPath.controlPoints[0]);\n match._visible = true;\n selectedPath.controlPoints.push(match);\n this.sketchPoints.push(match);\n }\n break;\n }\n }\n }\n }\n }\n addSketchNodeOnPath(node, faceId, pickedPoint) {\n const index = node._lineSegmentStartingPoints[faceId];\n let counter = 0;\n const manager = node._manager;\n for (let pathIndex = 0; pathIndex < node.paths.length; pathIndex++) {\n const path = node.paths[pathIndex];\n for (let cpIndex = 0; cpIndex < node.paths.length; cpIndex++) {\n const controlPoint = path.controlPoints[cpIndex];\n if (counter === index) {\n const spliceIndex = path.controlPoints.indexOf(controlPoint);\n const sketchControlPoint = manager.create(Token.SketchControlPoint);\n sketchControlPoint.position = exports.KbVector.FromVec3(pickedPoint);\n path.controlPoints.splice(spliceIndex + 1, 0, sketchControlPoint);\n sketchControlPoint._visible = true;\n sketchControlPoint._expanded = true;\n this.sketchPoints.push(sketchControlPoint);\n return;\n }\n counter++;\n }\n }\n }\n getRightClickButtons() {\n return [\n { label: 'delete node', callback: () => this.deleteSketchPoint() },\n { label: 'delete path', callback: () => this.deleteSketchPath() },\n { label: 'convert to cubic bezier', callback: () => this.separateSketchNode(exports.eSketchPathType.cubicBezier) },\n {\n label: 'convert to quadratic bezier',\n callback: () => this.separateSketchNode(exports.eSketchPathType.quadraticBezier),\n },\n { label: 'convert to hermite', callback: () => this.separateSketchNode(exports.eSketchPathType.hermite) },\n { label: 'convert to catmullrom', callback: () => this.separateSketchNode(exports.eSketchPathType.catmullRom) },\n { label: 'convert to points', callback: () => this.separateSketchNode(exports.eSketchPathType.points) },\n {\n label: 'arc through 3 points',\n callback: () => this.separateSketchNode(exports.eSketchPathType.arcThrough3Points),\n },\n ];\n }\n getRightClickButtonsForLines(node, faceId, pickedPoint) {\n return [\n {\n label: 'add point on line',\n callback: () => this.addSketchNodeOnPath(node, faceId, pickedPoint),\n },\n ];\n }\n }\n\n function downloadBlob(blob, filename = 'download') {\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = filename || 'download';\n const clickHandler = () => {\n setTimeout(() => {\n URL.revokeObjectURL(url);\n a.removeEventListener('click', clickHandler);\n }, 150);\n };\n a.addEventListener('click', clickHandler, false);\n a.click();\n }\n function dataURLtoBlob(dataurl) {\n const arr = dataurl.split(',');\n const mime = arr[0].match(/:(.*?);/)[1];\n const bstr = atob(arr[1]);\n let n = bstr.length;\n const u8arr = new Uint8Array(n);\n while (n--) {\n u8arr[n] = bstr.charCodeAt(n);\n }\n return new Blob([u8arr], { type: mime });\n }\n\n (function (eSnapshotType) {\n eSnapshotType[\"image\"] = \"image\";\n eSnapshotType[\"blob\"] = \"blob\";\n eSnapshotType[\"dataUrl\"] = \"dataUrl\";\n })(exports.eSnapshotType || (exports.eSnapshotType = {}));\n class SnapshotModule {\n constructor(v, scene) {\n this.v = v;\n this.scene = scene;\n }\n take(args) {\n if (args.dataType == exports.eSnapshotType.image) {\n return this.download(args);\n }\n else if (args.dataType == exports.eSnapshotType.blob) {\n return this.takeAsBlob(args);\n }\n else {\n return this.takeAsDataUrl(args);\n }\n }\n takeAsDataUrl(args) {\n //set the viewpoint\n let viewpointSet = false;\n if (args.viewpoint) {\n const viewpoint = this.v.sceneNode._manager.getNodeByIdOrName(args.viewpoint);\n if (!viewpoint) {\n throw `Could not find viewpoint ${args.viewpoint} for snapshot`;\n }\n else {\n this.v.camera.storeCameraSettings();\n this.v.camera.moveCameraToViewpoint(viewpoint);\n viewpointSet = true;\n }\n }\n return this.v\n .whenAssetsLoaded()\n .then(() => {\n if (args.frameCamera) {\n this.v.camera.frameCamera(this.v.sceneNode, {\n padding: args.framePadding,\n });\n }\n return this.v.forceAndWaitForNextRender().then(() => {\n return this.v.forceAndWaitForNextRender();\n });\n })\n .then(() => {\n const engine = this.v.scene.getEngine();\n const mimeType = args.mimeType || 'image/png';\n const snapshotCanvas = document.createElement('canvas');\n snapshotCanvas.width = args.width;\n snapshotCanvas.height = args.height;\n const renderContext = snapshotCanvas.getContext('2d');\n const ratio = engine.getRenderWidth() / engine.getRenderHeight();\n let newWidth = args.width;\n let newHeight = newWidth / ratio;\n if (newHeight > args.height) {\n newHeight = args.height;\n newWidth = newHeight * ratio;\n }\n const offsetX = Math.max(0, args.width - newWidth) / 2;\n const offsetY = Math.max(0, args.height - newHeight) / 2;\n const renderingCanvas = engine.getRenderingCanvas();\n if (renderContext && renderingCanvas) {\n renderContext.drawImage(renderingCanvas, offsetX, offsetY, newWidth, newHeight);\n }\n const dataUrl = snapshotCanvas.toDataURL(mimeType);\n if (viewpointSet) {\n this.v.camera.restoreCameraSettings();\n }\n snapshotCanvas.width = 0;\n snapshotCanvas.height = 0;\n return dataUrl;\n });\n }\n takeAsBlob(args) {\n return this.takeAsDataUrl(args).then(dataUrl => dataURLtoBlob(dataUrl));\n }\n download(args) {\n return this.takeAsBlob(args).then(blob => downloadBlob(blob, args.filename));\n }\n }\n\n var maskFragmentShader = \"precision highp float;\\r\\n \\r\\nuniform vec4 lineColor;\\r\\n\\r\\nvoid main(void) {\\r\\n gl_FragColor = lineColor;\\r\\n}\";\n\n var maskVertexShader = \"precision highp float;\\r\\n // Attributes\\r\\nattribute vec3 position;\\r\\n// Uniforms\\r\\nuniform mat4 worldViewProjection;\\r\\nvoid main(void) {\\r\\n gl_Position = worldViewProjection * vec4(position, 1.0);\\r\\n}\\r\\n\\r\\n\";\n\n var outlineFragmentShader = \"#ifdef GL_ES\\r\\nprecision highp float;\\r\\n#endif\\r\\n\\r\\n// Samplers\\r\\nvarying vec2 vUV;\\r\\nuniform sampler2D textureSampler;\\r\\nuniform sampler2D maskSampler;\\r\\n\\r\\n// Parameters\\r\\nuniform vec2 screenSize;\\r\\nuniform float threshold;\\r\\nuniform float lineWidth;\\r\\nuniform bool debug;\\r\\n\\r\\nvoid main(void) \\r\\n{\\r\\n // Calculating how far away to check pixels for different colors to determine whether to draw an outline pixel\\r\\n float dx = (1.0 / screenSize.x) * lineWidth;\\r\\n float dy = (1.0 / screenSize.y) * lineWidth;\\r\\n\\r\\n float xMin = dx * 0.5;\\r\\n float xMax = 1. - dx * 0.5;\\r\\n float yMin = dy * 0.5;\\r\\n float yMax = 1. - dy * 0.5;\\r\\n\\r\\n float right = clamp(vUV.x + dx, xMin, xMax);\\r\\n float left = clamp(vUV.x - dx, xMin, xMax);\\r\\n float top = clamp(vUV.y + dy, yMin, yMax);\\r\\n float bottom = clamp(vUV.y - dy, yMin, yMax);\\r\\n\\r\\n // calculating the uvs corresponsing to the pixels from the step above\\r\\n vec2 uvCenter = vUV;\\r\\n vec2 uvLeft = vec2(left, uvCenter.y);\\r\\n vec2 uvRight = vec2(right, uvCenter.y);\\r\\n vec2 uvTop = vec2(uvCenter.x, top);\\r\\n vec2 uvBottom = vec2(uvCenter.x, bottom);\\r\\n vec2 uvTopLeft = vec2(left, top);\\r\\n vec2 uvTopRight = vec2(right, top);\\r\\n vec2 uvBottomLeft = vec2(left, bottom);\\r\\n vec2 uvBottomRight = vec2(right, bottom);\\r\\n\\r\\n // getting the colors of the pixels at the 4 corners of our check box\\r\\n vec4 mCenter = texture2D(maskSampler, uvCenter);\\r\\n vec4 mleft = texture2D(maskSampler, uvLeft);\\r\\n vec4 mRight = texture2D(maskSampler, uvRight);\\r\\n vec4 mTop = texture2D(maskSampler, uvTop);\\r\\n vec4 mBottom = texture2D(maskSampler, uvBottom);\\r\\n vec4 mTopleft = texture2D(maskSampler, uvTopLeft);\\r\\n vec4 mTopRight = texture2D(maskSampler, uvTopRight);\\r\\n vec4 mBottomLeft = texture2D(maskSampler, uvBottomLeft);\\r\\n vec4 mBottomRight = texture2D(maskSampler, uvBottomRight);\\r\\n\\r\\n // getting the difference in colors between the center pixel and the other pixels\\r\\n vec4 dL = abs(mCenter - mleft);\\r\\n vec4 dR = abs(mCenter - mRight);\\r\\n vec4 dT = abs(mCenter - mTop);\\r\\n vec4 dB = abs(mCenter - mBottom);\\r\\n vec4 dTL = abs(mCenter - mTopleft);\\r\\n vec4 dTR = abs(mCenter - mTopRight);\\r\\n vec4 dBL = abs(mCenter - mBottomLeft);\\r\\n vec4 dBR = abs(mCenter - mBottomRight);\\r\\n\\r\\n // getting the maximum difference from the center pixel to any of the other pixels\\r\\n vec4 totalD = max(dT, dR);\\r\\n totalD = max(totalD, dB);\\r\\n totalD = max(totalD, dL);\\r\\n totalD = max(totalD, dTL);\\r\\n totalD = max(totalD, dTR);\\r\\n totalD = max(totalD, dBL);\\r\\n totalD = max(totalD, dBR);\\r\\n\\r\\n float delta = length(totalD) * mCenter.a;\\r\\n if(delta < threshold) {\\r\\n delta = 0.0;\\r\\n }\\r\\n\\r\\n if (debug == true) {\\r\\n gl_FragColor = texture2D(maskSampler, vUV);\\r\\n } else {\\r\\n // if(delta > threshold) {\\r\\n // gl_FragColor = texture2D(maskSampler, vUV);\\r\\n // } else {\\r\\n // gl_FragColor = texture2D(textureSampler, vUV);\\r\\n // }\\r\\n // Merge the real scene output with the outline\\r\\n vec4 albedoColor = texture2D(textureSampler, vUV);\\r\\n gl_FragColor = mCenter.rgba * delta + albedoColor * (1.0 - delta);\\r\\n // gl_FragColor = mCenter.rgba * delta;\\r\\n }\\r\\n}\";\n\n Effect.ShadersStore['customMaskVertexShader'] = maskVertexShader;\n Effect.ShadersStore['customMaskFragmentShader'] = maskFragmentShader;\n Effect.ShadersStore['simpleOutlineFragmentShader'] = outlineFragmentShader;\n class Highlighter {\n constructor(kbViewer, scene, defaultHighlightColor, cameraManager) {\n this.kbViewer = kbViewer;\n this.scene = scene;\n this.defaultHighlightColor = defaultHighlightColor;\n this.colorMap = new Map();\n this.nodeColors = new Map();\n this.highlighterDb = new Map();\n this.engine = scene.getEngine();\n this.highlightPipeline = new PostProcessRenderPipeline(this.engine, 'highlightPipeline');\n this.renderTarget = new RenderTargetTexture('Highlight render target', 1024, scene, { samples: 2 });\n this.renderTarget.renderList = [];\n this.renderTarget.clearColor = new Color4(0, 0, 0, 0);\n scene.customRenderTargets.push(this.renderTarget);\n this.postProcess = new PostProcess('Highlighter post process', 'simpleOutline', ['screenSize', 'threshold', 'lineWidth', 'debug'], ['maskSampler'], 1.0, null, undefined, this.engine, true);\n // This may help with the highlight separating from the scene meshes, if we can ge the highlight to combine with the scene\n // this.postProcess.autoClear = false;\n // this.postProcess.alphaMode = Engine.ALPHA_COMBINE;\n this.postProcess.samples = 4;\n this.postProcess.onApply = effect => {\n effect.setFloat2('screenSize', this.postProcess.width, this.postProcess.height);\n effect.setFloat('threshold', 0.3);\n effect.setFloat('lineWidth', 4.0);\n effect.setBool('debug', false);\n effect.setTexture('maskSampler', this.renderTarget);\n window.enableHighlightDebug = () => {\n enableHighlightDebug(effect);\n };\n };\n const highlightEffect = new PostProcessRenderEffect(this.engine, 'highlightEffect', () => [this.postProcess], false);\n this.highlightPipeline.addEffect(highlightEffect);\n this.scene.postProcessRenderPipelineManager.addPipeline(this.highlightPipeline);\n cameraManager.setPipeline(this.highlightPipeline);\n function enableHighlightDebug(effect) {\n effect.setBool('debug', true);\n }\n }\n has(node) {\n return this.highlighterDb.has(node._dynamicId);\n }\n add(node, color = this.defaultHighlightColor) {\n this.startPostProcess();\n const renderNode = this.kbViewer.getRendererNode(node);\n this.highlighterDb.set(node._dynamicId, color);\n this.addHighlightToRendered(renderNode, color);\n }\n remove(node) {\n var _a;\n if (this.highlighterDb.has(node._dynamicId)) {\n const renderNode = this.kbViewer.getRendererNode(node);\n if (((_a = this.activeHover) === null || _a === void 0 ? void 0 : _a._dynamicId) !== node._dynamicId) {\n // Don't remove the highlight from a hover. Once the hover clears the highlight will be cleared.\n this.removeHighlightFromRendered(renderNode);\n this.highlighterDb.delete(node._dynamicId);\n }\n }\n }\n hover(node) {\n if (node != this.activeHover) {\n this.startPostProcess();\n this.clearHover();\n this.activeHover = node;\n const renderNode = this.kbViewer.getRendererNode(node);\n this.addHighlightToRendered(renderNode, this.defaultHighlightColor);\n this.kbViewer.canvas.style.cursor = 'pointer';\n this.scene.defaultCursor = 'pointer';\n this.kbViewer.forceRenderOnNextFrame = true;\n }\n }\n clearHover() {\n if (this.activeHover) {\n const renderNode = this.kbViewer.getRendererNode(this.activeHover);\n this.removeHighlightFromRendered(renderNode);\n //if the node had a highlight previously, restore it\n if (this.highlighterDb.has(this.activeHover._dynamicId)) {\n const color = this.highlighterDb.get(this.activeHover._dynamicId);\n this.addHighlightToRendered(renderNode, color);\n }\n // const targets = renderNode instanceof AbstractMesh ? [renderNode] : renderNode.getChildMeshes();\n // for (const target of targets) {\n // if (this.highlighterDb.has(target)) {\n // const color = this.highlighterDb.get(target)!;\n // this.addHighlightToRendered(target, color);\n // }\n // }\n this.activeHover = undefined;\n this.kbViewer.canvas.style.cursor = 'default';\n this.scene.defaultCursor = 'default';\n this.kbViewer.forceRenderOnNextFrame = true;\n }\n }\n clearAll() {\n this.colorMap.forEach(entry => {\n this.renderTarget.setMaterialForRendering(Array.from(entry.meshes), undefined);\n });\n if (this.renderTarget.renderList) {\n while (this.renderTarget.renderList.length > 0) {\n this.renderTarget.renderList.pop();\n }\n }\n this.nodeColors.clear();\n this.highlighterDb.clear();\n this.colorMap.clear();\n this.activeHover = undefined;\n }\n addHighlightToRendered(node, color) {\n var _a;\n const targets = node instanceof AbstractMesh ? [node] : node.getChildMeshes();\n for (const renderNode of targets) {\n if (((_a = this.renderTarget.renderList) === null || _a === void 0 ? void 0 : _a.contains(renderNode)) === false) {\n if (!this.renderTarget.renderList) {\n this.renderTarget.renderList = [];\n }\n this.renderTarget.renderList.push(renderNode);\n }\n let colorMapKey = '';\n if (color) {\n colorMapKey = this.colorToString(color);\n }\n else {\n colorMapKey = this.colorToString(this.defaultHighlightColor);\n }\n this.addNodeToColorMap(colorMapKey, renderNode, color);\n this.nodeColors.set(renderNode, colorMapKey);\n }\n }\n removeHighlightFromRendered(node) {\n var _a;\n const targets = node instanceof AbstractMesh ? [node] : node.getChildMeshes();\n for (const renderNode of targets) {\n const colorKey = this.nodeColors.get(renderNode);\n (_a = this.renderTarget.renderList) === null || _a === void 0 ? void 0 : _a.remove(renderNode);\n if (colorKey) {\n this.removeNodeFromColorMap(colorKey, renderNode);\n this.nodeColors.delete(renderNode);\n }\n }\n }\n addNodeToColorMap(colorMapKey, node, color) {\n let colorMapEntry = this.colorMap.get(colorMapKey);\n if (!colorMapEntry) {\n const newShader = new ShaderMaterial('customMaskMat_' + colorMapKey, this.scene, 'customMask', {\n attributes: ['position', 'uv'],\n uniforms: ['worldViewProjection', 'color', 'lineColor'],\n });\n if (color) {\n newShader.setColor4('lineColor', color.toColor4());\n }\n else {\n newShader.setColor4('lineColor', this.defaultHighlightColor.toColor4());\n }\n colorMapEntry = {\n material: newShader,\n meshes: new Set(),\n };\n }\n colorMapEntry.meshes.add(node);\n this.renderTarget.setMaterialForRendering(Array.from(colorMapEntry.meshes), colorMapEntry.material);\n }\n removeNodeFromColorMap(colorMapKey, node) {\n const colorMapEntry = this.colorMap.get(colorMapKey);\n if (colorMapEntry) {\n colorMapEntry.meshes.delete(node);\n this.renderTarget.setMaterialForRendering(node, undefined);\n }\n }\n colorToString(color) {\n return color.cssString();\n }\n startPostProcess() { }\n }\n\n class RightClickMenu {\n constructor(viewer, scene) {\n this.viewer = viewer;\n this.scene = scene;\n this.contextMenuOpen = false;\n }\n isOpen() {\n return this.contextMenuOpen;\n }\n showContextMenu(xPosition, yPosition, buttons) {\n this.createContextMenu(xPosition, yPosition, buttons);\n if (this.viewer.uiOverlay && this.contextmenu) {\n this.viewer.container.appendChild(this.contextmenu);\n this.contextMenuOpen = true;\n }\n }\n hideContextMenu() {\n if (this.contextmenu) {\n this.contextmenu.style.display = 'none';\n this.contextMenuOpen = false;\n }\n }\n createContextMenu(xPosition, yPosition, buttons) {\n var _a;\n //const buttons = [];\n if (this.contextmenu && this.viewer.container.contains(this.contextmenu)) {\n (_a = this.viewer.container) === null || _a === void 0 ? void 0 : _a.removeChild(this.contextmenu);\n }\n const contextMenu = document.createElement('div');\n contextMenu.style.position = 'absolute';\n contextMenu.style.top = yPosition.toString() + 'px';\n contextMenu.style.left = (xPosition + 10).toString() + 'px';\n contextMenu.style.width = 'auto';\n contextMenu.style.height = 'auto';\n contextMenu.style.zIndex = '2';\n contextMenu.addEventListener('click', e => {\n if (e.button === 2) {\n e.preventDefault();\n e.stopImmediatePropagation();\n }\n });\n document.addEventListener('click', e => {\n if (e.button != 2) {\n this.hideContextMenu();\n }\n });\n document.addEventListener('wheel', e => {\n this.hideContextMenu();\n });\n contextMenu.addEventListener('scroll', e => {\n if (this.contextmenu) {\n this.contextmenu.style.display = 'none';\n }\n });\n this.contextmenu = contextMenu;\n buttons.forEach(button => {\n var _a;\n const newButton = document.createElement('div');\n newButton.innerText = button.label;\n newButton.addEventListener('click', e => {\n button.callback();\n this.hideContextMenu();\n });\n (_a = this.contextmenu) === null || _a === void 0 ? void 0 : _a.appendChild(newButton);\n newButton.style.zIndex = '100000';\n newButton.style.color = 'white';\n newButton.style.background = 'rgba(36,36,36,255)';\n newButton.style.cursor = 'pointer';\n newButton.style.padding = '10px';\n newButton.addEventListener('mouseover', e => {\n newButton.style.background = 'rgba(61,61,61,255)';\n });\n newButton.addEventListener('mouseout', e => {\n newButton.style.background = 'rgba(36,36,36,255)';\n });\n });\n }\n }\n\n const FADE_TIME = 300;\n /**\n * Applcation class for the viewer, to contain all of the initializers and hooks and connect the modules and 3d engine.\n * @param canvasElement An HTML DOM element that the viewer will be attached to\n */\n class KbViewer {\n constructor(options) {\n this.forceRenderOnNextFrame = false;\n this.pauseRender = false;\n this.MeshWarningTracker = new Map();\n this.normalSmoothingWarnings = new Map();\n /** Events / Observables */\n /** observable for tracking when something changed that could affect the position of a node on the screen */\n this.viewChanged = new Subject();\n this.afterRender = new Subject();\n this.fpsTracker = new Subject();\n this.polygonTracker = new Subject();\n this.warningTracker = new Subject();\n this.meshWarningsNeedsUpdate = new Subject();\n this.materialWarningsNeedsUpdate = new Subject();\n this.animationWarningsNeedsUpdate = new Subject();\n this.disposed = false;\n this.forceRunRenderer = false;\n this.isDevEnvironment = false;\n /** tracks babylon nodes who are being tracked for positions (hotspots) */\n this.positionTrackedNodes = new Map();\n this.nextFrameCallbacks = [];\n this._renderLoopRunning = false;\n this.allAssetsLoaded = false;\n /** tracks any additional promises that renders and load spinners should wait for */\n this.additionalLoadBlockers = [];\n this.options = {\n highlightColor: exports.KbColor.KbmaxOrange(),\n editorMode: false,\n forceDisablePostProcess: false,\n enableScreenshots: false,\n debugMode: false,\n webworkerPath: '/worker3d.js',\n ...options,\n };\n if (typeof window !== 'undefined' && options.webworkerPath && !options.webworkerPath.startsWith('http')) {\n this.options.webworkerPath = `${window.location.protocol}//${window.location.host}${this.options.webworkerPath}`;\n }\n Kb3dWorker.workerPath = this.options.webworkerPath;\n // Create canvas and engine.\n this.container = options.container;\n this.canvas = this.createCanvas();\n // Anti-aliasing=true (second parameter) causes the canvas to not get cleared on iOS 15.4. Warrants testing in future iOS updates.\n const iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);\n this.engine = new Engine(this.canvas, !iOS, { stencil: true, preserveDrawingBuffer: this.options.enableScreenshots }, true); //set adaptToDeviceRatio to true, and let the hardware scaling optimizer take over from there\n this.engine.setAlphaMode(Engine.ALPHA_COMBINE);\n this.glInfo = this.engine.getGlInfo();\n // eslint-disable-next-line no-console\n console.log('WebGL Renderer', this.glInfo.vendor, this.glInfo.renderer, this.glInfo.version);\n // Create the scene.\n const scene = this.createScene();\n this.scene = scene;\n this.scene.hoverCursor = 'pointer';\n this.utilityLayer = new UtilityLayerRenderer(this.scene);\n this.utilityLayer.utilityLayerScene.useRightHandedSystem = true;\n this.utilityLayer.processAllEvents = true;\n this.camera = new CameraTools(this.scene, this.canvas, this);\n this.bbCache = new BoundingBoxCache(this);\n // var hdrTexture = CubeTexture.CreateFromPrefilteredData('/assets/environments/environment.dds', scene);\n // hdrTexture.gammaSpace = false;\n // scene.environmentTexture = hdrTexture;\n this.highlightColor = options.highlightColor || exports.KbColor.KbmaxOrange();\n this.gizmos = new GizmoTools(scene, this);\n this.rightClickMenu = new RightClickMenu(this, this.scene);\n this.animation = new AnimationModule(this, this.scene);\n this.highlighter = new Highlighter(this, this.scene, this.highlightColor, this.camera);\n this.interaction = new Interaction(this, this.scene, this.highlighter);\n this.sketchEditor = new SketchEditor(this, this.scene, this.highlightColor);\n this.gui = new GuiHelper(scene, this.highlighter);\n this.ar = new AR(this, scene);\n this.snapshot = new SnapshotModule(this, scene);\n this.rendererManager = new RendererManager(this, scene);\n this.interaction.attachScene(this.utilityLayer.utilityLayerScene, true);\n this.gltfExporter = new GLTFKb3dExporter(scene);\n this.objExporter = new ObjKb3dExporter(scene, this.rendererManager);\n }\n get settings() {\n return SettingsManagerService;\n }\n setRenderMode(mode, force) {\n this.rendererManager.setRenderMode(mode, this.sceneNode, force);\n }\n loadScene(o) {\n if (!o.sceneNode._manager) {\n throw 'sceneNode must be constructed with a manager';\n }\n this.sceneNode = o.sceneNode;\n this.manager = o.sceneNode._manager;\n this.isDevEnvironment = this.manager.isDevEnvironment;\n const loadingExperience = o.loadingExperience || this.sceneNode.loadingExperience;\n this.createLoadingExperience(loadingExperience, this.sceneNode.loadingImagePath);\n let viewpoint = o.viewpoint ||\n (o.sceneNode.viewpointId ? this.manager.getById(o.sceneNode.viewpointId) : undefined);\n if (!viewpoint) {\n viewpoint = this.manager.create(Token.ViewpointNode);\n viewpoint.type = exports.eViewpointType.orbit;\n viewpoint.targetMode = exports.eViewpointTargetMode.point;\n viewpoint.position = new exports.KbVector(3, 3, 3);\n viewpoint.targetPoint = exports.KbVector.Zero();\n }\n this.camera.moveCameraToViewpoint(viewpoint);\n // Start render loop.\n this.startRender();\n // The canvas/window resize event handler.\n // window.addEventListener('resize', () => {\n // if (!this.ar.xrLoading && !this.ar.xrActive) { //don't mess with the AR canvas resize\n // this.engine.resize();\n // this.viewChanged.next();\n // }\n // });\n const promises = [this.whenAssetsLoaded()];\n if (o.deferLoadingPromise)\n promises.push(o.deferLoadingPromise);\n return Promise.all(promises).then(() => {\n var _a;\n const http = (_a = this.sceneNode._manager) === null || _a === void 0 ? void 0 : _a.getService(Token.HttpService);\n let frame = true;\n if (this.sceneNode.viewpointId)\n frame = this.sceneNode.frameViewpoint;\n if (o.frameViewpoint != null)\n frame = o.frameViewpoint;\n if (frame) {\n this.camera.frameCamera(this.sceneNode);\n }\n this.hideLoadingExperience();\n // Wait for everything to be loaded and processed before trying to optimize scene because the scene optimizer watches the FPS and we want the state to be stable\n // Disable the graphics optimization (for example when rendering)\n if (!this.options.forceDisableGraphicsOptimization) {\n this.waitForNextKb3dRender().then(() => {\n this.optimizeScene(this.scene);\n });\n }\n this.meshWarningsNeedsUpdate\n .pipe(throttleTime(1000, undefined, { leading: true, trailing: true }))\n .subscribe(() => {\n this.updateMeshWarnings();\n this.updateTextureWarnings();\n });\n this.materialWarningsNeedsUpdate\n .pipe(throttleTime(15000, undefined, { leading: true, trailing: false }))\n .subscribe(() => {\n this.updateMaterialWarnings();\n });\n this.animationWarningsNeedsUpdate.subscribe(value => {\n this.updateAnimationWarnings(value);\n });\n this.updateTextureWarnings();\n this.updateLightWarnings();\n this.updateMaterialWarnings();\n if (http) {\n http.executeDeferredCalls();\n }\n });\n }\n getNode(id) {\n return this.manager.getById(id);\n }\n getRendererNode(n) {\n if (isSceneNode(n) && n.isNested() === false) {\n return this.rendererManager.sceneRenderer.get3d(n);\n }\n else if (isSceneNode(n) && n.isNested()) {\n return this.rendererManager.mesh.get3d(n);\n }\n else if (isLightNode(n)) {\n return this.rendererManager.light.get3d(n);\n }\n else if (isSpaceNode(n)) {\n return this.rendererManager.mesh.get3d(n);\n }\n else if (isMaterialNode(n)) {\n return this.rendererManager.material.get3d(n);\n }\n else if (isConnector(n)) {\n return this.rendererManager.connector.get3d(n);\n }\n else if (isSketchControlPoint(n)) {\n return this.rendererManager.controlPointRenderer.get3d(n);\n }\n else if (isTextureLayer(n)) {\n return this.rendererManager.textures.get3d(n);\n }\n return undefined;\n }\n getFPS() {\n return this.engine.getFps().toFixed();\n }\n getWarnings() {\n return this.warningMessages;\n }\n getMeshBoundingBox(node, vertexGroups) {\n let mesh = this.rendererManager.mesh.get3d(node);\n let newMesh;\n if (vertexGroups) {\n const newIndices = [];\n const newPositions = [];\n let indices;\n let positions;\n if (mesh instanceof Mesh && mesh.geometry) {\n positions = mesh.geometry.getVerticesData(VertexBuffer.PositionKind);\n indices = mesh.geometry.getIndices();\n }\n else {\n indices = [];\n positions = [];\n }\n for (let i = 0; i < vertexGroups.length; i++) {\n const vertexGroup = vertexGroups[i];\n if (vertexGroup && vertexGroup.startIndex && vertexGroup.endIndex) {\n for (let j = vertexGroup.startIndex; j < vertexGroup.endIndex; j++) {\n newIndices.push(indices[j]);\n for (let k = 0; k < 3; k++) {\n newPositions[indices[j] * 3 + k] = positions[indices[j] * 3 + k];\n }\n }\n }\n }\n newMesh = new Mesh('temp mesh', this.scene, mesh === null || mesh === void 0 ? void 0 : mesh.parent);\n const newVertexData = new VertexData();\n newVertexData.indices = newIndices;\n newVertexData.positions = newPositions;\n newVertexData.applyToMesh(newMesh, true);\n newMesh.visibility = 0;\n }\n if (newMesh) {\n mesh = newMesh;\n }\n if (mesh && mesh instanceof AbstractMesh) {\n const boundingBox = mesh.getBoundingInfo().boundingBox;\n newMesh === null || newMesh === void 0 ? void 0 : newMesh.dispose();\n return {\n maximum: boundingBox.maximum,\n minimum: boundingBox.minimum,\n center: boundingBox.center,\n minWorld: boundingBox.minimumWorld,\n maxWorld: boundingBox.maximumWorld,\n };\n }\n }\n updateLightWarnings() {\n let totalSpotLights = 0;\n let totalPointLights = 0;\n let shadowCastingLights = 0;\n let tempWarning = '';\n this.lightsWarningMessages = [];\n this.scene.lights.forEach(light => {\n if (light.isEnabled()) {\n if (light instanceof SpotLight) {\n totalSpotLights += 1;\n }\n else if (light instanceof PointLight) {\n totalPointLights += 1;\n }\n if (light.shadowEnabled) {\n shadowCastingLights += 1;\n }\n }\n });\n if (totalSpotLights + totalPointLights > 10) {\n tempWarning = `Performance Warning: The number of spotlights (${totalSpotLights}) and/or pointlights (${totalPointLights}) is higher than recommended for optimal performance.`;\n this.lightsWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n if (shadowCastingLights > 4) {\n tempWarning = `Performance Warning: The number of shadow casting lights (${shadowCastingLights}) is higher than recommended for optimal performance.`;\n this.lightsWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n this.updateWarnings();\n }\n updateTextureWarnings() {\n const bigTextures2048 = new Map();\n const bigTextures4096 = new Map();\n let tempWarning = '';\n this.textureWarningMessages = [];\n this.sceneNode.meshes.forEach(node => {\n const mesh = this.getRendererNode(node);\n let textures = [];\n if (mesh instanceof AbstractMesh && mesh.isEnabled()) {\n if (mesh.material instanceof MultiMaterial) {\n mesh.material.subMaterials.forEach(subMaterial => {\n const subMaterialTextures = subMaterial === null || subMaterial === void 0 ? void 0 : subMaterial.getActiveTextures();\n if (subMaterialTextures) {\n subMaterialTextures.forEach(texture => {\n if (texture instanceof Texture) {\n textures.push(texture);\n }\n });\n }\n });\n }\n else if (mesh.material instanceof Material) {\n textures = mesh.material.getActiveTextures();\n }\n }\n if (textures) {\n textures.forEach(texture => {\n const textureSize = Math.max(texture.getSize().height, texture.getSize().width);\n if (texture instanceof Texture) {\n if (textureSize > 4096) {\n bigTextures4096.set(texture.uniqueId, texture);\n bigTextures2048.set(texture.uniqueId, texture);\n }\n else if (textureSize > 2048) {\n bigTextures2048.set(texture.uniqueId, texture);\n }\n }\n });\n }\n });\n if (bigTextures4096.size > 4) {\n tempWarning = `Warning, number of textures with resolutions over 4096 (${bigTextures4096.size}) is higher than recommended for optimal performance.`;\n this.textureWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n else if (bigTextures2048.size > 20) {\n tempWarning = `Warning, number of textures with resolutions over 2048 (${bigTextures2048.size}) is higher than recommended for optimal performance.`;\n this.textureWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n this.updateWarnings();\n }\n updateMeshWarnings() {\n this.totalPolygons = this.recursiveGetPolygons(this.sceneNode).polygons;\n let meshCastAndReceiveShadows = 0;\n let tempWarning = '';\n this.meshWarningMessages = [];\n this.MeshWarningTracker.forEach(mesh => {\n if (mesh.isEnabled) {\n if (mesh.featureNumber > 15) {\n tempWarning = `Performance Warning: The number of features on ${mesh.name} is higher than recommended for optimal performance.`;\n this.meshWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n if (mesh.castShadows && mesh.receiveShadows) {\n meshCastAndReceiveShadows += 1;\n }\n }\n });\n if (this.totalPolygons > 500000) {\n tempWarning = `Performance Warning: Polygon count of ${this.totalPolygons} is higher than recommended for optimal performance.`;\n this.meshWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n if (meshCastAndReceiveShadows > 10) {\n tempWarning = `Performance Warning: The number of meshes that cast and receive shadows (${meshCastAndReceiveShadows}) is higher than recommended for optimal performance.`;\n this.meshWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n this.updateWarnings();\n }\n updateNormalSmoothingWarnings(feature, polygonCount, removed) {\n var _a;\n if (removed) {\n this.normalSmoothingWarnings.delete(feature.id);\n }\n else {\n if (polygonCount > 100000 && feature.enabled) {\n const warning = `Performance Warning: Too many polygons (${polygonCount}) are selected inside \"${feature.name}\" on \"${(_a = feature._parent) === null || _a === void 0 ? void 0 : _a.name}\".`;\n this.normalSmoothingWarnings.set(feature.id, warning);\n if (this.isDevEnvironment) {\n console.warn(warning);\n }\n }\n else {\n this.normalSmoothingWarnings.delete(feature.id);\n }\n }\n this.updateWarnings;\n }\n updateMaterialWarnings() {\n let tempWarning = '';\n const localMaterialCount = this.getLocalMaterialsRecursive(this.sceneNode);\n this.materialWarningMessages = [];\n if (localMaterialCount > 20) {\n tempWarning = `Performance Warning: The number of local materials (${localMaterialCount}) is higher than recommended for optimal performance.`;\n this.materialWarningMessages.push(tempWarning);\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n }\n updateAnimationWarnings(activeAnimations) {\n let tempWarning = '';\n if (activeAnimations > 1) {\n tempWarning = `Performance Warning: More than 1 animation (${activeAnimations}) is active at the same instance.`;\n if (this.isDevEnvironment) {\n console.warn(tempWarning);\n }\n }\n }\n updateWarnings() {\n const tempArray = [];\n if (this.lightsWarningMessages && this.lightsWarningMessages.length > 0) {\n this.lightsWarningMessages.forEach(warning => {\n tempArray.push(warning);\n });\n }\n if (this.textureWarningMessages && this.textureWarningMessages.length > 0) {\n this.textureWarningMessages.forEach(warning => {\n tempArray.push(warning);\n });\n }\n if (this.meshWarningMessages && this.meshWarningMessages.length > 0) {\n this.meshWarningMessages.forEach(warning => {\n tempArray.push(warning);\n });\n }\n if (this.materialWarningMessages && this.materialWarningMessages.length > 0) {\n this.materialWarningMessages.forEach(warning => {\n tempArray.push(warning);\n });\n }\n if (this.normalSmoothingWarnings && this.normalSmoothingWarnings.size > 0) {\n this.normalSmoothingWarnings.forEach(warning => {\n tempArray.push(warning);\n });\n }\n if (tempArray.length === 0) {\n tempArray.push('No warnings to display.');\n }\n this.warningMessages = tempArray;\n this.warningTracker.next();\n }\n extractMeshGeometry(node) {\n const mesh = this.rendererManager.mesh.get3d(node);\n if (mesh && mesh instanceof Mesh && mesh.geometry) {\n const newGeometry = new exports.KbGeometry();\n newGeometry.indices = new Uint32Array(mesh.geometry.getIndices() || []);\n newGeometry.positions = new Float32Array(mesh.geometry.getVerticesData(VertexBuffer.PositionKind) || []);\n if (newGeometry.indices.length === 0 || newGeometry.positions.length === 0) {\n return null;\n }\n const normals = mesh.geometry.getVerticesData(VertexBuffer.NormalKind);\n if (normals) {\n newGeometry.normals = new Float32Array(normals);\n }\n const tangents = mesh.geometry.getVerticesData(VertexBuffer.TangentKind);\n if (tangents) {\n newGeometry.tangents = new Float32Array(tangents);\n }\n const uvs = mesh.geometry.getVerticesData(VertexBuffer.UVKind);\n if (uvs) {\n newGeometry.uvs = new Float32Array(uvs);\n }\n return newGeometry;\n }\n }\n applySvgToSketch(node, data) {\n return SvgConverter.overwriteSketchWithSvg(node, data);\n }\n draggingEvent(mousePosition) {\n let lastPickedMesh;\n const dragOver = new Subject();\n mousePosition.subscribe(position => {\n const pickInfo = this.interaction.pick(position.x, position.y);\n const mesh = pickInfo === null || pickInfo === void 0 ? void 0 : pickInfo.targetNode;\n if (lastPickedMesh !== mesh) {\n if (lastPickedMesh) {\n this.highlighter.remove(lastPickedMesh);\n }\n if (mesh) {\n this.highlighter.add(mesh, exports.KbColor.Green());\n }\n dragOver.next(mesh);\n lastPickedMesh = mesh;\n }\n }, () => { }, () => {\n if (lastPickedMesh) {\n this.highlighter.remove(lastPickedMesh);\n dragOver.complete();\n }\n });\n return dragOver.asObservable();\n }\n dispose() {\n this.disposed = true;\n this.positionTrackedNodes.clear();\n this.rendererManager.disposeAll();\n this.scene.dispose();\n this.engine.dispose();\n this.camera.dispose();\n this.manager.dispose();\n this.bbCache.dispose();\n this.sketchEditor.dispose();\n if (this.canvas) {\n this.container.removeChild(this.canvas);\n delete this.canvas;\n }\n if (this.uiOverlay) {\n this.container.removeChild(this.uiOverlay);\n delete this.uiOverlay;\n }\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n delete this.resizeObserver;\n }\n this.fpsTracker.complete();\n this.polygonTracker.complete();\n this.warningTracker.complete();\n this.meshWarningsNeedsUpdate.complete();\n this.materialWarningsNeedsUpdate.complete();\n this.animationWarningsNeedsUpdate.complete();\n }\n getScreenPositionOfNode(node) {\n const bNode = this.rendererManager.mesh.get3d(node);\n if (bNode) {\n return nodeToScreen(bNode, this.scene.activeCamera);\n }\n }\n getScreenBoundingBoxOfNode(node) {\n const bNode = this.rendererManager.mesh.get3d(node);\n if (bNode) {\n return getScreenBoundingBox(bNode, this.scene.activeCamera, true);\n }\n }\n getBabylonJson() {\n return JSON.stringify(SceneSerializer.Serialize(this.scene), null, 2);\n }\n exportGlb() {\n var _a;\n return this.gltfExporter.exportGlb((_a = this.sceneNode) === null || _a === void 0 ? void 0 : _a.name);\n }\n exportObj(meshNode) {\n var _a;\n const fileName = meshNode ? meshNode.name : (_a = this.sceneNode) === null || _a === void 0 ? void 0 : _a.name;\n return this.objExporter.exportObj(fileName, meshNode);\n }\n //returns an object containing the polygons and vertices withing the selected node\n recursiveGetPolygons(node) {\n if (node.visible == false) {\n return { polygons: 0, vertices: 0 };\n }\n if (node instanceof exports.MeshNode) {\n return { polygons: node._polygonCount || 0, vertices: node._verticesCount || 0 };\n }\n const result = { polygons: 0, vertices: 0 };\n const children = node.getChildren();\n children.forEach(child => {\n if (child instanceof exports.MeshNode || child instanceof exports.MeshGroupNode) {\n const childData = this.recursiveGetPolygons(child);\n result.polygons += childData.polygons;\n result.vertices += childData.vertices;\n }\n });\n return result;\n }\n //call with null\n onNextFrame(func) {\n this.nextFrameCallbacks.push(func);\n }\n userIsInteracting() {\n return this.interaction.pointerIsDown || this.gizmos.dragging;\n }\n /** runs the kb3d renderers. Called before the babylon render */\n preRender() {\n // If this kb viewer instance is disposed, exit the render loop\n if (this.disposed) {\n return;\n }\n this.bbCache.update(); //update watchers of the bbcache of everything that changed since the last frame\n this.animation.update(); //update all animations. This can result in changes, so should be called before the check for changes\n if (!this.rendererManager.isStable()) {\n /** nodes must be processed in a specific order. For example, materials must be processed before meshes,\n * or a new material wouldn't exist yet in babylon when the mesh renderer tries to apply it.\n */\n const hasChanges = SyncService.hasChanges;\n this.rendererManager.render();\n this.gizmos.updateGizmoPositions();\n //if there were changes, force a babylon render asap to keep responsive\n if (hasChanges) {\n this.forceRenderOnNextFrame = true;\n }\n this.viewChanged.next();\n while (this.nextFrameCallbacks.length > 0) {\n this.nextFrameCallbacks.pop()();\n }\n nextTick();\n }\n }\n startRender() {\n if (!this._renderLoopRunning) {\n this._renderLoopRunning = true;\n let frameCount = 0;\n // Run the render loop.\n this.engine.runRenderLoop(() => {\n this.preRender();\n let skipped = true;\n if (!this.pauseRender) {\n frameCount++;\n if (this.forceRunRenderer ||\n this.forceRenderOnNextFrame ||\n this.userIsInteracting() ||\n this.camera.cameraMoving ||\n this.animation.animationsAreRunning ||\n this.ar.xrActive) {\n this.scene.render();\n this.forceRenderOnNextFrame = false;\n this.viewChanged.next();\n skipped = false;\n }\n else if (frameCount > 10) {\n this.scene.render();\n skipped = false;\n }\n if (frameCount > 10) {\n frameCount = 0;\n this.fpsTracker.next(this.getFPS());\n }\n this.afterRender.next({ skipped });\n }\n });\n }\n }\n stopRender() {\n this.engine.stopRenderLoop();\n this._renderLoopRunning = false;\n }\n createCanvas() {\n const canvas = document.createElement('canvas');\n canvas.style.width = '100%';\n canvas.style.height = '100%';\n canvas.style.outline = 'none';\n canvas.style.opacity = '0';\n canvas.style.transition = `opacity ${FADE_TIME}ms linear`;\n this.container.appendChild(canvas);\n if (!this.container.style.position) {\n this.container.style.position = 'relative';\n }\n this.uiOverlay = this.createOverlay();\n this.container.appendChild(this.uiOverlay);\n this.resizeObserver = new ResizeObserver(() => this.resize());\n this.resizeObserver.observe(canvas);\n return canvas;\n }\n createOverlay() {\n const overlay = document.createElement('div');\n overlay.style.position = 'absolute';\n overlay.style.top = '0';\n overlay.style.left = '0';\n overlay.style.width = '100%';\n overlay.style.height = '100%';\n overlay.style.pointerEvents = 'none';\n return overlay;\n }\n createLoadingExperience(loadingExperience, loadingImagePath) {\n if (loadingExperience == exports.eLoadingExperience.image) {\n const matService = this.manager.getService(Token.MaterialService);\n this.loadingOverlay = this.createOverlay();\n this.loadingOverlay.style.opacity = '0';\n this.loadingOverlay.style.transition = `opacity ${FADE_TIME}ms linear`;\n const img = document.createElement('img');\n img.style.position = 'absolute';\n img.style.width = '100%';\n img.style.height = '100%';\n img.style.backgroundSize = 'auto 100%';\n img.style.backgroundRepeat = 'no-repeat';\n img.style.backgroundPosition = 'center';\n img.style.backgroundColor = 'transparent';\n img.style.backgroundImage = `url('${matService.getAbsoluteTexturePath(loadingImagePath)}')`;\n this.loadingOverlay.appendChild(img);\n this.container.appendChild(this.loadingOverlay);\n this.loadingOverlay.style.opacity = '1';\n }\n else if (loadingExperience == exports.eLoadingExperience.fade) ;\n else if (loadingExperience == exports.eLoadingExperience.spinner) {\n this.loadingOverlay = this.createOverlay();\n this.loadingOverlay.style.opacity = '0';\n this.loadingOverlay.style.transition = `opacity ${FADE_TIME}ms linear`;\n this.loadingOverlay.style.display = 'flex';\n this.loadingOverlay.style.alignItems = 'center';\n this.loadingOverlay.style.justifyContent = 'center';\n this.loadingOverlay.innerHTML = `\r\n \r\n \r\n \r\n \r\n `;\n this.container.appendChild(this.loadingOverlay);\n this.loadingOverlay.style.opacity = '1';\n }\n else {\n this.canvas.style.opacity = '1';\n }\n }\n hideLoadingExperience() {\n if (this.loadingOverlay) {\n this.loadingOverlay.style.opacity = '0';\n setTimeout(() => {\n var _a;\n (_a = this.loadingOverlay) === null || _a === void 0 ? void 0 : _a.remove();\n this.loadingOverlay = undefined;\n }, FADE_TIME);\n }\n this.canvas.style.opacity = '1';\n }\n resize() {\n if (!this.ar || (!this.ar.xrLoading && !this.ar.xrActive)) {\n //don't mess with the AR canvas resize\n this.engine.resize();\n this.fireViewChangedOnNextRender();\n }\n }\n optimizeScene(scene) {\n if (this.sceneNode.enableSceneOptimization) {\n this.forceRunRenderer = true; // Run renderer until optimizer is done optimizing\n const sceneOptimizerOptions = new SceneOptimizerOptions(30, 2000);\n let priority = 0;\n sceneOptimizerOptions.addCustomOptimization(function () {\n console.warn('Low scene performance detected - disabling 3d features to improve performance.');\n return true;\n }, function () {\n return 'custom optimization to throw console warning when optimizer needs to run.';\n }, priority);\n sceneOptimizerOptions.optimizations.push(new ShadowsOptimization(priority));\n sceneOptimizerOptions.optimizations.push(new LensFlaresOptimization(priority));\n // Next priority\n priority++;\n sceneOptimizerOptions.optimizations.push(new PostProcessesOptimization(priority));\n sceneOptimizerOptions.optimizations.push(new ParticlesOptimization(priority));\n priority++;\n sceneOptimizerOptions.optimizations.push(new TextureOptimization(priority, 256));\n priority++;\n sceneOptimizerOptions.optimizations.push(new RenderTargetsOptimization(priority));\n // Don't scale the resolution when in editor mode because it affects usability\n if (!this.options.editorMode) {\n priority++;\n sceneOptimizerOptions.optimizations.push(new HardwareScalingOptimization(priority, 4));\n }\n const sceneOptimizer = new SceneOptimizer(scene, sceneOptimizerOptions, false);\n sceneOptimizer.onSuccessObservable.add(() => {\n this.startSceneRenderAutoStop(scene, this.engine);\n // Run optimizer in improvement mode in case the scene speeds up later\n new SceneOptimizer(scene, sceneOptimizerOptions, false, true);\n });\n sceneOptimizer.onFailureObservable.add(() => this.startSceneRenderAutoStop(scene, this.engine));\n sceneOptimizer.start();\n }\n }\n createScene() {\n // Create a basic BJS Scene object.\n const scene = new Scene(this.engine);\n scene.useRightHandedSystem = true;\n scene.clearColor = new Color4(0, 0, 0, 0); //default background to transparent\n // Create a FreeCamera, and set its position to (x:0, y:5, z:-10).\n //this.m_camera = new FreeCamera('camera1', new Vector3(0, 5, -10), this.m_scene);\n //scene.createDefaultCameraOrLight(true, true, true);\n this.createDefaultEnv();\n return scene;\n }\n startSceneRenderAutoStop(scene, engine) {\n this.forceRunRenderer = false;\n }\n createDefaultEnv() {\n if (!this.scene) {\n return;\n }\n const helper = this.scene.createDefaultEnvironment({\n skyboxSize: 500,\n groundShadowLevel: 0.5,\n });\n if (helper !== null && helper.skybox !== null && helper.ground !== null) {\n helper.setMainColor(Color3.Gray());\n helper.rootMesh.position.y = -5;\n helper.skybox.isPickable = false;\n helper.rootMesh.isPickable = false;\n helper.ground.isPickable = false;\n //helper.rootMesh.name = KbViewer.KBMAXPREFIX + helper.rootMesh.name;\n //helper.skybox.name = KbViewer.KBMAXPREFIX + helper.skybox.name;\n for (let i = 0; i < this.scene.meshes.length; i++) {\n this.scene.meshes[i].name = KBMAXPREFIX + this.scene.meshes[i].name;\n this.scene.meshes[i].id = KBMAXPREFIX + this.scene.meshes[i].id;\n }\n }\n }\n pauseRenderWhile(action) {\n this.pauseRender = true;\n action();\n this.pauseRender = false;\n }\n /**\n * returns a promise that is resolved when the following has happened:\n * * the scene graph is fully loaded\n * * at least one pass through the render loop since the scene has been loaded has completed\n * * any server assets in flight (meshes, textures) have been received and processed\n */\n whenAssetsLoaded(waitForMaterials = true) {\n if (!this.sceneNode) {\n throw Error('a scene needs to be loaded into the viewer to wait for assets');\n }\n const promise = new Promise((resolve, reject) => {\n var _a, _b;\n const http = (_a = this.sceneNode._manager) === null || _a === void 0 ? void 0 : _a.getService(Token.HttpService);\n const materialService = (_b = this.sceneNode._manager) === null || _b === void 0 ? void 0 : _b.getService(Token.MaterialService);\n if (!http) {\n throw Error('HTTP API service could not be initialized');\n }\n if (!materialService) {\n throw Error('Material service could not be initialized');\n }\n this.forceAndWaitForNextRender().then(() => {\n const promises = [\n ...http.trackedAssetCalls,\n ...this.additionalLoadBlockers,\n this.scene.whenReadyAsync(),\n ];\n if (waitForMaterials) {\n promises.push(...materialService.trackedAssetCalls);\n }\n Promise.all(promises).finally(() => {\n // now wait for a render loop and make sure no new loading blockers were added since the last batch\n this.forceAndWaitForNextRender().then(() => {\n if (http.trackedAssetCalls.length ||\n this.additionalLoadBlockers.length ||\n (waitForMaterials && materialService.trackedAssetCalls.length) ||\n !this.scene.isReady() ||\n !this.rendererManager.isStable()) {\n return this.whenAssetsLoaded(waitForMaterials).finally(() => {\n resolve();\n });\n }\n else {\n resolve();\n }\n });\n });\n });\n });\n return promise;\n }\n deferSceneReady(promise) {\n promise.then(() => {\n this.additionalLoadBlockers = this.additionalLoadBlockers.filter(somePromise => somePromise !== promise);\n });\n this.additionalLoadBlockers.push(promise);\n }\n /**\n * Returns a promise that resolves when the next kb3d render processing has happened.\n * Note that this does not necessarily mean that the babylon render has happened!\n * If you want to wait for both, see forceAndWaitForNextRender\n */\n waitForNextKb3dRender() {\n return this.afterRender.pipe(take(1)).toPromise();\n }\n forceAndWaitForNextRender() {\n this.forceRenderOnNextFrame = true;\n return this.waitForNextKb3dRender();\n }\n async waitForStableRender(timeout = 5000) {\n const start = performance.now();\n await this.forceAndWaitForNextRender();\n while (!this.rendererManager.isStable()) {\n await this.forceAndWaitForNextRender();\n if (performance.now() - start > timeout) {\n console.error(`waiting for stable render took longer than timeout of ${timeout}ms, unblocking loading`);\n return false;\n }\n }\n return true;\n }\n fireViewChangedOnNextRender() {\n this.forceAndWaitForNextRender().then(() => {\n this.viewChanged.next();\n });\n }\n getActiveMates() {\n const mates = new Array();\n this.sceneNode.runOnAllScenes(s => {\n mates.push(...s._manager.getByToken(Token.MateNode).filter(m => m.isActive()));\n });\n return mates;\n }\n nodesIntersect(node1, node2) {\n const bb1 = this.bbCache.getWorld(node1);\n const bb2 = this.bbCache.getWorld(node2);\n if (bb1 && bb2) {\n return bb1.boundingInfo.intersects(bb2.boundingInfo, false);\n }\n return false;\n }\n getReferenceNodes(dynamicId) {\n var _a;\n const result = [];\n const references = this.rendererManager.referenceProcessor.getReferencesTo();\n if (references.has(dynamicId)) {\n const ids = (_a = references.get(dynamicId)) === null || _a === void 0 ? void 0 : _a.keys();\n if (ids) {\n for (const key of ids) {\n result.push(this.manager.getById(key));\n }\n }\n return result;\n }\n else {\n return [];\n }\n }\n getLocalMaterialsRecursive(node) {\n let result = 0;\n if (!node.scenes) {\n return node.materials.length | 0;\n }\n else {\n node.scenes.forEach(scene => {\n result += this.getLocalMaterialsRecursive(scene);\n });\n result += node.materials.length;\n }\n return result;\n }\n getTransformSpaceDifference(originNode, destinationNode) {\n const originMesh = this.getRendererNode(originNode);\n const destinationMesh = this.getRendererNode(destinationNode);\n const result = {\n scale: Vector3.One(),\n rotationQuaternion: new Quaternion(),\n translation: Vector3.Zero(),\n };\n if (!destinationMesh) {\n const resultMatrix = originMesh.getWorldMatrix();\n resultMatrix.decompose(result.scale, result.rotationQuaternion, result.translation);\n }\n else if (originMesh && destinationMesh) {\n const originMatrix = originMesh.getWorldMatrix();\n const destinationMatrix = destinationMesh.getWorldMatrix().clone();\n destinationMatrix.invert();\n const resultMatrix = originMatrix.multiply(destinationMatrix);\n resultMatrix.decompose(result.scale, result.rotationQuaternion, result.translation);\n }\n else {\n return null;\n }\n return {\n scale: result.scale.x,\n rotationQuaternion: exports.KbQuaternion.FromQuat(result.rotationQuaternion),\n translation: exports.KbVector.FromVec3(result.translation),\n };\n }\n centerMeshToOrigin(node) {\n const boundingBox = this.getMeshBoundingBox(node);\n const center = boundingBox === null || boundingBox === void 0 ? void 0 : boundingBox.maxWorld.add(boundingBox.minWorld);\n if (center) {\n center === null || center === void 0 ? void 0 : center.scaleInPlace(-0.5);\n const result = new exports.KbVector(center.x, center.y, center.z);\n return result;\n }\n else {\n return new exports.KbVector(0, 0, 0);\n }\n }\n }\n\n function kb3dTest() {\n let map = new SetMap();\n map.add('A', 'B', 'C');\n map.add('B', 'C', 'D');\n map.add('C', 'E');\n map.add('D', 'E', 'F');\n map.add('E');\n map.add('F');\n map.add('G', 'F', 'E');\n topologicalSort(map, s => s);\n map = new SetMap();\n map.add('0', '1', '2');\n map.add('1', '2');\n map.add('2', '0', '3');\n map.add('3');\n topologicalSort(map, s => s);\n map = new SetMap();\n map.add('2');\n map.add('3', '8', '10');\n map.add('5', '11');\n map.add('7', '8', '11');\n map.add('8', '9');\n map.add('9');\n map.add('10');\n map.add('11', '2', '9', '10');\n topologicalSort(map, s => s);\n const kbViewer = new KbViewer({ container: document.getElementById('viewer-div') });\n let manager = new Kb3dManager({ assetRoot: '' }); //default services automatically used\n let sceneNode = manager.create(Token.SceneNode);\n sceneNode.backgroundColor = new exports.KbColor(0.9, 0.9, 0.9, 1);\n sceneNode.enableHoverEffects = true;\n kbViewer.loadScene({ sceneNode });\n const group = manager.create(Token.MeshGroupNode);\n const box = manager.create(Token.BoxNode);\n const boxId = box.id;\n group.meshes.push(box);\n // let blah = manager.getById(boxId);\n // let db = manager.getAll().map(n => { return { id: n.id, name: n.name, type: n.$type }; });\n // alert(JSON.stringify(db, null, 2));\n // sceneNode.meshes.push(group);\n // db = manager.getAll().map(n => { return { id: n.id, name: n.name, type: n.$type }; });\n // alert(JSON.stringify(db, null, 2));\n // setTimeout(() => {\n // sceneNode.meshes.remove(group);\n // db = manager.getAll().map(n => { return { id: n.id, name: n.name, type: n.$type }; });\n // alert(JSON.stringify(db, null, 2));\n // }, 500);\n //sceneNode.meshes.push(box);\n // function animate(time: number) {\n // requestAnimationFrame(animate);\n // TWEEN.update(time);\n // }\n // requestAnimationFrame(animate);\n // let pos = { x: box.position.x, y: box.position.y, z: box.position.z };\n // const anim = new TWEEN.Tween(pos)\n // .to({ x: 3, y: 0, z: 0 }, 5000)\n // .onUpdate(() => {\n // box.position = KbVector.From(pos);\n // })\n // .start();\n // let group = manager.create(Token.MeshGroupNode);\n // group.rotation = new KbVector(0, 0, 0);\n // sceneNode.meshes.push(group);\n // let box = manager.create(Token.BoxNode);\n // let boxId = box.id;\n // box.materialId = \"bricks01\";\n // group.meshes.push(box);\n // let conn1 = manager.create(Token.Connector, {\n // positionMode: eConnectorPositionMode.boundingBox,\n // position: new KbVector(0, 1, 1),\n // direction: new KbVector(0, 0, 1)\n // });\n // box.features.push(conn1);\n // let mat = manager.create(Token.AdvancedMaterialNode, {\n // albedoColor: new KbColor(1, 0, 0),\n // backFaceCulling: false\n // });\n // sceneNode.materials.push(mat);\n // box.materialId = mat.id;\n // let sphere = manager.create(Token.SphereNode, {\n // diameter: 1,\n // position: new KbVector(2, 0,0)\n // });\n // group.meshes.push(sphere);\n // let box2 = manager.create(Token.BoxNode);\n // sceneNode.meshes.push(box2);\n // box2.position = new KbVector(0, 0, 3);\n // box2.width = 2;\n // let conn3 = manager.create(Token.Connector, {\n // positionMode: eConnectorPositionMode.absolute,\n // position: new KbVector(0, 0, -0.5),\n // direction: new KbVector(0, 0, -1),\n // angle: 0\n // });\n // let conn4 = manager.create(Token.Connector, {\n // positionMode: eConnectorPositionMode.absolute,\n // position: new KbVector(1, 0, 0),\n // direction: new KbVector(1, 0, 0),\n // angle: 30\n // });\n // let conn5 = manager.create(Token.Connector, {\n // positionMode: eConnectorPositionMode.absolute,\n // position: new KbVector(0, .5, 0),\n // direction: new KbVector(0, 1, 0),\n // angle: 0\n // });\n // box2.features.push(conn3);\n // box2.features.push(conn4);\n // box2.features.push(conn5);\n // manager.draggables.add(group.id, \"blah\", {\n // mode: eDragMode.free,\n // //surfaceNodes: [sphere.id, sphere2.id],\n // planeNormal: new KbVector(0, 1, 0),\n // // planeOrigin: new KbVector(0,0,0),\n // //disableOffset: false,\n // connectionMode: eConnectionMode.screen,\n // showConnectors: true,\n // connectRadius: 10,\n // dragOpacity: .3,\n // dragStart: (a) => {\n // },\n // dragging: (a) => {\n // },\n // dropped: (a) => {\n // },\n // // canConnect: (a) => {\n // // a.\n // // }\n // });\n // kbViewer.interaction.onPointerUp.subscribe(p => {\n // console.log(kbViewer.getScreenPositionOfNode(box));\n // console.log(kbViewer.getScreenBoundingBoxOfNode(box));\n // });\n const light = manager.create(Token.DirectionalLightNode);\n sceneNode.lights.push(light);\n // let mat = manager.create(tok.AdvancedMaterialNode, {\n // albedoColor: new KbColor(252, 0, 0)\n // });\n // sceneNode.materials.push(mat);\n // box.materialId = mat.id;\n //box.materialId = \"4454a0e3-e1e4-42d4-aea5-6915681bfc12\";\n // for (let row = 0; row < 10; row++){\n // for (let col = 0; col < 10; col++) {\n // let nested = manager.nestScene(sceneNode);\n // nested.name = \"nested\" + row;\n // let nestedManager = nested._manager as Kb3dManager;\n // let nestedBox = nestedManager.create(tok.BoxNode);\n // nestedBox.name = \"nestedBox\" + row;\n // if (row % 2 > 0) {\n // nestedBox.materialId = \"rock01\";\n // } else {\n // nestedBox.materialId = \"bricks01\";\n // }\n // nested.meshes.push(nestedBox);\n // nested.position = new KbVector(row * 1.5, col * 1.5, 0);\n // }\n // }\n kbViewer.interaction.onClick.subscribe(p => {\n console.log(p);\n });\n kbViewer.interaction.onKeyboard.subscribe(k => {\n console.log(k);\n });\n const btnAnimate = document.getElementById('btnAnimate');\n if (btnAnimate) {\n btnAnimate.onclick = () => {\n kbViewer.animation\n .queue({\n name: 'a1',\n node: box,\n prop: 'position',\n toValue: new exports.KbVector(10, 0, 0),\n duration: 1000,\n easing: exports.eEasing.quadraticIn,\n })\n .then(() => {\n return kbViewer.animation.queue({\n name: 'a2',\n node: box,\n prop: 'rotation',\n toValue: new exports.KbVector(box.eulerRotation.x + 720, 0, 0),\n duration: 1000,\n });\n })\n .then(() => {\n return kbViewer.animation.queue({\n name: 'a3',\n node: box,\n prop: 'position',\n toValue: new exports.KbVector(0, 0, 0),\n duration: 1000,\n easing: exports.eEasing.quadraticOut,\n });\n });\n };\n }\n const btnStop = document.getElementById('btnStop');\n if (btnStop) {\n btnStop.onclick = () => {\n kbViewer.animation.stop('a1');\n };\n }\n const txtJson = document.getElementById('txtJson');\n const txtCounter = document.getElementById('txtCounter');\n const btnToJson = document.getElementById('btnToJson');\n if (btnToJson) {\n btnToJson.onclick = () => {\n txtJson.value = manager.serializeToJson(sceneNode, { prettyPrint: true });\n updateJsonLength();\n };\n }\n const btnToFullJson = document.getElementById('btnToFullJson');\n if (btnToFullJson) {\n btnToFullJson.onclick = () => {\n txtJson.value = manager.serializeToJson(sceneNode, { omitDefaultValues: false, prettyPrint: true });\n updateJsonLength();\n };\n }\n const btnFromJson = document.getElementById('btnFromJson');\n if (btnFromJson) {\n btnFromJson.onclick = () => {\n manager = new Kb3dManager();\n const jsonObject = JSON.parse(txtJson.value);\n sceneNode = manager.create(Token.SceneNode, jsonObject);\n kbViewer.loadScene({ sceneNode });\n };\n }\n const btnBabylonJson = document.getElementById('btnBabylonJson');\n if (btnBabylonJson) {\n btnBabylonJson.onclick = () => {\n txtJson.value = kbViewer.getBabylonJson();\n };\n }\n const btnWidth = document.getElementById('btnWidth');\n if (btnWidth) {\n btnWidth.onclick = () => {\n box.depth = box.depth + 1;\n };\n }\n const btnMaterialColor = document.getElementById('btnMaterialColor');\n if (btnMaterialColor) {\n btnMaterialColor.onclick = () => {\n //mat.albedoColor = new KbColor(0, 0, 252);\n };\n }\n // let btnToggleVisible = document.getElementById(\"btnToggleVisible\");\n // if (btnToggleVisible) {\n // btnToggleVisible.onclick = () => {\n // box.visible = !box.visible;\n // };\n // }\n const btnSaveMesh = document.getElementById('btnSaveMesh');\n if (btnSaveMesh) {\n btnSaveMesh.onclick = () => {\n const myArray = new ArrayBuffer(512);\n const longInt8View = new Uint8Array(myArray);\n // generate some data\n for (let i = 0; i < longInt8View.length; i++) {\n longInt8View[i] = i % 256;\n }\n const xhr = new XMLHttpRequest();\n xhr.open('POST', '/api/meshes/72b7487f-2ab2-4faf-b034-a1178feeb191', false);\n xhr.send(myArray);\n };\n }\n const btnGetSavedMesh = document.getElementById('btnGetSavedMesh');\n if (btnGetSavedMesh) {\n btnGetSavedMesh.onclick = () => {\n const oReq = new XMLHttpRequest();\n oReq.open('GET', '/api/meshes/72b7487f-2ab2-4faf-b034-a1178feeb191', true);\n oReq.responseType = 'arraybuffer';\n oReq.onload = function (oEvent) {\n const arrayBuffer = oReq.response; // Note: not oReq.responseText\n if (arrayBuffer) {\n const byteArray = new Uint8Array(arrayBuffer);\n for (let i = 0; i < byteArray.byteLength; i++) {\n // do something with each byte in the array\n console.log(byteArray[i]);\n }\n }\n };\n oReq.send(null);\n };\n }\n const updateJsonLength = () => {\n txtCounter.innerHTML = new TextEncoder().encode(txtJson.value).length.toString() + ' bytes';\n };\n }\n\n const kb3dEnums = _kb3dEnums;\n\n exports.ABORTED = ABORTED;\n exports.ALL_CHANGES = ALL_CHANGES;\n exports.ALL_GEOMETRY = ALL_GEOMETRY;\n exports.AR = AR;\n exports.AUTO_MESH_NAME = AUTO_MESH_NAME;\n exports.AnimationModule = AnimationModule;\n exports.AnnotationRenderer = AnnotationRenderer;\n exports.ArrayMap = ArrayMap;\n exports.BaseKb3dModel = BaseKb3dModel;\n exports.Boundary = Boundary;\n exports.BoundingBoxCache = BoundingBoxCache;\n exports.BoundingBoxRelativeHelper = BoundingBoxRelativeHelperKbVector;\n exports.CONNECTOR_DIAM = CONNECTOR_DIAM;\n exports.CameraTools = CameraTools;\n exports.ChangeMap = ChangeMap;\n exports.ColorFillTextureLayerRenderer = ColorFillTextureLayerRenderer;\n exports.ConnectorRenderer = ConnectorRenderer;\n exports.DimensionRenderer = DimensionRenderer;\n exports.Dragger = Dragger;\n exports.Enumerable = Enumerable;\n exports.FileTextureLayerRenderer = FileTextureLayerRenderer;\n exports.FontService = FontService;\n exports.GLTFKb3dExporter = GLTFKb3dExporter;\n exports.GizmoTools = GizmoTools;\n exports.GuiHelper = GuiHelper;\n exports.HandlerMap = HandlerMap;\n exports.HttpService = HttpService;\n exports.Ignore = Ignore;\n exports.IgnoreChanges = IgnoreChanges;\n exports.IgnoreHistory = IgnoreHistory;\n exports.Inject = Inject;\n exports.Interaction = Interaction;\n exports.KBMAXPREFIX = KBMAXPREFIX;\n exports.Kb3dManager = Kb3dManager;\n exports.Kb3dModel = Kb3dModel;\n exports.Kb3dModels = Kb3dModels;\n exports.Kb3dService = Kb3dService;\n exports.Kb3dWorker = Kb3dWorker;\n exports.KbAxisDragGizmo = KbAxisDragGizmo;\n exports.KbAxisScaleGizmo = KbAxisScaleGizmo;\n exports.KbGizmo = KbGizmo;\n exports.KbLightGizmo = KbLightGizmo;\n exports.KbPlaneRotationGizmo = KbPlaneRotationGizmo;\n exports.KbPositionGizmo = KbPositionGizmo;\n exports.KbRotationGizmo = KbRotationGizmo;\n exports.KbScaleGizmo = KbScaleGizmo;\n exports.KbVertexSelectGizmo = KbVertexSelectGizmo;\n exports.KbViewer = KbViewer;\n exports.KbViewpointGizmo = KbViewpointGizmo;\n exports.LOCAL_ENVIRONMENT_DOMAIN = LOCAL_ENVIRONMENT_DOMAIN;\n exports.LibraryEnvironments = LibraryEnvironments;\n exports.LibraryEnvironmentsMap = LibraryEnvironmentsMap;\n exports.LibraryMaterials = LibraryMaterials;\n exports.LibraryMaterialsByCategory = LibraryMaterialsByCategory;\n exports.LightRenderer = LightRenderer;\n exports.MateProcessor = MateProcessor;\n exports.MateRenderer = MateRenderer;\n exports.MaterialRenderer = MaterialRenderer;\n exports.MeshRenderer = MeshRenderer;\n exports.MeshService = MeshService;\n exports.MoveVerticesRenderer = MoveVerticesRenderer;\n exports.NEW_GEOMETRY = NEW_GEOMETRY;\n exports.NodeReference = NodeReference;\n exports.NormalSmoothingRenderer = NormalSmoothingRenderer;\n exports.ObjKb3dExporter = ObjKb3dExporter;\n exports.PRECISION = PRECISION;\n exports.PathHandler = PathHandler;\n exports.PathParser = PathParser;\n exports.PathRenderer = PathRenderer;\n exports.PatternFeature = PatternFeature;\n exports.PatternRenderer = PatternRenderer;\n exports.Processor = Processor;\n exports.Quad = Quad;\n exports.QuadTree = QuadTree;\n exports.RendererManager = RendererManager;\n exports.SKYBOX_SIZE = SKYBOX_SIZE;\n exports.SamplingModeMap = SamplingModeMap;\n exports.SceneRenderer = SceneRenderer;\n exports.SetMap = SetMap;\n exports.ShadowLightNode = ShadowLightNode;\n exports.SketchEditor = SketchEditor;\n exports.SnapshotModule = SnapshotModule;\n exports.SubmeshRenderer = SubmeshRenderer;\n exports.SvgConverter = SvgConverter;\n exports.SvgTextureLayerRenderer = SvgTextureLayerRenderer;\n exports.SyncService = SyncService;\n exports.TagArrayMap = TagArrayMap;\n exports.TextMeshFont = TextMeshFont;\n exports.TextMeshVertexData = TextMeshVertexData;\n exports.TextureLayerRenderer = TextureLayerRenderer;\n exports.Token = Token;\n exports.TrackChanges = TrackChanges;\n exports.TrackChangesNode = TrackChangesNode;\n exports.USDZConverter = USDZConverter;\n exports.UUID = UUID;\n exports.UVMapHelper = UVMapHelper;\n exports.UvMapRenderer = UvMapRenderer;\n exports.Validator = Validator;\n exports.ViewpointRenderer = ViewpointRenderer;\n exports.absoluteUrlRegex = absoluteUrlRegex;\n exports.addArrays = addArrays;\n exports.appendOrIncrementNumber = appendOrIncrementNumber;\n exports.applyMatrix4 = applyMatrix4;\n exports.applyTransformToSpace = applyTransformToSpace;\n exports.applyTransformToVector = applyTransformToVector;\n exports.axisToVector3 = axisToVector3;\n exports.bakeMeshTransform = bakeMeshTransform;\n exports.boundingVectorsToScreen = boundingVectorsToScreen;\n exports.buildHeader = buildHeader;\n exports.buildUSDAFile = buildUSDAFile;\n exports.buildXform = buildXform;\n exports.calculateFaceNormal = calculateFaceNormal;\n exports.calculateFaceNormalFromFloats = calculateFaceNormalFromFloats;\n exports.calculateTransform = calculateTransform;\n exports.changesProcessed = changesProcessed;\n exports.computeLocalTransform = computeLocalTransform;\n exports.computeNormal = computeNormal;\n exports.convertHdrToEnv = convertHdrToEnv;\n exports.createAnnotationTextModels = createAnnotationTextModels;\n exports.createLightVisualization = createLightVisualization;\n exports.createSketchPointForEditor = createSketchPointForEditor;\n exports.createUvMapVisualization = createUvMapVisualization;\n exports.createViewpointVisualization = createViewpointVisualization;\n exports.defaults = defaults;\n exports.degreeToRadian = degreeToRadian;\n exports.drawLine = drawLine;\n exports.escapeGUID = escapeGUID;\n exports.excludeVertices = excludeVertices;\n exports.fillSketchPolygon = fillSketchPolygon;\n exports.getByDynamicId = getByDynamicId;\n exports.getCameraPositionWithOffset = getCameraPositionWithOffset;\n exports.getConstructorParamsForModel = getConstructorParamsForModel;\n exports.getDimensionLinePoints = getDimensionLinePoints;\n exports.getHierarchyBoundingVectors = getHierarchyBoundingVectors;\n exports.getNodeChain = getNodeChain;\n exports.getNodeMap = getNodeMap;\n exports.getPositionFromConnnector = getPositionFromConnnector;\n exports.getRotationBtwVectors = getRotationBtwVectors;\n exports.getScreenBoundingBox = getScreenBoundingBox;\n exports.getSketchNormalVector3 = getSketchNormalVector3;\n exports.getToken = getToken;\n exports.guidRegex = guidRegex;\n exports.history = history;\n exports.injectParameters = injectParameters;\n exports.instanceOf = instanceOf;\n exports.instanceOfAny = instanceOfAny;\n exports.isAbsoluteUrl = isAbsoluteUrl;\n exports.isAnnotation = isAnnotation;\n exports.isBoxMesh = isBoxMesh;\n exports.isCircularPattern = isCircularPattern;\n exports.isConeMesh = isConeMesh;\n exports.isConnector = isConnector;\n exports.isCustomMeshNode = isCustomMeshNode;\n exports.isCylinderMesh = isCylinderMesh;\n exports.isDefined = isDefined;\n exports.isDiscMesh = isDiscMesh;\n exports.isFeatureNode = isFeatureNode;\n exports.isGuid = isGuid;\n exports.isInstanceOf = isInstanceOf;\n exports.isLightNode = isLightNode;\n exports.isLinearPattern = isLinearPattern;\n exports.isMate = isMate;\n exports.isMaterialNode = isMaterialNode;\n exports.isMeshGroupNode = isMeshGroupNode;\n exports.isMeshNode = isMeshNode;\n exports.isObject = isObject$1;\n exports.isPattern = isPattern;\n exports.isPickable = isPickable;\n exports.isPlaneMesh = isPlaneMesh;\n exports.isPrimitiveMeshNode = isPrimitiveMeshNode;\n exports.isSceneNode = isSceneNode;\n exports.isSketchControlPoint = isSketchControlPoint;\n exports.isSketchNode = isSketchNode;\n exports.isSpaceNode = isSpaceNode;\n exports.isSphereMesh = isSphereMesh;\n exports.isSubmesh = isSubmesh;\n exports.isTextNode = isTextNode;\n exports.isTextureLayer = isTextureLayer;\n exports.isTorusMesh = isTorusMesh;\n exports.isTrackedArray = isTrackedArray;\n exports.isTrackedClass = isTrackedClass;\n exports.isTrackedInstance = isTrackedInstance;\n exports.isTrackedInstanceOfAny = isTrackedInstanceOfAny;\n exports.isTrackedMeshNode = isTrackedMeshNode;\n exports.isViewpointNode = isViewpointNode;\n exports.kb3dEnums = kb3dEnums;\n exports.kb3dTest = kb3dTest;\n exports.makeRotationAxis = makeRotationAxis;\n exports.mathClamp = mathClamp;\n exports.mergeVertices = mergeVertices;\n exports.mergeVerticesIntoAll = mergeVerticesIntoAll;\n exports.multiplyScalar = multiplyScalar;\n exports.nextTick = nextTick;\n exports.nodeToScreen = nodeToScreen;\n exports.ofToken = ofToken;\n exports.omitUndefinedElements = omitUndefinedElements;\n exports.parseSketchGeometry = parseSketchGeometry;\n exports.projectOnNodeAxis = projectOnNodeAxis;\n exports.removeVerticesFromAll = removeVerticesFromAll;\n exports.rotationToVector = rotationToVector;\n exports.rotationToVectorToRef = rotationToVectorToRef;\n exports.roundToPlaces = roundToPlaces;\n exports.roundVectorToPlaces = roundVectorToPlaces;\n exports.sortMates = sortMates;\n exports.toBoundingBoxInfo = toBoundingBoxInfo;\n exports.toNDC = toNDC;\n exports.toPixels = toPixels;\n exports.toRadians = toRadians;\n exports.toScreen = toScreen;\n exports.transformVectorWithQuat = transformVectorWithQuat;\n exports.updateAnnotationText = updateAnnotationText;\n exports.updateMatrixOfAncestorChain = updateMatrixOfAncestorChain;\n\n return exports;\n\n}({}));\n//# sourceMappingURL=viewer.js.map\n","declare global {\r\n interface String {\r\n capitalize(): string;\r\n splitWords(): string[];\r\n isEqual(str: string | undefined): boolean;\r\n equalsAny(...strings: string[]): boolean;\r\n toSentence(): string;\r\n }\r\n interface Array {\r\n sortBy(predicate: (element: T) => any): void;\r\n /**\r\n * Conditionally removes items from an array and returns a new array with the removed items.\r\n */\r\n removeWhere(predicate: (item: T) => boolean): T[];\r\n\r\n remove(item: T): T[];\r\n\r\n selectMany(selector: (item: T) => TChild[]): TChild[];\r\n first(): T;\r\n last(): T;\r\n\r\n clear(): void;\r\n\r\n reorder(fromIndex: number, toIndex: number, undo?: boolean): void;\r\n\r\n contains(item: T): boolean;\r\n /**\r\n * Given a predicate to reduce each item in the array to a value,\r\n * will return that value if all items in the array have the same value.\r\n * If not, will return null.\r\n */\r\n getCommonOrNull(predicate: (item: T) => any): any;\r\n\r\n toMap(keySelector: (item: T) => TKey): Map;\r\n }\r\n interface Set {\r\n find(predicate: (item: T) => boolean): T | undefined;\r\n }\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n interface Map {\r\n hasAny(...keys: K[]): boolean;\r\n }\r\n}\r\n\r\nString.prototype.capitalize = function () {\r\n return this.charAt(0).toUpperCase() + this.slice(1);\r\n};\r\n\r\nconst splitWordsRegex = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;\r\nString.prototype.splitWords = function () {\r\n return this.match(splitWordsRegex) || [];\r\n};\r\n\r\nString.prototype.isEqual = function (str: string) {\r\n return (this ? this.toUpperCase() : undefined) === (str ? str.toUpperCase() : undefined);\r\n};\r\n\r\nString.prototype.equalsAny = function (...strings: string[]) {\r\n return strings && strings.some(s => s.isEqual(this as string));\r\n};\r\n\r\nString.prototype.toSentence = function () {\r\n return this.replace(/([A-Z])/g, ' $1') // insert a space before all caps\r\n .replace(/^./, function (str) {\r\n return str.toUpperCase();\r\n }) // uppercase the first character\r\n .trim(); //trip leading and trainling whitespace\r\n};\r\n\r\nObject.defineProperty(Array.prototype, 'sortBy', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate: (item: any) => any) {\r\n return (this as any[]).sort((a, b) => {\r\n if (predicate(a) < predicate(b)) {\r\n return -1;\r\n } else if (predicate(a) > predicate(b)) {\r\n return 1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'remove', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (item: any): any[] | undefined {\r\n const index = this.indexOf(item);\r\n if (index != -1) {\r\n return this.splice(this.indexOf(item), 1);\r\n }\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'removeWhere', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate: (item: any) => boolean) {\r\n const removed = new Array();\r\n for (let i = this.length - 1; i >= 0; i--) {\r\n const item = this[i];\r\n if (predicate(item)) {\r\n removed.push(...this.splice(i, 1));\r\n }\r\n }\r\n return removed;\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'contains', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (item: any): boolean {\r\n const index = this.indexOf(item);\r\n return index != -1;\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'selectMany', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector: (item: any) => any[]) {\r\n return this.reduce((out: any, v: any) => {\r\n let vres = selector(v);\r\n if (vres != null) {\r\n if (!Array.isArray(vres)) vres = [vres];\r\n out.push(...vres);\r\n }\r\n\r\n return out;\r\n }, []);\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'first', {\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n let item;\r\n if (this.length) {\r\n item = this[0];\r\n }\r\n return item;\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'last', {\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n if (this.length) {\r\n return this[this.length - 1];\r\n }\r\n return undefined;\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'getCommonOrNull', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (valueDelegate: (item: any) => any) {\r\n const arr = this as any[];\r\n if (this.length && arr.every(i => valueDelegate(i) == valueDelegate(arr[0]))) {\r\n return valueDelegate(arr[0]);\r\n }\r\n return null;\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'toMap', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (keySelector: (item: any) => any) {\r\n const m = new Map();\r\n for (const i of this) {\r\n m.set(keySelector(i), i);\r\n }\r\n return m;\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'clear', {\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n if (this.length > 0) {\r\n this.splice(0, this.length);\r\n }\r\n },\r\n});\r\n\r\nObject.defineProperty(Array.prototype, 'reorder', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (fromIndex: number, toIndex: number, undo?: boolean) {\r\n if (undo) {\r\n if (fromIndex > toIndex) {\r\n fromIndex--;\r\n } else {\r\n toIndex++;\r\n }\r\n }\r\n const itemToMove = this[fromIndex];\r\n for (let i = fromIndex; i < this.length - 1; i++) {\r\n this[i] = this[i + 1];\r\n }\r\n if (toIndex > fromIndex) {\r\n toIndex--;\r\n }\r\n for (let i = this.length - 1; i > toIndex; i--) {\r\n this[i] = this[i - 1];\r\n }\r\n this[toIndex] = itemToMove;\r\n },\r\n});\r\n\r\nObject.defineProperty(Set.prototype, 'find', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate: (item: any) => boolean) {\r\n for (const i of this) {\r\n if (predicate(i)) return i;\r\n }\r\n return undefined;\r\n },\r\n});\r\n\r\nObject.defineProperty(Map.prototype, 'hasAny', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (...keys: any[]) {\r\n return keys.some(k => this.has(k));\r\n },\r\n});\r\n\r\nexport {};\r\n","/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","import { FontService, HttpService, MeshService } from '@models/services';\r\nimport { MaterialService } from '../services/material-service';\r\nimport { AnnotationNode, DimensionNode } from './annotations';\r\nimport {\r\n BaseConnector,\r\n CircularPatternFeature,\r\n DeleteFacesFeature,\r\n DisplacementMapFeature,\r\n ExtrudeFeature,\r\n Feature,\r\n JoinGeometryFeature,\r\n MoveVerticesFeature,\r\n NormalSmoothingFeature,\r\n SweepFeature,\r\n TransformFeature,\r\n UvMapFeature,\r\n WeldVerticesFeature,\r\n} from './features';\r\nimport { Connector } from './features/connector';\r\nimport { MirrorFeature } from './features/mirror-feature';\r\nimport { PatternFeature } from './features/pattern-feature';\r\nimport { SketchControlPoint } from './features/sketch-control-point';\r\nimport { SliceFeature } from './features/slice-feature';\r\nimport { SubmeshFeature } from './features/submesh-feature';\r\nimport { IImportInfo } from './kb3d-models';\r\nimport { Kb3dObject } from './kb3d-object';\r\nimport { DirectionalLightNode, HemisphericLightNode, LightNode, PointLightNode, SpotLightNode } from './lights';\r\nimport {\r\n AdvancedMaterialNode,\r\n FileTextureLayer,\r\n MaterialNode,\r\n SvgTextureLayer,\r\n TextTextureLayer,\r\n TextureLayer,\r\n} from './materials';\r\nimport { ColorFillTextureLayer } from './materials/color-fill-texture-layer';\r\nimport { MateNode } from './mates/mate-node';\r\nimport {\r\n BoxNode,\r\n CustomMeshNode,\r\n CylinderNode,\r\n DiscNode,\r\n MeshGroupNode,\r\n MeshNode,\r\n PlaneNode,\r\n PrimitiveMeshNode,\r\n SpaceNode,\r\n SphereNode,\r\n TorusNode,\r\n} from './meshes';\r\nimport { ConeNode } from './meshes/cone-node';\r\nimport { SketchNode } from './meshes/sketch-node';\r\nimport { SketchPath } from './meshes/sketch-node-path';\r\nimport { TextNode } from './meshes/text-node';\r\nimport { KbColor, KbGeometry, KbQuaternion, KbVector } from './primitives';\r\nimport { SceneNode } from './scene-node';\r\nimport { ViewpointNode } from './viewpoints/viewpoint-node';\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport class Token {\r\n protected constructor(public key: string) {}\r\n\r\n public static withKey(key: keyof typeof Token): Token {\r\n const token = this[key] as Token;\r\n if (!token) throw new Error(`Could not find token for key '${key}'`);\r\n return token;\r\n }\r\n\r\n public static tryWithKey(key: keyof typeof Token): Token | undefined {\r\n const token = this[key] as Token;\r\n return token;\r\n }\r\n\r\n /** Services */\r\n public static HttpService = new Token('HttpService');\r\n public static MaterialService = new Token('MaterialService');\r\n public static MeshService = new Token('MeshService');\r\n public static JobService = new Token('JobService');\r\n public static SceneService = new Token('SceneService');\r\n public static FontService = new Token('FontService');\r\n public static Ignore = new Token('Ignore');\r\n\r\n /** Roots */\r\n public static SceneNode = new Token('SceneNode');\r\n public static Kb3dObject = new Token('Kb3dObject');\r\n public static ImportInfo = new Token('ImportInfo');\r\n\r\n /** Lights */\r\n public static LightNode = new Token('LightNode');\r\n public static DirectionalLightNode = new Token('DirectionalLightNode');\r\n public static HemisphericLightNode = new Token('HemisphericLightNode');\r\n public static PointLightNode = new Token('PointLightNode');\r\n public static SpotLightNode = new Token('SpotLightNode');\r\n\r\n /** Meshes */\r\n public static BoxNode = new Token('BoxNode');\r\n public static CustomMeshNode = new Token('CustomMeshNode');\r\n public static CylinderNode = new Token('CylinderNode');\r\n public static ConeNode = new Token('ConeNode');\r\n public static DiscNode = new Token('DiscNode');\r\n public static PlaneNode = new Token('PlaneNode');\r\n public static SphereNode = new Token('SphereNode');\r\n public static TorusNode = new Token('TorusNode');\r\n public static MeshNode = new Token('MeshNode');\r\n public static PrimitiveMeshNode = new Token('PrimitiveMeshNode');\r\n public static MeshGroupNode = new Token('MeshGroupNode');\r\n public static SpaceNode = new Token('SpaceNode');\r\n public static TextNode = new Token('TextNode');\r\n public static SketchNode = new Token('SketchNode');\r\n public static SketchPath = new Token('SketchPath');\r\n\r\n /** Dimensions */\r\n public static AnnotationNode = new Token('AnnotationNode');\r\n public static DimensionNode = new Token('DimensionNode');\r\n\r\n /** Primitives */\r\n public static KbColor = new Token('KbColor');\r\n // public static KbColor4 = new Token(\"KbColor4\");\r\n public static KbGeometry = new Token('KbGeometry');\r\n public static KbQuaternion = new Token('KbQuaternion');\r\n public static KbVector = new Token('KbVector');\r\n\r\n /** Materials */\r\n public static MaterialNode = new Token('MaterialNode');\r\n public static AdvancedMaterialNode = new Token('AdvancedMaterialNode');\r\n public static MaterialMapping = new Token('MaterialMapping');\r\n\r\n /** Textures */\r\n public static TextureLayer = new Token('TextureLayer');\r\n public static FileTextureLayer = new Token('FileTextureLayer');\r\n public static SvgTextureLayer = new Token('SvgTextureLayer');\r\n public static TextTextureLayer = new Token('TextTextureLayer');\r\n public static ColorFillTextureLayer = new Token('ColorFillTextureLayer');\r\n\r\n /** Viewpoints */\r\n public static ViewpointNode = new Token('ViewpointNode');\r\n\r\n /** Features */\r\n public static Feature = new Token('Feature');\r\n public static BaseConnector = new Token('BaseConnector');\r\n public static Connector = new Token('Connector');\r\n public static SketchControlPoint = new Token('SketchControlPoint');\r\n public static SubmeshFeature = new Token('SubmeshFeature');\r\n public static MoveVerticesFeature = new Token('MoveVerticesFeature');\r\n public static WeldVerticesFeature = new Token('WeldVerticesFeature');\r\n public static DisplacementMapFeature = new Token('DisplacementMapFeature');\r\n public static UvMapFeature = new Token('UvMapFeature');\r\n public static LinearPatternFeature = new Token('LinearPatternFeature');\r\n public static CircularPatternFeature = new Token('CircularPatternFeature');\r\n public static JoinGeometryFeature = new Token('JoinGeometryFeature');\r\n public static DeleteFacesFeature = new Token('DeleteFacesFeature');\r\n public static NormalSmoothingFeature = new Token('NormalSmoothingFeature');\r\n public static SliceFeature = new Token('SliceFeature');\r\n public static MirrorFeature = new Token('MirrorFeature');\r\n public static TransformFeature = new Token('TransformFeature');\r\n public static ExtrudeFeature = new Token('ExtrudeFeature');\r\n public static SweepFeature = new Token('SweepFeature');\r\n\r\n public static MateNode = new Token('MateNode');\r\n\r\n protected static MapFrom(...tokens: Token[]) {\r\n return new Map(tokens.map(t => [t, null]));\r\n }\r\n\r\n public static PrimitiveTokens = [Token.KbVector, Token.KbQuaternion, Token.KbColor];\r\n public static PrimitiveTokenMap = Token.MapFrom(...Token.PrimitiveTokens);\r\n\r\n public static PrimitiveMeshTokens = [\r\n Token.BoxNode,\r\n Token.CylinderNode,\r\n Token.ConeNode,\r\n Token.DiscNode,\r\n Token.PlaneNode,\r\n Token.SphereNode,\r\n Token.TorusNode,\r\n ];\r\n public static PrimitiveMeshTokenMap = Token.MapFrom(...Token.PrimitiveMeshTokens);\r\n\r\n public static MeshTokens = Token.PrimitiveMeshTokens.concat(Token.CustomMeshNode, Token.SketchNode, Token.TextNode);\r\n public static MeshTokenMap = Token.MapFrom(...Token.MeshTokens);\r\n\r\n public static MeshAndGroupTokens = Token.MeshTokens.concat(Token.MeshGroupNode);\r\n public static MeshAndGroupTokenMap = Token.MapFrom(...Token.MeshAndGroupTokens);\r\n\r\n public static SpaceTokens = Token.MeshAndGroupTokens.concat(Token.SceneNode);\r\n public static SpaceTokenMap = Token.MapFrom(...Token.SpaceTokens);\r\n\r\n public static MaterialTokens = [Token.AdvancedMaterialNode];\r\n\r\n public static MaterialTokenMap = Token.MapFrom(...Token.MaterialTokens);\r\n\r\n public static AnnotationTokens = [Token.AnnotationNode, Token.DimensionNode];\r\n\r\n public static AnnotationTokenMap = Token.MapFrom(...Token.AnnotationTokens);\r\n\r\n public static PositionalLightTokens = [Token.PointLightNode, Token.SpotLightNode];\r\n public static GlobalLightTokens = [Token.DirectionalLightNode, Token.HemisphericLightNode];\r\n public static LightTokens = [...Token.GlobalLightTokens, ...Token.PositionalLightTokens];\r\n public static LightTokenMap = Token.MapFrom(...Token.LightTokens);\r\n\r\n public static FeatureTokens = [\r\n Token.MoveVerticesFeature,\r\n Token.WeldVerticesFeature,\r\n Token.DisplacementMapFeature,\r\n Token.UvMapFeature,\r\n Token.SubmeshFeature,\r\n Token.LinearPatternFeature,\r\n Token.CircularPatternFeature,\r\n Token.JoinGeometryFeature,\r\n Token.DeleteFacesFeature,\r\n Token.NormalSmoothingFeature,\r\n Token.SliceFeature,\r\n Token.MirrorFeature,\r\n Token.TransformFeature,\r\n Token.ExtrudeFeature,\r\n Token.SweepFeature,\r\n ];\r\n public static FeatureTokenMap = Token.MapFrom(...Token.FeatureTokens);\r\n\r\n public static ConnectorTokens = [Token.Connector, Token.SketchControlPoint];\r\n\r\n public static TextureLayerTokens = [\r\n Token.TextureLayer,\r\n Token.FileTextureLayer,\r\n Token.SvgTextureLayer,\r\n Token.TextTextureLayer,\r\n Token.ColorFillTextureLayer,\r\n ];\r\n public static TextureLayerTokenMap = Token.MapFrom(...Token.TextureLayerTokens);\r\n\r\n public static NodeTokens = [\r\n ...Token.SpaceTokens,\r\n ...Token.MaterialTokens,\r\n ...Token.LightTokens,\r\n ...Token.AnnotationTokens,\r\n Token.ViewpointNode,\r\n Token.MateNode,\r\n ];\r\n public static NodeTokenMap = Token.MapFrom(...Token.NodeTokens);\r\n public static BaseNodeTokens = [\r\n Token.SpaceNode,\r\n Token.MaterialNode,\r\n Token.LightNode,\r\n Token.ViewpointNode,\r\n Token.MateNode,\r\n Token.AnnotationNode,\r\n ];\r\n\r\n public static AllTokens = Token.NodeTokens.concat(\r\n ...Token.PrimitiveTokens,\r\n Token.FeatureTokens,\r\n Token.TextureLayerTokens,\r\n Token.ConnectorTokens,\r\n [Token.SketchPath]\r\n );\r\n public static AllTokenMap = Token.MapFrom(...Token.AllTokens);\r\n\r\n public isPrimitive(): boolean {\r\n return Token.PrimitiveTokenMap.has(this);\r\n }\r\n public isPrimitiveMesh(): boolean {\r\n return Token.PrimitiveMeshTokenMap.has(this);\r\n }\r\n public isMesh(): boolean {\r\n return Token.MeshTokenMap.has(this);\r\n }\r\n public isMeshOrGroup(): boolean {\r\n return Token.MeshAndGroupTokenMap.has(this);\r\n }\r\n public isMaterial(): boolean {\r\n return Token.MaterialTokenMap.has(this);\r\n }\r\n public isFeature(): boolean {\r\n return Token.FeatureTokenMap.has(this);\r\n }\r\n public isTexture(): boolean {\r\n return Token.TextureLayerTokenMap.has(this);\r\n }\r\n public isLight(): boolean {\r\n return Token.LightTokenMap.has(this);\r\n }\r\n public isViewpoint(): boolean {\r\n return Token.ViewpointNode === this;\r\n }\r\n public isMate(): boolean {\r\n return Token.MateNode === this;\r\n }\r\n public isConnector(): boolean {\r\n return Token.Connector === this || Token.SketchControlPoint === this;\r\n }\r\n public isAnnotation(): boolean {\r\n return Token.AnnotationTokenMap.has(this);\r\n }\r\n public isNode(): boolean {\r\n return Token.NodeTokenMap.has(this);\r\n }\r\n public isSceneNode(): boolean {\r\n return Token.SceneNode === this;\r\n }\r\n public isSketchPath(): boolean {\r\n return Token.SketchPath === this;\r\n }\r\n}\r\n","import { ITrackedClass } from '@models/interfaces';\r\nimport { Token } from '../token';\r\nimport { Validator } from '../validator';\r\nimport { TrackChangesOptions } from './change-tracker';\r\nimport { IDecoratedModel } from './kb3d-decorator';\r\n\r\nexport type Constructor = new (...args: any[]) => T;\r\n// eslint-disable-next-line @typescript-eslint/ban-types\r\nexport type AbstractConstructor = Function & { prototype: T };\r\n\r\nexport interface IKb3dModel extends TrackChangesOptions {\r\n token: Token;\r\n classConstructor: Constructor | AbstractConstructor;\r\n /**\r\n * the function to create the class used by the manager.\r\n * If provided, you will be passed an anonymous object in the shape\r\n * of the class that can be used to create the instance.\r\n * If not provided, the constructor of the class will be called by\r\n * the manager with no arguments.\r\n */\r\n create?: (args: Partial) => T;\r\n afterCreate?: (instance: T) => void;\r\n /**\r\n * Hook that happens while serializing this model to JSON.\r\n * You are passed the instance and the default serialization of the model,\r\n * which you can modify.\r\n * Return true to include the instance in the serialization, or false to omit it\r\n */\r\n onSerializing?: (instance: T, serializedObject: Partial) => boolean;\r\n\r\n /** if trackChanges is true, the model will be wrapped in the TrackChanges decorator */\r\n trackChanges: boolean;\r\n\r\n validate?: (node: ITrackedClass, v: Validator) => void;\r\n}\r\n\r\nexport const Kb3dModels = new Map>();\r\n\r\n/**\r\n * Curry function to filter items in an array to items of a token type\r\n * @param classKey String key of the class you want to see if the instance is an instance of\r\n */\r\nexport function ofToken(token: Token) {\r\n return (instance: any): instance is T => instanceOf(instance, token);\r\n}\r\n\r\n/**\r\n * Checks if the instance of a class given is an instance of the class represented by it's\r\n * injectable class key. If the instance is an instance of a class that was not\r\n * decorated, or if the class represented by the key was not decorated, then this will\r\n * return false!\r\n * @param instance An instance of a class that was decorated\r\n * @param classKey String key of the class you want to see if the instance is an instance of\r\n */\r\nexport function instanceOf(instance: any, token: Token): instance is T {\r\n if (!instance) return false;\r\n\r\n const model = Kb3dModels.get(token);\r\n return model ? instance instanceof model.classConstructor : false;\r\n}\r\n\r\n/** Curry-able version of instanceOf */\r\nexport function isInstanceOf(token: Token) {\r\n return (instance: any): instance is T => instanceOf(instance, token);\r\n}\r\n\r\nexport function getToken(object: T): Token | undefined {\r\n const node = object as unknown as IDecoratedModel;\r\n if (node.$type) {\r\n return Token.tryWithKey(node.$type);\r\n }\r\n}\r\n\r\n/**\r\n * Checks if the instance of a class given is an instance of the class represented by it's\r\n * injectable class key. If the instance is an instance of a class that was not\r\n * decorated, or if the class represented by the key was not decorated, then this will\r\n * return false!\r\n * @param instance An instance of a class that was decorated\r\n * @param classKey String key of the class you want to see if the instance is an instance of\r\n */\r\nexport function instanceOfAny(instance: any, ...tokens: Token[]): instance is T {\r\n if (!instance) return false;\r\n\r\n return tokens.some(t => instanceOf(instance, t));\r\n}\r\n","import { Kb3dModels } from '@models/classes/decorators/model-utils';\r\nimport { Token } from '@models/classes/token';\r\n\r\nexport type ITrackedClass = T & {\r\n isModified: boolean;\r\n /** properties that have been changed since the last render processing */\r\n changes: Map, any>;\r\n /** the values of properties before they were changed */\r\n originalValues: Map;\r\n destroy: () => void;\r\n removedFromChildArray: (parent: ITrackedClass, item: any, arrayPropertyName: string) => void;\r\n addedToChildArray: (parent: ITrackedClass, item: any, arrayPropertyName: string) => void;\r\n commitChanges: () => void;\r\n setPropertyIsModified: (prop: string | symbol, modified: boolean) => void;\r\n trackChanges: (active: boolean) => void;\r\n nodeReferences:\r\n | Map<\r\n string | symbol,\r\n {\r\n classRef: new (...args: any[]) => any;\r\n limitKeys: Set | undefined;\r\n }\r\n >\r\n | undefined;\r\n rawNode: T;\r\n};\r\n\r\nexport type ITrackedArray = T[] & {\r\n pop: (destroy: boolean) => T | undefined;\r\n};\r\n\r\nexport enum EChangeOperation {\r\n // CreateAndPush and Remove correspond to functions in the custom KBArray class.\r\n // They use Push and Splice internally but also signify we need a\r\n // changeTracker destroy on undo and redo respectively and create on redo and undo respectively.\r\n Push,\r\n Pop,\r\n Shift,\r\n Unshift,\r\n Splice,\r\n CreateAndPush,\r\n Remove,\r\n}\r\n\r\nexport interface IHistoryStateChange {\r\n node: G & ITrackedClass;\r\n properties: Array>;\r\n}\r\nexport interface IHistoryStateChangeProperty {\r\n name: keyof G;\r\n operation?: EChangeOperation;\r\n previousValue: T;\r\n newValue: T;\r\n}\r\n\r\nexport function isTrackedClass(object: T): object is ITrackedClass {\r\n return object && typeof object === 'object' && '$changesTracked' in object;\r\n}\r\n\r\nexport function isTrackedArray(object: T[]): object is ITrackedArray {\r\n return !!(object as any).$isTracked;\r\n}\r\n\r\nexport function isTrackedInstance(instance: T, token: Token): instance is ITrackedClass {\r\n if (!instance) return false;\r\n\r\n const model = Kb3dModels.get(token);\r\n return model ? instance instanceof model.classConstructor && isTrackedClass(instance) : false;\r\n}\r\n\r\nexport function isTrackedInstanceOfAny(instance: T, ...tokens: Token[]): instance is T {\r\n if (!instance) return false;\r\n\r\n return tokens.some(t => isTrackedInstance(instance, t));\r\n}\r\n","import { ITrackedClass } from '@models/interfaces/tracked-class';\r\n\r\nconst changedItems = new Set();\r\nconst deletedItems = new Set();\r\n\r\n/** This class syncs changes to the renderer to update the scene view */\r\nexport class SyncService {\r\n static registerChangedState(tracker: ITrackedClass, modified: boolean) {\r\n if (modified) {\r\n // If node was deleted, ignore further changes, unless the item was moved to a different parent\r\n if (!deletedItems.has(tracker) || tracker.changes.has('_parent')) {\r\n changedItems.add(tracker);\r\n }\r\n } else {\r\n changedItems.delete(tracker);\r\n }\r\n }\r\n // When a new object is being created, the proxy being used to set the values will be the proxy of the parent of the class being created.\r\n // So, we need to make sure the changed items map is always pointing to the correct proxy (the proxy with the highest specificity)\r\n static registerNewObject(tracker: ITrackedClass) {\r\n changedItems.add(tracker);\r\n }\r\n static registerDeleted(tracker: ITrackedClass) {\r\n deletedItems.add(tracker);\r\n }\r\n\r\n static get hasChanges() {\r\n return changedItems.size > 0 || deletedItems.size > 0;\r\n }\r\n static getChangedNodes() {\r\n return [...changedItems.values()];\r\n }\r\n static getDeletedNodes() {\r\n return [...deletedItems.values()];\r\n }\r\n\r\n static nodeDeletionProcessed(tracker: ITrackedClass) {\r\n //when a node is deleted, we remove it from all the maps\r\n changedItems.delete(tracker);\r\n deletedItems.delete(tracker);\r\n }\r\n\r\n static nodeChangesProcessed(tracker: ITrackedClass) {\r\n //when node changes have been processed, we only remove it from the changedItems map\r\n changedItems.delete(tracker);\r\n }\r\n}\r\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __createBinding(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","export function isFunction(x: any): x is Function {\n return typeof x === 'function';\n}\n","let _enable_super_gross_mode_that_will_cause_bad_things = false;\n\n/**\n * The global configuration object for RxJS, used to configure things\n * like what Promise contructor should used to create Promises\n */\nexport const config = {\n /**\n * The promise constructor used by default for methods such as\n * {@link toPromise} and {@link forEach}\n */\n Promise: undefined as PromiseConstructorLike,\n\n /**\n * If true, turns on synchronous error rethrowing, which is a deprecated behavior\n * in v6 and higher. This behavior enables bad patterns like wrapping a subscribe\n * call in a try/catch block. It also enables producer interference, a nasty bug\n * where a multicast can be broken for all observers by a downstream consumer with\n * an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BY TIME\n * FOR MIGRATION REASONS.\n */\n set useDeprecatedSynchronousErrorHandling(value: boolean) {\n if (value) {\n const error = new Error();\n console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \\n' + error.stack);\n } else if (_enable_super_gross_mode_that_will_cause_bad_things) {\n console.log('RxJS: Back to a better error behavior. Thank you. <3');\n }\n _enable_super_gross_mode_that_will_cause_bad_things = value;\n },\n\n get useDeprecatedSynchronousErrorHandling() {\n return _enable_super_gross_mode_that_will_cause_bad_things;\n },\n};\n","/**\n * Throws an error on another job so that it's picked up by the runtime's\n * uncaught error handling mechanism.\n * @param err the error to throw\n */\nexport function hostReportError(err: any) {\n setTimeout(() => { throw err; }, 0);\n}","import { Observer } from './types';\nimport { config } from './config';\nimport { hostReportError } from './util/hostReportError';\n\nexport const empty: Observer = {\n closed: true,\n next(value: any): void { /* noop */},\n error(err: any): void {\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n } else {\n hostReportError(err);\n }\n },\n complete(): void { /*noop*/ }\n};\n","export function isObject(x: any): x is Object {\n return x !== null && typeof x === 'object';\n}\n","export interface UnsubscriptionError extends Error {\n readonly errors: any[];\n}\n\nexport interface UnsubscriptionErrorCtor {\n new(errors: any[]): UnsubscriptionError;\n}\n\nconst UnsubscriptionErrorImpl = (() => {\n function UnsubscriptionErrorImpl(this: any, errors: any[]) {\n Error.call(this);\n this.message = errors ?\n `${errors.length} errors occurred during unsubscription:\n${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\\n ')}` : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n return this;\n }\n\n UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype);\n\n return UnsubscriptionErrorImpl;\n})();\n\n/**\n * An error thrown when one or more errors have occurred during the\n * `unsubscribe` of a {@link Subscription}.\n */\nexport const UnsubscriptionError: UnsubscriptionErrorCtor = UnsubscriptionErrorImpl as any;","import { isArray } from './util/isArray';\nimport { isObject } from './util/isObject';\nimport { isFunction } from './util/isFunction';\nimport { UnsubscriptionError } from './util/UnsubscriptionError';\nimport { SubscriptionLike, TeardownLogic } from './types';\n\n/**\n * Represents a disposable resource, such as the execution of an Observable. A\n * Subscription has one important method, `unsubscribe`, that takes no argument\n * and just disposes the resource held by the subscription.\n *\n * Additionally, subscriptions may be grouped together through the `add()`\n * method, which will attach a child Subscription to the current Subscription.\n * When a Subscription is unsubscribed, all its children (and its grandchildren)\n * will be unsubscribed as well.\n *\n * @class Subscription\n */\nexport class Subscription implements SubscriptionLike {\n /** @nocollapse */\n public static EMPTY: Subscription = (function(empty: any) {\n empty.closed = true;\n return empty;\n }(new Subscription()));\n\n /**\n * A flag to indicate whether this Subscription has already been unsubscribed.\n * @type {boolean}\n */\n public closed: boolean = false;\n\n /** @internal */\n protected _parentOrParents: Subscription | Subscription[] = null;\n /** @internal */\n private _subscriptions: SubscriptionLike[] = null;\n\n /**\n * @param {function(): void} [unsubscribe] A function describing how to\n * perform the disposal of resources when the `unsubscribe` method is called.\n */\n constructor(unsubscribe?: () => void) {\n if (unsubscribe) {\n (this as any)._ctorUnsubscribe = true;\n (this as any)._unsubscribe = unsubscribe;\n }\n }\n\n /**\n * Disposes the resources held by the subscription. May, for instance, cancel\n * an ongoing Observable execution or cancel any other type of work that\n * started when the Subscription was created.\n * @return {void}\n */\n unsubscribe(): void {\n let errors: any[];\n\n if (this.closed) {\n return;\n }\n\n let { _parentOrParents, _ctorUnsubscribe, _unsubscribe, _subscriptions } = (this as any);\n\n this.closed = true;\n this._parentOrParents = null;\n // null out _subscriptions first so any child subscriptions that attempt\n // to remove themselves from this subscription will noop\n this._subscriptions = null;\n\n if (_parentOrParents instanceof Subscription) {\n _parentOrParents.remove(this);\n } else if (_parentOrParents !== null) {\n for (let index = 0; index < _parentOrParents.length; ++index) {\n const parent = _parentOrParents[index];\n parent.remove(this);\n }\n }\n\n if (isFunction(_unsubscribe)) {\n // It's only possible to null _unsubscribe - to release the reference to\n // any teardown function passed in the constructor - if the property was\n // actually assigned in the constructor, as there are some classes that\n // are derived from Subscriber (which derives from Subscription) that\n // implement an _unsubscribe method as a mechanism for obtaining\n // unsubscription notifications and some of those subscribers are\n // recycled. Also, in some of those subscribers, _unsubscribe switches\n // from a prototype method to an instance property - see notifyNext in\n // RetryWhenSubscriber.\n if (_ctorUnsubscribe) {\n (this as any)._unsubscribe = undefined;\n }\n try {\n _unsubscribe.call(this);\n } catch (e) {\n errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];\n }\n }\n\n if (isArray(_subscriptions)) {\n let index = -1;\n let len = _subscriptions.length;\n\n while (++index < len) {\n const sub = _subscriptions[index];\n if (isObject(sub)) {\n try {\n sub.unsubscribe();\n } catch (e) {\n errors = errors || [];\n if (e instanceof UnsubscriptionError) {\n errors = errors.concat(flattenUnsubscriptionErrors(e.errors));\n } else {\n errors.push(e);\n }\n }\n }\n }\n }\n\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n }\n\n /**\n * Adds a tear down to be called during the unsubscribe() of this\n * Subscription. Can also be used to add a child subscription.\n *\n * If the tear down being added is a subscription that is already\n * unsubscribed, is the same reference `add` is being called on, or is\n * `Subscription.EMPTY`, it will not be added.\n *\n * If this subscription is already in an `closed` state, the passed\n * tear down logic will be executed immediately.\n *\n * When a parent subscription is unsubscribed, any child subscriptions that were added to it are also unsubscribed.\n *\n * @param {TeardownLogic} teardown The additional logic to execute on\n * teardown.\n * @return {Subscription} Returns the Subscription used or created to be\n * added to the inner subscriptions list. This Subscription can be used with\n * `remove()` to remove the passed teardown logic from the inner subscriptions\n * list.\n */\n add(teardown: TeardownLogic): Subscription {\n let subscription = (teardown);\n\n if (!teardown) {\n return Subscription.EMPTY;\n }\n\n switch (typeof teardown) {\n case 'function':\n subscription = new Subscription(<(() => void)>teardown);\n case 'object':\n if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {\n // This also covers the case where `subscription` is `Subscription.EMPTY`, which is always in `closed` state.\n return subscription;\n } else if (this.closed) {\n subscription.unsubscribe();\n return subscription;\n } else if (!(subscription instanceof Subscription)) {\n const tmp = subscription;\n subscription = new Subscription();\n subscription._subscriptions = [tmp];\n }\n break;\n default: {\n throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');\n }\n }\n\n // Add `this` as parent of `subscription` if that's not already the case.\n let { _parentOrParents } = subscription;\n if (_parentOrParents === null) {\n // If we don't have a parent, then set `subscription._parents` to\n // the `this`, which is the common case that we optimize for.\n subscription._parentOrParents = this;\n } else if (_parentOrParents instanceof Subscription) {\n if (_parentOrParents === this) {\n // The `subscription` already has `this` as a parent.\n return subscription;\n }\n // If there's already one parent, but not multiple, allocate an\n // Array to store the rest of the parent Subscriptions.\n subscription._parentOrParents = [_parentOrParents, this];\n } else if (_parentOrParents.indexOf(this) === -1) {\n // Only add `this` to the _parentOrParents list if it's not already there.\n _parentOrParents.push(this);\n } else {\n // The `subscription` already has `this` as a parent.\n return subscription;\n }\n\n // Optimize for the common case when adding the first subscription.\n const subscriptions = this._subscriptions;\n if (subscriptions === null) {\n this._subscriptions = [subscription];\n } else {\n subscriptions.push(subscription);\n }\n\n return subscription;\n }\n\n /**\n * Removes a Subscription from the internal list of subscriptions that will\n * unsubscribe during the unsubscribe process of this Subscription.\n * @param {Subscription} subscription The subscription to remove.\n * @return {void}\n */\n remove(subscription: Subscription): void {\n const subscriptions = this._subscriptions;\n if (subscriptions) {\n const subscriptionIndex = subscriptions.indexOf(subscription);\n if (subscriptionIndex !== -1) {\n subscriptions.splice(subscriptionIndex, 1);\n }\n }\n }\n}\n\nfunction flattenUnsubscriptionErrors(errors: any[]) {\n return errors.reduce((errs, err) => errs.concat((err instanceof UnsubscriptionError) ? err.errors : err), []);\n}\n","/** @deprecated do not use, this is no longer checked by RxJS internals */\nexport const rxSubscriber = (() =>\n typeof Symbol === 'function'\n ? Symbol('rxSubscriber')\n : '@@rxSubscriber_' + Math.random())();\n\n/**\n * @deprecated use rxSubscriber instead\n */\nexport const $$rxSubscriber = rxSubscriber;\n","import { isFunction } from './util/isFunction';\nimport { empty as emptyObserver } from './Observer';\nimport { Observer, PartialObserver, TeardownLogic } from './types';\nimport { Subscription } from './Subscription';\nimport { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';\nimport { config } from './config';\nimport { hostReportError } from './util/hostReportError';\n\n/**\n * Implements the {@link Observer} interface and extends the\n * {@link Subscription} class. While the {@link Observer} is the public API for\n * consuming the values of an {@link Observable}, all Observers get converted to\n * a Subscriber, in order to provide Subscription-like capabilities such as\n * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for\n * implementing operators, but it is rarely used as a public API.\n *\n * @class Subscriber\n */\nexport class Subscriber extends Subscription implements Observer {\n\n [rxSubscriberSymbol]() { return this; }\n\n /**\n * A static factory for a Subscriber, given a (potentially partial) definition\n * of an Observer.\n * @param {function(x: ?T): void} [next] The `next` callback of an Observer.\n * @param {function(e: ?any): void} [error] The `error` callback of an\n * Observer.\n * @param {function(): void} [complete] The `complete` callback of an\n * Observer.\n * @return {Subscriber} A Subscriber wrapping the (partially defined)\n * Observer represented by the given arguments.\n * @nocollapse\n */\n static create(next?: (x?: T) => void,\n error?: (e?: any) => void,\n complete?: () => void): Subscriber {\n const subscriber = new Subscriber(next, error, complete);\n subscriber.syncErrorThrowable = false;\n return subscriber;\n }\n\n /** @internal */ syncErrorValue: any = null;\n /** @internal */ syncErrorThrown: boolean = false;\n /** @internal */ syncErrorThrowable: boolean = false;\n\n protected isStopped: boolean = false;\n protected destination: PartialObserver | Subscriber; // this `any` is the escape hatch to erase extra type param (e.g. R)\n\n /**\n * @param {Observer|function(value: T): void} [destinationOrNext] A partially\n * defined Observer or a `next` callback function.\n * @param {function(e: ?any): void} [error] The `error` callback of an\n * Observer.\n * @param {function(): void} [complete] The `complete` callback of an\n * Observer.\n */\n constructor(destinationOrNext?: PartialObserver | ((value: T) => void),\n error?: (e?: any) => void,\n complete?: () => void) {\n super();\n\n switch (arguments.length) {\n case 0:\n this.destination = emptyObserver;\n break;\n case 1:\n if (!destinationOrNext) {\n this.destination = emptyObserver;\n break;\n }\n if (typeof destinationOrNext === 'object') {\n if (destinationOrNext instanceof Subscriber) {\n this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;\n this.destination = destinationOrNext;\n destinationOrNext.add(this);\n } else {\n this.syncErrorThrowable = true;\n this.destination = new SafeSubscriber(this, > destinationOrNext);\n }\n break;\n }\n default:\n this.syncErrorThrowable = true;\n this.destination = new SafeSubscriber(this, <((value: T) => void)> destinationOrNext, error, complete);\n break;\n }\n }\n\n /**\n * The {@link Observer} callback to receive notifications of type `next` from\n * the Observable, with a value. The Observable may call this method 0 or more\n * times.\n * @param {T} [value] The `next` value.\n * @return {void}\n */\n next(value?: T): void {\n if (!this.isStopped) {\n this._next(value);\n }\n }\n\n /**\n * The {@link Observer} callback to receive notifications of type `error` from\n * the Observable, with an attached `Error`. Notifies the Observer that\n * the Observable has experienced an error condition.\n * @param {any} [err] The `error` exception.\n * @return {void}\n */\n error(err?: any): void {\n if (!this.isStopped) {\n this.isStopped = true;\n this._error(err);\n }\n }\n\n /**\n * The {@link Observer} callback to receive a valueless notification of type\n * `complete` from the Observable. Notifies the Observer that the Observable\n * has finished sending push-based notifications.\n * @return {void}\n */\n complete(): void {\n if (!this.isStopped) {\n this.isStopped = true;\n this._complete();\n }\n }\n\n unsubscribe(): void {\n if (this.closed) {\n return;\n }\n this.isStopped = true;\n super.unsubscribe();\n }\n\n protected _next(value: T): void {\n this.destination.next(value);\n }\n\n protected _error(err: any): void {\n this.destination.error(err);\n this.unsubscribe();\n }\n\n protected _complete(): void {\n this.destination.complete();\n this.unsubscribe();\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _unsubscribeAndRecycle(): Subscriber {\n const { _parentOrParents } = this;\n this._parentOrParents = null;\n this.unsubscribe();\n this.closed = false;\n this.isStopped = false;\n this._parentOrParents = _parentOrParents;\n return this;\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class SafeSubscriber extends Subscriber {\n\n private _context: any;\n\n constructor(private _parentSubscriber: Subscriber,\n observerOrNext?: PartialObserver | ((value: T) => void),\n error?: (e?: any) => void,\n complete?: () => void) {\n super();\n\n let next: ((value: T) => void);\n let context: any = this;\n\n if (isFunction(observerOrNext)) {\n next = (<((value: T) => void)> observerOrNext);\n } else if (observerOrNext) {\n next = (> observerOrNext).next;\n error = (> observerOrNext).error;\n complete = (> observerOrNext).complete;\n if (observerOrNext !== emptyObserver) {\n context = Object.create(observerOrNext);\n if (isFunction(context.unsubscribe)) {\n this.add(<() => void> context.unsubscribe.bind(context));\n }\n context.unsubscribe = this.unsubscribe.bind(this);\n }\n }\n\n this._context = context;\n this._next = next;\n this._error = error;\n this._complete = complete;\n }\n\n next(value?: T): void {\n if (!this.isStopped && this._next) {\n const { _parentSubscriber } = this;\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._next, value);\n } else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {\n this.unsubscribe();\n }\n }\n }\n\n error(err?: any): void {\n if (!this.isStopped) {\n const { _parentSubscriber } = this;\n const { useDeprecatedSynchronousErrorHandling } = config;\n if (this._error) {\n if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(this._error, err);\n this.unsubscribe();\n } else {\n this.__tryOrSetError(_parentSubscriber, this._error, err);\n this.unsubscribe();\n }\n } else if (!_parentSubscriber.syncErrorThrowable) {\n this.unsubscribe();\n if (useDeprecatedSynchronousErrorHandling) {\n throw err;\n }\n hostReportError(err);\n } else {\n if (useDeprecatedSynchronousErrorHandling) {\n _parentSubscriber.syncErrorValue = err;\n _parentSubscriber.syncErrorThrown = true;\n } else {\n hostReportError(err);\n }\n this.unsubscribe();\n }\n }\n }\n\n complete(): void {\n if (!this.isStopped) {\n const { _parentSubscriber } = this;\n if (this._complete) {\n const wrappedComplete = () => this._complete.call(this._context);\n\n if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {\n this.__tryOrUnsub(wrappedComplete);\n this.unsubscribe();\n } else {\n this.__tryOrSetError(_parentSubscriber, wrappedComplete);\n this.unsubscribe();\n }\n } else {\n this.unsubscribe();\n }\n }\n }\n\n private __tryOrUnsub(fn: Function, value?: any): void {\n try {\n fn.call(this._context, value);\n } catch (err) {\n this.unsubscribe();\n if (config.useDeprecatedSynchronousErrorHandling) {\n throw err;\n } else {\n hostReportError(err);\n }\n }\n }\n\n private __tryOrSetError(parent: Subscriber, fn: Function, value?: any): boolean {\n if (!config.useDeprecatedSynchronousErrorHandling) {\n throw new Error('bad call');\n }\n try {\n fn.call(this._context, value);\n } catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n parent.syncErrorValue = err;\n parent.syncErrorThrown = true;\n return true;\n } else {\n hostReportError(err);\n return true;\n }\n }\n return false;\n }\n\n /** @internal This is an internal implementation detail, do not use. */\n _unsubscribe(): void {\n const { _parentSubscriber } = this;\n this._context = null;\n this._parentSubscriber = null;\n _parentSubscriber.unsubscribe();\n }\n}\n","export function identity(x: T): T {\n return x;\n}\n","import { noop } from './noop';\nimport { identity } from './identity';\nimport { UnaryFunction } from '../types';\n\n/* tslint:disable:max-line-length */\nexport function pipe(): UnaryFunction;\nexport function pipe(fn1: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction, fn5: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction, fn5: UnaryFunction, fn6: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction, fn5: UnaryFunction, fn6: UnaryFunction, fn7: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction, fn5: UnaryFunction, fn6: UnaryFunction, fn7: UnaryFunction, fn8: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction, fn5: UnaryFunction, fn6: UnaryFunction, fn7: UnaryFunction, fn8: UnaryFunction, fn9: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction, fn4: UnaryFunction, fn5: UnaryFunction, fn6: UnaryFunction, fn7: UnaryFunction, fn8: UnaryFunction, fn9: UnaryFunction, ...fns: UnaryFunction[]): UnaryFunction;\n/* tslint:enable:max-line-length */\n\nexport function pipe(...fns: Array>): UnaryFunction {\n return pipeFromArray(fns);\n}\n\n/** @internal */\nexport function pipeFromArray(fns: Array>): UnaryFunction {\n if (fns.length === 0) {\n return identity as UnaryFunction;\n }\n\n if (fns.length === 1) {\n return fns[0];\n }\n\n return function piped(input: T): R {\n return fns.reduce((prev: any, fn: UnaryFunction) => fn(prev), input as any);\n };\n}\n","import { Operator } from './Operator';\nimport { Subscriber } from './Subscriber';\nimport { Subscription } from './Subscription';\nimport { TeardownLogic, OperatorFunction, PartialObserver, Subscribable } from './types';\nimport { canReportError } from './util/canReportError';\nimport { toSubscriber } from './util/toSubscriber';\nimport { iif } from './observable/iif';\nimport { throwError } from './observable/throwError';\nimport { observable as Symbol_observable } from './symbol/observable';\nimport { pipeFromArray } from './util/pipe';\nimport { config } from './config';\n\n/**\n * A representation of any set of values over any amount of time. This is the most basic building block\n * of RxJS.\n *\n * @class Observable\n */\nexport class Observable implements Subscribable {\n\n /** Internal implementation detail, do not use directly. */\n public _isScalar: boolean = false;\n\n /** @deprecated This is an internal implementation detail, do not use. */\n source: Observable;\n\n /** @deprecated This is an internal implementation detail, do not use. */\n operator: Operator;\n\n /**\n * @constructor\n * @param {Function} subscribe the function that is called when the Observable is\n * initially subscribed to. This function is given a Subscriber, to which new values\n * can be `next`ed, or an `error` method can be called to raise an error, or\n * `complete` can be called to notify of a successful completion.\n */\n constructor(subscribe?: (this: Observable, subscriber: Subscriber) => TeardownLogic) {\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n\n // HACK: Since TypeScript inherits static properties too, we have to\n // fight against TypeScript here so Subject can have a different static create signature\n /**\n * Creates a new cold Observable by calling the Observable constructor\n * @static true\n * @owner Observable\n * @method create\n * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor\n * @return {Observable} a new cold observable\n * @nocollapse\n * @deprecated use new Observable() instead\n */\n static create: Function = (subscribe?: (subscriber: Subscriber) => TeardownLogic) => {\n return new Observable(subscribe);\n }\n\n /**\n * Creates a new Observable, with this Observable as the source, and the passed\n * operator defined as the new observable's operator.\n * @method lift\n * @param {Operator} operator the operator defining the operation to take on the observable\n * @return {Observable} a new observable with the Operator applied\n */\n lift(operator: Operator): Observable {\n const observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n }\n\n subscribe(observer?: PartialObserver): Subscription;\n /** @deprecated Use an observer instead of a complete callback */\n subscribe(next: null | undefined, error: null | undefined, complete: () => void): Subscription;\n /** @deprecated Use an observer instead of an error callback */\n subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Subscription;\n /** @deprecated Use an observer instead of a complete callback */\n subscribe(next: (value: T) => void, error: null | undefined, complete: () => void): Subscription;\n subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;\n /**\n * Invokes an execution of an Observable and registers Observer handlers for notifications it will emit.\n *\n * Use it when you have all these Observables, but still nothing is happening.\n *\n * `subscribe` is not a regular operator, but a method that calls Observable's internal `subscribe` function. It\n * might be for example a function that you passed to Observable's constructor, but most of the time it is\n * a library implementation, which defines what will be emitted by an Observable, and when it be will emitted. This means\n * that calling `subscribe` is actually the moment when Observable starts its work, not when it is created, as it is often\n * the thought.\n *\n * Apart from starting the execution of an Observable, this method allows you to listen for values\n * that an Observable emits, as well as for when it completes or errors. You can achieve this in two\n * of the following ways.\n *\n * The first way is creating an object that implements {@link Observer} interface. It should have methods\n * defined by that interface, but note that it should be just a regular JavaScript object, which you can create\n * yourself in any way you want (ES6 class, classic function constructor, object literal etc.). In particular do\n * not attempt to use any RxJS implementation details to create Observers - you don't need them. Remember also\n * that your object does not have to implement all methods. If you find yourself creating a method that doesn't\n * do anything, you can simply omit it. Note however, if the `error` method is not provided, all errors will\n * be left uncaught.\n *\n * The second way is to give up on Observer object altogether and simply provide callback functions in place of its methods.\n * This means you can provide three functions as arguments to `subscribe`, where the first function is equivalent\n * of a `next` method, the second of an `error` method and the third of a `complete` method. Just as in case of Observer,\n * if you do not need to listen for something, you can omit a function, preferably by passing `undefined` or `null`,\n * since `subscribe` recognizes these functions by where they were placed in function call. When it comes\n * to `error` function, just as before, if not provided, errors emitted by an Observable will be thrown.\n *\n * Whichever style of calling `subscribe` you use, in both cases it returns a Subscription object.\n * This object allows you to call `unsubscribe` on it, which in turn will stop the work that an Observable does and will clean\n * up all resources that an Observable used. Note that cancelling a subscription will not call `complete` callback\n * provided to `subscribe` function, which is reserved for a regular completion signal that comes from an Observable.\n *\n * Remember that callbacks provided to `subscribe` are not guaranteed to be called asynchronously.\n * It is an Observable itself that decides when these functions will be called. For example {@link of}\n * by default emits all its values synchronously. Always check documentation for how given Observable\n * will behave when subscribed and if its default behavior can be modified with a `scheduler`.\n *\n * ## Example\n * ### Subscribe with an Observer\n * ```ts\n * import { of } from 'rxjs';\n *\n * const sumObserver = {\n * sum: 0,\n * next(value) {\n * console.log('Adding: ' + value);\n * this.sum = this.sum + value;\n * },\n * error() {\n * // We actually could just remove this method,\n * // since we do not really care about errors right now.\n * },\n * complete() {\n * console.log('Sum equals: ' + this.sum);\n * }\n * };\n *\n * of(1, 2, 3) // Synchronously emits 1, 2, 3 and then completes.\n * .subscribe(sumObserver);\n *\n * // Logs:\n * // \"Adding: 1\"\n * // \"Adding: 2\"\n * // \"Adding: 3\"\n * // \"Sum equals: 6\"\n * ```\n *\n * ### Subscribe with functions\n * ```ts\n * import { of } from 'rxjs'\n *\n * let sum = 0;\n *\n * of(1, 2, 3).subscribe(\n * value => {\n * console.log('Adding: ' + value);\n * sum = sum + value;\n * },\n * undefined,\n * () => console.log('Sum equals: ' + sum)\n * );\n *\n * // Logs:\n * // \"Adding: 1\"\n * // \"Adding: 2\"\n * // \"Adding: 3\"\n * // \"Sum equals: 6\"\n * ```\n *\n * ### Cancel a subscription\n * ```ts\n * import { interval } from 'rxjs';\n *\n * const subscription = interval(1000).subscribe(\n * num => console.log(num),\n * undefined,\n * () => {\n * // Will not be called, even when cancelling subscription.\n * console.log('completed!');\n * }\n * );\n *\n * setTimeout(() => {\n * subscription.unsubscribe();\n * console.log('unsubscribed!');\n * }, 2500);\n *\n * // Logs:\n * // 0 after 1s\n * // 1 after 2s\n * // \"unsubscribed!\" after 2.5s\n * ```\n *\n * @param {Observer|Function} observerOrNext (optional) Either an observer with methods to be called,\n * or the first of three possible handlers, which is the handler for each value emitted from the subscribed\n * Observable.\n * @param {Function} error (optional) A handler for a terminal event resulting from an error. If no error handler is provided,\n * the error will be thrown as unhandled.\n * @param {Function} complete (optional) A handler for a terminal event resulting from successful completion.\n * @return {ISubscription} a subscription reference to the registered handlers\n * @method subscribe\n */\n subscribe(observerOrNext?: PartialObserver | ((value: T) => void),\n error?: (error: any) => void,\n complete?: () => void): Subscription {\n\n const { operator } = this;\n const sink = toSubscriber(observerOrNext, error, complete);\n\n if (operator) {\n sink.add(operator.call(sink, this.source));\n } else {\n sink.add(\n this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?\n this._subscribe(sink) :\n this._trySubscribe(sink)\n );\n }\n\n if (config.useDeprecatedSynchronousErrorHandling) {\n if (sink.syncErrorThrowable) {\n sink.syncErrorThrowable = false;\n if (sink.syncErrorThrown) {\n throw sink.syncErrorValue;\n }\n }\n }\n\n return sink;\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _trySubscribe(sink: Subscriber): TeardownLogic {\n try {\n return this._subscribe(sink);\n } catch (err) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n sink.syncErrorThrown = true;\n sink.syncErrorValue = err;\n }\n if (canReportError(sink)) {\n sink.error(err);\n } else {\n console.warn(err);\n }\n }\n }\n\n /**\n * @method forEach\n * @param {Function} next a handler for each value emitted by the observable\n * @param {PromiseConstructor} [promiseCtor] a constructor function used to instantiate the Promise\n * @return {Promise} a promise that either resolves on observable completion or\n * rejects with the handled error\n */\n forEach(next: (value: T) => void, promiseCtor?: PromiseConstructorLike): Promise {\n promiseCtor = getPromiseCtor(promiseCtor);\n\n return new promiseCtor((resolve, reject) => {\n // Must be declared in a separate statement to avoid a ReferenceError when\n // accessing subscription below in the closure due to Temporal Dead Zone.\n let subscription: Subscription;\n subscription = this.subscribe((value) => {\n try {\n next(value);\n } catch (err) {\n reject(err);\n if (subscription) {\n subscription.unsubscribe();\n }\n }\n }, reject, resolve);\n }) as Promise;\n }\n\n /** @internal This is an internal implementation detail, do not use. */\n _subscribe(subscriber: Subscriber): TeardownLogic {\n const { source } = this;\n return source && source.subscribe(subscriber);\n }\n\n // `if` and `throw` are special snow flakes, the compiler sees them as reserved words. Deprecated in\n // favor of iif and throwError functions.\n /**\n * @nocollapse\n * @deprecated In favor of iif creation function: import { iif } from 'rxjs';\n */\n static if: typeof iif;\n /**\n * @nocollapse\n * @deprecated In favor of throwError creation function: import { throwError } from 'rxjs';\n */\n static throw: typeof throwError;\n\n /**\n * An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable\n * @method Symbol.observable\n * @return {Observable} this instance of the observable\n */\n [Symbol_observable]() {\n return this;\n }\n\n /* tslint:disable:max-line-length */\n pipe(): Observable;\n pipe(op1: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction, op9: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction, op9: OperatorFunction, ...operations: OperatorFunction[]): Observable<{}>;\n /* tslint:enable:max-line-length */\n\n /**\n * Used to stitch together functional operators into a chain.\n * @method pipe\n * @return {Observable} the Observable result of all of the operators having\n * been called in the order they were passed in.\n *\n * ### Example\n * ```ts\n * import { interval } from 'rxjs';\n * import { map, filter, scan } from 'rxjs/operators';\n *\n * interval(1000)\n * .pipe(\n * filter(x => x % 2 === 0),\n * map(x => x + x),\n * scan((acc, x) => acc + x)\n * )\n * .subscribe(x => console.log(x))\n * ```\n */\n pipe(...operations: OperatorFunction[]): Observable {\n if (operations.length === 0) {\n return this as any;\n }\n\n return pipeFromArray(operations)(this);\n }\n\n /* tslint:disable:max-line-length */\n toPromise(this: Observable): Promise;\n toPromise(this: Observable, PromiseCtor: typeof Promise): Promise;\n toPromise(this: Observable, PromiseCtor: PromiseConstructorLike): Promise;\n /* tslint:enable:max-line-length */\n\n toPromise(promiseCtor?: PromiseConstructorLike): Promise {\n promiseCtor = getPromiseCtor(promiseCtor);\n\n return new promiseCtor((resolve, reject) => {\n let value: any;\n this.subscribe((x: T) => value = x, (err: any) => reject(err), () => resolve(value));\n }) as Promise;\n }\n}\n\n/**\n * Decides between a passed promise constructor from consuming code,\n * A default configured promise constructor, and the native promise\n * constructor and returns it. If nothing can be found, it will throw\n * an error.\n * @param promiseCtor The optional promise constructor to passed by consuming code\n */\nfunction getPromiseCtor(promiseCtor: PromiseConstructorLike | undefined) {\n if (!promiseCtor) {\n promiseCtor = config.Promise || Promise;\n }\n\n if (!promiseCtor) {\n throw new Error('no Promise impl found');\n }\n\n return promiseCtor;\n}\n","import { Subscriber } from '../Subscriber';\nimport { rxSubscriber as rxSubscriberSymbol } from '../symbol/rxSubscriber';\nimport { empty as emptyObserver } from '../Observer';\nimport { PartialObserver } from '../types';\n\nexport function toSubscriber(\n nextOrObserver?: PartialObserver | ((value: T) => void),\n error?: (error: any) => void,\n complete?: () => void): Subscriber {\n\n if (nextOrObserver) {\n if (nextOrObserver instanceof Subscriber) {\n return (> nextOrObserver);\n }\n\n if (nextOrObserver[rxSubscriberSymbol]) {\n return nextOrObserver[rxSubscriberSymbol]();\n }\n }\n\n if (!nextOrObserver && !error && !complete) {\n return new Subscriber(emptyObserver);\n }\n\n return new Subscriber(nextOrObserver, error, complete);\n}\n","import { Subscriber } from '../Subscriber';\nimport { Subject } from '../Subject';\n\n/**\n * Determines whether the ErrorObserver is closed or stopped or has a\n * destination that is closed or stopped - in which case errors will\n * need to be reported via a different mechanism.\n * @param observer the observer\n */\nexport function canReportError(observer: Subscriber | Subject): boolean {\n while (observer) {\n const { closed, destination, isStopped } = observer as any;\n if (closed || isStopped) {\n return false;\n } else if (destination && destination instanceof Subscriber) {\n observer = destination;\n } else {\n observer = null;\n }\n }\n return true;\n}\n","export interface ObjectUnsubscribedError extends Error {\n}\n\nexport interface ObjectUnsubscribedErrorCtor {\n new(): ObjectUnsubscribedError;\n}\n\nconst ObjectUnsubscribedErrorImpl = (() => {\n function ObjectUnsubscribedErrorImpl(this: any) {\n Error.call(this);\n this.message = 'object unsubscribed';\n this.name = 'ObjectUnsubscribedError';\n return this;\n }\n\n ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);\n\n return ObjectUnsubscribedErrorImpl;\n})();\n\n/**\n * An error thrown when an action is invalid because the object has been\n * unsubscribed.\n *\n * @see {@link Subject}\n * @see {@link BehaviorSubject}\n *\n * @class ObjectUnsubscribedError\n */\nexport const ObjectUnsubscribedError: ObjectUnsubscribedErrorCtor = ObjectUnsubscribedErrorImpl as any;","import { Subject } from './Subject';\nimport { Observer } from './types';\nimport { Subscription } from './Subscription';\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class SubjectSubscription extends Subscription {\n closed: boolean = false;\n\n constructor(public subject: Subject, public subscriber: Observer) {\n super();\n }\n\n unsubscribe() {\n if (this.closed) {\n return;\n }\n\n this.closed = true;\n\n const subject = this.subject;\n const observers = subject.observers;\n\n this.subject = null;\n\n if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {\n return;\n }\n\n const subscriberIndex = observers.indexOf(this.subscriber);\n\n if (subscriberIndex !== -1) {\n observers.splice(subscriberIndex, 1);\n }\n }\n}\n","import { Operator } from './Operator';\nimport { Observable } from './Observable';\nimport { Subscriber } from './Subscriber';\nimport { Subscription } from './Subscription';\nimport { Observer, SubscriptionLike, TeardownLogic } from './types';\nimport { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';\nimport { SubjectSubscription } from './SubjectSubscription';\nimport { rxSubscriber as rxSubscriberSymbol } from '../internal/symbol/rxSubscriber';\n\n/**\n * @class SubjectSubscriber\n */\nexport class SubjectSubscriber extends Subscriber {\n constructor(protected destination: Subject) {\n super(destination);\n }\n}\n\n/**\n * A Subject is a special type of Observable that allows values to be\n * multicasted to many Observers. Subjects are like EventEmitters.\n *\n * Every Subject is an Observable and an Observer. You can subscribe to a\n * Subject, and you can call next to feed values as well as error and complete.\n *\n * @class Subject\n */\nexport class Subject extends Observable implements SubscriptionLike {\n\n [rxSubscriberSymbol]() {\n return new SubjectSubscriber(this);\n }\n\n observers: Observer[] = [];\n\n closed = false;\n\n isStopped = false;\n\n hasError = false;\n\n thrownError: any = null;\n\n constructor() {\n super();\n }\n\n /**@nocollapse\n * @deprecated use new Subject() instead\n */\n static create: Function = (destination: Observer, source: Observable): AnonymousSubject => {\n return new AnonymousSubject(destination, source);\n }\n\n lift(operator: Operator): Observable {\n const subject = new AnonymousSubject(this, this);\n subject.operator = operator;\n return subject;\n }\n\n next(value?: T) {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n if (!this.isStopped) {\n const { observers } = this;\n const len = observers.length;\n const copy = observers.slice();\n for (let i = 0; i < len; i++) {\n copy[i].next(value);\n }\n }\n }\n\n error(err: any) {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n this.hasError = true;\n this.thrownError = err;\n this.isStopped = true;\n const { observers } = this;\n const len = observers.length;\n const copy = observers.slice();\n for (let i = 0; i < len; i++) {\n copy[i].error(err);\n }\n this.observers.length = 0;\n }\n\n complete() {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n this.isStopped = true;\n const { observers } = this;\n const len = observers.length;\n const copy = observers.slice();\n for (let i = 0; i < len; i++) {\n copy[i].complete();\n }\n this.observers.length = 0;\n }\n\n unsubscribe() {\n this.isStopped = true;\n this.closed = true;\n this.observers = null;\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _trySubscribe(subscriber: Subscriber): TeardownLogic {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n } else {\n return super._trySubscribe(subscriber);\n }\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _subscribe(subscriber: Subscriber): Subscription {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n } else if (this.hasError) {\n subscriber.error(this.thrownError);\n return Subscription.EMPTY;\n } else if (this.isStopped) {\n subscriber.complete();\n return Subscription.EMPTY;\n } else {\n this.observers.push(subscriber);\n return new SubjectSubscription(this, subscriber);\n }\n }\n\n /**\n * Creates a new Observable with this Subject as the source. You can do this\n * to create customize Observer-side logic of the Subject and conceal it from\n * code that uses the Observable.\n * @return {Observable} Observable that the Subject casts to\n */\n asObservable(): Observable {\n const observable = new Observable();\n (observable).source = this;\n return observable;\n }\n}\n\n/**\n * @class AnonymousSubject\n */\nexport class AnonymousSubject extends Subject {\n constructor(protected destination?: Observer, source?: Observable) {\n super();\n this.source = source;\n }\n\n next(value: T) {\n const { destination } = this;\n if (destination && destination.next) {\n destination.next(value);\n }\n }\n\n error(err: any) {\n const { destination } = this;\n if (destination && destination.error) {\n this.destination.error(err);\n }\n }\n\n complete() {\n const { destination } = this;\n if (destination && destination.complete) {\n this.destination.complete();\n }\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _subscribe(subscriber: Subscriber): Subscription {\n const { source } = this;\n if (source) {\n return this.source.subscribe(subscriber);\n } else {\n return Subscription.EMPTY;\n }\n }\n}\n","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { MonoTypeOperatorFunction, TeardownLogic } from '../types';\nimport { ConnectableObservable } from '../observable/ConnectableObservable';\nimport { Observable } from '../Observable';\n\n/**\n * Make a {@link ConnectableObservable} behave like a ordinary observable and automates the way\n * you can connect to it.\n *\n * Internally it counts the subscriptions to the observable and subscribes (only once) to the source if\n * the number of subscriptions is larger than 0. If the number of subscriptions is smaller than 1, it\n * unsubscribes from the source. This way you can make sure that everything before the *published*\n * refCount has only a single subscription independently of the number of subscribers to the target\n * observable.\n *\n * Note that using the {@link share} operator is exactly the same as using the *publish* operator\n * (making the observable hot) and the *refCount* operator in a sequence.\n *\n * ![](refCount.png)\n *\n * ## Example\n *\n * In the following example there are two intervals turned into connectable observables\n * by using the *publish* operator. The first one uses the *refCount* operator, the\n * second one does not use it. You will notice that a connectable observable does nothing\n * until you call its connect function.\n *\n * ```ts\n * import { interval } from 'rxjs';\n * import { tap, publish, refCount } from 'rxjs/operators';\n *\n * // Turn the interval observable into a ConnectableObservable (hot)\n * const refCountInterval = interval(400).pipe(\n * tap((num) => console.log(`refCount ${num}`)),\n * publish(),\n * refCount()\n * );\n *\n * const publishedInterval = interval(400).pipe(\n * tap((num) => console.log(`publish ${num}`)),\n * publish()\n * );\n *\n * refCountInterval.subscribe();\n * refCountInterval.subscribe();\n * // 'refCount 0' -----> 'refCount 1' -----> etc\n * // All subscriptions will receive the same value and the tap (and\n * // every other operator) before the publish operator will be executed\n * // only once per event independently of the number of subscriptions.\n *\n * publishedInterval.subscribe();\n * // Nothing happens until you call .connect() on the observable.\n * ```\n *\n * @see {@link ConnectableObservable}\n * @see {@link share}\n * @see {@link publish}\n */\nexport function refCount(): MonoTypeOperatorFunction {\n return function refCountOperatorFunction(source: ConnectableObservable): Observable {\n return source.lift(new RefCountOperator(source));\n } as MonoTypeOperatorFunction;\n}\n\nclass RefCountOperator implements Operator {\n constructor(private connectable: ConnectableObservable) {\n }\n call(subscriber: Subscriber, source: any): TeardownLogic {\n\n const { connectable } = this;\n ( connectable)._refCount++;\n\n const refCounter = new RefCountSubscriber(subscriber, connectable);\n const subscription = source.subscribe(refCounter);\n\n if (!refCounter.closed) {\n ( refCounter).connection = connectable.connect();\n }\n\n return subscription;\n }\n}\n\nclass RefCountSubscriber extends Subscriber {\n\n private connection: Subscription;\n\n constructor(destination: Subscriber,\n private connectable: ConnectableObservable) {\n super(destination);\n }\n\n protected _unsubscribe() {\n\n const { connectable } = this;\n if (!connectable) {\n this.connection = null;\n return;\n }\n\n this.connectable = null;\n const refCount = ( connectable)._refCount;\n if (refCount <= 0) {\n this.connection = null;\n return;\n }\n\n ( connectable)._refCount = refCount - 1;\n if (refCount > 1) {\n this.connection = null;\n return;\n }\n\n ///\n // Compare the local RefCountSubscriber's connection Subscription to the\n // connection Subscription on the shared ConnectableObservable. In cases\n // where the ConnectableObservable source synchronously emits values, and\n // the RefCountSubscriber's downstream Observers synchronously unsubscribe,\n // execution continues to here before the RefCountOperator has a chance to\n // supply the RefCountSubscriber with the shared connection Subscription.\n // For example:\n // ```\n // range(0, 10).pipe(\n // publish(),\n // refCount(),\n // take(5),\n // )\n // .subscribe();\n // ```\n // In order to account for this case, RefCountSubscriber should only dispose\n // the ConnectableObservable's shared connection Subscription if the\n // connection Subscription exists, *and* either:\n // a. RefCountSubscriber doesn't have a reference to the shared connection\n // Subscription yet, or,\n // b. RefCountSubscriber's connection Subscription reference is identical\n // to the shared connection Subscription\n ///\n const { connection } = this;\n const sharedConnection = ( connectable)._connection;\n this.connection = null;\n\n if (sharedConnection && (!connection || sharedConnection === connection)) {\n sharedConnection.unsubscribe();\n }\n }\n}\n","import { Subject, SubjectSubscriber } from '../Subject';\nimport { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { TeardownLogic } from '../types';\nimport { refCount as higherOrderRefCount } from '../operators/refCount';\n\n/**\n * @class ConnectableObservable\n */\nexport class ConnectableObservable extends Observable {\n\n protected _subject: Subject;\n protected _refCount: number = 0;\n protected _connection: Subscription;\n /** @internal */\n _isComplete = false;\n\n constructor(public source: Observable,\n protected subjectFactory: () => Subject) {\n super();\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _subscribe(subscriber: Subscriber) {\n return this.getSubject().subscribe(subscriber);\n }\n\n protected getSubject(): Subject {\n const subject = this._subject;\n if (!subject || subject.isStopped) {\n this._subject = this.subjectFactory();\n }\n return this._subject;\n }\n\n connect(): Subscription {\n let connection = this._connection;\n if (!connection) {\n this._isComplete = false;\n connection = this._connection = new Subscription();\n connection.add(this.source\n .subscribe(new ConnectableSubscriber(this.getSubject(), this)));\n if (connection.closed) {\n this._connection = null;\n connection = Subscription.EMPTY;\n }\n }\n return connection;\n }\n\n refCount(): Observable {\n return higherOrderRefCount()(this) as Observable;\n }\n}\n\nexport const connectableObservableDescriptor: PropertyDescriptorMap = (() => {\n const connectableProto = ConnectableObservable.prototype;\n return {\n operator: { value: null as null },\n _refCount: { value: 0, writable: true },\n _subject: { value: null as null, writable: true },\n _connection: { value: null as null, writable: true },\n _subscribe: { value: connectableProto._subscribe },\n _isComplete: { value: connectableProto._isComplete, writable: true },\n getSubject: { value: connectableProto.getSubject },\n connect: { value: connectableProto.connect },\n refCount: { value: connectableProto.refCount }\n };\n})();\n\nclass ConnectableSubscriber extends SubjectSubscriber {\n constructor(destination: Subject,\n private connectable: ConnectableObservable) {\n super(destination);\n }\n protected _error(err: any): void {\n this._unsubscribe();\n super._error(err);\n }\n protected _complete(): void {\n this.connectable._isComplete = true;\n this._unsubscribe();\n super._complete();\n }\n protected _unsubscribe() {\n const connectable = this.connectable;\n if (connectable) {\n this.connectable = null;\n const connection = connectable._connection;\n connectable._refCount = 0;\n connectable._subject = null;\n connectable._connection = null;\n if (connection) {\n connection.unsubscribe();\n }\n }\n }\n}\n\nclass RefCountOperator implements Operator {\n constructor(private connectable: ConnectableObservable) {\n }\n call(subscriber: Subscriber, source: any): TeardownLogic {\n\n const { connectable } = this;\n ( connectable)._refCount++;\n\n const refCounter = new RefCountSubscriber(subscriber, connectable);\n const subscription = source.subscribe(refCounter);\n\n if (!refCounter.closed) {\n ( refCounter).connection = connectable.connect();\n }\n\n return subscription;\n }\n}\n\nclass RefCountSubscriber extends Subscriber {\n\n private connection: Subscription;\n\n constructor(destination: Subscriber,\n private connectable: ConnectableObservable) {\n super(destination);\n }\n\n protected _unsubscribe() {\n\n const { connectable } = this;\n if (!connectable) {\n this.connection = null;\n return;\n }\n\n this.connectable = null;\n const refCount = ( connectable)._refCount;\n if (refCount <= 0) {\n this.connection = null;\n return;\n }\n\n ( connectable)._refCount = refCount - 1;\n if (refCount > 1) {\n this.connection = null;\n return;\n }\n\n ///\n // Compare the local RefCountSubscriber's connection Subscription to the\n // connection Subscription on the shared ConnectableObservable. In cases\n // where the ConnectableObservable source synchronously emits values, and\n // the RefCountSubscriber's downstream Observers synchronously unsubscribe,\n // execution continues to here before the RefCountOperator has a chance to\n // supply the RefCountSubscriber with the shared connection Subscription.\n // For example:\n // ```\n // range(0, 10).pipe(\n // publish(),\n // refCount(),\n // take(5),\n // ).subscribe();\n // ```\n // In order to account for this case, RefCountSubscriber should only dispose\n // the ConnectableObservable's shared connection Subscription if the\n // connection Subscription exists, *and* either:\n // a. RefCountSubscriber doesn't have a reference to the shared connection\n // Subscription yet, or,\n // b. RefCountSubscriber's connection Subscription reference is identical\n // to the shared connection Subscription\n ///\n const { connection } = this;\n const sharedConnection = ( connectable)._connection;\n this.connection = null;\n\n if (sharedConnection && (!connection || sharedConnection === connection)) {\n sharedConnection.unsubscribe();\n }\n }\n}\n","import { Subject } from './Subject';\nimport { Subscriber } from './Subscriber';\nimport { Subscription } from './Subscription';\nimport { SubscriptionLike } from './types';\nimport { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';\n\n/**\n * A variant of Subject that requires an initial value and emits its current\n * value whenever it is subscribed to.\n *\n * @class BehaviorSubject\n */\nexport class BehaviorSubject extends Subject {\n\n constructor(private _value: T) {\n super();\n }\n\n get value(): T {\n return this.getValue();\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _subscribe(subscriber: Subscriber): Subscription {\n const subscription = super._subscribe(subscriber);\n if (subscription && !(subscription).closed) {\n subscriber.next(this._value);\n }\n return subscription;\n }\n\n getValue(): T {\n if (this.hasError) {\n throw this.thrownError;\n } else if (this.closed) {\n throw new ObjectUnsubscribedError();\n } else {\n return this._value;\n }\n }\n\n next(value: T): void {\n super.next(this._value = value);\n }\n}\n","import { Action } from './Action';\nimport { SchedulerAction } from '../types';\nimport { Subscription } from '../Subscription';\nimport { AsyncScheduler } from './AsyncScheduler';\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class AsyncAction extends Action {\n\n public id: any;\n public state: T;\n public delay: number;\n protected pending: boolean = false;\n\n constructor(protected scheduler: AsyncScheduler,\n protected work: (this: SchedulerAction, state?: T) => void) {\n super(scheduler, work);\n }\n\n public schedule(state?: T, delay: number = 0): Subscription {\n\n if (this.closed) {\n return this;\n }\n\n // Always replace the current state with the new state.\n this.state = state;\n\n const id = this.id;\n const scheduler = this.scheduler;\n\n //\n // Important implementation note:\n //\n // Actions only execute once by default, unless rescheduled from within the\n // scheduled callback. This allows us to implement single and repeat\n // actions via the same code path, without adding API surface area, as well\n // as mimic traditional recursion but across asynchronous boundaries.\n //\n // However, JS runtimes and timers distinguish between intervals achieved by\n // serial `setTimeout` calls vs. a single `setInterval` call. An interval of\n // serial `setTimeout` calls can be individually delayed, which delays\n // scheduling the next `setTimeout`, and so on. `setInterval` attempts to\n // guarantee the interval callback will be invoked more precisely to the\n // interval period, regardless of load.\n //\n // Therefore, we use `setInterval` to schedule single and repeat actions.\n // If the action reschedules itself with the same delay, the interval is not\n // canceled. If the action doesn't reschedule, or reschedules with a\n // different delay, the interval will be canceled after scheduled callback\n // execution.\n //\n if (id != null) {\n this.id = this.recycleAsyncId(scheduler, id, delay);\n }\n\n // Set the pending flag indicating that this action has been scheduled, or\n // has recursively rescheduled itself.\n this.pending = true;\n\n this.delay = delay;\n // If this action has already an async Id, don't request a new one.\n this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);\n\n return this;\n }\n\n protected requestAsyncId(scheduler: AsyncScheduler, id?: any, delay: number = 0): any {\n return setInterval(scheduler.flush.bind(scheduler, this), delay);\n }\n\n protected recycleAsyncId(scheduler: AsyncScheduler, id: any, delay: number = 0): any {\n // If this action is rescheduled with the same delay time, don't clear the interval id.\n if (delay !== null && this.delay === delay && this.pending === false) {\n return id;\n }\n // Otherwise, if the action's delay time is different from the current delay,\n // or the action has been rescheduled before it's executed, clear the interval id\n clearInterval(id);\n return undefined;\n }\n\n /**\n * Immediately executes this action and the `work` it contains.\n * @return {any}\n */\n public execute(state: T, delay: number): any {\n\n if (this.closed) {\n return new Error('executing a cancelled action');\n }\n\n this.pending = false;\n const error = this._execute(state, delay);\n if (error) {\n return error;\n } else if (this.pending === false && this.id != null) {\n // Dequeue if the action didn't reschedule itself. Don't call\n // unsubscribe(), because the action could reschedule later.\n // For example:\n // ```\n // scheduler.schedule(function doWork(counter) {\n // /* ... I'm a busy worker bee ... */\n // var originalAction = this;\n // /* wait 100ms before rescheduling the action */\n // setTimeout(function () {\n // originalAction.schedule(counter + 1);\n // }, 100);\n // }, 1000);\n // ```\n this.id = this.recycleAsyncId(this.scheduler, this.id, null);\n }\n }\n\n protected _execute(state: T, delay: number): any {\n let errored: boolean = false;\n let errorValue: any = undefined;\n try {\n this.work(state);\n } catch (e) {\n errored = true;\n errorValue = !!e && e || new Error(e);\n }\n if (errored) {\n this.unsubscribe();\n return errorValue;\n }\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _unsubscribe() {\n\n const id = this.id;\n const scheduler = this.scheduler;\n const actions = scheduler.actions;\n const index = actions.indexOf(this);\n\n this.work = null;\n this.state = null;\n this.pending = false;\n this.scheduler = null;\n\n if (index !== -1) {\n actions.splice(index, 1);\n }\n\n if (id != null) {\n this.id = this.recycleAsyncId(scheduler, id, null);\n }\n\n this.delay = null;\n }\n}\n","import { Scheduler } from '../Scheduler';\nimport { Subscription } from '../Subscription';\nimport { SchedulerAction } from '../types';\n\n/**\n * A unit of work to be executed in a `scheduler`. An action is typically\n * created from within a {@link SchedulerLike} and an RxJS user does not need to concern\n * themselves about creating and manipulating an Action.\n *\n * ```ts\n * class Action extends Subscription {\n * new (scheduler: Scheduler, work: (state?: T) => void);\n * schedule(state?: T, delay: number = 0): Subscription;\n * }\n * ```\n *\n * @class Action\n */\nexport class Action extends Subscription {\n constructor(scheduler: Scheduler, work: (this: SchedulerAction, state?: T) => void) {\n super();\n }\n /**\n * Schedules this action on its parent {@link SchedulerLike} for execution. May be passed\n * some context object, `state`. May happen at some point in the future,\n * according to the `delay` parameter, if specified.\n * @param {T} [state] Some contextual data that the `work` function uses when\n * called by the Scheduler.\n * @param {number} [delay] Time to wait before executing the work, where the\n * time unit is implicit and defined by the Scheduler.\n * @return {void}\n */\n public schedule(state?: T, delay: number = 0): Subscription {\n return this;\n }\n}\n","import { AsyncAction } from './AsyncAction';\nimport { Subscription } from '../Subscription';\nimport { QueueScheduler } from './QueueScheduler';\nimport { SchedulerAction } from '../types';\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class QueueAction extends AsyncAction {\n\n constructor(protected scheduler: QueueScheduler,\n protected work: (this: SchedulerAction, state?: T) => void) {\n super(scheduler, work);\n }\n\n public schedule(state?: T, delay: number = 0): Subscription {\n if (delay > 0) {\n return super.schedule(state, delay);\n }\n this.delay = delay;\n this.state = state;\n this.scheduler.flush(this);\n return this;\n }\n\n public execute(state: T, delay: number): any {\n return (delay > 0 || this.closed) ?\n super.execute(state, delay) :\n this._execute(state, delay) ;\n }\n\n protected requestAsyncId(scheduler: QueueScheduler, id?: any, delay: number = 0): any {\n // If delay exists and is greater than 0, or if the delay is null (the\n // action wasn't rescheduled) but was originally scheduled as an async\n // action, then recycle as an async action.\n if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {\n return super.requestAsyncId(scheduler, id, delay);\n }\n // Otherwise flush the scheduler starting with this action.\n return scheduler.flush(this);\n }\n}\n","import { Action } from './scheduler/Action';\nimport { Subscription } from './Subscription';\nimport { SchedulerLike, SchedulerAction } from './types';\n\n/**\n * An execution context and a data structure to order tasks and schedule their\n * execution. Provides a notion of (potentially virtual) time, through the\n * `now()` getter method.\n *\n * Each unit of work in a Scheduler is called an `Action`.\n *\n * ```ts\n * class Scheduler {\n * now(): number;\n * schedule(work, delay?, state?): Subscription;\n * }\n * ```\n *\n * @class Scheduler\n * @deprecated Scheduler is an internal implementation detail of RxJS, and\n * should not be used directly. Rather, create your own class and implement\n * {@link SchedulerLike}\n */\nexport class Scheduler implements SchedulerLike {\n\n /**\n * Note: the extra arrow function wrapper is to make testing by overriding\n * Date.now easier.\n * @nocollapse\n */\n public static now: () => number = () => Date.now();\n\n constructor(private SchedulerAction: typeof Action,\n now: () => number = Scheduler.now) {\n this.now = now;\n }\n\n /**\n * A getter method that returns a number representing the current time\n * (at the time this function was called) according to the scheduler's own\n * internal clock.\n * @return {number} A number that represents the current time. May or may not\n * have a relation to wall-clock time. May or may not refer to a time unit\n * (e.g. milliseconds).\n */\n public now: () => number;\n\n /**\n * Schedules a function, `work`, for execution. May happen at some point in\n * the future, according to the `delay` parameter, if specified. May be passed\n * some context object, `state`, which will be passed to the `work` function.\n *\n * The given arguments will be processed an stored as an Action object in a\n * queue of actions.\n *\n * @param {function(state: ?T): ?Subscription} work A function representing a\n * task, or some unit of work to be executed by the Scheduler.\n * @param {number} [delay] Time to wait before executing the work, where the\n * time unit is implicit and defined by the Scheduler itself.\n * @param {T} [state] Some contextual data that the `work` function uses when\n * called by the Scheduler.\n * @return {Subscription} A subscription in order to be able to unsubscribe\n * the scheduled work.\n */\n public schedule(work: (this: SchedulerAction, state?: T) => void, delay: number = 0, state?: T): Subscription {\n return new this.SchedulerAction(this, work).schedule(state, delay);\n }\n}\n","import { Scheduler } from '../Scheduler';\nimport { Action } from './Action';\nimport { AsyncAction } from './AsyncAction';\nimport { SchedulerAction } from '../types';\nimport { Subscription } from '../Subscription';\n\nexport class AsyncScheduler extends Scheduler {\n public static delegate?: Scheduler;\n public actions: Array> = [];\n /**\n * A flag to indicate whether the Scheduler is currently executing a batch of\n * queued actions.\n * @type {boolean}\n * @deprecated internal use only\n */\n public active: boolean = false;\n /**\n * An internal ID used to track the latest asynchronous task such as those\n * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and\n * others.\n * @type {any}\n * @deprecated internal use only\n */\n public scheduled: any = undefined;\n\n constructor(SchedulerAction: typeof Action,\n now: () => number = Scheduler.now) {\n super(SchedulerAction, () => {\n if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {\n return AsyncScheduler.delegate.now();\n } else {\n return now();\n }\n });\n }\n\n public schedule(work: (this: SchedulerAction, state?: T) => void, delay: number = 0, state?: T): Subscription {\n if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {\n return AsyncScheduler.delegate.schedule(work, delay, state);\n } else {\n return super.schedule(work, delay, state);\n }\n }\n\n public flush(action: AsyncAction): void {\n\n const {actions} = this;\n\n if (this.active) {\n actions.push(action);\n return;\n }\n\n let error: any;\n this.active = true;\n\n do {\n if (error = action.execute(action.state, action.delay)) {\n break;\n }\n } while (action = actions.shift()); // exhaust the scheduler queue\n\n this.active = false;\n\n if (error) {\n while (action = actions.shift()) {\n action.unsubscribe();\n }\n throw error;\n }\n }\n}\n","import { AsyncScheduler } from './AsyncScheduler';\n\nexport class QueueScheduler extends AsyncScheduler {\n}\n","import { QueueAction } from './QueueAction';\nimport { QueueScheduler } from './QueueScheduler';\n\n/**\n *\n * Queue Scheduler\n *\n * Put every next task on a queue, instead of executing it immediately\n *\n * `queue` scheduler, when used with delay, behaves the same as {@link asyncScheduler} scheduler.\n *\n * When used without delay, it schedules given task synchronously - executes it right when\n * it is scheduled. However when called recursively, that is when inside the scheduled task,\n * another task is scheduled with queue scheduler, instead of executing immediately as well,\n * that task will be put on a queue and wait for current one to finish.\n *\n * This means that when you execute task with `queue` scheduler, you are sure it will end\n * before any other task scheduled with that scheduler will start.\n *\n * ## Examples\n * Schedule recursively first, then do something\n * ```ts\n * import { queueScheduler } from 'rxjs';\n *\n * queueScheduler.schedule(() => {\n * queueScheduler.schedule(() => console.log('second')); // will not happen now, but will be put on a queue\n *\n * console.log('first');\n * });\n *\n * // Logs:\n * // \"first\"\n * // \"second\"\n * ```\n *\n * Reschedule itself recursively\n * ```ts\n * import { queueScheduler } from 'rxjs';\n *\n * queueScheduler.schedule(function(state) {\n * if (state !== 0) {\n * console.log('before', state);\n * this.schedule(state - 1); // `this` references currently executing Action,\n * // which we reschedule with new state\n * console.log('after', state);\n * }\n * }, 0, 3);\n *\n * // In scheduler that runs recursively, you would expect:\n * // \"before\", 3\n * // \"before\", 2\n * // \"before\", 1\n * // \"after\", 1\n * // \"after\", 2\n * // \"after\", 3\n *\n * // But with queue it logs:\n * // \"before\", 3\n * // \"after\", 3\n * // \"before\", 2\n * // \"after\", 2\n * // \"before\", 1\n * // \"after\", 1\n * ```\n */\nexport const queueScheduler = new QueueScheduler(QueueAction);\n\n/**\n * @deprecated renamed. Use {@link queueScheduler}\n */\nexport const queue = queueScheduler;\n","import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\n\n/**\n * The same Observable instance returned by any call to {@link empty} without a\n * `scheduler`. It is preferrable to use this over `empty()`.\n */\nexport const EMPTY = new Observable(subscriber => subscriber.complete());\n\n/**\n * Creates an Observable that emits no items to the Observer and immediately\n * emits a complete notification.\n *\n * Just emits 'complete', and nothing else.\n * \n *\n * ![](empty.png)\n *\n * This static operator is useful for creating a simple Observable that only\n * emits the complete notification. It can be used for composing with other\n * Observables, such as in a {@link mergeMap}.\n *\n * ## Examples\n * ### Emit the number 7, then complete\n * ```ts\n * import { empty } from 'rxjs';\n * import { startWith } from 'rxjs/operators';\n *\n * const result = empty().pipe(startWith(7));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * ### Map and flatten only odd numbers to the sequence 'a', 'b', 'c'\n * ```ts\n * import { empty, interval, of } from 'rxjs';\n * import { mergeMap } from 'rxjs/operators';\n *\n * const interval$ = interval(1000);\n * const result = interval$.pipe(\n * mergeMap(x => x % 2 === 1 ? of('a', 'b', 'c') : empty()),\n * );\n * result.subscribe(x => console.log(x));\n *\n * // Results in the following to the console:\n * // x is equal to the count on the interval eg(0,1,2,3,...)\n * // x will occur every 1000ms\n * // if x % 2 is equal to 1 print abc\n * // if x % 2 is not equal to 1 nothing will be output\n * ```\n *\n * @see {@link Observable}\n * @see {@link never}\n * @see {@link of}\n * @see {@link throwError}\n *\n * @param scheduler A {@link SchedulerLike} to use for scheduling\n * the emission of the complete notification.\n * @return An \"empty\" Observable: emits only the complete\n * notification.\n * @deprecated Deprecated in favor of using {@link EMPTY} constant, or {@link scheduled} (e.g. `scheduled([], scheduler)`)\n */\nexport function empty(scheduler?: SchedulerLike) {\n return scheduler ? emptyScheduled(scheduler) : EMPTY;\n}\n\nfunction emptyScheduled(scheduler: SchedulerLike) {\n return new Observable(subscriber => scheduler.schedule(() => subscriber.complete()));\n}\n","import { SchedulerLike } from '../types';\n\nexport function isScheduler(value: any): value is SchedulerLike {\n return value && typeof (value).schedule === 'function';\n}\n","import { Subscriber } from '../Subscriber';\n\n/**\n * Subscribes to an ArrayLike with a subscriber\n * @param array The array or array-like to subscribe to\n */\nexport const subscribeToArray = (array: ArrayLike) => (subscriber: Subscriber) => {\n for (let i = 0, len = array.length; i < len && !subscriber.closed; i++) {\n subscriber.next(array[i]);\n }\n subscriber.complete();\n};\n","import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\nimport { Subscription } from '../Subscription';\n\nexport function scheduleArray(input: ArrayLike, scheduler: SchedulerLike) {\n return new Observable(subscriber => {\n const sub = new Subscription();\n let i = 0;\n sub.add(scheduler.schedule(function () {\n if (i === input.length) {\n subscriber.complete();\n return;\n }\n subscriber.next(input[i++]);\n if (!subscriber.closed) {\n sub.add(this.schedule());\n }\n }));\n return sub;\n });\n}\n","import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\nimport { subscribeToArray } from '../util/subscribeToArray';\nimport { scheduleArray } from '../scheduled/scheduleArray';\n\nexport function fromArray(input: ArrayLike, scheduler?: SchedulerLike) {\n if (!scheduler) {\n return new Observable(subscribeToArray(input));\n } else {\n return scheduleArray(input, scheduler);\n }\n}\n","import { SchedulerLike } from '../types';\nimport { isScheduler } from '../util/isScheduler';\nimport { fromArray } from './fromArray';\nimport { Observable } from '../Observable';\nimport { scheduleArray } from '../scheduled/scheduleArray';\n\n/* tslint:disable:max-line-length */\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, d: T4, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, g: T7, scheduler: SchedulerLike):\n Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, g: T7, h: T8, scheduler: SchedulerLike):\n Observable;\n/** @deprecated use {@link scheduled} instead `scheduled([a, b, c], scheduler)` */\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, g: T7, h: T8, i: T9, scheduler: SchedulerLike):\n Observable;\nexport function of(...args: (T | SchedulerLike)[]): Observable;\n\n// TODO(benlesh): Update the typings for this when we can switch to TS 3.x\nexport function of(a: T): Observable;\nexport function of(a: T, b: T2): Observable;\nexport function of(a: T, b: T2, c: T3): Observable;\nexport function of(a: T, b: T2, c: T3, d: T4): Observable;\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5): Observable;\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6): Observable;\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, g: T7):\n Observable;\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, g: T7, h: T8):\n Observable;\nexport function of(a: T, b: T2, c: T3, d: T4, e: T5, f: T6, g: T7, h: T8, i: T9):\n Observable;\nexport function of(...args: T[]): Observable;\n/* tslint:enable:max-line-length */\n\n/**\n * Converts the arguments to an observable sequence.\n *\n * Each argument becomes a `next` notification.\n *\n * ![](of.png)\n *\n * Unlike {@link from}, it does not do any flattening and emits each argument in whole\n * as a separate `next` notification.\n *\n * ## Examples\n *\n * Emit the values `10, 20, 30`\n *\n * ```ts\n * import { of } from 'rxjs';\n *\n * of(10, 20, 30)\n * .subscribe(\n * next => console.log('next:', next),\n * err => console.log('error:', err),\n * () => console.log('the end'),\n * );\n * // result:\n * // 'next: 10'\n * // 'next: 20'\n * // 'next: 30'\n *\n * ```\n *\n * Emit the array `[1,2,3]`\n *\n * ```ts\n * import { of } from 'rxjs';\n *\n * of([1,2,3])\n * .subscribe(\n * next => console.log('next:', next),\n * err => console.log('error:', err),\n * () => console.log('the end'),\n * );\n * // result:\n * // 'next: [1,2,3]'\n * ```\n *\n * @see {@link from}\n * @see {@link range}\n *\n * @param {...T} values A comma separated list of arguments you want to be emitted\n * @return {Observable} An Observable that emits the arguments\n * described above and then completes.\n * @method of\n * @owner Observable\n */\n\nexport function of(...args: Array): Observable {\n let scheduler = args[args.length - 1] as SchedulerLike;\n if (isScheduler(scheduler)) {\n args.pop();\n return scheduleArray(args as T[], scheduler);\n } else {\n return fromArray(args as T[]);\n }\n}\n","import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\nimport { Subscriber } from '../Subscriber';\n\n/**\n * Creates an Observable that emits no items to the Observer and immediately\n * emits an error notification.\n *\n * Just emits 'error', and nothing else.\n * \n *\n * ![](throw.png)\n *\n * This static operator is useful for creating a simple Observable that only\n * emits the error notification. It can be used for composing with other\n * Observables, such as in a {@link mergeMap}.\n *\n * ## Examples\n * ### Emit the number 7, then emit an error\n * ```ts\n * import { throwError, concat, of } from 'rxjs';\n *\n * const result = concat(of(7), throwError(new Error('oops!')));\n * result.subscribe(x => console.log(x), e => console.error(e));\n *\n * // Logs:\n * // 7\n * // Error: oops!\n * ```\n *\n * ---\n *\n * ### Map and flatten numbers to the sequence 'a', 'b', 'c', but throw an error for 2\n * ```ts\n * import { throwError, interval, of } from 'rxjs';\n * import { mergeMap } from 'rxjs/operators';\n *\n * interval(1000).pipe(\n * mergeMap(x => x === 2\n * ? throwError('Twos are bad')\n * : of('a', 'b', 'c')\n * ),\n * ).subscribe(x => console.log(x), e => console.error(e));\n *\n * // Logs:\n * // a\n * // b\n * // c\n * // a\n * // b\n * // c\n * // Twos are bad\n * ```\n *\n * @see {@link Observable}\n * @see {@link empty}\n * @see {@link never}\n * @see {@link of}\n *\n * @param {any} error The particular Error to pass to the error notification.\n * @param {SchedulerLike} [scheduler] A {@link SchedulerLike} to use for scheduling\n * the emission of the error notification.\n * @return {Observable} An error Observable: emits only the error notification\n * using the given error argument.\n * @static true\n * @name throwError\n * @owner Observable\n */\nexport function throwError(error: any, scheduler?: SchedulerLike): Observable {\n if (!scheduler) {\n return new Observable(subscriber => subscriber.error(error));\n } else {\n return new Observable(subscriber => scheduler.schedule(dispatch, 0, { error, subscriber }));\n }\n}\n\ninterface DispatchArg {\n error: any;\n subscriber: Subscriber;\n}\n\nfunction dispatch({ error, subscriber }: DispatchArg) {\n subscriber.error(error);\n}\n","import { PartialObserver } from './types';\nimport { Observable } from './Observable';\nimport { empty } from './observable/empty';\nimport { of } from './observable/of';\nimport { throwError } from './observable/throwError';\nimport { deprecate } from 'util';\n\n// TODO: When this enum is removed, replace it with a type alias. See #4556.\n/**\n * @deprecated NotificationKind is deprecated as const enums are not compatible with isolated modules. Use a string literal instead.\n */\nexport enum NotificationKind {\n NEXT = 'N',\n ERROR = 'E',\n COMPLETE = 'C',\n}\n\n/**\n * Represents a push-based event or value that an {@link Observable} can emit.\n * This class is particularly useful for operators that manage notifications,\n * like {@link materialize}, {@link dematerialize}, {@link observeOn}, and\n * others. Besides wrapping the actual delivered value, it also annotates it\n * with metadata of, for instance, what type of push message it is (`next`,\n * `error`, or `complete`).\n *\n * @see {@link materialize}\n * @see {@link dematerialize}\n * @see {@link observeOn}\n *\n * @class Notification\n */\nexport class Notification {\n hasValue: boolean;\n\n constructor(public kind: 'N' | 'E' | 'C', public value?: T, public error?: any) {\n this.hasValue = kind === 'N';\n }\n\n /**\n * Delivers to the given `observer` the value wrapped by this Notification.\n * @param {Observer} observer\n * @return\n */\n observe(observer: PartialObserver): any {\n switch (this.kind) {\n case 'N':\n return observer.next && observer.next(this.value);\n case 'E':\n return observer.error && observer.error(this.error);\n case 'C':\n return observer.complete && observer.complete();\n }\n }\n\n /**\n * Given some {@link Observer} callbacks, deliver the value represented by the\n * current Notification to the correctly corresponding callback.\n * @param {function(value: T): void} next An Observer `next` callback.\n * @param {function(err: any): void} [error] An Observer `error` callback.\n * @param {function(): void} [complete] An Observer `complete` callback.\n * @return {any}\n */\n do(next: (value: T) => void, error?: (err: any) => void, complete?: () => void): any {\n const kind = this.kind;\n switch (kind) {\n case 'N':\n return next && next(this.value);\n case 'E':\n return error && error(this.error);\n case 'C':\n return complete && complete();\n }\n }\n\n /**\n * Takes an Observer or its individual callback functions, and calls `observe`\n * or `do` methods accordingly.\n * @param {Observer|function(value: T): void} nextOrObserver An Observer or\n * the `next` callback.\n * @param {function(err: any): void} [error] An Observer `error` callback.\n * @param {function(): void} [complete] An Observer `complete` callback.\n * @return {any}\n */\n accept(nextOrObserver: PartialObserver | ((value: T) => void), error?: (err: any) => void, complete?: () => void) {\n if (nextOrObserver && typeof (>nextOrObserver).next === 'function') {\n return this.observe(>nextOrObserver);\n } else {\n return this.do(<(value: T) => void>nextOrObserver, error, complete);\n }\n }\n\n /**\n * Returns a simple Observable that just delivers the notification represented\n * by this Notification instance.\n * @return {any}\n */\n toObservable(): Observable {\n const kind = this.kind;\n switch (kind) {\n case 'N':\n return of(this.value);\n case 'E':\n return throwError(this.error);\n case 'C':\n return empty();\n }\n throw new Error('unexpected notification kind value');\n }\n\n private static completeNotification: Notification = new Notification('C');\n private static undefinedValueNotification: Notification = new Notification('N', undefined);\n\n /**\n * A shortcut to create a Notification instance of the type `next` from a\n * given value.\n * @param {T} value The `next` value.\n * @return {Notification} The \"next\" Notification representing the\n * argument.\n * @nocollapse\n */\n static createNext(value: T): Notification {\n if (typeof value !== 'undefined') {\n return new Notification('N', value);\n }\n return Notification.undefinedValueNotification;\n }\n\n /**\n * A shortcut to create a Notification instance of the type `error` from a\n * given error.\n * @param {any} [err] The `error` error.\n * @return {Notification} The \"error\" Notification representing the\n * argument.\n * @nocollapse\n */\n static createError(err?: any): Notification {\n return new Notification('E', undefined, err);\n }\n\n /**\n * A shortcut to create a Notification instance of the type `complete`.\n * @return {Notification} The valueless \"complete\" Notification.\n * @nocollapse\n */\n static createComplete(): Notification {\n return Notification.completeNotification;\n }\n}\n","import { Observable } from '../Observable';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { Notification } from '../Notification';\nimport { MonoTypeOperatorFunction, PartialObserver, SchedulerAction, SchedulerLike, TeardownLogic } from '../types';\n\n/**\n *\n * Re-emits all notifications from source Observable with specified scheduler.\n *\n * Ensure a specific scheduler is used, from outside of an Observable.\n *\n * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule\n * notifications emitted by the source Observable. It might be useful, if you do not have control over\n * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.\n *\n * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,\n * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal\n * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits\n * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.\n * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split\n * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source\n * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a\n * little bit more, to ensure that they are emitted at expected moments.\n *\n * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications\n * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`\n * will delay all notifications - including error notifications - while `delay` will pass through error\n * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator\n * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used\n * for notification emissions in general.\n *\n * ## Example\n * Ensure values in subscribe are called just before browser repaint.\n * ```ts\n * import { interval } from 'rxjs';\n * import { observeOn } from 'rxjs/operators';\n *\n * const intervals = interval(10); // Intervals are scheduled\n * // with async scheduler by default...\n * intervals.pipe(\n * observeOn(animationFrameScheduler), // ...but we will observe on animationFrame\n * ) // scheduler to ensure smooth animation.\n * .subscribe(val => {\n * someDiv.style.height = val + 'px';\n * });\n * ```\n *\n * @see {@link delay}\n *\n * @param {SchedulerLike} scheduler Scheduler that will be used to reschedule notifications from source Observable.\n * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.\n * @return {Observable} Observable that emits the same notifications as the source Observable,\n * but with provided scheduler.\n *\n * @method observeOn\n * @owner Observable\n */\nexport function observeOn(scheduler: SchedulerLike, delay: number = 0): MonoTypeOperatorFunction {\n return function observeOnOperatorFunction(source: Observable): Observable {\n return source.lift(new ObserveOnOperator(scheduler, delay));\n };\n}\n\nexport class ObserveOnOperator implements Operator {\n constructor(private scheduler: SchedulerLike, private delay: number = 0) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class ObserveOnSubscriber extends Subscriber {\n /** @nocollapse */\n static dispatch(this: SchedulerAction, arg: ObserveOnMessage) {\n const { notification, destination } = arg;\n notification.observe(destination);\n this.unsubscribe();\n }\n\n constructor(destination: Subscriber,\n private scheduler: SchedulerLike,\n private delay: number = 0) {\n super(destination);\n }\n\n private scheduleMessage(notification: Notification): void {\n const destination = this.destination as Subscription;\n destination.add(this.scheduler.schedule(\n ObserveOnSubscriber.dispatch,\n this.delay,\n new ObserveOnMessage(notification, this.destination)\n ));\n }\n\n protected _next(value: T): void {\n this.scheduleMessage(Notification.createNext(value));\n }\n\n protected _error(err: any): void {\n this.scheduleMessage(Notification.createError(err));\n this.unsubscribe();\n }\n\n protected _complete(): void {\n this.scheduleMessage(Notification.createComplete());\n this.unsubscribe();\n }\n}\n\nexport class ObserveOnMessage {\n constructor(public notification: Notification,\n public destination: PartialObserver) {\n }\n}\n","import { Subject } from './Subject';\nimport { SchedulerLike } from './types';\nimport { queue } from './scheduler/queue';\nimport { Subscriber } from './Subscriber';\nimport { Subscription } from './Subscription';\nimport { ObserveOnSubscriber } from './operators/observeOn';\nimport { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';\nimport { SubjectSubscription } from './SubjectSubscription';\n/**\n * A variant of Subject that \"replays\" or emits old values to new subscribers.\n * It buffers a set number of values and will emit those values immediately to\n * any new subscribers in addition to emitting new values to existing subscribers.\n *\n * @class ReplaySubject\n */\nexport class ReplaySubject extends Subject {\n private _events: (ReplayEvent | T)[] = [];\n private _bufferSize: number;\n private _windowTime: number;\n private _infiniteTimeWindow: boolean = false;\n\n constructor(bufferSize: number = Number.POSITIVE_INFINITY,\n windowTime: number = Number.POSITIVE_INFINITY,\n private scheduler?: SchedulerLike) {\n super();\n this._bufferSize = bufferSize < 1 ? 1 : bufferSize;\n this._windowTime = windowTime < 1 ? 1 : windowTime;\n\n if (windowTime === Number.POSITIVE_INFINITY) {\n this._infiniteTimeWindow = true;\n this.next = this.nextInfiniteTimeWindow;\n } else {\n this.next = this.nextTimeWindow;\n }\n }\n\n private nextInfiniteTimeWindow(value: T): void {\n if (!this.isStopped) {\n const _events = this._events;\n _events.push(value);\n // Since this method is invoked in every next() call than the buffer\n // can overgrow the max size only by one item\n if (_events.length > this._bufferSize) {\n _events.shift();\n }\n }\n super.next(value);\n }\n\n private nextTimeWindow(value: T): void {\n if (!this.isStopped) {\n this._events.push(new ReplayEvent(this._getNow(), value));\n this._trimBufferThenGetEvents();\n }\n super.next(value);\n }\n\n /** @deprecated This is an internal implementation detail, do not use. */\n _subscribe(subscriber: Subscriber): Subscription {\n // When `_infiniteTimeWindow === true` then the buffer is already trimmed\n const _infiniteTimeWindow = this._infiniteTimeWindow;\n const _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();\n const scheduler = this.scheduler;\n const len = _events.length;\n let subscription: Subscription;\n\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n } else if (this.isStopped || this.hasError) {\n subscription = Subscription.EMPTY;\n } else {\n this.observers.push(subscriber);\n subscription = new SubjectSubscription(this, subscriber);\n }\n\n if (scheduler) {\n subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));\n }\n\n if (_infiniteTimeWindow) {\n for (let i = 0; i < len && !subscriber.closed; i++) {\n subscriber.next(_events[i]);\n }\n } else {\n for (let i = 0; i < len && !subscriber.closed; i++) {\n subscriber.next((>_events[i]).value);\n }\n }\n\n if (this.hasError) {\n subscriber.error(this.thrownError);\n } else if (this.isStopped) {\n subscriber.complete();\n }\n\n return subscription;\n }\n\n _getNow(): number {\n return (this.scheduler || queue).now();\n }\n\n private _trimBufferThenGetEvents(): ReplayEvent[] {\n const now = this._getNow();\n const _bufferSize = this._bufferSize;\n const _windowTime = this._windowTime;\n const _events = []>this._events;\n\n const eventsCount = _events.length;\n let spliceCount = 0;\n\n // Trim events that fall out of the time window.\n // Start at the front of the list. Break early once\n // we encounter an event that falls within the window.\n while (spliceCount < eventsCount) {\n if ((now - _events[spliceCount].time) < _windowTime) {\n break;\n }\n spliceCount++;\n }\n\n if (eventsCount > _bufferSize) {\n spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);\n }\n\n if (spliceCount > 0) {\n _events.splice(0, spliceCount);\n }\n\n return _events;\n }\n\n}\n\nclass ReplayEvent {\n constructor(public time: number, public value: T) {\n }\n}\n","import { AsyncAction } from './AsyncAction';\nimport { AsyncScheduler } from './AsyncScheduler';\n\n/**\n *\n * Async Scheduler\n *\n * Schedule task as if you used setTimeout(task, duration)\n *\n * `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript\n * event loop queue. It is best used to delay tasks in time or to schedule tasks repeating\n * in intervals.\n *\n * If you just want to \"defer\" task, that is to perform it right after currently\n * executing synchronous code ends (commonly achieved by `setTimeout(deferredTask, 0)`),\n * better choice will be the {@link asapScheduler} scheduler.\n *\n * ## Examples\n * Use async scheduler to delay task\n * ```ts\n * import { asyncScheduler } from 'rxjs';\n *\n * const task = () => console.log('it works!');\n *\n * asyncScheduler.schedule(task, 2000);\n *\n * // After 2 seconds logs:\n * // \"it works!\"\n * ```\n *\n * Use async scheduler to repeat task in intervals\n * ```ts\n * import { asyncScheduler } from 'rxjs';\n *\n * function task(state) {\n * console.log(state);\n * this.schedule(state + 1, 1000); // `this` references currently executing Action,\n * // which we reschedule with new state and delay\n * }\n *\n * asyncScheduler.schedule(task, 3000, 0);\n *\n * // Logs:\n * // 0 after 3s\n * // 1 after 4s\n * // 2 after 5s\n * // 3 after 6s\n * ```\n */\nexport const asyncScheduler = new AsyncScheduler(AsyncAction);\n\n/**\n * @deprecated renamed. Use {@link asyncScheduler}\n */\nexport const async = asyncScheduler;","export interface ArgumentOutOfRangeError extends Error {\n}\n\nexport interface ArgumentOutOfRangeErrorCtor {\n new(): ArgumentOutOfRangeError;\n}\n\nconst ArgumentOutOfRangeErrorImpl = (() => {\n function ArgumentOutOfRangeErrorImpl(this: any) {\n Error.call(this);\n this.message = 'argument out of range';\n this.name = 'ArgumentOutOfRangeError';\n return this;\n }\n\n ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);\n\n return ArgumentOutOfRangeErrorImpl;\n})();\n\n/**\n * An error thrown when an element was queried at a certain index of an\n * Observable, but no such index or position exists in that sequence.\n *\n * @see {@link elementAt}\n * @see {@link take}\n * @see {@link takeLast}\n *\n * @class ArgumentOutOfRangeError\n */\nexport const ArgumentOutOfRangeError: ArgumentOutOfRangeErrorCtor = ArgumentOutOfRangeErrorImpl as any;","export interface EmptyError extends Error {\n}\n\nexport interface EmptyErrorCtor {\n new(): EmptyError;\n}\n\nconst EmptyErrorImpl = (() => {\n function EmptyErrorImpl(this: any) {\n Error.call(this);\n this.message = 'no elements in sequence';\n this.name = 'EmptyError';\n return this;\n }\n\n EmptyErrorImpl.prototype = Object.create(Error.prototype);\n\n return EmptyErrorImpl;\n})();\n\n/**\n * An error thrown when an Observable or a sequence was queried but has no\n * elements.\n *\n * @see {@link first}\n * @see {@link last}\n * @see {@link single}\n *\n * @class EmptyError\n */\nexport const EmptyError: EmptyErrorCtor = EmptyErrorImpl as any;","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable } from '../Observable';\nimport { OperatorFunction } from '../types';\n\n/**\n * Applies a given `project` function to each value emitted by the source\n * Observable, and emits the resulting values as an Observable.\n *\n * Like [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map),\n * it passes each source value through a transformation function to get\n * corresponding output values.\n *\n * ![](map.png)\n *\n * Similar to the well known `Array.prototype.map` function, this operator\n * applies a projection to each value and emits that projection in the output\n * Observable.\n *\n * ## Example\n * Map every click to the clientX position of that click\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { map } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const positions = clicks.pipe(map(ev => ev.clientX));\n * positions.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link mapTo}\n * @see {@link pluck}\n *\n * @param {function(value: T, index: number): R} project The function to apply\n * to each `value` emitted by the source Observable. The `index` parameter is\n * the number `i` for the i-th emission that has happened since the\n * subscription, starting from the number `0`.\n * @param {any} [thisArg] An optional argument to define what `this` is in the\n * `project` function.\n * @return {Observable} An Observable that emits the values from the source\n * Observable transformed by the given `project` function.\n * @method map\n * @owner Observable\n */\nexport function map(project: (value: T, index: number) => R, thisArg?: any): OperatorFunction {\n return function mapOperation(source: Observable): Observable {\n if (typeof project !== 'function') {\n throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');\n }\n return source.lift(new MapOperator(project, thisArg));\n };\n}\n\nexport class MapOperator implements Operator {\n constructor(private project: (value: T, index: number) => R, private thisArg: any) {\n }\n\n call(subscriber: Subscriber, source: any): any {\n return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass MapSubscriber extends Subscriber {\n count: number = 0;\n private thisArg: any;\n\n constructor(destination: Subscriber,\n private project: (value: T, index: number) => R,\n thisArg: any) {\n super(destination);\n this.thisArg = thisArg || this;\n }\n\n // NOTE: This looks unoptimized, but it's actually purposefully NOT\n // using try/catch optimizations.\n protected _next(value: T) {\n let result: R;\n try {\n result = this.project.call(this.thisArg, value, this.count++);\n } catch (err) {\n this.destination.error(err);\n return;\n }\n this.destination.next(result);\n }\n}\n","import { Subscriber } from './Subscriber';\nimport { InnerSubscriber } from './InnerSubscriber';\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class OuterSubscriber extends Subscriber {\n notifyNext(outerValue: T, innerValue: R,\n outerIndex: number, innerIndex: number,\n innerSub: InnerSubscriber): void {\n this.destination.next(innerValue);\n }\n\n notifyError(error: any, innerSub: InnerSubscriber): void {\n this.destination.error(error);\n }\n\n notifyComplete(innerSub: InnerSubscriber): void {\n this.destination.complete();\n }\n}\n","import { Subscriber } from './Subscriber';\nimport { OuterSubscriber } from './OuterSubscriber';\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class InnerSubscriber extends Subscriber {\n private index = 0;\n\n constructor(private parent: OuterSubscriber, public outerValue: T, public outerIndex: number) {\n super();\n }\n\n protected _next(value: R): void {\n this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this);\n }\n\n protected _error(error: any): void {\n this.parent.notifyError(error, this);\n this.unsubscribe();\n }\n\n protected _complete(): void {\n this.parent.notifyComplete(this);\n this.unsubscribe();\n }\n}\n","export function getSymbolIterator(): symbol {\n if (typeof Symbol !== 'function' || !Symbol.iterator) {\n return '@@iterator' as any;\n }\n\n return Symbol.iterator;\n}\n\nexport const iterator = getSymbolIterator();\n\n/**\n * @deprecated use {@link iterator} instead\n */\nexport const $$iterator = iterator;\n","/**\n * Tests to see if the object is an ES2015 (ES6) Promise\n * @see {@link https://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects}\n * @param value the object to test\n */\nexport function isPromise(value: any): value is PromiseLike {\n return !!value && typeof (value).subscribe !== 'function' && typeof (value as any).then === 'function';\n}\n","import { ObservableInput } from '../types';\nimport { subscribeToArray } from './subscribeToArray';\nimport { subscribeToPromise } from './subscribeToPromise';\nimport { subscribeToIterable } from './subscribeToIterable';\nimport { subscribeToObservable } from './subscribeToObservable';\nimport { isArrayLike } from './isArrayLike';\nimport { isPromise } from './isPromise';\nimport { isObject } from './isObject';\nimport { iterator as Symbol_iterator } from '../symbol/iterator';\nimport { observable as Symbol_observable } from '../symbol/observable';\nimport { Subscription } from '../Subscription';\nimport { Subscriber } from '../Subscriber';\n\nexport const subscribeTo = (result: ObservableInput): (subscriber: Subscriber) => Subscription | void => {\n if (!!result && typeof result[Symbol_observable] === 'function') {\n return subscribeToObservable(result as any);\n } else if (isArrayLike(result)) {\n return subscribeToArray(result);\n } else if (isPromise(result)) {\n return subscribeToPromise(result as Promise);\n } else if (!!result && typeof result[Symbol_iterator] === 'function') {\n return subscribeToIterable(result as any);\n } else {\n const value = isObject(result) ? 'an invalid object' : `'${result}'`;\n const msg = `You provided ${value} where a stream was expected.`\n + ' You can provide an Observable, Promise, Array, or Iterable.';\n throw new TypeError(msg);\n }\n};\n","import { Subscriber } from '../Subscriber';\nimport { observable as Symbol_observable } from '../symbol/observable';\n\n/**\n * Subscribes to an object that implements Symbol.observable with the given\n * Subscriber.\n * @param obj An object that implements Symbol.observable\n */\nexport const subscribeToObservable = (obj: any) => (subscriber: Subscriber) => {\n const obs = obj[Symbol_observable]();\n if (typeof obs.subscribe !== 'function') {\n // Should be caught by observable subscribe function error handling.\n throw new TypeError('Provided object does not correctly implement Symbol.observable');\n } else {\n return obs.subscribe(subscriber);\n }\n};\n","import { Subscriber } from '../Subscriber';\nimport { hostReportError } from './hostReportError';\n\nexport const subscribeToPromise = (promise: PromiseLike) => (subscriber: Subscriber) => {\n promise.then(\n (value) => {\n if (!subscriber.closed) {\n subscriber.next(value);\n subscriber.complete();\n }\n },\n (err: any) => subscriber.error(err)\n )\n .then(null, hostReportError);\n return subscriber;\n};\n","import { Subscriber } from '../Subscriber';\nimport { iterator as Symbol_iterator } from '../symbol/iterator';\n\nexport const subscribeToIterable = (iterable: Iterable) => (subscriber: Subscriber) => {\n const iterator = (iterable as any)[Symbol_iterator]();\n\n do {\n let item: IteratorResult;\n try {\n item = iterator.next();\n } catch (err) {\n subscriber.error(err);\n return subscriber;\n }\n if (item.done) {\n subscriber.complete();\n break;\n }\n subscriber.next(item.value);\n if (subscriber.closed) {\n break;\n }\n } while (true);\n\n // Finalize the iterator if it happens to be a Generator\n if (typeof iterator.return === 'function') {\n subscriber.add(() => {\n if (iterator.return) {\n iterator.return();\n }\n });\n }\n\n return subscriber;\n};\n","import { Subscription } from '../Subscription';\nimport { InnerSubscriber } from '../InnerSubscriber';\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { Subscriber } from '../Subscriber';\nimport { subscribeTo } from './subscribeTo';\nimport { Observable } from '../Observable';\n\nexport function subscribeToResult(\n outerSubscriber: OuterSubscriber,\n result: any,\n outerValue: undefined,\n outerIndex: undefined,\n innerSubscriber: InnerSubscriber\n): Subscription | undefined;\n\nexport function subscribeToResult(\n outerSubscriber: OuterSubscriber,\n result: any,\n outerValue?: T,\n outerIndex?: number\n): Subscription | undefined;\n\nexport function subscribeToResult(\n outerSubscriber: OuterSubscriber,\n result: any,\n outerValue?: T,\n outerIndex?: number,\n innerSubscriber: Subscriber = new InnerSubscriber(outerSubscriber, outerValue, outerIndex)\n): Subscription | undefined {\n if (innerSubscriber.closed) {\n return undefined;\n }\n if (result instanceof Observable) {\n return result.subscribe(innerSubscriber);\n }\n return subscribeTo(result)(innerSubscriber) as Subscription;\n}\n","import { Observable } from '../Observable';\nimport { ObservableInput, SchedulerLike, ObservedValueOf } from '../types';\nimport { isScheduler } from '../util/isScheduler';\nimport { isArray } from '../util/isArray';\nimport { Subscriber } from '../Subscriber';\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { Operator } from '../Operator';\nimport { InnerSubscriber } from '../InnerSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { fromArray } from './fromArray';\n\nconst NONE = {};\n\n/* tslint:disable:max-line-length */\n\n// If called with a single array, it \"auto-spreads\" the array, with result selector\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, R>(sources: [O1], resultSelector: (v1: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, R>(sources: [O1, O2], resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, R>(sources: [O1, O2, O3], resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, R>(sources: [O1, O2, O3, O4], resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, R>(sources: [O1, O2, O3, O4, O5], resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf, v5: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput, R>(sources: [O1, O2, O3, O4, O5, O6], resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf, v5: ObservedValueOf, v6: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, R>(sources: O[], resultSelector: (...args: ObservedValueOf[]) => R, scheduler?: SchedulerLike): Observable;\n\n// standard call, but with a result selector\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, R>(v1: O1, resultSelector: (v1: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, R>(v1: O1, v2: O2, resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, R>(v1: O1, v2: O2, v3: O3, resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, R>(v1: O1, v2: O2, v3: O3, v4: O4, resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, R>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf, v5: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput, R>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, resultSelector: (v1: ObservedValueOf, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf, v5: ObservedValueOf, v6: ObservedValueOf) => R, scheduler?: SchedulerLike): Observable;\n\n// With a scheduler (deprecated)\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest>(sources: [O1], scheduler: SchedulerLike): Observable<[ObservedValueOf]>;\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest, O2 extends ObservableInput>(sources: [O1, O2], scheduler: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput>(sources: [O1, O2, O3], scheduler: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(sources: [O1, O2, O3, O4], scheduler: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(sources: [O1, O2, O3, O4, O5], scheduler: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(sources: [O1, O2, O3, O4, O5, O6], scheduler: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest>(sources: O[], scheduler: SchedulerLike): Observable[]>;\n\n// Best case\nexport function combineLatest>(sources: [O1]): Observable<[ObservedValueOf]>;\nexport function combineLatest, O2 extends ObservableInput>(sources: [O1, O2]): Observable<[ObservedValueOf, ObservedValueOf]>;\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput>(sources: [O1, O2, O3]): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(sources: [O1, O2, O3, O4]): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(sources: [O1, O2, O3, O4, O5]): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(sources: [O1, O2, O3, O4, O5, O6]): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\nexport function combineLatest>(sources: O[]): Observable[]>;\n\n// Standard calls\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest>(v1: O1, scheduler?: SchedulerLike): Observable<[ObservedValueOf]>;\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest, O2 extends ObservableInput>(v1: O1, v2: O2, scheduler?: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput>(v1: O1, v2: O2, v3: O3, scheduler?: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, scheduler?: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, scheduler?: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, scheduler?: SchedulerLike): Observable<[ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf, ObservedValueOf]>;\n\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest>(...observables: O[]): Observable;\n\n/** @deprecated Pass arguments in a single array instead `combineLatest([a, b, c])` */\nexport function combineLatest, R>(...observables: Array | ((...values: Array) => R)>): Observable;\n\n/** @deprecated resultSelector no longer supported, pipe to map instead */\nexport function combineLatest, R>(array: O[], resultSelector: (...values: ObservedValueOf[]) => R, scheduler?: SchedulerLike): Observable;\n\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest>(...observables: Array): Observable;\n\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest, R>(...observables: Array[]) => R) | SchedulerLike>): Observable;\n\n/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */\nexport function combineLatest(...observables: Array | ((...values: Array) => R) | SchedulerLike>): Observable;\n/* tslint:enable:max-line-length */\n\n/**\n * Combines multiple Observables to create an Observable whose values are\n * calculated from the latest values of each of its input Observables.\n *\n * Whenever any input Observable emits a value, it\n * computes a formula using the latest values from all the inputs, then emits\n * the output of that formula.\n *\n * ![](combineLatest.png)\n *\n * `combineLatest` combines the values from all the Observables passed as\n * arguments. This is done by subscribing to each Observable in order and,\n * whenever any Observable emits, collecting an array of the most recent\n * values from each Observable. So if you pass `n` Observables to operator,\n * returned Observable will always emit an array of `n` values, in order\n * corresponding to order of passed Observables (value from the first Observable\n * on the first place and so on).\n *\n * Static version of `combineLatest` accepts either an array of Observables\n * or each Observable can be put directly as an argument. Note that array of\n * Observables is good choice, if you don't know beforehand how many Observables\n * you will combine. Passing empty array will result in Observable that\n * completes immediately.\n *\n * To ensure output array has always the same length, `combineLatest` will\n * actually wait for all input Observables to emit at least once,\n * before it starts emitting results. This means if some Observable emits\n * values before other Observables started emitting, all these values but the last\n * will be lost. On the other hand, if some Observable does not emit a value but\n * completes, resulting Observable will complete at the same moment without\n * emitting anything, since it will be now impossible to include value from\n * completed Observable in resulting array. Also, if some input Observable does\n * not emit any value and never completes, `combineLatest` will also never emit\n * and never complete, since, again, it will wait for all streams to emit some\n * value.\n *\n * If at least one Observable was passed to `combineLatest` and all passed Observables\n * emitted something, resulting Observable will complete when all combined\n * streams complete. So even if some Observable completes, result of\n * `combineLatest` will still emit values when other Observables do. In case\n * of completed Observable, its value from now on will always be the last\n * emitted value. On the other hand, if any Observable errors, `combineLatest`\n * will error immediately as well, and all other Observables will be unsubscribed.\n *\n * `combineLatest` accepts as optional parameter `project` function, which takes\n * as arguments all values that would normally be emitted by resulting Observable.\n * `project` can return any kind of value, which will be then emitted by Observable\n * instead of default array. Note that `project` does not take as argument that array\n * of values, but values themselves. That means default `project` can be imagined\n * as function that takes all its arguments and puts them into an array.\n *\n * ## Examples\n * ### Combine two timer Observables\n * ```ts\n * import { combineLatest, timer } from 'rxjs';\n *\n * const firstTimer = timer(0, 1000); // emit 0, 1, 2... after every second, starting from now\n * const secondTimer = timer(500, 1000); // emit 0, 1, 2... after every second, starting 0,5s from now\n * const combinedTimers = combineLatest(firstTimer, secondTimer);\n * combinedTimers.subscribe(value => console.log(value));\n * // Logs\n * // [0, 0] after 0.5s\n * // [1, 0] after 1s\n * // [1, 1] after 1.5s\n * // [2, 1] after 2s\n * ```\n *\n * ### Combine an array of Observables\n * ```ts\n * import { combineLatest, of } from 'rxjs';\n * import { delay, starWith } from 'rxjs/operators';\n *\n * const observables = [1, 5, 10].map(\n * n => of(n).pipe(\n * delay(n * 1000), // emit 0 and then emit n after n seconds\n * startWith(0),\n * )\n * );\n * const combined = combineLatest(observables);\n * combined.subscribe(value => console.log(value));\n * // Logs\n * // [0, 0, 0] immediately\n * // [1, 0, 0] after 1s\n * // [1, 5, 0] after 5s\n * // [1, 5, 10] after 10s\n * ```\n *\n *\n * ### Use project function to dynamically calculate the Body-Mass Index\n * ```ts\n * import { combineLatest, of } from 'rxjs';\n * import { map } from 'rxjs/operators';\n *\n * const weight = of(70, 72, 76, 79, 75);\n * const height = of(1.76, 1.77, 1.78);\n * const bmi = combineLatest(weight, height).pipe(\n * map(([w, h]) => w / (h * h)),\n * );\n * bmi.subscribe(x => console.log('BMI is ' + x));\n *\n * // With output to console:\n * // BMI is 24.212293388429753\n * // BMI is 23.93948099205209\n * // BMI is 23.671253629592222\n * ```\n *\n * @see {@link combineAll}\n * @see {@link merge}\n * @see {@link withLatestFrom}\n *\n * @param {ObservableInput} observable1 An input Observable to combine with other Observables.\n * @param {ObservableInput} observable2 An input Observable to combine with other Observables.\n * More than one input Observables may be given as arguments\n * or an array of Observables may be given as the first argument.\n * @param {function} [project] An optional function to project the values from\n * the combined latest values into a new value on the output Observable.\n * @param {SchedulerLike} [scheduler=null] The {@link SchedulerLike} to use for subscribing to\n * each input Observable.\n * @return {Observable} An Observable of projected values from the most recent\n * values from each input Observable, or an array of the most recent values from\n * each input Observable.\n */\nexport function combineLatest, R>(\n ...observables: (O | ((...values: ObservedValueOf[]) => R) | SchedulerLike)[]\n): Observable {\n let resultSelector: ((...values: Array) => R) | undefined = undefined;\n let scheduler: SchedulerLike|undefined = undefined;\n\n if (isScheduler(observables[observables.length - 1])) {\n scheduler = observables.pop() as SchedulerLike;\n }\n\n if (typeof observables[observables.length - 1] === 'function') {\n resultSelector = observables.pop() as (...values: Array) => R;\n }\n\n // if the first and only other argument besides the resultSelector is an array\n // assume it's been called with `combineLatest([obs1, obs2, obs3], resultSelector)`\n if (observables.length === 1 && isArray(observables[0])) {\n observables = observables[0] as any;\n }\n\n return fromArray(observables, scheduler).lift(new CombineLatestOperator(resultSelector));\n}\n\nexport class CombineLatestOperator implements Operator {\n constructor(private resultSelector?: (...values: Array) => R) {\n }\n\n call(subscriber: Subscriber, source: any): any {\n return source.subscribe(new CombineLatestSubscriber(subscriber, this.resultSelector));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class CombineLatestSubscriber extends OuterSubscriber {\n private active: number = 0;\n private values: any[] = [];\n private observables: any[] = [];\n private toRespond?: number;\n\n constructor(destination: Subscriber, private resultSelector?: (...values: Array) => R) {\n super(destination);\n }\n\n protected _next(observable: any) {\n this.values.push(NONE);\n this.observables.push(observable);\n }\n\n protected _complete() {\n const observables = this.observables;\n const len = observables.length;\n if (len === 0) {\n this.destination.complete!();\n } else {\n this.active = len;\n this.toRespond = len;\n for (let i = 0; i < len; i++) {\n const observable = observables[i];\n this.add(subscribeToResult(this, observable, undefined, i));\n }\n }\n }\n\n notifyComplete(unused: Subscriber): void {\n if ((this.active -= 1) === 0) {\n this.destination.complete!();\n }\n }\n\n notifyNext(_outerValue: T, innerValue: R,\n outerIndex: number): void {\n const values = this.values;\n const oldVal = values[outerIndex];\n const toRespond = !this.toRespond\n ? 0\n : oldVal === NONE ? --this.toRespond : this.toRespond;\n values[outerIndex] = innerValue;\n\n if (toRespond === 0) {\n if (this.resultSelector) {\n this._tryResultSelector(values);\n } else {\n this.destination.next!(values.slice());\n }\n }\n }\n\n private _tryResultSelector(values: any[]) {\n let result: any;\n try {\n result = this.resultSelector!.apply(this, values);\n } catch (err) {\n this.destination.error!(err);\n return;\n }\n this.destination.next!(result);\n }\n}\n","import { scheduleObservable } from './scheduleObservable';\nimport { schedulePromise } from './schedulePromise';\nimport { scheduleArray } from './scheduleArray';\nimport { scheduleIterable } from './scheduleIterable';\nimport { ObservableInput, SchedulerLike, Observable } from 'rxjs';\nimport { isInteropObservable } from '../util/isInteropObservable';\nimport { isPromise } from '../util/isPromise';\nimport { isArrayLike } from '../util/isArrayLike';\nimport { isIterable } from '../util/isIterable';\n\n/**\n * Converts from a common {@link ObservableInput} type to an observable where subscription and emissions\n * are scheduled on the provided scheduler.\n *\n * @see from\n * @see of\n *\n * @param input The observable, array, promise, iterable, etc you would like to schedule\n * @param scheduler The scheduler to use to schedule the subscription and emissions from\n * the returned observable.\n */\nexport function scheduled(input: ObservableInput, scheduler: SchedulerLike): Observable {\n if (input != null) {\n if (isInteropObservable(input)) {\n return scheduleObservable(input, scheduler);\n } else if (isPromise(input)) {\n return schedulePromise(input, scheduler);\n } else if (isArrayLike(input)) {\n return scheduleArray(input, scheduler);\n } else if (isIterable(input) || typeof input === 'string') {\n return scheduleIterable(input, scheduler);\n }\n }\n\n throw new TypeError((input !== null && typeof input || input) + ' is not observable');\n}\n","import { InteropObservable } from '../types';\nimport { observable as Symbol_observable } from '../symbol/observable';\n\n/** Identifies an input as being Observable (but not necessary an Rx Observable) */\nexport function isInteropObservable(input: any): input is InteropObservable {\n return input && typeof input[Symbol_observable] === 'function';\n}\n","import { Observable } from '../Observable';\nimport { Subscription } from '../Subscription';\nimport { observable as Symbol_observable } from '../symbol/observable';\nimport { InteropObservable, SchedulerLike, Subscribable } from '../types';\n\nexport function scheduleObservable(input: InteropObservable, scheduler: SchedulerLike) {\n return new Observable(subscriber => {\n const sub = new Subscription();\n sub.add(scheduler.schedule(() => {\n const observable: Subscribable = input[Symbol_observable]();\n sub.add(observable.subscribe({\n next(value) { sub.add(scheduler.schedule(() => subscriber.next(value))); },\n error(err) { sub.add(scheduler.schedule(() => subscriber.error(err))); },\n complete() { sub.add(scheduler.schedule(() => subscriber.complete())); },\n }));\n }));\n return sub;\n });\n}\n","import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\nimport { Subscription } from '../Subscription';\n\nexport function schedulePromise(input: PromiseLike, scheduler: SchedulerLike) {\n return new Observable(subscriber => {\n const sub = new Subscription();\n sub.add(scheduler.schedule(() => input.then(\n value => {\n sub.add(scheduler.schedule(() => {\n subscriber.next(value);\n sub.add(scheduler.schedule(() => subscriber.complete()));\n }));\n },\n err => {\n sub.add(scheduler.schedule(() => subscriber.error(err)));\n }\n )));\n return sub;\n });\n}\n","import { iterator as Symbol_iterator } from '../symbol/iterator';\n\n/** Identifies an input as being an Iterable */\nexport function isIterable(input: any): input is Iterable {\n return input && typeof input[Symbol_iterator] === 'function';\n}\n","import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\nimport { Subscription } from '../Subscription';\nimport { iterator as Symbol_iterator } from '../symbol/iterator';\n\nexport function scheduleIterable(input: Iterable, scheduler: SchedulerLike) {\n if (!input) {\n throw new Error('Iterable cannot be null');\n }\n return new Observable(subscriber => {\n const sub = new Subscription();\n let iterator: Iterator;\n sub.add(() => {\n // Finalize generators\n if (iterator && typeof iterator.return === 'function') {\n iterator.return();\n }\n });\n sub.add(scheduler.schedule(() => {\n iterator = input[Symbol_iterator]();\n sub.add(scheduler.schedule(function () {\n if (subscriber.closed) {\n return;\n }\n let value: T;\n let done: boolean;\n try {\n const result = iterator.next();\n value = result.value;\n done = result.done;\n } catch (err) {\n subscriber.error(err);\n return;\n }\n if (done) {\n subscriber.complete();\n } else {\n subscriber.next(value);\n this.schedule();\n }\n }));\n }));\n return sub;\n });\n}\n","import { Observable } from '../Observable';\nimport { subscribeTo } from '../util/subscribeTo';\nimport { ObservableInput, SchedulerLike, ObservedValueOf } from '../types';\nimport { scheduled } from '../scheduled/scheduled';\n\nexport function from>(input: O): Observable>;\n/** @deprecated use {@link scheduled} instead. */\nexport function from>(input: O, scheduler: SchedulerLike): Observable>;\n\n/**\n * Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object.\n *\n * Converts almost anything to an Observable.\n *\n * ![](from.png)\n *\n * `from` converts various other objects and data types into Observables. It also converts a Promise, an array-like, or an\n * iterable\n * object into an Observable that emits the items in that promise, array, or iterable. A String, in this context, is treated\n * as an array of characters. Observable-like objects (contains a function named with the ES2015 Symbol for Observable) can also be\n * converted through this operator.\n *\n * ## Examples\n *\n * ### Converts an array to an Observable\n *\n * ```ts\n * import { from } from 'rxjs';\n *\n * const array = [10, 20, 30];\n * const result = from(array);\n *\n * result.subscribe(x => console.log(x));\n *\n * // Logs:\n * // 10\n * // 20\n * // 30\n * ```\n *\n * ---\n *\n * ### Convert an infinite iterable (from a generator) to an Observable\n *\n * ```ts\n * import { from } from 'rxjs';\n * import { take } from 'rxjs/operators';\n *\n * function* generateDoubles(seed) {\n * let i = seed;\n * while (true) {\n * yield i;\n * i = 2 * i; // double it\n * }\n * }\n *\n * const iterator = generateDoubles(3);\n * const result = from(iterator).pipe(take(10));\n *\n * result.subscribe(x => console.log(x));\n *\n * // Logs:\n * // 3\n * // 6\n * // 12\n * // 24\n * // 48\n * // 96\n * // 192\n * // 384\n * // 768\n * // 1536\n * ```\n *\n * ---\n *\n * ### With async scheduler\n *\n * ```ts\n * import { from, asyncScheduler } from 'rxjs';\n *\n * console.log('start');\n *\n * const array = [10, 20, 30];\n * const result = from(array, asyncScheduler);\n *\n * result.subscribe(x => console.log(x));\n *\n * console.log('end');\n *\n * // Logs:\n * // start\n * // end\n * // 10\n * // 20\n * // 30\n * ```\n *\n * @see {@link fromEvent}\n * @see {@link fromEventPattern}\n *\n * @param {ObservableInput} A subscription object, a Promise, an Observable-like,\n * an Array, an iterable, or an array-like object to be converted.\n * @param {SchedulerLike} An optional {@link SchedulerLike} on which to schedule the emission of values.\n * @return {Observable}\n * @name from\n * @owner Observable\n */\nexport function from(input: ObservableInput, scheduler?: SchedulerLike): Observable {\n if (!scheduler) {\n if (input instanceof Observable) {\n return input;\n }\n return new Observable(subscribeTo(input));\n } else {\n return scheduled(input, scheduler);\n }\n}\n","/** @prettier */\nimport { Subscription } from './Subscription';\nimport { Subscriber } from './Subscriber';\nimport { Observable } from './Observable';\nimport { subscribeTo } from './util/subscribeTo';\n\ninterface SimpleOuterSubscriberLike {\n /**\n * A handler for inner next notifications from the inner subscription\n * @param innerValue the value nexted by the inner producer\n */\n notifyNext(innerValue: T): void;\n /**\n * A handler for inner error notifications from the inner subscription\n * @param err the error from the inner producer\n */\n notifyError(err: any): void;\n /**\n * A handler for inner complete notifications from the inner subscription.\n */\n notifyComplete(): void;\n}\n\nexport class SimpleInnerSubscriber extends Subscriber {\n constructor(private parent: SimpleOuterSubscriberLike) {\n super();\n }\n\n protected _next(value: T): void {\n this.parent.notifyNext(value);\n }\n\n protected _error(error: any): void {\n this.parent.notifyError(error);\n this.unsubscribe();\n }\n\n protected _complete(): void {\n this.parent.notifyComplete();\n this.unsubscribe();\n }\n}\n\nexport class ComplexInnerSubscriber extends Subscriber {\n constructor(private parent: ComplexOuterSubscriber, public outerValue: T, public outerIndex: number) {\n super();\n }\n\n protected _next(value: R): void {\n this.parent.notifyNext(this.outerValue, value, this.outerIndex, this);\n }\n\n protected _error(error: any): void {\n this.parent.notifyError(error);\n this.unsubscribe();\n }\n\n protected _complete(): void {\n this.parent.notifyComplete(this);\n this.unsubscribe();\n }\n}\n\nexport class SimpleOuterSubscriber extends Subscriber implements SimpleOuterSubscriberLike {\n notifyNext(innerValue: R): void {\n this.destination.next(innerValue);\n }\n\n notifyError(err: any): void {\n this.destination.error(err);\n }\n\n notifyComplete(): void {\n this.destination.complete();\n }\n}\n\n/**\n * DO NOT USE (formerly \"OuterSubscriber\")\n * TODO: We want to refactor this and remove it. It is retaining values it shouldn't for long\n * periods of time.\n */\nexport class ComplexOuterSubscriber extends Subscriber {\n /**\n * @param _outerValue Used by: bufferToggle, delayWhen, windowToggle\n * @param innerValue Used by: subclass default, combineLatest, race, bufferToggle, windowToggle, withLatestFrom\n * @param _outerIndex Used by: combineLatest, race, withLatestFrom\n * @param _innerSub Used by: delayWhen\n */\n notifyNext(_outerValue: T, innerValue: R, _outerIndex: number, _innerSub: ComplexInnerSubscriber): void {\n this.destination.next(innerValue);\n }\n\n notifyError(error: any): void {\n this.destination.error(error);\n }\n\n /**\n * @param _innerSub Used by: race, bufferToggle, delayWhen, windowToggle, windowWhen\n */\n notifyComplete(_innerSub: ComplexInnerSubscriber): void {\n this.destination.complete();\n }\n}\n\nexport function innerSubscribe(result: any, innerSubscriber: Subscriber): Subscription | undefined {\n if (innerSubscriber.closed) {\n return undefined;\n }\n if (result instanceof Observable) {\n return result.subscribe(innerSubscriber);\n }\n let subscription: Subscription;\n try {\n subscription = subscribeTo(result)(innerSubscriber) as Subscription;\n } catch (error) {\n innerSubscriber.error(error);\n }\n return subscription;\n}\n","import { Observable } from '../Observable';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';\nimport { map } from './map';\nimport { from } from '../observable/from';\nimport { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';\n\n/* tslint:disable:max-line-length */\nexport function mergeMap>(project: (value: T, index: number) => O, concurrent?: number): OperatorFunction>;\n/** @deprecated resultSelector no longer supported, use inner map instead */\nexport function mergeMap>(project: (value: T, index: number) => O, resultSelector: undefined, concurrent?: number): OperatorFunction>;\n/** @deprecated resultSelector no longer supported, use inner map instead */\nexport function mergeMap>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Projects each source value to an Observable which is merged in the output\n * Observable.\n *\n * Maps each value to an Observable, then flattens all of\n * these inner Observables using {@link mergeAll}.\n *\n * ![](mergeMap.png)\n *\n * Returns an Observable that emits items based on applying a function that you\n * supply to each item emitted by the source Observable, where that function\n * returns an Observable, and then merging those resulting Observables and\n * emitting the results of this merger.\n *\n * ## Example\n * Map and flatten each letter to an Observable ticking every 1 second\n * ```ts\n * import { of, interval } from 'rxjs';\n * import { mergeMap, map } from 'rxjs/operators';\n *\n * const letters = of('a', 'b', 'c');\n * const result = letters.pipe(\n * mergeMap(x => interval(1000).pipe(map(i => x+i))),\n * );\n * result.subscribe(x => console.log(x));\n *\n * // Results in the following:\n * // a0\n * // b0\n * // c0\n * // a1\n * // b1\n * // c1\n * // continues to list a,b,c with respective ascending integers\n * ```\n *\n * @see {@link concatMap}\n * @see {@link exhaustMap}\n * @see {@link merge}\n * @see {@link mergeAll}\n * @see {@link mergeMapTo}\n * @see {@link mergeScan}\n * @see {@link switchMap}\n *\n * @param {function(value: T, ?index: number): ObservableInput} project A function\n * that, when applied to an item emitted by the source Observable, returns an\n * Observable.\n * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input\n * Observables being subscribed to concurrently.\n * @return {Observable} An Observable that emits the result of applying the\n * projection function (and the optional deprecated `resultSelector`) to each item\n * emitted by the source Observable and merging the results of the Observables\n * obtained from this transformation.\n */\nexport function mergeMap>(\n project: (value: T, index: number) => O,\n resultSelector?: ((outerValue: T, innerValue: ObservedValueOf, outerIndex: number, innerIndex: number) => R) | number,\n concurrent: number = Number.POSITIVE_INFINITY\n): OperatorFunction|R> {\n if (typeof resultSelector === 'function') {\n // DEPRECATED PATH\n return (source: Observable) => source.pipe(\n mergeMap((a, i) => from(project(a, i)).pipe(\n map((b: any, ii: number) => resultSelector(a, b, i, ii)),\n ), concurrent)\n );\n } else if (typeof resultSelector === 'number') {\n concurrent = resultSelector;\n }\n return (source: Observable) => source.lift(new MergeMapOperator(project, concurrent));\n}\n\nexport class MergeMapOperator implements Operator {\n constructor(private project: (value: T, index: number) => ObservableInput,\n private concurrent: number = Number.POSITIVE_INFINITY) {\n }\n\n call(observer: Subscriber, source: any): any {\n return source.subscribe(new MergeMapSubscriber(\n observer, this.project, this.concurrent\n ));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class MergeMapSubscriber extends SimpleOuterSubscriber {\n private hasCompleted: boolean = false;\n private buffer: T[] = [];\n private active: number = 0;\n protected index: number = 0;\n\n constructor(destination: Subscriber,\n private project: (value: T, index: number) => ObservableInput,\n private concurrent: number = Number.POSITIVE_INFINITY) {\n super(destination);\n }\n\n protected _next(value: T): void {\n if (this.active < this.concurrent) {\n this._tryNext(value);\n } else {\n this.buffer.push(value);\n }\n }\n\n protected _tryNext(value: T) {\n let result: ObservableInput;\n const index = this.index++;\n try {\n result = this.project(value, index);\n } catch (err) {\n this.destination.error!(err);\n return;\n }\n this.active++;\n this._innerSub(result);\n }\n\n private _innerSub(ish: ObservableInput): void {\n const innerSubscriber = new SimpleInnerSubscriber(this);\n const destination = this.destination as Subscription;\n destination.add(innerSubscriber);\n const innerSubscription = innerSubscribe(ish, innerSubscriber);\n // The returned subscription will usually be the subscriber that was\n // passed. However, interop subscribers will be wrapped and for\n // unsubscriptions to chain correctly, the wrapper needs to be added, too.\n if (innerSubscription !== innerSubscriber) {\n destination.add(innerSubscription);\n }\n }\n\n protected _complete(): void {\n this.hasCompleted = true;\n if (this.active === 0 && this.buffer.length === 0) {\n this.destination.complete!();\n }\n this.unsubscribe();\n }\n\n notifyNext(innerValue: R): void {\n this.destination.next!(innerValue);\n }\n\n notifyComplete(): void {\n const buffer = this.buffer;\n this.active--;\n if (buffer.length > 0) {\n this._next(buffer.shift()!);\n } else if (this.active === 0 && this.hasCompleted) {\n this.destination.complete!();\n }\n }\n}\n\n/**\n * @deprecated renamed. Use {@link mergeMap}\n */\nexport const flatMap = mergeMap;","\nimport { mergeMap } from './mergeMap';\nimport { identity } from '../util/identity';\nimport { OperatorFunction, ObservableInput } from '../types';\n\n/**\n * Converts a higher-order Observable into a first-order Observable which\n * concurrently delivers all values that are emitted on the inner Observables.\n *\n * Flattens an Observable-of-Observables.\n *\n * ![](mergeAll.png)\n *\n * `mergeAll` subscribes to an Observable that emits Observables, also known as\n * a higher-order Observable. Each time it observes one of these emitted inner\n * Observables, it subscribes to that and delivers all the values from the\n * inner Observable on the output Observable. The output Observable only\n * completes once all inner Observables have completed. Any error delivered by\n * a inner Observable will be immediately emitted on the output Observable.\n *\n * ## Examples\n * Spawn a new interval Observable for each click event, and blend their outputs as one Observable\n * ```ts\n * import { fromEvent, interval } from 'rxjs';\n * import { map, mergeAll } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const higherOrder = clicks.pipe(map((ev) => interval(1000)));\n * const firstOrder = higherOrder.pipe(mergeAll());\n * firstOrder.subscribe(x => console.log(x));\n * ```\n *\n * Count from 0 to 9 every second for each click, but only allow 2 concurrent timers\n * ```ts\n * import { fromEvent, interval } from 'rxjs';\n * import { take, map, mergeAll } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const higherOrder = clicks.pipe(\n * map((ev) => interval(1000).pipe(take(10))),\n * );\n * const firstOrder = higherOrder.pipe(mergeAll(2));\n * firstOrder.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link combineAll}\n * @see {@link concatAll}\n * @see {@link exhaust}\n * @see {@link merge}\n * @see {@link mergeMap}\n * @see {@link mergeMapTo}\n * @see {@link mergeScan}\n * @see {@link switchAll}\n * @see {@link switchMap}\n * @see {@link zipAll}\n *\n * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of inner\n * Observables being subscribed to concurrently.\n * @return {Observable} An Observable that emits values coming from all the\n * inner Observables emitted by the source Observable.\n * @method mergeAll\n * @owner Observable\n */\nexport function mergeAll(concurrent: number = Number.POSITIVE_INFINITY): OperatorFunction, T> {\n return mergeMap(identity, concurrent);\n}\n","\nimport { mergeAll } from './mergeAll';\nimport { OperatorFunction, ObservableInput } from '../types';\n\nexport function concatAll(): OperatorFunction, T>;\nexport function concatAll(): OperatorFunction;\n\n/**\n * Converts a higher-order Observable into a first-order Observable by\n * concatenating the inner Observables in order.\n *\n * Flattens an Observable-of-Observables by putting one\n * inner Observable after the other.\n *\n * ![](concatAll.png)\n *\n * Joins every Observable emitted by the source (a higher-order Observable), in\n * a serial fashion. It subscribes to each inner Observable only after the\n * previous inner Observable has completed, and merges all of their values into\n * the returned observable.\n *\n * __Warning:__ If the source Observable emits Observables quickly and\n * endlessly, and the inner Observables it emits generally complete slower than\n * the source emits, you can run into memory issues as the incoming Observables\n * collect in an unbounded buffer.\n *\n * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set\n * to `1`.\n *\n * ## Example\n *\n * For each click event, tick every second from 0 to 3, with no concurrency\n * ```ts\n * import { fromEvent, interval } from 'rxjs';\n * import { map, take, concatAll } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const higherOrder = clicks.pipe(\n * map(ev => interval(1000).pipe(take(4))),\n * );\n * const firstOrder = higherOrder.pipe(concatAll());\n * firstOrder.subscribe(x => console.log(x));\n *\n * // Results in the following:\n * // (results are not concurrent)\n * // For every click on the \"document\" it will emit values 0 to 3 spaced\n * // on a 1000ms interval\n * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3\n * ```\n *\n * @see {@link combineAll}\n * @see {@link concat}\n * @see {@link concatMap}\n * @see {@link concatMapTo}\n * @see {@link exhaust}\n * @see {@link mergeAll}\n * @see {@link switchAll}\n * @see {@link switchMap}\n * @see {@link zipAll}\n *\n * @return {Observable} An Observable emitting values from all the inner\n * Observables concatenated.\n * @method concatAll\n * @owner Observable\n */\nexport function concatAll(): OperatorFunction, T> {\n return mergeAll(1);\n}\n","import { Observable } from '../Observable';\nimport { ObservableInput, SchedulerLike, ObservedValueOf } from '../types';\nimport { isScheduler } from '../util/isScheduler';\nimport { of } from './of';\nimport { from } from './from';\nimport { concatAll } from '../operators/concatAll';\n\n/* tslint:disable:max-line-length */\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat>(v1: O1, scheduler: SchedulerLike): Observable>;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat, O2 extends ObservableInput>(v1: O1, v2: O2, scheduler: SchedulerLike): Observable | ObservedValueOf>;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput>(v1: O1, v2: O2, v3: O3, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf>;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf>;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>;\n\nexport function concat>(v1: O1): Observable>;\nexport function concat, O2 extends ObservableInput>(v1: O1, v2: O2): Observable | ObservedValueOf>;\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput>(v1: O1, v2: O2, v3: O3): Observable | ObservedValueOf | ObservedValueOf>;\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf>;\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>;\nexport function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>;\nexport function concat>(...observables: O[]): Observable>;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat>(...observables: (O | SchedulerLike)[]): Observable>;\nexport function concat(...observables: ObservableInput[]): Observable;\n/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */\nexport function concat(...observables: (ObservableInput | SchedulerLike)[]): Observable;\n/* tslint:enable:max-line-length */\n/**\n * Creates an output Observable which sequentially emits all values from given\n * Observable and then moves on to the next.\n *\n * Concatenates multiple Observables together by\n * sequentially emitting their values, one Observable after the other.\n *\n * ![](concat.png)\n *\n * `concat` joins multiple Observables together, by subscribing to them one at a time and\n * merging their results into the output Observable. You can pass either an array of\n * Observables, or put them directly as arguments. Passing an empty array will result\n * in Observable that completes immediately.\n *\n * `concat` will subscribe to first input Observable and emit all its values, without\n * changing or affecting them in any way. When that Observable completes, it will\n * subscribe to then next Observable passed and, again, emit its values. This will be\n * repeated, until the operator runs out of Observables. When last input Observable completes,\n * `concat` will complete as well. At any given moment only one Observable passed to operator\n * emits values. If you would like to emit values from passed Observables concurrently, check out\n * {@link merge} instead, especially with optional `concurrent` parameter. As a matter of fact,\n * `concat` is an equivalent of `merge` operator with `concurrent` parameter set to `1`.\n *\n * Note that if some input Observable never completes, `concat` will also never complete\n * and Observables following the one that did not complete will never be subscribed. On the other\n * hand, if some Observable simply completes immediately after it is subscribed, it will be\n * invisible for `concat`, which will just move on to the next Observable.\n *\n * If any Observable in chain errors, instead of passing control to the next Observable,\n * `concat` will error immediately as well. Observables that would be subscribed after\n * the one that emitted error, never will.\n *\n * If you pass to `concat` the same Observable many times, its stream of values\n * will be \"replayed\" on every subscription, which means you can repeat given Observable\n * as many times as you like. If passing the same Observable to `concat` 1000 times becomes tedious,\n * you can always use {@link repeat}.\n *\n * ## Examples\n * ### Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10\n * ```ts\n * import { concat, interval, range } from 'rxjs';\n * import { take } from 'rxjs/operators';\n *\n * const timer = interval(1000).pipe(take(4));\n * const sequence = range(1, 10);\n * const result = concat(timer, sequence);\n * result.subscribe(x => console.log(x));\n *\n * // results in:\n * // 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10\n * ```\n *\n * ### Concatenate 3 Observables\n * ```ts\n * import { concat, interval } from 'rxjs';\n * import { take } from 'rxjs/operators';\n *\n * const timer1 = interval(1000).pipe(take(10));\n * const timer2 = interval(2000).pipe(take(6));\n * const timer3 = interval(500).pipe(take(10));\n *\n * const result = concat(timer1, timer2, timer3);\n * result.subscribe(x => console.log(x));\n *\n * // results in the following:\n * // (Prints to console sequentially)\n * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9\n * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5\n * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9\n * ```\n *\n * ### Concatenate the same Observable to repeat it\n * ```ts\n * import { concat, interval } from 'rxjs';\n * import { take } from 'rxjs/operators';\n *\n * const timer = interval(1000).pipe(take(2));\n *\n * concat(timer, timer) // concatenating the same Observable!\n * .subscribe(\n * value => console.log(value),\n * err => {},\n * () => console.log('...and it is done!')\n * );\n *\n * // Logs:\n * // 0 after 1s\n * // 1 after 2s\n * // 0 after 3s\n * // 1 after 4s\n * // \"...and it is done!\" also after 4s\n * ```\n *\n * @see {@link concatAll}\n * @see {@link concatMap}\n * @see {@link concatMapTo}\n * @see {@link startWith}\n * @see {@link endWith}\n *\n * @param {ObservableInput} input1 An input Observable to concatenate with others.\n * @param {ObservableInput} input2 An input Observable to concatenate with others.\n * More than one input Observables may be given as argument.\n * @param {SchedulerLike} [scheduler=null] An optional {@link SchedulerLike} to schedule each\n * Observable subscription on.\n * @return {Observable} All values of each passed Observable merged into a\n * single Observable, in order, in serial fashion.\n * @static true\n * @name concat\n * @owner Observable\n */\nexport function concat, R>(...observables: Array): Observable | R> {\n return concatAll()(of(...observables));\n}\n","import { Observable } from '../Observable';\nimport { ObservableInput, SchedulerLike} from '../types';\nimport { isScheduler } from '../util/isScheduler';\nimport { mergeAll } from '../operators/mergeAll';\nimport { fromArray } from './fromArray';\n\n/* tslint:disable:max-line-length */\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, concurrent: number, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, concurrent: number, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, concurrent: number, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, concurrent: number, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, concurrent: number, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput, scheduler: SchedulerLike): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput, concurrent: number, scheduler: SchedulerLike): Observable;\n\nexport function merge(v1: ObservableInput): Observable;\nexport function merge(v1: ObservableInput, concurrent?: number): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, concurrent?: number): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, concurrent?: number): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, concurrent?: number): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, concurrent?: number): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput): Observable;\nexport function merge(v1: ObservableInput, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput, concurrent?: number): Observable;\nexport function merge(...observables: (ObservableInput | number)[]): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(...observables: (ObservableInput | SchedulerLike | number)[]): Observable;\nexport function merge(...observables: (ObservableInput | number)[]): Observable;\n/** @deprecated use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())*/\nexport function merge(...observables: (ObservableInput | SchedulerLike | number)[]): Observable;\n/* tslint:enable:max-line-length */\n/**\n * Creates an output Observable which concurrently emits all values from every\n * given input Observable.\n *\n * Flattens multiple Observables together by blending\n * their values into one Observable.\n *\n * ![](merge.png)\n *\n * `merge` subscribes to each given input Observable (as arguments), and simply\n * forwards (without doing any transformation) all the values from all the input\n * Observables to the output Observable. The output Observable only completes\n * once all input Observables have completed. Any error delivered by an input\n * Observable will be immediately emitted on the output Observable.\n *\n * ## Examples\n * ### Merge together two Observables: 1s interval and clicks\n * ```ts\n * import { merge, fromEvent, interval } from 'rxjs';\n *\n * const clicks = fromEvent(document, 'click');\n * const timer = interval(1000);\n * const clicksOrTimer = merge(clicks, timer);\n * clicksOrTimer.subscribe(x => console.log(x));\n *\n * // Results in the following:\n * // timer will emit ascending values, one every second(1000ms) to console\n * // clicks logs MouseEvents to console everytime the \"document\" is clicked\n * // Since the two streams are merged you see these happening\n * // as they occur.\n * ```\n *\n * ### Merge together 3 Observables, but only 2 run concurrently\n * ```ts\n * import { merge, interval } from 'rxjs';\n * import { take } from 'rxjs/operators';\n *\n * const timer1 = interval(1000).pipe(take(10));\n * const timer2 = interval(2000).pipe(take(6));\n * const timer3 = interval(500).pipe(take(10));\n * const concurrent = 2; // the argument\n * const merged = merge(timer1, timer2, timer3, concurrent);\n * merged.subscribe(x => console.log(x));\n *\n * // Results in the following:\n * // - First timer1 and timer2 will run concurrently\n * // - timer1 will emit a value every 1000ms for 10 iterations\n * // - timer2 will emit a value every 2000ms for 6 iterations\n * // - after timer1 hits its max iteration, timer2 will\n * // continue, and timer3 will start to run concurrently with timer2\n * // - when timer2 hits its max iteration it terminates, and\n * // timer3 will continue to emit a value every 500ms until it is complete\n * ```\n *\n * @see {@link mergeAll}\n * @see {@link mergeMap}\n * @see {@link mergeMapTo}\n * @see {@link mergeScan}\n *\n * @param {...ObservableInput} observables Input Observables to merge together.\n * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input\n * Observables being subscribed to concurrently.\n * @param {SchedulerLike} [scheduler=null] The {@link SchedulerLike} to use for managing\n * concurrency of input Observables.\n * @return {Observable} an Observable that emits items that are the result of\n * every input Observable.\n * @static true\n * @name merge\n * @owner Observable\n */\nexport function merge(...observables: Array | SchedulerLike | number>): Observable {\n let concurrent = Number.POSITIVE_INFINITY;\n let scheduler: SchedulerLike = null;\n let last: any = observables[observables.length - 1];\n if (isScheduler(last)) {\n scheduler = observables.pop();\n if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {\n concurrent = observables.pop();\n }\n } else if (typeof last === 'number') {\n concurrent = observables.pop();\n }\n\n if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {\n return >observables[0];\n }\n\n return mergeAll(concurrent)(fromArray(observables, scheduler));\n}\n","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable } from '../Observable';\nimport { OperatorFunction, MonoTypeOperatorFunction, TeardownLogic } from '../types';\n\n/* tslint:disable:max-line-length */\nexport function filter(predicate: (value: T, index: number) => value is S,\n thisArg?: any): OperatorFunction;\nexport function filter(predicate: (value: T, index: number) => boolean,\n thisArg?: any): MonoTypeOperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Filter items emitted by the source Observable by only emitting those that\n * satisfy a specified predicate.\n *\n * Like\n * [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),\n * it only emits a value from the source if it passes a criterion function.\n *\n * ![](filter.png)\n *\n * Similar to the well-known `Array.prototype.filter` method, this operator\n * takes values from the source Observable, passes them through a `predicate`\n * function and only emits those values that yielded `true`.\n *\n * ## Example\n * Emit only click events whose target was a DIV element\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { filter } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const clicksOnDivs = clicks.pipe(filter(ev => ev.target.tagName === 'DIV'));\n * clicksOnDivs.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link distinct}\n * @see {@link distinctUntilChanged}\n * @see {@link distinctUntilKeyChanged}\n * @see {@link ignoreElements}\n * @see {@link partition}\n * @see {@link skip}\n *\n * @param {function(value: T, index: number): boolean} predicate A function that\n * evaluates each value emitted by the source Observable. If it returns `true`,\n * the value is emitted, if `false` the value is not passed to the output\n * Observable. The `index` parameter is the number `i` for the i-th source\n * emission that has happened since the subscription, starting from the number\n * `0`.\n * @param {any} [thisArg] An optional argument to determine the value of `this`\n * in the `predicate` function.\n * @return {Observable} An Observable of values from the source that were\n * allowed by the `predicate` function.\n * @method filter\n * @owner Observable\n */\nexport function filter(predicate: (value: T, index: number) => boolean,\n thisArg?: any): MonoTypeOperatorFunction {\n return function filterOperatorFunction(source: Observable): Observable {\n return source.lift(new FilterOperator(predicate, thisArg));\n };\n}\n\nclass FilterOperator implements Operator {\n constructor(private predicate: (value: T, index: number) => boolean,\n private thisArg?: any) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass FilterSubscriber extends Subscriber {\n\n count: number = 0;\n\n constructor(destination: Subscriber,\n private predicate: (value: T, index: number) => boolean,\n private thisArg: any) {\n super(destination);\n }\n\n // the try catch block below is left specifically for\n // optimization and perf reasons. a tryCatcher is not necessary here.\n protected _next(value: T) {\n let result: any;\n try {\n result = this.predicate.call(this.thisArg, value, this.count++);\n } catch (err) {\n this.destination.error(err);\n return;\n }\n if (result) {\n this.destination.next(value);\n }\n }\n}\n","import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { async } from '../scheduler/async';\nimport { MonoTypeOperatorFunction, SchedulerLike, TeardownLogic } from '../types';\n\n/**\n * Emits a value from the source Observable only after a particular time span\n * has passed without another source emission.\n *\n * It's like {@link delay}, but passes only the most\n * recent value from each burst of emissions.\n *\n * ![](debounceTime.png)\n *\n * `debounceTime` delays values emitted by the source Observable, but drops\n * previous pending delayed emissions if a new value arrives on the source\n * Observable. This operator keeps track of the most recent value from the\n * source Observable, and emits that only when `dueTime` enough time has passed\n * without any other value appearing on the source Observable. If a new value\n * appears before `dueTime` silence occurs, the previous value will be dropped\n * and will not be emitted on the output Observable.\n *\n * This is a rate-limiting operator, because it is impossible for more than one\n * value to be emitted in any time window of duration `dueTime`, but it is also\n * a delay-like operator since output emissions do not occur at the same time as\n * they did on the source Observable. Optionally takes a {@link SchedulerLike} for\n * managing timers.\n *\n * ## Example\n * Emit the most recent click after a burst of clicks\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { debounceTime } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(debounceTime(1000));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link auditTime}\n * @see {@link debounce}\n * @see {@link delay}\n * @see {@link sampleTime}\n * @see {@link throttleTime}\n *\n * @param {number} dueTime The timeout duration in milliseconds (or the time\n * unit determined internally by the optional `scheduler`) for the window of\n * time required to wait for emission silence before emitting the most recent\n * source value.\n * @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for\n * managing the timers that handle the timeout for each value.\n * @return {Observable} An Observable that delays the emissions of the source\n * Observable by the specified `dueTime`, and may drop some values if they occur\n * too frequently.\n * @method debounceTime\n * @owner Observable\n */\nexport function debounceTime(dueTime: number, scheduler: SchedulerLike = async): MonoTypeOperatorFunction {\n return (source: Observable) => source.lift(new DebounceTimeOperator(dueTime, scheduler));\n}\n\nclass DebounceTimeOperator implements Operator {\n constructor(private dueTime: number, private scheduler: SchedulerLike) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass DebounceTimeSubscriber extends Subscriber {\n private debouncedSubscription: Subscription = null;\n private lastValue: T = null;\n private hasValue: boolean = false;\n\n constructor(destination: Subscriber,\n private dueTime: number,\n private scheduler: SchedulerLike) {\n super(destination);\n }\n\n protected _next(value: T) {\n this.clearDebounce();\n this.lastValue = value;\n this.hasValue = true;\n this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));\n }\n\n protected _complete() {\n this.debouncedNext();\n this.destination.complete();\n }\n\n debouncedNext(): void {\n this.clearDebounce();\n\n if (this.hasValue) {\n const { lastValue } = this;\n // This must be done *before* passing the value\n // along to the destination because it's possible for\n // the value to synchronously re-enter this operator\n // recursively when scheduled with things like\n // VirtualScheduler/TestScheduler.\n this.lastValue = null;\n this.hasValue = false;\n this.destination.next(lastValue);\n }\n }\n\n private clearDebounce(): void {\n const debouncedSubscription = this.debouncedSubscription;\n\n if (debouncedSubscription !== null) {\n this.remove(debouncedSubscription);\n debouncedSubscription.unsubscribe();\n this.debouncedSubscription = null;\n }\n }\n}\n\nfunction dispatchNext(subscriber: DebounceTimeSubscriber) {\n subscriber.debouncedNext();\n}\n","import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { OperatorFunction, MonoTypeOperatorFunction } from '../types';\n\n/* tslint:disable:max-line-length */\nexport function defaultIfEmpty(defaultValue?: T): MonoTypeOperatorFunction;\nexport function defaultIfEmpty(defaultValue?: R): OperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Emits a given value if the source Observable completes without emitting any\n * `next` value, otherwise mirrors the source Observable.\n *\n * If the source Observable turns out to be empty, then\n * this operator will emit a default value.\n *\n * ![](defaultIfEmpty.png)\n *\n * `defaultIfEmpty` emits the values emitted by the source Observable or a\n * specified default value if the source Observable is empty (completes without\n * having emitted any `next` value).\n *\n * ## Example\n * If no clicks happen in 5 seconds, then emit \"no clicks\"\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { defaultIfEmpty, takeUntil } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const clicksBeforeFive = clicks.pipe(takeUntil(interval(5000)));\n * const result = clicksBeforeFive.pipe(defaultIfEmpty('no clicks'));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link empty}\n * @see {@link last}\n *\n * @param {any} [defaultValue=null] The default value used if the source\n * Observable is empty.\n * @return {Observable} An Observable that emits either the specified\n * `defaultValue` if the source Observable emits no items, or the values emitted\n * by the source Observable.\n * @method defaultIfEmpty\n * @owner Observable\n */\nexport function defaultIfEmpty(defaultValue: R = null): OperatorFunction {\n return (source: Observable) => source.lift(new DefaultIfEmptyOperator(defaultValue)) as Observable;\n}\n\nclass DefaultIfEmptyOperator implements Operator {\n\n constructor(private defaultValue: R) {\n }\n\n call(subscriber: Subscriber, source: any): any {\n return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass DefaultIfEmptySubscriber extends Subscriber {\n private isEmpty: boolean = true;\n\n constructor(destination: Subscriber, private defaultValue: R) {\n super(destination);\n }\n\n protected _next(value: T): void {\n this.isEmpty = false;\n this.destination.next(value);\n }\n\n protected _complete(): void {\n if (this.isEmpty) {\n this.destination.next(this.defaultValue);\n }\n this.destination.complete();\n }\n}\n","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable } from '../Observable';\nimport { MonoTypeOperatorFunction, TeardownLogic } from '../types';\n\n/* tslint:disable:max-line-length */\nexport function distinctUntilChanged(compare?: (x: T, y: T) => boolean): MonoTypeOperatorFunction;\nexport function distinctUntilChanged(compare: (x: K, y: K) => boolean, keySelector: (x: T) => K): MonoTypeOperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.\n *\n * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.\n *\n * If a comparator function is not provided, an equality check is used by default.\n *\n * ## Example\n * A simple example with numbers\n * ```ts\n * import { of } from 'rxjs';\n * import { distinctUntilChanged } from 'rxjs/operators';\n *\n * of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4).pipe(\n * distinctUntilChanged(),\n * )\n * .subscribe(x => console.log(x)); // 1, 2, 1, 2, 3, 4\n * ```\n *\n * An example using a compare function\n * ```typescript\n * import { of } from 'rxjs';\n * import { distinctUntilChanged } from 'rxjs/operators';\n *\n * interface Person {\n * age: number,\n * name: string\n * }\n *\n * of(\n * { age: 4, name: 'Foo'},\n * { age: 7, name: 'Bar'},\n * { age: 5, name: 'Foo'},\n * { age: 6, name: 'Foo'},\n * ).pipe(\n * distinctUntilChanged((p: Person, q: Person) => p.name === q.name),\n * )\n * .subscribe(x => console.log(x));\n *\n * // displays:\n * // { age: 4, name: 'Foo' }\n * // { age: 7, name: 'Bar' }\n * // { age: 5, name: 'Foo' }\n * ```\n *\n * @see {@link distinct}\n * @see {@link distinctUntilKeyChanged}\n *\n * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.\n * @return {Observable} An Observable that emits items from the source Observable with distinct values.\n * @method distinctUntilChanged\n * @owner Observable\n */\nexport function distinctUntilChanged(compare?: (x: K, y: K) => boolean, keySelector?: (x: T) => K): MonoTypeOperatorFunction {\n return (source: Observable) => source.lift(new DistinctUntilChangedOperator(compare, keySelector));\n}\n\nclass DistinctUntilChangedOperator implements Operator {\n constructor(private compare: (x: K, y: K) => boolean,\n private keySelector: (x: T) => K) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass DistinctUntilChangedSubscriber extends Subscriber {\n private key: K;\n private hasKey: boolean = false;\n\n constructor(destination: Subscriber,\n compare: (x: K, y: K) => boolean,\n private keySelector: (x: T) => K) {\n super(destination);\n if (typeof compare === 'function') {\n this.compare = compare;\n }\n }\n\n private compare(x: any, y: any): boolean {\n return x === y;\n }\n\n protected _next(value: T): void {\n let key: any;\n try {\n const { keySelector } = this;\n key = keySelector ? keySelector(value) : value;\n } catch (err) {\n return this.destination.error(err);\n }\n let result = false;\n if (this.hasKey) {\n try {\n const { compare } = this;\n result = compare(this.key, key);\n } catch (err) {\n return this.destination.error(err);\n }\n } else {\n this.hasKey = true;\n }\n if (!result) {\n this.key = key;\n this.destination.next(value);\n }\n }\n}\n","import { EmptyError } from '../util/EmptyError';\nimport { Observable } from '../Observable';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { TeardownLogic, MonoTypeOperatorFunction } from '../types';\n\n/**\n * If the source observable completes without emitting a value, it will emit\n * an error. The error will be created at that time by the optional\n * `errorFactory` argument, otherwise, the error will be {@link EmptyError}.\n *\n * ![](throwIfEmpty.png)\n *\n * ## Example\n * ```ts\n * import { fromEvent, timer } from 'rxjs';\n * import { throwIfEmpty, takeUntil } from 'rxjs/operators';\n *\n * const click$ = fromEvent(document, 'click');\n *\n * click$.pipe(\n * takeUntil(timer(1000)),\n * throwIfEmpty(\n * () => new Error('the document was not clicked within 1 second')\n * ),\n * )\n * .subscribe({\n * next() { console.log('The button was clicked'); },\n * error(err) { console.error(err); }\n * });\n * ```\n *\n * @param errorFactory A factory function called to produce the\n * error to be thrown when the source observable completes without emitting a\n * value.\n */\nexport function throwIfEmpty (errorFactory: (() => any) = defaultErrorFactory): MonoTypeOperatorFunction {\n return (source: Observable) => {\n return source.lift(new ThrowIfEmptyOperator(errorFactory));\n };\n}\n\nclass ThrowIfEmptyOperator implements Operator {\n constructor(private errorFactory: () => any) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));\n }\n}\n\nclass ThrowIfEmptySubscriber extends Subscriber {\n private hasValue: boolean = false;\n\n constructor(destination: Subscriber, private errorFactory: () => any) {\n super(destination);\n }\n\n protected _next(value: T): void {\n this.hasValue = true;\n this.destination.next(value);\n }\n\n protected _complete() {\n if (!this.hasValue) {\n let err: any;\n try {\n err = this.errorFactory();\n } catch (e) {\n err = e;\n }\n this.destination.error(err);\n } else {\n return this.destination.complete();\n }\n }\n}\n\nfunction defaultErrorFactory() {\n return new EmptyError();\n}\n","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';\nimport { empty } from '../observable/empty';\nimport { Observable } from '../Observable';\nimport { MonoTypeOperatorFunction, TeardownLogic } from '../types';\n\n/**\n * Emits only the first `count` values emitted by the source Observable.\n *\n * Takes the first `count` values from the source, then\n * completes.\n *\n * ![](take.png)\n *\n * `take` returns an Observable that emits only the first `count` values emitted\n * by the source Observable. If the source emits fewer than `count` values then\n * all of its values are emitted. After that, it completes, regardless if the\n * source completes.\n *\n * ## Example\n * Take the first 5 seconds of an infinite 1-second interval Observable\n * ```ts\n * import { interval } from 'rxjs';\n * import { take } from 'rxjs/operators';\n *\n * const intervalCount = interval(1000);\n * const takeFive = intervalCount.pipe(take(5));\n * takeFive.subscribe(x => console.log(x));\n *\n * // Logs:\n * // 0\n * // 1\n * // 2\n * // 3\n * // 4\n * ```\n *\n * @see {@link takeLast}\n * @see {@link takeUntil}\n * @see {@link takeWhile}\n * @see {@link skip}\n *\n * @throws {ArgumentOutOfRangeError} When using `take(i)`, it delivers an\n * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.\n *\n * @param {number} count The maximum number of `next` values to emit.\n * @return {Observable} An Observable that emits only the first `count`\n * values emitted by the source Observable, or all of the values from the source\n * if the source emits fewer than `count` values.\n * @method take\n * @owner Observable\n */\nexport function take(count: number): MonoTypeOperatorFunction {\n return (source: Observable) => {\n if (count === 0) {\n return empty();\n } else {\n return source.lift(new TakeOperator(count));\n }\n };\n}\n\nclass TakeOperator implements Operator {\n constructor(private total: number) {\n if (this.total < 0) {\n throw new ArgumentOutOfRangeError;\n }\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new TakeSubscriber(subscriber, this.total));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass TakeSubscriber extends Subscriber {\n private count: number = 0;\n\n constructor(destination: Subscriber, private total: number) {\n super(destination);\n }\n\n protected _next(value: T): void {\n const total = this.total;\n const count = ++this.count;\n if (count <= total) {\n this.destination.next(value);\n if (count === total) {\n this.destination.complete();\n this.unsubscribe();\n }\n }\n }\n}\n","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { Observable } from '../Observable';\nimport { MonoTypeOperatorFunction, TeardownLogic } from '../types';\n\n/**\n * Returns an Observable that mirrors the source Observable, but will call a specified function when\n * the source terminates on complete or error.\n * @param {function} callback Function to be called when source terminates.\n * @return {Observable} An Observable that mirrors the source, but will call the specified function on termination.\n * @method finally\n * @owner Observable\n */\nexport function finalize(callback: () => void): MonoTypeOperatorFunction {\n return (source: Observable) => source.lift(new FinallyOperator(callback));\n}\n\nclass FinallyOperator implements Operator {\n constructor(private callback: () => void) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(new FinallySubscriber(subscriber, this.callback));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass FinallySubscriber extends Subscriber {\n constructor(destination: Subscriber, callback: () => void) {\n super(destination);\n this.add(new Subscription(callback));\n }\n}\n","import { Subject } from '../Subject';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable } from '../Observable';\nimport { ConnectableObservable, connectableObservableDescriptor } from '../observable/ConnectableObservable';\nimport { MonoTypeOperatorFunction, OperatorFunction, UnaryFunction, ObservedValueOf, ObservableInput } from '../types';\n\n/* tslint:disable:max-line-length */\nexport function multicast(subject: Subject): UnaryFunction, ConnectableObservable>;\nexport function multicast>(subject: Subject, selector: (shared: Observable) => O): UnaryFunction, ConnectableObservable>>;\nexport function multicast(subjectFactory: (this: Observable) => Subject): UnaryFunction, ConnectableObservable>;\nexport function multicast>(SubjectFactory: (this: Observable) => Subject, selector: (shared: Observable) => O): OperatorFunction>;\n/* tslint:enable:max-line-length */\n\n/**\n * Returns an Observable that emits the results of invoking a specified selector on items\n * emitted by a ConnectableObservable that shares a single subscription to the underlying stream.\n *\n * ![](multicast.png)\n *\n * @param {Function|Subject} subjectOrSubjectFactory - Factory function to create an intermediate subject through\n * which the source sequence's elements will be multicast to the selector function\n * or Subject to push source elements into.\n * @param {Function} [selector] - Optional selector function that can use the multicasted source stream\n * as many times as needed, without causing multiple subscriptions to the source stream.\n * Subscribers to the given source will receive all notifications of the source from the\n * time of the subscription forward.\n * @return {Observable} An Observable that emits the results of invoking the selector\n * on the items emitted by a `ConnectableObservable` that shares a single subscription to\n * the underlying stream.\n * @method multicast\n * @owner Observable\n */\nexport function multicast(subjectOrSubjectFactory: Subject | (() => Subject),\n selector?: (source: Observable) => Observable): OperatorFunction {\n return function multicastOperatorFunction(source: Observable): Observable {\n let subjectFactory: () => Subject;\n if (typeof subjectOrSubjectFactory === 'function') {\n subjectFactory = <() => Subject>subjectOrSubjectFactory;\n } else {\n subjectFactory = function subjectFactory() {\n return >subjectOrSubjectFactory;\n };\n }\n\n if (typeof selector === 'function') {\n return source.lift(new MulticastOperator(subjectFactory, selector));\n }\n\n const connectable: any = Object.create(source, connectableObservableDescriptor);\n connectable.source = source;\n connectable.subjectFactory = subjectFactory;\n\n return > connectable;\n };\n}\n\nexport class MulticastOperator implements Operator {\n constructor(private subjectFactory: () => Subject,\n private selector: (source: Observable) => Observable) {\n }\n call(subscriber: Subscriber, source: any): any {\n const { selector } = this;\n const subject = this.subjectFactory();\n const subscription = selector(subject).subscribe(subscriber);\n subscription.add(source.subscribe(subject));\n return subscription;\n }\n}\n","import { Observable } from '../Observable';\nimport { multicast } from './multicast';\nimport { refCount } from './refCount';\nimport { Subject } from '../Subject';\n\nimport { MonoTypeOperatorFunction } from '../types';\n\nfunction shareSubjectFactory() {\n return new Subject();\n}\n\n/**\n * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one\n * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will\n * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`.\n * This is an alias for `multicast(() => new Subject()), refCount()`.\n *\n * ![](share.png)\n *\n * @return {Observable} An Observable that upon connection causes the source Observable to emit items to its Observers.\n * @method share\n * @owner Observable\n */\nexport function share(): MonoTypeOperatorFunction {\n return (source: Observable) => refCount()(multicast(shareSubjectFactory)(source)) as Observable;\n}\n","import { Observable } from '../Observable';\nimport { ReplaySubject } from '../ReplaySubject';\nimport { Subscription } from '../Subscription';\nimport { MonoTypeOperatorFunction, SchedulerLike } from '../types';\nimport { Subscriber } from '../Subscriber';\n\nexport interface ShareReplayConfig {\n bufferSize?: number;\n windowTime?: number;\n refCount: boolean;\n scheduler?: SchedulerLike;\n}\n\n/**\n * Share source and replay specified number of emissions on subscription.\n *\n * This operator is a specialization of `replay` that connects to a source observable\n * and multicasts through a `ReplaySubject` constructed with the specified arguments.\n * A successfully completed source will stay cached in the `shareReplayed observable` forever,\n * but an errored source can be retried.\n *\n * ## Why use shareReplay?\n * You generally want to use `shareReplay` when you have side-effects or taxing computations\n * that you do not wish to be executed amongst multiple subscribers.\n * It may also be valuable in situations where you know you will have late subscribers to\n * a stream that need access to previously emitted values.\n * This ability to replay values on subscription is what differentiates {@link share} and `shareReplay`.\n *\n * ![](shareReplay.png)\n *\n * ## Example\n * ```ts\n * import { interval } from 'rxjs';\n * import { shareReplay, take } from 'rxjs/operators';\n *\n * const obs$ = interval(1000);\n * const shared$ = obs$.pipe(\n * take(4),\n * shareReplay(3)\n * );\n * shared$.subscribe(x => console.log('source A: ', x));\n * shared$.subscribe(y => console.log('source B: ', y));\n *\n * ```\n *\n * @see {@link publish}\n * @see {@link share}\n * @see {@link publishReplay}\n *\n * @param {Number} [bufferSize=Number.POSITIVE_INFINITY] Maximum element count of the replay buffer.\n * @param {Number} [windowTime=Number.POSITIVE_INFINITY] Maximum time length of the replay buffer in milliseconds.\n * @param {Scheduler} [scheduler] Scheduler where connected observers within the selector function\n * will be invoked on.\n * @return {Observable} An observable sequence that contains the elements of a sequence produced\n * by multicasting the source sequence within a selector function.\n * @method shareReplay\n * @owner Observable\n */\nexport function shareReplay(\n config: ShareReplayConfig\n): MonoTypeOperatorFunction;\nexport function shareReplay(\n bufferSize?: number,\n windowTime?: number,\n scheduler?: SchedulerLike\n): MonoTypeOperatorFunction;\nexport function shareReplay(\n configOrBufferSize?: ShareReplayConfig | number,\n windowTime?: number,\n scheduler?: SchedulerLike\n): MonoTypeOperatorFunction {\n let config: ShareReplayConfig;\n if (configOrBufferSize && typeof configOrBufferSize === 'object') {\n config = configOrBufferSize as ShareReplayConfig;\n } else {\n config = {\n bufferSize: configOrBufferSize as number | undefined,\n windowTime,\n refCount: false,\n scheduler,\n };\n }\n return (source: Observable) => source.lift(shareReplayOperator(config));\n}\n\nfunction shareReplayOperator({\n bufferSize = Number.POSITIVE_INFINITY,\n windowTime = Number.POSITIVE_INFINITY,\n refCount: useRefCount,\n scheduler,\n}: ShareReplayConfig) {\n let subject: ReplaySubject | undefined;\n let refCount = 0;\n let subscription: Subscription | undefined;\n let hasError = false;\n let isComplete = false;\n\n return function shareReplayOperation(\n this: Subscriber,\n source: Observable\n ) {\n refCount++;\n let innerSub: Subscription;\n if (!subject || hasError) {\n hasError = false;\n subject = new ReplaySubject(bufferSize, windowTime, scheduler);\n innerSub = subject.subscribe(this);\n subscription = source.subscribe({\n next(value) {\n subject.next(value);\n },\n error(err) {\n hasError = true;\n subject.error(err);\n },\n complete() {\n isComplete = true;\n subscription = undefined;\n subject.complete();\n },\n });\n\n // Here we need to check to see if the source synchronously completed. Although\n // we're setting `subscription = undefined` in the completion handler, if the source\n // is synchronous, that will happen *before* subscription is set by the return of\n // the `subscribe` call.\n if (isComplete) {\n subscription = undefined;\n }\n } else {\n innerSub = subject.subscribe(this);\n }\n\n this.add(() => {\n refCount--;\n innerSub.unsubscribe();\n innerSub = undefined;\n if (subscription && !isComplete && useRefCount && refCount === 0) {\n subscription.unsubscribe();\n subscription = undefined;\n subject = undefined;\n }\n });\n };\n}\n","import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';\nimport { map } from './map';\nimport { from } from '../observable/from';\nimport { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';\n\n/* tslint:disable:max-line-length */\nexport function switchMap>(project: (value: T, index: number) => O): OperatorFunction>;\n/** @deprecated resultSelector is no longer supported, use inner map instead */\nexport function switchMap>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction>;\n/** @deprecated resultSelector is no longer supported, use inner map instead */\nexport function switchMap>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf, outerIndex: number, innerIndex: number) => R): OperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Projects each source value to an Observable which is merged in the output\n * Observable, emitting values only from the most recently projected Observable.\n *\n * Maps each value to an Observable, then flattens all of\n * these inner Observables.\n *\n * ![](switchMap.png)\n *\n * Returns an Observable that emits items based on applying a function that you\n * supply to each item emitted by the source Observable, where that function\n * returns an (so-called \"inner\") Observable. Each time it observes one of these\n * inner Observables, the output Observable begins emitting the items emitted by\n * that inner Observable. When a new inner Observable is emitted, `switchMap`\n * stops emitting items from the earlier-emitted inner Observable and begins\n * emitting items from the new one. It continues to behave like this for\n * subsequent inner Observables.\n *\n * ## Example\n * Generate new Observable according to source Observable values\n * ```typescript\n * import { of } from 'rxjs';\n * import { switchMap } from 'rxjs/operators';\n *\n * const switched = of(1, 2, 3).pipe(switchMap((x: number) => of(x, x ** 2, x ** 3)));\n * switched.subscribe(x => console.log(x));\n * // outputs\n * // 1\n * // 1\n * // 1\n * // 2\n * // 4\n * // 8\n * // ... and so on\n * ```\n *\n * Rerun an interval Observable on every click event\n * ```ts\n * import { fromEvent, interval } from 'rxjs';\n * import { switchMap } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(switchMap((ev) => interval(1000)));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link concatMap}\n * @see {@link exhaustMap}\n * @see {@link mergeMap}\n * @see {@link switchAll}\n * @see {@link switchMapTo}\n *\n * @param {function(value: T, ?index: number): ObservableInput} project A function\n * that, when applied to an item emitted by the source Observable, returns an\n * Observable.\n * @return {Observable} An Observable that emits the result of applying the\n * projection function (and the optional deprecated `resultSelector`) to each item\n * emitted by the source Observable and taking only the values from the most recently\n * projected inner Observable.\n * @method switchMap\n * @owner Observable\n */\nexport function switchMap>(\n project: (value: T, index: number) => O,\n resultSelector?: (outerValue: T, innerValue: ObservedValueOf, outerIndex: number, innerIndex: number) => R,\n): OperatorFunction|R> {\n if (typeof resultSelector === 'function') {\n return (source: Observable) => source.pipe(\n switchMap((a, i) => from(project(a, i)).pipe(\n map((b, ii) => resultSelector(a, b, i, ii))\n ))\n );\n }\n return (source: Observable) => source.lift(new SwitchMapOperator(project));\n}\n\nclass SwitchMapOperator implements Operator {\n constructor(private project: (value: T, index: number) => ObservableInput) {\n }\n\n call(subscriber: Subscriber, source: any): any {\n return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass SwitchMapSubscriber extends SimpleOuterSubscriber {\n private index = 0;\n private innerSubscription?: Subscription;\n\n constructor(destination: Subscriber,\n private project: (value: T, index: number) => ObservableInput) {\n super(destination);\n }\n\n protected _next(value: T) {\n let result: ObservableInput;\n const index = this.index++;\n try {\n result = this.project(value, index);\n } catch (error) {\n this.destination.error!(error);\n return;\n }\n this._innerSub(result);\n }\n\n private _innerSub(result: ObservableInput) {\n const innerSubscription = this.innerSubscription;\n if (innerSubscription) {\n innerSubscription.unsubscribe();\n }\n const innerSubscriber = new SimpleInnerSubscriber(this);\n const destination = this.destination as Subscription;\n destination.add(innerSubscriber);\n this.innerSubscription = innerSubscribe(result, innerSubscriber);\n // The returned subscription will usually be the subscriber that was\n // passed. However, interop subscribers will be wrapped and for\n // unsubscriptions to chain correctly, the wrapper needs to be added, too.\n if (this.innerSubscription !== innerSubscriber) {\n destination.add(this.innerSubscription);\n }\n }\n\n protected _complete(): void {\n const {innerSubscription} = this;\n if (!innerSubscription || innerSubscription.closed) {\n super._complete();\n }\n this.unsubscribe();\n }\n\n protected _unsubscribe() {\n this.innerSubscription = undefined;\n }\n\n notifyComplete(): void {\n this.innerSubscription = undefined;\n if (this.isStopped) {\n super._complete();\n }\n }\n\n notifyNext(innerValue: R): void {\n this.destination.next!(innerValue);\n }\n}\n","import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\n\nimport { MonoTypeOperatorFunction, TeardownLogic } from '../types';\nimport { innerSubscribe, SimpleInnerSubscriber, SimpleOuterSubscriber } from '../innerSubscribe';\n\n/**\n * Emits the values emitted by the source Observable until a `notifier`\n * Observable emits a value.\n *\n * Lets values pass until a second Observable,\n * `notifier`, emits a value. Then, it completes.\n *\n * ![](takeUntil.png)\n *\n * `takeUntil` subscribes and begins mirroring the source Observable. It also\n * monitors a second Observable, `notifier` that you provide. If the `notifier`\n * emits a value, the output Observable stops mirroring the source Observable\n * and completes. If the `notifier` doesn't emit any value and completes\n * then `takeUntil` will pass all values.\n *\n * ## Example\n * Tick every second until the first click happens\n * ```ts\n * import { fromEvent, interval } from 'rxjs';\n * import { takeUntil } from 'rxjs/operators';\n *\n * const source = interval(1000);\n * const clicks = fromEvent(document, 'click');\n * const result = source.pipe(takeUntil(clicks));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link take}\n * @see {@link takeLast}\n * @see {@link takeWhile}\n * @see {@link skip}\n *\n * @param {Observable} notifier The Observable whose first emitted value will\n * cause the output Observable of `takeUntil` to stop emitting values from the\n * source Observable.\n * @return {Observable} An Observable that emits the values from the source\n * Observable until such time as `notifier` emits its first value.\n * @method takeUntil\n * @owner Observable\n */\nexport function takeUntil(notifier: Observable): MonoTypeOperatorFunction {\n return (source: Observable) => source.lift(new TakeUntilOperator(notifier));\n}\n\nclass TakeUntilOperator implements Operator {\n constructor(private notifier: Observable) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n const takeUntilSubscriber = new TakeUntilSubscriber(subscriber);\n const notifierSubscription = innerSubscribe(this.notifier, new SimpleInnerSubscriber(takeUntilSubscriber));\n if (notifierSubscription && !takeUntilSubscriber.seenValue) {\n takeUntilSubscriber.add(notifierSubscription);\n return source.subscribe(takeUntilSubscriber);\n }\n return takeUntilSubscriber;\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass TakeUntilSubscriber extends SimpleOuterSubscriber {\n seenValue = false;\n\n constructor(destination: Subscriber, ) {\n super(destination);\n }\n\n notifyNext(): void {\n this.seenValue = true;\n this.complete();\n }\n\n notifyComplete(): void {\n // noop\n }\n}\n","import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { OperatorFunction, MonoTypeOperatorFunction, TeardownLogic } from '../types';\n\nexport function takeWhile(predicate: (value: T, index: number) => value is S): OperatorFunction;\nexport function takeWhile(predicate: (value: T, index: number) => value is S, inclusive: false): OperatorFunction;\nexport function takeWhile(predicate: (value: T, index: number) => boolean, inclusive?: boolean): MonoTypeOperatorFunction;\n\n/**\n * Emits values emitted by the source Observable so long as each value satisfies\n * the given `predicate`, and then completes as soon as this `predicate` is not\n * satisfied.\n *\n * Takes values from the source only while they pass the\n * condition given. When the first value does not satisfy, it completes.\n *\n * ![](takeWhile.png)\n *\n * `takeWhile` subscribes and begins mirroring the source Observable. Each value\n * emitted on the source is given to the `predicate` function which returns a\n * boolean, representing a condition to be satisfied by the source values. The\n * output Observable emits the source values until such time as the `predicate`\n * returns false, at which point `takeWhile` stops mirroring the source\n * Observable and completes the output Observable.\n *\n * ## Example\n * Emit click events only while the clientX property is greater than 200\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { takeWhile } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(takeWhile(ev => ev.clientX > 200));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link take}\n * @see {@link takeLast}\n * @see {@link takeUntil}\n * @see {@link skip}\n *\n * @param {function(value: T, index: number): boolean} predicate A function that\n * evaluates a value emitted by the source Observable and returns a boolean.\n * Also takes the (zero-based) index as the second argument.\n * @param {boolean} inclusive When set to `true` the value that caused\n * `predicate` to return `false` will also be emitted.\n * @return {Observable} An Observable that emits the values from the source\n * Observable so long as each value satisfies the condition defined by the\n * `predicate`, then completes.\n * @method takeWhile\n * @owner Observable\n */\nexport function takeWhile(\n predicate: (value: T, index: number) => boolean,\n inclusive = false): MonoTypeOperatorFunction {\n return (source: Observable) =>\n source.lift(new TakeWhileOperator(predicate, inclusive));\n}\n\nclass TakeWhileOperator implements Operator {\n constructor(\n private predicate: (value: T, index: number) => boolean,\n private inclusive: boolean) {}\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(\n new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass TakeWhileSubscriber extends Subscriber {\n private index: number = 0;\n\n constructor(\n destination: Subscriber,\n private predicate: (value: T, index: number) => boolean,\n private inclusive: boolean) {\n super(destination);\n }\n\n protected _next(value: T): void {\n const destination = this.destination;\n let result: boolean;\n try {\n result = this.predicate(value, this.index++);\n } catch (err) {\n destination.error(err);\n return;\n }\n this.nextOrComplete(value, result);\n }\n\n private nextOrComplete(value: T, predicateResult: boolean): void {\n const destination = this.destination;\n if (Boolean(predicateResult)) {\n destination.next(value);\n } else {\n if (this.inclusive) {\n destination.next(value);\n }\n destination.complete();\n }\n }\n}\n","import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\n\nimport { MonoTypeOperatorFunction, SubscribableOrPromise, TeardownLogic } from '../types';\nimport { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';\n\nexport interface ThrottleConfig {\n leading?: boolean;\n trailing?: boolean;\n}\n\nexport const defaultThrottleConfig: ThrottleConfig = {\n leading: true,\n trailing: false\n};\n\n/**\n * Emits a value from the source Observable, then ignores subsequent source\n * values for a duration determined by another Observable, then repeats this\n * process.\n *\n * It's like {@link throttleTime}, but the silencing\n * duration is determined by a second Observable.\n *\n * ![](throttle.png)\n *\n * `throttle` emits the source Observable values on the output Observable\n * when its internal timer is disabled, and ignores source values when the timer\n * is enabled. Initially, the timer is disabled. As soon as the first source\n * value arrives, it is forwarded to the output Observable, and then the timer\n * is enabled by calling the `durationSelector` function with the source value,\n * which returns the \"duration\" Observable. When the duration Observable emits a\n * value or completes, the timer is disabled, and this process repeats for the\n * next source value.\n *\n * ## Example\n * Emit clicks at a rate of at most one click per second\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { throttle } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(throttle(ev => interval(1000)));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link audit}\n * @see {@link debounce}\n * @see {@link delayWhen}\n * @see {@link sample}\n * @see {@link throttleTime}\n *\n * @param {function(value: T): SubscribableOrPromise} durationSelector A function\n * that receives a value from the source Observable, for computing the silencing\n * duration for each source value, returned as an Observable or a Promise.\n * @param {Object} config a configuration object to define `leading` and `trailing` behavior. Defaults\n * to `{ leading: true, trailing: false }`.\n * @return {Observable} An Observable that performs the throttle operation to\n * limit the rate of emissions from the source.\n * @method throttle\n * @owner Observable\n */\nexport function throttle(durationSelector: (value: T) => SubscribableOrPromise,\n config: ThrottleConfig = defaultThrottleConfig): MonoTypeOperatorFunction {\n return (source: Observable) => source.lift(new ThrottleOperator(durationSelector, !!config.leading, !!config.trailing));\n}\n\nclass ThrottleOperator implements Operator {\n constructor(private durationSelector: (value: T) => SubscribableOrPromise,\n private leading: boolean,\n private trailing: boolean) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(\n new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing)\n );\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc\n * @ignore\n * @extends {Ignored}\n */\nclass ThrottleSubscriber extends SimpleOuterSubscriber {\n private _throttled?: Subscription;\n private _sendValue?: T;\n private _hasValue = false;\n\n constructor(protected destination: Subscriber,\n private durationSelector: (value: T) => SubscribableOrPromise,\n private _leading: boolean,\n private _trailing: boolean) {\n super(destination);\n }\n\n protected _next(value: T): void {\n this._hasValue = true;\n this._sendValue = value;\n\n if (!this._throttled) {\n if (this._leading) {\n this.send();\n } else {\n this.throttle(value);\n }\n }\n }\n\n private send() {\n const { _hasValue, _sendValue } = this;\n if (_hasValue) {\n this.destination.next(_sendValue);\n this.throttle(_sendValue!);\n }\n this._hasValue = false;\n this._sendValue = undefined;\n }\n\n private throttle(value: T): void {\n const duration = this.tryDurationSelector(value);\n if (!!duration) {\n this.add(this._throttled = innerSubscribe(duration, new SimpleInnerSubscriber(this)));\n }\n }\n\n private tryDurationSelector(value: T): SubscribableOrPromise | null {\n try {\n return this.durationSelector(value);\n } catch (err) {\n this.destination.error(err);\n return null;\n }\n }\n\n private throttlingDone() {\n const { _throttled, _trailing } = this;\n if (_throttled) {\n _throttled.unsubscribe();\n }\n this._throttled = undefined;\n\n if (_trailing) {\n this.send();\n }\n }\n\n notifyNext(): void {\n this.throttlingDone();\n }\n\n notifyComplete(): void {\n this.throttlingDone();\n }\n}\n","import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { async } from '../scheduler/async';\nimport { Observable } from '../Observable';\nimport { ThrottleConfig, defaultThrottleConfig } from './throttle';\nimport { MonoTypeOperatorFunction, SchedulerLike, TeardownLogic } from '../types';\n\n/**\n * Emits a value from the source Observable, then ignores subsequent source\n * values for `duration` milliseconds, then repeats this process.\n *\n * Lets a value pass, then ignores source values for the\n * next `duration` milliseconds.\n *\n * ![](throttleTime.png)\n *\n * `throttleTime` emits the source Observable values on the output Observable\n * when its internal timer is disabled, and ignores source values when the timer\n * is enabled. Initially, the timer is disabled. As soon as the first source\n * value arrives, it is forwarded to the output Observable, and then the timer\n * is enabled. After `duration` milliseconds (or the time unit determined\n * internally by the optional `scheduler`) has passed, the timer is disabled,\n * and this process repeats for the next source value. Optionally takes a\n * {@link SchedulerLike} for managing timers.\n *\n * ## Examples\n *\n * #### Limit click rate\n *\n * Emit clicks at a rate of at most one click per second\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { throttleTime } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(throttleTime(1000));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * #### Double Click\n *\n * The following example only emits clicks which happen within a subsequent\n * delay of 400ms of the previous click. This for example can emulate a double\n * click. It makes use of the `trailing` parameter of the throttle configuration.\n *\n * ```ts\n * import { fromEvent, asyncScheduler } from 'rxjs';\n * import { throttleTime, withLatestFrom } from 'rxjs/operators';\n *\n * // defaultThottleConfig = { leading: true, trailing: false }\n * const throttleConfig = {\n * leading: false,\n * trailing: true\n * }\n *\n * const click = fromEvent(document, 'click');\n * const doubleClick = click.pipe(\n * throttleTime(400, asyncScheduler, throttleConfig)\n * );\n *\n * doubleClick.subscribe((throttleValue: Event) => {\n * console.log(`Double-clicked! Timestamp: ${throttleValue.timeStamp}`);\n * });\n * ```\n *\n * If you enable the `leading` parameter in this example, the output would be the primary click and\n * the double click, but restricts additional clicks within 400ms.\n *\n * @see {@link auditTime}\n * @see {@link debounceTime}\n * @see {@link delay}\n * @see {@link sampleTime}\n * @see {@link throttle}\n *\n * @param {number} duration Time to wait before emitting another value after\n * emitting the last value, measured in milliseconds or the time unit determined\n * internally by the optional `scheduler`.\n * @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for\n * managing the timers that handle the throttling.\n * @param {Object} config a configuration object to define `leading` and\n * `trailing` behavior. Defaults to `{ leading: true, trailing: false }`.\n * @return {Observable} An Observable that performs the throttle operation to\n * limit the rate of emissions from the source.\n * @method throttleTime\n * @owner Observable\n */\nexport function throttleTime(duration: number,\n scheduler: SchedulerLike = async,\n config: ThrottleConfig = defaultThrottleConfig): MonoTypeOperatorFunction {\n return (source: Observable) => source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing));\n}\n\nclass ThrottleTimeOperator implements Operator {\n constructor(private duration: number,\n private scheduler: SchedulerLike,\n private leading: boolean,\n private trailing: boolean) {\n }\n\n call(subscriber: Subscriber, source: any): TeardownLogic {\n return source.subscribe(\n new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing)\n );\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass ThrottleTimeSubscriber extends Subscriber {\n private throttled: Subscription;\n private _hasTrailingValue: boolean = false;\n private _trailingValue: T = null;\n\n constructor(destination: Subscriber,\n private duration: number,\n private scheduler: SchedulerLike,\n private leading: boolean,\n private trailing: boolean) {\n super(destination);\n }\n\n protected _next(value: T) {\n if (this.throttled) {\n if (this.trailing) {\n this._trailingValue = value;\n this._hasTrailingValue = true;\n }\n } else {\n this.add(this.throttled = this.scheduler.schedule>(dispatchNext, this.duration, { subscriber: this }));\n if (this.leading) {\n this.destination.next(value);\n } else if (this.trailing) {\n this._trailingValue = value;\n this._hasTrailingValue = true;\n }\n }\n }\n\n protected _complete() {\n if (this._hasTrailingValue) {\n this.destination.next(this._trailingValue);\n this.destination.complete();\n } else {\n this.destination.complete();\n }\n }\n\n clearThrottle() {\n const throttled = this.throttled;\n if (throttled) {\n if (this.trailing && this._hasTrailingValue) {\n this.destination.next(this._trailingValue);\n this._trailingValue = null;\n this._hasTrailingValue = false;\n }\n throttled.unsubscribe();\n this.remove(throttled);\n this.throttled = null;\n }\n }\n}\n\ninterface DispatchArg {\n subscriber: ThrottleTimeSubscriber;\n}\n\nfunction dispatchNext(arg: DispatchArg) {\n const { subscriber } = arg;\n subscriber.clearThrottle();\n}\n","import { Subject } from 'rxjs';\r\n\r\nexport function isDefined(item: T | undefined | null): item is T {\r\n return typeof item !== 'undefined' && item !== null;\r\n}\r\n\r\nexport function isObject(o: any) {\r\n return typeof o === 'object' && o != null;\r\n}\r\n\r\n/** Type guard for filtering out undefined */\r\nexport function omitUndefinedElements(item: T): item is NonNullable {\r\n return item !== null && typeof item !== 'undefined';\r\n}\r\n\r\nexport const changesProcessed = new Subject();\r\n\r\nexport const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\r\n\r\nexport function isGuid(str: string) {\r\n return guidRegex.test(str);\r\n}\r\n\r\nexport const absoluteUrlRegex = /^(?:[a-z]+:)?\\/\\//i;\r\nexport function isAbsoluteUrl(url: string): boolean {\r\n return absoluteUrlRegex.test(url);\r\n}\r\n\r\nexport function appendOrIncrementNumber(name: string) {\r\n const lastNumber = name.replace(/\\D*(\\d*)\\s*$/, '$1');\r\n if (lastNumber === '') {\r\n return name + ' 2';\r\n } else {\r\n return name.replace(/\\d*\\s*$/, (parseInt(lastNumber, 10) + 1).toString());\r\n }\r\n}\r\n\r\n/** UUID generation based on: https://github.com/jchook/uuid-random/blob/master/index.js */\r\nexport class UUID {\r\n private static buf: Uint8Array;\r\n private static bufIdx = 0;\r\n private static hexBytes = new Array();\r\n private static i: number;\r\n private static bufferSize = 4096;\r\n\r\n public static initialize() {\r\n // Pre-calculate toString(16) for speed\r\n for (UUID.i = 0; UUID.i < 256; UUID.i++) {\r\n UUID.hexBytes[UUID.i] = (UUID.i + 0x100).toString(16).substr(1);\r\n }\r\n }\r\n\r\n // Buffer some random bytes for speed\r\n protected static randomBytesBuffered(n: number) {\r\n if (!UUID.buf || UUID.bufIdx + n > UUID.bufferSize) {\r\n UUID.bufIdx = 0;\r\n UUID.buf = crypto.getRandomValues(new Uint8Array(UUID.bufferSize));\r\n }\r\n return UUID.buf.slice(UUID.bufIdx, (UUID.bufIdx += n));\r\n }\r\n\r\n // uuid.bin\r\n protected static uuidBin() {\r\n const b = UUID.randomBytesBuffered(16);\r\n b[6] = (b[6] & 0x0f) | 0x40;\r\n b[8] = (b[8] & 0x3f) | 0x80;\r\n return b;\r\n }\r\n\r\n public static generate() {\r\n const b = UUID.uuidBin();\r\n return (\r\n UUID.hexBytes[b[0]] +\r\n UUID.hexBytes[b[1]] +\r\n UUID.hexBytes[b[2]] +\r\n UUID.hexBytes[b[3]] +\r\n '-' +\r\n UUID.hexBytes[b[4]] +\r\n UUID.hexBytes[b[5]] +\r\n '-' +\r\n UUID.hexBytes[b[6]] +\r\n UUID.hexBytes[b[7]] +\r\n '-' +\r\n UUID.hexBytes[b[8]] +\r\n UUID.hexBytes[b[9]] +\r\n '-' +\r\n UUID.hexBytes[b[10]] +\r\n UUID.hexBytes[b[11]] +\r\n UUID.hexBytes[b[12]] +\r\n UUID.hexBytes[b[13]] +\r\n UUID.hexBytes[b[14]] +\r\n UUID.hexBytes[b[15]]\r\n );\r\n }\r\n}\r\nUUID.initialize();\r\n","import { BehaviorSubject } from 'rxjs';\r\nimport { take } from 'rxjs/operators';\r\nimport { EChangeOperation, IHistoryStateChange, isTrackedClass, ITrackedClass } from '../interfaces/tracked-class';\r\nimport { changesProcessed } from './utilities';\r\n\r\ntype TrackedObject = ITrackedClass | any[];\r\ntype ChangeGroup = {\r\n change: Map;\r\n undoFunction?: () => void;\r\n redoFunction?: () => void;\r\n description: string;\r\n};\r\n\r\nexport interface ChangeInfo {\r\n index: number;\r\n description: string;\r\n nodes: any[];\r\n properties: IterableIterator;\r\n}\r\n\r\nclass SceneHistory {\r\n private active = false;\r\n private changes: ChangeGroup[] = [];\r\n private undoneChanges: ChangeGroup[] = [];\r\n\r\n private ignoreChangesFromObjects = new Set();\r\n\r\n openChange: ChangeGroup | undefined;\r\n state = new BehaviorSubject([]);\r\n undoneState = new BehaviorSubject([]);\r\n\r\n private updateState() {\r\n return this.state.next(this.getMergedChanges(this.changes));\r\n }\r\n private updateUndoneState() {\r\n return this.undoneState.next(this.getMergedChanges(this.undoneChanges));\r\n }\r\n\r\n private getMergedChanges(changes: ChangeGroup[]) {\r\n return changes.map((c, index) => {\r\n const changePart = Array.from(c.change.values());\r\n return {\r\n description: c.description,\r\n index,\r\n nodes: changePart.map(node => node.node),\r\n // Return a set of properties to drop duplicate array elements\r\n properties: new Set(\r\n changePart.flatMap(node => node.properties.flatMap(property => property.name))\r\n ).values(),\r\n };\r\n });\r\n }\r\n\r\n ignoreUntilStable(object: TrackedObject) {\r\n if (this.ignoreChangesFromObjects.size === 0) {\r\n changesProcessed.pipe(take(1)).subscribe(() => {\r\n this.ignoreChangesFromObjects.clear();\r\n });\r\n }\r\n this.ignoreChangesFromObjects.add(object);\r\n }\r\n\r\n start() {\r\n this.active = true;\r\n }\r\n\r\n stop() {\r\n this.active = false;\r\n }\r\n\r\n /**\r\n * Adds a change to the history. If you added an open-ended change\r\n * @param description\r\n * @param processFunction\r\n * @param undoFunction\r\n */\r\n addChange(description: string, processFunction: (redo: boolean) => void, undoFunction?: () => void) {\r\n // if (this.openChange) {\r\n // console.warn(\r\n // 'Starting a new history change with a previous change still open. You may get a strange history state.',\r\n // `Change still open: ${this.openChange.description}`,\r\n // `New change: ${description}`\r\n // );\r\n // }\r\n\r\n let newChange: ChangeGroup | undefined;\r\n if (!this.openChange) {\r\n newChange = this.openChange = {\r\n change: new Map(),\r\n description,\r\n undoFunction,\r\n };\r\n }\r\n processFunction(false);\r\n\r\n const done = (description: string | void) => {\r\n if (this.openChange) {\r\n if (this.openChange.change.size > 0 || this.openChange.undoFunction !== undefined) {\r\n if (description) {\r\n this.openChange.description = description;\r\n }\r\n this.changes.push(this.openChange);\r\n }\r\n\r\n delete this.openChange;\r\n this.updateState();\r\n\r\n if (this.undoneChanges.length > 0) {\r\n this.undoneChanges.clear();\r\n this.updateUndoneState();\r\n }\r\n }\r\n };\r\n\r\n if (undoFunction) {\r\n this.openChange.redoFunction = () => processFunction(true);\r\n done();\r\n } else if (newChange) {\r\n changesProcessed.pipe(take(1)).subscribe(done);\r\n }\r\n }\r\n\r\n undo() {\r\n if (this.openChange) {\r\n throw Error(\"Can't undo while there are open changes\");\r\n }\r\n if (this.changes.length < 1) {\r\n return;\r\n }\r\n const lastChangeSet = this.changes.pop();\r\n if (lastChangeSet) {\r\n this.undoneChanges.push(lastChangeSet);\r\n if (lastChangeSet.undoFunction) {\r\n lastChangeSet.undoFunction();\r\n } else {\r\n this.processChangeSet(lastChangeSet, change => {\r\n // Undo changes in reverse so they are consistent with how they were added.\r\n change.properties\r\n .slice()\r\n .reverse()\r\n .forEach(property => {\r\n const restore = property.previousValue;\r\n switch (property.operation) {\r\n case EChangeOperation.CreateAndPush:\r\n change.node.pop(true);\r\n break;\r\n case EChangeOperation.Push:\r\n change.node.pop();\r\n break;\r\n case EChangeOperation.Unshift:\r\n change.node.shift();\r\n break;\r\n case EChangeOperation.Shift:\r\n change.node.unshift(property.previousValue);\r\n if (isTrackedClass(restore)) {\r\n (restore as ITrackedClass).isModified = true;\r\n }\r\n break;\r\n case EChangeOperation.Pop:\r\n change.node.push(property.previousValue);\r\n if (isTrackedClass(restore)) {\r\n (restore as ITrackedClass).isModified = true;\r\n }\r\n break;\r\n case EChangeOperation.Remove:\r\n case EChangeOperation.Splice:\r\n // Property name is the index of the splice\r\n // Remove all the added values, add back in the old ones\r\n change.node.splice(property.name, property.newValue.length, ...restore);\r\n if (Array.isArray(restore) && restore.length > 0) {\r\n restore.forEach(restoreItem => {\r\n if (isTrackedClass(restoreItem)) {\r\n (restoreItem as ITrackedClass).isModified = true;\r\n }\r\n });\r\n }\r\n break;\r\n default:\r\n change.node[property.name] = property.previousValue;\r\n }\r\n });\r\n });\r\n }\r\n\r\n this.updateState();\r\n this.updateUndoneState();\r\n }\r\n }\r\n\r\n redo() {\r\n if (this.openChange) {\r\n throw Error(\"Can't redo while there are open changes\");\r\n }\r\n if (this.undoneChanges.length < 1) {\r\n return;\r\n }\r\n const lastUndoneChangeSet = this.undoneChanges.pop();\r\n if (lastUndoneChangeSet) {\r\n this.changes.push(lastUndoneChangeSet);\r\n if (lastUndoneChangeSet.redoFunction) {\r\n lastUndoneChangeSet.redoFunction();\r\n } else {\r\n this.processChangeSet(lastUndoneChangeSet, change => {\r\n // Redo changes in the initial order\r\n change.properties.forEach(property => {\r\n const restore = property.newValue;\r\n switch (property.operation) {\r\n case EChangeOperation.CreateAndPush:\r\n change.node.createAndPush(property.newValue);\r\n if (isTrackedClass(restore)) {\r\n (restore as ITrackedClass).isModified = true;\r\n }\r\n break;\r\n case EChangeOperation.Push:\r\n change.node.push(property.newValue);\r\n break;\r\n case EChangeOperation.Unshift:\r\n change.node.unshift(property.newValue);\r\n if (isTrackedClass(restore)) {\r\n (restore as ITrackedClass).isModified = true;\r\n }\r\n break;\r\n case EChangeOperation.Shift:\r\n change.node.shift();\r\n break;\r\n case EChangeOperation.Pop:\r\n change.node.pop();\r\n break;\r\n case EChangeOperation.Remove:\r\n property.previousValue.length === 1 && change.node.remove(property.previousValue[0]);\r\n break;\r\n case EChangeOperation.Splice:\r\n change.node.splice(property.name, property.previousValue.length, ...restore);\r\n if (Array.isArray(restore) && restore.length > 0) {\r\n restore.forEach(restoreItem => {\r\n if (isTrackedClass(restoreItem)) {\r\n (restoreItem as ITrackedClass).isModified = true;\r\n }\r\n });\r\n }\r\n break;\r\n default:\r\n change.node[property.name] = property.newValue;\r\n }\r\n });\r\n });\r\n }\r\n\r\n this.updateState();\r\n this.updateUndoneState();\r\n }\r\n }\r\n\r\n undoTo(index: number) {\r\n while (this.changes.length > index + 1) {\r\n this.undo();\r\n }\r\n }\r\n\r\n redoTo(index: number) {\r\n while (this.undoneChanges.length > index) {\r\n this.redo();\r\n }\r\n }\r\n\r\n // startGroupingAllChanges() {\r\n // this.groupAllIncomingChanges = true;\r\n // this.changes.push(new Map());\r\n // }\r\n\r\n // stopGroupingAllChanges() {\r\n // this.groupAllIncomingChanges = false;\r\n // this.removeLastChangeIfEmpty();\r\n // this.updateState();\r\n // }\r\n\r\n // startGroupingObjectsChanges(objects: Array) {\r\n // this.groupChangesInObjects = new Set(objects.filter(isTrackedClass));\r\n // this.changes.push(new Map());\r\n // }\r\n\r\n // stopGroupingObjectsChanges() {\r\n // this.groupChangesInObjects = undefined;\r\n // this.removeLastChangeIfEmpty();\r\n // }\r\n\r\n changeEvent(\r\n object: T,\r\n property: keyof T | symbol,\r\n value: any,\r\n originalValue: any,\r\n operation?: EChangeOperation\r\n ) {\r\n if (\r\n this.active &&\r\n (isTrackedClass(object) || Array.isArray(object)) &&\r\n value !== originalValue &&\r\n !this.ignoreChangesFromObjects.has(object)\r\n ) {\r\n if (!this.openChange) {\r\n return;\r\n }\r\n const openChange = this.openChange;\r\n\r\n let lastChangeOnObject = openChange.change.get(object);\r\n if (!lastChangeOnObject) {\r\n lastChangeOnObject = { node: object, properties: [] };\r\n openChange.change.set(object, lastChangeOnObject);\r\n }\r\n\r\n const lastChangeOnObjectProperty = lastChangeOnObject.properties.find(\r\n openChange => openChange.name === property\r\n );\r\n if (!lastChangeOnObjectProperty) {\r\n lastChangeOnObject.properties.push({\r\n name: property,\r\n previousValue: originalValue,\r\n newValue: value,\r\n operation,\r\n });\r\n } else {\r\n lastChangeOnObjectProperty.newValue = value;\r\n }\r\n }\r\n }\r\n\r\n changeEvents(\r\n object: T,\r\n changes: Array<{ property: keyof T | symbol; value: any; originalValue: any; operation: EChangeOperation }>\r\n ) {\r\n if (\r\n this.active &&\r\n (isTrackedClass(object) || Array.isArray(object)) &&\r\n !this.ignoreChangesFromObjects.has(object)\r\n ) {\r\n changes.forEach(change => {\r\n this.changeEvent(object, change.property, change.value, change.originalValue, change.operation);\r\n });\r\n }\r\n }\r\n\r\n removeLastChange(object: T, property: keyof T) {\r\n // todo\r\n }\r\n\r\n private processChangeSet(changeSet: ChangeGroup, process: (change: IHistoryStateChange) => void) {\r\n changeSet.change.forEach(change => process(change));\r\n }\r\n}\r\n\r\nexport const history = new SceneHistory();\r\n","import { EChangeOperation, isTrackedClass, ITrackedArray, ITrackedClass } from '../../interfaces/tracked-class';\r\nimport { SyncService } from '../../services/sync-service';\r\nimport { history } from '../history';\r\nimport { changesProcessed } from '../utilities';\r\n\r\nexport function nextTick() {\r\n changesProcessed.next();\r\n}\r\n\r\nconst __arrayProtoFunctions: any = {};\r\n['push', 'unshift', 'shift', 'pop', 'splice', 'reorder', 'clear'].forEach((arrayFunc: any) => {\r\n __arrayProtoFunctions[arrayFunc] = Array.prototype[arrayFunc];\r\n\r\n // We shouldn't need this code after the Vue update to 3.2. Was needed to fix reactivity on arrays for Vue\r\n // Delete this when no confirmed that there are no issues with reactivity in creator\r\n // Array.prototype[arrayFunc] = function(...args: any) {\r\n // if(isTrackedArray(this)) {\r\n // return TrackedArray.prototype[arrayFunc].apply(this, args);\r\n // } else {\r\n // return __arrayProtoFunctions[arrayFunc].apply(this, args);\r\n // }\r\n // }\r\n});\r\n\r\nclass TrackedArray extends Array implements ITrackedArray {\r\n $isTracked = true;\r\n\r\n constructor(\r\n private parentObj: T & ITrackedClass,\r\n private propertyName: string,\r\n private changesIgnored: boolean,\r\n private historyIgnored: boolean,\r\n source?: A[]\r\n ) {\r\n super();\r\n\r\n if (source) {\r\n for (let i = 0; i < source.length; i++) {\r\n __arrayProtoFunctions.push.call(this, source[i]);\r\n }\r\n }\r\n }\r\n\r\n push(...items: A[]) {\r\n if (!this.changesIgnored) {\r\n this.parentObj.setPropertyIsModified(this.propertyName, true);\r\n if (!this.historyIgnored) {\r\n history.changeEvents(\r\n this,\r\n items.map(item => ({\r\n property: this.length,\r\n operation: EChangeOperation.Push,\r\n value: item,\r\n originalValue: undefined,\r\n }))\r\n );\r\n }\r\n }\r\n\r\n const res = __arrayProtoFunctions.push.apply(this, items); // super.push(...items);\r\n for (const item of items) {\r\n this.parentObj.addedToChildArray(this.parentObj, item, this.propertyName);\r\n }\r\n return res;\r\n }\r\n\r\n unshift(...items: A[]) {\r\n if (!this.changesIgnored) {\r\n this.parentObj.setPropertyIsModified(this.propertyName, true);\r\n if (!this.historyIgnored) {\r\n history.changeEvents(\r\n this,\r\n items.map(item => ({\r\n property: 0,\r\n operation: EChangeOperation.Push,\r\n value: item,\r\n originalValue: undefined,\r\n }))\r\n );\r\n }\r\n }\r\n const res = __arrayProtoFunctions.unshift.apply(this, items); // super.unshift(...items);\r\n\r\n for (const item of items) {\r\n this.parentObj.addedToChildArray(this.parentObj, item, this.propertyName);\r\n }\r\n\r\n return res;\r\n }\r\n\r\n shift(destroy?: boolean): A {\r\n const result = __arrayProtoFunctions.shift.apply(this); // super.shift();\r\n if (!this.changesIgnored) {\r\n this.parentObj.setPropertyIsModified(this.propertyName, true);\r\n if (!this.historyIgnored) {\r\n history.changeEvent(this, 0, undefined, result, EChangeOperation.Shift);\r\n }\r\n }\r\n if (destroy && isTrackedClass(result)) {\r\n result.destroy();\r\n }\r\n this.parentObj.addedToChildArray(this.parentObj, result, this.propertyName);\r\n\r\n return result;\r\n }\r\n\r\n pop(destroy?: boolean): A {\r\n const result = __arrayProtoFunctions.pop.apply(this); // super.pop();\r\n if (!this.changesIgnored) {\r\n this.parentObj.setPropertyIsModified(this.propertyName, true);\r\n if (!this.historyIgnored) {\r\n history.changeEvent(this, this.length, undefined, result, EChangeOperation.Pop);\r\n }\r\n }\r\n if (destroy && isTrackedClass(result)) {\r\n result.destroy();\r\n }\r\n this.parentObj.addedToChildArray(this.parentObj, result, this.propertyName);\r\n return result;\r\n }\r\n\r\n splice(start: number, deleteCount: number | undefined, ...insert: A[]): A[] {\r\n // const result = Array.prototype.splice.call(array, start, deleteCount || 0, ...insert);\r\n let result: A[];\r\n if (insert.length === 0) {\r\n result = __arrayProtoFunctions.splice.apply(this, [start, deleteCount]); // super.splice(start, deleteCount);\r\n } else {\r\n result = __arrayProtoFunctions.splice.apply(this, [start, deleteCount || 0, ...insert]); // super.splice(start, deleteCount || 0, ...insert);\r\n }\r\n\r\n result.forEach(resultItem => {\r\n if (isTrackedClass(resultItem)) {\r\n resultItem.destroy();\r\n }\r\n });\r\n for (const item of result) {\r\n this.parentObj.removedFromChildArray(this.parentObj, item, this.propertyName);\r\n }\r\n for (const item of insert) {\r\n this.parentObj.addedToChildArray(this.parentObj, item, this.propertyName);\r\n }\r\n\r\n if (!this.changesIgnored) {\r\n this.parentObj.setPropertyIsModified(this.propertyName, true);\r\n if (!this.historyIgnored) {\r\n history.changeEvent(this, start, insert, result, EChangeOperation.Splice);\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n remove(item: A): A[] {\r\n const index = this.indexOf(item);\r\n if (index > -1) {\r\n return this.splice(index, 1);\r\n }\r\n return [];\r\n }\r\n\r\n reorder(fromIndex: number, toIndex: number, undo: boolean) {\r\n __arrayProtoFunctions.reorder.apply(this, [fromIndex, toIndex, undo]);\r\n\r\n if (!this.changesIgnored) {\r\n this.parentObj.setPropertyIsModified(this.propertyName, true);\r\n }\r\n }\r\n}\r\n\r\n/** Decorator to track the properties of a class. Used in conjunction with the change tracker class.\r\n * Properties with this decorator will be watched by the change tracker\r\n * @param {Object} options decorator options object\r\n * @param {Function} options.onCreate function that is called when a new class instance is created. Called with the proxy object that was created.\r\n */\r\nexport function TrackChanges(options?: TrackChangesOptions) {\r\n const onCreateCallback = options ? options.onCreate : undefined;\r\n const isPropertyEqualOverride = options ? options.isPropertyEqual : undefined;\r\n const onDestroy = options ? options.onDestroy : undefined;\r\n const addedToChildArray = options ? options.addedToChildArray : undefined;\r\n const removedFromChildArray = options ? options.removedFromChildArray : undefined;\r\n\r\n return (targetClass: C) => {\r\n const TrackedClass = class extends targetClass implements ITrackedClass {\r\n get $changesTracked() {\r\n return true;\r\n }\r\n\r\n setPropertyIsModified() {}\r\n destroy() {}\r\n\r\n constructor(...args: any[]) {\r\n super(...args);\r\n const trackingState: { isModified: boolean; baseObject: any } = {\r\n baseObject: this,\r\n isModified: false,\r\n };\r\n\r\n if (typeof this.originalValues === 'undefined') {\r\n Object.defineProperties(this, {\r\n changes: {\r\n value: new Map(),\r\n enumerable: false,\r\n writable: false,\r\n configurable: false,\r\n },\r\n originalValues: {\r\n value: new Map(),\r\n enumerable: false,\r\n writable: false,\r\n configurable: false,\r\n },\r\n _trackChanges: {\r\n value: false,\r\n enumerable: false,\r\n writable: true,\r\n configurable: false,\r\n },\r\n isModified: {\r\n configurable: false,\r\n enumerable: false,\r\n set: () => {},\r\n get: () => trackingState.isModified,\r\n },\r\n commitChanges: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: (inherited = false) => commitChanges(this, inherited),\r\n },\r\n setPropertyIsModified: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: setPropertyIsModified,\r\n },\r\n destroy: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: () => destroy(this),\r\n },\r\n trackChanges: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: (active: boolean) => (this._trackChanges = active),\r\n },\r\n rawNode: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: trackingState.baseObject,\r\n },\r\n });\r\n }\r\n\r\n const changedValuesMap: Map = this.changes;\r\n const originalValuesMap: Map = this.originalValues;\r\n\r\n const proxy = new Proxy(this, {\r\n // get: (target, property) => {\r\n // if (property === 'isModified') {\r\n // return trackingState.isModified;\r\n // } else if (property === 'commitChanges') {\r\n // return (inherited: boolean = false) => commitChanges(target, inherited);\r\n // } else if (property === 'setPropertyIsModified') {\r\n // return setPropertyIsModified;\r\n // } else if (property === 'addedToChildArray') {\r\n // return addedToChildArray ? addedToChildArray : () => { }\r\n // } else if (property === 'removedFromChildArray') {\r\n // return removedFromChildArray ? removedFromChildArray : () => { }\r\n // } else if (property === 'destroy') {\r\n // return () => destroy(target);\r\n // } else if (property === 'trackChanges') {\r\n // return (active: boolean) => this._trackChanges = active;\r\n // } else if (property === 'rawNode') {\r\n // return trackingState.baseObject;\r\n // }\r\n // return target[property as string];\r\n // },\r\n set: (target, property, newValue) => {\r\n // Allow clearing changes by setting is modified to false.\r\n if (property === 'isModified') {\r\n if (newValue === false && newValue !== trackingState.isModified) {\r\n originalValuesMap.clear();\r\n changedValuesMap.clear();\r\n updateIsModified();\r\n } else if (newValue === true) {\r\n for (const key in target) {\r\n setPropertyIsModified(key, true);\r\n }\r\n }\r\n return true;\r\n // Throw type error on trying to redefine decorator functions\r\n } else if (property === 'setPropertyIsModified') {\r\n return false;\r\n } else {\r\n // If object is not being tracked, just set the value without tracking the changes\r\n if (!this._trackChanges) {\r\n return Reflect.set(trackingState.baseObject, property, newValue);\r\n }\r\n\r\n const changesIgnored =\r\n Reflect.has(target, '_changesIgnoredProperties') &&\r\n Reflect.get(target, '_changesIgnoredProperties').has(property);\r\n const historyIgnored =\r\n Reflect.has(target, '_historyIgnoredProperties') &&\r\n Reflect.get(target, '_historyIgnoredProperties').has(property);\r\n\r\n // If the value is an array, then we have to proxy the array to pick up new array elements\r\n // Important that this occurs even if the object is not being tracked because\r\n // parent node management will break without the array proxy\r\n if (Array.isArray(newValue)) {\r\n newValue = new TrackedArray(\r\n proxy,\r\n property.toString(),\r\n changesIgnored,\r\n historyIgnored,\r\n newValue\r\n );\r\n }\r\n\r\n if (!changesIgnored) {\r\n const originalValue = originalValuesMap.get(property.toString());\r\n const currentValue = Reflect.get(target, property);\r\n\r\n // If the new value is the same as previous, do nothing.\r\n if (\r\n isPropertyEqualOverride &&\r\n isPropertyEqualOverride(currentValue, newValue, property as any)\r\n ) {\r\n return true;\r\n } else if (currentValue === newValue) {\r\n return true;\r\n }\r\n\r\n // Skip checks if originalValue is null. It means isModified is forced to be true until node is processed.\r\n if (originalValue !== null) {\r\n if (!originalValue) {\r\n // If the value is changed and was never changed before, register the change\r\n originalValuesMap.set(property.toString(), currentValue);\r\n } else {\r\n let isPropertyModified: boolean;\r\n // If the value was changed before, see if it's the same as the original value.\r\n let isEqualToOriginal: boolean | undefined;\r\n if (isPropertyEqualOverride) {\r\n isEqualToOriginal = isPropertyEqualOverride(\r\n originalValue,\r\n newValue,\r\n property as any\r\n );\r\n }\r\n if (typeof isEqualToOriginal !== 'undefined') {\r\n isPropertyModified = !isEqualToOriginal;\r\n } else {\r\n isPropertyModified = originalValue !== newValue;\r\n }\r\n\r\n // If the value is the same as the original, de-register the change\r\n if (!isPropertyModified) {\r\n originalValuesMap.delete(property.toString());\r\n }\r\n }\r\n\r\n updateIsModified();\r\n }\r\n }\r\n if (originalValuesMap.has(property.toString())) {\r\n changedValuesMap.set(property.toString(), newValue);\r\n } else {\r\n changedValuesMap.delete(property.toString());\r\n }\r\n\r\n return Reflect.set(trackingState.baseObject, property, newValue);\r\n }\r\n },\r\n });\r\n // Don't register changes in the history when creating new objects as they have to be registered as new objects instead.\r\n history.ignoreUntilStable(proxy);\r\n\r\n // The sync service won't have the right proxy object when a new object is created\r\n SyncService.registerNewObject(proxy);\r\n\r\n // The properties set on the object in the constructor won't be tracked because the original constructor runs before\r\n // the object is proxied.\r\n let trackedNewProperty = false;\r\n for (const property in this) {\r\n if (!this._changesIgnoredProperties || !this._changesIgnoredProperties.has(property)) {\r\n if (Array.isArray(this[property])) {\r\n const arrayHistoryIgnored =\r\n this._historyIgnoredProperties && this._historyIgnoredProperties.has(property);\r\n // We've already filtered out change ignored properties above\r\n this[property] = new TrackedArray(\r\n proxy,\r\n property.toString(),\r\n false,\r\n arrayHistoryIgnored,\r\n this[property]\r\n ) as any;\r\n }\r\n originalValuesMap.set(property, this[property]);\r\n changedValuesMap.set(property, this[property]);\r\n trackedNewProperty = true;\r\n }\r\n }\r\n if (trackedNewProperty) {\r\n updateIsModified();\r\n }\r\n\r\n if (onCreateCallback) {\r\n onCreateCallback(proxy as unknown as T & ITrackedClass);\r\n }\r\n\r\n return proxy;\r\n\r\n function updateIsModified() {\r\n // If the original value map is not empty, we have some pending changes so this object is considered modified\r\n if (trackingState.isModified !== originalValuesMap.size > 0) {\r\n trackingState.isModified = originalValuesMap.size > 0;\r\n SyncService.registerChangedState(proxy, trackingState.isModified);\r\n }\r\n }\r\n\r\n function commitChanges(target: any, inherited: boolean) {\r\n if (trackingState.isModified) {\r\n if (!inherited) {\r\n // Register the change on the history\r\n originalValuesMap.forEach((oldValue, property) => {\r\n const historyIgnored =\r\n Reflect.has(target, '_historyIgnoredProperties') &&\r\n Reflect.get(target, '_historyIgnoredProperties').has(property);\r\n\r\n if (!historyIgnored) {\r\n history.changeEvent(proxy, property, trackingState.baseObject[property], oldValue);\r\n }\r\n });\r\n\r\n originalValuesMap.clear();\r\n changedValuesMap.clear();\r\n }\r\n updateIsModified();\r\n }\r\n SyncService.nodeChangesProcessed(target);\r\n }\r\n\r\n function setPropertyIsModified(prop: string, modified: boolean) {\r\n if (modified) {\r\n // When forcing a property as modified, set the original value to null so it stays modified until processed (never matches)\r\n originalValuesMap.set(prop, null);\r\n changedValuesMap.set(prop, proxy[prop]);\r\n } else {\r\n originalValuesMap.delete(prop);\r\n changedValuesMap.delete(prop);\r\n }\r\n updateIsModified();\r\n }\r\n\r\n function destroy(target: any) {\r\n if (onDestroy) {\r\n onDestroy(proxy as unknown as T & ITrackedClass);\r\n }\r\n SyncService.registerDeleted(proxy);\r\n const inheritedDestroyFunc = Object.getPrototypeOf(target).destroy;\r\n if (typeof inheritedDestroyFunc === 'function') {\r\n inheritedDestroyFunc();\r\n }\r\n }\r\n }\r\n };\r\n\r\n Object.defineProperties(TrackedClass.prototype, {\r\n addedToChildArray: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: addedToChildArray ? addedToChildArray : () => {},\r\n },\r\n removedFromChildArray: {\r\n configurable: false,\r\n enumerable: false,\r\n writable: false,\r\n value: removedFromChildArray ? removedFromChildArray : () => {},\r\n },\r\n });\r\n\r\n return TrackedClass;\r\n };\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/ban-types\r\nexport function NodeReference(classRef: Function & { prototype: T }, ...keys: Array) {\r\n return (target: any, propertyKey: string, parameterIndex?: number) => {\r\n if (typeof target.nodeReferences === 'undefined') {\r\n Object.defineProperty(target, 'nodeReferences', {\r\n value: new Map(),\r\n enumerable: false,\r\n writable: false,\r\n configurable: false,\r\n });\r\n }\r\n\r\n target.nodeReferences.set(propertyKey, {\r\n classRef,\r\n limitKeys: keys.length > 0 ? new Set(keys) : undefined,\r\n });\r\n };\r\n}\r\n\r\n/** Property decorator to ignore changes on some properties. The node will not be processed if only ignored properties change. */\r\nexport function IgnoreChanges(target: any, propertyKey: string, parameterIndex?: number) {\r\n if (typeof target._changesIgnoredProperties === 'undefined') {\r\n Object.defineProperty(target, '_changesIgnoredProperties', {\r\n value: new Map(),\r\n enumerable: false,\r\n writable: false,\r\n configurable: false,\r\n });\r\n }\r\n\r\n target._changesIgnoredProperties.set(propertyKey, true);\r\n}\r\n\r\n/** Property decorator to ignore history on some properties. The property changing will not trigger history additions. */\r\nexport function IgnoreHistory(target: any, propertyKey: string, parameterIndex?: number) {\r\n if (typeof target._historyIgnoredProperties === 'undefined') {\r\n Object.defineProperty(target, '_historyIgnoredProperties', {\r\n value: new Map(),\r\n enumerable: false,\r\n writable: false,\r\n configurable: false,\r\n });\r\n }\r\n\r\n target._historyIgnoredProperties.set(propertyKey, true);\r\n}\r\n\r\nexport interface TrackChangesOptions {\r\n /** Function to run on creation of class instance.\r\n * @param proxyObj the constructed class instance proxy object.\r\n */\r\n onCreate?: (proxyObj: T & ITrackedClass) => void;\r\n /** Function to run on removal of class instance - called manually, or when removed from an array.\r\n * @param proxyObj the constructed class instance proxy object.\r\n */\r\n onDestroy?: (proxyObj: T & ITrackedClass) => void;\r\n /** Function to run on undoing removing a class instance from the scene. If we need to undo anything that was destroyed in the onDestroy hook.\r\n * @param proxyObj the constructed class instance proxy object.\r\n */\r\n onUndestroy?: (proxyObj: T & ITrackedClass) => void;\r\n /** Function to override the changed check behavior for certain properties on this class.\r\n * If property has not changed compared to the original value, then change queue will be cleared.\r\n * @param originalValue the old value A to compare against\r\n * @param newValue the new value B to compare against\r\n * @param name the property name being changed\r\n * @returns boolean or undefined. If undefined, will fall back to strict equality check for property.\r\n */\r\n isPropertyEqual?: (originalValue: any, newValue: any, name: keyof T) => boolean | undefined;\r\n /**\r\n * Function called when an item is added to a property array of the tracked class\r\n */\r\n addedToChildArray?: (parent: T & ITrackedClass, item: any, arrayPropertyName: string) => void;\r\n /**\r\n * Function called when an item is removed from a property array of the tracked class\r\n */\r\n removedFromChildArray?: (parent: T & ITrackedClass, item: any, arrayPropertyName: string) => void;\r\n}\r\n","import { isTrackedClass, ITrackedClass } from '../../interfaces/tracked-class';\r\nimport { isPrimitive } from '../primitives/primitive-utilities';\r\nimport { Token } from '../token';\r\nimport { TrackChanges, TrackChangesOptions } from './change-tracker';\r\nimport { instanceOf } from './model-utils';\r\n\r\n/** Convenience decorator that sets up default options for Kb3dObjects with the change tracker */\r\nexport function TrackChangesNode(options: TrackChangesOptions = {}) {\r\n const origAddedToChildArray = options.addedToChildArray;\r\n options.addedToChildArray = (parent: T, item: any, arrayPropName: string) => {\r\n if (origAddedToChildArray) origAddedToChildArray(parent, item, arrayPropName);\r\n if (instanceOf(parent, Token.Kb3dObject) && instanceOf(item, Token.Kb3dObject)) {\r\n item._parent = parent;\r\n if (isTrackedClass(parent) && (parent as any)._trackChanges) {\r\n item.calculateParents();\r\n }\r\n }\r\n };\r\n\r\n const origDestroy = options.onDestroy;\r\n options.onDestroy = (item: T & ITrackedClass) => {\r\n if (origDestroy) origDestroy(item);\r\n\r\n const children = item.getChildren();\r\n for (let i = 0; i < children.length; i++) {\r\n const child = children[i];\r\n if (isTrackedClass(child)) {\r\n child.destroy();\r\n }\r\n }\r\n\r\n if (item._parent && instanceOf(item._parent, Token.Kb3dObject) && instanceOf(item, Token.Kb3dObject)) {\r\n if (item._parent._manager) {\r\n item._parent._manager.unregister(item);\r\n }\r\n }\r\n\r\n item._parent = undefined;\r\n item.isModified = false;\r\n };\r\n\r\n if (!options.isPropertyEqual) {\r\n options.isPropertyEqual = (oldValue, newValue, propertyKey) => {\r\n let result: boolean | undefined;\r\n\r\n // Check equality on node properties by handling arrays and KB primitives. Fall back to strict equality checks for other values.\r\n if (Array.isArray(oldValue) && Array.isArray(newValue)) {\r\n if (oldValue.length === newValue.length) {\r\n let isEqual = true;\r\n\r\n for (let i = 0; i < newValue.length; i++) {\r\n if (newValue[i] !== oldValue[i]) {\r\n isEqual = false;\r\n break;\r\n }\r\n }\r\n result = isEqual;\r\n } else {\r\n result = false;\r\n }\r\n } else if (isPrimitive(newValue)) {\r\n result = typeof oldValue !== 'undefined' && newValue.equal(oldValue);\r\n }\r\n // console.log('checking equality', oldValue, newValue, result);\r\n return result;\r\n };\r\n }\r\n\r\n return TrackChanges(options);\r\n}\r\n","import { KbColor } from './kb-color';\r\nimport { KbQuaternion } from './kb-quaternion';\r\nimport { IKbVectorLike, KbVector } from './kb-vector';\r\n\r\nexport function isKbVector(object: any): object is KbVector {\r\n return object && object.x !== undefined && object.y !== undefined && object.z !== undefined;\r\n}\r\n\r\nexport function isKbColor(object: any): object is KbColor {\r\n return (\r\n object && object.r !== undefined && object.g !== undefined && object.b !== undefined && object.a !== undefined\r\n );\r\n}\r\n\r\nexport function isKbQuaternion(object: any): object is KbQuaternion {\r\n return (\r\n object && object.x !== undefined && object.y !== undefined && object.z !== undefined && object.w !== undefined\r\n );\r\n}\r\n\r\nexport function isPrimitive(object: any) {\r\n return isKbVector(object) || isKbColor(object) || isKbQuaternion(object);\r\n}\r\n\r\nexport interface IBoundingBox {\r\n min: IKbVectorLike;\r\n max: IKbVectorLike;\r\n center: IKbVectorLike;\r\n}\r\n","import { Token } from '../token';\r\nimport { TrackChangesNode } from './change-tracker-node';\r\nimport { AbstractConstructor, IKb3dModel, Kb3dModels } from './model-utils';\r\n\r\n/** represents an instance of a class decorated by kb3dModel */\r\nexport interface IDecoratedModel {\r\n $type: keyof typeof Token;\r\n [key: string]: any;\r\n}\r\n\r\nexport function Kb3dModel(options: Partial> & Pick, 'token'>) {\r\n if (!('trackChanges' in options)) options.trackChanges = true; //if trackChanges was not provided, default to true\r\n\r\n const $type = options.token.key;\r\n\r\n return (constructor: C) => {\r\n //set the $type on the prototype so we can always retrieve it from an instance\r\n Object.defineProperty(constructor.prototype, '$type', {\r\n enumerable: false,\r\n writable: true,\r\n value: $type,\r\n });\r\n\r\n /** we bundle up the track changes decorator here as well, as we want our map storing the constructors of\r\n * our models to actually be storing the constructor of the track changes proxy... so that when a class\r\n * is constructed using \"create\" that it will actually create the proxy class.\r\n */\r\n if (options.trackChanges) {\r\n const trackChangesFactory = TrackChangesNode(options);\r\n const combinedConstructor = trackChangesFactory(constructor);\r\n options.classConstructor = combinedConstructor;\r\n } else {\r\n options.classConstructor = constructor;\r\n }\r\n Kb3dModels.set(options.token, options as IKb3dModel);\r\n };\r\n}\r\n\r\nexport function BaseKb3dModel(options: Partial> & Pick, 'token'>) {\r\n return >(constructor: C) => {\r\n options.classConstructor = constructor;\r\n Kb3dModels.set(options.token, options as IKb3dModel);\r\n };\r\n}\r\n","/**\r\n * Applied to a getter or setter property, will make it enumerable\r\n */\r\nexport function Enumerable() {\r\n return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\r\n descriptor.enumerable = true;\r\n };\r\n}\r\n","import { Token } from '../token';\r\nimport { Constructor, IKb3dModel } from './model-utils';\r\n\r\nexport interface IInjectParameter {\r\n classConstructor: Constructor;\r\n token: Token;\r\n parameterIndex: number;\r\n ignore: boolean;\r\n}\r\n\r\nexport const injectParameters: any[] = [];\r\n\r\nexport function Inject(token: Token) {\r\n return (target: Constructor, propertyKey: undefined, parameterIndex: number) => {\r\n injectParameters.push({\r\n token: token,\r\n classConstructor: target,\r\n parameterIndex,\r\n ignore: false,\r\n });\r\n };\r\n}\r\n\r\nexport function Ignore() {\r\n return (target: Constructor, propertyKey: undefined, parameterIndex: number) => {\r\n injectParameters.push({\r\n token: Token.Ignore,\r\n classConstructor: target,\r\n parameterIndex,\r\n ignore: true,\r\n });\r\n };\r\n}\r\n\r\nexport function getConstructorParamsForModel(modelDef: IKb3dModel): IInjectParameter[] {\r\n let constructor: any;\r\n if (modelDef.trackChanges) {\r\n constructor = Object.getPrototypeOf(modelDef.classConstructor);\r\n } else {\r\n constructor = modelDef.classConstructor;\r\n }\r\n const paramsForType = injectParameters.filter(i => i.classConstructor == constructor);\r\n\r\n paramsForType.sortBy(p => p.index);\r\n if (modelDef.classConstructor && paramsForType.length < modelDef.classConstructor.length) {\r\n throw new Error(\r\n 'You must decorate every constructor parameter with an @Inject or @Ignore decorator for type ' +\r\n modelDef.token.key\r\n );\r\n }\r\n return paramsForType;\r\n}\r\n","import { IKb3dModel, Kb3dModels } from './model-utils';\r\n\r\nexport function Kb3dService(options: Partial> & Pick, 'token'>) {\r\n const $type = options.token.key;\r\n\r\n return (constructor: C) => {\r\n constructor.prototype.$type = $type;\r\n options.classConstructor = constructor;\r\n Kb3dModels.set(options.token, options as IKb3dModel);\r\n };\r\n}\r\n","export enum eParentChangeBehavior {\r\n PRESERVE_POSITION,\r\n PRESERVE_PROPERTY,\r\n}\r\nexport interface KbViewerSettings {\r\n parentChangeBehavior: eParentChangeBehavior;\r\n}\r\n","import { isTrackedClass, ITrackedClass } from '@models/interfaces';\r\nimport { IgnoreChanges } from './decorators/change-tracker';\r\nimport { Enumerable } from './decorators/enumerable';\r\nimport { BaseKb3dModel } from './decorators/kb3d-decorator';\r\nimport { instanceOf, instanceOfAny } from './decorators/model-utils';\r\nimport { Kb3dManager } from './kb3d-manager';\r\nimport { IKb3dObject } from './kb3d-models';\r\nimport { SceneNode } from './scene-node';\r\nimport { Token } from './token';\r\nimport { UUID } from './utilities';\r\n\r\nexport enum eNodeError {\r\n 'FEATURE_REFERENCE',\r\n 'GEOMETRY_SAVE',\r\n}\r\n\r\nexport interface INodeError {\r\n error: eNodeError;\r\n}\r\n\r\nexport type ValidationObject = {\r\n [K in keyof T]: string[];\r\n};\r\n\r\n/**\r\n * Base class for kb3d models. Any model that has an id and $type should derive from this class\r\n */\r\n@BaseKb3dModel({\r\n token: Token.Kb3dObject,\r\n})\r\nexport abstract class Kb3dObject implements IKb3dObject {\r\n constructor() {\r\n this.id = UUID.generate();\r\n this._dynamicId = UUID.generate();\r\n }\r\n\r\n public id: string;\r\n\r\n /**\r\n * Dynamically created id that is used to track assets in the 3d engine. Ensures there is\r\n * no duplicate id's when there are nested scenes.\r\n */\r\n public _dynamicId: string;\r\n\r\n @IgnoreChanges\r\n public name: string;\r\n\r\n @IgnoreChanges\r\n public $type: keyof typeof Token;\r\n\r\n get _token() {\r\n return Token.withKey(this.$type);\r\n }\r\n\r\n @IgnoreChanges\r\n public _manager: Kb3dManager | undefined;\r\n\r\n /**\r\n * The parent kb3dObject. This should not need to be set manually as adding nodes to arrays will set this automatically.\r\n * If this is a nested sceneNode, then _parent will be it's parent scene node\r\n * */\r\n public _parent: Kb3dObject | undefined;\r\n\r\n /** the closest ancestor this is a sceneNode. If this is a nested scene node, then _parentScene will be equal to itself */\r\n @IgnoreChanges\r\n public _parentScene: SceneNode | undefined;\r\n\r\n @IgnoreChanges\r\n private __rootScene: SceneNode | undefined;\r\n get _rootScene() {\r\n return this.__rootScene;\r\n }\r\n\r\n protected setRootScene(scene: SceneNode | undefined) {\r\n if (this.__rootScene !== scene) {\r\n this.__rootScene = scene;\r\n if (isTrackedClass(this)) {\r\n (this as ITrackedClass).trackChanges(!!scene);\r\n }\r\n }\r\n }\r\n\r\n @IgnoreChanges\r\n public _level = -1;\r\n\r\n @IgnoreChanges\r\n public _errors: INodeError[] = [];\r\n\r\n _selected = false;\r\n\r\n @IgnoreChanges\r\n _expanded = false;\r\n\r\n private _metadata: any;\r\n @Enumerable()\r\n public get metadata(): any {\r\n if (!this._metadata) this._metadata = {};\r\n return this._metadata;\r\n }\r\n public set metadata(val) {\r\n this._metadata = val;\r\n }\r\n\r\n public clone(this: T) {\r\n if (this._manager) {\r\n return this._manager.clone(this);\r\n }\r\n }\r\n\r\n public serialize(this: T): Partial | undefined {\r\n if (this._manager) {\r\n return this._manager.serialize(this);\r\n }\r\n }\r\n\r\n public serializeToJson(prettyPrint = false): string {\r\n if (this._manager) {\r\n return this._manager.serializeToJson(this, { prettyPrint });\r\n }\r\n return '';\r\n }\r\n\r\n public calculateParents(deletion = false, parent?: Kb3dObject) {\r\n // When a node is deleted and recreated, the children won't have parents because they were not re-added to the parent's arrays.\r\n // This solves that case by making sure the hierarchy is consistent from the top down\r\n if (parent && this._parent !== parent) {\r\n this._parent = parent;\r\n }\r\n if (this._parent) {\r\n this._level = this._parent._level == -1 ? -1 : this._parent._level + 1;\r\n this._parentScene = this._parent._parentScene;\r\n this.setRootScene(this._parent._rootScene);\r\n if (instanceOf(this, Token.SceneNode)) {\r\n //it's a nested scene\r\n this._parentScene = this;\r\n } else {\r\n this._manager = this._parent._manager; // a nested scene uses it's own manager, but everything else should have the same as it's parent\r\n }\r\n if (this._parentScene && !deletion) {\r\n this._manager?.register(this);\r\n }\r\n } else if (instanceOf(this, Token.SceneNode) && !deletion) {\r\n this._level = 0;\r\n this._parentScene = this;\r\n this.setRootScene(this);\r\n this._manager?.register(this);\r\n } else {\r\n this._level = -1; // -1 means this is not part of a scene node hierarchy\r\n\r\n // TODO add this change after release on Jan 13 2023, test to ensure it works\r\n // if(isTrackedClass(this)) {\r\n // this.trackChanges(false);\r\n // }\r\n }\r\n\r\n for (const c of this.getChildren()) {\r\n c.calculateParents(deletion, this);\r\n }\r\n }\r\n\r\n /**\r\n * Derived classes that have children should override this\r\n */\r\n public getChildren(): Kb3dObject[] {\r\n return [];\r\n }\r\n\r\n /**\r\n * Derived classes with children should override this\r\n */\r\n public getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n return undefined;\r\n }\r\n\r\n public getChildArray(child: Kb3dObject) {\r\n return this.getChildArrayForType(Token.withKey(child.$type));\r\n }\r\n\r\n public addChildren(...children: Kb3dObject[]) {\r\n for (const c of children) {\r\n this.getChildArray(c)?.push(c);\r\n }\r\n }\r\n\r\n public removeChildren(...children: Kb3dObject[]) {\r\n for (const c of children) {\r\n this.getChildArray(c)?.remove(c);\r\n }\r\n }\r\n\r\n public insertChildAfter(afterChild: Kb3dObject, newChild: Kb3dObject) {\r\n const arr1 = this.getChildArray(afterChild);\r\n const arr2 = this.getChildArray(newChild);\r\n if (!arr1 || !arr2) throw 'incompatible child';\r\n if (arr1 !== arr2) throw 'children mismatch';\r\n const index = arr1.indexOf(afterChild);\r\n if (index === -1) throw 'could not find given child';\r\n arr1.splice(index + 1, 0, newChild);\r\n }\r\n\r\n public getAncestors() {\r\n const ancestors = new Array();\r\n let parent = this._parent;\r\n while (parent != null) {\r\n ancestors.push(parent);\r\n parent = parent._parent;\r\n }\r\n return ancestors;\r\n }\r\n\r\n public getNamePath() {\r\n let path = '';\r\n let self: Kb3dObject | undefined = this;\r\n while (self && !instanceOf(self, Token.SceneNode)) {\r\n path = self.name + (path ? '/' + path : '');\r\n self = self._parent;\r\n }\r\n return path;\r\n }\r\n\r\n /**\r\n * Filters children recursively based on a condition. This is an O(n) operation, so only use when performance is not paramount\r\n * @param predicate expression to test whether the object should be included\r\n * @param includeSelf whether to include this kb3dObject in the search\r\n * @param alwaysIncludeChildren if true, will always search children even if the parent resolves to false\r\n */\r\n public filter(\r\n predicate: (node: Kb3dObject) => boolean,\r\n includeSelf = false,\r\n alwaysIncludeChildren = true\r\n ): T[] {\r\n const res: Kb3dObject[] = [];\r\n let included = true;\r\n if (includeSelf && predicate(this)) {\r\n res.push(this);\r\n } else {\r\n included = false;\r\n }\r\n if (included || alwaysIncludeChildren) {\r\n const children = this.getChildren();\r\n for (const child of children) {\r\n res.push(...child.filter(predicate, true, alwaysIncludeChildren));\r\n }\r\n }\r\n\r\n return res as T[];\r\n }\r\n\r\n /**\r\n * filters children by type given a list of type tokens\r\n * @param tokens\r\n */\r\n public filterByType(...tokens: Array>): T[] {\r\n return this.filter(node => instanceOfAny(node, ...tokens)) as T[];\r\n }\r\n\r\n /**\r\n * filters children, but only those that qualify as nodes\r\n * @param predicate\r\n * @param includeSelf\r\n * @param alwaysIncludeChildren\r\n */\r\n public filterNodes(\r\n predicate: (node: Kb3dObject) => boolean,\r\n includeSelf = false,\r\n alwaysIncludeChildren = true\r\n ): T[] {\r\n const nodePredicate = (node: Kb3dObject) => node.isNode() && predicate(node);\r\n return this.filter(nodePredicate, includeSelf, alwaysIncludeChildren);\r\n }\r\n\r\n public isNode() {\r\n return this._token.isNode();\r\n }\r\n}\r\n","import { BaseKb3dModel, instanceOf } from '../decorators';\r\nimport { IFeature } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { TextureLayer } from '../materials';\r\nimport { SpaceNode } from '../meshes';\r\nimport { Token } from '../token';\r\n\r\nexport enum eMeshChangeTypes {\r\n VertexIndices,\r\n VertexPositions,\r\n VertexNormals,\r\n VertexUvs,\r\n Submeshes,\r\n Transform,\r\n}\r\n\r\nexport const ALL_GEOMETRY = [\r\n eMeshChangeTypes.VertexIndices,\r\n eMeshChangeTypes.VertexPositions,\r\n eMeshChangeTypes.VertexNormals,\r\n eMeshChangeTypes.VertexUvs,\r\n eMeshChangeTypes.Submeshes,\r\n];\r\n\r\nexport const ALL_CHANGES = [...ALL_GEOMETRY, eMeshChangeTypes.Transform];\r\n\r\nexport type FeatureWithTextures = Feature & { textures: TextureLayer[] };\r\n\r\n@BaseKb3dModel({\r\n token: Token.Feature,\r\n})\r\nexport abstract class Feature extends Kb3dObject implements IFeature {\r\n /**\r\n * Defines what kinds of geometry this feature depends on to function; if earlier features\r\n * that affect this geometry kind are modified, added or removed, then this feature gets disabled.\r\n * */\r\n static _dependsOn?: Set;\r\n\r\n /**\r\n * Defines what kinds of geometry this feature will affect; if this geometry kind is reset on the mesh,\r\n * then this feature will be re-processed.\r\n */\r\n static _affects?: Set;\r\n\r\n /**\r\n * Defines what geometry changes will cause this feature to require an update\r\n */\r\n static _affectedBy?: Set;\r\n\r\n get dependsOn() {\r\n return (this.constructor as typeof Feature)._dependsOn;\r\n }\r\n\r\n get affects() {\r\n return (this.constructor as typeof Feature)._affects;\r\n }\r\n\r\n get affectedBy() {\r\n return (this.constructor as typeof Feature)._affectedBy;\r\n }\r\n\r\n constructor() {\r\n super();\r\n }\r\n\r\n public enabled: boolean;\r\n public _suppressed = false;\r\n\r\n //this gets set to true when a change in the feature stack causes this feature to break\r\n public _disableFeatureStackChange: boolean;\r\n\r\n /** override base parent for more specific typing*/\r\n public _parent: SpaceNode | undefined;\r\n\r\n public getAncestors() {\r\n return super.getAncestors() as SpaceNode[];\r\n }\r\n}\r\n\r\nexport function isFeatureNode(node: Kb3dObject): node is Feature {\r\n return instanceOf(node, Token.Feature);\r\n}\r\n","import { BaseKb3dModel } from '../decorators';\r\nimport { eConnectorPositionMode } from '../enums';\r\nimport { IBaseConnector } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { SpaceNode } from '../meshes/space-node';\r\nimport { IKbVectorLike, KbVector } from '../primitives';\r\nimport { Token } from '../token';\r\n\r\n@BaseKb3dModel({\r\n token: Token.BaseConnector,\r\n})\r\nexport abstract class BaseConnector extends Kb3dObject implements IBaseConnector {\r\n public enabled: boolean;\r\n public positionMode: eConnectorPositionMode;\r\n public position: KbVector;\r\n public direction: KbVector;\r\n public angle: number;\r\n public tag: string;\r\n public positionZeroToOne: number;\r\n public interpolateDirection: boolean;\r\n\r\n public _visible: boolean;\r\n public _isPickable: boolean;\r\n public _sketchControlPoints: IKbVectorLike[] = [];\r\n\r\n /** Extended by child classes to return the space node parent of this connector */\r\n public getSpaceParent(): SpaceNode | undefined {\r\n return undefined;\r\n }\r\n}\r\n","let defaults = {\r\n AnnotationNode: {\r\n enabled: true,\r\n label: null,\r\n fontFamily: null,\r\n fontSize: 0.1,\r\n lineSpacing: 0,\r\n preloadFontStylesheet: \"\",\r\n color: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n targetId: null,\r\n billboard: false,\r\n isPickable: false,\r\n keepOnTop: false,\r\n lineStyle: \"solid\",\r\n horizontalTextAlign: \"left\",\r\n verticalBoxAlign: \"middle\",\r\n horizontalBoxAlign: \"center\",\r\n offset: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n name: null,\r\n metadata: {},\r\n },\r\n DimensionNode: {\r\n target2Id: null,\r\n lineCapStyle: \"line\",\r\n axis: \"free\",\r\n lineThickness: 0.05,\r\n dimensionGap: 0.1,\r\n dimensionUnitPrecision: 2,\r\n labelOffset: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n scaleWithCamera: false,\r\n enabled: true,\r\n label: null,\r\n fontFamily: null,\r\n fontSize: 0.1,\r\n lineSpacing: 0,\r\n preloadFontStylesheet: \"\",\r\n color: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n targetId: null,\r\n billboard: false,\r\n isPickable: false,\r\n keepOnTop: false,\r\n lineStyle: \"solid\",\r\n horizontalTextAlign: \"left\",\r\n verticalBoxAlign: \"middle\",\r\n horizontalBoxAlign: \"center\",\r\n offset: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n name: null,\r\n metadata: {},\r\n },\r\n BaseConnector: {\r\n positionMode: \"boundingBox\",\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n direction: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n angle: 0,\r\n positionZeroToOne: 0,\r\n interpolateDirection: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n Connector: {\r\n enabled: true,\r\n positionMode: \"boundingBox\",\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n direction: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n angle: 0,\r\n positionZeroToOne: 0,\r\n interpolateDirection: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n CircularPatternFeature: {\r\n arc: 360,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n axis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n count: 1,\r\n meshId: null,\r\n distance: 1,\r\n addEndMesh: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n DeleteFacesFeature: {\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n DisplacementMapFeature: {\r\n minDisplacement: 0,\r\n maxDisplacement: 1,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n ExtrudeFeature: {\r\n size: 0,\r\n capEnd: false,\r\n capStart: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n Feature: {\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n JoinGeometryFeature: {\r\n joinType: \"cut\",\r\n meshId: null,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n LinearPatternFeature: {\r\n translation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n count: 1,\r\n meshId: null,\r\n distance: 1,\r\n addEndMesh: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n MirrorFeature: {\r\n cloneGeometry: false,\r\n intersect: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n normal: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n removeGeometry: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n MoveVerticesFeature: {\r\n translation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scale: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n center: \"barycenter\",\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n NormalSmoothingFeature: {\r\n smooth: true,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n PatternFeature: {\r\n count: 1,\r\n meshId: null,\r\n distance: 1,\r\n addEndMesh: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n SliceFeature: {\r\n intersect: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n normal: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n removeGeometry: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n SubmeshFeature: {\r\n uvMapping: false,\r\n materialId: null,\r\n center: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n projectionAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n angle: 0,\r\n scale: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n uTile: 1,\r\n vTile: 1,\r\n uOffset: 0,\r\n vOffset: 0,\r\n mode: \"planar\",\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n SweepFeature: {\r\n start: null,\r\n end: null,\r\n path: null,\r\n mitredExtrusion: false,\r\n size: 0,\r\n capEnd: false,\r\n capStart: false,\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n TransformFeature: {\r\n scale: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n UvMapFeature: {\r\n center: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n projectionAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n angle: 0,\r\n scale: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n uTile: 1,\r\n vTile: 1,\r\n uOffset: 0,\r\n vOffset: 0,\r\n mode: \"planar\",\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n WeldVerticesFeature: {\r\n enabled: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n Kb3dObject: {\r\n name: null,\r\n metadata: {},\r\n },\r\n DirectionalLightNode: {\r\n direction: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n generatesShadows: false,\r\n shadowQuality: \"medium\",\r\n shadowResolution: \"low\",\r\n shadowFilter: \"simple\",\r\n processTransparency: false,\r\n intensity: 1,\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n HemisphericLightNode: {\r\n direction: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n groundColor: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n intensity: 1,\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n LightNode: {\r\n intensity: 1,\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n PointLightNode: {\r\n generatesShadows: false,\r\n shadowQuality: \"medium\",\r\n shadowResolution: \"low\",\r\n shadowFilter: \"simple\",\r\n processTransparency: false,\r\n intensity: 1,\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n ShadowLightNode: {\r\n generatesShadows: false,\r\n shadowQuality: \"medium\",\r\n shadowResolution: \"low\",\r\n shadowFilter: \"simple\",\r\n processTransparency: false,\r\n intensity: 1,\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n SpotLightNode: {\r\n coneAngle: 60,\r\n direction: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n generatesShadows: false,\r\n shadowQuality: \"medium\",\r\n shadowResolution: \"low\",\r\n shadowFilter: \"simple\",\r\n processTransparency: false,\r\n intensity: 1,\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n AdvancedMaterialNode: {\r\n workflowMode: \"metallicRoughness\",\r\n backFaceCulling: false,\r\n directIntensity: 1,\r\n emissiveIntensity: 1,\r\n environmentIntensity: 1,\r\n specularIntensity: 1,\r\n metallic: 0,\r\n roughness: 1,\r\n microSurface: 1,\r\n useSpecularOverAlpha: true,\r\n useRadianceOverAlpha: true,\r\n ambientColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n albedoColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n specularColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n reflectionColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n anisotropyEnabled: false,\r\n anisotropicDirection: {\"$type\":\"KbVector\",\"x\":1.0,\"y\":1.0,\"z\":1.0},\r\n anisotropicIntensity: 1,\r\n subsurfaceThickness: 1,\r\n subsurfaceRefractionEnabled: false,\r\n subsurfaceReflectionEnabled: false,\r\n reflectionType: \"plane\",\r\n probePositionTargetId: null,\r\n subsurfaceRefractionIndex: 1,\r\n subsurfaceRefractionIntensity: 1,\r\n subsurfaceRefractionLinkTransparency: false,\r\n subsurfaceTranslucencyEnabled: false,\r\n subsurfaceTranslucencyIntensity: 1,\r\n subsurfaceUseAlbedoForTintColor: true,\r\n subsurfaceTintColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n clearcoatEnabled: false,\r\n clearcoatIntensity: 1,\r\n clearcoatTintEnabled: false,\r\n clearcoatTintColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n clearcoatTintIntensity: 0.1,\r\n archived: false,\r\n location: \"local\",\r\n alpha: 1,\r\n zOffset: 0,\r\n doubleSided: false,\r\n legacyTextureStacking: true,\r\n viewMode: \"shaded\",\r\n emissiveColor: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n hasTransparency: false,\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n ColorFillTextureLayer: {\r\n color: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n width: 256,\r\n height: 256,\r\n enabled: true,\r\n strength: 1,\r\n tile: false,\r\n maintainAspect: false,\r\n useClippingMask: false,\r\n blendMode: \"normal\",\r\n horizontalAlign: \"center\",\r\n verticalAlign: \"middle\",\r\n horizontalFit: \"none\",\r\n verticalFit: \"none\",\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n FileTextureLayer: {\r\n width: 256,\r\n height: 256,\r\n flipNormalsRg: false,\r\n enabled: true,\r\n strength: 1,\r\n tile: false,\r\n maintainAspect: false,\r\n useClippingMask: false,\r\n blendMode: \"normal\",\r\n horizontalAlign: \"center\",\r\n verticalAlign: \"middle\",\r\n horizontalFit: \"none\",\r\n verticalFit: \"none\",\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n MaterialMapping: {\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n MaterialNode: {\r\n location: \"local\",\r\n alpha: 1,\r\n zOffset: 0,\r\n reflectionType: \"plane\",\r\n doubleSided: false,\r\n legacyTextureStacking: true,\r\n viewMode: \"shaded\",\r\n emissiveColor: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n hasTransparency: false,\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n SvgTextureLayer: {\r\n width: 256,\r\n height: 256,\r\n preloadFontStylesheet: \"\",\r\n enabled: true,\r\n strength: 1,\r\n tile: false,\r\n maintainAspect: false,\r\n useClippingMask: false,\r\n blendMode: \"normal\",\r\n horizontalAlign: \"center\",\r\n verticalAlign: \"middle\",\r\n horizontalFit: \"none\",\r\n verticalFit: \"none\",\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n TextTextureLayer: {\r\n text: \"\",\r\n color: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n enabled: true,\r\n strength: 1,\r\n tile: false,\r\n maintainAspect: false,\r\n useClippingMask: false,\r\n blendMode: \"normal\",\r\n horizontalAlign: \"center\",\r\n verticalAlign: \"middle\",\r\n horizontalFit: \"none\",\r\n verticalFit: \"none\",\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n TextureLayer: {\r\n enabled: true,\r\n strength: 1,\r\n tile: false,\r\n maintainAspect: false,\r\n useClippingMask: false,\r\n blendMode: \"normal\",\r\n horizontalAlign: \"center\",\r\n verticalAlign: \"middle\",\r\n horizontalFit: \"none\",\r\n verticalFit: \"none\",\r\n uOffset: 0,\r\n vOffset: 0,\r\n uScale: 1,\r\n vScale: 1,\r\n uAngle: 0,\r\n vAngle: 0,\r\n wAngle: 0,\r\n uPivot: 0.5,\r\n vPivot: 0.5,\r\n wPivot: 0.5,\r\n name: null,\r\n metadata: {},\r\n },\r\n MateNode: {\r\n enabled: true,\r\n connector1: null,\r\n connector2: null,\r\n mateType: \"fastened\",\r\n flip: false,\r\n offsetX: 0,\r\n offsetY: 0,\r\n offsetZ: 0,\r\n offsetAngle: 0,\r\n name: null,\r\n metadata: {},\r\n },\r\n BoxNode: {\r\n height: 1,\r\n width: 1,\r\n depth: 1,\r\n tessellation: 1,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n ConeNode: {\r\n height: 1,\r\n radiusTop: 0,\r\n radiusBottom: 0.5,\r\n tessellation: 24,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n CustomMeshNode: {\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n CylinderNode: {\r\n height: 1,\r\n radius: 0.5,\r\n arc: 360,\r\n tessellation: 24,\r\n subdivisions: 1,\r\n capMode: \"both\",\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n DiscNode: {\r\n radius: 0.5,\r\n tessellation: 64,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n GroundNode: {\r\n height: 1,\r\n width: 1,\r\n subdivisions: 1,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n MeshGroupNode: {\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n MeshNode: {\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n PlaneNode: {\r\n depth: 4,\r\n width: 4,\r\n segments: 1,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n PrimitiveMeshNode: {\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n SketchControlPoint: {\r\n positionMode: \"absolute\",\r\n direction2: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":-1.0,\"z\":0.0},\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n direction: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n angle: 0,\r\n positionZeroToOne: 0,\r\n interpolateDirection: true,\r\n name: null,\r\n metadata: {},\r\n },\r\n SketchNode: {\r\n normal: \"y\",\r\n addFace: false,\r\n closePath: false,\r\n tracePath: false,\r\n lineThickness: 1,\r\n pathColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n flipPath: false,\r\n clonePath: null,\r\n boundingXOverride: null,\r\n boundingYOverride: null,\r\n boundingZOverride: null,\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n SketchPath: {\r\n pathGroupKey: \"default\",\r\n holeForPathGroup: null,\r\n type: \"points\",\r\n tessellation: 16,\r\n name: null,\r\n metadata: {},\r\n },\r\n SpaceNode: {\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n SphereNode: {\r\n tessellation: 32,\r\n radius: 0.5,\r\n latitudeStart: 0,\r\n latitudeSlice: 180,\r\n arc: 360,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n TextNode: {\r\n curveRadius: 0,\r\n charSpacing: 1,\r\n text: \"\",\r\n fontFile: \"\",\r\n fontSize: 1,\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n TorusNode: {\r\n radius: 0.5,\r\n thickness: 0.25,\r\n arc: 360,\r\n latitudeStart: 0,\r\n latitudeSlice: 360,\r\n tessellation: 16,\r\n sideOrientation: \"frontSide\",\r\n materialId: null,\r\n flipSurfaceOrientation: false,\r\n receiveShadows: false,\r\n castShadows: false,\r\n isPickable: true,\r\n checkCollisions: false,\r\n opacity: 1,\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n SceneNode: {\r\n background: \"transparent\",\r\n environment: \"library://adams_place_bridge\",\r\n environmentBlur: 0.27,\r\n environmentIntensity: 1,\r\n backgroundColor: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":0.0},\r\n ambientColor: {\"$type\":\"KbColor\",\"r\":0.0,\"g\":0.0,\"b\":0.0,\"a\":1.0},\r\n renderMode: \"shaded\",\r\n edgeColor: {\"$type\":\"KbColor\",\"r\":1.0,\"g\":1.0,\"b\":1.0,\"a\":1.0},\r\n edgeWidth: 1,\r\n edgeDisplayTolerance: 0.95,\r\n viewpointId: null,\r\n frameViewpoint: false,\r\n progressiveTextureLoad: true,\r\n enableDeferredSceneUpdates: true,\r\n enableGrid: false,\r\n enableGridAxes: false,\r\n gridSize: 10,\r\n gridStepSize: 1,\r\n gridMajorInterval: 1,\r\n gridNormal: \"y\",\r\n environmentRotation: 0,\r\n connectorSize: 0.1,\r\n enableFxaaPostProcess: false,\r\n enableLensEffectsPostProcess: false,\r\n enableSSAOPostProcess: false,\r\n textureSamplingMode: \"trilinear\",\r\n fullscreenEnabled: true,\r\n arEnabled: true,\r\n xrAllowScaling: false,\r\n unitsPerMeter: 1,\r\n xrAddShadow: true,\r\n xrLightingEstimation: false,\r\n enableHoverEffects: false,\r\n enableSceneOptimization: true,\r\n loadingExperience: \"spinner\",\r\n loadingImagePath: null,\r\n dimensionUnitScalar: 1,\r\n dimensionUnitSymbol: \"m\",\r\n conversionMap: {},\r\n visible: true,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n useEuler: false,\r\n eulerRotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n rotationAngle: 0,\r\n scaling: 1,\r\n pivot: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fixed: false,\r\n name: null,\r\n metadata: {},\r\n },\r\n ViewpointNode: {\r\n type: \"orbit\",\r\n targetMode: \"point\",\r\n projection: \"perspective\",\r\n offsetX: 0,\r\n offsetY: 0,\r\n position: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n targetPoint: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n targetMeshId: null,\r\n rotation: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":0.0,\"z\":0.0},\r\n fov: 50,\r\n allowOrbit: true,\r\n allowPan: true,\r\n allowZoom: true,\r\n limitMinimumTargetDistance: false,\r\n minTargetDistance: 0.001,\r\n maxTargetDistance: 10000,\r\n orbitAxis: {\"$type\":\"KbVector\",\"x\":0.0,\"y\":1.0,\"z\":0.0},\r\n limitLatOrbit: false,\r\n limitMinLatitude: 0,\r\n limitMaxLatitude: 180,\r\n limitLngOrbit: false,\r\n limitMinLongitude: -180,\r\n limitMaxLongitude: 180,\r\n name: null,\r\n metadata: {},\r\n },\r\n};\r\nexport { defaults };","import { BaseKb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IMaterialMapping } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\n\r\n@BaseKb3dModel({\r\n token: Token.MaterialMapping,\r\n})\r\nexport abstract class MaterialMapping extends Kb3dObject implements IMaterialMapping {\r\n uOffset = 0; // Define an offset on the texture to offset the u coordinates of the UVs\r\n vOffset = 0; // Define an offset on the texture to offset the v coordinates of the UVs\r\n uScale = 1; // Define an offset on the texture to scale the u coordinates of the UVs\r\n vScale = 1; // Define an offset on the texture to scale the v coordinates of the UVs\r\n uAngle = 0; // Define an offset on the texture to rotate around the u coordinates of the UVs\r\n vAngle = 0; // Define an offset on the texture to rotate around the v coordinates of the UVs\r\n wAngle = 0; // Define an offset on the texture to rotate around the w coordinates of the UVs\r\n uPivot = 0.5; // Defines the center of rotation (U)\r\n vPivot = 0.5; // Defines the center of rotation (V)\r\n wPivot = 0.5; // Defines the center of rotation (W)\r\n}\r\n","import { isTrackedClass } from '../../interfaces/tracked-class';\r\nimport { IMaterialService } from '../../services/material-service';\r\nimport { IgnoreChanges } from '../decorators/change-tracker';\r\nimport { Enumerable } from '../decorators/enumerable';\r\nimport { BaseKb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf, instanceOfAny } from '../decorators/model-utils';\r\nimport { defaults } from '../default-values';\r\nimport { eMaterialLocation, eMaterialViewMode, eReflectionType } from '../enums';\r\nimport { IMaterialNode, IReference, ITextureLayer } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { KbColor } from '../primitives/kb-color';\r\nimport { Token } from '../token';\r\nimport { isAbsoluteUrl } from '../utilities';\r\nimport { AdvancedMaterialNode } from './advanced-material-node';\r\nimport { MaterialMapping } from './material-mapping';\r\nimport { TextureLayer } from './texture-layer';\r\n\r\nconst NEVER_INHERIT = new Set([\r\n '$type',\r\n 'overriddenProperties',\r\n '_parentMaterial',\r\n 'parentMaterialId',\r\n 'location',\r\n 'children',\r\n '_selected',\r\n '_expanded',\r\n 'id',\r\n 'name',\r\n 'visible',\r\n '_parent',\r\n '_parentScene',\r\n '_rootScene',\r\n '_level',\r\n]);\r\n\r\n@BaseKb3dModel({\r\n token: Token.MaterialNode,\r\n})\r\nexport abstract class MaterialNode extends MaterialMapping implements IMaterialNode {\r\n constructor(public _materialService: IMaterialService) {\r\n super();\r\n\r\n this._initialized = false;\r\n }\r\n\r\n protected _materials: MaterialNode[];\r\n @Enumerable()\r\n public get materials(): MaterialNode[] {\r\n if (!this._materials) this._materials = [];\r\n return this._materials;\r\n }\r\n public set materials(val) {\r\n this._materials = val;\r\n }\r\n\r\n @IgnoreChanges\r\n _initialized: boolean;\r\n\r\n // Location is where this material is actually defined/saved. Here we also assign the icon this material uses in the tree.\r\n // Local is unique to this scene\r\n // Global is saved to this tenant's account and can be used in any of this tenant's scenes\r\n // Library is defined by kbmax and can be used on any scene by any tenant.\r\n @IgnoreChanges\r\n location: eMaterialLocation;\r\n\r\n // Id of material to inherit from. This material will be loaded and the user can copy properties from this material.\r\n @IgnoreChanges\r\n parentMaterialId?: string;\r\n _parentMaterial?: IMaterialNode;\r\n\r\n public _overriddenPropertiesSet = new Set();\r\n\r\n /** Implementation detail for persisting to database, do not use this property in the client code */\r\n private _overriddenProperties: string[];\r\n @Enumerable()\r\n public get overriddenProperties(): string[] {\r\n if (!this._overriddenProperties) this._overriddenProperties = [];\r\n return this._overriddenProperties;\r\n }\r\n public set overriddenProperties(val) {\r\n this._overriddenProperties = val;\r\n }\r\n\r\n /**\r\n * Archived: When this is set to true, material will be archived and\r\n * will not automatically be displayed when materials get loaded.\r\n */\r\n archived: boolean;\r\n\r\n private _textures: TextureLayer[];\r\n @Enumerable()\r\n public get textures(): TextureLayer[] {\r\n if (!this._textures) this._textures = [];\r\n return this._textures;\r\n }\r\n public set textures(val) {\r\n this._textures = val;\r\n }\r\n\r\n alpha: number;\r\n emissiveColor?: KbColor;\r\n viewMode: eMaterialViewMode;\r\n zOffset?: number;\r\n doubleSided: boolean;\r\n hasTransparency: boolean;\r\n probePositionTargetId?: string;\r\n reflectionType?: eReflectionType;\r\n @IgnoreChanges\r\n legacyTextureStacking: boolean;\r\n\r\n init() {\r\n this.refreshParentMaterial();\r\n\r\n if (!this._initialized) {\r\n if (isTrackedClass(this)) {\r\n // Always track changes on initialized materials because they may be global materials\r\n this.trackChanges(true);\r\n this.isModified = true;\r\n }\r\n this._initialized = true;\r\n\r\n this.textures.forEach(texture => {\r\n texture.init(this);\r\n });\r\n }\r\n }\r\n\r\n getChildren() {\r\n return [...this.textures, ...this.materials];\r\n }\r\n\r\n getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n if (token.isMaterial()) {\r\n return this.materials;\r\n } else if (token.isTexture()) {\r\n return this.textures;\r\n } else {\r\n throw 'unexpected token';\r\n }\r\n }\r\n\r\n overrideProperty(property: string | symbol | number) {\r\n if (this.parentMaterialId) {\r\n this._overriddenPropertiesSet.add(property);\r\n }\r\n }\r\n\r\n inheritProperty(property: string | symbol | number) {\r\n if (this.parentMaterialId) {\r\n this._overriddenPropertiesSet.delete(property);\r\n\r\n if (this._parentMaterial) {\r\n (this as any)[property] =\r\n (this._parentMaterial as any)[property] == null\r\n ? (defaults as any)[this.$type][property]\r\n : (this._parentMaterial as any)[property];\r\n }\r\n }\r\n }\r\n\r\n getTextureByName(name: string) {\r\n return [...this.textures].find(f => f.name.isEqual(name));\r\n }\r\n\r\n protected inheritFromMaterial(parentMat: IMaterialNode) {\r\n this.parentMaterialId = parentMat.id;\r\n this._parentMaterial = parentMat;\r\n if (!this._manager) {\r\n return;\r\n }\r\n const manager = this._manager;\r\n\r\n NEVER_INHERIT.forEach(prop => {\r\n this._overriddenPropertiesSet.add(prop);\r\n });\r\n\r\n for (const _key in parentMat) {\r\n const key = _key as keyof IMaterialNode;\r\n if (!this._overriddenPropertiesSet.has(key)) {\r\n //if this is a serialization of a texture node, then we need to deserialize it\r\n if (Array.isArray(parentMat[key])) {\r\n const currentTextures = (this as any)[key] as TextureLayer[];\r\n (parentMat[key] as ITextureLayer[]).forEach((tex, indexOnParent) => {\r\n const texDef = { ...tex, name: `Base ${tex.name || tex.channel}` };\r\n if (!texDef.id) {\r\n texDef.id = `${parentMat.id}_${tex.channel}`;\r\n }\r\n\r\n const currentIndex = currentTextures.findIndex(\r\n currentTexture => currentTexture.id === texDef.id\r\n );\r\n if (currentIndex < 0) {\r\n const textureNode = manager.deserialize(texDef) as TextureLayer;\r\n textureNode._external = true;\r\n // If this material is already initialized, make sure the new texture is also initialized.\r\n if (this._initialized) {\r\n textureNode.init(this);\r\n }\r\n currentTextures.splice(indexOnParent, 0, textureNode);\r\n } else {\r\n // currentTextures.splice(currentIndex, 1, textureNode);\r\n }\r\n });\r\n } else {\r\n (this as any)[key] =\r\n parentMat[key] instanceof Kb3dObject ? parentMat[key] : manager.deserialize(parentMat[key]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public refreshParentMaterial() {\r\n if (this.parentMaterialId) {\r\n this._materialService.getMaterialById(this.parentMaterialId).subscribe(parentMaterial => {\r\n if (parentMaterial && parentMaterial.data) {\r\n this.inheritFromMaterial(parentMaterial.data as any);\r\n }\r\n });\r\n }\r\n }\r\n\r\n public getMediaReferences() {\r\n const refs = new Array();\r\n for (const texture of this.textures) {\r\n if (instanceOf(texture, Token.FileTextureLayer) && texture.path && !isAbsoluteUrl(texture.path)) {\r\n refs.push({\r\n type: 'Media',\r\n id: 'media/' + texture.path,\r\n });\r\n }\r\n }\r\n return refs;\r\n }\r\n}\r\n\r\nexport function isMaterialNode(node: Kb3dObject): node is MaterialNode {\r\n return instanceOfAny(node, ...Token.MaterialTokens);\r\n}\r\n","\n/******************************************************************************\nCopyright (c) Microsoft Corporation.\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n","/**\r\n * Class used to evaluate queries containing `and` and `or` operators\r\n */\r\nexport class AndOrNotEvaluator {\r\n /**\r\n * Evaluate a query\r\n * @param query defines the query to evaluate\r\n * @param evaluateCallback defines the callback used to filter result\r\n * @returns true if the query matches\r\n */\r\n public static Eval(query: string, evaluateCallback: (val: any) => boolean): boolean {\r\n if (!query.match(/\\([^()]*\\)/g)) {\r\n query = AndOrNotEvaluator._HandleParenthesisContent(query, evaluateCallback);\r\n } else {\r\n query = query.replace(/\\([^()]*\\)/g, (r) => {\r\n // remove parenthesis\r\n r = r.slice(1, r.length - 1);\r\n return AndOrNotEvaluator._HandleParenthesisContent(r, evaluateCallback);\r\n });\r\n }\r\n\r\n if (query === \"true\") {\r\n return true;\r\n }\r\n\r\n if (query === \"false\") {\r\n return false;\r\n }\r\n\r\n return AndOrNotEvaluator.Eval(query, evaluateCallback);\r\n }\r\n\r\n private static _HandleParenthesisContent(parenthesisContent: string, evaluateCallback: (val: string) => boolean): string {\r\n evaluateCallback =\r\n evaluateCallback ||\r\n ((r) => {\r\n return r === \"true\" ? true : false;\r\n });\r\n\r\n let result;\r\n const or = parenthesisContent.split(\"||\");\r\n\r\n for (const i in or) {\r\n if (Object.prototype.hasOwnProperty.call(or, i)) {\r\n let ori = AndOrNotEvaluator._SimplifyNegation(or[i].trim());\r\n const and = ori.split(\"&&\");\r\n\r\n if (and.length > 1) {\r\n for (let j = 0; j < and.length; ++j) {\r\n const andj = AndOrNotEvaluator._SimplifyNegation(and[j].trim());\r\n if (andj !== \"true\" && andj !== \"false\") {\r\n if (andj[0] === \"!\") {\r\n result = !evaluateCallback(andj.substring(1));\r\n } else {\r\n result = evaluateCallback(andj);\r\n }\r\n } else {\r\n result = andj === \"true\" ? true : false;\r\n }\r\n if (!result) {\r\n // no need to continue since 'false && ... && ...' will always return false\r\n ori = \"false\";\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (result || ori === \"true\") {\r\n // no need to continue since 'true || ... || ...' will always return true\r\n result = true;\r\n break;\r\n }\r\n\r\n // result equals false (or undefined)\r\n\r\n if (ori !== \"true\" && ori !== \"false\") {\r\n if (ori[0] === \"!\") {\r\n result = !evaluateCallback(ori.substring(1));\r\n } else {\r\n result = evaluateCallback(ori);\r\n }\r\n } else {\r\n result = ori === \"true\" ? true : false;\r\n }\r\n }\r\n }\r\n\r\n // the whole parenthesis scope is replaced by 'true' or 'false'\r\n return result ? \"true\" : \"false\";\r\n }\r\n\r\n private static _SimplifyNegation(booleanString: string): string {\r\n booleanString = booleanString.replace(/^[\\s!]+/, (r) => {\r\n // remove whitespaces\r\n r = r.replace(/[\\s]/g, () => \"\");\r\n return r.length % 2 ? \"!\" : \"\";\r\n });\r\n\r\n booleanString = booleanString.trim();\r\n\r\n if (booleanString === \"!true\") {\r\n booleanString = \"false\";\r\n } else if (booleanString === \"!false\") {\r\n booleanString = \"true\";\r\n }\r\n\r\n return booleanString;\r\n }\r\n}\r\n","import { AndOrNotEvaluator } from \"./andOrNotEvaluator\";\r\n\r\n/**\r\n * Class used to store custom tags\r\n */\r\nexport class Tags {\r\n /**\r\n * Adds support for tags on the given object\r\n * @param obj defines the object to use\r\n */\r\n public static EnableFor(obj: any): void {\r\n obj._tags = obj._tags || {};\r\n\r\n obj.hasTags = () => {\r\n return Tags.HasTags(obj);\r\n };\r\n\r\n obj.addTags = (tagsString: string) => {\r\n return Tags.AddTagsTo(obj, tagsString);\r\n };\r\n\r\n obj.removeTags = (tagsString: string) => {\r\n return Tags.RemoveTagsFrom(obj, tagsString);\r\n };\r\n\r\n obj.matchesTagsQuery = (tagsQuery: string) => {\r\n return Tags.MatchesQuery(obj, tagsQuery);\r\n };\r\n }\r\n\r\n /**\r\n * Removes tags support\r\n * @param obj defines the object to use\r\n */\r\n public static DisableFor(obj: any): void {\r\n delete obj._tags;\r\n delete obj.hasTags;\r\n delete obj.addTags;\r\n delete obj.removeTags;\r\n delete obj.matchesTagsQuery;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the given object has tags\r\n * @param obj defines the object to use\r\n * @returns a boolean\r\n */\r\n public static HasTags(obj: any): boolean {\r\n if (!obj._tags) {\r\n return false;\r\n }\r\n\r\n const tags = obj._tags;\r\n for (const i in tags) {\r\n if (Object.prototype.hasOwnProperty.call(tags, i)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets the tags available on a given object\r\n * @param obj defines the object to use\r\n * @param asString defines if the tags must be returned as a string instead of an array of strings\r\n * @returns the tags\r\n */\r\n public static GetTags(obj: any, asString: boolean = true): any {\r\n if (!obj._tags) {\r\n return null;\r\n }\r\n if (asString) {\r\n const tagsArray = [];\r\n for (const tag in obj._tags) {\r\n if (Object.prototype.hasOwnProperty.call(obj._tags, tag) && obj._tags[tag] === true) {\r\n tagsArray.push(tag);\r\n }\r\n }\r\n return tagsArray.join(\" \");\r\n } else {\r\n return obj._tags;\r\n }\r\n }\r\n\r\n /**\r\n * Adds tags to an object\r\n * @param obj defines the object to use\r\n * @param tagsString defines the tag string. The tags 'true' and 'false' are reserved and cannot be used as tags.\r\n * A tag cannot start with '||', '&&', and '!'. It cannot contain whitespaces\r\n */\r\n public static AddTagsTo(obj: any, tagsString: string): void {\r\n if (!tagsString) {\r\n return;\r\n }\r\n\r\n if (typeof tagsString !== \"string\") {\r\n return;\r\n }\r\n\r\n const tags = tagsString.split(\" \");\r\n tags.forEach(function (tag) {\r\n Tags._AddTagTo(obj, tag);\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _AddTagTo(obj: any, tag: string): void {\r\n tag = tag.trim();\r\n\r\n if (tag === \"\" || tag === \"true\" || tag === \"false\") {\r\n return;\r\n }\r\n\r\n if (tag.match(/[\\s]/) || tag.match(/^([!]|([|]|[&]){2})/)) {\r\n return;\r\n }\r\n\r\n Tags.EnableFor(obj);\r\n obj._tags[tag] = true;\r\n }\r\n\r\n /**\r\n * Removes specific tags from a specific object\r\n * @param obj defines the object to use\r\n * @param tagsString defines the tags to remove\r\n */\r\n public static RemoveTagsFrom(obj: any, tagsString: string) {\r\n if (!Tags.HasTags(obj)) {\r\n return;\r\n }\r\n const tags = tagsString.split(\" \");\r\n for (const t in tags) {\r\n Tags._RemoveTagFrom(obj, tags[t]);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _RemoveTagFrom(obj: any, tag: string): void {\r\n delete obj._tags[tag];\r\n }\r\n\r\n /**\r\n * Defines if tags hosted on an object match a given query\r\n * @param obj defines the object to use\r\n * @param tagsQuery defines the tag query\r\n * @returns a boolean\r\n */\r\n public static MatchesQuery(obj: any, tagsQuery: string): boolean {\r\n if (tagsQuery === undefined) {\r\n return true;\r\n }\r\n\r\n if (tagsQuery === \"\") {\r\n return Tags.HasTags(obj);\r\n }\r\n\r\n return AndOrNotEvaluator.Eval(tagsQuery, (r) => Tags.HasTags(obj) && obj._tags[r]);\r\n }\r\n}\r\n","/**\r\n * Scalar computation library\r\n */\r\nexport class Scalar {\r\n /**\r\n * Two pi constants convenient for computation.\r\n */\r\n public static TwoPi: number = Math.PI * 2;\r\n\r\n /**\r\n * Boolean : true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)\r\n * @param a number\r\n * @param b number\r\n * @param epsilon (default = 1.401298E-45)\r\n * @returns true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)\r\n */\r\n public static WithinEpsilon(a: number, b: number, epsilon: number = 1.401298e-45): boolean {\r\n return Math.abs(a - b) <= epsilon;\r\n }\r\n\r\n /**\r\n * Returns a string : the upper case translation of the number i to hexadecimal.\r\n * @param i number\r\n * @returns the upper case translation of the number i to hexadecimal.\r\n */\r\n public static ToHex(i: number): string {\r\n const str = i.toString(16);\r\n\r\n if (i <= 15) {\r\n return (\"0\" + str).toUpperCase();\r\n }\r\n\r\n return str.toUpperCase();\r\n }\r\n\r\n /**\r\n * Returns -1 if value is negative and +1 is value is positive.\r\n * @param value the value\r\n * @returns the value itself if it's equal to zero.\r\n */\r\n public static Sign(value: number): number {\r\n value = +value; // convert to a number\r\n\r\n if (value === 0 || isNaN(value)) {\r\n return value;\r\n }\r\n\r\n return value > 0 ? 1 : -1;\r\n }\r\n\r\n /**\r\n * Returns the value itself if it's between min and max.\r\n * Returns min if the value is lower than min.\r\n * Returns max if the value is greater than max.\r\n * @param value the value to clmap\r\n * @param min the min value to clamp to (default: 0)\r\n * @param max the max value to clamp to (default: 1)\r\n * @returns the clamped value\r\n */\r\n public static Clamp(value: number, min = 0, max = 1): number {\r\n return Math.min(max, Math.max(min, value));\r\n }\r\n\r\n /**\r\n * the log2 of value.\r\n * @param value the value to compute log2 of\r\n * @returns the log2 of value.\r\n */\r\n public static Log2(value: number): number {\r\n return Math.log(value) * Math.LOG2E;\r\n }\r\n\r\n /**\r\n * the floor part of a log2 value.\r\n * @param value the value to compute log2 of\r\n * @returns the log2 of value.\r\n */\r\n public static ILog2(value: number): number {\r\n if (Math.log2) {\r\n return Math.floor(Math.log2(value));\r\n }\r\n\r\n if (value < 0) {\r\n return NaN;\r\n } else if (value === 0) {\r\n return -Infinity;\r\n }\r\n\r\n let n = 0;\r\n if (value < 1) {\r\n while (value < 1) {\r\n n++;\r\n value = value * 2;\r\n }\r\n n = -n;\r\n } else if (value > 1) {\r\n while (value > 1) {\r\n n++;\r\n value = Math.floor(value / 2);\r\n }\r\n }\r\n\r\n return n;\r\n }\r\n\r\n /**\r\n * Loops the value, so that it is never larger than length and never smaller than 0.\r\n *\r\n * This is similar to the modulo operator but it works with floating point numbers.\r\n * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.\r\n * With t = 5 and length = 2.5, the result would be 0.0.\r\n * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator\r\n * @param value the value\r\n * @param length the length\r\n * @returns the looped value\r\n */\r\n public static Repeat(value: number, length: number): number {\r\n return value - Math.floor(value / length) * length;\r\n }\r\n\r\n /**\r\n * Normalize the value between 0.0 and 1.0 using min and max values\r\n * @param value value to normalize\r\n * @param min max to normalize between\r\n * @param max min to normalize between\r\n * @returns the normalized value\r\n */\r\n public static Normalize(value: number, min: number, max: number): number {\r\n return (value - min) / (max - min);\r\n }\r\n\r\n /**\r\n * Denormalize the value from 0.0 and 1.0 using min and max values\r\n * @param normalized value to denormalize\r\n * @param min max to denormalize between\r\n * @param max min to denormalize between\r\n * @returns the denormalized value\r\n */\r\n public static Denormalize(normalized: number, min: number, max: number): number {\r\n return normalized * (max - min) + min;\r\n }\r\n\r\n /**\r\n * Calculates the shortest difference between two given angles given in degrees.\r\n * @param current current angle in degrees\r\n * @param target target angle in degrees\r\n * @returns the delta\r\n */\r\n public static DeltaAngle(current: number, target: number): number {\r\n let num: number = Scalar.Repeat(target - current, 360.0);\r\n if (num > 180.0) {\r\n num -= 360.0;\r\n }\r\n return num;\r\n }\r\n\r\n /**\r\n * PingPongs the value t, so that it is never larger than length and never smaller than 0.\r\n * @param tx value\r\n * @param length length\r\n * @returns The returned value will move back and forth between 0 and length\r\n */\r\n public static PingPong(tx: number, length: number): number {\r\n const t: number = Scalar.Repeat(tx, length * 2.0);\r\n return length - Math.abs(t - length);\r\n }\r\n\r\n /**\r\n * Interpolates between min and max with smoothing at the limits.\r\n *\r\n * This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up\r\n * from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.\r\n * @param from from\r\n * @param to to\r\n * @param tx value\r\n * @returns the smooth stepped value\r\n */\r\n public static SmoothStep(from: number, to: number, tx: number): number {\r\n let t: number = Scalar.Clamp(tx);\r\n t = -2.0 * t * t * t + 3.0 * t * t;\r\n return to * t + from * (1.0 - t);\r\n }\r\n\r\n /**\r\n * Moves a value current towards target.\r\n *\r\n * This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.\r\n * Negative values of maxDelta pushes the value away from target.\r\n * @param current current value\r\n * @param target target value\r\n * @param maxDelta max distance to move\r\n * @returns resulting value\r\n */\r\n public static MoveTowards(current: number, target: number, maxDelta: number): number {\r\n let result: number = 0;\r\n if (Math.abs(target - current) <= maxDelta) {\r\n result = target;\r\n } else {\r\n result = current + Scalar.Sign(target - current) * maxDelta;\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.\r\n *\r\n * Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta\r\n * are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.\r\n * @param current current value\r\n * @param target target value\r\n * @param maxDelta max distance to move\r\n * @returns resulting angle\r\n */\r\n public static MoveTowardsAngle(current: number, target: number, maxDelta: number): number {\r\n const num: number = Scalar.DeltaAngle(current, target);\r\n let result: number = 0;\r\n if (-maxDelta < num && num < maxDelta) {\r\n result = target;\r\n } else {\r\n target = current + num;\r\n result = Scalar.MoveTowards(current, target, maxDelta);\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new scalar with values linearly interpolated of \"amount\" between the start scalar and the end scalar.\r\n * @param start start value\r\n * @param end target value\r\n * @param amount amount to lerp between\r\n * @returns the lerped value\r\n */\r\n public static Lerp(start: number, end: number, amount: number): number {\r\n return start + (end - start) * amount;\r\n }\r\n\r\n /**\r\n * Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.\r\n * The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.\r\n * @param start start value\r\n * @param end target value\r\n * @param amount amount to lerp between\r\n * @returns the lerped value\r\n */\r\n public static LerpAngle(start: number, end: number, amount: number): number {\r\n let num: number = Scalar.Repeat(end - start, 360.0);\r\n if (num > 180.0) {\r\n num -= 360.0;\r\n }\r\n return start + num * Scalar.Clamp(amount);\r\n }\r\n\r\n /**\r\n * Calculates the linear parameter t that produces the interpolant value within the range [a, b].\r\n * @param a start value\r\n * @param b target value\r\n * @param value value between a and b\r\n * @returns the inverseLerp value\r\n */\r\n public static InverseLerp(a: number, b: number, value: number): number {\r\n let result: number = 0;\r\n if (a != b) {\r\n result = Scalar.Clamp((value - a) / (b - a));\r\n } else {\r\n result = 0.0;\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new scalar located for \"amount\" (float) on the Hermite spline defined by the scalars \"value1\", \"value3\", \"tangent1\", \"tangent2\".\r\n * @see http://mathworld.wolfram.com/HermitePolynomial.html\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param amount defines the amount on the interpolation spline (between 0 and 1)\r\n * @returns hermite result\r\n */\r\n public static Hermite(value1: number, tangent1: number, value2: number, tangent2: number, amount: number): number {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\r\n const part2 = -2.0 * cubed + 3.0 * squared;\r\n const part3 = cubed - 2.0 * squared + amount;\r\n const part4 = cubed - squared;\r\n\r\n return value1 * part1 + value2 * part2 + tangent1 * part3 + tangent2 * part4;\r\n }\r\n\r\n /**\r\n * Returns a new scalar which is the 1st derivative of the Hermite spline defined by the scalars \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @returns 1st derivative\r\n */\r\n public static Hermite1stDerivative(value1: number, tangent1: number, value2: number, tangent2: number, time: number): number {\r\n const t2 = time * time;\r\n return (t2 - time) * 6 * value1 + (3 * t2 - 4 * time + 1) * tangent1 + (-t2 + time) * 6 * value2 + (3 * t2 - 2 * time) * tangent2;\r\n }\r\n\r\n /**\r\n * Returns a random float number between and min and max values\r\n * @param min min value of random\r\n * @param max max value of random\r\n * @returns random value\r\n */\r\n public static RandomRange(min: number, max: number): number {\r\n if (min === max) {\r\n return min;\r\n }\r\n return Math.random() * (max - min) + min;\r\n }\r\n\r\n /**\r\n * This function returns percentage of a number in a given range.\r\n *\r\n * RangeToPercent(40,20,60) will return 0.5 (50%)\r\n * RangeToPercent(34,0,100) will return 0.34 (34%)\r\n * @param number to convert to percentage\r\n * @param min min range\r\n * @param max max range\r\n * @returns the percentage\r\n */\r\n public static RangeToPercent(number: number, min: number, max: number): number {\r\n return (number - min) / (max - min);\r\n }\r\n\r\n /**\r\n * This function returns number that corresponds to the percentage in a given range.\r\n *\r\n * PercentToRange(0.34,0,100) will return 34.\r\n * @param percent to convert to number\r\n * @param min min range\r\n * @param max max range\r\n * @returns the number\r\n */\r\n public static PercentToRange(percent: number, min: number, max: number): number {\r\n return (max - min) * percent + min;\r\n }\r\n\r\n /**\r\n * Returns the angle converted to equivalent value between -Math.PI and Math.PI radians.\r\n * @param angle The angle to normalize in radian.\r\n * @returns The converted angle.\r\n */\r\n public static NormalizeRadians(angle: number): number {\r\n // More precise but slower version kept for reference.\r\n // angle = angle % Tools.TwoPi;\r\n // angle = (angle + Tools.TwoPi) % Tools.TwoPi;\r\n\r\n //if (angle > Math.PI) {\r\n //\tangle -= Tools.TwoPi;\r\n //}\r\n\r\n angle -= Scalar.TwoPi * Math.floor((angle + Math.PI) / Scalar.TwoPi);\r\n\r\n return angle;\r\n }\r\n\r\n /**\r\n * Returns the highest common factor of two integers.\r\n * @param a first parameter\r\n * @param b second parameter\r\n * @returns HCF of a and b\r\n */\r\n public static HCF(a: number, b: number): number {\r\n const r: number = a % b;\r\n if (r === 0) {\r\n return b;\r\n }\r\n return Scalar.HCF(b, r);\r\n }\r\n}\r\n","/**\r\n * Constant used to convert a value to gamma space\r\n * @ignorenaming\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport const ToGammaSpace = 1 / 2.2;\r\n\r\n/**\r\n * Constant used to convert a value to linear space\r\n * @ignorenaming\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport const ToLinearSpace = 2.2;\r\n\r\n/**\r\n * Constant Golden Ratio value in Babylon.js\r\n * @ignorenaming\r\n */\r\nexport const PHI = (1 + Math.sqrt(5)) / 2;\r\n\r\n/**\r\n * Constant used to define the minimal number value in Babylon.js\r\n * @ignorenaming\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst Epsilon = 0.001;\r\nexport { Epsilon };\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\nimport type { Nullable } from \"../types\";\r\n\r\n/** @internal */\r\ninterface TupleTypes {\r\n 2: [T, T];\r\n 3: [T, T, T];\r\n 4: [T, T, T, T];\r\n 5: [T, T, T, T, T];\r\n 6: [T, T, T, T, T, T];\r\n 7: [T, T, T, T, T, T, T];\r\n 8: [T, T, T, T, T, T, T, T];\r\n 9: [T, T, T, T, T, T, T, T, T];\r\n 10: [T, T, T, T, T, T, T, T, T, T];\r\n 11: [T, T, T, T, T, T, T, T, T, T, T];\r\n 12: [T, T, T, T, T, T, T, T, T, T, T, T];\r\n 13: [T, T, T, T, T, T, T, T, T, T, T, T, T];\r\n 14: [T, T, T, T, T, T, T, T, T, T, T, T, T, T];\r\n 15: [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T];\r\n}\r\n\r\n/**\r\n * Class containing a set of static utilities functions for arrays.\r\n */\r\nexport class ArrayTools {\r\n /**\r\n * Returns an array of the given size filled with elements built from the given constructor and the parameters.\r\n * @param size the number of element to construct and put in the array.\r\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.\r\n * @returns a new array filled with new objects.\r\n */\r\n public static BuildArray(size: number, itemBuilder: () => T): Array {\r\n const a: T[] = [];\r\n for (let i = 0; i < size; ++i) {\r\n a.push(itemBuilder());\r\n }\r\n return a;\r\n }\r\n\r\n /**\r\n * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.\r\n * @param size he number of element to construct and put in the tuple.\r\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.\r\n * @returns a new tuple filled with new objects.\r\n */\r\n public static BuildTuple>(size: N, itemBuilder: () => T): TupleTypes[N] {\r\n return ArrayTools.BuildArray(size, itemBuilder) as any;\r\n }\r\n}\r\n\r\n/**\r\n * Defines the callback type used when an observed array function is triggered.\r\n * @internal\r\n */\r\nexport type _ObserveCallback = (functionName: string, previousLength: number) => void;\r\n\r\n/**\r\n * Observes a function and calls the given callback when it is called.\r\n * @param object Defines the object the function to observe belongs to.\r\n * @param functionName Defines the name of the function to observe.\r\n * @param callback Defines the callback to call when the function is called.\r\n * @returns A function to call to stop observing\r\n */\r\nfunction _observeArrayfunction(object: { [key: string]: any }, functionName: string, callback: _ObserveCallback): Nullable<() => void> {\r\n // Finds the function to observe\r\n const oldFunction = object[functionName];\r\n if (typeof oldFunction !== \"function\") {\r\n return null;\r\n }\r\n\r\n // Creates a new function that calls the callback and the old function\r\n const newFunction = function () {\r\n const previousLength = object.length;\r\n const returnValue = newFunction.previous.apply(object, arguments);\r\n callback(functionName, previousLength);\r\n return returnValue;\r\n } as any;\r\n\r\n // Doublishly links the new function and the old function\r\n oldFunction.next = newFunction;\r\n newFunction.previous = oldFunction;\r\n\r\n // Replaces the old function with the new function\r\n object[functionName] = newFunction;\r\n\r\n // Returns a function to disable the hook\r\n return () => {\r\n // Only unhook if the function is still hooked\r\n const previous = newFunction.previous;\r\n if (!previous) {\r\n return;\r\n }\r\n\r\n // Finds the ref to the next function in the chain\r\n const next = newFunction.next;\r\n\r\n // If in the middle of the chain, link the previous and next functions\r\n if (next) {\r\n previous.next = next;\r\n next.previous = previous;\r\n }\r\n // If at the end of the chain, remove the reference to the previous function\r\n // and restore the previous function\r\n else {\r\n previous.next = undefined;\r\n object[functionName] = previous;\r\n }\r\n\r\n // Lose reference to the previous and next functions\r\n newFunction.next = undefined;\r\n newFunction.previous = undefined;\r\n };\r\n}\r\n\r\n/**\r\n * Defines the list of functions to proxy when observing an array.\r\n * The scope is currently reduced to the common functions used in the render target render list and the scene cameras.\r\n */\r\nconst observedArrayFunctions = [\"push\", \"splice\", \"pop\", \"shift\", \"unshift\"];\r\n\r\n/**\r\n * Observes an array and notifies the given observer when the array is modified.\r\n * @param array Defines the array to observe\r\n * @param callback Defines the function to call when the array is modified (in the limit of the observed array functions)\r\n * @returns A function to call to stop observing the array\r\n * @internal\r\n */\r\nexport function _ObserveArray(array: T[], callback: _ObserveCallback) {\r\n // Observes all the required array functions and stores the unhook functions\r\n const unObserveFunctions = observedArrayFunctions.map((name) => {\r\n return _observeArrayfunction(array, name, callback);\r\n });\r\n\r\n // Returns a function that unhook all the observed functions\r\n return () => {\r\n unObserveFunctions.forEach((unObserveFunction) => {\r\n unObserveFunction?.();\r\n });\r\n };\r\n}\r\n","/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst _RegisteredTypes: { [key: string]: Object } = {};\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function RegisterClass(className: string, type: Object) {\r\n _RegisteredTypes[className] = type;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function GetClass(fqdn: string): any {\r\n return _RegisteredTypes[fqdn];\r\n}\r\n","/** @internal */\r\nexport class PerformanceConfigurator {\r\n /** @internal */\r\n public static MatrixUse64Bits = false;\r\n /** @internal */\r\n public static MatrixTrackPrecisionChange = true;\r\n /** @internal */\r\n public static MatrixCurrentType: any = Float32Array;\r\n /** @internal */\r\n public static MatrixTrackedMatrices: Array | null = [];\r\n\r\n /**\r\n * @internal\r\n */\r\n public static SetMatrixPrecision(use64bits: boolean) {\r\n PerformanceConfigurator.MatrixTrackPrecisionChange = false;\r\n\r\n if (use64bits && !PerformanceConfigurator.MatrixUse64Bits) {\r\n if (PerformanceConfigurator.MatrixTrackedMatrices) {\r\n for (let m = 0; m < PerformanceConfigurator.MatrixTrackedMatrices.length; ++m) {\r\n const matrix = PerformanceConfigurator.MatrixTrackedMatrices[m];\r\n const values = matrix._m;\r\n\r\n matrix._m = new Array(16);\r\n\r\n for (let i = 0; i < 16; ++i) {\r\n matrix._m[i] = values[i];\r\n }\r\n }\r\n }\r\n }\r\n\r\n PerformanceConfigurator.MatrixUse64Bits = use64bits;\r\n PerformanceConfigurator.MatrixCurrentType = PerformanceConfigurator.MatrixUse64Bits ? Array : Float32Array;\r\n PerformanceConfigurator.MatrixTrackedMatrices = null; // reclaim some memory, as we don't need _TrackedMatrices anymore\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an Observer registered to a given Observable object.\r\n */\r\nexport class Observer {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<() => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param scope defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n */\r\n public remove() {\r\n if (this._remove) {\r\n this._remove();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.\r\n */\r\nexport class Observable {\r\n private _observers = new Array>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise(promise: Promise, onErrorObservable?: Observable): Observable {\r\n const observable = new Observable();\r\n\r\n promise\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer) => void,\r\n /**\r\n * If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(\r\n callback: (eventData: T, eventState: EventState) => void,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n if (this._lastNotifiedValue !== undefined) {\r\n this.notifyObserver(observer, this._lastNotifiedValue);\r\n }\r\n }\r\n // attach the remove function to the observer\r\n observer._remove = () => {\r\n this.remove(observer);\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Nullable> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable {\r\n const result = new Observable();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\n\r\nimport type { Engine } from \"./engine\";\r\nimport type { Scene } from \"../scene\";\r\n\r\n/**\r\n * The engine store class is responsible to hold all the instances of Engine and Scene created\r\n * during the life time of the application.\r\n */\r\nexport class EngineStore {\r\n /** Gets the list of created engines */\r\n public static Instances = new Array();\r\n\r\n /**\r\n * Notifies when an engine was disposed.\r\n * Mainly used for static/cache cleanup\r\n */\r\n public static OnEnginesDisposedObservable = new Observable();\r\n\r\n /** @internal */\r\n public static _LastCreatedScene: Nullable = null;\r\n\r\n /**\r\n * Gets the latest created engine\r\n */\r\n public static get LastCreatedEngine(): Nullable {\r\n if (this.Instances.length === 0) {\r\n return null;\r\n }\r\n\r\n return this.Instances[this.Instances.length - 1];\r\n }\r\n\r\n /**\r\n * Gets the latest created scene\r\n */\r\n public static get LastCreatedScene(): Nullable {\r\n return this._LastCreatedScene;\r\n }\r\n\r\n /**\r\n * Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded\r\n * @ignorenaming\r\n */\r\n public static UseFallbackTexture = true;\r\n\r\n /**\r\n * Texture content used if a texture cannot loaded\r\n * @ignorenaming\r\n */\r\n public static FallbackTexture = \"\";\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Scalar } from \"./math.scalar\";\r\nimport { Epsilon } from \"./math.constants\";\r\nimport type { Viewport } from \"./math.viewport\";\r\nimport type { DeepImmutable, Nullable, FloatArray, float } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport type { IPlaneLike } from \"./math.like\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { Plane } from \"./math.plane\";\r\nimport { PerformanceConfigurator } from \"../Engines/performanceConfigurator\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\nexport type Vector2Constructor = new (...args: ConstructorParameters) => T;\r\nexport type Vector3Constructor = new (...args: ConstructorParameters) => T;\r\nexport type Vector4Constructor = new (...args: ConstructorParameters) => T;\r\nexport type QuaternionConstructor = new (...args: ConstructorParameters) => T;\r\nexport type MatrixConstructor = new () => T;\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst _ExtractAsInt = (value: number) => {\r\n return parseInt(value.toString().replace(/\\W/g, \"\"));\r\n};\r\n\r\n/**\r\n * Class representing a vector containing 2 coordinates\r\n * Example Playground - Overview - https://playground.babylonjs.com/#QYBWV4#9\r\n */\r\nexport class Vector2 {\r\n private static _ZeroReadOnly = Vector2.Zero() as DeepImmutable;\r\n\r\n /**\r\n * Creates a new Vector2 from the given x and y coordinates\r\n * @param x defines the first coordinate\r\n * @param y defines the second coordinate\r\n */\r\n constructor(\r\n /** defines the first coordinate */\r\n public x: number = 0,\r\n /** defines the second coordinate */\r\n public y: number = 0\r\n ) {}\r\n\r\n /**\r\n * Gets a string with the Vector2 coordinates\r\n * @returns a string with the Vector2 coordinates\r\n */\r\n public toString(): string {\r\n return `{X: ${this.x} Y: ${this.y}}`;\r\n }\r\n\r\n /**\r\n * Gets class name\r\n * @returns the string \"Vector2\"\r\n */\r\n public getClassName(): string {\r\n return \"Vector2\";\r\n }\r\n\r\n /**\r\n * Gets current vector hash code\r\n * @returns the Vector2 hash code as a number\r\n */\r\n public getHashCode(): number {\r\n const x = _ExtractAsInt(this.x);\r\n const y = _ExtractAsInt(this.y);\r\n let hash = x;\r\n hash = (hash * 397) ^ y;\r\n return hash;\r\n }\r\n\r\n // Operators\r\n\r\n /**\r\n * Sets the Vector2 coordinates in the given array or Float32Array from the given index.\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#15\r\n * @param array defines the source array\r\n * @param index defines the offset in source array\r\n * @returns the current Vector2\r\n */\r\n public toArray(array: FloatArray, index: number = 0): this {\r\n array[index] = this.x;\r\n array[index + 1] = this.y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Update the current vector from an array\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#39\r\n * @param array defines the destination array\r\n * @param index defines the offset in the destination array\r\n * @returns the current Vector2\r\n */\r\n public fromArray(array: FloatArray, index: number = 0): this {\r\n Vector2.FromArrayToRef(array, index, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Copy the current vector to an array\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#40\r\n * @returns a new array with 2 elements: the Vector2 coordinates.\r\n */\r\n public asArray(): number[] {\r\n const result = new Array();\r\n this.toArray(result, 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the Vector2 coordinates with the given Vector2 coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#24\r\n * @param source defines the source Vector2\r\n * @returns the current updated Vector2\r\n */\r\n public copyFrom(source: DeepImmutable): this {\r\n this.x = source.x;\r\n this.y = source.y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the Vector2 coordinates with the given floats\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#25\r\n * @param x defines the first coordinate\r\n * @param y defines the second coordinate\r\n * @returns the current updated Vector2\r\n */\r\n public copyFromFloats(x: number, y: number): this {\r\n this.x = x;\r\n this.y = y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the Vector2 coordinates with the given floats\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#62\r\n * @param x defines the first coordinate\r\n * @param y defines the second coordinate\r\n * @returns the current updated Vector2\r\n */\r\n public set(x: number, y: number): this {\r\n return this.copyFromFloats(x, y);\r\n }\r\n /**\r\n * Add another vector with the current one\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#11\r\n * @param otherVector defines the other vector\r\n * @returns a new Vector2 set with the addition of the current Vector2 and the given one coordinates\r\n */\r\n public add(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector2Constructor)(this.x + otherVector.x, this.y + otherVector.y);\r\n }\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the addition of the current Vector2 and the given one coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#12\r\n * @param otherVector defines the other vector\r\n * @param result defines the target vector\r\n * @returns result input\r\n */\r\n public addToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x + otherVector.x;\r\n result.y = this.y + otherVector.y;\r\n return result;\r\n }\r\n\r\n /**\r\n * Set the Vector2 coordinates by adding the given Vector2 coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#13\r\n * @param otherVector defines the other vector\r\n * @returns the current updated Vector2\r\n */\r\n public addInPlace(otherVector: DeepImmutable): this {\r\n this.x += otherVector.x;\r\n this.y += otherVector.y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 by adding the current Vector2 coordinates to the given Vector3 x, y coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#14\r\n * @param otherVector defines the other vector\r\n * @returns a new Vector2\r\n */\r\n public addVector3(otherVector: Vector3): this {\r\n return new (this.constructor as Vector2Constructor)(this.x + otherVector.x, this.y + otherVector.y);\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#61\r\n * @param otherVector defines the other vector\r\n * @returns a new Vector2\r\n */\r\n public subtract(otherVector: Vector2): this {\r\n return new (this.constructor as Vector2Constructor)(this.x - otherVector.x, this.y - otherVector.y);\r\n }\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the subtraction of the given one from the current Vector2 coordinates.\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#63\r\n * @param otherVector defines the other vector\r\n * @param result defines the target vector\r\n * @returns result input\r\n */\r\n public subtractToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x - otherVector.x;\r\n result.y = this.y - otherVector.y;\r\n return result;\r\n }\r\n /**\r\n * Sets the current Vector2 coordinates by subtracting from it the given one coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#88\r\n * @param otherVector defines the other vector\r\n * @returns the current updated Vector2\r\n */\r\n public subtractInPlace(otherVector: DeepImmutable): this {\r\n this.x -= otherVector.x;\r\n this.y -= otherVector.y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiplies in place the current Vector2 coordinates by the given ones\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#43\r\n * @param otherVector defines the other vector\r\n * @returns the current updated Vector2\r\n */\r\n public multiplyInPlace(otherVector: DeepImmutable): this {\r\n this.x *= otherVector.x;\r\n this.y *= otherVector.y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 set with the multiplication of the current Vector2 and the given one coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#42\r\n * @param otherVector defines the other vector\r\n * @returns a new Vector2\r\n */\r\n public multiply(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector2Constructor)(this.x * otherVector.x, this.y * otherVector.y);\r\n }\r\n\r\n /**\r\n * Sets \"result\" coordinates with the multiplication of the current Vector2 and the given one coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#44\r\n * @param otherVector defines the other vector\r\n * @param result defines the target vector\r\n * @returns result input\r\n */\r\n public multiplyToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x * otherVector.x;\r\n result.y = this.y * otherVector.y;\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#89\r\n * @param x defines the first coordinate\r\n * @param y defines the second coordinate\r\n * @returns a new Vector2\r\n */\r\n public multiplyByFloats(x: number, y: number): this {\r\n return new (this.constructor as Vector2Constructor)(this.x * x, this.y * y);\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#27\r\n * @param otherVector defines the other vector\r\n * @returns a new Vector2\r\n */\r\n public divide(otherVector: Vector2): this {\r\n return new (this.constructor as Vector2Constructor)(this.x / otherVector.x, this.y / otherVector.y);\r\n }\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the Vector2 divided by the given one coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#30\r\n * @param otherVector defines the other vector\r\n * @param result defines the target vector\r\n * @returns result input\r\n */\r\n public divideToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x / otherVector.x;\r\n result.y = this.y / otherVector.y;\r\n return result;\r\n }\r\n\r\n /**\r\n * Divides the current Vector2 coordinates by the given ones\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#28\r\n * @param otherVector defines the other vector\r\n * @returns the current updated Vector2\r\n */\r\n public divideInPlace(otherVector: DeepImmutable): this {\r\n return this.divideToRef(otherVector, this);\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 with current Vector2 negated coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#22\r\n * @returns a new Vector2\r\n */\r\n public negate(): this {\r\n return new (this.constructor as Vector2Constructor)(-this.x, -this.y);\r\n }\r\n\r\n /**\r\n * Negate this vector in place\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#23\r\n * @returns this\r\n */\r\n public negateInPlace(): this {\r\n this.x *= -1;\r\n this.y *= -1;\r\n return this;\r\n }\r\n\r\n /**\r\n * Negate the current Vector2 and stores the result in the given vector \"result\" coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#41\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public negateToRef(result: T): T {\r\n return result.copyFromFloats(this.x * -1, this.y * -1);\r\n }\r\n\r\n /**\r\n * Multiply the Vector2 coordinates by\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#59\r\n * @param scale defines the scaling factor\r\n * @returns the current updated Vector2\r\n */\r\n public scaleInPlace(scale: number): this {\r\n this.x *= scale;\r\n this.y *= scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 scaled by \"scale\" from the current Vector2\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#52\r\n * @param scale defines the scaling factor\r\n * @returns a new Vector2\r\n */\r\n public scale(scale: number): this {\r\n const result = new (this.constructor as Vector2Constructor)(0, 0);\r\n this.scaleToRef(scale, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Scale the current Vector2 values by a factor to a given Vector2\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#57\r\n * @param scale defines the scale factor\r\n * @param result defines the Vector2 object where to store the result\r\n * @returns result input\r\n */\r\n public scaleToRef(scale: number, result: T): T {\r\n result.x = this.x * scale;\r\n result.y = this.y * scale;\r\n return result;\r\n }\r\n\r\n /**\r\n * Scale the current Vector2 values by a factor and add the result to a given Vector2\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#58\r\n * @param scale defines the scale factor\r\n * @param result defines the Vector2 object where to store the result\r\n * @returns result input\r\n */\r\n public scaleAndAddToRef(scale: number, result: T): T {\r\n result.x += this.x * scale;\r\n result.y += this.y * scale;\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets a boolean if two vectors are equals\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#31\r\n * @param otherVector defines the other vector\r\n * @returns true if the given vector coordinates strictly equal the current Vector2 ones\r\n */\r\n public equals(otherVector: DeepImmutable): boolean {\r\n return otherVector && this.x === otherVector.x && this.y === otherVector.y;\r\n }\r\n\r\n /**\r\n * Gets a boolean if two vectors are equals (using an epsilon value)\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#32\r\n * @param otherVector defines the other vector\r\n * @param epsilon defines the minimal distance to consider equality\r\n * @returns true if the given vector coordinates are close to the current ones by a distance of epsilon.\r\n */\r\n public equalsWithEpsilon(otherVector: DeepImmutable, epsilon: number = Epsilon): boolean {\r\n return otherVector && Scalar.WithinEpsilon(this.x, otherVector.x, epsilon) && Scalar.WithinEpsilon(this.y, otherVector.y, epsilon);\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 from current Vector2 floored values\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#35\r\n * eg (1.2, 2.31) returns (1, 2)\r\n * @returns a new Vector2\r\n */\r\n public floor(): this {\r\n return new (this.constructor as Vector2Constructor)(Math.floor(this.x), Math.floor(this.y));\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 from current Vector2 fractional values\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#34\r\n * eg (1.2, 2.31) returns (0.2, 0.31)\r\n * @returns a new Vector2\r\n */\r\n public fract(): this {\r\n return new (this.constructor as Vector2Constructor)(this.x - Math.floor(this.x), this.y - Math.floor(this.y));\r\n }\r\n\r\n /**\r\n * Rotate the current vector into a given result vector\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#49\r\n * @param angle defines the rotation angle\r\n * @param result defines the result vector where to store the rotated vector\r\n * @returns result input\r\n */\r\n public rotateToRef(angle: number, result: T): T {\r\n const cos = Math.cos(angle);\r\n const sin = Math.sin(angle);\r\n const x = cos * this.x - sin * this.y;\r\n const y = sin * this.x + cos * this.y;\r\n result.x = x;\r\n result.y = y;\r\n return result;\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets the length of the vector\r\n * @returns the vector length (float)\r\n */\r\n public length(): number {\r\n return Math.sqrt(this.x * this.x + this.y * this.y);\r\n }\r\n\r\n /**\r\n * Gets the vector squared length\r\n * @returns the vector squared length (float)\r\n */\r\n public lengthSquared(): number {\r\n return this.x * this.x + this.y * this.y;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Normalize the vector\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#48\r\n * @returns the current updated Vector2\r\n */\r\n public normalize(): this {\r\n Vector2.NormalizeToRef(this, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 copied from the Vector2\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#20\r\n * @returns a new Vector2\r\n */\r\n public clone(): this {\r\n return new (this.constructor as Vector2Constructor)(this.x, this.y);\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Gets a new Vector2(0, 0)\r\n * @returns a new Vector2\r\n */\r\n public static Zero(): Vector2 {\r\n return new Vector2(0, 0);\r\n }\r\n\r\n /**\r\n * Gets a new Vector2(1, 1)\r\n * @returns a new Vector2\r\n */\r\n public static One(): Vector2 {\r\n return new Vector2(1, 1);\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @returns a Vector2 with random values between min and max\r\n */\r\n public static Random(min: number = 0, max: number = 1): Vector2 {\r\n return new Vector2(Scalar.RandomRange(min, max), Scalar.RandomRange(min, max));\r\n }\r\n\r\n /**\r\n * Gets a zero Vector2 that must not be updated\r\n */\r\n public static get ZeroReadOnly(): DeepImmutable {\r\n return Vector2._ZeroReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 set from the given index element of the given array\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#79\r\n * @param array defines the data source\r\n * @param offset defines the offset in the data source\r\n * @returns a new Vector2\r\n */\r\n public static FromArray(array: DeepImmutable>, offset: number = 0): Vector2 {\r\n return new Vector2(array[offset], array[offset + 1]);\r\n }\r\n\r\n /**\r\n * Sets \"result\" from the given index element of the given array\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#80\r\n * @param array defines the data source\r\n * @param offset defines the offset in the data source\r\n * @param result defines the target vector\r\n * @returns result input\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number, result: T): T {\r\n result.x = array[offset];\r\n result.y = array[offset + 1];\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 located for \"amount\" (float) on the CatmullRom spline defined by the given four Vector2\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#65\r\n * @param value1 defines 1st point of control\r\n * @param value2 defines 2nd point of control\r\n * @param value3 defines 3rd point of control\r\n * @param value4 defines 4th point of control\r\n * @param amount defines the interpolation factor\r\n * @returns a new Vector2\r\n */\r\n public static CatmullRom(\r\n value1: DeepImmutable,\r\n value2: DeepImmutable,\r\n value3: DeepImmutable,\r\n value4: DeepImmutable,\r\n amount: number\r\n ): T {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n\r\n const x =\r\n 0.5 *\r\n (2.0 * value2.x +\r\n (-value1.x + value3.x) * amount +\r\n (2.0 * value1.x - 5.0 * value2.x + 4.0 * value3.x - value4.x) * squared +\r\n (-value1.x + 3.0 * value2.x - 3.0 * value3.x + value4.x) * cubed);\r\n\r\n const y =\r\n 0.5 *\r\n (2.0 * value2.y +\r\n (-value1.y + value3.y) * amount +\r\n (2.0 * value1.y - 5.0 * value2.y + 4.0 * value3.y - value4.y) * squared +\r\n (-value1.y + 3.0 * value2.y - 3.0 * value3.y + value4.y) * cubed);\r\n\r\n return new (value1.constructor as Vector2Constructor)(x, y);\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 set with same the coordinates than \"value\" ones if the vector \"value\" is in the square defined by \"min\" and \"max\".\r\n * If a coordinate of \"value\" is lower than \"min\" coordinates, the returned Vector2 is given this \"min\" coordinate.\r\n * If a coordinate of \"value\" is greater than \"max\" coordinates, the returned Vector2 is given this \"max\" coordinate\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#76\r\n * @param value defines the value to clamp\r\n * @param min defines the lower limit\r\n * @param max defines the upper limit\r\n * @returns a new Vector2\r\n */\r\n public static Clamp(value: DeepImmutable, min: DeepImmutable, max: DeepImmutable): T {\r\n let x = value.x;\r\n x = x > max.x ? max.x : x;\r\n x = x < min.x ? min.x : x;\r\n\r\n let y = value.y;\r\n y = y > max.y ? max.y : y;\r\n y = y < min.y ? min.y : y;\r\n\r\n return new (value.constructor as Vector2Constructor)(x, y);\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 located for \"amount\" (float) on the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\"\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#81\r\n * @param value1 defines the 1st control point\r\n * @param tangent1 defines the outgoing tangent\r\n * @param value2 defines the 2nd control point\r\n * @param tangent2 defines the incoming tangent\r\n * @param amount defines the interpolation factor\r\n * @returns a new Vector2\r\n */\r\n public static Hermite(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n amount: number\r\n ): T {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\r\n const part2 = -2.0 * cubed + 3.0 * squared;\r\n const part3 = cubed - 2.0 * squared + amount;\r\n const part4 = cubed - squared;\r\n\r\n const x = value1.x * part1 + value2.x * part2 + tangent1.x * part3 + tangent2.x * part4;\r\n const y = value1.y * part1 + value2.y * part2 + tangent1.y * part3 + tangent2.y * part4;\r\n\r\n return new (value1.constructor as Vector2Constructor)(x, y);\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#82\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @returns 1st derivative\r\n */\r\n public static Hermite1stDerivative(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number\r\n ): T {\r\n const result = new (value1.constructor as Vector2Constructor)();\r\n\r\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#83\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @param result define where the derivative will be stored\r\n * @returns result input\r\n */\r\n public static Hermite1stDerivativeToRef(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number,\r\n result: T\r\n ): T {\r\n const t2 = time * time;\r\n\r\n result.x = (t2 - time) * 6 * value1.x + (3 * t2 - 4 * time + 1) * tangent1.x + (-t2 + time) * 6 * value2.x + (3 * t2 - 2 * time) * tangent2.x;\r\n result.y = (t2 - time) * 6 * value1.y + (3 * t2 - 4 * time + 1) * tangent1.y + (-t2 + time) * 6 * value2.y + (3 * t2 - 2 * time) * tangent2.y;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 located for \"amount\" (float) on the linear interpolation between the vector \"start\" adn the vector \"end\".\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#84\r\n * @param start defines the start vector\r\n * @param end defines the end vector\r\n * @param amount defines the interpolation factor\r\n * @returns a new Vector2\r\n */\r\n public static Lerp(start: DeepImmutable, end: DeepImmutable, amount: number): Vector2 {\r\n const x = start.x + (end.x - start.x) * amount;\r\n const y = start.y + (end.y - start.y) * amount;\r\n return new (start.constructor as Vector2Constructor)(x, y);\r\n }\r\n\r\n /**\r\n * Gets the dot product of the vector \"left\" and the vector \"right\"\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#90\r\n * @param left defines first vector\r\n * @param right defines second vector\r\n * @returns the dot product (float)\r\n */\r\n public static Dot(left: DeepImmutable, right: DeepImmutable): number {\r\n return left.x * right.x + left.y * right.y;\r\n }\r\n\r\n /**\r\n * Returns a new Vector2 equal to the normalized given vector\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#46\r\n * @param vector defines the vector to normalize\r\n * @returns a new Vector2\r\n */\r\n public static Normalize(vector: DeepImmutable): T {\r\n const newVector = new (vector.constructor as Vector2Constructor)();\r\n this.NormalizeToRef(vector, newVector);\r\n return newVector;\r\n }\r\n\r\n /**\r\n * Normalize a given vector into a second one\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#50\r\n * @param vector defines the vector to normalize\r\n * @param result defines the vector where to store the result\r\n * @returns result input\r\n */\r\n public static NormalizeToRef(vector: DeepImmutable, result: T): T {\r\n const len = vector.length();\r\n\r\n if (len === 0) {\r\n return result;\r\n }\r\n\r\n result.x = vector.x / len;\r\n result.y = vector.y / len;\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 set with the minimal coordinate values from the \"left\" and \"right\" vectors\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#86\r\n * @param left defines 1st vector\r\n * @param right defines 2nd vector\r\n * @returns a new Vector2\r\n */\r\n public static Minimize(left: DeepImmutable, right: DeepImmutable): T {\r\n const x = left.x < right.x ? left.x : right.x;\r\n const y = left.y < right.y ? left.y : right.y;\r\n return new (left.constructor as Vector2Constructor)(x, y);\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 set with the maximal coordinate values from the \"left\" and \"right\" vectors\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#86\r\n * @param left defines 1st vector\r\n * @param right defines 2nd vector\r\n * @returns a new Vector2\r\n */\r\n public static Maximize(left: DeepImmutable, right: DeepImmutable): T {\r\n const x = left.x > right.x ? left.x : right.x;\r\n const y = left.y > right.y ? left.y : right.y;\r\n return new (left.constructor as Vector2Constructor)(x, y);\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#17\r\n * @param vector defines the vector to transform\r\n * @param transformation defines the matrix to apply\r\n * @returns a new Vector2\r\n */\r\n public static Transform(vector: DeepImmutable, transformation: DeepImmutable): T {\r\n const result = new (vector.constructor as Vector2Constructor)();\r\n Vector2.TransformToRef(vector, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector \"result\" coordinates\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#19\r\n * @param vector defines the vector to transform\r\n * @param transformation defines the matrix to apply\r\n * @param result defines the target vector\r\n * @returns result input\r\n */\r\n public static TransformToRef(vector: DeepImmutable, transformation: DeepImmutable, result: T): T {\r\n const m = transformation.m;\r\n const x = vector.x * m[0] + vector.y * m[4] + m[12];\r\n const y = vector.x * m[1] + vector.y * m[5] + m[13];\r\n result.x = x;\r\n result.y = y;\r\n return result;\r\n }\r\n\r\n /**\r\n * Determines if a given vector is included in a triangle\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#87\r\n * @param p defines the vector to test\r\n * @param p0 defines 1st triangle point\r\n * @param p1 defines 2nd triangle point\r\n * @param p2 defines 3rd triangle point\r\n * @returns true if the point \"p\" is in the triangle defined by the vectors \"p0\", \"p1\", \"p2\"\r\n */\r\n public static PointInTriangle(p: DeepImmutable, p0: DeepImmutable, p1: DeepImmutable, p2: DeepImmutable): boolean {\r\n const a = (1 / 2) * (-p1.y * p2.x + p0.y * (-p1.x + p2.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y);\r\n const sign = a < 0 ? -1 : 1;\r\n const s = (p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y) * sign;\r\n const t = (p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y) * sign;\r\n\r\n return s > 0 && t > 0 && s + t < 2 * a * sign;\r\n }\r\n\r\n /**\r\n * Gets the distance between the vectors \"value1\" and \"value2\"\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#71\r\n * @param value1 defines first vector\r\n * @param value2 defines second vector\r\n * @returns the distance between vectors\r\n */\r\n public static Distance(value1: DeepImmutable, value2: DeepImmutable): number {\r\n return Math.sqrt(Vector2.DistanceSquared(value1, value2));\r\n }\r\n\r\n /**\r\n * Returns the squared distance between the vectors \"value1\" and \"value2\"\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#72\r\n * @param value1 defines first vector\r\n * @param value2 defines second vector\r\n * @returns the squared distance between vectors\r\n */\r\n public static DistanceSquared(value1: DeepImmutable, value2: DeepImmutable): number {\r\n const x = value1.x - value2.x;\r\n const y = value1.y - value2.y;\r\n return x * x + y * y;\r\n }\r\n\r\n /**\r\n * Gets a new Vector2 located at the center of the vectors \"value1\" and \"value2\"\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#86\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#66\r\n * @param value1 defines first vector\r\n * @param value2 defines second vector\r\n * @returns a new Vector2\r\n */\r\n public static Center(value1: DeepImmutable, value2: DeepImmutable): T {\r\n const result = new (value1.constructor as Vector2Constructor)();\r\n return Vector2.CenterToRef(value1, value2, result);\r\n }\r\n\r\n /**\r\n * Gets the center of the vectors \"value1\" and \"value2\" and stores the result in the vector \"ref\"\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#66\r\n * @param value1 defines first vector\r\n * @param value2 defines second vector\r\n * @param ref defines third vector\r\n * @returns ref\r\n */\r\n public static CenterToRef(value1: DeepImmutable, value2: DeepImmutable, ref: T): T {\r\n return ref.copyFromFloats((value1.x + value2.x) / 2, (value1.y + value2.y) / 2);\r\n }\r\n\r\n /**\r\n * Gets the shortest distance (float) between the point \"p\" and the segment defined by the two points \"segA\" and \"segB\".\r\n * Example Playground https://playground.babylonjs.com/#QYBWV4#77\r\n * @param p defines the middle point\r\n * @param segA defines one point of the segment\r\n * @param segB defines the other point of the segment\r\n * @returns the shortest distance\r\n */\r\n public static DistanceOfPointFromSegment(p: DeepImmutable, segA: DeepImmutable, segB: DeepImmutable): number {\r\n const l2 = Vector2.DistanceSquared(segA, segB);\r\n if (l2 === 0.0) {\r\n return Vector2.Distance(p, segA);\r\n }\r\n const v = segB.subtract(segA);\r\n const t = Math.max(0, Math.min(1, Vector2.Dot(p.subtract(segA), v) / l2));\r\n const proj = segA.add(v.multiplyByFloats(t, t));\r\n return Vector2.Distance(p, proj);\r\n }\r\n}\r\n\r\n/**\r\n * Class used to store (x,y,z) vector representation\r\n * A Vector3 is the main object used in 3D geometry\r\n * It can represent either the coordinates of a point the space, either a direction\r\n * Reminder: js uses a left handed forward facing system\r\n * Example Playground - Overview - https://playground.babylonjs.com/#R1F8YU\r\n */\r\nexport class Vector3 {\r\n private static _UpReadOnly = Vector3.Up() as DeepImmutable;\r\n private static _DownReadOnly = Vector3.Down() as DeepImmutable;\r\n private static _LeftHandedForwardReadOnly = Vector3.Forward(false) as DeepImmutable;\r\n private static _RightHandedForwardReadOnly = Vector3.Forward(true) as DeepImmutable;\r\n private static _LeftHandedBackwardReadOnly = Vector3.Backward(false) as DeepImmutable;\r\n private static _RightHandedBackwardReadOnly = Vector3.Backward(true) as DeepImmutable;\r\n private static _RightReadOnly = Vector3.Right() as DeepImmutable;\r\n private static _LeftReadOnly = Vector3.Left() as DeepImmutable;\r\n private static _ZeroReadOnly = Vector3.Zero() as DeepImmutable;\r\n private static _OneReadOnly = Vector3.One() as DeepImmutable;\r\n\r\n /** @internal */\r\n public _x: number;\r\n\r\n /** @internal */\r\n public _y: number;\r\n\r\n /** @internal */\r\n public _z: number;\r\n\r\n /** @internal */\r\n public _isDirty = true;\r\n\r\n /** Gets or sets the x coordinate */\r\n public get x() {\r\n return this._x;\r\n }\r\n\r\n public set x(value: number) {\r\n this._x = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /** Gets or sets the y coordinate */\r\n public get y() {\r\n return this._y;\r\n }\r\n\r\n public set y(value: number) {\r\n this._y = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /** Gets or sets the z coordinate */\r\n public get z() {\r\n return this._z;\r\n }\r\n\r\n public set z(value: number) {\r\n this._z = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Creates a new Vector3 object from the given x, y, z (floats) coordinates.\r\n * @param x defines the first coordinates (on X axis)\r\n * @param y defines the second coordinates (on Y axis)\r\n * @param z defines the third coordinates (on Z axis)\r\n */\r\n constructor(x: number = 0, y: number = 0, z: number = 0) {\r\n this._x = x;\r\n this._y = y;\r\n this._z = z;\r\n }\r\n\r\n /**\r\n * Creates a string representation of the Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#67\r\n * @returns a string with the Vector3 coordinates.\r\n */\r\n public toString(): string {\r\n return `{X: ${this._x} Y: ${this._y} Z: ${this._z}}`;\r\n }\r\n\r\n /**\r\n * Gets the class name\r\n * @returns the string \"Vector3\"\r\n */\r\n public getClassName(): string {\r\n return \"Vector3\";\r\n }\r\n\r\n /**\r\n * Creates the Vector3 hash code\r\n * @returns a number which tends to be unique between Vector3 instances\r\n */\r\n public getHashCode(): number {\r\n const x = _ExtractAsInt(this._x);\r\n const y = _ExtractAsInt(this._y);\r\n const z = _ExtractAsInt(this._z);\r\n\r\n let hash = x;\r\n hash = (hash * 397) ^ y;\r\n hash = (hash * 397) ^ z;\r\n return hash;\r\n }\r\n\r\n // Operators\r\n\r\n /**\r\n * Creates an array containing three elements : the coordinates of the Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#10\r\n * @returns a new array of numbers\r\n */\r\n public asArray(): number[] {\r\n const result: number[] = [];\r\n this.toArray(result, 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Populates the given array or Float32Array from the given index with the successive coordinates of the Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#65\r\n * @param array defines the destination array\r\n * @param index defines the offset in the destination array\r\n * @returns the current Vector3\r\n */\r\n public toArray(array: FloatArray, index: number = 0): this {\r\n array[index] = this._x;\r\n array[index + 1] = this._y;\r\n array[index + 2] = this._z;\r\n return this;\r\n }\r\n\r\n /**\r\n * Update the current vector from an array\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#24\r\n * @param array defines the destination array\r\n * @param index defines the offset in the destination array\r\n * @returns the current Vector3\r\n */\r\n public fromArray(array: FloatArray, index: number = 0): this {\r\n Vector3.FromArrayToRef(array, index, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Converts the current Vector3 into a quaternion (considering that the Vector3 contains Euler angles representation of a rotation)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#66\r\n * @returns a new Quaternion object, computed from the Vector3 coordinates\r\n */\r\n public toQuaternion(): Quaternion {\r\n return Quaternion.RotationYawPitchRoll(this._y, this._x, this._z);\r\n }\r\n\r\n /**\r\n * Adds the given vector to the current Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#4\r\n * @param otherVector defines the second operand\r\n * @returns the current updated Vector3\r\n */\r\n public addInPlace(otherVector: DeepImmutable): this {\r\n return this.addInPlaceFromFloats(otherVector._x, otherVector._y, otherVector._z);\r\n }\r\n\r\n /**\r\n * Adds the given coordinates to the current Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#5\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public addInPlaceFromFloats(x: number, y: number, z: number): this {\r\n this._x += x;\r\n this._y += y;\r\n this._z += z;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets a new Vector3, result of the addition the current Vector3 and the given vector\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#3\r\n * @param otherVector defines the second operand\r\n * @returns the resulting Vector3\r\n */\r\n public add(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector3Constructor)(this._x + otherVector._x, this._y + otherVector._y, this._z + otherVector._z);\r\n }\r\n\r\n /**\r\n * Adds the current Vector3 to the given one and stores the result in the vector \"result\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#6\r\n * @param otherVector defines the second operand\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public addToRef(otherVector: DeepImmutable, result: T): T {\r\n return result.copyFromFloats(this._x + otherVector._x, this._y + otherVector._y, this._z + otherVector._z);\r\n }\r\n\r\n /**\r\n * Subtract the given vector from the current Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#61\r\n * @param otherVector defines the second operand\r\n * @returns the current updated Vector3\r\n */\r\n public subtractInPlace(otherVector: DeepImmutable): this {\r\n this._x -= otherVector._x;\r\n this._y -= otherVector._y;\r\n this._z -= otherVector._z;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3, result of the subtraction of the given vector from the current Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#60\r\n * @param otherVector defines the second operand\r\n * @returns the resulting Vector3\r\n */\r\n public subtract(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector3Constructor)(this._x - otherVector._x, this._y - otherVector._y, this._z - otherVector._z);\r\n }\r\n\r\n /**\r\n * Subtracts the given vector from the current Vector3 and stores the result in the vector \"result\".\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#63\r\n * @param otherVector defines the second operand\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public subtractToRef(otherVector: DeepImmutable, result: T): T {\r\n return this.subtractFromFloatsToRef(otherVector._x, otherVector._y, otherVector._z, result);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the subtraction of the given floats from the current Vector3 coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#62\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the resulting Vector3\r\n */\r\n public subtractFromFloats(x: number, y: number, z: number): this {\r\n return new (this.constructor as Vector3Constructor)(this._x - x, this._y - y, this._z - z);\r\n }\r\n\r\n /**\r\n * Subtracts the given floats from the current Vector3 coordinates and set the given vector \"result\" with this result\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#64\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public subtractFromFloatsToRef(x: number, y: number, z: number, result: T): T {\r\n return result.copyFromFloats(this._x - x, this._y - y, this._z - z);\r\n }\r\n\r\n /**\r\n * Gets a new Vector3 set with the current Vector3 negated coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#35\r\n * @returns a new Vector3\r\n */\r\n public negate(): this {\r\n return new (this.constructor as Vector3Constructor)(-this._x, -this._y, -this._z);\r\n }\r\n\r\n /**\r\n * Negate this vector in place\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#36\r\n * @returns this\r\n */\r\n public negateInPlace(): this {\r\n this._x *= -1;\r\n this._y *= -1;\r\n this._z *= -1;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Negate the current Vector3 and stores the result in the given vector \"result\" coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#37\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public negateToRef(result: T): T {\r\n return result.copyFromFloats(this._x * -1, this._y * -1, this._z * -1);\r\n }\r\n\r\n /**\r\n * Multiplies the Vector3 coordinates by the float \"scale\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#56\r\n * @param scale defines the multiplier factor\r\n * @returns the current updated Vector3\r\n */\r\n public scaleInPlace(scale: number): this {\r\n this._x *= scale;\r\n this._y *= scale;\r\n this._z *= scale;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float \"scale\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#53\r\n * @param scale defines the multiplier factor\r\n * @returns a new Vector3\r\n */\r\n public scale(scale: number): this {\r\n return new (this.constructor as Vector3Constructor)(this._x * scale, this._y * scale, this._z * scale);\r\n }\r\n\r\n /**\r\n * Multiplies the current Vector3 coordinates by the float \"scale\" and stores the result in the given vector \"result\" coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#57\r\n * @param scale defines the multiplier factor\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public scaleToRef(scale: number, result: T): T {\r\n return result.copyFromFloats(this._x * scale, this._y * scale, this._z * scale);\r\n }\r\n\r\n /**\r\n * Creates a vector normal (perpendicular) to the current Vector3 and stores the result in the given vector\r\n * Out of the infinite possibilities the normal chosen is the one formed by rotating the current vector\r\n * 90 degrees about an axis which lies perpendicular to the current vector\r\n * and its projection on the xz plane. In the case of a current vector in the xz plane\r\n * the normal is calculated to be along the y axis.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#230\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#231\r\n * @param result defines the Vector3 object where to store the resultant normal\r\n * returns the result\r\n */\r\n public getNormalToRef(result: DeepImmutable): Vector3 {\r\n /**\r\n * Calculates the spherical coordinates of the current vector\r\n * so saves on memory rather than importing whole Spherical Class\r\n */\r\n const radius: number = this.length();\r\n let theta: number = Math.acos(this.y / radius);\r\n const phi = Math.atan2(this.z, this.x);\r\n //makes angle 90 degs to current vector\r\n if (theta > Math.PI / 2) {\r\n theta -= Math.PI / 2;\r\n } else {\r\n theta += Math.PI / 2;\r\n }\r\n //Calculates resutant normal vector from spherical coordinate of perpendicular vector\r\n const x = radius * Math.sin(theta) * Math.cos(phi);\r\n const y = radius * Math.cos(theta);\r\n const z = radius * Math.sin(theta) * Math.sin(phi);\r\n result.set(x, y, z);\r\n return result;\r\n }\r\n\r\n /**\r\n * Rotates the vector using the given unit quaternion and stores the new vector in result\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#9\r\n * @param q the unit quaternion representing the rotation\r\n * @param result the output vector\r\n * @returns the result\r\n */\r\n public applyRotationQuaternionToRef(q: Quaternion, result: T): T {\r\n // Derived from https://raw.org/proof/vector-rotation-using-quaternions/\r\n\r\n const vx = this._x,\r\n vy = this._y,\r\n vz = this._z;\r\n const qx = q._x,\r\n qy = q._y,\r\n qz = q._z,\r\n qw = q._w;\r\n\r\n // t = 2q x v\r\n const tx = 2 * (qy * vz - qz * vy);\r\n const ty = 2 * (qz * vx - qx * vz);\r\n const tz = 2 * (qx * vy - qy * vx);\r\n\r\n // v + w t + q x t\r\n result._x = vx + qw * tx + qy * tz - qz * ty;\r\n result._y = vy + qw * ty + qz * tx - qx * tz;\r\n result._z = vz + qw * tz + qx * ty - qy * tx;\r\n\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Rotates the vector in place using the given unit quaternion\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#8\r\n * @param q the unit quaternion representing the rotation\r\n * @returns the current updated Vector3\r\n */\r\n public applyRotationQuaternionInPlace(q: Quaternion): this {\r\n return this.applyRotationQuaternionToRef(q, this);\r\n }\r\n\r\n /**\r\n * Rotates the vector using the given unit quaternion and returns the new vector\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#7\r\n * @param q the unit quaternion representing the rotation\r\n * @returns a new Vector3\r\n */\r\n public applyRotationQuaternion(q: Quaternion): this {\r\n return this.applyRotationQuaternionToRef(q, new (this.constructor as Vector3Constructor)());\r\n }\r\n\r\n /**\r\n * Scale the current Vector3 values by a factor and add the result to a given Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#55\r\n * @param scale defines the scale factor\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns result input\r\n */\r\n public scaleAndAddToRef(scale: number, result: T): T {\r\n return result.addInPlaceFromFloats(this._x * scale, this._y * scale, this._z * scale);\r\n }\r\n\r\n /**\r\n * Projects the current point Vector3 to a plane along a ray starting from a specified origin and passing through the current point Vector3.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#48\r\n * @param plane defines the plane to project to\r\n * @param origin defines the origin of the projection ray\r\n * @returns the projected vector3\r\n */\r\n public projectOnPlane(plane: Plane, origin: Vector3): T {\r\n const result = new (this.constructor as Vector3Constructor)();\r\n this.projectOnPlaneToRef(plane, origin, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Projects the current point Vector3 to a plane along a ray starting from a specified origin and passing through the current point Vector3.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#49\r\n * @param plane defines the plane to project to\r\n * @param origin defines the origin of the projection ray\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public projectOnPlaneToRef(plane: Plane, origin: Vector3, result: T): T {\r\n const n = plane.normal;\r\n const d = plane.d;\r\n\r\n const V = MathTmp.Vector3[0];\r\n\r\n // ray direction\r\n this.subtractToRef(origin, V);\r\n\r\n V.normalize();\r\n\r\n const denom = Vector3.Dot(V, n);\r\n\r\n //When the ray is close to parallel to the plane return infinity vector\r\n if (Math.abs(denom) < Math.pow(10, -10)) {\r\n result.setAll(Infinity);\r\n } else {\r\n const t = -(Vector3.Dot(origin, n) + d) / denom;\r\n\r\n // P = P0 + t*V\r\n const scaledV = V.scaleInPlace(t);\r\n origin.addToRef(scaledV, result);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns true if the current Vector3 and the given vector coordinates are strictly equal\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#19\r\n * @param otherVector defines the second operand\r\n * @returns true if both vectors are equals\r\n */\r\n public equals(otherVector: DeepImmutable): boolean {\r\n return otherVector && this._x === otherVector._x && this._y === otherVector._y && this._z === otherVector._z;\r\n }\r\n\r\n /**\r\n * Returns true if the current Vector3 and the given vector coordinates are distant less than epsilon\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#21\r\n * @param otherVector defines the second operand\r\n * @param epsilon defines the minimal distance to define values as equals\r\n * @returns true if both vectors are distant less than epsilon\r\n */\r\n public equalsWithEpsilon(otherVector: DeepImmutable, epsilon: number = Epsilon): boolean {\r\n return (\r\n otherVector &&\r\n Scalar.WithinEpsilon(this._x, otherVector._x, epsilon) &&\r\n Scalar.WithinEpsilon(this._y, otherVector._y, epsilon) &&\r\n Scalar.WithinEpsilon(this._z, otherVector._z, epsilon)\r\n );\r\n }\r\n\r\n /**\r\n * Returns true if the current Vector3 coordinates equals the given floats\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#20\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns true if both vectors are equal\r\n */\r\n public equalsToFloats(x: number, y: number, z: number): boolean {\r\n return this._x === x && this._y === y && this._z === z;\r\n }\r\n\r\n /**\r\n * Multiplies the current Vector3 coordinates by the given ones\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#32\r\n * @param otherVector defines the second operand\r\n * @returns the current updated Vector3\r\n */\r\n public multiplyInPlace(otherVector: DeepImmutable): this {\r\n this._x *= otherVector._x;\r\n this._y *= otherVector._y;\r\n this._z *= otherVector._z;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3, result of the multiplication of the current Vector3 by the given vector\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#31\r\n * @param otherVector defines the second operand\r\n * @returns the new Vector3\r\n */\r\n public multiply(otherVector: DeepImmutable): this {\r\n return this.multiplyByFloats(otherVector._x, otherVector._y, otherVector._z);\r\n }\r\n\r\n /**\r\n * Multiplies the current Vector3 by the given one and stores the result in the given vector \"result\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#33\r\n * @param otherVector defines the second operand\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public multiplyToRef(otherVector: DeepImmutable, result: T): T {\r\n return result.copyFromFloats(this._x * otherVector._x, this._y * otherVector._y, this._z * otherVector._z);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the result of the multiplication of the current Vector3 coordinates by the given floats\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#34\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the new Vector3\r\n */\r\n public multiplyByFloats(x: number, y: number, z: number): this {\r\n return new (this.constructor as Vector3Constructor)(this._x * x, this._y * y, this._z * z);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#16\r\n * @param otherVector defines the second operand\r\n * @returns the new Vector3\r\n */\r\n public divide(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector3Constructor)(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);\r\n }\r\n\r\n /**\r\n * Divides the current Vector3 coordinates by the given ones and stores the result in the given vector \"result\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#18\r\n * @param otherVector defines the second operand\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public divideToRef(otherVector: DeepImmutable, result: T): T {\r\n return result.copyFromFloats(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);\r\n }\r\n\r\n /**\r\n * Divides the current Vector3 coordinates by the given ones.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#17\r\n * @param otherVector defines the second operand\r\n * @returns the current updated Vector3\r\n */\r\n public divideInPlace(otherVector: Vector3): this {\r\n return this.divideToRef(otherVector, this);\r\n }\r\n\r\n /**\r\n * Updates the current Vector3 with the minimal coordinate values between its and the given vector ones\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#29\r\n * @param other defines the second operand\r\n * @returns the current updated Vector3\r\n */\r\n public minimizeInPlace(other: DeepImmutable): this {\r\n return this.minimizeInPlaceFromFloats(other._x, other._y, other._z);\r\n }\r\n\r\n /**\r\n * Updates the current Vector3 with the maximal coordinate values between its and the given vector ones.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#27\r\n * @param other defines the second operand\r\n * @returns the current updated Vector3\r\n */\r\n public maximizeInPlace(other: DeepImmutable): this {\r\n return this.maximizeInPlaceFromFloats(other._x, other._y, other._z);\r\n }\r\n\r\n /**\r\n * Updates the current Vector3 with the minimal coordinate values between its and the given coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#30\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public minimizeInPlaceFromFloats(x: number, y: number, z: number): this {\r\n if (x < this._x) {\r\n this.x = x;\r\n }\r\n if (y < this._y) {\r\n this.y = y;\r\n }\r\n if (z < this._z) {\r\n this.z = z;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the current Vector3 with the maximal coordinate values between its and the given coordinates.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#28\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public maximizeInPlaceFromFloats(x: number, y: number, z: number): this {\r\n if (x > this._x) {\r\n this.x = x;\r\n }\r\n if (y > this._y) {\r\n this.y = y;\r\n }\r\n if (z > this._z) {\r\n this.z = z;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Due to float precision, scale of a mesh could be uniform but float values are off by a small fraction\r\n * Check if is non uniform within a certain amount of decimal places to account for this\r\n * @param epsilon the amount the values can differ\r\n * @returns if the the vector is non uniform to a certain number of decimal places\r\n */\r\n public isNonUniformWithinEpsilon(epsilon: number) {\r\n const absX = Math.abs(this._x);\r\n const absY = Math.abs(this._y);\r\n if (!Scalar.WithinEpsilon(absX, absY, epsilon)) {\r\n return true;\r\n }\r\n\r\n const absZ = Math.abs(this._z);\r\n if (!Scalar.WithinEpsilon(absX, absZ, epsilon)) {\r\n return true;\r\n }\r\n\r\n if (!Scalar.WithinEpsilon(absY, absZ, epsilon)) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the vector is non uniform meaning x, y or z are not all the same\r\n */\r\n public get isNonUniform(): boolean {\r\n const absX = Math.abs(this._x);\r\n const absY = Math.abs(this._y);\r\n if (absX !== absY) {\r\n return true;\r\n }\r\n\r\n const absZ = Math.abs(this._z);\r\n if (absX !== absZ) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a new Vector3 from current Vector3 floored values\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#22\r\n * @returns a new Vector3\r\n */\r\n public floor(): this {\r\n return new (this.constructor as Vector3Constructor)(Math.floor(this._x), Math.floor(this._y), Math.floor(this._z));\r\n }\r\n\r\n /**\r\n * Gets a new Vector3 from current Vector3 fractional values\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#23\r\n * @returns a new Vector3\r\n */\r\n public fract(): this {\r\n return new (this.constructor as Vector3Constructor)(this._x - Math.floor(this._x), this._y - Math.floor(this._y), this._z - Math.floor(this._z));\r\n }\r\n\r\n // Properties\r\n /**\r\n * Gets the length of the Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#25\r\n * @returns the length of the Vector3\r\n */\r\n public length(): number {\r\n return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z);\r\n }\r\n\r\n /**\r\n * Gets the squared length of the Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#26\r\n * @returns squared length of the Vector3\r\n */\r\n public lengthSquared(): number {\r\n return this._x * this._x + this._y * this._y + this._z * this._z;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the vector contains a zero in one of its components\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#1\r\n */\r\n public get hasAZeroComponent(): boolean {\r\n return this._x * this._y * this._z === 0;\r\n }\r\n\r\n /**\r\n * Normalize the current Vector3.\r\n * Please note that this is an in place operation.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#122\r\n * @returns the current updated Vector3\r\n */\r\n public normalize(): this {\r\n return this.normalizeFromLength(this.length());\r\n }\r\n\r\n /**\r\n * Reorders the x y z properties of the vector in place\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#44\r\n * @param order new ordering of the properties (eg. for vector 1,2,3 with \"ZYX\" will produce 3,2,1)\r\n * @returns the current updated vector\r\n */\r\n public reorderInPlace(order: string) {\r\n order = order.toLowerCase();\r\n if (order === \"xyz\") {\r\n return this;\r\n }\r\n MathTmp.Vector3[0].copyFrom(this);\r\n [\"x\", \"y\", \"z\"].forEach((val, i) => {\r\n (this)[val] = (MathTmp.Vector3[0])[order[i]];\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Rotates the vector around 0,0,0 by a quaternion\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#47\r\n * @param quaternion the rotation quaternion\r\n * @param result vector to store the result\r\n * @returns the resulting vector\r\n */\r\n public rotateByQuaternionToRef(quaternion: Quaternion, result: T): T {\r\n quaternion.toRotationMatrix(MathTmp.Matrix[0]);\r\n Vector3.TransformCoordinatesToRef(this, MathTmp.Matrix[0], result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Rotates a vector around a given point\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#46\r\n * @param quaternion the rotation quaternion\r\n * @param point the point to rotate around\r\n * @param result vector to store the result\r\n * @returns the resulting vector\r\n */\r\n public rotateByQuaternionAroundPointToRef(quaternion: Quaternion, point: Vector3, result: T): T {\r\n this.subtractToRef(point, MathTmp.Vector3[0]);\r\n MathTmp.Vector3[0].rotateByQuaternionToRef(quaternion, MathTmp.Vector3[0]);\r\n point.addToRef(MathTmp.Vector3[0], result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 as the cross product of the current vector and the \"other\" one\r\n * The cross product is then orthogonal to both current and \"other\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#14\r\n * @param other defines the right operand\r\n * @returns the cross product\r\n */\r\n public cross(other: Vector3): this {\r\n const result = new (this.constructor as Vector3Constructor)();\r\n return Vector3.CrossToRef(this, other, result);\r\n }\r\n\r\n /**\r\n * Normalize the current Vector3 with the given input length.\r\n * Please note that this is an in place operation.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#123\r\n * @param len the length of the vector\r\n * @returns the current updated Vector3\r\n */\r\n public normalizeFromLength(len: number): this {\r\n if (len === 0 || len === 1.0) {\r\n return this;\r\n }\r\n\r\n return this.scaleInPlace(1.0 / len);\r\n }\r\n\r\n /**\r\n * Normalize the current Vector3 to a new vector\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#124\r\n * @returns the new Vector3\r\n */\r\n public normalizeToNew(): this {\r\n const normalized = new (this.constructor as Vector3Constructor)(0, 0, 0);\r\n this.normalizeToRef(normalized);\r\n return normalized;\r\n }\r\n\r\n /**\r\n * Normalize the current Vector3 to the reference\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#125\r\n * @param reference define the Vector3 to update\r\n * @returns the updated Vector3\r\n */\r\n public normalizeToRef(reference: T): T {\r\n const len = this.length();\r\n if (len === 0 || len === 1.0) {\r\n return reference.copyFromFloats(this._x, this._y, this._z);\r\n }\r\n\r\n return this.scaleToRef(1.0 / len, reference);\r\n }\r\n\r\n /**\r\n * Creates a new Vector3 copied from the current Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#11\r\n * @returns the new Vector3\r\n */\r\n public clone(): this {\r\n return new (this.constructor as Vector3Constructor)(this._x, this._y, this._z);\r\n }\r\n\r\n /**\r\n * Copies the given vector coordinates to the current Vector3 ones\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#12\r\n * @param source defines the source Vector3\r\n * @returns the current updated Vector3\r\n */\r\n public copyFrom(source: DeepImmutable): this {\r\n return this.copyFromFloats(source._x, source._y, source._z);\r\n }\r\n\r\n /**\r\n * Copies the given floats to the current Vector3 coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#13\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public copyFromFloats(x: number, y: number, z: number): this {\r\n this._x = x;\r\n this._y = y;\r\n this._z = z;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Copies the given floats to the current Vector3 coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#58\r\n * @param x defines the x coordinate of the operand\r\n * @param y defines the y coordinate of the operand\r\n * @param z defines the z coordinate of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public set(x: number, y: number, z: number): this {\r\n return this.copyFromFloats(x, y, z);\r\n }\r\n\r\n /**\r\n * Copies the given float to the current Vector3 coordinates\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#59\r\n * @param v defines the x, y and z coordinates of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public setAll(v: number): this {\r\n this._x = this._y = this._z = v;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Get the clip factor between two vectors\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#126\r\n * @param vector0 defines the first operand\r\n * @param vector1 defines the second operand\r\n * @param axis defines the axis to use\r\n * @param size defines the size along the axis\r\n * @returns the clip factor\r\n */\r\n public static GetClipFactor(vector0: DeepImmutable, vector1: DeepImmutable, axis: DeepImmutable, size: number): number {\r\n const d0 = Vector3.Dot(vector0, axis) - size;\r\n const d1 = Vector3.Dot(vector1, axis) - size;\r\n\r\n const s = d0 / (d0 - d1);\r\n\r\n return s;\r\n }\r\n\r\n /**\r\n * Get angle between two vectors\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#86\r\n * @param vector0 the starting point\r\n * @param vector1 the ending point\r\n * @param normal direction of the normal\r\n * @returns the angle between vector0 and vector1\r\n */\r\n public static GetAngleBetweenVectors(vector0: DeepImmutable, vector1: DeepImmutable, normal: DeepImmutable): number {\r\n const v0: Vector3 = vector0.normalizeToRef(MathTmp.Vector3[1]);\r\n const v1: Vector3 = vector1.normalizeToRef(MathTmp.Vector3[2]);\r\n let dot: number = Vector3.Dot(v0, v1);\r\n // Vectors are normalized so dot will be in [-1, 1] (aside precision issues enough to break the result which explains the below clamp)\r\n dot = Scalar.Clamp(dot, -1, 1);\r\n\r\n const angle = Math.acos(dot);\r\n const n = MathTmp.Vector3[3];\r\n Vector3.CrossToRef(v0, v1, n);\r\n if (Vector3.Dot(n, normal) > 0) {\r\n return isNaN(angle) ? 0 : angle;\r\n }\r\n return isNaN(angle) ? -Math.PI : -Math.acos(dot);\r\n }\r\n\r\n /**\r\n * Get angle between two vectors projected on a plane\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#87\r\n * Expectation compute time: 0.01 ms (median) and 0.02 ms (percentile 95%)\r\n * @param vector0 angle between vector0 and vector1\r\n * @param vector1 angle between vector0 and vector1\r\n * @param normal Normal of the projection plane\r\n * @returns the angle in radians (float) between vector0 and vector1 projected on the plane with the specified normal\r\n */\r\n public static GetAngleBetweenVectorsOnPlane(vector0: Vector3, vector1: Vector3, normal: Vector3): number {\r\n MathTmp.Vector3[0].copyFrom(vector0);\r\n const v0 = MathTmp.Vector3[0];\r\n MathTmp.Vector3[1].copyFrom(vector1);\r\n const v1 = MathTmp.Vector3[1];\r\n MathTmp.Vector3[2].copyFrom(normal);\r\n const vNormal = MathTmp.Vector3[2];\r\n const right = MathTmp.Vector3[3];\r\n const forward = MathTmp.Vector3[4];\r\n\r\n v0.normalize();\r\n v1.normalize();\r\n vNormal.normalize();\r\n\r\n Vector3.CrossToRef(vNormal, v0, right);\r\n Vector3.CrossToRef(right, vNormal, forward);\r\n\r\n const angle = Math.atan2(Vector3.Dot(v1, right), Vector3.Dot(v1, forward));\r\n\r\n return Scalar.NormalizeRadians(angle);\r\n }\r\n\r\n /**\r\n * Gets the rotation that aligns the roll axis (Y) to the line joining the start point to the target point and stores it in the ref Vector3\r\n * Example PG https://playground.babylonjs.com/#R1F8YU#189\r\n * @param start the starting point\r\n * @param target the target point\r\n * @param ref the vector3 to store the result\r\n * @returns ref in the form (pitch, yaw, 0)\r\n */\r\n public static PitchYawRollToMoveBetweenPointsToRef(start: Vector3, target: Vector3, ref: T): T {\r\n const diff = TmpVectors.Vector3[0];\r\n target.subtractToRef(start, diff);\r\n ref._y = Math.atan2(diff.x, diff.z) || 0;\r\n ref._x = Math.atan2(Math.sqrt(diff.x ** 2 + diff.z ** 2), diff.y) || 0;\r\n ref._z = 0;\r\n ref._isDirty = true;\r\n return ref;\r\n }\r\n\r\n /**\r\n * Gets the rotation that aligns the roll axis (Y) to the line joining the start point to the target point\r\n * Example PG https://playground.babylonjs.com/#R1F8YU#188\r\n * @param start the starting point\r\n * @param target the target point\r\n * @returns the rotation in the form (pitch, yaw, 0)\r\n */\r\n public static PitchYawRollToMoveBetweenPoints(start: Vector3, target: Vector3): Vector3 {\r\n const ref = Vector3.Zero();\r\n return Vector3.PitchYawRollToMoveBetweenPointsToRef(start, target, ref);\r\n }\r\n\r\n /**\r\n * Slerp between two vectors. See also `SmoothToRef`\r\n * Slerp is a spherical linear interpolation\r\n * giving a slow in and out effect\r\n * Example Playground 1 https://playground.babylonjs.com/#R1F8YU#108\r\n * Example Playground 2 https://playground.babylonjs.com/#R1F8YU#109\r\n * @param vector0 Start vector\r\n * @param vector1 End vector\r\n * @param slerp amount (will be clamped between 0 and 1)\r\n * @param result The slerped vector\r\n */\r\n public static SlerpToRef(vector0: Vector3, vector1: Vector3, slerp: number, result: T): T {\r\n slerp = Scalar.Clamp(slerp, 0, 1);\r\n const vector0Dir = MathTmp.Vector3[0];\r\n const vector1Dir = MathTmp.Vector3[1];\r\n\r\n vector0Dir.copyFrom(vector0);\r\n const vector0Length = vector0Dir.length();\r\n vector0Dir.normalizeFromLength(vector0Length);\r\n\r\n vector1Dir.copyFrom(vector1);\r\n const vector1Length = vector1Dir.length();\r\n vector1Dir.normalizeFromLength(vector1Length);\r\n\r\n const dot = Vector3.Dot(vector0Dir, vector1Dir);\r\n\r\n let scale0;\r\n let scale1;\r\n\r\n if (dot < 1 - Epsilon) {\r\n const omega = Math.acos(dot);\r\n const invSin = 1 / Math.sin(omega);\r\n scale0 = Math.sin((1 - slerp) * omega) * invSin;\r\n scale1 = Math.sin(slerp * omega) * invSin;\r\n } else {\r\n // Use linear interpolation\r\n scale0 = 1 - slerp;\r\n scale1 = slerp;\r\n }\r\n\r\n vector0Dir.scaleInPlace(scale0);\r\n vector1Dir.scaleInPlace(scale1);\r\n result.copyFrom(vector0Dir).addInPlace(vector1Dir);\r\n result.scaleInPlace(Scalar.Lerp(vector0Length, vector1Length, slerp));\r\n return result;\r\n }\r\n\r\n /**\r\n * Smooth interpolation between two vectors using Slerp\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#110\r\n * @param source source vector\r\n * @param goal goal vector\r\n * @param deltaTime current interpolation frame\r\n * @param lerpTime total interpolation time\r\n * @param result the smoothed vector\r\n */\r\n public static SmoothToRef(source: Vector3, goal: Vector3, deltaTime: number, lerpTime: number, result: T): T {\r\n Vector3.SlerpToRef(source, goal, lerpTime === 0 ? 1 : deltaTime / lerpTime, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set from the index \"offset\" of the given array\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#83\r\n * @param array defines the source array\r\n * @param offset defines the offset in the source array\r\n * @returns the new Vector3\r\n */\r\n public static FromArray(array: DeepImmutable>, offset: number = 0): Vector3 {\r\n return new Vector3(array[offset], array[offset + 1], array[offset + 2]);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set from the index \"offset\" of the given Float32Array\r\n * @param array defines the source array\r\n * @param offset defines the offset in the source array\r\n * @returns the new Vector3\r\n * @deprecated Please use FromArray instead.\r\n */\r\n public static FromFloatArray(array: DeepImmutable, offset?: number): Vector3 {\r\n return Vector3.FromArray(array, offset);\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the element values from the index \"offset\" of the given array\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#84\r\n * @param array defines the source array\r\n * @param offset defines the offset in the source array\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number, result: T): T {\r\n result._x = array[offset];\r\n result._y = array[offset + 1];\r\n result._z = array[offset + 2];\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the element values from the index \"offset\" of the given Float32Array\r\n * @param array defines the source array\r\n * @param offset defines the offset in the source array\r\n * @param result defines the Vector3 where to store the result\r\n * @deprecated Please use FromArrayToRef instead.\r\n */\r\n public static FromFloatArrayToRef(array: DeepImmutable, offset: number, result: T): T {\r\n return Vector3.FromArrayToRef(array, offset, result);\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the given floats.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#85\r\n * @param x defines the x coordinate of the source\r\n * @param y defines the y coordinate of the source\r\n * @param z defines the z coordinate of the source\r\n * @param result defines the Vector3 where to store the result\r\n */\r\n public static FromFloatsToRef(x: number, y: number, z: number, result: T): T {\r\n result.copyFromFloats(x, y, z);\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set to (0.0, 0.0, 0.0)\r\n * @returns a new empty Vector3\r\n */\r\n public static Zero(): Vector3 {\r\n return new Vector3(0.0, 0.0, 0.0);\r\n }\r\n /**\r\n * Returns a new Vector3 set to (1.0, 1.0, 1.0)\r\n * @returns a new Vector3\r\n */\r\n public static One(): Vector3 {\r\n return new Vector3(1.0, 1.0, 1.0);\r\n }\r\n /**\r\n * Returns a new Vector3 set to (0.0, 1.0, 0.0)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\r\n * @returns a new up Vector3\r\n */\r\n public static Up(): Vector3 {\r\n return new Vector3(0.0, 1.0, 0.0);\r\n }\r\n\r\n /**\r\n * Gets an up Vector3 that must not be updated\r\n */\r\n public static get UpReadOnly(): DeepImmutable {\r\n return Vector3._UpReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a down Vector3 that must not be updated\r\n */\r\n public static get DownReadOnly(): DeepImmutable {\r\n return Vector3._DownReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a right Vector3 that must not be updated\r\n */\r\n public static get RightReadOnly(): DeepImmutable {\r\n return Vector3._RightReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a left Vector3 that must not be updated\r\n */\r\n public static get LeftReadOnly(): DeepImmutable {\r\n return Vector3._LeftReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a forward Vector3 that must not be updated\r\n */\r\n public static get LeftHandedForwardReadOnly(): DeepImmutable {\r\n return Vector3._LeftHandedForwardReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a forward Vector3 that must not be updated\r\n */\r\n public static get RightHandedForwardReadOnly(): DeepImmutable {\r\n return Vector3._RightHandedForwardReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a backward Vector3 that must not be updated\r\n */\r\n public static get LeftHandedBackwardReadOnly(): DeepImmutable {\r\n return Vector3._LeftHandedBackwardReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a backward Vector3 that must not be updated\r\n */\r\n public static get RightHandedBackwardReadOnly(): DeepImmutable {\r\n return Vector3._RightHandedBackwardReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a zero Vector3 that must not be updated\r\n */\r\n public static get ZeroReadOnly(): DeepImmutable {\r\n return Vector3._ZeroReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a one Vector3 that must not be updated\r\n */\r\n public static get OneReadOnly(): DeepImmutable {\r\n return Vector3._OneReadOnly;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set to (0.0, -1.0, 0.0)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\r\n * @returns a new down Vector3\r\n */\r\n public static Down(): Vector3 {\r\n return new Vector3(0.0, -1.0, 0.0);\r\n }\r\n /**\r\n * Returns a new Vector3 set to (0.0, 0.0, 1.0)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\r\n * @param rightHandedSystem is the scene right-handed (negative z)\r\n * @returns a new forward Vector3\r\n */\r\n public static Forward(rightHandedSystem: boolean = false): Vector3 {\r\n return new Vector3(0.0, 0.0, rightHandedSystem ? -1.0 : 1.0);\r\n }\r\n /**\r\n * Returns a new Vector3 set to (0.0, 0.0, -1.0)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\r\n * @param rightHandedSystem is the scene right-handed (negative-z)\r\n * @returns a new Backward Vector3\r\n */\r\n public static Backward(rightHandedSystem: boolean = false): Vector3 {\r\n return new Vector3(0.0, 0.0, rightHandedSystem ? 1.0 : -1.0);\r\n }\r\n /**\r\n * Returns a new Vector3 set to (1.0, 0.0, 0.0)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\r\n * @returns a new right Vector3\r\n */\r\n public static Right(): Vector3 {\r\n return new Vector3(1.0, 0.0, 0.0);\r\n }\r\n /**\r\n * Returns a new Vector3 set to (-1.0, 0.0, 0.0)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#71\r\n * @returns a new left Vector3\r\n */\r\n public static Left(): Vector3 {\r\n return new Vector3(-1.0, 0.0, 0.0);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @returns a Vector3 with random values between min and max\r\n */\r\n public static Random(min: number = 0, max: number = 1): Vector3 {\r\n return new Vector3(Scalar.RandomRange(min, max), Scalar.RandomRange(min, max), Scalar.RandomRange(min, max));\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the result of the transformation by the given matrix of the given vector.\r\n * This method computes transformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#111\r\n * @param vector defines the Vector3 to transform\r\n * @param transformation defines the transformation matrix\r\n * @returns the transformed Vector3\r\n */\r\n public static TransformCoordinates(vector: DeepImmutable, transformation: DeepImmutable): Vector3 {\r\n const result = Vector3.Zero();\r\n Vector3.TransformCoordinatesToRef(vector, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given vector\r\n * This method computes transformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#113\r\n * @param vector defines the Vector3 to transform\r\n * @param transformation defines the transformation matrix\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static TransformCoordinatesToRef(vector: DeepImmutable, transformation: DeepImmutable, result: T): T {\r\n Vector3.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)\r\n * This method computes transformed coordinates only, not transformed direction vectors\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#115\r\n * @param x define the x coordinate of the source vector\r\n * @param y define the y coordinate of the source vector\r\n * @param z define the z coordinate of the source vector\r\n * @param transformation defines the transformation matrix\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static TransformCoordinatesFromFloatsToRef(x: number, y: number, z: number, transformation: DeepImmutable, result: T): T {\r\n const m = transformation.m;\r\n const rx = x * m[0] + y * m[4] + z * m[8] + m[12];\r\n const ry = x * m[1] + y * m[5] + z * m[9] + m[13];\r\n const rz = x * m[2] + y * m[6] + z * m[10] + m[14];\r\n const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);\r\n\r\n result._x = rx * rw;\r\n result._y = ry * rw;\r\n result._z = rz * rw;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the result of the normal transformation by the given matrix of the given vector\r\n * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#112\r\n * @param vector defines the Vector3 to transform\r\n * @param transformation defines the transformation matrix\r\n * @returns the new Vector3\r\n */\r\n public static TransformNormal(vector: DeepImmutable, transformation: DeepImmutable): Vector3 {\r\n const result = Vector3.Zero();\r\n Vector3.TransformNormalToRef(vector, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given vector\r\n * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#114\r\n * @param vector defines the Vector3 to transform\r\n * @param transformation defines the transformation matrix\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static TransformNormalToRef(vector: DeepImmutable, transformation: DeepImmutable, result: T): T {\r\n this.TransformNormalFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given floats (x, y, z)\r\n * This methods computes transformed normalized direction vectors only (ie. it does not apply translation)\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#116\r\n * @param x define the x coordinate of the source vector\r\n * @param y define the y coordinate of the source vector\r\n * @param z define the z coordinate of the source vector\r\n * @param transformation defines the transformation matrix\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static TransformNormalFromFloatsToRef(x: number, y: number, z: number, transformation: DeepImmutable, result: T): T {\r\n const m = transformation.m;\r\n result._x = x * m[0] + y * m[4] + z * m[8];\r\n result._y = x * m[1] + y * m[5] + z * m[9];\r\n result._z = x * m[2] + y * m[6] + z * m[10];\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 located for \"amount\" on the CatmullRom interpolation spline defined by the vectors \"value1\", \"value2\", \"value3\", \"value4\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#69\r\n * @param value1 defines the first control point\r\n * @param value2 defines the second control point\r\n * @param value3 defines the third control point\r\n * @param value4 defines the fourth control point\r\n * @param amount defines the amount on the spline to use\r\n * @returns the new Vector3\r\n */\r\n public static CatmullRom(\r\n value1: DeepImmutable,\r\n value2: DeepImmutable,\r\n value3: DeepImmutable,\r\n value4: DeepImmutable,\r\n amount: number\r\n ): T {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n\r\n const x =\r\n 0.5 *\r\n (2.0 * value2._x +\r\n (-value1._x + value3._x) * amount +\r\n (2.0 * value1._x - 5.0 * value2._x + 4.0 * value3._x - value4._x) * squared +\r\n (-value1._x + 3.0 * value2._x - 3.0 * value3._x + value4._x) * cubed);\r\n\r\n const y =\r\n 0.5 *\r\n (2.0 * value2._y +\r\n (-value1._y + value3._y) * amount +\r\n (2.0 * value1._y - 5.0 * value2._y + 4.0 * value3._y - value4._y) * squared +\r\n (-value1._y + 3.0 * value2._y - 3.0 * value3._y + value4._y) * cubed);\r\n\r\n const z =\r\n 0.5 *\r\n (2.0 * value2._z +\r\n (-value1._z + value3._z) * amount +\r\n (2.0 * value1._z - 5.0 * value2._z + 4.0 * value3._z - value4._z) * squared +\r\n (-value1._z + 3.0 * value2._z - 3.0 * value3._z + value4._z) * cubed);\r\n\r\n return new (value1.constructor as Vector3Constructor)(x, y, z);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the coordinates of \"value\", if the vector \"value\" is in the cube defined by the vectors \"min\" and \"max\"\r\n * If a coordinate value of \"value\" is lower than one of the \"min\" coordinate, then this \"value\" coordinate is set with the \"min\" one\r\n * If a coordinate value of \"value\" is greater than one of the \"max\" coordinate, then this \"value\" coordinate is set with the \"max\" one\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#76\r\n * @param value defines the current value\r\n * @param min defines the lower range value\r\n * @param max defines the upper range value\r\n * @returns the new Vector3\r\n */\r\n public static Clamp(value: DeepImmutable, min: DeepImmutable, max: DeepImmutable): T {\r\n const result = new (value.constructor as Vector3Constructor)();\r\n Vector3.ClampToRef(value, min, max, result);\r\n return result;\r\n }\r\n /**\r\n * Sets the given vector \"result\" with the coordinates of \"value\", if the vector \"value\" is in the cube defined by the vectors \"min\" and \"max\"\r\n * If a coordinate value of \"value\" is lower than one of the \"min\" coordinate, then this \"value\" coordinate is set with the \"min\" one\r\n * If a coordinate value of \"value\" is greater than one of the \"max\" coordinate, then this \"value\" coordinate is set with the \"max\" one\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#77\r\n * @param value defines the current value\r\n * @param min defines the lower range value\r\n * @param max defines the upper range value\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static ClampToRef(value: DeepImmutable, min: DeepImmutable, max: DeepImmutable, result: T): T {\r\n let x = value._x;\r\n x = x > max._x ? max._x : x;\r\n x = x < min._x ? min._x : x;\r\n\r\n let y = value._y;\r\n y = y > max._y ? max._y : y;\r\n y = y < min._y ? min._y : y;\r\n\r\n let z = value._z;\r\n z = z > max._z ? max._z : z;\r\n z = z < min._z ? min._z : z;\r\n\r\n result.copyFromFloats(x, y, z);\r\n return result;\r\n }\r\n\r\n /**\r\n * Checks if a given vector is inside a specific range\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#75\r\n * @param v defines the vector to test\r\n * @param min defines the minimum range\r\n * @param max defines the maximum range\r\n */\r\n public static CheckExtends(v: Vector3, min: Vector3, max: Vector3): void {\r\n min.minimizeInPlace(v);\r\n max.maximizeInPlace(v);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 located for \"amount\" (float) on the Hermite interpolation spline defined by the vectors \"value1\", \"tangent1\", \"value2\", \"tangent2\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#89\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent vector\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent vector\r\n * @param amount defines the amount on the interpolation spline (between 0 and 1)\r\n * @returns the new Vector3\r\n */\r\n public static Hermite(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n amount: number\r\n ): T {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\r\n const part2 = -2.0 * cubed + 3.0 * squared;\r\n const part3 = cubed - 2.0 * squared + amount;\r\n const part4 = cubed - squared;\r\n\r\n const x = value1._x * part1 + value2._x * part2 + tangent1._x * part3 + tangent2._x * part4;\r\n const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;\r\n const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;\r\n return new (value1.constructor as Vector3Constructor)(x, y, z);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 which is the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#90\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @returns 1st derivative\r\n */\r\n public static Hermite1stDerivative(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number\r\n ): T {\r\n const result = new (value1.constructor as Vector3Constructor)();\r\n\r\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Update a Vector3 with the 1st derivative of the Hermite spline defined by the vectors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#91\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @param result define where to store the derivative\r\n * @returns result input\r\n */\r\n public static Hermite1stDerivativeToRef(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number,\r\n result: T\r\n ): T {\r\n const t2 = time * time;\r\n\r\n result._x = (t2 - time) * 6 * value1._x + (3 * t2 - 4 * time + 1) * tangent1._x + (-t2 + time) * 6 * value2._x + (3 * t2 - 2 * time) * tangent2._x;\r\n result._y = (t2 - time) * 6 * value1._y + (3 * t2 - 4 * time + 1) * tangent1._y + (-t2 + time) * 6 * value2._y + (3 * t2 - 2 * time) * tangent2._y;\r\n result._z = (t2 - time) * 6 * value1._z + (3 * t2 - 4 * time + 1) * tangent1._z + (-t2 + time) * 6 * value2._z + (3 * t2 - 2 * time) * tangent2._z;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 located for \"amount\" (float) on the linear interpolation between the vectors \"start\" and \"end\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#95\r\n * @param start defines the start value\r\n * @param end defines the end value\r\n * @param amount max defines amount between both (between 0 and 1)\r\n * @returns the new Vector3\r\n */\r\n public static Lerp(start: DeepImmutable, end: DeepImmutable, amount: number): T {\r\n const result = new (start.constructor as Vector3Constructor)(0, 0, 0);\r\n Vector3.LerpToRef(start, end, amount, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the result of the linear interpolation from the vector \"start\" for \"amount\" to the vector \"end\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#93\r\n * @param start defines the start value\r\n * @param end defines the end value\r\n * @param amount max defines amount between both (between 0 and 1)\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static LerpToRef(start: DeepImmutable, end: DeepImmutable, amount: number, result: T): T {\r\n result._x = start._x + (end._x - start._x) * amount;\r\n result._y = start._y + (end._y - start._y) * amount;\r\n result._z = start._z + (end._z - start._z) * amount;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the dot product (float) between the vectors \"left\" and \"right\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#82\r\n * @param left defines the left operand\r\n * @param right defines the right operand\r\n * @returns the dot product\r\n */\r\n public static Dot(left: DeepImmutable, right: DeepImmutable): number {\r\n return left._x * right._x + left._y * right._y + left._z * right._z;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 as the cross product of the vectors \"left\" and \"right\"\r\n * The cross product is then orthogonal to both \"left\" and \"right\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#15\r\n * @param left defines the left operand\r\n * @param right defines the right operand\r\n * @returns the cross product\r\n */\r\n public static Cross(left: DeepImmutable, right: DeepImmutable): T {\r\n const result = new (left.constructor as Vector3Constructor)();\r\n Vector3.CrossToRef(left, right, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the cross product of \"left\" and \"right\"\r\n * The cross product is then orthogonal to both \"left\" and \"right\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#78\r\n * @param left defines the left operand\r\n * @param right defines the right operand\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static CrossToRef(left: DeepImmutable, right: DeepImmutable, result: T): T {\r\n const x = left._y * right._z - left._z * right._y;\r\n const y = left._z * right._x - left._x * right._z;\r\n const z = left._x * right._y - left._y * right._x;\r\n result.copyFromFloats(x, y, z);\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 as the normalization of the given vector\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#98\r\n * @param vector defines the Vector3 to normalize\r\n * @returns the new Vector3\r\n */\r\n public static Normalize(vector: DeepImmutable): Vector3 {\r\n const result = Vector3.Zero();\r\n Vector3.NormalizeToRef(vector, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the normalization of the given first vector\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#98\r\n * @param vector defines the Vector3 to normalize\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static NormalizeToRef(vector: DeepImmutable, result: T): T {\r\n vector.normalizeToRef(result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Project a Vector3 onto screen space\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#101\r\n * @param vector defines the Vector3 to project\r\n * @param world defines the world matrix to use\r\n * @param transform defines the transform (view x projection) matrix to use\r\n * @param viewport defines the screen viewport to use\r\n * @returns the new Vector3\r\n */\r\n public static Project(vector: DeepImmutable, world: DeepImmutable, transform: DeepImmutable, viewport: DeepImmutable): T {\r\n const result = new (vector.constructor as Vector3Constructor)();\r\n Vector3.ProjectToRef(vector, world, transform, viewport, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Project a Vector3 onto screen space to reference\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#102\r\n * @param vector defines the Vector3 to project\r\n * @param world defines the world matrix to use\r\n * @param transform defines the transform (view x projection) matrix to use\r\n * @param viewport defines the screen viewport to use\r\n * @param result the vector in which the screen space will be stored\r\n * @returns result input\r\n */\r\n public static ProjectToRef(\r\n vector: DeepImmutable,\r\n world: DeepImmutable,\r\n transform: DeepImmutable,\r\n viewport: DeepImmutable,\r\n result: T\r\n ): T {\r\n const cw = viewport.width;\r\n const ch = viewport.height;\r\n const cx = viewport.x;\r\n const cy = viewport.y;\r\n\r\n const viewportMatrix = MathTmp.Matrix[1];\r\n\r\n Matrix.FromValuesToRef(cw / 2.0, 0, 0, 0, 0, -ch / 2.0, 0, 0, 0, 0, 0.5, 0, cx + cw / 2.0, ch / 2.0 + cy, 0.5, 1, viewportMatrix);\r\n\r\n const matrix = MathTmp.Matrix[0];\r\n world.multiplyToRef(transform, matrix);\r\n matrix.multiplyToRef(viewportMatrix, matrix);\r\n\r\n Vector3.TransformCoordinatesToRef(vector, matrix, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Reflects a vector off the plane defined by a normalized normal\r\n * @param inDirection defines the vector direction\r\n * @param normal defines the normal - Must be normalized\r\n * @returns the resulting vector\r\n */\r\n public static Reflect(inDirection: DeepImmutable, normal: DeepImmutable): Vector3 {\r\n return this.ReflectToRef(inDirection, normal, new Vector3());\r\n }\r\n\r\n /**\r\n * Reflects a vector off the plane defined by a normalized normal to reference\r\n * @param inDirection defines the vector direction\r\n * @param normal defines the normal - Must be normalized\r\n * @param result defines the Vector3 where to store the result\r\n * @returns the resulting vector\r\n */\r\n public static ReflectToRef(inDirection: DeepImmutable, normal: DeepImmutable, ref: T): T {\r\n const tmp = TmpVectors.Vector3[0];\r\n tmp.copyFrom(normal).scaleInPlace(2 * Vector3.Dot(inDirection, normal));\r\n\r\n return ref.copyFrom(inDirection).subtractInPlace(tmp);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _UnprojectFromInvertedMatrixToRef(source: DeepImmutable, matrix: DeepImmutable, result: T): T {\r\n Vector3.TransformCoordinatesToRef(source, matrix, result);\r\n const m = matrix.m;\r\n const num = source._x * m[3] + source._y * m[7] + source._z * m[11] + m[15];\r\n if (Scalar.WithinEpsilon(num, 1.0)) {\r\n result.scaleInPlace(1.0 / num);\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Unproject from screen space to object space\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#121\r\n * @param source defines the screen space Vector3 to use\r\n * @param viewportWidth defines the current width of the viewport\r\n * @param viewportHeight defines the current height of the viewport\r\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\r\n * @param transform defines the transform (view x projection) matrix to use\r\n * @returns the new Vector3\r\n */\r\n public static UnprojectFromTransform(\r\n source: DeepImmutable,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n transform: DeepImmutable\r\n ): T {\r\n return this.Unproject(source, viewportWidth, viewportHeight, world, transform, Matrix.IdentityReadOnly);\r\n }\r\n\r\n /**\r\n * Unproject from screen space to object space\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#117\r\n * @param source defines the screen space Vector3 to use\r\n * @param viewportWidth defines the current width of the viewport\r\n * @param viewportHeight defines the current height of the viewport\r\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\r\n * @param view defines the view matrix to use\r\n * @param projection defines the projection matrix to use\r\n * @returns the new Vector3\r\n */\r\n public static Unproject(\r\n source: DeepImmutable,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable\r\n ): T {\r\n const result = new (source.constructor as Vector3Constructor)();\r\n\r\n Vector3.UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Unproject from screen space to object space\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#119\r\n * @param source defines the screen space Vector3 to use\r\n * @param viewportWidth defines the current width of the viewport\r\n * @param viewportHeight defines the current height of the viewport\r\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\r\n * @param view defines the view matrix to use\r\n * @param projection defines the projection matrix to use\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static UnprojectToRef(\r\n source: DeepImmutable,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable,\r\n result: T\r\n ): T {\r\n Vector3.UnprojectFloatsToRef(source._x, source._y, source._z, viewportWidth, viewportHeight, world, view, projection, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Unproject from screen space to object space\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#120\r\n * @param sourceX defines the screen space x coordinate to use\r\n * @param sourceY defines the screen space y coordinate to use\r\n * @param sourceZ defines the screen space z coordinate to use\r\n * @param viewportWidth defines the current width of the viewport\r\n * @param viewportHeight defines the current height of the viewport\r\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\r\n * @param view defines the view matrix to use\r\n * @param projection defines the projection matrix to use\r\n * @param result defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static UnprojectFloatsToRef(\r\n sourceX: float,\r\n sourceY: float,\r\n sourceZ: float,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable,\r\n result: T\r\n ): T {\r\n const matrix = MathTmp.Matrix[0];\r\n world.multiplyToRef(view, matrix);\r\n matrix.multiplyToRef(projection, matrix);\r\n matrix.invert();\r\n\r\n const screenSource = MathTmp.Vector3[0];\r\n screenSource.x = (sourceX / viewportWidth) * 2 - 1;\r\n screenSource.y = -((sourceY / viewportHeight) * 2 - 1);\r\n if (EngineStore.LastCreatedEngine?.isNDCHalfZRange) {\r\n screenSource.z = sourceZ;\r\n } else {\r\n screenSource.z = 2 * sourceZ - 1.0;\r\n }\r\n\r\n Vector3._UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets the minimal coordinate values between two Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#97\r\n * @param left defines the first operand\r\n * @param right defines the second operand\r\n * @returns the new Vector3\r\n */\r\n public static Minimize(left: DeepImmutable, right: DeepImmutable): T {\r\n const min = new (left.constructor as Vector3Constructor)();\r\n min.copyFrom(left);\r\n min.minimizeInPlace(right);\r\n return min;\r\n }\r\n\r\n /**\r\n * Gets the maximal coordinate values between two Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#96\r\n * @param left defines the first operand\r\n * @param right defines the second operand\r\n * @returns the new Vector3\r\n */\r\n public static Maximize(left: DeepImmutable, right: DeepImmutable): T {\r\n const max = new (left.constructor as Vector3Constructor)();\r\n max.copyFrom(left);\r\n max.maximizeInPlace(right);\r\n return max;\r\n }\r\n\r\n /**\r\n * Returns the distance between the vectors \"value1\" and \"value2\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#81\r\n * @param value1 defines the first operand\r\n * @param value2 defines the second operand\r\n * @returns the distance\r\n */\r\n public static Distance(value1: DeepImmutable, value2: DeepImmutable): number {\r\n return Math.sqrt(Vector3.DistanceSquared(value1, value2));\r\n }\r\n\r\n /**\r\n * Returns the squared distance between the vectors \"value1\" and \"value2\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#80\r\n * @param value1 defines the first operand\r\n * @param value2 defines the second operand\r\n * @returns the squared distance\r\n */\r\n public static DistanceSquared(value1: DeepImmutable, value2: DeepImmutable): number {\r\n const x = value1._x - value2._x;\r\n const y = value1._y - value2._y;\r\n const z = value1._z - value2._z;\r\n\r\n return x * x + y * y + z * z;\r\n }\r\n\r\n /**\r\n * Projects \"vector\" on the triangle determined by its extremities \"p0\", \"p1\" and \"p2\", stores the result in \"ref\"\r\n * and returns the distance to the projected point.\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#104\r\n * From http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.4264&rep=rep1&type=pdf\r\n *\r\n * @param vector the vector to get distance from\r\n * @param p0 extremity of the triangle\r\n * @param p1 extremity of the triangle\r\n * @param p2 extremity of the triangle\r\n * @param ref variable to store the result to\r\n * @returns The distance between \"ref\" and \"vector\"\r\n */\r\n public static ProjectOnTriangleToRef(vector: DeepImmutable, p0: DeepImmutable, p1: DeepImmutable, p2: DeepImmutable, ref: Vector3): number {\r\n const p1p0 = MathTmp.Vector3[0];\r\n const p2p0 = MathTmp.Vector3[1];\r\n const p2p1 = MathTmp.Vector3[2];\r\n const normal = MathTmp.Vector3[3];\r\n const vectorp0 = MathTmp.Vector3[4];\r\n\r\n // Triangle vectors\r\n p1.subtractToRef(p0, p1p0);\r\n p2.subtractToRef(p0, p2p0);\r\n p2.subtractToRef(p1, p2p1);\r\n\r\n const p1p0L = p1p0.length();\r\n const p2p0L = p2p0.length();\r\n const p2p1L = p2p1.length();\r\n\r\n if (p1p0L < Epsilon || p2p0L < Epsilon || p2p1L < Epsilon) {\r\n // This is a degenerate triangle. As we assume this is part of a non-degenerate mesh,\r\n // we will find a better intersection later.\r\n // Let's just return one of the extremities\r\n ref.copyFrom(p0);\r\n return Vector3.Distance(vector, p0);\r\n }\r\n\r\n // Compute normal and vector to p0\r\n vector.subtractToRef(p0, vectorp0);\r\n Vector3.CrossToRef(p1p0, p2p0, normal);\r\n const nl = normal.length();\r\n if (nl < Epsilon) {\r\n // Extremities are aligned, we are back on the case of a degenerate triangle\r\n ref.copyFrom(p0);\r\n return Vector3.Distance(vector, p0);\r\n }\r\n normal.normalizeFromLength(nl);\r\n let l = vectorp0.length();\r\n if (l < Epsilon) {\r\n // Vector is p0\r\n ref.copyFrom(p0);\r\n return 0;\r\n }\r\n vectorp0.normalizeFromLength(l);\r\n\r\n // Project to \"proj\" that lies on the triangle plane\r\n const cosA = Vector3.Dot(normal, vectorp0);\r\n const projVector = MathTmp.Vector3[5];\r\n const proj = MathTmp.Vector3[6];\r\n projVector.copyFrom(normal).scaleInPlace(-l * cosA);\r\n proj.copyFrom(vector).addInPlace(projVector);\r\n\r\n // Compute barycentric coordinates (v0, v1 and v2 are axis from barycenter to extremities)\r\n const v0 = MathTmp.Vector3[4];\r\n const v1 = MathTmp.Vector3[5];\r\n const v2 = MathTmp.Vector3[7];\r\n const tmp = MathTmp.Vector3[8];\r\n\r\n v0.copyFrom(p1p0).scaleInPlace(1 / p1p0L);\r\n tmp.copyFrom(p2p0).scaleInPlace(1 / p2p0L);\r\n v0.addInPlace(tmp).scaleInPlace(-1);\r\n\r\n v1.copyFrom(p1p0).scaleInPlace(-1 / p1p0L);\r\n tmp.copyFrom(p2p1).scaleInPlace(1 / p2p1L);\r\n v1.addInPlace(tmp).scaleInPlace(-1);\r\n\r\n v2.copyFrom(p2p1).scaleInPlace(-1 / p2p1L);\r\n tmp.copyFrom(p2p0).scaleInPlace(-1 / p2p0L);\r\n v2.addInPlace(tmp).scaleInPlace(-1);\r\n\r\n // Determines which edge of the triangle is closest to \"proj\"\r\n const projP = MathTmp.Vector3[9];\r\n let dot;\r\n projP.copyFrom(proj).subtractInPlace(p0);\r\n Vector3.CrossToRef(v0, projP, tmp);\r\n dot = Vector3.Dot(tmp, normal);\r\n const s0 = dot;\r\n\r\n projP.copyFrom(proj).subtractInPlace(p1);\r\n Vector3.CrossToRef(v1, projP, tmp);\r\n dot = Vector3.Dot(tmp, normal);\r\n const s1 = dot;\r\n\r\n projP.copyFrom(proj).subtractInPlace(p2);\r\n Vector3.CrossToRef(v2, projP, tmp);\r\n dot = Vector3.Dot(tmp, normal);\r\n const s2 = dot;\r\n\r\n const edge = MathTmp.Vector3[10];\r\n let e0, e1;\r\n if (s0 > 0 && s1 < 0) {\r\n edge.copyFrom(p1p0);\r\n e0 = p0;\r\n e1 = p1;\r\n } else if (s1 > 0 && s2 < 0) {\r\n edge.copyFrom(p2p1);\r\n e0 = p1;\r\n e1 = p2;\r\n } else {\r\n edge.copyFrom(p2p0).scaleInPlace(-1);\r\n e0 = p2;\r\n e1 = p0;\r\n }\r\n\r\n // Determines if \"proj\" lies inside the triangle\r\n const tmp2 = MathTmp.Vector3[9];\r\n const tmp3 = MathTmp.Vector3[4];\r\n e0.subtractToRef(proj, tmp);\r\n e1.subtractToRef(proj, tmp2);\r\n Vector3.CrossToRef(tmp, tmp2, tmp3);\r\n const isOutside = Vector3.Dot(tmp3, normal) < 0;\r\n\r\n // If inside, we already found the projected point, \"proj\"\r\n if (!isOutside) {\r\n ref.copyFrom(proj);\r\n return Math.abs(l * cosA);\r\n }\r\n\r\n // If outside, we find \"triProj\", the closest point from \"proj\" on the closest edge\r\n const r = MathTmp.Vector3[5];\r\n Vector3.CrossToRef(edge, tmp3, r);\r\n r.normalize();\r\n const e0proj = MathTmp.Vector3[9];\r\n e0proj.copyFrom(e0).subtractInPlace(proj);\r\n const e0projL = e0proj.length();\r\n if (e0projL < Epsilon) {\r\n // Proj is e0\r\n ref.copyFrom(e0);\r\n return Vector3.Distance(vector, e0);\r\n }\r\n e0proj.normalizeFromLength(e0projL);\r\n const cosG = Vector3.Dot(r, e0proj);\r\n const triProj = MathTmp.Vector3[7];\r\n triProj.copyFrom(proj).addInPlace(r.scaleInPlace(e0projL * cosG));\r\n\r\n // Now we clamp \"triProj\" so it lies between e0 and e1\r\n tmp.copyFrom(triProj).subtractInPlace(e0);\r\n l = edge.length();\r\n edge.normalizeFromLength(l);\r\n let t = Vector3.Dot(tmp, edge) / Math.max(l, Epsilon);\r\n t = Scalar.Clamp(t, 0, 1);\r\n triProj.copyFrom(e0).addInPlace(edge.scaleInPlace(t * l));\r\n ref.copyFrom(triProj);\r\n\r\n return Vector3.Distance(vector, triProj);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 located at the center between \"value1\" and \"value2\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#72\r\n * @param value1 defines the first operand\r\n * @param value2 defines the second operand\r\n * @returns the new Vector3\r\n */\r\n public static Center(value1: DeepImmutable, value2: DeepImmutable): Vector3 {\r\n return Vector3.CenterToRef(value1, value2, Vector3.Zero());\r\n }\r\n\r\n /**\r\n * Gets the center of the vectors \"value1\" and \"value2\" and stores the result in the vector \"ref\"\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#73\r\n * @param value1 defines first vector\r\n * @param value2 defines second vector\r\n * @param ref defines third vector\r\n * @returns ref\r\n */\r\n public static CenterToRef(value1: DeepImmutable, value2: DeepImmutable, ref: T): T {\r\n return ref.copyFromFloats((value1._x + value2._x) / 2, (value1._y + value2._y) / 2, (value1._z + value2._z) / 2);\r\n }\r\n\r\n /**\r\n * Given three orthogonal normalized left-handed oriented Vector3 axis in space (target system),\r\n * RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply\r\n * to something in order to rotate it from its local system to the given target system\r\n * Note: axis1, axis2 and axis3 are normalized during this operation\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#106\r\n * @param axis1 defines the first axis\r\n * @param axis2 defines the second axis\r\n * @param axis3 defines the third axis\r\n * @returns a new Vector3\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/target_align\r\n */\r\n public static RotationFromAxis(axis1: DeepImmutable, axis2: DeepImmutable, axis3: DeepImmutable): T {\r\n const rotation = new (axis1.constructor as Vector3Constructor)();\r\n Vector3.RotationFromAxisToRef(axis1, axis2, axis3, rotation);\r\n return rotation;\r\n }\r\n\r\n /**\r\n * The same than RotationFromAxis but updates the given ref Vector3 parameter instead of returning a new Vector3\r\n * Example Playground https://playground.babylonjs.com/#R1F8YU#107\r\n * @param axis1 defines the first axis\r\n * @param axis2 defines the second axis\r\n * @param axis3 defines the third axis\r\n * @param ref defines the Vector3 where to store the result\r\n * @returns result input\r\n */\r\n public static RotationFromAxisToRef(axis1: DeepImmutable, axis2: DeepImmutable, axis3: DeepImmutable, ref: T): T {\r\n const quat = MathTmp.Quaternion[0];\r\n Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);\r\n quat.toEulerAnglesToRef(ref);\r\n return ref;\r\n }\r\n}\r\n\r\n/**\r\n * Vector4 class created for EulerAngle class conversion to Quaternion\r\n */\r\nexport class Vector4 {\r\n private static _ZeroReadOnly = Vector4.Zero() as DeepImmutable;\r\n\r\n /**\r\n * Creates a Vector4 object from the given floats.\r\n * @param x x value of the vector\r\n * @param y y value of the vector\r\n * @param z z value of the vector\r\n * @param w w value of the vector\r\n */\r\n constructor(\r\n /** x value of the vector */\r\n public x: number = 0,\r\n /** y value of the vector */\r\n public y: number = 0,\r\n /** z value of the vector */\r\n public z: number = 0,\r\n /** w value of the vector */\r\n public w: number = 0\r\n ) {}\r\n\r\n /**\r\n * Returns the string with the Vector4 coordinates.\r\n * @returns a string containing all the vector values\r\n */\r\n public toString(): string {\r\n return `{X: ${this.x} Y: ${this.y} Z: ${this.z} W: ${this.w}}`;\r\n }\r\n\r\n /**\r\n * Returns the string \"Vector4\".\r\n * @returns \"Vector4\"\r\n */\r\n public getClassName(): string {\r\n return \"Vector4\";\r\n }\r\n\r\n /**\r\n * Returns the Vector4 hash code.\r\n * @returns a unique hash code\r\n */\r\n public getHashCode(): number {\r\n const x = _ExtractAsInt(this.x);\r\n const y = _ExtractAsInt(this.y);\r\n const z = _ExtractAsInt(this.z);\r\n const w = _ExtractAsInt(this.w);\r\n\r\n let hash = x;\r\n hash = (hash * 397) ^ y;\r\n hash = (hash * 397) ^ z;\r\n hash = (hash * 397) ^ w;\r\n return hash;\r\n }\r\n\r\n // Operators\r\n /**\r\n * Returns a new array populated with 4 elements : the Vector4 coordinates.\r\n * @returns the resulting array\r\n */\r\n public asArray(): number[] {\r\n const result = new Array();\r\n\r\n this.toArray(result, 0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Populates the given array from the given index with the Vector4 coordinates.\r\n * @param array array to populate\r\n * @param index index of the array to start at (default: 0)\r\n * @returns the Vector4.\r\n */\r\n public toArray(array: FloatArray, index?: number): this {\r\n if (index === undefined) {\r\n index = 0;\r\n }\r\n array[index] = this.x;\r\n array[index + 1] = this.y;\r\n array[index + 2] = this.z;\r\n array[index + 3] = this.w;\r\n return this;\r\n }\r\n\r\n /**\r\n * Update the current vector from an array\r\n * @param array defines the destination array\r\n * @param index defines the offset in the destination array\r\n * @returns the current Vector3\r\n */\r\n public fromArray(array: FloatArray, index: number = 0): this {\r\n Vector4.FromArrayToRef(array, index, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds the given vector to the current Vector4.\r\n * @param otherVector the vector to add\r\n * @returns the updated Vector4.\r\n */\r\n public addInPlace(otherVector: DeepImmutable): this {\r\n this.x += otherVector.x;\r\n this.y += otherVector.y;\r\n this.z += otherVector.z;\r\n this.w += otherVector.w;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 as the result of the addition of the current Vector4 and the given one.\r\n * @param otherVector the vector to add\r\n * @returns the resulting vector\r\n */\r\n public add(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector4Constructor)(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z, this.w + otherVector.w);\r\n }\r\n\r\n /**\r\n * Updates the given vector \"result\" with the result of the addition of the current Vector4 and the given one.\r\n * @param otherVector the vector to add\r\n * @param result the vector to store the result\r\n * @returns result input\r\n */\r\n public addToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x + otherVector.x;\r\n result.y = this.y + otherVector.y;\r\n result.z = this.z + otherVector.z;\r\n result.w = this.w + otherVector.w;\r\n return result;\r\n }\r\n\r\n /**\r\n * Subtract in place the given vector from the current Vector4.\r\n * @param otherVector the vector to subtract\r\n * @returns the updated Vector4.\r\n */\r\n public subtractInPlace(otherVector: DeepImmutable): this {\r\n this.x -= otherVector.x;\r\n this.y -= otherVector.y;\r\n this.z -= otherVector.z;\r\n this.w -= otherVector.w;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 with the result of the subtraction of the given vector from the current Vector4.\r\n * @param otherVector the vector to add\r\n * @returns the new vector with the result\r\n */\r\n public subtract(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector4Constructor)(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z, this.w - otherVector.w);\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the result of the subtraction of the given vector from the current Vector4.\r\n * @param otherVector the vector to subtract\r\n * @param result the vector to store the result\r\n * @returns result input\r\n */\r\n public subtractToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x - otherVector.x;\r\n result.y = this.y - otherVector.y;\r\n result.z = this.z - otherVector.z;\r\n result.w = this.w - otherVector.w;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.\r\n */\r\n /**\r\n * Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.\r\n * @param x value to subtract\r\n * @param y value to subtract\r\n * @param z value to subtract\r\n * @param w value to subtract\r\n * @returns new vector containing the result\r\n */\r\n public subtractFromFloats(x: number, y: number, z: number, w: number): this {\r\n return new (this.constructor as Vector4Constructor)(this.x - x, this.y - y, this.z - z, this.w - w);\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" set with the result of the subtraction of the given floats from the current Vector4 coordinates.\r\n * @param x value to subtract\r\n * @param y value to subtract\r\n * @param z value to subtract\r\n * @param w value to subtract\r\n * @param result the vector to store the result in\r\n * @returns result input\r\n */\r\n public subtractFromFloatsToRef(x: number, y: number, z: number, w: number, result: T): T {\r\n result.x = this.x - x;\r\n result.y = this.y - y;\r\n result.z = this.z - z;\r\n result.w = this.w - w;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 set with the current Vector4 negated coordinates.\r\n * @returns a new vector with the negated values\r\n */\r\n public negate(): this {\r\n return new (this.constructor as Vector4Constructor)(-this.x, -this.y, -this.z, -this.w);\r\n }\r\n\r\n /**\r\n * Negate this vector in place\r\n * @returns this\r\n */\r\n public negateInPlace(): this {\r\n this.x *= -1;\r\n this.y *= -1;\r\n this.z *= -1;\r\n this.w *= -1;\r\n return this;\r\n }\r\n\r\n /**\r\n * Negate the current Vector4 and stores the result in the given vector \"result\" coordinates\r\n * @param result defines the Vector3 object where to store the result\r\n * @returns the result\r\n */\r\n public negateToRef(result: T): T {\r\n return result.copyFromFloats(this.x * -1, this.y * -1, this.z * -1, this.w * -1);\r\n }\r\n\r\n /**\r\n * Multiplies the current Vector4 coordinates by scale (float).\r\n * @param scale the number to scale with\r\n * @returns the updated Vector4.\r\n */\r\n public scaleInPlace(scale: number): this {\r\n this.x *= scale;\r\n this.y *= scale;\r\n this.z *= scale;\r\n this.w *= scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 set with the current Vector4 coordinates multiplied by scale (float).\r\n * @param scale the number to scale with\r\n * @returns a new vector with the result\r\n */\r\n public scale(scale: number): this {\r\n return new (this.constructor as Vector4Constructor)(this.x * scale, this.y * scale, this.z * scale, this.w * scale);\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the current Vector4 coordinates multiplied by scale (float).\r\n * @param scale the number to scale with\r\n * @param result a vector to store the result in\r\n * @returns result input\r\n */\r\n public scaleToRef(scale: number, result: T): T {\r\n result.x = this.x * scale;\r\n result.y = this.y * scale;\r\n result.z = this.z * scale;\r\n result.w = this.w * scale;\r\n return result;\r\n }\r\n\r\n /**\r\n * Scale the current Vector4 values by a factor and add the result to a given Vector4\r\n * @param scale defines the scale factor\r\n * @param result defines the Vector4 object where to store the result\r\n * @returns result input\r\n */\r\n public scaleAndAddToRef(scale: number, result: T): T {\r\n result.x += this.x * scale;\r\n result.y += this.y * scale;\r\n result.z += this.z * scale;\r\n result.w += this.w * scale;\r\n return result;\r\n }\r\n\r\n /**\r\n * Boolean : True if the current Vector4 coordinates are stricly equal to the given ones.\r\n * @param otherVector the vector to compare against\r\n * @returns true if they are equal\r\n */\r\n public equals(otherVector: DeepImmutable): boolean {\r\n return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z && this.w === otherVector.w;\r\n }\r\n\r\n /**\r\n * Boolean : True if the current Vector4 coordinates are each beneath the distance \"epsilon\" from the given vector ones.\r\n * @param otherVector vector to compare against\r\n * @param epsilon (Default: very small number)\r\n * @returns true if they are equal\r\n */\r\n public equalsWithEpsilon(otherVector: DeepImmutable, epsilon: number = Epsilon): boolean {\r\n return (\r\n otherVector &&\r\n Scalar.WithinEpsilon(this.x, otherVector.x, epsilon) &&\r\n Scalar.WithinEpsilon(this.y, otherVector.y, epsilon) &&\r\n Scalar.WithinEpsilon(this.z, otherVector.z, epsilon) &&\r\n Scalar.WithinEpsilon(this.w, otherVector.w, epsilon)\r\n );\r\n }\r\n\r\n /**\r\n * Boolean : True if the given floats are strictly equal to the current Vector4 coordinates.\r\n * @param x x value to compare against\r\n * @param y y value to compare against\r\n * @param z z value to compare against\r\n * @param w w value to compare against\r\n * @returns true if equal\r\n */\r\n public equalsToFloats(x: number, y: number, z: number, w: number): boolean {\r\n return this.x === x && this.y === y && this.z === z && this.w === w;\r\n }\r\n\r\n /**\r\n * Multiplies in place the current Vector4 by the given one.\r\n * @param otherVector vector to multiple with\r\n * @returns the updated Vector4.\r\n */\r\n public multiplyInPlace(otherVector: Vector4): this {\r\n this.x *= otherVector.x;\r\n this.y *= otherVector.y;\r\n this.z *= otherVector.z;\r\n this.w *= otherVector.w;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 set with the multiplication result of the current Vector4 and the given one.\r\n * @param otherVector vector to multiple with\r\n * @returns resulting new vector\r\n */\r\n public multiply(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector4Constructor)(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z, this.w * otherVector.w);\r\n }\r\n /**\r\n * Updates the given vector \"result\" with the multiplication result of the current Vector4 and the given one.\r\n * @param otherVector vector to multiple with\r\n * @param result vector to store the result\r\n * @returns result input\r\n */\r\n public multiplyToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x * otherVector.x;\r\n result.y = this.y * otherVector.y;\r\n result.z = this.z * otherVector.z;\r\n result.w = this.w * otherVector.w;\r\n return result;\r\n }\r\n /**\r\n * Returns a new Vector4 set with the multiplication result of the given floats and the current Vector4 coordinates.\r\n * @param x x value multiply with\r\n * @param y y value multiply with\r\n * @param z z value multiply with\r\n * @param w w value multiply with\r\n * @returns resulting new vector\r\n */\r\n public multiplyByFloats(x: number, y: number, z: number, w: number): this {\r\n return new (this.constructor as Vector4Constructor)(this.x * x, this.y * y, this.z * z, this.w * w);\r\n }\r\n /**\r\n * Returns a new Vector4 set with the division result of the current Vector4 by the given one.\r\n * @param otherVector vector to devide with\r\n * @returns resulting new vector\r\n */\r\n public divide(otherVector: DeepImmutable): this {\r\n return new (this.constructor as Vector4Constructor)(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z, this.w / otherVector.w);\r\n }\r\n /**\r\n * Updates the given vector \"result\" with the division result of the current Vector4 by the given one.\r\n * @param otherVector vector to devide with\r\n * @param result vector to store the result\r\n * @returns result input\r\n */\r\n public divideToRef(otherVector: DeepImmutable, result: T): T {\r\n result.x = this.x / otherVector.x;\r\n result.y = this.y / otherVector.y;\r\n result.z = this.z / otherVector.z;\r\n result.w = this.w / otherVector.w;\r\n return result;\r\n }\r\n\r\n /**\r\n * Divides the current Vector3 coordinates by the given ones.\r\n * @param otherVector vector to devide with\r\n * @returns the updated Vector3.\r\n */\r\n public divideInPlace(otherVector: DeepImmutable): this {\r\n return this.divideToRef(otherVector, this);\r\n }\r\n\r\n /**\r\n * Updates the Vector4 coordinates with the minimum values between its own and the given vector ones\r\n * @param other defines the second operand\r\n * @returns the current updated Vector4\r\n */\r\n public minimizeInPlace(other: DeepImmutable): this {\r\n if (other.x < this.x) {\r\n this.x = other.x;\r\n }\r\n if (other.y < this.y) {\r\n this.y = other.y;\r\n }\r\n if (other.z < this.z) {\r\n this.z = other.z;\r\n }\r\n if (other.w < this.w) {\r\n this.w = other.w;\r\n }\r\n return this;\r\n }\r\n /**\r\n * Updates the Vector4 coordinates with the maximum values between its own and the given vector ones\r\n * @param other defines the second operand\r\n * @returns the current updated Vector4\r\n */\r\n public maximizeInPlace(other: DeepImmutable): this {\r\n if (other.x > this.x) {\r\n this.x = other.x;\r\n }\r\n if (other.y > this.y) {\r\n this.y = other.y;\r\n }\r\n if (other.z > this.z) {\r\n this.z = other.z;\r\n }\r\n if (other.w > this.w) {\r\n this.w = other.w;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets a new Vector4 from current Vector4 floored values\r\n * @returns a new Vector4\r\n */\r\n public floor(): this {\r\n return new (this.constructor as Vector4Constructor)(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z), Math.floor(this.w));\r\n }\r\n\r\n /**\r\n * Gets a new Vector4 from current Vector4 fractional values\r\n * @returns a new Vector4\r\n */\r\n public fract(): this {\r\n return new (this.constructor as Vector4Constructor)(\r\n this.x - Math.floor(this.x),\r\n this.y - Math.floor(this.y),\r\n this.z - Math.floor(this.z),\r\n this.w - Math.floor(this.w)\r\n );\r\n }\r\n\r\n // Properties\r\n /**\r\n * Returns the Vector4 length (float).\r\n * @returns the length\r\n */\r\n public length(): number {\r\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);\r\n }\r\n /**\r\n * Returns the Vector4 squared length (float).\r\n * @returns the length squared\r\n */\r\n public lengthSquared(): number {\r\n return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Normalizes in place the Vector4.\r\n * @returns the updated Vector4.\r\n */\r\n public normalize(): this {\r\n const len = this.length();\r\n\r\n if (len === 0) {\r\n return this;\r\n }\r\n\r\n return this.scaleInPlace(1.0 / len);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 from the Vector4 (x, y, z) coordinates.\r\n * @returns this converted to a new vector3\r\n */\r\n public toVector3(): Vector3 {\r\n return new Vector3(this.x, this.y, this.z);\r\n }\r\n /**\r\n * Returns a new Vector4 copied from the current one.\r\n * @returns the new cloned vector\r\n */\r\n public clone(): this {\r\n return new (this.constructor as Vector4Constructor)(this.x, this.y, this.z, this.w);\r\n }\r\n /**\r\n * Updates the current Vector4 with the given one coordinates.\r\n * @param source the source vector to copy from\r\n * @returns the updated Vector4.\r\n */\r\n public copyFrom(source: DeepImmutable): this {\r\n this.x = source.x;\r\n this.y = source.y;\r\n this.z = source.z;\r\n this.w = source.w;\r\n return this;\r\n }\r\n /**\r\n * Updates the current Vector4 coordinates with the given floats.\r\n * @param x float to copy from\r\n * @param y float to copy from\r\n * @param z float to copy from\r\n * @param w float to copy from\r\n * @returns the updated Vector4.\r\n */\r\n public copyFromFloats(x: number, y: number, z: number, w: number): this {\r\n this.x = x;\r\n this.y = y;\r\n this.z = z;\r\n this.w = w;\r\n return this;\r\n }\r\n /**\r\n * Updates the current Vector4 coordinates with the given floats.\r\n * @param x float to set from\r\n * @param y float to set from\r\n * @param z float to set from\r\n * @param w float to set from\r\n * @returns the updated Vector4.\r\n */\r\n public set(x: number, y: number, z: number, w: number): this {\r\n return this.copyFromFloats(x, y, z, w);\r\n }\r\n\r\n /**\r\n * Copies the given float to the current Vector3 coordinates\r\n * @param v defines the x, y, z and w coordinates of the operand\r\n * @returns the current updated Vector3\r\n */\r\n public setAll(v: number): this {\r\n this.x = this.y = this.z = this.w = v;\r\n return this;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Returns a new Vector4 set from the starting index of the given array.\r\n * @param array the array to pull values from\r\n * @param offset the offset into the array to start at\r\n * @returns the new vector\r\n */\r\n public static FromArray(array: DeepImmutable>, offset?: number): Vector4 {\r\n if (!offset) {\r\n offset = 0;\r\n }\r\n return new Vector4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\r\n }\r\n /**\r\n * Updates the given vector \"result\" from the starting index of the given array.\r\n * @param array the array to pull values from\r\n * @param offset the offset into the array to start at\r\n * @param result the vector to store the result in\r\n * @returns result input\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number, result: T): T {\r\n result.x = array[offset];\r\n result.y = array[offset + 1];\r\n result.z = array[offset + 2];\r\n result.w = array[offset + 3];\r\n return result;\r\n }\r\n /**\r\n * Updates the given vector \"result\" from the starting index of the given Float32Array.\r\n * @param array the array to pull values from\r\n * @param offset the offset into the array to start at\r\n * @param result the vector to store the result in\r\n * @returns result input\r\n */\r\n public static FromFloatArrayToRef(array: DeepImmutable, offset: number, result: T): T {\r\n Vector4.FromArrayToRef(array, offset, result);\r\n return result;\r\n }\r\n /**\r\n * Updates the given vector \"result\" coordinates from the given floats.\r\n * @param x float to set from\r\n * @param y float to set from\r\n * @param z float to set from\r\n * @param w float to set from\r\n * @param result the vector to the floats in\r\n * @returns result input\r\n */\r\n public static FromFloatsToRef(x: number, y: number, z: number, w: number, result: T): T {\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = w;\r\n return result;\r\n }\r\n /**\r\n * Returns a new Vector4 set to (0.0, 0.0, 0.0, 0.0)\r\n * @returns the new vector\r\n */\r\n public static Zero(): Vector4 {\r\n return new Vector4(0.0, 0.0, 0.0, 0.0);\r\n }\r\n /**\r\n * Returns a new Vector4 set to (1.0, 1.0, 1.0, 1.0)\r\n * @returns the new vector\r\n */\r\n public static One(): Vector4 {\r\n return new Vector4(1.0, 1.0, 1.0, 1.0);\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @returns a Vector4 with random values between min and max\r\n */\r\n public static Random(min: number = 0, max: number = 1): Vector4 {\r\n return new Vector4(Scalar.RandomRange(min, max), Scalar.RandomRange(min, max), Scalar.RandomRange(min, max), Scalar.RandomRange(min, max));\r\n }\r\n\r\n /**\r\n * Gets a zero Vector4 that must not be updated\r\n */\r\n public static get ZeroReadOnly(): DeepImmutable {\r\n return Vector4._ZeroReadOnly;\r\n }\r\n /**\r\n * Returns a new normalized Vector4 from the given one.\r\n * @param vector the vector to normalize\r\n * @returns the vector\r\n */\r\n public static Normalize(vector: DeepImmutable): Vector4 {\r\n const result = Vector4.Zero();\r\n Vector4.NormalizeToRef(vector, result);\r\n return result;\r\n }\r\n /**\r\n * Updates the given vector \"result\" from the normalization of the given one.\r\n * @param vector the vector to normalize\r\n * @param result the vector to store the result in\r\n * @returns result input\r\n */\r\n public static NormalizeToRef(vector: DeepImmutable, result: T): T {\r\n result.copyFrom(vector);\r\n result.normalize();\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a vector with the minimum values from the left and right vectors\r\n * @param left left vector to minimize\r\n * @param right right vector to minimize\r\n * @returns a new vector with the minimum of the left and right vector values\r\n */\r\n public static Minimize(left: DeepImmutable, right: DeepImmutable): T {\r\n const min = new (left.constructor as Vector4Constructor)();\r\n min.copyFrom(left);\r\n min.minimizeInPlace(right);\r\n return min;\r\n }\r\n\r\n /**\r\n * Returns a vector with the maximum values from the left and right vectors\r\n * @param left left vector to maximize\r\n * @param right right vector to maximize\r\n * @returns a new vector with the maximum of the left and right vector values\r\n */\r\n public static Maximize(left: DeepImmutable, right: DeepImmutable): T {\r\n const max = new (left.constructor as Vector4Constructor)();\r\n max.copyFrom(left);\r\n max.maximizeInPlace(right);\r\n return max;\r\n }\r\n /**\r\n * Returns the distance (float) between the vectors \"value1\" and \"value2\".\r\n * @param value1 value to calulate the distance between\r\n * @param value2 value to calulate the distance between\r\n * @returns the distance between the two vectors\r\n */\r\n public static Distance(value1: DeepImmutable, value2: DeepImmutable): number {\r\n return Math.sqrt(Vector4.DistanceSquared(value1, value2));\r\n }\r\n /**\r\n * Returns the squared distance (float) between the vectors \"value1\" and \"value2\".\r\n * @param value1 value to calulate the distance between\r\n * @param value2 value to calulate the distance between\r\n * @returns the distance between the two vectors squared\r\n */\r\n public static DistanceSquared(value1: DeepImmutable, value2: DeepImmutable): number {\r\n const x = value1.x - value2.x;\r\n const y = value1.y - value2.y;\r\n const z = value1.z - value2.z;\r\n const w = value1.w - value2.w;\r\n\r\n return x * x + y * y + z * z + w * w;\r\n }\r\n /**\r\n * Returns a new Vector4 located at the center between the vectors \"value1\" and \"value2\".\r\n * @param value1 value to calulate the center between\r\n * @param value2 value to calulate the center between\r\n * @returns the center between the two vectors\r\n */\r\n public static Center(value1: DeepImmutable, value2: DeepImmutable): Vector4 {\r\n return Vector4.CenterToRef(value1, value2, Vector4.Zero());\r\n }\r\n\r\n /**\r\n * Gets the center of the vectors \"value1\" and \"value2\" and stores the result in the vector \"ref\"\r\n * @param value1 defines first vector\r\n * @param value2 defines second vector\r\n * @param ref defines third vector\r\n * @returns ref\r\n */\r\n public static CenterToRef(value1: DeepImmutable, value2: DeepImmutable, ref: T): T {\r\n return ref.copyFromFloats((value1.x + value2.x) / 2, (value1.y + value2.y) / 2, (value1.z + value2.z) / 2, (value1.w + value2.w) / 2);\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 set with the result of the transformation by the given matrix of the given vector.\r\n * This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\r\n * The difference with Vector3.TransformCoordinates is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead\r\n * @param vector defines the Vector3 to transform\r\n * @param transformation defines the transformation matrix\r\n * @returns the transformed Vector4\r\n */\r\n public static TransformCoordinates(vector: DeepImmutable, transformation: DeepImmutable): Vector4 {\r\n const result = Vector4.Zero();\r\n Vector4.TransformCoordinatesToRef(vector, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given vector\r\n * This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)\r\n * The difference with Vector3.TransformCoordinatesToRef is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead\r\n * @param vector defines the Vector3 to transform\r\n * @param transformation defines the transformation matrix\r\n * @param result defines the Vector4 where to store the result\r\n * @returns result input\r\n */\r\n public static TransformCoordinatesToRef(vector: DeepImmutable, transformation: DeepImmutable, result: T): T {\r\n Vector4.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)\r\n * This method computes tranformed coordinates only, not transformed direction vectors\r\n * The difference with Vector3.TransformCoordinatesFromFloatsToRef is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead\r\n * @param x define the x coordinate of the source vector\r\n * @param y define the y coordinate of the source vector\r\n * @param z define the z coordinate of the source vector\r\n * @param transformation defines the transformation matrix\r\n * @param result defines the Vector4 where to store the result\r\n * @returns result input\r\n */\r\n public static TransformCoordinatesFromFloatsToRef(x: number, y: number, z: number, transformation: DeepImmutable, result: T): T {\r\n const m = transformation.m;\r\n const rx = x * m[0] + y * m[4] + z * m[8] + m[12];\r\n const ry = x * m[1] + y * m[5] + z * m[9] + m[13];\r\n const rz = x * m[2] + y * m[6] + z * m[10] + m[14];\r\n const rw = x * m[3] + y * m[7] + z * m[11] + m[15];\r\n\r\n result.x = rx;\r\n result.y = ry;\r\n result.z = rz;\r\n result.w = rw;\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Vector4 set with the result of the normal transformation by the given matrix of the given vector.\r\n * This methods computes transformed normalized direction vectors only.\r\n * @param vector the vector to transform\r\n * @param transformation the transformation matrix to apply\r\n * @returns the new vector\r\n */\r\n public static TransformNormal(vector: DeepImmutable, transformation: DeepImmutable): T {\r\n const result = new (vector.constructor as Vector4Constructor)();\r\n Vector4.TransformNormalToRef(vector, transformation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given vector.\r\n * This methods computes transformed normalized direction vectors only.\r\n * @param vector the vector to transform\r\n * @param transformation the transformation matrix to apply\r\n * @param result the vector to store the result in\r\n * @returns result input\r\n */\r\n public static TransformNormalToRef(vector: DeepImmutable, transformation: DeepImmutable, result: T): T {\r\n const m = transformation.m;\r\n const x = vector.x * m[0] + vector.y * m[4] + vector.z * m[8];\r\n const y = vector.x * m[1] + vector.y * m[5] + vector.z * m[9];\r\n const z = vector.x * m[2] + vector.y * m[6] + vector.z * m[10];\r\n result.x = x;\r\n result.y = y;\r\n result.z = z;\r\n result.w = vector.w;\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector \"result\" with the result of the normal transformation by the given matrix of the given floats (x, y, z, w).\r\n * This methods computes transformed normalized direction vectors only.\r\n * @param x value to transform\r\n * @param y value to transform\r\n * @param z value to transform\r\n * @param w value to transform\r\n * @param transformation the transformation matrix to apply\r\n * @param result the vector to store the results in\r\n * @returns result input\r\n */\r\n public static TransformNormalFromFloatsToRef(x: number, y: number, z: number, w: number, transformation: DeepImmutable, result: T): T {\r\n const m = transformation.m;\r\n result.x = x * m[0] + y * m[4] + z * m[8];\r\n result.y = x * m[1] + y * m[5] + z * m[9];\r\n result.z = x * m[2] + y * m[6] + z * m[10];\r\n result.w = w;\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new Vector4 from a Vector3\r\n * @param source defines the source data\r\n * @param w defines the 4th component (default is 0)\r\n * @returns a new Vector4\r\n */\r\n public static FromVector3(source: Vector3, w: number = 0) {\r\n return new Vector4(source._x, source._y, source._z, w);\r\n }\r\n}\r\n\r\n/**\r\n * Class used to store quaternion data\r\n * Example Playground - Overview - https://playground.babylonjs.com/#L49EJ7#100\r\n * @see https://en.wikipedia.org/wiki/Quaternion\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms\r\n */\r\nexport class Quaternion {\r\n /** @internal */\r\n public _x: number;\r\n\r\n /** @internal */\r\n public _y: number;\r\n\r\n /** @internal */\r\n public _z: number;\r\n\r\n /** @internal */\r\n public _w: number;\r\n\r\n /** @internal */\r\n public _isDirty = true;\r\n\r\n /** Gets or sets the x coordinate */\r\n public get x() {\r\n return this._x;\r\n }\r\n\r\n public set x(value: number) {\r\n this._x = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /** Gets or sets the y coordinate */\r\n public get y() {\r\n return this._y;\r\n }\r\n\r\n public set y(value: number) {\r\n this._y = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /** Gets or sets the z coordinate */\r\n public get z() {\r\n return this._z;\r\n }\r\n\r\n public set z(value: number) {\r\n this._z = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /** Gets or sets the w coordinate */\r\n public get w() {\r\n return this._w;\r\n }\r\n\r\n public set w(value: number) {\r\n this._w = value;\r\n this._isDirty = true;\r\n }\r\n /**\r\n * Creates a new Quaternion from the given floats\r\n * @param x defines the first component (0 by default)\r\n * @param y defines the second component (0 by default)\r\n * @param z defines the third component (0 by default)\r\n * @param w defines the fourth component (1.0 by default)\r\n */\r\n constructor(x: number = 0.0, y: number = 0.0, z: number = 0.0, w: number = 1.0) {\r\n this._x = x;\r\n this._y = y;\r\n this._z = z;\r\n this._w = w;\r\n }\r\n\r\n /**\r\n * Gets a string representation for the current quaternion\r\n * @returns a string with the Quaternion coordinates\r\n */\r\n public toString(): string {\r\n return `{X: ${this._x} Y: ${this._y} Z: ${this._z} W: ${this._w}}`;\r\n }\r\n\r\n /**\r\n * Gets the class name of the quaternion\r\n * @returns the string \"Quaternion\"\r\n */\r\n public getClassName(): string {\r\n return \"Quaternion\";\r\n }\r\n\r\n /**\r\n * Gets a hash code for this quaternion\r\n * @returns the quaternion hash code\r\n */\r\n public getHashCode(): number {\r\n const x = _ExtractAsInt(this._x);\r\n const y = _ExtractAsInt(this._y);\r\n const z = _ExtractAsInt(this._z);\r\n const w = _ExtractAsInt(this._w);\r\n\r\n let hash = x;\r\n hash = (hash * 397) ^ y;\r\n hash = (hash * 397) ^ z;\r\n hash = (hash * 397) ^ w;\r\n return hash;\r\n }\r\n\r\n /**\r\n * Copy the quaternion to an array\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#13\r\n * @returns a new array populated with 4 elements from the quaternion coordinates\r\n */\r\n public asArray(): number[] {\r\n return [this._x, this._y, this._z, this._w];\r\n }\r\n\r\n /**\r\n * Stores from the starting index in the given array the Quaternion successive values\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#59\r\n * @param array defines the array where to store the x,y,z,w components\r\n * @param index defines an optional index in the target array to define where to start storing values\r\n * @returns the current Quaternion object\r\n */\r\n public toArray(array: FloatArray, index: number = 0): Quaternion {\r\n array[index] = this._x;\r\n array[index + 1] = this._y;\r\n array[index + 2] = this._z;\r\n array[index + 3] = this._w;\r\n return this;\r\n }\r\n\r\n /**\r\n * Check if two quaternions are equals\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#38\r\n * @param otherQuaternion defines the second operand\r\n * @returns true if the current quaternion and the given one coordinates are strictly equals\r\n */\r\n public equals(otherQuaternion: DeepImmutable): boolean {\r\n return otherQuaternion && this._x === otherQuaternion._x && this._y === otherQuaternion._y && this._z === otherQuaternion._z && this._w === otherQuaternion._w;\r\n }\r\n\r\n /**\r\n * Gets a boolean if two quaternions are equals (using an epsilon value)\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#37\r\n * @param otherQuaternion defines the other quaternion\r\n * @param epsilon defines the minimal distance to consider equality\r\n * @returns true if the given quaternion coordinates are close to the current ones by a distance of epsilon.\r\n */\r\n public equalsWithEpsilon(otherQuaternion: DeepImmutable, epsilon: number = Epsilon): boolean {\r\n return (\r\n otherQuaternion &&\r\n Scalar.WithinEpsilon(this._x, otherQuaternion._x, epsilon) &&\r\n Scalar.WithinEpsilon(this._y, otherQuaternion._y, epsilon) &&\r\n Scalar.WithinEpsilon(this._z, otherQuaternion._z, epsilon) &&\r\n Scalar.WithinEpsilon(this._w, otherQuaternion._w, epsilon)\r\n );\r\n }\r\n\r\n /**\r\n * Clone the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#12\r\n * @returns a new quaternion copied from the current one\r\n */\r\n public clone(): this {\r\n return new (this.constructor as QuaternionConstructor)(this._x, this._y, this._z, this._w);\r\n }\r\n\r\n /**\r\n * Copy a quaternion to the current one\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#86\r\n * @param other defines the other quaternion\r\n * @returns the updated current quaternion\r\n */\r\n public copyFrom(other: DeepImmutable): this {\r\n this._x = other._x;\r\n this._y = other._y;\r\n this._z = other._z;\r\n this._w = other._w;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the current quaternion with the given float coordinates\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#87\r\n * @param x defines the x coordinate\r\n * @param y defines the y coordinate\r\n * @param z defines the z coordinate\r\n * @param w defines the w coordinate\r\n * @returns the updated current quaternion\r\n */\r\n public copyFromFloats(x: number, y: number, z: number, w: number): this {\r\n this._x = x;\r\n this._y = y;\r\n this._z = z;\r\n this._w = w;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the current quaternion from the given float coordinates\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#56\r\n * @param x defines the x coordinate\r\n * @param y defines the y coordinate\r\n * @param z defines the z coordinate\r\n * @param w defines the w coordinate\r\n * @returns the updated current quaternion\r\n */\r\n public set(x: number, y: number, z: number, w: number): this {\r\n return this.copyFromFloats(x, y, z, w);\r\n }\r\n\r\n /**\r\n * Adds two quaternions\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#10\r\n * @param other defines the second operand\r\n * @returns a new quaternion as the addition result of the given one and the current quaternion\r\n */\r\n public add(other: DeepImmutable): this {\r\n return new (this.constructor as QuaternionConstructor)(this._x + other._x, this._y + other._y, this._z + other._z, this._w + other._w);\r\n }\r\n\r\n /**\r\n * Add a quaternion to the current one\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#11\r\n * @param other defines the quaternion to add\r\n * @returns the current quaternion\r\n */\r\n public addInPlace(other: DeepImmutable): this {\r\n this._x += other._x;\r\n this._y += other._y;\r\n this._z += other._z;\r\n this._w += other._w;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Subtract two quaternions\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#57\r\n * @param other defines the second operand\r\n * @returns a new quaternion as the subtraction result of the given one from the current one\r\n */\r\n public subtract(other: Quaternion): this {\r\n return new (this.constructor as QuaternionConstructor)(this._x - other._x, this._y - other._y, this._z - other._z, this._w - other._w);\r\n }\r\n\r\n /**\r\n * Subtract a quaternion to the current one\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#58\r\n * @param other defines the quaternion to subtract\r\n * @returns the current quaternion\r\n */\r\n public subtractInPlace(other: DeepImmutable): this {\r\n this._x -= other._x;\r\n this._y -= other._y;\r\n this._z -= other._z;\r\n this._w -= other._w;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiplies the current quaternion by a scale factor\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#88\r\n * @param value defines the scale factor\r\n * @returns a new quaternion set by multiplying the current quaternion coordinates by the float \"scale\"\r\n */\r\n public scale(value: number): this {\r\n return new (this.constructor as QuaternionConstructor)(this._x * value, this._y * value, this._z * value, this._w * value);\r\n }\r\n\r\n /**\r\n * Scale the current quaternion values by a factor and stores the result to a given quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#89\r\n * @param scale defines the scale factor\r\n * @param result defines the Quaternion object where to store the result\r\n * @returns result input\r\n */\r\n public scaleToRef(scale: number, result: T): T {\r\n result._x = this._x * scale;\r\n result._y = this._y * scale;\r\n result._z = this._z * scale;\r\n result._w = this._w * scale;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Multiplies in place the current quaternion by a scale factor\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#90\r\n * @param value defines the scale factor\r\n * @returns the current modified quaternion\r\n */\r\n public scaleInPlace(value: number): this {\r\n this._x *= value;\r\n this._y *= value;\r\n this._z *= value;\r\n this._w *= value;\r\n this._isDirty = true;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Scale the current quaternion values by a factor and add the result to a given quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#91\r\n * @param scale defines the scale factor\r\n * @param result defines the Quaternion object where to store the result\r\n * @returns result input\r\n */\r\n public scaleAndAddToRef(scale: number, result: T): T {\r\n result._x += this._x * scale;\r\n result._y += this._y * scale;\r\n result._z += this._z * scale;\r\n result._w += this._w * scale;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Multiplies two quaternions\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#43\r\n * @param q1 defines the second operand\r\n * @returns a new quaternion set as the multiplication result of the current one with the given one \"q1\"\r\n */\r\n public multiply(q1: DeepImmutable): this {\r\n const result = new (this.constructor as QuaternionConstructor)(0, 0, 0, 1.0);\r\n this.multiplyToRef(q1, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given \"result\" as the the multiplication result of the current one with the given one \"q1\"\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#45\r\n * @param q1 defines the second operand\r\n * @param result defines the target quaternion\r\n * @returns the current quaternion\r\n */\r\n public multiplyToRef(q1: DeepImmutable, result: T): T {\r\n const x = this._x * q1._w + this._y * q1._z - this._z * q1._y + this._w * q1._x;\r\n const y = -this._x * q1._z + this._y * q1._w + this._z * q1._x + this._w * q1._y;\r\n const z = this._x * q1._y - this._y * q1._x + this._z * q1._w + this._w * q1._z;\r\n const w = -this._x * q1._x - this._y * q1._y - this._z * q1._z + this._w * q1._w;\r\n result.copyFromFloats(x, y, z, w);\r\n return result;\r\n }\r\n\r\n /**\r\n * Updates the current quaternion with the multiplication of itself with the given one \"q1\"\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#46\r\n * @param q1 defines the second operand\r\n * @returns the currentupdated quaternion\r\n */\r\n public multiplyInPlace(q1: DeepImmutable): this {\r\n this.multiplyToRef(q1, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Conjugates the current quaternion and stores the result in the given quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#81\r\n * @param ref defines the target quaternion\r\n * @returns result input\r\n */\r\n public conjugateToRef(ref: T): T {\r\n ref.copyFromFloats(-this._x, -this._y, -this._z, this._w);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Conjugates in place the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#82\r\n * @returns the current updated quaternion\r\n */\r\n public conjugateInPlace(): this {\r\n this._x *= -1;\r\n this._y *= -1;\r\n this._z *= -1;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Conjugates (1-q) the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#83\r\n * @returns a new quaternion\r\n */\r\n public conjugate(): this {\r\n return new (this.constructor as QuaternionConstructor)(-this._x, -this._y, -this._z, this._w);\r\n }\r\n\r\n /**\r\n * Returns the inverse of the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#84\r\n * @returns a new quaternion\r\n */\r\n public invert(): this {\r\n const conjugate = this.conjugate();\r\n const lengthSquared = this.lengthSquared();\r\n if (lengthSquared == 0 || lengthSquared == 1) {\r\n return conjugate;\r\n }\r\n conjugate.scaleInPlace(1 / lengthSquared);\r\n return conjugate;\r\n }\r\n\r\n /**\r\n * Invert in place the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#85\r\n * @returns this quaternion\r\n */\r\n public invertInPlace(): this {\r\n this.conjugateInPlace();\r\n const lengthSquared = this.lengthSquared();\r\n if (lengthSquared == 0 || lengthSquared == 1) {\r\n return this;\r\n }\r\n this.scaleInPlace(1 / lengthSquared);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets squared length of current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#29\r\n * @returns the quaternion length (float)\r\n */\r\n public lengthSquared(): number {\r\n return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;\r\n }\r\n\r\n /**\r\n * Gets length of current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#28\r\n * @returns the quaternion length (float)\r\n */\r\n public length(): number {\r\n return Math.sqrt(this.lengthSquared());\r\n }\r\n\r\n /**\r\n * Normalize in place the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#54\r\n * @returns the current updated quaternion\r\n */\r\n public normalize(): this {\r\n const len = this.length();\r\n if (len === 0) {\r\n return this;\r\n }\r\n\r\n const inv = 1.0 / len;\r\n this.scaleInPlace(inv);\r\n return this;\r\n }\r\n\r\n /**\r\n * Normalize a copy of the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#55\r\n * @returns the normalized quaternion\r\n */\r\n public normalizeToNew(): this {\r\n const len = this.length();\r\n if (len === 0) {\r\n return this.clone();\r\n }\r\n\r\n const inv = 1.0 / len;\r\n return this.scale(inv);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the Euler angles translated from the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#32\r\n * @returns a new Vector3 containing the Euler angles\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/rotation_conventions\r\n */\r\n public toEulerAngles(): Vector3 {\r\n const result = Vector3.Zero();\r\n this.toEulerAnglesToRef(result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given vector3 \"result\" with the Euler angles translated from the current quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#31\r\n * @param result defines the vector which will be filled with the Euler angles\r\n * @returns result input\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/rotation_conventions\r\n */\r\n public toEulerAnglesToRef(result: T): T {\r\n const qz = this._z;\r\n const qx = this._x;\r\n const qy = this._y;\r\n const qw = this._w;\r\n\r\n const zAxisY = qy * qz - qx * qw;\r\n const limit = 0.4999999;\r\n\r\n if (zAxisY < -limit) {\r\n result._y = 2 * Math.atan2(qy, qw);\r\n result._x = Math.PI / 2;\r\n result._z = 0;\r\n result._isDirty = true;\r\n } else if (zAxisY > limit) {\r\n result._y = 2 * Math.atan2(qy, qw);\r\n result._x = -Math.PI / 2;\r\n result._z = 0;\r\n result._isDirty = true;\r\n } else {\r\n const sqw = qw * qw;\r\n const sqz = qz * qz;\r\n const sqx = qx * qx;\r\n const sqy = qy * qy;\r\n result._z = Math.atan2(2.0 * (qx * qy + qz * qw), -sqz - sqx + sqy + sqw);\r\n result._x = Math.asin(-2.0 * zAxisY);\r\n result._y = Math.atan2(2.0 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);\r\n result._isDirty = true;\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Updates the given rotation matrix with the current quaternion values\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#67\r\n * @param result defines the target matrix\r\n * @returns the current unchanged quaternion\r\n */\r\n public toRotationMatrix(result: T): T {\r\n Matrix.FromQuaternionToRef(this, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Updates the current quaternion from the given rotation matrix values\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#41\r\n * @param matrix defines the source matrix\r\n * @returns the current updated quaternion\r\n */\r\n public fromRotationMatrix(matrix: DeepImmutable): this {\r\n Quaternion.FromRotationMatrixToRef(matrix, this);\r\n return this;\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Creates a new quaternion from a rotation matrix\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#101\r\n * @param matrix defines the source matrix\r\n * @returns a new quaternion created from the given rotation matrix values\r\n */\r\n public static FromRotationMatrix(matrix: DeepImmutable): Quaternion {\r\n const result = new Quaternion();\r\n Quaternion.FromRotationMatrixToRef(matrix, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Updates the given quaternion with the given rotation matrix values\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#102\r\n * @param matrix defines the source matrix\r\n * @param result defines the target quaternion\r\n * @returns result input\r\n */\r\n public static FromRotationMatrixToRef(matrix: DeepImmutable, result: T): T {\r\n const data = matrix.m;\r\n const m11 = data[0],\r\n m12 = data[4],\r\n m13 = data[8];\r\n const m21 = data[1],\r\n m22 = data[5],\r\n m23 = data[9];\r\n const m31 = data[2],\r\n m32 = data[6],\r\n m33 = data[10];\r\n const trace = m11 + m22 + m33;\r\n let s;\r\n\r\n if (trace > 0) {\r\n s = 0.5 / Math.sqrt(trace + 1.0);\r\n\r\n result._w = 0.25 / s;\r\n result._x = (m32 - m23) * s;\r\n result._y = (m13 - m31) * s;\r\n result._z = (m21 - m12) * s;\r\n result._isDirty = true;\r\n } else if (m11 > m22 && m11 > m33) {\r\n s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);\r\n\r\n result._w = (m32 - m23) / s;\r\n result._x = 0.25 * s;\r\n result._y = (m12 + m21) / s;\r\n result._z = (m13 + m31) / s;\r\n result._isDirty = true;\r\n } else if (m22 > m33) {\r\n s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);\r\n\r\n result._w = (m13 - m31) / s;\r\n result._x = (m12 + m21) / s;\r\n result._y = 0.25 * s;\r\n result._z = (m23 + m32) / s;\r\n result._isDirty = true;\r\n } else {\r\n s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);\r\n\r\n result._w = (m21 - m12) / s;\r\n result._x = (m13 + m31) / s;\r\n result._y = (m23 + m32) / s;\r\n result._z = 0.25 * s;\r\n result._isDirty = true;\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the dot product (float) between the quaternions \"left\" and \"right\"\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#61\r\n * @param left defines the left operand\r\n * @param right defines the right operand\r\n * @returns the dot product\r\n */\r\n public static Dot(left: DeepImmutable, right: DeepImmutable): number {\r\n return left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;\r\n }\r\n\r\n /**\r\n * Checks if the orientations of two rotation quaternions are close to each other\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#60\r\n * @param quat0 defines the first quaternion to check\r\n * @param quat1 defines the second quaternion to check\r\n * @param epsilon defines closeness, 0 same orientation, 1 PI apart, default 0.1\r\n * @returns true if the two quaternions are close to each other within epsilon\r\n */\r\n public static AreClose(quat0: DeepImmutable, quat1: DeepImmutable, epsilon: number = 0.1): boolean {\r\n const dot = Quaternion.Dot(quat0, quat1);\r\n\r\n return 1 - dot * dot <= epsilon;\r\n }\r\n\r\n /**\r\n * Smooth interpolation between two quaternions using Slerp\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#93\r\n * @param source source quaternion\r\n * @param goal goal quaternion\r\n * @param deltaTime current interpolation frame\r\n * @param lerpTime total interpolation time\r\n * @param result the smoothed quaternion\r\n */\r\n public static SmoothToRef(source: Quaternion, goal: Quaternion, deltaTime: number, lerpTime: number, result: T): T {\r\n let slerp = lerpTime === 0 ? 1 : deltaTime / lerpTime;\r\n slerp = Scalar.Clamp(slerp, 0, 1);\r\n\r\n Quaternion.SlerpToRef(source, goal, slerp, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates an empty quaternion\r\n * @returns a new quaternion set to (0.0, 0.0, 0.0)\r\n */\r\n public static Zero(): Quaternion {\r\n return new Quaternion(0.0, 0.0, 0.0, 0.0);\r\n }\r\n\r\n /**\r\n * Inverse a given quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#103\r\n * @param q defines the source quaternion\r\n * @returns a new quaternion as the inverted current quaternion\r\n */\r\n public static Inverse(q: DeepImmutable): T {\r\n return new (q.constructor as QuaternionConstructor)(-q._x, -q._y, -q._z, q._w);\r\n }\r\n\r\n /**\r\n * Inverse a given quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#104\r\n * @param q defines the source quaternion\r\n * @param result the quaternion the result will be stored in\r\n * @returns the result quaternion\r\n */\r\n public static InverseToRef(q: Quaternion, result: T): T {\r\n result.set(-q._x, -q._y, -q._z, q._w);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates an identity quaternion\r\n * @returns the identity quaternion\r\n */\r\n public static Identity(): Quaternion {\r\n return new Quaternion(0.0, 0.0, 0.0, 1.0);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the given quaternion is identity\r\n * @param quaternion defines the quaternion to check\r\n * @returns true if the quaternion is identity\r\n */\r\n public static IsIdentity(quaternion: DeepImmutable): boolean {\r\n return quaternion && quaternion._x === 0 && quaternion._y === 0 && quaternion._z === 0 && quaternion._w === 1;\r\n }\r\n\r\n /**\r\n * Creates a quaternion from a rotation around an axis\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#72\r\n * @param axis defines the axis to use\r\n * @param angle defines the angle to use\r\n * @returns a new quaternion created from the given axis (Vector3) and angle in radians (float)\r\n */\r\n public static RotationAxis(axis: DeepImmutable, angle: number): Quaternion {\r\n return Quaternion.RotationAxisToRef(axis, angle, new Quaternion());\r\n }\r\n\r\n /**\r\n * Creates a rotation around an axis and stores it into the given quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#73\r\n * @param axis defines the axis to use\r\n * @param angle defines the angle to use\r\n * @param result defines the target quaternion\r\n * @returns the target quaternion\r\n */\r\n public static RotationAxisToRef(axis: DeepImmutable, angle: number, result: T): T {\r\n const sin = Math.sin(angle / 2);\r\n axis.normalize();\r\n result._w = Math.cos(angle / 2);\r\n result._x = axis._x * sin;\r\n result._y = axis._y * sin;\r\n result._z = axis._z * sin;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new quaternion from data stored into an array\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#63\r\n * @param array defines the data source\r\n * @param offset defines the offset in the source array where the data starts\r\n * @returns a new quaternion\r\n */\r\n public static FromArray(array: DeepImmutable>, offset?: number): Quaternion {\r\n if (!offset) {\r\n offset = 0;\r\n }\r\n return new Quaternion(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\r\n }\r\n\r\n /**\r\n * Updates the given quaternion \"result\" from the starting index of the given array.\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#64\r\n * @param array the array to pull values from\r\n * @param offset the offset into the array to start at\r\n * @param result the quaternion to store the result in\r\n * @returns result input\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number, result: T): T {\r\n result._x = array[offset];\r\n result._y = array[offset + 1];\r\n result._z = array[offset + 2];\r\n result._w = array[offset + 3];\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Create a quaternion from Euler rotation angles\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#33\r\n * @param x Pitch\r\n * @param y Yaw\r\n * @param z Roll\r\n * @returns the new Quaternion\r\n */\r\n public static FromEulerAngles(x: number, y: number, z: number): Quaternion {\r\n const q = new Quaternion();\r\n Quaternion.RotationYawPitchRollToRef(y, x, z, q);\r\n return q;\r\n }\r\n\r\n /**\r\n * Updates a quaternion from Euler rotation angles\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#34\r\n * @param x Pitch\r\n * @param y Yaw\r\n * @param z Roll\r\n * @param result the quaternion to store the result\r\n * @returns the updated quaternion\r\n */\r\n public static FromEulerAnglesToRef(x: number, y: number, z: number, result: T): T {\r\n Quaternion.RotationYawPitchRollToRef(y, x, z, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Create a quaternion from Euler rotation vector\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#35\r\n * @param vec the Euler vector (x Pitch, y Yaw, z Roll)\r\n * @returns the new Quaternion\r\n */\r\n public static FromEulerVector(vec: DeepImmutable): Quaternion {\r\n const q = new Quaternion();\r\n Quaternion.RotationYawPitchRollToRef(vec._y, vec._x, vec._z, q);\r\n return q;\r\n }\r\n\r\n /**\r\n * Updates a quaternion from Euler rotation vector\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#36\r\n * @param vec the Euler vector (x Pitch, y Yaw, z Roll)\r\n * @param result the quaternion to store the result\r\n * @returns the updated quaternion\r\n */\r\n public static FromEulerVectorToRef(vec: DeepImmutable, result: T): T {\r\n Quaternion.RotationYawPitchRollToRef(vec._y, vec._x, vec._z, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Updates a quaternion so that it rotates vector vecFrom to vector vecTo\r\n * Example Playground - https://playground.babylonjs.com/#L49EJ7#70\r\n * @param vecFrom defines the direction vector from which to rotate\r\n * @param vecTo defines the direction vector to which to rotate\r\n * @param result the quaternion to store the result\r\n * @param epsilon defines the minimal dot value to define vecs as opposite. Default: `BABYLON.Epsilon`\r\n * @returns the updated quaternion\r\n */\r\n public static FromUnitVectorsToRef(vecFrom: DeepImmutable, vecTo: DeepImmutable, result: T, epsilon = Epsilon): T {\r\n const r = Vector3.Dot(vecFrom, vecTo) + 1;\r\n\r\n if (r < epsilon) {\r\n if (Math.abs(vecFrom.x) > Math.abs(vecFrom.z)) {\r\n result.set(-vecFrom.y, vecFrom.x, 0, 0);\r\n } else {\r\n result.set(0, -vecFrom.z, vecFrom.y, 0);\r\n }\r\n } else {\r\n Vector3.CrossToRef(vecFrom, vecTo, TmpVectors.Vector3[0]);\r\n result.set(TmpVectors.Vector3[0].x, TmpVectors.Vector3[0].y, TmpVectors.Vector3[0].z, r);\r\n }\r\n\r\n return result.normalize();\r\n }\r\n\r\n /**\r\n * Creates a new quaternion from the given Euler float angles (y, x, z)\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#77\r\n * @param yaw defines the rotation around Y axis\r\n * @param pitch defines the rotation around X axis\r\n * @param roll defines the rotation around Z axis\r\n * @returns the new quaternion\r\n */\r\n public static RotationYawPitchRoll(yaw: number, pitch: number, roll: number): Quaternion {\r\n const q = new Quaternion();\r\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, q);\r\n return q;\r\n }\r\n\r\n /**\r\n * Creates a new rotation from the given Euler float angles (y, x, z) and stores it in the target quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#78\r\n * @param yaw defines the rotation around Y axis\r\n * @param pitch defines the rotation around X axis\r\n * @param roll defines the rotation around Z axis\r\n * @param result defines the target quaternion\r\n * @returns result input\r\n */\r\n public static RotationYawPitchRollToRef(yaw: number, pitch: number, roll: number, result: T): T {\r\n // Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)\r\n const halfRoll = roll * 0.5;\r\n const halfPitch = pitch * 0.5;\r\n const halfYaw = yaw * 0.5;\r\n\r\n const sinRoll = Math.sin(halfRoll);\r\n const cosRoll = Math.cos(halfRoll);\r\n const sinPitch = Math.sin(halfPitch);\r\n const cosPitch = Math.cos(halfPitch);\r\n const sinYaw = Math.sin(halfYaw);\r\n const cosYaw = Math.cos(halfYaw);\r\n\r\n result._x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;\r\n result._y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;\r\n result._z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;\r\n result._w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#68\r\n * @param alpha defines the rotation around first axis\r\n * @param beta defines the rotation around second axis\r\n * @param gamma defines the rotation around third axis\r\n * @returns the new quaternion\r\n */\r\n public static RotationAlphaBetaGamma(alpha: number, beta: number, gamma: number): Quaternion {\r\n const result = new Quaternion();\r\n Quaternion.RotationAlphaBetaGammaToRef(alpha, beta, gamma, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation and stores it in the target quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#69\r\n * @param alpha defines the rotation around first axis\r\n * @param beta defines the rotation around second axis\r\n * @param gamma defines the rotation around third axis\r\n * @param result defines the target quaternion\r\n * @returns result input\r\n */\r\n public static RotationAlphaBetaGammaToRef(alpha: number, beta: number, gamma: number, result: T): T {\r\n // Produces a quaternion from Euler angles in the z-x-z orientation\r\n const halfGammaPlusAlpha = (gamma + alpha) * 0.5;\r\n const halfGammaMinusAlpha = (gamma - alpha) * 0.5;\r\n const halfBeta = beta * 0.5;\r\n\r\n result._x = Math.cos(halfGammaMinusAlpha) * Math.sin(halfBeta);\r\n result._y = Math.sin(halfGammaMinusAlpha) * Math.sin(halfBeta);\r\n result._z = Math.sin(halfGammaPlusAlpha) * Math.cos(halfBeta);\r\n result._w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new quaternion containing the rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation)\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#75\r\n * @param axis1 defines the first axis\r\n * @param axis2 defines the second axis\r\n * @param axis3 defines the third axis\r\n * @returns the new quaternion\r\n */\r\n public static RotationQuaternionFromAxis(axis1: DeepImmutable, axis2: DeepImmutable, axis3: DeepImmutable): Quaternion {\r\n const quat = new Quaternion(0.0, 0.0, 0.0, 0.0);\r\n Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);\r\n return quat;\r\n }\r\n\r\n /**\r\n * Creates a rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation) and stores it in the target quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#76\r\n * @param axis1 defines the first axis\r\n * @param axis2 defines the second axis\r\n * @param axis3 defines the third axis\r\n * @param ref defines the target quaternion\r\n * @returns result input\r\n */\r\n public static RotationQuaternionFromAxisToRef(axis1: DeepImmutable, axis2: DeepImmutable, axis3: DeepImmutable, ref: T): T {\r\n const rotMat = MathTmp.Matrix[0];\r\n Matrix.FromXYZAxesToRef(axis1.normalize(), axis2.normalize(), axis3.normalize(), rotMat);\r\n Quaternion.FromRotationMatrixToRef(rotMat, ref);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like \"up\".\r\n * This function works in left handed mode\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#96\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @returns A new quaternion oriented toward the specified forward and up.\r\n */\r\n public static FromLookDirectionLH(forward: DeepImmutable, up: DeepImmutable): Quaternion {\r\n const quat = new Quaternion();\r\n Quaternion.FromLookDirectionLHToRef(forward, up, quat);\r\n return quat;\r\n }\r\n\r\n /**\r\n * Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like \"up\", and stores it in the target quaternion.\r\n * This function works in left handed mode\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#97\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @param ref defines the target quaternion.\r\n * @returns result input\r\n */\r\n public static FromLookDirectionLHToRef(forward: DeepImmutable, up: DeepImmutable, ref: T): T {\r\n const rotMat = MathTmp.Matrix[0];\r\n Matrix.LookDirectionLHToRef(forward, up, rotMat);\r\n Quaternion.FromRotationMatrixToRef(rotMat, ref);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like \"up\".\r\n * This function works in right handed mode\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#98\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @returns A new quaternion oriented toward the specified forward and up.\r\n */\r\n public static FromLookDirectionRH(forward: DeepImmutable, up: DeepImmutable): Quaternion {\r\n const quat = new Quaternion();\r\n Quaternion.FromLookDirectionRHToRef(forward, up, quat);\r\n return quat;\r\n }\r\n\r\n /**\r\n * Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like \"up\", and stores it in the target quaternion.\r\n * This function works in right handed mode\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#105\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @param ref defines the target quaternion.\r\n * @returns result input\r\n */\r\n public static FromLookDirectionRHToRef(forward: DeepImmutable, up: DeepImmutable, ref: T): T {\r\n const rotMat = MathTmp.Matrix[0];\r\n Matrix.LookDirectionRHToRef(forward, up, rotMat);\r\n return Quaternion.FromRotationMatrixToRef(rotMat, ref);\r\n }\r\n\r\n /**\r\n * Interpolates between two quaternions\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#79\r\n * @param left defines first quaternion\r\n * @param right defines second quaternion\r\n * @param amount defines the gradient to use\r\n * @returns the new interpolated quaternion\r\n */\r\n public static Slerp(left: DeepImmutable, right: DeepImmutable, amount: number): Quaternion {\r\n const result = Quaternion.Identity();\r\n\r\n Quaternion.SlerpToRef(left, right, amount, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Interpolates between two quaternions and stores it into a target quaternion\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#92\r\n * @param left defines first quaternion\r\n * @param right defines second quaternion\r\n * @param amount defines the gradient to use\r\n * @param result defines the target quaternion\r\n * @returns result input\r\n */\r\n public static SlerpToRef(left: DeepImmutable, right: DeepImmutable, amount: number, result: T): T {\r\n let num2;\r\n let num3;\r\n let num4 = left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;\r\n let flag = false;\r\n\r\n if (num4 < 0) {\r\n flag = true;\r\n num4 = -num4;\r\n }\r\n\r\n if (num4 > 0.999999) {\r\n num3 = 1 - amount;\r\n num2 = flag ? -amount : amount;\r\n } else {\r\n const num5 = Math.acos(num4);\r\n const num6 = 1.0 / Math.sin(num5);\r\n num3 = Math.sin((1.0 - amount) * num5) * num6;\r\n num2 = flag ? -Math.sin(amount * num5) * num6 : Math.sin(amount * num5) * num6;\r\n }\r\n\r\n result._x = num3 * left._x + num2 * right._x;\r\n result._y = num3 * left._y + num2 * right._y;\r\n result._z = num3 * left._z + num2 * right._z;\r\n result._w = num3 * left._w + num2 * right._w;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n\r\n /**\r\n * Interpolate between two quaternions using Hermite interpolation\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#47\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-quaternion-spline\r\n * @param value1 defines first quaternion\r\n * @param tangent1 defines the incoming tangent\r\n * @param value2 defines second quaternion\r\n * @param tangent2 defines the outgoing tangent\r\n * @param amount defines the target quaternion\r\n * @returns the new interpolated quaternion\r\n */\r\n public static Hermite(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n amount: number\r\n ): T {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\r\n const part2 = -2.0 * cubed + 3.0 * squared;\r\n const part3 = cubed - 2.0 * squared + amount;\r\n const part4 = cubed - squared;\r\n\r\n const x = value1._x * part1 + value2._x * part2 + tangent1._x * part3 + tangent2._x * part4;\r\n const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;\r\n const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;\r\n const w = value1._w * part1 + value2._w * part2 + tangent1._w * part3 + tangent2._w * part4;\r\n return new (value1.constructor as QuaternionConstructor)(x, y, z, w);\r\n }\r\n\r\n /**\r\n * Returns a new Quaternion which is the 1st derivative of the Hermite spline defined by the quaternions \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#48\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @returns 1st derivative\r\n */\r\n public static Hermite1stDerivative(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number\r\n ): T {\r\n const result = new (value1.constructor as QuaternionConstructor)();\r\n\r\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Update a Quaternion with the 1st derivative of the Hermite spline defined by the quaternions \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * Example Playground https://playground.babylonjs.com/#L49EJ7#49\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @param result define where to store the derivative\r\n * @returns result input\r\n */\r\n public static Hermite1stDerivativeToRef(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number,\r\n result: T\r\n ): T {\r\n const t2 = time * time;\r\n\r\n result._x = (t2 - time) * 6 * value1._x + (3 * t2 - 4 * time + 1) * tangent1._x + (-t2 + time) * 6 * value2._x + (3 * t2 - 2 * time) * tangent2._x;\r\n result._y = (t2 - time) * 6 * value1._y + (3 * t2 - 4 * time + 1) * tangent1._y + (-t2 + time) * 6 * value2._y + (3 * t2 - 2 * time) * tangent2._y;\r\n result._z = (t2 - time) * 6 * value1._z + (3 * t2 - 4 * time + 1) * tangent1._z + (-t2 + time) * 6 * value2._z + (3 * t2 - 2 * time) * tangent2._z;\r\n result._w = (t2 - time) * 6 * value1._w + (3 * t2 - 4 * time + 1) * tangent1._w + (-t2 + time) * 6 * value2._w + (3 * t2 - 2 * time) * tangent2._w;\r\n result._isDirty = true;\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * Class used to store matrix data (4x4)\r\n * Note on matrix definitions in Babylon.js for setting values directly\r\n * rather than using one of the methods available.\r\n * Matrix size is given by rows x columns.\r\n * A Vector3 is a 1 X 3 matrix [x, y, z].\r\n *\r\n * In Babylon.js multiplying a 1 x 3 matrix by a 4 x 4 matrix\r\n * is done using BABYLON.Vector4.TransformCoordinates(Vector3, Matrix).\r\n * and extending the passed Vector3 to a Vector4, V = [x, y, z, 1].\r\n * Let M be a matrix with elements m(row, column), so that\r\n * m(2, 3) is the element in row 2 column 3 of M.\r\n *\r\n * Multiplication is of the form VM and has the resulting Vector4\r\n * VM = [xm(0, 0) + ym(1, 0) + zm(2, 0) + m(3, 0), xm(0, 1) + ym(1, 1) + zm(2, 1) + m(3, 1), xm(0, 2) + ym(1, 2) + zm(2, 2) + m(3, 2), xm(0, 3) + ym(1, 3) + zm(2, 3) + m(3, 3)].\r\n * On the web you will find many examples that use the opposite convention of MV,\r\n * in which case to make use of the examples you will need to transpose the matrix.\r\n *\r\n * Example Playground - Overview Linear Algebra - https://playground.babylonjs.com/#AV9X17\r\n * Example Playground - Overview Transformation - https://playground.babylonjs.com/#AV9X17#1\r\n * Example Playground - Overview Projection - https://playground.babylonjs.com/#AV9X17#2\r\n */\r\nexport class Matrix {\r\n /**\r\n * Gets the precision of matrix computations\r\n */\r\n public static get Use64Bits(): boolean {\r\n return PerformanceConfigurator.MatrixUse64Bits;\r\n }\r\n\r\n private static _UpdateFlagSeed = 0;\r\n private static _IdentityReadOnly = Matrix.Identity() as DeepImmutable;\r\n\r\n private _isIdentity = false;\r\n private _isIdentityDirty = true;\r\n private _isIdentity3x2 = true;\r\n private _isIdentity3x2Dirty = true;\r\n /**\r\n * Gets the update flag of the matrix which is an unique number for the matrix.\r\n * It will be incremented every time the matrix data change.\r\n * You can use it to speed the comparison between two versions of the same matrix.\r\n */\r\n public updateFlag: number = -1;\r\n\r\n private readonly _m: Float32Array | Array;\r\n\r\n /**\r\n * Gets the internal data of the matrix\r\n */\r\n public get m(): DeepImmutable> {\r\n return this._m;\r\n }\r\n\r\n /**\r\n * Update the updateFlag to indicate that the matrix has been updated\r\n */\r\n public markAsUpdated() {\r\n this.updateFlag = Matrix._UpdateFlagSeed++;\r\n this._isIdentity = false;\r\n this._isIdentity3x2 = false;\r\n this._isIdentityDirty = true;\r\n this._isIdentity3x2Dirty = true;\r\n }\r\n\r\n private _updateIdentityStatus(isIdentity: boolean, isIdentityDirty: boolean = false, isIdentity3x2: boolean = false, isIdentity3x2Dirty: boolean = true) {\r\n this._isIdentity = isIdentity;\r\n this._isIdentity3x2 = isIdentity || isIdentity3x2;\r\n this._isIdentityDirty = this._isIdentity ? false : isIdentityDirty;\r\n this._isIdentity3x2Dirty = this._isIdentity3x2 ? false : isIdentity3x2Dirty;\r\n }\r\n\r\n /**\r\n * Creates an empty matrix (filled with zeros)\r\n */\r\n public constructor() {\r\n if (PerformanceConfigurator.MatrixTrackPrecisionChange) {\r\n PerformanceConfigurator.MatrixTrackedMatrices!.push(this);\r\n }\r\n\r\n this._m = new PerformanceConfigurator.MatrixCurrentType(16);\r\n\r\n this.markAsUpdated();\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Check if the current matrix is identity\r\n * @returns true is the matrix is the identity matrix\r\n */\r\n public isIdentity(): boolean {\r\n if (this._isIdentityDirty) {\r\n this._isIdentityDirty = false;\r\n const m = this._m;\r\n this._isIdentity =\r\n m[0] === 1.0 &&\r\n m[1] === 0.0 &&\r\n m[2] === 0.0 &&\r\n m[3] === 0.0 &&\r\n m[4] === 0.0 &&\r\n m[5] === 1.0 &&\r\n m[6] === 0.0 &&\r\n m[7] === 0.0 &&\r\n m[8] === 0.0 &&\r\n m[9] === 0.0 &&\r\n m[10] === 1.0 &&\r\n m[11] === 0.0 &&\r\n m[12] === 0.0 &&\r\n m[13] === 0.0 &&\r\n m[14] === 0.0 &&\r\n m[15] === 1.0;\r\n }\r\n\r\n return this._isIdentity;\r\n }\r\n\r\n /**\r\n * Check if the current matrix is identity as a texture matrix (3x2 store in 4x4)\r\n * @returns true is the matrix is the identity matrix\r\n */\r\n public isIdentityAs3x2(): boolean {\r\n if (this._isIdentity3x2Dirty) {\r\n this._isIdentity3x2Dirty = false;\r\n if (this._m[0] !== 1.0 || this._m[5] !== 1.0 || this._m[15] !== 1.0) {\r\n this._isIdentity3x2 = false;\r\n } else if (\r\n this._m[1] !== 0.0 ||\r\n this._m[2] !== 0.0 ||\r\n this._m[3] !== 0.0 ||\r\n this._m[4] !== 0.0 ||\r\n this._m[6] !== 0.0 ||\r\n this._m[7] !== 0.0 ||\r\n this._m[8] !== 0.0 ||\r\n this._m[9] !== 0.0 ||\r\n this._m[10] !== 0.0 ||\r\n this._m[11] !== 0.0 ||\r\n this._m[12] !== 0.0 ||\r\n this._m[13] !== 0.0 ||\r\n this._m[14] !== 0.0\r\n ) {\r\n this._isIdentity3x2 = false;\r\n } else {\r\n this._isIdentity3x2 = true;\r\n }\r\n }\r\n\r\n return this._isIdentity3x2;\r\n }\r\n\r\n /**\r\n * Gets the determinant of the matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#34\r\n * @returns the matrix determinant\r\n */\r\n public determinant(): number {\r\n if (this._isIdentity === true) {\r\n return 1;\r\n }\r\n\r\n const m = this._m;\r\n const m00 = m[0],\r\n m01 = m[1],\r\n m02 = m[2],\r\n m03 = m[3];\r\n const m10 = m[4],\r\n m11 = m[5],\r\n m12 = m[6],\r\n m13 = m[7];\r\n const m20 = m[8],\r\n m21 = m[9],\r\n m22 = m[10],\r\n m23 = m[11];\r\n const m30 = m[12],\r\n m31 = m[13],\r\n m32 = m[14],\r\n m33 = m[15];\r\n // https://en.wikipedia.org/wiki/Laplace_expansion\r\n // to compute the deterrminant of a 4x4 Matrix we compute the cofactors of any row or column,\r\n // then we multiply each Cofactor by its corresponding matrix value and sum them all to get the determinant\r\n // Cofactor(i, j) = sign(i,j) * det(Minor(i, j))\r\n // where\r\n // - sign(i,j) = (i+j) % 2 === 0 ? 1 : -1\r\n // - Minor(i, j) is the 3x3 matrix we get by removing row i and column j from current Matrix\r\n //\r\n // Here we do that for the 1st row.\r\n\r\n const det_22_33 = m22 * m33 - m32 * m23;\r\n const det_21_33 = m21 * m33 - m31 * m23;\r\n const det_21_32 = m21 * m32 - m31 * m22;\r\n const det_20_33 = m20 * m33 - m30 * m23;\r\n const det_20_32 = m20 * m32 - m22 * m30;\r\n const det_20_31 = m20 * m31 - m30 * m21;\r\n const cofact_00 = +(m11 * det_22_33 - m12 * det_21_33 + m13 * det_21_32);\r\n const cofact_01 = -(m10 * det_22_33 - m12 * det_20_33 + m13 * det_20_32);\r\n const cofact_02 = +(m10 * det_21_33 - m11 * det_20_33 + m13 * det_20_31);\r\n const cofact_03 = -(m10 * det_21_32 - m11 * det_20_32 + m12 * det_20_31);\r\n return m00 * cofact_00 + m01 * cofact_01 + m02 * cofact_02 + m03 * cofact_03;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Returns the matrix as a Float32Array or Array\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#49\r\n * @returns the matrix underlying array\r\n */\r\n public toArray(): DeepImmutable> {\r\n return this._m;\r\n }\r\n /**\r\n * Returns the matrix as a Float32Array or Array\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#114\r\n * @returns the matrix underlying array.\r\n */\r\n public asArray(): DeepImmutable> {\r\n return this._m;\r\n }\r\n\r\n /**\r\n * Inverts the current matrix in place\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#118\r\n * @returns the current inverted matrix\r\n */\r\n public invert(): this {\r\n this.invertToRef(this);\r\n return this;\r\n }\r\n /**\r\n * Sets all the matrix elements to zero\r\n * @returns the current matrix\r\n */\r\n public reset(): this {\r\n Matrix.FromValuesToRef(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, this);\r\n this._updateIdentityStatus(false);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds the current matrix with a second one\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#44\r\n * @param other defines the matrix to add\r\n * @returns a new matrix as the addition of the current matrix and the given one\r\n */\r\n public add(other: DeepImmutable): this {\r\n const result = new (this.constructor as MatrixConstructor)();\r\n this.addToRef(other, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given matrix \"result\" to the addition of the current matrix and the given one\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#45\r\n * @param other defines the matrix to add\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public addToRef(other: DeepImmutable, result: T): T {\r\n const m = this._m;\r\n const resultM = result._m;\r\n const otherM = other.m;\r\n for (let index = 0; index < 16; index++) {\r\n resultM[index] = m[index] + otherM[index];\r\n }\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Adds in place the given matrix to the current matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#46\r\n * @param other defines the second operand\r\n * @returns the current updated matrix\r\n */\r\n public addToSelf(other: DeepImmutable): this {\r\n const m = this._m;\r\n const otherM = other.m;\r\n for (let index = 0; index < 16; index++) {\r\n m[index] += otherM[index];\r\n }\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the given matrix to the current inverted Matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#119\r\n * @param other defines the target matrix\r\n * @returns result input\r\n */\r\n public invertToRef(other: T): T {\r\n if (this._isIdentity === true) {\r\n Matrix.IdentityToRef(other);\r\n return other;\r\n }\r\n\r\n // the inverse of a Matrix is the transpose of cofactor matrix divided by the determinant\r\n const m = this._m;\r\n const m00 = m[0],\r\n m01 = m[1],\r\n m02 = m[2],\r\n m03 = m[3];\r\n const m10 = m[4],\r\n m11 = m[5],\r\n m12 = m[6],\r\n m13 = m[7];\r\n const m20 = m[8],\r\n m21 = m[9],\r\n m22 = m[10],\r\n m23 = m[11];\r\n const m30 = m[12],\r\n m31 = m[13],\r\n m32 = m[14],\r\n m33 = m[15];\r\n\r\n const det_22_33 = m22 * m33 - m32 * m23;\r\n const det_21_33 = m21 * m33 - m31 * m23;\r\n const det_21_32 = m21 * m32 - m31 * m22;\r\n const det_20_33 = m20 * m33 - m30 * m23;\r\n const det_20_32 = m20 * m32 - m22 * m30;\r\n const det_20_31 = m20 * m31 - m30 * m21;\r\n\r\n const cofact_00 = +(m11 * det_22_33 - m12 * det_21_33 + m13 * det_21_32);\r\n const cofact_01 = -(m10 * det_22_33 - m12 * det_20_33 + m13 * det_20_32);\r\n const cofact_02 = +(m10 * det_21_33 - m11 * det_20_33 + m13 * det_20_31);\r\n const cofact_03 = -(m10 * det_21_32 - m11 * det_20_32 + m12 * det_20_31);\r\n\r\n const det = m00 * cofact_00 + m01 * cofact_01 + m02 * cofact_02 + m03 * cofact_03;\r\n\r\n if (det === 0) {\r\n // not invertible\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n\r\n const detInv = 1 / det;\r\n const det_12_33 = m12 * m33 - m32 * m13;\r\n const det_11_33 = m11 * m33 - m31 * m13;\r\n const det_11_32 = m11 * m32 - m31 * m12;\r\n const det_10_33 = m10 * m33 - m30 * m13;\r\n const det_10_32 = m10 * m32 - m30 * m12;\r\n const det_10_31 = m10 * m31 - m30 * m11;\r\n const det_12_23 = m12 * m23 - m22 * m13;\r\n const det_11_23 = m11 * m23 - m21 * m13;\r\n const det_11_22 = m11 * m22 - m21 * m12;\r\n const det_10_23 = m10 * m23 - m20 * m13;\r\n const det_10_22 = m10 * m22 - m20 * m12;\r\n const det_10_21 = m10 * m21 - m20 * m11;\r\n\r\n const cofact_10 = -(m01 * det_22_33 - m02 * det_21_33 + m03 * det_21_32);\r\n const cofact_11 = +(m00 * det_22_33 - m02 * det_20_33 + m03 * det_20_32);\r\n const cofact_12 = -(m00 * det_21_33 - m01 * det_20_33 + m03 * det_20_31);\r\n const cofact_13 = +(m00 * det_21_32 - m01 * det_20_32 + m02 * det_20_31);\r\n\r\n const cofact_20 = +(m01 * det_12_33 - m02 * det_11_33 + m03 * det_11_32);\r\n const cofact_21 = -(m00 * det_12_33 - m02 * det_10_33 + m03 * det_10_32);\r\n const cofact_22 = +(m00 * det_11_33 - m01 * det_10_33 + m03 * det_10_31);\r\n const cofact_23 = -(m00 * det_11_32 - m01 * det_10_32 + m02 * det_10_31);\r\n\r\n const cofact_30 = -(m01 * det_12_23 - m02 * det_11_23 + m03 * det_11_22);\r\n const cofact_31 = +(m00 * det_12_23 - m02 * det_10_23 + m03 * det_10_22);\r\n const cofact_32 = -(m00 * det_11_23 - m01 * det_10_23 + m03 * det_10_21);\r\n const cofact_33 = +(m00 * det_11_22 - m01 * det_10_22 + m02 * det_10_21);\r\n\r\n Matrix.FromValuesToRef(\r\n cofact_00 * detInv,\r\n cofact_10 * detInv,\r\n cofact_20 * detInv,\r\n cofact_30 * detInv,\r\n cofact_01 * detInv,\r\n cofact_11 * detInv,\r\n cofact_21 * detInv,\r\n cofact_31 * detInv,\r\n cofact_02 * detInv,\r\n cofact_12 * detInv,\r\n cofact_22 * detInv,\r\n cofact_32 * detInv,\r\n cofact_03 * detInv,\r\n cofact_13 * detInv,\r\n cofact_23 * detInv,\r\n cofact_33 * detInv,\r\n other\r\n );\r\n\r\n return other;\r\n }\r\n\r\n /**\r\n * add a value at the specified position in the current Matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#47\r\n * @param index the index of the value within the matrix. between 0 and 15.\r\n * @param value the value to be added\r\n * @returns the current updated matrix\r\n */\r\n public addAtIndex(index: number, value: number): this {\r\n this._m[index] += value;\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * mutiply the specified position in the current Matrix by a value\r\n * @param index the index of the value within the matrix. between 0 and 15.\r\n * @param value the value to be added\r\n * @returns the current updated matrix\r\n */\r\n public multiplyAtIndex(index: number, value: number): this {\r\n this._m[index] *= value;\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * Inserts the translation vector (using 3 floats) in the current matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#120\r\n * @param x defines the 1st component of the translation\r\n * @param y defines the 2nd component of the translation\r\n * @param z defines the 3rd component of the translation\r\n * @returns the current updated matrix\r\n */\r\n public setTranslationFromFloats(x: number, y: number, z: number): this {\r\n this._m[12] = x;\r\n this._m[13] = y;\r\n this._m[14] = z;\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds the translation vector (using 3 floats) in the current matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#20\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#48\r\n * @param x defines the 1st component of the translation\r\n * @param y defines the 2nd component of the translation\r\n * @param z defines the 3rd component of the translation\r\n * @returns the current updated matrix\r\n */\r\n public addTranslationFromFloats(x: number, y: number, z: number): this {\r\n this._m[12] += x;\r\n this._m[13] += y;\r\n this._m[14] += z;\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * Inserts the translation vector in the current matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#121\r\n * @param vector3 defines the translation to insert\r\n * @returns the current updated matrix\r\n */\r\n public setTranslation(vector3: DeepImmutable): this {\r\n return this.setTranslationFromFloats(vector3._x, vector3._y, vector3._z);\r\n }\r\n\r\n /**\r\n * Gets the translation value of the current matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#122\r\n * @returns a new Vector3 as the extracted translation from the matrix\r\n */\r\n public getTranslation(): Vector3 {\r\n return new Vector3(this._m[12], this._m[13], this._m[14]);\r\n }\r\n\r\n /**\r\n * Fill a Vector3 with the extracted translation from the matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#123\r\n * @param result defines the Vector3 where to store the translation\r\n * @returns the current matrix\r\n */\r\n public getTranslationToRef(result: T): T {\r\n result.x = this._m[12];\r\n result.y = this._m[13];\r\n result.z = this._m[14];\r\n return result;\r\n }\r\n\r\n /**\r\n * Remove rotation and scaling part from the matrix\r\n * @returns the updated matrix\r\n */\r\n public removeRotationAndScaling(): this {\r\n const m = this.m;\r\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, m[12], m[13], m[14], m[15], this);\r\n this._updateIdentityStatus(m[12] === 0 && m[13] === 0 && m[14] === 0 && m[15] === 1);\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiply two matrices\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#15\r\n * A.multiply(B) means apply B to A so result is B x A\r\n * @param other defines the second operand\r\n * @returns a new matrix set with the multiplication result of the current Matrix and the given one\r\n */\r\n public multiply(other: DeepImmutable): this {\r\n const result = new (this.constructor as MatrixConstructor)();\r\n this.multiplyToRef(other, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Copy the current matrix from the given one\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#21\r\n * @param other defines the source matrix\r\n * @returns the current updated matrix\r\n */\r\n public copyFrom(other: DeepImmutable): this {\r\n other.copyToArray(this._m);\r\n const o = other as Matrix;\r\n this.updateFlag = o.updateFlag;\r\n this._updateIdentityStatus(o._isIdentity, o._isIdentityDirty, o._isIdentity3x2, o._isIdentity3x2Dirty);\r\n return this;\r\n }\r\n\r\n /**\r\n * Populates the given array from the starting index with the current matrix values\r\n * @param array defines the target array\r\n * @param offset defines the offset in the target array where to start storing values\r\n * @returns the current matrix\r\n */\r\n public copyToArray(array: Float32Array | Array, offset: number = 0): this {\r\n const source = this._m;\r\n array[offset] = source[0];\r\n array[offset + 1] = source[1];\r\n array[offset + 2] = source[2];\r\n array[offset + 3] = source[3];\r\n array[offset + 4] = source[4];\r\n array[offset + 5] = source[5];\r\n array[offset + 6] = source[6];\r\n array[offset + 7] = source[7];\r\n array[offset + 8] = source[8];\r\n array[offset + 9] = source[9];\r\n array[offset + 10] = source[10];\r\n array[offset + 11] = source[11];\r\n array[offset + 12] = source[12];\r\n array[offset + 13] = source[13];\r\n array[offset + 14] = source[14];\r\n array[offset + 15] = source[15];\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the given matrix \"result\" with the multiplication result of the current Matrix and the given one\r\n * A.multiplyToRef(B, R) means apply B to A and store in R and R = B x A\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#16\r\n * @param other defines the second operand\r\n * @param result defines the matrix where to store the multiplication\r\n * @returns result input\r\n */\r\n public multiplyToRef(other: DeepImmutable, result: T): T {\r\n if (this._isIdentity) {\r\n result.copyFrom(other);\r\n return result;\r\n }\r\n if ((other as Matrix)._isIdentity) {\r\n result.copyFrom(this);\r\n return result;\r\n }\r\n\r\n this.multiplyToArray(other, result._m, 0);\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the Float32Array \"result\" from the given index \"offset\" with the multiplication of the current matrix and the given one\r\n * @param other defines the second operand\r\n * @param result defines the array where to store the multiplication\r\n * @param offset defines the offset in the target array where to start storing values\r\n * @returns the current matrix\r\n */\r\n public multiplyToArray(other: DeepImmutable, result: Float32Array | Array, offset: number): this {\r\n const m = this._m;\r\n const otherM = other.m;\r\n const tm0 = m[0],\r\n tm1 = m[1],\r\n tm2 = m[2],\r\n tm3 = m[3];\r\n const tm4 = m[4],\r\n tm5 = m[5],\r\n tm6 = m[6],\r\n tm7 = m[7];\r\n const tm8 = m[8],\r\n tm9 = m[9],\r\n tm10 = m[10],\r\n tm11 = m[11];\r\n const tm12 = m[12],\r\n tm13 = m[13],\r\n tm14 = m[14],\r\n tm15 = m[15];\r\n\r\n const om0 = otherM[0],\r\n om1 = otherM[1],\r\n om2 = otherM[2],\r\n om3 = otherM[3];\r\n const om4 = otherM[4],\r\n om5 = otherM[5],\r\n om6 = otherM[6],\r\n om7 = otherM[7];\r\n const om8 = otherM[8],\r\n om9 = otherM[9],\r\n om10 = otherM[10],\r\n om11 = otherM[11];\r\n const om12 = otherM[12],\r\n om13 = otherM[13],\r\n om14 = otherM[14],\r\n om15 = otherM[15];\r\n\r\n result[offset] = tm0 * om0 + tm1 * om4 + tm2 * om8 + tm3 * om12;\r\n result[offset + 1] = tm0 * om1 + tm1 * om5 + tm2 * om9 + tm3 * om13;\r\n result[offset + 2] = tm0 * om2 + tm1 * om6 + tm2 * om10 + tm3 * om14;\r\n result[offset + 3] = tm0 * om3 + tm1 * om7 + tm2 * om11 + tm3 * om15;\r\n\r\n result[offset + 4] = tm4 * om0 + tm5 * om4 + tm6 * om8 + tm7 * om12;\r\n result[offset + 5] = tm4 * om1 + tm5 * om5 + tm6 * om9 + tm7 * om13;\r\n result[offset + 6] = tm4 * om2 + tm5 * om6 + tm6 * om10 + tm7 * om14;\r\n result[offset + 7] = tm4 * om3 + tm5 * om7 + tm6 * om11 + tm7 * om15;\r\n\r\n result[offset + 8] = tm8 * om0 + tm9 * om4 + tm10 * om8 + tm11 * om12;\r\n result[offset + 9] = tm8 * om1 + tm9 * om5 + tm10 * om9 + tm11 * om13;\r\n result[offset + 10] = tm8 * om2 + tm9 * om6 + tm10 * om10 + tm11 * om14;\r\n result[offset + 11] = tm8 * om3 + tm9 * om7 + tm10 * om11 + tm11 * om15;\r\n\r\n result[offset + 12] = tm12 * om0 + tm13 * om4 + tm14 * om8 + tm15 * om12;\r\n result[offset + 13] = tm12 * om1 + tm13 * om5 + tm14 * om9 + tm15 * om13;\r\n result[offset + 14] = tm12 * om2 + tm13 * om6 + tm14 * om10 + tm15 * om14;\r\n result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;\r\n return this;\r\n }\r\n\r\n /**\r\n * Check equality between this matrix and a second one\r\n * @param value defines the second matrix to compare\r\n * @returns true is the current matrix and the given one values are strictly equal\r\n */\r\n public equals(value: DeepImmutable): boolean {\r\n const other = value as Matrix;\r\n if (!other) {\r\n return false;\r\n }\r\n\r\n if (this._isIdentity || other._isIdentity) {\r\n if (!this._isIdentityDirty && !other._isIdentityDirty) {\r\n return this._isIdentity && other._isIdentity;\r\n }\r\n }\r\n\r\n const m = this.m;\r\n const om = other.m;\r\n return (\r\n m[0] === om[0] &&\r\n m[1] === om[1] &&\r\n m[2] === om[2] &&\r\n m[3] === om[3] &&\r\n m[4] === om[4] &&\r\n m[5] === om[5] &&\r\n m[6] === om[6] &&\r\n m[7] === om[7] &&\r\n m[8] === om[8] &&\r\n m[9] === om[9] &&\r\n m[10] === om[10] &&\r\n m[11] === om[11] &&\r\n m[12] === om[12] &&\r\n m[13] === om[13] &&\r\n m[14] === om[14] &&\r\n m[15] === om[15]\r\n );\r\n }\r\n\r\n /**\r\n * Clone the current matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#18\r\n * @returns a new matrix from the current matrix\r\n */\r\n public clone(): this {\r\n const matrix = new (this.constructor as MatrixConstructor)();\r\n matrix.copyFrom(this);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Returns the name of the current matrix class\r\n * @returns the string \"Matrix\"\r\n */\r\n public getClassName(): string {\r\n return \"Matrix\";\r\n }\r\n\r\n /**\r\n * Gets the hash code of the current matrix\r\n * @returns the hash code\r\n */\r\n public getHashCode(): number {\r\n let hash = _ExtractAsInt(this._m[0]);\r\n for (let i = 1; i < 16; i++) {\r\n hash = (hash * 397) ^ _ExtractAsInt(this._m[i]);\r\n }\r\n return hash;\r\n }\r\n\r\n /**\r\n * Decomposes the current Matrix into a translation, rotation and scaling components of the provided node\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#13\r\n * @param node the node to decompose the matrix to\r\n * @returns true if operation was successful\r\n */\r\n public decomposeToTransformNode(node: TransformNode): boolean {\r\n node.rotationQuaternion = node.rotationQuaternion || new Quaternion();\r\n return this.decompose(node.scaling, node.rotationQuaternion, node.position);\r\n }\r\n /**\r\n * Decomposes the current Matrix into a translation, rotation and scaling components\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#12\r\n * @param scale defines the scale vector3 given as a reference to update\r\n * @param rotation defines the rotation quaternion given as a reference to update\r\n * @param translation defines the translation vector3 given as a reference to update\r\n * @param preserveScalingNode Use scaling sign coming from this node. Otherwise scaling sign might change.\r\n * @returns true if operation was successful\r\n */\r\n public decompose(scale?: Vector3, rotation?: Quaternion, translation?: Vector3, preserveScalingNode?: TransformNode): boolean {\r\n if (this._isIdentity) {\r\n if (translation) {\r\n translation.setAll(0);\r\n }\r\n if (scale) {\r\n scale.setAll(1);\r\n }\r\n if (rotation) {\r\n rotation.copyFromFloats(0, 0, 0, 1);\r\n }\r\n return true;\r\n }\r\n\r\n const m = this._m;\r\n if (translation) {\r\n translation.copyFromFloats(m[12], m[13], m[14]);\r\n }\r\n\r\n scale = scale || MathTmp.Vector3[0];\r\n\r\n scale.x = Math.sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]);\r\n scale.y = Math.sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]);\r\n scale.z = Math.sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]);\r\n\r\n if (preserveScalingNode) {\r\n const signX = preserveScalingNode.scaling.x < 0 ? -1 : 1;\r\n const signY = preserveScalingNode.scaling.y < 0 ? -1 : 1;\r\n const signZ = preserveScalingNode.scaling.z < 0 ? -1 : 1;\r\n\r\n scale.x *= signX;\r\n scale.y *= signY;\r\n scale.z *= signZ;\r\n } else {\r\n if (this.determinant() <= 0) {\r\n scale.y *= -1;\r\n }\r\n }\r\n\r\n if (scale._x === 0 || scale._y === 0 || scale._z === 0) {\r\n if (rotation) {\r\n rotation.copyFromFloats(0.0, 0.0, 0.0, 1.0);\r\n }\r\n return false;\r\n }\r\n\r\n if (rotation) {\r\n const sx = 1 / scale._x,\r\n sy = 1 / scale._y,\r\n sz = 1 / scale._z;\r\n Matrix.FromValuesToRef(\r\n m[0] * sx,\r\n m[1] * sx,\r\n m[2] * sx,\r\n 0.0,\r\n m[4] * sy,\r\n m[5] * sy,\r\n m[6] * sy,\r\n 0.0,\r\n m[8] * sz,\r\n m[9] * sz,\r\n m[10] * sz,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0,\r\n MathTmp.Matrix[0]\r\n );\r\n\r\n Quaternion.FromRotationMatrixToRef(MathTmp.Matrix[0], rotation);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Gets specific row of the matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\r\n * @param index defines the number of the row to get\r\n * @returns the index-th row of the current matrix as a new Vector4\r\n */\r\n public getRow(index: number): Nullable {\r\n if (index < 0 || index > 3) {\r\n return null;\r\n }\r\n const i = index * 4;\r\n return new Vector4(this._m[i + 0], this._m[i + 1], this._m[i + 2], this._m[i + 3]);\r\n }\r\n\r\n /**\r\n * Gets specific row of the matrix to ref\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\r\n * @param index defines the number of the row to get\r\n * @param rowVector vector to store the index-th row of the current matrix\r\n * @returns result input\r\n */\r\n public getRowToRef(index: number, rowVector: T): T {\r\n if (index >= 0 && index < 3) {\r\n const i = index * 4;\r\n rowVector.x = this._m[i + 0];\r\n rowVector.y = this._m[i + 1];\r\n rowVector.z = this._m[i + 2];\r\n rowVector.w = this._m[i + 3];\r\n }\r\n return rowVector;\r\n }\r\n\r\n /**\r\n * Sets the index-th row of the current matrix to the vector4 values\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\r\n * @param index defines the number of the row to set\r\n * @param row defines the target vector4\r\n * @returns the updated current matrix\r\n */\r\n public setRow(index: number, row: Vector4): this {\r\n return this.setRowFromFloats(index, row.x, row.y, row.z, row.w);\r\n }\r\n\r\n /**\r\n * Compute the transpose of the matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#40\r\n * @returns the new transposed matrix\r\n */\r\n public transpose(): this {\r\n const result = new (this.constructor as MatrixConstructor)();\r\n Matrix.TransposeToRef(this, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Compute the transpose of the matrix and store it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#41\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public transposeToRef(result: T): T {\r\n Matrix.TransposeToRef(this, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the index-th row of the current matrix with the given 4 x float values\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#36\r\n * @param index defines the row index\r\n * @param x defines the x component to set\r\n * @param y defines the y component to set\r\n * @param z defines the z component to set\r\n * @param w defines the w component to set\r\n * @returns the updated current matrix\r\n */\r\n public setRowFromFloats(index: number, x: number, y: number, z: number, w: number): this {\r\n if (index < 0 || index > 3) {\r\n return this;\r\n }\r\n const i = index * 4;\r\n this._m[i + 0] = x;\r\n this._m[i + 1] = y;\r\n this._m[i + 2] = z;\r\n this._m[i + 3] = w;\r\n\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * Compute a new matrix set with the current matrix values multiplied by scale (float)\r\n * @param scale defines the scale factor\r\n * @returns a new matrix\r\n */\r\n public scale(scale: number): this {\r\n const result = new (this.constructor as MatrixConstructor)();\r\n this.scaleToRef(scale, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Scale the current matrix values by a factor to a given result matrix\r\n * @param scale defines the scale factor\r\n * @param result defines the matrix to store the result\r\n * @returns result input\r\n */\r\n public scaleToRef(scale: number, result: T): T {\r\n for (let index = 0; index < 16; index++) {\r\n result._m[index] = this._m[index] * scale;\r\n }\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Scale the current matrix values by a factor and add the result to a given matrix\r\n * @param scale defines the scale factor\r\n * @param result defines the Matrix to store the result\r\n * @returns result input\r\n */\r\n public scaleAndAddToRef(scale: number, result: T): T {\r\n for (let index = 0; index < 16; index++) {\r\n result._m[index] += this._m[index] * scale;\r\n }\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Writes to the given matrix a normal matrix, computed from this one (using values from identity matrix for fourth row and column).\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#17\r\n * @param ref matrix to store the result\r\n */\r\n public toNormalMatrix(ref: T): T {\r\n const tmp = MathTmp.Matrix[0];\r\n this.invertToRef(tmp);\r\n tmp.transposeToRef(ref);\r\n const m = ref._m;\r\n Matrix.FromValuesToRef(m[0], m[1], m[2], 0.0, m[4], m[5], m[6], 0.0, m[8], m[9], m[10], 0.0, 0.0, 0.0, 0.0, 1.0, ref);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Gets only rotation part of the current matrix\r\n * @returns a new matrix sets to the extracted rotation matrix from the current one\r\n */\r\n public getRotationMatrix(): this {\r\n const result = new (this.constructor as MatrixConstructor)();\r\n this.getRotationMatrixToRef(result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Extracts the rotation matrix from the current one and sets it as the given \"result\"\r\n * @param result defines the target matrix to store data to\r\n * @returns result input\r\n */\r\n public getRotationMatrixToRef(result: T): T {\r\n const scale = MathTmp.Vector3[0];\r\n if (!this.decompose(scale)) {\r\n Matrix.IdentityToRef(result);\r\n return result;\r\n }\r\n\r\n const m = this._m;\r\n const sx = 1 / scale._x,\r\n sy = 1 / scale._y,\r\n sz = 1 / scale._z;\r\n Matrix.FromValuesToRef(m[0] * sx, m[1] * sx, m[2] * sx, 0.0, m[4] * sy, m[5] * sy, m[6] * sy, 0.0, m[8] * sz, m[9] * sz, m[10] * sz, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Toggles model matrix from being right handed to left handed in place and vice versa\r\n */\r\n public toggleModelMatrixHandInPlace(): this {\r\n const m = this._m;\r\n m[2] *= -1;\r\n m[6] *= -1;\r\n m[8] *= -1;\r\n m[9] *= -1;\r\n m[14] *= -1;\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n /**\r\n * Toggles projection matrix from being right handed to left handed in place and vice versa\r\n */\r\n public toggleProjectionMatrixHandInPlace(): this {\r\n const m = this._m;\r\n m[8] *= -1;\r\n m[9] *= -1;\r\n m[10] *= -1;\r\n m[11] *= -1;\r\n this.markAsUpdated();\r\n return this;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Creates a matrix from an array\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#42\r\n * @param array defines the source array\r\n * @param offset defines an offset in the source array\r\n * @returns a new Matrix set from the starting index of the given array\r\n */\r\n public static FromArray(array: DeepImmutable>, offset: number = 0): Matrix {\r\n const result = new Matrix();\r\n Matrix.FromArrayToRef(array, offset, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Copy the content of an array into a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#43\r\n * @param array defines the source array\r\n * @param offset defines an offset in the source array\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number, result: T): T {\r\n for (let index = 0; index < 16; index++) {\r\n result._m[index] = array[index + offset];\r\n }\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Stores an array into a matrix after having multiplied each component by a given factor\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#50\r\n * @param array defines the source array\r\n * @param offset defines the offset in the source array\r\n * @param scale defines the scaling factor\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static FromFloat32ArrayToRefScaled(array: DeepImmutable>, offset: number, scale: number, result: T): T {\r\n for (let index = 0; index < 16; index++) {\r\n result._m[index] = array[index + offset] * scale;\r\n }\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets an identity matrix that must not be updated\r\n */\r\n public static get IdentityReadOnly(): DeepImmutable {\r\n return Matrix._IdentityReadOnly;\r\n }\r\n\r\n /**\r\n * Stores a list of values (16) inside a given matrix\r\n * @param initialM11 defines 1st value of 1st row\r\n * @param initialM12 defines 2nd value of 1st row\r\n * @param initialM13 defines 3rd value of 1st row\r\n * @param initialM14 defines 4th value of 1st row\r\n * @param initialM21 defines 1st value of 2nd row\r\n * @param initialM22 defines 2nd value of 2nd row\r\n * @param initialM23 defines 3rd value of 2nd row\r\n * @param initialM24 defines 4th value of 2nd row\r\n * @param initialM31 defines 1st value of 3rd row\r\n * @param initialM32 defines 2nd value of 3rd row\r\n * @param initialM33 defines 3rd value of 3rd row\r\n * @param initialM34 defines 4th value of 3rd row\r\n * @param initialM41 defines 1st value of 4th row\r\n * @param initialM42 defines 2nd value of 4th row\r\n * @param initialM43 defines 3rd value of 4th row\r\n * @param initialM44 defines 4th value of 4th row\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static FromValuesToRef(\r\n initialM11: number,\r\n initialM12: number,\r\n initialM13: number,\r\n initialM14: number,\r\n initialM21: number,\r\n initialM22: number,\r\n initialM23: number,\r\n initialM24: number,\r\n initialM31: number,\r\n initialM32: number,\r\n initialM33: number,\r\n initialM34: number,\r\n initialM41: number,\r\n initialM42: number,\r\n initialM43: number,\r\n initialM44: number,\r\n result: Matrix\r\n ): void {\r\n const m = result._m;\r\n m[0] = initialM11;\r\n m[1] = initialM12;\r\n m[2] = initialM13;\r\n m[3] = initialM14;\r\n m[4] = initialM21;\r\n m[5] = initialM22;\r\n m[6] = initialM23;\r\n m[7] = initialM24;\r\n m[8] = initialM31;\r\n m[9] = initialM32;\r\n m[10] = initialM33;\r\n m[11] = initialM34;\r\n m[12] = initialM41;\r\n m[13] = initialM42;\r\n m[14] = initialM43;\r\n m[15] = initialM44;\r\n\r\n result.markAsUpdated();\r\n }\r\n\r\n /**\r\n * Creates new matrix from a list of values (16)\r\n * @param initialM11 defines 1st value of 1st row\r\n * @param initialM12 defines 2nd value of 1st row\r\n * @param initialM13 defines 3rd value of 1st row\r\n * @param initialM14 defines 4th value of 1st row\r\n * @param initialM21 defines 1st value of 2nd row\r\n * @param initialM22 defines 2nd value of 2nd row\r\n * @param initialM23 defines 3rd value of 2nd row\r\n * @param initialM24 defines 4th value of 2nd row\r\n * @param initialM31 defines 1st value of 3rd row\r\n * @param initialM32 defines 2nd value of 3rd row\r\n * @param initialM33 defines 3rd value of 3rd row\r\n * @param initialM34 defines 4th value of 3rd row\r\n * @param initialM41 defines 1st value of 4th row\r\n * @param initialM42 defines 2nd value of 4th row\r\n * @param initialM43 defines 3rd value of 4th row\r\n * @param initialM44 defines 4th value of 4th row\r\n * @returns the new matrix\r\n */\r\n public static FromValues(\r\n initialM11: number,\r\n initialM12: number,\r\n initialM13: number,\r\n initialM14: number,\r\n initialM21: number,\r\n initialM22: number,\r\n initialM23: number,\r\n initialM24: number,\r\n initialM31: number,\r\n initialM32: number,\r\n initialM33: number,\r\n initialM34: number,\r\n initialM41: number,\r\n initialM42: number,\r\n initialM43: number,\r\n initialM44: number\r\n ): Matrix {\r\n const result = new Matrix();\r\n const m = result._m;\r\n m[0] = initialM11;\r\n m[1] = initialM12;\r\n m[2] = initialM13;\r\n m[3] = initialM14;\r\n m[4] = initialM21;\r\n m[5] = initialM22;\r\n m[6] = initialM23;\r\n m[7] = initialM24;\r\n m[8] = initialM31;\r\n m[9] = initialM32;\r\n m[10] = initialM33;\r\n m[11] = initialM34;\r\n m[12] = initialM41;\r\n m[13] = initialM42;\r\n m[14] = initialM43;\r\n m[15] = initialM44;\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new matrix composed by merging scale (vector3), rotation (quaternion) and translation (vector3)\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#24\r\n * @param scale defines the scale vector3\r\n * @param rotation defines the rotation quaternion\r\n * @param translation defines the translation vector3\r\n * @returns a new matrix\r\n */\r\n public static Compose(scale: DeepImmutable, rotation: DeepImmutable, translation: DeepImmutable): Matrix {\r\n const result = new Matrix();\r\n Matrix.ComposeToRef(scale, rotation, translation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets a matrix to a value composed by merging scale (vector3), rotation (quaternion) and translation (vector3)\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#25\r\n * @param scale defines the scale vector3\r\n * @param rotation defines the rotation quaternion\r\n * @param translation defines the translation vector3\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static ComposeToRef(scale: DeepImmutable, rotation: DeepImmutable, translation: DeepImmutable, result: T): T {\r\n const m = result._m;\r\n const x = rotation._x,\r\n y = rotation._y,\r\n z = rotation._z,\r\n w = rotation._w;\r\n const x2 = x + x,\r\n y2 = y + y,\r\n z2 = z + z;\r\n const xx = x * x2,\r\n xy = x * y2,\r\n xz = x * z2;\r\n const yy = y * y2,\r\n yz = y * z2,\r\n zz = z * z2;\r\n const wx = w * x2,\r\n wy = w * y2,\r\n wz = w * z2;\r\n\r\n const sx = scale._x,\r\n sy = scale._y,\r\n sz = scale._z;\r\n\r\n m[0] = (1 - (yy + zz)) * sx;\r\n m[1] = (xy + wz) * sx;\r\n m[2] = (xz - wy) * sx;\r\n m[3] = 0;\r\n\r\n m[4] = (xy - wz) * sy;\r\n m[5] = (1 - (xx + zz)) * sy;\r\n m[6] = (yz + wx) * sy;\r\n m[7] = 0;\r\n\r\n m[8] = (xz + wy) * sz;\r\n m[9] = (yz - wx) * sz;\r\n m[10] = (1 - (xx + yy)) * sz;\r\n m[11] = 0;\r\n\r\n m[12] = translation._x;\r\n m[13] = translation._y;\r\n m[14] = translation._z;\r\n m[15] = 1;\r\n\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new identity matrix\r\n * @returns a new identity matrix\r\n */\r\n public static Identity(): Matrix {\r\n const identity = Matrix.FromValues(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);\r\n identity._updateIdentityStatus(true);\r\n return identity;\r\n }\r\n\r\n /**\r\n * Creates a new identity matrix and stores the result in a given matrix\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static IdentityToRef(result: T): T {\r\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n result._updateIdentityStatus(true);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new zero matrix\r\n * @returns a new zero matrix\r\n */\r\n public static Zero(): Matrix {\r\n const zero = Matrix.FromValues(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);\r\n zero._updateIdentityStatus(false);\r\n return zero;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the X axis\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#97\r\n * @param angle defines the angle (in radians) to use\r\n * @returns the new matrix\r\n */\r\n public static RotationX(angle: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.RotationXToRef(angle, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new matrix as the invert of a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#124\r\n * @param source defines the source matrix\r\n * @returns the new matrix\r\n */\r\n public static Invert(source: DeepImmutable): T {\r\n const result = new (source.constructor as MatrixConstructor)();\r\n source.invertToRef(result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the X axis and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#98\r\n * @param angle defines the angle (in radians) to use\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static RotationXToRef(angle: number, result: T): T {\r\n const s = Math.sin(angle);\r\n const c = Math.cos(angle);\r\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n\r\n result._updateIdentityStatus(c === 1 && s === 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the Y axis\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#99\r\n * @param angle defines the angle (in radians) to use\r\n * @returns the new matrix\r\n */\r\n public static RotationY(angle: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.RotationYToRef(angle, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the Y axis and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#100\r\n * @param angle defines the angle (in radians) to use\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static RotationYToRef(angle: number, result: T): T {\r\n const s = Math.sin(angle);\r\n const c = Math.cos(angle);\r\n Matrix.FromValuesToRef(c, 0.0, -s, 0.0, 0.0, 1.0, 0.0, 0.0, s, 0.0, c, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n\r\n result._updateIdentityStatus(c === 1 && s === 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the Z axis\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#101\r\n * @param angle defines the angle (in radians) to use\r\n * @returns the new matrix\r\n */\r\n public static RotationZ(angle: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.RotationZToRef(angle, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the Z axis and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#102\r\n * @param angle defines the angle (in radians) to use\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static RotationZToRef(angle: number, result: T): T {\r\n const s = Math.sin(angle);\r\n const c = Math.cos(angle);\r\n Matrix.FromValuesToRef(c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n\r\n result._updateIdentityStatus(c === 1 && s === 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the given axis\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#96\r\n * @param axis defines the axis to use\r\n * @param angle defines the angle (in radians) to use\r\n * @returns the new matrix\r\n */\r\n public static RotationAxis(axis: DeepImmutable, angle: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.RotationAxisToRef(axis, angle, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new rotation matrix for \"angle\" radians around the given axis and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#94\r\n * @param axis defines the axis to use\r\n * @param angle defines the angle (in radians) to use\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static RotationAxisToRef(axis: DeepImmutable, angle: number, result: T): T {\r\n const s = Math.sin(-angle);\r\n const c = Math.cos(-angle);\r\n const c1 = 1 - c;\r\n\r\n axis.normalize();\r\n const m = result._m;\r\n m[0] = axis._x * axis._x * c1 + c;\r\n m[1] = axis._x * axis._y * c1 - axis._z * s;\r\n m[2] = axis._x * axis._z * c1 + axis._y * s;\r\n m[3] = 0.0;\r\n\r\n m[4] = axis._y * axis._x * c1 + axis._z * s;\r\n m[5] = axis._y * axis._y * c1 + c;\r\n m[6] = axis._y * axis._z * c1 - axis._x * s;\r\n m[7] = 0.0;\r\n\r\n m[8] = axis._z * axis._x * c1 - axis._y * s;\r\n m[9] = axis._z * axis._y * c1 + axis._x * s;\r\n m[10] = axis._z * axis._z * c1 + c;\r\n m[11] = 0.0;\r\n\r\n m[12] = 0.0;\r\n m[13] = 0.0;\r\n m[14] = 0.0;\r\n m[15] = 1.0;\r\n\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Takes normalised vectors and returns a rotation matrix to align \"from\" with \"to\".\r\n * Taken from http://www.iquilezles.org/www/articles/noacos/noacos.htm\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#93\r\n * @param from defines the vector to align\r\n * @param to defines the vector to align to\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static RotationAlignToRef(from: DeepImmutable, to: DeepImmutable, result: T): T {\r\n const c = Vector3.Dot(to, from);\r\n const m = result._m;\r\n if (c < -1 + Epsilon) {\r\n // from and to are colinear and opposite direction.\r\n // compute a PI rotation on Z axis\r\n m[0] = -1;\r\n m[1] = 0;\r\n m[2] = 0;\r\n m[3] = 0;\r\n m[4] = 0;\r\n m[5] = -1;\r\n m[6] = 0;\r\n m[7] = 0;\r\n m[8] = 0;\r\n m[9] = 0;\r\n m[10] = 1;\r\n m[11] = 0;\r\n } else {\r\n const v = Vector3.Cross(to, from);\r\n const k = 1 / (1 + c);\r\n\r\n m[0] = v._x * v._x * k + c;\r\n m[1] = v._y * v._x * k - v._z;\r\n m[2] = v._z * v._x * k + v._y;\r\n m[3] = 0;\r\n m[4] = v._x * v._y * k + v._z;\r\n m[5] = v._y * v._y * k + c;\r\n m[6] = v._z * v._y * k - v._x;\r\n m[7] = 0;\r\n m[8] = v._x * v._z * k - v._y;\r\n m[9] = v._y * v._z * k + v._x;\r\n m[10] = v._z * v._z * k + c;\r\n m[11] = 0;\r\n }\r\n m[12] = 0;\r\n m[13] = 0;\r\n m[14] = 0;\r\n m[15] = 1;\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a rotation matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#103\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#105\r\n * @param yaw defines the yaw angle in radians (Y axis)\r\n * @param pitch defines the pitch angle in radians (X axis)\r\n * @param roll defines the roll angle in radians (Z axis)\r\n * @returns the new rotation matrix\r\n */\r\n public static RotationYawPitchRoll(yaw: number, pitch: number, roll: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a rotation matrix and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#104\r\n * @param yaw defines the yaw angle in radians (Y axis)\r\n * @param pitch defines the pitch angle in radians (X axis)\r\n * @param roll defines the roll angle in radians (Z axis)\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static RotationYawPitchRollToRef(yaw: number, pitch: number, roll: number, result: T): T {\r\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, MathTmp.Quaternion[0]);\r\n MathTmp.Quaternion[0].toRotationMatrix(result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a scaling matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#107\r\n * @param x defines the scale factor on X axis\r\n * @param y defines the scale factor on Y axis\r\n * @param z defines the scale factor on Z axis\r\n * @returns the new matrix\r\n */\r\n public static Scaling(x: number, y: number, z: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.ScalingToRef(x, y, z, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a scaling matrix and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#108\r\n * @param x defines the scale factor on X axis\r\n * @param y defines the scale factor on Y axis\r\n * @param z defines the scale factor on Z axis\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static ScalingToRef(x: number, y: number, z: number, result: T): T {\r\n Matrix.FromValuesToRef(x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n\r\n result._updateIdentityStatus(x === 1 && y === 1 && z === 1);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a translation matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#109\r\n * @param x defines the translation on X axis\r\n * @param y defines the translation on Y axis\r\n * @param z defines the translationon Z axis\r\n * @returns the new matrix\r\n */\r\n public static Translation(x: number, y: number, z: number): Matrix {\r\n const result = new Matrix();\r\n Matrix.TranslationToRef(x, y, z, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a translation matrix and stores it in a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#110\r\n * @param x defines the translation on X axis\r\n * @param y defines the translation on Y axis\r\n * @param z defines the translationon Z axis\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static TranslationToRef(x: number, y: number, z: number, result: T): T {\r\n Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, x, y, z, 1.0, result);\r\n result._updateIdentityStatus(x === 0 && y === 0 && z === 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Matrix whose values are the interpolated values for \"gradient\" (float) between the ones of the matrices \"startValue\" and \"endValue\".\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#55\r\n * @param startValue defines the start value\r\n * @param endValue defines the end value\r\n * @param gradient defines the gradient factor\r\n * @returns the new matrix\r\n */\r\n public static Lerp(startValue: DeepImmutable, endValue: DeepImmutable, gradient: number): T {\r\n const result = new (startValue.constructor as MatrixConstructor)();\r\n Matrix.LerpToRef(startValue, endValue, gradient, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Set the given matrix \"result\" as the interpolated values for \"gradient\" (float) between the ones of the matrices \"startValue\" and \"endValue\".\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#54\r\n * @param startValue defines the start value\r\n * @param endValue defines the end value\r\n * @param gradient defines the gradient factor\r\n * @param result defines the Matrix object where to store data\r\n * @returns result input\r\n */\r\n public static LerpToRef(startValue: DeepImmutable, endValue: DeepImmutable, gradient: number, result: T): T {\r\n const resultM = result._m;\r\n const startM = startValue.m;\r\n const endM = endValue.m;\r\n for (let index = 0; index < 16; index++) {\r\n resultM[index] = startM[index] * (1.0 - gradient) + endM[index] * gradient;\r\n }\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Builds a new matrix whose values are computed by:\r\n * * decomposing the the \"startValue\" and \"endValue\" matrices into their respective scale, rotation and translation matrices\r\n * * interpolating for \"gradient\" (float) the values between each of these decomposed matrices between the start and the end\r\n * * recomposing a new matrix from these 3 interpolated scale, rotation and translation matrices\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#22\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#51\r\n * @param startValue defines the first matrix\r\n * @param endValue defines the second matrix\r\n * @param gradient defines the gradient between the two matrices\r\n * @returns the new matrix\r\n */\r\n public static DecomposeLerp(startValue: DeepImmutable, endValue: DeepImmutable, gradient: number): T {\r\n const result = new (startValue.constructor as MatrixConstructor)();\r\n Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Update a matrix to values which are computed by:\r\n * * decomposing the the \"startValue\" and \"endValue\" matrices into their respective scale, rotation and translation matrices\r\n * * interpolating for \"gradient\" (float) the values between each of these decomposed matrices between the start and the end\r\n * * recomposing a new matrix from these 3 interpolated scale, rotation and translation matrices\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#23\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#53\r\n * @param startValue defines the first matrix\r\n * @param endValue defines the second matrix\r\n * @param gradient defines the gradient between the two matrices\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static DecomposeLerpToRef(startValue: DeepImmutable, endValue: DeepImmutable, gradient: number, result: T): T {\r\n const startScale = MathTmp.Vector3[0];\r\n const startRotation = MathTmp.Quaternion[0];\r\n const startTranslation = MathTmp.Vector3[1];\r\n startValue.decompose(startScale, startRotation, startTranslation);\r\n\r\n const endScale = MathTmp.Vector3[2];\r\n const endRotation = MathTmp.Quaternion[1];\r\n const endTranslation = MathTmp.Vector3[3];\r\n endValue.decompose(endScale, endRotation, endTranslation);\r\n\r\n const resultScale = MathTmp.Vector3[4];\r\n Vector3.LerpToRef(startScale, endScale, gradient, resultScale);\r\n const resultRotation = MathTmp.Quaternion[2];\r\n Quaternion.SlerpToRef(startRotation, endRotation, gradient, resultRotation);\r\n\r\n const resultTranslation = MathTmp.Vector3[5];\r\n Vector3.LerpToRef(startTranslation, endTranslation, gradient, resultTranslation);\r\n\r\n Matrix.ComposeToRef(resultScale, resultRotation, resultTranslation, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\r\n * This function generates a matrix suitable for a left handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#58\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#59\r\n * @param eye defines the final position of the entity\r\n * @param target defines where the entity should look at\r\n * @param up defines the up vector for the entity\r\n * @returns the new matrix\r\n */\r\n public static LookAtLH(eye: DeepImmutable, target: DeepImmutable, up: DeepImmutable): Matrix {\r\n const result = new Matrix();\r\n Matrix.LookAtLHToRef(eye, target, up, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\r\n * This function generates a matrix suitable for a left handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#60\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#61\r\n * @param eye defines the final position of the entity\r\n * @param target defines where the entity should look at\r\n * @param up defines the up vector for the entity\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static LookAtLHToRef(eye: DeepImmutable, target: DeepImmutable, up: DeepImmutable, result: Matrix): void {\r\n const xAxis = MathTmp.Vector3[0];\r\n const yAxis = MathTmp.Vector3[1];\r\n const zAxis = MathTmp.Vector3[2];\r\n\r\n // Z axis\r\n target.subtractToRef(eye, zAxis);\r\n zAxis.normalize();\r\n\r\n // X axis\r\n Vector3.CrossToRef(up, zAxis, xAxis);\r\n\r\n const xSquareLength = xAxis.lengthSquared();\r\n if (xSquareLength === 0) {\r\n xAxis.x = 1.0;\r\n } else {\r\n xAxis.normalizeFromLength(Math.sqrt(xSquareLength));\r\n }\r\n\r\n // Y axis\r\n Vector3.CrossToRef(zAxis, xAxis, yAxis);\r\n yAxis.normalize();\r\n\r\n // Eye angles\r\n const ex = -Vector3.Dot(xAxis, eye);\r\n const ey = -Vector3.Dot(yAxis, eye);\r\n const ez = -Vector3.Dot(zAxis, eye);\r\n\r\n Matrix.FromValuesToRef(xAxis._x, yAxis._x, zAxis._x, 0.0, xAxis._y, yAxis._y, zAxis._y, 0.0, xAxis._z, yAxis._z, zAxis._z, 0.0, ex, ey, ez, 1.0, result);\r\n }\r\n\r\n /**\r\n * Creates a new matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\r\n * This function generates a matrix suitable for a right handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#62\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#63\r\n * @param eye defines the final position of the entity\r\n * @param target defines where the entity should look at\r\n * @param up defines the up vector for the entity\r\n * @returns the new matrix\r\n */\r\n public static LookAtRH(eye: DeepImmutable, target: DeepImmutable, up: DeepImmutable): Matrix {\r\n const result = new Matrix();\r\n Matrix.LookAtRHToRef(eye, target, up, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes three vectors as arguments that together describe the position and orientation of the camera.\r\n * This function generates a matrix suitable for a right handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#64\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#65\r\n * @param eye defines the final position of the entity\r\n * @param target defines where the entity should look at\r\n * @param up defines the up vector for the entity\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static LookAtRHToRef(eye: DeepImmutable, target: DeepImmutable, up: DeepImmutable, result: T): T {\r\n const xAxis = MathTmp.Vector3[0];\r\n const yAxis = MathTmp.Vector3[1];\r\n const zAxis = MathTmp.Vector3[2];\r\n\r\n // Z axis\r\n eye.subtractToRef(target, zAxis);\r\n zAxis.normalize();\r\n\r\n // X axis\r\n Vector3.CrossToRef(up, zAxis, xAxis);\r\n\r\n const xSquareLength = xAxis.lengthSquared();\r\n if (xSquareLength === 0) {\r\n xAxis.x = 1.0;\r\n } else {\r\n xAxis.normalizeFromLength(Math.sqrt(xSquareLength));\r\n }\r\n\r\n // Y axis\r\n Vector3.CrossToRef(zAxis, xAxis, yAxis);\r\n yAxis.normalize();\r\n\r\n // Eye angles\r\n const ex = -Vector3.Dot(xAxis, eye);\r\n const ey = -Vector3.Dot(yAxis, eye);\r\n const ez = -Vector3.Dot(zAxis, eye);\r\n\r\n Matrix.FromValuesToRef(xAxis._x, yAxis._x, zAxis._x, 0.0, xAxis._y, yAxis._y, zAxis._y, 0.0, xAxis._z, yAxis._z, zAxis._z, 0.0, ex, ey, ez, 1.0, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\r\n * This function generates a matrix suitable for a left handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#66\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @returns the new matrix\r\n */\r\n public static LookDirectionLH(forward: DeepImmutable, up: DeepImmutable): Matrix {\r\n const result = new Matrix();\r\n Matrix.LookDirectionLHToRef(forward, up, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\r\n * This function generates a matrix suitable for a left handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#67\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static LookDirectionLHToRef(forward: DeepImmutable, up: DeepImmutable, result: T): T {\r\n const back = MathTmp.Vector3[0];\r\n back.copyFrom(forward);\r\n back.scaleInPlace(-1);\r\n const left = MathTmp.Vector3[1];\r\n Vector3.CrossToRef(up, back, left);\r\n\r\n // Generate the rotation matrix.\r\n Matrix.FromValuesToRef(left._x, left._y, left._z, 0.0, up._x, up._y, up._z, 0.0, back._x, back._y, back._z, 0.0, 0, 0, 0, 1.0, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\r\n * This function generates a matrix suitable for a right handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#68\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @returns the new matrix\r\n */\r\n public static LookDirectionRH(forward: DeepImmutable, up: DeepImmutable): Matrix {\r\n const result = new Matrix();\r\n Matrix.LookDirectionRHToRef(forward, up, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given \"result\" Matrix to a matrix that transforms vertices from world space to camera space. It takes two vectors as arguments that together describe the orientation of the camera. The position is assumed to be at the origin (0,0,0)\r\n * This function generates a matrix suitable for a right handed coordinate system\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#69\r\n * @param forward defines the forward direction - Must be normalized and orthogonal to up.\r\n * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static LookDirectionRHToRef(forward: DeepImmutable, up: DeepImmutable, result: T): T {\r\n const right = MathTmp.Vector3[2];\r\n Vector3.CrossToRef(up, forward, right);\r\n\r\n // Generate the rotation matrix.\r\n Matrix.FromValuesToRef(right._x, right._y, right._z, 0.0, up._x, up._y, up._z, 0.0, forward._x, forward._y, forward._z, 0.0, 0, 0, 0, 1.0, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Create a left-handed orthographic projection matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#70\r\n * @param width defines the viewport width\r\n * @param height defines the viewport height\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @returns a new matrix as a left-handed orthographic projection matrix\r\n */\r\n public static OrthoLH(width: number, height: number, znear: number, zfar: number, halfZRange?: boolean): Matrix {\r\n const matrix = new Matrix();\r\n Matrix.OrthoLHToRef(width, height, znear, zfar, matrix, halfZRange);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Store a left-handed orthographic projection to a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#71\r\n * @param width defines the viewport width\r\n * @param height defines the viewport height\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param result defines the target matrix\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @returns result input\r\n */\r\n public static OrthoLHToRef(width: number, height: number, znear: number, zfar: number, result: T, halfZRange?: boolean): T {\r\n const n = znear;\r\n const f = zfar;\r\n\r\n const a = 2.0 / width;\r\n const b = 2.0 / height;\r\n const c = 2.0 / (f - n);\r\n const d = -(f + n) / (f - n);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, 0.0, 0.0, d, 1.0, result);\r\n\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n\r\n result._updateIdentityStatus(a === 1 && b === 1 && c === 1 && d === 0);\r\n return result;\r\n }\r\n\r\n /**\r\n * Create a left-handed orthographic projection matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#72\r\n * @param left defines the viewport left coordinate\r\n * @param right defines the viewport right coordinate\r\n * @param bottom defines the viewport bottom coordinate\r\n * @param top defines the viewport top coordinate\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @returns a new matrix as a left-handed orthographic projection matrix\r\n */\r\n public static OrthoOffCenterLH(left: number, right: number, bottom: number, top: number, znear: number, zfar: number, halfZRange?: boolean): Matrix {\r\n const matrix = new Matrix();\r\n Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, matrix, halfZRange);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Stores a left-handed orthographic projection into a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#73\r\n * @param left defines the viewport left coordinate\r\n * @param right defines the viewport right coordinate\r\n * @param bottom defines the viewport bottom coordinate\r\n * @param top defines the viewport top coordinate\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param result defines the target matrix\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @returns result input\r\n */\r\n public static OrthoOffCenterLHToRef(\r\n left: number,\r\n right: number,\r\n bottom: number,\r\n top: number,\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n halfZRange?: boolean\r\n ): T {\r\n const n = znear;\r\n const f = zfar;\r\n\r\n const a = 2.0 / (right - left);\r\n const b = 2.0 / (top - bottom);\r\n const c = 2.0 / (f - n);\r\n const d = -(f + n) / (f - n);\r\n const i0 = (left + right) / (left - right);\r\n const i1 = (top + bottom) / (bottom - top);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, i0, i1, d, 1.0, result);\r\n\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a right-handed orthographic projection matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#76\r\n * @param left defines the viewport left coordinate\r\n * @param right defines the viewport right coordinate\r\n * @param bottom defines the viewport bottom coordinate\r\n * @param top defines the viewport top coordinate\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @returns a new matrix as a right-handed orthographic projection matrix\r\n */\r\n public static OrthoOffCenterRH(left: number, right: number, bottom: number, top: number, znear: number, zfar: number, halfZRange?: boolean): Matrix {\r\n const matrix = new Matrix();\r\n Matrix.OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, matrix, halfZRange);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Stores a right-handed orthographic projection into a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#77\r\n * @param left defines the viewport left coordinate\r\n * @param right defines the viewport right coordinate\r\n * @param bottom defines the viewport bottom coordinate\r\n * @param top defines the viewport top coordinate\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param result defines the target matrix\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @returns result input\r\n */\r\n public static OrthoOffCenterRHToRef(\r\n left: number,\r\n right: number,\r\n bottom: number,\r\n top: number,\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n halfZRange?: boolean\r\n ): T {\r\n Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange);\r\n result._m[10] *= -1; // No need to call markAsUpdated as previous function already called it and let _isIdentityDirty to true\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a left-handed perspective projection matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#85\r\n * @param width defines the viewport width\r\n * @param height defines the viewport height\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @returns a new matrix as a left-handed perspective projection matrix\r\n */\r\n public static PerspectiveLH(width: number, height: number, znear: number, zfar: number, halfZRange?: boolean, projectionPlaneTilt: number = 0): Matrix {\r\n const matrix = new Matrix();\r\n\r\n const n = znear;\r\n const f = zfar;\r\n\r\n const a = (2.0 * n) / width;\r\n const b = (2.0 * n) / height;\r\n const c = (f + n) / (f - n);\r\n const d = (-2.0 * f * n) / (f - n);\r\n const rot = Math.tan(projectionPlaneTilt);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, c, 1.0, 0.0, 0.0, d, 0.0, matrix);\r\n\r\n if (halfZRange) {\r\n matrix.multiplyToRef(mtxConvertNDCToHalfZRange, matrix);\r\n }\r\n\r\n matrix._updateIdentityStatus(false);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Creates a left-handed perspective projection matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#78\r\n * @param fov defines the horizontal field of view\r\n * @param aspect defines the aspect ratio\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\r\n * @returns a new matrix as a left-handed perspective projection matrix\r\n */\r\n public static PerspectiveFovLH(\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0,\r\n reverseDepthBufferMode: boolean = false\r\n ): Matrix {\r\n const matrix = new Matrix();\r\n Matrix.PerspectiveFovLHToRef(fov, aspect, znear, zfar, matrix, true, halfZRange, projectionPlaneTilt, reverseDepthBufferMode);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Stores a left-handed perspective projection into a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#81\r\n * @param fov defines the horizontal field of view\r\n * @param aspect defines the aspect ratio\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\r\n * @param result defines the target matrix\r\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\r\n * @returns result input\r\n */\r\n public static PerspectiveFovLHToRef(\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n isVerticalFovFixed = true,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0,\r\n reverseDepthBufferMode: boolean = false\r\n ): T {\r\n const n = znear;\r\n const f = zfar;\r\n\r\n const t = 1.0 / Math.tan(fov * 0.5);\r\n const a = isVerticalFovFixed ? t / aspect : t;\r\n const b = isVerticalFovFixed ? t : t * aspect;\r\n const c = reverseDepthBufferMode && n === 0 ? -1 : f !== 0 ? (f + n) / (f - n) : 1;\r\n const d = reverseDepthBufferMode && n === 0 ? 2 * f : f !== 0 ? (-2.0 * f * n) / (f - n) : -2 * n;\r\n const rot = Math.tan(projectionPlaneTilt);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, c, 1.0, 0.0, 0.0, d, 0.0, result);\r\n\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n\r\n result._updateIdentityStatus(false);\r\n return result;\r\n }\r\n\r\n /**\r\n * Stores a left-handed perspective projection into a given matrix with depth reversed\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#89\r\n * @param fov defines the horizontal field of view\r\n * @param aspect defines the aspect ratio\r\n * @param znear defines the near clip plane\r\n * @param zfar not used as infinity is used as far clip\r\n * @param result defines the target matrix\r\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @returns result input\r\n */\r\n public static PerspectiveFovReverseLHToRef(\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n isVerticalFovFixed = true,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0\r\n ): T {\r\n const t = 1.0 / Math.tan(fov * 0.5);\r\n const a = isVerticalFovFixed ? t / aspect : t;\r\n const b = isVerticalFovFixed ? t : t * aspect;\r\n const rot = Math.tan(projectionPlaneTilt);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, -znear, 1.0, 0.0, 0.0, 1.0, 0.0, result);\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n result._updateIdentityStatus(false);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a right-handed perspective projection matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#83\r\n * @param fov defines the horizontal field of view\r\n * @param aspect defines the aspect ratio\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\r\n * @returns a new matrix as a right-handed perspective projection matrix\r\n */\r\n public static PerspectiveFovRH(\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0,\r\n reverseDepthBufferMode: boolean = false\r\n ): Matrix {\r\n const matrix = new Matrix();\r\n Matrix.PerspectiveFovRHToRef(fov, aspect, znear, zfar, matrix, true, halfZRange, projectionPlaneTilt, reverseDepthBufferMode);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Stores a right-handed perspective projection into a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#84\r\n * @param fov defines the horizontal field of view\r\n * @param aspect defines the aspect ratio\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane. If 0, assume we are in \"infinite zfar\" mode\r\n * @param result defines the target matrix\r\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)\r\n * @returns result input\r\n */\r\n public static PerspectiveFovRHToRef(\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n isVerticalFovFixed = true,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0,\r\n reverseDepthBufferMode: boolean = false\r\n ): T {\r\n //alternatively this could be expressed as:\r\n // m = PerspectiveFovLHToRef\r\n // m[10] *= -1.0;\r\n // m[11] *= -1.0;\r\n\r\n const n = znear;\r\n const f = zfar;\r\n\r\n const t = 1.0 / Math.tan(fov * 0.5);\r\n const a = isVerticalFovFixed ? t / aspect : t;\r\n const b = isVerticalFovFixed ? t : t * aspect;\r\n const c = reverseDepthBufferMode && n === 0 ? 1 : f !== 0 ? -(f + n) / (f - n) : -1;\r\n const d = reverseDepthBufferMode && n === 0 ? 2 * f : f !== 0 ? (-2 * f * n) / (f - n) : -2 * n;\r\n const rot = Math.tan(projectionPlaneTilt);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, c, -1.0, 0.0, 0.0, d, 0.0, result);\r\n\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n\r\n result._updateIdentityStatus(false);\r\n return result;\r\n }\r\n\r\n /**\r\n * Stores a right-handed perspective projection into a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#90\r\n * @param fov defines the horizontal field of view\r\n * @param aspect defines the aspect ratio\r\n * @param znear defines the near clip plane\r\n * @param zfar not used as infinity is used as far clip\r\n * @param result defines the target matrix\r\n * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @returns result input\r\n */\r\n public static PerspectiveFovReverseRHToRef(\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n isVerticalFovFixed = true,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0\r\n ): T {\r\n const t = 1.0 / Math.tan(fov * 0.5);\r\n const a = isVerticalFovFixed ? t / aspect : t;\r\n const b = isVerticalFovFixed ? t : t * aspect;\r\n const rot = Math.tan(projectionPlaneTilt);\r\n\r\n Matrix.FromValuesToRef(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, rot, 0.0, 0.0, -znear, -1.0, 0.0, 0.0, -1.0, 0.0, result);\r\n\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n\r\n result._updateIdentityStatus(false);\r\n return result;\r\n }\r\n\r\n /**\r\n * Stores a perspective projection for WebVR info a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#92\r\n * @param fov defines the field of view\r\n * @param fov.upDegrees\r\n * @param fov.downDegrees\r\n * @param fov.leftDegrees\r\n * @param fov.rightDegrees\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @param result defines the target matrix\r\n * @param rightHanded defines if the matrix must be in right-handed mode (false by default)\r\n * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)\r\n * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)\r\n * @returns result input\r\n */\r\n public static PerspectiveFovWebVRToRef(\r\n fov: { upDegrees: number; downDegrees: number; leftDegrees: number; rightDegrees: number },\r\n znear: number,\r\n zfar: number,\r\n result: T,\r\n rightHanded = false,\r\n halfZRange?: boolean,\r\n projectionPlaneTilt: number = 0\r\n ): T {\r\n const rightHandedFactor = rightHanded ? -1 : 1;\r\n\r\n const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);\r\n const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);\r\n const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);\r\n const rightTan = Math.tan((fov.rightDegrees * Math.PI) / 180.0);\r\n const xScale = 2.0 / (leftTan + rightTan);\r\n const yScale = 2.0 / (upTan + downTan);\r\n const rot = Math.tan(projectionPlaneTilt);\r\n\r\n const m = result._m;\r\n m[0] = xScale;\r\n m[1] = m[2] = m[3] = m[4] = 0.0;\r\n m[5] = yScale;\r\n m[6] = 0.0;\r\n m[7] = rot;\r\n m[8] = (leftTan - rightTan) * xScale * 0.5;\r\n m[9] = -((upTan - downTan) * yScale * 0.5);\r\n m[10] = -zfar / (znear - zfar);\r\n m[11] = 1.0 * rightHandedFactor;\r\n m[12] = m[13] = m[15] = 0.0;\r\n m[14] = -(2.0 * zfar * znear) / (zfar - znear);\r\n\r\n if (halfZRange) {\r\n result.multiplyToRef(mtxConvertNDCToHalfZRange, result);\r\n }\r\n\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n\r\n /**\r\n * Computes a complete transformation matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#113\r\n * @param viewport defines the viewport to use\r\n * @param world defines the world matrix\r\n * @param view defines the view matrix\r\n * @param projection defines the projection matrix\r\n * @param zmin defines the near clip plane\r\n * @param zmax defines the far clip plane\r\n * @returns the transformation matrix\r\n */\r\n public static GetFinalMatrix(\r\n viewport: DeepImmutable,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable,\r\n zmin: number,\r\n zmax: number\r\n ): T {\r\n const cw = viewport.width;\r\n const ch = viewport.height;\r\n const cx = viewport.x;\r\n const cy = viewport.y;\r\n\r\n const viewportMatrix = Matrix.FromValues(cw / 2.0, 0.0, 0.0, 0.0, 0.0, -ch / 2.0, 0.0, 0.0, 0.0, 0.0, zmax - zmin, 0.0, cx + cw / 2.0, ch / 2.0 + cy, zmin, 1.0);\r\n\r\n const matrix = new (world.constructor as MatrixConstructor)();\r\n world.multiplyToRef(view, matrix);\r\n matrix.multiplyToRef(projection, matrix);\r\n return matrix.multiplyToRef(viewportMatrix, matrix);\r\n }\r\n\r\n /**\r\n * Extracts a 2x2 matrix from a given matrix and store the result in a Float32Array\r\n * @param matrix defines the matrix to use\r\n * @returns a new Float32Array array with 4 elements : the 2x2 matrix extracted from the given matrix\r\n */\r\n public static GetAsMatrix2x2(matrix: DeepImmutable): Float32Array | Array {\r\n const m = matrix.m;\r\n const arr = [m[0], m[1], m[4], m[5]];\r\n return PerformanceConfigurator.MatrixUse64Bits ? arr : new Float32Array(arr);\r\n }\r\n /**\r\n * Extracts a 3x3 matrix from a given matrix and store the result in a Float32Array\r\n * @param matrix defines the matrix to use\r\n * @returns a new Float32Array array with 9 elements : the 3x3 matrix extracted from the given matrix\r\n */\r\n public static GetAsMatrix3x3(matrix: DeepImmutable): Float32Array | Array {\r\n const m = matrix.m;\r\n const arr = [m[0], m[1], m[2], m[4], m[5], m[6], m[8], m[9], m[10]];\r\n return PerformanceConfigurator.MatrixUse64Bits ? arr : new Float32Array(arr);\r\n }\r\n\r\n /**\r\n * Compute the transpose of a given matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#111\r\n * @param matrix defines the matrix to transpose\r\n * @returns the new matrix\r\n */\r\n public static Transpose(matrix: DeepImmutable): T {\r\n const result = new (matrix.constructor as MatrixConstructor)();\r\n Matrix.TransposeToRef(matrix, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Compute the transpose of a matrix and store it in a target matrix\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#112\r\n * @param matrix defines the matrix to transpose\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static TransposeToRef(matrix: DeepImmutable, result: T): T {\r\n const rm = result._m;\r\n const mm = matrix.m;\r\n rm[0] = mm[0];\r\n rm[1] = mm[4];\r\n rm[2] = mm[8];\r\n rm[3] = mm[12];\r\n\r\n rm[4] = mm[1];\r\n rm[5] = mm[5];\r\n rm[6] = mm[9];\r\n rm[7] = mm[13];\r\n\r\n rm[8] = mm[2];\r\n rm[9] = mm[6];\r\n rm[10] = mm[10];\r\n rm[11] = mm[14];\r\n\r\n rm[12] = mm[3];\r\n rm[13] = mm[7];\r\n rm[14] = mm[11];\r\n rm[15] = mm[15];\r\n\r\n result.markAsUpdated();\r\n\r\n // identity-ness does not change when transposing\r\n result._updateIdentityStatus((matrix as Matrix)._isIdentity, (matrix as Matrix)._isIdentityDirty);\r\n return result;\r\n }\r\n\r\n /**\r\n * Computes a reflection matrix from a plane\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#87\r\n * @param plane defines the reflection plane\r\n * @returns a new matrix\r\n */\r\n public static Reflection(plane: DeepImmutable): Matrix {\r\n const matrix = new Matrix();\r\n Matrix.ReflectionToRef(plane, matrix);\r\n return matrix;\r\n }\r\n\r\n /**\r\n * Computes a reflection matrix from a plane\r\n * Example Playground - https://playground.babylonjs.com/#AV9X17#88\r\n * @param plane defines the reflection plane\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static ReflectionToRef(plane: DeepImmutable, result: T): T {\r\n plane.normalize();\r\n const x = plane.normal.x;\r\n const y = plane.normal.y;\r\n const z = plane.normal.z;\r\n const temp = -2 * x;\r\n const temp2 = -2 * y;\r\n const temp3 = -2 * z;\r\n Matrix.FromValuesToRef(\r\n temp * x + 1,\r\n temp2 * x,\r\n temp3 * x,\r\n 0.0,\r\n temp * y,\r\n temp2 * y + 1,\r\n temp3 * y,\r\n 0.0,\r\n temp * z,\r\n temp2 * z,\r\n temp3 * z + 1,\r\n 0.0,\r\n temp * plane.d,\r\n temp2 * plane.d,\r\n temp3 * plane.d,\r\n 1.0,\r\n result\r\n );\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the given matrix as a rotation matrix composed from the 3 left handed axes\r\n * @param xaxis defines the value of the 1st axis\r\n * @param yaxis defines the value of the 2nd axis\r\n * @param zaxis defines the value of the 3rd axis\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static FromXYZAxesToRef(xaxis: DeepImmutable, yaxis: DeepImmutable, zaxis: DeepImmutable, result: T): T {\r\n Matrix.FromValuesToRef(xaxis._x, xaxis._y, xaxis._z, 0.0, yaxis._x, yaxis._y, yaxis._z, 0.0, zaxis._x, zaxis._y, zaxis._z, 0.0, 0.0, 0.0, 0.0, 1.0, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a rotation matrix from a quaternion and stores it in a target matrix\r\n * @param quat defines the quaternion to use\r\n * @param result defines the target matrix\r\n * @returns result input\r\n */\r\n public static FromQuaternionToRef(quat: DeepImmutable, result: T): T {\r\n const xx = quat._x * quat._x;\r\n const yy = quat._y * quat._y;\r\n const zz = quat._z * quat._z;\r\n const xy = quat._x * quat._y;\r\n const zw = quat._z * quat._w;\r\n const zx = quat._z * quat._x;\r\n const yw = quat._y * quat._w;\r\n const yz = quat._y * quat._z;\r\n const xw = quat._x * quat._w;\r\n\r\n result._m[0] = 1.0 - 2.0 * (yy + zz);\r\n result._m[1] = 2.0 * (xy + zw);\r\n result._m[2] = 2.0 * (zx - yw);\r\n result._m[3] = 0.0;\r\n\r\n result._m[4] = 2.0 * (xy - zw);\r\n result._m[5] = 1.0 - 2.0 * (zz + xx);\r\n result._m[6] = 2.0 * (yz + xw);\r\n result._m[7] = 0.0;\r\n\r\n result._m[8] = 2.0 * (zx + yw);\r\n result._m[9] = 2.0 * (yz - xw);\r\n result._m[10] = 1.0 - 2.0 * (yy + xx);\r\n result._m[11] = 0.0;\r\n\r\n result._m[12] = 0.0;\r\n result._m[13] = 0.0;\r\n result._m[14] = 0.0;\r\n result._m[15] = 1.0;\r\n\r\n result.markAsUpdated();\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n * Same as Tmp but not exported to keep it only for math functions to avoid conflicts\r\n */\r\nclass MathTmp {\r\n public static Vector3 = ArrayTools.BuildTuple(11, Vector3.Zero);\r\n public static Matrix = ArrayTools.BuildTuple(2, Matrix.Identity);\r\n public static Quaternion = ArrayTools.BuildTuple(3, Quaternion.Zero);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class TmpVectors {\r\n public static Vector2 = ArrayTools.BuildTuple(3, Vector2.Zero); // 3 temp Vector2 at once should be enough\r\n public static Vector3 = ArrayTools.BuildTuple(13, Vector3.Zero); // 13 temp Vector3 at once should be enough\r\n public static Vector4 = ArrayTools.BuildTuple(3, Vector4.Zero); // 3 temp Vector4 at once should be enough\r\n public static Quaternion = ArrayTools.BuildTuple(2, Quaternion.Zero); // 2 temp Quaternion at once should be enough\r\n public static Matrix = ArrayTools.BuildTuple(8, Matrix.Identity); // 8 temp Matrices at once should be enough\r\n}\r\n\r\nRegisterClass(\"BABYLON.Vector2\", Vector2);\r\nRegisterClass(\"BABYLON.Vector3\", Vector3);\r\nRegisterClass(\"BABYLON.Vector4\", Vector4);\r\nRegisterClass(\"BABYLON.Matrix\", Matrix);\r\n\r\nconst mtxConvertNDCToHalfZRange = Matrix.FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1);\r\n","/**\r\n * @internal\r\n */\r\nexport function _WarnImport(name: string) {\r\n return `${name} needs to be imported before as it contains a side-effect required by your code.`;\r\n}\r\n","import type { DeepImmutable, FloatArray } from \"../types\";\r\nimport { Scalar } from \"./math.scalar\";\r\nimport { ToLinearSpace, ToGammaSpace } from \"./math.constants\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\nfunction colorChannelToLinearSpace(color: number): number {\r\n return Math.pow(color, ToLinearSpace);\r\n}\r\n\r\nfunction colorChannelToLinearSpaceExact(color: number): number {\r\n if (color <= 0.04045) {\r\n return 0.0773993808 * color;\r\n }\r\n return Math.pow(0.947867299 * (color + 0.055), 2.4);\r\n}\r\n\r\nfunction colorChannelToGammaSpace(color: number): number {\r\n return Math.pow(color, ToGammaSpace);\r\n}\r\n\r\nfunction colorChannelToGammaSpaceExact(color: number): number {\r\n if (color <= 0.0031308) {\r\n return 12.92 * color;\r\n }\r\n return 1.055 * Math.pow(color, 0.41666) - 0.055;\r\n}\r\n\r\n/**\r\n * Class used to hold a RGB color\r\n */\r\nexport class Color3 {\r\n /**\r\n * Creates a new Color3 object from red, green, blue values, all between 0 and 1\r\n * @param r defines the red component (between 0 and 1, default is 0)\r\n * @param g defines the green component (between 0 and 1, default is 0)\r\n * @param b defines the blue component (between 0 and 1, default is 0)\r\n */\r\n constructor(\r\n /**\r\n * Defines the red component (between 0 and 1, default is 0)\r\n */\r\n public r: number = 0,\r\n /**\r\n * Defines the green component (between 0 and 1, default is 0)\r\n */\r\n public g: number = 0,\r\n /**\r\n * Defines the blue component (between 0 and 1, default is 0)\r\n */\r\n public b: number = 0\r\n ) {}\r\n\r\n /**\r\n * Creates a string with the Color3 current values\r\n * @returns the string representation of the Color3 object\r\n */\r\n public toString(): string {\r\n return \"{R: \" + this.r + \" G:\" + this.g + \" B:\" + this.b + \"}\";\r\n }\r\n\r\n /**\r\n * Returns the string \"Color3\"\r\n * @returns \"Color3\"\r\n */\r\n public getClassName(): string {\r\n return \"Color3\";\r\n }\r\n\r\n /**\r\n * Compute the Color3 hash code\r\n * @returns an unique number that can be used to hash Color3 objects\r\n */\r\n public getHashCode(): number {\r\n let hash = (this.r * 255) | 0;\r\n hash = (hash * 397) ^ ((this.g * 255) | 0);\r\n hash = (hash * 397) ^ ((this.b * 255) | 0);\r\n return hash;\r\n }\r\n\r\n // Operators\r\n\r\n /**\r\n * Stores in the given array from the given starting index the red, green, blue values as successive elements\r\n * @param array defines the array where to store the r,g,b components\r\n * @param index defines an optional index in the target array to define where to start storing values\r\n * @returns the current Color3 object\r\n */\r\n public toArray(array: FloatArray, index: number = 0): Color3 {\r\n array[index] = this.r;\r\n array[index + 1] = this.g;\r\n array[index + 2] = this.b;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Update the current color with values stored in an array from the starting index of the given array\r\n * @param array defines the source array\r\n * @param offset defines an offset in the source array\r\n * @returns the current Color3 object\r\n */\r\n public fromArray(array: DeepImmutable>, offset: number = 0): Color3 {\r\n Color3.FromArrayToRef(array, offset, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Color4 object from the current Color3 and the given alpha\r\n * @param alpha defines the alpha component on the new Color4 object (default is 1)\r\n * @returns a new Color4 object\r\n */\r\n public toColor4(alpha: number = 1): Color4 {\r\n return new Color4(this.r, this.g, this.b, alpha);\r\n }\r\n\r\n /**\r\n * Returns a new array populated with 3 numeric elements : red, green and blue values\r\n * @returns the new array\r\n */\r\n public asArray(): number[] {\r\n return [this.r, this.g, this.b];\r\n }\r\n\r\n /**\r\n * Returns the luminance value\r\n * @returns a float value\r\n */\r\n public toLuminance(): number {\r\n return this.r * 0.3 + this.g * 0.59 + this.b * 0.11;\r\n }\r\n\r\n /**\r\n * Multiply each Color3 rgb values by the given Color3 rgb values in a new Color3 object\r\n * @param otherColor defines the second operand\r\n * @returns the new Color3 object\r\n */\r\n public multiply(otherColor: DeepImmutable): Color3 {\r\n return new Color3(this.r * otherColor.r, this.g * otherColor.g, this.b * otherColor.b);\r\n }\r\n\r\n /**\r\n * Multiply the rgb values of the Color3 and the given Color3 and stores the result in the object \"result\"\r\n * @param otherColor defines the second operand\r\n * @param result defines the Color3 object where to store the result\r\n * @returns the current Color3\r\n */\r\n public multiplyToRef(otherColor: DeepImmutable, result: Color3): Color3 {\r\n result.r = this.r * otherColor.r;\r\n result.g = this.g * otherColor.g;\r\n result.b = this.b * otherColor.b;\r\n return this;\r\n }\r\n\r\n /**\r\n * Determines equality between Color3 objects\r\n * @param otherColor defines the second operand\r\n * @returns true if the rgb values are equal to the given ones\r\n */\r\n public equals(otherColor: DeepImmutable): boolean {\r\n return otherColor && this.r === otherColor.r && this.g === otherColor.g && this.b === otherColor.b;\r\n }\r\n\r\n /**\r\n * Determines equality between the current Color3 object and a set of r,b,g values\r\n * @param r defines the red component to check\r\n * @param g defines the green component to check\r\n * @param b defines the blue component to check\r\n * @returns true if the rgb values are equal to the given ones\r\n */\r\n public equalsFloats(r: number, g: number, b: number): boolean {\r\n return this.r === r && this.g === g && this.b === b;\r\n }\r\n\r\n /**\r\n * Creates a new Color3 with the current Color3 values multiplied by scale\r\n * @param scale defines the scaling factor to apply\r\n * @returns a new Color3 object\r\n */\r\n public scale(scale: number): Color3 {\r\n return new Color3(this.r * scale, this.g * scale, this.b * scale);\r\n }\r\n\r\n /**\r\n * Multiplies the Color3 values by the float \"scale\"\r\n * @param scale defines the scaling factor to apply\r\n * @returns the current updated Color3\r\n */\r\n public scaleInPlace(scale: number): Color3 {\r\n this.r *= scale;\r\n this.g *= scale;\r\n this.b *= scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiplies the rgb values by scale and stores the result into \"result\"\r\n * @param scale defines the scaling factor\r\n * @param result defines the Color3 object where to store the result\r\n * @returns the unmodified current Color3\r\n */\r\n public scaleToRef(scale: number, result: Color3): Color3 {\r\n result.r = this.r * scale;\r\n result.g = this.g * scale;\r\n result.b = this.b * scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Scale the current Color3 values by a factor and add the result to a given Color3\r\n * @param scale defines the scale factor\r\n * @param result defines color to store the result into\r\n * @returns the unmodified current Color3\r\n */\r\n public scaleAndAddToRef(scale: number, result: Color3): Color3 {\r\n result.r += this.r * scale;\r\n result.g += this.g * scale;\r\n result.b += this.b * scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Clamps the rgb values by the min and max values and stores the result into \"result\"\r\n * @param min defines minimum clamping value (default is 0)\r\n * @param max defines maximum clamping value (default is 1)\r\n * @param result defines color to store the result into\r\n * @returns the original Color3\r\n */\r\n public clampToRef(min: number = 0, max: number = 1, result: Color3): Color3 {\r\n result.r = Scalar.Clamp(this.r, min, max);\r\n result.g = Scalar.Clamp(this.g, min, max);\r\n result.b = Scalar.Clamp(this.b, min, max);\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a new Color3 set with the added values of the current Color3 and of the given one\r\n * @param otherColor defines the second operand\r\n * @returns the new Color3\r\n */\r\n public add(otherColor: DeepImmutable): Color3 {\r\n return new Color3(this.r + otherColor.r, this.g + otherColor.g, this.b + otherColor.b);\r\n }\r\n\r\n /**\r\n * Stores the result of the addition of the current Color3 and given one rgb values into \"result\"\r\n * @param otherColor defines the second operand\r\n * @param result defines Color3 object to store the result into\r\n * @returns the unmodified current Color3\r\n */\r\n public addToRef(otherColor: DeepImmutable, result: Color3): Color3 {\r\n result.r = this.r + otherColor.r;\r\n result.g = this.g + otherColor.g;\r\n result.b = this.b + otherColor.b;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Color3 set with the subtracted values of the given one from the current Color3\r\n * @param otherColor defines the second operand\r\n * @returns the new Color3\r\n */\r\n public subtract(otherColor: DeepImmutable): Color3 {\r\n return new Color3(this.r - otherColor.r, this.g - otherColor.g, this.b - otherColor.b);\r\n }\r\n\r\n /**\r\n * Stores the result of the subtraction of given one from the current Color3 rgb values into \"result\"\r\n * @param otherColor defines the second operand\r\n * @param result defines Color3 object to store the result into\r\n * @returns the unmodified current Color3\r\n */\r\n public subtractToRef(otherColor: DeepImmutable, result: Color3): Color3 {\r\n result.r = this.r - otherColor.r;\r\n result.g = this.g - otherColor.g;\r\n result.b = this.b - otherColor.b;\r\n return this;\r\n }\r\n\r\n /**\r\n * Copy the current object\r\n * @returns a new Color3 copied the current one\r\n */\r\n public clone(): Color3 {\r\n return new Color3(this.r, this.g, this.b);\r\n }\r\n\r\n /**\r\n * Copies the rgb values from the source in the current Color3\r\n * @param source defines the source Color3 object\r\n * @returns the updated Color3 object\r\n */\r\n public copyFrom(source: DeepImmutable): Color3 {\r\n this.r = source.r;\r\n this.g = source.g;\r\n this.b = source.b;\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the Color3 rgb values from the given floats\r\n * @param r defines the red component to read from\r\n * @param g defines the green component to read from\r\n * @param b defines the blue component to read from\r\n * @returns the current Color3 object\r\n */\r\n public copyFromFloats(r: number, g: number, b: number): Color3 {\r\n this.r = r;\r\n this.g = g;\r\n this.b = b;\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the Color3 rgb values from the given floats\r\n * @param r defines the red component to read from\r\n * @param g defines the green component to read from\r\n * @param b defines the blue component to read from\r\n * @returns the current Color3 object\r\n */\r\n public set(r: number, g: number, b: number): Color3 {\r\n return this.copyFromFloats(r, g, b);\r\n }\r\n\r\n /**\r\n * Compute the Color3 hexadecimal code as a string\r\n * @returns a string containing the hexadecimal representation of the Color3 object\r\n */\r\n public toHexString(): string {\r\n const intR = Math.round(this.r * 255);\r\n const intG = Math.round(this.g * 255);\r\n const intB = Math.round(this.b * 255);\r\n return \"#\" + Scalar.ToHex(intR) + Scalar.ToHex(intG) + Scalar.ToHex(intB);\r\n }\r\n\r\n /**\r\n * Converts current color in rgb space to HSV values\r\n * @returns a new color3 representing the HSV values\r\n */\r\n public toHSV(): Color3 {\r\n const result = new Color3();\r\n\r\n this.toHSVToRef(result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Converts current color in rgb space to HSV values\r\n * @param result defines the Color3 where to store the HSV values\r\n */\r\n public toHSVToRef(result: Color3) {\r\n const r = this.r;\r\n const g = this.g;\r\n const b = this.b;\r\n\r\n const max = Math.max(r, g, b);\r\n const min = Math.min(r, g, b);\r\n let h = 0;\r\n let s = 0;\r\n const v = max;\r\n\r\n const dm = max - min;\r\n\r\n if (max !== 0) {\r\n s = dm / max;\r\n }\r\n\r\n if (max != min) {\r\n if (max == r) {\r\n h = (g - b) / dm;\r\n if (g < b) {\r\n h += 6;\r\n }\r\n } else if (max == g) {\r\n h = (b - r) / dm + 2;\r\n } else if (max == b) {\r\n h = (r - g) / dm + 4;\r\n }\r\n h *= 60;\r\n }\r\n\r\n result.r = h;\r\n result.g = s;\r\n result.b = v;\r\n }\r\n\r\n /**\r\n * Computes a new Color3 converted from the current one to linear space\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns a new Color3 object\r\n */\r\n public toLinearSpace(exact = false): Color3 {\r\n const convertedColor = new Color3();\r\n this.toLinearSpaceToRef(convertedColor, exact);\r\n return convertedColor;\r\n }\r\n\r\n /**\r\n * Converts the Color3 values to linear space and stores the result in \"convertedColor\"\r\n * @param convertedColor defines the Color3 object where to store the linear space version\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns the unmodified Color3\r\n */\r\n public toLinearSpaceToRef(convertedColor: Color3, exact = false): Color3 {\r\n if (exact) {\r\n convertedColor.r = colorChannelToLinearSpaceExact(this.r);\r\n convertedColor.g = colorChannelToLinearSpaceExact(this.g);\r\n convertedColor.b = colorChannelToLinearSpaceExact(this.b);\r\n } else {\r\n convertedColor.r = colorChannelToLinearSpace(this.r);\r\n convertedColor.g = colorChannelToLinearSpace(this.g);\r\n convertedColor.b = colorChannelToLinearSpace(this.b);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Computes a new Color3 converted from the current one to gamma space\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns a new Color3 object\r\n */\r\n public toGammaSpace(exact = false): Color3 {\r\n const convertedColor = new Color3();\r\n this.toGammaSpaceToRef(convertedColor, exact);\r\n return convertedColor;\r\n }\r\n\r\n /**\r\n * Converts the Color3 values to gamma space and stores the result in \"convertedColor\"\r\n * @param convertedColor defines the Color3 object where to store the gamma space version\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns the unmodified Color3\r\n */\r\n public toGammaSpaceToRef(convertedColor: Color3, exact = false): Color3 {\r\n if (exact) {\r\n convertedColor.r = colorChannelToGammaSpaceExact(this.r);\r\n convertedColor.g = colorChannelToGammaSpaceExact(this.g);\r\n convertedColor.b = colorChannelToGammaSpaceExact(this.b);\r\n } else {\r\n convertedColor.r = colorChannelToGammaSpace(this.r);\r\n convertedColor.g = colorChannelToGammaSpace(this.g);\r\n convertedColor.b = colorChannelToGammaSpace(this.b);\r\n }\r\n return this;\r\n }\r\n\r\n // Statics\r\n\r\n private static _BlackReadOnly = Color3.Black() as DeepImmutable;\r\n\r\n /**\r\n * Converts Hue, saturation and value to a Color3 (RGB)\r\n * @param hue defines the hue (value between 0 and 360)\r\n * @param saturation defines the saturation (value between 0 and 1)\r\n * @param value defines the value (value between 0 and 1)\r\n * @param result defines the Color3 where to store the RGB values\r\n */\r\n public static HSVtoRGBToRef(hue: number, saturation: number, value: number, result: Color3) {\r\n const chroma = value * saturation;\r\n const h = hue / 60;\r\n const x = chroma * (1 - Math.abs((h % 2) - 1));\r\n let r = 0;\r\n let g = 0;\r\n let b = 0;\r\n\r\n if (h >= 0 && h <= 1) {\r\n r = chroma;\r\n g = x;\r\n } else if (h >= 1 && h <= 2) {\r\n r = x;\r\n g = chroma;\r\n } else if (h >= 2 && h <= 3) {\r\n g = chroma;\r\n b = x;\r\n } else if (h >= 3 && h <= 4) {\r\n g = x;\r\n b = chroma;\r\n } else if (h >= 4 && h <= 5) {\r\n r = x;\r\n b = chroma;\r\n } else if (h >= 5 && h <= 6) {\r\n r = chroma;\r\n b = x;\r\n }\r\n\r\n const m = value - chroma;\r\n result.set(r + m, g + m, b + m);\r\n }\r\n\r\n /**\r\n * Converts Hue, saturation and value to a new Color3 (RGB)\r\n * @param hue defines the hue (value between 0 and 360)\r\n * @param saturation defines the saturation (value between 0 and 1)\r\n * @param value defines the value (value between 0 and 1)\r\n * @returns a new Color3 object\r\n */\r\n public static FromHSV(hue: number, saturation: number, value: number): Color3 {\r\n const result = new Color3(0, 0, 0);\r\n Color3.HSVtoRGBToRef(hue, saturation, value, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new Color3 from the string containing valid hexadecimal values\r\n * @param hex defines a string containing valid hexadecimal values\r\n * @returns a new Color3 object\r\n */\r\n public static FromHexString(hex: string): Color3 {\r\n if (hex.substring(0, 1) !== \"#\" || hex.length !== 7) {\r\n return new Color3(0, 0, 0);\r\n }\r\n\r\n const r = parseInt(hex.substring(1, 3), 16);\r\n const g = parseInt(hex.substring(3, 5), 16);\r\n const b = parseInt(hex.substring(5, 7), 16);\r\n\r\n return Color3.FromInts(r, g, b);\r\n }\r\n\r\n /**\r\n * Creates a new Color3 from the starting index of the given array\r\n * @param array defines the source array\r\n * @param offset defines an offset in the source array\r\n * @returns a new Color3 object\r\n */\r\n public static FromArray(array: DeepImmutable>, offset: number = 0): Color3 {\r\n return new Color3(array[offset], array[offset + 1], array[offset + 2]);\r\n }\r\n\r\n /**\r\n * Creates a new Color3 from the starting index element of the given array\r\n * @param array defines the source array to read from\r\n * @param offset defines the offset in the source array\r\n * @param result defines the target Color3 object\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number = 0, result: Color3) {\r\n result.r = array[offset];\r\n result.g = array[offset + 1];\r\n result.b = array[offset + 2];\r\n }\r\n\r\n /**\r\n * Creates a new Color3 from integer values (< 256)\r\n * @param r defines the red component to read from (value between 0 and 255)\r\n * @param g defines the green component to read from (value between 0 and 255)\r\n * @param b defines the blue component to read from (value between 0 and 255)\r\n * @returns a new Color3 object\r\n */\r\n public static FromInts(r: number, g: number, b: number): Color3 {\r\n return new Color3(r / 255.0, g / 255.0, b / 255.0);\r\n }\r\n\r\n /**\r\n * Creates a new Color3 with values linearly interpolated of \"amount\" between the start Color3 and the end Color3\r\n * @param start defines the start Color3 value\r\n * @param end defines the end Color3 value\r\n * @param amount defines the gradient value between start and end\r\n * @returns a new Color3 object\r\n */\r\n public static Lerp(start: DeepImmutable, end: DeepImmutable, amount: number): Color3 {\r\n const result = new Color3(0.0, 0.0, 0.0);\r\n Color3.LerpToRef(start, end, amount, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new Color3 with values linearly interpolated of \"amount\" between the start Color3 and the end Color3\r\n * @param left defines the start value\r\n * @param right defines the end value\r\n * @param amount defines the gradient factor\r\n * @param result defines the Color3 object where to store the result\r\n */\r\n public static LerpToRef(left: DeepImmutable, right: DeepImmutable, amount: number, result: Color3): void {\r\n result.r = left.r + (right.r - left.r) * amount;\r\n result.g = left.g + (right.g - left.g) * amount;\r\n result.b = left.b + (right.b - left.b) * amount;\r\n }\r\n\r\n /**\r\n * Returns a new Color3 located for \"amount\" (float) on the Hermite interpolation spline defined by the vectors \"value1\", \"tangent1\", \"value2\", \"tangent2\"\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent Color3\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent Color3\r\n * @param amount defines the amount on the interpolation spline (between 0 and 1)\r\n * @returns the new Color3\r\n */\r\n public static Hermite(value1: DeepImmutable, tangent1: DeepImmutable, value2: DeepImmutable, tangent2: DeepImmutable, amount: number): Color3 {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\r\n const part2 = -2.0 * cubed + 3.0 * squared;\r\n const part3 = cubed - 2.0 * squared + amount;\r\n const part4 = cubed - squared;\r\n\r\n const r = value1.r * part1 + value2.r * part2 + tangent1.r * part3 + tangent2.r * part4;\r\n const g = value1.g * part1 + value2.g * part2 + tangent1.g * part3 + tangent2.g * part4;\r\n const b = value1.b * part1 + value2.b * part2 + tangent1.b * part3 + tangent2.b * part4;\r\n return new Color3(r, g, b);\r\n }\r\n\r\n /**\r\n * Returns a new Color3 which is the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @returns 1st derivative\r\n */\r\n public static Hermite1stDerivative(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number\r\n ): Color3 {\r\n const result = Color3.Black();\r\n\r\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a new Color3 which is the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @param result define where to store the derivative\r\n */\r\n public static Hermite1stDerivativeToRef(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number,\r\n result: Color3\r\n ) {\r\n const t2 = time * time;\r\n\r\n result.r = (t2 - time) * 6 * value1.r + (3 * t2 - 4 * time + 1) * tangent1.r + (-t2 + time) * 6 * value2.r + (3 * t2 - 2 * time) * tangent2.r;\r\n result.g = (t2 - time) * 6 * value1.g + (3 * t2 - 4 * time + 1) * tangent1.g + (-t2 + time) * 6 * value2.g + (3 * t2 - 2 * time) * tangent2.g;\r\n result.b = (t2 - time) * 6 * value1.b + (3 * t2 - 4 * time + 1) * tangent1.b + (-t2 + time) * 6 * value2.b + (3 * t2 - 2 * time) * tangent2.b;\r\n }\r\n\r\n /**\r\n * Returns a Color3 value containing a red color\r\n * @returns a new Color3 object\r\n */\r\n public static Red(): Color3 {\r\n return new Color3(1, 0, 0);\r\n }\r\n /**\r\n * Returns a Color3 value containing a green color\r\n * @returns a new Color3 object\r\n */\r\n public static Green(): Color3 {\r\n return new Color3(0, 1, 0);\r\n }\r\n /**\r\n * Returns a Color3 value containing a blue color\r\n * @returns a new Color3 object\r\n */\r\n public static Blue(): Color3 {\r\n return new Color3(0, 0, 1);\r\n }\r\n /**\r\n * Returns a Color3 value containing a black color\r\n * @returns a new Color3 object\r\n */\r\n public static Black(): Color3 {\r\n return new Color3(0, 0, 0);\r\n }\r\n\r\n /**\r\n * Gets a Color3 value containing a black color that must not be updated\r\n */\r\n public static get BlackReadOnly(): DeepImmutable {\r\n return Color3._BlackReadOnly;\r\n }\r\n\r\n /**\r\n * Returns a Color3 value containing a white color\r\n * @returns a new Color3 object\r\n */\r\n public static White(): Color3 {\r\n return new Color3(1, 1, 1);\r\n }\r\n /**\r\n * Returns a Color3 value containing a purple color\r\n * @returns a new Color3 object\r\n */\r\n public static Purple(): Color3 {\r\n return new Color3(0.5, 0, 0.5);\r\n }\r\n /**\r\n * Returns a Color3 value containing a magenta color\r\n * @returns a new Color3 object\r\n */\r\n public static Magenta(): Color3 {\r\n return new Color3(1, 0, 1);\r\n }\r\n /**\r\n * Returns a Color3 value containing a yellow color\r\n * @returns a new Color3 object\r\n */\r\n public static Yellow(): Color3 {\r\n return new Color3(1, 1, 0);\r\n }\r\n /**\r\n * Returns a Color3 value containing a gray color\r\n * @returns a new Color3 object\r\n */\r\n public static Gray(): Color3 {\r\n return new Color3(0.5, 0.5, 0.5);\r\n }\r\n /**\r\n * Returns a Color3 value containing a teal color\r\n * @returns a new Color3 object\r\n */\r\n public static Teal(): Color3 {\r\n return new Color3(0, 1.0, 1.0);\r\n }\r\n /**\r\n * Returns a Color3 value containing a random color\r\n * @returns a new Color3 object\r\n */\r\n public static Random(): Color3 {\r\n return new Color3(Math.random(), Math.random(), Math.random());\r\n }\r\n}\r\n\r\n/**\r\n * Class used to hold a RBGA color\r\n */\r\nexport class Color4 {\r\n /**\r\n * Creates a new Color4 object from red, green, blue values, all between 0 and 1\r\n * @param r defines the red component (between 0 and 1, default is 0)\r\n * @param g defines the green component (between 0 and 1, default is 0)\r\n * @param b defines the blue component (between 0 and 1, default is 0)\r\n * @param a defines the alpha component (between 0 and 1, default is 1)\r\n */\r\n constructor(\r\n /**\r\n * Defines the red component (between 0 and 1, default is 0)\r\n */\r\n public r: number = 0,\r\n /**\r\n * Defines the green component (between 0 and 1, default is 0)\r\n */\r\n public g: number = 0,\r\n /**\r\n * Defines the blue component (between 0 and 1, default is 0)\r\n */\r\n public b: number = 0,\r\n /**\r\n * Defines the alpha component (between 0 and 1, default is 1)\r\n */\r\n public a: number = 1\r\n ) {}\r\n\r\n // Operators\r\n\r\n /**\r\n * Adds in place the given Color4 values to the current Color4 object\r\n * @param right defines the second operand\r\n * @returns the current updated Color4 object\r\n */\r\n public addInPlace(right: DeepImmutable): Color4 {\r\n this.r += right.r;\r\n this.g += right.g;\r\n this.b += right.b;\r\n this.a += right.a;\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a new array populated with 4 numeric elements : red, green, blue, alpha values\r\n * @returns the new array\r\n */\r\n public asArray(): number[] {\r\n return [this.r, this.g, this.b, this.a];\r\n }\r\n\r\n /**\r\n * Stores from the starting index in the given array the Color4 successive values\r\n * @param array defines the array where to store the r,g,b components\r\n * @param index defines an optional index in the target array to define where to start storing values\r\n * @returns the current Color4 object\r\n */\r\n public toArray(array: FloatArray, index: number = 0): Color4 {\r\n array[index] = this.r;\r\n array[index + 1] = this.g;\r\n array[index + 2] = this.b;\r\n array[index + 3] = this.a;\r\n return this;\r\n }\r\n\r\n /**\r\n * Update the current color with values stored in an array from the starting index of the given array\r\n * @param array defines the source array\r\n * @param offset defines an offset in the source array\r\n * @returns the current Color4 object\r\n */\r\n public fromArray(array: DeepImmutable>, offset: number = 0): Color4 {\r\n Color4.FromArrayToRef(array, offset, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Determines equality between Color4 objects\r\n * @param otherColor defines the second operand\r\n * @returns true if the rgba values are equal to the given ones\r\n */\r\n public equals(otherColor: DeepImmutable): boolean {\r\n return otherColor && this.r === otherColor.r && this.g === otherColor.g && this.b === otherColor.b && this.a === otherColor.a;\r\n }\r\n\r\n /**\r\n * Creates a new Color4 set with the added values of the current Color4 and of the given one\r\n * @param right defines the second operand\r\n * @returns a new Color4 object\r\n */\r\n public add(right: DeepImmutable): Color4 {\r\n return new Color4(this.r + right.r, this.g + right.g, this.b + right.b, this.a + right.a);\r\n }\r\n\r\n /**\r\n * Creates a new Color4 set with the subtracted values of the given one from the current Color4\r\n * @param right defines the second operand\r\n * @returns a new Color4 object\r\n */\r\n public subtract(right: DeepImmutable): Color4 {\r\n return new Color4(this.r - right.r, this.g - right.g, this.b - right.b, this.a - right.a);\r\n }\r\n\r\n /**\r\n * Subtracts the given ones from the current Color4 values and stores the results in \"result\"\r\n * @param right defines the second operand\r\n * @param result defines the Color4 object where to store the result\r\n * @returns the current Color4 object\r\n */\r\n public subtractToRef(right: DeepImmutable, result: Color4): Color4 {\r\n result.r = this.r - right.r;\r\n result.g = this.g - right.g;\r\n result.b = this.b - right.b;\r\n result.a = this.a - right.a;\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a new Color4 with the current Color4 values multiplied by scale\r\n * @param scale defines the scaling factor to apply\r\n * @returns a new Color4 object\r\n */\r\n public scale(scale: number): Color4 {\r\n return new Color4(this.r * scale, this.g * scale, this.b * scale, this.a * scale);\r\n }\r\n\r\n /**\r\n * Multiplies the Color4 values by the float \"scale\"\r\n * @param scale defines the scaling factor to apply\r\n * @returns the current updated Color4\r\n */\r\n public scaleInPlace(scale: number): Color4 {\r\n this.r *= scale;\r\n this.g *= scale;\r\n this.b *= scale;\r\n this.a *= scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiplies the current Color4 values by scale and stores the result in \"result\"\r\n * @param scale defines the scaling factor to apply\r\n * @param result defines the Color4 object where to store the result\r\n * @returns the current unmodified Color4\r\n */\r\n public scaleToRef(scale: number, result: Color4): Color4 {\r\n result.r = this.r * scale;\r\n result.g = this.g * scale;\r\n result.b = this.b * scale;\r\n result.a = this.a * scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Scale the current Color4 values by a factor and add the result to a given Color4\r\n * @param scale defines the scale factor\r\n * @param result defines the Color4 object where to store the result\r\n * @returns the unmodified current Color4\r\n */\r\n public scaleAndAddToRef(scale: number, result: Color4): Color4 {\r\n result.r += this.r * scale;\r\n result.g += this.g * scale;\r\n result.b += this.b * scale;\r\n result.a += this.a * scale;\r\n return this;\r\n }\r\n\r\n /**\r\n * Clamps the rgb values by the min and max values and stores the result into \"result\"\r\n * @param min defines minimum clamping value (default is 0)\r\n * @param max defines maximum clamping value (default is 1)\r\n * @param result defines color to store the result into.\r\n * @returns the current Color4\r\n */\r\n public clampToRef(min: number = 0, max: number = 1, result: Color4): Color4 {\r\n result.r = Scalar.Clamp(this.r, min, max);\r\n result.g = Scalar.Clamp(this.g, min, max);\r\n result.b = Scalar.Clamp(this.b, min, max);\r\n result.a = Scalar.Clamp(this.a, min, max);\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiply an Color4 value by another and return a new Color4 object\r\n * @param color defines the Color4 value to multiply by\r\n * @returns a new Color4 object\r\n */\r\n public multiply(color: Color4): Color4 {\r\n return new Color4(this.r * color.r, this.g * color.g, this.b * color.b, this.a * color.a);\r\n }\r\n\r\n /**\r\n * Multiply a Color4 value by another and push the result in a reference value\r\n * @param color defines the Color4 value to multiply by\r\n * @param result defines the Color4 to fill the result in\r\n * @returns the result Color4\r\n */\r\n public multiplyToRef(color: Color4, result: Color4): Color4 {\r\n result.r = this.r * color.r;\r\n result.g = this.g * color.g;\r\n result.b = this.b * color.b;\r\n result.a = this.a * color.a;\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a string with the Color4 current values\r\n * @returns the string representation of the Color4 object\r\n */\r\n public toString(): string {\r\n return \"{R: \" + this.r + \" G:\" + this.g + \" B:\" + this.b + \" A:\" + this.a + \"}\";\r\n }\r\n\r\n /**\r\n * Returns the string \"Color4\"\r\n * @returns \"Color4\"\r\n */\r\n public getClassName(): string {\r\n return \"Color4\";\r\n }\r\n\r\n /**\r\n * Compute the Color4 hash code\r\n * @returns an unique number that can be used to hash Color4 objects\r\n */\r\n public getHashCode(): number {\r\n let hash = (this.r * 255) | 0;\r\n hash = (hash * 397) ^ ((this.g * 255) | 0);\r\n hash = (hash * 397) ^ ((this.b * 255) | 0);\r\n hash = (hash * 397) ^ ((this.a * 255) | 0);\r\n return hash;\r\n }\r\n\r\n /**\r\n * Creates a new Color4 copied from the current one\r\n * @returns a new Color4 object\r\n */\r\n public clone(): Color4 {\r\n return new Color4(this.r, this.g, this.b, this.a);\r\n }\r\n\r\n /**\r\n * Copies the given Color4 values into the current one\r\n * @param source defines the source Color4 object\r\n * @returns the current updated Color4 object\r\n */\r\n public copyFrom(source: Color4): Color4 {\r\n this.r = source.r;\r\n this.g = source.g;\r\n this.b = source.b;\r\n this.a = source.a;\r\n return this;\r\n }\r\n\r\n /**\r\n * Copies the given float values into the current one\r\n * @param r defines the red component to read from\r\n * @param g defines the green component to read from\r\n * @param b defines the blue component to read from\r\n * @param a defines the alpha component to read from\r\n * @returns the current updated Color4 object\r\n */\r\n public copyFromFloats(r: number, g: number, b: number, a: number): Color4 {\r\n this.r = r;\r\n this.g = g;\r\n this.b = b;\r\n this.a = a;\r\n return this;\r\n }\r\n\r\n /**\r\n * Copies the given float values into the current one\r\n * @param r defines the red component to read from\r\n * @param g defines the green component to read from\r\n * @param b defines the blue component to read from\r\n * @param a defines the alpha component to read from\r\n * @returns the current updated Color4 object\r\n */\r\n public set(r: number, g: number, b: number, a: number): Color4 {\r\n return this.copyFromFloats(r, g, b, a);\r\n }\r\n\r\n /**\r\n * Compute the Color4 hexadecimal code as a string\r\n * @param returnAsColor3 defines if the string should only contains RGB values (off by default)\r\n * @returns a string containing the hexadecimal representation of the Color4 object\r\n */\r\n public toHexString(returnAsColor3 = false): string {\r\n const intR = Math.round(this.r * 255);\r\n const intG = Math.round(this.g * 255);\r\n const intB = Math.round(this.b * 255);\r\n\r\n if (returnAsColor3) {\r\n return \"#\" + Scalar.ToHex(intR) + Scalar.ToHex(intG) + Scalar.ToHex(intB);\r\n }\r\n\r\n const intA = Math.round(this.a * 255);\r\n return \"#\" + Scalar.ToHex(intR) + Scalar.ToHex(intG) + Scalar.ToHex(intB) + Scalar.ToHex(intA);\r\n }\r\n\r\n /**\r\n * Computes a new Color4 converted from the current one to linear space\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns a new Color4 object\r\n */\r\n public toLinearSpace(exact = false): Color4 {\r\n const convertedColor = new Color4();\r\n this.toLinearSpaceToRef(convertedColor, exact);\r\n return convertedColor;\r\n }\r\n\r\n /**\r\n * Converts the Color4 values to linear space and stores the result in \"convertedColor\"\r\n * @param convertedColor defines the Color4 object where to store the linear space version\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns the unmodified Color4\r\n */\r\n public toLinearSpaceToRef(convertedColor: Color4, exact = false): Color4 {\r\n if (exact) {\r\n convertedColor.r = colorChannelToLinearSpaceExact(this.r);\r\n convertedColor.g = colorChannelToLinearSpaceExact(this.g);\r\n convertedColor.b = colorChannelToLinearSpaceExact(this.b);\r\n } else {\r\n convertedColor.r = colorChannelToLinearSpace(this.r);\r\n convertedColor.g = colorChannelToLinearSpace(this.g);\r\n convertedColor.b = colorChannelToLinearSpace(this.b);\r\n }\r\n convertedColor.a = this.a;\r\n return this;\r\n }\r\n\r\n /**\r\n * Computes a new Color4 converted from the current one to gamma space\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns a new Color4 object\r\n */\r\n public toGammaSpace(exact = false): Color4 {\r\n const convertedColor = new Color4();\r\n this.toGammaSpaceToRef(convertedColor, exact);\r\n return convertedColor;\r\n }\r\n\r\n /**\r\n * Converts the Color4 values to gamma space and stores the result in \"convertedColor\"\r\n * @param convertedColor defines the Color4 object where to store the gamma space version\r\n * @param exact defines if the conversion will be done in an exact way which is slower but more accurate (default is false)\r\n * @returns the unmodified Color4\r\n */\r\n public toGammaSpaceToRef(convertedColor: Color4, exact = false): Color4 {\r\n if (exact) {\r\n convertedColor.r = colorChannelToGammaSpaceExact(this.r);\r\n convertedColor.g = colorChannelToGammaSpaceExact(this.g);\r\n convertedColor.b = colorChannelToGammaSpaceExact(this.b);\r\n } else {\r\n convertedColor.r = colorChannelToGammaSpace(this.r);\r\n convertedColor.g = colorChannelToGammaSpace(this.g);\r\n convertedColor.b = colorChannelToGammaSpace(this.b);\r\n }\r\n convertedColor.a = this.a;\r\n return this;\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Creates a new Color4 from the string containing valid hexadecimal values.\r\n *\r\n * A valid hex string is either in the format #RRGGBB or #RRGGBBAA.\r\n *\r\n * When a hex string without alpha is passed, the resulting Color4 has\r\n * its alpha value set to 1.0.\r\n *\r\n * An invalid string results in a Color with all its channels set to 0.0,\r\n * i.e. \"transparent black\".\r\n *\r\n * @param hex defines a string containing valid hexadecimal values\r\n * @returns a new Color4 object\r\n */\r\n public static FromHexString(hex: string): Color4 {\r\n if (hex.substring(0, 1) !== \"#\" || (hex.length !== 9 && hex.length !== 7)) {\r\n return new Color4(0.0, 0.0, 0.0, 0.0);\r\n }\r\n\r\n const r = parseInt(hex.substring(1, 3), 16);\r\n const g = parseInt(hex.substring(3, 5), 16);\r\n const b = parseInt(hex.substring(5, 7), 16);\r\n const a = hex.length === 9 ? parseInt(hex.substring(7, 9), 16) : 255;\r\n\r\n return Color4.FromInts(r, g, b, a);\r\n }\r\n\r\n /**\r\n * Creates a new Color4 object set with the linearly interpolated values of \"amount\" between the left Color4 object and the right Color4 object\r\n * @param left defines the start value\r\n * @param right defines the end value\r\n * @param amount defines the gradient factor\r\n * @returns a new Color4 object\r\n */\r\n public static Lerp(left: DeepImmutable, right: DeepImmutable, amount: number): Color4 {\r\n const result = new Color4(0.0, 0.0, 0.0, 0.0);\r\n Color4.LerpToRef(left, right, amount, result);\r\n return result;\r\n }\r\n\r\n /**\r\n * Set the given \"result\" with the linearly interpolated values of \"amount\" between the left Color4 object and the right Color4 object\r\n * @param left defines the start value\r\n * @param right defines the end value\r\n * @param amount defines the gradient factor\r\n * @param result defines the Color4 object where to store data\r\n */\r\n public static LerpToRef(left: DeepImmutable, right: DeepImmutable, amount: number, result: Color4): void {\r\n result.r = left.r + (right.r - left.r) * amount;\r\n result.g = left.g + (right.g - left.g) * amount;\r\n result.b = left.b + (right.b - left.b) * amount;\r\n result.a = left.a + (right.a - left.a) * amount;\r\n }\r\n\r\n /**\r\n * Interpolate between two Color4 using Hermite interpolation\r\n * @param value1 defines first Color4\r\n * @param tangent1 defines the incoming tangent\r\n * @param value2 defines second Color4\r\n * @param tangent2 defines the outgoing tangent\r\n * @param amount defines the target Color4\r\n * @returns the new interpolated Color4\r\n */\r\n public static Hermite(value1: DeepImmutable, tangent1: DeepImmutable, value2: DeepImmutable, tangent2: DeepImmutable, amount: number): Color4 {\r\n const squared = amount * amount;\r\n const cubed = amount * squared;\r\n const part1 = 2.0 * cubed - 3.0 * squared + 1.0;\r\n const part2 = -2.0 * cubed + 3.0 * squared;\r\n const part3 = cubed - 2.0 * squared + amount;\r\n const part4 = cubed - squared;\r\n\r\n const r = value1.r * part1 + value2.r * part2 + tangent1.r * part3 + tangent2.r * part4;\r\n const g = value1.g * part1 + value2.g * part2 + tangent1.g * part3 + tangent2.g * part4;\r\n const b = value1.b * part1 + value2.b * part2 + tangent1.b * part3 + tangent2.b * part4;\r\n const a = value1.a * part1 + value2.a * part2 + tangent1.a * part3 + tangent2.a * part4;\r\n return new Color4(r, g, b, a);\r\n }\r\n\r\n /**\r\n * Returns a new Color4 which is the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @returns 1st derivative\r\n */\r\n public static Hermite1stDerivative(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number\r\n ): Color4 {\r\n const result = new Color4();\r\n\r\n this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Update a Color4 with the 1st derivative of the Hermite spline defined by the colors \"value1\", \"value2\", \"tangent1\", \"tangent2\".\r\n * @param value1 defines the first control point\r\n * @param tangent1 defines the first tangent\r\n * @param value2 defines the second control point\r\n * @param tangent2 defines the second tangent\r\n * @param time define where the derivative must be done\r\n * @param result define where to store the derivative\r\n */\r\n public static Hermite1stDerivativeToRef(\r\n value1: DeepImmutable,\r\n tangent1: DeepImmutable,\r\n value2: DeepImmutable,\r\n tangent2: DeepImmutable,\r\n time: number,\r\n result: Color4\r\n ) {\r\n const t2 = time * time;\r\n\r\n result.r = (t2 - time) * 6 * value1.r + (3 * t2 - 4 * time + 1) * tangent1.r + (-t2 + time) * 6 * value2.r + (3 * t2 - 2 * time) * tangent2.r;\r\n result.g = (t2 - time) * 6 * value1.g + (3 * t2 - 4 * time + 1) * tangent1.g + (-t2 + time) * 6 * value2.g + (3 * t2 - 2 * time) * tangent2.g;\r\n result.b = (t2 - time) * 6 * value1.b + (3 * t2 - 4 * time + 1) * tangent1.b + (-t2 + time) * 6 * value2.b + (3 * t2 - 2 * time) * tangent2.b;\r\n result.a = (t2 - time) * 6 * value1.a + (3 * t2 - 4 * time + 1) * tangent1.a + (-t2 + time) * 6 * value2.a + (3 * t2 - 2 * time) * tangent2.a;\r\n }\r\n\r\n /**\r\n * Creates a new Color4 from a Color3 and an alpha value\r\n * @param color3 defines the source Color3 to read from\r\n * @param alpha defines the alpha component (1.0 by default)\r\n * @returns a new Color4 object\r\n */\r\n public static FromColor3(color3: DeepImmutable, alpha: number = 1.0): Color4 {\r\n return new Color4(color3.r, color3.g, color3.b, alpha);\r\n }\r\n\r\n /**\r\n * Creates a new Color4 from the starting index element of the given array\r\n * @param array defines the source array to read from\r\n * @param offset defines the offset in the source array\r\n * @returns a new Color4 object\r\n */\r\n public static FromArray(array: DeepImmutable>, offset: number = 0): Color4 {\r\n return new Color4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\r\n }\r\n\r\n /**\r\n * Creates a new Color4 from the starting index element of the given array\r\n * @param array defines the source array to read from\r\n * @param offset defines the offset in the source array\r\n * @param result defines the target Color4 object\r\n */\r\n public static FromArrayToRef(array: DeepImmutable>, offset: number = 0, result: Color4) {\r\n result.r = array[offset];\r\n result.g = array[offset + 1];\r\n result.b = array[offset + 2];\r\n result.a = array[offset + 3];\r\n }\r\n\r\n /**\r\n * Creates a new Color3 from integer values (< 256)\r\n * @param r defines the red component to read from (value between 0 and 255)\r\n * @param g defines the green component to read from (value between 0 and 255)\r\n * @param b defines the blue component to read from (value between 0 and 255)\r\n * @param a defines the alpha component to read from (value between 0 and 255)\r\n * @returns a new Color3 object\r\n */\r\n public static FromInts(r: number, g: number, b: number, a: number): Color4 {\r\n return new Color4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);\r\n }\r\n\r\n /**\r\n * Check the content of a given array and convert it to an array containing RGBA data\r\n * If the original array was already containing count * 4 values then it is returned directly\r\n * @param colors defines the array to check\r\n * @param count defines the number of RGBA data to expect\r\n * @returns an array containing count * 4 values (RGBA)\r\n */\r\n public static CheckColors4(colors: number[], count: number): number[] {\r\n // Check if color3 was used\r\n if (colors.length === count * 3) {\r\n const colors4 = [];\r\n for (let index = 0; index < colors.length; index += 3) {\r\n const newIndex = (index / 3) * 4;\r\n colors4[newIndex] = colors[index];\r\n colors4[newIndex + 1] = colors[index + 1];\r\n colors4[newIndex + 2] = colors[index + 2];\r\n colors4[newIndex + 3] = 1.0;\r\n }\r\n\r\n return colors4;\r\n }\r\n\r\n return colors;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class TmpColors {\r\n public static Color3: Color3[] = ArrayTools.BuildArray(3, Color3.Black);\r\n public static Color4: Color4[] = ArrayTools.BuildArray(3, () => new Color4(0, 0, 0, 0));\r\n}\r\n\r\nRegisterClass(\"BABYLON.Color3\", Color3);\r\nRegisterClass(\"BABYLON.Color4\", Color4);\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tags } from \"../Misc/tags\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Quaternion, Vector2, Vector3, Matrix } from \"../Maths/math.vector\";\r\nimport { _WarnImport } from \"./devTools\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport { Color4, Color3 } from \"../Maths/math.color\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\n\r\nimport type { ImageProcessingConfiguration } from \"../Materials/imageProcessingConfiguration\";\r\nimport type { FresnelParameters } from \"../Materials/fresnelParameters\";\r\nimport type { ColorCurves } from \"../Materials/colorCurves\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\n\r\nconst __decoratorInitialStore = {};\r\nconst __mergedStore = {};\r\n\r\n/** @internal */\r\nexport interface CopySourceOptions {\r\n /*\r\n * if a texture is used in more than one channel (e.g diffuse and opacity),\r\n * only clone it once and reuse it on the other channels. Default false\r\n */\r\n cloneTexturesOnlyOnce?: boolean;\r\n}\r\n\r\nconst _copySource = function (creationFunction: () => T, source: T, instanciate: boolean, options: CopySourceOptions = {}): T {\r\n const destination = creationFunction();\r\n\r\n // Tags\r\n if (Tags && Tags.HasTags(source)) {\r\n Tags.AddTagsTo(destination, Tags.GetTags(source, true));\r\n }\r\n\r\n const classStore = getMergedStore(destination);\r\n\r\n // Map from source texture uniqueId to destination texture\r\n const textureMap: Record = {};\r\n\r\n // Properties\r\n for (const property in classStore) {\r\n const propertyDescriptor = classStore[property];\r\n const sourceProperty = (source)[property];\r\n const propertyType = propertyDescriptor.type;\r\n\r\n if (sourceProperty !== undefined && sourceProperty !== null && (property !== \"uniqueId\" || SerializationHelper.AllowLoadingUniqueId)) {\r\n switch (propertyType) {\r\n case 0: // Value\r\n case 6: // Mesh reference\r\n case 11: // Camera reference\r\n (destination)[property] = sourceProperty;\r\n break;\r\n case 1: // Texture\r\n if (options.cloneTexturesOnlyOnce && textureMap[sourceProperty.uniqueId]) {\r\n (destination)[property] = textureMap[sourceProperty.uniqueId];\r\n } else {\r\n (destination)[property] = instanciate || sourceProperty.isRenderTarget ? sourceProperty : sourceProperty.clone();\r\n textureMap[sourceProperty.uniqueId] = (destination)[property];\r\n }\r\n break;\r\n case 2: // Color3\r\n case 3: // FresnelParameters\r\n case 4: // Vector2\r\n case 5: // Vector3\r\n case 7: // Color Curves\r\n case 10: // Quaternion\r\n case 12: // Matrix\r\n (destination)[property] = instanciate ? sourceProperty : sourceProperty.clone();\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return destination;\r\n};\r\n\r\nfunction getDirectStore(target: any): any {\r\n const classKey = target.getClassName();\r\n\r\n if (!(__decoratorInitialStore)[classKey]) {\r\n (__decoratorInitialStore)[classKey] = {};\r\n }\r\n\r\n return (__decoratorInitialStore)[classKey];\r\n}\r\n\r\n/**\r\n * Return the list of properties flagged as serializable\r\n * @param target host object\r\n */\r\nfunction getMergedStore(target: any): any {\r\n const classKey = target.getClassName();\r\n\r\n if ((__mergedStore)[classKey]) {\r\n return (__mergedStore)[classKey];\r\n }\r\n\r\n (__mergedStore)[classKey] = {};\r\n\r\n const store = (__mergedStore)[classKey];\r\n let currentTarget = target;\r\n let currentKey = classKey;\r\n while (currentKey) {\r\n const initialStore = (__decoratorInitialStore)[currentKey];\r\n for (const property in initialStore) {\r\n store[property] = initialStore[property];\r\n }\r\n\r\n let parent: any;\r\n let done = false;\r\n\r\n do {\r\n parent = Object.getPrototypeOf(currentTarget);\r\n if (!parent.getClassName) {\r\n done = true;\r\n break;\r\n }\r\n\r\n if (parent.getClassName() !== currentKey) {\r\n break;\r\n }\r\n\r\n currentTarget = parent;\r\n } while (parent);\r\n\r\n if (done) {\r\n break;\r\n }\r\n\r\n currentKey = parent.getClassName();\r\n currentTarget = parent;\r\n }\r\n\r\n return store;\r\n}\r\n\r\nfunction generateSerializableMember(type: number, sourceName?: string) {\r\n return (target: any, propertyKey: string | symbol) => {\r\n const classStore = getDirectStore(target);\r\n\r\n if (!classStore[propertyKey]) {\r\n classStore[propertyKey] = { type: type, sourceName: sourceName };\r\n }\r\n };\r\n}\r\n\r\nfunction generateExpandMember(setCallback: string, targetKey: Nullable = null) {\r\n return (target: any, propertyKey: string) => {\r\n const key = targetKey || \"_\" + propertyKey;\r\n Object.defineProperty(target, propertyKey, {\r\n get: function (this: any) {\r\n return this[key];\r\n },\r\n set: function (this: any, value) {\r\n // does this object (i.e. vector3) has an equals function? use it!\r\n // Note - not using \"with epsilon\" here, it is expected te behave like the internal cache does.\r\n if (typeof this.equals === \"function\") {\r\n if (this.equals(value)) {\r\n return;\r\n }\r\n }\r\n if (this[key] === value) {\r\n return;\r\n }\r\n this[key] = value;\r\n\r\n target[setCallback].apply(this);\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n });\r\n };\r\n}\r\n\r\nexport function expandToProperty(callback: string, targetKey: Nullable = null) {\r\n return generateExpandMember(callback, targetKey);\r\n}\r\n\r\nexport function serialize(sourceName?: string) {\r\n return generateSerializableMember(0, sourceName); // value member\r\n}\r\n\r\nexport function serializeAsTexture(sourceName?: string) {\r\n return generateSerializableMember(1, sourceName); // texture member\r\n}\r\n\r\nexport function serializeAsColor3(sourceName?: string) {\r\n return generateSerializableMember(2, sourceName); // color3 member\r\n}\r\n\r\nexport function serializeAsFresnelParameters(sourceName?: string) {\r\n return generateSerializableMember(3, sourceName); // fresnel parameters member\r\n}\r\n\r\nexport function serializeAsVector2(sourceName?: string) {\r\n return generateSerializableMember(4, sourceName); // vector2 member\r\n}\r\n\r\nexport function serializeAsVector3(sourceName?: string) {\r\n return generateSerializableMember(5, sourceName); // vector3 member\r\n}\r\n\r\nexport function serializeAsMeshReference(sourceName?: string) {\r\n return generateSerializableMember(6, sourceName); // mesh reference member\r\n}\r\n\r\nexport function serializeAsColorCurves(sourceName?: string) {\r\n return generateSerializableMember(7, sourceName); // color curves\r\n}\r\n\r\nexport function serializeAsColor4(sourceName?: string) {\r\n return generateSerializableMember(8, sourceName); // color 4\r\n}\r\n\r\nexport function serializeAsImageProcessingConfiguration(sourceName?: string) {\r\n return generateSerializableMember(9, sourceName); // image processing\r\n}\r\n\r\nexport function serializeAsQuaternion(sourceName?: string) {\r\n return generateSerializableMember(10, sourceName); // quaternion member\r\n}\r\n\r\nexport function serializeAsMatrix(sourceName?: string) {\r\n return generateSerializableMember(12, sourceName); // matrix member\r\n}\r\n\r\n/**\r\n * Decorator used to define property that can be serialized as reference to a camera\r\n * @param sourceName defines the name of the property to decorate\r\n */\r\nexport function serializeAsCameraReference(sourceName?: string) {\r\n return generateSerializableMember(11, sourceName); // camera reference member\r\n}\r\n\r\n/**\r\n * Class used to help serialization objects\r\n */\r\nexport class SerializationHelper {\r\n /**\r\n * Gets or sets a boolean to indicate if the UniqueId property should be serialized\r\n */\r\n public static AllowLoadingUniqueId = false;\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _ImageProcessingConfigurationParser = (sourceProperty: any): ImageProcessingConfiguration => {\r\n throw _WarnImport(\"ImageProcessingConfiguration\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _FresnelParametersParser = (sourceProperty: any): FresnelParameters => {\r\n throw _WarnImport(\"FresnelParameters\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _ColorCurvesParser = (sourceProperty: any): ColorCurves => {\r\n throw _WarnImport(\"ColorCurves\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _TextureParser = (sourceProperty: any, scene: Scene, rootUrl: string): Nullable => {\r\n throw _WarnImport(\"Texture\");\r\n };\r\n\r\n /**\r\n * Appends the serialized animations from the source animations\r\n * @param source Source containing the animations\r\n * @param destination Target to store the animations\r\n */\r\n public static AppendSerializedAnimations(source: IAnimatable, destination: any): void {\r\n if (source.animations) {\r\n destination.animations = [];\r\n for (let animationIndex = 0; animationIndex < source.animations.length; animationIndex++) {\r\n const animation = source.animations[animationIndex];\r\n\r\n destination.animations.push(animation.serialize());\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Static function used to serialized a specific entity\r\n * @param entity defines the entity to serialize\r\n * @param serializationObject defines the optional target object where serialization data will be stored\r\n * @returns a JSON compatible object representing the serialization of the entity\r\n */\r\n public static Serialize(entity: T, serializationObject?: any): any {\r\n if (!serializationObject) {\r\n serializationObject = {};\r\n }\r\n\r\n // Tags\r\n if (Tags) {\r\n serializationObject.tags = Tags.GetTags(entity);\r\n }\r\n\r\n const serializedProperties = getMergedStore(entity);\r\n\r\n // Properties\r\n for (const property in serializedProperties) {\r\n const propertyDescriptor = serializedProperties[property];\r\n const targetPropertyName = propertyDescriptor.sourceName || property;\r\n const propertyType = propertyDescriptor.type;\r\n const sourceProperty = (entity)[property];\r\n\r\n if (sourceProperty !== undefined && sourceProperty !== null && (property !== \"uniqueId\" || SerializationHelper.AllowLoadingUniqueId)) {\r\n switch (propertyType) {\r\n case 0: // Value\r\n serializationObject[targetPropertyName] = sourceProperty;\r\n break;\r\n case 1: // Texture\r\n serializationObject[targetPropertyName] = sourceProperty.serialize();\r\n break;\r\n case 2: // Color3\r\n serializationObject[targetPropertyName] = sourceProperty.asArray();\r\n break;\r\n case 3: // FresnelParameters\r\n serializationObject[targetPropertyName] = sourceProperty.serialize();\r\n break;\r\n case 4: // Vector2\r\n serializationObject[targetPropertyName] = sourceProperty.asArray();\r\n break;\r\n case 5: // Vector3\r\n serializationObject[targetPropertyName] = sourceProperty.asArray();\r\n break;\r\n case 6: // Mesh reference\r\n serializationObject[targetPropertyName] = sourceProperty.id;\r\n break;\r\n case 7: // Color Curves\r\n serializationObject[targetPropertyName] = sourceProperty.serialize();\r\n break;\r\n case 8: // Color 4\r\n serializationObject[targetPropertyName] = (sourceProperty).asArray();\r\n break;\r\n case 9: // Image Processing\r\n serializationObject[targetPropertyName] = (sourceProperty).serialize();\r\n break;\r\n case 10: // Quaternion\r\n serializationObject[targetPropertyName] = (sourceProperty).asArray();\r\n break;\r\n case 11: // Camera reference\r\n serializationObject[targetPropertyName] = (sourceProperty).id;\r\n break;\r\n case 12: // Matrix\r\n serializationObject[targetPropertyName] = (sourceProperty).asArray();\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Given a source json and a destination object in a scene, this function will parse the source and will try to apply its content to the destination object\r\n * @param source the source json data\r\n * @param destination the destination object\r\n * @param scene the scene where the object is\r\n * @param rootUrl root url to use to load assets\r\n */\r\n public static ParseProperties(source: any, destination: any, scene: Nullable, rootUrl: Nullable) {\r\n if (!rootUrl) {\r\n rootUrl = \"\";\r\n }\r\n\r\n const classStore = getMergedStore(destination);\r\n\r\n // Properties\r\n for (const property in classStore) {\r\n const propertyDescriptor = classStore[property];\r\n const sourceProperty = source[propertyDescriptor.sourceName || property];\r\n const propertyType = propertyDescriptor.type;\r\n\r\n if (sourceProperty !== undefined && sourceProperty !== null && (property !== \"uniqueId\" || SerializationHelper.AllowLoadingUniqueId)) {\r\n const dest = destination;\r\n switch (propertyType) {\r\n case 0: // Value\r\n dest[property] = sourceProperty;\r\n break;\r\n case 1: // Texture\r\n if (scene) {\r\n dest[property] = SerializationHelper._TextureParser(sourceProperty, scene, rootUrl);\r\n }\r\n break;\r\n case 2: // Color3\r\n dest[property] = Color3.FromArray(sourceProperty);\r\n break;\r\n case 3: // FresnelParameters\r\n dest[property] = SerializationHelper._FresnelParametersParser(sourceProperty);\r\n break;\r\n case 4: // Vector2\r\n dest[property] = Vector2.FromArray(sourceProperty);\r\n break;\r\n case 5: // Vector3\r\n dest[property] = Vector3.FromArray(sourceProperty);\r\n break;\r\n case 6: // Mesh reference\r\n if (scene) {\r\n dest[property] = scene.getLastMeshById(sourceProperty);\r\n }\r\n break;\r\n case 7: // Color Curves\r\n dest[property] = SerializationHelper._ColorCurvesParser(sourceProperty);\r\n break;\r\n case 8: // Color 4\r\n dest[property] = Color4.FromArray(sourceProperty);\r\n break;\r\n case 9: // Image Processing\r\n dest[property] = SerializationHelper._ImageProcessingConfigurationParser(sourceProperty);\r\n break;\r\n case 10: // Quaternion\r\n dest[property] = Quaternion.FromArray(sourceProperty);\r\n break;\r\n case 11: // Camera reference\r\n if (scene) {\r\n dest[property] = scene.getCameraById(sourceProperty);\r\n }\r\n break;\r\n case 12: // Matrix\r\n dest[property] = Matrix.FromArray(sourceProperty);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new entity from a serialization data object\r\n * @param creationFunction defines a function used to instanciated the new entity\r\n * @param source defines the source serialization data\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root url for resources\r\n * @returns a new entity\r\n */\r\n public static Parse(creationFunction: () => T, source: any, scene: Nullable, rootUrl: Nullable = null): T {\r\n const destination = creationFunction();\r\n\r\n // Tags\r\n if (Tags) {\r\n Tags.AddTagsTo(destination, source.tags);\r\n }\r\n\r\n SerializationHelper.ParseProperties(source, destination, scene, rootUrl);\r\n\r\n return destination;\r\n }\r\n\r\n /**\r\n * Clones an object\r\n * @param creationFunction defines the function used to instanciate the new object\r\n * @param source defines the source object\r\n * @returns the cloned object\r\n */\r\n public static Clone(creationFunction: () => T, source: T, options: CopySourceOptions = {}): T {\r\n return _copySource(creationFunction, source, false, options);\r\n }\r\n\r\n /**\r\n * Instanciates a new object based on a source one (some data will be shared between both object)\r\n * @param creationFunction defines the function used to instanciate the new object\r\n * @param source defines the source object\r\n * @returns the new object\r\n */\r\n public static Instanciate(creationFunction: () => T, source: T): T {\r\n return _copySource(creationFunction, source, true);\r\n }\r\n}\r\n\r\n/** @internal */\r\ndeclare const _native: any;\r\n\r\n/**\r\n * Decorator used to redirect a function to a native implementation if available.\r\n * @internal\r\n */\r\nexport function nativeOverride boolean>(\r\n target: any,\r\n propertyKey: string,\r\n descriptor: TypedPropertyDescriptor<(...params: Parameters) => unknown>,\r\n predicate?: T\r\n) {\r\n // Cache the original JS function for later.\r\n const jsFunc = descriptor.value!;\r\n\r\n // Override the JS function to check for a native override on first invocation. Setting descriptor.value overrides the function at the early stage of code being loaded/imported.\r\n descriptor.value = (...params: Parameters): unknown => {\r\n // Assume the resolved function will be the original JS function, then we will check for the Babylon Native context.\r\n let func = jsFunc;\r\n\r\n // Check if we are executing in a Babylon Native context (e.g. check the presence of the _native global property) and if so also check if a function override is available.\r\n if (typeof _native !== \"undefined\" && _native[propertyKey]) {\r\n const nativeFunc = _native[propertyKey] as (...params: Parameters) => unknown;\r\n // If a predicate was provided, then we'll need to invoke the predicate on each invocation of the underlying function to determine whether to call the native function or the JS function.\r\n if (predicate) {\r\n // The resolved function will execute the predicate and then either execute the native function or the JS function.\r\n func = (...params: Parameters) => (predicate(...params) ? nativeFunc(...params) : jsFunc(...params));\r\n } else {\r\n // The resolved function will directly execute the native function.\r\n func = nativeFunc;\r\n }\r\n }\r\n\r\n // Override the JS function again with the final resolved target function.\r\n target[propertyKey] = func;\r\n\r\n // The JS function has now been overridden based on whether we're executing in the context of Babylon Native, but we still need to invoke that function.\r\n // Future invocations of the function will just directly invoke the final overridden function, not any of the decorator setup logic above.\r\n return func(...params);\r\n };\r\n}\r\n\r\n/**\r\n * Decorator factory that applies the nativeOverride decorator, but determines whether to redirect to the native implementation based on a filter function that evaluates the function arguments.\r\n * @param predicate\r\n * @example @nativeOverride.filter((...[arg1]: Parameters) => arg1.length > 20)\r\n * public someMethod(arg1: string, arg2: number): string {\r\n * @internal\r\n */\r\nnativeOverride.filter = function boolean>(predicate: T) {\r\n return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...params: Parameters) => unknown>) =>\r\n nativeOverride(target, propertyKey, descriptor, predicate);\r\n};\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Scene } from \"./scene\";\r\nimport type { Nullable } from \"./types\";\r\nimport { Matrix, Vector3 } from \"./Maths/math.vector\";\r\nimport type { Engine } from \"./Engines/engine\";\r\nimport type { IBehaviorAware, Behavior } from \"./Behaviors/behavior\";\r\nimport { SerializationHelper, serialize } from \"./Misc/decorators\";\r\nimport type { Observer } from \"./Misc/observable\";\r\nimport { Observable } from \"./Misc/observable\";\r\nimport { EngineStore } from \"./Engines/engineStore\";\r\nimport { _WarnImport } from \"./Misc/devTools\";\r\nimport type { AbstractActionManager } from \"./Actions/abstractActionManager\";\r\nimport type { IInspectable } from \"./Misc/iInspectable\";\r\nimport type { AbstractScene } from \"./abstractScene\";\r\nimport type { IAccessibilityTag } from \"./IAccessibilityTag\";\r\nimport type { AnimationRange } from \"./Animations/animationRange\";\r\nimport type { AnimationPropertiesOverride } from \"./Animations/animationPropertiesOverride\";\r\nimport type { AbstractMesh } from \"./Meshes/abstractMesh\";\r\nimport type { Animation } from \"./Animations/animation\";\r\nimport type { Animatable } from \"./Animations/animatable\";\r\n\r\n/**\r\n * Defines how a node can be built from a string name.\r\n */\r\nexport type NodeConstructor = (name: string, scene: Scene, options?: any) => () => Node;\r\n\r\n/** @internal */\r\nclass _InternalNodeDataInfo {\r\n public _doNotSerialize = false;\r\n public _isDisposed = false;\r\n public _sceneRootNodesIndex = -1;\r\n public _isEnabled = true;\r\n public _isParentEnabled = true;\r\n public _isReady = true;\r\n public _onEnabledStateChangedObservable = new Observable();\r\n public _onClonedObservable = new Observable();\r\n}\r\n\r\n/**\r\n * Node is the basic class for all scene objects (Mesh, Light, Camera.)\r\n */\r\nexport class Node implements IBehaviorAware {\r\n protected _isDirty = false;\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _AnimationRangeFactory = (_name: string, _from: number, _to: number): AnimationRange => {\r\n throw _WarnImport(\"AnimationRange\");\r\n };\r\n\r\n private static _NodeConstructors: { [key: string]: any } = {};\r\n\r\n /**\r\n * Add a new node constructor\r\n * @param type defines the type name of the node to construct\r\n * @param constructorFunc defines the constructor function\r\n */\r\n public static AddNodeConstructor(type: string, constructorFunc: NodeConstructor) {\r\n this._NodeConstructors[type] = constructorFunc;\r\n }\r\n\r\n /**\r\n * Returns a node constructor based on type name\r\n * @param type defines the type name\r\n * @param name defines the new node name\r\n * @param scene defines the hosting scene\r\n * @param options defines optional options to transmit to constructors\r\n * @returns the new constructor or null\r\n */\r\n public static Construct(type: string, name: string, scene: Scene, options?: any): Nullable<() => Node> {\r\n const constructorFunc = this._NodeConstructors[type];\r\n\r\n if (!constructorFunc) {\r\n return null;\r\n }\r\n\r\n return constructorFunc(name, scene, options);\r\n }\r\n\r\n private _nodeDataStorage = new _InternalNodeDataInfo();\r\n\r\n /**\r\n * Gets or sets the name of the node\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Gets or sets the id of the node\r\n */\r\n @serialize()\r\n public id: string;\r\n\r\n /**\r\n * Gets or sets the unique id of the node\r\n */\r\n @serialize()\r\n public uniqueId: number;\r\n\r\n /**\r\n * Gets or sets a string used to store user defined state for the node\r\n */\r\n @serialize()\r\n public state = \"\";\r\n\r\n /**\r\n * Gets or sets an object used to store user defined information for the node\r\n */\r\n @serialize()\r\n public metadata: any = null;\r\n\r\n /** @internal */\r\n public _internalMetadata: any;\r\n\r\n /**\r\n * For internal use only. Please do not use.\r\n */\r\n public reservedDataStore: any = null;\r\n\r\n /**\r\n * List of inspectable custom properties (used by the Inspector)\r\n * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility\r\n */\r\n public inspectableCustomProperties: IInspectable[];\r\n\r\n /**\r\n * Gets or sets the accessibility tag to describe the node for accessibility purpose.\r\n */\r\n public set accessibilityTag(value: Nullable) {\r\n this._accessibilityTag = value;\r\n this.onAccessibilityTagChangedObservable.notifyObservers(value);\r\n }\r\n\r\n public get accessibilityTag() {\r\n return this._accessibilityTag;\r\n }\r\n\r\n protected _accessibilityTag: Nullable = null;\r\n\r\n public onAccessibilityTagChangedObservable = new Observable>();\r\n\r\n /**\r\n * Gets or sets a boolean used to define if the node must be serialized\r\n */\r\n public get doNotSerialize() {\r\n if (this._nodeDataStorage._doNotSerialize) {\r\n return true;\r\n }\r\n\r\n if (this._parentNode) {\r\n return this._parentNode.doNotSerialize;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public set doNotSerialize(value: boolean) {\r\n this._nodeDataStorage._doNotSerialize = value;\r\n }\r\n\r\n /** @internal */\r\n public _parentContainer: Nullable = null;\r\n\r\n /**\r\n * Gets a list of Animations associated with the node\r\n */\r\n public animations = new Array();\r\n protected _ranges: { [name: string]: Nullable } = {};\r\n\r\n /**\r\n * Callback raised when the node is ready to be used\r\n */\r\n public onReady: Nullable<(node: Node) => void> = null;\r\n\r\n /** @internal */\r\n public _currentRenderId = -1;\r\n private _parentUpdateId = -1;\r\n /** @internal */\r\n public _childUpdateId = -1;\r\n\r\n /** @internal */\r\n public _waitingParentId: Nullable = null;\r\n /** @internal */\r\n public _waitingParentInstanceIndex: Nullable = null;\r\n /** @internal */\r\n public _waitingParsedUniqueId: Nullable = null;\r\n /** @internal */\r\n public _scene: Scene;\r\n /** @internal */\r\n public _cache: any = {};\r\n\r\n protected _parentNode: Nullable = null;\r\n\r\n /** @internal */\r\n protected _children: Nullable = null;\r\n\r\n /** @internal */\r\n public _worldMatrix = Matrix.Identity();\r\n /** @internal */\r\n public _worldMatrixDeterminant = 0;\r\n /** @internal */\r\n public _worldMatrixDeterminantIsDirty = true;\r\n\r\n /**\r\n * Gets a boolean indicating if the node has been disposed\r\n * @returns true if the node was disposed\r\n */\r\n public isDisposed(): boolean {\r\n return this._nodeDataStorage._isDisposed;\r\n }\r\n\r\n /**\r\n * Gets or sets the parent of the node (without keeping the current position in the scene)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/parent\r\n */\r\n public set parent(parent: Nullable) {\r\n if (this._parentNode === parent) {\r\n return;\r\n }\r\n\r\n const previousParentNode = this._parentNode;\r\n\r\n // Remove self from list of children of parent\r\n if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {\r\n const index = this._parentNode._children.indexOf(this);\r\n if (index !== -1) {\r\n this._parentNode._children.splice(index, 1);\r\n }\r\n\r\n if (!parent && !this._nodeDataStorage._isDisposed) {\r\n this._addToSceneRootNodes();\r\n }\r\n }\r\n\r\n // Store new parent\r\n this._parentNode = parent;\r\n\r\n // Add as child to new parent\r\n if (this._parentNode) {\r\n if (this._parentNode._children === undefined || this._parentNode._children === null) {\r\n this._parentNode._children = new Array();\r\n }\r\n this._parentNode._children.push(this);\r\n\r\n if (!previousParentNode) {\r\n this._removeFromSceneRootNodes();\r\n }\r\n }\r\n\r\n // Enabled state\r\n this._syncParentEnabledState();\r\n }\r\n\r\n public get parent(): Nullable {\r\n return this._parentNode;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _serializeAsParent(serializationObject: any): void {\r\n serializationObject.parentId = this.uniqueId;\r\n }\r\n\r\n /** @internal */\r\n public _addToSceneRootNodes() {\r\n if (this._nodeDataStorage._sceneRootNodesIndex === -1) {\r\n this._nodeDataStorage._sceneRootNodesIndex = this._scene.rootNodes.length;\r\n this._scene.rootNodes.push(this);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _removeFromSceneRootNodes() {\r\n if (this._nodeDataStorage._sceneRootNodesIndex !== -1) {\r\n const rootNodes = this._scene.rootNodes;\r\n const lastIdx = rootNodes.length - 1;\r\n rootNodes[this._nodeDataStorage._sceneRootNodesIndex] = rootNodes[lastIdx];\r\n rootNodes[this._nodeDataStorage._sceneRootNodesIndex]._nodeDataStorage._sceneRootNodesIndex = this._nodeDataStorage._sceneRootNodesIndex;\r\n this._scene.rootNodes.pop();\r\n this._nodeDataStorage._sceneRootNodesIndex = -1;\r\n }\r\n }\r\n\r\n private _animationPropertiesOverride: Nullable = null;\r\n\r\n /**\r\n * Gets or sets the animation properties override\r\n */\r\n public get animationPropertiesOverride(): Nullable {\r\n if (!this._animationPropertiesOverride) {\r\n return this._scene.animationPropertiesOverride;\r\n }\r\n return this._animationPropertiesOverride;\r\n }\r\n\r\n public set animationPropertiesOverride(value: Nullable) {\r\n this._animationPropertiesOverride = value;\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"Node\" string\r\n */\r\n public getClassName(): string {\r\n return \"Node\";\r\n }\r\n\r\n /** @internal */\r\n public readonly _isNode = true;\r\n\r\n /**\r\n * An event triggered when the mesh is disposed\r\n */\r\n public onDisposeObservable = new Observable();\r\n\r\n private _onDisposeObserver: Nullable> = null;\r\n /**\r\n * Sets a callback that will be raised when the node will be disposed\r\n */\r\n public set onDispose(callback: () => void) {\r\n if (this._onDisposeObserver) {\r\n this.onDisposeObservable.remove(this._onDisposeObserver);\r\n }\r\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when the enabled state of the node changes\r\n */\r\n public get onEnabledStateChangedObservable(): Observable {\r\n return this._nodeDataStorage._onEnabledStateChangedObservable;\r\n }\r\n\r\n /**\r\n * An event triggered when the node is cloned\r\n */\r\n public get onClonedObservable(): Observable {\r\n return this._nodeDataStorage._onClonedObservable;\r\n }\r\n\r\n /**\r\n * Creates a new Node\r\n * @param name the name and id to be given to this node\r\n * @param scene the scene this node will be added to\r\n */\r\n constructor(name: string, scene: Nullable = null) {\r\n this.name = name;\r\n this.id = name;\r\n this._scene = (scene || EngineStore.LastCreatedScene);\r\n this.uniqueId = this._scene.getUniqueId();\r\n this._initCache();\r\n }\r\n\r\n /**\r\n * Gets the scene of the node\r\n * @returns a scene\r\n */\r\n public getScene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Gets the engine of the node\r\n * @returns a Engine\r\n */\r\n public getEngine(): Engine {\r\n return this._scene.getEngine();\r\n }\r\n\r\n // Behaviors\r\n private _behaviors = new Array>();\r\n\r\n /**\r\n * Attach a behavior to the node\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\r\n * @param behavior defines the behavior to attach\r\n * @param attachImmediately defines that the behavior must be attached even if the scene is still loading\r\n * @returns the current Node\r\n */\r\n public addBehavior(behavior: Behavior, attachImmediately = false): Node {\r\n const index = this._behaviors.indexOf(behavior);\r\n\r\n if (index !== -1) {\r\n return this;\r\n }\r\n\r\n behavior.init();\r\n if (this._scene.isLoading && !attachImmediately) {\r\n // We defer the attach when the scene will be loaded\r\n this._scene.onDataLoadedObservable.addOnce(() => {\r\n behavior.attach(this);\r\n });\r\n } else {\r\n behavior.attach(this);\r\n }\r\n this._behaviors.push(behavior);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove an attached behavior\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\r\n * @param behavior defines the behavior to attach\r\n * @returns the current Node\r\n */\r\n public removeBehavior(behavior: Behavior): Node {\r\n const index = this._behaviors.indexOf(behavior);\r\n\r\n if (index === -1) {\r\n return this;\r\n }\r\n\r\n this._behaviors[index].detach();\r\n this._behaviors.splice(index, 1);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the list of attached behaviors\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\r\n */\r\n public get behaviors(): Behavior[] {\r\n return this._behaviors;\r\n }\r\n\r\n /**\r\n * Gets an attached behavior by name\r\n * @param name defines the name of the behavior to look for\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors\r\n * @returns null if behavior was not found else the requested behavior\r\n */\r\n public getBehaviorByName(name: string): Nullable> {\r\n for (const behavior of this._behaviors) {\r\n if (behavior.name === name) {\r\n return behavior;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Returns the latest update of the World matrix\r\n * @returns a Matrix\r\n */\r\n public getWorldMatrix(): Matrix {\r\n if (this._currentRenderId !== this._scene.getRenderId()) {\r\n this.computeWorldMatrix();\r\n }\r\n return this._worldMatrix;\r\n }\r\n\r\n /** @internal */\r\n public _getWorldMatrixDeterminant(): number {\r\n if (this._worldMatrixDeterminantIsDirty) {\r\n this._worldMatrixDeterminantIsDirty = false;\r\n this._worldMatrixDeterminant = this._worldMatrix.determinant();\r\n }\r\n return this._worldMatrixDeterminant;\r\n }\r\n\r\n /**\r\n * Returns directly the latest state of the mesh World matrix.\r\n * A Matrix is returned.\r\n */\r\n public get worldMatrixFromCache(): Matrix {\r\n return this._worldMatrix;\r\n }\r\n\r\n // override it in derived class if you add new variables to the cache\r\n // and call the parent class method\r\n /** @internal */\r\n public _initCache() {\r\n this._cache = {};\r\n this._cache.parent = undefined;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public updateCache(force?: boolean): void {\r\n if (!force && this.isSynchronized()) {\r\n return;\r\n }\r\n\r\n this._cache.parent = this.parent;\r\n\r\n this._updateCache();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getActionManagerForTrigger(trigger?: number, _initialCall = true): Nullable {\r\n if (!this.parent) {\r\n return null;\r\n }\r\n\r\n return this.parent._getActionManagerForTrigger(trigger, false);\r\n }\r\n\r\n // override it in derived class if you add new variables to the cache\r\n // and call the parent class method if !ignoreParentClass\r\n /**\r\n * @internal\r\n */\r\n public _updateCache(_ignoreParentClass?: boolean): void {}\r\n\r\n // override it in derived class if you add new variables to the cache\r\n /** @internal */\r\n public _isSynchronized(): boolean {\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public _markSyncedWithParent() {\r\n if (this._parentNode) {\r\n this._parentUpdateId = this._parentNode._childUpdateId;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public isSynchronizedWithParent(): boolean {\r\n if (!this._parentNode) {\r\n return true;\r\n }\r\n\r\n if (this._parentNode._isDirty || this._parentUpdateId !== this._parentNode._childUpdateId) {\r\n return false;\r\n }\r\n\r\n return this._parentNode.isSynchronized();\r\n }\r\n\r\n /** @internal */\r\n public isSynchronized(): boolean {\r\n if (this._cache.parent !== this._parentNode) {\r\n this._cache.parent = this._parentNode;\r\n return false;\r\n }\r\n\r\n if (this._parentNode && !this.isSynchronizedWithParent()) {\r\n return false;\r\n }\r\n\r\n return this._isSynchronized();\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 * @returns true if the node is ready\r\n */\r\n public isReady(_completeCheck = false): boolean {\r\n return this._nodeDataStorage._isReady;\r\n }\r\n\r\n /**\r\n * Flag the node as dirty (Forcing it to update everything)\r\n * @param _property helps children apply precise \"dirtyfication\"\r\n * @returns this node\r\n */\r\n public markAsDirty(_property?: string): Node {\r\n this._currentRenderId = Number.MAX_VALUE;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Is this node enabled?\r\n * If the node has a parent, all ancestors will be checked and false will be returned if any are false (not enabled), otherwise will return true\r\n * @param checkAncestors indicates if this method should check the ancestors. The default is to check the ancestors. If set to false, the method will return the value of this node without checking ancestors\r\n * @returns whether this node (and its parent) is enabled\r\n */\r\n public isEnabled(checkAncestors: boolean = true): boolean {\r\n if (checkAncestors === false) {\r\n return this._nodeDataStorage._isEnabled;\r\n }\r\n\r\n if (!this._nodeDataStorage._isEnabled) {\r\n return false;\r\n }\r\n\r\n return this._nodeDataStorage._isParentEnabled;\r\n }\r\n\r\n /** @internal */\r\n protected _syncParentEnabledState() {\r\n this._nodeDataStorage._isParentEnabled = this._parentNode ? this._parentNode.isEnabled() : true;\r\n\r\n if (this._children) {\r\n this._children.forEach((c) => {\r\n c._syncParentEnabledState(); // Force children to update accordingly\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Set the enabled state of this node\r\n * @param value defines the new enabled state\r\n */\r\n public setEnabled(value: boolean): void {\r\n if (this._nodeDataStorage._isEnabled === value) {\r\n return;\r\n }\r\n this._nodeDataStorage._isEnabled = value;\r\n this._syncParentEnabledState();\r\n this._nodeDataStorage._onEnabledStateChangedObservable.notifyObservers(value);\r\n }\r\n\r\n /**\r\n * Is this node a descendant of the given node?\r\n * The function will iterate up the hierarchy until the ancestor was found or no more parents defined\r\n * @param ancestor defines the parent node to inspect\r\n * @returns a boolean indicating if this node is a descendant of the given node\r\n */\r\n public isDescendantOf(ancestor: Node): boolean {\r\n if (this.parent) {\r\n if (this.parent === ancestor) {\r\n return true;\r\n }\r\n\r\n return this.parent.isDescendantOf(ancestor);\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getDescendants(results: Node[], directDescendantsOnly: boolean = false, predicate?: (node: Node) => boolean): void {\r\n if (!this._children) {\r\n return;\r\n }\r\n\r\n for (let index = 0; index < this._children.length; index++) {\r\n const item = this._children[index];\r\n\r\n if (!predicate || predicate(item)) {\r\n results.push(item);\r\n }\r\n\r\n if (!directDescendantsOnly) {\r\n item._getDescendants(results, false, predicate);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Will return all nodes that have this node as ascendant\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns all children nodes of all types\r\n */\r\n public getDescendants(directDescendantsOnly?: boolean, predicate?: (node: Node) => node is T): T[];\r\n\r\n /**\r\n * Will return all nodes that have this node as ascendant\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns all children nodes of all types\r\n */\r\n public getDescendants(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): Node[];\r\n\r\n /**\r\n * Will return all nodes that have this node as ascendant\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns all children nodes of all types\r\n */\r\n public getDescendants(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): Node[] {\r\n const results = new Array();\r\n\r\n this._getDescendants(results, directDescendantsOnly, predicate);\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Get all child-meshes of this node\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: false)\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns an array of AbstractMesh\r\n */\r\n public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => node is T): T[];\r\n\r\n /**\r\n * Get all child-meshes of this node\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: false)\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns an array of AbstractMesh\r\n */\r\n public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[];\r\n\r\n /**\r\n * Get all child-meshes of this node\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: false)\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns an array of AbstractMesh\r\n */\r\n public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[] {\r\n const results: Array = [];\r\n this._getDescendants(results, directDescendantsOnly, (node: Node) => {\r\n return (!predicate || predicate(node)) && (node).cullingStrategy !== undefined;\r\n });\r\n return results;\r\n }\r\n\r\n /**\r\n * Get all direct children of this node\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)\r\n * @returns an array of Node\r\n */\r\n public getChildren(predicate?: (node: Node) => node is T, directDescendantsOnly?: boolean): T[];\r\n\r\n /**\r\n * Get all direct children of this node\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)\r\n * @returns an array of Node\r\n */\r\n public getChildren(predicate?: (node: Node) => boolean, directDescendantsOnly?: boolean): Node[];\r\n\r\n /**\r\n * Get all direct children of this node\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)\r\n * @returns an array of Node\r\n */\r\n public getChildren(predicate?: (node: Node) => boolean, directDescendantsOnly = true): Node[] {\r\n return this.getDescendants(directDescendantsOnly, predicate);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setReady(state: boolean): void {\r\n if (state === this._nodeDataStorage._isReady) {\r\n return;\r\n }\r\n\r\n if (!state) {\r\n this._nodeDataStorage._isReady = false;\r\n return;\r\n }\r\n\r\n if (this.onReady) {\r\n this.onReady(this);\r\n }\r\n this._nodeDataStorage._isReady = true;\r\n }\r\n\r\n /**\r\n * Get an animation by name\r\n * @param name defines the name of the animation to look for\r\n * @returns null if not found else the requested animation\r\n */\r\n public getAnimationByName(name: string): Nullable {\r\n for (let i = 0; i < this.animations.length; i++) {\r\n const animation = this.animations[i];\r\n\r\n if (animation.name === name) {\r\n return animation;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Creates an animation range for this node\r\n * @param name defines the name of the range\r\n * @param from defines the starting key\r\n * @param to defines the end key\r\n */\r\n public createAnimationRange(name: string, from: number, to: number): void {\r\n // check name not already in use\r\n if (!this._ranges[name]) {\r\n this._ranges[name] = Node._AnimationRangeFactory(name, from, to);\r\n for (let i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {\r\n if (this.animations[i]) {\r\n this.animations[i].createRange(name, from, to);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Delete a specific animation range\r\n * @param name defines the name of the range to delete\r\n * @param deleteFrames defines if animation frames from the range must be deleted as well\r\n */\r\n public deleteAnimationRange(name: string, deleteFrames = true): void {\r\n for (let i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {\r\n if (this.animations[i]) {\r\n this.animations[i].deleteRange(name, deleteFrames);\r\n }\r\n }\r\n this._ranges[name] = null; // said much faster than 'delete this._range[name]'\r\n }\r\n\r\n /**\r\n * Get an animation range by name\r\n * @param name defines the name of the animation range to look for\r\n * @returns null if not found else the requested animation range\r\n */\r\n public getAnimationRange(name: string): Nullable {\r\n return this._ranges[name] || null;\r\n }\r\n\r\n /**\r\n * Clone the current node\r\n * @param name Name of the new clone\r\n * @param newParent New parent for the clone\r\n * @param doNotCloneChildren Do not clone children hierarchy\r\n * @returns the new transform node\r\n */\r\n public clone(name: string, newParent: Nullable, doNotCloneChildren?: boolean): Nullable {\r\n const result = SerializationHelper.Clone(() => new Node(name, this.getScene()), this);\r\n\r\n if (newParent) {\r\n result.parent = newParent;\r\n }\r\n\r\n if (!doNotCloneChildren) {\r\n // Children\r\n const directDescendants = this.getDescendants(true);\r\n for (let index = 0; index < directDescendants.length; index++) {\r\n const child = directDescendants[index];\r\n\r\n child.clone(name + \".\" + child.name, result);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets the list of all animation ranges defined on this node\r\n * @returns an array\r\n */\r\n public getAnimationRanges(): Nullable[] {\r\n const animationRanges: Nullable[] = [];\r\n let name: string;\r\n for (name in this._ranges) {\r\n animationRanges.push(this._ranges[name]);\r\n }\r\n return animationRanges;\r\n }\r\n\r\n /**\r\n * Will start the animation sequence\r\n * @param name defines the range frames for animation sequence\r\n * @param loop defines if the animation should loop (false by default)\r\n * @param speedRatio defines the speed factor in which to run the animation (1 by default)\r\n * @param onAnimationEnd defines a function to be executed when the animation ended (undefined by default)\r\n * @returns the object created for this animation. If range does not exist, it will return null\r\n */\r\n public beginAnimation(name: string, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): Nullable {\r\n const range = this.getAnimationRange(name);\r\n\r\n if (!range) {\r\n return null;\r\n }\r\n\r\n return this._scene.beginAnimation(this, range.from, range.to, loop, speedRatio, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Serialize animation ranges into a JSON compatible object\r\n * @returns serialization object\r\n */\r\n public serializeAnimationRanges(): any {\r\n const serializationRanges = [];\r\n for (const name in this._ranges) {\r\n const localRange = this._ranges[name];\r\n if (!localRange) {\r\n continue;\r\n }\r\n const range: any = {};\r\n range.name = name;\r\n range.from = localRange.from;\r\n range.to = localRange.to;\r\n serializationRanges.push(range);\r\n }\r\n return serializationRanges;\r\n }\r\n\r\n /**\r\n * Computes the world matrix of the node\r\n * @param _force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\r\n * @returns the world matrix\r\n */\r\n public computeWorldMatrix(_force?: boolean): Matrix {\r\n if (!this._worldMatrix) {\r\n this._worldMatrix = Matrix.Identity();\r\n }\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * Releases resources associated with this node.\r\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\r\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n this._nodeDataStorage._isDisposed = true;\r\n\r\n if (!doNotRecurse) {\r\n const nodes = this.getDescendants(true);\r\n for (const node of nodes) {\r\n node.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n }\r\n\r\n if (!this.parent) {\r\n this._removeFromSceneRootNodes();\r\n } else {\r\n this.parent = null;\r\n }\r\n\r\n // Callback\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n\r\n this.onEnabledStateChangedObservable.clear();\r\n this.onClonedObservable.clear();\r\n\r\n // Behaviors\r\n for (const behavior of this._behaviors) {\r\n behavior.detach();\r\n }\r\n\r\n this._behaviors.length = 0;\r\n\r\n this.metadata = null;\r\n }\r\n\r\n /**\r\n * Parse animation range data from a serialization object and store them into a given node\r\n * @param node defines where to store the animation ranges\r\n * @param parsedNode defines the serialization object to read data from\r\n * @param _scene defines the hosting scene\r\n */\r\n public static ParseAnimationRanges(node: Node, parsedNode: any, _scene: Scene): void {\r\n if (parsedNode.ranges) {\r\n for (let index = 0; index < parsedNode.ranges.length; index++) {\r\n const data = parsedNode.ranges[index];\r\n node.createAnimationRange(data.name, data.from, data.to);\r\n }\r\n }\r\n }\r\n /**\r\n * Return the minimum and maximum world vectors of the entire hierarchy under current node\r\n * @param includeDescendants Include bounding info from descendants as well (true by default)\r\n * @param predicate defines a callback function that can be customize to filter what meshes should be included in the list used to compute the bounding vectors\r\n * @returns the new bounding vectors\r\n */\r\n public getHierarchyBoundingVectors(includeDescendants = true, predicate: Nullable<(abstractMesh: AbstractMesh) => boolean> = null): { min: Vector3; max: Vector3 } {\r\n // Ensures that all world matrix will be recomputed.\r\n this.getScene().incrementRenderId();\r\n\r\n this.computeWorldMatrix(true);\r\n\r\n let min: Vector3;\r\n let max: Vector3;\r\n\r\n const thisAbstractMesh = this as Node as AbstractMesh;\r\n if (thisAbstractMesh.getBoundingInfo && thisAbstractMesh.subMeshes) {\r\n // If this is an abstract mesh get its bounding info\r\n const boundingInfo = thisAbstractMesh.getBoundingInfo();\r\n min = boundingInfo.boundingBox.minimumWorld.clone();\r\n max = boundingInfo.boundingBox.maximumWorld.clone();\r\n } else {\r\n min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\r\n }\r\n\r\n if (includeDescendants) {\r\n const descendants = this.getDescendants(false);\r\n\r\n for (const descendant of descendants) {\r\n const childMesh = descendant;\r\n childMesh.computeWorldMatrix(true);\r\n\r\n // Filters meshes based on custom predicate function.\r\n if (predicate && !predicate(childMesh)) {\r\n continue;\r\n }\r\n\r\n //make sure we have the needed params to get mix and max\r\n if (!childMesh.getBoundingInfo || childMesh.getTotalVertices() === 0) {\r\n continue;\r\n }\r\n\r\n const childBoundingInfo = childMesh.getBoundingInfo();\r\n const boundingBox = childBoundingInfo.boundingBox;\r\n\r\n const minBox = boundingBox.minimumWorld;\r\n const maxBox = boundingBox.maximumWorld;\r\n\r\n Vector3.CheckExtends(minBox, min, max);\r\n Vector3.CheckExtends(maxBox, min, max);\r\n }\r\n }\r\n\r\n return {\r\n min: min,\r\n max: max,\r\n };\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n/**\r\n * Checks if the window object exists\r\n * @returns true if the window object exists\r\n */\r\nexport function IsWindowObjectExist(): boolean {\r\n return typeof window !== \"undefined\";\r\n}\r\n\r\n/**\r\n * Checks if the navigator object exists\r\n * @returns true if the navigator object exists\r\n */\r\nexport function IsNavigatorAvailable(): boolean {\r\n return typeof navigator !== \"undefined\";\r\n}\r\n\r\n/**\r\n * Check if the document object exists\r\n * @returns true if the document object exists\r\n */\r\nexport function IsDocumentAvailable(): boolean {\r\n return typeof document !== \"undefined\";\r\n}\r\n\r\n/**\r\n * Extracts text content from a DOM element hierarchy\r\n * @param element defines the root element\r\n * @returns a string\r\n */\r\nexport function GetDOMTextContent(element: HTMLElement): string {\r\n let result = \"\";\r\n let child = element.firstChild;\r\n\r\n while (child) {\r\n if (child.nodeType === 3) {\r\n result += child.textContent;\r\n }\r\n child = child.nextSibling;\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Sets of helpers dealing with the DOM and some of the recurrent functions needed in\r\n * Babylon.js\r\n */\r\nexport const DomManagement = {\r\n /**\r\n * Checks if the window object exists\r\n * @returns true if the window object exists\r\n */\r\n IsWindowObjectExist,\r\n\r\n /**\r\n * Checks if the navigator object exists\r\n * @returns true if the navigator object exists\r\n */\r\n IsNavigatorAvailable,\r\n\r\n /**\r\n * Check if the document object exists\r\n * @returns true if the document object exists\r\n */\r\n IsDocumentAvailable,\r\n /**\r\n * Extracts text content from a DOM element hierarchy\r\n * @param element defines the root element\r\n * @returns a string\r\n */\r\n GetDOMTextContent,\r\n};\r\n","/**\r\n * Logger used throughout the application to allow configuration of\r\n * the log level required for the messages.\r\n */\r\nexport class Logger {\r\n /**\r\n * No log\r\n */\r\n public static readonly NoneLogLevel = 0;\r\n /**\r\n * Only message logs\r\n */\r\n public static readonly MessageLogLevel = 1;\r\n /**\r\n * Only warning logs\r\n */\r\n public static readonly WarningLogLevel = 2;\r\n /**\r\n * Only error logs\r\n */\r\n public static readonly ErrorLogLevel = 4;\r\n /**\r\n * All logs\r\n */\r\n public static readonly AllLogLevel = 7;\r\n\r\n /**\r\n * Message to display when a message has been logged too many times\r\n */\r\n public static MessageLimitReached = \"Too many %TYPE%s (%LIMIT%), no more %TYPE%s will be reported for this message.\";\r\n\r\n private static _LogCache = \"\";\r\n private static _LogLimitOutputs: { [message: string]: { limit: number; current: number } } = {};\r\n // levels according to the (binary) numbering.\r\n private static _Levels = [\r\n {},\r\n { color: \"white\", logFunc: console.log, name: \"Log\" },\r\n { color: \"orange\", logFunc: console.warn, name: \"Warn\" },\r\n {},\r\n { color: \"red\", logFunc: console.error, name: \"Error\" },\r\n ];\r\n\r\n /**\r\n * Gets a value indicating the number of loading errors\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static errorsCount = 0;\r\n\r\n /**\r\n * Callback called when a new log is added\r\n */\r\n public static OnNewCacheEntry: (entry: string) => void;\r\n\r\n private static _CheckLimit(message: string, limit: number): boolean {\r\n let entry = Logger._LogLimitOutputs[message];\r\n if (!entry) {\r\n entry = { limit, current: 1 };\r\n Logger._LogLimitOutputs[message] = entry;\r\n } else {\r\n entry.current++;\r\n }\r\n return entry.current <= entry.limit;\r\n }\r\n\r\n private static _GenerateLimitMessage(message: string, level: number = 1): void {\r\n const entry = Logger._LogLimitOutputs[message];\r\n if (!entry || !Logger.MessageLimitReached) {\r\n return;\r\n }\r\n const type = this._Levels[level];\r\n if (entry.current === entry.limit) {\r\n Logger[type.name as \"Log\" | \"Warn\" | \"Error\"](Logger.MessageLimitReached.replace(/%LIMIT%/g, \"\" + entry.limit).replace(/%TYPE%/g, type.name ?? \"\"));\r\n }\r\n }\r\n\r\n private static _AddLogEntry(entry: string) {\r\n Logger._LogCache = entry + Logger._LogCache;\r\n\r\n if (Logger.OnNewCacheEntry) {\r\n Logger.OnNewCacheEntry(entry);\r\n }\r\n }\r\n\r\n private static _FormatMessage(message: string): string {\r\n const padStr = (i: number) => (i < 10 ? \"0\" + i : \"\" + i);\r\n\r\n const date = new Date();\r\n return \"[\" + padStr(date.getHours()) + \":\" + padStr(date.getMinutes()) + \":\" + padStr(date.getSeconds()) + \"]: \" + message;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private static _LogDisabled(message: string, limit?: number): void {\r\n // nothing to do\r\n }\r\n private static _LogEnabled(level: number = 1, message: string, limit?: number): void {\r\n if (limit !== undefined && !Logger._CheckLimit(message, limit)) {\r\n return;\r\n }\r\n\r\n const formattedMessage = Logger._FormatMessage(message);\r\n const type = this._Levels[level];\r\n type.logFunc && type.logFunc(\"BJS - \" + formattedMessage);\r\n\r\n const entry = `
${formattedMessage}

`;\r\n Logger._AddLogEntry(entry);\r\n Logger._GenerateLimitMessage(message, level);\r\n }\r\n\r\n /**\r\n * Log a message to the console\r\n */\r\n public static Log: (message: string, limit?: number) => void = Logger._LogEnabled.bind(Logger, Logger.MessageLogLevel);\r\n\r\n /**\r\n * Write a warning message to the console\r\n */\r\n public static Warn: (message: string, limit?: number) => void = Logger._LogEnabled.bind(Logger, Logger.WarningLogLevel);\r\n\r\n /**\r\n * Write an error message to the console\r\n */\r\n public static Error: (message: string, limit?: number) => void = Logger._LogEnabled.bind(Logger, Logger.ErrorLogLevel);\r\n\r\n /**\r\n * Gets current log cache (list of logs)\r\n */\r\n public static get LogCache(): string {\r\n return Logger._LogCache;\r\n }\r\n\r\n /**\r\n * Clears the log cache\r\n */\r\n public static ClearLogCache(): void {\r\n Logger._LogCache = \"\";\r\n Logger._LogLimitOutputs = {};\r\n Logger.errorsCount = 0;\r\n }\r\n\r\n /**\r\n * Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)\r\n */\r\n public static set LogLevels(level: number) {\r\n Logger.Log = Logger._LogDisabled;\r\n Logger.Warn = Logger._LogDisabled;\r\n Logger.Error = Logger._LogDisabled;\r\n [Logger.MessageLogLevel, Logger.WarningLogLevel, Logger.ErrorLogLevel].forEach((l) => {\r\n if ((level & l) === l) {\r\n const type = this._Levels[l];\r\n Logger[type.name as \"Log\" | \"Warn\" | \"Error\"] = Logger._LogEnabled.bind(Logger, l);\r\n }\r\n });\r\n }\r\n}\r\n","import { Logger } from \"./logger\";\r\n\r\nconst CloneValue = (source: any, destinationObject: any) => {\r\n if (!source) {\r\n return null;\r\n }\r\n\r\n if (source.getClassName && source.getClassName() === \"Mesh\") {\r\n return null;\r\n }\r\n\r\n if (source.getClassName && (source.getClassName() === \"SubMesh\" || source.getClassName() === \"PhysicsBody\")) {\r\n return source.clone(destinationObject);\r\n } else if (source.clone) {\r\n return source.clone();\r\n } else if (Array.isArray(source)) {\r\n return source.slice();\r\n }\r\n return null;\r\n};\r\n\r\nfunction GetAllPropertyNames(obj: any): string[] {\r\n const props: string[] = [];\r\n\r\n do {\r\n Object.getOwnPropertyNames(obj).forEach(function (prop) {\r\n if (props.indexOf(prop) === -1) {\r\n props.push(prop);\r\n }\r\n });\r\n } while ((obj = Object.getPrototypeOf(obj)));\r\n\r\n return props;\r\n}\r\n\r\n/**\r\n * Class containing a set of static utilities functions for deep copy.\r\n */\r\nexport class DeepCopier {\r\n /**\r\n * Tries to copy an object by duplicating every property\r\n * @param source defines the source object\r\n * @param destination defines the target object\r\n * @param doNotCopyList defines a list of properties to avoid\r\n * @param mustCopyList defines a list of properties to copy (even if they start with _)\r\n */\r\n public static DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void {\r\n const properties = GetAllPropertyNames(source);\r\n for (const prop of properties) {\r\n if (prop[0] === \"_\" && (!mustCopyList || mustCopyList.indexOf(prop) === -1)) {\r\n continue;\r\n }\r\n\r\n if (prop.endsWith(\"Observable\")) {\r\n continue;\r\n }\r\n\r\n if (doNotCopyList && doNotCopyList.indexOf(prop) !== -1) {\r\n continue;\r\n }\r\n\r\n const sourceValue = source[prop];\r\n const typeOfSourceValue = typeof sourceValue;\r\n\r\n if (typeOfSourceValue === \"function\") {\r\n continue;\r\n }\r\n\r\n try {\r\n if (typeOfSourceValue === \"object\") {\r\n if (sourceValue instanceof Uint8Array) {\r\n destination[prop] = Uint8Array.from(sourceValue);\r\n } else if (sourceValue instanceof Array) {\r\n destination[prop] = [];\r\n\r\n if (sourceValue.length > 0) {\r\n if (typeof sourceValue[0] == \"object\") {\r\n for (let index = 0; index < sourceValue.length; index++) {\r\n const clonedValue = CloneValue(sourceValue[index], destination);\r\n\r\n if (destination[prop].indexOf(clonedValue) === -1) {\r\n // Test if auto inject was not done\r\n destination[prop].push(clonedValue);\r\n }\r\n }\r\n } else {\r\n destination[prop] = sourceValue.slice(0);\r\n }\r\n }\r\n } else {\r\n destination[prop] = CloneValue(sourceValue, destination);\r\n }\r\n } else {\r\n destination[prop] = sourceValue;\r\n }\r\n } catch (e) {\r\n // Log a warning (it could be because of a read-only property)\r\n Logger.Warn(e.message);\r\n }\r\n }\r\n }\r\n}\r\n","import { IsWindowObjectExist } from \"./domManagement\";\r\n\r\n/**\r\n * Class containing a set of static utilities functions for precision date\r\n */\r\nexport class PrecisionDate {\r\n /**\r\n * Gets either window.performance.now() if supported or Date.now() else\r\n */\r\n public static get Now(): number {\r\n if (IsWindowObjectExist() && window.performance && window.performance.now) {\r\n return window.performance.now();\r\n }\r\n\r\n return Date.now();\r\n }\r\n}\r\n","import type { IWebRequest } from \"./interfaces/iWebRequest\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { INative } from \"../Engines/Native/nativeInterfaces\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const _native: INative;\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nfunction createXMLHttpRequest(): XMLHttpRequest {\r\n // If running in Babylon Native, then defer to the native XMLHttpRequest, which has the same public contract\r\n if (typeof _native !== \"undefined\" && _native.XMLHttpRequest) {\r\n return new _native.XMLHttpRequest();\r\n } else {\r\n return new XMLHttpRequest();\r\n }\r\n}\r\n\r\n/**\r\n * Extended version of XMLHttpRequest with support for customizations (headers, ...)\r\n */\r\nexport class WebRequest implements IWebRequest {\r\n private readonly _xhr = createXMLHttpRequest();\r\n\r\n /**\r\n * Custom HTTP Request Headers to be sent with XMLHttpRequests\r\n * i.e. when loading files, where the server/service expects an Authorization header\r\n */\r\n public static CustomRequestHeaders: { [key: string]: string } = {};\r\n\r\n /**\r\n * Add callback functions in this array to update all the requests before they get sent to the network\r\n */\r\n public static CustomRequestModifiers = new Array<(request: XMLHttpRequest, url: string) => void>();\r\n\r\n public static SkipRequestModificationForBabylonCDN = true;\r\n\r\n private _requestURL: string = \"\";\r\n\r\n private _injectCustomRequestHeaders(): void {\r\n if (this._shouldSkipRequestModifications(this._requestURL)) {\r\n return;\r\n }\r\n for (const key in WebRequest.CustomRequestHeaders) {\r\n const val = WebRequest.CustomRequestHeaders[key];\r\n if (val) {\r\n this._xhr.setRequestHeader(key, val);\r\n }\r\n }\r\n }\r\n\r\n private _shouldSkipRequestModifications(url: string): boolean {\r\n return WebRequest.SkipRequestModificationForBabylonCDN && (url.includes(\"preview.babylonjs.com\") || url.includes(\"cdn.babylonjs.com\"));\r\n }\r\n\r\n /**\r\n * Gets or sets a function to be called when loading progress changes\r\n */\r\n public get onprogress(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null {\r\n return this._xhr.onprogress;\r\n }\r\n\r\n public set onprogress(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null) {\r\n this._xhr.onprogress = value;\r\n }\r\n\r\n /**\r\n * Returns client's state\r\n */\r\n public get readyState(): number {\r\n return this._xhr.readyState;\r\n }\r\n\r\n /**\r\n * Returns client's status\r\n */\r\n public get status(): number {\r\n return this._xhr.status;\r\n }\r\n\r\n /**\r\n * Returns client's status as a text\r\n */\r\n public get statusText(): string {\r\n return this._xhr.statusText;\r\n }\r\n\r\n /**\r\n * Returns client's response\r\n */\r\n public get response(): any {\r\n return this._xhr.response;\r\n }\r\n\r\n /**\r\n * Returns client's response url\r\n */\r\n public get responseURL(): string {\r\n return this._xhr.responseURL;\r\n }\r\n\r\n /**\r\n * Returns client's response as text\r\n */\r\n public get responseText(): string {\r\n return this._xhr.responseText;\r\n }\r\n\r\n /**\r\n * Gets or sets the expected response type\r\n */\r\n public get responseType(): XMLHttpRequestResponseType {\r\n return this._xhr.responseType;\r\n }\r\n\r\n public set responseType(value: XMLHttpRequestResponseType) {\r\n this._xhr.responseType = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the timeout value in milliseconds\r\n */\r\n public get timeout(): number {\r\n return this._xhr.timeout;\r\n }\r\n\r\n public set timeout(value: number) {\r\n this._xhr.timeout = value;\r\n }\r\n\r\n /** @internal */\r\n public addEventListener(\r\n type: K,\r\n listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,\r\n options?: boolean | AddEventListenerOptions\r\n ): void;\r\n public addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {\r\n this._xhr.addEventListener(type, listener, options);\r\n }\r\n\r\n /** @internal */\r\n public removeEventListener(\r\n type: K,\r\n listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,\r\n options?: boolean | EventListenerOptions\r\n ): void;\r\n public removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void {\r\n this._xhr.removeEventListener(type, listener, options);\r\n }\r\n\r\n /**\r\n * Cancels any network activity\r\n */\r\n public abort() {\r\n this._xhr.abort();\r\n }\r\n\r\n /**\r\n * Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD\r\n * @param body defines an optional request body\r\n */\r\n public send(body?: Document | XMLHttpRequestBodyInit | null): void {\r\n if (WebRequest.CustomRequestHeaders) {\r\n this._injectCustomRequestHeaders();\r\n }\r\n\r\n this._xhr.send(body);\r\n }\r\n\r\n /**\r\n * Sets the request method, request URL\r\n * @param method defines the method to use (GET, POST, etc..)\r\n * @param url defines the url to connect with\r\n */\r\n public open(method: string, url: string): void {\r\n for (const update of WebRequest.CustomRequestModifiers) {\r\n if (this._shouldSkipRequestModifications(url)) {\r\n return;\r\n }\r\n update(this._xhr, url);\r\n }\r\n\r\n // Clean url\r\n url = url.replace(\"file:http:\", \"http:\");\r\n url = url.replace(\"file:https:\", \"https:\");\r\n\r\n this._requestURL = url;\r\n\r\n return this._xhr.open(method, url, true);\r\n }\r\n\r\n /**\r\n * Sets the value of a request header.\r\n * @param name The name of the header whose value is to be set\r\n * @param value The value to set as the body of the header\r\n */\r\n setRequestHeader(name: string, value: string): void {\r\n this._xhr.setRequestHeader(name, value);\r\n }\r\n\r\n /**\r\n * Get the string containing the text of a particular header's value.\r\n * @param name The name of the header\r\n * @returns The string containing the text of the given header name\r\n */\r\n getResponseHeader(name: string): Nullable {\r\n return this._xhr.getResponseHeader(name);\r\n }\r\n}\r\n","/**\r\n * Class used to help managing file picking and drag'n'drop\r\n * File Storage\r\n */\r\nexport class FilesInputStore {\r\n /**\r\n * List of files ready to be loaded\r\n */\r\n public static FilesToLoad: { [key: string]: File } = {};\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n/**\r\n * Base error. Due to limitations of typedoc-check and missing documentation\r\n * in lib.es5.d.ts, cannot extend Error directly for RuntimeError.\r\n * @ignore\r\n */\r\nexport abstract class BaseError extends Error {\r\n // See https://stackoverflow.com/questions/12915412/how-do-i-extend-a-host-object-e-g-error-in-typescript\r\n // and https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work\r\n\r\n // Polyfill for Object.setPrototypeOf if necessary.\r\n protected static _setPrototypeOf: (o: any, proto: object | null) => any =\r\n (Object as any).setPrototypeOf ||\r\n ((o, proto) => {\r\n o.__proto__ = proto;\r\n return o;\r\n });\r\n}\r\n\r\n/* IMP! DO NOT CHANGE THE NUMBERING OF EXISTING ERROR CODES */\r\n/**\r\n * Error codes for BaseError\r\n */\r\nexport const ErrorCodes = {\r\n // Mesh errors 0-999\r\n /** Invalid or empty mesh vertex positions. */\r\n MeshInvalidPositionsError: 0,\r\n\r\n // Texture errors 1000-1999\r\n /** Unsupported texture found. */\r\n UnsupportedTextureError: 1000,\r\n\r\n // GLTFLoader errors 2000-2999\r\n /** Unexpected magic number found in GLTF file header. */\r\n GLTFLoaderUnexpectedMagicError: 2000,\r\n\r\n // SceneLoader errors 3000-3999\r\n /** SceneLoader generic error code. Ideally wraps the inner exception. */\r\n SceneLoaderError: 3000,\r\n\r\n // File related errors 4000-4999\r\n /** Load file error */\r\n LoadFileError: 4000,\r\n /** Request file error */\r\n RequestFileError: 4001,\r\n /** Read file error */\r\n ReadFileError: 4002,\r\n} as const;\r\n\r\n/**\r\n * Error code type\r\n */\r\nexport type ErrorCodesType = (typeof ErrorCodes)[keyof typeof ErrorCodes];\r\n\r\n/**\r\n * Application runtime error\r\n */\r\nexport class RuntimeError extends BaseError {\r\n /**\r\n * The error code\r\n */\r\n public errorCode: ErrorCodesType;\r\n\r\n /**\r\n * The error that caused this outer error\r\n */\r\n public innerError?: Error;\r\n\r\n /**\r\n * Creates a new RuntimeError\r\n * @param message defines the message of the error\r\n * @param errorCode the error code\r\n * @param innerError the error that caused the outer error\r\n */\r\n public constructor(message: string, errorCode: ErrorCodesType, innerError?: Error) {\r\n super(message);\r\n\r\n this.errorCode = errorCode;\r\n this.innerError = innerError;\r\n\r\n this.name = \"RuntimeError\";\r\n BaseError._setPrototypeOf(this, RuntimeError.prototype);\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\n/**\r\n * Checks for a matching suffix at the end of a string (for ES5 and lower)\r\n * @param str Source string\r\n * @param suffix Suffix to search for in the source string\r\n * @returns Boolean indicating whether the suffix was found (true) or not (false)\r\n * @deprecated Please use native string function instead\r\n */\r\nexport const EndsWith = (str: string, suffix: string): boolean => {\r\n return str.endsWith(suffix);\r\n};\r\n\r\n/**\r\n * Checks for a matching suffix at the beginning of a string (for ES5 and lower)\r\n * @param str Source string\r\n * @param suffix Suffix to search for in the source string\r\n * @returns Boolean indicating whether the suffix was found (true) or not (false)\r\n * @deprecated Please use native string function instead\r\n */\r\nexport const StartsWith = (str: string, suffix: string): boolean => {\r\n if (!str) {\r\n return false;\r\n }\r\n return str.startsWith(suffix);\r\n};\r\n\r\n/**\r\n * Decodes a buffer into a string\r\n * @param buffer The buffer to decode\r\n * @returns The decoded string\r\n */\r\nexport const Decode = (buffer: Uint8Array | Uint16Array): string => {\r\n if (typeof TextDecoder !== \"undefined\") {\r\n return new TextDecoder().decode(buffer);\r\n }\r\n\r\n let result = \"\";\r\n for (let i = 0; i < buffer.byteLength; i++) {\r\n result += String.fromCharCode(buffer[i]);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Encode a buffer to a base64 string\r\n * @param buffer defines the buffer to encode\r\n * @returns the encoded string\r\n */\r\nexport const EncodeArrayBufferToBase64 = (buffer: ArrayBuffer | ArrayBufferView): string => {\r\n const keyStr = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\r\n let output = \"\";\r\n let chr1, chr2, chr3, enc1, enc2, enc3, enc4;\r\n let i = 0;\r\n const bytes = ArrayBuffer.isView(buffer) ? new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength) : new Uint8Array(buffer);\r\n\r\n while (i < bytes.length) {\r\n chr1 = bytes[i++];\r\n chr2 = i < bytes.length ? bytes[i++] : Number.NaN;\r\n chr3 = i < bytes.length ? bytes[i++] : Number.NaN;\r\n\r\n enc1 = chr1 >> 2;\r\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\r\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\r\n enc4 = chr3 & 63;\r\n\r\n if (isNaN(chr2)) {\r\n enc3 = enc4 = 64;\r\n } else if (isNaN(chr3)) {\r\n enc4 = 64;\r\n }\r\n output += keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);\r\n }\r\n\r\n return output;\r\n};\r\n\r\n/**\r\n * Converts a given base64 string as an ASCII encoded stream of data\r\n * @param base64Data The base64 encoded string to decode\r\n * @returns Decoded ASCII string\r\n */\r\nexport const DecodeBase64ToString = (base64Data: string): string => {\r\n return atob(base64Data);\r\n};\r\n\r\n/**\r\n * Converts a given base64 string into an ArrayBuffer of raw byte data\r\n * @param base64Data The base64 encoded string to decode\r\n * @returns ArrayBuffer of byte data\r\n */\r\nexport const DecodeBase64ToBinary = (base64Data: string): ArrayBuffer => {\r\n const decodedString = DecodeBase64ToString(base64Data);\r\n const bufferLength = decodedString.length;\r\n const bufferView = new Uint8Array(new ArrayBuffer(bufferLength));\r\n\r\n for (let i = 0; i < bufferLength; i++) {\r\n bufferView[i] = decodedString.charCodeAt(i);\r\n }\r\n\r\n return bufferView.buffer;\r\n};\r\n\r\n/**\r\n * Converts a number to string and pads with preceding zeroes until it is of specified length.\r\n * @param num the number to convert and pad\r\n * @param length the expected length of the string\r\n * @returns the padded string\r\n */\r\nexport const PadNumber = (num: number, length: number): string => {\r\n let str = String(num);\r\n while (str.length < length) {\r\n str = \"0\" + str;\r\n }\r\n return str;\r\n};\r\n/**\r\n * Helper to manipulate strings\r\n */\r\nexport const StringTools = {\r\n EndsWith,\r\n StartsWith,\r\n Decode,\r\n EncodeArrayBufferToBase64,\r\n DecodeBase64ToString,\r\n DecodeBase64ToBinary,\r\n PadNumber,\r\n};\r\n","import type { ProcessingOptions } from \"./shaderProcessingOptions\";\r\n\r\nconst defaultAttributeKeywordName = \"attribute\";\r\nconst defaultVaryingKeywordName = \"varying\";\r\n\r\n/** @internal */\r\nexport class ShaderCodeNode {\r\n line: string;\r\n children: ShaderCodeNode[] = [];\r\n additionalDefineKey?: string;\r\n additionalDefineValue?: string;\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n isValid(preprocessors: { [key: string]: string }): boolean {\r\n return true;\r\n }\r\n\r\n process(preprocessors: { [key: string]: string }, options: ProcessingOptions): string {\r\n let result = \"\";\r\n if (this.line) {\r\n let value: string = this.line;\r\n const processor = options.processor;\r\n if (processor) {\r\n // This must be done before other replacements to avoid mistakenly changing something that was already changed.\r\n if (processor.lineProcessor) {\r\n value = processor.lineProcessor(value, options.isFragment, options.processingContext);\r\n }\r\n\r\n const attributeKeyword = options.processor?.attributeKeywordName ?? defaultAttributeKeywordName;\r\n const varyingKeyword =\r\n options.isFragment && options.processor?.varyingFragmentKeywordName\r\n ? options.processor?.varyingFragmentKeywordName\r\n : !options.isFragment && options.processor?.varyingVertexKeywordName\r\n ? options.processor?.varyingVertexKeywordName\r\n : defaultVaryingKeywordName;\r\n\r\n if (!options.isFragment && processor.attributeProcessor && this.line.startsWith(attributeKeyword)) {\r\n value = processor.attributeProcessor(this.line, preprocessors, options.processingContext);\r\n } else if (\r\n processor.varyingProcessor &&\r\n (processor.varyingCheck?.(this.line, options.isFragment) || (!processor.varyingCheck && this.line.startsWith(varyingKeyword)))\r\n ) {\r\n value = processor.varyingProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\r\n } else if (processor.uniformProcessor && processor.uniformRegexp && processor.uniformRegexp.test(this.line)) {\r\n if (!options.lookForClosingBracketForUniformBuffer) {\r\n value = processor.uniformProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\r\n }\r\n } else if (processor.uniformBufferProcessor && processor.uniformBufferRegexp && processor.uniformBufferRegexp.test(this.line)) {\r\n if (!options.lookForClosingBracketForUniformBuffer) {\r\n value = processor.uniformBufferProcessor(this.line, options.isFragment, options.processingContext);\r\n options.lookForClosingBracketForUniformBuffer = true;\r\n }\r\n } else if (processor.textureProcessor && processor.textureRegexp && processor.textureRegexp.test(this.line)) {\r\n value = processor.textureProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\r\n } else if ((processor.uniformProcessor || processor.uniformBufferProcessor) && this.line.startsWith(\"uniform\") && !options.lookForClosingBracketForUniformBuffer) {\r\n const regex = /uniform\\s+(?:(?:highp)?|(?:lowp)?)\\s*(\\S+)\\s+(\\S+)\\s*;/;\r\n\r\n if (regex.test(this.line)) {\r\n // uniform\r\n if (processor.uniformProcessor) {\r\n value = processor.uniformProcessor(this.line, options.isFragment, preprocessors, options.processingContext);\r\n }\r\n } else {\r\n // Uniform buffer\r\n if (processor.uniformBufferProcessor) {\r\n value = processor.uniformBufferProcessor(this.line, options.isFragment, options.processingContext);\r\n options.lookForClosingBracketForUniformBuffer = true;\r\n }\r\n }\r\n }\r\n\r\n if (options.lookForClosingBracketForUniformBuffer && this.line.indexOf(\"}\") !== -1) {\r\n options.lookForClosingBracketForUniformBuffer = false;\r\n if (processor.endOfUniformBufferProcessor) {\r\n value = processor.endOfUniformBufferProcessor(this.line, options.isFragment, options.processingContext);\r\n }\r\n }\r\n }\r\n\r\n result += value + \"\\n\";\r\n }\r\n\r\n this.children.forEach((child) => {\r\n result += child.process(preprocessors, options);\r\n });\r\n\r\n if (this.additionalDefineKey) {\r\n preprocessors[this.additionalDefineKey] = this.additionalDefineValue || \"true\";\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n","/** @internal */\r\nexport class ShaderCodeCursor {\r\n private _lines: string[] = [];\r\n lineIndex: number;\r\n\r\n get currentLine(): string {\r\n return this._lines[this.lineIndex];\r\n }\r\n\r\n get canRead(): boolean {\r\n return this.lineIndex < this._lines.length - 1;\r\n }\r\n\r\n set lines(value: string[]) {\r\n this._lines.length = 0;\r\n\r\n for (const line of value) {\r\n // Skip empty lines\r\n if (!line || line === \"\\r\") {\r\n continue;\r\n }\r\n\r\n // Prevent removing line break in macros.\r\n if (line[0] === \"#\") {\r\n this._lines.push(line);\r\n continue;\r\n }\r\n\r\n // Do not split single line comments\r\n const trimmedLine = line.trim();\r\n\r\n if (!trimmedLine) {\r\n continue;\r\n }\r\n\r\n if (trimmedLine.startsWith(\"//\")) {\r\n this._lines.push(line);\r\n continue;\r\n }\r\n\r\n // Work with semicolon in the line\r\n const semicolonIndex = trimmedLine.indexOf(\";\");\r\n\r\n if (semicolonIndex === -1) {\r\n // No semicolon in the line\r\n this._lines.push(trimmedLine);\r\n } else if (semicolonIndex === trimmedLine.length - 1) {\r\n // Single semicolon at the end of the line\r\n // If trimmedLine == \";\", we must not push, to be backward compatible with the old code!\r\n if (trimmedLine.length > 1) {\r\n this._lines.push(trimmedLine);\r\n }\r\n } else {\r\n // Semicolon in the middle of the line\r\n const split = line.split(\";\");\r\n\r\n for (let index = 0; index < split.length; index++) {\r\n let subLine = split[index];\r\n\r\n if (!subLine) {\r\n continue;\r\n }\r\n\r\n subLine = subLine.trim();\r\n\r\n if (!subLine) {\r\n continue;\r\n }\r\n\r\n this._lines.push(subLine + (index !== split.length - 1 ? \";\" : \"\"));\r\n }\r\n }\r\n }\r\n }\r\n}\r\n","import { ShaderCodeNode } from \"./shaderCodeNode\";\r\nimport type { ProcessingOptions } from \"./shaderProcessingOptions\";\r\n\r\n/** @internal */\r\nexport class ShaderCodeConditionNode extends ShaderCodeNode {\r\n process(preprocessors: { [key: string]: string }, options: ProcessingOptions) {\r\n for (let index = 0; index < this.children.length; index++) {\r\n const node = this.children[index];\r\n\r\n if (node.isValid(preprocessors)) {\r\n return node.process(preprocessors, options);\r\n }\r\n }\r\n\r\n return \"\";\r\n }\r\n}\r\n","import { ShaderCodeNode } from \"./shaderCodeNode\";\r\nimport type { ShaderDefineExpression } from \"./Expressions/shaderDefineExpression\";\r\n\r\n/** @internal */\r\nexport class ShaderCodeTestNode extends ShaderCodeNode {\r\n public testExpression: ShaderDefineExpression;\r\n\r\n public isValid(preprocessors: { [key: string]: string }) {\r\n return this.testExpression.isTrue(preprocessors);\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n/** @internal */\r\nexport class ShaderDefineExpression {\r\n /**\r\n * Cache items count limit for the InfixToPostfix cache.\r\n * It uses to improve the performance of the shader compilation.\r\n * For details see PR: https://github.com/BabylonJS/Babylon.js/pull/13936\r\n */\r\n static InfixToPostfixCacheLimitSize = 50000;\r\n\r\n /**\r\n * When the cache size is exceeded, a cache cleanup will be triggered\r\n * and the cache will be reduced by the size specified\r\n * in the InfixToPostfixCacheCleanupSize variable, removing entries\r\n * that have not been accessed the longest.\r\n */\r\n static InfixToPostfixCacheCleanupSize = 25000;\r\n\r\n protected static _InfixToPostfixCache: Map<\r\n string,\r\n {\r\n accessTime: number;\r\n result: string[];\r\n }\r\n > = new Map();\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isTrue(preprocessors: { [key: string]: string }): boolean {\r\n return true;\r\n }\r\n\r\n private static _OperatorPriority: { [name: string]: number } = {\r\n \")\": 0,\r\n \"(\": 1,\r\n \"||\": 2,\r\n \"&&\": 3,\r\n };\r\n\r\n private static _Stack = [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"];\r\n\r\n public static postfixToInfix(postfix: string[]): string {\r\n const stack: string[] = [];\r\n\r\n for (const c of postfix) {\r\n if (ShaderDefineExpression._OperatorPriority[c] === undefined) {\r\n stack.push(c);\r\n } else {\r\n const v1 = stack[stack.length - 1],\r\n v2 = stack[stack.length - 2];\r\n\r\n stack.length -= 2;\r\n stack.push(`(${v2}${c}${v1})`);\r\n }\r\n }\r\n\r\n return stack[stack.length - 1];\r\n }\r\n\r\n /**\r\n * Converts an infix expression to a postfix expression.\r\n *\r\n * This method is used to transform infix expressions, which are more human-readable,\r\n * into postfix expressions, also known as Reverse Polish Notation (RPN), that can be\r\n * evaluated more efficiently by a computer. The conversion is based on the operator\r\n * priority defined in _OperatorPriority.\r\n *\r\n * The function employs a stack-based algorithm for the conversion and caches the result\r\n * to improve performance. The cache keeps track of each converted expression's access time\r\n * to manage the cache size and optimize memory usage. When the cache size exceeds a specified\r\n * limit, the least recently accessed items in the cache are deleted.\r\n *\r\n * The cache mechanism is particularly helpful for shader compilation, where the same infix\r\n * expressions might be encountered repeatedly, hence the caching can speed up the process.\r\n *\r\n * @param infix - The infix expression to be converted.\r\n * @returns The postfix expression as an array of strings.\r\n */\r\n public static infixToPostfix(infix: string): string[] {\r\n // Is infix already in cache\r\n const cacheItem = ShaderDefineExpression._InfixToPostfixCache.get(infix);\r\n if (cacheItem) {\r\n cacheItem.accessTime = Date.now();\r\n return cacheItem.result;\r\n }\r\n\r\n // Is infix contain any operator\r\n if (!infix.includes(\"&&\") && !infix.includes(\"||\") && !infix.includes(\")\") && !infix.includes(\"(\")) {\r\n return [infix];\r\n }\r\n\r\n const result: string[] = [];\r\n\r\n let stackIdx = -1;\r\n\r\n const pushOperand = () => {\r\n operand = operand.trim();\r\n if (operand !== \"\") {\r\n result.push(operand);\r\n operand = \"\";\r\n }\r\n };\r\n\r\n const push = (s: string) => {\r\n if (stackIdx < ShaderDefineExpression._Stack.length - 1) {\r\n ShaderDefineExpression._Stack[++stackIdx] = s;\r\n }\r\n };\r\n\r\n const peek = () => ShaderDefineExpression._Stack[stackIdx];\r\n\r\n const pop = () => (stackIdx === -1 ? \"!!INVALID EXPRESSION!!\" : ShaderDefineExpression._Stack[stackIdx--]);\r\n\r\n let idx = 0,\r\n operand = \"\";\r\n\r\n while (idx < infix.length) {\r\n const c = infix.charAt(idx),\r\n token = idx < infix.length - 1 ? infix.substr(idx, 2) : \"\";\r\n\r\n if (c === \"(\") {\r\n operand = \"\";\r\n push(c);\r\n } else if (c === \")\") {\r\n pushOperand();\r\n while (stackIdx !== -1 && peek() !== \"(\") {\r\n result.push(pop());\r\n }\r\n pop();\r\n } else if (ShaderDefineExpression._OperatorPriority[token] > 1) {\r\n pushOperand();\r\n while (stackIdx !== -1 && ShaderDefineExpression._OperatorPriority[peek()] >= ShaderDefineExpression._OperatorPriority[token]) {\r\n result.push(pop());\r\n }\r\n push(token);\r\n idx++;\r\n } else {\r\n operand += c;\r\n }\r\n idx++;\r\n }\r\n\r\n pushOperand();\r\n\r\n while (stackIdx !== -1) {\r\n if (peek() === \"(\") {\r\n pop();\r\n } else {\r\n result.push(pop());\r\n }\r\n }\r\n\r\n // If the cache is at capacity, clear it before adding a new item\r\n if (ShaderDefineExpression._InfixToPostfixCache.size >= ShaderDefineExpression.InfixToPostfixCacheLimitSize) {\r\n ShaderDefineExpression.ClearCache();\r\n }\r\n\r\n // Add the new item to the cache, including the current time as the last access time\r\n ShaderDefineExpression._InfixToPostfixCache.set(infix, { result, accessTime: Date.now() });\r\n\r\n return result;\r\n }\r\n\r\n private static ClearCache(): void {\r\n // Convert the cache to an array and sort by last access time\r\n const sortedCache = Array.from(ShaderDefineExpression._InfixToPostfixCache.entries()).sort((a, b) => a[1].accessTime - b[1].accessTime);\r\n\r\n // Remove the least recently accessed half of the cache\r\n for (let i = 0; i < ShaderDefineExpression.InfixToPostfixCacheCleanupSize; i++) {\r\n ShaderDefineExpression._InfixToPostfixCache.delete(sortedCache[i][0]);\r\n }\r\n }\r\n}\r\n","import { ShaderDefineExpression } from \"../shaderDefineExpression\";\r\n\r\n/** @internal */\r\nexport class ShaderDefineIsDefinedOperator extends ShaderDefineExpression {\r\n public constructor(public define: string, public not: boolean = false) {\r\n super();\r\n }\r\n\r\n public isTrue(preprocessors: { [key: string]: string }) {\r\n let condition = preprocessors[this.define] !== undefined;\r\n\r\n if (this.not) {\r\n condition = !condition;\r\n }\r\n\r\n return condition;\r\n }\r\n}\r\n","import { ShaderDefineExpression } from \"../shaderDefineExpression\";\r\n\r\n/** @internal */\r\nexport class ShaderDefineOrOperator extends ShaderDefineExpression {\r\n public leftOperand: ShaderDefineExpression;\r\n public rightOperand: ShaderDefineExpression;\r\n\r\n public isTrue(preprocessors: { [key: string]: string }): boolean {\r\n return this.leftOperand.isTrue(preprocessors) || this.rightOperand.isTrue(preprocessors);\r\n }\r\n}\r\n","import { ShaderDefineExpression } from \"../shaderDefineExpression\";\r\n\r\n/** @internal */\r\nexport class ShaderDefineAndOperator extends ShaderDefineExpression {\r\n public leftOperand: ShaderDefineExpression;\r\n public rightOperand: ShaderDefineExpression;\r\n\r\n public isTrue(preprocessors: { [key: string]: string }): boolean {\r\n return this.leftOperand.isTrue(preprocessors) && this.rightOperand.isTrue(preprocessors);\r\n }\r\n}\r\n","import { ShaderDefineExpression } from \"../shaderDefineExpression\";\r\n\r\n/** @internal */\r\nexport class ShaderDefineArithmeticOperator extends ShaderDefineExpression {\r\n public constructor(public define: string, public operand: string, public testValue: string) {\r\n super();\r\n }\r\n\r\n public isTrue(preprocessors: { [key: string]: string }) {\r\n let value = preprocessors[this.define];\r\n\r\n if (value === undefined) {\r\n value = this.define;\r\n }\r\n\r\n let condition = false;\r\n const left = parseInt(value);\r\n const right = parseInt(this.testValue);\r\n\r\n switch (this.operand) {\r\n case \">\":\r\n condition = left > right;\r\n break;\r\n case \"<\":\r\n condition = left < right;\r\n break;\r\n case \"<=\":\r\n condition = left <= right;\r\n break;\r\n case \">=\":\r\n condition = left >= right;\r\n break;\r\n case \"==\":\r\n condition = left === right;\r\n break;\r\n case \"!=\":\r\n condition = left !== right;\r\n break;\r\n }\r\n\r\n return condition;\r\n }\r\n}\r\n","/**\r\n * Language of the shader code\r\n */\r\nexport enum ShaderLanguage {\r\n /** language is GLSL (used by WebGL) */\r\n GLSL,\r\n /** language is WGSL (used by WebGPU) */\r\n WGSL,\r\n}\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { ShaderCodeNode } from \"./shaderCodeNode\";\r\nimport { ShaderCodeCursor } from \"./shaderCodeCursor\";\r\nimport { ShaderCodeConditionNode } from \"./shaderCodeConditionNode\";\r\nimport { ShaderCodeTestNode } from \"./shaderCodeTestNode\";\r\nimport { ShaderDefineIsDefinedOperator } from \"./Expressions/Operators/shaderDefineIsDefinedOperator\";\r\nimport { ShaderDefineOrOperator } from \"./Expressions/Operators/shaderDefineOrOperator\";\r\nimport { ShaderDefineAndOperator } from \"./Expressions/Operators/shaderDefineAndOperator\";\r\nimport { ShaderDefineExpression } from \"./Expressions/shaderDefineExpression\";\r\nimport { ShaderDefineArithmeticOperator } from \"./Expressions/Operators/shaderDefineArithmeticOperator\";\r\nimport type { ProcessingOptions } from \"./shaderProcessingOptions\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\n\r\nimport type { WebRequest } from \"../../Misc/webRequest\";\r\nimport type { LoadFileError } from \"../../Misc/fileTools\";\r\nimport type { IOfflineProvider } from \"../../Offline/IOfflineProvider\";\r\nimport type { IFileRequest } from \"../../Misc/fileRequest\";\r\nimport type { ThinEngine } from \"../thinEngine\";\r\n\r\nconst regexSE = /defined\\s*?\\((.+?)\\)/g;\r\nconst regexSERevert = /defined\\s*?\\[(.+?)\\]/g;\r\nconst regexShaderInclude = /#include\\s?<(.+)>(\\((.*)\\))*(\\[(.*)\\])*/g;\r\nconst regexShaderDecl = /__decl__/;\r\nconst regexLightX = /light\\{X\\}.(\\w*)/g;\r\nconst regexX = /\\{X\\}/g;\r\nconst reusableMatches: RegExpMatchArray[] = [];\r\n\r\n/** @internal */\r\nexport class ShaderProcessor {\r\n private static _MoveCursorRegex = /(#ifdef)|(#else)|(#elif)|(#endif)|(#ifndef)|(#if)/;\r\n\r\n public static Initialize(options: ProcessingOptions): void {\r\n if (options.processor && options.processor.initializeShaders) {\r\n options.processor.initializeShaders(options.processingContext);\r\n }\r\n }\r\n\r\n public static Process(sourceCode: string, options: ProcessingOptions, callback: (migratedCode: string, codeBeforeMigration: string) => void, engine: ThinEngine) {\r\n if (options.processor?.preProcessShaderCode) {\r\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\r\n }\r\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\r\n if (options.processCodeAfterIncludes) {\r\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\r\n }\r\n const migratedCode = this._ProcessShaderConversion(codeWithIncludes, options, engine);\r\n callback(migratedCode, codeWithIncludes);\r\n });\r\n }\r\n\r\n public static PreProcess(sourceCode: string, options: ProcessingOptions, callback: (migratedCode: string, codeBeforeMigration: string) => void, engine: ThinEngine) {\r\n if (options.processor?.preProcessShaderCode) {\r\n sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);\r\n }\r\n this._ProcessIncludes(sourceCode, options, (codeWithIncludes) => {\r\n if (options.processCodeAfterIncludes) {\r\n codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? \"fragment\" : \"vertex\", codeWithIncludes);\r\n }\r\n const migratedCode = this._ApplyPreProcessing(codeWithIncludes, options, engine);\r\n callback(migratedCode, codeWithIncludes);\r\n });\r\n }\r\n\r\n public static Finalize(vertexCode: string, fragmentCode: string, options: ProcessingOptions): { vertexCode: string; fragmentCode: string } {\r\n if (!options.processor || !options.processor.finalizeShaders) {\r\n return { vertexCode, fragmentCode };\r\n }\r\n\r\n return options.processor.finalizeShaders(vertexCode, fragmentCode, options.processingContext);\r\n }\r\n\r\n private static _ProcessPrecision(source: string, options: ProcessingOptions): string {\r\n if (options.processor?.noPrecision) {\r\n return source;\r\n }\r\n\r\n const shouldUseHighPrecisionShader = options.shouldUseHighPrecisionShader;\r\n\r\n if (source.indexOf(\"precision highp float\") === -1) {\r\n if (!shouldUseHighPrecisionShader) {\r\n source = \"precision mediump float;\\n\" + source;\r\n } else {\r\n source = \"precision highp float;\\n\" + source;\r\n }\r\n } else {\r\n if (!shouldUseHighPrecisionShader) {\r\n // Moving highp to mediump\r\n source = source.replace(\"precision highp float\", \"precision mediump float\");\r\n }\r\n }\r\n\r\n return source;\r\n }\r\n\r\n private static _ExtractOperation(expression: string) {\r\n const regex = /defined\\((.+)\\)/;\r\n\r\n const match = regex.exec(expression);\r\n\r\n if (match && match.length) {\r\n return new ShaderDefineIsDefinedOperator(match[1].trim(), expression[0] === \"!\");\r\n }\r\n\r\n const operators = [\"==\", \"!=\", \">=\", \"<=\", \"<\", \">\"];\r\n let operator = \"\";\r\n let indexOperator = 0;\r\n\r\n for (operator of operators) {\r\n indexOperator = expression.indexOf(operator);\r\n\r\n if (indexOperator > -1) {\r\n break;\r\n }\r\n }\r\n\r\n if (indexOperator === -1) {\r\n return new ShaderDefineIsDefinedOperator(expression);\r\n }\r\n\r\n const define = expression.substring(0, indexOperator).trim();\r\n const value = expression.substring(indexOperator + operator.length).trim();\r\n\r\n return new ShaderDefineArithmeticOperator(define, operator, value);\r\n }\r\n\r\n private static _BuildSubExpression(expression: string): ShaderDefineExpression {\r\n expression = expression.replace(regexSE, \"defined[$1]\");\r\n\r\n const postfix = ShaderDefineExpression.infixToPostfix(expression);\r\n\r\n const stack: (string | ShaderDefineExpression)[] = [];\r\n\r\n for (const c of postfix) {\r\n if (c !== \"||\" && c !== \"&&\") {\r\n stack.push(c);\r\n } else if (stack.length >= 2) {\r\n let v1 = stack[stack.length - 1],\r\n v2 = stack[stack.length - 2];\r\n\r\n stack.length -= 2;\r\n\r\n const operator = c == \"&&\" ? new ShaderDefineAndOperator() : new ShaderDefineOrOperator();\r\n\r\n if (typeof v1 === \"string\") {\r\n v1 = v1.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n if (typeof v2 === \"string\") {\r\n v2 = v2.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n operator.leftOperand = typeof v2 === \"string\" ? this._ExtractOperation(v2) : v2;\r\n operator.rightOperand = typeof v1 === \"string\" ? this._ExtractOperation(v1) : v1;\r\n\r\n stack.push(operator);\r\n }\r\n }\r\n\r\n let result = stack[stack.length - 1];\r\n\r\n if (typeof result === \"string\") {\r\n result = result.replace(regexSERevert, \"defined($1)\");\r\n }\r\n\r\n // note: stack.length !== 1 if there was an error in the parsing\r\n\r\n return typeof result === \"string\" ? this._ExtractOperation(result) : result;\r\n }\r\n\r\n private static _BuildExpression(line: string, start: number): ShaderCodeTestNode {\r\n const node = new ShaderCodeTestNode();\r\n const command = line.substring(0, start);\r\n let expression = line.substring(start);\r\n\r\n expression = expression.substring(0, (expression.indexOf(\"//\") + 1 || expression.length + 1) - 1).trim();\r\n\r\n if (command === \"#ifdef\") {\r\n node.testExpression = new ShaderDefineIsDefinedOperator(expression);\r\n } else if (command === \"#ifndef\") {\r\n node.testExpression = new ShaderDefineIsDefinedOperator(expression, true);\r\n } else {\r\n node.testExpression = this._BuildSubExpression(expression);\r\n }\r\n\r\n return node;\r\n }\r\n\r\n private static _MoveCursorWithinIf(cursor: ShaderCodeCursor, rootNode: ShaderCodeConditionNode, ifNode: ShaderCodeNode) {\r\n let line = cursor.currentLine;\r\n while (this._MoveCursor(cursor, ifNode)) {\r\n line = cursor.currentLine;\r\n const first5 = line.substring(0, 5).toLowerCase();\r\n\r\n if (first5 === \"#else\") {\r\n const elseNode = new ShaderCodeNode();\r\n rootNode.children.push(elseNode);\r\n this._MoveCursor(cursor, elseNode);\r\n return;\r\n } else if (first5 === \"#elif\") {\r\n const elifNode = this._BuildExpression(line, 5);\r\n\r\n rootNode.children.push(elifNode);\r\n ifNode = elifNode;\r\n }\r\n }\r\n }\r\n\r\n private static _MoveCursor(cursor: ShaderCodeCursor, rootNode: ShaderCodeNode): boolean {\r\n while (cursor.canRead) {\r\n cursor.lineIndex++;\r\n const line = cursor.currentLine;\r\n\r\n if (line.indexOf(\"#\") >= 0) {\r\n const matches = ShaderProcessor._MoveCursorRegex.exec(line);\r\n\r\n if (matches && matches.length) {\r\n const keyword = matches[0];\r\n\r\n switch (keyword) {\r\n case \"#ifdef\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n rootNode.children.push(newRootNode);\r\n\r\n const ifNode = this._BuildExpression(line, 6);\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n case \"#else\":\r\n case \"#elif\":\r\n return true;\r\n case \"#endif\":\r\n return false;\r\n case \"#ifndef\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n rootNode.children.push(newRootNode);\r\n\r\n const ifNode = this._BuildExpression(line, 7);\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n case \"#if\": {\r\n const newRootNode = new ShaderCodeConditionNode();\r\n const ifNode = this._BuildExpression(line, 3);\r\n rootNode.children.push(newRootNode);\r\n\r\n newRootNode.children.push(ifNode);\r\n this._MoveCursorWithinIf(cursor, newRootNode, ifNode);\r\n break;\r\n }\r\n }\r\n continue;\r\n }\r\n }\r\n\r\n const newNode = new ShaderCodeNode();\r\n newNode.line = line;\r\n rootNode.children.push(newNode);\r\n\r\n // Detect additional defines\r\n if (line[0] === \"#\" && line[1] === \"d\") {\r\n const split = line.replace(\";\", \"\").split(\" \");\r\n newNode.additionalDefineKey = split[1];\r\n\r\n if (split.length === 3) {\r\n newNode.additionalDefineValue = split[2];\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n private static _EvaluatePreProcessors(sourceCode: string, preprocessors: { [key: string]: string }, options: ProcessingOptions): string {\r\n const rootNode = new ShaderCodeNode();\r\n const cursor = new ShaderCodeCursor();\r\n\r\n cursor.lineIndex = -1;\r\n cursor.lines = sourceCode.split(\"\\n\");\r\n\r\n // Decompose (We keep it in 2 steps so it is easier to maintain and perf hit is insignificant)\r\n this._MoveCursor(cursor, rootNode);\r\n\r\n // Recompose\r\n return rootNode.process(preprocessors, options);\r\n }\r\n\r\n private static _PreparePreProcessors(options: ProcessingOptions, engine: ThinEngine): { [key: string]: string } {\r\n const defines = options.defines;\r\n const preprocessors: { [key: string]: string } = {};\r\n\r\n for (const define of defines) {\r\n const keyValue = define.replace(\"#define\", \"\").replace(\";\", \"\").trim();\r\n const split = keyValue.split(\" \");\r\n preprocessors[split[0]] = split.length > 1 ? split[1] : \"\";\r\n }\r\n\r\n if (options.processor?.shaderLanguage === ShaderLanguage.GLSL) {\r\n preprocessors[\"GL_ES\"] = \"true\";\r\n }\r\n preprocessors[\"__VERSION__\"] = options.version;\r\n preprocessors[options.platformName] = \"true\";\r\n\r\n engine._getGlobalDefines(preprocessors);\r\n\r\n return preprocessors;\r\n }\r\n\r\n private static _ProcessShaderConversion(sourceCode: string, options: ProcessingOptions, engine: ThinEngine): string {\r\n let preparedSourceCode = this._ProcessPrecision(sourceCode, options);\r\n\r\n if (!options.processor) {\r\n return preparedSourceCode;\r\n }\r\n\r\n // Already converted\r\n if (options.processor.shaderLanguage === ShaderLanguage.GLSL && preparedSourceCode.indexOf(\"#version 3\") !== -1) {\r\n preparedSourceCode = preparedSourceCode.replace(\"#version 300 es\", \"\");\r\n if (!options.processor.parseGLES3) {\r\n return preparedSourceCode;\r\n }\r\n }\r\n\r\n const defines = options.defines;\r\n\r\n const preprocessors = this._PreparePreProcessors(options, engine);\r\n\r\n // General pre processing\r\n if (options.processor.preProcessor) {\r\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\r\n }\r\n\r\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\r\n\r\n // Post processing\r\n if (options.processor.postProcessor) {\r\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\r\n }\r\n\r\n // Inline functions tagged with #define inline\r\n if (engine._features.needShaderCodeInlining) {\r\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\r\n }\r\n\r\n return preparedSourceCode;\r\n }\r\n\r\n private static _ApplyPreProcessing(sourceCode: string, options: ProcessingOptions, engine: ThinEngine): string {\r\n let preparedSourceCode = sourceCode;\r\n\r\n const defines = options.defines;\r\n\r\n const preprocessors = this._PreparePreProcessors(options, engine);\r\n\r\n // General pre processing\r\n if (options.processor?.preProcessor) {\r\n preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);\r\n }\r\n\r\n preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);\r\n\r\n // Post processing\r\n if (options.processor?.postProcessor) {\r\n preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);\r\n }\r\n\r\n // Inline functions tagged with #define inline\r\n if (engine._features.needShaderCodeInlining) {\r\n preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);\r\n }\r\n\r\n return preparedSourceCode;\r\n }\r\n\r\n /** @internal */\r\n public static _ProcessIncludes(sourceCode: string, options: ProcessingOptions, callback: (data: any) => void): void {\r\n reusableMatches.length = 0;\r\n let match: RegExpMatchArray | null;\r\n // stay back-compat to the old matchAll syntax\r\n while ((match = regexShaderInclude.exec(sourceCode)) !== null) {\r\n reusableMatches.push(match);\r\n }\r\n\r\n let returnValue = String(sourceCode);\r\n let parts = [sourceCode];\r\n\r\n let keepProcessing = false;\r\n\r\n for (const match of reusableMatches) {\r\n let includeFile = match[1];\r\n\r\n // Uniform declaration\r\n if (includeFile.indexOf(\"__decl__\") !== -1) {\r\n includeFile = includeFile.replace(regexShaderDecl, \"\");\r\n if (options.supportsUniformBuffers) {\r\n includeFile = includeFile.replace(\"Vertex\", \"Ubo\").replace(\"Fragment\", \"Ubo\");\r\n }\r\n includeFile = includeFile + \"Declaration\";\r\n }\r\n\r\n if (options.includesShadersStore[includeFile]) {\r\n // Substitution\r\n let includeContent = options.includesShadersStore[includeFile];\r\n if (match[2]) {\r\n const splits = match[3].split(\",\");\r\n\r\n for (let index = 0; index < splits.length; index += 2) {\r\n const source = new RegExp(splits[index], \"g\");\r\n const dest = splits[index + 1];\r\n\r\n includeContent = includeContent.replace(source, dest);\r\n }\r\n }\r\n\r\n if (match[4]) {\r\n const indexString = match[5];\r\n\r\n if (indexString.indexOf(\"..\") !== -1) {\r\n const indexSplits = indexString.split(\"..\");\r\n const minIndex = parseInt(indexSplits[0]);\r\n let maxIndex = parseInt(indexSplits[1]);\r\n let sourceIncludeContent = includeContent.slice(0);\r\n includeContent = \"\";\r\n\r\n if (isNaN(maxIndex)) {\r\n maxIndex = options.indexParameters[indexSplits[1]];\r\n }\r\n\r\n for (let i = minIndex; i < maxIndex; i++) {\r\n if (!options.supportsUniformBuffers) {\r\n // Ubo replacement\r\n sourceIncludeContent = sourceIncludeContent.replace(regexLightX, (str: string, p1: string) => {\r\n return p1 + \"{X}\";\r\n });\r\n }\r\n includeContent += sourceIncludeContent.replace(regexX, i.toString()) + \"\\n\";\r\n }\r\n } else {\r\n if (!options.supportsUniformBuffers) {\r\n // Ubo replacement\r\n includeContent = includeContent.replace(regexLightX, (str: string, p1: string) => {\r\n return p1 + \"{X}\";\r\n });\r\n }\r\n includeContent = includeContent.replace(regexX, indexString);\r\n }\r\n }\r\n\r\n // Replace\r\n // Split all parts on match[0] and intersperse the parts with the include content\r\n const newParts = [];\r\n for (const part of parts) {\r\n const splitPart = part.split(match[0]);\r\n for (let i = 0; i < splitPart.length - 1; i++) {\r\n newParts.push(splitPart[i]);\r\n newParts.push(includeContent);\r\n }\r\n newParts.push(splitPart[splitPart.length - 1]);\r\n }\r\n parts = newParts;\r\n\r\n keepProcessing = keepProcessing || includeContent.indexOf(\"#include<\") >= 0 || includeContent.indexOf(\"#include <\") >= 0;\r\n } else {\r\n const includeShaderUrl = options.shadersRepository + \"ShadersInclude/\" + includeFile + \".fx\";\r\n\r\n ShaderProcessor._FileToolsLoadFile(includeShaderUrl, (fileContent) => {\r\n options.includesShadersStore[includeFile] = fileContent as string;\r\n this._ProcessIncludes(parts.join(\"\"), options, callback);\r\n });\r\n return;\r\n }\r\n }\r\n reusableMatches.length = 0;\r\n\r\n returnValue = parts.join(\"\");\r\n\r\n if (keepProcessing) {\r\n this._ProcessIncludes(returnValue.toString(), options, callback);\r\n } else {\r\n callback(returnValue);\r\n }\r\n }\r\n\r\n /**\r\n * Loads a file from a url\r\n * @param url url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @returns a file request object\r\n * @internal\r\n */\r\n public static _FileToolsLoadFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void\r\n ): IFileRequest {\r\n throw _WarnImport(\"FileTools\");\r\n }\r\n}\r\n","import { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\n/**\r\n * Defines the shader related stores and directory\r\n */\r\nexport class ShaderStore {\r\n /**\r\n * Gets or sets the relative url used to load shaders if using the engine in non-minified mode\r\n */\r\n public static ShadersRepository = \"src/Shaders/\";\r\n /**\r\n * Store of each shader (The can be looked up using effect.key)\r\n */\r\n public static ShadersStore: { [key: string]: string } = {};\r\n /**\r\n * Store of each included file for a shader (The can be looked up using effect.key)\r\n */\r\n public static IncludesShadersStore: { [key: string]: string } = {};\r\n\r\n /**\r\n * Gets or sets the relative url used to load shaders (WGSL) if using the engine in non-minified mode\r\n */\r\n public static ShadersRepositoryWGSL = \"src/ShadersWGSL/\";\r\n /**\r\n * Store of each shader (WGSL)\r\n */\r\n public static ShadersStoreWGSL: { [key: string]: string } = {};\r\n /**\r\n * Store of each included file for a shader (WGSL)\r\n */\r\n public static IncludesShadersStoreWGSL: { [key: string]: string } = {};\r\n\r\n /**\r\n * Gets the shaders repository path for a given shader language\r\n * @param shaderLanguage the shader language\r\n * @returns the path to the shaders repository\r\n */\r\n public static GetShadersRepository(shaderLanguage = ShaderLanguage.GLSL): string {\r\n return shaderLanguage === ShaderLanguage.GLSL ? ShaderStore.ShadersRepository : ShaderStore.ShadersRepositoryWGSL;\r\n }\r\n\r\n /**\r\n * Gets the shaders store of a given shader language\r\n * @param shaderLanguage the shader language\r\n * @returns the shaders store\r\n */\r\n public static GetShadersStore(shaderLanguage = ShaderLanguage.GLSL): { [key: string]: string } {\r\n return shaderLanguage === ShaderLanguage.GLSL ? ShaderStore.ShadersStore : ShaderStore.ShadersStoreWGSL;\r\n }\r\n\r\n /**\r\n * Gets the include shaders store of a given shader language\r\n * @param shaderLanguage the shader language\r\n * @returns the include shaders store\r\n */\r\n public static GetIncludesShadersStore(shaderLanguage = ShaderLanguage.GLSL): { [key: string]: string } {\r\n return shaderLanguage === ShaderLanguage.GLSL ? ShaderStore.IncludesShadersStore : ShaderStore.IncludesShadersStoreWGSL;\r\n }\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\nimport type { FloatArray, Nullable } from \"../types\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport type { IPipelineContext } from \"../Engines/IPipelineContext\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions, ShaderCustomProcessingFunction, ShaderProcessingContext } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { IMatrixLike, IVector2Like, IVector3Like, IVector4Like, IColor3Like, IColor4Like, IQuaternionLike } from \"../Maths/math.like\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { IEffectFallbacks } from \"./iEffectFallbacks\";\r\nimport { ShaderStore as EngineShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { ThinTexture } from \"../Materials/Textures/thinTexture\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { PostProcess } from \"../PostProcesses/postProcess\";\r\n\r\n/**\r\n * Options to be used when creating an effect.\r\n */\r\nexport interface IEffectCreationOptions {\r\n /**\r\n * Attributes that will be used in the shader.\r\n */\r\n attributes: string[];\r\n /**\r\n * Uniform variable names that will be set in the shader.\r\n */\r\n uniformsNames: string[];\r\n /**\r\n * Uniform buffer variable names that will be set in the shader.\r\n */\r\n uniformBuffersNames: string[];\r\n /**\r\n * Sampler texture variable names that will be set in the shader.\r\n */\r\n samplers: string[];\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * Possible fallbacks for this effect to improve performance when needed.\r\n */\r\n fallbacks: Nullable;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: Effect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: Effect, errors: string) => void>;\r\n /**\r\n * Parameters to be used with Babylons include syntax to iterate over an array (eg. {lights: 10})\r\n */\r\n indexParameters?: any;\r\n /**\r\n * Max number of lights that can be used in the shader.\r\n */\r\n maxSimultaneousLights?: number;\r\n /**\r\n * See https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings\r\n */\r\n transformFeedbackVaryings?: Nullable;\r\n /**\r\n * If provided, will be called two times with the vertex and fragment code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable;\r\n /**\r\n * If provided, will be called two times with the vertex and fragment code so that this code can be updated after the #include have been processed\r\n */\r\n processCodeAfterIncludes?: Nullable;\r\n /**\r\n * Is this effect rendering to several color attachments ?\r\n */\r\n multiTarget?: boolean;\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n}\r\n\r\n/**\r\n * Effect containing vertex and fragment shader that can be executed on an object.\r\n */\r\nexport class Effect implements IDisposable {\r\n /**\r\n * Gets or sets the relative url used to load shaders if using the engine in non-minified mode\r\n */\r\n public static get ShadersRepository(): string {\r\n return EngineShaderStore.ShadersRepository;\r\n }\r\n public static set ShadersRepository(repo: string) {\r\n EngineShaderStore.ShadersRepository = repo;\r\n }\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: any = null;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: Effect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: Effect, errors: string) => void> = null;\r\n /**\r\n * Callback that will be called when effect is bound.\r\n */\r\n public onBind: Nullable<(effect: Effect) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable();\r\n\r\n /** @internal */\r\n public _onBindObservable: Nullable> = null;\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n /**\r\n * @internal\r\n * Forces the code from bindForSubMesh to be fully run the next time it is called\r\n * It is used in frozen mode to make sure the effect is properly rebound when a new effect is created\r\n */\r\n public _forceRebindOnNextCall = false;\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously using instances\r\n */\r\n public _wasPreviouslyUsingInstances: Nullable = null;\r\n\r\n private _isDisposed = false;\r\n\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public get onBindObservable(): Observable {\r\n if (!this._onBindObservable) {\r\n this._onBindObservable = new Observable();\r\n }\r\n\r\n return this._onBindObservable;\r\n }\r\n\r\n /** @internal */\r\n public _bonesComputationForcedToCPU = false;\r\n /** @internal */\r\n public _uniformBuffersNames: { [key: string]: number } = {};\r\n /** @internal */\r\n public _samplerList: string[];\r\n /** @internal */\r\n public _multiTarget: boolean = false;\r\n\r\n private static _UniqueIdSeed = 0;\r\n /** @internal */\r\n public _engine: Engine;\r\n private _uniformBuffersNamesList: string[];\r\n private _uniformsNames: string[];\r\n private _samplers: { [key: string]: number } = {};\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n private _allFallbacksProcessed = false;\r\n private _attributesNames: string[];\r\n private _attributes: number[];\r\n private _attributeLocationByName: { [name: string]: number };\r\n private _uniforms: { [key: string]: Nullable } = {};\r\n /**\r\n * Key for the effect.\r\n * @internal\r\n */\r\n public _key: string = \"\";\r\n private _indexParameters: any;\r\n private _fallbacks: Nullable = null;\r\n private _vertexSourceCodeOverride: string = \"\";\r\n private _fragmentSourceCodeOverride: string = \"\";\r\n private _transformFeedbackVaryings: Nullable = null;\r\n private _shaderLanguage: ShaderLanguage;\r\n /**\r\n * Compiled shader to webGL program.\r\n * @internal\r\n */\r\n public _pipelineContext: Nullable = null;\r\n /** @internal */\r\n public _vertexSourceCode: string = \"\";\r\n /** @internal */\r\n public _fragmentSourceCode: string = \"\";\r\n\r\n /** @internal */\r\n private _vertexSourceCodeBeforeMigration: string = \"\";\r\n /** @internal */\r\n private _fragmentSourceCodeBeforeMigration: string = \"\";\r\n\r\n /** @internal */\r\n private _rawVertexSourceCode: string = \"\";\r\n /** @internal */\r\n private _rawFragmentSourceCode: string = \"\";\r\n\r\n private static _BaseCache: { [key: number]: DataBuffer } = {};\r\n private _processingContext: Nullable;\r\n\r\n /**\r\n * Instantiates an effect.\r\n * An effect can be used to create/manage/execute vertex and fragment shaders.\r\n * @param baseName Name of the effect.\r\n * @param attributesNamesOrOptions List of attribute names that will be passed to the shader or set of all options to create the effect.\r\n * @param uniformsNamesOrEngine List of uniform variable names that will be passed to the shader or the engine that will be used to render effect.\r\n * @param samplers List of sampler variables that will be passed to the shader.\r\n * @param engine Engine to be used to render the effect\r\n * @param defines Define statements to be added to the shader.\r\n * @param fallbacks Possible fallbacks for this effect to improve performance when needed.\r\n * @param onCompiled Callback that will be called when the shader is compiled.\r\n * @param onError Callback that will be called if an error occurs during shader compilation.\r\n * @param indexParameters Parameters to be used with Babylons include syntax to iterate over an array (eg. {lights: 10})\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n * @param shaderLanguage the language the shader is written in (default: GLSL)\r\n */\r\n constructor(\r\n baseName: any,\r\n attributesNamesOrOptions: string[] | IEffectCreationOptions,\r\n uniformsNamesOrEngine: string[] | ThinEngine,\r\n samplers: Nullable = null,\r\n engine?: ThinEngine,\r\n defines: Nullable = null,\r\n fallbacks: Nullable = null,\r\n onCompiled: Nullable<(effect: Effect) => void> = null,\r\n onError: Nullable<(effect: Effect, errors: string) => void> = null,\r\n indexParameters?: any,\r\n key: string = \"\",\r\n shaderLanguage = ShaderLanguage.GLSL\r\n ) {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n let processCodeAfterIncludes: ShaderCustomProcessingFunction | undefined = undefined;\r\n let processFinalCode: Nullable = null;\r\n\r\n if ((attributesNamesOrOptions).attributes) {\r\n const options = attributesNamesOrOptions;\r\n this._engine = uniformsNamesOrEngine;\r\n\r\n this._attributesNames = options.attributes;\r\n this._uniformsNames = options.uniformsNames.concat(options.samplers);\r\n this._samplerList = options.samplers.slice();\r\n this.defines = options.defines;\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._fallbacks = options.fallbacks;\r\n this._indexParameters = options.indexParameters;\r\n this._transformFeedbackVaryings = options.transformFeedbackVaryings || null;\r\n this._multiTarget = !!options.multiTarget;\r\n this._shaderLanguage = options.shaderLanguage ?? ShaderLanguage.GLSL;\r\n\r\n if (options.uniformBuffersNames) {\r\n this._uniformBuffersNamesList = options.uniformBuffersNames.slice();\r\n for (let i = 0; i < options.uniformBuffersNames.length; i++) {\r\n this._uniformBuffersNames[options.uniformBuffersNames[i]] = i;\r\n }\r\n }\r\n\r\n processFinalCode = options.processFinalCode ?? null;\r\n processCodeAfterIncludes = options.processCodeAfterIncludes ?? undefined;\r\n } else {\r\n this._engine = engine;\r\n this.defines = defines == null ? \"\" : defines;\r\n this._uniformsNames = (uniformsNamesOrEngine).concat(samplers);\r\n this._samplerList = samplers ? samplers.slice() : [];\r\n this._attributesNames = attributesNamesOrOptions;\r\n this._uniformBuffersNamesList = [];\r\n this._shaderLanguage = shaderLanguage;\r\n\r\n this.onError = onError;\r\n this.onCompiled = onCompiled;\r\n\r\n this._indexParameters = indexParameters;\r\n this._fallbacks = fallbacks;\r\n }\r\n\r\n this._attributeLocationByName = {};\r\n\r\n this.uniqueId = Effect._UniqueIdSeed++;\r\n\r\n let vertexSource: any;\r\n let fragmentSource: any;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (baseName.vertexSource) {\r\n vertexSource = \"source:\" + baseName.vertexSource;\r\n } else if (baseName.vertexElement) {\r\n vertexSource = hostDocument ? hostDocument.getElementById(baseName.vertexElement) : null;\r\n\r\n if (!vertexSource) {\r\n vertexSource = baseName.vertexElement;\r\n }\r\n } else {\r\n vertexSource = baseName.vertex || baseName;\r\n }\r\n\r\n if (baseName.fragmentSource) {\r\n fragmentSource = \"source:\" + baseName.fragmentSource;\r\n } else if (baseName.fragmentElement) {\r\n fragmentSource = hostDocument ? hostDocument.getElementById(baseName.fragmentElement) : null;\r\n\r\n if (!fragmentSource) {\r\n fragmentSource = baseName.fragmentElement;\r\n }\r\n } else {\r\n fragmentSource = baseName.fragment || baseName;\r\n }\r\n\r\n this._processingContext = this._engine._getShaderProcessingContext(this._shaderLanguage);\r\n\r\n let processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: this._indexParameters,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\r\n processor: this._engine._getShaderProcessor(this._shaderLanguage),\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: EngineShaderStore.GetShadersRepository(this._shaderLanguage),\r\n includesShadersStore: EngineShaderStore.GetIncludesShadersStore(this._shaderLanguage),\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: this._processingContext,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n processCodeAfterIncludes,\r\n };\r\n\r\n const shaderCodes: [string | undefined, string | undefined] = [undefined, undefined];\r\n const shadersLoaded = () => {\r\n if (shaderCodes[0] && shaderCodes[1]) {\r\n processorOptions.isFragment = true;\r\n const [migratedVertexCode, fragmentCode] = shaderCodes;\r\n ShaderProcessor.Process(\r\n fragmentCode,\r\n processorOptions,\r\n (migratedFragmentCode, codeBeforeMigration) => {\r\n this._fragmentSourceCodeBeforeMigration = codeBeforeMigration;\r\n if (processFinalCode) {\r\n migratedFragmentCode = processFinalCode(\"fragment\", migratedFragmentCode);\r\n }\r\n const finalShaders = ShaderProcessor.Finalize(migratedVertexCode, migratedFragmentCode, processorOptions);\r\n processorOptions = null as any;\r\n this._useFinalCode(finalShaders.vertexCode, finalShaders.fragmentCode, baseName);\r\n },\r\n this._engine\r\n );\r\n }\r\n };\r\n this._loadShader(vertexSource, \"Vertex\", \"\", (vertexCode) => {\r\n ShaderProcessor.Initialize(processorOptions);\r\n ShaderProcessor.Process(\r\n vertexCode,\r\n processorOptions,\r\n (migratedVertexCode, codeBeforeMigration) => {\r\n this._rawVertexSourceCode = vertexCode;\r\n this._vertexSourceCodeBeforeMigration = codeBeforeMigration;\r\n if (processFinalCode) {\r\n migratedVertexCode = processFinalCode(\"vertex\", migratedVertexCode);\r\n }\r\n shaderCodes[0] = migratedVertexCode;\r\n shadersLoaded();\r\n },\r\n this._engine\r\n );\r\n });\r\n this._loadShader(fragmentSource, \"Fragment\", \"Pixel\", (fragmentCode) => {\r\n this._rawFragmentSourceCode = fragmentCode;\r\n shaderCodes[1] = fragmentCode;\r\n shadersLoaded();\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedVertexCode: string, migratedFragmentCode: string, baseName: any) {\r\n if (baseName) {\r\n const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;\r\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;\r\n\r\n this._vertexSourceCode = (this._shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME vertex:\" + vertex + \"\\n\" + migratedVertexCode;\r\n this._fragmentSourceCode = (this._shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME fragment:\" + fragment + \"\\n\" + migratedFragmentCode;\r\n } else {\r\n this._vertexSourceCode = migratedVertexCode;\r\n this._fragmentSourceCode = migratedFragmentCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The set of names of attribute variables for the shader.\r\n * @returns An array of attribute names.\r\n */\r\n public getAttributesNames(): string[] {\r\n return this._attributesNames;\r\n }\r\n\r\n /**\r\n * Returns the attribute at the given index.\r\n * @param index The index of the attribute.\r\n * @returns The location of the attribute.\r\n */\r\n public getAttributeLocation(index: number): number {\r\n return this._attributes[index];\r\n }\r\n\r\n /**\r\n * Returns the attribute based on the name of the variable.\r\n * @param name of the attribute to look up.\r\n * @returns the attribute location.\r\n */\r\n public getAttributeLocationByName(name: string): number {\r\n return this._attributeLocationByName[name];\r\n }\r\n\r\n /**\r\n * The number of attributes.\r\n * @returns the number of attributes.\r\n */\r\n public getAttributesCount(): number {\r\n return this._attributes.length;\r\n }\r\n\r\n /**\r\n * Gets the index of a uniform variable.\r\n * @param uniformName of the uniform to look up.\r\n * @returns the index.\r\n */\r\n public getUniformIndex(uniformName: string): number {\r\n return this._uniformsNames.indexOf(uniformName);\r\n }\r\n\r\n /**\r\n * Returns the attribute based on the name of the variable.\r\n * @param uniformName of the uniform to look up.\r\n * @returns the location of the uniform.\r\n */\r\n public getUniform(uniformName: string): Nullable {\r\n return this._uniforms[uniformName];\r\n }\r\n\r\n /**\r\n * Returns an array of sampler variable names\r\n * @returns The array of sampler variable names.\r\n */\r\n public getSamplers(): string[] {\r\n return this._samplerList;\r\n }\r\n\r\n /**\r\n * Returns an array of uniform variable names\r\n * @returns The array of uniform variable names.\r\n */\r\n public getUniformNames(): string[] {\r\n return this._uniformsNames;\r\n }\r\n\r\n /**\r\n * Returns an array of uniform buffer variable names\r\n * @returns The array of uniform buffer variable names.\r\n */\r\n public getUniformBuffersNames(): string[] {\r\n return this._uniformBuffersNamesList;\r\n }\r\n\r\n /**\r\n * Returns the index parameters used to create the effect\r\n * @returns The index parameters object\r\n */\r\n public getIndexParameters(): any {\r\n return this._indexParameters;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that all fallbacks were used during compilation\r\n * @returns true if all fallbacks were used\r\n */\r\n public allFallbacksProcessed(): boolean {\r\n return this._allFallbacksProcessed;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: Effect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n const shaderStore = EngineShaderStore.GetShadersStore(this._shaderLanguage);\r\n\r\n // Is in local store ?\r\n if (shaderStore[shader + key + \"Shader\"]) {\r\n callback(shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = EngineShaderStore.GetShadersRepository(this._shaderLanguage) + shader;\r\n }\r\n\r\n // Vertex shader\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the vertex shader source code of this effect\r\n * This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)\r\n */\r\n public get vertexSourceCode(): string {\r\n return this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride\r\n ? this._vertexSourceCodeOverride\r\n : this._pipelineContext?._getVertexShaderCode() ?? this._vertexSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the fragment shader source code of this effect\r\n * This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)\r\n */\r\n public get fragmentSourceCode(): string {\r\n return this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride\r\n ? this._fragmentSourceCodeOverride\r\n : this._pipelineContext?._getFragmentShaderCode() ?? this._fragmentSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the vertex shader source code before migration.\r\n * This is the source code after the include directives have been replaced by their contents but before the code is migrated, i.e. before ShaderProcess._ProcessShaderConversion is executed.\r\n * This method is, among other things, responsible for parsing #if/#define directives as well as converting GLES2 syntax to GLES3 (in the case of WebGL).\r\n */\r\n public get vertexSourceCodeBeforeMigration(): string {\r\n return this._vertexSourceCodeBeforeMigration;\r\n }\r\n\r\n /**\r\n * Gets the fragment shader source code before migration.\r\n * This is the source code after the include directives have been replaced by their contents but before the code is migrated, i.e. before ShaderProcess._ProcessShaderConversion is executed.\r\n * This method is, among other things, responsible for parsing #if/#define directives as well as converting GLES2 syntax to GLES3 (in the case of WebGL).\r\n */\r\n public get fragmentSourceCodeBeforeMigration(): string {\r\n return this._fragmentSourceCodeBeforeMigration;\r\n }\r\n\r\n /**\r\n * Gets the vertex shader source code before it has been modified by any processing\r\n */\r\n public get rawVertexSourceCode(): string {\r\n return this._rawVertexSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the fragment shader source code before it has been modified by any processing\r\n */\r\n public get rawFragmentSourceCode(): string {\r\n return this._rawFragmentSourceCode;\r\n }\r\n\r\n /**\r\n * Recompiles the webGL program\r\n * @param vertexSourceCode The source code for the vertex shader.\r\n * @param fragmentSourceCode The source code for the fragment shader.\r\n * @param onCompiled Callback called when completed.\r\n * @param onError Callback called on error.\r\n * @internal\r\n */\r\n public _rebuildProgram(vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void) {\r\n this._isReady = false;\r\n\r\n this._vertexSourceCodeOverride = vertexSourceCode;\r\n this._fragmentSourceCodeOverride = fragmentSourceCode;\r\n this.onError = (effect, error) => {\r\n if (onError) {\r\n onError(error);\r\n }\r\n };\r\n this.onCompiled = () => {\r\n const scenes = this.getEngine().scenes;\r\n if (scenes) {\r\n for (let i = 0; i < scenes.length; i++) {\r\n scenes[i].markAllMaterialsAsDirty(Constants.MATERIAL_AllDirtyFlag);\r\n }\r\n }\r\n\r\n this._pipelineContext!._handlesSpectorRebuildCallback(onCompiled);\r\n };\r\n this._fallbacks = null;\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const attributesNames = this._attributesNames;\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createPipelineContext(this._processingContext);\r\n this._pipelineContext._name = this._key;\r\n\r\n const rebuildRebind = this._rebuildProgram.bind(this);\r\n if (this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride) {\r\n engine._preparePipelineContext(\r\n this._pipelineContext,\r\n this._vertexSourceCodeOverride,\r\n this._fragmentSourceCodeOverride,\r\n true,\r\n this._rawVertexSourceCode,\r\n this._rawFragmentSourceCode,\r\n rebuildRebind,\r\n null,\r\n this._transformFeedbackVaryings,\r\n this._key\r\n );\r\n } else {\r\n engine._preparePipelineContext(\r\n this._pipelineContext,\r\n this._vertexSourceCode,\r\n this._fragmentSourceCode,\r\n false,\r\n this._rawVertexSourceCode,\r\n this._rawFragmentSourceCode,\r\n rebuildRebind,\r\n defines,\r\n this._transformFeedbackVaryings,\r\n this._key\r\n );\r\n }\r\n\r\n engine._executeWhenRenderingStateIsCompiled(this._pipelineContext, () => {\r\n this._attributes = [];\r\n this._pipelineContext!._fillEffectInformation(\r\n this,\r\n this._uniformBuffersNames,\r\n this._uniformsNames,\r\n this._uniforms,\r\n this._samplerList,\r\n this._samplers,\r\n attributesNames,\r\n this._attributes\r\n );\r\n\r\n // Caches attribute locations.\r\n if (attributesNames) {\r\n for (let i = 0; i < attributesNames.length; i++) {\r\n const name = attributesNames[i];\r\n this._attributeLocationByName[name] = this._attributes[i];\r\n }\r\n }\r\n\r\n engine.bindSamplers(this);\r\n\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n // Unbind mesh reference in fallbacks\r\n if (this._fallbacks) {\r\n this._fallbacks.unBindMesh();\r\n }\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deletePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _getShaderCodeAndErrorLine(code: Nullable, error: Nullable, isFragment: boolean): [Nullable, Nullable] {\r\n const regexp = isFragment ? /FRAGMENT SHADER ERROR: 0:(\\d+?):/ : /VERTEX SHADER ERROR: 0:(\\d+?):/;\r\n\r\n let errorLine = null;\r\n\r\n if (error && code) {\r\n const res = error.match(regexp);\r\n if (res && res.length === 2) {\r\n const lineNumber = parseInt(res[1]);\r\n const lines = code.split(\"\\n\", -1);\r\n if (lines.length >= lineNumber) {\r\n errorLine = `Offending line [${lineNumber}] in ${isFragment ? \"fragment\" : \"vertex\"} code: ${lines[lineNumber - 1]}`;\r\n }\r\n }\r\n }\r\n\r\n return [code, errorLine];\r\n }\r\n\r\n private _processCompilationErrors(e: any, previousPipelineContext: Nullable = null) {\r\n this._compilationError = e.message;\r\n const attributesNames = this._attributesNames;\r\n const fallbacks = this._fallbacks;\r\n\r\n // Let's go through fallbacks then\r\n Logger.Error(\"Unable to compile effect:\");\r\n Logger.Error(\r\n \"Uniforms: \" +\r\n this._uniformsNames.map(function (uniform) {\r\n return \" \" + uniform;\r\n })\r\n );\r\n Logger.Error(\r\n \"Attributes: \" +\r\n attributesNames.map(function (attribute) {\r\n return \" \" + attribute;\r\n })\r\n );\r\n Logger.Error(\"Defines:\\n\" + this.defines);\r\n if (Effect.LogShaderCodeOnCompilationError) {\r\n let lineErrorVertex = null,\r\n lineErrorFragment = null,\r\n code = null;\r\n if (this._pipelineContext?._getVertexShaderCode()) {\r\n [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(this._pipelineContext._getVertexShaderCode(), this._compilationError, false);\r\n if (code) {\r\n Logger.Error(\"Vertex code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n if (this._pipelineContext?._getFragmentShaderCode()) {\r\n [code, lineErrorFragment] = this._getShaderCodeAndErrorLine(this._pipelineContext?._getFragmentShaderCode(), this._compilationError, true);\r\n if (code) {\r\n Logger.Error(\"Fragment code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n if (lineErrorVertex) {\r\n Logger.Error(lineErrorVertex);\r\n }\r\n if (lineErrorFragment) {\r\n Logger.Error(lineErrorFragment);\r\n }\r\n }\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n\r\n const notifyErrors = () => {\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n };\r\n\r\n // In case a previous compilation was successful, we need to restore the previous pipeline context\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n notifyErrors();\r\n }\r\n\r\n // Lets try to compile fallbacks as long as we have some.\r\n if (fallbacks) {\r\n this._pipelineContext = null;\r\n if (fallbacks.hasMoreFallbacks) {\r\n this._allFallbacksProcessed = false;\r\n Logger.Error(\"Trying next fallback.\");\r\n this.defines = fallbacks.reduce(this.defines, this);\r\n this._prepareEffect();\r\n } else {\r\n // Sorry we did everything we can\r\n this._allFallbacksProcessed = true;\r\n notifyErrors();\r\n this.onErrorObservable.clear();\r\n\r\n // Unbind mesh reference in fallbacks\r\n if (this._fallbacks) {\r\n this._fallbacks.unBindMesh();\r\n }\r\n }\r\n } else {\r\n this._allFallbacksProcessed = true;\r\n\r\n // In case of error, without any prior successful compilation, let s notify observers\r\n if (!previousPipelineContext) {\r\n notifyErrors();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Checks if the effect is supported. (Must be called after compilation)\r\n */\r\n public get isSupported(): boolean {\r\n return this._compilationError === \"\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the engine to be used as output of the shader.\r\n * @param channel Name of the output variable.\r\n * @param texture Texture to bind.\r\n * @internal\r\n */\r\n public _bindTexture(channel: string, texture: Nullable): void {\r\n this._engine._bindTexture(this._samplers[channel], texture, channel);\r\n }\r\n\r\n /**\r\n * Sets a texture on the engine to be used in the shader.\r\n * @param channel Name of the sampler variable.\r\n * @param texture Texture to set.\r\n */\r\n public setTexture(channel: string, texture: Nullable): void {\r\n this._engine.setTexture(this._samplers[channel], this._uniforms[channel], texture, channel);\r\n }\r\n\r\n /**\r\n * Sets a depth stencil texture from a render target on the engine to be used in the shader.\r\n * @param channel Name of the sampler variable.\r\n * @param texture Texture to set.\r\n */\r\n public setDepthStencilTexture(channel: string, texture: Nullable): void {\r\n this._engine.setDepthStencilTexture(this._samplers[channel], this._uniforms[channel], texture, channel);\r\n }\r\n\r\n /**\r\n * Sets an array of textures on the engine to be used in the shader.\r\n * @param channel Name of the variable.\r\n * @param textures Textures to set.\r\n */\r\n public setTextureArray(channel: string, textures: ThinTexture[]): void {\r\n const exName = channel + \"Ex\";\r\n if (this._samplerList.indexOf(exName + \"0\") === -1) {\r\n const initialPos = this._samplerList.indexOf(channel);\r\n for (let index = 1; index < textures.length; index++) {\r\n const currentExName = exName + (index - 1).toString();\r\n this._samplerList.splice(initialPos + index, 0, currentExName);\r\n }\r\n\r\n // Reset every channels\r\n let channelIndex = 0;\r\n for (const key of this._samplerList) {\r\n this._samplers[key] = channelIndex;\r\n channelIndex += 1;\r\n }\r\n }\r\n\r\n this._engine.setTextureArray(this._samplers[channel], this._uniforms[channel], textures, channel);\r\n }\r\n\r\n /**\r\n * Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)\r\n * @param channel Name of the sampler variable.\r\n * @param postProcess Post process to get the input texture from.\r\n */\r\n public setTextureFromPostProcess(channel: string, postProcess: Nullable): void {\r\n this._engine.setTextureFromPostProcess(this._samplers[channel], postProcess, channel);\r\n }\r\n\r\n /**\r\n * (Warning! setTextureFromPostProcessOutput may be desired instead)\r\n * Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)\r\n * @param channel Name of the sampler variable.\r\n * @param postProcess Post process to get the output texture from.\r\n */\r\n public setTextureFromPostProcessOutput(channel: string, postProcess: Nullable): void {\r\n this._engine.setTextureFromPostProcessOutput(this._samplers[channel], postProcess, channel);\r\n }\r\n\r\n /**\r\n * Binds a buffer to a uniform.\r\n * @param buffer Buffer to bind.\r\n * @param name Name of the uniform variable to bind to.\r\n */\r\n public bindUniformBuffer(buffer: DataBuffer, name: string): void {\r\n const bufferName = this._uniformBuffersNames[name];\r\n if (bufferName === undefined || (Effect._BaseCache[bufferName] === buffer && this._engine._features.useUBOBindingCache)) {\r\n return;\r\n }\r\n Effect._BaseCache[bufferName] = buffer;\r\n this._engine.bindUniformBufferBase(buffer, bufferName, name);\r\n }\r\n\r\n /**\r\n * Binds block to a uniform.\r\n * @param blockName Name of the block to bind.\r\n * @param index Index to bind.\r\n */\r\n public bindUniformBlock(blockName: string, index: number): void {\r\n this._engine.bindUniformBlock(this._pipelineContext!, blockName, index);\r\n }\r\n\r\n /**\r\n * Sets an integer value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param value Value to be set.\r\n * @returns this effect.\r\n */\r\n public setInt(uniformName: string, value: number): Effect {\r\n this._pipelineContext!.setInt(uniformName, value);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int2 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First int in int2.\r\n * @param y Second int in int2.\r\n * @returns this effect.\r\n */\r\n public setInt2(uniformName: string, x: number, y: number): Effect {\r\n this._pipelineContext!.setInt2(uniformName, x, y);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int3 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First int in int3.\r\n * @param y Second int in int3.\r\n * @param z Third int in int3.\r\n * @returns this effect.\r\n */\r\n public setInt3(uniformName: string, x: number, y: number, z: number): Effect {\r\n this._pipelineContext!.setInt3(uniformName, x, y, z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int4 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First int in int4.\r\n * @param y Second int in int4.\r\n * @param z Third int in int4.\r\n * @param w Fourth int in int4.\r\n * @returns this effect.\r\n */\r\n public setInt4(uniformName: string, x: number, y: number, z: number, w: number): Effect {\r\n this._pipelineContext!.setInt4(uniformName, x, y, z, w);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setIntArray(uniformName: string, array: Int32Array): Effect {\r\n this._pipelineContext!.setIntArray(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setIntArray2(uniformName: string, array: Int32Array): Effect {\r\n this._pipelineContext!.setIntArray2(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setIntArray3(uniformName: string, array: Int32Array): Effect {\r\n this._pipelineContext!.setIntArray3(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setIntArray4(uniformName: string, array: Int32Array): Effect {\r\n this._pipelineContext!.setIntArray4(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned integer value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param value Value to be set.\r\n * @returns this effect.\r\n */\r\n public setUInt(uniformName: string, value: number): Effect {\r\n this._pipelineContext!.setInt(uniformName, value);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int2 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First unsigned int in uint2.\r\n * @param y Second unsigned int in uint2.\r\n * @returns this effect.\r\n */\r\n public setUInt2(uniformName: string, x: number, y: number): Effect {\r\n this._pipelineContext!.setInt2(uniformName, x, y);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int3 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First unsigned int in uint3.\r\n * @param y Second unsigned int in uint3.\r\n * @param z Third unsigned int in uint3.\r\n * @returns this effect.\r\n */\r\n public setUInt3(uniformName: string, x: number, y: number, z: number): Effect {\r\n this._pipelineContext!.setInt3(uniformName, x, y, z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int4 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First unsigned int in uint4.\r\n * @param y Second unsigned int in uint4.\r\n * @param z Third unsigned int in uint4.\r\n * @param w Fourth unsigned int in uint4.\r\n * @returns this effect.\r\n */\r\n public setUInt4(uniformName: string, x: number, y: number, z: number, w: number): Effect {\r\n this._pipelineContext!.setInt4(uniformName, x, y, z, w);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setUIntArray(uniformName: string, array: Uint32Array): Effect {\r\n this._pipelineContext!.setUIntArray(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setUIntArray2(uniformName: string, array: Uint32Array): Effect {\r\n this._pipelineContext!.setUIntArray2(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setUIntArray3(uniformName: string, array: Uint32Array): Effect {\r\n this._pipelineContext!.setUIntArray3(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setUIntArray4(uniformName: string, array: Uint32Array): Effect {\r\n this._pipelineContext!.setUIntArray4(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an float array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setFloatArray(uniformName: string, array: FloatArray): Effect {\r\n this._pipelineContext!.setArray(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setFloatArray2(uniformName: string, array: FloatArray): Effect {\r\n this._pipelineContext!.setArray2(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setFloatArray3(uniformName: string, array: FloatArray): Effect {\r\n this._pipelineContext!.setArray3(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setFloatArray4(uniformName: string, array: FloatArray): Effect {\r\n this._pipelineContext!.setArray4(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setArray(uniformName: string, array: number[]): Effect {\r\n this._pipelineContext!.setArray(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setArray2(uniformName: string, array: number[]): Effect {\r\n this._pipelineContext!.setArray2(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setArray3(uniformName: string, array: number[]): Effect {\r\n this._pipelineContext!.setArray3(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setArray4(uniformName: string, array: number[]): Effect {\r\n this._pipelineContext!.setArray4(uniformName, array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets matrices on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param matrices matrices to be set.\r\n * @returns this effect.\r\n */\r\n public setMatrices(uniformName: string, matrices: Float32Array | Array): Effect {\r\n this._pipelineContext!.setMatrices(uniformName, matrices as Float32Array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets matrix on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param matrix matrix to be set.\r\n * @returns this effect.\r\n */\r\n public setMatrix(uniformName: string, matrix: IMatrixLike): Effect {\r\n this._pipelineContext!.setMatrix(uniformName, matrix);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)\r\n * @param uniformName Name of the variable.\r\n * @param matrix matrix to be set.\r\n * @returns this effect.\r\n */\r\n public setMatrix3x3(uniformName: string, matrix: Float32Array | Array): Effect {\r\n // the cast is ok because it is gl.uniformMatrix3fv() which is called at the end, and this function accepts Float32Array and Array\r\n this._pipelineContext!.setMatrix3x3(uniformName, matrix as Float32Array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)\r\n * @param uniformName Name of the variable.\r\n * @param matrix matrix to be set.\r\n * @returns this effect.\r\n */\r\n public setMatrix2x2(uniformName: string, matrix: Float32Array | Array): Effect {\r\n // the cast is ok because it is gl.uniformMatrix3fv() which is called at the end, and this function accepts Float32Array and Array\r\n this._pipelineContext!.setMatrix2x2(uniformName, matrix as Float32Array);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a float on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param value value to be set.\r\n * @returns this effect.\r\n */\r\n public setFloat(uniformName: string, value: number): Effect {\r\n this._pipelineContext!.setFloat(uniformName, value);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a boolean on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param bool value to be set.\r\n * @returns this effect.\r\n */\r\n public setBool(uniformName: string, bool: boolean): Effect {\r\n this._pipelineContext!.setInt(uniformName, bool ? 1 : 0);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Vector2 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param vector2 vector2 to be set.\r\n * @returns this effect.\r\n */\r\n public setVector2(uniformName: string, vector2: IVector2Like): Effect {\r\n this._pipelineContext!.setVector2(uniformName, vector2);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a float2 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First float in float2.\r\n * @param y Second float in float2.\r\n * @returns this effect.\r\n */\r\n public setFloat2(uniformName: string, x: number, y: number): Effect {\r\n this._pipelineContext!.setFloat2(uniformName, x, y);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Vector3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param vector3 Value to be set.\r\n * @returns this effect.\r\n */\r\n public setVector3(uniformName: string, vector3: IVector3Like): Effect {\r\n this._pipelineContext!.setVector3(uniformName, vector3);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a float3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First float in float3.\r\n * @param y Second float in float3.\r\n * @param z Third float in float3.\r\n * @returns this effect.\r\n */\r\n public setFloat3(uniformName: string, x: number, y: number, z: number): Effect {\r\n this._pipelineContext!.setFloat3(uniformName, x, y, z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Vector4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param vector4 Value to be set.\r\n * @returns this effect.\r\n */\r\n public setVector4(uniformName: string, vector4: IVector4Like): Effect {\r\n this._pipelineContext!.setVector4(uniformName, vector4);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Quaternion on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param quaternion Value to be set.\r\n * @returns this effect.\r\n */\r\n public setQuaternion(uniformName: string, quaternion: IQuaternionLike): Effect {\r\n this._pipelineContext!.setQuaternion(uniformName, quaternion);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a float4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First float in float4.\r\n * @param y Second float in float4.\r\n * @param z Third float in float4.\r\n * @param w Fourth float in float4.\r\n * @returns this effect.\r\n */\r\n public setFloat4(uniformName: string, x: number, y: number, z: number, w: number): Effect {\r\n this._pipelineContext!.setFloat4(uniformName, x, y, z, w);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Color3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param color3 Value to be set.\r\n * @returns this effect.\r\n */\r\n public setColor3(uniformName: string, color3: IColor3Like): Effect {\r\n this._pipelineContext!.setColor3(uniformName, color3);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Color4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param color3 Value to be set.\r\n * @param alpha Alpha value to be set.\r\n * @returns this effect.\r\n */\r\n public setColor4(uniformName: string, color3: IColor3Like, alpha: number): Effect {\r\n this._pipelineContext!.setColor4(uniformName, color3, alpha);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a Color4 on a uniform variable\r\n * @param uniformName defines the name of the variable\r\n * @param color4 defines the value to be set\r\n * @returns this effect.\r\n */\r\n public setDirectColor4(uniformName: string, color4: IColor4Like): Effect {\r\n this._pipelineContext!.setDirectColor4(uniformName, color4);\r\n return this;\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseEffect(this);\r\n\r\n this._isDisposed = true;\r\n }\r\n\r\n /**\r\n * This function will add a new shader to the shader store\r\n * @param name the name of the shader\r\n * @param pixelShader optional pixel shader content\r\n * @param vertexShader optional vertex shader content\r\n * @param shaderLanguage the language the shader is written in (default: GLSL)\r\n */\r\n public static RegisterShader(name: string, pixelShader?: string, vertexShader?: string, shaderLanguage = ShaderLanguage.GLSL) {\r\n if (pixelShader) {\r\n EngineShaderStore.GetShadersStore(shaderLanguage)[`${name}PixelShader`] = pixelShader;\r\n }\r\n\r\n if (vertexShader) {\r\n EngineShaderStore.GetShadersStore(shaderLanguage)[`${name}VertexShader`] = vertexShader;\r\n }\r\n }\r\n\r\n /**\r\n * Store of each shader (The can be looked up using effect.key)\r\n */\r\n public static ShadersStore: { [key: string]: string } = EngineShaderStore.ShadersStore;\r\n /**\r\n * Store of each included file for a shader (The can be looked up using effect.key)\r\n */\r\n public static IncludesShadersStore: { [key: string]: string } = EngineShaderStore.IncludesShadersStore;\r\n\r\n /**\r\n * Resets the cache of effects.\r\n */\r\n public static ResetCache() {\r\n Effect._BaseCache = {};\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * @internal\r\n **/\r\nexport class DepthCullingState {\r\n protected _isDepthTestDirty = false;\r\n protected _isDepthMaskDirty = false;\r\n protected _isDepthFuncDirty = false;\r\n protected _isCullFaceDirty = false;\r\n protected _isCullDirty = false;\r\n protected _isZOffsetDirty = false;\r\n protected _isFrontFaceDirty = false;\r\n\r\n protected _depthTest: boolean;\r\n protected _depthMask: boolean;\r\n protected _depthFunc: Nullable;\r\n protected _cull: Nullable;\r\n protected _cullFace: Nullable;\r\n protected _zOffset: number;\r\n protected _zOffsetUnits: number;\r\n protected _frontFace: Nullable;\r\n\r\n /**\r\n * Initializes the state.\r\n * @param reset\r\n */\r\n public constructor(reset = true) {\r\n if (reset) {\r\n this.reset();\r\n }\r\n }\r\n\r\n public get isDirty(): boolean {\r\n return (\r\n this._isDepthFuncDirty ||\r\n this._isDepthTestDirty ||\r\n this._isDepthMaskDirty ||\r\n this._isCullFaceDirty ||\r\n this._isCullDirty ||\r\n this._isZOffsetDirty ||\r\n this._isFrontFaceDirty\r\n );\r\n }\r\n\r\n public get zOffset(): number {\r\n return this._zOffset;\r\n }\r\n\r\n public set zOffset(value: number) {\r\n if (this._zOffset === value) {\r\n return;\r\n }\r\n\r\n this._zOffset = value;\r\n this._isZOffsetDirty = true;\r\n }\r\n\r\n public get zOffsetUnits(): number {\r\n return this._zOffsetUnits;\r\n }\r\n\r\n public set zOffsetUnits(value: number) {\r\n if (this._zOffsetUnits === value) {\r\n return;\r\n }\r\n\r\n this._zOffsetUnits = value;\r\n this._isZOffsetDirty = true;\r\n }\r\n\r\n public get cullFace(): Nullable {\r\n return this._cullFace;\r\n }\r\n\r\n public set cullFace(value: Nullable) {\r\n if (this._cullFace === value) {\r\n return;\r\n }\r\n\r\n this._cullFace = value;\r\n this._isCullFaceDirty = true;\r\n }\r\n\r\n public get cull(): Nullable {\r\n return this._cull;\r\n }\r\n\r\n public set cull(value: Nullable) {\r\n if (this._cull === value) {\r\n return;\r\n }\r\n\r\n this._cull = value;\r\n this._isCullDirty = true;\r\n }\r\n\r\n public get depthFunc(): Nullable {\r\n return this._depthFunc;\r\n }\r\n\r\n public set depthFunc(value: Nullable) {\r\n if (this._depthFunc === value) {\r\n return;\r\n }\r\n\r\n this._depthFunc = value;\r\n this._isDepthFuncDirty = true;\r\n }\r\n\r\n public get depthMask(): boolean {\r\n return this._depthMask;\r\n }\r\n\r\n public set depthMask(value: boolean) {\r\n if (this._depthMask === value) {\r\n return;\r\n }\r\n\r\n this._depthMask = value;\r\n this._isDepthMaskDirty = true;\r\n }\r\n\r\n public get depthTest(): boolean {\r\n return this._depthTest;\r\n }\r\n\r\n public set depthTest(value: boolean) {\r\n if (this._depthTest === value) {\r\n return;\r\n }\r\n\r\n this._depthTest = value;\r\n this._isDepthTestDirty = true;\r\n }\r\n\r\n public get frontFace(): Nullable {\r\n return this._frontFace;\r\n }\r\n\r\n public set frontFace(value: Nullable) {\r\n if (this._frontFace === value) {\r\n return;\r\n }\r\n\r\n this._frontFace = value;\r\n this._isFrontFaceDirty = true;\r\n }\r\n\r\n public reset() {\r\n this._depthMask = true;\r\n this._depthTest = true;\r\n this._depthFunc = null;\r\n this._cullFace = null;\r\n this._cull = null;\r\n this._zOffset = 0;\r\n this._zOffsetUnits = 0;\r\n this._frontFace = null;\r\n\r\n this._isDepthTestDirty = true;\r\n this._isDepthMaskDirty = true;\r\n this._isDepthFuncDirty = false;\r\n this._isCullFaceDirty = false;\r\n this._isCullDirty = false;\r\n this._isZOffsetDirty = true;\r\n this._isFrontFaceDirty = false;\r\n }\r\n\r\n public apply(gl: WebGLRenderingContext) {\r\n if (!this.isDirty) {\r\n return;\r\n }\r\n\r\n // Cull\r\n if (this._isCullDirty) {\r\n if (this.cull) {\r\n gl.enable(gl.CULL_FACE);\r\n } else {\r\n gl.disable(gl.CULL_FACE);\r\n }\r\n\r\n this._isCullDirty = false;\r\n }\r\n\r\n // Cull face\r\n if (this._isCullFaceDirty) {\r\n gl.cullFace(this.cullFace);\r\n this._isCullFaceDirty = false;\r\n }\r\n\r\n // Depth mask\r\n if (this._isDepthMaskDirty) {\r\n gl.depthMask(this.depthMask);\r\n this._isDepthMaskDirty = false;\r\n }\r\n\r\n // Depth test\r\n if (this._isDepthTestDirty) {\r\n if (this.depthTest) {\r\n gl.enable(gl.DEPTH_TEST);\r\n } else {\r\n gl.disable(gl.DEPTH_TEST);\r\n }\r\n this._isDepthTestDirty = false;\r\n }\r\n\r\n // Depth func\r\n if (this._isDepthFuncDirty) {\r\n gl.depthFunc(this.depthFunc);\r\n this._isDepthFuncDirty = false;\r\n }\r\n\r\n // zOffset\r\n if (this._isZOffsetDirty) {\r\n if (this.zOffset || this.zOffsetUnits) {\r\n gl.enable(gl.POLYGON_OFFSET_FILL);\r\n gl.polygonOffset(this.zOffset, this.zOffsetUnits);\r\n } else {\r\n gl.disable(gl.POLYGON_OFFSET_FILL);\r\n }\r\n\r\n this._isZOffsetDirty = false;\r\n }\r\n\r\n // Front face\r\n if (this._isFrontFaceDirty) {\r\n gl.frontFace(this.frontFace);\r\n this._isFrontFaceDirty = false;\r\n }\r\n }\r\n}\r\n","import { Constants } from \"../Engines/constants\";\r\nimport type { IStencilState } from \"./IStencilState\";\r\n\r\n/**\r\n * @internal\r\n **/\r\nexport class StencilState implements IStencilState {\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */\r\n public static readonly ALWAYS = Constants.ALWAYS;\r\n /** Passed to stencilOperation to specify that stencil value must be kept */\r\n public static readonly KEEP = Constants.KEEP;\r\n /** Passed to stencilOperation to specify that stencil value must be replaced */\r\n public static readonly REPLACE = Constants.REPLACE;\r\n\r\n public constructor() {\r\n this.reset();\r\n }\r\n\r\n public reset() {\r\n this.enabled = false;\r\n this.mask = 0xff;\r\n\r\n this.func = StencilState.ALWAYS;\r\n this.funcRef = 1;\r\n this.funcMask = 0xff;\r\n\r\n this.opStencilFail = StencilState.KEEP;\r\n this.opDepthFail = StencilState.KEEP;\r\n this.opStencilDepthPass = StencilState.REPLACE;\r\n }\r\n\r\n public func: number;\r\n public get stencilFunc(): number {\r\n return this.func;\r\n }\r\n\r\n public set stencilFunc(value: number) {\r\n this.func = value;\r\n }\r\n\r\n public funcRef: number;\r\n public get stencilFuncRef(): number {\r\n return this.funcRef;\r\n }\r\n\r\n public set stencilFuncRef(value: number) {\r\n this.funcRef = value;\r\n }\r\n\r\n public funcMask: number;\r\n public get stencilFuncMask(): number {\r\n return this.funcMask;\r\n }\r\n\r\n public set stencilFuncMask(value: number) {\r\n this.funcMask = value;\r\n }\r\n\r\n public opStencilFail: number;\r\n public get stencilOpStencilFail(): number {\r\n return this.opStencilFail;\r\n }\r\n\r\n public set stencilOpStencilFail(value: number) {\r\n this.opStencilFail = value;\r\n }\r\n\r\n public opDepthFail: number;\r\n public get stencilOpDepthFail(): number {\r\n return this.opDepthFail;\r\n }\r\n\r\n public set stencilOpDepthFail(value: number) {\r\n this.opDepthFail = value;\r\n }\r\n\r\n public opStencilDepthPass: number;\r\n public get stencilOpStencilDepthPass(): number {\r\n return this.opStencilDepthPass;\r\n }\r\n\r\n public set stencilOpStencilDepthPass(value: number) {\r\n this.opStencilDepthPass = value;\r\n }\r\n\r\n public mask: number;\r\n public get stencilMask(): number {\r\n return this.mask;\r\n }\r\n\r\n public set stencilMask(value: number) {\r\n this.mask = value;\r\n }\r\n\r\n public enabled: boolean;\r\n public get stencilTest(): boolean {\r\n return this.enabled;\r\n }\r\n\r\n public set stencilTest(value: boolean) {\r\n this.enabled = value;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * @internal\r\n **/\r\nexport class AlphaState {\r\n public _blendFunctionParameters = new Array>(4);\r\n public _blendEquationParameters = new Array>(2);\r\n public _blendConstants = new Array>(4);\r\n public _isBlendConstantsDirty = false;\r\n\r\n private _alphaBlend = false;\r\n private _isAlphaBlendDirty = false;\r\n private _isBlendFunctionParametersDirty = false;\r\n private _isBlendEquationParametersDirty = false;\r\n\r\n /**\r\n * Initializes the state.\r\n */\r\n public constructor() {\r\n this.reset();\r\n }\r\n\r\n public get isDirty(): boolean {\r\n return this._isAlphaBlendDirty || this._isBlendFunctionParametersDirty || this._isBlendEquationParametersDirty;\r\n }\r\n\r\n public get alphaBlend(): boolean {\r\n return this._alphaBlend;\r\n }\r\n\r\n public set alphaBlend(value: boolean) {\r\n if (this._alphaBlend === value) {\r\n return;\r\n }\r\n\r\n this._alphaBlend = value;\r\n this._isAlphaBlendDirty = true;\r\n }\r\n\r\n public setAlphaBlendConstants(r: number, g: number, b: number, a: number): void {\r\n if (this._blendConstants[0] === r && this._blendConstants[1] === g && this._blendConstants[2] === b && this._blendConstants[3] === a) {\r\n return;\r\n }\r\n\r\n this._blendConstants[0] = r;\r\n this._blendConstants[1] = g;\r\n this._blendConstants[2] = b;\r\n this._blendConstants[3] = a;\r\n\r\n this._isBlendConstantsDirty = true;\r\n }\r\n\r\n public setAlphaBlendFunctionParameters(value0: number, value1: number, value2: number, value3: number): void {\r\n if (\r\n this._blendFunctionParameters[0] === value0 &&\r\n this._blendFunctionParameters[1] === value1 &&\r\n this._blendFunctionParameters[2] === value2 &&\r\n this._blendFunctionParameters[3] === value3\r\n ) {\r\n return;\r\n }\r\n\r\n this._blendFunctionParameters[0] = value0;\r\n this._blendFunctionParameters[1] = value1;\r\n this._blendFunctionParameters[2] = value2;\r\n this._blendFunctionParameters[3] = value3;\r\n\r\n this._isBlendFunctionParametersDirty = true;\r\n }\r\n\r\n public setAlphaEquationParameters(rgb: number, alpha: number): void {\r\n if (this._blendEquationParameters[0] === rgb && this._blendEquationParameters[1] === alpha) {\r\n return;\r\n }\r\n\r\n this._blendEquationParameters[0] = rgb;\r\n this._blendEquationParameters[1] = alpha;\r\n\r\n this._isBlendEquationParametersDirty = true;\r\n }\r\n\r\n public reset() {\r\n this._alphaBlend = false;\r\n this._blendFunctionParameters[0] = null;\r\n this._blendFunctionParameters[1] = null;\r\n this._blendFunctionParameters[2] = null;\r\n this._blendFunctionParameters[3] = null;\r\n\r\n this._blendEquationParameters[0] = null;\r\n this._blendEquationParameters[1] = null;\r\n\r\n this._blendConstants[0] = null;\r\n this._blendConstants[1] = null;\r\n this._blendConstants[2] = null;\r\n this._blendConstants[3] = null;\r\n\r\n this._isAlphaBlendDirty = true;\r\n this._isBlendFunctionParametersDirty = false;\r\n this._isBlendEquationParametersDirty = false;\r\n this._isBlendConstantsDirty = false;\r\n }\r\n\r\n public apply(gl: WebGLRenderingContext) {\r\n if (!this.isDirty) {\r\n return;\r\n }\r\n\r\n // Alpha blend\r\n if (this._isAlphaBlendDirty) {\r\n if (this._alphaBlend) {\r\n gl.enable(gl.BLEND);\r\n } else {\r\n gl.disable(gl.BLEND);\r\n }\r\n\r\n this._isAlphaBlendDirty = false;\r\n }\r\n\r\n // Alpha function\r\n if (this._isBlendFunctionParametersDirty) {\r\n gl.blendFuncSeparate(\r\n this._blendFunctionParameters[0],\r\n this._blendFunctionParameters[1],\r\n this._blendFunctionParameters[2],\r\n this._blendFunctionParameters[3]\r\n );\r\n this._isBlendFunctionParametersDirty = false;\r\n }\r\n\r\n // Alpha equation\r\n if (this._isBlendEquationParametersDirty) {\r\n gl.blendEquationSeparate(this._blendEquationParameters[0]!, this._blendEquationParameters[1]!);\r\n this._isBlendEquationParametersDirty = false;\r\n }\r\n\r\n // Constants\r\n if (this._isBlendConstantsDirty) {\r\n gl.blendColor(this._blendConstants[0], this._blendConstants[1], this._blendConstants[2], this._blendConstants[3]);\r\n this._isBlendConstantsDirty = false;\r\n }\r\n }\r\n}\r\n","import { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable, int } from \"../../types\";\r\nimport type { ICanvas, ICanvasRenderingContext } from \"../../Engines/ICanvas\";\r\nimport type { HardwareTextureWrapper } from \"./hardwareTextureWrapper\";\r\nimport { TextureSampler } from \"./textureSampler\";\r\n\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { SphericalPolynomial } from \"../../Maths/sphericalPolynomial\";\r\n\r\n/**\r\n * Defines the source of the internal texture\r\n */\r\nexport enum InternalTextureSource {\r\n /**\r\n * The source of the texture data is unknown\r\n */\r\n Unknown,\r\n /**\r\n * Texture data comes from an URL\r\n */\r\n Url,\r\n /**\r\n * Texture data is only used for temporary storage\r\n */\r\n Temp,\r\n /**\r\n * Texture data comes from raw data (ArrayBuffer)\r\n */\r\n Raw,\r\n /**\r\n * Texture content is dynamic (video or dynamic texture)\r\n */\r\n Dynamic,\r\n /**\r\n * Texture content is generated by rendering to it\r\n */\r\n RenderTarget,\r\n /**\r\n * Texture content is part of a multi render target process\r\n */\r\n MultiRenderTarget,\r\n /**\r\n * Texture data comes from a cube data file\r\n */\r\n Cube,\r\n /**\r\n * Texture data comes from a raw cube data\r\n */\r\n CubeRaw,\r\n /**\r\n * Texture data come from a prefiltered cube data file\r\n */\r\n CubePrefiltered,\r\n /**\r\n * Texture content is raw 3D data\r\n */\r\n Raw3D,\r\n /**\r\n * Texture content is raw 2D array data\r\n */\r\n Raw2DArray,\r\n /**\r\n * Texture content is a depth/stencil texture\r\n */\r\n DepthStencil,\r\n /**\r\n * Texture data comes from a raw cube data encoded with RGBD\r\n */\r\n CubeRawRGBD,\r\n /**\r\n * Texture content is a depth texture\r\n */\r\n Depth,\r\n}\r\n\r\n/**\r\n * Class used to store data associated with WebGL texture data for the engine\r\n * This class should not be used directly\r\n */\r\nexport class InternalTexture extends TextureSampler {\r\n /**\r\n * Defines if the texture is ready\r\n */\r\n public isReady: boolean = false;\r\n /**\r\n * Defines if the texture is a cube texture\r\n */\r\n public isCube: boolean = false;\r\n /**\r\n * Defines if the texture contains 3D data\r\n */\r\n public is3D: boolean = false;\r\n /**\r\n * Defines if the texture contains 2D array data\r\n */\r\n public is2DArray: boolean = false;\r\n /**\r\n * Defines if the texture contains multiview data\r\n */\r\n public isMultiview: boolean = false;\r\n /**\r\n * Gets the URL used to load this texture\r\n */\r\n public url: string = \"\";\r\n /** @internal */\r\n public _originalUrl: string; // not empty only if different from url\r\n /**\r\n * Gets a boolean indicating if the texture needs mipmaps generation\r\n */\r\n public generateMipMaps: boolean = false;\r\n /**\r\n * Gets a boolean indicating if the texture uses mipmaps\r\n * TODO implements useMipMaps as a separate setting from generateMipMaps\r\n */\r\n public get useMipMaps() {\r\n return this.generateMipMaps;\r\n }\r\n public set useMipMaps(value: boolean) {\r\n this.generateMipMaps = value;\r\n }\r\n /**\r\n * Gets the number of samples used by the texture (WebGL2+ only)\r\n */\r\n public samples: number = 0;\r\n /**\r\n * Gets the type of the texture (int, float...)\r\n */\r\n public type: number = -1;\r\n /**\r\n * Gets the format of the texture (RGB, RGBA...)\r\n */\r\n public format: number = -1;\r\n /**\r\n * Observable called when the texture is loaded\r\n */\r\n public onLoadedObservable = new Observable();\r\n /**\r\n * Observable called when the texture load is raising an error\r\n */\r\n public onErrorObservable = new Observable>();\r\n /**\r\n * If this callback is defined it will be called instead of the default _rebuild function\r\n */\r\n public onRebuildCallback: Nullable<\r\n (internalTexture: InternalTexture) => {\r\n proxy: Nullable>;\r\n isReady: boolean;\r\n isAsync: boolean;\r\n }\r\n > = null;\r\n /**\r\n * Gets the width of the texture\r\n */\r\n public width: number = 0;\r\n /**\r\n * Gets the height of the texture\r\n */\r\n public height: number = 0;\r\n /**\r\n * Gets the depth of the texture\r\n */\r\n public depth: number = 0;\r\n /**\r\n * Gets the initial width of the texture (It could be rescaled if the current system does not support non power of two textures)\r\n */\r\n public baseWidth: number = 0;\r\n /**\r\n * Gets the initial height of the texture (It could be rescaled if the current system does not support non power of two textures)\r\n */\r\n public baseHeight: number = 0;\r\n /**\r\n * Gets the initial depth of the texture (It could be rescaled if the current system does not support non power of two textures)\r\n */\r\n public baseDepth: number = 0;\r\n /**\r\n * Gets a boolean indicating if the texture is inverted on Y axis\r\n */\r\n public invertY: boolean = false;\r\n /**\r\n * Used for debugging purpose only\r\n */\r\n public label?: string;\r\n\r\n // Private\r\n /** @internal */\r\n public _invertVScale = false;\r\n /** @internal */\r\n public _associatedChannel = -1;\r\n /** @internal */\r\n public _source = InternalTextureSource.Unknown;\r\n /** @internal */\r\n public _buffer: Nullable = null;\r\n /** @internal */\r\n public _bufferView: Nullable = null;\r\n /** @internal */\r\n public _bufferViewArray: Nullable = null;\r\n /** @internal */\r\n public _bufferViewArrayArray: Nullable = null;\r\n /** @internal */\r\n public _size: number = 0;\r\n /** @internal */\r\n public _extension: string = \"\";\r\n /** @internal */\r\n public _files: Nullable = null;\r\n /** @internal */\r\n public _workingCanvas: Nullable = null;\r\n /** @internal */\r\n public _workingContext: Nullable = null;\r\n /** @internal */\r\n public _cachedCoordinatesMode: Nullable = null;\r\n /** @internal */\r\n public _isDisabled: boolean = false;\r\n /** @internal */\r\n public _compression: Nullable = null;\r\n /** @internal */\r\n public _sphericalPolynomial: Nullable = null;\r\n /** @internal */\r\n public _sphericalPolynomialPromise: Nullable> = null;\r\n /** @internal */\r\n public _sphericalPolynomialComputed = false;\r\n /** @internal */\r\n public _lodGenerationScale: number = 0;\r\n /** @internal */\r\n public _lodGenerationOffset: number = 0;\r\n /** @internal */\r\n public _useSRGBBuffer: boolean = false;\r\n\r\n // The following three fields helps sharing generated fixed LODs for texture filtering\r\n // In environment not supporting the textureLOD extension like EDGE. They are for internal use only.\r\n // They are at the level of the gl texture to benefit from the cache.\r\n /** @internal */\r\n public _lodTextureHigh: Nullable = null;\r\n /** @internal */\r\n public _lodTextureMid: Nullable = null;\r\n /** @internal */\r\n public _lodTextureLow: Nullable = null;\r\n /** @internal */\r\n public _isRGBD: boolean = false;\r\n\r\n /** @internal */\r\n public _linearSpecularLOD: boolean = false;\r\n /** @internal */\r\n public _irradianceTexture: Nullable = null;\r\n\r\n /** @internal */\r\n public _hardwareTexture: Nullable = null;\r\n\r\n /** @internal */\r\n public _maxLodLevel: Nullable = null;\r\n\r\n /** @internal */\r\n public _references: number = 1;\r\n\r\n /** @internal */\r\n public _gammaSpace: Nullable = null;\r\n\r\n private _engine: ThinEngine;\r\n private _uniqueId: number;\r\n\r\n /** @internal */\r\n public static _Counter = 0;\r\n\r\n /** Gets the unique id of the internal texture */\r\n public get uniqueId() {\r\n return this._uniqueId;\r\n }\r\n\r\n /** @internal */\r\n public _setUniqueId(id: number) {\r\n this._uniqueId = id;\r\n }\r\n\r\n /**\r\n * Gets the Engine the texture belongs to.\r\n * @returns The babylon engine\r\n */\r\n public getEngine(): ThinEngine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * Gets the data source type of the texture\r\n */\r\n public get source(): InternalTextureSource {\r\n return this._source;\r\n }\r\n\r\n /**\r\n * Creates a new InternalTexture\r\n * @param engine defines the engine to use\r\n * @param source defines the type of data that will be used\r\n * @param delayAllocation if the texture allocation should be delayed (default: false)\r\n */\r\n constructor(engine: ThinEngine, source: InternalTextureSource, delayAllocation = false) {\r\n super();\r\n\r\n this._engine = engine;\r\n this._source = source;\r\n this._uniqueId = InternalTexture._Counter++;\r\n\r\n if (!delayAllocation) {\r\n this._hardwareTexture = engine._createHardwareTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Increments the number of references (ie. the number of Texture that point to it)\r\n */\r\n public incrementReferences(): void {\r\n this._references++;\r\n }\r\n\r\n /**\r\n * Change the size of the texture (not the size of the content)\r\n * @param width defines the new width\r\n * @param height defines the new height\r\n * @param depth defines the new depth (1 by default)\r\n */\r\n public updateSize(width: int, height: int, depth: int = 1): void {\r\n this._engine.updateTextureDimensions(this, width, height, depth);\r\n\r\n this.width = width;\r\n this.height = height;\r\n this.depth = depth;\r\n\r\n this.baseWidth = width;\r\n this.baseHeight = height;\r\n this.baseDepth = depth;\r\n\r\n this._size = width * height * depth;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n this.isReady = false;\r\n this._cachedCoordinatesMode = null;\r\n this._cachedWrapU = null;\r\n this._cachedWrapV = null;\r\n this._cachedWrapR = null;\r\n this._cachedAnisotropicFilteringLevel = null;\r\n if (this.onRebuildCallback) {\r\n const data = this.onRebuildCallback(this);\r\n const swapAndSetIsReady = (proxyInternalTexture: InternalTexture) => {\r\n proxyInternalTexture._swapAndDie(this, false);\r\n this.isReady = data.isReady;\r\n };\r\n if (data.isAsync) {\r\n (data.proxy as Promise).then(swapAndSetIsReady);\r\n } else {\r\n swapAndSetIsReady(data.proxy as InternalTexture);\r\n }\r\n return;\r\n }\r\n\r\n let proxy: InternalTexture;\r\n switch (this.source) {\r\n case InternalTextureSource.Temp:\r\n break;\r\n\r\n case InternalTextureSource.Url:\r\n proxy = this._engine.createTexture(\r\n this._originalUrl ?? this.url,\r\n !this.generateMipMaps,\r\n this.invertY,\r\n null,\r\n this.samplingMode,\r\n // Do not use Proxy here as it could be fully synchronous\r\n // and proxy would be undefined.\r\n (temp) => {\r\n temp._swapAndDie(this, false);\r\n this.isReady = true;\r\n },\r\n null,\r\n this._buffer,\r\n undefined,\r\n this.format,\r\n this._extension,\r\n undefined,\r\n undefined,\r\n undefined,\r\n this._useSRGBBuffer\r\n );\r\n return;\r\n\r\n case InternalTextureSource.Raw:\r\n proxy = this._engine.createRawTexture(\r\n this._bufferView,\r\n this.baseWidth,\r\n this.baseHeight,\r\n this.format,\r\n this.generateMipMaps,\r\n this.invertY,\r\n this.samplingMode,\r\n this._compression,\r\n this.type,\r\n undefined,\r\n this._useSRGBBuffer\r\n );\r\n proxy._swapAndDie(this, false);\r\n\r\n this.isReady = true;\r\n break;\r\n\r\n case InternalTextureSource.Raw3D:\r\n proxy = this._engine.createRawTexture3D(\r\n this._bufferView,\r\n this.baseWidth,\r\n this.baseHeight,\r\n this.baseDepth,\r\n this.format,\r\n this.generateMipMaps,\r\n this.invertY,\r\n this.samplingMode,\r\n this._compression,\r\n this.type\r\n );\r\n proxy._swapAndDie(this, false);\r\n\r\n this.isReady = true;\r\n break;\r\n\r\n case InternalTextureSource.Raw2DArray:\r\n proxy = this._engine.createRawTexture2DArray(\r\n this._bufferView,\r\n this.baseWidth,\r\n this.baseHeight,\r\n this.baseDepth,\r\n this.format,\r\n this.generateMipMaps,\r\n this.invertY,\r\n this.samplingMode,\r\n this._compression,\r\n this.type\r\n );\r\n proxy._swapAndDie(this, false);\r\n\r\n this.isReady = true;\r\n break;\r\n\r\n case InternalTextureSource.Dynamic:\r\n proxy = this._engine.createDynamicTexture(this.baseWidth, this.baseHeight, this.generateMipMaps, this.samplingMode);\r\n proxy._swapAndDie(this, false);\r\n this._engine.updateDynamicTexture(this, this._engine.getRenderingCanvas()!, this.invertY, undefined, undefined, true);\r\n\r\n // The engine will make sure to update content so no need to flag it as isReady = true\r\n break;\r\n\r\n case InternalTextureSource.Cube:\r\n proxy = this._engine.createCubeTexture(\r\n this.url,\r\n null,\r\n this._files,\r\n !this.generateMipMaps,\r\n () => {\r\n proxy._swapAndDie(this, false);\r\n this.isReady = true;\r\n },\r\n null,\r\n this.format,\r\n this._extension,\r\n false,\r\n 0,\r\n 0,\r\n null,\r\n undefined,\r\n this._useSRGBBuffer\r\n );\r\n return;\r\n\r\n case InternalTextureSource.CubeRaw:\r\n proxy = this._engine.createRawCubeTexture(\r\n this._bufferViewArray!,\r\n this.width,\r\n this.format,\r\n this.type,\r\n this.generateMipMaps,\r\n this.invertY,\r\n this.samplingMode,\r\n this._compression\r\n );\r\n proxy._swapAndDie(this, false);\r\n this.isReady = true;\r\n break;\r\n\r\n case InternalTextureSource.CubeRawRGBD:\r\n // This case is being handeled by the environment texture tools and is not a part of the rebuild process.\r\n // To use CubeRawRGBD use updateRGBDAsync on the cube texture.\r\n return;\r\n\r\n case InternalTextureSource.CubePrefiltered:\r\n proxy = this._engine.createPrefilteredCubeTexture(\r\n this.url,\r\n null,\r\n this._lodGenerationScale,\r\n this._lodGenerationOffset,\r\n (proxy) => {\r\n if (proxy) {\r\n proxy._swapAndDie(this, false);\r\n }\r\n this.isReady = true;\r\n },\r\n null,\r\n this.format,\r\n this._extension\r\n );\r\n proxy._sphericalPolynomial = this._sphericalPolynomial;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _swapAndDie(target: InternalTexture, swapAll = true): void {\r\n // TODO what about refcount on target?\r\n\r\n this._hardwareTexture?.setUsage(target._source, this.generateMipMaps, this.isCube, this.width, this.height);\r\n\r\n target._hardwareTexture = this._hardwareTexture;\r\n if (swapAll) {\r\n target._isRGBD = this._isRGBD;\r\n }\r\n\r\n if (this._lodTextureHigh) {\r\n if (target._lodTextureHigh) {\r\n target._lodTextureHigh.dispose();\r\n }\r\n target._lodTextureHigh = this._lodTextureHigh;\r\n }\r\n\r\n if (this._lodTextureMid) {\r\n if (target._lodTextureMid) {\r\n target._lodTextureMid.dispose();\r\n }\r\n target._lodTextureMid = this._lodTextureMid;\r\n }\r\n\r\n if (this._lodTextureLow) {\r\n if (target._lodTextureLow) {\r\n target._lodTextureLow.dispose();\r\n }\r\n target._lodTextureLow = this._lodTextureLow;\r\n }\r\n\r\n if (this._irradianceTexture) {\r\n if (target._irradianceTexture) {\r\n target._irradianceTexture.dispose();\r\n }\r\n target._irradianceTexture = this._irradianceTexture;\r\n }\r\n\r\n const cache = this._engine.getLoadedTexturesCache();\r\n let index = cache.indexOf(this);\r\n if (index !== -1) {\r\n cache.splice(index, 1);\r\n }\r\n\r\n index = cache.indexOf(target);\r\n if (index === -1) {\r\n cache.push(target);\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the current allocated resources\r\n */\r\n public dispose(): void {\r\n this._references--;\r\n this.onLoadedObservable.clear();\r\n this.onErrorObservable.clear();\r\n if (this._references === 0) {\r\n this._engine._releaseTexture(this);\r\n this._hardwareTexture = null;\r\n }\r\n }\r\n}\r\n","import { Constants } from \"../../Engines/constants\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Class used to store a texture sampler data\r\n */\r\nexport class TextureSampler {\r\n /**\r\n * Gets the sampling mode of the texture\r\n */\r\n public samplingMode: number = -1;\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n public get wrapU() {\r\n return this._cachedWrapU;\r\n }\r\n\r\n public set wrapU(value: Nullable) {\r\n this._cachedWrapU = value;\r\n }\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n public get wrapV() {\r\n return this._cachedWrapV;\r\n }\r\n\r\n public set wrapV(value: Nullable) {\r\n this._cachedWrapV = value;\r\n }\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n public get wrapR() {\r\n return this._cachedWrapR;\r\n }\r\n\r\n public set wrapR(value: Nullable) {\r\n this._cachedWrapR = value;\r\n }\r\n\r\n /**\r\n * With compliant hardware and browser (supporting anisotropic filtering)\r\n * this defines the level of anisotropic filtering in the texture.\r\n * The higher the better but the slower.\r\n */\r\n public get anisotropicFilteringLevel() {\r\n return this._cachedAnisotropicFilteringLevel;\r\n }\r\n\r\n public set anisotropicFilteringLevel(value: Nullable) {\r\n this._cachedAnisotropicFilteringLevel = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the comparison function (Constants.LESS, Constants.EQUAL, etc). Set 0 to not use a comparison function\r\n */\r\n public get comparisonFunction() {\r\n return this._comparisonFunction;\r\n }\r\n\r\n public set comparisonFunction(value: number) {\r\n this._comparisonFunction = value;\r\n }\r\n\r\n private _useMipMaps = true;\r\n /**\r\n * Indicates to use the mip maps (if available on the texture).\r\n * Thanks to this flag, you can instruct the sampler to not sample the mipmaps even if they exist (and if the sampling mode is set to a value that normally samples the mipmaps!)\r\n */\r\n public get useMipMaps() {\r\n return this._useMipMaps;\r\n }\r\n\r\n public set useMipMaps(value: boolean) {\r\n this._useMipMaps = value;\r\n }\r\n\r\n /** @internal */\r\n public _cachedWrapU: Nullable = null;\r\n\r\n /** @internal */\r\n public _cachedWrapV: Nullable = null;\r\n\r\n /** @internal */\r\n public _cachedWrapR: Nullable = null;\r\n\r\n /** @internal */\r\n public _cachedAnisotropicFilteringLevel: Nullable = null;\r\n\r\n /** @internal */\r\n public _comparisonFunction: number = 0;\r\n\r\n /**\r\n * Creates a Sampler instance\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Sets all the parameters of the sampler\r\n * @param wrapU u address mode (default: TEXTURE_WRAP_ADDRESSMODE)\r\n * @param wrapV v address mode (default: TEXTURE_WRAP_ADDRESSMODE)\r\n * @param wrapR r address mode (default: TEXTURE_WRAP_ADDRESSMODE)\r\n * @param anisotropicFilteringLevel anisotropic level (default: 1)\r\n * @param samplingMode sampling mode (default: Constants.TEXTURE_BILINEAR_SAMPLINGMODE)\r\n * @param comparisonFunction comparison function (default: 0 - no comparison function)\r\n * @returns the current sampler instance\r\n */\r\n public setParameters(\r\n wrapU = Constants.TEXTURE_WRAP_ADDRESSMODE,\r\n wrapV = Constants.TEXTURE_WRAP_ADDRESSMODE,\r\n wrapR = Constants.TEXTURE_WRAP_ADDRESSMODE,\r\n anisotropicFilteringLevel = 1,\r\n samplingMode = Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n comparisonFunction = 0\r\n ): TextureSampler {\r\n this._cachedWrapU = wrapU;\r\n this._cachedWrapV = wrapV;\r\n this._cachedWrapR = wrapR;\r\n this._cachedAnisotropicFilteringLevel = anisotropicFilteringLevel;\r\n this.samplingMode = samplingMode;\r\n this._comparisonFunction = comparisonFunction;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Compares this sampler with another one\r\n * @param other sampler to compare with\r\n * @returns true if the samplers have the same parametres, else false\r\n */\r\n public compareSampler(other: TextureSampler): boolean {\r\n return (\r\n this._cachedWrapU === other._cachedWrapU &&\r\n this._cachedWrapV === other._cachedWrapV &&\r\n this._cachedWrapR === other._cachedWrapR &&\r\n this._cachedAnisotropicFilteringLevel === other._cachedAnisotropicFilteringLevel &&\r\n this.samplingMode === other.samplingMode &&\r\n this._comparisonFunction === other._comparisonFunction &&\r\n this._useMipMaps === other._useMipMaps\r\n );\r\n }\r\n}\r\n","import { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IShaderProcessor } from \"../Processors/iShaderProcessor\";\r\nimport type { ShaderProcessingContext } from \"../Processors/shaderProcessingOptions\";\r\n\r\nimport type { ThinEngine } from \"../thinEngine\";\r\n\r\n/** @internal */\r\nexport class WebGLShaderProcessor implements IShaderProcessor {\r\n public shaderLanguage = ShaderLanguage.GLSL;\r\n\r\n public postProcessor(code: string, defines: string[], isFragment: boolean, processingContext: Nullable, engine: ThinEngine) {\r\n // Remove extensions\r\n if (!engine.getCaps().drawBuffersExtension) {\r\n // even if enclosed in #if/#endif, IE11 does parse the #extension declaration, so we need to remove it altogether\r\n const regex = /#extension.+GL_EXT_draw_buffers.+(enable|require)/g;\r\n code = code.replace(regex, \"\");\r\n }\r\n\r\n return code;\r\n }\r\n}\r\n","import { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\nimport type { IShaderProcessor } from \"../Processors/iShaderProcessor\";\r\n\r\nconst varyingRegex = /(flat\\s)?\\s*varying\\s*.*/;\r\n\r\n/** @internal */\r\nexport class WebGL2ShaderProcessor implements IShaderProcessor {\r\n public shaderLanguage = ShaderLanguage.GLSL;\r\n\r\n public attributeProcessor(attribute: string) {\r\n return attribute.replace(\"attribute\", \"in\");\r\n }\r\n\r\n public varyingCheck(varying: string, _isFragment: boolean) {\r\n return varyingRegex.test(varying);\r\n }\r\n\r\n public varyingProcessor(varying: string, isFragment: boolean) {\r\n return varying.replace(\"varying\", isFragment ? \"in\" : \"out\");\r\n }\r\n\r\n public postProcessor(code: string, defines: string[], isFragment: boolean) {\r\n const hasDrawBuffersExtension = code.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1;\r\n\r\n // Remove extensions\r\n const regex = /#extension.+(GL_OVR_multiview2|GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;\r\n code = code.replace(regex, \"\");\r\n\r\n // Replace instructions\r\n code = code.replace(/texture2D\\s*\\(/g, \"texture(\");\r\n if (isFragment) {\r\n const hasOutput = code.search(/layout *\\(location *= *0\\) *out/g) !== -1;\r\n\r\n code = code.replace(/texture2DLodEXT\\s*\\(/g, \"textureLod(\");\r\n code = code.replace(/textureCubeLodEXT\\s*\\(/g, \"textureLod(\");\r\n code = code.replace(/textureCube\\s*\\(/g, \"texture(\");\r\n code = code.replace(/gl_FragDepthEXT/g, \"gl_FragDepth\");\r\n code = code.replace(/gl_FragColor/g, \"glFragColor\");\r\n code = code.replace(/gl_FragData/g, \"glFragData\");\r\n code = code.replace(/void\\s+?main\\s*\\(/g, (hasDrawBuffersExtension || hasOutput ? \"\" : \"layout(location = 0) out vec4 glFragColor;\\n\") + \"void main(\");\r\n } else {\r\n const hasMultiviewExtension = defines.indexOf(\"#define MULTIVIEW\") !== -1;\r\n if (hasMultiviewExtension) {\r\n return \"#extension GL_OVR_multiview2 : require\\nlayout (num_views = 2) in;\\n\" + code;\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n}\r\n","/**\r\n * Class used to store gfx data (like WebGLBuffer)\r\n */\r\nexport class DataBuffer {\r\n private static _Counter = 0;\r\n\r\n /**\r\n * Gets or sets the number of objects referencing this buffer\r\n */\r\n public references: number = 0;\r\n /** Gets or sets the size of the underlying buffer */\r\n public capacity: number = 0;\r\n /**\r\n * Gets or sets a boolean indicating if the buffer contains 32bits indices\r\n */\r\n public is32Bits: boolean = false;\r\n\r\n /**\r\n * Gets the underlying buffer\r\n */\r\n public get underlyingResource(): any {\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets the unique id of this buffer\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * Constructs the buffer\r\n */\r\n constructor() {\r\n this.uniqueId = DataBuffer._Counter++;\r\n }\r\n}\r\n","import { DataBuffer } from \"../../Buffers/dataBuffer\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/** @internal */\r\nexport class WebGLDataBuffer extends DataBuffer {\r\n private _buffer: Nullable;\r\n\r\n public constructor(resource: WebGLBuffer) {\r\n super();\r\n this._buffer = resource;\r\n }\r\n\r\n public get underlyingResource(): any {\r\n return this._buffer;\r\n }\r\n}\r\n","import type { IPipelineContext } from \"../IPipelineContext\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Effect } from \"../../Materials/effect\";\r\nimport type { IMatrixLike, IVector2Like, IVector3Like, IVector4Like, IColor3Like, IColor4Like, IQuaternionLike } from \"../../Maths/math.like\";\r\nimport type { ThinEngine } from \"../thinEngine\";\r\n\r\n/** @internal */\r\nexport class WebGLPipelineContext implements IPipelineContext {\r\n private _valueCache: { [key: string]: any } = {};\r\n private _uniforms: { [key: string]: Nullable };\r\n\r\n public engine: ThinEngine;\r\n public program: Nullable;\r\n public context?: WebGLRenderingContext;\r\n public vertexShader?: WebGLShader;\r\n public fragmentShader?: WebGLShader;\r\n public isParallelCompiled: boolean;\r\n public onCompiled?: () => void;\r\n public transformFeedback?: WebGLTransformFeedback | null;\r\n\r\n public vertexCompilationError: Nullable = null;\r\n public fragmentCompilationError: Nullable = null;\r\n public programLinkError: Nullable = null;\r\n public programValidationError: Nullable = null;\r\n\r\n /** @internal */\r\n public _isDisposed = false;\r\n\r\n public get isAsync() {\r\n return this.isParallelCompiled;\r\n }\r\n\r\n public get isReady(): boolean {\r\n if (this.program) {\r\n if (this.isParallelCompiled) {\r\n return this.engine._isRenderingStateCompiled(this);\r\n }\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public _handlesSpectorRebuildCallback(onCompiled: (program: WebGLProgram) => void): void {\r\n if (onCompiled && this.program) {\r\n onCompiled(this.program);\r\n }\r\n }\r\n\r\n public _fillEffectInformation(\r\n effect: Effect,\r\n uniformBuffersNames: { [key: string]: number },\r\n uniformsNames: string[],\r\n uniforms: { [key: string]: Nullable },\r\n samplerList: string[],\r\n samplers: { [key: string]: number },\r\n attributesNames: string[],\r\n attributes: number[]\r\n ) {\r\n const engine = this.engine;\r\n if (engine.supportsUniformBuffers) {\r\n for (const name in uniformBuffersNames) {\r\n effect.bindUniformBlock(name, uniformBuffersNames[name]);\r\n }\r\n }\r\n\r\n const effectAvailableUniforms = this.engine.getUniforms(this, uniformsNames);\r\n effectAvailableUniforms.forEach((uniform, index) => {\r\n uniforms[uniformsNames[index]] = uniform;\r\n });\r\n this._uniforms = uniforms;\r\n\r\n let index: number;\r\n for (index = 0; index < samplerList.length; index++) {\r\n const sampler = effect.getUniform(samplerList[index]);\r\n if (sampler == null) {\r\n samplerList.splice(index, 1);\r\n index--;\r\n }\r\n }\r\n\r\n samplerList.forEach((name, index) => {\r\n samplers[name] = index;\r\n });\r\n\r\n for (const attr of engine.getAttributes(this, attributesNames)) {\r\n attributes.push(attr);\r\n }\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n this._uniforms = {};\r\n this._isDisposed = true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _cacheMatrix(uniformName: string, matrix: IMatrixLike): boolean {\r\n const cache = this._valueCache[uniformName];\r\n const flag = matrix.updateFlag;\r\n if (cache !== undefined && cache === flag) {\r\n return false;\r\n }\r\n\r\n this._valueCache[uniformName] = flag;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _cacheFloat2(uniformName: string, x: number, y: number): boolean {\r\n let cache = this._valueCache[uniformName];\r\n if (!cache || cache.length !== 2) {\r\n cache = [x, y];\r\n this._valueCache[uniformName] = cache;\r\n return true;\r\n }\r\n\r\n let changed = false;\r\n if (cache[0] !== x) {\r\n cache[0] = x;\r\n changed = true;\r\n }\r\n if (cache[1] !== y) {\r\n cache[1] = y;\r\n changed = true;\r\n }\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _cacheFloat3(uniformName: string, x: number, y: number, z: number): boolean {\r\n let cache = this._valueCache[uniformName];\r\n if (!cache || cache.length !== 3) {\r\n cache = [x, y, z];\r\n this._valueCache[uniformName] = cache;\r\n return true;\r\n }\r\n\r\n let changed = false;\r\n if (cache[0] !== x) {\r\n cache[0] = x;\r\n changed = true;\r\n }\r\n if (cache[1] !== y) {\r\n cache[1] = y;\r\n changed = true;\r\n }\r\n if (cache[2] !== z) {\r\n cache[2] = z;\r\n changed = true;\r\n }\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _cacheFloat4(uniformName: string, x: number, y: number, z: number, w: number): boolean {\r\n let cache = this._valueCache[uniformName];\r\n if (!cache || cache.length !== 4) {\r\n cache = [x, y, z, w];\r\n this._valueCache[uniformName] = cache;\r\n return true;\r\n }\r\n\r\n let changed = false;\r\n if (cache[0] !== x) {\r\n cache[0] = x;\r\n changed = true;\r\n }\r\n if (cache[1] !== y) {\r\n cache[1] = y;\r\n changed = true;\r\n }\r\n if (cache[2] !== z) {\r\n cache[2] = z;\r\n changed = true;\r\n }\r\n if (cache[3] !== w) {\r\n cache[3] = w;\r\n changed = true;\r\n }\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * Sets an integer value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param value Value to be set.\r\n */\r\n public setInt(uniformName: string, value: number): void {\r\n const cache = this._valueCache[uniformName];\r\n if (cache !== undefined && cache === value) {\r\n return;\r\n }\r\n\r\n if (this.engine.setInt(this._uniforms[uniformName], value)) {\r\n this._valueCache[uniformName] = value;\r\n }\r\n }\r\n\r\n /**\r\n * Sets a int2 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First int in int2.\r\n * @param y Second int in int2.\r\n */\r\n public setInt2(uniformName: string, x: number, y: number): void {\r\n if (this._cacheFloat2(uniformName, x, y)) {\r\n if (!this.engine.setInt2(this._uniforms[uniformName], x, y)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a int3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First int in int3.\r\n * @param y Second int in int3.\r\n * @param z Third int in int3.\r\n */\r\n public setInt3(uniformName: string, x: number, y: number, z: number): void {\r\n if (this._cacheFloat3(uniformName, x, y, z)) {\r\n if (!this.engine.setInt3(this._uniforms[uniformName], x, y, z)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a int4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First int in int4.\r\n * @param y Second int in int4.\r\n * @param z Third int in int4.\r\n * @param w Fourth int in int4.\r\n */\r\n public setInt4(uniformName: string, x: number, y: number, z: number, w: number): void {\r\n if (this._cacheFloat4(uniformName, x, y, z, w)) {\r\n if (!this.engine.setInt4(this._uniforms[uniformName], x, y, z, w)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets an int array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setIntArray(uniformName: string, array: Int32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setIntArray(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setIntArray2(uniformName: string, array: Int32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setIntArray2(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setIntArray3(uniformName: string, array: Int32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setIntArray3(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setIntArray4(uniformName: string, array: Int32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setIntArray4(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an unsigned integer value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param value Value to be set.\r\n */\r\n public setUInt(uniformName: string, value: number): void {\r\n const cache = this._valueCache[uniformName];\r\n if (cache !== undefined && cache === value) {\r\n return;\r\n }\r\n\r\n if (this.engine.setUInt(this._uniforms[uniformName], value)) {\r\n this._valueCache[uniformName] = value;\r\n }\r\n }\r\n\r\n /**\r\n * Sets an unsigned int2 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First unsigned int in uint2.\r\n * @param y Second unsigned int in uint2.\r\n */\r\n public setUInt2(uniformName: string, x: number, y: number): void {\r\n if (this._cacheFloat2(uniformName, x, y)) {\r\n if (!this.engine.setUInt2(this._uniforms[uniformName], x, y)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets an unsigned int3 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First unsigned int in uint3.\r\n * @param y Second unsigned int in uint3.\r\n * @param z Third unsigned int in uint3.\r\n */\r\n public setUInt3(uniformName: string, x: number, y: number, z: number): void {\r\n if (this._cacheFloat3(uniformName, x, y, z)) {\r\n if (!this.engine.setUInt3(this._uniforms[uniformName], x, y, z)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets an unsigned int4 value on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First unsigned int in uint4.\r\n * @param y Second unsigned int in uint4.\r\n * @param z Third unsigned int in uint4.\r\n * @param w Fourth unsigned int in uint4.\r\n */\r\n public setUInt4(uniformName: string, x: number, y: number, z: number, w: number): void {\r\n if (this._cacheFloat4(uniformName, x, y, z, w)) {\r\n if (!this.engine.setUInt4(this._uniforms[uniformName], x, y, z, w)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setUIntArray(uniformName: string, array: Uint32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setUIntArray(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setUIntArray2(uniformName: string, array: Uint32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setUIntArray2(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setUIntArray3(uniformName: string, array: Uint32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setUIntArray3(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an unsigned int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setUIntArray4(uniformName: string, array: Uint32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setUIntArray4(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an array on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setArray(uniformName: string, array: number[]): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setArray(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setArray2(uniformName: string, array: number[]): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setArray2(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n * @returns this effect.\r\n */\r\n public setArray3(uniformName: string, array: number[]): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setArray3(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)\r\n * @param uniformName Name of the variable.\r\n * @param array array to be set.\r\n */\r\n public setArray4(uniformName: string, array: number[]): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setArray4(this._uniforms[uniformName], array);\r\n }\r\n\r\n /**\r\n * Sets matrices on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param matrices matrices to be set.\r\n */\r\n public setMatrices(uniformName: string, matrices: Float32Array): void {\r\n if (!matrices) {\r\n return;\r\n }\r\n\r\n this._valueCache[uniformName] = null;\r\n this.engine.setMatrices(this._uniforms[uniformName], matrices);\r\n }\r\n\r\n /**\r\n * Sets matrix on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param matrix matrix to be set.\r\n */\r\n public setMatrix(uniformName: string, matrix: IMatrixLike): void {\r\n if (this._cacheMatrix(uniformName, matrix)) {\r\n if (!this.engine.setMatrices(this._uniforms[uniformName], matrix.toArray() as Float32Array)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)\r\n * @param uniformName Name of the variable.\r\n * @param matrix matrix to be set.\r\n */\r\n public setMatrix3x3(uniformName: string, matrix: Float32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setMatrix3x3(this._uniforms[uniformName], matrix);\r\n }\r\n\r\n /**\r\n * Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)\r\n * @param uniformName Name of the variable.\r\n * @param matrix matrix to be set.\r\n */\r\n public setMatrix2x2(uniformName: string, matrix: Float32Array): void {\r\n this._valueCache[uniformName] = null;\r\n this.engine.setMatrix2x2(this._uniforms[uniformName], matrix);\r\n }\r\n\r\n /**\r\n * Sets a float on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param value value to be set.\r\n * @returns this effect.\r\n */\r\n public setFloat(uniformName: string, value: number): void {\r\n const cache = this._valueCache[uniformName];\r\n if (cache !== undefined && cache === value) {\r\n return;\r\n }\r\n\r\n if (this.engine.setFloat(this._uniforms[uniformName], value)) {\r\n this._valueCache[uniformName] = value;\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Vector2 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param vector2 vector2 to be set.\r\n */\r\n public setVector2(uniformName: string, vector2: IVector2Like): void {\r\n if (this._cacheFloat2(uniformName, vector2.x, vector2.y)) {\r\n if (!this.engine.setFloat2(this._uniforms[uniformName], vector2.x, vector2.y)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a float2 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First float in float2.\r\n * @param y Second float in float2.\r\n */\r\n public setFloat2(uniformName: string, x: number, y: number): void {\r\n if (this._cacheFloat2(uniformName, x, y)) {\r\n if (!this.engine.setFloat2(this._uniforms[uniformName], x, y)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Vector3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param vector3 Value to be set.\r\n */\r\n public setVector3(uniformName: string, vector3: IVector3Like): void {\r\n if (this._cacheFloat3(uniformName, vector3.x, vector3.y, vector3.z)) {\r\n if (!this.engine.setFloat3(this._uniforms[uniformName], vector3.x, vector3.y, vector3.z)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a float3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First float in float3.\r\n * @param y Second float in float3.\r\n * @param z Third float in float3.\r\n */\r\n public setFloat3(uniformName: string, x: number, y: number, z: number): void {\r\n if (this._cacheFloat3(uniformName, x, y, z)) {\r\n if (!this.engine.setFloat3(this._uniforms[uniformName], x, y, z)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Vector4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param vector4 Value to be set.\r\n */\r\n public setVector4(uniformName: string, vector4: IVector4Like): void {\r\n if (this._cacheFloat4(uniformName, vector4.x, vector4.y, vector4.z, vector4.w)) {\r\n if (!this.engine.setFloat4(this._uniforms[uniformName], vector4.x, vector4.y, vector4.z, vector4.w)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Quaternion on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param quaternion Value to be set.\r\n */\r\n public setQuaternion(uniformName: string, quaternion: IQuaternionLike): void {\r\n if (this._cacheFloat4(uniformName, quaternion.x, quaternion.y, quaternion.z, quaternion.w)) {\r\n if (!this.engine.setFloat4(this._uniforms[uniformName], quaternion.x, quaternion.y, quaternion.z, quaternion.w)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a float4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param x First float in float4.\r\n * @param y Second float in float4.\r\n * @param z Third float in float4.\r\n * @param w Fourth float in float4.\r\n * @returns this effect.\r\n */\r\n public setFloat4(uniformName: string, x: number, y: number, z: number, w: number): void {\r\n if (this._cacheFloat4(uniformName, x, y, z, w)) {\r\n if (!this.engine.setFloat4(this._uniforms[uniformName], x, y, z, w)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Color3 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param color3 Value to be set.\r\n */\r\n public setColor3(uniformName: string, color3: IColor3Like): void {\r\n if (this._cacheFloat3(uniformName, color3.r, color3.g, color3.b)) {\r\n if (!this.engine.setFloat3(this._uniforms[uniformName], color3.r, color3.g, color3.b)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Color4 on a uniform variable.\r\n * @param uniformName Name of the variable.\r\n * @param color3 Value to be set.\r\n * @param alpha Alpha value to be set.\r\n */\r\n public setColor4(uniformName: string, color3: IColor3Like, alpha: number): void {\r\n if (this._cacheFloat4(uniformName, color3.r, color3.g, color3.b, alpha)) {\r\n if (!this.engine.setFloat4(this._uniforms[uniformName], color3.r, color3.g, color3.b, alpha)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a Color4 on a uniform variable\r\n * @param uniformName defines the name of the variable\r\n * @param color4 defines the value to be set\r\n */\r\n public setDirectColor4(uniformName: string, color4: IColor4Like): void {\r\n if (this._cacheFloat4(uniformName, color4.r, color4.g, color4.b, color4.a)) {\r\n if (!this.engine.setFloat4(this._uniforms[uniformName], color4.r, color4.g, color4.b, color4.a)) {\r\n this._valueCache[uniformName] = null;\r\n }\r\n }\r\n }\r\n\r\n public _getVertexShaderCode(): string | null {\r\n return this.vertexShader ? this.engine._getShaderSource(this.vertexShader) : null;\r\n }\r\n\r\n public _getFragmentShaderCode(): string | null {\r\n return this.fragmentShader ? this.engine._getShaderSource(this.fragmentShader) : null;\r\n }\r\n}\r\n","import type { HardwareTextureWrapper } from \"../../Materials/Textures/hardwareTextureWrapper\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/** @internal */\r\nexport class WebGLHardwareTexture implements HardwareTextureWrapper {\r\n private _webGLTexture: WebGLTexture;\r\n private _context: WebGLRenderingContext;\r\n\r\n // There can be multiple buffers for a single WebGL texture because different layers of a 2DArrayTexture / 3DTexture\r\n // or different faces of a cube texture can be bound to different render targets at the same time.\r\n private _MSAARenderBuffers: Nullable = null;\r\n\r\n public get underlyingResource(): Nullable {\r\n return this._webGLTexture;\r\n }\r\n\r\n constructor(existingTexture: Nullable = null, context: WebGLRenderingContext) {\r\n this._context = context as WebGLRenderingContext;\r\n if (!existingTexture) {\r\n existingTexture = context.createTexture();\r\n if (!existingTexture) {\r\n throw new Error(\"Unable to create webGL texture\");\r\n }\r\n }\r\n this.set(existingTexture);\r\n }\r\n\r\n public setUsage(): void {}\r\n\r\n public set(hardwareTexture: WebGLTexture) {\r\n this._webGLTexture = hardwareTexture;\r\n }\r\n\r\n public reset() {\r\n this._webGLTexture = null as any;\r\n this._MSAARenderBuffers = null;\r\n }\r\n\r\n public addMSAARenderBuffer(buffer: WebGLRenderbuffer) {\r\n if (!this._MSAARenderBuffers) {\r\n this._MSAARenderBuffers = [];\r\n }\r\n this._MSAARenderBuffers.push(buffer);\r\n }\r\n\r\n public releaseMSAARenderBuffers() {\r\n if (this._MSAARenderBuffers) {\r\n for (const buffer of this._MSAARenderBuffers) {\r\n this._context.deleteRenderbuffer(buffer);\r\n }\r\n this._MSAARenderBuffers = null;\r\n }\r\n }\r\n\r\n public release() {\r\n this.releaseMSAARenderBuffers();\r\n\r\n if (this._webGLTexture) {\r\n this._context.deleteTexture(this._webGLTexture);\r\n }\r\n this.reset();\r\n }\r\n}\r\n","import type { IDrawContext } from \"../Engines/IDrawContext\";\r\nimport type { IMaterialContext } from \"../Engines/IMaterialContext\";\r\nimport type { Nullable } from \"../types\";\r\n\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { Effect } from \"./effect\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\n\r\n/** @internal */\r\nexport class DrawWrapper {\r\n public effect: Nullable;\r\n public defines: Nullable;\r\n public materialContext?: IMaterialContext;\r\n public drawContext?: IDrawContext;\r\n\r\n public static IsWrapper(effect: Effect | DrawWrapper): effect is DrawWrapper {\r\n return (effect as Effect).getPipelineContext === undefined;\r\n }\r\n\r\n public static GetEffect(effect: Effect | DrawWrapper): Nullable {\r\n return (effect as Effect).getPipelineContext === undefined ? (effect as DrawWrapper).effect : (effect as Effect);\r\n }\r\n\r\n constructor(engine: ThinEngine, createMaterialContext = true) {\r\n this.effect = null;\r\n this.defines = null;\r\n this.drawContext = engine.createDrawContext();\r\n if (createMaterialContext) {\r\n this.materialContext = engine.createMaterialContext();\r\n }\r\n }\r\n\r\n public setEffect(effect: Nullable, defines?: Nullable, resetContext = true): void {\r\n this.effect = effect;\r\n if (defines !== undefined) {\r\n this.defines = defines;\r\n }\r\n if (resetContext) {\r\n this.drawContext?.reset();\r\n }\r\n }\r\n\r\n public dispose(): void {\r\n this.drawContext?.dispose();\r\n }\r\n}\r\n","import type { IStencilState } from \"./IStencilState\";\r\n\r\n/**\r\n * @internal\r\n **/\r\nexport class StencilStateComposer {\r\n protected _isStencilTestDirty = false;\r\n protected _isStencilMaskDirty = false;\r\n protected _isStencilFuncDirty = false;\r\n protected _isStencilOpDirty = false;\r\n\r\n protected _enabled: boolean;\r\n\r\n protected _mask: number;\r\n\r\n protected _func: number;\r\n protected _funcRef: number;\r\n protected _funcMask: number;\r\n\r\n protected _opStencilFail: number;\r\n protected _opDepthFail: number;\r\n protected _opStencilDepthPass: number;\r\n\r\n public stencilGlobal: IStencilState;\r\n public stencilMaterial: IStencilState | undefined;\r\n\r\n public useStencilGlobalOnly = false;\r\n\r\n public get isDirty(): boolean {\r\n return this._isStencilTestDirty || this._isStencilMaskDirty || this._isStencilFuncDirty || this._isStencilOpDirty;\r\n }\r\n\r\n public get func(): number {\r\n return this._func;\r\n }\r\n\r\n public set func(value: number) {\r\n if (this._func === value) {\r\n return;\r\n }\r\n\r\n this._func = value;\r\n this._isStencilFuncDirty = true;\r\n }\r\n\r\n public get funcRef(): number {\r\n return this._funcRef;\r\n }\r\n\r\n public set funcRef(value: number) {\r\n if (this._funcRef === value) {\r\n return;\r\n }\r\n\r\n this._funcRef = value;\r\n this._isStencilFuncDirty = true;\r\n }\r\n\r\n public get funcMask(): number {\r\n return this._funcMask;\r\n }\r\n\r\n public set funcMask(value: number) {\r\n if (this._funcMask === value) {\r\n return;\r\n }\r\n\r\n this._funcMask = value;\r\n this._isStencilFuncDirty = true;\r\n }\r\n\r\n public get opStencilFail(): number {\r\n return this._opStencilFail;\r\n }\r\n\r\n public set opStencilFail(value: number) {\r\n if (this._opStencilFail === value) {\r\n return;\r\n }\r\n\r\n this._opStencilFail = value;\r\n this._isStencilOpDirty = true;\r\n }\r\n\r\n public get opDepthFail(): number {\r\n return this._opDepthFail;\r\n }\r\n\r\n public set opDepthFail(value: number) {\r\n if (this._opDepthFail === value) {\r\n return;\r\n }\r\n\r\n this._opDepthFail = value;\r\n this._isStencilOpDirty = true;\r\n }\r\n\r\n public get opStencilDepthPass(): number {\r\n return this._opStencilDepthPass;\r\n }\r\n\r\n public set opStencilDepthPass(value: number) {\r\n if (this._opStencilDepthPass === value) {\r\n return;\r\n }\r\n\r\n this._opStencilDepthPass = value;\r\n this._isStencilOpDirty = true;\r\n }\r\n\r\n public get mask(): number {\r\n return this._mask;\r\n }\r\n\r\n public set mask(value: number) {\r\n if (this._mask === value) {\r\n return;\r\n }\r\n\r\n this._mask = value;\r\n this._isStencilMaskDirty = true;\r\n }\r\n\r\n public get enabled(): boolean {\r\n return this._enabled;\r\n }\r\n\r\n public set enabled(value: boolean) {\r\n if (this._enabled === value) {\r\n return;\r\n }\r\n\r\n this._enabled = value;\r\n this._isStencilTestDirty = true;\r\n }\r\n\r\n public constructor(reset = true) {\r\n if (reset) {\r\n this.reset();\r\n }\r\n }\r\n\r\n public reset() {\r\n this.stencilMaterial = undefined;\r\n\r\n this.stencilGlobal?.reset();\r\n\r\n this._isStencilTestDirty = true;\r\n this._isStencilMaskDirty = true;\r\n this._isStencilFuncDirty = true;\r\n this._isStencilOpDirty = true;\r\n }\r\n\r\n public apply(gl?: WebGLRenderingContext) {\r\n if (!gl) {\r\n return;\r\n }\r\n\r\n const stencilMaterialEnabled = !this.useStencilGlobalOnly && !!this.stencilMaterial?.enabled;\r\n\r\n this.enabled = stencilMaterialEnabled ? this.stencilMaterial!.enabled : this.stencilGlobal.enabled;\r\n this.func = stencilMaterialEnabled ? this.stencilMaterial!.func : this.stencilGlobal.func;\r\n this.funcRef = stencilMaterialEnabled ? this.stencilMaterial!.funcRef : this.stencilGlobal.funcRef;\r\n this.funcMask = stencilMaterialEnabled ? this.stencilMaterial!.funcMask : this.stencilGlobal.funcMask;\r\n this.opStencilFail = stencilMaterialEnabled ? this.stencilMaterial!.opStencilFail : this.stencilGlobal.opStencilFail;\r\n this.opDepthFail = stencilMaterialEnabled ? this.stencilMaterial!.opDepthFail : this.stencilGlobal.opDepthFail;\r\n this.opStencilDepthPass = stencilMaterialEnabled ? this.stencilMaterial!.opStencilDepthPass : this.stencilGlobal.opStencilDepthPass;\r\n this.mask = stencilMaterialEnabled ? this.stencilMaterial!.mask : this.stencilGlobal.mask;\r\n\r\n if (!this.isDirty) {\r\n return;\r\n }\r\n\r\n // Stencil test\r\n if (this._isStencilTestDirty) {\r\n if (this.enabled) {\r\n gl.enable(gl.STENCIL_TEST);\r\n } else {\r\n gl.disable(gl.STENCIL_TEST);\r\n }\r\n this._isStencilTestDirty = false;\r\n }\r\n\r\n // Stencil mask\r\n if (this._isStencilMaskDirty) {\r\n gl.stencilMask(this.mask);\r\n this._isStencilMaskDirty = false;\r\n }\r\n\r\n // Stencil func\r\n if (this._isStencilFuncDirty) {\r\n gl.stencilFunc(this.func, this.funcRef, this.funcMask);\r\n this._isStencilFuncDirty = false;\r\n }\r\n\r\n // Stencil op\r\n if (this._isStencilOpDirty) {\r\n gl.stencilOp(this.opStencilFail, this.opDepthFail, this.opStencilDepthPass);\r\n this._isStencilOpDirty = false;\r\n }\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { EngineStore } from \"./engineStore\";\r\nimport type { IInternalTextureLoader } from \"../Materials/Textures/internalTextureLoader\";\r\nimport type { IEffectCreationOptions } from \"../Materials/effect\";\r\nimport { Effect } from \"../Materials/effect\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { IShaderProcessor } from \"./Processors/iShaderProcessor\";\r\nimport type { ShaderProcessingContext } from \"./Processors/shaderProcessingOptions\";\r\nimport type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { Nullable, DataArray, IndicesArray } from \"../types\";\r\nimport type { EngineCapabilities } from \"./engineCapabilities\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { DepthCullingState } from \"../States/depthCullingState\";\r\nimport { StencilState } from \"../States/stencilState\";\r\nimport { AlphaState } from \"../States/alphaCullingState\";\r\nimport { Constants } from \"./constants\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport type { IViewportLike, IColor4Like } from \"../Maths/math.like\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport type { IFileRequest } from \"../Misc/fileRequest\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { IsDocumentAvailable, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { WebGLShaderProcessor } from \"./WebGL/webGLShaderProcessors\";\r\nimport { WebGL2ShaderProcessor } from \"./WebGL/webGL2ShaderProcessors\";\r\nimport { WebGLDataBuffer } from \"../Meshes/WebGL/webGLDataBuffer\";\r\nimport type { IPipelineContext } from \"./IPipelineContext\";\r\nimport { WebGLPipelineContext } from \"./WebGL/webGLPipelineContext\";\r\nimport type { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { InstancingAttributeInfo } from \"./instancingAttributeInfo\";\r\nimport type { ThinTexture } from \"../Materials/Textures/thinTexture\";\r\nimport type { IOfflineProvider } from \"../Offline/IOfflineProvider\";\r\nimport type { IEffectFallbacks } from \"../Materials/iEffectFallbacks\";\r\nimport type { IWebRequest } from \"../Misc/interfaces/iWebRequest\";\r\nimport { PerformanceConfigurator } from \"./performanceConfigurator\";\r\nimport type { EngineFeatures } from \"./engineFeatures\";\r\nimport type { HardwareTextureWrapper } from \"../Materials/Textures/hardwareTextureWrapper\";\r\nimport { WebGLHardwareTexture } from \"./WebGL/webGLHardwareTexture\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport type { IMaterialContext } from \"./IMaterialContext\";\r\nimport type { IDrawContext } from \"./IDrawContext\";\r\nimport type { ICanvas, ICanvasRenderingContext, IImage } from \"./ICanvas\";\r\nimport { StencilStateComposer } from \"../States/stencilStateComposer\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport type { IAudioEngineOptions } from \"../Audio/Interfaces/IAudioEngineOptions\";\r\nimport type { IStencilState } from \"../States/IStencilState\";\r\nimport type { InternalTextureCreationOptions, TextureSize } from \"../Materials/Textures/textureCreationOptions\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\nimport type { RenderTargetWrapper } from \"./renderTargetWrapper\";\r\nimport type { WebGLRenderTargetWrapper } from \"./WebGL/webGLRenderTargetWrapper\";\r\nimport type { VideoTexture } from \"../Materials/Textures/videoTexture\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { WebRequest } from \"../Misc/webRequest\";\r\nimport type { LoadFileError } from \"../Misc/fileTools\";\r\nimport type { Texture } from \"../Materials/Textures/texture\";\r\nimport { PrecisionDate } from \"core/Misc/precisionDate\";\r\n\r\n/**\r\n * Defines the interface used by objects working like Scene\r\n * @internal\r\n */\r\nexport interface ISceneLike {\r\n addPendingData(data: any): void;\r\n removePendingData(data: any): void;\r\n offlineProvider: IOfflineProvider;\r\n}\r\n\r\n/**\r\n * Keeps track of all the buffer info used in engine.\r\n */\r\nclass BufferPointer {\r\n public active: boolean;\r\n public index: number;\r\n public size: number;\r\n public type: number;\r\n public normalized: boolean;\r\n public stride: number;\r\n public offset: number;\r\n public buffer: WebGLBuffer;\r\n}\r\n\r\n/**\r\n * Information about the current host\r\n */\r\nexport interface HostInformation {\r\n /**\r\n * Defines if the current host is a mobile\r\n */\r\n isMobile: boolean;\r\n}\r\n\r\n/** Interface defining initialization parameters for ThinEngine class */\r\nexport interface ThinEngineOptions {\r\n /**\r\n * Defines if the engine should no exceed a specified device ratio\r\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio\r\n */\r\n limitDeviceRatio?: number;\r\n /**\r\n * Defines if webaudio should be initialized as well\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic\r\n */\r\n audioEngine?: boolean;\r\n /**\r\n * Specifies options for the audio engine\r\n */\r\n audioEngineOptions?: IAudioEngineOptions;\r\n\r\n /**\r\n * Defines if animations should run using a deterministic lock step\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n */\r\n deterministicLockstep?: boolean;\r\n /** Defines the maximum steps to use with deterministic lock step mode */\r\n lockstepMaxSteps?: number;\r\n /** Defines the seconds between each deterministic lock step */\r\n timeStep?: number;\r\n /**\r\n * Defines that engine should ignore context lost events\r\n * If this event happens when this parameter is true, you will have to reload the page to restore rendering\r\n */\r\n doNotHandleContextLost?: boolean;\r\n /**\r\n * Defines that engine should ignore modifying touch action attribute and style\r\n * If not handle, you might need to set it up on your side for expected touch devices behavior.\r\n */\r\n doNotHandleTouchAction?: boolean;\r\n\r\n /**\r\n * Make the matrix computations to be performed in 64 bits instead of 32 bits. False by default\r\n */\r\n useHighPrecisionMatrix?: boolean;\r\n\r\n /**\r\n * Defines whether to adapt to the device's viewport characteristics (default: false)\r\n */\r\n adaptToDeviceRatio?: boolean;\r\n\r\n /**\r\n * True if the more expensive but exact conversions should be used for transforming colors to and from linear space within shaders.\r\n * Otherwise, the default is to use a cheaper approximation.\r\n */\r\n useExactSrgbConversions?: boolean;\r\n\r\n /**\r\n * Defines whether MSAA is enabled on the canvas.\r\n */\r\n antialias?: boolean;\r\n\r\n /**\r\n * Defines whether the stencil buffer should be enabled.\r\n */\r\n stencil?: boolean;\r\n\r\n /**\r\n * Defines whether the canvas should be created in \"premultiplied\" mode (if false, the canvas is created in the \"opaque\" mode) (true by default)\r\n */\r\n premultipliedAlpha?: boolean;\r\n}\r\n\r\n/** Interface defining initialization parameters for Engine class */\r\nexport interface EngineOptions extends ThinEngineOptions, WebGLContextAttributes {\r\n /**\r\n * Defines if webvr should be enabled automatically\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRCamera\r\n */\r\n autoEnableWebVR?: boolean;\r\n /**\r\n * Defines if webgl2 should be turned off even if supported\r\n * @see https://doc.babylonjs.com/setup/support/webGL2\r\n */\r\n disableWebGL2Support?: boolean;\r\n\r\n /**\r\n * Defines that engine should compile shaders with high precision floats (if supported). True by default\r\n */\r\n useHighPrecisionFloats?: boolean;\r\n /**\r\n * Make the canvas XR Compatible for XR sessions\r\n */\r\n xrCompatible?: boolean;\r\n\r\n /**\r\n * Will prevent the system from falling back to software implementation if a hardware device cannot be created\r\n */\r\n failIfMajorPerformanceCaveat?: boolean;\r\n\r\n /**\r\n * If sRGB Buffer support is not set during construction, use this value to force a specific state\r\n * This is added due to an issue when processing textures in chrome/edge/firefox\r\n * This will not influence NativeEngine and WebGPUEngine which set the behavior to true during construction.\r\n */\r\n forceSRGBBufferSupportState?: boolean;\r\n}\r\n\r\n/**\r\n * The base engine class (root of all engines)\r\n */\r\nexport class ThinEngine {\r\n private static _TempClearColorUint32 = new Uint32Array(4);\r\n private static _TempClearColorInt32 = new Int32Array(4);\r\n\r\n /** Use this array to turn off some WebGL2 features on known buggy browsers version */\r\n public static ExceptionList = [\r\n { key: \"Chrome/63.0\", capture: \"63\\\\.0\\\\.3239\\\\.(\\\\d+)\", captureConstraint: 108, targets: [\"uniformBuffer\"] },\r\n { key: \"Firefox/58\", capture: null, captureConstraint: null, targets: [\"uniformBuffer\"] },\r\n { key: \"Firefox/59\", capture: null, captureConstraint: null, targets: [\"uniformBuffer\"] },\r\n { key: \"Chrome/72.+?Mobile\", capture: null, captureConstraint: null, targets: [\"vao\"] },\r\n { key: \"Chrome/73.+?Mobile\", capture: null, captureConstraint: null, targets: [\"vao\"] },\r\n { key: \"Chrome/74.+?Mobile\", capture: null, captureConstraint: null, targets: [\"vao\"] },\r\n { key: \"Mac OS.+Chrome/71\", capture: null, captureConstraint: null, targets: [\"vao\"] },\r\n { key: \"Mac OS.+Chrome/72\", capture: null, captureConstraint: null, targets: [\"vao\"] },\r\n { key: \"Mac OS.+Chrome\", capture: null, captureConstraint: null, targets: [\"uniformBuffer\"] },\r\n // desktop osx safari 15.4\r\n { key: \".*AppleWebKit.*(15.4).*Safari\", capture: null, captureConstraint: null, targets: [\"antialias\", \"maxMSAASamples\"] },\r\n // mobile browsers using safari 15.4 on ios\r\n { key: \".*(15.4).*AppleWebKit.*Safari\", capture: null, captureConstraint: null, targets: [\"antialias\", \"maxMSAASamples\"] },\r\n ];\r\n\r\n /** @internal */\r\n public static _TextureLoaders: IInternalTextureLoader[] = [];\r\n\r\n /**\r\n * Returns the current npm package of the sdk\r\n */\r\n // Not mixed with Version for tooling purpose.\r\n public static get NpmPackage(): string {\r\n return \"babylonjs@6.15.0\";\r\n }\r\n\r\n /**\r\n * Returns the current version of the framework\r\n */\r\n public static get Version(): string {\r\n return \"6.15.0\";\r\n }\r\n\r\n /**\r\n * Returns a string describing the current engine\r\n */\r\n public get description(): string {\r\n let description = this.name + this.webGLVersion;\r\n\r\n if (this._caps.parallelShaderCompile) {\r\n description += \" - Parallel shader compilation\";\r\n }\r\n\r\n return description;\r\n }\r\n\r\n /** @internal */\r\n protected _name = \"WebGL\";\r\n\r\n /**\r\n * Gets or sets the name of the engine\r\n */\r\n public get name(): string {\r\n return this._name;\r\n }\r\n\r\n public set name(value: string) {\r\n this._name = value;\r\n }\r\n\r\n /**\r\n * Returns the version of the engine\r\n */\r\n public get version(): number {\r\n return this._webGLVersion;\r\n }\r\n\r\n protected _isDisposed = false;\r\n\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n // Updatable statics so stick with vars here\r\n\r\n /**\r\n * Gets or sets the epsilon value used by collision engine\r\n */\r\n public static CollisionsEpsilon = 0.001;\r\n\r\n /**\r\n * Gets or sets the relative url used to load shaders if using the engine in non-minified mode\r\n */\r\n public static get ShadersRepository(): string {\r\n return Effect.ShadersRepository;\r\n }\r\n public static set ShadersRepository(value: string) {\r\n Effect.ShadersRepository = value;\r\n }\r\n\r\n protected _shaderProcessor: Nullable;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getShaderProcessor(shaderLanguage: ShaderLanguage): Nullable {\r\n return this._shaderProcessor;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean that indicates if textures must be forced to power of 2 size even if not required\r\n */\r\n public forcePOTTextures = false;\r\n\r\n /**\r\n * Gets a boolean indicating if the engine is currently rendering in fullscreen mode\r\n */\r\n public isFullscreen = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if back faces must be culled. If false, front faces are culled instead (true by default)\r\n * If non null, this takes precedence over the value from the material\r\n */\r\n public cullBackFaces: Nullable = null;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the engine must keep rendering even if the window is not in foreground\r\n */\r\n public renderEvenInBackground = true;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that cache can be kept between frames\r\n */\r\n public preventCacheWipeBetweenFrames = false;\r\n\r\n /** Gets or sets a boolean indicating if the engine should validate programs after compilation */\r\n public validateShaderPrograms = false;\r\n\r\n private _useReverseDepthBuffer = false;\r\n /**\r\n * Gets or sets a boolean indicating if depth buffer should be reverse, going from far to near.\r\n * This can provide greater z depth for distant objects.\r\n */\r\n public get useReverseDepthBuffer(): boolean {\r\n return this._useReverseDepthBuffer;\r\n }\r\n\r\n public set useReverseDepthBuffer(useReverse) {\r\n if (useReverse === this._useReverseDepthBuffer) {\r\n return;\r\n }\r\n\r\n this._useReverseDepthBuffer = useReverse;\r\n\r\n if (useReverse) {\r\n this._depthCullingState.depthFunc = Constants.GEQUAL;\r\n } else {\r\n this._depthCullingState.depthFunc = Constants.LEQUAL;\r\n }\r\n }\r\n\r\n /**\r\n * Indicates if the z range in NDC space is 0..1 (value: true) or -1..1 (value: false)\r\n */\r\n public readonly isNDCHalfZRange: boolean = false;\r\n\r\n /**\r\n * Indicates that the origin of the texture/framebuffer space is the bottom left corner. If false, the origin is top left\r\n */\r\n public readonly hasOriginBottomLeft: boolean = true;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that uniform buffers must be disabled even if they are supported\r\n */\r\n public disableUniformBuffers = false;\r\n\r\n /**\r\n * An event triggered when the engine is disposed.\r\n */\r\n public readonly onDisposeObservable = new Observable();\r\n\r\n private _frameId = 0;\r\n /**\r\n * Gets the current frame id\r\n */\r\n public get frameId(): number {\r\n return this._frameId;\r\n }\r\n\r\n /**\r\n * The time (in milliseconds elapsed since the current page has been loaded) when the engine was initialized\r\n */\r\n public readonly startTime: number;\r\n\r\n /** @internal */\r\n public _uniformBuffers = new Array();\r\n /** @internal */\r\n public _storageBuffers = new Array();\r\n\r\n /**\r\n * Gets a boolean indicating that the engine supports uniform buffers\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets\r\n */\r\n public get supportsUniformBuffers(): boolean {\r\n return this.webGLVersion > 1 && !this.disableUniformBuffers;\r\n }\r\n\r\n // Private Members\r\n\r\n /** @internal */\r\n public _gl: WebGL2RenderingContext;\r\n /** @internal */\r\n public _webGLVersion = 1.0;\r\n protected _renderingCanvas: Nullable;\r\n protected _windowIsBackground = false;\r\n protected _creationOptions: EngineOptions;\r\n protected _audioContext: Nullable;\r\n protected _audioDestination: Nullable;\r\n /** @internal */\r\n public _glSRGBExtensionValues: {\r\n SRGB: typeof WebGL2RenderingContext.SRGB;\r\n SRGB8: typeof WebGL2RenderingContext.SRGB8 | EXT_sRGB[\"SRGB_ALPHA_EXT\"];\r\n SRGB8_ALPHA8: typeof WebGL2RenderingContext.SRGB8_ALPHA8 | EXT_sRGB[\"SRGB_ALPHA_EXT\"];\r\n };\r\n /**\r\n * Gets the options used for engine creation\r\n * @returns EngineOptions object\r\n */\r\n public getCreationOptions() {\r\n return this._creationOptions;\r\n }\r\n\r\n protected _highPrecisionShadersAllowed = true;\r\n /** @internal */\r\n public get _shouldUseHighPrecisionShader(): boolean {\r\n return !!(this._caps.highPrecisionShaderSupported && this._highPrecisionShadersAllowed);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that only power of 2 textures are supported\r\n * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them\r\n */\r\n public get needPOTTextures(): boolean {\r\n return this._webGLVersion < 2 || this.forcePOTTextures;\r\n }\r\n\r\n /** @internal */\r\n public _badOS = false;\r\n\r\n /** @internal */\r\n public _badDesktopOS = false;\r\n\r\n /** @internal */\r\n public _hardwareScalingLevel: number;\r\n /** @internal */\r\n public _caps: EngineCapabilities;\r\n /** @internal */\r\n public _features: EngineFeatures;\r\n protected _isStencilEnable: boolean;\r\n\r\n private _glVersion: string;\r\n private _glRenderer: string;\r\n private _glVendor: string;\r\n\r\n /** @internal */\r\n public _videoTextureSupported: boolean;\r\n\r\n protected _renderingQueueLaunched = false;\r\n protected _activeRenderLoops = new Array<() => void>();\r\n\r\n /**\r\n * Gets the list of current active render loop functions\r\n * @returns an array with the current render loop functions\r\n */\r\n public get activeRenderLoops(): Array<() => void> {\r\n return this._activeRenderLoops;\r\n }\r\n\r\n // Lost context\r\n /**\r\n * Observable signaled when a context lost event is raised\r\n */\r\n public onContextLostObservable = new Observable();\r\n /**\r\n * Observable signaled when a context restored event is raised\r\n */\r\n public onContextRestoredObservable = new Observable();\r\n private _onContextLost: (evt: Event) => void;\r\n private _onContextRestored: (evt: Event) => void;\r\n protected _contextWasLost = false;\r\n\r\n /** @internal */\r\n public _doNotHandleContextLost = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if resources should be retained to be able to handle context lost events\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#handling-webgl-context-lost\r\n */\r\n public get doNotHandleContextLost(): boolean {\r\n return this._doNotHandleContextLost;\r\n }\r\n\r\n public set doNotHandleContextLost(value: boolean) {\r\n this._doNotHandleContextLost = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that vertex array object must be disabled even if they are supported\r\n */\r\n public disableVertexArrayObjects = false;\r\n\r\n // States\r\n /** @internal */\r\n protected _colorWrite = true;\r\n /** @internal */\r\n protected _colorWriteChanged = true;\r\n /** @internal */\r\n protected _depthCullingState = new DepthCullingState();\r\n /** @internal */\r\n protected _stencilStateComposer = new StencilStateComposer();\r\n /** @internal */\r\n protected _stencilState = new StencilState();\r\n /** @internal */\r\n public _alphaState = new AlphaState();\r\n /** @internal */\r\n public _alphaMode = Constants.ALPHA_ADD;\r\n /** @internal */\r\n public _alphaEquation = Constants.ALPHA_DISABLE;\r\n\r\n // Cache\r\n /** @internal */\r\n public _internalTexturesCache = new Array();\r\n /** @internal */\r\n public _renderTargetWrapperCache = new Array();\r\n /** @internal */\r\n protected _activeChannel = 0;\r\n private _currentTextureChannel = -1;\r\n /** @internal */\r\n protected _boundTexturesCache: { [key: string]: Nullable } = {};\r\n protected _currentEffect: Nullable;\r\n /** @internal */\r\n public _currentDrawContext: IDrawContext;\r\n /** @internal */\r\n public _currentMaterialContext: IMaterialContext;\r\n /** @internal */\r\n protected _currentProgram: Nullable;\r\n protected _compiledEffects: { [key: string]: Effect } = {};\r\n private _vertexAttribArraysEnabled: boolean[] = [];\r\n /** @internal */\r\n protected _cachedViewport: Nullable;\r\n private _cachedVertexArrayObject: Nullable;\r\n /** @internal */\r\n protected _cachedVertexBuffers: any;\r\n /** @internal */\r\n protected _cachedIndexBuffer: Nullable;\r\n /** @internal */\r\n protected _cachedEffectForVertexBuffers: Nullable;\r\n\r\n /** @internal */\r\n public _currentRenderTarget: Nullable;\r\n private _uintIndicesCurrentlySet = false;\r\n protected _currentBoundBuffer = new Array>();\r\n /** @internal */\r\n public _currentFramebuffer: Nullable = null;\r\n /** @internal */\r\n public _dummyFramebuffer: Nullable = null;\r\n private _currentBufferPointers = new Array();\r\n private _currentInstanceLocations = new Array();\r\n private _currentInstanceBuffers = new Array();\r\n private _textureUnits: Int32Array;\r\n\r\n /** @internal */\r\n public _workingCanvas: Nullable;\r\n /** @internal */\r\n public _workingContext: Nullable;\r\n\r\n /** @internal */\r\n public _boundRenderFunction: any;\r\n\r\n private _vaoRecordInProgress = false;\r\n private _mustWipeVertexAttributes = false;\r\n\r\n private _emptyTexture: Nullable;\r\n private _emptyCubeTexture: Nullable;\r\n private _emptyTexture3D: Nullable;\r\n private _emptyTexture2DArray: Nullable;\r\n\r\n /** @internal */\r\n public _frameHandler: number;\r\n\r\n private _nextFreeTextureSlots = new Array();\r\n private _maxSimultaneousTextures = 0;\r\n private _maxMSAASamplesOverride: Nullable = null;\r\n\r\n private _activeRequests = new Array();\r\n\r\n /**\r\n * If set to true zooming in and out in the browser will rescale the hardware-scaling correctly.\r\n */\r\n public adaptToDeviceRatio: boolean = false;\r\n /** @internal */\r\n protected _lastDevicePixelRatio: number = 1.0;\r\n\r\n /** @internal */\r\n public _transformTextureUrl: Nullable<(url: string) => string> = null;\r\n\r\n /**\r\n * Gets information about the current host\r\n */\r\n public hostInformation: HostInformation = {\r\n isMobile: false,\r\n };\r\n\r\n protected get _supportsHardwareTextureRescaling() {\r\n return false;\r\n }\r\n\r\n private _framebufferDimensionsObject: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n\r\n /**\r\n * sets the object from which width and height will be taken from when getting render width and height\r\n * Will fallback to the gl object\r\n * @param dimensions the framebuffer width and height that will be used.\r\n */\r\n public set framebufferDimensionsObject(dimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>) {\r\n this._framebufferDimensionsObject = dimensions;\r\n }\r\n\r\n /**\r\n * Gets the current viewport\r\n */\r\n public get currentViewport(): Nullable {\r\n return this._cachedViewport;\r\n }\r\n\r\n /**\r\n * Gets the default empty texture\r\n */\r\n public get emptyTexture(): InternalTexture {\r\n if (!this._emptyTexture) {\r\n this._emptyTexture = this.createRawTexture(new Uint8Array(4), 1, 1, Constants.TEXTUREFORMAT_RGBA, false, false, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n }\r\n\r\n return this._emptyTexture;\r\n }\r\n\r\n /**\r\n * Gets the default empty 3D texture\r\n */\r\n public get emptyTexture3D(): InternalTexture {\r\n if (!this._emptyTexture3D) {\r\n this._emptyTexture3D = this.createRawTexture3D(new Uint8Array(4), 1, 1, 1, Constants.TEXTUREFORMAT_RGBA, false, false, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n }\r\n\r\n return this._emptyTexture3D;\r\n }\r\n\r\n /**\r\n * Gets the default empty 2D array texture\r\n */\r\n public get emptyTexture2DArray(): InternalTexture {\r\n if (!this._emptyTexture2DArray) {\r\n this._emptyTexture2DArray = this.createRawTexture2DArray(\r\n new Uint8Array(4),\r\n 1,\r\n 1,\r\n 1,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n false,\r\n false,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE\r\n );\r\n }\r\n\r\n return this._emptyTexture2DArray;\r\n }\r\n\r\n /**\r\n * Gets the default empty cube texture\r\n */\r\n public get emptyCubeTexture(): InternalTexture {\r\n if (!this._emptyCubeTexture) {\r\n const faceData = new Uint8Array(4);\r\n const cubeData = [faceData, faceData, faceData, faceData, faceData, faceData];\r\n this._emptyCubeTexture = this.createRawCubeTexture(\r\n cubeData,\r\n 1,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n Constants.TEXTURETYPE_UNSIGNED_INT,\r\n false,\r\n false,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE\r\n );\r\n }\r\n\r\n return this._emptyCubeTexture;\r\n }\r\n\r\n /**\r\n * Defines whether the engine has been created with the premultipliedAlpha option on or not.\r\n */\r\n public premultipliedAlpha: boolean = true;\r\n\r\n /**\r\n * Observable event triggered before each texture is initialized\r\n */\r\n public onBeforeTextureInitObservable = new Observable();\r\n\r\n /** @internal */\r\n protected _isWebGPU: boolean = false;\r\n /**\r\n * Gets a boolean indicating if the engine runs in WebGPU or not.\r\n */\r\n public get isWebGPU(): boolean {\r\n return this._isWebGPU;\r\n }\r\n\r\n /** @internal */\r\n protected _shaderPlatformName: string;\r\n /**\r\n * Gets the shader platform name used by the effects.\r\n */\r\n public get shaderPlatformName(): string {\r\n return this._shaderPlatformName;\r\n }\r\n\r\n /**\r\n * Enables or disables the snapshot rendering mode\r\n * Note that the WebGL engine does not support snapshot rendering so setting the value won't have any effect for this engine\r\n */\r\n public get snapshotRendering(): boolean {\r\n return false;\r\n }\r\n\r\n public set snapshotRendering(activate) {\r\n // WebGL engine does not support snapshot rendering\r\n }\r\n\r\n protected _snapshotRenderingMode = Constants.SNAPSHOTRENDERING_STANDARD;\r\n /**\r\n * Gets or sets the snapshot rendering mode\r\n */\r\n public get snapshotRenderingMode(): number {\r\n return this._snapshotRenderingMode;\r\n }\r\n\r\n public set snapshotRenderingMode(mode: number) {\r\n this._snapshotRenderingMode = mode;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the exact sRGB conversions or faster approximations are used for converting to and from linear space.\r\n */\r\n public readonly useExactSrgbConversions: boolean;\r\n\r\n /**\r\n * Creates a new snapshot at the next frame using the current snapshotRenderingMode\r\n */\r\n public snapshotRenderingReset(): void {\r\n this.snapshotRendering = false;\r\n }\r\n\r\n private _checkForMobile: () => void;\r\n\r\n private static _CreateCanvas(width: number, height: number): ICanvas {\r\n if (typeof document === \"undefined\") {\r\n return (new OffscreenCanvas(width, height));\r\n }\r\n const canvas = (document.createElement(\"canvas\"));\r\n canvas.width = width;\r\n canvas.height = height;\r\n return canvas;\r\n }\r\n\r\n /**\r\n * Create a canvas. This method is overridden by other engines\r\n * @param width width\r\n * @param height height\r\n * @returns ICanvas interface\r\n */\r\n public createCanvas(width: number, height: number): ICanvas {\r\n return ThinEngine._CreateCanvas(width, height);\r\n }\r\n\r\n /**\r\n * Create an image to use with canvas\r\n * @returns IImage interface\r\n */\r\n public createCanvasImage(): IImage {\r\n return document.createElement(\"img\");\r\n }\r\n\r\n /**\r\n * Creates a new engine\r\n * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context\r\n * @param antialias defines enable antialiasing (default: false)\r\n * @param options defines further options to be sent to the getContext() function\r\n * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)\r\n */\r\n constructor(\r\n canvasOrContext: Nullable,\r\n antialias?: boolean,\r\n options?: EngineOptions,\r\n adaptToDeviceRatio?: boolean\r\n ) {\r\n this.startTime = PrecisionDate.Now;\r\n\r\n let canvas: Nullable = null;\r\n\r\n options = options || {};\r\n\r\n this._creationOptions = options;\r\n\r\n // Save this off for use in resize().\r\n this.adaptToDeviceRatio = adaptToDeviceRatio ?? false;\r\n\r\n this._stencilStateComposer.stencilGlobal = this._stencilState;\r\n\r\n PerformanceConfigurator.SetMatrixPrecision(!!options.useHighPrecisionMatrix);\r\n\r\n options.antialias = antialias ?? options.antialias;\r\n options.deterministicLockstep = options.deterministicLockstep ?? false;\r\n options.lockstepMaxSteps = options.lockstepMaxSteps ?? 4;\r\n options.timeStep = options.timeStep ?? 1 / 60;\r\n options.audioEngine = options.audioEngine ?? true;\r\n options.stencil = options.stencil ?? true;\r\n\r\n this._audioContext = options.audioEngineOptions?.audioContext ?? null;\r\n this._audioDestination = options.audioEngineOptions?.audioDestination ?? null;\r\n this.premultipliedAlpha = options.premultipliedAlpha ?? true;\r\n this.useExactSrgbConversions = options.useExactSrgbConversions ?? false;\r\n this._doNotHandleContextLost = !!options.doNotHandleContextLost;\r\n this._isStencilEnable = options.stencil ? true : false;\r\n\r\n // Viewport\r\n adaptToDeviceRatio = adaptToDeviceRatio || options.adaptToDeviceRatio || false;\r\n\r\n const devicePixelRatio = IsWindowObjectExist() ? window.devicePixelRatio || 1.0 : 1.0;\r\n\r\n const limitDeviceRatio = options.limitDeviceRatio || devicePixelRatio;\r\n this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, devicePixelRatio) : 1.0;\r\n this._lastDevicePixelRatio = devicePixelRatio;\r\n\r\n if (!canvasOrContext) {\r\n return;\r\n }\r\n\r\n if ((canvasOrContext as any).getContext) {\r\n canvas = canvasOrContext;\r\n this._renderingCanvas = canvas;\r\n\r\n if (options.preserveDrawingBuffer === undefined) {\r\n options.preserveDrawingBuffer = false;\r\n }\r\n\r\n if (options.xrCompatible === undefined) {\r\n options.xrCompatible = true;\r\n }\r\n\r\n // Exceptions\r\n if (navigator && navigator.userAgent) {\r\n this._setupMobileChecks();\r\n\r\n const ua = navigator.userAgent;\r\n for (const exception of ThinEngine.ExceptionList) {\r\n const key = exception.key;\r\n const targets = exception.targets;\r\n const check = new RegExp(key);\r\n\r\n if (check.test(ua)) {\r\n if (exception.capture && exception.captureConstraint) {\r\n const capture = exception.capture;\r\n const constraint = exception.captureConstraint;\r\n\r\n const regex = new RegExp(capture);\r\n const matches = regex.exec(ua);\r\n\r\n if (matches && matches.length > 0) {\r\n const capturedValue = parseInt(matches[matches.length - 1]);\r\n if (capturedValue >= constraint) {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n for (const target of targets) {\r\n switch (target) {\r\n case \"uniformBuffer\":\r\n this.disableUniformBuffers = true;\r\n break;\r\n case \"vao\":\r\n this.disableVertexArrayObjects = true;\r\n break;\r\n case \"antialias\":\r\n options.antialias = false;\r\n break;\r\n case \"maxMSAASamples\":\r\n this._maxMSAASamplesOverride = 1;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Context lost\r\n if (!this._doNotHandleContextLost) {\r\n this._onContextLost = (evt: Event) => {\r\n evt.preventDefault();\r\n this._contextWasLost = true;\r\n Logger.Warn(\"WebGL context lost.\");\r\n\r\n this.onContextLostObservable.notifyObservers(this);\r\n };\r\n\r\n this._onContextRestored = () => {\r\n this._restoreEngineAfterContextLost(this._initGLContext.bind(this));\r\n };\r\n\r\n canvas.addEventListener(\"webglcontextlost\", this._onContextLost, false);\r\n canvas.addEventListener(\"webglcontextrestored\", this._onContextRestored, false);\r\n\r\n options.powerPreference = options.powerPreference || \"high-performance\";\r\n }\r\n\r\n // Detect if we are running on a faulty buggy desktop OS.\r\n this._badDesktopOS = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\r\n if (this._badDesktopOS) {\r\n options.xrCompatible = false;\r\n }\r\n\r\n // GL\r\n if (!options.disableWebGL2Support) {\r\n try {\r\n this._gl = (canvas.getContext(\"webgl2\", options) || canvas.getContext(\"experimental-webgl2\", options));\r\n if (this._gl) {\r\n this._webGLVersion = 2.0;\r\n this._shaderPlatformName = \"WEBGL2\";\r\n\r\n // Prevent weird browsers to lie (yeah that happens!)\r\n if (!this._gl.deleteQuery) {\r\n this._webGLVersion = 1.0;\r\n this._shaderPlatformName = \"WEBGL1\";\r\n }\r\n }\r\n } catch (e) {\r\n // Do nothing\r\n }\r\n }\r\n\r\n if (!this._gl) {\r\n if (!canvas) {\r\n throw new Error(\"The provided canvas is null or undefined.\");\r\n }\r\n try {\r\n this._gl = (canvas.getContext(\"webgl\", options) || canvas.getContext(\"experimental-webgl\", options));\r\n } catch (e) {\r\n throw new Error(\"WebGL not supported\");\r\n }\r\n }\r\n\r\n if (!this._gl) {\r\n throw new Error(\"WebGL not supported\");\r\n }\r\n } else {\r\n this._gl = canvasOrContext;\r\n this._renderingCanvas = this._gl.canvas as HTMLCanvasElement;\r\n\r\n if ((this._gl as any).renderbufferStorageMultisample) {\r\n this._webGLVersion = 2.0;\r\n this._shaderPlatformName = \"WEBGL2\";\r\n } else {\r\n this._shaderPlatformName = \"WEBGL1\";\r\n }\r\n\r\n const attributes = this._gl.getContextAttributes();\r\n if (attributes) {\r\n options.stencil = attributes.stencil;\r\n }\r\n }\r\n\r\n // Ensures a consistent color space unpacking of textures cross browser.\r\n this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);\r\n\r\n if (options.useHighPrecisionFloats !== undefined) {\r\n this._highPrecisionShadersAllowed = options.useHighPrecisionFloats;\r\n }\r\n\r\n this.resize();\r\n\r\n this._initGLContext();\r\n this._initFeatures();\r\n\r\n // Prepare buffer pointers\r\n for (let i = 0; i < this._caps.maxVertexAttribs; i++) {\r\n this._currentBufferPointers[i] = new BufferPointer();\r\n }\r\n\r\n // Shader processor\r\n this._shaderProcessor = this.webGLVersion > 1 ? new WebGL2ShaderProcessor() : new WebGLShaderProcessor();\r\n\r\n // Detect if we are running on a faulty buggy OS.\r\n this._badOS = /iPad/i.test(navigator.userAgent) || /iPhone/i.test(navigator.userAgent);\r\n\r\n // Starting with iOS 14, we can trust the browser\r\n // let matches = navigator.userAgent.match(/Version\\/(\\d+)/);\r\n\r\n // if (matches && matches.length === 2) {\r\n // if (parseInt(matches[1]) >= 14) {\r\n // this._badOS = false;\r\n // }\r\n // }\r\n\r\n const versionToLog = `Babylon.js v${ThinEngine.Version}`;\r\n console.log(versionToLog + ` - ${this.description}`);\r\n\r\n // Check setAttribute in case of workers\r\n if (this._renderingCanvas && this._renderingCanvas.setAttribute) {\r\n this._renderingCanvas.setAttribute(\"data-engine\", versionToLog);\r\n }\r\n }\r\n\r\n protected _setupMobileChecks(): void {\r\n if (!(navigator && navigator.userAgent)) {\r\n return;\r\n }\r\n\r\n // Function to check if running on mobile device\r\n this._checkForMobile = () => {\r\n const currentUA = navigator.userAgent;\r\n this.hostInformation.isMobile =\r\n currentUA.indexOf(\"Mobile\") !== -1 ||\r\n // Needed for iOS 13+ detection on iPad (inspired by solution from https://stackoverflow.com/questions/9038625/detect-if-device-is-ios)\r\n (currentUA.indexOf(\"Mac\") !== -1 && IsDocumentAvailable() && \"ontouchend\" in document);\r\n };\r\n\r\n // Set initial isMobile value\r\n this._checkForMobile();\r\n\r\n // Set up event listener to check when window is resized (used to get emulator activation to work properly)\r\n if (IsWindowObjectExist()) {\r\n window.addEventListener(\"resize\", this._checkForMobile);\r\n }\r\n }\r\n\r\n protected _restoreEngineAfterContextLost(initEngine: () => void): void {\r\n // Adding a timeout to avoid race condition at browser level\r\n setTimeout(async () => {\r\n this._dummyFramebuffer = null;\r\n\r\n const depthTest = this._depthCullingState.depthTest; // backup those values because the call to initEngine / wipeCaches will reset them\r\n const depthFunc = this._depthCullingState.depthFunc;\r\n const depthMask = this._depthCullingState.depthMask;\r\n const stencilTest = this._stencilState.stencilTest;\r\n\r\n // Rebuild context\r\n await initEngine();\r\n\r\n // Ensure webgl and engine states are matching\r\n this.wipeCaches(true);\r\n\r\n // Rebuild effects\r\n this._rebuildEffects();\r\n this._rebuildComputeEffects?.();\r\n\r\n // Note:\r\n // The call to _rebuildBuffers must be made before the call to _rebuildInternalTextures because in the process of _rebuildBuffers the buffers used by the post process managers will be rebuilt\r\n // and we may need to use the post process manager of the scene during _rebuildInternalTextures (in WebGL1, non-POT textures are rescaled using a post process + post process manager of the scene)\r\n\r\n // Rebuild buffers\r\n this._rebuildBuffers();\r\n // Rebuild textures\r\n this._rebuildInternalTextures();\r\n // Rebuild textures\r\n this._rebuildRenderTargetWrappers();\r\n\r\n // Reset engine states after all the buffer/textures/... have been rebuilt\r\n this.wipeCaches(true);\r\n\r\n this._depthCullingState.depthTest = depthTest;\r\n this._depthCullingState.depthFunc = depthFunc;\r\n this._depthCullingState.depthMask = depthMask;\r\n this._stencilState.stencilTest = stencilTest;\r\n\r\n Logger.Warn(this.name + \" context successfully restored.\");\r\n this.onContextRestoredObservable.notifyObservers(this);\r\n this._contextWasLost = false;\r\n }, 0);\r\n }\r\n\r\n /**\r\n * Shared initialization across engines types.\r\n * @param canvas The canvas associated with this instance of the engine.\r\n */\r\n protected _sharedInit(canvas: HTMLCanvasElement) {\r\n this._renderingCanvas = canvas;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getShaderProcessingContext(shaderLanguage: ShaderLanguage): Nullable {\r\n return null;\r\n }\r\n\r\n private _rebuildInternalTextures(): void {\r\n const currentState = this._internalTexturesCache.slice(); // Do a copy because the rebuild will add proxies\r\n\r\n for (const internalTexture of currentState) {\r\n internalTexture._rebuild();\r\n }\r\n }\r\n\r\n private _rebuildRenderTargetWrappers(): void {\r\n const currentState = this._renderTargetWrapperCache.slice(); // Do a copy because the rebuild will add proxies\r\n\r\n for (const renderTargetWrapper of currentState) {\r\n renderTargetWrapper._rebuild();\r\n }\r\n }\r\n\r\n private _rebuildEffects(): void {\r\n for (const key in this._compiledEffects) {\r\n const effect = this._compiledEffects[key];\r\n\r\n effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\r\n effect._wasPreviouslyReady = false;\r\n effect._prepareEffect();\r\n }\r\n\r\n Effect.ResetCache();\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if all created effects are ready\r\n * @returns true if all effects are ready\r\n */\r\n public areAllEffectsReady(): boolean {\r\n for (const key in this._compiledEffects) {\r\n const effect = this._compiledEffects[key];\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n protected _rebuildBuffers(): void {\r\n // Uniforms\r\n for (const uniformBuffer of this._uniformBuffers) {\r\n uniformBuffer._rebuild();\r\n }\r\n // Storage buffers\r\n for (const storageBuffer of this._storageBuffers) {\r\n storageBuffer._rebuild();\r\n }\r\n }\r\n\r\n protected _initGLContext(): void {\r\n // Caps\r\n this._caps = {\r\n maxTexturesImageUnits: this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),\r\n maxCombinedTexturesImageUnits: this._gl.getParameter(this._gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),\r\n maxVertexTextureImageUnits: this._gl.getParameter(this._gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),\r\n maxTextureSize: this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),\r\n maxSamples: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_SAMPLES) : 1,\r\n maxCubemapTextureSize: this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),\r\n maxRenderTextureSize: this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),\r\n maxVertexAttribs: this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS),\r\n maxVaryingVectors: this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),\r\n maxFragmentUniformVectors: this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),\r\n maxVertexUniformVectors: this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),\r\n parallelShaderCompile: this._gl.getExtension(\"KHR_parallel_shader_compile\") || undefined,\r\n standardDerivatives: this._webGLVersion > 1 || this._gl.getExtension(\"OES_standard_derivatives\") !== null,\r\n maxAnisotropy: 1,\r\n astc: this._gl.getExtension(\"WEBGL_compressed_texture_astc\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_astc\"),\r\n bptc: this._gl.getExtension(\"EXT_texture_compression_bptc\") || this._gl.getExtension(\"WEBKIT_EXT_texture_compression_bptc\"),\r\n s3tc: this._gl.getExtension(\"WEBGL_compressed_texture_s3tc\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_s3tc\"),\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n s3tc_srgb: this._gl.getExtension(\"WEBGL_compressed_texture_s3tc_srgb\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_s3tc_srgb\"),\r\n pvrtc: this._gl.getExtension(\"WEBGL_compressed_texture_pvrtc\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_pvrtc\"),\r\n etc1: this._gl.getExtension(\"WEBGL_compressed_texture_etc1\") || this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_etc1\"),\r\n etc2:\r\n this._gl.getExtension(\"WEBGL_compressed_texture_etc\") ||\r\n this._gl.getExtension(\"WEBKIT_WEBGL_compressed_texture_etc\") ||\r\n this._gl.getExtension(\"WEBGL_compressed_texture_es3_0\"), // also a requirement of OpenGL ES 3\r\n textureAnisotropicFilterExtension:\r\n this._gl.getExtension(\"EXT_texture_filter_anisotropic\") ||\r\n this._gl.getExtension(\"WEBKIT_EXT_texture_filter_anisotropic\") ||\r\n this._gl.getExtension(\"MOZ_EXT_texture_filter_anisotropic\"),\r\n uintIndices: this._webGLVersion > 1 || this._gl.getExtension(\"OES_element_index_uint\") !== null,\r\n fragmentDepthSupported: this._webGLVersion > 1 || this._gl.getExtension(\"EXT_frag_depth\") !== null,\r\n highPrecisionShaderSupported: false,\r\n timerQuery: this._gl.getExtension(\"EXT_disjoint_timer_query_webgl2\") || this._gl.getExtension(\"EXT_disjoint_timer_query\"),\r\n supportOcclusionQuery: this._webGLVersion > 1,\r\n canUseTimestampForTimerQuery: false,\r\n drawBuffersExtension: false,\r\n maxMSAASamples: 1,\r\n colorBufferFloat: !!(this._webGLVersion > 1 && this._gl.getExtension(\"EXT_color_buffer_float\")),\r\n colorBufferHalfFloat: !!(this._webGLVersion > 1 && this._gl.getExtension(\"EXT_color_buffer_half_float\")),\r\n textureFloat: this._webGLVersion > 1 || this._gl.getExtension(\"OES_texture_float\") ? true : false,\r\n textureHalfFloat: this._webGLVersion > 1 || this._gl.getExtension(\"OES_texture_half_float\") ? true : false,\r\n textureHalfFloatRender: false,\r\n textureFloatLinearFiltering: false,\r\n textureFloatRender: false,\r\n textureHalfFloatLinearFiltering: false,\r\n vertexArrayObject: false,\r\n instancedArrays: false,\r\n textureLOD: this._webGLVersion > 1 || this._gl.getExtension(\"EXT_shader_texture_lod\") ? true : false,\r\n texelFetch: this._webGLVersion !== 1,\r\n blendMinMax: false,\r\n multiview: this._gl.getExtension(\"OVR_multiview2\"),\r\n oculusMultiview: this._gl.getExtension(\"OCULUS_multiview\"),\r\n depthTextureExtension: false,\r\n canUseGLInstanceID: this._webGLVersion > 1,\r\n canUseGLVertexID: this._webGLVersion > 1,\r\n supportComputeShaders: false,\r\n supportSRGBBuffers: false,\r\n supportTransformFeedbacks: this._webGLVersion > 1,\r\n textureMaxLevel: this._webGLVersion > 1,\r\n texture2DArrayMaxLayerCount: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_ARRAY_TEXTURE_LAYERS) : 128,\r\n disableMorphTargetTexture: false,\r\n };\r\n\r\n // Infos\r\n this._glVersion = this._gl.getParameter(this._gl.VERSION);\r\n\r\n const rendererInfo: any = this._gl.getExtension(\"WEBGL_debug_renderer_info\");\r\n if (rendererInfo != null) {\r\n this._glRenderer = this._gl.getParameter(rendererInfo.UNMASKED_RENDERER_WEBGL);\r\n this._glVendor = this._gl.getParameter(rendererInfo.UNMASKED_VENDOR_WEBGL);\r\n }\r\n\r\n if (!this._glVendor) {\r\n this._glVendor = this._gl.getParameter(this._gl.VENDOR) || \"Unknown vendor\";\r\n }\r\n\r\n if (!this._glRenderer) {\r\n this._glRenderer = this._gl.getParameter(this._gl.RENDERER) || \"Unknown renderer\";\r\n }\r\n\r\n // Constants\r\n if (this._gl.HALF_FLOAT_OES !== 0x8d61) {\r\n this._gl.HALF_FLOAT_OES = 0x8d61; // Half floating-point type (16-bit).\r\n }\r\n if (this._gl.RGBA16F !== 0x881a) {\r\n this._gl.RGBA16F = 0x881a; // RGBA 16-bit floating-point color-renderable internal sized format.\r\n }\r\n if (this._gl.RGBA32F !== 0x8814) {\r\n this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.\r\n }\r\n if (this._gl.DEPTH24_STENCIL8 !== 35056) {\r\n this._gl.DEPTH24_STENCIL8 = 35056;\r\n }\r\n\r\n // Extensions\r\n if (this._caps.timerQuery) {\r\n if (this._webGLVersion === 1) {\r\n this._gl.getQuery = (this._caps.timerQuery).getQueryEXT.bind(this._caps.timerQuery);\r\n }\r\n // WebGLQuery casted to number to avoid TS error\r\n this._caps.canUseTimestampForTimerQuery = ((this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT, this._caps.timerQuery.QUERY_COUNTER_BITS_EXT) as number) ?? 0) > 0;\r\n }\r\n\r\n this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension\r\n ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT)\r\n : 0;\r\n this._caps.textureFloatLinearFiltering = this._caps.textureFloat && this._gl.getExtension(\"OES_texture_float_linear\") ? true : false;\r\n this._caps.textureFloatRender = this._caps.textureFloat && this._canRenderToFloatFramebuffer() ? true : false;\r\n this._caps.textureHalfFloatLinearFiltering =\r\n this._webGLVersion > 1 || (this._caps.textureHalfFloat && this._gl.getExtension(\"OES_texture_half_float_linear\")) ? true : false;\r\n\r\n // Compressed formats\r\n if (this._caps.astc) {\r\n this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;\r\n }\r\n if (this._caps.bptc) {\r\n this._gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = this._caps.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;\r\n }\r\n if (this._caps.s3tc_srgb) {\r\n this._gl.COMPRESSED_SRGB_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_S3TC_DXT1_EXT;\r\n this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;\r\n this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;\r\n }\r\n if (this._caps.etc2) {\r\n this._gl.COMPRESSED_SRGB8_ETC2 = this._caps.etc2.COMPRESSED_SRGB8_ETC2;\r\n this._gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = this._caps.etc2.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;\r\n }\r\n\r\n // Checks if some of the format renders first to allow the use of webgl inspector.\r\n if (this._webGLVersion > 1) {\r\n if (this._gl.HALF_FLOAT_OES !== 0x140b) {\r\n this._gl.HALF_FLOAT_OES = 0x140b;\r\n }\r\n }\r\n this._caps.textureHalfFloatRender = this._caps.textureHalfFloat && this._canRenderToHalfFloatFramebuffer();\r\n // Draw buffers\r\n if (this._webGLVersion > 1) {\r\n this._caps.drawBuffersExtension = true;\r\n this._caps.maxMSAASamples = this._maxMSAASamplesOverride !== null ? this._maxMSAASamplesOverride : this._gl.getParameter(this._gl.MAX_SAMPLES);\r\n } else {\r\n const drawBuffersExtension = this._gl.getExtension(\"WEBGL_draw_buffers\");\r\n\r\n if (drawBuffersExtension !== null) {\r\n this._caps.drawBuffersExtension = true;\r\n this._gl.drawBuffers = drawBuffersExtension.drawBuffersWEBGL.bind(drawBuffersExtension);\r\n (this._gl.DRAW_FRAMEBUFFER as any) = this._gl.FRAMEBUFFER;\r\n\r\n for (let i = 0; i < 16; i++) {\r\n (this._gl)[\"COLOR_ATTACHMENT\" + i + \"_WEBGL\"] = (drawBuffersExtension)[\"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\r\n }\r\n }\r\n }\r\n\r\n // Depth Texture\r\n if (this._webGLVersion > 1) {\r\n this._caps.depthTextureExtension = true;\r\n } else {\r\n const depthTextureExtension = this._gl.getExtension(\"WEBGL_depth_texture\");\r\n\r\n if (depthTextureExtension != null) {\r\n this._caps.depthTextureExtension = true;\r\n this._gl.UNSIGNED_INT_24_8 = depthTextureExtension.UNSIGNED_INT_24_8_WEBGL;\r\n }\r\n }\r\n\r\n // Vertex array object\r\n if (this.disableVertexArrayObjects) {\r\n this._caps.vertexArrayObject = false;\r\n } else if (this._webGLVersion > 1) {\r\n this._caps.vertexArrayObject = true;\r\n } else {\r\n const vertexArrayObjectExtension = this._gl.getExtension(\"OES_vertex_array_object\");\r\n\r\n if (vertexArrayObjectExtension != null) {\r\n this._caps.vertexArrayObject = true;\r\n this._gl.createVertexArray = vertexArrayObjectExtension.createVertexArrayOES.bind(vertexArrayObjectExtension);\r\n this._gl.bindVertexArray = vertexArrayObjectExtension.bindVertexArrayOES.bind(vertexArrayObjectExtension);\r\n this._gl.deleteVertexArray = vertexArrayObjectExtension.deleteVertexArrayOES.bind(vertexArrayObjectExtension);\r\n }\r\n }\r\n\r\n // Instances count\r\n if (this._webGLVersion > 1) {\r\n this._caps.instancedArrays = true;\r\n } else {\r\n const instanceExtension = this._gl.getExtension(\"ANGLE_instanced_arrays\");\r\n\r\n if (instanceExtension != null) {\r\n this._caps.instancedArrays = true;\r\n this._gl.drawArraysInstanced = instanceExtension.drawArraysInstancedANGLE.bind(instanceExtension);\r\n this._gl.drawElementsInstanced = instanceExtension.drawElementsInstancedANGLE.bind(instanceExtension);\r\n this._gl.vertexAttribDivisor = instanceExtension.vertexAttribDivisorANGLE.bind(instanceExtension);\r\n } else {\r\n this._caps.instancedArrays = false;\r\n }\r\n }\r\n\r\n if (this._gl.getShaderPrecisionFormat) {\r\n const vertexhighp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.HIGH_FLOAT);\r\n const fragmenthighp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);\r\n\r\n if (vertexhighp && fragmenthighp) {\r\n this._caps.highPrecisionShaderSupported = vertexhighp.precision !== 0 && fragmenthighp.precision !== 0;\r\n }\r\n }\r\n\r\n if (this._webGLVersion > 1) {\r\n this._caps.blendMinMax = true;\r\n } else {\r\n const blendMinMaxExtension = this._gl.getExtension(\"EXT_blend_minmax\");\r\n if (blendMinMaxExtension != null) {\r\n this._caps.blendMinMax = true;\r\n this._gl.MAX = blendMinMaxExtension.MAX_EXT as typeof WebGL2RenderingContext.MAX;\r\n this._gl.MIN = blendMinMaxExtension.MIN_EXT as typeof WebGL2RenderingContext.MIN;\r\n }\r\n }\r\n\r\n // sRGB buffers\r\n // only run this if not already set to true (in the constructor, for example)\r\n if (!this._caps.supportSRGBBuffers) {\r\n if (this._webGLVersion > 1) {\r\n this._caps.supportSRGBBuffers = true;\r\n this._glSRGBExtensionValues = {\r\n SRGB: WebGL2RenderingContext.SRGB,\r\n SRGB8: WebGL2RenderingContext.SRGB8,\r\n SRGB8_ALPHA8: WebGL2RenderingContext.SRGB8_ALPHA8,\r\n };\r\n } else {\r\n const sRGBExtension = this._gl.getExtension(\"EXT_sRGB\");\r\n\r\n if (sRGBExtension != null) {\r\n this._caps.supportSRGBBuffers = true;\r\n this._glSRGBExtensionValues = {\r\n SRGB: sRGBExtension.SRGB_EXT as typeof WebGL2RenderingContext.SRGB | EXT_sRGB[\"SRGB_EXT\"],\r\n SRGB8: sRGBExtension.SRGB_ALPHA_EXT as typeof WebGL2RenderingContext.SRGB8 | EXT_sRGB[\"SRGB_ALPHA_EXT\"],\r\n SRGB8_ALPHA8: sRGBExtension.SRGB_ALPHA_EXT as typeof WebGL2RenderingContext.SRGB8_ALPHA8 | EXT_sRGB[\"SRGB8_ALPHA8_EXT\"],\r\n };\r\n }\r\n }\r\n // take into account the forced state that was provided in options\r\n // When the issue in angle/chrome is fixed the flag should be taken into account only when it is explicitly defined\r\n this._caps.supportSRGBBuffers = this._caps.supportSRGBBuffers && !!(this._creationOptions && this._creationOptions.forceSRGBBufferSupportState);\r\n }\r\n\r\n // Depth buffer\r\n this._depthCullingState.depthTest = true;\r\n this._depthCullingState.depthFunc = this._gl.LEQUAL;\r\n this._depthCullingState.depthMask = true;\r\n\r\n // Texture maps\r\n this._maxSimultaneousTextures = this._caps.maxCombinedTexturesImageUnits;\r\n for (let slot = 0; slot < this._maxSimultaneousTextures; slot++) {\r\n this._nextFreeTextureSlots.push(slot);\r\n }\r\n\r\n if (this._glRenderer === \"Mali-G72\") {\r\n // Overcome a bug when using a texture to store morph targets on Mali-G72\r\n this._caps.disableMorphTargetTexture = true;\r\n }\r\n }\r\n\r\n protected _initFeatures(): void {\r\n this._features = {\r\n forceBitmapOverHTMLImageElement: false,\r\n supportRenderAndCopyToLodForFloatTextures: this._webGLVersion !== 1,\r\n supportDepthStencilTexture: this._webGLVersion !== 1,\r\n supportShadowSamplers: this._webGLVersion !== 1,\r\n uniformBufferHardCheckMatrix: false,\r\n allowTexturePrefiltering: this._webGLVersion !== 1,\r\n trackUbosInFrame: false,\r\n checkUbosContentBeforeUpload: false,\r\n supportCSM: this._webGLVersion !== 1,\r\n basisNeedsPOT: this._webGLVersion === 1,\r\n support3DTextures: this._webGLVersion !== 1,\r\n needTypeSuffixInShaderConstants: this._webGLVersion !== 1,\r\n supportMSAA: this._webGLVersion !== 1,\r\n supportSSAO2: this._webGLVersion !== 1,\r\n supportExtendedTextureFormats: this._webGLVersion !== 1,\r\n supportSwitchCaseInShader: this._webGLVersion !== 1,\r\n supportSyncTextureRead: true,\r\n needsInvertingBitmap: true,\r\n useUBOBindingCache: true,\r\n needShaderCodeInlining: false,\r\n needToAlwaysBindUniformBuffers: false,\r\n supportRenderPasses: false,\r\n supportSpriteInstancing: true,\r\n _collectUbosUpdatedInFrame: false,\r\n };\r\n }\r\n\r\n /**\r\n * Gets version of the current webGL context\r\n * Keep it for back compat - use version instead\r\n */\r\n public get webGLVersion(): number {\r\n return this._webGLVersion;\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"Engine\" string\r\n */\r\n public getClassName(): string {\r\n return \"ThinEngine\";\r\n }\r\n\r\n /**\r\n * Returns true if the stencil buffer has been enabled through the creation option of the context.\r\n */\r\n public get isStencilEnable(): boolean {\r\n return this._isStencilEnable;\r\n }\r\n\r\n /** @internal */\r\n public _prepareWorkingCanvas(): void {\r\n if (this._workingCanvas) {\r\n return;\r\n }\r\n\r\n this._workingCanvas = this.createCanvas(1, 1);\r\n const context = this._workingCanvas.getContext(\"2d\");\r\n\r\n if (context) {\r\n this._workingContext = context;\r\n }\r\n }\r\n\r\n /**\r\n * Reset the texture cache to empty state\r\n */\r\n public resetTextureCache() {\r\n for (const key in this._boundTexturesCache) {\r\n if (!Object.prototype.hasOwnProperty.call(this._boundTexturesCache, key)) {\r\n continue;\r\n }\r\n this._boundTexturesCache[key] = null;\r\n }\r\n\r\n this._currentTextureChannel = -1;\r\n }\r\n\r\n /**\r\n * Gets an object containing information about the current engine context\r\n * @returns an object containing the vendor, the renderer and the version of the current engine context\r\n */\r\n public getInfo() {\r\n return this.getGlInfo();\r\n }\r\n\r\n /**\r\n * Gets an object containing information about the current webGL context\r\n * @returns an object containing the vendor, the renderer and the version of the current webGL context\r\n */\r\n public getGlInfo() {\r\n return {\r\n vendor: this._glVendor,\r\n renderer: this._glRenderer,\r\n version: this._glVersion,\r\n };\r\n }\r\n\r\n /**\r\n * Defines the hardware scaling level.\r\n * By default the hardware scaling level is computed from the window device ratio.\r\n * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.\r\n * @param level defines the level to use\r\n */\r\n public setHardwareScalingLevel(level: number): void {\r\n this._hardwareScalingLevel = level;\r\n this.resize();\r\n }\r\n\r\n /**\r\n * Gets the current hardware scaling level.\r\n * By default the hardware scaling level is computed from the window device ratio.\r\n * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.\r\n * @returns a number indicating the current hardware scaling level\r\n */\r\n public getHardwareScalingLevel(): number {\r\n return this._hardwareScalingLevel;\r\n }\r\n\r\n /**\r\n * Gets the list of loaded textures\r\n * @returns an array containing all loaded textures\r\n */\r\n public getLoadedTexturesCache(): InternalTexture[] {\r\n return this._internalTexturesCache;\r\n }\r\n\r\n /**\r\n * Gets the object containing all engine capabilities\r\n * @returns the EngineCapabilities object\r\n */\r\n public getCaps(): EngineCapabilities {\r\n return this._caps;\r\n }\r\n\r\n /**\r\n * stop executing a render loop function and remove it from the execution array\r\n * @param renderFunction defines the function to be removed. If not provided all functions will be removed.\r\n */\r\n public stopRenderLoop(renderFunction?: () => void): void {\r\n if (!renderFunction) {\r\n this._activeRenderLoops.length = 0;\r\n this._cancelFrame();\r\n return;\r\n }\r\n\r\n const index = this._activeRenderLoops.indexOf(renderFunction);\r\n\r\n if (index >= 0) {\r\n this._activeRenderLoops.splice(index, 1);\r\n if (this._activeRenderLoops.length == 0) {\r\n this._cancelFrame();\r\n }\r\n }\r\n }\r\n\r\n protected _cancelFrame() {\r\n if (this._renderingQueueLaunched && this._frameHandler) {\r\n this._renderingQueueLaunched = false;\r\n if (!IsWindowObjectExist()) {\r\n if (typeof cancelAnimationFrame === \"function\") {\r\n return cancelAnimationFrame(this._frameHandler);\r\n }\r\n } else {\r\n const { cancelAnimationFrame } = this.getHostWindow() || window;\r\n if (typeof cancelAnimationFrame === \"function\") {\r\n return cancelAnimationFrame(this._frameHandler);\r\n }\r\n }\r\n return clearTimeout(this._frameHandler);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _renderLoop(): void {\r\n if (!this._contextWasLost) {\r\n let shouldRender = true;\r\n if (this._isDisposed || (!this.renderEvenInBackground && this._windowIsBackground)) {\r\n shouldRender = false;\r\n }\r\n\r\n if (shouldRender) {\r\n // Start new frame\r\n this.beginFrame();\r\n\r\n for (let index = 0; index < this._activeRenderLoops.length; index++) {\r\n const renderFunction = this._activeRenderLoops[index];\r\n\r\n renderFunction();\r\n }\r\n\r\n // Present\r\n this.endFrame();\r\n }\r\n }\r\n\r\n if (this._activeRenderLoops.length > 0) {\r\n this._frameHandler = this._queueNewFrame(this._boundRenderFunction, this.getHostWindow());\r\n } else {\r\n this._renderingQueueLaunched = false;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the HTML canvas attached with the current webGL context\r\n * @returns a HTML canvas\r\n */\r\n public getRenderingCanvas(): Nullable {\r\n return this._renderingCanvas;\r\n }\r\n\r\n /**\r\n * Gets the audio context specified in engine initialization options\r\n * @returns an Audio Context\r\n */\r\n public getAudioContext(): Nullable {\r\n return this._audioContext;\r\n }\r\n\r\n /**\r\n * Gets the audio destination specified in engine initialization options\r\n * @returns an audio destination node\r\n */\r\n public getAudioDestination(): Nullable {\r\n return this._audioDestination;\r\n }\r\n\r\n /**\r\n * Gets host window\r\n * @returns the host window object\r\n */\r\n public getHostWindow(): Nullable {\r\n if (!IsWindowObjectExist()) {\r\n return null;\r\n }\r\n\r\n if (this._renderingCanvas && this._renderingCanvas.ownerDocument && this._renderingCanvas.ownerDocument.defaultView) {\r\n return this._renderingCanvas.ownerDocument.defaultView;\r\n }\r\n\r\n return window;\r\n }\r\n\r\n /**\r\n * Gets the current render width\r\n * @param useScreen defines if screen size must be used (or the current render target if any)\r\n * @returns a number defining the current render width\r\n */\r\n public getRenderWidth(useScreen = false): number {\r\n if (!useScreen && this._currentRenderTarget) {\r\n return this._currentRenderTarget.width;\r\n }\r\n\r\n return this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferWidth : this._gl.drawingBufferWidth;\r\n }\r\n\r\n /**\r\n * Gets the current render height\r\n * @param useScreen defines if screen size must be used (or the current render target if any)\r\n * @returns a number defining the current render height\r\n */\r\n public getRenderHeight(useScreen = false): number {\r\n if (!useScreen && this._currentRenderTarget) {\r\n return this._currentRenderTarget.height;\r\n }\r\n\r\n return this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferHeight : this._gl.drawingBufferHeight;\r\n }\r\n\r\n /**\r\n * Can be used to override the current requestAnimationFrame requester.\r\n * @internal\r\n */\r\n protected _queueNewFrame(bindedRenderFunction: any, requester?: any): number {\r\n return ThinEngine.QueueNewFrame(bindedRenderFunction, requester);\r\n }\r\n\r\n /**\r\n * Register and execute a render loop. The engine can have more than one render function\r\n * @param renderFunction defines the function to continuously execute\r\n */\r\n public runRenderLoop(renderFunction: () => void): void {\r\n if (this._activeRenderLoops.indexOf(renderFunction) !== -1) {\r\n return;\r\n }\r\n\r\n this._activeRenderLoops.push(renderFunction);\r\n\r\n if (!this._renderingQueueLaunched) {\r\n this._renderingQueueLaunched = true;\r\n this._boundRenderFunction = this._renderLoop.bind(this);\r\n this._frameHandler = this._queueNewFrame(this._boundRenderFunction, this.getHostWindow());\r\n }\r\n }\r\n\r\n /**\r\n * Clear the current render buffer or the current render target (if any is set up)\r\n * @param color defines the color to use\r\n * @param backBuffer defines if the back buffer must be cleared\r\n * @param depth defines if the depth buffer must be cleared\r\n * @param stencil defines if the stencil buffer must be cleared\r\n */\r\n public clear(color: Nullable, backBuffer: boolean, depth: boolean, stencil: boolean = false): void {\r\n const useStencilGlobalOnly = this.stencilStateComposer.useStencilGlobalOnly;\r\n this.stencilStateComposer.useStencilGlobalOnly = true; // make sure the stencil mask is coming from the global stencil and not from a material (effect) which would currently be in effect\r\n\r\n this.applyStates();\r\n\r\n this.stencilStateComposer.useStencilGlobalOnly = useStencilGlobalOnly;\r\n\r\n let mode = 0;\r\n if (backBuffer && color) {\r\n let setBackBufferColor = true;\r\n if (this._currentRenderTarget) {\r\n const textureFormat = this._currentRenderTarget.texture?.format;\r\n if (\r\n textureFormat === Constants.TEXTUREFORMAT_RED_INTEGER ||\r\n textureFormat === Constants.TEXTUREFORMAT_RG_INTEGER ||\r\n textureFormat === Constants.TEXTUREFORMAT_RGB_INTEGER ||\r\n textureFormat === Constants.TEXTUREFORMAT_RGBA_INTEGER\r\n ) {\r\n const textureType = this._currentRenderTarget.texture?.type;\r\n if (textureType === Constants.TEXTURETYPE_UNSIGNED_INTEGER || textureType === Constants.TEXTURETYPE_UNSIGNED_SHORT) {\r\n ThinEngine._TempClearColorUint32[0] = color.r * 255;\r\n ThinEngine._TempClearColorUint32[1] = color.g * 255;\r\n ThinEngine._TempClearColorUint32[2] = color.b * 255;\r\n ThinEngine._TempClearColorUint32[3] = color.a * 255;\r\n this._gl.clearBufferuiv(this._gl.COLOR, 0, ThinEngine._TempClearColorUint32);\r\n setBackBufferColor = false;\r\n } else {\r\n ThinEngine._TempClearColorInt32[0] = color.r * 255;\r\n ThinEngine._TempClearColorInt32[1] = color.g * 255;\r\n ThinEngine._TempClearColorInt32[2] = color.b * 255;\r\n ThinEngine._TempClearColorInt32[3] = color.a * 255;\r\n this._gl.clearBufferiv(this._gl.COLOR, 0, ThinEngine._TempClearColorInt32);\r\n setBackBufferColor = false;\r\n }\r\n }\r\n }\r\n\r\n if (setBackBufferColor) {\r\n this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);\r\n mode |= this._gl.COLOR_BUFFER_BIT;\r\n }\r\n }\r\n\r\n if (depth) {\r\n if (this.useReverseDepthBuffer) {\r\n this._depthCullingState.depthFunc = this._gl.GEQUAL;\r\n this._gl.clearDepth(0.0);\r\n } else {\r\n this._gl.clearDepth(1.0);\r\n }\r\n mode |= this._gl.DEPTH_BUFFER_BIT;\r\n }\r\n if (stencil) {\r\n this._gl.clearStencil(0);\r\n mode |= this._gl.STENCIL_BUFFER_BIT;\r\n }\r\n this._gl.clear(mode);\r\n }\r\n\r\n protected _viewportCached = { x: 0, y: 0, z: 0, w: 0 };\r\n\r\n /**\r\n * @internal\r\n */\r\n public _viewport(x: number, y: number, width: number, height: number): void {\r\n if (x !== this._viewportCached.x || y !== this._viewportCached.y || width !== this._viewportCached.z || height !== this._viewportCached.w) {\r\n this._viewportCached.x = x;\r\n this._viewportCached.y = y;\r\n this._viewportCached.z = width;\r\n this._viewportCached.w = height;\r\n\r\n this._gl.viewport(x, y, width, height);\r\n }\r\n }\r\n\r\n /**\r\n * Set the WebGL's viewport\r\n * @param viewport defines the viewport element to be used\r\n * @param requiredWidth defines the width required for rendering. If not provided the rendering canvas' width is used\r\n * @param requiredHeight defines the height required for rendering. If not provided the rendering canvas' height is used\r\n */\r\n public setViewport(viewport: IViewportLike, requiredWidth?: number, requiredHeight?: number): void {\r\n const width = requiredWidth || this.getRenderWidth();\r\n const height = requiredHeight || this.getRenderHeight();\r\n const x = viewport.x || 0;\r\n const y = viewport.y || 0;\r\n\r\n this._cachedViewport = viewport;\r\n\r\n this._viewport(x * width, y * height, width * viewport.width, height * viewport.height);\r\n }\r\n\r\n /**\r\n * Begin a new frame\r\n */\r\n public beginFrame(): void {}\r\n\r\n /**\r\n * Enf the current frame\r\n */\r\n public endFrame(): void {\r\n // Force a flush in case we are using a bad OS.\r\n if (this._badOS) {\r\n this.flushFramebuffer();\r\n }\r\n this._frameId++;\r\n }\r\n\r\n /**\r\n * Resize the view according to the canvas' size\r\n * @param forceSetSize true to force setting the sizes of the underlying canvas\r\n */\r\n public resize(forceSetSize = false): void {\r\n let width: number;\r\n let height: number;\r\n\r\n // Re-query hardware scaling level to handle zoomed-in resizing.\r\n if (this.adaptToDeviceRatio) {\r\n const devicePixelRatio = IsWindowObjectExist() ? window.devicePixelRatio || 1.0 : 1.0;\r\n const changeRatio = this._lastDevicePixelRatio / devicePixelRatio;\r\n this._lastDevicePixelRatio = devicePixelRatio;\r\n this._hardwareScalingLevel *= changeRatio;\r\n }\r\n\r\n if (IsWindowObjectExist() && IsDocumentAvailable()) {\r\n // make sure it is a Node object, and is a part of the document.\r\n if (this._renderingCanvas) {\r\n const boundingRect = this._renderingCanvas.getBoundingClientRect\r\n ? this._renderingCanvas.getBoundingClientRect()\r\n : {\r\n // fallback to last solution in case the function doesn't exist\r\n width: this._renderingCanvas.width * this._hardwareScalingLevel,\r\n height: this._renderingCanvas.height * this._hardwareScalingLevel,\r\n };\r\n width = this._renderingCanvas.clientWidth || boundingRect.width || this._renderingCanvas.width || 100;\r\n height = this._renderingCanvas.clientHeight || boundingRect.height || this._renderingCanvas.height || 100;\r\n } else {\r\n width = window.innerWidth;\r\n height = window.innerHeight;\r\n }\r\n } else {\r\n width = this._renderingCanvas ? this._renderingCanvas.width : 100;\r\n height = this._renderingCanvas ? this._renderingCanvas.height : 100;\r\n }\r\n\r\n this.setSize(width / this._hardwareScalingLevel, height / this._hardwareScalingLevel, forceSetSize);\r\n }\r\n\r\n /**\r\n * Force a specific size of the canvas\r\n * @param width defines the new canvas' width\r\n * @param height defines the new canvas' height\r\n * @param forceSetSize true to force setting the sizes of the underlying canvas\r\n * @returns true if the size was changed\r\n */\r\n public setSize(width: number, height: number, forceSetSize = false): boolean {\r\n if (!this._renderingCanvas) {\r\n return false;\r\n }\r\n\r\n width = width | 0;\r\n height = height | 0;\r\n\r\n if (!forceSetSize && this._renderingCanvas.width === width && this._renderingCanvas.height === height) {\r\n return false;\r\n }\r\n\r\n this._renderingCanvas.width = width;\r\n this._renderingCanvas.height = height;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Binds the frame buffer to the specified texture.\r\n * @param rtWrapper The render target wrapper to render to\r\n * @param faceIndex The face of the texture to render to in case of cube texture and if the render target wrapper is not a multi render target\r\n * @param requiredWidth The width of the target to render to\r\n * @param requiredHeight The height of the target to render to\r\n * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true\r\n * @param lodLevel Defines the lod level to bind to the frame buffer\r\n * @param layer Defines the 2d array index to bind to the frame buffer if the render target wrapper is not a multi render target\r\n */\r\n public bindFramebuffer(\r\n rtWrapper: RenderTargetWrapper,\r\n faceIndex: number = 0,\r\n requiredWidth?: number,\r\n requiredHeight?: number,\r\n forceFullscreenViewport?: boolean,\r\n lodLevel = 0,\r\n layer = 0\r\n ): void {\r\n const webglRTWrapper = rtWrapper as WebGLRenderTargetWrapper;\r\n\r\n if (this._currentRenderTarget) {\r\n this.unBindFramebuffer(this._currentRenderTarget);\r\n }\r\n this._currentRenderTarget = rtWrapper;\r\n this._bindUnboundFramebuffer(webglRTWrapper._MSAAFramebuffer ? webglRTWrapper._MSAAFramebuffer : webglRTWrapper._framebuffer);\r\n\r\n const gl = this._gl;\r\n if (!rtWrapper.isMulti) {\r\n if (rtWrapper.is2DArray) {\r\n gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, rtWrapper.texture!._hardwareTexture?.underlyingResource, lodLevel, layer);\r\n } else if (rtWrapper.isCube) {\r\n gl.framebufferTexture2D(\r\n gl.FRAMEBUFFER,\r\n gl.COLOR_ATTACHMENT0,\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex,\r\n rtWrapper.texture!._hardwareTexture?.underlyingResource,\r\n lodLevel\r\n );\r\n }\r\n }\r\n\r\n const depthStencilTexture = rtWrapper._depthStencilTexture;\r\n if (depthStencilTexture) {\r\n const attachment = rtWrapper._depthStencilTextureWithStencil ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;\r\n if (rtWrapper.is2DArray) {\r\n gl.framebufferTextureLayer(gl.FRAMEBUFFER, attachment, depthStencilTexture._hardwareTexture?.underlyingResource, lodLevel, layer);\r\n } else if (rtWrapper.isCube) {\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, depthStencilTexture._hardwareTexture?.underlyingResource, lodLevel);\r\n } else {\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, depthStencilTexture._hardwareTexture?.underlyingResource, lodLevel);\r\n }\r\n }\r\n\r\n if (this._cachedViewport && !forceFullscreenViewport) {\r\n this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);\r\n } else {\r\n if (!requiredWidth) {\r\n requiredWidth = rtWrapper.width;\r\n if (lodLevel) {\r\n requiredWidth = requiredWidth / Math.pow(2, lodLevel);\r\n }\r\n }\r\n if (!requiredHeight) {\r\n requiredHeight = rtWrapper.height;\r\n if (lodLevel) {\r\n requiredHeight = requiredHeight / Math.pow(2, lodLevel);\r\n }\r\n }\r\n\r\n this._viewport(0, 0, requiredWidth, requiredHeight);\r\n }\r\n\r\n this.wipeCaches();\r\n }\r\n\r\n /**\r\n * Set various states to the webGL context\r\n * @param culling defines culling state: true to enable culling, false to disable it\r\n * @param zOffset defines the value to apply to zOffset (0 by default)\r\n * @param force defines if states must be applied even if cache is up to date\r\n * @param reverseSide defines if culling must be reversed (CCW if false, CW if true)\r\n * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)\r\n * @param stencil stencil states to set\r\n * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)\r\n */\r\n public setState(culling: boolean, zOffset: number = 0, force?: boolean, reverseSide = false, cullBackFaces?: boolean, stencil?: IStencilState, zOffsetUnits: number = 0): void {\r\n // Culling\r\n if (this._depthCullingState.cull !== culling || force) {\r\n this._depthCullingState.cull = culling;\r\n }\r\n\r\n // Cull face\r\n const cullFace = this.cullBackFaces ?? cullBackFaces ?? true ? this._gl.BACK : this._gl.FRONT;\r\n if (this._depthCullingState.cullFace !== cullFace || force) {\r\n this._depthCullingState.cullFace = cullFace;\r\n }\r\n\r\n // Z offset\r\n this.setZOffset(zOffset);\r\n this.setZOffsetUnits(zOffsetUnits);\r\n\r\n // Front face\r\n const frontFace = reverseSide ? this._gl.CW : this._gl.CCW;\r\n if (this._depthCullingState.frontFace !== frontFace || force) {\r\n this._depthCullingState.frontFace = frontFace;\r\n }\r\n\r\n this._stencilStateComposer.stencilMaterial = stencil;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if depth testing is enabled\r\n * @returns the current state\r\n */\r\n public getDepthBuffer(): boolean {\r\n return this._depthCullingState.depthTest;\r\n }\r\n\r\n /**\r\n * Enable or disable depth buffering\r\n * @param enable defines the state to set\r\n */\r\n public setDepthBuffer(enable: boolean): void {\r\n this._depthCullingState.depthTest = enable;\r\n }\r\n\r\n /**\r\n * Set the z offset Factor to apply to current rendering\r\n * @param value defines the offset to apply\r\n */\r\n public setZOffset(value: number): void {\r\n this._depthCullingState.zOffset = this.useReverseDepthBuffer ? -value : value;\r\n }\r\n\r\n /**\r\n * Gets the current value of the zOffset Factor\r\n * @returns the current zOffset Factor state\r\n */\r\n public getZOffset(): number {\r\n const zOffset = this._depthCullingState.zOffset;\r\n return this.useReverseDepthBuffer ? -zOffset : zOffset;\r\n }\r\n\r\n /**\r\n * Set the z offset Units to apply to current rendering\r\n * @param value defines the offset to apply\r\n */\r\n public setZOffsetUnits(value: number): void {\r\n this._depthCullingState.zOffsetUnits = this.useReverseDepthBuffer ? -value : value;\r\n }\r\n\r\n /**\r\n * Gets the current value of the zOffset Units\r\n * @returns the current zOffset Units state\r\n */\r\n public getZOffsetUnits(): number {\r\n const zOffsetUnits = this._depthCullingState.zOffsetUnits;\r\n return this.useReverseDepthBuffer ? -zOffsetUnits : zOffsetUnits;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindUnboundFramebuffer(framebuffer: Nullable) {\r\n if (this._currentFramebuffer !== framebuffer) {\r\n this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, framebuffer);\r\n this._currentFramebuffer = framebuffer;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _currentFrameBufferIsDefaultFrameBuffer() {\r\n return this._currentFramebuffer === null;\r\n }\r\n\r\n /**\r\n * Generates the mipmaps for a texture\r\n * @param texture texture to generate the mipmaps for\r\n */\r\n public generateMipmaps(texture: InternalTexture): void {\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\r\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n }\r\n\r\n /**\r\n * Unbind the current render target texture from the webGL context\r\n * @param texture defines the render target wrapper to unbind\r\n * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated\r\n * @param onBeforeUnbind defines a function which will be called before the effective unbind\r\n */\r\n public unBindFramebuffer(texture: RenderTargetWrapper, disableGenerateMipMaps = false, onBeforeUnbind?: () => void): void {\r\n const webglRTWrapper = texture as WebGLRenderTargetWrapper;\r\n\r\n this._currentRenderTarget = null;\r\n\r\n // If MSAA, we need to bitblt back to main texture\r\n const gl = this._gl;\r\n if (webglRTWrapper._MSAAFramebuffer) {\r\n if (texture.isMulti) {\r\n // This texture is part of a MRT texture, we need to treat all attachments\r\n this.unBindMultiColorAttachmentFramebuffer(texture, disableGenerateMipMaps, onBeforeUnbind);\r\n return;\r\n }\r\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, webglRTWrapper._MSAAFramebuffer);\r\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, webglRTWrapper._framebuffer);\r\n gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);\r\n }\r\n\r\n if (texture.texture?.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {\r\n this.generateMipmaps(texture.texture);\r\n }\r\n\r\n if (onBeforeUnbind) {\r\n if (webglRTWrapper._MSAAFramebuffer) {\r\n // Bind the correct framebuffer\r\n this._bindUnboundFramebuffer(webglRTWrapper._framebuffer);\r\n }\r\n onBeforeUnbind();\r\n }\r\n\r\n this._bindUnboundFramebuffer(null);\r\n }\r\n\r\n /**\r\n * Force a webGL flush (ie. a flush of all waiting webGL commands)\r\n */\r\n public flushFramebuffer(): void {\r\n this._gl.flush();\r\n }\r\n\r\n /**\r\n * Unbind the current render target and bind the default framebuffer\r\n */\r\n public restoreDefaultFramebuffer(): void {\r\n if (this._currentRenderTarget) {\r\n this.unBindFramebuffer(this._currentRenderTarget);\r\n } else {\r\n this._bindUnboundFramebuffer(null);\r\n }\r\n if (this._cachedViewport) {\r\n this.setViewport(this._cachedViewport);\r\n }\r\n\r\n this.wipeCaches();\r\n }\r\n\r\n // VBOs\r\n\r\n /** @internal */\r\n protected _resetVertexBufferBinding(): void {\r\n this.bindArrayBuffer(null);\r\n this._cachedVertexBuffers = null;\r\n }\r\n\r\n /**\r\n * Creates a vertex buffer\r\n * @param data the data for the vertex buffer\r\n * @returns the new WebGL static buffer\r\n */\r\n public createVertexBuffer(data: DataArray): DataBuffer {\r\n return this._createVertexBuffer(data, this._gl.STATIC_DRAW);\r\n }\r\n\r\n private _createVertexBuffer(data: DataArray, usage: number): DataBuffer {\r\n const vbo = this._gl.createBuffer();\r\n\r\n if (!vbo) {\r\n throw new Error(\"Unable to create vertex buffer\");\r\n }\r\n\r\n const dataBuffer = new WebGLDataBuffer(vbo);\r\n this.bindArrayBuffer(dataBuffer);\r\n\r\n if (data instanceof Array) {\r\n this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), usage);\r\n } else {\r\n this._gl.bufferData(this._gl.ARRAY_BUFFER, data, usage);\r\n }\r\n\r\n this._resetVertexBufferBinding();\r\n\r\n dataBuffer.references = 1;\r\n return dataBuffer;\r\n }\r\n\r\n /**\r\n * Creates a dynamic vertex buffer\r\n * @param data the data for the dynamic vertex buffer\r\n * @returns the new WebGL dynamic buffer\r\n */\r\n public createDynamicVertexBuffer(data: DataArray): DataBuffer {\r\n return this._createVertexBuffer(data, this._gl.DYNAMIC_DRAW);\r\n }\r\n\r\n protected _resetIndexBufferBinding(): void {\r\n this.bindIndexBuffer(null);\r\n this._cachedIndexBuffer = null;\r\n }\r\n\r\n /**\r\n * Creates a new index buffer\r\n * @param indices defines the content of the index buffer\r\n * @param updatable defines if the index buffer must be updatable\r\n * @returns a new webGL buffer\r\n */\r\n public createIndexBuffer(indices: IndicesArray, updatable?: boolean): DataBuffer {\r\n const vbo = this._gl.createBuffer();\r\n const dataBuffer = new WebGLDataBuffer(vbo!);\r\n\r\n if (!vbo) {\r\n throw new Error(\"Unable to create index buffer\");\r\n }\r\n\r\n this.bindIndexBuffer(dataBuffer);\r\n\r\n const data = this._normalizeIndexData(indices);\r\n this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, data, updatable ? this._gl.DYNAMIC_DRAW : this._gl.STATIC_DRAW);\r\n this._resetIndexBufferBinding();\r\n dataBuffer.references = 1;\r\n dataBuffer.is32Bits = data.BYTES_PER_ELEMENT === 4;\r\n return dataBuffer;\r\n }\r\n\r\n protected _normalizeIndexData(indices: IndicesArray): Uint16Array | Uint32Array {\r\n const bytesPerElement = (indices as Exclude).BYTES_PER_ELEMENT;\r\n if (bytesPerElement === 2) {\r\n return indices as Uint16Array;\r\n }\r\n\r\n // Check 32 bit support\r\n if (this._caps.uintIndices) {\r\n if (indices instanceof Uint32Array) {\r\n return indices;\r\n } else {\r\n // number[] or Int32Array, check if 32 bit is necessary\r\n for (let index = 0; index < indices.length; index++) {\r\n if (indices[index] >= 65535) {\r\n return new Uint32Array(indices);\r\n }\r\n }\r\n\r\n return new Uint16Array(indices);\r\n }\r\n }\r\n\r\n // No 32 bit support, force conversion to 16 bit (values greater 16 bit are lost)\r\n return new Uint16Array(indices);\r\n }\r\n\r\n /**\r\n * Bind a webGL buffer to the webGL context\r\n * @param buffer defines the buffer to bind\r\n */\r\n public bindArrayBuffer(buffer: Nullable): void {\r\n if (!this._vaoRecordInProgress) {\r\n this._unbindVertexArrayObject();\r\n }\r\n this._bindBuffer(buffer, this._gl.ARRAY_BUFFER);\r\n }\r\n\r\n /**\r\n * Bind a specific block at a given index in a specific shader program\r\n * @param pipelineContext defines the pipeline context to use\r\n * @param blockName defines the block name\r\n * @param index defines the index where to bind the block\r\n */\r\n public bindUniformBlock(pipelineContext: IPipelineContext, blockName: string, index: number): void {\r\n const program = (pipelineContext as WebGLPipelineContext).program!;\r\n\r\n const uniformLocation = this._gl.getUniformBlockIndex(program, blockName);\r\n\r\n this._gl.uniformBlockBinding(program, uniformLocation, index);\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected bindIndexBuffer(buffer: Nullable): void {\r\n if (!this._vaoRecordInProgress) {\r\n this._unbindVertexArrayObject();\r\n }\r\n this._bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);\r\n }\r\n\r\n private _bindBuffer(buffer: Nullable, target: number): void {\r\n if (this._vaoRecordInProgress || this._currentBoundBuffer[target] !== buffer) {\r\n this._gl.bindBuffer(target, buffer ? buffer.underlyingResource : null);\r\n this._currentBoundBuffer[target] = buffer;\r\n }\r\n }\r\n\r\n /**\r\n * update the bound buffer with the given data\r\n * @param data defines the data to update\r\n */\r\n public updateArrayBuffer(data: Float32Array): void {\r\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);\r\n }\r\n\r\n private _vertexAttribPointer(buffer: DataBuffer, indx: number, size: number, type: number, normalized: boolean, stride: number, offset: number): void {\r\n const pointer = this._currentBufferPointers[indx];\r\n if (!pointer) {\r\n return;\r\n }\r\n\r\n let changed = false;\r\n if (!pointer.active) {\r\n changed = true;\r\n pointer.active = true;\r\n pointer.index = indx;\r\n pointer.size = size;\r\n pointer.type = type;\r\n pointer.normalized = normalized;\r\n pointer.stride = stride;\r\n pointer.offset = offset;\r\n pointer.buffer = buffer;\r\n } else {\r\n if (pointer.buffer !== buffer) {\r\n pointer.buffer = buffer;\r\n changed = true;\r\n }\r\n if (pointer.size !== size) {\r\n pointer.size = size;\r\n changed = true;\r\n }\r\n if (pointer.type !== type) {\r\n pointer.type = type;\r\n changed = true;\r\n }\r\n if (pointer.normalized !== normalized) {\r\n pointer.normalized = normalized;\r\n changed = true;\r\n }\r\n if (pointer.stride !== stride) {\r\n pointer.stride = stride;\r\n changed = true;\r\n }\r\n if (pointer.offset !== offset) {\r\n pointer.offset = offset;\r\n changed = true;\r\n }\r\n }\r\n\r\n if (changed || this._vaoRecordInProgress) {\r\n this.bindArrayBuffer(buffer);\r\n if (type === this._gl.UNSIGNED_INT || type === this._gl.INT) {\r\n this._gl.vertexAttribIPointer(indx, size, type, stride, offset);\r\n } else {\r\n this._gl.vertexAttribPointer(indx, size, type, normalized, stride, offset);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindIndexBufferWithCache(indexBuffer: Nullable): void {\r\n if (indexBuffer == null) {\r\n return;\r\n }\r\n if (this._cachedIndexBuffer !== indexBuffer) {\r\n this._cachedIndexBuffer = indexBuffer;\r\n this.bindIndexBuffer(indexBuffer);\r\n this._uintIndicesCurrentlySet = indexBuffer.is32Bits;\r\n }\r\n }\r\n\r\n private _bindVertexBuffersAttributes(\r\n vertexBuffers: { [key: string]: Nullable },\r\n effect: Effect,\r\n overrideVertexBuffers?: { [kind: string]: Nullable }\r\n ): void {\r\n const attributes = effect.getAttributesNames();\r\n\r\n if (!this._vaoRecordInProgress) {\r\n this._unbindVertexArrayObject();\r\n }\r\n\r\n this.unbindAllAttributes();\r\n\r\n for (let index = 0; index < attributes.length; index++) {\r\n const order = effect.getAttributeLocation(index);\r\n\r\n if (order >= 0) {\r\n const ai = attributes[index];\r\n let vertexBuffer: Nullable = null;\r\n\r\n if (overrideVertexBuffers) {\r\n vertexBuffer = overrideVertexBuffers[ai];\r\n }\r\n\r\n if (!vertexBuffer) {\r\n vertexBuffer = vertexBuffers[ai];\r\n }\r\n\r\n if (!vertexBuffer) {\r\n continue;\r\n }\r\n\r\n this._gl.enableVertexAttribArray(order);\r\n if (!this._vaoRecordInProgress) {\r\n this._vertexAttribArraysEnabled[order] = true;\r\n }\r\n\r\n const buffer = vertexBuffer.getBuffer();\r\n if (buffer) {\r\n this._vertexAttribPointer(buffer, order, vertexBuffer.getSize(), vertexBuffer.type, vertexBuffer.normalized, vertexBuffer.byteStride, vertexBuffer.byteOffset);\r\n\r\n if (vertexBuffer.getIsInstanced()) {\r\n this._gl.vertexAttribDivisor(order, vertexBuffer.getInstanceDivisor());\r\n if (!this._vaoRecordInProgress) {\r\n this._currentInstanceLocations.push(order);\r\n this._currentInstanceBuffers.push(buffer);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Records a vertex array object\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects\r\n * @param vertexBuffers defines the list of vertex buffers to store\r\n * @param indexBuffer defines the index buffer to store\r\n * @param effect defines the effect to store\r\n * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers\r\n * @returns the new vertex array object\r\n */\r\n public recordVertexArrayObject(\r\n vertexBuffers: { [key: string]: VertexBuffer },\r\n indexBuffer: Nullable,\r\n effect: Effect,\r\n overrideVertexBuffers?: { [kind: string]: Nullable }\r\n ): WebGLVertexArrayObject {\r\n const vao = this._gl.createVertexArray();\r\n\r\n if (!vao) {\r\n throw new Error(\"Unable to create VAO\");\r\n }\r\n\r\n this._vaoRecordInProgress = true;\r\n\r\n this._gl.bindVertexArray(vao);\r\n\r\n this._mustWipeVertexAttributes = true;\r\n this._bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers);\r\n\r\n this.bindIndexBuffer(indexBuffer);\r\n\r\n this._vaoRecordInProgress = false;\r\n this._gl.bindVertexArray(null);\r\n\r\n return vao;\r\n }\r\n\r\n /**\r\n * Bind a specific vertex array object\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects\r\n * @param vertexArrayObject defines the vertex array object to bind\r\n * @param indexBuffer defines the index buffer to bind\r\n */\r\n public bindVertexArrayObject(vertexArrayObject: WebGLVertexArrayObject, indexBuffer: Nullable): void {\r\n if (this._cachedVertexArrayObject !== vertexArrayObject) {\r\n this._cachedVertexArrayObject = vertexArrayObject;\r\n\r\n this._gl.bindVertexArray(vertexArrayObject);\r\n this._cachedVertexBuffers = null;\r\n this._cachedIndexBuffer = null;\r\n\r\n this._uintIndicesCurrentlySet = indexBuffer != null && indexBuffer.is32Bits;\r\n this._mustWipeVertexAttributes = true;\r\n }\r\n }\r\n\r\n /**\r\n * Bind webGl buffers directly to the webGL context\r\n * @param vertexBuffer defines the vertex buffer to bind\r\n * @param indexBuffer defines the index buffer to bind\r\n * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer\r\n * @param vertexStrideSize defines the vertex stride of the vertex buffer\r\n * @param effect defines the effect associated with the vertex buffer\r\n */\r\n public bindBuffersDirectly(vertexBuffer: DataBuffer, indexBuffer: DataBuffer, vertexDeclaration: number[], vertexStrideSize: number, effect: Effect): void {\r\n if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {\r\n this._cachedVertexBuffers = vertexBuffer;\r\n this._cachedEffectForVertexBuffers = effect;\r\n\r\n const attributesCount = effect.getAttributesCount();\r\n\r\n this._unbindVertexArrayObject();\r\n this.unbindAllAttributes();\r\n\r\n let offset = 0;\r\n for (let index = 0; index < attributesCount; index++) {\r\n if (index < vertexDeclaration.length) {\r\n const order = effect.getAttributeLocation(index);\r\n\r\n if (order >= 0) {\r\n this._gl.enableVertexAttribArray(order);\r\n this._vertexAttribArraysEnabled[order] = true;\r\n this._vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);\r\n }\r\n\r\n offset += vertexDeclaration[index] * 4;\r\n }\r\n }\r\n }\r\n\r\n this._bindIndexBufferWithCache(indexBuffer);\r\n }\r\n\r\n private _unbindVertexArrayObject(): void {\r\n if (!this._cachedVertexArrayObject) {\r\n return;\r\n }\r\n\r\n this._cachedVertexArrayObject = null;\r\n this._gl.bindVertexArray(null);\r\n }\r\n\r\n /**\r\n * Bind a list of vertex buffers to the webGL context\r\n * @param vertexBuffers defines the list of vertex buffers to bind\r\n * @param indexBuffer defines the index buffer to bind\r\n * @param effect defines the effect associated with the vertex buffers\r\n * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers\r\n */\r\n public bindBuffers(\r\n vertexBuffers: { [key: string]: Nullable },\r\n indexBuffer: Nullable,\r\n effect: Effect,\r\n overrideVertexBuffers?: { [kind: string]: Nullable }\r\n ): void {\r\n if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {\r\n this._cachedVertexBuffers = vertexBuffers;\r\n this._cachedEffectForVertexBuffers = effect;\r\n\r\n this._bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers);\r\n }\r\n\r\n this._bindIndexBufferWithCache(indexBuffer);\r\n }\r\n\r\n /**\r\n * Unbind all instance attributes\r\n */\r\n public unbindInstanceAttributes() {\r\n let boundBuffer;\r\n for (let i = 0, ul = this._currentInstanceLocations.length; i < ul; i++) {\r\n const instancesBuffer = this._currentInstanceBuffers[i];\r\n if (boundBuffer != instancesBuffer && instancesBuffer.references) {\r\n boundBuffer = instancesBuffer;\r\n this.bindArrayBuffer(instancesBuffer);\r\n }\r\n const offsetLocation = this._currentInstanceLocations[i];\r\n this._gl.vertexAttribDivisor(offsetLocation, 0);\r\n }\r\n this._currentInstanceBuffers.length = 0;\r\n this._currentInstanceLocations.length = 0;\r\n }\r\n\r\n /**\r\n * Release and free the memory of a vertex array object\r\n * @param vao defines the vertex array object to delete\r\n */\r\n public releaseVertexArrayObject(vao: WebGLVertexArrayObject) {\r\n this._gl.deleteVertexArray(vao);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseBuffer(buffer: DataBuffer): boolean {\r\n buffer.references--;\r\n\r\n if (buffer.references === 0) {\r\n this._deleteBuffer(buffer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n protected _deleteBuffer(buffer: DataBuffer): void {\r\n this._gl.deleteBuffer(buffer.underlyingResource);\r\n }\r\n\r\n /**\r\n * Update the content of a webGL buffer used with instantiation and bind it to the webGL context\r\n * @param instancesBuffer defines the webGL buffer to update and bind\r\n * @param data defines the data to store in the buffer\r\n * @param offsetLocations defines the offsets or attributes information used to determine where data must be stored in the buffer\r\n */\r\n public updateAndBindInstancesBuffer(instancesBuffer: DataBuffer, data: Float32Array, offsetLocations: number[] | InstancingAttributeInfo[]): void {\r\n this.bindArrayBuffer(instancesBuffer);\r\n if (data) {\r\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);\r\n }\r\n\r\n if ((offsetLocations[0]).index !== undefined) {\r\n this.bindInstancesBuffer(instancesBuffer, offsetLocations as any, true);\r\n } else {\r\n for (let index = 0; index < 4; index++) {\r\n const offsetLocation = offsetLocations[index];\r\n\r\n if (!this._vertexAttribArraysEnabled[offsetLocation]) {\r\n this._gl.enableVertexAttribArray(offsetLocation);\r\n this._vertexAttribArraysEnabled[offsetLocation] = true;\r\n }\r\n\r\n this._vertexAttribPointer(instancesBuffer, offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);\r\n this._gl.vertexAttribDivisor(offsetLocation, 1);\r\n this._currentInstanceLocations.push(offsetLocation);\r\n this._currentInstanceBuffers.push(instancesBuffer);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Bind the content of a webGL buffer used with instantiation\r\n * @param instancesBuffer defines the webGL buffer to bind\r\n * @param attributesInfo defines the offsets or attributes information used to determine where data must be stored in the buffer\r\n * @param computeStride defines Whether to compute the strides from the info or use the default 0\r\n */\r\n public bindInstancesBuffer(instancesBuffer: DataBuffer, attributesInfo: InstancingAttributeInfo[], computeStride = true): void {\r\n this.bindArrayBuffer(instancesBuffer);\r\n\r\n let stride = 0;\r\n if (computeStride) {\r\n for (let i = 0; i < attributesInfo.length; i++) {\r\n const ai = attributesInfo[i];\r\n stride += ai.attributeSize * 4;\r\n }\r\n }\r\n\r\n for (let i = 0; i < attributesInfo.length; i++) {\r\n const ai = attributesInfo[i];\r\n if (ai.index === undefined) {\r\n ai.index = this._currentEffect!.getAttributeLocationByName(ai.attributeName);\r\n }\r\n\r\n if (ai.index < 0) {\r\n continue;\r\n }\r\n\r\n if (!this._vertexAttribArraysEnabled[ai.index]) {\r\n this._gl.enableVertexAttribArray(ai.index);\r\n this._vertexAttribArraysEnabled[ai.index] = true;\r\n }\r\n\r\n this._vertexAttribPointer(instancesBuffer, ai.index, ai.attributeSize, ai.attributeType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);\r\n this._gl.vertexAttribDivisor(ai.index, ai.divisor === undefined ? 1 : ai.divisor);\r\n this._currentInstanceLocations.push(ai.index);\r\n this._currentInstanceBuffers.push(instancesBuffer);\r\n }\r\n }\r\n\r\n /**\r\n * Disable the instance attribute corresponding to the name in parameter\r\n * @param name defines the name of the attribute to disable\r\n */\r\n public disableInstanceAttributeByName(name: string) {\r\n if (!this._currentEffect) {\r\n return;\r\n }\r\n\r\n const attributeLocation = this._currentEffect.getAttributeLocationByName(name);\r\n this.disableInstanceAttribute(attributeLocation);\r\n }\r\n\r\n /**\r\n * Disable the instance attribute corresponding to the location in parameter\r\n * @param attributeLocation defines the attribute location of the attribute to disable\r\n */\r\n public disableInstanceAttribute(attributeLocation: number) {\r\n let shouldClean = false;\r\n let index: number;\r\n while ((index = this._currentInstanceLocations.indexOf(attributeLocation)) !== -1) {\r\n this._currentInstanceLocations.splice(index, 1);\r\n this._currentInstanceBuffers.splice(index, 1);\r\n\r\n shouldClean = true;\r\n index = this._currentInstanceLocations.indexOf(attributeLocation);\r\n }\r\n\r\n if (shouldClean) {\r\n this._gl.vertexAttribDivisor(attributeLocation, 0);\r\n this.disableAttributeByIndex(attributeLocation);\r\n }\r\n }\r\n\r\n /**\r\n * Disable the attribute corresponding to the location in parameter\r\n * @param attributeLocation defines the attribute location of the attribute to disable\r\n */\r\n public disableAttributeByIndex(attributeLocation: number) {\r\n this._gl.disableVertexAttribArray(attributeLocation);\r\n this._vertexAttribArraysEnabled[attributeLocation] = false;\r\n this._currentBufferPointers[attributeLocation].active = false;\r\n }\r\n\r\n /**\r\n * Send a draw order\r\n * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)\r\n * @param indexStart defines the starting index\r\n * @param indexCount defines the number of index to draw\r\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\r\n */\r\n public draw(useTriangles: boolean, indexStart: number, indexCount: number, instancesCount?: number): void {\r\n this.drawElementsType(useTriangles ? Constants.MATERIAL_TriangleFillMode : Constants.MATERIAL_WireFrameFillMode, indexStart, indexCount, instancesCount);\r\n }\r\n\r\n /**\r\n * Draw a list of points\r\n * @param verticesStart defines the index of first vertex to draw\r\n * @param verticesCount defines the count of vertices to draw\r\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\r\n */\r\n public drawPointClouds(verticesStart: number, verticesCount: number, instancesCount?: number): void {\r\n this.drawArraysType(Constants.MATERIAL_PointFillMode, verticesStart, verticesCount, instancesCount);\r\n }\r\n\r\n /**\r\n * Draw a list of unindexed primitives\r\n * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)\r\n * @param verticesStart defines the index of first vertex to draw\r\n * @param verticesCount defines the count of vertices to draw\r\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\r\n */\r\n public drawUnIndexed(useTriangles: boolean, verticesStart: number, verticesCount: number, instancesCount?: number): void {\r\n this.drawArraysType(useTriangles ? Constants.MATERIAL_TriangleFillMode : Constants.MATERIAL_WireFrameFillMode, verticesStart, verticesCount, instancesCount);\r\n }\r\n\r\n /**\r\n * Draw a list of indexed primitives\r\n * @param fillMode defines the primitive to use\r\n * @param indexStart defines the starting index\r\n * @param indexCount defines the number of index to draw\r\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\r\n */\r\n public drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void {\r\n // Apply states\r\n this.applyStates();\r\n\r\n this._reportDrawCall();\r\n\r\n // Render\r\n\r\n const drawMode = this._drawMode(fillMode);\r\n const indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;\r\n const mult = this._uintIndicesCurrentlySet ? 4 : 2;\r\n if (instancesCount) {\r\n this._gl.drawElementsInstanced(drawMode, indexCount, indexFormat, indexStart * mult, instancesCount);\r\n } else {\r\n this._gl.drawElements(drawMode, indexCount, indexFormat, indexStart * mult);\r\n }\r\n }\r\n\r\n /**\r\n * Draw a list of unindexed primitives\r\n * @param fillMode defines the primitive to use\r\n * @param verticesStart defines the index of first vertex to draw\r\n * @param verticesCount defines the count of vertices to draw\r\n * @param instancesCount defines the number of instances to draw (if instantiation is enabled)\r\n */\r\n public drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void {\r\n // Apply states\r\n this.applyStates();\r\n\r\n this._reportDrawCall();\r\n\r\n const drawMode = this._drawMode(fillMode);\r\n if (instancesCount) {\r\n this._gl.drawArraysInstanced(drawMode, verticesStart, verticesCount, instancesCount);\r\n } else {\r\n this._gl.drawArrays(drawMode, verticesStart, verticesCount);\r\n }\r\n }\r\n\r\n private _drawMode(fillMode: number): number {\r\n switch (fillMode) {\r\n // Triangle views\r\n case Constants.MATERIAL_TriangleFillMode:\r\n return this._gl.TRIANGLES;\r\n case Constants.MATERIAL_PointFillMode:\r\n return this._gl.POINTS;\r\n case Constants.MATERIAL_WireFrameFillMode:\r\n return this._gl.LINES;\r\n // Draw modes\r\n case Constants.MATERIAL_PointListDrawMode:\r\n return this._gl.POINTS;\r\n case Constants.MATERIAL_LineListDrawMode:\r\n return this._gl.LINES;\r\n case Constants.MATERIAL_LineLoopDrawMode:\r\n return this._gl.LINE_LOOP;\r\n case Constants.MATERIAL_LineStripDrawMode:\r\n return this._gl.LINE_STRIP;\r\n case Constants.MATERIAL_TriangleStripDrawMode:\r\n return this._gl.TRIANGLE_STRIP;\r\n case Constants.MATERIAL_TriangleFanDrawMode:\r\n return this._gl.TRIANGLE_FAN;\r\n default:\r\n return this._gl.TRIANGLES;\r\n }\r\n }\r\n\r\n /** @internal */\r\n protected _reportDrawCall() {\r\n // Will be implemented by children\r\n }\r\n\r\n // Shaders\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseEffect(effect: Effect): void {\r\n if (this._compiledEffects[effect._key]) {\r\n delete this._compiledEffects[effect._key];\r\n }\r\n const pipelineContext = effect.getPipelineContext();\r\n if (pipelineContext) {\r\n this._deletePipelineContext(pipelineContext);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deletePipelineContext(pipelineContext: IPipelineContext): void {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n if (webGLPipelineContext && webGLPipelineContext.program) {\r\n webGLPipelineContext.program.__SPECTOR_rebuildProgram = null;\r\n\r\n this._gl.deleteProgram(webGLPipelineContext.program);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _getGlobalDefines(defines?: { [key: string]: string }): string | undefined {\r\n if (defines) {\r\n if (this.isNDCHalfZRange) {\r\n defines[\"IS_NDC_HALF_ZRANGE\"] = \"\";\r\n } else {\r\n delete defines[\"IS_NDC_HALF_ZRANGE\"];\r\n }\r\n if (this.useReverseDepthBuffer) {\r\n defines[\"USE_REVERSE_DEPTHBUFFER\"] = \"\";\r\n } else {\r\n delete defines[\"USE_REVERSE_DEPTHBUFFER\"];\r\n }\r\n if (this.useExactSrgbConversions) {\r\n defines[\"USE_EXACT_SRGB_CONVERSIONS\"] = \"\";\r\n } else {\r\n delete defines[\"USE_EXACT_SRGB_CONVERSIONS\"];\r\n }\r\n return;\r\n } else {\r\n let s = \"\";\r\n if (this.isNDCHalfZRange) {\r\n s += \"#define IS_NDC_HALF_ZRANGE\";\r\n }\r\n if (this.useReverseDepthBuffer) {\r\n if (s) {\r\n s += \"\\n\";\r\n }\r\n s += \"#define USE_REVERSE_DEPTHBUFFER\";\r\n }\r\n if (this.useExactSrgbConversions) {\r\n if (s) {\r\n s += \"\\n\";\r\n }\r\n s += \"#define USE_EXACT_SRGB_CONVERSIONS\";\r\n }\r\n return s;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new effect (used to store vertex/fragment shaders)\r\n * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)\r\n * @param attributesNamesOrOptions defines either a list of attribute names or an IEffectCreationOptions object\r\n * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use\r\n * @param samplers defines an array of string used to represent textures\r\n * @param defines defines the string containing the defines to use to compile the shaders\r\n * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails\r\n * @param onCompiled defines a function to call when the effect creation is successful\r\n * @param onError defines a function to call when the effect creation has failed\r\n * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)\r\n * @param shaderLanguage the language the shader is written in (default: GLSL)\r\n * @returns the new Effect\r\n */\r\n public createEffect(\r\n baseName: any,\r\n attributesNamesOrOptions: string[] | IEffectCreationOptions,\r\n uniformsNamesOrEngine: string[] | ThinEngine,\r\n samplers?: string[],\r\n defines?: string,\r\n fallbacks?: IEffectFallbacks,\r\n onCompiled?: Nullable<(effect: Effect) => void>,\r\n onError?: Nullable<(effect: Effect, errors: string) => void>,\r\n indexParameters?: any,\r\n shaderLanguage = ShaderLanguage.GLSL\r\n ): Effect {\r\n const vertex = baseName.vertexElement || baseName.vertex || baseName.vertexToken || baseName.vertexSource || baseName;\r\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.fragmentToken || baseName.fragmentSource || baseName;\r\n const globalDefines = this._getGlobalDefines()!;\r\n\r\n let fullDefines = defines ?? (attributesNamesOrOptions).defines ?? \"\";\r\n\r\n if (globalDefines) {\r\n fullDefines += globalDefines;\r\n }\r\n\r\n const name = vertex + \"+\" + fragment + \"@\" + fullDefines;\r\n if (this._compiledEffects[name]) {\r\n const compiledEffect = this._compiledEffects[name];\r\n if (onCompiled && compiledEffect.isReady()) {\r\n onCompiled(compiledEffect);\r\n }\r\n\r\n return compiledEffect;\r\n }\r\n const effect = new Effect(\r\n baseName,\r\n attributesNamesOrOptions,\r\n uniformsNamesOrEngine,\r\n samplers,\r\n this,\r\n defines,\r\n fallbacks,\r\n onCompiled,\r\n onError,\r\n indexParameters,\r\n name,\r\n shaderLanguage\r\n );\r\n this._compiledEffects[name] = effect;\r\n\r\n return effect;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _ConcatenateShader(source: string, defines: Nullable, shaderVersion: string = \"\"): string {\r\n return shaderVersion + (defines ? defines + \"\\n\" : \"\") + source;\r\n }\r\n\r\n private _compileShader(source: string, type: string, defines: Nullable, shaderVersion: string): WebGLShader {\r\n return this._compileRawShader(ThinEngine._ConcatenateShader(source, defines, shaderVersion), type);\r\n }\r\n\r\n private _compileRawShader(source: string, type: string): WebGLShader {\r\n const gl = this._gl;\r\n\r\n const shader = gl.createShader(type === \"vertex\" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);\r\n\r\n if (!shader) {\r\n let error: GLenum = gl.NO_ERROR;\r\n let tempError: GLenum = gl.NO_ERROR;\r\n while ((tempError = gl.getError()) !== gl.NO_ERROR) {\r\n error = tempError;\r\n }\r\n\r\n throw new Error(\r\n `Something went wrong while creating a gl ${type} shader object. gl error=${error}, gl isContextLost=${gl.isContextLost()}, _contextWasLost=${this._contextWasLost}`\r\n );\r\n }\r\n\r\n gl.shaderSource(shader, source);\r\n gl.compileShader(shader);\r\n\r\n return shader;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getShaderSource(shader: WebGLShader): Nullable {\r\n return this._gl.getShaderSource(shader);\r\n }\r\n\r\n /**\r\n * Directly creates a webGL program\r\n * @param pipelineContext defines the pipeline context to attach to\r\n * @param vertexCode defines the vertex shader code to use\r\n * @param fragmentCode defines the fragment shader code to use\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\r\n * @returns the new webGL program\r\n */\r\n public createRawShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n context?: WebGLRenderingContext,\r\n transformFeedbackVaryings: Nullable = null\r\n ): WebGLProgram {\r\n context = context || this._gl;\r\n\r\n const vertexShader = this._compileRawShader(vertexCode, \"vertex\");\r\n const fragmentShader = this._compileRawShader(fragmentCode, \"fragment\");\r\n\r\n return this._createShaderProgram(pipelineContext as WebGLPipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings);\r\n }\r\n\r\n /**\r\n * Creates a webGL program\r\n * @param pipelineContext defines the pipeline context to attach to\r\n * @param vertexCode defines the vertex shader code to use\r\n * @param fragmentCode defines the fragment shader code to use\r\n * @param defines defines the string containing the defines to use to compile the shaders\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\r\n * @returns the new webGL program\r\n */\r\n public createShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n defines: Nullable,\r\n context?: WebGLRenderingContext,\r\n transformFeedbackVaryings: Nullable = null\r\n ): WebGLProgram {\r\n context = context || this._gl;\r\n\r\n const shaderVersion = this._webGLVersion > 1 ? \"#version 300 es\\n#define WEBGL2 \\n\" : \"\";\r\n const vertexShader = this._compileShader(vertexCode, \"vertex\", defines, shaderVersion);\r\n const fragmentShader = this._compileShader(fragmentCode, \"fragment\", defines, shaderVersion);\r\n\r\n return this._createShaderProgram(pipelineContext as WebGLPipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings);\r\n }\r\n\r\n /**\r\n * Inline functions in shader code that are marked to be inlined\r\n * @param code code to inline\r\n * @returns inlined code\r\n */\r\n public inlineShaderCode(code: string): string {\r\n // no inlining needed in the WebGL engine\r\n return code;\r\n }\r\n\r\n /**\r\n * Creates a new pipeline context\r\n * @param shaderProcessingContext defines the shader processing context used during the processing if available\r\n * @returns the new pipeline\r\n */\r\n public createPipelineContext(shaderProcessingContext: Nullable): IPipelineContext {\r\n const pipelineContext = new WebGLPipelineContext();\r\n pipelineContext.engine = this;\r\n\r\n if (this._caps.parallelShaderCompile) {\r\n pipelineContext.isParallelCompiled = true;\r\n }\r\n\r\n return pipelineContext;\r\n }\r\n\r\n /**\r\n * Creates a new material context\r\n * @returns the new context\r\n */\r\n public createMaterialContext(): IMaterialContext | undefined {\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Creates a new draw context\r\n * @returns the new context\r\n */\r\n public createDrawContext(): IDrawContext | undefined {\r\n return undefined;\r\n }\r\n\r\n protected _createShaderProgram(\r\n pipelineContext: WebGLPipelineContext,\r\n vertexShader: WebGLShader,\r\n fragmentShader: WebGLShader,\r\n context: WebGLRenderingContext,\r\n transformFeedbackVaryings: Nullable = null\r\n ): WebGLProgram {\r\n const shaderProgram = context.createProgram();\r\n pipelineContext.program = shaderProgram;\r\n\r\n if (!shaderProgram) {\r\n throw new Error(\"Unable to create program\");\r\n }\r\n\r\n context.attachShader(shaderProgram, vertexShader);\r\n context.attachShader(shaderProgram, fragmentShader);\r\n\r\n context.linkProgram(shaderProgram);\r\n\r\n pipelineContext.context = context;\r\n pipelineContext.vertexShader = vertexShader;\r\n pipelineContext.fragmentShader = fragmentShader;\r\n\r\n if (!pipelineContext.isParallelCompiled) {\r\n this._finalizePipelineContext(pipelineContext);\r\n }\r\n\r\n return shaderProgram;\r\n }\r\n\r\n protected _finalizePipelineContext(pipelineContext: WebGLPipelineContext) {\r\n const context = pipelineContext.context!;\r\n const vertexShader = pipelineContext.vertexShader!;\r\n const fragmentShader = pipelineContext.fragmentShader!;\r\n const program = pipelineContext.program!;\r\n\r\n const linked = context.getProgramParameter(program, context.LINK_STATUS);\r\n if (!linked) {\r\n // Get more info\r\n // Vertex\r\n if (!this._gl.getShaderParameter(vertexShader, this._gl.COMPILE_STATUS)) {\r\n const log = this._gl.getShaderInfoLog(vertexShader);\r\n if (log) {\r\n pipelineContext.vertexCompilationError = log;\r\n throw new Error(\"VERTEX SHADER \" + log);\r\n }\r\n }\r\n\r\n // Fragment\r\n if (!this._gl.getShaderParameter(fragmentShader, this._gl.COMPILE_STATUS)) {\r\n const log = this._gl.getShaderInfoLog(fragmentShader);\r\n if (log) {\r\n pipelineContext.fragmentCompilationError = log;\r\n throw new Error(\"FRAGMENT SHADER \" + log);\r\n }\r\n }\r\n\r\n const error = context.getProgramInfoLog(program);\r\n if (error) {\r\n pipelineContext.programLinkError = error;\r\n throw new Error(error);\r\n }\r\n }\r\n\r\n if (this.validateShaderPrograms) {\r\n context.validateProgram(program);\r\n const validated = context.getProgramParameter(program, context.VALIDATE_STATUS);\r\n\r\n if (!validated) {\r\n const error = context.getProgramInfoLog(program);\r\n if (error) {\r\n pipelineContext.programValidationError = error;\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n context.deleteShader(vertexShader);\r\n context.deleteShader(fragmentShader);\r\n\r\n pipelineContext.vertexShader = undefined;\r\n pipelineContext.fragmentShader = undefined;\r\n\r\n if (pipelineContext.onCompiled) {\r\n pipelineContext.onCompiled();\r\n pipelineContext.onCompiled = undefined;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _preparePipelineContext(\r\n pipelineContext: IPipelineContext,\r\n vertexSourceCode: string,\r\n fragmentSourceCode: string,\r\n createAsRaw: boolean,\r\n rawVertexSourceCode: string,\r\n rawFragmentSourceCode: string,\r\n rebuildRebind: any,\r\n defines: Nullable,\r\n transformFeedbackVaryings: Nullable,\r\n key: string\r\n ) {\r\n const webGLRenderingState = pipelineContext as WebGLPipelineContext;\r\n\r\n if (createAsRaw) {\r\n webGLRenderingState.program = this.createRawShaderProgram(webGLRenderingState, vertexSourceCode, fragmentSourceCode, undefined, transformFeedbackVaryings);\r\n } else {\r\n webGLRenderingState.program = this.createShaderProgram(webGLRenderingState, vertexSourceCode, fragmentSourceCode, defines, undefined, transformFeedbackVaryings);\r\n }\r\n webGLRenderingState.program.__SPECTOR_rebuildProgram = rebuildRebind;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _isRenderingStateCompiled(pipelineContext: IPipelineContext): boolean {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n if (this._isDisposed || webGLPipelineContext._isDisposed) {\r\n return false;\r\n }\r\n if (this._gl.getProgramParameter(webGLPipelineContext.program!, this._caps.parallelShaderCompile!.COMPLETION_STATUS_KHR)) {\r\n this._finalizePipelineContext(webGLPipelineContext);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _executeWhenRenderingStateIsCompiled(pipelineContext: IPipelineContext, action: () => void) {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n\r\n if (!webGLPipelineContext.isParallelCompiled) {\r\n action();\r\n return;\r\n }\r\n\r\n const oldHandler = webGLPipelineContext.onCompiled;\r\n\r\n if (oldHandler) {\r\n webGLPipelineContext.onCompiled = () => {\r\n oldHandler!();\r\n action();\r\n };\r\n } else {\r\n webGLPipelineContext.onCompiled = action;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names\r\n * @param pipelineContext defines the pipeline context to use\r\n * @param uniformsNames defines the list of uniform names\r\n * @returns an array of webGL uniform locations\r\n */\r\n public getUniforms(pipelineContext: IPipelineContext, uniformsNames: string[]): Nullable[] {\r\n const results = new Array>();\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n\r\n for (let index = 0; index < uniformsNames.length; index++) {\r\n results.push(this._gl.getUniformLocation(webGLPipelineContext.program!, uniformsNames[index]));\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Gets the list of active attributes for a given webGL program\r\n * @param pipelineContext defines the pipeline context to use\r\n * @param attributesNames defines the list of attribute names to get\r\n * @returns an array of indices indicating the offset of each attribute\r\n */\r\n public getAttributes(pipelineContext: IPipelineContext, attributesNames: string[]): number[] {\r\n const results = [];\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n\r\n for (let index = 0; index < attributesNames.length; index++) {\r\n try {\r\n results.push(this._gl.getAttribLocation(webGLPipelineContext.program!, attributesNames[index]));\r\n } catch (e) {\r\n results.push(-1);\r\n }\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Activates an effect, making it the current one (ie. the one used for rendering)\r\n * @param effect defines the effect to activate\r\n */\r\n public enableEffect(effect: Nullable): void {\r\n effect = effect !== null && DrawWrapper.IsWrapper(effect) ? effect.effect : effect; // get only the effect, we don't need a Wrapper in the WebGL engine\r\n\r\n if (!effect || effect === this._currentEffect) {\r\n return;\r\n }\r\n\r\n this._stencilStateComposer.stencilMaterial = undefined;\r\n\r\n effect = effect as Effect;\r\n\r\n // Use program\r\n this.bindSamplers(effect);\r\n\r\n this._currentEffect = effect;\r\n\r\n if (effect.onBind) {\r\n effect.onBind(effect);\r\n }\r\n if (effect._onBindObservable) {\r\n effect._onBindObservable.notifyObservers(effect);\r\n }\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a number (int)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param value defines the int number to store\r\n * @returns true if the value was set\r\n */\r\n public setInt(uniform: Nullable, value: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform1i(uniform, value);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a int2\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @returns true if the value was set\r\n */\r\n public setInt2(uniform: Nullable, x: number, y: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform2i(uniform, x, y);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a int3\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @param z defines the 3rd component of the value\r\n * @returns true if the value was set\r\n */\r\n public setInt3(uniform: Nullable, x: number, y: number, z: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform3i(uniform, x, y, z);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a int4\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @param z defines the 3rd component of the value\r\n * @param w defines the 4th component of the value\r\n * @returns true if the value was set\r\n */\r\n public setInt4(uniform: Nullable, x: number, y: number, z: number, w: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform4i(uniform, x, y, z, w);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of int32\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setIntArray(uniform: Nullable, array: Int32Array): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform1iv(uniform, array);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of int32 (stored as vec2)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setIntArray2(uniform: Nullable, array: Int32Array): boolean {\r\n if (!uniform || array.length % 2 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform2iv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of int32 (stored as vec3)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setIntArray3(uniform: Nullable, array: Int32Array): boolean {\r\n if (!uniform || array.length % 3 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform3iv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of int32 (stored as vec4)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setIntArray4(uniform: Nullable, array: Int32Array): boolean {\r\n if (!uniform || array.length % 4 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform4iv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a number (unsigned int)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param value defines the unsigned int number to store\r\n * @returns true if the value was set\r\n */\r\n public setUInt(uniform: Nullable, value: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform1ui(uniform, value);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a unsigned int2\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @returns true if the value was set\r\n */\r\n public setUInt2(uniform: Nullable, x: number, y: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform2ui(uniform, x, y);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a unsigned int3\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @param z defines the 3rd component of the value\r\n * @returns true if the value was set\r\n */\r\n public setUInt3(uniform: Nullable, x: number, y: number, z: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform3ui(uniform, x, y, z);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a unsigned int4\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @param z defines the 3rd component of the value\r\n * @param w defines the 4th component of the value\r\n * @returns true if the value was set\r\n */\r\n public setUInt4(uniform: Nullable, x: number, y: number, z: number, w: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform4ui(uniform, x, y, z, w);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of unsigned int32\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of unsigned int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setUIntArray(uniform: Nullable, array: Uint32Array): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform1uiv(uniform, array);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of unsigned int32 (stored as vec2)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of unsigned int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setUIntArray2(uniform: Nullable, array: Uint32Array): boolean {\r\n if (!uniform || array.length % 2 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform2uiv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of unsigned int32 (stored as vec3)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of unsigned int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setUIntArray3(uniform: Nullable, array: Uint32Array): boolean {\r\n if (!uniform || array.length % 3 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform3uiv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of unsigned int32 (stored as vec4)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of unsigned int32 to store\r\n * @returns true if the value was set\r\n */\r\n public setUIntArray4(uniform: Nullable, array: Uint32Array): boolean {\r\n if (!uniform || array.length % 4 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform4uiv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of number\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of number to store\r\n * @returns true if the value was set\r\n */\r\n public setArray(uniform: Nullable, array: number[] | Float32Array): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n if (array.length < 1) {\r\n return false;\r\n }\r\n this._gl.uniform1fv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of number (stored as vec2)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of number to store\r\n * @returns true if the value was set\r\n */\r\n public setArray2(uniform: Nullable, array: number[] | Float32Array): boolean {\r\n if (!uniform || array.length % 2 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform2fv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of number (stored as vec3)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of number to store\r\n * @returns true if the value was set\r\n */\r\n public setArray3(uniform: Nullable, array: number[] | Float32Array): boolean {\r\n if (!uniform || array.length % 3 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform3fv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of number (stored as vec4)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param array defines the array of number to store\r\n * @returns true if the value was set\r\n */\r\n public setArray4(uniform: Nullable, array: number[] | Float32Array): boolean {\r\n if (!uniform || array.length % 4 !== 0) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform4fv(uniform, array);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to an array of float32 (stored as matrices)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param matrices defines the array of float32 to store\r\n * @returns true if the value was set\r\n */\r\n public setMatrices(uniform: Nullable, matrices: Float32Array): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniformMatrix4fv(uniform, false, matrices);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a matrix (3x3)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param matrix defines the Float32Array representing the 3x3 matrix to store\r\n * @returns true if the value was set\r\n */\r\n public setMatrix3x3(uniform: Nullable, matrix: Float32Array): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniformMatrix3fv(uniform, false, matrix);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a matrix (2x2)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param matrix defines the Float32Array representing the 2x2 matrix to store\r\n * @returns true if the value was set\r\n */\r\n public setMatrix2x2(uniform: Nullable, matrix: Float32Array): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniformMatrix2fv(uniform, false, matrix);\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a number (float)\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param value defines the float number to store\r\n * @returns true if the value was transferred\r\n */\r\n public setFloat(uniform: Nullable, value: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform1f(uniform, value);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a vec2\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @returns true if the value was set\r\n */\r\n public setFloat2(uniform: Nullable, x: number, y: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform2f(uniform, x, y);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a vec3\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @param z defines the 3rd component of the value\r\n * @returns true if the value was set\r\n */\r\n public setFloat3(uniform: Nullable, x: number, y: number, z: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform3f(uniform, x, y, z);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Set the value of an uniform to a vec4\r\n * @param uniform defines the webGL uniform location where to store the value\r\n * @param x defines the 1st component of the value\r\n * @param y defines the 2nd component of the value\r\n * @param z defines the 3rd component of the value\r\n * @param w defines the 4th component of the value\r\n * @returns true if the value was set\r\n */\r\n public setFloat4(uniform: Nullable, x: number, y: number, z: number, w: number): boolean {\r\n if (!uniform) {\r\n return false;\r\n }\r\n\r\n this._gl.uniform4f(uniform, x, y, z, w);\r\n\r\n return true;\r\n }\r\n\r\n // States\r\n\r\n /**\r\n * Apply all cached states (depth, culling, stencil and alpha)\r\n */\r\n public applyStates() {\r\n this._depthCullingState.apply(this._gl);\r\n this._stencilStateComposer.apply(this._gl);\r\n this._alphaState.apply(this._gl);\r\n\r\n if (this._colorWriteChanged) {\r\n this._colorWriteChanged = false;\r\n const enable = this._colorWrite;\r\n this._gl.colorMask(enable, enable, enable, enable);\r\n }\r\n }\r\n\r\n /**\r\n * Enable or disable color writing\r\n * @param enable defines the state to set\r\n */\r\n public setColorWrite(enable: boolean): void {\r\n if (enable !== this._colorWrite) {\r\n this._colorWriteChanged = true;\r\n this._colorWrite = enable;\r\n }\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if color writing is enabled\r\n * @returns the current color writing state\r\n */\r\n public getColorWrite(): boolean {\r\n return this._colorWrite;\r\n }\r\n\r\n /**\r\n * Gets the depth culling state manager\r\n */\r\n public get depthCullingState(): DepthCullingState {\r\n return this._depthCullingState;\r\n }\r\n\r\n /**\r\n * Gets the alpha state manager\r\n */\r\n public get alphaState(): AlphaState {\r\n return this._alphaState;\r\n }\r\n\r\n /**\r\n * Gets the stencil state manager\r\n */\r\n public get stencilState(): StencilState {\r\n return this._stencilState;\r\n }\r\n\r\n /**\r\n * Gets the stencil state composer\r\n */\r\n public get stencilStateComposer(): StencilStateComposer {\r\n return this._stencilStateComposer;\r\n }\r\n\r\n // Textures\r\n\r\n /**\r\n * Clears the list of texture accessible through engine.\r\n * This can help preventing texture load conflict due to name collision.\r\n */\r\n public clearInternalTexturesCache() {\r\n this._internalTexturesCache.length = 0;\r\n }\r\n\r\n /**\r\n * Force the entire cache to be cleared\r\n * You should not have to use this function unless your engine needs to share the webGL context with another engine\r\n * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)\r\n */\r\n public wipeCaches(bruteForce?: boolean): void {\r\n if (this.preventCacheWipeBetweenFrames && !bruteForce) {\r\n return;\r\n }\r\n this._currentEffect = null;\r\n this._viewportCached.x = 0;\r\n this._viewportCached.y = 0;\r\n this._viewportCached.z = 0;\r\n this._viewportCached.w = 0;\r\n\r\n // Done before in case we clean the attributes\r\n this._unbindVertexArrayObject();\r\n\r\n if (bruteForce) {\r\n this._currentProgram = null;\r\n this.resetTextureCache();\r\n\r\n this._stencilStateComposer.reset();\r\n\r\n this._depthCullingState.reset();\r\n this._depthCullingState.depthFunc = this._gl.LEQUAL;\r\n\r\n this._alphaState.reset();\r\n this._alphaMode = Constants.ALPHA_ADD;\r\n this._alphaEquation = Constants.ALPHA_DISABLE;\r\n\r\n this._colorWrite = true;\r\n this._colorWriteChanged = true;\r\n\r\n this._unpackFlipYCached = null;\r\n\r\n this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);\r\n this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);\r\n\r\n this._mustWipeVertexAttributes = true;\r\n this.unbindAllAttributes();\r\n }\r\n\r\n this._resetVertexBufferBinding();\r\n this._cachedIndexBuffer = null;\r\n this._cachedEffectForVertexBuffers = null;\r\n this.bindIndexBuffer(null);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getSamplingParameters(samplingMode: number, generateMipMaps: boolean): { min: number; mag: number } {\r\n const gl = this._gl;\r\n let magFilter: GLenum = gl.NEAREST;\r\n let minFilter: GLenum = gl.NEAREST;\r\n\r\n switch (samplingMode) {\r\n case Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST:\r\n magFilter = gl.LINEAR;\r\n if (generateMipMaps) {\r\n minFilter = gl.LINEAR_MIPMAP_NEAREST;\r\n } else {\r\n minFilter = gl.LINEAR;\r\n }\r\n break;\r\n case Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR:\r\n magFilter = gl.LINEAR;\r\n if (generateMipMaps) {\r\n minFilter = gl.LINEAR_MIPMAP_LINEAR;\r\n } else {\r\n minFilter = gl.LINEAR;\r\n }\r\n break;\r\n case Constants.TEXTURE_NEAREST_NEAREST_MIPLINEAR:\r\n magFilter = gl.NEAREST;\r\n if (generateMipMaps) {\r\n minFilter = gl.NEAREST_MIPMAP_LINEAR;\r\n } else {\r\n minFilter = gl.NEAREST;\r\n }\r\n break;\r\n case Constants.TEXTURE_NEAREST_NEAREST_MIPNEAREST:\r\n magFilter = gl.NEAREST;\r\n if (generateMipMaps) {\r\n minFilter = gl.NEAREST_MIPMAP_NEAREST;\r\n } else {\r\n minFilter = gl.NEAREST;\r\n }\r\n break;\r\n case Constants.TEXTURE_NEAREST_LINEAR_MIPNEAREST:\r\n magFilter = gl.NEAREST;\r\n if (generateMipMaps) {\r\n minFilter = gl.LINEAR_MIPMAP_NEAREST;\r\n } else {\r\n minFilter = gl.LINEAR;\r\n }\r\n break;\r\n case Constants.TEXTURE_NEAREST_LINEAR_MIPLINEAR:\r\n magFilter = gl.NEAREST;\r\n if (generateMipMaps) {\r\n minFilter = gl.LINEAR_MIPMAP_LINEAR;\r\n } else {\r\n minFilter = gl.LINEAR;\r\n }\r\n break;\r\n case Constants.TEXTURE_NEAREST_LINEAR:\r\n magFilter = gl.NEAREST;\r\n minFilter = gl.LINEAR;\r\n break;\r\n case Constants.TEXTURE_NEAREST_NEAREST:\r\n magFilter = gl.NEAREST;\r\n minFilter = gl.NEAREST;\r\n break;\r\n case Constants.TEXTURE_LINEAR_NEAREST_MIPNEAREST:\r\n magFilter = gl.LINEAR;\r\n if (generateMipMaps) {\r\n minFilter = gl.NEAREST_MIPMAP_NEAREST;\r\n } else {\r\n minFilter = gl.NEAREST;\r\n }\r\n break;\r\n case Constants.TEXTURE_LINEAR_NEAREST_MIPLINEAR:\r\n magFilter = gl.LINEAR;\r\n if (generateMipMaps) {\r\n minFilter = gl.NEAREST_MIPMAP_LINEAR;\r\n } else {\r\n minFilter = gl.NEAREST;\r\n }\r\n break;\r\n case Constants.TEXTURE_LINEAR_LINEAR:\r\n magFilter = gl.LINEAR;\r\n minFilter = gl.LINEAR;\r\n break;\r\n case Constants.TEXTURE_LINEAR_NEAREST:\r\n magFilter = gl.LINEAR;\r\n minFilter = gl.NEAREST;\r\n break;\r\n }\r\n\r\n return {\r\n min: minFilter,\r\n mag: magFilter,\r\n };\r\n }\r\n\r\n /** @internal */\r\n protected _createTexture(): WebGLTexture {\r\n const texture = this._gl.createTexture();\r\n\r\n if (!texture) {\r\n throw new Error(\"Unable to create texture\");\r\n }\r\n\r\n return texture;\r\n }\r\n\r\n /** @internal */\r\n public _createHardwareTexture(): HardwareTextureWrapper {\r\n return new WebGLHardwareTexture(this._createTexture(), this._gl);\r\n }\r\n\r\n /**\r\n * Creates an internal texture without binding it to a framebuffer\r\n * @internal\r\n * @param size defines the size of the texture\r\n * @param options defines the options used to create the texture\r\n * @param delayGPUTextureCreation true to delay the texture creation the first time it is really needed. false to create it right away\r\n * @param source source type of the texture\r\n * @returns a new internal texture\r\n */\r\n public _createInternalTexture(\r\n size: TextureSize,\r\n options: boolean | InternalTextureCreationOptions,\r\n delayGPUTextureCreation = true,\r\n source = InternalTextureSource.Unknown\r\n ): InternalTexture {\r\n let generateMipMaps = false;\r\n let type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n let samplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;\r\n let format = Constants.TEXTUREFORMAT_RGBA;\r\n let useSRGBBuffer = false;\r\n let samples = 1;\r\n let label: string | undefined;\r\n if (options !== undefined && typeof options === \"object\") {\r\n generateMipMaps = !!options.generateMipMaps;\r\n type = options.type === undefined ? Constants.TEXTURETYPE_UNSIGNED_INT : options.type;\r\n samplingMode = options.samplingMode === undefined ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : options.samplingMode;\r\n format = options.format === undefined ? Constants.TEXTUREFORMAT_RGBA : options.format;\r\n useSRGBBuffer = options.useSRGBBuffer === undefined ? false : options.useSRGBBuffer;\r\n samples = options.samples ?? 1;\r\n label = options.label;\r\n } else {\r\n generateMipMaps = !!options;\r\n }\r\n\r\n useSRGBBuffer &&= this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU);\r\n\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {\r\n // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n } else if (type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {\r\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n Logger.Warn(\"Float textures are not supported. Type forced to TEXTURETYPE_UNSIGNED_BYTE\");\r\n }\r\n\r\n const gl = this._gl;\r\n const texture = new InternalTexture(this, source);\r\n const width = (<{ width: number; height: number; layers?: number }>size).width || size;\r\n const height = (<{ width: number; height: number; layers?: number }>size).height || size;\r\n const layers = (<{ width: number; height: number; layers?: number }>size).layers || 0;\r\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\r\n const target = layers !== 0 ? gl.TEXTURE_2D_ARRAY : gl.TEXTURE_2D;\r\n const sizedFormat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);\r\n const internalFormat = this._getInternalFormat(format);\r\n const textureType = this._getWebGLTextureType(type);\r\n\r\n // Bind\r\n this._bindTextureDirectly(target, texture);\r\n\r\n if (layers !== 0) {\r\n texture.is2DArray = true;\r\n gl.texImage3D(target, 0, sizedFormat, width, height, layers, 0, internalFormat, textureType, null);\r\n } else {\r\n gl.texImage2D(target, 0, sizedFormat, width, height, 0, internalFormat, textureType, null);\r\n }\r\n\r\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, filters.mag);\r\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, filters.min);\r\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n\r\n // MipMaps\r\n if (generateMipMaps) {\r\n this._gl.generateMipmap(target);\r\n }\r\n\r\n this._bindTextureDirectly(target, null);\r\n\r\n texture._useSRGBBuffer = useSRGBBuffer;\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n texture.width = width;\r\n texture.height = height;\r\n texture.depth = layers;\r\n texture.isReady = true;\r\n texture.samples = samples;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n texture.type = type;\r\n texture.format = format;\r\n texture.label = label;\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n return texture;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getUseSRGBBuffer(useSRGBBuffer: boolean, noMipmap: boolean): boolean {\r\n // Generating mipmaps for sRGB textures is not supported in WebGL1 so we must disable the support if mipmaps is enabled\r\n return useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU || noMipmap);\r\n }\r\n\r\n protected _createTextureBase(\r\n url: Nullable,\r\n noMipmap: boolean,\r\n invertY: boolean,\r\n scene: Nullable,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n onLoad: Nullable<(texture: InternalTexture) => void> = null,\r\n onError: Nullable<(message: string, exception: any) => void> = null,\r\n prepareTexture: (\r\n texture: InternalTexture,\r\n extension: string,\r\n scene: Nullable,\r\n img: HTMLImageElement | ImageBitmap | { width: number; height: number },\r\n invertY: boolean,\r\n noMipmap: boolean,\r\n isCompressed: boolean,\r\n processFunction: (\r\n width: number,\r\n height: number,\r\n img: HTMLImageElement | ImageBitmap | { width: number; height: number },\r\n extension: string,\r\n texture: InternalTexture,\r\n continuationCallback: () => void\r\n ) => boolean,\r\n samplingMode: number\r\n ) => void,\r\n prepareTextureProcessFunction: (\r\n width: number,\r\n height: number,\r\n img: HTMLImageElement | ImageBitmap | { width: number; height: number },\r\n extension: string,\r\n texture: InternalTexture,\r\n continuationCallback: () => void\r\n ) => boolean,\r\n buffer: Nullable = null,\r\n fallback: Nullable = null,\r\n format: Nullable = null,\r\n forcedExtension: Nullable = null,\r\n mimeType?: string,\r\n loaderOptions?: any,\r\n useSRGBBuffer?: boolean\r\n ): InternalTexture {\r\n url = url || \"\";\r\n const fromData = url.substr(0, 5) === \"data:\";\r\n const fromBlob = url.substr(0, 5) === \"blob:\";\r\n const isBase64 = fromData && url.indexOf(\";base64,\") !== -1;\r\n\r\n const texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Url);\r\n\r\n if (texture !== fallback) {\r\n texture.label = url.substring(0, 60); // default label, can be overriden by the caller\r\n }\r\n\r\n const originalUrl = url;\r\n if (this._transformTextureUrl && !isBase64 && !fallback && !buffer) {\r\n url = this._transformTextureUrl(url);\r\n }\r\n\r\n if (originalUrl !== url) {\r\n texture._originalUrl = originalUrl;\r\n }\r\n\r\n // establish the file extension, if possible\r\n const lastDot = url.lastIndexOf(\".\");\r\n let extension = forcedExtension ? forcedExtension : lastDot > -1 ? url.substring(lastDot).toLowerCase() : \"\";\r\n let loader: Nullable = null;\r\n\r\n // Remove query string\r\n const queryStringIndex = extension.indexOf(\"?\");\r\n\r\n if (queryStringIndex > -1) {\r\n extension = extension.split(\"?\")[0];\r\n }\r\n\r\n for (const availableLoader of ThinEngine._TextureLoaders) {\r\n if (availableLoader.canLoad(extension, mimeType)) {\r\n loader = availableLoader;\r\n break;\r\n }\r\n }\r\n\r\n if (scene) {\r\n scene.addPendingData(texture);\r\n }\r\n texture.url = url;\r\n texture.generateMipMaps = !noMipmap;\r\n texture.samplingMode = samplingMode;\r\n texture.invertY = invertY;\r\n texture._useSRGBBuffer = this._getUseSRGBBuffer(!!useSRGBBuffer, noMipmap);\r\n\r\n if (!this._doNotHandleContextLost) {\r\n // Keep a link to the buffer only if we plan to handle context lost\r\n texture._buffer = buffer;\r\n }\r\n\r\n let onLoadObserver: Nullable> = null;\r\n if (onLoad && !fallback) {\r\n onLoadObserver = texture.onLoadedObservable.add(onLoad);\r\n }\r\n\r\n if (!fallback) {\r\n this._internalTexturesCache.push(texture);\r\n }\r\n\r\n const onInternalError = (message?: string, exception?: any) => {\r\n if (scene) {\r\n scene.removePendingData(texture);\r\n }\r\n\r\n if (url === originalUrl) {\r\n if (onLoadObserver) {\r\n texture.onLoadedObservable.remove(onLoadObserver);\r\n }\r\n\r\n if (EngineStore.UseFallbackTexture) {\r\n this._createTextureBase(\r\n EngineStore.FallbackTexture,\r\n noMipmap,\r\n texture.invertY,\r\n scene,\r\n samplingMode,\r\n null,\r\n onError,\r\n prepareTexture,\r\n prepareTextureProcessFunction,\r\n buffer,\r\n texture\r\n );\r\n }\r\n\r\n message = (message || \"Unknown error\") + (EngineStore.UseFallbackTexture ? \" - Fallback texture was used\" : \"\");\r\n texture.onErrorObservable.notifyObservers({ message, exception });\r\n if (onError) {\r\n onError(message, exception);\r\n }\r\n } else {\r\n // fall back to the original url if the transformed url fails to load\r\n Logger.Warn(`Failed to load ${url}, falling back to ${originalUrl}`);\r\n this._createTextureBase(\r\n originalUrl,\r\n noMipmap,\r\n texture.invertY,\r\n scene,\r\n samplingMode,\r\n onLoad,\r\n onError,\r\n prepareTexture,\r\n prepareTextureProcessFunction,\r\n buffer,\r\n texture,\r\n format,\r\n forcedExtension,\r\n mimeType,\r\n loaderOptions,\r\n useSRGBBuffer\r\n );\r\n }\r\n };\r\n\r\n // processing for non-image formats\r\n if (loader) {\r\n const callback = (data: ArrayBufferView) => {\r\n loader!.loadData(\r\n data,\r\n texture,\r\n (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void, loadFailed) => {\r\n if (loadFailed) {\r\n onInternalError(\"TextureLoader failed to load data\");\r\n } else {\r\n prepareTexture(\r\n texture,\r\n extension,\r\n scene,\r\n { width, height },\r\n texture.invertY,\r\n !loadMipmap,\r\n isCompressed,\r\n () => {\r\n done();\r\n return false;\r\n },\r\n samplingMode\r\n );\r\n }\r\n },\r\n loaderOptions\r\n );\r\n };\r\n\r\n if (!buffer) {\r\n this._loadFile(\r\n url,\r\n (data) => callback(new Uint8Array(data as ArrayBuffer)),\r\n undefined,\r\n scene ? scene.offlineProvider : undefined,\r\n true,\r\n (request?: IWebRequest, exception?: any) => {\r\n onInternalError(\"Unable to load \" + (request ? request.responseURL : url, exception));\r\n }\r\n );\r\n } else {\r\n if (buffer instanceof ArrayBuffer) {\r\n callback(new Uint8Array(buffer));\r\n } else if (ArrayBuffer.isView(buffer)) {\r\n callback(buffer);\r\n } else {\r\n if (onError) {\r\n onError(\"Unable to load: only ArrayBuffer or ArrayBufferView is supported\", null);\r\n }\r\n }\r\n }\r\n } else {\r\n const onload = (img: HTMLImageElement | ImageBitmap) => {\r\n if (fromBlob && !this._doNotHandleContextLost) {\r\n // We need to store the image if we need to rebuild the texture\r\n // in case of a webgl context lost\r\n texture._buffer = img;\r\n }\r\n\r\n prepareTexture(texture, extension, scene, img, texture.invertY, noMipmap, false, prepareTextureProcessFunction, samplingMode);\r\n };\r\n // According to the WebGL spec section 6.10, ImageBitmaps must be inverted on creation.\r\n // So, we pass imageOrientation to _FileToolsLoadImage() as it may create an ImageBitmap.\r\n\r\n if (!fromData || isBase64) {\r\n if (buffer && (typeof (buffer).decoding === \"string\" || (buffer).close)) {\r\n onload(buffer);\r\n } else {\r\n ThinEngine._FileToolsLoadImage(\r\n url,\r\n onload,\r\n onInternalError,\r\n scene ? scene.offlineProvider : null,\r\n mimeType,\r\n texture.invertY && this._features.needsInvertingBitmap ? { imageOrientation: \"flipY\" } : undefined\r\n );\r\n }\r\n } else if (typeof buffer === \"string\" || buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer) || buffer instanceof Blob) {\r\n ThinEngine._FileToolsLoadImage(\r\n buffer,\r\n onload,\r\n onInternalError,\r\n scene ? scene.offlineProvider : null,\r\n mimeType,\r\n texture.invertY && this._features.needsInvertingBitmap ? { imageOrientation: \"flipY\" } : undefined\r\n );\r\n } else if (buffer) {\r\n onload(buffer);\r\n }\r\n }\r\n\r\n return texture;\r\n }\r\n\r\n /**\r\n * Usually called from Texture.ts.\r\n * Passed information to create a WebGLTexture\r\n * @param url defines a value which contains one of the following:\r\n * * A conventional http URL, e.g. 'http://...' or 'file://...'\r\n * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'\r\n * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'\r\n * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file\r\n * @param invertY when true, image is flipped when loaded. You probably want true. Certain compressed textures may invert this if their default is inverted (eg. ktx)\r\n * @param scene needed for loading to the correct scene\r\n * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)\r\n * @param onLoad optional callback to be called upon successful completion\r\n * @param onError optional callback to be called upon failure\r\n * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob\r\n * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities\r\n * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n * @param mimeType defines an optional mime type\r\n * @param loaderOptions options to be passed to the loader\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns a InternalTexture for assignment back into BABYLON.Texture\r\n */\r\n public createTexture(\r\n url: Nullable,\r\n noMipmap: boolean,\r\n invertY: boolean,\r\n scene: Nullable,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n onLoad: Nullable<(texture: InternalTexture) => void> = null,\r\n onError: Nullable<(message: string, exception: any) => void> = null,\r\n buffer: Nullable = null,\r\n fallback: Nullable = null,\r\n format: Nullable = null,\r\n forcedExtension: Nullable = null,\r\n mimeType?: string,\r\n loaderOptions?: any,\r\n creationFlags?: number,\r\n useSRGBBuffer?: boolean\r\n ): InternalTexture {\r\n return this._createTextureBase(\r\n url,\r\n noMipmap,\r\n invertY,\r\n scene,\r\n samplingMode,\r\n onLoad,\r\n onError,\r\n this._prepareWebGLTexture.bind(this),\r\n (potWidth, potHeight, img, extension, texture, continuationCallback) => {\r\n const gl = this._gl;\r\n const isPot = img.width === potWidth && img.height === potHeight;\r\n\r\n const internalFormat = format\r\n ? this._getInternalFormat(format, texture._useSRGBBuffer)\r\n : extension === \".jpg\" && !texture._useSRGBBuffer\r\n ? gl.RGB\r\n : texture._useSRGBBuffer\r\n ? this._glSRGBExtensionValues.SRGB8_ALPHA8\r\n : gl.RGBA;\r\n let texelFormat = format ? this._getInternalFormat(format) : extension === \".jpg\" && !texture._useSRGBBuffer ? gl.RGB : gl.RGBA;\r\n\r\n if (texture._useSRGBBuffer && this.webGLVersion === 1) {\r\n texelFormat = internalFormat;\r\n }\r\n\r\n if (isPot) {\r\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, img as any);\r\n return false;\r\n }\r\n\r\n const maxTextureSize = this._caps.maxTextureSize;\r\n\r\n if (img.width > maxTextureSize || img.height > maxTextureSize || !this._supportsHardwareTextureRescaling) {\r\n this._prepareWorkingCanvas();\r\n if (!this._workingCanvas || !this._workingContext) {\r\n return false;\r\n }\r\n\r\n this._workingCanvas.width = potWidth;\r\n this._workingCanvas.height = potHeight;\r\n\r\n this._workingContext.drawImage(img as any, 0, 0, img.width, img.height, 0, 0, potWidth, potHeight);\r\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, this._workingCanvas as TexImageSource);\r\n\r\n texture.width = potWidth;\r\n texture.height = potHeight;\r\n\r\n return false;\r\n } else {\r\n // Using shaders when possible to rescale because canvas.drawImage is lossy\r\n const source = new InternalTexture(this, InternalTextureSource.Temp);\r\n this._bindTextureDirectly(gl.TEXTURE_2D, source, true);\r\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, img as any);\r\n\r\n this._rescaleTexture(source, texture, scene, internalFormat, () => {\r\n this._releaseTexture(source);\r\n this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);\r\n\r\n continuationCallback();\r\n });\r\n }\r\n\r\n return true;\r\n },\r\n buffer,\r\n fallback,\r\n format,\r\n forcedExtension,\r\n mimeType,\r\n loaderOptions,\r\n useSRGBBuffer\r\n );\r\n }\r\n\r\n /**\r\n * Loads an image as an HTMLImageElement.\r\n * @param input url string, ArrayBuffer, or Blob to load\r\n * @param onLoad callback called when the image successfully loads\r\n * @param onError callback called when the image fails to load\r\n * @param offlineProvider offline provider for caching\r\n * @param mimeType optional mime type\r\n * @param imageBitmapOptions optional the options to use when creating an ImageBitmap\r\n * @returns the HTMLImageElement of the loaded image\r\n * @internal\r\n */\r\n public static _FileToolsLoadImage(\r\n input: string | ArrayBuffer | ArrayBufferView | Blob,\r\n onLoad: (img: HTMLImageElement | ImageBitmap) => void,\r\n onError: (message?: string, exception?: any) => void,\r\n offlineProvider: Nullable,\r\n mimeType?: string,\r\n imageBitmapOptions?: ImageBitmapOptions\r\n ): Nullable {\r\n throw _WarnImport(\"FileTools\");\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _rescaleTexture(source: InternalTexture, destination: InternalTexture, scene: Nullable, internalFormat: number, onComplete: () => void): void {}\r\n\r\n /**\r\n * Creates a raw texture\r\n * @param data defines the data to store in the texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param format defines the format of the data\r\n * @param generateMipMaps defines if the engine should generate the mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)\r\n * @param compression defines the compression used (null by default)\r\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns the raw texture inside an InternalTexture\r\n */\r\n public createRawTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n creationFlags = 0,\r\n useSRGBBuffer: boolean = false\r\n ): InternalTexture {\r\n throw _WarnImport(\"Engine.RawTexture\");\r\n }\r\n\r\n /**\r\n * Creates a new raw cube texture\r\n * @param data defines the array of data to use to create each face\r\n * @param size defines the size of the textures\r\n * @param format defines the format of the data\r\n * @param type defines the type of the data (like Engine.TEXTURETYPE_UNSIGNED_INT)\r\n * @param generateMipMaps defines if the engine should generate the mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param compression defines the compression used (null by default)\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n public createRawCubeTexture(\r\n data: Nullable,\r\n size: number,\r\n format: number,\r\n type: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null\r\n ): InternalTexture {\r\n throw _WarnImport(\"Engine.RawTexture\");\r\n }\r\n\r\n /**\r\n * Creates a new raw 3D texture\r\n * @param data defines the data used to create the texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param depth defines the depth of the texture\r\n * @param format defines the format of the texture\r\n * @param generateMipMaps defines if the engine must generate mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param compression defines the compressed used (can be null)\r\n * @param textureType defines the compressed used (can be null)\r\n * @returns a new raw 3D texture (stored in an InternalTexture)\r\n */\r\n public createRawTexture3D(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null,\r\n textureType = Constants.TEXTURETYPE_UNSIGNED_INT\r\n ): InternalTexture {\r\n throw _WarnImport(\"Engine.RawTexture\");\r\n }\r\n\r\n /**\r\n * Creates a new raw 2D array texture\r\n * @param data defines the data used to create the texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param depth defines the number of layers of the texture\r\n * @param format defines the format of the texture\r\n * @param generateMipMaps defines if the engine must generate mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param compression defines the compressed used (can be null)\r\n * @param textureType defines the compressed used (can be null)\r\n * @returns a new raw 2D array texture (stored in an InternalTexture)\r\n */\r\n public createRawTexture2DArray(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null,\r\n textureType = Constants.TEXTURETYPE_UNSIGNED_INT\r\n ): InternalTexture {\r\n throw _WarnImport(\"Engine.RawTexture\");\r\n }\r\n\r\n private _unpackFlipYCached: Nullable = null;\r\n\r\n /**\r\n * In case you are sharing the context with other applications, it might\r\n * be interested to not cache the unpack flip y state to ensure a consistent\r\n * value would be set.\r\n */\r\n public enableUnpackFlipYCached = true;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _unpackFlipY(value: boolean): void {\r\n if (this._unpackFlipYCached !== value) {\r\n this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, value ? 1 : 0);\r\n\r\n if (this.enableUnpackFlipYCached) {\r\n this._unpackFlipYCached = value;\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _getUnpackAlignement(): number {\r\n return this._gl.getParameter(this._gl.UNPACK_ALIGNMENT);\r\n }\r\n\r\n private _getTextureTarget(texture: InternalTexture): number {\r\n if (texture.isCube) {\r\n return this._gl.TEXTURE_CUBE_MAP;\r\n } else if (texture.is3D) {\r\n return this._gl.TEXTURE_3D;\r\n } else if (texture.is2DArray || texture.isMultiview) {\r\n return this._gl.TEXTURE_2D_ARRAY;\r\n }\r\n return this._gl.TEXTURE_2D;\r\n }\r\n\r\n /**\r\n * Update the sampling mode of a given texture\r\n * @param samplingMode defines the required sampling mode\r\n * @param texture defines the texture to update\r\n * @param generateMipMaps defines whether to generate mipmaps for the texture\r\n */\r\n public updateTextureSamplingMode(samplingMode: number, texture: InternalTexture, generateMipMaps: boolean = false): void {\r\n const target = this._getTextureTarget(texture);\r\n const filters = this._getSamplingParameters(samplingMode, texture.useMipMaps || generateMipMaps);\r\n\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_MIN_FILTER, filters.min);\r\n\r\n if (generateMipMaps) {\r\n texture.generateMipMaps = true;\r\n this._gl.generateMipmap(target);\r\n }\r\n\r\n this._bindTextureDirectly(target, null);\r\n\r\n texture.samplingMode = samplingMode;\r\n }\r\n\r\n /**\r\n * Update the dimensions of a texture\r\n * @param texture texture to update\r\n * @param width new width of the texture\r\n * @param height new height of the texture\r\n * @param depth new depth of the texture\r\n */\r\n public updateTextureDimensions(texture: InternalTexture, width: number, height: number, depth: number = 1): void {}\r\n\r\n /**\r\n * Update the sampling mode of a given texture\r\n * @param texture defines the texture to update\r\n * @param wrapU defines the texture wrap mode of the u coordinates\r\n * @param wrapV defines the texture wrap mode of the v coordinates\r\n * @param wrapR defines the texture wrap mode of the r coordinates\r\n */\r\n public updateTextureWrappingMode(texture: InternalTexture, wrapU: Nullable, wrapV: Nullable = null, wrapR: Nullable = null): void {\r\n const target = this._getTextureTarget(texture);\r\n\r\n if (wrapU !== null) {\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(wrapU), texture);\r\n texture._cachedWrapU = wrapU;\r\n }\r\n if (wrapV !== null) {\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(wrapV), texture);\r\n texture._cachedWrapV = wrapV;\r\n }\r\n if ((texture.is2DArray || texture.is3D) && wrapR !== null) {\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(wrapR), texture);\r\n texture._cachedWrapR = wrapR;\r\n }\r\n\r\n this._bindTextureDirectly(target, null);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setupDepthStencilTexture(\r\n internalTexture: InternalTexture,\r\n size: number | { width: number; height: number; layers?: number },\r\n generateStencil: boolean,\r\n bilinearFiltering: boolean,\r\n comparisonFunction: number,\r\n samples = 1\r\n ): void {\r\n const width = (<{ width: number; height: number; layers?: number }>size).width || size;\r\n const height = (<{ width: number; height: number; layers?: number }>size).height || size;\r\n const layers = (<{ width: number; height: number; layers?: number }>size).layers || 0;\r\n\r\n internalTexture.baseWidth = width;\r\n internalTexture.baseHeight = height;\r\n internalTexture.width = width;\r\n internalTexture.height = height;\r\n internalTexture.is2DArray = layers > 0;\r\n internalTexture.depth = layers;\r\n internalTexture.isReady = true;\r\n internalTexture.samples = samples;\r\n internalTexture.generateMipMaps = false;\r\n internalTexture.samplingMode = bilinearFiltering ? Constants.TEXTURE_BILINEAR_SAMPLINGMODE : Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n internalTexture._comparisonFunction = comparisonFunction;\r\n\r\n const gl = this._gl;\r\n const target = this._getTextureTarget(internalTexture);\r\n const samplingParameters = this._getSamplingParameters(internalTexture.samplingMode, false);\r\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, samplingParameters.mag);\r\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, samplingParameters.min);\r\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n\r\n // TEXTURE_COMPARE_FUNC/MODE are only availble in WebGL2.\r\n if (this.webGLVersion > 1) {\r\n if (comparisonFunction === 0) {\r\n gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, Constants.LEQUAL);\r\n gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.NONE);\r\n } else {\r\n gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);\r\n gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _uploadCompressedDataToTextureDirectly(\r\n texture: InternalTexture,\r\n internalFormat: number,\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n faceIndex: number = 0,\r\n lod: number = 0\r\n ) {\r\n const gl = this._gl;\r\n\r\n let target: GLenum = gl.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\r\n }\r\n\r\n if (texture._useSRGBBuffer) {\r\n switch (internalFormat) {\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:\r\n // Note, if using ETC1 and sRGB is requested, this will use ETC2 if available.\r\n if (this._caps.etc2) {\r\n internalFormat = gl.COMPRESSED_SRGB8_ETC2;\r\n } else {\r\n texture._useSRGBBuffer = false;\r\n }\r\n break;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:\r\n if (this._caps.etc2) {\r\n internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;\r\n } else {\r\n texture._useSRGBBuffer = false;\r\n }\r\n break;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:\r\n internalFormat = gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;\r\n break;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:\r\n internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;\r\n break;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1:\r\n if (this._caps.s3tc_srgb) {\r\n internalFormat = gl.COMPRESSED_SRGB_S3TC_DXT1_EXT;\r\n } else {\r\n // S3TC sRGB extension not supported\r\n texture._useSRGBBuffer = false;\r\n }\r\n break;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1:\r\n if (this._caps.s3tc_srgb) {\r\n internalFormat = gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;\r\n } else {\r\n // S3TC sRGB extension not supported\r\n texture._useSRGBBuffer = false;\r\n }\r\n break;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5:\r\n if (this._caps.s3tc_srgb) {\r\n internalFormat = gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;\r\n } else {\r\n // S3TC sRGB extension not supported\r\n texture._useSRGBBuffer = false;\r\n }\r\n break;\r\n default:\r\n // We don't support a sRGB format corresponding to internalFormat, so revert to non sRGB format\r\n texture._useSRGBBuffer = false;\r\n break;\r\n }\r\n }\r\n\r\n this._gl.compressedTexImage2D(target, lod, internalFormat, width, height, 0, data);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _uploadDataToTextureDirectly(\r\n texture: InternalTexture,\r\n imageData: ArrayBufferView,\r\n faceIndex: number = 0,\r\n lod: number = 0,\r\n babylonInternalFormat?: number,\r\n useTextureWidthAndHeight = false\r\n ): void {\r\n const gl = this._gl;\r\n\r\n const textureType = this._getWebGLTextureType(texture.type);\r\n const format = this._getInternalFormat(texture.format);\r\n const internalFormat =\r\n babylonInternalFormat === undefined\r\n ? this._getRGBABufferInternalSizedFormat(texture.type, texture.format, texture._useSRGBBuffer)\r\n : this._getInternalFormat(babylonInternalFormat, texture._useSRGBBuffer);\r\n\r\n this._unpackFlipY(texture.invertY);\r\n\r\n let target: GLenum = gl.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\r\n }\r\n\r\n const lodMaxWidth = Math.round(Math.log(texture.width) * Math.LOG2E);\r\n const lodMaxHeight = Math.round(Math.log(texture.height) * Math.LOG2E);\r\n const width = useTextureWidthAndHeight ? texture.width : Math.pow(2, Math.max(lodMaxWidth - lod, 0));\r\n const height = useTextureWidthAndHeight ? texture.height : Math.pow(2, Math.max(lodMaxHeight - lod, 0));\r\n\r\n gl.texImage2D(target, lod, internalFormat, width, height, 0, format, textureType, imageData);\r\n }\r\n\r\n /**\r\n * Update a portion of an internal texture\r\n * @param texture defines the texture to update\r\n * @param imageData defines the data to store into the texture\r\n * @param xOffset defines the x coordinates of the update rectangle\r\n * @param yOffset defines the y coordinates of the update rectangle\r\n * @param width defines the width of the update rectangle\r\n * @param height defines the height of the update rectangle\r\n * @param faceIndex defines the face index if texture is a cube (0 by default)\r\n * @param lod defines the lod level to update (0 by default)\r\n * @param generateMipMaps defines whether to generate mipmaps or not\r\n */\r\n public updateTextureData(\r\n texture: InternalTexture,\r\n imageData: ArrayBufferView,\r\n xOffset: number,\r\n yOffset: number,\r\n width: number,\r\n height: number,\r\n faceIndex: number = 0,\r\n lod: number = 0,\r\n generateMipMaps = false\r\n ): void {\r\n const gl = this._gl;\r\n\r\n const textureType = this._getWebGLTextureType(texture.type);\r\n const format = this._getInternalFormat(texture.format);\r\n\r\n this._unpackFlipY(texture.invertY);\r\n\r\n let targetForBinding: GLenum = gl.TEXTURE_2D;\r\n let target: GLenum = gl.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\r\n targetForBinding = gl.TEXTURE_CUBE_MAP;\r\n }\r\n\r\n this._bindTextureDirectly(targetForBinding, texture, true);\r\n\r\n gl.texSubImage2D(target, lod, xOffset, yOffset, width, height, format, textureType, imageData);\r\n\r\n if (generateMipMaps) {\r\n this._gl.generateMipmap(target);\r\n }\r\n\r\n this._bindTextureDirectly(targetForBinding, null);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _uploadArrayBufferViewToTexture(texture: InternalTexture, imageData: ArrayBufferView, faceIndex: number = 0, lod: number = 0): void {\r\n const gl = this._gl;\r\n const bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;\r\n\r\n this._bindTextureDirectly(bindTarget, texture, true);\r\n\r\n this._uploadDataToTextureDirectly(texture, imageData, faceIndex, lod);\r\n\r\n this._bindTextureDirectly(bindTarget, null, true);\r\n }\r\n\r\n protected _prepareWebGLTextureContinuation(texture: InternalTexture, scene: Nullable, noMipmap: boolean, isCompressed: boolean, samplingMode: number): void {\r\n const gl = this._gl;\r\n if (!gl) {\r\n return;\r\n }\r\n\r\n const filters = this._getSamplingParameters(samplingMode, !noMipmap);\r\n\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);\r\n\r\n if (!noMipmap && !isCompressed) {\r\n gl.generateMipmap(gl.TEXTURE_2D);\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_2D, null);\r\n\r\n // this.resetTextureCache();\r\n if (scene) {\r\n scene.removePendingData(texture);\r\n }\r\n\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n }\r\n\r\n private _prepareWebGLTexture(\r\n texture: InternalTexture,\r\n extension: string,\r\n scene: Nullable,\r\n img: HTMLImageElement | ImageBitmap | { width: number; height: number },\r\n invertY: boolean,\r\n noMipmap: boolean,\r\n isCompressed: boolean,\r\n processFunction: (\r\n width: number,\r\n height: number,\r\n img: HTMLImageElement | ImageBitmap | { width: number; height: number },\r\n extension: string,\r\n texture: InternalTexture,\r\n continuationCallback: () => void\r\n ) => boolean,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE\r\n ): void {\r\n const maxTextureSize = this.getCaps().maxTextureSize;\r\n const potWidth = Math.min(maxTextureSize, this.needPOTTextures ? ThinEngine.GetExponentOfTwo(img.width, maxTextureSize) : img.width);\r\n const potHeight = Math.min(maxTextureSize, this.needPOTTextures ? ThinEngine.GetExponentOfTwo(img.height, maxTextureSize) : img.height);\r\n\r\n const gl = this._gl;\r\n if (!gl) {\r\n return;\r\n }\r\n\r\n if (!texture._hardwareTexture) {\r\n // this.resetTextureCache();\r\n if (scene) {\r\n scene.removePendingData(texture);\r\n }\r\n\r\n return;\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);\r\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\r\n\r\n texture.baseWidth = img.width;\r\n texture.baseHeight = img.height;\r\n texture.width = potWidth;\r\n texture.height = potHeight;\r\n texture.isReady = true;\r\n\r\n if (\r\n processFunction(potWidth, potHeight, img, extension, texture, () => {\r\n this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);\r\n })\r\n ) {\r\n // Returning as texture needs extra async steps\r\n return;\r\n }\r\n\r\n this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setupFramebufferDepthAttachments(\r\n generateStencilBuffer: boolean,\r\n generateDepthBuffer: boolean,\r\n width: number,\r\n height: number,\r\n samples = 1\r\n ): Nullable {\r\n const gl = this._gl;\r\n\r\n // Create the depth/stencil buffer\r\n if (generateStencilBuffer && generateDepthBuffer) {\r\n return this._createRenderBuffer(width, height, samples, gl.DEPTH_STENCIL, gl.DEPTH24_STENCIL8, gl.DEPTH_STENCIL_ATTACHMENT);\r\n }\r\n if (generateDepthBuffer) {\r\n let depthFormat: GLenum = gl.DEPTH_COMPONENT16;\r\n if (this._webGLVersion > 1) {\r\n depthFormat = gl.DEPTH_COMPONENT32F;\r\n }\r\n\r\n return this._createRenderBuffer(width, height, samples, depthFormat, depthFormat, gl.DEPTH_ATTACHMENT);\r\n }\r\n if (generateStencilBuffer) {\r\n return this._createRenderBuffer(width, height, samples, gl.STENCIL_INDEX8, gl.STENCIL_INDEX8, gl.STENCIL_ATTACHMENT);\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _createRenderBuffer(\r\n width: number,\r\n height: number,\r\n samples: number,\r\n internalFormat: number,\r\n msInternalFormat: number,\r\n attachment: number,\r\n unbindBuffer = true\r\n ): Nullable {\r\n const gl = this._gl;\r\n const renderBuffer = gl.createRenderbuffer();\r\n return this._updateRenderBuffer(renderBuffer, width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer);\r\n }\r\n\r\n public _updateRenderBuffer(\r\n renderBuffer: Nullable,\r\n width: number,\r\n height: number,\r\n samples: number,\r\n internalFormat: number,\r\n msInternalFormat: number,\r\n attachment: number,\r\n unbindBuffer = true\r\n ): Nullable {\r\n const gl = this._gl;\r\n\r\n gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);\r\n\r\n if (samples > 1 && gl.renderbufferStorageMultisample) {\r\n gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, msInternalFormat, width, height);\r\n } else {\r\n gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);\r\n }\r\n\r\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderBuffer);\r\n\r\n if (unbindBuffer) {\r\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\r\n }\r\n\r\n return renderBuffer;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseTexture(texture: InternalTexture): void {\r\n this._deleteTexture(texture._hardwareTexture?.underlyingResource);\r\n\r\n // Unbind channels\r\n this.unbindAllTextures();\r\n\r\n const index = this._internalTexturesCache.indexOf(texture);\r\n if (index !== -1) {\r\n this._internalTexturesCache.splice(index, 1);\r\n }\r\n\r\n // Integrated fixed lod samplers.\r\n if (texture._lodTextureHigh) {\r\n texture._lodTextureHigh.dispose();\r\n }\r\n if (texture._lodTextureMid) {\r\n texture._lodTextureMid.dispose();\r\n }\r\n if (texture._lodTextureLow) {\r\n texture._lodTextureLow.dispose();\r\n }\r\n\r\n // Integrated irradiance map.\r\n if (texture._irradianceTexture) {\r\n texture._irradianceTexture.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseRenderTargetWrapper(rtWrapper: RenderTargetWrapper): void {\r\n const index = this._renderTargetWrapperCache.indexOf(rtWrapper);\r\n if (index !== -1) {\r\n this._renderTargetWrapperCache.splice(index, 1);\r\n }\r\n }\r\n\r\n protected _deleteTexture(texture: Nullable): void {\r\n if (texture) {\r\n this._gl.deleteTexture(texture);\r\n }\r\n }\r\n\r\n protected _setProgram(program: WebGLProgram): void {\r\n if (this._currentProgram !== program) {\r\n this._gl.useProgram(program);\r\n this._currentProgram = program;\r\n }\r\n }\r\n\r\n protected _boundUniforms: { [key: number]: WebGLUniformLocation } = {};\r\n\r\n /**\r\n * Binds an effect to the webGL context\r\n * @param effect defines the effect to bind\r\n */\r\n public bindSamplers(effect: Effect): void {\r\n const webGLPipelineContext = effect.getPipelineContext() as WebGLPipelineContext;\r\n this._setProgram(webGLPipelineContext.program!);\r\n const samplers = effect.getSamplers();\r\n for (let index = 0; index < samplers.length; index++) {\r\n const uniform = effect.getUniform(samplers[index]);\r\n\r\n if (uniform) {\r\n this._boundUniforms[index] = uniform;\r\n }\r\n }\r\n this._currentEffect = null;\r\n }\r\n\r\n private _activateCurrentTexture() {\r\n if (this._currentTextureChannel !== this._activeChannel) {\r\n this._gl.activeTexture(this._gl.TEXTURE0 + this._activeChannel);\r\n this._currentTextureChannel = this._activeChannel;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindTextureDirectly(target: number, texture: Nullable, forTextureDataUpdate = false, force = false): boolean {\r\n let wasPreviouslyBound = false;\r\n const isTextureForRendering = texture && texture._associatedChannel > -1;\r\n if (forTextureDataUpdate && isTextureForRendering) {\r\n this._activeChannel = texture!._associatedChannel;\r\n }\r\n\r\n const currentTextureBound = this._boundTexturesCache[this._activeChannel];\r\n\r\n if (currentTextureBound !== texture || force) {\r\n this._activateCurrentTexture();\r\n\r\n if (texture && texture.isMultiview) {\r\n //this._gl.bindTexture(target, texture ? texture._colorTextureArray : null);\r\n console.error(target, texture);\r\n throw \"_bindTextureDirectly called with a multiview texture!\";\r\n } else {\r\n this._gl.bindTexture(target, texture?._hardwareTexture?.underlyingResource ?? null);\r\n }\r\n\r\n this._boundTexturesCache[this._activeChannel] = texture;\r\n\r\n if (texture) {\r\n texture._associatedChannel = this._activeChannel;\r\n }\r\n } else if (forTextureDataUpdate) {\r\n wasPreviouslyBound = true;\r\n this._activateCurrentTexture();\r\n }\r\n\r\n if (isTextureForRendering && !forTextureDataUpdate) {\r\n this._bindSamplerUniformToChannel(texture!._associatedChannel, this._activeChannel);\r\n }\r\n\r\n return wasPreviouslyBound;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindTexture(channel: number, texture: Nullable, name: string): void {\r\n if (channel === undefined) {\r\n return;\r\n }\r\n\r\n if (texture) {\r\n texture._associatedChannel = channel;\r\n }\r\n\r\n this._activeChannel = channel;\r\n const target = texture ? this._getTextureTarget(texture) : this._gl.TEXTURE_2D;\r\n this._bindTextureDirectly(target, texture);\r\n }\r\n\r\n /**\r\n * Unbind all textures from the webGL context\r\n */\r\n public unbindAllTextures(): void {\r\n for (let channel = 0; channel < this._maxSimultaneousTextures; channel++) {\r\n this._activeChannel = channel;\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\r\n if (this.webGLVersion > 1) {\r\n this._bindTextureDirectly(this._gl.TEXTURE_3D, null);\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets a texture to the according uniform.\r\n * @param channel The texture channel\r\n * @param uniform The uniform to set\r\n * @param texture The texture to apply\r\n * @param name The name of the uniform in the effect\r\n */\r\n public setTexture(channel: number, uniform: Nullable, texture: Nullable, name: string): void {\r\n if (channel === undefined) {\r\n return;\r\n }\r\n\r\n if (uniform) {\r\n this._boundUniforms[channel] = uniform;\r\n }\r\n\r\n this._setTexture(channel, texture);\r\n }\r\n\r\n private _bindSamplerUniformToChannel(sourceSlot: number, destination: number) {\r\n const uniform = this._boundUniforms[sourceSlot];\r\n if (!uniform || uniform._currentState === destination) {\r\n return;\r\n }\r\n this._gl.uniform1i(uniform, destination);\r\n uniform._currentState = destination;\r\n }\r\n\r\n private _getTextureWrapMode(mode: number): number {\r\n switch (mode) {\r\n case Constants.TEXTURE_WRAP_ADDRESSMODE:\r\n return this._gl.REPEAT;\r\n case Constants.TEXTURE_CLAMP_ADDRESSMODE:\r\n return this._gl.CLAMP_TO_EDGE;\r\n case Constants.TEXTURE_MIRROR_ADDRESSMODE:\r\n return this._gl.MIRRORED_REPEAT;\r\n }\r\n return this._gl.REPEAT;\r\n }\r\n\r\n protected _setTexture(channel: number, texture: Nullable, isPartOfTextureArray = false, depthStencilTexture = false, name = \"\"): boolean {\r\n // Not ready?\r\n if (!texture) {\r\n if (this._boundTexturesCache[channel] != null) {\r\n this._activeChannel = channel;\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\r\n if (this.webGLVersion > 1) {\r\n this._bindTextureDirectly(this._gl.TEXTURE_3D, null);\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null);\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n // Video\r\n if ((texture).video) {\r\n this._activeChannel = channel;\r\n const videoInternalTexture = (texture).getInternalTexture();\r\n if (videoInternalTexture) {\r\n videoInternalTexture._associatedChannel = channel;\r\n }\r\n (texture).update();\r\n } else if (texture.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {\r\n // Delay loading\r\n texture.delayLoad();\r\n return false;\r\n }\r\n\r\n let internalTexture: InternalTexture;\r\n if (depthStencilTexture) {\r\n internalTexture = (texture).depthStencilTexture!;\r\n } else if (texture.isReady()) {\r\n internalTexture = texture.getInternalTexture();\r\n } else if (texture.isCube) {\r\n internalTexture = this.emptyCubeTexture;\r\n } else if (texture.is3D) {\r\n internalTexture = this.emptyTexture3D;\r\n } else if (texture.is2DArray) {\r\n internalTexture = this.emptyTexture2DArray;\r\n } else {\r\n internalTexture = this.emptyTexture;\r\n }\r\n\r\n if (!isPartOfTextureArray && internalTexture) {\r\n internalTexture._associatedChannel = channel;\r\n }\r\n\r\n let needToBind = true;\r\n if (this._boundTexturesCache[channel] === internalTexture) {\r\n if (!isPartOfTextureArray) {\r\n this._bindSamplerUniformToChannel(internalTexture._associatedChannel, channel);\r\n }\r\n\r\n needToBind = false;\r\n }\r\n\r\n this._activeChannel = channel;\r\n const target = this._getTextureTarget(internalTexture);\r\n if (needToBind) {\r\n this._bindTextureDirectly(target, internalTexture, isPartOfTextureArray);\r\n }\r\n\r\n if (internalTexture && !internalTexture.isMultiview) {\r\n // CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT.\r\n if (internalTexture.isCube && internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) {\r\n internalTexture._cachedCoordinatesMode = texture.coordinatesMode;\r\n\r\n const textureWrapMode =\r\n texture.coordinatesMode !== Constants.TEXTURE_CUBIC_MODE && texture.coordinatesMode !== Constants.TEXTURE_SKYBOX_MODE\r\n ? Constants.TEXTURE_WRAP_ADDRESSMODE\r\n : Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n texture.wrapU = textureWrapMode;\r\n texture.wrapV = textureWrapMode;\r\n }\r\n\r\n if (internalTexture._cachedWrapU !== texture.wrapU) {\r\n internalTexture._cachedWrapU = texture.wrapU;\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);\r\n }\r\n\r\n if (internalTexture._cachedWrapV !== texture.wrapV) {\r\n internalTexture._cachedWrapV = texture.wrapV;\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);\r\n }\r\n\r\n if (internalTexture.is3D && internalTexture._cachedWrapR !== texture.wrapR) {\r\n internalTexture._cachedWrapR = texture.wrapR;\r\n this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(texture.wrapR), internalTexture);\r\n }\r\n\r\n this._setAnisotropicLevel(target, internalTexture, texture.anisotropicFilteringLevel);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Sets an array of texture to the webGL context\r\n * @param channel defines the channel where the texture array must be set\r\n * @param uniform defines the associated uniform location\r\n * @param textures defines the array of textures to bind\r\n * @param name name of the channel\r\n */\r\n public setTextureArray(channel: number, uniform: Nullable, textures: ThinTexture[], name: string): void {\r\n if (channel === undefined || !uniform) {\r\n return;\r\n }\r\n\r\n if (!this._textureUnits || this._textureUnits.length !== textures.length) {\r\n this._textureUnits = new Int32Array(textures.length);\r\n }\r\n for (let i = 0; i < textures.length; i++) {\r\n const texture = textures[i].getInternalTexture();\r\n\r\n if (texture) {\r\n this._textureUnits[i] = channel + i;\r\n texture._associatedChannel = channel + i;\r\n } else {\r\n this._textureUnits[i] = -1;\r\n }\r\n }\r\n this._gl.uniform1iv(uniform, this._textureUnits);\r\n\r\n for (let index = 0; index < textures.length; index++) {\r\n this._setTexture(this._textureUnits[index], textures[index], true);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setAnisotropicLevel(target: number, internalTexture: InternalTexture, anisotropicFilteringLevel: number) {\r\n const anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;\r\n if (\r\n internalTexture.samplingMode !== Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST &&\r\n internalTexture.samplingMode !== Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR &&\r\n internalTexture.samplingMode !== Constants.TEXTURE_LINEAR_LINEAR\r\n ) {\r\n anisotropicFilteringLevel = 1; // Forcing the anisotropic to 1 because else webgl will force filters to linear\r\n }\r\n\r\n if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== anisotropicFilteringLevel) {\r\n this._setTextureParameterFloat(\r\n target,\r\n anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT,\r\n Math.min(anisotropicFilteringLevel, this._caps.maxAnisotropy),\r\n internalTexture\r\n );\r\n internalTexture._cachedAnisotropicFilteringLevel = anisotropicFilteringLevel;\r\n }\r\n }\r\n\r\n private _setTextureParameterFloat(target: number, parameter: number, value: number, texture: InternalTexture): void {\r\n this._bindTextureDirectly(target, texture, true, true);\r\n this._gl.texParameterf(target, parameter, value);\r\n }\r\n\r\n private _setTextureParameterInteger(target: number, parameter: number, value: number, texture?: InternalTexture) {\r\n if (texture) {\r\n this._bindTextureDirectly(target, texture, true, true);\r\n }\r\n this._gl.texParameteri(target, parameter, value);\r\n }\r\n\r\n /**\r\n * Unbind all vertex attributes from the webGL context\r\n */\r\n public unbindAllAttributes() {\r\n if (this._mustWipeVertexAttributes) {\r\n this._mustWipeVertexAttributes = false;\r\n\r\n for (let i = 0; i < this._caps.maxVertexAttribs; i++) {\r\n this.disableAttributeByIndex(i);\r\n }\r\n return;\r\n }\r\n\r\n for (let i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {\r\n if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {\r\n continue;\r\n }\r\n\r\n this.disableAttributeByIndex(i);\r\n }\r\n }\r\n\r\n /**\r\n * Force the engine to release all cached effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled\r\n */\r\n public releaseEffects() {\r\n for (const name in this._compiledEffects) {\r\n const webGLPipelineContext = this._compiledEffects[name].getPipelineContext() as WebGLPipelineContext;\r\n this._deletePipelineContext(webGLPipelineContext);\r\n }\r\n\r\n this._compiledEffects = {};\r\n }\r\n\r\n /**\r\n * Dispose and release all associated resources\r\n */\r\n public dispose(): void {\r\n this._isDisposed = true;\r\n this.stopRenderLoop();\r\n\r\n // Clear observables\r\n if (this.onBeforeTextureInitObservable) {\r\n this.onBeforeTextureInitObservable.clear();\r\n }\r\n\r\n // Empty texture\r\n if (this._emptyTexture) {\r\n this._releaseTexture(this._emptyTexture);\r\n this._emptyTexture = null;\r\n }\r\n if (this._emptyCubeTexture) {\r\n this._releaseTexture(this._emptyCubeTexture);\r\n this._emptyCubeTexture = null;\r\n }\r\n\r\n if (this._dummyFramebuffer) {\r\n this._gl.deleteFramebuffer(this._dummyFramebuffer);\r\n }\r\n\r\n // Release effects\r\n this.releaseEffects();\r\n this.releaseComputeEffects?.();\r\n\r\n // Unbind\r\n this.unbindAllAttributes();\r\n this._boundUniforms = {};\r\n\r\n // Events\r\n if (IsWindowObjectExist()) {\r\n if (this._renderingCanvas) {\r\n if (!this._doNotHandleContextLost) {\r\n this._renderingCanvas.removeEventListener(\"webglcontextlost\", this._onContextLost);\r\n this._renderingCanvas.removeEventListener(\"webglcontextrestored\", this._onContextRestored);\r\n }\r\n\r\n window.removeEventListener(\"resize\", this._checkForMobile);\r\n }\r\n }\r\n\r\n this._workingCanvas = null;\r\n this._workingContext = null;\r\n this._currentBufferPointers.length = 0;\r\n this._renderingCanvas = null;\r\n this._currentProgram = null;\r\n this._boundRenderFunction = null;\r\n\r\n Effect.ResetCache();\r\n\r\n // Abort active requests\r\n for (const request of this._activeRequests) {\r\n request.abort();\r\n }\r\n\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n }\r\n\r\n /**\r\n * Attach a new callback raised when context lost event is fired\r\n * @param callback defines the callback to call\r\n */\r\n public attachContextLostEvent(callback: (event: WebGLContextEvent) => void): void {\r\n if (this._renderingCanvas) {\r\n this._renderingCanvas.addEventListener(\"webglcontextlost\", callback, false);\r\n }\r\n }\r\n\r\n /**\r\n * Attach a new callback raised when context restored event is fired\r\n * @param callback defines the callback to call\r\n */\r\n public attachContextRestoredEvent(callback: (event: WebGLContextEvent) => void): void {\r\n if (this._renderingCanvas) {\r\n this._renderingCanvas.addEventListener(\"webglcontextrestored\", callback, false);\r\n }\r\n }\r\n\r\n /**\r\n * Get the current error code of the webGL context\r\n * @returns the error code\r\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError\r\n */\r\n public getError(): number {\r\n return this._gl.getError();\r\n }\r\n\r\n private _canRenderToFloatFramebuffer(): boolean {\r\n if (this._webGLVersion > 1) {\r\n return this._caps.colorBufferFloat;\r\n }\r\n return this._canRenderToFramebuffer(Constants.TEXTURETYPE_FLOAT);\r\n }\r\n\r\n private _canRenderToHalfFloatFramebuffer(): boolean {\r\n if (this._webGLVersion > 1) {\r\n return this._caps.colorBufferFloat;\r\n }\r\n return this._canRenderToFramebuffer(Constants.TEXTURETYPE_HALF_FLOAT);\r\n }\r\n\r\n // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture\r\n private _canRenderToFramebuffer(type: number): boolean {\r\n const gl = this._gl;\r\n\r\n //clear existing errors\r\n // eslint-disable-next-line no-empty\r\n while (gl.getError() !== gl.NO_ERROR) {}\r\n\r\n let successful = true;\r\n\r\n const texture = gl.createTexture();\r\n gl.bindTexture(gl.TEXTURE_2D, texture);\r\n gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(type), 1, 1, 0, gl.RGBA, this._getWebGLTextureType(type), null);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\r\n\r\n const fb = gl.createFramebuffer();\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, fb);\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\r\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\r\n\r\n successful = successful && status === gl.FRAMEBUFFER_COMPLETE;\r\n successful = successful && gl.getError() === gl.NO_ERROR;\r\n\r\n //try render by clearing frame buffer's color buffer\r\n if (successful) {\r\n gl.clear(gl.COLOR_BUFFER_BIT);\r\n successful = successful && gl.getError() === gl.NO_ERROR;\r\n }\r\n\r\n //try reading from frame to ensure render occurs (just creating the FBO is not sufficient to determine if rendering is supported)\r\n if (successful) {\r\n //in practice it's sufficient to just read from the backbuffer rather than handle potentially issues reading from the texture\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\r\n const readFormat = gl.RGBA;\r\n const readType = gl.UNSIGNED_BYTE;\r\n const buffer = new Uint8Array(4);\r\n gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer);\r\n successful = successful && gl.getError() === gl.NO_ERROR;\r\n }\r\n\r\n //clean up\r\n gl.deleteTexture(texture);\r\n gl.deleteFramebuffer(fb);\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\r\n\r\n //clear accumulated errors\r\n // eslint-disable-next-line no-empty\r\n while (!successful && gl.getError() !== gl.NO_ERROR) {}\r\n\r\n return successful;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getWebGLTextureType(type: number): number {\r\n if (this._webGLVersion === 1) {\r\n switch (type) {\r\n case Constants.TEXTURETYPE_FLOAT:\r\n return this._gl.FLOAT;\r\n case Constants.TEXTURETYPE_HALF_FLOAT:\r\n return this._gl.HALF_FLOAT_OES;\r\n case Constants.TEXTURETYPE_UNSIGNED_BYTE:\r\n return this._gl.UNSIGNED_BYTE;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:\r\n return this._gl.UNSIGNED_SHORT_4_4_4_4;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:\r\n return this._gl.UNSIGNED_SHORT_5_5_5_1;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:\r\n return this._gl.UNSIGNED_SHORT_5_6_5;\r\n }\r\n return this._gl.UNSIGNED_BYTE;\r\n }\r\n\r\n switch (type) {\r\n case Constants.TEXTURETYPE_BYTE:\r\n return this._gl.BYTE;\r\n case Constants.TEXTURETYPE_UNSIGNED_BYTE:\r\n return this._gl.UNSIGNED_BYTE;\r\n case Constants.TEXTURETYPE_SHORT:\r\n return this._gl.SHORT;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT:\r\n return this._gl.UNSIGNED_SHORT;\r\n case Constants.TEXTURETYPE_INT:\r\n return this._gl.INT;\r\n case Constants.TEXTURETYPE_UNSIGNED_INTEGER: // Refers to UNSIGNED_INT\r\n return this._gl.UNSIGNED_INT;\r\n case Constants.TEXTURETYPE_FLOAT:\r\n return this._gl.FLOAT;\r\n case Constants.TEXTURETYPE_HALF_FLOAT:\r\n return this._gl.HALF_FLOAT;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:\r\n return this._gl.UNSIGNED_SHORT_4_4_4_4;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:\r\n return this._gl.UNSIGNED_SHORT_5_5_5_1;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:\r\n return this._gl.UNSIGNED_SHORT_5_6_5;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV:\r\n return this._gl.UNSIGNED_INT_2_10_10_10_REV;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_24_8:\r\n return this._gl.UNSIGNED_INT_24_8;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV:\r\n return this._gl.UNSIGNED_INT_10F_11F_11F_REV;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV:\r\n return this._gl.UNSIGNED_INT_5_9_9_9_REV;\r\n case Constants.TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV:\r\n return this._gl.FLOAT_32_UNSIGNED_INT_24_8_REV;\r\n }\r\n\r\n return this._gl.UNSIGNED_BYTE;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getInternalFormat(format: number, useSRGBBuffer = false): number {\r\n let internalFormat: GLenum = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;\r\n\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_ALPHA:\r\n internalFormat = this._gl.ALPHA;\r\n break;\r\n case Constants.TEXTUREFORMAT_LUMINANCE:\r\n internalFormat = this._gl.LUMINANCE;\r\n break;\r\n case Constants.TEXTUREFORMAT_LUMINANCE_ALPHA:\r\n internalFormat = this._gl.LUMINANCE_ALPHA;\r\n break;\r\n case Constants.TEXTUREFORMAT_RED:\r\n internalFormat = this._gl.RED;\r\n break;\r\n case Constants.TEXTUREFORMAT_RG:\r\n internalFormat = this._gl.RG;\r\n break;\r\n case Constants.TEXTUREFORMAT_RGB:\r\n internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;\r\n break;\r\n case Constants.TEXTUREFORMAT_RGBA:\r\n internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;\r\n break;\r\n }\r\n\r\n if (this._webGLVersion > 1) {\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n internalFormat = this._gl.RED_INTEGER;\r\n break;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n internalFormat = this._gl.RG_INTEGER;\r\n break;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n internalFormat = this._gl.RGB_INTEGER;\r\n break;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n internalFormat = this._gl.RGBA_INTEGER;\r\n break;\r\n }\r\n }\r\n\r\n return internalFormat;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getRGBABufferInternalSizedFormat(type: number, format?: number, useSRGBBuffer = false): number {\r\n if (this._webGLVersion === 1) {\r\n if (format !== undefined) {\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_ALPHA:\r\n return this._gl.ALPHA;\r\n case Constants.TEXTUREFORMAT_LUMINANCE:\r\n return this._gl.LUMINANCE;\r\n case Constants.TEXTUREFORMAT_LUMINANCE_ALPHA:\r\n return this._gl.LUMINANCE_ALPHA;\r\n case Constants.TEXTUREFORMAT_RGB:\r\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;\r\n }\r\n }\r\n return this._gl.RGBA;\r\n }\r\n\r\n switch (type) {\r\n case Constants.TEXTURETYPE_BYTE:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED:\r\n return this._gl.R8_SNORM;\r\n case Constants.TEXTUREFORMAT_RG:\r\n return this._gl.RG8_SNORM;\r\n case Constants.TEXTUREFORMAT_RGB:\r\n return this._gl.RGB8_SNORM;\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n return this._gl.R8I;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n return this._gl.RG8I;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n return this._gl.RGB8I;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGBA8I;\r\n default:\r\n return this._gl.RGBA8_SNORM;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_BYTE:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED:\r\n return this._gl.R8;\r\n case Constants.TEXTUREFORMAT_RG:\r\n return this._gl.RG8;\r\n case Constants.TEXTUREFORMAT_RGB:\r\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8 : this._gl.RGB8; // By default. Other possibilities are RGB565, SRGB8.\r\n case Constants.TEXTUREFORMAT_RGBA:\r\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8; // By default. Other possibilities are RGB5_A1, RGBA4, SRGB8_ALPHA8.\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n return this._gl.R8UI;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n return this._gl.RG8UI;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n return this._gl.RGB8UI;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGBA8UI;\r\n case Constants.TEXTUREFORMAT_ALPHA:\r\n return this._gl.ALPHA;\r\n case Constants.TEXTUREFORMAT_LUMINANCE:\r\n return this._gl.LUMINANCE;\r\n case Constants.TEXTUREFORMAT_LUMINANCE_ALPHA:\r\n return this._gl.LUMINANCE_ALPHA;\r\n default:\r\n return this._gl.RGBA8;\r\n }\r\n case Constants.TEXTURETYPE_SHORT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n return this._gl.R16I;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n return this._gl.RG16I;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n return this._gl.RGB16I;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGBA16I;\r\n default:\r\n return this._gl.RGBA16I;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n return this._gl.R16UI;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n return this._gl.RG16UI;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n return this._gl.RGB16UI;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGBA16UI;\r\n default:\r\n return this._gl.RGBA16UI;\r\n }\r\n case Constants.TEXTURETYPE_INT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n return this._gl.R32I;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n return this._gl.RG32I;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n return this._gl.RGB32I;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGBA32I;\r\n default:\r\n return this._gl.RGBA32I;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_INTEGER: // Refers to UNSIGNED_INT\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED_INTEGER:\r\n return this._gl.R32UI;\r\n case Constants.TEXTUREFORMAT_RG_INTEGER:\r\n return this._gl.RG32UI;\r\n case Constants.TEXTUREFORMAT_RGB_INTEGER:\r\n return this._gl.RGB32UI;\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGBA32UI;\r\n default:\r\n return this._gl.RGBA32UI;\r\n }\r\n case Constants.TEXTURETYPE_FLOAT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED:\r\n return this._gl.R32F; // By default. Other possibility is R16F.\r\n case Constants.TEXTUREFORMAT_RG:\r\n return this._gl.RG32F; // By default. Other possibility is RG16F.\r\n case Constants.TEXTUREFORMAT_RGB:\r\n return this._gl.RGB32F; // By default. Other possibilities are RGB16F, R11F_G11F_B10F, RGB9_E5.\r\n case Constants.TEXTUREFORMAT_RGBA:\r\n return this._gl.RGBA32F; // By default. Other possibility is RGBA16F.\r\n default:\r\n return this._gl.RGBA32F;\r\n }\r\n case Constants.TEXTURETYPE_HALF_FLOAT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RED:\r\n return this._gl.R16F;\r\n case Constants.TEXTUREFORMAT_RG:\r\n return this._gl.RG16F;\r\n case Constants.TEXTUREFORMAT_RGB:\r\n return this._gl.RGB16F; // By default. Other possibilities are R11F_G11F_B10F, RGB9_E5.\r\n case Constants.TEXTUREFORMAT_RGBA:\r\n return this._gl.RGBA16F;\r\n default:\r\n return this._gl.RGBA16F;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:\r\n return this._gl.RGB565;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV:\r\n return this._gl.R11F_G11F_B10F;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV:\r\n return this._gl.RGB9_E5;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:\r\n return this._gl.RGBA4;\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:\r\n return this._gl.RGB5_A1;\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_RGBA:\r\n return this._gl.RGB10_A2; // By default. Other possibility is RGB5_A1.\r\n case Constants.TEXTUREFORMAT_RGBA_INTEGER:\r\n return this._gl.RGB10_A2UI;\r\n default:\r\n return this._gl.RGB10_A2;\r\n }\r\n }\r\n\r\n return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getRGBAMultiSampleBufferFormat(type: number, format = Constants.TEXTUREFORMAT_RGBA): number {\r\n switch (type) {\r\n case Constants.TEXTURETYPE_FLOAT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_R:\r\n return this._gl.R32F;\r\n default:\r\n return this._gl.RGBA32F;\r\n }\r\n case Constants.TEXTURETYPE_HALF_FLOAT:\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_R:\r\n return this._gl.R16F;\r\n default:\r\n return this._gl.RGBA16F;\r\n }\r\n }\r\n\r\n return this._gl.RGBA8;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (data: any) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: IWebRequest, exception?: any) => void\r\n ): IFileRequest {\r\n const request = ThinEngine._FileToolsLoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError);\r\n this._activeRequests.push(request);\r\n request.onCompleteObservable.add((request) => {\r\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\r\n });\r\n return request;\r\n }\r\n\r\n /**\r\n * Loads a file from a url\r\n * @param url url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @returns a file request object\r\n * @internal\r\n */\r\n public static _FileToolsLoadFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void\r\n ): IFileRequest {\r\n throw _WarnImport(\"FileTools\");\r\n }\r\n\r\n /**\r\n * Reads pixels from the current frame buffer. Please note that this function can be slow\r\n * @param x defines the x coordinate of the rectangle where pixels must be read\r\n * @param y defines the y coordinate of the rectangle where pixels must be read\r\n * @param width defines the width of the rectangle where pixels must be read\r\n * @param height defines the height of the rectangle where pixels must be read\r\n * @param hasAlpha defines whether the output should have alpha or not (defaults to true)\r\n * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels\r\n * @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors\r\n */\r\n public readPixels(x: number, y: number, width: number, height: number, hasAlpha = true, flushRenderer = true): Promise {\r\n const numChannels = hasAlpha ? 4 : 3;\r\n const format = hasAlpha ? this._gl.RGBA : this._gl.RGB;\r\n const data = new Uint8Array(height * width * numChannels);\r\n if (flushRenderer) {\r\n this.flushFramebuffer();\r\n }\r\n this._gl.readPixels(x, y, width, height, format, this._gl.UNSIGNED_BYTE, data);\r\n return Promise.resolve(data);\r\n }\r\n\r\n // Statics\r\n\r\n private static _IsSupported: Nullable = null;\r\n private static _HasMajorPerformanceCaveat: Nullable = null;\r\n\r\n /**\r\n * Gets a Promise indicating if the engine can be instantiated (ie. if a webGL context can be found)\r\n */\r\n public static get IsSupportedAsync(): Promise {\r\n return Promise.resolve(this.isSupported());\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)\r\n */\r\n public static get IsSupported(): boolean {\r\n return this.isSupported(); // Backward compat\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)\r\n * @returns true if the engine can be created\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static isSupported(): boolean {\r\n if (this._HasMajorPerformanceCaveat !== null) {\r\n return !this._HasMajorPerformanceCaveat; // We know it is performant so WebGL is supported\r\n }\r\n\r\n if (this._IsSupported === null) {\r\n try {\r\n const tempcanvas = this._CreateCanvas(1, 1);\r\n const gl = tempcanvas.getContext(\"webgl\") || (tempcanvas as any).getContext(\"experimental-webgl\");\r\n\r\n this._IsSupported = gl != null && !!window.WebGLRenderingContext;\r\n } catch (e) {\r\n this._IsSupported = false;\r\n }\r\n }\r\n\r\n return this._IsSupported;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the engine can be instantiated on a performant device (ie. if a webGL context can be found and it does not use a slow implementation)\r\n */\r\n public static get HasMajorPerformanceCaveat(): boolean {\r\n if (this._HasMajorPerformanceCaveat === null) {\r\n try {\r\n const tempcanvas = this._CreateCanvas(1, 1);\r\n const gl =\r\n tempcanvas.getContext(\"webgl\", { failIfMajorPerformanceCaveat: true }) ||\r\n (tempcanvas as any).getContext(\"experimental-webgl\", { failIfMajorPerformanceCaveat: true });\r\n\r\n this._HasMajorPerformanceCaveat = !gl;\r\n } catch (e) {\r\n this._HasMajorPerformanceCaveat = false;\r\n }\r\n }\r\n\r\n return this._HasMajorPerformanceCaveat;\r\n }\r\n\r\n /**\r\n * Find the next highest power of two.\r\n * @param x Number to start search from.\r\n * @returns Next highest power of two.\r\n */\r\n public static CeilingPOT(x: number): number {\r\n x--;\r\n x |= x >> 1;\r\n x |= x >> 2;\r\n x |= x >> 4;\r\n x |= x >> 8;\r\n x |= x >> 16;\r\n x++;\r\n return x;\r\n }\r\n\r\n /**\r\n * Find the next lowest power of two.\r\n * @param x Number to start search from.\r\n * @returns Next lowest power of two.\r\n */\r\n public static FloorPOT(x: number): number {\r\n x = x | (x >> 1);\r\n x = x | (x >> 2);\r\n x = x | (x >> 4);\r\n x = x | (x >> 8);\r\n x = x | (x >> 16);\r\n return x - (x >> 1);\r\n }\r\n\r\n /**\r\n * Find the nearest power of two.\r\n * @param x Number to start search from.\r\n * @returns Next nearest power of two.\r\n */\r\n public static NearestPOT(x: number): number {\r\n const c = ThinEngine.CeilingPOT(x);\r\n const f = ThinEngine.FloorPOT(x);\r\n return c - x > x - f ? f : c;\r\n }\r\n\r\n /**\r\n * Get the closest exponent of two\r\n * @param value defines the value to approximate\r\n * @param max defines the maximum value to return\r\n * @param mode defines how to define the closest value\r\n * @returns closest exponent of two of the given value\r\n */\r\n public static GetExponentOfTwo(value: number, max: number, mode = Constants.SCALEMODE_NEAREST): number {\r\n let pot;\r\n\r\n switch (mode) {\r\n case Constants.SCALEMODE_FLOOR:\r\n pot = ThinEngine.FloorPOT(value);\r\n break;\r\n case Constants.SCALEMODE_NEAREST:\r\n pot = ThinEngine.NearestPOT(value);\r\n break;\r\n case Constants.SCALEMODE_CEILING:\r\n default:\r\n pot = ThinEngine.CeilingPOT(value);\r\n break;\r\n }\r\n\r\n return Math.min(pot, max);\r\n }\r\n\r\n /**\r\n * Queue a new function into the requested animation frame pool (ie. this function will be executed by the browser (or the javascript engine) for the next frame)\r\n * @param func - the function to be called\r\n * @param requester - the object that will request the next frame. Falls back to window.\r\n * @returns frame number\r\n */\r\n public static QueueNewFrame(func: () => void, requester?: any): number {\r\n // Note that there is kind of a typing issue here, as `setTimeout` might return something else than a number (NodeJs returns a NodeJS.Timeout object).\r\n // Also if the global `requestAnimationFrame`'s returnType is number, `requester.requestPostAnimationFrame` and `requester.requestAnimationFrame` types\r\n // are `any`.\r\n\r\n if (!IsWindowObjectExist()) {\r\n if (typeof requestAnimationFrame === \"function\") {\r\n return requestAnimationFrame(func);\r\n }\r\n } else {\r\n const { requestAnimationFrame } = requester || window;\r\n if (typeof requestAnimationFrame === \"function\") {\r\n return requestAnimationFrame(func);\r\n }\r\n }\r\n\r\n // fallback to the global `setTimeout`.\r\n // In most cases (aka in the browser), `window` is the global object, so instead of calling `window.setTimeout` we could call the global `setTimeout`.\r\n return setTimeout(func, 16) as unknown as number;\r\n }\r\n\r\n /**\r\n * Gets host document\r\n * @returns the host document object\r\n */\r\n public getHostDocument(): Nullable {\r\n if (this._renderingCanvas && this._renderingCanvas.ownerDocument) {\r\n return this._renderingCanvas.ownerDocument;\r\n }\r\n\r\n return IsDocumentAvailable() ? document : null;\r\n }\r\n}\r\n","import { IsWindowObjectExist } from \"./domManagement\";\r\n\r\n/**\r\n * Class used to provide helper for timing\r\n */\r\nexport class TimingTools {\r\n /**\r\n * Polyfill for setImmediate\r\n * @param action defines the action to execute after the current execution block\r\n */\r\n public static SetImmediate(action: () => void) {\r\n if (IsWindowObjectExist() && window.setImmediate) {\r\n window.setImmediate(action);\r\n } else {\r\n setTimeout(action, 1);\r\n }\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { WebRequest } from \"./webRequest\";\r\nimport { IsWindowObjectExist } from \"./domManagement\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { IOfflineProvider } from \"../Offline/IOfflineProvider\";\r\nimport type { IFileRequest } from \"./fileRequest\";\r\nimport { Observable } from \"./observable\";\r\nimport { FilesInputStore } from \"./filesInputStore\";\r\nimport { RetryStrategy } from \"./retryStrategy\";\r\nimport { BaseError, ErrorCodes, RuntimeError } from \"./error\";\r\nimport { DecodeBase64ToBinary, DecodeBase64ToString, EncodeArrayBufferToBase64 } from \"./stringTools\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { Logger } from \"./logger\";\r\nimport { TimingTools } from \"./timingTools\";\r\n\r\nconst Base64DataUrlRegEx = new RegExp(/^data:([^,]+\\/[^,]+)?;base64,/i);\r\n\r\n/** @ignore */\r\nexport class LoadFileError extends RuntimeError {\r\n public request?: WebRequest;\r\n public file?: File;\r\n\r\n /**\r\n * Creates a new LoadFileError\r\n * @param message defines the message of the error\r\n * @param object defines the optional web request\r\n */\r\n constructor(message: string, object?: WebRequest | File) {\r\n super(message, ErrorCodes.LoadFileError);\r\n\r\n this.name = \"LoadFileError\";\r\n BaseError._setPrototypeOf(this, LoadFileError.prototype);\r\n\r\n if (object instanceof WebRequest) {\r\n this.request = object;\r\n } else {\r\n this.file = object;\r\n }\r\n }\r\n}\r\n\r\n/** @ignore */\r\nexport class RequestFileError extends RuntimeError {\r\n /**\r\n * Creates a new LoadFileError\r\n * @param message defines the message of the error\r\n * @param request defines the optional web request\r\n */\r\n constructor(message: string, public request: WebRequest) {\r\n super(message, ErrorCodes.RequestFileError);\r\n this.name = \"RequestFileError\";\r\n BaseError._setPrototypeOf(this, RequestFileError.prototype);\r\n }\r\n}\r\n\r\n/** @ignore */\r\nexport class ReadFileError extends RuntimeError {\r\n /**\r\n * Creates a new ReadFileError\r\n * @param message defines the message of the error\r\n * @param file defines the optional file\r\n */\r\n constructor(message: string, public file: File) {\r\n super(message, ErrorCodes.ReadFileError);\r\n this.name = \"ReadFileError\";\r\n BaseError._setPrototypeOf(this, ReadFileError.prototype);\r\n }\r\n}\r\n/**\r\n * @internal\r\n */\r\nexport const FileToolsOptions: {\r\n DefaultRetryStrategy: (url: string, request: WebRequest, retryIndex: number) => number;\r\n BaseUrl: string;\r\n CorsBehavior: string | ((url: string | string[]) => string);\r\n PreprocessUrl: (url: string) => string;\r\n} = {\r\n /**\r\n * Gets or sets the retry strategy to apply when an error happens while loading an asset.\r\n * When defining this function, return the wait time before trying again or return -1 to\r\n * stop retrying and error out.\r\n */\r\n DefaultRetryStrategy: RetryStrategy.ExponentialBackoff(),\r\n\r\n /**\r\n * Gets or sets the base URL to use to load assets\r\n */\r\n BaseUrl: \"\",\r\n\r\n /**\r\n * Default behaviour for cors in the application.\r\n * It can be a string if the expected behavior is identical in the entire app.\r\n * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)\r\n */\r\n CorsBehavior: \"anonymous\",\r\n\r\n /**\r\n * Gets or sets a function used to pre-process url before using them to load assets\r\n * @param url\r\n */\r\n PreprocessUrl: (url: string) => {\r\n return url;\r\n },\r\n};\r\n\r\n/**\r\n * Removes unwanted characters from an url\r\n * @param url defines the url to clean\r\n * @returns the cleaned url\r\n */\r\nconst _CleanUrl = (url: string): string => {\r\n url = url.replace(/#/gm, \"%23\");\r\n return url;\r\n};\r\n\r\n/**\r\n * Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.\r\n * @param url define the url we are trying\r\n * @param element define the dom element where to configure the cors policy\r\n * @internal\r\n */\r\nexport const SetCorsBehavior = (url: string | string[], element: { crossOrigin: string | null }): void => {\r\n if (url && url.indexOf(\"data:\") === 0) {\r\n return;\r\n }\r\n\r\n if (FileToolsOptions.CorsBehavior) {\r\n if (typeof FileToolsOptions.CorsBehavior === \"string\" || FileToolsOptions.CorsBehavior instanceof String) {\r\n element.crossOrigin = FileToolsOptions.CorsBehavior;\r\n } else {\r\n const result = FileToolsOptions.CorsBehavior(url);\r\n if (result) {\r\n element.crossOrigin = result;\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Loads an image as an HTMLImageElement.\r\n * @param input url string, ArrayBuffer, or Blob to load\r\n * @param onLoad callback called when the image successfully loads\r\n * @param onError callback called when the image fails to load\r\n * @param offlineProvider offline provider for caching\r\n * @param mimeType optional mime type\r\n * @param imageBitmapOptions\r\n * @returns the HTMLImageElement of the loaded image\r\n * @internal\r\n */\r\nexport const LoadImage = (\r\n input: string | ArrayBuffer | ArrayBufferView | Blob,\r\n onLoad: (img: HTMLImageElement | ImageBitmap) => void,\r\n onError: (message?: string, exception?: any) => void,\r\n offlineProvider: Nullable,\r\n mimeType: string = \"\",\r\n imageBitmapOptions?: ImageBitmapOptions\r\n): Nullable => {\r\n let url: string;\r\n let usingObjectURL = false;\r\n\r\n if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {\r\n if (typeof Blob !== \"undefined\" && typeof URL !== \"undefined\") {\r\n url = URL.createObjectURL(new Blob([input], { type: mimeType }));\r\n usingObjectURL = true;\r\n } else {\r\n url = `data:${mimeType};base64,` + EncodeArrayBufferToBase64(input);\r\n }\r\n } else if (input instanceof Blob) {\r\n url = URL.createObjectURL(input);\r\n usingObjectURL = true;\r\n } else {\r\n url = _CleanUrl(input);\r\n url = FileToolsOptions.PreprocessUrl(input);\r\n }\r\n\r\n const engine = EngineStore.LastCreatedEngine;\r\n\r\n const onErrorHandler = (exception: any) => {\r\n if (onError) {\r\n const inputText = url || input.toString();\r\n onError(`Error while trying to load image: ${inputText.indexOf(\"http\") === 0 || inputText.length <= 128 ? inputText : inputText.slice(0, 128) + \"...\"}`, exception);\r\n }\r\n };\r\n\r\n if (typeof Image === \"undefined\" || (engine?._features.forceBitmapOverHTMLImageElement ?? false)) {\r\n LoadFile(\r\n url,\r\n (data) => {\r\n engine!\r\n .createImageBitmap(new Blob([data], { type: mimeType }), { premultiplyAlpha: \"none\", ...imageBitmapOptions })\r\n .then((imgBmp) => {\r\n onLoad(imgBmp);\r\n if (usingObjectURL) {\r\n URL.revokeObjectURL(url);\r\n }\r\n })\r\n .catch((reason) => {\r\n if (onError) {\r\n onError(\"Error while trying to load image: \" + input, reason);\r\n }\r\n });\r\n },\r\n undefined,\r\n offlineProvider || undefined,\r\n true,\r\n (request, exception) => {\r\n onErrorHandler(exception);\r\n }\r\n );\r\n\r\n return null;\r\n }\r\n\r\n const img = new Image();\r\n SetCorsBehavior(url, img);\r\n\r\n const handlersList: { target: any; name: string; handler: any }[] = [];\r\n\r\n const loadHandlersList = () => {\r\n handlersList.forEach((handler) => {\r\n handler.target.addEventListener(handler.name, handler.handler);\r\n });\r\n };\r\n\r\n const unloadHandlersList = () => {\r\n handlersList.forEach((handler) => {\r\n handler.target.removeEventListener(handler.name, handler.handler);\r\n });\r\n handlersList.length = 0;\r\n };\r\n\r\n const loadHandler = () => {\r\n unloadHandlersList();\r\n\r\n onLoad(img);\r\n\r\n // Must revoke the URL after calling onLoad to avoid security exceptions in\r\n // certain scenarios (e.g. when hosted in vscode).\r\n if (usingObjectURL && img.src) {\r\n URL.revokeObjectURL(img.src);\r\n }\r\n };\r\n\r\n const errorHandler = (err: any) => {\r\n unloadHandlersList();\r\n\r\n onErrorHandler(err);\r\n\r\n if (usingObjectURL && img.src) {\r\n URL.revokeObjectURL(img.src);\r\n }\r\n };\r\n\r\n const cspHandler = (err: any) => {\r\n if (err.blockedURI !== img.src) {\r\n return;\r\n }\r\n\r\n unloadHandlersList();\r\n const cspException = new Error(`CSP violation of policy ${err.effectiveDirective} ${err.blockedURI}. Current policy is ${err.originalPolicy}`);\r\n\r\n EngineStore.UseFallbackTexture = false;\r\n onErrorHandler(cspException);\r\n if (usingObjectURL && img.src) {\r\n URL.revokeObjectURL(img.src);\r\n }\r\n img.src = \"\";\r\n };\r\n\r\n handlersList.push({ target: img, name: \"load\", handler: loadHandler });\r\n handlersList.push({ target: img, name: \"error\", handler: errorHandler });\r\n handlersList.push({ target: document, name: \"securitypolicyviolation\", handler: cspHandler });\r\n\r\n loadHandlersList();\r\n\r\n const fromBlob = url.substring(0, 5) === \"blob:\";\r\n const fromData = url.substring(0, 5) === \"data:\";\r\n const noOfflineSupport = () => {\r\n if (fromBlob || fromData) {\r\n img.src = url;\r\n } else {\r\n LoadFile(\r\n url,\r\n (data, _, contentType) => {\r\n const type = !mimeType && contentType ? contentType : mimeType;\r\n const blob = new Blob([data], { type });\r\n const url = URL.createObjectURL(blob);\r\n usingObjectURL = true;\r\n img.src = url;\r\n },\r\n undefined,\r\n offlineProvider || undefined,\r\n true,\r\n (request, exception) => {\r\n onErrorHandler(exception);\r\n }\r\n );\r\n }\r\n };\r\n\r\n const loadFromOfflineSupport = () => {\r\n if (offlineProvider) {\r\n offlineProvider.loadImage(url, img);\r\n }\r\n };\r\n\r\n if (!fromBlob && !fromData && offlineProvider && offlineProvider.enableTexturesOffline) {\r\n offlineProvider.open(loadFromOfflineSupport, noOfflineSupport);\r\n } else {\r\n if (url.indexOf(\"file:\") !== -1) {\r\n const textureName = decodeURIComponent(url.substring(5).toLowerCase());\r\n if (FilesInputStore.FilesToLoad[textureName] && typeof URL !== \"undefined\") {\r\n try {\r\n let blobURL;\r\n try {\r\n blobURL = URL.createObjectURL(FilesInputStore.FilesToLoad[textureName]);\r\n } catch (ex) {\r\n // Chrome doesn't support oneTimeOnly parameter\r\n blobURL = URL.createObjectURL(FilesInputStore.FilesToLoad[textureName]);\r\n }\r\n img.src = blobURL;\r\n usingObjectURL = true;\r\n } catch (e) {\r\n img.src = \"\";\r\n }\r\n return img;\r\n }\r\n }\r\n\r\n noOfflineSupport();\r\n }\r\n\r\n return img;\r\n};\r\n\r\n/**\r\n * Reads a file from a File object\r\n * @param file defines the file to load\r\n * @param onSuccess defines the callback to call when data is loaded\r\n * @param onProgress defines the callback to call during loading process\r\n * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer\r\n * @param onError defines the callback to call when an error occurs\r\n * @returns a file request object\r\n * @internal\r\n */\r\nexport const ReadFile = (\r\n file: File,\r\n onSuccess: (data: any) => void,\r\n onProgress?: (ev: ProgressEvent) => any,\r\n useArrayBuffer?: boolean,\r\n onError?: (error: ReadFileError) => void\r\n): IFileRequest => {\r\n const reader = new FileReader();\r\n const fileRequest: IFileRequest = {\r\n onCompleteObservable: new Observable(),\r\n abort: () => reader.abort(),\r\n };\r\n\r\n reader.onloadend = () => fileRequest.onCompleteObservable.notifyObservers(fileRequest);\r\n if (onError) {\r\n reader.onerror = () => {\r\n onError(new ReadFileError(`Unable to read ${file.name}`, file));\r\n };\r\n }\r\n reader.onload = (e) => {\r\n //target doesn't have result from ts 1.3\r\n onSuccess((e.target)[\"result\"]);\r\n };\r\n if (onProgress) {\r\n reader.onprogress = onProgress;\r\n }\r\n if (!useArrayBuffer) {\r\n // Asynchronous read\r\n reader.readAsText(file);\r\n } else {\r\n reader.readAsArrayBuffer(file);\r\n }\r\n\r\n return fileRequest;\r\n};\r\n\r\n/**\r\n * Loads a file from a url, a data url, or a file url\r\n * @param fileOrUrl file, url, data url, or file url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @param onOpened\r\n * @returns a file request object\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport const LoadFile = (\r\n fileOrUrl: File | string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string, contentType?: Nullable) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void,\r\n onOpened?: (request: WebRequest) => void\r\n): IFileRequest => {\r\n if ((fileOrUrl as File).name) {\r\n return ReadFile(\r\n fileOrUrl as File,\r\n onSuccess,\r\n onProgress,\r\n useArrayBuffer,\r\n onError\r\n ? (error: ReadFileError) => {\r\n onError(undefined, error);\r\n }\r\n : undefined\r\n );\r\n }\r\n\r\n const url = fileOrUrl as string;\r\n\r\n // If file and file input are set\r\n if (url.indexOf(\"file:\") !== -1) {\r\n let fileName = decodeURIComponent(url.substring(5).toLowerCase());\r\n if (fileName.indexOf(\"./\") === 0) {\r\n fileName = fileName.substring(2);\r\n }\r\n const file = FilesInputStore.FilesToLoad[fileName];\r\n if (file) {\r\n return ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError ? (error) => onError(undefined, new LoadFileError(error.message, error.file)) : undefined);\r\n }\r\n }\r\n\r\n // For a Base64 Data URL\r\n const { match, type } = TestBase64DataUrl(url);\r\n if (match) {\r\n const fileRequest: IFileRequest = {\r\n onCompleteObservable: new Observable(),\r\n abort: () => () => {},\r\n };\r\n\r\n try {\r\n const data = useArrayBuffer ? DecodeBase64UrlToBinary(url) : DecodeBase64UrlToString(url);\r\n onSuccess(data, undefined, type);\r\n } catch (error) {\r\n if (onError) {\r\n onError(undefined, error);\r\n } else {\r\n Logger.Error(error.message || \"Failed to parse the Data URL\");\r\n }\r\n }\r\n\r\n TimingTools.SetImmediate(() => {\r\n fileRequest.onCompleteObservable.notifyObservers(fileRequest);\r\n });\r\n\r\n return fileRequest;\r\n }\r\n\r\n return RequestFile(\r\n url,\r\n (data, request) => {\r\n onSuccess(data, request?.responseURL, request?.getResponseHeader(\"content-type\"));\r\n },\r\n onProgress,\r\n offlineProvider,\r\n useArrayBuffer,\r\n onError\r\n ? (error) => {\r\n onError(error.request, new LoadFileError(error.message, error.request));\r\n }\r\n : undefined,\r\n onOpened\r\n );\r\n};\r\n\r\n/**\r\n * Loads a file from a url\r\n * @param url url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @param onOpened callback called when the web request is opened\r\n * @returns a file request object\r\n * @internal\r\n */\r\nexport const RequestFile = (\r\n url: string,\r\n onSuccess?: (data: string | ArrayBuffer, request?: WebRequest) => void,\r\n onProgress?: (event: ProgressEvent) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (error: RequestFileError) => void,\r\n onOpened?: (request: WebRequest) => void\r\n): IFileRequest => {\r\n url = _CleanUrl(url);\r\n url = FileToolsOptions.PreprocessUrl(url);\r\n\r\n const loadUrl = FileToolsOptions.BaseUrl + url;\r\n\r\n let aborted = false;\r\n const fileRequest: IFileRequest = {\r\n onCompleteObservable: new Observable(),\r\n abort: () => (aborted = true),\r\n };\r\n\r\n const requestFile = () => {\r\n let request: Nullable = new WebRequest();\r\n let retryHandle: Nullable> = null;\r\n let onReadyStateChange: Nullable<() => void>;\r\n\r\n const unbindEvents = () => {\r\n if (!request) {\r\n return;\r\n }\r\n\r\n if (onProgress) {\r\n request.removeEventListener(\"progress\", onProgress);\r\n }\r\n if (onReadyStateChange) {\r\n request.removeEventListener(\"readystatechange\", onReadyStateChange);\r\n }\r\n request.removeEventListener(\"loadend\", onLoadEnd!);\r\n };\r\n\r\n let onLoadEnd: Nullable<() => void> = () => {\r\n unbindEvents();\r\n\r\n fileRequest.onCompleteObservable.notifyObservers(fileRequest);\r\n fileRequest.onCompleteObservable.clear();\r\n\r\n onProgress = undefined;\r\n onReadyStateChange = null;\r\n onLoadEnd = null;\r\n onError = undefined;\r\n onOpened = undefined;\r\n onSuccess = undefined;\r\n };\r\n\r\n fileRequest.abort = () => {\r\n aborted = true;\r\n\r\n if (onLoadEnd) {\r\n onLoadEnd();\r\n }\r\n\r\n if (request && request.readyState !== (XMLHttpRequest.DONE || 4)) {\r\n request.abort();\r\n }\r\n\r\n if (retryHandle !== null) {\r\n clearTimeout(retryHandle);\r\n retryHandle = null;\r\n }\r\n\r\n request = null;\r\n };\r\n\r\n const handleError = (error: any) => {\r\n const message = error.message || \"Unknown error\";\r\n if (onError && request) {\r\n onError(new RequestFileError(message, request));\r\n } else {\r\n Logger.Error(message);\r\n }\r\n };\r\n\r\n const retryLoop = (retryIndex: number) => {\r\n if (!request) {\r\n return;\r\n }\r\n request.open(\"GET\", loadUrl);\r\n\r\n if (onOpened) {\r\n try {\r\n onOpened(request);\r\n } catch (e) {\r\n handleError(e);\r\n return;\r\n }\r\n }\r\n\r\n if (useArrayBuffer) {\r\n request.responseType = \"arraybuffer\";\r\n }\r\n\r\n if (onProgress) {\r\n request.addEventListener(\"progress\", onProgress);\r\n }\r\n\r\n if (onLoadEnd) {\r\n request.addEventListener(\"loadend\", onLoadEnd);\r\n }\r\n\r\n onReadyStateChange = () => {\r\n if (aborted || !request) {\r\n return;\r\n }\r\n\r\n // In case of undefined state in some browsers.\r\n if (request.readyState === (XMLHttpRequest.DONE || 4)) {\r\n // Some browsers have issues where onreadystatechange can be called multiple times with the same value.\r\n if (onReadyStateChange) {\r\n request.removeEventListener(\"readystatechange\", onReadyStateChange);\r\n }\r\n\r\n if ((request.status >= 200 && request.status < 300) || (request.status === 0 && (!IsWindowObjectExist() || IsFileURL()))) {\r\n try {\r\n if (onSuccess) {\r\n onSuccess(useArrayBuffer ? request.response : request.responseText, request);\r\n }\r\n } catch (e) {\r\n handleError(e);\r\n }\r\n return;\r\n }\r\n\r\n const retryStrategy = FileToolsOptions.DefaultRetryStrategy;\r\n if (retryStrategy) {\r\n const waitTime = retryStrategy(loadUrl, request, retryIndex);\r\n if (waitTime !== -1) {\r\n // Prevent the request from completing for retry.\r\n unbindEvents();\r\n\r\n request = new WebRequest();\r\n retryHandle = setTimeout(() => retryLoop(retryIndex + 1), waitTime);\r\n return;\r\n }\r\n }\r\n\r\n const error = new RequestFileError(\"Error status: \" + request.status + \" \" + request.statusText + \" - Unable to load \" + loadUrl, request);\r\n if (onError) {\r\n onError(error);\r\n }\r\n }\r\n };\r\n\r\n request.addEventListener(\"readystatechange\", onReadyStateChange);\r\n\r\n request.send();\r\n };\r\n\r\n retryLoop(0);\r\n };\r\n\r\n // Caching all files\r\n if (offlineProvider && offlineProvider.enableSceneOffline) {\r\n const noOfflineSupport = (request?: any) => {\r\n if (request && request.status > 400) {\r\n if (onError) {\r\n onError(request);\r\n }\r\n } else {\r\n requestFile();\r\n }\r\n };\r\n\r\n const loadFromOfflineSupport = () => {\r\n // TODO: database needs to support aborting and should return a IFileRequest\r\n\r\n if (offlineProvider) {\r\n offlineProvider.loadFile(\r\n FileToolsOptions.BaseUrl + url,\r\n (data) => {\r\n if (!aborted && onSuccess) {\r\n onSuccess(data);\r\n }\r\n\r\n fileRequest.onCompleteObservable.notifyObservers(fileRequest);\r\n },\r\n onProgress\r\n ? (event) => {\r\n if (!aborted && onProgress) {\r\n onProgress(event);\r\n }\r\n }\r\n : undefined,\r\n noOfflineSupport,\r\n useArrayBuffer\r\n );\r\n }\r\n };\r\n\r\n offlineProvider.open(loadFromOfflineSupport, noOfflineSupport);\r\n } else {\r\n requestFile();\r\n }\r\n\r\n return fileRequest;\r\n};\r\n\r\n/**\r\n * Checks if the loaded document was accessed via `file:`-Protocol.\r\n * @returns boolean\r\n * @internal\r\n */\r\nexport const IsFileURL = (): boolean => {\r\n return typeof location !== \"undefined\" && location.protocol === \"file:\";\r\n};\r\n\r\n/**\r\n * Test if the given uri is a valid base64 data url\r\n * @param uri The uri to test\r\n * @returns True if the uri is a base64 data url or false otherwise\r\n * @internal\r\n */\r\nexport const IsBase64DataUrl = (uri: string): boolean => {\r\n return Base64DataUrlRegEx.test(uri);\r\n};\r\n\r\nexport const TestBase64DataUrl = (uri: string): { match: boolean; type: string } => {\r\n const results = Base64DataUrlRegEx.exec(uri);\r\n if (results === null || results.length === 0) {\r\n return { match: false, type: \"\" };\r\n } else {\r\n const type = results[0].replace(\"data:\", \"\").replace(\"base64,\", \"\");\r\n return { match: true, type };\r\n }\r\n};\r\n\r\n/**\r\n * Decode the given base64 uri.\r\n * @param uri The uri to decode\r\n * @returns The decoded base64 data.\r\n * @internal\r\n */\r\nexport function DecodeBase64UrlToBinary(uri: string): ArrayBuffer {\r\n return DecodeBase64ToBinary(uri.split(\",\")[1]);\r\n}\r\n\r\n/**\r\n * Decode the given base64 uri into a UTF-8 encoded string.\r\n * @param uri The uri to decode\r\n * @returns The decoded base64 data.\r\n * @internal\r\n */\r\nexport const DecodeBase64UrlToString = (uri: string): string => {\r\n return DecodeBase64ToString(uri.split(\",\")[1]);\r\n};\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n ThinEngine._FileToolsLoadImage = LoadImage;\r\n ThinEngine._FileToolsLoadFile = LoadFile;\r\n ShaderProcessor._FileToolsLoadFile = LoadFile;\r\n};\r\n\r\ninitSideEffects();\r\n\r\n// deprecated\r\n\r\n/**\r\n * FileTools defined as any.\r\n * This should not be imported or used in future releases or in any module in the framework\r\n * @internal\r\n * @deprecated import the needed function from fileTools.ts\r\n */\r\nexport let FileTools: {\r\n DecodeBase64UrlToBinary: (uri: string) => ArrayBuffer;\r\n DecodeBase64UrlToString: (uri: string) => string;\r\n DefaultRetryStrategy: any;\r\n BaseUrl: any;\r\n CorsBehavior: any;\r\n PreprocessUrl: any;\r\n IsBase64DataUrl: (uri: string) => boolean;\r\n IsFileURL: () => boolean;\r\n LoadFile: (\r\n fileOrUrl: string | File,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string | undefined) => void,\r\n onProgress?: ((ev: ProgressEvent) => void) | undefined,\r\n offlineProvider?: IOfflineProvider | undefined,\r\n useArrayBuffer?: boolean | undefined,\r\n onError?: ((request?: WebRequest | undefined, exception?: LoadFileError | undefined) => void) | undefined,\r\n onOpened?: ((request: WebRequest) => void) | undefined\r\n ) => IFileRequest;\r\n LoadImage: (\r\n input: string | ArrayBuffer | Blob | ArrayBufferView,\r\n onLoad: (img: HTMLImageElement | ImageBitmap) => void,\r\n onError: (message?: string | undefined, exception?: any) => void,\r\n offlineProvider: Nullable,\r\n mimeType?: string | undefined,\r\n imageBitmapOptions?: ImageBitmapOptions | undefined\r\n ) => Nullable;\r\n ReadFile: (\r\n file: File,\r\n onSuccess: (data: any) => void,\r\n onProgress?: ((ev: ProgressEvent) => any) | undefined,\r\n useArrayBuffer?: boolean | undefined,\r\n onError?: ((error: ReadFileError) => void) | undefined\r\n ) => IFileRequest;\r\n RequestFile: (\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, request?: WebRequest | undefined) => void,\r\n onProgress?: ((event: ProgressEvent) => void) | undefined,\r\n offlineProvider?: IOfflineProvider | undefined,\r\n useArrayBuffer?: boolean | undefined,\r\n onError?: ((error: RequestFileError) => void) | undefined,\r\n onOpened?: ((request: WebRequest) => void) | undefined\r\n ) => IFileRequest;\r\n SetCorsBehavior: (url: string | string[], element: { crossOrigin: string | null }) => void;\r\n};\r\n/**\r\n * @param DecodeBase64UrlToBinary\r\n * @param DecodeBase64UrlToString\r\n * @param FileToolsOptions\r\n * @internal\r\n */\r\nexport const _injectLTSFileTools = (\r\n DecodeBase64UrlToBinary: (uri: string) => ArrayBuffer,\r\n DecodeBase64UrlToString: (uri: string) => string,\r\n FileToolsOptions: { DefaultRetryStrategy: any; BaseUrl: any; CorsBehavior: any; PreprocessUrl: any },\r\n IsBase64DataUrl: (uri: string) => boolean,\r\n IsFileURL: () => boolean,\r\n LoadFile: (\r\n fileOrUrl: string | File,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string | undefined) => void,\r\n onProgress?: ((ev: ProgressEvent) => void) | undefined,\r\n offlineProvider?: IOfflineProvider | undefined,\r\n useArrayBuffer?: boolean | undefined,\r\n onError?: ((request?: WebRequest | undefined, exception?: LoadFileError | undefined) => void) | undefined,\r\n onOpened?: ((request: WebRequest) => void) | undefined\r\n ) => IFileRequest,\r\n LoadImage: (\r\n input: string | ArrayBuffer | ArrayBufferView | Blob,\r\n onLoad: (img: HTMLImageElement | ImageBitmap) => void,\r\n onError: (message?: string | undefined, exception?: any) => void,\r\n offlineProvider: Nullable,\r\n mimeType?: string,\r\n imageBitmapOptions?: ImageBitmapOptions | undefined\r\n ) => Nullable,\r\n ReadFile: (\r\n file: File,\r\n onSuccess: (data: any) => void,\r\n onProgress?: ((ev: ProgressEvent) => any) | undefined,\r\n useArrayBuffer?: boolean | undefined,\r\n onError?: ((error: ReadFileError) => void) | undefined\r\n ) => IFileRequest,\r\n RequestFile: (\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, request?: WebRequest | undefined) => void,\r\n onProgress?: ((event: ProgressEvent) => void) | undefined,\r\n offlineProvider?: IOfflineProvider | undefined,\r\n useArrayBuffer?: boolean | undefined,\r\n onError?: ((error: RequestFileError) => void) | undefined,\r\n onOpened?: ((request: WebRequest) => void) | undefined\r\n ) => IFileRequest,\r\n SetCorsBehavior: (url: string | string[], element: { crossOrigin: string | null }) => void\r\n) => {\r\n /**\r\n * Backwards compatibility.\r\n * @internal\r\n * @deprecated\r\n */\r\n FileTools = {\r\n DecodeBase64UrlToBinary,\r\n DecodeBase64UrlToString,\r\n DefaultRetryStrategy: FileToolsOptions.DefaultRetryStrategy,\r\n BaseUrl: FileToolsOptions.BaseUrl,\r\n CorsBehavior: FileToolsOptions.CorsBehavior,\r\n PreprocessUrl: FileToolsOptions.PreprocessUrl,\r\n IsBase64DataUrl,\r\n IsFileURL,\r\n LoadFile,\r\n LoadImage,\r\n ReadFile,\r\n RequestFile,\r\n SetCorsBehavior,\r\n };\r\n\r\n Object.defineProperty(FileTools, \"DefaultRetryStrategy\", {\r\n get: function (this: null) {\r\n return FileToolsOptions.DefaultRetryStrategy;\r\n },\r\n set: function (this: null, value: (url: string, request: WebRequest, retryIndex: number) => number) {\r\n FileToolsOptions.DefaultRetryStrategy = value;\r\n },\r\n });\r\n\r\n Object.defineProperty(FileTools, \"BaseUrl\", {\r\n get: function (this: null) {\r\n return FileToolsOptions.BaseUrl;\r\n },\r\n set: function (this: null, value: string) {\r\n FileToolsOptions.BaseUrl = value;\r\n },\r\n });\r\n\r\n Object.defineProperty(FileTools, \"PreprocessUrl\", {\r\n get: function (this: null) {\r\n return FileToolsOptions.PreprocessUrl;\r\n },\r\n set: function (this: null, value: (url: string) => string) {\r\n FileToolsOptions.PreprocessUrl = value;\r\n },\r\n });\r\n\r\n Object.defineProperty(FileTools, \"CorsBehavior\", {\r\n get: function (this: null) {\r\n return FileToolsOptions.CorsBehavior;\r\n },\r\n set: function (this: null, value: string | ((url: string | string[]) => string)) {\r\n FileToolsOptions.CorsBehavior = value;\r\n },\r\n });\r\n};\r\n\r\n_injectLTSFileTools(DecodeBase64UrlToBinary, DecodeBase64UrlToString, FileToolsOptions, IsBase64DataUrl, IsFileURL, LoadFile, LoadImage, ReadFile, RequestFile, SetCorsBehavior);\r\n","import type { WebRequest } from \"./webRequest\";\r\n\r\n/**\r\n * Class used to define a retry strategy when error happens while loading assets\r\n */\r\nexport class RetryStrategy {\r\n /**\r\n * Function used to defines an exponential back off strategy\r\n * @param maxRetries defines the maximum number of retries (3 by default)\r\n * @param baseInterval defines the interval between retries\r\n * @returns the strategy function to use\r\n */\r\n public static ExponentialBackoff(maxRetries = 3, baseInterval = 500) {\r\n return (url: string, request: WebRequest, retryIndex: number): number => {\r\n if (request.status !== 0 || retryIndex >= maxRetries || url.indexOf(\"file:\") !== -1) {\r\n return -1;\r\n }\r\n\r\n return Math.pow(2, retryIndex) * baseInterval;\r\n };\r\n }\r\n}\r\n","import { Logger } from \"./logger\";\r\nimport { GetClass } from \"./typeStore\";\r\n\r\n/**\r\n * Class used to enable instantiation of objects by class name\r\n */\r\nexport class InstantiationTools {\r\n /**\r\n * Use this object to register external classes like custom textures or material\r\n * to allow the loaders to instantiate them\r\n */\r\n public static RegisteredExternalClasses: { [key: string]: Object } = {};\r\n\r\n /**\r\n * Tries to instantiate a new object from a given class name\r\n * @param className defines the class name to instantiate\r\n * @returns the new object or null if the system was not able to do the instantiation\r\n */\r\n public static Instantiate(className: string): any {\r\n if (this.RegisteredExternalClasses && this.RegisteredExternalClasses[className]) {\r\n return this.RegisteredExternalClasses[className];\r\n }\r\n\r\n const internalClass = GetClass(className);\r\n if (internalClass) {\r\n return internalClass;\r\n }\r\n\r\n Logger.Warn(className + \" not found, you may have missed an import.\");\r\n\r\n const arr = className.split(\".\");\r\n\r\n let fn: any = window || this;\r\n for (let i = 0, len = arr.length; i < len; i++) {\r\n fn = fn[arr[i]];\r\n }\r\n\r\n if (typeof fn !== \"function\") {\r\n return null;\r\n }\r\n\r\n return fn;\r\n }\r\n}\r\n","/**\r\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\r\n * Be aware Math.random() could cause collisions, but:\r\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\r\n * @returns a pseudo random id\r\n */\r\nexport function RandomGUID(): string {\r\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\r\n const r = (Math.random() * 16) | 0,\r\n v = c === \"x\" ? r : (r & 0x3) | 0x8;\r\n return v.toString(16);\r\n });\r\n}\r\n/**\r\n * Class used to manipulate GUIDs\r\n */\r\nexport const GUID = {\r\n /**\r\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\r\n * Be aware Math.random() could cause collisions, but:\r\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\r\n * @returns a pseudo random id\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n RandomId: RandomGUID,\r\n};\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"./observable\";\r\nimport { GetDOMTextContent, IsNavigatorAvailable, IsWindowObjectExist } from \"./domManagement\";\r\nimport { Logger } from \"./logger\";\r\nimport { DeepCopier } from \"./deepCopier\";\r\nimport { PrecisionDate } from \"./precisionDate\";\r\nimport { _WarnImport } from \"./devTools\";\r\nimport { WebRequest } from \"./webRequest\";\r\nimport type { IFileRequest } from \"./fileRequest\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { ReadFileError } from \"./fileTools\";\r\nimport {\r\n FileToolsOptions,\r\n DecodeBase64UrlToBinary,\r\n IsBase64DataUrl,\r\n LoadFile as FileToolsLoadFile,\r\n LoadImage as FileToolLoadImage,\r\n ReadFile as FileToolsReadFile,\r\n SetCorsBehavior,\r\n} from \"./fileTools\";\r\nimport type { IOfflineProvider } from \"../Offline/IOfflineProvider\";\r\nimport { TimingTools } from \"./timingTools\";\r\nimport { InstantiationTools } from \"./instantiationTools\";\r\nimport { RandomGUID } from \"./guid\";\r\nimport type { IScreenshotSize } from \"./interfaces/screenshotSize\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { IColor4Like } from \"../Maths/math.like\";\r\n\r\ndeclare function importScripts(...urls: string[]): void;\r\n\r\n/**\r\n * Class containing a set of static utilities functions\r\n */\r\nexport class Tools {\r\n /**\r\n * Gets or sets the base URL to use to load assets\r\n */\r\n public static get BaseUrl() {\r\n return FileToolsOptions.BaseUrl;\r\n }\r\n\r\n public static set BaseUrl(value: string) {\r\n FileToolsOptions.BaseUrl = value;\r\n }\r\n\r\n /**\r\n * Enable/Disable Custom HTTP Request Headers globally.\r\n * default = false\r\n * @see CustomRequestHeaders\r\n */\r\n public static UseCustomRequestHeaders = false;\r\n\r\n /**\r\n * Custom HTTP Request Headers to be sent with XMLHttpRequests\r\n * i.e. when loading files, where the server/service expects an Authorization header\r\n */\r\n public static CustomRequestHeaders = WebRequest.CustomRequestHeaders;\r\n\r\n /**\r\n * Gets or sets the retry strategy to apply when an error happens while loading an asset\r\n */\r\n public static get DefaultRetryStrategy() {\r\n return FileToolsOptions.DefaultRetryStrategy;\r\n }\r\n\r\n public static set DefaultRetryStrategy(strategy: (url: string, request: WebRequest, retryIndex: number) => number) {\r\n FileToolsOptions.DefaultRetryStrategy = strategy;\r\n }\r\n\r\n /**\r\n * Default behaviour for cors in the application.\r\n * It can be a string if the expected behavior is identical in the entire app.\r\n * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)\r\n */\r\n public static get CorsBehavior(): string | ((url: string | string[]) => string) {\r\n return FileToolsOptions.CorsBehavior;\r\n }\r\n\r\n public static set CorsBehavior(value: string | ((url: string | string[]) => string)) {\r\n FileToolsOptions.CorsBehavior = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded\r\n * @ignorenaming\r\n */\r\n public static get UseFallbackTexture() {\r\n return EngineStore.UseFallbackTexture;\r\n }\r\n\r\n public static set UseFallbackTexture(value: boolean) {\r\n EngineStore.UseFallbackTexture = value;\r\n }\r\n\r\n /**\r\n * Use this object to register external classes like custom textures or material\r\n * to allow the loaders to instantiate them\r\n */\r\n public static get RegisteredExternalClasses() {\r\n return InstantiationTools.RegisteredExternalClasses;\r\n }\r\n\r\n public static set RegisteredExternalClasses(classes: { [key: string]: Object }) {\r\n InstantiationTools.RegisteredExternalClasses = classes;\r\n }\r\n\r\n /**\r\n * Texture content used if a texture cannot loaded\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static get fallbackTexture() {\r\n return EngineStore.FallbackTexture;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static set fallbackTexture(value: string) {\r\n EngineStore.FallbackTexture = value;\r\n }\r\n\r\n /**\r\n * Read the content of a byte array at a specified coordinates (taking in account wrapping)\r\n * @param u defines the coordinate on X axis\r\n * @param v defines the coordinate on Y axis\r\n * @param width defines the width of the source data\r\n * @param height defines the height of the source data\r\n * @param pixels defines the source byte array\r\n * @param color defines the output color\r\n */\r\n public static FetchToRef(u: number, v: number, width: number, height: number, pixels: Uint8Array, color: IColor4Like): void {\r\n const wrappedU = (Math.abs(u) * width) % width | 0;\r\n const wrappedV = (Math.abs(v) * height) % height | 0;\r\n\r\n const position = (wrappedU + wrappedV * width) * 4;\r\n color.r = pixels[position] / 255;\r\n color.g = pixels[position + 1] / 255;\r\n color.b = pixels[position + 2] / 255;\r\n color.a = pixels[position + 3] / 255;\r\n }\r\n\r\n /**\r\n * Interpolates between a and b via alpha\r\n * @param a The lower value (returned when alpha = 0)\r\n * @param b The upper value (returned when alpha = 1)\r\n * @param alpha The interpolation-factor\r\n * @returns The mixed value\r\n */\r\n public static Mix(a: number, b: number, alpha: number): number {\r\n return a * (1 - alpha) + b * alpha;\r\n }\r\n\r\n /**\r\n * Tries to instantiate a new object from a given class name\r\n * @param className defines the class name to instantiate\r\n * @returns the new object or null if the system was not able to do the instantiation\r\n */\r\n public static Instantiate(className: string): any {\r\n return InstantiationTools.Instantiate(className);\r\n }\r\n\r\n /**\r\n * Polyfill for setImmediate\r\n * @param action defines the action to execute after the current execution block\r\n */\r\n public static SetImmediate(action: () => void) {\r\n TimingTools.SetImmediate(action);\r\n }\r\n\r\n /**\r\n * Function indicating if a number is an exponent of 2\r\n * @param value defines the value to test\r\n * @returns true if the value is an exponent of 2\r\n */\r\n public static IsExponentOfTwo(value: number): boolean {\r\n let count = 1;\r\n\r\n do {\r\n count *= 2;\r\n } while (count < value);\r\n\r\n return count === value;\r\n }\r\n\r\n private static _TmpFloatArray = new Float32Array(1);\r\n\r\n /**\r\n * Returns the nearest 32-bit single precision float representation of a Number\r\n * @param value A Number. If the parameter is of a different type, it will get converted\r\n * to a number or to NaN if it cannot be converted\r\n * @returns number\r\n */\r\n public static FloatRound(value: number): number {\r\n if (Math.fround) {\r\n return Math.fround(value);\r\n }\r\n\r\n return (Tools._TmpFloatArray[0] = value), Tools._TmpFloatArray[0];\r\n }\r\n\r\n /**\r\n * Extracts the filename from a path\r\n * @param path defines the path to use\r\n * @returns the filename\r\n */\r\n public static GetFilename(path: string): string {\r\n const index = path.lastIndexOf(\"/\");\r\n if (index < 0) {\r\n return path;\r\n }\r\n\r\n return path.substring(index + 1);\r\n }\r\n\r\n /**\r\n * Extracts the \"folder\" part of a path (everything before the filename).\r\n * @param uri The URI to extract the info from\r\n * @param returnUnchangedIfNoSlash Do not touch the URI if no slashes are present\r\n * @returns The \"folder\" part of the path\r\n */\r\n public static GetFolderPath(uri: string, returnUnchangedIfNoSlash = false): string {\r\n const index = uri.lastIndexOf(\"/\");\r\n if (index < 0) {\r\n if (returnUnchangedIfNoSlash) {\r\n return uri;\r\n }\r\n return \"\";\r\n }\r\n\r\n return uri.substring(0, index + 1);\r\n }\r\n\r\n /**\r\n * Extracts text content from a DOM element hierarchy\r\n * Back Compat only, please use GetDOMTextContent instead.\r\n */\r\n public static GetDOMTextContent = GetDOMTextContent;\r\n\r\n /**\r\n * Convert an angle in radians to degrees\r\n * @param angle defines the angle to convert\r\n * @returns the angle in degrees\r\n */\r\n public static ToDegrees(angle: number): number {\r\n return (angle * 180) / Math.PI;\r\n }\r\n\r\n /**\r\n * Convert an angle in degrees to radians\r\n * @param angle defines the angle to convert\r\n * @returns the angle in radians\r\n */\r\n public static ToRadians(angle: number): number {\r\n return (angle * Math.PI) / 180;\r\n }\r\n\r\n /**\r\n * Smooth angle changes (kind of low-pass filter), in particular for device orientation \"shaking\"\r\n * Use trigonometric functions to avoid discontinuity (0/360, -180/180)\r\n * @param previousAngle defines last angle value, in degrees\r\n * @param newAngle defines new angle value, in degrees\r\n * @param smoothFactor defines smoothing sensitivity; min 0: no smoothing, max 1: new data ignored\r\n * @returns the angle in degrees\r\n */\r\n public static SmoothAngleChange(previousAngle: number, newAngle: number, smoothFactor = 0.9): number {\r\n const previousAngleRad = this.ToRadians(previousAngle);\r\n const newAngleRad = this.ToRadians(newAngle);\r\n return this.ToDegrees(\r\n Math.atan2(\r\n (1 - smoothFactor) * Math.sin(newAngleRad) + smoothFactor * Math.sin(previousAngleRad),\r\n (1 - smoothFactor) * Math.cos(newAngleRad) + smoothFactor * Math.cos(previousAngleRad)\r\n )\r\n );\r\n }\r\n\r\n /**\r\n * Returns an array if obj is not an array\r\n * @param obj defines the object to evaluate as an array\r\n * @param allowsNullUndefined defines a boolean indicating if obj is allowed to be null or undefined\r\n * @returns either obj directly if obj is an array or a new array containing obj\r\n */\r\n public static MakeArray(obj: any, allowsNullUndefined?: boolean): Nullable> {\r\n if (allowsNullUndefined !== true && (obj === undefined || obj == null)) {\r\n return null;\r\n }\r\n\r\n return Array.isArray(obj) ? obj : [obj];\r\n }\r\n\r\n /**\r\n * Gets the pointer prefix to use\r\n * @param engine defines the engine we are finding the prefix for\r\n * @returns \"pointer\" if touch is enabled. Else returns \"mouse\"\r\n */\r\n public static GetPointerPrefix(engine: Engine): string {\r\n let eventPrefix = \"pointer\";\r\n\r\n // Check if pointer events are supported\r\n if (IsWindowObjectExist() && !window.PointerEvent) {\r\n eventPrefix = \"mouse\";\r\n }\r\n\r\n // Special Fallback MacOS Safari...\r\n if (\r\n engine._badDesktopOS &&\r\n !engine._badOS &&\r\n // And not ipad pros who claim to be macs...\r\n !(document && \"ontouchend\" in document)\r\n ) {\r\n eventPrefix = \"mouse\";\r\n }\r\n\r\n return eventPrefix;\r\n }\r\n\r\n /**\r\n * Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.\r\n * @param url define the url we are trying\r\n * @param element define the dom element where to configure the cors policy\r\n * @param element.crossOrigin\r\n */\r\n public static SetCorsBehavior(url: string | string[], element: { crossOrigin: string | null }): void {\r\n SetCorsBehavior(url, element);\r\n }\r\n\r\n /**\r\n * Sets the referrerPolicy behavior on a dom element.\r\n * @param referrerPolicy define the referrer policy to use\r\n * @param element define the dom element where to configure the referrer policy\r\n * @param element.referrerPolicy\r\n */\r\n public static SetReferrerPolicyBehavior(referrerPolicy: Nullable, element: { referrerPolicy: string | null }): void {\r\n element.referrerPolicy = referrerPolicy;\r\n }\r\n\r\n // External files\r\n\r\n /**\r\n * Removes unwanted characters from an url\r\n * @param url defines the url to clean\r\n * @returns the cleaned url\r\n */\r\n public static CleanUrl(url: string): string {\r\n url = url.replace(/#/gm, \"%23\");\r\n return url;\r\n }\r\n\r\n /**\r\n * Gets or sets a function used to pre-process url before using them to load assets\r\n */\r\n public static get PreprocessUrl() {\r\n return FileToolsOptions.PreprocessUrl;\r\n }\r\n\r\n public static set PreprocessUrl(processor: (url: string) => string) {\r\n FileToolsOptions.PreprocessUrl = processor;\r\n }\r\n\r\n /**\r\n * Loads an image as an HTMLImageElement.\r\n * @param input url string, ArrayBuffer, or Blob to load\r\n * @param onLoad callback called when the image successfully loads\r\n * @param onError callback called when the image fails to load\r\n * @param offlineProvider offline provider for caching\r\n * @param mimeType optional mime type\r\n * @param imageBitmapOptions optional the options to use when creating an ImageBitmap\r\n * @returns the HTMLImageElement of the loaded image\r\n */\r\n public static LoadImage(\r\n input: string | ArrayBuffer | Blob,\r\n onLoad: (img: HTMLImageElement | ImageBitmap) => void,\r\n onError: (message?: string, exception?: any) => void,\r\n offlineProvider: Nullable,\r\n mimeType?: string,\r\n imageBitmapOptions?: ImageBitmapOptions\r\n ): Nullable {\r\n return FileToolLoadImage(input, onLoad, onError, offlineProvider, mimeType, imageBitmapOptions);\r\n }\r\n\r\n /**\r\n * Loads a file from a url\r\n * @param url url string, ArrayBuffer, or Blob to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param offlineProvider defines the offline provider for caching\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @returns a file request object\r\n */\r\n public static LoadFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (data: any) => void,\r\n offlineProvider?: IOfflineProvider,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: any) => void\r\n ): IFileRequest {\r\n return FileToolsLoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError);\r\n }\r\n\r\n /**\r\n * Loads a file from a url\r\n * @param url the file url to load\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @returns a promise containing an ArrayBuffer corresponding to the loaded file\r\n */\r\n public static LoadFileAsync(url: string, useArrayBuffer = true): Promise {\r\n return new Promise((resolve, reject) => {\r\n FileToolsLoadFile(\r\n url,\r\n (data) => {\r\n resolve(data);\r\n },\r\n undefined,\r\n undefined,\r\n useArrayBuffer,\r\n (request, exception) => {\r\n reject(exception);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Load a script (identified by an url). When the url returns, the\r\n * content of this file is added into a new script element, attached to the DOM (body element)\r\n * @param scriptUrl defines the url of the script to laod\r\n * @param onSuccess defines the callback called when the script is loaded\r\n * @param onError defines the callback to call if an error occurs\r\n * @param scriptId defines the id of the script element\r\n */\r\n public static LoadScript(scriptUrl: string, onSuccess: () => void, onError?: (message?: string, exception?: any) => void, scriptId?: string) {\r\n if (typeof importScripts === \"function\") {\r\n try {\r\n importScripts(scriptUrl);\r\n onSuccess();\r\n } catch (e) {\r\n onError?.(`Unable to load script '${scriptUrl}' in worker`, e);\r\n }\r\n return;\r\n } else if (!IsWindowObjectExist()) {\r\n onError?.(`Cannot load script '${scriptUrl}' outside of a window or a worker`);\r\n return;\r\n }\r\n const head = document.getElementsByTagName(\"head\")[0];\r\n const script = document.createElement(\"script\");\r\n script.setAttribute(\"type\", \"text/javascript\");\r\n script.setAttribute(\"src\", scriptUrl);\r\n if (scriptId) {\r\n script.id = scriptId;\r\n }\r\n\r\n script.onload = () => {\r\n if (onSuccess) {\r\n onSuccess();\r\n }\r\n };\r\n\r\n script.onerror = (e) => {\r\n if (onError) {\r\n onError(`Unable to load script '${scriptUrl}'`, e);\r\n }\r\n };\r\n\r\n head.appendChild(script);\r\n }\r\n\r\n /**\r\n * Load an asynchronous script (identified by an url). When the url returns, the\r\n * content of this file is added into a new script element, attached to the DOM (body element)\r\n * @param scriptUrl defines the url of the script to laod\r\n * @returns a promise request object\r\n */\r\n public static LoadScriptAsync(scriptUrl: string): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.LoadScript(\r\n scriptUrl,\r\n () => {\r\n resolve();\r\n },\r\n (message, exception) => {\r\n reject(exception || new Error(message));\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Loads a file from a blob\r\n * @param fileToLoad defines the blob to use\r\n * @param callback defines the callback to call when data is loaded\r\n * @param progressCallback defines the callback to call during loading process\r\n * @returns a file request object\r\n */\r\n public static ReadFileAsDataURL(fileToLoad: Blob, callback: (data: any) => void, progressCallback: (ev: ProgressEvent) => any): IFileRequest {\r\n const reader = new FileReader();\r\n\r\n const request: IFileRequest = {\r\n onCompleteObservable: new Observable(),\r\n abort: () => reader.abort(),\r\n };\r\n\r\n reader.onloadend = () => {\r\n request.onCompleteObservable.notifyObservers(request);\r\n };\r\n\r\n reader.onload = (e) => {\r\n //target doesn't have result from ts 1.3\r\n callback((e.target)[\"result\"]);\r\n };\r\n\r\n reader.onprogress = progressCallback;\r\n\r\n reader.readAsDataURL(fileToLoad);\r\n\r\n return request;\r\n }\r\n\r\n /**\r\n * Reads a file from a File object\r\n * @param file defines the file to load\r\n * @param onSuccess defines the callback to call when data is loaded\r\n * @param onProgress defines the callback to call during loading process\r\n * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer\r\n * @param onError defines the callback to call when an error occurs\r\n * @returns a file request object\r\n */\r\n public static ReadFile(\r\n file: File,\r\n onSuccess: (data: any) => void,\r\n onProgress?: (ev: ProgressEvent) => any,\r\n useArrayBuffer?: boolean,\r\n onError?: (error: ReadFileError) => void\r\n ): IFileRequest {\r\n return FileToolsReadFile(file, onSuccess, onProgress, useArrayBuffer, onError);\r\n }\r\n\r\n /**\r\n * Creates a data url from a given string content\r\n * @param content defines the content to convert\r\n * @returns the new data url link\r\n */\r\n public static FileAsURL(content: string): string {\r\n const fileBlob = new Blob([content]);\r\n const url = window.URL;\r\n const link: string = url.createObjectURL(fileBlob);\r\n return link;\r\n }\r\n\r\n /**\r\n * Format the given number to a specific decimal format\r\n * @param value defines the number to format\r\n * @param decimals defines the number of decimals to use\r\n * @returns the formatted string\r\n */\r\n public static Format(value: number, decimals = 2): string {\r\n return value.toFixed(decimals);\r\n }\r\n\r\n /**\r\n * Tries to copy an object by duplicating every property\r\n * @param source defines the source object\r\n * @param destination defines the target object\r\n * @param doNotCopyList defines a list of properties to avoid\r\n * @param mustCopyList defines a list of properties to copy (even if they start with _)\r\n */\r\n public static DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void {\r\n DeepCopier.DeepCopy(source, destination, doNotCopyList, mustCopyList);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the given object has no own property\r\n * @param obj defines the object to test\r\n * @returns true if object has no own property\r\n */\r\n public static IsEmpty(obj: any): boolean {\r\n for (const i in obj) {\r\n if (Object.prototype.hasOwnProperty.call(obj, i)) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Function used to register events at window level\r\n * @param windowElement defines the Window object to use\r\n * @param events defines the events to register\r\n */\r\n public static RegisterTopRootEvents(windowElement: Window, events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {\r\n for (let index = 0; index < events.length; index++) {\r\n const event = events[index];\r\n windowElement.addEventListener(event.name, event.handler, false);\r\n\r\n try {\r\n if (window.parent) {\r\n window.parent.addEventListener(event.name, event.handler, false);\r\n }\r\n } catch (e) {\r\n // Silently fails...\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Function used to unregister events from window level\r\n * @param windowElement defines the Window object to use\r\n * @param events defines the events to unregister\r\n */\r\n public static UnregisterTopRootEvents(windowElement: Window, events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {\r\n for (let index = 0; index < events.length; index++) {\r\n const event = events[index];\r\n windowElement.removeEventListener(event.name, event.handler);\r\n\r\n try {\r\n if (windowElement.parent) {\r\n windowElement.parent.removeEventListener(event.name, event.handler);\r\n }\r\n } catch (e) {\r\n // Silently fails...\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Dumps the current bound framebuffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param engine defines the hosting engine\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a void promise\r\n */\r\n public static async DumpFramebuffer(\r\n width: number,\r\n height: number,\r\n engine: Engine,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n ) {\r\n throw _WarnImport(\"DumpTools\");\r\n }\r\n\r\n /**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n public static DumpData(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n successCallback?: (data: string | ArrayBuffer) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n ) {\r\n throw _WarnImport(\"DumpTools\");\r\n }\r\n\r\n /**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a promise that resolve to the final data\r\n */\r\n public static DumpDataAsync(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n ): Promise {\r\n throw _WarnImport(\"DumpTools\");\r\n }\r\n\r\n private static _IsOffScreenCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): canvas is OffscreenCanvas {\r\n return (canvas as OffscreenCanvas).convertToBlob !== undefined;\r\n }\r\n\r\n /**\r\n * Converts the canvas data to blob.\r\n * This acts as a polyfill for browsers not supporting the to blob function.\r\n * @param canvas Defines the canvas to extract the data from (can be an offscreen canvas)\r\n * @param successCallback Defines the callback triggered once the data are available\r\n * @param mimeType Defines the mime type of the result\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n static ToBlob(canvas: HTMLCanvasElement | OffscreenCanvas, successCallback: (blob: Nullable) => void, mimeType = \"image/png\", quality?: number): void {\r\n // We need HTMLCanvasElement.toBlob for HD screenshots\r\n if (!Tools._IsOffScreenCanvas(canvas) && !canvas.toBlob) {\r\n // low performance polyfill based on toDataURL (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob)\r\n canvas.toBlob = function (callback, type, quality) {\r\n setTimeout(() => {\r\n const binStr = atob(this.toDataURL(type, quality).split(\",\")[1]),\r\n len = binStr.length,\r\n arr = new Uint8Array(len);\r\n\r\n for (let i = 0; i < len; i++) {\r\n arr[i] = binStr.charCodeAt(i);\r\n }\r\n callback(new Blob([arr]));\r\n });\r\n };\r\n }\r\n if (Tools._IsOffScreenCanvas(canvas)) {\r\n canvas\r\n .convertToBlob({\r\n type: mimeType,\r\n quality,\r\n })\r\n .then((blob) => successCallback(blob));\r\n } else {\r\n canvas.toBlob(\r\n function (blob) {\r\n successCallback(blob);\r\n },\r\n mimeType,\r\n quality\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Download a Blob object\r\n * @param blob the Blob object\r\n * @param fileName the file name to download\r\n * @returns\r\n */\r\n static DownloadBlob(blob: Blob, fileName?: string) {\r\n //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.\r\n if (\"download\" in document.createElement(\"a\")) {\r\n if (!fileName) {\r\n const date = new Date();\r\n const stringDate =\r\n (date.getFullYear() + \"-\" + (date.getMonth() + 1)).slice(2) + \"-\" + date.getDate() + \"_\" + date.getHours() + \"-\" + (\"0\" + date.getMinutes()).slice(-2);\r\n fileName = \"screenshot_\" + stringDate + \".png\";\r\n }\r\n Tools.Download(blob, fileName);\r\n } else {\r\n if (blob && typeof URL !== \"undefined\") {\r\n const url = URL.createObjectURL(blob);\r\n\r\n const newWindow = window.open(\"\");\r\n if (!newWindow) {\r\n return;\r\n }\r\n const img = newWindow.document.createElement(\"img\");\r\n img.onload = function () {\r\n // no longer need to read the blob so it's revoked\r\n URL.revokeObjectURL(url);\r\n };\r\n img.src = url;\r\n newWindow.document.body.appendChild(img);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Encodes the canvas data to base 64, or automatically downloads the result if `fileName` is defined.\r\n * @param canvas The canvas to get the data from, which can be an offscreen canvas.\r\n * @param successCallback The callback which is triggered once the data is available. If `fileName` is defined, the callback will be invoked after the download occurs, and the `data` argument will be an empty string.\r\n * @param mimeType The mime type of the result.\r\n * @param fileName The name of the file to download. If defined, the result will automatically be downloaded. If not defined, and `successCallback` is also not defined, the result will automatically be downloaded with an auto-generated file name.\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n static EncodeScreenshotCanvasData(\r\n canvas: HTMLCanvasElement | OffscreenCanvas,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n ): void {\r\n if (typeof fileName === \"string\" || !successCallback) {\r\n this.ToBlob(\r\n canvas,\r\n function (blob) {\r\n if (blob) {\r\n Tools.DownloadBlob(blob, fileName);\r\n }\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n },\r\n mimeType,\r\n quality\r\n );\r\n } else if (successCallback) {\r\n if (Tools._IsOffScreenCanvas(canvas)) {\r\n canvas\r\n .convertToBlob({\r\n type: mimeType,\r\n quality,\r\n })\r\n .then((blob) => {\r\n const reader = new FileReader();\r\n reader.readAsDataURL(blob);\r\n reader.onloadend = () => {\r\n const base64data = reader.result;\r\n successCallback(base64data as string);\r\n };\r\n });\r\n return;\r\n }\r\n const base64Image = canvas.toDataURL(mimeType, quality);\r\n successCallback(base64Image);\r\n }\r\n }\r\n\r\n /**\r\n * Downloads a blob in the browser\r\n * @param blob defines the blob to download\r\n * @param fileName defines the name of the downloaded file\r\n */\r\n public static Download(blob: Blob, fileName: string): void {\r\n if (typeof URL === \"undefined\") {\r\n return;\r\n }\r\n\r\n const url = window.URL.createObjectURL(blob);\r\n const a = document.createElement(\"a\");\r\n document.body.appendChild(a);\r\n a.style.display = \"none\";\r\n a.href = url;\r\n a.download = fileName;\r\n a.addEventListener(\"click\", () => {\r\n if (a.parentElement) {\r\n a.parentElement.removeChild(a);\r\n }\r\n });\r\n a.click();\r\n window.URL.revokeObjectURL(url);\r\n }\r\n\r\n /**\r\n * Will return the right value of the noPreventDefault variable\r\n * Needed to keep backwards compatibility to the old API.\r\n *\r\n * @param args arguments passed to the attachControl function\r\n * @returns the correct value for noPreventDefault\r\n */\r\n public static BackCompatCameraNoPreventDefault(args: IArguments): boolean {\r\n // is it used correctly?\r\n if (typeof args[0] === \"boolean\") {\r\n return args[0];\r\n } else if (typeof args[1] === \"boolean\") {\r\n return args[1];\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback defines the callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an to display it\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param forceDownload force the system to download the image even if a successCallback is provided\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static CreateScreenshot(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n forceDownload = false,\r\n quality?: number\r\n ): void {\r\n throw _WarnImport(\"ScreenshotTools\");\r\n }\r\n\r\n /**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an to display it\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static CreateScreenshotAsync(engine: Engine, camera: Camera, size: IScreenshotSize | number, mimeType = \"image/png\", quality?: number): Promise {\r\n throw _WarnImport(\"ScreenshotTools\");\r\n }\r\n\r\n /**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback The callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an to display it\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static CreateScreenshotUsingRenderTarget(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n samples = 1,\r\n antialiasing = false,\r\n fileName?: string,\r\n renderSprites = false,\r\n enableStencilBuffer = false,\r\n useLayerMask = true,\r\n quality?: number\r\n ): void {\r\n throw _WarnImport(\"ScreenshotTools\");\r\n }\r\n\r\n /**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * to the src parameter of an to display it\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static CreateScreenshotUsingRenderTargetAsync(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n mimeType = \"image/png\",\r\n samples = 1,\r\n antialiasing = false,\r\n fileName?: string,\r\n renderSprites = false,\r\n enableStencilBuffer = false,\r\n useLayerMask = true,\r\n quality?: number\r\n ): Promise {\r\n throw _WarnImport(\"ScreenshotTools\");\r\n }\r\n\r\n /**\r\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\r\n * Be aware Math.random() could cause collisions, but:\r\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\r\n * @returns a pseudo random id\r\n */\r\n public static RandomId(): string {\r\n return RandomGUID();\r\n }\r\n\r\n /**\r\n * Test if the given uri is a base64 string\r\n * @deprecated Please use FileTools.IsBase64DataUrl instead.\r\n * @param uri The uri to test\r\n * @returns True if the uri is a base64 string or false otherwise\r\n */\r\n public static IsBase64(uri: string): boolean {\r\n return IsBase64DataUrl(uri);\r\n }\r\n\r\n /**\r\n * Decode the given base64 uri.\r\n * @deprecated Please use FileTools.DecodeBase64UrlToBinary instead.\r\n * @param uri The uri to decode\r\n * @returns The decoded base64 data.\r\n */\r\n public static DecodeBase64(uri: string): ArrayBuffer {\r\n return DecodeBase64UrlToBinary(uri);\r\n }\r\n\r\n public static GetAbsoluteUrl: (url: string) => string =\r\n typeof document === \"object\"\r\n ? (url) => {\r\n const a = document.createElement(\"a\");\r\n a.href = url;\r\n return a.href;\r\n }\r\n : typeof URL === \"function\" && typeof location === \"object\"\r\n ? (url) => new URL(url, location.origin).href\r\n : () => {\r\n throw new Error(\"Unable to get absolute URL. Override BABYLON.Tools.GetAbsoluteUrl to a custom implementation for the current context.\");\r\n };\r\n\r\n // Logs\r\n /**\r\n * No log\r\n */\r\n public static readonly NoneLogLevel = Logger.NoneLogLevel;\r\n /**\r\n * Only message logs\r\n */\r\n public static readonly MessageLogLevel = Logger.MessageLogLevel;\r\n /**\r\n * Only warning logs\r\n */\r\n public static readonly WarningLogLevel = Logger.WarningLogLevel;\r\n /**\r\n * Only error logs\r\n */\r\n public static readonly ErrorLogLevel = Logger.ErrorLogLevel;\r\n /**\r\n * All logs\r\n */\r\n public static readonly AllLogLevel = Logger.AllLogLevel;\r\n\r\n /**\r\n * Gets a value indicating the number of loading errors\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static get errorsCount(): number {\r\n return Logger.errorsCount;\r\n }\r\n\r\n /**\r\n * Callback called when a new log is added\r\n */\r\n public static OnNewCacheEntry: (entry: string) => void;\r\n\r\n /**\r\n * Log a message to the console\r\n * @param message defines the message to log\r\n */\r\n public static Log(message: string): void {\r\n Logger.Log(message);\r\n }\r\n\r\n /**\r\n * Write a warning message to the console\r\n * @param message defines the message to log\r\n */\r\n public static Warn(message: string): void {\r\n Logger.Warn(message);\r\n }\r\n\r\n /**\r\n * Write an error message to the console\r\n * @param message defines the message to log\r\n */\r\n public static Error(message: string): void {\r\n Logger.Error(message);\r\n }\r\n\r\n /**\r\n * Gets current log cache (list of logs)\r\n */\r\n public static get LogCache(): string {\r\n return Logger.LogCache;\r\n }\r\n\r\n /**\r\n * Clears the log cache\r\n */\r\n public static ClearLogCache(): void {\r\n Logger.ClearLogCache();\r\n }\r\n\r\n /**\r\n * Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)\r\n */\r\n public static set LogLevels(level: number) {\r\n Logger.LogLevels = level;\r\n }\r\n\r\n /**\r\n * Checks if the window object exists\r\n * Back Compat only, please use IsWindowObjectExist instead.\r\n */\r\n public static IsWindowObjectExist = IsWindowObjectExist;\r\n\r\n // Performances\r\n\r\n /**\r\n * No performance log\r\n */\r\n public static readonly PerformanceNoneLogLevel = 0;\r\n /**\r\n * Use user marks to log performance\r\n */\r\n public static readonly PerformanceUserMarkLogLevel = 1;\r\n /**\r\n * Log performance to the console\r\n */\r\n public static readonly PerformanceConsoleLogLevel = 2;\r\n\r\n private static _Performance: Performance;\r\n\r\n /**\r\n * Sets the current performance log level\r\n */\r\n public static set PerformanceLogLevel(level: number) {\r\n if ((level & Tools.PerformanceUserMarkLogLevel) === Tools.PerformanceUserMarkLogLevel) {\r\n Tools.StartPerformanceCounter = Tools._StartUserMark;\r\n Tools.EndPerformanceCounter = Tools._EndUserMark;\r\n return;\r\n }\r\n\r\n if ((level & Tools.PerformanceConsoleLogLevel) === Tools.PerformanceConsoleLogLevel) {\r\n Tools.StartPerformanceCounter = Tools._StartPerformanceConsole;\r\n Tools.EndPerformanceCounter = Tools._EndPerformanceConsole;\r\n return;\r\n }\r\n\r\n Tools.StartPerformanceCounter = Tools._StartPerformanceCounterDisabled;\r\n Tools.EndPerformanceCounter = Tools._EndPerformanceCounterDisabled;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private static _StartPerformanceCounterDisabled(counterName: string, condition?: boolean): void {}\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private static _EndPerformanceCounterDisabled(counterName: string, condition?: boolean): void {}\r\n\r\n private static _StartUserMark(counterName: string, condition = true): void {\r\n if (!Tools._Performance) {\r\n if (!IsWindowObjectExist()) {\r\n return;\r\n }\r\n Tools._Performance = window.performance;\r\n }\r\n\r\n if (!condition || !Tools._Performance.mark) {\r\n return;\r\n }\r\n Tools._Performance.mark(counterName + \"-Begin\");\r\n }\r\n\r\n private static _EndUserMark(counterName: string, condition = true): void {\r\n if (!condition || !Tools._Performance.mark) {\r\n return;\r\n }\r\n Tools._Performance.mark(counterName + \"-End\");\r\n Tools._Performance.measure(counterName, counterName + \"-Begin\", counterName + \"-End\");\r\n }\r\n\r\n private static _StartPerformanceConsole(counterName: string, condition = true): void {\r\n if (!condition) {\r\n return;\r\n }\r\n\r\n Tools._StartUserMark(counterName, condition);\r\n\r\n if (console.time) {\r\n console.time(counterName);\r\n }\r\n }\r\n\r\n private static _EndPerformanceConsole(counterName: string, condition = true): void {\r\n if (!condition) {\r\n return;\r\n }\r\n\r\n Tools._EndUserMark(counterName, condition);\r\n\r\n console.timeEnd(counterName);\r\n }\r\n\r\n /**\r\n * Starts a performance counter\r\n */\r\n public static StartPerformanceCounter: (counterName: string, condition?: boolean) => void = Tools._StartPerformanceCounterDisabled;\r\n\r\n /**\r\n * Ends a specific performance counter\r\n */\r\n public static EndPerformanceCounter: (counterName: string, condition?: boolean) => void = Tools._EndPerformanceCounterDisabled;\r\n\r\n /**\r\n * Gets either window.performance.now() if supported or Date.now() else\r\n */\r\n public static get Now(): number {\r\n return PrecisionDate.Now;\r\n }\r\n\r\n /**\r\n * This method will return the name of the class used to create the instance of the given object.\r\n * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator.\r\n * @param object the object to get the class name from\r\n * @param isType defines if the object is actually a type\r\n * @returns the name of the class, will be \"object\" for a custom data type not using the @className decorator\r\n */\r\n public static GetClassName(object: any, isType = false): string {\r\n let name = null;\r\n\r\n if (!isType && object.getClassName) {\r\n name = object.getClassName();\r\n } else {\r\n if (object instanceof Object) {\r\n const classObj = isType ? object : Object.getPrototypeOf(object);\r\n name = classObj.constructor[\"__bjsclassName__\"];\r\n }\r\n if (!name) {\r\n name = typeof object;\r\n }\r\n }\r\n return name;\r\n }\r\n\r\n /**\r\n * Gets the first element of an array satisfying a given predicate\r\n * @param array defines the array to browse\r\n * @param predicate defines the predicate to use\r\n * @returns null if not found or the element\r\n */\r\n public static First(array: Array, predicate: (item: T) => boolean): Nullable {\r\n for (const el of array) {\r\n if (predicate(el)) {\r\n return el;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * This method will return the name of the full name of the class, including its owning module (if any).\r\n * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator or implementing a method getClassName():string (in which case the module won't be specified).\r\n * @param object the object to get the class name from\r\n * @param isType defines if the object is actually a type\r\n * @returns a string that can have two forms: \"moduleName.className\" if module was specified when the class' Name was registered or \"className\" if there was not module specified.\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static getFullClassName(object: any, isType = false): Nullable {\r\n let className = null;\r\n let moduleName = null;\r\n\r\n if (!isType && object.getClassName) {\r\n className = object.getClassName();\r\n } else {\r\n if (object instanceof Object) {\r\n const classObj = isType ? object : Object.getPrototypeOf(object);\r\n className = classObj.constructor[\"__bjsclassName__\"];\r\n moduleName = classObj.constructor[\"__bjsmoduleName__\"];\r\n }\r\n if (!className) {\r\n className = typeof object;\r\n }\r\n }\r\n\r\n if (!className) {\r\n return null;\r\n }\r\n\r\n return (moduleName != null ? moduleName + \".\" : \"\") + className;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves after the given amount of time.\r\n * @param delay Number of milliseconds to delay\r\n * @returns Promise that resolves after the given amount of time\r\n */\r\n public static DelayAsync(delay: number): Promise {\r\n return new Promise((resolve) => {\r\n setTimeout(() => {\r\n resolve();\r\n }, delay);\r\n });\r\n }\r\n\r\n /**\r\n * Utility function to detect if the current user agent is Safari\r\n * @returns whether or not the current user agent is safari\r\n */\r\n public static IsSafari(): boolean {\r\n if (!IsNavigatorAvailable()) {\r\n return false;\r\n }\r\n\r\n return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\r\n }\r\n}\r\n\r\n/**\r\n * Use this className as a decorator on a given class definition to add it a name and optionally its module.\r\n * You can then use the Tools.getClassName(obj) on an instance to retrieve its class name.\r\n * This method is the only way to get it done in all cases, even if the .js file declaring the class is minified\r\n * @param name The name of the class, case should be preserved\r\n * @param module The name of the Module hosting the class, optional, but strongly recommended to specify if possible. Case should be preserved.\r\n */\r\nexport function className(name: string, module?: string): (target: Object) => void {\r\n return (target: Object) => {\r\n (target)[\"__bjsclassName__\"] = name;\r\n (target)[\"__bjsmoduleName__\"] = module != null ? module : null;\r\n };\r\n}\r\n\r\n/**\r\n * An implementation of a loop for asynchronous functions.\r\n */\r\nexport class AsyncLoop {\r\n /**\r\n * Defines the current index of the loop.\r\n */\r\n public index: number;\r\n private _done: boolean;\r\n private _fn: (asyncLoop: AsyncLoop) => void;\r\n private _successCallback: () => void;\r\n\r\n /**\r\n * Constructor.\r\n * @param iterations the number of iterations.\r\n * @param func the function to run each iteration\r\n * @param successCallback the callback that will be called upon successful execution\r\n * @param offset starting offset.\r\n */\r\n constructor(\r\n /**\r\n * Defines the number of iterations for the loop\r\n */\r\n public iterations: number,\r\n func: (asyncLoop: AsyncLoop) => void,\r\n successCallback: () => void,\r\n offset = 0\r\n ) {\r\n this.index = offset - 1;\r\n this._done = false;\r\n this._fn = func;\r\n this._successCallback = successCallback;\r\n }\r\n\r\n /**\r\n * Execute the next iteration. Must be called after the last iteration was finished.\r\n */\r\n public executeNext(): void {\r\n if (!this._done) {\r\n if (this.index + 1 < this.iterations) {\r\n ++this.index;\r\n this._fn(this);\r\n } else {\r\n this.breakLoop();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Break the loop and run the success callback.\r\n */\r\n public breakLoop(): void {\r\n this._done = true;\r\n this._successCallback();\r\n }\r\n\r\n /**\r\n * Create and run an async loop.\r\n * @param iterations the number of iterations.\r\n * @param fn the function to run each iteration\r\n * @param successCallback the callback that will be called upon successful execution\r\n * @param offset starting offset.\r\n * @returns the created async loop object\r\n */\r\n public static Run(iterations: number, fn: (asyncLoop: AsyncLoop) => void, successCallback: () => void, offset = 0): AsyncLoop {\r\n const loop = new AsyncLoop(iterations, fn, successCallback, offset);\r\n\r\n loop.executeNext();\r\n\r\n return loop;\r\n }\r\n\r\n /**\r\n * A for-loop that will run a given number of iterations synchronous and the rest async.\r\n * @param iterations total number of iterations\r\n * @param syncedIterations number of synchronous iterations in each async iteration.\r\n * @param fn the function to call each iteration.\r\n * @param callback a success call back that will be called when iterating stops.\r\n * @param breakFunction a break condition (optional)\r\n * @param timeout timeout settings for the setTimeout function. default - 0.\r\n * @returns the created async loop object\r\n */\r\n public static SyncAsyncForLoop(\r\n iterations: number,\r\n syncedIterations: number,\r\n fn: (iteration: number) => void,\r\n callback: () => void,\r\n breakFunction?: () => boolean,\r\n timeout = 0\r\n ): AsyncLoop {\r\n return AsyncLoop.Run(\r\n Math.ceil(iterations / syncedIterations),\r\n (loop: AsyncLoop) => {\r\n if (breakFunction && breakFunction()) {\r\n loop.breakLoop();\r\n } else {\r\n setTimeout(() => {\r\n for (let i = 0; i < syncedIterations; ++i) {\r\n const iteration = loop.index * syncedIterations + i;\r\n if (iteration >= iterations) {\r\n break;\r\n }\r\n fn(iteration);\r\n if (breakFunction && breakFunction()) {\r\n loop.breakLoop();\r\n break;\r\n }\r\n }\r\n loop.executeNext();\r\n }, timeout);\r\n }\r\n },\r\n callback\r\n );\r\n }\r\n}\r\n\r\n// Will only be define if Tools is imported freeing up some space when only engine is required\r\nEngineStore.FallbackTexture =\r\n \"data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z\";\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n// \"Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed.\"\r\n// https://en.wikipedia.org/wiki/Coroutine\r\n\r\n// In this implementation, coroutines are typically created via generator functions (function* with yield statements).\r\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*\r\n\r\n// In this implementation, the generator function (possibly parameterized) is referred to as a coroutine factory, and the returned iterator is referred to as the coroutine.\r\n// Technically yielding generator functions are not required - anything that implements the contract of Coroutine can be run as a coroutine.\r\n\r\n// The coroutine is started with the first call to next on the iterator, it is suspended with yield statements, and it is resumed with additional calls to next on the iterator.\r\n// To create an object satisfying the Coroutine contract with a generator function, it must not yield values, but rather only void via a plain \"yield;\" statement.\r\n// Coroutines can call other coroutines via:\r\n// 1. yield* someOtherCoroutine(); // If the called coroutine does not return a value\r\n// 2. const result = yield* someOtherCoroutine(); // If the called coroutine returns a value\r\n\r\n// Coroutines are run with the runCoroutine function, which takes a Coroutine, a CoroutineScheduler, and a success and error callback.\r\n// A scheduler is responsible for scheduling the next step of a coroutine, either synchronously or asynchronously.\r\n\r\n/**\r\n * A Coroutine is the intersection of:\r\n * 1. An Iterator that yields void, returns a T, and is not passed values with calls to next.\r\n * 2. An IterableIterator of void (since it only yields void).\r\n */\r\ntype CoroutineBase = Iterator & IterableIterator;\r\n/** @internal */\r\nexport type Coroutine = CoroutineBase;\r\n/** @internal */\r\nexport type AsyncCoroutine = CoroutineBase, T>;\r\n\r\n// A CoroutineStep represents a single step of a coroutine, and is an IteratorResult as returned from Coroutine.next().\r\n/** @internal */\r\nexport type CoroutineStep = IteratorResult;\r\n\r\n// A CoroutineScheduler is responsible for scheduling the call to Coroutine.next and invokes the success or error callback after next is called.\r\n/** @internal */\r\nexport type CoroutineScheduler = (coroutine: AsyncCoroutine, onStep: (stepResult: CoroutineStep) => void, onError: (stepError: any) => void) => void;\r\n\r\n// The inline scheduler simply steps the coroutine synchronously. This is useful for running a coroutine synchronously, and also as a helper function for other schedulers.\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function inlineScheduler(coroutine: AsyncCoroutine, onStep: (stepResult: CoroutineStep) => void, onError: (stepError: any) => void) {\r\n try {\r\n const step = coroutine.next();\r\n\r\n if (step.done) {\r\n onStep(step);\r\n } else if (!step.value) {\r\n // NOTE: The properties of step have been narrowed, but the type of step itself is not narrowed, so the cast below is the most type safe way to deal with this without instantiating a new object to hold the values.\r\n onStep(step as { done: typeof step.done; value: typeof step.value });\r\n } else {\r\n step.value.then(() => {\r\n step.value = undefined;\r\n onStep(step as { done: typeof step.done; value: typeof step.value });\r\n }, onError);\r\n }\r\n } catch (error) {\r\n onError(error);\r\n }\r\n}\r\n\r\n// The yielding scheduler steps the coroutine synchronously until the specified time interval has elapsed, then yields control so other operations can be performed.\r\n// A single instance of a yielding scheduler could be shared across multiple coroutines to yield when their collective work exceeds the threshold.\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function createYieldingScheduler(yieldAfterMS = 25) {\r\n let startTime: number | undefined;\r\n return (coroutine: AsyncCoroutine, onStep: (stepResult: CoroutineStep) => void, onError: (stepError: any) => void) => {\r\n const currentTime = performance.now();\r\n\r\n if (startTime === undefined || currentTime - startTime > yieldAfterMS) {\r\n // If this is the first coroutine step, or if the time interval has elapsed, record a new start time, and schedule the coroutine step to happen later, effectively yielding control of the execution context.\r\n startTime = currentTime;\r\n setTimeout(() => {\r\n inlineScheduler(coroutine, onStep, onError);\r\n }, 0);\r\n } else {\r\n // Otherwise it is not time to yield yet, so step the coroutine synchronously.\r\n inlineScheduler(coroutine, onStep, onError);\r\n }\r\n };\r\n}\r\n\r\n// Runs the specified coroutine with the specified scheduler. The success or error callback will be invoked when the coroutine finishes.\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function runCoroutine(\r\n coroutine: AsyncCoroutine,\r\n scheduler: CoroutineScheduler,\r\n onSuccess: (result: T) => void,\r\n onError: (error: any) => void,\r\n abortSignal?: AbortSignal\r\n) {\r\n const resume = () => {\r\n let reschedule: boolean | undefined;\r\n\r\n const onStep = (stepResult: CoroutineStep) => {\r\n if (stepResult.done) {\r\n // If the coroutine is done, report success.\r\n onSuccess(stepResult.value);\r\n } else {\r\n // If the coroutine is not done, resume the coroutine (via the scheduler).\r\n if (reschedule === undefined) {\r\n // If reschedule is undefined at this point, then the coroutine must have stepped synchronously, so just flag another loop iteration.\r\n reschedule = true;\r\n } else {\r\n // If reschedule is defined at this point, then the coroutine must have stepped asynchronously, so call resume to restart the step loop.\r\n resume();\r\n }\r\n }\r\n };\r\n\r\n do {\r\n reschedule = undefined;\r\n\r\n if (!abortSignal || !abortSignal.aborted) {\r\n scheduler(coroutine, onStep, onError);\r\n } else {\r\n onError(new Error(\"Aborted\"));\r\n }\r\n\r\n if (reschedule === undefined) {\r\n // If reschedule is undefined at this point, then the coroutine must have stepped asynchronously, so stop looping and let the coroutine be resumed later.\r\n reschedule = false;\r\n }\r\n } while (reschedule);\r\n };\r\n\r\n resume();\r\n}\r\n\r\n// Runs the specified coroutine synchronously.\r\n/**\r\n * @internal\r\n */\r\nexport function runCoroutineSync(coroutine: Coroutine, abortSignal?: AbortSignal): T {\r\n // Run the coroutine with the inline scheduler, storing the returned value, or re-throwing the error (since the error callback will be called synchronously by the inline scheduler).\r\n let result: T | undefined;\r\n runCoroutine(\r\n coroutine,\r\n inlineScheduler,\r\n (r: T) => (result = r),\r\n (e: any) => {\r\n throw e;\r\n },\r\n abortSignal\r\n );\r\n\r\n // Synchronously return the result of the coroutine.\r\n return result!;\r\n}\r\n\r\n// Runs the specified coroutine asynchronously with the specified scheduler.\r\n/**\r\n * @internal\r\n */\r\nexport function runCoroutineAsync(coroutine: AsyncCoroutine, scheduler: CoroutineScheduler, abortSignal?: AbortSignal): Promise {\r\n // Run the coroutine with a yielding scheduler, resolving or rejecting the result promise when the coroutine finishes.\r\n return new Promise((resolve, reject) => {\r\n runCoroutine(coroutine, scheduler, resolve, reject, abortSignal);\r\n });\r\n}\r\n\r\n/**\r\n * Given a function that returns a Coroutine, produce a function with the same parameters that returns a T.\r\n * The returned function runs the coroutine synchronously.\r\n * @param coroutineFactory A function that returns a Coroutine.\r\n * @param abortSignal\r\n * @returns A function that runs the coroutine synchronously.\r\n * @internal\r\n */\r\nexport function makeSyncFunction(\r\n coroutineFactory: (...params: TParams) => Coroutine,\r\n abortSignal?: AbortSignal\r\n): (...params: TParams) => TReturn {\r\n return (...params: TParams) => {\r\n // Run the coroutine synchronously.\r\n return runCoroutineSync(coroutineFactory(...params), abortSignal);\r\n };\r\n}\r\n\r\n/**\r\n * Given a function that returns a Coroutine, product a function with the same parameters that returns a Promise.\r\n * The returned function runs the coroutine asynchronously, yield control of the execution context occasionally to enable a more responsive experience.\r\n * @param coroutineFactory A function that returns a Coroutine.\r\n * @param scheduler\r\n * @param abortSignal\r\n * @returns A function that runs the coroutine asynchronously.\r\n * @internal\r\n */\r\nexport function makeAsyncFunction(\r\n coroutineFactory: (...params: TParams) => AsyncCoroutine,\r\n scheduler: CoroutineScheduler,\r\n abortSignal?: AbortSignal\r\n): (...params: TParams) => Promise {\r\n return (...params: TParams) => {\r\n // Run the coroutine asynchronously.\r\n return runCoroutineAsync(coroutineFactory(...params), scheduler, abortSignal);\r\n };\r\n}\r\n","/**\r\n * Defines an array and its length.\r\n * It can be helpful to group result from both Arrays and smart arrays in one structure.\r\n */\r\nexport interface ISmartArrayLike {\r\n /**\r\n * The data of the array.\r\n */\r\n data: Array;\r\n /**\r\n * The active length of the array.\r\n */\r\n length: number;\r\n}\r\n\r\n/**\r\n * Defines an GC Friendly array where the backfield array do not shrink to prevent over allocations.\r\n */\r\nexport class SmartArray implements ISmartArrayLike {\r\n /**\r\n * The full set of data from the array.\r\n */\r\n public data: Array;\r\n\r\n /**\r\n * The active length of the array.\r\n */\r\n public length: number = 0;\r\n\r\n protected _id: number;\r\n\r\n /**\r\n * Instantiates a Smart Array.\r\n * @param capacity defines the default capacity of the array.\r\n */\r\n constructor(capacity: number) {\r\n this.data = new Array(capacity);\r\n this._id = SmartArray._GlobalId++;\r\n }\r\n\r\n /**\r\n * Pushes a value at the end of the active data.\r\n * @param value defines the object to push in the array.\r\n */\r\n public push(value: T): void {\r\n this.data[this.length++] = value;\r\n\r\n if (this.length > this.data.length) {\r\n this.data.length *= 2;\r\n }\r\n }\r\n\r\n /**\r\n * Iterates over the active data and apply the lambda to them.\r\n * @param func defines the action to apply on each value.\r\n */\r\n public forEach(func: (content: T) => void): void {\r\n for (let index = 0; index < this.length; index++) {\r\n func(this.data[index]);\r\n }\r\n }\r\n\r\n /**\r\n * Sorts the full sets of data.\r\n * @param compareFn defines the comparison function to apply.\r\n */\r\n public sort(compareFn: (a: T, b: T) => number): void {\r\n this.data.sort(compareFn);\r\n }\r\n\r\n /**\r\n * Resets the active data to an empty array.\r\n */\r\n public reset(): void {\r\n this.length = 0;\r\n }\r\n\r\n /**\r\n * Releases all the data from the array as well as the array.\r\n */\r\n public dispose(): void {\r\n this.reset();\r\n\r\n if (this.data) {\r\n this.data.length = 0;\r\n }\r\n }\r\n\r\n /**\r\n * Concats the active data with a given array.\r\n * @param array defines the data to concatenate with.\r\n */\r\n public concat(array: any): void {\r\n if (array.length === 0) {\r\n return;\r\n }\r\n if (this.length + array.length > this.data.length) {\r\n this.data.length = (this.length + array.length) * 2;\r\n }\r\n\r\n for (let index = 0; index < array.length; index++) {\r\n this.data[this.length++] = (array.data || array)[index];\r\n }\r\n }\r\n\r\n /**\r\n * Returns the position of a value in the active data.\r\n * @param value defines the value to find the index for\r\n * @returns the index if found in the active data otherwise -1\r\n */\r\n public indexOf(value: T): number {\r\n const position = this.data.indexOf(value);\r\n\r\n if (position >= this.length) {\r\n return -1;\r\n }\r\n\r\n return position;\r\n }\r\n\r\n /**\r\n * Returns whether an element is part of the active data.\r\n * @param value defines the value to look for\r\n * @returns true if found in the active data otherwise false\r\n */\r\n public contains(value: T): boolean {\r\n return this.indexOf(value) !== -1;\r\n }\r\n\r\n // Statics\r\n private static _GlobalId = 0;\r\n}\r\n\r\n/**\r\n * Defines an GC Friendly array where the backfield array do not shrink to prevent over allocations.\r\n * The data in this array can only be present once\r\n */\r\nexport class SmartArrayNoDuplicate extends SmartArray {\r\n private _duplicateId = 0;\r\n\r\n /**\r\n * Pushes a value at the end of the active data.\r\n * THIS DOES NOT PREVENT DUPPLICATE DATA\r\n * @param value defines the object to push in the array.\r\n */\r\n public push(value: T): void {\r\n super.push(value);\r\n\r\n if (!(value).__smartArrayFlags) {\r\n (value).__smartArrayFlags = {};\r\n }\r\n\r\n (value).__smartArrayFlags[this._id] = this._duplicateId;\r\n }\r\n\r\n /**\r\n * Pushes a value at the end of the active data.\r\n * If the data is already present, it won t be added again\r\n * @param value defines the object to push in the array.\r\n * @returns true if added false if it was already present\r\n */\r\n public pushNoDuplicate(value: T): boolean {\r\n if ((value).__smartArrayFlags && (value).__smartArrayFlags[this._id] === this._duplicateId) {\r\n return false;\r\n }\r\n this.push(value);\r\n return true;\r\n }\r\n\r\n /**\r\n * Resets the active data to an empty array.\r\n */\r\n public reset(): void {\r\n super.reset();\r\n this._duplicateId++;\r\n }\r\n\r\n /**\r\n * Concats the active data with a given array.\r\n * This ensures no duplicate will be present in the result.\r\n * @param array defines the data to concatenate with.\r\n */\r\n public concatWithNoDuplicate(array: any): void {\r\n if (array.length === 0) {\r\n return;\r\n }\r\n if (this.length + array.length > this.data.length) {\r\n this.data.length = (this.length + array.length) * 2;\r\n }\r\n\r\n for (let index = 0; index < array.length; index++) {\r\n const item = (array.data || array)[index];\r\n this.pushNoDuplicate(item);\r\n }\r\n }\r\n}\r\n","/**\r\n * Class used to represent a viewport on screen\r\n */\r\nexport class Viewport {\r\n /**\r\n * Creates a Viewport object located at (x, y) and sized (width, height)\r\n * @param x defines viewport left coordinate\r\n * @param y defines viewport top coordinate\r\n * @param width defines the viewport width\r\n * @param height defines the viewport height\r\n */\r\n constructor(\r\n /** viewport left coordinate */\r\n public x: number,\r\n /** viewport top coordinate */\r\n public y: number,\r\n /**viewport width */\r\n public width: number,\r\n /** viewport height */\r\n public height: number\r\n ) {}\r\n\r\n /**\r\n * Creates a new viewport using absolute sizing (from 0-> width, 0-> height instead of 0->1)\r\n * @param renderWidth defines the rendering width\r\n * @param renderHeight defines the rendering height\r\n * @returns a new Viewport\r\n */\r\n public toGlobal(renderWidth: number, renderHeight: number): Viewport {\r\n return new Viewport(this.x * renderWidth, this.y * renderHeight, this.width * renderWidth, this.height * renderHeight);\r\n }\r\n\r\n /**\r\n * Stores absolute viewport value into a target viewport (from 0-> width, 0-> height instead of 0->1)\r\n * @param renderWidth defines the rendering width\r\n * @param renderHeight defines the rendering height\r\n * @param ref defines the target viewport\r\n * @returns the current viewport\r\n */\r\n public toGlobalToRef(renderWidth: number, renderHeight: number, ref: Viewport): Viewport {\r\n ref.x = this.x * renderWidth;\r\n ref.y = this.y * renderHeight;\r\n ref.width = this.width * renderWidth;\r\n ref.height = this.height * renderHeight;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Viewport copied from the current one\r\n * @returns a new Viewport\r\n */\r\n public clone(): Viewport {\r\n return new Viewport(this.x, this.y, this.width, this.height);\r\n }\r\n}\r\n","import type { DeepImmutable } from \"../types\";\r\nimport { Vector3, Matrix } from \"./math.vector\";\r\n\r\n/**\r\n * Represents a plane by the equation ax + by + cz + d = 0\r\n */\r\nexport class Plane {\r\n private static _TmpMatrix = Matrix.Identity();\r\n\r\n /**\r\n * Normal of the plane (a,b,c)\r\n */\r\n public normal: Vector3;\r\n /**\r\n * d component of the plane\r\n */\r\n public d: number;\r\n /**\r\n * Creates a Plane object according to the given floats a, b, c, d and the plane equation : ax + by + cz + d = 0\r\n * @param a a component of the plane\r\n * @param b b component of the plane\r\n * @param c c component of the plane\r\n * @param d d component of the plane\r\n */\r\n constructor(a: number, b: number, c: number, d: number) {\r\n this.normal = new Vector3(a, b, c);\r\n this.d = d;\r\n }\r\n\r\n /**\r\n * @returns the plane coordinates as a new array of 4 elements [a, b, c, d].\r\n */\r\n public asArray(): number[] {\r\n return [this.normal.x, this.normal.y, this.normal.z, this.d];\r\n }\r\n\r\n // Methods\r\n /**\r\n * @returns a new plane copied from the current Plane.\r\n */\r\n public clone(): Plane {\r\n return new Plane(this.normal.x, this.normal.y, this.normal.z, this.d);\r\n }\r\n /**\r\n * @returns the string \"Plane\".\r\n */\r\n public getClassName(): string {\r\n return \"Plane\";\r\n }\r\n /**\r\n * @returns the Plane hash code.\r\n */\r\n public getHashCode(): number {\r\n let hash = this.normal.getHashCode();\r\n hash = (hash * 397) ^ (this.d | 0);\r\n return hash;\r\n }\r\n /**\r\n * Normalize the current Plane in place.\r\n * @returns the updated Plane.\r\n */\r\n public normalize(): Plane {\r\n const norm = Math.sqrt(this.normal.x * this.normal.x + this.normal.y * this.normal.y + this.normal.z * this.normal.z);\r\n let magnitude = 0.0;\r\n\r\n if (norm !== 0) {\r\n magnitude = 1.0 / norm;\r\n }\r\n this.normal.x *= magnitude;\r\n this.normal.y *= magnitude;\r\n this.normal.z *= magnitude;\r\n this.d *= magnitude;\r\n return this;\r\n }\r\n /**\r\n * Applies a transformation the plane and returns the result\r\n * @param transformation the transformation matrix to be applied to the plane\r\n * @returns a new Plane as the result of the transformation of the current Plane by the given matrix.\r\n */\r\n public transform(transformation: DeepImmutable): Plane {\r\n const invertedMatrix = Plane._TmpMatrix;\r\n transformation.invertToRef(invertedMatrix);\r\n const m = invertedMatrix.m;\r\n const x = this.normal.x;\r\n const y = this.normal.y;\r\n const z = this.normal.z;\r\n const d = this.d;\r\n\r\n const normalX = x * m[0] + y * m[1] + z * m[2] + d * m[3];\r\n const normalY = x * m[4] + y * m[5] + z * m[6] + d * m[7];\r\n const normalZ = x * m[8] + y * m[9] + z * m[10] + d * m[11];\r\n const finalD = x * m[12] + y * m[13] + z * m[14] + d * m[15];\r\n\r\n return new Plane(normalX, normalY, normalZ, finalD);\r\n }\r\n\r\n /**\r\n * Compute the dot product between the point and the plane normal\r\n * @param point point to calculate the dot product with\r\n * @returns the dot product (float) of the point coordinates and the plane normal.\r\n */\r\n public dotCoordinate(point: DeepImmutable): number {\r\n return this.normal.x * point.x + this.normal.y * point.y + this.normal.z * point.z + this.d;\r\n }\r\n\r\n /**\r\n * Updates the current Plane from the plane defined by the three given points.\r\n * @param point1 one of the points used to construct the plane\r\n * @param point2 one of the points used to construct the plane\r\n * @param point3 one of the points used to construct the plane\r\n * @returns the updated Plane.\r\n */\r\n public copyFromPoints(point1: DeepImmutable, point2: DeepImmutable, point3: DeepImmutable): Plane {\r\n const x1 = point2.x - point1.x;\r\n const y1 = point2.y - point1.y;\r\n const z1 = point2.z - point1.z;\r\n const x2 = point3.x - point1.x;\r\n const y2 = point3.y - point1.y;\r\n const z2 = point3.z - point1.z;\r\n const yz = y1 * z2 - z1 * y2;\r\n const xz = z1 * x2 - x1 * z2;\r\n const xy = x1 * y2 - y1 * x2;\r\n const pyth = Math.sqrt(yz * yz + xz * xz + xy * xy);\r\n let invPyth;\r\n\r\n if (pyth !== 0) {\r\n invPyth = 1.0 / pyth;\r\n } else {\r\n invPyth = 0.0;\r\n }\r\n\r\n this.normal.x = yz * invPyth;\r\n this.normal.y = xz * invPyth;\r\n this.normal.z = xy * invPyth;\r\n this.d = -(this.normal.x * point1.x + this.normal.y * point1.y + this.normal.z * point1.z);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Checks if the plane is facing a given direction (meaning if the plane's normal is pointing in the opposite direction of the given vector).\r\n * Note that for this function to work as expected you should make sure that:\r\n * - direction and the plane normal are normalized\r\n * - epsilon is a number just bigger than -1, something like -0.99 for eg\r\n * @param direction the direction to check if the plane is facing\r\n * @param epsilon value the dot product is compared against (returns true if dot <= epsilon)\r\n * @returns True if the plane is facing the given direction\r\n */\r\n public isFrontFacingTo(direction: DeepImmutable, epsilon: number): boolean {\r\n const dot = Vector3.Dot(this.normal, direction);\r\n return dot <= epsilon;\r\n }\r\n\r\n /**\r\n * Calculates the distance to a point\r\n * @param point point to calculate distance to\r\n * @returns the signed distance (float) from the given point to the Plane.\r\n */\r\n public signedDistanceTo(point: DeepImmutable): number {\r\n return Vector3.Dot(point, this.normal) + this.d;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Creates a plane from an array\r\n * @param array the array to create a plane from\r\n * @returns a new Plane from the given array.\r\n */\r\n static FromArray(array: DeepImmutable>): Plane {\r\n return new Plane(array[0], array[1], array[2], array[3]);\r\n }\r\n /**\r\n * Creates a plane from three points\r\n * @param point1 point used to create the plane\r\n * @param point2 point used to create the plane\r\n * @param point3 point used to create the plane\r\n * @returns a new Plane defined by the three given points.\r\n */\r\n static FromPoints(point1: DeepImmutable, point2: DeepImmutable, point3: DeepImmutable): Plane {\r\n const result = new Plane(0.0, 0.0, 0.0, 0.0);\r\n result.copyFromPoints(point1, point2, point3);\r\n return result;\r\n }\r\n /**\r\n * Creates a plane from an origin point and a normal\r\n * @param origin origin of the plane to be constructed\r\n * @param normal normal of the plane to be constructed\r\n * @returns a new Plane the normal vector to this plane at the given origin point.\r\n * Note : the vector \"normal\" is updated because normalized.\r\n */\r\n static FromPositionAndNormal(origin: DeepImmutable, normal: Vector3): Plane {\r\n const result = new Plane(0.0, 0.0, 0.0, 0.0);\r\n normal.normalize();\r\n result.normal = normal;\r\n result.d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);\r\n return result;\r\n }\r\n\r\n /**\r\n * Calculates the distance from a plane and a point\r\n * @param origin origin of the plane to be constructed\r\n * @param normal normal of the plane to be constructed\r\n * @param point point to calculate distance to\r\n * @returns the signed distance between the plane defined by the normal vector at the \"origin\"\" point and the given other point.\r\n */\r\n static SignedDistanceToPlaneFromPositionAndNormal(origin: DeepImmutable, normal: DeepImmutable, point: DeepImmutable): number {\r\n const d = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);\r\n return Vector3.Dot(point, normal) + d;\r\n }\r\n}\r\n","import type { Matrix, Vector3 } from \"./math.vector\";\r\nimport type { DeepImmutable } from \"../types\";\r\nimport { Plane } from \"./math.plane\";\r\n\r\n/**\r\n * Represents a camera frustum\r\n */\r\nexport class Frustum {\r\n /**\r\n * Gets the planes representing the frustum\r\n * @param transform matrix to be applied to the returned planes\r\n * @returns a new array of 6 Frustum planes computed by the given transformation matrix.\r\n */\r\n public static GetPlanes(transform: DeepImmutable): Plane[] {\r\n const frustumPlanes = [];\r\n for (let index = 0; index < 6; index++) {\r\n frustumPlanes.push(new Plane(0.0, 0.0, 0.0, 0.0));\r\n }\r\n Frustum.GetPlanesToRef(transform, frustumPlanes);\r\n return frustumPlanes;\r\n }\r\n\r\n /**\r\n * Gets the near frustum plane transformed by the transform matrix\r\n * @param transform transformation matrix to be applied to the resulting frustum plane\r\n * @param frustumPlane the resulting frustum plane\r\n */\r\n public static GetNearPlaneToRef(transform: DeepImmutable, frustumPlane: Plane): void {\r\n const m = transform.m;\r\n frustumPlane.normal.x = m[3] + m[2];\r\n frustumPlane.normal.y = m[7] + m[6];\r\n frustumPlane.normal.z = m[11] + m[10];\r\n frustumPlane.d = m[15] + m[14];\r\n frustumPlane.normalize();\r\n }\r\n\r\n /**\r\n * Gets the far frustum plane transformed by the transform matrix\r\n * @param transform transformation matrix to be applied to the resulting frustum plane\r\n * @param frustumPlane the resulting frustum plane\r\n */\r\n public static GetFarPlaneToRef(transform: DeepImmutable, frustumPlane: Plane): void {\r\n const m = transform.m;\r\n frustumPlane.normal.x = m[3] - m[2];\r\n frustumPlane.normal.y = m[7] - m[6];\r\n frustumPlane.normal.z = m[11] - m[10];\r\n frustumPlane.d = m[15] - m[14];\r\n frustumPlane.normalize();\r\n }\r\n\r\n /**\r\n * Gets the left frustum plane transformed by the transform matrix\r\n * @param transform transformation matrix to be applied to the resulting frustum plane\r\n * @param frustumPlane the resulting frustum plane\r\n */\r\n public static GetLeftPlaneToRef(transform: DeepImmutable, frustumPlane: Plane): void {\r\n const m = transform.m;\r\n frustumPlane.normal.x = m[3] + m[0];\r\n frustumPlane.normal.y = m[7] + m[4];\r\n frustumPlane.normal.z = m[11] + m[8];\r\n frustumPlane.d = m[15] + m[12];\r\n frustumPlane.normalize();\r\n }\r\n\r\n /**\r\n * Gets the right frustum plane transformed by the transform matrix\r\n * @param transform transformation matrix to be applied to the resulting frustum plane\r\n * @param frustumPlane the resulting frustum plane\r\n */\r\n public static GetRightPlaneToRef(transform: DeepImmutable, frustumPlane: Plane): void {\r\n const m = transform.m;\r\n frustumPlane.normal.x = m[3] - m[0];\r\n frustumPlane.normal.y = m[7] - m[4];\r\n frustumPlane.normal.z = m[11] - m[8];\r\n frustumPlane.d = m[15] - m[12];\r\n frustumPlane.normalize();\r\n }\r\n\r\n /**\r\n * Gets the top frustum plane transformed by the transform matrix\r\n * @param transform transformation matrix to be applied to the resulting frustum plane\r\n * @param frustumPlane the resulting frustum plane\r\n */\r\n public static GetTopPlaneToRef(transform: DeepImmutable, frustumPlane: Plane): void {\r\n const m = transform.m;\r\n frustumPlane.normal.x = m[3] - m[1];\r\n frustumPlane.normal.y = m[7] - m[5];\r\n frustumPlane.normal.z = m[11] - m[9];\r\n frustumPlane.d = m[15] - m[13];\r\n frustumPlane.normalize();\r\n }\r\n\r\n /**\r\n * Gets the bottom frustum plane transformed by the transform matrix\r\n * @param transform transformation matrix to be applied to the resulting frustum plane\r\n * @param frustumPlane the resulting frustum plane\r\n */\r\n public static GetBottomPlaneToRef(transform: DeepImmutable, frustumPlane: Plane): void {\r\n const m = transform.m;\r\n frustumPlane.normal.x = m[3] + m[1];\r\n frustumPlane.normal.y = m[7] + m[5];\r\n frustumPlane.normal.z = m[11] + m[9];\r\n frustumPlane.d = m[15] + m[13];\r\n frustumPlane.normalize();\r\n }\r\n\r\n /**\r\n * Sets the given array \"frustumPlanes\" with the 6 Frustum planes computed by the given transformation matrix.\r\n * @param transform transformation matrix to be applied to the resulting frustum planes\r\n * @param frustumPlanes the resulting frustum planes\r\n */\r\n public static GetPlanesToRef(transform: DeepImmutable, frustumPlanes: Plane[]): void {\r\n // Near\r\n Frustum.GetNearPlaneToRef(transform, frustumPlanes[0]);\r\n\r\n // Far\r\n Frustum.GetFarPlaneToRef(transform, frustumPlanes[1]);\r\n\r\n // Left\r\n Frustum.GetLeftPlaneToRef(transform, frustumPlanes[2]);\r\n\r\n // Right\r\n Frustum.GetRightPlaneToRef(transform, frustumPlanes[3]);\r\n\r\n // Top\r\n Frustum.GetTopPlaneToRef(transform, frustumPlanes[4]);\r\n\r\n // Bottom\r\n Frustum.GetBottomPlaneToRef(transform, frustumPlanes[5]);\r\n }\r\n\r\n /**\r\n * Tests if a point is located between the frustum planes.\r\n * @param point defines the point to test\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if the point is located between the frustum planes\r\n */\r\n public static IsPointInFrustum(point: Vector3, frustumPlanes: Array>): boolean {\r\n for (let i = 0; i < 6; i++) {\r\n if (frustumPlanes[i].dotCoordinate(point) < 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n}\r\n","import { serialize, SerializationHelper, serializeAsVector3 } from \"../Misc/decorators\";\r\nimport { SmartArray } from \"../Misc/smartArray\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { CameraInputsManager } from \"./cameraInputsManager\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3, Quaternion } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ICullable } from \"../Culling/boundingInfo\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { GetClass } from \"../Misc/typeStore\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Frustum } from \"../Maths/math.frustum\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport type { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { FreeCamera } from \"./freeCamera\";\r\nimport type { TargetCamera } from \"./targetCamera\";\r\nimport type { Ray } from \"../Culling/ray\";\r\n\r\n/**\r\n * This is the base class of all the camera used in the application.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\r\n */\r\nexport class Camera extends Node {\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _CreateDefaultParsedCamera = (name: string, scene: Scene): Camera => {\r\n throw _WarnImport(\"UniversalCamera\");\r\n };\r\n\r\n /**\r\n * This is the default projection mode used by the cameras.\r\n * It helps recreating a feeling of perspective and better appreciate depth.\r\n * This is the best way to simulate real life cameras.\r\n */\r\n public static readonly PERSPECTIVE_CAMERA = Constants.PERSPECTIVE_CAMERA;\r\n /**\r\n * This helps creating camera with an orthographic mode.\r\n * Orthographic is commonly used in engineering as a means to produce object specifications that communicate dimensions unambiguously, each line of 1 unit length (cm, meter..whatever) will appear to have the same length everywhere on the drawing. This allows the drafter to dimension only a subset of lines and let the reader know that other lines of that length on the drawing are also that length in reality. Every parallel line in the drawing is also parallel in the object.\r\n */\r\n public static readonly ORTHOGRAPHIC_CAMERA = Constants.ORTHOGRAPHIC_CAMERA;\r\n\r\n /**\r\n * This is the default FOV mode for perspective cameras.\r\n * This setting aligns the upper and lower bounds of the viewport to the upper and lower bounds of the camera frustum.\r\n */\r\n public static readonly FOVMODE_VERTICAL_FIXED = Constants.FOVMODE_VERTICAL_FIXED;\r\n /**\r\n * This setting aligns the left and right bounds of the viewport to the left and right bounds of the camera frustum.\r\n */\r\n public static readonly FOVMODE_HORIZONTAL_FIXED = Constants.FOVMODE_HORIZONTAL_FIXED;\r\n\r\n /**\r\n * This specifies there is no need for a camera rig.\r\n * Basically only one eye is rendered corresponding to the camera.\r\n */\r\n public static readonly RIG_MODE_NONE = Constants.RIG_MODE_NONE;\r\n /**\r\n * Simulates a camera Rig with one blue eye and one red eye.\r\n * This can be use with 3d blue and red glasses.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_ANAGLYPH = Constants.RIG_MODE_STEREOSCOPIC_ANAGLYPH;\r\n /**\r\n * Defines that both eyes of the camera will be rendered side by side with a parallel target.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = Constants.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL;\r\n /**\r\n * Defines that both eyes of the camera will be rendered side by side with a none parallel target.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = Constants.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;\r\n /**\r\n * Defines that both eyes of the camera will be rendered over under each other.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_OVERUNDER = Constants.RIG_MODE_STEREOSCOPIC_OVERUNDER;\r\n /**\r\n * Defines that both eyes of the camera will be rendered on successive lines interlaced for passive 3d monitors.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_INTERLACED = Constants.RIG_MODE_STEREOSCOPIC_INTERLACED;\r\n /**\r\n * Defines that both eyes of the camera should be renderered in a VR mode (carbox).\r\n */\r\n public static readonly RIG_MODE_VR = Constants.RIG_MODE_VR;\r\n /**\r\n * Defines that both eyes of the camera should be renderered in a VR mode (webVR).\r\n */\r\n public static readonly RIG_MODE_WEBVR = Constants.RIG_MODE_WEBVR;\r\n /**\r\n * Custom rig mode allowing rig cameras to be populated manually with any number of cameras\r\n */\r\n public static readonly RIG_MODE_CUSTOM = Constants.RIG_MODE_CUSTOM;\r\n\r\n /**\r\n * Defines if by default attaching controls should prevent the default javascript event to continue.\r\n */\r\n public static ForceAttachControlToAlwaysPreventDefault = false;\r\n\r\n /**\r\n * Define the input manager associated with the camera.\r\n */\r\n public inputs: CameraInputsManager;\r\n\r\n /** @internal */\r\n @serializeAsVector3(\"position\")\r\n public _position = Vector3.Zero();\r\n\r\n /**\r\n * Define the current local position of the camera in the scene\r\n */\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n\r\n public set position(newPosition: Vector3) {\r\n this._position = newPosition;\r\n }\r\n\r\n @serializeAsVector3(\"upVector\")\r\n protected _upVector = Vector3.Up();\r\n\r\n /**\r\n * The vector the camera should consider as up.\r\n * (default is Vector3(0, 1, 0) aka Vector3.Up())\r\n */\r\n public set upVector(vec: Vector3) {\r\n this._upVector = vec;\r\n }\r\n\r\n public get upVector() {\r\n return this._upVector;\r\n }\r\n\r\n /**\r\n * The screen area in scene units squared\r\n */\r\n public get screenArea(): number {\r\n let x = 0;\r\n let y = 0;\r\n if (this.mode === Camera.PERSPECTIVE_CAMERA) {\r\n if (this.fovMode === Camera.FOVMODE_VERTICAL_FIXED) {\r\n y = this.minZ * 2 * Math.tan(this.fov / 2);\r\n x = this.getEngine().getAspectRatio(this) * y;\r\n } else {\r\n x = this.minZ * 2 * Math.tan(this.fov / 2);\r\n y = x / this.getEngine().getAspectRatio(this);\r\n }\r\n } else {\r\n const halfWidth = this.getEngine().getRenderWidth() / 2.0;\r\n const halfHeight = this.getEngine().getRenderHeight() / 2.0;\r\n\r\n x = (this.orthoRight ?? halfWidth) - (this.orthoLeft ?? -halfWidth);\r\n y = (this.orthoTop ?? halfHeight) - (this.orthoBottom ?? -halfHeight);\r\n }\r\n\r\n return x * y;\r\n }\r\n\r\n /**\r\n * Define the current limit on the left side for an orthographic camera\r\n * In scene unit\r\n */\r\n private _orthoLeft: Nullable = null;\r\n\r\n public set orthoLeft(value: Nullable) {\r\n this._orthoLeft = value;\r\n\r\n for (const rigCamera of this._rigCameras) {\r\n rigCamera.orthoLeft = value;\r\n }\r\n }\r\n\r\n @serialize()\r\n public get orthoLeft(): Nullable {\r\n return this._orthoLeft;\r\n }\r\n\r\n /**\r\n * Define the current limit on the right side for an orthographic camera\r\n * In scene unit\r\n */\r\n private _orthoRight: Nullable = null;\r\n\r\n public set orthoRight(value: Nullable) {\r\n this._orthoRight = value;\r\n\r\n for (const rigCamera of this._rigCameras) {\r\n rigCamera.orthoRight = value;\r\n }\r\n }\r\n\r\n @serialize()\r\n public get orthoRight(): Nullable {\r\n return this._orthoRight;\r\n }\r\n\r\n /**\r\n * Define the current limit on the bottom side for an orthographic camera\r\n * In scene unit\r\n */\r\n private _orthoBottom: Nullable = null;\r\n\r\n public set orthoBottom(value: Nullable) {\r\n this._orthoBottom = value;\r\n\r\n for (const rigCamera of this._rigCameras) {\r\n rigCamera.orthoBottom = value;\r\n }\r\n }\r\n\r\n @serialize()\r\n public get orthoBottom(): Nullable {\r\n return this._orthoBottom;\r\n }\r\n\r\n /**\r\n * Define the current limit on the top side for an orthographic camera\r\n * In scene unit\r\n */\r\n private _orthoTop: Nullable = null;\r\n\r\n public set orthoTop(value: Nullable) {\r\n this._orthoTop = value;\r\n\r\n for (const rigCamera of this._rigCameras) {\r\n rigCamera.orthoTop = value;\r\n }\r\n }\r\n\r\n @serialize()\r\n public get orthoTop(): Nullable {\r\n return this._orthoTop;\r\n }\r\n\r\n /**\r\n * Field Of View is set in Radians. (default is 0.8)\r\n */\r\n @serialize()\r\n public fov = 0.8;\r\n\r\n /**\r\n * Projection plane tilt around the X axis (horizontal), set in Radians. (default is 0)\r\n * Can be used to make vertical lines in world space actually vertical on the screen.\r\n * See https://forum.babylonjs.com/t/add-vertical-shift-to-3ds-max-exporter-babylon-cameras/17480\r\n */\r\n @serialize()\r\n public projectionPlaneTilt = 0;\r\n\r\n /**\r\n * Define the minimum distance the camera can see from.\r\n * This is important to note that the depth buffer are not infinite and the closer it starts\r\n * the more your scene might encounter depth fighting issue.\r\n */\r\n @serialize()\r\n public minZ = 1;\r\n\r\n /**\r\n * Define the maximum distance the camera can see to.\r\n * This is important to note that the depth buffer are not infinite and the further it end\r\n * the more your scene might encounter depth fighting issue.\r\n */\r\n @serialize()\r\n public maxZ = 10000.0;\r\n\r\n /**\r\n * Define the default inertia of the camera.\r\n * This helps giving a smooth feeling to the camera movement.\r\n */\r\n @serialize()\r\n public inertia = 0.9;\r\n\r\n /**\r\n * Define the mode of the camera (Camera.PERSPECTIVE_CAMERA or Camera.ORTHOGRAPHIC_CAMERA)\r\n */\r\n private _mode = Camera.PERSPECTIVE_CAMERA;\r\n set mode(mode: number) {\r\n this._mode = mode;\r\n\r\n // Pass the mode down to the rig cameras\r\n for (const rigCamera of this._rigCameras) {\r\n rigCamera.mode = mode;\r\n }\r\n }\r\n\r\n @serialize()\r\n get mode(): number {\r\n return this._mode;\r\n }\r\n\r\n /**\r\n * Define whether the camera is intermediate.\r\n * This is useful to not present the output directly to the screen in case of rig without post process for instance\r\n */\r\n public isIntermediate = false;\r\n\r\n /**\r\n * Define the viewport of the camera.\r\n * This correspond to the portion of the screen the camera will render to in normalized 0 to 1 unit.\r\n */\r\n public viewport = new Viewport(0, 0, 1.0, 1.0);\r\n\r\n /**\r\n * Restricts the camera to viewing objects with the same layerMask.\r\n * A camera with a layerMask of 1 will render mesh.layerMask & camera.layerMask!== 0\r\n */\r\n @serialize()\r\n public layerMask: number = 0x0fffffff;\r\n\r\n /**\r\n * fovMode sets the camera frustum bounds to the viewport bounds. (default is FOVMODE_VERTICAL_FIXED)\r\n */\r\n @serialize()\r\n public fovMode: number = Camera.FOVMODE_VERTICAL_FIXED;\r\n\r\n /**\r\n * Rig mode of the camera.\r\n * This is useful to create the camera with two \"eyes\" instead of one to create VR or stereoscopic scenes.\r\n * This is normally controlled byt the camera themselves as internal use.\r\n */\r\n @serialize()\r\n public cameraRigMode = Camera.RIG_MODE_NONE;\r\n\r\n /**\r\n * Defines the distance between both \"eyes\" in case of a RIG\r\n */\r\n @serialize()\r\n public interaxialDistance: number;\r\n\r\n /**\r\n * Defines if stereoscopic rendering is done side by side or over under.\r\n */\r\n @serialize()\r\n public isStereoscopicSideBySide: boolean;\r\n\r\n /**\r\n * Defines the list of custom render target which are rendered to and then used as the input to this camera's render. Eg. display another camera view on a TV in the main scene\r\n * This is pretty helpful if you wish to make a camera render to a texture you could reuse somewhere\r\n * else in the scene. (Eg. security camera)\r\n *\r\n * To change the final output target of the camera, camera.outputRenderTarget should be used instead (eg. webXR renders to a render target corresponding to an HMD)\r\n */\r\n public customRenderTargets = new Array();\r\n /**\r\n * When set, the camera will render to this render target instead of the default canvas\r\n *\r\n * If the desire is to use the output of a camera as a texture in the scene consider using camera.customRenderTargets instead\r\n */\r\n public outputRenderTarget: Nullable = null;\r\n\r\n /**\r\n * Observable triggered when the camera view matrix has changed.\r\n */\r\n public onViewMatrixChangedObservable = new Observable();\r\n /**\r\n * Observable triggered when the camera Projection matrix has changed.\r\n */\r\n public onProjectionMatrixChangedObservable = new Observable();\r\n /**\r\n * Observable triggered when the inputs have been processed.\r\n */\r\n public onAfterCheckInputsObservable = new Observable();\r\n /**\r\n * Observable triggered when reset has been called and applied to the camera.\r\n */\r\n public onRestoreStateObservable = new Observable();\r\n\r\n /**\r\n * Is this camera a part of a rig system?\r\n */\r\n public isRigCamera: boolean = false;\r\n\r\n /**\r\n * If isRigCamera set to true this will be set with the parent camera.\r\n * The parent camera is not (!) necessarily the .parent of this camera (like in the case of XR)\r\n */\r\n public rigParent?: Camera;\r\n\r\n /**\r\n * Render pass id used by the camera to render into the main framebuffer\r\n */\r\n public renderPassId: number;\r\n\r\n /** @internal */\r\n public _cameraRigParams: any;\r\n /** @internal */\r\n public _rigCameras = new Array();\r\n /** @internal */\r\n public _rigPostProcess: Nullable;\r\n\r\n protected _webvrViewMatrix = Matrix.Identity();\r\n /** @internal */\r\n public _skipRendering = false;\r\n\r\n /** @internal */\r\n public _projectionMatrix = new Matrix();\r\n\r\n /** @internal */\r\n public _postProcesses = new Array>();\r\n\r\n /** @internal */\r\n public _activeMeshes = new SmartArray(256);\r\n\r\n protected _globalPosition = Vector3.Zero();\r\n\r\n /** @internal */\r\n public _computedViewMatrix = Matrix.Identity();\r\n private _doNotComputeProjectionMatrix = false;\r\n private _transformMatrix = Matrix.Zero();\r\n private _frustumPlanes: Plane[];\r\n private _refreshFrustumPlanes = true;\r\n private _storedFov: number;\r\n private _stateStored: boolean;\r\n private _absoluteRotation: Quaternion = Quaternion.Identity();\r\n\r\n /**\r\n * Instantiates a new camera object.\r\n * This should not be used directly but through the inherited cameras: ArcRotate, Free...\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\r\n * @param name Defines the name of the camera in the scene\r\n * @param position Defines the position of the camera\r\n * @param scene Defines the scene the camera belongs too\r\n * @param setActiveOnSceneIfNoneActive Defines if the camera should be set as active after creation if no other camera have been defined in the scene\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene, setActiveOnSceneIfNoneActive = true) {\r\n super(name, scene);\r\n\r\n this.getScene().addCamera(this);\r\n\r\n if (setActiveOnSceneIfNoneActive && !this.getScene().activeCamera) {\r\n this.getScene().activeCamera = this;\r\n }\r\n\r\n this.position = position;\r\n this.renderPassId = this.getScene().getEngine().createRenderPassId(`Camera ${name}`);\r\n }\r\n\r\n /**\r\n * Store current camera state (fov, position, etc..)\r\n * @returns the camera\r\n */\r\n public storeState(): Camera {\r\n this._stateStored = true;\r\n this._storedFov = this.fov;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Restores the camera state values if it has been stored. You must call storeState() first\r\n */\r\n protected _restoreStateValues(): boolean {\r\n if (!this._stateStored) {\r\n return false;\r\n }\r\n\r\n this.fov = this._storedFov;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Restored camera state. You must call storeState() first.\r\n * @returns true if restored and false otherwise\r\n */\r\n public restoreState(): boolean {\r\n if (this._restoreStateValues()) {\r\n this.onRestoreStateObservable.notifyObservers(this);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets the class name of the camera.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"Camera\";\r\n }\r\n\r\n /** @internal */\r\n public readonly _isCamera = true;\r\n\r\n /**\r\n * Gets a string representation of the camera useful for debug purpose.\r\n * @param fullDetails Defines that a more verbose level of logging is required\r\n * @returns the string representation\r\n */\r\n public toString(fullDetails?: boolean): string {\r\n let ret = \"Name: \" + this.name;\r\n ret += \", type: \" + this.getClassName();\r\n if (this.animations) {\r\n for (let i = 0; i < this.animations.length; i++) {\r\n ret += \", animation[0]: \" + this.animations[i].toString(fullDetails);\r\n }\r\n }\r\n return ret;\r\n }\r\n\r\n /**\r\n * Automatically tilts the projection plane, using `projectionPlaneTilt`, to correct the perspective effect on vertical lines.\r\n */\r\n public applyVerticalCorrection() {\r\n const rot = this.absoluteRotation.toEulerAngles();\r\n\r\n this.projectionPlaneTilt = this._scene.useRightHandedSystem ? -rot.x : rot.x;\r\n }\r\n\r\n /**\r\n * Gets the current world space position of the camera.\r\n */\r\n public get globalPosition(): Vector3 {\r\n return this._globalPosition;\r\n }\r\n\r\n /**\r\n * Gets the list of active meshes this frame (meshes no culled or excluded by lod s in the frame)\r\n * @returns the active meshe list\r\n */\r\n public getActiveMeshes(): SmartArray {\r\n return this._activeMeshes;\r\n }\r\n\r\n /**\r\n * Check whether a mesh is part of the current active mesh list of the camera\r\n * @param mesh Defines the mesh to check\r\n * @returns true if active, false otherwise\r\n */\r\n public isActiveMesh(mesh: Mesh): boolean {\r\n return this._activeMeshes.indexOf(mesh) !== -1;\r\n }\r\n\r\n /**\r\n * Is this camera ready to be used/rendered\r\n * @param completeCheck defines if a complete check (including post processes) has to be done (false by default)\r\n * @returns true if the camera is ready\r\n */\r\n public isReady(completeCheck = false): boolean {\r\n if (completeCheck) {\r\n for (const pp of this._postProcesses) {\r\n if (pp && !pp.isReady()) {\r\n return false;\r\n }\r\n }\r\n }\r\n return super.isReady(completeCheck);\r\n }\r\n\r\n /** @internal */\r\n public _initCache() {\r\n super._initCache();\r\n\r\n this._cache.position = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n this._cache.upVector = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n\r\n this._cache.mode = undefined;\r\n this._cache.minZ = undefined;\r\n this._cache.maxZ = undefined;\r\n\r\n this._cache.fov = undefined;\r\n this._cache.fovMode = undefined;\r\n this._cache.aspectRatio = undefined;\r\n\r\n this._cache.orthoLeft = undefined;\r\n this._cache.orthoRight = undefined;\r\n this._cache.orthoBottom = undefined;\r\n this._cache.orthoTop = undefined;\r\n this._cache.renderWidth = undefined;\r\n this._cache.renderHeight = undefined;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateCache(ignoreParentClass?: boolean): void {\r\n if (!ignoreParentClass) {\r\n super._updateCache();\r\n }\r\n\r\n this._cache.position.copyFrom(this.position);\r\n this._cache.upVector.copyFrom(this.upVector);\r\n }\r\n\r\n /** @internal */\r\n public _isSynchronized(): boolean {\r\n return this._isSynchronizedViewMatrix() && this._isSynchronizedProjectionMatrix();\r\n }\r\n\r\n /** @internal */\r\n public _isSynchronizedViewMatrix(): boolean {\r\n if (!super._isSynchronized()) {\r\n return false;\r\n }\r\n\r\n return this._cache.position.equals(this.position) && this._cache.upVector.equals(this.upVector) && this.isSynchronizedWithParent();\r\n }\r\n\r\n /** @internal */\r\n public _isSynchronizedProjectionMatrix(): boolean {\r\n let check = this._cache.mode === this.mode && this._cache.minZ === this.minZ && this._cache.maxZ === this.maxZ;\r\n\r\n if (!check) {\r\n return false;\r\n }\r\n\r\n const engine = this.getEngine();\r\n\r\n if (this.mode === Camera.PERSPECTIVE_CAMERA) {\r\n check =\r\n this._cache.fov === this.fov &&\r\n this._cache.fovMode === this.fovMode &&\r\n this._cache.aspectRatio === engine.getAspectRatio(this) &&\r\n this._cache.projectionPlaneTilt === this.projectionPlaneTilt;\r\n } else {\r\n check =\r\n this._cache.orthoLeft === this.orthoLeft &&\r\n this._cache.orthoRight === this.orthoRight &&\r\n this._cache.orthoBottom === this.orthoBottom &&\r\n this._cache.orthoTop === this.orthoTop &&\r\n this._cache.renderWidth === engine.getRenderWidth() &&\r\n this._cache.renderHeight === engine.getRenderHeight();\r\n }\r\n\r\n return check;\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void;\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n * BACK COMPAT SIGNATURE ONLY.\r\n */\r\n public attachControl(ignored: any, noPreventDefault?: boolean): void;\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * This function is here because typescript removes the typing of the last function.\r\n * @param _ignored defines an ignored parameter kept for backward compatibility.\r\n * @param _noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(_ignored?: any, _noPreventDefault?: boolean): void {}\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void;\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n */\r\n public detachControl(ignored?: any): void;\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n * This function is here because typescript removes the typing of the last function.\r\n * @param _ignored defines an ignored parameter kept for backward compatibility.\r\n */\r\n public detachControl(_ignored?: any): void {}\r\n\r\n /**\r\n * Update the camera state according to the different inputs gathered during the frame.\r\n */\r\n public update(): void {\r\n this._checkInputs();\r\n if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\r\n this._updateRigCameras();\r\n }\r\n\r\n // Attempt to update the camera's view and projection matrices.\r\n // This call is being made because these matrices are no longer being updated\r\n // as a part of the picking ray process (in addition to scene.render).\r\n this.getViewMatrix();\r\n this.getProjectionMatrix();\r\n }\r\n\r\n /** @internal */\r\n public _checkInputs(): void {\r\n this.onAfterCheckInputsObservable.notifyObservers(this);\r\n }\r\n\r\n /** @internal */\r\n public get rigCameras(): Camera[] {\r\n return this._rigCameras;\r\n }\r\n\r\n /**\r\n * Gets the post process used by the rig cameras\r\n */\r\n public get rigPostProcess(): Nullable {\r\n return this._rigPostProcess;\r\n }\r\n\r\n /**\r\n * Internal, gets the first post process.\r\n * @returns the first post process to be run on this camera.\r\n */\r\n public _getFirstPostProcess(): Nullable {\r\n for (let ppIndex = 0; ppIndex < this._postProcesses.length; ppIndex++) {\r\n if (this._postProcesses[ppIndex] !== null) {\r\n return this._postProcesses[ppIndex];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n private _cascadePostProcessesToRigCams(): void {\r\n // invalidate framebuffer\r\n const firstPostProcess = this._getFirstPostProcess();\r\n if (firstPostProcess) {\r\n firstPostProcess.markTextureDirty();\r\n }\r\n\r\n // glue the rigPostProcess to the end of the user postprocesses & assign to each sub-camera\r\n for (let i = 0, len = this._rigCameras.length; i < len; i++) {\r\n const cam = this._rigCameras[i];\r\n const rigPostProcess = cam._rigPostProcess;\r\n\r\n // for VR rig, there does not have to be a post process\r\n if (rigPostProcess) {\r\n const isPass = rigPostProcess.getEffectName() === \"pass\";\r\n if (isPass) {\r\n // any rig which has a PassPostProcess for rig[0], cannot be isIntermediate when there are also user postProcesses\r\n cam.isIntermediate = this._postProcesses.length === 0;\r\n }\r\n cam._postProcesses = this._postProcesses.slice(0).concat(rigPostProcess);\r\n rigPostProcess.markTextureDirty();\r\n } else {\r\n cam._postProcesses = this._postProcesses.slice(0);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Attach a post process to the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses#attach-postprocess\r\n * @param postProcess The post process to attach to the camera\r\n * @param insertAt The position of the post process in case several of them are in use in the scene\r\n * @returns the position the post process has been inserted at\r\n */\r\n public attachPostProcess(postProcess: PostProcess, insertAt: Nullable = null): number {\r\n if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {\r\n Logger.Error(\"You're trying to reuse a post process not defined as reusable.\");\r\n return 0;\r\n }\r\n\r\n if (insertAt == null || insertAt < 0) {\r\n this._postProcesses.push(postProcess);\r\n } else if (this._postProcesses[insertAt] === null) {\r\n this._postProcesses[insertAt] = postProcess;\r\n } else {\r\n this._postProcesses.splice(insertAt, 0, postProcess);\r\n }\r\n this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated\r\n\r\n // Update prePass\r\n if (this._scene.prePassRenderer) {\r\n this._scene.prePassRenderer.markAsDirty();\r\n }\r\n\r\n return this._postProcesses.indexOf(postProcess);\r\n }\r\n\r\n /**\r\n * Detach a post process to the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses#attach-postprocess\r\n * @param postProcess The post process to detach from the camera\r\n */\r\n public detachPostProcess(postProcess: PostProcess): void {\r\n const idx = this._postProcesses.indexOf(postProcess);\r\n if (idx !== -1) {\r\n this._postProcesses[idx] = null;\r\n }\r\n\r\n // Update prePass\r\n if (this._scene.prePassRenderer) {\r\n this._scene.prePassRenderer.markAsDirty();\r\n }\r\n\r\n this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated\r\n }\r\n\r\n /**\r\n * Gets the current world matrix of the camera\r\n */\r\n public getWorldMatrix(): Matrix {\r\n if (this._isSynchronizedViewMatrix()) {\r\n return this._worldMatrix;\r\n }\r\n\r\n // Getting the the view matrix will also compute the world matrix.\r\n this.getViewMatrix();\r\n\r\n return this._worldMatrix;\r\n }\r\n\r\n /** @internal */\r\n public _getViewMatrix(): Matrix {\r\n return Matrix.Identity();\r\n }\r\n\r\n /**\r\n * Gets the current view matrix of the camera.\r\n * @param force forces the camera to recompute the matrix without looking at the cached state\r\n * @returns the view matrix\r\n */\r\n public getViewMatrix(force?: boolean): Matrix {\r\n if (!force && this._isSynchronizedViewMatrix()) {\r\n return this._computedViewMatrix;\r\n }\r\n\r\n this.updateCache();\r\n this._computedViewMatrix = this._getViewMatrix();\r\n this._currentRenderId = this.getScene().getRenderId();\r\n this._childUpdateId++;\r\n\r\n this._refreshFrustumPlanes = true;\r\n\r\n if (this._cameraRigParams && this._cameraRigParams.vrPreViewMatrix) {\r\n this._computedViewMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._computedViewMatrix);\r\n }\r\n\r\n // Notify parent camera if rig camera is changed\r\n if (this.parent && (this.parent as Camera).onViewMatrixChangedObservable) {\r\n (this.parent as Camera).onViewMatrixChangedObservable.notifyObservers(this.parent as Camera);\r\n }\r\n\r\n this.onViewMatrixChangedObservable.notifyObservers(this);\r\n\r\n this._computedViewMatrix.invertToRef(this._worldMatrix);\r\n\r\n return this._computedViewMatrix;\r\n }\r\n\r\n /**\r\n * Freeze the projection matrix.\r\n * It will prevent the cache check of the camera projection compute and can speed up perf\r\n * if no parameter of the camera are meant to change\r\n * @param projection Defines manually a projection if necessary\r\n */\r\n public freezeProjectionMatrix(projection?: Matrix): void {\r\n this._doNotComputeProjectionMatrix = true;\r\n if (projection !== undefined) {\r\n this._projectionMatrix = projection;\r\n }\r\n }\r\n\r\n /**\r\n * Unfreeze the projection matrix if it has previously been freezed by freezeProjectionMatrix.\r\n */\r\n public unfreezeProjectionMatrix(): void {\r\n this._doNotComputeProjectionMatrix = false;\r\n }\r\n\r\n /**\r\n * Gets the current projection matrix of the camera.\r\n * @param force forces the camera to recompute the matrix without looking at the cached state\r\n * @returns the projection matrix\r\n */\r\n public getProjectionMatrix(force?: boolean): Matrix {\r\n if (this._doNotComputeProjectionMatrix || (!force && this._isSynchronizedProjectionMatrix())) {\r\n return this._projectionMatrix;\r\n }\r\n\r\n // Cache\r\n this._cache.mode = this.mode;\r\n this._cache.minZ = this.minZ;\r\n this._cache.maxZ = this.maxZ;\r\n\r\n // Matrix\r\n this._refreshFrustumPlanes = true;\r\n\r\n const engine = this.getEngine();\r\n const scene = this.getScene();\r\n const reverseDepth = engine.useReverseDepthBuffer;\r\n if (this.mode === Camera.PERSPECTIVE_CAMERA) {\r\n this._cache.fov = this.fov;\r\n this._cache.fovMode = this.fovMode;\r\n this._cache.aspectRatio = engine.getAspectRatio(this);\r\n this._cache.projectionPlaneTilt = this.projectionPlaneTilt;\r\n\r\n if (this.minZ <= 0) {\r\n this.minZ = 0.1;\r\n }\r\n\r\n let getProjectionMatrix: (\r\n fov: number,\r\n aspect: number,\r\n znear: number,\r\n zfar: number,\r\n result: Matrix,\r\n isVerticalFovFixed: boolean,\r\n halfZRange: boolean,\r\n projectionPlaneTilt: number,\r\n reverseDepthBufferMode: boolean\r\n ) => void;\r\n if (scene.useRightHandedSystem) {\r\n getProjectionMatrix = Matrix.PerspectiveFovRHToRef;\r\n } else {\r\n getProjectionMatrix = Matrix.PerspectiveFovLHToRef;\r\n }\r\n\r\n getProjectionMatrix(\r\n this.fov,\r\n engine.getAspectRatio(this),\r\n reverseDepth ? this.maxZ : this.minZ,\r\n reverseDepth ? this.minZ : this.maxZ,\r\n this._projectionMatrix,\r\n this.fovMode === Camera.FOVMODE_VERTICAL_FIXED,\r\n engine.isNDCHalfZRange,\r\n this.projectionPlaneTilt,\r\n reverseDepth\r\n );\r\n } else {\r\n const halfWidth = engine.getRenderWidth() / 2.0;\r\n const halfHeight = engine.getRenderHeight() / 2.0;\r\n if (scene.useRightHandedSystem) {\r\n Matrix.OrthoOffCenterRHToRef(\r\n this.orthoLeft ?? -halfWidth,\r\n this.orthoRight ?? halfWidth,\r\n this.orthoBottom ?? -halfHeight,\r\n this.orthoTop ?? halfHeight,\r\n reverseDepth ? this.maxZ : this.minZ,\r\n reverseDepth ? this.minZ : this.maxZ,\r\n this._projectionMatrix,\r\n engine.isNDCHalfZRange\r\n );\r\n } else {\r\n Matrix.OrthoOffCenterLHToRef(\r\n this.orthoLeft ?? -halfWidth,\r\n this.orthoRight ?? halfWidth,\r\n this.orthoBottom ?? -halfHeight,\r\n this.orthoTop ?? halfHeight,\r\n reverseDepth ? this.maxZ : this.minZ,\r\n reverseDepth ? this.minZ : this.maxZ,\r\n this._projectionMatrix,\r\n engine.isNDCHalfZRange\r\n );\r\n }\r\n\r\n this._cache.orthoLeft = this.orthoLeft;\r\n this._cache.orthoRight = this.orthoRight;\r\n this._cache.orthoBottom = this.orthoBottom;\r\n this._cache.orthoTop = this.orthoTop;\r\n this._cache.renderWidth = engine.getRenderWidth();\r\n this._cache.renderHeight = engine.getRenderHeight();\r\n }\r\n\r\n this.onProjectionMatrixChangedObservable.notifyObservers(this);\r\n\r\n return this._projectionMatrix;\r\n }\r\n\r\n /**\r\n * Gets the transformation matrix (ie. the multiplication of view by projection matrices)\r\n * @returns a Matrix\r\n */\r\n public getTransformationMatrix(): Matrix {\r\n this._computedViewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);\r\n return this._transformMatrix;\r\n }\r\n\r\n private _updateFrustumPlanes(): void {\r\n if (!this._refreshFrustumPlanes) {\r\n return;\r\n }\r\n\r\n this.getTransformationMatrix();\r\n\r\n if (!this._frustumPlanes) {\r\n this._frustumPlanes = Frustum.GetPlanes(this._transformMatrix);\r\n } else {\r\n Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);\r\n }\r\n\r\n this._refreshFrustumPlanes = false;\r\n }\r\n\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * This checks the bounding box center. See isCompletelyInFrustum for a full bounding check\r\n * @param target The object to check\r\n * @param checkRigCameras If the rig cameras should be checked (eg. with webVR camera both eyes should be checked) (Default: false)\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n public isInFrustum(target: ICullable, checkRigCameras = false): boolean {\r\n this._updateFrustumPlanes();\r\n\r\n if (checkRigCameras && this.rigCameras.length > 0) {\r\n let result = false;\r\n this.rigCameras.forEach((cam) => {\r\n cam._updateFrustumPlanes();\r\n result = result || target.isInFrustum(cam._frustumPlanes);\r\n });\r\n return result;\r\n } else {\r\n return target.isInFrustum(this._frustumPlanes);\r\n }\r\n }\r\n\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param target The object to check\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n public isCompletelyInFrustum(target: ICullable): boolean {\r\n this._updateFrustumPlanes();\r\n\r\n return target.isCompletelyInFrustum(this._frustumPlanes);\r\n }\r\n\r\n /**\r\n * Gets a ray in the forward direction from the camera.\r\n * @param length Defines the length of the ray to create\r\n * @param transform Defines the transform to apply to the ray, by default the world matrix is used to create a workd space ray\r\n * @param origin Defines the start point of the ray which defaults to the camera position\r\n * @returns the forward ray\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getForwardRay(length = 100, transform?: Matrix, origin?: Vector3): Ray {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Gets a ray in the forward direction from the camera.\r\n * @param refRay the ray to (re)use when setting the values\r\n * @param length Defines the length of the ray to create\r\n * @param transform Defines the transform to apply to the ray, by default the world matrx is used to create a workd space ray\r\n * @param origin Defines the start point of the ray which defaults to the camera position\r\n * @returns the forward ray\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getForwardRayToRef(refRay: Ray, length = 100, transform?: Matrix, origin?: Vector3): Ray {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Releases resources associated with this node.\r\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\r\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n // Observables\r\n this.onViewMatrixChangedObservable.clear();\r\n this.onProjectionMatrixChangedObservable.clear();\r\n this.onAfterCheckInputsObservable.clear();\r\n this.onRestoreStateObservable.clear();\r\n\r\n // Inputs\r\n if (this.inputs) {\r\n this.inputs.clear();\r\n }\r\n\r\n // Animations\r\n this.getScene().stopAnimation(this);\r\n\r\n // Remove from scene\r\n this.getScene().removeCamera(this);\r\n while (this._rigCameras.length > 0) {\r\n const camera = this._rigCameras.pop();\r\n if (camera) {\r\n camera.dispose();\r\n }\r\n }\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.cameras.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.cameras.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n // Postprocesses\r\n if (this._rigPostProcess) {\r\n this._rigPostProcess.dispose(this);\r\n this._rigPostProcess = null;\r\n this._postProcesses.length = 0;\r\n } else if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\r\n this._rigPostProcess = null;\r\n this._postProcesses.length = 0;\r\n } else {\r\n let i = this._postProcesses.length;\r\n while (--i >= 0) {\r\n const postProcess = this._postProcesses[i];\r\n if (postProcess) {\r\n postProcess.dispose(this);\r\n }\r\n }\r\n }\r\n\r\n // Render targets\r\n let i = this.customRenderTargets.length;\r\n while (--i >= 0) {\r\n this.customRenderTargets[i].dispose();\r\n }\r\n this.customRenderTargets.length = 0;\r\n\r\n // Active Meshes\r\n this._activeMeshes.dispose();\r\n\r\n this.getScene().getEngine().releaseRenderPassId(this.renderPassId);\r\n\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n\r\n /** @internal */\r\n public _isLeftCamera = false;\r\n /**\r\n * Gets the left camera of a rig setup in case of Rigged Camera\r\n */\r\n public get isLeftCamera(): boolean {\r\n return this._isLeftCamera;\r\n }\r\n\r\n /** @internal */\r\n public _isRightCamera = false;\r\n /**\r\n * Gets the right camera of a rig setup in case of Rigged Camera\r\n */\r\n public get isRightCamera(): boolean {\r\n return this._isRightCamera;\r\n }\r\n\r\n /**\r\n * Gets the left camera of a rig setup in case of Rigged Camera\r\n */\r\n public get leftCamera(): Nullable {\r\n if (this._rigCameras.length < 1) {\r\n return null;\r\n }\r\n return this._rigCameras[0];\r\n }\r\n\r\n /**\r\n * Gets the right camera of a rig setup in case of Rigged Camera\r\n */\r\n public get rightCamera(): Nullable {\r\n if (this._rigCameras.length < 2) {\r\n return null;\r\n }\r\n return this._rigCameras[1];\r\n }\r\n\r\n /**\r\n * Gets the left camera target of a rig setup in case of Rigged Camera\r\n * @returns the target position\r\n */\r\n public getLeftTarget(): Nullable {\r\n if (this._rigCameras.length < 1) {\r\n return null;\r\n }\r\n return (this._rigCameras[0]).getTarget();\r\n }\r\n\r\n /**\r\n * Gets the right camera target of a rig setup in case of Rigged Camera\r\n * @returns the target position\r\n */\r\n public getRightTarget(): Nullable {\r\n if (this._rigCameras.length < 2) {\r\n return null;\r\n }\r\n return (this._rigCameras[1]).getTarget();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public setCameraRigMode(mode: number, rigParams: any): void {\r\n if (this.cameraRigMode === mode) {\r\n return;\r\n }\r\n\r\n while (this._rigCameras.length > 0) {\r\n const camera = this._rigCameras.pop();\r\n\r\n if (camera) {\r\n camera.dispose();\r\n }\r\n }\r\n this.cameraRigMode = mode;\r\n this._cameraRigParams = {};\r\n //we have to implement stereo camera calcultating left and right viewpoints from interaxialDistance and target,\r\n //not from a given angle as it is now, but until that complete code rewriting provisional stereoHalfAngle value is introduced\r\n this._cameraRigParams.interaxialDistance = rigParams.interaxialDistance || 0.0637;\r\n this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(this._cameraRigParams.interaxialDistance / 0.0637);\r\n\r\n // create the rig cameras, unless none\r\n if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\r\n const leftCamera = this.createRigCamera(this.name + \"_L\", 0);\r\n if (leftCamera) {\r\n leftCamera._isLeftCamera = true;\r\n }\r\n const rightCamera = this.createRigCamera(this.name + \"_R\", 1);\r\n if (rightCamera) {\r\n rightCamera._isRightCamera = true;\r\n }\r\n if (leftCamera && rightCamera) {\r\n this._rigCameras.push(leftCamera);\r\n this._rigCameras.push(rightCamera);\r\n }\r\n }\r\n\r\n this._setRigMode(rigParams);\r\n\r\n this._cascadePostProcessesToRigCams();\r\n this.update();\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _setRigMode(rigParams: any) {\r\n // no-op\r\n }\r\n\r\n /** @internal */\r\n public _getVRProjectionMatrix(): Matrix {\r\n Matrix.PerspectiveFovLHToRef(\r\n this._cameraRigParams.vrMetrics.aspectRatioFov,\r\n this._cameraRigParams.vrMetrics.aspectRatio,\r\n this.minZ,\r\n this.maxZ,\r\n this._cameraRigParams.vrWorkMatrix,\r\n true,\r\n this.getEngine().isNDCHalfZRange\r\n );\r\n this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix, this._projectionMatrix);\r\n return this._projectionMatrix;\r\n }\r\n\r\n protected _updateCameraRotationMatrix() {\r\n //Here for WebVR\r\n }\r\n\r\n protected _updateWebVRCameraRotationMatrix() {\r\n //Here for WebVR\r\n }\r\n\r\n /**\r\n * This function MUST be overwritten by the different WebVR cameras available.\r\n * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.\r\n * @internal\r\n */\r\n public _getWebVRProjectionMatrix(): Matrix {\r\n return Matrix.Identity();\r\n }\r\n\r\n /**\r\n * This function MUST be overwritten by the different WebVR cameras available.\r\n * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.\r\n * @internal\r\n */\r\n public _getWebVRViewMatrix(): Matrix {\r\n return Matrix.Identity();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public setCameraRigParameter(name: string, value: any) {\r\n if (!this._cameraRigParams) {\r\n this._cameraRigParams = {};\r\n }\r\n this._cameraRigParams[name] = value;\r\n //provisionnally:\r\n if (name === \"interaxialDistance\") {\r\n this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(value / 0.0637);\r\n }\r\n }\r\n\r\n /**\r\n * needs to be overridden by children so sub has required properties to be copied\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public createRigCamera(name: string, cameraIndex: number): Nullable {\r\n return null;\r\n }\r\n\r\n /**\r\n * May need to be overridden by children\r\n * @internal\r\n */\r\n public _updateRigCameras() {\r\n for (let i = 0; i < this._rigCameras.length; i++) {\r\n this._rigCameras[i].minZ = this.minZ;\r\n this._rigCameras[i].maxZ = this.maxZ;\r\n this._rigCameras[i].fov = this.fov;\r\n this._rigCameras[i].upVector.copyFrom(this.upVector);\r\n }\r\n\r\n // only update viewport when ANAGLYPH\r\n if (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH) {\r\n this._rigCameras[0].viewport = this._rigCameras[1].viewport = this.viewport;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _setupInputs() {}\r\n\r\n /**\r\n * Serialiaze the camera setup to a json representation\r\n * @returns the JSON representation\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n serializationObject.uniqueId = this.uniqueId;\r\n\r\n // Type\r\n serializationObject.type = this.getClassName();\r\n\r\n // Parent\r\n if (this.parent) {\r\n this.parent._serializeAsParent(serializationObject);\r\n }\r\n\r\n if (this.inputs) {\r\n this.inputs.serialize(serializationObject);\r\n }\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\r\n serializationObject.ranges = this.serializeAnimationRanges();\r\n\r\n serializationObject.isEnabled = this.isEnabled();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Clones the current camera.\r\n * @param name The cloned camera name\r\n * @param newParent The cloned camera's new parent (none by default)\r\n * @returns the cloned camera\r\n */\r\n public clone(name: string, newParent: Nullable = null): Camera {\r\n const camera = SerializationHelper.Clone(\r\n Camera.GetConstructorFromName(this.getClassName(), name, this.getScene(), this.interaxialDistance, this.isStereoscopicSideBySide),\r\n this\r\n );\r\n camera.name = name;\r\n camera.parent = newParent;\r\n\r\n this.onClonedObservable.notifyObservers(camera);\r\n\r\n return camera;\r\n }\r\n\r\n /**\r\n * Gets the direction of the camera relative to a given local axis.\r\n * @param localAxis Defines the reference axis to provide a relative direction.\r\n * @returns the direction\r\n */\r\n public getDirection(localAxis: Vector3): Vector3 {\r\n const result = Vector3.Zero();\r\n\r\n this.getDirectionToRef(localAxis, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the current camera absolute rotation\r\n */\r\n public get absoluteRotation(): Quaternion {\r\n this.getWorldMatrix().decompose(undefined, this._absoluteRotation);\r\n\r\n return this._absoluteRotation;\r\n }\r\n\r\n /**\r\n * Gets the direction of the camera relative to a given local axis into a passed vector.\r\n * @param localAxis Defines the reference axis to provide a relative direction.\r\n * @param result Defines the vector to store the result in\r\n */\r\n public getDirectionToRef(localAxis: Vector3, result: Vector3): void {\r\n Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);\r\n }\r\n\r\n /**\r\n * Gets a camera constructor for a given camera type\r\n * @param type The type of the camera to construct (should be equal to one of the camera class name)\r\n * @param name The name of the camera the result will be able to instantiate\r\n * @param scene The scene the result will construct the camera in\r\n * @param interaxial_distance In case of stereoscopic setup, the distance between both eyes\r\n * @param isStereoscopicSideBySide In case of stereoscopic setup, should the sereo be side b side\r\n * @returns a factory method to construct the camera\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n static GetConstructorFromName(type: string, name: string, scene: Scene, interaxial_distance: number = 0, isStereoscopicSideBySide: boolean = true): () => Camera {\r\n const constructorFunc = Node.Construct(type, name, scene, {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interaxial_distance: interaxial_distance,\r\n isStereoscopicSideBySide: isStereoscopicSideBySide,\r\n });\r\n\r\n if (constructorFunc) {\r\n return <() => Camera>constructorFunc;\r\n }\r\n\r\n // Default to universal camera\r\n return () => Camera._CreateDefaultParsedCamera(name, scene);\r\n }\r\n\r\n /**\r\n * Compute the world matrix of the camera.\r\n * @returns the camera world matrix\r\n */\r\n public computeWorldMatrix(): Matrix {\r\n return this.getWorldMatrix();\r\n }\r\n\r\n /**\r\n * Parse a JSON and creates the camera from the parsed information\r\n * @param parsedCamera The JSON to parse\r\n * @param scene The scene to instantiate the camera in\r\n * @returns the newly constructed camera\r\n */\r\n public static Parse(parsedCamera: any, scene: Scene): Camera {\r\n const type = parsedCamera.type;\r\n const construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);\r\n\r\n const camera = SerializationHelper.Parse(construct, parsedCamera, scene);\r\n\r\n // Parent\r\n if (parsedCamera.parentId !== undefined) {\r\n camera._waitingParentId = parsedCamera.parentId;\r\n }\r\n\r\n // Parent instance index\r\n if (parsedCamera.parentInstanceIndex !== undefined) {\r\n camera._waitingParentInstanceIndex = parsedCamera.parentInstanceIndex;\r\n }\r\n\r\n //If camera has an input manager, let it parse inputs settings\r\n if (camera.inputs) {\r\n camera.inputs.parse(parsedCamera);\r\n\r\n camera._setupInputs();\r\n }\r\n\r\n if (parsedCamera.upVector) {\r\n camera.upVector = Vector3.FromArray(parsedCamera.upVector); // need to force the upVector\r\n }\r\n\r\n if ((camera).setPosition) {\r\n // need to force position\r\n camera.position.copyFromFloats(0, 0, 0);\r\n (camera).setPosition(Vector3.FromArray(parsedCamera.position));\r\n }\r\n\r\n // Target\r\n if (parsedCamera.target) {\r\n if ((camera).setTarget) {\r\n (camera).setTarget(Vector3.FromArray(parsedCamera.target));\r\n }\r\n }\r\n\r\n // Apply 3d rig, when found\r\n if (parsedCamera.cameraRigMode) {\r\n const rigParams = parsedCamera.interaxial_distance ? { interaxialDistance: parsedCamera.interaxial_distance } : {};\r\n camera.setCameraRigMode(parsedCamera.cameraRigMode, rigParams);\r\n }\r\n\r\n // Animations\r\n if (parsedCamera.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedCamera.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedCamera.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n camera.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n Node.ParseAnimationRanges(camera, parsedCamera, scene);\r\n }\r\n\r\n if (parsedCamera.autoAnimate) {\r\n scene.beginAnimation(camera, parsedCamera.autoAnimateFrom, parsedCamera.autoAnimateTo, parsedCamera.autoAnimateLoop, parsedCamera.autoAnimateSpeed || 1.0);\r\n }\r\n\r\n // Check if isEnabled is defined to be back compatible with prior serialized versions.\r\n if (parsedCamera.isEnabled !== undefined) {\r\n camera.setEnabled(parsedCamera.isEnabled);\r\n }\r\n\r\n return camera;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * This class implement a typical dictionary using a string as key and the generic type T as value.\r\n * The underlying implementation relies on an associative array to ensure the best performances.\r\n * The value can be anything including 'null' but except 'undefined'\r\n */\r\nexport class StringDictionary {\r\n /**\r\n * This will clear this dictionary and copy the content from the 'source' one.\r\n * If the T value is a custom object, it won't be copied/cloned, the same object will be used\r\n * @param source the dictionary to take the content from and copy to this dictionary\r\n */\r\n public copyFrom(source: StringDictionary) {\r\n this.clear();\r\n source.forEach((t, v) => this.add(t, v));\r\n }\r\n\r\n /**\r\n * Get a value based from its key\r\n * @param key the given key to get the matching value from\r\n * @returns the value if found, otherwise undefined is returned\r\n */\r\n public get(key: string): T | undefined {\r\n const val = this._data[key];\r\n if (val !== undefined) {\r\n return val;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Get a value from its key or add it if it doesn't exist.\r\n * This method will ensure you that a given key/data will be present in the dictionary.\r\n * @param key the given key to get the matching value from\r\n * @param factory the factory that will create the value if the key is not present in the dictionary.\r\n * The factory will only be invoked if there's no data for the given key.\r\n * @returns the value corresponding to the key.\r\n */\r\n public getOrAddWithFactory(key: string, factory: (key: string) => T): T {\r\n let val = this.get(key);\r\n if (val !== undefined) {\r\n return val;\r\n }\r\n\r\n val = factory(key);\r\n if (val) {\r\n this.add(key, val);\r\n }\r\n\r\n return val;\r\n }\r\n\r\n /**\r\n * Get a value from its key if present in the dictionary otherwise add it\r\n * @param key the key to get the value from\r\n * @param val if there's no such key/value pair in the dictionary add it with this value\r\n * @returns the value corresponding to the key\r\n */\r\n public getOrAdd(key: string, val: T): T {\r\n const curVal = this.get(key);\r\n if (curVal !== undefined) {\r\n return curVal;\r\n }\r\n\r\n this.add(key, val);\r\n return val;\r\n }\r\n\r\n /**\r\n * Check if there's a given key in the dictionary\r\n * @param key the key to check for\r\n * @returns true if the key is present, false otherwise\r\n */\r\n public contains(key: string): boolean {\r\n return this._data[key] !== undefined;\r\n }\r\n\r\n /**\r\n * Add a new key and its corresponding value\r\n * @param key the key to add\r\n * @param value the value corresponding to the key\r\n * @returns true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary\r\n */\r\n public add(key: string, value: T): boolean {\r\n if (this._data[key] !== undefined) {\r\n return false;\r\n }\r\n this._data[key] = value;\r\n ++this._count;\r\n return true;\r\n }\r\n\r\n /**\r\n * Update a specific value associated to a key\r\n * @param key defines the key to use\r\n * @param value defines the value to store\r\n * @returns true if the value was updated (or false if the key was not found)\r\n */\r\n public set(key: string, value: T): boolean {\r\n if (this._data[key] === undefined) {\r\n return false;\r\n }\r\n this._data[key] = value;\r\n return true;\r\n }\r\n\r\n /**\r\n * Get the element of the given key and remove it from the dictionary\r\n * @param key defines the key to search\r\n * @returns the value associated with the key or null if not found\r\n */\r\n public getAndRemove(key: string): Nullable {\r\n const val = this.get(key);\r\n if (val !== undefined) {\r\n delete this._data[key];\r\n --this._count;\r\n return val;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Remove a key/value from the dictionary.\r\n * @param key the key to remove\r\n * @returns true if the item was successfully deleted, false if no item with such key exist in the dictionary\r\n */\r\n public remove(key: string): boolean {\r\n if (this.contains(key)) {\r\n delete this._data[key];\r\n --this._count;\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Clear the whole content of the dictionary\r\n */\r\n public clear() {\r\n this._data = {};\r\n this._count = 0;\r\n }\r\n\r\n /**\r\n * Gets the current count\r\n */\r\n public get count() {\r\n return this._count;\r\n }\r\n\r\n /**\r\n * Execute a callback on each key/val of the dictionary.\r\n * Note that you can remove any element in this dictionary in the callback implementation\r\n * @param callback the callback to execute on a given key/value pair\r\n */\r\n public forEach(callback: (key: string, val: T) => void) {\r\n for (const cur in this._data) {\r\n const val = this._data[cur];\r\n callback(cur, val);\r\n }\r\n }\r\n\r\n /**\r\n * Execute a callback on every occurrence of the dictionary until it returns a valid TRes object.\r\n * If the callback returns null or undefined the method will iterate to the next key/value pair\r\n * Note that you can remove any element in this dictionary in the callback implementation\r\n * @param callback the callback to execute, if it return a valid T instanced object the enumeration will stop and the object will be returned\r\n * @returns the first item\r\n */\r\n public first(callback: (key: string, val: T) => TRes) {\r\n for (const cur in this._data) {\r\n const val = this._data[cur];\r\n const res = callback(cur, val);\r\n if (res) {\r\n return res;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n private _count = 0;\r\n private _data: { [key: string]: T } = {};\r\n}\r\n","import type { Scene } from \"./scene\";\r\nimport type { Nullable } from \"./types\";\r\nimport type { AbstractMesh } from \"./Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"./Meshes/transformNode\";\r\nimport type { Geometry } from \"./Meshes/geometry\";\r\nimport type { Skeleton } from \"./Bones/skeleton\";\r\nimport type { MorphTargetManager } from \"./Morph/morphTargetManager\";\r\nimport type { AssetContainer } from \"./assetContainer\";\r\nimport type { IParticleSystem } from \"./Particles/IParticleSystem\";\r\nimport type { AnimationGroup } from \"./Animations/animationGroup\";\r\nimport type { BaseTexture } from \"./Materials/Textures/baseTexture\";\r\nimport type { Material } from \"./Materials/material\";\r\nimport type { MultiMaterial } from \"./Materials/multiMaterial\";\r\nimport type { AbstractActionManager } from \"./Actions/abstractActionManager\";\r\nimport type { Camera } from \"./Cameras/camera\";\r\nimport type { Light } from \"./Lights/light\";\r\nimport type { Node } from \"./node\";\r\nimport type { PostProcess } from \"./PostProcesses/postProcess\";\r\nimport type { Animation } from \"./Animations/animation\";\r\n\r\n/**\r\n * Defines how the parser contract is defined.\r\n * These parsers are used to parse a list of specific assets (like particle systems, etc..)\r\n */\r\nexport type BabylonFileParser = (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => void;\r\n\r\n/**\r\n * Defines how the individual parser contract is defined.\r\n * These parser can parse an individual asset\r\n */\r\nexport type IndividualBabylonFileParser = (parsedData: any, scene: Scene, rootUrl: string) => any;\r\n\r\n/**\r\n * Base class of the scene acting as a container for the different elements composing a scene.\r\n * This class is dynamically extended by the different components of the scene increasing\r\n * flexibility and reducing coupling\r\n */\r\nexport abstract class AbstractScene {\r\n /**\r\n * Stores the list of available parsers in the application.\r\n */\r\n private static _BabylonFileParsers: { [key: string]: BabylonFileParser } = {};\r\n\r\n /**\r\n * Stores the list of available individual parsers in the application.\r\n */\r\n private static _IndividualBabylonFileParsers: { [key: string]: IndividualBabylonFileParser } = {};\r\n\r\n /**\r\n * Adds a parser in the list of available ones\r\n * @param name Defines the name of the parser\r\n * @param parser Defines the parser to add\r\n */\r\n public static AddParser(name: string, parser: BabylonFileParser): void {\r\n this._BabylonFileParsers[name] = parser;\r\n }\r\n\r\n /**\r\n * Gets a general parser from the list of available ones\r\n * @param name Defines the name of the parser\r\n * @returns the requested parser or null\r\n */\r\n public static GetParser(name: string): Nullable {\r\n if (this._BabylonFileParsers[name]) {\r\n return this._BabylonFileParsers[name];\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Adds n individual parser in the list of available ones\r\n * @param name Defines the name of the parser\r\n * @param parser Defines the parser to add\r\n */\r\n public static AddIndividualParser(name: string, parser: IndividualBabylonFileParser): void {\r\n this._IndividualBabylonFileParsers[name] = parser;\r\n }\r\n\r\n /**\r\n * Gets an individual parser from the list of available ones\r\n * @param name Defines the name of the parser\r\n * @returns the requested parser or null\r\n */\r\n public static GetIndividualParser(name: string): Nullable {\r\n if (this._IndividualBabylonFileParsers[name]) {\r\n return this._IndividualBabylonFileParsers[name];\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Parser json data and populate both a scene and its associated container object\r\n * @param jsonData Defines the data to parse\r\n * @param scene Defines the scene to parse the data for\r\n * @param container Defines the container attached to the parsing sequence\r\n * @param rootUrl Defines the root url of the data\r\n */\r\n public static Parse(jsonData: any, scene: Scene, container: AssetContainer, rootUrl: string): void {\r\n for (const parserName in this._BabylonFileParsers) {\r\n if (Object.prototype.hasOwnProperty.call(this._BabylonFileParsers, parserName)) {\r\n this._BabylonFileParsers[parserName](jsonData, scene, container, rootUrl);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the list of root nodes (ie. nodes with no parent)\r\n */\r\n public rootNodes = new Array();\r\n\r\n /** All of the cameras added to this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\r\n */\r\n public cameras = new Array();\r\n\r\n /**\r\n * All of the lights added to this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\n public lights = new Array();\r\n\r\n /**\r\n * All of the (abstract) meshes added to this scene\r\n */\r\n public meshes = new Array();\r\n\r\n /**\r\n * The list of skeletons added to the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons\r\n */\r\n public skeletons = new Array();\r\n\r\n /**\r\n * All of the particle systems added to this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro\r\n */\r\n public particleSystems = new Array();\r\n\r\n /**\r\n * Gets a list of Animations associated with the scene\r\n */\r\n public animations: Animation[] = [];\r\n\r\n /**\r\n * All of the animation groups added to this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/groupAnimations\r\n */\r\n public animationGroups = new Array();\r\n\r\n /**\r\n * All of the multi-materials added to this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\r\n */\r\n public multiMaterials = new Array();\r\n\r\n /**\r\n * All of the materials added to this scene\r\n * In the context of a Scene, it is not supposed to be modified manually.\r\n * Any addition or removal should be done using the addMaterial and removeMaterial Scene methods.\r\n * Note also that the order of the Material within the array is not significant and might change.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction\r\n */\r\n public materials = new Array();\r\n\r\n /**\r\n * The list of morph target managers added to the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph\r\n */\r\n public morphTargetManagers = new Array();\r\n\r\n /**\r\n * The list of geometries used in the scene.\r\n */\r\n public geometries = new Array();\r\n\r\n /**\r\n * All of the transform nodes added to this scene\r\n * In the context of a Scene, it is not supposed to be modified manually.\r\n * Any addition or removal should be done using the addTransformNode and removeTransformNode Scene methods.\r\n * Note also that the order of the TransformNode within the array is not significant and might change.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/transform_node\r\n */\r\n public transformNodes = new Array();\r\n\r\n /**\r\n * ActionManagers available on the scene.\r\n * @deprecated\r\n */\r\n public actionManagers = new Array();\r\n\r\n /**\r\n * Textures to keep.\r\n */\r\n public textures = new Array();\r\n\r\n /** @internal */\r\n protected _environmentTexture: Nullable = null;\r\n /**\r\n * Texture used in all pbr material as the reflection texture.\r\n * As in the majority of the scene they are the same (exception for multi room and so on),\r\n * this is easier to reference from here than from all the materials.\r\n */\r\n public get environmentTexture(): Nullable {\r\n return this._environmentTexture;\r\n }\r\n\r\n public set environmentTexture(value: Nullable) {\r\n this._environmentTexture = value;\r\n }\r\n\r\n /**\r\n * The list of postprocesses added to the scene\r\n */\r\n public postProcesses = new Array();\r\n\r\n /**\r\n * @returns all meshes, lights, cameras, transformNodes and bones\r\n */\r\n public getNodes(): Array {\r\n let nodes = new Array();\r\n nodes = nodes.concat(this.meshes);\r\n nodes = nodes.concat(this.lights);\r\n nodes = nodes.concat(this.cameras);\r\n nodes = nodes.concat(this.transformNodes); // dummies\r\n this.skeletons.forEach((skeleton) => (nodes = nodes.concat(skeleton.bones)));\r\n return nodes;\r\n }\r\n}\r\n","/**\r\n * Manages the defines for the Material\r\n */\r\nexport class MaterialDefines {\r\n /** @internal */\r\n protected _keys: string[] = [];\r\n private _isDirty = true;\r\n /** @internal */\r\n public _renderId: number;\r\n\r\n /** @internal */\r\n public _areLightsDirty = true;\r\n /** @internal */\r\n public _areLightsDisposed = false;\r\n /** @internal */\r\n public _areAttributesDirty = true;\r\n /** @internal */\r\n public _areTexturesDirty = true;\r\n /** @internal */\r\n public _areFresnelDirty = true;\r\n /** @internal */\r\n public _areMiscDirty = true;\r\n /** @internal */\r\n public _arePrePassDirty = true;\r\n /** @internal */\r\n public _areImageProcessingDirty = true;\r\n\r\n /** @internal */\r\n public _normals = false;\r\n /** @internal */\r\n public _uvs = false;\r\n\r\n /** @internal */\r\n public _needNormals = false;\r\n /** @internal */\r\n public _needUVs = false;\r\n\r\n protected _externalProperties?: { [name: string]: { type: string; default: any } };\r\n\r\n [id: string]: any;\r\n\r\n /**\r\n * Creates a new instance\r\n * @param externalProperties list of external properties to inject into the object\r\n */\r\n constructor(externalProperties?: { [name: string]: { type: string; default: any } }) {\r\n this._externalProperties = externalProperties;\r\n\r\n // Initialize External Properties\r\n if (externalProperties) {\r\n for (const prop in externalProperties) {\r\n if (Object.prototype.hasOwnProperty.call(externalProperties, prop)) {\r\n this._setDefaultValue(prop);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Specifies if the material needs to be re-calculated\r\n */\r\n public get isDirty(): boolean {\r\n return this._isDirty;\r\n }\r\n\r\n /**\r\n * Marks the material to indicate that it has been re-calculated\r\n */\r\n public markAsProcessed() {\r\n this._isDirty = false;\r\n this._areAttributesDirty = false;\r\n this._areTexturesDirty = false;\r\n this._areFresnelDirty = false;\r\n this._areLightsDirty = false;\r\n this._areLightsDisposed = false;\r\n this._areMiscDirty = false;\r\n this._arePrePassDirty = false;\r\n this._areImageProcessingDirty = false;\r\n }\r\n\r\n /**\r\n * Marks the material to indicate that it needs to be re-calculated\r\n */\r\n public markAsUnprocessed() {\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the material to indicate all of its defines need to be re-calculated\r\n */\r\n public markAllAsDirty() {\r\n this._areTexturesDirty = true;\r\n this._areAttributesDirty = true;\r\n this._areLightsDirty = true;\r\n this._areFresnelDirty = true;\r\n this._areMiscDirty = true;\r\n this._arePrePassDirty = false;\r\n this._areImageProcessingDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the material to indicate that image processing needs to be re-calculated\r\n */\r\n public markAsImageProcessingDirty() {\r\n this._areImageProcessingDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the material to indicate the lights need to be re-calculated\r\n * @param disposed Defines whether the light is dirty due to dispose or not\r\n */\r\n public markAsLightDirty(disposed = false) {\r\n this._areLightsDirty = true;\r\n this._areLightsDisposed = this._areLightsDisposed || disposed;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the attribute state as changed\r\n */\r\n public markAsAttributesDirty() {\r\n this._areAttributesDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the texture state as changed\r\n */\r\n public markAsTexturesDirty() {\r\n this._areTexturesDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the fresnel state as changed\r\n */\r\n public markAsFresnelDirty() {\r\n this._areFresnelDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the misc state as changed\r\n */\r\n public markAsMiscDirty() {\r\n this._areMiscDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Marks the prepass state as changed\r\n */\r\n public markAsPrePassDirty() {\r\n this._arePrePassDirty = true;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Rebuilds the material defines\r\n */\r\n public rebuild() {\r\n this._keys.length = 0;\r\n\r\n for (const key of Object.keys(this)) {\r\n if (key[0] === \"_\") {\r\n continue;\r\n }\r\n\r\n this._keys.push(key);\r\n }\r\n\r\n if (this._externalProperties) {\r\n for (const name in this._externalProperties) {\r\n if (this._keys.indexOf(name) === -1) {\r\n this._keys.push(name);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Specifies if two material defines are equal\r\n * @param other - A material define instance to compare to\r\n * @returns - Boolean indicating if the material defines are equal (true) or not (false)\r\n */\r\n public isEqual(other: MaterialDefines): boolean {\r\n if (this._keys.length !== other._keys.length) {\r\n return false;\r\n }\r\n\r\n for (let index = 0; index < this._keys.length; index++) {\r\n const prop = this._keys[index];\r\n\r\n if ((this)[prop] !== (other)[prop]) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Clones this instance's defines to another instance\r\n * @param other - material defines to clone values to\r\n */\r\n public cloneTo(other: MaterialDefines): void {\r\n if (this._keys.length !== other._keys.length) {\r\n other._keys = this._keys.slice(0);\r\n }\r\n\r\n for (let index = 0; index < this._keys.length; index++) {\r\n const prop = this._keys[index];\r\n\r\n (other)[prop] = (this)[prop];\r\n }\r\n }\r\n\r\n /**\r\n * Resets the material define values\r\n */\r\n public reset(): void {\r\n this._keys.forEach((prop) => this._setDefaultValue(prop));\r\n }\r\n\r\n private _setDefaultValue(prop: string): void {\r\n const type = this._externalProperties?.[prop]?.type ?? typeof (this)[prop];\r\n const defValue = this._externalProperties?.[prop]?.default;\r\n\r\n switch (type) {\r\n case \"number\":\r\n (this)[prop] = defValue ?? 0;\r\n break;\r\n case \"string\":\r\n (this)[prop] = defValue ?? \"\";\r\n break;\r\n default:\r\n (this)[prop] = defValue ?? false;\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Converts the material define values to a string\r\n * @returns - String of material define information\r\n */\r\n public toString(): string {\r\n let result = \"\";\r\n for (let index = 0; index < this._keys.length; index++) {\r\n const prop = this._keys[index];\r\n const value = (this)[prop];\r\n const type = typeof value;\r\n\r\n switch (type) {\r\n case \"number\":\r\n case \"string\":\r\n result += \"#define \" + prop + \" \" + value + \"\\n\";\r\n break;\r\n default:\r\n if (value) {\r\n result += \"#define \" + prop + \"\\n\";\r\n }\r\n break;\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n","import { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport type { Effect } from \"../Materials/effect\";\r\n\r\n/**\r\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\nexport class ColorCurves {\r\n private _dirty = true;\r\n\r\n private _tempColor = new Color4(0, 0, 0, 0);\r\n\r\n private _globalCurve = new Color4(0, 0, 0, 0);\r\n private _highlightsCurve = new Color4(0, 0, 0, 0);\r\n private _midtonesCurve = new Color4(0, 0, 0, 0);\r\n private _shadowsCurve = new Color4(0, 0, 0, 0);\r\n\r\n private _positiveCurve = new Color4(0, 0, 0, 0);\r\n private _negativeCurve = new Color4(0, 0, 0, 0);\r\n\r\n @serialize()\r\n private _globalHue = 30;\r\n\r\n @serialize()\r\n private _globalDensity = 0;\r\n\r\n @serialize()\r\n private _globalSaturation = 0;\r\n\r\n @serialize()\r\n private _globalExposure = 0;\r\n\r\n /**\r\n * Gets the global Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public get globalHue(): number {\r\n return this._globalHue;\r\n }\r\n /**\r\n * Sets the global Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public set globalHue(value: number) {\r\n this._globalHue = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the global Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public get globalDensity(): number {\r\n return this._globalDensity;\r\n }\r\n /**\r\n * Sets the global Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public set globalDensity(value: number) {\r\n this._globalDensity = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the global Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public get globalSaturation(): number {\r\n return this._globalSaturation;\r\n }\r\n /**\r\n * Sets the global Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public set globalSaturation(value: number) {\r\n this._globalSaturation = value;\r\n this._dirty = true;\r\n }\r\n\r\n /**\r\n * Gets the global Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public get globalExposure(): number {\r\n return this._globalExposure;\r\n }\r\n /**\r\n * Sets the global Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public set globalExposure(value: number) {\r\n this._globalExposure = value;\r\n this._dirty = true;\r\n }\r\n\r\n @serialize()\r\n private _highlightsHue = 30;\r\n\r\n @serialize()\r\n private _highlightsDensity = 0;\r\n\r\n @serialize()\r\n private _highlightsSaturation = 0;\r\n\r\n @serialize()\r\n private _highlightsExposure = 0;\r\n\r\n /**\r\n * Gets the highlights Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public get highlightsHue(): number {\r\n return this._highlightsHue;\r\n }\r\n /**\r\n * Sets the highlights Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public set highlightsHue(value: number) {\r\n this._highlightsHue = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the highlights Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public get highlightsDensity(): number {\r\n return this._highlightsDensity;\r\n }\r\n /**\r\n * Sets the highlights Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public set highlightsDensity(value: number) {\r\n this._highlightsDensity = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the highlights Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public get highlightsSaturation(): number {\r\n return this._highlightsSaturation;\r\n }\r\n /**\r\n * Sets the highlights Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public set highlightsSaturation(value: number) {\r\n this._highlightsSaturation = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the highlights Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public get highlightsExposure(): number {\r\n return this._highlightsExposure;\r\n }\r\n /**\r\n * Sets the highlights Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public set highlightsExposure(value: number) {\r\n this._highlightsExposure = value;\r\n this._dirty = true;\r\n }\r\n\r\n @serialize()\r\n private _midtonesHue = 30;\r\n\r\n @serialize()\r\n private _midtonesDensity = 0;\r\n\r\n @serialize()\r\n private _midtonesSaturation = 0;\r\n\r\n @serialize()\r\n private _midtonesExposure = 0;\r\n\r\n /**\r\n * Gets the midtones Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public get midtonesHue(): number {\r\n return this._midtonesHue;\r\n }\r\n /**\r\n * Sets the midtones Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public set midtonesHue(value: number) {\r\n this._midtonesHue = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the midtones Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public get midtonesDensity(): number {\r\n return this._midtonesDensity;\r\n }\r\n /**\r\n * Sets the midtones Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public set midtonesDensity(value: number) {\r\n this._midtonesDensity = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the midtones Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public get midtonesSaturation(): number {\r\n return this._midtonesSaturation;\r\n }\r\n /**\r\n * Sets the midtones Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public set midtonesSaturation(value: number) {\r\n this._midtonesSaturation = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the midtones Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public get midtonesExposure(): number {\r\n return this._midtonesExposure;\r\n }\r\n /**\r\n * Sets the midtones Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public set midtonesExposure(value: number) {\r\n this._midtonesExposure = value;\r\n this._dirty = true;\r\n }\r\n\r\n private _shadowsHue = 30;\r\n private _shadowsDensity = 0;\r\n private _shadowsSaturation = 0;\r\n private _shadowsExposure = 0;\r\n\r\n /**\r\n * Gets the shadows Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public get shadowsHue(): number {\r\n return this._shadowsHue;\r\n }\r\n /**\r\n * Sets the shadows Hue value.\r\n * The hue value is a standard HSB hue in the range [0,360] where 0=red, 120=green and 240=blue. The default value is 30 degrees (orange).\r\n */\r\n public set shadowsHue(value: number) {\r\n this._shadowsHue = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the shadows Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public get shadowsDensity(): number {\r\n return this._shadowsDensity;\r\n }\r\n /**\r\n * Sets the shadows Density value.\r\n * The density value is in range [-100,+100] where 0 means the color filter has no effect and +100 means the color filter has maximum effect.\r\n * Values less than zero provide a filter of opposite hue.\r\n */\r\n public set shadowsDensity(value: number) {\r\n this._shadowsDensity = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the shadows Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public get shadowsSaturation(): number {\r\n return this._shadowsSaturation;\r\n }\r\n /**\r\n * Sets the shadows Saturation value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase saturation and negative values decrease saturation.\r\n */\r\n public set shadowsSaturation(value: number) {\r\n this._shadowsSaturation = value;\r\n this._dirty = true;\r\n }\r\n /**\r\n * Gets the shadows Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public get shadowsExposure(): number {\r\n return this._shadowsExposure;\r\n }\r\n /**\r\n * Sets the shadows Exposure value.\r\n * This is an adjustment value in the range [-100,+100], where the default value of 0.0 makes no adjustment, positive values increase exposure and negative values decrease exposure.\r\n */\r\n public set shadowsExposure(value: number) {\r\n this._shadowsExposure = value;\r\n this._dirty = true;\r\n }\r\n\r\n /**\r\n * Returns the class name\r\n * @returns The class name\r\n */\r\n public getClassName(): string {\r\n return \"ColorCurves\";\r\n }\r\n\r\n /**\r\n * Binds the color curves to the shader.\r\n * @param colorCurves The color curve to bind\r\n * @param effect The effect to bind to\r\n * @param positiveUniform The positive uniform shader parameter\r\n * @param neutralUniform The neutral uniform shader parameter\r\n * @param negativeUniform The negative uniform shader parameter\r\n */\r\n public static Bind(\r\n colorCurves: ColorCurves,\r\n effect: Effect,\r\n positiveUniform = \"vCameraColorCurvePositive\",\r\n neutralUniform = \"vCameraColorCurveNeutral\",\r\n negativeUniform = \"vCameraColorCurveNegative\"\r\n ): void {\r\n if (colorCurves._dirty) {\r\n colorCurves._dirty = false;\r\n\r\n // Fill in global info.\r\n colorCurves._getColorGradingDataToRef(\r\n colorCurves._globalHue,\r\n colorCurves._globalDensity,\r\n colorCurves._globalSaturation,\r\n colorCurves._globalExposure,\r\n colorCurves._globalCurve\r\n );\r\n\r\n // Compute highlights info.\r\n colorCurves._getColorGradingDataToRef(\r\n colorCurves._highlightsHue,\r\n colorCurves._highlightsDensity,\r\n colorCurves._highlightsSaturation,\r\n colorCurves._highlightsExposure,\r\n colorCurves._tempColor\r\n );\r\n colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._highlightsCurve);\r\n\r\n // Compute midtones info.\r\n colorCurves._getColorGradingDataToRef(\r\n colorCurves._midtonesHue,\r\n colorCurves._midtonesDensity,\r\n colorCurves._midtonesSaturation,\r\n colorCurves._midtonesExposure,\r\n colorCurves._tempColor\r\n );\r\n colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._midtonesCurve);\r\n\r\n // Compute shadows info.\r\n colorCurves._getColorGradingDataToRef(\r\n colorCurves._shadowsHue,\r\n colorCurves._shadowsDensity,\r\n colorCurves._shadowsSaturation,\r\n colorCurves._shadowsExposure,\r\n colorCurves._tempColor\r\n );\r\n colorCurves._tempColor.multiplyToRef(colorCurves._globalCurve, colorCurves._shadowsCurve);\r\n\r\n // Compute deltas (neutral is midtones).\r\n colorCurves._highlightsCurve.subtractToRef(colorCurves._midtonesCurve, colorCurves._positiveCurve);\r\n colorCurves._midtonesCurve.subtractToRef(colorCurves._shadowsCurve, colorCurves._negativeCurve);\r\n }\r\n\r\n if (effect) {\r\n effect.setFloat4(positiveUniform, colorCurves._positiveCurve.r, colorCurves._positiveCurve.g, colorCurves._positiveCurve.b, colorCurves._positiveCurve.a);\r\n effect.setFloat4(neutralUniform, colorCurves._midtonesCurve.r, colorCurves._midtonesCurve.g, colorCurves._midtonesCurve.b, colorCurves._midtonesCurve.a);\r\n effect.setFloat4(negativeUniform, colorCurves._negativeCurve.r, colorCurves._negativeCurve.g, colorCurves._negativeCurve.b, colorCurves._negativeCurve.a);\r\n }\r\n }\r\n\r\n /**\r\n * Prepare the list of uniforms associated with the ColorCurves effects.\r\n * @param uniformsList The list of uniforms used in the effect\r\n */\r\n public static PrepareUniforms(uniformsList: string[]): void {\r\n uniformsList.push(\"vCameraColorCurveNeutral\", \"vCameraColorCurvePositive\", \"vCameraColorCurveNegative\");\r\n }\r\n\r\n /**\r\n * Returns color grading data based on a hue, density, saturation and exposure value.\r\n * @param hue\r\n * @param density\r\n * @param saturation The saturation.\r\n * @param exposure The exposure.\r\n * @param result The result data container.\r\n */\r\n private _getColorGradingDataToRef(hue: number, density: number, saturation: number, exposure: number, result: Color4): void {\r\n if (hue == null) {\r\n return;\r\n }\r\n\r\n hue = ColorCurves._Clamp(hue, 0, 360);\r\n density = ColorCurves._Clamp(density, -100, 100);\r\n saturation = ColorCurves._Clamp(saturation, -100, 100);\r\n exposure = ColorCurves._Clamp(exposure, -100, 100);\r\n\r\n // Remap the slider/config filter density with non-linear mapping and also scale by half\r\n // so that the maximum filter density is only 50% control. This provides fine control\r\n // for small values and reasonable range.\r\n density = ColorCurves._ApplyColorGradingSliderNonlinear(density);\r\n density *= 0.5;\r\n\r\n exposure = ColorCurves._ApplyColorGradingSliderNonlinear(exposure);\r\n\r\n if (density < 0) {\r\n density *= -1;\r\n hue = (hue + 180) % 360;\r\n }\r\n\r\n ColorCurves._FromHSBToRef(hue, density, 50 + 0.25 * exposure, result);\r\n result.scaleToRef(2, result);\r\n result.a = 1 + 0.01 * saturation;\r\n }\r\n\r\n /**\r\n * Takes an input slider value and returns an adjusted value that provides extra control near the centre.\r\n * @param value The input slider value in range [-100,100].\r\n * @returns Adjusted value.\r\n */\r\n private static _ApplyColorGradingSliderNonlinear(value: number): number {\r\n value /= 100;\r\n\r\n let x: number = Math.abs(value);\r\n x = Math.pow(x, 2);\r\n\r\n if (value < 0) {\r\n x *= -1;\r\n }\r\n\r\n x *= 100;\r\n\r\n return x;\r\n }\r\n\r\n /**\r\n * Returns an RGBA Color4 based on Hue, Saturation and Brightness (also referred to as value, HSV).\r\n * @param hue The hue (H) input.\r\n * @param saturation The saturation (S) input.\r\n * @param brightness The brightness (B) input.\r\n * @param result\r\n * @result An RGBA color represented as Vector4.\r\n */\r\n private static _FromHSBToRef(hue: number, saturation: number, brightness: number, result: Color4): void {\r\n let h: number = ColorCurves._Clamp(hue, 0, 360);\r\n const s: number = ColorCurves._Clamp(saturation / 100, 0, 1);\r\n const v: number = ColorCurves._Clamp(brightness / 100, 0, 1);\r\n\r\n if (s === 0) {\r\n result.r = v;\r\n result.g = v;\r\n result.b = v;\r\n } else {\r\n // sector 0 to 5\r\n h /= 60;\r\n const i = Math.floor(h);\r\n\r\n // fractional part of h\r\n const f = h - i;\r\n const p = v * (1 - s);\r\n const q = v * (1 - s * f);\r\n const t = v * (1 - s * (1 - f));\r\n\r\n switch (i) {\r\n case 0:\r\n result.r = v;\r\n result.g = t;\r\n result.b = p;\r\n break;\r\n case 1:\r\n result.r = q;\r\n result.g = v;\r\n result.b = p;\r\n break;\r\n case 2:\r\n result.r = p;\r\n result.g = v;\r\n result.b = t;\r\n break;\r\n case 3:\r\n result.r = p;\r\n result.g = q;\r\n result.b = v;\r\n break;\r\n case 4:\r\n result.r = t;\r\n result.g = p;\r\n result.b = v;\r\n break;\r\n default:\r\n // case 5:\r\n result.r = v;\r\n result.g = p;\r\n result.b = q;\r\n break;\r\n }\r\n }\r\n\r\n result.a = 1;\r\n }\r\n\r\n /**\r\n * Returns a value clamped between min and max\r\n * @param value The value to clamp\r\n * @param min The minimum of value\r\n * @param max The maximum of value\r\n * @returns The clamped value.\r\n */\r\n private static _Clamp(value: number, min: number, max: number): number {\r\n return Math.min(Math.max(value, min), max);\r\n }\r\n\r\n /**\r\n * Clones the current color curve instance.\r\n * @returns The cloned curves\r\n */\r\n public clone(): ColorCurves {\r\n return SerializationHelper.Clone(() => new ColorCurves(), this);\r\n }\r\n\r\n /**\r\n * Serializes the current color curve instance to a json representation.\r\n * @returns a JSON representation\r\n */\r\n public serialize(): any {\r\n return SerializationHelper.Serialize(this);\r\n }\r\n\r\n /**\r\n * Parses the color curve from a json representation.\r\n * @param source the JSON source to parse\r\n * @returns The parsed curves\r\n */\r\n public static Parse(source: any): ColorCurves {\r\n return SerializationHelper.Parse(() => new ColorCurves(), source, null, null);\r\n }\r\n}\r\n\r\n// References the dependencies.\r\nSerializationHelper._ColorCurvesParser = ColorCurves.Parse;\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { serialize, SerializationHelper, serializeAsTexture, serializeAsColorCurves, serializeAsColor4 } from \"../Misc/decorators\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { MaterialDefines } from \"../Materials/materialDefines\";\r\nimport { ColorCurves } from \"../Materials/colorCurves\";\r\n\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport type { Effect } from \"../Materials/effect\";\r\n\r\n/**\r\n * Interface to follow in your material defines to integrate easily the\r\n * Image processing functions.\r\n * @internal\r\n */\r\nexport interface IImageProcessingConfigurationDefines {\r\n IMAGEPROCESSING: boolean;\r\n VIGNETTE: boolean;\r\n VIGNETTEBLENDMODEMULTIPLY: boolean;\r\n VIGNETTEBLENDMODEOPAQUE: boolean;\r\n TONEMAPPING: boolean;\r\n TONEMAPPING_ACES: boolean;\r\n CONTRAST: boolean;\r\n EXPOSURE: boolean;\r\n COLORCURVES: boolean;\r\n COLORGRADING: boolean;\r\n COLORGRADING3D: boolean;\r\n SAMPLER3DGREENDEPTH: boolean;\r\n SAMPLER3DBGRMAP: boolean;\r\n DITHER: boolean;\r\n IMAGEPROCESSINGPOSTPROCESS: boolean;\r\n SKIPFINALCOLORCLAMP: boolean;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ImageProcessingConfigurationDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {\r\n public IMAGEPROCESSING = false;\r\n public VIGNETTE = false;\r\n public VIGNETTEBLENDMODEMULTIPLY = false;\r\n public VIGNETTEBLENDMODEOPAQUE = false;\r\n public TONEMAPPING = false;\r\n public TONEMAPPING_ACES = false;\r\n public CONTRAST = false;\r\n public COLORCURVES = false;\r\n public COLORGRADING = false;\r\n public COLORGRADING3D = false;\r\n public SAMPLER3DGREENDEPTH = false;\r\n public SAMPLER3DBGRMAP = false;\r\n public DITHER = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public EXPOSURE = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n\r\n constructor() {\r\n super();\r\n this.rebuild();\r\n }\r\n}\r\n\r\n/**\r\n * This groups together the common properties used for image processing either in direct forward pass\r\n * or through post processing effect depending on the use of the image processing pipeline in your scene\r\n * or not.\r\n */\r\nexport class ImageProcessingConfiguration {\r\n /**\r\n * Default tone mapping applied in BabylonJS.\r\n */\r\n public static readonly TONEMAPPING_STANDARD = 0;\r\n\r\n /**\r\n * ACES Tone mapping (used by default in unreal and unity). This can help getting closer\r\n * to other engines rendering to increase portability.\r\n */\r\n public static readonly TONEMAPPING_ACES = 1;\r\n\r\n /**\r\n * Color curves setup used in the effect if colorCurvesEnabled is set to true\r\n */\r\n @serializeAsColorCurves()\r\n public colorCurves: Nullable = new ColorCurves();\r\n\r\n @serialize()\r\n private _colorCurvesEnabled = false;\r\n /**\r\n * Gets whether the color curves effect is enabled.\r\n */\r\n public get colorCurvesEnabled(): boolean {\r\n return this._colorCurvesEnabled;\r\n }\r\n /**\r\n * Sets whether the color curves effect is enabled.\r\n */\r\n public set colorCurvesEnabled(value: boolean) {\r\n if (this._colorCurvesEnabled === value) {\r\n return;\r\n }\r\n\r\n this._colorCurvesEnabled = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serializeAsTexture(\"colorGradingTexture\")\r\n private _colorGradingTexture: Nullable;\r\n /**\r\n * Color grading LUT texture used in the effect if colorGradingEnabled is set to true\r\n */\r\n public get colorGradingTexture(): Nullable {\r\n return this._colorGradingTexture;\r\n }\r\n /**\r\n * Color grading LUT texture used in the effect if colorGradingEnabled is set to true\r\n */\r\n public set colorGradingTexture(value: Nullable) {\r\n if (this._colorGradingTexture === value) {\r\n return;\r\n }\r\n\r\n this._colorGradingTexture = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _colorGradingEnabled = false;\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public get colorGradingEnabled(): boolean {\r\n return this._colorGradingEnabled;\r\n }\r\n /**\r\n * Sets whether the color grading effect is enabled.\r\n */\r\n public set colorGradingEnabled(value: boolean) {\r\n if (this._colorGradingEnabled === value) {\r\n return;\r\n }\r\n\r\n this._colorGradingEnabled = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _colorGradingWithGreenDepth = true;\r\n /**\r\n * Gets whether the color grading effect is using a green depth for the 3d Texture.\r\n */\r\n public get colorGradingWithGreenDepth(): boolean {\r\n return this._colorGradingWithGreenDepth;\r\n }\r\n /**\r\n * Sets whether the color grading effect is using a green depth for the 3d Texture.\r\n */\r\n public set colorGradingWithGreenDepth(value: boolean) {\r\n if (this._colorGradingWithGreenDepth === value) {\r\n return;\r\n }\r\n\r\n this._colorGradingWithGreenDepth = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _colorGradingBGR = true;\r\n /**\r\n * Gets whether the color grading texture contains BGR values.\r\n */\r\n public get colorGradingBGR(): boolean {\r\n return this._colorGradingBGR;\r\n }\r\n /**\r\n * Sets whether the color grading texture contains BGR values.\r\n */\r\n public set colorGradingBGR(value: boolean) {\r\n if (this._colorGradingBGR === value) {\r\n return;\r\n }\r\n\r\n this._colorGradingBGR = value;\r\n this._updateParameters();\r\n }\r\n\r\n /** @internal */\r\n @serialize()\r\n public _exposure = 1.0;\r\n /**\r\n * Gets the Exposure used in the effect.\r\n */\r\n public get exposure(): number {\r\n return this._exposure;\r\n }\r\n /**\r\n * Sets the Exposure used in the effect.\r\n */\r\n public set exposure(value: number) {\r\n if (this._exposure === value) {\r\n return;\r\n }\r\n\r\n this._exposure = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _toneMappingEnabled = false;\r\n /**\r\n * Gets whether the tone mapping effect is enabled.\r\n */\r\n public get toneMappingEnabled(): boolean {\r\n return this._toneMappingEnabled;\r\n }\r\n /**\r\n * Sets whether the tone mapping effect is enabled.\r\n */\r\n public set toneMappingEnabled(value: boolean) {\r\n if (this._toneMappingEnabled === value) {\r\n return;\r\n }\r\n\r\n this._toneMappingEnabled = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _toneMappingType = ImageProcessingConfiguration.TONEMAPPING_STANDARD;\r\n /**\r\n * Gets the type of tone mapping effect.\r\n */\r\n public get toneMappingType(): number {\r\n return this._toneMappingType;\r\n }\r\n /**\r\n * Sets the type of tone mapping effect used in BabylonJS.\r\n */\r\n public set toneMappingType(value: number) {\r\n if (this._toneMappingType === value) {\r\n return;\r\n }\r\n\r\n this._toneMappingType = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n protected _contrast = 1.0;\r\n /**\r\n * Gets the contrast used in the effect.\r\n */\r\n public get contrast(): number {\r\n return this._contrast;\r\n }\r\n /**\r\n * Sets the contrast used in the effect.\r\n */\r\n public set contrast(value: number) {\r\n if (this._contrast === value) {\r\n return;\r\n }\r\n\r\n this._contrast = value;\r\n this._updateParameters();\r\n }\r\n\r\n /**\r\n * Vignette stretch size.\r\n */\r\n @serialize()\r\n public vignetteStretch = 0;\r\n\r\n /**\r\n * Vignette center X Offset.\r\n */\r\n @serialize()\r\n public vignetteCenterX = 0;\r\n\r\n /**\r\n * Vignette center Y Offset.\r\n */\r\n @serialize()\r\n public vignetteCenterY = 0;\r\n\r\n /**\r\n * Back Compat: Vignette center Y Offset.\r\n * @deprecated use vignetteCenterY instead\r\n */\r\n public get vignetteCentreY(): number {\r\n return this.vignetteCenterY;\r\n }\r\n public set vignetteCentreY(value: number) {\r\n this.vignetteCenterY = value;\r\n }\r\n\r\n /**\r\n * Back Compat: Vignette center X Offset.\r\n * @deprecated use vignetteCenterX instead\r\n */\r\n public get vignetteCentreX(): number {\r\n return this.vignetteCenterX;\r\n }\r\n public set vignetteCentreX(value: number) {\r\n this.vignetteCenterX = value;\r\n }\r\n\r\n /**\r\n * Vignette weight or intensity of the vignette effect.\r\n */\r\n @serialize()\r\n public vignetteWeight = 1.5;\r\n\r\n /**\r\n * Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)\r\n * if vignetteEnabled is set to true.\r\n */\r\n @serializeAsColor4()\r\n public vignetteColor: Color4 = new Color4(0, 0, 0, 0);\r\n\r\n /**\r\n * Camera field of view used by the Vignette effect.\r\n */\r\n @serialize()\r\n public vignetteCameraFov = 0.5;\r\n\r\n @serialize()\r\n private _vignetteBlendMode = ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;\r\n /**\r\n * Gets the vignette blend mode allowing different kind of effect.\r\n */\r\n public get vignetteBlendMode(): number {\r\n return this._vignetteBlendMode;\r\n }\r\n /**\r\n * Sets the vignette blend mode allowing different kind of effect.\r\n */\r\n public set vignetteBlendMode(value: number) {\r\n if (this._vignetteBlendMode === value) {\r\n return;\r\n }\r\n\r\n this._vignetteBlendMode = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _vignetteEnabled = false;\r\n /**\r\n * Gets whether the vignette effect is enabled.\r\n */\r\n public get vignetteEnabled(): boolean {\r\n return this._vignetteEnabled;\r\n }\r\n /**\r\n * Sets whether the vignette effect is enabled.\r\n */\r\n public set vignetteEnabled(value: boolean) {\r\n if (this._vignetteEnabled === value) {\r\n return;\r\n }\r\n\r\n this._vignetteEnabled = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _ditheringEnabled = false;\r\n /**\r\n * Gets whether the dithering effect is enabled.\r\n * The dithering effect can be used to reduce banding.\r\n */\r\n public get ditheringEnabled(): boolean {\r\n return this._ditheringEnabled;\r\n }\r\n /**\r\n * Sets whether the dithering effect is enabled.\r\n * The dithering effect can be used to reduce banding.\r\n */\r\n public set ditheringEnabled(value: boolean) {\r\n if (this._ditheringEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ditheringEnabled = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _ditheringIntensity = 1.0 / 255.0;\r\n /**\r\n * Gets the dithering intensity. 0 is no dithering. Default is 1.0 / 255.0.\r\n */\r\n public get ditheringIntensity(): number {\r\n return this._ditheringIntensity;\r\n }\r\n /**\r\n * Sets the dithering intensity. 0 is no dithering. Default is 1.0 / 255.0.\r\n */\r\n public set ditheringIntensity(value: number) {\r\n if (this._ditheringIntensity === value) {\r\n return;\r\n }\r\n\r\n this._ditheringIntensity = value;\r\n this._updateParameters();\r\n }\r\n\r\n /** @internal */\r\n @serialize()\r\n public _skipFinalColorClamp = false;\r\n /**\r\n * If apply by post process is set to true, setting this to true will skip the the final color clamp step in the fragment shader\r\n * Applies to PBR materials.\r\n */\r\n public get skipFinalColorClamp(): boolean {\r\n return this._skipFinalColorClamp;\r\n }\r\n /**\r\n * If apply by post process is set to true, setting this to true will skip the the final color clamp step in the fragment shader\r\n * Applies to PBR materials.\r\n */\r\n public set skipFinalColorClamp(value: boolean) {\r\n if (this._skipFinalColorClamp === value) {\r\n return;\r\n }\r\n\r\n this._skipFinalColorClamp = value;\r\n this._updateParameters();\r\n }\r\n\r\n /** @internal */\r\n @serialize()\r\n public _applyByPostProcess = false;\r\n /**\r\n * Gets whether the image processing is applied through a post process or not.\r\n */\r\n public get applyByPostProcess(): boolean {\r\n return this._applyByPostProcess;\r\n }\r\n /**\r\n * Sets whether the image processing is applied through a post process or not.\r\n */\r\n public set applyByPostProcess(value: boolean) {\r\n if (this._applyByPostProcess === value) {\r\n return;\r\n }\r\n\r\n this._applyByPostProcess = value;\r\n this._updateParameters();\r\n }\r\n\r\n @serialize()\r\n private _isEnabled = true;\r\n /**\r\n * Gets whether the image processing is enabled or not.\r\n */\r\n public get isEnabled(): boolean {\r\n return this._isEnabled;\r\n }\r\n /**\r\n * Sets whether the image processing is enabled or not.\r\n */\r\n public set isEnabled(value: boolean) {\r\n if (this._isEnabled === value) {\r\n return;\r\n }\r\n\r\n this._isEnabled = value;\r\n this._updateParameters();\r\n }\r\n\r\n /**\r\n * An event triggered when the configuration changes and requires Shader to Update some parameters.\r\n */\r\n public onUpdateParameters = new Observable();\r\n\r\n /**\r\n * Method called each time the image processing information changes requires to recompile the effect.\r\n */\r\n protected _updateParameters(): void {\r\n this.onUpdateParameters.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Gets the current class name.\r\n * @returns \"ImageProcessingConfiguration\"\r\n */\r\n public getClassName(): string {\r\n return \"ImageProcessingConfiguration\";\r\n }\r\n\r\n /**\r\n * Prepare the list of uniforms associated with the Image Processing effects.\r\n * @param uniforms The list of uniforms used in the effect\r\n * @param defines the list of defines currently in use\r\n */\r\n public static PrepareUniforms(uniforms: string[], defines: IImageProcessingConfigurationDefines): void {\r\n if (defines.EXPOSURE) {\r\n uniforms.push(\"exposureLinear\");\r\n }\r\n if (defines.CONTRAST) {\r\n uniforms.push(\"contrast\");\r\n }\r\n if (defines.COLORGRADING) {\r\n uniforms.push(\"colorTransformSettings\");\r\n }\r\n if (defines.VIGNETTE || defines.DITHER) {\r\n uniforms.push(\"vInverseScreenSize\");\r\n }\r\n if (defines.VIGNETTE) {\r\n uniforms.push(\"vignetteSettings1\");\r\n uniforms.push(\"vignetteSettings2\");\r\n }\r\n if (defines.COLORCURVES) {\r\n ColorCurves.PrepareUniforms(uniforms);\r\n }\r\n if (defines.DITHER) {\r\n uniforms.push(\"ditherIntensity\");\r\n }\r\n }\r\n\r\n /**\r\n * Prepare the list of samplers associated with the Image Processing effects.\r\n * @param samplersList The list of uniforms used in the effect\r\n * @param defines the list of defines currently in use\r\n */\r\n public static PrepareSamplers(samplersList: string[], defines: IImageProcessingConfigurationDefines): void {\r\n if (defines.COLORGRADING) {\r\n samplersList.push(\"txColorTransform\");\r\n }\r\n }\r\n\r\n /**\r\n * Prepare the list of defines associated to the shader.\r\n * @param defines the list of defines to complete\r\n * @param forPostProcess Define if we are currently in post process mode or not\r\n */\r\n public prepareDefines(defines: IImageProcessingConfigurationDefines, forPostProcess = false): void {\r\n if (forPostProcess !== this.applyByPostProcess || !this._isEnabled) {\r\n defines.VIGNETTE = false;\r\n defines.TONEMAPPING = false;\r\n defines.TONEMAPPING_ACES = false;\r\n defines.CONTRAST = false;\r\n defines.EXPOSURE = false;\r\n defines.COLORCURVES = false;\r\n defines.COLORGRADING = false;\r\n defines.COLORGRADING3D = false;\r\n defines.DITHER = false;\r\n defines.IMAGEPROCESSING = false;\r\n defines.SKIPFINALCOLORCLAMP = this.skipFinalColorClamp;\r\n defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess && this._isEnabled;\r\n return;\r\n }\r\n\r\n defines.VIGNETTE = this.vignetteEnabled;\r\n defines.VIGNETTEBLENDMODEMULTIPLY = this.vignetteBlendMode === ImageProcessingConfiguration._VIGNETTEMODE_MULTIPLY;\r\n defines.VIGNETTEBLENDMODEOPAQUE = !defines.VIGNETTEBLENDMODEMULTIPLY;\r\n\r\n defines.TONEMAPPING = this.toneMappingEnabled;\r\n switch (this._toneMappingType) {\r\n case ImageProcessingConfiguration.TONEMAPPING_ACES:\r\n defines.TONEMAPPING_ACES = true;\r\n break;\r\n default:\r\n defines.TONEMAPPING_ACES = false;\r\n break;\r\n }\r\n\r\n defines.CONTRAST = this.contrast !== 1.0;\r\n defines.EXPOSURE = this.exposure !== 1.0;\r\n defines.COLORCURVES = this.colorCurvesEnabled && !!this.colorCurves;\r\n defines.COLORGRADING = this.colorGradingEnabled && !!this.colorGradingTexture;\r\n if (defines.COLORGRADING) {\r\n defines.COLORGRADING3D = this.colorGradingTexture!.is3D;\r\n } else {\r\n defines.COLORGRADING3D = false;\r\n }\r\n defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;\r\n defines.SAMPLER3DBGRMAP = this.colorGradingBGR;\r\n defines.DITHER = this._ditheringEnabled;\r\n defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;\r\n defines.SKIPFINALCOLORCLAMP = this.skipFinalColorClamp;\r\n defines.IMAGEPROCESSING = defines.VIGNETTE || defines.TONEMAPPING || defines.CONTRAST || defines.EXPOSURE || defines.COLORCURVES || defines.COLORGRADING || defines.DITHER;\r\n }\r\n\r\n /**\r\n * Returns true if all the image processing information are ready.\r\n * @returns True if ready, otherwise, false\r\n */\r\n public isReady() {\r\n // Color Grading texture can not be none blocking.\r\n return !this.colorGradingEnabled || !this.colorGradingTexture || this.colorGradingTexture.isReady();\r\n }\r\n\r\n /**\r\n * Binds the image processing to the shader.\r\n * @param effect The effect to bind to\r\n * @param overrideAspectRatio Override the aspect ratio of the effect\r\n */\r\n public bind(effect: Effect, overrideAspectRatio?: number): void {\r\n // Color Curves\r\n if (this._colorCurvesEnabled && this.colorCurves) {\r\n ColorCurves.Bind(this.colorCurves, effect);\r\n }\r\n\r\n // Vignette and dither handled together due to common uniform.\r\n if (this._vignetteEnabled || this._ditheringEnabled) {\r\n const inverseWidth = 1 / effect.getEngine().getRenderWidth();\r\n const inverseHeight = 1 / effect.getEngine().getRenderHeight();\r\n effect.setFloat2(\"vInverseScreenSize\", inverseWidth, inverseHeight);\r\n\r\n if (this._ditheringEnabled) {\r\n effect.setFloat(\"ditherIntensity\", 0.5 * this._ditheringIntensity);\r\n }\r\n\r\n if (this._vignetteEnabled) {\r\n const aspectRatio = overrideAspectRatio != null ? overrideAspectRatio : inverseHeight / inverseWidth;\r\n\r\n let vignetteScaleY = Math.tan(this.vignetteCameraFov * 0.5);\r\n let vignetteScaleX = vignetteScaleY * aspectRatio;\r\n\r\n const vignetteScaleGeometricMean = Math.sqrt(vignetteScaleX * vignetteScaleY);\r\n vignetteScaleX = Tools.Mix(vignetteScaleX, vignetteScaleGeometricMean, this.vignetteStretch);\r\n vignetteScaleY = Tools.Mix(vignetteScaleY, vignetteScaleGeometricMean, this.vignetteStretch);\r\n\r\n effect.setFloat4(\"vignetteSettings1\", vignetteScaleX, vignetteScaleY, -vignetteScaleX * this.vignetteCenterX, -vignetteScaleY * this.vignetteCenterY);\r\n\r\n const vignettePower = -2.0 * this.vignetteWeight;\r\n effect.setFloat4(\"vignetteSettings2\", this.vignetteColor.r, this.vignetteColor.g, this.vignetteColor.b, vignettePower);\r\n }\r\n }\r\n\r\n // Exposure\r\n effect.setFloat(\"exposureLinear\", this.exposure);\r\n\r\n // Contrast\r\n effect.setFloat(\"contrast\", this.contrast);\r\n\r\n // Color transform settings\r\n if (this.colorGradingTexture) {\r\n effect.setTexture(\"txColorTransform\", this.colorGradingTexture);\r\n const textureSize = this.colorGradingTexture.getSize().height;\r\n\r\n effect.setFloat4(\r\n \"colorTransformSettings\",\r\n (textureSize - 1) / textureSize, // textureScale\r\n 0.5 / textureSize, // textureOffset\r\n textureSize, // textureSize\r\n this.colorGradingTexture.level // weight\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Clones the current image processing instance.\r\n * @returns The cloned image processing\r\n */\r\n public clone(): ImageProcessingConfiguration {\r\n return SerializationHelper.Clone(() => new ImageProcessingConfiguration(), this);\r\n }\r\n\r\n /**\r\n * Serializes the current image processing instance to a json representation.\r\n * @returns a JSON representation\r\n */\r\n public serialize(): any {\r\n return SerializationHelper.Serialize(this);\r\n }\r\n\r\n /**\r\n * Parses the image processing from a json representation.\r\n * @param source the JSON source to parse\r\n * @returns The parsed image processing\r\n */\r\n public static Parse(source: any): ImageProcessingConfiguration {\r\n const parsed = SerializationHelper.Parse(() => new ImageProcessingConfiguration(), source, null, null);\r\n // Backward compatibility\r\n if (source.vignetteCentreX !== undefined) {\r\n parsed.vignetteCenterX = source.vignetteCentreX;\r\n }\r\n if (source.vignetteCentreY !== undefined) {\r\n parsed.vignetteCenterY = source.vignetteCentreY;\r\n }\r\n\r\n return parsed;\r\n }\r\n\r\n // Static constants associated to the image processing.\r\n private static _VIGNETTEMODE_MULTIPLY = 0;\r\n private static _VIGNETTEMODE_OPAQUE = 1;\r\n\r\n /**\r\n * Used to apply the vignette as a mix with the pixel color.\r\n */\r\n public static get VIGNETTEMODE_MULTIPLY(): number {\r\n return this._VIGNETTEMODE_MULTIPLY;\r\n }\r\n\r\n /**\r\n * Used to apply the vignette as a replacement of the pixel color.\r\n */\r\n public static get VIGNETTEMODE_OPAQUE(): number {\r\n return this._VIGNETTEMODE_OPAQUE;\r\n }\r\n}\r\n\r\n// References the dependencies.\r\nSerializationHelper._ImageProcessingConfigurationParser = ImageProcessingConfiguration.Parse;\r\n","/**\r\n * Enum for Device Types\r\n */\r\nexport enum DeviceType {\r\n /** Generic */\r\n Generic = 0,\r\n /** Keyboard */\r\n Keyboard = 1,\r\n /** Mouse */\r\n Mouse = 2,\r\n /** Touch Pointers */\r\n Touch = 3,\r\n /** PS4 Dual Shock */\r\n DualShock = 4,\r\n /** Xbox */\r\n Xbox = 5,\r\n /** Switch Controller */\r\n Switch = 6,\r\n /** PS5 DualSense */\r\n DualSense = 7,\r\n}\r\n\r\n// Device Enums\r\n/**\r\n * Enum for All Pointers (Touch/Mouse)\r\n */\r\nexport enum PointerInput {\r\n /** Horizontal Axis (Not used in events/observables; only in polling) */\r\n Horizontal = 0,\r\n /** Vertical Axis (Not used in events/observables; only in polling) */\r\n Vertical = 1,\r\n /** Left Click or Touch */\r\n LeftClick = 2,\r\n /** Middle Click */\r\n MiddleClick = 3,\r\n /** Right Click */\r\n RightClick = 4,\r\n /** Browser Back */\r\n BrowserBack = 5,\r\n /** Browser Forward */\r\n BrowserForward = 6,\r\n /** Mouse Wheel X */\r\n MouseWheelX = 7,\r\n /** Mouse Wheel Y */\r\n MouseWheelY = 8,\r\n /** Mouse Wheel Z */\r\n MouseWheelZ = 9,\r\n /** Used in events/observables to identify if x/y changes occurred */\r\n Move = 12,\r\n}\r\n\r\n/** @internal */\r\nexport enum NativePointerInput {\r\n /** Horizontal Axis */\r\n Horizontal = PointerInput.Horizontal,\r\n /** Vertical Axis */\r\n Vertical = 1,\r\n /** Left Click or Touch */\r\n LeftClick = 2,\r\n /** Middle Click */\r\n MiddleClick = 3,\r\n /** Right Click */\r\n RightClick = 4,\r\n /** Browser Back */\r\n BrowserBack = 5,\r\n /** Browser Forward */\r\n BrowserForward = 6,\r\n /** Mouse Wheel X */\r\n MouseWheelX = 7,\r\n /** Mouse Wheel Y */\r\n MouseWheelY = 8,\r\n /** Mouse Wheel Z */\r\n MouseWheelZ = 9,\r\n /** Delta X */\r\n DeltaHorizontal = 10,\r\n /** Delta Y */\r\n DeltaVertical = 11,\r\n}\r\n\r\n/**\r\n * Enum for Dual Shock Gamepad\r\n */\r\nexport enum DualShockInput {\r\n /** Cross */\r\n Cross = 0,\r\n /** Circle */\r\n Circle = 1,\r\n /** Square */\r\n Square = 2,\r\n /** Triangle */\r\n Triangle = 3,\r\n /** L1 */\r\n L1 = 4,\r\n /** R1 */\r\n R1 = 5,\r\n /** L2 */\r\n L2 = 6,\r\n /** R2 */\r\n R2 = 7,\r\n /** Share */\r\n Share = 8,\r\n /** Options */\r\n Options = 9,\r\n /** L3 */\r\n L3 = 10,\r\n /** R3 */\r\n R3 = 11,\r\n /** DPadUp */\r\n DPadUp = 12,\r\n /** DPadDown */\r\n DPadDown = 13,\r\n /** DPadLeft */\r\n DPadLeft = 14,\r\n /** DRight */\r\n DPadRight = 15,\r\n /** Home */\r\n Home = 16,\r\n /** TouchPad */\r\n TouchPad = 17,\r\n /** LStickXAxis */\r\n LStickXAxis = 18,\r\n /** LStickYAxis */\r\n LStickYAxis = 19,\r\n /** RStickXAxis */\r\n RStickXAxis = 20,\r\n /** RStickYAxis */\r\n RStickYAxis = 21,\r\n}\r\n\r\n/**\r\n * Enum for Dual Sense Gamepad\r\n */\r\nexport enum DualSenseInput {\r\n /** Cross */\r\n Cross = 0,\r\n /** Circle */\r\n Circle = 1,\r\n /** Square */\r\n Square = 2,\r\n /** Triangle */\r\n Triangle = 3,\r\n /** L1 */\r\n L1 = 4,\r\n /** R1 */\r\n R1 = 5,\r\n /** L2 */\r\n L2 = 6,\r\n /** R2 */\r\n R2 = 7,\r\n /** Create */\r\n Create = 8,\r\n /** Options */\r\n Options = 9,\r\n /** L3 */\r\n L3 = 10,\r\n /** R3 */\r\n R3 = 11,\r\n /** DPadUp */\r\n DPadUp = 12,\r\n /** DPadDown */\r\n DPadDown = 13,\r\n /** DPadLeft */\r\n DPadLeft = 14,\r\n /** DRight */\r\n DPadRight = 15,\r\n /** Home */\r\n Home = 16,\r\n /** TouchPad */\r\n TouchPad = 17,\r\n /** LStickXAxis */\r\n LStickXAxis = 18,\r\n /** LStickYAxis */\r\n LStickYAxis = 19,\r\n /** RStickXAxis */\r\n RStickXAxis = 20,\r\n /** RStickYAxis */\r\n RStickYAxis = 21,\r\n}\r\n\r\n/**\r\n * Enum for Xbox Gamepad\r\n */\r\nexport enum XboxInput {\r\n /** A */\r\n A = 0,\r\n /** B */\r\n B = 1,\r\n /** X */\r\n X = 2,\r\n /** Y */\r\n Y = 3,\r\n /** LB */\r\n LB = 4,\r\n /** RB */\r\n RB = 5,\r\n /** LT */\r\n LT = 6,\r\n /** RT */\r\n RT = 7,\r\n /** Back */\r\n Back = 8,\r\n /** Start */\r\n Start = 9,\r\n /** LS */\r\n LS = 10,\r\n /** RS */\r\n RS = 11,\r\n /** DPadUp */\r\n DPadUp = 12,\r\n /** DPadDown */\r\n DPadDown = 13,\r\n /** DPadLeft */\r\n DPadLeft = 14,\r\n /** DRight */\r\n DPadRight = 15,\r\n /** Home */\r\n Home = 16,\r\n /** LStickXAxis */\r\n LStickXAxis = 17,\r\n /** LStickYAxis */\r\n LStickYAxis = 18,\r\n /** RStickXAxis */\r\n RStickXAxis = 19,\r\n /** RStickYAxis */\r\n RStickYAxis = 20,\r\n}\r\n\r\n/**\r\n * Enum for Switch (Pro/JoyCon L+R) Gamepad\r\n */\r\nexport enum SwitchInput {\r\n /** B */\r\n B = 0,\r\n /** A */\r\n A = 1,\r\n /** Y */\r\n Y = 2,\r\n /** X */\r\n X = 3,\r\n /** L */\r\n L = 4,\r\n /** R */\r\n R = 5,\r\n /** ZL */\r\n ZL = 6,\r\n /** ZR */\r\n ZR = 7,\r\n /** Minus */\r\n Minus = 8,\r\n /** Plus */\r\n Plus = 9,\r\n /** LS */\r\n LS = 10,\r\n /** RS */\r\n RS = 11,\r\n /** DPadUp */\r\n DPadUp = 12,\r\n /** DPadDown */\r\n DPadDown = 13,\r\n /** DPadLeft */\r\n DPadLeft = 14,\r\n /** DRight */\r\n DPadRight = 15,\r\n /** Home */\r\n Home = 16,\r\n /** Capture */\r\n Capture = 17,\r\n /** LStickXAxis */\r\n LStickXAxis = 18,\r\n /** LStickYAxis */\r\n LStickYAxis = 19,\r\n /** RStickXAxis */\r\n RStickXAxis = 20,\r\n /** RStickYAxis */\r\n RStickYAxis = 21,\r\n}\r\n","import type { PointerInput } from \"../DeviceInput/InputDevices/deviceEnums\";\r\n\r\n/**\r\n * Event Types\r\n */\r\nexport enum DeviceInputEventType {\r\n // Pointers\r\n /** PointerMove */\r\n PointerMove,\r\n /** PointerDown */\r\n PointerDown,\r\n /** PointerUp */\r\n PointerUp,\r\n}\r\n\r\n/**\r\n * Native friendly interface for Event Object\r\n */\r\nexport interface IUIEvent {\r\n /**\r\n * Input array index\r\n */\r\n inputIndex: number;\r\n\r\n /**\r\n * Current target for an event\r\n */\r\n currentTarget?: any;\r\n\r\n /**\r\n * Alias for target\r\n * @deprecated Use target instead\r\n */\r\n srcElement?: any;\r\n\r\n /**\r\n * Type of event\r\n */\r\n type: string;\r\n\r\n /**\r\n * Reference to object where object was dispatched\r\n */\r\n target: any;\r\n\r\n /**\r\n * Tells user agent what to do when not explicitly handled\r\n */\r\n preventDefault: () => void;\r\n}\r\n\r\n/**\r\n * Native friendly interface for KeyboardEvent Object\r\n */\r\nexport interface IKeyboardEvent extends IUIEvent {\r\n /**\r\n * Status of Alt key being pressed\r\n */\r\n altKey: boolean;\r\n\r\n /**\r\n * Unicode value of character pressed\r\n * @deprecated Required for event, use keyCode instead.\r\n */\r\n charCode?: number;\r\n\r\n /**\r\n * Code for key based on layout\r\n */\r\n code: string;\r\n\r\n /**\r\n * Status of Ctrl key being pressed\r\n */\r\n ctrlKey: boolean;\r\n\r\n /**\r\n * String representation of key\r\n */\r\n key: string;\r\n /**\r\n * ASCII value of key\r\n * @deprecated Used with DeviceSourceManager\r\n */\r\n keyCode: number;\r\n\r\n /**\r\n * Status of Meta key (eg. Windows key) being pressed\r\n */\r\n metaKey: boolean;\r\n\r\n /**\r\n * Status of Shift key being pressed\r\n */\r\n shiftKey: boolean;\r\n}\r\n\r\n/**\r\n * Native friendly interface for MouseEvent Object\r\n */\r\nexport interface IMouseEvent extends IUIEvent {\r\n /**\r\n * Subset of possible PointerInput values for events, excluding ones that CANNOT be in events organically\r\n */\r\n inputIndex: Exclude;\r\n\r\n /**\r\n * Status of Alt key being pressed\r\n */\r\n altKey: boolean;\r\n\r\n /**\r\n * Value of single mouse button pressed\r\n */\r\n button: number;\r\n\r\n /**\r\n * Value of all mouse buttons pressed\r\n */\r\n buttons: number;\r\n\r\n /**\r\n * Current X coordinate\r\n */\r\n clientX: number;\r\n\r\n /**\r\n * Current Y coordinate\r\n */\r\n clientY: number;\r\n\r\n /**\r\n * Status of Ctrl key being pressed\r\n */\r\n ctrlKey: boolean;\r\n\r\n /**\r\n * Provides current click count\r\n */\r\n detail?: number;\r\n\r\n /**\r\n * Status of Meta key (eg. Windows key) being pressed\r\n */\r\n metaKey: boolean;\r\n\r\n /**\r\n * Delta of movement on X axis\r\n */\r\n movementX: number;\r\n\r\n /**\r\n * Delta of movement on Y axis\r\n */\r\n movementY: number;\r\n\r\n /**\r\n * Delta of movement on X axis\r\n * @deprecated Use 'movementX' instead\r\n */\r\n mozMovementX?: number;\r\n\r\n /**\r\n * Delta of movement on Y axis\r\n * @deprecated Use 'movementY' instead\r\n */\r\n mozMovementY?: number;\r\n\r\n /**\r\n * Delta of movement on X axis\r\n * @deprecated Use 'movementX' instead\r\n */\r\n msMovementX?: number;\r\n\r\n /**\r\n * Delta of movement on Y axis\r\n * @deprecated Use 'movementY' instead\r\n */\r\n msMovementY?: number;\r\n\r\n /**\r\n * Current coordinate of X within container\r\n */\r\n offsetX: number;\r\n\r\n /**\r\n * Current coordinate of Y within container\r\n */\r\n offsetY: number;\r\n\r\n /**\r\n * Horizontal coordinate of event\r\n */\r\n pageX: number;\r\n\r\n /**\r\n * Vertical coordinate of event\r\n */\r\n pageY: number;\r\n\r\n /**\r\n * Status of Shift key being pressed\r\n */\r\n shiftKey: boolean;\r\n\r\n /**\r\n * Delta of movement on X axis\r\n * @deprecated Use 'movementX' instead\r\n */\r\n webkitMovementX?: number;\r\n\r\n /**\r\n * Delta of movement on Y axis\r\n * @deprecated Use 'movementY' instead\r\n */\r\n webkitMovementY?: number;\r\n\r\n /**\r\n * Alias of clientX\r\n */\r\n x: number;\r\n\r\n /**\r\n * Alias of clientY\r\n */\r\n y: number;\r\n}\r\n\r\n/**\r\n * Native friendly interface for PointerEvent Object\r\n */\r\nexport interface IPointerEvent extends IMouseEvent {\r\n /**\r\n * Subset of possible PointerInput values for events, excluding ones that CANNOT be in events organically and mouse wheel values\r\n */\r\n inputIndex: Exclude;\r\n\r\n /**\r\n * Pointer Event ID\r\n */\r\n pointerId: number;\r\n\r\n /**\r\n * Type of pointer\r\n */\r\n pointerType: string;\r\n}\r\n\r\n/**\r\n * Native friendly interface for WheelEvent Object\r\n */\r\nexport interface IWheelEvent extends IMouseEvent {\r\n /**\r\n * Subset of possible PointerInput values for events that can only be used with mouse wheel\r\n */\r\n inputIndex: PointerInput.MouseWheelX | PointerInput.MouseWheelY | PointerInput.MouseWheelZ;\r\n\r\n /**\r\n * Units for delta value\r\n */\r\n deltaMode: number;\r\n\r\n /**\r\n * Horizontal scroll delta\r\n */\r\n deltaX: number;\r\n\r\n /**\r\n * Vertical scroll delta\r\n */\r\n deltaY: number;\r\n\r\n /**\r\n * Z-Axis scroll delta\r\n */\r\n deltaZ: number;\r\n\r\n /**\r\n * WheelDelta (From MouseWheel Event)\r\n * @deprecated\r\n */\r\n wheelDelta?: number;\r\n}\r\n\r\n/**\r\n * Constants used for Events\r\n */\r\nexport class EventConstants {\r\n /**\r\n * Pixel delta for Wheel Events (Default)\r\n */\r\n public static DOM_DELTA_PIXEL = 0x00;\r\n\r\n /**\r\n * Line delta for Wheel Events\r\n */\r\n public static DOM_DELTA_LINE = 0x01;\r\n\r\n /**\r\n * Page delta for Wheel Events\r\n */\r\n public static DOM_DELTA_PAGE = 0x02;\r\n}\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { FloatArray, Nullable } from \"../../types\";\r\nimport type { DataBuffer } from \"../../Buffers/dataBuffer\";\r\nimport { WebGLDataBuffer } from \"../../Meshes/WebGL/webGLDataBuffer\";\r\nimport type { IPipelineContext } from \"../IPipelineContext\";\r\nimport type { WebGLPipelineContext } from \"../WebGL/webGLPipelineContext\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Create an uniform buffer\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets\r\n * @param elements defines the content of the uniform buffer\r\n * @returns the webGL uniform buffer\r\n */\r\n createUniformBuffer(elements: FloatArray): DataBuffer;\r\n\r\n /**\r\n * Create a dynamic uniform buffer\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets\r\n * @param elements defines the content of the uniform buffer\r\n * @returns the webGL uniform buffer\r\n */\r\n createDynamicUniformBuffer(elements: FloatArray): DataBuffer;\r\n\r\n /**\r\n * Update an existing uniform buffer\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets\r\n * @param uniformBuffer defines the target uniform buffer\r\n * @param elements defines the content to update\r\n * @param offset defines the offset in the uniform buffer where update should start\r\n * @param count defines the size of the data to update\r\n */\r\n updateUniformBuffer(uniformBuffer: DataBuffer, elements: FloatArray, offset?: number, count?: number): void;\r\n\r\n /**\r\n * Bind an uniform buffer to the current webGL context\r\n * @param buffer defines the buffer to bind\r\n */\r\n bindUniformBuffer(buffer: Nullable): void;\r\n\r\n /**\r\n * Bind a buffer to the current webGL context at a given location\r\n * @param buffer defines the buffer to bind\r\n * @param location defines the index where to bind the buffer\r\n * @param name Name of the uniform variable to bind\r\n */\r\n bindUniformBufferBase(buffer: DataBuffer, location: number, name: string): void;\r\n\r\n /**\r\n * Bind a specific block at a given index in a specific shader program\r\n * @param pipelineContext defines the pipeline context to use\r\n * @param blockName defines the block name\r\n * @param index defines the index where to bind the block\r\n */\r\n bindUniformBlock(pipelineContext: IPipelineContext, blockName: string, index: number): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createUniformBuffer = function (elements: FloatArray): DataBuffer {\r\n const ubo = this._gl.createBuffer();\r\n\r\n if (!ubo) {\r\n throw new Error(\"Unable to create uniform buffer\");\r\n }\r\n const result = new WebGLDataBuffer(ubo);\r\n\r\n this.bindUniformBuffer(result);\r\n\r\n if (elements instanceof Float32Array) {\r\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, elements, this._gl.STATIC_DRAW);\r\n } else {\r\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(elements), this._gl.STATIC_DRAW);\r\n }\r\n\r\n this.bindUniformBuffer(null);\r\n\r\n result.references = 1;\r\n return result;\r\n};\r\n\r\nThinEngine.prototype.createDynamicUniformBuffer = function (elements: FloatArray): DataBuffer {\r\n const ubo = this._gl.createBuffer();\r\n\r\n if (!ubo) {\r\n throw new Error(\"Unable to create dynamic uniform buffer\");\r\n }\r\n\r\n const result = new WebGLDataBuffer(ubo);\r\n this.bindUniformBuffer(result);\r\n\r\n if (elements instanceof Float32Array) {\r\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, elements, this._gl.DYNAMIC_DRAW);\r\n } else {\r\n this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(elements), this._gl.DYNAMIC_DRAW);\r\n }\r\n\r\n this.bindUniformBuffer(null);\r\n\r\n result.references = 1;\r\n return result;\r\n};\r\n\r\nThinEngine.prototype.updateUniformBuffer = function (uniformBuffer: DataBuffer, elements: FloatArray, offset?: number, count?: number): void {\r\n this.bindUniformBuffer(uniformBuffer);\r\n\r\n if (offset === undefined) {\r\n offset = 0;\r\n }\r\n\r\n if (count === undefined) {\r\n if (elements instanceof Float32Array) {\r\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, elements);\r\n } else {\r\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, new Float32Array(elements));\r\n }\r\n } else {\r\n if (elements instanceof Float32Array) {\r\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, elements.subarray(offset, offset + count));\r\n } else {\r\n this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, new Float32Array(elements).subarray(offset, offset + count));\r\n }\r\n }\r\n\r\n this.bindUniformBuffer(null);\r\n};\r\n\r\nThinEngine.prototype.bindUniformBuffer = function (buffer: Nullable): void {\r\n this._gl.bindBuffer(this._gl.UNIFORM_BUFFER, buffer ? buffer.underlyingResource : null);\r\n};\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nThinEngine.prototype.bindUniformBufferBase = function (buffer: DataBuffer, location: number, name: string): void {\r\n this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER, location, buffer ? buffer.underlyingResource : null);\r\n};\r\n\r\nThinEngine.prototype.bindUniformBlock = function (pipelineContext: IPipelineContext, blockName: string, index: number): void {\r\n const program = (pipelineContext as WebGLPipelineContext).program!;\r\n\r\n const uniformLocation = this._gl.getUniformBlockIndex(program, blockName);\r\n\r\n if (uniformLocation !== 0xffffffff) {\r\n this._gl.uniformBlockBinding(program, uniformLocation, index);\r\n }\r\n};\r\n","import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable, FloatArray } from \"../types\";\r\nimport type { IMatrixLike, IVector3Like, IVector4Like, IColor3Like, IColor4Like } from \"../Maths/math.like\";\r\nimport type { Effect } from \"./effect\";\r\nimport type { ThinTexture } from \"../Materials/Textures/thinTexture\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\nimport \"../Engines/Extensions/engine.uniformBuffer\";\r\n\r\n/**\r\n * Uniform buffer objects.\r\n *\r\n * Handles blocks of uniform on the GPU.\r\n *\r\n * If WebGL 2 is not available, this class falls back on traditional setUniformXXX calls.\r\n *\r\n * For more information, please refer to :\r\n * https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object\r\n */\r\nexport class UniformBuffer {\r\n /** @internal */\r\n public static _UpdatedUbosInFrame: { [name: string]: number } = {};\r\n\r\n private _engine: ThinEngine;\r\n private _buffer: Nullable;\r\n private _buffers: Array<[DataBuffer, Float32Array | undefined]>;\r\n private _bufferIndex: number;\r\n private _createBufferOnWrite: boolean;\r\n private _data: number[];\r\n private _bufferData: Float32Array;\r\n private _dynamic?: boolean;\r\n private _uniformLocations: { [key: string]: number };\r\n private _uniformSizes: { [key: string]: number };\r\n private _uniformArraySizes: { [key: string]: { strideSize: number; arraySize: number } };\r\n private _uniformLocationPointer: number;\r\n private _needSync: boolean;\r\n private _noUBO: boolean;\r\n private _currentEffect: Effect;\r\n private _currentEffectName: string;\r\n private _name: string;\r\n private _currentFrameId: number;\r\n\r\n // Pool for avoiding memory leaks\r\n private static _MAX_UNIFORM_SIZE = 256;\r\n private static _TempBuffer = new Float32Array(UniformBuffer._MAX_UNIFORM_SIZE);\r\n private static _TempBufferInt32View = new Int32Array(UniformBuffer._TempBuffer.buffer);\r\n private static _TempBufferUInt32View = new Uint32Array(UniformBuffer._TempBuffer.buffer);\r\n\r\n /**\r\n * Lambda to Update a 3x3 Matrix in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateMatrix3x3: (name: string, matrix: Float32Array) => void;\r\n\r\n /**\r\n * Lambda to Update a 2x2 Matrix in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateMatrix2x2: (name: string, matrix: Float32Array) => void;\r\n\r\n /**\r\n * Lambda to Update a single float in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateFloat: (name: string, x: number) => void;\r\n\r\n /**\r\n * Lambda to Update a vec2 of float in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateFloat2: (name: string, x: number, y: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec3 of float in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateFloat3: (name: string, x: number, y: number, z: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec4 of float in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateFloat4: (name: string, x: number, y: number, z: number, w: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update an array of float in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateFloatArray: (name: string, array: Float32Array) => void;\r\n\r\n /**\r\n * Lambda to Update an array of number in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateArray: (name: string, array: number[]) => void;\r\n\r\n /**\r\n * Lambda to Update an array of number in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateIntArray: (name: string, array: Int32Array) => void;\r\n\r\n /**\r\n * Lambda to Update an array of number in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateUIntArray: (name: string, array: Uint32Array) => void;\r\n\r\n /**\r\n * Lambda to Update a 4x4 Matrix in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateMatrix: (name: string, mat: IMatrixLike) => void;\r\n\r\n /**\r\n * Lambda to Update an array of 4x4 Matrix in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateMatrices: (name: string, mat: Float32Array) => void;\r\n\r\n /**\r\n * Lambda to Update vec3 of float from a Vector in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateVector3: (name: string, vector: IVector3Like) => void;\r\n\r\n /**\r\n * Lambda to Update vec4 of float from a Vector in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateVector4: (name: string, vector: IVector4Like) => void;\r\n\r\n /**\r\n * Lambda to Update vec3 of float from a Color in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateColor3: (name: string, color: IColor3Like, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update vec4 of float from a Color in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateColor4: (name: string, color: IColor3Like, alpha: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update vec4 of float from a Color in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateDirectColor4: (name: string, color: IColor4Like, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a int a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateInt: (name: string, x: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec2 of int in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateInt2: (name: string, x: number, y: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec3 of int in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateInt3: (name: string, x: number, y: number, z: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec4 of int in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateInt4: (name: string, x: number, y: number, z: number, w: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a unsigned int a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateUInt: (name: string, x: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec2 of unsigned int in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateUInt2: (name: string, x: number, y: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec3 of unsigned int in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateUInt3: (name: string, x: number, y: number, z: number, suffix?: string) => void;\r\n\r\n /**\r\n * Lambda to Update a vec4 of unsigned int in a uniform buffer.\r\n * This is dynamic to allow compat with webgl 1 and 2.\r\n * You will need to pass the name of the uniform as well as the value.\r\n */\r\n public updateUInt4: (name: string, x: number, y: number, z: number, w: number, suffix?: string) => void;\r\n\r\n /**\r\n * Instantiates a new Uniform buffer objects.\r\n *\r\n * Handles blocks of uniform on the GPU.\r\n *\r\n * If WebGL 2 is not available, this class falls back on traditional setUniformXXX calls.\r\n *\r\n * For more information, please refer to :\r\n * @see https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object\r\n * @param engine Define the engine the buffer is associated with\r\n * @param data Define the data contained in the buffer\r\n * @param dynamic Define if the buffer is updatable\r\n * @param name to assign to the buffer (debugging purpose)\r\n * @param forceNoUniformBuffer define that this object must not rely on UBO objects\r\n */\r\n constructor(engine: ThinEngine, data?: number[], dynamic?: boolean, name?: string, forceNoUniformBuffer = false) {\r\n this._engine = engine;\r\n this._noUBO = !engine.supportsUniformBuffers || forceNoUniformBuffer;\r\n this._dynamic = dynamic;\r\n this._name = name ?? \"no-name\";\r\n\r\n this._data = data || [];\r\n\r\n this._uniformLocations = {};\r\n this._uniformSizes = {};\r\n this._uniformArraySizes = {};\r\n this._uniformLocationPointer = 0;\r\n this._needSync = false;\r\n\r\n if (this._engine._features.trackUbosInFrame) {\r\n this._buffers = [];\r\n this._bufferIndex = -1;\r\n this._createBufferOnWrite = false;\r\n this._currentFrameId = 0;\r\n }\r\n\r\n if (this._noUBO) {\r\n this.updateMatrix3x3 = this._updateMatrix3x3ForEffect;\r\n this.updateMatrix2x2 = this._updateMatrix2x2ForEffect;\r\n this.updateFloat = this._updateFloatForEffect;\r\n this.updateFloat2 = this._updateFloat2ForEffect;\r\n this.updateFloat3 = this._updateFloat3ForEffect;\r\n this.updateFloat4 = this._updateFloat4ForEffect;\r\n this.updateFloatArray = this._updateFloatArrayForEffect;\r\n this.updateArray = this._updateArrayForEffect;\r\n this.updateIntArray = this._updateIntArrayForEffect;\r\n this.updateUIntArray = this._updateUIntArrayForEffect;\r\n this.updateMatrix = this._updateMatrixForEffect;\r\n this.updateMatrices = this._updateMatricesForEffect;\r\n this.updateVector3 = this._updateVector3ForEffect;\r\n this.updateVector4 = this._updateVector4ForEffect;\r\n this.updateColor3 = this._updateColor3ForEffect;\r\n this.updateColor4 = this._updateColor4ForEffect;\r\n this.updateDirectColor4 = this._updateDirectColor4ForEffect;\r\n this.updateInt = this._updateIntForEffect;\r\n this.updateInt2 = this._updateInt2ForEffect;\r\n this.updateInt3 = this._updateInt3ForEffect;\r\n this.updateInt4 = this._updateInt4ForEffect;\r\n this.updateUInt = this._updateUIntForEffect;\r\n this.updateUInt2 = this._updateUInt2ForEffect;\r\n this.updateUInt3 = this._updateUInt3ForEffect;\r\n this.updateUInt4 = this._updateUInt4ForEffect;\r\n } else {\r\n this._engine._uniformBuffers.push(this);\r\n\r\n this.updateMatrix3x3 = this._updateMatrix3x3ForUniform;\r\n this.updateMatrix2x2 = this._updateMatrix2x2ForUniform;\r\n this.updateFloat = this._updateFloatForUniform;\r\n this.updateFloat2 = this._updateFloat2ForUniform;\r\n this.updateFloat3 = this._updateFloat3ForUniform;\r\n this.updateFloat4 = this._updateFloat4ForUniform;\r\n this.updateFloatArray = this._updateFloatArrayForUniform;\r\n this.updateArray = this._updateArrayForUniform;\r\n this.updateIntArray = this._updateIntArrayForUniform;\r\n this.updateUIntArray = this._updateUIntArrayForUniform;\r\n this.updateMatrix = this._updateMatrixForUniform;\r\n this.updateMatrices = this._updateMatricesForUniform;\r\n this.updateVector3 = this._updateVector3ForUniform;\r\n this.updateVector4 = this._updateVector4ForUniform;\r\n this.updateColor3 = this._updateColor3ForUniform;\r\n this.updateColor4 = this._updateColor4ForUniform;\r\n this.updateDirectColor4 = this._updateDirectColor4ForUniform;\r\n this.updateInt = this._updateIntForUniform;\r\n this.updateInt2 = this._updateInt2ForUniform;\r\n this.updateInt3 = this._updateInt3ForUniform;\r\n this.updateInt4 = this._updateInt4ForUniform;\r\n this.updateUInt = this._updateUIntForUniform;\r\n this.updateUInt2 = this._updateUInt2ForUniform;\r\n this.updateUInt3 = this._updateUInt3ForUniform;\r\n this.updateUInt4 = this._updateUInt4ForUniform;\r\n }\r\n }\r\n\r\n /**\r\n * Indicates if the buffer is using the WebGL2 UBO implementation,\r\n * or just falling back on setUniformXXX calls.\r\n */\r\n public get useUbo(): boolean {\r\n return !this._noUBO;\r\n }\r\n\r\n /**\r\n * Indicates if the WebGL underlying uniform buffer is in sync\r\n * with the javascript cache data.\r\n */\r\n public get isSync(): boolean {\r\n return !this._needSync;\r\n }\r\n\r\n /**\r\n * Indicates if the WebGL underlying uniform buffer is dynamic.\r\n * Also, a dynamic UniformBuffer will disable cache verification and always\r\n * update the underlying WebGL uniform buffer to the GPU.\r\n * @returns if Dynamic, otherwise false\r\n */\r\n public isDynamic(): boolean {\r\n return this._dynamic !== undefined;\r\n }\r\n\r\n /**\r\n * The data cache on JS side.\r\n * @returns the underlying data as a float array\r\n */\r\n public getData(): Float32Array {\r\n return this._bufferData;\r\n }\r\n\r\n /**\r\n * The underlying WebGL Uniform buffer.\r\n * @returns the webgl buffer\r\n */\r\n public getBuffer(): Nullable {\r\n return this._buffer;\r\n }\r\n\r\n /**\r\n * std140 layout specifies how to align data within an UBO structure.\r\n * See https://khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf#page=159\r\n * for specs.\r\n * @param size\r\n */\r\n private _fillAlignment(size: number) {\r\n // This code has been simplified because we only use floats, vectors of 1, 2, 3, 4 components\r\n // and 4x4 matrices\r\n // TODO : change if other types are used\r\n\r\n let alignment;\r\n if (size <= 2) {\r\n alignment = size;\r\n } else {\r\n alignment = 4;\r\n }\r\n\r\n if (this._uniformLocationPointer % alignment !== 0) {\r\n const oldPointer = this._uniformLocationPointer;\r\n this._uniformLocationPointer += alignment - (this._uniformLocationPointer % alignment);\r\n const diff = this._uniformLocationPointer - oldPointer;\r\n\r\n for (let i = 0; i < diff; i++) {\r\n this._data.push(0);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Adds an uniform in the buffer.\r\n * Warning : the subsequents calls of this function must be in the same order as declared in the shader\r\n * for the layout to be correct ! The addUniform function only handles types like float, vec2, vec3, vec4, mat4,\r\n * meaning size=1,2,3,4 or 16. It does not handle struct types.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param size Data size, or data directly.\r\n * @param arraySize The number of elements in the array, 0 if not an array.\r\n */\r\n public addUniform(name: string, size: number | number[], arraySize = 0) {\r\n if (this._noUBO) {\r\n return;\r\n }\r\n\r\n if (this._uniformLocations[name] !== undefined) {\r\n // Already existing uniform\r\n return;\r\n }\r\n // This function must be called in the order of the shader layout !\r\n // size can be the size of the uniform, or data directly\r\n let data;\r\n\r\n // std140 FTW...\r\n if (arraySize > 0) {\r\n if (size instanceof Array) {\r\n throw \"addUniform should not be use with Array in UBO: \" + name;\r\n }\r\n\r\n this._fillAlignment(4);\r\n\r\n this._uniformArraySizes[name] = { strideSize: size, arraySize };\r\n if (size == 16) {\r\n size = size * arraySize;\r\n } else {\r\n const perElementPadding = 4 - size;\r\n const totalPadding = perElementPadding * arraySize;\r\n size = size * arraySize + totalPadding;\r\n }\r\n\r\n data = [];\r\n // Fill with zeros\r\n for (let i = 0; i < size; i++) {\r\n data.push(0);\r\n }\r\n } else {\r\n if (size instanceof Array) {\r\n data = size;\r\n size = data.length;\r\n } else {\r\n size = size;\r\n data = [];\r\n\r\n // Fill with zeros\r\n for (let i = 0; i < size; i++) {\r\n data.push(0);\r\n }\r\n }\r\n this._fillAlignment(size);\r\n }\r\n\r\n this._uniformSizes[name] = size;\r\n this._uniformLocations[name] = this._uniformLocationPointer;\r\n this._uniformLocationPointer += size;\r\n\r\n for (let i = 0; i < size; i++) {\r\n this._data.push(data[i]);\r\n }\r\n\r\n this._needSync = true;\r\n }\r\n\r\n /**\r\n * Adds a Matrix 4x4 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param mat A 4x4 matrix.\r\n */\r\n public addMatrix(name: string, mat: IMatrixLike) {\r\n this.addUniform(name, Array.prototype.slice.call(mat.toArray()));\r\n }\r\n\r\n /**\r\n * Adds a vec2 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param x Define the x component value of the vec2\r\n * @param y Define the y component value of the vec2\r\n */\r\n public addFloat2(name: string, x: number, y: number) {\r\n const temp = [x, y];\r\n this.addUniform(name, temp);\r\n }\r\n\r\n /**\r\n * Adds a vec3 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param x Define the x component value of the vec3\r\n * @param y Define the y component value of the vec3\r\n * @param z Define the z component value of the vec3\r\n */\r\n public addFloat3(name: string, x: number, y: number, z: number) {\r\n const temp = [x, y, z];\r\n this.addUniform(name, temp);\r\n }\r\n\r\n /**\r\n * Adds a vec3 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param color Define the vec3 from a Color\r\n */\r\n public addColor3(name: string, color: IColor3Like) {\r\n const temp = [color.r, color.g, color.b];\r\n this.addUniform(name, temp);\r\n }\r\n\r\n /**\r\n * Adds a vec4 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param color Define the rgb components from a Color\r\n * @param alpha Define the a component of the vec4\r\n */\r\n public addColor4(name: string, color: IColor3Like, alpha: number) {\r\n const temp = [color.r, color.g, color.b, alpha];\r\n this.addUniform(name, temp);\r\n }\r\n\r\n /**\r\n * Adds a vec3 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n * @param vector Define the vec3 components from a Vector\r\n */\r\n public addVector3(name: string, vector: IVector3Like) {\r\n const temp = [vector.x, vector.y, vector.z];\r\n this.addUniform(name, temp);\r\n }\r\n\r\n /**\r\n * Adds a Matrix 3x3 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n */\r\n public addMatrix3x3(name: string) {\r\n this.addUniform(name, 12);\r\n }\r\n\r\n /**\r\n * Adds a Matrix 2x2 to the uniform buffer.\r\n * @param name Name of the uniform, as used in the uniform block in the shader.\r\n */\r\n public addMatrix2x2(name: string) {\r\n this.addUniform(name, 8);\r\n }\r\n\r\n /**\r\n * Effectively creates the WebGL Uniform Buffer, once layout is completed with `addUniform`.\r\n */\r\n public create(): void {\r\n if (this._noUBO) {\r\n return;\r\n }\r\n if (this._buffer) {\r\n return; // nothing to do\r\n }\r\n\r\n // See spec, alignment must be filled as a vec4\r\n this._fillAlignment(4);\r\n this._bufferData = new Float32Array(this._data);\r\n\r\n this._rebuild();\r\n\r\n this._needSync = true;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (this._noUBO || !this._bufferData) {\r\n return;\r\n }\r\n\r\n if (this._dynamic) {\r\n this._buffer = this._engine.createDynamicUniformBuffer(this._bufferData);\r\n } else {\r\n this._buffer = this._engine.createUniformBuffer(this._bufferData);\r\n }\r\n\r\n if (this._engine._features.trackUbosInFrame) {\r\n this._buffers.push([this._buffer, this._engine._features.checkUbosContentBeforeUpload ? this._bufferData.slice() : undefined]);\r\n this._bufferIndex = this._buffers.length - 1;\r\n this._createBufferOnWrite = false;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public get _numBuffers(): number {\r\n return this._buffers.length;\r\n }\r\n\r\n /** @internal */\r\n public get _indexBuffer(): number {\r\n return this._bufferIndex;\r\n }\r\n\r\n /** Gets the name of this buffer */\r\n public get name(): string {\r\n return this._name;\r\n }\r\n\r\n /** Gets the current effect */\r\n public get currentEffect(): Nullable {\r\n return this._currentEffect;\r\n }\r\n\r\n private _buffersEqual(buf1: Float32Array, buf2: Float32Array): boolean {\r\n for (let i = 0; i < buf1.length; ++i) {\r\n if (buf1[i] !== buf2[i]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n private _copyBuffer(src: Float32Array, dst: Float32Array): void {\r\n for (let i = 0; i < src.length; ++i) {\r\n dst[i] = src[i];\r\n }\r\n }\r\n\r\n /**\r\n * Updates the WebGL Uniform Buffer on the GPU.\r\n * If the `dynamic` flag is set to true, no cache comparison is done.\r\n * Otherwise, the buffer will be updated only if the cache differs.\r\n */\r\n public update(): void {\r\n if (this._noUBO) {\r\n return;\r\n }\r\n\r\n this.bindUniformBuffer();\r\n\r\n if (!this._buffer) {\r\n this.create();\r\n return;\r\n }\r\n\r\n if (!this._dynamic && !this._needSync) {\r\n this._createBufferOnWrite = this._engine._features.trackUbosInFrame;\r\n return;\r\n }\r\n\r\n if (this._buffers && this._buffers.length > 1 && this._buffers[this._bufferIndex][1]) {\r\n if (this._buffersEqual(this._bufferData, this._buffers[this._bufferIndex][1]!)) {\r\n this._needSync = false;\r\n this._createBufferOnWrite = this._engine._features.trackUbosInFrame;\r\n return;\r\n } else {\r\n this._copyBuffer(this._bufferData, this._buffers[this._bufferIndex][1]!);\r\n }\r\n }\r\n\r\n this._engine.updateUniformBuffer(this._buffer, this._bufferData);\r\n\r\n if (this._engine._features._collectUbosUpdatedInFrame) {\r\n if (!UniformBuffer._UpdatedUbosInFrame[this._name]) {\r\n UniformBuffer._UpdatedUbosInFrame[this._name] = 0;\r\n }\r\n UniformBuffer._UpdatedUbosInFrame[this._name]++;\r\n }\r\n\r\n this._needSync = false;\r\n this._createBufferOnWrite = this._engine._features.trackUbosInFrame;\r\n }\r\n\r\n private _createNewBuffer() {\r\n if (this._bufferIndex + 1 < this._buffers.length) {\r\n this._bufferIndex++;\r\n this._buffer = this._buffers[this._bufferIndex][0];\r\n this._createBufferOnWrite = false;\r\n this._needSync = true;\r\n } else {\r\n this._rebuild();\r\n }\r\n }\r\n\r\n private _checkNewFrame(): void {\r\n if (this._engine._features.trackUbosInFrame && this._currentFrameId !== this._engine.frameId) {\r\n this._currentFrameId = this._engine.frameId;\r\n this._createBufferOnWrite = false;\r\n if (this._buffers && this._buffers.length > 0) {\r\n this._needSync = this._bufferIndex !== 0;\r\n this._bufferIndex = 0;\r\n this._buffer = this._buffers[this._bufferIndex][0];\r\n } else {\r\n this._bufferIndex = -1;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Updates the value of an uniform. The `update` method must be called afterwards to make it effective in the GPU.\r\n * @param uniformName Define the name of the uniform, as used in the uniform block in the shader.\r\n * @param data Define the flattened data\r\n * @param size Define the size of the data.\r\n */\r\n public updateUniform(uniformName: string, data: FloatArray, size: number) {\r\n this._checkNewFrame();\r\n\r\n let location = this._uniformLocations[uniformName];\r\n if (location === undefined) {\r\n if (this._buffer) {\r\n // Cannot add an uniform if the buffer is already created\r\n Logger.Error(\"Cannot add an uniform after UBO has been created.\");\r\n return;\r\n }\r\n this.addUniform(uniformName, size);\r\n location = this._uniformLocations[uniformName];\r\n }\r\n\r\n if (!this._buffer) {\r\n this.create();\r\n }\r\n\r\n if (!this._dynamic) {\r\n // Cache for static uniform buffers\r\n let changed = false;\r\n\r\n for (let i = 0; i < size; i++) {\r\n // We are checking the matrix cache before calling updateUniform so we do not need to check it here\r\n // Hence the test for size === 16 to simply commit the matrix values\r\n if ((size === 16 && !this._engine._features.uniformBufferHardCheckMatrix) || this._bufferData[location + i] !== Tools.FloatRound(data[i])) {\r\n changed = true;\r\n if (this._createBufferOnWrite) {\r\n this._createNewBuffer();\r\n }\r\n this._bufferData[location + i] = data[i];\r\n }\r\n }\r\n\r\n this._needSync = this._needSync || changed;\r\n } else {\r\n // No cache for dynamic\r\n for (let i = 0; i < size; i++) {\r\n this._bufferData[location + i] = data[i];\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Updates the value of an uniform. The `update` method must be called afterwards to make it effective in the GPU.\r\n * @param uniformName Define the name of the uniform, as used in the uniform block in the shader.\r\n * @param data Define the flattened data\r\n * @param size Define the size of the data.\r\n */\r\n public updateUniformArray(uniformName: string, data: FloatArray, size: number) {\r\n this._checkNewFrame();\r\n\r\n const location = this._uniformLocations[uniformName];\r\n if (location === undefined) {\r\n Logger.Error(\"Cannot add an uniform Array dynamically. Please, add it using addUniform and make sure that uniform buffers are supported by the current engine.\");\r\n return;\r\n }\r\n\r\n if (!this._buffer) {\r\n this.create();\r\n }\r\n\r\n const arraySizes = this._uniformArraySizes[uniformName];\r\n\r\n if (!this._dynamic) {\r\n // Cache for static uniform buffers\r\n let changed = false;\r\n let countToFour = 0;\r\n let baseStride = 0;\r\n for (let i = 0; i < size; i++) {\r\n if (this._bufferData[location + baseStride * 4 + countToFour] !== Tools.FloatRound(data[i])) {\r\n changed = true;\r\n if (this._createBufferOnWrite) {\r\n this._createNewBuffer();\r\n }\r\n this._bufferData[location + baseStride * 4 + countToFour] = data[i];\r\n }\r\n countToFour++;\r\n if (countToFour === arraySizes.strideSize) {\r\n for (; countToFour < 4; countToFour++) {\r\n this._bufferData[location + baseStride * 4 + countToFour] = 0;\r\n }\r\n countToFour = 0;\r\n baseStride++;\r\n }\r\n }\r\n\r\n this._needSync = this._needSync || changed;\r\n } else {\r\n // No cache for dynamic\r\n for (let i = 0; i < size; i++) {\r\n this._bufferData[location + i] = data[i];\r\n }\r\n }\r\n }\r\n\r\n // Matrix cache\r\n private _valueCache: { [key: string]: number } = {};\r\n private _cacheMatrix(name: string, matrix: IMatrixLike): boolean {\r\n this._checkNewFrame();\r\n\r\n const cache = this._valueCache[name];\r\n const flag = matrix.updateFlag;\r\n if (cache !== undefined && cache === flag) {\r\n return false;\r\n }\r\n\r\n this._valueCache[name] = flag;\r\n return true;\r\n }\r\n\r\n // Update methods\r\n\r\n private _updateMatrix3x3ForUniform(name: string, matrix: Float32Array): void {\r\n // To match std140, matrix must be realigned\r\n for (let i = 0; i < 3; i++) {\r\n UniformBuffer._TempBuffer[i * 4] = matrix[i * 3];\r\n UniformBuffer._TempBuffer[i * 4 + 1] = matrix[i * 3 + 1];\r\n UniformBuffer._TempBuffer[i * 4 + 2] = matrix[i * 3 + 2];\r\n UniformBuffer._TempBuffer[i * 4 + 3] = 0.0;\r\n }\r\n\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 12);\r\n }\r\n\r\n private _updateMatrix3x3ForEffect(name: string, matrix: Float32Array): void {\r\n this._currentEffect.setMatrix3x3(name, matrix);\r\n }\r\n\r\n private _updateMatrix2x2ForEffect(name: string, matrix: Float32Array): void {\r\n this._currentEffect.setMatrix2x2(name, matrix);\r\n }\r\n\r\n private _updateMatrix2x2ForUniform(name: string, matrix: Float32Array): void {\r\n // To match std140, matrix must be realigned\r\n for (let i = 0; i < 2; i++) {\r\n UniformBuffer._TempBuffer[i * 4] = matrix[i * 2];\r\n UniformBuffer._TempBuffer[i * 4 + 1] = matrix[i * 2 + 1];\r\n UniformBuffer._TempBuffer[i * 4 + 2] = 0.0;\r\n UniformBuffer._TempBuffer[i * 4 + 3] = 0.0;\r\n }\r\n\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 8);\r\n }\r\n\r\n private _updateFloatForEffect(name: string, x: number) {\r\n this._currentEffect.setFloat(name, x);\r\n }\r\n\r\n private _updateFloatForUniform(name: string, x: number) {\r\n UniformBuffer._TempBuffer[0] = x;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 1);\r\n }\r\n\r\n private _updateFloat2ForEffect(name: string, x: number, y: number, suffix = \"\") {\r\n this._currentEffect.setFloat2(name + suffix, x, y);\r\n }\r\n\r\n private _updateFloat2ForUniform(name: string, x: number, y: number) {\r\n UniformBuffer._TempBuffer[0] = x;\r\n UniformBuffer._TempBuffer[1] = y;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 2);\r\n }\r\n\r\n private _updateFloat3ForEffect(name: string, x: number, y: number, z: number, suffix = \"\") {\r\n this._currentEffect.setFloat3(name + suffix, x, y, z);\r\n }\r\n\r\n private _updateFloat3ForUniform(name: string, x: number, y: number, z: number) {\r\n UniformBuffer._TempBuffer[0] = x;\r\n UniformBuffer._TempBuffer[1] = y;\r\n UniformBuffer._TempBuffer[2] = z;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\r\n }\r\n\r\n private _updateFloat4ForEffect(name: string, x: number, y: number, z: number, w: number, suffix = \"\") {\r\n this._currentEffect.setFloat4(name + suffix, x, y, z, w);\r\n }\r\n\r\n private _updateFloat4ForUniform(name: string, x: number, y: number, z: number, w: number) {\r\n UniformBuffer._TempBuffer[0] = x;\r\n UniformBuffer._TempBuffer[1] = y;\r\n UniformBuffer._TempBuffer[2] = z;\r\n UniformBuffer._TempBuffer[3] = w;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\r\n }\r\n\r\n private _updateFloatArrayForEffect(name: string, array: Float32Array) {\r\n this._currentEffect.setFloatArray(name, array);\r\n }\r\n\r\n private _updateFloatArrayForUniform(name: string, array: Float32Array) {\r\n this.updateUniformArray(name, array, array.length);\r\n }\r\n\r\n private _updateArrayForEffect(name: string, array: number[]) {\r\n this._currentEffect.setArray(name, array);\r\n }\r\n\r\n private _updateArrayForUniform(name: string, array: number[]) {\r\n this.updateUniformArray(name, array, array.length);\r\n }\r\n\r\n private _updateIntArrayForEffect(name: string, array: Int32Array) {\r\n this._currentEffect.setIntArray(name, array);\r\n }\r\n\r\n private _updateIntArrayForUniform(name: string, array: Int32Array) {\r\n UniformBuffer._TempBufferInt32View.set(array);\r\n this.updateUniformArray(name, UniformBuffer._TempBuffer, array.length);\r\n }\r\n\r\n private _updateUIntArrayForEffect(name: string, array: Uint32Array) {\r\n this._currentEffect.setUIntArray(name, array);\r\n }\r\n\r\n private _updateUIntArrayForUniform(name: string, array: Uint32Array) {\r\n UniformBuffer._TempBufferUInt32View.set(array);\r\n this.updateUniformArray(name, UniformBuffer._TempBuffer, array.length);\r\n }\r\n\r\n private _updateMatrixForEffect(name: string, mat: IMatrixLike) {\r\n this._currentEffect.setMatrix(name, mat);\r\n }\r\n\r\n private _updateMatrixForUniform(name: string, mat: IMatrixLike) {\r\n if (this._cacheMatrix(name, mat)) {\r\n this.updateUniform(name, mat.toArray(), 16);\r\n }\r\n }\r\n\r\n private _updateMatricesForEffect(name: string, mat: Float32Array) {\r\n this._currentEffect.setMatrices(name, mat);\r\n }\r\n\r\n private _updateMatricesForUniform(name: string, mat: Float32Array) {\r\n this.updateUniform(name, mat, mat.length);\r\n }\r\n\r\n private _updateVector3ForEffect(name: string, vector: IVector3Like) {\r\n this._currentEffect.setVector3(name, vector);\r\n }\r\n\r\n private _updateVector3ForUniform(name: string, vector: IVector3Like) {\r\n UniformBuffer._TempBuffer[0] = vector.x;\r\n UniformBuffer._TempBuffer[1] = vector.y;\r\n UniformBuffer._TempBuffer[2] = vector.z;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\r\n }\r\n\r\n private _updateVector4ForEffect(name: string, vector: IVector4Like) {\r\n this._currentEffect.setVector4(name, vector);\r\n }\r\n\r\n private _updateVector4ForUniform(name: string, vector: IVector4Like) {\r\n UniformBuffer._TempBuffer[0] = vector.x;\r\n UniformBuffer._TempBuffer[1] = vector.y;\r\n UniformBuffer._TempBuffer[2] = vector.z;\r\n UniformBuffer._TempBuffer[3] = vector.w;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\r\n }\r\n\r\n private _updateColor3ForEffect(name: string, color: IColor3Like, suffix = \"\") {\r\n this._currentEffect.setColor3(name + suffix, color);\r\n }\r\n\r\n private _updateColor3ForUniform(name: string, color: IColor3Like) {\r\n UniformBuffer._TempBuffer[0] = color.r;\r\n UniformBuffer._TempBuffer[1] = color.g;\r\n UniformBuffer._TempBuffer[2] = color.b;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\r\n }\r\n\r\n private _updateColor4ForEffect(name: string, color: IColor3Like, alpha: number, suffix = \"\") {\r\n this._currentEffect.setColor4(name + suffix, color, alpha);\r\n }\r\n\r\n private _updateDirectColor4ForEffect(name: string, color: IColor4Like, suffix = \"\") {\r\n this._currentEffect.setDirectColor4(name + suffix, color);\r\n }\r\n\r\n private _updateColor4ForUniform(name: string, color: IColor3Like, alpha: number) {\r\n UniformBuffer._TempBuffer[0] = color.r;\r\n UniformBuffer._TempBuffer[1] = color.g;\r\n UniformBuffer._TempBuffer[2] = color.b;\r\n UniformBuffer._TempBuffer[3] = alpha;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\r\n }\r\n\r\n private _updateDirectColor4ForUniform(name: string, color: IColor4Like) {\r\n UniformBuffer._TempBuffer[0] = color.r;\r\n UniformBuffer._TempBuffer[1] = color.g;\r\n UniformBuffer._TempBuffer[2] = color.b;\r\n UniformBuffer._TempBuffer[3] = color.a;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\r\n }\r\n\r\n private _updateIntForEffect(name: string, x: number, suffix = \"\") {\r\n this._currentEffect.setInt(name + suffix, x);\r\n }\r\n\r\n private _updateIntForUniform(name: string, x: number) {\r\n UniformBuffer._TempBufferInt32View[0] = x;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 1);\r\n }\r\n\r\n private _updateInt2ForEffect(name: string, x: number, y: number, suffix = \"\") {\r\n this._currentEffect.setInt2(name + suffix, x, y);\r\n }\r\n\r\n private _updateInt2ForUniform(name: string, x: number, y: number) {\r\n UniformBuffer._TempBufferInt32View[0] = x;\r\n UniformBuffer._TempBufferInt32View[1] = y;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 2);\r\n }\r\n\r\n private _updateInt3ForEffect(name: string, x: number, y: number, z: number, suffix = \"\") {\r\n this._currentEffect.setInt3(name + suffix, x, y, z);\r\n }\r\n\r\n private _updateInt3ForUniform(name: string, x: number, y: number, z: number) {\r\n UniformBuffer._TempBufferInt32View[0] = x;\r\n UniformBuffer._TempBufferInt32View[1] = y;\r\n UniformBuffer._TempBufferInt32View[2] = z;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\r\n }\r\n\r\n private _updateInt4ForEffect(name: string, x: number, y: number, z: number, w: number, suffix = \"\") {\r\n this._currentEffect.setInt4(name + suffix, x, y, z, w);\r\n }\r\n\r\n private _updateInt4ForUniform(name: string, x: number, y: number, z: number, w: number) {\r\n UniformBuffer._TempBufferInt32View[0] = x;\r\n UniformBuffer._TempBufferInt32View[1] = y;\r\n UniformBuffer._TempBufferInt32View[2] = z;\r\n UniformBuffer._TempBufferInt32View[3] = w;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\r\n }\r\n\r\n private _updateUIntForEffect(name: string, x: number, suffix = \"\") {\r\n this._currentEffect.setUInt(name + suffix, x);\r\n }\r\n\r\n private _updateUIntForUniform(name: string, x: number) {\r\n UniformBuffer._TempBufferUInt32View[0] = x;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 1);\r\n }\r\n\r\n private _updateUInt2ForEffect(name: string, x: number, y: number, suffix = \"\") {\r\n this._currentEffect.setUInt2(name + suffix, x, y);\r\n }\r\n\r\n private _updateUInt2ForUniform(name: string, x: number, y: number) {\r\n UniformBuffer._TempBufferUInt32View[0] = x;\r\n UniformBuffer._TempBufferUInt32View[1] = y;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 2);\r\n }\r\n\r\n private _updateUInt3ForEffect(name: string, x: number, y: number, z: number, suffix = \"\") {\r\n this._currentEffect.setUInt3(name + suffix, x, y, z);\r\n }\r\n\r\n private _updateUInt3ForUniform(name: string, x: number, y: number, z: number) {\r\n UniformBuffer._TempBufferUInt32View[0] = x;\r\n UniformBuffer._TempBufferUInt32View[1] = y;\r\n UniformBuffer._TempBufferUInt32View[2] = z;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 3);\r\n }\r\n\r\n private _updateUInt4ForEffect(name: string, x: number, y: number, z: number, w: number, suffix = \"\") {\r\n this._currentEffect.setUInt4(name + suffix, x, y, z, w);\r\n }\r\n\r\n private _updateUInt4ForUniform(name: string, x: number, y: number, z: number, w: number) {\r\n UniformBuffer._TempBufferUInt32View[0] = x;\r\n UniformBuffer._TempBufferUInt32View[1] = y;\r\n UniformBuffer._TempBufferUInt32View[2] = z;\r\n UniformBuffer._TempBufferUInt32View[3] = w;\r\n this.updateUniform(name, UniformBuffer._TempBuffer, 4);\r\n }\r\n\r\n /**\r\n * Sets a sampler uniform on the effect.\r\n * @param name Define the name of the sampler.\r\n * @param texture Define the texture to set in the sampler\r\n */\r\n public setTexture(name: string, texture: Nullable) {\r\n this._currentEffect.setTexture(name, texture);\r\n }\r\n\r\n /**\r\n * Directly updates the value of the uniform in the cache AND on the GPU.\r\n * @param uniformName Define the name of the uniform, as used in the uniform block in the shader.\r\n * @param data Define the flattened data\r\n */\r\n public updateUniformDirectly(uniformName: string, data: FloatArray) {\r\n this.updateUniform(uniformName, data, data.length);\r\n\r\n this.update();\r\n }\r\n\r\n /**\r\n * Associates an effect to this uniform buffer\r\n * @param effect Define the effect to associate the buffer to\r\n * @param name Name of the uniform block in the shader.\r\n */\r\n public bindToEffect(effect: Effect, name: string): void {\r\n this._currentEffect = effect;\r\n this._currentEffectName = name;\r\n }\r\n\r\n /**\r\n * Binds the current (GPU) buffer to the effect\r\n */\r\n public bindUniformBuffer(): void {\r\n if (!this._noUBO && this._buffer && this._currentEffect) {\r\n this._currentEffect.bindUniformBuffer(this._buffer, this._currentEffectName);\r\n }\r\n }\r\n\r\n /**\r\n * Dissociates the current effect from this uniform buffer\r\n */\r\n public unbindEffect(): void {\r\n this._currentEffect = undefined as any;\r\n this._currentEffectName = undefined as any;\r\n }\r\n\r\n /**\r\n * Sets the current state of the class (_bufferIndex, _buffer) to point to the data buffer passed in parameter if this buffer is one of the buffers handled by the class (meaning if it can be found in the _buffers array)\r\n * This method is meant to be able to update a buffer at any time: just call setDataBuffer to set the class in the right state, call some updateXXX methods and then call udpate() => that will update the GPU buffer on the graphic card\r\n * @param dataBuffer buffer to look for\r\n * @returns true if the buffer has been found and the class internal state points to it, else false\r\n */\r\n public setDataBuffer(dataBuffer: DataBuffer): boolean {\r\n if (!this._buffers) {\r\n return this._buffer === dataBuffer;\r\n }\r\n\r\n for (let b = 0; b < this._buffers.length; ++b) {\r\n const buffer = this._buffers[b];\r\n if (buffer[0] === dataBuffer) {\r\n this._bufferIndex = b;\r\n this._buffer = dataBuffer;\r\n this._createBufferOnWrite = false;\r\n this._currentEffect = undefined as any;\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Disposes the uniform buffer.\r\n */\r\n public dispose(): void {\r\n if (this._noUBO) {\r\n return;\r\n }\r\n\r\n const uniformBuffers = this._engine._uniformBuffers;\r\n const index = uniformBuffers.indexOf(this);\r\n\r\n if (index !== -1) {\r\n uniformBuffers[index] = uniformBuffers[uniformBuffers.length - 1];\r\n uniformBuffers.pop();\r\n }\r\n\r\n if (this._engine._features.trackUbosInFrame && this._buffers) {\r\n for (let i = 0; i < this._buffers.length; ++i) {\r\n const buffer = this._buffers[i][0];\r\n this._engine._releaseBuffer(buffer!);\r\n }\r\n } else if (this._buffer && this._engine._releaseBuffer(this._buffer)) {\r\n this._buffer = null;\r\n }\r\n }\r\n}\r\n","import type { Nullable, DataArray, FloatArray } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { DataBuffer } from \"./dataBuffer\";\r\n\r\n/**\r\n * Class used to store data that will be store in GPU memory\r\n */\r\nexport class Buffer {\r\n private _engine: ThinEngine;\r\n private _buffer: Nullable;\r\n /** @internal */\r\n public _data: Nullable;\r\n private _updatable: boolean;\r\n private _instanced: boolean;\r\n private _divisor: number;\r\n private _isAlreadyOwned = false;\r\n\r\n /**\r\n * Gets the byte stride.\r\n */\r\n public readonly byteStride: number;\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this buffer\r\n * @param updatable whether the data is updatable\r\n * @param stride the stride (optional)\r\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\r\n * @param instanced whether the buffer is instanced (optional)\r\n * @param useBytes set to true if the stride in in bytes (optional)\r\n * @param divisor sets an optional divisor for instances (1 by default)\r\n */\r\n constructor(\r\n engine: any,\r\n data: DataArray | DataBuffer,\r\n updatable: boolean,\r\n stride = 0,\r\n postponeInternalCreation = false,\r\n instanced = false,\r\n useBytes = false,\r\n divisor?: number\r\n ) {\r\n if (engine.getScene) {\r\n // old versions of VertexBuffer accepted 'mesh' instead of 'engine'\r\n this._engine = engine.getScene().getEngine();\r\n } else {\r\n this._engine = engine;\r\n }\r\n\r\n this._updatable = updatable;\r\n this._instanced = instanced;\r\n this._divisor = divisor || 1;\r\n\r\n if (data instanceof DataBuffer) {\r\n this._data = null;\r\n this._buffer = data;\r\n } else {\r\n this._data = data;\r\n this._buffer = null;\r\n }\r\n\r\n this.byteStride = useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT;\r\n\r\n if (!postponeInternalCreation) {\r\n // by default\r\n this.create();\r\n }\r\n }\r\n\r\n /**\r\n * Create a new VertexBuffer based on the current buffer\r\n * @param kind defines the vertex buffer kind (position, normal, etc.)\r\n * @param offset defines offset in the buffer (0 by default)\r\n * @param size defines the size in floats of attributes (position is 3 for instance)\r\n * @param stride defines the stride size in floats in the buffer (the offset to apply to reach next value when data is interleaved)\r\n * @param instanced defines if the vertex buffer contains indexed data\r\n * @param useBytes defines if the offset and stride are in bytes *\r\n * @param divisor sets an optional divisor for instances (1 by default)\r\n * @returns the new vertex buffer\r\n */\r\n public createVertexBuffer(kind: string, offset: number, size: number, stride?: number, instanced?: boolean, useBytes = false, divisor?: number): VertexBuffer {\r\n const byteOffset = useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT;\r\n const byteStride = stride ? (useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT) : this.byteStride;\r\n\r\n // a lot of these parameters are ignored as they are overridden by the buffer\r\n return new VertexBuffer(\r\n this._engine,\r\n this,\r\n kind,\r\n this._updatable,\r\n true,\r\n byteStride,\r\n instanced === undefined ? this._instanced : instanced,\r\n byteOffset,\r\n size,\r\n undefined,\r\n undefined,\r\n true,\r\n this._divisor || divisor\r\n );\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is updatable?\r\n * @returns true if the buffer is updatable\r\n */\r\n public isUpdatable(): boolean {\r\n return this._updatable;\r\n }\r\n\r\n /**\r\n * Gets current buffer's data\r\n * @returns a DataArray or null\r\n */\r\n public getData(): Nullable {\r\n return this._data;\r\n }\r\n\r\n /**\r\n * Gets underlying native buffer\r\n * @returns underlying native buffer\r\n */\r\n public getBuffer(): Nullable {\r\n return this._buffer;\r\n }\r\n\r\n /**\r\n * Gets the stride in float32 units (i.e. byte stride / 4).\r\n * May not be an integer if the byte stride is not divisible by 4.\r\n * @returns the stride in float32 units\r\n * @deprecated Please use byteStride instead.\r\n */\r\n public getStrideSize(): number {\r\n return this.byteStride / Float32Array.BYTES_PER_ELEMENT;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Store data into the buffer. Creates the buffer if not used already.\r\n * If the buffer was already used, it will be updated only if it is updatable, otherwise it will do nothing.\r\n * @param data defines the data to store\r\n */\r\n public create(data: Nullable = null): void {\r\n if (!data && this._buffer) {\r\n return; // nothing to do\r\n }\r\n\r\n data = data || this._data;\r\n\r\n if (!data) {\r\n return;\r\n }\r\n\r\n if (!this._buffer) {\r\n // create buffer\r\n if (this._updatable) {\r\n this._buffer = this._engine.createDynamicVertexBuffer(data);\r\n this._data = data;\r\n } else {\r\n this._buffer = this._engine.createVertexBuffer(data);\r\n }\r\n } else if (this._updatable) {\r\n // update buffer\r\n this._engine.updateDynamicVertexBuffer(this._buffer, data);\r\n this._data = data;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n this._buffer = null;\r\n this.create(this._data);\r\n }\r\n\r\n /**\r\n * Update current buffer data\r\n * @param data defines the data to store\r\n */\r\n public update(data: DataArray): void {\r\n this.create(data);\r\n }\r\n\r\n /**\r\n * Updates the data directly.\r\n * @param data the new data\r\n * @param offset the new offset\r\n * @param vertexCount the vertex count (optional)\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateDirectly(data: DataArray, offset: number, vertexCount?: number, useBytes: boolean = false): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n if (this._updatable) {\r\n // update buffer\r\n this._engine.updateDynamicVertexBuffer(\r\n this._buffer,\r\n data,\r\n useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT,\r\n vertexCount ? vertexCount * this.byteStride : undefined\r\n );\r\n if (offset === 0 && vertexCount === undefined) {\r\n // Keep the data if we easily can\r\n this._data = data;\r\n } else {\r\n this._data = null;\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _increaseReferences() {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n if (!this._isAlreadyOwned) {\r\n this._isAlreadyOwned = true;\r\n return;\r\n }\r\n\r\n this._buffer.references++;\r\n }\r\n\r\n /**\r\n * Release all resources\r\n */\r\n public dispose(): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n if (this._engine._releaseBuffer(this._buffer)) {\r\n this._buffer = null;\r\n this._data = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Specialized buffer used to store vertex data\r\n */\r\nexport class VertexBuffer {\r\n private static _Counter = 0;\r\n\r\n /** @internal */\r\n public _buffer: Buffer;\r\n /** @internal */\r\n public _validOffsetRange: boolean; // used internally by the engine\r\n private _kind: string;\r\n private _size: number;\r\n private _ownsBuffer: boolean;\r\n private _instanced: boolean;\r\n private _instanceDivisor: number;\r\n\r\n /**\r\n * The byte type.\r\n */\r\n public static readonly BYTE = 5120;\r\n\r\n /**\r\n * The unsigned byte type.\r\n */\r\n public static readonly UNSIGNED_BYTE = 5121;\r\n\r\n /**\r\n * The short type.\r\n */\r\n public static readonly SHORT = 5122;\r\n\r\n /**\r\n * The unsigned short type.\r\n */\r\n public static readonly UNSIGNED_SHORT = 5123;\r\n\r\n /**\r\n * The integer type.\r\n */\r\n public static readonly INT = 5124;\r\n\r\n /**\r\n * The unsigned integer type.\r\n */\r\n public static readonly UNSIGNED_INT = 5125;\r\n\r\n /**\r\n * The float type.\r\n */\r\n public static readonly FLOAT = 5126;\r\n\r\n /**\r\n * Gets or sets the instance divisor when in instanced mode\r\n */\r\n public get instanceDivisor(): number {\r\n return this._instanceDivisor;\r\n }\r\n\r\n public set instanceDivisor(value: number) {\r\n const isInstanced = value != 0;\r\n this._instanceDivisor = value;\r\n\r\n if (isInstanced !== this._instanced) {\r\n this._instanced = isInstanced;\r\n this._computeHashCode();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the byte stride.\r\n */\r\n public readonly byteStride: number;\r\n\r\n /**\r\n * Gets the byte offset.\r\n */\r\n public readonly byteOffset: number;\r\n\r\n /**\r\n * Gets whether integer data values should be normalized into a certain range when being casted to a float.\r\n */\r\n public readonly normalized: boolean;\r\n\r\n /**\r\n * Gets the data type of each component in the array.\r\n */\r\n public readonly type: number;\r\n\r\n /**\r\n * Gets the unique id of this vertex buffer\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * Gets a hash code representing the format (type, normalized, size, instanced, stride) of this buffer\r\n * All buffers with the same format will have the same hash code\r\n */\r\n public readonly hashCode: number;\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this vertex buffer\r\n * @param kind the vertex buffer kind\r\n * @param updatable whether the data is updatable\r\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\r\n * @param stride the stride (optional)\r\n * @param instanced whether the buffer is instanced (optional)\r\n * @param offset the offset of the data (optional)\r\n * @param size the number of components (optional)\r\n * @param type the type of the component (optional)\r\n * @param normalized whether the data contains normalized data (optional)\r\n * @param useBytes set to true if stride and offset are in bytes (optional)\r\n * @param divisor defines the instance divisor to use (1 by default)\r\n * @param takeBufferOwnership defines if the buffer should be released when the vertex buffer is disposed\r\n */\r\n constructor(\r\n engine: any,\r\n data: DataArray | Buffer | DataBuffer,\r\n kind: string,\r\n updatable: boolean,\r\n postponeInternalCreation?: boolean,\r\n stride?: number,\r\n instanced?: boolean,\r\n offset?: number,\r\n size?: number,\r\n type?: number,\r\n normalized = false,\r\n useBytes = false,\r\n divisor = 1,\r\n takeBufferOwnership = false\r\n ) {\r\n if (data instanceof Buffer) {\r\n this._buffer = data;\r\n this._ownsBuffer = takeBufferOwnership;\r\n } else {\r\n this._buffer = new Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes);\r\n this._ownsBuffer = true;\r\n }\r\n\r\n this.uniqueId = VertexBuffer._Counter++;\r\n this._kind = kind;\r\n\r\n if (type == undefined) {\r\n const vertexData = this.getData();\r\n this.type = VertexBuffer.FLOAT;\r\n if (vertexData instanceof Int8Array) {\r\n this.type = VertexBuffer.BYTE;\r\n } else if (vertexData instanceof Uint8Array) {\r\n this.type = VertexBuffer.UNSIGNED_BYTE;\r\n } else if (vertexData instanceof Int16Array) {\r\n this.type = VertexBuffer.SHORT;\r\n } else if (vertexData instanceof Uint16Array) {\r\n this.type = VertexBuffer.UNSIGNED_SHORT;\r\n } else if (vertexData instanceof Int32Array) {\r\n this.type = VertexBuffer.INT;\r\n } else if (vertexData instanceof Uint32Array) {\r\n this.type = VertexBuffer.UNSIGNED_INT;\r\n }\r\n } else {\r\n this.type = type;\r\n }\r\n\r\n const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);\r\n\r\n if (useBytes) {\r\n this._size = size || (stride ? stride / typeByteLength : VertexBuffer.DeduceStride(kind));\r\n this.byteStride = stride || this._buffer.byteStride || this._size * typeByteLength;\r\n this.byteOffset = offset || 0;\r\n } else {\r\n this._size = size || stride || VertexBuffer.DeduceStride(kind);\r\n this.byteStride = stride ? stride * typeByteLength : this._buffer.byteStride || this._size * typeByteLength;\r\n this.byteOffset = (offset || 0) * typeByteLength;\r\n }\r\n\r\n this.normalized = normalized;\r\n\r\n this._instanced = instanced !== undefined ? instanced : false;\r\n this._instanceDivisor = instanced ? divisor : 0;\r\n\r\n this._computeHashCode();\r\n }\r\n\r\n private _computeHashCode(): void {\r\n // note: cast to any because the property is declared readonly\r\n (this.hashCode as any) =\r\n ((this.type - 5120) << 0) +\r\n ((this.normalized ? 1 : 0) << 3) +\r\n (this._size << 4) +\r\n ((this._instanced ? 1 : 0) << 6) +\r\n /* keep 5 bits free */\r\n (this.byteStride << 12);\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n this._buffer._rebuild();\r\n }\r\n\r\n /**\r\n * Returns the kind of the VertexBuffer (string)\r\n * @returns a string\r\n */\r\n public getKind(): string {\r\n return this._kind;\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets a boolean indicating if the VertexBuffer is updatable?\r\n * @returns true if the buffer is updatable\r\n */\r\n public isUpdatable(): boolean {\r\n return this._buffer.isUpdatable();\r\n }\r\n\r\n /**\r\n * Gets current buffer's data\r\n * @returns a DataArray or null\r\n */\r\n public getData(): Nullable {\r\n return this._buffer.getData();\r\n }\r\n\r\n /**\r\n * Gets current buffer's data as a float array. Float data is constructed if the vertex buffer data cannot be returned directly.\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n public getFloatData(totalVertices: number, forceCopy?: boolean): Nullable {\r\n const data = this.getData();\r\n if (!data) {\r\n return null;\r\n }\r\n\r\n const tightlyPackedByteStride = this.getSize() * VertexBuffer.GetTypeByteLength(this.type);\r\n const count = totalVertices * this.getSize();\r\n\r\n if (this.type !== VertexBuffer.FLOAT || this.byteStride !== tightlyPackedByteStride) {\r\n const copy = new Float32Array(count);\r\n this.forEach(count, (value, index) => (copy[index] = value));\r\n return copy;\r\n }\r\n\r\n if (!(data instanceof Array || data instanceof Float32Array) || this.byteOffset !== 0 || data.length !== count) {\r\n if (data instanceof Array) {\r\n const offset = this.byteOffset / 4;\r\n return data.slice(offset, offset + count);\r\n } else if (data instanceof ArrayBuffer) {\r\n return new Float32Array(data, this.byteOffset, count);\r\n } else {\r\n let offset = data.byteOffset + this.byteOffset;\r\n if (forceCopy) {\r\n const result = new Float32Array(count);\r\n const source = new Float32Array(data.buffer, offset, count);\r\n\r\n result.set(source);\r\n\r\n return result;\r\n }\r\n\r\n // Protect against bad data\r\n const remainder = offset % 4;\r\n\r\n if (remainder) {\r\n offset = Math.max(0, offset - remainder);\r\n }\r\n\r\n return new Float32Array(data.buffer, offset, count);\r\n }\r\n }\r\n\r\n if (forceCopy) {\r\n return data.slice();\r\n }\r\n\r\n return data;\r\n }\r\n\r\n /**\r\n * Gets underlying native buffer\r\n * @returns underlying native buffer\r\n */\r\n public getBuffer(): Nullable {\r\n return this._buffer.getBuffer();\r\n }\r\n\r\n /**\r\n * Gets the stride in float32 units (i.e. byte stride / 4).\r\n * May not be an integer if the byte stride is not divisible by 4.\r\n * @returns the stride in float32 units\r\n * @deprecated Please use byteStride instead.\r\n */\r\n public getStrideSize(): number {\r\n return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);\r\n }\r\n\r\n /**\r\n * Returns the offset as a multiple of the type byte length.\r\n * @returns the offset in bytes\r\n * @deprecated Please use byteOffset instead.\r\n */\r\n public getOffset(): number {\r\n return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);\r\n }\r\n\r\n /**\r\n * Returns the number of components or the byte size per vertex attribute\r\n * @param sizeInBytes If true, returns the size in bytes or else the size in number of components of the vertex attribute (default: false)\r\n * @returns the number of components\r\n */\r\n public getSize(sizeInBytes = false): number {\r\n return sizeInBytes ? this._size * VertexBuffer.GetTypeByteLength(this.type) : this._size;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating is the internal buffer of the VertexBuffer is instanced\r\n * @returns true if this buffer is instanced\r\n */\r\n public getIsInstanced(): boolean {\r\n return this._instanced;\r\n }\r\n\r\n /**\r\n * Returns the instancing divisor, zero for non-instanced (integer).\r\n * @returns a number\r\n */\r\n public getInstanceDivisor(): number {\r\n return this._instanceDivisor;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Store data into the buffer. If the buffer was already used it will be either recreated or updated depending on isUpdatable property\r\n * @param data defines the data to store\r\n */\r\n public create(data?: DataArray): void {\r\n this._buffer.create(data);\r\n }\r\n\r\n /**\r\n * Updates the underlying buffer according to the passed numeric array or Float32Array.\r\n * This function will create a new buffer if the current one is not updatable\r\n * @param data defines the data to store\r\n */\r\n public update(data: DataArray): void {\r\n this._buffer.update(data);\r\n }\r\n\r\n /**\r\n * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.\r\n * Returns the directly updated WebGLBuffer.\r\n * @param data the new data\r\n * @param offset the new offset\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateDirectly(data: DataArray, offset: number, useBytes: boolean = false): void {\r\n this._buffer.updateDirectly(data, offset, undefined, useBytes);\r\n }\r\n\r\n /**\r\n * Disposes the VertexBuffer and the underlying WebGLBuffer.\r\n */\r\n public dispose(): void {\r\n if (this._ownsBuffer) {\r\n this._buffer.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * Enumerates each value of this vertex buffer as numbers.\r\n * @param count the number of values to enumerate\r\n * @param callback the callback function called for each value\r\n */\r\n public forEach(count: number, callback: (value: number, index: number) => void): void {\r\n VertexBuffer.ForEach(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);\r\n }\r\n\r\n // Enums\r\n /**\r\n * Positions\r\n */\r\n public static readonly PositionKind = \"position\";\r\n /**\r\n * Normals\r\n */\r\n public static readonly NormalKind = \"normal\";\r\n /**\r\n * Tangents\r\n */\r\n public static readonly TangentKind = \"tangent\";\r\n /**\r\n * Texture coordinates\r\n */\r\n public static readonly UVKind = \"uv\";\r\n /**\r\n * Texture coordinates 2\r\n */\r\n public static readonly UV2Kind = \"uv2\";\r\n /**\r\n * Texture coordinates 3\r\n */\r\n public static readonly UV3Kind = \"uv3\";\r\n /**\r\n * Texture coordinates 4\r\n */\r\n public static readonly UV4Kind = \"uv4\";\r\n /**\r\n * Texture coordinates 5\r\n */\r\n public static readonly UV5Kind = \"uv5\";\r\n /**\r\n * Texture coordinates 6\r\n */\r\n public static readonly UV6Kind = \"uv6\";\r\n /**\r\n * Colors\r\n */\r\n public static readonly ColorKind = \"color\";\r\n /**\r\n * Instance Colors\r\n */\r\n public static readonly ColorInstanceKind = \"instanceColor\";\r\n /**\r\n * Matrix indices (for bones)\r\n */\r\n public static readonly MatricesIndicesKind = \"matricesIndices\";\r\n /**\r\n * Matrix weights (for bones)\r\n */\r\n public static readonly MatricesWeightsKind = \"matricesWeights\";\r\n /**\r\n * Additional matrix indices (for bones)\r\n */\r\n public static readonly MatricesIndicesExtraKind = \"matricesIndicesExtra\";\r\n /**\r\n * Additional matrix weights (for bones)\r\n */\r\n public static readonly MatricesWeightsExtraKind = \"matricesWeightsExtra\";\r\n\r\n /**\r\n * Deduces the stride given a kind.\r\n * @param kind The kind string to deduce\r\n * @returns The deduced stride\r\n */\r\n public static DeduceStride(kind: string): number {\r\n switch (kind) {\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind:\r\n case VertexBuffer.UV3Kind:\r\n case VertexBuffer.UV4Kind:\r\n case VertexBuffer.UV5Kind:\r\n case VertexBuffer.UV6Kind:\r\n return 2;\r\n case VertexBuffer.NormalKind:\r\n case VertexBuffer.PositionKind:\r\n return 3;\r\n case VertexBuffer.ColorKind:\r\n case VertexBuffer.MatricesIndicesKind:\r\n case VertexBuffer.MatricesIndicesExtraKind:\r\n case VertexBuffer.MatricesWeightsKind:\r\n case VertexBuffer.MatricesWeightsExtraKind:\r\n case VertexBuffer.TangentKind:\r\n return 4;\r\n default:\r\n throw new Error(\"Invalid kind '\" + kind + \"'\");\r\n }\r\n }\r\n\r\n /**\r\n * Gets the byte length of the given type.\r\n * @param type the type\r\n * @returns the number of bytes\r\n */\r\n public static GetTypeByteLength(type: number): number {\r\n switch (type) {\r\n case VertexBuffer.BYTE:\r\n case VertexBuffer.UNSIGNED_BYTE:\r\n return 1;\r\n case VertexBuffer.SHORT:\r\n case VertexBuffer.UNSIGNED_SHORT:\r\n return 2;\r\n case VertexBuffer.INT:\r\n case VertexBuffer.UNSIGNED_INT:\r\n case VertexBuffer.FLOAT:\r\n return 4;\r\n default:\r\n throw new Error(`Invalid type '${type}'`);\r\n }\r\n }\r\n\r\n /**\r\n * Enumerates each value of the given parameters as numbers.\r\n * @param data the data to enumerate\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param componentCount the number of components per element\r\n * @param componentType the type of the component\r\n * @param count the number of values to enumerate\r\n * @param normalized whether the data is normalized\r\n * @param callback the callback function called for each value\r\n */\r\n public static ForEach(\r\n data: DataArray,\r\n byteOffset: number,\r\n byteStride: number,\r\n componentCount: number,\r\n componentType: number,\r\n count: number,\r\n normalized: boolean,\r\n callback: (value: number, index: number) => void\r\n ): void {\r\n if (data instanceof Array) {\r\n let offset = byteOffset / 4;\r\n const stride = byteStride / 4;\r\n for (let index = 0; index < count; index += componentCount) {\r\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\r\n callback(data[offset + componentIndex], index + componentIndex);\r\n }\r\n offset += stride;\r\n }\r\n } else {\r\n const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);\r\n const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);\r\n for (let index = 0; index < count; index += componentCount) {\r\n let componentByteOffset = byteOffset;\r\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\r\n const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);\r\n callback(value, index + componentIndex);\r\n componentByteOffset += componentByteLength;\r\n }\r\n byteOffset += byteStride;\r\n }\r\n }\r\n }\r\n\r\n private static _GetFloatValue(dataView: DataView, type: number, byteOffset: number, normalized: boolean): number {\r\n switch (type) {\r\n case VertexBuffer.BYTE: {\r\n let value = dataView.getInt8(byteOffset);\r\n if (normalized) {\r\n value = Math.max(value / 127, -1);\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.UNSIGNED_BYTE: {\r\n let value = dataView.getUint8(byteOffset);\r\n if (normalized) {\r\n value = value / 255;\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.SHORT: {\r\n let value = dataView.getInt16(byteOffset, true);\r\n if (normalized) {\r\n value = Math.max(value / 32767, -1);\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.UNSIGNED_SHORT: {\r\n let value = dataView.getUint16(byteOffset, true);\r\n if (normalized) {\r\n value = value / 65535;\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.INT: {\r\n return dataView.getInt32(byteOffset, true);\r\n }\r\n case VertexBuffer.UNSIGNED_INT: {\r\n return dataView.getUint32(byteOffset, true);\r\n }\r\n case VertexBuffer.FLOAT: {\r\n return dataView.getFloat32(byteOffset, true);\r\n }\r\n default: {\r\n throw new Error(`Invalid component type ${type}`);\r\n }\r\n }\r\n }\r\n}\r\n","import type { Nullable, FloatArray } from \"../types\";\r\nimport { Vector3, Vector2, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { Sprite } from \"../Sprites/sprite\";\r\n\r\nimport type { Ray } from \"../Culling/ray\";\r\n\r\n/**\r\n * Information about the result of picking within a scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/picking_collisions\r\n */\r\nexport class PickingInfo {\r\n /**\r\n * If the pick collided with an object\r\n */\r\n public hit = false;\r\n /**\r\n * Distance away where the pick collided\r\n */\r\n public distance = 0;\r\n /**\r\n * The location of pick collision\r\n */\r\n public pickedPoint: Nullable = null;\r\n /**\r\n * The mesh corresponding the pick collision\r\n */\r\n public pickedMesh: Nullable = null;\r\n /** (See getTextureCoordinates) The barycentric U coordinate that is used when calculating the texture coordinates of the collision.*/\r\n public bu = 0;\r\n /** (See getTextureCoordinates) The barycentric V coordinate that is used when calculating the texture coordinates of the collision.*/\r\n public bv = 0;\r\n /** The index of the face on the mesh that was picked, or the index of the Line if the picked Mesh is a LinesMesh */\r\n public faceId = -1;\r\n /** The index of the face on the subMesh that was picked, or the index of the Line if the picked Mesh is a LinesMesh */\r\n public subMeshFaceId = -1;\r\n /** Id of the submesh that was picked */\r\n public subMeshId = 0;\r\n /** If a sprite was picked, this will be the sprite the pick collided with */\r\n public pickedSprite: Nullable = null;\r\n /** If we are picking a mesh with thin instance, this will give you the picked thin instance */\r\n public thinInstanceIndex = -1;\r\n /**\r\n * The ray that was used to perform the picking.\r\n */\r\n public ray: Nullable = null;\r\n /**\r\n * If a mesh was used to do the picking (eg. 6dof controller) as a \"near interaction\", this will be populated.\r\n */\r\n public originMesh: Nullable = null;\r\n /**\r\n * The aim-space transform of the input used for picking, if it is an XR input source.\r\n */\r\n public aimTransform: Nullable = null;\r\n /**\r\n * The grip-space transform of the input used for picking, if it is an XR input source.\r\n * Some XR sources, such as input coming from head mounted displays, do not have this.\r\n */\r\n public gripTransform: Nullable = null;\r\n\r\n /**\r\n * Gets the normal corresponding to the face the pick collided with\r\n * @param useWorldCoordinates If the resulting normal should be relative to the world (default: false)\r\n * @param useVerticesNormals If the vertices normals should be used to calculate the normal instead of the normal map (default: true)\r\n * @returns The normal corresponding to the face the pick collided with\r\n * @remarks Note that the returned normal will always point towards the picking ray.\r\n */\r\n public getNormal(useWorldCoordinates = false, useVerticesNormals = true): Nullable {\r\n if (!this.pickedMesh || (useVerticesNormals && !this.pickedMesh.isVerticesDataPresent(VertexBuffer.NormalKind))) {\r\n return null;\r\n }\r\n\r\n let indices = this.pickedMesh.getIndices();\r\n\r\n if (indices?.length === 0) {\r\n indices = null;\r\n }\r\n\r\n let result: Vector3;\r\n\r\n const tmp0 = TmpVectors.Vector3[0];\r\n const tmp1 = TmpVectors.Vector3[1];\r\n const tmp2 = TmpVectors.Vector3[2];\r\n\r\n if (useVerticesNormals) {\r\n const normals = this.pickedMesh.getVerticesData(VertexBuffer.NormalKind);\r\n\r\n let normal0 = indices\r\n ? Vector3.FromArrayToRef(normals, indices[this.faceId * 3] * 3, tmp0)\r\n : tmp0.copyFromFloats(normals[this.faceId * 3 * 3], normals[this.faceId * 3 * 3 + 1], normals[this.faceId * 3 * 3 + 2]);\r\n let normal1 = indices\r\n ? Vector3.FromArrayToRef(normals, indices[this.faceId * 3 + 1] * 3, tmp1)\r\n : tmp1.copyFromFloats(normals[(this.faceId * 3 + 1) * 3], normals[(this.faceId * 3 + 1) * 3 + 1], normals[(this.faceId * 3 + 1) * 3 + 2]);\r\n let normal2 = indices\r\n ? Vector3.FromArrayToRef(normals, indices[this.faceId * 3 + 2] * 3, tmp2)\r\n : tmp2.copyFromFloats(normals[(this.faceId * 3 + 2) * 3], normals[(this.faceId * 3 + 2) * 3 + 1], normals[(this.faceId * 3 + 2) * 3 + 2]);\r\n\r\n normal0 = normal0.scale(this.bu);\r\n normal1 = normal1.scale(this.bv);\r\n normal2 = normal2.scale(1.0 - this.bu - this.bv);\r\n\r\n result = new Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);\r\n } else {\r\n const positions = this.pickedMesh.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n const vertex1 = indices\r\n ? Vector3.FromArrayToRef(positions, indices[this.faceId * 3] * 3, tmp0)\r\n : tmp0.copyFromFloats(positions[this.faceId * 3 * 3], positions[this.faceId * 3 * 3 + 1], positions[this.faceId * 3 * 3 + 2]);\r\n const vertex2 = indices\r\n ? Vector3.FromArrayToRef(positions, indices[this.faceId * 3 + 1] * 3, tmp1)\r\n : tmp1.copyFromFloats(positions[(this.faceId * 3 + 1) * 3], positions[(this.faceId * 3 + 1) * 3 + 1], positions[(this.faceId * 3 + 1) * 3 + 2]);\r\n const vertex3 = indices\r\n ? Vector3.FromArrayToRef(positions, indices[this.faceId * 3 + 2] * 3, tmp2)\r\n : tmp2.copyFromFloats(positions[(this.faceId * 3 + 2) * 3], positions[(this.faceId * 3 + 2) * 3 + 1], positions[(this.faceId * 3 + 2) * 3 + 2]);\r\n\r\n const p1p2 = vertex1.subtract(vertex2);\r\n const p3p2 = vertex3.subtract(vertex2);\r\n\r\n result = Vector3.Cross(p1p2, p3p2);\r\n }\r\n\r\n const transformNormalToWorld = (pickedMesh: AbstractMesh, n: Vector3) => {\r\n let wm = pickedMesh.getWorldMatrix();\r\n\r\n if (pickedMesh.nonUniformScaling) {\r\n TmpVectors.Matrix[0].copyFrom(wm);\r\n wm = TmpVectors.Matrix[0];\r\n wm.setTranslationFromFloats(0, 0, 0);\r\n wm.invert();\r\n wm.transposeToRef(TmpVectors.Matrix[1]);\r\n\r\n wm = TmpVectors.Matrix[1];\r\n }\r\n\r\n Vector3.TransformNormalToRef(n, wm, n);\r\n };\r\n\r\n if (useWorldCoordinates) {\r\n transformNormalToWorld(this.pickedMesh, result);\r\n }\r\n\r\n if (this.ray) {\r\n const normalForDirectionChecking = TmpVectors.Vector3[0].copyFrom(result);\r\n\r\n if (!useWorldCoordinates) {\r\n // the normal has not been transformed to world space as part as the normal processing, so we must do it now\r\n transformNormalToWorld(this.pickedMesh, normalForDirectionChecking);\r\n }\r\n\r\n // Flip the normal if the picking ray is in the same direction.\r\n if (Vector3.Dot(normalForDirectionChecking, this.ray.direction) > 0) {\r\n result.negateInPlace();\r\n }\r\n }\r\n\r\n result.normalize();\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets the texture coordinates of where the pick occurred\r\n * @param uvSet The UV set to use to calculate the texture coordinates (default: VertexBuffer.UVKind)\r\n * @returns The vector containing the coordinates of the texture\r\n */\r\n public getTextureCoordinates(uvSet = VertexBuffer.UVKind): Nullable {\r\n if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(uvSet)) {\r\n return null;\r\n }\r\n\r\n const indices = this.pickedMesh.getIndices();\r\n if (!indices) {\r\n return null;\r\n }\r\n\r\n const uvs = this.pickedMesh.getVerticesData(uvSet);\r\n if (!uvs) {\r\n return null;\r\n }\r\n\r\n let uv0 = Vector2.FromArray(uvs, indices[this.faceId * 3] * 2);\r\n let uv1 = Vector2.FromArray(uvs, indices[this.faceId * 3 + 1] * 2);\r\n let uv2 = Vector2.FromArray(uvs, indices[this.faceId * 3 + 2] * 2);\r\n\r\n uv0 = uv0.scale(this.bu);\r\n uv1 = uv1.scale(this.bv);\r\n uv2 = uv2.scale(1.0 - this.bu - this.bv);\r\n\r\n return new Vector2(uv0.x + uv1.x + uv2.x, uv0.y + uv1.y + uv2.y);\r\n }\r\n}\r\n","import type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Sprite } from \"../Sprites/sprite\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Vector2 } from \"../Maths/math.vector\";\r\n\r\n/**\r\n * Interface used to define ActionEvent\r\n */\r\nexport interface IActionEvent {\r\n /** The mesh or sprite that triggered the action */\r\n source: any;\r\n /** The X mouse cursor position at the time of the event */\r\n pointerX: number;\r\n /** The Y mouse cursor position at the time of the event */\r\n pointerY: number;\r\n /** The mesh that is currently pointed at (can be null) */\r\n meshUnderPointer: Nullable;\r\n /** the original (browser) event that triggered the ActionEvent */\r\n sourceEvent?: any;\r\n /** additional data for the event */\r\n additionalData?: any;\r\n}\r\n\r\n/**\r\n * ActionEvent is the event being sent when an action is triggered.\r\n */\r\nexport class ActionEvent implements IActionEvent {\r\n /**\r\n * Creates a new ActionEvent\r\n * @param source The mesh or sprite that triggered the action\r\n * @param pointerX The X mouse cursor position at the time of the event\r\n * @param pointerY The Y mouse cursor position at the time of the event\r\n * @param meshUnderPointer The mesh that is currently pointed at (can be null)\r\n * @param sourceEvent the original (browser) event that triggered the ActionEvent\r\n * @param additionalData additional data for the event\r\n */\r\n constructor(\r\n /** The mesh or sprite that triggered the action */\r\n public source: any,\r\n /** The X mouse cursor position at the time of the event */\r\n public pointerX: number,\r\n /** The Y mouse cursor position at the time of the event */\r\n public pointerY: number,\r\n /** The mesh that is currently pointed at (can be null) */\r\n public meshUnderPointer: Nullable,\r\n /** the original (browser) event that triggered the ActionEvent */\r\n public sourceEvent?: any,\r\n /** additional data for the event */\r\n public additionalData?: any\r\n ) {}\r\n\r\n /**\r\n * Helper function to auto-create an ActionEvent from a source mesh.\r\n * @param source The source mesh that triggered the event\r\n * @param evt The original (browser) event\r\n * @param additionalData additional data for the event\r\n * @returns the new ActionEvent\r\n */\r\n public static CreateNew(source: AbstractMesh, evt?: any, additionalData?: any): ActionEvent {\r\n const scene = source.getScene();\r\n return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer || source, evt, additionalData);\r\n }\r\n\r\n /**\r\n * Helper function to auto-create an ActionEvent from a source sprite\r\n * @param source The source sprite that triggered the event\r\n * @param scene Scene associated with the sprite\r\n * @param evt The original (browser) event\r\n * @param additionalData additional data for the event\r\n * @returns the new ActionEvent\r\n */\r\n public static CreateNewFromSprite(source: Sprite, scene: Scene, evt?: any, additionalData?: any): ActionEvent {\r\n return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt, additionalData);\r\n }\r\n\r\n /**\r\n * Helper function to auto-create an ActionEvent from a scene. If triggered by a mesh use ActionEvent.CreateNew\r\n * @param scene the scene where the event occurred\r\n * @param evt The original (browser) event\r\n * @returns the new ActionEvent\r\n */\r\n public static CreateNewFromScene(scene: Scene, evt: any): ActionEvent {\r\n return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);\r\n }\r\n\r\n /**\r\n * Helper function to auto-create an ActionEvent from a primitive\r\n * @param prim defines the target primitive\r\n * @param pointerPos defines the pointer position\r\n * @param evt The original (browser) event\r\n * @param additionalData additional data for the event\r\n * @returns the new ActionEvent\r\n */\r\n public static CreateNewFromPrimitive(prim: any, pointerPos: Vector2, evt?: Event, additionalData?: any): ActionEvent {\r\n return new ActionEvent(prim, pointerPos.x, pointerPos.y, null, evt, additionalData);\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { PostProcess } from \"./postProcess\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport type { RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\n\r\nimport type { Scene } from \"../scene\";\r\n\r\n/**\r\n * PostProcessManager is used to manage one or more post processes or post process pipelines\r\n * See https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses\r\n */\r\nexport class PostProcessManager {\r\n private _scene: Scene;\r\n private _indexBuffer: Nullable;\r\n private _vertexBuffers: { [key: string]: Nullable } = {};\r\n\r\n /**\r\n * Creates a new instance PostProcess\r\n * @param scene The scene that the post process is associated with.\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n }\r\n\r\n private _prepareBuffers(): void {\r\n if (this._vertexBuffers[VertexBuffer.PositionKind]) {\r\n return;\r\n }\r\n\r\n // VBO\r\n const vertices = [];\r\n vertices.push(1, 1);\r\n vertices.push(-1, 1);\r\n vertices.push(-1, -1);\r\n vertices.push(1, -1);\r\n\r\n this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(this._scene.getEngine(), vertices, VertexBuffer.PositionKind, false, false, 2);\r\n\r\n this._buildIndexBuffer();\r\n }\r\n\r\n private _buildIndexBuffer(): void {\r\n // Indices\r\n const indices = [];\r\n indices.push(0);\r\n indices.push(1);\r\n indices.push(2);\r\n\r\n indices.push(0);\r\n indices.push(2);\r\n indices.push(3);\r\n\r\n this._indexBuffer = this._scene.getEngine().createIndexBuffer(indices);\r\n }\r\n\r\n /**\r\n * Rebuilds the vertex buffers of the manager.\r\n * @internal\r\n */\r\n public _rebuild(): void {\r\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\r\n\r\n if (!vb) {\r\n return;\r\n }\r\n vb._rebuild();\r\n this._buildIndexBuffer();\r\n }\r\n\r\n // Methods\r\n /**\r\n * Prepares a frame to be run through a post process.\r\n * @param sourceTexture The input texture to the post processes. (default: null)\r\n * @param postProcesses An array of post processes to be run. (default: null)\r\n * @returns True if the post processes were able to be run.\r\n * @internal\r\n */\r\n public _prepareFrame(sourceTexture: Nullable = null, postProcesses: Nullable = null): boolean {\r\n const camera = this._scene.activeCamera;\r\n if (!camera) {\r\n return false;\r\n }\r\n\r\n postProcesses = postProcesses || >camera._postProcesses.filter((pp) => {\r\n return pp != null;\r\n });\r\n\r\n if (!postProcesses || postProcesses.length === 0 || !this._scene.postProcessesEnabled) {\r\n return false;\r\n }\r\n\r\n postProcesses[0].activate(camera, sourceTexture, postProcesses !== null && postProcesses !== undefined);\r\n return true;\r\n }\r\n\r\n /**\r\n * Manually render a set of post processes to a texture.\r\n * Please note, the frame buffer won't be unbound after the call in case you have more render to do.\r\n * @param postProcesses An array of post processes to be run.\r\n * @param targetTexture The render target wrapper to render to.\r\n * @param forceFullscreenViewport force gl.viewport to be full screen eg. 0,0,textureWidth,textureHeight\r\n * @param faceIndex defines the face to render to if a cubemap is defined as the target\r\n * @param lodLevel defines which lod of the texture to render to\r\n * @param doNotBindFrambuffer If set to true, assumes that the framebuffer has been bound previously\r\n */\r\n public directRender(\r\n postProcesses: PostProcess[],\r\n targetTexture: Nullable = null,\r\n forceFullscreenViewport = false,\r\n faceIndex = 0,\r\n lodLevel = 0,\r\n doNotBindFrambuffer = false\r\n ): void {\r\n const engine = this._scene.getEngine();\r\n\r\n for (let index = 0; index < postProcesses.length; index++) {\r\n if (index < postProcesses.length - 1) {\r\n postProcesses[index + 1].activate(this._scene.activeCamera, targetTexture?.texture);\r\n } else {\r\n if (targetTexture) {\r\n engine.bindFramebuffer(targetTexture, faceIndex, undefined, undefined, forceFullscreenViewport, lodLevel);\r\n } else if (!doNotBindFrambuffer) {\r\n engine.restoreDefaultFramebuffer();\r\n }\r\n engine._debugInsertMarker?.(`post process ${postProcesses[index].name} output`);\r\n }\r\n\r\n const pp = postProcesses[index];\r\n const effect = pp.apply();\r\n\r\n if (effect) {\r\n pp.onBeforeRenderObservable.notifyObservers(effect);\r\n\r\n // VBOs\r\n this._prepareBuffers();\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n\r\n // Draw order\r\n engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n\r\n pp.onAfterRenderObservable.notifyObservers(effect);\r\n }\r\n }\r\n\r\n // Restore depth buffer\r\n engine.setDepthBuffer(true);\r\n engine.setDepthWrite(true);\r\n }\r\n\r\n /**\r\n * Finalize the result of the output of the postprocesses.\r\n * @param doNotPresent If true the result will not be displayed to the screen.\r\n * @param targetTexture The render target wrapper to render to.\r\n * @param faceIndex The index of the face to bind the target texture to.\r\n * @param postProcesses The array of post processes to render.\r\n * @param forceFullscreenViewport force gl.viewport to be full screen eg. 0,0,textureWidth,textureHeight (default: false)\r\n * @internal\r\n */\r\n public _finalizeFrame(\r\n doNotPresent?: boolean,\r\n targetTexture?: RenderTargetWrapper,\r\n faceIndex?: number,\r\n postProcesses?: Array,\r\n forceFullscreenViewport = false\r\n ): void {\r\n const camera = this._scene.activeCamera;\r\n\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n postProcesses = postProcesses || >camera._postProcesses.filter((pp) => {\r\n return pp != null;\r\n });\r\n if (postProcesses.length === 0 || !this._scene.postProcessesEnabled) {\r\n return;\r\n }\r\n const engine = this._scene.getEngine();\r\n\r\n for (let index = 0, len = postProcesses.length; index < len; index++) {\r\n const pp = postProcesses[index];\r\n\r\n if (index < len - 1) {\r\n pp._outputTexture = postProcesses[index + 1].activate(camera, targetTexture?.texture);\r\n } else {\r\n if (targetTexture) {\r\n engine.bindFramebuffer(targetTexture, faceIndex, undefined, undefined, forceFullscreenViewport);\r\n pp._outputTexture = targetTexture;\r\n } else {\r\n engine.restoreDefaultFramebuffer();\r\n pp._outputTexture = null;\r\n }\r\n engine._debugInsertMarker?.(`post process ${postProcesses[index].name} output`);\r\n }\r\n\r\n if (doNotPresent) {\r\n break;\r\n }\r\n\r\n const effect = pp.apply();\r\n\r\n if (effect) {\r\n pp.onBeforeRenderObservable.notifyObservers(effect);\r\n\r\n // VBOs\r\n this._prepareBuffers();\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n\r\n // Draw order\r\n engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n\r\n pp.onAfterRenderObservable.notifyObservers(effect);\r\n }\r\n }\r\n\r\n // Restore states\r\n engine.setDepthBuffer(true);\r\n engine.setDepthWrite(true);\r\n engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n }\r\n\r\n /**\r\n * Disposes of the post process manager.\r\n */\r\n public dispose(): void {\r\n const buffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (buffer) {\r\n buffer.dispose();\r\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this._scene.getEngine()._releaseBuffer(this._indexBuffer);\r\n this._indexBuffer = null;\r\n }\r\n }\r\n}\r\n","import { SmartArray, SmartArrayNoDuplicate } from \"../Misc/smartArray\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Nullable, DeepImmutable } from \"../types\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { IParticleSystem } from \"../Particles/IParticleSystem\";\r\nimport type { IEdgesRenderer } from \"./edgesRenderer\";\r\nimport type { ISpriteManager } from \"../Sprites/spriteManager\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\n\r\n/**\r\n * This represents the object necessary to create a rendering group.\r\n * This is exclusively used and created by the rendering manager.\r\n * To modify the behavior, you use the available helpers in your scene or meshes.\r\n * @internal\r\n */\r\nexport class RenderingGroup {\r\n private static _ZeroVector: DeepImmutable = Vector3.Zero();\r\n private _scene: Scene;\r\n private _opaqueSubMeshes = new SmartArray(256);\r\n private _transparentSubMeshes = new SmartArray(256);\r\n private _alphaTestSubMeshes = new SmartArray(256);\r\n private _depthOnlySubMeshes = new SmartArray(256);\r\n private _particleSystems = new SmartArray(256);\r\n private _spriteManagers = new SmartArray(256);\r\n\r\n private _opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>;\r\n private _alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>;\r\n private _transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number;\r\n\r\n private _renderOpaque: (subMeshes: SmartArray) => void;\r\n private _renderAlphaTest: (subMeshes: SmartArray) => void;\r\n private _renderTransparent: (subMeshes: SmartArray) => void;\r\n\r\n /** @internal */\r\n public _empty = true;\r\n\r\n /** @internal */\r\n public _edgesRenderers = new SmartArrayNoDuplicate(16);\r\n\r\n public onBeforeTransparentRendering: () => void;\r\n\r\n /**\r\n * Set the opaque sort comparison function.\r\n * If null the sub meshes will be render in the order they were created\r\n */\r\n public set opaqueSortCompareFn(value: Nullable<(a: SubMesh, b: SubMesh) => number>) {\r\n if (value) {\r\n this._opaqueSortCompareFn = value;\r\n } else {\r\n this._opaqueSortCompareFn = RenderingGroup.PainterSortCompare;\r\n }\r\n this._renderOpaque = this._renderOpaqueSorted;\r\n }\r\n\r\n /**\r\n * Set the alpha test sort comparison function.\r\n * If null the sub meshes will be render in the order they were created\r\n */\r\n public set alphaTestSortCompareFn(value: Nullable<(a: SubMesh, b: SubMesh) => number>) {\r\n if (value) {\r\n this._alphaTestSortCompareFn = value;\r\n } else {\r\n this._alphaTestSortCompareFn = RenderingGroup.PainterSortCompare;\r\n }\r\n this._renderAlphaTest = this._renderAlphaTestSorted;\r\n }\r\n\r\n /**\r\n * Set the transparent sort comparison function.\r\n * If null the sub meshes will be render in the order they were created\r\n */\r\n public set transparentSortCompareFn(value: Nullable<(a: SubMesh, b: SubMesh) => number>) {\r\n if (value) {\r\n this._transparentSortCompareFn = value;\r\n } else {\r\n this._transparentSortCompareFn = RenderingGroup.defaultTransparentSortCompare;\r\n }\r\n this._renderTransparent = this._renderTransparentSorted;\r\n }\r\n\r\n /**\r\n * Creates a new rendering group.\r\n * @param index The rendering group index\r\n * @param scene\r\n * @param opaqueSortCompareFn The opaque sort comparison function. If null no order is applied\r\n * @param alphaTestSortCompareFn The alpha test sort comparison function. If null no order is applied\r\n * @param transparentSortCompareFn The transparent sort comparison function. If null back to front + alpha index sort is applied\r\n */\r\n constructor(\r\n public index: number,\r\n scene: Scene,\r\n opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n transparentSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null\r\n ) {\r\n this._scene = scene;\r\n\r\n this.opaqueSortCompareFn = opaqueSortCompareFn;\r\n this.alphaTestSortCompareFn = alphaTestSortCompareFn;\r\n this.transparentSortCompareFn = transparentSortCompareFn;\r\n }\r\n\r\n /**\r\n * Render all the sub meshes contained in the group.\r\n * @param customRenderFunction Used to override the default render behaviour of the group.\r\n * @param renderSprites\r\n * @param renderParticles\r\n * @param activeMeshes\r\n * @returns true if rendered some submeshes.\r\n */\r\n public render(\r\n customRenderFunction: Nullable<\r\n (\r\n opaqueSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray\r\n ) => void\r\n >,\r\n renderSprites: boolean,\r\n renderParticles: boolean,\r\n activeMeshes: Nullable\r\n ): void {\r\n if (customRenderFunction) {\r\n customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes, this._depthOnlySubMeshes);\r\n return;\r\n }\r\n\r\n const engine = this._scene.getEngine();\r\n\r\n // Depth only\r\n if (this._depthOnlySubMeshes.length !== 0) {\r\n engine.setColorWrite(false);\r\n this._renderAlphaTest(this._depthOnlySubMeshes);\r\n engine.setColorWrite(true);\r\n }\r\n\r\n // Opaque\r\n if (this._opaqueSubMeshes.length !== 0) {\r\n this._renderOpaque(this._opaqueSubMeshes);\r\n }\r\n\r\n // Alpha test\r\n if (this._alphaTestSubMeshes.length !== 0) {\r\n this._renderAlphaTest(this._alphaTestSubMeshes);\r\n }\r\n\r\n const stencilState = engine.getStencilBuffer();\r\n engine.setStencilBuffer(false);\r\n\r\n // Sprites\r\n if (renderSprites) {\r\n this._renderSprites();\r\n }\r\n\r\n // Particles\r\n if (renderParticles) {\r\n this._renderParticles(activeMeshes);\r\n }\r\n\r\n if (this.onBeforeTransparentRendering) {\r\n this.onBeforeTransparentRendering();\r\n }\r\n\r\n // Transparent\r\n if (this._transparentSubMeshes.length !== 0 || this._scene.useOrderIndependentTransparency) {\r\n engine.setStencilBuffer(stencilState);\r\n if (this._scene.useOrderIndependentTransparency) {\r\n const excludedMeshes = this._scene.depthPeelingRenderer!.render(this._transparentSubMeshes);\r\n if (excludedMeshes.length) {\r\n // Render leftover meshes that could not be processed by depth peeling\r\n this._renderTransparent(excludedMeshes);\r\n }\r\n } else {\r\n this._renderTransparent(this._transparentSubMeshes);\r\n }\r\n engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n }\r\n\r\n // Set back stencil to false in case it changes before the edge renderer.\r\n engine.setStencilBuffer(false);\r\n\r\n // Edges\r\n if (this._edgesRenderers.length) {\r\n for (let edgesRendererIndex = 0; edgesRendererIndex < this._edgesRenderers.length; edgesRendererIndex++) {\r\n this._edgesRenderers.data[edgesRendererIndex].render();\r\n }\r\n\r\n engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n }\r\n\r\n // Restore Stencil state.\r\n engine.setStencilBuffer(stencilState);\r\n }\r\n\r\n /**\r\n * Renders the opaque submeshes in the order from the opaqueSortCompareFn.\r\n * @param subMeshes The submeshes to render\r\n */\r\n private _renderOpaqueSorted(subMeshes: SmartArray): void {\r\n return RenderingGroup._RenderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false);\r\n }\r\n\r\n /**\r\n * Renders the opaque submeshes in the order from the alphatestSortCompareFn.\r\n * @param subMeshes The submeshes to render\r\n */\r\n private _renderAlphaTestSorted(subMeshes: SmartArray): void {\r\n return RenderingGroup._RenderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false);\r\n }\r\n\r\n /**\r\n * Renders the opaque submeshes in the order from the transparentSortCompareFn.\r\n * @param subMeshes The submeshes to render\r\n */\r\n private _renderTransparentSorted(subMeshes: SmartArray): void {\r\n return RenderingGroup._RenderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true);\r\n }\r\n\r\n /**\r\n * Renders the submeshes in a specified order.\r\n * @param subMeshes The submeshes to sort before render\r\n * @param sortCompareFn The comparison function use to sort\r\n * @param camera The camera position use to preprocess the submeshes to help sorting\r\n * @param transparent Specifies to activate blending if true\r\n */\r\n private static _RenderSorted(\r\n subMeshes: SmartArray,\r\n sortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>,\r\n camera: Nullable,\r\n transparent: boolean\r\n ): void {\r\n let subIndex = 0;\r\n let subMesh: SubMesh;\r\n const cameraPosition = camera ? camera.globalPosition : RenderingGroup._ZeroVector;\r\n\r\n if (transparent) {\r\n for (; subIndex < subMeshes.length; subIndex++) {\r\n subMesh = subMeshes.data[subIndex];\r\n subMesh._alphaIndex = subMesh.getMesh().alphaIndex;\r\n subMesh._distanceToCamera = Vector3.Distance(subMesh.getBoundingInfo().boundingSphere.centerWorld, cameraPosition);\r\n }\r\n }\r\n\r\n const sortedArray = subMeshes.length === subMeshes.data.length ? subMeshes.data : subMeshes.data.slice(0, subMeshes.length);\r\n\r\n if (sortCompareFn) {\r\n sortedArray.sort(sortCompareFn);\r\n }\r\n\r\n const scene = sortedArray[0].getMesh().getScene();\r\n for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {\r\n subMesh = sortedArray[subIndex];\r\n\r\n if (scene._activeMeshesFrozenButKeepClipping && !subMesh.isInFrustum(scene._frustumPlanes)) {\r\n continue;\r\n }\r\n\r\n if (transparent) {\r\n const material = subMesh.getMaterial();\r\n\r\n if (material && material.needDepthPrePass) {\r\n const engine = material.getScene().getEngine();\r\n engine.setColorWrite(false);\r\n engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n subMesh.render(false);\r\n engine.setColorWrite(true);\r\n }\r\n }\r\n\r\n subMesh.render(transparent);\r\n }\r\n }\r\n\r\n /**\r\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\r\n * are rendered back to front if in the same alpha index.\r\n *\r\n * @param a The first submesh\r\n * @param b The second submesh\r\n * @returns The result of the comparison\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static defaultTransparentSortCompare(a: SubMesh, b: SubMesh): number {\r\n // Alpha index first\r\n if (a._alphaIndex > b._alphaIndex) {\r\n return 1;\r\n }\r\n if (a._alphaIndex < b._alphaIndex) {\r\n return -1;\r\n }\r\n\r\n // Then distance to camera\r\n return RenderingGroup.backToFrontSortCompare(a, b);\r\n }\r\n\r\n /**\r\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\r\n * are rendered back to front.\r\n *\r\n * @param a The first submesh\r\n * @param b The second submesh\r\n * @returns The result of the comparison\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static backToFrontSortCompare(a: SubMesh, b: SubMesh): number {\r\n // Then distance to camera\r\n if (a._distanceToCamera < b._distanceToCamera) {\r\n return 1;\r\n }\r\n if (a._distanceToCamera > b._distanceToCamera) {\r\n return -1;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n /**\r\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\r\n * are rendered front to back (prevent overdraw).\r\n *\r\n * @param a The first submesh\r\n * @param b The second submesh\r\n * @returns The result of the comparison\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static frontToBackSortCompare(a: SubMesh, b: SubMesh): number {\r\n // Then distance to camera\r\n if (a._distanceToCamera < b._distanceToCamera) {\r\n return -1;\r\n }\r\n if (a._distanceToCamera > b._distanceToCamera) {\r\n return 1;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n /**\r\n * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)\r\n * are grouped by material then geometry.\r\n *\r\n * @param a The first submesh\r\n * @param b The second submesh\r\n * @returns The result of the comparison\r\n */\r\n public static PainterSortCompare(a: SubMesh, b: SubMesh): number {\r\n const meshA = a.getMesh();\r\n const meshB = b.getMesh();\r\n\r\n if (meshA.material && meshB.material) {\r\n return meshA.material.uniqueId - meshB.material.uniqueId;\r\n }\r\n\r\n return meshA.uniqueId - meshB.uniqueId;\r\n }\r\n\r\n /**\r\n * Resets the different lists of submeshes to prepare a new frame.\r\n */\r\n public prepare(): void {\r\n this._opaqueSubMeshes.reset();\r\n this._transparentSubMeshes.reset();\r\n this._alphaTestSubMeshes.reset();\r\n this._depthOnlySubMeshes.reset();\r\n this._particleSystems.reset();\r\n this.prepareSprites();\r\n this._edgesRenderers.reset();\r\n this._empty = true;\r\n }\r\n\r\n /**\r\n * Resets the different lists of sprites to prepare a new frame.\r\n */\r\n public prepareSprites(): void {\r\n this._spriteManagers.reset();\r\n }\r\n\r\n public dispose(): void {\r\n this._opaqueSubMeshes.dispose();\r\n this._transparentSubMeshes.dispose();\r\n this._alphaTestSubMeshes.dispose();\r\n this._depthOnlySubMeshes.dispose();\r\n this._particleSystems.dispose();\r\n this._spriteManagers.dispose();\r\n this._edgesRenderers.dispose();\r\n }\r\n\r\n /**\r\n * Inserts the submesh in its correct queue depending on its material.\r\n * @param subMesh The submesh to dispatch\r\n * @param [mesh] Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.\r\n * @param [material] Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.\r\n */\r\n public dispatch(subMesh: SubMesh, mesh?: AbstractMesh, material?: Nullable): void {\r\n // Get mesh and materials if not provided\r\n if (mesh === undefined) {\r\n mesh = subMesh.getMesh();\r\n }\r\n if (material === undefined) {\r\n material = subMesh.getMaterial();\r\n }\r\n\r\n if (material === null || material === undefined) {\r\n return;\r\n }\r\n\r\n if (material.needAlphaBlendingForMesh(mesh)) {\r\n // Transparent\r\n this._transparentSubMeshes.push(subMesh);\r\n } else if (material.needAlphaTesting()) {\r\n // Alpha test\r\n if (material.needDepthPrePass) {\r\n this._depthOnlySubMeshes.push(subMesh);\r\n }\r\n\r\n this._alphaTestSubMeshes.push(subMesh);\r\n } else {\r\n if (material.needDepthPrePass) {\r\n this._depthOnlySubMeshes.push(subMesh);\r\n }\r\n\r\n this._opaqueSubMeshes.push(subMesh); // Opaque\r\n }\r\n\r\n mesh._renderingGroup = this;\r\n\r\n if (mesh._edgesRenderer && mesh._edgesRenderer.isEnabled) {\r\n this._edgesRenderers.pushNoDuplicate(mesh._edgesRenderer);\r\n }\r\n\r\n this._empty = false;\r\n }\r\n\r\n public dispatchSprites(spriteManager: ISpriteManager) {\r\n this._spriteManagers.push(spriteManager);\r\n this._empty = false;\r\n }\r\n\r\n public dispatchParticles(particleSystem: IParticleSystem) {\r\n this._particleSystems.push(particleSystem);\r\n this._empty = false;\r\n }\r\n\r\n private _renderParticles(activeMeshes: Nullable): void {\r\n if (this._particleSystems.length === 0) {\r\n return;\r\n }\r\n\r\n // Particles\r\n const activeCamera = this._scene.activeCamera;\r\n this._scene.onBeforeParticlesRenderingObservable.notifyObservers(this._scene);\r\n for (let particleIndex = 0; particleIndex < this._particleSystems.length; particleIndex++) {\r\n const particleSystem = this._particleSystems.data[particleIndex];\r\n\r\n if ((activeCamera && activeCamera.layerMask & particleSystem.layerMask) === 0) {\r\n continue;\r\n }\r\n\r\n const emitter: any = particleSystem.emitter;\r\n if (!emitter.position || !activeMeshes || activeMeshes.indexOf(emitter) !== -1) {\r\n this._scene._activeParticles.addCount(particleSystem.render(), false);\r\n }\r\n }\r\n this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene);\r\n }\r\n\r\n private _renderSprites(): void {\r\n if (!this._scene.spritesEnabled || this._spriteManagers.length === 0) {\r\n return;\r\n }\r\n\r\n // Sprites\r\n const activeCamera = this._scene.activeCamera;\r\n this._scene.onBeforeSpritesRenderingObservable.notifyObservers(this._scene);\r\n for (let id = 0; id < this._spriteManagers.length; id++) {\r\n const spriteManager = this._spriteManagers.data[id];\r\n\r\n if ((activeCamera && activeCamera.layerMask & spriteManager.layerMask) !== 0) {\r\n spriteManager.render();\r\n }\r\n }\r\n this._scene.onAfterSpritesRenderingObservable.notifyObservers(this._scene);\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport type { ISpriteManager } from \"../Sprites/spriteManager\";\r\nimport type { IParticleSystem } from \"../Particles/IParticleSystem\";\r\nimport { RenderingGroup } from \"./renderingGroup\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n\r\n/**\r\n * Interface describing the different options available in the rendering manager\r\n * regarding Auto Clear between groups.\r\n */\r\nexport interface IRenderingManagerAutoClearSetup {\r\n /**\r\n * Defines whether or not autoclear is enable.\r\n */\r\n autoClear: boolean;\r\n /**\r\n * Defines whether or not to autoclear the depth buffer.\r\n */\r\n depth: boolean;\r\n /**\r\n * Defines whether or not to autoclear the stencil buffer.\r\n */\r\n stencil: boolean;\r\n}\r\n\r\n/**\r\n * This class is used by the onRenderingGroupObservable\r\n */\r\nexport class RenderingGroupInfo {\r\n /**\r\n * The Scene that being rendered\r\n */\r\n scene: Scene;\r\n\r\n /**\r\n * The camera currently used for the rendering pass\r\n */\r\n camera: Nullable;\r\n\r\n /**\r\n * The ID of the renderingGroup being processed\r\n */\r\n renderingGroupId: number;\r\n}\r\n\r\n/**\r\n * This is the manager responsible of all the rendering for meshes sprites and particles.\r\n * It is enable to manage the different groups as well as the different necessary sort functions.\r\n * This should not be used directly aside of the few static configurations\r\n */\r\nexport class RenderingManager {\r\n /**\r\n * The max id used for rendering groups (not included)\r\n */\r\n public static MAX_RENDERINGGROUPS = 4;\r\n\r\n /**\r\n * The min id used for rendering groups (included)\r\n */\r\n public static MIN_RENDERINGGROUPS = 0;\r\n\r\n /**\r\n * Used to globally prevent autoclearing scenes.\r\n */\r\n public static AUTOCLEAR = true;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _useSceneAutoClearSetup = false;\r\n\r\n private _scene: Scene;\r\n private _renderingGroups = new Array();\r\n private _depthStencilBufferAlreadyCleaned: boolean;\r\n\r\n private _autoClearDepthStencil: { [id: number]: IRenderingManagerAutoClearSetup } = {};\r\n private _customOpaqueSortCompareFn: { [id: number]: Nullable<(a: SubMesh, b: SubMesh) => number> } = {};\r\n private _customAlphaTestSortCompareFn: { [id: number]: Nullable<(a: SubMesh, b: SubMesh) => number> } = {};\r\n private _customTransparentSortCompareFn: { [id: number]: Nullable<(a: SubMesh, b: SubMesh) => number> } = {};\r\n private _renderingGroupInfo: Nullable = new RenderingGroupInfo();\r\n\r\n private _maintainStateBetweenFrames = false;\r\n /**\r\n * Gets or sets a boolean indicating that the manager will not reset between frames.\r\n * This means that if a mesh becomes invisible or transparent it will not be visible until this boolean is set to false again.\r\n * By default, the rendering manager will dispatch all active meshes per frame (moving them to the transparent, opaque or alpha testing lists).\r\n * By turning this property on, you will accelerate the rendering by keeping all these lists unchanged between frames.\r\n */\r\n public get maintainStateBetweenFrames() {\r\n return this._maintainStateBetweenFrames;\r\n }\r\n\r\n public set maintainStateBetweenFrames(value: boolean) {\r\n if (value === this._maintainStateBetweenFrames) {\r\n return;\r\n }\r\n\r\n this._maintainStateBetweenFrames = value;\r\n\r\n // Restore wasDispatched flags when switching to maintainStateBetweenFrames to false\r\n if (!this._maintainStateBetweenFrames) {\r\n for (const mesh of this._scene.meshes) {\r\n if (mesh.subMeshes) {\r\n for (const subMesh of mesh.subMeshes) {\r\n subMesh._wasDispatched = false;\r\n }\r\n }\r\n }\r\n\r\n if (this._scene.spriteManagers) {\r\n for (const spriteManager of this._scene.spriteManagers) {\r\n spriteManager._wasDispatched = false;\r\n }\r\n }\r\n\r\n for (const particleSystem of this._scene.particleSystems) {\r\n particleSystem._wasDispatched = false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Instantiates a new rendering group for a particular scene\r\n * @param scene Defines the scene the groups belongs to\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n\r\n for (let i = RenderingManager.MIN_RENDERINGGROUPS; i < RenderingManager.MAX_RENDERINGGROUPS; i++) {\r\n this._autoClearDepthStencil[i] = { autoClear: true, depth: true, stencil: true };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the rendering group with the specified id.\r\n */\r\n public getRenderingGroup(id: number): RenderingGroup {\r\n const renderingGroupId = id || 0;\r\n\r\n this._prepareRenderingGroup(renderingGroupId);\r\n\r\n return this._renderingGroups[renderingGroupId];\r\n }\r\n\r\n private _clearDepthStencilBuffer(depth = true, stencil = true): void {\r\n if (this._depthStencilBufferAlreadyCleaned) {\r\n return;\r\n }\r\n\r\n this._scene.getEngine().clear(null, false, depth, stencil);\r\n this._depthStencilBufferAlreadyCleaned = true;\r\n }\r\n\r\n /**\r\n * Renders the entire managed groups. This is used by the scene or the different render targets.\r\n * @internal\r\n */\r\n public render(\r\n customRenderFunction: Nullable<\r\n (\r\n opaqueSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray\r\n ) => void\r\n >,\r\n activeMeshes: Nullable,\r\n renderParticles: boolean,\r\n renderSprites: boolean\r\n ): void {\r\n // Update the observable context (not null as it only goes away on dispose)\r\n const info = this._renderingGroupInfo!;\r\n info.scene = this._scene;\r\n info.camera = this._scene.activeCamera;\r\n\r\n // Dispatch sprites\r\n if (this._scene.spriteManagers && renderSprites) {\r\n for (let index = 0; index < this._scene.spriteManagers.length; index++) {\r\n const manager = this._scene.spriteManagers[index];\r\n this.dispatchSprites(manager);\r\n }\r\n }\r\n\r\n // Render\r\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\r\n this._depthStencilBufferAlreadyCleaned = index === RenderingManager.MIN_RENDERINGGROUPS;\r\n const renderingGroup = this._renderingGroups[index];\r\n if (!renderingGroup || renderingGroup._empty) {\r\n continue;\r\n }\r\n\r\n const renderingGroupMask = Math.pow(2, index);\r\n info.renderingGroupId = index;\r\n\r\n // Before Observable\r\n this._scene.onBeforeRenderingGroupObservable.notifyObservers(info, renderingGroupMask);\r\n\r\n // Clear depth/stencil if needed\r\n if (RenderingManager.AUTOCLEAR) {\r\n const autoClear = this._useSceneAutoClearSetup ? this._scene.getAutoClearDepthStencilSetup(index) : this._autoClearDepthStencil[index];\r\n\r\n if (autoClear && autoClear.autoClear) {\r\n this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);\r\n }\r\n }\r\n\r\n // Render\r\n for (const step of this._scene._beforeRenderingGroupDrawStage) {\r\n step.action(index);\r\n }\r\n renderingGroup.render(customRenderFunction, renderSprites, renderParticles, activeMeshes);\r\n for (const step of this._scene._afterRenderingGroupDrawStage) {\r\n step.action(index);\r\n }\r\n\r\n // After Observable\r\n this._scene.onAfterRenderingGroupObservable.notifyObservers(info, renderingGroupMask);\r\n }\r\n }\r\n\r\n /**\r\n * Resets the different information of the group to prepare a new frame\r\n * @internal\r\n */\r\n public reset(): void {\r\n if (this.maintainStateBetweenFrames) {\r\n return;\r\n }\r\n\r\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\r\n const renderingGroup = this._renderingGroups[index];\r\n if (renderingGroup) {\r\n renderingGroup.prepare();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Resets the sprites information of the group to prepare a new frame\r\n * @internal\r\n */\r\n public resetSprites(): void {\r\n if (this.maintainStateBetweenFrames) {\r\n return;\r\n }\r\n\r\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\r\n const renderingGroup = this._renderingGroups[index];\r\n if (renderingGroup) {\r\n renderingGroup.prepareSprites();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Dispose and release the group and its associated resources.\r\n * @internal\r\n */\r\n public dispose(): void {\r\n this.freeRenderingGroups();\r\n this._renderingGroups.length = 0;\r\n this._renderingGroupInfo = null;\r\n }\r\n\r\n /**\r\n * Clear the info related to rendering groups preventing retention points during dispose.\r\n */\r\n public freeRenderingGroups(): void {\r\n for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {\r\n const renderingGroup = this._renderingGroups[index];\r\n if (renderingGroup) {\r\n renderingGroup.dispose();\r\n }\r\n }\r\n }\r\n\r\n private _prepareRenderingGroup(renderingGroupId: number): void {\r\n if (this._renderingGroups[renderingGroupId] === undefined) {\r\n this._renderingGroups[renderingGroupId] = new RenderingGroup(\r\n renderingGroupId,\r\n this._scene,\r\n this._customOpaqueSortCompareFn[renderingGroupId],\r\n this._customAlphaTestSortCompareFn[renderingGroupId],\r\n this._customTransparentSortCompareFn[renderingGroupId]\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Add a sprite manager to the rendering manager in order to render it this frame.\r\n * @param spriteManager Define the sprite manager to render\r\n */\r\n public dispatchSprites(spriteManager: ISpriteManager) {\r\n if (this.maintainStateBetweenFrames && spriteManager._wasDispatched) {\r\n return;\r\n }\r\n spriteManager._wasDispatched = true;\r\n this.getRenderingGroup(spriteManager.renderingGroupId).dispatchSprites(spriteManager);\r\n }\r\n\r\n /**\r\n * Add a particle system to the rendering manager in order to render it this frame.\r\n * @param particleSystem Define the particle system to render\r\n */\r\n public dispatchParticles(particleSystem: IParticleSystem) {\r\n if (this.maintainStateBetweenFrames && particleSystem._wasDispatched) {\r\n return;\r\n }\r\n particleSystem._wasDispatched = true;\r\n this.getRenderingGroup(particleSystem.renderingGroupId).dispatchParticles(particleSystem);\r\n }\r\n\r\n /**\r\n * Add a submesh to the manager in order to render it this frame\r\n * @param subMesh The submesh to dispatch\r\n * @param mesh Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.\r\n * @param material Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.\r\n */\r\n public dispatch(subMesh: SubMesh, mesh?: AbstractMesh, material?: Nullable): void {\r\n if (mesh === undefined) {\r\n mesh = subMesh.getMesh();\r\n }\r\n if (this.maintainStateBetweenFrames && subMesh._wasDispatched) {\r\n return;\r\n }\r\n subMesh._wasDispatched = true;\r\n this.getRenderingGroup(mesh.renderingGroupId).dispatch(subMesh, mesh, material);\r\n }\r\n\r\n /**\r\n * Overrides the default sort function applied in the rendering group to prepare the meshes.\r\n * This allowed control for front to back rendering or reversely depending of the special needs.\r\n *\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param opaqueSortCompareFn The opaque queue comparison function use to sort.\r\n * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.\r\n * @param transparentSortCompareFn The transparent queue comparison function use to sort.\r\n */\r\n public setRenderingOrder(\r\n renderingGroupId: number,\r\n opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n transparentSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null\r\n ) {\r\n this._customOpaqueSortCompareFn[renderingGroupId] = opaqueSortCompareFn;\r\n this._customAlphaTestSortCompareFn[renderingGroupId] = alphaTestSortCompareFn;\r\n this._customTransparentSortCompareFn[renderingGroupId] = transparentSortCompareFn;\r\n\r\n if (this._renderingGroups[renderingGroupId]) {\r\n const group = this._renderingGroups[renderingGroupId];\r\n group.opaqueSortCompareFn = this._customOpaqueSortCompareFn[renderingGroupId];\r\n group.alphaTestSortCompareFn = this._customAlphaTestSortCompareFn[renderingGroupId];\r\n group.transparentSortCompareFn = this._customTransparentSortCompareFn[renderingGroupId];\r\n }\r\n }\r\n\r\n /**\r\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.\r\n *\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\r\n * @param depth Automatically clears depth between groups if true and autoClear is true.\r\n * @param stencil Automatically clears stencil between groups if true and autoClear is true.\r\n */\r\n public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean, depth = true, stencil = true): void {\r\n this._autoClearDepthStencil[renderingGroupId] = {\r\n autoClear: autoClearDepthStencil,\r\n depth: depth,\r\n stencil: stencil,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current auto clear configuration for one rendering group of the rendering\r\n * manager.\r\n * @param index the rendering group index to get the information for\r\n * @returns The auto clear setup for the requested rendering group\r\n */\r\n public getAutoClearDepthStencilSetup(index: number): IRenderingManagerAutoClearSetup {\r\n return this._autoClearDepthStencil[index];\r\n }\r\n}\r\n","import type { Scene } from \"./scene\";\r\nimport type { SmartArrayNoDuplicate } from \"./Misc/smartArray\";\r\nimport type { Nullable } from \"./types\";\r\nimport type { PickingInfo } from \"./Collisions/pickingInfo\";\r\nimport type { AbstractScene } from \"./abstractScene\";\r\nimport type { IPointerEvent } from \"./Events/deviceInputEvents\";\r\n\r\nimport type { Mesh } from \"./Meshes/mesh\";\r\nimport type { Effect } from \"./Materials/effect\";\r\nimport type { Camera } from \"./Cameras/camera\";\r\nimport type { AbstractMesh } from \"./Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"./Meshes/subMesh\";\r\nimport type { RenderTargetTexture } from \"./Materials/Textures/renderTargetTexture\";\r\n\r\n/**\r\n * Groups all the scene component constants in one place to ease maintenance.\r\n * @internal\r\n */\r\nexport class SceneComponentConstants {\r\n public static readonly NAME_EFFECTLAYER = \"EffectLayer\";\r\n public static readonly NAME_LAYER = \"Layer\";\r\n public static readonly NAME_LENSFLARESYSTEM = \"LensFlareSystem\";\r\n public static readonly NAME_BOUNDINGBOXRENDERER = \"BoundingBoxRenderer\";\r\n public static readonly NAME_PARTICLESYSTEM = \"ParticleSystem\";\r\n public static readonly NAME_GAMEPAD = \"Gamepad\";\r\n public static readonly NAME_SIMPLIFICATIONQUEUE = \"SimplificationQueue\";\r\n public static readonly NAME_GEOMETRYBUFFERRENDERER = \"GeometryBufferRenderer\";\r\n public static readonly NAME_PREPASSRENDERER = \"PrePassRenderer\";\r\n public static readonly NAME_DEPTHRENDERER = \"DepthRenderer\";\r\n public static readonly NAME_DEPTHPEELINGRENDERER = \"DepthPeelingRenderer\";\r\n public static readonly NAME_POSTPROCESSRENDERPIPELINEMANAGER = \"PostProcessRenderPipelineManager\";\r\n public static readonly NAME_SPRITE = \"Sprite\";\r\n public static readonly NAME_SUBSURFACE = \"SubSurface\";\r\n public static readonly NAME_OUTLINERENDERER = \"Outline\";\r\n public static readonly NAME_PROCEDURALTEXTURE = \"ProceduralTexture\";\r\n public static readonly NAME_SHADOWGENERATOR = \"ShadowGenerator\";\r\n public static readonly NAME_OCTREE = \"Octree\";\r\n public static readonly NAME_PHYSICSENGINE = \"PhysicsEngine\";\r\n public static readonly NAME_AUDIO = \"Audio\";\r\n public static readonly NAME_FLUIDRENDERER = \"FluidRenderer\";\r\n\r\n public static readonly STEP_ISREADYFORMESH_EFFECTLAYER = 0;\r\n\r\n public static readonly STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER = 0;\r\n\r\n public static readonly STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER = 0;\r\n\r\n public static readonly STEP_PREACTIVEMESH_BOUNDINGBOXRENDERER = 0;\r\n\r\n public static readonly STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER = 1;\r\n\r\n public static readonly STEP_BEFORECAMERADRAW_PREPASS = 0;\r\n public static readonly STEP_BEFORECAMERADRAW_EFFECTLAYER = 1;\r\n public static readonly STEP_BEFORECAMERADRAW_LAYER = 2;\r\n\r\n public static readonly STEP_BEFORERENDERTARGETDRAW_PREPASS = 0;\r\n public static readonly STEP_BEFORERENDERTARGETDRAW_LAYER = 1;\r\n\r\n public static readonly STEP_BEFORERENDERINGMESH_PREPASS = 0;\r\n public static readonly STEP_BEFORERENDERINGMESH_OUTLINE = 1;\r\n\r\n public static readonly STEP_AFTERRENDERINGMESH_PREPASS = 0;\r\n public static readonly STEP_AFTERRENDERINGMESH_OUTLINE = 1;\r\n\r\n public static readonly STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW = 0;\r\n public static readonly STEP_AFTERRENDERINGGROUPDRAW_BOUNDINGBOXRENDERER = 1;\r\n\r\n public static readonly STEP_BEFORECAMERAUPDATE_SIMPLIFICATIONQUEUE = 0;\r\n public static readonly STEP_BEFORECAMERAUPDATE_GAMEPAD = 1;\r\n\r\n public static readonly STEP_BEFORECLEAR_PROCEDURALTEXTURE = 0;\r\n public static readonly STEP_BEFORECLEAR_PREPASS = 1;\r\n\r\n public static readonly STEP_BEFORERENDERTARGETCLEAR_PREPASS = 0;\r\n\r\n public static readonly STEP_AFTERRENDERTARGETDRAW_PREPASS = 0;\r\n public static readonly STEP_AFTERRENDERTARGETDRAW_LAYER = 1;\r\n\r\n public static readonly STEP_AFTERCAMERADRAW_PREPASS = 0;\r\n public static readonly STEP_AFTERCAMERADRAW_EFFECTLAYER = 1;\r\n public static readonly STEP_AFTERCAMERADRAW_LENSFLARESYSTEM = 2;\r\n public static readonly STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;\r\n public static readonly STEP_AFTERCAMERADRAW_LAYER = 4;\r\n public static readonly STEP_AFTERCAMERADRAW_FLUIDRENDERER = 5;\r\n\r\n public static readonly STEP_AFTERCAMERAPOSTPROCESS_LAYER = 0;\r\n\r\n public static readonly STEP_AFTERRENDERTARGETPOSTPROCESS_LAYER = 0;\r\n\r\n public static readonly STEP_AFTERRENDER_AUDIO = 0;\r\n\r\n public static readonly STEP_GATHERRENDERTARGETS_DEPTHRENDERER = 0;\r\n public static readonly STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER = 1;\r\n public static readonly STEP_GATHERRENDERTARGETS_SHADOWGENERATOR = 2;\r\n public static readonly STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER = 3;\r\n\r\n public static readonly STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER = 0;\r\n public static readonly STEP_GATHERACTIVECAMERARENDERTARGETS_FLUIDRENDERER = 1;\r\n\r\n public static readonly STEP_POINTERMOVE_SPRITE = 0;\r\n public static readonly STEP_POINTERDOWN_SPRITE = 0;\r\n public static readonly STEP_POINTERUP_SPRITE = 0;\r\n}\r\n\r\n/**\r\n * This represents a scene component.\r\n *\r\n * This is used to decouple the dependency the scene is having on the different workloads like\r\n * layers, post processes...\r\n */\r\nexport interface ISceneComponent {\r\n /**\r\n * The name of the component. Each component must have a unique name.\r\n */\r\n name: string;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n scene: Scene;\r\n\r\n /**\r\n * Register the component to one instance of a scene.\r\n */\r\n register(): void;\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n rebuild(): void;\r\n\r\n /**\r\n * Disposes the component and the associated ressources.\r\n */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * This represents a SERIALIZABLE scene component.\r\n *\r\n * This extends Scene Component to add Serialization methods on top.\r\n */\r\nexport interface ISceneSerializableComponent extends ISceneComponent {\r\n /**\r\n * Adds all the elements from the container to the scene\r\n * @param container the container holding the elements\r\n */\r\n addFromContainer(container: AbstractScene): void;\r\n\r\n /**\r\n * Removes all the elements in the container from the scene\r\n * @param container contains the elements to remove\r\n * @param dispose if the removed element should be disposed (default: false)\r\n */\r\n removeFromContainer(container: AbstractScene, dispose?: boolean): void;\r\n\r\n /**\r\n * Serializes the component data to the specified json object\r\n * @param serializationObject The object to serialize to\r\n */\r\n serialize(serializationObject: any): void;\r\n}\r\n\r\n/**\r\n * Strong typing of a Mesh related stage step action\r\n */\r\nexport type MeshStageAction = (mesh: AbstractMesh, hardwareInstancedRendering: boolean) => boolean;\r\n\r\n/**\r\n * Strong typing of a Evaluate Sub Mesh related stage step action\r\n */\r\nexport type EvaluateSubMeshStageAction = (mesh: AbstractMesh, subMesh: SubMesh) => void;\r\n\r\n/**\r\n * Strong typing of a pre active Mesh related stage step action\r\n */\r\nexport type PreActiveMeshStageAction = (mesh: AbstractMesh) => void;\r\n\r\n/**\r\n * Strong typing of a Camera related stage step action\r\n */\r\nexport type CameraStageAction = (camera: Camera) => void;\r\n\r\n/**\r\n * Strong typing of a Camera Frame buffer related stage step action\r\n */\r\nexport type CameraStageFrameBufferAction = (camera: Camera) => boolean;\r\n\r\n/**\r\n * Strong typing of a Render Target related stage step action\r\n */\r\nexport type RenderTargetStageAction = (renderTarget: RenderTargetTexture, faceIndex?: number, layer?: number) => void;\r\n\r\n/**\r\n * Strong typing of a RenderingGroup related stage step action\r\n */\r\nexport type RenderingGroupStageAction = (renderingGroupId: number) => void;\r\n\r\n/**\r\n * Strong typing of a Mesh Render related stage step action\r\n */\r\nexport type RenderingMeshStageAction = (mesh: Mesh, subMesh: SubMesh, batch: any, effect: Nullable) => void;\r\n\r\n/**\r\n * Strong typing of a simple stage step action\r\n */\r\nexport type SimpleStageAction = () => void;\r\n\r\n/**\r\n * Strong typing of a render target action.\r\n */\r\nexport type RenderTargetsStageAction = (renderTargets: SmartArrayNoDuplicate) => void;\r\n\r\n/**\r\n * Strong typing of a pointer move action.\r\n */\r\nexport type PointerMoveStageAction = (\r\n unTranslatedPointerX: number,\r\n unTranslatedPointerY: number,\r\n pickResult: Nullable,\r\n isMeshPicked: boolean,\r\n element: Nullable\r\n) => Nullable;\r\n\r\n/**\r\n * Strong typing of a pointer up/down action.\r\n */\r\nexport type PointerUpDownStageAction = (\r\n unTranslatedPointerX: number,\r\n unTranslatedPointerY: number,\r\n pickResult: Nullable,\r\n evt: IPointerEvent,\r\n doubleClick: boolean\r\n) => Nullable;\r\n\r\n/**\r\n * Representation of a stage in the scene (Basically a list of ordered steps)\r\n * @internal\r\n */\r\nexport class Stage extends Array<{ index: number; component: ISceneComponent; action: T }> {\r\n /**\r\n * Hide ctor from the rest of the world.\r\n * @param items The items to add.\r\n */\r\n private constructor(items?: { index: number; component: ISceneComponent; action: T }[]) {\r\n super(...(items));\r\n }\r\n\r\n /**\r\n * Creates a new Stage.\r\n * @returns A new instance of a Stage\r\n */\r\n static Create(): Stage {\r\n return Object.create(Stage.prototype);\r\n }\r\n\r\n /**\r\n * Registers a step in an ordered way in the targeted stage.\r\n * @param index Defines the position to register the step in\r\n * @param component Defines the component attached to the step\r\n * @param action Defines the action to launch during the step\r\n */\r\n public registerStep(index: number, component: ISceneComponent, action: T): void {\r\n let i = 0;\r\n let maxIndex = Number.MAX_VALUE;\r\n for (; i < this.length; i++) {\r\n const step = this[i];\r\n maxIndex = step.index;\r\n if (index < maxIndex) {\r\n break;\r\n }\r\n }\r\n this.splice(i, 0, { index, component, action: action.bind(component) });\r\n }\r\n\r\n /**\r\n * Clears all the steps from the stage.\r\n */\r\n public clear(): void {\r\n this.length = 0;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { Vector2 } from \"../Maths/math.vector\";\r\nimport type { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport type { IMouseEvent, IPointerEvent } from \"./deviceInputEvents\";\r\nimport type { InputManager } from \"../Inputs/scene.inputManager\";\r\n\r\nimport type { Ray } from \"../Culling/ray\";\r\n\r\n/**\r\n * Gather the list of pointer event types as constants.\r\n */\r\nexport class PointerEventTypes {\r\n /**\r\n * The pointerdown event is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons depressed to at least one button depressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer.\r\n */\r\n public static readonly POINTERDOWN = 0x01;\r\n /**\r\n * The pointerup event is fired when a pointer is no longer active.\r\n */\r\n public static readonly POINTERUP = 0x02;\r\n /**\r\n * The pointermove event is fired when a pointer changes coordinates.\r\n */\r\n public static readonly POINTERMOVE = 0x04;\r\n /**\r\n * The pointerwheel event is fired when a mouse wheel has been rotated.\r\n */\r\n public static readonly POINTERWHEEL = 0x08;\r\n /**\r\n * The pointerpick event is fired when a mesh or sprite has been picked by the pointer.\r\n */\r\n public static readonly POINTERPICK = 0x10;\r\n /**\r\n * The pointertap event is fired when a the object has been touched and released without drag.\r\n */\r\n public static readonly POINTERTAP = 0x20;\r\n /**\r\n * The pointerdoubletap event is fired when a the object has been touched and released twice without drag.\r\n */\r\n public static readonly POINTERDOUBLETAP = 0x40;\r\n}\r\n\r\n/**\r\n * Base class of pointer info types.\r\n */\r\nexport class PointerInfoBase {\r\n /**\r\n * Instantiates the base class of pointers info.\r\n * @param type Defines the type of event (PointerEventTypes)\r\n * @param event Defines the related dom event\r\n */\r\n constructor(\r\n /**\r\n * Defines the type of event (PointerEventTypes)\r\n */\r\n public type: number,\r\n /**\r\n * Defines the related dom event\r\n */\r\n public event: IMouseEvent\r\n ) {}\r\n}\r\n\r\n/**\r\n * This class is used to store pointer related info for the onPrePointerObservable event.\r\n * Set the skipOnPointerObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onPointerObservable\r\n */\r\nexport class PointerInfoPre extends PointerInfoBase {\r\n /**\r\n * Ray from a pointer if available (eg. 6dof controller)\r\n */\r\n public ray: Nullable = null;\r\n\r\n /**\r\n * Defines picking info coming from a near interaction (proximity instead of ray-based picking)\r\n */\r\n public nearInteractionPickingInfo: Nullable;\r\n\r\n /**\r\n * The original picking info that was used to trigger the pointer event\r\n */\r\n public originalPickingInfo: Nullable = null;\r\n\r\n /**\r\n * Defines the local position of the pointer on the canvas.\r\n */\r\n public localPosition: Vector2;\r\n\r\n /**\r\n * Defines whether the engine should skip the next OnPointerObservable associated to this pre.\r\n */\r\n public skipOnPointerObservable: boolean;\r\n\r\n /**\r\n * Instantiates a PointerInfoPre to store pointer related info to the onPrePointerObservable event.\r\n * @param type Defines the type of event (PointerEventTypes)\r\n * @param event Defines the related dom event\r\n * @param localX Defines the local x coordinates of the pointer when the event occured\r\n * @param localY Defines the local y coordinates of the pointer when the event occured\r\n */\r\n constructor(type: number, event: IMouseEvent, localX: number, localY: number) {\r\n super(type, event);\r\n this.skipOnPointerObservable = false;\r\n this.localPosition = new Vector2(localX, localY);\r\n }\r\n}\r\n\r\n/**\r\n * This type contains all the data related to a pointer event in Babylon.js.\r\n * The event member is an instance of PointerEvent for all types except PointerWheel and is of type MouseWheelEvent when type equals PointerWheel. The different event types can be found in the PointerEventTypes class.\r\n */\r\nexport class PointerInfo extends PointerInfoBase {\r\n private _pickInfo: Nullable;\r\n private _inputManager: Nullable;\r\n\r\n /**\r\n * Defines the picking info associated with this PointerInfo object (if applicable)\r\n */\r\n public get pickInfo(): Nullable {\r\n if (!this._pickInfo) {\r\n this._generatePickInfo();\r\n }\r\n\r\n return this._pickInfo;\r\n }\r\n /**\r\n * Instantiates a PointerInfo to store pointer related info to the onPointerObservable event.\r\n * @param type Defines the type of event (PointerEventTypes)\r\n * @param event Defines the related dom event\r\n * @param pickInfo Defines the picking info associated to the info (if any)\r\n * @param inputManager Defines the InputManager to use if there is no pickInfo\r\n */\r\n constructor(type: number, event: IMouseEvent, pickInfo: Nullable, inputManager: Nullable = null) {\r\n super(type, event);\r\n this._pickInfo = pickInfo;\r\n this._inputManager = inputManager;\r\n }\r\n\r\n /**\r\n * Generates the picking info if needed\r\n */\r\n /** @internal */\r\n public _generatePickInfo(): void {\r\n if (this._inputManager) {\r\n this._pickInfo = this._inputManager._pickMove(this.event as IPointerEvent);\r\n this._inputManager._setRayOnPointerInfo(this._pickInfo, this.event);\r\n this._inputManager = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Data relating to a touch event on the screen.\r\n */\r\nexport interface PointerTouch {\r\n /**\r\n * X coordinate of touch.\r\n */\r\n x: number;\r\n /**\r\n * Y coordinate of touch.\r\n */\r\n y: number;\r\n /**\r\n * Id of touch. Unique for each finger.\r\n */\r\n pointerId: number;\r\n /**\r\n * Event type passed from DOM.\r\n */\r\n type: any;\r\n}\r\n","import type { IDisposable } from \"../scene\";\r\nimport type { IActionEvent } from \"./actionEvent\";\r\nimport type { IAction } from \"./action\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Nullable } from \"../types\";\r\n\r\n/**\r\n * Abstract class used to decouple action Manager from scene and meshes.\r\n * Do not instantiate.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions\r\n */\r\nexport abstract class AbstractActionManager implements IDisposable {\r\n /** Gets the list of active triggers */\r\n public static Triggers: { [key: string]: number } = {};\r\n\r\n /** Gets the cursor to use when hovering items */\r\n public hoverCursor: string = \"\";\r\n\r\n /** Gets the list of actions */\r\n public actions = new Array();\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the manager is recursive meaning that it can trigger action from children\r\n */\r\n public isRecursive = false;\r\n\r\n /**\r\n * Releases all associated resources\r\n */\r\n public abstract dispose(): void;\r\n\r\n /**\r\n * Does this action manager has pointer triggers\r\n */\r\n public abstract get hasPointerTriggers(): boolean;\r\n\r\n /**\r\n * Does this action manager has pick triggers\r\n */\r\n public abstract get hasPickTriggers(): boolean;\r\n\r\n /**\r\n * Process a specific trigger\r\n * @param trigger defines the trigger to process\r\n * @param evt defines the event details to be processed\r\n */\r\n public abstract processTrigger(trigger: number, evt?: IActionEvent): void;\r\n\r\n /**\r\n * Does this action manager handles actions of any of the given triggers\r\n * @param triggers defines the triggers to be tested\r\n * @returns a boolean indicating whether one (or more) of the triggers is handled\r\n */\r\n public abstract hasSpecificTriggers(triggers: number[]): boolean;\r\n\r\n /**\r\n * Does this action manager handles actions of any of the given triggers. This function takes two arguments for\r\n * speed.\r\n * @param triggerA defines the trigger to be tested\r\n * @param triggerB defines the trigger to be tested\r\n * @returns a boolean indicating whether one (or more) of the triggers is handled\r\n */\r\n public abstract hasSpecificTriggers2(triggerA: number, triggerB: number): boolean;\r\n\r\n /**\r\n * Does this action manager handles actions of a given trigger\r\n * @param trigger defines the trigger to be tested\r\n * @param parameterPredicate defines an optional predicate to filter triggers by parameter\r\n * @returns whether the trigger is handled\r\n */\r\n public abstract hasSpecificTrigger(trigger: number, parameterPredicate?: (parameter: any) => boolean): boolean;\r\n\r\n /**\r\n * Serialize this manager to a JSON object\r\n * @param name defines the property name to store this manager\r\n * @returns a JSON representation of this manager\r\n */\r\n public abstract serialize(name: string): any;\r\n\r\n /**\r\n * Registers an action to this action manager\r\n * @param action defines the action to be registered\r\n * @returns the action amended (prepared) after registration\r\n */\r\n public abstract registerAction(action: IAction): Nullable;\r\n\r\n /**\r\n * Unregisters an action to this action manager\r\n * @param action defines the action to be unregistered\r\n * @returns a boolean indicating whether the action has been unregistered\r\n */\r\n public abstract unregisterAction(action: IAction): Boolean;\r\n\r\n /**\r\n * Does exist one action manager with at least one trigger\r\n **/\r\n public static get HasTriggers(): boolean {\r\n for (const t in AbstractActionManager.Triggers) {\r\n if (Object.prototype.hasOwnProperty.call(AbstractActionManager.Triggers, t)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Does exist one action manager with at least one pick trigger\r\n **/\r\n public static get HasPickTriggers(): boolean {\r\n for (const t in AbstractActionManager.Triggers) {\r\n if (Object.prototype.hasOwnProperty.call(AbstractActionManager.Triggers, t)) {\r\n const tAsInt = parseInt(t);\r\n if (tAsInt >= Constants.ACTION_OnPickTrigger && tAsInt <= Constants.ACTION_OnPickUpTrigger) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Does exist one action manager that handles actions of a given trigger\r\n * @param trigger defines the trigger to be tested\r\n * @returns a boolean indicating whether the trigger is handled by at least one action manager\r\n **/\r\n public static HasSpecificTrigger(trigger: number): boolean {\r\n for (const t in AbstractActionManager.Triggers) {\r\n if (Object.prototype.hasOwnProperty.call(AbstractActionManager.Triggers, t)) {\r\n const tAsInt = parseInt(t);\r\n if (tAsInt === trigger) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n","import type { IKeyboardEvent } from \"./deviceInputEvents\";\r\n\r\n/**\r\n * Gather the list of keyboard event types as constants.\r\n */\r\nexport class KeyboardEventTypes {\r\n /**\r\n * The keydown event is fired when a key becomes active (pressed).\r\n */\r\n public static readonly KEYDOWN = 0x01;\r\n /**\r\n * The keyup event is fired when a key has been released.\r\n */\r\n public static readonly KEYUP = 0x02;\r\n}\r\n\r\n/**\r\n * This class is used to store keyboard related info for the onKeyboardObservable event.\r\n */\r\nexport class KeyboardInfo {\r\n /**\r\n * Instantiates a new keyboard info.\r\n * This class is used to store keyboard related info for the onKeyboardObservable event.\r\n * @param type Defines the type of event (KeyboardEventTypes)\r\n * @param event Defines the related dom event\r\n */\r\n constructor(\r\n /**\r\n * Defines the type of event (KeyboardEventTypes)\r\n */\r\n public type: number,\r\n /**\r\n * Defines the related dom event\r\n */\r\n public event: IKeyboardEvent\r\n ) {}\r\n}\r\n\r\n/**\r\n * This class is used to store keyboard related info for the onPreKeyboardObservable event.\r\n * Set the skipOnKeyboardObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onKeyboardObservable\r\n */\r\nexport class KeyboardInfoPre extends KeyboardInfo {\r\n /**\r\n * Defines whether the engine should skip the next onKeyboardObservable associated to this pre.\r\n */\r\n public skipOnKeyboardObservable: boolean;\r\n\r\n /**\r\n * Defines whether the engine should skip the next onKeyboardObservable associated to this pre.\r\n * @deprecated use skipOnKeyboardObservable property instead\r\n */\r\n public get skipOnPointerObservable() {\r\n return this.skipOnKeyboardObservable;\r\n }\r\n public set skipOnPointerObservable(value) {\r\n this.skipOnKeyboardObservable = value;\r\n }\r\n\r\n /**\r\n * Instantiates a new keyboard pre info.\r\n * This class is used to store keyboard related info for the onPreKeyboardObservable event.\r\n * @param type Defines the type of event (KeyboardEventTypes)\r\n * @param event Defines the related dom event\r\n */\r\n constructor(\r\n /**\r\n * Defines the type of event (KeyboardEventTypes)\r\n */\r\n public type: number,\r\n /**\r\n * Defines the related dom event\r\n */\r\n public event: IKeyboardEvent\r\n ) {\r\n super(type, event);\r\n this.skipOnKeyboardObservable = false;\r\n }\r\n}\r\n","import { Constants } from \"../Engines/constants\";\r\nimport type { IUIEvent } from \"../Events/deviceInputEvents\";\r\nimport { EventConstants } from \"../Events/deviceInputEvents\";\r\nimport type { Nullable } from \"../types\";\r\nimport { DeviceType, NativePointerInput, PointerInput } from \"./InputDevices/deviceEnums\";\r\nimport type { IDeviceInputSystem } from \"./inputInterfaces\";\r\n\r\n/**\r\n * Class to wrap DeviceInputSystem data into an event object\r\n */\r\nexport class DeviceEventFactory {\r\n /**\r\n * Create device input events based on provided type and slot\r\n *\r\n * @param deviceType Type of device\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @param currentState Current value for given input\r\n * @param deviceInputSystem Reference to DeviceInputSystem\r\n * @param elementToAttachTo HTMLElement to reference as target for inputs\r\n * @returns IUIEvent object\r\n */\r\n public static CreateDeviceEvent(\r\n deviceType: DeviceType,\r\n deviceSlot: number,\r\n inputIndex: number,\r\n currentState: Nullable,\r\n deviceInputSystem: IDeviceInputSystem,\r\n elementToAttachTo?: any,\r\n pointerId?: number\r\n ): IUIEvent {\r\n switch (deviceType) {\r\n case DeviceType.Keyboard:\r\n return this._CreateKeyboardEvent(inputIndex, currentState, deviceInputSystem, elementToAttachTo);\r\n case DeviceType.Mouse:\r\n if (inputIndex === PointerInput.MouseWheelX || inputIndex === PointerInput.MouseWheelY || inputIndex === PointerInput.MouseWheelZ) {\r\n return this._CreateWheelEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo);\r\n }\r\n // eslint-disable-next-line no-fallthrough\r\n case DeviceType.Touch:\r\n return this._CreatePointerEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo, pointerId);\r\n default:\r\n throw `Unable to generate event for device ${DeviceType[deviceType]}`;\r\n }\r\n }\r\n\r\n /**\r\n * Creates pointer event\r\n *\r\n * @param deviceType Type of device\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @param currentState Current value for given input\r\n * @param deviceInputSystem Reference to DeviceInputSystem\r\n * @param elementToAttachTo HTMLElement to reference as target for inputs\r\n * @returns IUIEvent object (Pointer)\r\n */\r\n private static _CreatePointerEvent(\r\n deviceType: DeviceType,\r\n deviceSlot: number,\r\n inputIndex: number,\r\n currentState: Nullable,\r\n deviceInputSystem: IDeviceInputSystem,\r\n elementToAttachTo?: any,\r\n pointerId?: number\r\n ): any {\r\n const evt = this._CreateMouseEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo);\r\n\r\n if (deviceType === DeviceType.Mouse) {\r\n evt.deviceType = DeviceType.Mouse;\r\n evt.pointerId = 1;\r\n evt.pointerType = \"mouse\";\r\n } else {\r\n evt.deviceType = DeviceType.Touch;\r\n evt.pointerId = pointerId ?? deviceSlot;\r\n evt.pointerType = \"touch\";\r\n }\r\n\r\n let buttons = 0;\r\n\r\n // Populate buttons property with current state of all mouse buttons\r\n // Uses values found on: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n buttons += deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.LeftClick);\r\n buttons += deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.RightClick) * 2;\r\n buttons += deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.MiddleClick) * 4;\r\n evt.buttons = buttons;\r\n\r\n if (inputIndex === PointerInput.Move) {\r\n evt.type = \"pointermove\";\r\n } else if (inputIndex >= PointerInput.LeftClick && inputIndex <= PointerInput.RightClick) {\r\n evt.type = currentState === 1 ? \"pointerdown\" : \"pointerup\";\r\n evt.button = inputIndex - 2;\r\n }\r\n\r\n return evt;\r\n }\r\n\r\n /**\r\n * Create Mouse Wheel Event\r\n * @param deviceType Type of device\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @param currentState Current value for given input\r\n * @param deviceInputSystem Reference to DeviceInputSystem\r\n * @param elementToAttachTo HTMLElement to reference as target for inputs\r\n * @returns IUIEvent object (Wheel)\r\n */\r\n private static _CreateWheelEvent(\r\n deviceType: DeviceType,\r\n deviceSlot: number,\r\n inputIndex: number,\r\n currentState: Nullable,\r\n deviceInputSystem: IDeviceInputSystem,\r\n elementToAttachTo: any\r\n ): any {\r\n const evt = this._CreateMouseEvent(deviceType, deviceSlot, inputIndex, currentState, deviceInputSystem, elementToAttachTo);\r\n\r\n // While WheelEvents don't generally have a pointerId, we used to add one in the InputManager\r\n // This line has been added to make the InputManager more platform-agnostic\r\n // Similar code exists in the WebDeviceInputSystem to handle browser created events\r\n evt.pointerId = 1;\r\n evt.type = \"wheel\";\r\n evt.deltaMode = EventConstants.DOM_DELTA_PIXEL;\r\n evt.deltaX = 0;\r\n evt.deltaY = 0;\r\n evt.deltaZ = 0;\r\n\r\n switch (inputIndex) {\r\n case PointerInput.MouseWheelX:\r\n evt.deltaX = currentState;\r\n break;\r\n case PointerInput.MouseWheelY:\r\n evt.deltaY = currentState;\r\n break;\r\n case PointerInput.MouseWheelZ:\r\n evt.deltaZ = currentState;\r\n break;\r\n }\r\n\r\n return evt;\r\n }\r\n\r\n /**\r\n * Create Mouse Event\r\n * @param deviceType Type of device\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @param currentState Current value for given input\r\n * @param deviceInputSystem Reference to DeviceInputSystem\r\n * @param elementToAttachTo HTMLElement to reference as target for inputs\r\n * @returns IUIEvent object (Mouse)\r\n */\r\n private static _CreateMouseEvent(\r\n deviceType: DeviceType,\r\n deviceSlot: number,\r\n inputIndex: number,\r\n currentState: Nullable,\r\n deviceInputSystem: IDeviceInputSystem,\r\n elementToAttachTo?: any\r\n ): any {\r\n const evt = this._CreateEvent(elementToAttachTo);\r\n const pointerX = deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.Horizontal);\r\n const pointerY = deviceInputSystem.pollInput(deviceType, deviceSlot, PointerInput.Vertical);\r\n\r\n // Handle offsets/deltas based on existence of HTMLElement\r\n if (elementToAttachTo) {\r\n evt.movementX = 0;\r\n evt.movementY = 0;\r\n evt.offsetX = evt.movementX - elementToAttachTo.getBoundingClientRect().x;\r\n evt.offsetY = evt.movementY - elementToAttachTo.getBoundingClientRect().y;\r\n } else {\r\n evt.movementX = deviceInputSystem.pollInput(deviceType, deviceSlot, NativePointerInput.DeltaHorizontal); // DeltaHorizontal\r\n evt.movementY = deviceInputSystem.pollInput(deviceType, deviceSlot, NativePointerInput.DeltaVertical); // DeltaVertical\r\n evt.offsetX = 0;\r\n evt.offsetY = 0;\r\n }\r\n this._CheckNonCharacterKeys(evt, deviceInputSystem);\r\n\r\n evt.clientX = pointerX;\r\n evt.clientY = pointerY;\r\n evt.x = pointerX;\r\n evt.y = pointerY;\r\n\r\n evt.deviceType = deviceType;\r\n evt.deviceSlot = deviceSlot;\r\n evt.inputIndex = inputIndex;\r\n\r\n return evt;\r\n }\r\n\r\n /**\r\n * Create Keyboard Event\r\n * @param inputIndex Id of input to be checked\r\n * @param currentState Current value for given input\r\n * @param deviceInputSystem Reference to DeviceInputSystem\r\n * @param elementToAttachTo HTMLElement to reference as target for inputs\r\n * @returns IEvent object (Keyboard)\r\n */\r\n private static _CreateKeyboardEvent(inputIndex: number, currentState: Nullable, deviceInputSystem: IDeviceInputSystem, elementToAttachTo?: any): any {\r\n const evt = this._CreateEvent(elementToAttachTo);\r\n this._CheckNonCharacterKeys(evt, deviceInputSystem);\r\n evt.deviceType = DeviceType.Keyboard;\r\n evt.deviceSlot = 0;\r\n evt.inputIndex = inputIndex;\r\n\r\n evt.type = currentState === 1 ? \"keydown\" : \"keyup\";\r\n evt.key = String.fromCharCode(inputIndex);\r\n evt.keyCode = inputIndex;\r\n\r\n return evt;\r\n }\r\n\r\n /**\r\n * Add parameters for non-character keys (Ctrl, Alt, Meta, Shift)\r\n * @param evt Event object to add parameters to\r\n * @param deviceInputSystem DeviceInputSystem to pull values from\r\n */\r\n private static _CheckNonCharacterKeys(evt: any, deviceInputSystem: IDeviceInputSystem): void {\r\n const isKeyboardActive = deviceInputSystem.isDeviceAvailable(DeviceType.Keyboard);\r\n const altKey = isKeyboardActive && deviceInputSystem.pollInput(DeviceType.Keyboard, 0, Constants.INPUT_ALT_KEY) === 1;\r\n const ctrlKey = isKeyboardActive && deviceInputSystem.pollInput(DeviceType.Keyboard, 0, Constants.INPUT_CTRL_KEY) === 1;\r\n const metaKey =\r\n isKeyboardActive &&\r\n (deviceInputSystem.pollInput(DeviceType.Keyboard, 0, Constants.INPUT_META_KEY1) === 1 ||\r\n deviceInputSystem.pollInput(DeviceType.Keyboard, 0, Constants.INPUT_META_KEY2) === 1 ||\r\n deviceInputSystem.pollInput(DeviceType.Keyboard, 0, Constants.INPUT_META_KEY3) === 1);\r\n const shiftKey = isKeyboardActive && deviceInputSystem.pollInput(DeviceType.Keyboard, 0, Constants.INPUT_SHIFT_KEY) === 1;\r\n\r\n evt.altKey = altKey;\r\n evt.ctrlKey = ctrlKey;\r\n evt.metaKey = metaKey;\r\n evt.shiftKey = shiftKey;\r\n }\r\n\r\n /**\r\n * Create base event object\r\n * @param elementToAttachTo Value to use as event target\r\n * @returns\r\n */\r\n private static _CreateEvent(elementToAttachTo: any): any {\r\n const evt: { [k: string]: any } = {};\r\n evt.preventDefault = () => {};\r\n evt.target = elementToAttachTo;\r\n\r\n return evt;\r\n }\r\n}\r\n","import type { INative } from \"../Engines/Native/nativeInterfaces\";\r\nimport type { IUIEvent } from \"../Events/deviceInputEvents\";\r\nimport { DeviceEventFactory } from \"./eventFactory\";\r\nimport { DeviceType } from \"./InputDevices/deviceEnums\";\r\nimport type { IDeviceInputSystem } from \"./inputInterfaces\";\r\n\r\ndeclare const _native: INative;\r\n\r\n/** @internal */\r\nexport class NativeDeviceInputSystem implements IDeviceInputSystem {\r\n private readonly _nativeInput: IDeviceInputSystem;\r\n\r\n public constructor(\r\n onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onInputChanged: (deviceType: DeviceType, deviceSlot: number, eventData: IUIEvent) => void\r\n ) {\r\n this._nativeInput = _native.DeviceInputSystem\r\n ? new _native.DeviceInputSystem(onDeviceConnected, onDeviceDisconnected, (deviceType, deviceSlot, inputIndex, currentState) => {\r\n const evt = DeviceEventFactory.CreateDeviceEvent(deviceType, deviceSlot, inputIndex, currentState, this);\r\n\r\n onInputChanged(deviceType, deviceSlot, evt);\r\n })\r\n : this._createDummyNativeInput();\r\n }\r\n\r\n // Public functions\r\n /**\r\n * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @returns Current value of input\r\n */\r\n public pollInput(deviceType: DeviceType, deviceSlot: number, inputIndex: number): number {\r\n return this._nativeInput.pollInput(deviceType, deviceSlot, inputIndex);\r\n }\r\n\r\n /**\r\n * Check for a specific device in the DeviceInputSystem\r\n * @param deviceType Type of device to check for\r\n * @returns bool with status of device's existence\r\n */\r\n public isDeviceAvailable(deviceType: DeviceType): boolean {\r\n //TODO: FIx native side first\r\n return deviceType === DeviceType.Mouse || deviceType === DeviceType.Touch;\r\n }\r\n\r\n /**\r\n * Dispose of all the observables\r\n */\r\n public dispose(): void {\r\n this._nativeInput.dispose();\r\n }\r\n\r\n /**\r\n * For versions of BabylonNative that don't have the NativeInput plugin initialized, create a dummy version\r\n * @returns Object with dummy functions\r\n */\r\n private _createDummyNativeInput() {\r\n const nativeInput = {\r\n pollInput: () => {\r\n return 0;\r\n },\r\n isDeviceAvailable: () => {\r\n return false;\r\n },\r\n dispose: () => {},\r\n };\r\n\r\n return nativeInput;\r\n }\r\n}\r\n","import type { Engine } from \"../Engines/engine\";\r\nimport type { IPointerEvent, IUIEvent } from \"../Events/deviceInputEvents\";\r\nimport { IsNavigatorAvailable } from \"../Misc/domManagement\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { DeviceEventFactory } from \"./eventFactory\";\r\nimport { DeviceType, PointerInput } from \"./InputDevices/deviceEnums\";\r\nimport type { IDeviceInputSystem } from \"./inputInterfaces\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst MAX_KEYCODES = 255;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst MAX_POINTER_INPUTS = Object.keys(PointerInput).length / 2;\r\n\r\n/** @internal */\r\nexport class WebDeviceInputSystem implements IDeviceInputSystem {\r\n // Private Members\r\n private _inputs: Array<{ [deviceSlot: number]: Array }> = [];\r\n private _gamepads: Array;\r\n private _keyboardActive: boolean = false;\r\n private _pointerActive: boolean = false;\r\n private _elementToAttachTo: HTMLElement;\r\n private _metaKeys: Array;\r\n private readonly _engine: Engine;\r\n private readonly _usingSafari: boolean = Tools.IsSafari();\r\n // Found solution for determining if MacOS is being used here:\r\n // https://stackoverflow.com/questions/10527983/best-way-to-detect-mac-os-x-or-windows-computers-with-javascript-or-jquery\r\n private readonly _usingMacOS: boolean = IsNavigatorAvailable() && /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);\r\n\r\n private _onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void;\r\n private _onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void;\r\n private _onInputChanged: (deviceType: DeviceType, deviceSlot: number, eventData: IUIEvent) => void;\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _keyboardDownEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _keyboardUpEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _keyboardBlurEvent = (evt: any) => {};\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _pointerMoveEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _pointerDownEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _pointerUpEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _pointerCancelEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _pointerWheelEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _pointerBlurEvent = (evt: any) => {};\r\n private _wheelEventName: string;\r\n private _eventsAttached: boolean = false;\r\n\r\n private _mouseId = -1;\r\n private readonly _isUsingFirefox = IsNavigatorAvailable() && navigator.userAgent && navigator.userAgent.indexOf(\"Firefox\") !== -1;\r\n\r\n // Array to store active Pointer ID values; prevents issues with negative pointerIds\r\n private _activeTouchIds: Array;\r\n private _maxTouchPoints: number = 0;\r\n\r\n private _pointerInputClearObserver: Nullable> = null;\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _gamepadConnectedEvent = (evt: any) => {};\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _gamepadDisconnectedEvent = (evt: any) => {};\r\n\r\n private _eventPrefix: string;\r\n\r\n constructor(\r\n engine: Engine,\r\n onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void,\r\n onInputChanged: (deviceType: DeviceType, deviceSlot: number, eventData: IUIEvent) => void\r\n ) {\r\n this._eventPrefix = Tools.GetPointerPrefix(engine);\r\n this._engine = engine;\r\n\r\n this._onDeviceConnected = onDeviceConnected;\r\n this._onDeviceDisconnected = onDeviceDisconnected;\r\n this._onInputChanged = onInputChanged;\r\n\r\n // If we need a pointerId, set one for future use\r\n this._mouseId = this._isUsingFirefox ? 0 : 1;\r\n\r\n this._enableEvents();\r\n\r\n if (this._usingMacOS) {\r\n this._metaKeys = [];\r\n }\r\n\r\n // Set callback to enable event handler switching when inputElement changes\r\n if (!this._engine._onEngineViewChanged) {\r\n this._engine._onEngineViewChanged = () => {\r\n this._enableEvents();\r\n };\r\n }\r\n }\r\n\r\n // Public functions\r\n /**\r\n * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @returns Current value of input\r\n */\r\n public pollInput(deviceType: DeviceType, deviceSlot: number, inputIndex: number): number {\r\n const device = this._inputs[deviceType][deviceSlot];\r\n\r\n if (!device) {\r\n throw `Unable to find device ${DeviceType[deviceType]}`;\r\n }\r\n\r\n if (deviceType >= DeviceType.DualShock && deviceType <= DeviceType.DualSense) {\r\n this._updateDevice(deviceType, deviceSlot, inputIndex);\r\n }\r\n\r\n const currentValue = device[inputIndex];\r\n if (currentValue === undefined) {\r\n throw `Unable to find input ${inputIndex} for device ${DeviceType[deviceType]} in slot ${deviceSlot}`;\r\n }\r\n\r\n if (inputIndex === PointerInput.Move) {\r\n Tools.Warn(`Unable to provide information for PointerInput.Move. Try using PointerInput.Horizontal or PointerInput.Vertical for move data.`);\r\n }\r\n\r\n return currentValue;\r\n }\r\n\r\n /**\r\n * Check for a specific device in the DeviceInputSystem\r\n * @param deviceType Type of device to check for\r\n * @returns bool with status of device's existence\r\n */\r\n public isDeviceAvailable(deviceType: DeviceType): boolean {\r\n return this._inputs[deviceType] !== undefined;\r\n }\r\n\r\n /**\r\n * Dispose of all the eventlisteners\r\n */\r\n public dispose(): void {\r\n // Callbacks\r\n this._onDeviceConnected = () => {};\r\n this._onDeviceDisconnected = () => {};\r\n this._onInputChanged = () => {};\r\n delete this._engine._onEngineViewChanged;\r\n\r\n if (this._elementToAttachTo) {\r\n this._disableEvents();\r\n }\r\n }\r\n\r\n /**\r\n * Enable listening for user input events\r\n */\r\n private _enableEvents(): void {\r\n const inputElement = this?._engine.getInputElement();\r\n if (inputElement && (!this._eventsAttached || this._elementToAttachTo !== inputElement)) {\r\n // Remove events before adding to avoid double events or simultaneous events on multiple canvases\r\n this._disableEvents();\r\n\r\n // If the inputs array has already been created, zero it out to before setting up events\r\n if (this._inputs) {\r\n for (const inputs of this._inputs) {\r\n if (inputs) {\r\n for (const deviceSlotKey in inputs) {\r\n const deviceSlot = +deviceSlotKey;\r\n const device = inputs[deviceSlot];\r\n if (device) {\r\n for (let inputIndex = 0; inputIndex < device.length; inputIndex++) {\r\n device[inputIndex] = 0;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n this._elementToAttachTo = inputElement;\r\n // Set tab index for the inputElement to the engine's canvasTabIndex, if and only if the element's tab index is -1\r\n this._elementToAttachTo.tabIndex = this._elementToAttachTo.tabIndex !== -1 ? this._elementToAttachTo.tabIndex : this._engine.canvasTabIndex;\r\n this._handleKeyActions();\r\n this._handlePointerActions();\r\n this._handleGamepadActions();\r\n this._eventsAttached = true;\r\n\r\n // Check for devices that are already connected but aren't registered. Currently, only checks for gamepads and mouse\r\n this._checkForConnectedDevices();\r\n }\r\n }\r\n\r\n /**\r\n * Disable listening for user input events\r\n */\r\n private _disableEvents(): void {\r\n if (this._elementToAttachTo) {\r\n // Blur Events\r\n this._elementToAttachTo.removeEventListener(\"blur\", this._keyboardBlurEvent);\r\n this._elementToAttachTo.removeEventListener(\"blur\", this._pointerBlurEvent);\r\n\r\n // Keyboard Events\r\n this._elementToAttachTo.removeEventListener(\"keydown\", this._keyboardDownEvent);\r\n this._elementToAttachTo.removeEventListener(\"keyup\", this._keyboardUpEvent);\r\n\r\n // Pointer Events\r\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"move\", this._pointerMoveEvent);\r\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"down\", this._pointerDownEvent);\r\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"up\", this._pointerUpEvent);\r\n this._elementToAttachTo.removeEventListener(this._eventPrefix + \"cancel\", this._pointerCancelEvent);\r\n this._elementToAttachTo.removeEventListener(this._wheelEventName, this._pointerWheelEvent);\r\n\r\n // Gamepad Events\r\n window.removeEventListener(\"gamepadconnected\", this._gamepadConnectedEvent);\r\n window.removeEventListener(\"gamepaddisconnected\", this._gamepadDisconnectedEvent);\r\n }\r\n\r\n if (this._pointerInputClearObserver) {\r\n this._engine.onEndFrameObservable.remove(this._pointerInputClearObserver);\r\n }\r\n\r\n this._eventsAttached = false;\r\n }\r\n\r\n /**\r\n * Checks for existing connections to devices and register them, if necessary\r\n * Currently handles gamepads and mouse\r\n */\r\n private _checkForConnectedDevices(): void {\r\n if (navigator.getGamepads) {\r\n const gamepads = navigator.getGamepads();\r\n\r\n for (const gamepad of gamepads) {\r\n if (gamepad) {\r\n this._addGamePad(gamepad);\r\n }\r\n }\r\n }\r\n\r\n // If the device in use has mouse capabilities, pre-register mouse\r\n if (typeof matchMedia === \"function\" && matchMedia(\"(pointer:fine)\").matches) {\r\n // This will provide a dummy value for the cursor position and is expected to be overridden when the first mouse event happens.\r\n // There isn't any good way to get the current position outside of a pointer event so that's why this was done.\r\n this._addPointerDevice(DeviceType.Mouse, 0, 0, 0);\r\n }\r\n }\r\n\r\n // Private functions\r\n /**\r\n * Add a gamepad to the DeviceInputSystem\r\n * @param gamepad A single DOM Gamepad object\r\n */\r\n private _addGamePad(gamepad: any): void {\r\n const deviceType = this._getGamepadDeviceType(gamepad.id);\r\n const deviceSlot = gamepad.index;\r\n\r\n this._gamepads = this._gamepads || new Array(gamepad.index + 1);\r\n this._registerDevice(deviceType, deviceSlot, gamepad.buttons.length + gamepad.axes.length);\r\n\r\n this._gamepads[deviceSlot] = deviceType;\r\n }\r\n\r\n /**\r\n * Add pointer device to DeviceInputSystem\r\n * @param deviceType Type of Pointer to add\r\n * @param deviceSlot Pointer ID (0 for mouse, pointerId for Touch)\r\n * @param currentX Current X at point of adding\r\n * @param currentY Current Y at point of adding\r\n */\r\n private _addPointerDevice(deviceType: DeviceType, deviceSlot: number, currentX: number, currentY: number): void {\r\n if (!this._pointerActive) {\r\n this._pointerActive = true;\r\n }\r\n this._registerDevice(deviceType, deviceSlot, MAX_POINTER_INPUTS);\r\n const pointer = this._inputs[deviceType][deviceSlot]; /* initialize our pointer position immediately after registration */\r\n pointer[0] = currentX;\r\n pointer[1] = currentY;\r\n }\r\n\r\n /**\r\n * Add device and inputs to device array\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param numberOfInputs Number of input entries to create for given device\r\n */\r\n private _registerDevice(deviceType: DeviceType, deviceSlot: number, numberOfInputs: number): void {\r\n if (deviceSlot === undefined) {\r\n throw `Unable to register device ${DeviceType[deviceType]} to undefined slot.`;\r\n }\r\n\r\n if (!this._inputs[deviceType]) {\r\n this._inputs[deviceType] = {};\r\n }\r\n\r\n if (!this._inputs[deviceType][deviceSlot]) {\r\n const device = new Array(numberOfInputs);\r\n\r\n device.fill(0);\r\n\r\n this._inputs[deviceType][deviceSlot] = device;\r\n this._onDeviceConnected(deviceType, deviceSlot);\r\n }\r\n }\r\n\r\n /**\r\n * Given a specific device name, remove that device from the device map\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n */\r\n private _unregisterDevice(deviceType: DeviceType, deviceSlot: number): void {\r\n if (this._inputs[deviceType][deviceSlot]) {\r\n delete this._inputs[deviceType][deviceSlot];\r\n this._onDeviceDisconnected(deviceType, deviceSlot);\r\n }\r\n }\r\n\r\n /**\r\n * Handle all actions that come from keyboard interaction\r\n */\r\n private _handleKeyActions(): void {\r\n this._keyboardDownEvent = (evt) => {\r\n if (!this._keyboardActive) {\r\n this._keyboardActive = true;\r\n this._registerDevice(DeviceType.Keyboard, 0, MAX_KEYCODES);\r\n }\r\n\r\n const kbKey = this._inputs[DeviceType.Keyboard][0];\r\n if (kbKey) {\r\n kbKey[evt.keyCode] = 1;\r\n\r\n const deviceEvent = evt as IUIEvent;\r\n deviceEvent.inputIndex = evt.keyCode;\r\n\r\n if (this._usingMacOS && evt.metaKey && evt.key !== \"Meta\") {\r\n if (!this._metaKeys.includes(evt.keyCode)) {\r\n this._metaKeys.push(evt.keyCode);\r\n }\r\n }\r\n\r\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\r\n }\r\n };\r\n\r\n this._keyboardUpEvent = (evt) => {\r\n if (!this._keyboardActive) {\r\n this._keyboardActive = true;\r\n this._registerDevice(DeviceType.Keyboard, 0, MAX_KEYCODES);\r\n }\r\n\r\n const kbKey = this._inputs[DeviceType.Keyboard][0];\r\n if (kbKey) {\r\n kbKey[evt.keyCode] = 0;\r\n\r\n const deviceEvent = evt as IUIEvent;\r\n deviceEvent.inputIndex = evt.keyCode;\r\n\r\n if (this._usingMacOS && evt.key === \"Meta\" && this._metaKeys.length > 0) {\r\n for (const keyCode of this._metaKeys) {\r\n const deviceEvent: IUIEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Keyboard, 0, keyCode, 0, this, this._elementToAttachTo);\r\n kbKey[keyCode] = 0;\r\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\r\n }\r\n this._metaKeys.splice(0, this._metaKeys.length);\r\n }\r\n\r\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\r\n }\r\n };\r\n\r\n this._keyboardBlurEvent = () => {\r\n if (this._keyboardActive) {\r\n const kbKey = this._inputs[DeviceType.Keyboard][0];\r\n\r\n for (let i = 0; i < kbKey.length; i++) {\r\n if (kbKey[i] !== 0) {\r\n kbKey[i] = 0;\r\n\r\n const deviceEvent: IUIEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Keyboard, 0, i, 0, this, this._elementToAttachTo);\r\n\r\n this._onInputChanged(DeviceType.Keyboard, 0, deviceEvent);\r\n }\r\n }\r\n if (this._usingMacOS) {\r\n this._metaKeys.splice(0, this._metaKeys.length);\r\n }\r\n }\r\n };\r\n\r\n this._elementToAttachTo.addEventListener(\"keydown\", this._keyboardDownEvent);\r\n this._elementToAttachTo.addEventListener(\"keyup\", this._keyboardUpEvent);\r\n this._elementToAttachTo.addEventListener(\"blur\", this._keyboardBlurEvent);\r\n }\r\n\r\n /**\r\n * Handle all actions that come from pointer interaction\r\n */\r\n private _handlePointerActions(): void {\r\n // If maxTouchPoints is defined, use that value. Otherwise, allow for a minimum for supported gestures like pinch\r\n this._maxTouchPoints = (IsNavigatorAvailable() && navigator.maxTouchPoints) || 2;\r\n if (!this._activeTouchIds) {\r\n this._activeTouchIds = new Array(this._maxTouchPoints);\r\n }\r\n\r\n for (let i = 0; i < this._maxTouchPoints; i++) {\r\n this._activeTouchIds[i] = -1;\r\n }\r\n\r\n this._pointerMoveEvent = (evt) => {\r\n const deviceType = this._getPointerType(evt);\r\n const deviceSlot = deviceType === DeviceType.Mouse ? 0 : this._activeTouchIds.indexOf(evt.pointerId);\r\n\r\n if (!this._inputs[deviceType]) {\r\n this._inputs[deviceType] = {};\r\n }\r\n\r\n if (!this._inputs[deviceType][deviceSlot]) {\r\n this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);\r\n }\r\n\r\n const pointer = this._inputs[deviceType][deviceSlot];\r\n if (pointer) {\r\n const deviceEvent = evt as IPointerEvent;\r\n deviceEvent.inputIndex = PointerInput.Move;\r\n\r\n pointer[PointerInput.Horizontal] = evt.clientX;\r\n pointer[PointerInput.Vertical] = evt.clientY;\r\n\r\n if (evt.pointerId === undefined) {\r\n evt.pointerId = this._mouseId;\r\n }\r\n\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n\r\n // Lets Propagate the event for move with same position.\r\n if (!this._usingSafari && evt.button !== -1) {\r\n deviceEvent.inputIndex = evt.button + 2;\r\n pointer[evt.button + 2] = pointer[evt.button + 2] ? 0 : 1; // Reverse state of button if evt.button has value\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n }\r\n }\r\n };\r\n\r\n this._pointerDownEvent = (evt) => {\r\n const deviceType = this._getPointerType(evt);\r\n let deviceSlot = deviceType === DeviceType.Mouse ? 0 : evt.pointerId;\r\n\r\n if (deviceType === DeviceType.Touch) {\r\n const idx = this._activeTouchIds.indexOf(-1);\r\n\r\n if (idx >= 0) {\r\n deviceSlot = idx;\r\n this._activeTouchIds[idx] = evt.pointerId;\r\n } else {\r\n // We can't find an open slot to store new pointer so just return (can only support max number of touches)\r\n Tools.Warn(`Max number of touches exceeded. Ignoring touches in excess of ${this._maxTouchPoints}`);\r\n return;\r\n }\r\n }\r\n\r\n if (!this._inputs[deviceType]) {\r\n this._inputs[deviceType] = {};\r\n }\r\n\r\n if (!this._inputs[deviceType][deviceSlot]) {\r\n this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);\r\n } else if (deviceType === DeviceType.Touch) {\r\n this._onDeviceConnected(deviceType, deviceSlot);\r\n }\r\n\r\n const pointer = this._inputs[deviceType][deviceSlot];\r\n if (pointer) {\r\n const previousHorizontal = pointer[PointerInput.Horizontal];\r\n const previousVertical = pointer[PointerInput.Vertical];\r\n\r\n if (deviceType === DeviceType.Mouse) {\r\n // Mouse; Set pointerId if undefined\r\n if (evt.pointerId === undefined) {\r\n evt.pointerId = this._mouseId;\r\n }\r\n\r\n if (!document.pointerLockElement) {\r\n try {\r\n this._elementToAttachTo.setPointerCapture(this._mouseId);\r\n } catch (e) {\r\n // DO NOTHING\r\n }\r\n }\r\n } else {\r\n // Touch; Since touches are dynamically assigned, only set capture if we have an id\r\n if (evt.pointerId && !document.pointerLockElement) {\r\n try {\r\n this._elementToAttachTo.setPointerCapture(evt.pointerId);\r\n } catch (e) {\r\n // DO NOTHING\r\n }\r\n }\r\n }\r\n\r\n pointer[PointerInput.Horizontal] = evt.clientX;\r\n pointer[PointerInput.Vertical] = evt.clientY;\r\n pointer[evt.button + 2] = 1;\r\n\r\n const deviceEvent = evt as IUIEvent;\r\n\r\n // NOTE: The +2 used here to is because PointerInput has the same value progression for its mouse buttons as PointerEvent.button\r\n // However, we have our X and Y values front-loaded to group together the touch inputs but not break this progression\r\n // EG. ([X, Y, Left-click], Middle-click, etc...)\r\n deviceEvent.inputIndex = evt.button + 2;\r\n\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n\r\n if (previousHorizontal !== evt.clientX || previousVertical !== evt.clientY) {\r\n deviceEvent.inputIndex = PointerInput.Move;\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n }\r\n }\r\n };\r\n\r\n this._pointerUpEvent = (evt) => {\r\n const deviceType = this._getPointerType(evt);\r\n const deviceSlot = deviceType === DeviceType.Mouse ? 0 : this._activeTouchIds.indexOf(evt.pointerId);\r\n\r\n if (deviceType === DeviceType.Touch) {\r\n if (deviceSlot === -1) {\r\n return;\r\n } else {\r\n this._activeTouchIds[deviceSlot] = -1;\r\n }\r\n }\r\n\r\n const pointer = this._inputs[deviceType]?.[deviceSlot];\r\n if (pointer && pointer[evt.button + 2] !== 0) {\r\n const previousHorizontal = pointer[PointerInput.Horizontal];\r\n const previousVertical = pointer[PointerInput.Vertical];\r\n\r\n pointer[PointerInput.Horizontal] = evt.clientX;\r\n pointer[PointerInput.Vertical] = evt.clientY;\r\n pointer[evt.button + 2] = 0;\r\n\r\n const deviceEvent = evt as IUIEvent;\r\n\r\n if (evt.pointerId === undefined) {\r\n evt.pointerId = this._mouseId;\r\n }\r\n\r\n if (previousHorizontal !== evt.clientX || previousVertical !== evt.clientY) {\r\n deviceEvent.inputIndex = PointerInput.Move;\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n }\r\n\r\n // NOTE: The +2 used here to is because PointerInput has the same value progression for its mouse buttons as PointerEvent.button\r\n // However, we have our X and Y values front-loaded to group together the touch inputs but not break this progression\r\n // EG. ([X, Y, Left-click], Middle-click, etc...)\r\n deviceEvent.inputIndex = evt.button + 2;\r\n\r\n if (deviceType === DeviceType.Mouse && this._mouseId >= 0 && this._elementToAttachTo.hasPointerCapture?.(this._mouseId)) {\r\n this._elementToAttachTo.releasePointerCapture(this._mouseId);\r\n } else if (evt.pointerId && this._elementToAttachTo.hasPointerCapture?.(evt.pointerId)) {\r\n this._elementToAttachTo.releasePointerCapture(evt.pointerId);\r\n }\r\n\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n\r\n if (deviceType === DeviceType.Touch) {\r\n this._onDeviceDisconnected(deviceType, deviceSlot);\r\n }\r\n }\r\n };\r\n\r\n this._pointerCancelEvent = (evt) => {\r\n if (evt.pointerType === \"mouse\") {\r\n const pointer = this._inputs[DeviceType.Mouse][0];\r\n\r\n if (this._mouseId >= 0 && this._elementToAttachTo.hasPointerCapture?.(this._mouseId)) {\r\n this._elementToAttachTo.releasePointerCapture(this._mouseId);\r\n }\r\n\r\n for (let inputIndex = PointerInput.LeftClick; inputIndex <= PointerInput.BrowserForward; inputIndex++) {\r\n if (pointer[inputIndex] === 1) {\r\n pointer[inputIndex] = 0;\r\n\r\n const deviceEvent: IUIEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Mouse, 0, inputIndex, 0, this, this._elementToAttachTo);\r\n\r\n this._onInputChanged(DeviceType.Mouse, 0, deviceEvent);\r\n }\r\n }\r\n } else {\r\n const deviceSlot = this._activeTouchIds.indexOf(evt.pointerId);\r\n\r\n if (this._elementToAttachTo.hasPointerCapture?.(evt.pointerId)) {\r\n this._elementToAttachTo.releasePointerCapture(evt.pointerId);\r\n }\r\n\r\n this._inputs[DeviceType.Touch][deviceSlot][PointerInput.LeftClick] = 0;\r\n\r\n const deviceEvent: IUIEvent = DeviceEventFactory.CreateDeviceEvent(\r\n DeviceType.Touch,\r\n deviceSlot,\r\n PointerInput.LeftClick,\r\n 0,\r\n this,\r\n this._elementToAttachTo,\r\n evt.pointerId\r\n );\r\n\r\n this._onInputChanged(DeviceType.Touch, deviceSlot, deviceEvent);\r\n\r\n this._activeTouchIds[deviceSlot] = -1;\r\n this._onDeviceDisconnected(DeviceType.Touch, deviceSlot);\r\n }\r\n };\r\n\r\n // Set Wheel Event Name, code originally from scene.inputManager\r\n this._wheelEventName =\r\n \"onwheel\" in document.createElement(\"div\")\r\n ? \"wheel\" // Modern browsers support \"wheel\"\r\n : (document).onmousewheel !== undefined\r\n ? \"mousewheel\" // Webkit and IE support at least \"mousewheel\"\r\n : \"DOMMouseScroll\"; // let's assume that remaining browsers are older Firefox\r\n\r\n // Code originally in scene.inputManager.ts\r\n // Chrome reports warning in console if wheel listener doesn't set an explicit passive option.\r\n // IE11 only supports captureEvent:boolean, not options:object, and it defaults to false.\r\n // Feature detection technique copied from: https://github.com/github/eventlistener-polyfill (MIT license)\r\n let passiveSupported = false;\r\n const noop = function () {};\r\n\r\n try {\r\n const options = Object.defineProperty({}, \"passive\", {\r\n get: function () {\r\n passiveSupported = true;\r\n },\r\n });\r\n\r\n this._elementToAttachTo.addEventListener(\"test\", noop, options);\r\n this._elementToAttachTo.removeEventListener(\"test\", noop, options);\r\n } catch (e) {\r\n /* */\r\n }\r\n\r\n this._pointerBlurEvent = () => {\r\n // Handle mouse buttons\r\n if (this.isDeviceAvailable(DeviceType.Mouse)) {\r\n const pointer = this._inputs[DeviceType.Mouse][0];\r\n\r\n if (this._mouseId >= 0 && this._elementToAttachTo.hasPointerCapture?.(this._mouseId)) {\r\n this._elementToAttachTo.releasePointerCapture(this._mouseId);\r\n }\r\n\r\n for (let inputIndex = PointerInput.LeftClick; inputIndex <= PointerInput.BrowserForward; inputIndex++) {\r\n if (pointer[inputIndex] === 1) {\r\n pointer[inputIndex] = 0;\r\n\r\n const deviceEvent: IUIEvent = DeviceEventFactory.CreateDeviceEvent(DeviceType.Mouse, 0, inputIndex, 0, this, this._elementToAttachTo);\r\n\r\n this._onInputChanged(DeviceType.Mouse, 0, deviceEvent);\r\n }\r\n }\r\n }\r\n\r\n // Handle Active Touches\r\n if (this.isDeviceAvailable(DeviceType.Touch)) {\r\n const pointer = this._inputs[DeviceType.Touch];\r\n\r\n for (let deviceSlot = 0; deviceSlot < this._activeTouchIds.length; deviceSlot++) {\r\n const pointerId = this._activeTouchIds[deviceSlot];\r\n\r\n if (this._elementToAttachTo.hasPointerCapture?.(pointerId)) {\r\n this._elementToAttachTo.releasePointerCapture(pointerId);\r\n }\r\n\r\n if (pointerId !== -1 && pointer[deviceSlot]?.[PointerInput.LeftClick] === 1) {\r\n pointer[deviceSlot][PointerInput.LeftClick] = 0;\r\n\r\n const deviceEvent: IUIEvent = DeviceEventFactory.CreateDeviceEvent(\r\n DeviceType.Touch,\r\n deviceSlot,\r\n PointerInput.LeftClick,\r\n 0,\r\n this,\r\n this._elementToAttachTo,\r\n pointerId\r\n );\r\n\r\n this._onInputChanged(DeviceType.Touch, deviceSlot, deviceEvent);\r\n\r\n this._activeTouchIds[deviceSlot] = -1;\r\n this._onDeviceDisconnected(DeviceType.Touch, deviceSlot);\r\n }\r\n }\r\n }\r\n };\r\n\r\n this._pointerWheelEvent = (evt) => {\r\n const deviceType = DeviceType.Mouse;\r\n const deviceSlot = 0;\r\n\r\n if (!this._inputs[deviceType]) {\r\n this._inputs[deviceType] = [];\r\n }\r\n\r\n if (!this._inputs[deviceType][deviceSlot]) {\r\n this._pointerActive = true;\r\n this._registerDevice(deviceType, deviceSlot, MAX_POINTER_INPUTS);\r\n }\r\n\r\n const pointer = this._inputs[deviceType][deviceSlot];\r\n if (pointer) {\r\n pointer[PointerInput.MouseWheelX] = evt.deltaX || 0;\r\n pointer[PointerInput.MouseWheelY] = evt.deltaY || evt.wheelDelta || 0;\r\n pointer[PointerInput.MouseWheelZ] = evt.deltaZ || 0;\r\n\r\n const deviceEvent = evt as IUIEvent;\r\n // By default, there is no pointerId for mouse wheel events so we'll add one here\r\n // This logic was originally in the InputManager but was added here to make the\r\n // InputManager more platform-agnostic\r\n if (evt.pointerId === undefined) {\r\n evt.pointerId = this._mouseId;\r\n }\r\n\r\n if (pointer[PointerInput.MouseWheelX] !== 0) {\r\n deviceEvent.inputIndex = PointerInput.MouseWheelX;\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n }\r\n if (pointer[PointerInput.MouseWheelY] !== 0) {\r\n deviceEvent.inputIndex = PointerInput.MouseWheelY;\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n }\r\n if (pointer[PointerInput.MouseWheelZ] !== 0) {\r\n deviceEvent.inputIndex = PointerInput.MouseWheelZ;\r\n this._onInputChanged(deviceType, deviceSlot, deviceEvent);\r\n }\r\n }\r\n };\r\n\r\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"move\", this._pointerMoveEvent);\r\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"down\", this._pointerDownEvent);\r\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"up\", this._pointerUpEvent);\r\n this._elementToAttachTo.addEventListener(this._eventPrefix + \"cancel\", this._pointerCancelEvent);\r\n this._elementToAttachTo.addEventListener(\"blur\", this._pointerBlurEvent);\r\n this._elementToAttachTo.addEventListener(this._wheelEventName, this._pointerWheelEvent, passiveSupported ? { passive: false } : false);\r\n\r\n // Since there's no up or down event for mouse wheel or delta x/y, clear mouse values at end of frame\r\n this._pointerInputClearObserver = this._engine.onEndFrameObservable.add(() => {\r\n if (this.isDeviceAvailable(DeviceType.Mouse)) {\r\n const pointer = this._inputs[DeviceType.Mouse][0];\r\n pointer[PointerInput.MouseWheelX] = 0;\r\n pointer[PointerInput.MouseWheelY] = 0;\r\n pointer[PointerInput.MouseWheelZ] = 0;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Handle all actions that come from gamepad interaction\r\n */\r\n private _handleGamepadActions(): void {\r\n this._gamepadConnectedEvent = (evt: any) => {\r\n this._addGamePad(evt.gamepad);\r\n };\r\n\r\n this._gamepadDisconnectedEvent = (evt: any) => {\r\n if (this._gamepads) {\r\n const deviceType = this._getGamepadDeviceType(evt.gamepad.id);\r\n const deviceSlot = evt.gamepad.index;\r\n\r\n this._unregisterDevice(deviceType, deviceSlot);\r\n delete this._gamepads[deviceSlot];\r\n }\r\n };\r\n\r\n window.addEventListener(\"gamepadconnected\", this._gamepadConnectedEvent);\r\n window.addEventListener(\"gamepaddisconnected\", this._gamepadDisconnectedEvent);\r\n }\r\n\r\n /**\r\n * Update all non-event based devices with each frame\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n */\r\n private _updateDevice(deviceType: DeviceType, deviceSlot: number, inputIndex: number): void {\r\n // Gamepads\r\n const gp = navigator.getGamepads()[deviceSlot];\r\n\r\n if (gp && deviceType === this._gamepads[deviceSlot]) {\r\n const device = this._inputs[deviceType][deviceSlot];\r\n\r\n if (inputIndex >= gp.buttons.length) {\r\n device[inputIndex] = gp.axes[inputIndex - gp.buttons.length].valueOf();\r\n } else {\r\n device[inputIndex] = gp.buttons[inputIndex].value;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets DeviceType from the device name\r\n * @param deviceName Name of Device from DeviceInputSystem\r\n * @returns DeviceType enum value\r\n */\r\n private _getGamepadDeviceType(deviceName: string): DeviceType {\r\n if (deviceName.indexOf(\"054c\") !== -1) {\r\n // DualShock 4 Gamepad\r\n return deviceName.indexOf(\"0ce6\") !== -1 ? DeviceType.DualSense : DeviceType.DualShock;\r\n } else if (deviceName.indexOf(\"Xbox One\") !== -1 || deviceName.search(\"Xbox 360\") !== -1 || deviceName.search(\"xinput\") !== -1) {\r\n // Xbox Gamepad\r\n return DeviceType.Xbox;\r\n } else if (deviceName.indexOf(\"057e\") !== -1) {\r\n // Switch Gamepad\r\n return DeviceType.Switch;\r\n }\r\n\r\n return DeviceType.Generic;\r\n }\r\n\r\n /**\r\n * Get DeviceType from a given pointer/mouse/touch event.\r\n * @param evt PointerEvent to evaluate\r\n * @returns DeviceType interpreted from event\r\n */\r\n private _getPointerType(evt: any): DeviceType {\r\n let deviceType = DeviceType.Mouse;\r\n\r\n if (evt.pointerType === \"touch\" || evt.pointerType === \"pen\" || evt.touches) {\r\n deviceType = DeviceType.Touch;\r\n }\r\n\r\n return deviceType;\r\n }\r\n}\r\n","import type { DeviceType } from \"./deviceEnums\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { DeviceInput } from \"./deviceTypes\";\r\nimport type { IDeviceInputSystem } from \"../inputInterfaces\";\r\nimport type { IKeyboardEvent, IPointerEvent, IWheelEvent } from \"../../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Subset of DeviceInput that only handles pointers and keyboard\r\n */\r\nexport type DeviceSourceEvent = T extends DeviceType.Keyboard\r\n ? IKeyboardEvent\r\n : T extends DeviceType.Mouse\r\n ? IWheelEvent | IPointerEvent\r\n : T extends DeviceType.Touch\r\n ? IPointerEvent\r\n : never;\r\n\r\n/**\r\n * Class that handles all input for a specific device\r\n */\r\nexport class DeviceSource {\r\n // Public Members\r\n /**\r\n * Observable to handle device input changes per device\r\n */\r\n public readonly onInputChangedObservable = new Observable>();\r\n\r\n // Private Members\r\n private readonly _deviceInputSystem: IDeviceInputSystem;\r\n\r\n /**\r\n * Default Constructor\r\n * @param deviceInputSystem - Reference to DeviceInputSystem\r\n * @param deviceType - Type of device\r\n * @param deviceSlot - \"Slot\" or index that device is referenced in\r\n */\r\n constructor(\r\n deviceInputSystem: IDeviceInputSystem,\r\n /** Type of device */\r\n public readonly deviceType: T,\r\n /** \"Slot\" or index that device is referenced in */\r\n public readonly deviceSlot: number = 0\r\n ) {\r\n this._deviceInputSystem = deviceInputSystem;\r\n }\r\n\r\n /**\r\n * Get input for specific input\r\n * @param inputIndex - index of specific input on device\r\n * @returns Input value from DeviceInputSystem\r\n */\r\n public getInput(inputIndex: DeviceInput): number {\r\n return this._deviceInputSystem.pollInput(this.deviceType, this.deviceSlot, inputIndex);\r\n }\r\n}\r\n","import type { IDisposable } from \"../scene\";\r\nimport { DeviceType } from \"./InputDevices/deviceEnums\";\r\nimport type { Observable } from \"../Misc/observable\";\r\nimport type { IDeviceInputSystem } from \"./inputInterfaces\";\r\nimport { NativeDeviceInputSystem } from \"./nativeDeviceInputSystem\";\r\nimport { WebDeviceInputSystem } from \"./webDeviceInputSystem\";\r\nimport { DeviceSource } from \"./InputDevices/deviceSource\";\r\nimport type { INative } from \"../Engines/Native/nativeInterfaces\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { IUIEvent } from \"../Events/deviceInputEvents\";\r\n\r\ntype Distribute = T extends DeviceType ? DeviceSource : never;\r\n\r\nexport type DeviceSourceType = Distribute;\r\n\r\ndeclare const _native: INative;\r\n\r\ndeclare module \"../Engines/engine\" {\r\n interface Engine {\r\n /** @internal */\r\n _deviceSourceManager?: InternalDeviceSourceManager;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport interface IObservableManager {\r\n onDeviceConnectedObservable: Observable;\r\n onDeviceDisconnectedObservable: Observable;\r\n\r\n // Functions\r\n _onInputChanged(deviceType: DeviceType, deviceSlot: number, eventData: IUIEvent): void;\r\n _addDevice(deviceSource: DeviceSource): void;\r\n _removeDevice(deviceType: DeviceType, deviceSlot: number): void;\r\n}\r\n\r\n/** @internal */\r\nexport class InternalDeviceSourceManager implements IDisposable {\r\n // Public Members\r\n public readonly _deviceInputSystem: IDeviceInputSystem;\r\n\r\n // Private Members\r\n // This is a master list of all device type/slot combos\r\n private readonly _devices: Array>;\r\n\r\n private readonly _registeredManagers = new Array();\r\n\r\n public _refCount = 0;\r\n\r\n public constructor(engine: Engine) {\r\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\r\n this._devices = new Array>(numberOfDeviceTypes);\r\n\r\n const onDeviceConnected = (deviceType: DeviceType, deviceSlot: number) => {\r\n if (!this._devices[deviceType]) {\r\n this._devices[deviceType] = new Array();\r\n }\r\n\r\n if (!this._devices[deviceType][deviceSlot]) {\r\n this._devices[deviceType][deviceSlot] = deviceSlot;\r\n }\r\n for (const manager of this._registeredManagers) {\r\n const deviceSource = new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot);\r\n manager._addDevice(deviceSource);\r\n }\r\n };\r\n\r\n const onDeviceDisconnected = (deviceType: DeviceType, deviceSlot: number) => {\r\n if (this._devices[deviceType]?.[deviceSlot]) {\r\n delete this._devices[deviceType][deviceSlot];\r\n }\r\n for (const manager of this._registeredManagers) {\r\n manager._removeDevice(deviceType, deviceSlot);\r\n }\r\n };\r\n\r\n const onInputChanged = (deviceType: DeviceType, deviceSlot: number, eventData: IUIEvent) => {\r\n if (eventData) {\r\n for (const manager of this._registeredManagers) {\r\n manager._onInputChanged(deviceType, deviceSlot, eventData);\r\n }\r\n }\r\n };\r\n\r\n if (typeof _native !== \"undefined\") {\r\n this._deviceInputSystem = new NativeDeviceInputSystem(onDeviceConnected, onDeviceDisconnected, onInputChanged);\r\n } else {\r\n this._deviceInputSystem = new WebDeviceInputSystem(engine, onDeviceConnected, onDeviceDisconnected, onInputChanged);\r\n }\r\n }\r\n\r\n // Public Functions\r\n public readonly registerManager = (manager: IObservableManager): void => {\r\n for (let deviceType = 0; deviceType < this._devices.length; deviceType++) {\r\n const device = this._devices[deviceType];\r\n for (const deviceSlotKey in device) {\r\n const deviceSlot = +deviceSlotKey;\r\n manager._addDevice(new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot));\r\n }\r\n }\r\n this._registeredManagers.push(manager);\r\n };\r\n\r\n public readonly unregisterManager = (manager: IObservableManager): void => {\r\n const idx = this._registeredManagers.indexOf(manager);\r\n\r\n if (idx > -1) {\r\n this._registeredManagers.splice(idx, 1);\r\n }\r\n };\r\n\r\n public dispose(): void {\r\n this._deviceInputSystem.dispose();\r\n }\r\n}\r\n","import type { Engine } from \"../../Engines/engine\";\r\nimport { DeviceType } from \"./deviceEnums\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { DeviceSource } from \"./deviceSource\";\r\nimport type { IObservableManager, DeviceSourceType } from \"../internalDeviceSourceManager\";\r\nimport { InternalDeviceSourceManager } from \"../internalDeviceSourceManager\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { IKeyboardEvent, IPointerEvent, IUIEvent, IWheelEvent } from \"../../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Class to keep track of devices\r\n */\r\nexport class DeviceSourceManager implements IDisposable, IObservableManager {\r\n // Public Members\r\n /**\r\n * Observable to be triggered when after a device is connected, any new observers added will be triggered against already connected devices\r\n */\r\n public readonly onDeviceConnectedObservable: Observable;\r\n\r\n /**\r\n * Observable to be triggered when after a device is disconnected\r\n */\r\n public readonly onDeviceDisconnectedObservable: Observable;\r\n\r\n // Private Members\r\n private _engine: Engine;\r\n private _onDisposeObserver: Nullable>;\r\n private readonly _devices: Array>>;\r\n private readonly _firstDevice: Array;\r\n\r\n // Public Functions\r\n /**\r\n * Gets a DeviceSource, given a type and slot\r\n * @param deviceType - Type of Device\r\n * @param deviceSlot - Slot or ID of device\r\n * @returns DeviceSource\r\n */\r\n public getDeviceSource(deviceType: T, deviceSlot?: number): Nullable> {\r\n if (deviceSlot === undefined) {\r\n if (this._firstDevice[deviceType] === undefined) {\r\n return null;\r\n }\r\n\r\n deviceSlot = this._firstDevice[deviceType];\r\n }\r\n\r\n if (!this._devices[deviceType] || this._devices[deviceType][deviceSlot] === undefined) {\r\n return null;\r\n }\r\n\r\n return this._devices[deviceType][deviceSlot] as DeviceSource;\r\n }\r\n /**\r\n * Gets an array of DeviceSource objects for a given device type\r\n * @param deviceType - Type of Device\r\n * @returns All available DeviceSources of a given type\r\n */\r\n public getDeviceSources(deviceType: T): ReadonlyArray> {\r\n // If device type hasn't had any devices connected yet, return empty array.\r\n if (!this._devices[deviceType]) {\r\n return [];\r\n }\r\n return this._devices[deviceType].filter((source) => {\r\n return !!source;\r\n }) as Array>;\r\n }\r\n\r\n /**\r\n * Default constructor\r\n * @param engine - Used to get canvas (if applicable)\r\n */\r\n constructor(engine: Engine) {\r\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\r\n this._devices = new Array(numberOfDeviceTypes);\r\n this._firstDevice = new Array(numberOfDeviceTypes);\r\n this._engine = engine;\r\n\r\n if (!this._engine._deviceSourceManager) {\r\n this._engine._deviceSourceManager = new InternalDeviceSourceManager(engine);\r\n }\r\n this._engine._deviceSourceManager._refCount++;\r\n\r\n // Observables\r\n this.onDeviceConnectedObservable = new Observable((observer) => {\r\n for (const devices of this._devices) {\r\n if (devices) {\r\n for (const device of devices) {\r\n if (device) {\r\n this.onDeviceConnectedObservable.notifyObserver(observer, device as DeviceSourceType);\r\n }\r\n }\r\n }\r\n }\r\n });\r\n this.onDeviceDisconnectedObservable = new Observable();\r\n\r\n this._engine._deviceSourceManager.registerManager(this);\r\n\r\n this._onDisposeObserver = engine.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Dispose of DeviceSourceManager\r\n */\r\n public dispose(): void {\r\n // Null out observable refs\r\n this.onDeviceConnectedObservable.clear();\r\n this.onDeviceDisconnectedObservable.clear();\r\n\r\n if (this._engine._deviceSourceManager) {\r\n this._engine._deviceSourceManager.unregisterManager(this);\r\n if (--this._engine._deviceSourceManager._refCount < 1) {\r\n this._engine._deviceSourceManager.dispose();\r\n delete this._engine._deviceSourceManager;\r\n }\r\n }\r\n this._engine.onDisposeObservable.remove(this._onDisposeObserver);\r\n }\r\n\r\n // Hidden Functions\r\n /**\r\n * @param deviceSource - Source to add\r\n * @internal\r\n */\r\n public _addDevice(deviceSource: DeviceSourceType): void {\r\n if (!this._devices[deviceSource.deviceType]) {\r\n this._devices[deviceSource.deviceType] = new Array();\r\n }\r\n\r\n if (!this._devices[deviceSource.deviceType][deviceSource.deviceSlot]) {\r\n this._devices[deviceSource.deviceType][deviceSource.deviceSlot] = deviceSource;\r\n this._updateFirstDevices(deviceSource.deviceType);\r\n }\r\n\r\n this.onDeviceConnectedObservable.notifyObservers(deviceSource);\r\n }\r\n\r\n /**\r\n * @param deviceType - DeviceType\r\n * @param deviceSlot - DeviceSlot\r\n * @internal\r\n */\r\n public _removeDevice(deviceType: DeviceType, deviceSlot: number): void {\r\n const deviceSource = this._devices[deviceType]?.[deviceSlot]; // Grab local reference to use before removing from devices\r\n this.onDeviceDisconnectedObservable.notifyObservers(deviceSource as DeviceSourceType);\r\n if (this._devices[deviceType]?.[deviceSlot]) {\r\n delete this._devices[deviceType][deviceSlot];\r\n }\r\n // Even if we don't delete a device, we should still check for the first device as things may have gotten out of sync.\r\n this._updateFirstDevices(deviceType);\r\n }\r\n\r\n /**\r\n * @param deviceType - DeviceType\r\n * @param deviceSlot - DeviceSlot\r\n * @param eventData - Event\r\n * @internal\r\n */\r\n public _onInputChanged(deviceType: T, deviceSlot: number, eventData: IUIEvent): void {\r\n this._devices[deviceType]?.[deviceSlot]?.onInputChangedObservable.notifyObservers(eventData as IKeyboardEvent | IWheelEvent | IPointerEvent);\r\n }\r\n\r\n // Private Functions\r\n private _updateFirstDevices(type: DeviceType): void {\r\n switch (type) {\r\n case DeviceType.Keyboard:\r\n case DeviceType.Mouse:\r\n this._firstDevice[type] = 0;\r\n break;\r\n case DeviceType.Touch:\r\n case DeviceType.DualSense:\r\n case DeviceType.DualShock:\r\n case DeviceType.Xbox:\r\n case DeviceType.Switch:\r\n case DeviceType.Generic: {\r\n delete this._firstDevice[type];\r\n // eslint-disable-next-line no-case-declarations\r\n const devices = this._devices[type];\r\n if (devices) {\r\n for (let i = 0; i < devices.length; i++) {\r\n if (devices[i]) {\r\n this._firstDevice[type] = i;\r\n break;\r\n }\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n","import type { EventState, Observable, Observer } from \"../Misc/observable\";\r\nimport { PointerInfoPre, PointerInfo, PointerEventTypes } from \"../Events/pointerEvents\";\r\nimport type { Nullable } from \"../types\";\r\nimport { AbstractActionManager } from \"../Actions/abstractActionManager\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport { Vector2, Matrix } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { ActionEvent } from \"../Actions/actionEvent\";\r\nimport { KeyboardEventTypes, KeyboardInfoPre, KeyboardInfo } from \"../Events/keyboardEvents\";\r\nimport { DeviceType, PointerInput } from \"../DeviceInput/InputDevices/deviceEnums\";\r\nimport type { IKeyboardEvent, IMouseEvent, IPointerEvent } from \"../Events/deviceInputEvents\";\r\nimport { DeviceSourceManager } from \"../DeviceInput/InputDevices/deviceSourceManager\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nclass _ClickInfo {\r\n private _singleClick = false;\r\n private _doubleClick = false;\r\n private _hasSwiped = false;\r\n private _ignore = false;\r\n\r\n public get singleClick(): boolean {\r\n return this._singleClick;\r\n }\r\n public get doubleClick(): boolean {\r\n return this._doubleClick;\r\n }\r\n public get hasSwiped(): boolean {\r\n return this._hasSwiped;\r\n }\r\n public get ignore(): boolean {\r\n return this._ignore;\r\n }\r\n\r\n public set singleClick(b: boolean) {\r\n this._singleClick = b;\r\n }\r\n public set doubleClick(b: boolean) {\r\n this._doubleClick = b;\r\n }\r\n public set hasSwiped(b: boolean) {\r\n this._hasSwiped = b;\r\n }\r\n public set ignore(b: boolean) {\r\n this._ignore = b;\r\n }\r\n}\r\n\r\n/** @internal */\r\ninterface _IClickEvent {\r\n clickInfo: _ClickInfo;\r\n evt: IPointerEvent;\r\n timeoutId: number;\r\n}\r\n\r\n/**\r\n * Class used to manage all inputs for the scene.\r\n */\r\nexport class InputManager {\r\n /** The distance in pixel that you have to move to prevent some events */\r\n public static DragMovementThreshold = 10; // in pixels\r\n /** Time in milliseconds to wait to raise long press events if button is still pressed */\r\n public static LongPressDelay = 500; // in milliseconds\r\n /** Time in milliseconds with two consecutive clicks will be considered as a double click */\r\n public static DoubleClickDelay = 300; // in milliseconds\r\n /**\r\n * This flag will modify the behavior so that, when true, a click will happen if and only if\r\n * another click DOES NOT happen within the DoubleClickDelay time frame. If another click does\r\n * happen within that time frame, the first click will not fire an event and and a double click will occur.\r\n */\r\n public static ExclusiveDoubleClickMode = false;\r\n\r\n /** This is a defensive check to not allow control attachment prior to an already active one. If already attached, previous control is unattached before attaching the new one. */\r\n private _alreadyAttached = false;\r\n private _alreadyAttachedTo: Nullable;\r\n\r\n // Pointers\r\n private _onPointerMove: (evt: IMouseEvent) => void;\r\n private _onPointerDown: (evt: IPointerEvent) => void;\r\n private _onPointerUp: (evt: IPointerEvent) => void;\r\n\r\n private _initClickEvent: (\r\n obs1: Observable,\r\n obs2: Observable,\r\n evt: IPointerEvent,\r\n cb: (clickInfo: _ClickInfo, pickResult: Nullable) => void\r\n ) => void;\r\n private _initActionManager: (act: Nullable, clickInfo: _ClickInfo) => Nullable;\r\n private _delayedSimpleClick: (btn: number, clickInfo: _ClickInfo, cb: (clickInfo: _ClickInfo, pickResult: Nullable) => void) => void;\r\n private _meshPickProceed = false;\r\n\r\n private _previousButtonPressed: number;\r\n private _currentPickResult: Nullable = null;\r\n private _previousPickResult: Nullable = null;\r\n private _totalPointersPressed = 0;\r\n private _doubleClickOccured = false;\r\n private _isSwiping: boolean = false;\r\n private _swipeButtonPressed: number = -1;\r\n private _skipPointerTap: boolean = false;\r\n private _isMultiTouchGesture: boolean = false;\r\n\r\n private _pointerOverMesh: Nullable;\r\n\r\n private _pickedDownMesh: Nullable;\r\n private _pickedUpMesh: Nullable;\r\n\r\n private _pointerX: number = 0;\r\n private _pointerY: number = 0;\r\n private _unTranslatedPointerX: number;\r\n private _unTranslatedPointerY: number;\r\n private _startingPointerPosition = new Vector2(0, 0);\r\n private _previousStartingPointerPosition = new Vector2(0, 0);\r\n private _startingPointerTime = 0;\r\n private _previousStartingPointerTime = 0;\r\n private _pointerCaptures: { [pointerId: number]: boolean } = {};\r\n private _meshUnderPointerId: { [pointerId: number]: Nullable } = {};\r\n private _movePointerInfo: Nullable = null;\r\n private _cameraObserverCount = 0;\r\n private _delayedClicks: Array> = [null, null, null, null, null];\r\n\r\n // Keyboard\r\n private _onKeyDown: (evt: IKeyboardEvent) => void;\r\n private _onKeyUp: (evt: IKeyboardEvent) => void;\r\n\r\n private _scene: Scene;\r\n private _deviceSourceManager: Nullable = null;\r\n\r\n /**\r\n * Creates a new InputManager\r\n * @param scene - defines the hosting scene\r\n */\r\n constructor(scene?: Scene) {\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n if (!this._scene) {\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the mesh that is currently under the pointer\r\n * @returns Mesh that the pointer is pointer is hovering over\r\n */\r\n public get meshUnderPointer(): Nullable {\r\n if (this._movePointerInfo) {\r\n // Because _pointerOverMesh is populated as part of _pickMove, we need to force a pick to update it.\r\n // Calling _pickMove calls _setCursorAndPointerOverMesh which calls setPointerOverMesh\r\n this._movePointerInfo._generatePickInfo();\r\n // Once we have what we need, we can clear _movePointerInfo because we don't need it anymore\r\n this._movePointerInfo = null;\r\n }\r\n return this._pointerOverMesh;\r\n }\r\n\r\n /**\r\n * When using more than one pointer (for example in XR) you can get the mesh under the specific pointer\r\n * @param pointerId - the pointer id to use\r\n * @returns The mesh under this pointer id or null if not found\r\n */\r\n public getMeshUnderPointerByPointerId(pointerId: number): Nullable {\r\n return this._meshUnderPointerId[pointerId] || null;\r\n }\r\n\r\n /**\r\n * Gets the pointer coordinates in 2D without any translation (ie. straight out of the pointer event)\r\n * @returns Vector with X/Y values directly from pointer event\r\n */\r\n public get unTranslatedPointer(): Vector2 {\r\n return new Vector2(this._unTranslatedPointerX, this._unTranslatedPointerY);\r\n }\r\n\r\n /**\r\n * Gets or sets the current on-screen X position of the pointer\r\n * @returns Translated X with respect to screen\r\n */\r\n public get pointerX(): number {\r\n return this._pointerX;\r\n }\r\n\r\n public set pointerX(value: number) {\r\n this._pointerX = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the current on-screen Y position of the pointer\r\n * @returns Translated Y with respect to screen\r\n */\r\n public get pointerY(): number {\r\n return this._pointerY;\r\n }\r\n\r\n public set pointerY(value: number) {\r\n this._pointerY = value;\r\n }\r\n\r\n private _updatePointerPosition(evt: IPointerEvent): void {\r\n const canvasRect = this._scene.getEngine().getInputElementClientRect();\r\n\r\n if (!canvasRect) {\r\n return;\r\n }\r\n\r\n this._pointerX = evt.clientX - canvasRect.left;\r\n this._pointerY = evt.clientY - canvasRect.top;\r\n\r\n this._unTranslatedPointerX = this._pointerX;\r\n this._unTranslatedPointerY = this._pointerY;\r\n }\r\n\r\n private _processPointerMove(pickResult: Nullable, evt: IPointerEvent) {\r\n const scene = this._scene;\r\n const engine = scene.getEngine();\r\n const canvas = engine.getInputElement();\r\n\r\n if (canvas) {\r\n canvas.tabIndex = engine.canvasTabIndex;\r\n\r\n // Restore pointer\r\n if (!scene.doNotHandleCursors) {\r\n canvas.style.cursor = scene.defaultCursor;\r\n }\r\n }\r\n\r\n this._setCursorAndPointerOverMesh(pickResult, evt, scene);\r\n\r\n for (const step of scene._pointerMoveStage) {\r\n // If _pointerMoveState is defined, we have an active spriteManager and can't use Lazy Picking\r\n // Therefore, we need to force a pick to update the pickResult\r\n pickResult = pickResult || this._pickMove(evt);\r\n const isMeshPicked = pickResult?.pickedMesh ? true : false;\r\n pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, isMeshPicked, canvas);\r\n }\r\n\r\n const type = evt.inputIndex >= PointerInput.MouseWheelX && evt.inputIndex <= PointerInput.MouseWheelZ ? PointerEventTypes.POINTERWHEEL : PointerEventTypes.POINTERMOVE;\r\n\r\n if (scene.onPointerMove) {\r\n // Because of lazy picking, we need to force a pick to update the pickResult\r\n pickResult = pickResult || this._pickMove(evt);\r\n scene.onPointerMove(evt, pickResult, type);\r\n }\r\n\r\n let pointerInfo: PointerInfo;\r\n if (pickResult) {\r\n pointerInfo = new PointerInfo(type, evt, pickResult);\r\n this._setRayOnPointerInfo(pickResult, evt);\r\n } else {\r\n pointerInfo = new PointerInfo(type, evt, null, this);\r\n this._movePointerInfo = pointerInfo;\r\n }\r\n\r\n if (scene.onPointerObservable.hasObservers()) {\r\n scene.onPointerObservable.notifyObservers(pointerInfo, type);\r\n }\r\n }\r\n\r\n // Pointers handling\r\n /** @internal */\r\n public _setRayOnPointerInfo(pickInfo: Nullable, event: IMouseEvent) {\r\n const scene = this._scene;\r\n if (pickInfo && scene._pickingAvailable) {\r\n if (!pickInfo.ray) {\r\n pickInfo.ray = scene.createPickingRay(event.offsetX, event.offsetY, Matrix.Identity(), scene.activeCamera);\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _addCameraPointerObserver(observer: (p: PointerInfo, s: EventState) => void, mask?: number): Nullable> {\r\n this._cameraObserverCount++;\r\n return this._scene.onPointerObservable.add(observer, mask);\r\n }\r\n\r\n /** @internal */\r\n public _removeCameraPointerObserver(observer: Observer): boolean {\r\n this._cameraObserverCount--;\r\n return this._scene.onPointerObservable.remove(observer);\r\n }\r\n\r\n private _checkForPicking(): boolean {\r\n return !!(this._scene.onPointerObservable.observers.length > this._cameraObserverCount || this._scene.onPointerPick);\r\n }\r\n\r\n private _checkPrePointerObservable(pickResult: Nullable, evt: IPointerEvent, type: number) {\r\n const scene = this._scene;\r\n const pi = new PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);\r\n if (pickResult) {\r\n pi.originalPickingInfo = pickResult;\r\n pi.ray = pickResult.ray;\r\n if (pickResult.originMesh) {\r\n pi.nearInteractionPickingInfo = pickResult;\r\n }\r\n }\r\n\r\n scene.onPrePointerObservable.notifyObservers(pi, type);\r\n if (pi.skipOnPointerObservable) {\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _pickMove(evt: IPointerEvent): PickingInfo {\r\n const scene = this._scene;\r\n const pickResult = scene.pick(\r\n this._unTranslatedPointerX,\r\n this._unTranslatedPointerY,\r\n scene.pointerMovePredicate,\r\n scene.pointerMoveFastCheck,\r\n scene.cameraToUseForPointers,\r\n scene.pointerMoveTrianglePredicate\r\n );\r\n\r\n this._setCursorAndPointerOverMesh(pickResult, evt, scene);\r\n\r\n return pickResult;\r\n }\r\n\r\n private _setCursorAndPointerOverMesh(pickResult: Nullable, evt: IPointerEvent, scene: Scene) {\r\n const engine = scene.getEngine();\r\n const canvas = engine.getInputElement();\r\n\r\n if (pickResult?.pickedMesh) {\r\n this.setPointerOverMesh(pickResult.pickedMesh, evt.pointerId, pickResult, evt);\r\n\r\n if (!scene.doNotHandleCursors && canvas && this._pointerOverMesh) {\r\n const actionManager = this._pointerOverMesh._getActionManagerForTrigger();\r\n if (actionManager && actionManager.hasPointerTriggers) {\r\n canvas.style.cursor = actionManager.hoverCursor || scene.hoverCursor;\r\n }\r\n }\r\n } else {\r\n this.setPointerOverMesh(null, evt.pointerId, pickResult, evt);\r\n }\r\n }\r\n\r\n /**\r\n * Use this method to simulate a pointer move on a mesh\r\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\r\n * @param pickResult - pickingInfo of the object wished to simulate pointer event on\r\n * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\r\n */\r\n public simulatePointerMove(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): void {\r\n const evt = new PointerEvent(\"pointermove\", pointerEventInit);\r\n evt.inputIndex = PointerInput.Move;\r\n\r\n if (this._checkPrePointerObservable(pickResult, evt, PointerEventTypes.POINTERMOVE)) {\r\n return;\r\n }\r\n this._processPointerMove(pickResult, evt);\r\n }\r\n\r\n /**\r\n * Use this method to simulate a pointer down on a mesh\r\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\r\n * @param pickResult - pickingInfo of the object wished to simulate pointer event on\r\n * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\r\n */\r\n public simulatePointerDown(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): void {\r\n const evt = new PointerEvent(\"pointerdown\", pointerEventInit);\r\n evt.inputIndex = evt.button + 2;\r\n\r\n if (this._checkPrePointerObservable(pickResult, evt, PointerEventTypes.POINTERDOWN)) {\r\n return;\r\n }\r\n\r\n this._processPointerDown(pickResult, evt);\r\n }\r\n\r\n private _processPointerDown(pickResult: Nullable, evt: IPointerEvent): void {\r\n const scene = this._scene;\r\n if (pickResult?.pickedMesh) {\r\n this._pickedDownMesh = pickResult.pickedMesh;\r\n const actionManager = pickResult.pickedMesh._getActionManagerForTrigger();\r\n if (actionManager) {\r\n if (actionManager.hasPickTriggers) {\r\n actionManager.processTrigger(Constants.ACTION_OnPickDownTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n switch (evt.button) {\r\n case 0:\r\n actionManager.processTrigger(Constants.ACTION_OnLeftPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n break;\r\n case 1:\r\n actionManager.processTrigger(Constants.ACTION_OnCenterPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n break;\r\n case 2:\r\n actionManager.processTrigger(Constants.ACTION_OnRightPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n break;\r\n }\r\n }\r\n\r\n if (actionManager.hasSpecificTrigger(Constants.ACTION_OnLongPressTrigger)) {\r\n window.setTimeout(() => {\r\n const pickResult = scene.pick(\r\n this._unTranslatedPointerX,\r\n this._unTranslatedPointerY,\r\n (mesh: AbstractMesh): boolean =>\r\n (\r\n (mesh.isPickable &&\r\n mesh.isVisible &&\r\n mesh.isReady() &&\r\n mesh.actionManager &&\r\n mesh.actionManager.hasSpecificTrigger(Constants.ACTION_OnLongPressTrigger) &&\r\n mesh === this._pickedDownMesh)\r\n ),\r\n false,\r\n scene.cameraToUseForPointers\r\n );\r\n\r\n if (pickResult?.pickedMesh && actionManager) {\r\n if (this._totalPointersPressed !== 0 && Date.now() - this._startingPointerTime > InputManager.LongPressDelay && !this._isPointerSwiping()) {\r\n this._startingPointerTime = 0;\r\n actionManager.processTrigger(Constants.ACTION_OnLongPressTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt));\r\n }\r\n }\r\n }, InputManager.LongPressDelay);\r\n }\r\n }\r\n } else {\r\n for (const step of scene._pointerDownStage) {\r\n pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt, false);\r\n }\r\n }\r\n\r\n let pointerInfo: PointerInfo;\r\n const type = PointerEventTypes.POINTERDOWN;\r\n\r\n if (pickResult) {\r\n if (scene.onPointerDown) {\r\n scene.onPointerDown(evt, pickResult, type);\r\n }\r\n\r\n pointerInfo = new PointerInfo(type, evt, pickResult);\r\n this._setRayOnPointerInfo(pickResult, evt);\r\n } else {\r\n pointerInfo = new PointerInfo(type, evt, null, this);\r\n }\r\n\r\n if (scene.onPointerObservable.hasObservers()) {\r\n scene.onPointerObservable.notifyObservers(pointerInfo, type);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * @internals Boolean if delta for pointer exceeds drag movement threshold\r\n */\r\n public _isPointerSwiping(): boolean {\r\n return this._isSwiping;\r\n }\r\n\r\n /**\r\n * Use this method to simulate a pointer up on a mesh\r\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\r\n * @param pickResult - pickingInfo of the object wished to simulate pointer event on\r\n * @param pointerEventInit - pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\r\n * @param doubleTap - indicates that the pointer up event should be considered as part of a double click (false by default)\r\n */\r\n public simulatePointerUp(pickResult: PickingInfo, pointerEventInit?: PointerEventInit, doubleTap?: boolean): void {\r\n const evt = new PointerEvent(\"pointerup\", pointerEventInit);\r\n evt.inputIndex = PointerInput.Move;\r\n const clickInfo = new _ClickInfo();\r\n\r\n if (doubleTap) {\r\n clickInfo.doubleClick = true;\r\n } else {\r\n clickInfo.singleClick = true;\r\n }\r\n\r\n if (this._checkPrePointerObservable(pickResult, evt, PointerEventTypes.POINTERUP)) {\r\n return;\r\n }\r\n\r\n this._processPointerUp(pickResult, evt, clickInfo);\r\n }\r\n\r\n private _processPointerUp(pickResult: Nullable, evt: IPointerEvent, clickInfo: _ClickInfo): void {\r\n const scene = this._scene;\r\n if (pickResult?.pickedMesh) {\r\n this._pickedUpMesh = pickResult.pickedMesh;\r\n if (this._pickedDownMesh === this._pickedUpMesh) {\r\n if (scene.onPointerPick) {\r\n scene.onPointerPick(evt, pickResult);\r\n }\r\n if (clickInfo.singleClick && !clickInfo.ignore && scene.onPointerObservable.observers.length > this._cameraObserverCount) {\r\n const type = PointerEventTypes.POINTERPICK;\r\n const pi = new PointerInfo(type, evt, pickResult);\r\n this._setRayOnPointerInfo(pickResult, evt);\r\n scene.onPointerObservable.notifyObservers(pi, type);\r\n }\r\n }\r\n const actionManager = pickResult.pickedMesh._getActionManagerForTrigger();\r\n if (actionManager && !clickInfo.ignore) {\r\n actionManager.processTrigger(Constants.ACTION_OnPickUpTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n\r\n if (!clickInfo.hasSwiped && clickInfo.singleClick) {\r\n actionManager.processTrigger(Constants.ACTION_OnPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n }\r\n\r\n const doubleClickActionManager = pickResult.pickedMesh._getActionManagerForTrigger(Constants.ACTION_OnDoublePickTrigger);\r\n if (clickInfo.doubleClick && doubleClickActionManager) {\r\n doubleClickActionManager.processTrigger(Constants.ACTION_OnDoublePickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt, pickResult));\r\n }\r\n }\r\n } else {\r\n if (!clickInfo.ignore) {\r\n for (const step of scene._pointerUpStage) {\r\n pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt, clickInfo.doubleClick);\r\n }\r\n }\r\n }\r\n\r\n if (this._pickedDownMesh && this._pickedDownMesh !== this._pickedUpMesh) {\r\n const pickedDownActionManager = this._pickedDownMesh._getActionManagerForTrigger(Constants.ACTION_OnPickOutTrigger);\r\n if (pickedDownActionManager) {\r\n pickedDownActionManager.processTrigger(Constants.ACTION_OnPickOutTrigger, ActionEvent.CreateNew(this._pickedDownMesh, evt));\r\n }\r\n }\r\n\r\n if (!clickInfo.ignore) {\r\n const pi = new PointerInfo(PointerEventTypes.POINTERUP, evt, pickResult);\r\n // Set ray on picking info. Note that this info will also be reused for the tap notification.\r\n this._setRayOnPointerInfo(pickResult, evt);\r\n scene.onPointerObservable.notifyObservers(pi, PointerEventTypes.POINTERUP);\r\n\r\n if (scene.onPointerUp) {\r\n scene.onPointerUp(evt, pickResult, PointerEventTypes.POINTERUP);\r\n }\r\n\r\n if (!clickInfo.hasSwiped && !this._skipPointerTap && !this._isMultiTouchGesture) {\r\n let type = 0;\r\n if (clickInfo.singleClick) {\r\n type = PointerEventTypes.POINTERTAP;\r\n } else if (clickInfo.doubleClick) {\r\n type = PointerEventTypes.POINTERDOUBLETAP;\r\n }\r\n\r\n if (type) {\r\n const pi = new PointerInfo(type, evt, pickResult);\r\n if (scene.onPointerObservable.hasObservers() && scene.onPointerObservable.hasSpecificMask(type)) {\r\n scene.onPointerObservable.notifyObservers(pi, type);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the current pointer event is captured (meaning that the scene has already handled the pointer down)\r\n * @param pointerId - defines the pointer id to use in a multi-touch scenario (0 by default)\r\n * @returns true if the pointer was captured\r\n */\r\n public isPointerCaptured(pointerId = 0): boolean {\r\n return this._pointerCaptures[pointerId];\r\n }\r\n\r\n /**\r\n * Attach events to the canvas (To handle actionManagers triggers and raise onPointerMove, onPointerDown and onPointerUp\r\n * @param attachUp - defines if you want to attach events to pointerup\r\n * @param attachDown - defines if you want to attach events to pointerdown\r\n * @param attachMove - defines if you want to attach events to pointermove\r\n * @param elementToAttachTo - defines the target DOM element to attach to (will use the canvas by default)\r\n */\r\n public attachControl(attachUp = true, attachDown = true, attachMove = true, elementToAttachTo: Nullable = null): void {\r\n const scene = this._scene;\r\n const engine = scene.getEngine();\r\n\r\n if (!elementToAttachTo) {\r\n elementToAttachTo = engine.getInputElement();\r\n }\r\n\r\n if (this._alreadyAttached) {\r\n this.detachControl();\r\n }\r\n\r\n if (elementToAttachTo) {\r\n this._alreadyAttachedTo = elementToAttachTo;\r\n }\r\n this._deviceSourceManager = new DeviceSourceManager(engine);\r\n\r\n // Because this is only called from _initClickEvent, which is called in _onPointerUp, we'll use the pointerUpPredicate for the pick call\r\n this._initActionManager = (act: Nullable): Nullable => {\r\n if (!this._meshPickProceed) {\r\n const pickResult =\r\n scene.skipPointerUpPicking || (scene._registeredActions === 0 && !this._checkForPicking() && !scene.onPointerUp)\r\n ? null\r\n : scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerUpPredicate, scene.pointerUpFastCheck, scene.cameraToUseForPointers);\r\n this._currentPickResult = pickResult;\r\n if (pickResult) {\r\n act = pickResult.hit && pickResult.pickedMesh ? pickResult.pickedMesh._getActionManagerForTrigger() : null;\r\n }\r\n this._meshPickProceed = true;\r\n }\r\n return act;\r\n };\r\n\r\n this._delayedSimpleClick = (btn: number, clickInfo: _ClickInfo, cb: (clickInfo: _ClickInfo, pickResult: Nullable) => void) => {\r\n // double click delay is over and that no double click has been raised since, or the 2 consecutive keys pressed are different\r\n if ((Date.now() - this._previousStartingPointerTime > InputManager.DoubleClickDelay && !this._doubleClickOccured) || btn !== this._previousButtonPressed) {\r\n this._doubleClickOccured = false;\r\n clickInfo.singleClick = true;\r\n clickInfo.ignore = false;\r\n\r\n // If we have a delayed click, we need to resolve the TAP event\r\n if (this._delayedClicks[btn]) {\r\n const evt = this._delayedClicks[btn]!.evt;\r\n const type = PointerEventTypes.POINTERTAP;\r\n const pi = new PointerInfo(type, evt, this._currentPickResult);\r\n if (scene.onPointerObservable.hasObservers() && scene.onPointerObservable.hasSpecificMask(type)) {\r\n scene.onPointerObservable.notifyObservers(pi, type);\r\n }\r\n\r\n // Clear the delayed click\r\n this._delayedClicks[btn] = null;\r\n }\r\n }\r\n };\r\n\r\n this._initClickEvent = (\r\n obs1: Observable,\r\n obs2: Observable,\r\n evt: IPointerEvent,\r\n cb: (clickInfo: _ClickInfo, pickResult: Nullable) => void\r\n ): void => {\r\n const clickInfo = new _ClickInfo();\r\n this._currentPickResult = null;\r\n let act: Nullable = null;\r\n\r\n let checkPicking =\r\n obs1.hasSpecificMask(PointerEventTypes.POINTERPICK) ||\r\n obs2.hasSpecificMask(PointerEventTypes.POINTERPICK) ||\r\n obs1.hasSpecificMask(PointerEventTypes.POINTERTAP) ||\r\n obs2.hasSpecificMask(PointerEventTypes.POINTERTAP) ||\r\n obs1.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP) ||\r\n obs2.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP);\r\n if (!checkPicking && AbstractActionManager) {\r\n act = this._initActionManager(act, clickInfo);\r\n if (act) {\r\n checkPicking = act.hasPickTriggers;\r\n }\r\n }\r\n\r\n let needToIgnoreNext = false;\r\n\r\n if (checkPicking) {\r\n const btn = evt.button;\r\n clickInfo.hasSwiped = this._isPointerSwiping();\r\n\r\n if (!clickInfo.hasSwiped) {\r\n let checkSingleClickImmediately = !InputManager.ExclusiveDoubleClickMode;\r\n\r\n if (!checkSingleClickImmediately) {\r\n checkSingleClickImmediately = !obs1.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP) && !obs2.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP);\r\n\r\n if (checkSingleClickImmediately && !AbstractActionManager.HasSpecificTrigger(Constants.ACTION_OnDoublePickTrigger)) {\r\n act = this._initActionManager(act, clickInfo);\r\n if (act) {\r\n checkSingleClickImmediately = !act.hasSpecificTrigger(Constants.ACTION_OnDoublePickTrigger);\r\n }\r\n }\r\n }\r\n\r\n if (checkSingleClickImmediately) {\r\n // single click detected if double click delay is over or two different successive keys pressed without exclusive double click or no double click required\r\n if (Date.now() - this._previousStartingPointerTime > InputManager.DoubleClickDelay || btn !== this._previousButtonPressed) {\r\n clickInfo.singleClick = true;\r\n cb(clickInfo, this._currentPickResult);\r\n needToIgnoreNext = true;\r\n }\r\n }\r\n // at least one double click is required to be check and exclusive double click is enabled\r\n else {\r\n // Queue up a delayed click, just in case this isn't a double click\r\n // It should be noted that while this delayed event happens\r\n // because of user input, it shouldn't be considered as a direct,\r\n // timing-dependent result of that input. It's meant to just fire the TAP event\r\n const delayedClick = {\r\n evt: evt,\r\n clickInfo: clickInfo,\r\n timeoutId: window.setTimeout(this._delayedSimpleClick.bind(this, btn, clickInfo, cb), InputManager.DoubleClickDelay),\r\n };\r\n\r\n this._delayedClicks[btn] = delayedClick;\r\n }\r\n\r\n let checkDoubleClick = obs1.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP) || obs2.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP);\r\n if (!checkDoubleClick && AbstractActionManager.HasSpecificTrigger(Constants.ACTION_OnDoublePickTrigger)) {\r\n act = this._initActionManager(act, clickInfo);\r\n if (act) {\r\n checkDoubleClick = act.hasSpecificTrigger(Constants.ACTION_OnDoublePickTrigger);\r\n }\r\n }\r\n if (checkDoubleClick) {\r\n // two successive keys pressed are equal, double click delay is not over and double click has not just occurred\r\n if (btn === this._previousButtonPressed && Date.now() - this._previousStartingPointerTime < InputManager.DoubleClickDelay && !this._doubleClickOccured) {\r\n // pointer has not moved for 2 clicks, it's a double click\r\n if (!clickInfo.hasSwiped && !this._isPointerSwiping()) {\r\n this._previousStartingPointerTime = 0;\r\n this._doubleClickOccured = true;\r\n clickInfo.doubleClick = true;\r\n clickInfo.ignore = false;\r\n // If we have a pending click, we need to cancel it\r\n if (InputManager.ExclusiveDoubleClickMode && this._delayedClicks[btn]) {\r\n clearTimeout(this._delayedClicks[btn]?.timeoutId);\r\n this._delayedClicks[btn] = null;\r\n }\r\n\r\n cb(clickInfo, this._currentPickResult);\r\n }\r\n // if the two successive clicks are too far, it's just two simple clicks\r\n else {\r\n this._doubleClickOccured = false;\r\n this._previousStartingPointerTime = this._startingPointerTime;\r\n this._previousStartingPointerPosition.x = this._startingPointerPosition.x;\r\n this._previousStartingPointerPosition.y = this._startingPointerPosition.y;\r\n this._previousButtonPressed = btn;\r\n if (InputManager.ExclusiveDoubleClickMode) {\r\n // If we have a delayed click, we need to cancel it\r\n if (this._delayedClicks[btn]) {\r\n clearTimeout(this._delayedClicks[btn]?.timeoutId);\r\n this._delayedClicks[btn] = null;\r\n }\r\n cb(clickInfo, this._previousPickResult);\r\n } else {\r\n cb(clickInfo, this._currentPickResult);\r\n }\r\n }\r\n needToIgnoreNext = true;\r\n }\r\n // just the first click of the double has been raised\r\n else {\r\n this._doubleClickOccured = false;\r\n this._previousStartingPointerTime = this._startingPointerTime;\r\n this._previousStartingPointerPosition.x = this._startingPointerPosition.x;\r\n this._previousStartingPointerPosition.y = this._startingPointerPosition.y;\r\n this._previousButtonPressed = btn!;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Even if ExclusiveDoubleClickMode is true, we need to always handle\r\n // up events at time of execution, unless we're explicitly ignoring them.\r\n if (!needToIgnoreNext) {\r\n cb(clickInfo, this._currentPickResult);\r\n }\r\n };\r\n\r\n this._onPointerMove = (evt: IMouseEvent) => {\r\n this._updatePointerPosition(evt as IPointerEvent);\r\n\r\n // Check if pointer leaves DragMovementThreshold range to determine if swipe is occurring\r\n if (!this._isSwiping && this._swipeButtonPressed !== -1) {\r\n this._isSwiping =\r\n Math.abs(this._startingPointerPosition.x - this._pointerX) > InputManager.DragMovementThreshold ||\r\n Math.abs(this._startingPointerPosition.y - this._pointerY) > InputManager.DragMovementThreshold;\r\n }\r\n\r\n // Because there's a race condition between pointermove and pointerlockchange events, we need to\r\n // verify that the pointer is still locked after each pointermove event.\r\n if (engine.isPointerLock) {\r\n engine._verifyPointerLock();\r\n }\r\n\r\n // PreObservable support\r\n if (\r\n this._checkPrePointerObservable(\r\n null,\r\n evt as IPointerEvent,\r\n evt.inputIndex >= PointerInput.MouseWheelX && evt.inputIndex <= PointerInput.MouseWheelZ ? PointerEventTypes.POINTERWHEEL : PointerEventTypes.POINTERMOVE\r\n )\r\n ) {\r\n return;\r\n }\r\n\r\n if (!scene.cameraToUseForPointers && !scene.activeCamera) {\r\n return;\r\n }\r\n\r\n if (scene.skipPointerMovePicking) {\r\n this._processPointerMove(new PickingInfo(), evt as IPointerEvent);\r\n return;\r\n }\r\n\r\n if (!scene.pointerMovePredicate) {\r\n scene.pointerMovePredicate = (mesh: AbstractMesh): boolean =>\r\n mesh.isPickable &&\r\n mesh.isVisible &&\r\n mesh.isReady() &&\r\n mesh.isEnabled() &&\r\n (mesh.enablePointerMoveEvents || scene.constantlyUpdateMeshUnderPointer || mesh._getActionManagerForTrigger() !== null) &&\r\n (!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0);\r\n }\r\n\r\n const pickResult = scene._registeredActions > 0 || scene.constantlyUpdateMeshUnderPointer ? this._pickMove(evt as IPointerEvent) : null;\r\n this._processPointerMove(pickResult, evt as IPointerEvent);\r\n };\r\n\r\n this._onPointerDown = (evt: IPointerEvent) => {\r\n this._totalPointersPressed++;\r\n this._pickedDownMesh = null;\r\n this._meshPickProceed = false;\r\n\r\n // If ExclusiveDoubleClickMode is true, we need to resolve any pending delayed clicks\r\n if (InputManager.ExclusiveDoubleClickMode) {\r\n for (let i = 0; i < this._delayedClicks.length; i++) {\r\n if (this._delayedClicks[i]) {\r\n // If the button that was pressed is the same as the one that was released,\r\n // just clear the timer. This will be resolved in the up event.\r\n if (evt.button === i) {\r\n clearTimeout(this._delayedClicks[i]?.timeoutId);\r\n } else {\r\n // Otherwise, we need to resolve the click\r\n const clickInfo = this._delayedClicks[i]!.clickInfo;\r\n this._doubleClickOccured = false;\r\n clickInfo.singleClick = true;\r\n clickInfo.ignore = false;\r\n\r\n const prevEvt = this._delayedClicks[i]!.evt;\r\n const type = PointerEventTypes.POINTERTAP;\r\n const pi = new PointerInfo(type, prevEvt, this._currentPickResult);\r\n if (scene.onPointerObservable.hasObservers() && scene.onPointerObservable.hasSpecificMask(type)) {\r\n scene.onPointerObservable.notifyObservers(pi, type);\r\n }\r\n\r\n // Clear the delayed click\r\n this._delayedClicks[i] = null;\r\n }\r\n }\r\n }\r\n }\r\n\r\n this._updatePointerPosition(evt);\r\n\r\n if (this._swipeButtonPressed === -1) {\r\n this._swipeButtonPressed = evt.button;\r\n }\r\n\r\n if (scene.preventDefaultOnPointerDown && elementToAttachTo) {\r\n evt.preventDefault();\r\n elementToAttachTo.focus();\r\n }\r\n\r\n this._startingPointerPosition.x = this._pointerX;\r\n this._startingPointerPosition.y = this._pointerY;\r\n this._startingPointerTime = Date.now();\r\n\r\n // PreObservable support\r\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERDOWN)) {\r\n return;\r\n }\r\n\r\n if (!scene.cameraToUseForPointers && !scene.activeCamera) {\r\n return;\r\n }\r\n\r\n this._pointerCaptures[evt.pointerId] = true;\r\n\r\n if (!scene.pointerDownPredicate) {\r\n scene.pointerDownPredicate = (mesh: AbstractMesh): boolean => {\r\n return (\r\n mesh.isPickable &&\r\n mesh.isVisible &&\r\n mesh.isReady() &&\r\n mesh.isEnabled() &&\r\n (!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0)\r\n );\r\n };\r\n }\r\n\r\n // Meshes\r\n this._pickedDownMesh = null;\r\n let pickResult;\r\n if (scene.skipPointerDownPicking || (scene._registeredActions === 0 && !this._checkForPicking() && !scene.onPointerDown)) {\r\n pickResult = new PickingInfo();\r\n } else {\r\n pickResult = scene.pick(\r\n this._unTranslatedPointerX,\r\n this._unTranslatedPointerY,\r\n scene.pointerDownPredicate,\r\n scene.pointerDownFastCheck,\r\n scene.cameraToUseForPointers\r\n );\r\n }\r\n\r\n this._processPointerDown(pickResult, evt);\r\n };\r\n\r\n this._onPointerUp = (evt: IPointerEvent) => {\r\n if (this._totalPointersPressed === 0) {\r\n // We are attaching the pointer up to windows because of a bug in FF\r\n return; // So we need to test it the pointer down was pressed before.\r\n }\r\n\r\n this._totalPointersPressed--;\r\n this._pickedUpMesh = null;\r\n this._meshPickProceed = false;\r\n\r\n this._updatePointerPosition(evt);\r\n\r\n if (scene.preventDefaultOnPointerUp && elementToAttachTo) {\r\n evt.preventDefault();\r\n elementToAttachTo.focus();\r\n }\r\n\r\n this._initClickEvent(scene.onPrePointerObservable, scene.onPointerObservable, evt, (clickInfo: _ClickInfo, pickResult: Nullable) => {\r\n // PreObservable support\r\n if (scene.onPrePointerObservable.hasObservers()) {\r\n this._skipPointerTap = false;\r\n if (!clickInfo.ignore) {\r\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERUP)) {\r\n // If we're skipping the next observable, we need to reset the swipe state before returning\r\n if (this._swipeButtonPressed === evt.button) {\r\n this._isSwiping = false;\r\n this._swipeButtonPressed = -1;\r\n }\r\n\r\n // If we're going to skip the POINTERUP, we need to reset the pointer capture\r\n if (evt.buttons === 0) {\r\n this._pointerCaptures[evt.pointerId] = false;\r\n }\r\n\r\n return;\r\n }\r\n if (!clickInfo.hasSwiped) {\r\n if (clickInfo.singleClick && scene.onPrePointerObservable.hasSpecificMask(PointerEventTypes.POINTERTAP)) {\r\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERTAP)) {\r\n this._skipPointerTap = true;\r\n }\r\n }\r\n if (clickInfo.doubleClick && scene.onPrePointerObservable.hasSpecificMask(PointerEventTypes.POINTERDOUBLETAP)) {\r\n if (this._checkPrePointerObservable(null, evt, PointerEventTypes.POINTERDOUBLETAP)) {\r\n this._skipPointerTap = true;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // There should be a pointer captured at this point so if there isn't we should reset and return\r\n if (!this._pointerCaptures[evt.pointerId]) {\r\n if (this._swipeButtonPressed === evt.button) {\r\n this._isSwiping = false;\r\n this._swipeButtonPressed = -1;\r\n }\r\n return;\r\n }\r\n\r\n // Only release capture if all buttons are released\r\n if (evt.buttons === 0) {\r\n this._pointerCaptures[evt.pointerId] = false;\r\n }\r\n if (!scene.cameraToUseForPointers && !scene.activeCamera) {\r\n return;\r\n }\r\n\r\n if (!scene.pointerUpPredicate) {\r\n scene.pointerUpPredicate = (mesh: AbstractMesh): boolean => {\r\n return (\r\n mesh.isPickable &&\r\n mesh.isVisible &&\r\n mesh.isReady() &&\r\n mesh.isEnabled() &&\r\n (!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0)\r\n );\r\n };\r\n }\r\n\r\n // Meshes\r\n if (!this._meshPickProceed && ((AbstractActionManager && AbstractActionManager.HasTriggers) || this._checkForPicking() || scene.onPointerUp)) {\r\n this._initActionManager(null, clickInfo);\r\n }\r\n if (!pickResult) {\r\n pickResult = this._currentPickResult;\r\n }\r\n\r\n this._processPointerUp(pickResult, evt, clickInfo);\r\n\r\n this._previousPickResult = this._currentPickResult;\r\n\r\n if (this._swipeButtonPressed === evt.button) {\r\n this._isSwiping = false;\r\n this._swipeButtonPressed = -1;\r\n }\r\n });\r\n };\r\n\r\n this._onKeyDown = (evt: IKeyboardEvent) => {\r\n const type = KeyboardEventTypes.KEYDOWN;\r\n if (scene.onPreKeyboardObservable.hasObservers()) {\r\n const pi = new KeyboardInfoPre(type, evt);\r\n scene.onPreKeyboardObservable.notifyObservers(pi, type);\r\n if (pi.skipOnKeyboardObservable) {\r\n return;\r\n }\r\n }\r\n\r\n if (scene.onKeyboardObservable.hasObservers()) {\r\n const pi = new KeyboardInfo(type, evt);\r\n scene.onKeyboardObservable.notifyObservers(pi, type);\r\n }\r\n\r\n if (scene.actionManager) {\r\n scene.actionManager.processTrigger(Constants.ACTION_OnKeyDownTrigger, ActionEvent.CreateNewFromScene(scene, evt));\r\n }\r\n };\r\n\r\n this._onKeyUp = (evt: IKeyboardEvent) => {\r\n const type = KeyboardEventTypes.KEYUP;\r\n if (scene.onPreKeyboardObservable.hasObservers()) {\r\n const pi = new KeyboardInfoPre(type, evt);\r\n scene.onPreKeyboardObservable.notifyObservers(pi, type);\r\n if (pi.skipOnKeyboardObservable) {\r\n return;\r\n }\r\n }\r\n\r\n if (scene.onKeyboardObservable.hasObservers()) {\r\n const pi = new KeyboardInfo(type, evt);\r\n scene.onKeyboardObservable.notifyObservers(pi, type);\r\n }\r\n\r\n if (scene.actionManager) {\r\n scene.actionManager.processTrigger(Constants.ACTION_OnKeyUpTrigger, ActionEvent.CreateNewFromScene(scene, evt));\r\n }\r\n };\r\n\r\n // If a device connects that we can handle, wire up the observable\r\n this._deviceSourceManager.onDeviceConnectedObservable.add((deviceSource) => {\r\n if (deviceSource.deviceType === DeviceType.Mouse) {\r\n deviceSource.onInputChangedObservable.add((eventData) => {\r\n if (\r\n eventData.inputIndex === PointerInput.LeftClick ||\r\n eventData.inputIndex === PointerInput.MiddleClick ||\r\n eventData.inputIndex === PointerInput.RightClick ||\r\n eventData.inputIndex === PointerInput.BrowserBack ||\r\n eventData.inputIndex === PointerInput.BrowserForward\r\n ) {\r\n if (attachDown && deviceSource.getInput(eventData.inputIndex) === 1) {\r\n this._onPointerDown(eventData);\r\n } else if (attachUp && deviceSource.getInput(eventData.inputIndex) === 0) {\r\n this._onPointerUp(eventData);\r\n }\r\n } else if (attachMove) {\r\n if (eventData.inputIndex === PointerInput.Move) {\r\n this._onPointerMove(eventData);\r\n } else if (\r\n eventData.inputIndex === PointerInput.MouseWheelX ||\r\n eventData.inputIndex === PointerInput.MouseWheelY ||\r\n eventData.inputIndex === PointerInput.MouseWheelZ\r\n ) {\r\n this._onPointerMove(eventData);\r\n }\r\n }\r\n });\r\n } else if (deviceSource.deviceType === DeviceType.Touch) {\r\n deviceSource.onInputChangedObservable.add((eventData) => {\r\n if (eventData.inputIndex === PointerInput.LeftClick) {\r\n if (attachDown && deviceSource.getInput(eventData.inputIndex) === 1) {\r\n this._onPointerDown(eventData);\r\n if (this._totalPointersPressed > 1) {\r\n this._isMultiTouchGesture = true;\r\n }\r\n } else if (attachUp && deviceSource.getInput(eventData.inputIndex) === 0) {\r\n this._onPointerUp(eventData);\r\n if (this._totalPointersPressed === 0) {\r\n this._isMultiTouchGesture = false;\r\n }\r\n }\r\n }\r\n\r\n if (attachMove && eventData.inputIndex === PointerInput.Move) {\r\n this._onPointerMove(eventData);\r\n }\r\n });\r\n } else if (deviceSource.deviceType === DeviceType.Keyboard) {\r\n deviceSource.onInputChangedObservable.add((eventData) => {\r\n if (eventData.type === \"keydown\") {\r\n this._onKeyDown(eventData);\r\n } else if (eventData.type === \"keyup\") {\r\n this._onKeyUp(eventData);\r\n }\r\n });\r\n }\r\n });\r\n\r\n this._alreadyAttached = true;\r\n }\r\n\r\n /**\r\n * Detaches all event handlers\r\n */\r\n public detachControl() {\r\n if (this._alreadyAttached) {\r\n this._deviceSourceManager!.dispose();\r\n this._deviceSourceManager = null;\r\n\r\n // Cursor\r\n if (this._alreadyAttachedTo && !this._scene.doNotHandleCursors) {\r\n this._alreadyAttachedTo.style.cursor = this._scene.defaultCursor;\r\n }\r\n\r\n this._alreadyAttached = false;\r\n this._alreadyAttachedTo = null;\r\n }\r\n }\r\n\r\n /**\r\n * Force the value of meshUnderPointer\r\n * @param mesh - defines the mesh to use\r\n * @param pointerId - optional pointer id when using more than one pointer. Defaults to 0\r\n * @param pickResult - optional pickingInfo data used to find mesh\r\n * @param evt - optional pointer event\r\n */\r\n public setPointerOverMesh(mesh: Nullable, pointerId: number = 0, pickResult?: Nullable, evt?: IPointerEvent): void {\r\n if (this._meshUnderPointerId[pointerId] === mesh && (!mesh || !mesh._internalAbstractMeshDataInfo._pointerOverDisableMeshTesting)) {\r\n return;\r\n }\r\n\r\n const underPointerMesh = this._meshUnderPointerId[pointerId];\r\n\r\n let actionManager: Nullable;\r\n if (underPointerMesh) {\r\n actionManager = underPointerMesh._getActionManagerForTrigger(Constants.ACTION_OnPointerOutTrigger);\r\n if (actionManager) {\r\n actionManager.processTrigger(Constants.ACTION_OnPointerOutTrigger, ActionEvent.CreateNew(underPointerMesh, evt, { pointerId }));\r\n }\r\n }\r\n\r\n if (mesh) {\r\n this._meshUnderPointerId[pointerId] = mesh;\r\n this._pointerOverMesh = mesh;\r\n\r\n actionManager = mesh._getActionManagerForTrigger(Constants.ACTION_OnPointerOverTrigger);\r\n if (actionManager) {\r\n actionManager.processTrigger(Constants.ACTION_OnPointerOverTrigger, ActionEvent.CreateNew(mesh, evt, { pointerId, pickResult }));\r\n }\r\n } else {\r\n delete this._meshUnderPointerId[pointerId];\r\n this._pointerOverMesh = null;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the mesh under the pointer\r\n * @returns a Mesh or null if no mesh is under the pointer\r\n */\r\n public getPointerOverMesh(): Nullable {\r\n return this.meshUnderPointer;\r\n }\r\n\r\n /**\r\n * @param mesh - Mesh to invalidate\r\n * @internal\r\n */\r\n public _invalidateMesh(mesh: AbstractMesh) {\r\n if (this._pointerOverMesh === mesh) {\r\n this._pointerOverMesh = null;\r\n }\r\n if (this._pickedDownMesh === mesh) {\r\n this._pickedDownMesh = null;\r\n }\r\n if (this._pickedUpMesh === mesh) {\r\n this._pickedUpMesh = null;\r\n }\r\n for (const pointerId in this._meshUnderPointerId) {\r\n if (this._meshUnderPointerId[pointerId] === mesh) {\r\n delete this._meshUnderPointerId[pointerId];\r\n }\r\n }\r\n }\r\n}\r\n","import { PrecisionDate } from \"./precisionDate\";\r\n\r\n/**\r\n * This class is used to track a performance counter which is number based.\r\n * The user has access to many properties which give statistics of different nature.\r\n *\r\n * The implementer can track two kinds of Performance Counter: time and count.\r\n * For time you can optionally call fetchNewFrame() to notify the start of a new frame to monitor, then call beginMonitoring() to start and endMonitoring() to record the lapsed time. endMonitoring takes a newFrame parameter for you to specify if the monitored time should be set for a new frame or accumulated to the current frame being monitored.\r\n * For count you first have to call fetchNewFrame() to notify the start of a new frame to monitor, then call addCount() how many time required to increment the count value you monitor.\r\n */\r\nexport class PerfCounter {\r\n /**\r\n * Gets or sets a global boolean to turn on and off all the counters\r\n */\r\n public static Enabled = true;\r\n\r\n /**\r\n * Returns the smallest value ever\r\n */\r\n public get min(): number {\r\n return this._min;\r\n }\r\n\r\n /**\r\n * Returns the biggest value ever\r\n */\r\n public get max(): number {\r\n return this._max;\r\n }\r\n\r\n /**\r\n * Returns the average value since the performance counter is running\r\n */\r\n public get average(): number {\r\n return this._average;\r\n }\r\n\r\n /**\r\n * Returns the average value of the last second the counter was monitored\r\n */\r\n public get lastSecAverage(): number {\r\n return this._lastSecAverage;\r\n }\r\n\r\n /**\r\n * Returns the current value\r\n */\r\n public get current(): number {\r\n return this._current;\r\n }\r\n\r\n /**\r\n * Gets the accumulated total\r\n */\r\n public get total(): number {\r\n return this._totalAccumulated;\r\n }\r\n\r\n /**\r\n * Gets the total value count\r\n */\r\n public get count(): number {\r\n return this._totalValueCount;\r\n }\r\n\r\n /**\r\n * Creates a new counter\r\n */\r\n constructor() {\r\n this._startMonitoringTime = 0;\r\n this._min = 0;\r\n this._max = 0;\r\n this._average = 0;\r\n this._lastSecAverage = 0;\r\n this._current = 0;\r\n this._totalValueCount = 0;\r\n this._totalAccumulated = 0;\r\n this._lastSecAccumulated = 0;\r\n this._lastSecTime = 0;\r\n this._lastSecValueCount = 0;\r\n }\r\n\r\n /**\r\n * Call this method to start monitoring a new frame.\r\n * This scenario is typically used when you accumulate monitoring time many times for a single frame, you call this method at the start of the frame, then beginMonitoring to start recording and endMonitoring(false) to accumulated the recorded time to the PerfCounter or addCount() to accumulate a monitored count.\r\n */\r\n public fetchNewFrame() {\r\n this._totalValueCount++;\r\n this._current = 0;\r\n this._lastSecValueCount++;\r\n }\r\n\r\n /**\r\n * Call this method to monitor a count of something (e.g. mesh drawn in viewport count)\r\n * @param newCount the count value to add to the monitored count\r\n * @param fetchResult true when it's the last time in the frame you add to the counter and you wish to update the statistics properties (min/max/average), false if you only want to update statistics.\r\n */\r\n public addCount(newCount: number, fetchResult: boolean) {\r\n if (!PerfCounter.Enabled) {\r\n return;\r\n }\r\n this._current += newCount;\r\n if (fetchResult) {\r\n this._fetchResult();\r\n }\r\n }\r\n\r\n /**\r\n * Start monitoring this performance counter\r\n */\r\n public beginMonitoring() {\r\n if (!PerfCounter.Enabled) {\r\n return;\r\n }\r\n this._startMonitoringTime = PrecisionDate.Now;\r\n }\r\n\r\n /**\r\n * Compute the time lapsed since the previous beginMonitoring() call.\r\n * @param newFrame true by default to fetch the result and monitor a new frame, if false the time monitored will be added to the current frame counter\r\n */\r\n public endMonitoring(newFrame: boolean = true) {\r\n if (!PerfCounter.Enabled) {\r\n return;\r\n }\r\n\r\n if (newFrame) {\r\n this.fetchNewFrame();\r\n }\r\n\r\n const currentTime = PrecisionDate.Now;\r\n this._current = currentTime - this._startMonitoringTime;\r\n\r\n if (newFrame) {\r\n this._fetchResult();\r\n }\r\n }\r\n\r\n /**\r\n * Call this method to end the monitoring of a frame.\r\n * This scenario is typically used when you accumulate monitoring time many times for a single frame, you call this method at the end of the frame, after beginMonitoring to start recording and endMonitoring(false) to accumulated the recorded time to the PerfCounter or addCount() to accumulate a monitored count.\r\n */\r\n public endFrame() {\r\n this._fetchResult();\r\n }\r\n\r\n private _fetchResult() {\r\n this._totalAccumulated += this._current;\r\n this._lastSecAccumulated += this._current;\r\n\r\n // Min/Max update\r\n this._min = Math.min(this._min, this._current);\r\n this._max = Math.max(this._max, this._current);\r\n this._average = this._totalAccumulated / this._totalValueCount;\r\n\r\n // Reset last sec?\r\n const now = PrecisionDate.Now;\r\n if (now - this._lastSecTime > 1000) {\r\n this._lastSecAverage = this._lastSecAccumulated / this._lastSecValueCount;\r\n this._lastSecTime = now;\r\n this._lastSecAccumulated = 0;\r\n this._lastSecValueCount = 0;\r\n }\r\n }\r\n\r\n private _startMonitoringTime: number;\r\n private _min: number;\r\n private _max: number;\r\n private _average: number;\r\n private _current: number;\r\n private _totalValueCount: number;\r\n private _totalAccumulated: number;\r\n private _lastSecAverage: number;\r\n private _lastSecAccumulated: number;\r\n private _lastSecTime: number;\r\n private _lastSecValueCount: number;\r\n}\r\n","/**\r\n * Helper class used to generate session unique ID\r\n */\r\nexport class UniqueIdGenerator {\r\n // Statics\r\n private static _UniqueIdCounter = 1;\r\n\r\n /**\r\n * Gets an unique (relatively to the current scene) Id\r\n */\r\n public static get UniqueId() {\r\n const result = this._UniqueIdCounter;\r\n this._UniqueIdCounter++;\r\n return result;\r\n }\r\n}\r\n","/** Defines the cross module constantsused by lights to avoid circular dependencies */\r\nexport class LightConstants {\r\n /**\r\n * Falloff Default: light is falling off following the material specification:\r\n * standard material is using standard falloff whereas pbr material can request special falloff per materials.\r\n */\r\n public static readonly FALLOFF_DEFAULT = 0;\r\n\r\n /**\r\n * Falloff Physical: light is falling off following the inverse squared distance law.\r\n */\r\n public static readonly FALLOFF_PHYSICAL = 1;\r\n\r\n /**\r\n * Falloff gltf: light is falling off as described in the gltf moving to PBR document\r\n * to enhance interoperability with other engines.\r\n */\r\n public static readonly FALLOFF_GLTF = 2;\r\n\r\n /**\r\n * Falloff Standard: light is falling off like in the standard material\r\n * to enhance interoperability with other materials.\r\n */\r\n public static readonly FALLOFF_STANDARD = 3;\r\n\r\n //lightmapMode Consts\r\n /**\r\n * If every light affecting the material is in this lightmapMode,\r\n * material.lightmapTexture adds or multiplies\r\n * (depends on material.useLightmapAsShadowmap)\r\n * after every other light calculations.\r\n */\r\n public static readonly LIGHTMAP_DEFAULT = 0;\r\n /**\r\n * material.lightmapTexture as only diffuse lighting from this light\r\n * adds only specular lighting from this light\r\n * adds dynamic shadows\r\n */\r\n public static readonly LIGHTMAP_SPECULAR = 1;\r\n /**\r\n * material.lightmapTexture as only lighting\r\n * no light calculation from this light\r\n * only adds dynamic shadows from this light\r\n */\r\n public static readonly LIGHTMAP_SHADOWSONLY = 2;\r\n\r\n // Intensity Mode Consts\r\n /**\r\n * Each light type uses the default quantity according to its type:\r\n * point/spot lights use luminous intensity\r\n * directional lights use illuminance\r\n */\r\n public static readonly INTENSITYMODE_AUTOMATIC = 0;\r\n /**\r\n * lumen (lm)\r\n */\r\n public static readonly INTENSITYMODE_LUMINOUSPOWER = 1;\r\n /**\r\n * candela (lm/sr)\r\n */\r\n public static readonly INTENSITYMODE_LUMINOUSINTENSITY = 2;\r\n /**\r\n * lux (lm/m^2)\r\n */\r\n public static readonly INTENSITYMODE_ILLUMINANCE = 3;\r\n /**\r\n * nit (cd/m^2)\r\n */\r\n public static readonly INTENSITYMODE_LUMINANCE = 4;\r\n\r\n // Light types ids const.\r\n /**\r\n * Light type const id of the point light.\r\n */\r\n public static readonly LIGHTTYPEID_POINTLIGHT = 0;\r\n /**\r\n * Light type const id of the directional light.\r\n */\r\n public static readonly LIGHTTYPEID_DIRECTIONALLIGHT = 1;\r\n /**\r\n * Light type const id of the spot light.\r\n */\r\n public static readonly LIGHTTYPEID_SPOTLIGHT = 2;\r\n /**\r\n * Light type const id of the hemispheric light.\r\n */\r\n public static readonly LIGHTTYPEID_HEMISPHERICLIGHT = 3;\r\n\r\n /**\r\n * Sort function to order lights for rendering.\r\n * @param a First Light object to compare to second.\r\n * @param b Second Light object to compare first.\r\n * @returns -1 to reduce's a's index relative to be, 0 for no change, 1 to increase a's index relative to b.\r\n */\r\n public static CompareLightsPriority(a: ISortableLight, b: ISortableLight): number {\r\n //shadow-casting lights have priority over non-shadow-casting lights\r\n //the renderPriority is a secondary sort criterion\r\n if (a.shadowEnabled !== b.shadowEnabled) {\r\n return (b.shadowEnabled ? 1 : 0) - (a.shadowEnabled ? 1 : 0);\r\n }\r\n return b.renderPriority - a.renderPriority;\r\n }\r\n}\r\n\r\n/**\r\n * Defines the common interface of sortable lights\r\n */\r\nexport interface ISortableLight {\r\n /**\r\n * Gets or sets whether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching\r\n * the current shadow generator.\r\n */\r\n shadowEnabled: boolean;\r\n /**\r\n * Defines the rendering priority of the lights. It can help in case of fallback or number of lights\r\n * exceeding the number allowed of the materials.\r\n */\r\n renderPriority: number;\r\n}\r\n","import type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n\r\n/**\r\n * Class used to store configuration data associated with pointer picking\r\n */\r\nexport class PointerPickingConfiguration {\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\r\n */\r\n public pointerDownPredicate: (Mesh: AbstractMesh) => boolean;\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\r\n */\r\n public pointerUpPredicate: (Mesh: AbstractMesh) => boolean;\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\r\n */\r\n public pointerMovePredicate: (Mesh: AbstractMesh) => boolean;\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\r\n */\r\n public pointerDownFastCheck = false;\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\r\n */\r\n public pointerUpFastCheck = false;\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\r\n */\r\n public pointerMoveFastCheck = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer move event occurs.\r\n */\r\n public skipPointerMovePicking = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer down event occurs.\r\n */\r\n public skipPointerDownPicking = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer up event occurs. Off by default.\r\n */\r\n public skipPointerUpPicking = false;\r\n}\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Nullable } from \"./types\";\r\nimport { Tools } from \"./Misc/tools\";\r\nimport type { IAnimatable } from \"./Animations/animatable.interface\";\r\nimport { PrecisionDate } from \"./Misc/precisionDate\";\r\nimport type { Observer } from \"./Misc/observable\";\r\nimport { Observable } from \"./Misc/observable\";\r\nimport type { ISmartArrayLike } from \"./Misc/smartArray\";\r\nimport { SmartArrayNoDuplicate, SmartArray } from \"./Misc/smartArray\";\r\nimport { StringDictionary } from \"./Misc/stringDictionary\";\r\nimport { Tags } from \"./Misc/tags\";\r\nimport type { Vector2, Vector4 } from \"./Maths/math.vector\";\r\nimport { Vector3, Matrix, TmpVectors } from \"./Maths/math.vector\";\r\nimport type { IParticleSystem } from \"./Particles/IParticleSystem\";\r\nimport { AbstractScene } from \"./abstractScene\";\r\nimport { ImageProcessingConfiguration } from \"./Materials/imageProcessingConfiguration\";\r\nimport { UniformBuffer } from \"./Materials/uniformBuffer\";\r\nimport { PickingInfo } from \"./Collisions/pickingInfo\";\r\nimport type { ICollisionCoordinator } from \"./Collisions/collisionCoordinator\";\r\nimport type { PointerEventTypes, PointerInfoPre, PointerInfo } from \"./Events/pointerEvents\";\r\nimport type { KeyboardInfoPre, KeyboardInfo } from \"./Events/keyboardEvents\";\r\nimport { ActionEvent } from \"./Actions/actionEvent\";\r\nimport { PostProcessManager } from \"./PostProcesses/postProcessManager\";\r\nimport type { IOfflineProvider } from \"./Offline/IOfflineProvider\";\r\nimport type { RenderingGroupInfo, IRenderingManagerAutoClearSetup } from \"./Rendering/renderingManager\";\r\nimport { RenderingManager } from \"./Rendering/renderingManager\";\r\nimport type {\r\n ISceneComponent,\r\n ISceneSerializableComponent,\r\n SimpleStageAction,\r\n RenderTargetsStageAction,\r\n RenderTargetStageAction,\r\n MeshStageAction,\r\n EvaluateSubMeshStageAction,\r\n PreActiveMeshStageAction,\r\n CameraStageAction,\r\n RenderingGroupStageAction,\r\n RenderingMeshStageAction,\r\n PointerMoveStageAction,\r\n PointerUpDownStageAction,\r\n CameraStageFrameBufferAction,\r\n} from \"./sceneComponent\";\r\nimport { Stage } from \"./sceneComponent\";\r\nimport type { Engine } from \"./Engines/engine\";\r\nimport { Constants } from \"./Engines/constants\";\r\nimport { IsWindowObjectExist } from \"./Misc/domManagement\";\r\nimport { EngineStore } from \"./Engines/engineStore\";\r\nimport type { AbstractActionManager } from \"./Actions/abstractActionManager\";\r\nimport { _WarnImport } from \"./Misc/devTools\";\r\nimport type { WebRequest } from \"./Misc/webRequest\";\r\nimport { InputManager } from \"./Inputs/scene.inputManager\";\r\nimport { PerfCounter } from \"./Misc/perfCounter\";\r\nimport type { IFileRequest } from \"./Misc/fileRequest\";\r\nimport { Color4, Color3 } from \"./Maths/math.color\";\r\nimport type { Plane } from \"./Maths/math.plane\";\r\nimport { Frustum } from \"./Maths/math.frustum\";\r\nimport { UniqueIdGenerator } from \"./Misc/uniqueIdGenerator\";\r\nimport type { LoadFileError, RequestFileError, ReadFileError } from \"./Misc/fileTools\";\r\nimport { ReadFile, RequestFile, LoadFile } from \"./Misc/fileTools\";\r\nimport type { IClipPlanesHolder } from \"./Misc/interfaces/iClipPlanesHolder\";\r\nimport type { IPointerEvent } from \"./Events/deviceInputEvents\";\r\nimport { LightConstants } from \"./Lights/lightConstants\";\r\nimport { _ObserveArray } from \"./Misc/arrayTools\";\r\nimport type { IAction } from \"./Actions/action\";\r\nimport type { AnimationPropertiesOverride } from \"./Animations/animationPropertiesOverride\";\r\nimport type { AnimationGroup } from \"./Animations/animationGroup\";\r\nimport type { Skeleton } from \"./Bones/skeleton\";\r\nimport type { Bone } from \"./Bones/bone\";\r\nimport type { Camera } from \"./Cameras/camera\";\r\nimport type { WebVRFreeCamera } from \"./Cameras/VR/webVRCamera\";\r\nimport type { Collider } from \"./Collisions/collider\";\r\nimport type { Ray, TrianglePickingPredicate } from \"./Culling/ray\";\r\nimport type { Light } from \"./Lights/light\";\r\nimport type { PerformanceViewerCollector } from \"./Misc/PerformanceViewer/performanceViewerCollector\";\r\nimport type { MorphTarget } from \"./Morph/morphTarget\";\r\nimport type { MorphTargetManager } from \"./Morph/morphTargetManager\";\r\nimport type { PostProcess } from \"./PostProcesses/postProcess\";\r\nimport type { Material } from \"./Materials/material\";\r\nimport type { BaseTexture } from \"./Materials/Textures/baseTexture\";\r\nimport type { Geometry } from \"./Meshes/geometry\";\r\nimport type { TransformNode } from \"./Meshes/transformNode\";\r\nimport type { AbstractMesh } from \"./Meshes/abstractMesh\";\r\nimport type { MultiMaterial } from \"./Materials/multiMaterial\";\r\nimport type { Effect } from \"./Materials/effect\";\r\nimport type { RenderTargetTexture } from \"./Materials/Textures/renderTargetTexture\";\r\nimport type { Mesh } from \"./Meshes/mesh\";\r\nimport type { SubMesh } from \"./Meshes/subMesh\";\r\nimport type { Node } from \"./node\";\r\nimport type { Animation } from \"./Animations/animation\";\r\nimport type { Animatable } from \"./Animations/animatable\";\r\nimport type { Texture } from \"./Materials/Textures/texture\";\r\nimport { PointerPickingConfiguration } from \"./Inputs/pointerPickingConfiguration\";\r\n\r\n/**\r\n * Define an interface for all classes that will hold resources\r\n */\r\nexport interface IDisposable {\r\n /**\r\n * Releases all held resources\r\n */\r\n dispose(): void;\r\n}\r\n\r\n/** Interface defining initialization parameters for Scene class */\r\nexport interface SceneOptions {\r\n /**\r\n * Defines that scene should keep up-to-date a map of geometry to enable fast look-up by uniqueId\r\n * It will improve performance when the number of geometries becomes important.\r\n */\r\n useGeometryUniqueIdsMap?: boolean;\r\n\r\n /**\r\n * Defines that each material of the scene should keep up-to-date a map of referencing meshes for fast disposing\r\n * It will improve performance when the number of mesh becomes important, but might consume a bit more memory\r\n */\r\n useMaterialMeshMap?: boolean;\r\n\r\n /**\r\n * Defines that each mesh of the scene should keep up-to-date a map of referencing cloned meshes for fast disposing\r\n * It will improve performance when the number of mesh becomes important, but might consume a bit more memory\r\n */\r\n useClonedMeshMap?: boolean;\r\n\r\n /** Defines if the creation of the scene should impact the engine (Eg. UtilityLayer's scene) */\r\n virtual?: boolean;\r\n}\r\n\r\n/**\r\n * Define how the scene should favor performance over ease of use\r\n */\r\nexport enum ScenePerformancePriority {\r\n /** Default mode. No change. Performance will be treated as less important than backward compatibility */\r\n BackwardCompatible,\r\n /** Some performance options will be turned on trying to strike a balance between perf and ease of use */\r\n Intermediate,\r\n /** Performance will be top priority */\r\n Aggressive,\r\n}\r\n\r\n/**\r\n * Represents a scene to be rendered by the engine.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene\r\n */\r\nexport class Scene extends AbstractScene implements IAnimatable, IClipPlanesHolder {\r\n /** The fog is deactivated */\r\n public static readonly FOGMODE_NONE = 0;\r\n /** The fog density is following an exponential function */\r\n public static readonly FOGMODE_EXP = 1;\r\n /** The fog density is following an exponential function faster than FOGMODE_EXP */\r\n public static readonly FOGMODE_EXP2 = 2;\r\n /** The fog density is following a linear function. */\r\n public static readonly FOGMODE_LINEAR = 3;\r\n\r\n /**\r\n * Gets or sets the minimum deltatime when deterministic lock step is enabled\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n */\r\n public static MinDeltaTime = 1.0;\r\n /**\r\n * Gets or sets the maximum deltatime when deterministic lock step is enabled\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n */\r\n public static MaxDeltaTime = 1000.0;\r\n\r\n /**\r\n * Factory used to create the default material.\r\n * @param scene The scene to create the material for\r\n * @returns The default material\r\n */\r\n public static DefaultMaterialFactory(scene: Scene): Material {\r\n throw _WarnImport(\"StandardMaterial\");\r\n }\r\n\r\n /**\r\n * Factory used to create the a collision coordinator.\r\n * @returns The collision coordinator\r\n */\r\n public static CollisionCoordinatorFactory(): ICollisionCoordinator {\r\n throw _WarnImport(\"DefaultCollisionCoordinator\");\r\n }\r\n\r\n // Members\r\n\r\n /** @internal */\r\n public _inputManager = new InputManager(this);\r\n\r\n /** Define this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position */\r\n public cameraToUseForPointers: Nullable = null;\r\n\r\n /** @internal */\r\n public readonly _isScene = true;\r\n\r\n /** @internal */\r\n public _blockEntityCollection = false;\r\n\r\n /**\r\n * Gets or sets a boolean that indicates if the scene must clear the render buffer before rendering a frame\r\n */\r\n public autoClear = true;\r\n /**\r\n * Gets or sets a boolean that indicates if the scene must clear the depth and stencil buffers before rendering a frame\r\n */\r\n public autoClearDepthAndStencil = true;\r\n /**\r\n * Defines the color used to clear the render buffer (Default is (0.2, 0.2, 0.3, 1.0))\r\n */\r\n public clearColor: Color4 = new Color4(0.2, 0.2, 0.3, 1.0);\r\n /**\r\n * Defines the color used to simulate the ambient color (Default is (0, 0, 0))\r\n */\r\n public ambientColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * This is use to store the default BRDF lookup for PBR materials in your scene.\r\n * It should only be one of the following (if not the default embedded one):\r\n * * For uncorrelated BRDF (pbr.brdf.useEnergyConservation = false and pbr.brdf.useSmithVisibilityHeightCorrelated = false) : https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds\r\n * * For correlated BRDF (pbr.brdf.useEnergyConservation = false and pbr.brdf.useSmithVisibilityHeightCorrelated = true) : https://assets.babylonjs.com/environments/correlatedBRDF.dds\r\n * * For correlated multi scattering BRDF (pbr.brdf.useEnergyConservation = true and pbr.brdf.useSmithVisibilityHeightCorrelated = true) : https://assets.babylonjs.com/environments/correlatedMSBRDF.dds\r\n * The material properties need to be setup according to the type of texture in use.\r\n */\r\n public environmentBRDFTexture: BaseTexture;\r\n\r\n /**\r\n * Texture used in all pbr material as the reflection texture.\r\n * As in the majority of the scene they are the same (exception for multi room and so on),\r\n * this is easier to reference from here than from all the materials.\r\n */\r\n public get environmentTexture(): Nullable {\r\n return this._environmentTexture;\r\n }\r\n /**\r\n * Texture used in all pbr material as the reflection texture.\r\n * As in the majority of the scene they are the same (exception for multi room and so on),\r\n * this is easier to set here than in all the materials.\r\n */\r\n public set environmentTexture(value: Nullable) {\r\n if (this._environmentTexture === value) {\r\n return;\r\n }\r\n\r\n this._environmentTexture = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n /**\r\n * Intensity of the environment in all pbr material.\r\n * This dims or reinforces the IBL lighting overall (reflection and diffuse).\r\n * As in the majority of the scene they are the same (exception for multi room and so on),\r\n * this is easier to reference from here than from all the materials.\r\n */\r\n public environmentIntensity: number = 1;\r\n\r\n /** @internal */\r\n protected _imageProcessingConfiguration: ImageProcessingConfiguration;\r\n /**\r\n * Default image processing configuration used either in the rendering\r\n * Forward main pass or through the imageProcessingPostProcess if present.\r\n * As in the majority of the scene they are the same (exception for multi camera),\r\n * this is easier to reference from here than from all the materials and post process.\r\n *\r\n * No setter as we it is a shared configuration, you can set the values instead.\r\n */\r\n public get imageProcessingConfiguration(): ImageProcessingConfiguration {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n private _performancePriority = ScenePerformancePriority.BackwardCompatible;\r\n\r\n /**\r\n * Observable triggered when the performance priority is changed\r\n */\r\n public onScenePerformancePriorityChangedObservable = new Observable();\r\n /**\r\n * Gets or sets a value indicating how to treat performance relatively to ease of use and backward compatibility\r\n */\r\n public get performancePriority() {\r\n return this._performancePriority;\r\n }\r\n\r\n public set performancePriority(value) {\r\n if (value === this._performancePriority) {\r\n return;\r\n }\r\n\r\n this._performancePriority = value;\r\n\r\n switch (value) {\r\n case ScenePerformancePriority.BackwardCompatible:\r\n this.skipFrustumClipping = false;\r\n this._renderingManager.maintainStateBetweenFrames = false;\r\n this.skipPointerMovePicking = false;\r\n this.autoClear = true;\r\n break;\r\n case ScenePerformancePriority.Intermediate:\r\n this.skipFrustumClipping = false;\r\n this._renderingManager.maintainStateBetweenFrames = false;\r\n this.skipPointerMovePicking = true;\r\n this.autoClear = false;\r\n break;\r\n case ScenePerformancePriority.Aggressive:\r\n this.skipFrustumClipping = true;\r\n this._renderingManager.maintainStateBetweenFrames = true;\r\n this.skipPointerMovePicking = true;\r\n this.autoClear = false;\r\n break;\r\n }\r\n\r\n this.onScenePerformancePriorityChangedObservable.notifyObservers(value);\r\n }\r\n\r\n private _forceWireframe = false;\r\n /**\r\n * Gets or sets a boolean indicating if all rendering must be done in wireframe\r\n */\r\n public set forceWireframe(value: boolean) {\r\n if (this._forceWireframe === value) {\r\n return;\r\n }\r\n this._forceWireframe = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_MiscDirtyFlag);\r\n }\r\n public get forceWireframe(): boolean {\r\n return this._forceWireframe;\r\n }\r\n\r\n private _skipFrustumClipping = false;\r\n /**\r\n * Gets or sets a boolean indicating if we should skip the frustum clipping part of the active meshes selection\r\n */\r\n public set skipFrustumClipping(value: boolean) {\r\n if (this._skipFrustumClipping === value) {\r\n return;\r\n }\r\n this._skipFrustumClipping = value;\r\n }\r\n public get skipFrustumClipping(): boolean {\r\n return this._skipFrustumClipping;\r\n }\r\n\r\n private _forcePointsCloud = false;\r\n /**\r\n * Gets or sets a boolean indicating if all rendering must be done in point cloud\r\n */\r\n public set forcePointsCloud(value: boolean) {\r\n if (this._forcePointsCloud === value) {\r\n return;\r\n }\r\n this._forcePointsCloud = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_MiscDirtyFlag);\r\n }\r\n public get forcePointsCloud(): boolean {\r\n return this._forcePointsCloud;\r\n }\r\n\r\n /**\r\n * Gets or sets the active clipplane 1\r\n */\r\n public clipPlane: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 2\r\n */\r\n public clipPlane2: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 3\r\n */\r\n public clipPlane3: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 4\r\n */\r\n public clipPlane4: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 5\r\n */\r\n public clipPlane5: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 6\r\n */\r\n public clipPlane6: Nullable;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if animations are enabled\r\n */\r\n public animationsEnabled = true;\r\n\r\n private _animationPropertiesOverride: Nullable = null;\r\n\r\n /**\r\n * Gets or sets the animation properties override\r\n */\r\n public get animationPropertiesOverride(): Nullable {\r\n return this._animationPropertiesOverride;\r\n }\r\n\r\n public set animationPropertiesOverride(value: Nullable) {\r\n this._animationPropertiesOverride = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if a constant deltatime has to be used\r\n * This is mostly useful for testing purposes when you do not want the animations to scale with the framerate\r\n */\r\n public useConstantAnimationDeltaTime = false;\r\n /**\r\n * Gets or sets a boolean indicating if the scene must keep the meshUnderPointer property updated\r\n * Please note that it requires to run a ray cast through the scene on every frame\r\n */\r\n public constantlyUpdateMeshUnderPointer = false;\r\n\r\n /**\r\n * Defines the HTML cursor to use when hovering over interactive elements\r\n */\r\n public hoverCursor = \"pointer\";\r\n /**\r\n * Defines the HTML default cursor to use (empty by default)\r\n */\r\n public defaultCursor: string = \"\";\r\n /**\r\n * Defines whether cursors are handled by the scene.\r\n */\r\n public doNotHandleCursors = false;\r\n /**\r\n * This is used to call preventDefault() on pointer down\r\n * in order to block unwanted artifacts like system double clicks\r\n */\r\n public preventDefaultOnPointerDown = true;\r\n\r\n /**\r\n * This is used to call preventDefault() on pointer up\r\n * in order to block unwanted artifacts like system double clicks\r\n */\r\n public preventDefaultOnPointerUp = true;\r\n\r\n // Metadata\r\n /**\r\n * Gets or sets user defined metadata\r\n */\r\n public metadata: any = null;\r\n\r\n /**\r\n * For internal use only. Please do not use.\r\n */\r\n public reservedDataStore: any = null;\r\n\r\n /**\r\n * Gets the name of the plugin used to load this scene (null by default)\r\n */\r\n public loadingPluginName: string;\r\n\r\n /**\r\n * Use this array to add regular expressions used to disable offline support for specific urls\r\n */\r\n public disableOfflineSupportExceptionRules = new Array();\r\n\r\n /**\r\n * An event triggered when the scene is disposed.\r\n */\r\n public onDisposeObservable = new Observable();\r\n\r\n private _onDisposeObserver: Nullable> = null;\r\n /** Sets a function to be executed when this scene is disposed. */\r\n public set onDispose(callback: () => void) {\r\n if (this._onDisposeObserver) {\r\n this.onDisposeObservable.remove(this._onDisposeObserver);\r\n }\r\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered before rendering the scene (right after animations and physics)\r\n */\r\n public onBeforeRenderObservable = new Observable();\r\n\r\n private _onBeforeRenderObserver: Nullable> = null;\r\n /** Sets a function to be executed before rendering this scene */\r\n public set beforeRender(callback: Nullable<() => void>) {\r\n if (this._onBeforeRenderObserver) {\r\n this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\r\n }\r\n if (callback) {\r\n this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);\r\n }\r\n }\r\n\r\n /**\r\n * An event triggered after rendering the scene\r\n */\r\n public onAfterRenderObservable = new Observable();\r\n\r\n /**\r\n * An event triggered after rendering the scene for an active camera (When scene.render is called this will be called after each camera)\r\n * This is triggered for each \"sub\" camera in a Camera Rig unlike onAfterCameraRenderObservable\r\n */\r\n public onAfterRenderCameraObservable = new Observable();\r\n\r\n private _onAfterRenderObserver: Nullable> = null;\r\n /** Sets a function to be executed after rendering this scene */\r\n public set afterRender(callback: Nullable<() => void>) {\r\n if (this._onAfterRenderObserver) {\r\n this.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n }\r\n\r\n if (callback) {\r\n this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);\r\n }\r\n }\r\n\r\n /**\r\n * An event triggered before animating the scene\r\n */\r\n public onBeforeAnimationsObservable = new Observable();\r\n\r\n /**\r\n * An event triggered after animations processing\r\n */\r\n public onAfterAnimationsObservable = new Observable();\r\n\r\n /**\r\n * An event triggered before draw calls are ready to be sent\r\n */\r\n public onBeforeDrawPhaseObservable = new Observable();\r\n\r\n /**\r\n * An event triggered after draw calls have been sent\r\n */\r\n public onAfterDrawPhaseObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the scene is ready\r\n */\r\n public onReadyObservable = new Observable();\r\n\r\n /**\r\n * An event triggered before rendering a camera\r\n */\r\n public onBeforeCameraRenderObservable = new Observable();\r\n\r\n private _onBeforeCameraRenderObserver: Nullable> = null;\r\n /** Sets a function to be executed before rendering a camera*/\r\n public set beforeCameraRender(callback: () => void) {\r\n if (this._onBeforeCameraRenderObserver) {\r\n this.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);\r\n }\r\n\r\n this._onBeforeCameraRenderObserver = this.onBeforeCameraRenderObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered after rendering a camera\r\n * This is triggered for the full rig Camera only unlike onAfterRenderCameraObservable\r\n */\r\n public onAfterCameraRenderObservable = new Observable();\r\n\r\n private _onAfterCameraRenderObserver: Nullable> = null;\r\n /** Sets a function to be executed after rendering a camera*/\r\n public set afterCameraRender(callback: () => void) {\r\n if (this._onAfterCameraRenderObserver) {\r\n this.onAfterCameraRenderObservable.remove(this._onAfterCameraRenderObserver);\r\n }\r\n this._onAfterCameraRenderObserver = this.onAfterCameraRenderObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when active meshes evaluation is about to start\r\n */\r\n public onBeforeActiveMeshesEvaluationObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when active meshes evaluation is done\r\n */\r\n public onAfterActiveMeshesEvaluationObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when particles rendering is about to start\r\n * Note: This event can be trigger more than once per frame (because particles can be rendered by render target textures as well)\r\n */\r\n public onBeforeParticlesRenderingObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when particles rendering is done\r\n * Note: This event can be trigger more than once per frame (because particles can be rendered by render target textures as well)\r\n */\r\n public onAfterParticlesRenderingObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when SceneLoader.Append or SceneLoader.Load or SceneLoader.ImportMesh were successfully executed\r\n */\r\n public onDataLoadedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a camera is created\r\n */\r\n public onNewCameraAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a camera is removed\r\n */\r\n public onCameraRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a light is created\r\n */\r\n public onNewLightAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a light is removed\r\n */\r\n public onLightRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a geometry is created\r\n */\r\n public onNewGeometryAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a geometry is removed\r\n */\r\n public onGeometryRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a transform node is created\r\n */\r\n public onNewTransformNodeAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a transform node is removed\r\n */\r\n public onTransformNodeRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a mesh is created\r\n */\r\n public onNewMeshAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a mesh is removed\r\n */\r\n public onMeshRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a skeleton is created\r\n */\r\n public onNewSkeletonAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a skeleton is removed\r\n */\r\n public onSkeletonRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a material is created\r\n */\r\n public onNewMaterialAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a multi material is created\r\n */\r\n public onNewMultiMaterialAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a material is removed\r\n */\r\n public onMaterialRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a multi material is removed\r\n */\r\n public onMultiMaterialRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a texture is created\r\n */\r\n public onNewTextureAddedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when a texture is removed\r\n */\r\n public onTextureRemovedObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when render targets are about to be rendered\r\n * Can happen multiple times per frame.\r\n */\r\n public onBeforeRenderTargetsRenderObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when render targets were rendered.\r\n * Can happen multiple times per frame.\r\n */\r\n public onAfterRenderTargetsRenderObservable = new Observable();\r\n\r\n /**\r\n * An event triggered before calculating deterministic simulation step\r\n */\r\n public onBeforeStepObservable = new Observable();\r\n\r\n /**\r\n * An event triggered after calculating deterministic simulation step\r\n */\r\n public onAfterStepObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the activeCamera property is updated\r\n */\r\n public onActiveCameraChanged = new Observable();\r\n\r\n /**\r\n * An event triggered when the activeCameras property is updated\r\n */\r\n public onActiveCamerasChanged = new Observable();\r\n\r\n /**\r\n * This Observable will be triggered before rendering each renderingGroup of each rendered camera.\r\n * The RenderingGroupInfo class contains all the information about the context in which the observable is called\r\n * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)\r\n */\r\n public onBeforeRenderingGroupObservable = new Observable();\r\n\r\n /**\r\n * This Observable will be triggered after rendering each renderingGroup of each rendered camera.\r\n * The RenderingGroupInfo class contains all the information about the context in which the observable is called\r\n * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)\r\n */\r\n public onAfterRenderingGroupObservable = new Observable();\r\n\r\n /**\r\n * This Observable will when a mesh has been imported into the scene.\r\n */\r\n public onMeshImportedObservable = new Observable();\r\n\r\n /**\r\n * This Observable will when an animation file has been imported into the scene.\r\n */\r\n public onAnimationFileImportedObservable = new Observable();\r\n\r\n /**\r\n * Gets or sets a user defined funtion to select LOD from a mesh and a camera.\r\n * By default this function is undefined and Babylon.js will select LOD based on distance to camera\r\n */\r\n public customLODSelector: (mesh: AbstractMesh, camera: Camera) => Nullable;\r\n\r\n // Animations\r\n\r\n /** @internal */\r\n public _registeredForLateAnimationBindings = new SmartArrayNoDuplicate(256);\r\n\r\n // Pointers\r\n private _pointerPickingConfiguration = new PointerPickingConfiguration();\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\r\n */\r\n public get pointerDownPredicate() {\r\n return this._pointerPickingConfiguration.pointerDownPredicate;\r\n }\r\n\r\n public set pointerDownPredicate(value) {\r\n this._pointerPickingConfiguration.pointerDownPredicate = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\r\n */\r\n public get pointerUpPredicate() {\r\n return this._pointerPickingConfiguration.pointerUpPredicate;\r\n }\r\n\r\n public set pointerUpPredicate(value) {\r\n this._pointerPickingConfiguration.pointerUpPredicate = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\r\n */\r\n public get pointerMovePredicate() {\r\n return this._pointerPickingConfiguration.pointerMovePredicate;\r\n }\r\n\r\n public set pointerMovePredicate(value) {\r\n this._pointerPickingConfiguration.pointerMovePredicate = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer down event\r\n */\r\n public get pointerDownFastCheck() {\r\n return this._pointerPickingConfiguration.pointerDownFastCheck;\r\n }\r\n\r\n public set pointerDownFastCheck(value) {\r\n this._pointerPickingConfiguration.pointerDownFastCheck = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer up event\r\n */\r\n public get pointerUpFastCheck() {\r\n return this._pointerPickingConfiguration.pointerUpFastCheck;\r\n }\r\n\r\n public set pointerUpFastCheck(value) {\r\n this._pointerPickingConfiguration.pointerUpFastCheck = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate meshes for a pointer move event\r\n */\r\n public get pointerMoveFastCheck() {\r\n return this._pointerPickingConfiguration.pointerMoveFastCheck;\r\n }\r\n\r\n public set pointerMoveFastCheck(value) {\r\n this._pointerPickingConfiguration.pointerMoveFastCheck = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer move event occurs.\r\n */\r\n public get skipPointerMovePicking() {\r\n return this._pointerPickingConfiguration.skipPointerMovePicking;\r\n }\r\n\r\n public set skipPointerMovePicking(value) {\r\n this._pointerPickingConfiguration.skipPointerMovePicking = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer down event occurs.\r\n */\r\n public get skipPointerDownPicking() {\r\n return this._pointerPickingConfiguration.skipPointerDownPicking;\r\n }\r\n\r\n public set skipPointerDownPicking(value) {\r\n this._pointerPickingConfiguration.skipPointerDownPicking = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer up event occurs. Off by default.\r\n */\r\n public get skipPointerUpPicking() {\r\n return this._pointerPickingConfiguration.skipPointerUpPicking;\r\n }\r\n\r\n public set skipPointerUpPicking(value) {\r\n this._pointerPickingConfiguration.skipPointerUpPicking = value;\r\n }\r\n\r\n /** Callback called when a pointer move is detected */\r\n public onPointerMove?: (evt: IPointerEvent, pickInfo: PickingInfo, type: PointerEventTypes) => void;\r\n /** Callback called when a pointer down is detected */\r\n public onPointerDown?: (evt: IPointerEvent, pickInfo: PickingInfo, type: PointerEventTypes) => void;\r\n /** Callback called when a pointer up is detected */\r\n public onPointerUp?: (evt: IPointerEvent, pickInfo: Nullable, type: PointerEventTypes) => void;\r\n /** Callback called when a pointer pick is detected */\r\n public onPointerPick?: (evt: IPointerEvent, pickInfo: PickingInfo) => void;\r\n\r\n /**\r\n * Gets or sets a predicate used to select candidate faces for a pointer move event\r\n */\r\n public pointerMoveTrianglePredicate: ((p0: Vector3, p1: Vector3, p2: Vector3, ray: Ray) => boolean) | undefined;\r\n\r\n /**\r\n * This observable event is triggered when any ponter event is triggered. It is registered during Scene.attachControl() and it is called BEFORE the 3D engine process anything (mesh/sprite picking for instance).\r\n * You have the possibility to skip the process and the call to onPointerObservable by setting PointerInfoPre.skipOnPointerObservable to true\r\n */\r\n public onPrePointerObservable = new Observable();\r\n\r\n /**\r\n * Observable event triggered each time an input event is received from the rendering canvas\r\n */\r\n public onPointerObservable = new Observable();\r\n\r\n /**\r\n * Gets the pointer coordinates without any translation (ie. straight out of the pointer event)\r\n */\r\n public get unTranslatedPointer(): Vector2 {\r\n return this._inputManager.unTranslatedPointer;\r\n }\r\n\r\n /**\r\n * Gets or sets the distance in pixel that you have to move to prevent some events. Default is 10 pixels\r\n */\r\n public static get DragMovementThreshold() {\r\n return InputManager.DragMovementThreshold;\r\n }\r\n\r\n public static set DragMovementThreshold(value: number) {\r\n InputManager.DragMovementThreshold = value;\r\n }\r\n\r\n /**\r\n * Time in milliseconds to wait to raise long press events if button is still pressed. Default is 500 ms\r\n */\r\n public static get LongPressDelay() {\r\n return InputManager.LongPressDelay;\r\n }\r\n\r\n public static set LongPressDelay(value: number) {\r\n InputManager.LongPressDelay = value;\r\n }\r\n\r\n /**\r\n * Time in milliseconds to wait to raise long press events if button is still pressed. Default is 300 ms\r\n */\r\n public static get DoubleClickDelay() {\r\n return InputManager.DoubleClickDelay;\r\n }\r\n\r\n public static set DoubleClickDelay(value: number) {\r\n InputManager.DoubleClickDelay = value;\r\n }\r\n\r\n /** If you need to check double click without raising a single click at first click, enable this flag */\r\n public static get ExclusiveDoubleClickMode() {\r\n return InputManager.ExclusiveDoubleClickMode;\r\n }\r\n\r\n public static set ExclusiveDoubleClickMode(value: boolean) {\r\n InputManager.ExclusiveDoubleClickMode = value;\r\n }\r\n\r\n /**\r\n * Bind the current view position to an effect.\r\n * @param effect The effect to be bound\r\n * @param variableName name of the shader variable that will hold the eye position\r\n * @param isVector3 true to indicates that variableName is a Vector3 and not a Vector4\r\n * @returns the computed eye position\r\n */\r\n public bindEyePosition(effect: Nullable, variableName = \"vEyePosition\", isVector3 = false): Vector4 {\r\n const eyePosition = this._forcedViewPosition\r\n ? this._forcedViewPosition\r\n : this._mirroredCameraPosition\r\n ? this._mirroredCameraPosition\r\n : this.activeCamera!.globalPosition ?? (this.activeCamera as WebVRFreeCamera).devicePosition;\r\n\r\n const invertNormal = this.useRightHandedSystem === (this._mirroredCameraPosition != null);\r\n\r\n TmpVectors.Vector4[0].set(eyePosition.x, eyePosition.y, eyePosition.z, invertNormal ? -1 : 1);\r\n\r\n if (effect) {\r\n if (isVector3) {\r\n effect.setFloat3(variableName, TmpVectors.Vector4[0].x, TmpVectors.Vector4[0].y, TmpVectors.Vector4[0].z);\r\n } else {\r\n effect.setVector4(variableName, TmpVectors.Vector4[0]);\r\n }\r\n }\r\n\r\n return TmpVectors.Vector4[0];\r\n }\r\n\r\n /**\r\n * Update the scene ubo before it can be used in rendering processing\r\n * @returns the scene UniformBuffer\r\n */\r\n public finalizeSceneUbo(): UniformBuffer {\r\n const ubo = this.getSceneUniformBuffer();\r\n const eyePosition = this.bindEyePosition(null);\r\n ubo.updateFloat4(\"vEyePosition\", eyePosition.x, eyePosition.y, eyePosition.z, eyePosition.w);\r\n\r\n ubo.update();\r\n\r\n return ubo;\r\n }\r\n\r\n // Mirror\r\n /** @internal */\r\n public _mirroredCameraPosition: Nullable;\r\n\r\n // Keyboard\r\n\r\n /**\r\n * This observable event is triggered when any keyboard event si raised and registered during Scene.attachControl()\r\n * You have the possibility to skip the process and the call to onKeyboardObservable by setting KeyboardInfoPre.skipOnPointerObservable to true\r\n */\r\n public onPreKeyboardObservable = new Observable();\r\n\r\n /**\r\n * Observable event triggered each time an keyboard event is received from the hosting window\r\n */\r\n public onKeyboardObservable = new Observable();\r\n\r\n // Coordinates system\r\n\r\n private _useRightHandedSystem = false;\r\n /**\r\n * Gets or sets a boolean indicating if the scene must use right-handed coordinates system\r\n */\r\n public set useRightHandedSystem(value: boolean) {\r\n if (this._useRightHandedSystem === value) {\r\n return;\r\n }\r\n this._useRightHandedSystem = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_MiscDirtyFlag);\r\n }\r\n public get useRightHandedSystem(): boolean {\r\n return this._useRightHandedSystem;\r\n }\r\n\r\n // Deterministic lockstep\r\n private _timeAccumulator: number = 0;\r\n private _currentStepId: number = 0;\r\n private _currentInternalStep: number = 0;\r\n\r\n /**\r\n * Sets the step Id used by deterministic lock step\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n * @param newStepId defines the step Id\r\n */\r\n public setStepId(newStepId: number): void {\r\n this._currentStepId = newStepId;\r\n }\r\n\r\n /**\r\n * Gets the step Id used by deterministic lock step\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n * @returns the step Id\r\n */\r\n public getStepId(): number {\r\n return this._currentStepId;\r\n }\r\n\r\n /**\r\n * Gets the internal step used by deterministic lock step\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n * @returns the internal step\r\n */\r\n public getInternalStep(): number {\r\n return this._currentInternalStep;\r\n }\r\n\r\n // Fog\r\n\r\n private _fogEnabled = true;\r\n /**\r\n * Gets or sets a boolean indicating if fog is enabled on this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\r\n * (Default is true)\r\n */\r\n public set fogEnabled(value: boolean) {\r\n if (this._fogEnabled === value) {\r\n return;\r\n }\r\n this._fogEnabled = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_MiscDirtyFlag);\r\n }\r\n public get fogEnabled(): boolean {\r\n return this._fogEnabled;\r\n }\r\n\r\n private _fogMode = Scene.FOGMODE_NONE;\r\n /**\r\n * Gets or sets the fog mode to use\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\r\n * | mode | value |\r\n * | --- | --- |\r\n * | FOGMODE_NONE | 0 |\r\n * | FOGMODE_EXP | 1 |\r\n * | FOGMODE_EXP2 | 2 |\r\n * | FOGMODE_LINEAR | 3 |\r\n */\r\n public set fogMode(value: number) {\r\n if (this._fogMode === value) {\r\n return;\r\n }\r\n this._fogMode = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_MiscDirtyFlag);\r\n }\r\n public get fogMode(): number {\r\n return this._fogMode;\r\n }\r\n\r\n /**\r\n * Gets or sets the fog color to use\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\r\n * (Default is Color3(0.2, 0.2, 0.3))\r\n */\r\n public fogColor = new Color3(0.2, 0.2, 0.3);\r\n /**\r\n * Gets or sets the fog density to use\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\r\n * (Default is 0.1)\r\n */\r\n public fogDensity = 0.1;\r\n /**\r\n * Gets or sets the fog start distance to use\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\r\n * (Default is 0)\r\n */\r\n public fogStart = 0;\r\n /**\r\n * Gets or sets the fog end distance to use\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/environment_introduction#fog\r\n * (Default is 1000)\r\n */\r\n public fogEnd = 1000.0;\r\n\r\n /**\r\n * Flag indicating that the frame buffer binding is handled by another component\r\n */\r\n public get prePass(): boolean {\r\n return !!this.prePassRenderer && this.prePassRenderer.defaultRT.enabled;\r\n }\r\n\r\n /**\r\n * Flag indicating if we need to store previous matrices when rendering\r\n */\r\n public needsPreviousWorldMatrices = false;\r\n\r\n // Lights\r\n private _shadowsEnabled = true;\r\n /**\r\n * Gets or sets a boolean indicating if shadows are enabled on this scene\r\n */\r\n public set shadowsEnabled(value: boolean) {\r\n if (this._shadowsEnabled === value) {\r\n return;\r\n }\r\n this._shadowsEnabled = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_LightDirtyFlag);\r\n }\r\n public get shadowsEnabled(): boolean {\r\n return this._shadowsEnabled;\r\n }\r\n\r\n private _lightsEnabled = true;\r\n /**\r\n * Gets or sets a boolean indicating if lights are enabled on this scene\r\n */\r\n public set lightsEnabled(value: boolean) {\r\n if (this._lightsEnabled === value) {\r\n return;\r\n }\r\n this._lightsEnabled = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_LightDirtyFlag);\r\n }\r\n\r\n public get lightsEnabled(): boolean {\r\n return this._lightsEnabled;\r\n }\r\n\r\n private _activeCameras: Nullable;\r\n private _unObserveActiveCameras: Nullable<() => void> = null;\r\n\r\n /** All of the active cameras added to this scene. */\r\n public get activeCameras(): Nullable {\r\n return this._activeCameras;\r\n }\r\n\r\n public set activeCameras(cameras: Nullable) {\r\n if (this._unObserveActiveCameras) {\r\n this._unObserveActiveCameras();\r\n this._unObserveActiveCameras = null;\r\n }\r\n\r\n if (cameras) {\r\n this._unObserveActiveCameras = _ObserveArray(cameras, () => {\r\n this.onActiveCamerasChanged.notifyObservers(this);\r\n });\r\n }\r\n\r\n this._activeCameras = cameras;\r\n }\r\n\r\n /** @internal */\r\n public _activeCamera: Nullable;\r\n /** Gets or sets the current active camera */\r\n public get activeCamera(): Nullable {\r\n return this._activeCamera;\r\n }\r\n\r\n public set activeCamera(value: Nullable) {\r\n if (value === this._activeCamera) {\r\n return;\r\n }\r\n\r\n this._activeCamera = value;\r\n this.onActiveCameraChanged.notifyObservers(this);\r\n }\r\n\r\n private _defaultMaterial: Material;\r\n\r\n /** The default material used on meshes when no material is affected */\r\n public get defaultMaterial(): Material {\r\n if (!this._defaultMaterial) {\r\n this._defaultMaterial = Scene.DefaultMaterialFactory(this);\r\n }\r\n\r\n return this._defaultMaterial;\r\n }\r\n\r\n /** The default material used on meshes when no material is affected */\r\n public set defaultMaterial(value: Material) {\r\n this._defaultMaterial = value;\r\n }\r\n\r\n // Textures\r\n private _texturesEnabled = true;\r\n /**\r\n * Gets or sets a boolean indicating if textures are enabled on this scene\r\n */\r\n public set texturesEnabled(value: boolean) {\r\n if (this._texturesEnabled === value) {\r\n return;\r\n }\r\n this._texturesEnabled = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n public get texturesEnabled(): boolean {\r\n return this._texturesEnabled;\r\n }\r\n\r\n // Physics\r\n /**\r\n * Gets or sets a boolean indicating if physic engines are enabled on this scene\r\n */\r\n public physicsEnabled = true;\r\n\r\n // Particles\r\n /**\r\n * Gets or sets a boolean indicating if particles are enabled on this scene\r\n */\r\n public particlesEnabled = true;\r\n\r\n // Sprites\r\n /**\r\n * Gets or sets a boolean indicating if sprites are enabled on this scene\r\n */\r\n public spritesEnabled = true;\r\n\r\n // Skeletons\r\n private _skeletonsEnabled = true;\r\n /**\r\n * Gets or sets a boolean indicating if skeletons are enabled on this scene\r\n */\r\n public set skeletonsEnabled(value: boolean) {\r\n if (this._skeletonsEnabled === value) {\r\n return;\r\n }\r\n this._skeletonsEnabled = value;\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_AttributesDirtyFlag);\r\n }\r\n\r\n public get skeletonsEnabled(): boolean {\r\n return this._skeletonsEnabled;\r\n }\r\n\r\n // Lens flares\r\n /**\r\n * Gets or sets a boolean indicating if lens flares are enabled on this scene\r\n */\r\n public lensFlaresEnabled = true;\r\n\r\n // Collisions\r\n /**\r\n * Gets or sets a boolean indicating if collisions are enabled on this scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n */\r\n public collisionsEnabled = true;\r\n\r\n private _collisionCoordinator: ICollisionCoordinator;\r\n\r\n /** @internal */\r\n public get collisionCoordinator(): ICollisionCoordinator {\r\n if (!this._collisionCoordinator) {\r\n this._collisionCoordinator = Scene.CollisionCoordinatorFactory();\r\n this._collisionCoordinator.init(this);\r\n }\r\n\r\n return this._collisionCoordinator;\r\n }\r\n\r\n /**\r\n * Defines the gravity applied to this scene (used only for collisions)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n */\r\n public gravity = new Vector3(0, -9.807, 0);\r\n\r\n // Postprocesses\r\n /**\r\n * Gets or sets a boolean indicating if postprocesses are enabled on this scene\r\n */\r\n public postProcessesEnabled = true;\r\n /**\r\n * Gets the current postprocess manager\r\n */\r\n public postProcessManager: PostProcessManager;\r\n\r\n // Customs render targets\r\n /**\r\n * Gets or sets a boolean indicating if render targets are enabled on this scene\r\n */\r\n public renderTargetsEnabled = true;\r\n /**\r\n * Gets or sets a boolean indicating if next render targets must be dumped as image for debugging purposes\r\n * We recommend not using it and instead rely on Spector.js: http://spector.babylonjs.com\r\n */\r\n public dumpNextRenderTargets = false;\r\n /**\r\n * The list of user defined render targets added to the scene\r\n */\r\n public customRenderTargets = new Array();\r\n\r\n /**\r\n * Defines if texture loading must be delayed\r\n * If true, textures will only be loaded when they need to be rendered\r\n */\r\n public useDelayedTextureLoading: boolean;\r\n\r\n /**\r\n * Gets the list of meshes imported to the scene through SceneLoader\r\n */\r\n public importedMeshesFiles = new Array();\r\n\r\n // Probes\r\n /**\r\n * Gets or sets a boolean indicating if probes are enabled on this scene\r\n */\r\n public probesEnabled = true;\r\n\r\n // Offline support\r\n /**\r\n * Gets or sets the current offline provider to use to store scene data\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeCached\r\n */\r\n public offlineProvider: IOfflineProvider;\r\n\r\n /**\r\n * Gets or sets the action manager associated with the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions\r\n */\r\n public actionManager: AbstractActionManager;\r\n\r\n private _meshesForIntersections = new SmartArrayNoDuplicate(256);\r\n\r\n // Procedural textures\r\n /**\r\n * Gets or sets a boolean indicating if procedural textures are enabled on this scene\r\n */\r\n public proceduralTexturesEnabled = true;\r\n\r\n // Private\r\n private _engine: Engine;\r\n\r\n // Performance counters\r\n private _totalVertices = new PerfCounter();\r\n /** @internal */\r\n public _activeIndices = new PerfCounter();\r\n /** @internal */\r\n public _activeParticles = new PerfCounter();\r\n /** @internal */\r\n public _activeBones = new PerfCounter();\r\n\r\n private _animationRatio: number;\r\n\r\n /** @internal */\r\n public _animationTimeLast: number;\r\n\r\n /** @internal */\r\n public _animationTime: number = 0;\r\n\r\n /**\r\n * Gets or sets a general scale for animation speed\r\n * @see https://www.babylonjs-playground.com/#IBU2W7#3\r\n */\r\n public animationTimeScale: number = 1;\r\n\r\n /** @internal */\r\n public _cachedMaterial: Nullable;\r\n /** @internal */\r\n public _cachedEffect: Nullable;\r\n /** @internal */\r\n public _cachedVisibility: Nullable;\r\n\r\n private _renderId = 0;\r\n private _frameId = 0;\r\n private _executeWhenReadyTimeoutId: Nullable> = null;\r\n private _intermediateRendering = false;\r\n private _defaultFrameBufferCleared = false;\r\n\r\n private _viewUpdateFlag = -1;\r\n private _projectionUpdateFlag = -1;\r\n\r\n /** @internal */\r\n public _toBeDisposed = new Array>(256);\r\n private _activeRequests = new Array();\r\n\r\n /** @internal */\r\n public _pendingData = new Array();\r\n private _isDisposed = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that all submeshes of active meshes must be rendered\r\n * Use this boolean to avoid computing frustum clipping on submeshes (This could help when you are CPU bound)\r\n */\r\n public dispatchAllSubMeshesOfActiveMeshes: boolean = false;\r\n private _activeMeshes = new SmartArray(256);\r\n private _processedMaterials = new SmartArray(256);\r\n private _renderTargets = new SmartArrayNoDuplicate(256);\r\n private _materialsRenderTargets = new SmartArrayNoDuplicate(256);\r\n /** @internal */\r\n public _activeParticleSystems = new SmartArray(256);\r\n private _activeSkeletons = new SmartArrayNoDuplicate(32);\r\n private _softwareSkinnedMeshes = new SmartArrayNoDuplicate(32);\r\n\r\n private _renderingManager: RenderingManager;\r\n\r\n /**\r\n * Gets the scene's rendering manager\r\n */\r\n public get renderingManager(): RenderingManager {\r\n return this._renderingManager;\r\n }\r\n\r\n /** @internal */\r\n public _activeAnimatables = new Array();\r\n\r\n private _transformMatrix = Matrix.Zero();\r\n private _sceneUbo: UniformBuffer;\r\n\r\n /** @internal */\r\n public _viewMatrix: Matrix;\r\n /** @internal */\r\n public _projectionMatrix: Matrix;\r\n /** @internal */\r\n public _forcedViewPosition: Nullable;\r\n\r\n /** @internal */\r\n public _frustumPlanes: Plane[];\r\n /**\r\n * Gets the list of frustum planes (built from the active camera)\r\n */\r\n public get frustumPlanes(): Plane[] {\r\n return this._frustumPlanes;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if lights must be sorted by priority (off by default)\r\n * This is useful if there are more lights that the maximum simulteanous authorized\r\n */\r\n public requireLightSorting = false;\r\n\r\n /** @internal */\r\n public readonly useMaterialMeshMap: boolean;\r\n /** @internal */\r\n public readonly useClonedMeshMap: boolean;\r\n\r\n private _externalData: StringDictionary;\r\n private _uid: Nullable;\r\n\r\n /**\r\n * @internal\r\n * Backing store of defined scene components.\r\n */\r\n public _components: ISceneComponent[] = [];\r\n\r\n /**\r\n * @internal\r\n * Backing store of defined scene components.\r\n */\r\n public _serializableComponents: ISceneSerializableComponent[] = [];\r\n\r\n /**\r\n * List of components to register on the next registration step.\r\n */\r\n private _transientComponents: ISceneComponent[] = [];\r\n\r\n /**\r\n * Registers the transient components if needed.\r\n */\r\n private _registerTransientComponents(): void {\r\n // Register components that have been associated lately to the scene.\r\n if (this._transientComponents.length > 0) {\r\n for (const component of this._transientComponents) {\r\n component.register();\r\n }\r\n this._transientComponents.length = 0;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Add a component to the scene.\r\n * Note that the ccomponent could be registered on th next frame if this is called after\r\n * the register component stage.\r\n * @param component Defines the component to add to the scene\r\n */\r\n public _addComponent(component: ISceneComponent) {\r\n this._components.push(component);\r\n this._transientComponents.push(component);\r\n\r\n const serializableComponent = component as any;\r\n if (serializableComponent.addFromContainer && serializableComponent.serialize) {\r\n this._serializableComponents.push(serializableComponent);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Gets a component from the scene.\r\n * @param name defines the name of the component to retrieve\r\n * @returns the component or null if not present\r\n */\r\n public _getComponent(name: string): Nullable {\r\n for (const component of this._components) {\r\n if (component.name === name) {\r\n return component;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Defines the actions happening before camera updates.\r\n */\r\n public _beforeCameraUpdateStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening before clear the canvas.\r\n */\r\n public _beforeClearStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening before clear the canvas.\r\n */\r\n public _beforeRenderTargetClearStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions when collecting render targets for the frame.\r\n */\r\n public _gatherRenderTargetsStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening for one camera in the frame.\r\n */\r\n public _gatherActiveCameraRenderTargetsStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening during the per mesh ready checks.\r\n */\r\n public _isReadyForMeshStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening before evaluate active mesh checks.\r\n */\r\n public _beforeEvaluateActiveMeshStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening during the evaluate sub mesh checks.\r\n */\r\n public _evaluateSubMeshStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening during the active mesh stage.\r\n */\r\n public _preActiveMeshStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening during the per camera render target step.\r\n */\r\n public _cameraDrawRenderTargetStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just before the active camera is drawing.\r\n */\r\n public _beforeCameraDrawStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just before a render target is drawing.\r\n */\r\n public _beforeRenderTargetDrawStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just before a rendering group is drawing.\r\n */\r\n public _beforeRenderingGroupDrawStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just before a mesh is drawing.\r\n */\r\n public _beforeRenderingMeshStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just after a mesh has been drawn.\r\n */\r\n public _afterRenderingMeshStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just after a rendering group has been drawn.\r\n */\r\n public _afterRenderingGroupDrawStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just after the active camera has been drawn.\r\n */\r\n public _afterCameraDrawStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just after the post processing\r\n */\r\n public _afterCameraPostProcessStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just after a render target has been drawn.\r\n */\r\n public _afterRenderTargetDrawStage = Stage.Create();\r\n /**\r\n * Defines the actions happening just after the post processing on a render target\r\n */\r\n public _afterRenderTargetPostProcessStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening just after rendering all cameras and computing intersections.\r\n */\r\n public _afterRenderStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening when a pointer move event happens.\r\n */\r\n public _pointerMoveStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening when a pointer down event happens.\r\n */\r\n public _pointerDownStage = Stage.Create();\r\n /**\r\n * @internal\r\n * Defines the actions happening when a pointer up event happens.\r\n */\r\n public _pointerUpStage = Stage.Create();\r\n\r\n /**\r\n * an optional map from Geometry Id to Geometry index in the 'geometries' array\r\n */\r\n private _geometriesByUniqueId: Nullable<{ [uniqueId: string]: number | undefined }> = null;\r\n\r\n /**\r\n * Creates a new Scene\r\n * @param engine defines the engine to use to render this scene\r\n * @param options defines the scene options\r\n */\r\n constructor(engine: Engine, options?: SceneOptions) {\r\n super();\r\n\r\n this.activeCameras = new Array();\r\n\r\n const fullOptions = {\r\n useGeometryUniqueIdsMap: true,\r\n useMaterialMeshMap: true,\r\n useClonedMeshMap: true,\r\n virtual: false,\r\n ...options,\r\n };\r\n\r\n this._engine = engine || EngineStore.LastCreatedEngine;\r\n if (!fullOptions.virtual) {\r\n EngineStore._LastCreatedScene = this;\r\n this._engine.scenes.push(this);\r\n } else {\r\n this._engine._virtualScenes.push(this);\r\n }\r\n\r\n this._uid = null;\r\n\r\n this._renderingManager = new RenderingManager(this);\r\n\r\n if (PostProcessManager) {\r\n this.postProcessManager = new PostProcessManager(this);\r\n }\r\n\r\n if (IsWindowObjectExist()) {\r\n this.attachControl();\r\n }\r\n\r\n // Uniform Buffer\r\n this._createUbo();\r\n\r\n // Default Image processing definition\r\n if (ImageProcessingConfiguration) {\r\n this._imageProcessingConfiguration = new ImageProcessingConfiguration();\r\n }\r\n\r\n this.setDefaultCandidateProviders();\r\n\r\n if (fullOptions.useGeometryUniqueIdsMap) {\r\n this._geometriesByUniqueId = {};\r\n }\r\n\r\n this.useMaterialMeshMap = fullOptions.useMaterialMeshMap;\r\n this.useClonedMeshMap = fullOptions.useClonedMeshMap;\r\n\r\n if (!options || !options.virtual) {\r\n this._engine.onNewSceneAddedObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"Scene\" string\r\n */\r\n public getClassName(): string {\r\n return \"Scene\";\r\n }\r\n\r\n private _defaultMeshCandidates: ISmartArrayLike = {\r\n data: [],\r\n length: 0,\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getDefaultMeshCandidates(): ISmartArrayLike {\r\n this._defaultMeshCandidates.data = this.meshes;\r\n this._defaultMeshCandidates.length = this.meshes.length;\r\n return this._defaultMeshCandidates;\r\n }\r\n\r\n private _defaultSubMeshCandidates: ISmartArrayLike = {\r\n data: [],\r\n length: 0,\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getDefaultSubMeshCandidates(mesh: AbstractMesh): ISmartArrayLike {\r\n this._defaultSubMeshCandidates.data = mesh.subMeshes;\r\n this._defaultSubMeshCandidates.length = mesh.subMeshes.length;\r\n return this._defaultSubMeshCandidates;\r\n }\r\n\r\n /**\r\n * Sets the default candidate providers for the scene.\r\n * This sets the getActiveMeshCandidates, getActiveSubMeshCandidates, getIntersectingSubMeshCandidates\r\n * and getCollidingSubMeshCandidates to their default function\r\n */\r\n public setDefaultCandidateProviders(): void {\r\n this.getActiveMeshCandidates = this._getDefaultMeshCandidates.bind(this);\r\n\r\n this.getActiveSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);\r\n this.getIntersectingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);\r\n this.getCollidingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);\r\n }\r\n\r\n /**\r\n * Gets the mesh that is currently under the pointer\r\n */\r\n public get meshUnderPointer(): Nullable {\r\n return this._inputManager.meshUnderPointer;\r\n }\r\n\r\n /**\r\n * Gets or sets the current on-screen X position of the pointer\r\n */\r\n public get pointerX(): number {\r\n return this._inputManager.pointerX;\r\n }\r\n\r\n public set pointerX(value: number) {\r\n this._inputManager.pointerX = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the current on-screen Y position of the pointer\r\n */\r\n public get pointerY(): number {\r\n return this._inputManager.pointerY;\r\n }\r\n\r\n public set pointerY(value: number) {\r\n this._inputManager.pointerY = value;\r\n }\r\n\r\n /**\r\n * Gets the cached material (ie. the latest rendered one)\r\n * @returns the cached material\r\n */\r\n public getCachedMaterial(): Nullable {\r\n return this._cachedMaterial;\r\n }\r\n\r\n /**\r\n * Gets the cached effect (ie. the latest rendered one)\r\n * @returns the cached effect\r\n */\r\n public getCachedEffect(): Nullable {\r\n return this._cachedEffect;\r\n }\r\n\r\n /**\r\n * Gets the cached visibility state (ie. the latest rendered one)\r\n * @returns the cached visibility state\r\n */\r\n public getCachedVisibility(): Nullable {\r\n return this._cachedVisibility;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the current material / effect / visibility must be bind again\r\n * @param material defines the current material\r\n * @param effect defines the current effect\r\n * @param visibility defines the current visibility state\r\n * @returns true if one parameter is not cached\r\n */\r\n public isCachedMaterialInvalid(material: Material, effect: Effect, visibility: number = 1) {\r\n return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;\r\n }\r\n\r\n /**\r\n * Gets the engine associated with the scene\r\n * @returns an Engine\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * Gets the total number of vertices rendered per frame\r\n * @returns the total number of vertices rendered per frame\r\n */\r\n public getTotalVertices(): number {\r\n return this._totalVertices.current;\r\n }\r\n\r\n /**\r\n * Gets the performance counter for total vertices\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\r\n */\r\n public get totalVerticesPerfCounter(): PerfCounter {\r\n return this._totalVertices;\r\n }\r\n\r\n /**\r\n * Gets the total number of active indices rendered per frame (You can deduce the number of rendered triangles by dividing this number by 3)\r\n * @returns the total number of active indices rendered per frame\r\n */\r\n public getActiveIndices(): number {\r\n return this._activeIndices.current;\r\n }\r\n\r\n /**\r\n * Gets the performance counter for active indices\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\r\n */\r\n public get totalActiveIndicesPerfCounter(): PerfCounter {\r\n return this._activeIndices;\r\n }\r\n\r\n /**\r\n * Gets the total number of active particles rendered per frame\r\n * @returns the total number of active particles rendered per frame\r\n */\r\n public getActiveParticles(): number {\r\n return this._activeParticles.current;\r\n }\r\n\r\n /**\r\n * Gets the performance counter for active particles\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\r\n */\r\n public get activeParticlesPerfCounter(): PerfCounter {\r\n return this._activeParticles;\r\n }\r\n\r\n /**\r\n * Gets the total number of active bones rendered per frame\r\n * @returns the total number of active bones rendered per frame\r\n */\r\n public getActiveBones(): number {\r\n return this._activeBones.current;\r\n }\r\n\r\n /**\r\n * Gets the performance counter for active bones\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#instrumentation\r\n */\r\n public get activeBonesPerfCounter(): PerfCounter {\r\n return this._activeBones;\r\n }\r\n\r\n /**\r\n * Gets the array of active meshes\r\n * @returns an array of AbstractMesh\r\n */\r\n public getActiveMeshes(): SmartArray {\r\n return this._activeMeshes;\r\n }\r\n\r\n /**\r\n * Gets the animation ratio (which is 1.0 is the scene renders at 60fps and 2 if the scene renders at 30fps, etc.)\r\n * @returns a number\r\n */\r\n public getAnimationRatio(): number {\r\n return this._animationRatio !== undefined ? this._animationRatio : 1;\r\n }\r\n\r\n /**\r\n * Gets an unique Id for the current render phase\r\n * @returns a number\r\n */\r\n public getRenderId(): number {\r\n return this._renderId;\r\n }\r\n\r\n /**\r\n * Gets an unique Id for the current frame\r\n * @returns a number\r\n */\r\n public getFrameId(): number {\r\n return this._frameId;\r\n }\r\n\r\n /** Call this function if you want to manually increment the render Id*/\r\n public incrementRenderId(): void {\r\n this._renderId++;\r\n }\r\n\r\n private _createUbo(): void {\r\n this.setSceneUniformBuffer(this.createSceneUniformBuffer());\r\n }\r\n\r\n /**\r\n * Use this method to simulate a pointer move on a mesh\r\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\r\n * @param pickResult pickingInfo of the object wished to simulate pointer event on\r\n * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\r\n * @returns the current scene\r\n */\r\n public simulatePointerMove(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): Scene {\r\n this._inputManager.simulatePointerMove(pickResult, pointerEventInit);\r\n return this;\r\n }\r\n\r\n /**\r\n * Use this method to simulate a pointer down on a mesh\r\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\r\n * @param pickResult pickingInfo of the object wished to simulate pointer event on\r\n * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\r\n * @returns the current scene\r\n */\r\n public simulatePointerDown(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): Scene {\r\n this._inputManager.simulatePointerDown(pickResult, pointerEventInit);\r\n return this;\r\n }\r\n\r\n /**\r\n * Use this method to simulate a pointer up on a mesh\r\n * The pickResult parameter can be obtained from a scene.pick or scene.pickWithRay\r\n * @param pickResult pickingInfo of the object wished to simulate pointer event on\r\n * @param pointerEventInit pointer event state to be used when simulating the pointer event (eg. pointer id for multitouch)\r\n * @param doubleTap indicates that the pointer up event should be considered as part of a double click (false by default)\r\n * @returns the current scene\r\n */\r\n public simulatePointerUp(pickResult: PickingInfo, pointerEventInit?: PointerEventInit, doubleTap?: boolean): Scene {\r\n this._inputManager.simulatePointerUp(pickResult, pointerEventInit, doubleTap);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the current pointer event is captured (meaning that the scene has already handled the pointer down)\r\n * @param pointerId defines the pointer id to use in a multi-touch scenario (0 by default)\r\n * @returns true if the pointer was captured\r\n */\r\n public isPointerCaptured(pointerId = 0): boolean {\r\n return this._inputManager.isPointerCaptured(pointerId);\r\n }\r\n\r\n /**\r\n * Attach events to the canvas (To handle actionManagers triggers and raise onPointerMove, onPointerDown and onPointerUp\r\n * @param attachUp defines if you want to attach events to pointerup\r\n * @param attachDown defines if you want to attach events to pointerdown\r\n * @param attachMove defines if you want to attach events to pointermove\r\n */\r\n public attachControl(attachUp = true, attachDown = true, attachMove = true): void {\r\n this._inputManager.attachControl(attachUp, attachDown, attachMove);\r\n }\r\n\r\n /** Detaches all event handlers*/\r\n public detachControl() {\r\n this._inputManager.detachControl();\r\n }\r\n\r\n /**\r\n * This function will check if the scene can be rendered (textures are loaded, shaders are compiled)\r\n * Delay loaded resources are not taking in account\r\n * @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: true)\r\n * @returns true if all required resources are ready\r\n */\r\n public isReady(checkRenderTargets = true): boolean {\r\n if (this._isDisposed) {\r\n return false;\r\n }\r\n\r\n let index: number;\r\n const engine = this.getEngine();\r\n\r\n const currentRenderPassId = engine.currentRenderPassId;\r\n\r\n engine.currentRenderPassId = this.activeCamera?.renderPassId ?? currentRenderPassId;\r\n\r\n let isReady = true;\r\n\r\n // Pending data\r\n if (this._pendingData.length > 0) {\r\n isReady = false;\r\n }\r\n\r\n // Ensures that the pre-pass renderer is enabled if it is to be enabled.\r\n this.prePassRenderer?.update();\r\n\r\n // Meshes\r\n if (checkRenderTargets) {\r\n this._processedMaterials.reset();\r\n this._materialsRenderTargets.reset();\r\n }\r\n\r\n for (index = 0; index < this.meshes.length; index++) {\r\n const mesh = this.meshes[index];\r\n\r\n if (!mesh.subMeshes || mesh.subMeshes.length === 0) {\r\n continue;\r\n }\r\n\r\n // Do not stop at the first encountered \"unready\" object as we want to ensure\r\n // all materials are starting off their compilation in parallel.\r\n if (!mesh.isReady(true)) {\r\n isReady = false;\r\n continue;\r\n }\r\n\r\n const hardwareInstancedRendering =\r\n mesh.hasThinInstances ||\r\n mesh.getClassName() === \"InstancedMesh\" ||\r\n mesh.getClassName() === \"InstancedLinesMesh\" ||\r\n (engine.getCaps().instancedArrays && (mesh).instances.length > 0);\r\n // Is Ready For Mesh\r\n for (const step of this._isReadyForMeshStage) {\r\n if (!step.action(mesh, hardwareInstancedRendering)) {\r\n isReady = false;\r\n }\r\n }\r\n\r\n if (!checkRenderTargets) {\r\n continue;\r\n }\r\n\r\n const mat = mesh.material || this.defaultMaterial;\r\n if (mat) {\r\n if (mat._storeEffectOnSubMeshes) {\r\n for (const subMesh of mesh.subMeshes) {\r\n const material = subMesh.getMaterial();\r\n if (material && material.hasRenderTargetTextures && material.getRenderTargetTextures != null) {\r\n if (this._processedMaterials.indexOf(material) === -1) {\r\n this._processedMaterials.push(material);\r\n\r\n this._materialsRenderTargets.concatWithNoDuplicate(material.getRenderTargetTextures!());\r\n }\r\n }\r\n }\r\n } else {\r\n if (mat.hasRenderTargetTextures && mat.getRenderTargetTextures != null) {\r\n if (this._processedMaterials.indexOf(mat) === -1) {\r\n this._processedMaterials.push(mat);\r\n\r\n this._materialsRenderTargets.concatWithNoDuplicate(mat.getRenderTargetTextures!());\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Render targets\r\n if (checkRenderTargets) {\r\n for (index = 0; index < this._materialsRenderTargets.length; ++index) {\r\n const rtt = this._materialsRenderTargets.data[index];\r\n if (!rtt.isReadyForRendering()) {\r\n isReady = false;\r\n }\r\n }\r\n }\r\n\r\n // Geometries\r\n for (index = 0; index < this.geometries.length; index++) {\r\n const geometry = this.geometries[index];\r\n\r\n if (geometry.delayLoadState === Constants.DELAYLOADSTATE_LOADING) {\r\n isReady = false;\r\n }\r\n }\r\n\r\n // Post-processes\r\n if (this.activeCameras && this.activeCameras.length > 0) {\r\n for (const camera of this.activeCameras) {\r\n if (!camera.isReady(true)) {\r\n isReady = false;\r\n }\r\n }\r\n } else if (this.activeCamera) {\r\n if (!this.activeCamera.isReady(true)) {\r\n isReady = false;\r\n }\r\n }\r\n\r\n // Particles\r\n for (const particleSystem of this.particleSystems) {\r\n if (!particleSystem.isReady()) {\r\n isReady = false;\r\n }\r\n }\r\n\r\n // Layers\r\n if (this.layers) {\r\n for (const layer of this.layers) {\r\n if (!layer.isReady()) {\r\n isReady = false;\r\n }\r\n }\r\n }\r\n\r\n // Effects\r\n if (!engine.areAllEffectsReady()) {\r\n isReady = false;\r\n }\r\n\r\n engine.currentRenderPassId = currentRenderPassId;\r\n\r\n return isReady;\r\n }\r\n\r\n /** Resets all cached information relative to material (including effect and visibility) */\r\n public resetCachedMaterial(): void {\r\n this._cachedMaterial = null;\r\n this._cachedEffect = null;\r\n this._cachedVisibility = null;\r\n }\r\n\r\n /**\r\n * Registers a function to be called before every frame render\r\n * @param func defines the function to register\r\n */\r\n public registerBeforeRender(func: () => void): void {\r\n this.onBeforeRenderObservable.add(func);\r\n }\r\n\r\n /**\r\n * Unregisters a function called before every frame render\r\n * @param func defines the function to unregister\r\n */\r\n public unregisterBeforeRender(func: () => void): void {\r\n this.onBeforeRenderObservable.removeCallback(func);\r\n }\r\n\r\n /**\r\n * Registers a function to be called after every frame render\r\n * @param func defines the function to register\r\n */\r\n public registerAfterRender(func: () => void): void {\r\n this.onAfterRenderObservable.add(func);\r\n }\r\n\r\n /**\r\n * Unregisters a function called after every frame render\r\n * @param func defines the function to unregister\r\n */\r\n public unregisterAfterRender(func: () => void): void {\r\n this.onAfterRenderObservable.removeCallback(func);\r\n }\r\n\r\n private _executeOnceBeforeRender(func: () => void): void {\r\n const execFunc = () => {\r\n func();\r\n setTimeout(() => {\r\n this.unregisterBeforeRender(execFunc);\r\n });\r\n };\r\n this.registerBeforeRender(execFunc);\r\n }\r\n\r\n /**\r\n * The provided function will run before render once and will be disposed afterwards.\r\n * A timeout delay can be provided so that the function will be executed in N ms.\r\n * The timeout is using the browser's native setTimeout so time percision cannot be guaranteed.\r\n * @param func The function to be executed.\r\n * @param timeout optional delay in ms\r\n */\r\n public executeOnceBeforeRender(func: () => void, timeout?: number): void {\r\n if (timeout !== undefined) {\r\n setTimeout(() => {\r\n this._executeOnceBeforeRender(func);\r\n }, timeout);\r\n } else {\r\n this._executeOnceBeforeRender(func);\r\n }\r\n }\r\n\r\n /**\r\n * This function can help adding any object to the list of data awaited to be ready in order to check for a complete scene loading.\r\n * @param data defines the object to wait for\r\n */\r\n public addPendingData(data: any): void {\r\n this._pendingData.push(data);\r\n }\r\n\r\n /**\r\n * Remove a pending data from the loading list which has previously been added with addPendingData.\r\n * @param data defines the object to remove from the pending list\r\n */\r\n public removePendingData(data: any): void {\r\n const wasLoading = this.isLoading;\r\n const index = this._pendingData.indexOf(data);\r\n\r\n if (index !== -1) {\r\n this._pendingData.splice(index, 1);\r\n }\r\n\r\n if (wasLoading && !this.isLoading) {\r\n this.onDataLoadedObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the number of items waiting to be loaded\r\n * @returns the number of items waiting to be loaded\r\n */\r\n public getWaitingItemsCount(): number {\r\n return this._pendingData.length;\r\n }\r\n\r\n /**\r\n * Returns a boolean indicating if the scene is still loading data\r\n */\r\n public get isLoading(): boolean {\r\n return this._pendingData.length > 0;\r\n }\r\n\r\n /**\r\n * Registers a function to be executed when the scene is ready\r\n * @param func - the function to be executed\r\n * @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: false)\r\n */\r\n public executeWhenReady(func: () => void, checkRenderTargets = false): void {\r\n this.onReadyObservable.addOnce(func);\r\n\r\n if (this._executeWhenReadyTimeoutId !== null) {\r\n return;\r\n }\r\n\r\n this._checkIsReady(checkRenderTargets);\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when the scene is ready\r\n * @param checkRenderTargets true to also check that the meshes rendered as part of a render target are ready (default: false)\r\n * @returns A promise that resolves when the scene is ready\r\n */\r\n public whenReadyAsync(checkRenderTargets = false): Promise {\r\n return new Promise((resolve) => {\r\n this.executeWhenReady(() => {\r\n resolve();\r\n }, checkRenderTargets);\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _checkIsReady(checkRenderTargets = false) {\r\n this._registerTransientComponents();\r\n\r\n if (this.isReady(checkRenderTargets)) {\r\n this.onReadyObservable.notifyObservers(this);\r\n\r\n this.onReadyObservable.clear();\r\n this._executeWhenReadyTimeoutId = null;\r\n return;\r\n }\r\n\r\n if (this._isDisposed) {\r\n this.onReadyObservable.clear();\r\n this._executeWhenReadyTimeoutId = null;\r\n return;\r\n }\r\n\r\n this._executeWhenReadyTimeoutId = setTimeout(() => {\r\n // Ensure materials effects are checked outside render loops\r\n this.incrementRenderId();\r\n this._checkIsReady(checkRenderTargets);\r\n }, 100);\r\n }\r\n\r\n /**\r\n * Gets all animatable attached to the scene\r\n */\r\n public get animatables(): Animatable[] {\r\n return this._activeAnimatables;\r\n }\r\n\r\n /**\r\n * Resets the last animation time frame.\r\n * Useful to override when animations start running when loading a scene for the first time.\r\n */\r\n public resetLastAnimationTimeFrame(): void {\r\n this._animationTimeLast = PrecisionDate.Now;\r\n }\r\n\r\n // Matrix\r\n\r\n /**\r\n * Gets the current view matrix\r\n * @returns a Matrix\r\n */\r\n public getViewMatrix(): Matrix {\r\n return this._viewMatrix;\r\n }\r\n\r\n /**\r\n * Gets the current projection matrix\r\n * @returns a Matrix\r\n */\r\n public getProjectionMatrix(): Matrix {\r\n return this._projectionMatrix;\r\n }\r\n\r\n /**\r\n * Gets the current transform matrix\r\n * @returns a Matrix made of View * Projection\r\n */\r\n public getTransformMatrix(): Matrix {\r\n return this._transformMatrix;\r\n }\r\n\r\n /**\r\n * Sets the current transform matrix\r\n * @param viewL defines the View matrix to use\r\n * @param projectionL defines the Projection matrix to use\r\n * @param viewR defines the right View matrix to use (if provided)\r\n * @param projectionR defines the right Projection matrix to use (if provided)\r\n */\r\n public setTransformMatrix(viewL: Matrix, projectionL: Matrix, viewR?: Matrix, projectionR?: Matrix): void {\r\n // clear the multiviewSceneUbo if no viewR and projectionR are defined\r\n if (!viewR && !projectionR && this._multiviewSceneUbo) {\r\n this._multiviewSceneUbo.dispose();\r\n this._multiviewSceneUbo = null;\r\n }\r\n if (this._viewUpdateFlag === viewL.updateFlag && this._projectionUpdateFlag === projectionL.updateFlag) {\r\n return;\r\n }\r\n\r\n this._viewUpdateFlag = viewL.updateFlag;\r\n this._projectionUpdateFlag = projectionL.updateFlag;\r\n this._viewMatrix = viewL;\r\n this._projectionMatrix = projectionL;\r\n\r\n this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);\r\n\r\n // Update frustum\r\n if (!this._frustumPlanes) {\r\n this._frustumPlanes = Frustum.GetPlanes(this._transformMatrix);\r\n } else {\r\n Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);\r\n }\r\n\r\n if (this._multiviewSceneUbo && this._multiviewSceneUbo.useUbo) {\r\n this._updateMultiviewUbo(viewR, projectionR);\r\n } else if (this._sceneUbo.useUbo) {\r\n this._sceneUbo.updateMatrix(\"viewProjection\", this._transformMatrix);\r\n this._sceneUbo.updateMatrix(\"view\", this._viewMatrix);\r\n this._sceneUbo.updateMatrix(\"projection\", this._projectionMatrix);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the uniform buffer used to store scene data\r\n * @returns a UniformBuffer\r\n */\r\n public getSceneUniformBuffer(): UniformBuffer {\r\n return this._multiviewSceneUbo ? this._multiviewSceneUbo : this._sceneUbo;\r\n }\r\n\r\n /**\r\n * Creates a scene UBO\r\n * @param name name of the uniform buffer (optional, for debugging purpose only)\r\n * @returns a new ubo\r\n */\r\n public createSceneUniformBuffer(name?: string): UniformBuffer {\r\n const sceneUbo = new UniformBuffer(this._engine, undefined, false, name ?? \"scene\");\r\n sceneUbo.addUniform(\"viewProjection\", 16);\r\n sceneUbo.addUniform(\"view\", 16);\r\n sceneUbo.addUniform(\"projection\", 16);\r\n sceneUbo.addUniform(\"vEyePosition\", 4);\r\n\r\n return sceneUbo;\r\n }\r\n\r\n /**\r\n * Sets the scene ubo\r\n * @param ubo the ubo to set for the scene\r\n */\r\n public setSceneUniformBuffer(ubo: UniformBuffer): void {\r\n this._sceneUbo = ubo;\r\n this._viewUpdateFlag = -1;\r\n this._projectionUpdateFlag = -1;\r\n }\r\n\r\n /**\r\n * Gets an unique (relatively to the current scene) Id\r\n * @returns an unique number for the scene\r\n */\r\n public getUniqueId() {\r\n return UniqueIdGenerator.UniqueId;\r\n }\r\n\r\n /**\r\n * Add a mesh to the list of scene's meshes\r\n * @param newMesh defines the mesh to add\r\n * @param recursive if all child meshes should also be added to the scene\r\n */\r\n public addMesh(newMesh: AbstractMesh, recursive = false) {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n\r\n this.meshes.push(newMesh);\r\n\r\n newMesh._resyncLightSources();\r\n\r\n if (!newMesh.parent) {\r\n newMesh._addToSceneRootNodes();\r\n }\r\n\r\n this.onNewMeshAddedObservable.notifyObservers(newMesh);\r\n\r\n if (recursive) {\r\n newMesh.getChildMeshes().forEach((m) => {\r\n this.addMesh(m);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Remove a mesh for the list of scene's meshes\r\n * @param toRemove defines the mesh to remove\r\n * @param recursive if all child meshes should also be removed from the scene\r\n * @returns the index where the mesh was in the mesh list\r\n */\r\n public removeMesh(toRemove: AbstractMesh, recursive = false): number {\r\n const index = this.meshes.indexOf(toRemove);\r\n if (index !== -1) {\r\n // Remove from the scene if mesh found\r\n this.meshes[index] = this.meshes[this.meshes.length - 1];\r\n this.meshes.pop();\r\n\r\n if (!toRemove.parent) {\r\n toRemove._removeFromSceneRootNodes();\r\n }\r\n }\r\n\r\n this._inputManager._invalidateMesh(toRemove);\r\n\r\n this.onMeshRemovedObservable.notifyObservers(toRemove);\r\n if (recursive) {\r\n toRemove.getChildMeshes().forEach((m) => {\r\n this.removeMesh(m);\r\n });\r\n }\r\n return index;\r\n }\r\n\r\n /**\r\n * Add a transform node to the list of scene's transform nodes\r\n * @param newTransformNode defines the transform node to add\r\n */\r\n public addTransformNode(newTransformNode: TransformNode) {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n\r\n if (newTransformNode.getScene() === this && newTransformNode._indexInSceneTransformNodesArray !== -1) {\r\n // Already there?\r\n return;\r\n }\r\n\r\n newTransformNode._indexInSceneTransformNodesArray = this.transformNodes.length;\r\n this.transformNodes.push(newTransformNode);\r\n\r\n if (!newTransformNode.parent) {\r\n newTransformNode._addToSceneRootNodes();\r\n }\r\n\r\n this.onNewTransformNodeAddedObservable.notifyObservers(newTransformNode);\r\n }\r\n\r\n /**\r\n * Remove a transform node for the list of scene's transform nodes\r\n * @param toRemove defines the transform node to remove\r\n * @returns the index where the transform node was in the transform node list\r\n */\r\n public removeTransformNode(toRemove: TransformNode): number {\r\n const index = toRemove._indexInSceneTransformNodesArray;\r\n if (index !== -1) {\r\n if (index !== this.transformNodes.length - 1) {\r\n const lastNode = this.transformNodes[this.transformNodes.length - 1];\r\n this.transformNodes[index] = lastNode;\r\n lastNode._indexInSceneTransformNodesArray = index;\r\n }\r\n\r\n toRemove._indexInSceneTransformNodesArray = -1;\r\n this.transformNodes.pop();\r\n if (!toRemove.parent) {\r\n toRemove._removeFromSceneRootNodes();\r\n }\r\n }\r\n\r\n this.onTransformNodeRemovedObservable.notifyObservers(toRemove);\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Remove a skeleton for the list of scene's skeletons\r\n * @param toRemove defines the skeleton to remove\r\n * @returns the index where the skeleton was in the skeleton list\r\n */\r\n public removeSkeleton(toRemove: Skeleton): number {\r\n const index = this.skeletons.indexOf(toRemove);\r\n if (index !== -1) {\r\n // Remove from the scene if found\r\n this.skeletons.splice(index, 1);\r\n this.onSkeletonRemovedObservable.notifyObservers(toRemove);\r\n\r\n // Clean active container\r\n this._executeActiveContainerCleanup(this._activeSkeletons);\r\n }\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Remove a morph target for the list of scene's morph targets\r\n * @param toRemove defines the morph target to remove\r\n * @returns the index where the morph target was in the morph target list\r\n */\r\n public removeMorphTargetManager(toRemove: MorphTargetManager): number {\r\n const index = this.morphTargetManagers.indexOf(toRemove);\r\n if (index !== -1) {\r\n // Remove from the scene if found\r\n this.morphTargetManagers.splice(index, 1);\r\n }\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Remove a light for the list of scene's lights\r\n * @param toRemove defines the light to remove\r\n * @returns the index where the light was in the light list\r\n */\r\n public removeLight(toRemove: Light): number {\r\n const index = this.lights.indexOf(toRemove);\r\n if (index !== -1) {\r\n // Remove from meshes\r\n for (const mesh of this.meshes) {\r\n mesh._removeLightSource(toRemove, false);\r\n }\r\n\r\n // Remove from the scene if mesh found\r\n this.lights.splice(index, 1);\r\n this.sortLightsByPriority();\r\n\r\n if (!toRemove.parent) {\r\n toRemove._removeFromSceneRootNodes();\r\n }\r\n }\r\n this.onLightRemovedObservable.notifyObservers(toRemove);\r\n return index;\r\n }\r\n\r\n /**\r\n * Remove a camera for the list of scene's cameras\r\n * @param toRemove defines the camera to remove\r\n * @returns the index where the camera was in the camera list\r\n */\r\n public removeCamera(toRemove: Camera): number {\r\n const index = this.cameras.indexOf(toRemove);\r\n if (index !== -1) {\r\n // Remove from the scene if mesh found\r\n this.cameras.splice(index, 1);\r\n if (!toRemove.parent) {\r\n toRemove._removeFromSceneRootNodes();\r\n }\r\n }\r\n // Remove from activeCameras\r\n if (this.activeCameras) {\r\n const index2 = this.activeCameras.indexOf(toRemove);\r\n if (index2 !== -1) {\r\n // Remove from the scene if mesh found\r\n this.activeCameras.splice(index2, 1);\r\n }\r\n }\r\n // Reset the activeCamera\r\n if (this.activeCamera === toRemove) {\r\n if (this.cameras.length > 0) {\r\n this.activeCamera = this.cameras[0];\r\n } else {\r\n this.activeCamera = null;\r\n }\r\n }\r\n this.onCameraRemovedObservable.notifyObservers(toRemove);\r\n return index;\r\n }\r\n\r\n /**\r\n * Remove a particle system for the list of scene's particle systems\r\n * @param toRemove defines the particle system to remove\r\n * @returns the index where the particle system was in the particle system list\r\n */\r\n public removeParticleSystem(toRemove: IParticleSystem): number {\r\n const index = this.particleSystems.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.particleSystems.splice(index, 1);\r\n\r\n // Clean active container\r\n this._executeActiveContainerCleanup(this._activeParticleSystems);\r\n }\r\n return index;\r\n }\r\n\r\n /**\r\n * Remove a animation for the list of scene's animations\r\n * @param toRemove defines the animation to remove\r\n * @returns the index where the animation was in the animation list\r\n */\r\n public removeAnimation(toRemove: Animation): number {\r\n const index = this.animations.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.animations.splice(index, 1);\r\n }\r\n return index;\r\n }\r\n\r\n /**\r\n * Will stop the animation of the given target\r\n * @param target - the target\r\n * @param animationName - the name of the animation to stop (all animations will be stopped if both this and targetMask are empty)\r\n * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)\r\n */\r\n public stopAnimation(target: any, animationName?: string, targetMask?: (target: any) => boolean): void {\r\n // Do nothing as code will be provided by animation component\r\n }\r\n\r\n /**\r\n * Removes the given animation group from this scene.\r\n * @param toRemove The animation group to remove\r\n * @returns The index of the removed animation group\r\n */\r\n public removeAnimationGroup(toRemove: AnimationGroup): number {\r\n const index = this.animationGroups.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.animationGroups.splice(index, 1);\r\n }\r\n return index;\r\n }\r\n\r\n /**\r\n * Removes the given multi-material from this scene.\r\n * @param toRemove The multi-material to remove\r\n * @returns The index of the removed multi-material\r\n */\r\n public removeMultiMaterial(toRemove: MultiMaterial): number {\r\n const index = this.multiMaterials.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.multiMaterials.splice(index, 1);\r\n }\r\n\r\n this.onMultiMaterialRemovedObservable.notifyObservers(toRemove);\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Removes the given material from this scene.\r\n * @param toRemove The material to remove\r\n * @returns The index of the removed material\r\n */\r\n public removeMaterial(toRemove: Material): number {\r\n const index = toRemove._indexInSceneMaterialArray;\r\n if (index !== -1 && index < this.materials.length) {\r\n if (index !== this.materials.length - 1) {\r\n const lastMaterial = this.materials[this.materials.length - 1];\r\n this.materials[index] = lastMaterial;\r\n lastMaterial._indexInSceneMaterialArray = index;\r\n }\r\n\r\n toRemove._indexInSceneMaterialArray = -1;\r\n this.materials.pop();\r\n }\r\n\r\n this.onMaterialRemovedObservable.notifyObservers(toRemove);\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Removes the given action manager from this scene.\r\n * @deprecated\r\n * @param toRemove The action manager to remove\r\n * @returns The index of the removed action manager\r\n */\r\n public removeActionManager(toRemove: AbstractActionManager): number {\r\n const index = this.actionManagers.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.actionManagers.splice(index, 1);\r\n }\r\n return index;\r\n }\r\n\r\n /**\r\n * Removes the given texture from this scene.\r\n * @param toRemove The texture to remove\r\n * @returns The index of the removed texture\r\n */\r\n public removeTexture(toRemove: BaseTexture): number {\r\n const index = this.textures.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.textures.splice(index, 1);\r\n }\r\n this.onTextureRemovedObservable.notifyObservers(toRemove);\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Adds the given light to this scene\r\n * @param newLight The light to add\r\n */\r\n public addLight(newLight: Light): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.lights.push(newLight);\r\n this.sortLightsByPriority();\r\n\r\n if (!newLight.parent) {\r\n newLight._addToSceneRootNodes();\r\n }\r\n\r\n // Add light to all meshes (To support if the light is removed and then re-added)\r\n for (const mesh of this.meshes) {\r\n if (mesh.lightSources.indexOf(newLight) === -1) {\r\n mesh.lightSources.push(newLight);\r\n mesh._resyncLightSources();\r\n }\r\n }\r\n\r\n this.onNewLightAddedObservable.notifyObservers(newLight);\r\n }\r\n\r\n /**\r\n * Sorts the list list based on light priorities\r\n */\r\n public sortLightsByPriority(): void {\r\n if (this.requireLightSorting) {\r\n this.lights.sort(LightConstants.CompareLightsPriority);\r\n }\r\n }\r\n\r\n /**\r\n * Adds the given camera to this scene\r\n * @param newCamera The camera to add\r\n */\r\n public addCamera(newCamera: Camera): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n\r\n this.cameras.push(newCamera);\r\n this.onNewCameraAddedObservable.notifyObservers(newCamera);\r\n\r\n if (!newCamera.parent) {\r\n newCamera._addToSceneRootNodes();\r\n }\r\n }\r\n\r\n /**\r\n * Adds the given skeleton to this scene\r\n * @param newSkeleton The skeleton to add\r\n */\r\n public addSkeleton(newSkeleton: Skeleton): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.skeletons.push(newSkeleton);\r\n this.onNewSkeletonAddedObservable.notifyObservers(newSkeleton);\r\n }\r\n\r\n /**\r\n * Adds the given particle system to this scene\r\n * @param newParticleSystem The particle system to add\r\n */\r\n public addParticleSystem(newParticleSystem: IParticleSystem): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.particleSystems.push(newParticleSystem);\r\n }\r\n\r\n /**\r\n * Adds the given animation to this scene\r\n * @param newAnimation The animation to add\r\n */\r\n public addAnimation(newAnimation: Animation): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.animations.push(newAnimation);\r\n }\r\n\r\n /**\r\n * Adds the given animation group to this scene.\r\n * @param newAnimationGroup The animation group to add\r\n */\r\n public addAnimationGroup(newAnimationGroup: AnimationGroup): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.animationGroups.push(newAnimationGroup);\r\n }\r\n\r\n /**\r\n * Adds the given multi-material to this scene\r\n * @param newMultiMaterial The multi-material to add\r\n */\r\n public addMultiMaterial(newMultiMaterial: MultiMaterial): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.multiMaterials.push(newMultiMaterial);\r\n this.onNewMultiMaterialAddedObservable.notifyObservers(newMultiMaterial);\r\n }\r\n\r\n /**\r\n * Adds the given material to this scene\r\n * @param newMaterial The material to add\r\n */\r\n public addMaterial(newMaterial: Material): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n\r\n if (newMaterial.getScene() === this && newMaterial._indexInSceneMaterialArray !== -1) {\r\n // Already there??\r\n return;\r\n }\r\n\r\n newMaterial._indexInSceneMaterialArray = this.materials.length;\r\n this.materials.push(newMaterial);\r\n this.onNewMaterialAddedObservable.notifyObservers(newMaterial);\r\n }\r\n\r\n /**\r\n * Adds the given morph target to this scene\r\n * @param newMorphTargetManager The morph target to add\r\n */\r\n public addMorphTargetManager(newMorphTargetManager: MorphTargetManager): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.morphTargetManagers.push(newMorphTargetManager);\r\n }\r\n\r\n /**\r\n * Adds the given geometry to this scene\r\n * @param newGeometry The geometry to add\r\n */\r\n public addGeometry(newGeometry: Geometry): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n\r\n if (this._geometriesByUniqueId) {\r\n this._geometriesByUniqueId[newGeometry.uniqueId] = this.geometries.length;\r\n }\r\n\r\n this.geometries.push(newGeometry);\r\n }\r\n\r\n /**\r\n * Adds the given action manager to this scene\r\n * @deprecated\r\n * @param newActionManager The action manager to add\r\n */\r\n public addActionManager(newActionManager: AbstractActionManager): void {\r\n this.actionManagers.push(newActionManager);\r\n }\r\n\r\n /**\r\n * Adds the given texture to this scene.\r\n * @param newTexture The texture to add\r\n */\r\n public addTexture(newTexture: BaseTexture): void {\r\n if (this._blockEntityCollection) {\r\n return;\r\n }\r\n this.textures.push(newTexture);\r\n this.onNewTextureAddedObservable.notifyObservers(newTexture);\r\n }\r\n\r\n /**\r\n * Switch active camera\r\n * @param newCamera defines the new active camera\r\n * @param attachControl defines if attachControl must be called for the new active camera (default: true)\r\n */\r\n public switchActiveCamera(newCamera: Camera, attachControl = true): void {\r\n const canvas = this._engine.getInputElement();\r\n\r\n if (!canvas) {\r\n return;\r\n }\r\n\r\n if (this.activeCamera) {\r\n this.activeCamera.detachControl();\r\n }\r\n this.activeCamera = newCamera;\r\n if (attachControl) {\r\n newCamera.attachControl();\r\n }\r\n }\r\n\r\n /**\r\n * sets the active camera of the scene using its Id\r\n * @param id defines the camera's Id\r\n * @returns the new active camera or null if none found.\r\n */\r\n public setActiveCameraById(id: string): Nullable {\r\n const camera = this.getCameraById(id);\r\n\r\n if (camera) {\r\n this.activeCamera = camera;\r\n return camera;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * sets the active camera of the scene using its name\r\n * @param name defines the camera's name\r\n * @returns the new active camera or null if none found.\r\n */\r\n public setActiveCameraByName(name: string): Nullable {\r\n const camera = this.getCameraByName(name);\r\n\r\n if (camera) {\r\n this.activeCamera = camera;\r\n return camera;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * get an animation group using its name\r\n * @param name defines the material's name\r\n * @returns the animation group or null if none found.\r\n */\r\n public getAnimationGroupByName(name: string): Nullable {\r\n for (let index = 0; index < this.animationGroups.length; index++) {\r\n if (this.animationGroups[index].name === name) {\r\n return this.animationGroups[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _getMaterial(allowMultiMaterials: boolean, predicate: (m: Material) => boolean): Nullable {\r\n for (let index = 0; index < this.materials.length; index++) {\r\n const material = this.materials[index];\r\n if (predicate(material)) {\r\n return material;\r\n }\r\n }\r\n if (allowMultiMaterials) {\r\n for (let index = 0; index < this.multiMaterials.length; index++) {\r\n const material = this.multiMaterials[index];\r\n if (predicate(material)) {\r\n return material;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Get a material using its unique id\r\n * @param uniqueId defines the material's unique id\r\n * @param allowMultiMaterials determines whether multimaterials should be considered\r\n * @returns the material or null if none found.\r\n */\r\n public getMaterialByUniqueID(uniqueId: number, allowMultiMaterials: boolean = false): Nullable {\r\n return this._getMaterial(allowMultiMaterials, (m) => m.uniqueId === uniqueId);\r\n }\r\n\r\n /**\r\n * get a material using its id\r\n * @param id defines the material's Id\r\n * @param allowMultiMaterials determines whether multimaterials should be considered\r\n * @returns the material or null if none found.\r\n */\r\n public getMaterialById(id: string, allowMultiMaterials: boolean = false): Nullable {\r\n return this._getMaterial(allowMultiMaterials, (m) => m.id === id);\r\n }\r\n\r\n /**\r\n * Gets a material using its name\r\n * @param name defines the material's name\r\n * @param allowMultiMaterials determines whether multimaterials should be considered\r\n * @returns the material or null if none found.\r\n */\r\n public getMaterialByName(name: string, allowMultiMaterials: boolean = false): Nullable {\r\n return this._getMaterial(allowMultiMaterials, (m) => m.name === name);\r\n }\r\n\r\n /**\r\n * Gets a last added material using a given id\r\n * @param id defines the material's id\r\n * @param allowMultiMaterials determines whether multimaterials should be considered\r\n * @returns the last material with the given id or null if none found.\r\n */\r\n public getLastMaterialById(id: string, allowMultiMaterials: boolean = false): Nullable {\r\n for (let index = this.materials.length - 1; index >= 0; index--) {\r\n if (this.materials[index].id === id) {\r\n return this.materials[index];\r\n }\r\n }\r\n if (allowMultiMaterials) {\r\n for (let index = this.multiMaterials.length - 1; index >= 0; index--) {\r\n if (this.multiMaterials[index].id === id) {\r\n return this.multiMaterials[index];\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Get a texture using its unique id\r\n * @param uniqueId defines the texture's unique id\r\n * @returns the texture or null if none found.\r\n */\r\n public getTextureByUniqueId(uniqueId: number): Nullable {\r\n for (let index = 0; index < this.textures.length; index++) {\r\n if (this.textures[index].uniqueId === uniqueId) {\r\n return this.textures[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a texture using its name\r\n * @param name defines the texture's name\r\n * @returns the texture or null if none found.\r\n */\r\n public getTextureByName(name: string): Nullable {\r\n for (let index = 0; index < this.textures.length; index++) {\r\n if (this.textures[index].name === name) {\r\n return this.textures[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a camera using its Id\r\n * @param id defines the Id to look for\r\n * @returns the camera or null if not found\r\n */\r\n public getCameraById(id: string): Nullable {\r\n for (let index = 0; index < this.cameras.length; index++) {\r\n if (this.cameras[index].id === id) {\r\n return this.cameras[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a camera using its unique Id\r\n * @param uniqueId defines the unique Id to look for\r\n * @returns the camera or null if not found\r\n */\r\n public getCameraByUniqueId(uniqueId: number): Nullable {\r\n for (let index = 0; index < this.cameras.length; index++) {\r\n if (this.cameras[index].uniqueId === uniqueId) {\r\n return this.cameras[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a camera using its name\r\n * @param name defines the camera's name\r\n * @returns the camera or null if none found.\r\n */\r\n public getCameraByName(name: string): Nullable {\r\n for (let index = 0; index < this.cameras.length; index++) {\r\n if (this.cameras[index].name === name) {\r\n return this.cameras[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a bone using its Id\r\n * @param id defines the bone's Id\r\n * @returns the bone or null if not found\r\n */\r\n public getBoneById(id: string): Nullable {\r\n for (let skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {\r\n const skeleton = this.skeletons[skeletonIndex];\r\n for (let boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {\r\n if (skeleton.bones[boneIndex].id === id) {\r\n return skeleton.bones[boneIndex];\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a bone using its id\r\n * @param name defines the bone's name\r\n * @returns the bone or null if not found\r\n */\r\n public getBoneByName(name: string): Nullable {\r\n for (let skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {\r\n const skeleton = this.skeletons[skeletonIndex];\r\n for (let boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {\r\n if (skeleton.bones[boneIndex].name === name) {\r\n return skeleton.bones[boneIndex];\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a light node using its name\r\n * @param name defines the the light's name\r\n * @returns the light or null if none found.\r\n */\r\n public getLightByName(name: string): Nullable {\r\n for (let index = 0; index < this.lights.length; index++) {\r\n if (this.lights[index].name === name) {\r\n return this.lights[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a light node using its Id\r\n * @param id defines the light's Id\r\n * @returns the light or null if none found.\r\n */\r\n public getLightById(id: string): Nullable {\r\n for (let index = 0; index < this.lights.length; index++) {\r\n if (this.lights[index].id === id) {\r\n return this.lights[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a light node using its scene-generated unique Id\r\n * @param uniqueId defines the light's unique Id\r\n * @returns the light or null if none found.\r\n */\r\n public getLightByUniqueId(uniqueId: number): Nullable {\r\n for (let index = 0; index < this.lights.length; index++) {\r\n if (this.lights[index].uniqueId === uniqueId) {\r\n return this.lights[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a particle system by Id\r\n * @param id defines the particle system Id\r\n * @returns the corresponding system or null if none found\r\n */\r\n public getParticleSystemById(id: string): Nullable {\r\n for (let index = 0; index < this.particleSystems.length; index++) {\r\n if (this.particleSystems[index].id === id) {\r\n return this.particleSystems[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a geometry using its Id\r\n * @param id defines the geometry's Id\r\n * @returns the geometry or null if none found.\r\n */\r\n public getGeometryById(id: string): Nullable {\r\n for (let index = 0; index < this.geometries.length; index++) {\r\n if (this.geometries[index].id === id) {\r\n return this.geometries[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _getGeometryByUniqueId(uniqueId: number): Nullable {\r\n if (this._geometriesByUniqueId) {\r\n const index = this._geometriesByUniqueId[uniqueId];\r\n if (index !== undefined) {\r\n return this.geometries[index];\r\n }\r\n } else {\r\n for (let index = 0; index < this.geometries.length; index++) {\r\n if (this.geometries[index].uniqueId === uniqueId) {\r\n return this.geometries[index];\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Add a new geometry to this scene\r\n * @param geometry defines the geometry to be added to the scene.\r\n * @param force defines if the geometry must be pushed even if a geometry with this id already exists\r\n * @returns a boolean defining if the geometry was added or not\r\n */\r\n public pushGeometry(geometry: Geometry, force?: boolean): boolean {\r\n if (!force && this._getGeometryByUniqueId(geometry.uniqueId)) {\r\n return false;\r\n }\r\n\r\n this.addGeometry(geometry);\r\n\r\n this.onNewGeometryAddedObservable.notifyObservers(geometry);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Removes an existing geometry\r\n * @param geometry defines the geometry to be removed from the scene\r\n * @returns a boolean defining if the geometry was removed or not\r\n */\r\n public removeGeometry(geometry: Geometry): boolean {\r\n let index;\r\n if (this._geometriesByUniqueId) {\r\n index = this._geometriesByUniqueId[geometry.uniqueId];\r\n if (index === undefined) {\r\n return false;\r\n }\r\n } else {\r\n index = this.geometries.indexOf(geometry);\r\n if (index < 0) {\r\n return false;\r\n }\r\n }\r\n\r\n if (index !== this.geometries.length - 1) {\r\n const lastGeometry = this.geometries[this.geometries.length - 1];\r\n if (lastGeometry) {\r\n this.geometries[index] = lastGeometry;\r\n if (this._geometriesByUniqueId) {\r\n this._geometriesByUniqueId[lastGeometry.uniqueId] = index;\r\n }\r\n }\r\n }\r\n\r\n if (this._geometriesByUniqueId) {\r\n this._geometriesByUniqueId[geometry.uniqueId] = undefined;\r\n }\r\n\r\n this.geometries.pop();\r\n\r\n this.onGeometryRemovedObservable.notifyObservers(geometry);\r\n return true;\r\n }\r\n\r\n /**\r\n * Gets the list of geometries attached to the scene\r\n * @returns an array of Geometry\r\n */\r\n public getGeometries(): Geometry[] {\r\n return this.geometries;\r\n }\r\n\r\n /**\r\n * Gets the first added mesh found of a given Id\r\n * @param id defines the Id to search for\r\n * @returns the mesh found or null if not found at all\r\n */\r\n public getMeshById(id: string): Nullable {\r\n for (let index = 0; index < this.meshes.length; index++) {\r\n if (this.meshes[index].id === id) {\r\n return this.meshes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a list of meshes using their Id\r\n * @param id defines the Id to search for\r\n * @returns a list of meshes\r\n */\r\n public getMeshesById(id: string): Array {\r\n return this.meshes.filter(function (m) {\r\n return m.id === id;\r\n });\r\n }\r\n\r\n /**\r\n * Gets the first added transform node found of a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found transform node or null if not found at all.\r\n */\r\n public getTransformNodeById(id: string): Nullable {\r\n for (let index = 0; index < this.transformNodes.length; index++) {\r\n if (this.transformNodes[index].id === id) {\r\n return this.transformNodes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a transform node with its auto-generated unique Id\r\n * @param uniqueId defines the unique Id to search for\r\n * @returns the found transform node or null if not found at all.\r\n */\r\n public getTransformNodeByUniqueId(uniqueId: number): Nullable {\r\n for (let index = 0; index < this.transformNodes.length; index++) {\r\n if (this.transformNodes[index].uniqueId === uniqueId) {\r\n return this.transformNodes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a list of transform nodes using their Id\r\n * @param id defines the Id to search for\r\n * @returns a list of transform nodes\r\n */\r\n public getTransformNodesById(id: string): Array {\r\n return this.transformNodes.filter(function (m) {\r\n return m.id === id;\r\n });\r\n }\r\n\r\n /**\r\n * Gets a mesh with its auto-generated unique Id\r\n * @param uniqueId defines the unique Id to search for\r\n * @returns the found mesh or null if not found at all.\r\n */\r\n public getMeshByUniqueId(uniqueId: number): Nullable {\r\n for (let index = 0; index < this.meshes.length; index++) {\r\n if (this.meshes[index].uniqueId === uniqueId) {\r\n return this.meshes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a the last added mesh using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found mesh or null if not found at all.\r\n */\r\n public getLastMeshById(id: string): Nullable {\r\n for (let index = this.meshes.length - 1; index >= 0; index--) {\r\n if (this.meshes[index].id === id) {\r\n return this.meshes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a the last transform node using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found mesh or null if not found at all.\r\n */\r\n public getLastTransformNodeById(id: string): Nullable {\r\n for (let index = this.transformNodes.length - 1; index >= 0; index--) {\r\n if (this.transformNodes[index].id === id) {\r\n return this.transformNodes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a the last added node (Mesh, Camera, Light) using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found node or null if not found at all\r\n */\r\n public getLastEntryById(id: string): Nullable {\r\n let index: number;\r\n for (index = this.meshes.length - 1; index >= 0; index--) {\r\n if (this.meshes[index].id === id) {\r\n return this.meshes[index];\r\n }\r\n }\r\n\r\n for (index = this.transformNodes.length - 1; index >= 0; index--) {\r\n if (this.transformNodes[index].id === id) {\r\n return this.transformNodes[index];\r\n }\r\n }\r\n\r\n for (index = this.cameras.length - 1; index >= 0; index--) {\r\n if (this.cameras[index].id === id) {\r\n return this.cameras[index];\r\n }\r\n }\r\n\r\n for (index = this.lights.length - 1; index >= 0; index--) {\r\n if (this.lights[index].id === id) {\r\n return this.lights[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a node (Mesh, Camera, Light) using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found node or null if not found at all\r\n */\r\n public getNodeById(id: string): Nullable {\r\n const mesh = this.getMeshById(id);\r\n if (mesh) {\r\n return mesh;\r\n }\r\n\r\n const transformNode = this.getTransformNodeById(id);\r\n if (transformNode) {\r\n return transformNode;\r\n }\r\n\r\n const light = this.getLightById(id);\r\n if (light) {\r\n return light;\r\n }\r\n\r\n const camera = this.getCameraById(id);\r\n if (camera) {\r\n return camera;\r\n }\r\n\r\n const bone = this.getBoneById(id);\r\n if (bone) {\r\n return bone;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a node (Mesh, Camera, Light) using a given name\r\n * @param name defines the name to search for\r\n * @returns the found node or null if not found at all.\r\n */\r\n public getNodeByName(name: string): Nullable {\r\n const mesh = this.getMeshByName(name);\r\n if (mesh) {\r\n return mesh;\r\n }\r\n\r\n const transformNode = this.getTransformNodeByName(name);\r\n if (transformNode) {\r\n return transformNode;\r\n }\r\n\r\n const light = this.getLightByName(name);\r\n if (light) {\r\n return light;\r\n }\r\n\r\n const camera = this.getCameraByName(name);\r\n if (camera) {\r\n return camera;\r\n }\r\n\r\n const bone = this.getBoneByName(name);\r\n if (bone) {\r\n return bone;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a mesh using a given name\r\n * @param name defines the name to search for\r\n * @returns the found mesh or null if not found at all.\r\n */\r\n public getMeshByName(name: string): Nullable {\r\n for (let index = 0; index < this.meshes.length; index++) {\r\n if (this.meshes[index].name === name) {\r\n return this.meshes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a transform node using a given name\r\n * @param name defines the name to search for\r\n * @returns the found transform node or null if not found at all.\r\n */\r\n public getTransformNodeByName(name: string): Nullable {\r\n for (let index = 0; index < this.transformNodes.length; index++) {\r\n if (this.transformNodes[index].name === name) {\r\n return this.transformNodes[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a skeleton using a given Id (if many are found, this function will pick the last one)\r\n * @param id defines the Id to search for\r\n * @returns the found skeleton or null if not found at all.\r\n */\r\n public getLastSkeletonById(id: string): Nullable {\r\n for (let index = this.skeletons.length - 1; index >= 0; index--) {\r\n if (this.skeletons[index].id === id) {\r\n return this.skeletons[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a skeleton using a given auto generated unique id\r\n * @param uniqueId defines the unique id to search for\r\n * @returns the found skeleton or null if not found at all.\r\n */\r\n public getSkeletonByUniqueId(uniqueId: number): Nullable {\r\n for (let index = 0; index < this.skeletons.length; index++) {\r\n if (this.skeletons[index].uniqueId === uniqueId) {\r\n return this.skeletons[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a skeleton using a given id (if many are found, this function will pick the first one)\r\n * @param id defines the id to search for\r\n * @returns the found skeleton or null if not found at all.\r\n */\r\n public getSkeletonById(id: string): Nullable {\r\n for (let index = 0; index < this.skeletons.length; index++) {\r\n if (this.skeletons[index].id === id) {\r\n return this.skeletons[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a skeleton using a given name\r\n * @param name defines the name to search for\r\n * @returns the found skeleton or null if not found at all.\r\n */\r\n public getSkeletonByName(name: string): Nullable {\r\n for (let index = 0; index < this.skeletons.length; index++) {\r\n if (this.skeletons[index].name === name) {\r\n return this.skeletons[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a morph target manager using a given id (if many are found, this function will pick the last one)\r\n * @param id defines the id to search for\r\n * @returns the found morph target manager or null if not found at all.\r\n */\r\n public getMorphTargetManagerById(id: number): Nullable {\r\n for (let index = 0; index < this.morphTargetManagers.length; index++) {\r\n if (this.morphTargetManagers[index].uniqueId === id) {\r\n return this.morphTargetManagers[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a morph target using a given id (if many are found, this function will pick the first one)\r\n * @param id defines the id to search for\r\n * @returns the found morph target or null if not found at all.\r\n */\r\n public getMorphTargetById(id: string): Nullable {\r\n for (let managerIndex = 0; managerIndex < this.morphTargetManagers.length; ++managerIndex) {\r\n const morphTargetManager = this.morphTargetManagers[managerIndex];\r\n for (let index = 0; index < morphTargetManager.numTargets; ++index) {\r\n const target = morphTargetManager.getTarget(index);\r\n if (target.id === id) {\r\n return target;\r\n }\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a morph target using a given name (if many are found, this function will pick the first one)\r\n * @param name defines the name to search for\r\n * @returns the found morph target or null if not found at all.\r\n */\r\n public getMorphTargetByName(name: string): Nullable {\r\n for (let managerIndex = 0; managerIndex < this.morphTargetManagers.length; ++managerIndex) {\r\n const morphTargetManager = this.morphTargetManagers[managerIndex];\r\n for (let index = 0; index < morphTargetManager.numTargets; ++index) {\r\n const target = morphTargetManager.getTarget(index);\r\n if (target.name === name) {\r\n return target;\r\n }\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a post process using a given name (if many are found, this function will pick the first one)\r\n * @param name defines the name to search for\r\n * @returns the found post process or null if not found at all.\r\n */\r\n public getPostProcessByName(name: string): Nullable {\r\n for (let postProcessIndex = 0; postProcessIndex < this.postProcesses.length; ++postProcessIndex) {\r\n const postProcess = this.postProcesses[postProcessIndex];\r\n if (postProcess.name === name) {\r\n return postProcess;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the given mesh is active\r\n * @param mesh defines the mesh to look for\r\n * @returns true if the mesh is in the active list\r\n */\r\n public isActiveMesh(mesh: AbstractMesh): boolean {\r\n return this._activeMeshes.indexOf(mesh) !== -1;\r\n }\r\n\r\n /**\r\n * Return a unique id as a string which can serve as an identifier for the scene\r\n */\r\n public get uid(): string {\r\n if (!this._uid) {\r\n this._uid = Tools.RandomId();\r\n }\r\n return this._uid;\r\n }\r\n\r\n /**\r\n * Add an externally attached data from its key.\r\n * This method call will fail and return false, if such key already exists.\r\n * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.\r\n * @param key the unique key that identifies the data\r\n * @param data the data object to associate to the key for this Engine instance\r\n * @returns true if no such key were already present and the data was added successfully, false otherwise\r\n */\r\n public addExternalData(key: string, data: T): boolean {\r\n if (!this._externalData) {\r\n this._externalData = new StringDictionary();\r\n }\r\n return this._externalData.add(key, data);\r\n }\r\n\r\n /**\r\n * Get an externally attached data from its key\r\n * @param key the unique key that identifies the data\r\n * @returns the associated data, if present (can be null), or undefined if not present\r\n */\r\n public getExternalData(key: string): Nullable {\r\n if (!this._externalData) {\r\n return null;\r\n }\r\n return this._externalData.get(key);\r\n }\r\n\r\n /**\r\n * Get an externally attached data from its key, create it using a factory if it's not already present\r\n * @param key the unique key that identifies the data\r\n * @param factory the factory that will be called to create the instance if and only if it doesn't exists\r\n * @returns the associated data, can be null if the factory returned null.\r\n */\r\n public getOrAddExternalDataWithFactory(key: string, factory: (k: string) => T): T {\r\n if (!this._externalData) {\r\n this._externalData = new StringDictionary();\r\n }\r\n return this._externalData.getOrAddWithFactory(key, factory);\r\n }\r\n\r\n /**\r\n * Remove an externally attached data from the Engine instance\r\n * @param key the unique key that identifies the data\r\n * @returns true if the data was successfully removed, false if it doesn't exist\r\n */\r\n public removeExternalData(key: string): boolean {\r\n return this._externalData.remove(key);\r\n }\r\n\r\n private _evaluateSubMesh(subMesh: SubMesh, mesh: AbstractMesh, initialMesh: AbstractMesh, forcePush: boolean): void {\r\n if (forcePush || subMesh.isInFrustum(this._frustumPlanes)) {\r\n for (const step of this._evaluateSubMeshStage) {\r\n step.action(mesh, subMesh);\r\n }\r\n\r\n const material = subMesh.getMaterial();\r\n if (material !== null && material !== undefined) {\r\n // Render targets\r\n if (material.hasRenderTargetTextures && material.getRenderTargetTextures != null) {\r\n if (this._processedMaterials.indexOf(material) === -1) {\r\n this._processedMaterials.push(material);\r\n\r\n this._materialsRenderTargets.concatWithNoDuplicate(material.getRenderTargetTextures!());\r\n }\r\n }\r\n\r\n // Dispatch\r\n this._renderingManager.dispatch(subMesh, mesh, material);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clear the processed materials smart array preventing retention point in material dispose.\r\n */\r\n public freeProcessedMaterials(): void {\r\n this._processedMaterials.dispose();\r\n }\r\n\r\n private _preventFreeActiveMeshesAndRenderingGroups = false;\r\n\r\n /** Gets or sets a boolean blocking all the calls to freeActiveMeshes and freeRenderingGroups\r\n * It can be used in order to prevent going through methods freeRenderingGroups and freeActiveMeshes several times to improve performance\r\n * when disposing several meshes in a row or a hierarchy of meshes.\r\n * When used, it is the responsibility of the user to blockfreeActiveMeshesAndRenderingGroups back to false.\r\n */\r\n public get blockfreeActiveMeshesAndRenderingGroups(): boolean {\r\n return this._preventFreeActiveMeshesAndRenderingGroups;\r\n }\r\n\r\n public set blockfreeActiveMeshesAndRenderingGroups(value: boolean) {\r\n if (this._preventFreeActiveMeshesAndRenderingGroups === value) {\r\n return;\r\n }\r\n\r\n if (value) {\r\n this.freeActiveMeshes();\r\n this.freeRenderingGroups();\r\n }\r\n\r\n this._preventFreeActiveMeshesAndRenderingGroups = value;\r\n }\r\n\r\n /**\r\n * Clear the active meshes smart array preventing retention point in mesh dispose.\r\n */\r\n public freeActiveMeshes(): void {\r\n if (this.blockfreeActiveMeshesAndRenderingGroups) {\r\n return;\r\n }\r\n\r\n this._activeMeshes.dispose();\r\n if (this.activeCamera && this.activeCamera._activeMeshes) {\r\n this.activeCamera._activeMeshes.dispose();\r\n }\r\n if (this.activeCameras) {\r\n for (let i = 0; i < this.activeCameras.length; i++) {\r\n const activeCamera = this.activeCameras[i];\r\n if (activeCamera && activeCamera._activeMeshes) {\r\n activeCamera._activeMeshes.dispose();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clear the info related to rendering groups preventing retention points during dispose.\r\n */\r\n public freeRenderingGroups(): void {\r\n if (this.blockfreeActiveMeshesAndRenderingGroups) {\r\n return;\r\n }\r\n\r\n if (this._renderingManager) {\r\n this._renderingManager.freeRenderingGroups();\r\n }\r\n if (this.textures) {\r\n for (let i = 0; i < this.textures.length; i++) {\r\n const texture = this.textures[i];\r\n if (texture && (texture).renderList) {\r\n (texture).freeRenderingGroups();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _isInIntermediateRendering(): boolean {\r\n return this._intermediateRendering;\r\n }\r\n\r\n /**\r\n * Lambda returning the list of potentially active meshes.\r\n */\r\n public getActiveMeshCandidates: () => ISmartArrayLike;\r\n\r\n /**\r\n * Lambda returning the list of potentially active sub meshes.\r\n */\r\n public getActiveSubMeshCandidates: (mesh: AbstractMesh) => ISmartArrayLike;\r\n\r\n /**\r\n * Lambda returning the list of potentially intersecting sub meshes.\r\n */\r\n public getIntersectingSubMeshCandidates: (mesh: AbstractMesh, localRay: Ray) => ISmartArrayLike;\r\n\r\n /**\r\n * Lambda returning the list of potentially colliding sub meshes.\r\n */\r\n public getCollidingSubMeshCandidates: (mesh: AbstractMesh, collider: Collider) => ISmartArrayLike;\r\n\r\n /** @internal */\r\n public _activeMeshesFrozen = false;\r\n /** @internal */\r\n public _activeMeshesFrozenButKeepClipping = false;\r\n private _skipEvaluateActiveMeshesCompletely = false;\r\n\r\n /**\r\n * Use this function to stop evaluating active meshes. The current list will be keep alive between frames\r\n * @param skipEvaluateActiveMeshes defines an optional boolean indicating that the evaluate active meshes step must be completely skipped\r\n * @param onSuccess optional success callback\r\n * @param onError optional error callback\r\n * @param freezeMeshes defines if meshes should be frozen (true by default)\r\n * @param keepFrustumCulling defines if you want to keep running the frustum clipping (false by default)\r\n * @returns the current scene\r\n */\r\n public freezeActiveMeshes(\r\n skipEvaluateActiveMeshes = false,\r\n onSuccess?: () => void,\r\n onError?: (message: string) => void,\r\n freezeMeshes = true,\r\n keepFrustumCulling = false\r\n ): Scene {\r\n this.executeWhenReady(() => {\r\n if (!this.activeCamera) {\r\n onError && onError(\"No active camera found\");\r\n return;\r\n }\r\n\r\n if (!this._frustumPlanes) {\r\n this.updateTransformMatrix();\r\n }\r\n\r\n this._evaluateActiveMeshes();\r\n this._activeMeshesFrozen = true;\r\n this._activeMeshesFrozenButKeepClipping = keepFrustumCulling;\r\n this._skipEvaluateActiveMeshesCompletely = skipEvaluateActiveMeshes;\r\n\r\n if (freezeMeshes) {\r\n for (let index = 0; index < this._activeMeshes.length; index++) {\r\n this._activeMeshes.data[index]._freeze();\r\n }\r\n }\r\n onSuccess && onSuccess();\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Use this function to restart evaluating active meshes on every frame\r\n * @returns the current scene\r\n */\r\n public unfreezeActiveMeshes(): Scene {\r\n for (let index = 0; index < this.meshes.length; index++) {\r\n const mesh = this.meshes[index];\r\n if (mesh._internalAbstractMeshDataInfo) {\r\n mesh._internalAbstractMeshDataInfo._isActive = false;\r\n }\r\n }\r\n\r\n for (let index = 0; index < this._activeMeshes.length; index++) {\r\n this._activeMeshes.data[index]._unFreeze();\r\n }\r\n\r\n this._activeMeshesFrozen = false;\r\n return this;\r\n }\r\n\r\n private _executeActiveContainerCleanup(container: SmartArray) {\r\n const isInFastMode = this._engine.snapshotRendering && this._engine.snapshotRenderingMode === Constants.SNAPSHOTRENDERING_FAST;\r\n\r\n if (!isInFastMode && this._activeMeshesFrozen && this._activeMeshes.length) {\r\n return; // Do not execute in frozen mode\r\n }\r\n\r\n // We need to ensure we are not in the rendering loop\r\n this.onBeforeRenderObservable.addOnce(() => container.dispose());\r\n }\r\n\r\n private _evaluateActiveMeshes(): void {\r\n if (this._engine.snapshotRendering && this._engine.snapshotRenderingMode === Constants.SNAPSHOTRENDERING_FAST) {\r\n if (this._activeMeshes.length > 0) {\r\n this.activeCamera?._activeMeshes.reset();\r\n this._activeMeshes.reset();\r\n this._renderingManager.reset();\r\n this._processedMaterials.reset();\r\n this._activeParticleSystems.reset();\r\n this._activeSkeletons.reset();\r\n this._softwareSkinnedMeshes.reset();\r\n }\r\n return;\r\n }\r\n\r\n if (this._activeMeshesFrozen && this._activeMeshes.length) {\r\n if (!this._skipEvaluateActiveMeshesCompletely) {\r\n const len = this._activeMeshes.length;\r\n for (let i = 0; i < len; i++) {\r\n const mesh = this._activeMeshes.data[i];\r\n mesh.computeWorldMatrix();\r\n }\r\n }\r\n\r\n if (this._activeParticleSystems) {\r\n const psLength = this._activeParticleSystems.length;\r\n for (let i = 0; i < psLength; i++) {\r\n this._activeParticleSystems.data[i].animate();\r\n }\r\n }\r\n\r\n this._renderingManager.resetSprites();\r\n\r\n return;\r\n }\r\n\r\n if (!this.activeCamera) {\r\n return;\r\n }\r\n\r\n this.onBeforeActiveMeshesEvaluationObservable.notifyObservers(this);\r\n\r\n this.activeCamera._activeMeshes.reset();\r\n this._activeMeshes.reset();\r\n this._renderingManager.reset();\r\n this._processedMaterials.reset();\r\n this._activeParticleSystems.reset();\r\n this._activeSkeletons.reset();\r\n this._softwareSkinnedMeshes.reset();\r\n this._materialsRenderTargets.reset();\r\n\r\n for (const step of this._beforeEvaluateActiveMeshStage) {\r\n step.action();\r\n }\r\n\r\n // Determine mesh candidates\r\n const meshes = this.getActiveMeshCandidates();\r\n\r\n // Check each mesh\r\n const len = meshes.length;\r\n for (let i = 0; i < len; i++) {\r\n const mesh = meshes.data[i];\r\n mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate = false;\r\n if (mesh.isBlocked) {\r\n continue;\r\n }\r\n\r\n this._totalVertices.addCount(mesh.getTotalVertices(), false);\r\n\r\n if (!mesh.isReady() || !mesh.isEnabled() || mesh.scaling.hasAZeroComponent) {\r\n continue;\r\n }\r\n\r\n mesh.computeWorldMatrix();\r\n\r\n // Intersections\r\n if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers2(Constants.ACTION_OnIntersectionEnterTrigger, Constants.ACTION_OnIntersectionExitTrigger)) {\r\n this._meshesForIntersections.pushNoDuplicate(mesh);\r\n }\r\n\r\n // Switch to current LOD\r\n let meshToRender = this.customLODSelector ? this.customLODSelector(mesh, this.activeCamera) : mesh.getLOD(this.activeCamera);\r\n mesh._internalAbstractMeshDataInfo._currentLOD = meshToRender;\r\n mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate = true;\r\n if (meshToRender === undefined || meshToRender === null) {\r\n continue;\r\n }\r\n\r\n // Compute world matrix if LOD is billboard\r\n if (meshToRender !== mesh && meshToRender.billboardMode !== 0) {\r\n meshToRender.computeWorldMatrix();\r\n }\r\n\r\n mesh._preActivate();\r\n\r\n if (\r\n mesh.isVisible &&\r\n mesh.visibility > 0 &&\r\n (mesh.layerMask & this.activeCamera.layerMask) !== 0 &&\r\n (this._skipFrustumClipping || mesh.alwaysSelectAsActiveMesh || mesh.isInFrustum(this._frustumPlanes))\r\n ) {\r\n this._activeMeshes.push(mesh);\r\n this.activeCamera._activeMeshes.push(mesh);\r\n\r\n if (meshToRender !== mesh) {\r\n meshToRender._activate(this._renderId, false);\r\n }\r\n\r\n for (const step of this._preActiveMeshStage) {\r\n step.action(mesh);\r\n }\r\n\r\n if (mesh._activate(this._renderId, false)) {\r\n if (!mesh.isAnInstance) {\r\n meshToRender._internalAbstractMeshDataInfo._onlyForInstances = false;\r\n } else {\r\n if (mesh._internalAbstractMeshDataInfo._actAsRegularMesh) {\r\n meshToRender = mesh;\r\n }\r\n }\r\n meshToRender._internalAbstractMeshDataInfo._isActive = true;\r\n this._activeMesh(mesh, meshToRender);\r\n }\r\n\r\n mesh._postActivate();\r\n }\r\n }\r\n\r\n this.onAfterActiveMeshesEvaluationObservable.notifyObservers(this);\r\n\r\n // Particle systems\r\n if (this.particlesEnabled) {\r\n this.onBeforeParticlesRenderingObservable.notifyObservers(this);\r\n for (let particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {\r\n const particleSystem = this.particleSystems[particleIndex];\r\n\r\n if (!particleSystem.isStarted() || !particleSystem.emitter) {\r\n continue;\r\n }\r\n\r\n const emitter = particleSystem.emitter;\r\n if (!emitter.position || emitter.isEnabled()) {\r\n this._activeParticleSystems.push(particleSystem);\r\n particleSystem.animate();\r\n this._renderingManager.dispatchParticles(particleSystem);\r\n }\r\n }\r\n this.onAfterParticlesRenderingObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n private _activeMesh(sourceMesh: AbstractMesh, mesh: AbstractMesh): void {\r\n if (this._skeletonsEnabled && mesh.skeleton !== null && mesh.skeleton !== undefined) {\r\n if (this._activeSkeletons.pushNoDuplicate(mesh.skeleton)) {\r\n mesh.skeleton.prepare();\r\n this._activeBones.addCount(mesh.skeleton.bones.length, false);\r\n }\r\n\r\n if (!mesh.computeBonesUsingShaders) {\r\n this._softwareSkinnedMeshes.pushNoDuplicate(mesh);\r\n }\r\n }\r\n\r\n let forcePush = sourceMesh.hasInstances || sourceMesh.isAnInstance || this.dispatchAllSubMeshesOfActiveMeshes || this._skipFrustumClipping || mesh.alwaysSelectAsActiveMesh;\r\n\r\n if (mesh && mesh.subMeshes && mesh.subMeshes.length > 0) {\r\n const subMeshes = this.getActiveSubMeshCandidates(mesh);\r\n const len = subMeshes.length;\r\n forcePush = forcePush || len === 1;\r\n for (let i = 0; i < len; i++) {\r\n const subMesh = subMeshes.data[i];\r\n this._evaluateSubMesh(subMesh, mesh, sourceMesh, forcePush);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Update the transform matrix to update from the current active camera\r\n * @param force defines a boolean used to force the update even if cache is up to date\r\n */\r\n public updateTransformMatrix(force?: boolean): void {\r\n if (!this.activeCamera) {\r\n return;\r\n }\r\n\r\n if (this.activeCamera._renderingMultiview) {\r\n const leftCamera = this.activeCamera._rigCameras[0];\r\n const rightCamera = this.activeCamera._rigCameras[1];\r\n this.setTransformMatrix(leftCamera.getViewMatrix(), leftCamera.getProjectionMatrix(force), rightCamera.getViewMatrix(), rightCamera.getProjectionMatrix(force));\r\n } else {\r\n this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));\r\n }\r\n }\r\n\r\n private _bindFrameBuffer(camera: Nullable, clear = true) {\r\n if (camera && camera._multiviewTexture) {\r\n camera._multiviewTexture._bindFrameBuffer();\r\n } else if (camera && camera.outputRenderTarget) {\r\n camera.outputRenderTarget._bindFrameBuffer();\r\n } else {\r\n if (!this._engine._currentFrameBufferIsDefaultFrameBuffer()) {\r\n this._engine.restoreDefaultFramebuffer();\r\n }\r\n }\r\n if (clear) {\r\n this._clearFrameBuffer(camera);\r\n }\r\n }\r\n\r\n private _clearFrameBuffer(camera: Nullable) {\r\n // we assume the framebuffer currently bound is the right one\r\n if (camera && camera._multiviewTexture) {\r\n // no clearing?\r\n } else if (camera && camera.outputRenderTarget && !camera._renderingMultiview) {\r\n const rtt = camera.outputRenderTarget;\r\n if (rtt.onClearObservable.hasObservers()) {\r\n rtt.onClearObservable.notifyObservers(this._engine);\r\n } else if (!rtt.skipInitialClear) {\r\n if (this.autoClear) {\r\n this._engine.clear(rtt.clearColor || this.clearColor, !rtt._cleared, true, true);\r\n }\r\n rtt._cleared = true;\r\n }\r\n } else {\r\n if (!this._defaultFrameBufferCleared) {\r\n this._defaultFrameBufferCleared = true;\r\n this._clear();\r\n } else {\r\n this._engine.clear(null, false, true, true);\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _allowPostProcessClearColor = true;\r\n /**\r\n * @internal\r\n */\r\n public _renderForCamera(camera: Camera, rigParent?: Camera, bindFrameBuffer = true): void {\r\n if (camera && camera._skipRendering) {\r\n return;\r\n }\r\n\r\n const engine = this._engine;\r\n\r\n // Use _activeCamera instead of activeCamera to avoid onActiveCameraChanged\r\n this._activeCamera = camera;\r\n\r\n if (!this.activeCamera) {\r\n throw new Error(\"Active camera not set\");\r\n }\r\n\r\n // Viewport\r\n engine.setViewport(this.activeCamera.viewport);\r\n\r\n // Camera\r\n this.resetCachedMaterial();\r\n this._renderId++;\r\n\r\n if (!this.prePass && bindFrameBuffer) {\r\n let skipInitialClear = true;\r\n if (camera._renderingMultiview && camera.outputRenderTarget) {\r\n skipInitialClear = camera.outputRenderTarget.skipInitialClear;\r\n if (this.autoClear) {\r\n this._defaultFrameBufferCleared = false;\r\n camera.outputRenderTarget.skipInitialClear = false;\r\n }\r\n }\r\n this._bindFrameBuffer(this._activeCamera);\r\n if (camera._renderingMultiview && camera.outputRenderTarget) {\r\n camera.outputRenderTarget.skipInitialClear = skipInitialClear;\r\n }\r\n }\r\n\r\n this.updateTransformMatrix();\r\n\r\n this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera);\r\n\r\n // Meshes\r\n this._evaluateActiveMeshes();\r\n\r\n // Software skinning\r\n for (let softwareSkinnedMeshIndex = 0; softwareSkinnedMeshIndex < this._softwareSkinnedMeshes.length; softwareSkinnedMeshIndex++) {\r\n const mesh = this._softwareSkinnedMeshes.data[softwareSkinnedMeshIndex];\r\n\r\n mesh.applySkeleton(mesh.skeleton);\r\n }\r\n\r\n // Render targets\r\n this.onBeforeRenderTargetsRenderObservable.notifyObservers(this);\r\n\r\n this._renderTargets.concatWithNoDuplicate(this._materialsRenderTargets);\r\n\r\n if (camera.customRenderTargets && camera.customRenderTargets.length > 0) {\r\n this._renderTargets.concatWithNoDuplicate(camera.customRenderTargets);\r\n }\r\n\r\n if (rigParent && rigParent.customRenderTargets && rigParent.customRenderTargets.length > 0) {\r\n this._renderTargets.concatWithNoDuplicate(rigParent.customRenderTargets);\r\n }\r\n\r\n if (this.environmentTexture && this.environmentTexture.isRenderTarget) {\r\n this._renderTargets.pushNoDuplicate(this.environmentTexture as RenderTargetTexture);\r\n }\r\n\r\n // Collects render targets from external components.\r\n for (const step of this._gatherActiveCameraRenderTargetsStage) {\r\n step.action(this._renderTargets);\r\n }\r\n\r\n let needRebind = false;\r\n if (this.renderTargetsEnabled) {\r\n this._intermediateRendering = true;\r\n\r\n if (this._renderTargets.length > 0) {\r\n Tools.StartPerformanceCounter(\"Render targets\", this._renderTargets.length > 0);\r\n for (let renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {\r\n const renderTarget = this._renderTargets.data[renderIndex];\r\n if (renderTarget._shouldRender()) {\r\n this._renderId++;\r\n const hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;\r\n renderTarget.render(hasSpecialRenderTargetCamera, this.dumpNextRenderTargets);\r\n needRebind = true;\r\n }\r\n }\r\n Tools.EndPerformanceCounter(\"Render targets\", this._renderTargets.length > 0);\r\n\r\n this._renderId++;\r\n }\r\n\r\n for (const step of this._cameraDrawRenderTargetStage) {\r\n needRebind = step.action(this.activeCamera) || needRebind;\r\n }\r\n\r\n this._intermediateRendering = false;\r\n }\r\n\r\n this._engine.currentRenderPassId = camera.outputRenderTarget?.renderPassId ?? camera.renderPassId ?? Constants.RENDERPASS_MAIN;\r\n\r\n // Restore framebuffer after rendering to targets\r\n if (needRebind && !this.prePass) {\r\n this._bindFrameBuffer(this._activeCamera, false);\r\n }\r\n\r\n this.onAfterRenderTargetsRenderObservable.notifyObservers(this);\r\n\r\n // Prepare Frame\r\n if (this.postProcessManager && !camera._multiviewTexture && !this.prePass) {\r\n this.postProcessManager._prepareFrame();\r\n }\r\n\r\n // Before Camera Draw\r\n for (const step of this._beforeCameraDrawStage) {\r\n step.action(this.activeCamera);\r\n }\r\n\r\n // Render\r\n this.onBeforeDrawPhaseObservable.notifyObservers(this);\r\n\r\n if (engine.snapshotRendering && engine.snapshotRenderingMode === Constants.SNAPSHOTRENDERING_FAST) {\r\n this.finalizeSceneUbo();\r\n }\r\n this._renderingManager.render(null, null, true, true);\r\n this.onAfterDrawPhaseObservable.notifyObservers(this);\r\n\r\n // After Camera Draw\r\n for (const step of this._afterCameraDrawStage) {\r\n step.action(this.activeCamera);\r\n }\r\n\r\n // Finalize frame\r\n if (this.postProcessManager && !camera._multiviewTexture) {\r\n // if the camera has an output render target, render the post process to the render target\r\n const texture = camera.outputRenderTarget ? camera.outputRenderTarget.renderTarget! : undefined;\r\n this.postProcessManager._finalizeFrame(camera.isIntermediate, texture);\r\n }\r\n\r\n // After post process\r\n for (const step of this._afterCameraPostProcessStage) {\r\n step.action(this.activeCamera);\r\n }\r\n\r\n // Reset some special arrays\r\n this._renderTargets.reset();\r\n\r\n this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera);\r\n }\r\n\r\n private _processSubCameras(camera: Camera, bindFrameBuffer = true): void {\r\n if (camera.cameraRigMode === Constants.RIG_MODE_NONE || camera._renderingMultiview) {\r\n if (camera._renderingMultiview && !this._multiviewSceneUbo) {\r\n this._createMultiviewUbo();\r\n }\r\n this._renderForCamera(camera, undefined, bindFrameBuffer);\r\n this.onAfterRenderCameraObservable.notifyObservers(camera);\r\n return;\r\n }\r\n\r\n if (camera._useMultiviewToSingleView) {\r\n this._renderMultiviewToSingleView(camera);\r\n } else {\r\n // rig cameras\r\n this.onBeforeCameraRenderObservable.notifyObservers(camera);\r\n for (let index = 0; index < camera._rigCameras.length; index++) {\r\n this._renderForCamera(camera._rigCameras[index], camera);\r\n }\r\n }\r\n\r\n // Use _activeCamera instead of activeCamera to avoid onActiveCameraChanged\r\n this._activeCamera = camera;\r\n this.updateTransformMatrix();\r\n this.onAfterRenderCameraObservable.notifyObservers(camera);\r\n }\r\n\r\n private _checkIntersections(): void {\r\n for (let index = 0; index < this._meshesForIntersections.length; index++) {\r\n const sourceMesh = this._meshesForIntersections.data[index];\r\n\r\n if (!sourceMesh.actionManager) {\r\n continue;\r\n }\r\n\r\n for (let actionIndex = 0; sourceMesh.actionManager && actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {\r\n const action: IAction = sourceMesh.actionManager.actions[actionIndex];\r\n\r\n if (action.trigger === Constants.ACTION_OnIntersectionEnterTrigger || action.trigger === Constants.ACTION_OnIntersectionExitTrigger) {\r\n const parameters = action.getTriggerParameter();\r\n const otherMesh = parameters.mesh ? parameters.mesh : parameters;\r\n\r\n const areIntersecting = otherMesh.intersectsMesh(sourceMesh, parameters.usePreciseIntersection);\r\n const currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);\r\n\r\n if (areIntersecting && currentIntersectionInProgress === -1) {\r\n if (action.trigger === Constants.ACTION_OnIntersectionEnterTrigger) {\r\n action._executeCurrent(ActionEvent.CreateNew(sourceMesh, undefined, otherMesh));\r\n sourceMesh._intersectionsInProgress.push(otherMesh);\r\n } else if (action.trigger === Constants.ACTION_OnIntersectionExitTrigger) {\r\n sourceMesh._intersectionsInProgress.push(otherMesh);\r\n }\r\n } else if (!areIntersecting && currentIntersectionInProgress > -1) {\r\n //They intersected, and now they don't.\r\n\r\n //is this trigger an exit trigger? execute an event.\r\n if (action.trigger === Constants.ACTION_OnIntersectionExitTrigger) {\r\n action._executeCurrent(ActionEvent.CreateNew(sourceMesh, undefined, otherMesh));\r\n }\r\n\r\n //if this is an exit trigger, or no exit trigger exists, remove the id from the intersection in progress array.\r\n if (\r\n !sourceMesh.actionManager.hasSpecificTrigger(Constants.ACTION_OnIntersectionExitTrigger, (parameter) => {\r\n const parameterMesh = parameter.mesh ? parameter.mesh : parameter;\r\n return otherMesh === parameterMesh;\r\n }) ||\r\n action.trigger === Constants.ACTION_OnIntersectionExitTrigger\r\n ) {\r\n sourceMesh._intersectionsInProgress.splice(currentIntersectionInProgress, 1);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _advancePhysicsEngineStep(step: number) {\r\n // Do nothing. Code will be replaced if physics engine component is referenced\r\n }\r\n\r\n /**\r\n * User updatable function that will return a deterministic frame time when engine is in deterministic lock step mode\r\n */\r\n public getDeterministicFrameTime: () => number = () => {\r\n return this._engine.getTimeStep();\r\n };\r\n\r\n /** @internal */\r\n public _animate(): void {\r\n // Nothing to do as long as Animatable have not been imported.\r\n }\r\n\r\n /** Execute all animations (for a frame) */\r\n public animate() {\r\n if (this._engine.isDeterministicLockStep()) {\r\n let deltaTime = Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime)) + this._timeAccumulator;\r\n\r\n const defaultFrameTime = this._engine.getTimeStep();\r\n const defaultFPS = 1000.0 / defaultFrameTime / 1000.0;\r\n\r\n let stepsTaken = 0;\r\n\r\n const maxSubSteps = this._engine.getLockstepMaxSteps();\r\n\r\n let internalSteps = Math.floor(deltaTime / defaultFrameTime);\r\n internalSteps = Math.min(internalSteps, maxSubSteps);\r\n\r\n while (deltaTime > 0 && stepsTaken < internalSteps) {\r\n this.onBeforeStepObservable.notifyObservers(this);\r\n\r\n // Animations\r\n this._animationRatio = defaultFrameTime * defaultFPS;\r\n this._animate();\r\n this.onAfterAnimationsObservable.notifyObservers(this);\r\n\r\n // Physics\r\n if (this.physicsEnabled) {\r\n this._advancePhysicsEngineStep(defaultFrameTime);\r\n }\r\n\r\n this.onAfterStepObservable.notifyObservers(this);\r\n this._currentStepId++;\r\n\r\n stepsTaken++;\r\n deltaTime -= defaultFrameTime;\r\n }\r\n\r\n this._timeAccumulator = deltaTime < 0 ? 0 : deltaTime;\r\n } else {\r\n // Animations\r\n const deltaTime = this.useConstantAnimationDeltaTime ? 16 : Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime));\r\n this._animationRatio = deltaTime * (60.0 / 1000.0);\r\n this._animate();\r\n this.onAfterAnimationsObservable.notifyObservers(this);\r\n\r\n // Physics\r\n if (this.physicsEnabled) {\r\n this._advancePhysicsEngineStep(deltaTime);\r\n }\r\n }\r\n }\r\n\r\n private _clear(): void {\r\n if (this.autoClearDepthAndStencil || this.autoClear) {\r\n this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, this.autoClearDepthAndStencil, this.autoClearDepthAndStencil);\r\n }\r\n }\r\n\r\n private _checkCameraRenderTarget(camera: Nullable) {\r\n if (camera?.outputRenderTarget && !camera?.isRigCamera) {\r\n camera.outputRenderTarget._cleared = false;\r\n }\r\n if (camera?.rigCameras?.length) {\r\n for (let i = 0; i < camera.rigCameras.length; ++i) {\r\n const rtt = camera.rigCameras[i].outputRenderTarget;\r\n if (rtt) {\r\n rtt._cleared = false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Resets the draw wrappers cache of all meshes\r\n * @param passId If provided, releases only the draw wrapper corresponding to this render pass id\r\n */\r\n public resetDrawCache(passId?: number): void {\r\n if (!this.meshes) {\r\n return;\r\n }\r\n\r\n for (const mesh of this.meshes) {\r\n mesh.resetDrawCache(passId);\r\n }\r\n }\r\n\r\n /**\r\n * Render the scene\r\n * @param updateCameras defines a boolean indicating if cameras must update according to their inputs (true by default)\r\n * @param ignoreAnimations defines a boolean indicating if animations should not be executed (false by default)\r\n */\r\n public render(updateCameras = true, ignoreAnimations = false): void {\r\n if (this.isDisposed) {\r\n return;\r\n }\r\n\r\n if (this.onReadyObservable.hasObservers() && this._executeWhenReadyTimeoutId === null) {\r\n this._checkIsReady();\r\n }\r\n\r\n this._frameId++;\r\n this._defaultFrameBufferCleared = false;\r\n this._checkCameraRenderTarget(this.activeCamera);\r\n if (this.activeCameras?.length) {\r\n this.activeCameras.forEach(this._checkCameraRenderTarget);\r\n }\r\n\r\n // Register components that have been associated lately to the scene.\r\n this._registerTransientComponents();\r\n\r\n this._activeParticles.fetchNewFrame();\r\n this._totalVertices.fetchNewFrame();\r\n this._activeIndices.fetchNewFrame();\r\n this._activeBones.fetchNewFrame();\r\n this._meshesForIntersections.reset();\r\n this.resetCachedMaterial();\r\n\r\n this.onBeforeAnimationsObservable.notifyObservers(this);\r\n\r\n // Actions\r\n if (this.actionManager) {\r\n this.actionManager.processTrigger(Constants.ACTION_OnEveryFrameTrigger);\r\n }\r\n\r\n // Animations\r\n if (!ignoreAnimations) {\r\n this.animate();\r\n }\r\n\r\n // Before camera update steps\r\n for (const step of this._beforeCameraUpdateStage) {\r\n step.action();\r\n }\r\n\r\n // Update Cameras\r\n if (updateCameras) {\r\n if (this.activeCameras && this.activeCameras.length > 0) {\r\n for (let cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {\r\n const camera = this.activeCameras[cameraIndex];\r\n camera.update();\r\n if (camera.cameraRigMode !== Constants.RIG_MODE_NONE) {\r\n // rig cameras\r\n for (let index = 0; index < camera._rigCameras.length; index++) {\r\n camera._rigCameras[index].update();\r\n }\r\n }\r\n }\r\n } else if (this.activeCamera) {\r\n this.activeCamera.update();\r\n if (this.activeCamera.cameraRigMode !== Constants.RIG_MODE_NONE) {\r\n // rig cameras\r\n for (let index = 0; index < this.activeCamera._rigCameras.length; index++) {\r\n this.activeCamera._rigCameras[index].update();\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Before render\r\n this.onBeforeRenderObservable.notifyObservers(this);\r\n\r\n const engine = this.getEngine();\r\n\r\n // Customs render targets\r\n this.onBeforeRenderTargetsRenderObservable.notifyObservers(this);\r\n\r\n const currentActiveCamera = this.activeCameras?.length ? this.activeCameras[0] : this.activeCamera;\r\n if (this.renderTargetsEnabled) {\r\n Tools.StartPerformanceCounter(\"Custom render targets\", this.customRenderTargets.length > 0);\r\n this._intermediateRendering = true;\r\n for (let customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {\r\n const renderTarget = this.customRenderTargets[customIndex];\r\n if (renderTarget._shouldRender()) {\r\n this._renderId++;\r\n\r\n this.activeCamera = renderTarget.activeCamera || this.activeCamera;\r\n\r\n if (!this.activeCamera) {\r\n throw new Error(\"Active camera not set\");\r\n }\r\n\r\n // Viewport\r\n engine.setViewport(this.activeCamera.viewport);\r\n\r\n // Camera\r\n this.updateTransformMatrix();\r\n\r\n renderTarget.render(currentActiveCamera !== this.activeCamera, this.dumpNextRenderTargets);\r\n }\r\n }\r\n Tools.EndPerformanceCounter(\"Custom render targets\", this.customRenderTargets.length > 0);\r\n this._intermediateRendering = false;\r\n this._renderId++;\r\n }\r\n\r\n this._engine.currentRenderPassId = currentActiveCamera?.renderPassId ?? Constants.RENDERPASS_MAIN;\r\n\r\n // Restore back buffer\r\n this.activeCamera = currentActiveCamera;\r\n if (this._activeCamera && this._activeCamera.cameraRigMode !== Constants.RIG_MODE_CUSTOM && !this.prePass) {\r\n this._bindFrameBuffer(this._activeCamera, false);\r\n }\r\n this.onAfterRenderTargetsRenderObservable.notifyObservers(this);\r\n\r\n for (const step of this._beforeClearStage) {\r\n step.action();\r\n }\r\n\r\n // Clear\r\n this._clearFrameBuffer(this.activeCamera);\r\n\r\n // Collects render targets from external components.\r\n for (const step of this._gatherRenderTargetsStage) {\r\n step.action(this._renderTargets);\r\n }\r\n\r\n // Multi-cameras?\r\n if (this.activeCameras && this.activeCameras.length > 0) {\r\n for (let cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {\r\n this._processSubCameras(this.activeCameras[cameraIndex], cameraIndex > 0);\r\n }\r\n } else {\r\n if (!this.activeCamera) {\r\n throw new Error(\"No camera defined\");\r\n }\r\n\r\n this._processSubCameras(this.activeCamera, !!this.activeCamera.outputRenderTarget);\r\n }\r\n\r\n // Intersection checks\r\n this._checkIntersections();\r\n\r\n // Executes the after render stage actions.\r\n for (const step of this._afterRenderStage) {\r\n step.action();\r\n }\r\n\r\n // After render\r\n if (this.afterRender) {\r\n this.afterRender();\r\n }\r\n\r\n this.onAfterRenderObservable.notifyObservers(this);\r\n\r\n // Cleaning\r\n if (this._toBeDisposed.length) {\r\n for (let index = 0; index < this._toBeDisposed.length; index++) {\r\n const data = this._toBeDisposed[index];\r\n if (data) {\r\n data.dispose();\r\n }\r\n }\r\n\r\n this._toBeDisposed.length = 0;\r\n }\r\n\r\n if (this.dumpNextRenderTargets) {\r\n this.dumpNextRenderTargets = false;\r\n }\r\n\r\n this._activeBones.addCount(0, true);\r\n this._activeIndices.addCount(0, true);\r\n this._activeParticles.addCount(0, true);\r\n\r\n this._engine.restoreDefaultFramebuffer();\r\n }\r\n\r\n /**\r\n * Freeze all materials\r\n * A frozen material will not be updatable but should be faster to render\r\n * Note: multimaterials will not be frozen, but their submaterials will\r\n */\r\n public freezeMaterials(): void {\r\n for (let i = 0; i < this.materials.length; i++) {\r\n this.materials[i].freeze();\r\n }\r\n }\r\n\r\n /**\r\n * Unfreeze all materials\r\n * A frozen material will not be updatable but should be faster to render\r\n */\r\n public unfreezeMaterials(): void {\r\n for (let i = 0; i < this.materials.length; i++) {\r\n this.materials[i].unfreeze();\r\n }\r\n }\r\n\r\n /**\r\n * Releases all held resources\r\n */\r\n public dispose(): void {\r\n if (this.isDisposed) {\r\n return;\r\n }\r\n\r\n this.beforeRender = null;\r\n this.afterRender = null;\r\n this.metadata = null;\r\n\r\n this.skeletons.length = 0;\r\n this.morphTargetManagers.length = 0;\r\n this._transientComponents.length = 0;\r\n this._isReadyForMeshStage.clear();\r\n this._beforeEvaluateActiveMeshStage.clear();\r\n this._evaluateSubMeshStage.clear();\r\n this._preActiveMeshStage.clear();\r\n this._cameraDrawRenderTargetStage.clear();\r\n this._beforeCameraDrawStage.clear();\r\n this._beforeRenderTargetDrawStage.clear();\r\n this._beforeRenderingGroupDrawStage.clear();\r\n this._beforeRenderingMeshStage.clear();\r\n this._afterRenderingMeshStage.clear();\r\n this._afterRenderingGroupDrawStage.clear();\r\n this._afterCameraDrawStage.clear();\r\n this._afterRenderTargetDrawStage.clear();\r\n this._afterRenderStage.clear();\r\n this._beforeCameraUpdateStage.clear();\r\n this._beforeClearStage.clear();\r\n this._gatherRenderTargetsStage.clear();\r\n this._gatherActiveCameraRenderTargetsStage.clear();\r\n this._pointerMoveStage.clear();\r\n this._pointerDownStage.clear();\r\n this._pointerUpStage.clear();\r\n\r\n this.importedMeshesFiles = new Array();\r\n\r\n if (this.stopAllAnimations) {\r\n // Ensures that no animatable notifies a callback that could start a new animation group, constantly adding new animatables to the active list...\r\n this._activeAnimatables.forEach((animatable) => {\r\n animatable.onAnimationEndObservable.clear();\r\n animatable.onAnimationEnd = null;\r\n });\r\n this.stopAllAnimations();\r\n }\r\n\r\n this.resetCachedMaterial();\r\n\r\n // Smart arrays\r\n if (this.activeCamera) {\r\n this.activeCamera._activeMeshes.dispose();\r\n this.activeCamera = null;\r\n }\r\n this.activeCameras = null;\r\n\r\n this._activeMeshes.dispose();\r\n this._renderingManager.dispose();\r\n this._processedMaterials.dispose();\r\n this._activeParticleSystems.dispose();\r\n this._activeSkeletons.dispose();\r\n this._softwareSkinnedMeshes.dispose();\r\n this._renderTargets.dispose();\r\n this._materialsRenderTargets.dispose();\r\n this._registeredForLateAnimationBindings.dispose();\r\n this._meshesForIntersections.dispose();\r\n this._toBeDisposed.length = 0;\r\n\r\n // Abort active requests\r\n const activeRequests = this._activeRequests.slice();\r\n for (const request of activeRequests) {\r\n request.abort();\r\n }\r\n this._activeRequests.length = 0;\r\n\r\n // Events\r\n try {\r\n this.onDisposeObservable.notifyObservers(this);\r\n } catch (e) {\r\n console.error(\"An error occurred while calling onDisposeObservable!\", e);\r\n }\r\n\r\n this.detachControl();\r\n\r\n // Detach cameras\r\n const canvas = this._engine.getInputElement();\r\n\r\n if (canvas) {\r\n for (let index = 0; index < this.cameras.length; index++) {\r\n this.cameras[index].detachControl();\r\n }\r\n }\r\n\r\n // Release animation groups\r\n this._disposeList(this.animationGroups);\r\n\r\n // Release lights\r\n this._disposeList(this.lights);\r\n\r\n // Release meshes\r\n this._disposeList(this.meshes, (item) => item.dispose(true));\r\n this._disposeList(this.transformNodes, (item) => item.dispose(true));\r\n\r\n // Release cameras\r\n const cameras = this.cameras;\r\n this._disposeList(cameras);\r\n\r\n // Release materials\r\n if (this._defaultMaterial) {\r\n this._defaultMaterial.dispose();\r\n }\r\n this._disposeList(this.multiMaterials);\r\n this._disposeList(this.materials);\r\n\r\n // Release particles\r\n this._disposeList(this.particleSystems);\r\n\r\n // Release postProcesses\r\n this._disposeList(this.postProcesses);\r\n\r\n // Release textures\r\n this._disposeList(this.textures);\r\n\r\n // Release morph targets\r\n this._disposeList(this.morphTargetManagers);\r\n\r\n // Release UBO\r\n this._sceneUbo.dispose();\r\n\r\n if (this._multiviewSceneUbo) {\r\n this._multiviewSceneUbo.dispose();\r\n }\r\n\r\n // Post-processes\r\n this.postProcessManager.dispose();\r\n\r\n // Components\r\n this._disposeList(this._components);\r\n\r\n // Remove from engine\r\n let index = this._engine.scenes.indexOf(this);\r\n\r\n if (index > -1) {\r\n this._engine.scenes.splice(index, 1);\r\n }\r\n\r\n if (EngineStore._LastCreatedScene === this) {\r\n if (this._engine.scenes.length > 0) {\r\n EngineStore._LastCreatedScene = this._engine.scenes[this._engine.scenes.length - 1];\r\n } else {\r\n EngineStore._LastCreatedScene = null;\r\n }\r\n }\r\n\r\n index = this._engine._virtualScenes.indexOf(this);\r\n\r\n if (index > -1) {\r\n this._engine._virtualScenes.splice(index, 1);\r\n }\r\n\r\n this._engine.wipeCaches(true);\r\n this.onDisposeObservable.clear();\r\n this.onBeforeRenderObservable.clear();\r\n this.onAfterRenderObservable.clear();\r\n this.onBeforeRenderTargetsRenderObservable.clear();\r\n this.onAfterRenderTargetsRenderObservable.clear();\r\n this.onAfterStepObservable.clear();\r\n this.onBeforeStepObservable.clear();\r\n this.onBeforeActiveMeshesEvaluationObservable.clear();\r\n this.onAfterActiveMeshesEvaluationObservable.clear();\r\n this.onBeforeParticlesRenderingObservable.clear();\r\n this.onAfterParticlesRenderingObservable.clear();\r\n this.onBeforeDrawPhaseObservable.clear();\r\n this.onAfterDrawPhaseObservable.clear();\r\n this.onBeforeAnimationsObservable.clear();\r\n this.onAfterAnimationsObservable.clear();\r\n this.onDataLoadedObservable.clear();\r\n this.onBeforeRenderingGroupObservable.clear();\r\n this.onAfterRenderingGroupObservable.clear();\r\n this.onMeshImportedObservable.clear();\r\n this.onBeforeCameraRenderObservable.clear();\r\n this.onAfterCameraRenderObservable.clear();\r\n this.onAfterRenderCameraObservable.clear();\r\n this.onReadyObservable.clear();\r\n this.onNewCameraAddedObservable.clear();\r\n this.onCameraRemovedObservable.clear();\r\n this.onNewLightAddedObservable.clear();\r\n this.onLightRemovedObservable.clear();\r\n this.onNewGeometryAddedObservable.clear();\r\n this.onGeometryRemovedObservable.clear();\r\n this.onNewTransformNodeAddedObservable.clear();\r\n this.onTransformNodeRemovedObservable.clear();\r\n this.onNewMeshAddedObservable.clear();\r\n this.onMeshRemovedObservable.clear();\r\n this.onNewSkeletonAddedObservable.clear();\r\n this.onSkeletonRemovedObservable.clear();\r\n this.onNewMaterialAddedObservable.clear();\r\n this.onNewMultiMaterialAddedObservable.clear();\r\n this.onMaterialRemovedObservable.clear();\r\n this.onMultiMaterialRemovedObservable.clear();\r\n this.onNewTextureAddedObservable.clear();\r\n this.onTextureRemovedObservable.clear();\r\n this.onPrePointerObservable.clear();\r\n this.onPointerObservable.clear();\r\n this.onPreKeyboardObservable.clear();\r\n this.onKeyboardObservable.clear();\r\n this.onActiveCameraChanged.clear();\r\n this.onScenePerformancePriorityChangedObservable.clear();\r\n this._isDisposed = true;\r\n }\r\n\r\n private _disposeList(items: T[], callback?: (item: T) => void): void {\r\n const itemsCopy = items.slice(0);\r\n callback = callback ?? ((item) => item.dispose());\r\n for (const item of itemsCopy) {\r\n callback(item);\r\n }\r\n items.length = 0;\r\n }\r\n\r\n /**\r\n * Gets if the scene is already disposed\r\n */\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Call this function to reduce memory footprint of the scene.\r\n * Vertex buffers will not store CPU data anymore (this will prevent picking, collisions or physics to work correctly)\r\n */\r\n public clearCachedVertexData(): void {\r\n for (let meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {\r\n const mesh = this.meshes[meshIndex];\r\n const geometry = (mesh).geometry;\r\n\r\n if (geometry) {\r\n geometry.clearCachedData();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * This function will remove the local cached buffer data from texture.\r\n * It will save memory but will prevent the texture from being rebuilt\r\n */\r\n public cleanCachedTextureBuffer(): void {\r\n for (const baseTexture of this.textures) {\r\n const buffer = (baseTexture)._buffer;\r\n\r\n if (buffer) {\r\n (baseTexture)._buffer = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Get the world extend vectors with an optional filter\r\n *\r\n * @param filterPredicate the predicate - which meshes should be included when calculating the world size\r\n * @returns {{ min: Vector3; max: Vector3 }} min and max vectors\r\n */\r\n public getWorldExtends(filterPredicate?: (mesh: AbstractMesh) => boolean): { min: Vector3; max: Vector3 } {\r\n const min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n const max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\r\n filterPredicate = filterPredicate || (() => true);\r\n this.meshes.filter(filterPredicate).forEach((mesh) => {\r\n mesh.computeWorldMatrix(true);\r\n\r\n if (!mesh.subMeshes || mesh.subMeshes.length === 0 || mesh.infiniteDistance) {\r\n return;\r\n }\r\n\r\n const boundingInfo = mesh.getBoundingInfo();\r\n\r\n const minBox = boundingInfo.boundingBox.minimumWorld;\r\n const maxBox = boundingInfo.boundingBox.maximumWorld;\r\n\r\n Vector3.CheckExtends(minBox, min, max);\r\n Vector3.CheckExtends(maxBox, min, max);\r\n });\r\n\r\n return {\r\n min: min,\r\n max: max,\r\n };\r\n }\r\n\r\n // Picking\r\n\r\n /**\r\n * Creates a ray that can be used to pick in the scene\r\n * @param x defines the x coordinate of the origin (on-screen)\r\n * @param y defines the y coordinate of the origin (on-screen)\r\n * @param world defines the world matrix to use if you want to pick in object space (instead of world space)\r\n * @param camera defines the camera to use for the picking\r\n * @param cameraViewSpace defines if picking will be done in view space (false by default)\r\n * @returns a Ray\r\n */\r\n public createPickingRay(x: number, y: number, world: Nullable, camera: Nullable, cameraViewSpace = false): Ray {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Creates a ray that can be used to pick in the scene\r\n * @param x defines the x coordinate of the origin (on-screen)\r\n * @param y defines the y coordinate of the origin (on-screen)\r\n * @param world defines the world matrix to use if you want to pick in object space (instead of world space)\r\n * @param result defines the ray where to store the picking ray\r\n * @param camera defines the camera to use for the picking\r\n * @param cameraViewSpace defines if picking will be done in view space (false by default)\r\n * @param enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)\r\n * @returns the current scene\r\n */\r\n public createPickingRayToRef(\r\n x: number,\r\n y: number,\r\n world: Nullable,\r\n result: Ray,\r\n camera: Nullable,\r\n cameraViewSpace = false,\r\n enableDistantPicking = false\r\n ): Scene {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Creates a ray that can be used to pick in the scene\r\n * @param x defines the x coordinate of the origin (on-screen)\r\n * @param y defines the y coordinate of the origin (on-screen)\r\n * @param camera defines the camera to use for the picking\r\n * @returns a Ray\r\n */\r\n public createPickingRayInCameraSpace(x: number, y: number, camera?: Camera): Ray {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Creates a ray that can be used to pick in the scene\r\n * @param x defines the x coordinate of the origin (on-screen)\r\n * @param y defines the y coordinate of the origin (on-screen)\r\n * @param result defines the ray where to store the picking ray\r\n * @param camera defines the camera to use for the picking\r\n * @returns the current scene\r\n */\r\n public createPickingRayInCameraSpaceToRef(x: number, y: number, result: Ray, camera?: Camera): Scene {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /** @internal */\r\n public get _pickingAvailable(): boolean {\r\n return false;\r\n }\r\n\r\n /** @internal */\r\n public _registeredActions: number = 0;\r\n\r\n /** Launch a ray to try to pick a mesh in the scene\r\n * @param x position on screen\r\n * @param y position on screen\r\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\r\n * @param fastCheck defines if the first intersection will be used (and not the closest)\r\n * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @returns a PickingInfo\r\n */\r\n public pick(\r\n x: number,\r\n y: number,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n fastCheck?: boolean,\r\n camera?: Nullable,\r\n trianglePredicate?: TrianglePickingPredicate\r\n ): PickingInfo {\r\n // Dummy info if picking as not been imported\r\n return new PickingInfo();\r\n }\r\n\r\n /** Launch a ray to try to pick a mesh in the scene using only bounding information of the main mesh (not using submeshes)\r\n * @param x position on screen\r\n * @param y position on screen\r\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\r\n * @param fastCheck defines if the first intersection will be used (and not the closest)\r\n * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used\r\n * @returns a PickingInfo (Please note that some info will not be set like distance, bv, bu and everything that cannot be capture by only using bounding infos)\r\n */\r\n public pickWithBoundingInfo(x: number, y: number, predicate?: (mesh: AbstractMesh) => boolean, fastCheck?: boolean, camera?: Nullable): Nullable {\r\n // Dummy info if picking as not been imported\r\n return new PickingInfo();\r\n }\r\n\r\n /**\r\n * Use the given ray to pick a mesh in the scene. A mesh triangle can be picked both from its front and back sides,\r\n * irrespective of orientation.\r\n * @param ray The ray to use to pick meshes\r\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must have isPickable set to true\r\n * @param fastCheck defines if the first intersection will be used (and not the closest)\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @returns a PickingInfo\r\n */\r\n public pickWithRay(ray: Ray, predicate?: (mesh: AbstractMesh) => boolean, fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Launch a ray to try to pick a mesh in the scene. A mesh triangle can be picked both from its front and back sides,\r\n * irrespective of orientation.\r\n * @param x X position on screen\r\n * @param y Y position on screen\r\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\r\n * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @returns an array of PickingInfo\r\n */\r\n public multiPick(x: number, y: number, predicate?: (mesh: AbstractMesh) => boolean, camera?: Camera, trianglePredicate?: TrianglePickingPredicate): Nullable {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Launch a ray to try to pick a mesh in the scene\r\n * @param ray Ray to use\r\n * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @returns an array of PickingInfo\r\n */\r\n public multiPickWithRay(ray: Ray, predicate?: (mesh: AbstractMesh) => boolean, trianglePredicate?: TrianglePickingPredicate): Nullable {\r\n throw _WarnImport(\"Ray\");\r\n }\r\n\r\n /**\r\n * Force the value of meshUnderPointer\r\n * @param mesh defines the mesh to use\r\n * @param pointerId optional pointer id when using more than one pointer\r\n * @param pickResult optional pickingInfo data used to find mesh\r\n */\r\n public setPointerOverMesh(mesh: Nullable, pointerId?: number, pickResult?: Nullable): void {\r\n this._inputManager.setPointerOverMesh(mesh, pointerId, pickResult);\r\n }\r\n\r\n /**\r\n * Gets the mesh under the pointer\r\n * @returns a Mesh or null if no mesh is under the pointer\r\n */\r\n public getPointerOverMesh(): Nullable {\r\n return this._inputManager.getPointerOverMesh();\r\n }\r\n\r\n // Misc.\r\n /** @internal */\r\n public _rebuildGeometries(): void {\r\n for (const geometry of this.geometries) {\r\n geometry._rebuild();\r\n }\r\n\r\n for (const mesh of this.meshes) {\r\n mesh._rebuild();\r\n }\r\n\r\n if (this.postProcessManager) {\r\n this.postProcessManager._rebuild();\r\n }\r\n\r\n for (const component of this._components) {\r\n component.rebuild();\r\n }\r\n\r\n for (const system of this.particleSystems) {\r\n system.rebuild();\r\n }\r\n\r\n if (this.spriteManagers) {\r\n for (const spriteMgr of this.spriteManagers) {\r\n spriteMgr.rebuild();\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _rebuildTextures(): void {\r\n for (const texture of this.textures) {\r\n texture._rebuild();\r\n }\r\n\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n // Tags\r\n private _getByTags(list: any[], tagsQuery: string, forEach?: (item: any) => void): any[] {\r\n if (tagsQuery === undefined) {\r\n // returns the complete list (could be done with Tags.MatchesQuery but no need to have a for-loop here)\r\n return list;\r\n }\r\n\r\n const listByTags = [];\r\n\r\n forEach =\r\n forEach ||\r\n ((item: any) => {\r\n return;\r\n });\r\n\r\n for (const i in list) {\r\n const item = list[i];\r\n if (Tags && Tags.MatchesQuery(item, tagsQuery)) {\r\n listByTags.push(item);\r\n forEach(item);\r\n }\r\n }\r\n\r\n return listByTags;\r\n }\r\n\r\n /**\r\n * Get a list of meshes by tags\r\n * @param tagsQuery defines the tags query to use\r\n * @param forEach defines a predicate used to filter results\r\n * @returns an array of Mesh\r\n */\r\n public getMeshesByTags(tagsQuery: string, forEach?: (mesh: AbstractMesh) => void): Mesh[] {\r\n return this._getByTags(this.meshes, tagsQuery, forEach);\r\n }\r\n\r\n /**\r\n * Get a list of cameras by tags\r\n * @param tagsQuery defines the tags query to use\r\n * @param forEach defines a predicate used to filter results\r\n * @returns an array of Camera\r\n */\r\n public getCamerasByTags(tagsQuery: string, forEach?: (camera: Camera) => void): Camera[] {\r\n return this._getByTags(this.cameras, tagsQuery, forEach);\r\n }\r\n\r\n /**\r\n * Get a list of lights by tags\r\n * @param tagsQuery defines the tags query to use\r\n * @param forEach defines a predicate used to filter results\r\n * @returns an array of Light\r\n */\r\n public getLightsByTags(tagsQuery: string, forEach?: (light: Light) => void): Light[] {\r\n return this._getByTags(this.lights, tagsQuery, forEach);\r\n }\r\n\r\n /**\r\n * Get a list of materials by tags\r\n * @param tagsQuery defines the tags query to use\r\n * @param forEach defines a predicate used to filter results\r\n * @returns an array of Material\r\n */\r\n public getMaterialByTags(tagsQuery: string, forEach?: (material: Material) => void): Material[] {\r\n return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));\r\n }\r\n\r\n /**\r\n * Get a list of transform nodes by tags\r\n * @param tagsQuery defines the tags query to use\r\n * @param forEach defines a predicate used to filter results\r\n * @returns an array of TransformNode\r\n */\r\n public getTransformNodesByTags(tagsQuery: string, forEach?: (transform: TransformNode) => void): TransformNode[] {\r\n return this._getByTags(this.transformNodes, tagsQuery, forEach);\r\n }\r\n\r\n /**\r\n * Overrides the default sort function applied in the rendering group to prepare the meshes.\r\n * This allowed control for front to back rendering or reversly depending of the special needs.\r\n *\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param opaqueSortCompareFn The opaque queue comparison function use to sort.\r\n * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.\r\n * @param transparentSortCompareFn The transparent queue comparison function use to sort.\r\n */\r\n public setRenderingOrder(\r\n renderingGroupId: number,\r\n opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n transparentSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null\r\n ): void {\r\n this._renderingManager.setRenderingOrder(renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn);\r\n }\r\n\r\n /**\r\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.\r\n *\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\r\n * @param depth Automatically clears depth between groups if true and autoClear is true.\r\n * @param stencil Automatically clears stencil between groups if true and autoClear is true.\r\n */\r\n public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean, depth = true, stencil = true): void {\r\n this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil, depth, stencil);\r\n }\r\n\r\n /**\r\n * Gets the current auto clear configuration for one rendering group of the rendering\r\n * manager.\r\n * @param index the rendering group index to get the information for\r\n * @returns The auto clear setup for the requested rendering group\r\n */\r\n public getAutoClearDepthStencilSetup(index: number): IRenderingManagerAutoClearSetup {\r\n return this._renderingManager.getAutoClearDepthStencilSetup(index);\r\n }\r\n\r\n private _blockMaterialDirtyMechanism = false;\r\n\r\n /** Gets or sets a boolean blocking all the calls to markAllMaterialsAsDirty (ie. the materials won't be updated if they are out of sync) */\r\n public get blockMaterialDirtyMechanism(): boolean {\r\n return this._blockMaterialDirtyMechanism;\r\n }\r\n\r\n public set blockMaterialDirtyMechanism(value: boolean) {\r\n if (this._blockMaterialDirtyMechanism === value) {\r\n return;\r\n }\r\n\r\n this._blockMaterialDirtyMechanism = value;\r\n\r\n if (!value) {\r\n // Do a complete update\r\n this.markAllMaterialsAsDirty(Constants.MATERIAL_AllDirtyFlag);\r\n }\r\n }\r\n\r\n /**\r\n * Will flag all materials as dirty to trigger new shader compilation\r\n * @param flag defines the flag used to specify which material part must be marked as dirty\r\n * @param predicate If not null, it will be used to specify if a material has to be marked as dirty\r\n */\r\n public markAllMaterialsAsDirty(flag: number, predicate?: (mat: Material) => boolean): void {\r\n if (this._blockMaterialDirtyMechanism) {\r\n return;\r\n }\r\n\r\n for (const material of this.materials) {\r\n if (predicate && !predicate(material)) {\r\n continue;\r\n }\r\n material.markAsDirty(flag);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadFile(\r\n fileOrUrl: File | string,\r\n onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n useOfflineSupport?: boolean,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void,\r\n onOpened?: (request: WebRequest) => void\r\n ): IFileRequest {\r\n const request = LoadFile(fileOrUrl, onSuccess, onProgress, useOfflineSupport ? this.offlineProvider : undefined, useArrayBuffer, onError, onOpened);\r\n this._activeRequests.push(request);\r\n request.onCompleteObservable.add((request) => {\r\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\r\n });\r\n return request;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadFileAsync(\r\n fileOrUrl: File | string,\r\n onProgress?: (data: any) => void,\r\n useOfflineSupport?: boolean,\r\n useArrayBuffer?: boolean,\r\n onOpened?: (request: WebRequest) => void\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n this._loadFile(\r\n fileOrUrl,\r\n (data) => {\r\n resolve(data);\r\n },\r\n onProgress,\r\n useOfflineSupport,\r\n useArrayBuffer,\r\n (request, exception) => {\r\n reject(exception);\r\n },\r\n onOpened\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _requestFile(\r\n url: string,\r\n onSuccess: (data: string | ArrayBuffer, request?: WebRequest) => void,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n useOfflineSupport?: boolean,\r\n useArrayBuffer?: boolean,\r\n onError?: (error: RequestFileError) => void,\r\n onOpened?: (request: WebRequest) => void\r\n ): IFileRequest {\r\n const request = RequestFile(url, onSuccess, onProgress, useOfflineSupport ? this.offlineProvider : undefined, useArrayBuffer, onError, onOpened);\r\n this._activeRequests.push(request);\r\n request.onCompleteObservable.add((request) => {\r\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\r\n });\r\n return request;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _requestFileAsync(\r\n url: string,\r\n onProgress?: (ev: ProgressEvent) => void,\r\n useOfflineSupport?: boolean,\r\n useArrayBuffer?: boolean,\r\n onOpened?: (request: WebRequest) => void\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n this._requestFile(\r\n url,\r\n (data) => {\r\n resolve(data);\r\n },\r\n onProgress,\r\n useOfflineSupport,\r\n useArrayBuffer,\r\n (error) => {\r\n reject(error);\r\n },\r\n onOpened\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _readFile(\r\n file: File,\r\n onSuccess: (data: string | ArrayBuffer) => void,\r\n onProgress?: (ev: ProgressEvent) => any,\r\n useArrayBuffer?: boolean,\r\n onError?: (error: ReadFileError) => void\r\n ): IFileRequest {\r\n const request = ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError);\r\n this._activeRequests.push(request);\r\n request.onCompleteObservable.add((request) => {\r\n this._activeRequests.splice(this._activeRequests.indexOf(request), 1);\r\n });\r\n return request;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _readFileAsync(file: File, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean): Promise {\r\n return new Promise((resolve, reject) => {\r\n this._readFile(\r\n file,\r\n (data) => {\r\n resolve(data);\r\n },\r\n onProgress,\r\n useArrayBuffer,\r\n (error) => {\r\n reject(error);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Internal perfCollector instance used for sharing between inspector and playground.\r\n * Marked as protected to allow sharing between prototype extensions, but disallow access at toplevel.\r\n */\r\n protected _perfCollector: Nullable = null;\r\n\r\n /**\r\n * This method gets the performance collector belonging to the scene, which is generally shared with the inspector.\r\n * @returns the perf collector belonging to the scene.\r\n */\r\n public getPerfCollector(): PerformanceViewerCollector {\r\n throw _WarnImport(\"performanceViewerSceneExtension\");\r\n }\r\n\r\n // deprecated\r\n\r\n /**\r\n * Sets the active camera of the scene using its Id\r\n * @param id defines the camera's Id\r\n * @returns the new active camera or null if none found.\r\n * @deprecated Please use setActiveCameraById instead\r\n */\r\n setActiveCameraByID(id: string): Nullable {\r\n return this.setActiveCameraById(id);\r\n }\r\n /**\r\n * Get a material using its id\r\n * @param id defines the material's Id\r\n * @returns the material or null if none found.\r\n * @deprecated Please use getMaterialById instead\r\n */\r\n getMaterialByID(id: string): Nullable {\r\n return this.getMaterialById(id);\r\n }\r\n /**\r\n * Gets a the last added material using a given id\r\n * @param id defines the material's Id\r\n * @returns the last material with the given id or null if none found.\r\n * @deprecated Please use getLastMaterialById instead\r\n */\r\n getLastMaterialByID(id: string): Nullable {\r\n return this.getLastMaterialById(id);\r\n }\r\n\r\n /**\r\n * Get a texture using its unique id\r\n * @param uniqueId defines the texture's unique id\r\n * @returns the texture or null if none found.\r\n * @deprecated Please use getTextureByUniqueId instead\r\n */\r\n getTextureByUniqueID(uniqueId: number): Nullable {\r\n return this.getTextureByUniqueId(uniqueId);\r\n }\r\n /**\r\n * Gets a camera using its Id\r\n * @param id defines the Id to look for\r\n * @returns the camera or null if not found\r\n * @deprecated Please use getCameraById instead\r\n */\r\n getCameraByID(id: string): Nullable {\r\n return this.getCameraById(id);\r\n }\r\n /**\r\n * Gets a camera using its unique Id\r\n * @param uniqueId defines the unique Id to look for\r\n * @returns the camera or null if not found\r\n * @deprecated Please use getCameraByUniqueId instead\r\n */\r\n getCameraByUniqueID(uniqueId: number): Nullable {\r\n return this.getCameraByUniqueId(uniqueId);\r\n }\r\n /**\r\n * Gets a bone using its Id\r\n * @param id defines the bone's Id\r\n * @returns the bone or null if not found\r\n * @deprecated Please use getBoneById instead\r\n */\r\n getBoneByID(id: string): Nullable {\r\n return this.getBoneById(id);\r\n }\r\n /**\r\n * Gets a light node using its Id\r\n * @param id defines the light's Id\r\n * @returns the light or null if none found.\r\n * @deprecated Please use getLightById instead\r\n */\r\n getLightByID(id: string): Nullable {\r\n return this.getLightById(id);\r\n }\r\n /**\r\n * Gets a light node using its scene-generated unique Id\r\n * @param uniqueId defines the light's unique Id\r\n * @returns the light or null if none found.\r\n * @deprecated Please use getLightByUniqueId instead\r\n */\r\n getLightByUniqueID(uniqueId: number): Nullable {\r\n return this.getLightByUniqueId(uniqueId);\r\n }\r\n /**\r\n * Gets a particle system by Id\r\n * @param id defines the particle system Id\r\n * @returns the corresponding system or null if none found\r\n * @deprecated Please use getParticleSystemById instead\r\n */\r\n getParticleSystemByID(id: string): Nullable {\r\n return this.getParticleSystemById(id);\r\n }\r\n /**\r\n * Gets a geometry using its Id\r\n * @param id defines the geometry's Id\r\n * @returns the geometry or null if none found.\r\n * @deprecated Please use getGeometryById instead\r\n */\r\n getGeometryByID(id: string): Nullable {\r\n return this.getGeometryById(id);\r\n }\r\n /**\r\n * Gets the first added mesh found of a given Id\r\n * @param id defines the Id to search for\r\n * @returns the mesh found or null if not found at all\r\n * @deprecated Please use getMeshById instead\r\n */\r\n getMeshByID(id: string): Nullable {\r\n return this.getMeshById(id);\r\n }\r\n /**\r\n * Gets a mesh with its auto-generated unique Id\r\n * @param uniqueId defines the unique Id to search for\r\n * @returns the found mesh or null if not found at all.\r\n * @deprecated Please use getMeshByUniqueId instead\r\n */\r\n getMeshByUniqueID(uniqueId: number): Nullable {\r\n return this.getMeshByUniqueId(uniqueId);\r\n }\r\n /**\r\n * Gets a the last added mesh using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found mesh or null if not found at all.\r\n * @deprecated Please use getLastMeshById instead\r\n */\r\n getLastMeshByID(id: string): Nullable {\r\n return this.getLastMeshById(id);\r\n }\r\n /**\r\n * Gets a list of meshes using their Id\r\n * @param id defines the Id to search for\r\n * @returns a list of meshes\r\n * @deprecated Please use getMeshesById instead\r\n */\r\n getMeshesByID(id: string): Array {\r\n return this.getMeshesById(id);\r\n }\r\n /**\r\n * Gets the first added transform node found of a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found transform node or null if not found at all.\r\n * @deprecated Please use getTransformNodeById instead\r\n */\r\n getTransformNodeByID(id: string): Nullable {\r\n return this.getTransformNodeById(id);\r\n }\r\n /**\r\n * Gets a transform node with its auto-generated unique Id\r\n * @param uniqueId defines the unique Id to search for\r\n * @returns the found transform node or null if not found at all.\r\n * @deprecated Please use getTransformNodeByUniqueId instead\r\n */\r\n getTransformNodeByUniqueID(uniqueId: number): Nullable {\r\n return this.getTransformNodeByUniqueId(uniqueId);\r\n }\r\n /**\r\n * Gets a list of transform nodes using their Id\r\n * @param id defines the Id to search for\r\n * @returns a list of transform nodes\r\n * @deprecated Please use getTransformNodesById instead\r\n */\r\n getTransformNodesByID(id: string): Array {\r\n return this.getTransformNodesById(id);\r\n }\r\n /**\r\n * Gets a node (Mesh, Camera, Light) using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found node or null if not found at all\r\n * @deprecated Please use getNodeById instead\r\n */\r\n getNodeByID(id: string): Nullable {\r\n return this.getNodeById(id);\r\n }\r\n /**\r\n * Gets a the last added node (Mesh, Camera, Light) using a given Id\r\n * @param id defines the Id to search for\r\n * @returns the found node or null if not found at all\r\n * @deprecated Please use getLastEntryById instead\r\n */\r\n getLastEntryByID(id: string): Nullable {\r\n return this.getLastEntryById(id);\r\n }\r\n /**\r\n * Gets a skeleton using a given Id (if many are found, this function will pick the last one)\r\n * @param id defines the Id to search for\r\n * @returns the found skeleton or null if not found at all.\r\n * @deprecated Please use getLastSkeletonById instead\r\n */\r\n getLastSkeletonByID(id: string): Nullable {\r\n return this.getLastSkeletonById(id);\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class IntersectionInfo {\r\n public faceId = 0;\r\n public subMeshId = 0;\r\n\r\n constructor(public bu: Nullable, public bv: Nullable, public distance: number) {}\r\n}\r\n","import type { DeepImmutable, Nullable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { BoundingSphere } from \"../Culling/boundingSphere\";\r\n\r\nimport type { ICullable } from \"./boundingInfo\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\nimport type { DrawWrapper } from \"../Materials/drawWrapper\";\r\n\r\n/**\r\n * Class used to store bounding box information\r\n */\r\nexport class BoundingBox implements ICullable {\r\n /**\r\n * Gets the 8 vectors representing the bounding box in local space\r\n */\r\n public readonly vectors: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);\r\n /**\r\n * Gets the center of the bounding box in local space\r\n */\r\n public readonly center: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the center of the bounding box in world space\r\n */\r\n public readonly centerWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the extend size in local space\r\n */\r\n public readonly extendSize: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the extend size in world space\r\n */\r\n public readonly extendSizeWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the OBB (object bounding box) directions\r\n */\r\n public readonly directions: Vector3[] = ArrayTools.BuildArray(3, Vector3.Zero);\r\n /**\r\n * Gets the 8 vectors representing the bounding box in world space\r\n */\r\n public readonly vectorsWorld: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);\r\n /**\r\n * Gets the minimum vector in world space\r\n */\r\n public readonly minimumWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in world space\r\n */\r\n public readonly maximumWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the minimum vector in local space\r\n */\r\n public readonly minimum: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in local space\r\n */\r\n public readonly maximum: Vector3 = Vector3.Zero();\r\n\r\n private _worldMatrix: DeepImmutable;\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);\r\n\r\n /**\r\n * @internal\r\n */\r\n public _tag: number;\r\n\r\n /** @internal */\r\n public _drawWrapperFront: Nullable = null;\r\n /** @internal */\r\n public _drawWrapperBack: Nullable = null;\r\n\r\n /**\r\n * Creates a new bounding box\r\n * @param min defines the minimum vector (in local space)\r\n * @param max defines the maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(min: DeepImmutable, max: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n this.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Recreates the entire bounding box from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable, max: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n const vectors = this.vectors;\r\n\r\n this.minimum.copyFromFloats(minX, minY, minZ);\r\n this.maximum.copyFromFloats(maxX, maxY, maxZ);\r\n vectors[0].copyFromFloats(minX, minY, minZ);\r\n vectors[1].copyFromFloats(maxX, maxY, maxZ);\r\n vectors[2].copyFromFloats(maxX, minY, minZ);\r\n vectors[3].copyFromFloats(minX, maxY, minZ);\r\n vectors[4].copyFromFloats(minX, minY, maxZ);\r\n vectors[5].copyFromFloats(maxX, maxY, minZ);\r\n vectors[6].copyFromFloats(minX, maxY, maxZ);\r\n vectors[7].copyFromFloats(maxX, minY, maxZ);\r\n\r\n // OBB\r\n max.addToRef(min, this.center).scaleInPlace(0.5);\r\n max.subtractToRef(min, this.extendSize).scaleInPlace(0.5);\r\n\r\n this._worldMatrix = worldMatrix || Matrix.IdentityReadOnly;\r\n\r\n this._update(this._worldMatrix);\r\n }\r\n\r\n /**\r\n * Scale the current bounding box by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding box\r\n */\r\n public scale(factor: number): BoundingBox {\r\n const tmpVectors = BoundingBox._TmpVector3;\r\n const diff = this.maximum.subtractToRef(this.minimum, tmpVectors[0]);\r\n const len = diff.length();\r\n diff.normalizeFromLength(len);\r\n const distance = len * factor;\r\n const newRadius = diff.scaleInPlace(distance * 0.5);\r\n\r\n const min = this.center.subtractToRef(newRadius, tmpVectors[1]);\r\n const max = this.center.addToRef(newRadius, tmpVectors[2]);\r\n\r\n this.reConstruct(min, max, this._worldMatrix);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the world matrix of the bounding box\r\n * @returns a matrix\r\n */\r\n public getWorldMatrix(): DeepImmutable {\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _update(world: DeepImmutable): void {\r\n const minWorld = this.minimumWorld;\r\n const maxWorld = this.maximumWorld;\r\n const directions = this.directions;\r\n const vectorsWorld = this.vectorsWorld;\r\n const vectors = this.vectors;\r\n\r\n if (!world.isIdentity()) {\r\n minWorld.setAll(Number.MAX_VALUE);\r\n maxWorld.setAll(-Number.MAX_VALUE);\r\n\r\n for (let index = 0; index < 8; ++index) {\r\n const v = vectorsWorld[index];\r\n Vector3.TransformCoordinatesToRef(vectors[index], world, v);\r\n minWorld.minimizeInPlace(v);\r\n maxWorld.maximizeInPlace(v);\r\n }\r\n\r\n // Extend\r\n maxWorld.subtractToRef(minWorld, this.extendSizeWorld).scaleInPlace(0.5);\r\n maxWorld.addToRef(minWorld, this.centerWorld).scaleInPlace(0.5);\r\n } else {\r\n minWorld.copyFrom(this.minimum);\r\n maxWorld.copyFrom(this.maximum);\r\n for (let index = 0; index < 8; ++index) {\r\n vectorsWorld[index].copyFrom(vectors[index]);\r\n }\r\n\r\n // Extend\r\n this.extendSizeWorld.copyFrom(this.extendSize);\r\n this.centerWorld.copyFrom(this.center);\r\n }\r\n\r\n Vector3.FromArrayToRef(world.m, 0, directions[0]);\r\n Vector3.FromArrayToRef(world.m, 4, directions[1]);\r\n Vector3.FromArrayToRef(world.m, 8, directions[2]);\r\n\r\n this._worldMatrix = world;\r\n }\r\n\r\n /**\r\n * Tests if the bounding box is intersecting the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public isInFrustum(frustumPlanes: Array>): boolean {\r\n return BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);\r\n }\r\n\r\n /**\r\n * Tests if the bounding box is entirely inside the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an inclusion\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Array>): boolean {\r\n return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);\r\n }\r\n\r\n /**\r\n * Tests if a point is inside the bounding box\r\n * @param point defines the point to test\r\n * @returns true if the point is inside the bounding box\r\n */\r\n public intersectsPoint(point: DeepImmutable): boolean {\r\n const min = this.minimumWorld;\r\n const max = this.maximumWorld;\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n const pointX = point.x,\r\n pointY = point.y,\r\n pointZ = point.z;\r\n const delta = -Epsilon;\r\n\r\n if (maxX - pointX < delta || delta > pointX - minX) {\r\n return false;\r\n }\r\n\r\n if (maxY - pointY < delta || delta > pointY - minY) {\r\n return false;\r\n }\r\n\r\n if (maxZ - pointZ < delta || delta > pointZ - minZ) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if the bounding box intersects with a bounding sphere\r\n * @param sphere defines the sphere to test\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsSphere(sphere: DeepImmutable): boolean {\r\n return BoundingBox.IntersectsSphere(this.minimumWorld, this.maximumWorld, sphere.centerWorld, sphere.radiusWorld);\r\n }\r\n\r\n /**\r\n * Tests if the bounding box intersects with a box defined by a min and max vectors\r\n * @param min defines the min vector to use\r\n * @param max defines the max vector to use\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsMinMax(min: DeepImmutable, max: DeepImmutable): boolean {\r\n const myMin = this.minimumWorld;\r\n const myMax = this.maximumWorld;\r\n const myMinX = myMin.x,\r\n myMinY = myMin.y,\r\n myMinZ = myMin.z,\r\n myMaxX = myMax.x,\r\n myMaxY = myMax.y,\r\n myMaxZ = myMax.z;\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n if (myMaxX < minX || myMinX > maxX) {\r\n return false;\r\n }\r\n\r\n if (myMaxY < minY || myMinY > maxY) {\r\n return false;\r\n }\r\n\r\n if (myMaxZ < minZ || myMinZ > maxZ) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Disposes the resources of the class\r\n */\r\n public dispose(): void {\r\n this._drawWrapperFront?.dispose();\r\n this._drawWrapperBack?.dispose();\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Tests if two bounding boxes are intersections\r\n * @param box0 defines the first box to test\r\n * @param box1 defines the second box to test\r\n * @returns true if there is an intersection\r\n */\r\n public static Intersects(box0: DeepImmutable, box1: DeepImmutable): boolean {\r\n return box0.intersectsMinMax(box1.minimumWorld, box1.maximumWorld);\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defines by a min/max vectors intersects a sphere\r\n * @param minPoint defines the minimum vector of the bounding box\r\n * @param maxPoint defines the maximum vector of the bounding box\r\n * @param sphereCenter defines the sphere center\r\n * @param sphereRadius defines the sphere radius\r\n * @returns true if there is an intersection\r\n */\r\n public static IntersectsSphere(minPoint: DeepImmutable, maxPoint: DeepImmutable, sphereCenter: DeepImmutable, sphereRadius: number): boolean {\r\n const vector = BoundingBox._TmpVector3[0];\r\n Vector3.ClampToRef(sphereCenter, minPoint, maxPoint, vector);\r\n const num = Vector3.DistanceSquared(sphereCenter, vector);\r\n return num <= sphereRadius * sphereRadius;\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defined with 8 vectors is entirely inside frustum planes\r\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an inclusion\r\n */\r\n public static IsCompletelyInFrustum(boundingVectors: Array>, frustumPlanes: Array>): boolean {\r\n for (let p = 0; p < 6; ++p) {\r\n const frustumPlane = frustumPlanes[p];\r\n for (let i = 0; i < 8; ++i) {\r\n if (frustumPlane.dotCoordinate(boundingVectors[i]) < 0) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defined with 8 vectors intersects frustum planes\r\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public static IsInFrustum(boundingVectors: Array>, frustumPlanes: Array>): boolean {\r\n for (let p = 0; p < 6; ++p) {\r\n let canReturnFalse = true;\r\n const frustumPlane = frustumPlanes[p];\r\n for (let i = 0; i < 8; ++i) {\r\n if (frustumPlane.dotCoordinate(boundingVectors[i]) >= 0) {\r\n canReturnFalse = false;\r\n break;\r\n }\r\n }\r\n if (canReturnFalse) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n}\r\n","import type { DeepImmutable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\n/**\r\n * Class used to store bounding sphere information\r\n */\r\nexport class BoundingSphere {\r\n /**\r\n * Gets the center of the bounding sphere in local space\r\n */\r\n public readonly center = Vector3.Zero();\r\n /**\r\n * Radius of the bounding sphere in local space\r\n */\r\n public radius: number;\r\n /**\r\n * Gets the center of the bounding sphere in world space\r\n */\r\n public readonly centerWorld = Vector3.Zero();\r\n /**\r\n * Radius of the bounding sphere in world space\r\n */\r\n public radiusWorld: number;\r\n /**\r\n * Gets the minimum vector in local space\r\n */\r\n public readonly minimum = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in local space\r\n */\r\n public readonly maximum = Vector3.Zero();\r\n\r\n private _worldMatrix: DeepImmutable;\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);\r\n\r\n /**\r\n * Creates a new bounding sphere\r\n * @param min defines the minimum vector (in local space)\r\n * @param max defines the maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(min: DeepImmutable, max: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n this.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n /**\r\n * Recreates the entire bounding sphere from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable, max: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n this.minimum.copyFrom(min);\r\n this.maximum.copyFrom(max);\r\n\r\n const distance = Vector3.Distance(min, max);\r\n\r\n max.addToRef(min, this.center).scaleInPlace(0.5);\r\n this.radius = distance * 0.5;\r\n\r\n this._update(worldMatrix || Matrix.IdentityReadOnly);\r\n }\r\n\r\n /**\r\n * Scale the current bounding sphere by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding box\r\n */\r\n public scale(factor: number): BoundingSphere {\r\n const newRadius = this.radius * factor;\r\n const tmpVectors = BoundingSphere._TmpVector3;\r\n const tempRadiusVector = tmpVectors[0].setAll(newRadius);\r\n const min = this.center.subtractToRef(tempRadiusVector, tmpVectors[1]);\r\n const max = this.center.addToRef(tempRadiusVector, tmpVectors[2]);\r\n\r\n this.reConstruct(min, max, this._worldMatrix);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the world matrix of the bounding box\r\n * @returns a matrix\r\n */\r\n public getWorldMatrix(): DeepImmutable {\r\n return this._worldMatrix;\r\n }\r\n\r\n // Methods\r\n /**\r\n * @internal\r\n */\r\n public _update(worldMatrix: DeepImmutable): void {\r\n if (!worldMatrix.isIdentity()) {\r\n Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);\r\n const tempVector = BoundingSphere._TmpVector3[0];\r\n Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, worldMatrix, tempVector);\r\n this.radiusWorld = Math.max(Math.abs(tempVector.x), Math.abs(tempVector.y), Math.abs(tempVector.z)) * this.radius;\r\n } else {\r\n this.centerWorld.copyFrom(this.center);\r\n this.radiusWorld = this.radius;\r\n }\r\n }\r\n\r\n /**\r\n * Tests if the bounding sphere is intersecting the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public isInFrustum(frustumPlanes: Array>): boolean {\r\n const center = this.centerWorld;\r\n const radius = this.radiusWorld;\r\n for (let i = 0; i < 6; i++) {\r\n if (frustumPlanes[i].dotCoordinate(center) <= -radius) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if the bounding sphere center is in between the frustum planes.\r\n * Used for optimistic fast inclusion.\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if the sphere center is in between the frustum planes\r\n */\r\n public isCenterInFrustum(frustumPlanes: Array>): boolean {\r\n const center = this.centerWorld;\r\n for (let i = 0; i < 6; i++) {\r\n if (frustumPlanes[i].dotCoordinate(center) < 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if a point is inside the bounding sphere\r\n * @param point defines the point to test\r\n * @returns true if the point is inside the bounding sphere\r\n */\r\n public intersectsPoint(point: DeepImmutable): boolean {\r\n const squareDistance = Vector3.DistanceSquared(this.centerWorld, point);\r\n if (this.radiusWorld * this.radiusWorld < squareDistance) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Checks if two sphere intersect\r\n * @param sphere0 sphere 0\r\n * @param sphere1 sphere 1\r\n * @returns true if the spheres intersect\r\n */\r\n public static Intersects(sphere0: DeepImmutable, sphere1: DeepImmutable): boolean {\r\n const squareDistance = Vector3.DistanceSquared(sphere0.centerWorld, sphere1.centerWorld);\r\n const radiusSum = sphere0.radiusWorld + sphere1.radiusWorld;\r\n\r\n if (radiusSum * radiusSum < squareDistance) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Creates a sphere from a center and a radius\r\n * @param center The center\r\n * @param radius radius\r\n * @param matrix Optional worldMatrix\r\n * @returns The sphere\r\n */\r\n public static CreateFromCenterAndRadius(center: DeepImmutable, radius: number, matrix?: DeepImmutable): BoundingSphere {\r\n this._TmpVector3[0].copyFrom(center);\r\n this._TmpVector3[1].copyFromFloats(0, 0, radius);\r\n this._TmpVector3[2].copyFrom(center);\r\n this._TmpVector3[0].addInPlace(this._TmpVector3[1]);\r\n this._TmpVector3[2].subtractInPlace(this._TmpVector3[1]);\r\n\r\n const sphere = new BoundingSphere(this._TmpVector3[0], this._TmpVector3[2]);\r\n\r\n if (matrix) {\r\n sphere._worldMatrix = matrix;\r\n } else {\r\n sphere._worldMatrix = Matrix.Identity();\r\n }\r\n\r\n return sphere;\r\n }\r\n}\r\n","import type { DeepImmutable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { TmpVectors } from \"../Maths/math.vector\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { BoundingBox } from \"./boundingBox\";\r\nimport { BoundingSphere } from \"./boundingSphere\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\nimport type { Collider } from \"../Collisions/collider\";\r\n\r\nconst _result0 = { min: 0, max: 0 };\r\nconst _result1 = { min: 0, max: 0 };\r\nconst computeBoxExtents = (axis: DeepImmutable, box: DeepImmutable, result: { min: number; max: number }) => {\r\n const p = Vector3.Dot(box.centerWorld, axis);\r\n\r\n const r0 = Math.abs(Vector3.Dot(box.directions[0], axis)) * box.extendSize.x;\r\n const r1 = Math.abs(Vector3.Dot(box.directions[1], axis)) * box.extendSize.y;\r\n const r2 = Math.abs(Vector3.Dot(box.directions[2], axis)) * box.extendSize.z;\r\n\r\n const r = r0 + r1 + r2;\r\n result.min = p - r;\r\n result.max = p + r;\r\n};\r\n\r\nconst axisOverlap = (axis: DeepImmutable, box0: DeepImmutable, box1: DeepImmutable): boolean => {\r\n computeBoxExtents(axis, box0, _result0);\r\n computeBoxExtents(axis, box1, _result1);\r\n return !(_result0.min > _result1.max || _result1.min > _result0.max);\r\n};\r\n\r\n/**\r\n * Interface for cullable objects\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#back-face-culling\r\n */\r\nexport interface ICullable {\r\n /**\r\n * Checks if the object or part of the object is in the frustum\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n isInFrustum(frustumPlanes: Plane[]): boolean;\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n isCompletelyInFrustum(frustumPlanes: Plane[]): boolean;\r\n}\r\n\r\n/**\r\n * Info for a bounding data of a mesh\r\n */\r\nexport class BoundingInfo implements ICullable {\r\n /**\r\n * Bounding box for the mesh\r\n */\r\n public readonly boundingBox: BoundingBox;\r\n /**\r\n * Bounding sphere for the mesh\r\n */\r\n public readonly boundingSphere: BoundingSphere;\r\n\r\n private _isLocked = false;\r\n\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(2, Vector3.Zero);\r\n\r\n /**\r\n * Constructs bounding info\r\n * @param minimum min vector of the bounding box/sphere\r\n * @param maximum max vector of the bounding box/sphere\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(minimum: DeepImmutable, maximum: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n this.boundingBox = new BoundingBox(minimum, maximum, worldMatrix);\r\n this.boundingSphere = new BoundingSphere(minimum, maximum, worldMatrix);\r\n }\r\n\r\n /**\r\n * Recreates the entire bounding info from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable, max: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n this.boundingBox.reConstruct(min, max, worldMatrix);\r\n this.boundingSphere.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n /**\r\n * min vector of the bounding box/sphere\r\n */\r\n public get minimum(): Vector3 {\r\n return this.boundingBox.minimum;\r\n }\r\n\r\n /**\r\n * max vector of the bounding box/sphere\r\n */\r\n public get maximum(): Vector3 {\r\n return this.boundingBox.maximum;\r\n }\r\n\r\n /**\r\n * If the info is locked and won't be updated to avoid perf overhead\r\n */\r\n public get isLocked(): boolean {\r\n return this._isLocked;\r\n }\r\n\r\n public set isLocked(value: boolean) {\r\n this._isLocked = value;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Updates the bounding sphere and box\r\n * @param world world matrix to be used to update\r\n */\r\n public update(world: DeepImmutable) {\r\n if (this._isLocked) {\r\n return;\r\n }\r\n this.boundingBox._update(world);\r\n this.boundingSphere._update(world);\r\n }\r\n\r\n /**\r\n * Recreate the bounding info to be centered around a specific point given a specific extend.\r\n * @param center New center of the bounding info\r\n * @param extend New extend of the bounding info\r\n * @returns the current bounding info\r\n */\r\n public centerOn(center: DeepImmutable, extend: DeepImmutable): BoundingInfo {\r\n const minimum = BoundingInfo._TmpVector3[0].copyFrom(center).subtractInPlace(extend);\r\n const maximum = BoundingInfo._TmpVector3[1].copyFrom(center).addInPlace(extend);\r\n\r\n this.boundingBox.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n this.boundingSphere.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Grows the bounding info to include the given point.\r\n * @param point The point that will be included in the current bounding info (in local space)\r\n * @returns the current bounding info\r\n */\r\n public encapsulate(point: Vector3): BoundingInfo {\r\n const minimum = Vector3.Minimize(this.minimum, point);\r\n const maximum = Vector3.Maximize(this.maximum, point);\r\n this.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Grows the bounding info to encapsulate the given bounding info.\r\n * @param toEncapsulate The bounding info that will be encapsulated in the current bounding info\r\n * @returns the current bounding info\r\n */\r\n public encapsulateBoundingInfo(toEncapsulate: BoundingInfo): BoundingInfo {\r\n const invw = TmpVectors.Matrix[0];\r\n this.boundingBox.getWorldMatrix().invertToRef(invw);\r\n\r\n const v = TmpVectors.Vector3[0];\r\n\r\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.minimumWorld, invw, v);\r\n this.encapsulate(v);\r\n\r\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.maximumWorld, invw, v);\r\n this.encapsulate(v);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Scale the current bounding info by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding info\r\n */\r\n public scale(factor: number): BoundingInfo {\r\n this.boundingBox.scale(factor);\r\n this.boundingSphere.scale(factor);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns `true` if the bounding info is within the frustum defined by the passed array of planes.\r\n * @param frustumPlanes defines the frustum to test\r\n * @param strategy defines the strategy to use for the culling (default is BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD)\r\n * The different strategies available are:\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD most accurate but slower @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_STANDARD\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY faster but less accurate @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\r\n * @returns true if the bounding info is in the frustum planes\r\n */\r\n public isInFrustum(frustumPlanes: Array>, strategy: number = Constants.MESHES_CULLINGSTRATEGY_STANDARD): boolean {\r\n const inclusionTest =\r\n strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n if (inclusionTest) {\r\n if (this.boundingSphere.isCenterInFrustum(frustumPlanes)) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!this.boundingSphere.isInFrustum(frustumPlanes)) {\r\n return false;\r\n }\r\n\r\n const bSphereOnlyTest =\r\n strategy === Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n if (bSphereOnlyTest) {\r\n return true;\r\n }\r\n\r\n return this.boundingBox.isInFrustum(frustumPlanes);\r\n }\r\n\r\n /**\r\n * Gets the world distance between the min and max points of the bounding box\r\n */\r\n public get diagonalLength(): number {\r\n const boundingBox = this.boundingBox;\r\n const diag = boundingBox.maximumWorld.subtractToRef(boundingBox.minimumWorld, BoundingInfo._TmpVector3[0]);\r\n return diag.length();\r\n }\r\n\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Array>): boolean {\r\n return this.boundingBox.isCompletelyInFrustum(frustumPlanes);\r\n }\r\n /**\r\n * @internal\r\n */\r\n public _checkCollision(collider: Collider): boolean {\r\n return collider._canDoCollision(this.boundingSphere.centerWorld, this.boundingSphere.radiusWorld, this.boundingBox.minimumWorld, this.boundingBox.maximumWorld);\r\n }\r\n\r\n /**\r\n * Checks if a point is inside the bounding box and bounding sphere or the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n * @param point the point to check intersection with\r\n * @returns if the point intersects\r\n */\r\n public intersectsPoint(point: DeepImmutable): boolean {\r\n if (!this.boundingSphere.centerWorld) {\r\n return false;\r\n }\r\n\r\n if (!this.boundingSphere.intersectsPoint(point)) {\r\n return false;\r\n }\r\n\r\n if (!this.boundingBox.intersectsPoint(point)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Checks if another bounding info intersects the bounding box and bounding sphere or the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n * @param boundingInfo the bounding info to check intersection with\r\n * @param precise if the intersection should be done using OBB\r\n * @returns if the bounding info intersects\r\n */\r\n public intersects(boundingInfo: DeepImmutable, precise: boolean): boolean {\r\n if (!BoundingSphere.Intersects(this.boundingSphere, boundingInfo.boundingSphere)) {\r\n return false;\r\n }\r\n\r\n if (!BoundingBox.Intersects(this.boundingBox, boundingInfo.boundingBox)) {\r\n return false;\r\n }\r\n\r\n if (!precise) {\r\n return true;\r\n }\r\n\r\n const box0 = this.boundingBox;\r\n const box1 = boundingInfo.boundingBox;\r\n\r\n if (!axisOverlap(box0.directions[0], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box0.directions[1], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box0.directions[2], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[0], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[1], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[2], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n","import type { FloatArray, Nullable, IndicesArray } from \"../types\";\r\nimport type { Vector2 } from \"./math.vector\";\r\nimport { Vector3 } from \"./math.vector\";\r\nimport { nativeOverride } from \"../Misc/decorators\";\r\n\r\n// This helper class is only here so we can apply the nativeOverride decorator to functions.\r\nclass MathHelpers {\r\n @nativeOverride.filter((...[positions, indices]: Parameters) => !Array.isArray(positions) && !Array.isArray(indices))\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static extractMinAndMaxIndexed(positions: FloatArray, indices: IndicesArray, indexStart: number, indexCount: number, minimum: Vector3, maximum: Vector3): void {\r\n for (let index = indexStart; index < indexStart + indexCount; index++) {\r\n const offset = indices[index] * 3;\r\n const x = positions[offset];\r\n const y = positions[offset + 1];\r\n const z = positions[offset + 2];\r\n minimum.minimizeInPlaceFromFloats(x, y, z);\r\n maximum.maximizeInPlaceFromFloats(x, y, z);\r\n }\r\n }\r\n\r\n @nativeOverride.filter((...[positions]: Parameters) => !Array.isArray(positions))\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static extractMinAndMax(positions: FloatArray, start: number, count: number, stride: number, minimum: Vector3, maximum: Vector3): void {\r\n for (let index = start, offset = start * stride; index < start + count; index++, offset += stride) {\r\n const x = positions[offset];\r\n const y = positions[offset + 1];\r\n const z = positions[offset + 2];\r\n minimum.minimizeInPlaceFromFloats(x, y, z);\r\n maximum.maximizeInPlaceFromFloats(x, y, z);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Extracts minimum and maximum values from a list of indexed positions\r\n * @param positions defines the positions to use\r\n * @param indices defines the indices to the positions\r\n * @param indexStart defines the start index\r\n * @param indexCount defines the end index\r\n * @param bias defines bias value to add to the result\r\n * @returns minimum and maximum values\r\n */\r\nexport function extractMinAndMaxIndexed(\r\n positions: FloatArray,\r\n indices: IndicesArray,\r\n indexStart: number,\r\n indexCount: number,\r\n bias: Nullable = null\r\n): { minimum: Vector3; maximum: Vector3 } {\r\n const minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n const maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\r\n\r\n MathHelpers.extractMinAndMaxIndexed(positions, indices, indexStart, indexCount, minimum, maximum);\r\n\r\n if (bias) {\r\n minimum.x -= minimum.x * bias.x + bias.y;\r\n minimum.y -= minimum.y * bias.x + bias.y;\r\n minimum.z -= minimum.z * bias.x + bias.y;\r\n maximum.x += maximum.x * bias.x + bias.y;\r\n maximum.y += maximum.y * bias.x + bias.y;\r\n maximum.z += maximum.z * bias.x + bias.y;\r\n }\r\n\r\n return {\r\n minimum: minimum,\r\n maximum: maximum,\r\n };\r\n}\r\n\r\n/**\r\n * Extracts minimum and maximum values from a list of positions\r\n * @param positions defines the positions to use\r\n * @param start defines the start index in the positions array\r\n * @param count defines the number of positions to handle\r\n * @param bias defines bias value to add to the result\r\n * @param stride defines the stride size to use (distance between two positions in the positions array)\r\n * @returns minimum and maximum values\r\n */\r\nexport function extractMinAndMax(positions: FloatArray, start: number, count: number, bias: Nullable = null, stride?: number): { minimum: Vector3; maximum: Vector3 } {\r\n const minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n const maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\r\n\r\n if (!stride) {\r\n stride = 3;\r\n }\r\n\r\n MathHelpers.extractMinAndMax(positions, start, count, stride, minimum, maximum);\r\n\r\n if (bias) {\r\n minimum.x -= minimum.x * bias.x + bias.y;\r\n minimum.y -= minimum.y * bias.x + bias.y;\r\n minimum.z -= minimum.z * bias.x + bias.y;\r\n maximum.x += maximum.x * bias.x + bias.y;\r\n maximum.y += maximum.y * bias.x + bias.y;\r\n maximum.z += maximum.z * bias.x + bias.y;\r\n }\r\n\r\n return {\r\n minimum: minimum,\r\n maximum: maximum,\r\n };\r\n}\r\n","import type { Nullable, IndicesArray, DeepImmutable, FloatArray } from \"../types\";\r\nimport type { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { IntersectionInfo } from \"../Collisions/intersectionInfo\";\r\nimport type { ICullable } from \"../Culling/boundingInfo\";\r\nimport { BoundingInfo } from \"../Culling/boundingInfo\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { extractMinAndMaxIndexed } from \"../Maths/math.functions\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport type { IMaterialContext } from \"../Engines/IMaterialContext\";\r\n\r\nimport type { Collider } from \"../Collisions/collider\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { MaterialDefines } from \"../Materials/materialDefines\";\r\nimport type { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport type { AbstractMesh } from \"./abstractMesh\";\r\nimport type { Mesh } from \"./mesh\";\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { TrianglePickingPredicate } from \"../Culling/ray\";\r\n\r\n/**\r\n * Defines a subdivision inside a mesh\r\n */\r\nexport class SubMesh implements ICullable {\r\n private _engine: Engine;\r\n /** @internal */\r\n public _drawWrappers: Array; // index in this array = pass id\r\n private _mainDrawWrapperOverride: Nullable = null;\r\n\r\n /**\r\n * Gets material defines used by the effect associated to the sub mesh\r\n */\r\n public get materialDefines(): Nullable {\r\n return this._mainDrawWrapperOverride ? (this._mainDrawWrapperOverride.defines as MaterialDefines) : (this._getDrawWrapper()?.defines as Nullable);\r\n }\r\n\r\n /**\r\n * Sets material defines used by the effect associated to the sub mesh\r\n */\r\n public set materialDefines(defines: Nullable) {\r\n const drawWrapper = this._mainDrawWrapperOverride ?? this._getDrawWrapper(undefined, true)!;\r\n drawWrapper.defines = defines;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getDrawWrapper(passId?: number, createIfNotExisting = false): DrawWrapper | undefined {\r\n passId = passId ?? this._engine.currentRenderPassId;\r\n let drawWrapper = this._drawWrappers[passId];\r\n if (!drawWrapper && createIfNotExisting) {\r\n this._drawWrappers[passId] = drawWrapper = new DrawWrapper(this._mesh.getScene().getEngine());\r\n }\r\n return drawWrapper;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _removeDrawWrapper(passId: number, disposeWrapper = true) {\r\n if (disposeWrapper) {\r\n this._drawWrappers[passId]?.dispose();\r\n }\r\n this._drawWrappers[passId] = undefined as any;\r\n }\r\n\r\n /**\r\n * Gets associated (main) effect (possibly the effect override if defined)\r\n */\r\n public get effect(): Nullable {\r\n return this._mainDrawWrapperOverride ? this._mainDrawWrapperOverride.effect : this._getDrawWrapper()?.effect ?? null;\r\n }\r\n\r\n /** @internal */\r\n public get _drawWrapper(): DrawWrapper {\r\n return this._mainDrawWrapperOverride ?? this._getDrawWrapper(undefined, true)!;\r\n }\r\n\r\n /** @internal */\r\n public get _drawWrapperOverride(): Nullable {\r\n return this._mainDrawWrapperOverride;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setMainDrawWrapperOverride(wrapper: Nullable): void {\r\n this._mainDrawWrapperOverride = wrapper;\r\n }\r\n\r\n /**\r\n * Sets associated effect (effect used to render this submesh)\r\n * @param effect defines the effect to associate with\r\n * @param defines defines the set of defines used to compile this effect\r\n * @param materialContext material context associated to the effect\r\n * @param resetContext true to reset the draw context\r\n */\r\n public setEffect(effect: Nullable, defines: Nullable = null, materialContext?: IMaterialContext, resetContext = true) {\r\n const drawWrapper = this._drawWrapper;\r\n drawWrapper.setEffect(effect, defines, resetContext);\r\n if (materialContext !== undefined) {\r\n drawWrapper.materialContext = materialContext;\r\n }\r\n if (!effect) {\r\n drawWrapper.defines = null;\r\n drawWrapper.materialContext = undefined;\r\n }\r\n }\r\n\r\n /**\r\n * Resets the draw wrappers cache\r\n * @param passId If provided, releases only the draw wrapper corresponding to this render pass id\r\n */\r\n public resetDrawCache(passId?: number): void {\r\n if (this._drawWrappers) {\r\n if (passId !== undefined) {\r\n this._removeDrawWrapper(passId);\r\n return;\r\n } else {\r\n for (const drawWrapper of this._drawWrappers) {\r\n drawWrapper?.dispose();\r\n }\r\n }\r\n }\r\n this._drawWrappers = [];\r\n }\r\n\r\n /** @internal */\r\n public _linesIndexCount: number = 0;\r\n private _mesh: AbstractMesh;\r\n private _renderingMesh: Mesh;\r\n private _boundingInfo: BoundingInfo;\r\n private _linesIndexBuffer: Nullable = null;\r\n /** @internal */\r\n public _lastColliderWorldVertices: Nullable = null;\r\n /** @internal */\r\n public _trianglePlanes: Plane[];\r\n /** @internal */\r\n public _lastColliderTransformMatrix: Nullable = null;\r\n /** @internal */\r\n public _wasDispatched = false;\r\n\r\n /** @internal */\r\n public _renderId = 0;\r\n /** @internal */\r\n public _alphaIndex: number = 0;\r\n /** @internal */\r\n public _distanceToCamera: number = 0;\r\n /** @internal */\r\n public _id: number;\r\n\r\n private _currentMaterial: Nullable = null;\r\n\r\n /**\r\n * Add a new submesh to a mesh\r\n * @param materialIndex defines the material index to use\r\n * @param verticesStart defines vertex index start\r\n * @param verticesCount defines vertices count\r\n * @param indexStart defines index start\r\n * @param indexCount defines indices count\r\n * @param mesh defines the parent mesh\r\n * @param renderingMesh defines an optional rendering mesh\r\n * @param createBoundingBox defines if bounding box should be created for this submesh\r\n * @returns the new submesh\r\n */\r\n public static AddToMesh(\r\n materialIndex: number,\r\n verticesStart: number,\r\n verticesCount: number,\r\n indexStart: number,\r\n indexCount: number,\r\n mesh: AbstractMesh,\r\n renderingMesh?: Mesh,\r\n createBoundingBox: boolean = true\r\n ): SubMesh {\r\n return new SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox);\r\n }\r\n\r\n /**\r\n * Creates a new submesh\r\n * @param materialIndex defines the material index to use\r\n * @param verticesStart defines vertex index start\r\n * @param verticesCount defines vertices count\r\n * @param indexStart defines index start\r\n * @param indexCount defines indices count\r\n * @param mesh defines the parent mesh\r\n * @param renderingMesh defines an optional rendering mesh\r\n * @param createBoundingBox defines if bounding box should be created for this submesh\r\n * @param addToMesh defines a boolean indicating that the submesh must be added to the mesh.subMeshes array (true by default)\r\n */\r\n constructor(\r\n /** the material index to use */\r\n public materialIndex: number,\r\n /** vertex index start */\r\n public verticesStart: number,\r\n /** vertices count */\r\n public verticesCount: number,\r\n /** index start */\r\n public indexStart: number,\r\n /** indices count */\r\n public indexCount: number,\r\n mesh: AbstractMesh,\r\n renderingMesh?: Mesh,\r\n createBoundingBox: boolean = true,\r\n addToMesh = true\r\n ) {\r\n this._mesh = mesh;\r\n this._renderingMesh = renderingMesh || mesh;\r\n if (addToMesh) {\r\n mesh.subMeshes.push(this);\r\n }\r\n\r\n this._engine = this._mesh.getScene().getEngine();\r\n this.resetDrawCache();\r\n this._trianglePlanes = [];\r\n\r\n this._id = mesh.subMeshes.length - 1;\r\n\r\n if (createBoundingBox) {\r\n this.refreshBoundingInfo();\r\n mesh.computeWorldMatrix(true);\r\n }\r\n }\r\n\r\n /**\r\n * Returns true if this submesh covers the entire parent mesh\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public get IsGlobal(): boolean {\r\n return this.verticesStart === 0 && this.verticesCount === this._mesh.getTotalVertices() && this.indexStart === 0 && this.indexCount === this._mesh.getTotalIndices();\r\n }\r\n\r\n /**\r\n * Returns the submesh BoundingInfo object\r\n * @returns current bounding info (or mesh's one if the submesh is global)\r\n */\r\n public getBoundingInfo(): BoundingInfo {\r\n if (this.IsGlobal) {\r\n return this._mesh.getBoundingInfo();\r\n }\r\n\r\n return this._boundingInfo;\r\n }\r\n\r\n /**\r\n * Sets the submesh BoundingInfo\r\n * @param boundingInfo defines the new bounding info to use\r\n * @returns the SubMesh\r\n */\r\n public setBoundingInfo(boundingInfo: BoundingInfo): SubMesh {\r\n this._boundingInfo = boundingInfo;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the mesh of the current submesh\r\n * @returns the parent mesh\r\n */\r\n public getMesh(): AbstractMesh {\r\n return this._mesh;\r\n }\r\n\r\n /**\r\n * Returns the rendering mesh of the submesh\r\n * @returns the rendering mesh (could be different from parent mesh)\r\n */\r\n public getRenderingMesh(): Mesh {\r\n return this._renderingMesh;\r\n }\r\n\r\n /**\r\n * Returns the replacement mesh of the submesh\r\n * @returns the replacement mesh (could be different from parent mesh)\r\n */\r\n public getReplacementMesh(): Nullable {\r\n return this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : null;\r\n }\r\n\r\n /**\r\n * Returns the effective mesh of the submesh\r\n * @returns the effective mesh (could be different from parent mesh)\r\n */\r\n public getEffectiveMesh(): AbstractMesh {\r\n const replacementMesh = this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : null;\r\n\r\n return replacementMesh ? replacementMesh : this._renderingMesh;\r\n }\r\n\r\n /**\r\n * Returns the submesh material\r\n * @param getDefaultMaterial Defines whether or not to get the default material if nothing has been defined.\r\n * @returns null or the current material\r\n */\r\n public getMaterial(getDefaultMaterial = true): Nullable {\r\n const rootMaterial = this._renderingMesh.getMaterialForRenderPass(this._engine.currentRenderPassId) ?? this._renderingMesh.material;\r\n\r\n if (!rootMaterial) {\r\n return getDefaultMaterial ? this._mesh.getScene().defaultMaterial : null;\r\n } else if (this._isMultiMaterial(rootMaterial)) {\r\n const effectiveMaterial = rootMaterial.getSubMaterial(this.materialIndex);\r\n\r\n if (this._currentMaterial !== effectiveMaterial) {\r\n this._currentMaterial = effectiveMaterial;\r\n this.resetDrawCache();\r\n }\r\n\r\n return effectiveMaterial;\r\n }\r\n\r\n return rootMaterial;\r\n }\r\n\r\n private _isMultiMaterial(material: Material): material is MultiMaterial {\r\n return (material as MultiMaterial).getSubMaterial !== undefined;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Sets a new updated BoundingInfo object to the submesh\r\n * @param data defines an optional position array to use to determine the bounding info\r\n * @returns the SubMesh\r\n */\r\n public refreshBoundingInfo(data: Nullable = null): SubMesh {\r\n this._lastColliderWorldVertices = null;\r\n\r\n if (this.IsGlobal || !this._renderingMesh || !this._renderingMesh.geometry) {\r\n return this;\r\n }\r\n\r\n if (!data) {\r\n data = this._renderingMesh.getVerticesData(VertexBuffer.PositionKind);\r\n }\r\n\r\n if (!data) {\r\n this._boundingInfo = this._mesh.getBoundingInfo();\r\n return this;\r\n }\r\n\r\n const indices = this._renderingMesh.getIndices();\r\n let extend: { minimum: Vector3; maximum: Vector3 };\r\n\r\n //is this the only submesh?\r\n if (this.indexStart === 0 && this.indexCount === indices.length) {\r\n const boundingInfo = this._renderingMesh.getBoundingInfo();\r\n\r\n //the rendering mesh's bounding info can be used, it is the standard submesh for all indices.\r\n extend = { minimum: boundingInfo.minimum.clone(), maximum: boundingInfo.maximum.clone() };\r\n } else {\r\n extend = extractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount, this._renderingMesh.geometry.boundingBias);\r\n }\r\n\r\n if (this._boundingInfo) {\r\n this._boundingInfo.reConstruct(extend.minimum, extend.maximum);\r\n } else {\r\n this._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _checkCollision(collider: Collider): boolean {\r\n const boundingInfo = this.getBoundingInfo();\r\n\r\n return boundingInfo._checkCollision(collider);\r\n }\r\n\r\n /**\r\n * Updates the submesh BoundingInfo\r\n * @param world defines the world matrix to use to update the bounding info\r\n * @returns the submesh\r\n */\r\n public updateBoundingInfo(world: DeepImmutable): SubMesh {\r\n let boundingInfo = this.getBoundingInfo();\r\n\r\n if (!boundingInfo) {\r\n this.refreshBoundingInfo();\r\n boundingInfo = this.getBoundingInfo();\r\n }\r\n if (boundingInfo) {\r\n (boundingInfo).update(world);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * True is the submesh bounding box intersects the frustum defined by the passed array of planes.\r\n * @param frustumPlanes defines the frustum planes\r\n * @returns true if the submesh is intersecting with the frustum\r\n */\r\n public isInFrustum(frustumPlanes: Plane[]): boolean {\r\n const boundingInfo = this.getBoundingInfo();\r\n\r\n if (!boundingInfo) {\r\n return false;\r\n }\r\n return boundingInfo.isInFrustum(frustumPlanes, this._mesh.cullingStrategy);\r\n }\r\n\r\n /**\r\n * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes\r\n * @param frustumPlanes defines the frustum planes\r\n * @returns true if the submesh is inside the frustum\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {\r\n const boundingInfo = this.getBoundingInfo();\r\n\r\n if (!boundingInfo) {\r\n return false;\r\n }\r\n return boundingInfo.isCompletelyInFrustum(frustumPlanes);\r\n }\r\n\r\n /**\r\n * Renders the submesh\r\n * @param enableAlphaMode defines if alpha needs to be used\r\n * @returns the submesh\r\n */\r\n public render(enableAlphaMode: boolean): SubMesh {\r\n this._renderingMesh.render(this, enableAlphaMode, this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : undefined);\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getLinesIndexBuffer(indices: IndicesArray, engine: Engine): DataBuffer {\r\n if (!this._linesIndexBuffer) {\r\n const linesIndices = [];\r\n\r\n for (let index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {\r\n linesIndices.push(indices[index], indices[index + 1], indices[index + 1], indices[index + 2], indices[index + 2], indices[index]);\r\n }\r\n\r\n this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);\r\n this._linesIndexCount = linesIndices.length;\r\n }\r\n return this._linesIndexBuffer;\r\n }\r\n\r\n /**\r\n * Checks if the submesh intersects with a ray\r\n * @param ray defines the ray to test\r\n * @returns true is the passed ray intersects the submesh bounding box\r\n */\r\n public canIntersects(ray: Ray): boolean {\r\n const boundingInfo = this.getBoundingInfo();\r\n\r\n if (!boundingInfo) {\r\n return false;\r\n }\r\n return ray.intersectsBox(boundingInfo.boundingBox);\r\n }\r\n\r\n /**\r\n * Intersects current submesh with a ray\r\n * @param ray defines the ray to test\r\n * @param positions defines mesh's positions array\r\n * @param indices defines mesh's indices array\r\n * @param fastCheck defines if the first intersection will be used (and not the closest)\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @returns intersection info or null if no intersection\r\n */\r\n public intersects(ray: Ray, positions: Vector3[], indices: IndicesArray, fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable {\r\n const material = this.getMaterial();\r\n if (!material) {\r\n return null;\r\n }\r\n let step = 3;\r\n let checkStopper = false;\r\n\r\n switch (material.fillMode) {\r\n case Constants.MATERIAL_PointListDrawMode:\r\n case Constants.MATERIAL_LineLoopDrawMode:\r\n case Constants.MATERIAL_LineStripDrawMode:\r\n case Constants.MATERIAL_TriangleFanDrawMode:\r\n return null;\r\n case Constants.MATERIAL_TriangleStripDrawMode:\r\n step = 1;\r\n checkStopper = true;\r\n break;\r\n default:\r\n break;\r\n }\r\n\r\n // LineMesh first as it's also a Mesh...\r\n if (material.fillMode === Constants.MATERIAL_LineListDrawMode) {\r\n // Check if mesh is unindexed\r\n if (!indices.length) {\r\n return this._intersectUnIndexedLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);\r\n }\r\n return this._intersectLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);\r\n } else {\r\n // Check if mesh is unindexed\r\n if (!indices.length && this._mesh._unIndexed) {\r\n return this._intersectUnIndexedTriangles(ray, positions, indices, fastCheck, trianglePredicate);\r\n }\r\n\r\n return this._intersectTriangles(ray, positions, indices, step, checkStopper, fastCheck, trianglePredicate);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n private _intersectLines(ray: Ray, positions: Vector3[], indices: IndicesArray, intersectionThreshold: number, fastCheck?: boolean): Nullable {\r\n let intersectInfo: Nullable = null;\r\n\r\n // Line test\r\n for (let index = this.indexStart; index < this.indexStart + this.indexCount; index += 2) {\r\n const p0 = positions[indices[index]];\r\n const p1 = positions[indices[index + 1]];\r\n\r\n const length = ray.intersectionSegment(p0, p1, intersectionThreshold);\r\n if (length < 0) {\r\n continue;\r\n }\r\n\r\n if (fastCheck || !intersectInfo || length < intersectInfo.distance) {\r\n intersectInfo = new IntersectionInfo(null, null, length);\r\n intersectInfo.faceId = index / 2;\r\n if (fastCheck) {\r\n break;\r\n }\r\n }\r\n }\r\n return intersectInfo;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n private _intersectUnIndexedLines(ray: Ray, positions: Vector3[], indices: IndicesArray, intersectionThreshold: number, fastCheck?: boolean): Nullable {\r\n let intersectInfo: Nullable = null;\r\n\r\n // Line test\r\n for (let index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 2) {\r\n const p0 = positions[index];\r\n const p1 = positions[index + 1];\r\n\r\n const length = ray.intersectionSegment(p0, p1, intersectionThreshold);\r\n if (length < 0) {\r\n continue;\r\n }\r\n\r\n if (fastCheck || !intersectInfo || length < intersectInfo.distance) {\r\n intersectInfo = new IntersectionInfo(null, null, length);\r\n intersectInfo.faceId = index / 2;\r\n if (fastCheck) {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return intersectInfo;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n private _intersectTriangles(\r\n ray: Ray,\r\n positions: Vector3[],\r\n indices: IndicesArray,\r\n step: number,\r\n checkStopper: boolean,\r\n fastCheck?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n ): Nullable {\r\n let intersectInfo: Nullable = null;\r\n\r\n // Triangles test\r\n let faceId = -1;\r\n for (let index = this.indexStart; index < this.indexStart + this.indexCount - (3 - step); index += step) {\r\n faceId++;\r\n const indexA = indices[index];\r\n const indexB = indices[index + 1];\r\n const indexC = indices[index + 2];\r\n\r\n if (checkStopper && indexC === 0xffffffff) {\r\n index += 2;\r\n continue;\r\n }\r\n\r\n const p0 = positions[indexA];\r\n const p1 = positions[indexB];\r\n const p2 = positions[indexC];\r\n\r\n // stay defensive and don't check against undefined positions.\r\n if (!p0 || !p1 || !p2) {\r\n continue;\r\n }\r\n\r\n if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray, indexA, indexB, indexC)) {\r\n continue;\r\n }\r\n\r\n const currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);\r\n\r\n if (currentIntersectInfo) {\r\n if (currentIntersectInfo.distance < 0) {\r\n continue;\r\n }\r\n\r\n if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {\r\n intersectInfo = currentIntersectInfo;\r\n intersectInfo.faceId = faceId;\r\n\r\n if (fastCheck) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return intersectInfo;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n private _intersectUnIndexedTriangles(\r\n ray: Ray,\r\n positions: Vector3[],\r\n indices: IndicesArray,\r\n fastCheck?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n ): Nullable {\r\n let intersectInfo: Nullable = null;\r\n // Triangles test\r\n for (let index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 3) {\r\n const p0 = positions[index];\r\n const p1 = positions[index + 1];\r\n const p2 = positions[index + 2];\r\n\r\n if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray, -1, -1, -1)) {\r\n continue;\r\n }\r\n\r\n const currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);\r\n\r\n if (currentIntersectInfo) {\r\n if (currentIntersectInfo.distance < 0) {\r\n continue;\r\n }\r\n\r\n if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {\r\n intersectInfo = currentIntersectInfo;\r\n intersectInfo.faceId = index / 3;\r\n\r\n if (fastCheck) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return intersectInfo;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (this._linesIndexBuffer) {\r\n this._linesIndexBuffer = null;\r\n }\r\n }\r\n\r\n // Clone\r\n /**\r\n * Creates a new submesh from the passed mesh\r\n * @param newMesh defines the new hosting mesh\r\n * @param newRenderingMesh defines an optional rendering mesh\r\n * @returns the new submesh\r\n */\r\n public clone(newMesh: AbstractMesh, newRenderingMesh?: Mesh): SubMesh {\r\n const result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);\r\n\r\n if (!this.IsGlobal) {\r\n const boundingInfo = this.getBoundingInfo();\r\n\r\n if (!boundingInfo) {\r\n return result;\r\n }\r\n\r\n result._boundingInfo = new BoundingInfo(boundingInfo.minimum, boundingInfo.maximum);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n // Dispose\r\n\r\n /**\r\n * Release associated resources\r\n */\r\n public dispose(): void {\r\n if (this._linesIndexBuffer) {\r\n this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer);\r\n this._linesIndexBuffer = null;\r\n }\r\n\r\n // Remove from mesh\r\n const index = this._mesh.subMeshes.indexOf(this);\r\n this._mesh.subMeshes.splice(index, 1);\r\n\r\n this.resetDrawCache();\r\n }\r\n\r\n /**\r\n * Gets the class name\r\n * @returns the string \"SubMesh\".\r\n */\r\n public getClassName(): string {\r\n return \"SubMesh\";\r\n }\r\n\r\n // Statics\r\n /**\r\n * Creates a new submesh from indices data\r\n * @param materialIndex the index of the main mesh material\r\n * @param startIndex the index where to start the copy in the mesh indices array\r\n * @param indexCount the number of indices to copy then from the startIndex\r\n * @param mesh the main mesh to create the submesh from\r\n * @param renderingMesh the optional rendering mesh\r\n * @param createBoundingBox defines if bounding box should be created for this submesh\r\n * @returns a new submesh\r\n */\r\n public static CreateFromIndices(\r\n materialIndex: number,\r\n startIndex: number,\r\n indexCount: number,\r\n mesh: AbstractMesh,\r\n renderingMesh?: Mesh,\r\n createBoundingBox: boolean = true\r\n ): SubMesh {\r\n let minVertexIndex = Number.MAX_VALUE;\r\n let maxVertexIndex = -Number.MAX_VALUE;\r\n\r\n const whatWillRender = renderingMesh || mesh;\r\n const indices = whatWillRender!.getIndices()!;\r\n\r\n for (let index = startIndex; index < startIndex + indexCount; index++) {\r\n const vertexIndex = indices[index];\r\n\r\n if (vertexIndex < minVertexIndex) {\r\n minVertexIndex = vertexIndex;\r\n }\r\n if (vertexIndex > maxVertexIndex) {\r\n maxVertexIndex = vertexIndex;\r\n }\r\n }\r\n\r\n return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh, createBoundingBox);\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Nullable, FloatArray, IndicesArray, DeepImmutable } from \"../types\";\r\nimport type { Matrix, Vector2 } from \"../Maths/math.vector\";\r\nimport { Vector3, Vector4, TmpVectors } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { Color3 } from \"../Maths/math.color\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { nativeOverride } from \"../Misc/decorators\";\r\nimport type { Coroutine } from \"../Misc/coroutine\";\r\nimport { makeSyncFunction, runCoroutineSync } from \"../Misc/coroutine\";\r\nimport type { ICreateCapsuleOptions } from \"./Builders/capsuleBuilder\";\r\nimport { RuntimeError, ErrorCodes } from \"../Misc/error\";\r\n\r\nimport type { Geometry } from \"../Meshes/geometry\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { SubMesh } from \"./subMesh\";\r\n\r\n/**\r\n * Define an interface for all classes that will get and set the data on vertices\r\n */\r\nexport interface IGetSetVerticesData {\r\n /**\r\n * Gets a boolean indicating if specific vertex data is present\r\n * @param kind defines the vertex data kind to use\r\n * @returns true is data kind is present\r\n */\r\n isVerticesDataPresent(kind: string): boolean;\r\n /**\r\n * Gets a specific vertex data attached to this geometry. Float data is constructed if the vertex buffer data cannot be returned directly.\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n getVerticesData(kind: string, copyWhenShared?: boolean, forceCopy?: boolean): Nullable;\r\n /**\r\n * Returns an array of integers or a typed array (Int32Array, Uint32Array, Uint16Array) populated with the mesh indices.\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 * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns the indices array or an empty array if the mesh has no geometry\r\n */\r\n getIndices(copyWhenShared?: boolean, forceCopy?: boolean): Nullable;\r\n /**\r\n * Set specific vertex data\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @param data defines the vertex data to use\r\n * @param updatable defines if the vertex must be flagged as updatable (false as default)\r\n * @param stride defines the stride to use (0 by default). This value is deduced from the kind value if not specified\r\n */\r\n setVerticesData(kind: string, data: FloatArray, updatable: boolean): void;\r\n /**\r\n * Update a specific associated vertex buffer\r\n * @param kind defines which buffer to write to (positions, indices, normals, etc). 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 * @param data defines the data source\r\n * @param updateExtends defines if extends info of the mesh must be updated (can be null). This is mostly useful for \"position\" kind\r\n * @param makeItUnique defines if the geometry associated with the mesh must be cloned to make the change only for this mesh (and not all meshes associated with the same geometry)\r\n */\r\n updateVerticesData(kind: string, data: FloatArray, updateExtends?: boolean, makeItUnique?: boolean): void;\r\n /**\r\n * Creates a new index buffer\r\n * @param indices defines the indices to store in the index buffer\r\n * @param totalVertices defines the total number of vertices (could be null)\r\n * @param updatable defines if the index buffer must be flagged as updatable (false by default)\r\n */\r\n setIndices(indices: IndicesArray, totalVertices: Nullable, updatable?: boolean): void;\r\n}\r\n\r\n/** Class used to attach material info to sub section of a vertex data class */\r\nexport class VertexDataMaterialInfo {\r\n /** Defines the material index to use */\r\n public materialIndex: number;\r\n /** Defines vertex index start*/\r\n public verticesStart: number;\r\n /** Defines vertices count */\r\n public verticesCount: number;\r\n /** Defines index start */\r\n public indexStart: number;\r\n /** Defines indices count */\r\n public indexCount: number;\r\n}\r\n\r\n/**\r\n * This class contains the various kinds of data on every vertex of a mesh used in determining its shape and appearance\r\n */\r\nexport class VertexData {\r\n /**\r\n * Mesh side orientation : usually the external or front surface\r\n */\r\n public static readonly FRONTSIDE = 0;\r\n /**\r\n * Mesh side orientation : usually the internal or back surface\r\n */\r\n public static readonly BACKSIDE = 1;\r\n /**\r\n * Mesh side orientation : both internal and external or front and back surfaces\r\n */\r\n public static readonly DOUBLESIDE = 2;\r\n /**\r\n * Mesh side orientation : by default, `FRONTSIDE`\r\n */\r\n public static readonly DEFAULTSIDE = 0;\r\n\r\n /**\r\n * An array of the x, y, z position of each vertex [...., x, y, z, .....]\r\n */\r\n public positions: Nullable;\r\n\r\n /**\r\n * An array of the x, y, z normal vector of each vertex [...., x, y, z, .....]\r\n */\r\n public normals: Nullable;\r\n\r\n /**\r\n * An array of the x, y, z tangent vector of each vertex [...., x, y, z, .....]\r\n */\r\n public tangents: Nullable;\r\n\r\n /**\r\n * An array of u,v which maps a texture image onto each vertex [...., u, v, .....]\r\n */\r\n public uvs: Nullable;\r\n\r\n /**\r\n * A second array of u,v which maps a texture image onto each vertex [...., u, v, .....]\r\n */\r\n public uvs2: Nullable;\r\n\r\n /**\r\n * A third array of u,v which maps a texture image onto each vertex [...., u, v, .....]\r\n */\r\n public uvs3: Nullable;\r\n\r\n /**\r\n * A fourth array of u,v which maps a texture image onto each vertex [...., u, v, .....]\r\n */\r\n public uvs4: Nullable;\r\n\r\n /**\r\n * A fifth array of u,v which maps a texture image onto each vertex [...., u, v, .....]\r\n */\r\n public uvs5: Nullable;\r\n\r\n /**\r\n * A sixth array of u,v which maps a texture image onto each vertex [...., u, v, .....]\r\n */\r\n public uvs6: Nullable;\r\n\r\n /**\r\n * An array of the r, g, b, a, color of each vertex [...., r, g, b, a, .....]\r\n */\r\n public colors: Nullable;\r\n\r\n /**\r\n * An array containing the list of indices to the array of matrices produced by bones, each vertex have up to 4 indices (8 if the matricesIndicesExtra is set).\r\n */\r\n public matricesIndices: Nullable;\r\n\r\n /**\r\n * An array containing the list of weights defining the weight of each indexed matrix in the final computation\r\n */\r\n public matricesWeights: Nullable;\r\n\r\n /**\r\n * An array extending the number of possible indices\r\n */\r\n public matricesIndicesExtra: Nullable;\r\n\r\n /**\r\n * An array extending the number of possible weights when the number of indices is extended\r\n */\r\n public matricesWeightsExtra: Nullable;\r\n\r\n /**\r\n * An array of i, j, k the three vertex indices required for each triangular facet [...., i, j, k .....]\r\n */\r\n public indices: Nullable;\r\n\r\n /**\r\n * An array defining material association for sub sections of the vertex data\r\n */\r\n public materialInfos: Nullable>;\r\n\r\n /**\r\n * Uses the passed data array to set the set the values for the specified kind of data\r\n * @param data a linear array of floating numbers\r\n * @param kind the type of data that is being set, eg positions, colors etc\r\n */\r\n public set(data: FloatArray, kind: string) {\r\n if (!data.length) {\r\n Logger.Warn(`Setting vertex data kind '${kind}' with an empty array`);\r\n }\r\n\r\n switch (kind) {\r\n case VertexBuffer.PositionKind:\r\n this.positions = data;\r\n break;\r\n case VertexBuffer.NormalKind:\r\n this.normals = data;\r\n break;\r\n case VertexBuffer.TangentKind:\r\n this.tangents = data;\r\n break;\r\n case VertexBuffer.UVKind:\r\n this.uvs = data;\r\n break;\r\n case VertexBuffer.UV2Kind:\r\n this.uvs2 = data;\r\n break;\r\n case VertexBuffer.UV3Kind:\r\n this.uvs3 = data;\r\n break;\r\n case VertexBuffer.UV4Kind:\r\n this.uvs4 = data;\r\n break;\r\n case VertexBuffer.UV5Kind:\r\n this.uvs5 = data;\r\n break;\r\n case VertexBuffer.UV6Kind:\r\n this.uvs6 = data;\r\n break;\r\n case VertexBuffer.ColorKind:\r\n this.colors = data;\r\n break;\r\n case VertexBuffer.MatricesIndicesKind:\r\n this.matricesIndices = data;\r\n break;\r\n case VertexBuffer.MatricesWeightsKind:\r\n this.matricesWeights = data;\r\n break;\r\n case VertexBuffer.MatricesIndicesExtraKind:\r\n this.matricesIndicesExtra = data;\r\n break;\r\n case VertexBuffer.MatricesWeightsExtraKind:\r\n this.matricesWeightsExtra = data;\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Associates the vertexData to the passed Mesh.\r\n * Sets it as updatable or not (default `false`)\r\n * @param mesh the mesh the vertexData is applied to\r\n * @param updatable when used and having the value true allows new data to update the vertexData\r\n * @returns the VertexData\r\n */\r\n public applyToMesh(mesh: Mesh, updatable?: boolean): VertexData {\r\n this._applyTo(mesh, updatable, false);\r\n return this;\r\n }\r\n\r\n /**\r\n * Associates the vertexData to the passed Geometry.\r\n * Sets it as updatable or not (default `false`)\r\n * @param geometry the geometry the vertexData is applied to\r\n * @param updatable when used and having the value true allows new data to update the vertexData\r\n * @returns VertexData\r\n */\r\n public applyToGeometry(geometry: Geometry, updatable?: boolean): VertexData {\r\n this._applyTo(geometry, updatable, false);\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the associated mesh\r\n * @param mesh the mesh to be updated\r\n * @returns VertexData\r\n */\r\n public updateMesh(mesh: Mesh): VertexData {\r\n this._update(mesh);\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the associated geometry\r\n * @param geometry the geometry to be updated\r\n * @returns VertexData.\r\n */\r\n public updateGeometry(geometry: Geometry): VertexData {\r\n this._update(geometry);\r\n return this;\r\n }\r\n\r\n private readonly _applyTo = makeSyncFunction(this._applyToCoroutine.bind(this));\r\n\r\n /**\r\n * @internal\r\n */\r\n public *_applyToCoroutine(meshOrGeometry: IGetSetVerticesData, updatable: boolean = false, isAsync: boolean): Coroutine {\r\n if (this.positions) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.PositionKind, this.positions, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.normals) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.NormalKind, this.normals, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.tangents) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.TangentKind, this.tangents, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.uvs) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.UVKind, this.uvs, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.uvs2) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.UV2Kind, this.uvs2, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.uvs3) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.UV3Kind, this.uvs3, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.uvs4) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.UV4Kind, this.uvs4, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.uvs5) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.UV5Kind, this.uvs5, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.uvs6) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.UV6Kind, this.uvs6, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.colors) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.ColorKind, this.colors, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.matricesIndices) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesIndicesKind, this.matricesIndices, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.matricesWeights) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.matricesIndicesExtra) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.matricesWeightsExtra) {\r\n meshOrGeometry.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n if (this.indices) {\r\n meshOrGeometry.setIndices(this.indices, null, updatable);\r\n if (isAsync) {\r\n yield;\r\n }\r\n } else {\r\n meshOrGeometry.setIndices([], null);\r\n }\r\n\r\n if ((meshOrGeometry as Mesh).subMeshes && this.materialInfos && this.materialInfos.length > 1) {\r\n const mesh = meshOrGeometry as Mesh;\r\n mesh.subMeshes = [];\r\n for (const matInfo of this.materialInfos) {\r\n new SubMesh(matInfo.materialIndex, matInfo.verticesStart, matInfo.verticesCount, matInfo.indexStart, matInfo.indexCount, mesh);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n private _update(meshOrGeometry: IGetSetVerticesData, updateExtends?: boolean, makeItUnique?: boolean): VertexData {\r\n if (this.positions) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.PositionKind, this.positions, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.normals) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.tangents) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.TangentKind, this.tangents, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.uvs) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.uvs2) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.UV2Kind, this.uvs2, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.uvs3) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.UV3Kind, this.uvs3, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.uvs4) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.UV4Kind, this.uvs4, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.uvs5) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.UV5Kind, this.uvs5, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.uvs6) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.UV6Kind, this.uvs6, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.colors) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.ColorKind, this.colors, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.matricesIndices) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesIndicesKind, this.matricesIndices, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.matricesWeights) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.matricesIndicesExtra) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.matricesWeightsExtra) {\r\n meshOrGeometry.updateVerticesData(VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updateExtends, makeItUnique);\r\n }\r\n\r\n if (this.indices) {\r\n meshOrGeometry.setIndices(this.indices, null);\r\n }\r\n return this;\r\n }\r\n\r\n @nativeOverride.filter((...[coordinates]: Parameters) => !Array.isArray(coordinates))\r\n private static _TransformVector3Coordinates(coordinates: FloatArray, transformation: DeepImmutable, offset = 0, length = coordinates.length) {\r\n const coordinate = TmpVectors.Vector3[0];\r\n const transformedCoordinate = TmpVectors.Vector3[1];\r\n for (let index = offset; index < offset + length; index += 3) {\r\n Vector3.FromArrayToRef(coordinates, index, coordinate);\r\n Vector3.TransformCoordinatesToRef(coordinate, transformation, transformedCoordinate);\r\n coordinates[index] = transformedCoordinate.x;\r\n coordinates[index + 1] = transformedCoordinate.y;\r\n coordinates[index + 2] = transformedCoordinate.z;\r\n }\r\n }\r\n\r\n @nativeOverride.filter((...[normals]: Parameters) => !Array.isArray(normals))\r\n private static _TransformVector3Normals(normals: FloatArray, transformation: DeepImmutable, offset = 0, length = normals.length) {\r\n const normal = TmpVectors.Vector3[0];\r\n const transformedNormal = TmpVectors.Vector3[1];\r\n for (let index = offset; index < offset + length; index += 3) {\r\n Vector3.FromArrayToRef(normals, index, normal);\r\n Vector3.TransformNormalToRef(normal, transformation, transformedNormal);\r\n normals[index] = transformedNormal.x;\r\n normals[index + 1] = transformedNormal.y;\r\n normals[index + 2] = transformedNormal.z;\r\n }\r\n }\r\n\r\n @nativeOverride.filter((...[normals]: Parameters) => !Array.isArray(normals))\r\n private static _TransformVector4Normals(normals: FloatArray, transformation: DeepImmutable, offset = 0, length = normals.length) {\r\n const normal = TmpVectors.Vector4[0];\r\n const transformedNormal = TmpVectors.Vector4[1];\r\n for (let index = offset; index < offset + length; index += 4) {\r\n Vector4.FromArrayToRef(normals, index, normal);\r\n Vector4.TransformNormalToRef(normal, transformation, transformedNormal);\r\n normals[index] = transformedNormal.x;\r\n normals[index + 1] = transformedNormal.y;\r\n normals[index + 2] = transformedNormal.z;\r\n normals[index + 3] = transformedNormal.w;\r\n }\r\n }\r\n\r\n @nativeOverride.filter((...[indices]: Parameters) => !Array.isArray(indices))\r\n private static _FlipFaces(indices: IndicesArray, offset = 0, length = indices.length) {\r\n for (let index = offset; index < offset + length; index += 3) {\r\n const tmp = indices[index + 1];\r\n indices[index + 1] = indices[index + 2];\r\n indices[index + 2] = tmp;\r\n }\r\n }\r\n\r\n /**\r\n * Transforms each position and each normal of the vertexData according to the passed Matrix\r\n * @param matrix the transforming matrix\r\n * @returns the VertexData\r\n */\r\n public transform(matrix: Matrix): VertexData {\r\n const flip = matrix.determinant() < 0;\r\n if (this.positions) {\r\n VertexData._TransformVector3Coordinates(this.positions, matrix);\r\n }\r\n\r\n if (this.normals) {\r\n VertexData._TransformVector3Normals(this.normals, matrix);\r\n }\r\n\r\n if (this.tangents) {\r\n VertexData._TransformVector4Normals(this.tangents, matrix);\r\n }\r\n\r\n if (flip && this.indices) {\r\n VertexData._FlipFaces(this.indices);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Generates an array of vertex data where each vertex data only has one material info\r\n * @returns An array of VertexData\r\n */\r\n public splitBasedOnMaterialID() {\r\n if (!this.materialInfos || this.materialInfos.length < 2) {\r\n return [this];\r\n }\r\n\r\n const result = new Array();\r\n for (const materialInfo of this.materialInfos) {\r\n const vertexData = new VertexData();\r\n\r\n if (this.positions) {\r\n vertexData.positions = this.positions.slice(materialInfo.verticesStart * 3, (materialInfo.verticesCount + materialInfo.verticesStart) * 3);\r\n }\r\n\r\n if (this.normals) {\r\n vertexData.normals = this.normals.slice(materialInfo.verticesStart * 3, (materialInfo.verticesCount + materialInfo.verticesStart) * 3);\r\n }\r\n\r\n if (this.tangents) {\r\n vertexData.tangents = this.tangents.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\r\n }\r\n\r\n if (this.colors) {\r\n vertexData.colors = this.colors.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\r\n }\r\n\r\n if (this.uvs) {\r\n vertexData.uvs = this.uvs.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\r\n }\r\n\r\n if (this.uvs2) {\r\n vertexData.uvs2 = this.uvs2.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\r\n }\r\n\r\n if (this.uvs3) {\r\n vertexData.uvs3 = this.uvs3.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\r\n }\r\n\r\n if (this.uvs4) {\r\n vertexData.uvs4 = this.uvs4.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\r\n }\r\n\r\n if (this.uvs5) {\r\n vertexData.uvs5 = this.uvs5.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\r\n }\r\n\r\n if (this.uvs6) {\r\n vertexData.uvs6 = this.uvs6.slice(materialInfo.verticesStart * 2, (materialInfo.verticesCount + materialInfo.verticesStart) * 2);\r\n }\r\n\r\n if (this.matricesIndices) {\r\n vertexData.matricesIndices = this.matricesIndices.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\r\n }\r\n\r\n if (this.matricesIndicesExtra) {\r\n vertexData.matricesIndicesExtra = this.matricesIndicesExtra.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\r\n }\r\n\r\n if (this.matricesWeights) {\r\n vertexData.matricesWeights = this.matricesWeights.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\r\n }\r\n\r\n if (this.matricesWeightsExtra) {\r\n vertexData.matricesWeightsExtra = this.matricesWeightsExtra.slice(materialInfo.verticesStart * 4, (materialInfo.verticesCount + materialInfo.verticesStart) * 4);\r\n }\r\n\r\n if (this.indices) {\r\n vertexData.indices = [];\r\n for (let index = materialInfo.indexStart; index < materialInfo.indexStart + materialInfo.indexCount; index++) {\r\n vertexData.indices.push(this.indices[index] - materialInfo.verticesStart);\r\n }\r\n }\r\n\r\n const newMaterialInfo = new VertexDataMaterialInfo();\r\n newMaterialInfo.indexStart = 0;\r\n newMaterialInfo.indexCount = vertexData.indices ? vertexData.indices.length : 0;\r\n newMaterialInfo.materialIndex = materialInfo.materialIndex;\r\n newMaterialInfo.verticesStart = 0;\r\n newMaterialInfo.verticesCount = (vertexData.positions ? vertexData.positions.length : 0) / 3;\r\n vertexData.materialInfos = [newMaterialInfo];\r\n\r\n result.push(vertexData);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Merges the passed VertexData into the current one\r\n * @param others the VertexData to be merged into the current one\r\n * @param use32BitsIndices defines a boolean indicating if indices must be store in a 32 bits array\r\n * @param forceCloneIndices defines a boolean indicating if indices are forced to be cloned\r\n * @param mergeMaterialIds defines a boolean indicating if we need to merge the material infos\r\n * @param enableCompletion defines a boolean indicating if the vertex data should be completed to be compatible\r\n * @returns the modified VertexData\r\n */\r\n public merge(others: VertexData | VertexData[], use32BitsIndices = false, forceCloneIndices = false, mergeMaterialIds = false, enableCompletion = false) {\r\n const vertexDatas: { vertexData: VertexData; transform?: Matrix }[] = Array.isArray(others)\r\n ? others.map((other) => {\r\n return { vertexData: other };\r\n })\r\n : [{ vertexData: others }];\r\n return runCoroutineSync(this._mergeCoroutine(undefined, vertexDatas, use32BitsIndices, false, forceCloneIndices, mergeMaterialIds, enableCompletion));\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public *_mergeCoroutine(\r\n transform: Matrix | undefined,\r\n vertexDatas: { vertexData: VertexData; transform?: Matrix }[],\r\n use32BitsIndices = false,\r\n isAsync: boolean,\r\n forceCloneIndices: boolean,\r\n mergeMaterialIds = false,\r\n enableCompletion = false\r\n ): Coroutine {\r\n this._validate();\r\n\r\n let others = vertexDatas.map((vertexData) => vertexData.vertexData);\r\n // eslint-disable-next-line @typescript-eslint/no-this-alias\r\n let root: VertexData = this;\r\n\r\n for (const other of others) {\r\n if (!other) {\r\n continue;\r\n }\r\n\r\n other._validate();\r\n\r\n if (!enableCompletion) {\r\n if (\r\n !this.normals !== !other.normals ||\r\n !this.tangents !== !other.tangents ||\r\n !this.uvs !== !other.uvs ||\r\n !this.uvs2 !== !other.uvs2 ||\r\n !this.uvs3 !== !other.uvs3 ||\r\n !this.uvs4 !== !other.uvs4 ||\r\n !this.uvs5 !== !other.uvs5 ||\r\n !this.uvs6 !== !other.uvs6 ||\r\n !this.colors !== !other.colors ||\r\n !this.matricesIndices !== !other.matricesIndices ||\r\n !this.matricesWeights !== !other.matricesWeights ||\r\n !this.matricesIndicesExtra !== !other.matricesIndicesExtra ||\r\n !this.matricesWeightsExtra !== !other.matricesWeightsExtra\r\n ) {\r\n throw new Error(\"Cannot merge vertex data that do not have the same set of attributes\");\r\n }\r\n } else {\r\n if (!this.normals !== !other.normals) {\r\n if (!this.normals) {\r\n this.normals = Array.from(other.normals!);\r\n } else {\r\n other.normals = Array.from(this.normals);\r\n }\r\n }\r\n\r\n if (!this.tangents !== !other.tangents) {\r\n if (!this.tangents) {\r\n this.tangents = Array.from(other.tangents!);\r\n } else {\r\n other.tangents = Array.from(this.tangents);\r\n }\r\n }\r\n\r\n if (!this.uvs !== !other.uvs) {\r\n if (!this.uvs) {\r\n this.uvs = Array.from(other.uvs!);\r\n } else {\r\n other.uvs = Array.from(this.uvs);\r\n }\r\n }\r\n\r\n if (!this.uvs2 !== !other.uvs2) {\r\n if (!this.uvs2) {\r\n this.uvs2 = Array.from(other.uvs2!);\r\n } else {\r\n other.uvs2 = Array.from(this.uvs2);\r\n }\r\n }\r\n\r\n if (!this.uvs3 !== !other.uvs3) {\r\n if (!this.uvs3) {\r\n this.uvs3 = Array.from(other.uvs3!);\r\n } else {\r\n other.uvs3 = Array.from(this.uvs3);\r\n }\r\n }\r\n\r\n if (!this.uvs4 !== !other.uvs4) {\r\n if (!this.uvs4) {\r\n this.uvs4 = Array.from(other.uvs4!);\r\n } else {\r\n other.uvs4 = Array.from(this.uvs4);\r\n }\r\n }\r\n\r\n if (!this.uvs5 !== !other.uvs5) {\r\n if (!this.uvs5) {\r\n this.uvs5 = Array.from(other.uvs5!);\r\n } else {\r\n other.uvs5 = Array.from(this.uvs5);\r\n }\r\n }\r\n\r\n if (!this.uvs6 !== !other.uvs6) {\r\n if (!this.uvs6) {\r\n this.uvs6 = Array.from(other.uvs6!);\r\n } else {\r\n other.uvs6 = Array.from(this.uvs6);\r\n }\r\n }\r\n\r\n if (!this.colors !== !other.colors) {\r\n if (!this.colors) {\r\n this.colors = Array.from(other.colors!);\r\n } else {\r\n other.colors = Array.from(this.colors);\r\n }\r\n }\r\n\r\n if (!this.matricesIndices !== !other.matricesIndices) {\r\n if (!this.matricesIndices) {\r\n this.matricesIndices = Array.from(other.matricesIndices!);\r\n } else {\r\n other.matricesIndices = Array.from(this.matricesIndices);\r\n }\r\n }\r\n\r\n if (!this.matricesWeights !== !other.matricesWeights) {\r\n if (!this.matricesWeights) {\r\n this.matricesWeights = Array.from(other.matricesWeights!);\r\n } else {\r\n other.matricesWeights = Array.from(this.matricesWeights);\r\n }\r\n }\r\n\r\n if (!this.matricesIndicesExtra !== !other.matricesIndicesExtra) {\r\n if (!this.matricesIndicesExtra) {\r\n this.matricesIndicesExtra = Array.from(other.matricesIndicesExtra!);\r\n } else {\r\n other.matricesIndicesExtra = Array.from(this.matricesIndicesExtra);\r\n }\r\n }\r\n\r\n if (!this.matricesWeightsExtra !== !other.matricesWeightsExtra) {\r\n if (!this.matricesWeightsExtra) {\r\n this.matricesWeightsExtra = Array.from(other.matricesWeightsExtra!);\r\n } else {\r\n other.matricesWeightsExtra = Array.from(this.matricesWeightsExtra);\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (mergeMaterialIds) {\r\n // Merge material infos\r\n let materialIndex = 0;\r\n let indexOffset = 0;\r\n let vertexOffset = 0;\r\n const materialInfos: VertexDataMaterialInfo[] = [];\r\n let currentMaterialInfo: Nullable = null;\r\n const vertexDataList: { vertexData: VertexData; transform?: Matrix }[] = [];\r\n\r\n // We need to split vertexData with more than one materialInfo\r\n for (const split of this.splitBasedOnMaterialID()) {\r\n vertexDataList.push({ vertexData: split, transform: transform });\r\n }\r\n\r\n for (const vertexData of vertexDatas) {\r\n for (const split of vertexData.vertexData.splitBasedOnMaterialID()) {\r\n vertexDataList.push({ vertexData: split, transform: vertexData.transform });\r\n }\r\n }\r\n\r\n // Sort by material IDs\r\n vertexDataList.sort((a, b) => {\r\n const matInfoA = a.vertexData.materialInfos ? a.vertexData.materialInfos[0].materialIndex : 0;\r\n const matInfoB = b.vertexData.materialInfos ? b.vertexData.materialInfos[0].materialIndex : 0;\r\n\r\n if (matInfoA > matInfoB) {\r\n return 1;\r\n }\r\n\r\n if (matInfoA === matInfoB) {\r\n return 0;\r\n }\r\n\r\n return -1;\r\n });\r\n\r\n // Build the new material info\r\n for (const vertexDataSource of vertexDataList) {\r\n const vertexData = vertexDataSource.vertexData;\r\n if (vertexData.materialInfos) {\r\n materialIndex = vertexData.materialInfos[0].materialIndex;\r\n } else {\r\n materialIndex = 0;\r\n }\r\n if (currentMaterialInfo && currentMaterialInfo.materialIndex === materialIndex) {\r\n currentMaterialInfo.indexCount += vertexData.indices!.length;\r\n currentMaterialInfo.verticesCount += vertexData.positions!.length / 3;\r\n } else {\r\n const materialInfo = new VertexDataMaterialInfo();\r\n materialInfo.materialIndex = materialIndex;\r\n materialInfo.indexStart = indexOffset;\r\n materialInfo.indexCount = vertexData.indices!.length;\r\n materialInfo.verticesStart = vertexOffset;\r\n materialInfo.verticesCount = vertexData.positions!.length / 3;\r\n\r\n materialInfos.push(materialInfo);\r\n currentMaterialInfo = materialInfo;\r\n }\r\n indexOffset += vertexData.indices!.length;\r\n vertexOffset += vertexData.positions!.length / 3;\r\n }\r\n // Extract sorted values\r\n const first = vertexDataList.splice(0, 1)[0];\r\n root = first.vertexData;\r\n transform = first.transform;\r\n others = vertexDataList.map((v) => v.vertexData);\r\n vertexDatas = vertexDataList;\r\n\r\n this.materialInfos = materialInfos;\r\n }\r\n\r\n // Merge geometries\r\n const totalIndices = others.reduce((indexSum, vertexData) => indexSum + (vertexData.indices?.length ?? 0), root.indices?.length ?? 0);\r\n const sliceIndices = forceCloneIndices || others.some((vertexData) => vertexData.indices === root.indices);\r\n let indices = sliceIndices ? root.indices?.slice() : root.indices;\r\n if (totalIndices > 0) {\r\n let indicesOffset = indices?.length ?? 0;\r\n\r\n if (!indices) {\r\n indices = new Array(totalIndices);\r\n }\r\n\r\n if (indices.length !== totalIndices) {\r\n if (Array.isArray(indices)) {\r\n indices.length = totalIndices;\r\n } else {\r\n const temp = use32BitsIndices || indices instanceof Uint32Array ? new Uint32Array(totalIndices) : new Uint16Array(totalIndices);\r\n temp.set(indices);\r\n indices = temp;\r\n }\r\n\r\n if (transform && transform.determinant() < 0) {\r\n VertexData._FlipFaces(indices, 0, indicesOffset);\r\n }\r\n }\r\n\r\n let positionsOffset = root.positions ? root.positions.length / 3 : 0;\r\n for (const { vertexData: other, transform } of vertexDatas) {\r\n if (other.indices) {\r\n for (let index = 0; index < other.indices.length; index++) {\r\n indices[indicesOffset + index] = other.indices[index] + positionsOffset;\r\n }\r\n\r\n if (transform && transform.determinant() < 0) {\r\n VertexData._FlipFaces(indices, indicesOffset, other.indices.length);\r\n }\r\n\r\n // The call to _validate already checked for positions\r\n positionsOffset += other.positions!.length / 3;\r\n indicesOffset += other.indices.length;\r\n\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n }\r\n }\r\n\r\n this.indices = indices!;\r\n\r\n this.positions = VertexData._MergeElement(\r\n VertexBuffer.PositionKind,\r\n root.positions,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.positions, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n if (root.normals) {\r\n this.normals = VertexData._MergeElement(\r\n VertexBuffer.NormalKind,\r\n root.normals,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.normals, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.tangents) {\r\n this.tangents = VertexData._MergeElement(\r\n VertexBuffer.TangentKind,\r\n root.tangents,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.tangents, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.uvs) {\r\n this.uvs = VertexData._MergeElement(\r\n VertexBuffer.UVKind,\r\n root.uvs,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.uvs, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.uvs2) {\r\n this.uvs2 = VertexData._MergeElement(\r\n VertexBuffer.UV2Kind,\r\n root.uvs2,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.uvs2, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.uvs3) {\r\n this.uvs3 = VertexData._MergeElement(\r\n VertexBuffer.UV3Kind,\r\n root.uvs3,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.uvs3, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.uvs4) {\r\n this.uvs4 = VertexData._MergeElement(\r\n VertexBuffer.UV4Kind,\r\n root.uvs4,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.uvs4, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.uvs5) {\r\n this.uvs5 = VertexData._MergeElement(\r\n VertexBuffer.UV5Kind,\r\n root.uvs5,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.uvs5, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.uvs6) {\r\n this.uvs6 = VertexData._MergeElement(\r\n VertexBuffer.UV6Kind,\r\n root.uvs6,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.uvs6, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.colors) {\r\n this.colors = VertexData._MergeElement(\r\n VertexBuffer.ColorKind,\r\n root.colors,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.colors, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.matricesIndices) {\r\n this.matricesIndices = VertexData._MergeElement(\r\n VertexBuffer.MatricesIndicesKind,\r\n root.matricesIndices,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.matricesIndices, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.matricesWeights) {\r\n this.matricesWeights = VertexData._MergeElement(\r\n VertexBuffer.MatricesWeightsKind,\r\n root.matricesWeights,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.matricesWeights, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.matricesIndicesExtra) {\r\n this.matricesIndicesExtra = VertexData._MergeElement(\r\n VertexBuffer.MatricesIndicesExtraKind,\r\n root.matricesIndicesExtra,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.matricesIndicesExtra, other.transform])\r\n );\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n if (root.matricesWeightsExtra) {\r\n this.matricesWeightsExtra = VertexData._MergeElement(\r\n VertexBuffer.MatricesWeightsExtraKind,\r\n root.matricesWeightsExtra,\r\n transform,\r\n vertexDatas.map((other) => [other.vertexData.matricesWeightsExtra, other.transform])\r\n );\r\n }\r\n\r\n return this;\r\n }\r\n\r\n private static _MergeElement(\r\n kind: string,\r\n source: Nullable,\r\n transform: Matrix | undefined,\r\n others: readonly (readonly [element: Nullable, transform?: Matrix])[]\r\n ): Nullable {\r\n const nonNullOthers = others.filter((other): other is [element: FloatArray, transform?: Matrix] => other[0] !== null && other[0] !== undefined);\r\n\r\n // If there is no source to copy and no other non-null sources then skip this element.\r\n if (!source && nonNullOthers.length == 0) {\r\n return source;\r\n }\r\n\r\n if (!source) {\r\n return this._MergeElement(kind, nonNullOthers[0][0], nonNullOthers[0][1], nonNullOthers.slice(1));\r\n }\r\n\r\n const len = nonNullOthers.reduce((sumLen, elements) => sumLen + elements[0].length, source.length);\r\n\r\n const transformRange =\r\n kind === VertexBuffer.PositionKind\r\n ? VertexData._TransformVector3Coordinates\r\n : kind === VertexBuffer.NormalKind\r\n ? VertexData._TransformVector3Normals\r\n : kind === VertexBuffer.TangentKind\r\n ? VertexData._TransformVector4Normals\r\n : () => {};\r\n\r\n if (source instanceof Float32Array) {\r\n // use non-loop method when the source is Float32Array\r\n const ret32 = new Float32Array(len);\r\n ret32.set(source);\r\n transform && transformRange(ret32, transform, 0, source.length);\r\n\r\n let offset = source.length;\r\n for (const [vertexData, transform] of nonNullOthers) {\r\n ret32.set(vertexData, offset);\r\n transform && transformRange(ret32, transform, offset, vertexData.length);\r\n offset += vertexData.length;\r\n }\r\n return ret32;\r\n } else {\r\n // don't use concat as it is super slow, just loop for other cases\r\n const ret = new Array(len);\r\n for (let i = 0; i < source.length; i++) {\r\n ret[i] = source[i];\r\n }\r\n transform && transformRange(ret, transform, 0, source.length);\r\n\r\n let offset = source.length;\r\n for (const [vertexData, transform] of nonNullOthers) {\r\n for (let i = 0; i < vertexData.length; i++) {\r\n ret[offset + i] = vertexData[i];\r\n }\r\n transform && transformRange(ret, transform, offset, vertexData.length);\r\n offset += vertexData.length;\r\n }\r\n return ret;\r\n }\r\n }\r\n\r\n private _validate(): void {\r\n if (!this.positions) {\r\n throw new RuntimeError(\"Positions are required\", ErrorCodes.MeshInvalidPositionsError);\r\n }\r\n\r\n const getElementCount = (kind: string, values: FloatArray) => {\r\n const stride = VertexBuffer.DeduceStride(kind);\r\n if (values.length % stride !== 0) {\r\n throw new Error(\"The \" + kind + \"s array count must be a multiple of \" + stride);\r\n }\r\n\r\n return values.length / stride;\r\n };\r\n\r\n const positionsElementCount = getElementCount(VertexBuffer.PositionKind, this.positions);\r\n\r\n const validateElementCount = (kind: string, values: FloatArray) => {\r\n const elementCount = getElementCount(kind, values);\r\n if (elementCount !== positionsElementCount) {\r\n throw new Error(\"The \" + kind + \"s element count (\" + elementCount + \") does not match the positions count (\" + positionsElementCount + \")\");\r\n }\r\n };\r\n\r\n if (this.normals) {\r\n validateElementCount(VertexBuffer.NormalKind, this.normals);\r\n }\r\n if (this.tangents) {\r\n validateElementCount(VertexBuffer.TangentKind, this.tangents);\r\n }\r\n if (this.uvs) {\r\n validateElementCount(VertexBuffer.UVKind, this.uvs);\r\n }\r\n if (this.uvs2) {\r\n validateElementCount(VertexBuffer.UV2Kind, this.uvs2);\r\n }\r\n if (this.uvs3) {\r\n validateElementCount(VertexBuffer.UV3Kind, this.uvs3);\r\n }\r\n if (this.uvs4) {\r\n validateElementCount(VertexBuffer.UV4Kind, this.uvs4);\r\n }\r\n if (this.uvs5) {\r\n validateElementCount(VertexBuffer.UV5Kind, this.uvs5);\r\n }\r\n if (this.uvs6) {\r\n validateElementCount(VertexBuffer.UV6Kind, this.uvs6);\r\n }\r\n if (this.colors) {\r\n validateElementCount(VertexBuffer.ColorKind, this.colors);\r\n }\r\n if (this.matricesIndices) {\r\n validateElementCount(VertexBuffer.MatricesIndicesKind, this.matricesIndices);\r\n }\r\n if (this.matricesWeights) {\r\n validateElementCount(VertexBuffer.MatricesWeightsKind, this.matricesWeights);\r\n }\r\n if (this.matricesIndicesExtra) {\r\n validateElementCount(VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra);\r\n }\r\n if (this.matricesWeightsExtra) {\r\n validateElementCount(VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra);\r\n }\r\n }\r\n\r\n /**\r\n * Clone the current vertex data\r\n * @returns a copy of the current data\r\n */\r\n public clone() {\r\n const serializationObject = this.serialize();\r\n return VertexData.Parse(serializationObject);\r\n }\r\n\r\n /**\r\n * Serializes the VertexData\r\n * @returns a serialized object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n if (this.positions) {\r\n serializationObject.positions = Array.from(this.positions);\r\n }\r\n\r\n if (this.normals) {\r\n serializationObject.normals = Array.from(this.normals);\r\n }\r\n\r\n if (this.tangents) {\r\n serializationObject.tangents = Array.from(this.tangents);\r\n }\r\n\r\n if (this.uvs) {\r\n serializationObject.uvs = Array.from(this.uvs);\r\n }\r\n\r\n if (this.uvs2) {\r\n serializationObject.uvs2 = Array.from(this.uvs2);\r\n }\r\n\r\n if (this.uvs3) {\r\n serializationObject.uvs3 = Array.from(this.uvs3);\r\n }\r\n\r\n if (this.uvs4) {\r\n serializationObject.uvs4 = Array.from(this.uvs4);\r\n }\r\n\r\n if (this.uvs5) {\r\n serializationObject.uvs5 = Array.from(this.uvs5);\r\n }\r\n\r\n if (this.uvs6) {\r\n serializationObject.uvs6 = Array.from(this.uvs6);\r\n }\r\n\r\n if (this.colors) {\r\n serializationObject.colors = Array.from(this.colors);\r\n }\r\n\r\n if (this.matricesIndices) {\r\n serializationObject.matricesIndices = Array.from(this.matricesIndices);\r\n serializationObject.matricesIndices._isExpanded = true;\r\n }\r\n\r\n if (this.matricesWeights) {\r\n serializationObject.matricesWeights = Array.from(this.matricesWeights);\r\n }\r\n\r\n if (this.matricesIndicesExtra) {\r\n serializationObject.matricesIndicesExtra = Array.from(this.matricesIndicesExtra);\r\n serializationObject.matricesIndicesExtra._isExpanded = true;\r\n }\r\n\r\n if (this.matricesWeightsExtra) {\r\n serializationObject.matricesWeightsExtra = Array.from(this.matricesWeightsExtra);\r\n }\r\n\r\n serializationObject.indices = Array.from(this.indices as number[]);\r\n\r\n if (this.materialInfos) {\r\n serializationObject.materialInfos = [];\r\n for (const materialInfo of this.materialInfos) {\r\n const materialInfoSerializationObject = {\r\n indexStart: materialInfo.indexStart,\r\n indexCount: materialInfo.indexCount,\r\n materialIndex: materialInfo.materialIndex,\r\n verticesStart: materialInfo.verticesStart,\r\n verticesCount: materialInfo.verticesCount,\r\n };\r\n serializationObject.materialInfos.push(materialInfoSerializationObject);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Extracts the vertexData from a mesh\r\n * @param mesh the mesh from which to extract the VertexData\r\n * @param copyWhenShared defines if the VertexData must be cloned when shared between multiple meshes, optional, default false\r\n * @param forceCopy indicating that the VertexData must be cloned, optional, default false\r\n * @returns the object VertexData associated to the passed mesh\r\n */\r\n public static ExtractFromMesh(mesh: Mesh, copyWhenShared?: boolean, forceCopy?: boolean): VertexData {\r\n return VertexData._ExtractFrom(mesh, copyWhenShared, forceCopy);\r\n }\r\n\r\n /**\r\n * Extracts the vertexData from the geometry\r\n * @param geometry the geometry from which to extract the VertexData\r\n * @param copyWhenShared defines if the VertexData must be cloned when the geometry is shared between multiple meshes, optional, default false\r\n * @param forceCopy indicating that the VertexData must be cloned, optional, default false\r\n * @returns the object VertexData associated to the passed mesh\r\n */\r\n public static ExtractFromGeometry(geometry: Geometry, copyWhenShared?: boolean, forceCopy?: boolean): VertexData {\r\n return VertexData._ExtractFrom(geometry, copyWhenShared, forceCopy);\r\n }\r\n\r\n private static _ExtractFrom(meshOrGeometry: IGetSetVerticesData, copyWhenShared?: boolean, forceCopy?: boolean): VertexData {\r\n const result = new VertexData();\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.PositionKind)) {\r\n result.positions = meshOrGeometry.getVerticesData(VertexBuffer.PositionKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n result.normals = meshOrGeometry.getVerticesData(VertexBuffer.NormalKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.TangentKind)) {\r\n result.tangents = meshOrGeometry.getVerticesData(VertexBuffer.TangentKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n result.uvs = meshOrGeometry.getVerticesData(VertexBuffer.UVKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\r\n result.uvs2 = meshOrGeometry.getVerticesData(VertexBuffer.UV2Kind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV3Kind)) {\r\n result.uvs3 = meshOrGeometry.getVerticesData(VertexBuffer.UV3Kind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV4Kind)) {\r\n result.uvs4 = meshOrGeometry.getVerticesData(VertexBuffer.UV4Kind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV5Kind)) {\r\n result.uvs5 = meshOrGeometry.getVerticesData(VertexBuffer.UV5Kind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV6Kind)) {\r\n result.uvs6 = meshOrGeometry.getVerticesData(VertexBuffer.UV6Kind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.ColorKind)) {\r\n result.colors = meshOrGeometry.getVerticesData(VertexBuffer.ColorKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {\r\n result.matricesIndices = meshOrGeometry.getVerticesData(VertexBuffer.MatricesIndicesKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\r\n result.matricesWeights = meshOrGeometry.getVerticesData(VertexBuffer.MatricesWeightsKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesIndicesExtraKind)) {\r\n result.matricesIndicesExtra = meshOrGeometry.getVerticesData(VertexBuffer.MatricesIndicesExtraKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesWeightsExtraKind)) {\r\n result.matricesWeightsExtra = meshOrGeometry.getVerticesData(VertexBuffer.MatricesWeightsExtraKind, copyWhenShared, forceCopy);\r\n }\r\n\r\n result.indices = meshOrGeometry.getIndices(copyWhenShared, forceCopy);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a Ribbon\r\n * @param options an object used to set the following optional parameters for the ribbon, required but can be empty\r\n * * pathArray array of paths, each of which an array of successive Vector3\r\n * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false\r\n * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false\r\n * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false\r\n * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional\r\n * * colors a linear array, of length 4 * number of vertices, of custom color values, optional\r\n * @param options.pathArray\r\n * @param options.closeArray\r\n * @param options.closePath\r\n * @param options.offset\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.invertUV\r\n * @param options.uvs\r\n * @param options.colors\r\n * @returns the VertexData of the ribbon\r\n * @deprecated use CreateRibbonVertexData instead\r\n */\r\n public static CreateRibbon(options: {\r\n pathArray: Vector3[][];\r\n closeArray?: boolean;\r\n closePath?: boolean;\r\n offset?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n invertUV?: boolean;\r\n uvs?: Vector2[];\r\n colors?: Color4[];\r\n }): VertexData {\r\n throw _WarnImport(\"ribbonBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a box\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * size sets the width, height and depth of the box to the value of size, optional default 1\r\n * * width sets the width (x direction) of the box, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the box, overwrites the height set by size, optional, default size\r\n * * depth sets the depth (z direction) of the box, overwrites the depth set by size, optional, default size\r\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\r\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the box\r\n * @deprecated Please use CreateBoxVertexData from the BoxBuilder file instead\r\n */\r\n public static CreateBox(options: {\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"boxBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a tiled box\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * faceTiles sets the pattern, tile size and number of tiles for a face\r\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\r\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param options.pattern\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.tileSize\r\n * @param options.tileWidth\r\n * @param options.tileHeight\r\n * @param options.alignHorizontal\r\n * @param options.alignVertical\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.sideOrientation\r\n * @returns the VertexData of the box\r\n * @deprecated Please use CreateTiledBoxVertexData instead\r\n */\r\n public static CreateTiledBox(options: {\r\n pattern?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n sideOrientation?: number;\r\n }): VertexData {\r\n throw _WarnImport(\"tiledBoxBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a tiled plane\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * pattern a limited pattern arrangement depending on the number\r\n * * tileSize sets the width, height and depth of the tile to the value of size, optional default 1\r\n * * tileWidth sets the width (x direction) of the tile, overwrites the width set by size, optional, default size\r\n * * tileHeight sets the height (y direction) of the tile, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.pattern\r\n * @param options.tileSize\r\n * @param options.tileWidth\r\n * @param options.tileHeight\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.alignHorizontal\r\n * @param options.alignVertical\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the tiled plane\r\n * @deprecated use CreateTiledPlaneVertexData instead\r\n */\r\n public static CreateTiledPlane(options: {\r\n pattern?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"tiledPlaneBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for an ellipsoid, defaults to a sphere\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * segments sets the number of horizontal strips optional, default 32\r\n * * diameter sets the axes dimensions, diameterX, diameterY and diameterZ to the value of diameter, optional default 1\r\n * * diameterX sets the diameterX (x direction) of the ellipsoid, overwrites the diameterX set by diameter, optional, default diameter\r\n * * diameterY sets the diameterY (y direction) of the ellipsoid, overwrites the diameterY set by diameter, optional, default diameter\r\n * * diameterZ sets the diameterZ (z direction) of the ellipsoid, overwrites the diameterZ set by diameter, optional, default diameter\r\n * * arc a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the circumference (latitude) given by the arc value, optional, default 1\r\n * * slice a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the height (latitude) given by the arc value, optional, default 1\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.segments\r\n * @param options.diameter\r\n * @param options.diameterX\r\n * @param options.diameterY\r\n * @param options.diameterZ\r\n * @param options.arc\r\n * @param options.slice\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the ellipsoid\r\n * @deprecated use CreateSphereVertexData instead\r\n */\r\n public static CreateSphere(options: {\r\n segments?: number;\r\n diameter?: number;\r\n diameterX?: number;\r\n diameterY?: number;\r\n diameterZ?: number;\r\n arc?: number;\r\n slice?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"sphereBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a cylinder, cone or prism\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * height sets the height (y direction) of the cylinder, optional, default 2\r\n * * diameterTop sets the diameter of the top of the cone, overwrites diameter, optional, default diameter\r\n * * diameterBottom sets the diameter of the bottom of the cone, overwrites diameter, optional, default diameter\r\n * * diameter sets the diameter of the top and bottom of the cone, optional default 1\r\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\r\n * * subdivisions` the number of rings along the cylinder height, optional, default 1\r\n * * arc a number from 0 to 1, to create an unclosed cylinder based on the fraction of the circumference given by the arc value, optional, default 1\r\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * * hasRings when true makes each subdivision independently treated as a face for faceUV and faceColors, optional, default false\r\n * * enclose when true closes an open cylinder by adding extra flat faces between the height axis and vertical edges, think cut cake\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.height\r\n * @param options.diameterTop\r\n * @param options.diameterBottom\r\n * @param options.diameter\r\n * @param options.tessellation\r\n * @param options.subdivisions\r\n * @param options.arc\r\n * @param options.faceColors\r\n * @param options.faceUV\r\n * @param options.hasRings\r\n * @param options.enclose\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the cylinder, cone or prism\r\n * @deprecated please use CreateCylinderVertexData instead\r\n */\r\n public static CreateCylinder(options: {\r\n height?: number;\r\n diameterTop?: number;\r\n diameterBottom?: number;\r\n diameter?: number;\r\n tessellation?: number;\r\n subdivisions?: number;\r\n arc?: number;\r\n faceColors?: Color4[];\r\n faceUV?: Vector4[];\r\n hasRings?: boolean;\r\n enclose?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"cylinderBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a torus\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * diameter the diameter of the torus, optional default 1\r\n * * thickness the diameter of the tube forming the torus, optional default 0.5\r\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.diameter\r\n * @param options.thickness\r\n * @param options.tessellation\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the torus\r\n * @deprecated use CreateTorusVertexData instead\r\n */\r\n public static CreateTorus(options: {\r\n diameter?: number;\r\n thickness?: number;\r\n tessellation?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"torusBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData of the LineSystem\r\n * @param options an object used to set the following optional parameters for the LineSystem, required but can be empty\r\n * - lines an array of lines, each line being an array of successive Vector3\r\n * - colors an array of line colors, each of the line colors being an array of successive Color4, one per line point\r\n * @param options.lines\r\n * @param options.colors\r\n * @returns the VertexData of the LineSystem\r\n * @deprecated use CreateLineSystemVertexData instead\r\n */\r\n public static CreateLineSystem(options: { lines: Vector3[][]; colors?: Nullable }): VertexData {\r\n throw _WarnImport(\"linesBuilder\");\r\n }\r\n\r\n /**\r\n * Create the VertexData for a DashedLines\r\n * @param options an object used to set the following optional parameters for the DashedLines, required but can be empty\r\n * - points an array successive Vector3\r\n * - dashSize the size of the dashes relative to the dash number, optional, default 3\r\n * - gapSize the size of the gap between two successive dashes relative to the dash number, optional, default 1\r\n * - dashNb the intended total number of dashes, optional, default 200\r\n * @param options.points\r\n * @param options.dashSize\r\n * @param options.gapSize\r\n * @param options.dashNb\r\n * @returns the VertexData for the DashedLines\r\n * @deprecated use CreateDashedLinesVertexData instead\r\n */\r\n public static CreateDashedLines(options: { points: Vector3[]; dashSize?: number; gapSize?: number; dashNb?: number }): VertexData {\r\n throw _WarnImport(\"linesBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a Ground\r\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\r\n * - width the width (x direction) of the ground, optional, default 1\r\n * - height the height (z direction) of the ground, optional, default 1\r\n * - subdivisions the number of subdivisions per side, optional, default 1\r\n * @param options.width\r\n * @param options.height\r\n * @param options.subdivisions\r\n * @param options.subdivisionsX\r\n * @param options.subdivisionsY\r\n * @returns the VertexData of the Ground\r\n * @deprecated Please use CreateGroundVertexData instead\r\n */\r\n public static CreateGround(options: { width?: number; height?: number; subdivisions?: number; subdivisionsX?: number; subdivisionsY?: number }): VertexData {\r\n throw _WarnImport(\"groundBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a TiledGround by subdividing the ground into tiles\r\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\r\n * * xmin the ground minimum X coordinate, optional, default -1\r\n * * zmin the ground minimum Z coordinate, optional, default -1\r\n * * xmax the ground maximum X coordinate, optional, default 1\r\n * * zmax the ground maximum Z coordinate, optional, default 1\r\n * * subdivisions a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the ground width and height creating 'tiles', default {w: 6, h: 6}\r\n * * precision a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the tile width and height, default {w: 2, h: 2}\r\n * @param options.xmin\r\n * @param options.zmin\r\n * @param options.xmax\r\n * @param options.zmax\r\n * @param options.subdivisions\r\n * @param options.subdivisions.w\r\n * @param options.subdivisions.h\r\n * @param options.precision\r\n * @param options.precision.w\r\n * @param options.precision.h\r\n * @returns the VertexData of the TiledGround\r\n * @deprecated use CreateTiledGroundVertexData instead\r\n */\r\n public static CreateTiledGround(options: {\r\n xmin: number;\r\n zmin: number;\r\n xmax: number;\r\n zmax: number;\r\n subdivisions?: { w: number; h: number };\r\n precision?: { w: number; h: number };\r\n }): VertexData {\r\n throw _WarnImport(\"groundBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData of the Ground designed from a heightmap\r\n * @param options an object used to set the following parameters for the Ground, required and provided by CreateGroundFromHeightMap\r\n * * width the width (x direction) of the ground\r\n * * height the height (z direction) of the ground\r\n * * subdivisions the number of subdivisions per side\r\n * * minHeight the minimum altitude on the ground, optional, default 0\r\n * * maxHeight the maximum altitude on the ground, optional default 1\r\n * * colorFilter the filter to apply to the image pixel colors to compute the height, optional Color3, default (0.3, 0.59, 0.11)\r\n * * buffer the array holding the image color data\r\n * * bufferWidth the width of image\r\n * * bufferHeight the height of image\r\n * * alphaFilter Remove any data where the alpha channel is below this value, defaults 0 (all data visible)\r\n * @param options.width\r\n * @param options.height\r\n * @param options.subdivisions\r\n * @param options.minHeight\r\n * @param options.maxHeight\r\n * @param options.colorFilter\r\n * @param options.buffer\r\n * @param options.bufferWidth\r\n * @param options.bufferHeight\r\n * @param options.alphaFilter\r\n * @returns the VertexData of the Ground designed from a heightmap\r\n * @deprecated use CreateGroundFromHeightMapVertexData instead\r\n */\r\n public static CreateGroundFromHeightMap(options: {\r\n width: number;\r\n height: number;\r\n subdivisions: number;\r\n minHeight: number;\r\n maxHeight: number;\r\n colorFilter: Color3;\r\n buffer: Uint8Array;\r\n bufferWidth: number;\r\n bufferHeight: number;\r\n alphaFilter: number;\r\n }): VertexData {\r\n throw _WarnImport(\"groundBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a Plane\r\n * @param options an object used to set the following optional parameters for the plane, required but can be empty\r\n * * size sets the width and height of the plane to the value of size, optional default 1\r\n * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the box\r\n * @deprecated use CreatePlaneVertexData instead\r\n */\r\n public static CreatePlane(options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 }): VertexData {\r\n throw _WarnImport(\"planeBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData of the Disc or regular Polygon\r\n * @param options an object used to set the following optional parameters for the disc, required but can be empty\r\n * * radius the radius of the disc, optional default 0.5\r\n * * tessellation the number of polygon sides, optional, default 64\r\n * * arc a number from 0 to 1, to create an unclosed polygon based on the fraction of the circumference given by the arc value, optional, default 1\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.tessellation\r\n * @param options.arc\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the box\r\n * @deprecated use CreateDiscVertexData instead\r\n */\r\n public static CreateDisc(options: { radius?: number; tessellation?: number; arc?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 }): VertexData {\r\n throw _WarnImport(\"discBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\r\n * All parameters are provided by CreatePolygon as needed\r\n * @param polygon a mesh built from polygonTriangulation.build()\r\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param wrap a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\r\n * @returns the VertexData of the Polygon\r\n * @deprecated use CreatePolygonVertexData instead\r\n */\r\n public static CreatePolygon(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4, wrap?: boolean): VertexData {\r\n throw _WarnImport(\"polygonBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData of the IcoSphere\r\n * @param options an object used to set the following optional parameters for the IcoSphere, required but can be empty\r\n * * radius the radius of the IcoSphere, optional default 1\r\n * * radiusX allows stretching in the x direction, optional, default radius\r\n * * radiusY allows stretching in the y direction, optional, default radius\r\n * * radiusZ allows stretching in the z direction, optional, default radius\r\n * * flat when true creates a flat shaded mesh, optional, default true\r\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.radiusX\r\n * @param options.radiusY\r\n * @param options.radiusZ\r\n * @param options.flat\r\n * @param options.subdivisions\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the IcoSphere\r\n * @deprecated use CreateIcoSphereVertexData instead\r\n */\r\n public static CreateIcoSphere(options: {\r\n radius?: number;\r\n radiusX?: number;\r\n radiusY?: number;\r\n radiusZ?: number;\r\n flat?: boolean;\r\n subdivisions?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"icoSphereBuilder\");\r\n }\r\n\r\n // inspired from // http://stemkoski.github.io/Three.js/Polyhedra.html\r\n /**\r\n * Creates the VertexData for a Polyhedron\r\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\r\n * * type provided types are:\r\n * * 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)\r\n * * 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)\r\n * * size the size of the IcoSphere, optional default 1\r\n * * sizeX allows stretching in the x direction, optional, default size\r\n * * sizeY allows stretching in the y direction, optional, default size\r\n * * sizeZ allows stretching in the z direction, optional, default size\r\n * * custom a number that overwrites the type to create from an extended set of polyhedron from https://www.babylonjs-playground.com/#21QRSK#15 with minimised editor\r\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * * flat when true creates a flat shaded mesh, optional, default true\r\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.type\r\n * @param options.size\r\n * @param options.sizeX\r\n * @param options.sizeY\r\n * @param options.sizeZ\r\n * @param options.custom\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.flat\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the Polyhedron\r\n * @deprecated use CreatePolyhedronVertexData instead\r\n */\r\n public static CreatePolyhedron(options: {\r\n type?: number;\r\n size?: number;\r\n sizeX?: number;\r\n sizeY?: number;\r\n sizeZ?: number;\r\n custom?: any;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n flat?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"polyhedronBuilder\");\r\n }\r\n\r\n /**\r\n * Creates the VertexData for a Capsule, inspired from https://github.com/maximeq/three-js-capsule-geometry/blob/master/src/CapsuleBufferGeometry.js\r\n * @param options an object used to set the following optional parameters for the capsule, required but can be empty\r\n * @returns the VertexData of the Capsule\r\n * @deprecated Please use CreateCapsuleVertexData from the capsuleBuilder file instead\r\n */\r\n public static CreateCapsule(\r\n options: ICreateCapsuleOptions = {\r\n orientation: Vector3.Up(),\r\n subdivisions: 2,\r\n tessellation: 16,\r\n height: 1,\r\n radius: 0.25,\r\n capSubdivisions: 6,\r\n }\r\n ): VertexData {\r\n throw _WarnImport(\"capsuleBuilder\");\r\n }\r\n\r\n // based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473\r\n /**\r\n * Creates the VertexData for a TorusKnot\r\n * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty\r\n * * radius the radius of the torus knot, optional, default 2\r\n * * tube the thickness of the tube, optional, default 0.5\r\n * * radialSegments the number of sides on each tube segments, optional, default 32\r\n * * tubularSegments the number of tubes to decompose the knot into, optional, default 32\r\n * * p the number of windings around the z axis, optional, default 2\r\n * * q the number of windings around the x axis, optional, default 3\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.tube\r\n * @param options.radialSegments\r\n * @param options.tubularSegments\r\n * @param options.p\r\n * @param options.q\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the Torus Knot\r\n * @deprecated use CreateTorusKnotVertexData instead\r\n */\r\n public static CreateTorusKnot(options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }): VertexData {\r\n throw _WarnImport(\"torusKnotBuilder\");\r\n }\r\n\r\n // Tools\r\n\r\n /**\r\n * Compute normals for given positions and indices\r\n * @param positions an array of vertex positions, [...., x, y, z, ......]\r\n * @param indices an array of indices in groups of three for each triangular facet, [...., i, j, k, ......]\r\n * @param normals an array of vertex normals, [...., x, y, z, ......]\r\n * @param options an object used to set the following optional parameters for the TorusKnot, optional\r\n * * facetNormals : optional array of facet normals (vector3)\r\n * * facetPositions : optional array of facet positions (vector3)\r\n * * facetPartitioning : optional partitioning array. facetPositions is required for facetPartitioning computation\r\n * * ratio : optional partitioning ratio / bounding box, required for facetPartitioning computation\r\n * * bInfo : optional bounding info, required for facetPartitioning computation\r\n * * bbSize : optional bounding box size data, required for facetPartitioning computation\r\n * * subDiv : optional partitioning data about subdivisions on each axis (int), required for facetPartitioning computation\r\n * * useRightHandedSystem: optional boolean to for right handed system computation\r\n * * depthSort : optional boolean to enable the facet depth sort computation\r\n * * distanceTo : optional Vector3 to compute the facet depth from this location\r\n * * depthSortedFacets : optional array of depthSortedFacets to store the facet distances from the reference location\r\n * @param options.facetNormals\r\n * @param options.facetPositions\r\n * @param options.facetPartitioning\r\n * @param options.ratio\r\n * @param options.bInfo\r\n * @param options.bbSize\r\n * @param options.subDiv\r\n * @param options.useRightHandedSystem\r\n * @param options.depthSort\r\n * @param options.distanceTo\r\n * @param options.depthSortedFacets\r\n */\r\n public static ComputeNormals(\r\n positions: any,\r\n indices: any,\r\n normals: any,\r\n options?: {\r\n facetNormals?: any;\r\n facetPositions?: any;\r\n facetPartitioning?: any;\r\n ratio?: number;\r\n bInfo?: any;\r\n bbSize?: Vector3;\r\n subDiv?: any;\r\n useRightHandedSystem?: boolean;\r\n depthSort?: boolean;\r\n distanceTo?: Vector3;\r\n depthSortedFacets?: any;\r\n }\r\n ): void {\r\n // temporary scalar variables\r\n let index = 0; // facet index\r\n let p1p2x = 0.0; // p1p2 vector x coordinate\r\n let p1p2y = 0.0; // p1p2 vector y coordinate\r\n let p1p2z = 0.0; // p1p2 vector z coordinate\r\n let p3p2x = 0.0; // p3p2 vector x coordinate\r\n let p3p2y = 0.0; // p3p2 vector y coordinate\r\n let p3p2z = 0.0; // p3p2 vector z coordinate\r\n let faceNormalx = 0.0; // facet normal x coordinate\r\n let faceNormaly = 0.0; // facet normal y coordinate\r\n let faceNormalz = 0.0; // facet normal z coordinate\r\n let length = 0.0; // facet normal length before normalization\r\n let v1x = 0; // vector1 x index in the positions array\r\n let v1y = 0; // vector1 y index in the positions array\r\n let v1z = 0; // vector1 z index in the positions array\r\n let v2x = 0; // vector2 x index in the positions array\r\n let v2y = 0; // vector2 y index in the positions array\r\n let v2z = 0; // vector2 z index in the positions array\r\n let v3x = 0; // vector3 x index in the positions array\r\n let v3y = 0; // vector3 y index in the positions array\r\n let v3z = 0; // vector3 z index in the positions array\r\n let computeFacetNormals = false;\r\n let computeFacetPositions = false;\r\n let computeFacetPartitioning = false;\r\n let computeDepthSort = false;\r\n let faceNormalSign = 1;\r\n let ratio = 0;\r\n let distanceTo: Nullable = null;\r\n if (options) {\r\n computeFacetNormals = options.facetNormals ? true : false;\r\n computeFacetPositions = options.facetPositions ? true : false;\r\n computeFacetPartitioning = options.facetPartitioning ? true : false;\r\n faceNormalSign = options.useRightHandedSystem === true ? -1 : 1;\r\n ratio = options.ratio || 0;\r\n computeDepthSort = options.depthSort ? true : false;\r\n distanceTo = options.distanceTo;\r\n if (computeDepthSort) {\r\n if (distanceTo === undefined) {\r\n distanceTo = Vector3.Zero();\r\n }\r\n }\r\n }\r\n\r\n // facetPartitioning reinit if needed\r\n let xSubRatio = 0;\r\n let ySubRatio = 0;\r\n let zSubRatio = 0;\r\n let subSq = 0;\r\n if (computeFacetPartitioning && options && options.bbSize) {\r\n //let bbSizeMax = options.bbSize.x > options.bbSize.y ? options.bbSize.x : options.bbSize.y;\r\n //bbSizeMax = bbSizeMax > options.bbSize.z ? bbSizeMax : options.bbSize.z;\r\n xSubRatio = (options.subDiv.X * ratio) / options.bbSize.x;\r\n ySubRatio = (options.subDiv.Y * ratio) / options.bbSize.y;\r\n zSubRatio = (options.subDiv.Z * ratio) / options.bbSize.z;\r\n subSq = options.subDiv.max * options.subDiv.max;\r\n options.facetPartitioning.length = 0;\r\n }\r\n\r\n // reset the normals\r\n for (index = 0; index < positions.length; index++) {\r\n normals[index] = 0.0;\r\n }\r\n\r\n // Loop : 1 indice triplet = 1 facet\r\n const nbFaces = (indices.length / 3) | 0;\r\n for (index = 0; index < nbFaces; index++) {\r\n // get the indexes of the coordinates of each vertex of the facet\r\n v1x = indices[index * 3] * 3;\r\n v1y = v1x + 1;\r\n v1z = v1x + 2;\r\n v2x = indices[index * 3 + 1] * 3;\r\n v2y = v2x + 1;\r\n v2z = v2x + 2;\r\n v3x = indices[index * 3 + 2] * 3;\r\n v3y = v3x + 1;\r\n v3z = v3x + 2;\r\n\r\n p1p2x = positions[v1x] - positions[v2x]; // compute two vectors per facet : p1p2 and p3p2\r\n p1p2y = positions[v1y] - positions[v2y];\r\n p1p2z = positions[v1z] - positions[v2z];\r\n\r\n p3p2x = positions[v3x] - positions[v2x];\r\n p3p2y = positions[v3y] - positions[v2y];\r\n p3p2z = positions[v3z] - positions[v2z];\r\n\r\n // compute the face normal with the cross product\r\n faceNormalx = faceNormalSign * (p1p2y * p3p2z - p1p2z * p3p2y);\r\n faceNormaly = faceNormalSign * (p1p2z * p3p2x - p1p2x * p3p2z);\r\n faceNormalz = faceNormalSign * (p1p2x * p3p2y - p1p2y * p3p2x);\r\n // normalize this normal and store it in the array facetData\r\n length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);\r\n length = length === 0 ? 1.0 : length;\r\n faceNormalx /= length;\r\n faceNormaly /= length;\r\n faceNormalz /= length;\r\n\r\n if (computeFacetNormals && options) {\r\n options.facetNormals[index].x = faceNormalx;\r\n options.facetNormals[index].y = faceNormaly;\r\n options.facetNormals[index].z = faceNormalz;\r\n }\r\n\r\n if (computeFacetPositions && options) {\r\n // compute and the facet barycenter coordinates in the array facetPositions\r\n options.facetPositions[index].x = (positions[v1x] + positions[v2x] + positions[v3x]) / 3.0;\r\n options.facetPositions[index].y = (positions[v1y] + positions[v2y] + positions[v3y]) / 3.0;\r\n options.facetPositions[index].z = (positions[v1z] + positions[v2z] + positions[v3z]) / 3.0;\r\n }\r\n\r\n if (computeFacetPartitioning && options) {\r\n // store the facet indexes in arrays in the main facetPartitioning array :\r\n // compute each facet vertex (+ facet barycenter) index in the partiniong array\r\n const ox = Math.floor((options.facetPositions[index].x - options.bInfo.minimum.x * ratio) * xSubRatio);\r\n const oy = Math.floor((options.facetPositions[index].y - options.bInfo.minimum.y * ratio) * ySubRatio);\r\n const oz = Math.floor((options.facetPositions[index].z - options.bInfo.minimum.z * ratio) * zSubRatio);\r\n const b1x = Math.floor((positions[v1x] - options.bInfo.minimum.x * ratio) * xSubRatio);\r\n const b1y = Math.floor((positions[v1y] - options.bInfo.minimum.y * ratio) * ySubRatio);\r\n const b1z = Math.floor((positions[v1z] - options.bInfo.minimum.z * ratio) * zSubRatio);\r\n const b2x = Math.floor((positions[v2x] - options.bInfo.minimum.x * ratio) * xSubRatio);\r\n const b2y = Math.floor((positions[v2y] - options.bInfo.minimum.y * ratio) * ySubRatio);\r\n const b2z = Math.floor((positions[v2z] - options.bInfo.minimum.z * ratio) * zSubRatio);\r\n const b3x = Math.floor((positions[v3x] - options.bInfo.minimum.x * ratio) * xSubRatio);\r\n const b3y = Math.floor((positions[v3y] - options.bInfo.minimum.y * ratio) * ySubRatio);\r\n const b3z = Math.floor((positions[v3z] - options.bInfo.minimum.z * ratio) * zSubRatio);\r\n\r\n const block_idx_v1 = b1x + options.subDiv.max * b1y + subSq * b1z;\r\n const block_idx_v2 = b2x + options.subDiv.max * b2y + subSq * b2z;\r\n const block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;\r\n const block_idx_o = ox + options.subDiv.max * oy + subSq * oz;\r\n\r\n options.facetPartitioning[block_idx_o] = options.facetPartitioning[block_idx_o] ? options.facetPartitioning[block_idx_o] : new Array();\r\n options.facetPartitioning[block_idx_v1] = options.facetPartitioning[block_idx_v1] ? options.facetPartitioning[block_idx_v1] : new Array();\r\n options.facetPartitioning[block_idx_v2] = options.facetPartitioning[block_idx_v2] ? options.facetPartitioning[block_idx_v2] : new Array();\r\n options.facetPartitioning[block_idx_v3] = options.facetPartitioning[block_idx_v3] ? options.facetPartitioning[block_idx_v3] : new Array();\r\n\r\n // push each facet index in each block containing the vertex\r\n options.facetPartitioning[block_idx_v1].push(index);\r\n if (block_idx_v2 != block_idx_v1) {\r\n options.facetPartitioning[block_idx_v2].push(index);\r\n }\r\n if (!(block_idx_v3 == block_idx_v2 || block_idx_v3 == block_idx_v1)) {\r\n options.facetPartitioning[block_idx_v3].push(index);\r\n }\r\n if (!(block_idx_o == block_idx_v1 || block_idx_o == block_idx_v2 || block_idx_o == block_idx_v3)) {\r\n options.facetPartitioning[block_idx_o].push(index);\r\n }\r\n }\r\n\r\n if (computeDepthSort && options && options.facetPositions) {\r\n const dsf = options.depthSortedFacets[index];\r\n dsf.ind = index * 3;\r\n dsf.sqDistance = Vector3.DistanceSquared(options.facetPositions[index], distanceTo!);\r\n }\r\n\r\n // compute the normals anyway\r\n normals[v1x] += faceNormalx; // accumulate all the normals per face\r\n normals[v1y] += faceNormaly;\r\n normals[v1z] += faceNormalz;\r\n normals[v2x] += faceNormalx;\r\n normals[v2y] += faceNormaly;\r\n normals[v2z] += faceNormalz;\r\n normals[v3x] += faceNormalx;\r\n normals[v3y] += faceNormaly;\r\n normals[v3z] += faceNormalz;\r\n }\r\n // last normalization of each normal\r\n for (index = 0; index < normals.length / 3; index++) {\r\n faceNormalx = normals[index * 3];\r\n faceNormaly = normals[index * 3 + 1];\r\n faceNormalz = normals[index * 3 + 2];\r\n\r\n length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);\r\n length = length === 0 ? 1.0 : length;\r\n faceNormalx /= length;\r\n faceNormaly /= length;\r\n faceNormalz /= length;\r\n\r\n normals[index * 3] = faceNormalx;\r\n normals[index * 3 + 1] = faceNormaly;\r\n normals[index * 3 + 2] = faceNormalz;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _ComputeSides(\r\n sideOrientation: number,\r\n positions: FloatArray,\r\n indices: FloatArray | IndicesArray,\r\n normals: FloatArray,\r\n uvs: FloatArray,\r\n frontUVs?: Vector4,\r\n backUVs?: Vector4\r\n ) {\r\n const li: number = indices.length;\r\n const ln: number = normals.length;\r\n let i: number;\r\n let n: number;\r\n sideOrientation = sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n switch (sideOrientation) {\r\n case VertexData.FRONTSIDE:\r\n // nothing changed\r\n break;\r\n\r\n case VertexData.BACKSIDE:\r\n // indices\r\n for (i = 0; i < li; i += 3) {\r\n const tmp = indices[i];\r\n indices[i] = indices[i + 2];\r\n indices[i + 2] = tmp;\r\n }\r\n // normals\r\n for (n = 0; n < ln; n++) {\r\n normals[n] = -normals[n];\r\n }\r\n break;\r\n\r\n case VertexData.DOUBLESIDE: {\r\n // positions\r\n const lp: number = positions.length;\r\n const l: number = lp / 3;\r\n for (let p = 0; p < lp; p++) {\r\n positions[lp + p] = positions[p];\r\n }\r\n // indices\r\n for (i = 0; i < li; i += 3) {\r\n indices[i + li] = indices[i + 2] + l;\r\n indices[i + 1 + li] = indices[i + 1] + l;\r\n indices[i + 2 + li] = indices[i] + l;\r\n }\r\n // normals\r\n for (n = 0; n < ln; n++) {\r\n normals[ln + n] = -normals[n];\r\n }\r\n\r\n // uvs\r\n const lu: number = uvs.length;\r\n let u: number = 0;\r\n for (u = 0; u < lu; u++) {\r\n uvs[u + lu] = uvs[u];\r\n }\r\n frontUVs = frontUVs ? frontUVs : new Vector4(0.0, 0.0, 1.0, 1.0);\r\n backUVs = backUVs ? backUVs : new Vector4(0.0, 0.0, 1.0, 1.0);\r\n u = 0;\r\n for (i = 0; i < lu / 2; i++) {\r\n uvs[u] = frontUVs.x + (frontUVs.z - frontUVs.x) * uvs[u];\r\n uvs[u + 1] = frontUVs.y + (frontUVs.w - frontUVs.y) * uvs[u + 1];\r\n uvs[u + lu] = backUVs.x + (backUVs.z - backUVs.x) * uvs[u + lu];\r\n uvs[u + lu + 1] = backUVs.y + (backUVs.w - backUVs.y) * uvs[u + lu + 1];\r\n u += 2;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a VertexData from serialized data\r\n * @param parsedVertexData the parsed data from an imported file\r\n * @returns a VertexData\r\n */\r\n public static Parse(parsedVertexData: any) {\r\n const vertexData = new VertexData();\r\n\r\n // positions\r\n const positions = parsedVertexData.positions;\r\n if (positions) {\r\n vertexData.set(positions, VertexBuffer.PositionKind);\r\n }\r\n\r\n // normals\r\n const normals = parsedVertexData.normals;\r\n if (normals) {\r\n vertexData.set(normals, VertexBuffer.NormalKind);\r\n }\r\n\r\n // tangents\r\n const tangents = parsedVertexData.tangents;\r\n if (tangents) {\r\n vertexData.set(tangents, VertexBuffer.TangentKind);\r\n }\r\n\r\n // uvs\r\n const uvs = parsedVertexData.uvs;\r\n if (uvs) {\r\n vertexData.set(uvs, VertexBuffer.UVKind);\r\n }\r\n\r\n // uv2s\r\n const uvs2 = parsedVertexData.uvs2;\r\n if (uvs2) {\r\n vertexData.set(uvs2, VertexBuffer.UV2Kind);\r\n }\r\n\r\n // uv3s\r\n const uvs3 = parsedVertexData.uvs3;\r\n if (uvs3) {\r\n vertexData.set(uvs3, VertexBuffer.UV3Kind);\r\n }\r\n\r\n // uv4s\r\n const uvs4 = parsedVertexData.uvs4;\r\n if (uvs4) {\r\n vertexData.set(uvs4, VertexBuffer.UV4Kind);\r\n }\r\n\r\n // uv5s\r\n const uvs5 = parsedVertexData.uvs5;\r\n if (uvs5) {\r\n vertexData.set(uvs5, VertexBuffer.UV5Kind);\r\n }\r\n\r\n // uv6s\r\n const uvs6 = parsedVertexData.uvs6;\r\n if (uvs6) {\r\n vertexData.set(uvs6, VertexBuffer.UV6Kind);\r\n }\r\n\r\n // colors\r\n const colors = parsedVertexData.colors;\r\n if (colors) {\r\n vertexData.set(Color4.CheckColors4(colors, positions.length / 3), VertexBuffer.ColorKind);\r\n }\r\n\r\n // matricesIndices\r\n const matricesIndices = parsedVertexData.matricesIndices;\r\n if (matricesIndices) {\r\n vertexData.set(matricesIndices, VertexBuffer.MatricesIndicesKind);\r\n }\r\n\r\n // matricesWeights\r\n const matricesWeights = parsedVertexData.matricesWeights;\r\n if (matricesWeights) {\r\n vertexData.set(matricesWeights, VertexBuffer.MatricesWeightsKind);\r\n }\r\n\r\n // indices\r\n const indices = parsedVertexData.indices;\r\n if (indices) {\r\n vertexData.indices = indices;\r\n }\r\n\r\n // MaterialInfos\r\n const materialInfos = parsedVertexData.materialInfos;\r\n if (materialInfos) {\r\n vertexData.materialInfos = [];\r\n for (const materialInfoFromJSON of materialInfos) {\r\n const materialInfo = new VertexDataMaterialInfo();\r\n materialInfo.indexCount = materialInfoFromJSON.indexCount;\r\n materialInfo.indexStart = materialInfoFromJSON.indexStart;\r\n materialInfo.verticesCount = materialInfoFromJSON.verticesCount;\r\n materialInfo.verticesStart = materialInfoFromJSON.verticesStart;\r\n materialInfo.materialIndex = materialInfoFromJSON.materialIndex;\r\n vertexData.materialInfos.push(materialInfo);\r\n }\r\n }\r\n\r\n return vertexData;\r\n }\r\n\r\n /**\r\n * Applies VertexData created from the imported parameters to the geometry\r\n * @param parsedVertexData the parsed data from an imported file\r\n * @param geometry the geometry to apply the VertexData to\r\n */\r\n public static ImportVertexData(parsedVertexData: any, geometry: Geometry) {\r\n const vertexData = VertexData.Parse(parsedVertexData);\r\n\r\n geometry.setAllVerticesData(vertexData, parsedVertexData.updatable);\r\n }\r\n}\r\n","import { Constants } from \"../Engines/constants\";\r\n\r\n/**\r\n * Class used to represent data loading progression\r\n */\r\nexport class SceneLoaderFlags {\r\n // Flags\r\n private static _ForceFullSceneLoadingForIncremental = false;\r\n private static _ShowLoadingScreen = true;\r\n private static _CleanBoneMatrixWeights = false;\r\n private static _LoggingLevel = Constants.SCENELOADER_NO_LOGGING;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if entire scene must be loaded even if scene contains incremental data\r\n */\r\n public static get ForceFullSceneLoadingForIncremental() {\r\n return SceneLoaderFlags._ForceFullSceneLoadingForIncremental;\r\n }\r\n\r\n public static set ForceFullSceneLoadingForIncremental(value: boolean) {\r\n SceneLoaderFlags._ForceFullSceneLoadingForIncremental = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if loading screen must be displayed while loading a scene\r\n */\r\n public static get ShowLoadingScreen(): boolean {\r\n return SceneLoaderFlags._ShowLoadingScreen;\r\n }\r\n\r\n public static set ShowLoadingScreen(value: boolean) {\r\n SceneLoaderFlags._ShowLoadingScreen = value;\r\n }\r\n\r\n /**\r\n * Defines the current logging level (while loading the scene)\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static get loggingLevel(): number {\r\n return SceneLoaderFlags._LoggingLevel;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static set loggingLevel(value: number) {\r\n SceneLoaderFlags._LoggingLevel = value;\r\n }\r\n\r\n /**\r\n * Gets or set a boolean indicating if matrix weights must be cleaned upon loading\r\n */\r\n public static get CleanBoneMatrixWeights(): boolean {\r\n return SceneLoaderFlags._CleanBoneMatrixWeights;\r\n }\r\n\r\n public static set CleanBoneMatrixWeights(value: boolean) {\r\n SceneLoaderFlags._CleanBoneMatrixWeights = value;\r\n }\r\n}\r\n","/**\r\n * Options used to control default behaviors regarding compatibility support\r\n */\r\nexport class CompatibilityOptions {\r\n /**\r\n * Defines if the system should use OpenGL convention for UVs when creating geometry or loading .babylon files (false by default)\r\n */\r\n public static UseOpenGLOrientationForUV = false;\r\n}\r\n","import type { Nullable, FloatArray, DataArray, IndicesArray } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Vector2 } from \"../Maths/math.vector\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { IGetSetVerticesData } from \"../Meshes/mesh.vertexData\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { SceneLoaderFlags } from \"../Loading/sceneLoaderFlags\";\r\nimport { BoundingInfo } from \"../Culling/boundingInfo\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport { Tags } from \"../Misc/tags\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { extractMinAndMax } from \"../Maths/math.functions\";\r\nimport type { AbstractScene } from \"../abstractScene\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { CompatibilityOptions } from \"../Compat/compatibilityOptions\";\r\n\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\n\r\n/**\r\n * Class used to store geometry data (vertex buffers + index buffer)\r\n */\r\nexport class Geometry implements IGetSetVerticesData {\r\n // Members\r\n /**\r\n * Gets or sets the ID of the geometry\r\n */\r\n public id: string;\r\n /**\r\n * Gets or sets the unique ID of the geometry\r\n */\r\n public uniqueId: number;\r\n /**\r\n * Gets the delay loading state of the geometry (none by default which means not delayed)\r\n */\r\n public delayLoadState = Constants.DELAYLOADSTATE_NONE;\r\n /**\r\n * Gets the file containing the data to load when running in delay load state\r\n */\r\n public delayLoadingFile: Nullable;\r\n /**\r\n * Callback called when the geometry is updated\r\n */\r\n public onGeometryUpdated: (geometry: Geometry, kind?: string) => void;\r\n\r\n // Private\r\n private _scene: Scene;\r\n private _engine: Engine;\r\n private _meshes: Mesh[];\r\n private _totalVertices = 0;\r\n /** @internal */\r\n public _loadedUniqueId: string;\r\n /** @internal */\r\n public _indices: IndicesArray;\r\n /** @internal */\r\n public _vertexBuffers: { [key: string]: VertexBuffer };\r\n private _isDisposed = false;\r\n private _extend: { minimum: Vector3; maximum: Vector3 };\r\n private _boundingBias: Vector2;\r\n /** @internal */\r\n public _delayInfo: Array;\r\n private _indexBuffer: Nullable;\r\n private _indexBufferIsUpdatable = false;\r\n /** @internal */\r\n public _boundingInfo: Nullable;\r\n /** @internal */\r\n public _delayLoadingFunction: Nullable<(any: any, geometry: Geometry) => void>;\r\n /** @internal */\r\n public _softwareSkinningFrameId: number;\r\n private _vertexArrayObjects: { [key: string]: WebGLVertexArrayObject };\r\n private _updatable: boolean;\r\n\r\n // Cache\r\n /** @internal */\r\n public _positions: Nullable;\r\n private _positionsCache: Vector3[] = [];\r\n\r\n /** @internal */\r\n public _parentContainer: Nullable = null;\r\n\r\n /**\r\n * Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y\r\n */\r\n public get boundingBias(): Vector2 {\r\n return this._boundingBias;\r\n }\r\n\r\n /**\r\n * Gets or sets the Bias Vector to apply on the bounding elements (box/sphere), the max extend is computed as v += v * bias.x + bias.y, the min is computed as v -= v * bias.x + bias.y\r\n */\r\n public set boundingBias(value: Vector2) {\r\n if (this._boundingBias) {\r\n this._boundingBias.copyFrom(value);\r\n } else {\r\n this._boundingBias = value.clone();\r\n }\r\n\r\n this._updateBoundingInfo(true, null);\r\n }\r\n\r\n /**\r\n * Static function used to attach a new empty geometry to a mesh\r\n * @param mesh defines the mesh to attach the geometry to\r\n * @returns the new Geometry\r\n */\r\n public static CreateGeometryForMesh(mesh: Mesh): Geometry {\r\n const geometry = new Geometry(Geometry.RandomId(), mesh.getScene());\r\n\r\n geometry.applyToMesh(mesh);\r\n\r\n return geometry;\r\n }\r\n\r\n /** Get the list of meshes using this geometry */\r\n public get meshes(): Mesh[] {\r\n return this._meshes;\r\n }\r\n\r\n /**\r\n * If set to true (false by default), the bounding info applied to the meshes sharing this geometry will be the bounding info defined at the class level\r\n * and won't be computed based on the vertex positions (which is what we get when useBoundingInfoFromGeometry = false)\r\n */\r\n public useBoundingInfoFromGeometry = false;\r\n\r\n /**\r\n * Creates a new geometry\r\n * @param id defines the unique ID\r\n * @param scene defines the hosting scene\r\n * @param vertexData defines the VertexData used to get geometry data\r\n * @param updatable defines if geometry must be updatable (false by default)\r\n * @param mesh defines the mesh that will be associated with the geometry\r\n */\r\n constructor(id: string, scene?: Scene, vertexData?: VertexData, updatable: boolean = false, mesh: Nullable = null) {\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n if (!this._scene) {\r\n return;\r\n }\r\n this.id = id;\r\n this.uniqueId = this._scene.getUniqueId();\r\n this._engine = this._scene.getEngine();\r\n this._meshes = [];\r\n //Init vertex buffer cache\r\n this._vertexBuffers = {};\r\n this._indices = [];\r\n this._updatable = updatable;\r\n\r\n // vertexData\r\n if (vertexData) {\r\n this.setAllVerticesData(vertexData, updatable);\r\n } else {\r\n this._totalVertices = 0;\r\n }\r\n\r\n if (this._engine.getCaps().vertexArrayObject) {\r\n this._vertexArrayObjects = {};\r\n }\r\n\r\n // applyToMesh\r\n if (mesh) {\r\n this.applyToMesh(mesh);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current extend of the geometry\r\n */\r\n public get extend(): { minimum: Vector3; maximum: Vector3 } {\r\n return this._extend;\r\n }\r\n\r\n /**\r\n * Gets the hosting scene\r\n * @returns the hosting Scene\r\n */\r\n public getScene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Gets the hosting engine\r\n * @returns the hosting Engine\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * Defines if the geometry is ready to use\r\n * @returns true if the geometry is ready to be used\r\n */\r\n public isReady(): boolean {\r\n return this.delayLoadState === Constants.DELAYLOADSTATE_LOADED || this.delayLoadState === Constants.DELAYLOADSTATE_NONE;\r\n }\r\n\r\n /**\r\n * Gets a value indicating that the geometry should not be serialized\r\n */\r\n public get doNotSerialize(): boolean {\r\n for (let index = 0; index < this._meshes.length; index++) {\r\n if (!this._meshes[index].doNotSerialize) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (this._vertexArrayObjects) {\r\n this._vertexArrayObjects = {};\r\n }\r\n\r\n // Index buffer\r\n if (this._meshes.length !== 0 && this._indices) {\r\n this._indexBuffer = this._engine.createIndexBuffer(this._indices, this._updatable);\r\n }\r\n\r\n // Vertex buffers\r\n for (const key in this._vertexBuffers) {\r\n const vertexBuffer = this._vertexBuffers[key];\r\n vertexBuffer._rebuild();\r\n }\r\n }\r\n\r\n /**\r\n * Affects all geometry data in one call\r\n * @param vertexData defines the geometry data\r\n * @param updatable defines if the geometry must be flagged as updatable (false as default)\r\n */\r\n public setAllVerticesData(vertexData: VertexData, updatable?: boolean): void {\r\n vertexData.applyToGeometry(this, updatable);\r\n this._notifyUpdate();\r\n }\r\n\r\n /**\r\n * Set specific vertex data\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @param data defines the vertex data to use\r\n * @param updatable defines if the vertex must be flagged as updatable (false as default)\r\n * @param stride defines the stride to use (0 by default). This value is deduced from the kind value if not specified\r\n */\r\n public setVerticesData(kind: string, data: FloatArray, updatable: boolean = false, stride?: number): void {\r\n if (updatable && Array.isArray(data)) {\r\n // to avoid converting to Float32Array at each draw call in engine.updateDynamicVertexBuffer, we make the conversion a single time here\r\n data = new Float32Array(data);\r\n }\r\n const buffer = new VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);\r\n this.setVerticesBuffer(buffer);\r\n }\r\n\r\n /**\r\n * Removes a specific vertex data\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n */\r\n public removeVerticesData(kind: string) {\r\n if (this._vertexBuffers[kind]) {\r\n this._vertexBuffers[kind].dispose();\r\n delete this._vertexBuffers[kind];\r\n }\r\n\r\n if (this._vertexArrayObjects) {\r\n this._disposeVertexArrayObjects();\r\n }\r\n }\r\n\r\n /**\r\n * Affect a vertex buffer to the geometry. the vertexBuffer.getKind() function is used to determine where to store the data\r\n * @param buffer defines the vertex buffer to use\r\n * @param totalVertices defines the total number of vertices for position kind (could be null)\r\n * @param disposeExistingBuffer disposes the existing buffer, if any (default: true)\r\n */\r\n public setVerticesBuffer(buffer: VertexBuffer, totalVertices: Nullable = null, disposeExistingBuffer = true): void {\r\n const kind = buffer.getKind();\r\n if (this._vertexBuffers[kind] && disposeExistingBuffer) {\r\n this._vertexBuffers[kind].dispose();\r\n }\r\n\r\n if (buffer._buffer) {\r\n buffer._buffer._increaseReferences();\r\n }\r\n\r\n this._vertexBuffers[kind] = buffer;\r\n const meshes = this._meshes;\r\n const numOfMeshes = meshes.length;\r\n\r\n if (kind === VertexBuffer.PositionKind) {\r\n const data = buffer.getData();\r\n if (totalVertices != null) {\r\n this._totalVertices = totalVertices;\r\n } else {\r\n if (data != null) {\r\n this._totalVertices = data.length / (buffer.type === VertexBuffer.BYTE ? buffer.byteStride : buffer.byteStride / 4);\r\n }\r\n }\r\n\r\n this._updateExtend(data);\r\n this._resetPointsArrayCache();\r\n\r\n for (let index = 0; index < numOfMeshes; index++) {\r\n const mesh = meshes[index];\r\n mesh.buildBoundingInfo(this._extend.minimum, this._extend.maximum);\r\n mesh._createGlobalSubMesh(mesh.isUnIndexed);\r\n mesh.computeWorldMatrix(true);\r\n mesh.synchronizeInstances();\r\n }\r\n }\r\n\r\n this._notifyUpdate(kind);\r\n }\r\n\r\n /**\r\n * Update a specific vertex buffer\r\n * This function will directly update the underlying DataBuffer according to the passed numeric array or Float32Array\r\n * It will do nothing if the buffer is not updatable\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @param data defines the data to use\r\n * @param offset defines the offset in the target buffer where to store the data\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateVerticesDataDirectly(kind: string, data: DataArray, offset: number, useBytes: boolean = false): void {\r\n const vertexBuffer = this.getVertexBuffer(kind);\r\n\r\n if (!vertexBuffer) {\r\n return;\r\n }\r\n\r\n vertexBuffer.updateDirectly(data, offset, useBytes);\r\n this._notifyUpdate(kind);\r\n }\r\n\r\n /**\r\n * Update a specific vertex buffer\r\n * This function will create a new buffer if the current one is not updatable\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @param data defines the data to use\r\n * @param updateExtends defines if the geometry extends must be recomputed (false by default)\r\n */\r\n public updateVerticesData(kind: string, data: FloatArray, updateExtends: boolean = false): void {\r\n const vertexBuffer = this.getVertexBuffer(kind);\r\n\r\n if (!vertexBuffer) {\r\n return;\r\n }\r\n\r\n vertexBuffer.update(data);\r\n\r\n if (kind === VertexBuffer.PositionKind) {\r\n this._updateBoundingInfo(updateExtends, data);\r\n }\r\n this._notifyUpdate(kind);\r\n }\r\n\r\n private _updateBoundingInfo(updateExtends: boolean, data: Nullable) {\r\n if (updateExtends) {\r\n this._updateExtend(data);\r\n }\r\n\r\n this._resetPointsArrayCache();\r\n\r\n if (updateExtends) {\r\n const meshes = this._meshes;\r\n for (const mesh of meshes) {\r\n if (mesh.hasBoundingInfo) {\r\n mesh.getBoundingInfo().reConstruct(this._extend.minimum, this._extend.maximum);\r\n } else {\r\n mesh.buildBoundingInfo(this._extend.minimum, this._extend.maximum);\r\n }\r\n\r\n const subMeshes = mesh.subMeshes;\r\n for (const subMesh of subMeshes) {\r\n subMesh.refreshBoundingInfo();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bind(\r\n effect: Nullable,\r\n indexToBind?: Nullable,\r\n overrideVertexBuffers?: { [kind: string]: Nullable },\r\n overrideVertexArrayObjects?: { [key: string]: WebGLVertexArrayObject }\r\n ): void {\r\n if (!effect) {\r\n return;\r\n }\r\n\r\n if (indexToBind === undefined) {\r\n indexToBind = this._indexBuffer;\r\n }\r\n const vbs = this.getVertexBuffers();\r\n\r\n if (!vbs) {\r\n return;\r\n }\r\n\r\n if (indexToBind != this._indexBuffer || (!this._vertexArrayObjects && !overrideVertexArrayObjects)) {\r\n this._engine.bindBuffers(vbs, indexToBind, effect, overrideVertexBuffers);\r\n return;\r\n }\r\n\r\n const vaos = overrideVertexArrayObjects ? overrideVertexArrayObjects : this._vertexArrayObjects;\r\n\r\n // Using VAO\r\n if (!vaos[effect.key]) {\r\n vaos[effect.key] = this._engine.recordVertexArrayObject(vbs, indexToBind, effect, overrideVertexBuffers);\r\n }\r\n\r\n this._engine.bindVertexArrayObject(vaos[effect.key], indexToBind);\r\n }\r\n\r\n /**\r\n * Gets total number of vertices\r\n * @returns the total number of vertices\r\n */\r\n public getTotalVertices(): number {\r\n if (!this.isReady()) {\r\n return 0;\r\n }\r\n\r\n return this._totalVertices;\r\n }\r\n\r\n /**\r\n * Gets a specific vertex data attached to this geometry. Float data is constructed if the vertex buffer data cannot be returned directly.\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n public getVerticesData(kind: string, copyWhenShared?: boolean, forceCopy?: boolean): Nullable {\r\n const vertexBuffer = this.getVertexBuffer(kind);\r\n if (!vertexBuffer) {\r\n return null;\r\n }\r\n\r\n return vertexBuffer.getFloatData(this._totalVertices, forceCopy || (copyWhenShared && this._meshes.length !== 1));\r\n }\r\n\r\n /**\r\n * Returns a boolean defining if the vertex data for the requested `kind` is updatable\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @returns true if the vertex buffer with the specified kind is updatable\r\n */\r\n public isVertexBufferUpdatable(kind: string): boolean {\r\n const vb = this._vertexBuffers[kind];\r\n\r\n if (!vb) {\r\n return false;\r\n }\r\n\r\n return vb.isUpdatable();\r\n }\r\n\r\n /**\r\n * Gets a specific vertex buffer\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @returns a VertexBuffer\r\n */\r\n public getVertexBuffer(kind: string): Nullable {\r\n if (!this.isReady()) {\r\n return null;\r\n }\r\n return this._vertexBuffers[kind];\r\n }\r\n\r\n /**\r\n * Returns all vertex buffers\r\n * @returns an object holding all vertex buffers indexed by kind\r\n */\r\n public getVertexBuffers(): Nullable<{ [key: string]: VertexBuffer }> {\r\n if (!this.isReady()) {\r\n return null;\r\n }\r\n return this._vertexBuffers;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if specific vertex buffer is present\r\n * @param kind defines the data kind (Position, normal, etc...)\r\n * @returns true if data is present\r\n */\r\n public isVerticesDataPresent(kind: string): boolean {\r\n if (!this._vertexBuffers) {\r\n if (this._delayInfo) {\r\n return this._delayInfo.indexOf(kind) !== -1;\r\n }\r\n return false;\r\n }\r\n return this._vertexBuffers[kind] !== undefined;\r\n }\r\n\r\n /**\r\n * Gets a list of all attached data kinds (Position, normal, etc...)\r\n * @returns a list of string containing all kinds\r\n */\r\n public getVerticesDataKinds(): string[] {\r\n const result = [];\r\n let kind;\r\n if (!this._vertexBuffers && this._delayInfo) {\r\n for (kind in this._delayInfo) {\r\n result.push(kind);\r\n }\r\n } else {\r\n for (kind in this._vertexBuffers) {\r\n result.push(kind);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Update index buffer\r\n * @param indices defines the indices to store in the index buffer\r\n * @param offset defines the offset in the target buffer where to store the data\r\n * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)\r\n */\r\n public updateIndices(indices: IndicesArray, offset?: number, gpuMemoryOnly = false): void {\r\n if (!this._indexBuffer) {\r\n return;\r\n }\r\n\r\n if (!this._indexBufferIsUpdatable) {\r\n this.setIndices(indices, null, true);\r\n } else {\r\n const needToUpdateSubMeshes = indices.length !== this._indices.length;\r\n\r\n if (!gpuMemoryOnly) {\r\n this._indices = indices.slice();\r\n }\r\n this._engine.updateDynamicIndexBuffer(this._indexBuffer, indices, offset);\r\n if (needToUpdateSubMeshes) {\r\n for (const mesh of this._meshes) {\r\n mesh._createGlobalSubMesh(true);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new index buffer\r\n * @param indices defines the indices to store in the index buffer\r\n * @param totalVertices defines the total number of vertices (could be null)\r\n * @param updatable defines if the index buffer must be flagged as updatable (false by default)\r\n */\r\n public setIndices(indices: IndicesArray, totalVertices: Nullable = null, updatable: boolean = false): void {\r\n if (this._indexBuffer) {\r\n this._engine._releaseBuffer(this._indexBuffer);\r\n }\r\n\r\n this._indices = indices;\r\n this._indexBufferIsUpdatable = updatable;\r\n if (this._meshes.length !== 0 && this._indices) {\r\n this._indexBuffer = this._engine.createIndexBuffer(this._indices, updatable);\r\n }\r\n\r\n if (totalVertices != undefined) {\r\n // including null and undefined\r\n this._totalVertices = totalVertices;\r\n }\r\n\r\n for (const mesh of this._meshes) {\r\n mesh._createGlobalSubMesh(true);\r\n mesh.synchronizeInstances();\r\n }\r\n\r\n this._notifyUpdate();\r\n }\r\n\r\n /**\r\n * Return the total number of indices\r\n * @returns the total number of indices\r\n */\r\n public getTotalIndices(): number {\r\n if (!this.isReady()) {\r\n return 0;\r\n }\r\n return this._indices.length;\r\n }\r\n\r\n /**\r\n * Gets the index buffer array\r\n * @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns the index buffer array\r\n */\r\n public getIndices(copyWhenShared?: boolean, forceCopy?: boolean): Nullable {\r\n if (!this.isReady()) {\r\n return null;\r\n }\r\n const orig = this._indices;\r\n if (!forceCopy && (!copyWhenShared || this._meshes.length === 1)) {\r\n return orig;\r\n } else {\r\n return orig.slice();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the index buffer\r\n * @returns the index buffer\r\n */\r\n public getIndexBuffer(): Nullable {\r\n if (!this.isReady()) {\r\n return null;\r\n }\r\n return this._indexBuffer;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseVertexArrayObject(effect: Nullable = null) {\r\n if (!effect || !this._vertexArrayObjects) {\r\n return;\r\n }\r\n\r\n if (this._vertexArrayObjects[effect.key]) {\r\n this._engine.releaseVertexArrayObject(this._vertexArrayObjects[effect.key]);\r\n delete this._vertexArrayObjects[effect.key];\r\n }\r\n }\r\n\r\n /**\r\n * Release the associated resources for a specific mesh\r\n * @param mesh defines the source mesh\r\n * @param shouldDispose defines if the geometry must be disposed if there is no more mesh pointing to it\r\n */\r\n public releaseForMesh(mesh: Mesh, shouldDispose?: boolean): void {\r\n const meshes = this._meshes;\r\n const index = meshes.indexOf(mesh);\r\n\r\n if (index === -1) {\r\n return;\r\n }\r\n\r\n meshes.splice(index, 1);\r\n\r\n if (this._vertexArrayObjects) {\r\n mesh._invalidateInstanceVertexArrayObject();\r\n }\r\n\r\n mesh._geometry = null;\r\n\r\n if (meshes.length === 0 && shouldDispose) {\r\n this.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * Apply current geometry to a given mesh\r\n * @param mesh defines the mesh to apply geometry to\r\n */\r\n public applyToMesh(mesh: Mesh): void {\r\n if (mesh._geometry === this) {\r\n return;\r\n }\r\n\r\n const previousGeometry = mesh._geometry;\r\n if (previousGeometry) {\r\n previousGeometry.releaseForMesh(mesh);\r\n }\r\n\r\n if (this._vertexArrayObjects) {\r\n mesh._invalidateInstanceVertexArrayObject();\r\n }\r\n\r\n const meshes = this._meshes;\r\n\r\n // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()\r\n mesh._geometry = this;\r\n mesh._internalAbstractMeshDataInfo._positions = null;\r\n\r\n this._scene.pushGeometry(this);\r\n\r\n meshes.push(mesh);\r\n\r\n if (this.isReady()) {\r\n this._applyToMesh(mesh);\r\n } else if (this._boundingInfo) {\r\n mesh.setBoundingInfo(this._boundingInfo);\r\n }\r\n }\r\n\r\n private _updateExtend(data: Nullable = null) {\r\n if (this.useBoundingInfoFromGeometry && this._boundingInfo) {\r\n this._extend = {\r\n minimum: this._boundingInfo.minimum.clone(),\r\n maximum: this._boundingInfo.maximum.clone(),\r\n };\r\n } else {\r\n if (!data) {\r\n data = this.getVerticesData(VertexBuffer.PositionKind)!;\r\n // This can happen if the buffer comes from a Hardware Buffer where\r\n // The data have not been uploaded by Babylon. (ex: Compute Shaders and Storage Buffers)\r\n if (!data) {\r\n return;\r\n }\r\n }\r\n\r\n this._extend = extractMinAndMax(data, 0, this._totalVertices, this.boundingBias, 3);\r\n }\r\n }\r\n\r\n private _applyToMesh(mesh: Mesh): void {\r\n const numOfMeshes = this._meshes.length;\r\n\r\n // vertexBuffers\r\n for (const kind in this._vertexBuffers) {\r\n if (numOfMeshes === 1) {\r\n this._vertexBuffers[kind].create();\r\n }\r\n\r\n if (kind === VertexBuffer.PositionKind) {\r\n if (!this._extend) {\r\n this._updateExtend();\r\n }\r\n mesh.buildBoundingInfo(this._extend.minimum, this._extend.maximum);\r\n\r\n mesh._createGlobalSubMesh(mesh.isUnIndexed);\r\n\r\n //bounding info was just created again, world matrix should be applied again.\r\n mesh._updateBoundingInfo();\r\n }\r\n }\r\n\r\n // indexBuffer\r\n if (numOfMeshes === 1 && this._indices && this._indices.length > 0) {\r\n this._indexBuffer = this._engine.createIndexBuffer(this._indices, this._updatable);\r\n }\r\n\r\n // morphTargets\r\n mesh._syncGeometryWithMorphTargetManager();\r\n\r\n // instances\r\n mesh.synchronizeInstances();\r\n }\r\n\r\n private _notifyUpdate(kind?: string) {\r\n if (this.onGeometryUpdated) {\r\n this.onGeometryUpdated(this, kind);\r\n }\r\n\r\n if (this._vertexArrayObjects) {\r\n this._disposeVertexArrayObjects();\r\n }\r\n\r\n for (const mesh of this._meshes) {\r\n mesh._markSubMeshesAsAttributesDirty();\r\n }\r\n }\r\n\r\n /**\r\n * Load the geometry if it was flagged as delay loaded\r\n * @param scene defines the hosting scene\r\n * @param onLoaded defines a callback called when the geometry is loaded\r\n */\r\n public load(scene: Scene, onLoaded?: () => void): void {\r\n if (this.delayLoadState === Constants.DELAYLOADSTATE_LOADING) {\r\n return;\r\n }\r\n\r\n if (this.isReady()) {\r\n if (onLoaded) {\r\n onLoaded();\r\n }\r\n return;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADING;\r\n\r\n this._queueLoad(scene, onLoaded);\r\n }\r\n\r\n private _queueLoad(scene: Scene, onLoaded?: () => void): void {\r\n if (!this.delayLoadingFile) {\r\n return;\r\n }\r\n\r\n scene.addPendingData(this);\r\n scene._loadFile(\r\n this.delayLoadingFile,\r\n (data) => {\r\n if (!this._delayLoadingFunction) {\r\n return;\r\n }\r\n\r\n this._delayLoadingFunction(JSON.parse(data as string), this);\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._delayInfo = [];\r\n\r\n scene.removePendingData(this);\r\n\r\n const meshes = this._meshes;\r\n const numOfMeshes = meshes.length;\r\n for (let index = 0; index < numOfMeshes; index++) {\r\n this._applyToMesh(meshes[index]);\r\n }\r\n\r\n if (onLoaded) {\r\n onLoaded();\r\n }\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n\r\n /**\r\n * Invert the geometry to move from a right handed system to a left handed one.\r\n */\r\n public toLeftHanded(): void {\r\n // Flip faces\r\n const tIndices = this.getIndices(false);\r\n if (tIndices != null && tIndices.length > 0) {\r\n for (let i = 0; i < tIndices.length; i += 3) {\r\n const tTemp = tIndices[i + 0];\r\n tIndices[i + 0] = tIndices[i + 2];\r\n tIndices[i + 2] = tTemp;\r\n }\r\n this.setIndices(tIndices);\r\n }\r\n\r\n // Negate position.z\r\n const tPositions = this.getVerticesData(VertexBuffer.PositionKind, false);\r\n if (tPositions != null && tPositions.length > 0) {\r\n for (let i = 0; i < tPositions.length; i += 3) {\r\n tPositions[i + 2] = -tPositions[i + 2];\r\n }\r\n this.setVerticesData(VertexBuffer.PositionKind, tPositions, false);\r\n }\r\n\r\n // Negate normal.z\r\n const tNormals = this.getVerticesData(VertexBuffer.NormalKind, false);\r\n if (tNormals != null && tNormals.length > 0) {\r\n for (let i = 0; i < tNormals.length; i += 3) {\r\n tNormals[i + 2] = -tNormals[i + 2];\r\n }\r\n this.setVerticesData(VertexBuffer.NormalKind, tNormals, false);\r\n }\r\n }\r\n\r\n // Cache\r\n /** @internal */\r\n public _resetPointsArrayCache(): void {\r\n this._positions = null;\r\n }\r\n\r\n /** @internal */\r\n public _generatePointsArray(): boolean {\r\n if (this._positions) {\r\n return true;\r\n }\r\n\r\n const data = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (!data || data.length === 0) {\r\n return false;\r\n }\r\n\r\n for (let index = this._positionsCache.length * 3, arrayIdx = this._positionsCache.length; index < data.length; index += 3, ++arrayIdx) {\r\n this._positionsCache[arrayIdx] = Vector3.FromArray(data, index);\r\n }\r\n\r\n for (let index = 0, arrayIdx = 0; index < data.length; index += 3, ++arrayIdx) {\r\n this._positionsCache[arrayIdx].set(data[0 + index], data[1 + index], data[2 + index]);\r\n }\r\n\r\n // just in case the number of positions was reduced, splice the array\r\n this._positionsCache.length = data.length / 3;\r\n\r\n this._positions = this._positionsCache;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Gets a value indicating if the geometry is disposed\r\n * @returns true if the geometry was disposed\r\n */\r\n public isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n private _disposeVertexArrayObjects(): void {\r\n if (this._vertexArrayObjects) {\r\n for (const kind in this._vertexArrayObjects) {\r\n this._engine.releaseVertexArrayObject(this._vertexArrayObjects[kind]);\r\n }\r\n this._vertexArrayObjects = {}; // Will trigger a rebuild of the VAO if supported\r\n\r\n const meshes = this._meshes;\r\n const numOfMeshes = meshes.length;\r\n for (let index = 0; index < numOfMeshes; index++) {\r\n meshes[index]._invalidateInstanceVertexArrayObject();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Free all associated resources\r\n */\r\n public dispose(): void {\r\n const meshes = this._meshes;\r\n const numOfMeshes = meshes.length;\r\n let index: number;\r\n for (index = 0; index < numOfMeshes; index++) {\r\n this.releaseForMesh(meshes[index]);\r\n }\r\n this._meshes.length = 0;\r\n\r\n this._disposeVertexArrayObjects();\r\n\r\n for (const kind in this._vertexBuffers) {\r\n this._vertexBuffers[kind].dispose();\r\n }\r\n this._vertexBuffers = {};\r\n this._totalVertices = 0;\r\n\r\n if (this._indexBuffer) {\r\n this._engine._releaseBuffer(this._indexBuffer);\r\n }\r\n this._indexBuffer = null;\r\n this._indices = [];\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NONE;\r\n this.delayLoadingFile = null;\r\n this._delayLoadingFunction = null;\r\n this._delayInfo = [];\r\n\r\n this._boundingInfo = null;\r\n\r\n this._scene.removeGeometry(this);\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.geometries.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.geometries.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n this._isDisposed = true;\r\n }\r\n\r\n /**\r\n * Clone the current geometry into a new geometry\r\n * @param id defines the unique ID of the new geometry\r\n * @returns a new geometry object\r\n */\r\n public copy(id: string): Geometry {\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = [];\r\n\r\n const indices = this.getIndices();\r\n if (indices) {\r\n for (let index = 0; index < indices.length; index++) {\r\n (vertexData.indices).push(indices[index]);\r\n }\r\n }\r\n\r\n let updatable = false;\r\n let stopChecking = false;\r\n let kind;\r\n for (kind in this._vertexBuffers) {\r\n // using slice() to make a copy of the array and not just reference it\r\n const data = this.getVerticesData(kind);\r\n\r\n if (data) {\r\n if (data instanceof Float32Array) {\r\n vertexData.set(new Float32Array(data), kind);\r\n } else {\r\n vertexData.set((data).slice(0), kind);\r\n }\r\n if (!stopChecking) {\r\n const vb = this.getVertexBuffer(kind);\r\n\r\n if (vb) {\r\n updatable = vb.isUpdatable();\r\n stopChecking = !updatable;\r\n }\r\n }\r\n }\r\n }\r\n\r\n const geometry = new Geometry(id, this._scene, vertexData, updatable);\r\n\r\n geometry.delayLoadState = this.delayLoadState;\r\n geometry.delayLoadingFile = this.delayLoadingFile;\r\n geometry._delayLoadingFunction = this._delayLoadingFunction;\r\n\r\n for (kind in this._delayInfo) {\r\n geometry._delayInfo = geometry._delayInfo || [];\r\n geometry._delayInfo.push(kind);\r\n }\r\n\r\n // Bounding info\r\n geometry._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);\r\n\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Serialize the current geometry info (and not the vertices data) into a JSON object\r\n * @returns a JSON representation of the current geometry data (without the vertices data)\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.id = this.id;\r\n serializationObject.uniqueId = this.uniqueId;\r\n serializationObject.updatable = this._updatable;\r\n\r\n if (Tags && Tags.HasTags(this)) {\r\n serializationObject.tags = Tags.GetTags(this);\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n private _toNumberArray(origin: Nullable): number[] {\r\n if (Array.isArray(origin)) {\r\n return origin;\r\n } else {\r\n return Array.prototype.slice.call(origin);\r\n }\r\n }\r\n\r\n /**\r\n * Release any memory retained by the cached data on the Geometry.\r\n *\r\n * Call this function to reduce memory footprint of the mesh.\r\n * Vertex buffers will not store CPU data anymore (this will prevent picking, collisions or physics to work correctly)\r\n */\r\n public clearCachedData(): void {\r\n this._indices = [];\r\n this._resetPointsArrayCache();\r\n\r\n for (const vbName in this._vertexBuffers) {\r\n if (!Object.prototype.hasOwnProperty.call(this._vertexBuffers, vbName)) {\r\n continue;\r\n }\r\n this._vertexBuffers[vbName]._buffer._data = null;\r\n }\r\n }\r\n\r\n /**\r\n * Serialize all vertices data into a JSON object\r\n * @returns a JSON representation of the current geometry data\r\n */\r\n public serializeVerticeData(): any {\r\n const serializationObject = this.serialize();\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.PositionKind)) {\r\n serializationObject.positions = this._toNumberArray(this.getVerticesData(VertexBuffer.PositionKind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.PositionKind)) {\r\n serializationObject.positions._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n serializationObject.normals = this._toNumberArray(this.getVerticesData(VertexBuffer.NormalKind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.NormalKind)) {\r\n serializationObject.normals._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.TangentKind)) {\r\n serializationObject.tangents = this._toNumberArray(this.getVerticesData(VertexBuffer.TangentKind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.TangentKind)) {\r\n serializationObject.tangents._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n serializationObject.uvs = this._toNumberArray(this.getVerticesData(VertexBuffer.UVKind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.UVKind)) {\r\n serializationObject.uvs._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\r\n serializationObject.uv2s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV2Kind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.UV2Kind)) {\r\n serializationObject.uv2s._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.UV3Kind)) {\r\n serializationObject.uv3s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV3Kind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.UV3Kind)) {\r\n serializationObject.uv3s._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.UV4Kind)) {\r\n serializationObject.uv4s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV4Kind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.UV4Kind)) {\r\n serializationObject.uv4s._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.UV5Kind)) {\r\n serializationObject.uv5s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV5Kind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.UV5Kind)) {\r\n serializationObject.uv5s._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.UV6Kind)) {\r\n serializationObject.uv6s = this._toNumberArray(this.getVerticesData(VertexBuffer.UV6Kind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.UV6Kind)) {\r\n serializationObject.uv6s._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.ColorKind)) {\r\n serializationObject.colors = this._toNumberArray(this.getVerticesData(VertexBuffer.ColorKind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.ColorKind)) {\r\n serializationObject.colors._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {\r\n serializationObject.matricesIndices = this._toNumberArray(this.getVerticesData(VertexBuffer.MatricesIndicesKind));\r\n serializationObject.matricesIndices._isExpanded = true;\r\n if (this.isVertexBufferUpdatable(VertexBuffer.MatricesIndicesKind)) {\r\n serializationObject.matricesIndices._updatable = true;\r\n }\r\n }\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\r\n serializationObject.matricesWeights = this._toNumberArray(this.getVerticesData(VertexBuffer.MatricesWeightsKind));\r\n if (this.isVertexBufferUpdatable(VertexBuffer.MatricesWeightsKind)) {\r\n serializationObject.matricesWeights._updatable = true;\r\n }\r\n }\r\n\r\n serializationObject.indices = this._toNumberArray(this.getIndices());\r\n\r\n return serializationObject;\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Extracts a clone of a mesh geometry\r\n * @param mesh defines the source mesh\r\n * @param id defines the unique ID of the new geometry object\r\n * @returns the new geometry object\r\n */\r\n public static ExtractFromMesh(mesh: Mesh, id: string): Nullable {\r\n const geometry = mesh._geometry;\r\n\r\n if (!geometry) {\r\n return null;\r\n }\r\n\r\n return geometry.copy(id);\r\n }\r\n\r\n /**\r\n * You should now use Tools.RandomId(), this method is still here for legacy reasons.\r\n * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523\r\n * Be aware Math.random() could cause collisions, but:\r\n * \"All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide\"\r\n * @returns a string containing a new GUID\r\n */\r\n public static RandomId(): string {\r\n return Tools.RandomId();\r\n }\r\n\r\n private static _GetGeometryByLoadedUniqueId(uniqueId: string, scene: Scene) {\r\n for (let index = 0; index < scene.geometries.length; index++) {\r\n if (scene.geometries[index]._loadedUniqueId === uniqueId) {\r\n return scene.geometries[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _ImportGeometry(parsedGeometry: any, mesh: Mesh): void {\r\n const scene = mesh.getScene();\r\n\r\n // Geometry\r\n const geometryUniqueId = parsedGeometry.geometryUniqueId;\r\n const geometryId = parsedGeometry.geometryId;\r\n if (geometryUniqueId || geometryId) {\r\n const geometry = geometryUniqueId ? this._GetGeometryByLoadedUniqueId(geometryUniqueId, scene) : scene.getGeometryById(geometryId);\r\n if (geometry) {\r\n geometry.applyToMesh(mesh);\r\n }\r\n } else if (parsedGeometry instanceof ArrayBuffer) {\r\n const binaryInfo = mesh._binaryInfo;\r\n\r\n if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {\r\n const positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positionsData, false);\r\n }\r\n\r\n if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {\r\n const normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normalsData, false);\r\n }\r\n\r\n if (binaryInfo.tangetsAttrDesc && binaryInfo.tangetsAttrDesc.count > 0) {\r\n const tangentsData = new Float32Array(parsedGeometry, binaryInfo.tangetsAttrDesc.offset, binaryInfo.tangetsAttrDesc.count);\r\n mesh.setVerticesData(VertexBuffer.TangentKind, tangentsData, false);\r\n }\r\n\r\n if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {\r\n const uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n for (let index = 1; index < uvsData.length; index += 2) {\r\n uvsData[index] = 1 - uvsData[index];\r\n }\r\n }\r\n mesh.setVerticesData(VertexBuffer.UVKind, uvsData, false);\r\n }\r\n\r\n if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {\r\n const uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n for (let index = 1; index < uvs2Data.length; index += 2) {\r\n uvs2Data[index] = 1 - uvs2Data[index];\r\n }\r\n }\r\n mesh.setVerticesData(VertexBuffer.UV2Kind, uvs2Data, false);\r\n }\r\n\r\n if (binaryInfo.uvs3AttrDesc && binaryInfo.uvs3AttrDesc.count > 0) {\r\n const uvs3Data = new Float32Array(parsedGeometry, binaryInfo.uvs3AttrDesc.offset, binaryInfo.uvs3AttrDesc.count);\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n for (let index = 1; index < uvs3Data.length; index += 2) {\r\n uvs3Data[index] = 1 - uvs3Data[index];\r\n }\r\n }\r\n mesh.setVerticesData(VertexBuffer.UV3Kind, uvs3Data, false);\r\n }\r\n\r\n if (binaryInfo.uvs4AttrDesc && binaryInfo.uvs4AttrDesc.count > 0) {\r\n const uvs4Data = new Float32Array(parsedGeometry, binaryInfo.uvs4AttrDesc.offset, binaryInfo.uvs4AttrDesc.count);\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n for (let index = 1; index < uvs4Data.length; index += 2) {\r\n uvs4Data[index] = 1 - uvs4Data[index];\r\n }\r\n }\r\n mesh.setVerticesData(VertexBuffer.UV4Kind, uvs4Data, false);\r\n }\r\n\r\n if (binaryInfo.uvs5AttrDesc && binaryInfo.uvs5AttrDesc.count > 0) {\r\n const uvs5Data = new Float32Array(parsedGeometry, binaryInfo.uvs5AttrDesc.offset, binaryInfo.uvs5AttrDesc.count);\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n for (let index = 1; index < uvs5Data.length; index += 2) {\r\n uvs5Data[index] = 1 - uvs5Data[index];\r\n }\r\n }\r\n mesh.setVerticesData(VertexBuffer.UV5Kind, uvs5Data, false);\r\n }\r\n\r\n if (binaryInfo.uvs6AttrDesc && binaryInfo.uvs6AttrDesc.count > 0) {\r\n const uvs6Data = new Float32Array(parsedGeometry, binaryInfo.uvs6AttrDesc.offset, binaryInfo.uvs6AttrDesc.count);\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n for (let index = 1; index < uvs6Data.length; index += 2) {\r\n uvs6Data[index] = 1 - uvs6Data[index];\r\n }\r\n }\r\n mesh.setVerticesData(VertexBuffer.UV6Kind, uvs6Data, false);\r\n }\r\n\r\n if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {\r\n const colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);\r\n mesh.setVerticesData(VertexBuffer.ColorKind, colorsData, false, binaryInfo.colorsAttrDesc.stride);\r\n }\r\n\r\n if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {\r\n const matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);\r\n const floatIndices = [];\r\n for (let i = 0; i < matricesIndicesData.length; i++) {\r\n const index = matricesIndicesData[i];\r\n floatIndices.push(index & 0x000000ff);\r\n floatIndices.push((index & 0x0000ff00) >> 8);\r\n floatIndices.push((index & 0x00ff0000) >> 16);\r\n floatIndices.push((index >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\r\n }\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, false);\r\n }\r\n\r\n if (binaryInfo.matricesIndicesExtraAttrDesc && binaryInfo.matricesIndicesExtraAttrDesc.count > 0) {\r\n const matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesExtraAttrDesc.offset, binaryInfo.matricesIndicesExtraAttrDesc.count);\r\n const floatIndices = [];\r\n for (let i = 0; i < matricesIndicesData.length; i++) {\r\n const index = matricesIndicesData[i];\r\n floatIndices.push(index & 0x000000ff);\r\n floatIndices.push((index & 0x0000ff00) >> 8);\r\n floatIndices.push((index & 0x00ff0000) >> 16);\r\n floatIndices.push((index >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\r\n }\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, false);\r\n }\r\n\r\n if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {\r\n const matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);\r\n mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);\r\n }\r\n\r\n if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {\r\n const indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);\r\n mesh.setIndices(indicesData, null);\r\n }\r\n\r\n if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {\r\n const subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);\r\n\r\n mesh.subMeshes = [];\r\n for (let i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {\r\n const materialIndex = subMeshesData[i * 5 + 0];\r\n const verticesStart = subMeshesData[i * 5 + 1];\r\n const verticesCount = subMeshesData[i * 5 + 2];\r\n const indexStart = subMeshesData[i * 5 + 3];\r\n const indexCount = subMeshesData[i * 5 + 4];\r\n\r\n SubMesh.AddToMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);\r\n }\r\n }\r\n } else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {\r\n mesh.setVerticesData(VertexBuffer.PositionKind, parsedGeometry.positions, parsedGeometry.positions._updatable);\r\n\r\n mesh.setVerticesData(VertexBuffer.NormalKind, parsedGeometry.normals, parsedGeometry.normals._updatable);\r\n\r\n if (parsedGeometry.tangents) {\r\n mesh.setVerticesData(VertexBuffer.TangentKind, parsedGeometry.tangents, parsedGeometry.tangents._updatable);\r\n }\r\n\r\n if (parsedGeometry.uvs) {\r\n mesh.setVerticesData(VertexBuffer.UVKind, parsedGeometry.uvs, parsedGeometry.uvs._updatable);\r\n }\r\n\r\n if (parsedGeometry.uvs2) {\r\n mesh.setVerticesData(VertexBuffer.UV2Kind, parsedGeometry.uvs2, parsedGeometry.uvs2._updatable);\r\n }\r\n\r\n if (parsedGeometry.uvs3) {\r\n mesh.setVerticesData(VertexBuffer.UV3Kind, parsedGeometry.uvs3, parsedGeometry.uvs3._updatable);\r\n }\r\n\r\n if (parsedGeometry.uvs4) {\r\n mesh.setVerticesData(VertexBuffer.UV4Kind, parsedGeometry.uvs4, parsedGeometry.uvs4._updatable);\r\n }\r\n\r\n if (parsedGeometry.uvs5) {\r\n mesh.setVerticesData(VertexBuffer.UV5Kind, parsedGeometry.uvs5, parsedGeometry.uvs5._updatable);\r\n }\r\n\r\n if (parsedGeometry.uvs6) {\r\n mesh.setVerticesData(VertexBuffer.UV6Kind, parsedGeometry.uvs6, parsedGeometry.uvs6._updatable);\r\n }\r\n\r\n if (parsedGeometry.colors) {\r\n mesh.setVerticesData(VertexBuffer.ColorKind, Color4.CheckColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), parsedGeometry.colors._updatable);\r\n }\r\n\r\n if (parsedGeometry.matricesIndices) {\r\n if (!parsedGeometry.matricesIndices._isExpanded) {\r\n const floatIndices = [];\r\n\r\n for (let i = 0; i < parsedGeometry.matricesIndices.length; i++) {\r\n const matricesIndex = parsedGeometry.matricesIndices[i];\r\n\r\n floatIndices.push(matricesIndex & 0x000000ff);\r\n floatIndices.push((matricesIndex & 0x0000ff00) >> 8);\r\n floatIndices.push((matricesIndex & 0x00ff0000) >> 16);\r\n floatIndices.push((matricesIndex >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, parsedGeometry.matricesIndices._updatable);\r\n } else {\r\n delete parsedGeometry.matricesIndices._isExpanded;\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, parsedGeometry.matricesIndices._updatable);\r\n }\r\n }\r\n\r\n if (parsedGeometry.matricesIndicesExtra) {\r\n if (!parsedGeometry.matricesIndicesExtra._isExpanded) {\r\n const floatIndices = [];\r\n\r\n for (let i = 0; i < parsedGeometry.matricesIndicesExtra.length; i++) {\r\n const matricesIndex = parsedGeometry.matricesIndicesExtra[i];\r\n\r\n floatIndices.push(matricesIndex & 0x000000ff);\r\n floatIndices.push((matricesIndex & 0x0000ff00) >> 8);\r\n floatIndices.push((matricesIndex & 0x00ff0000) >> 16);\r\n floatIndices.push((matricesIndex >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, parsedGeometry.matricesIndicesExtra._updatable);\r\n } else {\r\n delete parsedGeometry.matricesIndices._isExpanded;\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, parsedGeometry.matricesIndicesExtra, parsedGeometry.matricesIndicesExtra._updatable);\r\n }\r\n }\r\n\r\n if (parsedGeometry.matricesWeights) {\r\n Geometry._CleanMatricesWeights(parsedGeometry, mesh);\r\n mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);\r\n }\r\n\r\n if (parsedGeometry.matricesWeightsExtra) {\r\n mesh.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);\r\n }\r\n\r\n mesh.setIndices(parsedGeometry.indices, null);\r\n }\r\n\r\n // SubMeshes\r\n if (parsedGeometry.subMeshes) {\r\n mesh.subMeshes = [];\r\n for (let subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {\r\n const parsedSubMesh = parsedGeometry.subMeshes[subIndex];\r\n\r\n SubMesh.AddToMesh(\r\n parsedSubMesh.materialIndex,\r\n parsedSubMesh.verticesStart,\r\n parsedSubMesh.verticesCount,\r\n parsedSubMesh.indexStart,\r\n parsedSubMesh.indexCount,\r\n mesh\r\n );\r\n }\r\n }\r\n\r\n // Flat shading\r\n if (mesh._shouldGenerateFlatShading) {\r\n mesh.convertToFlatShadedMesh();\r\n mesh._shouldGenerateFlatShading = false;\r\n }\r\n\r\n // Update\r\n mesh.computeWorldMatrix(true);\r\n\r\n scene.onMeshImportedObservable.notifyObservers(mesh);\r\n }\r\n\r\n private static _CleanMatricesWeights(parsedGeometry: any, mesh: Mesh): void {\r\n const epsilon: number = 1e-3;\r\n if (!SceneLoaderFlags.CleanBoneMatrixWeights) {\r\n return;\r\n }\r\n let noInfluenceBoneIndex = 0.0;\r\n if (parsedGeometry.skeletonId > -1) {\r\n const skeleton = mesh.getScene().getLastSkeletonById(parsedGeometry.skeletonId);\r\n\r\n if (!skeleton) {\r\n return;\r\n }\r\n noInfluenceBoneIndex = skeleton.bones.length;\r\n } else {\r\n return;\r\n }\r\n const matricesIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);\r\n const matricesIndicesExtra = mesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);\r\n const matricesWeights = parsedGeometry.matricesWeights;\r\n const matricesWeightsExtra = parsedGeometry.matricesWeightsExtra;\r\n const influencers = parsedGeometry.numBoneInfluencer;\r\n const size = matricesWeights.length;\r\n\r\n for (let i = 0; i < size; i += 4) {\r\n let weight = 0.0;\r\n let firstZeroWeight = -1;\r\n for (let j = 0; j < 4; j++) {\r\n const w = matricesWeights[i + j];\r\n weight += w;\r\n if (w < epsilon && firstZeroWeight < 0) {\r\n firstZeroWeight = j;\r\n }\r\n }\r\n if (matricesWeightsExtra) {\r\n for (let j = 0; j < 4; j++) {\r\n const w = matricesWeightsExtra[i + j];\r\n weight += w;\r\n if (w < epsilon && firstZeroWeight < 0) {\r\n firstZeroWeight = j + 4;\r\n }\r\n }\r\n }\r\n if (firstZeroWeight < 0 || firstZeroWeight > influencers - 1) {\r\n firstZeroWeight = influencers - 1;\r\n }\r\n if (weight > epsilon) {\r\n const mweight = 1.0 / weight;\r\n for (let j = 0; j < 4; j++) {\r\n matricesWeights[i + j] *= mweight;\r\n }\r\n if (matricesWeightsExtra) {\r\n for (let j = 0; j < 4; j++) {\r\n matricesWeightsExtra[i + j] *= mweight;\r\n }\r\n }\r\n } else {\r\n if (firstZeroWeight >= 4) {\r\n matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;\r\n matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;\r\n } else {\r\n matricesWeights[i + firstZeroWeight] = 1.0 - weight;\r\n matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;\r\n }\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);\r\n if (parsedGeometry.matricesWeightsExtra) {\r\n mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);\r\n }\r\n }\r\n\r\n /**\r\n * Create a new geometry from persisted data (Using .babylon file format)\r\n * @param parsedVertexData defines the persisted data\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root url to use to load assets (like delayed data)\r\n * @returns the new geometry object\r\n */\r\n public static Parse(parsedVertexData: any, scene: Scene, rootUrl: string): Nullable {\r\n const geometry = new Geometry(parsedVertexData.id, scene, undefined, parsedVertexData.updatable);\r\n geometry._loadedUniqueId = parsedVertexData.uniqueId;\r\n\r\n if (Tags) {\r\n Tags.AddTagsTo(geometry, parsedVertexData.tags);\r\n }\r\n\r\n if (parsedVertexData.delayLoadingFile) {\r\n geometry.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n geometry.delayLoadingFile = rootUrl + parsedVertexData.delayLoadingFile;\r\n geometry._boundingInfo = new BoundingInfo(Vector3.FromArray(parsedVertexData.boundingBoxMinimum), Vector3.FromArray(parsedVertexData.boundingBoxMaximum));\r\n\r\n geometry._delayInfo = [];\r\n if (parsedVertexData.hasUVs) {\r\n geometry._delayInfo.push(VertexBuffer.UVKind);\r\n }\r\n\r\n if (parsedVertexData.hasUVs2) {\r\n geometry._delayInfo.push(VertexBuffer.UV2Kind);\r\n }\r\n\r\n if (parsedVertexData.hasUVs3) {\r\n geometry._delayInfo.push(VertexBuffer.UV3Kind);\r\n }\r\n\r\n if (parsedVertexData.hasUVs4) {\r\n geometry._delayInfo.push(VertexBuffer.UV4Kind);\r\n }\r\n\r\n if (parsedVertexData.hasUVs5) {\r\n geometry._delayInfo.push(VertexBuffer.UV5Kind);\r\n }\r\n\r\n if (parsedVertexData.hasUVs6) {\r\n geometry._delayInfo.push(VertexBuffer.UV6Kind);\r\n }\r\n\r\n if (parsedVertexData.hasColors) {\r\n geometry._delayInfo.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n if (parsedVertexData.hasMatricesIndices) {\r\n geometry._delayInfo.push(VertexBuffer.MatricesIndicesKind);\r\n }\r\n\r\n if (parsedVertexData.hasMatricesWeights) {\r\n geometry._delayInfo.push(VertexBuffer.MatricesWeightsKind);\r\n }\r\n\r\n geometry._delayLoadingFunction = VertexData.ImportVertexData;\r\n } else {\r\n VertexData.ImportVertexData(parsedVertexData, geometry);\r\n }\r\n\r\n scene.pushGeometry(geometry, true);\r\n\r\n return geometry;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { PrecisionDate } from \"./precisionDate\";\r\n\r\n/**\r\n * Performance monitor tracks rolling average frame-time and frame-time variance over a user defined sliding-window\r\n */\r\nexport class PerformanceMonitor {\r\n private _enabled: boolean = true;\r\n private _rollingFrameTime: RollingAverage;\r\n private _lastFrameTimeMs: Nullable;\r\n\r\n /**\r\n * constructor\r\n * @param frameSampleSize The number of samples required to saturate the sliding window\r\n */\r\n constructor(frameSampleSize: number = 30) {\r\n this._rollingFrameTime = new RollingAverage(frameSampleSize);\r\n }\r\n\r\n /**\r\n * Samples current frame\r\n * @param timeMs A timestamp in milliseconds of the current frame to compare with other frames\r\n */\r\n public sampleFrame(timeMs: number = PrecisionDate.Now) {\r\n if (!this._enabled) {\r\n return;\r\n }\r\n\r\n if (this._lastFrameTimeMs != null) {\r\n const dt = timeMs - this._lastFrameTimeMs;\r\n this._rollingFrameTime.add(dt);\r\n }\r\n\r\n this._lastFrameTimeMs = timeMs;\r\n }\r\n\r\n /**\r\n * Returns the average frame time in milliseconds over the sliding window (or the subset of frames sampled so far)\r\n */\r\n public get averageFrameTime(): number {\r\n return this._rollingFrameTime.average;\r\n }\r\n\r\n /**\r\n * Returns the variance frame time in milliseconds over the sliding window (or the subset of frames sampled so far)\r\n */\r\n public get averageFrameTimeVariance(): number {\r\n return this._rollingFrameTime.variance;\r\n }\r\n\r\n /**\r\n * Returns the frame time of the most recent frame\r\n */\r\n public get instantaneousFrameTime(): number {\r\n return this._rollingFrameTime.history(0);\r\n }\r\n\r\n /**\r\n * Returns the average framerate in frames per second over the sliding window (or the subset of frames sampled so far)\r\n */\r\n public get averageFPS(): number {\r\n return 1000.0 / this._rollingFrameTime.average;\r\n }\r\n\r\n /**\r\n * Returns the average framerate in frames per second using the most recent frame time\r\n */\r\n public get instantaneousFPS(): number {\r\n const history = this._rollingFrameTime.history(0);\r\n\r\n if (history === 0) {\r\n return 0;\r\n }\r\n\r\n return 1000.0 / history;\r\n }\r\n\r\n /**\r\n * Returns true if enough samples have been taken to completely fill the sliding window\r\n */\r\n public get isSaturated(): boolean {\r\n return this._rollingFrameTime.isSaturated();\r\n }\r\n\r\n /**\r\n * Enables contributions to the sliding window sample set\r\n */\r\n public enable() {\r\n this._enabled = true;\r\n }\r\n\r\n /**\r\n * Disables contributions to the sliding window sample set\r\n * Samples will not be interpolated over the disabled period\r\n */\r\n public disable() {\r\n this._enabled = false;\r\n //clear last sample to avoid interpolating over the disabled period when next enabled\r\n this._lastFrameTimeMs = null;\r\n }\r\n\r\n /**\r\n * Returns true if sampling is enabled\r\n */\r\n public get isEnabled(): boolean {\r\n return this._enabled;\r\n }\r\n\r\n /**\r\n * Resets performance monitor\r\n */\r\n public reset() {\r\n //clear last sample to avoid interpolating over the disabled period when next enabled\r\n this._lastFrameTimeMs = null;\r\n //wipe record\r\n this._rollingFrameTime.reset();\r\n }\r\n}\r\n\r\n/**\r\n * RollingAverage\r\n *\r\n * Utility to efficiently compute the rolling average and variance over a sliding window of samples\r\n */\r\nexport class RollingAverage {\r\n /**\r\n * Current average\r\n */\r\n public average: number;\r\n /**\r\n * Current variance\r\n */\r\n public variance: number;\r\n\r\n protected _samples: Array;\r\n protected _sampleCount: number;\r\n protected _pos: number;\r\n protected _m2: number; //sum of squares of differences from the (current) mean\r\n\r\n /**\r\n * constructor\r\n * @param length The number of samples required to saturate the sliding window\r\n */\r\n constructor(length: number) {\r\n this._samples = new Array(length);\r\n this.reset();\r\n }\r\n\r\n /**\r\n * Adds a sample to the sample set\r\n * @param v The sample value\r\n */\r\n public add(v: number) {\r\n //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance\r\n let delta: number;\r\n\r\n //we need to check if we've already wrapped round\r\n if (this.isSaturated()) {\r\n //remove bottom of stack from mean\r\n const bottomValue = this._samples[this._pos];\r\n delta = bottomValue - this.average;\r\n this.average -= delta / (this._sampleCount - 1);\r\n this._m2 -= delta * (bottomValue - this.average);\r\n } else {\r\n this._sampleCount++;\r\n }\r\n\r\n //add new value to mean\r\n delta = v - this.average;\r\n this.average += delta / this._sampleCount;\r\n this._m2 += delta * (v - this.average);\r\n\r\n //set the new variance\r\n this.variance = this._m2 / (this._sampleCount - 1);\r\n\r\n this._samples[this._pos] = v;\r\n this._pos++;\r\n\r\n this._pos %= this._samples.length; //positive wrap around\r\n }\r\n\r\n /**\r\n * Returns previously added values or null if outside of history or outside the sliding window domain\r\n * @param i Index in history. For example, pass 0 for the most recent value and 1 for the value before that\r\n * @returns Value previously recorded with add() or null if outside of range\r\n */\r\n public history(i: number): number {\r\n if (i >= this._sampleCount || i >= this._samples.length) {\r\n return 0;\r\n }\r\n\r\n const i0 = this._wrapPosition(this._pos - 1.0);\r\n return this._samples[this._wrapPosition(i0 - i)];\r\n }\r\n\r\n /**\r\n * Returns true if enough samples have been taken to completely fill the sliding window\r\n * @returns true if sample-set saturated\r\n */\r\n public isSaturated(): boolean {\r\n return this._sampleCount >= this._samples.length;\r\n }\r\n\r\n /**\r\n * Resets the rolling average (equivalent to 0 samples taken so far)\r\n */\r\n public reset() {\r\n this.average = 0;\r\n this.variance = 0;\r\n this._sampleCount = 0;\r\n this._pos = 0;\r\n this._m2 = 0;\r\n }\r\n\r\n /**\r\n * Wraps a value around the sample range boundaries\r\n * @param i Position in sample range, for example if the sample length is 5, and i is -3, then 2 will be returned.\r\n * @returns Wrapped position in sample range\r\n */\r\n protected _wrapPosition(i: number): number {\r\n const max = this._samples.length;\r\n return ((i % max) + max) % max;\r\n }\r\n}\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { Constants } from \"../constants\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Sets alpha constants used by some alpha blending modes\r\n * @param r defines the red component\r\n * @param g defines the green component\r\n * @param b defines the blue component\r\n * @param a defines the alpha component\r\n */\r\n setAlphaConstants(r: number, g: number, b: number, a: number): void;\r\n\r\n /**\r\n * Sets the current alpha mode\r\n * @param mode defines the mode to use (one of the Engine.ALPHA_XXX)\r\n * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering\r\n */\r\n setAlphaMode(mode: number, noDepthWriteChange?: boolean): void;\r\n\r\n /**\r\n * Gets the current alpha mode\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering\r\n * @returns the current alpha mode\r\n */\r\n getAlphaMode(): number;\r\n\r\n /**\r\n * Sets the current alpha equation\r\n * @param equation defines the equation to use (one of the Engine.ALPHA_EQUATION_XXX)\r\n */\r\n setAlphaEquation(equation: number): void;\r\n\r\n /**\r\n * Gets the current alpha equation.\r\n * @returns the current alpha equation\r\n */\r\n getAlphaEquation(): number;\r\n }\r\n}\r\n\r\nThinEngine.prototype.setAlphaConstants = function (r: number, g: number, b: number, a: number) {\r\n this._alphaState.setAlphaBlendConstants(r, g, b, a);\r\n};\r\n\r\nThinEngine.prototype.setAlphaMode = function (mode: number, noDepthWriteChange: boolean = false): void {\r\n if (this._alphaMode === mode) {\r\n if (!noDepthWriteChange) {\r\n // Make sure we still have the correct depth mask according to the alpha mode (a transparent material could have forced writting to the depth buffer, for instance)\r\n const depthMask = mode === Constants.ALPHA_DISABLE;\r\n if (this.depthCullingState.depthMask !== depthMask) {\r\n this.depthCullingState.depthMask = depthMask;\r\n }\r\n }\r\n return;\r\n }\r\n\r\n switch (mode) {\r\n case Constants.ALPHA_DISABLE:\r\n this._alphaState.alphaBlend = false;\r\n break;\r\n case Constants.ALPHA_PREMULTIPLIED:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_PREMULTIPLIED_PORTERDUFF:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_COMBINE:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_ONEONE:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ZERO, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_ADD:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_SUBTRACT:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_MULTIPLY:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR, this._gl.ZERO, this._gl.ONE, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_MAXIMIZED:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_INTERPOLATE:\r\n this._alphaState.setAlphaBlendFunctionParameters(\r\n this._gl.CONSTANT_COLOR,\r\n this._gl.ONE_MINUS_CONSTANT_COLOR,\r\n this._gl.CONSTANT_ALPHA,\r\n this._gl.ONE_MINUS_CONSTANT_ALPHA\r\n );\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_SCREENMODE:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_ONEONE_ONEONE:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ONE, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_ALPHATOCOLOR:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_ALPHA, this._gl.ONE, this._gl.ZERO, this._gl.ZERO);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_REVERSEONEMINUS:\r\n this._alphaState.setAlphaBlendFunctionParameters(\r\n this._gl.ONE_MINUS_DST_COLOR,\r\n this._gl.ONE_MINUS_SRC_COLOR,\r\n this._gl.ONE_MINUS_DST_ALPHA,\r\n this._gl.ONE_MINUS_SRC_ALPHA\r\n );\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_SRC_DSTONEMINUSSRCALPHA:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_ONEONE_ONEZERO:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ONE, this._gl.ZERO);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_EXCLUSION:\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE_MINUS_DST_COLOR, this._gl.ONE_MINUS_SRC_COLOR, this._gl.ZERO, this._gl.ONE);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n case Constants.ALPHA_LAYER_ACCUMULATE:\r\n // Same as ALPHA_COMBINE but accumulates (1 - alpha) values in the alpha channel for a later readout in order independant transparency\r\n this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);\r\n this._alphaState.alphaBlend = true;\r\n break;\r\n }\r\n if (!noDepthWriteChange) {\r\n this.depthCullingState.depthMask = mode === Constants.ALPHA_DISABLE;\r\n }\r\n this._alphaMode = mode;\r\n};\r\n\r\nThinEngine.prototype.getAlphaMode = function (): number {\r\n return this._alphaMode;\r\n};\r\n\r\nThinEngine.prototype.setAlphaEquation = function (equation: number): void {\r\n if (this._alphaEquation === equation) {\r\n return;\r\n }\r\n\r\n switch (equation) {\r\n case Constants.ALPHA_EQUATION_ADD:\r\n this._alphaState.setAlphaEquationParameters(Constants.GL_ALPHA_EQUATION_ADD, Constants.GL_ALPHA_EQUATION_ADD);\r\n break;\r\n case Constants.ALPHA_EQUATION_SUBSTRACT:\r\n this._alphaState.setAlphaEquationParameters(Constants.GL_ALPHA_EQUATION_SUBTRACT, Constants.GL_ALPHA_EQUATION_SUBTRACT);\r\n break;\r\n case Constants.ALPHA_EQUATION_REVERSE_SUBTRACT:\r\n this._alphaState.setAlphaEquationParameters(Constants.GL_ALPHA_EQUATION_REVERSE_SUBTRACT, Constants.GL_ALPHA_EQUATION_REVERSE_SUBTRACT);\r\n break;\r\n case Constants.ALPHA_EQUATION_MAX:\r\n this._alphaState.setAlphaEquationParameters(Constants.GL_ALPHA_EQUATION_MAX, Constants.GL_ALPHA_EQUATION_MAX);\r\n break;\r\n case Constants.ALPHA_EQUATION_MIN:\r\n this._alphaState.setAlphaEquationParameters(Constants.GL_ALPHA_EQUATION_MIN, Constants.GL_ALPHA_EQUATION_MIN);\r\n break;\r\n case Constants.ALPHA_EQUATION_DARKEN:\r\n this._alphaState.setAlphaEquationParameters(Constants.GL_ALPHA_EQUATION_MIN, Constants.GL_ALPHA_EQUATION_ADD);\r\n break;\r\n }\r\n this._alphaEquation = equation;\r\n};\r\n\r\nThinEngine.prototype.getAlphaEquation = function () {\r\n return this._alphaEquation;\r\n};\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../constants\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /** @internal */\r\n _readTexturePixels(\r\n texture: InternalTexture,\r\n width: number,\r\n height: number,\r\n faceIndex?: number,\r\n level?: number,\r\n buffer?: Nullable,\r\n flushRenderer?: boolean,\r\n noDataConversion?: boolean,\r\n x?: number,\r\n y?: number\r\n ): Promise;\r\n\r\n /** @internal */\r\n _readTexturePixelsSync(\r\n texture: InternalTexture,\r\n width: number,\r\n height: number,\r\n faceIndex?: number,\r\n level?: number,\r\n buffer?: Nullable,\r\n flushRenderer?: boolean,\r\n noDataConversion?: boolean,\r\n x?: number,\r\n y?: number\r\n ): ArrayBufferView;\r\n }\r\n}\r\n\r\n/**\r\n * Allocate a typed array depending on a texture type. Optionally can copy existing data in the buffer.\r\n * @param type type of the texture\r\n * @param sizeOrDstBuffer size of the array OR an existing buffer that will be used as the destination of the copy (if copyBuffer is provided)\r\n * @param sizeInBytes true if the size of the array is given in bytes, false if it is the number of elements of the array\r\n * @param copyBuffer if provided, buffer to copy into the destination buffer (either a newly allocated buffer if sizeOrDstBuffer is a number or use sizeOrDstBuffer as the destination buffer otherwise)\r\n * @returns the allocated buffer or sizeOrDstBuffer if the latter is an ArrayBuffer\r\n */\r\nexport function allocateAndCopyTypedBuffer(type: number, sizeOrDstBuffer: number | ArrayBuffer, sizeInBytes = false, copyBuffer?: ArrayBuffer): ArrayBufferView {\r\n switch (type) {\r\n case Constants.TEXTURETYPE_BYTE: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Int8Array(sizeOrDstBuffer) : new Int8Array(sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Int8Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_BYTE: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint8Array(sizeOrDstBuffer) : new Uint8Array(sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Uint8Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n case Constants.TEXTURETYPE_SHORT: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Int16Array(sizeOrDstBuffer) : new Int16Array(sizeInBytes ? sizeOrDstBuffer / 2 : sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Int16Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT:\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:\r\n case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:\r\n case Constants.TEXTURETYPE_HALF_FLOAT: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint16Array(sizeOrDstBuffer) : new Uint16Array(sizeInBytes ? sizeOrDstBuffer / 2 : sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Uint16Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n case Constants.TEXTURETYPE_INT: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Int32Array(sizeOrDstBuffer) : new Int32Array(sizeInBytes ? sizeOrDstBuffer / 4 : sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Int32Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n case Constants.TEXTURETYPE_UNSIGNED_INTEGER:\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV:\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_24_8:\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV:\r\n case Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV:\r\n case Constants.TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint32Array(sizeOrDstBuffer) : new Uint32Array(sizeInBytes ? sizeOrDstBuffer / 4 : sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Uint32Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n case Constants.TEXTURETYPE_FLOAT: {\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Float32Array(sizeOrDstBuffer) : new Float32Array(sizeInBytes ? sizeOrDstBuffer / 4 : sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Float32Array(copyBuffer));\r\n }\r\n return buffer;\r\n }\r\n }\r\n\r\n const buffer = sizeOrDstBuffer instanceof ArrayBuffer ? new Uint8Array(sizeOrDstBuffer) : new Uint8Array(sizeOrDstBuffer);\r\n if (copyBuffer) {\r\n buffer.set(new Uint8Array(copyBuffer));\r\n }\r\n return buffer;\r\n}\r\n\r\nThinEngine.prototype._readTexturePixelsSync = function (\r\n texture: InternalTexture,\r\n width: number,\r\n height: number,\r\n faceIndex = -1,\r\n level = 0,\r\n buffer: Nullable = null,\r\n flushRenderer = true,\r\n noDataConversion = false,\r\n x = 0,\r\n y = 0\r\n): ArrayBufferView {\r\n const gl = this._gl;\r\n if (!gl) {\r\n throw new Error(\"Engine does not have gl rendering context.\");\r\n }\r\n if (!this._dummyFramebuffer) {\r\n const dummy = gl.createFramebuffer();\r\n\r\n if (!dummy) {\r\n throw new Error(\"Unable to create dummy framebuffer\");\r\n }\r\n\r\n this._dummyFramebuffer = dummy;\r\n }\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._dummyFramebuffer);\r\n\r\n if (faceIndex > -1) {\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, texture._hardwareTexture?.underlyingResource, level);\r\n } else {\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture._hardwareTexture?.underlyingResource, level);\r\n }\r\n\r\n let readType = texture.type !== undefined ? this._getWebGLTextureType(texture.type) : gl.UNSIGNED_BYTE;\r\n\r\n if (!noDataConversion) {\r\n switch (readType) {\r\n case gl.UNSIGNED_BYTE:\r\n if (!buffer) {\r\n buffer = new Uint8Array(4 * width * height);\r\n }\r\n readType = gl.UNSIGNED_BYTE;\r\n break;\r\n default:\r\n if (!buffer) {\r\n buffer = new Float32Array(4 * width * height);\r\n }\r\n readType = gl.FLOAT;\r\n break;\r\n }\r\n } else if (!buffer) {\r\n buffer = allocateAndCopyTypedBuffer(texture.type, 4 * width * height);\r\n }\r\n\r\n if (flushRenderer) {\r\n this.flushFramebuffer();\r\n }\r\n\r\n gl.readPixels(x, y, width, height, gl.RGBA, readType, buffer);\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._currentFramebuffer);\r\n\r\n return buffer;\r\n};\r\n\r\nThinEngine.prototype._readTexturePixels = function (\r\n texture: InternalTexture,\r\n width: number,\r\n height: number,\r\n faceIndex = -1,\r\n level = 0,\r\n buffer: Nullable = null,\r\n flushRenderer = true,\r\n noDataConversion = false,\r\n x = 0,\r\n y = 0\r\n): Promise {\r\n return Promise.resolve(this._readTexturePixelsSync(texture, width, height, faceIndex, level, buffer, flushRenderer, noDataConversion, x, y));\r\n};\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { DataBuffer } from \"../../Buffers/dataBuffer\";\r\nimport type { IndicesArray, DataArray } from \"../../types\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Update a dynamic index buffer\r\n * @param indexBuffer defines the target index buffer\r\n * @param indices defines the data to update\r\n * @param offset defines the offset in the target index buffer where update should start\r\n */\r\n updateDynamicIndexBuffer(indexBuffer: DataBuffer, indices: IndicesArray, offset?: number): void;\r\n\r\n /**\r\n * Updates a dynamic vertex buffer.\r\n * @param vertexBuffer the vertex buffer to update\r\n * @param data the data used to update the vertex buffer\r\n * @param byteOffset the byte offset of the data\r\n * @param byteLength the byte length of the data\r\n */\r\n updateDynamicVertexBuffer(vertexBuffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nThinEngine.prototype.updateDynamicIndexBuffer = function (this: ThinEngine, indexBuffer: DataBuffer, indices: IndicesArray, offset: number = 0): void {\r\n // Force cache update\r\n this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER] = null;\r\n this.bindIndexBuffer(indexBuffer);\r\n\r\n let view: ArrayBufferView;\r\n if (indexBuffer.is32Bits) {\r\n // anything else than Uint32Array needs to be converted to Uint32Array\r\n view = indices instanceof Uint32Array ? indices : new Uint32Array(indices);\r\n } else {\r\n // anything else than Uint16Array needs to be converted to Uint16Array\r\n view = indices instanceof Uint16Array ? indices : new Uint16Array(indices);\r\n }\r\n\r\n this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, view, this._gl.DYNAMIC_DRAW);\r\n\r\n this._resetIndexBufferBinding();\r\n};\r\n\r\nThinEngine.prototype.updateDynamicVertexBuffer = function (this: ThinEngine, vertexBuffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void {\r\n this.bindArrayBuffer(vertexBuffer);\r\n\r\n if (byteOffset === undefined) {\r\n byteOffset = 0;\r\n }\r\n\r\n const dataLength = (data as ArrayBuffer).byteLength || (data as number[]).length;\r\n\r\n if (byteLength === undefined || (byteLength >= dataLength && byteOffset === 0)) {\r\n if (data instanceof Array) {\r\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, new Float32Array(data));\r\n } else {\r\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, data);\r\n }\r\n } else {\r\n if (data instanceof Array) {\r\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(data).subarray(byteOffset, byteOffset + byteLength));\r\n } else {\r\n if (data instanceof ArrayBuffer) {\r\n data = new Uint8Array(data, byteOffset, byteLength);\r\n } else {\r\n data = new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);\r\n }\r\n\r\n this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);\r\n }\r\n }\r\n\r\n this._resetVertexBufferBinding();\r\n};\r\n","import { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport type { IOfflineProvider } from \"../Offline/IOfflineProvider\";\r\nimport type { ILoadingScreen } from \"../Loading/loadingScreen\";\r\nimport { IsDocumentAvailable, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { EngineStore } from \"./engineStore\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { WebGLPipelineContext } from \"./WebGL/webGLPipelineContext\";\r\nimport type { IPipelineContext } from \"./IPipelineContext\";\r\nimport type { ICustomAnimationFrameRequester } from \"../Misc/customAnimationFrameRequester\";\r\nimport type { EngineOptions } from \"./thinEngine\";\r\nimport { ThinEngine } from \"./thinEngine\";\r\nimport { Constants } from \"./constants\";\r\nimport type { IViewportLike, IColor4Like } from \"../Maths/math.like\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PerformanceMonitor } from \"../Misc/performanceMonitor\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { PerfCounter } from \"../Misc/perfCounter\";\r\nimport { WebGLDataBuffer } from \"../Meshes/WebGL/webGLDataBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { RenderTargetWrapper } from \"./renderTargetWrapper\";\r\nimport { WebGLHardwareTexture } from \"./WebGL/webGLHardwareTexture\";\r\n\r\nimport \"./Extensions/engine.alpha\";\r\nimport \"./Extensions/engine.readTexture\";\r\nimport \"./Extensions/engine.dynamicBuffer\";\r\nimport type { IAudioEngine } from \"../Audio/Interfaces/IAudioEngine\";\r\n\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { PostProcess } from \"../PostProcesses/postProcess\";\r\n\r\n/**\r\n * Defines the interface used by display changed events\r\n */\r\nexport interface IDisplayChangedEventArgs {\r\n /** Gets the vrDisplay object (if any) */\r\n vrDisplay: Nullable;\r\n /** Gets a boolean indicating if webVR is supported */\r\n vrSupported: boolean;\r\n}\r\n\r\n/**\r\n * Defines the interface used by objects containing a viewport (like a camera)\r\n */\r\ninterface IViewportOwnerLike {\r\n /**\r\n * Gets or sets the viewport\r\n */\r\n viewport: IViewportLike;\r\n}\r\n\r\n/**\r\n * The engine class is responsible for interfacing with all lower-level APIs such as WebGL and Audio\r\n */\r\nexport class Engine extends ThinEngine {\r\n // Const statics\r\n\r\n /** Defines that alpha blending is disabled */\r\n public static readonly ALPHA_DISABLE = Constants.ALPHA_DISABLE;\r\n /** Defines that alpha blending to SRC ALPHA * SRC + DEST */\r\n public static readonly ALPHA_ADD = Constants.ALPHA_ADD;\r\n /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */\r\n public static readonly ALPHA_COMBINE = Constants.ALPHA_COMBINE;\r\n /** Defines that alpha blending to DEST - SRC * DEST */\r\n public static readonly ALPHA_SUBTRACT = Constants.ALPHA_SUBTRACT;\r\n /** Defines that alpha blending to SRC * DEST */\r\n public static readonly ALPHA_MULTIPLY = Constants.ALPHA_MULTIPLY;\r\n /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC) * DEST */\r\n public static readonly ALPHA_MAXIMIZED = Constants.ALPHA_MAXIMIZED;\r\n /** Defines that alpha blending to SRC + DEST */\r\n public static readonly ALPHA_ONEONE = Constants.ALPHA_ONEONE;\r\n /** Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST */\r\n public static readonly ALPHA_PREMULTIPLIED = Constants.ALPHA_PREMULTIPLIED;\r\n /**\r\n * Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST\r\n * Alpha will be set to (1 - SRC ALPHA) * DEST ALPHA\r\n */\r\n public static readonly ALPHA_PREMULTIPLIED_PORTERDUFF = Constants.ALPHA_PREMULTIPLIED_PORTERDUFF;\r\n /** Defines that alpha blending to CST * SRC + (1 - CST) * DEST */\r\n public static readonly ALPHA_INTERPOLATE = Constants.ALPHA_INTERPOLATE;\r\n /**\r\n * Defines that alpha blending to SRC + (1 - SRC) * DEST\r\n * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DEST ALPHA\r\n */\r\n public static readonly ALPHA_SCREENMODE = Constants.ALPHA_SCREENMODE;\r\n\r\n /** Defines that the resource is not delayed*/\r\n public static readonly DELAYLOADSTATE_NONE = Constants.DELAYLOADSTATE_NONE;\r\n /** Defines that the resource was successfully delay loaded */\r\n public static readonly DELAYLOADSTATE_LOADED = Constants.DELAYLOADSTATE_LOADED;\r\n /** Defines that the resource is currently delay loading */\r\n public static readonly DELAYLOADSTATE_LOADING = Constants.DELAYLOADSTATE_LOADING;\r\n /** Defines that the resource is delayed and has not started loading */\r\n public static readonly DELAYLOADSTATE_NOTLOADED = Constants.DELAYLOADSTATE_NOTLOADED;\r\n\r\n // Depht or Stencil test Constants.\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn */\r\n public static readonly NEVER = Constants.NEVER;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */\r\n public static readonly ALWAYS = Constants.ALWAYS;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value */\r\n public static readonly LESS = Constants.LESS;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value */\r\n public static readonly EQUAL = Constants.EQUAL;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value */\r\n public static readonly LEQUAL = Constants.LEQUAL;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value */\r\n public static readonly GREATER = Constants.GREATER;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value */\r\n public static readonly GEQUAL = Constants.GEQUAL;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value */\r\n public static readonly NOTEQUAL = Constants.NOTEQUAL;\r\n\r\n // Stencil Actions Constants.\r\n /** Passed to stencilOperation to specify that stencil value must be kept */\r\n public static readonly KEEP = Constants.KEEP;\r\n /** Passed to stencilOperation to specify that stencil value must be replaced */\r\n public static readonly REPLACE = Constants.REPLACE;\r\n /** Passed to stencilOperation to specify that stencil value must be incremented */\r\n public static readonly INCR = Constants.INCR;\r\n /** Passed to stencilOperation to specify that stencil value must be decremented */\r\n public static readonly DECR = Constants.DECR;\r\n /** Passed to stencilOperation to specify that stencil value must be inverted */\r\n public static readonly INVERT = Constants.INVERT;\r\n /** Passed to stencilOperation to specify that stencil value must be incremented with wrapping */\r\n public static readonly INCR_WRAP = Constants.INCR_WRAP;\r\n /** Passed to stencilOperation to specify that stencil value must be decremented with wrapping */\r\n public static readonly DECR_WRAP = Constants.DECR_WRAP;\r\n\r\n /** Texture is not repeating outside of 0..1 UVs */\r\n public static readonly TEXTURE_CLAMP_ADDRESSMODE = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n /** Texture is repeating outside of 0..1 UVs */\r\n public static readonly TEXTURE_WRAP_ADDRESSMODE = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n /** Texture is repeating and mirrored */\r\n public static readonly TEXTURE_MIRROR_ADDRESSMODE = Constants.TEXTURE_MIRROR_ADDRESSMODE;\r\n\r\n /** ALPHA */\r\n public static readonly TEXTUREFORMAT_ALPHA = Constants.TEXTUREFORMAT_ALPHA;\r\n /** LUMINANCE */\r\n public static readonly TEXTUREFORMAT_LUMINANCE = Constants.TEXTUREFORMAT_LUMINANCE;\r\n /** LUMINANCE_ALPHA */\r\n public static readonly TEXTUREFORMAT_LUMINANCE_ALPHA = Constants.TEXTUREFORMAT_LUMINANCE_ALPHA;\r\n /** RGB */\r\n public static readonly TEXTUREFORMAT_RGB = Constants.TEXTUREFORMAT_RGB;\r\n /** RGBA */\r\n public static readonly TEXTUREFORMAT_RGBA = Constants.TEXTUREFORMAT_RGBA;\r\n /** RED */\r\n public static readonly TEXTUREFORMAT_RED = Constants.TEXTUREFORMAT_RED;\r\n /** RED (2nd reference) */\r\n public static readonly TEXTUREFORMAT_R = Constants.TEXTUREFORMAT_R;\r\n /** RG */\r\n public static readonly TEXTUREFORMAT_RG = Constants.TEXTUREFORMAT_RG;\r\n /** RED_INTEGER */\r\n public static readonly TEXTUREFORMAT_RED_INTEGER = Constants.TEXTUREFORMAT_RED_INTEGER;\r\n /** RED_INTEGER (2nd reference) */\r\n public static readonly TEXTUREFORMAT_R_INTEGER = Constants.TEXTUREFORMAT_R_INTEGER;\r\n /** RG_INTEGER */\r\n public static readonly TEXTUREFORMAT_RG_INTEGER = Constants.TEXTUREFORMAT_RG_INTEGER;\r\n /** RGB_INTEGER */\r\n public static readonly TEXTUREFORMAT_RGB_INTEGER = Constants.TEXTUREFORMAT_RGB_INTEGER;\r\n /** RGBA_INTEGER */\r\n public static readonly TEXTUREFORMAT_RGBA_INTEGER = Constants.TEXTUREFORMAT_RGBA_INTEGER;\r\n\r\n /** UNSIGNED_BYTE */\r\n public static readonly TEXTURETYPE_UNSIGNED_BYTE = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n /** UNSIGNED_BYTE (2nd reference) */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n /** FLOAT */\r\n public static readonly TEXTURETYPE_FLOAT = Constants.TEXTURETYPE_FLOAT;\r\n /** HALF_FLOAT */\r\n public static readonly TEXTURETYPE_HALF_FLOAT = Constants.TEXTURETYPE_HALF_FLOAT;\r\n /** BYTE */\r\n public static readonly TEXTURETYPE_BYTE = Constants.TEXTURETYPE_BYTE;\r\n /** SHORT */\r\n public static readonly TEXTURETYPE_SHORT = Constants.TEXTURETYPE_SHORT;\r\n /** UNSIGNED_SHORT */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT = Constants.TEXTURETYPE_UNSIGNED_SHORT;\r\n /** INT */\r\n public static readonly TEXTURETYPE_INT = Constants.TEXTURETYPE_INT;\r\n /** UNSIGNED_INT */\r\n public static readonly TEXTURETYPE_UNSIGNED_INTEGER = Constants.TEXTURETYPE_UNSIGNED_INTEGER;\r\n /** UNSIGNED_SHORT_4_4_4_4 */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4 = Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4;\r\n /** UNSIGNED_SHORT_5_5_5_1 */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1 = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1;\r\n /** UNSIGNED_SHORT_5_6_5 */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT_5_6_5 = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n /** UNSIGNED_INT_2_10_10_10_REV */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV = Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV;\r\n /** UNSIGNED_INT_24_8 */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_24_8 = Constants.TEXTURETYPE_UNSIGNED_INT_24_8;\r\n /** UNSIGNED_INT_10F_11F_11F_REV */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV = Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV;\r\n /** UNSIGNED_INT_5_9_9_9_REV */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV = Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV;\r\n /** FLOAT_32_UNSIGNED_INT_24_8_REV */\r\n public static readonly TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV = Constants.TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV;\r\n\r\n /** nearest is mag = nearest and min = nearest and mip = none */\r\n public static readonly TEXTURE_NEAREST_SAMPLINGMODE = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n /** Bilinear is mag = linear and min = linear and mip = nearest */\r\n public static readonly TEXTURE_BILINEAR_SAMPLINGMODE = Constants.TEXTURE_BILINEAR_SAMPLINGMODE;\r\n /** Trilinear is mag = linear and min = linear and mip = linear */\r\n public static readonly TEXTURE_TRILINEAR_SAMPLINGMODE = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;\r\n /** nearest is mag = nearest and min = nearest and mip = linear */\r\n public static readonly TEXTURE_NEAREST_NEAREST_MIPLINEAR = Constants.TEXTURE_NEAREST_NEAREST_MIPLINEAR;\r\n /** Bilinear is mag = linear and min = linear and mip = nearest */\r\n public static readonly TEXTURE_LINEAR_LINEAR_MIPNEAREST = Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST;\r\n /** Trilinear is mag = linear and min = linear and mip = linear */\r\n public static readonly TEXTURE_LINEAR_LINEAR_MIPLINEAR = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n /** mag = nearest and min = nearest and mip = nearest */\r\n public static readonly TEXTURE_NEAREST_NEAREST_MIPNEAREST = Constants.TEXTURE_NEAREST_NEAREST_MIPNEAREST;\r\n /** mag = nearest and min = linear and mip = nearest */\r\n public static readonly TEXTURE_NEAREST_LINEAR_MIPNEAREST = Constants.TEXTURE_NEAREST_LINEAR_MIPNEAREST;\r\n /** mag = nearest and min = linear and mip = linear */\r\n public static readonly TEXTURE_NEAREST_LINEAR_MIPLINEAR = Constants.TEXTURE_NEAREST_LINEAR_MIPLINEAR;\r\n /** mag = nearest and min = linear and mip = none */\r\n public static readonly TEXTURE_NEAREST_LINEAR = Constants.TEXTURE_NEAREST_LINEAR;\r\n /** mag = nearest and min = nearest and mip = none */\r\n public static readonly TEXTURE_NEAREST_NEAREST = Constants.TEXTURE_NEAREST_NEAREST;\r\n /** mag = linear and min = nearest and mip = nearest */\r\n public static readonly TEXTURE_LINEAR_NEAREST_MIPNEAREST = Constants.TEXTURE_LINEAR_NEAREST_MIPNEAREST;\r\n /** mag = linear and min = nearest and mip = linear */\r\n public static readonly TEXTURE_LINEAR_NEAREST_MIPLINEAR = Constants.TEXTURE_LINEAR_NEAREST_MIPLINEAR;\r\n /** mag = linear and min = linear and mip = none */\r\n public static readonly TEXTURE_LINEAR_LINEAR = Constants.TEXTURE_LINEAR_LINEAR;\r\n /** mag = linear and min = nearest and mip = none */\r\n public static readonly TEXTURE_LINEAR_NEAREST = Constants.TEXTURE_LINEAR_NEAREST;\r\n\r\n /** Explicit coordinates mode */\r\n public static readonly TEXTURE_EXPLICIT_MODE = Constants.TEXTURE_EXPLICIT_MODE;\r\n /** Spherical coordinates mode */\r\n public static readonly TEXTURE_SPHERICAL_MODE = Constants.TEXTURE_SPHERICAL_MODE;\r\n /** Planar coordinates mode */\r\n public static readonly TEXTURE_PLANAR_MODE = Constants.TEXTURE_PLANAR_MODE;\r\n /** Cubic coordinates mode */\r\n public static readonly TEXTURE_CUBIC_MODE = Constants.TEXTURE_CUBIC_MODE;\r\n /** Projection coordinates mode */\r\n public static readonly TEXTURE_PROJECTION_MODE = Constants.TEXTURE_PROJECTION_MODE;\r\n /** Skybox coordinates mode */\r\n public static readonly TEXTURE_SKYBOX_MODE = Constants.TEXTURE_SKYBOX_MODE;\r\n /** Inverse Cubic coordinates mode */\r\n public static readonly TEXTURE_INVCUBIC_MODE = Constants.TEXTURE_INVCUBIC_MODE;\r\n /** Equirectangular coordinates mode */\r\n public static readonly TEXTURE_EQUIRECTANGULAR_MODE = Constants.TEXTURE_EQUIRECTANGULAR_MODE;\r\n /** Equirectangular Fixed coordinates mode */\r\n public static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MODE = Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MODE;\r\n /** Equirectangular Fixed Mirrored coordinates mode */\r\n public static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE = Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE;\r\n\r\n // Texture rescaling mode\r\n /** Defines that texture rescaling will use a floor to find the closer power of 2 size */\r\n public static readonly SCALEMODE_FLOOR = Constants.SCALEMODE_FLOOR;\r\n /** Defines that texture rescaling will look for the nearest power of 2 size */\r\n public static readonly SCALEMODE_NEAREST = Constants.SCALEMODE_NEAREST;\r\n /** Defines that texture rescaling will use a ceil to find the closer power of 2 size */\r\n public static readonly SCALEMODE_CEILING = Constants.SCALEMODE_CEILING;\r\n\r\n /**\r\n * Returns the current npm package of the sdk\r\n */\r\n // Not mixed with Version for tooling purpose.\r\n public static get NpmPackage(): string {\r\n return ThinEngine.NpmPackage;\r\n }\r\n\r\n /**\r\n * Returns the current version of the framework\r\n */\r\n public static get Version(): string {\r\n return ThinEngine.Version;\r\n }\r\n\r\n /** Gets the list of created engines */\r\n public static get Instances(): Engine[] {\r\n return EngineStore.Instances;\r\n }\r\n\r\n /**\r\n * Gets the latest created engine\r\n */\r\n public static get LastCreatedEngine(): Nullable {\r\n return EngineStore.LastCreatedEngine;\r\n }\r\n\r\n /**\r\n * Gets the latest created scene\r\n */\r\n public static get LastCreatedScene(): Nullable {\r\n return EngineStore.LastCreatedScene;\r\n }\r\n\r\n /** @internal */\r\n /**\r\n * Engine abstraction for loading and creating an image bitmap from a given source string.\r\n * @param imageSource source to load the image from.\r\n * @param options An object that sets options for the image's extraction.\r\n * @returns ImageBitmap.\r\n */\r\n public _createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise {\r\n const promise = new Promise((resolve, reject) => {\r\n const image = new Image();\r\n image.onload = () => {\r\n image.decode().then(() => {\r\n this.createImageBitmap(image, options).then((imageBitmap) => {\r\n resolve(imageBitmap);\r\n });\r\n });\r\n };\r\n image.onerror = () => {\r\n reject(`Error loading image ${image.src}`);\r\n };\r\n\r\n image.src = imageSource;\r\n });\r\n\r\n return promise;\r\n }\r\n\r\n /**\r\n * Engine abstraction for createImageBitmap\r\n * @param image source for image\r\n * @param options An object that sets options for the image's extraction.\r\n * @returns ImageBitmap\r\n */\r\n public createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise {\r\n return createImageBitmap(image, options);\r\n }\r\n\r\n /**\r\n * Resize an image and returns the image data as an uint8array\r\n * @param image image to resize\r\n * @param bufferWidth destination buffer width\r\n * @param bufferHeight destination buffer height\r\n * @returns an uint8array containing RGBA values of bufferWidth * bufferHeight size\r\n */\r\n public resizeImageBitmap(image: HTMLImageElement | ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array {\r\n const canvas = this.createCanvas(bufferWidth, bufferHeight);\r\n const context = canvas.getContext(\"2d\");\r\n\r\n if (!context) {\r\n throw new Error(\"Unable to get 2d context for resizeImageBitmap\");\r\n }\r\n\r\n context.drawImage(image, 0, 0);\r\n\r\n // Create VertexData from map data\r\n // Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949\r\n const buffer = (context.getImageData(0, 0, bufferWidth, bufferHeight).data);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Will flag all materials in all scenes in all engines as dirty to trigger new shader compilation\r\n * @param flag defines which part of the materials must be marked as dirty\r\n * @param predicate defines a predicate used to filter which materials should be affected\r\n */\r\n public static MarkAllMaterialsAsDirty(flag: number, predicate?: (mat: Material) => boolean): void {\r\n for (let engineIndex = 0; engineIndex < Engine.Instances.length; engineIndex++) {\r\n const engine = Engine.Instances[engineIndex];\r\n\r\n for (let sceneIndex = 0; sceneIndex < engine.scenes.length; sceneIndex++) {\r\n engine.scenes[sceneIndex].markAllMaterialsAsDirty(flag, predicate);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Method called to create the default loading screen.\r\n * This can be overridden in your own app.\r\n * @param canvas The rendering canvas element\r\n * @returns The loading screen\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static DefaultLoadingScreenFactory(canvas: HTMLCanvasElement): ILoadingScreen {\r\n throw _WarnImport(\"LoadingScreen\");\r\n }\r\n\r\n /**\r\n * Method called to create the default rescale post process on each engine.\r\n */\r\n public static _RescalePostProcessFactory: Nullable<(engine: Engine) => PostProcess> = null;\r\n\r\n // Members\r\n\r\n /**\r\n * Gets or sets a boolean to enable/disable IndexedDB support and avoid XHR on .manifest\r\n **/\r\n public enableOfflineSupport = false;\r\n\r\n /**\r\n * Gets or sets a boolean to enable/disable checking manifest if IndexedDB support is enabled (js will always consider the database is up to date)\r\n **/\r\n public disableManifestCheck = false;\r\n\r\n /**\r\n * Gets or sets a boolean to enable/disable the context menu (right-click) from appearing on the main canvas\r\n */\r\n public disableContextMenu: boolean = true;\r\n\r\n /**\r\n * Gets the list of created scenes\r\n */\r\n public scenes = new Array();\r\n\r\n /** @internal */\r\n public _virtualScenes = new Array();\r\n\r\n /**\r\n * Event raised when a new scene is created\r\n */\r\n public onNewSceneAddedObservable = new Observable();\r\n\r\n /**\r\n * Gets the list of created postprocesses\r\n */\r\n public postProcesses = new Array();\r\n\r\n /**\r\n * Gets a boolean indicating if the pointer is currently locked\r\n */\r\n public isPointerLock = false;\r\n\r\n // Observables\r\n\r\n /**\r\n * Observable event triggered each time the rendering canvas is resized\r\n */\r\n public onResizeObservable = new Observable();\r\n\r\n /**\r\n * Observable event triggered each time the canvas loses focus\r\n */\r\n public onCanvasBlurObservable = new Observable();\r\n\r\n /**\r\n * Observable event triggered each time the canvas gains focus\r\n */\r\n public onCanvasFocusObservable = new Observable();\r\n\r\n /**\r\n * Observable event triggered each time the canvas receives pointerout event\r\n */\r\n public onCanvasPointerOutObservable = new Observable();\r\n\r\n /**\r\n * Observable raised when the engine begins a new frame\r\n */\r\n public onBeginFrameObservable = new Observable();\r\n\r\n /**\r\n * If set, will be used to request the next animation frame for the render loop\r\n */\r\n public customAnimationFrameRequester: Nullable = null;\r\n\r\n /**\r\n * Observable raised when the engine ends the current frame\r\n */\r\n public onEndFrameObservable = new Observable();\r\n\r\n /**\r\n * Observable raised when the engine is about to compile a shader\r\n */\r\n public onBeforeShaderCompilationObservable = new Observable();\r\n\r\n /**\r\n * Observable raised when the engine has just compiled a shader\r\n */\r\n public onAfterShaderCompilationObservable = new Observable();\r\n\r\n /**\r\n * Gets the audio engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static audioEngine: Nullable;\r\n\r\n /**\r\n * Default AudioEngine factory responsible of creating the Audio Engine.\r\n * By default, this will create a BabylonJS Audio Engine if the workload has been embedded.\r\n */\r\n public static AudioEngineFactory: (\r\n hostElement: Nullable,\r\n audioContext: Nullable,\r\n audioDestination: Nullable\r\n ) => IAudioEngine;\r\n\r\n /**\r\n * Default offline support factory responsible of creating a tool used to store data locally.\r\n * By default, this will create a Database object if the workload has been embedded.\r\n */\r\n public static OfflineProviderFactory: (urlToScene: string, callbackManifestChecked: (checked: boolean) => any, disableManifestCheck: boolean) => IOfflineProvider;\r\n\r\n private _loadingScreen: ILoadingScreen;\r\n private _pointerLockRequested: boolean;\r\n private _rescalePostProcess: Nullable;\r\n\r\n // Deterministic lockstepMaxSteps\r\n protected _deterministicLockstep: boolean = false;\r\n protected _lockstepMaxSteps: number = 4;\r\n protected _timeStep: number = 1 / 60;\r\n\r\n protected get _supportsHardwareTextureRescaling() {\r\n return !!Engine._RescalePostProcessFactory;\r\n }\r\n\r\n // FPS\r\n private _fps = 60;\r\n private _deltaTime = 0;\r\n\r\n /** @internal */\r\n public _drawCalls = new PerfCounter();\r\n\r\n /** Gets or sets the tab index to set to the rendering canvas. 1 is the minimum value to set to be able to capture keyboard events */\r\n public canvasTabIndex = 1;\r\n\r\n /**\r\n * Turn this value on if you want to pause FPS computation when in background\r\n */\r\n public disablePerformanceMonitorInBackground = false;\r\n\r\n private _performanceMonitor = new PerformanceMonitor();\r\n /**\r\n * Gets the performance monitor attached to this engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation\r\n */\r\n public get performanceMonitor(): PerformanceMonitor {\r\n return this._performanceMonitor;\r\n }\r\n\r\n // Focus\r\n private _onFocus: () => void;\r\n private _onBlur: () => void;\r\n private _onCanvasPointerOut: (event: PointerEvent) => void;\r\n private _onCanvasBlur: () => void;\r\n private _onCanvasFocus: () => void;\r\n private _onCanvasContextMenu: (evt: Event) => void;\r\n\r\n private _onFullscreenChange: () => void;\r\n private _onPointerLockChange: () => void;\r\n\r\n protected _compatibilityMode = true;\r\n\r\n /**\r\n * (WebGPU only) True (default) to be in compatibility mode, meaning rendering all existing scenes without artifacts (same rendering than WebGL).\r\n * Setting the property to false will improve performances but may not work in some scenes if some precautions are not taken.\r\n * See https://doc.babylonjs.com/setup/support/webGPU/webGPUOptimization/webGPUNonCompatibilityMode for more details\r\n */\r\n public get compatibilityMode() {\r\n return this._compatibilityMode;\r\n }\r\n\r\n public set compatibilityMode(mode: boolean) {\r\n // not supported in WebGL\r\n this._compatibilityMode = true;\r\n }\r\n\r\n // Events\r\n\r\n /**\r\n * Gets the HTML element used to attach event listeners\r\n * @returns a HTML element\r\n */\r\n public getInputElement(): Nullable {\r\n return this._renderingCanvas;\r\n }\r\n\r\n /**\r\n * Creates a new engine\r\n * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context\r\n * @param antialias defines enable antialiasing (default: false)\r\n * @param options defines further options to be sent to the getContext() function\r\n * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)\r\n */\r\n constructor(\r\n canvasOrContext: Nullable,\r\n antialias?: boolean,\r\n options?: EngineOptions,\r\n adaptToDeviceRatio: boolean = false\r\n ) {\r\n super(canvasOrContext, antialias, options, adaptToDeviceRatio);\r\n\r\n Engine.Instances.push(this);\r\n\r\n if (!canvasOrContext) {\r\n return;\r\n }\r\n\r\n this._features.supportRenderPasses = true;\r\n\r\n options = this._creationOptions;\r\n\r\n if ((canvasOrContext).getContext) {\r\n const canvas = canvasOrContext;\r\n\r\n this._sharedInit(canvas);\r\n\r\n this._connectVREvents();\r\n }\r\n\r\n // Load WebVR Devices\r\n this._prepareVRComponent();\r\n if (options.autoEnableWebVR) {\r\n this.initWebVR();\r\n }\r\n }\r\n\r\n protected _initGLContext(): void {\r\n super._initGLContext();\r\n\r\n this._rescalePostProcess = null;\r\n }\r\n\r\n /**\r\n * Shared initialization across engines types.\r\n * @param canvas The canvas associated with this instance of the engine.\r\n */\r\n protected _sharedInit(canvas: HTMLCanvasElement) {\r\n super._sharedInit(canvas);\r\n\r\n this._onCanvasFocus = () => {\r\n this.onCanvasFocusObservable.notifyObservers(this);\r\n };\r\n\r\n this._onCanvasBlur = () => {\r\n this.onCanvasBlurObservable.notifyObservers(this);\r\n };\r\n\r\n this._onCanvasContextMenu = (evt: Event) => {\r\n if (this.disableContextMenu) {\r\n evt.preventDefault();\r\n }\r\n };\r\n\r\n canvas.addEventListener(\"focus\", this._onCanvasFocus);\r\n canvas.addEventListener(\"blur\", this._onCanvasBlur);\r\n canvas.addEventListener(\"contextmenu\", this._onCanvasContextMenu);\r\n\r\n this._onBlur = () => {\r\n if (this.disablePerformanceMonitorInBackground) {\r\n this._performanceMonitor.disable();\r\n }\r\n this._windowIsBackground = true;\r\n };\r\n\r\n this._onFocus = () => {\r\n if (this.disablePerformanceMonitorInBackground) {\r\n this._performanceMonitor.enable();\r\n }\r\n this._windowIsBackground = false;\r\n };\r\n\r\n this._onCanvasPointerOut = (ev) => {\r\n // Check that the element at the point of the pointer out isn't the canvas and if it isn't, notify observers\r\n // Note: This is a workaround for a bug with Safari\r\n if (document.elementFromPoint(ev.clientX, ev.clientY) !== canvas) {\r\n this.onCanvasPointerOutObservable.notifyObservers(ev);\r\n }\r\n };\r\n\r\n const hostWindow = this.getHostWindow(); // it calls IsWindowObjectExist()\r\n if (hostWindow && typeof hostWindow.addEventListener === \"function\") {\r\n hostWindow.addEventListener(\"blur\", this._onBlur);\r\n hostWindow.addEventListener(\"focus\", this._onFocus);\r\n }\r\n\r\n canvas.addEventListener(\"pointerout\", this._onCanvasPointerOut);\r\n\r\n if (!this._creationOptions.doNotHandleTouchAction) {\r\n this._disableTouchAction();\r\n }\r\n\r\n // Create Audio Engine if needed.\r\n if (!Engine.audioEngine && this._creationOptions.audioEngine && Engine.AudioEngineFactory) {\r\n Engine.audioEngine = Engine.AudioEngineFactory(this.getRenderingCanvas(), this.getAudioContext(), this.getAudioDestination());\r\n }\r\n if (IsDocumentAvailable()) {\r\n // Fullscreen\r\n this._onFullscreenChange = () => {\r\n this.isFullscreen = !!document.fullscreenElement;\r\n\r\n // Pointer lock\r\n if (this.isFullscreen && this._pointerLockRequested && canvas) {\r\n Engine._RequestPointerlock(canvas);\r\n }\r\n };\r\n\r\n document.addEventListener(\"fullscreenchange\", this._onFullscreenChange, false);\r\n document.addEventListener(\"webkitfullscreenchange\", this._onFullscreenChange, false);\r\n\r\n // Pointer lock\r\n this._onPointerLockChange = () => {\r\n this.isPointerLock = document.pointerLockElement === canvas;\r\n };\r\n\r\n document.addEventListener(\"pointerlockchange\", this._onPointerLockChange, false);\r\n document.addEventListener(\"webkitpointerlockchange\", this._onPointerLockChange, false);\r\n }\r\n\r\n this.enableOfflineSupport = Engine.OfflineProviderFactory !== undefined;\r\n\r\n this._deterministicLockstep = !!this._creationOptions.deterministicLockstep;\r\n this._lockstepMaxSteps = this._creationOptions.lockstepMaxSteps || 0;\r\n this._timeStep = this._creationOptions.timeStep || 1 / 60;\r\n }\r\n\r\n /** @internal */\r\n public _verifyPointerLock(): void {\r\n this._onPointerLockChange?.();\r\n }\r\n\r\n /**\r\n * Gets current aspect ratio\r\n * @param viewportOwner defines the camera to use to get the aspect ratio\r\n * @param useScreen defines if screen size must be used (or the current render target if any)\r\n * @returns a number defining the aspect ratio\r\n */\r\n public getAspectRatio(viewportOwner: IViewportOwnerLike, useScreen = false): number {\r\n const viewport = viewportOwner.viewport;\r\n return (this.getRenderWidth(useScreen) * viewport.width) / (this.getRenderHeight(useScreen) * viewport.height);\r\n }\r\n\r\n /**\r\n * Gets current screen aspect ratio\r\n * @returns a number defining the aspect ratio\r\n */\r\n public getScreenAspectRatio(): number {\r\n return this.getRenderWidth(true) / this.getRenderHeight(true);\r\n }\r\n\r\n /**\r\n * Gets the client rect of the HTML canvas attached with the current webGL context\r\n * @returns a client rectangle\r\n */\r\n public getRenderingCanvasClientRect(): Nullable {\r\n if (!this._renderingCanvas) {\r\n return null;\r\n }\r\n return this._renderingCanvas.getBoundingClientRect();\r\n }\r\n\r\n /**\r\n * Gets the client rect of the HTML element used for events\r\n * @returns a client rectangle\r\n */\r\n public getInputElementClientRect(): Nullable {\r\n if (!this._renderingCanvas) {\r\n return null;\r\n }\r\n return this.getInputElement()!.getBoundingClientRect();\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the engine is running in deterministic lock step mode\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n * @returns true if engine is in deterministic lock step mode\r\n */\r\n public isDeterministicLockStep(): boolean {\r\n return this._deterministicLockstep;\r\n }\r\n\r\n /**\r\n * Gets the max steps when engine is running in deterministic lock step\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep\r\n * @returns the max steps\r\n */\r\n public getLockstepMaxSteps(): number {\r\n return this._lockstepMaxSteps;\r\n }\r\n\r\n /**\r\n * Returns the time in ms between steps when using deterministic lock step.\r\n * @returns time step in (ms)\r\n */\r\n public getTimeStep(): number {\r\n return this._timeStep * 1000;\r\n }\r\n\r\n /**\r\n * Force the mipmap generation for the given render target texture\r\n * @param texture defines the render target texture to use\r\n * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.\r\n */\r\n public generateMipMapsForCubemap(texture: InternalTexture, unbind = true) {\r\n if (texture.generateMipMaps) {\r\n const gl = this._gl;\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\r\n gl.generateMipmap(gl.TEXTURE_CUBE_MAP);\r\n if (unbind) {\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n }\r\n }\r\n }\r\n\r\n /** States */\r\n\r\n /**\r\n * Gets a boolean indicating if depth writing is enabled\r\n * @returns the current depth writing state\r\n */\r\n public getDepthWrite(): boolean {\r\n return this._depthCullingState.depthMask;\r\n }\r\n\r\n /**\r\n * Enable or disable depth writing\r\n * @param enable defines the state to set\r\n */\r\n public setDepthWrite(enable: boolean): void {\r\n this._depthCullingState.depthMask = enable;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if stencil buffer is enabled\r\n * @returns the current stencil buffer state\r\n */\r\n public getStencilBuffer(): boolean {\r\n return this._stencilState.stencilTest;\r\n }\r\n\r\n /**\r\n * Enable or disable the stencil buffer\r\n * @param enable defines if the stencil buffer must be enabled or disabled\r\n */\r\n public setStencilBuffer(enable: boolean): void {\r\n this._stencilState.stencilTest = enable;\r\n }\r\n\r\n /**\r\n * Gets the current stencil mask\r\n * @returns a number defining the new stencil mask to use\r\n */\r\n public getStencilMask(): number {\r\n return this._stencilState.stencilMask;\r\n }\r\n\r\n /**\r\n * Sets the current stencil mask\r\n * @param mask defines the new stencil mask to use\r\n */\r\n public setStencilMask(mask: number): void {\r\n this._stencilState.stencilMask = mask;\r\n }\r\n\r\n /**\r\n * Gets the current stencil function\r\n * @returns a number defining the stencil function to use\r\n */\r\n public getStencilFunction(): number {\r\n return this._stencilState.stencilFunc;\r\n }\r\n\r\n /**\r\n * Gets the current stencil reference value\r\n * @returns a number defining the stencil reference value to use\r\n */\r\n public getStencilFunctionReference(): number {\r\n return this._stencilState.stencilFuncRef;\r\n }\r\n\r\n /**\r\n * Gets the current stencil mask\r\n * @returns a number defining the stencil mask to use\r\n */\r\n public getStencilFunctionMask(): number {\r\n return this._stencilState.stencilFuncMask;\r\n }\r\n\r\n /**\r\n * Sets the current stencil function\r\n * @param stencilFunc defines the new stencil function to use\r\n */\r\n public setStencilFunction(stencilFunc: number) {\r\n this._stencilState.stencilFunc = stencilFunc;\r\n }\r\n\r\n /**\r\n * Sets the current stencil reference\r\n * @param reference defines the new stencil reference to use\r\n */\r\n public setStencilFunctionReference(reference: number) {\r\n this._stencilState.stencilFuncRef = reference;\r\n }\r\n\r\n /**\r\n * Sets the current stencil mask\r\n * @param mask defines the new stencil mask to use\r\n */\r\n public setStencilFunctionMask(mask: number) {\r\n this._stencilState.stencilFuncMask = mask;\r\n }\r\n\r\n /**\r\n * Gets the current stencil operation when stencil fails\r\n * @returns a number defining stencil operation to use when stencil fails\r\n */\r\n public getStencilOperationFail(): number {\r\n return this._stencilState.stencilOpStencilFail;\r\n }\r\n\r\n /**\r\n * Gets the current stencil operation when depth fails\r\n * @returns a number defining stencil operation to use when depth fails\r\n */\r\n public getStencilOperationDepthFail(): number {\r\n return this._stencilState.stencilOpDepthFail;\r\n }\r\n\r\n /**\r\n * Gets the current stencil operation when stencil passes\r\n * @returns a number defining stencil operation to use when stencil passes\r\n */\r\n public getStencilOperationPass(): number {\r\n return this._stencilState.stencilOpStencilDepthPass;\r\n }\r\n\r\n /**\r\n * Sets the stencil operation to use when stencil fails\r\n * @param operation defines the stencil operation to use when stencil fails\r\n */\r\n public setStencilOperationFail(operation: number): void {\r\n this._stencilState.stencilOpStencilFail = operation;\r\n }\r\n\r\n /**\r\n * Sets the stencil operation to use when depth fails\r\n * @param operation defines the stencil operation to use when depth fails\r\n */\r\n public setStencilOperationDepthFail(operation: number): void {\r\n this._stencilState.stencilOpDepthFail = operation;\r\n }\r\n\r\n /**\r\n * Sets the stencil operation to use when stencil passes\r\n * @param operation defines the stencil operation to use when stencil passes\r\n */\r\n public setStencilOperationPass(operation: number): void {\r\n this._stencilState.stencilOpStencilDepthPass = operation;\r\n }\r\n\r\n /**\r\n * Sets a boolean indicating if the dithering state is enabled or disabled\r\n * @param value defines the dithering state\r\n */\r\n public setDitheringState(value: boolean): void {\r\n if (value) {\r\n this._gl.enable(this._gl.DITHER);\r\n } else {\r\n this._gl.disable(this._gl.DITHER);\r\n }\r\n }\r\n\r\n /**\r\n * Sets a boolean indicating if the rasterizer state is enabled or disabled\r\n * @param value defines the rasterizer state\r\n */\r\n public setRasterizerState(value: boolean): void {\r\n if (value) {\r\n this._gl.disable(this._gl.RASTERIZER_DISCARD);\r\n } else {\r\n this._gl.enable(this._gl.RASTERIZER_DISCARD);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current depth function\r\n * @returns a number defining the depth function\r\n */\r\n public getDepthFunction(): Nullable {\r\n return this._depthCullingState.depthFunc;\r\n }\r\n\r\n /**\r\n * Sets the current depth function\r\n * @param depthFunc defines the function to use\r\n */\r\n public setDepthFunction(depthFunc: number) {\r\n this._depthCullingState.depthFunc = depthFunc;\r\n }\r\n\r\n /**\r\n * Sets the current depth function to GREATER\r\n */\r\n public setDepthFunctionToGreater(): void {\r\n this.setDepthFunction(Constants.GREATER);\r\n }\r\n\r\n /**\r\n * Sets the current depth function to GEQUAL\r\n */\r\n public setDepthFunctionToGreaterOrEqual(): void {\r\n this.setDepthFunction(Constants.GEQUAL);\r\n }\r\n\r\n /**\r\n * Sets the current depth function to LESS\r\n */\r\n public setDepthFunctionToLess(): void {\r\n this.setDepthFunction(Constants.LESS);\r\n }\r\n\r\n /**\r\n * Sets the current depth function to LEQUAL\r\n */\r\n public setDepthFunctionToLessOrEqual(): void {\r\n this.setDepthFunction(Constants.LEQUAL);\r\n }\r\n\r\n private _cachedStencilBuffer: boolean;\r\n private _cachedStencilFunction: number;\r\n private _cachedStencilMask: number;\r\n private _cachedStencilOperationPass: number;\r\n private _cachedStencilOperationFail: number;\r\n private _cachedStencilOperationDepthFail: number;\r\n private _cachedStencilReference: number;\r\n\r\n /**\r\n * Caches the the state of the stencil buffer\r\n */\r\n public cacheStencilState() {\r\n this._cachedStencilBuffer = this.getStencilBuffer();\r\n this._cachedStencilFunction = this.getStencilFunction();\r\n this._cachedStencilMask = this.getStencilMask();\r\n this._cachedStencilOperationPass = this.getStencilOperationPass();\r\n this._cachedStencilOperationFail = this.getStencilOperationFail();\r\n this._cachedStencilOperationDepthFail = this.getStencilOperationDepthFail();\r\n this._cachedStencilReference = this.getStencilFunctionReference();\r\n }\r\n\r\n /**\r\n * Restores the state of the stencil buffer\r\n */\r\n public restoreStencilState() {\r\n this.setStencilFunction(this._cachedStencilFunction);\r\n this.setStencilMask(this._cachedStencilMask);\r\n this.setStencilBuffer(this._cachedStencilBuffer);\r\n this.setStencilOperationPass(this._cachedStencilOperationPass);\r\n this.setStencilOperationFail(this._cachedStencilOperationFail);\r\n this.setStencilOperationDepthFail(this._cachedStencilOperationDepthFail);\r\n this.setStencilFunctionReference(this._cachedStencilReference);\r\n }\r\n\r\n /**\r\n * Directly set the WebGL Viewport\r\n * @param x defines the x coordinate of the viewport (in screen space)\r\n * @param y defines the y coordinate of the viewport (in screen space)\r\n * @param width defines the width of the viewport (in screen space)\r\n * @param height defines the height of the viewport (in screen space)\r\n * @returns the current viewport Object (if any) that is being replaced by this call. You can restore this viewport later on to go back to the original state\r\n */\r\n public setDirectViewport(x: number, y: number, width: number, height: number): Nullable {\r\n const currentViewport = this._cachedViewport;\r\n this._cachedViewport = null;\r\n\r\n this._viewport(x, y, width, height);\r\n\r\n return currentViewport;\r\n }\r\n\r\n /**\r\n * Executes a scissor clear (ie. a clear on a specific portion of the screen)\r\n * @param x defines the x-coordinate of the bottom left corner of the clear rectangle\r\n * @param y defines the y-coordinate of the corner of the clear rectangle\r\n * @param width defines the width of the clear rectangle\r\n * @param height defines the height of the clear rectangle\r\n * @param clearColor defines the clear color\r\n */\r\n public scissorClear(x: number, y: number, width: number, height: number, clearColor: IColor4Like): void {\r\n this.enableScissor(x, y, width, height);\r\n this.clear(clearColor, true, true, true);\r\n this.disableScissor();\r\n }\r\n\r\n /**\r\n * Enable scissor test on a specific rectangle (ie. render will only be executed on a specific portion of the screen)\r\n * @param x defines the x-coordinate of the bottom left corner of the clear rectangle\r\n * @param y defines the y-coordinate of the corner of the clear rectangle\r\n * @param width defines the width of the clear rectangle\r\n * @param height defines the height of the clear rectangle\r\n */\r\n public enableScissor(x: number, y: number, width: number, height: number): void {\r\n const gl = this._gl;\r\n\r\n // Change state\r\n gl.enable(gl.SCISSOR_TEST);\r\n gl.scissor(x, y, width, height);\r\n }\r\n\r\n /**\r\n * Disable previously set scissor test rectangle\r\n */\r\n public disableScissor() {\r\n const gl = this._gl;\r\n\r\n gl.disable(gl.SCISSOR_TEST);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _reportDrawCall(numDrawCalls = 1) {\r\n this._drawCalls.addCount(numDrawCalls, false);\r\n }\r\n\r\n /**\r\n * Initializes a webVR display and starts listening to display change events\r\n * The onVRDisplayChangedObservable will be notified upon these changes\r\n * @returns The onVRDisplayChangedObservable\r\n */\r\n public initWebVR(): Observable {\r\n throw _WarnImport(\"WebVRCamera\");\r\n }\r\n\r\n /** @internal */\r\n public _prepareVRComponent() {\r\n // Do nothing as the engine side effect will overload it\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _connectVREvents(canvas?: HTMLCanvasElement, document?: any) {\r\n // Do nothing as the engine side effect will overload it\r\n }\r\n\r\n /** @internal */\r\n public _submitVRFrame() {\r\n // Do nothing as the engine side effect will overload it\r\n }\r\n /**\r\n * Call this function to leave webVR mode\r\n * Will do nothing if webVR is not supported or if there is no webVR device\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRCamera\r\n */\r\n public disableVR() {\r\n // Do nothing as the engine side effect will overload it\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the system is in VR mode and is presenting\r\n * @returns true if VR mode is engaged\r\n */\r\n public isVRPresenting() {\r\n return false;\r\n }\r\n\r\n /** @internal */\r\n public _requestVRFrame() {\r\n // Do nothing as the engine side effect will overload it\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean): Promise {\r\n return new Promise((resolve, reject) => {\r\n this._loadFile(\r\n url,\r\n (data) => {\r\n resolve(data);\r\n },\r\n undefined,\r\n offlineProvider,\r\n useArrayBuffer,\r\n (request, exception) => {\r\n reject(exception);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Gets the source code of the vertex shader associated with a specific webGL program\r\n * @param program defines the program to use\r\n * @returns a string containing the source code of the vertex shader associated with the program\r\n */\r\n public getVertexShaderSource(program: WebGLProgram): Nullable {\r\n const shaders = this._gl.getAttachedShaders(program);\r\n\r\n if (!shaders) {\r\n return null;\r\n }\r\n\r\n return this._gl.getShaderSource(shaders[0]);\r\n }\r\n\r\n /**\r\n * Gets the source code of the fragment shader associated with a specific webGL program\r\n * @param program defines the program to use\r\n * @returns a string containing the source code of the fragment shader associated with the program\r\n */\r\n public getFragmentShaderSource(program: WebGLProgram): Nullable {\r\n const shaders = this._gl.getAttachedShaders(program);\r\n\r\n if (!shaders) {\r\n return null;\r\n }\r\n\r\n return this._gl.getShaderSource(shaders[1]);\r\n }\r\n\r\n /**\r\n * Sets a depth stencil texture from a render target to the according uniform.\r\n * @param channel The texture channel\r\n * @param uniform The uniform to set\r\n * @param texture The render target texture containing the depth stencil texture to apply\r\n * @param name The texture name\r\n */\r\n public setDepthStencilTexture(channel: number, uniform: Nullable, texture: Nullable, name?: string): void {\r\n if (channel === undefined) {\r\n return;\r\n }\r\n\r\n if (uniform) {\r\n this._boundUniforms[channel] = uniform;\r\n }\r\n\r\n if (!texture || !texture.depthStencilTexture) {\r\n this._setTexture(channel, null, undefined, undefined, name);\r\n } else {\r\n this._setTexture(channel, texture, false, true, name);\r\n }\r\n }\r\n\r\n /**\r\n * Sets a texture to the webGL context from a postprocess\r\n * @param channel defines the channel to use\r\n * @param postProcess defines the source postprocess\r\n * @param name name of the channel\r\n */\r\n public setTextureFromPostProcess(channel: number, postProcess: Nullable, name: string): void {\r\n let postProcessInput = null;\r\n if (postProcess) {\r\n if (postProcess._forcedOutputTexture) {\r\n postProcessInput = postProcess._forcedOutputTexture;\r\n } else if (postProcess._textures.data[postProcess._currentRenderTextureInd]) {\r\n postProcessInput = postProcess._textures.data[postProcess._currentRenderTextureInd];\r\n }\r\n }\r\n\r\n this._bindTexture(channel, postProcessInput?.texture ?? null, name);\r\n }\r\n\r\n /**\r\n * Binds the output of the passed in post process to the texture channel specified\r\n * @param channel The channel the texture should be bound to\r\n * @param postProcess The post process which's output should be bound\r\n * @param name name of the channel\r\n */\r\n public setTextureFromPostProcessOutput(channel: number, postProcess: Nullable, name: string): void {\r\n this._bindTexture(channel, postProcess?._outputTexture?.texture ?? null, name);\r\n }\r\n\r\n protected _rebuildBuffers(): void {\r\n // Index / Vertex\r\n for (const scene of this.scenes) {\r\n scene.resetCachedMaterial();\r\n scene._rebuildGeometries();\r\n scene._rebuildTextures();\r\n }\r\n\r\n for (const scene of this._virtualScenes) {\r\n scene.resetCachedMaterial();\r\n scene._rebuildGeometries();\r\n scene._rebuildTextures();\r\n }\r\n\r\n super._rebuildBuffers();\r\n }\r\n\r\n /** @internal */\r\n public _renderFrame() {\r\n for (let index = 0; index < this._activeRenderLoops.length; index++) {\r\n const renderFunction = this._activeRenderLoops[index];\r\n\r\n renderFunction();\r\n }\r\n }\r\n\r\n protected _cancelFrame() {\r\n if (this._renderingQueueLaunched && this.customAnimationFrameRequester) {\r\n this._renderingQueueLaunched = false;\r\n const { cancelAnimationFrame } = this.customAnimationFrameRequester;\r\n if (cancelAnimationFrame) {\r\n cancelAnimationFrame(this.customAnimationFrameRequester.requestID);\r\n }\r\n } else {\r\n super._cancelFrame();\r\n }\r\n }\r\n\r\n public _renderLoop(): void {\r\n if (!this._contextWasLost) {\r\n let shouldRender = true;\r\n if (this.isDisposed || (!this.renderEvenInBackground && this._windowIsBackground)) {\r\n shouldRender = false;\r\n }\r\n\r\n if (shouldRender) {\r\n // Start new frame\r\n this.beginFrame();\r\n\r\n // Child canvases\r\n if (!this._renderViews()) {\r\n // Main frame\r\n this._renderFrame();\r\n }\r\n\r\n // Present\r\n this.endFrame();\r\n }\r\n }\r\n\r\n if (this._activeRenderLoops.length > 0) {\r\n // Register new frame\r\n if (this.customAnimationFrameRequester) {\r\n this.customAnimationFrameRequester.requestID = this._queueNewFrame(\r\n this.customAnimationFrameRequester.renderFunction || this._boundRenderFunction,\r\n this.customAnimationFrameRequester\r\n );\r\n this._frameHandler = this.customAnimationFrameRequester.requestID;\r\n } else if (this.isVRPresenting()) {\r\n this._requestVRFrame();\r\n } else {\r\n this._frameHandler = this._queueNewFrame(this._boundRenderFunction, this.getHostWindow());\r\n }\r\n } else {\r\n this._renderingQueueLaunched = false;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _renderViews() {\r\n return false;\r\n }\r\n\r\n /**\r\n * Toggle full screen mode\r\n * @param requestPointerLock defines if a pointer lock should be requested from the user\r\n */\r\n public switchFullscreen(requestPointerLock: boolean): void {\r\n if (this.isFullscreen) {\r\n this.exitFullscreen();\r\n } else {\r\n this.enterFullscreen(requestPointerLock);\r\n }\r\n }\r\n\r\n /**\r\n * Enters full screen mode\r\n * @param requestPointerLock defines if a pointer lock should be requested from the user\r\n */\r\n public enterFullscreen(requestPointerLock: boolean): void {\r\n if (!this.isFullscreen) {\r\n this._pointerLockRequested = requestPointerLock;\r\n if (this._renderingCanvas) {\r\n Engine._RequestFullscreen(this._renderingCanvas);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Exits full screen mode\r\n */\r\n public exitFullscreen(): void {\r\n if (this.isFullscreen) {\r\n Engine._ExitFullscreen();\r\n }\r\n }\r\n\r\n /**\r\n * Enters Pointerlock mode\r\n */\r\n public enterPointerlock(): void {\r\n if (this._renderingCanvas) {\r\n Engine._RequestPointerlock(this._renderingCanvas);\r\n }\r\n }\r\n\r\n /**\r\n * Exits Pointerlock mode\r\n */\r\n public exitPointerlock(): void {\r\n Engine._ExitPointerlock();\r\n }\r\n\r\n /**\r\n * Begin a new frame\r\n */\r\n public beginFrame(): void {\r\n this._measureFps();\r\n\r\n this.onBeginFrameObservable.notifyObservers(this);\r\n super.beginFrame();\r\n }\r\n\r\n /**\r\n * End the current frame\r\n */\r\n public endFrame(): void {\r\n super.endFrame();\r\n this._submitVRFrame();\r\n\r\n this.onEndFrameObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Resize the view according to the canvas' size\r\n * @param forceSetSize true to force setting the sizes of the underlying canvas\r\n */\r\n public resize(forceSetSize = false): void {\r\n // We're not resizing the size of the canvas while in VR mode & presenting\r\n if (this.isVRPresenting()) {\r\n return;\r\n }\r\n\r\n super.resize(forceSetSize);\r\n }\r\n\r\n /**\r\n * Force a specific size of the canvas\r\n * @param width defines the new canvas' width\r\n * @param height defines the new canvas' height\r\n * @param forceSetSize true to force setting the sizes of the underlying canvas\r\n * @returns true if the size was changed\r\n */\r\n public setSize(width: number, height: number, forceSetSize = false): boolean {\r\n if (!this._renderingCanvas) {\r\n return false;\r\n }\r\n\r\n if (!super.setSize(width, height, forceSetSize)) {\r\n return false;\r\n }\r\n\r\n if (this.scenes) {\r\n for (let index = 0; index < this.scenes.length; index++) {\r\n const scene = this.scenes[index];\r\n\r\n for (let camIndex = 0; camIndex < scene.cameras.length; camIndex++) {\r\n const cam = scene.cameras[camIndex];\r\n\r\n cam._currentRenderId = 0;\r\n }\r\n }\r\n\r\n if (this.onResizeObservable.hasObservers()) {\r\n this.onResizeObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public _deletePipelineContext(pipelineContext: IPipelineContext): void {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n if (webGLPipelineContext && webGLPipelineContext.program) {\r\n if (webGLPipelineContext.transformFeedback) {\r\n this.deleteTransformFeedback(webGLPipelineContext.transformFeedback);\r\n webGLPipelineContext.transformFeedback = null;\r\n }\r\n }\r\n super._deletePipelineContext(pipelineContext);\r\n }\r\n\r\n public createShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n defines: Nullable,\r\n context?: WebGLRenderingContext,\r\n transformFeedbackVaryings: Nullable = null\r\n ): WebGLProgram {\r\n context = context || this._gl;\r\n\r\n this.onBeforeShaderCompilationObservable.notifyObservers(this);\r\n\r\n const program = super.createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context, transformFeedbackVaryings);\r\n this.onAfterShaderCompilationObservable.notifyObservers(this);\r\n\r\n return program;\r\n }\r\n\r\n protected _createShaderProgram(\r\n pipelineContext: WebGLPipelineContext,\r\n vertexShader: WebGLShader,\r\n fragmentShader: WebGLShader,\r\n context: WebGLRenderingContext,\r\n transformFeedbackVaryings: Nullable = null\r\n ): WebGLProgram {\r\n const shaderProgram = context.createProgram();\r\n pipelineContext.program = shaderProgram;\r\n\r\n if (!shaderProgram) {\r\n throw new Error(\"Unable to create program\");\r\n }\r\n\r\n context.attachShader(shaderProgram, vertexShader);\r\n context.attachShader(shaderProgram, fragmentShader);\r\n\r\n if (this.webGLVersion > 1 && transformFeedbackVaryings) {\r\n const transformFeedback = this.createTransformFeedback();\r\n\r\n this.bindTransformFeedback(transformFeedback);\r\n this.setTranformFeedbackVaryings(shaderProgram, transformFeedbackVaryings);\r\n pipelineContext.transformFeedback = transformFeedback;\r\n }\r\n\r\n context.linkProgram(shaderProgram);\r\n\r\n if (this.webGLVersion > 1 && transformFeedbackVaryings) {\r\n this.bindTransformFeedback(null);\r\n }\r\n\r\n pipelineContext.context = context;\r\n pipelineContext.vertexShader = vertexShader;\r\n pipelineContext.fragmentShader = fragmentShader;\r\n\r\n if (!pipelineContext.isParallelCompiled) {\r\n this._finalizePipelineContext(pipelineContext);\r\n }\r\n\r\n return shaderProgram;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseTexture(texture: InternalTexture): void {\r\n super._releaseTexture(texture);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _releaseRenderTargetWrapper(rtWrapper: RenderTargetWrapper): void {\r\n super._releaseRenderTargetWrapper(rtWrapper);\r\n\r\n // Set output texture of post process to null if the framebuffer has been released/disposed\r\n this.scenes.forEach((scene) => {\r\n scene.postProcesses.forEach((postProcess) => {\r\n if (postProcess._outputTexture === rtWrapper) {\r\n postProcess._outputTexture = null;\r\n }\r\n });\r\n scene.cameras.forEach((camera) => {\r\n camera._postProcesses.forEach((postProcess) => {\r\n if (postProcess) {\r\n if (postProcess._outputTexture === rtWrapper) {\r\n postProcess._outputTexture = null;\r\n }\r\n }\r\n });\r\n });\r\n });\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _RenderPassIdCounter = 0;\r\n /**\r\n * Gets or sets the current render pass id\r\n */\r\n public currentRenderPassId = Constants.RENDERPASS_MAIN;\r\n\r\n private _renderPassNames: string[] = [\"main\"];\r\n /**\r\n * Gets the names of the render passes that are currently created\r\n * @returns list of the render pass names\r\n */\r\n public getRenderPassNames(): string[] {\r\n return this._renderPassNames;\r\n }\r\n\r\n /**\r\n * Gets the name of the current render pass\r\n * @returns name of the current render pass\r\n */\r\n public getCurrentRenderPassName(): string {\r\n return this._renderPassNames[this.currentRenderPassId];\r\n }\r\n\r\n /**\r\n * Creates a render pass id\r\n * @param name Name of the render pass (for debug purpose only)\r\n * @returns the id of the new render pass\r\n */\r\n public createRenderPassId(name?: string) {\r\n // Note: render pass id == 0 is always for the main render pass\r\n const id = ++Engine._RenderPassIdCounter;\r\n this._renderPassNames[id] = name ?? \"NONAME\";\r\n return id;\r\n }\r\n\r\n /**\r\n * Releases a render pass id\r\n * @param id id of the render pass to release\r\n */\r\n public releaseRenderPassId(id: number): void {\r\n this._renderPassNames[id] = undefined as any;\r\n\r\n for (let s = 0; s < this.scenes.length; ++s) {\r\n const scene = this.scenes[s];\r\n for (let m = 0; m < scene.meshes.length; ++m) {\r\n const mesh = scene.meshes[m];\r\n if (mesh.subMeshes) {\r\n for (let b = 0; b < mesh.subMeshes.length; ++b) {\r\n const subMesh = mesh.subMeshes[b];\r\n subMesh._removeDrawWrapper(id);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Rescales a texture\r\n * @param source input texture\r\n * @param destination destination texture\r\n * @param scene scene to use to render the resize\r\n * @param internalFormat format to use when resizing\r\n * @param onComplete callback to be called when resize has completed\r\n */\r\n public _rescaleTexture(source: InternalTexture, destination: InternalTexture, scene: Nullable, internalFormat: number, onComplete: () => void): void {\r\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR);\r\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR);\r\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);\r\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);\r\n\r\n const rtt = this.createRenderTargetTexture(\r\n {\r\n width: destination.width,\r\n height: destination.height,\r\n },\r\n {\r\n generateMipMaps: false,\r\n type: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n }\r\n );\r\n\r\n if (!this._rescalePostProcess && Engine._RescalePostProcessFactory) {\r\n this._rescalePostProcess = Engine._RescalePostProcessFactory(this);\r\n }\r\n\r\n if (this._rescalePostProcess) {\r\n this._rescalePostProcess.externalTextureSamplerBinding = true;\r\n this._rescalePostProcess.getEffect().executeWhenCompiled(() => {\r\n this._rescalePostProcess!.onApply = function (effect) {\r\n effect._bindTexture(\"textureSampler\", source);\r\n };\r\n\r\n let hostingScene: Scene = scene;\r\n\r\n if (!hostingScene) {\r\n hostingScene = this.scenes[this.scenes.length - 1];\r\n }\r\n hostingScene.postProcessManager.directRender([this._rescalePostProcess!], rtt, true);\r\n\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, destination, true);\r\n this._gl.copyTexImage2D(this._gl.TEXTURE_2D, 0, internalFormat, 0, 0, destination.width, destination.height, 0);\r\n\r\n this.unBindFramebuffer(rtt);\r\n rtt.dispose();\r\n\r\n if (onComplete) {\r\n onComplete();\r\n }\r\n });\r\n }\r\n }\r\n\r\n // FPS\r\n\r\n /**\r\n * Gets the current framerate\r\n * @returns a number representing the framerate\r\n */\r\n public getFps(): number {\r\n return this._fps;\r\n }\r\n\r\n /**\r\n * Gets the time spent between current and previous frame\r\n * @returns a number representing the delta time in ms\r\n */\r\n public getDeltaTime(): number {\r\n return this._deltaTime;\r\n }\r\n\r\n private _measureFps(): void {\r\n this._performanceMonitor.sampleFrame();\r\n this._fps = this._performanceMonitor.averageFPS;\r\n this._deltaTime = this._performanceMonitor.instantaneousFrameTime || 0;\r\n }\r\n\r\n /**\r\n * Wraps an external web gl texture in a Babylon texture.\r\n * @param texture defines the external texture\r\n * @param hasMipMaps defines whether the external texture has mip maps (default: false)\r\n * @param samplingMode defines the sampling mode for the external texture (default: Constants.TEXTURE_TRILINEAR_SAMPLINGMODE)\r\n * @returns the babylon internal texture\r\n */\r\n public wrapWebGLTexture(texture: WebGLTexture, hasMipMaps: boolean = false, samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE): InternalTexture {\r\n const hardwareTexture = new WebGLHardwareTexture(texture, this._gl);\r\n const internalTexture = new InternalTexture(this, InternalTextureSource.Unknown, true);\r\n internalTexture._hardwareTexture = hardwareTexture;\r\n internalTexture.isReady = true;\r\n internalTexture.useMipMaps = hasMipMaps;\r\n this.updateTextureSamplingMode(samplingMode, internalTexture);\r\n return internalTexture;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _uploadImageToTexture(texture: InternalTexture, image: HTMLImageElement | ImageBitmap, faceIndex: number = 0, lod: number = 0) {\r\n const gl = this._gl;\r\n\r\n const textureType = this._getWebGLTextureType(texture.type);\r\n const format = this._getInternalFormat(texture.format);\r\n const internalFormat = this._getRGBABufferInternalSizedFormat(texture.type, format);\r\n\r\n const bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;\r\n\r\n this._bindTextureDirectly(bindTarget, texture, true);\r\n this._unpackFlipY(texture.invertY);\r\n\r\n let target: GLenum = gl.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;\r\n }\r\n\r\n gl.texImage2D(target, lod, internalFormat, format, textureType, image);\r\n this._bindTextureDirectly(bindTarget, null, true);\r\n }\r\n\r\n /**\r\n * Updates a depth texture Comparison Mode and Function.\r\n * If the comparison Function is equal to 0, the mode will be set to none.\r\n * Otherwise, this only works in webgl 2 and requires a shadow sampler in the shader.\r\n * @param texture The texture to set the comparison function for\r\n * @param comparisonFunction The comparison function to set, 0 if no comparison required\r\n */\r\n public updateTextureComparisonFunction(texture: InternalTexture, comparisonFunction: number): void {\r\n if (this.webGLVersion === 1) {\r\n Logger.Error(\"WebGL 1 does not support texture comparison.\");\r\n return;\r\n }\r\n\r\n const gl = this._gl;\r\n\r\n if (texture.isCube) {\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);\r\n\r\n if (comparisonFunction === 0) {\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_FUNC, Constants.LEQUAL);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_MODE, gl.NONE);\r\n } else {\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);\r\n }\r\n\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\r\n } else {\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\r\n\r\n if (comparisonFunction === 0) {\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, Constants.LEQUAL);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.NONE);\r\n } else {\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC, comparisonFunction);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);\r\n }\r\n\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n }\r\n\r\n texture._comparisonFunction = comparisonFunction;\r\n }\r\n\r\n /**\r\n * Creates a webGL buffer to use with instantiation\r\n * @param capacity defines the size of the buffer\r\n * @returns the webGL buffer\r\n */\r\n public createInstancesBuffer(capacity: number): DataBuffer {\r\n const buffer = this._gl.createBuffer();\r\n\r\n if (!buffer) {\r\n throw new Error(\"Unable to create instance buffer\");\r\n }\r\n\r\n const result = new WebGLDataBuffer(buffer);\r\n result.capacity = capacity;\r\n\r\n this.bindArrayBuffer(result);\r\n this._gl.bufferData(this._gl.ARRAY_BUFFER, capacity, this._gl.DYNAMIC_DRAW);\r\n\r\n result.references = 1;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Delete a webGL buffer used with instantiation\r\n * @param buffer defines the webGL buffer to delete\r\n */\r\n public deleteInstancesBuffer(buffer: WebGLBuffer): void {\r\n this._gl.deleteBuffer(buffer);\r\n }\r\n\r\n private _clientWaitAsync(sync: WebGLSync, flags = 0, intervalms = 10): Promise {\r\n const gl = (this._gl as any);\r\n return new Promise((resolve, reject) => {\r\n const check = () => {\r\n const res = gl.clientWaitSync(sync, flags, 0);\r\n if (res == gl.WAIT_FAILED) {\r\n reject();\r\n return;\r\n }\r\n if (res == gl.TIMEOUT_EXPIRED) {\r\n setTimeout(check, intervalms);\r\n return;\r\n }\r\n resolve();\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _readPixelsAsync(x: number, y: number, w: number, h: number, format: number, type: number, outputBuffer: ArrayBufferView) {\r\n if (this._webGLVersion < 2) {\r\n throw new Error(\"_readPixelsAsync only work on WebGL2+\");\r\n }\r\n\r\n const gl = (this._gl as any);\r\n const buf = gl.createBuffer();\r\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);\r\n gl.bufferData(gl.PIXEL_PACK_BUFFER, outputBuffer.byteLength, gl.STREAM_READ);\r\n gl.readPixels(x, y, w, h, format, type, 0);\r\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\r\n\r\n const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);\r\n if (!sync) {\r\n return null;\r\n }\r\n\r\n gl.flush();\r\n\r\n return this._clientWaitAsync(sync, 0, 10).then(() => {\r\n gl.deleteSync(sync);\r\n\r\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);\r\n gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, outputBuffer);\r\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\r\n gl.deleteBuffer(buf);\r\n\r\n return outputBuffer;\r\n });\r\n }\r\n\r\n public dispose(): void {\r\n this.hideLoadingUI();\r\n\r\n this.onNewSceneAddedObservable.clear();\r\n\r\n // Release postProcesses\r\n while (this.postProcesses.length) {\r\n this.postProcesses[0].dispose();\r\n }\r\n\r\n // Rescale PP\r\n if (this._rescalePostProcess) {\r\n this._rescalePostProcess.dispose();\r\n }\r\n\r\n // Release scenes\r\n while (this.scenes.length) {\r\n this.scenes[0].dispose();\r\n }\r\n\r\n while (this._virtualScenes.length) {\r\n this._virtualScenes[0].dispose();\r\n }\r\n\r\n // Release audio engine\r\n if (EngineStore.Instances.length === 1 && Engine.audioEngine) {\r\n Engine.audioEngine.dispose();\r\n Engine.audioEngine = null;\r\n }\r\n\r\n //WebVR\r\n this.disableVR();\r\n\r\n // Events\r\n const hostWindow = this.getHostWindow(); // it calls IsWindowObjectExist()\r\n if (hostWindow && typeof hostWindow.removeEventListener === \"function\") {\r\n hostWindow.removeEventListener(\"blur\", this._onBlur);\r\n hostWindow.removeEventListener(\"focus\", this._onFocus);\r\n }\r\n\r\n if (this._renderingCanvas) {\r\n this._renderingCanvas.removeEventListener(\"focus\", this._onCanvasFocus);\r\n this._renderingCanvas.removeEventListener(\"blur\", this._onCanvasBlur);\r\n this._renderingCanvas.removeEventListener(\"pointerout\", this._onCanvasPointerOut);\r\n this._renderingCanvas.removeEventListener(\"contextmenu\", this._onCanvasContextMenu);\r\n }\r\n\r\n if (IsDocumentAvailable()) {\r\n document.removeEventListener(\"fullscreenchange\", this._onFullscreenChange);\r\n document.removeEventListener(\"mozfullscreenchange\", this._onFullscreenChange);\r\n document.removeEventListener(\"webkitfullscreenchange\", this._onFullscreenChange);\r\n document.removeEventListener(\"msfullscreenchange\", this._onFullscreenChange);\r\n document.removeEventListener(\"pointerlockchange\", this._onPointerLockChange);\r\n document.removeEventListener(\"mspointerlockchange\", this._onPointerLockChange);\r\n document.removeEventListener(\"mozpointerlockchange\", this._onPointerLockChange);\r\n document.removeEventListener(\"webkitpointerlockchange\", this._onPointerLockChange);\r\n }\r\n\r\n super.dispose();\r\n\r\n // Remove from Instances\r\n const index = EngineStore.Instances.indexOf(this);\r\n\r\n if (index >= 0) {\r\n EngineStore.Instances.splice(index, 1);\r\n }\r\n\r\n // no more engines left in the engine store? Notify!\r\n if (!Engine.Instances.length) {\r\n EngineStore.OnEnginesDisposedObservable.notifyObservers(this);\r\n }\r\n\r\n // Observables\r\n this.onResizeObservable.clear();\r\n this.onCanvasBlurObservable.clear();\r\n this.onCanvasFocusObservable.clear();\r\n this.onCanvasPointerOutObservable.clear();\r\n this.onBeginFrameObservable.clear();\r\n this.onEndFrameObservable.clear();\r\n }\r\n\r\n private _disableTouchAction(): void {\r\n if (!this._renderingCanvas || !this._renderingCanvas.setAttribute) {\r\n return;\r\n }\r\n\r\n this._renderingCanvas.setAttribute(\"touch-action\", \"none\");\r\n this._renderingCanvas.style.touchAction = \"none\";\r\n (this._renderingCanvas.style as any).webkitTapHighlightColor = \"transparent\";\r\n }\r\n\r\n // Loading screen\r\n\r\n /**\r\n * Display the loading screen\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\r\n */\r\n public displayLoadingUI(): void {\r\n if (!IsWindowObjectExist()) {\r\n return;\r\n }\r\n const loadingScreen = this.loadingScreen;\r\n if (loadingScreen) {\r\n loadingScreen.displayLoadingUI();\r\n }\r\n }\r\n\r\n /**\r\n * Hide the loading screen\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\r\n */\r\n public hideLoadingUI(): void {\r\n if (!IsWindowObjectExist()) {\r\n return;\r\n }\r\n const loadingScreen = this._loadingScreen;\r\n if (loadingScreen) {\r\n loadingScreen.hideLoadingUI();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current loading screen object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\r\n */\r\n public get loadingScreen(): ILoadingScreen {\r\n if (!this._loadingScreen && this._renderingCanvas) {\r\n this._loadingScreen = Engine.DefaultLoadingScreenFactory(this._renderingCanvas);\r\n }\r\n return this._loadingScreen;\r\n }\r\n\r\n /**\r\n * Sets the current loading screen object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\r\n */\r\n public set loadingScreen(loadingScreen: ILoadingScreen) {\r\n this._loadingScreen = loadingScreen;\r\n }\r\n\r\n /**\r\n * Sets the current loading screen text\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\r\n */\r\n public set loadingUIText(text: string) {\r\n this.loadingScreen.loadingUIText = text;\r\n }\r\n\r\n /**\r\n * Sets the current loading screen background color\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen\r\n */\r\n public set loadingUIBackgroundColor(color: string) {\r\n this.loadingScreen.loadingUIBackgroundColor = color;\r\n }\r\n\r\n /**\r\n * creates and returns a new video element\r\n * @param constraints video constraints\r\n * @returns video element\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public createVideoElement(constraints: MediaTrackConstraints): any {\r\n return document.createElement(\"video\");\r\n }\r\n\r\n /** Pointerlock and fullscreen */\r\n\r\n /**\r\n * Ask the browser to promote the current element to pointerlock mode\r\n * @param element defines the DOM element to promote\r\n */\r\n static _RequestPointerlock(element: HTMLElement): void {\r\n if (element.requestPointerLock) {\r\n // In some browsers, requestPointerLock returns a promise.\r\n // Handle possible rejections to avoid an unhandled top-level exception.\r\n const promise: unknown = element.requestPointerLock();\r\n if (promise instanceof Promise)\r\n promise\r\n .then(() => {\r\n element.focus();\r\n })\r\n .catch(() => {});\r\n else element.focus();\r\n }\r\n }\r\n\r\n /**\r\n * Asks the browser to exit pointerlock mode\r\n */\r\n static _ExitPointerlock(): void {\r\n if (document.exitPointerLock) {\r\n document.exitPointerLock();\r\n }\r\n }\r\n\r\n /**\r\n * Ask the browser to promote the current element to fullscreen rendering mode\r\n * @param element defines the DOM element to promote\r\n */\r\n static _RequestFullscreen(element: HTMLElement): void {\r\n const requestFunction = element.requestFullscreen || (element).webkitRequestFullscreen;\r\n if (!requestFunction) {\r\n return;\r\n }\r\n requestFunction.call(element);\r\n }\r\n\r\n /**\r\n * Asks the browser to exit fullscreen mode\r\n */\r\n static _ExitFullscreen(): void {\r\n const anyDoc = document as any;\r\n\r\n if (document.exitFullscreen) {\r\n document.exitFullscreen();\r\n } else if (anyDoc.webkitCancelFullScreen) {\r\n anyDoc.webkitCancelFullScreen();\r\n }\r\n }\r\n\r\n /**\r\n * Get Font size information\r\n * @param font font name\r\n * @returns an object containing ascent, height and descent\r\n */\r\n public getFontOffset(font: string): { ascent: number; height: number; descent: number } {\r\n const text = document.createElement(\"span\");\r\n text.innerHTML = \"Hg\";\r\n text.setAttribute(\"style\", `font: ${font} !important`);\r\n\r\n const block = document.createElement(\"div\");\r\n block.style.display = \"inline-block\";\r\n block.style.width = \"1px\";\r\n block.style.height = \"0px\";\r\n block.style.verticalAlign = \"bottom\";\r\n\r\n const div = document.createElement(\"div\");\r\n div.style.whiteSpace = \"nowrap\";\r\n div.appendChild(text);\r\n div.appendChild(block);\r\n\r\n document.body.appendChild(div);\r\n\r\n let fontAscent = 0;\r\n let fontHeight = 0;\r\n try {\r\n fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;\r\n block.style.verticalAlign = \"baseline\";\r\n fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;\r\n } finally {\r\n document.body.removeChild(div);\r\n }\r\n return { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };\r\n }\r\n}\r\n","import { Vector3 } from \"./math.vector\";\r\n\r\n/** Defines supported spaces */\r\nexport enum Space {\r\n /** Local (object) space */\r\n LOCAL = 0,\r\n /** World space */\r\n WORLD = 1,\r\n /** Bone space */\r\n BONE = 2,\r\n}\r\n\r\n/** Defines the 3 main axes */\r\nexport class Axis {\r\n /** X axis */\r\n public static X: Vector3 = new Vector3(1.0, 0.0, 0.0);\r\n /** Y axis */\r\n public static Y: Vector3 = new Vector3(0.0, 1.0, 0.0);\r\n /** Z axis */\r\n public static Z: Vector3 = new Vector3(0.0, 0.0, 1.0);\r\n}\r\n\r\n/**\r\n * Defines cartesian components.\r\n */\r\nexport enum Coordinate {\r\n /** X axis */\r\n X,\r\n /** Y axis */\r\n Y,\r\n /** Z axis */\r\n Z,\r\n}\r\n","import type { DeepImmutable, Nullable } from \"../types\";\r\nimport { serialize, serializeAsVector3, serializeAsQuaternion, SerializationHelper } from \"../Misc/decorators\";\r\nimport { Observable } from \"../Misc/observable\";\r\n\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Quaternion, Matrix, Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { Bone } from \"../Bones/bone\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Space } from \"../Maths/math.axis\";\r\n\r\nconst convertRHSToLHS = Matrix.Compose(Vector3.One(), Quaternion.FromEulerAngles(0, Math.PI, 0), Vector3.Zero());\r\n\r\n/**\r\n * A TransformNode is an object that is not rendered but can be used as a center of transformation. This can decrease memory usage and increase rendering speed compared to using an empty mesh as a parent and is less complicated than using a pivot matrix.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/transform_node\r\n */\r\nexport class TransformNode extends Node {\r\n // Statics\r\n /**\r\n * Object will not rotate to face the camera\r\n */\r\n public static BILLBOARDMODE_NONE = 0;\r\n /**\r\n * Object will rotate to face the camera but only on the x axis\r\n */\r\n public static BILLBOARDMODE_X = 1;\r\n /**\r\n * Object will rotate to face the camera but only on the y axis\r\n */\r\n public static BILLBOARDMODE_Y = 2;\r\n /**\r\n * Object will rotate to face the camera but only on the z axis\r\n */\r\n public static BILLBOARDMODE_Z = 4;\r\n /**\r\n * Object will rotate to face the camera\r\n */\r\n public static BILLBOARDMODE_ALL = 7;\r\n /**\r\n * Object will rotate to face the camera's position instead of orientation\r\n */\r\n public static BILLBOARDMODE_USE_POSITION = 128;\r\n /**\r\n * Child transform with Billboard flags should or should not apply parent rotation (default if off)\r\n */\r\n public static BillboardUseParentOrientation: boolean = false;\r\n\r\n private static _TmpRotation = Quaternion.Zero();\r\n private static _TmpScaling = Vector3.Zero();\r\n private static _TmpTranslation = Vector3.Zero();\r\n\r\n private _forward = new Vector3(0, 0, 1);\r\n private _up = new Vector3(0, 1, 0);\r\n private _right = new Vector3(1, 0, 0);\r\n\r\n // Properties\r\n @serializeAsVector3(\"position\")\r\n private _position = Vector3.Zero();\r\n\r\n @serializeAsVector3(\"rotation\")\r\n private _rotation = Vector3.Zero();\r\n\r\n @serializeAsQuaternion(\"rotationQuaternion\")\r\n private _rotationQuaternion: Nullable = null;\r\n\r\n @serializeAsVector3(\"scaling\")\r\n protected _scaling = Vector3.One();\r\n private _transformToBoneReferal: Nullable = null;\r\n private _currentParentWhenAttachingToBone: Nullable;\r\n private _isAbsoluteSynced = false;\r\n\r\n @serialize(\"billboardMode\")\r\n private _billboardMode = TransformNode.BILLBOARDMODE_NONE;\r\n\r\n /**\r\n * Gets or sets the billboard mode. Default is 0.\r\n *\r\n * | Value | Type | Description |\r\n * | --- | --- | --- |\r\n * | 0 | BILLBOARDMODE_NONE | |\r\n * | 1 | BILLBOARDMODE_X | |\r\n * | 2 | BILLBOARDMODE_Y | |\r\n * | 4 | BILLBOARDMODE_Z | |\r\n * | 7 | BILLBOARDMODE_ALL | |\r\n *\r\n */\r\n public get billboardMode() {\r\n return this._billboardMode;\r\n }\r\n\r\n public set billboardMode(value: number) {\r\n if (this._billboardMode === value) {\r\n return;\r\n }\r\n this._billboardMode = value;\r\n this._cache.useBillboardPosition = (this._billboardMode & TransformNode.BILLBOARDMODE_USE_POSITION) !== 0;\r\n this._computeUseBillboardPath();\r\n }\r\n\r\n private _preserveParentRotationForBillboard = false;\r\n /**\r\n * Gets or sets a boolean indicating that parent rotation should be preserved when using billboards.\r\n * This could be useful for glTF objects where parent rotation helps converting from right handed to left handed\r\n */\r\n public get preserveParentRotationForBillboard() {\r\n return this._preserveParentRotationForBillboard;\r\n }\r\n\r\n public set preserveParentRotationForBillboard(value: boolean) {\r\n if (value === this._preserveParentRotationForBillboard) {\r\n return;\r\n }\r\n this._preserveParentRotationForBillboard = value;\r\n this._computeUseBillboardPath();\r\n }\r\n\r\n private _computeUseBillboardPath(): void {\r\n this._cache.useBillboardPath = this._billboardMode !== TransformNode.BILLBOARDMODE_NONE && !this.preserveParentRotationForBillboard;\r\n }\r\n\r\n /**\r\n * Multiplication factor on scale x/y/z when computing the world matrix. Eg. for a 1x1x1 cube setting this to 2 will make it a 2x2x2 cube\r\n */\r\n @serialize()\r\n public scalingDeterminant = 1;\r\n\r\n @serialize(\"infiniteDistance\")\r\n private _infiniteDistance = false;\r\n\r\n /**\r\n * Gets or sets the distance of the object to max, often used by skybox\r\n */\r\n public get infiniteDistance() {\r\n return this._infiniteDistance;\r\n }\r\n\r\n public set infiniteDistance(value: boolean) {\r\n if (this._infiniteDistance === value) {\r\n return;\r\n }\r\n\r\n this._infiniteDistance = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that non uniform scaling (when at least one component is different from others) should be ignored.\r\n * By default the system will update normals to compensate\r\n */\r\n @serialize()\r\n public ignoreNonUniformScaling = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that even if rotationQuaternion is defined, you can keep updating rotation property and Babylon.js will just mix both\r\n */\r\n @serialize()\r\n public reIntegrateRotationIntoRotationQuaternion = false;\r\n\r\n // Cache\r\n /** @internal */\r\n public _poseMatrix: Nullable = null;\r\n /** @internal */\r\n public _localMatrix = Matrix.Zero();\r\n\r\n private _usePivotMatrix = false;\r\n private _absolutePosition = Vector3.Zero();\r\n private _absoluteScaling = Vector3.Zero();\r\n private _absoluteRotationQuaternion = Quaternion.Identity();\r\n private _pivotMatrix = Matrix.Identity();\r\n private _pivotMatrixInverse: Matrix;\r\n /** @internal */\r\n public _postMultiplyPivotMatrix = false;\r\n\r\n protected _isWorldMatrixFrozen = false;\r\n\r\n /** @internal */\r\n public _indexInSceneTransformNodesArray = -1;\r\n\r\n /**\r\n * An event triggered after the world matrix is updated\r\n */\r\n public onAfterWorldMatrixUpdateObservable = new Observable();\r\n\r\n constructor(name: string, scene: Nullable = null, isPure = true) {\r\n super(name, scene);\r\n\r\n if (isPure) {\r\n this.getScene().addTransformNode(this);\r\n }\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"TransformNode\" string\r\n */\r\n public getClassName(): string {\r\n return \"TransformNode\";\r\n }\r\n\r\n /**\r\n * Gets or set the node position (default is (0.0, 0.0, 0.0))\r\n */\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n\r\n public set position(newPosition: Vector3) {\r\n this._position = newPosition;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * return true if a pivot has been set\r\n * @returns true if a pivot matrix is used\r\n */\r\n public isUsingPivotMatrix(): boolean {\r\n return this._usePivotMatrix;\r\n }\r\n\r\n /**\r\n * Gets or sets the rotation property : a Vector3 defining the rotation value in radians around each local axis X, Y, Z (default is (0.0, 0.0, 0.0)).\r\n * If rotation quaternion is set, this Vector3 will be ignored and copy from the quaternion\r\n */\r\n public get rotation(): Vector3 {\r\n return this._rotation;\r\n }\r\n\r\n public set rotation(newRotation: Vector3) {\r\n this._rotation = newRotation;\r\n this._rotationQuaternion = null;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Gets or sets the scaling property : a Vector3 defining the node scaling along each local axis X, Y, Z (default is (1.0, 1.0, 1.0)).\r\n */\r\n public get scaling(): Vector3 {\r\n return this._scaling;\r\n }\r\n\r\n public set scaling(newScaling: Vector3) {\r\n this._scaling = newScaling;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Gets or sets the rotation Quaternion property : this a Quaternion object defining the node rotation by using a unit quaternion (undefined by default, but can be null).\r\n * If set, only the rotationQuaternion is then used to compute the node rotation (ie. node.rotation will be ignored)\r\n */\r\n public get rotationQuaternion(): Nullable {\r\n return this._rotationQuaternion;\r\n }\r\n\r\n public set rotationQuaternion(quaternion: Nullable) {\r\n this._rotationQuaternion = quaternion;\r\n //reset the rotation vector.\r\n if (quaternion) {\r\n this._rotation.setAll(0.0);\r\n }\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * The forward direction of that transform in world space.\r\n */\r\n public get forward(): Vector3 {\r\n Vector3.TransformNormalFromFloatsToRef(0, 0, this.getScene().useRightHandedSystem ? -1.0 : 1.0, this.getWorldMatrix(), this._forward);\r\n return this._forward.normalize();\r\n }\r\n\r\n /**\r\n * The up direction of that transform in world space.\r\n */\r\n public get up(): Vector3 {\r\n Vector3.TransformNormalFromFloatsToRef(0, 1, 0, this.getWorldMatrix(), this._up);\r\n return this._up.normalize();\r\n }\r\n\r\n /**\r\n * The right direction of that transform in world space.\r\n */\r\n public get right(): Vector3 {\r\n Vector3.TransformNormalFromFloatsToRef(this.getScene().useRightHandedSystem ? -1.0 : 1.0, 0, 0, this.getWorldMatrix(), this._right);\r\n return this._right.normalize();\r\n }\r\n\r\n /**\r\n * Copies the parameter passed Matrix into the mesh Pose matrix.\r\n * @param matrix the matrix to copy the pose from\r\n * @returns this TransformNode.\r\n */\r\n public updatePoseMatrix(matrix: Matrix): TransformNode {\r\n if (!this._poseMatrix) {\r\n this._poseMatrix = matrix.clone();\r\n return this;\r\n }\r\n this._poseMatrix.copyFrom(matrix);\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the mesh Pose matrix.\r\n * @returns the pose matrix\r\n */\r\n public getPoseMatrix(): Matrix {\r\n if (!this._poseMatrix) {\r\n this._poseMatrix = Matrix.Identity();\r\n }\r\n return this._poseMatrix;\r\n }\r\n\r\n /** @internal */\r\n public _isSynchronized(): boolean {\r\n const cache = this._cache;\r\n\r\n if (this._billboardMode !== cache.billboardMode || this._billboardMode !== TransformNode.BILLBOARDMODE_NONE) {\r\n return false;\r\n }\r\n\r\n if (cache.pivotMatrixUpdated) {\r\n return false;\r\n }\r\n\r\n if (this._infiniteDistance) {\r\n return false;\r\n }\r\n\r\n if (this._position._isDirty) {\r\n return false;\r\n }\r\n\r\n if (this._scaling._isDirty) {\r\n return false;\r\n }\r\n\r\n if ((this._rotationQuaternion && this._rotationQuaternion._isDirty) || this._rotation._isDirty) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public _initCache() {\r\n super._initCache();\r\n\r\n const cache = this._cache;\r\n cache.localMatrixUpdated = false;\r\n cache.billboardMode = -1;\r\n cache.infiniteDistance = false;\r\n cache.useBillboardPosition = false;\r\n cache.useBillboardPath = false;\r\n }\r\n\r\n /**\r\n * Returns the current mesh absolute position.\r\n * Returns a Vector3.\r\n */\r\n public get absolutePosition(): Vector3 {\r\n return this.getAbsolutePosition();\r\n }\r\n\r\n /**\r\n * Returns the current mesh absolute scaling.\r\n * Returns a Vector3.\r\n */\r\n public get absoluteScaling(): Vector3 {\r\n this._syncAbsoluteScalingAndRotation();\r\n return this._absoluteScaling;\r\n }\r\n\r\n /**\r\n * Returns the current mesh absolute rotation.\r\n * Returns a Quaternion.\r\n */\r\n public get absoluteRotationQuaternion(): Quaternion {\r\n this._syncAbsoluteScalingAndRotation();\r\n return this._absoluteRotationQuaternion;\r\n }\r\n\r\n /**\r\n * Sets a new matrix to apply before all other transformation\r\n * @param matrix defines the transform matrix\r\n * @returns the current TransformNode\r\n */\r\n public setPreTransformMatrix(matrix: Matrix): TransformNode {\r\n return this.setPivotMatrix(matrix, false);\r\n }\r\n\r\n /**\r\n * Sets a new pivot matrix to the current node\r\n * @param matrix defines the new pivot matrix to use\r\n * @param postMultiplyPivotMatrix defines if the pivot matrix must be cancelled in the world matrix. When this parameter is set to true (default), the inverse of the pivot matrix is also applied at the end to cancel the transformation effect\r\n * @returns the current TransformNode\r\n */\r\n public setPivotMatrix(matrix: DeepImmutable, postMultiplyPivotMatrix = true): TransformNode {\r\n this._pivotMatrix.copyFrom(matrix);\r\n this._usePivotMatrix = !this._pivotMatrix.isIdentity();\r\n\r\n this._cache.pivotMatrixUpdated = true;\r\n this._postMultiplyPivotMatrix = postMultiplyPivotMatrix;\r\n\r\n if (this._postMultiplyPivotMatrix) {\r\n if (!this._pivotMatrixInverse) {\r\n this._pivotMatrixInverse = Matrix.Invert(this._pivotMatrix);\r\n } else {\r\n this._pivotMatrix.invertToRef(this._pivotMatrixInverse);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the mesh pivot matrix.\r\n * Default : Identity.\r\n * @returns the matrix\r\n */\r\n public getPivotMatrix(): Matrix {\r\n return this._pivotMatrix;\r\n }\r\n\r\n /**\r\n * Instantiate (when possible) or clone that node with its hierarchy\r\n * @param newParent defines the new parent to use for the instance (or clone)\r\n * @param options defines options to configure how copy is done\r\n * @param options.doNotInstantiate defines if the model must be instantiated or just cloned\r\n * @param onNewNodeCreated defines an option callback to call when a clone or an instance is created\r\n * @returns an instance (or a clone) of the current node with its hierarchy\r\n */\r\n public instantiateHierarchy(\r\n newParent: Nullable = null,\r\n options?: { doNotInstantiate: boolean | ((node: TransformNode) => boolean) },\r\n onNewNodeCreated?: (source: TransformNode, clone: TransformNode) => void\r\n ): Nullable {\r\n const clone = this.clone(\"Clone of \" + (this.name || this.id), newParent || this.parent, true);\r\n\r\n if (clone) {\r\n if (onNewNodeCreated) {\r\n onNewNodeCreated(this, clone);\r\n }\r\n }\r\n\r\n for (const child of this.getChildTransformNodes(true)) {\r\n child.instantiateHierarchy(clone, options, onNewNodeCreated);\r\n }\r\n\r\n return clone;\r\n }\r\n\r\n /**\r\n * Prevents the World matrix to be computed any longer\r\n * @param newWorldMatrix defines an optional matrix to use as world matrix\r\n * @param decompose defines whether to decompose the given newWorldMatrix or directly assign\r\n * @returns the TransformNode.\r\n */\r\n public freezeWorldMatrix(newWorldMatrix: Nullable = null, decompose = false): TransformNode {\r\n if (newWorldMatrix) {\r\n if (decompose) {\r\n this._rotation.setAll(0);\r\n this._rotationQuaternion = this._rotationQuaternion || Quaternion.Identity();\r\n newWorldMatrix.decompose(this._scaling, this._rotationQuaternion, this._position);\r\n this.computeWorldMatrix(true);\r\n } else {\r\n this._worldMatrix = newWorldMatrix;\r\n this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);\r\n this._afterComputeWorldMatrix();\r\n }\r\n } else {\r\n this._isWorldMatrixFrozen = false; // no guarantee world is not already frozen, switch off temporarily\r\n this.computeWorldMatrix(true);\r\n }\r\n this._isDirty = false;\r\n this._isWorldMatrixFrozen = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Allows back the World matrix computation.\r\n * @returns the TransformNode.\r\n */\r\n public unfreezeWorldMatrix() {\r\n this._isWorldMatrixFrozen = false;\r\n this.computeWorldMatrix(true);\r\n return this;\r\n }\r\n\r\n /**\r\n * True if the World matrix has been frozen.\r\n */\r\n public get isWorldMatrixFrozen(): boolean {\r\n return this._isWorldMatrixFrozen;\r\n }\r\n\r\n /**\r\n * Returns the mesh absolute position in the World.\r\n * @returns a Vector3.\r\n */\r\n public getAbsolutePosition(): Vector3 {\r\n this.computeWorldMatrix();\r\n return this._absolutePosition;\r\n }\r\n\r\n /**\r\n * Sets the mesh absolute position in the World from a Vector3 or an Array(3).\r\n * @param absolutePosition the absolute position to set\r\n * @returns the TransformNode.\r\n */\r\n public setAbsolutePosition(absolutePosition: Vector3): TransformNode {\r\n if (!absolutePosition) {\r\n return this;\r\n }\r\n let absolutePositionX;\r\n let absolutePositionY;\r\n let absolutePositionZ;\r\n if (absolutePosition.x === undefined) {\r\n if (arguments.length < 3) {\r\n return this;\r\n }\r\n absolutePositionX = arguments[0];\r\n absolutePositionY = arguments[1];\r\n absolutePositionZ = arguments[2];\r\n } else {\r\n absolutePositionX = absolutePosition.x;\r\n absolutePositionY = absolutePosition.y;\r\n absolutePositionZ = absolutePosition.z;\r\n }\r\n if (this.parent) {\r\n const invertParentWorldMatrix = TmpVectors.Matrix[0];\r\n this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);\r\n Vector3.TransformCoordinatesFromFloatsToRef(absolutePositionX, absolutePositionY, absolutePositionZ, invertParentWorldMatrix, this.position);\r\n } else {\r\n this.position.x = absolutePositionX;\r\n this.position.y = absolutePositionY;\r\n this.position.z = absolutePositionZ;\r\n }\r\n\r\n this._absolutePosition.copyFrom(absolutePosition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the mesh position in its local space.\r\n * @param vector3 the position to set in localspace\r\n * @returns the TransformNode.\r\n */\r\n public setPositionWithLocalVector(vector3: Vector3): TransformNode {\r\n this.computeWorldMatrix();\r\n this.position = Vector3.TransformNormal(vector3, this._localMatrix);\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the mesh position in the local space from the current World matrix values.\r\n * @returns a new Vector3.\r\n */\r\n public getPositionExpressedInLocalSpace(): Vector3 {\r\n this.computeWorldMatrix();\r\n const invLocalWorldMatrix = TmpVectors.Matrix[0];\r\n this._localMatrix.invertToRef(invLocalWorldMatrix);\r\n return Vector3.TransformNormal(this.position, invLocalWorldMatrix);\r\n }\r\n\r\n /**\r\n * Translates the mesh along the passed Vector3 in its local space.\r\n * @param vector3 the distance to translate in localspace\r\n * @returns the TransformNode.\r\n */\r\n public locallyTranslate(vector3: Vector3): TransformNode {\r\n this.computeWorldMatrix(true);\r\n this.position = Vector3.TransformCoordinates(vector3, this._localMatrix);\r\n return this;\r\n }\r\n\r\n private static _LookAtVectorCache = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * Orients a mesh towards a target point. Mesh must be drawn facing user.\r\n * @param targetPoint the position (must be in same space as current mesh) to look at\r\n * @param yawCor optional yaw (y-axis) correction in radians\r\n * @param pitchCor optional pitch (x-axis) correction in radians\r\n * @param rollCor optional roll (z-axis) correction in radians\r\n * @param space the chosen space of the target\r\n * @returns the TransformNode.\r\n */\r\n public lookAt(targetPoint: Vector3, yawCor: number = 0, pitchCor: number = 0, rollCor: number = 0, space: Space = Space.LOCAL): TransformNode {\r\n const dv = TransformNode._LookAtVectorCache;\r\n const pos = space === Space.LOCAL ? this.position : this.getAbsolutePosition();\r\n targetPoint.subtractToRef(pos, dv);\r\n this.setDirection(dv, yawCor, pitchCor, rollCor);\r\n\r\n // Correct for parent's rotation offset\r\n if (space === Space.WORLD && this.parent) {\r\n if (this.rotationQuaternion) {\r\n // Get local rotation matrix of the looking object\r\n const rotationMatrix = TmpVectors.Matrix[0];\r\n this.rotationQuaternion.toRotationMatrix(rotationMatrix);\r\n\r\n // Offset rotation by parent's inverted rotation matrix to correct in world space\r\n const parentRotationMatrix = TmpVectors.Matrix[1];\r\n this.parent.getWorldMatrix().getRotationMatrixToRef(parentRotationMatrix);\r\n parentRotationMatrix.invert();\r\n rotationMatrix.multiplyToRef(parentRotationMatrix, rotationMatrix);\r\n this.rotationQuaternion.fromRotationMatrix(rotationMatrix);\r\n } else {\r\n // Get local rotation matrix of the looking object\r\n const quaternionRotation = TmpVectors.Quaternion[0];\r\n Quaternion.FromEulerVectorToRef(this.rotation, quaternionRotation);\r\n const rotationMatrix = TmpVectors.Matrix[0];\r\n quaternionRotation.toRotationMatrix(rotationMatrix);\r\n\r\n // Offset rotation by parent's inverted rotation matrix to correct in world space\r\n const parentRotationMatrix = TmpVectors.Matrix[1];\r\n this.parent.getWorldMatrix().getRotationMatrixToRef(parentRotationMatrix);\r\n parentRotationMatrix.invert();\r\n rotationMatrix.multiplyToRef(parentRotationMatrix, rotationMatrix);\r\n quaternionRotation.fromRotationMatrix(rotationMatrix);\r\n quaternionRotation.toEulerAnglesToRef(this.rotation);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 that is the localAxis, expressed in the mesh local space, rotated like the mesh.\r\n * This Vector3 is expressed in the World space.\r\n * @param localAxis axis to rotate\r\n * @returns a new Vector3 that is the localAxis, expressed in the mesh local space, rotated like the mesh.\r\n */\r\n public getDirection(localAxis: Vector3): Vector3 {\r\n const result = Vector3.Zero();\r\n\r\n this.getDirectionToRef(localAxis, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Sets the Vector3 \"result\" as the rotated Vector3 \"localAxis\" in the same rotation than the mesh.\r\n * localAxis is expressed in the mesh local space.\r\n * result is computed in the World space from the mesh World matrix.\r\n * @param localAxis axis to rotate\r\n * @param result the resulting transformnode\r\n * @returns this TransformNode.\r\n */\r\n public getDirectionToRef(localAxis: Vector3, result: Vector3): TransformNode {\r\n Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets this transform node rotation to the given local axis.\r\n * @param localAxis the axis in local space\r\n * @param yawCor optional yaw (y-axis) correction in radians\r\n * @param pitchCor optional pitch (x-axis) correction in radians\r\n * @param rollCor optional roll (z-axis) correction in radians\r\n * @returns this TransformNode\r\n */\r\n public setDirection(localAxis: Vector3, yawCor: number = 0, pitchCor: number = 0, rollCor: number = 0): TransformNode {\r\n const yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;\r\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\r\n const pitch = -Math.atan2(localAxis.y, len);\r\n if (this.rotationQuaternion) {\r\n Quaternion.RotationYawPitchRollToRef(yaw + yawCor, pitch + pitchCor, rollCor, this.rotationQuaternion);\r\n } else {\r\n this.rotation.x = pitch + pitchCor;\r\n this.rotation.y = yaw + yawCor;\r\n this.rotation.z = rollCor;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a new pivot point to the current node\r\n * @param point defines the new pivot point to use\r\n * @param space defines if the point is in world or local space (local by default)\r\n * @returns the current TransformNode\r\n */\r\n public setPivotPoint(point: Vector3, space: Space = Space.LOCAL): TransformNode {\r\n if (this.getScene().getRenderId() == 0) {\r\n this.computeWorldMatrix(true);\r\n }\r\n\r\n const wm = this.getWorldMatrix();\r\n\r\n if (space == Space.WORLD) {\r\n const tmat = TmpVectors.Matrix[0];\r\n wm.invertToRef(tmat);\r\n point = Vector3.TransformCoordinates(point, tmat);\r\n }\r\n\r\n return this.setPivotMatrix(Matrix.Translation(-point.x, -point.y, -point.z), true);\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the mesh pivot point coordinates in the local space.\r\n * @returns the pivot point\r\n */\r\n public getPivotPoint(): Vector3 {\r\n const point = Vector3.Zero();\r\n this.getPivotPointToRef(point);\r\n return point;\r\n }\r\n\r\n /**\r\n * Sets the passed Vector3 \"result\" with the coordinates of the mesh pivot point in the local space.\r\n * @param result the vector3 to store the result\r\n * @returns this TransformNode.\r\n */\r\n public getPivotPointToRef(result: Vector3): TransformNode {\r\n result.x = -this._pivotMatrix.m[12];\r\n result.y = -this._pivotMatrix.m[13];\r\n result.z = -this._pivotMatrix.m[14];\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 set with the mesh pivot point World coordinates.\r\n * @returns a new Vector3 set with the mesh pivot point World coordinates.\r\n */\r\n public getAbsolutePivotPoint(): Vector3 {\r\n const point = Vector3.Zero();\r\n this.getAbsolutePivotPointToRef(point);\r\n return point;\r\n }\r\n\r\n /**\r\n * Sets the Vector3 \"result\" coordinates with the mesh pivot point World coordinates.\r\n * @param result vector3 to store the result\r\n * @returns this TransformNode.\r\n */\r\n public getAbsolutePivotPointToRef(result: Vector3): TransformNode {\r\n this.getPivotPointToRef(result);\r\n Vector3.TransformCoordinatesToRef(result, this.getWorldMatrix(), result);\r\n return this;\r\n }\r\n\r\n /**\r\n * Flag the transform node as dirty (Forcing it to update everything)\r\n * @param property if set to \"rotation\" the objects rotationQuaternion will be set to null\r\n * @returns this node\r\n */\r\n public markAsDirty(property?: string): Node {\r\n if (this._isDirty) {\r\n return this;\r\n }\r\n\r\n // We need to explicitly update the children\r\n // as the scene.evaluateActiveMeshes will not poll the transform nodes\r\n if (this._children) {\r\n for (const child of this._children) {\r\n child.markAsDirty(property);\r\n }\r\n }\r\n return super.markAsDirty(property);\r\n }\r\n\r\n /**\r\n * Defines the passed node as the parent of the current node.\r\n * The node will remain exactly where it is and its position / rotation will be updated accordingly.\r\n * Note that if the mesh has a pivot matrix / point defined it will be applied after the parent was updated.\r\n * In that case the node will not remain in the same space as it is, as the pivot will be applied.\r\n * To avoid this, you can set updatePivot to true and the pivot will be updated to identity\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/parent\r\n * @param node the node ot set as the parent\r\n * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.\r\n * @param updatePivot if true, update the pivot matrix to keep the node in the same space as before\r\n * @returns this TransformNode.\r\n */\r\n public setParent(node: Nullable, preserveScalingSign: boolean = false, updatePivot = false): TransformNode {\r\n if (!node && !this.parent) {\r\n return this;\r\n }\r\n\r\n const quatRotation = TmpVectors.Quaternion[0];\r\n const position = TmpVectors.Vector3[0];\r\n const scale = TmpVectors.Vector3[1];\r\n const invParentMatrix = TmpVectors.Matrix[1];\r\n Matrix.IdentityToRef(invParentMatrix);\r\n const composedMatrix = TmpVectors.Matrix[0];\r\n this.computeWorldMatrix(true);\r\n\r\n let currentRotation = this.rotationQuaternion;\r\n if (!currentRotation) {\r\n currentRotation = TransformNode._TmpRotation;\r\n Quaternion.RotationYawPitchRollToRef(this._rotation.y, this._rotation.x, this._rotation.z, currentRotation);\r\n }\r\n\r\n // current global transformation without pivot\r\n Matrix.ComposeToRef(this.scaling, currentRotation, this.position, composedMatrix);\r\n if (this.parent) {\r\n composedMatrix.multiplyToRef(this.parent.computeWorldMatrix(true), composedMatrix);\r\n }\r\n\r\n // is a node was set, calculate the difference between this and the node\r\n if (node) {\r\n node.computeWorldMatrix(true).invertToRef(invParentMatrix);\r\n composedMatrix.multiplyToRef(invParentMatrix, composedMatrix);\r\n }\r\n composedMatrix.decompose(scale, quatRotation, position, preserveScalingSign ? this : undefined);\r\n\r\n if (this.rotationQuaternion) {\r\n this.rotationQuaternion.copyFrom(quatRotation);\r\n } else {\r\n quatRotation.toEulerAnglesToRef(this.rotation);\r\n }\r\n\r\n this.scaling.copyFrom(scale);\r\n this.position.copyFrom(position);\r\n\r\n this.parent = node;\r\n\r\n if (updatePivot) {\r\n this.setPivotMatrix(Matrix.Identity());\r\n }\r\n\r\n return this;\r\n }\r\n\r\n private _nonUniformScaling = false;\r\n /**\r\n * True if the scaling property of this object is non uniform eg. (1,2,1)\r\n */\r\n public get nonUniformScaling(): boolean {\r\n return this._nonUniformScaling;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateNonUniformScalingState(value: boolean): boolean {\r\n if (this._nonUniformScaling === value) {\r\n return false;\r\n }\r\n\r\n this._nonUniformScaling = value;\r\n return true;\r\n }\r\n\r\n /**\r\n * Attach the current TransformNode to another TransformNode associated with a bone\r\n * @param bone Bone affecting the TransformNode\r\n * @param affectedTransformNode TransformNode associated with the bone\r\n * @returns this object\r\n */\r\n public attachToBone(bone: Bone, affectedTransformNode: TransformNode): TransformNode {\r\n this._currentParentWhenAttachingToBone = this.parent;\r\n this._transformToBoneReferal = affectedTransformNode;\r\n this.parent = bone;\r\n\r\n bone.getSkeleton().prepare(); // make sure bone.getFinalMatrix() is up to date\r\n\r\n if (bone.getFinalMatrix().determinant() < 0) {\r\n this.scalingDeterminant *= -1;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Detach the transform node if its associated with a bone\r\n * @param resetToPreviousParent Indicates if the parent that was in effect when attachToBone was called should be set back or if we should set parent to null instead (defaults to the latter)\r\n * @returns this object\r\n */\r\n public detachFromBone(resetToPreviousParent = false): TransformNode {\r\n if (!this.parent) {\r\n if (resetToPreviousParent) {\r\n this.parent = this._currentParentWhenAttachingToBone;\r\n }\r\n return this;\r\n }\r\n\r\n if (this.parent.getWorldMatrix().determinant() < 0) {\r\n this.scalingDeterminant *= -1;\r\n }\r\n this._transformToBoneReferal = null;\r\n if (resetToPreviousParent) {\r\n this.parent = this._currentParentWhenAttachingToBone;\r\n } else {\r\n this.parent = null;\r\n }\r\n return this;\r\n }\r\n\r\n private static _RotationAxisCache = new Quaternion();\r\n /**\r\n * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space.\r\n * space (default LOCAL) can be either Space.LOCAL, either Space.WORLD.\r\n * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.\r\n * The passed axis is also normalized.\r\n * @param axis the axis to rotate around\r\n * @param amount the amount to rotate in radians\r\n * @param space Space to rotate in (Default: local)\r\n * @returns the TransformNode.\r\n */\r\n public rotate(axis: Vector3, amount: number, space?: Space): TransformNode {\r\n axis.normalize();\r\n if (!this.rotationQuaternion) {\r\n this.rotationQuaternion = this.rotation.toQuaternion();\r\n this.rotation.setAll(0);\r\n }\r\n let rotationQuaternion: Quaternion;\r\n if (!space || (space as any) === Space.LOCAL) {\r\n rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, TransformNode._RotationAxisCache);\r\n this.rotationQuaternion.multiplyToRef(rotationQuaternion, this.rotationQuaternion);\r\n } else {\r\n if (this.parent) {\r\n const invertParentWorldMatrix = TmpVectors.Matrix[0];\r\n this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);\r\n axis = Vector3.TransformNormal(axis, invertParentWorldMatrix);\r\n }\r\n rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, TransformNode._RotationAxisCache);\r\n rotationQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.\r\n * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.\r\n * The passed axis is also normalized. .\r\n * Method is based on http://www.euclideanspace.com/maths/geometry/affine/aroundPoint/index.htm\r\n * @param point the point to rotate around\r\n * @param axis the axis to rotate around\r\n * @param amount the amount to rotate in radians\r\n * @returns the TransformNode\r\n */\r\n public rotateAround(point: Vector3, axis: Vector3, amount: number): TransformNode {\r\n axis.normalize();\r\n if (!this.rotationQuaternion) {\r\n this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);\r\n this.rotation.setAll(0);\r\n }\r\n\r\n const tmpVector = TmpVectors.Vector3[0];\r\n const finalScale = TmpVectors.Vector3[1];\r\n const finalTranslation = TmpVectors.Vector3[2];\r\n\r\n const finalRotation = TmpVectors.Quaternion[0];\r\n\r\n const translationMatrix = TmpVectors.Matrix[0]; // T\r\n const translationMatrixInv = TmpVectors.Matrix[1]; // T'\r\n const rotationMatrix = TmpVectors.Matrix[2]; // R\r\n const finalMatrix = TmpVectors.Matrix[3]; // T' x R x T\r\n\r\n point.subtractToRef(this.position, tmpVector);\r\n Matrix.TranslationToRef(tmpVector.x, tmpVector.y, tmpVector.z, translationMatrix); // T\r\n Matrix.TranslationToRef(-tmpVector.x, -tmpVector.y, -tmpVector.z, translationMatrixInv); // T'\r\n Matrix.RotationAxisToRef(axis, amount, rotationMatrix); // R\r\n\r\n translationMatrixInv.multiplyToRef(rotationMatrix, finalMatrix); // T' x R\r\n finalMatrix.multiplyToRef(translationMatrix, finalMatrix); // T' x R x T\r\n\r\n finalMatrix.decompose(finalScale, finalRotation, finalTranslation);\r\n\r\n this.position.addInPlace(finalTranslation);\r\n finalRotation.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Translates the mesh along the axis vector for the passed distance in the given space.\r\n * space (default LOCAL) can be either Space.LOCAL, either Space.WORLD.\r\n * @param axis the axis to translate in\r\n * @param distance the distance to translate\r\n * @param space Space to rotate in (Default: local)\r\n * @returns the TransformNode.\r\n */\r\n public translate(axis: Vector3, distance: number, space?: Space): TransformNode {\r\n const displacementVector = axis.scale(distance);\r\n if (!space || (space as any) === Space.LOCAL) {\r\n const tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);\r\n this.setPositionWithLocalVector(tempV3);\r\n } else {\r\n this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a rotation step to the mesh current rotation.\r\n * x, y, z are Euler angles expressed in radians.\r\n * This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set.\r\n * This means this rotation is made in the mesh local space only.\r\n * It's useful to set a custom rotation order different from the BJS standard one YXZ.\r\n * Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis.\r\n * ```javascript\r\n * mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3);\r\n * ```\r\n * Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values.\r\n * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles.\r\n * @param x Rotation to add\r\n * @param y Rotation to add\r\n * @param z Rotation to add\r\n * @returns the TransformNode.\r\n */\r\n public addRotation(x: number, y: number, z: number): TransformNode {\r\n let rotationQuaternion;\r\n if (this.rotationQuaternion) {\r\n rotationQuaternion = this.rotationQuaternion;\r\n } else {\r\n rotationQuaternion = TmpVectors.Quaternion[1];\r\n Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, rotationQuaternion);\r\n }\r\n const accumulation = TmpVectors.Quaternion[0];\r\n Quaternion.RotationYawPitchRollToRef(y, x, z, accumulation);\r\n rotationQuaternion.multiplyInPlace(accumulation);\r\n if (!this.rotationQuaternion) {\r\n rotationQuaternion.toEulerAnglesToRef(this.rotation);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n protected _getEffectiveParent(): Nullable {\r\n return this.parent;\r\n }\r\n\r\n /**\r\n * Returns whether the transform node world matrix computation needs the camera information to be computed.\r\n * This is the case when the node is a billboard or has an infinite distance for instance.\r\n * @returns true if the world matrix computation needs the camera information to be computed\r\n */\r\n public isWorldMatrixCameraDependent(): boolean {\r\n return (this._infiniteDistance && !this.parent) || (this._billboardMode !== TransformNode.BILLBOARDMODE_NONE && !this.preserveParentRotationForBillboard);\r\n }\r\n\r\n /**\r\n * Computes the world matrix of the node\r\n * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\r\n * @param camera defines the camera used if different from the scene active camera (This is used with modes like Billboard or infinite distance)\r\n * @returns the world matrix\r\n */\r\n public computeWorldMatrix(force: boolean = false, camera: Nullable = null): Matrix {\r\n if (this._isWorldMatrixFrozen && !this._isDirty) {\r\n return this._worldMatrix;\r\n }\r\n\r\n const currentRenderId = this.getScene().getRenderId();\r\n if (!this._isDirty && !force && (this._currentRenderId === currentRenderId || this.isSynchronized())) {\r\n this._currentRenderId = currentRenderId;\r\n return this._worldMatrix;\r\n }\r\n\r\n camera = camera || this.getScene().activeCamera;\r\n\r\n this._updateCache();\r\n const cache = this._cache;\r\n cache.pivotMatrixUpdated = false;\r\n cache.billboardMode = this.billboardMode;\r\n cache.infiniteDistance = this.infiniteDistance;\r\n cache.parent = this._parentNode;\r\n\r\n this._currentRenderId = currentRenderId;\r\n this._childUpdateId += 1;\r\n this._isDirty = false;\r\n this._position._isDirty = false;\r\n this._rotation._isDirty = false;\r\n this._scaling._isDirty = false;\r\n const parent = this._getEffectiveParent();\r\n\r\n // Scaling\r\n const scaling: Vector3 = TransformNode._TmpScaling;\r\n let translation: Vector3 = this._position;\r\n\r\n // Translation\r\n if (this._infiniteDistance) {\r\n if (!this.parent && camera) {\r\n const cameraWorldMatrix = camera.getWorldMatrix();\r\n const cameraGlobalPosition = new Vector3(cameraWorldMatrix.m[12], cameraWorldMatrix.m[13], cameraWorldMatrix.m[14]);\r\n\r\n translation = TransformNode._TmpTranslation;\r\n translation.copyFromFloats(this._position.x + cameraGlobalPosition.x, this._position.y + cameraGlobalPosition.y, this._position.z + cameraGlobalPosition.z);\r\n }\r\n }\r\n\r\n // Scaling\r\n scaling.copyFromFloats(this._scaling.x * this.scalingDeterminant, this._scaling.y * this.scalingDeterminant, this._scaling.z * this.scalingDeterminant);\r\n\r\n // Rotation\r\n let rotation: Quaternion;\r\n if (this._rotationQuaternion) {\r\n this._rotationQuaternion._isDirty = false;\r\n rotation = this._rotationQuaternion;\r\n if (this.reIntegrateRotationIntoRotationQuaternion) {\r\n const len = this.rotation.lengthSquared();\r\n if (len) {\r\n this._rotationQuaternion.multiplyInPlace(Quaternion.RotationYawPitchRoll(this._rotation.y, this._rotation.x, this._rotation.z));\r\n this._rotation.copyFromFloats(0, 0, 0);\r\n }\r\n }\r\n } else {\r\n rotation = TransformNode._TmpRotation;\r\n Quaternion.RotationYawPitchRollToRef(this._rotation.y, this._rotation.x, this._rotation.z, rotation);\r\n }\r\n\r\n // Compose\r\n if (this._usePivotMatrix) {\r\n const scaleMatrix = TmpVectors.Matrix[1];\r\n Matrix.ScalingToRef(scaling.x, scaling.y, scaling.z, scaleMatrix);\r\n\r\n // Rotation\r\n const rotationMatrix = TmpVectors.Matrix[0];\r\n rotation.toRotationMatrix(rotationMatrix);\r\n\r\n // Composing transformations\r\n this._pivotMatrix.multiplyToRef(scaleMatrix, TmpVectors.Matrix[4]);\r\n TmpVectors.Matrix[4].multiplyToRef(rotationMatrix, this._localMatrix);\r\n\r\n // Post multiply inverse of pivotMatrix\r\n if (this._postMultiplyPivotMatrix) {\r\n this._localMatrix.multiplyToRef(this._pivotMatrixInverse, this._localMatrix);\r\n }\r\n\r\n this._localMatrix.addTranslationFromFloats(translation.x, translation.y, translation.z);\r\n } else {\r\n Matrix.ComposeToRef(scaling, rotation, translation, this._localMatrix);\r\n }\r\n\r\n // Parent\r\n if (parent && parent.getWorldMatrix) {\r\n if (force) {\r\n parent.computeWorldMatrix(force);\r\n }\r\n if (cache.useBillboardPath) {\r\n if (this._transformToBoneReferal) {\r\n parent.getWorldMatrix().multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), TmpVectors.Matrix[7]);\r\n } else {\r\n TmpVectors.Matrix[7].copyFrom(parent.getWorldMatrix());\r\n }\r\n\r\n // Extract scaling and translation from parent\r\n const translation = TmpVectors.Vector3[5];\r\n const scale = TmpVectors.Vector3[6];\r\n const orientation = TmpVectors.Quaternion[0];\r\n TmpVectors.Matrix[7].decompose(scale, orientation, translation);\r\n Matrix.ScalingToRef(scale.x, scale.y, scale.z, TmpVectors.Matrix[7]);\r\n TmpVectors.Matrix[7].setTranslation(translation);\r\n\r\n if (TransformNode.BillboardUseParentOrientation) {\r\n // set localMatrix translation to be transformed against parent's orientation.\r\n this._position.applyRotationQuaternionToRef(orientation, translation);\r\n this._localMatrix.setTranslation(translation);\r\n }\r\n\r\n this._localMatrix.multiplyToRef(TmpVectors.Matrix[7], this._worldMatrix);\r\n } else {\r\n if (this._transformToBoneReferal) {\r\n this._localMatrix.multiplyToRef(parent.getWorldMatrix(), TmpVectors.Matrix[6]);\r\n TmpVectors.Matrix[6].multiplyToRef(this._transformToBoneReferal.getWorldMatrix(), this._worldMatrix);\r\n } else {\r\n this._localMatrix.multiplyToRef(parent.getWorldMatrix(), this._worldMatrix);\r\n }\r\n }\r\n this._markSyncedWithParent();\r\n } else {\r\n this._worldMatrix.copyFrom(this._localMatrix);\r\n }\r\n\r\n // Billboarding based on camera orientation (testing PG:http://www.babylonjs-playground.com/#UJEIL#13)\r\n if (cache.useBillboardPath && camera && this.billboardMode && !cache.useBillboardPosition) {\r\n const storedTranslation = TmpVectors.Vector3[0];\r\n this._worldMatrix.getTranslationToRef(storedTranslation); // Save translation\r\n\r\n // Cancel camera rotation\r\n TmpVectors.Matrix[1].copyFrom(camera.getViewMatrix());\r\n\r\n if (this._scene.useRightHandedSystem) {\r\n TmpVectors.Matrix[1].multiplyToRef(convertRHSToLHS, TmpVectors.Matrix[1]);\r\n }\r\n\r\n TmpVectors.Matrix[1].setTranslationFromFloats(0, 0, 0);\r\n TmpVectors.Matrix[1].invertToRef(TmpVectors.Matrix[0]);\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_ALL) !== TransformNode.BILLBOARDMODE_ALL) {\r\n TmpVectors.Matrix[0].decompose(undefined, TmpVectors.Quaternion[0], undefined);\r\n const eulerAngles = TmpVectors.Vector3[1];\r\n TmpVectors.Quaternion[0].toEulerAnglesToRef(eulerAngles);\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_X) !== TransformNode.BILLBOARDMODE_X) {\r\n eulerAngles.x = 0;\r\n }\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Y) !== TransformNode.BILLBOARDMODE_Y) {\r\n eulerAngles.y = 0;\r\n }\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Z) !== TransformNode.BILLBOARDMODE_Z) {\r\n eulerAngles.z = 0;\r\n }\r\n\r\n Matrix.RotationYawPitchRollToRef(eulerAngles.y, eulerAngles.x, eulerAngles.z, TmpVectors.Matrix[0]);\r\n }\r\n this._worldMatrix.setTranslationFromFloats(0, 0, 0);\r\n this._worldMatrix.multiplyToRef(TmpVectors.Matrix[0], this._worldMatrix);\r\n\r\n // Restore translation\r\n this._worldMatrix.setTranslation(TmpVectors.Vector3[0]);\r\n }\r\n // Billboarding based on camera position\r\n else if (cache.useBillboardPath && camera && cache.useBillboardPosition) {\r\n const storedTranslation = TmpVectors.Vector3[0];\r\n // Save translation\r\n this._worldMatrix.getTranslationToRef(storedTranslation);\r\n\r\n // Compute camera position in local space\r\n const cameraPosition = camera.globalPosition;\r\n this._worldMatrix.invertToRef(TmpVectors.Matrix[1]);\r\n const camInObjSpace = TmpVectors.Vector3[1];\r\n Vector3.TransformCoordinatesToRef(cameraPosition, TmpVectors.Matrix[1], camInObjSpace);\r\n camInObjSpace.normalize();\r\n\r\n // Find the lookAt info in local space\r\n const yaw = -Math.atan2(camInObjSpace.z, camInObjSpace.x) + Math.PI / 2;\r\n const len = Math.sqrt(camInObjSpace.x * camInObjSpace.x + camInObjSpace.z * camInObjSpace.z);\r\n const pitch = -Math.atan2(camInObjSpace.y, len);\r\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, 0, TmpVectors.Quaternion[0]);\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_ALL) !== TransformNode.BILLBOARDMODE_ALL) {\r\n const eulerAngles = TmpVectors.Vector3[1];\r\n TmpVectors.Quaternion[0].toEulerAnglesToRef(eulerAngles);\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_X) !== TransformNode.BILLBOARDMODE_X) {\r\n eulerAngles.x = 0;\r\n }\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Y) !== TransformNode.BILLBOARDMODE_Y) {\r\n eulerAngles.y = 0;\r\n }\r\n\r\n if ((this.billboardMode & TransformNode.BILLBOARDMODE_Z) !== TransformNode.BILLBOARDMODE_Z) {\r\n eulerAngles.z = 0;\r\n }\r\n\r\n Matrix.RotationYawPitchRollToRef(eulerAngles.y, eulerAngles.x, eulerAngles.z, TmpVectors.Matrix[0]);\r\n } else {\r\n Matrix.FromQuaternionToRef(TmpVectors.Quaternion[0], TmpVectors.Matrix[0]);\r\n }\r\n\r\n // Cancel translation\r\n this._worldMatrix.setTranslationFromFloats(0, 0, 0);\r\n\r\n // Rotate according to lookat (diff from local to lookat)\r\n this._worldMatrix.multiplyToRef(TmpVectors.Matrix[0], this._worldMatrix);\r\n\r\n // Restore translation\r\n this._worldMatrix.setTranslation(TmpVectors.Vector3[0]);\r\n }\r\n\r\n // Normal matrix\r\n if (!this.ignoreNonUniformScaling) {\r\n if (this._scaling.isNonUniformWithinEpsilon(0.000001)) {\r\n this._updateNonUniformScalingState(true);\r\n } else if (parent && (parent)._nonUniformScaling) {\r\n this._updateNonUniformScalingState((parent)._nonUniformScaling);\r\n } else {\r\n this._updateNonUniformScalingState(false);\r\n }\r\n } else {\r\n this._updateNonUniformScalingState(false);\r\n }\r\n\r\n this._afterComputeWorldMatrix();\r\n\r\n // Absolute position\r\n this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);\r\n this._isAbsoluteSynced = false;\r\n\r\n // Callbacks\r\n this.onAfterWorldMatrixUpdateObservable.notifyObservers(this);\r\n\r\n if (!this._poseMatrix) {\r\n this._poseMatrix = Matrix.Invert(this._worldMatrix);\r\n }\r\n\r\n // Cache the determinant\r\n this._worldMatrixDeterminantIsDirty = true;\r\n\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * Resets this nodeTransform's local matrix to Matrix.Identity().\r\n * @param independentOfChildren indicates if all child nodeTransform's world-space transform should be preserved.\r\n */\r\n public resetLocalMatrix(independentOfChildren: boolean = true): void {\r\n this.computeWorldMatrix();\r\n if (independentOfChildren) {\r\n const children = this.getChildren();\r\n for (let i = 0; i < children.length; ++i) {\r\n const child = children[i] as TransformNode;\r\n if (child) {\r\n child.computeWorldMatrix();\r\n const bakedMatrix = TmpVectors.Matrix[0];\r\n child._localMatrix.multiplyToRef(this._localMatrix, bakedMatrix);\r\n const tmpRotationQuaternion = TmpVectors.Quaternion[0];\r\n bakedMatrix.decompose(child.scaling, tmpRotationQuaternion, child.position);\r\n if (child.rotationQuaternion) {\r\n child.rotationQuaternion.copyFrom(tmpRotationQuaternion);\r\n } else {\r\n tmpRotationQuaternion.toEulerAnglesToRef(child.rotation);\r\n }\r\n }\r\n }\r\n }\r\n this.scaling.copyFromFloats(1, 1, 1);\r\n this.position.copyFromFloats(0, 0, 0);\r\n this.rotation.copyFromFloats(0, 0, 0);\r\n\r\n //only if quaternion is already set\r\n if (this.rotationQuaternion) {\r\n this.rotationQuaternion = Quaternion.Identity();\r\n }\r\n this._worldMatrix = Matrix.Identity();\r\n }\r\n\r\n protected _afterComputeWorldMatrix(): void {}\r\n\r\n /**\r\n * If you'd like to be called back after the mesh position, rotation or scaling has been updated.\r\n * @param func callback function to add\r\n *\r\n * @returns the TransformNode.\r\n */\r\n public registerAfterWorldMatrixUpdate(func: (mesh: TransformNode) => void): TransformNode {\r\n this.onAfterWorldMatrixUpdateObservable.add(func);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a registered callback function.\r\n * @param func callback function to remove\r\n * @returns the TransformNode.\r\n */\r\n public unregisterAfterWorldMatrixUpdate(func: (mesh: TransformNode) => void): TransformNode {\r\n this.onAfterWorldMatrixUpdateObservable.removeCallback(func);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the position of the current mesh in camera space\r\n * @param camera defines the camera to use\r\n * @returns a position\r\n */\r\n public getPositionInCameraSpace(camera: Nullable = null): Vector3 {\r\n if (!camera) {\r\n camera = this.getScene().activeCamera;\r\n }\r\n\r\n return Vector3.TransformCoordinates(this.getAbsolutePosition(), camera.getViewMatrix());\r\n }\r\n\r\n /**\r\n * Returns the distance from the mesh to the active camera\r\n * @param camera defines the camera to use\r\n * @returns the distance\r\n */\r\n public getDistanceToCamera(camera: Nullable = null): number {\r\n if (!camera) {\r\n camera = this.getScene().activeCamera;\r\n }\r\n return this.getAbsolutePosition().subtract(camera.globalPosition).length();\r\n }\r\n\r\n /**\r\n * Clone the current transform node\r\n * @param name Name of the new clone\r\n * @param newParent New parent for the clone\r\n * @param doNotCloneChildren Do not clone children hierarchy\r\n * @returns the new transform node\r\n */\r\n public clone(name: string, newParent: Nullable, doNotCloneChildren?: boolean): Nullable {\r\n const result = SerializationHelper.Clone(() => new TransformNode(name, this.getScene()), this);\r\n\r\n result.name = name;\r\n result.id = name;\r\n\r\n if (newParent) {\r\n result.parent = newParent;\r\n }\r\n\r\n if (!doNotCloneChildren) {\r\n // Children\r\n const directDescendants = this.getDescendants(true);\r\n for (let index = 0; index < directDescendants.length; index++) {\r\n const child = directDescendants[index];\r\n\r\n if ((child).clone) {\r\n (child).clone(name + \".\" + child.name, result);\r\n }\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Serializes the objects information.\r\n * @param currentSerializationObject defines the object to serialize in\r\n * @returns the serialized object\r\n */\r\n public serialize(currentSerializationObject?: any): any {\r\n const serializationObject = SerializationHelper.Serialize(this, currentSerializationObject);\r\n serializationObject.type = this.getClassName();\r\n serializationObject.uniqueId = this.uniqueId;\r\n\r\n // Parent\r\n if (this.parent) {\r\n this.parent._serializeAsParent(serializationObject);\r\n }\r\n\r\n serializationObject.localMatrix = this.getPivotMatrix().asArray();\r\n\r\n serializationObject.isEnabled = this.isEnabled();\r\n\r\n return serializationObject;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Returns a new TransformNode object parsed from the source provided.\r\n * @param parsedTransformNode is the source.\r\n * @param scene the scene the object belongs to\r\n * @param rootUrl is a string, it's the root URL to prefix the `delayLoadingFile` property with\r\n * @returns a new TransformNode object parsed from the source provided.\r\n */\r\n public static Parse(parsedTransformNode: any, scene: Scene, rootUrl: string): TransformNode {\r\n const transformNode = SerializationHelper.Parse(() => new TransformNode(parsedTransformNode.name, scene), parsedTransformNode, scene, rootUrl);\r\n\r\n if (parsedTransformNode.localMatrix) {\r\n transformNode.setPreTransformMatrix(Matrix.FromArray(parsedTransformNode.localMatrix));\r\n } else if (parsedTransformNode.pivotMatrix) {\r\n transformNode.setPivotMatrix(Matrix.FromArray(parsedTransformNode.pivotMatrix));\r\n }\r\n\r\n transformNode.setEnabled(parsedTransformNode.isEnabled);\r\n\r\n transformNode._waitingParsedUniqueId = parsedTransformNode.uniqueId;\r\n\r\n // Parent\r\n if (parsedTransformNode.parentId !== undefined) {\r\n transformNode._waitingParentId = parsedTransformNode.parentId;\r\n }\r\n\r\n if (parsedTransformNode.parentInstanceIndex !== undefined) {\r\n transformNode._waitingParentInstanceIndex = parsedTransformNode.parentInstanceIndex;\r\n }\r\n\r\n return transformNode;\r\n }\r\n\r\n /**\r\n * Get all child-transformNodes of this node\r\n * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered\r\n * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored\r\n * @returns an array of TransformNode\r\n */\r\n public getChildTransformNodes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): TransformNode[] {\r\n const results: Array = [];\r\n this._getDescendants(results, directDescendantsOnly, (node: Node) => {\r\n return (!predicate || predicate(node)) && node instanceof TransformNode;\r\n });\r\n return results;\r\n }\r\n\r\n /**\r\n * Releases resources associated with this transform node.\r\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\r\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n // Animations\r\n this.getScene().stopAnimation(this);\r\n\r\n // Remove from scene\r\n this.getScene().removeTransformNode(this);\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.transformNodes.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.transformNodes.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n this.onAfterWorldMatrixUpdateObservable.clear();\r\n\r\n if (doNotRecurse) {\r\n const transformNodes = this.getChildTransformNodes(true);\r\n for (const transformNode of transformNodes) {\r\n transformNode.parent = null;\r\n transformNode.computeWorldMatrix(true);\r\n }\r\n }\r\n\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n\r\n /**\r\n * Uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units)\r\n * @param includeDescendants Use the hierarchy's bounding box instead of the mesh's bounding box. Default is false\r\n * @param ignoreRotation ignore rotation when computing the scale (ie. object will be axis aligned). Default is false\r\n * @param predicate predicate that is passed in to getHierarchyBoundingVectors when selecting which object should be included when scaling\r\n * @returns the current mesh\r\n */\r\n public normalizeToUnitCube(includeDescendants = true, ignoreRotation = false, predicate?: Nullable<(node: AbstractMesh) => boolean>): TransformNode {\r\n let storedRotation: Nullable = null;\r\n let storedRotationQuaternion: Nullable = null;\r\n\r\n if (ignoreRotation) {\r\n if (this.rotationQuaternion) {\r\n storedRotationQuaternion = this.rotationQuaternion.clone();\r\n this.rotationQuaternion.copyFromFloats(0, 0, 0, 1);\r\n } else if (this.rotation) {\r\n storedRotation = this.rotation.clone();\r\n this.rotation.copyFromFloats(0, 0, 0);\r\n }\r\n }\r\n\r\n const boundingVectors = this.getHierarchyBoundingVectors(includeDescendants, predicate);\r\n const sizeVec = boundingVectors.max.subtract(boundingVectors.min);\r\n const maxDimension = Math.max(sizeVec.x, sizeVec.y, sizeVec.z);\r\n\r\n if (maxDimension === 0) {\r\n return this;\r\n }\r\n\r\n const scale = 1 / maxDimension;\r\n\r\n this.scaling.scaleInPlace(scale);\r\n\r\n if (ignoreRotation) {\r\n if (this.rotationQuaternion && storedRotationQuaternion) {\r\n this.rotationQuaternion.copyFrom(storedRotationQuaternion);\r\n } else if (this.rotation && storedRotation) {\r\n this.rotation.copyFrom(storedRotation);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n private _syncAbsoluteScalingAndRotation(): void {\r\n if (!this._isAbsoluteSynced) {\r\n this._worldMatrix.decompose(this._absoluteScaling, this._absoluteRotationQuaternion);\r\n this._isAbsoluteSynced = true;\r\n }\r\n }\r\n}\r\n","import type { Collider } from \"./collider\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\n\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _MeshCollisionData {\r\n public _checkCollisions = false;\r\n public _collisionMask = -1;\r\n public _collisionGroup = -1;\r\n public _surroundingMeshes: Nullable = null;\r\n public _collider: Nullable = null;\r\n public _oldPositionForCollisions = new Vector3(0, 0, 0);\r\n public _diffPositionForCollisions = new Vector3(0, 0, 0);\r\n public _onCollideObserver: Nullable>;\r\n public _onCollisionPositionChangeObserver: Nullable>;\r\n public _collisionResponse = true;\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\nimport type { Nullable, FloatArray, IndicesArray, DeepImmutable } from \"../types\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene, IDisposable } from \"../scene\";\r\nimport { ScenePerformancePriority } from \"../scene\";\r\nimport type { Vector2 } from \"../Maths/math.vector\";\r\nimport { Quaternion, Matrix, Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport type { Node } from \"../node\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { IGetSetVerticesData } from \"../Meshes/mesh.vertexData\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport type { IntersectionInfo } from \"../Collisions/intersectionInfo\";\r\nimport type { ICullable } from \"../Culling/boundingInfo\";\r\nimport { BoundingInfo } from \"../Culling/boundingInfo\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { MaterialDefines } from \"../Materials/materialDefines\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport type { Skeleton } from \"../Bones/skeleton\";\r\nimport type { MorphTargetManager } from \"../Morph/morphTargetManager\";\r\nimport type { IBakedVertexAnimationManager } from \"../BakedVertexAnimation/bakedVertexAnimationManager\";\r\nimport type { IEdgesRenderer } from \"../Rendering/edgesRenderer\";\r\nimport type { SolidParticle } from \"../Particles/solidParticle\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { AbstractActionManager } from \"../Actions/abstractActionManager\";\r\nimport { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport { _MeshCollisionData } from \"../Collisions/meshCollisionData\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { RawTexture } from \"../Materials/Textures/rawTexture\";\r\nimport { extractMinAndMax } from \"../Maths/math.functions\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\nimport type { IParticleSystem } from \"../Particles/IParticleSystem\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { Collider } from \"../Collisions/collider\";\r\nimport type { TrianglePickingPredicate } from \"../Culling/ray\";\r\nimport type { RenderingGroup } from \"../Rendering/renderingGroup\";\r\nimport type { IEdgesRendererOptions } from \"../Rendering/edgesRenderer\";\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nclass _FacetDataStorage {\r\n // facetData private properties\r\n public facetPositions: Vector3[]; // facet local positions\r\n public facetNormals: Vector3[]; // facet local normals\r\n public facetPartitioning: number[][]; // partitioning array of facet index arrays\r\n public facetNb: number = 0; // facet number\r\n public partitioningSubdivisions: number = 10; // number of subdivisions per axis in the partitioning space\r\n public partitioningBBoxRatio: number = 1.01; // the partitioning array space is by default 1% bigger than the bounding box\r\n public facetDataEnabled: boolean = false; // is the facet data feature enabled on this mesh ?\r\n public facetParameters: any = {}; // keep a reference to the object parameters to avoid memory re-allocation\r\n public bbSize: Vector3 = Vector3.Zero(); // bbox size approximated for facet data\r\n public subDiv = {\r\n // actual number of subdivisions per axis for ComputeNormals()\r\n max: 1,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n X: 1,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n Y: 1,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n Z: 1,\r\n };\r\n\r\n public facetDepthSort: boolean = false; // is the facet depth sort to be computed\r\n public facetDepthSortEnabled: boolean = false; // is the facet depth sort initialized\r\n public depthSortedIndices: IndicesArray; // copy of the indices array to store them once sorted\r\n public depthSortedFacets: { ind: number; sqDistance: number }[]; // array of depth sorted facets\r\n public facetDepthSortFunction: (f1: { ind: number; sqDistance: number }, f2: { ind: number; sqDistance: number }) => number; // facet depth sort function\r\n public facetDepthSortFrom: Vector3; // location where to depth sort from\r\n public facetDepthSortOrigin: Vector3; // same as facetDepthSortFrom but expressed in the mesh local space\r\n\r\n public invertedMatrix: Matrix; // Inverted world matrix.\r\n}\r\n\r\n/**\r\n * @internal\r\n **/\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nclass _InternalAbstractMeshDataInfo {\r\n public _hasVertexAlpha = false;\r\n public _useVertexColors = true;\r\n public _numBoneInfluencers = 4;\r\n public _applyFog = true;\r\n public _receiveShadows = false;\r\n public _facetData = new _FacetDataStorage();\r\n public _visibility = 1.0;\r\n public _skeleton: Nullable = null;\r\n public _layerMask: number = 0x0fffffff;\r\n public _computeBonesUsingShaders = true;\r\n public _isActive = false;\r\n public _onlyForInstances = false;\r\n public _isActiveIntermediate = false;\r\n public _onlyForInstancesIntermediate = false;\r\n public _actAsRegularMesh = false;\r\n public _currentLOD: Nullable = null;\r\n public _currentLODIsUpToDate: boolean = false;\r\n public _collisionRetryCount: number = 3;\r\n public _morphTargetManager: Nullable = null;\r\n public _renderingGroupId = 0;\r\n public _bakedVertexAnimationManager: Nullable = null;\r\n public _material: Nullable = null;\r\n public _materialForRenderPass: Array; // map a render pass id (index in the array) to a Material\r\n public _positions: Nullable = null;\r\n public _pointerOverDisableMeshTesting: boolean = false;\r\n // Collisions\r\n public _meshCollisionData = new _MeshCollisionData();\r\n public _enableDistantPicking = false;\r\n /** @internal\r\n * Bounding info that is unnafected by the addition of thin instances\r\n */\r\n public _rawBoundingInfo: Nullable = null;\r\n}\r\n\r\n/**\r\n * Class used to store all common mesh properties\r\n */\r\nexport class AbstractMesh extends TransformNode implements IDisposable, ICullable, IGetSetVerticesData {\r\n /** No occlusion */\r\n public static OCCLUSION_TYPE_NONE = 0;\r\n /** Occlusion set to optimistic */\r\n public static OCCLUSION_TYPE_OPTIMISTIC = 1;\r\n /** Occlusion set to strict */\r\n public static OCCLUSION_TYPE_STRICT = 2;\r\n /** Use an accurate occlusion algorithm */\r\n public static OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;\r\n /** Use a conservative occlusion algorithm */\r\n public static OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;\r\n\r\n /** Default culling strategy : this is an exclusion test and it's the more accurate.\r\n * Test order :\r\n * Is the bounding sphere outside the frustum ?\r\n * If not, are the bounding box vertices outside the frustum ?\r\n * It not, then the cullable object is in the frustum.\r\n */\r\n public static readonly CULLINGSTRATEGY_STANDARD = Constants.MESHES_CULLINGSTRATEGY_STANDARD;\r\n /** Culling strategy : Bounding Sphere Only.\r\n * This is an exclusion test. It's faster than the standard strategy because the bounding box is not tested.\r\n * It's also less accurate than the standard because some not visible objects can still be selected.\r\n * Test : is the bounding sphere outside the frustum ?\r\n * If not, then the cullable object is in the frustum.\r\n */\r\n public static readonly CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY;\r\n /** Culling strategy : Optimistic Inclusion.\r\n * This in an inclusion test first, then the standard exclusion test.\r\n * This can be faster when a cullable object is expected to be almost always in the camera frustum.\r\n * This could also be a little slower than the standard test when the tested object center is not the frustum but one of its bounding box vertex is still inside.\r\n * Anyway, it's as accurate as the standard strategy.\r\n * Test :\r\n * Is the cullable object bounding sphere center in the frustum ?\r\n * If not, apply the default culling strategy.\r\n */\r\n public static readonly CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION;\r\n /** Culling strategy : Optimistic Inclusion then Bounding Sphere Only.\r\n * This in an inclusion test first, then the bounding sphere only exclusion test.\r\n * This can be the fastest test when a cullable object is expected to be almost always in the camera frustum.\r\n * This could also be a little slower than the BoundingSphereOnly strategy when the tested object center is not in the frustum but its bounding sphere still intersects it.\r\n * It's less accurate than the standard strategy and as accurate as the BoundingSphereOnly strategy.\r\n * Test :\r\n * Is the cullable object bounding sphere center in the frustum ?\r\n * If not, apply the Bounding Sphere Only strategy. No Bounding Box is tested here.\r\n */\r\n public static readonly CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n\r\n /**\r\n * No billboard\r\n */\r\n public static get BILLBOARDMODE_NONE(): number {\r\n return TransformNode.BILLBOARDMODE_NONE;\r\n }\r\n\r\n /** Billboard on X axis */\r\n public static get BILLBOARDMODE_X(): number {\r\n return TransformNode.BILLBOARDMODE_X;\r\n }\r\n\r\n /** Billboard on Y axis */\r\n public static get BILLBOARDMODE_Y(): number {\r\n return TransformNode.BILLBOARDMODE_Y;\r\n }\r\n\r\n /** Billboard on Z axis */\r\n public static get BILLBOARDMODE_Z(): number {\r\n return TransformNode.BILLBOARDMODE_Z;\r\n }\r\n\r\n /** Billboard on all axes */\r\n public static get BILLBOARDMODE_ALL(): number {\r\n return TransformNode.BILLBOARDMODE_ALL;\r\n }\r\n\r\n /** Billboard on using position instead of orientation */\r\n public static get BILLBOARDMODE_USE_POSITION(): number {\r\n return TransformNode.BILLBOARDMODE_USE_POSITION;\r\n }\r\n\r\n // Internal data\r\n /** @internal */\r\n public _internalAbstractMeshDataInfo = new _InternalAbstractMeshDataInfo();\r\n\r\n /** @internal */\r\n public _waitingMaterialId: Nullable = null;\r\n\r\n /**\r\n * The culling strategy to use to check whether the mesh must be rendered or not.\r\n * This value can be changed at any time and will be used on the next render mesh selection.\r\n * The possible values are :\r\n * - AbstractMesh.CULLINGSTRATEGY_STANDARD\r\n * - AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\r\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\r\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\r\n * Please read each static variable documentation to get details about the culling process.\r\n * */\r\n public cullingStrategy = AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY;\r\n\r\n /**\r\n * Gets the number of facets in the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#what-is-a-mesh-facet\r\n */\r\n public get facetNb(): number {\r\n return this._internalAbstractMeshDataInfo._facetData.facetNb;\r\n }\r\n /**\r\n * Gets or set the number (integer) of subdivisions per axis in the partitioning space\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#tweaking-the-partitioning\r\n */\r\n public get partitioningSubdivisions(): number {\r\n return this._internalAbstractMeshDataInfo._facetData.partitioningSubdivisions;\r\n }\r\n public set partitioningSubdivisions(nb: number) {\r\n this._internalAbstractMeshDataInfo._facetData.partitioningSubdivisions = nb;\r\n }\r\n /**\r\n * The ratio (float) to apply to the bounding box size to set to the partitioning space.\r\n * Ex : 1.01 (default) the partitioning space is 1% bigger than the bounding box\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#tweaking-the-partitioning\r\n */\r\n public get partitioningBBoxRatio(): number {\r\n return this._internalAbstractMeshDataInfo._facetData.partitioningBBoxRatio;\r\n }\r\n public set partitioningBBoxRatio(ratio: number) {\r\n this._internalAbstractMeshDataInfo._facetData.partitioningBBoxRatio = ratio;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the facets must be depth sorted on next call to `updateFacetData()`.\r\n * Works only for updatable meshes.\r\n * Doesn't work with multi-materials\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#facet-depth-sort\r\n */\r\n public get mustDepthSortFacets(): boolean {\r\n return this._internalAbstractMeshDataInfo._facetData.facetDepthSort;\r\n }\r\n public set mustDepthSortFacets(sort: boolean) {\r\n this._internalAbstractMeshDataInfo._facetData.facetDepthSort = sort;\r\n }\r\n\r\n /**\r\n * The location (Vector3) where the facet depth sort must be computed from.\r\n * By default, the active camera position.\r\n * Used only when facet depth sort is enabled\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#facet-depth-sort\r\n */\r\n public get facetDepthSortFrom(): Vector3 {\r\n return this._internalAbstractMeshDataInfo._facetData.facetDepthSortFrom;\r\n }\r\n public set facetDepthSortFrom(location: Vector3) {\r\n this._internalAbstractMeshDataInfo._facetData.facetDepthSortFrom = location;\r\n }\r\n\r\n /** number of collision detection tries. Change this value if not all collisions are detected and handled properly */\r\n public get collisionRetryCount(): number {\r\n return this._internalAbstractMeshDataInfo._collisionRetryCount;\r\n }\r\n public set collisionRetryCount(retryCount: number) {\r\n this._internalAbstractMeshDataInfo._collisionRetryCount = retryCount;\r\n }\r\n /**\r\n * gets a boolean indicating if facetData is enabled\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData#what-is-a-mesh-facet\r\n */\r\n public get isFacetDataEnabled(): boolean {\r\n return this._internalAbstractMeshDataInfo._facetData.facetDataEnabled;\r\n }\r\n\r\n /**\r\n * Gets or sets the morph target manager\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets\r\n */\r\n public get morphTargetManager(): Nullable {\r\n return this._internalAbstractMeshDataInfo._morphTargetManager;\r\n }\r\n\r\n public set morphTargetManager(value: Nullable) {\r\n if (this._internalAbstractMeshDataInfo._morphTargetManager === value) {\r\n return;\r\n }\r\n this._internalAbstractMeshDataInfo._morphTargetManager = value;\r\n this._syncGeometryWithMorphTargetManager();\r\n }\r\n\r\n /**\r\n * Gets or sets the baked vertex animation manager\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/baked_texture_animations\r\n */\r\n public get bakedVertexAnimationManager(): Nullable {\r\n return this._internalAbstractMeshDataInfo._bakedVertexAnimationManager;\r\n }\r\n\r\n public set bakedVertexAnimationManager(value: Nullable) {\r\n if (this._internalAbstractMeshDataInfo._bakedVertexAnimationManager === value) {\r\n return;\r\n }\r\n this._internalAbstractMeshDataInfo._bakedVertexAnimationManager = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n\r\n /** @internal */\r\n public _syncGeometryWithMorphTargetManager(): void {}\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateNonUniformScalingState(value: boolean): boolean {\r\n if (!super._updateNonUniformScalingState(value)) {\r\n return false;\r\n }\r\n this._markSubMeshesAsMiscDirty();\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public get rawBoundingInfo(): Nullable {\r\n return this._internalAbstractMeshDataInfo._rawBoundingInfo;\r\n }\r\n public set rawBoundingInfo(boundingInfo: Nullable) {\r\n this._internalAbstractMeshDataInfo._rawBoundingInfo = boundingInfo;\r\n }\r\n\r\n // Events\r\n\r\n /**\r\n * An event triggered when this mesh collides with another one\r\n */\r\n public onCollideObservable = new Observable();\r\n\r\n /** Set a function to call when this mesh collides with another one */\r\n public set onCollide(callback: (collidedMesh?: AbstractMesh) => void) {\r\n if (this._internalAbstractMeshDataInfo._meshCollisionData._onCollideObserver) {\r\n this.onCollideObservable.remove(this._internalAbstractMeshDataInfo._meshCollisionData._onCollideObserver);\r\n }\r\n this._internalAbstractMeshDataInfo._meshCollisionData._onCollideObserver = this.onCollideObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when the collision's position changes\r\n */\r\n public onCollisionPositionChangeObservable = new Observable();\r\n\r\n /** Set a function to call when the collision's position changes */\r\n public set onCollisionPositionChange(callback: () => void) {\r\n if (this._internalAbstractMeshDataInfo._meshCollisionData._onCollisionPositionChangeObserver) {\r\n this.onCollisionPositionChangeObservable.remove(this._internalAbstractMeshDataInfo._meshCollisionData._onCollisionPositionChangeObserver);\r\n }\r\n this._internalAbstractMeshDataInfo._meshCollisionData._onCollisionPositionChangeObserver = this.onCollisionPositionChangeObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when material is changed\r\n */\r\n public onMaterialChangedObservable = new Observable();\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets or sets the orientation for POV movement & rotation\r\n */\r\n public definedFacingForward = true;\r\n\r\n /** @internal */\r\n public _occlusionQuery: Nullable = null;\r\n\r\n /** @internal */\r\n public _renderingGroup: Nullable = null;\r\n\r\n /**\r\n * Gets or sets mesh visibility between 0 and 1 (default is 1)\r\n */\r\n public get visibility(): number {\r\n return this._internalAbstractMeshDataInfo._visibility;\r\n }\r\n\r\n /**\r\n * Gets or sets mesh visibility between 0 and 1 (default is 1)\r\n */\r\n public set visibility(value: number) {\r\n if (this._internalAbstractMeshDataInfo._visibility === value) {\r\n return;\r\n }\r\n\r\n const oldValue = this._internalAbstractMeshDataInfo._visibility;\r\n\r\n this._internalAbstractMeshDataInfo._visibility = value;\r\n\r\n if ((oldValue === 1 && value !== 1) || (oldValue !== 1 && value === 1)) {\r\n this._markSubMeshesAsDirty((defines) => {\r\n defines.markAsMiscDirty();\r\n defines.markAsPrePassDirty();\r\n });\r\n }\r\n }\r\n\r\n /** Gets or sets the alpha index used to sort transparent meshes\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering#alpha-index\r\n */\r\n public alphaIndex = Number.MAX_VALUE;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the mesh is visible (renderable). Default is true\r\n */\r\n public isVisible = true;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the mesh can be picked (by scene.pick for instance or through actions). Default is true\r\n */\r\n public isPickable = true;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the mesh can be near picked. Default is false\r\n */\r\n public isNearPickable = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the mesh can be near grabbed. Default is false\r\n */\r\n public isNearGrabbable = false;\r\n\r\n /** Gets or sets a boolean indicating that bounding boxes of subMeshes must be rendered as well (false by default) */\r\n public showSubMeshesBoundingBox = false;\r\n\r\n /** Gets or sets a boolean indicating if the mesh must be considered as a ray blocker for lens flares (false by default)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/lenseFlare\r\n */\r\n public isBlocker = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that pointer move events must be supported on this mesh (false by default)\r\n */\r\n public enablePointerMoveEvents = false;\r\n\r\n /**\r\n * Gets or sets the property which disables the test that is checking that the mesh under the pointer is the same than the previous time we tested for it (default: false).\r\n * Set this property to true if you want thin instances picking to be reported accurately when moving over the mesh.\r\n * Note that setting this property to true will incur some performance penalties when dealing with pointer events for this mesh so use it sparingly.\r\n */\r\n public get pointerOverDisableMeshTesting() {\r\n return this._internalAbstractMeshDataInfo._pointerOverDisableMeshTesting;\r\n }\r\n\r\n public set pointerOverDisableMeshTesting(disable: boolean) {\r\n this._internalAbstractMeshDataInfo._pointerOverDisableMeshTesting = disable;\r\n }\r\n\r\n /**\r\n * Specifies the rendering group id for this mesh (0 by default)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering#rendering-groups\r\n */\r\n public get renderingGroupId() {\r\n return this._internalAbstractMeshDataInfo._renderingGroupId;\r\n }\r\n\r\n public set renderingGroupId(value: number) {\r\n this._internalAbstractMeshDataInfo._renderingGroupId = value;\r\n }\r\n\r\n /** Gets or sets current material */\r\n public get material(): Nullable {\r\n return this._internalAbstractMeshDataInfo._material;\r\n }\r\n public set material(value: Nullable) {\r\n if (this._internalAbstractMeshDataInfo._material === value) {\r\n return;\r\n }\r\n\r\n // remove from material mesh map id needed\r\n if (this._internalAbstractMeshDataInfo._material && this._internalAbstractMeshDataInfo._material.meshMap) {\r\n this._internalAbstractMeshDataInfo._material.meshMap[this.uniqueId] = undefined;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._material = value;\r\n\r\n if (value && value.meshMap) {\r\n value.meshMap[this.uniqueId] = this;\r\n }\r\n\r\n if (this.onMaterialChangedObservable.hasObservers()) {\r\n this.onMaterialChangedObservable.notifyObservers(this);\r\n }\r\n\r\n if (!this.subMeshes) {\r\n return;\r\n }\r\n\r\n this.resetDrawCache();\r\n this._unBindEffect();\r\n }\r\n\r\n /**\r\n * Gets the material used to render the mesh in a specific render pass\r\n * @param renderPassId render pass id\r\n * @returns material used for the render pass. If no specific material is used for this render pass, undefined is returned (meaning mesh.material is used for this pass)\r\n */\r\n public getMaterialForRenderPass(renderPassId: number): Material | undefined {\r\n return this._internalAbstractMeshDataInfo._materialForRenderPass?.[renderPassId];\r\n }\r\n\r\n /**\r\n * Sets the material to be used to render the mesh in a specific render pass\r\n * @param renderPassId render pass id\r\n * @param material material to use for this render pass. If undefined is passed, no specific material will be used for this render pass but the regular material will be used instead (mesh.material)\r\n */\r\n public setMaterialForRenderPass(renderPassId: number, material?: Material): void {\r\n this.resetDrawCache(renderPassId);\r\n if (!this._internalAbstractMeshDataInfo._materialForRenderPass) {\r\n this._internalAbstractMeshDataInfo._materialForRenderPass = [];\r\n }\r\n this._internalAbstractMeshDataInfo._materialForRenderPass[renderPassId] = material;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this mesh can receive realtime shadows\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\r\n */\r\n public get receiveShadows(): boolean {\r\n return this._internalAbstractMeshDataInfo._receiveShadows;\r\n }\r\n public set receiveShadows(value: boolean) {\r\n if (this._internalAbstractMeshDataInfo._receiveShadows === value) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._receiveShadows = value;\r\n this._markSubMeshesAsLightDirty();\r\n }\r\n\r\n /** Defines color to use when rendering outline */\r\n public outlineColor = Color3.Red();\r\n /** Define width to use when rendering outline */\r\n public outlineWidth = 0.02;\r\n\r\n /** Defines color to use when rendering overlay */\r\n public overlayColor = Color3.Red();\r\n /** Defines alpha to use when rendering overlay */\r\n public overlayAlpha = 0.5;\r\n\r\n /** Gets or sets a boolean indicating that this mesh contains vertex color data with alpha values */\r\n public get hasVertexAlpha(): boolean {\r\n return this._internalAbstractMeshDataInfo._hasVertexAlpha;\r\n }\r\n public set hasVertexAlpha(value: boolean) {\r\n if (this._internalAbstractMeshDataInfo._hasVertexAlpha === value) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._hasVertexAlpha = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n this._markSubMeshesAsMiscDirty();\r\n }\r\n\r\n /** Gets or sets a boolean indicating that this mesh needs to use vertex color data to render (if this kind of vertex data is available in the geometry) */\r\n public get useVertexColors(): boolean {\r\n return this._internalAbstractMeshDataInfo._useVertexColors;\r\n }\r\n public set useVertexColors(value: boolean) {\r\n if (this._internalAbstractMeshDataInfo._useVertexColors === value) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._useVertexColors = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that bone animations must be computed by the GPU (true by default)\r\n */\r\n public get computeBonesUsingShaders(): boolean {\r\n return this._internalAbstractMeshDataInfo._computeBonesUsingShaders;\r\n }\r\n public set computeBonesUsingShaders(value: boolean) {\r\n if (this._internalAbstractMeshDataInfo._computeBonesUsingShaders === value) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._computeBonesUsingShaders = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n\r\n /** Gets or sets the number of allowed bone influences per vertex (4 by default) */\r\n public get numBoneInfluencers(): number {\r\n return this._internalAbstractMeshDataInfo._numBoneInfluencers;\r\n }\r\n public set numBoneInfluencers(value: number) {\r\n if (this._internalAbstractMeshDataInfo._numBoneInfluencers === value) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._numBoneInfluencers = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n\r\n /** Gets or sets a boolean indicating that this mesh will allow fog to be rendered on it (true by default) */\r\n public get applyFog(): boolean {\r\n return this._internalAbstractMeshDataInfo._applyFog;\r\n }\r\n public set applyFog(value: boolean) {\r\n if (this._internalAbstractMeshDataInfo._applyFog === value) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._applyFog = value;\r\n this._markSubMeshesAsMiscDirty();\r\n }\r\n\r\n /** When enabled, decompose picking matrices for better precision with large values for mesh position and scling */\r\n public get enableDistantPicking(): boolean {\r\n return this._internalAbstractMeshDataInfo._enableDistantPicking;\r\n }\r\n public set enableDistantPicking(value: boolean) {\r\n this._internalAbstractMeshDataInfo._enableDistantPicking = value;\r\n }\r\n\r\n /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes selection (true by default) */\r\n public useOctreeForRenderingSelection = true;\r\n /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes picking (true by default) */\r\n public useOctreeForPicking = true;\r\n /** Gets or sets a boolean indicating that internal octree (if available) can be used to boost submeshes collision (true by default) */\r\n public useOctreeForCollisions = true;\r\n /**\r\n * Gets or sets the current layer mask (default is 0x0FFFFFFF)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/layerMasksAndMultiCam\r\n */\r\n public get layerMask(): number {\r\n return this._internalAbstractMeshDataInfo._layerMask;\r\n }\r\n\r\n public set layerMask(value: number) {\r\n if (value === this._internalAbstractMeshDataInfo._layerMask) {\r\n return;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._layerMask = value;\r\n this._resyncLightSources();\r\n }\r\n\r\n /**\r\n * True if the mesh must be rendered in any case (this will shortcut the frustum clipping phase)\r\n */\r\n public alwaysSelectAsActiveMesh = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the bounding info does not need to be kept in sync (for performance reason)\r\n */\r\n public doNotSyncBoundingInfo = false;\r\n\r\n /**\r\n * Gets or sets the current action manager\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions\r\n */\r\n public actionManager: Nullable = null;\r\n\r\n /**\r\n * Gets or sets the ellipsoid used to impersonate this mesh when using collision engine (default is (0.5, 1, 0.5))\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n */\r\n public ellipsoid = new Vector3(0.5, 1, 0.5);\r\n /**\r\n * Gets or sets the ellipsoid offset used to impersonate this mesh when using collision engine (default is (0, 0, 0))\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n */\r\n public ellipsoidOffset = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * Gets or sets a collision mask used to mask collisions (default is -1).\r\n * A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0\r\n */\r\n public get collisionMask(): number {\r\n return this._internalAbstractMeshDataInfo._meshCollisionData._collisionMask;\r\n }\r\n\r\n public set collisionMask(mask: number) {\r\n this._internalAbstractMeshDataInfo._meshCollisionData._collisionMask = !isNaN(mask) ? mask : -1;\r\n }\r\n\r\n /**\r\n * Gets or sets a collision response flag (default is true).\r\n * when collisionResponse is false, events are still triggered but colliding entity has no response\r\n * This helps creating trigger volume when user wants collision feedback events but not position/velocity\r\n * to respond to the collision.\r\n */\r\n public get collisionResponse(): boolean {\r\n return this._internalAbstractMeshDataInfo._meshCollisionData._collisionResponse;\r\n }\r\n\r\n public set collisionResponse(response: boolean) {\r\n this._internalAbstractMeshDataInfo._meshCollisionData._collisionResponse = response;\r\n }\r\n /**\r\n * Gets or sets the current collision group mask (-1 by default).\r\n * A collision between A and B will happen if A.collisionGroup & b.collisionMask !== 0\r\n */\r\n public get collisionGroup(): number {\r\n return this._internalAbstractMeshDataInfo._meshCollisionData._collisionGroup;\r\n }\r\n\r\n public set collisionGroup(mask: number) {\r\n this._internalAbstractMeshDataInfo._meshCollisionData._collisionGroup = !isNaN(mask) ? mask : -1;\r\n }\r\n\r\n /**\r\n * Gets or sets current surrounding meshes (null by default).\r\n *\r\n * By default collision detection is tested against every mesh in the scene.\r\n * It is possible to set surroundingMeshes to a defined list of meshes and then only these specified\r\n * meshes will be tested for the collision.\r\n *\r\n * Note: if set to an empty array no collision will happen when this mesh is moved.\r\n */\r\n public get surroundingMeshes(): Nullable {\r\n return this._internalAbstractMeshDataInfo._meshCollisionData._surroundingMeshes;\r\n }\r\n\r\n public set surroundingMeshes(meshes: Nullable) {\r\n this._internalAbstractMeshDataInfo._meshCollisionData._surroundingMeshes = meshes;\r\n }\r\n\r\n // Edges\r\n /**\r\n * Defines edge width used when edgesRenderer is enabled\r\n * @see https://www.babylonjs-playground.com/#10OJSG#13\r\n */\r\n public edgesWidth = 1;\r\n /**\r\n * Defines edge color used when edgesRenderer is enabled\r\n * @see https://www.babylonjs-playground.com/#10OJSG#13\r\n */\r\n public edgesColor = new Color4(1, 0, 0, 1);\r\n /** @internal */\r\n public _edgesRenderer: Nullable = null;\r\n\r\n /** @internal */\r\n public _masterMesh: Nullable = null;\r\n protected _boundingInfo: Nullable = null;\r\n protected _boundingInfoIsDirty = true;\r\n /** @internal */\r\n public _renderId = 0;\r\n\r\n /**\r\n * Gets or sets the list of subMeshes\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\r\n */\r\n public subMeshes: SubMesh[];\r\n\r\n /** @internal */\r\n public _intersectionsInProgress = new Array();\r\n\r\n /** @internal */\r\n public _unIndexed = false;\r\n\r\n /** @internal */\r\n public _lightSources = new Array();\r\n\r\n /** Gets the list of lights affecting that mesh */\r\n public get lightSources(): Light[] {\r\n return this._lightSources;\r\n }\r\n\r\n /** @internal */\r\n public get _positions(): Nullable {\r\n return null;\r\n }\r\n\r\n // Loading properties\r\n /** @internal */\r\n public _waitingData: {\r\n lods: Nullable;\r\n actions: Nullable;\r\n freezeWorldMatrix: Nullable;\r\n } = {\r\n lods: null,\r\n actions: null,\r\n freezeWorldMatrix: null,\r\n };\r\n\r\n /** @internal */\r\n public _bonesTransformMatrices: Nullable = null;\r\n\r\n /** @internal */\r\n public _transformMatrixTexture: Nullable = null;\r\n\r\n /**\r\n * Gets or sets a skeleton to apply skinning transformations\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons\r\n */\r\n public set skeleton(value: Nullable) {\r\n const skeleton = this._internalAbstractMeshDataInfo._skeleton;\r\n if (skeleton && skeleton.needInitialSkinMatrix) {\r\n skeleton._unregisterMeshWithPoseMatrix(this);\r\n }\r\n\r\n if (value && value.needInitialSkinMatrix) {\r\n value._registerMeshWithPoseMatrix(this);\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._skeleton = value;\r\n\r\n if (!this._internalAbstractMeshDataInfo._skeleton) {\r\n this._bonesTransformMatrices = null;\r\n }\r\n\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n\r\n public get skeleton(): Nullable {\r\n return this._internalAbstractMeshDataInfo._skeleton;\r\n }\r\n\r\n /**\r\n * An event triggered when the mesh is rebuilt.\r\n */\r\n public onRebuildObservable = new Observable();\r\n\r\n /**\r\n * The current mesh uniform buffer.\r\n * @internal Internal use only.\r\n */\r\n public _uniformBuffer: UniformBuffer;\r\n\r\n // Constructor\r\n\r\n /**\r\n * Creates a new AbstractMesh\r\n * @param name defines the name of the mesh\r\n * @param scene defines the hosting scene\r\n */\r\n constructor(name: string, scene: Nullable = null) {\r\n super(name, scene, false);\r\n\r\n scene = this.getScene();\r\n\r\n scene.addMesh(this);\r\n\r\n this._resyncLightSources();\r\n\r\n // Mesh Uniform Buffer.\r\n this._uniformBuffer = new UniformBuffer(this.getScene().getEngine(), undefined, undefined, name, !this.getScene().getEngine().isWebGPU);\r\n this._buildUniformLayout();\r\n\r\n switch (scene.performancePriority) {\r\n case ScenePerformancePriority.Aggressive:\r\n this.doNotSyncBoundingInfo = true;\r\n // eslint-disable-next-line no-fallthrough\r\n case ScenePerformancePriority.Intermediate:\r\n this.alwaysSelectAsActiveMesh = true;\r\n this.isPickable = false;\r\n break;\r\n }\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"world\", 16);\r\n this._uniformBuffer.addUniform(\"visibility\", 1);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Transfer the mesh values to its UBO.\r\n * @param world The world matrix associated with the mesh\r\n */\r\n public transferToEffect(world: Matrix): void {\r\n const ubo = this._uniformBuffer;\r\n\r\n ubo.updateMatrix(\"world\", world);\r\n ubo.updateFloat(\"visibility\", this._internalAbstractMeshDataInfo._visibility);\r\n\r\n ubo.update();\r\n }\r\n\r\n /**\r\n * Gets the mesh uniform buffer.\r\n * @returns the uniform buffer of the mesh.\r\n */\r\n public getMeshUniformBuffer(): UniformBuffer {\r\n return this._uniformBuffer;\r\n }\r\n\r\n /**\r\n * Returns the string \"AbstractMesh\"\r\n * @returns \"AbstractMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"AbstractMesh\";\r\n }\r\n\r\n /**\r\n * Gets a string representation of the current mesh\r\n * @param fullDetails defines a boolean indicating if full details must be included\r\n * @returns a string representation of the current mesh\r\n */\r\n public toString(fullDetails?: boolean): string {\r\n let ret = \"Name: \" + this.name + \", isInstance: \" + (this.getClassName() !== \"InstancedMesh\" ? \"YES\" : \"NO\");\r\n ret += \", # of submeshes: \" + (this.subMeshes ? this.subMeshes.length : 0);\r\n\r\n const skeleton = this._internalAbstractMeshDataInfo._skeleton;\r\n if (skeleton) {\r\n ret += \", skeleton: \" + skeleton.name;\r\n }\r\n if (fullDetails) {\r\n ret += \", billboard mode: \" + [\"NONE\", \"X\", \"Y\", null, \"Z\", null, null, \"ALL\"][this.billboardMode];\r\n ret += \", freeze wrld mat: \" + (this._isWorldMatrixFrozen || this._waitingData.freezeWorldMatrix ? \"YES\" : \"NO\");\r\n }\r\n return ret;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n protected _getEffectiveParent(): Nullable {\r\n if (this._masterMesh && this.billboardMode !== TransformNode.BILLBOARDMODE_NONE) {\r\n return this._masterMesh;\r\n }\r\n\r\n return super._getEffectiveParent();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getActionManagerForTrigger(trigger?: number, initialCall = true): Nullable {\r\n if (this.actionManager && (initialCall || this.actionManager.isRecursive)) {\r\n if (trigger) {\r\n if (this.actionManager.hasSpecificTrigger(trigger)) {\r\n return this.actionManager;\r\n }\r\n } else {\r\n return this.actionManager;\r\n }\r\n }\r\n\r\n if (!this.parent) {\r\n return null;\r\n }\r\n\r\n return this.parent._getActionManagerForTrigger(trigger, false);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _rebuild(dispose = false): void {\r\n this.onRebuildObservable.notifyObservers(this);\r\n\r\n if (this._occlusionQuery !== null) {\r\n this._occlusionQuery = null;\r\n }\r\n\r\n if (!this.subMeshes) {\r\n return;\r\n }\r\n\r\n for (const subMesh of this.subMeshes) {\r\n subMesh._rebuild();\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _resyncLightSources(): void {\r\n this._lightSources.length = 0;\r\n\r\n for (const light of this.getScene().lights) {\r\n if (!light.isEnabled()) {\r\n continue;\r\n }\r\n\r\n if (light.canAffectMesh(this)) {\r\n this._lightSources.push(light);\r\n }\r\n }\r\n\r\n this._markSubMeshesAsLightDirty();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _resyncLightSource(light: Light): void {\r\n const isIn = light.isEnabled() && light.canAffectMesh(this);\r\n\r\n const index = this._lightSources.indexOf(light);\r\n let removed = false;\r\n if (index === -1) {\r\n if (!isIn) {\r\n return;\r\n }\r\n this._lightSources.push(light);\r\n } else {\r\n if (isIn) {\r\n return;\r\n }\r\n removed = true;\r\n this._lightSources.splice(index, 1);\r\n }\r\n\r\n this._markSubMeshesAsLightDirty(removed);\r\n }\r\n\r\n /** @internal */\r\n public _unBindEffect() {\r\n for (const subMesh of this.subMeshes) {\r\n subMesh.setEffect(null);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _removeLightSource(light: Light, dispose: boolean): void {\r\n const index = this._lightSources.indexOf(light);\r\n\r\n if (index === -1) {\r\n return;\r\n }\r\n this._lightSources.splice(index, 1);\r\n\r\n this._markSubMeshesAsLightDirty(dispose);\r\n }\r\n\r\n private _markSubMeshesAsDirty(func: (defines: MaterialDefines) => void) {\r\n if (!this.subMeshes) {\r\n return;\r\n }\r\n\r\n for (const subMesh of this.subMeshes) {\r\n for (let i = 0; i < subMesh._drawWrappers.length; ++i) {\r\n const drawWrapper = subMesh._drawWrappers[i];\r\n if (!drawWrapper || !drawWrapper.defines || !(drawWrapper.defines as MaterialDefines).markAllAsDirty) {\r\n continue;\r\n }\r\n func(drawWrapper.defines as MaterialDefines);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _markSubMeshesAsLightDirty(dispose: boolean = false) {\r\n this._markSubMeshesAsDirty((defines) => defines.markAsLightDirty(dispose));\r\n }\r\n\r\n /** @internal */\r\n public _markSubMeshesAsAttributesDirty() {\r\n this._markSubMeshesAsDirty((defines) => defines.markAsAttributesDirty());\r\n }\r\n\r\n /** @internal */\r\n public _markSubMeshesAsMiscDirty() {\r\n this._markSubMeshesAsDirty((defines) => defines.markAsMiscDirty());\r\n }\r\n\r\n /**\r\n * Flag the AbstractMesh as dirty (Forcing it to update everything)\r\n * @param property if set to \"rotation\" the objects rotationQuaternion will be set to null\r\n * @returns this AbstractMesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public markAsDirty(property?: string): AbstractMesh {\r\n this._currentRenderId = Number.MAX_VALUE;\r\n this._isDirty = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Resets the draw wrappers cache for all submeshes of this abstract mesh\r\n * @param passId If provided, releases only the draw wrapper corresponding to this render pass id\r\n */\r\n public resetDrawCache(passId?: number): void {\r\n if (!this.subMeshes) {\r\n return;\r\n }\r\n\r\n for (const subMesh of this.subMeshes) {\r\n subMesh.resetDrawCache(passId);\r\n }\r\n }\r\n\r\n // Methods\r\n /**\r\n * Returns true if the mesh is blocked. Implemented by child classes\r\n */\r\n public get isBlocked(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Returns the mesh itself by default. Implemented by child classes\r\n * @param camera defines the camera to use to pick the right LOD level\r\n * @returns the currentAbstractMesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getLOD(camera: Camera): Nullable {\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns 0 by default. Implemented by child classes\r\n * @returns an integer\r\n */\r\n public getTotalVertices(): number {\r\n return 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 0;\r\n }\r\n\r\n /**\r\n * Returns null by default. Implemented by child classes\r\n * @returns null\r\n */\r\n public getIndices(): Nullable {\r\n return null;\r\n }\r\n\r\n /**\r\n * Returns the array of the requested vertex data kind. Implemented by child classes\r\n * @param kind defines the vertex data kind to use\r\n * @returns null\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getVerticesData(kind: string): Nullable {\r\n return null;\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 * 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 * @param kind defines vertex data kind:\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 * @param data defines the data source\r\n * @param updatable defines if the data must be flagged as updatable (or static)\r\n * @param stride defines the vertex stride (size of an entire vertex). Can be null and in this case will be deduced from vertex data kind\r\n * @returns the current mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public setVerticesData(kind: string, data: FloatArray, updatable?: boolean, stride?: number): AbstractMesh {\r\n return this;\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 * @param kind defines vertex data kind:\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 * @param data defines the data source\r\n * @param updateExtends If `kind` is `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 * @param makeItUnique If true, a new global geometry is created from this data and is set to the mesh\r\n * @returns the current mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public updateVerticesData(kind: string, data: FloatArray, updateExtends?: boolean, makeItUnique?: boolean): AbstractMesh {\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the mesh indices,\r\n * If the mesh has no geometry, a new Geometry object is created and set to the mesh.\r\n * @param indices Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array)\r\n * @param totalVertices Defines the total number of vertices\r\n * @returns the current mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public setIndices(indices: IndicesArray, totalVertices: Nullable): AbstractMesh {\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if specific vertex data is present\r\n * @param kind defines the vertex data kind to use\r\n * @returns true is data kind is present\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isVerticesDataPresent(kind: string): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Returns the mesh BoundingInfo object or creates a new one and returns if it was undefined.\r\n * Note that it returns a shallow bounding of the mesh (i.e. it does not include children).\r\n * However, if the mesh contains thin instances, it will be expanded to include them. If you want the \"raw\" bounding data instead, then use `getRawBoundingInfo()`.\r\n * To get the full bounding of all children, call `getHierarchyBoundingVectors` instead.\r\n * @returns a BoundingInfo\r\n */\r\n public getBoundingInfo(): BoundingInfo {\r\n if (this._masterMesh) {\r\n return this._masterMesh.getBoundingInfo();\r\n }\r\n\r\n if (this._boundingInfoIsDirty) {\r\n this._boundingInfoIsDirty = false;\r\n // this._boundingInfo is being created if undefined\r\n this._updateBoundingInfo();\r\n }\r\n // cannot be null.\r\n return this._boundingInfo!;\r\n }\r\n\r\n /**\r\n * Returns the bounding info unnafected by instance data.\r\n * @returns the bounding info of the mesh unaffected by instance data.\r\n */\r\n public getRawBoundingInfo() {\r\n return this.rawBoundingInfo ?? this.getBoundingInfo();\r\n }\r\n\r\n /**\r\n * Overwrite the current bounding info\r\n * @param boundingInfo defines the new bounding info\r\n * @returns the current mesh\r\n */\r\n public setBoundingInfo(boundingInfo: BoundingInfo): AbstractMesh {\r\n this._boundingInfo = boundingInfo;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns true if there is already a bounding info\r\n */\r\n public get hasBoundingInfo(): boolean {\r\n return this._boundingInfo !== null;\r\n }\r\n\r\n /**\r\n * Creates a new bounding info for the mesh\r\n * @param minimum min vector of the bounding box/sphere\r\n * @param maximum max vector of the bounding box/sphere\r\n * @param worldMatrix defines the new world matrix\r\n * @returns the new bounding info\r\n */\r\n public buildBoundingInfo(minimum: DeepImmutable, maximum: DeepImmutable, worldMatrix?: DeepImmutable) {\r\n this._boundingInfo = new BoundingInfo(minimum, maximum, worldMatrix);\r\n return this._boundingInfo;\r\n }\r\n\r\n /**\r\n * Uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units)\r\n * @param includeDescendants Use the hierarchy's bounding box instead of the mesh's bounding box. Default is false\r\n * @param ignoreRotation ignore rotation when computing the scale (ie. object will be axis aligned). Default is false\r\n * @param predicate predicate that is passed in to getHierarchyBoundingVectors when selecting which object should be included when scaling\r\n * @returns the current mesh\r\n */\r\n public normalizeToUnitCube(includeDescendants = true, ignoreRotation = false, predicate?: Nullable<(node: AbstractMesh) => boolean>): AbstractMesh {\r\n return super.normalizeToUnitCube(includeDescendants, ignoreRotation, predicate);\r\n }\r\n\r\n /** Gets a boolean indicating if this mesh has skinning data and an attached skeleton */\r\n public get useBones(): boolean {\r\n return (\r\n (this.skeleton &&\r\n this.getScene().skeletonsEnabled &&\r\n this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind) &&\r\n this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind))\r\n );\r\n }\r\n\r\n /** @internal */\r\n public _preActivate(): void {}\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _preActivateForIntermediateRendering(renderId: number): void {}\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _activate(renderId: number, intermediateRendering: boolean): boolean {\r\n this._renderId = renderId;\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public _postActivate(): void {\r\n // Do nothing\r\n }\r\n\r\n /** @internal */\r\n public _freeze() {\r\n // Do nothing\r\n }\r\n\r\n /** @internal */\r\n public _unFreeze() {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Gets the current world matrix\r\n * @returns a Matrix\r\n */\r\n public getWorldMatrix(): Matrix {\r\n if (this._masterMesh && this.billboardMode === TransformNode.BILLBOARDMODE_NONE) {\r\n return this._masterMesh.getWorldMatrix();\r\n }\r\n\r\n return super.getWorldMatrix();\r\n }\r\n\r\n /** @internal */\r\n public _getWorldMatrixDeterminant(): number {\r\n if (this._masterMesh) {\r\n return this._masterMesh._getWorldMatrixDeterminant();\r\n }\r\n\r\n return super._getWorldMatrixDeterminant();\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if this mesh is an instance or a regular mesh\r\n */\r\n public get isAnInstance(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if this mesh has instances\r\n */\r\n public get hasInstances(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if this mesh has thin instances\r\n */\r\n public get hasThinInstances(): boolean {\r\n return false;\r\n }\r\n\r\n // ================================== Point of View Movement =================================\r\n\r\n /**\r\n * Perform relative position change from the point of view of behind the front of the mesh.\r\n * This is performed taking into account the meshes current rotation, so you do not have to care.\r\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\r\n * @param amountRight defines the distance on the right axis\r\n * @param amountUp defines the distance on the up axis\r\n * @param amountForward defines the distance on the forward axis\r\n * @returns the current mesh\r\n */\r\n public movePOV(amountRight: number, amountUp: number, amountForward: number): AbstractMesh {\r\n this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));\r\n return this;\r\n }\r\n\r\n /**\r\n * Calculate relative position change from the point of view of behind the front of the mesh.\r\n * This is performed taking into account the meshes current rotation, so you do not have to care.\r\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\r\n * @param amountRight defines the distance on the right axis\r\n * @param amountUp defines the distance on the up axis\r\n * @param amountForward defines the distance on the forward axis\r\n * @returns the new displacement vector\r\n */\r\n public calcMovePOV(amountRight: number, amountUp: number, amountForward: number): Vector3 {\r\n const rotMatrix = new Matrix();\r\n const rotQuaternion = this.rotationQuaternion ? this.rotationQuaternion : Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);\r\n rotQuaternion.toRotationMatrix(rotMatrix);\r\n\r\n const translationDelta = Vector3.Zero();\r\n const defForwardMult = this.definedFacingForward ? -1 : 1;\r\n Vector3.TransformCoordinatesFromFloatsToRef(amountRight * defForwardMult, amountUp, amountForward * defForwardMult, rotMatrix, translationDelta);\r\n return translationDelta;\r\n }\r\n // ================================== Point of View Rotation =================================\r\n /**\r\n * Perform relative rotation change from the point of view of behind the front of the mesh.\r\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\r\n * @param flipBack defines the flip\r\n * @param twirlClockwise defines the twirl\r\n * @param tiltRight defines the tilt\r\n * @returns the current mesh\r\n */\r\n public rotatePOV(flipBack: number, twirlClockwise: number, tiltRight: number): AbstractMesh {\r\n this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));\r\n return this;\r\n }\r\n\r\n /**\r\n * Calculate relative rotation change from the point of view of behind the front of the mesh.\r\n * Supports definition of mesh facing forward or backward {@link definedFacingForwardSearch | See definedFacingForwardSearch }.\r\n * @param flipBack defines the flip\r\n * @param twirlClockwise defines the twirl\r\n * @param tiltRight defines the tilt\r\n * @returns the new rotation vector\r\n */\r\n public calcRotatePOV(flipBack: number, twirlClockwise: number, tiltRight: number): Vector3 {\r\n const defForwardMult = this.definedFacingForward ? 1 : -1;\r\n return new Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);\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): AbstractMesh {\r\n if (this._boundingInfo && this._boundingInfo.isLocked) {\r\n return this;\r\n }\r\n\r\n this._refreshBoundingInfo(this._getPositionData(applySkeleton, applyMorph), null);\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _refreshBoundingInfo(data: Nullable, bias: Nullable): void {\r\n if (data) {\r\n const extend = extractMinAndMax(data, 0, this.getTotalVertices(), bias);\r\n if (this._boundingInfo) {\r\n this._boundingInfo.reConstruct(extend.minimum, extend.maximum);\r\n } else {\r\n this._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);\r\n }\r\n }\r\n\r\n if (this.subMeshes) {\r\n for (let index = 0; index < this.subMeshes.length; index++) {\r\n this.subMeshes[index].refreshBoundingInfo(data);\r\n }\r\n }\r\n\r\n this._updateBoundingInfo();\r\n }\r\n\r\n /**\r\n * Internal function to get buffer data and possibly apply morphs and normals\r\n * @param applySkeleton\r\n * @param applyMorph\r\n * @param data\r\n * @param kind the kind of data you want. Can be Normal or Position\r\n */\r\n private _getData(applySkeleton: boolean = false, applyMorph: boolean = false, data?: Nullable, kind: string = VertexBuffer.PositionKind): Nullable {\r\n data = data ?? this.getVerticesData(kind)!.slice();\r\n\r\n if (data && applyMorph && this.morphTargetManager) {\r\n let faceIndexCount = 0;\r\n let positionIndex = 0;\r\n for (let vertexCount = 0; vertexCount < data.length; vertexCount++) {\r\n for (let targetCount = 0; targetCount < this.morphTargetManager.numTargets; targetCount++) {\r\n const targetMorph = this.morphTargetManager.getTarget(targetCount);\r\n const influence = targetMorph.influence;\r\n if (influence > 0.0) {\r\n const morphTargetPositions = targetMorph.getPositions();\r\n if (morphTargetPositions) {\r\n data[vertexCount] += (morphTargetPositions[vertexCount] - data[vertexCount]) * influence;\r\n }\r\n }\r\n }\r\n\r\n faceIndexCount++;\r\n if (kind === VertexBuffer.PositionKind) {\r\n if (this._positions && faceIndexCount === 3) {\r\n // We want to merge into positions every 3 indices starting (but not 0)\r\n faceIndexCount = 0;\r\n const index = positionIndex * 3;\r\n this._positions[positionIndex++].copyFromFloats(data[index], data[index + 1], data[index + 2]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (data && applySkeleton && this.skeleton) {\r\n const matricesIndicesData = this.getVerticesData(VertexBuffer.MatricesIndicesKind);\r\n const matricesWeightsData = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\r\n if (matricesWeightsData && matricesIndicesData) {\r\n const needExtras = this.numBoneInfluencers > 4;\r\n const matricesIndicesExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;\r\n const matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;\r\n\r\n const skeletonMatrices = this.skeleton.getTransformMatrices(this);\r\n\r\n const tempVector = TmpVectors.Vector3[0];\r\n const finalMatrix = TmpVectors.Matrix[0];\r\n const tempMatrix = TmpVectors.Matrix[1];\r\n\r\n let matWeightIdx = 0;\r\n for (let index = 0; index < data.length; index += 3, matWeightIdx += 4) {\r\n finalMatrix.reset();\r\n\r\n let inf: number;\r\n let weight: number;\r\n for (inf = 0; inf < 4; inf++) {\r\n weight = matricesWeightsData[matWeightIdx + inf];\r\n if (weight > 0) {\r\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesData[matWeightIdx + inf] * 16), weight, tempMatrix);\r\n finalMatrix.addToSelf(tempMatrix);\r\n }\r\n }\r\n if (needExtras) {\r\n for (inf = 0; inf < 4; inf++) {\r\n weight = matricesWeightsExtraData![matWeightIdx + inf];\r\n if (weight > 0) {\r\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesExtraData![matWeightIdx + inf] * 16), weight, tempMatrix);\r\n finalMatrix.addToSelf(tempMatrix);\r\n }\r\n }\r\n }\r\n\r\n if (kind === VertexBuffer.NormalKind) {\r\n Vector3.TransformNormalFromFloatsToRef(data[index], data[index + 1], data[index + 2], finalMatrix, tempVector);\r\n } else {\r\n Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], finalMatrix, tempVector);\r\n }\r\n tempVector.toArray(data, index);\r\n\r\n if (kind === VertexBuffer.PositionKind && this._positions) {\r\n this._positions[index / 3].copyFrom(tempVector);\r\n }\r\n }\r\n }\r\n }\r\n\r\n return data;\r\n }\r\n\r\n /**\r\n * Get the normals vertex data and optionally apply skeleton and morphing.\r\n * @param applySkeleton defines whether to apply the skeleton\r\n * @param applyMorph defines whether to apply the morph target\r\n * @returns the normals data\r\n */\r\n public getNormalsData(applySkeleton = false, applyMorph = false): Nullable {\r\n return this._getData(applySkeleton, applyMorph, null, VertexBuffer.NormalKind);\r\n }\r\n\r\n /**\r\n * Get the position vertex data and optionally apply skeleton and morphing.\r\n * @param applySkeleton defines whether to apply the skeleton\r\n * @param applyMorph defines whether to apply the morph target\r\n * @param data defines the position data to apply the skeleton and morph to\r\n * @returns the position data\r\n */\r\n public getPositionData(applySkeleton: boolean = false, applyMorph: boolean = false, data?: Nullable): Nullable {\r\n return this._getData(applySkeleton, applyMorph, data, VertexBuffer.PositionKind);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getPositionData(applySkeleton: boolean, applyMorph: boolean): Nullable {\r\n let data = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (this._internalAbstractMeshDataInfo._positions) {\r\n this._internalAbstractMeshDataInfo._positions = null;\r\n }\r\n\r\n if (data && ((applySkeleton && this.skeleton) || (applyMorph && this.morphTargetManager))) {\r\n data = data.slice();\r\n this._generatePointsArray();\r\n if (this._positions) {\r\n const pos = this._positions;\r\n this._internalAbstractMeshDataInfo._positions = new Array(pos.length);\r\n for (let i = 0; i < pos.length; i++) {\r\n this._internalAbstractMeshDataInfo._positions[i] = pos[i]?.clone() || new Vector3();\r\n }\r\n }\r\n return this.getPositionData(applySkeleton, applyMorph, data);\r\n }\r\n\r\n return data;\r\n }\r\n\r\n /** @internal */\r\n public _updateBoundingInfo(): AbstractMesh {\r\n if (this._boundingInfo) {\r\n this._boundingInfo.update(this.worldMatrixFromCache);\r\n } else {\r\n this._boundingInfo = new BoundingInfo(Vector3.Zero(), Vector3.Zero(), this.worldMatrixFromCache);\r\n }\r\n this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateSubMeshesBoundingInfo(matrix: DeepImmutable): AbstractMesh {\r\n if (!this.subMeshes) {\r\n return this;\r\n }\r\n const count = this.subMeshes.length;\r\n for (let subIndex = 0; subIndex < count; subIndex++) {\r\n const subMesh = this.subMeshes[subIndex];\r\n if (count > 1 || !subMesh.IsGlobal) {\r\n subMesh.updateBoundingInfo(matrix);\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n protected _afterComputeWorldMatrix(): void {\r\n if (this.doNotSyncBoundingInfo) {\r\n return;\r\n }\r\n // Bounding info\r\n this._boundingInfoIsDirty = true;\r\n }\r\n\r\n /**\r\n * Returns `true` if the mesh is within the frustum defined by the passed array of planes.\r\n * A mesh is in the frustum if its bounding box intersects the frustum\r\n * @param frustumPlanes defines the frustum to test\r\n * @returns true if the mesh is in the frustum planes\r\n */\r\n public isInFrustum(frustumPlanes: Plane[]): boolean {\r\n return this.getBoundingInfo().isInFrustum(frustumPlanes, this.cullingStrategy);\r\n }\r\n\r\n /**\r\n * Returns `true` if the mesh is completely in the frustum defined be the passed array of planes.\r\n * A mesh is completely in the frustum if its bounding box it completely inside the frustum.\r\n * @param frustumPlanes defines the frustum to test\r\n * @returns true if the mesh is completely in the frustum planes\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {\r\n return this.getBoundingInfo().isCompletelyInFrustum(frustumPlanes);\r\n }\r\n\r\n /**\r\n * True if the mesh intersects another mesh or a SolidParticle object\r\n * @param mesh defines a target mesh or SolidParticle to test\r\n * @param precise Unless the parameter `precise` is set to `true` the intersection is computed according to Axis Aligned Bounding Boxes (AABB), else according to OBB (Oriented BBoxes)\r\n * @param includeDescendants Can be set to true to test if the mesh defined in parameters intersects with the current mesh or any child meshes\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsMesh(mesh: AbstractMesh | SolidParticle, precise: boolean = false, includeDescendants?: boolean): boolean {\r\n const boundingInfo = this.getBoundingInfo();\r\n const otherBoundingInfo = mesh.getBoundingInfo();\r\n\r\n if (boundingInfo.intersects(otherBoundingInfo, precise)) {\r\n return true;\r\n }\r\n\r\n if (includeDescendants) {\r\n for (const child of this.getChildMeshes()) {\r\n if (child.intersectsMesh(mesh, precise, true)) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Returns true if the passed point (Vector3) is inside the mesh bounding box\r\n * @param point defines the point to test\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsPoint(point: Vector3): boolean {\r\n return this.getBoundingInfo().intersectsPoint(point);\r\n }\r\n\r\n // Collisions\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this mesh can be used in the collision engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n */\r\n public get checkCollisions(): boolean {\r\n return this._internalAbstractMeshDataInfo._meshCollisionData._checkCollisions;\r\n }\r\n\r\n public set checkCollisions(collisionEnabled: boolean) {\r\n this._internalAbstractMeshDataInfo._meshCollisionData._checkCollisions = collisionEnabled;\r\n }\r\n\r\n /**\r\n * Gets Collider object used to compute collisions (not physics)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n */\r\n public get collider(): Nullable {\r\n return this._internalAbstractMeshDataInfo._meshCollisionData._collider;\r\n }\r\n\r\n /**\r\n * Move the mesh using collision engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions\r\n * @param displacement defines the requested displacement vector\r\n * @returns the current mesh\r\n */\r\n public moveWithCollisions(displacement: Vector3): AbstractMesh {\r\n const globalPosition = this.getAbsolutePosition();\r\n\r\n globalPosition.addToRef(this.ellipsoidOffset, this._internalAbstractMeshDataInfo._meshCollisionData._oldPositionForCollisions);\r\n const coordinator = this.getScene().collisionCoordinator;\r\n\r\n if (!this._internalAbstractMeshDataInfo._meshCollisionData._collider) {\r\n this._internalAbstractMeshDataInfo._meshCollisionData._collider = coordinator.createCollider();\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._meshCollisionData._collider._radius = this.ellipsoid;\r\n\r\n coordinator.getNewPosition(\r\n this._internalAbstractMeshDataInfo._meshCollisionData._oldPositionForCollisions,\r\n displacement,\r\n this._internalAbstractMeshDataInfo._meshCollisionData._collider,\r\n this.collisionRetryCount,\r\n this,\r\n this._onCollisionPositionChange,\r\n this.uniqueId\r\n );\r\n return this;\r\n }\r\n\r\n private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable = null) => {\r\n newPosition.subtractToRef(\r\n this._internalAbstractMeshDataInfo._meshCollisionData._oldPositionForCollisions,\r\n this._internalAbstractMeshDataInfo._meshCollisionData._diffPositionForCollisions\r\n );\r\n\r\n if (this._internalAbstractMeshDataInfo._meshCollisionData._diffPositionForCollisions.length() > Engine.CollisionsEpsilon) {\r\n this.position.addInPlace(this._internalAbstractMeshDataInfo._meshCollisionData._diffPositionForCollisions);\r\n }\r\n\r\n if (collidedMesh) {\r\n this.onCollideObservable.notifyObservers(collidedMesh);\r\n }\r\n\r\n this.onCollisionPositionChangeObservable.notifyObservers(this.position);\r\n };\r\n\r\n // Collisions\r\n /**\r\n * @internal\r\n */\r\n public _collideForSubMesh(subMesh: SubMesh, transformMatrix: Matrix, collider: Collider): AbstractMesh {\r\n this._generatePointsArray();\r\n\r\n if (!this._positions) {\r\n return this;\r\n }\r\n\r\n // Transformation\r\n if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix!.equals(transformMatrix)) {\r\n subMesh._lastColliderTransformMatrix = transformMatrix.clone();\r\n subMesh._lastColliderWorldVertices = [];\r\n subMesh._trianglePlanes = [];\r\n const start = subMesh.verticesStart;\r\n const end = subMesh.verticesStart + subMesh.verticesCount;\r\n for (let i = start; i < end; i++) {\r\n subMesh._lastColliderWorldVertices.push(Vector3.TransformCoordinates(this._positions[i], transformMatrix));\r\n }\r\n }\r\n\r\n // Collide\r\n collider._collide(\r\n subMesh._trianglePlanes,\r\n subMesh._lastColliderWorldVertices,\r\n this.getIndices(),\r\n subMesh.indexStart,\r\n subMesh.indexStart + subMesh.indexCount,\r\n subMesh.verticesStart,\r\n !!subMesh.getMaterial(),\r\n this,\r\n this._shouldConvertRHS(),\r\n subMesh.getMaterial()?.fillMode === Constants.MATERIAL_TriangleStripDrawMode\r\n );\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _processCollisionsForSubMeshes(collider: Collider, transformMatrix: Matrix): AbstractMesh {\r\n const subMeshes = this._scene.getCollidingSubMeshCandidates(this, collider);\r\n const len = subMeshes.length;\r\n\r\n for (let index = 0; index < len; index++) {\r\n const subMesh = subMeshes.data[index];\r\n\r\n // Bounding test\r\n if (len > 1 && !subMesh._checkCollision(collider)) {\r\n continue;\r\n }\r\n\r\n this._collideForSubMesh(subMesh, transformMatrix, collider);\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n public _shouldConvertRHS() {\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _checkCollision(collider: Collider): AbstractMesh {\r\n // Bounding box test\r\n if (!this.getBoundingInfo()._checkCollision(collider)) {\r\n return this;\r\n }\r\n\r\n // Transformation matrix\r\n const collisionsScalingMatrix = TmpVectors.Matrix[0];\r\n const collisionsTransformMatrix = TmpVectors.Matrix[1];\r\n Matrix.ScalingToRef(1.0 / collider._radius.x, 1.0 / collider._radius.y, 1.0 / collider._radius.z, collisionsScalingMatrix);\r\n this.worldMatrixFromCache.multiplyToRef(collisionsScalingMatrix, collisionsTransformMatrix);\r\n this._processCollisionsForSubMeshes(collider, collisionsTransformMatrix);\r\n return this;\r\n }\r\n\r\n // Picking\r\n /** @internal */\r\n public _generatePointsArray(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Checks if the passed Ray intersects with the mesh. A mesh triangle can be picked both from its front and back sides,\r\n * irrespective of orientation.\r\n * @param ray defines the ray to use. It should be in the mesh's LOCAL coordinate space.\r\n * @param fastCheck defines if fast mode (but less precise) must be used (false by default)\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\r\n * @param worldToUse defines the world matrix to use to get the world coordinate of the intersection point\r\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\r\n * @returns the picking info\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n */\r\n public intersects(\r\n ray: Ray,\r\n fastCheck?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate,\r\n onlyBoundingInfo = false,\r\n worldToUse?: Matrix,\r\n skipBoundingInfo = false\r\n ): PickingInfo {\r\n const pickingInfo = new PickingInfo();\r\n const className = this.getClassName();\r\n const intersectionThreshold = className === \"InstancedLinesMesh\" || className === \"LinesMesh\" || className === \"GreasedLineMesh\" ? (this as any).intersectionThreshold : 0;\r\n const boundingInfo = this.getBoundingInfo();\r\n if (!this.subMeshes) {\r\n return pickingInfo;\r\n }\r\n if (\r\n !skipBoundingInfo &&\r\n (!ray.intersectsSphere(boundingInfo.boundingSphere, intersectionThreshold) || !ray.intersectsBox(boundingInfo.boundingBox, intersectionThreshold))\r\n ) {\r\n return pickingInfo;\r\n }\r\n\r\n if (onlyBoundingInfo) {\r\n pickingInfo.hit = skipBoundingInfo ? false : true;\r\n pickingInfo.pickedMesh = skipBoundingInfo ? null : this;\r\n pickingInfo.distance = skipBoundingInfo ? 0 : Vector3.Distance(ray.origin, boundingInfo.boundingSphere.center);\r\n pickingInfo.subMeshId = 0;\r\n return pickingInfo;\r\n }\r\n\r\n if (!this._generatePointsArray()) {\r\n return pickingInfo;\r\n }\r\n\r\n let intersectInfo: Nullable = null;\r\n\r\n const subMeshes = this._scene.getIntersectingSubMeshCandidates(this, ray);\r\n const len: number = subMeshes.length;\r\n\r\n // Check if all submeshes are using a material that don't allow picking (point/lines rendering)\r\n // if no submesh can be picked that way, then fallback to BBox picking\r\n let anySubmeshSupportIntersect = false;\r\n for (let index = 0; index < len; index++) {\r\n const subMesh = subMeshes.data[index];\r\n const material = subMesh.getMaterial();\r\n if (!material) {\r\n continue;\r\n }\r\n if (\r\n material.fillMode == Constants.MATERIAL_TriangleStripDrawMode ||\r\n material.fillMode == Constants.MATERIAL_TriangleFillMode ||\r\n material.fillMode == Constants.MATERIAL_WireFrameFillMode ||\r\n material.fillMode == Constants.MATERIAL_PointFillMode ||\r\n material.fillMode == Constants.MATERIAL_LineListDrawMode\r\n ) {\r\n anySubmeshSupportIntersect = true;\r\n break;\r\n }\r\n }\r\n\r\n // no sub mesh support intersection, fallback to BBox that has already be done\r\n if (!anySubmeshSupportIntersect) {\r\n pickingInfo.hit = true;\r\n pickingInfo.pickedMesh = this;\r\n pickingInfo.distance = Vector3.Distance(ray.origin, boundingInfo.boundingSphere.center);\r\n pickingInfo.subMeshId = -1;\r\n return pickingInfo;\r\n }\r\n\r\n // at least 1 submesh supports intersection, keep going\r\n for (let index = 0; index < len; index++) {\r\n const subMesh = subMeshes.data[index];\r\n\r\n // Bounding test\r\n if (len > 1 && !subMesh.canIntersects(ray)) {\r\n continue;\r\n }\r\n\r\n const currentIntersectInfo = subMesh.intersects(ray, this._positions, this.getIndices(), fastCheck, trianglePredicate);\r\n\r\n if (currentIntersectInfo) {\r\n if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {\r\n intersectInfo = currentIntersectInfo;\r\n intersectInfo.subMeshId = index;\r\n\r\n if (fastCheck) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (intersectInfo) {\r\n // Get picked point\r\n const world = worldToUse ?? this.getWorldMatrix();\r\n const worldOrigin = TmpVectors.Vector3[0];\r\n const direction = TmpVectors.Vector3[1];\r\n Vector3.TransformCoordinatesToRef(ray.origin, world, worldOrigin);\r\n ray.direction.scaleToRef(intersectInfo.distance, direction);\r\n const worldDirection = Vector3.TransformNormal(direction, world);\r\n const pickedPoint = worldDirection.addInPlace(worldOrigin);\r\n\r\n // Return result\r\n pickingInfo.hit = true;\r\n pickingInfo.distance = Vector3.Distance(worldOrigin, pickedPoint);\r\n pickingInfo.pickedPoint = pickedPoint;\r\n pickingInfo.pickedMesh = this;\r\n pickingInfo.bu = intersectInfo.bu || 0;\r\n pickingInfo.bv = intersectInfo.bv || 0;\r\n pickingInfo.subMeshFaceId = intersectInfo.faceId;\r\n pickingInfo.faceId = intersectInfo.faceId + subMeshes.data[intersectInfo.subMeshId].indexStart / (this.getClassName().indexOf(\"LinesMesh\") !== -1 ? 2 : 3);\r\n pickingInfo.subMeshId = intersectInfo.subMeshId;\r\n return pickingInfo;\r\n }\r\n\r\n return pickingInfo;\r\n }\r\n\r\n /**\r\n * Clones the current mesh\r\n * @param name defines the mesh name\r\n * @param newParent defines the new mesh parent\r\n * @param doNotCloneChildren defines a boolean indicating that children must not be cloned (false by default)\r\n * @returns the new mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public clone(name: string, newParent: Nullable, doNotCloneChildren?: boolean): Nullable {\r\n return null;\r\n }\r\n\r\n /**\r\n * Disposes all the submeshes of the current meshnp\r\n * @returns the current mesh\r\n */\r\n public releaseSubMeshes(): AbstractMesh {\r\n if (this.subMeshes) {\r\n while (this.subMeshes.length) {\r\n this.subMeshes[0].dispose();\r\n }\r\n } else {\r\n this.subMeshes = new Array();\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Releases resources associated with this abstract mesh.\r\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\r\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n let index: number;\r\n\r\n // mesh map release.\r\n if (this._scene.useMaterialMeshMap) {\r\n // remove from material mesh map id needed\r\n if (this._internalAbstractMeshDataInfo._material && this._internalAbstractMeshDataInfo._material.meshMap) {\r\n this._internalAbstractMeshDataInfo._material.meshMap[this.uniqueId] = undefined;\r\n }\r\n }\r\n\r\n // Smart Array Retainers.\r\n this.getScene().freeActiveMeshes();\r\n this.getScene().freeRenderingGroups();\r\n\r\n // Action manager\r\n if (this.actionManager !== undefined && this.actionManager !== null) {\r\n this.actionManager.dispose();\r\n this.actionManager = null;\r\n }\r\n\r\n // Skeleton\r\n this._internalAbstractMeshDataInfo._skeleton = null;\r\n\r\n if (this._transformMatrixTexture) {\r\n this._transformMatrixTexture.dispose();\r\n this._transformMatrixTexture = null;\r\n }\r\n\r\n // Intersections in progress\r\n for (index = 0; index < this._intersectionsInProgress.length; index++) {\r\n const other = this._intersectionsInProgress[index];\r\n\r\n const pos = other._intersectionsInProgress.indexOf(this);\r\n other._intersectionsInProgress.splice(pos, 1);\r\n }\r\n\r\n this._intersectionsInProgress.length = 0;\r\n\r\n // Lights\r\n const lights = this.getScene().lights;\r\n\r\n lights.forEach((light: Light) => {\r\n let meshIndex = light.includedOnlyMeshes.indexOf(this);\r\n\r\n if (meshIndex !== -1) {\r\n light.includedOnlyMeshes.splice(meshIndex, 1);\r\n }\r\n\r\n meshIndex = light.excludedMeshes.indexOf(this);\r\n\r\n if (meshIndex !== -1) {\r\n light.excludedMeshes.splice(meshIndex, 1);\r\n }\r\n\r\n // Shadow generators\r\n const generators = light.getShadowGenerators();\r\n if (generators) {\r\n const iterator = generators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const generator = key.value;\r\n const shadowMap = generator.getShadowMap();\r\n\r\n if (shadowMap && shadowMap.renderList) {\r\n meshIndex = shadowMap.renderList.indexOf(this);\r\n\r\n if (meshIndex !== -1) {\r\n shadowMap.renderList.splice(meshIndex, 1);\r\n }\r\n }\r\n }\r\n }\r\n });\r\n\r\n // SubMeshes\r\n if (this.getClassName() !== \"InstancedMesh\" || this.getClassName() !== \"InstancedLinesMesh\") {\r\n this.releaseSubMeshes();\r\n }\r\n\r\n // Query\r\n const engine = this.getScene().getEngine();\r\n if (this._occlusionQuery !== null) {\r\n this.isOcclusionQueryInProgress = false;\r\n engine.deleteQuery(this._occlusionQuery);\r\n this._occlusionQuery = null;\r\n }\r\n\r\n // Engine\r\n engine.wipeCaches();\r\n\r\n // Remove from scene\r\n this.getScene().removeMesh(this);\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.meshes.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.meshes.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n if (disposeMaterialAndTextures) {\r\n if (this.material) {\r\n if (this.material.getClassName() === \"MultiMaterial\") {\r\n this.material.dispose(false, true, true);\r\n } else {\r\n this.material.dispose(false, true);\r\n }\r\n }\r\n }\r\n\r\n if (!doNotRecurse) {\r\n // Particles\r\n for (index = 0; index < this.getScene().particleSystems.length; index++) {\r\n if (this.getScene().particleSystems[index].emitter === this) {\r\n this.getScene().particleSystems[index].dispose();\r\n index--;\r\n }\r\n }\r\n }\r\n\r\n // facet data\r\n if (this._internalAbstractMeshDataInfo._facetData.facetDataEnabled) {\r\n this.disableFacetData();\r\n }\r\n\r\n this._uniformBuffer.dispose();\r\n\r\n this.onAfterWorldMatrixUpdateObservable.clear();\r\n this.onCollideObservable.clear();\r\n this.onCollisionPositionChangeObservable.clear();\r\n this.onRebuildObservable.clear();\r\n\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n\r\n /**\r\n * Adds the passed mesh as a child to the current mesh\r\n * @param mesh defines the child mesh\r\n * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.\r\n * @returns the current mesh\r\n */\r\n public addChild(mesh: AbstractMesh, preserveScalingSign: boolean = false): AbstractMesh {\r\n mesh.setParent(this, preserveScalingSign);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes the passed mesh from the current mesh children list\r\n * @param mesh defines the child mesh\r\n * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change.\r\n * @returns the current mesh\r\n */\r\n public removeChild(mesh: AbstractMesh, preserveScalingSign: boolean = false): AbstractMesh {\r\n mesh.setParent(null, preserveScalingSign);\r\n return this;\r\n }\r\n\r\n // Facet data\r\n /** @internal */\r\n private _initFacetData(): AbstractMesh {\r\n const data = this._internalAbstractMeshDataInfo._facetData;\r\n if (!data.facetNormals) {\r\n data.facetNormals = new Array();\r\n }\r\n if (!data.facetPositions) {\r\n data.facetPositions = new Array();\r\n }\r\n if (!data.facetPartitioning) {\r\n data.facetPartitioning = new Array();\r\n }\r\n data.facetNb = ((this.getIndices()).length / 3) | 0;\r\n data.partitioningSubdivisions = data.partitioningSubdivisions ? data.partitioningSubdivisions : 10; // default nb of partitioning subdivisions = 10\r\n data.partitioningBBoxRatio = data.partitioningBBoxRatio ? data.partitioningBBoxRatio : 1.01; // default ratio 1.01 = the partitioning is 1% bigger than the bounding box\r\n for (let f = 0; f < data.facetNb; f++) {\r\n data.facetNormals[f] = Vector3.Zero();\r\n data.facetPositions[f] = Vector3.Zero();\r\n }\r\n data.facetDataEnabled = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the mesh facetData arrays and the internal partitioning when the mesh is morphed or updated.\r\n * This method can be called within the render loop.\r\n * You don't need to call this method by yourself in the render loop when you update/morph a mesh with the methods CreateXXX() as they automatically manage this computation\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public updateFacetData(): AbstractMesh {\r\n const data = this._internalAbstractMeshDataInfo._facetData;\r\n if (!data.facetDataEnabled) {\r\n this._initFacetData();\r\n }\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const indices = this.getIndices();\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const bInfo = this.getBoundingInfo();\r\n\r\n if (data.facetDepthSort && !data.facetDepthSortEnabled) {\r\n // init arrays, matrix and sort function on first call\r\n data.facetDepthSortEnabled = true;\r\n if (indices instanceof Uint16Array) {\r\n data.depthSortedIndices = new Uint16Array(indices!);\r\n } else if (indices instanceof Uint32Array) {\r\n data.depthSortedIndices = new Uint32Array(indices!);\r\n } else {\r\n let needs32bits = false;\r\n for (let i = 0; i < indices!.length; i++) {\r\n if (indices![i] > 65535) {\r\n needs32bits = true;\r\n break;\r\n }\r\n }\r\n if (needs32bits) {\r\n data.depthSortedIndices = new Uint32Array(indices!);\r\n } else {\r\n data.depthSortedIndices = new Uint16Array(indices!);\r\n }\r\n }\r\n data.facetDepthSortFunction = function (f1, f2) {\r\n return f2.sqDistance - f1.sqDistance;\r\n };\r\n if (!data.facetDepthSortFrom) {\r\n const camera = this.getScene().activeCamera;\r\n data.facetDepthSortFrom = camera ? camera.position : Vector3.Zero();\r\n }\r\n data.depthSortedFacets = [];\r\n for (let f = 0; f < data.facetNb; f++) {\r\n const depthSortedFacet = { ind: f * 3, sqDistance: 0.0 };\r\n data.depthSortedFacets.push(depthSortedFacet);\r\n }\r\n data.invertedMatrix = Matrix.Identity();\r\n data.facetDepthSortOrigin = Vector3.Zero();\r\n }\r\n\r\n data.bbSize.x = bInfo.maximum.x - bInfo.minimum.x > Epsilon ? bInfo.maximum.x - bInfo.minimum.x : Epsilon;\r\n data.bbSize.y = bInfo.maximum.y - bInfo.minimum.y > Epsilon ? bInfo.maximum.y - bInfo.minimum.y : Epsilon;\r\n data.bbSize.z = bInfo.maximum.z - bInfo.minimum.z > Epsilon ? bInfo.maximum.z - bInfo.minimum.z : Epsilon;\r\n let bbSizeMax = data.bbSize.x > data.bbSize.y ? data.bbSize.x : data.bbSize.y;\r\n bbSizeMax = bbSizeMax > data.bbSize.z ? bbSizeMax : data.bbSize.z;\r\n data.subDiv.max = data.partitioningSubdivisions;\r\n data.subDiv.X = Math.floor((data.subDiv.max * data.bbSize.x) / bbSizeMax); // adjust the number of subdivisions per axis\r\n data.subDiv.Y = Math.floor((data.subDiv.max * data.bbSize.y) / bbSizeMax); // according to each bbox size per axis\r\n data.subDiv.Z = Math.floor((data.subDiv.max * data.bbSize.z) / bbSizeMax);\r\n data.subDiv.X = data.subDiv.X < 1 ? 1 : data.subDiv.X; // at least one subdivision\r\n data.subDiv.Y = data.subDiv.Y < 1 ? 1 : data.subDiv.Y;\r\n data.subDiv.Z = data.subDiv.Z < 1 ? 1 : data.subDiv.Z;\r\n // set the parameters for ComputeNormals()\r\n data.facetParameters.facetNormals = this.getFacetLocalNormals();\r\n data.facetParameters.facetPositions = this.getFacetLocalPositions();\r\n data.facetParameters.facetPartitioning = this.getFacetLocalPartitioning();\r\n data.facetParameters.bInfo = bInfo;\r\n data.facetParameters.bbSize = data.bbSize;\r\n data.facetParameters.subDiv = data.subDiv;\r\n data.facetParameters.ratio = this.partitioningBBoxRatio;\r\n data.facetParameters.depthSort = data.facetDepthSort;\r\n if (data.facetDepthSort && data.facetDepthSortEnabled) {\r\n this.computeWorldMatrix(true);\r\n this._worldMatrix.invertToRef(data.invertedMatrix);\r\n Vector3.TransformCoordinatesToRef(data.facetDepthSortFrom, data.invertedMatrix, data.facetDepthSortOrigin);\r\n data.facetParameters.distanceTo = data.facetDepthSortOrigin;\r\n }\r\n data.facetParameters.depthSortedFacets = data.depthSortedFacets;\r\n if (normals) {\r\n VertexData.ComputeNormals(positions, indices, normals, data.facetParameters);\r\n }\r\n\r\n if (data.facetDepthSort && data.facetDepthSortEnabled) {\r\n data.depthSortedFacets.sort(data.facetDepthSortFunction);\r\n const l = (data.depthSortedIndices.length / 3) | 0;\r\n for (let f = 0; f < l; f++) {\r\n const sind = data.depthSortedFacets[f].ind;\r\n data.depthSortedIndices[f * 3] = indices![sind];\r\n data.depthSortedIndices[f * 3 + 1] = indices![sind + 1];\r\n data.depthSortedIndices[f * 3 + 2] = indices![sind + 2];\r\n }\r\n this.updateIndices(data.depthSortedIndices, undefined, true);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the facetLocalNormals array.\r\n * The normals are expressed in the mesh local spac\r\n * @returns an array of Vector3\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetLocalNormals(): Vector3[] {\r\n const facetData = this._internalAbstractMeshDataInfo._facetData;\r\n if (!facetData.facetNormals) {\r\n this.updateFacetData();\r\n }\r\n return facetData.facetNormals;\r\n }\r\n\r\n /**\r\n * Returns the facetLocalPositions array.\r\n * The facet positions are expressed in the mesh local space\r\n * @returns an array of Vector3\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetLocalPositions(): Vector3[] {\r\n const facetData = this._internalAbstractMeshDataInfo._facetData;\r\n if (!facetData.facetPositions) {\r\n this.updateFacetData();\r\n }\r\n return facetData.facetPositions;\r\n }\r\n\r\n /**\r\n * Returns the facetLocalPartitioning array\r\n * @returns an array of array of numbers\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetLocalPartitioning(): number[][] {\r\n const facetData = this._internalAbstractMeshDataInfo._facetData;\r\n\r\n if (!facetData.facetPartitioning) {\r\n this.updateFacetData();\r\n }\r\n return facetData.facetPartitioning;\r\n }\r\n\r\n /**\r\n * Returns the i-th facet position in the world system.\r\n * This method allocates a new Vector3 per call\r\n * @param i defines the facet index\r\n * @returns a new Vector3\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetPosition(i: number): Vector3 {\r\n const pos = Vector3.Zero();\r\n this.getFacetPositionToRef(i, pos);\r\n return pos;\r\n }\r\n\r\n /**\r\n * Sets the reference Vector3 with the i-th facet position in the world system\r\n * @param i defines the facet index\r\n * @param ref defines the target vector\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetPositionToRef(i: number, ref: Vector3): AbstractMesh {\r\n const localPos = this.getFacetLocalPositions()[i];\r\n const world = this.getWorldMatrix();\r\n Vector3.TransformCoordinatesToRef(localPos, world, ref);\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the i-th facet normal in the world system.\r\n * This method allocates a new Vector3 per call\r\n * @param i defines the facet index\r\n * @returns a new Vector3\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetNormal(i: number): Vector3 {\r\n const norm = Vector3.Zero();\r\n this.getFacetNormalToRef(i, norm);\r\n return norm;\r\n }\r\n\r\n /**\r\n * Sets the reference Vector3 with the i-th facet normal in the world system\r\n * @param i defines the facet index\r\n * @param ref defines the target vector\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetNormalToRef(i: number, ref: Vector3) {\r\n const localNorm = this.getFacetLocalNormals()[i];\r\n Vector3.TransformNormalToRef(localNorm, this.getWorldMatrix(), ref);\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the facets (in an array) in the same partitioning block than the one the passed coordinates are located (expressed in the mesh local system)\r\n * @param x defines x coordinate\r\n * @param y defines y coordinate\r\n * @param z defines z coordinate\r\n * @returns the array of facet indexes\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetsAtLocalCoordinates(x: number, y: number, z: number): Nullable {\r\n const bInfo = this.getBoundingInfo();\r\n const data = this._internalAbstractMeshDataInfo._facetData;\r\n\r\n const ox = Math.floor(((x - bInfo.minimum.x * data.partitioningBBoxRatio) * data.subDiv.X * data.partitioningBBoxRatio) / data.bbSize.x);\r\n const oy = Math.floor(((y - bInfo.minimum.y * data.partitioningBBoxRatio) * data.subDiv.Y * data.partitioningBBoxRatio) / data.bbSize.y);\r\n const oz = Math.floor(((z - bInfo.minimum.z * data.partitioningBBoxRatio) * data.subDiv.Z * data.partitioningBBoxRatio) / data.bbSize.z);\r\n if (ox < 0 || ox > data.subDiv.max || oy < 0 || oy > data.subDiv.max || oz < 0 || oz > data.subDiv.max) {\r\n return null;\r\n }\r\n return data.facetPartitioning[ox + data.subDiv.max * oy + data.subDiv.max * data.subDiv.max * oz];\r\n }\r\n\r\n /**\r\n * Returns the closest mesh facet index at (x,y,z) World coordinates, null if not found\r\n * @param x defines x coordinate\r\n * @param y defines y coordinate\r\n * @param z defines z coordinate\r\n * @param projected sets as the (x,y,z) world projection on the facet\r\n * @param checkFace if true (default false), only the facet \"facing\" to (x,y,z) or only the ones \"turning their backs\", according to the parameter \"facing\" are returned\r\n * @param facing if facing and checkFace are true, only the facet \"facing\" to (x, y, z) are returned : positive dot (x, y, z) * facet position. If facing si false and checkFace is true, only the facet \"turning their backs\" to (x, y, z) are returned : negative dot (x, y, z) * facet position\r\n * @returns the face index if found (or null instead)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getClosestFacetAtCoordinates(x: number, y: number, z: number, projected?: Vector3, checkFace: boolean = false, facing: boolean = true): Nullable {\r\n const world = this.getWorldMatrix();\r\n const invMat = TmpVectors.Matrix[5];\r\n world.invertToRef(invMat);\r\n const invVect = TmpVectors.Vector3[8];\r\n Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, invMat, invVect); // transform (x,y,z) to coordinates in the mesh local space\r\n const closest = this.getClosestFacetAtLocalCoordinates(invVect.x, invVect.y, invVect.z, projected, checkFace, facing);\r\n if (projected) {\r\n // transform the local computed projected vector to world coordinates\r\n Vector3.TransformCoordinatesFromFloatsToRef(projected.x, projected.y, projected.z, world, projected);\r\n }\r\n return closest;\r\n }\r\n\r\n /**\r\n * Returns the closest mesh facet index at (x,y,z) local coordinates, null if not found\r\n * @param x defines x coordinate\r\n * @param y defines y coordinate\r\n * @param z defines z coordinate\r\n * @param projected sets as the (x,y,z) local projection on the facet\r\n * @param checkFace if true (default false), only the facet \"facing\" to (x,y,z) or only the ones \"turning their backs\", according to the parameter \"facing\" are returned\r\n * @param facing if facing and checkFace are true, only the facet \"facing\" to (x, y, z) are returned : positive dot (x, y, z) * facet position. If facing si false and checkFace is true, only the facet \"turning their backs\" to (x, y, z) are returned : negative dot (x, y, z) * facet position\r\n * @returns the face index if found (or null instead)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getClosestFacetAtLocalCoordinates(x: number, y: number, z: number, projected?: Vector3, checkFace: boolean = false, facing: boolean = true): Nullable {\r\n let closest = null;\r\n let tmpx = 0.0;\r\n let tmpy = 0.0;\r\n let tmpz = 0.0;\r\n let d = 0.0; // tmp dot facet normal * facet position\r\n let t0 = 0.0;\r\n let projx = 0.0;\r\n let projy = 0.0;\r\n let projz = 0.0;\r\n // Get all the facets in the same partitioning block than (x, y, z)\r\n const facetPositions = this.getFacetLocalPositions();\r\n const facetNormals = this.getFacetLocalNormals();\r\n const facetsInBlock = this.getFacetsAtLocalCoordinates(x, y, z);\r\n if (!facetsInBlock) {\r\n return null;\r\n }\r\n // Get the closest facet to (x, y, z)\r\n let shortest = Number.MAX_VALUE; // init distance vars\r\n let tmpDistance = shortest;\r\n let fib; // current facet in the block\r\n let norm; // current facet normal\r\n let p0; // current facet barycenter position\r\n // loop on all the facets in the current partitioning block\r\n for (let idx = 0; idx < facetsInBlock.length; idx++) {\r\n fib = facetsInBlock[idx];\r\n norm = facetNormals[fib];\r\n p0 = facetPositions[fib];\r\n\r\n d = (x - p0.x) * norm.x + (y - p0.y) * norm.y + (z - p0.z) * norm.z;\r\n if (!checkFace || (checkFace && facing && d >= 0.0) || (checkFace && !facing && d <= 0.0)) {\r\n // compute (x,y,z) projection on the facet = (projx, projy, projz)\r\n d = norm.x * p0.x + norm.y * p0.y + norm.z * p0.z;\r\n t0 = -(norm.x * x + norm.y * y + norm.z * z - d) / (norm.x * norm.x + norm.y * norm.y + norm.z * norm.z);\r\n projx = x + norm.x * t0;\r\n projy = y + norm.y * t0;\r\n projz = z + norm.z * t0;\r\n\r\n tmpx = projx - x;\r\n tmpy = projy - y;\r\n tmpz = projz - z;\r\n tmpDistance = tmpx * tmpx + tmpy * tmpy + tmpz * tmpz; // compute length between (x, y, z) and its projection on the facet\r\n if (tmpDistance < shortest) {\r\n // just keep the closest facet to (x, y, z)\r\n shortest = tmpDistance;\r\n closest = fib;\r\n if (projected) {\r\n projected.x = projx;\r\n projected.y = projy;\r\n projected.z = projz;\r\n }\r\n }\r\n }\r\n }\r\n return closest;\r\n }\r\n\r\n /**\r\n * Returns the object \"parameter\" set with all the expected parameters for facetData computation by ComputeNormals()\r\n * @returns the parameters\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public getFacetDataParameters(): any {\r\n return this._internalAbstractMeshDataInfo._facetData.facetParameters;\r\n }\r\n\r\n /**\r\n * Disables the feature FacetData and frees the related memory\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData\r\n */\r\n public disableFacetData(): AbstractMesh {\r\n const facetData = this._internalAbstractMeshDataInfo._facetData;\r\n if (facetData.facetDataEnabled) {\r\n facetData.facetDataEnabled = false;\r\n facetData.facetPositions = new Array();\r\n facetData.facetNormals = new Array();\r\n facetData.facetPartitioning = new Array();\r\n facetData.facetParameters = null;\r\n facetData.depthSortedIndices = new Uint32Array(0);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Updates the AbstractMesh indices array\r\n * @param indices defines the data source\r\n * @param offset defines the offset in the index buffer where to store the new data (can be null)\r\n * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)\r\n * @returns the current mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public updateIndices(indices: IndicesArray, offset?: number, gpuMemoryOnly = false): AbstractMesh {\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates new normals data for the mesh\r\n * @param updatable defines if the normal vertex buffer must be flagged as updatable\r\n * @returns the current mesh\r\n */\r\n public createNormals(updatable: boolean): AbstractMesh {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const indices = this.getIndices();\r\n let normals: FloatArray;\r\n\r\n if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n } else {\r\n normals = [];\r\n }\r\n\r\n VertexData.ComputeNormals(positions, indices, normals, { useRightHandedSystem: this.getScene().useRightHandedSystem });\r\n this.setVerticesData(VertexBuffer.NormalKind, normals, updatable);\r\n return this;\r\n }\r\n\r\n /**\r\n * Align the mesh with a normal\r\n * @param normal defines the normal to use\r\n * @param upDirection can be used to redefined the up vector to use (will use the (0, 1, 0) by default)\r\n * @returns the current mesh\r\n */\r\n public alignWithNormal(normal: Vector3, upDirection?: Vector3): AbstractMesh {\r\n if (!upDirection) {\r\n upDirection = Axis.Y;\r\n }\r\n\r\n const axisX = TmpVectors.Vector3[0];\r\n const axisZ = TmpVectors.Vector3[1];\r\n Vector3.CrossToRef(upDirection, normal, axisZ);\r\n Vector3.CrossToRef(normal, axisZ, axisX);\r\n\r\n if (this.rotationQuaternion) {\r\n Quaternion.RotationQuaternionFromAxisToRef(axisX, normal, axisZ, this.rotationQuaternion);\r\n } else {\r\n Vector3.RotationFromAxisToRef(axisX, normal, axisZ, this.rotation);\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n public _checkOcclusionQuery(): boolean {\r\n // Will be replaced by correct code if Occlusion queries are referenced\r\n return false;\r\n }\r\n\r\n /**\r\n * Disables the mesh edge rendering mode\r\n * @returns the currentAbstractMesh\r\n */\r\n disableEdgesRendering(): AbstractMesh {\r\n throw _WarnImport(\"EdgesRenderer\");\r\n }\r\n\r\n /**\r\n * Enables the edge rendering mode on the mesh.\r\n * This mode makes the mesh edges visible\r\n * @param epsilon defines the maximal distance between two angles to detect a face\r\n * @param checkVerticesInsteadOfIndices indicates that we should check vertex list directly instead of faces\r\n * @param options options to the edge renderer\r\n * @returns the currentAbstractMesh\r\n * @see https://www.babylonjs-playground.com/#19O9TU#0\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n enableEdgesRendering(epsilon?: number, checkVerticesInsteadOfIndices?: boolean, options?: IEdgesRendererOptions): AbstractMesh {\r\n throw _WarnImport(\"EdgesRenderer\");\r\n }\r\n\r\n /**\r\n * This function returns all of the particle systems in the scene that use the mesh as an emitter.\r\n * @returns an array of particle systems in the scene that use the mesh as an emitter\r\n */\r\n public getConnectedParticleSystems(): IParticleSystem[] {\r\n return this._scene.particleSystems.filter((particleSystem) => particleSystem.emitter === this);\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.AbstractMesh\", AbstractMesh);\r\n","import type { Effect } from \"./effect\";\r\nimport type { IClipPlanesHolder } from \"../Misc/interfaces/iClipPlanesHolder\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\n/** @internal */\r\nexport function addClipPlaneUniforms(uniforms: string[]): void {\r\n if (uniforms.indexOf(\"vClipPlane\") === -1) {\r\n uniforms.push(\"vClipPlane\");\r\n }\r\n if (uniforms.indexOf(\"vClipPlane2\") === -1) {\r\n uniforms.push(\"vClipPlane2\");\r\n }\r\n if (uniforms.indexOf(\"vClipPlane3\") === -1) {\r\n uniforms.push(\"vClipPlane3\");\r\n }\r\n if (uniforms.indexOf(\"vClipPlane4\") === -1) {\r\n uniforms.push(\"vClipPlane4\");\r\n }\r\n if (uniforms.indexOf(\"vClipPlane5\") === -1) {\r\n uniforms.push(\"vClipPlane5\");\r\n }\r\n if (uniforms.indexOf(\"vClipPlane6\") === -1) {\r\n uniforms.push(\"vClipPlane6\");\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function prepareStringDefinesForClipPlanes(primaryHolder: IClipPlanesHolder, secondaryHolder: IClipPlanesHolder, defines: string[]): void {\r\n const clipPlane = !!(primaryHolder.clipPlane ?? secondaryHolder.clipPlane);\r\n const clipPlane2 = !!(primaryHolder.clipPlane2 ?? secondaryHolder.clipPlane2);\r\n const clipPlane3 = !!(primaryHolder.clipPlane3 ?? secondaryHolder.clipPlane3);\r\n const clipPlane4 = !!(primaryHolder.clipPlane4 ?? secondaryHolder.clipPlane4);\r\n const clipPlane5 = !!(primaryHolder.clipPlane5 ?? secondaryHolder.clipPlane5);\r\n const clipPlane6 = !!(primaryHolder.clipPlane6 ?? secondaryHolder.clipPlane6);\r\n\r\n if (clipPlane) defines.push(\"#define CLIPPLANE\");\r\n if (clipPlane2) defines.push(\"#define CLIPPLANE2\");\r\n if (clipPlane3) defines.push(\"#define CLIPPLANE3\");\r\n if (clipPlane4) defines.push(\"#define CLIPPLANE4\");\r\n if (clipPlane5) defines.push(\"#define CLIPPLANE5\");\r\n if (clipPlane6) defines.push(\"#define CLIPPLANE6\");\r\n}\r\n\r\n/** @internal */\r\nexport function prepareDefinesForClipPlanes(primaryHolder: IClipPlanesHolder, secondaryHolder: IClipPlanesHolder, defines: Record): boolean {\r\n let changed = false;\r\n\r\n const clipPlane = !!(primaryHolder.clipPlane ?? secondaryHolder.clipPlane);\r\n const clipPlane2 = !!(primaryHolder.clipPlane2 ?? secondaryHolder.clipPlane2);\r\n const clipPlane3 = !!(primaryHolder.clipPlane3 ?? secondaryHolder.clipPlane3);\r\n const clipPlane4 = !!(primaryHolder.clipPlane4 ?? secondaryHolder.clipPlane4);\r\n const clipPlane5 = !!(primaryHolder.clipPlane5 ?? secondaryHolder.clipPlane5);\r\n const clipPlane6 = !!(primaryHolder.clipPlane6 ?? secondaryHolder.clipPlane6);\r\n\r\n // Do not factorize this code, it breaks browsers optimizations.\r\n if (defines[\"CLIPPLANE\"] !== clipPlane) {\r\n defines[\"CLIPPLANE\"] = clipPlane;\r\n changed = true;\r\n }\r\n if (defines[\"CLIPPLANE2\"] !== clipPlane2) {\r\n defines[\"CLIPPLANE2\"] = clipPlane2;\r\n changed = true;\r\n }\r\n if (defines[\"CLIPPLANE3\"] !== clipPlane3) {\r\n defines[\"CLIPPLANE3\"] = clipPlane3;\r\n changed = true;\r\n }\r\n if (defines[\"CLIPPLANE4\"] !== clipPlane4) {\r\n defines[\"CLIPPLANE4\"] = clipPlane4;\r\n changed = true;\r\n }\r\n if (defines[\"CLIPPLANE5\"] !== clipPlane5) {\r\n defines[\"CLIPPLANE5\"] = clipPlane5;\r\n changed = true;\r\n }\r\n if (defines[\"CLIPPLANE6\"] !== clipPlane6) {\r\n defines[\"CLIPPLANE6\"] = clipPlane6;\r\n changed = true;\r\n }\r\n\r\n return changed;\r\n}\r\n\r\n/** @internal */\r\nexport function bindClipPlane(effect: Effect, primaryHolder: IClipPlanesHolder, secondaryHolder: IClipPlanesHolder): void {\r\n let clipPlane = primaryHolder.clipPlane ?? secondaryHolder.clipPlane;\r\n setClipPlane(effect, \"vClipPlane\", clipPlane);\r\n clipPlane = primaryHolder.clipPlane2 ?? secondaryHolder.clipPlane2;\r\n setClipPlane(effect, \"vClipPlane2\", clipPlane);\r\n clipPlane = primaryHolder.clipPlane3 ?? secondaryHolder.clipPlane3;\r\n setClipPlane(effect, \"vClipPlane3\", clipPlane);\r\n clipPlane = primaryHolder.clipPlane4 ?? secondaryHolder.clipPlane4;\r\n setClipPlane(effect, \"vClipPlane4\", clipPlane);\r\n clipPlane = primaryHolder.clipPlane5 ?? secondaryHolder.clipPlane5;\r\n setClipPlane(effect, \"vClipPlane5\", clipPlane);\r\n clipPlane = primaryHolder.clipPlane6 ?? secondaryHolder.clipPlane6;\r\n setClipPlane(effect, \"vClipPlane6\", clipPlane);\r\n}\r\n\r\nfunction setClipPlane(effect: Effect, uniformName: string, clipPlane: Nullable): void {\r\n if (clipPlane) {\r\n effect.setFloat4(uniformName, clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);\r\n }\r\n}\r\n","import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { LightConstants } from \"../Lights/lightConstants\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { PrePassConfiguration } from \"../Materials/prePassConfiguration\";\r\n\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { Effect, IEffectCreationOptions } from \"./effect\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport { prepareDefinesForClipPlanes } from \"./clipPlaneMaterialHelper\";\r\nimport type { Material } from \"./material\";\r\n\r\n/**\r\n * \"Static Class\" containing the most commonly used helper while dealing with material for rendering purpose.\r\n *\r\n * It contains the basic tools to help defining defines, binding uniform for the common part of the materials.\r\n *\r\n * This works by convention in BabylonJS but is meant to be use only with shader following the in place naming rules and conventions.\r\n */\r\nexport class MaterialHelper {\r\n /**\r\n * Binds the scene's uniform buffer to the effect.\r\n * @param effect defines the effect to bind to the scene uniform buffer\r\n * @param sceneUbo defines the uniform buffer storing scene data\r\n */\r\n public static BindSceneUniformBuffer(effect: Effect, sceneUbo: UniformBuffer): void {\r\n sceneUbo.bindToEffect(effect, \"Scene\");\r\n }\r\n\r\n /**\r\n * Helps preparing the defines values about the UVs in used in the effect.\r\n * UVs are shared as much as we can across channels in the shaders.\r\n * @param texture The texture we are preparing the UVs for\r\n * @param defines The defines to update\r\n * @param key The channel key \"diffuse\", \"specular\"... used in the shader\r\n */\r\n public static PrepareDefinesForMergedUV(texture: BaseTexture, defines: any, key: string): void {\r\n defines._needUVs = true;\r\n defines[key] = true;\r\n if (texture.optimizeUVAllocation && texture.getTextureMatrix().isIdentityAs3x2()) {\r\n defines[key + \"DIRECTUV\"] = texture.coordinatesIndex + 1;\r\n defines[\"MAINUV\" + (texture.coordinatesIndex + 1)] = true;\r\n } else {\r\n defines[key + \"DIRECTUV\"] = 0;\r\n }\r\n }\r\n\r\n /**\r\n * Binds a texture matrix value to its corresponding uniform\r\n * @param texture The texture to bind the matrix for\r\n * @param uniformBuffer The uniform buffer receiving the data\r\n * @param key The channel key \"diffuse\", \"specular\"... used in the shader\r\n */\r\n public static BindTextureMatrix(texture: BaseTexture, uniformBuffer: UniformBuffer, key: string): void {\r\n const matrix = texture.getTextureMatrix();\r\n\r\n uniformBuffer.updateMatrix(key + \"Matrix\", matrix);\r\n }\r\n\r\n /**\r\n * Gets the current status of the fog (should it be enabled?)\r\n * @param mesh defines the mesh to evaluate for fog support\r\n * @param scene defines the hosting scene\r\n * @returns true if fog must be enabled\r\n */\r\n public static GetFogState(mesh: AbstractMesh, scene: Scene) {\r\n return scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE;\r\n }\r\n\r\n /**\r\n * Helper used to prepare the list of defines associated with misc. values for shader compilation\r\n * @param mesh defines the current mesh\r\n * @param scene defines the current scene\r\n * @param useLogarithmicDepth defines if logarithmic depth has to be turned on\r\n * @param pointsCloud defines if point cloud rendering has to be turned on\r\n * @param fogEnabled defines if fog has to be turned on\r\n * @param alphaTest defines if alpha testing has to be turned on\r\n * @param defines defines the current list of defines\r\n * @param applyDecalAfterDetail Defines if the decal is applied after or before the detail\r\n */\r\n public static PrepareDefinesForMisc(\r\n mesh: AbstractMesh,\r\n scene: Scene,\r\n useLogarithmicDepth: boolean,\r\n pointsCloud: boolean,\r\n fogEnabled: boolean,\r\n alphaTest: boolean,\r\n defines: any,\r\n applyDecalAfterDetail: boolean = false\r\n ): void {\r\n if (defines._areMiscDirty) {\r\n defines[\"LOGARITHMICDEPTH\"] = useLogarithmicDepth;\r\n defines[\"POINTSIZE\"] = pointsCloud;\r\n defines[\"FOG\"] = fogEnabled && this.GetFogState(mesh, scene);\r\n defines[\"NONUNIFORMSCALING\"] = mesh.nonUniformScaling;\r\n defines[\"ALPHATEST\"] = alphaTest;\r\n defines[\"DECAL_AFTER_DETAIL\"] = applyDecalAfterDetail;\r\n }\r\n }\r\n\r\n /**\r\n * Helper used to prepare the defines relative to the active camera\r\n * @param scene defines the current scene\r\n * @param defines specifies the list of active defines\r\n * @returns true if the defines have been updated, else false\r\n */\r\n public static PrepareDefinesForCamera(scene: Scene, defines: any): boolean {\r\n let changed = false;\r\n\r\n if (scene.activeCamera) {\r\n const wasOrtho = defines[\"CAMERA_ORTHOGRAPHIC\"] ? 1 : 0;\r\n const wasPersp = defines[\"CAMERA_PERSPECTIVE\"] ? 1 : 0;\r\n const isOrtho = scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA ? 1 : 0;\r\n const isPersp = scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA ? 1 : 0;\r\n\r\n if (wasOrtho ^ isOrtho || wasPersp ^ isPersp) {\r\n defines[\"CAMERA_ORTHOGRAPHIC\"] = isOrtho === 1;\r\n defines[\"CAMERA_PERSPECTIVE\"] = isPersp === 1;\r\n changed = true;\r\n }\r\n }\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * Helper used to prepare the list of defines associated with frame values for shader compilation\r\n * @param scene defines the current scene\r\n * @param engine defines the current engine\r\n * @param material defines the material we are compiling the shader for\r\n * @param defines specifies the list of active defines\r\n * @param useInstances defines if instances have to be turned on\r\n * @param useClipPlane defines if clip plane have to be turned on\r\n * @param useThinInstances defines if thin instances have to be turned on\r\n */\r\n public static PrepareDefinesForFrameBoundValues(\r\n scene: Scene,\r\n engine: Engine,\r\n material: Material,\r\n defines: any,\r\n useInstances: boolean,\r\n useClipPlane: Nullable = null,\r\n useThinInstances: boolean = false\r\n ): void {\r\n let changed = MaterialHelper.PrepareDefinesForCamera(scene, defines);\r\n\r\n if (useClipPlane !== false) {\r\n changed = prepareDefinesForClipPlanes(material, scene, defines);\r\n }\r\n\r\n if (defines[\"DEPTHPREPASS\"] !== !engine.getColorWrite()) {\r\n defines[\"DEPTHPREPASS\"] = !defines[\"DEPTHPREPASS\"];\r\n changed = true;\r\n }\r\n\r\n if (defines[\"INSTANCES\"] !== useInstances) {\r\n defines[\"INSTANCES\"] = useInstances;\r\n changed = true;\r\n }\r\n\r\n if (defines[\"THIN_INSTANCES\"] !== useThinInstances) {\r\n defines[\"THIN_INSTANCES\"] = useThinInstances;\r\n changed = true;\r\n }\r\n\r\n if (changed) {\r\n defines.markAsUnprocessed();\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines for bones\r\n * @param mesh The mesh containing the geometry data we will draw\r\n * @param defines The defines to update\r\n */\r\n public static PrepareDefinesForBones(mesh: AbstractMesh, defines: any) {\r\n if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\r\n defines[\"NUM_BONE_INFLUENCERS\"] = mesh.numBoneInfluencers;\r\n\r\n const materialSupportsBoneTexture = defines[\"BONETEXTURE\"] !== undefined;\r\n\r\n if (mesh.skeleton.isUsingTextureForMatrices && materialSupportsBoneTexture) {\r\n defines[\"BONETEXTURE\"] = true;\r\n } else {\r\n defines[\"BonesPerMesh\"] = mesh.skeleton.bones.length + 1;\r\n defines[\"BONETEXTURE\"] = materialSupportsBoneTexture ? false : undefined;\r\n\r\n const prePassRenderer = mesh.getScene().prePassRenderer;\r\n if (prePassRenderer && prePassRenderer.enabled) {\r\n const nonExcluded = prePassRenderer.excludedSkinnedMesh.indexOf(mesh) === -1;\r\n defines[\"BONES_VELOCITY_ENABLED\"] = nonExcluded;\r\n }\r\n }\r\n } else {\r\n defines[\"NUM_BONE_INFLUENCERS\"] = 0;\r\n defines[\"BonesPerMesh\"] = 0;\r\n if (defines[\"BONETEXTURE\"] !== undefined) {\r\n defines[\"BONETEXTURE\"] = false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines for morph targets\r\n * @param mesh The mesh containing the geometry data we will draw\r\n * @param defines The defines to update\r\n */\r\n public static PrepareDefinesForMorphTargets(mesh: AbstractMesh, defines: any) {\r\n const manager = (mesh).morphTargetManager;\r\n if (manager) {\r\n defines[\"MORPHTARGETS_UV\"] = manager.supportsUVs && defines[\"UV1\"];\r\n defines[\"MORPHTARGETS_TANGENT\"] = manager.supportsTangents && defines[\"TANGENT\"];\r\n defines[\"MORPHTARGETS_NORMAL\"] = manager.supportsNormals && defines[\"NORMAL\"];\r\n defines[\"MORPHTARGETS\"] = manager.numInfluencers > 0;\r\n defines[\"NUM_MORPH_INFLUENCERS\"] = manager.numInfluencers;\r\n\r\n defines[\"MORPHTARGETS_TEXTURE\"] = manager.isUsingTextureForTargets;\r\n } else {\r\n defines[\"MORPHTARGETS_UV\"] = false;\r\n defines[\"MORPHTARGETS_TANGENT\"] = false;\r\n defines[\"MORPHTARGETS_NORMAL\"] = false;\r\n defines[\"MORPHTARGETS\"] = false;\r\n defines[\"NUM_MORPH_INFLUENCERS\"] = 0;\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines for baked vertex animation\r\n * @param mesh The mesh containing the geometry data we will draw\r\n * @param defines The defines to update\r\n */\r\n public static PrepareDefinesForBakedVertexAnimation(mesh: AbstractMesh, defines: any) {\r\n const manager = (mesh).bakedVertexAnimationManager;\r\n defines[\"BAKED_VERTEX_ANIMATION_TEXTURE\"] = manager && manager.isEnabled ? true : false;\r\n }\r\n\r\n /**\r\n * Prepares the defines used in the shader depending on the attributes data available in the mesh\r\n * @param mesh The mesh containing the geometry data we will draw\r\n * @param defines The defines to update\r\n * @param useVertexColor Precise whether vertex colors should be used or not (override mesh info)\r\n * @param useBones Precise whether bones should be used or not (override mesh info)\r\n * @param useMorphTargets Precise whether morph targets should be used or not (override mesh info)\r\n * @param useVertexAlpha Precise whether vertex alpha should be used or not (override mesh info)\r\n * @param useBakedVertexAnimation Precise whether baked vertex animation should be used or not (override mesh info)\r\n * @returns false if defines are considered not dirty and have not been checked\r\n */\r\n public static PrepareDefinesForAttributes(\r\n mesh: AbstractMesh,\r\n defines: any,\r\n useVertexColor: boolean,\r\n useBones: boolean,\r\n useMorphTargets = false,\r\n useVertexAlpha = true,\r\n useBakedVertexAnimation = true\r\n ): boolean {\r\n if (!defines._areAttributesDirty && defines._needNormals === defines._normals && defines._needUVs === defines._uvs) {\r\n return false;\r\n }\r\n\r\n defines._normals = defines._needNormals;\r\n defines._uvs = defines._needUVs;\r\n\r\n defines[\"NORMAL\"] = defines._needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind);\r\n\r\n if (defines._needNormals && mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {\r\n defines[\"TANGENT\"] = true;\r\n }\r\n\r\n for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {\r\n defines[\"UV\" + i] = defines._needUVs ? mesh.isVerticesDataPresent(`uv${i === 1 ? \"\" : i}`) : false;\r\n }\r\n\r\n if (useVertexColor) {\r\n const hasVertexColors = mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind);\r\n defines[\"VERTEXCOLOR\"] = hasVertexColors;\r\n defines[\"VERTEXALPHA\"] = mesh.hasVertexAlpha && hasVertexColors && useVertexAlpha;\r\n }\r\n\r\n if (mesh.isVerticesDataPresent(VertexBuffer.ColorInstanceKind) && (mesh.hasInstances || mesh.hasThinInstances)) {\r\n defines[\"INSTANCESCOLOR\"] = true;\r\n }\r\n\r\n if (useBones) {\r\n this.PrepareDefinesForBones(mesh, defines);\r\n }\r\n\r\n if (useMorphTargets) {\r\n this.PrepareDefinesForMorphTargets(mesh, defines);\r\n }\r\n\r\n if (useBakedVertexAnimation) {\r\n this.PrepareDefinesForBakedVertexAnimation(mesh, defines);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Prepares the defines related to multiview\r\n * @param scene The scene we are intending to draw\r\n * @param defines The defines to update\r\n */\r\n public static PrepareDefinesForMultiview(scene: Scene, defines: any) {\r\n if (scene.activeCamera) {\r\n const previousMultiview = defines.MULTIVIEW;\r\n defines.MULTIVIEW = scene.activeCamera.outputRenderTarget !== null && scene.activeCamera.outputRenderTarget.getViewCount() > 1;\r\n if (defines.MULTIVIEW != previousMultiview) {\r\n defines.markAsUnprocessed();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines related to order independant transparency\r\n * @param scene The scene we are intending to draw\r\n * @param defines The defines to update\r\n * @param needAlphaBlending Determines if the material needs alpha blending\r\n */\r\n public static PrepareDefinesForOIT(scene: Scene, defines: any, needAlphaBlending: boolean) {\r\n const previousDefine = defines.ORDER_INDEPENDENT_TRANSPARENCY;\r\n const previousDefine16Bits = defines.ORDER_INDEPENDENT_TRANSPARENCY_16BITS;\r\n\r\n defines.ORDER_INDEPENDENT_TRANSPARENCY = scene.useOrderIndependentTransparency && needAlphaBlending;\r\n defines.ORDER_INDEPENDENT_TRANSPARENCY_16BITS = !scene.getEngine().getCaps().textureFloatLinearFiltering;\r\n\r\n if (previousDefine !== defines.ORDER_INDEPENDENT_TRANSPARENCY || previousDefine16Bits !== defines.ORDER_INDEPENDENT_TRANSPARENCY_16BITS) {\r\n defines.markAsUnprocessed();\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines related to the prepass\r\n * @param scene The scene we are intending to draw\r\n * @param defines The defines to update\r\n * @param canRenderToMRT Indicates if this material renders to several textures in the prepass\r\n */\r\n public static PrepareDefinesForPrePass(scene: Scene, defines: any, canRenderToMRT: boolean) {\r\n const previousPrePass = defines.PREPASS;\r\n\r\n if (!defines._arePrePassDirty) {\r\n return;\r\n }\r\n\r\n const texturesList = [\r\n {\r\n type: Constants.PREPASS_POSITION_TEXTURE_TYPE,\r\n define: \"PREPASS_POSITION\",\r\n index: \"PREPASS_POSITION_INDEX\",\r\n },\r\n {\r\n type: Constants.PREPASS_VELOCITY_TEXTURE_TYPE,\r\n define: \"PREPASS_VELOCITY\",\r\n index: \"PREPASS_VELOCITY_INDEX\",\r\n },\r\n {\r\n type: Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE,\r\n define: \"PREPASS_REFLECTIVITY\",\r\n index: \"PREPASS_REFLECTIVITY_INDEX\",\r\n },\r\n {\r\n type: Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE,\r\n define: \"PREPASS_IRRADIANCE\",\r\n index: \"PREPASS_IRRADIANCE_INDEX\",\r\n },\r\n {\r\n type: Constants.PREPASS_ALBEDO_SQRT_TEXTURE_TYPE,\r\n define: \"PREPASS_ALBEDO_SQRT\",\r\n index: \"PREPASS_ALBEDO_SQRT_INDEX\",\r\n },\r\n {\r\n type: Constants.PREPASS_DEPTH_TEXTURE_TYPE,\r\n define: \"PREPASS_DEPTH\",\r\n index: \"PREPASS_DEPTH_INDEX\",\r\n },\r\n {\r\n type: Constants.PREPASS_NORMAL_TEXTURE_TYPE,\r\n define: \"PREPASS_NORMAL\",\r\n index: \"PREPASS_NORMAL_INDEX\",\r\n },\r\n ];\r\n\r\n if (scene.prePassRenderer && scene.prePassRenderer.enabled && canRenderToMRT) {\r\n defines.PREPASS = true;\r\n defines.SCENE_MRT_COUNT = scene.prePassRenderer.mrtCount;\r\n\r\n for (let i = 0; i < texturesList.length; i++) {\r\n const index = scene.prePassRenderer.getIndex(texturesList[i].type);\r\n if (index !== -1) {\r\n defines[texturesList[i].define] = true;\r\n defines[texturesList[i].index] = index;\r\n } else {\r\n defines[texturesList[i].define] = false;\r\n }\r\n }\r\n } else {\r\n defines.PREPASS = false;\r\n for (let i = 0; i < texturesList.length; i++) {\r\n defines[texturesList[i].define] = false;\r\n }\r\n }\r\n\r\n if (defines.PREPASS != previousPrePass) {\r\n defines.markAsUnprocessed();\r\n defines.markAsImageProcessingDirty();\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines related to the light information passed in parameter\r\n * @param scene The scene we are intending to draw\r\n * @param mesh The mesh the effect is compiling for\r\n * @param light The light the effect is compiling for\r\n * @param lightIndex The index of the light\r\n * @param defines The defines to update\r\n * @param specularSupported Specifies whether specular is supported or not (override lights data)\r\n * @param state Defines the current state regarding what is needed (normals, etc...)\r\n * @param state.needNormals\r\n * @param state.needRebuild\r\n * @param state.shadowEnabled\r\n * @param state.specularEnabled\r\n * @param state.lightmapMode\r\n */\r\n public static PrepareDefinesForLight(\r\n scene: Scene,\r\n mesh: AbstractMesh,\r\n light: Light,\r\n lightIndex: number,\r\n defines: any,\r\n specularSupported: boolean,\r\n state: {\r\n needNormals: boolean;\r\n needRebuild: boolean;\r\n shadowEnabled: boolean;\r\n specularEnabled: boolean;\r\n lightmapMode: boolean;\r\n }\r\n ) {\r\n state.needNormals = true;\r\n\r\n if (defines[\"LIGHT\" + lightIndex] === undefined) {\r\n state.needRebuild = true;\r\n }\r\n\r\n defines[\"LIGHT\" + lightIndex] = true;\r\n\r\n defines[\"SPOTLIGHT\" + lightIndex] = false;\r\n defines[\"HEMILIGHT\" + lightIndex] = false;\r\n defines[\"POINTLIGHT\" + lightIndex] = false;\r\n defines[\"DIRLIGHT\" + lightIndex] = false;\r\n\r\n light.prepareLightSpecificDefines(defines, lightIndex);\r\n\r\n // FallOff.\r\n defines[\"LIGHT_FALLOFF_PHYSICAL\" + lightIndex] = false;\r\n defines[\"LIGHT_FALLOFF_GLTF\" + lightIndex] = false;\r\n defines[\"LIGHT_FALLOFF_STANDARD\" + lightIndex] = false;\r\n\r\n switch (light.falloffType) {\r\n case LightConstants.FALLOFF_GLTF:\r\n defines[\"LIGHT_FALLOFF_GLTF\" + lightIndex] = true;\r\n break;\r\n case LightConstants.FALLOFF_PHYSICAL:\r\n defines[\"LIGHT_FALLOFF_PHYSICAL\" + lightIndex] = true;\r\n break;\r\n case LightConstants.FALLOFF_STANDARD:\r\n defines[\"LIGHT_FALLOFF_STANDARD\" + lightIndex] = true;\r\n break;\r\n }\r\n\r\n // Specular\r\n if (specularSupported && !light.specular.equalsFloats(0, 0, 0)) {\r\n state.specularEnabled = true;\r\n }\r\n\r\n // Shadows\r\n defines[\"SHADOW\" + lightIndex] = false;\r\n defines[\"SHADOWCSM\" + lightIndex] = false;\r\n defines[\"SHADOWCSMDEBUG\" + lightIndex] = false;\r\n defines[\"SHADOWCSMNUM_CASCADES\" + lightIndex] = false;\r\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + lightIndex] = false;\r\n defines[\"SHADOWCSMNOBLEND\" + lightIndex] = false;\r\n defines[\"SHADOWCSM_RIGHTHANDED\" + lightIndex] = false;\r\n defines[\"SHADOWPCF\" + lightIndex] = false;\r\n defines[\"SHADOWPCSS\" + lightIndex] = false;\r\n defines[\"SHADOWPOISSON\" + lightIndex] = false;\r\n defines[\"SHADOWESM\" + lightIndex] = false;\r\n defines[\"SHADOWCLOSEESM\" + lightIndex] = false;\r\n defines[\"SHADOWCUBE\" + lightIndex] = false;\r\n defines[\"SHADOWLOWQUALITY\" + lightIndex] = false;\r\n defines[\"SHADOWMEDIUMQUALITY\" + lightIndex] = false;\r\n\r\n if (mesh && mesh.receiveShadows && scene.shadowsEnabled && light.shadowEnabled) {\r\n const shadowGenerator = light.getShadowGenerator(scene.activeCamera) ?? light.getShadowGenerator();\r\n if (shadowGenerator) {\r\n const shadowMap = shadowGenerator.getShadowMap();\r\n if (shadowMap) {\r\n if (shadowMap.renderList && shadowMap.renderList.length > 0) {\r\n state.shadowEnabled = true;\r\n shadowGenerator.prepareDefines(defines, lightIndex);\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (light.lightmapMode != LightConstants.LIGHTMAP_DEFAULT) {\r\n state.lightmapMode = true;\r\n defines[\"LIGHTMAPEXCLUDED\" + lightIndex] = true;\r\n defines[\"LIGHTMAPNOSPECULAR\" + lightIndex] = light.lightmapMode == LightConstants.LIGHTMAP_SHADOWSONLY;\r\n } else {\r\n defines[\"LIGHTMAPEXCLUDED\" + lightIndex] = false;\r\n defines[\"LIGHTMAPNOSPECULAR\" + lightIndex] = false;\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the defines related to the light information passed in parameter\r\n * @param scene The scene we are intending to draw\r\n * @param mesh The mesh the effect is compiling for\r\n * @param defines The defines to update\r\n * @param specularSupported Specifies whether specular is supported or not (override lights data)\r\n * @param maxSimultaneousLights Specifies how manuy lights can be added to the effect at max\r\n * @param disableLighting Specifies whether the lighting is disabled (override scene and light)\r\n * @returns true if normals will be required for the rest of the effect\r\n */\r\n public static PrepareDefinesForLights(scene: Scene, mesh: AbstractMesh, defines: any, specularSupported: boolean, maxSimultaneousLights = 4, disableLighting = false): boolean {\r\n if (!defines._areLightsDirty) {\r\n return defines._needNormals;\r\n }\r\n\r\n let lightIndex = 0;\r\n const state = {\r\n needNormals: defines._needNormals, // prevents overriding previous reflection or other needs for normals\r\n needRebuild: false,\r\n lightmapMode: false,\r\n shadowEnabled: false,\r\n specularEnabled: false,\r\n };\r\n\r\n if (scene.lightsEnabled && !disableLighting) {\r\n for (const light of mesh.lightSources) {\r\n this.PrepareDefinesForLight(scene, mesh, light, lightIndex, defines, specularSupported, state);\r\n\r\n lightIndex++;\r\n if (lightIndex === maxSimultaneousLights) {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n defines[\"SPECULARTERM\"] = state.specularEnabled;\r\n defines[\"SHADOWS\"] = state.shadowEnabled;\r\n\r\n // Resetting all other lights if any\r\n for (let index = lightIndex; index < maxSimultaneousLights; index++) {\r\n if (defines[\"LIGHT\" + index] !== undefined) {\r\n defines[\"LIGHT\" + index] = false;\r\n defines[\"HEMILIGHT\" + index] = false;\r\n defines[\"POINTLIGHT\" + index] = false;\r\n defines[\"DIRLIGHT\" + index] = false;\r\n defines[\"SPOTLIGHT\" + index] = false;\r\n defines[\"SHADOW\" + index] = false;\r\n defines[\"SHADOWCSM\" + index] = false;\r\n defines[\"SHADOWCSMDEBUG\" + index] = false;\r\n defines[\"SHADOWCSMNUM_CASCADES\" + index] = false;\r\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + index] = false;\r\n defines[\"SHADOWCSMNOBLEND\" + index] = false;\r\n defines[\"SHADOWCSM_RIGHTHANDED\" + index] = false;\r\n defines[\"SHADOWPCF\" + index] = false;\r\n defines[\"SHADOWPCSS\" + index] = false;\r\n defines[\"SHADOWPOISSON\" + index] = false;\r\n defines[\"SHADOWESM\" + index] = false;\r\n defines[\"SHADOWCLOSEESM\" + index] = false;\r\n defines[\"SHADOWCUBE\" + index] = false;\r\n defines[\"SHADOWLOWQUALITY\" + index] = false;\r\n defines[\"SHADOWMEDIUMQUALITY\" + index] = false;\r\n }\r\n }\r\n\r\n const caps = scene.getEngine().getCaps();\r\n\r\n if (defines[\"SHADOWFLOAT\"] === undefined) {\r\n state.needRebuild = true;\r\n }\r\n\r\n defines[\"SHADOWFLOAT\"] =\r\n state.shadowEnabled && ((caps.textureFloatRender && caps.textureFloatLinearFiltering) || (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering));\r\n defines[\"LIGHTMAPEXCLUDED\"] = state.lightmapMode;\r\n\r\n if (state.needRebuild) {\r\n defines.rebuild();\r\n }\r\n\r\n return state.needNormals;\r\n }\r\n\r\n /**\r\n * Prepares the uniforms and samplers list to be used in the effect (for a specific light)\r\n * @param lightIndex defines the light index\r\n * @param uniformsList The uniform list\r\n * @param samplersList The sampler list\r\n * @param projectedLightTexture defines if projected texture must be used\r\n * @param uniformBuffersList defines an optional list of uniform buffers\r\n * @param updateOnlyBuffersList True to only update the uniformBuffersList array\r\n */\r\n public static PrepareUniformsAndSamplersForLight(\r\n lightIndex: number,\r\n uniformsList: string[],\r\n samplersList: string[],\r\n projectedLightTexture?: any,\r\n uniformBuffersList: Nullable = null,\r\n updateOnlyBuffersList = false\r\n ) {\r\n if (uniformBuffersList) {\r\n uniformBuffersList.push(\"Light\" + lightIndex);\r\n }\r\n\r\n if (updateOnlyBuffersList) {\r\n return;\r\n }\r\n\r\n uniformsList.push(\r\n \"vLightData\" + lightIndex,\r\n \"vLightDiffuse\" + lightIndex,\r\n \"vLightSpecular\" + lightIndex,\r\n \"vLightDirection\" + lightIndex,\r\n \"vLightFalloff\" + lightIndex,\r\n \"vLightGround\" + lightIndex,\r\n \"lightMatrix\" + lightIndex,\r\n \"shadowsInfo\" + lightIndex,\r\n \"depthValues\" + lightIndex\r\n );\r\n\r\n samplersList.push(\"shadowSampler\" + lightIndex);\r\n samplersList.push(\"depthSampler\" + lightIndex);\r\n\r\n uniformsList.push(\r\n \"viewFrustumZ\" + lightIndex,\r\n \"cascadeBlendFactor\" + lightIndex,\r\n \"lightSizeUVCorrection\" + lightIndex,\r\n \"depthCorrection\" + lightIndex,\r\n \"penumbraDarkness\" + lightIndex,\r\n \"frustumLengths\" + lightIndex\r\n );\r\n\r\n if (projectedLightTexture) {\r\n samplersList.push(\"projectionLightSampler\" + lightIndex);\r\n uniformsList.push(\"textureProjectionMatrix\" + lightIndex);\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the uniforms and samplers list to be used in the effect\r\n * @param uniformsListOrOptions The uniform names to prepare or an EffectCreationOptions containing the list and extra information\r\n * @param samplersList The sampler list\r\n * @param defines The defines helping in the list generation\r\n * @param maxSimultaneousLights The maximum number of simultaneous light allowed in the effect\r\n */\r\n public static PrepareUniformsAndSamplersList(\r\n uniformsListOrOptions: string[] | IEffectCreationOptions,\r\n samplersList?: string[],\r\n defines?: any,\r\n maxSimultaneousLights = 4\r\n ): void {\r\n let uniformsList: string[];\r\n let uniformBuffersList: Nullable = null;\r\n\r\n if ((uniformsListOrOptions).uniformsNames) {\r\n const options = uniformsListOrOptions;\r\n uniformsList = options.uniformsNames;\r\n uniformBuffersList = options.uniformBuffersNames;\r\n samplersList = options.samplers;\r\n defines = options.defines;\r\n maxSimultaneousLights = options.maxSimultaneousLights || 0;\r\n } else {\r\n uniformsList = uniformsListOrOptions;\r\n if (!samplersList) {\r\n samplersList = [];\r\n }\r\n }\r\n\r\n for (let lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {\r\n if (!defines[\"LIGHT\" + lightIndex]) {\r\n break;\r\n }\r\n this.PrepareUniformsAndSamplersForLight(lightIndex, uniformsList, samplersList, defines[\"PROJECTEDLIGHTTEXTURE\" + lightIndex], uniformBuffersList);\r\n }\r\n\r\n if (defines[\"NUM_MORPH_INFLUENCERS\"]) {\r\n uniformsList.push(\"morphTargetInfluences\");\r\n }\r\n\r\n if (defines[\"BAKED_VERTEX_ANIMATION_TEXTURE\"]) {\r\n uniformsList.push(\"bakedVertexAnimationSettings\");\r\n uniformsList.push(\"bakedVertexAnimationTextureSizeInverted\");\r\n uniformsList.push(\"bakedVertexAnimationTime\");\r\n samplersList.push(\"bakedVertexAnimationTexture\");\r\n }\r\n }\r\n\r\n /**\r\n * This helps decreasing rank by rank the shadow quality (0 being the highest rank and quality)\r\n * @param defines The defines to update while falling back\r\n * @param fallbacks The authorized effect fallbacks\r\n * @param maxSimultaneousLights The maximum number of lights allowed\r\n * @param rank the current rank of the Effect\r\n * @returns The newly affected rank\r\n */\r\n public static HandleFallbacksForShadows(defines: any, fallbacks: EffectFallbacks, maxSimultaneousLights = 4, rank = 0): number {\r\n let lightFallbackRank = 0;\r\n for (let lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {\r\n if (!defines[\"LIGHT\" + lightIndex]) {\r\n break;\r\n }\r\n\r\n if (lightIndex > 0) {\r\n lightFallbackRank = rank + lightIndex;\r\n fallbacks.addFallback(lightFallbackRank, \"LIGHT\" + lightIndex);\r\n }\r\n\r\n if (!defines[\"SHADOWS\"]) {\r\n if (defines[\"SHADOW\" + lightIndex]) {\r\n fallbacks.addFallback(rank, \"SHADOW\" + lightIndex);\r\n }\r\n\r\n if (defines[\"SHADOWPCF\" + lightIndex]) {\r\n fallbacks.addFallback(rank, \"SHADOWPCF\" + lightIndex);\r\n }\r\n\r\n if (defines[\"SHADOWPCSS\" + lightIndex]) {\r\n fallbacks.addFallback(rank, \"SHADOWPCSS\" + lightIndex);\r\n }\r\n\r\n if (defines[\"SHADOWPOISSON\" + lightIndex]) {\r\n fallbacks.addFallback(rank, \"SHADOWPOISSON\" + lightIndex);\r\n }\r\n\r\n if (defines[\"SHADOWESM\" + lightIndex]) {\r\n fallbacks.addFallback(rank, \"SHADOWESM\" + lightIndex);\r\n }\r\n\r\n if (defines[\"SHADOWCLOSEESM\" + lightIndex]) {\r\n fallbacks.addFallback(rank, \"SHADOWCLOSEESM\" + lightIndex);\r\n }\r\n }\r\n }\r\n return lightFallbackRank++;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private static _TmpMorphInfluencers = { NUM_MORPH_INFLUENCERS: 0 };\r\n /**\r\n * Prepares the list of attributes required for morph targets according to the effect defines.\r\n * @param attribs The current list of supported attribs\r\n * @param mesh The mesh to prepare the morph targets attributes for\r\n * @param influencers The number of influencers\r\n */\r\n public static PrepareAttributesForMorphTargetsInfluencers(attribs: string[], mesh: AbstractMesh, influencers: number): void {\r\n this._TmpMorphInfluencers.NUM_MORPH_INFLUENCERS = influencers;\r\n this.PrepareAttributesForMorphTargets(attribs, mesh, this._TmpMorphInfluencers);\r\n }\r\n\r\n /**\r\n * Prepares the list of attributes required for morph targets according to the effect defines.\r\n * @param attribs The current list of supported attribs\r\n * @param mesh The mesh to prepare the morph targets attributes for\r\n * @param defines The current Defines of the effect\r\n */\r\n public static PrepareAttributesForMorphTargets(attribs: string[], mesh: AbstractMesh, defines: any): void {\r\n const influencers = defines[\"NUM_MORPH_INFLUENCERS\"];\r\n\r\n if (influencers > 0 && EngineStore.LastCreatedEngine) {\r\n const maxAttributesCount = EngineStore.LastCreatedEngine.getCaps().maxVertexAttribs;\r\n const manager = (mesh).morphTargetManager;\r\n if (manager?.isUsingTextureForTargets) {\r\n return;\r\n }\r\n const normal = manager && manager.supportsNormals && defines[\"NORMAL\"];\r\n const tangent = manager && manager.supportsTangents && defines[\"TANGENT\"];\r\n const uv = manager && manager.supportsUVs && defines[\"UV1\"];\r\n for (let index = 0; index < influencers; index++) {\r\n attribs.push(VertexBuffer.PositionKind + index);\r\n\r\n if (normal) {\r\n attribs.push(VertexBuffer.NormalKind + index);\r\n }\r\n\r\n if (tangent) {\r\n attribs.push(VertexBuffer.TangentKind + index);\r\n }\r\n\r\n if (uv) {\r\n attribs.push(VertexBuffer.UVKind + \"_\" + index);\r\n }\r\n\r\n if (attribs.length > maxAttributesCount) {\r\n Logger.Error(\"Cannot add more vertex attributes for mesh \" + mesh.name);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the list of attributes required for baked vertex animations according to the effect defines.\r\n * @param attribs The current list of supported attribs\r\n * @param mesh The mesh to prepare the morph targets attributes for\r\n * @param defines The current Defines of the effect\r\n */\r\n public static PrepareAttributesForBakedVertexAnimation(attribs: string[], mesh: AbstractMesh, defines: any): void {\r\n const enabled = defines[\"BAKED_VERTEX_ANIMATION_TEXTURE\"] && defines[\"INSTANCES\"];\r\n\r\n if (enabled) {\r\n attribs.push(\"bakedVertexAnimationSettingsInstanced\");\r\n }\r\n }\r\n\r\n /**\r\n * Prepares the list of attributes required for bones according to the effect defines.\r\n * @param attribs The current list of supported attribs\r\n * @param mesh The mesh to prepare the bones attributes for\r\n * @param defines The current Defines of the effect\r\n * @param fallbacks The current effect fallback strategy\r\n */\r\n public static PrepareAttributesForBones(attribs: string[], mesh: AbstractMesh, defines: any, fallbacks: EffectFallbacks): void {\r\n if (defines[\"NUM_BONE_INFLUENCERS\"] > 0) {\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (defines[\"NUM_BONE_INFLUENCERS\"] > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Check and prepare the list of attributes required for instances according to the effect defines.\r\n * @param attribs The current list of supported attribs\r\n * @param defines The current MaterialDefines of the effect\r\n */\r\n public static PrepareAttributesForInstances(attribs: string[], defines: MaterialDefines): void {\r\n if (defines[\"INSTANCES\"] || defines[\"THIN_INSTANCES\"]) {\r\n this.PushAttributesForInstances(attribs, !!defines[\"PREPASS_VELOCITY\"]);\r\n }\r\n\r\n if (defines.INSTANCESCOLOR) {\r\n attribs.push(VertexBuffer.ColorInstanceKind);\r\n }\r\n }\r\n\r\n /**\r\n * Add the list of attributes required for instances to the attribs array.\r\n * @param attribs The current list of supported attribs\r\n * @param needsPreviousMatrices If the shader needs previous matrices\r\n */\r\n public static PushAttributesForInstances(attribs: string[], needsPreviousMatrices: boolean = false): void {\r\n attribs.push(\"world0\");\r\n attribs.push(\"world1\");\r\n attribs.push(\"world2\");\r\n attribs.push(\"world3\");\r\n if (needsPreviousMatrices) {\r\n attribs.push(\"previousWorld0\");\r\n attribs.push(\"previousWorld1\");\r\n attribs.push(\"previousWorld2\");\r\n attribs.push(\"previousWorld3\");\r\n }\r\n }\r\n\r\n /**\r\n * Binds the light information to the effect.\r\n * @param light The light containing the generator\r\n * @param effect The effect we are binding the data to\r\n * @param lightIndex The light index in the effect used to render\r\n */\r\n public static BindLightProperties(light: Light, effect: Effect, lightIndex: number): void {\r\n light.transferToEffect(effect, lightIndex + \"\");\r\n }\r\n\r\n /**\r\n * Binds the lights information from the scene to the effect for the given mesh.\r\n * @param light Light to bind\r\n * @param lightIndex Light index\r\n * @param scene The scene where the light belongs to\r\n * @param effect The effect we are binding the data to\r\n * @param useSpecular Defines if specular is supported\r\n * @param receiveShadows Defines if the effect (mesh) we bind the light for receives shadows\r\n */\r\n public static BindLight(light: Light, lightIndex: number, scene: Scene, effect: Effect, useSpecular: boolean, receiveShadows = true): void {\r\n light._bindLight(lightIndex, scene, effect, useSpecular, receiveShadows);\r\n }\r\n\r\n /**\r\n * Binds the lights information from the scene to the effect for the given mesh.\r\n * @param scene The scene the lights belongs to\r\n * @param mesh The mesh we are binding the information to render\r\n * @param effect The effect we are binding the data to\r\n * @param defines The generated defines for the effect\r\n * @param maxSimultaneousLights The maximum number of light that can be bound to the effect\r\n */\r\n public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: any, maxSimultaneousLights = 4): void {\r\n const len = Math.min(mesh.lightSources.length, maxSimultaneousLights);\r\n\r\n for (let i = 0; i < len; i++) {\r\n const light = mesh.lightSources[i];\r\n this.BindLight(light, i, scene, effect, typeof defines === \"boolean\" ? defines : defines[\"SPECULARTERM\"], mesh.receiveShadows);\r\n }\r\n }\r\n\r\n private static _TempFogColor = Color3.Black();\r\n /**\r\n * Binds the fog information from the scene to the effect for the given mesh.\r\n * @param scene The scene the lights belongs to\r\n * @param mesh The mesh we are binding the information to render\r\n * @param effect The effect we are binding the data to\r\n * @param linearSpace Defines if the fog effect is applied in linear space\r\n */\r\n public static BindFogParameters(scene: Scene, mesh: AbstractMesh, effect: Effect, linearSpace = false): void {\r\n if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {\r\n effect.setFloat4(\"vFogInfos\", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);\r\n // Convert fog color to linear space if used in a linear space computed shader.\r\n if (linearSpace) {\r\n scene.fogColor.toLinearSpaceToRef(this._TempFogColor, scene.getEngine().useExactSrgbConversions);\r\n effect.setColor3(\"vFogColor\", this._TempFogColor);\r\n } else {\r\n effect.setColor3(\"vFogColor\", scene.fogColor);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Binds the bones information from the mesh to the effect.\r\n * @param mesh The mesh we are binding the information to render\r\n * @param effect The effect we are binding the data to\r\n * @param prePassConfiguration Configuration for the prepass, in case prepass is activated\r\n */\r\n public static BindBonesParameters(mesh?: AbstractMesh, effect?: Effect, prePassConfiguration?: PrePassConfiguration): void {\r\n if (!effect || !mesh) {\r\n return;\r\n }\r\n if (mesh.computeBonesUsingShaders && effect._bonesComputationForcedToCPU) {\r\n mesh.computeBonesUsingShaders = false;\r\n }\r\n\r\n if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\r\n const skeleton = mesh.skeleton;\r\n\r\n if (skeleton.isUsingTextureForMatrices && effect.getUniformIndex(\"boneTextureWidth\") > -1) {\r\n const boneTexture = skeleton.getTransformMatrixTexture(mesh);\r\n effect.setTexture(\"boneSampler\", boneTexture);\r\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\r\n } else {\r\n const matrices = skeleton.getTransformMatrices(mesh);\r\n\r\n if (matrices) {\r\n effect.setMatrices(\"mBones\", matrices);\r\n if (prePassConfiguration && mesh.getScene().prePassRenderer && mesh.getScene().prePassRenderer!.getIndex(Constants.PREPASS_VELOCITY_TEXTURE_TYPE)) {\r\n if (!prePassConfiguration.previousBones[mesh.uniqueId]) {\r\n prePassConfiguration.previousBones[mesh.uniqueId] = matrices.slice();\r\n }\r\n effect.setMatrices(\"mPreviousBones\", prePassConfiguration.previousBones[mesh.uniqueId]);\r\n MaterialHelper._CopyBonesTransformationMatrices(matrices, prePassConfiguration.previousBones[mesh.uniqueId]);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Copies the bones transformation matrices into the target array and returns the target's reference\r\n private static _CopyBonesTransformationMatrices(source: Float32Array, target: Float32Array): Float32Array {\r\n target.set(source);\r\n\r\n return target;\r\n }\r\n\r\n /**\r\n * Binds the morph targets information from the mesh to the effect.\r\n * @param abstractMesh The mesh we are binding the information to render\r\n * @param effect The effect we are binding the data to\r\n */\r\n public static BindMorphTargetParameters(abstractMesh: AbstractMesh, effect: Effect): void {\r\n const manager = (abstractMesh).morphTargetManager;\r\n if (!abstractMesh || !manager) {\r\n return;\r\n }\r\n\r\n effect.setFloatArray(\"morphTargetInfluences\", manager.influences);\r\n }\r\n\r\n /**\r\n * Binds the logarithmic depth information from the scene to the effect for the given defines.\r\n * @param defines The generated defines used in the effect\r\n * @param effect The effect we are binding the data to\r\n * @param scene The scene we are willing to render with logarithmic scale for\r\n */\r\n public static BindLogDepth(defines: any, effect: Effect, scene: Scene): void {\r\n if (!defines || defines[\"LOGARITHMICDEPTH\"] || (defines.indexOf && defines.indexOf(\"LOGARITHMICDEPTH\") >= 0)) {\r\n const camera = scene.activeCamera;\r\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n Logger.Error(\"Logarithmic depth is not compatible with orthographic cameras!\", 20);\r\n }\r\n effect.setFloat(\"logarithmicDepthConstant\", 2.0 / (Math.log(camera.maxZ + 1.0) / Math.LN2));\r\n }\r\n }\r\n}\r\n","import { Constants } from \"../Engines/constants\";\r\nimport { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport type { IStencilState } from \"../States/IStencilState\";\r\n\r\nimport type { Scene } from \"../scene\";\r\n\r\n/**\r\n * Class that holds the different stencil states of a material\r\n * Usage example: https://playground.babylonjs.com/#CW5PRI#10\r\n */\r\nexport class MaterialStencilState implements IStencilState {\r\n /**\r\n * Creates a material stencil state instance\r\n */\r\n public constructor() {\r\n this.reset();\r\n }\r\n\r\n /**\r\n * Resets all the stencil states to default values\r\n */\r\n public reset() {\r\n this.enabled = false;\r\n this.mask = 0xff;\r\n\r\n this.func = Constants.ALWAYS;\r\n this.funcRef = 1;\r\n this.funcMask = 0xff;\r\n\r\n this.opStencilFail = Constants.KEEP;\r\n this.opDepthFail = Constants.KEEP;\r\n this.opStencilDepthPass = Constants.REPLACE;\r\n }\r\n\r\n private _func: number;\r\n /**\r\n * Gets or sets the stencil function\r\n */\r\n @serialize()\r\n public get func(): number {\r\n return this._func;\r\n }\r\n\r\n public set func(value: number) {\r\n this._func = value;\r\n }\r\n\r\n private _funcRef: number;\r\n /**\r\n * Gets or sets the stencil function reference\r\n */\r\n @serialize()\r\n public get funcRef(): number {\r\n return this._funcRef;\r\n }\r\n\r\n public set funcRef(value: number) {\r\n this._funcRef = value;\r\n }\r\n\r\n private _funcMask: number;\r\n /**\r\n * Gets or sets the stencil function mask\r\n */\r\n @serialize()\r\n public get funcMask(): number {\r\n return this._funcMask;\r\n }\r\n\r\n public set funcMask(value: number) {\r\n this._funcMask = value;\r\n }\r\n\r\n private _opStencilFail: number;\r\n /**\r\n * Gets or sets the operation when the stencil test fails\r\n */\r\n @serialize()\r\n public get opStencilFail(): number {\r\n return this._opStencilFail;\r\n }\r\n\r\n public set opStencilFail(value: number) {\r\n this._opStencilFail = value;\r\n }\r\n\r\n private _opDepthFail: number;\r\n /**\r\n * Gets or sets the operation when the depth test fails\r\n */\r\n @serialize()\r\n public get opDepthFail(): number {\r\n return this._opDepthFail;\r\n }\r\n\r\n public set opDepthFail(value: number) {\r\n this._opDepthFail = value;\r\n }\r\n\r\n private _opStencilDepthPass: number;\r\n /**\r\n * Gets or sets the operation when the stencil+depth test succeeds\r\n */\r\n @serialize()\r\n public get opStencilDepthPass(): number {\r\n return this._opStencilDepthPass;\r\n }\r\n\r\n public set opStencilDepthPass(value: number) {\r\n this._opStencilDepthPass = value;\r\n }\r\n\r\n private _mask: number;\r\n /**\r\n * Gets or sets the stencil mask\r\n */\r\n @serialize()\r\n public get mask(): number {\r\n return this._mask;\r\n }\r\n\r\n public set mask(value: number) {\r\n this._mask = value;\r\n }\r\n\r\n private _enabled: boolean;\r\n /**\r\n * Enables or disables the stencil test\r\n */\r\n @serialize()\r\n public get enabled(): boolean {\r\n return this._enabled;\r\n }\r\n\r\n public set enabled(value: boolean) {\r\n this._enabled = value;\r\n }\r\n\r\n /**\r\n * Get the current class name, useful for serialization or dynamic coding.\r\n * @returns \"MaterialStencilState\"\r\n */\r\n public getClassName(): string {\r\n return \"MaterialStencilState\";\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the current configuration into another one.\r\n * @param stencilState defines stencil state where to copy the info\r\n */\r\n public copyTo(stencilState: MaterialStencilState): void {\r\n SerializationHelper.Clone(() => stencilState, this);\r\n }\r\n\r\n /**\r\n * Serializes this stencil configuration.\r\n * @returns - An object with the serialized config.\r\n */\r\n public serialize(): any {\r\n return SerializationHelper.Serialize(this);\r\n }\r\n\r\n /**\r\n * Parses a stencil state configuration from a serialized object.\r\n * @param source - Serialized object.\r\n * @param scene Defines the scene we are parsing for\r\n * @param rootUrl Defines the rootUrl to load from\r\n */\r\n public parse(source: any, scene: Scene, rootUrl: string): void {\r\n SerializationHelper.Parse(() => this, source, scene, rootUrl);\r\n }\r\n}\r\n","import type { ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\n\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { RenderTargetTexture } from \"./Textures/renderTargetTexture\";\r\n\r\n/** @internal */\r\nexport type MaterialPluginCreated = {};\r\n\r\n/** @internal */\r\nexport type MaterialPluginDisposed = {\r\n forceDisposeTextures?: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHasTexture = {\r\n hasTexture: boolean;\r\n texture: BaseTexture;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginIsReadyForSubMesh = {\r\n isReadyForSubMesh: boolean;\r\n defines: MaterialDefines;\r\n subMesh: SubMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetDefineNames = {\r\n defineNames?: { [name: string]: { type: string; default: any } };\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareEffect = {\r\n defines: MaterialDefines;\r\n fallbacks: EffectFallbacks;\r\n fallbackRank: number;\r\n customCode?: ShaderCustomProcessingFunction;\r\n attributes: string[];\r\n uniforms: string[];\r\n samplers: string[];\r\n uniformBuffersNames: string[];\r\n mesh: AbstractMesh;\r\n indexParameters: any;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareDefines = {\r\n defines: MaterialDefines;\r\n mesh: AbstractMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginPrepareUniformBuffer = {\r\n ubo: UniformBuffer;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginBindForSubMesh = {\r\n subMesh: SubMesh;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetAnimatables = {\r\n animatables: IAnimatable[];\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginGetActiveTextures = {\r\n activeTextures: BaseTexture[];\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginFillRenderTargetTextures = {\r\n renderTargets: SmartArray;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHasRenderTargetTextures = {\r\n hasRenderTargetTextures: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type MaterialPluginHardBindForSubMesh = {\r\n subMesh: SubMesh;\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nexport enum MaterialPluginEvent {\r\n Created = 0x0001,\r\n Disposed = 0x0002,\r\n GetDefineNames = 0x0004,\r\n PrepareUniformBuffer = 0x0008,\r\n IsReadyForSubMesh = 0x0010,\r\n PrepareDefines = 0x0020,\r\n BindForSubMesh = 0x0040,\r\n PrepareEffect = 0x0080,\r\n GetAnimatables = 0x0100,\r\n GetActiveTextures = 0x0200,\r\n HasTexture = 0x0400,\r\n FillRenderTargetTextures = 0x0800,\r\n HasRenderTargetTextures = 0x1000,\r\n HardBindForSubMesh = 0x2000,\r\n}\r\n","import type { DeepImmutable, Nullable } from \"../types\";\r\nimport { Scalar } from \"./math.scalar\";\r\nimport { Vector2, Vector3, Quaternion, Matrix } from \"./math.vector\";\r\nimport { Epsilon } from \"./math.constants\";\r\n\r\n/**\r\n * Defines potential orientation for back face culling\r\n */\r\nexport enum Orientation {\r\n /**\r\n * Clockwise\r\n */\r\n CW = 0,\r\n /** Counter clockwise */\r\n CCW = 1,\r\n}\r\n\r\n/** Class used to represent a Bezier curve */\r\nexport class BezierCurve {\r\n /**\r\n * Returns the cubic Bezier interpolated value (float) at \"t\" (float) from the given x1, y1, x2, y2 floats\r\n * @param t defines the time\r\n * @param x1 defines the left coordinate on X axis\r\n * @param y1 defines the left coordinate on Y axis\r\n * @param x2 defines the right coordinate on X axis\r\n * @param y2 defines the right coordinate on Y axis\r\n * @returns the interpolated value\r\n */\r\n public static Interpolate(t: number, x1: number, y1: number, x2: number, y2: number): number {\r\n // Extract X (which is equal to time here)\r\n const f0 = 1 - 3 * x2 + 3 * x1;\r\n const f1 = 3 * x2 - 6 * x1;\r\n const f2 = 3 * x1;\r\n\r\n let refinedT = t;\r\n for (let i = 0; i < 5; i++) {\r\n const refinedT2 = refinedT * refinedT;\r\n const refinedT3 = refinedT2 * refinedT;\r\n\r\n const x = f0 * refinedT3 + f1 * refinedT2 + f2 * refinedT;\r\n const slope = 1.0 / (3.0 * f0 * refinedT2 + 2.0 * f1 * refinedT + f2);\r\n refinedT -= (x - t) * slope;\r\n refinedT = Math.min(1, Math.max(0, refinedT));\r\n }\r\n\r\n // Resolve cubic bezier for the given x\r\n return 3 * Math.pow(1 - refinedT, 2) * refinedT * y1 + 3 * (1 - refinedT) * Math.pow(refinedT, 2) * y2 + Math.pow(refinedT, 3);\r\n }\r\n}\r\n\r\n/**\r\n * Defines angle representation\r\n */\r\nexport class Angle {\r\n private _radians: number;\r\n\r\n /**\r\n * Creates an Angle object of \"radians\" radians (float).\r\n * @param radians the angle in radians\r\n */\r\n constructor(radians: number) {\r\n this._radians = radians;\r\n if (this._radians < 0.0) {\r\n this._radians += 2.0 * Math.PI;\r\n }\r\n }\r\n\r\n /**\r\n * Get value in degrees\r\n * @returns the Angle value in degrees (float)\r\n */\r\n public degrees() {\r\n return (this._radians * 180.0) / Math.PI;\r\n }\r\n\r\n /**\r\n * Get value in radians\r\n * @returns the Angle value in radians (float)\r\n */\r\n public radians() {\r\n return this._radians;\r\n }\r\n\r\n /**\r\n * Gets a new Angle object valued with the gradient angle, in radians, of the line joining two points\r\n * @param a defines first point as the origin\r\n * @param b defines point\r\n * @returns a new Angle\r\n */\r\n public static BetweenTwoPoints(a: DeepImmutable, b: DeepImmutable): Angle {\r\n const delta = b.subtract(a);\r\n const theta = Math.atan2(delta.y, delta.x);\r\n return new Angle(theta);\r\n }\r\n\r\n /**\r\n * Gets a new Angle object from the given float in radians\r\n * @param radians defines the angle value in radians\r\n * @returns a new Angle\r\n */\r\n public static FromRadians(radians: number): Angle {\r\n return new Angle(radians);\r\n }\r\n /**\r\n * Gets a new Angle object from the given float in degrees\r\n * @param degrees defines the angle value in degrees\r\n * @returns a new Angle\r\n */\r\n public static FromDegrees(degrees: number): Angle {\r\n return new Angle((degrees * Math.PI) / 180.0);\r\n }\r\n}\r\n\r\n/**\r\n * This represents an arc in a 2d space.\r\n */\r\nexport class Arc2 {\r\n /**\r\n * Defines the center point of the arc.\r\n */\r\n public centerPoint: Vector2;\r\n /**\r\n * Defines the radius of the arc.\r\n */\r\n public radius: number;\r\n /**\r\n * Defines the angle of the arc (from mid point to end point).\r\n */\r\n public angle: Angle;\r\n /**\r\n * Defines the start angle of the arc (from start point to middle point).\r\n */\r\n public startAngle: Angle;\r\n /**\r\n * Defines the orientation of the arc (clock wise/counter clock wise).\r\n */\r\n public orientation: Orientation;\r\n\r\n /**\r\n * Creates an Arc object from the three given points : start, middle and end.\r\n * @param startPoint Defines the start point of the arc\r\n * @param midPoint Defines the middle point of the arc\r\n * @param endPoint Defines the end point of the arc\r\n */\r\n constructor(\r\n /** Defines the start point of the arc */\r\n public startPoint: Vector2,\r\n /** Defines the mid point of the arc */\r\n public midPoint: Vector2,\r\n /** Defines the end point of the arc */\r\n public endPoint: Vector2\r\n ) {\r\n const temp = Math.pow(midPoint.x, 2) + Math.pow(midPoint.y, 2);\r\n const startToMid = (Math.pow(startPoint.x, 2) + Math.pow(startPoint.y, 2) - temp) / 2;\r\n const midToEnd = (temp - Math.pow(endPoint.x, 2) - Math.pow(endPoint.y, 2)) / 2;\r\n const det = (startPoint.x - midPoint.x) * (midPoint.y - endPoint.y) - (midPoint.x - endPoint.x) * (startPoint.y - midPoint.y);\r\n\r\n this.centerPoint = new Vector2(\r\n (startToMid * (midPoint.y - endPoint.y) - midToEnd * (startPoint.y - midPoint.y)) / det,\r\n ((startPoint.x - midPoint.x) * midToEnd - (midPoint.x - endPoint.x) * startToMid) / det\r\n );\r\n\r\n this.radius = this.centerPoint.subtract(this.startPoint).length();\r\n\r\n this.startAngle = Angle.BetweenTwoPoints(this.centerPoint, this.startPoint);\r\n\r\n const a1 = this.startAngle.degrees();\r\n let a2 = Angle.BetweenTwoPoints(this.centerPoint, this.midPoint).degrees();\r\n let a3 = Angle.BetweenTwoPoints(this.centerPoint, this.endPoint).degrees();\r\n\r\n // angles correction\r\n if (a2 - a1 > +180.0) {\r\n a2 -= 360.0;\r\n }\r\n if (a2 - a1 < -180.0) {\r\n a2 += 360.0;\r\n }\r\n if (a3 - a2 > +180.0) {\r\n a3 -= 360.0;\r\n }\r\n if (a3 - a2 < -180.0) {\r\n a3 += 360.0;\r\n }\r\n\r\n this.orientation = a2 - a1 < 0 ? Orientation.CW : Orientation.CCW;\r\n this.angle = Angle.FromDegrees(this.orientation === Orientation.CW ? a1 - a3 : a3 - a1);\r\n }\r\n}\r\n\r\n/**\r\n * Represents a 2D path made up of multiple 2D points\r\n */\r\nexport class Path2 {\r\n private _points = new Array();\r\n private _length = 0.0;\r\n\r\n /**\r\n * If the path start and end point are the same\r\n */\r\n public closed = false;\r\n\r\n /**\r\n * Creates a Path2 object from the starting 2D coordinates x and y.\r\n * @param x the starting points x value\r\n * @param y the starting points y value\r\n */\r\n constructor(x: number, y: number) {\r\n this._points.push(new Vector2(x, y));\r\n }\r\n\r\n /**\r\n * Adds a new segment until the given coordinates (x, y) to the current Path2.\r\n * @param x the added points x value\r\n * @param y the added points y value\r\n * @returns the updated Path2.\r\n */\r\n public addLineTo(x: number, y: number): Path2 {\r\n if (this.closed) {\r\n return this;\r\n }\r\n const newPoint = new Vector2(x, y);\r\n const previousPoint = this._points[this._points.length - 1];\r\n this._points.push(newPoint);\r\n this._length += newPoint.subtract(previousPoint).length();\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds _numberOfSegments_ segments according to the arc definition (middle point coordinates, end point coordinates, the arc start point being the current Path2 last point) to the current Path2.\r\n * @param midX middle point x value\r\n * @param midY middle point y value\r\n * @param endX end point x value\r\n * @param endY end point y value\r\n * @param numberOfSegments (default: 36)\r\n * @returns the updated Path2.\r\n */\r\n public addArcTo(midX: number, midY: number, endX: number, endY: number, numberOfSegments = 36): Path2 {\r\n if (this.closed) {\r\n return this;\r\n }\r\n const startPoint = this._points[this._points.length - 1];\r\n const midPoint = new Vector2(midX, midY);\r\n const endPoint = new Vector2(endX, endY);\r\n\r\n const arc = new Arc2(startPoint, midPoint, endPoint);\r\n\r\n let increment = arc.angle.radians() / numberOfSegments;\r\n if (arc.orientation === Orientation.CW) {\r\n increment *= -1;\r\n }\r\n let currentAngle = arc.startAngle.radians() + increment;\r\n\r\n for (let i = 0; i < numberOfSegments; i++) {\r\n const x = Math.cos(currentAngle) * arc.radius + arc.centerPoint.x;\r\n const y = Math.sin(currentAngle) * arc.radius + arc.centerPoint.y;\r\n this.addLineTo(x, y);\r\n currentAngle += increment;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds _numberOfSegments_ segments according to the quadratic curve definition to the current Path2.\r\n * @param controlX control point x value\r\n * @param controlY control point y value\r\n * @param endX end point x value\r\n * @param endY end point y value\r\n * @param numberOfSegments (default: 36)\r\n * @returns the updated Path2.\r\n */\r\n public addQuadraticCurveTo(controlX: number, controlY: number, endX: number, endY: number, numberOfSegments = 36): Path2 {\r\n if (this.closed) {\r\n return this;\r\n }\r\n\r\n const equation = (t: number, val0: number, val1: number, val2: number) => {\r\n const res = (1.0 - t) * (1.0 - t) * val0 + 2.0 * t * (1.0 - t) * val1 + t * t * val2;\r\n return res;\r\n };\r\n const startPoint = this._points[this._points.length - 1];\r\n for (let i = 0; i <= numberOfSegments; i++) {\r\n const step = i / numberOfSegments;\r\n const x = equation(step, startPoint.x, controlX, endX);\r\n const y = equation(step, startPoint.y, controlY, endY);\r\n this.addLineTo(x, y);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds _numberOfSegments_ segments according to the bezier curve definition to the current Path2.\r\n * @param originTangentX tangent vector at the origin point x value\r\n * @param originTangentY tangent vector at the origin point y value\r\n * @param destinationTangentX tangent vector at the destination point x value\r\n * @param destinationTangentY tangent vector at the destination point y value\r\n * @param endX end point x value\r\n * @param endY end point y value\r\n * @param numberOfSegments (default: 36)\r\n * @returns the updated Path2.\r\n */\r\n public addBezierCurveTo(\r\n originTangentX: number,\r\n originTangentY: number,\r\n destinationTangentX: number,\r\n destinationTangentY: number,\r\n endX: number,\r\n endY: number,\r\n numberOfSegments = 36\r\n ): Path2 {\r\n if (this.closed) {\r\n return this;\r\n }\r\n\r\n const equation = (t: number, val0: number, val1: number, val2: number, val3: number) => {\r\n const res = (1.0 - t) * (1.0 - t) * (1.0 - t) * val0 + 3.0 * t * (1.0 - t) * (1.0 - t) * val1 + 3.0 * t * t * (1.0 - t) * val2 + t * t * t * val3;\r\n return res;\r\n };\r\n const startPoint = this._points[this._points.length - 1];\r\n for (let i = 0; i <= numberOfSegments; i++) {\r\n const step = i / numberOfSegments;\r\n const x = equation(step, startPoint.x, originTangentX, destinationTangentX, endX);\r\n const y = equation(step, startPoint.y, originTangentY, destinationTangentY, endY);\r\n this.addLineTo(x, y);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Defines if a given point is inside the polygon defines by the path\r\n * @param point defines the point to test\r\n * @returns true if the point is inside\r\n */\r\n public isPointInside(point: Vector2) {\r\n let isInside = false;\r\n const count = this._points.length;\r\n for (let p = count - 1, q = 0; q < count; p = q++) {\r\n let edgeLow = this._points[p];\r\n let edgeHigh = this._points[q];\r\n\r\n let edgeDx = edgeHigh.x - edgeLow.x;\r\n let edgeDy = edgeHigh.y - edgeLow.y;\r\n\r\n if (Math.abs(edgeDy) > Number.EPSILON) {\r\n // Not parallel\r\n if (edgeDy < 0) {\r\n edgeLow = this._points[q];\r\n edgeDx = -edgeDx;\r\n edgeHigh = this._points[p];\r\n edgeDy = -edgeDy;\r\n }\r\n\r\n if (point.y < edgeLow.y || point.y > edgeHigh.y) {\r\n continue;\r\n }\r\n\r\n if (point.y === edgeLow.y && point.x === edgeLow.x) {\r\n return true;\r\n } else {\r\n const perpEdge = edgeDy * (point.x - edgeLow.x) - edgeDx * (point.y - edgeLow.y);\r\n if (perpEdge === 0) {\r\n return true;\r\n }\r\n if (perpEdge < 0) {\r\n continue;\r\n }\r\n isInside = !isInside;\r\n }\r\n } else {\r\n // parallel or collinear\r\n if (point.y !== edgeLow.y) {\r\n continue;\r\n }\r\n\r\n if ((edgeHigh.x <= point.x && point.x <= edgeLow.x) || (edgeLow.x <= point.x && point.x <= edgeHigh.x)) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return isInside;\r\n }\r\n\r\n /**\r\n * Closes the Path2.\r\n * @returns the Path2.\r\n */\r\n public close(): Path2 {\r\n this.closed = true;\r\n return this;\r\n }\r\n /**\r\n * Gets the sum of the distance between each sequential point in the path\r\n * @returns the Path2 total length (float).\r\n */\r\n public length(): number {\r\n let result = this._length;\r\n\r\n if (this.closed) {\r\n const lastPoint = this._points[this._points.length - 1];\r\n const firstPoint = this._points[0];\r\n result += firstPoint.subtract(lastPoint).length();\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Gets the area of the polygon defined by the path\r\n * @returns area value\r\n */\r\n public area(): number {\r\n const n = this._points.length;\r\n let value = 0.0;\r\n\r\n for (let p = n - 1, q = 0; q < n; p = q++) {\r\n value += this._points[p].x * this._points[q].y - this._points[q].x * this._points[p].y;\r\n }\r\n\r\n return value * 0.5;\r\n }\r\n\r\n /**\r\n * Gets the points which construct the path\r\n * @returns the Path2 internal array of points.\r\n */\r\n public getPoints(): Vector2[] {\r\n return this._points;\r\n }\r\n\r\n /**\r\n * Retreives the point at the distance aways from the starting point\r\n * @param normalizedLengthPosition the length along the path to retrieve the point from\r\n * @returns a new Vector2 located at a percentage of the Path2 total length on this path.\r\n */\r\n public getPointAtLengthPosition(normalizedLengthPosition: number): Vector2 {\r\n if (normalizedLengthPosition < 0 || normalizedLengthPosition > 1) {\r\n return Vector2.Zero();\r\n }\r\n\r\n const lengthPosition = normalizedLengthPosition * this.length();\r\n\r\n let previousOffset = 0;\r\n for (let i = 0; i < this._points.length; i++) {\r\n const j = (i + 1) % this._points.length;\r\n\r\n const a = this._points[i];\r\n const b = this._points[j];\r\n const bToA = b.subtract(a);\r\n\r\n const nextOffset = bToA.length() + previousOffset;\r\n if (lengthPosition >= previousOffset && lengthPosition <= nextOffset) {\r\n const dir = bToA.normalize();\r\n const localOffset = lengthPosition - previousOffset;\r\n\r\n return new Vector2(a.x + dir.x * localOffset, a.y + dir.y * localOffset);\r\n }\r\n previousOffset = nextOffset;\r\n }\r\n\r\n return Vector2.Zero();\r\n }\r\n\r\n /**\r\n * Creates a new path starting from an x and y position\r\n * @param x starting x value\r\n * @param y starting y value\r\n * @returns a new Path2 starting at the coordinates (x, y).\r\n */\r\n public static StartingAt(x: number, y: number): Path2 {\r\n return new Path2(x, y);\r\n }\r\n}\r\n\r\n/**\r\n * Represents a 3D path made up of multiple 3D points\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D\r\n */\r\nexport class Path3D {\r\n private _curve = new Array();\r\n private _distances = new Array();\r\n private _tangents = new Array();\r\n private _normals = new Array();\r\n private _binormals = new Array();\r\n private _raw: boolean;\r\n private _alignTangentsWithPath: boolean;\r\n\r\n // holds interpolated point data\r\n private readonly _pointAtData = {\r\n id: 0,\r\n point: Vector3.Zero(),\r\n previousPointArrayIndex: 0,\r\n\r\n position: 0,\r\n subPosition: 0,\r\n\r\n interpolateReady: false,\r\n interpolationMatrix: Matrix.Identity(),\r\n };\r\n\r\n /**\r\n * new Path3D(path, normal, raw)\r\n * Creates a Path3D. A Path3D is a logical math object, so not a mesh.\r\n * please read the description in the tutorial : https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D\r\n * @param path an array of Vector3, the curve axis of the Path3D\r\n * @param firstNormal (options) Vector3, the first wanted normal to the curve. Ex (0, 1, 0) for a vertical normal.\r\n * @param raw (optional, default false) : boolean, if true the returned Path3D isn't normalized. Useful to depict path acceleration or speed.\r\n * @param alignTangentsWithPath (optional, default false) : boolean, if true the tangents will be aligned with the path.\r\n */\r\n constructor(\r\n /**\r\n * an array of Vector3, the curve axis of the Path3D\r\n */\r\n public path: Vector3[],\r\n firstNormal: Nullable = null,\r\n raw?: boolean,\r\n alignTangentsWithPath = false\r\n ) {\r\n for (let p = 0; p < path.length; p++) {\r\n this._curve[p] = path[p].clone(); // hard copy\r\n }\r\n this._raw = raw || false;\r\n this._alignTangentsWithPath = alignTangentsWithPath;\r\n this._compute(firstNormal, alignTangentsWithPath);\r\n }\r\n\r\n /**\r\n * Returns the Path3D array of successive Vector3 designing its curve.\r\n * @returns the Path3D array of successive Vector3 designing its curve.\r\n */\r\n public getCurve(): Vector3[] {\r\n return this._curve;\r\n }\r\n\r\n /**\r\n * Returns the Path3D array of successive Vector3 designing its curve.\r\n * @returns the Path3D array of successive Vector3 designing its curve.\r\n */\r\n public getPoints(): Vector3[] {\r\n return this._curve;\r\n }\r\n\r\n /**\r\n * @returns the computed length (float) of the path.\r\n */\r\n public length() {\r\n return this._distances[this._distances.length - 1];\r\n }\r\n\r\n /**\r\n * Returns an array populated with tangent vectors on each Path3D curve point.\r\n * @returns an array populated with tangent vectors on each Path3D curve point.\r\n */\r\n public getTangents(): Vector3[] {\r\n return this._tangents;\r\n }\r\n\r\n /**\r\n * Returns an array populated with normal vectors on each Path3D curve point.\r\n * @returns an array populated with normal vectors on each Path3D curve point.\r\n */\r\n public getNormals(): Vector3[] {\r\n return this._normals;\r\n }\r\n\r\n /**\r\n * Returns an array populated with binormal vectors on each Path3D curve point.\r\n * @returns an array populated with binormal vectors on each Path3D curve point.\r\n */\r\n public getBinormals(): Vector3[] {\r\n return this._binormals;\r\n }\r\n\r\n /**\r\n * Returns an array populated with distances (float) of the i-th point from the first curve point.\r\n * @returns an array populated with distances (float) of the i-th point from the first curve point.\r\n */\r\n public getDistances(): number[] {\r\n return this._distances;\r\n }\r\n\r\n /**\r\n * Returns an interpolated point along this path\r\n * @param position the position of the point along this path, from 0.0 to 1.0\r\n * @returns a new Vector3 as the point\r\n */\r\n public getPointAt(position: number): Vector3 {\r\n return this._updatePointAtData(position).point;\r\n }\r\n\r\n /**\r\n * Returns the tangent vector of an interpolated Path3D curve point at the specified position along this path.\r\n * @param position the position of the point along this path, from 0.0 to 1.0\r\n * @param interpolated (optional, default false) : boolean, if true returns an interpolated tangent instead of the tangent of the previous path point.\r\n * @returns a tangent vector corresponding to the interpolated Path3D curve point, if not interpolated, the tangent is taken from the precomputed tangents array.\r\n */\r\n public getTangentAt(position: number, interpolated = false): Vector3 {\r\n this._updatePointAtData(position, interpolated);\r\n return interpolated ? Vector3.TransformCoordinates(Vector3.Forward(), this._pointAtData.interpolationMatrix) : this._tangents[this._pointAtData.previousPointArrayIndex];\r\n }\r\n\r\n /**\r\n * Returns the tangent vector of an interpolated Path3D curve point at the specified position along this path.\r\n * @param position the position of the point along this path, from 0.0 to 1.0\r\n * @param interpolated (optional, default false) : boolean, if true returns an interpolated normal instead of the normal of the previous path point.\r\n * @returns a normal vector corresponding to the interpolated Path3D curve point, if not interpolated, the normal is taken from the precomputed normals array.\r\n */\r\n public getNormalAt(position: number, interpolated = false): Vector3 {\r\n this._updatePointAtData(position, interpolated);\r\n return interpolated ? Vector3.TransformCoordinates(Vector3.Right(), this._pointAtData.interpolationMatrix) : this._normals[this._pointAtData.previousPointArrayIndex];\r\n }\r\n\r\n /**\r\n * Returns the binormal vector of an interpolated Path3D curve point at the specified position along this path.\r\n * @param position the position of the point along this path, from 0.0 to 1.0\r\n * @param interpolated (optional, default false) : boolean, if true returns an interpolated binormal instead of the binormal of the previous path point.\r\n * @returns a binormal vector corresponding to the interpolated Path3D curve point, if not interpolated, the binormal is taken from the precomputed binormals array.\r\n */\r\n public getBinormalAt(position: number, interpolated = false): Vector3 {\r\n this._updatePointAtData(position, interpolated);\r\n return interpolated ? Vector3.TransformCoordinates(Vector3.UpReadOnly, this._pointAtData.interpolationMatrix) : this._binormals[this._pointAtData.previousPointArrayIndex];\r\n }\r\n\r\n /**\r\n * Returns the distance (float) of an interpolated Path3D curve point at the specified position along this path.\r\n * @param position the position of the point along this path, from 0.0 to 1.0\r\n * @returns the distance of the interpolated Path3D curve point at the specified position along this path.\r\n */\r\n public getDistanceAt(position: number): number {\r\n return this.length() * position;\r\n }\r\n\r\n /**\r\n * Returns the array index of the previous point of an interpolated point along this path\r\n * @param position the position of the point to interpolate along this path, from 0.0 to 1.0\r\n * @returns the array index\r\n */\r\n public getPreviousPointIndexAt(position: number) {\r\n this._updatePointAtData(position);\r\n return this._pointAtData.previousPointArrayIndex;\r\n }\r\n\r\n /**\r\n * Returns the position of an interpolated point relative to the two path points it lies between, from 0.0 (point A) to 1.0 (point B)\r\n * @param position the position of the point to interpolate along this path, from 0.0 to 1.0\r\n * @returns the sub position\r\n */\r\n public getSubPositionAt(position: number) {\r\n this._updatePointAtData(position);\r\n return this._pointAtData.subPosition;\r\n }\r\n\r\n /**\r\n * Returns the position of the closest virtual point on this path to an arbitrary Vector3, from 0.0 to 1.0\r\n * @param target the vector of which to get the closest position to\r\n * @returns the position of the closest virtual point on this path to the target vector\r\n */\r\n public getClosestPositionTo(target: Vector3) {\r\n let smallestDistance = Number.MAX_VALUE;\r\n let closestPosition = 0.0;\r\n for (let i = 0; i < this._curve.length - 1; i++) {\r\n const point = this._curve[i + 0];\r\n const tangent = this._curve[i + 1].subtract(point).normalize();\r\n const subLength = this._distances[i + 1] - this._distances[i + 0];\r\n const subPosition = Math.min((Math.max(Vector3.Dot(tangent, target.subtract(point).normalize()), 0.0) * Vector3.Distance(point, target)) / subLength, 1.0);\r\n const distance = Vector3.Distance(point.add(tangent.scale(subPosition * subLength)), target);\r\n\r\n if (distance < smallestDistance) {\r\n smallestDistance = distance;\r\n closestPosition = (this._distances[i + 0] + subLength * subPosition) / this.length();\r\n }\r\n }\r\n return closestPosition;\r\n }\r\n\r\n /**\r\n * Returns a sub path (slice) of this path\r\n * @param start the position of the fist path point, from 0.0 to 1.0, or a negative value, which will get wrapped around from the end of the path to 0.0 to 1.0 values\r\n * @param end the position of the last path point, from 0.0 to 1.0, or a negative value, which will get wrapped around from the end of the path to 0.0 to 1.0 values\r\n * @returns a sub path (slice) of this path\r\n */\r\n public slice(start: number = 0.0, end: number = 1.0) {\r\n if (start < 0.0) {\r\n start = 1 - ((start * -1.0) % 1.0);\r\n }\r\n if (end < 0.0) {\r\n end = 1 - ((end * -1.0) % 1.0);\r\n }\r\n if (start > end) {\r\n const _start = start;\r\n start = end;\r\n end = _start;\r\n }\r\n const curvePoints = this.getCurve();\r\n\r\n const startPoint = this.getPointAt(start);\r\n let startIndex = this.getPreviousPointIndexAt(start);\r\n\r\n const endPoint = this.getPointAt(end);\r\n const endIndex = this.getPreviousPointIndexAt(end) + 1;\r\n\r\n const slicePoints: Vector3[] = [];\r\n if (start !== 0.0) {\r\n startIndex++;\r\n slicePoints.push(startPoint);\r\n }\r\n\r\n slicePoints.push(...curvePoints.slice(startIndex, endIndex));\r\n if (end !== 1.0 || start === 1.0) {\r\n slicePoints.push(endPoint);\r\n }\r\n return new Path3D(slicePoints, this.getNormalAt(start), this._raw, this._alignTangentsWithPath);\r\n }\r\n\r\n /**\r\n * Forces the Path3D tangent, normal, binormal and distance recomputation.\r\n * @param path path which all values are copied into the curves points\r\n * @param firstNormal which should be projected onto the curve\r\n * @param alignTangentsWithPath (optional, default false) : boolean, if true the tangents will be aligned with the path\r\n * @returns the same object updated.\r\n */\r\n public update(path: Vector3[], firstNormal: Nullable = null, alignTangentsWithPath = false): Path3D {\r\n for (let p = 0; p < path.length; p++) {\r\n this._curve[p].x = path[p].x;\r\n this._curve[p].y = path[p].y;\r\n this._curve[p].z = path[p].z;\r\n }\r\n this._compute(firstNormal, alignTangentsWithPath);\r\n return this;\r\n }\r\n\r\n // private function compute() : computes tangents, normals and binormals\r\n private _compute(firstNormal: Nullable, alignTangentsWithPath = false): void {\r\n const l = this._curve.length;\r\n\r\n if (l < 2) {\r\n return;\r\n }\r\n\r\n // first and last tangents\r\n this._tangents[0] = this._getFirstNonNullVector(0);\r\n if (!this._raw) {\r\n this._tangents[0].normalize();\r\n }\r\n this._tangents[l - 1] = this._curve[l - 1].subtract(this._curve[l - 2]);\r\n if (!this._raw) {\r\n this._tangents[l - 1].normalize();\r\n }\r\n\r\n // normals and binormals at first point : arbitrary vector with _normalVector()\r\n const tg0 = this._tangents[0];\r\n const pp0 = this._normalVector(tg0, firstNormal);\r\n this._normals[0] = pp0;\r\n if (!this._raw) {\r\n this._normals[0].normalize();\r\n }\r\n this._binormals[0] = Vector3.Cross(tg0, this._normals[0]);\r\n if (!this._raw) {\r\n this._binormals[0].normalize();\r\n }\r\n this._distances[0] = 0.0;\r\n\r\n // normals and binormals : next points\r\n let prev: Vector3; // previous vector (segment)\r\n let cur: Vector3; // current vector (segment)\r\n let curTang: Vector3; // current tangent\r\n // previous normal\r\n let prevNor: Vector3; // previous normal\r\n let prevBinor: Vector3; // previous binormal\r\n\r\n for (let i = 1; i < l; i++) {\r\n // tangents\r\n prev = this._getLastNonNullVector(i);\r\n if (i < l - 1) {\r\n cur = this._getFirstNonNullVector(i);\r\n this._tangents[i] = alignTangentsWithPath ? cur : prev.add(cur);\r\n this._tangents[i].normalize();\r\n }\r\n this._distances[i] = this._distances[i - 1] + this._curve[i].subtract(this._curve[i - 1]).length();\r\n\r\n // normals and binormals\r\n // http://www.cs.cmu.edu/afs/andrew/scs/cs/15-462/web/old/asst2camera.html\r\n curTang = this._tangents[i];\r\n prevBinor = this._binormals[i - 1];\r\n this._normals[i] = Vector3.Cross(prevBinor, curTang);\r\n if (!this._raw) {\r\n if (this._normals[i].length() === 0) {\r\n prevNor = this._normals[i - 1];\r\n this._normals[i] = prevNor.clone();\r\n } else {\r\n this._normals[i].normalize();\r\n }\r\n }\r\n this._binormals[i] = Vector3.Cross(curTang, this._normals[i]);\r\n if (!this._raw) {\r\n this._binormals[i].normalize();\r\n }\r\n }\r\n this._pointAtData.id = NaN;\r\n }\r\n\r\n // private function getFirstNonNullVector(index)\r\n // returns the first non null vector from index : curve[index + N].subtract(curve[index])\r\n private _getFirstNonNullVector(index: number): Vector3 {\r\n let i = 1;\r\n let nNVector: Vector3 = this._curve[index + i].subtract(this._curve[index]);\r\n while (nNVector.length() === 0 && index + i + 1 < this._curve.length) {\r\n i++;\r\n nNVector = this._curve[index + i].subtract(this._curve[index]);\r\n }\r\n return nNVector;\r\n }\r\n\r\n // private function getLastNonNullVector(index)\r\n // returns the last non null vector from index : curve[index].subtract(curve[index - N])\r\n private _getLastNonNullVector(index: number): Vector3 {\r\n let i = 1;\r\n let nLVector: Vector3 = this._curve[index].subtract(this._curve[index - i]);\r\n while (nLVector.length() === 0 && index > i + 1) {\r\n i++;\r\n nLVector = this._curve[index].subtract(this._curve[index - i]);\r\n }\r\n return nLVector;\r\n }\r\n\r\n // private function normalVector(v0, vt, va) :\r\n // returns an arbitrary point in the plane defined by the point v0 and the vector vt orthogonal to this plane\r\n // if va is passed, it returns the va projection on the plane orthogonal to vt at the point v0\r\n private _normalVector(vt: Vector3, va: Nullable): Vector3 {\r\n let normal0: Vector3;\r\n let tgl = vt.length();\r\n if (tgl === 0.0) {\r\n tgl = 1.0;\r\n }\r\n\r\n if (va === undefined || va === null) {\r\n let point: Vector3;\r\n if (!Scalar.WithinEpsilon(Math.abs(vt.y) / tgl, 1.0, Epsilon)) {\r\n // search for a point in the plane\r\n point = new Vector3(0.0, -1.0, 0.0);\r\n } else if (!Scalar.WithinEpsilon(Math.abs(vt.x) / tgl, 1.0, Epsilon)) {\r\n point = new Vector3(1.0, 0.0, 0.0);\r\n } else if (!Scalar.WithinEpsilon(Math.abs(vt.z) / tgl, 1.0, Epsilon)) {\r\n point = new Vector3(0.0, 0.0, 1.0);\r\n } else {\r\n point = Vector3.Zero();\r\n }\r\n normal0 = Vector3.Cross(vt, point);\r\n } else {\r\n normal0 = Vector3.Cross(vt, va);\r\n Vector3.CrossToRef(normal0, vt, normal0);\r\n }\r\n normal0.normalize();\r\n return normal0;\r\n }\r\n\r\n /**\r\n * Updates the point at data for an interpolated point along this curve\r\n * @param position the position of the point along this curve, from 0.0 to 1.0\r\n * @param interpolateTNB\r\n * @interpolateTNB whether to compute the interpolated tangent, normal and binormal\r\n * @returns the (updated) point at data\r\n */\r\n private _updatePointAtData(position: number, interpolateTNB: boolean = false) {\r\n // set an id for caching the result\r\n if (this._pointAtData.id === position) {\r\n if (!this._pointAtData.interpolateReady) {\r\n this._updateInterpolationMatrix();\r\n }\r\n return this._pointAtData;\r\n } else {\r\n this._pointAtData.id = position;\r\n }\r\n const curvePoints = this.getPoints();\r\n\r\n // clamp position between 0.0 and 1.0\r\n if (position <= 0.0) {\r\n return this._setPointAtData(0.0, 0.0, curvePoints[0], 0, interpolateTNB);\r\n } else if (position >= 1.0) {\r\n return this._setPointAtData(1.0, 1.0, curvePoints[curvePoints.length - 1], curvePoints.length - 1, interpolateTNB);\r\n }\r\n\r\n let previousPoint: Vector3 = curvePoints[0];\r\n let currentPoint: Vector3;\r\n let currentLength = 0.0;\r\n const targetLength = position * this.length();\r\n\r\n for (let i = 1; i < curvePoints.length; i++) {\r\n currentPoint = curvePoints[i];\r\n const distance = Vector3.Distance(previousPoint, currentPoint);\r\n currentLength += distance;\r\n if (currentLength === targetLength) {\r\n return this._setPointAtData(position, 1.0, currentPoint, i, interpolateTNB);\r\n } else if (currentLength > targetLength) {\r\n const toLength = currentLength - targetLength;\r\n const diff = toLength / distance;\r\n const dir = previousPoint.subtract(currentPoint);\r\n const point = currentPoint.add(dir.scaleInPlace(diff));\r\n return this._setPointAtData(position, 1 - diff, point, i - 1, interpolateTNB);\r\n }\r\n previousPoint = currentPoint;\r\n }\r\n return this._pointAtData;\r\n }\r\n\r\n /**\r\n * Updates the point at data from the specified parameters\r\n * @param position where along the path the interpolated point is, from 0.0 to 1.0\r\n * @param subPosition\r\n * @param point the interpolated point\r\n * @param parentIndex the index of an existing curve point that is on, or else positionally the first behind, the interpolated point\r\n * @param interpolateTNB\r\n */\r\n private _setPointAtData(position: number, subPosition: number, point: Vector3, parentIndex: number, interpolateTNB: boolean) {\r\n this._pointAtData.point = point;\r\n this._pointAtData.position = position;\r\n this._pointAtData.subPosition = subPosition;\r\n this._pointAtData.previousPointArrayIndex = parentIndex;\r\n this._pointAtData.interpolateReady = interpolateTNB;\r\n\r\n if (interpolateTNB) {\r\n this._updateInterpolationMatrix();\r\n }\r\n return this._pointAtData;\r\n }\r\n\r\n /**\r\n * Updates the point at interpolation matrix for the tangents, normals and binormals\r\n */\r\n private _updateInterpolationMatrix() {\r\n this._pointAtData.interpolationMatrix = Matrix.Identity();\r\n const parentIndex = this._pointAtData.previousPointArrayIndex;\r\n\r\n if (parentIndex !== this._tangents.length - 1) {\r\n const index = parentIndex + 1;\r\n\r\n const tangentFrom = this._tangents[parentIndex].clone();\r\n const normalFrom = this._normals[parentIndex].clone();\r\n const binormalFrom = this._binormals[parentIndex].clone();\r\n\r\n const tangentTo = this._tangents[index].clone();\r\n const normalTo = this._normals[index].clone();\r\n const binormalTo = this._binormals[index].clone();\r\n\r\n const quatFrom = Quaternion.RotationQuaternionFromAxis(normalFrom, binormalFrom, tangentFrom);\r\n const quatTo = Quaternion.RotationQuaternionFromAxis(normalTo, binormalTo, tangentTo);\r\n const quatAt = Quaternion.Slerp(quatFrom, quatTo, this._pointAtData.subPosition);\r\n\r\n quatAt.toRotationMatrix(this._pointAtData.interpolationMatrix);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.\r\n * A Curve3 is designed from a series of successive Vector3.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves\r\n */\r\nexport class Curve3 {\r\n private _points: Vector3[];\r\n private _length: number = 0.0;\r\n\r\n /**\r\n * Returns a Curve3 object along a Quadratic Bezier curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#quadratic-bezier-curve\r\n * @param v0 (Vector3) the origin point of the Quadratic Bezier\r\n * @param v1 (Vector3) the control point\r\n * @param v2 (Vector3) the end point of the Quadratic Bezier\r\n * @param nbPoints (integer) the wanted number of points in the curve\r\n * @returns the created Curve3\r\n */\r\n public static CreateQuadraticBezier(v0: DeepImmutable, v1: DeepImmutable, v2: DeepImmutable, nbPoints: number): Curve3 {\r\n nbPoints = nbPoints > 2 ? nbPoints : 3;\r\n const bez = new Array();\r\n const equation = (t: number, val0: number, val1: number, val2: number) => {\r\n const res = (1.0 - t) * (1.0 - t) * val0 + 2.0 * t * (1.0 - t) * val1 + t * t * val2;\r\n return res;\r\n };\r\n for (let i = 0; i <= nbPoints; i++) {\r\n bez.push(new Vector3(equation(i / nbPoints, v0.x, v1.x, v2.x), equation(i / nbPoints, v0.y, v1.y, v2.y), equation(i / nbPoints, v0.z, v1.z, v2.z)));\r\n }\r\n return new Curve3(bez);\r\n }\r\n\r\n /**\r\n * Returns a Curve3 object along a Cubic Bezier curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#cubic-bezier-curve\r\n * @param v0 (Vector3) the origin point of the Cubic Bezier\r\n * @param v1 (Vector3) the first control point\r\n * @param v2 (Vector3) the second control point\r\n * @param v3 (Vector3) the end point of the Cubic Bezier\r\n * @param nbPoints (integer) the wanted number of points in the curve\r\n * @returns the created Curve3\r\n */\r\n public static CreateCubicBezier(v0: DeepImmutable, v1: DeepImmutable, v2: DeepImmutable, v3: DeepImmutable, nbPoints: number): Curve3 {\r\n nbPoints = nbPoints > 3 ? nbPoints : 4;\r\n const bez = new Array();\r\n const equation = (t: number, val0: number, val1: number, val2: number, val3: number) => {\r\n const res = (1.0 - t) * (1.0 - t) * (1.0 - t) * val0 + 3.0 * t * (1.0 - t) * (1.0 - t) * val1 + 3.0 * t * t * (1.0 - t) * val2 + t * t * t * val3;\r\n return res;\r\n };\r\n for (let i = 0; i <= nbPoints; i++) {\r\n bez.push(new Vector3(equation(i / nbPoints, v0.x, v1.x, v2.x, v3.x), equation(i / nbPoints, v0.y, v1.y, v2.y, v3.y), equation(i / nbPoints, v0.z, v1.z, v2.z, v3.z)));\r\n }\r\n return new Curve3(bez);\r\n }\r\n\r\n /**\r\n * Returns a Curve3 object along a Hermite Spline curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-spline\r\n * @param p1 (Vector3) the origin point of the Hermite Spline\r\n * @param t1 (Vector3) the tangent vector at the origin point\r\n * @param p2 (Vector3) the end point of the Hermite Spline\r\n * @param t2 (Vector3) the tangent vector at the end point\r\n * @param nSeg (integer) the number of curve segments or nSeg + 1 points in the array\r\n * @returns the created Curve3\r\n */\r\n public static CreateHermiteSpline(p1: DeepImmutable, t1: DeepImmutable, p2: DeepImmutable, t2: DeepImmutable, nSeg: number): Curve3 {\r\n const hermite = new Array();\r\n const step = 1.0 / nSeg;\r\n for (let i = 0; i <= nSeg; i++) {\r\n hermite.push(Vector3.Hermite(p1, t1, p2, t2, i * step));\r\n }\r\n return new Curve3(hermite);\r\n }\r\n\r\n /**\r\n * Returns a Curve3 object along a CatmullRom Spline curve :\r\n * @param points (array of Vector3) the points the spline must pass through. At least, four points required\r\n * @param nbPoints (integer) the wanted number of points between each curve control points\r\n * @param closed (boolean) optional with default false, when true forms a closed loop from the points\r\n * @returns the created Curve3\r\n */\r\n public static CreateCatmullRomSpline(points: DeepImmutable, nbPoints: number, closed?: boolean): Curve3 {\r\n const catmullRom = new Array();\r\n const step = 1.0 / nbPoints;\r\n let amount = 0.0;\r\n if (closed) {\r\n const pointsCount = points.length;\r\n for (let i = 0; i < pointsCount; i++) {\r\n amount = 0;\r\n for (let c = 0; c < nbPoints; c++) {\r\n catmullRom.push(\r\n Vector3.CatmullRom(points[i % pointsCount], points[(i + 1) % pointsCount], points[(i + 2) % pointsCount], points[(i + 3) % pointsCount], amount)\r\n );\r\n amount += step;\r\n }\r\n }\r\n catmullRom.push(catmullRom[0]);\r\n } else {\r\n const totalPoints = new Array();\r\n totalPoints.push(points[0].clone());\r\n Array.prototype.push.apply(totalPoints, points);\r\n totalPoints.push(points[points.length - 1].clone());\r\n let i = 0;\r\n for (; i < totalPoints.length - 3; i++) {\r\n amount = 0;\r\n for (let c = 0; c < nbPoints; c++) {\r\n catmullRom.push(Vector3.CatmullRom(totalPoints[i], totalPoints[i + 1], totalPoints[i + 2], totalPoints[i + 3], amount));\r\n amount += step;\r\n }\r\n }\r\n i--;\r\n catmullRom.push(Vector3.CatmullRom(totalPoints[i], totalPoints[i + 1], totalPoints[i + 2], totalPoints[i + 3], amount));\r\n }\r\n return new Curve3(catmullRom);\r\n }\r\n\r\n /**\r\n * Returns a Curve3 object along an arc through three vector3 points:\r\n * The three points should not be colinear. When they are the Curve3 is empty.\r\n * @param first (Vector3) the first point the arc must pass through.\r\n * @param second (Vector3) the second point the arc must pass through.\r\n * @param third (Vector3) the third point the arc must pass through.\r\n * @param steps (number) the larger the number of steps the more detailed the arc.\r\n * @param closed (boolean) optional with default false, when true forms the chord from the first and third point\r\n * @param fullCircle Circle (boolean) optional with default false, when true forms the complete circle through the three points\r\n * @returns the created Curve3\r\n */\r\n public static ArcThru3Points(first: Vector3, second: Vector3, third: Vector3, steps: number = 32, closed: boolean = false, fullCircle: boolean = false): Curve3 {\r\n const arc = new Array();\r\n const vec1 = second.subtract(first);\r\n const vec2 = third.subtract(second);\r\n const vec3 = first.subtract(third);\r\n const zAxis = Vector3.Cross(vec1, vec2);\r\n const len4 = zAxis.length();\r\n if (len4 < Math.pow(10, -8)) {\r\n return new Curve3(arc); // colinear points arc is empty\r\n }\r\n const len1_sq = vec1.lengthSquared();\r\n const len2_sq = vec2.lengthSquared();\r\n const len3_sq = vec3.lengthSquared();\r\n const len4_sq = zAxis.lengthSquared();\r\n const len1 = vec1.length();\r\n const len2 = vec2.length();\r\n const len3 = vec3.length();\r\n const radius = (0.5 * len1 * len2 * len3) / len4;\r\n const dot1 = Vector3.Dot(vec1, vec3);\r\n const dot2 = Vector3.Dot(vec1, vec2);\r\n const dot3 = Vector3.Dot(vec2, vec3);\r\n const a = (-0.5 * len2_sq * dot1) / len4_sq;\r\n const b = (-0.5 * len3_sq * dot2) / len4_sq;\r\n const c = (-0.5 * len1_sq * dot3) / len4_sq;\r\n const center = first.scale(a).add(second.scale(b)).add(third.scale(c));\r\n const radiusVec = first.subtract(center);\r\n const xAxis = radiusVec.normalize();\r\n const yAxis = Vector3.Cross(zAxis, xAxis).normalize();\r\n if (fullCircle) {\r\n const dStep = (2 * Math.PI) / steps;\r\n for (let theta = 0; theta <= 2 * Math.PI; theta += dStep) {\r\n arc.push(center.add(xAxis.scale(radius * Math.cos(theta)).add(yAxis.scale(radius * Math.sin(theta)))));\r\n }\r\n arc.push(first);\r\n } else {\r\n const dStep = 1 / steps;\r\n let theta = 0;\r\n let point = Vector3.Zero();\r\n do {\r\n point = center.add(xAxis.scale(radius * Math.cos(theta)).add(yAxis.scale(radius * Math.sin(theta))));\r\n arc.push(point);\r\n theta += dStep;\r\n } while (!point.equalsWithEpsilon(third, radius * dStep * 1.1));\r\n arc.push(third);\r\n if (closed) {\r\n arc.push(first);\r\n }\r\n }\r\n return new Curve3(arc);\r\n }\r\n\r\n /**\r\n * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.\r\n * A Curve3 is designed from a series of successive Vector3.\r\n * Tuto : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#curve3-object\r\n * @param points points which make up the curve\r\n */\r\n constructor(points: Vector3[]) {\r\n this._points = points;\r\n this._length = this._computeLength(points);\r\n }\r\n\r\n /**\r\n * @returns the Curve3 stored array of successive Vector3\r\n */\r\n public getPoints() {\r\n return this._points;\r\n }\r\n\r\n /**\r\n * @returns the computed length (float) of the curve.\r\n */\r\n public length() {\r\n return this._length;\r\n }\r\n\r\n /**\r\n * Returns a new instance of Curve3 object : var curve = curveA.continue(curveB);\r\n * This new Curve3 is built by translating and sticking the curveB at the end of the curveA.\r\n * curveA and curveB keep unchanged.\r\n * @param curve the curve to continue from this curve\r\n * @returns the newly constructed curve\r\n */\r\n public continue(curve: DeepImmutable): Curve3 {\r\n const lastPoint = this._points[this._points.length - 1];\r\n const continuedPoints = this._points.slice();\r\n const curvePoints = curve.getPoints();\r\n for (let i = 1; i < curvePoints.length; i++) {\r\n continuedPoints.push(curvePoints[i].subtract(curvePoints[0]).add(lastPoint));\r\n }\r\n const continuedCurve = new Curve3(continuedPoints);\r\n return continuedCurve;\r\n }\r\n\r\n private _computeLength(path: DeepImmutable): number {\r\n let l = 0;\r\n for (let i = 1; i < path.length; i++) {\r\n l += path[i].subtract(path[i - 1]).length();\r\n }\r\n return l;\r\n }\r\n}\r\n","/**\r\n * Defines an interface which represents an animation key frame\r\n */\r\nexport interface IAnimationKey {\r\n /**\r\n * Frame of the key frame\r\n */\r\n frame: number;\r\n /**\r\n * Value at the specifies key frame\r\n */\r\n value: any;\r\n /**\r\n * The input tangent for the cubic hermite spline\r\n */\r\n inTangent?: any;\r\n /**\r\n * The output tangent for the cubic hermite spline\r\n */\r\n outTangent?: any;\r\n /**\r\n * The animation interpolation type\r\n */\r\n interpolation?: AnimationKeyInterpolation;\r\n /**\r\n * Property defined by UI tools to link (or not ) the tangents\r\n */\r\n lockedTangent?: boolean;\r\n}\r\n\r\n/**\r\n * Enum for the animation key frame interpolation type\r\n */\r\nexport enum AnimationKeyInterpolation {\r\n /**\r\n * Use tangents to interpolate between start and end values.\r\n */\r\n NONE = 0,\r\n /**\r\n * Do not interpolate between keys and use the start key value only. Tangents are ignored\r\n */\r\n STEP = 1,\r\n}\r\n","import { serialize, SerializationHelper } from \"../Misc/decorators\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { Geometry } from \"../Meshes/geometry\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { Effect } from \"./effect\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { IInspectable } from \"../Misc/iInspectable\";\r\nimport { Plane } from \"../Maths/math.plane\";\r\nimport type { ShadowDepthWrapper } from \"./shadowDepthWrapper\";\r\nimport { MaterialHelper } from \"./materialHelper\";\r\nimport type { IMaterialContext } from \"../Engines/IMaterialContext\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport { MaterialStencilState } from \"./materialStencilState\";\r\nimport { ScenePerformancePriority } from \"../scene\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractScene } from \"../abstractScene\";\r\nimport type {\r\n MaterialPluginDisposed,\r\n MaterialPluginIsReadyForSubMesh,\r\n MaterialPluginGetDefineNames,\r\n MaterialPluginBindForSubMesh,\r\n MaterialPluginGetActiveTextures,\r\n MaterialPluginHasTexture,\r\n MaterialPluginGetAnimatables,\r\n MaterialPluginPrepareDefines,\r\n MaterialPluginPrepareEffect,\r\n MaterialPluginPrepareUniformBuffer,\r\n MaterialPluginCreated,\r\n MaterialPluginFillRenderTargetTextures,\r\n MaterialPluginHasRenderTargetTextures,\r\n MaterialPluginHardBindForSubMesh,\r\n} from \"./materialPluginEvent\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport type { ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { IClipPlanesHolder } from \"../Misc/interfaces/iClipPlanesHolder\";\r\n\r\nimport type { PrePassRenderer } from \"../Rendering/prePassRenderer\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { Animation } from \"../Animations/animation\";\r\nimport type { InstancedMesh } from \"../Meshes/instancedMesh\";\r\n\r\ndeclare let BABYLON: any;\r\n\r\n/**\r\n * Options for compiling materials.\r\n */\r\nexport interface IMaterialCompilationOptions {\r\n /**\r\n * Defines whether clip planes are enabled.\r\n */\r\n clipPlane: boolean;\r\n\r\n /**\r\n * Defines whether instances are enabled.\r\n */\r\n useInstances: boolean;\r\n}\r\n\r\n/**\r\n * Options passed when calling customShaderNameResolve\r\n */\r\nexport interface ICustomShaderNameResolveOptions {\r\n /**\r\n * If provided, will be called two times with the vertex and fragment code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable;\r\n}\r\n\r\n/**\r\n * Base class for the main features of a material in Babylon.js\r\n */\r\nexport class Material implements IAnimatable, IClipPlanesHolder {\r\n /**\r\n * Returns the triangle fill mode\r\n */\r\n public static readonly TriangleFillMode = Constants.MATERIAL_TriangleFillMode;\r\n /**\r\n * Returns the wireframe mode\r\n */\r\n public static readonly WireFrameFillMode = Constants.MATERIAL_WireFrameFillMode;\r\n /**\r\n * Returns the point fill mode\r\n */\r\n public static readonly PointFillMode = Constants.MATERIAL_PointFillMode;\r\n /**\r\n * Returns the point list draw mode\r\n */\r\n public static readonly PointListDrawMode = Constants.MATERIAL_PointListDrawMode;\r\n /**\r\n * Returns the line list draw mode\r\n */\r\n public static readonly LineListDrawMode = Constants.MATERIAL_LineListDrawMode;\r\n /**\r\n * Returns the line loop draw mode\r\n */\r\n public static readonly LineLoopDrawMode = Constants.MATERIAL_LineLoopDrawMode;\r\n /**\r\n * Returns the line strip draw mode\r\n */\r\n public static readonly LineStripDrawMode = Constants.MATERIAL_LineStripDrawMode;\r\n /**\r\n * Returns the triangle strip draw mode\r\n */\r\n public static readonly TriangleStripDrawMode = Constants.MATERIAL_TriangleStripDrawMode;\r\n /**\r\n * Returns the triangle fan draw mode\r\n */\r\n public static readonly TriangleFanDrawMode = Constants.MATERIAL_TriangleFanDrawMode;\r\n\r\n /**\r\n * Stores the clock-wise side orientation\r\n */\r\n public static readonly ClockWiseSideOrientation = Constants.MATERIAL_ClockWiseSideOrientation;\r\n\r\n /**\r\n * Stores the counter clock-wise side orientation\r\n */\r\n public static readonly CounterClockWiseSideOrientation = Constants.MATERIAL_CounterClockWiseSideOrientation;\r\n\r\n /**\r\n * The dirty texture flag value\r\n */\r\n public static readonly TextureDirtyFlag = Constants.MATERIAL_TextureDirtyFlag;\r\n\r\n /**\r\n * The dirty light flag value\r\n */\r\n public static readonly LightDirtyFlag = Constants.MATERIAL_LightDirtyFlag;\r\n\r\n /**\r\n * The dirty fresnel flag value\r\n */\r\n public static readonly FresnelDirtyFlag = Constants.MATERIAL_FresnelDirtyFlag;\r\n\r\n /**\r\n * The dirty attribute flag value\r\n */\r\n public static readonly AttributesDirtyFlag = Constants.MATERIAL_AttributesDirtyFlag;\r\n\r\n /**\r\n * The dirty misc flag value\r\n */\r\n public static readonly MiscDirtyFlag = Constants.MATERIAL_MiscDirtyFlag;\r\n\r\n /**\r\n * The dirty prepass flag value\r\n */\r\n public static readonly PrePassDirtyFlag = Constants.MATERIAL_PrePassDirtyFlag;\r\n\r\n /**\r\n * The all dirty flag value\r\n */\r\n public static readonly AllDirtyFlag = Constants.MATERIAL_AllDirtyFlag;\r\n\r\n /**\r\n * MaterialTransparencyMode: No transparency mode, Alpha channel is not use.\r\n */\r\n public static readonly MATERIAL_OPAQUE = 0;\r\n\r\n /**\r\n * MaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.\r\n */\r\n public static readonly MATERIAL_ALPHATEST = 1;\r\n\r\n /**\r\n * MaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\r\n */\r\n public static readonly MATERIAL_ALPHABLEND = 2;\r\n\r\n /**\r\n * MaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\r\n * They are also discarded below the alpha cutoff threshold to improve performances.\r\n */\r\n public static readonly MATERIAL_ALPHATESTANDBLEND = 3;\r\n\r\n /**\r\n * The Whiteout method is used to blend normals.\r\n * Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/\r\n */\r\n public static readonly MATERIAL_NORMALBLENDMETHOD_WHITEOUT = 0;\r\n\r\n /**\r\n * The Reoriented Normal Mapping method is used to blend normals.\r\n * Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/\r\n */\r\n public static readonly MATERIAL_NORMALBLENDMETHOD_RNM = 1;\r\n\r\n /**\r\n * Event observable which raises global events common to all materials (like MaterialPluginEvent.Created)\r\n */\r\n public static OnEventObservable = new Observable();\r\n\r\n /**\r\n * Custom callback helping to override the default shader used in the material.\r\n */\r\n public customShaderNameResolve: (\r\n shaderName: string,\r\n uniforms: string[],\r\n uniformBuffers: string[],\r\n samplers: string[],\r\n defines: MaterialDefines | string[],\r\n attributes?: string[],\r\n options?: ICustomShaderNameResolveOptions\r\n ) => string;\r\n\r\n /**\r\n * Custom shadow depth material to use for shadow rendering instead of the in-built one\r\n */\r\n public shadowDepthWrapper: Nullable = null;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the material is allowed (if supported) to do shader hot swapping.\r\n * This means that the material can keep using a previous shader while a new one is being compiled.\r\n * This is mostly used when shader parallel compilation is supported (true by default)\r\n */\r\n public allowShaderHotSwapping = true;\r\n\r\n /**\r\n * The ID of the material\r\n */\r\n @serialize()\r\n public id: string;\r\n\r\n /**\r\n * Gets or sets the unique id of the material\r\n */\r\n @serialize()\r\n public uniqueId: number;\r\n\r\n /** @internal */\r\n public _loadedUniqueId: string;\r\n\r\n /**\r\n * The name of the material\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Gets or sets user defined metadata\r\n */\r\n @serialize()\r\n public metadata: any = null;\r\n\r\n /** @internal */\r\n public _internalMetadata: any;\r\n\r\n /**\r\n * For internal use only. Please do not use.\r\n */\r\n public reservedDataStore: any = null;\r\n\r\n /**\r\n * Specifies if the ready state should be checked on each call\r\n */\r\n @serialize()\r\n public checkReadyOnEveryCall = false;\r\n\r\n /**\r\n * Specifies if the ready state should be checked once\r\n */\r\n @serialize()\r\n public checkReadyOnlyOnce = false;\r\n\r\n /**\r\n * The state of the material\r\n */\r\n @serialize()\r\n public state = \"\";\r\n\r\n /**\r\n * If the material can be rendered to several textures with MRT extension\r\n */\r\n public get canRenderToMRT(): boolean {\r\n // By default, shaders are not compatible with MRTs\r\n // Base classes should override that if their shader supports MRT\r\n return false;\r\n }\r\n\r\n /**\r\n * The alpha value of the material\r\n */\r\n @serialize(\"alpha\")\r\n protected _alpha = 1.0;\r\n\r\n /**\r\n * List of inspectable custom properties (used by the Inspector)\r\n * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility\r\n */\r\n public inspectableCustomProperties: IInspectable[];\r\n\r\n /**\r\n * Sets the alpha value of the material\r\n */\r\n public set alpha(value: number) {\r\n if (this._alpha === value) {\r\n return;\r\n }\r\n\r\n const oldValue = this._alpha;\r\n this._alpha = value;\r\n\r\n // Only call dirty when there is a state change (no alpha / alpha)\r\n if (oldValue === 1 || value === 1) {\r\n this.markAsDirty(Material.MiscDirtyFlag + Material.PrePassDirtyFlag);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the alpha value of the material\r\n */\r\n public get alpha(): number {\r\n return this._alpha;\r\n }\r\n\r\n /**\r\n * Specifies if back face culling is enabled\r\n */\r\n @serialize(\"backFaceCulling\")\r\n protected _backFaceCulling = true;\r\n\r\n /**\r\n * Sets the culling state (true to enable culling, false to disable)\r\n */\r\n public set backFaceCulling(value: boolean) {\r\n if (this._backFaceCulling === value) {\r\n return;\r\n }\r\n this._backFaceCulling = value;\r\n this.markAsDirty(Material.TextureDirtyFlag);\r\n }\r\n\r\n /**\r\n * Gets the culling state\r\n */\r\n public get backFaceCulling(): boolean {\r\n return this._backFaceCulling;\r\n }\r\n\r\n /**\r\n * Specifies if back or front faces should be culled (when culling is enabled)\r\n */\r\n @serialize(\"cullBackFaces\")\r\n protected _cullBackFaces = true;\r\n\r\n /**\r\n * Sets the type of faces that should be culled (true for back faces, false for front faces)\r\n */\r\n public set cullBackFaces(value: boolean) {\r\n if (this._cullBackFaces === value) {\r\n return;\r\n }\r\n this._cullBackFaces = value;\r\n this.markAsDirty(Material.TextureDirtyFlag);\r\n }\r\n\r\n /**\r\n * Gets the type of faces that should be culled\r\n */\r\n public get cullBackFaces(): boolean {\r\n return this._cullBackFaces;\r\n }\r\n\r\n private _blockDirtyMechanism = false;\r\n\r\n /**\r\n * Block the dirty-mechanism for this specific material\r\n * When set to false after being true the material will be marked as dirty.\r\n */\r\n public get blockDirtyMechanism(): boolean {\r\n return this._blockDirtyMechanism;\r\n }\r\n\r\n public set blockDirtyMechanism(value: boolean) {\r\n if (this._blockDirtyMechanism === value) {\r\n return;\r\n }\r\n\r\n this._blockDirtyMechanism = value;\r\n\r\n if (!value) {\r\n this.markDirty();\r\n }\r\n }\r\n\r\n /**\r\n * This allows you to modify the material without marking it as dirty after every change.\r\n * This function should be used if you need to make more than one dirty-enabling change to the material - adding a texture, setting a new fill mode and so on.\r\n * The callback will pass the material as an argument, so you can make your changes to it.\r\n * @param callback the callback to be executed that will update the material\r\n */\r\n public atomicMaterialsUpdate(callback: (material: this) => void): void {\r\n this.blockDirtyMechanism = true;\r\n try {\r\n callback(this);\r\n } finally {\r\n this.blockDirtyMechanism = false;\r\n }\r\n }\r\n\r\n /**\r\n * Stores the value for side orientation\r\n */\r\n @serialize()\r\n public sideOrientation: number;\r\n\r\n /**\r\n * Callback triggered when the material is compiled\r\n */\r\n public onCompiled: Nullable<(effect: Effect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: Effect, errors: string) => void> = null;\r\n\r\n /**\r\n * Callback triggered to get the render target textures\r\n */\r\n public getRenderTargetTextures: Nullable<() => SmartArray> = null;\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n */\r\n public get hasRenderTargetTextures(): boolean {\r\n this._eventInfo.hasRenderTargetTextures = false;\r\n this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);\r\n return this._eventInfo.hasRenderTargetTextures;\r\n }\r\n\r\n /**\r\n * Specifies if the material should be serialized\r\n */\r\n public doNotSerialize = false;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _storeEffectOnSubMeshes = false;\r\n\r\n /**\r\n * Stores the animations for the material\r\n */\r\n public animations: Nullable> = null;\r\n\r\n /**\r\n * An event triggered when the material is disposed\r\n */\r\n public onDisposeObservable = new Observable();\r\n\r\n /**\r\n * An observer which watches for dispose events\r\n */\r\n private _onDisposeObserver: Nullable> = null;\r\n private _onUnBindObservable: Nullable> = null;\r\n\r\n /**\r\n * Called during a dispose event\r\n */\r\n public set onDispose(callback: () => void) {\r\n if (this._onDisposeObserver) {\r\n this.onDisposeObservable.remove(this._onDisposeObserver);\r\n }\r\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\r\n }\r\n\r\n private _onBindObservable: Nullable>;\r\n\r\n /**\r\n * An event triggered when the material is bound\r\n */\r\n public get onBindObservable(): Observable {\r\n if (!this._onBindObservable) {\r\n this._onBindObservable = new Observable();\r\n }\r\n\r\n return this._onBindObservable;\r\n }\r\n\r\n /**\r\n * An observer which watches for bind events\r\n */\r\n private _onBindObserver: Nullable> = null;\r\n\r\n /**\r\n * Called during a bind event\r\n */\r\n public set onBind(callback: (Mesh: AbstractMesh) => void) {\r\n if (this._onBindObserver) {\r\n this.onBindObservable.remove(this._onBindObserver);\r\n }\r\n this._onBindObserver = this.onBindObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when the material is unbound\r\n */\r\n public get onUnBindObservable(): Observable {\r\n if (!this._onUnBindObservable) {\r\n this._onUnBindObservable = new Observable();\r\n }\r\n\r\n return this._onUnBindObservable;\r\n }\r\n\r\n protected _onEffectCreatedObservable: Nullable }>>;\r\n\r\n /**\r\n * An event triggered when the effect is (re)created\r\n */\r\n public get onEffectCreatedObservable(): Observable<{ effect: Effect; subMesh: Nullable }> {\r\n if (!this._onEffectCreatedObservable) {\r\n this._onEffectCreatedObservable = new Observable<{ effect: Effect; subMesh: Nullable }>();\r\n }\r\n\r\n return this._onEffectCreatedObservable;\r\n }\r\n\r\n /**\r\n * Stores the value of the alpha mode\r\n */\r\n @serialize(\"alphaMode\")\r\n private _alphaMode: number = Constants.ALPHA_COMBINE;\r\n\r\n /**\r\n * Sets the value of the alpha mode.\r\n *\r\n * | Value | Type | Description |\r\n * | --- | --- | --- |\r\n * | 0 | ALPHA_DISABLE | |\r\n * | 1 | ALPHA_ADD | |\r\n * | 2 | ALPHA_COMBINE | |\r\n * | 3 | ALPHA_SUBTRACT | |\r\n * | 4 | ALPHA_MULTIPLY | |\r\n * | 5 | ALPHA_MAXIMIZED | |\r\n * | 6 | ALPHA_ONEONE | |\r\n * | 7 | ALPHA_PREMULTIPLIED | |\r\n * | 8 | ALPHA_PREMULTIPLIED_PORTERDUFF | |\r\n * | 9 | ALPHA_INTERPOLATE | |\r\n * | 10 | ALPHA_SCREENMODE | |\r\n *\r\n */\r\n public set alphaMode(value: number) {\r\n if (this._alphaMode === value) {\r\n return;\r\n }\r\n this._alphaMode = value;\r\n this.markAsDirty(Material.TextureDirtyFlag);\r\n }\r\n\r\n /**\r\n * Gets the value of the alpha mode\r\n */\r\n public get alphaMode(): number {\r\n return this._alphaMode;\r\n }\r\n\r\n /**\r\n * Stores the state of the need depth pre-pass value\r\n */\r\n @serialize()\r\n private _needDepthPrePass = false;\r\n\r\n /**\r\n * Sets the need depth pre-pass value\r\n */\r\n public set needDepthPrePass(value: boolean) {\r\n if (this._needDepthPrePass === value) {\r\n return;\r\n }\r\n this._needDepthPrePass = value;\r\n if (this._needDepthPrePass) {\r\n this.checkReadyOnEveryCall = true;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the depth pre-pass value\r\n */\r\n public get needDepthPrePass(): boolean {\r\n return this._needDepthPrePass;\r\n }\r\n\r\n /**\r\n * Can this material render to prepass\r\n */\r\n public get isPrePassCapable(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Specifies if depth writing should be disabled\r\n */\r\n @serialize()\r\n public disableDepthWrite = false;\r\n\r\n /**\r\n * Specifies if color writing should be disabled\r\n */\r\n @serialize()\r\n public disableColorWrite = false;\r\n\r\n /**\r\n * Specifies if depth writing should be forced\r\n */\r\n @serialize()\r\n public forceDepthWrite = false;\r\n\r\n /**\r\n * Specifies the depth function that should be used. 0 means the default engine function\r\n */\r\n @serialize()\r\n public depthFunction = 0;\r\n\r\n /**\r\n * Specifies if there should be a separate pass for culling\r\n */\r\n @serialize()\r\n public separateCullingPass = false;\r\n\r\n /**\r\n * Stores the state specifying if fog should be enabled\r\n */\r\n @serialize(\"fogEnabled\")\r\n private _fogEnabled = true;\r\n\r\n /**\r\n * Sets the state for enabling fog\r\n */\r\n public set fogEnabled(value: boolean) {\r\n if (this._fogEnabled === value) {\r\n return;\r\n }\r\n this._fogEnabled = value;\r\n this.markAsDirty(Material.MiscDirtyFlag);\r\n }\r\n\r\n /**\r\n * Gets the value of the fog enabled state\r\n */\r\n public get fogEnabled(): boolean {\r\n return this._fogEnabled;\r\n }\r\n\r\n /**\r\n * Stores the size of points\r\n */\r\n @serialize()\r\n public pointSize = 1.0;\r\n\r\n /**\r\n * Stores the z offset Factor value\r\n */\r\n @serialize()\r\n public zOffset = 0;\r\n\r\n /**\r\n * Stores the z offset Units value\r\n */\r\n @serialize()\r\n public zOffsetUnits = 0;\r\n\r\n public get wireframe(): boolean {\r\n switch (this._fillMode) {\r\n case Material.WireFrameFillMode:\r\n case Material.LineListDrawMode:\r\n case Material.LineLoopDrawMode:\r\n case Material.LineStripDrawMode:\r\n return true;\r\n }\r\n\r\n return this._scene.forceWireframe;\r\n }\r\n\r\n /**\r\n * Sets the state of wireframe mode\r\n */\r\n public set wireframe(value: boolean) {\r\n this.fillMode = value ? Material.WireFrameFillMode : Material.TriangleFillMode;\r\n }\r\n\r\n /**\r\n * Gets the value specifying if point clouds are enabled\r\n */\r\n @serialize()\r\n public get pointsCloud(): boolean {\r\n switch (this._fillMode) {\r\n case Material.PointFillMode:\r\n case Material.PointListDrawMode:\r\n return true;\r\n }\r\n\r\n return this._scene.forcePointsCloud;\r\n }\r\n\r\n /**\r\n * Sets the state of point cloud mode\r\n */\r\n public set pointsCloud(value: boolean) {\r\n this.fillMode = value ? Material.PointFillMode : Material.TriangleFillMode;\r\n }\r\n\r\n /**\r\n * Gets the material fill mode\r\n */\r\n @serialize()\r\n public get fillMode(): number {\r\n return this._fillMode;\r\n }\r\n\r\n /**\r\n * Sets the material fill mode\r\n */\r\n public set fillMode(value: number) {\r\n if (this._fillMode === value) {\r\n return;\r\n }\r\n\r\n this._fillMode = value;\r\n this.markAsDirty(Material.MiscDirtyFlag);\r\n }\r\n\r\n /**\r\n * Gets or sets the active clipplane 1\r\n */\r\n public clipPlane: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 2\r\n */\r\n public clipPlane2: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 3\r\n */\r\n public clipPlane3: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 4\r\n */\r\n public clipPlane4: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 5\r\n */\r\n public clipPlane5: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 6\r\n */\r\n public clipPlane6: Nullable;\r\n\r\n /**\r\n * Gives access to the stencil properties of the material\r\n */\r\n public readonly stencil = new MaterialStencilState();\r\n\r\n /**\r\n * @internal\r\n * Stores the effects for the material\r\n */\r\n protected _materialContext: IMaterialContext | undefined;\r\n\r\n protected _drawWrapper: DrawWrapper;\r\n /** @internal */\r\n public _getDrawWrapper(): DrawWrapper {\r\n return this._drawWrapper;\r\n }\r\n /**\r\n * @internal\r\n */\r\n public _setDrawWrapper(drawWrapper: DrawWrapper) {\r\n this._drawWrapper = drawWrapper;\r\n }\r\n\r\n /**\r\n * Specifies if uniform buffers should be used\r\n */\r\n private _useUBO: boolean = false;\r\n\r\n /**\r\n * Stores a reference to the scene\r\n */\r\n private _scene: Scene;\r\n protected _needToBindSceneUbo: boolean;\r\n\r\n /**\r\n * Stores the fill mode state\r\n */\r\n private _fillMode = Material.TriangleFillMode;\r\n\r\n /**\r\n * Specifies if the depth write state should be cached\r\n */\r\n private _cachedDepthWriteState: boolean = false;\r\n\r\n /**\r\n * Specifies if the color write state should be cached\r\n */\r\n private _cachedColorWriteState: boolean = false;\r\n\r\n /**\r\n * Specifies if the depth function state should be cached\r\n */\r\n private _cachedDepthFunctionState: number = 0;\r\n\r\n /**\r\n * Stores the uniform buffer\r\n * @internal\r\n */\r\n public _uniformBuffer: UniformBuffer;\r\n\r\n /** @internal */\r\n public _indexInSceneMaterialArray = -1;\r\n\r\n /** @internal */\r\n public meshMap: Nullable<{ [id: string]: AbstractMesh | undefined }> = null;\r\n\r\n /** @internal */\r\n public _parentContainer: Nullable = null;\r\n\r\n /** @internal */\r\n public _dirtyCallbacks: { [code: number]: () => void };\r\n\r\n /** @internal */\r\n public _uniformBufferLayoutBuilt = false;\r\n\r\n protected _eventInfo: MaterialPluginCreated &\r\n MaterialPluginDisposed &\r\n MaterialPluginHasTexture &\r\n MaterialPluginIsReadyForSubMesh &\r\n MaterialPluginGetDefineNames &\r\n MaterialPluginPrepareEffect &\r\n MaterialPluginPrepareDefines &\r\n MaterialPluginPrepareUniformBuffer &\r\n MaterialPluginBindForSubMesh &\r\n MaterialPluginGetAnimatables &\r\n MaterialPluginGetActiveTextures &\r\n MaterialPluginFillRenderTargetTextures &\r\n MaterialPluginHasRenderTargetTextures &\r\n MaterialPluginHardBindForSubMesh = {} as any; // will be initialized before each event notification\r\n\r\n /** @internal */\r\n public _callbackPluginEventGeneric: (\r\n id: number,\r\n info:\r\n | MaterialPluginGetActiveTextures\r\n | MaterialPluginGetAnimatables\r\n | MaterialPluginHasTexture\r\n | MaterialPluginDisposed\r\n | MaterialPluginGetDefineNames\r\n | MaterialPluginPrepareEffect\r\n | MaterialPluginPrepareUniformBuffer\r\n ) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventIsReadyForSubMesh: (eventData: MaterialPluginIsReadyForSubMesh) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventPrepareDefines: (eventData: MaterialPluginPrepareDefines) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventPrepareDefinesBeforeAttributes: (eventData: MaterialPluginPrepareDefines) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventHardBindForSubMesh: (eventData: MaterialPluginHardBindForSubMesh) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventBindForSubMesh: (eventData: MaterialPluginBindForSubMesh) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventHasRenderTargetTextures: (eventData: MaterialPluginHasRenderTargetTextures) => void = () => void 0;\r\n /** @internal */\r\n public _callbackPluginEventFillRenderTargetTextures: (eventData: MaterialPluginFillRenderTargetTextures) => void = () => void 0;\r\n\r\n /**\r\n * Creates a material instance\r\n * @param name defines the name of the material\r\n * @param scene defines the scene to reference\r\n * @param doNotAdd specifies if the material should be added to the scene\r\n */\r\n constructor(name: string, scene?: Nullable, doNotAdd?: boolean) {\r\n this.name = name;\r\n const setScene = scene || EngineStore.LastCreatedScene;\r\n if (!setScene) {\r\n return;\r\n }\r\n this._scene = setScene;\r\n this._dirtyCallbacks = {};\r\n\r\n this._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag] = this._markAllSubMeshesAsTexturesDirty.bind(this);\r\n this._dirtyCallbacks[Constants.MATERIAL_LightDirtyFlag] = this._markAllSubMeshesAsLightsDirty.bind(this);\r\n this._dirtyCallbacks[Constants.MATERIAL_FresnelDirtyFlag] = this._markAllSubMeshesAsFresnelDirty.bind(this);\r\n this._dirtyCallbacks[Constants.MATERIAL_AttributesDirtyFlag] = this._markAllSubMeshesAsAttributesDirty.bind(this);\r\n this._dirtyCallbacks[Constants.MATERIAL_MiscDirtyFlag] = this._markAllSubMeshesAsMiscDirty.bind(this);\r\n this._dirtyCallbacks[Constants.MATERIAL_PrePassDirtyFlag] = this._markAllSubMeshesAsPrePassDirty.bind(this);\r\n this._dirtyCallbacks[Constants.MATERIAL_AllDirtyFlag] = this._markAllSubMeshesAsAllDirty.bind(this);\r\n\r\n this.id = name || Tools.RandomId();\r\n this.uniqueId = this._scene.getUniqueId();\r\n this._materialContext = this._scene.getEngine().createMaterialContext();\r\n this._drawWrapper = new DrawWrapper(this._scene.getEngine(), false);\r\n this._drawWrapper.materialContext = this._materialContext;\r\n\r\n if (this._scene.useRightHandedSystem) {\r\n this.sideOrientation = Material.ClockWiseSideOrientation;\r\n } else {\r\n this.sideOrientation = Material.CounterClockWiseSideOrientation;\r\n }\r\n\r\n this._uniformBuffer = new UniformBuffer(this._scene.getEngine(), undefined, undefined, name);\r\n this._useUBO = this.getScene().getEngine().supportsUniformBuffers;\r\n\r\n if (!doNotAdd) {\r\n this._scene.addMaterial(this);\r\n }\r\n\r\n if (this._scene.useMaterialMeshMap) {\r\n this.meshMap = {};\r\n }\r\n\r\n Material.OnEventObservable.notifyObservers(this, MaterialPluginEvent.Created);\r\n }\r\n\r\n /**\r\n * Returns a string representation of the current material\r\n * @param fullDetails defines a boolean indicating which levels of logging is desired\r\n * @returns a string with material information\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public toString(fullDetails?: boolean): string {\r\n const ret = \"Name: \" + this.name;\r\n return ret;\r\n }\r\n\r\n /**\r\n * Gets the class name of the material\r\n * @returns a string with the class name of the material\r\n */\r\n public getClassName(): string {\r\n return \"Material\";\r\n }\r\n\r\n /** @internal */\r\n public get _isMaterial() {\r\n return true;\r\n }\r\n\r\n /**\r\n * Specifies if updates for the material been locked\r\n */\r\n public get isFrozen(): boolean {\r\n return this.checkReadyOnlyOnce;\r\n }\r\n\r\n /**\r\n * Locks updates for the material\r\n */\r\n public freeze(): void {\r\n this.markDirty();\r\n this.checkReadyOnlyOnce = true;\r\n }\r\n\r\n /**\r\n * Unlocks updates for the material\r\n */\r\n public unfreeze(): void {\r\n this.markDirty();\r\n this.checkReadyOnlyOnce = false;\r\n }\r\n\r\n /**\r\n * Specifies if the material is ready to be used\r\n * @param mesh defines the mesh to check\r\n * @param useInstances specifies if instances should be used\r\n * @returns a boolean indicating if the material is ready to be used\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used\r\n * @param mesh defines the mesh to check\r\n * @param subMesh defines which submesh to check\r\n * @param useInstances specifies that instances should be used\r\n * @returns a boolean indicating that the submesh is ready or not\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n const defines = subMesh.materialDefines;\r\n if (!defines) {\r\n return false;\r\n }\r\n\r\n this._eventInfo.isReadyForSubMesh = true;\r\n this._eventInfo.defines = defines;\r\n this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);\r\n\r\n return this._eventInfo.isReadyForSubMesh;\r\n }\r\n\r\n /**\r\n * Returns the material effect\r\n * @returns the effect associated with the material\r\n */\r\n public getEffect(): Nullable {\r\n return this._drawWrapper.effect;\r\n }\r\n\r\n /**\r\n * Returns the current scene\r\n * @returns a Scene\r\n */\r\n public getScene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.\r\n */\r\n protected _forceAlphaTest = false;\r\n\r\n /**\r\n * The transparency mode of the material.\r\n */\r\n protected _transparencyMode: Nullable = null;\r\n\r\n /**\r\n * Gets the current transparency mode.\r\n */\r\n @serialize()\r\n public get transparencyMode(): Nullable {\r\n return this._transparencyMode;\r\n }\r\n\r\n /**\r\n * Sets the transparency mode of the material.\r\n *\r\n * | Value | Type | Description |\r\n * | ----- | ----------------------------------- | ----------- |\r\n * | 0 | OPAQUE | |\r\n * | 1 | ALPHATEST | |\r\n * | 2 | ALPHABLEND | |\r\n * | 3 | ALPHATESTANDBLEND | |\r\n *\r\n */\r\n public set transparencyMode(value: Nullable) {\r\n if (this._transparencyMode === value) {\r\n return;\r\n }\r\n\r\n this._transparencyMode = value;\r\n\r\n this._forceAlphaTest = value === Material.MATERIAL_ALPHATESTANDBLEND;\r\n\r\n this._markAllSubMeshesAsTexturesAndMiscDirty();\r\n }\r\n\r\n /**\r\n * Returns true if alpha blending should be disabled.\r\n */\r\n protected get _disableAlphaBlending(): boolean {\r\n return this._transparencyMode === Material.MATERIAL_OPAQUE || this._transparencyMode === Material.MATERIAL_ALPHATEST;\r\n }\r\n\r\n /**\r\n * Specifies whether or not this material should be rendered in alpha blend mode.\r\n * @returns a boolean specifying if alpha blending is needed\r\n */\r\n public needAlphaBlending(): boolean {\r\n if (this._disableAlphaBlending) {\r\n return false;\r\n }\r\n\r\n return this.alpha < 1.0;\r\n }\r\n\r\n /**\r\n * Specifies if the mesh will require alpha blending\r\n * @param mesh defines the mesh to check\r\n * @returns a boolean specifying if alpha blending is needed for the mesh\r\n */\r\n public needAlphaBlendingForMesh(mesh: AbstractMesh): boolean {\r\n if (mesh.visibility < 1.0) {\r\n return true;\r\n }\r\n\r\n if (this._disableAlphaBlending) {\r\n return false;\r\n }\r\n\r\n return mesh.hasVertexAlpha || this.needAlphaBlending();\r\n }\r\n\r\n /**\r\n * Specifies whether or not this material should be rendered in alpha test mode.\r\n * @returns a boolean specifying if an alpha test is needed.\r\n */\r\n public needAlphaTesting(): boolean {\r\n if (this._forceAlphaTest) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Specifies if material alpha testing should be turned on for the mesh\r\n * @param mesh defines the mesh to check\r\n */\r\n protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean {\r\n return !this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting();\r\n }\r\n\r\n /**\r\n * Gets the texture used for the alpha test\r\n * @returns the texture to use for alpha testing\r\n */\r\n public getAlphaTestTexture(): Nullable {\r\n return null;\r\n }\r\n\r\n /**\r\n * Marks the material to indicate that it needs to be re-calculated\r\n * @param forceMaterialDirty - Forces the material to be marked as dirty for all components (same as this.markAsDirty(Material.AllDirtyFlag)). You should use this flag if the material is frozen and you want to force a recompilation.\r\n */\r\n public markDirty(forceMaterialDirty = false): void {\r\n const meshes = this.getScene().meshes;\r\n for (const mesh of meshes) {\r\n if (!mesh.subMeshes) {\r\n continue;\r\n }\r\n for (const subMesh of mesh.subMeshes) {\r\n if (subMesh.getMaterial() !== this) {\r\n continue;\r\n }\r\n\r\n if (!subMesh.effect) {\r\n continue;\r\n }\r\n\r\n subMesh.effect._wasPreviouslyReady = false;\r\n subMesh.effect._wasPreviouslyUsingInstances = null;\r\n subMesh.effect._forceRebindOnNextCall = forceMaterialDirty;\r\n }\r\n }\r\n\r\n if (forceMaterialDirty) {\r\n this.markAsDirty(Material.AllDirtyFlag);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _preBind(effect?: Effect | DrawWrapper, overrideOrientation: Nullable = null): boolean {\r\n const engine = this._scene.getEngine();\r\n\r\n const orientation = overrideOrientation == null ? this.sideOrientation : overrideOrientation;\r\n const reverse = orientation === Material.ClockWiseSideOrientation;\r\n\r\n engine.enableEffect(effect ? effect : this._getDrawWrapper());\r\n engine.setState(\r\n this.backFaceCulling,\r\n this.zOffset,\r\n false,\r\n reverse,\r\n this._scene._mirroredCameraPosition ? !this.cullBackFaces : this.cullBackFaces,\r\n this.stencil,\r\n this.zOffsetUnits\r\n );\r\n\r\n return reverse;\r\n }\r\n\r\n /**\r\n * Binds the material to the mesh\r\n * @param world defines the world transformation matrix\r\n * @param mesh defines the mesh to bind the material to\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bind(world: Matrix, mesh?: Mesh): void {}\r\n\r\n /**\r\n * Initializes the uniform buffer layout for the shader.\r\n */\r\n public buildUniformLayout(): void {\r\n const ubo = this._uniformBuffer;\r\n\r\n this._eventInfo.ubo = ubo;\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareUniformBuffer, this._eventInfo);\r\n\r\n ubo.create();\r\n\r\n this._uniformBufferLayoutBuilt = true;\r\n }\r\n\r\n /**\r\n * Binds the submesh to the material\r\n * @param world defines the world transformation matrix\r\n * @param mesh defines the mesh containing the submesh\r\n * @param subMesh defines the submesh to bind the material to\r\n */\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventBindForSubMesh(this._eventInfo);\r\n effect._forceRebindOnNextCall = false;\r\n }\r\n\r\n /**\r\n * Binds the world matrix to the material\r\n * @param world defines the world transformation matrix\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bindOnlyWorldMatrix(world: Matrix): void {}\r\n\r\n /**\r\n * Binds the view matrix to the effect\r\n * @param effect defines the effect to bind the view matrix to\r\n */\r\n public bindView(effect: Effect): void {\r\n if (!this._useUBO) {\r\n effect.setMatrix(\"view\", this.getScene().getViewMatrix());\r\n } else {\r\n this._needToBindSceneUbo = true;\r\n }\r\n }\r\n\r\n /**\r\n * Binds the view projection and projection matrices to the effect\r\n * @param effect defines the effect to bind the view projection and projection matrices to\r\n */\r\n public bindViewProjection(effect: Effect): void {\r\n if (!this._useUBO) {\r\n effect.setMatrix(\"viewProjection\", this.getScene().getTransformMatrix());\r\n effect.setMatrix(\"projection\", this.getScene().getProjectionMatrix());\r\n } else {\r\n this._needToBindSceneUbo = true;\r\n }\r\n }\r\n\r\n /**\r\n * Binds the view matrix to the effect\r\n * @param effect defines the effect to bind the view matrix to\r\n * @param variableName name of the shader variable that will hold the eye position\r\n */\r\n public bindEyePosition(effect: Effect, variableName?: string): void {\r\n if (!this._useUBO) {\r\n this._scene.bindEyePosition(effect, variableName);\r\n } else {\r\n this._needToBindSceneUbo = true;\r\n }\r\n }\r\n\r\n /**\r\n * Processes to execute after binding the material to a mesh\r\n * @param mesh defines the rendered mesh\r\n * @param effect\r\n */\r\n protected _afterBind(mesh?: Mesh, effect: Nullable = null): void {\r\n this._scene._cachedMaterial = this;\r\n if (this._needToBindSceneUbo) {\r\n if (effect) {\r\n this._needToBindSceneUbo = false;\r\n MaterialHelper.BindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());\r\n this._scene.finalizeSceneUbo();\r\n }\r\n }\r\n if (mesh) {\r\n this._scene._cachedVisibility = mesh.visibility;\r\n } else {\r\n this._scene._cachedVisibility = 1;\r\n }\r\n\r\n if (this._onBindObservable && mesh) {\r\n this._onBindObservable.notifyObservers(mesh);\r\n }\r\n\r\n if (this.disableDepthWrite) {\r\n const engine = this._scene.getEngine();\r\n this._cachedDepthWriteState = engine.getDepthWrite();\r\n engine.setDepthWrite(false);\r\n }\r\n\r\n if (this.disableColorWrite) {\r\n const engine = this._scene.getEngine();\r\n this._cachedColorWriteState = engine.getColorWrite();\r\n engine.setColorWrite(false);\r\n }\r\n\r\n if (this.depthFunction !== 0) {\r\n const engine = this._scene.getEngine();\r\n this._cachedDepthFunctionState = engine.getDepthFunction() || 0;\r\n engine.setDepthFunction(this.depthFunction);\r\n }\r\n }\r\n\r\n /**\r\n * Unbinds the material from the mesh\r\n */\r\n public unbind(): void {\r\n if (this._onUnBindObservable) {\r\n this._onUnBindObservable.notifyObservers(this);\r\n }\r\n\r\n if (this.depthFunction !== 0) {\r\n const engine = this._scene.getEngine();\r\n engine.setDepthFunction(this._cachedDepthFunctionState);\r\n }\r\n\r\n if (this.disableDepthWrite) {\r\n const engine = this._scene.getEngine();\r\n engine.setDepthWrite(this._cachedDepthWriteState);\r\n }\r\n\r\n if (this.disableColorWrite) {\r\n const engine = this._scene.getEngine();\r\n engine.setColorWrite(this._cachedColorWriteState);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the animatable textures.\r\n * @returns - Array of animatable textures.\r\n */\r\n public getAnimatables(): IAnimatable[] {\r\n this._eventInfo.animatables = [];\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetAnimatables, this._eventInfo);\r\n return this._eventInfo.animatables;\r\n }\r\n\r\n /**\r\n * Gets the active textures from the material\r\n * @returns an array of textures\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n this._eventInfo.activeTextures = [];\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetActiveTextures, this._eventInfo);\r\n return this._eventInfo.activeTextures;\r\n }\r\n\r\n /**\r\n * Specifies if the material uses a texture\r\n * @param texture defines the texture to check against the material\r\n * @returns a boolean specifying if the material uses the texture\r\n */\r\n public hasTexture(texture: BaseTexture): boolean {\r\n this._eventInfo.hasTexture = false;\r\n this._eventInfo.texture = texture;\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.HasTexture, this._eventInfo);\r\n return this._eventInfo.hasTexture;\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the material, and gives it a new name\r\n * @param name defines the new name for the duplicated material\r\n * @returns the cloned material\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public clone(name: string): Nullable {\r\n return null;\r\n }\r\n\r\n protected _clonePlugins(targetMaterial: Material, rootUrl: string) {\r\n const serializationObject: any = {};\r\n\r\n // Create plugins in targetMaterial in case they don't exist\r\n this._serializePlugins(serializationObject);\r\n\r\n Material._parsePlugins(serializationObject, targetMaterial, this._scene, rootUrl);\r\n\r\n // Copy the properties of the current plugins to the cloned material's plugins\r\n if (this.pluginManager) {\r\n for (const plugin of this.pluginManager._plugins) {\r\n const targetPlugin = targetMaterial.pluginManager!.getPlugin(plugin.name)!;\r\n plugin.copyTo(targetPlugin);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the meshes bound to the material\r\n * @returns an array of meshes bound to the material\r\n */\r\n public getBindedMeshes(): AbstractMesh[] {\r\n if (this.meshMap) {\r\n const result = new Array();\r\n for (const meshId in this.meshMap) {\r\n const mesh = this.meshMap[meshId];\r\n if (mesh) {\r\n result.push(mesh);\r\n }\r\n }\r\n return result;\r\n } else {\r\n const meshes = this._scene.meshes;\r\n return meshes.filter((mesh) => mesh.material === this);\r\n }\r\n }\r\n\r\n /**\r\n * Force shader compilation\r\n * @param mesh defines the mesh associated with this material\r\n * @param onCompiled defines a function to execute once the material is compiled\r\n * @param options defines the options to configure the compilation\r\n * @param onError defines a function to execute if the material fails compiling\r\n */\r\n public forceCompilation(\r\n mesh: AbstractMesh,\r\n onCompiled?: (material: Material) => void,\r\n options?: Partial,\r\n onError?: (reason: string) => void\r\n ): void {\r\n const localOptions = {\r\n clipPlane: false,\r\n useInstances: false,\r\n ...options,\r\n };\r\n\r\n const scene = this.getScene();\r\n const currentHotSwapingState = this.allowShaderHotSwapping;\r\n this.allowShaderHotSwapping = false; // Turned off to let us evaluate the real compilation state\r\n\r\n const checkReady = () => {\r\n if (!this._scene || !this._scene.getEngine()) {\r\n return;\r\n }\r\n\r\n const clipPlaneState = scene.clipPlane;\r\n\r\n if (localOptions.clipPlane) {\r\n scene.clipPlane = new Plane(0, 0, 0, 1);\r\n }\r\n\r\n if (this._storeEffectOnSubMeshes) {\r\n let allDone = true,\r\n lastError = null;\r\n if (mesh.subMeshes) {\r\n const tempSubMesh = new SubMesh(0, 0, 0, 0, 0, mesh, undefined, false, false);\r\n if (tempSubMesh.materialDefines) {\r\n tempSubMesh.materialDefines._renderId = -1;\r\n }\r\n if (!this.isReadyForSubMesh(mesh, tempSubMesh, localOptions.useInstances)) {\r\n if (tempSubMesh.effect && tempSubMesh.effect.getCompilationError() && tempSubMesh.effect.allFallbacksProcessed()) {\r\n lastError = tempSubMesh.effect.getCompilationError();\r\n } else {\r\n allDone = false;\r\n setTimeout(checkReady, 16);\r\n }\r\n }\r\n }\r\n if (allDone) {\r\n this.allowShaderHotSwapping = currentHotSwapingState;\r\n if (lastError) {\r\n if (onError) {\r\n onError(lastError);\r\n }\r\n }\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n }\r\n } else {\r\n if (this.isReady()) {\r\n this.allowShaderHotSwapping = currentHotSwapingState;\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n } else {\r\n setTimeout(checkReady, 16);\r\n }\r\n }\r\n\r\n if (localOptions.clipPlane) {\r\n scene.clipPlane = clipPlaneState;\r\n }\r\n };\r\n\r\n checkReady();\r\n }\r\n\r\n /**\r\n * Force shader compilation\r\n * @param mesh defines the mesh that will use this material\r\n * @param options defines additional options for compiling the shaders\r\n * @returns a promise that resolves when the compilation completes\r\n */\r\n public forceCompilationAsync(mesh: AbstractMesh, options?: Partial): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.forceCompilation(\r\n mesh,\r\n () => {\r\n resolve();\r\n },\r\n options,\r\n (reason) => {\r\n reject(reason);\r\n }\r\n );\r\n });\r\n }\r\n\r\n private static readonly _AllDirtyCallBack = (defines: MaterialDefines) => defines.markAllAsDirty();\r\n private static readonly _ImageProcessingDirtyCallBack = (defines: MaterialDefines) => defines.markAsImageProcessingDirty();\r\n private static readonly _TextureDirtyCallBack = (defines: MaterialDefines) => defines.markAsTexturesDirty();\r\n private static readonly _FresnelDirtyCallBack = (defines: MaterialDefines) => defines.markAsFresnelDirty();\r\n private static readonly _MiscDirtyCallBack = (defines: MaterialDefines) => defines.markAsMiscDirty();\r\n private static readonly _PrePassDirtyCallBack = (defines: MaterialDefines) => defines.markAsPrePassDirty();\r\n private static readonly _LightsDirtyCallBack = (defines: MaterialDefines) => defines.markAsLightDirty();\r\n private static readonly _AttributeDirtyCallBack = (defines: MaterialDefines) => defines.markAsAttributesDirty();\r\n\r\n private static _FresnelAndMiscDirtyCallBack = (defines: MaterialDefines) => {\r\n Material._FresnelDirtyCallBack(defines);\r\n Material._MiscDirtyCallBack(defines);\r\n };\r\n\r\n private static _TextureAndMiscDirtyCallBack = (defines: MaterialDefines) => {\r\n Material._TextureDirtyCallBack(defines);\r\n Material._MiscDirtyCallBack(defines);\r\n };\r\n\r\n private static readonly _DirtyCallbackArray: Array<(defines: MaterialDefines) => void> = [];\r\n private static readonly _RunDirtyCallBacks = (defines: MaterialDefines) => {\r\n for (const cb of Material._DirtyCallbackArray) {\r\n cb(defines);\r\n }\r\n };\r\n\r\n /**\r\n * Marks a define in the material to indicate that it needs to be re-computed\r\n * @param flag defines a flag used to determine which parts of the material have to be marked as dirty\r\n */\r\n public markAsDirty(flag: number): void {\r\n if (this.getScene().blockMaterialDirtyMechanism || this._blockDirtyMechanism) {\r\n return;\r\n }\r\n\r\n Material._DirtyCallbackArray.length = 0;\r\n\r\n if (flag & Material.TextureDirtyFlag) {\r\n Material._DirtyCallbackArray.push(Material._TextureDirtyCallBack);\r\n }\r\n\r\n if (flag & Material.LightDirtyFlag) {\r\n Material._DirtyCallbackArray.push(Material._LightsDirtyCallBack);\r\n }\r\n\r\n if (flag & Material.FresnelDirtyFlag) {\r\n Material._DirtyCallbackArray.push(Material._FresnelDirtyCallBack);\r\n }\r\n\r\n if (flag & Material.AttributesDirtyFlag) {\r\n Material._DirtyCallbackArray.push(Material._AttributeDirtyCallBack);\r\n }\r\n\r\n if (flag & Material.MiscDirtyFlag) {\r\n Material._DirtyCallbackArray.push(Material._MiscDirtyCallBack);\r\n }\r\n\r\n if (flag & Material.PrePassDirtyFlag) {\r\n Material._DirtyCallbackArray.push(Material._PrePassDirtyCallBack);\r\n }\r\n\r\n if (Material._DirtyCallbackArray.length) {\r\n this._markAllSubMeshesAsDirty(Material._RunDirtyCallBacks);\r\n }\r\n\r\n this.getScene().resetCachedMaterial();\r\n }\r\n\r\n /**\r\n * Resets the draw wrappers cache for all submeshes that are using this material\r\n */\r\n public resetDrawCache(): void {\r\n const meshes = this.getScene().meshes;\r\n for (const mesh of meshes) {\r\n if (!mesh.subMeshes) {\r\n continue;\r\n }\r\n for (const subMesh of mesh.subMeshes) {\r\n if (subMesh.getMaterial() !== this) {\r\n continue;\r\n }\r\n\r\n subMesh.resetDrawCache();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Marks all submeshes of a material to indicate that their material defines need to be re-calculated\r\n * @param func defines a function which checks material defines against the submeshes\r\n */\r\n protected _markAllSubMeshesAsDirty(func: (defines: MaterialDefines) => void) {\r\n if (this.getScene().blockMaterialDirtyMechanism || this._blockDirtyMechanism) {\r\n return;\r\n }\r\n\r\n const meshes = this.getScene().meshes;\r\n for (const mesh of meshes) {\r\n if (!mesh.subMeshes) {\r\n continue;\r\n }\r\n for (const subMesh of mesh.subMeshes) {\r\n // We want to skip the submeshes which are not using this material or which have not yet rendered at least once\r\n if (subMesh.getMaterial(false) !== this) {\r\n continue;\r\n }\r\n\r\n for (const drawWrapper of subMesh._drawWrappers) {\r\n if (!drawWrapper || !drawWrapper.defines || !(drawWrapper.defines as MaterialDefines).markAllAsDirty) {\r\n continue;\r\n }\r\n if (this._materialContext === drawWrapper.materialContext) {\r\n func(drawWrapper.defines as MaterialDefines);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Indicates that the scene should check if the rendering now needs a prepass\r\n */\r\n protected _markScenePrePassDirty() {\r\n if (this.getScene().blockMaterialDirtyMechanism || this._blockDirtyMechanism) {\r\n return;\r\n }\r\n\r\n const prePassRenderer = this.getScene().enablePrePassRenderer();\r\n if (prePassRenderer) {\r\n prePassRenderer.markAsDirty();\r\n }\r\n }\r\n\r\n /**\r\n * Indicates that we need to re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsAllDirty() {\r\n this._markAllSubMeshesAsDirty(Material._AllDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that image processing needs to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsImageProcessingDirty() {\r\n this._markAllSubMeshesAsDirty(Material._ImageProcessingDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that textures need to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsTexturesDirty() {\r\n this._markAllSubMeshesAsDirty(Material._TextureDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that fresnel needs to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsFresnelDirty() {\r\n this._markAllSubMeshesAsDirty(Material._FresnelDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that fresnel and misc need to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsFresnelAndMiscDirty() {\r\n this._markAllSubMeshesAsDirty(Material._FresnelAndMiscDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that lights need to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsLightsDirty() {\r\n this._markAllSubMeshesAsDirty(Material._LightsDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that attributes need to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsAttributesDirty() {\r\n this._markAllSubMeshesAsDirty(Material._AttributeDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that misc needs to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsMiscDirty() {\r\n this._markAllSubMeshesAsDirty(Material._MiscDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that prepass needs to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsPrePassDirty() {\r\n this._markAllSubMeshesAsDirty(Material._MiscDirtyCallBack);\r\n }\r\n\r\n /**\r\n * Indicates that textures and misc need to be re-calculated for all submeshes\r\n */\r\n protected _markAllSubMeshesAsTexturesAndMiscDirty() {\r\n this._markAllSubMeshesAsDirty(Material._TextureAndMiscDirtyCallBack);\r\n }\r\n\r\n protected _checkScenePerformancePriority() {\r\n if (this._scene.performancePriority !== ScenePerformancePriority.BackwardCompatible) {\r\n this.checkReadyOnlyOnce = true;\r\n // re-set the flag when the perf priority changes\r\n const observer = this._scene.onScenePerformancePriorityChangedObservable.addOnce(() => {\r\n this.checkReadyOnlyOnce = false;\r\n });\r\n // if this material is disposed before the scene is disposed, cleanup the observer\r\n this.onDisposeObservable.add(() => {\r\n this._scene.onScenePerformancePriorityChangedObservable.remove(observer);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Sets the required values to the prepass renderer.\r\n * @param prePassRenderer defines the prepass renderer to setup.\r\n * @returns true if the pre pass is needed.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {\r\n // Do Nothing by default\r\n return false;\r\n }\r\n\r\n /**\r\n * Disposes the material\r\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\r\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\r\n * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, notBoundToMesh?: boolean): void {\r\n const scene = this.getScene();\r\n // Animations\r\n scene.stopAnimation(this);\r\n scene.freeProcessedMaterials();\r\n\r\n // Remove from scene\r\n scene.removeMaterial(this);\r\n\r\n this._eventInfo.forceDisposeTextures = forceDisposeTextures;\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.Disposed, this._eventInfo);\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.materials.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.materials.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n if (notBoundToMesh !== true) {\r\n // Remove from meshes\r\n if (this.meshMap) {\r\n for (const meshId in this.meshMap) {\r\n const mesh = this.meshMap[meshId];\r\n if (mesh) {\r\n mesh.material = null; // will set the entry in the map to undefined\r\n this.releaseVertexArrayObject(mesh, forceDisposeEffect);\r\n }\r\n }\r\n } else {\r\n const meshes = scene.meshes;\r\n for (const mesh of meshes) {\r\n if (mesh.material === this && !(mesh as InstancedMesh).sourceMesh) {\r\n mesh.material = null;\r\n this.releaseVertexArrayObject(mesh, forceDisposeEffect);\r\n }\r\n }\r\n }\r\n }\r\n\r\n this._uniformBuffer.dispose();\r\n\r\n // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect\r\n if (forceDisposeEffect && this._drawWrapper.effect) {\r\n if (!this._storeEffectOnSubMeshes) {\r\n this._drawWrapper.effect.dispose();\r\n }\r\n\r\n this._drawWrapper.effect = null;\r\n }\r\n\r\n this.metadata = null;\r\n\r\n // Callback\r\n this.onDisposeObservable.notifyObservers(this);\r\n\r\n this.onDisposeObservable.clear();\r\n if (this._onBindObservable) {\r\n this._onBindObservable.clear();\r\n }\r\n\r\n if (this._onUnBindObservable) {\r\n this._onUnBindObservable.clear();\r\n }\r\n\r\n if (this._onEffectCreatedObservable) {\r\n this._onEffectCreatedObservable.clear();\r\n }\r\n\r\n if (this._eventInfo) {\r\n this._eventInfo = {} as any;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private releaseVertexArrayObject(mesh: AbstractMesh, forceDisposeEffect?: boolean) {\r\n if ((mesh).geometry) {\r\n const geometry = (mesh).geometry;\r\n if (this._storeEffectOnSubMeshes) {\r\n for (const subMesh of mesh.subMeshes) {\r\n geometry._releaseVertexArrayObject(subMesh.effect);\r\n if (forceDisposeEffect && subMesh.effect) {\r\n subMesh.effect.dispose();\r\n }\r\n }\r\n } else {\r\n geometry._releaseVertexArrayObject(this._drawWrapper.effect);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serializes this material\r\n * @returns the serialized material object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.stencil = this.stencil.serialize();\r\n serializationObject.uniqueId = this.uniqueId;\r\n\r\n this._serializePlugins(serializationObject);\r\n\r\n return serializationObject;\r\n }\r\n\r\n protected _serializePlugins(serializationObject: any) {\r\n serializationObject.plugins = {};\r\n\r\n if (this.pluginManager) {\r\n for (const plugin of this.pluginManager._plugins) {\r\n serializationObject.plugins[plugin.getClassName()] = plugin.serialize();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a material from parsed material data\r\n * @param parsedMaterial defines parsed material data\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures\r\n * @returns a new material\r\n */\r\n public static Parse(parsedMaterial: any, scene: Scene, rootUrl: string): Nullable {\r\n if (!parsedMaterial.customType) {\r\n parsedMaterial.customType = \"BABYLON.StandardMaterial\";\r\n } else if (parsedMaterial.customType === \"BABYLON.PBRMaterial\" && parsedMaterial.overloadedAlbedo) {\r\n parsedMaterial.customType = \"BABYLON.LegacyPBRMaterial\";\r\n if (!BABYLON.LegacyPBRMaterial) {\r\n Logger.Error(\"Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library.\");\r\n return null;\r\n }\r\n }\r\n\r\n const materialType = Tools.Instantiate(parsedMaterial.customType);\r\n const material = materialType.Parse(parsedMaterial, scene, rootUrl);\r\n material._loadedUniqueId = parsedMaterial.uniqueId;\r\n\r\n return material;\r\n }\r\n\r\n protected static _parsePlugins(serializationObject: any, material: Material, scene: Scene, rootUrl: string) {\r\n if (!serializationObject.plugins) {\r\n return;\r\n }\r\n\r\n for (const pluginClassName in serializationObject.plugins) {\r\n const pluginData = serializationObject.plugins[pluginClassName];\r\n\r\n let plugin = material.pluginManager?.getPlugin(pluginData.name);\r\n\r\n if (!plugin) {\r\n const pluginClassType = Tools.Instantiate(\"BABYLON.\" + pluginClassName);\r\n if (pluginClassType) {\r\n plugin = new pluginClassType(material);\r\n }\r\n }\r\n\r\n plugin?.parse(pluginData, scene, rootUrl);\r\n }\r\n }\r\n}\r\n","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[];\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[] {\r\n return this._subMaterials;\r\n }\r\n\r\n public set subMaterials(value: Nullable[]) {\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[] {\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();\r\n\r\n this._storeEffectOnSubMeshes = true; // multimaterial is considered like a push material\r\n }\r\n\r\n private _hookArray(array: Nullable[]): void {\r\n const oldPush = array.push;\r\n array.push = (...items: Nullable[]) => {\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 {\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 = 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","import type { Mesh } from \"./mesh\";\r\nimport type { Nullable } from \"../types\";\r\n\r\n/**\r\n * Class used to represent a specific level of detail of a mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\r\n */\r\nexport class MeshLODLevel {\r\n /**\r\n * Creates a new LOD level\r\n * @param distanceOrScreenCoverage defines either the distance or the screen coverage where this level should start being displayed\r\n * @param mesh defines the mesh to use to render this level\r\n */\r\n constructor(\r\n /** Either distance from the center of the object to show this level or the screen coverage if `useLODScreenCoverage` is set to `true` on the mesh*/\r\n public distanceOrScreenCoverage: number,\r\n /** Defines the mesh to use to render this level */\r\n public mesh: Nullable\r\n ) {}\r\n}\r\n","import type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Tools, AsyncLoop } from \"../Misc/tools\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport { DeepCopier } from \"../Misc/deepCopier\";\r\nimport { Tags } from \"../Misc/tags\";\r\nimport type { Coroutine } from \"../Misc/coroutine\";\r\nimport { runCoroutineSync, runCoroutineAsync, createYieldingScheduler } from \"../Misc/coroutine\";\r\nimport type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { ScenePerformancePriority } from \"../scene\";\r\nimport type { Vector4 } from \"../Maths/math.vector\";\r\nimport { Quaternion, Matrix, Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport type { Color4 } from \"../Maths/math.color\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { Node } from \"../node\";\r\nimport { VertexBuffer, Buffer } from \"../Buffers/buffer\";\r\nimport type { IGetSetVerticesData } from \"./mesh.vertexData\";\r\nimport { VertexData } from \"./mesh.vertexData\";\r\n\r\nimport { Geometry } from \"./geometry\";\r\nimport { AbstractMesh } from \"./abstractMesh\";\r\nimport { SubMesh } from \"./subMesh\";\r\nimport type { BoundingSphere } from \"../Culling/boundingSphere\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport { SceneLoaderFlags } from \"../Loading/sceneLoaderFlags\";\r\nimport type { Skeleton } from \"../Bones/skeleton\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { SerializationHelper } from \"../Misc/decorators\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { GetClass, RegisterClass } from \"../Misc/typeStore\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { MeshLODLevel } from \"./meshLODLevel\";\r\nimport type { Path3D } from \"../Maths/math.path\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport type { TransformNode } from \"./transformNode\";\r\nimport type { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport type { PhysicsEngine as PhysicsEngineV1 } from \"../Physics/v1/physicsEngine\";\r\n\r\nimport type { GoldbergMesh } from \"./goldbergMesh\";\r\nimport type { InstancedMesh } from \"./instancedMesh\";\r\nimport type { IPhysicsEnabledObject, PhysicsImpostor } from \"../Physics/v1/physicsImpostor\";\r\nimport type { ICreateCapsuleOptions } from \"./Builders/capsuleBuilder\";\r\nimport type { LinesMesh } from \"./linesMesh\";\r\nimport type { GroundMesh } from \"./groundMesh\";\r\n\r\n/**\r\n * @internal\r\n **/\r\nexport class _CreationDataStorage {\r\n public closePath?: boolean;\r\n public closeArray?: boolean;\r\n public idx: number[];\r\n public dashSize: number;\r\n public gapSize: number;\r\n public path3D: Path3D;\r\n public pathArray: Vector3[][];\r\n public arc: number;\r\n public radius: number;\r\n public cap: number;\r\n public tessellation: number;\r\n}\r\n\r\n/**\r\n * @internal\r\n **/\r\nclass _InstanceDataStorage {\r\n public visibleInstances: any = {};\r\n public batchCache = new _InstancesBatch();\r\n public batchCacheReplacementModeInFrozenMode = new _InstancesBatch();\r\n public instancesBufferSize = 32 * 16 * 4; // let's start with a maximum of 32 instances\r\n public instancesBuffer: Nullable;\r\n public instancesPreviousBuffer: Nullable;\r\n public instancesData: Float32Array;\r\n public instancesPreviousData: Float32Array;\r\n public overridenInstanceCount: number;\r\n public isFrozen: boolean;\r\n public forceMatrixUpdates: boolean;\r\n public previousBatch: Nullable<_InstancesBatch>;\r\n public hardwareInstancedRendering: boolean;\r\n public sideOrientation: number;\r\n public manualUpdate: boolean;\r\n public previousManualUpdate: boolean;\r\n public previousRenderId: number;\r\n public masterMeshPreviousWorldMatrix: Nullable;\r\n}\r\n\r\n/**\r\n * @internal\r\n **/\r\nexport class _InstancesBatch {\r\n public mustReturn = false;\r\n public visibleInstances = new Array>>();\r\n public renderSelf = new Array();\r\n public hardwareInstancedRendering = new Array();\r\n}\r\n\r\n/**\r\n * @internal\r\n **/\r\nclass _ThinInstanceDataStorage {\r\n public instancesCount: number = 0;\r\n public matrixBuffer: Nullable = null;\r\n public previousMatrixBuffer: Nullable = null;\r\n public matrixBufferSize = 32 * 16; // let's start with a maximum of 32 thin instances\r\n public matrixData: Nullable = null;\r\n public previousMatrixData: Nullable;\r\n public boundingVectors: Array = [];\r\n public worldMatrices: Nullable = null;\r\n public masterMeshPreviousWorldMatrix: Nullable;\r\n}\r\n\r\n/**\r\n * @internal\r\n **/\r\nclass _InternalMeshDataInfo {\r\n // Events\r\n public _onBeforeRenderObservable: Nullable>;\r\n public _onBeforeBindObservable: Nullable>;\r\n public _onAfterRenderObservable: Nullable>;\r\n public _onBeforeDrawObservable: Nullable>;\r\n public _onBetweenPassObservable: Nullable>;\r\n\r\n public _areNormalsFrozen: boolean = false; // Will be used by ribbons mainly\r\n public _sourcePositions: Nullable; // Will be used to save original positions when using software skinning\r\n public _sourceNormals: Nullable; // Will be used to save original normals when using software skinning\r\n\r\n // Will be used to save a source mesh reference, If any\r\n public _source: Nullable = null;\r\n // Will be used to for fast cloned mesh lookup\r\n public meshMap: Nullable<{ [id: string]: Mesh | undefined }> = null;\r\n\r\n public _preActivateId: number = -1;\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public _LODLevels = new Array();\r\n /** Alternative definition of LOD level, using screen coverage instead of distance */\r\n public _useLODScreenCoverage: boolean = false;\r\n public _checkReadinessObserver: Nullable>;\r\n\r\n public _onMeshReadyObserverAdded: (observer: Observer) => void;\r\n\r\n public _effectiveMaterial: Nullable = null;\r\n\r\n public _forcedInstanceCount: number = 0;\r\n\r\n public _overrideRenderingFillMode: Nullable = null;\r\n}\r\n\r\n/**\r\n * Class used to represent renderable models\r\n */\r\nexport class Mesh extends AbstractMesh implements IGetSetVerticesData {\r\n // Consts\r\n\r\n /**\r\n * Mesh side orientation : usually the external or front surface\r\n */\r\n public static readonly FRONTSIDE = VertexData.FRONTSIDE;\r\n\r\n /**\r\n * Mesh side orientation : usually the internal or back surface\r\n */\r\n public static readonly BACKSIDE = VertexData.BACKSIDE;\r\n /**\r\n * Mesh side orientation : both internal and external or front and back surfaces\r\n */\r\n public static readonly DOUBLESIDE = VertexData.DOUBLESIDE;\r\n /**\r\n * Mesh side orientation : by default, `FRONTSIDE`\r\n */\r\n public static readonly DEFAULTSIDE = VertexData.DEFAULTSIDE;\r\n /**\r\n * Mesh cap setting : no cap\r\n */\r\n public static readonly NO_CAP = 0;\r\n /**\r\n * Mesh cap setting : one cap at the beginning of the mesh\r\n */\r\n public static readonly CAP_START = 1;\r\n /**\r\n * Mesh cap setting : one cap at the end of the mesh\r\n */\r\n public static readonly CAP_END = 2;\r\n /**\r\n * Mesh cap setting : two caps, one at the beginning and one at the end of the mesh\r\n */\r\n public static readonly CAP_ALL = 3;\r\n /**\r\n * Mesh pattern setting : no flip or rotate\r\n */\r\n public static readonly NO_FLIP = 0;\r\n /**\r\n * Mesh pattern setting : flip (reflect in y axis) alternate tiles on each row or column\r\n */\r\n public static readonly FLIP_TILE = 1;\r\n /**\r\n * Mesh pattern setting : rotate (180degs) alternate tiles on each row or column\r\n */\r\n public static readonly ROTATE_TILE = 2;\r\n /**\r\n * Mesh pattern setting : flip (reflect in y axis) all tiles on alternate rows\r\n */\r\n public static readonly FLIP_ROW = 3;\r\n /**\r\n * Mesh pattern setting : rotate (180degs) all tiles on alternate rows\r\n */\r\n public static readonly ROTATE_ROW = 4;\r\n /**\r\n * Mesh pattern setting : flip and rotate alternate tiles on each row or column\r\n */\r\n public static readonly FLIP_N_ROTATE_TILE = 5;\r\n /**\r\n * Mesh pattern setting : rotate pattern and rotate\r\n */\r\n public static readonly FLIP_N_ROTATE_ROW = 6;\r\n /**\r\n * Mesh tile positioning : part tiles same on left/right or top/bottom\r\n */\r\n public static readonly CENTER = 0;\r\n /**\r\n * Mesh tile positioning : part tiles on left\r\n */\r\n public static readonly LEFT = 1;\r\n /**\r\n * Mesh tile positioning : part tiles on right\r\n */\r\n public static readonly RIGHT = 2;\r\n /**\r\n * Mesh tile positioning : part tiles on top\r\n */\r\n public static readonly TOP = 3;\r\n /**\r\n * Mesh tile positioning : part tiles on bottom\r\n */\r\n public static readonly BOTTOM = 4;\r\n\r\n /**\r\n * Indicates that the instanced meshes should be sorted from back to front before rendering if their material is transparent\r\n */\r\n public static INSTANCEDMESH_SORT_TRANSPARENT = false;\r\n\r\n /**\r\n * Gets the default side orientation.\r\n * @param orientation the orientation to value to attempt to get\r\n * @returns the default orientation\r\n * @internal\r\n */\r\n public static _GetDefaultSideOrientation(orientation?: number): number {\r\n return orientation || Mesh.FRONTSIDE; // works as Mesh.FRONTSIDE is 0\r\n }\r\n\r\n // Internal data\r\n private _internalMeshDataInfo = new _InternalMeshDataInfo();\r\n\r\n /**\r\n * Determines if the LOD levels are intended to be calculated using screen coverage (surface area ratio) instead of distance.\r\n */\r\n public get useLODScreenCoverage() {\r\n return this._internalMeshDataInfo._useLODScreenCoverage;\r\n }\r\n\r\n public set useLODScreenCoverage(value: boolean) {\r\n this._internalMeshDataInfo._useLODScreenCoverage = value;\r\n this._sortLODLevels();\r\n }\r\n\r\n /**\r\n * Will notify when the mesh is completely ready, including materials.\r\n * Observers added to this observable will be removed once triggered\r\n */\r\n public onMeshReadyObservable: Observable;\r\n\r\n public get computeBonesUsingShaders(): boolean {\r\n return this._internalAbstractMeshDataInfo._computeBonesUsingShaders;\r\n }\r\n public set computeBonesUsingShaders(value: boolean) {\r\n if (this._internalAbstractMeshDataInfo._computeBonesUsingShaders === value) {\r\n return;\r\n }\r\n\r\n if (value && this._internalMeshDataInfo._sourcePositions) {\r\n // switch from software to GPU computation: we need to reset the vertex and normal buffers that have been updated by the software process\r\n this.setVerticesData(VertexBuffer.PositionKind, this._internalMeshDataInfo._sourcePositions, true);\r\n if (this._internalMeshDataInfo._sourceNormals) {\r\n this.setVerticesData(VertexBuffer.NormalKind, this._internalMeshDataInfo._sourceNormals, true);\r\n }\r\n\r\n this._internalMeshDataInfo._sourcePositions = null;\r\n this._internalMeshDataInfo._sourceNormals = null;\r\n }\r\n\r\n this._internalAbstractMeshDataInfo._computeBonesUsingShaders = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n\r\n /**\r\n * An event triggered before rendering the mesh\r\n */\r\n public get onBeforeRenderObservable(): Observable {\r\n if (!this._internalMeshDataInfo._onBeforeRenderObservable) {\r\n this._internalMeshDataInfo._onBeforeRenderObservable = new Observable();\r\n }\r\n\r\n return this._internalMeshDataInfo._onBeforeRenderObservable;\r\n }\r\n\r\n /**\r\n * An event triggered before binding the mesh\r\n */\r\n public get onBeforeBindObservable(): Observable {\r\n if (!this._internalMeshDataInfo._onBeforeBindObservable) {\r\n this._internalMeshDataInfo._onBeforeBindObservable = new Observable();\r\n }\r\n\r\n return this._internalMeshDataInfo._onBeforeBindObservable;\r\n }\r\n\r\n /**\r\n * An event triggered after rendering the mesh\r\n */\r\n public get onAfterRenderObservable(): Observable {\r\n if (!this._internalMeshDataInfo._onAfterRenderObservable) {\r\n this._internalMeshDataInfo._onAfterRenderObservable = new Observable();\r\n }\r\n\r\n return this._internalMeshDataInfo._onAfterRenderObservable;\r\n }\r\n\r\n /**\r\n * An event triggeredbetween rendering pass when using separateCullingPass = true\r\n */\r\n public get onBetweenPassObservable(): Observable {\r\n if (!this._internalMeshDataInfo._onBetweenPassObservable) {\r\n this._internalMeshDataInfo._onBetweenPassObservable = new Observable();\r\n }\r\n\r\n return this._internalMeshDataInfo._onBetweenPassObservable;\r\n }\r\n\r\n /**\r\n * An event triggered before drawing the mesh\r\n */\r\n public get onBeforeDrawObservable(): Observable {\r\n if (!this._internalMeshDataInfo._onBeforeDrawObservable) {\r\n this._internalMeshDataInfo._onBeforeDrawObservable = new Observable();\r\n }\r\n\r\n return this._internalMeshDataInfo._onBeforeDrawObservable;\r\n }\r\n\r\n private _onBeforeDrawObserver: Nullable>;\r\n\r\n /**\r\n * Sets a callback to call before drawing the mesh. It is recommended to use onBeforeDrawObservable instead\r\n */\r\n public set onBeforeDraw(callback: () => void) {\r\n if (this._onBeforeDrawObserver) {\r\n this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver);\r\n }\r\n this._onBeforeDrawObserver = this.onBeforeDrawObservable.add(callback);\r\n }\r\n\r\n public get hasInstances(): boolean {\r\n return this.instances.length > 0;\r\n }\r\n\r\n public get hasThinInstances(): boolean {\r\n return (this._thinInstanceDataStorage.instancesCount ?? 0) > 0;\r\n }\r\n\r\n // Members\r\n\r\n /**\r\n * Gets the delay loading state of the mesh (when delay loading is turned on)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/incrementalLoading\r\n */\r\n public delayLoadState = Constants.DELAYLOADSTATE_NONE;\r\n\r\n /**\r\n * Gets the list of instances created from this mesh\r\n * it is not supposed to be modified manually.\r\n * Note also that the order of the InstancedMesh wihin the array is not significant and might change.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\r\n */\r\n public instances = new Array();\r\n\r\n /**\r\n * Gets the file containing delay loading data for this mesh\r\n */\r\n public delayLoadingFile: string;\r\n\r\n /** @internal */\r\n public _binaryInfo: any;\r\n\r\n /**\r\n * User defined function used to change how LOD level selection is done\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\r\n */\r\n public onLODLevelSelection: (distance: number, mesh: Mesh, selectedLevel: Nullable) => void;\r\n\r\n // Private\r\n /** @internal */\r\n public _creationDataStorage: Nullable<_CreationDataStorage> = null;\r\n\r\n /** @internal */\r\n public _geometry: Nullable = null;\r\n /** @internal */\r\n public _delayInfo: Array;\r\n /** @internal */\r\n public _delayLoadingFunction: (any: any, mesh: Mesh) => void;\r\n\r\n /**\r\n * Gets or sets the forced number of instances to display.\r\n * If 0 (default value), the number of instances is not forced and depends on the draw type\r\n * (regular / instance / thin instances mesh)\r\n */\r\n public get forcedInstanceCount(): number {\r\n return this._internalMeshDataInfo._forcedInstanceCount;\r\n }\r\n\r\n public set forcedInstanceCount(count: number) {\r\n this._internalMeshDataInfo._forcedInstanceCount = count;\r\n }\r\n\r\n /** @internal */\r\n public _instanceDataStorage = new _InstanceDataStorage();\r\n\r\n /** @internal */\r\n public _thinInstanceDataStorage = new _ThinInstanceDataStorage();\r\n\r\n /** @internal */\r\n public _shouldGenerateFlatShading: boolean = false;\r\n\r\n // Use by builder only to know what orientation were the mesh build in.\r\n /** @internal */\r\n public _originalBuilderSideOrientation: number = Mesh.DEFAULTSIDE;\r\n\r\n /**\r\n * Use this property to change the original side orientation defined at construction time\r\n */\r\n public overrideMaterialSideOrientation: Nullable = null;\r\n\r\n /**\r\n * Use this property to override the Material's fillMode value\r\n */\r\n public get overrideRenderingFillMode(): Nullable {\r\n return this._internalMeshDataInfo._overrideRenderingFillMode;\r\n }\r\n\r\n public set overrideRenderingFillMode(fillMode: Nullable) {\r\n this._internalMeshDataInfo._overrideRenderingFillMode = fillMode;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating whether to render ignoring the active camera's max z setting. (false by default)\r\n * You should not mix meshes that have this property set to true with meshes that have it set to false if they all write\r\n * to the depth buffer, because the z-values are not comparable in the two cases and you will get rendering artifacts if you do.\r\n * You can set the property to true for meshes that do not write to the depth buffer, or set the same value (either false or true) otherwise.\r\n * Note this will reduce performance when set to true.\r\n */\r\n public ignoreCameraMaxZ = false;\r\n\r\n /**\r\n * Gets the source mesh (the one used to clone this one from)\r\n */\r\n public get source(): Nullable {\r\n return this._internalMeshDataInfo._source;\r\n }\r\n\r\n /**\r\n * Gets the list of clones of this mesh\r\n * The scene must have been constructed with useClonedMeshMap=true for this to work!\r\n * Note that useClonedMeshMap=true is the default setting\r\n */\r\n public get cloneMeshMap(): Nullable<{ [id: string]: Mesh | undefined }> {\r\n return this._internalMeshDataInfo.meshMap;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this mesh does not use index buffer\r\n */\r\n public get isUnIndexed(): boolean {\r\n return this._unIndexed;\r\n }\r\n\r\n public set isUnIndexed(value: boolean) {\r\n if (this._unIndexed !== value) {\r\n this._unIndexed = value;\r\n this._markSubMeshesAsAttributesDirty();\r\n }\r\n }\r\n\r\n /** Gets the array buffer used to store the instanced buffer used for instances' world matrices */\r\n public get worldMatrixInstancedBuffer() {\r\n return this._instanceDataStorage.instancesData;\r\n }\r\n\r\n /** Gets the array buffer used to store the instanced buffer used for instances' previous world matrices */\r\n public get previousWorldMatrixInstancedBuffer() {\r\n return this._instanceDataStorage.instancesPreviousData;\r\n }\r\n\r\n /** Gets or sets a boolean indicating that the update of the instance buffer of the world matrices is manual */\r\n public get manualUpdateOfWorldMatrixInstancedBuffer() {\r\n return this._instanceDataStorage.manualUpdate;\r\n }\r\n\r\n public set manualUpdateOfWorldMatrixInstancedBuffer(value: boolean) {\r\n this._instanceDataStorage.manualUpdate = value;\r\n }\r\n\r\n /** Gets or sets a boolean indicating that the update of the instance buffer of the world matrices is manual */\r\n public get manualUpdateOfPreviousWorldMatrixInstancedBuffer() {\r\n return this._instanceDataStorage.previousManualUpdate;\r\n }\r\n\r\n public set manualUpdateOfPreviousWorldMatrixInstancedBuffer(value: boolean) {\r\n this._instanceDataStorage.previousManualUpdate = value;\r\n }\r\n\r\n /** Gets or sets a boolean indicating that the update of the instance buffer of the world matrices must be performed in all cases (and notably even in frozen mode) */\r\n public get forceWorldMatrixInstancedBufferUpdate() {\r\n return this._instanceDataStorage.forceMatrixUpdates;\r\n }\r\n\r\n public set forceWorldMatrixInstancedBufferUpdate(value: boolean) {\r\n this._instanceDataStorage.forceMatrixUpdates = value;\r\n }\r\n\r\n /**\r\n * @constructor\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param scene The scene to add this mesh to.\r\n * @param parent The parent of this mesh, if it has one\r\n * @param source An optional Mesh from which geometry is shared, cloned.\r\n * @param doNotCloneChildren When cloning, skip cloning child meshes of source, default False.\r\n * When false, achieved by calling a clone(), also passing False.\r\n * This will make creation of children, recursive.\r\n * @param clonePhysicsImpostor When cloning, include cloning mesh physics impostor, default True.\r\n */\r\n constructor(\r\n name: string,\r\n scene: Nullable = null,\r\n parent: Nullable = null,\r\n source: Nullable = null,\r\n doNotCloneChildren?: boolean,\r\n clonePhysicsImpostor: boolean = true\r\n ) {\r\n super(name, scene);\r\n\r\n scene = this.getScene();\r\n\r\n this._onBeforeDraw = (isInstance: boolean, world: Matrix, effectiveMaterial?: Material) => {\r\n if (isInstance && effectiveMaterial) {\r\n if (this._uniformBuffer) {\r\n this.transferToEffect(world);\r\n } else {\r\n effectiveMaterial.bindOnlyWorldMatrix(world);\r\n }\r\n }\r\n };\r\n\r\n if (source) {\r\n // Geometry\r\n if (source._geometry) {\r\n source._geometry.applyToMesh(this);\r\n }\r\n\r\n // Deep copy\r\n DeepCopier.DeepCopy(\r\n source,\r\n this,\r\n [\r\n \"name\",\r\n \"material\",\r\n \"skeleton\",\r\n \"instances\",\r\n \"parent\",\r\n \"uniqueId\",\r\n \"source\",\r\n \"metadata\",\r\n \"morphTargetManager\",\r\n \"hasInstances\",\r\n \"worldMatrixInstancedBuffer\",\r\n \"previousWorldMatrixInstancedBuffer\",\r\n \"hasLODLevels\",\r\n \"geometry\",\r\n \"isBlocked\",\r\n \"areNormalsFrozen\",\r\n \"facetNb\",\r\n \"isFacetDataEnabled\",\r\n \"lightSources\",\r\n \"useBones\",\r\n \"isAnInstance\",\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 \"cloneMeshMap\",\r\n \"hasBoundingInfo\",\r\n \"physicsBody\",\r\n \"physicsImpostor\",\r\n ],\r\n [\"_poseMatrix\"]\r\n );\r\n\r\n // Source mesh\r\n this._internalMeshDataInfo._source = source;\r\n if (scene.useClonedMeshMap) {\r\n if (!source._internalMeshDataInfo.meshMap) {\r\n source._internalMeshDataInfo.meshMap = {};\r\n }\r\n source._internalMeshDataInfo.meshMap[this.uniqueId] = this;\r\n }\r\n\r\n // Construction Params\r\n // Clone parameters allowing mesh to be updated in case of parametric shapes.\r\n this._originalBuilderSideOrientation = source._originalBuilderSideOrientation;\r\n this._creationDataStorage = source._creationDataStorage;\r\n\r\n // Animation ranges\r\n if (source._ranges) {\r\n const ranges = source._ranges;\r\n for (const name in ranges) {\r\n if (!Object.prototype.hasOwnProperty.call(ranges, name)) {\r\n continue;\r\n }\r\n\r\n if (!ranges[name]) {\r\n continue;\r\n }\r\n\r\n this.createAnimationRange(name, ranges[name]!.from, ranges[name]!.to);\r\n }\r\n }\r\n\r\n // Metadata\r\n if (source.metadata && source.metadata.clone) {\r\n this.metadata = source.metadata.clone();\r\n } else {\r\n this.metadata = source.metadata;\r\n }\r\n this._internalMetadata = source._internalMetadata;\r\n\r\n // Tags\r\n if (Tags && Tags.HasTags(source)) {\r\n Tags.AddTagsTo(this, Tags.GetTags(source, true));\r\n }\r\n\r\n // Enabled. We shouldn't need to check the source's ancestors, as this mesh\r\n // will have the same ones.\r\n this.setEnabled(source.isEnabled(false));\r\n\r\n // Parent\r\n this.parent = source.parent;\r\n\r\n // Pivot\r\n this.setPivotMatrix(source.getPivotMatrix());\r\n\r\n this.id = name + \".\" + source.id;\r\n\r\n // Material\r\n this.material = source.material;\r\n\r\n if (!doNotCloneChildren) {\r\n // Children\r\n const directDescendants = source.getDescendants(true);\r\n for (let index = 0; index < directDescendants.length; index++) {\r\n const child = directDescendants[index];\r\n\r\n if ((child).clone) {\r\n (child).clone(name + \".\" + child.name, this);\r\n }\r\n }\r\n }\r\n\r\n // Morphs\r\n if (source.morphTargetManager) {\r\n this.morphTargetManager = source.morphTargetManager;\r\n }\r\n\r\n // Physics clone\r\n if (scene.getPhysicsEngine) {\r\n const physicsEngine = scene.getPhysicsEngine();\r\n if (clonePhysicsImpostor && physicsEngine) {\r\n if (physicsEngine.getPluginVersion() === 1) {\r\n const impostor = (physicsEngine as PhysicsEngineV1).getImpostorForPhysicsObject(source);\r\n if (impostor) {\r\n this.physicsImpostor = impostor.clone(this);\r\n }\r\n } else if (physicsEngine.getPluginVersion() === 2) {\r\n if (source.physicsBody) {\r\n source.physicsBody.clone(this);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Particles\r\n for (let index = 0; index < scene.particleSystems.length; index++) {\r\n const system = scene.particleSystems[index];\r\n\r\n if (system.emitter === source) {\r\n system.clone(system.name, this);\r\n }\r\n }\r\n\r\n // Skeleton\r\n this.skeleton = source.skeleton;\r\n\r\n this.refreshBoundingInfo(true, true);\r\n this.computeWorldMatrix(true);\r\n }\r\n\r\n // Parent\r\n if (parent !== null) {\r\n this.parent = parent;\r\n }\r\n\r\n this._instanceDataStorage.hardwareInstancedRendering = this.getEngine().getCaps().instancedArrays;\r\n\r\n this._internalMeshDataInfo._onMeshReadyObserverAdded = (observer: Observer) => {\r\n // only notify once! then unregister the observer\r\n observer.unregisterOnNextCall = true;\r\n if (this.isReady(true)) {\r\n this.onMeshReadyObservable.notifyObservers(this);\r\n } else {\r\n if (!this._internalMeshDataInfo._checkReadinessObserver) {\r\n this._internalMeshDataInfo._checkReadinessObserver = this._scene.onBeforeRenderObservable.add(() => {\r\n // check for complete readiness\r\n if (this.isReady(true)) {\r\n this._scene.onBeforeRenderObservable.remove(this._internalMeshDataInfo._checkReadinessObserver);\r\n this._internalMeshDataInfo._checkReadinessObserver = null;\r\n this.onMeshReadyObservable.notifyObservers(this);\r\n }\r\n });\r\n }\r\n }\r\n };\r\n\r\n this.onMeshReadyObservable = new Observable(this._internalMeshDataInfo._onMeshReadyObserverAdded);\r\n\r\n if (source) {\r\n source.onClonedObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n public instantiateHierarchy(\r\n newParent: Nullable = null,\r\n options?: { doNotInstantiate: boolean | ((node: TransformNode) => boolean) },\r\n onNewNodeCreated?: (source: TransformNode, clone: TransformNode) => void\r\n ): Nullable {\r\n const instance =\r\n this.getTotalVertices() === 0 || (options && options.doNotInstantiate && (options.doNotInstantiate === true || options.doNotInstantiate(this)))\r\n ? this.clone(\"Clone of \" + (this.name || this.id), newParent || this.parent, true)\r\n : this.createInstance(\"instance of \" + (this.name || this.id));\r\n\r\n instance.parent = newParent || this.parent;\r\n instance.position = this.position.clone();\r\n instance.scaling = this.scaling.clone();\r\n if (this.rotationQuaternion) {\r\n instance.rotationQuaternion = this.rotationQuaternion.clone();\r\n } else {\r\n instance.rotation = this.rotation.clone();\r\n }\r\n\r\n if (onNewNodeCreated) {\r\n onNewNodeCreated(this, instance);\r\n }\r\n\r\n for (const child of this.getChildTransformNodes(true)) {\r\n // instancedMesh should have a different sourced mesh\r\n if (child.getClassName() === \"InstancedMesh\" && instance.getClassName() === \"Mesh\" && (child as InstancedMesh).sourceMesh === this) {\r\n (child as InstancedMesh).instantiateHierarchy(\r\n instance,\r\n {\r\n doNotInstantiate: (options && options.doNotInstantiate) || false,\r\n newSourcedMesh: instance as Mesh,\r\n },\r\n onNewNodeCreated\r\n );\r\n } else {\r\n child.instantiateHierarchy(instance, options, onNewNodeCreated);\r\n }\r\n }\r\n\r\n return instance;\r\n }\r\n\r\n /**\r\n * Gets the class name\r\n * @returns the string \"Mesh\".\r\n */\r\n public getClassName(): string {\r\n return \"Mesh\";\r\n }\r\n\r\n /** @internal */\r\n public get _isMesh() {\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns a description of this mesh\r\n * @param fullDetails define if full details about this mesh must be used\r\n * @returns a descriptive string representing this mesh\r\n */\r\n public toString(fullDetails?: boolean): string {\r\n let ret = super.toString(fullDetails);\r\n ret += \", n vertices: \" + this.getTotalVertices();\r\n ret += \", parent: \" + (this._waitingParentId ? this._waitingParentId : this.parent ? this.parent.name : \"NONE\");\r\n\r\n if (this.animations) {\r\n for (let i = 0; i < this.animations.length; i++) {\r\n ret += \", animation[0]: \" + this.animations[i].toString(fullDetails);\r\n }\r\n }\r\n\r\n if (fullDetails) {\r\n if (this._geometry) {\r\n const ib = this.getIndices();\r\n const vb = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (vb && ib) {\r\n ret += \", flat shading: \" + (vb.length / 3 === ib.length ? \"YES\" : \"NO\");\r\n }\r\n } else {\r\n ret += \", flat shading: UNKNOWN\";\r\n }\r\n }\r\n return ret;\r\n }\r\n\r\n /** @internal */\r\n public _unBindEffect() {\r\n super._unBindEffect();\r\n\r\n for (const instance of this.instances) {\r\n instance._unBindEffect();\r\n }\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if this mesh has LOD\r\n */\r\n public get hasLODLevels(): boolean {\r\n return this._internalMeshDataInfo._LODLevels.length > 0;\r\n }\r\n\r\n /**\r\n * Gets the list of MeshLODLevel associated with the current mesh\r\n * @returns an array of MeshLODLevel\r\n */\r\n public getLODLevels(): MeshLODLevel[] {\r\n return this._internalMeshDataInfo._LODLevels;\r\n }\r\n\r\n private _sortLODLevels(): void {\r\n const sortingOrderFactor = this._internalMeshDataInfo._useLODScreenCoverage ? -1 : 1;\r\n this._internalMeshDataInfo._LODLevels.sort((a, b) => {\r\n if (a.distanceOrScreenCoverage < b.distanceOrScreenCoverage) {\r\n return sortingOrderFactor;\r\n }\r\n if (a.distanceOrScreenCoverage > b.distanceOrScreenCoverage) {\r\n return -sortingOrderFactor;\r\n }\r\n\r\n return 0;\r\n });\r\n }\r\n\r\n /**\r\n * Add a mesh as LOD level triggered at the given distance.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\r\n * @param distanceOrScreenCoverage Either distance from the center of the object to show this level or the screen coverage if `useScreenCoverage` is set to `true`.\r\n * If screen coverage, value is a fraction of the screen's total surface, between 0 and 1.\r\n * Example Playground for distance https://playground.babylonjs.com/#QE7KM#197\r\n * Example Playground for screen coverage https://playground.babylonjs.com/#QE7KM#196\r\n * @param mesh The mesh to be added as LOD level (can be null)\r\n * @returns This mesh (for chaining)\r\n */\r\n public addLODLevel(distanceOrScreenCoverage: number, mesh: Nullable): Mesh {\r\n if (mesh && mesh._masterMesh) {\r\n Logger.Warn(\"You cannot use a mesh as LOD level twice\");\r\n return this;\r\n }\r\n\r\n const level = new MeshLODLevel(distanceOrScreenCoverage, mesh);\r\n this._internalMeshDataInfo._LODLevels.push(level);\r\n\r\n if (mesh) {\r\n mesh._masterMesh = this;\r\n }\r\n\r\n this._sortLODLevels();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the LOD level mesh at the passed distance or null if not found.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\r\n * @param distance The distance from the center of the object to show this level\r\n * @returns a Mesh or `null`\r\n */\r\n public getLODLevelAtDistance(distance: number): Nullable {\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n for (let index = 0; index < internalDataInfo._LODLevels.length; index++) {\r\n const level = internalDataInfo._LODLevels[index];\r\n\r\n if (level.distanceOrScreenCoverage === distance) {\r\n return level.mesh;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Remove a mesh from the LOD array\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\r\n * @param mesh defines the mesh to be removed\r\n * @returns This mesh (for chaining)\r\n */\r\n public removeLODLevel(mesh: Nullable): Mesh {\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n for (let index = 0; index < internalDataInfo._LODLevels.length; index++) {\r\n if (internalDataInfo._LODLevels[index].mesh === mesh) {\r\n internalDataInfo._LODLevels.splice(index, 1);\r\n if (mesh) {\r\n mesh._masterMesh = null;\r\n }\r\n }\r\n }\r\n\r\n this._sortLODLevels();\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the registered LOD mesh distant from the parameter `camera` position if any, else returns the current mesh.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD\r\n * @param camera defines the camera to use to compute distance\r\n * @param boundingSphere defines a custom bounding sphere to use instead of the one from this mesh\r\n * @returns This mesh (for chaining)\r\n */\r\n public getLOD(camera: Camera, boundingSphere?: BoundingSphere): Nullable {\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n if (!internalDataInfo._LODLevels || internalDataInfo._LODLevels.length === 0) {\r\n return this;\r\n }\r\n\r\n const bSphere = boundingSphere || this.getBoundingInfo().boundingSphere;\r\n\r\n const distanceToCamera = camera.mode === Camera.ORTHOGRAPHIC_CAMERA ? camera.minZ : bSphere.centerWorld.subtract(camera.globalPosition).length();\r\n let compareValue = distanceToCamera;\r\n let compareSign = 1;\r\n\r\n if (internalDataInfo._useLODScreenCoverage) {\r\n const screenArea = camera.screenArea;\r\n let meshArea = (bSphere.radiusWorld * camera.minZ) / distanceToCamera;\r\n meshArea = meshArea * meshArea * Math.PI;\r\n compareValue = meshArea / screenArea;\r\n compareSign = -1;\r\n }\r\n\r\n if (compareSign * internalDataInfo._LODLevels[internalDataInfo._LODLevels.length - 1].distanceOrScreenCoverage > compareSign * compareValue) {\r\n if (this.onLODLevelSelection) {\r\n this.onLODLevelSelection(compareValue, this, this);\r\n }\r\n return this;\r\n }\r\n\r\n for (let index = 0; index < internalDataInfo._LODLevels.length; index++) {\r\n const level = internalDataInfo._LODLevels[index];\r\n\r\n if (compareSign * level.distanceOrScreenCoverage < compareSign * compareValue) {\r\n if (level.mesh) {\r\n if (level.mesh.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {\r\n level.mesh._checkDelayState();\r\n return this;\r\n }\r\n\r\n if (level.mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADING) {\r\n return this;\r\n }\r\n\r\n level.mesh._preActivate();\r\n level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\r\n }\r\n\r\n if (this.onLODLevelSelection) {\r\n this.onLODLevelSelection(compareValue, this, level.mesh);\r\n }\r\n\r\n return level.mesh;\r\n }\r\n }\r\n\r\n if (this.onLODLevelSelection) {\r\n this.onLODLevelSelection(compareValue, this, this);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the mesh internal Geometry object\r\n */\r\n public get geometry(): Nullable {\r\n return this._geometry;\r\n }\r\n\r\n /**\r\n * Returns the total number of vertices within the mesh geometry or zero if the mesh has no geometry.\r\n * @returns the total number of vertices\r\n */\r\n public getTotalVertices(): number {\r\n if (this._geometry === null || this._geometry === undefined) {\r\n return 0;\r\n }\r\n return this._geometry.getTotalVertices();\r\n }\r\n\r\n /**\r\n * Returns the content of an associated vertex buffer\r\n * @param kind defines which buffer to read from (positions, indices, normals, etc). 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 * @param copyWhenShared defines a boolean indicating that if the mesh geometry is shared among some other meshes, the returned array is a copy of the internal one\r\n * @param forceCopy defines a boolean forcing the copy of the buffer no matter what the value of copyWhenShared is\r\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\r\n * @returns a FloatArray or null if the mesh has no geometry or no vertex buffer for this kind.\r\n */\r\n public getVerticesData(kind: string, copyWhenShared?: boolean, forceCopy?: boolean, bypassInstanceData?: boolean): Nullable {\r\n if (!this._geometry) {\r\n return null;\r\n }\r\n let data = bypassInstanceData\r\n ? undefined\r\n : this._userInstancedBuffersStorage?.vertexBuffers[kind]?.getFloatData(\r\n this.instances.length + 1, // +1 because the master mesh is not included in the instances array\r\n forceCopy || (copyWhenShared && this._geometry.meshes.length !== 1)\r\n );\r\n if (!data) {\r\n data = this._geometry.getVerticesData(kind, copyWhenShared, forceCopy);\r\n }\r\n return data;\r\n }\r\n\r\n /**\r\n * Returns the mesh VertexBuffer object from the requested `kind`\r\n * @param kind defines which buffer to read from (positions, indices, normals, etc). Possible `kind` values :\r\n * - VertexBuffer.PositionKind\r\n * - VertexBuffer.NormalKind\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 * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\r\n * @returns a FloatArray or null if the mesh has no vertex buffer for this kind.\r\n */\r\n public getVertexBuffer(kind: string, bypassInstanceData?: boolean): Nullable {\r\n if (!this._geometry) {\r\n return null;\r\n }\r\n\r\n return (bypassInstanceData ? undefined : this._userInstancedBuffersStorage?.vertexBuffers[kind]) ?? this._geometry.getVertexBuffer(kind);\r\n }\r\n\r\n /**\r\n * Tests if a specific vertex buffer is associated with this mesh\r\n * @param kind defines which buffer to check (positions, indices, normals, etc). Possible `kind` values :\r\n * - VertexBuffer.PositionKind\r\n * - VertexBuffer.NormalKind\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 * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\r\n * @returns a boolean\r\n */\r\n public isVerticesDataPresent(kind: string, bypassInstanceData?: boolean): boolean {\r\n if (!this._geometry) {\r\n if (this._delayInfo) {\r\n return this._delayInfo.indexOf(kind) !== -1;\r\n }\r\n return false;\r\n }\r\n return (!bypassInstanceData && this._userInstancedBuffersStorage?.vertexBuffers[kind] !== undefined) || this._geometry.isVerticesDataPresent(kind);\r\n }\r\n\r\n /**\r\n * Returns a boolean defining if the vertex data for the requested `kind` is updatable.\r\n * @param kind defines which buffer to check (positions, indices, normals, etc). 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 * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\r\n * @returns a boolean\r\n */\r\n public isVertexBufferUpdatable(kind: string, bypassInstanceData?: boolean): boolean {\r\n if (!this._geometry) {\r\n if (this._delayInfo) {\r\n return this._delayInfo.indexOf(kind) !== -1;\r\n }\r\n return false;\r\n }\r\n if (!bypassInstanceData) {\r\n const buffer = this._userInstancedBuffersStorage?.vertexBuffers[kind];\r\n if (buffer) {\r\n return buffer.isUpdatable();\r\n }\r\n }\r\n return this._geometry.isVertexBufferUpdatable(kind);\r\n }\r\n\r\n /**\r\n * Returns a string which contains the list of existing `kinds` of Vertex Data associated with this mesh.\r\n * @param bypassInstanceData defines a boolean indicating that the function should not take into account the instance data (applies only if the mesh has instances). Default: false\r\n * @returns an array of strings\r\n */\r\n public getVerticesDataKinds(bypassInstanceData?: boolean): string[] {\r\n if (!this._geometry) {\r\n const result = new Array();\r\n if (this._delayInfo) {\r\n this._delayInfo.forEach(function (kind) {\r\n result.push(kind);\r\n });\r\n }\r\n return result;\r\n }\r\n const kinds = this._geometry.getVerticesDataKinds();\r\n if (!bypassInstanceData && this._userInstancedBuffersStorage) {\r\n for (const kind in this._userInstancedBuffersStorage.vertexBuffers) {\r\n if (kinds.indexOf(kind) === -1) {\r\n kinds.push(kind);\r\n }\r\n }\r\n }\r\n return kinds;\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 numner of indices or zero if the mesh has no geometry.\r\n */\r\n public getTotalIndices(): number {\r\n if (!this._geometry) {\r\n return 0;\r\n }\r\n return this._geometry.getTotalIndices();\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 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 * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns the indices array or an empty array if the mesh has no geometry\r\n */\r\n public getIndices(copyWhenShared?: boolean, forceCopy?: boolean): Nullable {\r\n if (!this._geometry) {\r\n return [];\r\n }\r\n return this._geometry.getIndices(copyWhenShared, forceCopy);\r\n }\r\n\r\n public get isBlocked(): boolean {\r\n return this._masterMesh !== null && this._masterMesh !== undefined;\r\n }\r\n\r\n /**\r\n * Determine if the current mesh is ready to be rendered\r\n * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)\r\n * @param forceInstanceSupport will check if the mesh will be ready when used with instances (false by default)\r\n * @returns true if all associated assets are ready (material, textures, shaders)\r\n */\r\n public isReady(completeCheck = false, forceInstanceSupport = false): boolean {\r\n if (this.delayLoadState === Constants.DELAYLOADSTATE_LOADING) {\r\n return false;\r\n }\r\n\r\n if (!super.isReady(completeCheck)) {\r\n return false;\r\n }\r\n\r\n if (!this.subMeshes || this.subMeshes.length === 0) {\r\n return true;\r\n }\r\n\r\n if (!completeCheck) {\r\n return true;\r\n }\r\n\r\n const engine = this.getEngine();\r\n const scene = this.getScene();\r\n const hardwareInstancedRendering = forceInstanceSupport || (engine.getCaps().instancedArrays && (this.instances.length > 0 || this.hasThinInstances));\r\n\r\n this.computeWorldMatrix();\r\n\r\n const mat = this.material || scene.defaultMaterial;\r\n if (mat) {\r\n if (mat._storeEffectOnSubMeshes) {\r\n for (const subMesh of this.subMeshes) {\r\n const effectiveMaterial = subMesh.getMaterial();\r\n if (effectiveMaterial) {\r\n if (effectiveMaterial._storeEffectOnSubMeshes) {\r\n if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {\r\n return false;\r\n }\r\n } else {\r\n if (!effectiveMaterial.isReady(this, hardwareInstancedRendering)) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n if (!mat.isReady(this, hardwareInstancedRendering)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n // Shadows\r\n const currentRenderPassId = engine.currentRenderPassId;\r\n for (const light of this.lightSources) {\r\n const generators = light.getShadowGenerators();\r\n\r\n if (!generators) {\r\n continue;\r\n }\r\n\r\n const iterator = generators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const generator = key.value;\r\n if (generator && (!generator.getShadowMap()?.renderList || (generator.getShadowMap()?.renderList && generator.getShadowMap()?.renderList?.indexOf(this) !== -1))) {\r\n const shadowMap = generator.getShadowMap()!;\r\n const renderPassIds = shadowMap.renderPassIds ?? [engine.currentRenderPassId];\r\n for (let p = 0; p < renderPassIds.length; ++p) {\r\n engine.currentRenderPassId = renderPassIds[p];\r\n for (const subMesh of this.subMeshes) {\r\n if (!generator.isReady(subMesh, hardwareInstancedRendering, subMesh.getMaterial()?.needAlphaBlendingForMesh(this) ?? false)) {\r\n engine.currentRenderPassId = currentRenderPassId;\r\n return false;\r\n }\r\n }\r\n }\r\n engine.currentRenderPassId = currentRenderPassId;\r\n }\r\n }\r\n }\r\n\r\n // LOD\r\n for (const lod of this._internalMeshDataInfo._LODLevels) {\r\n if (lod.mesh && !lod.mesh.isReady(hardwareInstancedRendering)) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the normals aren't to be recomputed on next mesh `positions` array update. This property is pertinent only for updatable parametric shapes.\r\n */\r\n public get areNormalsFrozen(): boolean {\r\n return this._internalMeshDataInfo._areNormalsFrozen;\r\n }\r\n\r\n /**\r\n * This function affects parametric shapes on vertex position update only : ribbons, tubes, etc. It has no effect at all on other shapes. It prevents the mesh normals from being recomputed on next `positions` array update.\r\n * @returns the current mesh\r\n */\r\n public freezeNormals(): Mesh {\r\n this._internalMeshDataInfo._areNormalsFrozen = true;\r\n return this;\r\n }\r\n\r\n /**\r\n * This function affects parametric shapes on vertex position update only : ribbons, tubes, etc. It has no effect at all on other shapes. It reactivates the mesh normals computation if it was previously frozen\r\n * @returns the current mesh\r\n */\r\n public unfreezeNormals(): Mesh {\r\n this._internalMeshDataInfo._areNormalsFrozen = false;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a value overriding the instance count. Only applicable when custom instanced InterleavedVertexBuffer are used rather than InstancedMeshs\r\n */\r\n public set overridenInstanceCount(count: number) {\r\n this._instanceDataStorage.overridenInstanceCount = count;\r\n }\r\n\r\n // Methods\r\n /** @internal */\r\n public _preActivate(): Mesh {\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n const sceneRenderId = this.getScene().getRenderId();\r\n if (internalDataInfo._preActivateId === sceneRenderId) {\r\n return this;\r\n }\r\n\r\n internalDataInfo._preActivateId = sceneRenderId;\r\n this._instanceDataStorage.visibleInstances = null;\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _preActivateForIntermediateRendering(renderId: number): Mesh {\r\n if (this._instanceDataStorage.visibleInstances) {\r\n this._instanceDataStorage.visibleInstances.intermediateDefaultRenderId = renderId;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _registerInstanceForRenderId(instance: InstancedMesh, renderId: number): Mesh {\r\n if (!this._instanceDataStorage.visibleInstances) {\r\n this._instanceDataStorage.visibleInstances = {\r\n defaultRenderId: renderId,\r\n selfDefaultRenderId: this._renderId,\r\n };\r\n }\r\n\r\n if (!this._instanceDataStorage.visibleInstances[renderId]) {\r\n if (this._instanceDataStorage.previousRenderId !== undefined && this._instanceDataStorage.isFrozen) {\r\n this._instanceDataStorage.visibleInstances[this._instanceDataStorage.previousRenderId] = null;\r\n }\r\n this._instanceDataStorage.previousRenderId = renderId;\r\n this._instanceDataStorage.visibleInstances[renderId] = new Array();\r\n }\r\n\r\n this._instanceDataStorage.visibleInstances[renderId].push(instance);\r\n return this;\r\n }\r\n\r\n protected _afterComputeWorldMatrix(): void {\r\n super._afterComputeWorldMatrix();\r\n\r\n if (!this.hasThinInstances) {\r\n return;\r\n }\r\n\r\n if (!this.doNotSyncBoundingInfo) {\r\n this.thinInstanceRefreshBoundingInfo(false);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _postActivate(): void {\r\n if (this.edgesShareWithInstances && this.edgesRenderer && this.edgesRenderer.isEnabled && this._renderingGroup) {\r\n this._renderingGroup._edgesRenderers.pushNoDuplicate(this.edgesRenderer);\r\n this.edgesRenderer.customInstances.push(this.getWorldMatrix());\r\n }\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): Mesh {\r\n if (this.hasBoundingInfo && this.getBoundingInfo().isLocked) {\r\n return this;\r\n }\r\n\r\n const bias = this.geometry ? this.geometry.boundingBias : null;\r\n this._refreshBoundingInfo(this._getPositionData(applySkeleton, applyMorph), bias);\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _createGlobalSubMesh(force: boolean): Nullable {\r\n const totalVertices = this.getTotalVertices();\r\n if (!totalVertices || !this.getIndices()) {\r\n return null;\r\n }\r\n\r\n // Check if we need to recreate the submeshes\r\n if (this.subMeshes && this.subMeshes.length > 0) {\r\n const ib = this.getIndices();\r\n\r\n if (!ib) {\r\n return null;\r\n }\r\n\r\n const totalIndices = ib.length;\r\n let needToRecreate = false;\r\n\r\n if (force) {\r\n needToRecreate = true;\r\n } else {\r\n for (const submesh of this.subMeshes) {\r\n if (submesh.indexStart + submesh.indexCount > totalIndices) {\r\n needToRecreate = true;\r\n break;\r\n }\r\n\r\n if (submesh.verticesStart + submesh.verticesCount > totalVertices) {\r\n needToRecreate = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (!needToRecreate) {\r\n return this.subMeshes[0];\r\n }\r\n }\r\n\r\n this.releaseSubMeshes();\r\n return new SubMesh(0, 0, totalVertices, 0, this.getTotalIndices(), this);\r\n }\r\n\r\n /**\r\n * This function will subdivide the mesh into multiple submeshes\r\n * @param count defines the expected number of submeshes\r\n */\r\n public subdivide(count: number): void {\r\n if (count < 1) {\r\n return;\r\n }\r\n\r\n const totalIndices = this.getTotalIndices();\r\n let subdivisionSize = (totalIndices / count) | 0;\r\n let offset = 0;\r\n\r\n // Ensure that subdivisionSize is a multiple of 3\r\n while (subdivisionSize % 3 !== 0) {\r\n subdivisionSize++;\r\n }\r\n\r\n this.releaseSubMeshes();\r\n for (let index = 0; index < count; index++) {\r\n if (offset >= totalIndices) {\r\n break;\r\n }\r\n\r\n SubMesh.CreateFromIndices(0, offset, index === count - 1 ? totalIndices - offset : subdivisionSize, this, undefined, false);\r\n\r\n offset += subdivisionSize;\r\n }\r\n\r\n this.refreshBoundingInfo();\r\n this.synchronizeInstances();\r\n }\r\n\r\n /**\r\n * Copy a FloatArray into a specific associated vertex buffer\r\n * @param kind defines which buffer to write to (positions, indices, normals, etc). 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 * @param data defines the data source\r\n * @param updatable defines if the updated vertex buffer must be flagged as updatable\r\n * @param stride defines the data stride size (can be null)\r\n * @returns the current mesh\r\n */\r\n public setVerticesData(kind: string, data: FloatArray, updatable: boolean = false, stride?: number): AbstractMesh {\r\n if (!this._geometry) {\r\n const vertexData = new VertexData();\r\n vertexData.set(data, kind);\r\n\r\n const scene = this.getScene();\r\n\r\n new Geometry(Geometry.RandomId(), scene, vertexData, updatable, this);\r\n } else {\r\n this._geometry.setVerticesData(kind, data, updatable, stride);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Delete a vertex buffer associated with this mesh\r\n * @param kind defines which buffer to delete (positions, indices, normals, etc). 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 public removeVerticesData(kind: string) {\r\n if (!this._geometry) {\r\n return;\r\n }\r\n\r\n this._geometry.removeVerticesData(kind);\r\n }\r\n\r\n /**\r\n * Flags an associated vertex buffer as updatable\r\n * @param kind defines which buffer to use (positions, indices, normals, etc). 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 * @param updatable defines if the updated vertex buffer must be flagged as updatable\r\n */\r\n public markVerticesDataAsUpdatable(kind: string, updatable = true) {\r\n const vb = this.getVertexBuffer(kind);\r\n\r\n if (!vb || vb.isUpdatable() === updatable) {\r\n return;\r\n }\r\n\r\n this.setVerticesData(kind, this.getVerticesData(kind), updatable);\r\n }\r\n\r\n /**\r\n * Sets the mesh global Vertex Buffer\r\n * @param buffer defines the buffer to use\r\n * @param disposeExistingBuffer disposes the existing buffer, if any (default: true)\r\n * @returns the current mesh\r\n */\r\n public setVerticesBuffer(buffer: VertexBuffer, disposeExistingBuffer = true): Mesh {\r\n if (!this._geometry) {\r\n this._geometry = Geometry.CreateGeometryForMesh(this);\r\n }\r\n\r\n this._geometry.setVerticesBuffer(buffer, null, disposeExistingBuffer);\r\n return this;\r\n }\r\n\r\n /**\r\n * Update a specific associated vertex buffer\r\n * @param kind defines which buffer to write to (positions, indices, normals, etc). 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 * @param data defines the data source\r\n * @param updateExtends defines if extends info of the mesh must be updated (can be null). This is mostly useful for \"position\" kind\r\n * @param makeItUnique defines if the geometry associated with the mesh must be cloned to make the change only for this mesh (and not all meshes associated with the same geometry)\r\n * @returns the current mesh\r\n */\r\n public updateVerticesData(kind: string, data: FloatArray, updateExtends?: boolean, makeItUnique?: boolean): AbstractMesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n if (!makeItUnique) {\r\n this._geometry.updateVerticesData(kind, data, updateExtends);\r\n } else {\r\n this.makeGeometryUnique();\r\n this.updateVerticesData(kind, data, updateExtends, false);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * This method updates the vertex positions of an updatable mesh according to the `positionFunction` returned values.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#other-shapes-updatemeshpositions\r\n * @param positionFunction is a simple JS function what is passed the mesh `positions` array. It doesn't need to return anything\r\n * @param computeNormals is a boolean (default true) to enable/disable the mesh normal recomputation after the vertex position update\r\n * @returns the current mesh\r\n */\r\n public updateMeshPositions(positionFunction: (data: FloatArray) => void, computeNormals: boolean = true): Mesh {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n if (!positions) {\r\n return this;\r\n }\r\n\r\n positionFunction(positions);\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\r\n\r\n if (computeNormals) {\r\n const indices = this.getIndices();\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n\r\n if (!normals) {\r\n return this;\r\n }\r\n\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a un-shared specific occurence of the geometry for the mesh.\r\n * @returns the current mesh\r\n */\r\n public makeGeometryUnique(): Mesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n\r\n if (this._geometry.meshes.length === 1) {\r\n return this;\r\n }\r\n\r\n const oldGeometry = this._geometry;\r\n const geometry = this._geometry.copy(Geometry.RandomId());\r\n oldGeometry.releaseForMesh(this, true);\r\n geometry.applyToMesh(this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the index buffer of this mesh\r\n * @param indices defines the source data\r\n * @param totalVertices defines the total number of vertices referenced by this index data (can be null)\r\n * @param updatable defines if the updated index buffer must be flagged as updatable (default is false)\r\n * @returns the current mesh\r\n */\r\n public setIndices(indices: IndicesArray, totalVertices: Nullable = null, updatable: boolean = false): AbstractMesh {\r\n if (!this._geometry) {\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n\r\n const scene = this.getScene();\r\n\r\n new Geometry(Geometry.RandomId(), scene, vertexData, updatable, this);\r\n } else {\r\n this._geometry.setIndices(indices, totalVertices, updatable);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Update the current index buffer\r\n * @param indices defines the source data\r\n * @param offset defines the offset in the index buffer where to store the new data (can be null)\r\n * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)\r\n * @returns the current mesh\r\n */\r\n public updateIndices(indices: IndicesArray, offset?: number, gpuMemoryOnly = false): AbstractMesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n\r\n this._geometry.updateIndices(indices, offset, gpuMemoryOnly);\r\n return this;\r\n }\r\n\r\n /**\r\n * Invert the geometry to move from a right handed system to a left handed one.\r\n * @returns the current mesh\r\n */\r\n public toLeftHanded(): Mesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n this._geometry.toLeftHanded();\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bind(subMesh: SubMesh, effect: Effect, fillMode: number, allowInstancedRendering = true): Mesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n\r\n const engine = this.getScene().getEngine();\r\n\r\n // Morph targets\r\n if (this.morphTargetManager && this.morphTargetManager.isUsingTextureForTargets) {\r\n this.morphTargetManager._bind(effect);\r\n }\r\n\r\n // Wireframe\r\n let indexToBind;\r\n if (this._unIndexed) {\r\n indexToBind = null;\r\n } else {\r\n switch (this._getRenderingFillMode(fillMode)) {\r\n case Material.PointFillMode:\r\n indexToBind = null;\r\n break;\r\n case Material.WireFrameFillMode:\r\n indexToBind = subMesh._getLinesIndexBuffer(this.getIndices(), engine);\r\n break;\r\n default:\r\n case Material.TriangleFillMode:\r\n indexToBind = this._geometry.getIndexBuffer();\r\n break;\r\n }\r\n }\r\n\r\n // VBOs\r\n if (!allowInstancedRendering || !this._userInstancedBuffersStorage || this.hasThinInstances) {\r\n this._geometry._bind(effect, indexToBind);\r\n } else {\r\n this._geometry._bind(effect, indexToBind, this._userInstancedBuffersStorage.vertexBuffers, this._userInstancedBuffersStorage.vertexArrayObjects);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number): Mesh {\r\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\r\n return this;\r\n }\r\n\r\n if (this._internalMeshDataInfo._onBeforeDrawObservable) {\r\n this._internalMeshDataInfo._onBeforeDrawObservable.notifyObservers(this);\r\n }\r\n\r\n const scene = this.getScene();\r\n const engine = scene.getEngine();\r\n\r\n if (this._unIndexed || fillMode == Material.PointFillMode) {\r\n // or triangles as points\r\n engine.drawArraysType(fillMode, subMesh.verticesStart, subMesh.verticesCount, this.forcedInstanceCount || instancesCount);\r\n } else if (fillMode == Material.WireFrameFillMode) {\r\n // Triangles as wireframe\r\n engine.drawElementsType(fillMode, 0, subMesh._linesIndexCount, this.forcedInstanceCount || instancesCount);\r\n } else {\r\n engine.drawElementsType(fillMode, subMesh.indexStart, subMesh.indexCount, this.forcedInstanceCount || instancesCount);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Registers for this mesh a javascript function called just before the rendering process\r\n * @param func defines the function to call before rendering this mesh\r\n * @returns the current mesh\r\n */\r\n public registerBeforeRender(func: (mesh: AbstractMesh) => void): Mesh {\r\n this.onBeforeRenderObservable.add(func);\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes a previously registered javascript function called before the rendering\r\n * @param func defines the function to remove\r\n * @returns the current mesh\r\n */\r\n public unregisterBeforeRender(func: (mesh: AbstractMesh) => void): Mesh {\r\n this.onBeforeRenderObservable.removeCallback(func);\r\n return this;\r\n }\r\n\r\n /**\r\n * Registers for this mesh a javascript function called just after the rendering is complete\r\n * @param func defines the function to call after rendering this mesh\r\n * @returns the current mesh\r\n */\r\n public registerAfterRender(func: (mesh: AbstractMesh) => void): Mesh {\r\n this.onAfterRenderObservable.add(func);\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes a previously registered javascript function called after the rendering.\r\n * @param func defines the function to remove\r\n * @returns the current mesh\r\n */\r\n public unregisterAfterRender(func: (mesh: AbstractMesh) => void): Mesh {\r\n this.onAfterRenderObservable.removeCallback(func);\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getInstancesRenderList(subMeshId: number, isReplacementMode: boolean = false): _InstancesBatch {\r\n if (this._instanceDataStorage.isFrozen) {\r\n if (isReplacementMode) {\r\n this._instanceDataStorage.batchCacheReplacementModeInFrozenMode.hardwareInstancedRendering[subMeshId] = false;\r\n this._instanceDataStorage.batchCacheReplacementModeInFrozenMode.renderSelf[subMeshId] = true;\r\n return this._instanceDataStorage.batchCacheReplacementModeInFrozenMode;\r\n }\r\n if (this._instanceDataStorage.previousBatch) {\r\n return this._instanceDataStorage.previousBatch;\r\n }\r\n }\r\n const scene = this.getScene();\r\n const isInIntermediateRendering = scene._isInIntermediateRendering();\r\n const onlyForInstances = isInIntermediateRendering\r\n ? this._internalAbstractMeshDataInfo._onlyForInstancesIntermediate\r\n : this._internalAbstractMeshDataInfo._onlyForInstances;\r\n const batchCache = this._instanceDataStorage.batchCache;\r\n batchCache.mustReturn = false;\r\n batchCache.renderSelf[subMeshId] = isReplacementMode || (!onlyForInstances && this.isEnabled() && this.isVisible);\r\n batchCache.visibleInstances[subMeshId] = null;\r\n\r\n if (this._instanceDataStorage.visibleInstances && !isReplacementMode) {\r\n const visibleInstances = this._instanceDataStorage.visibleInstances;\r\n const currentRenderId = scene.getRenderId();\r\n const defaultRenderId = isInIntermediateRendering ? visibleInstances.intermediateDefaultRenderId : visibleInstances.defaultRenderId;\r\n batchCache.visibleInstances[subMeshId] = visibleInstances[currentRenderId];\r\n\r\n if (!batchCache.visibleInstances[subMeshId] && defaultRenderId) {\r\n batchCache.visibleInstances[subMeshId] = visibleInstances[defaultRenderId];\r\n }\r\n }\r\n batchCache.hardwareInstancedRendering[subMeshId] =\r\n !isReplacementMode &&\r\n this._instanceDataStorage.hardwareInstancedRendering &&\r\n batchCache.visibleInstances[subMeshId] !== null &&\r\n batchCache.visibleInstances[subMeshId] !== undefined;\r\n this._instanceDataStorage.previousBatch = batchCache;\r\n\r\n return batchCache;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _renderWithInstances(subMesh: SubMesh, fillMode: number, batch: _InstancesBatch, effect: Effect, engine: Engine): Mesh {\r\n const visibleInstances = batch.visibleInstances[subMesh._id];\r\n const visibleInstanceCount = visibleInstances ? visibleInstances.length : 0;\r\n\r\n const instanceStorage = this._instanceDataStorage;\r\n const currentInstancesBufferSize = instanceStorage.instancesBufferSize;\r\n let instancesBuffer = instanceStorage.instancesBuffer;\r\n let instancesPreviousBuffer = instanceStorage.instancesPreviousBuffer;\r\n const matricesCount = visibleInstanceCount + 1;\r\n const bufferSize = matricesCount * 16 * 4;\r\n\r\n while (instanceStorage.instancesBufferSize < bufferSize) {\r\n instanceStorage.instancesBufferSize *= 2;\r\n }\r\n\r\n if (!instanceStorage.instancesData || currentInstancesBufferSize != instanceStorage.instancesBufferSize) {\r\n instanceStorage.instancesData = new Float32Array(instanceStorage.instancesBufferSize / 4);\r\n }\r\n if ((this._scene.needsPreviousWorldMatrices && !instanceStorage.instancesPreviousData) || currentInstancesBufferSize != instanceStorage.instancesBufferSize) {\r\n instanceStorage.instancesPreviousData = new Float32Array(instanceStorage.instancesBufferSize / 4);\r\n }\r\n\r\n let offset = 0;\r\n let instancesCount = 0;\r\n\r\n const renderSelf = batch.renderSelf[subMesh._id];\r\n\r\n const needUpdateBuffer =\r\n !instancesBuffer ||\r\n currentInstancesBufferSize !== instanceStorage.instancesBufferSize ||\r\n (this._scene.needsPreviousWorldMatrices && !instanceStorage.instancesPreviousBuffer);\r\n\r\n if (!this._instanceDataStorage.manualUpdate && (!instanceStorage.isFrozen || needUpdateBuffer)) {\r\n const world = this.getWorldMatrix();\r\n if (renderSelf) {\r\n if (this._scene.needsPreviousWorldMatrices) {\r\n if (!instanceStorage.masterMeshPreviousWorldMatrix) {\r\n instanceStorage.masterMeshPreviousWorldMatrix = world.clone();\r\n instanceStorage.masterMeshPreviousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\r\n } else {\r\n instanceStorage.masterMeshPreviousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\r\n instanceStorage.masterMeshPreviousWorldMatrix.copyFrom(world);\r\n }\r\n }\r\n world.copyToArray(instanceStorage.instancesData, offset);\r\n offset += 16;\r\n instancesCount++;\r\n }\r\n\r\n if (visibleInstances) {\r\n if (Mesh.INSTANCEDMESH_SORT_TRANSPARENT && this._scene.activeCamera && subMesh.getMaterial()?.needAlphaBlendingForMesh(subMesh.getRenderingMesh())) {\r\n const cameraPosition = this._scene.activeCamera.globalPosition;\r\n for (let instanceIndex = 0; instanceIndex < visibleInstances.length; instanceIndex++) {\r\n const instanceMesh = visibleInstances[instanceIndex];\r\n instanceMesh._distanceToCamera = Vector3.Distance(instanceMesh.getBoundingInfo().boundingSphere.centerWorld, cameraPosition);\r\n }\r\n visibleInstances.sort((m1, m2) => {\r\n return m1._distanceToCamera > m2._distanceToCamera ? -1 : m1._distanceToCamera < m2._distanceToCamera ? 1 : 0;\r\n });\r\n }\r\n for (let instanceIndex = 0; instanceIndex < visibleInstances.length; instanceIndex++) {\r\n const instance = visibleInstances[instanceIndex];\r\n const matrix = instance.getWorldMatrix();\r\n matrix.copyToArray(instanceStorage.instancesData, offset);\r\n\r\n if (this._scene.needsPreviousWorldMatrices) {\r\n if (!instance._previousWorldMatrix) {\r\n instance._previousWorldMatrix = matrix.clone();\r\n instance._previousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\r\n } else {\r\n instance._previousWorldMatrix.copyToArray(instanceStorage.instancesPreviousData, offset);\r\n instance._previousWorldMatrix.copyFrom(matrix);\r\n }\r\n }\r\n\r\n offset += 16;\r\n instancesCount++;\r\n }\r\n }\r\n } else {\r\n instancesCount = (renderSelf ? 1 : 0) + visibleInstanceCount;\r\n }\r\n\r\n if (needUpdateBuffer) {\r\n if (instancesBuffer) {\r\n instancesBuffer.dispose();\r\n }\r\n\r\n if (instancesPreviousBuffer) {\r\n instancesPreviousBuffer.dispose();\r\n }\r\n\r\n instancesBuffer = new Buffer(engine, instanceStorage.instancesData, true, 16, false, true);\r\n instanceStorage.instancesBuffer = instancesBuffer;\r\n if (!this._userInstancedBuffersStorage) {\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 this._userInstancedBuffersStorage.vertexBuffers[\"world0\"] = instancesBuffer.createVertexBuffer(\"world0\", 0, 4);\r\n this._userInstancedBuffersStorage.vertexBuffers[\"world1\"] = instancesBuffer.createVertexBuffer(\"world1\", 4, 4);\r\n this._userInstancedBuffersStorage.vertexBuffers[\"world2\"] = instancesBuffer.createVertexBuffer(\"world2\", 8, 4);\r\n this._userInstancedBuffersStorage.vertexBuffers[\"world3\"] = instancesBuffer.createVertexBuffer(\"world3\", 12, 4);\r\n\r\n if (this._scene.needsPreviousWorldMatrices) {\r\n instancesPreviousBuffer = new Buffer(engine, instanceStorage.instancesPreviousData, true, 16, false, true);\r\n instanceStorage.instancesPreviousBuffer = instancesPreviousBuffer;\r\n\r\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld0\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld0\", 0, 4);\r\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld1\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld1\", 4, 4);\r\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld2\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld2\", 8, 4);\r\n this._userInstancedBuffersStorage.vertexBuffers[\"previousWorld3\"] = instancesPreviousBuffer.createVertexBuffer(\"previousWorld3\", 12, 4);\r\n }\r\n this._invalidateInstanceVertexArrayObject();\r\n } else {\r\n if (!this._instanceDataStorage.isFrozen || this._instanceDataStorage.forceMatrixUpdates) {\r\n instancesBuffer!.updateDirectly(instanceStorage.instancesData, 0, instancesCount);\r\n if (this._scene.needsPreviousWorldMatrices && (!this._instanceDataStorage.manualUpdate || this._instanceDataStorage.previousManualUpdate)) {\r\n instancesPreviousBuffer!.updateDirectly(instanceStorage.instancesPreviousData, 0, instancesCount);\r\n }\r\n }\r\n }\r\n\r\n this._processInstancedBuffers(visibleInstances, renderSelf);\r\n\r\n // Stats\r\n this.getScene()._activeIndices.addCount(subMesh.indexCount * instancesCount, false);\r\n\r\n // Draw\r\n if (engine._currentDrawContext) {\r\n engine._currentDrawContext.useInstancing = true;\r\n }\r\n this._bind(subMesh, effect, fillMode);\r\n this._draw(subMesh, fillMode, instancesCount);\r\n\r\n // Write current matrices as previous matrices in case of manual update\r\n // Default behaviour when previous matrices are not specified explicitly\r\n // Will break if instances number/order changes\r\n if (\r\n this._scene.needsPreviousWorldMatrices &&\r\n !needUpdateBuffer &&\r\n this._instanceDataStorage.manualUpdate &&\r\n (!this._instanceDataStorage.isFrozen || this._instanceDataStorage.forceMatrixUpdates) &&\r\n !this._instanceDataStorage.previousManualUpdate\r\n ) {\r\n instancesPreviousBuffer!.updateDirectly(instanceStorage.instancesData, 0, instancesCount);\r\n }\r\n\r\n engine.unbindInstanceAttributes();\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _renderWithThinInstances(subMesh: SubMesh, fillMode: number, effect: Effect, engine: Engine) {\r\n // Stats\r\n const instancesCount = this._thinInstanceDataStorage?.instancesCount ?? 0;\r\n\r\n this.getScene()._activeIndices.addCount(subMesh.indexCount * instancesCount, false);\r\n\r\n // Draw\r\n if (engine._currentDrawContext) {\r\n engine._currentDrawContext.useInstancing = true;\r\n }\r\n this._bind(subMesh, effect, fillMode);\r\n this._draw(subMesh, fillMode, instancesCount);\r\n\r\n // Write current matrices as previous matrices\r\n // Default behaviour when previous matrices are not specified explicitly\r\n // Will break if instances number/order changes\r\n if (this._scene.needsPreviousWorldMatrices && !this._thinInstanceDataStorage.previousMatrixData && this._thinInstanceDataStorage.matrixData) {\r\n if (!this._thinInstanceDataStorage.previousMatrixBuffer) {\r\n this._thinInstanceDataStorage.previousMatrixBuffer = this._thinInstanceCreateMatrixBuffer(\"previousWorld\", this._thinInstanceDataStorage.matrixData, false);\r\n } else {\r\n this._thinInstanceDataStorage.previousMatrixBuffer!.updateDirectly(this._thinInstanceDataStorage.matrixData, 0, instancesCount);\r\n }\r\n }\r\n\r\n engine.unbindInstanceAttributes();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _processInstancedBuffers(visibleInstances: Nullable, renderSelf: boolean) {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _processRendering(\r\n renderingMesh: AbstractMesh,\r\n subMesh: SubMesh,\r\n effect: Effect,\r\n fillMode: number,\r\n batch: _InstancesBatch,\r\n hardwareInstancedRendering: boolean,\r\n onBeforeDraw: (isInstance: boolean, world: Matrix, effectiveMaterial?: Material) => void,\r\n effectiveMaterial?: Material\r\n ): Mesh {\r\n const scene = this.getScene();\r\n const engine = scene.getEngine();\r\n fillMode = this._getRenderingFillMode(fillMode);\r\n\r\n if (hardwareInstancedRendering && subMesh.getRenderingMesh().hasThinInstances) {\r\n this._renderWithThinInstances(subMesh, fillMode, effect, engine);\r\n return this;\r\n }\r\n\r\n if (hardwareInstancedRendering) {\r\n this._renderWithInstances(subMesh, fillMode, batch, effect, engine);\r\n } else {\r\n if (engine._currentDrawContext) {\r\n engine._currentDrawContext.useInstancing = false;\r\n }\r\n\r\n let instanceCount = 0;\r\n if (batch.renderSelf[subMesh._id]) {\r\n // Draw\r\n if (onBeforeDraw) {\r\n onBeforeDraw(false, renderingMesh.getWorldMatrix(), effectiveMaterial);\r\n }\r\n instanceCount++;\r\n\r\n this._draw(subMesh, fillMode, this._instanceDataStorage.overridenInstanceCount);\r\n }\r\n\r\n const visibleInstancesForSubMesh = batch.visibleInstances[subMesh._id];\r\n\r\n if (visibleInstancesForSubMesh) {\r\n const visibleInstanceCount = visibleInstancesForSubMesh.length;\r\n instanceCount += visibleInstanceCount;\r\n\r\n // Stats\r\n for (let instanceIndex = 0; instanceIndex < visibleInstanceCount; instanceIndex++) {\r\n const instance = visibleInstancesForSubMesh[instanceIndex];\r\n\r\n // World\r\n const world = instance.getWorldMatrix();\r\n if (onBeforeDraw) {\r\n onBeforeDraw(true, world, effectiveMaterial);\r\n }\r\n // Draw\r\n this._draw(subMesh, fillMode);\r\n }\r\n }\r\n\r\n // Stats\r\n scene._activeIndices.addCount(subMesh.indexCount * instanceCount, false);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _rebuild(dispose = false): void {\r\n if (this._instanceDataStorage.instancesBuffer) {\r\n // Dispose instance buffer to be recreated in _renderWithInstances when rendered\r\n if (dispose) {\r\n this._instanceDataStorage.instancesBuffer.dispose();\r\n }\r\n this._instanceDataStorage.instancesBuffer = null;\r\n }\r\n if (this._userInstancedBuffersStorage) {\r\n for (const kind in this._userInstancedBuffersStorage.vertexBuffers) {\r\n const buffer = this._userInstancedBuffersStorage.vertexBuffers[kind];\r\n if (buffer) {\r\n // Dispose instance buffer to be recreated in _renderWithInstances when rendered\r\n if (dispose) {\r\n buffer.dispose();\r\n }\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = null;\r\n }\r\n }\r\n if (this._userInstancedBuffersStorage.vertexArrayObjects) {\r\n this._userInstancedBuffersStorage.vertexArrayObjects = {};\r\n }\r\n }\r\n this._internalMeshDataInfo._effectiveMaterial = null;\r\n super._rebuild(dispose);\r\n }\r\n\r\n /** @internal */\r\n public _freeze() {\r\n if (!this.subMeshes) {\r\n return;\r\n }\r\n\r\n // Prepare batches\r\n for (let index = 0; index < this.subMeshes.length; index++) {\r\n this._getInstancesRenderList(index);\r\n }\r\n\r\n this._internalMeshDataInfo._effectiveMaterial = null;\r\n this._instanceDataStorage.isFrozen = true;\r\n }\r\n\r\n /** @internal */\r\n public _unFreeze() {\r\n this._instanceDataStorage.isFrozen = false;\r\n this._instanceDataStorage.previousBatch = null;\r\n }\r\n\r\n /**\r\n * Triggers the draw call for the mesh. Usually, you don't need to call this method by your own because the mesh rendering is handled by the scene rendering manager\r\n * @param subMesh defines the subMesh to render\r\n * @param enableAlphaMode defines if alpha mode can be changed\r\n * @param effectiveMeshReplacement defines an optional mesh used to provide info for the rendering\r\n * @returns the current mesh\r\n */\r\n public render(subMesh: SubMesh, enableAlphaMode: boolean, effectiveMeshReplacement?: AbstractMesh): Mesh {\r\n const scene = this.getScene();\r\n\r\n if (this._internalAbstractMeshDataInfo._isActiveIntermediate) {\r\n this._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n } else {\r\n this._internalAbstractMeshDataInfo._isActive = false;\r\n }\r\n\r\n if (this._checkOcclusionQuery() && !this._occlusionDataStorage.forceRenderingWhenOccluded) {\r\n return this;\r\n }\r\n\r\n // Managing instances\r\n const batch = this._getInstancesRenderList(subMesh._id, !!effectiveMeshReplacement);\r\n\r\n if (batch.mustReturn) {\r\n return this;\r\n }\r\n\r\n // Checking geometry state\r\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\r\n return this;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n let oldCameraMaxZ = 0;\r\n let oldCamera: Nullable = null;\r\n if (this.ignoreCameraMaxZ && scene.activeCamera && !scene._isInIntermediateRendering()) {\r\n oldCameraMaxZ = scene.activeCamera.maxZ;\r\n oldCamera = scene.activeCamera;\r\n scene.activeCamera.maxZ = 0;\r\n scene.updateTransformMatrix(true);\r\n }\r\n\r\n if (this._internalMeshDataInfo._onBeforeRenderObservable) {\r\n this._internalMeshDataInfo._onBeforeRenderObservable.notifyObservers(this);\r\n }\r\n\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n const hardwareInstancedRendering =\r\n batch.hardwareInstancedRendering[subMesh._id] ||\r\n renderingMesh.hasThinInstances ||\r\n (!!this._userInstancedBuffersStorage && !subMesh.getMesh()._internalAbstractMeshDataInfo._actAsRegularMesh);\r\n const instanceDataStorage = this._instanceDataStorage;\r\n\r\n const material = subMesh.getMaterial();\r\n if (!material) {\r\n if (oldCamera) {\r\n oldCamera.maxZ = oldCameraMaxZ;\r\n scene.updateTransformMatrix(true);\r\n }\r\n return this;\r\n }\r\n\r\n // Material\r\n if (!instanceDataStorage.isFrozen || !this._internalMeshDataInfo._effectiveMaterial || this._internalMeshDataInfo._effectiveMaterial !== material) {\r\n if (material._storeEffectOnSubMeshes) {\r\n if (!material.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {\r\n if (oldCamera) {\r\n oldCamera.maxZ = oldCameraMaxZ;\r\n scene.updateTransformMatrix(true);\r\n }\r\n return this;\r\n }\r\n } else if (!material.isReady(this, hardwareInstancedRendering)) {\r\n if (oldCamera) {\r\n oldCamera.maxZ = oldCameraMaxZ;\r\n scene.updateTransformMatrix(true);\r\n }\r\n return this;\r\n }\r\n\r\n this._internalMeshDataInfo._effectiveMaterial = material;\r\n } else if (\r\n (material._storeEffectOnSubMeshes && !subMesh.effect?._wasPreviouslyReady) ||\r\n (!material._storeEffectOnSubMeshes && !material.getEffect()?._wasPreviouslyReady)\r\n ) {\r\n if (oldCamera) {\r\n oldCamera.maxZ = oldCameraMaxZ;\r\n scene.updateTransformMatrix(true);\r\n }\r\n return this;\r\n }\r\n\r\n // Alpha mode\r\n if (enableAlphaMode) {\r\n engine.setAlphaMode(this._internalMeshDataInfo._effectiveMaterial.alphaMode);\r\n }\r\n\r\n let drawWrapper: Nullable;\r\n if (this._internalMeshDataInfo._effectiveMaterial._storeEffectOnSubMeshes) {\r\n drawWrapper = subMesh._drawWrapper;\r\n } else {\r\n drawWrapper = this._internalMeshDataInfo._effectiveMaterial._getDrawWrapper();\r\n }\r\n\r\n const effect = drawWrapper?.effect ?? null;\r\n\r\n for (const step of scene._beforeRenderingMeshStage) {\r\n step.action(this, subMesh, batch, effect);\r\n }\r\n\r\n if (!drawWrapper || !effect) {\r\n if (oldCamera) {\r\n oldCamera.maxZ = oldCameraMaxZ;\r\n scene.updateTransformMatrix(true);\r\n }\r\n return this;\r\n }\r\n\r\n const effectiveMesh = effectiveMeshReplacement || this;\r\n\r\n let sideOrientation: Nullable;\r\n\r\n if (!instanceDataStorage.isFrozen && (this._internalMeshDataInfo._effectiveMaterial.backFaceCulling || this.overrideMaterialSideOrientation !== null)) {\r\n const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();\r\n sideOrientation = this.overrideMaterialSideOrientation;\r\n if (sideOrientation == null) {\r\n sideOrientation = this._internalMeshDataInfo._effectiveMaterial.sideOrientation;\r\n }\r\n if (mainDeterminant < 0) {\r\n sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;\r\n }\r\n instanceDataStorage.sideOrientation = sideOrientation!;\r\n } else {\r\n sideOrientation = instanceDataStorage.sideOrientation;\r\n }\r\n\r\n const reverse = this._internalMeshDataInfo._effectiveMaterial._preBind(drawWrapper, sideOrientation);\r\n\r\n if (this._internalMeshDataInfo._effectiveMaterial.forceDepthWrite) {\r\n engine.setDepthWrite(true);\r\n }\r\n\r\n // Bind\r\n const effectiveMaterial = this._internalMeshDataInfo._effectiveMaterial;\r\n const fillMode = effectiveMaterial.fillMode;\r\n\r\n if (this._internalMeshDataInfo._onBeforeBindObservable) {\r\n this._internalMeshDataInfo._onBeforeBindObservable.notifyObservers(this);\r\n }\r\n\r\n if (!hardwareInstancedRendering) {\r\n // Binding will be done later because we need to add more info to the VB\r\n this._bind(subMesh, effect, fillMode, false);\r\n }\r\n\r\n const world = effectiveMesh.getWorldMatrix();\r\n if (effectiveMaterial._storeEffectOnSubMeshes) {\r\n effectiveMaterial.bindForSubMesh(world, this, subMesh);\r\n } else {\r\n effectiveMaterial.bind(world, this);\r\n }\r\n\r\n if (!effectiveMaterial.backFaceCulling && effectiveMaterial.separateCullingPass) {\r\n engine.setState(true, effectiveMaterial.zOffset, false, !reverse, effectiveMaterial.cullBackFaces, effectiveMaterial.stencil, effectiveMaterial.zOffsetUnits);\r\n this._processRendering(this, subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, this._internalMeshDataInfo._effectiveMaterial);\r\n engine.setState(true, effectiveMaterial.zOffset, false, reverse, effectiveMaterial.cullBackFaces, effectiveMaterial.stencil, effectiveMaterial.zOffsetUnits);\r\n\r\n if (this._internalMeshDataInfo._onBetweenPassObservable) {\r\n this._internalMeshDataInfo._onBetweenPassObservable.notifyObservers(subMesh);\r\n }\r\n }\r\n\r\n // Draw\r\n this._processRendering(this, subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, this._internalMeshDataInfo._effectiveMaterial);\r\n\r\n // Unbind\r\n this._internalMeshDataInfo._effectiveMaterial.unbind();\r\n\r\n for (const step of scene._afterRenderingMeshStage) {\r\n step.action(this, subMesh, batch, effect);\r\n }\r\n\r\n if (this._internalMeshDataInfo._onAfterRenderObservable) {\r\n this._internalMeshDataInfo._onAfterRenderObservable.notifyObservers(this);\r\n }\r\n\r\n if (oldCamera) {\r\n oldCamera.maxZ = oldCameraMaxZ;\r\n scene.updateTransformMatrix(true);\r\n }\r\n\r\n if (scene.performancePriority === ScenePerformancePriority.Aggressive && !instanceDataStorage.isFrozen) {\r\n this._freeze();\r\n }\r\n\r\n return this;\r\n }\r\n\r\n private _onBeforeDraw: (isInstance: boolean, world: Matrix, effectiveMaterial?: Material) => void;\r\n\r\n /**\r\n * Renormalize the mesh and patch it up if there are no weights\r\n * Similar to normalization by adding the weights compute the reciprocal and multiply all elements, this wil ensure that everything adds to 1.\r\n * However in the case of zero weights then we set just a single influence to 1.\r\n * We check in the function for extra's present and if so we use the normalizeSkinWeightsWithExtras rather than the FourWeights version.\r\n */\r\n public cleanMatrixWeights(): void {\r\n if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\r\n if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsExtraKind)) {\r\n this._normalizeSkinWeightsAndExtra();\r\n } else {\r\n this._normalizeSkinFourWeights();\r\n }\r\n }\r\n }\r\n\r\n // faster 4 weight version.\r\n private _normalizeSkinFourWeights(): void {\r\n const matricesWeights = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\r\n const numWeights = matricesWeights.length;\r\n\r\n for (let a = 0; a < numWeights; a += 4) {\r\n // accumulate weights\r\n const t = matricesWeights[a] + matricesWeights[a + 1] + matricesWeights[a + 2] + matricesWeights[a + 3];\r\n // check for invalid weight and just set it to 1.\r\n if (t === 0) {\r\n matricesWeights[a] = 1;\r\n } else {\r\n // renormalize so everything adds to 1 use reciprocal\r\n const recip = 1 / t;\r\n matricesWeights[a] *= recip;\r\n matricesWeights[a + 1] *= recip;\r\n matricesWeights[a + 2] *= recip;\r\n matricesWeights[a + 3] *= recip;\r\n }\r\n }\r\n this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);\r\n }\r\n // handle special case of extra verts. (in theory gltf can handle 12 influences)\r\n private _normalizeSkinWeightsAndExtra(): void {\r\n const matricesWeightsExtra = this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind);\r\n const matricesWeights = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\r\n const numWeights = matricesWeights.length;\r\n\r\n for (let a = 0; a < numWeights; a += 4) {\r\n // accumulate weights\r\n let t = matricesWeights[a] + matricesWeights[a + 1] + matricesWeights[a + 2] + matricesWeights[a + 3];\r\n t += matricesWeightsExtra[a] + matricesWeightsExtra[a + 1] + matricesWeightsExtra[a + 2] + matricesWeightsExtra[a + 3];\r\n // check for invalid weight and just set it to 1.\r\n if (t === 0) {\r\n matricesWeights[a] = 1;\r\n } else {\r\n // renormalize so everything adds to 1 use reciprocal\r\n const recip = 1 / t;\r\n matricesWeights[a] *= recip;\r\n matricesWeights[a + 1] *= recip;\r\n matricesWeights[a + 2] *= recip;\r\n matricesWeights[a + 3] *= recip;\r\n // same goes for extras\r\n matricesWeightsExtra[a] *= recip;\r\n matricesWeightsExtra[a + 1] *= recip;\r\n matricesWeightsExtra[a + 2] *= recip;\r\n matricesWeightsExtra[a + 3] *= recip;\r\n }\r\n }\r\n this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);\r\n this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsExtra);\r\n }\r\n\r\n /**\r\n * ValidateSkinning is used to determine that a mesh has valid skinning data along with skin metrics, if missing weights,\r\n * or not normalized it is returned as invalid mesh the string can be used for console logs, or on screen messages to let\r\n * the user know there was an issue with importing the mesh\r\n * @returns a validation object with skinned, valid and report string\r\n */\r\n public validateSkinning(): { skinned: boolean; valid: boolean; report: string } {\r\n const matricesWeightsExtra = this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind);\r\n const matricesWeights = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\r\n if (matricesWeights === null || this.skeleton == null) {\r\n return { skinned: false, valid: true, report: \"not skinned\" };\r\n }\r\n\r\n const numWeights = matricesWeights.length;\r\n let numberNotSorted: number = 0;\r\n let missingWeights: number = 0;\r\n let maxUsedWeights: number = 0;\r\n let numberNotNormalized: number = 0;\r\n const numInfluences: number = matricesWeightsExtra === null ? 4 : 8;\r\n const usedWeightCounts = new Array();\r\n for (let a = 0; a <= numInfluences; a++) {\r\n usedWeightCounts[a] = 0;\r\n }\r\n const toleranceEpsilon: number = 0.001;\r\n\r\n for (let a = 0; a < numWeights; a += 4) {\r\n let lastWeight: number = matricesWeights[a];\r\n let t = lastWeight;\r\n let usedWeights: number = t === 0 ? 0 : 1;\r\n\r\n for (let b = 1; b < numInfluences; b++) {\r\n const d = b < 4 ? matricesWeights[a + b] : matricesWeightsExtra[a + b - 4];\r\n if (d > lastWeight) {\r\n numberNotSorted++;\r\n }\r\n if (d !== 0) {\r\n usedWeights++;\r\n }\r\n t += d;\r\n lastWeight = d;\r\n }\r\n // count the buffer weights usage\r\n usedWeightCounts[usedWeights]++;\r\n\r\n // max influences\r\n if (usedWeights > maxUsedWeights) {\r\n maxUsedWeights = usedWeights;\r\n }\r\n\r\n // check for invalid weight and just set it to 1.\r\n if (t === 0) {\r\n missingWeights++;\r\n } else {\r\n // renormalize so everything adds to 1 use reciprocal\r\n const recip = 1 / t;\r\n let tolerance = 0;\r\n for (let b = 0; b < numInfluences; b++) {\r\n if (b < 4) {\r\n tolerance += Math.abs(matricesWeights[a + b] - matricesWeights[a + b] * recip);\r\n } else {\r\n tolerance += Math.abs(matricesWeightsExtra[a + b - 4] - matricesWeightsExtra[a + b - 4] * recip);\r\n }\r\n }\r\n // arbitrary epsilon value for dictating not normalized\r\n if (tolerance > toleranceEpsilon) {\r\n numberNotNormalized++;\r\n }\r\n }\r\n }\r\n\r\n // validate bone indices are in range of the skeleton\r\n const numBones: number = this.skeleton.bones.length;\r\n const matricesIndices = this.getVerticesData(VertexBuffer.MatricesIndicesKind);\r\n const matricesIndicesExtra = this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);\r\n let numBadBoneIndices: number = 0;\r\n for (let a = 0; a < numWeights; a += 4) {\r\n for (let b = 0; b < numInfluences; b++) {\r\n const index = b < 4 ? matricesIndices[a + b] : matricesIndicesExtra[a + b - 4];\r\n if (index >= numBones || index < 0) {\r\n numBadBoneIndices++;\r\n }\r\n }\r\n }\r\n\r\n // log mesh stats\r\n const output =\r\n \"Number of Weights = \" +\r\n numWeights / 4 +\r\n \"\\nMaximum influences = \" +\r\n maxUsedWeights +\r\n \"\\nMissing Weights = \" +\r\n missingWeights +\r\n \"\\nNot Sorted = \" +\r\n numberNotSorted +\r\n \"\\nNot Normalized = \" +\r\n numberNotNormalized +\r\n \"\\nWeightCounts = [\" +\r\n usedWeightCounts +\r\n \"]\" +\r\n \"\\nNumber of bones = \" +\r\n numBones +\r\n \"\\nBad Bone Indices = \" +\r\n numBadBoneIndices;\r\n\r\n return { skinned: true, valid: missingWeights === 0 && numberNotNormalized === 0 && numBadBoneIndices === 0, report: output };\r\n }\r\n\r\n /** @internal */\r\n public _checkDelayState(): Mesh {\r\n const scene = this.getScene();\r\n if (this._geometry) {\r\n this._geometry.load(scene);\r\n } else if (this.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADING;\r\n\r\n this._queueLoad(scene);\r\n }\r\n return this;\r\n }\r\n\r\n private _queueLoad(scene: Scene): Mesh {\r\n scene.addPendingData(this);\r\n\r\n const getBinaryData = this.delayLoadingFile.indexOf(\".babylonbinarymeshdata\") !== -1;\r\n\r\n Tools.LoadFile(\r\n this.delayLoadingFile,\r\n (data) => {\r\n if (data instanceof ArrayBuffer) {\r\n this._delayLoadingFunction(data, this);\r\n } else {\r\n this._delayLoadingFunction(JSON.parse(data), this);\r\n }\r\n\r\n this.instances.forEach((instance) => {\r\n instance.refreshBoundingInfo();\r\n instance._syncSubMeshes();\r\n });\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n scene.removePendingData(this);\r\n },\r\n () => {},\r\n scene.offlineProvider,\r\n getBinaryData\r\n );\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns `true` if the mesh is within the frustum defined by the passed array of planes.\r\n * A mesh is in the frustum if its bounding box intersects the frustum\r\n * @param frustumPlanes defines the frustum to test\r\n * @returns true if the mesh is in the frustum planes\r\n */\r\n public isInFrustum(frustumPlanes: Plane[]): boolean {\r\n if (this.delayLoadState === Constants.DELAYLOADSTATE_LOADING) {\r\n return false;\r\n }\r\n\r\n if (!super.isInFrustum(frustumPlanes)) {\r\n return false;\r\n }\r\n\r\n this._checkDelayState();\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Sets the mesh material by the material or multiMaterial `id` property\r\n * @param id is a string identifying the material or the multiMaterial\r\n * @returns the current mesh\r\n */\r\n public setMaterialById(id: string): Mesh {\r\n const materials = this.getScene().materials;\r\n let index: number;\r\n for (index = materials.length - 1; index > -1; index--) {\r\n if (materials[index].id === id) {\r\n this.material = materials[index];\r\n return this;\r\n }\r\n }\r\n\r\n // Multi\r\n const multiMaterials = this.getScene().multiMaterials;\r\n for (index = multiMaterials.length - 1; index > -1; index--) {\r\n if (multiMaterials[index].id === id) {\r\n this.material = multiMaterials[index];\r\n return this;\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns as a new array populated with the mesh material and/or skeleton, if any.\r\n * @returns an array of IAnimatable\r\n */\r\n public getAnimatables(): IAnimatable[] {\r\n const results = new Array();\r\n\r\n if (this.material) {\r\n results.push(this.material);\r\n }\r\n\r\n if (this.skeleton) {\r\n results.push(this.skeleton);\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Modifies the mesh geometry according to the passed transformation matrix.\r\n * This method returns nothing, but it really modifies the mesh even if it's originally not set as updatable.\r\n * The mesh normals are modified using the same transformation.\r\n * Note that, under the hood, this method sets a new VertexBuffer each call.\r\n * @param transform defines the transform matrix to use\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/bakingTransforms\r\n * @returns the current mesh\r\n */\r\n public bakeTransformIntoVertices(transform: Matrix): Mesh {\r\n // Position\r\n if (!this.isVerticesDataPresent(VertexBuffer.PositionKind)) {\r\n return this;\r\n }\r\n\r\n const submeshes = this.subMeshes.splice(0);\r\n\r\n this._resetPointsArrayCache();\r\n\r\n let data = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n const temp = Vector3.Zero();\r\n let index: number;\r\n for (index = 0; index < data.length; index += 3) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp).toArray(data, index);\r\n }\r\n\r\n this.setVerticesData(VertexBuffer.PositionKind, data, (this.getVertexBuffer(VertexBuffer.PositionKind)).isUpdatable());\r\n\r\n // Normals\r\n if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n data = this.getVerticesData(VertexBuffer.NormalKind);\r\n for (index = 0; index < data.length; index += 3) {\r\n Vector3.TransformNormalFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp)\r\n .normalize()\r\n .toArray(data, index);\r\n }\r\n this.setVerticesData(VertexBuffer.NormalKind, data, (this.getVertexBuffer(VertexBuffer.NormalKind)).isUpdatable());\r\n }\r\n\r\n // flip faces?\r\n if (transform.determinant() < 0) {\r\n this.flipFaces();\r\n }\r\n\r\n // Restore submeshes\r\n this.releaseSubMeshes();\r\n this.subMeshes = submeshes;\r\n return this;\r\n }\r\n\r\n /**\r\n * Modifies the mesh geometry according to its own current World Matrix.\r\n * The mesh World Matrix is then reset.\r\n * This method returns nothing but really modifies the mesh even if it's originally not set as updatable.\r\n * Note that, under the hood, this method sets a new VertexBuffer each call.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/bakingTransforms\r\n * @param bakeIndependentlyOfChildren indicates whether to preserve all child nodes' World Matrix during baking\r\n * @returns the current mesh\r\n */\r\n public bakeCurrentTransformIntoVertices(bakeIndependentlyOfChildren: boolean = true): Mesh {\r\n this.bakeTransformIntoVertices(this.computeWorldMatrix(true));\r\n this.resetLocalMatrix(bakeIndependentlyOfChildren);\r\n return this;\r\n }\r\n\r\n // Cache\r\n\r\n /** @internal */\r\n public get _positions(): Nullable {\r\n if (this._internalAbstractMeshDataInfo._positions) {\r\n return this._internalAbstractMeshDataInfo._positions;\r\n }\r\n\r\n if (this._geometry) {\r\n return this._geometry._positions;\r\n }\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n public _resetPointsArrayCache(): Mesh {\r\n if (this._geometry) {\r\n this._geometry._resetPointsArrayCache();\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n public _generatePointsArray(): boolean {\r\n if (this._geometry) {\r\n return this._geometry._generatePointsArray();\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Returns a new Mesh object generated from the current mesh properties.\r\n * This method must not get confused with createInstance()\r\n * @param name is a string, the name given to the new mesh\r\n * @param newParent can be any Node object (default `null`)\r\n * @param doNotCloneChildren allows/denies the recursive cloning of the original mesh children if any (default `false`)\r\n * @param clonePhysicsImpostor allows/denies the cloning in the same time of the original mesh `body` used by the physics engine, if any (default `true`)\r\n * @returns a new mesh\r\n */\r\n public clone(name: string = \"\", newParent: Nullable = null, doNotCloneChildren?: boolean, clonePhysicsImpostor: boolean = true): Mesh {\r\n return new Mesh(name, this.getScene(), newParent, this, doNotCloneChildren, clonePhysicsImpostor);\r\n }\r\n\r\n /**\r\n * Releases resources associated with this mesh.\r\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\r\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n this.morphTargetManager = null;\r\n\r\n if (this._geometry) {\r\n this._geometry.releaseForMesh(this, true);\r\n }\r\n\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n\r\n if (internalDataInfo._onBeforeDrawObservable) {\r\n internalDataInfo._onBeforeDrawObservable.clear();\r\n }\r\n\r\n if (internalDataInfo._onBeforeBindObservable) {\r\n internalDataInfo._onBeforeBindObservable.clear();\r\n }\r\n\r\n if (internalDataInfo._onBeforeRenderObservable) {\r\n internalDataInfo._onBeforeRenderObservable.clear();\r\n }\r\n\r\n if (internalDataInfo._onAfterRenderObservable) {\r\n internalDataInfo._onAfterRenderObservable.clear();\r\n }\r\n\r\n if (internalDataInfo._onBetweenPassObservable) {\r\n internalDataInfo._onBetweenPassObservable.clear();\r\n }\r\n\r\n // Sources\r\n if (this._scene.useClonedMeshMap) {\r\n if (internalDataInfo.meshMap) {\r\n for (const uniqueId in internalDataInfo.meshMap) {\r\n const mesh = internalDataInfo.meshMap[uniqueId];\r\n if (mesh) {\r\n mesh._internalMeshDataInfo._source = null;\r\n internalDataInfo.meshMap[uniqueId] = undefined;\r\n }\r\n }\r\n }\r\n\r\n if (internalDataInfo._source && internalDataInfo._source._internalMeshDataInfo.meshMap) {\r\n internalDataInfo._source._internalMeshDataInfo.meshMap[this.uniqueId] = undefined;\r\n }\r\n } else {\r\n const meshes = this.getScene().meshes;\r\n for (const abstractMesh of meshes) {\r\n const mesh = abstractMesh as Mesh;\r\n if (mesh._internalMeshDataInfo && mesh._internalMeshDataInfo._source && mesh._internalMeshDataInfo._source === this) {\r\n mesh._internalMeshDataInfo._source = null;\r\n }\r\n }\r\n }\r\n\r\n internalDataInfo._source = null;\r\n this._instanceDataStorage.visibleInstances = {};\r\n\r\n // Instances\r\n this._disposeInstanceSpecificData();\r\n\r\n // Thin instances\r\n this._disposeThinInstanceSpecificData();\r\n\r\n if (this._internalMeshDataInfo._checkReadinessObserver) {\r\n this._scene.onBeforeRenderObservable.remove(this._internalMeshDataInfo._checkReadinessObserver);\r\n }\r\n\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n\r\n /** @internal */\r\n public _disposeInstanceSpecificData() {\r\n // Do nothing\r\n }\r\n\r\n /** @internal */\r\n public _disposeThinInstanceSpecificData() {\r\n // Do nothing\r\n }\r\n\r\n /** @internal */\r\n public _invalidateInstanceVertexArrayObject() {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Modifies the mesh geometry according to a displacement map.\r\n * A displacement map is a colored image. Each pixel color value (actually a gradient computed from red, green, blue values) will give the displacement to apply to each mesh vertex.\r\n * The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated.\r\n * @param url is a string, the URL from the image file is to be downloaded.\r\n * @param minHeight is the lower limit of the displacement.\r\n * @param maxHeight is the upper limit of the displacement.\r\n * @param onSuccess is an optional Javascript function to be called just after the mesh is modified. It is passed the modified mesh and must return nothing.\r\n * @param uvOffset is an optional vector2 used to offset UV.\r\n * @param uvScale is an optional vector2 used to scale UV.\r\n * @param forceUpdate defines whether or not to force an update of the generated buffers. This is useful to apply on a deserialized model for instance.\r\n * @returns the Mesh.\r\n */\r\n public applyDisplacementMap(\r\n url: string,\r\n minHeight: number,\r\n maxHeight: number,\r\n onSuccess?: (mesh: Mesh) => void,\r\n uvOffset?: Vector2,\r\n uvScale?: Vector2,\r\n forceUpdate = false\r\n ): Mesh {\r\n const scene = this.getScene();\r\n\r\n const onload = (img: HTMLImageElement | ImageBitmap) => {\r\n // Getting height map data\r\n const heightMapWidth = img.width;\r\n const heightMapHeight = img.height;\r\n const canvas = this.getEngine().createCanvas(heightMapWidth, heightMapHeight);\r\n const context = canvas.getContext(\"2d\");\r\n\r\n context.drawImage(img, 0, 0);\r\n\r\n // Create VertexData from map data\r\n //Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949\r\n const buffer = (context.getImageData(0, 0, heightMapWidth, heightMapHeight).data);\r\n\r\n this.applyDisplacementMapFromBuffer(buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight, uvOffset, uvScale, forceUpdate);\r\n //execute success callback, if set\r\n if (onSuccess) {\r\n onSuccess(this);\r\n }\r\n };\r\n\r\n Tools.LoadImage(url, onload, () => {}, scene.offlineProvider);\r\n return this;\r\n }\r\n\r\n /**\r\n * Modifies the mesh geometry according to a displacementMap buffer.\r\n * A displacement map is a colored image. Each pixel color value (actually a gradient computed from red, green, blue values) will give the displacement to apply to each mesh vertex.\r\n * The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated.\r\n * @param buffer is a `Uint8Array` buffer containing series of `Uint8` lower than 255, the red, green, blue and alpha values of each successive pixel.\r\n * @param heightMapWidth is the width of the buffer image.\r\n * @param heightMapHeight is the height of the buffer image.\r\n * @param minHeight is the lower limit of the displacement.\r\n * @param maxHeight is the upper limit of the displacement.\r\n * @param uvOffset is an optional vector2 used to offset UV.\r\n * @param uvScale is an optional vector2 used to scale UV.\r\n * @param forceUpdate defines whether or not to force an update of the generated buffers. This is useful to apply on a deserialized model for instance.\r\n * @returns the Mesh.\r\n */\r\n public applyDisplacementMapFromBuffer(\r\n buffer: Uint8Array,\r\n heightMapWidth: number,\r\n heightMapHeight: number,\r\n minHeight: number,\r\n maxHeight: number,\r\n uvOffset?: Vector2,\r\n uvScale?: Vector2,\r\n forceUpdate = false\r\n ): Mesh {\r\n if (!this.isVerticesDataPresent(VertexBuffer.PositionKind) || !this.isVerticesDataPresent(VertexBuffer.NormalKind) || !this.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n Logger.Warn(\"Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing\");\r\n return this;\r\n }\r\n\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind, true, true);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const uvs = this.getVerticesData(VertexBuffer.UVKind);\r\n let position = Vector3.Zero();\r\n const normal = Vector3.Zero();\r\n const uv = Vector2.Zero();\r\n\r\n uvOffset = uvOffset || Vector2.Zero();\r\n uvScale = uvScale || new Vector2(1, 1);\r\n\r\n for (let index = 0; index < positions.length; index += 3) {\r\n Vector3.FromArrayToRef(positions, index, position);\r\n Vector3.FromArrayToRef(normals, index, normal);\r\n Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);\r\n\r\n // Compute height\r\n const u = (Math.abs(uv.x * uvScale.x + (uvOffset.x % 1)) * (heightMapWidth - 1)) % heightMapWidth | 0;\r\n const v = (Math.abs(uv.y * uvScale.y + (uvOffset.y % 1)) * (heightMapHeight - 1)) % heightMapHeight | 0;\r\n\r\n const pos = (u + v * heightMapWidth) * 4;\r\n const r = buffer[pos] / 255.0;\r\n const g = buffer[pos + 1] / 255.0;\r\n const b = buffer[pos + 2] / 255.0;\r\n\r\n const gradient = r * 0.3 + g * 0.59 + b * 0.11;\r\n\r\n normal.normalize();\r\n normal.scaleInPlace(minHeight + (maxHeight - minHeight) * gradient);\r\n position = position.add(normal);\r\n\r\n position.toArray(positions, index);\r\n }\r\n\r\n VertexData.ComputeNormals(positions, this.getIndices(), normals);\r\n\r\n if (forceUpdate) {\r\n this.setVerticesData(VertexBuffer.PositionKind, positions);\r\n this.setVerticesData(VertexBuffer.NormalKind, normals);\r\n this.setVerticesData(VertexBuffer.UVKind, uvs);\r\n } else {\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals);\r\n }\r\n return this;\r\n }\r\n\r\n private _getFlattenedNormals(indices: IndicesArray, positions: FloatArray): Float32Array {\r\n const normals = new Float32Array(indices.length * 3);\r\n let normalsCount = 0;\r\n\r\n // Decide if normals should be flipped\r\n const flipNormalGeneration =\r\n this.overrideMaterialSideOrientation ===\r\n (this._scene.useRightHandedSystem ? Constants.MATERIAL_CounterClockWiseSideOrientation : Constants.MATERIAL_ClockWiseSideOrientation);\r\n\r\n // Generate new normals\r\n for (let index = 0; index < indices.length; index += 3) {\r\n const p1 = Vector3.FromArray(positions, indices[index] * 3);\r\n const p2 = Vector3.FromArray(positions, indices[index + 1] * 3);\r\n const p3 = Vector3.FromArray(positions, indices[index + 2] * 3);\r\n\r\n const p1p2 = p1.subtract(p2);\r\n const p3p2 = p3.subtract(p2);\r\n\r\n const normal = Vector3.Normalize(Vector3.Cross(p1p2, p3p2));\r\n if (flipNormalGeneration) {\r\n normal.scaleInPlace(-1);\r\n }\r\n\r\n // Store same normals for every vertex\r\n for (let localIndex = 0; localIndex < 3; localIndex++) {\r\n normals[normalsCount++] = normal.x;\r\n normals[normalsCount++] = normal.y;\r\n normals[normalsCount++] = normal.z;\r\n }\r\n }\r\n\r\n return normals;\r\n }\r\n\r\n private _convertToUnIndexedMesh(flattenNormals: boolean = false): Mesh {\r\n const kinds = this.getVerticesDataKinds();\r\n const indices = this.getIndices()!;\r\n const data: { [kind: string]: FloatArray } = {};\r\n\r\n const separateVertices = (data: FloatArray, stride: number): Float32Array => {\r\n const newData = new Float32Array(indices.length * stride);\r\n let count = 0;\r\n for (let index = 0; index < indices.length; index++) {\r\n for (let offset = 0; offset < stride; offset++) {\r\n newData[count++] = data[indices[index] * stride + offset];\r\n }\r\n }\r\n return newData;\r\n };\r\n\r\n // Save previous submeshes\r\n const previousSubmeshes = this.geometry ? this.subMeshes.slice(0) : [];\r\n\r\n // Cache vertex data\r\n for (const kind of kinds) {\r\n data[kind] = this.getVerticesData(kind)!;\r\n }\r\n\r\n // Update vertex data\r\n for (const kind of kinds) {\r\n const vertexBuffer = this.getVertexBuffer(kind)!;\r\n const stride = vertexBuffer.getStrideSize();\r\n\r\n if (flattenNormals && kind === VertexBuffer.NormalKind) {\r\n const normals = this._getFlattenedNormals(indices, data[VertexBuffer.PositionKind]);\r\n this.setVerticesData(VertexBuffer.NormalKind, normals, vertexBuffer.isUpdatable(), stride);\r\n } else {\r\n this.setVerticesData(kind, separateVertices(data[kind], stride), vertexBuffer.isUpdatable(), stride);\r\n }\r\n }\r\n\r\n // Update morph targets\r\n if (this.morphTargetManager) {\r\n for (let targetIndex = 0; targetIndex < this.morphTargetManager.numTargets; targetIndex++) {\r\n const target = this.morphTargetManager.getTarget(targetIndex);\r\n\r\n const positions = target.getPositions()!;\r\n target.setPositions(separateVertices(positions, 3));\r\n\r\n const normals = target.getNormals();\r\n if (normals) {\r\n target.setNormals(flattenNormals ? this._getFlattenedNormals(indices, positions) : separateVertices(normals, 3));\r\n }\r\n\r\n const tangents = target.getTangents();\r\n if (tangents) {\r\n target.setTangents(separateVertices(tangents, 3));\r\n }\r\n\r\n const uvs = target.getUVs();\r\n if (uvs) {\r\n target.setUVs(separateVertices(uvs, 2));\r\n }\r\n }\r\n this.morphTargetManager.synchronize();\r\n }\r\n\r\n // Update indices\r\n for (let index = 0; index < indices.length; index++) {\r\n indices[index] = index;\r\n }\r\n this.setIndices(indices);\r\n\r\n this._unIndexed = true;\r\n\r\n // Update submeshes\r\n this.releaseSubMeshes();\r\n for (const previousOne of previousSubmeshes) {\r\n SubMesh.AddToMesh(previousOne.materialIndex, previousOne.indexStart, previousOne.indexCount, previousOne.indexStart, previousOne.indexCount, this);\r\n }\r\n\r\n this.synchronizeInstances();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Modify the mesh to get a flat shading rendering.\r\n * This means each mesh facet will then have its own normals. Usually new vertices are added in the mesh geometry to get this result.\r\n * Warning : the mesh is really modified even if not set originally as updatable and, under the hood, a new VertexBuffer is allocated.\r\n * @returns current mesh\r\n */\r\n public convertToFlatShadedMesh(): Mesh {\r\n return this._convertToUnIndexedMesh(true);\r\n }\r\n\r\n /**\r\n * This method removes all the mesh indices and add new vertices (duplication) in order to unfold facets into buffers.\r\n * In other words, more vertices, no more indices and a single bigger VBO.\r\n * The mesh is really modified even if not set originally as updatable. Under the hood, a new VertexBuffer is allocated.\r\n * @returns current mesh\r\n */\r\n public convertToUnIndexedMesh(): Mesh {\r\n return this._convertToUnIndexedMesh();\r\n }\r\n\r\n /**\r\n * Inverses facet orientations.\r\n * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.\r\n * @param flipNormals will also inverts the normals\r\n * @returns current mesh\r\n */\r\n public flipFaces(flipNormals: boolean = false): Mesh {\r\n const vertex_data = VertexData.ExtractFromMesh(this);\r\n let i: number;\r\n if (flipNormals && this.isVerticesDataPresent(VertexBuffer.NormalKind) && vertex_data.normals) {\r\n for (i = 0; i < vertex_data.normals.length; i++) {\r\n vertex_data.normals[i] *= -1;\r\n }\r\n }\r\n\r\n if (vertex_data.indices) {\r\n let temp;\r\n for (i = 0; i < vertex_data.indices.length; i += 3) {\r\n // reassign indices\r\n temp = vertex_data.indices[i + 1];\r\n vertex_data.indices[i + 1] = vertex_data.indices[i + 2];\r\n vertex_data.indices[i + 2] = temp;\r\n }\r\n }\r\n\r\n vertex_data.applyToMesh(this, this.isVertexBufferUpdatable(VertexBuffer.PositionKind));\r\n return this;\r\n }\r\n\r\n /**\r\n * Increase the number of facets and hence vertices in a mesh\r\n * Vertex normals are interpolated from existing vertex normals\r\n * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.\r\n * @param numberPerEdge the number of new vertices to add to each edge of a facet, optional default 1\r\n */\r\n public increaseVertices(numberPerEdge: number = 1): void {\r\n const vertex_data = VertexData.ExtractFromMesh(this);\r\n const currentIndices = vertex_data.indices && !Array.isArray(vertex_data.indices) && Array.from ? Array.from(vertex_data.indices) : vertex_data.indices;\r\n const positions = vertex_data.positions && !Array.isArray(vertex_data.positions) && Array.from ? Array.from(vertex_data.positions) : vertex_data.positions;\r\n const uvs = vertex_data.uvs && !Array.isArray(vertex_data.uvs) && Array.from ? Array.from(vertex_data.uvs) : vertex_data.uvs;\r\n const normals = vertex_data.normals && !Array.isArray(vertex_data.normals) && Array.from ? Array.from(vertex_data.normals) : vertex_data.normals;\r\n\r\n if (!currentIndices || !positions) {\r\n Logger.Warn(\"Couldn't increase number of vertices : VertexData must contain at least indices and positions\");\r\n } else {\r\n vertex_data.indices = currentIndices;\r\n vertex_data.positions = positions;\r\n if (uvs) {\r\n vertex_data.uvs = uvs;\r\n }\r\n if (normals) {\r\n vertex_data.normals = normals;\r\n }\r\n\r\n const segments: number = numberPerEdge + 1; //segments per current facet edge, become sides of new facets\r\n const tempIndices: Array> = new Array();\r\n for (let i = 0; i < segments + 1; i++) {\r\n tempIndices[i] = new Array();\r\n }\r\n let a: number; //vertex index of one end of a side\r\n let b: number; //vertex index of other end of the side\r\n const deltaPosition: Vector3 = new Vector3(0, 0, 0);\r\n const deltaNormal: Vector3 = new Vector3(0, 0, 0);\r\n const deltaUV: Vector2 = new Vector2(0, 0);\r\n const indices: number[] = new Array();\r\n const vertexIndex: number[] = new Array();\r\n const side: Array>> = new Array();\r\n let len: number;\r\n let positionPtr: number = positions.length;\r\n let uvPtr: number;\r\n if (uvs) {\r\n uvPtr = uvs.length;\r\n }\r\n let normalsPtr: number;\r\n if (normals) {\r\n normalsPtr = normals.length;\r\n }\r\n\r\n for (let i = 0; i < currentIndices.length; i += 3) {\r\n vertexIndex[0] = currentIndices[i];\r\n vertexIndex[1] = currentIndices[i + 1];\r\n vertexIndex[2] = currentIndices[i + 2];\r\n for (let j = 0; j < 3; j++) {\r\n a = vertexIndex[j];\r\n b = vertexIndex[(j + 1) % 3];\r\n if (side[a] === undefined && side[b] === undefined) {\r\n side[a] = new Array();\r\n side[b] = new Array();\r\n } else {\r\n if (side[a] === undefined) {\r\n side[a] = new Array();\r\n }\r\n if (side[b] === undefined) {\r\n side[b] = new Array();\r\n }\r\n }\r\n if (side[a][b] === undefined && side[b][a] === undefined) {\r\n side[a][b] = [];\r\n deltaPosition.x = (positions[3 * b] - positions[3 * a]) / segments;\r\n deltaPosition.y = (positions[3 * b + 1] - positions[3 * a + 1]) / segments;\r\n deltaPosition.z = (positions[3 * b + 2] - positions[3 * a + 2]) / segments;\r\n if (normals) {\r\n deltaNormal.x = (normals[3 * b] - normals[3 * a]) / segments;\r\n deltaNormal.y = (normals[3 * b + 1] - normals[3 * a + 1]) / segments;\r\n deltaNormal.z = (normals[3 * b + 2] - normals[3 * a + 2]) / segments;\r\n }\r\n if (uvs) {\r\n deltaUV.x = (uvs[2 * b] - uvs[2 * a]) / segments;\r\n deltaUV.y = (uvs[2 * b + 1] - uvs[2 * a + 1]) / segments;\r\n }\r\n side[a][b].push(a);\r\n for (let k = 1; k < segments; k++) {\r\n side[a][b].push(positions.length / 3);\r\n positions[positionPtr++] = positions[3 * a] + k * deltaPosition.x;\r\n positions[positionPtr++] = positions[3 * a + 1] + k * deltaPosition.y;\r\n positions[positionPtr++] = positions[3 * a + 2] + k * deltaPosition.z;\r\n if (normals) {\r\n normals[normalsPtr!++] = normals[3 * a] + k * deltaNormal.x;\r\n normals[normalsPtr!++] = normals[3 * a + 1] + k * deltaNormal.y;\r\n normals[normalsPtr!++] = normals[3 * a + 2] + k * deltaNormal.z;\r\n }\r\n if (uvs) {\r\n uvs[uvPtr!++] = uvs[2 * a] + k * deltaUV.x;\r\n uvs[uvPtr!++] = uvs[2 * a + 1] + k * deltaUV.y;\r\n }\r\n }\r\n side[a][b].push(b);\r\n side[b][a] = new Array();\r\n len = side[a][b].length;\r\n for (let idx = 0; idx < len; idx++) {\r\n side[b][a][idx] = side[a][b][len - 1 - idx];\r\n }\r\n }\r\n }\r\n //Calculate positions, normals and uvs of new internal vertices\r\n tempIndices[0][0] = currentIndices[i];\r\n tempIndices[1][0] = side[currentIndices[i]][currentIndices[i + 1]][1];\r\n tempIndices[1][1] = side[currentIndices[i]][currentIndices[i + 2]][1];\r\n for (let k = 2; k < segments; k++) {\r\n tempIndices[k][0] = side[currentIndices[i]][currentIndices[i + 1]][k];\r\n tempIndices[k][k] = side[currentIndices[i]][currentIndices[i + 2]][k];\r\n deltaPosition.x = (positions[3 * tempIndices[k][k]] - positions[3 * tempIndices[k][0]]) / k;\r\n deltaPosition.y = (positions[3 * tempIndices[k][k] + 1] - positions[3 * tempIndices[k][0] + 1]) / k;\r\n deltaPosition.z = (positions[3 * tempIndices[k][k] + 2] - positions[3 * tempIndices[k][0] + 2]) / k;\r\n if (normals) {\r\n deltaNormal.x = (normals[3 * tempIndices[k][k]] - normals[3 * tempIndices[k][0]]) / k;\r\n deltaNormal.y = (normals[3 * tempIndices[k][k] + 1] - normals[3 * tempIndices[k][0] + 1]) / k;\r\n deltaNormal.z = (normals[3 * tempIndices[k][k] + 2] - normals[3 * tempIndices[k][0] + 2]) / k;\r\n }\r\n if (uvs) {\r\n deltaUV.x = (uvs[2 * tempIndices[k][k]] - uvs[2 * tempIndices[k][0]]) / k;\r\n deltaUV.y = (uvs[2 * tempIndices[k][k] + 1] - uvs[2 * tempIndices[k][0] + 1]) / k;\r\n }\r\n for (let j = 1; j < k; j++) {\r\n tempIndices[k][j] = positions.length / 3;\r\n positions[positionPtr++] = positions[3 * tempIndices[k][0]] + j * deltaPosition.x;\r\n positions[positionPtr++] = positions[3 * tempIndices[k][0] + 1] + j * deltaPosition.y;\r\n positions[positionPtr++] = positions[3 * tempIndices[k][0] + 2] + j * deltaPosition.z;\r\n if (normals) {\r\n normals[normalsPtr!++] = normals[3 * tempIndices[k][0]] + j * deltaNormal.x;\r\n normals[normalsPtr!++] = normals[3 * tempIndices[k][0] + 1] + j * deltaNormal.y;\r\n normals[normalsPtr!++] = normals[3 * tempIndices[k][0] + 2] + j * deltaNormal.z;\r\n }\r\n if (uvs) {\r\n uvs[uvPtr!++] = uvs[2 * tempIndices[k][0]] + j * deltaUV.x;\r\n uvs[uvPtr!++] = uvs[2 * tempIndices[k][0] + 1] + j * deltaUV.y;\r\n }\r\n }\r\n }\r\n tempIndices[segments] = side[currentIndices[i + 1]][currentIndices[i + 2]];\r\n\r\n // reform indices\r\n indices.push(tempIndices[0][0], tempIndices[1][0], tempIndices[1][1]);\r\n for (let k = 1; k < segments; k++) {\r\n let j: number;\r\n for (j = 0; j < k; j++) {\r\n indices.push(tempIndices[k][j], tempIndices[k + 1][j], tempIndices[k + 1][j + 1]);\r\n indices.push(tempIndices[k][j], tempIndices[k + 1][j + 1], tempIndices[k][j + 1]);\r\n }\r\n indices.push(tempIndices[k][j], tempIndices[k + 1][j], tempIndices[k + 1][j + 1]);\r\n }\r\n }\r\n\r\n vertex_data.indices = indices;\r\n vertex_data.applyToMesh(this, this.isVertexBufferUpdatable(VertexBuffer.PositionKind));\r\n }\r\n }\r\n\r\n /**\r\n * Force adjacent facets to share vertices and remove any facets that have all vertices in a line\r\n * This will undo any application of covertToFlatShadedMesh\r\n * Warning : the mesh is really modified even if not set originally as updatable. A new VertexBuffer is created under the hood each call.\r\n */\r\n public forceSharedVertices(): void {\r\n const vertex_data = VertexData.ExtractFromMesh(this);\r\n const currentUVs = vertex_data.uvs;\r\n const currentIndices = vertex_data.indices;\r\n const currentPositions = vertex_data.positions;\r\n const currentColors = vertex_data.colors;\r\n const currentMatrixIndices = vertex_data.matricesIndices;\r\n const currentMatrixWeights = vertex_data.matricesWeights;\r\n const currentMatrixIndicesExtra = vertex_data.matricesIndicesExtra;\r\n const currentMatrixWeightsExtra = vertex_data.matricesWeightsExtra;\r\n\r\n if (currentIndices === void 0 || currentPositions === void 0 || currentIndices === null || currentPositions === null) {\r\n Logger.Warn(\"VertexData contains empty entries\");\r\n } else {\r\n const positions: Array = new Array();\r\n const indices: Array = new Array();\r\n const uvs: Array = new Array();\r\n const colors: Array = new Array();\r\n const matrixIndices: Array = new Array();\r\n const matrixWeights: Array = new Array();\r\n const matrixIndicesExtra: Array = new Array();\r\n const matrixWeightsExtra: Array = new Array();\r\n let pstring: Array = new Array(); //lists facet vertex positions (a,b,c) as string \"a|b|c\"\r\n\r\n let indexPtr: number = 0; // pointer to next available index value\r\n const uniquePositions: { [key: string]: number } = {}; // unique vertex positions\r\n let ptr: number; // pointer to element in uniquePositions\r\n let facet: Array;\r\n\r\n for (let i = 0; i < currentIndices.length; i += 3) {\r\n facet = [currentIndices[i], currentIndices[i + 1], currentIndices[i + 2]]; //facet vertex indices\r\n pstring = new Array();\r\n for (let j = 0; j < 3; j++) {\r\n pstring[j] = \"\";\r\n for (let k = 0; k < 3; k++) {\r\n //small values make 0\r\n if (Math.abs(currentPositions[3 * facet[j] + k]) < 0.00000001) {\r\n currentPositions[3 * facet[j] + k] = 0;\r\n }\r\n pstring[j] += currentPositions[3 * facet[j] + k] + \"|\";\r\n }\r\n }\r\n //check facet vertices to see that none are repeated\r\n // do not process any facet that has a repeated vertex, ie is a line\r\n if (!(pstring[0] == pstring[1] || pstring[0] == pstring[2] || pstring[1] == pstring[2])) {\r\n //for each facet position check if already listed in uniquePositions\r\n // if not listed add to uniquePositions and set index pointer\r\n // if listed use its index in uniquePositions and new index pointer\r\n for (let j = 0; j < 3; j++) {\r\n ptr = uniquePositions[pstring[j]];\r\n if (ptr === undefined) {\r\n uniquePositions[pstring[j]] = indexPtr;\r\n ptr = indexPtr++;\r\n //not listed so add individual x, y, z coordinates to positions\r\n for (let k = 0; k < 3; k++) {\r\n positions.push(currentPositions[3 * facet[j] + k]);\r\n }\r\n if (currentColors !== null && currentColors !== void 0) {\r\n for (let k = 0; k < 4; k++) {\r\n colors.push(currentColors[4 * facet[j] + k]);\r\n }\r\n }\r\n if (currentUVs !== null && currentUVs !== void 0) {\r\n for (let k = 0; k < 2; k++) {\r\n uvs.push(currentUVs[2 * facet[j] + k]);\r\n }\r\n }\r\n if (currentMatrixIndices !== null && currentMatrixIndices !== void 0) {\r\n for (let k = 0; k < 4; k++) {\r\n matrixIndices.push(currentMatrixIndices[4 * facet[j] + k]);\r\n }\r\n }\r\n if (currentMatrixWeights !== null && currentMatrixWeights !== void 0) {\r\n for (let k = 0; k < 4; k++) {\r\n matrixWeights.push(currentMatrixWeights[4 * facet[j] + k]);\r\n }\r\n }\r\n if (currentMatrixIndicesExtra !== null && currentMatrixIndicesExtra !== void 0) {\r\n for (let k = 0; k < 4; k++) {\r\n matrixIndicesExtra.push(currentMatrixIndicesExtra[4 * facet[j] + k]);\r\n }\r\n }\r\n if (currentMatrixWeightsExtra !== null && currentMatrixWeightsExtra !== void 0) {\r\n for (let k = 0; k < 4; k++) {\r\n matrixWeightsExtra.push(currentMatrixWeightsExtra[4 * facet[j] + k]);\r\n }\r\n }\r\n }\r\n // add new index pointer to indices array\r\n indices.push(ptr);\r\n }\r\n }\r\n }\r\n\r\n const normals: Array = new Array();\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n //create new vertex data object and update\r\n vertex_data.positions = positions;\r\n vertex_data.indices = indices;\r\n vertex_data.normals = normals;\r\n if (currentUVs !== null && currentUVs !== void 0) {\r\n vertex_data.uvs = uvs;\r\n }\r\n if (currentColors !== null && currentColors !== void 0) {\r\n vertex_data.colors = colors;\r\n }\r\n if (currentMatrixIndices !== null && currentMatrixIndices !== void 0) {\r\n vertex_data.matricesIndices = matrixIndices;\r\n }\r\n if (currentMatrixWeights !== null && currentMatrixWeights !== void 0) {\r\n vertex_data.matricesWeights = matrixWeights;\r\n }\r\n if (currentMatrixIndicesExtra !== null && currentMatrixIndicesExtra !== void 0) {\r\n vertex_data.matricesIndicesExtra = matrixIndicesExtra;\r\n }\r\n if (currentMatrixWeights !== null && currentMatrixWeights !== void 0) {\r\n vertex_data.matricesWeightsExtra = matrixWeightsExtra;\r\n }\r\n\r\n vertex_data.applyToMesh(this, this.isVertexBufferUpdatable(VertexBuffer.PositionKind));\r\n }\r\n }\r\n\r\n // Instances\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/naming-convention\r\n public static _instancedMeshFactory(name: string, mesh: Mesh): InstancedMesh {\r\n throw _WarnImport(\"InstancedMesh\");\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _PhysicsImpostorParser(scene: Scene, physicObject: IPhysicsEnabledObject, jsonObject: any): PhysicsImpostor {\r\n throw _WarnImport(\"PhysicsImpostor\");\r\n }\r\n\r\n /**\r\n * Creates a new InstancedMesh object from the mesh model.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/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 Mesh._instancedMeshFactory(name, this);\r\n }\r\n\r\n /**\r\n * Synchronises all the mesh instance submeshes to the current mesh submeshes, if any.\r\n * After this call, all the mesh instances have the same submeshes than the current mesh.\r\n * @returns the current mesh\r\n */\r\n public synchronizeInstances(): Mesh {\r\n for (let instanceIndex = 0; instanceIndex < this.instances.length; instanceIndex++) {\r\n const instance = this.instances[instanceIndex];\r\n instance._syncSubMeshes();\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Optimization of the mesh's indices, in case a mesh has duplicated vertices.\r\n * The function will only reorder the indices and will not remove unused vertices to avoid problems with submeshes.\r\n * This should be used together with the simplification to avoid disappearing triangles.\r\n * @param successCallback an optional success callback to be called after the optimization finished.\r\n * @returns the current mesh\r\n */\r\n public optimizeIndices(successCallback?: (mesh?: Mesh) => void): Mesh {\r\n const indices = this.getIndices();\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (!positions || !indices) {\r\n return this;\r\n }\r\n\r\n const vectorPositions = new Array();\r\n for (let pos = 0; pos < positions.length; pos = pos + 3) {\r\n vectorPositions.push(Vector3.FromArray(positions, pos));\r\n }\r\n const dupes = new Array();\r\n\r\n AsyncLoop.SyncAsyncForLoop(\r\n vectorPositions.length,\r\n 40,\r\n (iteration) => {\r\n const realPos = vectorPositions.length - 1 - iteration;\r\n const testedPosition = vectorPositions[realPos];\r\n for (let j = 0; j < realPos; ++j) {\r\n const againstPosition = vectorPositions[j];\r\n if (testedPosition.equals(againstPosition)) {\r\n dupes[realPos] = j;\r\n break;\r\n }\r\n }\r\n },\r\n () => {\r\n for (let i = 0; i < indices.length; ++i) {\r\n indices[i] = dupes[indices[i]] || indices[i];\r\n }\r\n\r\n //indices are now reordered\r\n const originalSubMeshes = this.subMeshes.slice(0);\r\n this.setIndices(indices);\r\n this.subMeshes = originalSubMeshes;\r\n if (successCallback) {\r\n successCallback(this);\r\n }\r\n }\r\n );\r\n return this;\r\n }\r\n\r\n /**\r\n * Serialize current mesh\r\n * @param serializationObject defines the object which will receive the serialization data\r\n */\r\n public serialize(serializationObject: any = {}): any {\r\n serializationObject.name = this.name;\r\n serializationObject.id = this.id;\r\n serializationObject.uniqueId = this.uniqueId;\r\n serializationObject.type = this.getClassName();\r\n\r\n if (Tags && Tags.HasTags(this)) {\r\n serializationObject.tags = Tags.GetTags(this);\r\n }\r\n\r\n serializationObject.position = this.position.asArray();\r\n\r\n if (this.rotationQuaternion) {\r\n serializationObject.rotationQuaternion = this.rotationQuaternion.asArray();\r\n } else if (this.rotation) {\r\n serializationObject.rotation = this.rotation.asArray();\r\n }\r\n\r\n serializationObject.scaling = this.scaling.asArray();\r\n if (this._postMultiplyPivotMatrix) {\r\n serializationObject.pivotMatrix = this.getPivotMatrix().asArray();\r\n } else {\r\n serializationObject.localMatrix = this.getPivotMatrix().asArray();\r\n }\r\n\r\n serializationObject.isEnabled = this.isEnabled(false);\r\n serializationObject.isVisible = this.isVisible;\r\n serializationObject.infiniteDistance = this.infiniteDistance;\r\n serializationObject.pickable = this.isPickable;\r\n\r\n serializationObject.receiveShadows = this.receiveShadows;\r\n\r\n serializationObject.billboardMode = this.billboardMode;\r\n serializationObject.visibility = this.visibility;\r\n\r\n serializationObject.checkCollisions = this.checkCollisions;\r\n serializationObject.isBlocker = this.isBlocker;\r\n serializationObject.overrideMaterialSideOrientation = this.overrideMaterialSideOrientation;\r\n\r\n // Parent\r\n if (this.parent) {\r\n this.parent._serializeAsParent(serializationObject);\r\n }\r\n\r\n // Geometry\r\n serializationObject.isUnIndexed = this.isUnIndexed;\r\n const geometry = this._geometry;\r\n if (geometry && this.subMeshes) {\r\n serializationObject.geometryUniqueId = geometry.uniqueId;\r\n serializationObject.geometryId = geometry.id;\r\n\r\n // SubMeshes\r\n serializationObject.subMeshes = [];\r\n for (let subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {\r\n const subMesh = this.subMeshes[subIndex];\r\n\r\n serializationObject.subMeshes.push({\r\n materialIndex: subMesh.materialIndex,\r\n verticesStart: subMesh.verticesStart,\r\n verticesCount: subMesh.verticesCount,\r\n indexStart: subMesh.indexStart,\r\n indexCount: subMesh.indexCount,\r\n });\r\n }\r\n }\r\n\r\n // Material\r\n if (this.material) {\r\n if (!this.material.doNotSerialize) {\r\n serializationObject.materialUniqueId = this.material.uniqueId;\r\n serializationObject.materialId = this.material.id; // back compat\r\n }\r\n } else {\r\n this.material = null;\r\n serializationObject.materialUniqueId = this._scene.defaultMaterial.uniqueId;\r\n serializationObject.materialId = this._scene.defaultMaterial.id; // back compat\r\n }\r\n\r\n // Morph targets\r\n if (this.morphTargetManager) {\r\n serializationObject.morphTargetManagerId = this.morphTargetManager.uniqueId;\r\n }\r\n\r\n // Skeleton\r\n if (this.skeleton) {\r\n serializationObject.skeletonId = this.skeleton.id;\r\n serializationObject.numBoneInfluencers = this.numBoneInfluencers;\r\n }\r\n\r\n // Physics\r\n //TODO implement correct serialization for physics impostors.\r\n if (this.getScene()._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE)) {\r\n const impostor = this.getPhysicsImpostor();\r\n if (impostor) {\r\n serializationObject.physicsMass = impostor.getParam(\"mass\");\r\n serializationObject.physicsFriction = impostor.getParam(\"friction\");\r\n serializationObject.physicsRestitution = impostor.getParam(\"mass\");\r\n serializationObject.physicsImpostor = impostor.type;\r\n }\r\n }\r\n\r\n // Metadata\r\n if (this.metadata) {\r\n serializationObject.metadata = this.metadata;\r\n }\r\n\r\n // Instances\r\n serializationObject.instances = [];\r\n for (let index = 0; index < this.instances.length; index++) {\r\n const instance = this.instances[index];\r\n if (instance.doNotSerialize) {\r\n continue;\r\n }\r\n\r\n const serializationInstance: any = {\r\n name: instance.name,\r\n id: instance.id,\r\n isEnabled: instance.isEnabled(false),\r\n isVisible: instance.isVisible,\r\n isPickable: instance.isPickable,\r\n checkCollisions: instance.checkCollisions,\r\n position: instance.position.asArray(),\r\n scaling: instance.scaling.asArray(),\r\n };\r\n\r\n if (instance.parent) {\r\n instance.parent._serializeAsParent(serializationInstance);\r\n }\r\n\r\n if (instance.rotationQuaternion) {\r\n serializationInstance.rotationQuaternion = instance.rotationQuaternion.asArray();\r\n } else if (instance.rotation) {\r\n serializationInstance.rotation = instance.rotation.asArray();\r\n }\r\n\r\n // Physics\r\n //TODO implement correct serialization for physics impostors.\r\n if (this.getScene()._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE)) {\r\n const impostor = instance.getPhysicsImpostor();\r\n if (impostor) {\r\n serializationInstance.physicsMass = impostor.getParam(\"mass\");\r\n serializationInstance.physicsFriction = impostor.getParam(\"friction\");\r\n serializationInstance.physicsRestitution = impostor.getParam(\"mass\");\r\n serializationInstance.physicsImpostor = impostor.type;\r\n }\r\n }\r\n\r\n // Metadata\r\n if (instance.metadata) {\r\n serializationInstance.metadata = instance.metadata;\r\n }\r\n\r\n // Action Manager\r\n if (instance.actionManager) {\r\n serializationInstance.actions = instance.actionManager.serialize(instance.name);\r\n }\r\n\r\n serializationObject.instances.push(serializationInstance);\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(instance, serializationInstance);\r\n serializationInstance.ranges = instance.serializeAnimationRanges();\r\n }\r\n\r\n // Thin instances\r\n if (this._thinInstanceDataStorage.instancesCount && this._thinInstanceDataStorage.matrixData) {\r\n serializationObject.thinInstances = {\r\n instancesCount: this._thinInstanceDataStorage.instancesCount,\r\n matrixData: Array.from(this._thinInstanceDataStorage.matrixData),\r\n matrixBufferSize: this._thinInstanceDataStorage.matrixBufferSize,\r\n enablePicking: this.thinInstanceEnablePicking,\r\n };\r\n\r\n if (this._userThinInstanceBuffersStorage) {\r\n const userThinInstance: any = {\r\n data: {},\r\n sizes: {},\r\n strides: {},\r\n };\r\n\r\n for (const kind in this._userThinInstanceBuffersStorage.data) {\r\n userThinInstance.data[kind] = Array.from(this._userThinInstanceBuffersStorage.data[kind]);\r\n userThinInstance.sizes[kind] = this._userThinInstanceBuffersStorage.sizes[kind];\r\n userThinInstance.strides[kind] = this._userThinInstanceBuffersStorage.strides[kind];\r\n }\r\n\r\n serializationObject.thinInstances.userThinInstance = userThinInstance;\r\n }\r\n }\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\r\n serializationObject.ranges = this.serializeAnimationRanges();\r\n\r\n // Layer mask\r\n serializationObject.layerMask = this.layerMask;\r\n\r\n // Alpha\r\n serializationObject.alphaIndex = this.alphaIndex;\r\n serializationObject.hasVertexAlpha = this.hasVertexAlpha;\r\n\r\n // Overlay\r\n serializationObject.overlayAlpha = this.overlayAlpha;\r\n serializationObject.overlayColor = this.overlayColor.asArray();\r\n serializationObject.renderOverlay = this.renderOverlay;\r\n\r\n // Fog\r\n serializationObject.applyFog = this.applyFog;\r\n\r\n // Action Manager\r\n if (this.actionManager) {\r\n serializationObject.actions = this.actionManager.serialize(this.name);\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /** @internal */\r\n public _syncGeometryWithMorphTargetManager() {\r\n if (!this.geometry) {\r\n return;\r\n }\r\n\r\n this._markSubMeshesAsAttributesDirty();\r\n\r\n const morphTargetManager = this._internalAbstractMeshDataInfo._morphTargetManager;\r\n if (morphTargetManager && morphTargetManager.vertexCount) {\r\n if (morphTargetManager.vertexCount !== this.getTotalVertices()) {\r\n Logger.Error(\"Mesh is incompatible with morph targets. Targets and mesh must all have the same vertices count.\");\r\n this.morphTargetManager = null;\r\n return;\r\n }\r\n\r\n if (morphTargetManager.isUsingTextureForTargets) {\r\n return;\r\n }\r\n\r\n for (let index = 0; index < morphTargetManager.numInfluencers; index++) {\r\n const morphTarget = morphTargetManager.getActiveTarget(index);\r\n\r\n const positions = morphTarget.getPositions();\r\n if (!positions) {\r\n Logger.Error(\"Invalid morph target. Target must have positions.\");\r\n return;\r\n }\r\n\r\n this.geometry.setVerticesData(VertexBuffer.PositionKind + index, positions, false, 3);\r\n\r\n const normals = morphTarget.getNormals();\r\n if (normals) {\r\n this.geometry.setVerticesData(VertexBuffer.NormalKind + index, normals, false, 3);\r\n }\r\n\r\n const tangents = morphTarget.getTangents();\r\n if (tangents) {\r\n this.geometry.setVerticesData(VertexBuffer.TangentKind + index, tangents, false, 3);\r\n }\r\n\r\n const uvs = morphTarget.getUVs();\r\n if (uvs) {\r\n this.geometry.setVerticesData(VertexBuffer.UVKind + \"_\" + index, uvs, false, 2);\r\n }\r\n }\r\n } else {\r\n let index = 0;\r\n\r\n // Positions\r\n while (this.geometry.isVerticesDataPresent(VertexBuffer.PositionKind + index)) {\r\n this.geometry.removeVerticesData(VertexBuffer.PositionKind + index);\r\n\r\n if (this.geometry.isVerticesDataPresent(VertexBuffer.NormalKind + index)) {\r\n this.geometry.removeVerticesData(VertexBuffer.NormalKind + index);\r\n }\r\n if (this.geometry.isVerticesDataPresent(VertexBuffer.TangentKind + index)) {\r\n this.geometry.removeVerticesData(VertexBuffer.TangentKind + index);\r\n }\r\n if (this.geometry.isVerticesDataPresent(VertexBuffer.UVKind + index)) {\r\n this.geometry.removeVerticesData(VertexBuffer.UVKind + \"_\" + index);\r\n }\r\n index++;\r\n }\r\n }\r\n }\r\n\r\n // Statics\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _GroundMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n throw _WarnImport(\"GroundMesh\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _GoldbergMeshParser = (parsedMesh: any, scene: Scene): GoldbergMesh => {\r\n throw _WarnImport(\"GoldbergMesh\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _LinesMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n throw _WarnImport(\"LinesMesh\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _GreasedLineMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n throw _WarnImport(\"GreasedLineMesh\");\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _TrailMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n throw _WarnImport(\"TrailMesh\");\r\n };\r\n\r\n /**\r\n * Returns a new Mesh object parsed from the source provided.\r\n * @param parsedMesh is the source\r\n * @param scene defines the hosting scene\r\n * @param rootUrl is the root URL to prefix the `delayLoadingFile` property with\r\n * @returns a new Mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene, rootUrl: string): Mesh {\r\n let mesh: Mesh;\r\n\r\n if (parsedMesh.type && parsedMesh.type === \"LinesMesh\") {\r\n mesh = Mesh._LinesMeshParser(parsedMesh, scene);\r\n } else if (parsedMesh.type && parsedMesh.type === \"GroundMesh\") {\r\n mesh = Mesh._GroundMeshParser(parsedMesh, scene);\r\n } else if (parsedMesh.type && parsedMesh.type === \"GoldbergMesh\") {\r\n mesh = Mesh._GoldbergMeshParser(parsedMesh, scene);\r\n } else if (parsedMesh.type && parsedMesh.type === \"GreasedLineMesh\") {\r\n mesh = Mesh._GreasedLineMeshParser(parsedMesh, scene);\r\n } else if (parsedMesh.type && parsedMesh.type === \"TrailMesh\") {\r\n mesh = Mesh._TrailMeshParser(parsedMesh, scene);\r\n } else {\r\n mesh = new Mesh(parsedMesh.name, scene);\r\n }\r\n mesh.id = parsedMesh.id;\r\n mesh._waitingParsedUniqueId = parsedMesh.uniqueId;\r\n\r\n if (Tags) {\r\n Tags.AddTagsTo(mesh, parsedMesh.tags);\r\n }\r\n\r\n mesh.position = Vector3.FromArray(parsedMesh.position);\r\n\r\n if (parsedMesh.metadata !== undefined) {\r\n mesh.metadata = parsedMesh.metadata;\r\n }\r\n\r\n if (parsedMesh.rotationQuaternion) {\r\n mesh.rotationQuaternion = Quaternion.FromArray(parsedMesh.rotationQuaternion);\r\n } else if (parsedMesh.rotation) {\r\n mesh.rotation = Vector3.FromArray(parsedMesh.rotation);\r\n }\r\n\r\n mesh.scaling = Vector3.FromArray(parsedMesh.scaling);\r\n\r\n if (parsedMesh.localMatrix) {\r\n mesh.setPreTransformMatrix(Matrix.FromArray(parsedMesh.localMatrix));\r\n } else if (parsedMesh.pivotMatrix) {\r\n mesh.setPivotMatrix(Matrix.FromArray(parsedMesh.pivotMatrix));\r\n }\r\n\r\n mesh.setEnabled(parsedMesh.isEnabled);\r\n mesh.isVisible = parsedMesh.isVisible;\r\n mesh.infiniteDistance = parsedMesh.infiniteDistance;\r\n\r\n mesh.showBoundingBox = parsedMesh.showBoundingBox;\r\n mesh.showSubMeshesBoundingBox = parsedMesh.showSubMeshesBoundingBox;\r\n\r\n if (parsedMesh.applyFog !== undefined) {\r\n mesh.applyFog = parsedMesh.applyFog;\r\n }\r\n\r\n if (parsedMesh.pickable !== undefined) {\r\n mesh.isPickable = parsedMesh.pickable;\r\n }\r\n\r\n if (parsedMesh.alphaIndex !== undefined) {\r\n mesh.alphaIndex = parsedMesh.alphaIndex;\r\n }\r\n\r\n mesh.receiveShadows = parsedMesh.receiveShadows;\r\n\r\n if (parsedMesh.billboardMode !== undefined) {\r\n mesh.billboardMode = parsedMesh.billboardMode;\r\n }\r\n\r\n if (parsedMesh.visibility !== undefined) {\r\n mesh.visibility = parsedMesh.visibility;\r\n }\r\n\r\n mesh.checkCollisions = parsedMesh.checkCollisions;\r\n mesh.overrideMaterialSideOrientation = parsedMesh.overrideMaterialSideOrientation;\r\n\r\n if (parsedMesh.isBlocker !== undefined) {\r\n mesh.isBlocker = parsedMesh.isBlocker;\r\n }\r\n\r\n mesh._shouldGenerateFlatShading = parsedMesh.useFlatShading;\r\n\r\n // freezeWorldMatrix\r\n if (parsedMesh.freezeWorldMatrix) {\r\n mesh._waitingData.freezeWorldMatrix = parsedMesh.freezeWorldMatrix;\r\n }\r\n\r\n // Parent\r\n if (parsedMesh.parentId !== undefined) {\r\n mesh._waitingParentId = parsedMesh.parentId;\r\n }\r\n\r\n if (parsedMesh.parentInstanceIndex !== undefined) {\r\n mesh._waitingParentInstanceIndex = parsedMesh.parentInstanceIndex;\r\n }\r\n\r\n // Actions\r\n if (parsedMesh.actions !== undefined) {\r\n mesh._waitingData.actions = parsedMesh.actions;\r\n }\r\n\r\n // Overlay\r\n if (parsedMesh.overlayAlpha !== undefined) {\r\n mesh.overlayAlpha = parsedMesh.overlayAlpha;\r\n }\r\n\r\n if (parsedMesh.overlayColor !== undefined) {\r\n mesh.overlayColor = Color3.FromArray(parsedMesh.overlayColor);\r\n }\r\n\r\n if (parsedMesh.renderOverlay !== undefined) {\r\n mesh.renderOverlay = parsedMesh.renderOverlay;\r\n }\r\n\r\n // Geometry\r\n mesh.isUnIndexed = !!parsedMesh.isUnIndexed;\r\n mesh.hasVertexAlpha = parsedMesh.hasVertexAlpha;\r\n\r\n if (parsedMesh.delayLoadingFile) {\r\n mesh.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;\r\n mesh.buildBoundingInfo(Vector3.FromArray(parsedMesh.boundingBoxMinimum), Vector3.FromArray(parsedMesh.boundingBoxMaximum));\r\n\r\n if (parsedMesh._binaryInfo) {\r\n mesh._binaryInfo = parsedMesh._binaryInfo;\r\n }\r\n\r\n mesh._delayInfo = [];\r\n if (parsedMesh.hasUVs) {\r\n mesh._delayInfo.push(VertexBuffer.UVKind);\r\n }\r\n\r\n if (parsedMesh.hasUVs2) {\r\n mesh._delayInfo.push(VertexBuffer.UV2Kind);\r\n }\r\n\r\n if (parsedMesh.hasUVs3) {\r\n mesh._delayInfo.push(VertexBuffer.UV3Kind);\r\n }\r\n\r\n if (parsedMesh.hasUVs4) {\r\n mesh._delayInfo.push(VertexBuffer.UV4Kind);\r\n }\r\n\r\n if (parsedMesh.hasUVs5) {\r\n mesh._delayInfo.push(VertexBuffer.UV5Kind);\r\n }\r\n\r\n if (parsedMesh.hasUVs6) {\r\n mesh._delayInfo.push(VertexBuffer.UV6Kind);\r\n }\r\n\r\n if (parsedMesh.hasColors) {\r\n mesh._delayInfo.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n if (parsedMesh.hasMatricesIndices) {\r\n mesh._delayInfo.push(VertexBuffer.MatricesIndicesKind);\r\n }\r\n\r\n if (parsedMesh.hasMatricesWeights) {\r\n mesh._delayInfo.push(VertexBuffer.MatricesWeightsKind);\r\n }\r\n\r\n mesh._delayLoadingFunction = Geometry._ImportGeometry;\r\n\r\n if (SceneLoaderFlags.ForceFullSceneLoadingForIncremental) {\r\n mesh._checkDelayState();\r\n }\r\n } else {\r\n Geometry._ImportGeometry(parsedMesh, mesh);\r\n }\r\n\r\n // Material\r\n if (parsedMesh.materialUniqueId) {\r\n mesh._waitingMaterialId = parsedMesh.materialUniqueId;\r\n } else if (parsedMesh.materialId) {\r\n mesh._waitingMaterialId = parsedMesh.materialId;\r\n }\r\n\r\n // Morph targets\r\n if (parsedMesh.morphTargetManagerId > -1) {\r\n mesh.morphTargetManager = scene.getMorphTargetManagerById(parsedMesh.morphTargetManagerId);\r\n }\r\n\r\n // Skeleton\r\n if (parsedMesh.skeletonId !== undefined && parsedMesh.skeletonId !== null) {\r\n mesh.skeleton = scene.getLastSkeletonById(parsedMesh.skeletonId);\r\n if (parsedMesh.numBoneInfluencers) {\r\n mesh.numBoneInfluencers = parsedMesh.numBoneInfluencers;\r\n }\r\n }\r\n\r\n // Animations\r\n if (parsedMesh.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedMesh.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n mesh.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n Node.ParseAnimationRanges(mesh, parsedMesh, scene);\r\n }\r\n\r\n if (parsedMesh.autoAnimate) {\r\n scene.beginAnimation(mesh, parsedMesh.autoAnimateFrom, parsedMesh.autoAnimateTo, parsedMesh.autoAnimateLoop, parsedMesh.autoAnimateSpeed || 1.0);\r\n }\r\n\r\n // Layer Mask\r\n if (parsedMesh.layerMask && !isNaN(parsedMesh.layerMask)) {\r\n mesh.layerMask = Math.abs(parseInt(parsedMesh.layerMask));\r\n } else {\r\n mesh.layerMask = 0x0fffffff;\r\n }\r\n\r\n // Physics\r\n if (parsedMesh.physicsImpostor) {\r\n Mesh._PhysicsImpostorParser(scene, mesh, parsedMesh);\r\n }\r\n\r\n // Levels\r\n if (parsedMesh.lodMeshIds) {\r\n mesh._waitingData.lods = {\r\n ids: parsedMesh.lodMeshIds,\r\n distances: parsedMesh.lodDistances ? parsedMesh.lodDistances : null,\r\n coverages: parsedMesh.lodCoverages ? parsedMesh.lodCoverages : null,\r\n };\r\n }\r\n\r\n // Instances\r\n if (parsedMesh.instances) {\r\n for (let index = 0; index < parsedMesh.instances.length; index++) {\r\n const parsedInstance = parsedMesh.instances[index];\r\n const instance = mesh.createInstance(parsedInstance.name);\r\n\r\n if (parsedInstance.id) {\r\n instance.id = parsedInstance.id;\r\n }\r\n\r\n if (Tags) {\r\n if (parsedInstance.tags) {\r\n Tags.AddTagsTo(instance, parsedInstance.tags);\r\n } else {\r\n Tags.AddTagsTo(instance, parsedMesh.tags);\r\n }\r\n }\r\n\r\n instance.position = Vector3.FromArray(parsedInstance.position);\r\n\r\n if (parsedInstance.metadata !== undefined) {\r\n instance.metadata = parsedInstance.metadata;\r\n }\r\n\r\n if (parsedInstance.parentId !== undefined) {\r\n instance._waitingParentId = parsedInstance.parentId;\r\n }\r\n\r\n if (parsedInstance.parentInstanceIndex !== undefined) {\r\n instance._waitingParentInstanceIndex = parsedInstance.parentInstanceIndex;\r\n }\r\n\r\n if (parsedInstance.isEnabled !== undefined && parsedInstance.isEnabled !== null) {\r\n instance.setEnabled(parsedInstance.isEnabled);\r\n }\r\n\r\n if (parsedInstance.isVisible !== undefined && parsedInstance.isVisible !== null) {\r\n instance.isVisible = parsedInstance.isVisible;\r\n }\r\n\r\n if (parsedInstance.isPickable !== undefined && parsedInstance.isPickable !== null) {\r\n instance.isPickable = parsedInstance.isPickable;\r\n }\r\n\r\n if (parsedInstance.rotationQuaternion) {\r\n instance.rotationQuaternion = Quaternion.FromArray(parsedInstance.rotationQuaternion);\r\n } else if (parsedInstance.rotation) {\r\n instance.rotation = Vector3.FromArray(parsedInstance.rotation);\r\n }\r\n\r\n instance.scaling = Vector3.FromArray(parsedInstance.scaling);\r\n\r\n if (parsedInstance.checkCollisions != undefined && parsedInstance.checkCollisions != null) {\r\n instance.checkCollisions = parsedInstance.checkCollisions;\r\n }\r\n if (parsedInstance.pickable != undefined && parsedInstance.pickable != null) {\r\n instance.isPickable = parsedInstance.pickable;\r\n }\r\n if (parsedInstance.showBoundingBox != undefined && parsedInstance.showBoundingBox != null) {\r\n instance.showBoundingBox = parsedInstance.showBoundingBox;\r\n }\r\n if (parsedInstance.showSubMeshesBoundingBox != undefined && parsedInstance.showSubMeshesBoundingBox != null) {\r\n instance.showSubMeshesBoundingBox = parsedInstance.showSubMeshesBoundingBox;\r\n }\r\n if (parsedInstance.alphaIndex != undefined && parsedInstance.showSubMeshesBoundingBox != null) {\r\n instance.alphaIndex = parsedInstance.alphaIndex;\r\n }\r\n\r\n // Physics\r\n if (parsedInstance.physicsImpostor) {\r\n Mesh._PhysicsImpostorParser(scene, instance, parsedInstance);\r\n }\r\n\r\n // Actions\r\n if (parsedInstance.actions !== undefined) {\r\n instance._waitingData.actions = parsedInstance.actions;\r\n }\r\n\r\n // Animation\r\n if (parsedInstance.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedInstance.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedInstance.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n instance.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n Node.ParseAnimationRanges(instance, parsedInstance, scene);\r\n\r\n if (parsedInstance.autoAnimate) {\r\n scene.beginAnimation(\r\n instance,\r\n parsedInstance.autoAnimateFrom,\r\n parsedInstance.autoAnimateTo,\r\n parsedInstance.autoAnimateLoop,\r\n parsedInstance.autoAnimateSpeed || 1.0\r\n );\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Thin instances\r\n if (parsedMesh.thinInstances) {\r\n const thinInstances = parsedMesh.thinInstances;\r\n\r\n mesh.thinInstanceEnablePicking = !!thinInstances.enablePicking;\r\n\r\n if (thinInstances.matrixData) {\r\n mesh.thinInstanceSetBuffer(\"matrix\", new Float32Array(thinInstances.matrixData), 16, false);\r\n\r\n mesh._thinInstanceDataStorage.matrixBufferSize = thinInstances.matrixBufferSize;\r\n mesh._thinInstanceDataStorage.instancesCount = thinInstances.instancesCount;\r\n } else {\r\n mesh._thinInstanceDataStorage.matrixBufferSize = thinInstances.matrixBufferSize;\r\n }\r\n\r\n if (parsedMesh.thinInstances.userThinInstance) {\r\n const userThinInstance = parsedMesh.thinInstances.userThinInstance;\r\n\r\n for (const kind in userThinInstance.data) {\r\n mesh.thinInstanceSetBuffer(kind, new Float32Array(userThinInstance.data[kind]), userThinInstance.strides[kind], false);\r\n mesh._userThinInstanceBuffersStorage.sizes[kind] = userThinInstance.sizes[kind];\r\n }\r\n }\r\n }\r\n\r\n return mesh;\r\n }\r\n\r\n // Skeletons\r\n\r\n /**\r\n * Prepare internal position array for software CPU skinning\r\n * @returns original positions used for CPU skinning. Useful for integrating Morphing with skeletons in same mesh\r\n */\r\n public setPositionsForCPUSkinning(): Nullable {\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n if (!internalDataInfo._sourcePositions) {\r\n const source = this.getVerticesData(VertexBuffer.PositionKind);\r\n if (!source) {\r\n return internalDataInfo._sourcePositions;\r\n }\r\n\r\n internalDataInfo._sourcePositions = new Float32Array(source);\r\n\r\n if (!this.isVertexBufferUpdatable(VertexBuffer.PositionKind)) {\r\n this.setVerticesData(VertexBuffer.PositionKind, source, true);\r\n }\r\n }\r\n return internalDataInfo._sourcePositions;\r\n }\r\n\r\n /**\r\n * Prepare internal normal array for software CPU skinning\r\n * @returns original normals used for CPU skinning. Useful for integrating Morphing with skeletons in same mesh.\r\n */\r\n public setNormalsForCPUSkinning(): Nullable {\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n\r\n if (!internalDataInfo._sourceNormals) {\r\n const source = this.getVerticesData(VertexBuffer.NormalKind);\r\n\r\n if (!source) {\r\n return internalDataInfo._sourceNormals;\r\n }\r\n\r\n internalDataInfo._sourceNormals = new Float32Array(source);\r\n\r\n if (!this.isVertexBufferUpdatable(VertexBuffer.NormalKind)) {\r\n this.setVerticesData(VertexBuffer.NormalKind, source, true);\r\n }\r\n }\r\n return internalDataInfo._sourceNormals;\r\n }\r\n\r\n /**\r\n * Updates the vertex buffer by applying transformation from the bones\r\n * @param skeleton defines the skeleton to apply to current mesh\r\n * @returns the current mesh\r\n */\r\n public applySkeleton(skeleton: Skeleton): Mesh {\r\n if (!this.geometry) {\r\n return this;\r\n }\r\n\r\n if (this.geometry._softwareSkinningFrameId == this.getScene().getFrameId()) {\r\n return this;\r\n }\r\n\r\n this.geometry._softwareSkinningFrameId = this.getScene().getFrameId();\r\n\r\n if (!this.isVerticesDataPresent(VertexBuffer.PositionKind)) {\r\n return this;\r\n }\r\n if (!this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {\r\n return this;\r\n }\r\n if (!this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {\r\n return this;\r\n }\r\n\r\n const hasNormals = this.isVerticesDataPresent(VertexBuffer.NormalKind);\r\n\r\n const internalDataInfo = this._internalMeshDataInfo;\r\n\r\n if (!internalDataInfo._sourcePositions) {\r\n const submeshes = this.subMeshes.slice();\r\n this.setPositionsForCPUSkinning();\r\n this.subMeshes = submeshes;\r\n }\r\n\r\n if (hasNormals && !internalDataInfo._sourceNormals) {\r\n this.setNormalsForCPUSkinning();\r\n }\r\n\r\n // positionsData checks for not being Float32Array will only pass at most once\r\n let positionsData = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (!positionsData) {\r\n return this;\r\n }\r\n\r\n if (!(positionsData instanceof Float32Array)) {\r\n positionsData = new Float32Array(positionsData);\r\n }\r\n\r\n // normalsData checks for not being Float32Array will only pass at most once\r\n let normalsData = this.getVerticesData(VertexBuffer.NormalKind);\r\n\r\n if (hasNormals) {\r\n if (!normalsData) {\r\n return this;\r\n }\r\n\r\n if (!(normalsData instanceof Float32Array)) {\r\n normalsData = new Float32Array(normalsData);\r\n }\r\n }\r\n\r\n const matricesIndicesData = this.getVerticesData(VertexBuffer.MatricesIndicesKind);\r\n const matricesWeightsData = this.getVerticesData(VertexBuffer.MatricesWeightsKind);\r\n\r\n if (!matricesWeightsData || !matricesIndicesData) {\r\n return this;\r\n }\r\n\r\n const needExtras = this.numBoneInfluencers > 4;\r\n const matricesIndicesExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;\r\n const matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;\r\n\r\n const skeletonMatrices = skeleton.getTransformMatrices(this);\r\n\r\n const tempVector3 = Vector3.Zero();\r\n const finalMatrix = new Matrix();\r\n const tempMatrix = new Matrix();\r\n\r\n let matWeightIdx = 0;\r\n let inf: number;\r\n for (let index = 0; index < positionsData.length; index += 3, matWeightIdx += 4) {\r\n let weight: number;\r\n for (inf = 0; inf < 4; inf++) {\r\n weight = matricesWeightsData[matWeightIdx + inf];\r\n if (weight > 0) {\r\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesData[matWeightIdx + inf] * 16), weight, tempMatrix);\r\n finalMatrix.addToSelf(tempMatrix);\r\n }\r\n }\r\n if (needExtras) {\r\n for (inf = 0; inf < 4; inf++) {\r\n weight = matricesWeightsExtraData![matWeightIdx + inf];\r\n if (weight > 0) {\r\n Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, Math.floor(matricesIndicesExtraData![matWeightIdx + inf] * 16), weight, tempMatrix);\r\n finalMatrix.addToSelf(tempMatrix);\r\n }\r\n }\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(\r\n internalDataInfo._sourcePositions![index],\r\n internalDataInfo._sourcePositions![index + 1],\r\n internalDataInfo._sourcePositions![index + 2],\r\n finalMatrix,\r\n tempVector3\r\n );\r\n tempVector3.toArray(positionsData, index);\r\n\r\n if (hasNormals) {\r\n Vector3.TransformNormalFromFloatsToRef(\r\n internalDataInfo._sourceNormals![index],\r\n internalDataInfo._sourceNormals![index + 1],\r\n internalDataInfo._sourceNormals![index + 2],\r\n finalMatrix,\r\n tempVector3\r\n );\r\n tempVector3.toArray(normalsData!, index);\r\n }\r\n\r\n finalMatrix.reset();\r\n }\r\n\r\n this.updateVerticesData(VertexBuffer.PositionKind, positionsData);\r\n if (hasNormals) {\r\n this.updateVerticesData(VertexBuffer.NormalKind, normalsData!);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n // Tools\r\n\r\n /**\r\n * Returns an object containing a min and max Vector3 which are the minimum and maximum vectors of each mesh bounding box from the passed array, in the world coordinates\r\n * @param meshes defines the list of meshes to scan\r\n * @returns an object `{min:` Vector3`, max:` Vector3`}`\r\n */\r\n public static MinMax(meshes: AbstractMesh[]): { min: Vector3; max: Vector3 } {\r\n let minVector: Nullable = null;\r\n let maxVector: Nullable = null;\r\n\r\n meshes.forEach(function (mesh) {\r\n const boundingInfo = mesh.getBoundingInfo();\r\n\r\n const boundingBox = boundingInfo.boundingBox;\r\n if (!minVector || !maxVector) {\r\n minVector = boundingBox.minimumWorld;\r\n maxVector = boundingBox.maximumWorld;\r\n } else {\r\n minVector.minimizeInPlace(boundingBox.minimumWorld);\r\n maxVector.maximizeInPlace(boundingBox.maximumWorld);\r\n }\r\n });\r\n\r\n if (!minVector || !maxVector) {\r\n return {\r\n min: Vector3.Zero(),\r\n max: Vector3.Zero(),\r\n };\r\n }\r\n\r\n return {\r\n min: minVector,\r\n max: maxVector,\r\n };\r\n }\r\n\r\n /**\r\n * Returns the center of the `{min:` Vector3`, max:` Vector3`}` or the center of MinMax vector3 computed from a mesh array\r\n * @param meshesOrMinMaxVector could be an array of meshes or a `{min:` Vector3`, max:` Vector3`}` object\r\n * @returns a vector3\r\n */\r\n public static Center(meshesOrMinMaxVector: { min: Vector3; max: Vector3 } | AbstractMesh[]): Vector3 {\r\n const minMaxVector = meshesOrMinMaxVector instanceof Array ? Mesh.MinMax(meshesOrMinMaxVector) : meshesOrMinMaxVector;\r\n return Vector3.Center(minMaxVector.min, minMaxVector.max);\r\n }\r\n\r\n /**\r\n * Merge the array of meshes into a single mesh for performance reasons.\r\n * @param meshes array of meshes with the vertices to merge. Entries cannot be empty meshes.\r\n * @param disposeSource when true (default), dispose of the vertices from the source meshes.\r\n * @param allow32BitsIndices when the sum of the vertices > 64k, this must be set to true.\r\n * @param meshSubclass (optional) can be set to a Mesh where the merged vertices will be inserted.\r\n * @param subdivideWithSubMeshes when true (false default), subdivide mesh into subMeshes.\r\n * @param multiMultiMaterials when true (false default), subdivide mesh into subMeshes with multiple materials, ignores subdivideWithSubMeshes.\r\n * @returns a new mesh\r\n */\r\n public static MergeMeshes(\r\n meshes: Array,\r\n disposeSource = true,\r\n allow32BitsIndices?: boolean,\r\n meshSubclass?: Mesh,\r\n subdivideWithSubMeshes?: boolean,\r\n multiMultiMaterials?: boolean\r\n ) {\r\n return runCoroutineSync(Mesh._MergeMeshesCoroutine(meshes, disposeSource, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials, false));\r\n }\r\n\r\n /**\r\n * Merge the array of meshes into a single mesh for performance reasons.\r\n * @param meshes array of meshes with the vertices to merge. Entries cannot be empty meshes.\r\n * @param disposeSource when true (default), dispose of the vertices from the source meshes.\r\n * @param allow32BitsIndices when the sum of the vertices > 64k, this must be set to true.\r\n * @param meshSubclass (optional) can be set to a Mesh where the merged vertices will be inserted.\r\n * @param subdivideWithSubMeshes when true (false default), subdivide mesh into subMeshes.\r\n * @param multiMultiMaterials when true (false default), subdivide mesh into subMeshes with multiple materials, ignores subdivideWithSubMeshes.\r\n * @returns a new mesh\r\n */\r\n public static MergeMeshesAsync(\r\n meshes: Array,\r\n disposeSource = true,\r\n allow32BitsIndices?: boolean,\r\n meshSubclass?: Mesh,\r\n subdivideWithSubMeshes?: boolean,\r\n multiMultiMaterials?: boolean\r\n ) {\r\n return runCoroutineAsync(\r\n Mesh._MergeMeshesCoroutine(meshes, disposeSource, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials, true),\r\n createYieldingScheduler()\r\n );\r\n }\r\n\r\n private static *_MergeMeshesCoroutine(\r\n meshes: Array,\r\n disposeSource = true,\r\n allow32BitsIndices: boolean | undefined,\r\n meshSubclass: Mesh | undefined,\r\n subdivideWithSubMeshes: boolean | undefined,\r\n multiMultiMaterials: boolean | undefined,\r\n isAsync: boolean\r\n ): Coroutine> {\r\n // Remove any null/undefined entries from the mesh array\r\n meshes = meshes.filter(Boolean);\r\n\r\n if (meshes.length === 0) {\r\n return null;\r\n }\r\n\r\n let index: number;\r\n if (!allow32BitsIndices) {\r\n let totalVertices = 0;\r\n\r\n // Counting vertices\r\n for (index = 0; index < meshes.length; index++) {\r\n totalVertices += meshes[index].getTotalVertices();\r\n\r\n if (totalVertices >= 65536) {\r\n Logger.Warn(\"Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices\");\r\n return null;\r\n }\r\n }\r\n }\r\n if (multiMultiMaterials) {\r\n subdivideWithSubMeshes = false;\r\n }\r\n const materialArray: Array = new Array();\r\n const materialIndexArray: Array = new Array();\r\n // Merge\r\n const indiceArray: Array = new Array();\r\n const currentOverrideMaterialSideOrientation = meshes[0].overrideMaterialSideOrientation;\r\n\r\n for (index = 0; index < meshes.length; index++) {\r\n const mesh = meshes[index];\r\n if (mesh.isAnInstance) {\r\n Logger.Warn(\"Cannot merge instance meshes.\");\r\n return null;\r\n }\r\n\r\n if (currentOverrideMaterialSideOrientation !== mesh.overrideMaterialSideOrientation) {\r\n Logger.Warn(\"Cannot merge meshes with different overrideMaterialSideOrientation values.\");\r\n return null;\r\n }\r\n\r\n if (subdivideWithSubMeshes) {\r\n indiceArray.push(mesh.getTotalIndices());\r\n }\r\n\r\n if (multiMultiMaterials) {\r\n if (mesh.material) {\r\n const material = mesh.material;\r\n if (material instanceof MultiMaterial) {\r\n for (let matIndex = 0; matIndex < material.subMaterials.length; matIndex++) {\r\n if (materialArray.indexOf(material.subMaterials[matIndex]) < 0) {\r\n materialArray.push(material.subMaterials[matIndex]);\r\n }\r\n }\r\n for (let subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {\r\n materialIndexArray.push(materialArray.indexOf(material.subMaterials[mesh.subMeshes[subIndex].materialIndex]));\r\n indiceArray.push(mesh.subMeshes[subIndex].indexCount);\r\n }\r\n } else {\r\n if (materialArray.indexOf(material) < 0) {\r\n materialArray.push(material);\r\n }\r\n for (let subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {\r\n materialIndexArray.push(materialArray.indexOf(material));\r\n indiceArray.push(mesh.subMeshes[subIndex].indexCount);\r\n }\r\n }\r\n } else {\r\n for (let subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {\r\n materialIndexArray.push(0);\r\n indiceArray.push(mesh.subMeshes[subIndex].indexCount);\r\n }\r\n }\r\n }\r\n }\r\n\r\n const source = meshes[0];\r\n\r\n const getVertexDataFromMesh = (mesh: Mesh) => {\r\n const wm = mesh.computeWorldMatrix(true);\r\n const vertexData = VertexData.ExtractFromMesh(mesh, false, false);\r\n return { vertexData, transform: wm };\r\n };\r\n\r\n const { vertexData: sourceVertexData, transform: sourceTransform } = getVertexDataFromMesh(source);\r\n if (isAsync) {\r\n yield;\r\n }\r\n\r\n const meshVertexDatas = new Array<{ vertexData: VertexData; transform?: Matrix }>(meshes.length - 1);\r\n for (let i = 1; i < meshes.length; i++) {\r\n meshVertexDatas[i - 1] = getVertexDataFromMesh(meshes[i]);\r\n if (isAsync) {\r\n yield;\r\n }\r\n }\r\n\r\n const mergeCoroutine = sourceVertexData._mergeCoroutine(sourceTransform, meshVertexDatas, allow32BitsIndices, isAsync, !disposeSource);\r\n let mergeCoroutineStep = mergeCoroutine.next();\r\n while (!mergeCoroutineStep.done) {\r\n if (isAsync) {\r\n yield;\r\n }\r\n mergeCoroutineStep = mergeCoroutine.next();\r\n }\r\n const vertexData = mergeCoroutineStep.value;\r\n\r\n if (!meshSubclass) {\r\n meshSubclass = new Mesh(source.name + \"_merged\", source.getScene());\r\n }\r\n\r\n const applyToCoroutine = vertexData._applyToCoroutine(meshSubclass, undefined, isAsync);\r\n let applyToCoroutineStep = applyToCoroutine.next();\r\n while (!applyToCoroutineStep.done) {\r\n if (isAsync) {\r\n yield;\r\n }\r\n applyToCoroutineStep = applyToCoroutine.next();\r\n }\r\n\r\n // Setting properties\r\n meshSubclass.checkCollisions = source.checkCollisions;\r\n meshSubclass.overrideMaterialSideOrientation = source.overrideMaterialSideOrientation;\r\n\r\n // Cleaning\r\n if (disposeSource) {\r\n for (index = 0; index < meshes.length; index++) {\r\n meshes[index].dispose();\r\n }\r\n }\r\n\r\n // Subdivide\r\n if (subdivideWithSubMeshes || multiMultiMaterials) {\r\n //-- removal of global submesh\r\n meshSubclass.releaseSubMeshes();\r\n index = 0;\r\n let offset = 0;\r\n\r\n //-- apply subdivision according to index table\r\n while (index < indiceArray.length) {\r\n SubMesh.CreateFromIndices(0, offset, indiceArray[index], meshSubclass, undefined, false);\r\n offset += indiceArray[index];\r\n index++;\r\n }\r\n\r\n for (const subMesh of meshSubclass.subMeshes) {\r\n subMesh.refreshBoundingInfo();\r\n }\r\n\r\n meshSubclass.computeWorldMatrix(true);\r\n }\r\n\r\n if (multiMultiMaterials) {\r\n const newMultiMaterial = new MultiMaterial(source.name + \"_merged\", source.getScene());\r\n newMultiMaterial.subMaterials = materialArray;\r\n for (let subIndex = 0; subIndex < meshSubclass.subMeshes.length; subIndex++) {\r\n meshSubclass.subMeshes[subIndex].materialIndex = materialIndexArray[subIndex];\r\n }\r\n meshSubclass.material = newMultiMaterial;\r\n } else {\r\n meshSubclass.material = source.material;\r\n }\r\n\r\n return meshSubclass;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public addInstance(instance: InstancedMesh) {\r\n instance._indexInSourceMeshInstanceArray = this.instances.length;\r\n this.instances.push(instance);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public removeInstance(instance: InstancedMesh) {\r\n // Remove from mesh\r\n const index = instance._indexInSourceMeshInstanceArray;\r\n if (index != -1) {\r\n if (index !== this.instances.length - 1) {\r\n const last = this.instances[this.instances.length - 1];\r\n this.instances[index] = last;\r\n last._indexInSourceMeshInstanceArray = index;\r\n }\r\n\r\n instance._indexInSourceMeshInstanceArray = -1;\r\n this.instances.pop();\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _shouldConvertRHS() {\r\n return this.overrideMaterialSideOrientation === Material.CounterClockWiseSideOrientation;\r\n }\r\n\r\n /** @internal */\r\n public _getRenderingFillMode(fillMode: number): number {\r\n const scene = this.getScene();\r\n\r\n if (scene.forcePointsCloud) return Material.PointFillMode;\r\n\r\n if (scene.forceWireframe) return Material.WireFrameFillMode;\r\n\r\n return this.overrideRenderingFillMode ?? fillMode;\r\n }\r\n\r\n // deprecated methods\r\n /**\r\n * Sets the mesh material by the material or multiMaterial `id` property\r\n * @param id is a string identifying the material or the multiMaterial\r\n * @returns the current mesh\r\n * @deprecated Please use MeshBuilder instead Please use setMaterialById instead\r\n */\r\n public setMaterialByID(id: string): Mesh {\r\n return this.setMaterialById(id);\r\n }\r\n\r\n /**\r\n * Creates a ribbon mesh.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n * @param name defines the name of the mesh to create\r\n * @param pathArray is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry.\r\n * @param closeArray creates a seam between the first and the last paths of the path array (default is false)\r\n * @param closePath creates a seam between the first and the last points of each path of the path array\r\n * @param offset is taken in account only if the `pathArray` is containing a single path\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @param instance defines an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#ribbon)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateRibbon(\r\n name: string,\r\n pathArray: Vector3[][],\r\n closeArray: boolean,\r\n closePath: boolean,\r\n offset: number,\r\n scene?: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a plane polygonal mesh. By default, this is a disc.\r\n * @param name defines the name of the mesh to create\r\n * @param radius sets the radius size (float) of the polygon (default 0.5)\r\n * @param tessellation sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateDisc(name: string, radius: number, tessellation: number, scene: Nullable, updatable?: boolean, sideOrientation?: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a box mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param size sets the size (float) of each box side (default 1)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateBox(name: string, size: number, scene: Nullable, updatable?: boolean, sideOrientation?: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a sphere mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param segments sets the sphere number of horizontal stripes (positive integer, default 32)\r\n * @param diameter sets the diameter size (float) of the sphere (default 1)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateSphere(name: string, segments: number, diameter: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a hemisphere mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param segments sets the sphere number of horizontal stripes (positive integer, default 32)\r\n * @param diameter sets the diameter size (float) of the sphere (default 1)\r\n * @param scene defines the hosting scene\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateHemisphere(name: string, segments: number, diameter: number, scene?: Scene): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a cylinder or a cone mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param height sets the height size (float) of the cylinder/cone (float, default 2)\r\n * @param diameterTop set the top cap diameter (floats, default 1)\r\n * @param diameterBottom set the bottom cap diameter (floats, default 1). This value can't be zero\r\n * @param tessellation sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance\r\n * @param subdivisions sets the number of rings along the cylinder height (positive integer, default 1)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateCylinder(\r\n name: string,\r\n height: number,\r\n diameterTop: number,\r\n diameterBottom: number,\r\n tessellation: number,\r\n subdivisions: any,\r\n scene?: Scene,\r\n updatable?: any,\r\n sideOrientation?: number\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n // Torus (Code from SharpDX.org)\r\n /**\r\n * Creates a torus mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param diameter sets the diameter size (float) of the torus (default 1)\r\n * @param thickness sets the diameter size of the tube of the torus (float, default 0.5)\r\n * @param tessellation sets the number of torus sides (positive integer, default 16)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateTorus(name: string, diameter: number, thickness: number, tessellation: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a torus knot mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param radius sets the global radius size (float) of the torus knot (default 2)\r\n * @param tube sets the diameter size of the tube of the torus (float, default 0.5)\r\n * @param radialSegments sets the number of sides on each tube segments (positive integer, default 32)\r\n * @param tubularSegments sets the number of tubes to decompose the knot into (positive integer, default 32)\r\n * @param p the number of windings on X axis (positive integers, default 2)\r\n * @param q the number of windings on Y axis (positive integers, default 3)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateTorusKnot(\r\n name: string,\r\n radius: number,\r\n tube: number,\r\n radialSegments: number,\r\n tubularSegments: number,\r\n p: number,\r\n q: number,\r\n scene?: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a line mesh..\r\n * @param name defines the name of the mesh to create\r\n * @param points is an array successive Vector3\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines).\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateLines(name: string, points: Vector3[], scene: Nullable, updatable: boolean, instance?: Nullable): LinesMesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a dashed line mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param points is an array successive Vector3\r\n * @param dashSize is the size of the dashes relatively the dash number (positive float, default 3)\r\n * @param gapSize is the size of the gap between two successive dashes relatively the dash number (positive float, default 1)\r\n * @param dashNb is the intended total number of dashes (positive integer, default 200)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateDashedLines(\r\n name: string,\r\n points: Vector3[],\r\n dashSize: number,\r\n gapSize: number,\r\n dashNb: number,\r\n scene: Nullable,\r\n updatable?: boolean,\r\n instance?: LinesMesh\r\n ): LinesMesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a polygon mesh.Please consider using the same method from the MeshBuilder class instead\r\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.\r\n * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.\r\n * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * Remember you can only change the shape positions, not their number when updating a polygon.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#non-regular-polygon\r\n * @param name defines the name of the mesh to create\r\n * @param shape is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * @param scene defines the hosting scene\r\n * @param holes is a required array of arrays of successive Vector3 used to defines holes in the polygon\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreatePolygon(name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number, earcutInjection?: any): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates an extruded polygon mesh, with depth in the Y direction..\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-non-regular-polygon\r\n * @param name defines the name of the mesh to create\r\n * @param shape is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * @param depth defines the height of extrusion\r\n * @param scene defines the hosting scene\r\n * @param holes is a required array of arrays of successive Vector3 used to defines holes in the polygon\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static ExtrudePolygon(\r\n name: string,\r\n shape: Vector3[],\r\n depth: number,\r\n scene: Scene,\r\n holes?: Vector3[][],\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n earcutInjection?: any\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates an extruded shape mesh.\r\n * The extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\r\n * @param name defines the name of the mesh to create\r\n * @param shape is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis\r\n * @param path is a required array of successive Vector3. This is the axis curve the shape is extruded along\r\n * @param scale is the value to scale the shape\r\n * @param rotation is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve\r\n * @param cap sets the way the extruded shape is capped. Possible values : Mesh.NO_CAP (default), Mesh.CAP_START, Mesh.CAP_END, Mesh.CAP_ALL\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#extruded-shape)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static ExtrudeShape(\r\n name: string,\r\n shape: Vector3[],\r\n path: Vector3[],\r\n scale: number,\r\n rotation: number,\r\n cap: number,\r\n scene: Nullable,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates an custom extruded shape mesh.\r\n * The custom extrusion is a parametric shape.\r\n * It has no predefined shape. Its final shape will depend on the input parameters.\r\n *\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\r\n * @param name defines the name of the mesh to create\r\n * @param shape is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis\r\n * @param path is a required array of successive Vector3. This is the axis curve the shape is extruded along\r\n * @param scaleFunction is a custom Javascript function called on each path point\r\n * @param rotationFunction is a custom Javascript function called on each path point\r\n * @param ribbonCloseArray forces the extrusion underlying ribbon to close all the paths in its `pathArray`\r\n * @param ribbonClosePath forces the extrusion underlying ribbon to close its `pathArray`\r\n * @param cap sets the way the extruded shape is capped. Possible values : Mesh.NO_CAP (default), Mesh.CAP_START, Mesh.CAP_END, Mesh.CAP_ALL\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#extruded-shape)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static ExtrudeShapeCustom(\r\n name: string,\r\n shape: Vector3[],\r\n path: Vector3[],\r\n scaleFunction: Nullable<{ (i: number, distance: number): number }>,\r\n rotationFunction: Nullable<{ (i: number, distance: number): number }>,\r\n ribbonCloseArray: boolean,\r\n ribbonClosePath: boolean,\r\n cap: number,\r\n scene: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates lathe mesh.\r\n * The lathe is a shape with a symmetry axis : a 2D model shape is rotated around this axis to design the lathe.\r\n * @param name defines the name of the mesh to create\r\n * @param shape is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero\r\n * @param radius is the radius value of the lathe\r\n * @param tessellation is the side number of the lathe.\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateLathe(name: string, shape: Vector3[], radius: number, tessellation: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a plane mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param size sets the size (float) of both sides of the plane at once (default 1)\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreatePlane(name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a ground mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param width set the width of the ground\r\n * @param height set the height of the ground\r\n * @param subdivisions sets the number of subdivisions per side\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateGround(name: string, width: number, height: number, subdivisions: number, scene?: Scene, updatable?: boolean): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a tiled ground mesh.\r\n * @param name defines the name of the mesh to create\r\n * @param xmin set the ground minimum X coordinate\r\n * @param zmin set the ground minimum Y coordinate\r\n * @param xmax set the ground maximum X coordinate\r\n * @param zmax set the ground maximum Z coordinate\r\n * @param subdivisions is an object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the numbers of subdivisions on the ground width and height. Each subdivision is called a tile\r\n * @param precision is an object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the numbers of subdivisions on the ground width and height of each tile\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateTiledGround(\r\n name: string,\r\n xmin: number,\r\n zmin: number,\r\n xmax: number,\r\n zmax: number,\r\n subdivisions: { w: number; h: number },\r\n precision: { w: number; h: number },\r\n scene: Scene,\r\n updatable?: boolean\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a ground mesh from a height map.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/height_map\r\n * @param name defines the name of the mesh to create\r\n * @param url sets the URL of the height map image resource\r\n * @param width set the ground width size\r\n * @param height set the ground height size\r\n * @param subdivisions sets the number of subdivision per side\r\n * @param minHeight is the minimum altitude on the ground\r\n * @param maxHeight is the maximum altitude on the ground\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param onReady is a callback function that will be called once the mesh is built (the height map download can last some time)\r\n * @param alphaFilter will filter any data where the alpha channel is below this value, defaults 0 (all data visible)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateGroundFromHeightMap(\r\n name: string,\r\n url: string,\r\n width: number,\r\n height: number,\r\n subdivisions: number,\r\n minHeight: number,\r\n maxHeight: number,\r\n scene: Scene,\r\n updatable?: boolean,\r\n onReady?: (mesh: GroundMesh) => void,\r\n alphaFilter?: number\r\n ): GroundMesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a tube mesh.\r\n * The tube is a parametric shape.\r\n * It has no predefined shape. Its final shape will depend on the input parameters.\r\n *\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n * @param name defines the name of the mesh to create\r\n * @param path is a required array of successive Vector3. It is the curve used as the axis of the tube\r\n * @param radius sets the tube radius size\r\n * @param tessellation is the number of sides on the tubular surface\r\n * @param radiusFunction is a custom function. If it is not null, it overrides the parameter `radius`. This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path\r\n * @param cap sets the way the extruded shape is capped. Possible values : Mesh.NO_CAP (default), Mesh.CAP_START, Mesh.CAP_END, Mesh.CAP_ALL\r\n * @param scene defines the hosting scene\r\n * @param updatable defines if the mesh must be flagged as updatable\r\n * @param sideOrientation defines the mesh side orientation (https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation)\r\n * @param instance is an instance of an existing Tube object to be updated with the passed `pathArray` parameter (https://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#tube)\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateTube(\r\n name: string,\r\n path: Vector3[],\r\n radius: number,\r\n tessellation: number,\r\n radiusFunction: { (i: number, distance: number): number },\r\n cap: number,\r\n scene: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a polyhedron mesh.\r\n *.\r\n * * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embedded types. Please refer to the type sheet in the tutorial to choose the wanted type\r\n * * The parameter `size` (positive float, default 1) sets the polygon size\r\n * * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value)\r\n * * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overwrittes the parameter `type`\r\n * * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron\r\n * * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`)\r\n * * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored\r\n * * You can also set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh to create\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreatePolyhedron(\r\n name: string,\r\n options: {\r\n type?: number;\r\n size?: number;\r\n sizeX?: number;\r\n sizeY?: number;\r\n sizeZ?: number;\r\n custom?: any;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n },\r\n scene: Scene\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided\r\n * * The parameter `radius` sets the radius size (float) of the icosphere (default 1)\r\n * * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value than `radius`)\r\n * * The parameter `subdivisions` sets the number of subdivisions (positive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size\r\n * * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface\r\n * * You can also set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra#icosphere\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateIcoSphere(\r\n name: string,\r\n options: { radius?: number; flat?: boolean; subdivisions?: number; sideOrientation?: number; updatable?: boolean },\r\n scene: Scene\r\n ): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Creates a decal mesh.\r\n *.\r\n * A decal is a mesh usually applied as a model onto the surface of another mesh\r\n * @param name defines the name of the mesh\r\n * @param sourceMesh defines the mesh receiving the decal\r\n * @param position sets the position of the decal in world coordinates\r\n * @param normal sets the normal of the mesh where the decal is applied onto in world coordinates\r\n * @param size sets the decal scaling\r\n * @param angle sets the angle to rotate the decal\r\n * @returns a new Mesh\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateDecal(name: string, sourceMesh: AbstractMesh, position: Vector3, normal: Vector3, size: Vector3, angle: number): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /** Creates a Capsule Mesh\r\n * @param name defines the name of the mesh.\r\n * @param options the constructors options used to shape the mesh.\r\n * @param scene defines the scene the mesh is scoped to.\r\n * @returns the capsule mesh\r\n * @see https://doc.babylonjs.com/how_to/capsule_shape\r\n * @deprecated Please use MeshBuilder instead\r\n */\r\n public static CreateCapsule(name: string, options: ICreateCapsuleOptions, scene: Scene): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n\r\n /**\r\n * Extends a mesh to a Goldberg mesh\r\n * Warning the mesh to convert MUST be an import of a perviously exported Goldberg mesh\r\n * @param mesh the mesh to convert\r\n * @returns the extended mesh\r\n * @deprecated Please use ExtendMeshToGoldberg instead\r\n */\r\n public static ExtendToGoldberg(mesh: Mesh): Mesh {\r\n throw new Error(\"Import MeshBuilder to populate this function\");\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.Mesh\", Mesh);\r\n","import type { Behavior } from \"../../Behaviors/behavior\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { PointerInfoPre } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { PrecisionDate } from \"../../Misc/precisionDate\";\r\nimport { Epsilon } from \"../../Maths/math.constants\";\r\n\r\n/**\r\n * The autoRotation behavior (AutoRotationBehavior) is designed to create a smooth rotation of an ArcRotateCamera when there is no user interaction.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior\r\n */\r\nexport class AutoRotationBehavior implements Behavior {\r\n /**\r\n * Gets the name of the behavior.\r\n */\r\n public get name(): string {\r\n return \"AutoRotation\";\r\n }\r\n\r\n private _zoomStopsAnimation = false;\r\n private _idleRotationSpeed = 0.05;\r\n private _idleRotationWaitTime = 2000;\r\n private _idleRotationSpinupTime = 2000;\r\n\r\n public targetAlpha: Nullable = null;\r\n\r\n /**\r\n * Sets the flag that indicates if user zooming should stop animation.\r\n */\r\n public set zoomStopsAnimation(flag: boolean) {\r\n this._zoomStopsAnimation = flag;\r\n }\r\n\r\n /**\r\n * Gets the flag that indicates if user zooming should stop animation.\r\n */\r\n public get zoomStopsAnimation(): boolean {\r\n return this._zoomStopsAnimation;\r\n }\r\n\r\n /**\r\n * Sets the default speed at which the camera rotates around the model.\r\n */\r\n public set idleRotationSpeed(speed: number) {\r\n this._idleRotationSpeed = speed;\r\n }\r\n\r\n /**\r\n * Gets the default speed at which the camera rotates around the model.\r\n */\r\n public get idleRotationSpeed() {\r\n return this._idleRotationSpeed;\r\n }\r\n\r\n /**\r\n * Sets the time (in milliseconds) to wait after user interaction before the camera starts rotating.\r\n */\r\n public set idleRotationWaitTime(time: number) {\r\n this._idleRotationWaitTime = time;\r\n }\r\n\r\n /**\r\n * Gets the time (milliseconds) to wait after user interaction before the camera starts rotating.\r\n */\r\n public get idleRotationWaitTime() {\r\n return this._idleRotationWaitTime;\r\n }\r\n\r\n /**\r\n * Sets the time (milliseconds) to take to spin up to the full idle rotation speed.\r\n */\r\n public set idleRotationSpinupTime(time: number) {\r\n this._idleRotationSpinupTime = time;\r\n }\r\n\r\n /**\r\n * Gets the time (milliseconds) to take to spin up to the full idle rotation speed.\r\n */\r\n public get idleRotationSpinupTime() {\r\n return this._idleRotationSpinupTime;\r\n }\r\n\r\n /**\r\n * Gets a value indicating if the camera is currently rotating because of this behavior\r\n */\r\n public get rotationInProgress(): boolean {\r\n return Math.abs(this._cameraRotationSpeed) > 0;\r\n }\r\n\r\n // Default behavior functions\r\n private _onPrePointerObservableObserver: Nullable>;\r\n private _onAfterCheckInputsObserver: Nullable>;\r\n private _attachedCamera: Nullable;\r\n private _isPointerDown = false;\r\n private _lastFrameTime: Nullable = null;\r\n private _lastInteractionTime = -Infinity;\r\n private _cameraRotationSpeed: number = 0;\r\n\r\n /**\r\n * Initializes the behavior.\r\n */\r\n public init(): void {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Attaches the behavior to its arc rotate camera.\r\n * @param camera Defines the camera to attach the behavior to\r\n */\r\n public attach(camera: ArcRotateCamera): void {\r\n this._attachedCamera = camera;\r\n const scene = this._attachedCamera.getScene();\r\n\r\n this._onPrePointerObservableObserver = scene.onPrePointerObservable.add((pointerInfoPre) => {\r\n if (pointerInfoPre.type === PointerEventTypes.POINTERDOWN) {\r\n this._isPointerDown = true;\r\n return;\r\n }\r\n\r\n if (pointerInfoPre.type === PointerEventTypes.POINTERUP) {\r\n this._isPointerDown = false;\r\n }\r\n });\r\n\r\n this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {\r\n if (this._reachTargetAlpha()) {\r\n return;\r\n }\r\n const now = PrecisionDate.Now;\r\n let dt = 0;\r\n if (this._lastFrameTime != null) {\r\n dt = now - this._lastFrameTime;\r\n }\r\n this._lastFrameTime = now;\r\n\r\n // Stop the animation if there is user interaction and the animation should stop for this interaction\r\n this._applyUserInteraction();\r\n\r\n const timeToRotation = now - this._lastInteractionTime - this._idleRotationWaitTime;\r\n const scale = Math.max(Math.min(timeToRotation / this._idleRotationSpinupTime, 1), 0);\r\n this._cameraRotationSpeed = this._idleRotationSpeed * scale;\r\n\r\n // Step camera rotation by rotation speed\r\n if (this._attachedCamera) {\r\n this._attachedCamera.alpha -= this._cameraRotationSpeed * (dt / 1000);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Detaches the behavior from its current arc rotate camera.\r\n */\r\n public detach(): void {\r\n if (!this._attachedCamera) {\r\n return;\r\n }\r\n const scene = this._attachedCamera.getScene();\r\n\r\n if (this._onPrePointerObservableObserver) {\r\n scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);\r\n }\r\n\r\n this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);\r\n this._attachedCamera = null;\r\n }\r\n\r\n /**\r\n * Force-reset the last interaction time\r\n * @param customTime an optional time that will be used instead of the current last interaction time. For example `Date.now()`\r\n */\r\n public resetLastInteractionTime(customTime?: number): void {\r\n this._lastInteractionTime = customTime ?? PrecisionDate.Now;\r\n }\r\n\r\n /**\r\n * Returns true if camera alpha reaches the target alpha\r\n * @returns true if camera alpha reaches the target alpha\r\n */\r\n private _reachTargetAlpha(): boolean {\r\n if (this._attachedCamera && this.targetAlpha) {\r\n return Math.abs(this._attachedCamera.alpha - this.targetAlpha) < Epsilon;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Returns true if user is scrolling.\r\n * @returns true if user is scrolling.\r\n */\r\n private _userIsZooming(): boolean {\r\n if (!this._attachedCamera) {\r\n return false;\r\n }\r\n return this._attachedCamera.inertialRadiusOffset !== 0;\r\n }\r\n\r\n private _lastFrameRadius = 0;\r\n private _shouldAnimationStopForInteraction(): boolean {\r\n if (!this._attachedCamera) {\r\n return false;\r\n }\r\n\r\n let zoomHasHitLimit = false;\r\n if (this._lastFrameRadius === this._attachedCamera.radius && this._attachedCamera.inertialRadiusOffset !== 0) {\r\n zoomHasHitLimit = true;\r\n }\r\n\r\n // Update the record of previous radius - works as an approx. indicator of hitting radius limits\r\n this._lastFrameRadius = this._attachedCamera.radius;\r\n return this._zoomStopsAnimation ? zoomHasHitLimit : this._userIsZooming();\r\n }\r\n\r\n /**\r\n * Applies any current user interaction to the camera. Takes into account maximum alpha rotation.\r\n */\r\n private _applyUserInteraction(): void {\r\n if (this._userIsMoving() && !this._shouldAnimationStopForInteraction()) {\r\n this._lastInteractionTime = PrecisionDate.Now;\r\n }\r\n }\r\n\r\n // Tools\r\n private _userIsMoving(): boolean {\r\n if (!this._attachedCamera) {\r\n return false;\r\n }\r\n\r\n return (\r\n this._attachedCamera.inertialAlphaOffset !== 0 ||\r\n this._attachedCamera.inertialBetaOffset !== 0 ||\r\n this._attachedCamera.inertialRadiusOffset !== 0 ||\r\n this._attachedCamera.inertialPanningX !== 0 ||\r\n this._attachedCamera.inertialPanningY !== 0 ||\r\n this._isPointerDown\r\n );\r\n }\r\n}\r\n","import { BezierCurve } from \"../Maths/math.path\";\r\n\r\n/**\r\n * This represents the main contract an easing function should follow.\r\n * Easing functions are used throughout the animation system.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport interface IEasingFunction {\r\n /**\r\n * Given an input gradient between 0 and 1, this returns the corresponding value\r\n * of the easing function.\r\n * The link below provides some of the most common examples of easing functions.\r\n * @see https://easings.net/\r\n * @param gradient Defines the value between 0 and 1 we want the easing value for\r\n * @returns the corresponding value on the curve defined by the easing function\r\n */\r\n ease(gradient: number): number;\r\n}\r\n\r\n/**\r\n * Base class used for every default easing function.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class EasingFunction implements IEasingFunction {\r\n /**\r\n * Interpolation follows the mathematical formula associated with the easing function.\r\n */\r\n public static readonly EASINGMODE_EASEIN = 0;\r\n\r\n /**\r\n * Interpolation follows 100% interpolation minus the output of the formula associated with the easing function.\r\n */\r\n public static readonly EASINGMODE_EASEOUT = 1;\r\n\r\n /**\r\n * Interpolation uses EaseIn for the first half of the animation and EaseOut for the second half.\r\n */\r\n public static readonly EASINGMODE_EASEINOUT = 2;\r\n\r\n private _easingMode = EasingFunction.EASINGMODE_EASEIN;\r\n\r\n /**\r\n * Sets the easing mode of the current function.\r\n * @param easingMode Defines the willing mode (EASINGMODE_EASEIN, EASINGMODE_EASEOUT or EASINGMODE_EASEINOUT)\r\n */\r\n public setEasingMode(easingMode: number) {\r\n const n = Math.min(Math.max(easingMode, 0), 2);\r\n this._easingMode = n;\r\n }\r\n /**\r\n * Gets the current easing mode.\r\n * @returns the easing mode\r\n */\r\n public getEasingMode(): number {\r\n return this._easingMode;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public easeInCore(gradient: number): number {\r\n throw new Error(\"You must implement this method\");\r\n }\r\n\r\n /**\r\n * Given an input gradient between 0 and 1, this returns the corresponding value\r\n * of the easing function.\r\n * @param gradient Defines the value between 0 and 1 we want the easing value for\r\n * @returns the corresponding value on the curve defined by the easing function\r\n */\r\n public ease(gradient: number): number {\r\n switch (this._easingMode) {\r\n case EasingFunction.EASINGMODE_EASEIN:\r\n return this.easeInCore(gradient);\r\n case EasingFunction.EASINGMODE_EASEOUT:\r\n return 1 - this.easeInCore(1 - gradient);\r\n }\r\n\r\n if (gradient >= 0.5) {\r\n return (1 - this.easeInCore((1 - gradient) * 2)) * 0.5 + 0.5;\r\n }\r\n\r\n return this.easeInCore(gradient * 2) * 0.5;\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a circle shape (see link below).\r\n * @see https://easings.net/#easeInCirc\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class CircleEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n gradient = Math.max(0, Math.min(1, gradient));\r\n return 1.0 - Math.sqrt(1.0 - gradient * gradient);\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a ease back shape (see link below).\r\n * @see https://easings.net/#easeInBack\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class BackEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * Instantiates a back ease easing\r\n * @see https://easings.net/#easeInBack\r\n * @param amplitude Defines the amplitude of the function\r\n */\r\n constructor(\r\n /** Defines the amplitude of the function */\r\n public amplitude: number = 1\r\n ) {\r\n super();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n const num = Math.max(0, this.amplitude);\r\n return Math.pow(gradient, 3.0) - gradient * num * Math.sin(3.1415926535897931 * gradient);\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a bouncing shape (see link below).\r\n * @see https://easings.net/#easeInBounce\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class BounceEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * Instantiates a bounce easing\r\n * @see https://easings.net/#easeInBounce\r\n * @param bounces Defines the number of bounces\r\n * @param bounciness Defines the amplitude of the bounce\r\n */\r\n constructor(\r\n /** Defines the number of bounces */\r\n public bounces: number = 3,\r\n /** Defines the amplitude of the bounce */\r\n public bounciness: number = 2\r\n ) {\r\n super();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n const y = Math.max(0.0, this.bounces);\r\n let bounciness = this.bounciness;\r\n if (bounciness <= 1.0) {\r\n bounciness = 1.001;\r\n }\r\n const num9 = Math.pow(bounciness, y);\r\n const num5 = 1.0 - bounciness;\r\n const num4 = (1.0 - num9) / num5 + num9 * 0.5;\r\n const num15 = gradient * num4;\r\n const num65 = Math.log(-num15 * (1.0 - bounciness) + 1.0) / Math.log(bounciness);\r\n const num3 = Math.floor(num65);\r\n const num13 = num3 + 1.0;\r\n const num8 = (1.0 - Math.pow(bounciness, num3)) / (num5 * num4);\r\n const num12 = (1.0 - Math.pow(bounciness, num13)) / (num5 * num4);\r\n const num7 = (num8 + num12) * 0.5;\r\n const num6 = gradient - num7;\r\n const num2 = num7 - num8;\r\n return (-Math.pow(1.0 / bounciness, y - num3) / (num2 * num2)) * (num6 - num2) * (num6 + num2);\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a power of 3 shape (see link below).\r\n * @see https://easings.net/#easeInCubic\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class CubicEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n return gradient * gradient * gradient;\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with an elastic shape (see link below).\r\n * @see https://easings.net/#easeInElastic\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class ElasticEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * Instantiates an elastic easing function\r\n * @see https://easings.net/#easeInElastic\r\n * @param oscillations Defines the number of oscillations\r\n * @param springiness Defines the amplitude of the oscillations\r\n */\r\n constructor(\r\n /** Defines the number of oscillations*/\r\n public oscillations: number = 3,\r\n /** Defines the amplitude of the oscillations*/\r\n public springiness: number = 3\r\n ) {\r\n super();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n let num2;\r\n const num3 = Math.max(0.0, this.oscillations);\r\n const num = Math.max(0.0, this.springiness);\r\n\r\n if (num == 0) {\r\n num2 = gradient;\r\n } else {\r\n num2 = (Math.exp(num * gradient) - 1.0) / (Math.exp(num) - 1.0);\r\n }\r\n return num2 * Math.sin((6.2831853071795862 * num3 + 1.5707963267948966) * gradient);\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with an exponential shape (see link below).\r\n * @see https://easings.net/#easeInExpo\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class ExponentialEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * Instantiates an exponential easing function\r\n * @see https://easings.net/#easeInExpo\r\n * @param exponent Defines the exponent of the function\r\n */\r\n constructor(\r\n /** Defines the exponent of the function */\r\n public exponent: number = 2\r\n ) {\r\n super();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n if (this.exponent <= 0) {\r\n return gradient;\r\n }\r\n\r\n return (Math.exp(this.exponent * gradient) - 1.0) / (Math.exp(this.exponent) - 1.0);\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a power shape (see link below).\r\n * @see https://easings.net/#easeInQuad\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class PowerEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * Instantiates an power base easing function\r\n * @see https://easings.net/#easeInQuad\r\n * @param power Defines the power of the function\r\n */\r\n constructor(\r\n /** Defines the power of the function */\r\n public power: number = 2\r\n ) {\r\n super();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n const y = Math.max(0.0, this.power);\r\n return Math.pow(gradient, y);\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a power of 2 shape (see link below).\r\n * @see https://easings.net/#easeInQuad\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class QuadraticEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n return gradient * gradient;\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a power of 4 shape (see link below).\r\n * @see https://easings.net/#easeInQuart\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class QuarticEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n return gradient * gradient * gradient * gradient;\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a power of 5 shape (see link below).\r\n * @see https://easings.net/#easeInQuint\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class QuinticEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n return gradient * gradient * gradient * gradient * gradient;\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a sin shape (see link below).\r\n * @see https://easings.net/#easeInSine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class SineEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n return 1.0 - Math.sin(1.5707963267948966 * (1.0 - gradient));\r\n }\r\n}\r\n\r\n/**\r\n * Easing function with a bezier shape (see link below).\r\n * @see http://cubic-bezier.com/#.17,.67,.83,.67\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#easing-functions\r\n */\r\nexport class BezierCurveEase extends EasingFunction implements IEasingFunction {\r\n /**\r\n * Instantiates a bezier function\r\n * @see http://cubic-bezier.com/#.17,.67,.83,.67\r\n * @param x1 Defines the x component of the start tangent in the bezier curve\r\n * @param y1 Defines the y component of the start tangent in the bezier curve\r\n * @param x2 Defines the x component of the end tangent in the bezier curve\r\n * @param y2 Defines the y component of the end tangent in the bezier curve\r\n */\r\n constructor(\r\n /** Defines the x component of the start tangent in the bezier curve */\r\n public x1: number = 0,\r\n /** Defines the y component of the start tangent in the bezier curve */\r\n public y1: number = 0,\r\n /** Defines the x component of the end tangent in the bezier curve */\r\n public x2: number = 1,\r\n /** Defines the y component of the end tangent in the bezier curve */\r\n public y2: number = 1\r\n ) {\r\n super();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public easeInCore(gradient: number): number {\r\n return BezierCurve.Interpolate(gradient, this.x1, this.y1, this.x2, this.y2);\r\n }\r\n}\r\n","/**\r\n * Represents the range of an animation\r\n */\r\nexport class AnimationRange {\r\n /**\r\n * Initializes the range of an animation\r\n * @param name The name of the animation range\r\n * @param from The starting frame of the animation\r\n * @param to The ending frame of the animation\r\n */\r\n constructor(\r\n /**The name of the animation range**/\r\n public name: string,\r\n /**The starting frame of the animation */\r\n public from: number,\r\n /**The ending frame of the animation*/\r\n public to: number\r\n ) {}\r\n\r\n /**\r\n * Makes a copy of the animation range\r\n * @returns A copy of the animation range\r\n */\r\n public clone(): AnimationRange {\r\n return new AnimationRange(this.name, this.from, this.to);\r\n }\r\n}\r\n","/**\r\n * Interface for the size containing width and height\r\n */\r\nexport interface ISize {\r\n /**\r\n * Width\r\n */\r\n width: number;\r\n /**\r\n * Height\r\n */\r\n height: number;\r\n}\r\n\r\n/**\r\n * Size containing width and height\r\n */\r\nexport class Size implements ISize {\r\n /**\r\n * Width\r\n */\r\n public width: number;\r\n /**\r\n * Height\r\n */\r\n public height: number;\r\n\r\n /**\r\n * Creates a Size object from the given width and height (floats).\r\n * @param width width of the new size\r\n * @param height height of the new size\r\n */\r\n public constructor(width: number, height: number) {\r\n this.width = width;\r\n this.height = height;\r\n }\r\n\r\n /**\r\n * Returns a string with the Size width and height\r\n * @returns a string with the Size width and height\r\n */\r\n public toString(): string {\r\n return `{W: ${this.width}, H: ${this.height}}`;\r\n }\r\n /**\r\n * \"Size\"\r\n * @returns the string \"Size\"\r\n */\r\n public getClassName(): string {\r\n return \"Size\";\r\n }\r\n /**\r\n * Returns the Size hash code.\r\n * @returns a hash code for a unique width and height\r\n */\r\n public getHashCode(): number {\r\n let hash = this.width | 0;\r\n hash = (hash * 397) ^ (this.height | 0);\r\n return hash;\r\n }\r\n /**\r\n * Updates the current size from the given one.\r\n * @param src the given size\r\n */\r\n public copyFrom(src: Size) {\r\n this.width = src.width;\r\n this.height = src.height;\r\n }\r\n /**\r\n * Updates in place the current Size from the given floats.\r\n * @param width width of the new size\r\n * @param height height of the new size\r\n * @returns the updated Size.\r\n */\r\n public copyFromFloats(width: number, height: number): Size {\r\n this.width = width;\r\n this.height = height;\r\n return this;\r\n }\r\n /**\r\n * Updates in place the current Size from the given floats.\r\n * @param width width to set\r\n * @param height height to set\r\n * @returns the updated Size.\r\n */\r\n public set(width: number, height: number): Size {\r\n return this.copyFromFloats(width, height);\r\n }\r\n /**\r\n * Multiplies the width and height by numbers\r\n * @param w factor to multiple the width by\r\n * @param h factor to multiple the height by\r\n * @returns a new Size set with the multiplication result of the current Size and the given floats.\r\n */\r\n public multiplyByFloats(w: number, h: number): Size {\r\n return new Size(this.width * w, this.height * h);\r\n }\r\n /**\r\n * Clones the size\r\n * @returns a new Size copied from the given one.\r\n */\r\n public clone(): Size {\r\n return new Size(this.width, this.height);\r\n }\r\n /**\r\n * True if the current Size and the given one width and height are strictly equal.\r\n * @param other the other size to compare against\r\n * @returns True if the current Size and the given one width and height are strictly equal.\r\n */\r\n public equals(other: Size): boolean {\r\n if (!other) {\r\n return false;\r\n }\r\n return this.width === other.width && this.height === other.height;\r\n }\r\n /**\r\n * The surface of the Size : width * height (float).\r\n */\r\n public get surface(): number {\r\n return this.width * this.height;\r\n }\r\n /**\r\n * Create a new size of zero\r\n * @returns a new Size set to (0.0, 0.0)\r\n */\r\n public static Zero(): Size {\r\n return new Size(0.0, 0.0);\r\n }\r\n /**\r\n * Sums the width and height of two sizes\r\n * @param otherSize size to add to this size\r\n * @returns a new Size set as the addition result of the current Size and the given one.\r\n */\r\n public add(otherSize: Size): Size {\r\n const r = new Size(this.width + otherSize.width, this.height + otherSize.height);\r\n return r;\r\n }\r\n /**\r\n * Subtracts the width and height of two\r\n * @param otherSize size to subtract to this size\r\n * @returns a new Size set as the subtraction result of the given one from the current Size.\r\n */\r\n public subtract(otherSize: Size): Size {\r\n const r = new Size(this.width - otherSize.width, this.height - otherSize.height);\r\n return r;\r\n }\r\n /**\r\n * Creates a new Size set at the linear interpolation \"amount\" between \"start\" and \"end\"\r\n * @param start starting size to lerp between\r\n * @param end end size to lerp between\r\n * @param amount amount to lerp between the start and end values\r\n * @returns a new Size set at the linear interpolation \"amount\" between \"start\" and \"end\"\r\n */\r\n public static Lerp(start: Size, end: Size, amount: number): Size {\r\n const w = start.width + (end.width - start.width) * amount;\r\n const h = start.height + (end.height - start.height) * amount;\r\n\r\n return new Size(w, h);\r\n }\r\n}\r\n","import type { IEasingFunction, EasingFunction } from \"./easing\";\r\nimport { Vector3, Quaternion, Vector2, Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\n\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { SerializationHelper } from \"../Misc/decorators\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { IAnimationKey } from \"./animationKey\";\r\nimport { AnimationKeyInterpolation } from \"./animationKey\";\r\nimport { AnimationRange } from \"./animationRange\";\r\nimport type { AnimationEvent } from \"./animationEvent\";\r\nimport { Node } from \"../node\";\r\nimport type { IAnimatable } from \"./animatable.interface\";\r\nimport { Size } from \"../Maths/math.size\";\r\nimport { WebRequest } from \"../Misc/webRequest\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport type { Animatable } from \"./animatable\";\r\nimport type { RuntimeAnimation } from \"./runtimeAnimation\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _IAnimationState {\r\n key: number;\r\n repeatCount: number;\r\n workValue?: any;\r\n loopMode?: number;\r\n offsetValue?: any;\r\n highLimitValue?: any;\r\n}\r\n\r\n/**\r\n * Class used to store any kind of animation\r\n */\r\nexport class Animation {\r\n private static _UniqueIdGenerator = 0;\r\n\r\n /**\r\n * Use matrix interpolation instead of using direct key value when animating matrices\r\n */\r\n public static AllowMatricesInterpolation = false;\r\n\r\n /**\r\n * When matrix interpolation is enabled, this boolean forces the system to use Matrix.DecomposeLerp instead of Matrix.Lerp. Interpolation is more precise but slower\r\n */\r\n public static AllowMatrixDecomposeForInterpolation = true;\r\n\r\n /**\r\n * Gets or sets the unique id of the animation (the uniqueness is solely among other animations)\r\n */\r\n public uniqueId: number;\r\n\r\n /** Define the Url to load snippets */\r\n public static SnippetUrl = Constants.SnippetUrl;\r\n\r\n /** Snippet ID if the animation was created from the snippet server */\r\n public snippetId: string;\r\n\r\n /**\r\n * Stores the key frames of the animation\r\n */\r\n private _keys: Array;\r\n\r\n /**\r\n * Stores the easing function of the animation\r\n */\r\n private _easingFunction: Nullable = null;\r\n\r\n /**\r\n * @internal Internal use only\r\n */\r\n public _runtimeAnimations = new Array();\r\n\r\n /**\r\n * The set of event that will be linked to this animation\r\n */\r\n private _events = new Array();\r\n\r\n /**\r\n * Stores an array of target property paths\r\n */\r\n public targetPropertyPath: string[];\r\n\r\n /**\r\n * Stores the blending speed of the animation\r\n */\r\n public blendingSpeed = 0.01;\r\n\r\n /**\r\n * Stores the animation ranges for the animation\r\n */\r\n private _ranges: { [name: string]: Nullable } = {};\r\n\r\n /**\r\n * @internal Internal use\r\n */\r\n public static _PrepareAnimation(\r\n name: string,\r\n targetProperty: string,\r\n framePerSecond: number,\r\n totalFrame: number,\r\n from: any,\r\n to: any,\r\n loopMode?: number,\r\n easingFunction?: EasingFunction\r\n ): Nullable {\r\n let dataType = undefined;\r\n\r\n if (!isNaN(parseFloat(from)) && isFinite(from)) {\r\n dataType = Animation.ANIMATIONTYPE_FLOAT;\r\n } else if (from instanceof Quaternion) {\r\n dataType = Animation.ANIMATIONTYPE_QUATERNION;\r\n } else if (from instanceof Vector3) {\r\n dataType = Animation.ANIMATIONTYPE_VECTOR3;\r\n } else if (from instanceof Vector2) {\r\n dataType = Animation.ANIMATIONTYPE_VECTOR2;\r\n } else if (from instanceof Color3) {\r\n dataType = Animation.ANIMATIONTYPE_COLOR3;\r\n } else if (from instanceof Color4) {\r\n dataType = Animation.ANIMATIONTYPE_COLOR4;\r\n } else if (from instanceof Size) {\r\n dataType = Animation.ANIMATIONTYPE_SIZE;\r\n }\r\n\r\n if (dataType == undefined) {\r\n return null;\r\n }\r\n\r\n const animation = new Animation(name, targetProperty, framePerSecond, dataType, loopMode);\r\n\r\n const keys: Array = [\r\n { frame: 0, value: from },\r\n { frame: totalFrame, value: to },\r\n ];\r\n animation.setKeys(keys);\r\n\r\n if (easingFunction !== undefined) {\r\n animation.setEasingFunction(easingFunction);\r\n }\r\n\r\n return animation;\r\n }\r\n\r\n /**\r\n * Sets up an animation\r\n * @param property The property to animate\r\n * @param animationType The animation type to apply\r\n * @param framePerSecond The frames per second of the animation\r\n * @param easingFunction The easing function used in the animation\r\n * @returns The created animation\r\n */\r\n public static CreateAnimation(property: string, animationType: number, framePerSecond: number, easingFunction: EasingFunction): Animation {\r\n const animation: Animation = new Animation(property + \"Animation\", property, framePerSecond, animationType, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n animation.setEasingFunction(easingFunction);\r\n\r\n return animation;\r\n }\r\n\r\n /**\r\n * Create and start an animation on a node\r\n * @param name defines the name of the global animation that will be run on all nodes\r\n * @param target defines the target where the animation will take place\r\n * @param targetProperty defines property to animate\r\n * @param framePerSecond defines the number of frame per second yo use\r\n * @param totalFrame defines the number of frames in total\r\n * @param from defines the initial value\r\n * @param to defines the final value\r\n * @param loopMode defines which loop mode you want to use (off by default)\r\n * @param easingFunction defines the easing function to use (linear by default)\r\n * @param onAnimationEnd defines the callback to call when animation end\r\n * @param scene defines the hosting scene\r\n * @returns the animatable created for this animation\r\n */\r\n public static CreateAndStartAnimation(\r\n name: string,\r\n target: any,\r\n targetProperty: string,\r\n framePerSecond: number,\r\n totalFrame: number,\r\n from: any,\r\n to: any,\r\n loopMode?: number,\r\n easingFunction?: EasingFunction,\r\n onAnimationEnd?: () => void,\r\n scene?: Scene\r\n ): Nullable {\r\n const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);\r\n\r\n if (!animation) {\r\n return null;\r\n }\r\n\r\n if (target.getScene) {\r\n scene = target.getScene();\r\n }\r\n\r\n if (!scene) {\r\n return null;\r\n }\r\n\r\n return scene.beginDirectAnimation(target, [animation], 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Create and start an animation on a node and its descendants\r\n * @param name defines the name of the global animation that will be run on all nodes\r\n * @param node defines the root node where the animation will take place\r\n * @param directDescendantsOnly if true only direct descendants will be used, if false direct and also indirect (children of children, an so on in a recursive manner) descendants will be used\r\n * @param targetProperty defines property to animate\r\n * @param framePerSecond defines the number of frame per second to use\r\n * @param totalFrame defines the number of frames in total\r\n * @param from defines the initial value\r\n * @param to defines the final value\r\n * @param loopMode defines which loop mode you want to use (off by default)\r\n * @param easingFunction defines the easing function to use (linear by default)\r\n * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)\r\n * @returns the list of animatables created for all nodes\r\n * @example https://www.babylonjs-playground.com/#MH0VLI\r\n */\r\n public static CreateAndStartHierarchyAnimation(\r\n name: string,\r\n node: Node,\r\n directDescendantsOnly: boolean,\r\n targetProperty: string,\r\n framePerSecond: number,\r\n totalFrame: number,\r\n from: any,\r\n to: any,\r\n loopMode?: number,\r\n easingFunction?: EasingFunction,\r\n onAnimationEnd?: () => void\r\n ): Nullable {\r\n const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);\r\n\r\n if (!animation) {\r\n return null;\r\n }\r\n\r\n const scene = node.getScene();\r\n return scene.beginDirectHierarchyAnimation(node, directDescendantsOnly, [animation], 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Creates a new animation, merges it with the existing animations and starts it\r\n * @param name Name of the animation\r\n * @param node Node which contains the scene that begins the animations\r\n * @param targetProperty Specifies which property to animate\r\n * @param framePerSecond The frames per second of the animation\r\n * @param totalFrame The total number of frames\r\n * @param from The frame at the beginning of the animation\r\n * @param to The frame at the end of the animation\r\n * @param loopMode Specifies the loop mode of the animation\r\n * @param easingFunction (Optional) The easing function of the animation, which allow custom mathematical formulas for animations\r\n * @param onAnimationEnd Callback to run once the animation is complete\r\n * @returns Nullable animation\r\n */\r\n public static CreateMergeAndStartAnimation(\r\n name: string,\r\n node: Node,\r\n targetProperty: string,\r\n framePerSecond: number,\r\n totalFrame: number,\r\n from: any,\r\n to: any,\r\n loopMode?: number,\r\n easingFunction?: EasingFunction,\r\n onAnimationEnd?: () => void\r\n ): Nullable {\r\n const animation = Animation._PrepareAnimation(name, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);\r\n\r\n if (!animation) {\r\n return null;\r\n }\r\n\r\n node.animations.push(animation);\r\n\r\n return node.getScene().beginAnimation(node, 0, totalFrame, animation.loopMode === 1, 1.0, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Convert the keyframes for all animations belonging to the group to be relative to a given reference frame.\r\n * @param sourceAnimation defines the Animation containing keyframes to convert\r\n * @param referenceFrame defines the frame that keyframes in the range will be relative to\r\n * @param range defines the name of the AnimationRange belonging to the Animation to convert\r\n * @param cloneOriginal defines whether or not to clone the animation and convert the clone or convert the original animation (default is false)\r\n * @param clonedName defines the name of the resulting cloned Animation if cloneOriginal is true\r\n * @returns a new Animation if cloneOriginal is true or the original Animation if cloneOriginal is false\r\n */\r\n public static MakeAnimationAdditive(sourceAnimation: Animation, referenceFrame = 0, range?: string, cloneOriginal = false, clonedName?: string): Animation {\r\n let animation = sourceAnimation;\r\n\r\n if (cloneOriginal) {\r\n animation = sourceAnimation.clone();\r\n animation.name = clonedName || animation.name;\r\n }\r\n\r\n if (!animation._keys.length) {\r\n return animation;\r\n }\r\n\r\n referenceFrame = referenceFrame >= 0 ? referenceFrame : 0;\r\n let startIndex = 0;\r\n const firstKey = animation._keys[0];\r\n let endIndex = animation._keys.length - 1;\r\n const lastKey = animation._keys[endIndex];\r\n const valueStore = {\r\n referenceValue: firstKey.value,\r\n referencePosition: TmpVectors.Vector3[0],\r\n referenceQuaternion: TmpVectors.Quaternion[0],\r\n referenceScaling: TmpVectors.Vector3[1],\r\n keyPosition: TmpVectors.Vector3[2],\r\n keyQuaternion: TmpVectors.Quaternion[1],\r\n keyScaling: TmpVectors.Vector3[3],\r\n };\r\n let referenceFound = false;\r\n let from = firstKey.frame;\r\n let to = lastKey.frame;\r\n if (range) {\r\n const rangeValue = animation.getRange(range);\r\n\r\n if (rangeValue) {\r\n from = rangeValue.from;\r\n to = rangeValue.to;\r\n }\r\n }\r\n let fromKeyFound = firstKey.frame === from;\r\n let toKeyFound = lastKey.frame === to;\r\n\r\n // There's only one key, so use it\r\n if (animation._keys.length === 1) {\r\n const value = animation._getKeyValue(animation._keys[0]);\r\n valueStore.referenceValue = value.clone ? value.clone() : value;\r\n referenceFound = true;\r\n }\r\n\r\n // Reference frame is before the first frame, so just use the first frame\r\n else if (referenceFrame <= firstKey.frame) {\r\n const value = animation._getKeyValue(firstKey.value);\r\n valueStore.referenceValue = value.clone ? value.clone() : value;\r\n referenceFound = true;\r\n }\r\n\r\n // Reference frame is after the last frame, so just use the last frame\r\n else if (referenceFrame >= lastKey.frame) {\r\n const value = animation._getKeyValue(lastKey.value);\r\n valueStore.referenceValue = value.clone ? value.clone() : value;\r\n referenceFound = true;\r\n }\r\n\r\n // Find key bookends, create them if they don't exist\r\n let index = 0;\r\n while (!referenceFound || !fromKeyFound || (!toKeyFound && index < animation._keys.length - 1)) {\r\n const currentKey = animation._keys[index];\r\n const nextKey = animation._keys[index + 1];\r\n\r\n // If reference frame wasn't found yet, check if we can interpolate to it\r\n if (!referenceFound && referenceFrame >= currentKey.frame && referenceFrame <= nextKey.frame) {\r\n let value;\r\n\r\n if (referenceFrame === currentKey.frame) {\r\n value = animation._getKeyValue(currentKey.value);\r\n } else if (referenceFrame === nextKey.frame) {\r\n value = animation._getKeyValue(nextKey.value);\r\n } else {\r\n const animationState = {\r\n key: index,\r\n repeatCount: 0,\r\n loopMode: this.ANIMATIONLOOPMODE_CONSTANT,\r\n };\r\n value = animation._interpolate(referenceFrame, animationState);\r\n }\r\n\r\n valueStore.referenceValue = value.clone ? value.clone() : value;\r\n referenceFound = true;\r\n }\r\n\r\n // If from key wasn't found yet, check if we can interpolate to it\r\n if (!fromKeyFound && from >= currentKey.frame && from <= nextKey.frame) {\r\n if (from === currentKey.frame) {\r\n startIndex = index;\r\n } else if (from === nextKey.frame) {\r\n startIndex = index + 1;\r\n } else {\r\n const animationState = {\r\n key: index,\r\n repeatCount: 0,\r\n loopMode: this.ANIMATIONLOOPMODE_CONSTANT,\r\n };\r\n const value = animation._interpolate(from, animationState);\r\n const key: IAnimationKey = {\r\n frame: from,\r\n value: value.clone ? value.clone() : value,\r\n };\r\n animation._keys.splice(index + 1, 0, key);\r\n startIndex = index + 1;\r\n }\r\n\r\n fromKeyFound = true;\r\n }\r\n\r\n // If to key wasn't found yet, check if we can interpolate to it\r\n if (!toKeyFound && to >= currentKey.frame && to <= nextKey.frame) {\r\n if (to === currentKey.frame) {\r\n endIndex = index;\r\n } else if (to === nextKey.frame) {\r\n endIndex = index + 1;\r\n } else {\r\n const animationState = {\r\n key: index,\r\n repeatCount: 0,\r\n loopMode: this.ANIMATIONLOOPMODE_CONSTANT,\r\n };\r\n const value = animation._interpolate(to, animationState);\r\n const key: IAnimationKey = {\r\n frame: to,\r\n value: value.clone ? value.clone() : value,\r\n };\r\n animation._keys.splice(index + 1, 0, key);\r\n endIndex = index + 1;\r\n }\r\n\r\n toKeyFound = true;\r\n }\r\n\r\n index++;\r\n }\r\n\r\n // Conjugate the quaternion\r\n if (animation.dataType === Animation.ANIMATIONTYPE_QUATERNION) {\r\n valueStore.referenceValue.normalize().conjugateInPlace();\r\n }\r\n\r\n // Decompose matrix and conjugate the quaternion\r\n else if (animation.dataType === Animation.ANIMATIONTYPE_MATRIX) {\r\n valueStore.referenceValue.decompose(valueStore.referenceScaling, valueStore.referenceQuaternion, valueStore.referencePosition);\r\n valueStore.referenceQuaternion.normalize().conjugateInPlace();\r\n }\r\n\r\n // Subtract the reference value from all of the key values\r\n for (index = startIndex; index <= endIndex; index++) {\r\n const key = animation._keys[index];\r\n\r\n // If this key was duplicated to create a frame 0 key, skip it because its value has already been updated\r\n if (index && animation.dataType !== Animation.ANIMATIONTYPE_FLOAT && key.value === firstKey.value) {\r\n continue;\r\n }\r\n\r\n switch (animation.dataType) {\r\n case Animation.ANIMATIONTYPE_MATRIX:\r\n key.value.decompose(valueStore.keyScaling, valueStore.keyQuaternion, valueStore.keyPosition);\r\n valueStore.keyPosition.subtractInPlace(valueStore.referencePosition);\r\n valueStore.keyScaling.divideInPlace(valueStore.referenceScaling);\r\n valueStore.referenceQuaternion.multiplyToRef(valueStore.keyQuaternion, valueStore.keyQuaternion);\r\n Matrix.ComposeToRef(valueStore.keyScaling, valueStore.keyQuaternion, valueStore.keyPosition, key.value);\r\n break;\r\n\r\n case Animation.ANIMATIONTYPE_QUATERNION:\r\n valueStore.referenceValue.multiplyToRef(key.value, key.value);\r\n break;\r\n\r\n case Animation.ANIMATIONTYPE_VECTOR2:\r\n case Animation.ANIMATIONTYPE_VECTOR3:\r\n case Animation.ANIMATIONTYPE_COLOR3:\r\n case Animation.ANIMATIONTYPE_COLOR4:\r\n key.value.subtractToRef(valueStore.referenceValue, key.value);\r\n break;\r\n\r\n case Animation.ANIMATIONTYPE_SIZE:\r\n key.value.width -= valueStore.referenceValue.width;\r\n key.value.height -= valueStore.referenceValue.height;\r\n break;\r\n\r\n default:\r\n key.value -= valueStore.referenceValue;\r\n }\r\n }\r\n\r\n return animation;\r\n }\r\n\r\n /**\r\n * Transition property of an host to the target Value\r\n * @param property The property to transition\r\n * @param targetValue The target Value of the property\r\n * @param host The object where the property to animate belongs\r\n * @param scene Scene used to run the animation\r\n * @param frameRate Framerate (in frame/s) to use\r\n * @param transition The transition type we want to use\r\n * @param duration The duration of the animation, in milliseconds\r\n * @param onAnimationEnd Callback trigger at the end of the animation\r\n * @returns Nullable animation\r\n */\r\n public static TransitionTo(\r\n property: string,\r\n targetValue: any,\r\n host: any,\r\n scene: Scene,\r\n frameRate: number,\r\n transition: Animation,\r\n duration: number,\r\n onAnimationEnd: Nullable<() => void> = null\r\n ): Nullable {\r\n if (duration <= 0) {\r\n host[property] = targetValue;\r\n if (onAnimationEnd) {\r\n onAnimationEnd();\r\n }\r\n return null;\r\n }\r\n\r\n const endFrame: number = frameRate * (duration / 1000);\r\n\r\n transition.setKeys([\r\n {\r\n frame: 0,\r\n value: host[property].clone ? host[property].clone() : host[property],\r\n },\r\n {\r\n frame: endFrame,\r\n value: targetValue,\r\n },\r\n ]);\r\n\r\n if (!host.animations) {\r\n host.animations = [];\r\n }\r\n\r\n host.animations.push(transition);\r\n\r\n const animation: Animatable = scene.beginAnimation(host, 0, endFrame, false);\r\n animation.onAnimationEnd = onAnimationEnd;\r\n return animation;\r\n }\r\n\r\n /**\r\n * Return the array of runtime animations currently using this animation\r\n */\r\n public get runtimeAnimations(): RuntimeAnimation[] {\r\n return this._runtimeAnimations;\r\n }\r\n\r\n /**\r\n * Specifies if any of the runtime animations are currently running\r\n */\r\n public get hasRunningRuntimeAnimations(): boolean {\r\n for (const runtimeAnimation of this._runtimeAnimations) {\r\n if (!runtimeAnimation.isStopped()) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Initializes the animation\r\n * @param name Name of the animation\r\n * @param targetProperty Property to animate\r\n * @param framePerSecond The frames per second of the animation\r\n * @param dataType The data type of the animation\r\n * @param loopMode The loop mode of the animation\r\n * @param enableBlending Specifies if blending should be enabled\r\n */\r\n constructor(\r\n /**Name of the animation */\r\n public name: string,\r\n /**Property to animate */\r\n public targetProperty: string,\r\n /**The frames per second of the animation */\r\n public framePerSecond: number,\r\n /**The data type of the animation */\r\n public dataType: number,\r\n /**The loop mode of the animation */\r\n public loopMode?: number,\r\n /**Specifies if blending should be enabled */\r\n public enableBlending?: boolean\r\n ) {\r\n this.targetPropertyPath = targetProperty.split(\".\");\r\n this.dataType = dataType;\r\n this.loopMode = loopMode === undefined ? Animation.ANIMATIONLOOPMODE_CYCLE : loopMode;\r\n this.uniqueId = Animation._UniqueIdGenerator++;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Converts the animation to a string\r\n * @param fullDetails support for multiple levels of logging within scene loading\r\n * @returns String form of the animation\r\n */\r\n public toString(fullDetails?: boolean): string {\r\n let ret = \"Name: \" + this.name + \", property: \" + this.targetProperty;\r\n ret += \", datatype: \" + [\"Float\", \"Vector3\", \"Quaternion\", \"Matrix\", \"Color3\", \"Vector2\"][this.dataType];\r\n ret += \", nKeys: \" + (this._keys ? this._keys.length : \"none\");\r\n ret += \", nRanges: \" + (this._ranges ? Object.keys(this._ranges).length : \"none\");\r\n if (fullDetails) {\r\n ret += \", Ranges: {\";\r\n let first = true;\r\n for (const name in this._ranges) {\r\n if (first) {\r\n ret += \", \";\r\n first = false;\r\n }\r\n ret += name;\r\n }\r\n ret += \"}\";\r\n }\r\n return ret;\r\n }\r\n\r\n /**\r\n * Add an event to this animation\r\n * @param event Event to add\r\n */\r\n public addEvent(event: AnimationEvent): void {\r\n this._events.push(event);\r\n this._events.sort((a, b) => a.frame - b.frame);\r\n }\r\n\r\n /**\r\n * Remove all events found at the given frame\r\n * @param frame The frame to remove events from\r\n */\r\n public removeEvents(frame: number): void {\r\n for (let index = 0; index < this._events.length; index++) {\r\n if (this._events[index].frame === frame) {\r\n this._events.splice(index, 1);\r\n index--;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves all the events from the animation\r\n * @returns Events from the animation\r\n */\r\n public getEvents(): AnimationEvent[] {\r\n return this._events;\r\n }\r\n\r\n /**\r\n * Creates an animation range\r\n * @param name Name of the animation range\r\n * @param from Starting frame of the animation range\r\n * @param to Ending frame of the animation\r\n */\r\n public createRange(name: string, from: number, to: number): void {\r\n // check name not already in use; could happen for bones after serialized\r\n if (!this._ranges[name]) {\r\n this._ranges[name] = new AnimationRange(name, from, to);\r\n }\r\n }\r\n\r\n /**\r\n * Deletes an animation range by name\r\n * @param name Name of the animation range to delete\r\n * @param deleteFrames Specifies if the key frames for the range should also be deleted (true) or not (false)\r\n */\r\n public deleteRange(name: string, deleteFrames = true): void {\r\n const range = this._ranges[name];\r\n if (!range) {\r\n return;\r\n }\r\n if (deleteFrames) {\r\n const from = range.from;\r\n const to = range.to;\r\n\r\n // this loop MUST go high to low for multiple splices to work\r\n for (let key = this._keys.length - 1; key >= 0; key--) {\r\n if (this._keys[key].frame >= from && this._keys[key].frame <= to) {\r\n this._keys.splice(key, 1);\r\n }\r\n }\r\n }\r\n this._ranges[name] = null; // said much faster than 'delete this._range[name]'\r\n }\r\n\r\n /**\r\n * Gets the animation range by name, or null if not defined\r\n * @param name Name of the animation range\r\n * @returns Nullable animation range\r\n */\r\n public getRange(name: string): Nullable {\r\n return this._ranges[name];\r\n }\r\n\r\n /**\r\n * Gets the key frames from the animation\r\n * @returns The key frames of the animation\r\n */\r\n public getKeys(): Array {\r\n return this._keys;\r\n }\r\n\r\n /**\r\n * Gets the highest frame rate of the animation\r\n * @returns Highest frame rate of the animation\r\n */\r\n public getHighestFrame(): number {\r\n let ret = 0;\r\n\r\n for (let key = 0, nKeys = this._keys.length; key < nKeys; key++) {\r\n if (ret < this._keys[key].frame) {\r\n ret = this._keys[key].frame;\r\n }\r\n }\r\n return ret;\r\n }\r\n\r\n /**\r\n * Gets the easing function of the animation\r\n * @returns Easing function of the animation\r\n */\r\n public getEasingFunction(): Nullable {\r\n return this._easingFunction;\r\n }\r\n\r\n /**\r\n * Sets the easing function of the animation\r\n * @param easingFunction A custom mathematical formula for animation\r\n */\r\n public setEasingFunction(easingFunction: Nullable): void {\r\n this._easingFunction = easingFunction;\r\n }\r\n\r\n /**\r\n * Interpolates a scalar linearly\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated scalar value\r\n */\r\n public floatInterpolateFunction(startValue: number, endValue: number, gradient: number): number {\r\n return Scalar.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a scalar cubically\r\n * @param startValue Start value of the animation curve\r\n * @param outTangent End tangent of the animation\r\n * @param endValue End value of the animation curve\r\n * @param inTangent Start tangent of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated scalar value\r\n */\r\n public floatInterpolateFunctionWithTangents(startValue: number, outTangent: number, endValue: number, inTangent: number, gradient: number): number {\r\n return Scalar.Hermite(startValue, outTangent, endValue, inTangent, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a quaternion using a spherical linear interpolation\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated quaternion value\r\n */\r\n public quaternionInterpolateFunction(startValue: Quaternion, endValue: Quaternion, gradient: number): Quaternion {\r\n return Quaternion.Slerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a quaternion cubically\r\n * @param startValue Start value of the animation curve\r\n * @param outTangent End tangent of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param inTangent Start tangent of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated quaternion value\r\n */\r\n public quaternionInterpolateFunctionWithTangents(startValue: Quaternion, outTangent: Quaternion, endValue: Quaternion, inTangent: Quaternion, gradient: number): Quaternion {\r\n return Quaternion.Hermite(startValue, outTangent, endValue, inTangent, gradient).normalize();\r\n }\r\n\r\n /**\r\n * Interpolates a Vector3 linearly\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\r\n * @returns Interpolated scalar value\r\n */\r\n public vector3InterpolateFunction(startValue: Vector3, endValue: Vector3, gradient: number): Vector3 {\r\n return Vector3.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Vector3 cubically\r\n * @param startValue Start value of the animation curve\r\n * @param outTangent End tangent of the animation\r\n * @param endValue End value of the animation curve\r\n * @param inTangent Start tangent of the animation curve\r\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\r\n * @returns InterpolatedVector3 value\r\n */\r\n public vector3InterpolateFunctionWithTangents(startValue: Vector3, outTangent: Vector3, endValue: Vector3, inTangent: Vector3, gradient: number): Vector3 {\r\n return Vector3.Hermite(startValue, outTangent, endValue, inTangent, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Vector2 linearly\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\r\n * @returns Interpolated Vector2 value\r\n */\r\n public vector2InterpolateFunction(startValue: Vector2, endValue: Vector2, gradient: number): Vector2 {\r\n return Vector2.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Vector2 cubically\r\n * @param startValue Start value of the animation curve\r\n * @param outTangent End tangent of the animation\r\n * @param endValue End value of the animation curve\r\n * @param inTangent Start tangent of the animation curve\r\n * @param gradient Scalar amount to interpolate (value between 0 and 1)\r\n * @returns Interpolated Vector2 value\r\n */\r\n public vector2InterpolateFunctionWithTangents(startValue: Vector2, outTangent: Vector2, endValue: Vector2, inTangent: Vector2, gradient: number): Vector2 {\r\n return Vector2.Hermite(startValue, outTangent, endValue, inTangent, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a size linearly\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated Size value\r\n */\r\n public sizeInterpolateFunction(startValue: Size, endValue: Size, gradient: number): Size {\r\n return Size.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Color3 linearly\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated Color3 value\r\n */\r\n public color3InterpolateFunction(startValue: Color3, endValue: Color3, gradient: number): Color3 {\r\n return Color3.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Color3 cubically\r\n * @param startValue Start value of the animation curve\r\n * @param outTangent End tangent of the animation\r\n * @param endValue End value of the animation curve\r\n * @param inTangent Start tangent of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns interpolated value\r\n */\r\n public color3InterpolateFunctionWithTangents(startValue: Color3, outTangent: Color3, endValue: Color3, inTangent: Color3, gradient: number): Color3 {\r\n return Color3.Hermite(startValue, outTangent, endValue, inTangent, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Color4 linearly\r\n * @param startValue Start value of the animation curve\r\n * @param endValue End value of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns Interpolated Color3 value\r\n */\r\n public color4InterpolateFunction(startValue: Color4, endValue: Color4, gradient: number): Color4 {\r\n return Color4.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Interpolates a Color4 cubically\r\n * @param startValue Start value of the animation curve\r\n * @param outTangent End tangent of the animation\r\n * @param endValue End value of the animation curve\r\n * @param inTangent Start tangent of the animation curve\r\n * @param gradient Scalar amount to interpolate\r\n * @returns interpolated value\r\n */\r\n public color4InterpolateFunctionWithTangents(startValue: Color4, outTangent: Color4, endValue: Color4, inTangent: Color4, gradient: number): Color4 {\r\n return Color4.Hermite(startValue, outTangent, endValue, inTangent, gradient);\r\n }\r\n\r\n /**\r\n * @internal Internal use only\r\n */\r\n public _getKeyValue(value: any): any {\r\n if (typeof value === \"function\") {\r\n return value();\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /**\r\n * Evaluate the animation value at a given frame\r\n * @param currentFrame defines the frame where we want to evaluate the animation\r\n * @returns the animation value\r\n */\r\n public evaluate(currentFrame: number) {\r\n return this._interpolate(currentFrame, {\r\n key: 0,\r\n repeatCount: 0,\r\n loopMode: Animation.ANIMATIONLOOPMODE_CONSTANT,\r\n });\r\n }\r\n\r\n /**\r\n * @internal Internal use only\r\n */\r\n public _interpolate(currentFrame: number, state: _IAnimationState): any {\r\n if (state.loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && state.repeatCount > 0) {\r\n return state.highLimitValue.clone ? state.highLimitValue.clone() : state.highLimitValue;\r\n }\r\n\r\n const keys = this._keys;\r\n const keysLength = keys.length;\r\n\r\n let key = state.key;\r\n\r\n while (key >= 0 && currentFrame < keys[key].frame) {\r\n --key;\r\n }\r\n\r\n while (key + 1 <= keysLength - 1 && currentFrame >= keys[key + 1].frame) {\r\n ++key;\r\n }\r\n\r\n state.key = key;\r\n\r\n if (key < 0) {\r\n return this._getKeyValue(keys[0].value);\r\n } else if (key + 1 > keysLength - 1) {\r\n return this._getKeyValue(keys[keysLength - 1].value);\r\n }\r\n\r\n const startKey = keys[key];\r\n const endKey = keys[key + 1];\r\n const startValue = this._getKeyValue(startKey.value);\r\n const endValue = this._getKeyValue(endKey.value);\r\n if (startKey.interpolation === AnimationKeyInterpolation.STEP) {\r\n if (endKey.frame > currentFrame) {\r\n return startValue;\r\n } else {\r\n return endValue;\r\n }\r\n }\r\n\r\n const useTangent = startKey.outTangent !== undefined && endKey.inTangent !== undefined;\r\n const frameDelta = endKey.frame - startKey.frame;\r\n\r\n // gradient : percent of currentFrame between the frame inf and the frame sup\r\n let gradient = (currentFrame - startKey.frame) / frameDelta;\r\n\r\n // check for easingFunction and correction of gradient\r\n const easingFunction = this.getEasingFunction();\r\n if (easingFunction !== null) {\r\n gradient = easingFunction.ease(gradient);\r\n }\r\n\r\n switch (this.dataType) {\r\n // Float\r\n case Animation.ANIMATIONTYPE_FLOAT: {\r\n const floatValue = useTangent\r\n ? this.floatInterpolateFunctionWithTangents(startValue, startKey.outTangent * frameDelta, endValue, endKey.inTangent * frameDelta, gradient)\r\n : this.floatInterpolateFunction(startValue, endValue, gradient);\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return floatValue;\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return state.offsetValue * state.repeatCount + floatValue;\r\n }\r\n break;\r\n }\r\n // Quaternion\r\n case Animation.ANIMATIONTYPE_QUATERNION: {\r\n const quatValue = useTangent\r\n ? this.quaternionInterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\r\n : this.quaternionInterpolateFunction(startValue, endValue, gradient);\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return quatValue;\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return quatValue.addInPlace(state.offsetValue.scale(state.repeatCount));\r\n }\r\n\r\n return quatValue;\r\n }\r\n // Vector3\r\n case Animation.ANIMATIONTYPE_VECTOR3: {\r\n const vec3Value = useTangent\r\n ? this.vector3InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\r\n : this.vector3InterpolateFunction(startValue, endValue, gradient);\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return vec3Value;\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return vec3Value.add(state.offsetValue.scale(state.repeatCount));\r\n }\r\n break;\r\n }\r\n // Vector2\r\n case Animation.ANIMATIONTYPE_VECTOR2: {\r\n const vec2Value = useTangent\r\n ? this.vector2InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\r\n : this.vector2InterpolateFunction(startValue, endValue, gradient);\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return vec2Value;\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return vec2Value.add(state.offsetValue.scale(state.repeatCount));\r\n }\r\n break;\r\n }\r\n // Size\r\n case Animation.ANIMATIONTYPE_SIZE: {\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return this.sizeInterpolateFunction(startValue, endValue, gradient);\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return this.sizeInterpolateFunction(startValue, endValue, gradient).add(state.offsetValue.scale(state.repeatCount));\r\n }\r\n break;\r\n }\r\n // Color3\r\n case Animation.ANIMATIONTYPE_COLOR3: {\r\n const color3Value = useTangent\r\n ? this.color3InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\r\n : this.color3InterpolateFunction(startValue, endValue, gradient);\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return color3Value;\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return color3Value.add(state.offsetValue.scale(state.repeatCount));\r\n }\r\n break;\r\n }\r\n // Color4\r\n case Animation.ANIMATIONTYPE_COLOR4: {\r\n const color4Value = useTangent\r\n ? this.color4InterpolateFunctionWithTangents(startValue, startKey.outTangent.scale(frameDelta), endValue, endKey.inTangent.scale(frameDelta), gradient)\r\n : this.color4InterpolateFunction(startValue, endValue, gradient);\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO:\r\n return color4Value;\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE:\r\n return color4Value.add(state.offsetValue.scale(state.repeatCount));\r\n }\r\n break;\r\n }\r\n // Matrix\r\n case Animation.ANIMATIONTYPE_MATRIX: {\r\n switch (state.loopMode) {\r\n case Animation.ANIMATIONLOOPMODE_CYCLE:\r\n case Animation.ANIMATIONLOOPMODE_CONSTANT:\r\n case Animation.ANIMATIONLOOPMODE_YOYO: {\r\n if (Animation.AllowMatricesInterpolation) {\r\n return this.matrixInterpolateFunction(startValue, endValue, gradient, state.workValue);\r\n }\r\n return startValue;\r\n }\r\n case Animation.ANIMATIONLOOPMODE_RELATIVE: {\r\n return startValue;\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n /**\r\n * Defines the function to use to interpolate matrices\r\n * @param startValue defines the start matrix\r\n * @param endValue defines the end matrix\r\n * @param gradient defines the gradient between both matrices\r\n * @param result defines an optional target matrix where to store the interpolation\r\n * @returns the interpolated matrix\r\n */\r\n public matrixInterpolateFunction(startValue: Matrix, endValue: Matrix, gradient: number, result?: Matrix): Matrix {\r\n if (Animation.AllowMatrixDecomposeForInterpolation) {\r\n if (result) {\r\n Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);\r\n return result;\r\n }\r\n return Matrix.DecomposeLerp(startValue, endValue, gradient);\r\n }\r\n\r\n if (result) {\r\n Matrix.LerpToRef(startValue, endValue, gradient, result);\r\n return result;\r\n }\r\n return Matrix.Lerp(startValue, endValue, gradient);\r\n }\r\n\r\n /**\r\n * Makes a copy of the animation\r\n * @returns Cloned animation\r\n */\r\n public clone(): Animation {\r\n const clone = new Animation(this.name, this.targetPropertyPath.join(\".\"), this.framePerSecond, this.dataType, this.loopMode);\r\n\r\n clone.enableBlending = this.enableBlending;\r\n clone.blendingSpeed = this.blendingSpeed;\r\n\r\n if (this._keys) {\r\n clone.setKeys(this._keys);\r\n }\r\n\r\n if (this._ranges) {\r\n clone._ranges = {};\r\n for (const name in this._ranges) {\r\n const range = this._ranges[name];\r\n if (!range) {\r\n continue;\r\n }\r\n clone._ranges[name] = range.clone();\r\n }\r\n }\r\n\r\n return clone;\r\n }\r\n\r\n /**\r\n * Sets the key frames of the animation\r\n * @param values The animation key frames to set\r\n */\r\n public setKeys(values: Array): void {\r\n this._keys = values.slice(0);\r\n }\r\n\r\n /**\r\n * Serializes the animation to an object\r\n * @returns Serialized object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.name = this.name;\r\n serializationObject.property = this.targetProperty;\r\n serializationObject.framePerSecond = this.framePerSecond;\r\n serializationObject.dataType = this.dataType;\r\n serializationObject.loopBehavior = this.loopMode;\r\n serializationObject.enableBlending = this.enableBlending;\r\n serializationObject.blendingSpeed = this.blendingSpeed;\r\n\r\n const dataType = this.dataType;\r\n serializationObject.keys = [];\r\n const keys = this.getKeys();\r\n for (let index = 0; index < keys.length; index++) {\r\n const animationKey = keys[index];\r\n\r\n const key: any = {};\r\n key.frame = animationKey.frame;\r\n\r\n switch (dataType) {\r\n case Animation.ANIMATIONTYPE_FLOAT:\r\n key.values = [animationKey.value];\r\n if (animationKey.inTangent !== undefined) {\r\n key.values.push(animationKey.inTangent);\r\n }\r\n if (animationKey.outTangent !== undefined) {\r\n if (animationKey.inTangent === undefined) {\r\n key.values.push(undefined);\r\n }\r\n key.values.push(animationKey.outTangent);\r\n }\r\n if (animationKey.interpolation !== undefined) {\r\n if (animationKey.inTangent === undefined) {\r\n key.values.push(undefined);\r\n }\r\n if (animationKey.outTangent === undefined) {\r\n key.values.push(undefined);\r\n }\r\n key.values.push(animationKey.interpolation);\r\n }\r\n break;\r\n case Animation.ANIMATIONTYPE_QUATERNION:\r\n case Animation.ANIMATIONTYPE_MATRIX:\r\n case Animation.ANIMATIONTYPE_VECTOR3:\r\n case Animation.ANIMATIONTYPE_COLOR3:\r\n case Animation.ANIMATIONTYPE_COLOR4:\r\n key.values = animationKey.value.asArray();\r\n if (animationKey.inTangent != undefined) {\r\n key.values.push(animationKey.inTangent.asArray());\r\n }\r\n if (animationKey.outTangent != undefined) {\r\n if (animationKey.inTangent === undefined) {\r\n key.values.push(undefined);\r\n }\r\n key.values.push(animationKey.outTangent.asArray());\r\n }\r\n if (animationKey.interpolation !== undefined) {\r\n if (animationKey.inTangent === undefined) {\r\n key.values.push(undefined);\r\n }\r\n if (animationKey.outTangent === undefined) {\r\n key.values.push(undefined);\r\n }\r\n key.values.push(animationKey.interpolation);\r\n }\r\n break;\r\n }\r\n\r\n serializationObject.keys.push(key);\r\n }\r\n\r\n serializationObject.ranges = [];\r\n for (const name in this._ranges) {\r\n const source = this._ranges[name];\r\n\r\n if (!source) {\r\n continue;\r\n }\r\n const range: any = {};\r\n range.name = name;\r\n range.from = source.from;\r\n range.to = source.to;\r\n serializationObject.ranges.push(range);\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Float animation type\r\n */\r\n public static readonly ANIMATIONTYPE_FLOAT = 0;\r\n /**\r\n * Vector3 animation type\r\n */\r\n public static readonly ANIMATIONTYPE_VECTOR3 = 1;\r\n /**\r\n * Quaternion animation type\r\n */\r\n public static readonly ANIMATIONTYPE_QUATERNION = 2;\r\n /**\r\n * Matrix animation type\r\n */\r\n public static readonly ANIMATIONTYPE_MATRIX = 3;\r\n /**\r\n * Color3 animation type\r\n */\r\n public static readonly ANIMATIONTYPE_COLOR3 = 4;\r\n /**\r\n * Color3 animation type\r\n */\r\n public static readonly ANIMATIONTYPE_COLOR4 = 7;\r\n /**\r\n * Vector2 animation type\r\n */\r\n public static readonly ANIMATIONTYPE_VECTOR2 = 5;\r\n /**\r\n * Size animation type\r\n */\r\n public static readonly ANIMATIONTYPE_SIZE = 6;\r\n /**\r\n * Relative Loop Mode\r\n */\r\n public static readonly ANIMATIONLOOPMODE_RELATIVE = 0;\r\n /**\r\n * Cycle Loop Mode\r\n */\r\n public static readonly ANIMATIONLOOPMODE_CYCLE = 1;\r\n /**\r\n * Constant Loop Mode\r\n */\r\n public static readonly ANIMATIONLOOPMODE_CONSTANT = 2;\r\n /**\r\n * Yoyo Loop Mode\r\n */\r\n public static readonly ANIMATIONLOOPMODE_YOYO = 4;\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _UniversalLerp(left: any, right: any, amount: number): any {\r\n const constructor = left.constructor;\r\n if (constructor.Lerp) {\r\n // Lerp supported\r\n return constructor.Lerp(left, right, amount);\r\n } else if (constructor.Slerp) {\r\n // Slerp supported\r\n return constructor.Slerp(left, right, amount);\r\n } else if (left.toFixed) {\r\n // Number\r\n return left * (1.0 - amount) + amount * right;\r\n } else {\r\n // Blending not supported\r\n return right;\r\n }\r\n }\r\n\r\n /**\r\n * Parses an animation object and creates an animation\r\n * @param parsedAnimation Parsed animation object\r\n * @returns Animation object\r\n */\r\n public static Parse(parsedAnimation: any): Animation {\r\n const animation = new Animation(parsedAnimation.name, parsedAnimation.property, parsedAnimation.framePerSecond, parsedAnimation.dataType, parsedAnimation.loopBehavior);\r\n\r\n const dataType = parsedAnimation.dataType;\r\n const keys: Array = [];\r\n let data;\r\n let index: number;\r\n\r\n if (parsedAnimation.enableBlending) {\r\n animation.enableBlending = parsedAnimation.enableBlending;\r\n }\r\n\r\n if (parsedAnimation.blendingSpeed) {\r\n animation.blendingSpeed = parsedAnimation.blendingSpeed;\r\n }\r\n\r\n for (index = 0; index < parsedAnimation.keys.length; index++) {\r\n const key = parsedAnimation.keys[index];\r\n let inTangent: any = undefined;\r\n let outTangent: any = undefined;\r\n let interpolation: any = undefined;\r\n\r\n switch (dataType) {\r\n case Animation.ANIMATIONTYPE_FLOAT:\r\n data = key.values[0];\r\n if (key.values.length >= 2) {\r\n inTangent = key.values[1];\r\n }\r\n if (key.values.length >= 3) {\r\n outTangent = key.values[2];\r\n }\r\n if (key.values.length >= 4) {\r\n interpolation = key.values[3];\r\n }\r\n break;\r\n case Animation.ANIMATIONTYPE_QUATERNION:\r\n data = Quaternion.FromArray(key.values);\r\n if (key.values.length >= 8) {\r\n const _inTangent = Quaternion.FromArray(key.values.slice(4, 8));\r\n if (!_inTangent.equals(Quaternion.Zero())) {\r\n inTangent = _inTangent;\r\n }\r\n }\r\n if (key.values.length >= 12) {\r\n const _outTangent = Quaternion.FromArray(key.values.slice(8, 12));\r\n if (!_outTangent.equals(Quaternion.Zero())) {\r\n outTangent = _outTangent;\r\n }\r\n }\r\n if (key.values.length >= 13) {\r\n interpolation = key.values[12];\r\n }\r\n break;\r\n case Animation.ANIMATIONTYPE_MATRIX:\r\n data = Matrix.FromArray(key.values);\r\n if (key.values.length >= 17) {\r\n interpolation = key.values[16];\r\n }\r\n break;\r\n case Animation.ANIMATIONTYPE_COLOR3:\r\n data = Color3.FromArray(key.values);\r\n if (key.values[3]) {\r\n inTangent = Color3.FromArray(key.values[3]);\r\n }\r\n if (key.values[4]) {\r\n outTangent = Color3.FromArray(key.values[4]);\r\n }\r\n if (key.values[5]) {\r\n interpolation = key.values[5];\r\n }\r\n break;\r\n case Animation.ANIMATIONTYPE_COLOR4:\r\n data = Color4.FromArray(key.values);\r\n if (key.values[4]) {\r\n inTangent = Color4.FromArray(key.values[4]);\r\n }\r\n if (key.values[5]) {\r\n outTangent = Color4.FromArray(key.values[5]);\r\n }\r\n if (key.values[6]) {\r\n interpolation = Color4.FromArray(key.values[6]);\r\n }\r\n break;\r\n case Animation.ANIMATIONTYPE_VECTOR3:\r\n default:\r\n data = Vector3.FromArray(key.values);\r\n if (key.values[3]) {\r\n inTangent = Vector3.FromArray(key.values[3]);\r\n }\r\n if (key.values[4]) {\r\n outTangent = Vector3.FromArray(key.values[4]);\r\n }\r\n if (key.values[5]) {\r\n interpolation = key.values[5];\r\n }\r\n break;\r\n }\r\n\r\n const keyData: any = {};\r\n keyData.frame = key.frame;\r\n keyData.value = data;\r\n\r\n if (inTangent != undefined) {\r\n keyData.inTangent = inTangent;\r\n }\r\n if (outTangent != undefined) {\r\n keyData.outTangent = outTangent;\r\n }\r\n if (interpolation != undefined) {\r\n keyData.interpolation = interpolation;\r\n }\r\n keys.push(keyData);\r\n }\r\n\r\n animation.setKeys(keys);\r\n\r\n if (parsedAnimation.ranges) {\r\n for (index = 0; index < parsedAnimation.ranges.length; index++) {\r\n data = parsedAnimation.ranges[index];\r\n animation.createRange(data.name, data.from, data.to);\r\n }\r\n }\r\n\r\n return animation;\r\n }\r\n\r\n /**\r\n * Appends the serialized animations from the source animations\r\n * @param source Source containing the animations\r\n * @param destination Target to store the animations\r\n */\r\n public static AppendSerializedAnimations(source: IAnimatable, destination: any): void {\r\n SerializationHelper.AppendSerializedAnimations(source, destination);\r\n }\r\n\r\n /**\r\n * Creates a new animation or an array of animations from a snippet saved in a remote file\r\n * @param name defines the name of the animation to create (can be null or empty to use the one from the json data)\r\n * @param url defines the url to load from\r\n * @returns a promise that will resolve to the new animation or an array of animations\r\n */\r\n public static ParseFromFileAsync(name: Nullable, url: string): Promise> {\r\n return new Promise((resolve, reject) => {\r\n const request = new WebRequest();\r\n request.addEventListener(\"readystatechange\", () => {\r\n if (request.readyState == 4) {\r\n if (request.status == 200) {\r\n let serializationObject = JSON.parse(request.responseText);\r\n if (serializationObject.animations) {\r\n serializationObject = serializationObject.animations;\r\n }\r\n\r\n if (serializationObject.length) {\r\n const output = new Array();\r\n for (const serializedAnimation of serializationObject) {\r\n output.push(this.Parse(serializedAnimation));\r\n }\r\n\r\n resolve(output);\r\n } else {\r\n const output = this.Parse(serializationObject);\r\n\r\n if (name) {\r\n output.name = name;\r\n }\r\n\r\n resolve(output);\r\n }\r\n } else {\r\n reject(\"Unable to load the animation\");\r\n }\r\n }\r\n });\r\n\r\n request.open(\"GET\", url);\r\n request.send();\r\n });\r\n }\r\n\r\n /**\r\n * Creates an animation or an array of animations from a snippet saved by the Inspector\r\n * @param snippetId defines the snippet to load\r\n * @returns a promise that will resolve to the new animation or a new array of animations\r\n */\r\n public static ParseFromSnippetAsync(snippetId: string): Promise> {\r\n return new Promise((resolve, reject) => {\r\n const request = new WebRequest();\r\n request.addEventListener(\"readystatechange\", () => {\r\n if (request.readyState == 4) {\r\n if (request.status == 200) {\r\n const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);\r\n\r\n if (snippet.animations) {\r\n const serializationObject = JSON.parse(snippet.animations);\r\n const outputs = new Array();\r\n for (const serializedAnimation of serializationObject.animations) {\r\n const output = this.Parse(serializedAnimation);\r\n output.snippetId = snippetId;\r\n outputs.push(output);\r\n }\r\n\r\n resolve(outputs);\r\n } else {\r\n const serializationObject = JSON.parse(snippet.animation);\r\n const output = this.Parse(serializationObject);\r\n\r\n output.snippetId = snippetId;\r\n\r\n resolve(output);\r\n }\r\n } else {\r\n reject(\"Unable to load the snippet \" + snippetId);\r\n }\r\n }\r\n });\r\n\r\n request.open(\"GET\", this.SnippetUrl + \"/\" + snippetId.replace(/#/g, \"/\"));\r\n request.send();\r\n });\r\n }\r\n\r\n /**\r\n * Creates an animation or an array of animations from a snippet saved by the Inspector\r\n * @deprecated Please use ParseFromSnippetAsync instead\r\n * @param snippetId defines the snippet to load\r\n * @returns a promise that will resolve to the new animation or a new array of animations\r\n */\r\n public static CreateFromSnippetAsync = Animation.ParseFromSnippetAsync;\r\n}\r\n\r\nRegisterClass(\"BABYLON.Animation\", Animation);\r\nNode._AnimationRangeFactory = (name: string, from: number, to: number) => new AnimationRange(name, from, to);\r\n","import type { Behavior } from \"../../Behaviors/behavior\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport { BackEase, EasingFunction } from \"../../Animations/easing\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Animatable } from \"../../Animations/animatable\";\r\nimport { Animation } from \"../../Animations/animation\";\r\n\r\n/**\r\n * Add a bouncing effect to an ArcRotateCamera when reaching a specified minimum and maximum radius\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior\r\n */\r\nexport class BouncingBehavior implements Behavior {\r\n /**\r\n * Gets the name of the behavior.\r\n */\r\n public get name(): string {\r\n return \"Bouncing\";\r\n }\r\n\r\n /**\r\n * The easing function used by animations\r\n */\r\n public static EasingFunction = new BackEase(0.3);\r\n\r\n /**\r\n * The easing mode used by animations\r\n */\r\n public static EasingMode = EasingFunction.EASINGMODE_EASEOUT;\r\n\r\n /**\r\n * The duration of the animation, in milliseconds\r\n */\r\n public transitionDuration = 450;\r\n\r\n /**\r\n * Length of the distance animated by the transition when lower radius is reached\r\n */\r\n public lowerRadiusTransitionRange = 2;\r\n\r\n /**\r\n * Length of the distance animated by the transition when upper radius is reached\r\n */\r\n public upperRadiusTransitionRange = -2;\r\n\r\n private _autoTransitionRange = false;\r\n\r\n /**\r\n * Gets a value indicating if the lowerRadiusTransitionRange and upperRadiusTransitionRange are defined automatically\r\n */\r\n public get autoTransitionRange(): boolean {\r\n return this._autoTransitionRange;\r\n }\r\n\r\n /**\r\n * Sets a value indicating if the lowerRadiusTransitionRange and upperRadiusTransitionRange are defined automatically\r\n * Transition ranges will be set to 5% of the bounding box diagonal in world space\r\n */\r\n public set autoTransitionRange(value: boolean) {\r\n if (this._autoTransitionRange === value) {\r\n return;\r\n }\r\n\r\n this._autoTransitionRange = value;\r\n\r\n const camera = this._attachedCamera;\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n if (value) {\r\n this._onMeshTargetChangedObserver = camera.onMeshTargetChangedObservable.add((mesh) => {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n mesh.computeWorldMatrix(true);\r\n const diagonal = mesh.getBoundingInfo().diagonalLength;\r\n\r\n this.lowerRadiusTransitionRange = diagonal * 0.05;\r\n this.upperRadiusTransitionRange = diagonal * 0.05;\r\n });\r\n } else if (this._onMeshTargetChangedObserver) {\r\n camera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);\r\n }\r\n }\r\n\r\n // Connection\r\n private _attachedCamera: Nullable;\r\n private _onAfterCheckInputsObserver: Nullable>;\r\n private _onMeshTargetChangedObserver: Nullable>>;\r\n\r\n /**\r\n * Initializes the behavior.\r\n */\r\n public init(): void {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Attaches the behavior to its arc rotate camera.\r\n * @param camera Defines the camera to attach the behavior to\r\n */\r\n public attach(camera: ArcRotateCamera): void {\r\n this._attachedCamera = camera;\r\n this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {\r\n if (!this._attachedCamera) {\r\n return;\r\n }\r\n\r\n // Add the bounce animation to the lower radius limit\r\n if (this._isRadiusAtLimit(this._attachedCamera.lowerRadiusLimit)) {\r\n this._applyBoundRadiusAnimation(this.lowerRadiusTransitionRange);\r\n }\r\n\r\n // Add the bounce animation to the upper radius limit\r\n if (this._isRadiusAtLimit(this._attachedCamera.upperRadiusLimit)) {\r\n this._applyBoundRadiusAnimation(this.upperRadiusTransitionRange);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Detaches the behavior from its current arc rotate camera.\r\n */\r\n public detach(): void {\r\n if (!this._attachedCamera) {\r\n return;\r\n }\r\n if (this._onAfterCheckInputsObserver) {\r\n this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);\r\n }\r\n if (this._onMeshTargetChangedObserver) {\r\n this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);\r\n }\r\n this._attachedCamera = null;\r\n }\r\n\r\n // Animations\r\n private _radiusIsAnimating: boolean = false;\r\n private _radiusBounceTransition: Nullable = null;\r\n private _animatables = new Array();\r\n private _cachedWheelPrecision: number;\r\n\r\n /**\r\n * Checks if the camera radius is at the specified limit. Takes into account animation locks.\r\n * @param radiusLimit The limit to check against.\r\n * @returns Bool to indicate if at limit.\r\n */\r\n private _isRadiusAtLimit(radiusLimit: Nullable): boolean {\r\n if (!this._attachedCamera) {\r\n return false;\r\n }\r\n\r\n if (this._attachedCamera.radius === radiusLimit && !this._radiusIsAnimating) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Applies an animation to the radius of the camera, extending by the radiusDelta.\r\n * @param radiusDelta The delta by which to animate to. Can be negative.\r\n */\r\n private _applyBoundRadiusAnimation(radiusDelta: number): void {\r\n if (!this._attachedCamera) {\r\n return;\r\n }\r\n\r\n if (!this._radiusBounceTransition) {\r\n BouncingBehavior.EasingFunction.setEasingMode(BouncingBehavior.EasingMode);\r\n this._radiusBounceTransition = Animation.CreateAnimation(\"radius\", Animation.ANIMATIONTYPE_FLOAT, 60, BouncingBehavior.EasingFunction);\r\n }\r\n // Prevent zoom until bounce has completed\r\n this._cachedWheelPrecision = this._attachedCamera.wheelPrecision;\r\n this._attachedCamera.wheelPrecision = Infinity;\r\n this._attachedCamera.inertialRadiusOffset = 0;\r\n\r\n // Animate to the radius limit\r\n this.stopAllAnimations();\r\n this._radiusIsAnimating = true;\r\n const animatable = Animation.TransitionTo(\r\n \"radius\",\r\n this._attachedCamera.radius + radiusDelta,\r\n this._attachedCamera,\r\n this._attachedCamera.getScene(),\r\n 60,\r\n this._radiusBounceTransition,\r\n this.transitionDuration,\r\n () => this._clearAnimationLocks()\r\n );\r\n\r\n if (animatable) {\r\n this._animatables.push(animatable);\r\n }\r\n }\r\n\r\n /**\r\n * Removes all animation locks. Allows new animations to be added to any of the camera properties.\r\n */\r\n protected _clearAnimationLocks(): void {\r\n this._radiusIsAnimating = false;\r\n\r\n if (this._attachedCamera) {\r\n this._attachedCamera.wheelPrecision = this._cachedWheelPrecision;\r\n }\r\n }\r\n\r\n /**\r\n * Stops and removes all animations that have been applied to the camera\r\n */\r\n public stopAllAnimations(): void {\r\n if (this._attachedCamera) {\r\n this._attachedCamera.animations = [];\r\n }\r\n while (this._animatables.length) {\r\n this._animatables[0].onAnimationEnd = null;\r\n this._animatables[0].stop();\r\n this._animatables.shift();\r\n }\r\n }\r\n}\r\n","import type { Behavior } from \"../../Behaviors/behavior\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport { ExponentialEase, EasingFunction } from \"../../Animations/easing\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { PointerInfoPre } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { PrecisionDate } from \"../../Misc/precisionDate\";\r\n\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport type { Animatable } from \"../../Animations/animatable\";\r\nimport { Animation } from \"../../Animations/animation\";\r\n\r\n/**\r\n * The framing behavior (FramingBehavior) is designed to automatically position an ArcRotateCamera when its target is set to a mesh. It is also useful if you want to prevent the camera to go under a virtual horizontal plane.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior\r\n */\r\nexport class FramingBehavior implements Behavior {\r\n /**\r\n * Gets the name of the behavior.\r\n */\r\n public get name(): string {\r\n return \"Framing\";\r\n }\r\n\r\n /**\r\n * An event triggered when the animation to zoom on target mesh has ended\r\n */\r\n public onTargetFramingAnimationEndObservable = new Observable();\r\n\r\n private _mode = FramingBehavior.FitFrustumSidesMode;\r\n private _radiusScale = 1.0;\r\n private _positionScale = 0.5;\r\n private _defaultElevation = 0.3;\r\n private _elevationReturnTime = 1500;\r\n private _elevationReturnWaitTime = 1000;\r\n private _zoomStopsAnimation = false;\r\n private _framingTime = 1500;\r\n\r\n /**\r\n * The easing function used by animations\r\n */\r\n public static EasingFunction = new ExponentialEase();\r\n\r\n /**\r\n * The easing mode used by animations\r\n */\r\n public static EasingMode = EasingFunction.EASINGMODE_EASEINOUT;\r\n\r\n /**\r\n * Sets the current mode used by the behavior\r\n */\r\n public set mode(mode: number) {\r\n this._mode = mode;\r\n }\r\n\r\n /**\r\n * Gets current mode used by the behavior.\r\n */\r\n public get mode(): number {\r\n return this._mode;\r\n }\r\n\r\n /**\r\n * Sets the scale applied to the radius (1 by default)\r\n */\r\n public set radiusScale(radius: number) {\r\n this._radiusScale = radius;\r\n }\r\n\r\n /**\r\n * Gets the scale applied to the radius\r\n */\r\n public get radiusScale(): number {\r\n return this._radiusScale;\r\n }\r\n\r\n /**\r\n * Sets the scale to apply on Y axis to position camera focus. 0.5 by default which means the center of the bounding box.\r\n */\r\n public set positionScale(scale: number) {\r\n this._positionScale = scale;\r\n }\r\n\r\n /**\r\n * Gets the scale to apply on Y axis to position camera focus. 0.5 by default which means the center of the bounding box.\r\n */\r\n public get positionScale(): number {\r\n return this._positionScale;\r\n }\r\n\r\n /**\r\n * Sets the angle above/below the horizontal plane to return to when the return to default elevation idle\r\n * behaviour is triggered, in radians.\r\n */\r\n public set defaultElevation(elevation: number) {\r\n this._defaultElevation = elevation;\r\n }\r\n\r\n /**\r\n * Gets the angle above/below the horizontal plane to return to when the return to default elevation idle\r\n * behaviour is triggered, in radians.\r\n */\r\n public get defaultElevation() {\r\n return this._defaultElevation;\r\n }\r\n\r\n /**\r\n * Sets the time (in milliseconds) taken to return to the default beta position.\r\n * Negative value indicates camera should not return to default.\r\n */\r\n public set elevationReturnTime(speed: number) {\r\n this._elevationReturnTime = speed;\r\n }\r\n\r\n /**\r\n * Gets the time (in milliseconds) taken to return to the default beta position.\r\n * Negative value indicates camera should not return to default.\r\n */\r\n public get elevationReturnTime(): number {\r\n return this._elevationReturnTime;\r\n }\r\n\r\n /**\r\n * Sets the delay (in milliseconds) taken before the camera returns to the default beta position.\r\n */\r\n public set elevationReturnWaitTime(time: number) {\r\n this._elevationReturnWaitTime = time;\r\n }\r\n\r\n /**\r\n * Gets the delay (in milliseconds) taken before the camera returns to the default beta position.\r\n */\r\n public get elevationReturnWaitTime(): number {\r\n return this._elevationReturnWaitTime;\r\n }\r\n\r\n /**\r\n * Sets the flag that indicates if user zooming should stop animation.\r\n */\r\n public set zoomStopsAnimation(flag: boolean) {\r\n this._zoomStopsAnimation = flag;\r\n }\r\n\r\n /**\r\n * Gets the flag that indicates if user zooming should stop animation.\r\n */\r\n public get zoomStopsAnimation(): boolean {\r\n return this._zoomStopsAnimation;\r\n }\r\n\r\n /**\r\n * Sets the transition time when framing the mesh, in milliseconds\r\n */\r\n public set framingTime(time: number) {\r\n this._framingTime = time;\r\n }\r\n\r\n /**\r\n * Gets the transition time when framing the mesh, in milliseconds\r\n */\r\n public get framingTime() {\r\n return this._framingTime;\r\n }\r\n\r\n /**\r\n * Define if the behavior should automatically change the configured\r\n * camera limits and sensibilities.\r\n */\r\n public autoCorrectCameraLimitsAndSensibility = true;\r\n\r\n // Default behavior functions\r\n private _onPrePointerObservableObserver: Nullable>;\r\n private _onAfterCheckInputsObserver: Nullable>;\r\n private _onMeshTargetChangedObserver: Nullable>>;\r\n private _attachedCamera: Nullable;\r\n private _isPointerDown = false;\r\n private _lastInteractionTime = -Infinity;\r\n\r\n /**\r\n * Initializes the behavior.\r\n */\r\n public init(): void {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Attaches the behavior to its arc rotate camera.\r\n * @param camera Defines the camera to attach the behavior to\r\n */\r\n public attach(camera: ArcRotateCamera): void {\r\n this._attachedCamera = camera;\r\n const scene = this._attachedCamera.getScene();\r\n\r\n FramingBehavior.EasingFunction.setEasingMode(FramingBehavior.EasingMode);\r\n\r\n this._onPrePointerObservableObserver = scene.onPrePointerObservable.add((pointerInfoPre) => {\r\n if (pointerInfoPre.type === PointerEventTypes.POINTERDOWN) {\r\n this._isPointerDown = true;\r\n return;\r\n }\r\n\r\n if (pointerInfoPre.type === PointerEventTypes.POINTERUP) {\r\n this._isPointerDown = false;\r\n }\r\n });\r\n\r\n this._onMeshTargetChangedObserver = camera.onMeshTargetChangedObservable.add((mesh) => {\r\n if (mesh) {\r\n this.zoomOnMesh(mesh, undefined, () => {\r\n this.onTargetFramingAnimationEndObservable.notifyObservers();\r\n });\r\n }\r\n });\r\n\r\n this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {\r\n // Stop the animation if there is user interaction and the animation should stop for this interaction\r\n this._applyUserInteraction();\r\n\r\n // Maintain the camera above the ground. If the user pulls the camera beneath the ground plane, lift it\r\n // back to the default position after a given timeout\r\n this._maintainCameraAboveGround();\r\n });\r\n }\r\n\r\n /**\r\n * Detaches the behavior from its current arc rotate camera.\r\n */\r\n public detach(): void {\r\n if (!this._attachedCamera) {\r\n return;\r\n }\r\n\r\n const scene = this._attachedCamera.getScene();\r\n\r\n if (this._onPrePointerObservableObserver) {\r\n scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);\r\n }\r\n\r\n if (this._onAfterCheckInputsObserver) {\r\n this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);\r\n }\r\n\r\n if (this._onMeshTargetChangedObserver) {\r\n this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);\r\n }\r\n\r\n this._attachedCamera = null;\r\n }\r\n\r\n // Framing control\r\n private _animatables = new Array();\r\n private _betaIsAnimating = false;\r\n private _betaTransition: Animation;\r\n private _radiusTransition: Animation;\r\n private _vectorTransition: Animation;\r\n\r\n /**\r\n * Targets the given mesh and updates zoom level accordingly.\r\n * @param mesh The mesh to target.\r\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\r\n * @param onAnimationEnd Callback triggered at the end of the framing animation\r\n */\r\n public zoomOnMesh(mesh: AbstractMesh, focusOnOriginXZ: boolean = false, onAnimationEnd: Nullable<() => void> = null): void {\r\n mesh.computeWorldMatrix(true);\r\n\r\n const boundingBox = mesh.getBoundingInfo().boundingBox;\r\n this.zoomOnBoundingInfo(boundingBox.minimumWorld, boundingBox.maximumWorld, focusOnOriginXZ, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Targets the given mesh with its children and updates zoom level accordingly.\r\n * @param mesh The mesh to target.\r\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\r\n * @param onAnimationEnd Callback triggered at the end of the framing animation\r\n */\r\n public zoomOnMeshHierarchy(mesh: AbstractMesh, focusOnOriginXZ: boolean = false, onAnimationEnd: Nullable<() => void> = null): void {\r\n mesh.computeWorldMatrix(true);\r\n\r\n const boundingBox = mesh.getHierarchyBoundingVectors(true);\r\n this.zoomOnBoundingInfo(boundingBox.min, boundingBox.max, focusOnOriginXZ, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Targets the given meshes with their children and updates zoom level accordingly.\r\n * @param meshes The mesh to target.\r\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\r\n * @param onAnimationEnd Callback triggered at the end of the framing animation\r\n */\r\n public zoomOnMeshesHierarchy(meshes: AbstractMesh[], focusOnOriginXZ: boolean = false, onAnimationEnd: Nullable<() => void> = null): void {\r\n const min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n const max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\r\n\r\n for (let i = 0; i < meshes.length; i++) {\r\n const boundingInfo = meshes[i].getHierarchyBoundingVectors(true);\r\n Vector3.CheckExtends(boundingInfo.min, min, max);\r\n Vector3.CheckExtends(boundingInfo.max, min, max);\r\n }\r\n\r\n this.zoomOnBoundingInfo(min, max, focusOnOriginXZ, onAnimationEnd);\r\n }\r\n\r\n /**\r\n * Targets the bounding box info defined by its extends and updates zoom level accordingly.\r\n * @param minimumWorld Determines the smaller position of the bounding box extend\r\n * @param maximumWorld Determines the bigger position of the bounding box extend\r\n * @param focusOnOriginXZ Determines if the camera should focus on 0 in the X and Z axis instead of the mesh\r\n * @param onAnimationEnd Callback triggered at the end of the framing animation\r\n * @returns true if the zoom was done\r\n */\r\n public zoomOnBoundingInfo(minimumWorld: Vector3, maximumWorld: Vector3, focusOnOriginXZ: boolean = false, onAnimationEnd: Nullable<() => void> = null): boolean {\r\n let zoomTarget: Vector3;\r\n\r\n if (!this._attachedCamera) {\r\n return false;\r\n }\r\n\r\n // Find target by interpolating from bottom of bounding box in world-space to top via framingPositionY\r\n const bottom = minimumWorld.y;\r\n const top = maximumWorld.y;\r\n const zoomTargetY = bottom + (top - bottom) * this._positionScale;\r\n const radiusWorld = maximumWorld.subtract(minimumWorld).scale(0.5);\r\n\r\n if (focusOnOriginXZ) {\r\n zoomTarget = new Vector3(0, zoomTargetY, 0);\r\n } else {\r\n const centerWorld = minimumWorld.add(radiusWorld);\r\n zoomTarget = new Vector3(centerWorld.x, zoomTargetY, centerWorld.z);\r\n }\r\n\r\n if (!this._vectorTransition) {\r\n this._vectorTransition = Animation.CreateAnimation(\"target\", Animation.ANIMATIONTYPE_VECTOR3, 60, FramingBehavior.EasingFunction);\r\n }\r\n\r\n this._betaIsAnimating = true;\r\n let animatable = Animation.TransitionTo(\"target\", zoomTarget, this._attachedCamera, this._attachedCamera.getScene(), 60, this._vectorTransition, this._framingTime);\r\n if (animatable) {\r\n this._animatables.push(animatable);\r\n }\r\n\r\n // sets the radius and lower radius bounds\r\n // Small delta ensures camera is not always at lower zoom limit.\r\n let radius = 0;\r\n if (this._mode === FramingBehavior.FitFrustumSidesMode) {\r\n const position = this._calculateLowerRadiusFromModelBoundingSphere(minimumWorld, maximumWorld);\r\n if (this.autoCorrectCameraLimitsAndSensibility) {\r\n this._attachedCamera.lowerRadiusLimit = radiusWorld.length() + this._attachedCamera.minZ;\r\n }\r\n radius = position;\r\n } else if (this._mode === FramingBehavior.IgnoreBoundsSizeMode) {\r\n radius = this._calculateLowerRadiusFromModelBoundingSphere(minimumWorld, maximumWorld);\r\n if (this.autoCorrectCameraLimitsAndSensibility && this._attachedCamera.lowerRadiusLimit === null) {\r\n this._attachedCamera.lowerRadiusLimit = this._attachedCamera.minZ;\r\n }\r\n }\r\n\r\n // Set sensibilities\r\n if (this.autoCorrectCameraLimitsAndSensibility) {\r\n const extend = maximumWorld.subtract(minimumWorld).length();\r\n this._attachedCamera.panningSensibility = 5000 / extend;\r\n this._attachedCamera.wheelPrecision = 100 / radius;\r\n }\r\n\r\n // transition to new radius\r\n if (!this._radiusTransition) {\r\n this._radiusTransition = Animation.CreateAnimation(\"radius\", Animation.ANIMATIONTYPE_FLOAT, 60, FramingBehavior.EasingFunction);\r\n }\r\n\r\n animatable = Animation.TransitionTo(\"radius\", radius, this._attachedCamera, this._attachedCamera.getScene(), 60, this._radiusTransition, this._framingTime, () => {\r\n this.stopAllAnimations();\r\n if (onAnimationEnd) {\r\n onAnimationEnd();\r\n }\r\n\r\n if (this._attachedCamera && this._attachedCamera.useInputToRestoreState) {\r\n this._attachedCamera.storeState();\r\n }\r\n });\r\n\r\n if (animatable) {\r\n this._animatables.push(animatable);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Calculates the lowest radius for the camera based on the bounding box of the mesh.\r\n * @param minimumWorld\r\n * @param maximumWorld\r\n * @returns The minimum distance from the primary mesh's center point at which the camera must be kept in order\r\n *\t\t to fully enclose the mesh in the viewing frustum.\r\n */\r\n protected _calculateLowerRadiusFromModelBoundingSphere(minimumWorld: Vector3, maximumWorld: Vector3): number {\r\n const size = maximumWorld.subtract(minimumWorld);\r\n const boxVectorGlobalDiagonal = size.length();\r\n const frustumSlope: Vector2 = this._getFrustumSlope();\r\n\r\n // Formula for setting distance\r\n // (Good explanation: http://stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene)\r\n const radiusWithoutFraming = boxVectorGlobalDiagonal * 0.5;\r\n\r\n // Horizon distance\r\n const radius = radiusWithoutFraming * this._radiusScale;\r\n const distanceForHorizontalFrustum = radius * Math.sqrt(1.0 + 1.0 / (frustumSlope.x * frustumSlope.x));\r\n const distanceForVerticalFrustum = radius * Math.sqrt(1.0 + 1.0 / (frustumSlope.y * frustumSlope.y));\r\n let distance = Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum);\r\n const camera = this._attachedCamera;\r\n\r\n if (!camera) {\r\n return 0;\r\n }\r\n\r\n if (camera.lowerRadiusLimit && this._mode === FramingBehavior.IgnoreBoundsSizeMode) {\r\n // Don't exceed the requested limit\r\n distance = distance < camera.lowerRadiusLimit ? camera.lowerRadiusLimit : distance;\r\n }\r\n\r\n // Don't exceed the upper radius limit\r\n if (camera.upperRadiusLimit) {\r\n distance = distance > camera.upperRadiusLimit ? camera.upperRadiusLimit : distance;\r\n }\r\n\r\n return distance;\r\n }\r\n\r\n /**\r\n * Keeps the camera above the ground plane. If the user pulls the camera below the ground plane, the camera\r\n * is automatically returned to its default position (expected to be above ground plane).\r\n */\r\n private _maintainCameraAboveGround(): void {\r\n if (this._elevationReturnTime < 0) {\r\n return;\r\n }\r\n\r\n const timeSinceInteraction = PrecisionDate.Now - this._lastInteractionTime;\r\n const defaultBeta = Math.PI * 0.5 - this._defaultElevation;\r\n const limitBeta = Math.PI * 0.5;\r\n\r\n // Bring the camera back up if below the ground plane\r\n if (this._attachedCamera && !this._betaIsAnimating && this._attachedCamera.beta > limitBeta && timeSinceInteraction >= this._elevationReturnWaitTime) {\r\n this._betaIsAnimating = true;\r\n\r\n //Transition to new position\r\n this.stopAllAnimations();\r\n\r\n if (!this._betaTransition) {\r\n this._betaTransition = Animation.CreateAnimation(\"beta\", Animation.ANIMATIONTYPE_FLOAT, 60, FramingBehavior.EasingFunction);\r\n }\r\n\r\n const animatabe = Animation.TransitionTo(\r\n \"beta\",\r\n defaultBeta,\r\n this._attachedCamera,\r\n this._attachedCamera.getScene(),\r\n 60,\r\n this._betaTransition,\r\n this._elevationReturnTime,\r\n () => {\r\n this._clearAnimationLocks();\r\n this.stopAllAnimations();\r\n }\r\n );\r\n\r\n if (animatabe) {\r\n this._animatables.push(animatabe);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Returns the frustum slope based on the canvas ratio and camera FOV\r\n * @returns The frustum slope represented as a Vector2 with X and Y slopes\r\n */\r\n private _getFrustumSlope(): Vector2 {\r\n // Calculate the viewport ratio\r\n // Aspect Ratio is Height/Width.\r\n const camera = this._attachedCamera;\r\n\r\n if (!camera) {\r\n return Vector2.Zero();\r\n }\r\n\r\n const engine = camera.getScene().getEngine();\r\n const aspectRatio = engine.getAspectRatio(camera);\r\n\r\n // Camera FOV is the vertical field of view (top-bottom) in radians.\r\n // Slope of the frustum top/bottom planes in view space, relative to the forward vector.\r\n const frustumSlopeY = Math.tan(camera.fov / 2);\r\n\r\n // Slope of the frustum left/right planes in view space, relative to the forward vector.\r\n // Provides the amount that one side (e.g. left) of the frustum gets wider for every unit\r\n // along the forward vector.\r\n const frustumSlopeX = frustumSlopeY * aspectRatio;\r\n\r\n return new Vector2(frustumSlopeX, frustumSlopeY);\r\n }\r\n\r\n /**\r\n * Removes all animation locks. Allows new animations to be added to any of the arcCamera properties.\r\n */\r\n private _clearAnimationLocks(): void {\r\n this._betaIsAnimating = false;\r\n }\r\n\r\n /**\r\n * Applies any current user interaction to the camera. Takes into account maximum alpha rotation.\r\n */\r\n private _applyUserInteraction(): void {\r\n if (this.isUserIsMoving) {\r\n this._lastInteractionTime = PrecisionDate.Now;\r\n this.stopAllAnimations();\r\n this._clearAnimationLocks();\r\n }\r\n }\r\n\r\n /**\r\n * Stops and removes all animations that have been applied to the camera\r\n */\r\n public stopAllAnimations(): void {\r\n if (this._attachedCamera) {\r\n this._attachedCamera.animations = [];\r\n }\r\n\r\n while (this._animatables.length) {\r\n if (this._animatables[0]) {\r\n this._animatables[0].onAnimationEnd = null;\r\n this._animatables[0].stop();\r\n }\r\n this._animatables.shift();\r\n }\r\n }\r\n\r\n /**\r\n * Gets a value indicating if the user is moving the camera\r\n */\r\n public get isUserIsMoving(): boolean {\r\n if (!this._attachedCamera) {\r\n return false;\r\n }\r\n\r\n return (\r\n this._attachedCamera.inertialAlphaOffset !== 0 ||\r\n this._attachedCamera.inertialBetaOffset !== 0 ||\r\n this._attachedCamera.inertialRadiusOffset !== 0 ||\r\n this._attachedCamera.inertialPanningX !== 0 ||\r\n this._attachedCamera.inertialPanningY !== 0 ||\r\n this._isPointerDown\r\n );\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * The camera can move all the way towards the mesh.\r\n */\r\n public static IgnoreBoundsSizeMode = 0;\r\n\r\n /**\r\n * The camera is not allowed to zoom closer to the mesh than the point at which the adjusted bounding sphere touches the frustum sides\r\n */\r\n public static FitFrustumSidesMode = 1;\r\n}\r\n","import { serialize, serializeAsVector3, serializeAsMeshReference } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Camera } from \"./camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Quaternion, Matrix, Vector3, Vector2, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n/**\r\n * A target camera takes a mesh or position as a target and continues to look at it while it moves.\r\n * This is the base of the follow, arc rotate cameras and Free camera\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\r\n */\r\nexport class TargetCamera extends Camera {\r\n private static _RigCamTransformMatrix = new Matrix();\r\n private static _TargetTransformMatrix = new Matrix();\r\n private static _TargetFocalPoint = new Vector3();\r\n\r\n private _tmpUpVector = Vector3.Zero();\r\n private _tmpTargetVector = Vector3.Zero();\r\n\r\n /**\r\n * Define the current direction the camera is moving to\r\n */\r\n public cameraDirection = new Vector3(0, 0, 0);\r\n /**\r\n * Define the current rotation the camera is rotating to\r\n */\r\n public cameraRotation = new Vector2(0, 0);\r\n\r\n /** Gets or sets a boolean indicating that the scaling of the parent hierarchy will not be taken in account by the camera */\r\n public ignoreParentScaling = false;\r\n\r\n /**\r\n * When set, the up vector of the camera will be updated by the rotation of the camera\r\n */\r\n public updateUpVectorFromRotation = false;\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n /**\r\n * Define the current rotation of the camera\r\n */\r\n @serializeAsVector3()\r\n public rotation = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * Define the current rotation of the camera as a quaternion to prevent Gimbal lock\r\n */\r\n public rotationQuaternion: Quaternion;\r\n\r\n /**\r\n * Define the current speed of the camera\r\n */\r\n @serialize()\r\n public speed = 2.0;\r\n\r\n /**\r\n * Add constraint to the camera to prevent it to move freely in all directions and\r\n * around all axis.\r\n */\r\n public noRotationConstraint = false;\r\n\r\n /**\r\n * Reverses mouselook direction to 'natural' panning as opposed to traditional direct\r\n * panning\r\n */\r\n public invertRotation = false;\r\n\r\n /**\r\n * Speed multiplier for inverse camera panning\r\n */\r\n public inverseRotationSpeed = 0.2;\r\n\r\n /**\r\n * Define the current target of the camera as an object or a position.\r\n * Please note that locking a target will disable panning.\r\n */\r\n @serializeAsMeshReference(\"lockedTargetId\")\r\n public lockedTarget: any = null;\r\n\r\n /** @internal */\r\n public _currentTarget = Vector3.Zero();\r\n /** @internal */\r\n public _initialFocalDistance = 1;\r\n /** @internal */\r\n public _viewMatrix = Matrix.Zero();\r\n /** @internal */\r\n public _camMatrix = Matrix.Zero();\r\n /** @internal */\r\n public _cameraTransformMatrix = Matrix.Zero();\r\n /** @internal */\r\n public _cameraRotationMatrix = Matrix.Zero();\r\n\r\n /** @internal */\r\n public _referencePoint = new Vector3(0, 0, 1);\r\n /** @internal */\r\n public _transformedReferencePoint = Vector3.Zero();\r\n\r\n protected _deferredPositionUpdate = new Vector3();\r\n protected _deferredRotationQuaternionUpdate = new Quaternion();\r\n protected _deferredRotationUpdate = new Vector3();\r\n protected _deferredUpdated = false;\r\n protected _deferOnly: boolean = false;\r\n\r\n /** @internal */\r\n public _reset: () => void;\r\n\r\n private _defaultUp = Vector3.Up();\r\n\r\n /**\r\n * Instantiates a target camera that takes a mesh or position as a target and continues to look at it while it moves.\r\n * This is the base of the follow, arc rotate cameras and Free camera\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras\r\n * @param name Defines the name of the camera in the scene\r\n * @param position Defines the start position of the camera in the scene\r\n * @param scene Defines the scene the camera belongs to\r\n * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene, setActiveOnSceneIfNoneActive = true) {\r\n super(name, position, scene, setActiveOnSceneIfNoneActive);\r\n }\r\n\r\n /**\r\n * Gets the position in front of the camera at a given distance.\r\n * @param distance The distance from the camera we want the position to be\r\n * @returns the position\r\n */\r\n public getFrontPosition(distance: number): Vector3 {\r\n this.getWorldMatrix();\r\n const direction = this.getTarget().subtract(this.position);\r\n direction.normalize();\r\n direction.scaleInPlace(distance);\r\n return this.globalPosition.add(direction);\r\n }\r\n\r\n /** @internal */\r\n public _getLockedTargetPosition(): Nullable {\r\n if (!this.lockedTarget) {\r\n return null;\r\n }\r\n\r\n if (this.lockedTarget.absolutePosition) {\r\n const lockedTarget = this.lockedTarget as AbstractMesh;\r\n const m = lockedTarget.computeWorldMatrix();\r\n // in some cases the absolute position resets externally, but doesn't update since the matrix is cached.\r\n m.getTranslationToRef(lockedTarget.absolutePosition);\r\n }\r\n\r\n return this.lockedTarget.absolutePosition || this.lockedTarget;\r\n }\r\n\r\n private _storedPosition: Vector3;\r\n private _storedRotation: Vector3;\r\n private _storedRotationQuaternion: Quaternion;\r\n\r\n /**\r\n * Store current camera state of the camera (fov, position, rotation, etc..)\r\n * @returns the camera\r\n */\r\n public storeState(): Camera {\r\n this._storedPosition = this.position.clone();\r\n this._storedRotation = this.rotation.clone();\r\n if (this.rotationQuaternion) {\r\n this._storedRotationQuaternion = this.rotationQuaternion.clone();\r\n }\r\n\r\n return super.storeState();\r\n }\r\n\r\n /**\r\n * Restored camera state. You must call storeState() first\r\n * @returns whether it was successful or not\r\n * @internal\r\n */\r\n public _restoreStateValues(): boolean {\r\n if (!super._restoreStateValues()) {\r\n return false;\r\n }\r\n\r\n this.position = this._storedPosition.clone();\r\n this.rotation = this._storedRotation.clone();\r\n\r\n if (this.rotationQuaternion) {\r\n this.rotationQuaternion = this._storedRotationQuaternion.clone();\r\n }\r\n\r\n this.cameraDirection.copyFromFloats(0, 0, 0);\r\n this.cameraRotation.copyFromFloats(0, 0);\r\n\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public _initCache() {\r\n super._initCache();\r\n this._cache.lockedTarget = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n this._cache.rotation = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n this._cache.rotationQuaternion = new Quaternion(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateCache(ignoreParentClass?: boolean): void {\r\n if (!ignoreParentClass) {\r\n super._updateCache();\r\n }\r\n\r\n const lockedTargetPosition = this._getLockedTargetPosition();\r\n if (!lockedTargetPosition) {\r\n this._cache.lockedTarget = null;\r\n } else {\r\n if (!this._cache.lockedTarget) {\r\n this._cache.lockedTarget = lockedTargetPosition.clone();\r\n } else {\r\n this._cache.lockedTarget.copyFrom(lockedTargetPosition);\r\n }\r\n }\r\n\r\n this._cache.rotation.copyFrom(this.rotation);\r\n if (this.rotationQuaternion) {\r\n this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);\r\n }\r\n }\r\n\r\n // Synchronized\r\n /** @internal */\r\n public _isSynchronizedViewMatrix(): boolean {\r\n if (!super._isSynchronizedViewMatrix()) {\r\n return false;\r\n }\r\n\r\n const lockedTargetPosition = this._getLockedTargetPosition();\r\n\r\n return (\r\n (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition) &&\r\n (this.rotationQuaternion ? this.rotationQuaternion.equals(this._cache.rotationQuaternion) : this._cache.rotation.equals(this.rotation))\r\n );\r\n }\r\n\r\n // Methods\r\n /** @internal */\r\n public _computeLocalCameraSpeed(): number {\r\n const engine = this.getEngine();\r\n return this.speed * Math.sqrt(engine.getDeltaTime() / (engine.getFps() * 100.0));\r\n }\r\n\r\n // Target\r\n\r\n /**\r\n * Defines the target the camera should look at.\r\n * @param target Defines the new target as a Vector\r\n */\r\n public setTarget(target: Vector3): void {\r\n this.upVector.normalize();\r\n\r\n this._initialFocalDistance = target.subtract(this.position).length();\r\n\r\n if (this.position.z === target.z) {\r\n this.position.z += Epsilon;\r\n }\r\n\r\n this._referencePoint.normalize().scaleInPlace(this._initialFocalDistance);\r\n\r\n Matrix.LookAtLHToRef(this.position, target, this._defaultUp, this._camMatrix);\r\n this._camMatrix.invert();\r\n\r\n this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);\r\n\r\n const vDir = target.subtract(this.position);\r\n\r\n if (vDir.x >= 0.0) {\r\n this.rotation.y = -Math.atan(vDir.z / vDir.x) + Math.PI / 2.0;\r\n } else {\r\n this.rotation.y = -Math.atan(vDir.z / vDir.x) - Math.PI / 2.0;\r\n }\r\n\r\n this.rotation.z = 0;\r\n\r\n if (isNaN(this.rotation.x)) {\r\n this.rotation.x = 0;\r\n }\r\n\r\n if (isNaN(this.rotation.y)) {\r\n this.rotation.y = 0;\r\n }\r\n\r\n if (isNaN(this.rotation.z)) {\r\n this.rotation.z = 0;\r\n }\r\n\r\n if (this.rotationQuaternion) {\r\n Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this.rotationQuaternion);\r\n }\r\n }\r\n\r\n /**\r\n * Defines the target point of the camera.\r\n * The camera looks towards it form the radius distance.\r\n */\r\n public get target(): Vector3 {\r\n return this.getTarget();\r\n }\r\n public set target(value: Vector3) {\r\n this.setTarget(value);\r\n }\r\n\r\n /**\r\n * Return the current target position of the camera. This value is expressed in local space.\r\n * @returns the target position\r\n */\r\n public getTarget(): Vector3 {\r\n return this._currentTarget;\r\n }\r\n\r\n /** @internal */\r\n public _decideIfNeedsToMove(): boolean {\r\n return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;\r\n }\r\n\r\n /** @internal */\r\n public _updatePosition(): void {\r\n if (this.parent) {\r\n this.parent.getWorldMatrix().invertToRef(TmpVectors.Matrix[0]);\r\n Vector3.TransformNormalToRef(this.cameraDirection, TmpVectors.Matrix[0], TmpVectors.Vector3[0]);\r\n this._deferredPositionUpdate.addInPlace(TmpVectors.Vector3[0]);\r\n if (!this._deferOnly) {\r\n this.position.copyFrom(this._deferredPositionUpdate);\r\n } else {\r\n this._deferredUpdated = true;\r\n }\r\n return;\r\n }\r\n this._deferredPositionUpdate.addInPlace(this.cameraDirection);\r\n if (!this._deferOnly) {\r\n this.position.copyFrom(this._deferredPositionUpdate);\r\n } else {\r\n this._deferredUpdated = true;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _checkInputs(): void {\r\n const directionMultiplier = this.invertRotation ? -this.inverseRotationSpeed : 1.0;\r\n const needToMove = this._decideIfNeedsToMove();\r\n const needToRotate = this.cameraRotation.x || this.cameraRotation.y;\r\n\r\n this._deferredUpdated = false;\r\n this._deferredRotationUpdate.copyFrom(this.rotation);\r\n this._deferredPositionUpdate.copyFrom(this.position);\r\n if (this.rotationQuaternion) {\r\n this._deferredRotationQuaternionUpdate.copyFrom(this.rotationQuaternion);\r\n }\r\n\r\n // Move\r\n if (needToMove) {\r\n this._updatePosition();\r\n }\r\n\r\n // Rotate\r\n if (needToRotate) {\r\n //rotate, if quaternion is set and rotation was used\r\n if (this.rotationQuaternion) {\r\n this.rotationQuaternion.toEulerAnglesToRef(this._deferredRotationUpdate);\r\n }\r\n\r\n this._deferredRotationUpdate.x += this.cameraRotation.x * directionMultiplier;\r\n this._deferredRotationUpdate.y += this.cameraRotation.y * directionMultiplier;\r\n\r\n // Apply constraints\r\n if (!this.noRotationConstraint) {\r\n const limit = 1.570796;\r\n\r\n if (this._deferredRotationUpdate.x > limit) {\r\n this._deferredRotationUpdate.x = limit;\r\n }\r\n if (this._deferredRotationUpdate.x < -limit) {\r\n this._deferredRotationUpdate.x = -limit;\r\n }\r\n }\r\n\r\n if (!this._deferOnly) {\r\n this.rotation.copyFrom(this._deferredRotationUpdate);\r\n } else {\r\n this._deferredUpdated = true;\r\n }\r\n\r\n //rotate, if quaternion is set and rotation was used\r\n if (this.rotationQuaternion) {\r\n const len = this._deferredRotationUpdate.lengthSquared();\r\n if (len) {\r\n Quaternion.RotationYawPitchRollToRef(\r\n this._deferredRotationUpdate.y,\r\n this._deferredRotationUpdate.x,\r\n this._deferredRotationUpdate.z,\r\n this._deferredRotationQuaternionUpdate\r\n );\r\n if (!this._deferOnly) {\r\n this.rotationQuaternion.copyFrom(this._deferredRotationQuaternionUpdate);\r\n } else {\r\n this._deferredUpdated = true;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Inertia\r\n if (needToMove) {\r\n if (Math.abs(this.cameraDirection.x) < this.speed * Epsilon) {\r\n this.cameraDirection.x = 0;\r\n }\r\n\r\n if (Math.abs(this.cameraDirection.y) < this.speed * Epsilon) {\r\n this.cameraDirection.y = 0;\r\n }\r\n\r\n if (Math.abs(this.cameraDirection.z) < this.speed * Epsilon) {\r\n this.cameraDirection.z = 0;\r\n }\r\n\r\n this.cameraDirection.scaleInPlace(this.inertia);\r\n }\r\n if (needToRotate) {\r\n if (Math.abs(this.cameraRotation.x) < this.speed * Epsilon) {\r\n this.cameraRotation.x = 0;\r\n }\r\n\r\n if (Math.abs(this.cameraRotation.y) < this.speed * Epsilon) {\r\n this.cameraRotation.y = 0;\r\n }\r\n this.cameraRotation.scaleInPlace(this.inertia);\r\n }\r\n\r\n super._checkInputs();\r\n }\r\n\r\n protected _updateCameraRotationMatrix() {\r\n if (this.rotationQuaternion) {\r\n this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix);\r\n } else {\r\n Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);\r\n }\r\n }\r\n\r\n /**\r\n * Update the up vector to apply the rotation of the camera (So if you changed the camera rotation.z this will let you update the up vector as well)\r\n * @returns the current camera\r\n */\r\n private _rotateUpVectorWithCameraRotationMatrix(): TargetCamera {\r\n Vector3.TransformNormalToRef(this._defaultUp, this._cameraRotationMatrix, this.upVector);\r\n return this;\r\n }\r\n\r\n private _cachedRotationZ = 0;\r\n private _cachedQuaternionRotationZ = 0;\r\n /** @internal */\r\n public _getViewMatrix(): Matrix {\r\n if (this.lockedTarget) {\r\n this.setTarget(this._getLockedTargetPosition()!);\r\n }\r\n\r\n // Compute\r\n this._updateCameraRotationMatrix();\r\n\r\n // Apply the changed rotation to the upVector\r\n if (this.rotationQuaternion && this._cachedQuaternionRotationZ != this.rotationQuaternion.z) {\r\n this._rotateUpVectorWithCameraRotationMatrix();\r\n this._cachedQuaternionRotationZ = this.rotationQuaternion.z;\r\n } else if (this._cachedRotationZ !== this.rotation.z) {\r\n this._rotateUpVectorWithCameraRotationMatrix();\r\n this._cachedRotationZ = this.rotation.z;\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);\r\n\r\n // Computing target and final matrix\r\n this.position.addToRef(this._transformedReferencePoint, this._currentTarget);\r\n if (this.updateUpVectorFromRotation) {\r\n if (this.rotationQuaternion) {\r\n Axis.Y.rotateByQuaternionToRef(this.rotationQuaternion, this.upVector);\r\n } else {\r\n Quaternion.FromEulerVectorToRef(this.rotation, this._tmpQuaternion);\r\n Axis.Y.rotateByQuaternionToRef(this._tmpQuaternion, this.upVector);\r\n }\r\n }\r\n this._computeViewMatrix(this.position, this._currentTarget, this.upVector);\r\n return this._viewMatrix;\r\n }\r\n\r\n protected _computeViewMatrix(position: Vector3, target: Vector3, up: Vector3): void {\r\n if (this.ignoreParentScaling) {\r\n if (this.parent) {\r\n const parentWorldMatrix = this.parent.getWorldMatrix();\r\n Vector3.TransformCoordinatesToRef(position, parentWorldMatrix, this._globalPosition);\r\n Vector3.TransformCoordinatesToRef(target, parentWorldMatrix, this._tmpTargetVector);\r\n Vector3.TransformNormalToRef(up, parentWorldMatrix, this._tmpUpVector);\r\n this._markSyncedWithParent();\r\n } else {\r\n this._globalPosition.copyFrom(position);\r\n this._tmpTargetVector.copyFrom(target);\r\n this._tmpUpVector.copyFrom(up);\r\n }\r\n\r\n if (this.getScene().useRightHandedSystem) {\r\n Matrix.LookAtRHToRef(this._globalPosition, this._tmpTargetVector, this._tmpUpVector, this._viewMatrix);\r\n } else {\r\n Matrix.LookAtLHToRef(this._globalPosition, this._tmpTargetVector, this._tmpUpVector, this._viewMatrix);\r\n }\r\n return;\r\n }\r\n\r\n if (this.getScene().useRightHandedSystem) {\r\n Matrix.LookAtRHToRef(position, target, up, this._viewMatrix);\r\n } else {\r\n Matrix.LookAtLHToRef(position, target, up, this._viewMatrix);\r\n }\r\n\r\n if (this.parent) {\r\n const parentWorldMatrix = this.parent.getWorldMatrix();\r\n this._viewMatrix.invert();\r\n this._viewMatrix.multiplyToRef(parentWorldMatrix, this._viewMatrix);\r\n this._viewMatrix.getTranslationToRef(this._globalPosition);\r\n this._viewMatrix.invert();\r\n this._markSyncedWithParent();\r\n } else {\r\n this._globalPosition.copyFrom(position);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public createRigCamera(name: string, cameraIndex: number): Nullable {\r\n if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {\r\n const rigCamera = new TargetCamera(name, this.position.clone(), this.getScene());\r\n rigCamera.isRigCamera = true;\r\n rigCamera.rigParent = this;\r\n if (this.cameraRigMode === Camera.RIG_MODE_VR || this.cameraRigMode === Camera.RIG_MODE_WEBVR) {\r\n if (!this.rotationQuaternion) {\r\n this.rotationQuaternion = new Quaternion();\r\n }\r\n rigCamera._cameraRigParams = {};\r\n rigCamera.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n rigCamera.mode = this.mode;\r\n rigCamera.orthoLeft = this.orthoLeft;\r\n rigCamera.orthoRight = this.orthoRight;\r\n rigCamera.orthoTop = this.orthoTop;\r\n rigCamera.orthoBottom = this.orthoBottom;\r\n\r\n return rigCamera;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateRigCameras() {\r\n const camLeft = this._rigCameras[0];\r\n const camRight = this._rigCameras[1];\r\n\r\n this.computeWorldMatrix();\r\n\r\n switch (this.cameraRigMode) {\r\n case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:\r\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:\r\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:\r\n case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:\r\n case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED: {\r\n //provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:\r\n const leftSign = this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED ? 1 : -1;\r\n const rightSign = this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED ? -1 : 1;\r\n this._getRigCamPositionAndTarget(this._cameraRigParams.stereoHalfAngle * leftSign, camLeft);\r\n this._getRigCamPositionAndTarget(this._cameraRigParams.stereoHalfAngle * rightSign, camRight);\r\n break;\r\n }\r\n case Camera.RIG_MODE_VR:\r\n if (camLeft.rotationQuaternion) {\r\n camLeft.rotationQuaternion.copyFrom(this.rotationQuaternion);\r\n camRight.rotationQuaternion.copyFrom(this.rotationQuaternion);\r\n } else {\r\n camLeft.rotation.copyFrom(this.rotation);\r\n camRight.rotation.copyFrom(this.rotation);\r\n }\r\n camLeft.position.copyFrom(this.position);\r\n camRight.position.copyFrom(this.position);\r\n\r\n break;\r\n }\r\n super._updateRigCameras();\r\n }\r\n\r\n private _getRigCamPositionAndTarget(halfSpace: number, rigCamera: TargetCamera) {\r\n const target = this.getTarget();\r\n target.subtractToRef(this.position, TargetCamera._TargetFocalPoint);\r\n\r\n TargetCamera._TargetFocalPoint.normalize().scaleInPlace(this._initialFocalDistance);\r\n const newFocalTarget = TargetCamera._TargetFocalPoint.addInPlace(this.position);\r\n\r\n Matrix.TranslationToRef(-newFocalTarget.x, -newFocalTarget.y, -newFocalTarget.z, TargetCamera._TargetTransformMatrix);\r\n TargetCamera._TargetTransformMatrix.multiplyToRef(Matrix.RotationAxis(rigCamera.upVector, halfSpace), TargetCamera._RigCamTransformMatrix);\r\n Matrix.TranslationToRef(newFocalTarget.x, newFocalTarget.y, newFocalTarget.z, TargetCamera._TargetTransformMatrix);\r\n\r\n TargetCamera._RigCamTransformMatrix.multiplyToRef(TargetCamera._TargetTransformMatrix, TargetCamera._RigCamTransformMatrix);\r\n\r\n Vector3.TransformCoordinatesToRef(this.position, TargetCamera._RigCamTransformMatrix, rigCamera.position);\r\n rigCamera.setTarget(newFocalTarget);\r\n }\r\n\r\n /**\r\n * Gets the current object class name.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"TargetCamera\";\r\n }\r\n}\r\n","import { Logger } from \"../Misc/logger\";\r\nimport { SerializationHelper } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Camera } from \"./camera\";\r\n/**\r\n * @ignore\r\n * This is a list of all the different input types that are available in the application.\r\n * Fo instance: ArcRotateCameraGamepadInput...\r\n */\r\n// eslint-disable-next-line no-var, @typescript-eslint/naming-convention\r\nexport var CameraInputTypes = {};\r\n\r\n/**\r\n * This is the contract to implement in order to create a new input class.\r\n * Inputs are dealing with listening to user actions and moving the camera accordingly.\r\n */\r\nexport interface ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n camera: Nullable;\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n getClassName(): string;\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n getSimpleName(): string;\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n attachControl(noPreventDefault?: boolean): void;\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n detachControl(): void;\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n checkInputs?: () => void;\r\n}\r\n\r\n/**\r\n * Represents a map of input types to input instance or input index to input instance.\r\n */\r\nexport interface CameraInputsMap {\r\n /**\r\n * Accessor to the input by input type.\r\n */\r\n [name: string]: ICameraInput;\r\n /**\r\n * Accessor to the input by input index.\r\n */\r\n [idx: number]: ICameraInput;\r\n}\r\n\r\n/**\r\n * This represents the input manager used within a camera.\r\n * It helps dealing with all the different kind of input attached to a camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class CameraInputsManager {\r\n /**\r\n * Defines the list of inputs attached to the camera.\r\n */\r\n public attached: CameraInputsMap;\r\n\r\n /**\r\n * Defines the dom element the camera is collecting inputs from.\r\n * This is null if the controls have not been attached.\r\n */\r\n public attachedToElement: boolean = false;\r\n\r\n /**\r\n * Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public noPreventDefault: boolean;\r\n\r\n /**\r\n * Defined the camera the input manager belongs to.\r\n */\r\n public camera: TCamera;\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs: () => void;\r\n\r\n /**\r\n * Instantiate a new Camera Input Manager.\r\n * @param camera Defines the camera the input manager belongs to\r\n */\r\n constructor(camera: TCamera) {\r\n this.attached = {};\r\n this.camera = camera;\r\n this.checkInputs = () => {};\r\n }\r\n\r\n /**\r\n * Add an input method to a camera\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n * @param input Camera input method\r\n */\r\n public add(input: ICameraInput): void {\r\n const type = input.getSimpleName();\r\n if (this.attached[type]) {\r\n Logger.Warn(\"camera input of type \" + type + \" already exists on camera\");\r\n return;\r\n }\r\n\r\n this.attached[type] = input;\r\n\r\n input.camera = this.camera;\r\n\r\n // for checkInputs, we are dynamically creating a function\r\n // the goal is to avoid the performance penalty of looping for inputs in the render loop\r\n if (input.checkInputs) {\r\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\r\n }\r\n\r\n if (this.attachedToElement) {\r\n input.attachControl(this.noPreventDefault);\r\n }\r\n }\r\n\r\n /**\r\n * Remove a specific input method from a camera\r\n * example: camera.inputs.remove(camera.inputs.attached.mouse);\r\n * @param inputToRemove camera input method\r\n */\r\n public remove(inputToRemove: ICameraInput): void {\r\n for (const cam in this.attached) {\r\n const input = this.attached[cam];\r\n if (input === inputToRemove) {\r\n input.detachControl();\r\n input.camera = null;\r\n delete this.attached[cam];\r\n this.rebuildInputCheck();\r\n\r\n return;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Remove a specific input type from a camera\r\n * example: camera.inputs.remove(\"ArcRotateCameraGamepadInput\");\r\n * @param inputType the type of the input to remove\r\n */\r\n public removeByType(inputType: string): void {\r\n for (const cam in this.attached) {\r\n const input = this.attached[cam];\r\n if (input.getClassName() === inputType) {\r\n input.detachControl();\r\n input.camera = null;\r\n delete this.attached[cam];\r\n this.rebuildInputCheck();\r\n }\r\n }\r\n }\r\n\r\n private _addCheckInputs(fn: () => void) {\r\n const current = this.checkInputs;\r\n return () => {\r\n current();\r\n fn();\r\n };\r\n }\r\n\r\n /**\r\n * Attach the input controls to the currently attached dom element to listen the events from.\r\n * @param input Defines the input to attach\r\n */\r\n public attachInput(input: ICameraInput): void {\r\n if (this.attachedToElement) {\r\n input.attachControl(this.noPreventDefault);\r\n }\r\n }\r\n\r\n /**\r\n * Attach the current manager inputs controls to a specific dom element to listen the events from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachElement(noPreventDefault: boolean = false): void {\r\n if (this.attachedToElement) {\r\n return;\r\n }\r\n\r\n noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;\r\n this.attachedToElement = true;\r\n this.noPreventDefault = noPreventDefault;\r\n\r\n for (const cam in this.attached) {\r\n this.attached[cam].attachControl(noPreventDefault);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current manager inputs controls from a specific dom element.\r\n * @param disconnect Defines whether the input should be removed from the current list of attached inputs\r\n */\r\n public detachElement(disconnect = false): void {\r\n for (const cam in this.attached) {\r\n this.attached[cam].detachControl();\r\n\r\n if (disconnect) {\r\n this.attached[cam].camera = null;\r\n }\r\n }\r\n this.attachedToElement = false;\r\n }\r\n\r\n /**\r\n * Rebuild the dynamic inputCheck function from the current list of\r\n * defined inputs in the manager.\r\n */\r\n public rebuildInputCheck(): void {\r\n this.checkInputs = () => {};\r\n\r\n for (const cam in this.attached) {\r\n const input = this.attached[cam];\r\n if (input.checkInputs) {\r\n this.checkInputs = this._addCheckInputs(input.checkInputs.bind(input));\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Remove all attached input methods from a camera\r\n */\r\n public clear(): void {\r\n if (this.attachedToElement) {\r\n this.detachElement(true);\r\n }\r\n this.attached = {};\r\n this.attachedToElement = false;\r\n this.checkInputs = () => {};\r\n }\r\n\r\n /**\r\n * Serialize the current input manager attached to a camera.\r\n * This ensures than once parsed,\r\n * the input associated to the camera will be identical to the current ones\r\n * @param serializedCamera Defines the camera serialization JSON the input serialization should write to\r\n */\r\n public serialize(serializedCamera: any): void {\r\n const inputs: { [key: string]: any } = {};\r\n for (const cam in this.attached) {\r\n const input = this.attached[cam];\r\n const res = SerializationHelper.Serialize(input);\r\n inputs[input.getClassName()] = res;\r\n }\r\n\r\n serializedCamera.inputsmgr = inputs;\r\n }\r\n\r\n /**\r\n * Parses an input manager serialized JSON to restore the previous list of inputs\r\n * and states associated to a camera.\r\n * @param parsedCamera Defines the JSON to parse\r\n */\r\n public parse(parsedCamera: any): void {\r\n const parsedInputs = parsedCamera.inputsmgr;\r\n if (parsedInputs) {\r\n this.clear();\r\n\r\n for (const n in parsedInputs) {\r\n const construct = (CameraInputTypes)[n];\r\n if (construct) {\r\n const parsedinput = parsedInputs[n];\r\n const input = SerializationHelper.Parse(\r\n () => {\r\n return new construct();\r\n },\r\n parsedinput,\r\n null\r\n );\r\n this.add(input as any);\r\n }\r\n }\r\n } else {\r\n //2016-03-08 this part is for managing backward compatibility\r\n for (const n in this.attached) {\r\n const construct = (CameraInputTypes)[this.attached[n].getClassName()];\r\n if (construct) {\r\n const input = SerializationHelper.Parse(\r\n () => {\r\n return new construct();\r\n },\r\n parsedCamera,\r\n null\r\n );\r\n this.remove(this.attached[n]);\r\n this.add(input as any);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { EventState, Observer } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport type { PointerInfo, PointerTouch } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Base class for Camera Pointer Inputs.\r\n * See FollowCameraPointersInput in src/Cameras/Inputs/followCameraPointersInput.ts\r\n * for example usage.\r\n */\r\nexport abstract class BaseCameraPointersInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public abstract camera: Camera;\r\n\r\n /**\r\n * Whether keyboard modifier keys are pressed at time of last mouse event.\r\n */\r\n protected _altKey: boolean;\r\n protected _ctrlKey: boolean;\r\n protected _metaKey: boolean;\r\n protected _shiftKey: boolean;\r\n\r\n /**\r\n * Which mouse buttons were pressed at time of last mouse event.\r\n * https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n */\r\n protected _buttonsPressed: number;\r\n\r\n private _currentActiveButton: number = -1;\r\n private _contextMenuBind: EventListener;\r\n\r\n /**\r\n * Defines the buttons associated with the input to handle camera move.\r\n */\r\n @serialize()\r\n public buttons = [0, 1, 2];\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n const engine = this.camera.getEngine();\r\n const element = engine.getInputElement();\r\n let previousPinchSquaredDistance = 0;\r\n let previousMultiTouchPanPosition: Nullable = null;\r\n\r\n this._pointA = null;\r\n this._pointB = null;\r\n\r\n this._altKey = false;\r\n this._ctrlKey = false;\r\n this._metaKey = false;\r\n this._shiftKey = false;\r\n this._buttonsPressed = 0;\r\n\r\n this._pointerInput = (p) => {\r\n const evt = p.event;\r\n const isTouch = evt.pointerType === \"touch\";\r\n\r\n if (engine.isInVRExclusivePointerMode) {\r\n return;\r\n }\r\n\r\n if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {\r\n return;\r\n }\r\n\r\n const srcElement = evt.target;\r\n\r\n this._altKey = evt.altKey;\r\n this._ctrlKey = evt.ctrlKey;\r\n this._metaKey = evt.metaKey;\r\n this._shiftKey = evt.shiftKey;\r\n this._buttonsPressed = evt.buttons;\r\n\r\n if (engine.isPointerLock) {\r\n const offsetX = evt.movementX;\r\n const offsetY = evt.movementY;\r\n\r\n this.onTouch(null, offsetX, offsetY);\r\n this._pointA = null;\r\n this._pointB = null;\r\n } else if (p.type !== PointerEventTypes.POINTERDOWN && isTouch && this._pointA?.pointerId !== evt.pointerId && this._pointB?.pointerId !== evt.pointerId) {\r\n return; // If we get a non-down event for a touch that we're not tracking, ignore it\r\n } else if (p.type === PointerEventTypes.POINTERDOWN && (this._currentActiveButton === -1 || isTouch)) {\r\n try {\r\n srcElement?.setPointerCapture(evt.pointerId);\r\n } catch (e) {\r\n //Nothing to do with the error. Execution will continue.\r\n }\r\n\r\n if (this._pointA === null) {\r\n this._pointA = {\r\n x: evt.clientX,\r\n y: evt.clientY,\r\n pointerId: evt.pointerId,\r\n type: evt.pointerType,\r\n };\r\n } else if (this._pointB === null) {\r\n this._pointB = {\r\n x: evt.clientX,\r\n y: evt.clientY,\r\n pointerId: evt.pointerId,\r\n type: evt.pointerType,\r\n };\r\n } else {\r\n return; // We are already tracking two pointers so ignore this one\r\n }\r\n\r\n if (this._currentActiveButton === -1 && !isTouch) {\r\n this._currentActiveButton = evt.button;\r\n }\r\n this.onButtonDown(evt);\r\n\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n element && element.focus();\r\n }\r\n } else if (p.type === PointerEventTypes.POINTERDOUBLETAP) {\r\n this.onDoubleTap(evt.pointerType);\r\n } else if (p.type === PointerEventTypes.POINTERUP && (this._currentActiveButton === evt.button || isTouch)) {\r\n try {\r\n srcElement?.releasePointerCapture(evt.pointerId);\r\n } catch (e) {\r\n //Nothing to do with the error.\r\n }\r\n\r\n if (!isTouch) {\r\n this._pointB = null; // Mouse and pen are mono pointer\r\n }\r\n\r\n //would be better to use pointers.remove(evt.pointerId) for multitouch gestures,\r\n //but emptying completely pointers collection is required to fix a bug on iPhone :\r\n //when changing orientation while pinching camera,\r\n //one pointer stay pressed forever if we don't release all pointers\r\n //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected\r\n if (engine._badOS) {\r\n this._pointA = this._pointB = null;\r\n } else {\r\n //only remove the impacted pointer in case of multitouch allowing on most\r\n //platforms switching from rotate to zoom and pan seamlessly.\r\n if (this._pointB && this._pointA && this._pointA.pointerId == evt.pointerId) {\r\n this._pointA = this._pointB;\r\n this._pointB = null;\r\n } else if (this._pointA && this._pointB && this._pointB.pointerId == evt.pointerId) {\r\n this._pointB = null;\r\n } else {\r\n this._pointA = this._pointB = null;\r\n }\r\n }\r\n\r\n if (previousPinchSquaredDistance !== 0 || previousMultiTouchPanPosition) {\r\n // Previous pinch data is populated but a button has been lifted\r\n // so pinch has ended.\r\n this.onMultiTouch(\r\n this._pointA,\r\n this._pointB,\r\n previousPinchSquaredDistance,\r\n 0, // pinchSquaredDistance\r\n previousMultiTouchPanPosition,\r\n null // multiTouchPanPosition\r\n );\r\n previousPinchSquaredDistance = 0;\r\n previousMultiTouchPanPosition = null;\r\n }\r\n\r\n this._currentActiveButton = -1;\r\n this.onButtonUp(evt);\r\n\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n } else if (p.type === PointerEventTypes.POINTERMOVE) {\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n\r\n // One button down\r\n if (this._pointA && this._pointB === null) {\r\n const offsetX = evt.clientX - this._pointA.x;\r\n const offsetY = evt.clientY - this._pointA.y;\r\n this.onTouch(this._pointA, offsetX, offsetY);\r\n\r\n this._pointA.x = evt.clientX;\r\n this._pointA.y = evt.clientY;\r\n }\r\n // Two buttons down: pinch\r\n else if (this._pointA && this._pointB) {\r\n const ed = this._pointA.pointerId === evt.pointerId ? this._pointA : this._pointB;\r\n ed.x = evt.clientX;\r\n ed.y = evt.clientY;\r\n const distX = this._pointA.x - this._pointB.x;\r\n const distY = this._pointA.y - this._pointB.y;\r\n const pinchSquaredDistance = distX * distX + distY * distY;\r\n const multiTouchPanPosition = {\r\n x: (this._pointA.x + this._pointB.x) / 2,\r\n y: (this._pointA.y + this._pointB.y) / 2,\r\n pointerId: evt.pointerId,\r\n type: p.type,\r\n };\r\n\r\n this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition);\r\n\r\n previousMultiTouchPanPosition = multiTouchPanPosition;\r\n previousPinchSquaredDistance = pinchSquaredDistance;\r\n }\r\n }\r\n };\r\n\r\n this._observer = this.camera\r\n .getScene()\r\n ._inputManager._addCameraPointerObserver(\r\n this._pointerInput,\r\n PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE | PointerEventTypes.POINTERDOUBLETAP\r\n );\r\n\r\n this._onLostFocus = () => {\r\n this._pointA = this._pointB = null;\r\n previousPinchSquaredDistance = 0;\r\n previousMultiTouchPanPosition = null;\r\n this.onLostFocus();\r\n };\r\n\r\n this._contextMenuBind = this.onContextMenu.bind(this);\r\n\r\n element && element.addEventListener(\"contextmenu\", this._contextMenuBind, false);\r\n\r\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\r\n\r\n if (hostWindow) {\r\n Tools.RegisterTopRootEvents(hostWindow, [{ name: \"blur\", handler: this._onLostFocus }]);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._onLostFocus) {\r\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\r\n if (hostWindow) {\r\n Tools.UnregisterTopRootEvents(hostWindow, [{ name: \"blur\", handler: this._onLostFocus }]);\r\n }\r\n }\r\n\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n this._observer = null;\r\n\r\n if (this._contextMenuBind) {\r\n const inputElement = this.camera.getScene().getEngine().getInputElement();\r\n inputElement && inputElement.removeEventListener(\"contextmenu\", this._contextMenuBind);\r\n }\r\n\r\n this._onLostFocus = null;\r\n }\r\n\r\n this._altKey = false;\r\n this._ctrlKey = false;\r\n this._metaKey = false;\r\n this._shiftKey = false;\r\n this._buttonsPressed = 0;\r\n this._currentActiveButton = -1;\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"BaseCameraPointersInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"pointers\";\r\n }\r\n\r\n /**\r\n * Called on pointer POINTERDOUBLETAP event.\r\n * Override this method to provide functionality on POINTERDOUBLETAP event.\r\n * @param type\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public onDoubleTap(type: string) {}\r\n\r\n /**\r\n * Called on pointer POINTERMOVE event if only a single touch is active.\r\n * Override this method to provide functionality.\r\n * @param point\r\n * @param offsetX\r\n * @param offsetY\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public onTouch(point: Nullable, offsetX: number, offsetY: number): void {}\r\n\r\n /**\r\n * Called on pointer POINTERMOVE event if multiple touches are active.\r\n * Override this method to provide functionality.\r\n * @param _pointA\r\n * @param _pointB\r\n * @param previousPinchSquaredDistance\r\n * @param pinchSquaredDistance\r\n * @param previousMultiTouchPanPosition\r\n * @param multiTouchPanPosition\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public onMultiTouch(\r\n _pointA: Nullable,\r\n _pointB: Nullable,\r\n previousPinchSquaredDistance: number,\r\n pinchSquaredDistance: number,\r\n previousMultiTouchPanPosition: Nullable,\r\n multiTouchPanPosition: Nullable\r\n ): void {}\r\n\r\n /**\r\n * Called on JS contextmenu event.\r\n * Override this method to provide functionality.\r\n * @param evt\r\n */\r\n public onContextMenu(evt: PointerEvent): void {\r\n evt.preventDefault();\r\n }\r\n\r\n /**\r\n * Called each time a new POINTERDOWN event occurs. Ie, for each button\r\n * press.\r\n * Override this method to provide functionality.\r\n * @param evt\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public onButtonDown(evt: IPointerEvent): void {}\r\n\r\n /**\r\n * Called each time a new POINTERUP event occurs. Ie, for each button\r\n * release.\r\n * Override this method to provide functionality.\r\n * @param evt\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public onButtonUp(evt: IPointerEvent): void {}\r\n\r\n /**\r\n * Called when window becomes inactive.\r\n * Override this method to provide functionality.\r\n */\r\n public onLostFocus(): void {}\r\n\r\n private _pointerInput: (p: PointerInfo, s: EventState) => void;\r\n private _observer: Nullable>;\r\n private _onLostFocus: Nullable<(e: FocusEvent) => any>;\r\n private _pointA: Nullable;\r\n private _pointB: Nullable;\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport { BaseCameraPointersInput } from \"../../Cameras/Inputs/BaseCameraPointersInput\";\r\nimport type { PointerTouch } from \"../../Events/pointerEvents\";\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Manage the pointers inputs to control an arc rotate camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraPointersInput extends BaseCameraPointersInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: ArcRotateCamera;\r\n\r\n /**\r\n * The minimum radius used for pinch, to avoid radius lock at 0\r\n */\r\n public static MinimumRadiusForPinch: number = 0.001;\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCameraPointersInput\";\r\n }\r\n\r\n /**\r\n * Defines the buttons associated with the input to handle camera move.\r\n */\r\n @serialize()\r\n public buttons = [0, 1, 2];\r\n\r\n /**\r\n * Defines the pointer angular sensibility along the X axis or how fast is\r\n * the camera rotating.\r\n */\r\n @serialize()\r\n public angularSensibilityX = 1000.0;\r\n\r\n /**\r\n * Defines the pointer angular sensibility along the Y axis or how fast is\r\n * the camera rotating.\r\n */\r\n @serialize()\r\n public angularSensibilityY = 1000.0;\r\n\r\n /**\r\n * Defines the pointer pinch precision or how fast is the camera zooming.\r\n */\r\n @serialize()\r\n public pinchPrecision = 12.0;\r\n\r\n /**\r\n * pinchDeltaPercentage will be used instead of pinchPrecision if different\r\n * from 0.\r\n * It defines the percentage of current camera.radius to use as delta when\r\n * pinch zoom is used.\r\n */\r\n @serialize()\r\n public pinchDeltaPercentage = 0;\r\n\r\n /**\r\n * When useNaturalPinchZoom is true, multi touch zoom will zoom in such\r\n * that any object in the plane at the camera's target point will scale\r\n * perfectly with finger motion.\r\n * Overrides pinchDeltaPercentage and pinchPrecision.\r\n */\r\n @serialize()\r\n public useNaturalPinchZoom: boolean = false;\r\n\r\n /**\r\n * Defines whether zoom (2 fingers pinch) is enabled through multitouch\r\n */\r\n @serialize()\r\n public pinchZoom: boolean = true;\r\n\r\n /**\r\n * Defines the pointer panning sensibility or how fast is the camera moving.\r\n */\r\n @serialize()\r\n public panningSensibility: number = 1000.0;\r\n\r\n /**\r\n * Defines whether panning (2 fingers swipe) is enabled through multitouch.\r\n */\r\n @serialize()\r\n public multiTouchPanning: boolean = true;\r\n\r\n /**\r\n * Defines whether panning is enabled for both pan (2 fingers swipe) and\r\n * zoom (pinch) through multitouch.\r\n */\r\n @serialize()\r\n public multiTouchPanAndZoom: boolean = true;\r\n\r\n /**\r\n * Revers pinch action direction.\r\n */\r\n public pinchInwards = true;\r\n\r\n private _isPanClick: boolean = false;\r\n private _twoFingerActivityCount: number = 0;\r\n private _isPinching: boolean = false;\r\n\r\n /**\r\n * Move camera from multi touch panning positions.\r\n * @param previousMultiTouchPanPosition\r\n * @param multiTouchPanPosition\r\n */\r\n private _computeMultiTouchPanning(previousMultiTouchPanPosition: Nullable, multiTouchPanPosition: Nullable): void {\r\n if (this.panningSensibility !== 0 && previousMultiTouchPanPosition && multiTouchPanPosition) {\r\n const moveDeltaX = multiTouchPanPosition.x - previousMultiTouchPanPosition.x;\r\n const moveDeltaY = multiTouchPanPosition.y - previousMultiTouchPanPosition.y;\r\n this.camera.inertialPanningX += -moveDeltaX / this.panningSensibility;\r\n this.camera.inertialPanningY += moveDeltaY / this.panningSensibility;\r\n }\r\n }\r\n\r\n /**\r\n * Move camera from pinch zoom distances.\r\n * @param previousPinchSquaredDistance\r\n * @param pinchSquaredDistance\r\n */\r\n private _computePinchZoom(previousPinchSquaredDistance: number, pinchSquaredDistance: number): void {\r\n const radius = this.camera.radius || ArcRotateCameraPointersInput.MinimumRadiusForPinch;\r\n if (this.useNaturalPinchZoom) {\r\n this.camera.radius = (radius * Math.sqrt(previousPinchSquaredDistance)) / Math.sqrt(pinchSquaredDistance);\r\n } else if (this.pinchDeltaPercentage) {\r\n this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchSquaredDistance) * 0.001 * radius * this.pinchDeltaPercentage;\r\n } else {\r\n this.camera.inertialRadiusOffset +=\r\n (pinchSquaredDistance - previousPinchSquaredDistance) /\r\n ((this.pinchPrecision * (this.pinchInwards ? 1 : -1) * (this.angularSensibilityX + this.angularSensibilityY)) / 2);\r\n }\r\n }\r\n\r\n /**\r\n * Called on pointer POINTERMOVE event if only a single touch is active.\r\n * @param point\r\n * @param offsetX\r\n * @param offsetY\r\n */\r\n public onTouch(point: Nullable, offsetX: number, offsetY: number): void {\r\n if (this.panningSensibility !== 0 && ((this._ctrlKey && this.camera._useCtrlForPanning) || this._isPanClick)) {\r\n this.camera.inertialPanningX += -offsetX / this.panningSensibility;\r\n this.camera.inertialPanningY += offsetY / this.panningSensibility;\r\n } else {\r\n this.camera.inertialAlphaOffset -= offsetX / this.angularSensibilityX;\r\n this.camera.inertialBetaOffset -= offsetY / this.angularSensibilityY;\r\n }\r\n }\r\n\r\n /**\r\n * Called on pointer POINTERDOUBLETAP event.\r\n */\r\n public onDoubleTap() {\r\n if (this.camera.useInputToRestoreState) {\r\n this.camera.restoreState();\r\n }\r\n }\r\n\r\n /**\r\n * Called on pointer POINTERMOVE event if multiple touches are active.\r\n * @param pointA\r\n * @param pointB\r\n * @param previousPinchSquaredDistance\r\n * @param pinchSquaredDistance\r\n * @param previousMultiTouchPanPosition\r\n * @param multiTouchPanPosition\r\n */\r\n public onMultiTouch(\r\n pointA: Nullable,\r\n pointB: Nullable,\r\n previousPinchSquaredDistance: number,\r\n pinchSquaredDistance: number,\r\n previousMultiTouchPanPosition: Nullable,\r\n multiTouchPanPosition: Nullable\r\n ): void {\r\n if (previousPinchSquaredDistance === 0 && previousMultiTouchPanPosition === null) {\r\n // First time this method is called for new pinch.\r\n // Next time this is called there will be a\r\n // previousPinchSquaredDistance and pinchSquaredDistance to compare.\r\n return;\r\n }\r\n if (pinchSquaredDistance === 0 && multiTouchPanPosition === null) {\r\n // Last time this method is called at the end of a pinch.\r\n return;\r\n }\r\n\r\n // Zoom and panning enabled together\r\n if (this.multiTouchPanAndZoom) {\r\n this._computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance);\r\n this._computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition);\r\n\r\n // Zoom and panning enabled but only one at a time\r\n } else if (this.multiTouchPanning && this.pinchZoom) {\r\n this._twoFingerActivityCount++;\r\n\r\n if (\r\n this._isPinching ||\r\n (this._twoFingerActivityCount < 20 && Math.abs(Math.sqrt(pinchSquaredDistance) - Math.sqrt(previousPinchSquaredDistance)) > this.camera.pinchToPanMaxDistance)\r\n ) {\r\n // Since pinch has not been active long, assume we intend to zoom.\r\n this._computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance);\r\n\r\n // Since we are pinching, remain pinching on next iteration.\r\n this._isPinching = true;\r\n } else {\r\n // Pause between pinch starting and moving implies not a zoom event. Pan instead.\r\n this._computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition);\r\n }\r\n\r\n // Panning enabled, zoom disabled\r\n } else if (this.multiTouchPanning) {\r\n this._computeMultiTouchPanning(previousMultiTouchPanPosition, multiTouchPanPosition);\r\n\r\n // Zoom enabled, panning disabled\r\n } else if (this.pinchZoom) {\r\n this._computePinchZoom(previousPinchSquaredDistance, pinchSquaredDistance);\r\n }\r\n }\r\n\r\n /**\r\n * Called each time a new POINTERDOWN event occurs. Ie, for each button\r\n * press.\r\n * @param evt\r\n */\r\n public onButtonDown(evt: IPointerEvent): void {\r\n this._isPanClick = evt.button === this.camera._panningMouseButton;\r\n }\r\n\r\n /**\r\n * Called each time a new POINTERUP event occurs. Ie, for each button\r\n * release.\r\n */\r\n public onButtonUp(): void {\r\n this._twoFingerActivityCount = 0;\r\n this._isPinching = false;\r\n }\r\n\r\n /**\r\n * Called when window becomes inactive.\r\n */\r\n public onLostFocus(): void {\r\n this._isPanClick = false;\r\n this._twoFingerActivityCount = 0;\r\n this._isPinching = false;\r\n }\r\n}\r\n(CameraInputTypes)[\"ArcRotateCameraPointersInput\"] = ArcRotateCameraPointersInput;\r\n","import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { KeyboardInfo } from \"../../Events/keyboardEvents\";\r\nimport { KeyboardEventTypes } from \"../../Events/keyboardEvents\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Manage the keyboard inputs to control the movement of an arc rotate camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraKeyboardMoveInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: ArcRotateCamera;\r\n\r\n /**\r\n * Defines the list of key codes associated with the up action (increase alpha)\r\n */\r\n @serialize()\r\n public keysUp = [38];\r\n\r\n /**\r\n * Defines the list of key codes associated with the down action (decrease alpha)\r\n */\r\n @serialize()\r\n public keysDown = [40];\r\n\r\n /**\r\n * Defines the list of key codes associated with the left action (increase beta)\r\n */\r\n @serialize()\r\n public keysLeft = [37];\r\n\r\n /**\r\n * Defines the list of key codes associated with the right action (decrease beta)\r\n */\r\n @serialize()\r\n public keysRight = [39];\r\n\r\n /**\r\n * Defines the list of key codes associated with the reset action.\r\n * Those keys reset the camera to its last stored state (with the method camera.storeState())\r\n */\r\n @serialize()\r\n public keysReset = [220];\r\n\r\n /**\r\n * Defines the panning sensibility of the inputs.\r\n * (How fast is the camera panning)\r\n */\r\n @serialize()\r\n public panningSensibility: number = 50.0;\r\n\r\n /**\r\n * Defines the zooming sensibility of the inputs.\r\n * (How fast is the camera zooming)\r\n */\r\n @serialize()\r\n public zoomingSensibility: number = 25.0;\r\n\r\n /**\r\n * Defines whether maintaining the alt key down switch the movement mode from\r\n * orientation to zoom.\r\n */\r\n @serialize()\r\n public useAltToZoom: boolean = true;\r\n\r\n /**\r\n * Rotation speed of the camera\r\n */\r\n @serialize()\r\n public angularSpeed = 0.01;\r\n\r\n private _keys = new Array();\r\n private _ctrlPressed: boolean;\r\n private _altPressed: boolean;\r\n private _onCanvasBlurObserver: Nullable>;\r\n private _onKeyboardObserver: Nullable>;\r\n private _engine: Engine;\r\n private _scene: Scene;\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // was there a second variable defined?\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n\r\n if (this._onCanvasBlurObserver) {\r\n return;\r\n }\r\n\r\n this._scene = this.camera.getScene();\r\n this._engine = this._scene.getEngine();\r\n\r\n this._onCanvasBlurObserver = this._engine.onCanvasBlurObservable.add(() => {\r\n this._keys.length = 0;\r\n });\r\n\r\n this._onKeyboardObserver = this._scene.onKeyboardObservable.add((info) => {\r\n const evt = info.event;\r\n if (!evt.metaKey) {\r\n if (info.type === KeyboardEventTypes.KEYDOWN) {\r\n this._ctrlPressed = evt.ctrlKey;\r\n this._altPressed = evt.altKey;\r\n\r\n if (\r\n this.keysUp.indexOf(evt.keyCode) !== -1 ||\r\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\r\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\r\n this.keysReset.indexOf(evt.keyCode) !== -1\r\n ) {\r\n const index = this._keys.indexOf(evt.keyCode);\r\n\r\n if (index === -1) {\r\n this._keys.push(evt.keyCode);\r\n }\r\n\r\n if (evt.preventDefault) {\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n }\r\n }\r\n } else {\r\n if (\r\n this.keysUp.indexOf(evt.keyCode) !== -1 ||\r\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\r\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\r\n this.keysReset.indexOf(evt.keyCode) !== -1\r\n ) {\r\n const index = this._keys.indexOf(evt.keyCode);\r\n\r\n if (index >= 0) {\r\n this._keys.splice(index, 1);\r\n }\r\n\r\n if (evt.preventDefault) {\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._scene) {\r\n if (this._onKeyboardObserver) {\r\n this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);\r\n }\r\n if (this._onCanvasBlurObserver) {\r\n this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);\r\n }\r\n this._onKeyboardObserver = null;\r\n this._onCanvasBlurObserver = null;\r\n }\r\n\r\n this._keys.length = 0;\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (this._onKeyboardObserver) {\r\n const camera = this.camera;\r\n\r\n for (let index = 0; index < this._keys.length; index++) {\r\n const keyCode = this._keys[index];\r\n if (this.keysLeft.indexOf(keyCode) !== -1) {\r\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\r\n camera.inertialPanningX -= 1 / this.panningSensibility;\r\n } else {\r\n camera.inertialAlphaOffset -= this.angularSpeed;\r\n }\r\n } else if (this.keysUp.indexOf(keyCode) !== -1) {\r\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\r\n camera.inertialPanningY += 1 / this.panningSensibility;\r\n } else if (this._altPressed && this.useAltToZoom) {\r\n camera.inertialRadiusOffset += 1 / this.zoomingSensibility;\r\n } else {\r\n camera.inertialBetaOffset -= this.angularSpeed;\r\n }\r\n } else if (this.keysRight.indexOf(keyCode) !== -1) {\r\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\r\n camera.inertialPanningX += 1 / this.panningSensibility;\r\n } else {\r\n camera.inertialAlphaOffset += this.angularSpeed;\r\n }\r\n } else if (this.keysDown.indexOf(keyCode) !== -1) {\r\n if (this._ctrlPressed && this.camera._useCtrlForPanning) {\r\n camera.inertialPanningY -= 1 / this.panningSensibility;\r\n } else if (this._altPressed && this.useAltToZoom) {\r\n camera.inertialRadiusOffset -= 1 / this.zoomingSensibility;\r\n } else {\r\n camera.inertialBetaOffset += this.angularSpeed;\r\n }\r\n } else if (this.keysReset.indexOf(keyCode) !== -1) {\r\n if (camera.useInputToRestoreState) {\r\n camera.restoreState();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCameraKeyboardMoveInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"keyboard\";\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"ArcRotateCameraKeyboardMoveInput\"] = ArcRotateCameraKeyboardMoveInput;\r\n","import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { EventState, Observer } from \"../../Misc/observable\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { Plane } from \"../../Maths/math.plane\";\r\nimport { Vector3, Matrix, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Epsilon } from \"../../Maths/math.constants\";\r\nimport type { IWheelEvent } from \"../../Events/deviceInputEvents\";\r\nimport { EventConstants } from \"../../Events/deviceInputEvents\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Firefox uses a different scheme to report scroll distances to other\r\n * browsers. Rather than use complicated methods to calculate the exact\r\n * multiple we need to apply, let's just cheat and use a constant.\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode\r\n * https://stackoverflow.com/questions/20110224/what-is-the-height-of-a-line-in-a-wheel-event-deltamode-dom-delta-line\r\n */\r\nconst ffMultiplier = 40;\r\n\r\n/**\r\n * Manage the mouse wheel inputs to control an arc rotate camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraMouseWheelInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: ArcRotateCamera;\r\n\r\n /**\r\n * Gets or Set the mouse wheel precision or how fast is the camera zooming.\r\n */\r\n @serialize()\r\n public wheelPrecision = 3.0;\r\n\r\n /**\r\n * Gets or Set the boolean value that controls whether or not the mouse wheel\r\n * zooms to the location of the mouse pointer or not. The default is false.\r\n */\r\n @serialize()\r\n public zoomToMouseLocation = false;\r\n\r\n /**\r\n * wheelDeltaPercentage will be used instead of wheelPrecision if different from 0.\r\n * It defines the percentage of current camera.radius to use as delta when wheel is used.\r\n */\r\n @serialize()\r\n public wheelDeltaPercentage = 0;\r\n\r\n /**\r\n * If set, this function will be used to set the radius delta that will be added to the current camera radius\r\n */\r\n public customComputeDeltaFromMouseWheel: Nullable<(wheelDelta: number, input: ArcRotateCameraMouseWheelInput, event: IWheelEvent) => number> = null;\r\n\r\n private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;\r\n private _observer: Nullable>;\r\n private _hitPlane: Nullable;\r\n\r\n protected _computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta: number, radius: number) {\r\n let delta = 0;\r\n const wheelDelta = mouseWheelDelta * 0.01 * this.wheelDeltaPercentage * radius;\r\n if (mouseWheelDelta > 0) {\r\n delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);\r\n } else {\r\n delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);\r\n }\r\n return delta;\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n this._wheel = (p) => {\r\n //sanity check - this should be a PointerWheel event.\r\n if (p.type !== PointerEventTypes.POINTERWHEEL) {\r\n return;\r\n }\r\n const event = p.event;\r\n let delta = 0;\r\n const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly\r\n\r\n const wheelDelta = -(event.deltaY * platformScale);\r\n\r\n if (this.customComputeDeltaFromMouseWheel) {\r\n delta = this.customComputeDeltaFromMouseWheel(wheelDelta, this, event);\r\n } else {\r\n if (this.wheelDeltaPercentage) {\r\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, this.camera.radius);\r\n\r\n // If zooming in, estimate the target radius and use that to compute the delta for inertia\r\n // this will stop multiple scroll events zooming in from adding too much inertia\r\n if (delta > 0) {\r\n let estimatedTargetRadius = this.camera.radius;\r\n let targetInertia = this.camera.inertialRadiusOffset + delta;\r\n for (let i = 0; i < 20 && Math.abs(targetInertia) > 0.001; i++) {\r\n estimatedTargetRadius -= targetInertia;\r\n targetInertia *= this.camera.inertia;\r\n }\r\n estimatedTargetRadius = Scalar.Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);\r\n delta = this._computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);\r\n }\r\n } else {\r\n delta = wheelDelta / (this.wheelPrecision * 40);\r\n }\r\n }\r\n\r\n if (delta) {\r\n if (this.zoomToMouseLocation) {\r\n // If we are zooming to the mouse location, then we need to get the hit plane at the start of the zoom gesture if it doesn't exist\r\n // The hit plane is normally calculated after the first motion and each time there's motion so if we don't do this first,\r\n // the first zoom will be to the center of the screen\r\n if (!this._hitPlane) {\r\n this._updateHitPlane();\r\n }\r\n\r\n this._zoomToMouse(delta);\r\n } else {\r\n this.camera.inertialRadiusOffset += delta;\r\n }\r\n }\r\n\r\n if (event.preventDefault) {\r\n if (!noPreventDefault) {\r\n event.preventDefault();\r\n }\r\n }\r\n };\r\n\r\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel, PointerEventTypes.POINTERWHEEL);\r\n\r\n if (this.zoomToMouseLocation) {\r\n this._inertialPanning.setAll(0);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n this._observer = null;\r\n this._wheel = null;\r\n }\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (!this.zoomToMouseLocation) {\r\n return;\r\n }\r\n\r\n const camera = this.camera;\r\n const motion = 0.0 + camera.inertialAlphaOffset + camera.inertialBetaOffset + camera.inertialRadiusOffset;\r\n if (motion) {\r\n // if zooming is still happening as a result of inertia, then we also need to update\r\n // the hit plane.\r\n this._updateHitPlane();\r\n\r\n // Note we cannot use arcRotateCamera.inertialPlanning here because arcRotateCamera panning\r\n // uses a different panningInertia which could cause this panning to get out of sync with\r\n // the zooming, and for this to work they must be exactly in sync.\r\n camera.target.addInPlace(this._inertialPanning);\r\n this._inertialPanning.scaleInPlace(camera.inertia);\r\n this._zeroIfClose(this._inertialPanning);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCameraMouseWheelInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"mousewheel\";\r\n }\r\n\r\n private _updateHitPlane() {\r\n const camera = this.camera;\r\n const direction = camera.target.subtract(camera.position);\r\n this._hitPlane = Plane.FromPositionAndNormal(camera.target, direction);\r\n }\r\n\r\n // Get position on the hit plane\r\n private _getPosition(): Vector3 {\r\n const camera = this.camera;\r\n const scene = camera.getScene();\r\n\r\n // since the _hitPlane is always updated to be orthogonal to the camera position vector\r\n // we don't have to worry about this ray shooting off to infinity. This ray creates\r\n // a vector defining where we want to zoom to.\r\n const ray = scene.createPickingRay(scene.pointerX, scene.pointerY, Matrix.Identity(), camera, false);\r\n // Since the camera is the origin of the picking ray, we need to offset it by the camera's offset manually\r\n ray.origin.x -= camera.targetScreenOffset.x;\r\n ray.origin.y -= camera.targetScreenOffset.y;\r\n let distance = 0;\r\n if (this._hitPlane) {\r\n distance = ray.intersectsPlane(this._hitPlane) ?? 0;\r\n }\r\n\r\n // not using this ray again, so modifying its vectors here is fine\r\n return ray.origin.addInPlace(ray.direction.scaleInPlace(distance));\r\n }\r\n\r\n private _inertialPanning: Vector3 = Vector3.Zero();\r\n\r\n private _zoomToMouse(delta: number) {\r\n const camera = this.camera;\r\n const inertiaComp = 1 - camera.inertia;\r\n if (camera.lowerRadiusLimit) {\r\n const lowerLimit = camera.lowerRadiusLimit ?? 0;\r\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp < lowerLimit) {\r\n delta = (camera.radius - lowerLimit) * inertiaComp - camera.inertialRadiusOffset;\r\n }\r\n }\r\n if (camera.upperRadiusLimit) {\r\n const upperLimit = camera.upperRadiusLimit ?? 0;\r\n if (camera.radius - (camera.inertialRadiusOffset + delta) / inertiaComp > upperLimit) {\r\n delta = (camera.radius - upperLimit) * inertiaComp - camera.inertialRadiusOffset;\r\n }\r\n }\r\n\r\n const zoomDistance = delta / inertiaComp;\r\n const ratio = zoomDistance / camera.radius;\r\n const vec = this._getPosition();\r\n\r\n // Now this vector tells us how much we also need to pan the camera\r\n // so the targeted mouse location becomes the center of zooming.\r\n\r\n const directionToZoomLocation = TmpVectors.Vector3[6];\r\n vec.subtractToRef(camera.target, directionToZoomLocation);\r\n directionToZoomLocation.scaleInPlace(ratio);\r\n directionToZoomLocation.scaleInPlace(inertiaComp);\r\n this._inertialPanning.addInPlace(directionToZoomLocation);\r\n\r\n camera.inertialRadiusOffset += delta;\r\n }\r\n\r\n // Sets x y or z of passed in vector to zero if less than Epsilon.\r\n private _zeroIfClose(vec: Vector3) {\r\n if (Math.abs(vec.x) < Epsilon) {\r\n vec.x = 0;\r\n }\r\n if (Math.abs(vec.y) < Epsilon) {\r\n vec.y = 0;\r\n }\r\n if (Math.abs(vec.z) < Epsilon) {\r\n vec.z = 0;\r\n }\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"ArcRotateCameraMouseWheelInput\"] = ArcRotateCameraMouseWheelInput;\r\n","import type { ArcRotateCamera } from \"./arcRotateCamera\";\r\nimport { ArcRotateCameraPointersInput } from \"../Cameras/Inputs/arcRotateCameraPointersInput\";\r\nimport { ArcRotateCameraKeyboardMoveInput } from \"../Cameras/Inputs/arcRotateCameraKeyboardMoveInput\";\r\nimport { ArcRotateCameraMouseWheelInput } from \"../Cameras/Inputs/arcRotateCameraMouseWheelInput\";\r\nimport { CameraInputsManager } from \"../Cameras/cameraInputsManager\";\r\n\r\n/**\r\n * Default Inputs manager for the ArcRotateCamera.\r\n * It groups all the default supported inputs for ease of use.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraInputsManager extends CameraInputsManager {\r\n /**\r\n * Instantiates a new ArcRotateCameraInputsManager.\r\n * @param camera Defines the camera the inputs belong to\r\n */\r\n constructor(camera: ArcRotateCamera) {\r\n super(camera);\r\n }\r\n\r\n /**\r\n * Add mouse wheel input support to the input manager.\r\n * @returns the current input manager\r\n */\r\n public addMouseWheel(): ArcRotateCameraInputsManager {\r\n this.add(new ArcRotateCameraMouseWheelInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Add pointers input support to the input manager.\r\n * @returns the current input manager\r\n */\r\n public addPointers(): ArcRotateCameraInputsManager {\r\n this.add(new ArcRotateCameraPointersInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Add keyboard input support to the input manager.\r\n * @returns the current input manager\r\n */\r\n public addKeyboard(): ArcRotateCameraInputsManager {\r\n this.add(new ArcRotateCameraKeyboardMoveInput());\r\n return this;\r\n }\r\n}\r\n","import { serialize, serializeAsVector3, serializeAsMeshReference, serializeAsVector2 } from \"../Misc/decorators\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { AutoRotationBehavior } from \"../Behaviors/Cameras/autoRotationBehavior\";\r\nimport { BouncingBehavior } from \"../Behaviors/Cameras/bouncingBehavior\";\r\nimport { FramingBehavior } from \"../Behaviors/Cameras/framingBehavior\";\r\nimport { Camera } from \"./camera\";\r\nimport { TargetCamera } from \"./targetCamera\";\r\nimport type { ArcRotateCameraPointersInput } from \"../Cameras/Inputs/arcRotateCameraPointersInput\";\r\nimport type { ArcRotateCameraKeyboardMoveInput } from \"../Cameras/Inputs/arcRotateCameraKeyboardMoveInput\";\r\nimport type { ArcRotateCameraMouseWheelInput } from \"../Cameras/Inputs/arcRotateCameraMouseWheelInput\";\r\nimport { ArcRotateCameraInputsManager } from \"../Cameras/arcRotateCameraInputsManager\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\nimport type { Collider } from \"../Collisions/collider\";\r\n\r\nNode.AddNodeConstructor(\"ArcRotateCamera\", (name, scene) => {\r\n return () => new ArcRotateCamera(name, 0, 0, 1.0, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * This represents an orbital type of camera.\r\n *\r\n * This camera always points towards a given target position and can be rotated around that target with the target as the centre of rotation. It can be controlled with cursors and mouse, or with touch events.\r\n * Think of this camera as one orbiting its target position, or more imaginatively as a spy satellite orbiting the earth. Its position relative to the target (earth) can be set by three parameters, alpha (radians) the longitudinal rotation, beta (radians) the latitudinal rotation and radius the distance from the target position.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#arc-rotate-camera\r\n */\r\nexport class ArcRotateCamera extends TargetCamera {\r\n /**\r\n * Defines the rotation angle of the camera along the longitudinal axis.\r\n */\r\n @serialize()\r\n public alpha: number;\r\n\r\n /**\r\n * Defines the rotation angle of the camera along the latitudinal axis.\r\n */\r\n @serialize()\r\n public beta: number;\r\n\r\n /**\r\n * Defines the radius of the camera from it s target point.\r\n */\r\n @serialize()\r\n public radius: number;\r\n\r\n /**\r\n * Defines an override value to use as the parameter to setTarget.\r\n * This allows the parameter to be specified when animating the target (e.g. using FramingBehavior).\r\n */\r\n @serialize()\r\n public overrideCloneAlphaBetaRadius: Nullable;\r\n\r\n @serializeAsVector3(\"target\")\r\n protected _target: Vector3;\r\n @serializeAsMeshReference(\"targetHost\")\r\n protected _targetHost: Nullable;\r\n\r\n /**\r\n * Defines the target point of the camera.\r\n * The camera looks towards it from the radius distance.\r\n */\r\n public get target(): Vector3 {\r\n return this._target;\r\n }\r\n public set target(value: Vector3) {\r\n this.setTarget(value);\r\n }\r\n\r\n /**\r\n * Defines the target mesh of the camera.\r\n * The camera looks towards it from the radius distance.\r\n * Please note that setting a target host will disable panning.\r\n */\r\n public get targetHost(): Nullable {\r\n return this._targetHost;\r\n }\r\n public set targetHost(value: Nullable) {\r\n if (value) {\r\n this.setTarget(value);\r\n }\r\n }\r\n\r\n /**\r\n * Return the current target position of the camera. This value is expressed in local space.\r\n * @returns the target position\r\n */\r\n public getTarget(): Vector3 {\r\n return this.target;\r\n }\r\n\r\n /**\r\n * Define the current local position of the camera in the scene\r\n */\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n\r\n public set position(newPosition: Vector3) {\r\n this.setPosition(newPosition);\r\n }\r\n\r\n protected _upToYMatrix: Matrix;\r\n protected _yToUpMatrix: Matrix;\r\n\r\n /**\r\n * The vector the camera should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up())\r\n * Setting this will copy the given vector to the camera's upVector, and set rotation matrices to and from Y up.\r\n * DO NOT set the up vector using copyFrom or copyFromFloats, as this bypasses setting the above matrices.\r\n */\r\n set upVector(vec: Vector3) {\r\n if (!this._upToYMatrix) {\r\n this._yToUpMatrix = new Matrix();\r\n this._upToYMatrix = new Matrix();\r\n\r\n this._upVector = Vector3.Zero();\r\n }\r\n\r\n vec.normalize();\r\n this._upVector.copyFrom(vec);\r\n this.setMatUp();\r\n }\r\n\r\n get upVector() {\r\n return this._upVector;\r\n }\r\n\r\n /**\r\n * Sets the Y-up to camera up-vector rotation matrix, and the up-vector to Y-up rotation matrix.\r\n */\r\n public setMatUp() {\r\n // from y-up to custom-up (used in _getViewMatrix)\r\n Matrix.RotationAlignToRef(Vector3.UpReadOnly, this._upVector, this._yToUpMatrix);\r\n\r\n // from custom-up to y-up (used in rebuildAnglesAndRadius)\r\n Matrix.RotationAlignToRef(this._upVector, Vector3.UpReadOnly, this._upToYMatrix);\r\n }\r\n\r\n /**\r\n * Current inertia value on the longitudinal axis.\r\n * The bigger this number the longer it will take for the camera to stop.\r\n */\r\n @serialize()\r\n public inertialAlphaOffset = 0;\r\n\r\n /**\r\n * Current inertia value on the latitudinal axis.\r\n * The bigger this number the longer it will take for the camera to stop.\r\n */\r\n @serialize()\r\n public inertialBetaOffset = 0;\r\n\r\n /**\r\n * Current inertia value on the radius axis.\r\n * The bigger this number the longer it will take for the camera to stop.\r\n */\r\n @serialize()\r\n public inertialRadiusOffset = 0;\r\n\r\n /**\r\n * Minimum allowed angle on the longitudinal axis.\r\n * This can help limiting how the Camera is able to move in the scene.\r\n */\r\n @serialize()\r\n public lowerAlphaLimit: Nullable = null;\r\n\r\n /**\r\n * Maximum allowed angle on the longitudinal axis.\r\n * This can help limiting how the Camera is able to move in the scene.\r\n */\r\n @serialize()\r\n public upperAlphaLimit: Nullable = null;\r\n\r\n /**\r\n * Minimum allowed angle on the latitudinal axis.\r\n * This can help limiting how the Camera is able to move in the scene.\r\n */\r\n @serialize()\r\n public lowerBetaLimit: Nullable = 0.01;\r\n\r\n /**\r\n * Maximum allowed angle on the latitudinal axis.\r\n * This can help limiting how the Camera is able to move in the scene.\r\n */\r\n @serialize()\r\n public upperBetaLimit: Nullable = Math.PI - 0.01;\r\n\r\n /**\r\n * Minimum allowed distance of the camera to the target (The camera can not get closer).\r\n * This can help limiting how the Camera is able to move in the scene.\r\n */\r\n @serialize()\r\n public lowerRadiusLimit: Nullable = null;\r\n\r\n /**\r\n * Maximum allowed distance of the camera to the target (The camera can not get further).\r\n * This can help limiting how the Camera is able to move in the scene.\r\n */\r\n @serialize()\r\n public upperRadiusLimit: Nullable = null;\r\n\r\n /**\r\n * Defines the current inertia value used during panning of the camera along the X axis.\r\n */\r\n @serialize()\r\n public inertialPanningX: number = 0;\r\n\r\n /**\r\n * Defines the current inertia value used during panning of the camera along the Y axis.\r\n */\r\n @serialize()\r\n public inertialPanningY: number = 0;\r\n\r\n /**\r\n * Defines the distance used to consider the camera in pan mode vs pinch/zoom.\r\n * Basically if your fingers moves away from more than this distance you will be considered\r\n * in pinch mode.\r\n */\r\n @serialize()\r\n public pinchToPanMaxDistance: number = 20;\r\n\r\n /**\r\n * Defines the maximum distance the camera can pan.\r\n * This could help keeping the camera always in your scene.\r\n */\r\n @serialize()\r\n public panningDistanceLimit: Nullable = null;\r\n\r\n /**\r\n * Defines the target of the camera before panning.\r\n */\r\n @serializeAsVector3()\r\n public panningOriginTarget: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * Defines the value of the inertia used during panning.\r\n * 0 would mean stop inertia and one would mean no deceleration at all.\r\n */\r\n @serialize()\r\n public panningInertia = 0.9;\r\n\r\n //-- begin properties for backward compatibility for inputs\r\n\r\n /**\r\n * Gets or Set the pointer angular sensibility along the X axis or how fast is the camera rotating.\r\n */\r\n public get angularSensibilityX(): number {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n return pointers.angularSensibilityX;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set angularSensibilityX(value: number) {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n pointers.angularSensibilityX = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the pointer angular sensibility along the Y axis or how fast is the camera rotating.\r\n */\r\n public get angularSensibilityY(): number {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n return pointers.angularSensibilityY;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set angularSensibilityY(value: number) {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n pointers.angularSensibilityY = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the pointer pinch precision or how fast is the camera zooming.\r\n */\r\n public get pinchPrecision(): number {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n return pointers.pinchPrecision;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set pinchPrecision(value: number) {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n pointers.pinchPrecision = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the pointer pinch delta percentage or how fast is the camera zooming.\r\n * It will be used instead of pinchDeltaPrecision if different from 0.\r\n * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.\r\n */\r\n public get pinchDeltaPercentage(): number {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n return pointers.pinchDeltaPercentage;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set pinchDeltaPercentage(value: number) {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n pointers.pinchDeltaPercentage = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the pointer use natural pinch zoom to override the pinch precision\r\n * and pinch delta percentage.\r\n * When useNaturalPinchZoom is true, multi touch zoom will zoom in such\r\n * that any object in the plane at the camera's target point will scale\r\n * perfectly with finger motion.\r\n */\r\n public get useNaturalPinchZoom(): boolean {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n return pointers.useNaturalPinchZoom;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public set useNaturalPinchZoom(value: boolean) {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n pointers.useNaturalPinchZoom = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the pointer panning sensibility or how fast is the camera moving.\r\n */\r\n public get panningSensibility(): number {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n return pointers.panningSensibility;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set panningSensibility(value: number) {\r\n const pointers = this.inputs.attached[\"pointers\"];\r\n if (pointers) {\r\n pointers.panningSensibility = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control beta angle in a positive direction.\r\n */\r\n public get keysUp(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysUp;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysUp(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysUp = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control beta angle in a negative direction.\r\n */\r\n public get keysDown(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysDown;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysDown(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysDown = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control alpha angle in a negative direction.\r\n */\r\n public get keysLeft(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysLeft;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysLeft(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysLeft = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control alpha angle in a positive direction.\r\n */\r\n public get keysRight(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysRight;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysRight(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysRight = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the mouse wheel precision or how fast is the camera zooming.\r\n */\r\n public get wheelPrecision(): number {\r\n const mousewheel = this.inputs.attached[\"mousewheel\"];\r\n if (mousewheel) {\r\n return mousewheel.wheelPrecision;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set wheelPrecision(value: number) {\r\n const mousewheel = this.inputs.attached[\"mousewheel\"];\r\n if (mousewheel) {\r\n mousewheel.wheelPrecision = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the boolean value that controls whether or not the mouse wheel\r\n * zooms to the location of the mouse pointer or not. The default is false.\r\n */\r\n @serialize()\r\n public get zoomToMouseLocation(): boolean {\r\n const mousewheel = this.inputs.attached[\"mousewheel\"];\r\n if (mousewheel) {\r\n return mousewheel.zoomToMouseLocation;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public set zoomToMouseLocation(value: boolean) {\r\n const mousewheel = this.inputs.attached[\"mousewheel\"];\r\n if (mousewheel) {\r\n mousewheel.zoomToMouseLocation = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the mouse wheel delta percentage or how fast is the camera zooming.\r\n * It will be used instead of pinchDeltaPrecision if different from 0.\r\n * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.\r\n */\r\n public get wheelDeltaPercentage(): number {\r\n const mousewheel = this.inputs.attached[\"mousewheel\"];\r\n if (mousewheel) {\r\n return mousewheel.wheelDeltaPercentage;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set wheelDeltaPercentage(value: number) {\r\n const mousewheel = this.inputs.attached[\"mousewheel\"];\r\n if (mousewheel) {\r\n mousewheel.wheelDeltaPercentage = value;\r\n }\r\n }\r\n\r\n //-- end properties for backward compatibility for inputs\r\n\r\n /**\r\n * Defines how much the radius should be scaled while zooming on a particular mesh (through the zoomOn function)\r\n */\r\n @serialize()\r\n public zoomOnFactor = 1;\r\n\r\n /**\r\n * Defines a screen offset for the camera position.\r\n */\r\n @serializeAsVector2()\r\n public targetScreenOffset = Vector2.Zero();\r\n\r\n /**\r\n * Allows the camera to be completely reversed.\r\n * If false the camera can not arrive upside down.\r\n */\r\n @serialize()\r\n public allowUpsideDown = true;\r\n\r\n /**\r\n * Define if double tap/click is used to restore the previously saved state of the camera.\r\n */\r\n @serialize()\r\n public useInputToRestoreState = true;\r\n\r\n /** @internal */\r\n public _viewMatrix = new Matrix();\r\n /** @internal */\r\n public _useCtrlForPanning: boolean;\r\n /** @internal */\r\n public _panningMouseButton: number;\r\n\r\n /**\r\n * Defines the input associated to the camera.\r\n */\r\n public inputs: ArcRotateCameraInputsManager;\r\n\r\n /** @internal */\r\n public _reset: () => void;\r\n\r\n /**\r\n * Defines the allowed panning axis.\r\n */\r\n public panningAxis: Vector3 = new Vector3(1, 1, 0);\r\n protected _transformedDirection: Vector3 = new Vector3();\r\n\r\n /**\r\n * Defines if camera will eliminate transform on y axis.\r\n */\r\n public mapPanning: boolean = false;\r\n\r\n // Behaviors\r\n private _bouncingBehavior: Nullable;\r\n\r\n /**\r\n * Gets the bouncing behavior of the camera if it has been enabled.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior\r\n */\r\n public get bouncingBehavior(): Nullable {\r\n return this._bouncingBehavior;\r\n }\r\n\r\n /**\r\n * Defines if the bouncing behavior of the camera is enabled on the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior\r\n */\r\n public get useBouncingBehavior(): boolean {\r\n return this._bouncingBehavior != null;\r\n }\r\n\r\n public set useBouncingBehavior(value: boolean) {\r\n if (value === this.useBouncingBehavior) {\r\n return;\r\n }\r\n\r\n if (value) {\r\n this._bouncingBehavior = new BouncingBehavior();\r\n this.addBehavior(this._bouncingBehavior);\r\n } else if (this._bouncingBehavior) {\r\n this.removeBehavior(this._bouncingBehavior);\r\n this._bouncingBehavior = null;\r\n }\r\n }\r\n\r\n private _framingBehavior: Nullable;\r\n\r\n /**\r\n * Gets the framing behavior of the camera if it has been enabled.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior\r\n */\r\n public get framingBehavior(): Nullable {\r\n return this._framingBehavior;\r\n }\r\n\r\n /**\r\n * Defines if the framing behavior of the camera is enabled on the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior\r\n */\r\n public get useFramingBehavior(): boolean {\r\n return this._framingBehavior != null;\r\n }\r\n\r\n public set useFramingBehavior(value: boolean) {\r\n if (value === this.useFramingBehavior) {\r\n return;\r\n }\r\n\r\n if (value) {\r\n this._framingBehavior = new FramingBehavior();\r\n this.addBehavior(this._framingBehavior);\r\n } else if (this._framingBehavior) {\r\n this.removeBehavior(this._framingBehavior);\r\n this._framingBehavior = null;\r\n }\r\n }\r\n\r\n private _autoRotationBehavior: Nullable;\r\n\r\n /**\r\n * Gets the auto rotation behavior of the camera if it has been enabled.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior\r\n */\r\n public get autoRotationBehavior(): Nullable {\r\n return this._autoRotationBehavior;\r\n }\r\n\r\n /**\r\n * Defines if the auto rotation behavior of the camera is enabled on the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior\r\n */\r\n public get useAutoRotationBehavior(): boolean {\r\n return this._autoRotationBehavior != null;\r\n }\r\n\r\n public set useAutoRotationBehavior(value: boolean) {\r\n if (value === this.useAutoRotationBehavior) {\r\n return;\r\n }\r\n\r\n if (value) {\r\n this._autoRotationBehavior = new AutoRotationBehavior();\r\n this.addBehavior(this._autoRotationBehavior);\r\n } else if (this._autoRotationBehavior) {\r\n this.removeBehavior(this._autoRotationBehavior);\r\n this._autoRotationBehavior = null;\r\n }\r\n }\r\n\r\n /**\r\n * Observable triggered when the mesh target has been changed on the camera.\r\n */\r\n public onMeshTargetChangedObservable = new Observable>();\r\n\r\n /**\r\n * Event raised when the camera is colliding with a mesh.\r\n */\r\n public onCollide: (collidedMesh: AbstractMesh) => void;\r\n\r\n /**\r\n * Defines whether the camera should check collision with the objects oh the scene.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#how-can-i-do-this-\r\n */\r\n public checkCollisions = false;\r\n\r\n /**\r\n * Defines the collision radius of the camera.\r\n * This simulates a sphere around the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#arcrotatecamera\r\n */\r\n public collisionRadius = new Vector3(0.5, 0.5, 0.5);\r\n\r\n protected _collider: Collider;\r\n protected _previousPosition = Vector3.Zero();\r\n protected _collisionVelocity = Vector3.Zero();\r\n protected _newPosition = Vector3.Zero();\r\n protected _previousAlpha: number;\r\n protected _previousBeta: number;\r\n protected _previousRadius: number;\r\n //due to async collision inspection\r\n protected _collisionTriggered: boolean;\r\n\r\n protected _targetBoundingCenter: Nullable;\r\n\r\n private _computationVector: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * Instantiates a new ArcRotateCamera in a given scene\r\n * @param name Defines the name of the camera\r\n * @param alpha Defines the camera rotation along the longitudinal axis\r\n * @param beta Defines the camera rotation along the latitudinal axis\r\n * @param radius Defines the camera distance from its target\r\n * @param target Defines the camera target\r\n * @param scene Defines the scene the camera belongs to\r\n * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined\r\n */\r\n constructor(name: string, alpha: number, beta: number, radius: number, target: Vector3, scene?: Scene, setActiveOnSceneIfNoneActive = true) {\r\n super(name, Vector3.Zero(), scene, setActiveOnSceneIfNoneActive);\r\n\r\n this._target = Vector3.Zero();\r\n if (target) {\r\n this.setTarget(target);\r\n }\r\n\r\n this.alpha = alpha;\r\n this.beta = beta;\r\n this.radius = radius;\r\n\r\n this.getViewMatrix();\r\n this.inputs = new ArcRotateCameraInputsManager(this);\r\n this.inputs.addKeyboard().addMouseWheel().addPointers();\r\n }\r\n\r\n // Cache\r\n /** @internal */\r\n public _initCache(): void {\r\n super._initCache();\r\n this._cache._target = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n this._cache.alpha = undefined;\r\n this._cache.beta = undefined;\r\n this._cache.radius = undefined;\r\n this._cache.targetScreenOffset = Vector2.Zero();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateCache(ignoreParentClass?: boolean): void {\r\n if (!ignoreParentClass) {\r\n super._updateCache();\r\n }\r\n\r\n this._cache._target.copyFrom(this._getTargetPosition());\r\n this._cache.alpha = this.alpha;\r\n this._cache.beta = this.beta;\r\n this._cache.radius = this.radius;\r\n this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset);\r\n }\r\n\r\n protected _getTargetPosition(): Vector3 {\r\n if (this._targetHost && this._targetHost.getAbsolutePosition) {\r\n const pos: Vector3 = this._targetHost.getAbsolutePosition();\r\n if (this._targetBoundingCenter) {\r\n pos.addToRef(this._targetBoundingCenter, this._target);\r\n } else {\r\n this._target.copyFrom(pos);\r\n }\r\n }\r\n\r\n const lockedTargetPosition = this._getLockedTargetPosition();\r\n\r\n if (lockedTargetPosition) {\r\n return lockedTargetPosition;\r\n }\r\n\r\n return this._target;\r\n }\r\n\r\n private _storedAlpha: number;\r\n private _storedBeta: number;\r\n private _storedRadius: number;\r\n private _storedTarget: Vector3;\r\n private _storedTargetScreenOffset: Vector2;\r\n\r\n /**\r\n * Stores the current state of the camera (alpha, beta, radius and target)\r\n * @returns the camera itself\r\n */\r\n public storeState(): Camera {\r\n this._storedAlpha = this.alpha;\r\n this._storedBeta = this.beta;\r\n this._storedRadius = this.radius;\r\n this._storedTarget = this._getTargetPosition().clone();\r\n this._storedTargetScreenOffset = this.targetScreenOffset.clone();\r\n\r\n return super.storeState();\r\n }\r\n\r\n /**\r\n * @internal\r\n * Restored camera state. You must call storeState() first\r\n */\r\n public _restoreStateValues(): boolean {\r\n if (!super._restoreStateValues()) {\r\n return false;\r\n }\r\n\r\n this.setTarget(this._storedTarget.clone());\r\n this.alpha = this._storedAlpha;\r\n this.beta = this._storedBeta;\r\n this.radius = this._storedRadius;\r\n this.targetScreenOffset = this._storedTargetScreenOffset.clone();\r\n\r\n this.inertialAlphaOffset = 0;\r\n this.inertialBetaOffset = 0;\r\n this.inertialRadiusOffset = 0;\r\n this.inertialPanningX = 0;\r\n this.inertialPanningY = 0;\r\n\r\n return true;\r\n }\r\n\r\n // Synchronized\r\n /** @internal */\r\n public _isSynchronizedViewMatrix(): boolean {\r\n if (!super._isSynchronizedViewMatrix()) {\r\n return false;\r\n }\r\n\r\n return (\r\n this._cache._target.equals(this._getTargetPosition()) &&\r\n this._cache.alpha === this.alpha &&\r\n this._cache.beta === this.beta &&\r\n this._cache.radius === this.radius &&\r\n this._cache.targetScreenOffset.equals(this.targetScreenOffset)\r\n );\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void;\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(ignored: any, noPreventDefault?: boolean): void;\r\n /**\r\n * Attached controls to the current camera.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls\r\n */\r\n public attachControl(noPreventDefault: boolean, useCtrlForPanning: boolean): void;\r\n /**\r\n * Attached controls to the current camera.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls\r\n */\r\n public attachControl(ignored: any, noPreventDefault: boolean, useCtrlForPanning: boolean): void;\r\n /**\r\n * Attached controls to the current camera.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls\r\n * @param panningMouseButton Defines whether panning is allowed through mouse click button\r\n */\r\n public attachControl(noPreventDefault: boolean, useCtrlForPanning: boolean, panningMouseButton: number): void;\r\n /**\r\n * Attached controls to the current camera.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls\r\n * @param panningMouseButton Defines whether panning is allowed through mouse click button\r\n */\r\n public attachControl(ignored: any, noPreventDefault?: boolean, useCtrlForPanning: boolean | number = true, panningMouseButton: number = 2): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n const args = arguments;\r\n\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(args);\r\n this._useCtrlForPanning = useCtrlForPanning as boolean;\r\n this._panningMouseButton = panningMouseButton;\r\n // backwards compatibility\r\n if (typeof args[0] === \"boolean\") {\r\n if (args.length > 1) {\r\n this._useCtrlForPanning = args[1];\r\n }\r\n if (args.length > 2) {\r\n this._panningMouseButton = args[2];\r\n }\r\n }\r\n\r\n this.inputs.attachElement(noPreventDefault);\r\n\r\n this._reset = () => {\r\n this.inertialAlphaOffset = 0;\r\n this.inertialBetaOffset = 0;\r\n this.inertialRadiusOffset = 0;\r\n this.inertialPanningX = 0;\r\n this.inertialPanningY = 0;\r\n };\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n this.inputs.detachElement();\r\n\r\n if (this._reset) {\r\n this._reset();\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _checkInputs(): void {\r\n //if (async) collision inspection was triggered, don't update the camera's position - until the collision callback was called.\r\n if (this._collisionTriggered) {\r\n return;\r\n }\r\n\r\n this.inputs.checkInputs();\r\n // Inertia\r\n if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {\r\n const directionModifier = this.invertRotation ? -1 : 1;\r\n let inertialAlphaOffset = this.inertialAlphaOffset;\r\n if (this.beta <= 0) {\r\n inertialAlphaOffset *= -1;\r\n }\r\n if (this.getScene().useRightHandedSystem) {\r\n inertialAlphaOffset *= -1;\r\n }\r\n if (this.parent && this.parent._getWorldMatrixDeterminant() < 0) {\r\n inertialAlphaOffset *= -1;\r\n }\r\n this.alpha += inertialAlphaOffset * directionModifier;\r\n\r\n this.beta += this.inertialBetaOffset * directionModifier;\r\n\r\n this.radius -= this.inertialRadiusOffset;\r\n this.inertialAlphaOffset *= this.inertia;\r\n this.inertialBetaOffset *= this.inertia;\r\n this.inertialRadiusOffset *= this.inertia;\r\n if (Math.abs(this.inertialAlphaOffset) < Epsilon) {\r\n this.inertialAlphaOffset = 0;\r\n }\r\n if (Math.abs(this.inertialBetaOffset) < Epsilon) {\r\n this.inertialBetaOffset = 0;\r\n }\r\n if (Math.abs(this.inertialRadiusOffset) < this.speed * Epsilon) {\r\n this.inertialRadiusOffset = 0;\r\n }\r\n }\r\n\r\n // Panning inertia\r\n if (this.inertialPanningX !== 0 || this.inertialPanningY !== 0) {\r\n const localDirection = new Vector3(this.inertialPanningX, this.inertialPanningY, this.inertialPanningY);\r\n\r\n this._viewMatrix.invertToRef(this._cameraTransformMatrix);\r\n localDirection.multiplyInPlace(this.panningAxis);\r\n Vector3.TransformNormalToRef(localDirection, this._cameraTransformMatrix, this._transformedDirection);\r\n // Eliminate y if mapPanning is enabled\r\n if (this.mapPanning || !this.panningAxis.y) {\r\n this._transformedDirection.y = 0;\r\n }\r\n\r\n if (!this._targetHost) {\r\n if (this.panningDistanceLimit) {\r\n this._transformedDirection.addInPlace(this._target);\r\n const distanceSquared = Vector3.DistanceSquared(this._transformedDirection, this.panningOriginTarget);\r\n if (distanceSquared <= this.panningDistanceLimit * this.panningDistanceLimit) {\r\n this._target.copyFrom(this._transformedDirection);\r\n }\r\n } else {\r\n this._target.addInPlace(this._transformedDirection);\r\n }\r\n }\r\n\r\n this.inertialPanningX *= this.panningInertia;\r\n this.inertialPanningY *= this.panningInertia;\r\n\r\n if (Math.abs(this.inertialPanningX) < this.speed * Epsilon) {\r\n this.inertialPanningX = 0;\r\n }\r\n if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) {\r\n this.inertialPanningY = 0;\r\n }\r\n }\r\n\r\n // Limits\r\n this._checkLimits();\r\n\r\n super._checkInputs();\r\n }\r\n\r\n protected _checkLimits() {\r\n if (this.lowerBetaLimit === null || this.lowerBetaLimit === undefined) {\r\n if (this.allowUpsideDown && this.beta > Math.PI) {\r\n this.beta = this.beta - 2 * Math.PI;\r\n }\r\n } else {\r\n if (this.beta < this.lowerBetaLimit) {\r\n this.beta = this.lowerBetaLimit;\r\n }\r\n }\r\n\r\n if (this.upperBetaLimit === null || this.upperBetaLimit === undefined) {\r\n if (this.allowUpsideDown && this.beta < -Math.PI) {\r\n this.beta = this.beta + 2 * Math.PI;\r\n }\r\n } else {\r\n if (this.beta > this.upperBetaLimit) {\r\n this.beta = this.upperBetaLimit;\r\n }\r\n }\r\n\r\n if (this.lowerAlphaLimit !== null && this.alpha < this.lowerAlphaLimit) {\r\n this.alpha = this.lowerAlphaLimit;\r\n }\r\n if (this.upperAlphaLimit !== null && this.alpha > this.upperAlphaLimit) {\r\n this.alpha = this.upperAlphaLimit;\r\n }\r\n\r\n if (this.lowerRadiusLimit !== null && this.radius < this.lowerRadiusLimit) {\r\n this.radius = this.lowerRadiusLimit;\r\n this.inertialRadiusOffset = 0;\r\n }\r\n if (this.upperRadiusLimit !== null && this.radius > this.upperRadiusLimit) {\r\n this.radius = this.upperRadiusLimit;\r\n this.inertialRadiusOffset = 0;\r\n }\r\n }\r\n\r\n /**\r\n * Rebuilds angles (alpha, beta) and radius from the give position and target\r\n */\r\n public rebuildAnglesAndRadius(): void {\r\n this._position.subtractToRef(this._getTargetPosition(), this._computationVector);\r\n\r\n // need to rotate to Y up equivalent if up vector not Axis.Y\r\n if (this._upVector.x !== 0 || this._upVector.y !== 1.0 || this._upVector.z !== 0) {\r\n Vector3.TransformCoordinatesToRef(this._computationVector, this._upToYMatrix, this._computationVector);\r\n }\r\n\r\n this.radius = this._computationVector.length();\r\n\r\n if (this.radius === 0) {\r\n this.radius = 0.0001; // Just to avoid division by zero\r\n }\r\n\r\n // Alpha\r\n const previousAlpha = this.alpha;\r\n if (this._computationVector.x === 0 && this._computationVector.z === 0) {\r\n this.alpha = Math.PI / 2; // avoid division by zero when looking along up axis, and set to acos(0)\r\n } else {\r\n this.alpha = Math.acos(this._computationVector.x / Math.sqrt(Math.pow(this._computationVector.x, 2) + Math.pow(this._computationVector.z, 2)));\r\n }\r\n\r\n if (this._computationVector.z < 0) {\r\n this.alpha = 2 * Math.PI - this.alpha;\r\n }\r\n\r\n // Calculate the number of revolutions between the new and old alpha values.\r\n const alphaCorrectionTurns = Math.round((previousAlpha - this.alpha) / (2.0 * Math.PI));\r\n // Adjust alpha so that its numerical representation is the closest one to the old value.\r\n this.alpha += alphaCorrectionTurns * 2.0 * Math.PI;\r\n\r\n // Beta\r\n this.beta = Math.acos(this._computationVector.y / this.radius);\r\n\r\n this._checkLimits();\r\n }\r\n\r\n /**\r\n * Use a position to define the current camera related information like alpha, beta and radius\r\n * @param position Defines the position to set the camera at\r\n */\r\n public setPosition(position: Vector3): void {\r\n if (this._position.equals(position)) {\r\n return;\r\n }\r\n this._position.copyFrom(position);\r\n\r\n this.rebuildAnglesAndRadius();\r\n }\r\n\r\n /**\r\n * Defines the target the camera should look at.\r\n * This will automatically adapt alpha beta and radius to fit within the new target.\r\n * Please note that setting a target as a mesh will disable panning.\r\n * @param target Defines the new target as a Vector or a mesh\r\n * @param toBoundingCenter In case of a mesh target, defines whether to target the mesh position or its bounding information center\r\n * @param allowSamePosition If false, prevents reapplying the new computed position if it is identical to the current one (optim)\r\n * @param cloneAlphaBetaRadius If true, replicate the current setup (alpha, beta, radius) on the new target\r\n */\r\n public setTarget(target: AbstractMesh | Vector3, toBoundingCenter = false, allowSamePosition = false, cloneAlphaBetaRadius = false): void {\r\n cloneAlphaBetaRadius = this.overrideCloneAlphaBetaRadius ?? cloneAlphaBetaRadius;\r\n\r\n if ((target).getBoundingInfo) {\r\n if (toBoundingCenter) {\r\n this._targetBoundingCenter = (target).getBoundingInfo().boundingBox.centerWorld.clone();\r\n } else {\r\n this._targetBoundingCenter = null;\r\n }\r\n (target).computeWorldMatrix();\r\n this._targetHost = target;\r\n this._target = this._getTargetPosition();\r\n\r\n this.onMeshTargetChangedObservable.notifyObservers(this._targetHost);\r\n } else {\r\n const newTarget = target;\r\n const currentTarget = this._getTargetPosition();\r\n if (currentTarget && !allowSamePosition && currentTarget.equals(newTarget)) {\r\n return;\r\n }\r\n this._targetHost = null;\r\n this._target = newTarget;\r\n this._targetBoundingCenter = null;\r\n this.onMeshTargetChangedObservable.notifyObservers(null);\r\n }\r\n\r\n if (!cloneAlphaBetaRadius) {\r\n this.rebuildAnglesAndRadius();\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _getViewMatrix(): Matrix {\r\n // Compute\r\n const cosa = Math.cos(this.alpha);\r\n const sina = Math.sin(this.alpha);\r\n const cosb = Math.cos(this.beta);\r\n let sinb = Math.sin(this.beta);\r\n\r\n if (sinb === 0) {\r\n sinb = 0.0001;\r\n }\r\n\r\n if (this.radius === 0) {\r\n this.radius = 0.0001; // Just to avoid division by zero\r\n }\r\n\r\n const target = this._getTargetPosition();\r\n this._computationVector.copyFromFloats(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb);\r\n\r\n // Rotate according to up vector\r\n if (this._upVector.x !== 0 || this._upVector.y !== 1.0 || this._upVector.z !== 0) {\r\n Vector3.TransformCoordinatesToRef(this._computationVector, this._yToUpMatrix, this._computationVector);\r\n }\r\n\r\n target.addToRef(this._computationVector, this._newPosition);\r\n if (this.getScene().collisionsEnabled && this.checkCollisions) {\r\n const coordinator = this.getScene().collisionCoordinator;\r\n if (!this._collider) {\r\n this._collider = coordinator.createCollider();\r\n }\r\n this._collider._radius = this.collisionRadius;\r\n this._newPosition.subtractToRef(this._position, this._collisionVelocity);\r\n this._collisionTriggered = true;\r\n coordinator.getNewPosition(this._position, this._collisionVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);\r\n } else {\r\n this._position.copyFrom(this._newPosition);\r\n\r\n let up = this.upVector;\r\n if (this.allowUpsideDown && sinb < 0) {\r\n up = up.negate();\r\n }\r\n\r\n this._computeViewMatrix(this._position, target, up);\r\n\r\n this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);\r\n this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);\r\n }\r\n this._currentTarget = target;\r\n return this._viewMatrix;\r\n }\r\n\r\n protected _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable = null) => {\r\n if (!collidedMesh) {\r\n this._previousPosition.copyFrom(this._position);\r\n } else {\r\n this.setPosition(newPosition);\r\n\r\n if (this.onCollide) {\r\n this.onCollide(collidedMesh);\r\n }\r\n }\r\n\r\n // Recompute because of constraints\r\n const cosa = Math.cos(this.alpha);\r\n const sina = Math.sin(this.alpha);\r\n const cosb = Math.cos(this.beta);\r\n let sinb = Math.sin(this.beta);\r\n\r\n if (sinb === 0) {\r\n sinb = 0.0001;\r\n }\r\n\r\n const target = this._getTargetPosition();\r\n this._computationVector.copyFromFloats(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb);\r\n target.addToRef(this._computationVector, this._newPosition);\r\n this._position.copyFrom(this._newPosition);\r\n\r\n let up = this.upVector;\r\n if (this.allowUpsideDown && this.beta < 0) {\r\n up = up.clone();\r\n up = up.negate();\r\n }\r\n\r\n this._computeViewMatrix(this._position, target, up);\r\n this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);\r\n this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);\r\n\r\n this._collisionTriggered = false;\r\n };\r\n\r\n /**\r\n * Zooms on a mesh to be at the min distance where we could see it fully in the current viewport.\r\n * @param meshes Defines the mesh to zoom on\r\n * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)\r\n */\r\n public zoomOn(meshes?: AbstractMesh[], doNotUpdateMaxZ = false): void {\r\n meshes = meshes || this.getScene().meshes;\r\n\r\n const minMaxVector = Mesh.MinMax(meshes);\r\n const distance = Vector3.Distance(minMaxVector.min, minMaxVector.max);\r\n\r\n this.radius = distance * this.zoomOnFactor;\r\n\r\n this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);\r\n }\r\n\r\n /**\r\n * Focus on a mesh or a bounding box. This adapts the target and maxRadius if necessary but does not update the current radius.\r\n * The target will be changed but the radius\r\n * @param meshesOrMinMaxVectorAndDistance Defines the mesh or bounding info to focus on\r\n * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)\r\n */\r\n public focusOn(meshesOrMinMaxVectorAndDistance: AbstractMesh[] | { min: Vector3; max: Vector3; distance: number }, doNotUpdateMaxZ = false): void {\r\n let meshesOrMinMaxVector: { min: Vector3; max: Vector3 };\r\n let distance: number;\r\n\r\n if ((meshesOrMinMaxVectorAndDistance).min === undefined) {\r\n // meshes\r\n const meshes = meshesOrMinMaxVectorAndDistance || this.getScene().meshes;\r\n meshesOrMinMaxVector = Mesh.MinMax(meshes);\r\n distance = Vector3.Distance(meshesOrMinMaxVector.min, meshesOrMinMaxVector.max);\r\n } else {\r\n //minMaxVector and distance\r\n const minMaxVectorAndDistance = meshesOrMinMaxVectorAndDistance;\r\n meshesOrMinMaxVector = minMaxVectorAndDistance;\r\n distance = minMaxVectorAndDistance.distance;\r\n }\r\n\r\n this._target = Mesh.Center(meshesOrMinMaxVector);\r\n\r\n if (!doNotUpdateMaxZ) {\r\n this.maxZ = distance * 2;\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n * Override Camera.createRigCamera\r\n */\r\n public createRigCamera(name: string, cameraIndex: number): Camera {\r\n let alphaShift: number = 0;\r\n switch (this.cameraRigMode) {\r\n case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:\r\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:\r\n case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:\r\n case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED:\r\n case Camera.RIG_MODE_VR:\r\n alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? 1 : -1);\r\n break;\r\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:\r\n alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? -1 : 1);\r\n break;\r\n }\r\n const rigCam = new ArcRotateCamera(name, this.alpha + alphaShift, this.beta, this.radius, this._target, this.getScene());\r\n rigCam._cameraRigParams = {};\r\n rigCam.isRigCamera = true;\r\n rigCam.rigParent = this;\r\n rigCam.upVector = this.upVector;\r\n\r\n rigCam.mode = this.mode;\r\n rigCam.orthoLeft = this.orthoLeft;\r\n rigCam.orthoRight = this.orthoRight;\r\n rigCam.orthoBottom = this.orthoBottom;\r\n rigCam.orthoTop = this.orthoTop;\r\n\r\n return rigCam;\r\n }\r\n\r\n /**\r\n * @internal\r\n * @override\r\n * Override Camera._updateRigCameras\r\n */\r\n public _updateRigCameras() {\r\n const camLeft = this._rigCameras[0];\r\n const camRight = this._rigCameras[1];\r\n\r\n camLeft.beta = camRight.beta = this.beta;\r\n\r\n switch (this.cameraRigMode) {\r\n case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:\r\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:\r\n case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:\r\n case Camera.RIG_MODE_STEREOSCOPIC_INTERLACED:\r\n case Camera.RIG_MODE_VR:\r\n camLeft.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;\r\n camRight.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;\r\n break;\r\n case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:\r\n camLeft.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;\r\n camRight.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;\r\n break;\r\n }\r\n super._updateRigCameras();\r\n }\r\n\r\n /**\r\n * Destroy the camera and release the current resources hold by it.\r\n */\r\n public dispose(): void {\r\n this.inputs.clear();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Gets the current object class name.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCamera\";\r\n }\r\n}\r\n","import type { DeepImmutable, Nullable, float } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport { Matrix, Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport { IntersectionInfo } from \"../Collisions/intersectionInfo\";\r\nimport type { BoundingBox } from \"./boundingBox\";\r\nimport type { BoundingSphere } from \"./boundingSphere\";\r\nimport { Scene } from \"../scene\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\n\r\n/**\r\n * Class representing a ray with position and direction\r\n */\r\nexport class Ray {\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(6, Vector3.Zero);\r\n private static _RayDistant = Ray.Zero();\r\n private _tmpRay: Ray;\r\n\r\n /**\r\n * Creates a new ray\r\n * @param origin origin point\r\n * @param direction direction\r\n * @param length length of the ray\r\n */\r\n constructor(\r\n /** origin point */\r\n public origin: Vector3,\r\n /** direction */\r\n public direction: Vector3,\r\n /** length of the ray */\r\n public length: number = Number.MAX_VALUE\r\n ) {}\r\n\r\n // Methods\r\n\r\n /**\r\n * Clone the current ray\r\n * @returns a new ray\r\n */\r\n public clone(): Ray {\r\n return new Ray(this.origin.clone(), this.direction.clone(), this.length);\r\n }\r\n\r\n /**\r\n * Checks if the ray intersects a box\r\n * This does not account for the ray length by design to improve perfs.\r\n * @param minimum bound of the box\r\n * @param maximum bound of the box\r\n * @param intersectionTreshold extra extend to be added to the box in all direction\r\n * @returns if the box was hit\r\n */\r\n public intersectsBoxMinMax(minimum: DeepImmutable, maximum: DeepImmutable, intersectionTreshold: number = 0): boolean {\r\n const newMinimum = Ray._TmpVector3[0].copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);\r\n const newMaximum = Ray._TmpVector3[1].copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);\r\n let d = 0.0;\r\n let maxValue = Number.MAX_VALUE;\r\n let inv: number;\r\n let min: number;\r\n let max: number;\r\n let temp: number;\r\n if (Math.abs(this.direction.x) < 0.0000001) {\r\n if (this.origin.x < newMinimum.x || this.origin.x > newMaximum.x) {\r\n return false;\r\n }\r\n } else {\r\n inv = 1.0 / this.direction.x;\r\n min = (newMinimum.x - this.origin.x) * inv;\r\n max = (newMaximum.x - this.origin.x) * inv;\r\n if (max === -Infinity) {\r\n max = Infinity;\r\n }\r\n\r\n if (min > max) {\r\n temp = min;\r\n min = max;\r\n max = temp;\r\n }\r\n\r\n d = Math.max(min, d);\r\n maxValue = Math.min(max, maxValue);\r\n\r\n if (d > maxValue) {\r\n return false;\r\n }\r\n }\r\n\r\n if (Math.abs(this.direction.y) < 0.0000001) {\r\n if (this.origin.y < newMinimum.y || this.origin.y > newMaximum.y) {\r\n return false;\r\n }\r\n } else {\r\n inv = 1.0 / this.direction.y;\r\n min = (newMinimum.y - this.origin.y) * inv;\r\n max = (newMaximum.y - this.origin.y) * inv;\r\n\r\n if (max === -Infinity) {\r\n max = Infinity;\r\n }\r\n\r\n if (min > max) {\r\n temp = min;\r\n min = max;\r\n max = temp;\r\n }\r\n\r\n d = Math.max(min, d);\r\n maxValue = Math.min(max, maxValue);\r\n\r\n if (d > maxValue) {\r\n return false;\r\n }\r\n }\r\n\r\n if (Math.abs(this.direction.z) < 0.0000001) {\r\n if (this.origin.z < newMinimum.z || this.origin.z > newMaximum.z) {\r\n return false;\r\n }\r\n } else {\r\n inv = 1.0 / this.direction.z;\r\n min = (newMinimum.z - this.origin.z) * inv;\r\n max = (newMaximum.z - this.origin.z) * inv;\r\n\r\n if (max === -Infinity) {\r\n max = Infinity;\r\n }\r\n\r\n if (min > max) {\r\n temp = min;\r\n min = max;\r\n max = temp;\r\n }\r\n\r\n d = Math.max(min, d);\r\n maxValue = Math.min(max, maxValue);\r\n\r\n if (d > maxValue) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Checks if the ray intersects a box\r\n * This does not account for the ray lenght by design to improve perfs.\r\n * @param box the bounding box to check\r\n * @param intersectionTreshold extra extend to be added to the BoundingBox in all direction\r\n * @returns if the box was hit\r\n */\r\n public intersectsBox(box: DeepImmutable, intersectionTreshold: number = 0): boolean {\r\n return this.intersectsBoxMinMax(box.minimum, box.maximum, intersectionTreshold);\r\n }\r\n\r\n /**\r\n * If the ray hits a sphere\r\n * @param sphere the bounding sphere to check\r\n * @param intersectionTreshold extra extend to be added to the BoundingSphere in all direction\r\n * @returns true if it hits the sphere\r\n */\r\n public intersectsSphere(sphere: DeepImmutable, intersectionTreshold: number = 0): boolean {\r\n const x = sphere.center.x - this.origin.x;\r\n const y = sphere.center.y - this.origin.y;\r\n const z = sphere.center.z - this.origin.z;\r\n const pyth = x * x + y * y + z * z;\r\n const radius = sphere.radius + intersectionTreshold;\r\n const rr = radius * radius;\r\n\r\n if (pyth <= rr) {\r\n return true;\r\n }\r\n\r\n const dot = x * this.direction.x + y * this.direction.y + z * this.direction.z;\r\n if (dot < 0.0) {\r\n return false;\r\n }\r\n\r\n const temp = pyth - dot * dot;\r\n\r\n return temp <= rr;\r\n }\r\n\r\n /**\r\n * If the ray hits a triange\r\n * @param vertex0 triangle vertex\r\n * @param vertex1 triangle vertex\r\n * @param vertex2 triangle vertex\r\n * @returns intersection information if hit\r\n */\r\n public intersectsTriangle(vertex0: DeepImmutable, vertex1: DeepImmutable, vertex2: DeepImmutable): Nullable {\r\n const edge1 = Ray._TmpVector3[0];\r\n const edge2 = Ray._TmpVector3[1];\r\n const pvec = Ray._TmpVector3[2];\r\n const tvec = Ray._TmpVector3[3];\r\n const qvec = Ray._TmpVector3[4];\r\n\r\n vertex1.subtractToRef(vertex0, edge1);\r\n vertex2.subtractToRef(vertex0, edge2);\r\n Vector3.CrossToRef(this.direction, edge2, pvec);\r\n const det = Vector3.Dot(edge1, pvec);\r\n\r\n if (det === 0) {\r\n return null;\r\n }\r\n\r\n const invdet = 1 / det;\r\n\r\n this.origin.subtractToRef(vertex0, tvec);\r\n\r\n const bv = Vector3.Dot(tvec, pvec) * invdet;\r\n\r\n if (bv < 0 || bv > 1.0) {\r\n return null;\r\n }\r\n\r\n Vector3.CrossToRef(tvec, edge1, qvec);\r\n\r\n const bw = Vector3.Dot(this.direction, qvec) * invdet;\r\n\r\n if (bw < 0 || bv + bw > 1.0) {\r\n return null;\r\n }\r\n\r\n //check if the distance is longer than the predefined length.\r\n const distance = Vector3.Dot(edge2, qvec) * invdet;\r\n if (distance > this.length) {\r\n return null;\r\n }\r\n\r\n return new IntersectionInfo(1 - bv - bw, bv, distance);\r\n }\r\n\r\n /**\r\n * Checks if ray intersects a plane\r\n * @param plane the plane to check\r\n * @returns the distance away it was hit\r\n */\r\n public intersectsPlane(plane: DeepImmutable): Nullable {\r\n let distance: number;\r\n const result1 = Vector3.Dot(plane.normal, this.direction);\r\n if (Math.abs(result1) < 9.99999997475243e-7) {\r\n return null;\r\n } else {\r\n const result2 = Vector3.Dot(plane.normal, this.origin);\r\n distance = (-plane.d - result2) / result1;\r\n if (distance < 0.0) {\r\n if (distance < -9.99999997475243e-7) {\r\n return null;\r\n } else {\r\n return 0;\r\n }\r\n }\r\n\r\n return distance;\r\n }\r\n }\r\n /**\r\n * Calculate the intercept of a ray on a given axis\r\n * @param axis to check 'x' | 'y' | 'z'\r\n * @param offset from axis interception (i.e. an offset of 1y is intercepted above ground)\r\n * @returns a vector containing the coordinates where 'axis' is equal to zero (else offset), or null if there is no intercept.\r\n */\r\n public intersectsAxis(axis: string, offset: number = 0): Nullable {\r\n switch (axis) {\r\n case \"y\": {\r\n const t = (this.origin.y - offset) / this.direction.y;\r\n if (t > 0) {\r\n return null;\r\n }\r\n return new Vector3(this.origin.x + this.direction.x * -t, offset, this.origin.z + this.direction.z * -t);\r\n }\r\n case \"x\": {\r\n const t = (this.origin.x - offset) / this.direction.x;\r\n if (t > 0) {\r\n return null;\r\n }\r\n return new Vector3(offset, this.origin.y + this.direction.y * -t, this.origin.z + this.direction.z * -t);\r\n }\r\n case \"z\": {\r\n const t = (this.origin.z - offset) / this.direction.z;\r\n if (t > 0) {\r\n return null;\r\n }\r\n return new Vector3(this.origin.x + this.direction.x * -t, this.origin.y + this.direction.y * -t, offset);\r\n }\r\n default:\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Checks if ray intersects a mesh. The ray is defined in WORLD space. A mesh triangle can be picked both from its front and back sides,\r\n * irrespective of orientation.\r\n * @param mesh the mesh to check\r\n * @param fastCheck defines if the first intersection will be used (and not the closest)\r\n * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected\r\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\r\n * @param worldToUse defines the world matrix to use to get the world coordinate of the intersection point\r\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\r\n * @returns picking info of the intersection\r\n */\r\n public intersectsMesh(\r\n mesh: DeepImmutable,\r\n fastCheck?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate,\r\n onlyBoundingInfo = false,\r\n worldToUse?: Matrix,\r\n skipBoundingInfo = false\r\n ): PickingInfo {\r\n const tm = TmpVectors.Matrix[0];\r\n\r\n mesh.getWorldMatrix().invertToRef(tm);\r\n\r\n if (this._tmpRay) {\r\n Ray.TransformToRef(this, tm, this._tmpRay);\r\n } else {\r\n this._tmpRay = Ray.Transform(this, tm);\r\n }\r\n\r\n return mesh.intersects(this._tmpRay, fastCheck, trianglePredicate, onlyBoundingInfo, worldToUse, skipBoundingInfo);\r\n }\r\n\r\n /**\r\n * Checks if ray intersects a mesh\r\n * @param meshes the meshes to check\r\n * @param fastCheck defines if the first intersection will be used (and not the closest)\r\n * @param results array to store result in\r\n * @returns Array of picking infos\r\n */\r\n public intersectsMeshes(meshes: Array>, fastCheck?: boolean, results?: Array): Array {\r\n if (results) {\r\n results.length = 0;\r\n } else {\r\n results = [];\r\n }\r\n\r\n for (let i = 0; i < meshes.length; i++) {\r\n const pickInfo = this.intersectsMesh(meshes[i], fastCheck);\r\n\r\n if (pickInfo.hit) {\r\n results.push(pickInfo);\r\n }\r\n }\r\n\r\n results.sort(this._comparePickingInfo);\r\n\r\n return results;\r\n }\r\n\r\n private _comparePickingInfo(pickingInfoA: DeepImmutable, pickingInfoB: DeepImmutable): number {\r\n if (pickingInfoA.distance < pickingInfoB.distance) {\r\n return -1;\r\n } else if (pickingInfoA.distance > pickingInfoB.distance) {\r\n return 1;\r\n } else {\r\n return 0;\r\n }\r\n }\r\n\r\n private static _Smallnum = 0.00000001;\r\n private static _Rayl = 10e8;\r\n\r\n /**\r\n * Intersection test between the ray and a given segment within a given tolerance (threshold)\r\n * @param sega the first point of the segment to test the intersection against\r\n * @param segb the second point of the segment to test the intersection against\r\n * @param threshold the tolerance margin, if the ray doesn't intersect the segment but is close to the given threshold, the intersection is successful\r\n * @returns the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection\r\n */\r\n intersectionSegment(sega: DeepImmutable, segb: DeepImmutable, threshold: number): number {\r\n const o = this.origin;\r\n const u = TmpVectors.Vector3[0];\r\n const rsegb = TmpVectors.Vector3[1];\r\n const v = TmpVectors.Vector3[2];\r\n const w = TmpVectors.Vector3[3];\r\n\r\n segb.subtractToRef(sega, u);\r\n\r\n this.direction.scaleToRef(Ray._Rayl, v);\r\n o.addToRef(v, rsegb);\r\n\r\n sega.subtractToRef(o, w);\r\n\r\n const a = Vector3.Dot(u, u); // always >= 0\r\n const b = Vector3.Dot(u, v);\r\n const c = Vector3.Dot(v, v); // always >= 0\r\n const d = Vector3.Dot(u, w);\r\n const e = Vector3.Dot(v, w);\r\n const D = a * c - b * b; // always >= 0\r\n let sN: number,\r\n sD = D; // sc = sN / sD, default sD = D >= 0\r\n let tN: number,\r\n tD = D; // tc = tN / tD, default tD = D >= 0\r\n\r\n // compute the line parameters of the two closest points\r\n if (D < Ray._Smallnum) {\r\n // the lines are almost parallel\r\n sN = 0.0; // force using point P0 on segment S1\r\n sD = 1.0; // to prevent possible division by 0.0 later\r\n tN = e;\r\n tD = c;\r\n } else {\r\n // get the closest points on the infinite lines\r\n sN = b * e - c * d;\r\n tN = a * e - b * d;\r\n if (sN < 0.0) {\r\n // sc < 0 => the s=0 edge is visible\r\n sN = 0.0;\r\n tN = e;\r\n tD = c;\r\n } else if (sN > sD) {\r\n // sc > 1 => the s=1 edge is visible\r\n sN = sD;\r\n tN = e + b;\r\n tD = c;\r\n }\r\n }\r\n\r\n if (tN < 0.0) {\r\n // tc < 0 => the t=0 edge is visible\r\n tN = 0.0;\r\n // recompute sc for this edge\r\n if (-d < 0.0) {\r\n sN = 0.0;\r\n } else if (-d > a) {\r\n sN = sD;\r\n } else {\r\n sN = -d;\r\n sD = a;\r\n }\r\n } else if (tN > tD) {\r\n // tc > 1 => the t=1 edge is visible\r\n tN = tD;\r\n // recompute sc for this edge\r\n if (-d + b < 0.0) {\r\n sN = 0;\r\n } else if (-d + b > a) {\r\n sN = sD;\r\n } else {\r\n sN = -d + b;\r\n sD = a;\r\n }\r\n }\r\n // finally do the division to get sc and tc\r\n const sc = Math.abs(sN) < Ray._Smallnum ? 0.0 : sN / sD;\r\n const tc = Math.abs(tN) < Ray._Smallnum ? 0.0 : tN / tD;\r\n\r\n // get the difference of the two closest points\r\n const qtc = TmpVectors.Vector3[4];\r\n v.scaleToRef(tc, qtc);\r\n const qsc = TmpVectors.Vector3[5];\r\n u.scaleToRef(sc, qsc);\r\n qsc.addInPlace(w);\r\n const dP = TmpVectors.Vector3[6];\r\n qsc.subtractToRef(qtc, dP); // = S1(sc) - S2(tc)\r\n\r\n const isIntersected = tc > 0 && tc <= this.length && dP.lengthSquared() < threshold * threshold; // return intersection result\r\n\r\n if (isIntersected) {\r\n return qsc.length();\r\n }\r\n return -1;\r\n }\r\n\r\n /**\r\n * Update the ray from viewport position\r\n * @param x position\r\n * @param y y position\r\n * @param viewportWidth viewport width\r\n * @param viewportHeight viewport height\r\n * @param world world matrix\r\n * @param view view matrix\r\n * @param projection projection matrix\r\n * @param enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)\r\n * @returns this ray updated\r\n */\r\n public update(\r\n x: number,\r\n y: number,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable,\r\n enableDistantPicking: boolean = false\r\n ): Ray {\r\n if (enableDistantPicking) {\r\n // With world matrices having great values (like 8000000000 on 1 or more scaling or position axis),\r\n // multiplying view/projection/world and doing invert will result in loss of float precision in the matrix.\r\n // One way to fix it is to compute the ray with world at identity then transform the ray in object space.\r\n // This is slower (2 matrix inverts instead of 1) but precision is preserved.\r\n // This is hidden behind `EnableDistantPicking` flag (default is false)\r\n if (!Ray._RayDistant) {\r\n Ray._RayDistant = Ray.Zero();\r\n }\r\n\r\n Ray._RayDistant.unprojectRayToRef(x, y, viewportWidth, viewportHeight, Matrix.IdentityReadOnly, view, projection);\r\n\r\n const tm = TmpVectors.Matrix[0];\r\n world.invertToRef(tm);\r\n Ray.TransformToRef(Ray._RayDistant, tm, this);\r\n } else {\r\n this.unprojectRayToRef(x, y, viewportWidth, viewportHeight, world, view, projection);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Creates a ray with origin and direction of 0,0,0\r\n * @returns the new ray\r\n */\r\n public static Zero(): Ray {\r\n return new Ray(Vector3.Zero(), Vector3.Zero());\r\n }\r\n\r\n /**\r\n * Creates a new ray from screen space and viewport\r\n * @param x position\r\n * @param y y position\r\n * @param viewportWidth viewport width\r\n * @param viewportHeight viewport height\r\n * @param world world matrix\r\n * @param view view matrix\r\n * @param projection projection matrix\r\n * @returns new ray\r\n */\r\n public static CreateNew(\r\n x: number,\r\n y: number,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable\r\n ): Ray {\r\n const result = Ray.Zero();\r\n\r\n return result.update(x, y, viewportWidth, viewportHeight, world, view, projection);\r\n }\r\n\r\n /**\r\n * Function will create a new transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be\r\n * transformed to the given world matrix.\r\n * @param origin The origin point\r\n * @param end The end point\r\n * @param world a matrix to transform the ray to. Default is the identity matrix.\r\n * @returns the new ray\r\n */\r\n public static CreateNewFromTo(origin: Vector3, end: Vector3, world: DeepImmutable = Matrix.IdentityReadOnly): Ray {\r\n const direction = end.subtract(origin);\r\n const length = Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);\r\n direction.normalize();\r\n\r\n return Ray.Transform(new Ray(origin, direction, length), world);\r\n }\r\n\r\n /**\r\n * Transforms a ray by a matrix\r\n * @param ray ray to transform\r\n * @param matrix matrix to apply\r\n * @returns the resulting new ray\r\n */\r\n public static Transform(ray: DeepImmutable, matrix: DeepImmutable): Ray {\r\n const result = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 0));\r\n Ray.TransformToRef(ray, matrix, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Transforms a ray by a matrix\r\n * @param ray ray to transform\r\n * @param matrix matrix to apply\r\n * @param result ray to store result in\r\n */\r\n public static TransformToRef(ray: DeepImmutable, matrix: DeepImmutable, result: Ray): void {\r\n Vector3.TransformCoordinatesToRef(ray.origin, matrix, result.origin);\r\n Vector3.TransformNormalToRef(ray.direction, matrix, result.direction);\r\n result.length = ray.length;\r\n\r\n const dir = result.direction;\r\n const len = dir.length();\r\n\r\n if (!(len === 0 || len === 1)) {\r\n const num = 1.0 / len;\r\n dir.x *= num;\r\n dir.y *= num;\r\n dir.z *= num;\r\n result.length *= len;\r\n }\r\n }\r\n\r\n /**\r\n * Unproject a ray from screen space to object space\r\n * @param sourceX defines the screen space x coordinate to use\r\n * @param sourceY defines the screen space y coordinate to use\r\n * @param viewportWidth defines the current width of the viewport\r\n * @param viewportHeight defines the current height of the viewport\r\n * @param world defines the world matrix to use (can be set to Identity to go to world space)\r\n * @param view defines the view matrix to use\r\n * @param projection defines the projection matrix to use\r\n */\r\n public unprojectRayToRef(\r\n sourceX: float,\r\n sourceY: float,\r\n viewportWidth: number,\r\n viewportHeight: number,\r\n world: DeepImmutable,\r\n view: DeepImmutable,\r\n projection: DeepImmutable\r\n ): void {\r\n const matrix = TmpVectors.Matrix[0];\r\n world.multiplyToRef(view, matrix);\r\n matrix.multiplyToRef(projection, matrix);\r\n matrix.invert();\r\n\r\n const engine = EngineStore.LastCreatedEngine;\r\n const nearScreenSource = TmpVectors.Vector3[0];\r\n nearScreenSource.x = (sourceX / viewportWidth) * 2 - 1;\r\n nearScreenSource.y = -((sourceY / viewportHeight) * 2 - 1);\r\n nearScreenSource.z = engine?.useReverseDepthBuffer ? 1 : engine?.isNDCHalfZRange ? 0 : -1;\r\n\r\n // far Z need to be close but < to 1 or camera projection matrix with maxZ = 0 will NaN\r\n const farScreenSource = TmpVectors.Vector3[1].copyFromFloats(nearScreenSource.x, nearScreenSource.y, 1.0 - 1e-8);\r\n const nearVec3 = TmpVectors.Vector3[2];\r\n const farVec3 = TmpVectors.Vector3[3];\r\n Vector3._UnprojectFromInvertedMatrixToRef(nearScreenSource, matrix, nearVec3);\r\n Vector3._UnprojectFromInvertedMatrixToRef(farScreenSource, matrix, farVec3);\r\n\r\n this.origin.copyFrom(nearVec3);\r\n farVec3.subtractToRef(nearVec3, this.direction);\r\n this.direction.normalize();\r\n }\r\n}\r\n\r\n// Picking\r\n/**\r\n * Type used to define predicate used to select faces when a mesh intersection is detected\r\n */\r\nexport type TrianglePickingPredicate = (p0: Vector3, p1: Vector3, p2: Vector3, ray: Ray, i0: number, i1: number, i2: number) => boolean;\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal */\r\n _tempPickingRay: Nullable;\r\n\r\n /** @internal */\r\n _cachedRayForTransform: Ray;\r\n\r\n /** @internal */\r\n _pickWithRayInverseMatrix: Matrix;\r\n\r\n /** @internal */\r\n _internalPick(\r\n rayFunction: (world: Matrix, enableDistantPicking: boolean) => Ray,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n fastCheck?: boolean,\r\n onlyBoundingInfo?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n ): PickingInfo;\r\n\r\n /** @internal */\r\n _internalMultiPick(\r\n rayFunction: (world: Matrix, enableDistantPicking: boolean) => Ray,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n ): Nullable;\r\n\r\n /** @internal */\r\n _internalPickForMesh(\r\n pickingInfo: Nullable,\r\n rayFunction: (world: Matrix, enableDistantPicking: boolean) => Ray,\r\n mesh: AbstractMesh,\r\n world: Matrix,\r\n fastCheck?: boolean,\r\n onlyBoundingInfo?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate,\r\n skipBoundingInfo?: boolean\r\n ): Nullable;\r\n }\r\n}\r\n\r\nScene.prototype.createPickingRay = function (x: number, y: number, world: Nullable, camera: Nullable, cameraViewSpace = false): Ray {\r\n const result = Ray.Zero();\r\n\r\n this.createPickingRayToRef(x, y, world, result, camera, cameraViewSpace);\r\n\r\n return result;\r\n};\r\n\r\nScene.prototype.createPickingRayToRef = function (\r\n x: number,\r\n y: number,\r\n world: Nullable,\r\n result: Ray,\r\n camera: Nullable,\r\n cameraViewSpace = false,\r\n enableDistantPicking = false\r\n): Scene {\r\n const engine = this.getEngine();\r\n\r\n if (!camera) {\r\n if (!this.activeCamera) {\r\n return this;\r\n }\r\n\r\n camera = this.activeCamera;\r\n }\r\n\r\n const cameraViewport = camera.viewport;\r\n const viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());\r\n\r\n // Moving coordinates to local viewport world\r\n x = x / engine.getHardwareScalingLevel() - viewport.x;\r\n y = y / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - viewport.y - viewport.height);\r\n\r\n result.update(\r\n x,\r\n y,\r\n viewport.width,\r\n viewport.height,\r\n world ? world : Matrix.IdentityReadOnly,\r\n cameraViewSpace ? Matrix.IdentityReadOnly : camera.getViewMatrix(),\r\n camera.getProjectionMatrix(),\r\n enableDistantPicking\r\n );\r\n return this;\r\n};\r\n\r\nScene.prototype.createPickingRayInCameraSpace = function (x: number, y: number, camera?: Camera): Ray {\r\n const result = Ray.Zero();\r\n\r\n this.createPickingRayInCameraSpaceToRef(x, y, result, camera);\r\n\r\n return result;\r\n};\r\n\r\nScene.prototype.createPickingRayInCameraSpaceToRef = function (x: number, y: number, result: Ray, camera?: Camera): Scene {\r\n if (!PickingInfo) {\r\n return this;\r\n }\r\n\r\n const engine = this.getEngine();\r\n\r\n if (!camera) {\r\n if (!this.activeCamera) {\r\n throw new Error(\"Active camera not set\");\r\n }\r\n\r\n camera = this.activeCamera;\r\n }\r\n\r\n const cameraViewport = camera.viewport;\r\n const viewport = cameraViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());\r\n const identity = Matrix.Identity();\r\n\r\n // Moving coordinates to local viewport world\r\n x = x / engine.getHardwareScalingLevel() - viewport.x;\r\n y = y / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - viewport.y - viewport.height);\r\n result.update(x, y, viewport.width, viewport.height, identity, identity, camera.getProjectionMatrix());\r\n return this;\r\n};\r\n\r\nScene.prototype._internalPickForMesh = function (\r\n pickingInfo: Nullable,\r\n rayFunction: (world: Matrix, enableDistantPicking: boolean) => Ray,\r\n mesh: AbstractMesh,\r\n world: Matrix,\r\n fastCheck?: boolean,\r\n onlyBoundingInfo?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate,\r\n skipBoundingInfo?: boolean\r\n) {\r\n const ray = rayFunction(world, mesh.enableDistantPicking);\r\n\r\n const result = mesh.intersects(ray, fastCheck, trianglePredicate, onlyBoundingInfo, world, skipBoundingInfo);\r\n if (!result || !result.hit) {\r\n return null;\r\n }\r\n\r\n if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance) {\r\n return null;\r\n }\r\n\r\n return result;\r\n};\r\n\r\nScene.prototype._internalPick = function (\r\n rayFunction: (world: Matrix, enableDistantPicking: boolean) => Ray,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n fastCheck?: boolean,\r\n onlyBoundingInfo?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n): PickingInfo {\r\n let pickingInfo = null;\r\n\r\n const computeWorldMatrixForCamera = !!(this.activeCameras && this.activeCameras.length > 1 && this.cameraToUseForPointers !== this.activeCamera);\r\n const currentCamera = this.cameraToUseForPointers || this.activeCamera;\r\n\r\n for (let meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {\r\n const mesh = this.meshes[meshIndex];\r\n\r\n if (predicate) {\r\n if (!predicate(mesh)) {\r\n continue;\r\n }\r\n } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {\r\n continue;\r\n }\r\n\r\n const forceCompute = computeWorldMatrixForCamera && mesh.isWorldMatrixCameraDependent();\r\n const world = mesh.computeWorldMatrix(forceCompute, currentCamera);\r\n\r\n if (mesh.hasThinInstances && (mesh as Mesh).thinInstanceEnablePicking) {\r\n // first check if the ray intersects the whole bounding box/sphere of the mesh\r\n const result = this._internalPickForMesh(pickingInfo, rayFunction, mesh, world, true, true, trianglePredicate);\r\n if (result) {\r\n if (onlyBoundingInfo) {\r\n // the user only asked for a bounding info check so we can return\r\n return result;\r\n }\r\n const tmpMatrix = TmpVectors.Matrix[1];\r\n const thinMatrices = (mesh as Mesh).thinInstanceGetWorldMatrices();\r\n for (let index = 0; index < thinMatrices.length; index++) {\r\n const thinMatrix = thinMatrices[index];\r\n thinMatrix.multiplyToRef(world, tmpMatrix);\r\n const result = this._internalPickForMesh(pickingInfo, rayFunction, mesh, tmpMatrix, fastCheck, onlyBoundingInfo, trianglePredicate, true);\r\n\r\n if (result) {\r\n pickingInfo = result;\r\n pickingInfo.thinInstanceIndex = index;\r\n\r\n if (fastCheck) {\r\n return pickingInfo;\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n const result = this._internalPickForMesh(pickingInfo, rayFunction, mesh, world, fastCheck, onlyBoundingInfo, trianglePredicate);\r\n\r\n if (result) {\r\n pickingInfo = result;\r\n\r\n if (fastCheck) {\r\n return pickingInfo;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return pickingInfo || new PickingInfo();\r\n};\r\n\r\nScene.prototype._internalMultiPick = function (\r\n rayFunction: (world: Matrix, enableDistantPicking: boolean) => Ray,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n): Nullable {\r\n if (!PickingInfo) {\r\n return null;\r\n }\r\n const pickingInfos = new Array();\r\n const computeWorldMatrixForCamera = !!(this.activeCameras && this.activeCameras.length > 1 && this.cameraToUseForPointers !== this.activeCamera);\r\n const currentCamera = this.cameraToUseForPointers || this.activeCamera;\r\n\r\n for (let meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {\r\n const mesh = this.meshes[meshIndex];\r\n\r\n if (predicate) {\r\n if (!predicate(mesh)) {\r\n continue;\r\n }\r\n } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {\r\n continue;\r\n }\r\n\r\n const forceCompute = computeWorldMatrixForCamera && mesh.isWorldMatrixCameraDependent();\r\n const world = mesh.computeWorldMatrix(forceCompute, currentCamera);\r\n\r\n if (mesh.hasThinInstances && (mesh as Mesh).thinInstanceEnablePicking) {\r\n const result = this._internalPickForMesh(null, rayFunction, mesh, world, true, true, trianglePredicate);\r\n if (result) {\r\n const tmpMatrix = TmpVectors.Matrix[1];\r\n const thinMatrices = (mesh as Mesh).thinInstanceGetWorldMatrices();\r\n for (let index = 0; index < thinMatrices.length; index++) {\r\n const thinMatrix = thinMatrices[index];\r\n thinMatrix.multiplyToRef(world, tmpMatrix);\r\n const result = this._internalPickForMesh(null, rayFunction, mesh, tmpMatrix, false, false, trianglePredicate, true);\r\n\r\n if (result) {\r\n result.thinInstanceIndex = index;\r\n pickingInfos.push(result);\r\n }\r\n }\r\n }\r\n } else {\r\n const result = this._internalPickForMesh(null, rayFunction, mesh, world, false, false, trianglePredicate);\r\n\r\n if (result) {\r\n pickingInfos.push(result);\r\n }\r\n }\r\n }\r\n\r\n return pickingInfos;\r\n};\r\n\r\nScene.prototype.pickWithBoundingInfo = function (\r\n x: number,\r\n y: number,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n fastCheck?: boolean,\r\n camera?: Nullable\r\n): Nullable {\r\n if (!PickingInfo) {\r\n return null;\r\n }\r\n const result = this._internalPick(\r\n (world) => {\r\n if (!this._tempPickingRay) {\r\n this._tempPickingRay = Ray.Zero();\r\n }\r\n\r\n this.createPickingRayToRef(x, y, world, this._tempPickingRay, camera || null);\r\n return this._tempPickingRay;\r\n },\r\n predicate,\r\n fastCheck,\r\n true\r\n );\r\n if (result) {\r\n result.ray = this.createPickingRay(x, y, Matrix.Identity(), camera || null);\r\n }\r\n return result;\r\n};\r\n\r\nObject.defineProperty(Scene.prototype, \"_pickingAvailable\", {\r\n get: () => true,\r\n enumerable: false,\r\n configurable: false,\r\n});\r\n\r\nScene.prototype.pick = function (\r\n x: number,\r\n y: number,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n fastCheck?: boolean,\r\n camera?: Nullable,\r\n trianglePredicate?: TrianglePickingPredicate,\r\n _enableDistantPicking = false\r\n): PickingInfo {\r\n const result = this._internalPick(\r\n (world, enableDistantPicking) => {\r\n if (!this._tempPickingRay) {\r\n this._tempPickingRay = Ray.Zero();\r\n }\r\n\r\n this.createPickingRayToRef(x, y, world, this._tempPickingRay, camera || null, false, enableDistantPicking);\r\n return this._tempPickingRay;\r\n },\r\n predicate,\r\n fastCheck,\r\n false,\r\n trianglePredicate\r\n );\r\n if (result) {\r\n result.ray = this.createPickingRay(x, y, Matrix.Identity(), camera || null);\r\n }\r\n return result;\r\n};\r\n\r\nScene.prototype.pickWithRay = function (\r\n ray: Ray,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n fastCheck?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate\r\n): Nullable {\r\n const result = this._internalPick(\r\n (world) => {\r\n if (!this._pickWithRayInverseMatrix) {\r\n this._pickWithRayInverseMatrix = Matrix.Identity();\r\n }\r\n world.invertToRef(this._pickWithRayInverseMatrix);\r\n\r\n if (!this._cachedRayForTransform) {\r\n this._cachedRayForTransform = Ray.Zero();\r\n }\r\n\r\n Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);\r\n return this._cachedRayForTransform;\r\n },\r\n predicate,\r\n fastCheck,\r\n false,\r\n trianglePredicate\r\n );\r\n if (result) {\r\n result.ray = ray;\r\n }\r\n return result;\r\n};\r\n\r\nScene.prototype.multiPick = function (\r\n x: number,\r\n y: number,\r\n predicate?: (mesh: AbstractMesh) => boolean,\r\n camera?: Camera,\r\n trianglePredicate?: TrianglePickingPredicate\r\n): Nullable {\r\n return this._internalMultiPick((world) => this.createPickingRay(x, y, world, camera || null), predicate, trianglePredicate);\r\n};\r\n\r\nScene.prototype.multiPickWithRay = function (ray: Ray, predicate?: (mesh: AbstractMesh) => boolean, trianglePredicate?: TrianglePickingPredicate): Nullable {\r\n return this._internalMultiPick(\r\n (world) => {\r\n if (!this._pickWithRayInverseMatrix) {\r\n this._pickWithRayInverseMatrix = Matrix.Identity();\r\n }\r\n world.invertToRef(this._pickWithRayInverseMatrix);\r\n\r\n if (!this._cachedRayForTransform) {\r\n this._cachedRayForTransform = Ray.Zero();\r\n }\r\n\r\n Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);\r\n return this._cachedRayForTransform;\r\n },\r\n predicate,\r\n trianglePredicate\r\n );\r\n};\r\n\r\nCamera.prototype.getForwardRay = function (length = 100, transform?: Matrix, origin?: Vector3): Ray {\r\n return this.getForwardRayToRef(new Ray(Vector3.Zero(), Vector3.Zero(), length), length, transform, origin);\r\n};\r\n\r\nCamera.prototype.getForwardRayToRef = function (refRay: Ray, length = 100, transform?: Matrix, origin?: Vector3): Ray {\r\n if (!transform) {\r\n transform = this.getWorldMatrix();\r\n }\r\n refRay.length = length;\r\n\r\n if (!origin) {\r\n refRay.origin.copyFrom(this.position);\r\n } else {\r\n refRay.origin.copyFrom(origin);\r\n }\r\n TmpVectors.Vector3[2].set(0, 0, this._scene.useRightHandedSystem ? -1 : 1);\r\n Vector3.TransformNormalToRef(TmpVectors.Vector3[2], transform, TmpVectors.Vector3[3]);\r\n\r\n Vector3.NormalizeToRef(TmpVectors.Vector3[3], refRay.direction);\r\n\r\n return refRay;\r\n};\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Color3 } from \"../Maths/math.color\";\r\nimport { TmpVectors } from \"./math\";\r\n\r\n// https://dickyjim.wordpress.com/2013/09/04/spherical-harmonics-for-beginners/\r\n// http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf\r\n// https://www.ppsloan.org/publications/StupidSH36.pdf\r\n// http://cseweb.ucsd.edu/~ravir/papers/envmap/envmap.pdf\r\n// https://www.ppsloan.org/publications/SHJCGT.pdf\r\n// https://www.ppsloan.org/publications/shdering.pdf\r\n// https://google.github.io/filament/Filament.md.html#annex/sphericalharmonics\r\n// https://patapom.com/blog/SHPortal/\r\n// https://imdoingitwrong.wordpress.com/2011/04/14/spherical-harmonics-wtf/\r\n\r\n// Using real SH basis:\r\n// m>0 m m\r\n// y = sqrt(2) * K * P * cos(m*phi) * cos(theta)\r\n// l l l\r\n//\r\n// m<0 m |m|\r\n// y = sqrt(2) * K * P * sin(m*phi) * cos(theta)\r\n// l l l\r\n//\r\n// m=0 0 0\r\n// y = K * P * trigono terms\r\n// l l l\r\n//\r\n// m (2l + 1)(l - |m|)!\r\n// K = sqrt(------------------)\r\n// l 4pi(l + |m|)!\r\n//\r\n// and P by recursion:\r\n//\r\n// P00(x) = 1\r\n// P01(x) = x\r\n// Pll(x) = (-1^l)(2l - 1)!!(1-x*x)^(1/2)\r\n// ((2l - 1)x[Pl-1/m]-(l + m - 1)[Pl-2/m])\r\n// Plm(x) = ---------------------------------------\r\n// l - m\r\n// Leaving the trigonometric terms aside we can precompute the constants to :\r\nconst SH3ylmBasisConstants = [\r\n Math.sqrt(1 / (4 * Math.PI)), // l00\r\n\r\n -Math.sqrt(3 / (4 * Math.PI)), // l1_1\r\n Math.sqrt(3 / (4 * Math.PI)), // l10\r\n -Math.sqrt(3 / (4 * Math.PI)), // l11\r\n\r\n Math.sqrt(15 / (4 * Math.PI)), // l2_2\r\n -Math.sqrt(15 / (4 * Math.PI)), // l2_1\r\n Math.sqrt(5 / (16 * Math.PI)), // l20\r\n -Math.sqrt(15 / (4 * Math.PI)), // l21\r\n Math.sqrt(15 / (16 * Math.PI)), // l22\r\n];\r\n\r\n// cm = cos(m * phi)\r\n// sm = sin(m * phi)\r\n// {x,y,z} = {cos(phi)sin(theta), sin(phi)sin(theta), cos(theta)}\r\n// By recursion on using trigo identities:\r\nconst SH3ylmBasisTrigonometricTerms = [\r\n () => 1, // l00\r\n\r\n (direction: Vector3) => direction.y, // l1_1\r\n (direction: Vector3) => direction.z, // l10\r\n (direction: Vector3) => direction.x, // l11\r\n\r\n (direction: Vector3) => direction.x * direction.y, // l2_2\r\n (direction: Vector3) => direction.y * direction.z, // l2_1\r\n (direction: Vector3) => 3 * direction.z * direction.z - 1, // l20\r\n (direction: Vector3) => direction.x * direction.z, // l21\r\n (direction: Vector3) => direction.x * direction.x - direction.y * direction.y, // l22\r\n];\r\n\r\n// Wrap the full compute\r\nconst applySH3 = (lm: number, direction: Vector3) => {\r\n return SH3ylmBasisConstants[lm] * SH3ylmBasisTrigonometricTerms[lm](direction);\r\n};\r\n\r\n// Derived from the integration of the a kernel convolution to SH.\r\n// Great explanation here: https://patapom.com/blog/SHPortal/#about-distant-radiance-and-irradiance-environments\r\nconst SHCosKernelConvolution = [Math.PI, (2 * Math.PI) / 3, (2 * Math.PI) / 3, (2 * Math.PI) / 3, Math.PI / 4, Math.PI / 4, Math.PI / 4, Math.PI / 4, Math.PI / 4];\r\n\r\n/**\r\n * Class representing spherical harmonics coefficients to the 3rd degree\r\n */\r\nexport class SphericalHarmonics {\r\n /**\r\n * Defines whether or not the harmonics have been prescaled for rendering.\r\n */\r\n public preScaled = false;\r\n\r\n /**\r\n * The l0,0 coefficients of the spherical harmonics\r\n */\r\n public l00: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l1,-1 coefficients of the spherical harmonics\r\n */\r\n public l1_1: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l1,0 coefficients of the spherical harmonics\r\n */\r\n public l10: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l1,1 coefficients of the spherical harmonics\r\n */\r\n public l11: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l2,-2 coefficients of the spherical harmonics\r\n */\r\n public l2_2: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l2,-1 coefficients of the spherical harmonics\r\n */\r\n public l2_1: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l2,0 coefficients of the spherical harmonics\r\n */\r\n public l20: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l2,1 coefficients of the spherical harmonics\r\n */\r\n public l21: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The l2,2 coefficients of the spherical harmonics\r\n */\r\n public l22: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * Adds a light to the spherical harmonics\r\n * @param direction the direction of the light\r\n * @param color the color of the light\r\n * @param deltaSolidAngle the delta solid angle of the light\r\n */\r\n public addLight(direction: Vector3, color: Color3, deltaSolidAngle: number): void {\r\n TmpVectors.Vector3[0].set(color.r, color.g, color.b);\r\n const colorVector = TmpVectors.Vector3[0];\r\n const c = TmpVectors.Vector3[1];\r\n colorVector.scaleToRef(deltaSolidAngle, c);\r\n\r\n c.scaleToRef(applySH3(0, direction), TmpVectors.Vector3[2]);\r\n this.l00.addInPlace(TmpVectors.Vector3[2]);\r\n\r\n c.scaleToRef(applySH3(1, direction), TmpVectors.Vector3[2]);\r\n this.l1_1.addInPlace(TmpVectors.Vector3[2]);\r\n c.scaleToRef(applySH3(2, direction), TmpVectors.Vector3[2]);\r\n this.l10.addInPlace(TmpVectors.Vector3[2]);\r\n c.scaleToRef(applySH3(3, direction), TmpVectors.Vector3[2]);\r\n this.l11.addInPlace(TmpVectors.Vector3[2]);\r\n\r\n c.scaleToRef(applySH3(4, direction), TmpVectors.Vector3[2]);\r\n this.l2_2.addInPlace(TmpVectors.Vector3[2]);\r\n c.scaleToRef(applySH3(5, direction), TmpVectors.Vector3[2]);\r\n this.l2_1.addInPlace(TmpVectors.Vector3[2]);\r\n c.scaleToRef(applySH3(6, direction), TmpVectors.Vector3[2]);\r\n this.l20.addInPlace(TmpVectors.Vector3[2]);\r\n c.scaleToRef(applySH3(7, direction), TmpVectors.Vector3[2]);\r\n this.l21.addInPlace(TmpVectors.Vector3[2]);\r\n c.scaleToRef(applySH3(8, direction), TmpVectors.Vector3[2]);\r\n this.l22.addInPlace(TmpVectors.Vector3[2]);\r\n }\r\n\r\n /**\r\n * Scales the spherical harmonics by the given amount\r\n * @param scale the amount to scale\r\n */\r\n public scaleInPlace(scale: number): void {\r\n this.l00.scaleInPlace(scale);\r\n this.l1_1.scaleInPlace(scale);\r\n this.l10.scaleInPlace(scale);\r\n this.l11.scaleInPlace(scale);\r\n this.l2_2.scaleInPlace(scale);\r\n this.l2_1.scaleInPlace(scale);\r\n this.l20.scaleInPlace(scale);\r\n this.l21.scaleInPlace(scale);\r\n this.l22.scaleInPlace(scale);\r\n }\r\n\r\n /**\r\n * Convert from incident radiance (Li) to irradiance (E) by applying convolution with the cosine-weighted hemisphere.\r\n *\r\n * ```\r\n * E_lm = A_l * L_lm\r\n * ```\r\n *\r\n * In spherical harmonics this convolution amounts to scaling factors for each frequency band.\r\n * This corresponds to equation 5 in \"An Efficient Representation for Irradiance Environment Maps\", where\r\n * the scaling factors are given in equation 9.\r\n */\r\n public convertIncidentRadianceToIrradiance(): void {\r\n // Constant (Band 0)\r\n this.l00.scaleInPlace(SHCosKernelConvolution[0]);\r\n\r\n // Linear (Band 1)\r\n this.l1_1.scaleInPlace(SHCosKernelConvolution[1]);\r\n this.l10.scaleInPlace(SHCosKernelConvolution[2]);\r\n this.l11.scaleInPlace(SHCosKernelConvolution[3]);\r\n\r\n // Quadratic (Band 2)\r\n this.l2_2.scaleInPlace(SHCosKernelConvolution[4]);\r\n this.l2_1.scaleInPlace(SHCosKernelConvolution[5]);\r\n this.l20.scaleInPlace(SHCosKernelConvolution[6]);\r\n this.l21.scaleInPlace(SHCosKernelConvolution[7]);\r\n this.l22.scaleInPlace(SHCosKernelConvolution[8]);\r\n }\r\n\r\n /**\r\n * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.\r\n *\r\n * ```\r\n * L = (1/pi) * E * rho\r\n * ```\r\n *\r\n * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.\r\n */\r\n public convertIrradianceToLambertianRadiance(): void {\r\n this.scaleInPlace(1.0 / Math.PI);\r\n\r\n // The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied\r\n // (The pixel shader must apply albedo after texture fetches, etc).\r\n }\r\n\r\n /**\r\n * Integrates the reconstruction coefficients directly in to the SH preventing further\r\n * required operations at run time.\r\n *\r\n * This is simply done by scaling back the SH with Ylm constants parameter.\r\n * The trigonometric part being applied by the shader at run time.\r\n */\r\n public preScaleForRendering(): void {\r\n this.preScaled = true;\r\n\r\n this.l00.scaleInPlace(SH3ylmBasisConstants[0]);\r\n\r\n this.l1_1.scaleInPlace(SH3ylmBasisConstants[1]);\r\n this.l10.scaleInPlace(SH3ylmBasisConstants[2]);\r\n this.l11.scaleInPlace(SH3ylmBasisConstants[3]);\r\n\r\n this.l2_2.scaleInPlace(SH3ylmBasisConstants[4]);\r\n this.l2_1.scaleInPlace(SH3ylmBasisConstants[5]);\r\n this.l20.scaleInPlace(SH3ylmBasisConstants[6]);\r\n this.l21.scaleInPlace(SH3ylmBasisConstants[7]);\r\n this.l22.scaleInPlace(SH3ylmBasisConstants[8]);\r\n }\r\n\r\n /**\r\n * update the spherical harmonics coefficients from the given array\r\n * @param data defines the 9x3 coefficients (l00, l1-1, l10, l11, l2-2, l2-1, l20, l21, l22)\r\n * @returns the spherical harmonics (this)\r\n */\r\n public updateFromArray(data: ArrayLike>): SphericalHarmonics {\r\n Vector3.FromArrayToRef(data[0], 0, this.l00);\r\n Vector3.FromArrayToRef(data[1], 0, this.l1_1);\r\n Vector3.FromArrayToRef(data[2], 0, this.l10);\r\n Vector3.FromArrayToRef(data[3], 0, this.l11);\r\n Vector3.FromArrayToRef(data[4], 0, this.l2_2);\r\n Vector3.FromArrayToRef(data[5], 0, this.l2_1);\r\n Vector3.FromArrayToRef(data[6], 0, this.l20);\r\n Vector3.FromArrayToRef(data[7], 0, this.l21);\r\n Vector3.FromArrayToRef(data[8], 0, this.l22);\r\n return this;\r\n }\r\n\r\n /**\r\n * update the spherical harmonics coefficients from the given floats array\r\n * @param data defines the 9x3 coefficients (l00, l1-1, l10, l11, l2-2, l2-1, l20, l21, l22)\r\n * @returns the spherical harmonics (this)\r\n */\r\n public updateFromFloatsArray(data: ArrayLike): SphericalHarmonics {\r\n Vector3.FromFloatsToRef(data[0], data[1], data[2], this.l00);\r\n Vector3.FromFloatsToRef(data[3], data[4], data[5], this.l1_1);\r\n Vector3.FromFloatsToRef(data[6], data[7], data[8], this.l10);\r\n Vector3.FromFloatsToRef(data[9], data[10], data[11], this.l11);\r\n Vector3.FromFloatsToRef(data[12], data[13], data[14], this.l2_2);\r\n Vector3.FromFloatsToRef(data[15], data[16], data[17], this.l2_1);\r\n Vector3.FromFloatsToRef(data[18], data[19], data[20], this.l20);\r\n Vector3.FromFloatsToRef(data[21], data[22], data[23], this.l21);\r\n Vector3.FromFloatsToRef(data[24], data[25], data[26], this.l22);\r\n return this;\r\n }\r\n\r\n /**\r\n * Constructs a spherical harmonics from an array.\r\n * @param data defines the 9x3 coefficients (l00, l1-1, l10, l11, l2-2, l2-1, l20, l21, l22)\r\n * @returns the spherical harmonics\r\n */\r\n public static FromArray(data: ArrayLike>): SphericalHarmonics {\r\n const sh = new SphericalHarmonics();\r\n return sh.updateFromArray(data);\r\n }\r\n\r\n // Keep for references.\r\n /**\r\n * Gets the spherical harmonics from polynomial\r\n * @param polynomial the spherical polynomial\r\n * @returns the spherical harmonics\r\n */\r\n public static FromPolynomial(polynomial: SphericalPolynomial): SphericalHarmonics {\r\n const result = new SphericalHarmonics();\r\n\r\n result.l00 = polynomial.xx.scale(0.376127).add(polynomial.yy.scale(0.376127)).add(polynomial.zz.scale(0.376126));\r\n result.l1_1 = polynomial.y.scale(0.977204);\r\n result.l10 = polynomial.z.scale(0.977204);\r\n result.l11 = polynomial.x.scale(0.977204);\r\n result.l2_2 = polynomial.xy.scale(1.16538);\r\n result.l2_1 = polynomial.yz.scale(1.16538);\r\n result.l20 = polynomial.zz.scale(1.34567).subtract(polynomial.xx.scale(0.672834)).subtract(polynomial.yy.scale(0.672834));\r\n result.l21 = polynomial.zx.scale(1.16538);\r\n result.l22 = polynomial.xx.scale(1.16538).subtract(polynomial.yy.scale(1.16538));\r\n\r\n result.l1_1.scaleInPlace(-1);\r\n result.l11.scaleInPlace(-1);\r\n result.l2_1.scaleInPlace(-1);\r\n result.l21.scaleInPlace(-1);\r\n\r\n result.scaleInPlace(Math.PI);\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * Class representing spherical polynomial coefficients to the 3rd degree\r\n */\r\nexport class SphericalPolynomial {\r\n private _harmonics: Nullable;\r\n\r\n /**\r\n * The spherical harmonics used to create the polynomials.\r\n */\r\n public get preScaledHarmonics(): SphericalHarmonics {\r\n if (!this._harmonics) {\r\n this._harmonics = SphericalHarmonics.FromPolynomial(this);\r\n }\r\n if (!this._harmonics.preScaled) {\r\n this._harmonics.preScaleForRendering();\r\n }\r\n return this._harmonics;\r\n }\r\n\r\n /**\r\n * The x coefficients of the spherical polynomial\r\n */\r\n public x: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The y coefficients of the spherical polynomial\r\n */\r\n public y: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The z coefficients of the spherical polynomial\r\n */\r\n public z: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The xx coefficients of the spherical polynomial\r\n */\r\n public xx: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The yy coefficients of the spherical polynomial\r\n */\r\n public yy: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The zz coefficients of the spherical polynomial\r\n */\r\n public zz: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The xy coefficients of the spherical polynomial\r\n */\r\n public xy: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The yz coefficients of the spherical polynomial\r\n */\r\n public yz: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * The zx coefficients of the spherical polynomial\r\n */\r\n public zx: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * Adds an ambient color to the spherical polynomial\r\n * @param color the color to add\r\n */\r\n public addAmbient(color: Color3): void {\r\n TmpVectors.Vector3[0].copyFromFloats(color.r, color.g, color.b);\r\n const colorVector = TmpVectors.Vector3[0];\r\n this.xx.addInPlace(colorVector);\r\n this.yy.addInPlace(colorVector);\r\n this.zz.addInPlace(colorVector);\r\n }\r\n\r\n /**\r\n * Scales the spherical polynomial by the given amount\r\n * @param scale the amount to scale\r\n */\r\n public scaleInPlace(scale: number) {\r\n this.x.scaleInPlace(scale);\r\n this.y.scaleInPlace(scale);\r\n this.z.scaleInPlace(scale);\r\n this.xx.scaleInPlace(scale);\r\n this.yy.scaleInPlace(scale);\r\n this.zz.scaleInPlace(scale);\r\n this.yz.scaleInPlace(scale);\r\n this.zx.scaleInPlace(scale);\r\n this.xy.scaleInPlace(scale);\r\n }\r\n\r\n /**\r\n * Updates the spherical polynomial from harmonics\r\n * @param harmonics the spherical harmonics\r\n * @returns the spherical polynomial\r\n */\r\n public updateFromHarmonics(harmonics: SphericalHarmonics): SphericalPolynomial {\r\n this._harmonics = harmonics;\r\n\r\n this.x.copyFrom(harmonics.l11);\r\n this.x.scaleInPlace(1.02333).scaleInPlace(-1);\r\n this.y.copyFrom(harmonics.l1_1);\r\n this.y.scaleInPlace(1.02333).scaleInPlace(-1);\r\n this.z.copyFrom(harmonics.l10);\r\n this.z.scaleInPlace(1.02333);\r\n\r\n this.xx.copyFrom(harmonics.l00);\r\n TmpVectors.Vector3[0].copyFrom(harmonics.l20).scaleInPlace(0.247708);\r\n TmpVectors.Vector3[1].copyFrom(harmonics.l22).scaleInPlace(0.429043);\r\n this.xx.scaleInPlace(0.886277).subtractInPlace(TmpVectors.Vector3[0]).addInPlace(TmpVectors.Vector3[1]);\r\n this.yy.copyFrom(harmonics.l00);\r\n this.yy.scaleInPlace(0.886277).subtractInPlace(TmpVectors.Vector3[0]).subtractInPlace(TmpVectors.Vector3[1]);\r\n this.zz.copyFrom(harmonics.l00);\r\n TmpVectors.Vector3[0].copyFrom(harmonics.l20).scaleInPlace(0.495417);\r\n this.zz.scaleInPlace(0.886277).addInPlace(TmpVectors.Vector3[0]);\r\n\r\n this.yz.copyFrom(harmonics.l2_1);\r\n this.yz.scaleInPlace(0.858086).scaleInPlace(-1);\r\n this.zx.copyFrom(harmonics.l21);\r\n this.zx.scaleInPlace(0.858086).scaleInPlace(-1);\r\n this.xy.copyFrom(harmonics.l2_2);\r\n this.xy.scaleInPlace(0.858086);\r\n\r\n this.scaleInPlace(1.0 / Math.PI);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the spherical polynomial from harmonics\r\n * @param harmonics the spherical harmonics\r\n * @returns the spherical polynomial\r\n */\r\n public static FromHarmonics(harmonics: SphericalHarmonics): SphericalPolynomial {\r\n const result = new SphericalPolynomial();\r\n return result.updateFromHarmonics(harmonics);\r\n }\r\n\r\n /**\r\n * Constructs a spherical polynomial from an array.\r\n * @param data defines the 9x3 coefficients (x, y, z, xx, yy, zz, yz, zx, xy)\r\n * @returns the spherical polynomial\r\n */\r\n public static FromArray(data: ArrayLike>): SphericalPolynomial {\r\n const sp = new SphericalPolynomial();\r\n Vector3.FromArrayToRef(data[0], 0, sp.x);\r\n Vector3.FromArrayToRef(data[1], 0, sp.y);\r\n Vector3.FromArrayToRef(data[2], 0, sp.z);\r\n Vector3.FromArrayToRef(data[3], 0, sp.xx);\r\n Vector3.FromArrayToRef(data[4], 0, sp.yy);\r\n Vector3.FromArrayToRef(data[5], 0, sp.zz);\r\n Vector3.FromArrayToRef(data[6], 0, sp.yz);\r\n Vector3.FromArrayToRef(data[7], 0, sp.zx);\r\n Vector3.FromArrayToRef(data[8], 0, sp.xy);\r\n return sp;\r\n }\r\n}\r\n","import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';\r\nimport { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { Ray } from '@babylonjs/core/Culling/ray';\r\nimport { Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport type { IKbVectorLike } from '@models/classes/primitives/kb-vector';\r\n\r\nconst ray1 = Ray.Zero();\r\nconst vector1 = Vector3.Zero();\r\nconst vector2 = Vector3.Zero();\r\nconst vector3 = Vector3.Zero();\r\n\r\nexport type RoundDirection = 'ceil' | 'floor' | 'round';\r\n\r\nexport function getCameraPositionWithOffset(camera: Camera) {\r\n if (camera instanceof ArcRotateCamera) {\r\n camera.getForwardRayToRef(ray1);\r\n Vector3.CrossToRef(ray1.direction, Vector3.Up(), vector1);\r\n Vector3.CrossToRef(ray1.direction, vector1, vector2);\r\n vector1.normalize().scaleInPlace(-camera.targetScreenOffset.x);\r\n vector2.normalize().scaleInPlace(camera.targetScreenOffset.y);\r\n vector3.copyFrom(camera.globalPosition);\r\n vector3.addInPlace(vector1).addInPlace(vector2);\r\n\r\n return vector3;\r\n } else {\r\n return camera.globalPosition;\r\n }\r\n}\r\n\r\nexport function toRadians(degrees: number) {\r\n const scalar = Math.PI / 180;\r\n return degrees * scalar;\r\n}\r\n\r\nexport function roundVectorToPlaces(vector: Vector3, significance = 1, direction?: RoundDirection) {\r\n vector.x = roundToPlaces(vector.x, significance, direction);\r\n vector.y = roundToPlaces(vector.y, significance, direction);\r\n vector.z = roundToPlaces(vector.z, significance, direction);\r\n}\r\n\r\nexport function roundToPlaces(value: number, significance = 1, direction: RoundDirection = 'round') {\r\n const isRound = Math.round(value / significance) * significance === value;\r\n if (isRound) {\r\n return value;\r\n }\r\n const n = (value / significance) * (1 + Number.EPSILON);\r\n let tmp: number;\r\n if (direction === 'ceil') {\r\n tmp = Math.ceil(n);\r\n } else if (direction === 'floor') {\r\n tmp = Math.floor(n);\r\n } else {\r\n tmp = Math.round(n);\r\n }\r\n return tmp * significance;\r\n}\r\n\r\nexport function rotationToVector(toVector: Vector3, fromVector?: Vector3) {\r\n const result = new Quaternion();\r\n if (!fromVector) {\r\n fromVector = new Vector3(0, 1, 0);\r\n }\r\n rotationToVectorToRef(toVector, fromVector, result);\r\n\r\n return result;\r\n}\r\n\r\nexport function transformVectorWithQuat(vector: Vector3, quat: Quaternion) {\r\n const transform = new Matrix();\r\n quat.toRotationMatrix(transform);\r\n const transformVector = Vector3.TransformCoordinates(vector, transform);\r\n return transformVector;\r\n}\r\n\r\nexport function applyTransformToVector(vector: IKbVectorLike, transform: Matrix) {\r\n const v = new Vector3(vector.x, vector.y, vector.z);\r\n const matrix = Matrix.Compose(new Vector3(1, 1, 1), Quaternion.Identity(), v);\r\n return applyTransformToSpace(matrix, transform);\r\n}\r\n\r\nexport function applyTransformToSpace(worldTransform: Matrix | number[], inSpace?: Matrix) {\r\n if (!inSpace) {\r\n inSpace = Matrix.Identity();\r\n }\r\n const inSpaceInv = inSpace.clone().invert();\r\n\r\n if (Array.isArray(worldTransform)) {\r\n worldTransform = Matrix.FromArray(worldTransform);\r\n }\r\n\r\n const spaceTransform = inSpace.multiply(worldTransform);\r\n spaceTransform.multiplyToRef(inSpaceInv, spaceTransform);\r\n\r\n const t = new Vector3();\r\n const q = new Quaternion();\r\n const s = new Vector3();\r\n spaceTransform.decompose(s, q, t);\r\n\r\n return {\r\n position: { x: t.x, y: t.y, z: t.z } as IKbVectorLike,\r\n rotation: KbQuaternion.FromQuat(q),\r\n scaling: { x: s.x, y: s.y, z: s.z } as IKbVectorLike,\r\n };\r\n\r\n // const fromSpaceRotation = fromSpace.rotationQuaternion ? fromSpace.rotationQuaternion : Quaternion.Identity();\r\n // const toSpaceRotation = toSpace.rotationQuaternion ? toSpace.rotationQuaternion : Quaternion.Identity();\r\n\r\n // const fromSpaceRotationInverse = fromSpaceRotation.clone().invert();\r\n // const toSpaceRotationInverse = toSpaceRotation.clone().invert();\r\n\r\n // const q1 = q.clone().multiply(fromSpaceRotationInverse);\r\n // const q2 = toSpaceRotationInverse.multiply(q1);\r\n // const q3 = q2.multiply(toSpaceRotation);\r\n\r\n // return q3;\r\n}\r\n\r\nexport function computeLocalTransform(node: MeshNode) {\r\n let rotation: Quaternion;\r\n if (node.useEuler) {\r\n rotation = Quaternion.FromEulerAngles(\r\n toRadians(node.eulerRotation.x),\r\n toRadians(node.eulerRotation.y),\r\n toRadians(node.eulerRotation.z)\r\n );\r\n } else {\r\n rotation = Quaternion.RotationAxis(node.rotationAxis.toVec3(), node.rotationAngle * (Math.PI / 180));\r\n }\r\n\r\n const pivotTransform = node.pivot ? Matrix.Translation(-node.pivot.x, -node.pivot.y, -node.pivot.z) : undefined;\r\n\r\n const scalingTransform = Matrix.Scaling(node.scaling, node.scaling, node.scaling);\r\n const rotationTransform = new Matrix();\r\n Matrix.FromQuaternionToRef(rotation, rotationTransform);\r\n const translationTransform = Matrix.Translation(node.position.x, node.position.y, node.position.z);\r\n\r\n const transform = Matrix.Identity();\r\n if (pivotTransform) {\r\n transform.multiplyToRef(pivotTransform, transform);\r\n }\r\n transform.multiplyToRef(scalingTransform, transform);\r\n transform.multiplyToRef(rotationTransform, transform);\r\n transform.multiplyToRef(translationTransform, transform);\r\n if (pivotTransform) {\r\n transform.multiplyToRef(pivotTransform.invert(), transform);\r\n }\r\n\r\n return transform;\r\n}\r\n\r\nexport function rotationToVectorToRef(_toVector: Vector3, _fromVector: Vector3, result: Quaternion) {\r\n const toVector = _toVector.clone().normalize();\r\n const fromVector = _fromVector.clone().normalize();\r\n\r\n if (Vector3.Dot(fromVector, toVector) > 0.9999999) {\r\n result.set(0, 0, 0, 1); // Identity Quaternion\r\n }\r\n if (Vector3.Dot(fromVector, toVector) < -0.9999999) {\r\n // Rotate 180 degrees about arbitrary axis\r\n return Quaternion.RotationAxisToRef(\r\n Vector3.Right().equals(toVector) ? Vector3.Up().cross(toVector) : Vector3.Right().cross(toVector),\r\n Math.PI,\r\n result\r\n );\r\n }\r\n const rotAxis = toVector.cross(fromVector);\r\n const w = -Math.acos(Vector3.Dot(fromVector, toVector));\r\n\r\n return Quaternion.RotationAxisToRef(rotAxis, w, result);\r\n}\r\n\r\nexport function degreeToRadian(vectorDegree: Vector3, optionalResult?: Vector3): Vector3 {\r\n optionalResult = optionalResult || new Vector3();\r\n if (vectorDegree !== optionalResult) {\r\n optionalResult.copyFrom(vectorDegree);\r\n }\r\n return multiplyScalar(optionalResult, Math.PI / 180);\r\n}\r\n\r\nexport function multiplyScalar(vec: Vector3, scalar: number): Vector3 {\r\n vec.x *= scalar;\r\n vec.y *= scalar;\r\n vec.z *= scalar;\r\n return vec;\r\n}\r\n\r\nexport function computeNormal(normals: Vector3[]): Vector3 {\r\n const vertex1 = normals[0];\r\n const vertex2 = normals[1];\r\n const vertex3 = normals[2];\r\n const p1p2 = vertex1.subtract(vertex2);\r\n const p3p2 = vertex3.subtract(vertex2);\r\n\r\n const normal = Vector3.Normalize(Vector3.Cross(p1p2, p3p2));\r\n return normal;\r\n}\r\n\r\nexport function applyMatrix4(thisVect: Vector3, m: Matrix) {\r\n const x = thisVect.x,\r\n y = thisVect.y,\r\n z = thisVect.z;\r\n const e = m.asArray();\r\n thisVect.x = e[0] * x + e[4] * y + e[8] * z + e[12];\r\n thisVect.y = e[1] * x + e[5] * y + e[9] * z + e[13];\r\n thisVect.z = e[2] * x + e[6] * y + e[10] * z + e[14];\r\n return thisVect;\r\n}\r\n\r\nexport function mathClamp(x: number, a: number, b: number): number {\r\n return x < a ? a : x > b ? b : x;\r\n}\r\n\r\nexport function makeRotationAxis(axis: Vector3, angle: number): Matrix {\r\n const c = Math.cos(angle);\r\n const s = Math.sin(angle);\r\n const t = 1 - c;\r\n const x = axis.x,\r\n y = axis.y,\r\n z = axis.z;\r\n const tx = t * x,\r\n ty = t * y;\r\n const matrix = Matrix.FromValues(\r\n tx * x + c,\r\n tx * y - s * z,\r\n tx * z + s * y,\r\n 0,\r\n tx * y + s * z,\r\n ty * y + c,\r\n ty * z - s * x,\r\n 0,\r\n tx * z - s * y,\r\n ty * z + s * x,\r\n t * z * z + c,\r\n 0,\r\n 0,\r\n 0,\r\n 0,\r\n 1\r\n );\r\n return matrix;\r\n}\r\n\r\nexport function getRotationBtwVectors(u: Vector3, v: Vector3) {\r\n //http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final\r\n v.clone().normalize();\r\n u.clone().normalize();\r\n const dot = Vector3.Dot(u, v);\r\n const k = 1; //we are using unit vectors, so just use \"1\" instead of: Math.sqrt(u.length()^2 * v.length()^2);\r\n let w = k + dot;\r\n let r: Vector3;\r\n\r\n if (w < 0.0000001) {\r\n /* If u and v are exactly opposite, rotate 180 degrees\r\n * around an arbitrary orthogonal axis. Axis normalisation\r\n * can happen later, when we normalise the quaternion. */\r\n w = 0;\r\n r = Math.abs(u.x) > Math.abs(u.z) ? new Vector3(-u.y, u.x, 0) : new Vector3(0, -u.z, u.y);\r\n } else {\r\n r = Vector3.Cross(u, v);\r\n }\r\n\r\n return new Quaternion(r.x, r.y, r.z, w).normalize();\r\n}\r\n\r\nexport function addArrays(arrayA: number[], arrayB: number[]) {\r\n if (arrayA.length == 0) {\r\n return arrayB;\r\n }\r\n if (arrayB.length == 0) {\r\n return arrayA;\r\n }\r\n const result = [];\r\n const n = Math.min(arrayA.length, arrayB.length);\r\n for (let i = 0; i < n; i++) {\r\n result[i] = arrayA[i] + arrayB[i];\r\n }\r\n return result;\r\n}\r\n\r\nexport enum AxisType {\r\n X = 1,\r\n Y = 2,\r\n Z = 3,\r\n Custom = 4,\r\n}\r\n","import { Ignore } from '../decorators/inject-decorator';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IKbQuaternion } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { KbVector } from './kb-vector';\r\n\r\nexport interface IKbQuaternionLike {\r\n x: number;\r\n y: number;\r\n z: number;\r\n w: number;\r\n}\r\n\r\n@Kb3dModel({\r\n token: Token.KbQuaternion,\r\n trackChanges: false,\r\n create: args => new KbQuaternion(args.x || 0, args.y || 0, args.z || 0, args.w || 1),\r\n})\r\nexport class KbQuaternion implements IKbQuaternion {\r\n constructor(\r\n @Ignore() readonly x: number,\r\n @Ignore() readonly y: number,\r\n @Ignore() readonly z: number,\r\n @Ignore() readonly w: number\r\n ) {\r\n if (this.w > 1) {\r\n this.w = 1;\r\n }\r\n if (this.w < -1) {\r\n this.w = -1;\r\n }\r\n }\r\n\r\n clone() {\r\n return new KbQuaternion(this.x, this.y, this.z, this.w);\r\n }\r\n\r\n assign(v: { x?: number | null; y?: number | null; z?: number | null; w?: number | null }) {\r\n return new KbQuaternion(\r\n typeof v.x === 'number' ? v.x : this.x,\r\n typeof v.y === 'number' ? v.y : this.y,\r\n typeof v.z === 'number' ? v.z : this.z,\r\n typeof v.w === 'number' ? v.w : this.w\r\n );\r\n }\r\n\r\n toEuler(): KbVector {\r\n let x: number, y: number, z: number;\r\n\r\n const qz = this.z;\r\n const qx = this.x;\r\n const qy = this.y;\r\n const qw = this.w;\r\n const sqw = qw * qw;\r\n const sqz = qz * qz;\r\n const sqx = qx * qx;\r\n const sqy = qy * qy;\r\n const zAxisY = qy * qz - qx * qw;\r\n const limit = 0.4999999;\r\n if (zAxisY < -limit) {\r\n y = 2 * Math.atan2(qy, qw);\r\n x = Math.PI / 2;\r\n z = 0;\r\n } else if (zAxisY > limit) {\r\n y = 2 * Math.atan2(qy, qw);\r\n x = -Math.PI / 2;\r\n z = 0;\r\n } else {\r\n z = Math.atan2(2.0 * (qx * qy + qz * qw), -sqz - sqx + sqy + sqw);\r\n x = Math.asin(-2.0 * (qz * qy - qx * qw));\r\n y = Math.atan2(2.0 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);\r\n }\r\n\r\n const scalar = 180 / Math.PI;\r\n\r\n return new KbVector(x * scalar, y * scalar, z * scalar);\r\n }\r\n\r\n multiply(q: { x: number; y: number; z: number; w: number }) {\r\n const x = this.x * q.w + this.y * q.z - this.z * q.y + this.w * q.x;\r\n const y = -this.x * q.z + this.y * q.w + this.z * q.x + this.w * q.y;\r\n const z = this.x * q.y - this.y * q.x + this.z * q.w + this.w * q.z;\r\n const w = -this.x * q.x - this.y * q.y - this.z * q.z + this.w * q.w;\r\n\r\n return new KbQuaternion(x, y, z, w);\r\n }\r\n\r\n equal(q: IKbQuaternionLike | undefined): boolean {\r\n return (\r\n !!q &&\r\n basicallyEqual(q.x, this.x) &&\r\n basicallyEqual(q.y, this.y) &&\r\n basicallyEqual(q.z, this.z) &&\r\n basicallyEqual(q.w, this.w)\r\n );\r\n }\r\n\r\n toObject() {\r\n return { x: this.x, y: this.y, z: this.z, w: this.w } as IKbQuaternionLike;\r\n }\r\n\r\n getAngle() {\r\n return this._getRadAngle() * (180 / Math.PI);\r\n }\r\n\r\n private _getRadAngle() {\r\n return Math.acos(this.w) * 2;\r\n }\r\n\r\n getAxis() {\r\n const angle = this._getRadAngle();\r\n const sin = Math.sin(angle / 2);\r\n\r\n if (sin === 0) {\r\n return KbVector.Zero();\r\n } else {\r\n return new KbVector(this.x / sin, this.y / sin, this.z / sin).normalize();\r\n }\r\n }\r\n\r\n static FromRotationAxis(axis: KbVector, angle: number) {\r\n // var sin = Math.sin(angle / 2);\r\n // axis.normalize();\r\n // result.w = Math.cos(angle / 2);\r\n // result.x = axis._x * sin;\r\n // result.y = axis._y * sin;\r\n // result.z = axis._z * sin;\r\n\r\n const rad = (angle * Math.PI) / 180;\r\n const sin = Math.sin(rad / 2);\r\n const nAxis = axis.normalize();\r\n const result = new KbQuaternion(nAxis.x * sin, nAxis.y * sin, nAxis.z * sin, Math.cos(rad / 2));\r\n return result;\r\n }\r\n\r\n static FromYawPitchRoll(dV: KbVector) {\r\n const v = dV.scale(Math.PI / 180);\r\n const halfRoll = v.z * 0.5;\r\n const halfPitch = v.x * 0.5;\r\n const halfYaw = v.y * 0.5;\r\n const sinRoll = Math.sin(halfRoll);\r\n const cosRoll = Math.cos(halfRoll);\r\n const sinPitch = Math.sin(halfPitch);\r\n const cosPitch = Math.cos(halfPitch);\r\n const sinYaw = Math.sin(halfYaw);\r\n const cosYaw = Math.cos(halfYaw);\r\n const result = new KbQuaternion(\r\n cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll,\r\n sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll,\r\n cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll,\r\n cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll\r\n );\r\n\r\n return result;\r\n }\r\n\r\n static Identity() {\r\n return new KbQuaternion(0, 0, 0, 1);\r\n }\r\n\r\n static From(q: IKbQuaternionLike) {\r\n return new KbQuaternion(q.x, q.y, q.z, q.w);\r\n }\r\n}\r\n\r\nfunction basicallyEqual(a: number, b: number) {\r\n return Math.abs(a - b) < 0.0000000001; // To deal with floating point errors\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { IBoxNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.BoxNode,\r\n})\r\nexport class BoxNode extends PrimitiveMeshNode implements IBoxNode {\r\n public constructor() {\r\n super();\r\n }\r\n public height: number;\r\n public width: number;\r\n public depth: number;\r\n public tessellation: number;\r\n}\r\n\r\nexport function isBoxMesh(node: Kb3dObject): node is BoxNode {\r\n return instanceOf(node, Token.BoxNode);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { ICylinderNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.ConeNode,\r\n})\r\nexport class ConeNode extends PrimitiveMeshNode implements ICylinderNode {\r\n public constructor() {\r\n super();\r\n }\r\n public height: number;\r\n public radiusTop: number;\r\n public radiusBottom: number;\r\n public tessellation: number;\r\n}\r\n\r\nexport function isConeMesh(node: Kb3dObject): node is ConeNode {\r\n return instanceOf(node, Token.ConeNode);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { eCylinderCap } from '../enums';\r\nimport { ICylinderNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.CylinderNode,\r\n})\r\nexport class CylinderNode extends PrimitiveMeshNode implements ICylinderNode {\r\n public constructor() {\r\n super();\r\n }\r\n public height: number;\r\n public radius: number;\r\n public arc: number;\r\n\r\n public tessellation: number;\r\n public subdivisions: number;\r\n public capMode: eCylinderCap;\r\n}\r\n\r\nexport function isCylinderMesh(node: Kb3dObject): node is CylinderNode {\r\n return instanceOf(node, Token.CylinderNode);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { IDiscNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.DiscNode,\r\n})\r\nexport class DiscNode extends PrimitiveMeshNode implements IDiscNode {\r\n public constructor() {\r\n super();\r\n }\r\n public radius: number;\r\n public tessellation: number;\r\n}\r\n\r\nexport function isDiscMesh(node: Kb3dObject): node is DiscNode {\r\n return instanceOf(node, Token.DiscNode);\r\n}\r\n","import { isTrackedInstanceOfAny, ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { AnnotationNode } from '../annotations';\r\nimport { instanceOf, instanceOfAny } from '../decorators/model-utils';\r\nimport { SketchControlPoint } from '../features/sketch-control-point';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { CustomMeshNode } from './custom-mesh-node';\r\nimport { MeshGroupNode } from './mesh-group-node';\r\nimport { MeshNode } from './mesh-node';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\nimport { SketchNode } from './sketch-node';\r\nimport { SpaceNode } from './space-node';\r\nimport { TextNode } from './text-node';\r\n\r\nexport function isMeshGroupNode(node: Kb3dObject): node is MeshGroupNode {\r\n return instanceOf(node, Token.MeshGroupNode);\r\n}\r\n\r\nexport function isCustomMeshNode(node: Kb3dObject): node is CustomMeshNode {\r\n return instanceOf(node, Token.CustomMeshNode);\r\n}\r\n\r\nexport function isSketchNode(node: Kb3dObject): node is SketchNode {\r\n return instanceOf(node, Token.SketchNode);\r\n}\r\n\r\nexport function isTextNode(node: Kb3dObject): node is TextNode {\r\n return instanceOf(node, Token.TextNode);\r\n}\r\n\r\nexport function isSketchControlPoint(node: Kb3dObject): node is SketchControlPoint {\r\n return instanceOf(node, Token.SketchControlPoint);\r\n}\r\n\r\nexport function isMeshNode(node: Kb3dObject): node is MeshNode {\r\n return instanceOfAny(node, ...Token.MeshTokens);\r\n}\r\n\r\nexport function isPrimitiveMeshNode(node: Kb3dObject): node is PrimitiveMeshNode {\r\n return instanceOf(node, Token.PrimitiveMeshNode);\r\n}\r\n\r\nexport function isSpaceNode(node: Kb3dObject): node is SpaceNode {\r\n return instanceOf(node, Token.SpaceNode);\r\n}\r\n\r\nexport function isPickable(node: Kb3dObject): node is SpaceNode | AnnotationNode {\r\n if (node instanceof SpaceNode || node instanceof AnnotationNode) {\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n}\r\n\r\nexport function isTrackedMeshNode(node: Kb3dObject): node is ITrackedClass {\r\n return isMeshNode(node) && isTrackedInstanceOfAny(node, ...Token.MeshAndGroupTokens);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { IPlaneNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.PlaneNode,\r\n})\r\nexport class PlaneNode extends PrimitiveMeshNode implements IPlaneNode {\r\n public constructor() {\r\n super();\r\n }\r\n public depth: number;\r\n public width: number;\r\n public segments: number;\r\n}\r\n\r\nexport function isPlaneMesh(node: Kb3dObject): node is PlaneNode {\r\n return instanceOf(node, Token.PlaneNode);\r\n}\r\n","import { RoundDirection, roundToPlaces } from '@view/helpers/math-helper';\r\nimport { Ignore } from '../decorators/inject-decorator';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { Token } from '../token';\r\n\r\nexport interface IKbVectorLike {\r\n x: number;\r\n y: number;\r\n z: number;\r\n}\r\n\r\n@Kb3dModel({\r\n token: Token.KbVector,\r\n trackChanges: false,\r\n create: args => new KbVector(args.x || 0, args.y || 0, args.z || 0),\r\n})\r\nexport class KbVector implements IKbVectorLike {\r\n constructor(@Ignore() readonly x: number, @Ignore() readonly y: number, @Ignore() readonly z: number) {\r\n if (!isFinite(x) || isNaN(x)) {\r\n this.x = 0;\r\n console.error(\r\n 'Error: Non numeric or infinite value detected in x-value of a vector, please check snapcode for mistakes.'\r\n );\r\n }\r\n if (!isFinite(y) || isNaN(y)) {\r\n this.y = 0;\r\n console.error(\r\n 'Error: Non numeric or infinite value detected in y-value of a vector, please check snapcode for mistakes.'\r\n );\r\n }\r\n if (!isFinite(z) || isNaN(z)) {\r\n this.z = 0;\r\n console.error(\r\n 'Error: Non numeric or infinite value detected in z-value of a vector, please check snapcode for mistakes.'\r\n );\r\n }\r\n }\r\n\r\n add(v: IKbVectorLike): KbVector {\r\n return new KbVector(this.x + v.x, this.y + v.y, this.z + v.z);\r\n }\r\n subtract(v: IKbVectorLike): KbVector {\r\n return new KbVector(this.x - v.x, this.y - v.y, this.z - v.z);\r\n }\r\n multiply(v: IKbVectorLike): KbVector {\r\n return new KbVector(this.x * v.x, this.y * v.y, this.z * v.z);\r\n }\r\n divide(v: { x: number; y: number; z: number }): KbVector {\r\n const newX = v.x !== 0 ? this.x / v.x : 0;\r\n const newY = v.y !== 0 ? this.y / v.y : 0;\r\n const newZ = v.z !== 0 ? this.z / v.z : 0;\r\n return new KbVector(newX, newY, newZ);\r\n }\r\n crossProduct(v: IKbVectorLike) {\r\n const x = this.y * v.z - this.z * v.y;\r\n const y = this.z * v.x - this.x * v.z;\r\n const z = this.x * v.y - this.y * v.x;\r\n return new KbVector(x, y, z);\r\n }\r\n dotProduct(v: IKbVectorLike) {\r\n return this.x * v.x + this.y * v.y + this.z * v.z;\r\n }\r\n length() {\r\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\r\n }\r\n normalize() {\r\n const l = this.length();\r\n if (l === 0 || l === 1.0) {\r\n return this.clone();\r\n }\r\n return this.scale(1.0 / l);\r\n }\r\n scale(s: number): KbVector {\r\n return new KbVector(this.x * s, this.y * s, this.z * s);\r\n }\r\n equal(v: IKbVectorLike): boolean {\r\n return v.x == this.x && v.y == this.y && v.z == this.z;\r\n }\r\n clone(): KbVector {\r\n return new KbVector(this.x, this.y, this.z);\r\n }\r\n assign(v: { x?: number | null; y?: number | null; z?: number | null }) {\r\n return new KbVector(\r\n typeof v.x === 'number' ? v.x : this.x,\r\n typeof v.y === 'number' ? v.y : this.y,\r\n typeof v.z === 'number' ? v.z : this.z\r\n );\r\n }\r\n shiftClone(component: 'x' | 'y' | 'z', amount: number) {\r\n if (component === 'x') {\r\n return new KbVector(amount, this.y, this.z);\r\n } else if (component === 'y') {\r\n return new KbVector(this.x, amount, this.z);\r\n } else {\r\n return new KbVector(this.x, this.y, amount);\r\n }\r\n }\r\n\r\n toString() {\r\n return `{ x: ${this.x}, y: ${this.y}, z: ${this.z} }`;\r\n }\r\n toObject() {\r\n return { x: this.x, y: this.y, z: this.z } as IKbVectorLike;\r\n }\r\n round(significance = 1, direction?: RoundDirection) {\r\n return new KbVector(\r\n roundToPlaces(this.x, significance, direction),\r\n roundToPlaces(this.y, significance, direction),\r\n roundToPlaces(this.z, significance, direction)\r\n );\r\n }\r\n static Zero() {\r\n return new KbVector(0, 0, 0);\r\n }\r\n static Identity() {\r\n return new KbVector(1, 1, 1);\r\n }\r\n static From(v: IKbVectorLike) {\r\n return new KbVector(v.x, v.y, v.z);\r\n }\r\n}\r\n","import { BaseKb3dModel } from '../decorators';\r\nimport { Enumerable } from '../decorators/enumerable';\r\nimport { Connector } from '../features/connector';\r\nimport { Feature } from '../features/feature';\r\nimport { ISpaceNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { KbQuaternion } from '../primitives/kb-quaternion';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\n\r\n@BaseKb3dModel({\r\n token: Token.SpaceNode,\r\n})\r\nexport abstract class SpaceNode extends Kb3dObject implements ISpaceNode {\r\n constructor() {\r\n super();\r\n // this._rotationQuaternion = nodeConfig.rotationQuaternion ? KbQuaternion.FromVec3(nodeConfig.rotationQuaternion) : KbQuaternion.Identity();\r\n // this._rotation = this._rotationQuaternion.toEuler();\r\n }\r\n visible: boolean;\r\n position: KbVector;\r\n useEuler: boolean;\r\n eulerRotation: KbVector;\r\n rotationAngle: number;\r\n rotationAxis: KbVector;\r\n scaling: number;\r\n pivot: KbVector;\r\n fixed: boolean;\r\n _primeMover: boolean;\r\n /** override base parent for more specific typing*/\r\n _parent: SpaceNode | undefined;\r\n _showPivot = false;\r\n\r\n preTransform?: number[];\r\n\r\n getRotationQuaternion() {\r\n if (this.useEuler && this.eulerRotation) {\r\n return KbQuaternion.FromYawPitchRoll(this.eulerRotation);\r\n } else if (this.rotationAxis && this.rotationAngle !== undefined) {\r\n return KbQuaternion.FromRotationAxis(this.rotationAxis, this.rotationAngle);\r\n }\r\n return KbQuaternion.Identity();\r\n }\r\n setRotationQuaternion(q: KbQuaternion) {\r\n if (this.useEuler) {\r\n this.eulerRotation = q.toEuler();\r\n } else {\r\n this.rotationAngle = q.getAngle();\r\n this.rotationAxis = q.getAxis();\r\n }\r\n }\r\n\r\n private _features: Feature[];\r\n @Enumerable()\r\n public get features(): Feature[] {\r\n if (!this._features) this._features = [];\r\n return this._features;\r\n }\r\n public set features(val) {\r\n this._features = val;\r\n }\r\n\r\n private _connectors: Connector[];\r\n @Enumerable()\r\n public get connectors(): Connector[] {\r\n if (!this._connectors) this._connectors = [];\r\n return this._connectors;\r\n }\r\n public set connectors(val) {\r\n this._connectors = val;\r\n }\r\n\r\n public getChildren(): Kb3dObject[] {\r\n return [...this.features, ...this.connectors];\r\n }\r\n\r\n public getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n if (token.isFeature()) {\r\n return this.features;\r\n } else if (token == Token.Connector) {\r\n return this.connectors;\r\n } else {\r\n throw Error('unexpected token');\r\n }\r\n }\r\n\r\n /** overriden by derived classes to get only children that derive from SpaceNode (like groups, meshes, nested scenes) */\r\n public abstract getSpaceChildren(): SpaceNode[];\r\n\r\n public getAncestors(): SpaceNode[] {\r\n return super.getAncestors() as SpaceNode[];\r\n }\r\n\r\n public copyPropertiesTo(target: SpaceNode) {\r\n target.name = this.name;\r\n target.visible = this.visible;\r\n target.position = this.position;\r\n target.useEuler = this.useEuler;\r\n target.eulerRotation = this.eulerRotation;\r\n target.rotationAngle = this.rotationAngle;\r\n target.rotationAxis = this.rotationAxis;\r\n target.scaling = this.scaling;\r\n target.pivot = this.pivot;\r\n target.fixed = this.fixed;\r\n target._primeMover = this._primeMover;\r\n target._showPivot = this._showPivot;\r\n target.preTransform = this.preTransform;\r\n }\r\n\r\n public getFeatureByName(name: string) {\r\n return [...this.features, ...this.connectors].find(f => f.name.isEqual(name));\r\n }\r\n\r\n public rotate(axis: KbVector, angle: number) {\r\n axis.normalize();\r\n\r\n const q = KbQuaternion.FromRotationAxis(axis, angle);\r\n this.setRotationQuaternion(this.getRotationQuaternion().multiply(q));\r\n }\r\n}\r\n","import { BaseKb3dModel, NodeReference } from '../decorators';\r\nimport { IMeshNode } from '../kb3d-models';\r\nimport { MaterialNode } from '../materials/material-node';\r\nimport { Token } from '../token';\r\nimport { SpaceNode } from './space-node';\r\n\r\n@BaseKb3dModel({\r\n token: Token.MeshNode,\r\n})\r\nexport abstract class MeshNode extends SpaceNode implements IMeshNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Dynamically created id that is used to track assets in the 3d engine. Ensures there is\r\n * no duplicate id's when there are nested scenes.\r\n */\r\n public _activeDynamicId?: string;\r\n public _polygonCount?: number = 0;\r\n public _verticesCount?: number = 0;\r\n\r\n public flipSurfaceOrientation?: boolean;\r\n public receiveShadows?: boolean;\r\n public castShadows?: boolean;\r\n public checkCollisions?: boolean;\r\n public isPickable?: boolean;\r\n\r\n @NodeReference(MaterialNode, '' as any)\r\n public materialId?: string = null as any;\r\n\r\n public opacity?: number;\r\n\r\n public getSpaceChildren() {\r\n return new Array();\r\n }\r\n\r\n copyPropertiesTo(target: SpaceNode) {\r\n super.copyPropertiesTo(target);\r\n if (target instanceof MeshNode) {\r\n target.flipSurfaceOrientation = this.flipSurfaceOrientation;\r\n target.receiveShadows = this.receiveShadows;\r\n target.castShadows = this.castShadows;\r\n target.checkCollisions = this.checkCollisions;\r\n target.materialId = this.materialId;\r\n target.opacity = this.opacity;\r\n }\r\n }\r\n}\r\n","import { BaseKb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eSideOrientation } from '../enums';\r\nimport { IPrimitiveMeshNode, IUvData } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { MeshNode } from './mesh-node';\r\nimport { SpaceNode } from './space-node';\r\n\r\n@BaseKb3dModel({\r\n token: Token.PrimitiveMeshNode,\r\n})\r\nexport abstract class PrimitiveMeshNode extends MeshNode implements IPrimitiveMeshNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n /** for baking in uv map data into the primitive mesh */\r\n public uvOverrides?: IUvData;\r\n public sideOrientation: eSideOrientation;\r\n\r\n copyPropertiesTo(target: SpaceNode) {\r\n super.copyPropertiesTo(target);\r\n if (target instanceof PrimitiveMeshNode) {\r\n target.uvOverrides = this.uvOverrides;\r\n target.sideOrientation = this.sideOrientation;\r\n }\r\n }\r\n}\r\n","import { SpaceNode } from '.';\r\nimport { IgnoreChanges } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IMeshNode } from '../kb3d-models';\r\nimport { KbGeometry } from '../primitives/kb-geometry';\r\nimport { Token } from '../token';\r\nimport { MeshNode } from './mesh-node';\r\n\r\n/**\r\n * A Mesh Node. Must be a descendant of the MeshRoot node.\r\n * @param {Object} nodeConfig The configuration object of the node.\r\n * @param {string} nodeConfig.name The name of the node. Required.\r\n * @param {Object} parent The parent of this node. Optional, but mesh nodes should have parents if they are to be displayed.\r\n * @property\r\n */\r\n\r\n@Kb3dModel({\r\n token: Token.CustomMeshNode,\r\n})\r\nexport class CustomMeshNode extends MeshNode implements IMeshNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n /** Loading state of mesh. Used to keep track of when a request is in flight */\r\n @IgnoreChanges\r\n public _loading: string | null = null;\r\n\r\n /** The mesh geometry ID. Blank string is there is no geometry, otherwise is the same as the geometry.id */\r\n public geometryId: string;\r\n\r\n /** The mesh geometry. Undefined if not loaded or doesn't exist. Should be lazy loaded using the geometryId property. */\r\n public _geometry?: KbGeometry;\r\n\r\n get hasGeometry() {\r\n return this.geometryId != null && this.geometryId != '';\r\n }\r\n get geometryLoaded() {\r\n return this._geometry != null;\r\n }\r\n\r\n copyPropertiesTo(target: SpaceNode) {\r\n super.copyPropertiesTo(target);\r\n if (target instanceof CustomMeshNode) {\r\n target.geometryId = this.geometryId;\r\n }\r\n }\r\n}\r\n","import { Enumerable } from '../decorators/enumerable';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IMeshGroupNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { SpaceNode } from './space-node';\r\n\r\n@Kb3dModel({\r\n token: Token.MeshGroupNode,\r\n})\r\nexport class MeshGroupNode extends SpaceNode implements IMeshGroupNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n private _meshes: SpaceNode[];\r\n @Enumerable()\r\n public get meshes(): SpaceNode[] {\r\n if (!this._meshes) this._meshes = [];\r\n return this._meshes;\r\n }\r\n public set meshes(val) {\r\n this._meshes = val;\r\n }\r\n\r\n public getChildren(): Kb3dObject[] {\r\n return super.getChildren().concat(this.meshes);\r\n }\r\n\r\n public getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n if (token.isMeshOrGroup() || token.isLight()) {\r\n return this.meshes;\r\n } else if (token.isConnector()) {\r\n return this.connectors;\r\n } else {\r\n throw 'unexpected token';\r\n }\r\n }\r\n\r\n public getSpaceChildren() {\r\n return this.meshes;\r\n }\r\n}\r\n","import { Ignore } from '../decorators/inject-decorator';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IKbColor } from '../kb3d-models';\r\nimport { Token } from '../token';\r\n\r\nexport interface IKbColorLike {\r\n r: number;\r\n g: number;\r\n b: number;\r\n a?: number;\r\n}\r\n\r\n@Kb3dModel({\r\n token: Token.KbColor,\r\n trackChanges: false,\r\n create: args => new KbColor(args.r || 0, args.g || 0, args.b || 0, args.a),\r\n})\r\nexport class KbColor implements IKbColor {\r\n constructor(\r\n @Ignore() readonly r: number,\r\n @Ignore() readonly g: number,\r\n @Ignore() readonly b: number,\r\n @Ignore() readonly a: number = 1\r\n ) {}\r\n\r\n clone() {\r\n return new KbColor(this.r, this.g, this.b, this.a);\r\n }\r\n assign(c: { r?: number | null; g?: number | null; b?: number | null; a?: number | null }) {\r\n return new KbColor(\r\n typeof c.r === 'number' ? c.r : this.r,\r\n typeof c.g === 'number' ? c.g : this.g,\r\n typeof c.b === 'number' ? c.b : this.b,\r\n typeof c.a === 'number' ? c.a : this.a\r\n );\r\n }\r\n equal(c?: KbColor): boolean {\r\n return !!c && c.r == this.r && c.g == this.g && c.b == this.b && c.a == this.a;\r\n }\r\n cssString() {\r\n if (this.a < 1) {\r\n return `rgba(${this.r * 255}, ${this.g * 255}, ${this.b * 255}, ${this.a})`;\r\n } else {\r\n return `rgb(${this.r * 255}, ${this.g * 255}, ${this.b * 255})`;\r\n }\r\n }\r\n toObject() {\r\n return { r: this.r, g: this.g, b: this.b, a: this.a } as IKbColorLike;\r\n }\r\n toIntObject() {\r\n return { r: this.r * 255, g: this.g * 255, b: this.b * 255, a: this.a };\r\n }\r\n static From(c: IKbColorLike) {\r\n return new KbColor(c.r, c.g, c.b, c.a);\r\n }\r\n static FromIntObject(c: IKbColorLike) {\r\n return new KbColor(c.r / 255, c.g / 255, c.b / 255, c.a != null ? c.a : 1);\r\n }\r\n static White() {\r\n return new KbColor(1, 1, 1, 1);\r\n }\r\n static Black() {\r\n return new KbColor(0, 0, 0, 1);\r\n }\r\n static Transparent() {\r\n return new KbColor(0, 0, 0, 0);\r\n }\r\n static Green() {\r\n return new KbColor(0, 1, 0);\r\n }\r\n static Red() {\r\n return new KbColor(1, 0, 0);\r\n }\r\n static KbmaxOrange() {\r\n return new KbColor(227 / 255, 131 / 255, 28 / 255);\r\n }\r\n static KbmaxBlue() {\r\n return new KbColor(8 / 255, 72 / 255, 96 / 255);\r\n }\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IUvData } from '../kb3d-models';\r\nimport { MeshNode } from '../meshes/mesh-node';\r\nimport { Token } from '../token';\r\n\r\nexport const NEW_GEOMETRY = 'NEW_GEOMETRY';\r\n\r\n/** IUvData has number[] props needed for server, but we want\r\n * them to be float32array here\r\n */\r\nexport type UvBuffer = {\r\n [P in keyof IUvData]: Float32Array;\r\n};\r\n\r\nexport interface KBVertexData extends UvBuffer {\r\n indices?: Uint32Array;\r\n positions?: Float32Array;\r\n normals?: Float32Array;\r\n tangents?: Float32Array;\r\n}\r\n\r\nconst MAX_INT16 = 32767;\r\nconst MAX_UINT16 = 65535;\r\n\r\n@Kb3dModel({\r\n token: Token.KbGeometry,\r\n trackChanges: false,\r\n})\r\nexport class KbGeometry implements KBVertexData {\r\n indices?: Uint32Array;\r\n positions?: Float32Array;\r\n normals?: Float32Array;\r\n tangents?: Float32Array;\r\n uvs?: Float32Array;\r\n /**\r\n * This property is used by the mesh renderer when a node has a pretransform (baked transform) defined.\r\n * The first time the geometry is transformed, it's mutated. The 4x4 transform matrix is stored here.\r\n * When this geometry is used in the future, this transform has to be taken into account for any future transforms (or lack of a transform)\r\n * This is so that we can reuse a transformed geometry if many nodes have the same transform or if a single node needs to rebuild\r\n * it's own geometry often, which is the most common use case.\r\n */\r\n _hasTransform?: number[];\r\n\r\n shared = false;\r\n\r\n /**\r\n * A geometry object. Geometries are immutable, once they are created they should not be modified.\r\n */\r\n constructor() {}\r\n\r\n clone() {\r\n const newGeometry = new KbGeometry();\r\n newGeometry.indices = this.indices;\r\n newGeometry.positions = this.positions;\r\n newGeometry.normals = this.normals;\r\n newGeometry.tangents = this.tangents;\r\n newGeometry.uvs = this.uvs;\r\n\r\n return newGeometry;\r\n }\r\n\r\n /**\r\n * Freeze a geometry to enforce the immutability of geometries\r\n */\r\n // freeze() {\r\n // Object.freeze(this);\r\n // Object.freeze(this.vertexData);\r\n // }\r\n\r\n // update(vertexData: Partial) {\r\n // const newVertexData = { ...this.vertexData, ...vertexData };\r\n // const newGeometry = new KbGeometry(newVertexData, this.id);\r\n // return newGeometry;\r\n // }\r\n\r\n extractFromBinary(fileData: ArrayBuffer, meshNode: MeshNode): void {\r\n const dataView = new DataView(fileData);\r\n let curPos: number;\r\n\r\n // indices\r\n const indicesOffset = dataView.getInt32(0, true);\r\n curPos = 4;\r\n const indicesDataSize = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n\r\n let indices: Uint32Array;\r\n if (indicesDataSize === 16) {\r\n const indices16 = new Uint16Array(fileData, curPos, indicesOffset / 2);\r\n indices = Uint32Array.from(indices16);\r\n curPos += indicesOffset;\r\n } else if (indicesDataSize === 32) {\r\n indices = new Uint32Array(fileData, curPos, indicesOffset / 4);\r\n curPos += indicesOffset;\r\n } else {\r\n throw Error('Unknown indices data size ' + meshNode.name);\r\n }\r\n\r\n // positions\r\n const posOffset = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n const posDataSize = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n const posRatio = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n\r\n let positions: Float32Array;\r\n if (posDataSize === 32) {\r\n positions = new Float32Array(fileData.slice(curPos, curPos + posOffset));\r\n for (let i = 0; i < positions.length; i++) {\r\n positions[i] /= posRatio;\r\n }\r\n curPos += posOffset;\r\n } else {\r\n throw Error('Invalid positions in binary ' + meshNode.name);\r\n }\r\n\r\n // normals\r\n const norOffset = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n const norDataSize = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n const norRatio = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n\r\n let normals: Float32Array;\r\n if (norDataSize === 16) {\r\n const normalsInt = new Int16Array(fileData.slice(curPos, curPos + norOffset));\r\n normals = new Float32Array(normalsInt.length);\r\n for (let i = 0; i < normalsInt.length; i++) {\r\n normals[i] = normalsInt[i] / norRatio;\r\n }\r\n curPos += norOffset;\r\n } else {\r\n throw Error('Invalid normals in binary ' + meshNode.name);\r\n }\r\n\r\n const uvsOffset = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n const uvsDataSize = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n const uvsRatio = dataView.getInt32(curPos, true);\r\n curPos += 4;\r\n\r\n let uvs: Float32Array;\r\n if (uvsDataSize === 16) {\r\n const uvsInt = new Int16Array(fileData.slice(curPos, curPos + uvsOffset));\r\n uvs = new Float32Array(uvsInt.length);\r\n for (let i = 0; i < uvsInt.length; i++) {\r\n uvs[i] = uvsInt[i] / uvsRatio;\r\n }\r\n curPos += uvsOffset;\r\n } else {\r\n throw Error('Invalid uvs in binary ' + meshNode.name);\r\n }\r\n\r\n // Error reporting\r\n if (indices.length % 3 > 0) {\r\n console.warn('Incomplete indices triangles in mesh ' + meshNode.name);\r\n }\r\n if (positions.length % 3 > 0) {\r\n console.warn('Incomplete position vectors in mesh ' + meshNode.name);\r\n }\r\n if (normals.length % 3 > 0) {\r\n console.warn('Incomplete normal vectors in mesh ' + meshNode.name);\r\n }\r\n if (uvs.length % 2 > 0) {\r\n console.warn('Incomplete uv vectors in mesh ' + meshNode.name);\r\n }\r\n if (uvs.length > 0 && positions.length !== normals.length) {\r\n console.warn('Normals and Positions array size mismatch in ' + meshNode.name);\r\n }\r\n if (uvs.length > 0 && positions.length / 3 !== uvs.length / 2) {\r\n console.warn('UV array size mismatch in ' + meshNode.name);\r\n }\r\n // End error reporting\r\n\r\n this.positions = positions;\r\n this.indices = indices;\r\n if (normals.length > 0) {\r\n this.normals = normals;\r\n }\r\n if (uvs.length > 0) {\r\n this.uvs = uvs;\r\n }\r\n }\r\n\r\n toBinary(): ArrayBuffer | undefined {\r\n if (!this.positions || !this.indices) {\r\n return;\r\n }\r\n const positions = this.positions;\r\n const indices = this.indices;\r\n const normals = this.normals || new Float32Array([]);\r\n const uvs = this.uvs || new Float32Array([]);\r\n\r\n let fileLen = 0;\r\n let indicesOffset = 8; // indices data markers\r\n let indicesBits = 0;\r\n let indicesLength = 0;\r\n let posOffset = 0;\r\n let posBits = 0;\r\n let posLength = 0;\r\n let normalsOffset = 0;\r\n let normalsBits = 0;\r\n let normalsLength = 0;\r\n let uvsOffset = 0;\r\n let uvsBits = 0;\r\n let uvsLength = 0;\r\n // calculate the total size of the array\r\n\r\n fileLen += indicesOffset;\r\n if (canFitInUInt16Bit(indices)) {\r\n // write a 16bit array\r\n indicesBits = 16;\r\n indicesLength = indices.length * 2;\r\n fileLen += indicesLength;\r\n } else {\r\n // write a 32bit array\r\n indicesBits = 32;\r\n indicesLength = indices.length * 4;\r\n fileLen += indicesLength;\r\n }\r\n\r\n fileLen += 12; // position data markers\r\n posOffset = fileLen;\r\n posBits = 32;\r\n fileLen += positions.length * 4;\r\n posLength = positions.length * 4;\r\n\r\n fileLen += 12; // normals data markers\r\n normalsOffset = fileLen;\r\n // write the normals 16 bit array\r\n normalsBits = 16;\r\n fileLen += normals.length * 2;\r\n normalsLength = normals.length * 2;\r\n\r\n fileLen += 12; // uv data markers\r\n uvsOffset = fileLen;\r\n uvsBits = 16;\r\n fileLen += uvs.length * 2;\r\n uvsLength = uvs.length * 2;\r\n\r\n // create the buffer that represent the binary file\r\n const buffer = new ArrayBuffer(fileLen);\r\n const bufferView = new DataView(buffer);\r\n\r\n // let's write the data into the bufferView\r\n // write the indices\r\n bufferView.setInt32(indicesOffset - 8, indicesLength, true); // NOTICE that by default JS is big endian, but since our servers are x86 we are little endian\r\n bufferView.setInt32(indicesOffset - 4, indicesBits, true);\r\n\r\n if (indicesBits == 16) {\r\n for (let i = 0; i < indices.length; i++) {\r\n bufferView.setUint16(indicesOffset, indices[i], true);\r\n indicesOffset += 2;\r\n }\r\n } else if (indicesBits == 32) {\r\n for (let i = 0; i < indices.length; i++) {\r\n bufferView.setUint32(indicesOffset, indices[i], true);\r\n indicesOffset += 4;\r\n }\r\n }\r\n\r\n // write the positions\r\n bufferView.setInt32(posOffset - 12, posLength, true);\r\n bufferView.setInt32(posOffset - 8, posBits, true);\r\n bufferView.setInt32(posOffset - 4, 1, true); // ratio\r\n\r\n if (posBits == 32) {\r\n for (let i = 0; i < positions.length; i++) {\r\n bufferView.setFloat32(posOffset, positions[i], true);\r\n posOffset += 4;\r\n }\r\n } else {\r\n console.error('Fix me - non-32bit positions not supported');\r\n }\r\n\r\n // write the normals\r\n bufferView.setInt32(normalsOffset - 12, normalsLength, true);\r\n bufferView.setInt32(normalsOffset - 8, normalsBits, true);\r\n bufferView.setInt32(normalsOffset - 4, MAX_INT16, true);\r\n\r\n if (normalsBits == 16) {\r\n for (let i = 0; i < normals.length; i++) {\r\n const n = floatToIntStore(normals[i], MAX_INT16);\r\n bufferView.setInt16(normalsOffset, n, true);\r\n normalsOffset += 2;\r\n }\r\n } else {\r\n console.error('Fix me - non-16bit normals not supported');\r\n }\r\n\r\n // write the UVs\r\n bufferView.setInt32(uvsOffset - 12, uvsLength, true);\r\n bufferView.setInt32(uvsOffset - 8, uvsBits, true);\r\n bufferView.setInt32(uvsOffset - 4, MAX_INT16, true);\r\n\r\n if (uvsBits == 16) {\r\n for (let i = 0; i < uvs.length; i++) {\r\n const n = floatToIntStore(uvs[i], MAX_INT16);\r\n bufferView.setInt16(uvsOffset, n, true);\r\n uvsOffset += 2;\r\n }\r\n } else {\r\n console.error('Fix me - non-16bit uvs not supported');\r\n }\r\n\r\n return buffer;\r\n }\r\n}\r\n\r\n// function canFitInInt16Bit(inArray: Float32Array): boolean {\r\n\r\n// for (let i = 0; i < inArray.length; i++) {\r\n// const val = inArray[i];\r\n// if (val > 327.68 || val < -327.68) {\r\n// return false;\r\n// }\r\n// }\r\n// return true;\r\n// }\r\n\r\n// function canFitInInt8Bit(inArray: Float32Array): boolean {\r\n// for (let i = 0; i < inArray.length; i++) {\r\n// const val = inArray[i];\r\n// if (val > 1.28 || val < -1.28) {\r\n// return false;\r\n// }\r\n// }\r\n// return true;\r\n// }\r\n\r\nfunction canFitInUInt16Bit(inArray: Int32Array | Uint32Array) {\r\n for (let i = 0; i < inArray.length; i++) {\r\n const val = inArray[i];\r\n if (val > MAX_UINT16) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nfunction floatToIntStore(float: number, maxInt: number, maxVal = 1): number {\r\n // this function convert a value between -327.68 and 327.68 to an int 16. we use the convention to have only 2 decimal numbers\r\n float = (Math.min(Math.max(-maxVal, float), maxVal) * maxInt) / maxVal;\r\n\r\n const outVal = Math.trunc(float);\r\n return outVal;\r\n}\r\n","export enum eContainerItemLayout {\r\n horizontal = \"horizontal\",\r\n vertical = \"vertical\",\r\n absolute = \"absolute\",\r\n}\r\nexport enum eContainerChildAlignment {\r\n inherit = \"inherit\",\r\n stretch = \"stretch\",\r\n start = \"start\",\r\n center = \"center\",\r\n end = \"end\",\r\n}\r\nexport enum eContainerItemAlignment {\r\n stretch = \"stretch\",\r\n start = \"start\",\r\n center = \"center\",\r\n end = \"end\",\r\n}\r\nexport enum eContainerItemJustify {\r\n start = \"start\",\r\n center = \"center\",\r\n end = \"end\",\r\n}\r\nexport enum eScroll {\r\n none = \"none\",\r\n auto = \"auto\",\r\n x = \"x\",\r\n y = \"y\",\r\n}\r\nexport enum eRelativeSize {\r\n auto = \"auto\",\r\n x1 = \"x1\",\r\n x2 = \"x2\",\r\n x3 = \"x3\",\r\n x4 = \"x4\",\r\n x5 = \"x5\",\r\n x6 = \"x6\",\r\n x7 = \"x7\",\r\n x8 = \"x8\",\r\n x9 = \"x9\",\r\n x10 = \"x10\",\r\n x11 = \"x11\",\r\n x12 = \"x12\",\r\n custom = \"custom\",\r\n}\r\nexport enum ePadding {\r\n none = \"none\",\r\n small = \"small\",\r\n medium = \"medium\",\r\n large = \"large\",\r\n}\r\nexport enum eColorShade {\r\n default = \"default\",\r\n lighter1 = \"lighter1\",\r\n lighter2 = \"lighter2\",\r\n lighter3 = \"lighter3\",\r\n lighter4 = \"lighter4\",\r\n darker1 = \"darker1\",\r\n darker2 = \"darker2\",\r\n darker3 = \"darker3\",\r\n darker4 = \"darker4\",\r\n}\r\nexport enum eBackgroundColor {\r\n background = \"background\",\r\n primary = \"primary\",\r\n accent = \"accent\",\r\n warning = \"warning\",\r\n success = \"success\",\r\n input = \"input\",\r\n header = \"header\",\r\n}\r\nexport enum eElevation {\r\n none = \"none\",\r\n z1 = \"z1\",\r\n z2 = \"z2\",\r\n z3 = \"z3\",\r\n z4 = \"z4\",\r\n z5 = \"z5\",\r\n z6 = \"z6\",\r\n z7 = \"z7\",\r\n z8 = \"z8\",\r\n}\r\nexport enum eRuleType {\r\n value = \"value\",\r\n visibility = \"visibility\",\r\n validation = \"validation\",\r\n pricing = \"pricing\",\r\n message = \"message\",\r\n loaded = \"loaded\",\r\n submit = \"submit\",\r\n pageChanged = \"pageChanged\",\r\n tabChanged = \"tabChanged\",\r\n expanderChanged = \"expanderChanged\",\r\n output = \"output\",\r\n action = \"action\",\r\n function = \"function\",\r\n global = \"global\",\r\n globalEvent = \"globalEvent\",\r\n safeFunction = \"safeFunction\",\r\n naming = \"naming\",\r\n field = \"field\",\r\n button = \"button\",\r\n svgViewer = \"svgViewer\",\r\n dragStart = \"dragStart\",\r\n dragMove = \"dragMove\",\r\n dragEnd = \"dragEnd\",\r\n optionFilter = \"optionFilter\",\r\n nested = \"nested\",\r\n resize = \"resize\",\r\n nestedSetSelected = \"nestedSetSelected\",\r\n keyboard = \"keyboard\",\r\n manufacture = \"manufacture\",\r\n kineticDocumentRules = \"kineticDocumentRules\",\r\n layout = \"layout\",\r\n configuratorAdded = \"configuratorAdded\",\r\n configuratorRemoved = \"configuratorRemoved\",\r\n configuratorCopied = \"configuratorCopied\",\r\n product = \"product\",\r\n workflow = \"workflow\",\r\n beforeBuild = \"beforeBuild\",\r\n globalDefinition = \"globalDefinition\",\r\n quote = \"quote\",\r\n scene = \"scene\",\r\n sceneLoaded = \"sceneLoaded\",\r\n xrEnter = \"xrEnter\",\r\n xrExit = \"xrExit\",\r\n}\r\nexport enum eToolbarPosition {\r\n hidden = \"hidden\",\r\n topLeft = \"topLeft\",\r\n topRight = \"topRight\",\r\n bottomLeft = \"bottomLeft\",\r\n bottomRight = \"bottomRight\",\r\n}\r\nexport enum eValidationTiming {\r\n always = \"always\",\r\n onTouched = \"onTouched\",\r\n}\r\nexport enum eViewerMode {\r\n none = \"none\",\r\n media = \"media\",\r\n scene = \"scene\",\r\n}\r\nexport enum ePosition {\r\n left = \"left\",\r\n right = \"right\",\r\n}\r\nexport enum eIconStyle {\r\n none = \"none\",\r\n icon = \"icon\",\r\n media = \"media\",\r\n}\r\nexport enum eExportType {\r\n _custom = \"_custom\",\r\n pdf = \"pdf\",\r\n bmp = \"bmp\",\r\n doc = \"doc\",\r\n docm = \"docm\",\r\n dot = \"dot\",\r\n dotm = \"dotm\",\r\n dotx = \"dotx\",\r\n emf = \"emf\",\r\n epub = \"epub\",\r\n html = \"html\",\r\n jpg = \"jpg\",\r\n gif = \"gif\",\r\n tiff = \"tiff\",\r\n dwf = \"dwf\",\r\n edrw = \"edrw\",\r\n png = \"png\",\r\n odt = \"odt\",\r\n rtf = \"rtf\",\r\n tif = \"tif\",\r\n xaml = \"xaml\",\r\n xps = \"xps\",\r\n ods = \"ods\",\r\n svg = \"svg\",\r\n txt = \"txt\",\r\n easm = \"easm\",\r\n prt = \"prt\",\r\n g = \"g\",\r\n dwg = \"dwg\",\r\n dxf = \"dxf\",\r\n sldprt = \"sldprt\",\r\n sldasm = \"sldasm\",\r\n slddrw = \"slddrw\",\r\n sldlfp = \"sldlfp\",\r\n x_t = \"x_t\",\r\n x_b = \"x_b\",\r\n igs = \"igs\",\r\n stl = \"stl\",\r\n wrl = \"wrl\",\r\n u3d = \"u3d\",\r\n psd = \"psd\",\r\n ai = \"ai\",\r\n cgr = \"cgr\",\r\n asm = \"asm\",\r\n hcg = \"hcg\",\r\n hsf = \"hsf\",\r\n sat = \"sat\",\r\n stp = \"stp\",\r\n step = \"step\",\r\n vda = \"vda\",\r\n neu = \"neu\",\r\n iv = \"iv\",\r\n slp = \"slp\",\r\n eps = \"eps\",\r\n catproduct = \"catproduct\",\r\n jt = \"jt\",\r\n zgl = \"zgl\",\r\n xgl = \"xgl\",\r\n csv = \"csv\",\r\n xml = \"xml\",\r\n}\r\nexport enum eHotspotSource {\r\n none = \"none\",\r\n text = \"text\",\r\n media = \"media\",\r\n element = \"element\",\r\n}\r\nexport enum eHotspotAttach {\r\n topLeft = \"topLeft\",\r\n top = \"top\",\r\n topRight = \"topRight\",\r\n left = \"left\",\r\n center = \"center\",\r\n right = \"right\",\r\n bottomLeft = \"bottomLeft\",\r\n bottom = \"bottom\",\r\n bottomRight = \"bottomRight\",\r\n}\r\nexport enum eHotspotPosition {\r\n manual = \"manual\",\r\n target = \"target\",\r\n}\r\nexport enum eHotspotShape {\r\n circle = \"circle\",\r\n circleWithText = \"circleWithText\",\r\n image = \"image\",\r\n mesh = \"mesh\",\r\n text = \"text\",\r\n}\r\nexport enum eAnimationEasing {\r\n linear = \"linear\",\r\n easeInQuad = \"easeInQuad\",\r\n easeOutQuad = \"easeOutQuad\",\r\n easeInOutQuad = \"easeInOutQuad\",\r\n easeInCubic = \"easeInCubic\",\r\n easeOutCubic = \"easeOutCubic\",\r\n easeInOutCubic = \"easeInOutCubic\",\r\n easeInQuart = \"easeInQuart\",\r\n easeOutQuart = \"easeOutQuart\",\r\n easeInOutQuart = \"easeInOutQuart\",\r\n easeInQuint = \"easeInQuint\",\r\n easeOutQuint = \"easeOutQuint\",\r\n easeInOutQuint = \"easeInOutQuint\",\r\n easeInSine = \"easeInSine\",\r\n easeOutSine = \"easeOutSine\",\r\n easeInOutSine = \"easeInOutSine\",\r\n easeInExpo = \"easeInExpo\",\r\n easeOutExpo = \"easeOutExpo\",\r\n easeInOutExpo = \"easeInOutExpo\",\r\n easeInCirc = \"easeInCirc\",\r\n easeOutCirc = \"easeOutCirc\",\r\n easeInOutCirc = \"easeInOutCirc\",\r\n easeInElastic = \"easeInElastic\",\r\n easeOutElastic = \"easeOutElastic\",\r\n easeInOutElastic = \"easeInOutElastic\",\r\n easeInBack = \"easeInBack\",\r\n easeOutBack = \"easeOutBack\",\r\n easeInOutBack = \"easeInOutBack\",\r\n easeInBounce = \"easeInBounce\",\r\n easeOutBounce = \"easeOutBounce\",\r\n easeInOutBounce = \"easeInOutBounce\",\r\n}\r\nexport enum eQueryMode {\r\n none = \"none\",\r\n table = \"table\",\r\n database = \"database\",\r\n array = \"array\",\r\n optionFilter = \"optionFilter\",\r\n parentOptionFilter = \"parentOptionFilter\",\r\n}\r\nexport enum eOptionFilterSource {\r\n table = \"table\",\r\n database = \"database\",\r\n query = \"query\",\r\n safeFunction = \"safeFunction\",\r\n optionFilter = \"optionFilter\",\r\n}\r\nexport enum eOutputType {\r\n none = \"none\",\r\n word = \"word\",\r\n excel = \"excel\",\r\n image = \"image\",\r\n solidworks = \"solidworks\",\r\n inventor = \"inventor\",\r\n creo = \"creo\",\r\n creo3 = \"creo3\",\r\n cadDrawing = \"cadDrawing\",\r\n bom = \"bom\",\r\n sceneRender = \"sceneRender\",\r\n pdf = \"pdf\",\r\n salesforce = \"salesforce\",\r\n autoCad = \"autoCad\",\r\n zip = \"zip\",\r\n svg = \"svg\",\r\n text = \"text\",\r\n}\r\nexport enum eOutputFieldType {\r\n wordText = \"wordText\",\r\n wordContainer = \"wordContainer\",\r\n wordImage = \"wordImage\",\r\n wordList = \"wordList\",\r\n excelSheet = \"excelSheet\",\r\n excelCell = \"excelCell\",\r\n excelImage = \"excelImage\",\r\n excelTable = \"excelTable\",\r\n excelChart = \"excelChart\",\r\n cadReplaceComponent = \"cadReplaceComponent\",\r\n cadAngleMate = \"cadAngleMate\",\r\n cadCoincidentMate = \"cadCoincidentMate\",\r\n cadCoordinateSystemMate = \"cadCoordinateSystemMate\",\r\n cadDistanceMate = \"cadDistanceMate\",\r\n cadPositionConstraint = \"cadPositionConstraint\",\r\n cadDimension = \"cadDimension\",\r\n cadFeature = \"cadFeature\",\r\n cadLibFeature = \"cadLibFeature\",\r\n cadCustomProperty = \"cadCustomProperty\",\r\n cadComponent = \"cadComponent\",\r\n cadDrawingView = \"cadDrawingView\",\r\n cadDrawingSheet = \"cadDrawingSheet\",\r\n cadDrawingAnnotation = \"cadDrawingAnnotation\",\r\n cadDynamicDrawingDimension = \"cadDynamicDrawingDimension\",\r\n cadDynamicDrawingAnnotation = \"cadDynamicDrawingAnnotation\",\r\n cadDynamicComponent = \"cadDynamicComponent\",\r\n cadNestedComponent = \"cadNestedComponent\",\r\n cadScaleFeature = \"cadScaleFeature\",\r\n cadAnnotation = \"cadAnnotation\",\r\n cadText = \"cadText\",\r\n cadParameter = \"cadParameter\",\r\n cadRepresentation = \"cadRepresentation\",\r\n cadPoint = \"cadPoint\",\r\n cadLayer = \"cadLayer\",\r\n bomMapping = \"bomMapping\",\r\n salesForceObject = \"salesForceObject\",\r\n cadDrawingDimension = \"cadDrawingDimension\",\r\n pdfSection = \"pdfSection\",\r\n cadLibReference = \"cadLibReference\",\r\n cadLibDimension = \"cadLibDimension\",\r\n cadBlock = \"cadBlock\",\r\n cadBlockArray = \"cadBlockArray\",\r\n zipSection = \"zipSection\",\r\n}\r\nexport enum eSingleOptionBehavior {\r\n nothing = \"nothing\",\r\n disable = \"disable\",\r\n hide = \"hide\",\r\n}\r\nexport enum eConfiguratorImageSource {\r\n none = \"none\",\r\n media = \"media\",\r\n scene = \"scene\",\r\n}\r\nexport enum eTextColor {\r\n normal = \"normal\",\r\n header = \"header\",\r\n primary = \"primary\",\r\n accent = \"accent\",\r\n error = \"error\",\r\n success = \"success\",\r\n}\r\nexport enum eConfiguratorEntityType {\r\n product = \"product\",\r\n quoteHeader = \"quoteHeader\",\r\n}\r\nexport enum eBackground {\r\n color = \"color\",\r\n transparent = \"transparent\",\r\n environment = \"environment\",\r\n}\r\nexport enum eSideOrientation {\r\n frontSide = \"frontSide\",\r\n backSide = \"backSide\",\r\n doubleSide = \"doubleSide\",\r\n}\r\nexport enum eUvMode {\r\n planar = \"planar\",\r\n box = \"box\",\r\n cylindrical = \"cylindrical\",\r\n spherical = \"spherical\",\r\n useExisting = \"useExisting\",\r\n}\r\nexport enum eMaterialViewMode {\r\n shaded = \"shaded\",\r\n edges = \"edges\",\r\n wireframe = \"wireframe\",\r\n}\r\nexport enum eMaterialLocation {\r\n local = \"local\",\r\n global = \"global\",\r\n library = \"library\",\r\n}\r\nexport enum eAlphaMode {\r\n disable = \"disable\",\r\n add = \"add\",\r\n combine = \"combine\",\r\n subtract = \"subtract\",\r\n multiply = \"multiply\",\r\n}\r\nexport enum eViewpointType {\r\n orbit = \"orbit\",\r\n firstPerson = \"firstPerson\",\r\n overhead = \"overhead\",\r\n}\r\nexport enum eViewpointProjection {\r\n perspective = \"perspective\",\r\n orthographic = \"orthographic\",\r\n}\r\nexport enum eViewpointTargetMode {\r\n rotation = \"rotation\",\r\n point = \"point\",\r\n mesh = \"mesh\",\r\n}\r\nexport enum eConnectorPositionMode {\r\n boundingBox = \"boundingBox\",\r\n absolute = \"absolute\",\r\n moveAlongSketch = \"moveAlongSketch\",\r\n}\r\nexport enum eDragMode {\r\n plane = \"plane\",\r\n free = \"free\",\r\n surface = \"surface\",\r\n}\r\nexport enum eConnectionMode {\r\n none = \"none\",\r\n world = \"world\",\r\n screen = \"screen\",\r\n}\r\nexport enum eEasing {\r\n linear = \"linear\",\r\n quadraticIn = \"quadraticIn\",\r\n quadraticOut = \"quadraticOut\",\r\n quadraticInOut = \"quadraticInOut\",\r\n cubicIn = \"cubicIn\",\r\n cubicOut = \"cubicOut\",\r\n cubicInOut = \"cubicInOut\",\r\n quarticIn = \"quarticIn\",\r\n quarticOut = \"quarticOut\",\r\n quarticInOut = \"quarticInOut\",\r\n quinticIn = \"quinticIn\",\r\n quinticOut = \"quinticOut\",\r\n quinticInOut = \"quinticInOut\",\r\n sinusoidalIn = \"sinusoidalIn\",\r\n sinusoidalOut = \"sinusoidalOut\",\r\n sinusoidalInOut = \"sinusoidalInOut\",\r\n exponentialIn = \"exponentialIn\",\r\n exponentialOut = \"exponentialOut\",\r\n exponentialInOut = \"exponentialInOut\",\r\n circularIn = \"circularIn\",\r\n circularOut = \"circularOut\",\r\n circularInOut = \"circularInOut\",\r\n elasticIn = \"elasticIn\",\r\n elasticOut = \"elasticOut\",\r\n elasticInOut = \"elasticInOut\",\r\n backIn = \"backIn\",\r\n backOut = \"backOut\",\r\n backInOut = \"backInOut\",\r\n bounceIn = \"bounceIn\",\r\n bounceOut = \"bounceOut\",\r\n bounceInOut = \"bounceInOut\",\r\n}\r\nexport enum eCylinderCap {\r\n none = \"none\",\r\n start = \"start\",\r\n end = \"end\",\r\n both = \"both\",\r\n}\r\nexport enum eJoinType {\r\n union = \"union\",\r\n intersect = \"intersect\",\r\n cut = \"cut\",\r\n}\r\nexport enum eShadowQuality {\r\n low = \"low\",\r\n medium = \"medium\",\r\n high = \"high\",\r\n}\r\nexport enum eShadowResolution {\r\n low = \"low\",\r\n medium = \"medium\",\r\n high = \"high\",\r\n}\r\nexport enum eShadowFilter {\r\n none = \"none\",\r\n simple = \"simple\",\r\n advanced = \"advanced\",\r\n}\r\nexport enum eMaterialWorkflow {\r\n metallicRoughness = \"metallicRoughness\",\r\n specularGlossiness = \"specularGlossiness\",\r\n}\r\nexport enum eFeatureCenter {\r\n barycenter = \"barycenter\",\r\n meshPivotPoint = \"meshPivotPoint\",\r\n}\r\nexport enum eJobStatus {\r\n none = \"none\",\r\n waiting = \"waiting\",\r\n queued = \"queued\",\r\n working = \"working\",\r\n complete = \"complete\",\r\n failed = \"failed\",\r\n}\r\nexport enum eJobType {\r\n build = \"build\",\r\n render = \"render\",\r\n notification = \"notification\",\r\n upsertProductsToSfdc = \"upsertProductsToSfdc\",\r\n pullSfdcProducts = \"pullSfdcProducts\",\r\n submitFromSfdcCpq = \"submitFromSfdcCpq\",\r\n completeBuildState = \"completeBuildState\",\r\n cleanDb = \"cleanDb\",\r\n deployment = \"deployment\",\r\n sceneImport = \"sceneImport\",\r\n sceneExport = \"sceneExport\",\r\n sceneConvert = \"sceneConvert\",\r\n completeQuoteProductBuild = \"completeQuoteProductBuild\",\r\n configuratorExport = \"configuratorExport\",\r\n configuratorImport = \"configuratorImport\",\r\n}\r\nexport enum eEnvironment {\r\n prod = \"prod\",\r\n test = \"test\",\r\n dev = \"dev\",\r\n}\r\nexport enum eImportType {\r\n external = \"external\",\r\n kb3d = \"kb3d\",\r\n}\r\nexport enum eQueueMessageType {\r\n builder = \"builder\",\r\n cleanDb = \"cleanDb\",\r\n completeBuildState = \"completeBuildState\",\r\n notification = \"notification\",\r\n render = \"render\",\r\n pullSfdcProducts = \"pullSfdcProducts\",\r\n upsertProductsToSfdc = \"upsertProductsToSfdc\",\r\n submitFromSfdcCpq = \"submitFromSfdcCpq\",\r\n deployment = \"deployment\",\r\n completeQuoteProductBuild = \"completeQuoteProductBuild\",\r\n sceneImport = \"sceneImport\",\r\n sceneExport = \"sceneExport\",\r\n sceneConvert = \"sceneConvert\",\r\n}\r\nexport enum eMateType {\r\n fastened = \"fastened\",\r\n revolute = \"revolute\",\r\n slider = \"slider\",\r\n planar = \"planar\",\r\n cylindrical = \"cylindrical\",\r\n ball = \"ball\",\r\n parallel = \"parallel\",\r\n}\r\nexport enum eValidationType {\r\n error = \"error\",\r\n warning = \"warning\",\r\n info = \"info\",\r\n}\r\nexport enum eValidationSource {\r\n snap = \"snap\",\r\n configurator = \"configurator\",\r\n scene = \"scene\",\r\n}\r\nexport enum eTextureChannel {\r\n emissive = \"emissive\",\r\n albedo = \"albedo\",\r\n ambient = \"ambient\",\r\n opacity = \"opacity\",\r\n reflection = \"reflection\",\r\n specular = \"specular\",\r\n metallic = \"metallic\",\r\n roughness = \"roughness\",\r\n glossiness = \"glossiness\",\r\n normal = \"normal\",\r\n ambientOcclusion = \"ambientOcclusion\",\r\n anisotropyTangent = \"anisotropyTangent\",\r\n subsurfaceThickness = \"subsurfaceThickness\",\r\n clearCoatNormal = \"clearCoatNormal\",\r\n}\r\nexport enum eTextureHorizontalAlign {\r\n left = \"left\",\r\n center = \"center\",\r\n right = \"right\",\r\n}\r\nexport enum eTextureVerticalAlign {\r\n top = \"top\",\r\n middle = \"middle\",\r\n bottom = \"bottom\",\r\n}\r\nexport enum eTextureFit {\r\n none = \"none\",\r\n stretch = \"stretch\",\r\n contain = \"contain\",\r\n}\r\nexport enum eTextureBlendMode {\r\n normal = \"normal\",\r\n multiply = \"multiply\",\r\n screen = \"screen\",\r\n overlay = \"overlay\",\r\n darken = \"darken\",\r\n lighten = \"lighten\",\r\n hue = \"hue\",\r\n saturation = \"saturation\",\r\n color = \"color\",\r\n luminosity = \"luminosity\",\r\n difference = \"difference\",\r\n mask = \"mask\",\r\n vector = \"vector\",\r\n}\r\nexport enum eTextureWrapAddressMode {\r\n repeat = \"repeat\",\r\n clamp = \"clamp\",\r\n}\r\nexport enum eAnnotationLineStyle {\r\n solid = \"solid\",\r\n dashed = \"dashed\",\r\n dotted = \"dotted\",\r\n none = \"none\",\r\n}\r\nexport enum eDimensionLineCapStyle {\r\n none = \"none\",\r\n arrow = \"arrow\",\r\n line = \"line\",\r\n}\r\nexport enum eDimensionAxis {\r\n free = \"free\",\r\n x = \"x\",\r\n y = \"y\",\r\n z = \"z\",\r\n}\r\nexport enum eLoadingExperience {\r\n none = \"none\",\r\n fade = \"fade\",\r\n spinner = \"spinner\",\r\n image = \"image\",\r\n}\r\nexport enum eReflectionType {\r\n plane = \"plane\",\r\n probe = \"probe\",\r\n}\r\nexport enum eRenderMode {\r\n shaded = \"shaded\",\r\n wireframe = \"wireframe\",\r\n edge = \"edge\",\r\n hiddenEdges = \"hiddenEdges\",\r\n}\r\nexport enum eTextureSamplingMode {\r\n nearest = \"nearest\",\r\n bilinear = \"bilinear\",\r\n trilinear = \"trilinear\",\r\n}\r\nexport enum eAxis {\r\n x = \"x\",\r\n y = \"y\",\r\n z = \"z\",\r\n}\r\nexport enum eSketchPathType {\r\n points = \"points\",\r\n arcThrough3Points = \"arcThrough3Points\",\r\n centerRadiusCircle = \"centerRadiusCircle\",\r\n catmullRom = \"catmullRom\",\r\n cubicBezier = \"cubicBezier\",\r\n quadraticBezier = \"quadraticBezier\",\r\n hermite = \"hermite\",\r\n}\r\nexport enum eFilterControl {\r\n none = \"none\",\r\n text = \"text\",\r\n select = \"select\",\r\n multiSelect = \"multiSelect\",\r\n dateRange = \"dateRange\",\r\n numberRange = \"numberRange\",\r\n suggest = \"suggest\",\r\n checkbox = \"checkbox\",\r\n}\r\nexport enum eFilterSource {\r\n none = \"none\",\r\n enum = \"enum\",\r\n properties = \"properties\",\r\n users = \"users\",\r\n states = \"states\",\r\n configurators = \"configurators\",\r\n fields = \"fields\",\r\n customers = \"customers\",\r\n roles = \"roles\",\r\n productSorts = \"productSorts\",\r\n manufacturers = \"manufacturers\",\r\n attributes = \"attributes\",\r\n suggestContacts = \"suggestContacts\",\r\n suggestCustomers = \"suggestCustomers\",\r\n suggestQuotes = \"suggestQuotes\",\r\n suggestProducts = \"suggestProducts\",\r\n headerFields = \"headerFields\",\r\n}\r\nexport enum eFilterType {\r\n property = \"property\",\r\n fieldValue = \"fieldValue\",\r\n sort = \"sort\",\r\n attribute = \"attribute\",\r\n headerValue = \"headerValue\",\r\n}\r\nexport enum eFieldType {\r\n text = \"text\",\r\n number = \"number\",\r\n boolean = \"boolean\",\r\n color = \"color\",\r\n date = \"date\",\r\n upload = \"upload\",\r\n textArray = \"textArray\",\r\n numberArray = \"numberArray\",\r\n colorArray = \"colorArray\",\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { ISphereNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.SphereNode,\r\n})\r\nexport class SphereNode extends PrimitiveMeshNode implements ISphereNode {\r\n public constructor() {\r\n super();\r\n }\r\n\r\n public tessellation: number;\r\n public radius: number;\r\n public arc: number;\r\n public latitudeStart: number;\r\n public latitudeSlice: number;\r\n}\r\n\r\nexport function isSphereMesh(node: Kb3dObject): node is SphereNode {\r\n return instanceOf(node, Token.SphereNode);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { ITorusNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { PrimitiveMeshNode } from './primitive-mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.TorusNode,\r\n})\r\nexport class TorusNode extends PrimitiveMeshNode implements ITorusNode {\r\n public constructor() {\r\n super();\r\n }\r\n public radius: number;\r\n public thickness: number;\r\n public arc: number;\r\n public latitudeStart: number;\r\n public latitudeSlice: number;\r\n public tessellation: number;\r\n}\r\n\r\nexport function isTorusMesh(node: Kb3dObject): node is TorusNode {\r\n return instanceOf(node, Token.TorusNode);\r\n}\r\n","import { BoundingBox } from '@babylonjs/core/Culling/boundingBox';\r\nimport { Subject } from 'rxjs';\r\nimport { NodeReference } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eAxis } from '../enums';\r\nimport { ISketchNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { IKbVectorLike, KbColor, KbVector } from '../primitives';\r\nimport { IBoundingBox } from '../primitives/primitive-utilities';\r\nimport { Token } from '../token';\r\nimport { MeshNode } from './mesh-node';\r\nimport { SketchPath } from './sketch-node-path';\r\n\r\n@Kb3dModel({\r\n token: Token.SketchNode,\r\n})\r\nexport class SketchNode extends MeshNode implements ISketchNode {\r\n public constructor() {\r\n super();\r\n }\r\n\r\n _previewVisible: boolean;\r\n _boundingBoxMin = KbVector.Zero();\r\n _boundingBoxMax = KbVector.Zero();\r\n _boundingBoxChanges = new Subject();\r\n _controlPoints: IKbVectorLike[] = [];\r\n _lineSegmentStartingPoints: number[] = [];\r\n\r\n // todo remove\r\n _sketchPoints = new Float32Array();\r\n\r\n calculatedBoundingBox: BoundingBox;\r\n boundingXOverride?: number;\r\n boundingYOverride?: number;\r\n boundingZOverride?: number;\r\n paths: SketchPath[] = [];\r\n normal: eAxis;\r\n /** Whether to generate a face for this path */\r\n addFace = false;\r\n closePath = false;\r\n flipPath = false;\r\n\r\n tracePath = false;\r\n lineThickness: number;\r\n pathColor: KbColor;\r\n\r\n /** (Not Implemented) Path to clone. Will cause the paths property to be ignored */\r\n @NodeReference(SketchNode) clonePath?: string;\r\n\r\n public getChildren(): Kb3dObject[] {\r\n return super.getChildren().concat(this.paths);\r\n }\r\n\r\n public getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n if (token.isSketchPath()) {\r\n return this.paths;\r\n } else {\r\n return super.getChildArrayForType(token);\r\n }\r\n }\r\n\r\n public getBoundingBox() {\r\n const min = new KbVector(\r\n this.boundingXOverride == null ? this._boundingBoxMin.x : -this.boundingXOverride / 2,\r\n this.boundingYOverride == null ? this._boundingBoxMin.y : -this.boundingYOverride / 2,\r\n this.boundingZOverride == null ? this._boundingBoxMin.z : -this.boundingZOverride / 2\r\n );\r\n const max = new KbVector(\r\n this.boundingXOverride == null ? this._boundingBoxMax.x : this.boundingXOverride / 2,\r\n this.boundingYOverride == null ? this._boundingBoxMax.y : this.boundingYOverride / 2,\r\n this.boundingZOverride == null ? this._boundingBoxMax.z : this.boundingZOverride / 2\r\n );\r\n const centerBB = this._boundingBoxMin.add(this._boundingBoxMax).scale(0.5);\r\n const center = new KbVector(\r\n this.boundingXOverride == null ? centerBB.x : 0,\r\n this.boundingYOverride == null ? centerBB.y : 0,\r\n this.boundingZOverride == null ? centerBB.z : 0\r\n );\r\n return {\r\n min,\r\n max,\r\n center,\r\n };\r\n }\r\n\r\n public getSketchLength() {\r\n let sketchLength = 0;\r\n this.paths.forEach(path => {\r\n let lastPosition: IKbVectorLike | undefined = undefined;\r\n path._points.forEach(point => {\r\n if (!lastPosition) {\r\n lastPosition = point;\r\n } else {\r\n const currentPos = point;\r\n const distance = Math.sqrt(\r\n Math.pow(lastPosition.x - currentPos.x, 2) +\r\n Math.pow(lastPosition.y - currentPos.y, 2) +\r\n Math.pow(lastPosition.z - currentPos.z, 2)\r\n );\r\n sketchLength += distance;\r\n lastPosition = currentPos;\r\n }\r\n });\r\n });\r\n return sketchLength;\r\n }\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eSketchPathType } from '../enums';\r\nimport { SketchControlPoint } from '../features/sketch-control-point';\r\nimport { ISketchPath } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { IKbVectorLike } from '../primitives';\r\nimport { Token } from '../token';\r\nimport { SketchNode } from './sketch-node';\r\n\r\n@Kb3dModel({\r\n token: Token.SketchPath,\r\n})\r\nexport class SketchPath extends Kb3dObject implements ISketchPath {\r\n /** Next target path connected to this one. Full paths are built linked-list style */\r\n toIndex: number;\r\n /** Path control points */\r\n controlPoints: SketchControlPoint[] = [];\r\n /** How smooth to make this path when rasterizing to geometry */\r\n tessellation = 16;\r\n /** Type of arc to use for this path */\r\n type: eSketchPathType;\r\n\r\n /** For grouping paths as one contiguous shape. Only required for hole-path matching */\r\n pathGroupKey = 'default';\r\n\r\n /** Whether to treat this path as part of a hole for extrusions and fills */\r\n holeForPathGroup: string;\r\n\r\n _expanded = false;\r\n _points: IKbVectorLike[] = [];\r\n\r\n /** override base parent for more specific typing*/\r\n public _parent: SketchNode | undefined;\r\n\r\n public getChildren(): Kb3dObject[] {\r\n return super.getChildren().concat(this.controlPoints);\r\n }\r\n\r\n public getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n if (token.isConnector()) {\r\n return this.controlPoints;\r\n } else {\r\n return super.getChildArrayForType(token);\r\n }\r\n }\r\n\r\n public getAncestors() {\r\n return super.getAncestors() as SketchNode[];\r\n }\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ITextNode } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { MeshNode } from './mesh-node';\r\n\r\n@Kb3dModel({\r\n token: Token.TextNode,\r\n})\r\nexport class TextNode extends MeshNode implements ITextNode {\r\n curveRadius = 0;\r\n charSpacing = 1;\r\n\r\n text = '';\r\n\r\n fontFile: string;\r\n fontSize: number;\r\n}\r\n","import { NodeReference } from '../decorators';\r\nimport { instanceOfAny } from '../decorators/model-utils';\r\nimport { IPatternFeature } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { SketchNode } from '../meshes';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, Feature } from './feature';\r\n\r\nexport abstract class PatternFeature extends Feature implements IPatternFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n @NodeReference(SketchNode) meshId: string;\r\n count: number;\r\n distance: number;\r\n addEndMesh: boolean;\r\n}\r\n\r\nexport function isPattern(o: Kb3dObject): o is PatternFeature {\r\n return instanceOfAny(o, Token.LinearPatternFeature, Token.CircularPatternFeature);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { IConnector } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { SpaceNode } from '../meshes/space-node';\r\nimport { Token } from '../token';\r\nimport { BaseConnector } from './base-connector';\r\n\r\n@Kb3dModel({\r\n token: Token.Connector,\r\n})\r\nexport class Connector extends BaseConnector implements IConnector {\r\n /** override base parent for more specific typing*/\r\n public _parent: SpaceNode | undefined;\r\n\r\n public getAncestors() {\r\n return super.getAncestors() as SpaceNode[];\r\n }\r\n\r\n public getSpaceParent() {\r\n return this._parent;\r\n }\r\n}\r\n\r\nexport function isConnector(o: Kb3dObject): o is Connector {\r\n return instanceOf(o, Token.Connector);\r\n}\r\n","import { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { ICircularPatternFeature } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY } from './feature';\r\nimport { PatternFeature } from './pattern-feature';\r\n\r\n@Kb3dModel({\r\n token: Token.CircularPatternFeature,\r\n})\r\nexport class CircularPatternFeature extends PatternFeature implements ICircularPatternFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n arc: number;\r\n pivot: KbVector;\r\n axis: KbVector;\r\n}\r\n\r\nexport function isCircularPattern(o: Kb3dObject): o is CircularPatternFeature {\r\n return instanceOf(o, Token.CircularPatternFeature);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IDeleteFacesFeature, IVertexGroup } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { Feature, eMeshChangeTypes } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.DeleteFacesFeature,\r\n})\r\nexport class DeleteFacesFeature extends Feature implements IDeleteFacesFeature {\r\n static _dependsOn = new Set([eMeshChangeTypes.VertexIndices]);\r\n static _affects = new Set([eMeshChangeTypes.VertexIndices, eMeshChangeTypes.Submeshes]);\r\n static _affectedBy = new Set([eMeshChangeTypes.VertexIndices, eMeshChangeTypes.Submeshes]);\r\n\r\n vertexGroups: Array> = [];\r\n}\r\n","import { MaterialService } from '@models/services';\r\nimport { Enumerable, Inject } from '../decorators';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IDisplacementMapFeature } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { TextureLayer } from '../materials';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, eMeshChangeTypes, Feature, FeatureWithTextures } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.DisplacementMapFeature,\r\n})\r\nexport class DisplacementMapFeature extends Feature implements IDisplacementMapFeature, FeatureWithTextures {\r\n static _affects = new Set([eMeshChangeTypes.VertexNormals, eMeshChangeTypes.VertexPositions]);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n private _textures: TextureLayer[];\r\n constructor(@Inject(Token.MaterialService) public _materialService: MaterialService) {\r\n super();\r\n\r\n this._initialized = false;\r\n }\r\n\r\n @Enumerable()\r\n public get textures(): TextureLayer[] {\r\n if (!this._textures) this._textures = [];\r\n return this._textures;\r\n }\r\n public set textures(val) {\r\n this._textures = val;\r\n }\r\n\r\n minDisplacement: number;\r\n maxDisplacement: number;\r\n _initialized: boolean;\r\n\r\n public getChildren(): Kb3dObject[] {\r\n return [...this.textures];\r\n }\r\n\r\n public getChildArrayForType(token: Token): Kb3dObject[] | undefined {\r\n if (token.isTexture()) {\r\n return this.textures;\r\n } else {\r\n throw 'unexpected token';\r\n }\r\n }\r\n}\r\n","import { IExtrudeFeature } from 'viewer';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IVertexGroup } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.ExtrudeFeature,\r\n})\r\nexport class ExtrudeFeature extends Feature implements IExtrudeFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n size: number;\r\n capEnd: boolean;\r\n capStart: boolean;\r\n vertexGroups: Array> = [];\r\n}\r\n","import { NodeReference } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eJoinType } from '../enums';\r\nimport { IJoinGeometryFeature } from '../kb3d-models';\r\nimport { MeshNode } from '../meshes/mesh-node';\r\nimport { Token } from '../token';\r\nimport { ALL_CHANGES, ALL_GEOMETRY, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.JoinGeometryFeature,\r\n})\r\nexport class JoinGeometryFeature extends Feature implements IJoinGeometryFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_CHANGES);\r\n\r\n _previewVisible: boolean;\r\n joinType: eJoinType;\r\n @NodeReference(MeshNode) meshId: string;\r\n}\r\n","import { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { ILinearPatternFeature } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY } from './feature';\r\nimport { PatternFeature } from './pattern-feature';\r\n\r\n@Kb3dModel({\r\n token: Token.LinearPatternFeature,\r\n})\r\nexport class LinearPatternFeature extends PatternFeature implements ILinearPatternFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n translation: KbVector;\r\n}\r\n\r\nexport function isLinearPattern(o: Kb3dObject): o is LinearPatternFeature {\r\n return instanceOf(o, Token.LinearPatternFeature);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ISliceFeature } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.SliceFeature,\r\n})\r\nexport class SliceFeature extends Feature implements ISliceFeature {\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n static _affects = new Set(ALL_GEOMETRY);\r\n\r\n _previewVisible: boolean;\r\n normal: KbVector;\r\n intersect: KbVector;\r\n removeGeometry: boolean;\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IMirrorFeature } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY } from './feature';\r\nimport { SliceFeature } from './slice-feature';\r\n\r\n@Kb3dModel({\r\n token: Token.MirrorFeature,\r\n})\r\nexport class MirrorFeature extends SliceFeature implements IMirrorFeature {\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n static _affects = new Set(ALL_GEOMETRY);\r\n\r\n cloneGeometry: boolean;\r\n}\r\n","import { IgnoreChanges } from '../decorators/change-tracker';\r\nimport { Enumerable } from '../decorators/enumerable';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eFeatureCenter } from '../enums';\r\nimport { IMoveVerticesFeature } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { eMeshChangeTypes, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.MoveVerticesFeature,\r\n})\r\nexport class MoveVerticesFeature extends Feature implements IMoveVerticesFeature {\r\n static _dependsOn = new Set([eMeshChangeTypes.VertexIndices]);\r\n static _affectedBy = new Set([eMeshChangeTypes.VertexPositions]);\r\n static _affects = new Set([eMeshChangeTypes.VertexPositions]);\r\n\r\n translation: KbVector;\r\n rotationAngle: number;\r\n rotationAxis: KbVector;\r\n scale: KbVector;\r\n center: eFeatureCenter;\r\n _previewParticleSize = 0.005;\r\n\r\n @IgnoreChanges\r\n private _vertexIndices: number[];\r\n @Enumerable()\r\n public get vertexIndices(): number[] {\r\n if (!this._vertexIndices) this._vertexIndices = [];\r\n return this._vertexIndices;\r\n }\r\n public set vertexIndices(val) {\r\n this._vertexIndices = val;\r\n }\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { INormalSmoothingFeature, IVertexGroup } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.NormalSmoothingFeature,\r\n})\r\nexport class NormalSmoothingFeature extends Feature implements INormalSmoothingFeature {\r\n //static _dependsOn = new Set([eMeshChangeTypes.VertexIndices]);\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n vertexGroups: Array> = [];\r\n smooth = true;\r\n}\r\n","import { PickingInfo } from '@babylonjs/core/Collisions/pickingInfo';\r\nimport { KeyboardInfo } from '@babylonjs/core/Events/keyboardEvents';\r\nimport { PointerInfo, PointerInfoBase } from '@babylonjs/core/Events/pointerEvents';\r\nimport { BoundingBoxInfo } from '@view/modules';\r\nimport { AnnotationNode } from './annotations';\r\nimport { eConnectionMode, eDragMode, eMateType } from './enums';\r\nimport { Connector } from './features/connector';\r\nimport { Kb3dManager } from './kb3d-manager';\r\nimport { Kb3dObject } from './kb3d-object';\r\nimport { MateNode } from './mates/mate-node';\r\nimport { isPickable } from './meshes/mesh-utilities';\r\nimport { SpaceNode } from './meshes/space-node';\r\nimport { KbVector } from './primitives';\r\n\r\nexport enum eHandler {\r\n click = 'click',\r\n doubleClick = 'doubleClick',\r\n draggable = 'draggable',\r\n hotspot = 'hotspot',\r\n boundingBox = 'boundingBox',\r\n}\r\n\r\nexport type PointerInfoMinimal = PointerInfoBase & Pick;\r\n\r\nexport interface IKb3dPickInfo {\r\n pickInfo: PickingInfo;\r\n\r\n /** the specific node that the pointer is over */\r\n targetNode?: SpaceNode;\r\n\r\n /** the 3d point in the world where the mesh was clicked */\r\n pickedPoint?: KbVector;\r\n /** the 3d point of the target mesh that was clicked */\r\n meshPoint?: KbVector;\r\n\r\n /** UV intersection coordinates */\r\n u?: number;\r\n v?: number;\r\n\r\n getNormal: () => KbVector | undefined;\r\n}\r\n\r\nexport interface IKb3dPointerArgs extends PointerInfoBase, IKb3dPickInfo {\r\n /** the node that the handler was set on (could be an ancestor of the targetNode) */\r\n sourceNode?: SpaceNode;\r\n /** whether the event should continue to bubble up the ancestor nodes */\r\n propagate?: boolean;\r\n /** the type of pointer device. Eg: 'mouse', 'touch', etc. */\r\n pointerType?: string;\r\n /** the mouse button that was pressed (if there is one). 0 = left, 1 = center, 2 = right */\r\n button?: number;\r\n /** whether the ctrl key was pressed during the click */\r\n ctrlKey?: boolean;\r\n /** whether the shift key was pressed during the click */\r\n shiftKey?: boolean;\r\n /** whether the alt key was pressed during the click */\r\n altKey?: boolean;\r\n /** the screen coordinates of the click in relation to the canvas viewer */\r\n canvasX?: number;\r\n canvasY?: number;\r\n}\r\n\r\nexport interface IKb3dFacetSelectArgs extends IKb3dPointerArgs {\r\n selectedFaces: number[];\r\n}\r\n\r\nexport interface IKeyboardArgs extends KeyboardInfo {\r\n key: string;\r\n keyCode: number;\r\n altKey: boolean;\r\n ctrlKey: boolean;\r\n shiftKey: boolean;\r\n repeat: boolean;\r\n}\r\n\r\nexport type Kb3dPointerHandler = (args: IKb3dPointerArgs) => void;\r\n\r\nexport type Kb3dBoundingBoxChangeHandler = {\r\n mode: 'once' | 'forever';\r\n handler: (args: BoundingBoxInfo) => void;\r\n};\r\n\r\nexport interface IDragArgs {\r\n dragNode: SpaceNode;\r\n newPos: KbVector;\r\n startPos: KbVector;\r\n newRotationEuler: KbVector;\r\n newRotationAxis: KbVector;\r\n newRotationAngle: number;\r\n allow: boolean;\r\n u: number;\r\n v: number;\r\n //relativeSurfacePos: IVector2;\r\n\r\n /*following only used for connections*/\r\n connection?: IConnection;\r\n\r\n /** if withMates is true for the draggable, then this will contain the added mate in the dropped rule */\r\n mate?: MateNode;\r\n}\r\n\r\nexport interface IConnection {\r\n dragConnector: Connector;\r\n otherConnector: Connector;\r\n dragNode?: SpaceNode;\r\n otherNode?: SpaceNode;\r\n}\r\n\r\nexport interface ICanConnectArgs extends IConnection {\r\n allow: boolean;\r\n}\r\n\r\n// export enum eDragMode {\r\n// free,\r\n// plane,\r\n// //axis,\r\n// surface\r\n// }\r\n\r\n// export enum eConnectorMode {\r\n// none,\r\n// world,\r\n// screen\r\n// }\r\n\r\nexport interface IDraggable {\r\n /** The id, name, or wildcard of the node to define as draggable */\r\n id?: string | SpaceNode;\r\n /** The mode of the drag */\r\n mode?: eDragMode; // free, plane, surface\r\n /** In plane or linear mode, is a vector normal to the drag plane. This normal + the picked point on the mesh will determine the intersection plane */\r\n planeNormal?: KbVector;\r\n // /** In plane mode, it is the origin of the plane. If not provided, the origin of the drag node is used (usually the desired effect) */\r\n // planeOrigin?: KbVector;\r\n /** if disabled, the node origin will snap to the mouse position when you start dragging */\r\n disableOffset?: boolean;\r\n\r\n //axis?: KbVector;\r\n\r\n /** In surface mode, holds the id (if a singular surface) or ids (if multiple surfaces) of the surfaces */\r\n surfaceNodes?: string | string[];\r\n\r\n /** whether connectors are enabled during this drag operation and if so how the gauge proximity */\r\n connectionMode?: eConnectionMode;\r\n /** how to align the connectors when a connection is made */\r\n connectionType?: eMateType;\r\n /** whether to show the connector spheres or not */\r\n showConnectors?: boolean;\r\n /** the proximity distance between connectors that counts as a possible connection */\r\n connectRadius?: number;\r\n /** when a connector drag, controls the opacity of the dragged items */\r\n dragOpacity?: number;\r\n /**\r\n * Will add mates once a connection is made. Also uses mates to understand what connectors\r\n * are open for connection (meaning not part of mate). Will dynamically swap mate connectors\r\n * based on the drag node. Only valid if connectionMode is not 'none'\r\n * */\r\n withMates?: boolean;\r\n\r\n /** Called when the drag is started */\r\n dragStart?: (args: IDragArgs) => void;\r\n // /** Called at every frame to see if we want to allow the move */\r\n // allow?: (args: IDragArgs) => boolean;\r\n /** Called at every frame while dragging. Can be used to custom update the position by modifying newPos */\r\n dragging?: (args: IDragArgs) => void;\r\n /** Called when the node is dropped */\r\n dropped?: (args: IDragArgs) => void;\r\n\r\n canConnect?: (args: ICanConnectArgs) => void;\r\n}\r\n\r\n/** A 2 layer map that stores values by a key 1st, then a 2nd level of a string tag, then an array of values */\r\nexport class TagArrayMap {\r\n private _db = new Map>();\r\n\r\n public get(key: TKey, tag: string) {\r\n const v = this._db.get(key)?.get(tag);\r\n return v || [];\r\n }\r\n\r\n public deleteByKeyValue(key: TKey, value: TValue) {\r\n const e = this._db.get(key);\r\n if (e) {\r\n for (const values of e.values()) {\r\n values.removeWhere(v => v == value);\r\n }\r\n this.deleteEntryIfEmpty(key);\r\n }\r\n }\r\n\r\n public getByKey(key: TKey): TValue[] {\r\n if (this._db.has(key)) {\r\n return (this._db.get(key) as ArrayMap).all();\r\n }\r\n return [];\r\n }\r\n\r\n public set(key: TKey, tag: string, value: TValue) {\r\n if (!this._db.has(key)) this._db.set(key, new ArrayMap());\r\n this._db.get(key)?.add(tag, value);\r\n }\r\n\r\n public deleteByTag(...tags: string[]) {\r\n const result: Array<{ node: TKey; handlers: Record }> = [];\r\n for (const [key, value] of this._db.entries()) {\r\n const nodeResult: Record = {};\r\n result.push({ node: key, handlers: nodeResult });\r\n\r\n for (const tag of tags) {\r\n const handler = value.get(tag);\r\n if (handler) {\r\n nodeResult[tag] = handler;\r\n }\r\n\r\n value.delete(tag);\r\n }\r\n this.deleteEntryIfEmpty(key);\r\n }\r\n return result;\r\n }\r\n\r\n public delete(key: TKey, tag: string) {\r\n const e = this._db.get(key);\r\n if (e) {\r\n const result = e.get(tag);\r\n e.delete(tag);\r\n this.deleteEntryIfEmpty(key);\r\n return result;\r\n }\r\n return [];\r\n }\r\n\r\n public deleteByKey(key: TKey) {\r\n const handlers = this._db.get(key);\r\n const result: Record = {};\r\n if (handlers) {\r\n handlers.forEach((value, key) => {\r\n result[key] = value;\r\n });\r\n }\r\n\r\n this._db.delete(key);\r\n\r\n return result;\r\n }\r\n\r\n public clear() {\r\n this._db.clear();\r\n }\r\n\r\n public has(key: TKey, tag: string) {\r\n return this.get(key, tag).length > 0;\r\n }\r\n\r\n protected deleteEntryIfEmpty(key: TKey) {\r\n const e = this._db.get(key);\r\n if (e && !e.size) this._db.delete(key);\r\n }\r\n}\r\n\r\nexport class ArrayMap extends Map {\r\n public get(key: TKey) {\r\n return super.get(key) || [];\r\n }\r\n\r\n public add(key: TKey, ...values: TValue[]) {\r\n if (!this.has(key)) {\r\n super.set(key, [...values]);\r\n } else {\r\n this.get(key).push(...values);\r\n }\r\n }\r\n\r\n public removeValue(key: TKey, ...values: TValue[]) {\r\n const arr = super.get(key);\r\n if (arr) {\r\n arr.removeWhere(i => values.some(v => v == i));\r\n }\r\n }\r\n\r\n public all() {\r\n return [...this.values()].flat();\r\n }\r\n}\r\n\r\nexport class SetMap extends Map> {\r\n public get(key: TKey) {\r\n const set = super.get(key);\r\n if (!set) super.set(key, new Set());\r\n return super.get(key)!;\r\n }\r\n\r\n public add(key: TKey, ...values: TValue[]) {\r\n const s = this.get(key);\r\n for (const v of values) s.add(v);\r\n }\r\n\r\n public removeValue(key: TKey, ...values: TValue[]) {\r\n const s = super.get(key);\r\n if (s) {\r\n for (const v of values) s.delete(v);\r\n }\r\n }\r\n\r\n public all() {\r\n return [...this.values()].flat();\r\n }\r\n}\r\n\r\nexport class HandlerMap extends TagArrayMap {\r\n constructor(private manager: Kb3dManager) {\r\n super();\r\n }\r\n\r\n public add(idNameOrNode: string | SpaceNode | AnnotationNode, tag: string, handler: THandler) {\r\n let nodes = new Array();\r\n if (typeof idNameOrNode == 'string') {\r\n nodes = this.manager.getNodesByIdOrName(idNameOrNode, true);\r\n } else {\r\n nodes.push(idNameOrNode);\r\n }\r\n for (const n of nodes) {\r\n if (isPickable(n)) {\r\n this.set(n, tag, handler);\r\n }\r\n }\r\n }\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eConnectorPositionMode } from '../enums';\r\nimport { ISketchControlPoint } from '../kb3d-models';\r\nimport { SketchPath } from '../meshes/sketch-node-path';\r\nimport { KbVector } from '../primitives';\r\nimport { Token } from '../token';\r\nimport { BaseConnector } from './base-connector';\r\n\r\n@Kb3dModel({\r\n token: Token.SketchControlPoint,\r\n})\r\nexport class SketchControlPoint extends BaseConnector implements ISketchControlPoint {\r\n enabled = true; // non-configurable\r\n positionMode = eConnectorPositionMode.absolute;\r\n direction2?: KbVector;\r\n\r\n /** override base parent for more specific typing*/\r\n public _parent: SketchPath | undefined;\r\n\r\n public getSketch() {\r\n return this._parent?._parent;\r\n }\r\n\r\n public getSpaceParent() {\r\n return this.getSketch();\r\n }\r\n\r\n public getAncestors() {\r\n return super.getAncestors() as SketchPath[];\r\n }\r\n}\r\n\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eUvMode } from '../enums';\r\nimport { IUvMapFeature } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.UvMapFeature,\r\n})\r\nexport class UvMapFeature extends Feature implements IUvMapFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n center: KbVector;\r\n projectionAxis: KbVector;\r\n worldPosition = this._parent?.position;\r\n angle: number;\r\n scale: KbVector;\r\n uTile: number;\r\n vTile: number;\r\n uOffset: number;\r\n vOffset: number;\r\n mode: eUvMode;\r\n _previewMaterialVisible: boolean;\r\n _showMaterial: boolean;\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { ISubmeshFeature, IVertexGroup } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { ALL_GEOMETRY, eMeshChangeTypes } from './feature';\r\nimport { UvMapFeature } from './uv-map-feature';\r\n\r\nexport interface SubmeshData {\r\n materialIndex: number;\r\n verticesStart: number;\r\n verticesCount: number;\r\n indexStart: number;\r\n indexCount: number;\r\n}\r\n\r\n@Kb3dModel({\r\n token: Token.SubmeshFeature,\r\n})\r\nexport class SubmeshFeature extends UvMapFeature implements ISubmeshFeature {\r\n static _dependsOn = new Set([eMeshChangeTypes.VertexIndices]);\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set(ALL_GEOMETRY);\r\n\r\n vertexGroups: Array> = [];\r\n materialId: string;\r\n uvMapping: boolean;\r\n}\r\n\r\nexport function isSubmesh(o: Kb3dObject): o is SubmeshFeature {\r\n return instanceOf(o, Token.SubmeshFeature);\r\n}\r\n","import { NodeReference } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ISweepFeature } from '../kb3d-models';\r\nimport { SketchNode } from '../meshes/sketch-node';\r\nimport { Token } from '../token';\r\nimport { BaseConnector } from './base-connector';\r\nimport { ExtrudeFeature } from './extrude-feature';\r\nimport { ALL_GEOMETRY, eMeshChangeTypes } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.SweepFeature,\r\n})\r\nexport class SweepFeature extends ExtrudeFeature implements ISweepFeature {\r\n static _affects = new Set(ALL_GEOMETRY);\r\n static _affectedBy = new Set([...ALL_GEOMETRY, eMeshChangeTypes.Transform]);\r\n\r\n @NodeReference(BaseConnector) start?: string;\r\n @NodeReference(BaseConnector) end?: string;\r\n @NodeReference(SketchNode) path?: string;\r\n\r\n size = 0;\r\n mitredExtrusion: boolean;\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ITransformFeature } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { eMeshChangeTypes, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.TransformFeature,\r\n})\r\nexport class TransformFeature extends Feature implements ITransformFeature {\r\n static _affectedBy = new Set([eMeshChangeTypes.Transform, eMeshChangeTypes.VertexPositions]);\r\n static _affects = new Set([eMeshChangeTypes.VertexPositions]);\r\n\r\n scale: KbVector;\r\n}\r\n","import { IgnoreChanges } from '../decorators/change-tracker';\r\nimport { Enumerable } from '../decorators/enumerable';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eFeatureCenter } from '../enums';\r\nimport { IWeldVerticesFeature } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { eMeshChangeTypes, Feature } from './feature';\r\n\r\n@Kb3dModel({\r\n token: Token.WeldVerticesFeature,\r\n})\r\nexport class WeldVerticesFeature extends Feature implements IWeldVerticesFeature {\r\n static _dependsOn = new Set([eMeshChangeTypes.VertexIndices]);\r\n static _affectedBy = new Set([eMeshChangeTypes.VertexPositions, eMeshChangeTypes.VertexIndices]);\r\n static _affects = new Set([\r\n eMeshChangeTypes.VertexPositions,\r\n eMeshChangeTypes.VertexIndices,\r\n eMeshChangeTypes.VertexUvs,\r\n eMeshChangeTypes.VertexNormals,\r\n eMeshChangeTypes.Submeshes,\r\n ]);\r\n\r\n translation: KbVector;\r\n rotationAngle: number;\r\n _previewParticleSize: number;\r\n rotationAxis: KbVector;\r\n scale: KbVector;\r\n center: eFeatureCenter;\r\n\r\n @IgnoreChanges\r\n private _vertexIndices: number[];\r\n @Enumerable()\r\n public get vertexIndices(): number[] {\r\n if (!this._vertexIndices) this._vertexIndices = [];\r\n return this._vertexIndices;\r\n }\r\n public set vertexIndices(val) {\r\n this._vertexIndices = val;\r\n }\r\n}\r\n","import { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { NodeReference } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOfAny } from '../decorators/model-utils';\r\nimport { eAnnotationLineStyle, eTextureHorizontalAlign, eTextureVerticalAlign } from '../enums';\r\nimport { Connector } from '../features';\r\nimport { IAnnotationNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\n\r\n@Kb3dModel({\r\n token: Token.AnnotationNode,\r\n})\r\nexport class AnnotationNode extends Kb3dObject implements IAnnotationNode {\r\n public constructor() {\r\n super();\r\n }\r\n\r\n isPickable: boolean;\r\n enabled: boolean;\r\n billboard: boolean;\r\n color: KbColor;\r\n fontFamily: string;\r\n fontSize: number;\r\n keepOnTop: boolean;\r\n offset: KbVector;\r\n lineStyle: eAnnotationLineStyle;\r\n lineSpacing: number;\r\n horizontalTextAlign: eTextureHorizontalAlign;\r\n horizontalBoxAlign: eTextureHorizontalAlign;\r\n verticalBoxAlign: eTextureVerticalAlign;\r\n label = '';\r\n preloadFontStylesheet = '';\r\n\r\n @NodeReference(Connector, 'position', 'direction', 'angle')\r\n targetId?: string;\r\n}\r\n\r\nexport function isAnnotation(node: Kb3dObject): node is AnnotationNode {\r\n return instanceOfAny(node, Token.AnnotationNode, Token.DimensionNode);\r\n}\r\n","import { NodeReference } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eDimensionAxis, eDimensionLineCapStyle } from '../enums';\r\nimport { Connector } from '../features/connector';\r\nimport { IDimensionNode } from '../kb3d-models';\r\nimport { KbVector } from '../primitives';\r\nimport { Token } from '../token';\r\nimport { AnnotationNode } from './annotation-node';\r\n\r\n@Kb3dModel({\r\n token: Token.DimensionNode,\r\n})\r\nexport class DimensionNode extends AnnotationNode implements IDimensionNode {\r\n public constructor() {\r\n super();\r\n }\r\n\r\n lineCapStyle: eDimensionLineCapStyle;\r\n axis: eDimensionAxis;\r\n lineThickness: number;\r\n dimensionGap: number;\r\n labelOffset: KbVector;\r\n dimensionUnitPrecision: number;\r\n scaleWithCamera: boolean;\r\n\r\n @NodeReference(Connector, 'position')\r\n target2Id?: string;\r\n}\r\n","import { Kb3dModel } from './decorators/kb3d-decorator';\r\nimport { IImportInfo } from './kb3d-models';\r\nimport { Token } from './token';\r\n\r\n@Kb3dModel({\r\n token: Token.ImportInfo,\r\n trackChanges: false,\r\n})\r\nexport class ImportInfo implements IImportInfo {}\r\n","import { isAbsoluteUrl } from '../classes/utilities';\r\nimport { HttpService } from './http-service';\r\n\r\nconst fontFilesLoading = new Map>();\r\nconst stylesheetsLoading = new Map>();\r\nconst fontFamilySrcs = new Map();\r\n\r\nexport class FontService {\r\n constructor(private httpService: HttpService, private assetRoot = '') {}\r\n\r\n /** Can be both the font face name as well as the font file URL */\r\n public readyFonts = new Map();\r\n\r\n loadFont(stylesheetUrl: string, fontFamilies: string[]): Promise {\r\n const fontFaceSet: FontFaceSet = (document as any).fonts;\r\n if (typeof fontFaceSet === 'undefined') {\r\n return Promise.reject('FontFaceSet api not available');\r\n }\r\n\r\n return this.loadStylesheet(stylesheetUrl).then(() => this.loadFontFamily(fontFaceSet, fontFamilies));\r\n }\r\n\r\n loadFontByFile(path: string) {\r\n const absPath = isAbsoluteUrl(path) ? path : this.getAbsoluteFontPath(path);\r\n let loadPromise: Promise;\r\n if (fontFilesLoading.has(absPath)) {\r\n loadPromise = fontFilesLoading.get(absPath)!;\r\n } else {\r\n const promise = this.httpService.getPublicStatic(absPath, 'arraybuffer');\r\n fontFilesLoading.set(absPath, promise);\r\n loadPromise = promise;\r\n }\r\n\r\n return loadPromise.then(buffer => {\r\n if (buffer.byteLength === 0) {\r\n return Promise.reject('Could not fetch font');\r\n } else {\r\n this.readyFonts.set(path, buffer);\r\n }\r\n return buffer;\r\n });\r\n }\r\n\r\n loadFontData(stylesheetUrl: string, fontFamilies: string[]) {\r\n return this.loadStylesheet(stylesheetUrl).then(() => this.getFontData(fontFamilies));\r\n }\r\n\r\n getAbsoluteFontPath(relativePath: string) {\r\n return `${this.assetRoot}/media/${relativePath}`; //it's a relative path to the media folder\r\n }\r\n\r\n private loadStylesheet(stylesheetUrl: string) {\r\n let stylesheetLoad = stylesheetsLoading.get(stylesheetUrl);\r\n if (!stylesheetLoad) {\r\n stylesheetLoad = this.httpService.getPublicStatic(stylesheetUrl).then(res => {\r\n // Parse the css and store the srcs to the font files\r\n const fontFaces = res.matchAll(/@font-face\\s*{([\\s\\S]*?)}/gm);\r\n for (const face of fontFaces) {\r\n const fontFamilyMatch = face[1].match(/font-family\\s*:\\s*['\"]?(.*?)['\"]?[;,\\n]/m);\r\n\r\n if (fontFamilyMatch) {\r\n const fontFamilyName = fontFamilyMatch[1];\r\n const srcMatch = face[1].match(/src\\s*:.*?url\\s*\\([\\s\"']*(.*?)[\\s\"']*\\)/m);\r\n if (srcMatch) {\r\n const fontSrc = srcMatch[1];\r\n fontFamilySrcs.set(fontFamilyName.trim().toLowerCase(), fontSrc.trim());\r\n }\r\n }\r\n }\r\n });\r\n stylesheetsLoading.set(stylesheetUrl, stylesheetLoad);\r\n }\r\n\r\n return stylesheetLoad;\r\n }\r\n\r\n private getFontData(fontFamilies: string[]) {\r\n const loadFaces: string[] = [];\r\n const loadPromises: Array> = [];\r\n\r\n fontFamilies.forEach(fontFamily => {\r\n const fontSrc = fontFamilySrcs.get(fontFamily.trim().toLowerCase());\r\n if (!fontSrc) {\r\n console.warn(`Font family ${fontFamily} not found. Is it being loaded by the preloaded stylesheet?`);\r\n } else if (fontFilesLoading.has(fontFamily)) {\r\n loadPromises.push(fontFilesLoading.get(fontFamily)!);\r\n loadFaces.push(fontFamily);\r\n } else {\r\n const promise = this.httpService.getPublicStatic(fontSrc, 'arraybuffer');\r\n fontFilesLoading.set(fontFamily, promise);\r\n loadPromises.push(promise);\r\n loadFaces.push(fontFamily);\r\n }\r\n });\r\n\r\n const resMap: Record = {};\r\n return Promise.all(loadPromises).then(buffers => {\r\n buffers.forEach((buffer, index) => {\r\n resMap[loadFaces[index]] = buffer;\r\n this.readyFonts.set(loadFaces[index], buffer);\r\n });\r\n return resMap;\r\n });\r\n }\r\n\r\n private loadFontFamily(fontFaceSet: FontFaceSet, fontFamilies: string[]): Promise {\r\n return this.getFontData(fontFamilies).then(resultData => {\r\n const resultFonts: FontFace[] = [];\r\n fontFamilies.forEach(fontFamily => {\r\n if (resultData[fontFamily]) {\r\n const newFontFace = new FontFace(fontFamily, resultData[fontFamily]);\r\n // @ts-expect-error TS 5.1.6 definition does not include add on FontFaceSet\r\n fontFaceSet.add(newFontFace);\r\n resultFonts.push(newFontFace);\r\n } else {\r\n console.warn('Could not load font ' + fontFamily);\r\n }\r\n });\r\n return resultFonts;\r\n });\r\n }\r\n}\r\n","import { isAbsoluteUrl } from '@models/classes/utilities';\r\nimport { Observable } from 'rxjs';\r\n\r\nexport enum eContentType {\r\n json = 'application/json',\r\n formData = 'multipart/form-data',\r\n}\r\n\r\nexport interface IHttpEnvironment {\r\n lastDeploy?: number;\r\n cacheBuster?: string;\r\n}\r\n\r\ninterface IDeferredAssetCall {\r\n func: () => Promise;\r\n resolve: (value: T | PromiseLike) => void;\r\n reject: (reason?: any) => void;\r\n priority: number;\r\n}\r\n\r\nexport interface IBinaryResponse {\r\n data: T;\r\n width?: number;\r\n height?: number;\r\n}\r\n\r\nexport const ABORTED = 'ABORTED';\r\n\r\nexport class HttpService {\r\n public trackedAssetCalls = new Array>();\r\n private deferredAssetCalls = new Array>();\r\n private httpCallsToAbort = new Map();\r\n private deferredExecuted = false;\r\n\r\n constructor(private environment?: IHttpEnvironment) {}\r\n\r\n public addCacheParams(url: string): string {\r\n return this.getUrlWithParams(url, this.getEnvironmentCacheParams());\r\n }\r\n\r\n public get(url: string, params?: Record, trackAssetCall = true) {\r\n if (!isAbsoluteUrl(url) && this.environment) {\r\n // api calls in the test and prod environments should send the last deploy,\r\n // which allows the browser cache to store results for some calls\r\n if (this.environment) {\r\n const addParams = this.getEnvironmentCacheParams();\r\n params = params ? { ...params, ...addParams } : addParams;\r\n }\r\n }\r\n\r\n const u = this.getUrlWithParams(url, params);\r\n const p = this.fetchWrapper(u, 'GET');\r\n if (trackAssetCall) {\r\n this.trackAssetCall(p);\r\n }\r\n return p;\r\n }\r\n\r\n public getPublicStatic(\r\n url: string,\r\n type: 'json',\r\n params?: Record,\r\n trackAssetCall?: boolean\r\n ): Promise;\r\n public getPublicStatic(\r\n url: string,\r\n type: 'blob',\r\n params?: Record,\r\n trackAssetCall?: boolean\r\n ): Promise;\r\n public getPublicStatic(\r\n url: string,\r\n type: 'arraybuffer',\r\n params?: Record,\r\n trackAssetCall?: boolean\r\n ): Promise;\r\n public getPublicStatic(\r\n url: string,\r\n type?: 'text',\r\n params?: Record,\r\n trackAssetCall?: boolean\r\n ): Promise;\r\n public getPublicStatic(\r\n url: string,\r\n type: 'text' | 'blob' | 'json' | 'arraybuffer' = 'text',\r\n params?: Record,\r\n trackAssetCall = true\r\n ) {\r\n const u = this.getUrlWithParams(url, params);\r\n\r\n const requestInit = {\r\n method: 'GET',\r\n credentials: 'omit',\r\n } as RequestInit;\r\n const p = fetch(u, requestInit).then(res => {\r\n if (type === 'text') {\r\n return res.text();\r\n } else if (type === 'blob') {\r\n return res.blob();\r\n } else if (type === 'arraybuffer') {\r\n return res.arrayBuffer();\r\n } else {\r\n return res.json();\r\n }\r\n });\r\n\r\n if (trackAssetCall) {\r\n this.trackAssetCall(p);\r\n }\r\n return p;\r\n }\r\n\r\n public post(url: string, body?: any, contentType = eContentType.json) {\r\n return this.fetchWrapper(url, 'POST', body, contentType);\r\n }\r\n public put(url: string, body?: any, contentType = eContentType.json) {\r\n return this.fetchWrapper(url, 'PUT', body, contentType);\r\n }\r\n public delete(url: string, params?: Record) {\r\n const u = this.getUrlWithParams(url, params);\r\n return this.fetchWrapper(u, 'DELETE');\r\n }\r\n\r\n getBinary(\r\n url: string,\r\n responseType: 'arraybuffer',\r\n trackAssetCall: boolean,\r\n appendCacheParameters?: boolean,\r\n abortSubject?: Observable\r\n ): Promise>;\r\n getBinary(\r\n url: string,\r\n responseType: 'blob',\r\n trackAssetCall: boolean,\r\n appendCacheParameters?: boolean,\r\n abortSubject?: Observable\r\n ): Promise>;\r\n public getBinary(\r\n url: string,\r\n responseType: 'arraybuffer' | 'blob',\r\n trackAssetCall: boolean,\r\n appendCacheParameters = false,\r\n abortSubject?: Observable\r\n ): Promise> {\r\n const xhr = new XMLHttpRequest();\r\n if (appendCacheParameters && !isAbsoluteUrl(url) && this.environment) {\r\n if (this.environment) {\r\n const addParams = this.getEnvironmentCacheParams();\r\n url = this.getUrlWithParams(url, addParams);\r\n }\r\n }\r\n const abortSub = abortSubject?.subscribe(() => {\r\n xhr.abort();\r\n });\r\n\r\n const p = new Promise>((resolve, reject) => {\r\n xhr.open('GET', url, true);\r\n xhr.responseType = responseType;\r\n\r\n xhr.onload = function (oEvent) {\r\n if (xhr.status >= 200 && xhr.status < 300) {\r\n const allHeaders = xhr.getAllResponseHeaders();\r\n let height = null,\r\n width = null;\r\n if (allHeaders.match(/Original-Height/i)) {\r\n height = xhr.getResponseHeader('X-Original-Height');\r\n width = xhr.getResponseHeader('X-Original-Width');\r\n }\r\n const response: IBinaryResponse = {\r\n data: xhr.response,\r\n };\r\n if (height && width) {\r\n response.height = parseInt(height);\r\n response.width = parseInt(width);\r\n }\r\n resolve(response);\r\n } else {\r\n reject(xhr.statusText);\r\n }\r\n abortSub?.unsubscribe();\r\n };\r\n xhr.onerror = e => {\r\n reject(e);\r\n abortSub?.unsubscribe();\r\n };\r\n xhr.onabort = () => {\r\n reject(ABORTED);\r\n // do nothing\r\n };\r\n\r\n xhr.send(null);\r\n });\r\n\r\n if (trackAssetCall) {\r\n this.trackAssetCall(p);\r\n }\r\n\r\n return p;\r\n }\r\n\r\n /**\r\n * delays execution of parameter function until all blocking assets have been loaded for the scene.\r\n * executes immediately if scene is already loaded.\r\n */\r\n defer(func: () => Promise, priority = 100): Promise {\r\n if (this.deferredExecuted) {\r\n return func();\r\n } else {\r\n return new Promise((resolve, reject) => {\r\n this.deferredAssetCalls.push({ func, resolve, reject, priority });\r\n });\r\n }\r\n }\r\n\r\n executeDeferredCalls() {\r\n this.deferredAssetCalls.sort((a, b) => a.priority - b.priority);\r\n for (const call of this.deferredAssetCalls) {\r\n call.func().then(call.resolve).catch(call.reject);\r\n }\r\n this.deferredAssetCalls = [];\r\n this.deferredExecuted = true;\r\n }\r\n\r\n protected trackAssetCall(p: Promise) {\r\n const trackedPromise = p.finally(() => {\r\n this.trackedAssetCalls.remove(trackedPromise);\r\n });\r\n this.trackedAssetCalls.push(trackedPromise);\r\n }\r\n\r\n private getEnvironmentCacheParams(): Record {\r\n if (this.environment) {\r\n const params: Record = {};\r\n if (this.environment.lastDeploy) {\r\n params.d = this.environment.lastDeploy.toString();\r\n }\r\n if (this.environment.cacheBuster) {\r\n params.v = this.environment.cacheBuster;\r\n }\r\n return params;\r\n }\r\n return {};\r\n }\r\n\r\n private getUrlWithParams(url: string, params?: Record) {\r\n if (!params) return url;\r\n const urlParams = new URLSearchParams(Object.entries(params));\r\n\r\n let prefix = '?';\r\n if (url.match(/\\?/)) {\r\n prefix = '&';\r\n }\r\n\r\n return `${url}${prefix}${urlParams.toString()}`;\r\n }\r\n\r\n private fetchWrapper(\r\n url: string,\r\n method: string,\r\n body?: T,\r\n contentType: eContentType = eContentType.json\r\n ): Promise {\r\n const headers: Headers = new Headers();\r\n\r\n const requestInit = {\r\n method,\r\n headers,\r\n credentials: 'include',\r\n } as RequestInit;\r\n\r\n if (method.equalsAny('POST', 'PUT')) {\r\n if (contentType == eContentType.json) {\r\n headers.append('Content-Type', contentType);\r\n requestInit.body = JSON.stringify(body);\r\n } else if (contentType == eContentType.formData) {\r\n requestInit.body = body as any as FormData;\r\n }\r\n }\r\n\r\n const p = fetch(url, requestInit).then(r => {\r\n if (r.ok) {\r\n return r.json().catch(() => body);\r\n } else {\r\n throw new Error(JSON.stringify(r));\r\n }\r\n });\r\n return p as Promise;\r\n }\r\n}\r\n","export function getRotatedDimensions(width: number, height: number, rAngle: number) {\r\n const rad = (rAngle * Math.PI) / 180;\r\n return {\r\n width: width * Math.cos(rad) + height * Math.sin(rad),\r\n height: width * Math.sin(rad) + height * Math.cos(rad),\r\n };\r\n}\r\n\r\nexport function scaleImagePreserveAspect(\r\n targetWidth: number,\r\n targetHeight: number,\r\n naturalWidth?: number,\r\n naturalHeight?: number\r\n) {\r\n let drawWidth: number, drawHeight: number;\r\n const imageWidth = naturalWidth || 256;\r\n const imageHeight = naturalHeight || 256;\r\n if (imageWidth > imageHeight) {\r\n drawWidth = targetWidth;\r\n drawHeight = (imageHeight / imageWidth) * targetWidth;\r\n } else {\r\n drawWidth = (imageWidth / imageHeight) * targetHeight;\r\n drawHeight = targetHeight;\r\n }\r\n\r\n return {\r\n drawWidth: Math.ceil(drawWidth),\r\n drawHeight: Math.ceil(drawHeight),\r\n };\r\n}\r\n\r\nexport function getBinClampedSize(width: number, height: number, rounding: 'floor' | 'ceil' = 'floor') {\r\n if (rounding === 'floor') {\r\n const log2 = Math.min(Math.log2(width), Math.log2(height));\r\n return Math.pow(2, Math.floor(log2));\r\n } else {\r\n const log2 = Math.max(Math.log2(width), Math.log2(height));\r\n return Math.pow(2, Math.ceil(log2));\r\n }\r\n}\r\n","export const KBMAXPREFIX = '____kbm____';\r\nexport const LOCAL_ENVIRONMENT_DOMAIN = 'library://';\r\n","const SLOW_NETWORK_THRESHOLD = 100; // kB per second\r\n\r\nlet slowWarningThrown = false;\r\n\r\nexport function attachLoadingTimer(p: Promise) {\r\n const startTime = performance.now();\r\n\r\n p.then(result => {\r\n if (slowWarningThrown) {\r\n return;\r\n }\r\n\r\n let fileSize = 0;\r\n const endTime = performance.now();\r\n if ('byteLength' in result.data) {\r\n fileSize = result.data.byteLength;\r\n } else if ('size' in result.data) {\r\n fileSize = result.data.size;\r\n }\r\n\r\n if (startTime && endTime && fileSize > 50000) {\r\n const resultTime = endTime - startTime; // in milliseconds\r\n\r\n // if download speed is less than 100 kB per second, throw slow loading warning\r\n if (fileSize / resultTime < SLOW_NETWORK_THRESHOLD) {\r\n console.warn('Slow network detected. Scene experience may be degraded.');\r\n slowWarningThrown = true;\r\n }\r\n }\r\n }).catch(() => {\r\n // Do nothing\r\n });\r\n\r\n return p;\r\n}\r\n","import { isMobile } from '@common-util/device-helper';\r\nimport { scaleImagePreserveAspect } from '@common-util/texture-util';\r\nimport { FileTextureLayer } from '@models/classes';\r\nimport { Kb3dService } from '@models/classes/decorators/service-decorator';\r\nimport { eMaterialLocation, eTextureChannel } from '@models/classes/enums';\r\nimport { IAdvancedMaterialNode, IFilter, IMaterial, ISearchArgs, ITextureLayer } from '@models/classes/kb3d-models';\r\nimport { AdvancedMaterialNode } from '@models/classes/materials/advanced-material-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { isAbsoluteUrl } from '@models/classes/utilities';\r\nimport { LOCAL_ENVIRONMENT_DOMAIN } from '@models/constants';\r\nimport { BehaviorSubject, Observable, Subject, combineLatest, from, of } from 'rxjs';\r\nimport { map, shareReplay, switchMap, take } from 'rxjs/operators';\r\nimport { ABORTED, HttpService, IBinaryResponse } from './http-service';\r\nimport { attachLoadingTimer } from './loading-timer-helper';\r\n\r\nconst LIBRARY_PATH = '%LIBRARY%';\r\n\r\n// If this is a raster image, we store the bitmap. If this is an SVG, then we store the blob so it can be resized efficiently\r\nconst textureCache = new Map>();\r\nconst materialCache = new Map>();\r\n\r\nexport interface IMaterialService {\r\n getMaterialById: (id: string) => Observable;\r\n getMaterialLibraryCategories: () => IMaterialCategory[];\r\n getMaterialLibraryOptions: (category: string) => IMaterial[];\r\n getTexturePath: (node: FileTextureLayer, detailLevel?: number) => string;\r\n getTextureImage: (node: FileTextureLayer) => Observable<{ bitmap: ImageBitmap; url: string }>;\r\n getLibraryTexturePath: (path: string, quality?: number) => string;\r\n}\r\n\r\nexport interface IMaterialCategory {\r\n id: string;\r\n label: string;\r\n}\r\n\r\nconst TEXTURE_SIZES = [128, 256, 512, 1024, 2048, null];\r\nconst LIBRARY_TEXTURE_SIZES = [256, 256, 512, 1024, 2048, 2048];\r\nconst LIBRARY_ENV_SIZES = [128, 256, 512, 1024];\r\nconst LIBRARY_MOBILE_ENV_SIZES = [128, 128, 256, 512];\r\nconst MAX_DETAIL_LEVEL = 5;\r\n\r\n@Kb3dService({\r\n token: Token.MaterialService,\r\n})\r\nexport class MaterialService implements IMaterialService {\r\n public trackedAssetCalls = new Array>();\r\n\r\n materialUpdateChannel = new Map>();\r\n private abortSubjects = new Map>();\r\n textureDetailLevel = MAX_DETAIL_LEVEL;\r\n\r\n constructor(\r\n protected httpService: HttpService,\r\n protected assetRoot?: string,\r\n protected forceFullSizeTextures = false\r\n ) {\r\n if (forceFullSizeTextures) {\r\n this.textureDetailLevel = -1;\r\n } else if (window.screen.width <= 1024 || window.screen.height <= 1024) {\r\n this.textureDetailLevel = 2;\r\n }\r\n }\r\n\r\n public getMaterialLibraryCategories(): IMaterialCategory[] {\r\n const categoryIds = Object.keys(materialDefinitionSet);\r\n\r\n return categoryIds.map(id => ({\r\n id,\r\n label: materialDefinitionSet[id].label,\r\n }));\r\n }\r\n\r\n public getMaterialLibraryOptions(category: string): IMaterial[] {\r\n return LibraryMaterialsByCategory.get(category) || [];\r\n }\r\n\r\n public getMaterialById(guid: string): Observable {\r\n if (materialCache.has(guid)) {\r\n return materialCache.get(guid) as Observable;\r\n } else {\r\n let obs: Observable;\r\n const material = LibraryMaterials.get(guid);\r\n\r\n if (material) {\r\n //it's a library material\r\n obs = of(\r\n material\r\n //asapScheduler\r\n );\r\n } else {\r\n //maybe a global material\r\n obs = from(this.httpService.get(`/api/materials/${guid}`));\r\n }\r\n const updateChannel = new BehaviorSubject(null);\r\n this.materialUpdateChannel.set(guid, updateChannel);\r\n\r\n obs = combineLatest([obs, updateChannel])\r\n .pipe(\r\n map(([material, updatedMaterial]) => {\r\n if (!material) {\r\n return undefined;\r\n }\r\n return { ...material, ...(updatedMaterial || {}) };\r\n })\r\n )\r\n .pipe(shareReplay(1));\r\n\r\n materialCache.set(guid, obs);\r\n return obs;\r\n }\r\n }\r\n\r\n public getTexturePath(node: FileTextureLayer, detailLevel?: number) {\r\n let width: number | null = null;\r\n let height: number | null = null;\r\n if (!node.path) {\r\n return '';\r\n }\r\n\r\n if (detailLevel === undefined) {\r\n detailLevel = this.textureDetailLevel;\r\n }\r\n detailLevel = Math.min(MAX_DETAIL_LEVEL, detailLevel);\r\n\r\n if (node.path.startsWith(LIBRARY_PATH)) {\r\n return this.getLibraryTexturePath(node.path, detailLevel);\r\n } else if (!isAbsoluteUrl(node.path)) {\r\n const url = this.getAbsoluteTexturePath(node.path);\r\n if (detailLevel >= 0) {\r\n width = TEXTURE_SIZES[detailLevel];\r\n }\r\n if (detailLevel >= 0) {\r\n height = TEXTURE_SIZES[detailLevel];\r\n }\r\n\r\n const params: string[] = [];\r\n if (width != null) params.push(`width=${width}`);\r\n if (height != null) params.push(`height=${height}`);\r\n if (params.length > 0) {\r\n return url + '?' + params.join('&');\r\n } else {\r\n return url;\r\n }\r\n } else {\r\n return node.path;\r\n }\r\n }\r\n\r\n public getTextureImage(node: FileTextureLayer, trackAssetCall = true) {\r\n const initialUrl = this.getTexturePath(node, 0);\r\n const url = this.getTexturePath(node);\r\n\r\n let bitmapObs: Observable<{ bitmap: ImageBitmap | Blob; url: string }>;\r\n\r\n if (textureCache.has(url)) {\r\n bitmapObs = textureCache.get(url)!;\r\n } else {\r\n bitmapObs = new Observable<{ bitmap: ImageBitmap | Blob; url: string }>(subject => {\r\n const activeLinkAbort = this.abortSubjects.get(node._dynamicId);\r\n // if there already is an httpService call on this node. Abort the previous one\r\n if (activeLinkAbort) {\r\n activeLinkAbort.next();\r\n }\r\n\r\n const abortTextureLoad = new Subject();\r\n this.abortSubjects.set(node._dynamicId, abortTextureLoad);\r\n\r\n // Textures are absolute so we have to add the cache params before passing to http service\r\n // With this code library textures are always progressively loaded regardless of the scene setting because they do not have a root scene\r\n // revisit this if we want to change this behavior but it is non-trivial to do so\r\n if (this.forceFullSizeTextures || (node._rootScene && !node._rootScene.progressiveTextureLoad)) {\r\n const cacheParamUrl =\r\n this.assetRoot && url.startsWith(this.assetRoot) ? this.httpService.addCacheParams(url) : url;\r\n\r\n attachLoadingTimer(\r\n this.httpService.getBinary(cacheParamUrl, 'blob', false, true, abortTextureLoad)\r\n ).then(\r\n blobResult => {\r\n // clear the abort once the full image is loaded\r\n const activeLinkAbort = this.abortSubjects.get(node._dynamicId);\r\n if (activeLinkAbort) {\r\n activeLinkAbort.complete();\r\n this.abortSubjects.delete(node._dynamicId);\r\n }\r\n\r\n processImageBlob(blobResult).then(result => {\r\n if (result) {\r\n subject.next({ bitmap: result, url: cacheParamUrl });\r\n subject.complete();\r\n }\r\n });\r\n },\r\n err => {\r\n if (err !== ABORTED) {\r\n console.warn(`Could not load texture ${cacheParamUrl}: ` + err.toString());\r\n }\r\n subject.complete();\r\n }\r\n );\r\n } else {\r\n const initialCacheParamUrl =\r\n this.assetRoot && url.startsWith(this.assetRoot)\r\n ? this.httpService.addCacheParams(initialUrl)\r\n : initialUrl;\r\n\r\n const loadStartTime = performance.now();\r\n attachLoadingTimer(\r\n this.httpService.getBinary(initialCacheParamUrl, 'blob', false, true, abortTextureLoad)\r\n ).then(\r\n initialBlobResult => {\r\n processImageBlob(initialBlobResult).then(result => {\r\n const loadTime = performance.now() - loadStartTime;\r\n if (loadTime > 2000) {\r\n console.warn(`Texture ${initialCacheParamUrl} took ${loadTime}ms to load`);\r\n }\r\n if (result) {\r\n subject.next({ bitmap: result, url: initialCacheParamUrl });\r\n }\r\n const cacheParamUrl =\r\n this.assetRoot && url.startsWith(this.assetRoot)\r\n ? this.httpService.addCacheParams(url)\r\n : url;\r\n this.httpService\r\n .defer(() =>\r\n this.httpService.getBinary(cacheParamUrl, 'blob', false, true, abortTextureLoad)\r\n )\r\n .then(\r\n blobResult => {\r\n // clear the abort once the full image is loaded\r\n const activeLinkAbort = this.abortSubjects.get(node._dynamicId);\r\n if (activeLinkAbort) {\r\n activeLinkAbort.complete();\r\n this.abortSubjects.delete(node._dynamicId);\r\n }\r\n\r\n processImageBlob(blobResult).then(result => {\r\n if (result) {\r\n subject.next({ bitmap: result, url: cacheParamUrl });\r\n subject.complete();\r\n }\r\n });\r\n },\r\n err => {\r\n if (err !== ABORTED) {\r\n console.warn(\r\n `Could not load texture ${cacheParamUrl}: ` + err.toString()\r\n );\r\n }\r\n subject.complete();\r\n }\r\n );\r\n });\r\n },\r\n err => {\r\n if (err !== ABORTED) {\r\n console.warn(`Could not load texture ${initialCacheParamUrl}: ` + err.toString());\r\n }\r\n subject.complete();\r\n }\r\n );\r\n }\r\n }).pipe(shareReplay(1));\r\n }\r\n\r\n function processImageBlob(blob: IBinaryResponse): Promise {\r\n if (blob && blob.data) {\r\n if (blob.data.type === 'image/svg+xml') {\r\n return Promise.resolve(blob.data);\r\n } else {\r\n if (blob.data.type.match(/image/)) {\r\n const opts =\r\n blob.width && blob.height\r\n ? {\r\n resizeWidth: blob.width,\r\n resizeHeight: blob.height,\r\n resizeQuality: 'medium' as ResizeQuality,\r\n }\r\n : undefined;\r\n return createImageBitmap(blob.data, opts).then(bitmap => {\r\n return Promise.resolve(bitmap);\r\n });\r\n } else {\r\n console.warn('source file is not an image: ', url);\r\n }\r\n }\r\n }\r\n return Promise.resolve(null);\r\n }\r\n\r\n textureCache.set(url, bitmapObs);\r\n\r\n const obs = bitmapObs.pipe(\r\n switchMap(res => {\r\n /** bitmap is returned as blob for SVGs and imageBitmap for raster images */\r\n if (res.bitmap instanceof Blob) {\r\n const blobToConvert = res.bitmap;\r\n return new Promise<{ bitmap: ImageBitmap; url: string }>((resolve, reject) => {\r\n const imageElement = document.createElement('img');\r\n\r\n const blobUrl = URL.createObjectURL(blobToConvert);\r\n\r\n imageElement.onload = () => {\r\n // Figure out what resolution to actually draw the SVG at to fit within the envelope\r\n const scaled = scaleImagePreserveAspect(\r\n node.width,\r\n node.height,\r\n imageElement.naturalWidth,\r\n imageElement.naturalHeight\r\n );\r\n\r\n createImageBitmap(imageElement, {\r\n resizeWidth: scaled.drawWidth,\r\n resizeHeight: scaled.drawHeight,\r\n }).then(bitmap => {\r\n resolve({ bitmap: bitmap, url: res.url });\r\n });\r\n };\r\n imageElement.onerror = e => {\r\n reject(e);\r\n };\r\n imageElement.src = blobUrl;\r\n });\r\n } else {\r\n return of({ bitmap: res.bitmap, url: res.url });\r\n }\r\n })\r\n );\r\n\r\n if (trackAssetCall) {\r\n this.trackAssetCall(obs.pipe(take(1)).toPromise());\r\n }\r\n\r\n return obs;\r\n }\r\n\r\n public getLibraryTexturePath(relativePath: string, quality = 0) {\r\n const path = relativePath.substring(LIBRARY_PATH.length);\r\n let res: number;\r\n if (quality < 0) {\r\n res = LIBRARY_TEXTURE_SIZES[LIBRARY_TEXTURE_SIZES.length - 1];\r\n } else {\r\n res = LIBRARY_TEXTURE_SIZES[quality];\r\n }\r\n return `${this.assetRoot}/assets/textures/${path}_${res}.jpg`;\r\n }\r\n\r\n public getAbsoluteTexturePath(relativePath: string) {\r\n return `${this.assetRoot}/media/${relativePath}`; //it's a relative path to the media folder\r\n }\r\n\r\n public getAbsoluteEnvironmentPath(path: string, quality: 0 | 1 | 2 | 3) {\r\n if (path) {\r\n let url: string;\r\n if (path.startsWith(LOCAL_ENVIRONMENT_DOMAIN)) {\r\n const res = isMobile() ? LIBRARY_MOBILE_ENV_SIZES[quality] : LIBRARY_ENV_SIZES[quality];\r\n\r\n url = `${this.assetRoot}/assets/environments/${path.replace(LOCAL_ENVIRONMENT_DOMAIN, '')}_${res}.env`;\r\n } else {\r\n url = this.getAbsoluteTexturePath(path);\r\n }\r\n return this.httpService.addCacheParams(url);\r\n }\r\n return '';\r\n }\r\n\r\n public searchMaterialByName(name: string, loadArchivedMaterials: boolean) {\r\n const archivedFilter = { type: 'property', property: 'archived', values: [false] } as IFilter;\r\n const searchArgs = { query: name + '*', sortField: 'Name', filters: [], descending: false } as ISearchArgs;\r\n if (!loadArchivedMaterials) {\r\n searchArgs.filters?.push(archivedFilter);\r\n }\r\n let result = null;\r\n if (name) {\r\n result = this.httpService.post('/api/materials/search', searchArgs);\r\n }\r\n return result;\r\n }\r\n\r\n public getMaterialNameList() {\r\n const archivedFilter = { type: 'property', property: 'archived', values: [false] } as IFilter;\r\n const searchArgs = { fields: ['Guid', 'Name'], take: 10000, filters: [archivedFilter] } as ISearchArgs;\r\n return this.httpService.post('/api/materials/search', searchArgs);\r\n }\r\n\r\n protected setMaterialCache(guid: string, mat: IMaterial) {\r\n materialCache.set(guid, of(mat));\r\n }\r\n\r\n protected trackAssetCall(p: Promise) {\r\n const trackedPromise = p.finally(() => {\r\n this.trackedAssetCalls.remove(trackedPromise);\r\n });\r\n this.trackedAssetCalls.push(trackedPromise);\r\n }\r\n}\r\n\r\nexport interface IEnvironmentInfo {\r\n name: string;\r\n label: string;\r\n path: string;\r\n previewUrl: string;\r\n}\r\n\r\nexport const LibraryMaterials = new Map();\r\nexport const LibraryMaterialsByCategory = new Map();\r\nexport const LibraryEnvironments = new Array();\r\nexport const LibraryEnvironmentsMap = new Map();\r\n\r\nfunction makeLibraryMaterial(tag: string, index: number) {\r\n //pad the index string with zeros\r\n let indexStr = index + '';\r\n while (indexStr.length < 2) indexStr = '0' + indexStr;\r\n const iname = tag + indexStr;\r\n const baseUrl = `${tag}/${iname}`;\r\n\r\n return {\r\n id: -1,\r\n name: iname,\r\n guid: iname,\r\n tags: [{ name: tag }],\r\n data: {\r\n $type: Token.AdvancedMaterialNode.key,\r\n name: iname,\r\n id: iname,\r\n location: eMaterialLocation.library,\r\n textures: [\r\n {\r\n $type: 'FileTextureLayer',\r\n channel: eTextureChannel.ambientOcclusion,\r\n path: `${LIBRARY_PATH}${baseUrl}_ao`,\r\n } as ITextureLayer,\r\n {\r\n $type: 'FileTextureLayer',\r\n channel: eTextureChannel.albedo,\r\n path: `${LIBRARY_PATH}${baseUrl}_col`,\r\n } as ITextureLayer,\r\n {\r\n $type: 'FileTextureLayer',\r\n channel: eTextureChannel.metallic,\r\n path: `${LIBRARY_PATH}${baseUrl}_met`,\r\n } as ITextureLayer,\r\n {\r\n $type: 'FileTextureLayer',\r\n channel: eTextureChannel.normal,\r\n path: `${LIBRARY_PATH}${baseUrl}_nrm`,\r\n } as ITextureLayer,\r\n {\r\n $type: 'FileTextureLayer',\r\n channel: eTextureChannel.roughness,\r\n path: `${LIBRARY_PATH}${baseUrl}_rgh`,\r\n } as ITextureLayer,\r\n //{ $type: \"FileTextureLayer\", channel: eTextureChannel.displacement, path: `${LIBRARY_PATH}${baseUrl}_disp` },\r\n ],\r\n },\r\n };\r\n}\r\n\r\ninterface IMaterialDefinitionSet {\r\n [tagName: string]: {\r\n label: string;\r\n count: number;\r\n omit?: Partial<{\r\n //the textures to omit for\r\n [T in eTextureChannel]: boolean | number[];\r\n }>;\r\n props?: Partial & { [key: string]: any };\r\n };\r\n}\r\n\r\nfunction fillLibraryMaterialsMap() {\r\n for (const tag in materialDefinitionSet) {\r\n const entry = materialDefinitionSet[tag];\r\n for (let index = 1; index <= entry.count; index++) {\r\n const mat = makeLibraryMaterial(tag, index);\r\n const matData = mat.data as AdvancedMaterialNode;\r\n matData.roughness = 1;\r\n matData.metallic = 0;\r\n\r\n if (entry.omit) {\r\n const omit = entry.omit;\r\n matData.textures = matData.textures.filter(t => {\r\n if (omit[t.channel]) {\r\n if (omit[t.channel] === true) {\r\n return false;\r\n }\r\n if (Array.isArray(omit[t.channel]) && (omit[t.channel] as number[]).some(i => i === index)) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n });\r\n }\r\n // Metallic is multiplied against the texture, so if the material has a metallic texture then set metallic to 1.\r\n if (matData.textures.findIndex(t => t.channel === eTextureChannel.metallic) > -1) {\r\n matData.metallic = 1;\r\n }\r\n\r\n if (entry.props) {\r\n for (const p in entry.props) {\r\n (mat.data as any)[p] = entry.props[p];\r\n }\r\n }\r\n LibraryMaterials.set(mat.guid as string, mat);\r\n\r\n let categoryList = LibraryMaterialsByCategory.get(tag);\r\n if (!categoryList) {\r\n categoryList = [];\r\n }\r\n categoryList.push(mat);\r\n LibraryMaterialsByCategory.set(tag, categoryList);\r\n }\r\n }\r\n}\r\n\r\nconst materialDefinitionSet: IMaterialDefinitionSet = {\r\n asphalt: {\r\n label: 'Asphalt',\r\n count: 15,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 9, 10, 11, 12, 13, 14, 15],\r\n },\r\n },\r\n bark: {\r\n label: 'Bark',\r\n count: 6,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1],\r\n },\r\n },\r\n bricks: {\r\n label: 'Bricks',\r\n count: 17,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 3, 4],\r\n },\r\n },\r\n chipboard: {\r\n label: 'Chipboard',\r\n count: 3,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n },\r\n },\r\n concrete: {\r\n label: 'Concrete',\r\n count: 17,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 12, 14, 15, 16, 17],\r\n [eTextureChannel.roughness]: [1],\r\n },\r\n },\r\n corrugatedsteel: {\r\n label: 'Corrugated Steel',\r\n count: 5,\r\n },\r\n diamondplate: {\r\n label: 'Diamond Plate',\r\n count: 4,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n [eTextureChannel.albedo]: [4],\r\n },\r\n },\r\n fabric: {\r\n label: 'Fabric',\r\n count: 29,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n [eTextureChannel.metallic]: true,\r\n },\r\n },\r\n gravel: {\r\n label: 'Gravel',\r\n count: 8,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2],\r\n },\r\n },\r\n ground: {\r\n label: 'Ground',\r\n count: 28,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 3, 17],\r\n },\r\n },\r\n ice: {\r\n label: 'Ice',\r\n count: 4,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n leather: {\r\n label: 'Leather',\r\n count: 14,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14],\r\n },\r\n },\r\n marble: {\r\n label: 'Marble',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n metal: {\r\n label: 'Metal',\r\n count: 27,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n metalplates: {\r\n label: 'Metal Plate',\r\n count: 3,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n paint: {\r\n label: 'Paint',\r\n count: 6,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n },\r\n },\r\n paintedmetal: {\r\n label: 'Painted Metal',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n paintedplaster: {\r\n label: 'Painted Plaster',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n [eTextureChannel.metallic]: true,\r\n },\r\n },\r\n pavingstones: {\r\n label: 'Paving Stones',\r\n count: 41,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 3, 4],\r\n },\r\n },\r\n pipe: {\r\n label: 'Pipe',\r\n count: 4,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n planks: {\r\n label: 'Planks',\r\n count: 9,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: [1, 2],\r\n },\r\n },\r\n plastic: {\r\n label: 'Plastic',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n rock: {\r\n label: 'Rock',\r\n count: 14,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 6, 7, 8, 9],\r\n [eTextureChannel.albedo]: [4],\r\n },\r\n },\r\n rocks: {\r\n label: 'Rocks',\r\n count: 6,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n },\r\n },\r\n roofingtiles: {\r\n label: 'Roofing Tiles',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n rust: {\r\n label: 'Rust',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n },\r\n },\r\n scratches: {\r\n label: 'Scratches',\r\n count: 5,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.albedo]: true,\r\n },\r\n },\r\n terrazzo: {\r\n label: 'Terrazzo',\r\n count: 8,\r\n omit: {\r\n [eTextureChannel.ambientOcclusion]: true,\r\n [eTextureChannel.metallic]: true,\r\n },\r\n },\r\n tiles: {\r\n label: 'Tiles',\r\n count: 37,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [\r\n 1, 2, 3, 4, 5, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 29, 30, 31, 32, 33, 34, 35, 36, 37,\r\n ],\r\n },\r\n },\r\n wood: {\r\n label: 'Wood',\r\n count: 20,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20],\r\n },\r\n },\r\n woodfloor: {\r\n label: 'Wood Floor',\r\n count: 28,\r\n omit: {\r\n [eTextureChannel.metallic]: true,\r\n [eTextureChannel.ambientOcclusion]: [1, 2, 4, 5, 6, 8],\r\n },\r\n },\r\n woodsiding: {\r\n label: 'Wood Siding',\r\n count: 8,\r\n omit: {\r\n [eTextureChannel.metallic]: [5, 6, 7],\r\n },\r\n },\r\n};\r\n\r\nfillLibraryMaterialsMap();\r\n\r\n/** create library environments */\r\nfor (const env of [\r\n // \"country\",\r\n // \"environment\",\r\n // \"forest\",\r\n // \"night\",\r\n // \"parking\",\r\n // \"room\",\r\n\r\n 'adams_place_bridge',\r\n 'aerodynamics_workshop',\r\n 'autoshop',\r\n 'ballroom',\r\n 'boiler_room',\r\n 'cape_hill',\r\n 'colorful_studio',\r\n 'fireplace',\r\n 'greenwich_park',\r\n 'hospital_room',\r\n 'industrial_pipe_and_valve',\r\n 'leadenhall_market',\r\n 'machine_shop',\r\n 'modern_buildings_night',\r\n 'museum_of_ethnography',\r\n 'mutianyu',\r\n 'old_bus_depot',\r\n 'photo_studio',\r\n 'preller_drive',\r\n 'red_wall',\r\n 'rooitou_park',\r\n 'royal_esplanade',\r\n 'schadowplatz',\r\n 'small_cathedral',\r\n 'spruit_sunrise',\r\n 'studio_small',\r\n 'surgery',\r\n 'venice_sunset',\r\n 'winter_evening',\r\n 'wooden_lounge',\r\n]) {\r\n const label = env\r\n .split('_')\r\n .map(s => s.capitalize())\r\n .join(' ');\r\n const o = {\r\n name: env,\r\n label,\r\n path: `${LOCAL_ENVIRONMENT_DOMAIN}${env}`,\r\n previewUrl: `environments/${env}.jpg`,\r\n } as IEnvironmentInfo;\r\n LibraryEnvironments.push(o);\r\n LibraryEnvironmentsMap.set(o.path, o);\r\n}\r\n","export const MOBILE_WIDTH = 847;\r\n\r\nexport function isMobile() {\r\n return window != null && window.innerWidth < MOBILE_WIDTH;\r\n}\r\n","import { KbGeometry } from '@models/classes';\r\nimport { Token } from '@models/classes/token';\r\nimport { MeshNode } from '../classes/meshes/mesh-node';\r\nimport { isCustomMeshNode } from '../classes/meshes/mesh-utilities';\r\nimport { HttpService } from './http-service';\r\nimport { attachLoadingTimer } from './loading-timer-helper';\r\n\r\nconst geometryCache = new Map>();\r\n\r\nexport class MeshService {\r\n constructor(private httpService: HttpService, private assetRoot?: string) {}\r\n /**\r\n * Loads the geometry for a mesh node and adds it to the node, mutating the node object.\r\n * @param meshNode Mesh node to load geometry for\r\n */\r\n public hydrateGeometry(meshNode: T): Promise {\r\n if (!isCustomMeshNode(meshNode) || !meshNode.geometryId) {\r\n return Promise.resolve(meshNode);\r\n } else {\r\n let request = geometryCache.get(meshNode.geometryId);\r\n let shared = false;\r\n\r\n if (!request) {\r\n request = attachLoadingTimer(\r\n this.httpService.getBinary(`${this.assetRoot}/meshes/${meshNode.geometryId}`, 'arraybuffer', true)\r\n ).then(\r\n response => {\r\n if (response && response.data) {\r\n const geometry = meshNode._manager!.create(Token.KbGeometry);\r\n geometry.extractFromBinary(response.data, meshNode);\r\n return geometry;\r\n }\r\n return Promise.reject();\r\n },\r\n err => {\r\n console.error(`Geometry for \"${meshNode.name}\" could not be loaded`, err);\r\n return null;\r\n }\r\n );\r\n geometryCache.set(meshNode.geometryId, request);\r\n } else {\r\n shared = true;\r\n }\r\n\r\n return request.then(geometry => {\r\n if (geometry) {\r\n if (shared) {\r\n geometry.shared = true;\r\n }\r\n\r\n meshNode._geometry = geometry;\r\n }\r\n return meshNode;\r\n });\r\n }\r\n }\r\n}\r\n","import { BaseKb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOfAny } from '../decorators/model-utils';\r\nimport { ILightNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { SpaceNode } from '../meshes';\r\nimport { KbColor } from '../primitives/kb-color';\r\nimport { Token } from '../token';\r\n\r\n@BaseKb3dModel({\r\n token: Token.LightNode,\r\n})\r\nexport abstract class LightNode extends SpaceNode implements ILightNode {\r\n constructor() {\r\n super();\r\n }\r\n public visible: boolean;\r\n public intensity: number;\r\n public color: KbColor;\r\n\r\n getSpaceChildren() {\r\n return [];\r\n }\r\n}\r\n\r\nexport function isLightNode(node: Kb3dObject): node is LightNode {\r\n return instanceOfAny(node, ...Token.LightTokens);\r\n}\r\n","import { SketchControlPoint } from '.';\r\nimport { AnnotationNode } from './annotations';\r\nimport { IgnoreChanges } from './decorators/change-tracker';\r\nimport { Enumerable } from './decorators/enumerable';\r\nimport { Kb3dModel } from './decorators/kb3d-decorator';\r\nimport { instanceOf } from './decorators/model-utils';\r\nimport { eAxis, eBackground, eLoadingExperience, eRenderMode, eTextureSamplingMode } from './enums';\r\nimport { Connector } from './features/connector';\r\nimport { IImportInfo, ISceneNode } from './kb3d-models';\r\nimport { Kb3dObject } from './kb3d-object';\r\nimport { LightNode } from './lights';\r\nimport { MaterialNode } from './materials/material-node';\r\nimport { MateNode } from './mates/mate-node';\r\nimport { MeshGroupNode } from './meshes/mesh-group-node';\r\nimport { SpaceNode } from './meshes/space-node';\r\nimport { KbColor } from './primitives';\r\nimport { Token } from './token';\r\nimport { ViewpointNode } from './viewpoints/viewpoint-node';\r\n\r\n@Kb3dModel({\r\n token: Token.SceneNode,\r\n})\r\nexport class SceneNode extends MeshGroupNode implements ISceneNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n public nestedId: string;\r\n public background: eBackground;\r\n public environment: string;\r\n public environmentBlur: number;\r\n public environmentIntensity: number;\r\n public backgroundColor: KbColor;\r\n public ambientColor: KbColor;\r\n public renderMode: eRenderMode;\r\n public edgeColor: KbColor;\r\n public edgeWidth: number;\r\n public edgeDisplayTolerance: number;\r\n public viewpointId?: string;\r\n public frameViewpoint: boolean;\r\n public progressiveTextureLoad: boolean;\r\n public enableHoverEffects: boolean;\r\n public enableSceneOptimization: boolean;\r\n public enableDeferredSceneUpdates: boolean;\r\n public enableGrid?: boolean;\r\n public enableGridAxes?: boolean;\r\n public gridMajorInterval?: number;\r\n public gridNormal: eAxis;\r\n public gridSize?: number;\r\n public gridStepSize?: number;\r\n public connectorSize?: number;\r\n public arEnabled?: boolean;\r\n public fullscreenEnabled?: boolean;\r\n public xrAllowScaling: boolean;\r\n public unitsPerMeter: number;\r\n public xrAddShadow: boolean;\r\n public xrLightingEstimation: boolean;\r\n public enableFxaaPostProcess?: boolean;\r\n public enableLensEffectsPostProcess?: boolean;\r\n public enableSSAOPostProcess?: boolean;\r\n public environmentRotation: number;\r\n public dimensionUnitScalar?: number;\r\n public dimensionUnitSymbol?: string;\r\n public loadingExperience: eLoadingExperience;\r\n public loadingImagePath: string;\r\n public textureSamplingMode: eTextureSamplingMode;\r\n\r\n public _forceGrid = false;\r\n\r\n /** override base parent for more specific typing*/\r\n public _parent: SceneNode | undefined;\r\n\r\n @IgnoreChanges\r\n public conversionMap?: Record;\r\n\r\n @IgnoreChanges\r\n public _configurator: any; //filled in by kbmax for easy retrieval of the associated configurator\r\n\r\n private _materials: MaterialNode[];\r\n @Enumerable()\r\n public get materials(): MaterialNode[] {\r\n if (!this._materials) this._materials = [];\r\n return this._materials;\r\n }\r\n public set materials(val) {\r\n this._materials = val;\r\n }\r\n\r\n private _lights: LightNode[];\r\n @Enumerable()\r\n public get lights(): LightNode[] {\r\n if (!this._lights) this._lights = [];\r\n return this._lights;\r\n }\r\n public set lights(val) {\r\n this._lights = val;\r\n }\r\n\r\n private _viewpoints: ViewpointNode[];\r\n @Enumerable()\r\n public get viewpoints(): ViewpointNode[] {\r\n if (!this._viewpoints) this._viewpoints = [];\r\n return this._viewpoints;\r\n }\r\n public set viewpoints(val) {\r\n this._viewpoints = val;\r\n }\r\n\r\n private _scenes: SceneNode[];\r\n @Enumerable()\r\n public get scenes(): SceneNode[] {\r\n if (!this._scenes) this._scenes = [];\r\n return this._scenes;\r\n }\r\n public set scenes(val) {\r\n this._scenes = val;\r\n }\r\n\r\n private _mates: MateNode[];\r\n @Enumerable()\r\n public get mates(): MateNode[] {\r\n if (!this._mates) this._mates = [];\r\n return this._mates;\r\n }\r\n public set mates(val) {\r\n this._mates = val;\r\n }\r\n\r\n private _annotations: AnnotationNode[];\r\n @Enumerable()\r\n public get annotations(): AnnotationNode[] {\r\n if (!this._annotations) this._annotations = [];\r\n return this._annotations;\r\n }\r\n public set annotations(val) {\r\n this._annotations = val;\r\n }\r\n\r\n private _importHistory: IImportInfo[];\r\n @Enumerable()\r\n public get importHistory(): IImportInfo[] {\r\n if (!this._importHistory) this._importHistory = [];\r\n return this._importHistory;\r\n }\r\n public set importHistory(val) {\r\n this._importHistory = val;\r\n }\r\n\r\n private _exportHistory: IImportInfo[];\r\n @Enumerable()\r\n public get exportHistory(): IImportInfo[] {\r\n if (!this._exportHistory) this._exportHistory = [];\r\n return this._importHistory;\r\n }\r\n public set exportHistory(val) {\r\n this._exportHistory = val;\r\n }\r\n\r\n public getChildren() {\r\n return [\r\n ...this.meshes,\r\n ...this.materials,\r\n ...this.lights,\r\n ...this.viewpoints,\r\n ...this.mates,\r\n ...this.connectors,\r\n ...this.annotations,\r\n ];\r\n }\r\n\r\n public getChildArrayForType(token: Token): Kb3dObject[] {\r\n if (token.isMeshOrGroup() || token.isLight()) {\r\n return this.meshes;\r\n } else if (token.isMaterial()) {\r\n return this.materials;\r\n } else if (token.isViewpoint()) {\r\n return this.viewpoints;\r\n } else if (token.isMate()) {\r\n return this.mates;\r\n } else if (token.isConnector()) {\r\n return this.connectors;\r\n } else if (token.isAnnotation()) {\r\n return this.annotations;\r\n } else {\r\n throw 'unexpected token';\r\n }\r\n }\r\n\r\n public getChildArray(node: Kb3dObject) {\r\n if (Token.withKey(node.$type).isLight()) {\r\n // Lights can be defined as meshes but can be in the light array as well, so we have to check there\r\n if (this.lights.contains(node as LightNode)) {\r\n return this.lights;\r\n }\r\n }\r\n return super.getChildArray(node);\r\n }\r\n\r\n public isNested() {\r\n return this._parent != null;\r\n }\r\n\r\n public runOnAllScenes(action: (sceneNode: SceneNode) => void) {\r\n action(this);\r\n for (const nested of this.scenes) {\r\n nested.runOnAllScenes(action);\r\n }\r\n }\r\n\r\n public getSpaceChildren(): SpaceNode[] {\r\n return this.meshes.concat(this.scenes);\r\n }\r\n\r\n public getNestedPathTo(node: Kb3dObject) {\r\n let path = node.id;\r\n let parent = node._parentScene;\r\n let isPath = false;\r\n while (parent) {\r\n if (parent === this) break;\r\n path = parent.nestedId + '/' + path;\r\n isPath = true;\r\n parent = parent._parent;\r\n }\r\n return `${isPath ? '@' : ''}${path}`;\r\n }\r\n\r\n public getAllConnectors() {\r\n const connectors = new Array();\r\n this.runOnAllScenes(s => {\r\n connectors.push(...s._manager!.getByToken(Token.Connector).filter(c => c.enabled));\r\n });\r\n return connectors;\r\n }\r\n\r\n public getAllSketchControlPoints() {\r\n const points = new Array();\r\n this.runOnAllScenes(s => {\r\n points.push(...s._manager!.getByToken(Token.SketchControlPoint).filter(c => c.enabled));\r\n });\r\n return points;\r\n }\r\n}\r\n\r\nexport function isSceneNode(node: Kb3dObject): node is SceneNode {\r\n return instanceOf(node, Token.SceneNode);\r\n}\r\n","import { isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { FontService } from '@models/services/font-service';\r\nimport { HttpService, IHttpEnvironment } from '@models/services/http-service';\r\nimport { MaterialService } from '@models/services/material-service';\r\nimport { MeshService } from '@models/services/mesh-service';\r\nimport { getConstructorParamsForModel } from './decorators/inject-decorator';\r\nimport { IDecoratedModel } from './decorators/kb3d-decorator';\r\nimport { Constructor, IKb3dModel, Kb3dModels, instanceOf, instanceOfAny } from './decorators/model-utils';\r\nimport { defaults } from './default-values';\r\nimport {\r\n HandlerMap,\r\n IDraggable,\r\n Kb3dBoundingBoxChangeHandler,\r\n Kb3dPointerHandler,\r\n SetMap,\r\n TagArrayMap,\r\n} from './handlers';\r\nimport { IKb3dObject, ISceneInfo } from './kb3d-models';\r\nimport { Kb3dObject } from './kb3d-object';\r\nimport { LightNode, isLightNode } from './lights/light-node';\r\nimport { MaterialNode, isMaterialNode } from './materials/material-node';\r\nimport { MeshGroupNode } from './meshes/mesh-group-node';\r\nimport { isMeshNode } from './meshes/mesh-utilities';\r\nimport { SpaceNode } from './meshes/space-node';\r\nimport { SceneNode } from './scene-node';\r\nimport { Token } from './token';\r\nimport { isGuid, isObject } from './utilities';\r\n\r\nconst SET_TYPE = '__set';\r\n\r\n/** contains all kb3dobjects keyed by their dynamic Id, to fetch nodes from the 3d engine ID */\r\nconst dynamicDb: Map = new Map();\r\n\r\nexport function getByDynamicId(dynamicId: string, throwOnNotFound: true): T;\r\nexport function getByDynamicId(dynamicId: string, throwOnNotFound?: boolean): T | undefined;\r\nexport function getByDynamicId(dynamicId: string, throwOnNotFound = false): T | undefined {\r\n if (throwOnNotFound && !dynamicDb.has(dynamicId)) {\r\n throw `kb3d object with id ${dynamicId} not found`;\r\n }\r\n return dynamicDb.get(dynamicId) as T | undefined;\r\n}\r\n\r\nexport interface ISerializeOptions {\r\n /** whether to include children in the serialization. Defaults to true */\r\n includeChildNodes?: boolean;\r\n /** whether to omit properties that are the same as the default value of that property. Defaults to true */\r\n omitDefaultValues?: boolean;\r\n /** internal use */\r\n isRoot?: boolean;\r\n}\r\n\r\nexport interface IJsonSerializeOptions extends ISerializeOptions {\r\n prettyPrint?: boolean;\r\n}\r\n\r\nexport interface IDeserializeOptions {\r\n /** whether to create children while deserializing. Defaults to true */\r\n includeChildNodes?: boolean;\r\n /** when deserializing, set to true to issue new id's to all the kb3dobjects. Defaults to false */\r\n issueNewIds?: boolean;\r\n /** when copying properties from one node to another, we don't want to copy certain properties */\r\n copyingToDifferentNode?: boolean;\r\n}\r\n\r\nexport enum ImportOperation {\r\n ignore,\r\n add,\r\n replace,\r\n}\r\n\r\nexport interface IImportPreview {\r\n type: Token;\r\n node: Partial;\r\n namePath: string;\r\n matchingNode: Kb3dObject;\r\n operation: ImportOperation;\r\n children: IImportPreview[];\r\n parent?: IImportPreview;\r\n}\r\n\r\nexport interface IKb3dManagerOptions {\r\n services?: Map;\r\n /** the root domain that holds assets like meshes and textures. Leave empty to call for them on the host server */\r\n assetRoot?: string;\r\n forceFullSizeTextures?: boolean;\r\n environment?: IHttpEnvironment;\r\n}\r\n\r\nexport class Kb3dManager {\r\n services: Map;\r\n isDevEnvironment = true;\r\n\r\n constructor(options?: IKb3dManagerOptions) {\r\n //if no services are provided, then use the default services\r\n if (options && options.services) {\r\n this.services = options.services;\r\n } else {\r\n const httpService = new HttpService(options?.environment);\r\n if (options?.environment && options.environment.lastDeploy) {\r\n this.isDevEnvironment = false;\r\n }\r\n this.services = new Map([\r\n [Token.HttpService, httpService],\r\n [\r\n Token.MaterialService,\r\n new MaterialService(httpService, options?.assetRoot, options?.forceFullSizeTextures),\r\n ],\r\n [Token.MeshService, new MeshService(httpService, options?.assetRoot)],\r\n [Token.FontService, new FontService(httpService, options?.assetRoot)],\r\n ]);\r\n }\r\n }\r\n\r\n /** contains all kb3dobjects */\r\n private _db = new Map();\r\n /** contains all objects keyed by their token */\r\n private _tokenDb = new SetMap();\r\n /** contains all nodes (but not other kinds of objects) */\r\n private _nodeDb = new Map();\r\n /** holds a cache of name searches that have been performed with their results */\r\n private _nameSearchCache = new Map();\r\n /** contains nested scenes keyed by their nestedId */\r\n private _nestedSceneDb = new Map();\r\n\r\n /** holds a cache of click handlers that have been added to nodes in the context of this manager */\r\n public readonly clickHandlers = new HandlerMap(this);\r\n public readonly doubleClickHandlers = new HandlerMap(this);\r\n public readonly draggables = new HandlerMap(this);\r\n public readonly hotspotClickHandlers = new TagArrayMap void>();\r\n public readonly boundingboxChangeHandlers = new HandlerMap(this);\r\n\r\n public getService(serviceToken: Token): TService {\r\n return this.services.get(serviceToken);\r\n }\r\n\r\n public dispose() {\r\n /**only clear items out of the dynamic db that were part of this manager (as it is static and holds dynamic ids for all managers) */\r\n for (const [, value] of this._db) {\r\n dynamicDb.delete(value._dynamicId);\r\n }\r\n this._db.clear();\r\n this._nodeDb.clear();\r\n this.clickHandlers.clear();\r\n this.doubleClickHandlers.clear();\r\n this.draggables.clear();\r\n this.hotspotClickHandlers.clear();\r\n this.boundingboxChangeHandlers.clear();\r\n this._nameSearchCache.clear();\r\n this._tokenDb.clear();\r\n this._nestedSceneDb.clear();\r\n }\r\n\r\n /**\r\n * Accepts either a node id or a name to search for nodes. If using\r\n * node name wildcards * are allowed. The action provided will be run\r\n * on each of the matching nodes, with the args passed in to that action.\r\n * @param idOrName\r\n * @param action\r\n * @param args\r\n * @param useCache\r\n */\r\n public runOnNodes(\r\n idOrName: string,\r\n action: (node: T, args?: TArgs) => void,\r\n args?: TArgs,\r\n useCache = true\r\n ) {\r\n if (isGuid(idOrName)) {\r\n const node = this.getById(idOrName);\r\n if (node) action(node, args);\r\n } else {\r\n const nodes = this.getNodesByName(idOrName, useCache);\r\n for (const node of nodes) {\r\n action(node as T, args);\r\n }\r\n }\r\n }\r\n // @child1/xxxxx-xxxxxx-xxxx\r\n public getById(id: string): T | undefined {\r\n if (id && id.startsWith('@')) {\r\n //it's a nested path id\r\n const segments = id.split('/');\r\n const nestedId = segments.shift()!.substring(1).toLowerCase();\r\n const nestedScene = this._nestedSceneDb.get(nestedId);\r\n if (nestedScene) {\r\n let subId = segments.join('/');\r\n if (segments.length > 1) subId = '@' + subId;\r\n return nestedScene._manager!.getNodeByIdOrName(subId);\r\n }\r\n } else {\r\n return this._db.get(id) as T | undefined;\r\n }\r\n }\r\n\r\n public getAll() {\r\n return [...this._db.values()];\r\n }\r\n\r\n public getAllNodes() {\r\n return [...this._nodeDb.values()];\r\n }\r\n\r\n /**\r\n * Accepts either a node id or a name to search for nodes. Only returns the first\r\n * matching node. If using node name wildcards * are allowed.\r\n * @param idOrName\r\n * @param useCache\r\n */\r\n public getNodeByIdOrName(idOrName: string | T, useCache = true): T | undefined {\r\n if (typeof idOrName == 'string') {\r\n if (isGuid(idOrName) || idOrName.startsWith('@')) {\r\n return this.getById(idOrName);\r\n } else {\r\n return this.getFirstNodeByName(idOrName, useCache) as any as T;\r\n }\r\n } else if (idOrName instanceof Kb3dObject) {\r\n return idOrName;\r\n }\r\n }\r\n\r\n /**\r\n * Accepts either a node id or a name to search for nodes. If using\r\n * node name wildcards * are allowed.\r\n * @param idOrName\r\n * @param useCache\r\n */\r\n public getNodesByIdOrName(idOrName: string | T, useCache = true): T[] {\r\n const res = [];\r\n\r\n if (typeof idOrName == 'string') {\r\n if (isGuid(idOrName)) {\r\n const n = this.getById(idOrName);\r\n if (n) res.push(n);\r\n } else {\r\n res.push(...this.getNodesByName(idOrName, useCache));\r\n }\r\n } else if (idOrName instanceof Kb3dObject) {\r\n res.push(idOrName);\r\n }\r\n return res as T[];\r\n }\r\n\r\n /**\r\n * Get's the first node that matches the name given. Wildcards * are allowed.\r\n * @param name\r\n * @param useCache\r\n */\r\n public getFirstNodeByName(name: string, useCache = true) {\r\n const nodes = this.getNodesByName(name, useCache);\r\n if (nodes && nodes.length) {\r\n return nodes[0];\r\n }\r\n }\r\n\r\n /**\r\n * Returns a list of nodes that match the name given.\r\n * Wildcards * are allowed.\r\n * Results will be fed from a search cache if useCache is true\r\n * @param name\r\n * @param useCache\r\n */\r\n public getNodesByName(name: string, useCache = true): T[] {\r\n if (useCache && this._nameSearchCache.has(name)) {\r\n return this._nameSearchCache.get(name) as T[];\r\n }\r\n\r\n const results = new Array();\r\n const re = this.getWildcardRegex(name);\r\n\r\n for (const [, node] of this._db) {\r\n if (re.test(node.name)) {\r\n results.push(node as T);\r\n }\r\n }\r\n\r\n this._nameSearchCache.set(name, results);\r\n\r\n return results;\r\n }\r\n\r\n public getNodesContainingName(name: string, useCache = true): T[] {\r\n if (useCache && this._nameSearchCache.has(name)) {\r\n return this._nameSearchCache.get(name) as T[];\r\n }\r\n\r\n const results = new Array();\r\n const re = this.getWildcardRegex(name);\r\n\r\n for (const [, node] of this._db) {\r\n if (re.test(node.name)) {\r\n results.push(node as T);\r\n }\r\n }\r\n\r\n this._nameSearchCache.set(name, results);\r\n\r\n return results;\r\n }\r\n\r\n public getByToken(token: Token) {\r\n return [...this._tokenDb.get(token).values()] as T[];\r\n }\r\n\r\n public getByTokens(...tokens: Token[]) {\r\n return tokens.flatMap(t => [...this._tokenDb.get(t).values()]) as T[];\r\n }\r\n\r\n /** escapes the given string so that any special characters will be processed literally in a regex search */\r\n protected escapeRegex(str: string) {\r\n return str.replace(/([.*+?^=!:${}()|[\\]/\\\\])/g, '\\\\$1');\r\n }\r\n\r\n /**\r\n * Given a string with wildcards *, will provide a regex that can be used to\r\n * match strings.\r\n * @param rule\r\n */\r\n protected getWildcardRegex(rule: string): RegExp {\r\n // \".\" => Find a single character, except newline or line terminator\r\n // \".*\" => Matches any string that contains zero or more characters\r\n rule = rule.split('*').map(this.escapeRegex).join('.*');\r\n\r\n // \"^\" => Matches any string with the following at the beginning of it\r\n // \"$\" => Matches any string with that in front at the end of it\r\n rule = '^' + rule + '$';\r\n\r\n //Create a regular expression object for matching string\r\n return new RegExp(rule, 'i');\r\n }\r\n\r\n /**\r\n * absorbs a kb3d object that already exists into the manager.\r\n * @param o\r\n */\r\n public register(o: T) {\r\n if (o instanceof Kb3dObject) {\r\n if (!this._db.has(o.id)) {\r\n if (isTrackedClass(o)) {\r\n o.isModified = true; //force a full round of change detection if this is a newly registered object\r\n }\r\n }\r\n\r\n this._db.set(o.id, o);\r\n dynamicDb.set(o._dynamicId, o);\r\n this._tokenDb.add(Token.withKey(o.$type), o);\r\n\r\n if (o.isNode()) {\r\n this._nodeDb.set(o.id, o);\r\n }\r\n }\r\n }\r\n\r\n public unregister(o: T) {\r\n if (o instanceof Kb3dObject) {\r\n this.clickHandlers.deleteByKey(o as any as SpaceNode);\r\n this.doubleClickHandlers.deleteByKey(o as any as SpaceNode);\r\n this.draggables.deleteByKey(o as any as SpaceNode);\r\n this.boundingboxChangeHandlers.deleteByKey(o as any as SpaceNode);\r\n this._db.delete(o.id);\r\n dynamicDb.delete(o._dynamicId);\r\n this._tokenDb.removeValue(Token.withKey(o.$type), o);\r\n\r\n if (o.isNode()) {\r\n this._nodeDb.delete(o.id);\r\n }\r\n\r\n if (o instanceof SceneNode && o.isNested()) {\r\n this._nestedSceneDb.delete(o.nestedId);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates an instance of a kb3d model, given a token\r\n * and an anonymous object in the shape of the model that\r\n * can be used to set properties on it.\r\n *\r\n * As part of the creation process, we do things in this order:\r\n *\r\n * 1. Create an instance of the class. If a create function was provided\r\n * in the decorator for the class, that is used to create the instance.\r\n * If not, then it's created by calling the constructor of the class\r\n * with no arguments.\r\n * 2. We then apply default values to the properties of the class\r\n * 3. We then apply the args that were passed in to set properties on the class\r\n * 4. We then register the object into the map using it's id so it can be quickly retrieved\r\n */\r\n public create(token: Token, args: Partial = {}, options?: IDeserializeOptions): T {\r\n options = { includeChildNodes: true, ...options };\r\n\r\n const modelDef = Kb3dModels.get(token);\r\n if (!modelDef) {\r\n throw `could not find model with token: ${token.key}`;\r\n }\r\n const constructorParameters = getConstructorParamsForModel(modelDef);\r\n const hydratedParameters: any[] = [];\r\n for (const i of constructorParameters) {\r\n if (!i.ignore) {\r\n const service = this.services?.get(i.token);\r\n if (!service) {\r\n throw `Injected service of type '${i.token.key} could not be found to inject into the constructor of type '${token.key}`;\r\n }\r\n hydratedParameters.push(service);\r\n }\r\n }\r\n\r\n let model: T;\r\n if (modelDef.create) {\r\n model = modelDef.create(args);\r\n } else {\r\n model = new (modelDef.classConstructor as Constructor)(...hydratedParameters);\r\n }\r\n\r\n //now initialize the model for when no create function was given\r\n if (!modelDef.create) {\r\n this.initializeModel(isTrackedClass(model) ? model.rawNode : model, args, modelDef, options);\r\n }\r\n\r\n if (model instanceof SceneNode) {\r\n model._manager = this;\r\n model.calculateParents(); //because calculateParents also registers the item, we must call this after initialization, otherwise it won't have the right id\r\n }\r\n\r\n if (modelDef.afterCreate) {\r\n modelDef.afterCreate(model);\r\n }\r\n\r\n //need to clear the name cache since we just created a new node\r\n //no need to clear if the node is a primitive as they are never fetched by name\r\n if(!token.isPrimitive()) {\r\n this._nameSearchCache.clear();\r\n }\r\n\r\n return model;\r\n }\r\n\r\n public serializeToJson(instance: T, options?: IJsonSerializeOptions): string {\r\n const o = this.serialize(instance, options);\r\n const json = JSON.stringify(o, null, options?.prettyPrint ? 2 : undefined);\r\n return json;\r\n }\r\n\r\n public serialize(instance: T, options?: ISerializeOptions): Partial | undefined {\r\n options = {\r\n includeChildNodes: true,\r\n isRoot: true,\r\n omitDefaultValues: true,\r\n ...options,\r\n };\r\n\r\n let result: any = { $type: instance.$type };\r\n const defaultValues = (defaults as any)[instance.$type];\r\n\r\n for (const key in instance) {\r\n if (\r\n // Never persist properties beginning with an underscore\r\n key.substr(0, 1) !== '_' &&\r\n // If a property is the same as a default value, remove it\r\n (!options.omitDefaultValues ||\r\n !defaultValues ||\r\n !this.shallowEquals(defaultValues[key], (instance as any)[key]))\r\n ) {\r\n if (!isObject(instance[key])) {\r\n // For primitives, just copy the values over\r\n result[key] = instance[key];\r\n } else if (Array.isArray(instance[key])) {\r\n const sourceArray = instance[key] as T[];\r\n if (sourceArray.length && typeof sourceArray[0] !== 'object') {\r\n //it's an array of primitives\r\n result[key] = sourceArray.slice(0); //clone the array of primitives\r\n } else {\r\n result[key] = []; //make sure there is an array on target prop. Recreate it if one is there already.\r\n for (const sourceItem of sourceArray) {\r\n if (\r\n !sourceItem.$type ||\r\n !Token.withKey(sourceItem.$type).isNode() ||\r\n options.includeChildNodes\r\n ) {\r\n // exclude it if it's a kb3d model and includeChildren is false\r\n const targetItem = this.serialize(sourceItem, { ...options, isRoot: false });\r\n if (targetItem) {\r\n result[key].push(targetItem);\r\n }\r\n }\r\n }\r\n }\r\n } else if ((instance[key] as any) instanceof Map) {\r\n console.error('implement serializing maps');\r\n } else if ((instance[key] as any) instanceof Set) {\r\n result[key] = {\r\n $type: SET_TYPE,\r\n values: Array.from((instance[key] as Set).values()),\r\n };\r\n } else {\r\n // For anything else, try deserializing. The deserializer will just copy the property if it is not a serialized class.\r\n result[key] = this.serialize(instance[key], { ...options, isRoot: false });\r\n }\r\n }\r\n }\r\n\r\n if (instance.$type) {\r\n const modelDef = Kb3dModels.get(Token.withKey(instance.$type));\r\n if (modelDef && modelDef.onSerializing) {\r\n const include = modelDef.onSerializing(instance, result);\r\n // Always serialize the object if it is the root object. Otherwise, let the class decide.\r\n if (include === false && !options.isRoot) {\r\n result = undefined;\r\n }\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * See notes for the create() function as this is virtually the same.\r\n * The only difference is that the type here is discovered through the $type\r\n * property of the args object instead of an explicit token.\r\n * @param object\r\n */\r\n public deserialize(object: any, options?: IDeserializeOptions): T {\r\n if (!object || !object.$type) {\r\n return object;\r\n } else if (object.$type === SET_TYPE) {\r\n return new Set(object.values) as any;\r\n }\r\n return this.create(Token.withKey(object.$type), object, options);\r\n }\r\n\r\n public deserializeJson(json: string): T {\r\n const object = JSON.parse(json);\r\n return this.deserialize(object);\r\n }\r\n\r\n public clone(objectToClone: T): T {\r\n //make sure it's a kb3d model\r\n if (!objectToClone) throw 'no object provided to clone';\r\n if (!('$type' in objectToClone)) {\r\n throw 'object passed to clone function must be a kb3d model and have a $type defined';\r\n }\r\n const json = this.serializeToJson(objectToClone);\r\n const object = JSON.parse(json) as Kb3dObject;\r\n\r\n return this.deserialize(object, { issueNewIds: true });\r\n }\r\n\r\n public nestScene(nestedId: string, parent: SceneNode, serializedNested: Partial = {}) {\r\n const nestedMan = new Kb3dManager({ services: this.services });\r\n if (serializedNested.lights) {\r\n serializedNested.lights.clear();\r\n }\r\n const nested = nestedMan.create(Token.SceneNode, serializedNested);\r\n nested.nestedId = nestedId.replace('/', '');\r\n parent.scenes.push(nested);\r\n this._nestedSceneDb.set(nested.nestedId.toLowerCase(), nested);\r\n\r\n return nested;\r\n }\r\n\r\n protected getNodeNamePathMap() {\r\n const meshMap = new Map();\r\n const matMap = new Map();\r\n const lightMap = new Map();\r\n const allNodes = this._nodeDb.values();\r\n for (const n of allNodes) {\r\n if (isLightNode(n)) {\r\n lightMap.set(n.getNamePath(), n);\r\n } else if (isMaterialNode(n)) {\r\n matMap.set(n.getNamePath(), n);\r\n } else {\r\n meshMap.set(n.getNamePath(), n);\r\n }\r\n }\r\n return {\r\n meshes: meshMap,\r\n lights: lightMap,\r\n materials: matMap,\r\n };\r\n }\r\n\r\n public previewImport(parent: SceneNode | MeshGroupNode, imported: ISceneInfo) {\r\n const sceneNode = parent._parentScene;\r\n if (!sceneNode || !imported.scene) return;\r\n\r\n const nMap = this.getNodeNamePathMap();\r\n\r\n const processNode = (node: Partial, parentNamePath: string) => {\r\n const token = Token.withKey((node as any)['$type']);\r\n const namePath =\r\n token !== Token.SceneNode && node.name\r\n ? [parentNamePath, node.name].filter(Boolean).join('/')\r\n : parentNamePath;\r\n\r\n let matchingNode: Kb3dObject | undefined;\r\n if (token.isLight()) {\r\n matchingNode = nMap.lights.get(namePath);\r\n } else if (token.isMaterial()) {\r\n matchingNode = nMap.materials.get(namePath);\r\n } else {\r\n matchingNode = nMap.meshes.get(namePath);\r\n }\r\n\r\n const p = {\r\n node,\r\n type: Token.withKey((node as any)['$type']),\r\n namePath,\r\n matchingNode,\r\n operation: matchingNode ? ImportOperation.replace : ImportOperation.add,\r\n } as IImportPreview;\r\n p.children = ['meshes', 'materials', 'lights', 'viewpoints'].flatMap(childProp => {\r\n const childArr = (node as any)[childProp] as Kb3dObject[];\r\n return childArr\r\n ? childArr.map(c => {\r\n const cNode = processNode(c, childProp === 'meshes' ? namePath : '');\r\n cNode.parent = p;\r\n return cNode;\r\n })\r\n : [];\r\n });\r\n return p;\r\n };\r\n\r\n const pathToImportParent = parent.getNamePath();\r\n (imported.scene as any)['$type'] = 'SceneNode';\r\n return processNode(imported.scene, pathToImportParent).children;\r\n }\r\n\r\n public import(previews: IImportPreview[], parentNode: SpaceNode | MaterialNode, root = true) {\r\n const nMap = this.getNodeNamePathMap();\r\n\r\n // Materials have to come first so we know how they reconnect to the meshes to them\r\n previews.sort((a, b) => {\r\n if (a.type.isMaterial() && !b.type.isMaterial()) {\r\n return -1;\r\n } else {\r\n return 0;\r\n }\r\n });\r\n\r\n for (const p of previews) {\r\n if (p.operation !== ImportOperation.ignore) {\r\n let thisNode: Kb3dObject;\r\n\r\n if (p.operation === ImportOperation.add || !p.matchingNode) {\r\n const parentPath = p.namePath.substring(0, p.namePath.lastIndexOf('/'));\r\n\r\n let parent: Kb3dObject | undefined;\r\n if (!parentPath) {\r\n parent = parentNode;\r\n } else if (p.type.isLight()) {\r\n parent = nMap.lights.get(parentPath);\r\n } else if (p.type.isMaterial()) {\r\n parent = nMap.materials.get(parentPath);\r\n } else {\r\n parent = nMap.meshes.get(parentPath);\r\n }\r\n\r\n const newNode = this.deserialize(p.node, { includeChildNodes: false });\r\n if (\r\n instanceOfAny(newNode, ...Token.GlobalLightTokens) &&\r\n instanceOf(parentNode, Token.SceneNode)\r\n ) {\r\n parentNode.lights.push(newNode);\r\n } else if (parent?.id === parentNode.id) {\r\n parentNode?.addChildren(newNode);\r\n }\r\n thisNode = newNode;\r\n } else {\r\n // replace\r\n const originalId = p.matchingNode.id;\r\n const matchingMeshNode = isMeshNode(p.matchingNode) ? p.matchingNode : undefined;\r\n const originalMaterialId = matchingMeshNode ? matchingMeshNode.materialId : undefined;\r\n this.assign(p.matchingNode, p.node, { includeChildNodes: false });\r\n\r\n p.matchingNode.id = originalId;\r\n // If the new materialId from the import exists, that means the material was imported and added and can be used.\r\n // If the new materialId from the import does not exist, use the old materialId because the material was updated but\r\n // kept the original ID.\r\n if (matchingMeshNode && originalMaterialId && matchingMeshNode.materialId) {\r\n if (!this.getById(matchingMeshNode.materialId)) {\r\n matchingMeshNode.materialId = originalMaterialId;\r\n }\r\n }\r\n // Trigger change detection on this existing node\r\n if (isTrackedClass(p.matchingNode)) {\r\n p.matchingNode.isModified = true;\r\n }\r\n thisNode = p.matchingNode;\r\n }\r\n\r\n if (thisNode instanceof SpaceNode || thisNode instanceof MaterialNode) {\r\n this.import(p.children, thisNode, false);\r\n } else if (p.children && p.children.length > 0) {\r\n throw Error('Children on non-space node or non-material-node, how did this happen');\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected initializeModel(model: T, args: Partial, modelDef: IKb3dModel, options?: IDeserializeOptions) {\r\n this.setModelDefaultValues(model);\r\n this.assign(model, args, options);\r\n }\r\n\r\n protected setModelDefaultValues(o: any) {\r\n const values = (defaults as any)[o.$type];\r\n if (values) {\r\n for (const prop in values) {\r\n if (values[prop] && values[prop].$type) {\r\n o[prop] = this.deserialize(values[prop]);\r\n } else if (isObject(values[prop])) {\r\n o[prop] = { ...values[prop] }; //need to clone the object from default values otherwise the class and defaults will both be pointing to same instance!\r\n } else {\r\n o[prop] = values[prop];\r\n }\r\n }\r\n }\r\n }\r\n\r\n public assign(model: any, args: any, options?: IDeserializeOptions) {\r\n options = {\r\n includeChildNodes: true,\r\n issueNewIds: false,\r\n copyingToDifferentNode: false,\r\n ...options,\r\n };\r\n\r\n if (args) {\r\n if (options.copyingToDifferentNode) {\r\n // If we are using assign to copy properties from one node to another, serialize the data\r\n if (args instanceof Kb3dObject) {\r\n const defaultValues = { $type: args.$type };\r\n this.setModelDefaultValues(defaultValues);\r\n args = { ...defaultValues, ...this.serialize(args) };\r\n }\r\n }\r\n\r\n for (const prop in args) {\r\n // Never persist properties beginning with an underscore\r\n if (prop.substr(0, 1) == '_') continue;\r\n if (options.copyingToDifferentNode) {\r\n if ((prop.isEqual('id') && model.id) || prop.isEqual('$type')) {\r\n continue; // skip id's if copying to an existing node so the node retains its ID\r\n }\r\n }\r\n if (options.issueNewIds && prop.isEqual('id') && args.$type) continue; //skip id's if options specify so it will use the new one it generates during construction\r\n\r\n const sourceProp = args[prop];\r\n\r\n if (typeof model === 'undefined') {\r\n throw Error(); // this should never happen, this means a reference is being lost somewhere\r\n }\r\n\r\n if (prop === 'parent' || sourceProp === model[prop]) {\r\n // Don't break parent relationships\r\n continue; // Don't break parent relationships\r\n }\r\n\r\n if (!isObject(args[prop])) {\r\n // For primitives, just copy the values over\r\n model[prop] = args[prop];\r\n } else if (Array.isArray(sourceProp)) {\r\n // make sure there is an array on target prop. Recreate it if one is there already.\r\n if (model[prop]) {\r\n if (\r\n options.includeChildNodes ||\r\n !(\r\n model[prop].length > 0 &&\r\n model[prop][0].$type &&\r\n Token.withKey(model[prop][0].$type).isNode()\r\n )\r\n ) {\r\n model[prop].clear();\r\n }\r\n } else {\r\n model[prop] = [];\r\n }\r\n\r\n for (const sourceItem of sourceProp) {\r\n let targetItem: any;\r\n if (sourceItem.$type) {\r\n //it's one of our types so deserialize it\r\n if (options.includeChildNodes || !Token.withKey(sourceItem.$type).isNode()) {\r\n targetItem = this.deserialize(sourceItem, options);\r\n model[prop].push(targetItem);\r\n }\r\n } else if (isObject(sourceItem)) {\r\n targetItem = {};\r\n model[prop].push(targetItem);\r\n this.assign(targetItem, sourceItem, options);\r\n } else {\r\n //primitive type\r\n model[prop].push(sourceItem);\r\n }\r\n }\r\n } else {\r\n if (sourceProp.$type) {\r\n //it's one of our types so deserialize it\r\n if (options.includeChildNodes || !Token.withKey(sourceProp.$type).isNode()) {\r\n model[prop] = this.deserialize(sourceProp, options);\r\n }\r\n } else if (isObject(sourceProp)) {\r\n const targetItem: any = {};\r\n model[prop] = targetItem;\r\n this.assign(targetItem, sourceProp, options);\r\n } else {\r\n //primitive type\r\n model[prop] = sourceProp;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected shallowEquals(a: A, b: B) {\r\n if (!isObject(a)) {\r\n return (a as any) === (b as any);\r\n }\r\n\r\n for (const aProp in a) {\r\n if (aProp.substring(0, 1) !== '_') {\r\n if (!(aProp in b)) {\r\n return false;\r\n }\r\n if (a[aProp] !== (b as any)[aProp]) {\r\n return false;\r\n }\r\n }\r\n }\r\n for (const bProp in b) {\r\n if (bProp.substring(0, 1) !== '_') {\r\n if (!(bProp in a)) {\r\n return false;\r\n }\r\n if (b[bProp] !== (a as any)[bProp]) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n","import { eShadowFilter, eShadowQuality, eShadowResolution } from '../enums';\r\nimport { IShadowLightNode } from '../kb3d-models';\r\nimport { LightNode } from './light-node';\r\n\r\nexport abstract class ShadowLightNode extends LightNode implements IShadowLightNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n public generatesShadows: boolean;\r\n public shadowQuality: eShadowQuality;\r\n public shadowResolution: eShadowResolution;\r\n public shadowFilter: eShadowFilter;\r\n public processTransparency: boolean;\r\n}\r\n","import { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { IgnoreHistory } from '../decorators/change-tracker';\r\nimport { BaseKb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOfAny } from '../decorators/model-utils';\r\nimport {\r\n eTextureBlendMode,\r\n eTextureChannel,\r\n eTextureFit,\r\n eTextureHorizontalAlign,\r\n eTextureVerticalAlign,\r\n eTextureWrapAddressMode,\r\n} from '../enums';\r\nimport { FeatureWithTextures } from '../features/feature';\r\nimport { ITextureLayer } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\nimport { MaterialMapping } from './material-mapping';\r\nimport { MaterialNode } from './material-node';\r\n\r\n@BaseKb3dModel({\r\n token: Token.TextureLayer,\r\n})\r\nexport abstract class TextureLayer extends MaterialMapping implements ITextureLayer {\r\n channel: eTextureChannel;\r\n blendMode: eTextureBlendMode;\r\n horizontalAlign: eTextureHorizontalAlign;\r\n verticalAlign: eTextureVerticalAlign;\r\n horizontalFit: eTextureFit;\r\n verticalFit: eTextureFit;\r\n strength: number;\r\n colorize?: KbColor;\r\n tile: boolean;\r\n uWrap: eTextureWrapAddressMode;\r\n vWrap: eTextureWrapAddressMode;\r\n maintainAspect: boolean;\r\n _visualize: boolean;\r\n useClippingMask: boolean;\r\n\r\n @IgnoreHistory\r\n _init = false;\r\n\r\n @IgnoreHistory\r\n _external = false;\r\n\r\n enabled: boolean;\r\n _suppressed: boolean;\r\n\r\n /** override base parent for more specific typing*/\r\n public _parent: MaterialNode | FeatureWithTextures | undefined;\r\n\r\n init(parent: MaterialNode | FeatureWithTextures) {\r\n if (!this._init) {\r\n this._parent = parent;\r\n // Normally this function is called when the node is added to an array on the parent, but textures live in defined properties on a material.\r\n // So we have to explicitly call it here, on texture init. The texture won't be doing anything before init anyways.\r\n this.calculateParents();\r\n if (isTrackedClass(this)) {\r\n // Always track changes on initialized textures because they may be attached to global materials\r\n this.trackChanges(true);\r\n this._init = true;\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport function isTextureLayer(node: Kb3dObject): node is TextureLayer {\r\n return instanceOfAny(node, ...Token.TextureLayerTokens);\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IDirectionalLightNode } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { ShadowLightNode } from './shadow-light-node';\r\n\r\n@Kb3dModel({\r\n token: Token.DirectionalLightNode,\r\n})\r\nexport class DirectionalLightNode extends ShadowLightNode implements IDirectionalLightNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n public direction: KbVector;\r\n}\r\n","import { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IHemisphericLightNode } from '../kb3d-models';\r\nimport { KbColor } from '../primitives/kb-color';\r\nimport { Token } from '../token';\r\nimport { LightNode } from './light-node';\r\n\r\n@Kb3dModel({\r\n token: Token.HemisphericLightNode,\r\n})\r\nexport class HemisphericLightNode extends LightNode implements IHemisphericLightNode {\r\n constructor() {\r\n super();\r\n }\r\n public direction: KbVector;\r\n public groundColor: KbColor;\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IPointLightNode } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { ShadowLightNode } from './shadow-light-node';\r\n\r\n@Kb3dModel({\r\n token: Token.PointLightNode,\r\n})\r\nexport class PointLightNode extends ShadowLightNode implements IPointLightNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n public position: KbVector;\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ISpotLightNode } from '../kb3d-models';\r\nimport { KbVector } from '../primitives/kb-vector';\r\nimport { Token } from '../token';\r\nimport { DirectionalLightNode } from './directional-light-node';\r\n\r\n@Kb3dModel({\r\n token: Token.SpotLightNode,\r\n})\r\nexport class SpotLightNode extends DirectionalLightNode implements ISpotLightNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n public position: KbVector;\r\n public coneAngle: number;\r\n}\r\n","import { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { MaterialService } from '@models/services/material-service';\r\nimport { Enumerable, IgnoreChanges } from '../decorators';\r\nimport { Inject } from '../decorators/inject-decorator';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { eAlphaMode, eMaterialLocation, eMaterialWorkflow, eReflectionType } from '../enums';\r\nimport { IAdvancedMaterialNode } from '../kb3d-models';\r\nimport { KbColor } from '../primitives/kb-color';\r\nimport { Token } from '../token';\r\nimport { MaterialNode } from './material-node';\r\nimport { TextureLayer } from './texture-layer';\r\n\r\n@Kb3dModel({\r\n token: Token.AdvancedMaterialNode,\r\n onSerializing: (node, o) => {\r\n if (node.parentMaterialId == null) {\r\n return true;\r\n }\r\n\r\n // remove any textures that are from the parent material\r\n o.textures = o.textures?.filter(texture => !texture._external);\r\n\r\n // remove any properties from the serialization that are inherited from a global or library material\r\n const keys = Object.keys(o);\r\n for (const p of keys) {\r\n if (node._overriddenPropertiesSet && !node._overriddenPropertiesSet.has(p) && p !== 'textures') {\r\n delete (o as any)[p];\r\n }\r\n }\r\n if (node._overriddenPropertiesSet) {\r\n o.overriddenProperties = Array.from(node._overriddenPropertiesSet).map(val => val.toString());\r\n }\r\n\r\n return node.location == eMaterialLocation.local;\r\n },\r\n addedToChildArray: (node, child) => {\r\n if (child instanceof TextureLayer) {\r\n if (node._initialized) {\r\n child.init(node);\r\n }\r\n }\r\n },\r\n afterCreate: node => {\r\n node.overriddenProperties.forEach(val => node._overriddenPropertiesSet.add(val));\r\n\r\n node.calculateParents(); //parents need to be calculated again because the texture children don't exist yet the first time it is run\r\n node.refreshParentMaterial();\r\n },\r\n})\r\nexport class AdvancedMaterialNode extends MaterialNode implements IAdvancedMaterialNode {\r\n constructor(@Inject(Token.MaterialService) _materialService: MaterialService) {\r\n super(_materialService);\r\n\r\n this._initialized = false;\r\n }\r\n\r\n protected _materials: AdvancedMaterialNode[];\r\n @Enumerable()\r\n get materials(): AdvancedMaterialNode[] {\r\n if (!this._materials) this._materials = [];\r\n return this._materials;\r\n }\r\n set materials(val) {\r\n this._materials = val;\r\n }\r\n\r\n @IgnoreChanges\r\n _initialized = false;\r\n\r\n guid: string;\r\n\r\n alpha: number;\r\n alphaMode?: eAlphaMode;\r\n\r\n workflowMode: eMaterialWorkflow;\r\n\r\n /**\r\n * Intensity of the direct lights e.g. the four lights available in your scene.\r\n * This impacts both the direct diffuse and specular highlights.\r\n */\r\n directIntensity: number;\r\n\r\n /**\r\n * Intensity of the emissive part of the material.\r\n * This helps controlling the emissive effect without modifying the emissive color.\r\n */\r\n emissiveIntensity: number;\r\n\r\n /**\r\n * Intensity of the environment e.g. how much the environment will light the object\r\n * either through harmonics for rough material or through the refelction for shiny ones.\r\n */\r\n environmentIntensity: number;\r\n\r\n /**\r\n * This is a special control allowing the reduction of the specular highlights coming from the\r\n * four lights of the scene. Those highlights may not be needed in full environment lighting.\r\n */\r\n specularIntensity: number;\r\n\r\n /**\r\n * AKA Occlusion Texture Intensity in other nomenclature.\r\n */\r\n ambientTextureStrength?: number;\r\n\r\n /**\r\n * Specifies the metallic scalar of the metallic/roughness workflow.\r\n * Can also be used to scale the metalness values of the metallic texture.\r\n */\r\n metallic: number;\r\n\r\n /**\r\n * Specifies the roughness scalar of the metallic/roughness workflow.\r\n * Can also be used to scale the roughness values of the metallic texture.\r\n */\r\n roughness: number;\r\n\r\n /**\r\n * The color of a material in ambient lighting.\r\n */\r\n ambientColor: KbColor;\r\n\r\n /**\r\n * AKA Diffuse Color in other nomenclature.\r\n */\r\n albedoColor: KbColor;\r\n\r\n /**\r\n * AKA Specular Color in other nomenclature.\r\n */\r\n specularColor: KbColor;\r\n\r\n /**\r\n * The color reflected from the material.\r\n */\r\n reflectionColor: KbColor;\r\n\r\n /**\r\n * The type of reflection or refraction being used used (Plane or probe)\r\n */\r\n reflectionType: eReflectionType;\r\n\r\n /**\r\n * AKA Glossiness in other nomenclature.\r\n */\r\n microSurface: number;\r\n\r\n /**\r\n * Specifies that the material will keep the specular highlights over a transparent surface (only the most limunous ones).\r\n * A car glass is a good exemple of that. When sun reflects on it you can not see what is behind.\r\n */\r\n useSpecularOverAlpha: boolean;\r\n\r\n /**\r\n * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most limunous ones).\r\n * A car glass is a good exemple of that. When the street lights reflects on it you can not see what is behind.\r\n */\r\n useRadianceOverAlpha: boolean;\r\n\r\n /** Anisotropy settings */\r\n anisotropyEnabled: boolean;\r\n anisotropicDirection: KbVector;\r\n anisotropicIntensity: number;\r\n\r\n /** Clearcoat settings */\r\n clearcoatEnabled: boolean;\r\n clearcoatIntensity: number;\r\n clearcoatTintColor: KbColor;\r\n clearcoatTintEnabled: boolean;\r\n clearcoatTintIntensity: number;\r\n\r\n /** Refraction settings */\r\n subsurfaceRefractionEnabled: boolean;\r\n subsurfaceReflectionEnabled: boolean;\r\n subsurfaceRefractionIndex: number;\r\n subsurfaceRefractionIntensity: number;\r\n subsurfaceRefractionLinkTransparency: boolean;\r\n\r\n /** Translucency settings */\r\n subsurfaceTranslucencyEnabled: boolean;\r\n subsurfaceTranslucencyIntensity: number;\r\n\r\n /** Common subsurface settings shared between refraction and translucency */\r\n subsurfaceThickness: number;\r\n subsurfaceTintColor: KbColor;\r\n subsurfaceUseAlbedoForTintColor: boolean;\r\n}\r\n","import { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IColorFillTextureLayer } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { TextureLayer } from './texture-layer';\r\n\r\n@Kb3dModel({\r\n token: Token.ColorFillTextureLayer,\r\n})\r\nexport class ColorFillTextureLayer extends TextureLayer implements IColorFillTextureLayer {\r\n color: KbColor;\r\n\r\n width: number;\r\n height: number;\r\n}\r\n","import { IgnoreChanges, IgnoreHistory } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { IFileTextureLayer } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { TextureLayer } from './texture-layer';\r\n\r\n@Kb3dModel({\r\n token: Token.FileTextureLayer,\r\n onSerializing: (node, o) => {\r\n return !node._external; // TODO Copy this to other layer types\r\n },\r\n})\r\nexport class FileTextureLayer extends TextureLayer implements IFileTextureLayer {\r\n path = '';\r\n\r\n @IgnoreChanges _needsImageUpdate = false;\r\n @IgnoreHistory\r\n _buffer?: ImageBitmap; // the image data is saved here\r\n _bufferSource: string; // to trigger changes \r\n\r\n width: number;\r\n height: number;\r\n\r\n flipNormalsRg = false;\r\n}\r\n","import { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ISvgTextureLayer } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { TextureLayer } from './texture-layer';\r\n\r\n@Kb3dModel({\r\n token: Token.SvgTextureLayer,\r\n})\r\nexport class SvgTextureLayer extends TextureLayer implements ISvgTextureLayer {\r\n svgXml = '';\r\n height = 256;\r\n width = 256;\r\n preloadFontStylesheet = '';\r\n\r\n _raster?: ImageBitmap;\r\n}\r\n","import { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { ITextTextureLayer } from '../kb3d-models';\r\nimport { Token } from '../token';\r\nimport { TextureLayer } from './texture-layer';\r\n\r\n@Kb3dModel({\r\n token: Token.TextTextureLayer,\r\n})\r\nexport class TextTextureLayer extends TextureLayer implements ITextTextureLayer {\r\n color: KbColor;\r\n font: string;\r\n text: string;\r\n}\r\n","import { IgnoreChanges, NodeReference } from '../decorators/change-tracker';\r\nimport { Kb3dModel } from '../decorators/kb3d-decorator';\r\nimport { instanceOf } from '../decorators/model-utils';\r\nimport { eMateType } from '../enums';\r\nimport { BaseConnector } from '../features';\r\nimport { IMateNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { Token } from '../token';\r\n\r\n@Kb3dModel({\r\n token: Token.MateNode,\r\n validate: (n, v) => {\r\n if (n.changes.hasAny('connector1', 'connector2')) {\r\n v.assert(\r\n n,\r\n 'connector1',\r\n n.connector1 != null && n._manager?.getById(n.connector1) != null,\r\n 'Connector is required'\r\n );\r\n v.assert(\r\n n,\r\n 'connector2',\r\n n.connector2 != null && n._manager?.getById(n.connector2) != null,\r\n 'Connector is required'\r\n );\r\n v.assert(\r\n n,\r\n 'connector2',\r\n n._manager?.getById(n.connector1)?._parent !== n._manager?.getById(n.connector2)?._parent ||\r\n n._manager?.getById(n.connector1) == null,\r\n 'Connectors cannot have the same parent node'\r\n );\r\n }\r\n },\r\n})\r\nexport class MateNode extends Kb3dObject implements IMateNode {\r\n constructor() {\r\n super();\r\n }\r\n\r\n enabled: boolean;\r\n mateType: eMateType;\r\n @NodeReference(BaseConnector, 'position', 'direction', 'angle') connector1: string;\r\n @NodeReference(BaseConnector, 'position', 'direction', 'angle') connector2: string;\r\n flip: boolean;\r\n offsetX: number;\r\n offsetY: number;\r\n offsetZ: number;\r\n offsetAngle: number;\r\n\r\n /** used internally when processing mates to control whether c1/c2 need to be swapped */\r\n @IgnoreChanges\r\n _swap: boolean;\r\n\r\n getC1() {\r\n return this._manager?.getById(this.connector1);\r\n }\r\n getC2() {\r\n return this._manager?.getById(this.connector2);\r\n }\r\n isActive() {\r\n return this.enabled && this.getC1() != null && this.getC2() != null;\r\n }\r\n}\r\n\r\nexport function isMate(node: Kb3dObject): node is MateNode {\r\n return instanceOf(node, Token.MateNode);\r\n}\r\n","import { SetMap } from '@models/classes/handlers';\r\n\r\nexport interface TopologicalSortResult {\r\n /** the topologically sorted result set */\r\n sorted: Set;\r\n /** if any cycles were detected (which is not good), they are returned here */\r\n cycles: T[][];\r\n}\r\n\r\n/**\r\n * Does a topological sort of directed graph with cycle detection and warning.\r\n * @param nodes a map where the key is the node and value is an array containing the nodes the key node depends on\r\n * @param nameSelector function that returns a descriptive name for the node\r\n */\r\nexport function topologicalSort(nodes: SetMap, nameSelector: (node: T) => string) {\r\n const visited = new Set();\r\n const path = new Set();\r\n const sorted = new Set();\r\n const cycles = new Array();\r\n\r\n for (const [node] of nodes) {\r\n recurse(nodes, nameSelector, node, visited, path, sorted, cycles);\r\n }\r\n\r\n // console.log(`Original graph: ${getDescriptor(nameSelector, ...nodes.keys())}`);\r\n // console.log(`Sorted graph: ${getDescriptor(nameSelector, ...sorted)}`);\r\n\r\n return {\r\n sorted,\r\n cycles,\r\n } as TopologicalSortResult;\r\n}\r\n\r\nfunction recurse(\r\n nodes: SetMap,\r\n nameSelector: (node: T) => string,\r\n node: T,\r\n visited: Set,\r\n path: Set,\r\n sorted: Set,\r\n cycles: T[][]\r\n) {\r\n if (path.has(node)) {\r\n const items = [...path].reverse();\r\n cycles.push(items);\r\n //console.warn(`Cycle detected: ${getDescriptor(nameSelector, ...path, node)}`);\r\n }\r\n\r\n if (visited.has(node)) return;\r\n visited.add(node);\r\n path.add(node);\r\n\r\n const edges = nodes.get(node);\r\n if (edges) {\r\n for (const edge of edges) {\r\n recurse(nodes, nameSelector, edge, visited, path, sorted, cycles);\r\n }\r\n }\r\n\r\n path.delete(node);\r\n sorted.add(node);\r\n}\r\n\r\n// function getDescriptor(nameSelector: (n: any) => string, ...nodes: any[]){\r\n// return nodes.map(n => nameSelector(n)).join(\" -> \");\r\n// }\r\n","import { Enumerable, instanceOf, Kb3dModel } from '../decorators';\r\nimport { defaults } from '../default-values';\r\nimport { eViewpointProjection, eViewpointTargetMode, eViewpointType } from '../enums';\r\nimport { IViewpointNode } from '../kb3d-models';\r\nimport { Kb3dObject } from '../kb3d-object';\r\nimport { KbVector } from '../primitives';\r\nimport { Token } from '../token';\r\n\r\n@Kb3dModel({\r\n token: Token.ViewpointNode,\r\n onSerializing: (node, o) => {\r\n // remove any target properties not relevant to the target mode\r\n if (node.targetMode === eViewpointTargetMode.rotation) {\r\n delete o.targetPoint;\r\n delete node.targetMeshId;\r\n } else if (node.targetMode === eViewpointTargetMode.point) {\r\n delete o.rotation;\r\n delete node.targetMeshId;\r\n } else if (node.targetMode === eViewpointTargetMode.mesh) {\r\n delete o.targetPoint;\r\n delete o.rotation;\r\n }\r\n return true;\r\n },\r\n validate: (n, v) => {\r\n if (n.changes.hasAny('targetMode', 'targetMeshId')) {\r\n const exp =\r\n n.targetMode != eViewpointTargetMode.mesh ||\r\n (n.targetMeshId != null && n._manager?.getById(n.targetMeshId) != null);\r\n v.assert(n, 'targetMeshId', exp, 'Target mesh required');\r\n }\r\n },\r\n})\r\nexport class ViewpointNode extends Kb3dObject implements IViewpointNode {\r\n constructor() {\r\n super();\r\n\r\n this.type = eViewpointType.orbit;\r\n this.targetMode = eViewpointTargetMode.point;\r\n this.position = KbVector.Zero();\r\n this.rotation = KbVector.Zero();\r\n this.targetPoint = KbVector.Zero();\r\n this.fov = defaults.ViewpointNode.fov;\r\n this.projection = eViewpointProjection.perspective;\r\n }\r\n\r\n private _type?: eViewpointType;\r\n @Enumerable()\r\n public get type() {\r\n return this._type;\r\n }\r\n public set type(newType) {\r\n this._type = newType;\r\n switch (newType) {\r\n case eViewpointType.firstPerson:\r\n this.targetMode = eViewpointTargetMode.rotation;\r\n this.projection = eViewpointProjection.perspective;\r\n break;\r\n }\r\n }\r\n targetMode: eViewpointTargetMode;\r\n position: KbVector;\r\n rotation: KbVector;\r\n targetPoint: KbVector;\r\n targetMeshId: string | undefined;\r\n orbitAxis: KbVector;\r\n fov: number;\r\n projection: eViewpointProjection;\r\n minTargetDistance: number;\r\n maxTargetDistance: number;\r\n\r\n offsetX = 0; // For panning\r\n offsetY = 0;\r\n\r\n allowOrbit = true;\r\n allowPan = true;\r\n allowZoom = true;\r\n limitMinimumTargetDistance = false;\r\n limitLatOrbit = false;\r\n limitMinLatitude: number;\r\n limitMaxLatitude: number;\r\n limitLngOrbit = false;\r\n limitMinLongitude: number;\r\n limitMaxLongitude: number;\r\n}\r\n\r\nexport function isViewpointNode(node: Kb3dObject): node is ViewpointNode {\r\n return instanceOf(node, Token.ViewpointNode);\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\nimport type { ISize } from \"../../Maths/math.size\";\r\nimport { Size } from \"../../Maths/math.size\";\r\n\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { RenderTargetWrapper } from \"core/Engines/renderTargetWrapper\";\r\n\r\n/**\r\n * Base class of all the textures in babylon.\r\n * It groups all the common properties required to work with Thin Engine.\r\n */\r\nexport class ThinTexture {\r\n protected _wrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n public get wrapU() {\r\n return this._wrapU;\r\n }\r\n\r\n public set wrapU(value: number) {\r\n this._wrapU = value;\r\n }\r\n\r\n protected _wrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n public get wrapV() {\r\n return this._wrapV;\r\n }\r\n\r\n public set wrapV(value: number) {\r\n this._wrapV = value;\r\n }\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n public wrapR = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n\r\n /**\r\n * With compliant hardware and browser (supporting anisotropic filtering)\r\n * this defines the level of anisotropic filtering in the texture.\r\n * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.\r\n */\r\n public anisotropicFilteringLevel = 4;\r\n\r\n /**\r\n * Define the current state of the loading sequence when in delayed load mode.\r\n */\r\n public delayLoadState = Constants.DELAYLOADSTATE_NONE;\r\n\r\n /**\r\n * How a texture is mapped.\r\n * Unused in thin texture mode.\r\n */\r\n public get coordinatesMode(): number {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Define if the texture is a cube texture or if false a 2d texture.\r\n */\r\n public get isCube(): boolean {\r\n if (!this._texture) {\r\n return false;\r\n }\r\n\r\n return this._texture.isCube;\r\n }\r\n\r\n protected set isCube(value: boolean) {\r\n if (!this._texture) {\r\n return;\r\n }\r\n\r\n this._texture.isCube = value;\r\n }\r\n\r\n /**\r\n * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.\r\n */\r\n public get is3D(): boolean {\r\n if (!this._texture) {\r\n return false;\r\n }\r\n\r\n return this._texture.is3D;\r\n }\r\n\r\n protected set is3D(value: boolean) {\r\n if (!this._texture) {\r\n return;\r\n }\r\n\r\n this._texture.is3D = value;\r\n }\r\n\r\n /**\r\n * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.\r\n */\r\n public get is2DArray(): boolean {\r\n if (!this._texture) {\r\n return false;\r\n }\r\n\r\n return this._texture.is2DArray;\r\n }\r\n\r\n protected set is2DArray(value: boolean) {\r\n if (!this._texture) {\r\n return;\r\n }\r\n\r\n this._texture.is2DArray = value;\r\n }\r\n\r\n /**\r\n * Get the class name of the texture.\r\n * @returns \"ThinTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"ThinTexture\";\r\n }\r\n\r\n /** @internal */\r\n public _texture: Nullable = null;\r\n\r\n protected _engine: Nullable = null;\r\n\r\n private _cachedSize: ISize = Size.Zero();\r\n private _cachedBaseSize: ISize = Size.Zero();\r\n\r\n private static _IsRenderTargetWrapper(texture: Nullable | Nullable): texture is RenderTargetWrapper {\r\n return (texture as RenderTargetWrapper)?._shareDepth !== undefined;\r\n }\r\n\r\n /**\r\n * Instantiates a new ThinTexture.\r\n * Base class of all the textures in babylon.\r\n * This can be used as an internal texture wrapper in ThinEngine to benefit from the cache\r\n * @param internalTexture Define the internalTexture to wrap. You can also pass a RenderTargetWrapper, in which case the texture will be the render target's texture\r\n */\r\n constructor(internalTexture: Nullable) {\r\n this._texture = ThinTexture._IsRenderTargetWrapper(internalTexture) ? internalTexture.texture : internalTexture;\r\n if (this._texture) {\r\n this._engine = this._texture.getEngine();\r\n }\r\n }\r\n\r\n /**\r\n * Get if the texture is ready to be used (downloaded, converted, mip mapped...).\r\n * @returns true if fully ready\r\n */\r\n public isReady(): boolean {\r\n if (this.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {\r\n this.delayLoad();\r\n return false;\r\n }\r\n\r\n if (this._texture) {\r\n return this._texture.isReady;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Triggers the load sequence in delayed load mode.\r\n */\r\n public delayLoad(): void {}\r\n\r\n /**\r\n * Get the underlying lower level texture from Babylon.\r\n * @returns the internal texture\r\n */\r\n public getInternalTexture(): Nullable {\r\n return this._texture;\r\n }\r\n\r\n /**\r\n * Get the size of the texture.\r\n * @returns the texture size.\r\n */\r\n public getSize(): ISize {\r\n if (this._texture) {\r\n if (this._texture.width) {\r\n this._cachedSize.width = this._texture.width;\r\n this._cachedSize.height = this._texture.height;\r\n return this._cachedSize;\r\n }\r\n\r\n if (this._texture._size) {\r\n this._cachedSize.width = this._texture._size;\r\n this._cachedSize.height = this._texture._size;\r\n return this._cachedSize;\r\n }\r\n }\r\n\r\n return this._cachedSize;\r\n }\r\n\r\n /**\r\n * Get the base size of the texture.\r\n * It can be different from the size if the texture has been resized for POT for instance\r\n * @returns the base size\r\n */\r\n public getBaseSize(): ISize {\r\n if (!this.isReady() || !this._texture) {\r\n this._cachedBaseSize.width = 0;\r\n this._cachedBaseSize.height = 0;\r\n return this._cachedBaseSize;\r\n }\r\n\r\n if (this._texture._size) {\r\n this._cachedBaseSize.width = this._texture._size;\r\n this._cachedBaseSize.height = this._texture._size;\r\n return this._cachedBaseSize;\r\n }\r\n\r\n this._cachedBaseSize.width = this._texture.baseWidth;\r\n this._cachedBaseSize.height = this._texture.baseHeight;\r\n return this._cachedBaseSize;\r\n }\r\n\r\n /** @internal */\r\n protected _initialSamplingMode = Constants.TEXTURE_BILINEAR_SAMPLINGMODE;\r\n\r\n /**\r\n * Get the current sampling mode associated with the texture.\r\n */\r\n public get samplingMode(): number {\r\n if (!this._texture) {\r\n return this._initialSamplingMode;\r\n }\r\n\r\n return this._texture.samplingMode;\r\n }\r\n\r\n /**\r\n * Update the sampling mode of the texture.\r\n * Default is Trilinear mode.\r\n *\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 1 | NEAREST_SAMPLINGMODE or NEAREST_NEAREST_MIPLINEAR | Nearest is: mag = nearest, min = nearest, mip = linear |\r\n * | 2 | BILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPNEAREST | Bilinear is: mag = linear, min = linear, mip = nearest |\r\n * | 3 | TRILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPLINEAR | Trilinear is: mag = linear, min = linear, mip = linear |\r\n * | 4 | NEAREST_NEAREST_MIPNEAREST | |\r\n * | 5 | NEAREST_LINEAR_MIPNEAREST | |\r\n * | 6 | NEAREST_LINEAR_MIPLINEAR | |\r\n * | 7 | NEAREST_LINEAR | |\r\n * | 8 | NEAREST_NEAREST | |\r\n * | 9 | LINEAR_NEAREST_MIPNEAREST | |\r\n * | 10 | LINEAR_NEAREST_MIPLINEAR | |\r\n * | 11 | LINEAR_LINEAR | |\r\n * | 12 | LINEAR_NEAREST | |\r\n *\r\n * > _mag_: magnification filter (close to the viewer)\r\n * > _min_: minification filter (far from the viewer)\r\n * > _mip_: filter used between mip map levels\r\n *@param samplingMode Define the new sampling mode of the texture\r\n */\r\n public updateSamplingMode(samplingMode: number): void {\r\n if (this._texture && this._engine) {\r\n this._engine.updateTextureSamplingMode(samplingMode, this._texture);\r\n }\r\n }\r\n\r\n /**\r\n * Release and destroy the underlying lower level texture aka internalTexture.\r\n */\r\n public releaseInternalTexture(): void {\r\n if (this._texture) {\r\n this._texture.dispose();\r\n this._texture = null;\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n if (this._texture) {\r\n this.releaseInternalTexture();\r\n this._engine = null;\r\n }\r\n }\r\n}\r\n","import { serialize, SerializationHelper, serializeAsTexture } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\nimport { RandomGUID } from \"../../Misc/guid\";\r\n\r\nimport \"../../Misc/fileTools\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { ThinTexture } from \"./thinTexture\";\r\nimport type { AbstractScene } from \"../../abstractScene\";\r\n\r\nimport type { Animation } from \"../../Animations/animation\";\r\n\r\n/**\r\n * Base class of all the textures in babylon.\r\n * It groups all the common properties the materials, post process, lights... might need\r\n * in order to make a correct use of the texture.\r\n */\r\nexport class BaseTexture extends ThinTexture implements IAnimatable {\r\n /**\r\n * Default anisotropic filtering level for the application.\r\n * It is set to 4 as a good tradeoff between perf and quality.\r\n */\r\n public static DEFAULT_ANISOTROPIC_FILTERING_LEVEL = 4;\r\n\r\n /**\r\n * Gets or sets the unique id of the texture\r\n */\r\n @serialize()\r\n public uniqueId: number;\r\n\r\n /**\r\n * Define the name of the texture.\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Gets or sets an object used to store user defined information.\r\n */\r\n @serialize()\r\n public metadata: any = null;\r\n\r\n /** @internal */\r\n public _internalMetadata: any;\r\n\r\n /**\r\n * For internal use only. Please do not use.\r\n */\r\n public reservedDataStore: any = null;\r\n\r\n @serialize(\"hasAlpha\")\r\n private _hasAlpha = false;\r\n /**\r\n * Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).\r\n */\r\n public set hasAlpha(value: boolean) {\r\n if (this._hasAlpha === value) {\r\n return;\r\n }\r\n this._hasAlpha = value;\r\n if (this._scene) {\r\n this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => {\r\n return mat.hasTexture(this);\r\n });\r\n }\r\n }\r\n public get hasAlpha(): boolean {\r\n return this._hasAlpha;\r\n }\r\n\r\n @serialize(\"getAlphaFromRGB\")\r\n private _getAlphaFromRGB = false;\r\n /**\r\n * Defines if the alpha value should be determined via the rgb values.\r\n * If true the luminance of the pixel might be used to find the corresponding alpha value.\r\n */\r\n public set getAlphaFromRGB(value: boolean) {\r\n if (this._getAlphaFromRGB === value) {\r\n return;\r\n }\r\n this._getAlphaFromRGB = value;\r\n if (this._scene) {\r\n this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => {\r\n return mat.hasTexture(this);\r\n });\r\n }\r\n }\r\n public get getAlphaFromRGB(): boolean {\r\n return this._getAlphaFromRGB;\r\n }\r\n\r\n /**\r\n * Intensity or strength of the texture.\r\n * It is commonly used by materials to fine tune the intensity of the texture\r\n */\r\n @serialize()\r\n public level = 1;\r\n\r\n @serialize(\"coordinatesIndex\")\r\n protected _coordinatesIndex = 0;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the texture should try to reduce shader code if there is no UV manipulation.\r\n * (ie. when texture.getTextureMatrix().isIdentityAs3x2() returns true)\r\n */\r\n @serialize()\r\n public optimizeUVAllocation = true;\r\n\r\n /**\r\n * Define the UV channel to use starting from 0 and defaulting to 0.\r\n * This is part of the texture as textures usually maps to one uv set.\r\n */\r\n public set coordinatesIndex(value: number) {\r\n if (this._coordinatesIndex === value) {\r\n return;\r\n }\r\n this._coordinatesIndex = value;\r\n if (this._scene) {\r\n this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => {\r\n return mat.hasTexture(this);\r\n });\r\n }\r\n }\r\n public get coordinatesIndex(): number {\r\n return this._coordinatesIndex;\r\n }\r\n\r\n @serialize(\"coordinatesMode\")\r\n protected _coordinatesMode = Constants.TEXTURE_EXPLICIT_MODE;\r\n\r\n /**\r\n * How a texture is mapped.\r\n *\r\n * | Value | Type | Description |\r\n * | ----- | ----------------------------------- | ----------- |\r\n * | 0 | EXPLICIT_MODE | |\r\n * | 1 | SPHERICAL_MODE | |\r\n * | 2 | PLANAR_MODE | |\r\n * | 3 | CUBIC_MODE | |\r\n * | 4 | PROJECTION_MODE | |\r\n * | 5 | SKYBOX_MODE | |\r\n * | 6 | INVCUBIC_MODE | |\r\n * | 7 | EQUIRECTANGULAR_MODE | |\r\n * | 8 | FIXED_EQUIRECTANGULAR_MODE | |\r\n * | 9 | FIXED_EQUIRECTANGULAR_MIRRORED_MODE | |\r\n */\r\n public set coordinatesMode(value: number) {\r\n if (this._coordinatesMode === value) {\r\n return;\r\n }\r\n this._coordinatesMode = value;\r\n if (this._scene) {\r\n this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => {\r\n return mat.hasTexture(this);\r\n });\r\n }\r\n }\r\n public get coordinatesMode(): number {\r\n return this._coordinatesMode;\r\n }\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n @serialize()\r\n public get wrapU() {\r\n return this._wrapU;\r\n }\r\n public set wrapU(value: number) {\r\n this._wrapU = value;\r\n }\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n @serialize()\r\n public get wrapV() {\r\n return this._wrapV;\r\n }\r\n public set wrapV(value: number) {\r\n this._wrapV = value;\r\n }\r\n\r\n /**\r\n * | Value | Type | Description |\r\n * | ----- | ------------------ | ----------- |\r\n * | 0 | CLAMP_ADDRESSMODE | |\r\n * | 1 | WRAP_ADDRESSMODE | |\r\n * | 2 | MIRROR_ADDRESSMODE | |\r\n */\r\n @serialize()\r\n public wrapR = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n\r\n /**\r\n * With compliant hardware and browser (supporting anisotropic filtering)\r\n * this defines the level of anisotropic filtering in the texture.\r\n * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.\r\n */\r\n @serialize()\r\n public anisotropicFilteringLevel = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL;\r\n\r\n /** @internal */\r\n public _isCube = false;\r\n /**\r\n * Define if the texture is a cube texture or if false a 2d texture.\r\n */\r\n @serialize()\r\n public get isCube(): boolean {\r\n if (!this._texture) {\r\n return this._isCube;\r\n }\r\n\r\n return this._texture.isCube;\r\n }\r\n\r\n protected set isCube(value: boolean) {\r\n if (!this._texture) {\r\n this._isCube = value;\r\n } else {\r\n this._texture.isCube = value;\r\n }\r\n }\r\n\r\n /**\r\n * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.\r\n */\r\n @serialize()\r\n public get is3D(): boolean {\r\n if (!this._texture) {\r\n return false;\r\n }\r\n\r\n return this._texture.is3D;\r\n }\r\n\r\n protected set is3D(value: boolean) {\r\n if (!this._texture) {\r\n return;\r\n }\r\n\r\n this._texture.is3D = value;\r\n }\r\n\r\n /**\r\n * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.\r\n */\r\n @serialize()\r\n public get is2DArray(): boolean {\r\n if (!this._texture) {\r\n return false;\r\n }\r\n\r\n return this._texture.is2DArray;\r\n }\r\n\r\n protected set is2DArray(value: boolean) {\r\n if (!this._texture) {\r\n return;\r\n }\r\n\r\n this._texture.is2DArray = value;\r\n }\r\n\r\n private _gammaSpace = true;\r\n /**\r\n * Define if the texture contains data in gamma space (most of the png/jpg aside bump).\r\n * HDR texture are usually stored in linear space.\r\n * This only impacts the PBR and Background materials\r\n */\r\n @serialize()\r\n public get gammaSpace(): boolean {\r\n if (!this._texture) {\r\n return this._gammaSpace;\r\n } else {\r\n if (this._texture._gammaSpace === null) {\r\n this._texture._gammaSpace = this._gammaSpace;\r\n }\r\n }\r\n\r\n return this._texture._gammaSpace && !this._texture._useSRGBBuffer;\r\n }\r\n\r\n public set gammaSpace(gamma: boolean) {\r\n if (!this._texture) {\r\n if (this._gammaSpace === gamma) {\r\n return;\r\n }\r\n\r\n this._gammaSpace = gamma;\r\n } else {\r\n if (this._texture._gammaSpace === gamma) {\r\n return;\r\n }\r\n this._texture._gammaSpace = gamma;\r\n }\r\n\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /**\r\n * Gets or sets whether or not the texture contains RGBD data.\r\n */\r\n public get isRGBD(): boolean {\r\n return this._texture != null && this._texture._isRGBD;\r\n }\r\n public set isRGBD(value: boolean) {\r\n if (this._texture) {\r\n this._texture._isRGBD = value;\r\n }\r\n }\r\n\r\n /**\r\n * Is Z inverted in the texture (useful in a cube texture).\r\n */\r\n @serialize()\r\n public invertZ = false;\r\n\r\n /**\r\n * Are mip maps generated for this texture or not.\r\n */\r\n public get noMipmap(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n @serialize()\r\n public lodLevelInAlpha = false;\r\n\r\n /**\r\n * With prefiltered texture, defined the offset used during the prefiltering steps.\r\n */\r\n @serialize()\r\n public get lodGenerationOffset(): number {\r\n if (this._texture) {\r\n return this._texture._lodGenerationOffset;\r\n }\r\n\r\n return 0.0;\r\n }\r\n public set lodGenerationOffset(value: number) {\r\n if (this._texture) {\r\n this._texture._lodGenerationOffset = value;\r\n }\r\n }\r\n\r\n /**\r\n * With prefiltered texture, defined the scale used during the prefiltering steps.\r\n */\r\n @serialize()\r\n public get lodGenerationScale(): number {\r\n if (this._texture) {\r\n return this._texture._lodGenerationScale;\r\n }\r\n\r\n return 0.0;\r\n }\r\n public set lodGenerationScale(value: number) {\r\n if (this._texture) {\r\n this._texture._lodGenerationScale = value;\r\n }\r\n }\r\n\r\n /**\r\n * With prefiltered texture, defined if the specular generation is based on a linear ramp.\r\n * By default we are using a log2 of the linear roughness helping to keep a better resolution for\r\n * average roughness values.\r\n */\r\n @serialize()\r\n public get linearSpecularLOD(): boolean {\r\n if (this._texture) {\r\n return this._texture._linearSpecularLOD;\r\n }\r\n\r\n return false;\r\n }\r\n public set linearSpecularLOD(value: boolean) {\r\n if (this._texture) {\r\n this._texture._linearSpecularLOD = value;\r\n }\r\n }\r\n\r\n /**\r\n * In case a better definition than spherical harmonics is required for the diffuse part of the environment.\r\n * You can set the irradiance texture to rely on a texture instead of the spherical approach.\r\n * This texture need to have the same characteristics than its parent (Cube vs 2d, coordinates mode, Gamma/Linear, RGBD).\r\n */\r\n @serializeAsTexture()\r\n public get irradianceTexture(): Nullable {\r\n if (this._texture) {\r\n return this._texture._irradianceTexture;\r\n }\r\n\r\n return null;\r\n }\r\n public set irradianceTexture(value: Nullable) {\r\n if (this._texture) {\r\n this._texture._irradianceTexture = value;\r\n }\r\n }\r\n\r\n /**\r\n * Define if the texture is a render target.\r\n */\r\n @serialize()\r\n public isRenderTarget = false;\r\n\r\n /**\r\n * Define the unique id of the texture in the scene.\r\n */\r\n public get uid(): string {\r\n if (!this._uid) {\r\n this._uid = RandomGUID();\r\n }\r\n return this._uid;\r\n }\r\n\r\n /** @internal */\r\n public _prefiltered: boolean = false;\r\n /** @internal */\r\n public _forceSerialize: boolean = false;\r\n\r\n /**\r\n * Return a string representation of the texture.\r\n * @returns the texture as a string\r\n */\r\n public toString(): string {\r\n return this.name;\r\n }\r\n\r\n /**\r\n * Get the class name of the texture.\r\n * @returns \"BaseTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"BaseTexture\";\r\n }\r\n\r\n /**\r\n * Define the list of animation attached to the texture.\r\n */\r\n public animations = new Array();\r\n\r\n /**\r\n * An event triggered when the texture is disposed.\r\n */\r\n public onDisposeObservable = new Observable();\r\n\r\n private _onDisposeObserver: Nullable> = null;\r\n /**\r\n * Callback triggered when the texture has been disposed.\r\n * Kept for back compatibility, you can use the onDisposeObservable instead.\r\n */\r\n public set onDispose(callback: () => void) {\r\n if (this._onDisposeObserver) {\r\n this.onDisposeObservable.remove(this._onDisposeObserver);\r\n }\r\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\r\n }\r\n\r\n protected _scene: Nullable = null;\r\n\r\n /** @internal */\r\n private _uid: Nullable = null;\r\n\r\n /**\r\n * Define if the texture is preventing a material to render or not.\r\n * If not and the texture is not ready, the engine will use a default black texture instead.\r\n */\r\n public get isBlocking(): boolean {\r\n return true;\r\n }\r\n\r\n /** @internal */\r\n public _parentContainer: Nullable = null;\r\n\r\n protected _loadingError: boolean = false;\r\n protected _errorObject?: {\r\n message?: string;\r\n exception?: any;\r\n };\r\n\r\n /**\r\n * Was there any loading error?\r\n */\r\n public get loadingError(): boolean {\r\n return this._loadingError;\r\n }\r\n\r\n /**\r\n * If a loading error occurred this object will be populated with information about the error.\r\n */\r\n public get errorObject():\r\n | {\r\n message?: string;\r\n exception?: any;\r\n }\r\n | undefined {\r\n return this._errorObject;\r\n }\r\n\r\n /**\r\n * Instantiates a new BaseTexture.\r\n * Base class of all the textures in babylon.\r\n * It groups all the common properties the materials, post process, lights... might need\r\n * in order to make a correct use of the texture.\r\n * @param sceneOrEngine Define the scene or engine the texture belongs to\r\n * @param internalTexture Define the internal texture associated with the texture\r\n */\r\n constructor(sceneOrEngine?: Nullable, internalTexture: Nullable = null) {\r\n super(null);\r\n\r\n if (sceneOrEngine) {\r\n if (BaseTexture._IsScene(sceneOrEngine)) {\r\n this._scene = sceneOrEngine;\r\n } else {\r\n this._engine = sceneOrEngine;\r\n }\r\n } else {\r\n this._scene = EngineStore.LastCreatedScene;\r\n }\r\n\r\n if (this._scene) {\r\n this.uniqueId = this._scene.getUniqueId();\r\n this._scene.addTexture(this);\r\n this._engine = this._scene.getEngine();\r\n }\r\n\r\n this._texture = internalTexture;\r\n\r\n this._uid = null;\r\n }\r\n\r\n /**\r\n * Get the scene the texture belongs to.\r\n * @returns the scene or null if undefined\r\n */\r\n public getScene(): Nullable {\r\n return this._scene;\r\n }\r\n\r\n /** @internal */\r\n protected _getEngine(): Nullable {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * Checks if the texture has the same transform matrix than another texture\r\n * @param texture texture to check against\r\n * @returns true if the transforms are the same, else false\r\n */\r\n public checkTransformsAreIdentical(texture: Nullable): boolean {\r\n return texture !== null;\r\n }\r\n\r\n /**\r\n * Get the texture transform matrix used to offset tile the texture for instance.\r\n * @returns the transformation matrix\r\n */\r\n public getTextureMatrix(): Matrix {\r\n return Matrix.IdentityReadOnly;\r\n }\r\n\r\n /**\r\n * Get the texture reflection matrix used to rotate/transform the reflection.\r\n * @returns the reflection matrix\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n return Matrix.IdentityReadOnly;\r\n }\r\n\r\n /**\r\n * Gets a suitable rotate/transform matrix when the texture is used for refraction.\r\n * There's a separate function from getReflectionTextureMatrix because refraction requires a special configuration of the matrix in right-handed mode.\r\n * @returns The refraction matrix\r\n */\r\n public getRefractionTextureMatrix(): Matrix {\r\n return this.getReflectionTextureMatrix();\r\n }\r\n\r\n /**\r\n * Get if the texture is ready to be consumed (either it is ready or it is not blocking)\r\n * @returns true if ready, not blocking or if there was an error loading the texture\r\n */\r\n public isReadyOrNotBlocking(): boolean {\r\n return !this.isBlocking || this.isReady() || this.loadingError;\r\n }\r\n\r\n /**\r\n * Scales the texture if is `canRescale()`\r\n * @param ratio the resize factor we want to use to rescale\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public scale(ratio: number): void {}\r\n\r\n /**\r\n * Get if the texture can rescale.\r\n */\r\n public get canRescale(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getFromCache(url: Nullable, noMipmap: boolean, sampling?: number, invertY?: boolean, useSRGBBuffer?: boolean, isCube?: boolean): Nullable {\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return null;\r\n }\r\n\r\n const correctedUseSRGBBuffer = engine._getUseSRGBBuffer(!!useSRGBBuffer, noMipmap);\r\n\r\n const texturesCache = engine.getLoadedTexturesCache();\r\n for (let index = 0; index < texturesCache.length; index++) {\r\n const texturesCacheEntry = texturesCache[index];\r\n\r\n if (useSRGBBuffer === undefined || correctedUseSRGBBuffer === texturesCacheEntry._useSRGBBuffer) {\r\n if (invertY === undefined || invertY === texturesCacheEntry.invertY) {\r\n if (texturesCacheEntry.url === url && texturesCacheEntry.generateMipMaps === !noMipmap) {\r\n if (!sampling || sampling === texturesCacheEntry.samplingMode) {\r\n if (isCube === undefined || isCube === texturesCacheEntry.isCube) {\r\n texturesCacheEntry.incrementReferences();\r\n return texturesCacheEntry;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {}\r\n\r\n /**\r\n * Clones the texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): Nullable {\r\n return null;\r\n }\r\n\r\n /**\r\n * Get the texture underlying type (INT, FLOAT...)\r\n */\r\n public get textureType(): number {\r\n if (!this._texture) {\r\n return Constants.TEXTURETYPE_UNSIGNED_INT;\r\n }\r\n\r\n return this._texture.type !== undefined ? this._texture.type : Constants.TEXTURETYPE_UNSIGNED_INT;\r\n }\r\n\r\n /**\r\n * Get the texture underlying format (RGB, RGBA...)\r\n */\r\n public get textureFormat(): number {\r\n if (!this._texture) {\r\n return Constants.TEXTUREFORMAT_RGBA;\r\n }\r\n\r\n return this._texture.format !== undefined ? this._texture.format : Constants.TEXTUREFORMAT_RGBA;\r\n }\r\n\r\n /**\r\n * Indicates that textures need to be re-calculated for all materials\r\n */\r\n protected _markAllSubMeshesAsTexturesDirty() {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n /**\r\n * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.\r\n * This will returns an RGBA array buffer containing either in values (0-255) or\r\n * float values (0-1) depending of the underlying buffer type.\r\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\r\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\r\n * @param buffer defines a user defined buffer to fill with data (can be null)\r\n * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels\r\n * @param noDataConversion false to convert the data to Uint8Array (if texture type is UNSIGNED_BYTE) or to Float32Array (if texture type is anything but UNSIGNED_BYTE). If true, the type of the generated buffer (if buffer==null) will depend on the type of the texture\r\n * @param x defines the region x coordinates to start reading from (default to 0)\r\n * @param y defines the region y coordinates to start reading from (default to 0)\r\n * @param width defines the region width to read from (default to the texture size at level)\r\n * @param height defines the region width to read from (default to the texture size at level)\r\n * @returns The Array buffer promise containing the pixels data.\r\n */\r\n public readPixels(\r\n faceIndex = 0,\r\n level = 0,\r\n buffer: Nullable = null,\r\n flushRenderer = true,\r\n noDataConversion = false,\r\n x = 0,\r\n y = 0,\r\n width = Number.MAX_VALUE,\r\n height = Number.MAX_VALUE\r\n ): Nullable> {\r\n if (!this._texture) {\r\n return null;\r\n }\r\n\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return null;\r\n }\r\n\r\n const size = this.getSize();\r\n let maxWidth = size.width;\r\n let maxHeight = size.height;\r\n if (level !== 0) {\r\n maxWidth = maxWidth / Math.pow(2, level);\r\n maxHeight = maxHeight / Math.pow(2, level);\r\n maxWidth = Math.round(maxWidth);\r\n maxHeight = Math.round(maxHeight);\r\n }\r\n\r\n width = Math.min(maxWidth, width);\r\n height = Math.min(maxHeight, height);\r\n\r\n try {\r\n if (this._texture.isCube) {\r\n return engine._readTexturePixels(this._texture, width, height, faceIndex, level, buffer, flushRenderer, noDataConversion, x, y);\r\n }\r\n\r\n return engine._readTexturePixels(this._texture, width, height, -1, level, buffer, flushRenderer, noDataConversion, x, y);\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _readPixelsSync(faceIndex = 0, level = 0, buffer: Nullable = null, flushRenderer = true, noDataConversion = false): Nullable {\r\n if (!this._texture) {\r\n return null;\r\n }\r\n\r\n const size = this.getSize();\r\n let width = size.width;\r\n let height = size.height;\r\n\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return null;\r\n }\r\n\r\n if (level != 0) {\r\n width = width / Math.pow(2, level);\r\n height = height / Math.pow(2, level);\r\n\r\n width = Math.round(width);\r\n height = Math.round(height);\r\n }\r\n\r\n try {\r\n if (this._texture.isCube) {\r\n return engine._readTexturePixelsSync(this._texture, width, height, faceIndex, level, buffer, flushRenderer, noDataConversion);\r\n }\r\n\r\n return engine._readTexturePixelsSync(this._texture, width, height, -1, level, buffer, flushRenderer, noDataConversion);\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public get _lodTextureHigh(): Nullable {\r\n if (this._texture) {\r\n return this._texture._lodTextureHigh;\r\n }\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n public get _lodTextureMid(): Nullable {\r\n if (this._texture) {\r\n return this._texture._lodTextureMid;\r\n }\r\n return null;\r\n }\r\n\r\n /** @internal */\r\n public get _lodTextureLow(): Nullable {\r\n if (this._texture) {\r\n return this._texture._lodTextureLow;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n if (this._scene) {\r\n // Animations\r\n if (this._scene.stopAnimation) {\r\n this._scene.stopAnimation(this);\r\n }\r\n\r\n // Remove from scene\r\n this._scene.removePendingData(this);\r\n const index = this._scene.textures.indexOf(this);\r\n\r\n if (index >= 0) {\r\n this._scene.textures.splice(index, 1);\r\n }\r\n this._scene.onTextureRemovedObservable.notifyObservers(this);\r\n this._scene = null;\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.textures.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.textures.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n }\r\n\r\n // Callback\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n\r\n this.metadata = null;\r\n\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Serialize the texture into a JSON representation that can be parsed later on.\r\n * @param allowEmptyName True to force serialization even if name is empty. Default: false\r\n * @returns the JSON representation of the texture\r\n */\r\n public serialize(allowEmptyName = false): any {\r\n if (!this.name && !allowEmptyName) {\r\n return null;\r\n }\r\n\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Helper function to be called back once a list of texture contains only ready textures.\r\n * @param textures Define the list of textures to wait for\r\n * @param callback Define the callback triggered once the entire list will be ready\r\n */\r\n public static WhenAllReady(textures: BaseTexture[], callback: () => void): void {\r\n let numRemaining = textures.length;\r\n if (numRemaining === 0) {\r\n callback();\r\n return;\r\n }\r\n\r\n for (let i = 0; i < textures.length; i++) {\r\n const texture = textures[i];\r\n\r\n if (texture.isReady()) {\r\n if (--numRemaining === 0) {\r\n callback();\r\n }\r\n } else {\r\n const onLoadObservable = (texture as any).onLoadObservable as Observable;\r\n\r\n if (onLoadObservable) {\r\n onLoadObservable.addOnce(() => {\r\n if (--numRemaining === 0) {\r\n callback();\r\n }\r\n });\r\n } else {\r\n if (--numRemaining === 0) {\r\n callback();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private static _IsScene(sceneOrEngine: Scene | ThinEngine): sceneOrEngine is Scene {\r\n return sceneOrEngine.getClassName() === \"Scene\";\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { ISize } from \"../Maths/math.size\";\r\nimport type { Nullable } from \"../types\";\r\n\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\n\r\n/**\r\n * Transform some pixel data to a base64 string\r\n * @param pixels defines the pixel data to transform to base64\r\n * @param size defines the width and height of the (texture) data\r\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\r\n * @returns The base64 encoded string or null\r\n */\r\nexport function GenerateBase64StringFromPixelData(pixels: ArrayBufferView, size: ISize, invertY = false): Nullable {\r\n const width = size.width;\r\n const height = size.height;\r\n\r\n if (pixels instanceof Float32Array) {\r\n let len = pixels.byteLength / pixels.BYTES_PER_ELEMENT;\r\n const npixels = new Uint8Array(len);\r\n\r\n while (--len >= 0) {\r\n let val = pixels[len];\r\n if (val < 0) {\r\n val = 0;\r\n } else if (val > 1) {\r\n val = 1;\r\n }\r\n npixels[len] = val * 255;\r\n }\r\n\r\n pixels = npixels;\r\n }\r\n\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = width;\r\n canvas.height = height;\r\n\r\n const ctx = canvas.getContext(\"2d\");\r\n if (!ctx) {\r\n return null;\r\n }\r\n\r\n const imageData = ctx.createImageData(width, height);\r\n const castData = imageData.data;\r\n castData.set(pixels);\r\n ctx.putImageData(imageData, 0, 0);\r\n\r\n if (invertY) {\r\n const canvas2 = document.createElement(\"canvas\");\r\n canvas2.width = width;\r\n canvas2.height = height;\r\n\r\n const ctx2 = canvas2.getContext(\"2d\");\r\n if (!ctx2) {\r\n return null;\r\n }\r\n\r\n ctx2.translate(0, height);\r\n ctx2.scale(1, -1);\r\n ctx2.drawImage(canvas, 0, 0);\r\n\r\n return canvas2.toDataURL(\"image/png\");\r\n }\r\n\r\n return canvas.toDataURL(\"image/png\");\r\n}\r\n\r\n/**\r\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\r\n * @param texture defines the texture to read pixels from\r\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\r\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\r\n * @returns The base64 encoded string or null\r\n */\r\nexport function GenerateBase64StringFromTexture(texture: BaseTexture, faceIndex = 0, level = 0): Nullable {\r\n const internalTexture = texture.getInternalTexture();\r\n if (!internalTexture) {\r\n return null;\r\n }\r\n\r\n const pixels = texture._readPixelsSync(faceIndex, level);\r\n if (!pixels) {\r\n return null;\r\n }\r\n\r\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\r\n}\r\n\r\n/**\r\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\r\n * @param texture defines the texture to read pixels from\r\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\r\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\r\n * @returns The base64 encoded string or null wrapped in a promise\r\n */\r\nexport async function GenerateBase64StringFromTextureAsync(texture: BaseTexture, faceIndex = 0, level = 0): Promise> {\r\n const internalTexture = texture.getInternalTexture();\r\n if (!internalTexture) {\r\n return null;\r\n }\r\n\r\n const pixels = await texture.readPixels(faceIndex, level);\r\n if (!pixels) {\r\n return null;\r\n }\r\n\r\n return GenerateBase64StringFromPixelData(pixels, texture.getSize(), internalTexture.invertY);\r\n}\r\n\r\n/**\r\n * Class used to host copy specific utilities\r\n * (Back-compat)\r\n */\r\nexport const CopyTools = {\r\n /**\r\n * Transform some pixel data to a base64 string\r\n * @param pixels defines the pixel data to transform to base64\r\n * @param size defines the width and height of the (texture) data\r\n * @param invertY true if the data must be inverted for the Y coordinate during the conversion\r\n * @returns The base64 encoded string or null\r\n */\r\n GenerateBase64StringFromPixelData,\r\n\r\n /**\r\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\r\n * @param texture defines the texture to read pixels from\r\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\r\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\r\n * @returns The base64 encoded string or null\r\n */\r\n GenerateBase64StringFromTexture,\r\n\r\n /**\r\n * Reads the pixels stored in the webgl texture and returns them as a base64 string\r\n * @param texture defines the texture to read pixels from\r\n * @param faceIndex defines the face of the texture to read (in case of cube texture)\r\n * @param level defines the LOD level of the texture to read (in case of Mip Maps)\r\n * @returns The base64 encoded string or null wrapped in a promise\r\n */\r\n GenerateBase64StringFromTextureAsync,\r\n};\r\n","import { serialize, SerializationHelper } from \"../../Misc/decorators\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Matrix, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { GetClass, RegisterClass } from \"../../Misc/typeStore\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport type { IInspectable } from \"../../Misc/iInspectable\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { TimingTools } from \"../../Misc/timingTools\";\r\nimport { InstantiationTools } from \"../../Misc/instantiationTools\";\r\nimport { Plane } from \"../../Maths/math.plane\";\r\nimport { EncodeArrayBufferToBase64 } from \"../../Misc/stringTools\";\r\nimport { GenerateBase64StringFromTexture, GenerateBase64StringFromTextureAsync } from \"../../Misc/copyTools\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\nimport type { InternalTexture } from \"./internalTexture\";\r\n\r\nimport type { CubeTexture } from \"../../Materials/Textures/cubeTexture\";\r\nimport type { MirrorTexture } from \"../../Materials/Textures/mirrorTexture\";\r\nimport type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Defines the available options when creating a texture\r\n */\r\nexport interface ITextureCreationOptions {\r\n /** Defines if the texture will require mip maps or not (default: false) */\r\n noMipmap?: boolean;\r\n\r\n /** Defines if the texture needs to be inverted on the y axis during loading (default: true) */\r\n invertY?: boolean;\r\n\r\n /** Defines the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...) (default: Texture.TRILINEAR_SAMPLINGMODE) */\r\n samplingMode?: number;\r\n\r\n /** Defines a callback triggered when the texture has been loaded (default: null) */\r\n onLoad?: Nullable<() => void>;\r\n\r\n /** Defines a callback triggered when an error occurred during the loading session (default: null) */\r\n onError?: Nullable<(message?: string, exception?: any) => void>;\r\n\r\n /** Defines the buffer to load the texture from in case the texture is loaded from a buffer representation (default: null) */\r\n buffer?: Nullable;\r\n\r\n /** Defines if the buffer we are loading the texture from should be deleted after load (default: false) */\r\n deleteBuffer?: boolean;\r\n\r\n /** Defines the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...) (default: ) */\r\n format?: number;\r\n\r\n /** Defines an optional mime type information (default: undefined) */\r\n mimeType?: string;\r\n\r\n /** Options to be passed to the loader (default: undefined) */\r\n loaderOptions?: any;\r\n\r\n /** Specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg) (default: undefined) */\r\n creationFlags?: number;\r\n\r\n /** Defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU) (default: false) */\r\n useSRGBBuffer?: boolean;\r\n\r\n /** Defines the underlying texture from an already existing one */\r\n internalTexture?: InternalTexture;\r\n}\r\n\r\n/**\r\n * This represents a texture in babylon. It can be easily loaded from a network, base64 or html input.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#texture\r\n */\r\nexport class Texture extends BaseTexture {\r\n /**\r\n * Gets or sets a general boolean used to indicate that textures containing direct data (buffers) must be saved as part of the serialization process\r\n */\r\n public static SerializeBuffers = true;\r\n\r\n /**\r\n * Gets or sets a general boolean used to indicate that texture buffers must be saved as part of the serialization process.\r\n * If no buffer exists, one will be created as base64 string from the internal webgl data.\r\n */\r\n public static ForceSerializeBuffers = false;\r\n\r\n /**\r\n * This observable will notify when any texture had a loading error\r\n */\r\n public static OnTextureLoadErrorObservable = new Observable();\r\n\r\n /** @internal */\r\n public static _SerializeInternalTextureUniqueId = false;\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _CubeTextureParser = (jsonTexture: any, scene: Scene, rootUrl: string): CubeTexture => {\r\n throw _WarnImport(\"CubeTexture\");\r\n };\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _CreateMirror = (name: string, renderTargetSize: number, scene: Scene, generateMipMaps: boolean): MirrorTexture => {\r\n throw _WarnImport(\"MirrorTexture\");\r\n };\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _CreateRenderTargetTexture = (name: string, renderTargetSize: number, scene: Scene, generateMipMaps: boolean, creationFlags?: number): RenderTargetTexture => {\r\n throw _WarnImport(\"RenderTargetTexture\");\r\n };\r\n\r\n /** nearest is mag = nearest and min = nearest and no mip */\r\n public static readonly NEAREST_SAMPLINGMODE = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n /** nearest is mag = nearest and min = nearest and mip = linear */\r\n public static readonly NEAREST_NEAREST_MIPLINEAR = Constants.TEXTURE_NEAREST_NEAREST_MIPLINEAR; // nearest is mag = nearest and min = nearest and mip = linear\r\n\r\n /** Bilinear is mag = linear and min = linear and no mip */\r\n public static readonly BILINEAR_SAMPLINGMODE = Constants.TEXTURE_BILINEAR_SAMPLINGMODE;\r\n /** Bilinear is mag = linear and min = linear and mip = nearest */\r\n public static readonly LINEAR_LINEAR_MIPNEAREST = Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST; // Bilinear is mag = linear and min = linear and mip = nearest\r\n\r\n /** Trilinear is mag = linear and min = linear and mip = linear */\r\n public static readonly TRILINEAR_SAMPLINGMODE = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;\r\n /** Trilinear is mag = linear and min = linear and mip = linear */\r\n public static readonly LINEAR_LINEAR_MIPLINEAR = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR; // Trilinear is mag = linear and min = linear and mip = linear\r\n\r\n /** mag = nearest and min = nearest and mip = nearest */\r\n public static readonly NEAREST_NEAREST_MIPNEAREST = Constants.TEXTURE_NEAREST_NEAREST_MIPNEAREST;\r\n /** mag = nearest and min = linear and mip = nearest */\r\n public static readonly NEAREST_LINEAR_MIPNEAREST = Constants.TEXTURE_NEAREST_LINEAR_MIPNEAREST;\r\n /** mag = nearest and min = linear and mip = linear */\r\n public static readonly NEAREST_LINEAR_MIPLINEAR = Constants.TEXTURE_NEAREST_LINEAR_MIPLINEAR;\r\n /** mag = nearest and min = linear and mip = none */\r\n public static readonly NEAREST_LINEAR = Constants.TEXTURE_NEAREST_LINEAR;\r\n /** mag = nearest and min = nearest and mip = none */\r\n public static readonly NEAREST_NEAREST = Constants.TEXTURE_NEAREST_NEAREST;\r\n /** mag = linear and min = nearest and mip = nearest */\r\n public static readonly LINEAR_NEAREST_MIPNEAREST = Constants.TEXTURE_LINEAR_NEAREST_MIPNEAREST;\r\n /** mag = linear and min = nearest and mip = linear */\r\n public static readonly LINEAR_NEAREST_MIPLINEAR = Constants.TEXTURE_LINEAR_NEAREST_MIPLINEAR;\r\n /** mag = linear and min = linear and mip = none */\r\n public static readonly LINEAR_LINEAR = Constants.TEXTURE_LINEAR_LINEAR;\r\n /** mag = linear and min = nearest and mip = none */\r\n public static readonly LINEAR_NEAREST = Constants.TEXTURE_LINEAR_NEAREST;\r\n\r\n /** Explicit coordinates mode */\r\n public static readonly EXPLICIT_MODE = Constants.TEXTURE_EXPLICIT_MODE;\r\n /** Spherical coordinates mode */\r\n public static readonly SPHERICAL_MODE = Constants.TEXTURE_SPHERICAL_MODE;\r\n /** Planar coordinates mode */\r\n public static readonly PLANAR_MODE = Constants.TEXTURE_PLANAR_MODE;\r\n /** Cubic coordinates mode */\r\n public static readonly CUBIC_MODE = Constants.TEXTURE_CUBIC_MODE;\r\n /** Projection coordinates mode */\r\n public static readonly PROJECTION_MODE = Constants.TEXTURE_PROJECTION_MODE;\r\n /** Inverse Cubic coordinates mode */\r\n public static readonly SKYBOX_MODE = Constants.TEXTURE_SKYBOX_MODE;\r\n /** Inverse Cubic coordinates mode */\r\n public static readonly INVCUBIC_MODE = Constants.TEXTURE_INVCUBIC_MODE;\r\n /** Equirectangular coordinates mode */\r\n public static readonly EQUIRECTANGULAR_MODE = Constants.TEXTURE_EQUIRECTANGULAR_MODE;\r\n /** Equirectangular Fixed coordinates mode */\r\n public static readonly FIXED_EQUIRECTANGULAR_MODE = Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MODE;\r\n /** Equirectangular Fixed Mirrored coordinates mode */\r\n public static readonly FIXED_EQUIRECTANGULAR_MIRRORED_MODE = Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE;\r\n\r\n /** Texture is not repeating outside of 0..1 UVs */\r\n public static readonly CLAMP_ADDRESSMODE = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n /** Texture is repeating outside of 0..1 UVs */\r\n public static readonly WRAP_ADDRESSMODE = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n /** Texture is repeating and mirrored */\r\n public static readonly MIRROR_ADDRESSMODE = Constants.TEXTURE_MIRROR_ADDRESSMODE;\r\n\r\n /**\r\n * Gets or sets a boolean which defines if the texture url must be build from the serialized URL instead of just using the name and loading them side by side with the scene file\r\n */\r\n public static UseSerializedUrlIfAny = false;\r\n\r\n /**\r\n * Define the url of the texture.\r\n */\r\n @serialize()\r\n public url: Nullable = null;\r\n\r\n /**\r\n * Define an offset on the texture to offset the u coordinates of the UVs\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#offsetting\r\n */\r\n @serialize()\r\n public uOffset = 0;\r\n\r\n /**\r\n * Define an offset on the texture to offset the v coordinates of the UVs\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#offsetting\r\n */\r\n @serialize()\r\n public vOffset = 0;\r\n\r\n /**\r\n * Define an offset on the texture to scale the u coordinates of the UVs\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#tiling\r\n */\r\n @serialize()\r\n public uScale = 1.0;\r\n\r\n /**\r\n * Define an offset on the texture to scale the v coordinates of the UVs\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#tiling\r\n */\r\n @serialize()\r\n public vScale = 1.0;\r\n\r\n /**\r\n * Define an offset on the texture to rotate around the u coordinates of the UVs\r\n * The angle is defined in radians.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials\r\n */\r\n @serialize()\r\n public uAng = 0;\r\n\r\n /**\r\n * Define an offset on the texture to rotate around the v coordinates of the UVs\r\n * The angle is defined in radians.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials\r\n */\r\n @serialize()\r\n public vAng = 0;\r\n\r\n /**\r\n * Define an offset on the texture to rotate around the w coordinates of the UVs (in case of 3d texture)\r\n * The angle is defined in radians.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials\r\n */\r\n @serialize()\r\n public wAng = 0;\r\n\r\n /**\r\n * Defines the center of rotation (U)\r\n */\r\n @serialize()\r\n public uRotationCenter = 0.5;\r\n\r\n /**\r\n * Defines the center of rotation (V)\r\n */\r\n @serialize()\r\n public vRotationCenter = 0.5;\r\n\r\n /**\r\n * Defines the center of rotation (W)\r\n */\r\n @serialize()\r\n public wRotationCenter = 0.5;\r\n\r\n /**\r\n * Sets this property to true to avoid deformations when rotating the texture with non-uniform scaling\r\n */\r\n @serialize()\r\n public homogeneousRotationInUVTransform = false;\r\n\r\n /**\r\n * Are mip maps generated for this texture or not.\r\n */\r\n get noMipmap(): boolean {\r\n return this._noMipmap;\r\n }\r\n\r\n /**\r\n * List of inspectable custom properties (used by the Inspector)\r\n * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility\r\n */\r\n public inspectableCustomProperties: Nullable = null;\r\n\r\n /** @internal */\r\n public _noMipmap: boolean = false;\r\n /** @internal */\r\n public _invertY: boolean = false;\r\n private _rowGenerationMatrix: Nullable = null;\r\n private _cachedTextureMatrix: Nullable = null;\r\n private _projectionModeMatrix: Nullable = null;\r\n private _t0: Nullable = null;\r\n private _t1: Nullable = null;\r\n private _t2: Nullable = null;\r\n\r\n private _cachedUOffset: number = -1;\r\n private _cachedVOffset: number = -1;\r\n private _cachedUScale: number = 0;\r\n private _cachedVScale: number = 0;\r\n private _cachedUAng: number = -1;\r\n private _cachedVAng: number = -1;\r\n private _cachedWAng: number = -1;\r\n private _cachedReflectionProjectionMatrixId: number = -1;\r\n private _cachedURotationCenter: number = -1;\r\n private _cachedVRotationCenter: number = -1;\r\n private _cachedWRotationCenter: number = -1;\r\n private _cachedHomogeneousRotationInUVTransform: boolean = false;\r\n\r\n private _cachedReflectionTextureMatrix: Nullable = null;\r\n private _cachedReflectionUOffset = -1;\r\n private _cachedReflectionVOffset = -1;\r\n private _cachedReflectionUScale = 0;\r\n private _cachedReflectionVScale = 0;\r\n private _cachedReflectionCoordinatesMode = -1;\r\n\r\n /** @internal */\r\n public _buffer: Nullable = null;\r\n private _deleteBuffer: boolean = false;\r\n protected _format: Nullable = null;\r\n private _delayedOnLoad: Nullable<() => void> = null;\r\n private _delayedOnError: Nullable<() => void> = null;\r\n private _mimeType?: string;\r\n private _loaderOptions?: any;\r\n private _creationFlags?: number;\r\n /** @internal */\r\n public _useSRGBBuffer?: boolean;\r\n private _forcedExtension?: string;\r\n\r\n /** Returns the texture mime type if it was defined by a loader (undefined else) */\r\n public get mimeType() {\r\n return this._mimeType;\r\n }\r\n\r\n /**\r\n * Observable triggered once the texture has been loaded.\r\n */\r\n public onLoadObservable: Observable = new Observable();\r\n\r\n protected _isBlocking: boolean = true;\r\n /**\r\n * Is the texture preventing material to render while loading.\r\n * If false, a default texture will be used instead of the loading one during the preparation step.\r\n */\r\n public set isBlocking(value: boolean) {\r\n this._isBlocking = value;\r\n }\r\n @serialize()\r\n public get isBlocking(): boolean {\r\n return this._isBlocking;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the texture needs to be inverted on the y axis during loading\r\n */\r\n public get invertY(): boolean {\r\n return this._invertY;\r\n }\r\n\r\n /**\r\n * Instantiates a new texture.\r\n * This represents a texture in babylon. It can be easily loaded from a network, base64 or html input.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#texture\r\n * @param url defines the url of the picture to load as a texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param noMipmapOrOptions defines if the texture will require mip maps or not or set of all options to create the texture\r\n * @param invertY defines if the texture needs to be inverted on the y axis during loading\r\n * @param samplingMode defines the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)\r\n * @param onLoad defines a callback triggered when the texture has been loaded\r\n * @param onError defines a callback triggered when an error occurred during the loading session\r\n * @param buffer defines the buffer to load the texture from in case the texture is loaded from a buffer representation\r\n * @param deleteBuffer defines if the buffer we are loading the texture from should be deleted after load\r\n * @param format defines the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)\r\n * @param mimeType defines an optional mime type information\r\n * @param loaderOptions options to be passed to the loader\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n */\r\n constructor(\r\n url: Nullable,\r\n sceneOrEngine?: Nullable,\r\n noMipmapOrOptions?: boolean | ITextureCreationOptions,\r\n invertY?: boolean,\r\n samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n buffer: Nullable = null,\r\n deleteBuffer: boolean = false,\r\n format?: number,\r\n mimeType?: string,\r\n loaderOptions?: any,\r\n creationFlags?: number,\r\n forcedExtension?: string\r\n ) {\r\n super(sceneOrEngine);\r\n\r\n this.name = url || \"\";\r\n this.url = url;\r\n\r\n let noMipmap: boolean;\r\n let useSRGBBuffer: boolean = false;\r\n let internalTexture: Nullable = null;\r\n\r\n if (typeof noMipmapOrOptions === \"object\" && noMipmapOrOptions !== null) {\r\n noMipmap = noMipmapOrOptions.noMipmap ?? false;\r\n invertY = noMipmapOrOptions.invertY ?? (CompatibilityOptions.UseOpenGLOrientationForUV ? false : true);\r\n samplingMode = noMipmapOrOptions.samplingMode ?? Texture.TRILINEAR_SAMPLINGMODE;\r\n onLoad = noMipmapOrOptions.onLoad ?? null;\r\n onError = noMipmapOrOptions.onError ?? null;\r\n buffer = noMipmapOrOptions.buffer ?? null;\r\n deleteBuffer = noMipmapOrOptions.deleteBuffer ?? false;\r\n format = noMipmapOrOptions.format;\r\n mimeType = noMipmapOrOptions.mimeType;\r\n loaderOptions = noMipmapOrOptions.loaderOptions;\r\n creationFlags = noMipmapOrOptions.creationFlags;\r\n useSRGBBuffer = noMipmapOrOptions.useSRGBBuffer ?? false;\r\n internalTexture = noMipmapOrOptions.internalTexture ?? null;\r\n } else {\r\n noMipmap = !!noMipmapOrOptions;\r\n }\r\n\r\n this._noMipmap = noMipmap;\r\n this._invertY = invertY === undefined ? (CompatibilityOptions.UseOpenGLOrientationForUV ? false : true) : invertY;\r\n this._initialSamplingMode = samplingMode;\r\n this._buffer = buffer;\r\n this._deleteBuffer = deleteBuffer;\r\n this._mimeType = mimeType;\r\n this._loaderOptions = loaderOptions;\r\n this._creationFlags = creationFlags;\r\n this._useSRGBBuffer = useSRGBBuffer;\r\n this._forcedExtension = forcedExtension;\r\n if (format) {\r\n this._format = format;\r\n }\r\n\r\n const scene = this.getScene();\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return;\r\n }\r\n\r\n engine.onBeforeTextureInitObservable.notifyObservers(this);\r\n\r\n const load = () => {\r\n if (this._texture) {\r\n if (this._texture._invertVScale) {\r\n this.vScale *= -1;\r\n this.vOffset += 1;\r\n }\r\n\r\n // Update texture to match internal texture's wrapping\r\n if (this._texture._cachedWrapU !== null) {\r\n this.wrapU = this._texture._cachedWrapU;\r\n this._texture._cachedWrapU = null;\r\n }\r\n if (this._texture._cachedWrapV !== null) {\r\n this.wrapV = this._texture._cachedWrapV;\r\n this._texture._cachedWrapV = null;\r\n }\r\n if (this._texture._cachedWrapR !== null) {\r\n this.wrapR = this._texture._cachedWrapR;\r\n this._texture._cachedWrapR = null;\r\n }\r\n }\r\n\r\n if (this.onLoadObservable.hasObservers()) {\r\n this.onLoadObservable.notifyObservers(this);\r\n }\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n\r\n if (!this.isBlocking && scene) {\r\n scene.resetCachedMaterial();\r\n }\r\n };\r\n\r\n const errorHandler = (message?: string, exception?: any) => {\r\n this._loadingError = true;\r\n this._errorObject = { message, exception };\r\n if (onError) {\r\n onError(message, exception);\r\n }\r\n Texture.OnTextureLoadErrorObservable.notifyObservers(this);\r\n };\r\n\r\n if (!this.url && !internalTexture) {\r\n this._delayedOnLoad = load;\r\n this._delayedOnError = errorHandler;\r\n return;\r\n }\r\n\r\n this._texture = internalTexture ?? this._getFromCache(this.url, noMipmap, samplingMode, this._invertY, useSRGBBuffer);\r\n\r\n if (!this._texture) {\r\n if (!scene || !scene.useDelayedTextureLoading) {\r\n try {\r\n this._texture = engine.createTexture(\r\n this.url,\r\n noMipmap,\r\n this._invertY,\r\n scene,\r\n samplingMode,\r\n load,\r\n errorHandler,\r\n this._buffer,\r\n undefined,\r\n this._format,\r\n this._forcedExtension,\r\n mimeType,\r\n loaderOptions,\r\n creationFlags,\r\n useSRGBBuffer\r\n );\r\n } catch (e) {\r\n errorHandler(\"error loading\", e);\r\n throw e;\r\n }\r\n if (deleteBuffer) {\r\n this._buffer = null;\r\n }\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n\r\n this._delayedOnLoad = load;\r\n this._delayedOnError = errorHandler;\r\n }\r\n } else {\r\n if (this._texture.isReady) {\r\n TimingTools.SetImmediate(() => load());\r\n } else {\r\n const loadObserver = this._texture.onLoadedObservable.add(load);\r\n this._texture.onErrorObservable.add((e) => {\r\n errorHandler(e.message, e.exception);\r\n this._texture?.onLoadedObservable.remove(loadObserver);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Update the url (and optional buffer) of this texture if url was null during construction.\r\n * @param url the url of the texture\r\n * @param buffer the buffer of the texture (defaults to null)\r\n * @param onLoad callback called when the texture is loaded (defaults to null)\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n */\r\n public updateURL(\r\n url: string,\r\n buffer: Nullable = null,\r\n onLoad?: () => void,\r\n forcedExtension?: string\r\n ): void {\r\n if (this.url) {\r\n this.releaseInternalTexture();\r\n this.getScene()!.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n if (!this.name || this.name.startsWith(\"data:\")) {\r\n this.name = url;\r\n }\r\n this.url = url;\r\n this._buffer = buffer;\r\n this._forcedExtension = forcedExtension;\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n\r\n if (onLoad) {\r\n this._delayedOnLoad = onLoad;\r\n }\r\n this.delayLoad();\r\n }\r\n\r\n /**\r\n * Finish the loading sequence of a texture flagged as delayed load.\r\n * @internal\r\n */\r\n public delayLoad(): void {\r\n if (this.delayLoadState !== Constants.DELAYLOADSTATE_NOTLOADED) {\r\n return;\r\n }\r\n\r\n const scene = this.getScene();\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._texture = this._getFromCache(this.url, this._noMipmap, this.samplingMode, this._invertY, this._useSRGBBuffer);\r\n\r\n if (!this._texture) {\r\n this._texture = scene\r\n .getEngine()\r\n .createTexture(\r\n this.url,\r\n this._noMipmap,\r\n this._invertY,\r\n scene,\r\n this.samplingMode,\r\n this._delayedOnLoad,\r\n this._delayedOnError,\r\n this._buffer,\r\n null,\r\n this._format,\r\n this._forcedExtension,\r\n this._mimeType,\r\n this._loaderOptions,\r\n this._creationFlags,\r\n this._useSRGBBuffer\r\n );\r\n if (this._deleteBuffer) {\r\n this._buffer = null;\r\n }\r\n } else {\r\n if (this._delayedOnLoad) {\r\n if (this._texture.isReady) {\r\n TimingTools.SetImmediate(this._delayedOnLoad);\r\n } else {\r\n this._texture.onLoadedObservable.add(this._delayedOnLoad);\r\n }\r\n }\r\n }\r\n\r\n this._delayedOnLoad = null;\r\n this._delayedOnError = null;\r\n }\r\n\r\n private _prepareRowForTextureGeneration(x: number, y: number, z: number, t: Vector3): void {\r\n x *= this._cachedUScale;\r\n y *= this._cachedVScale;\r\n\r\n x -= this.uRotationCenter * this._cachedUScale;\r\n y -= this.vRotationCenter * this._cachedVScale;\r\n z -= this.wRotationCenter;\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix!, t);\r\n\r\n t.x += this.uRotationCenter * this._cachedUScale + this._cachedUOffset;\r\n t.y += this.vRotationCenter * this._cachedVScale + this._cachedVOffset;\r\n t.z += this.wRotationCenter;\r\n }\r\n\r\n /**\r\n * Checks if the texture has the same transform matrix than another texture\r\n * @param texture texture to check against\r\n * @returns true if the transforms are the same, else false\r\n */\r\n public checkTransformsAreIdentical(texture: Nullable): boolean {\r\n return (\r\n texture !== null &&\r\n this.uOffset === texture.uOffset &&\r\n this.vOffset === texture.vOffset &&\r\n this.uScale === texture.uScale &&\r\n this.vScale === texture.vScale &&\r\n this.uAng === texture.uAng &&\r\n this.vAng === texture.vAng &&\r\n this.wAng === texture.wAng\r\n );\r\n }\r\n\r\n /**\r\n * Get the current texture matrix which includes the requested offsetting, tiling and rotation components.\r\n * @param uBase\r\n * @returns the transform matrix of the texture.\r\n */\r\n public getTextureMatrix(uBase = 1): Matrix {\r\n if (\r\n this.uOffset === this._cachedUOffset &&\r\n this.vOffset === this._cachedVOffset &&\r\n this.uScale * uBase === this._cachedUScale &&\r\n this.vScale === this._cachedVScale &&\r\n this.uAng === this._cachedUAng &&\r\n this.vAng === this._cachedVAng &&\r\n this.wAng === this._cachedWAng &&\r\n this.uRotationCenter === this._cachedURotationCenter &&\r\n this.vRotationCenter === this._cachedVRotationCenter &&\r\n this.wRotationCenter === this._cachedWRotationCenter &&\r\n this.homogeneousRotationInUVTransform === this._cachedHomogeneousRotationInUVTransform\r\n ) {\r\n return this._cachedTextureMatrix!;\r\n }\r\n\r\n this._cachedUOffset = this.uOffset;\r\n this._cachedVOffset = this.vOffset;\r\n this._cachedUScale = this.uScale * uBase;\r\n this._cachedVScale = this.vScale;\r\n this._cachedUAng = this.uAng;\r\n this._cachedVAng = this.vAng;\r\n this._cachedWAng = this.wAng;\r\n this._cachedURotationCenter = this.uRotationCenter;\r\n this._cachedVRotationCenter = this.vRotationCenter;\r\n this._cachedWRotationCenter = this.wRotationCenter;\r\n this._cachedHomogeneousRotationInUVTransform = this.homogeneousRotationInUVTransform;\r\n\r\n if (!this._cachedTextureMatrix || !this._rowGenerationMatrix) {\r\n this._cachedTextureMatrix = Matrix.Zero();\r\n this._rowGenerationMatrix = new Matrix();\r\n this._t0 = Vector3.Zero();\r\n this._t1 = Vector3.Zero();\r\n this._t2 = Vector3.Zero();\r\n }\r\n\r\n Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix!);\r\n\r\n if (this.homogeneousRotationInUVTransform) {\r\n Matrix.TranslationToRef(-this._cachedURotationCenter, -this._cachedVRotationCenter, -this._cachedWRotationCenter, TmpVectors.Matrix[0]);\r\n Matrix.TranslationToRef(this._cachedURotationCenter, this._cachedVRotationCenter, this._cachedWRotationCenter, TmpVectors.Matrix[1]);\r\n Matrix.ScalingToRef(this._cachedUScale, this._cachedVScale, 0, TmpVectors.Matrix[2]);\r\n Matrix.TranslationToRef(this._cachedUOffset, this._cachedVOffset, 0, TmpVectors.Matrix[3]);\r\n\r\n TmpVectors.Matrix[0].multiplyToRef(this._rowGenerationMatrix!, this._cachedTextureMatrix);\r\n this._cachedTextureMatrix.multiplyToRef(TmpVectors.Matrix[1], this._cachedTextureMatrix);\r\n this._cachedTextureMatrix.multiplyToRef(TmpVectors.Matrix[2], this._cachedTextureMatrix);\r\n this._cachedTextureMatrix.multiplyToRef(TmpVectors.Matrix[3], this._cachedTextureMatrix);\r\n\r\n // copy the translation row to the 3rd row of the matrix so that we don't need to update the shaders (which expects the translation to be on the 3rd row)\r\n this._cachedTextureMatrix.setRowFromFloats(2, this._cachedTextureMatrix.m[12], this._cachedTextureMatrix.m[13], this._cachedTextureMatrix.m[14], 1);\r\n } else {\r\n this._prepareRowForTextureGeneration(0, 0, 0, this._t0!);\r\n this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1!);\r\n this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2!);\r\n\r\n this._t1!.subtractInPlace(this._t0!);\r\n this._t2!.subtractInPlace(this._t0!);\r\n\r\n Matrix.FromValuesToRef(\r\n this._t1!.x,\r\n this._t1!.y,\r\n this._t1!.z,\r\n 0.0,\r\n this._t2!.x,\r\n this._t2!.y,\r\n this._t2!.z,\r\n 0.0,\r\n this._t0!.x,\r\n this._t0!.y,\r\n this._t0!.z,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 0.0,\r\n 1.0,\r\n this._cachedTextureMatrix\r\n );\r\n }\r\n\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this._cachedTextureMatrix;\r\n }\r\n\r\n if (this.optimizeUVAllocation) {\r\n // We flag the materials that are using this texture as \"texture dirty\" because depending on the fact that the matrix is the identity or not, some defines\r\n // will get different values (see MaterialHelper.PrepareDefinesForMergedUV), meaning we should regenerate the effect accordingly\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => {\r\n return mat.hasTexture(this);\r\n });\r\n }\r\n\r\n return this._cachedTextureMatrix;\r\n }\r\n\r\n /**\r\n * Get the current matrix used to apply reflection. This is useful to rotate an environment texture for instance.\r\n * @returns The reflection texture transform\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this._cachedReflectionTextureMatrix!;\r\n }\r\n\r\n if (\r\n this.uOffset === this._cachedReflectionUOffset &&\r\n this.vOffset === this._cachedReflectionVOffset &&\r\n this.uScale === this._cachedReflectionUScale &&\r\n this.vScale === this._cachedReflectionVScale &&\r\n this.coordinatesMode === this._cachedReflectionCoordinatesMode\r\n ) {\r\n if (this.coordinatesMode === Texture.PROJECTION_MODE) {\r\n if (this._cachedReflectionProjectionMatrixId === scene.getProjectionMatrix().updateFlag) {\r\n return this._cachedReflectionTextureMatrix!;\r\n }\r\n } else {\r\n return this._cachedReflectionTextureMatrix!;\r\n }\r\n }\r\n\r\n if (!this._cachedReflectionTextureMatrix) {\r\n this._cachedReflectionTextureMatrix = Matrix.Zero();\r\n }\r\n\r\n if (!this._projectionModeMatrix) {\r\n this._projectionModeMatrix = Matrix.Zero();\r\n }\r\n\r\n const flagMaterialsAsTextureDirty = this._cachedReflectionCoordinatesMode !== this.coordinatesMode;\r\n\r\n this._cachedReflectionUOffset = this.uOffset;\r\n this._cachedReflectionVOffset = this.vOffset;\r\n this._cachedReflectionUScale = this.uScale;\r\n this._cachedReflectionVScale = this.vScale;\r\n this._cachedReflectionCoordinatesMode = this.coordinatesMode;\r\n\r\n switch (this.coordinatesMode) {\r\n case Texture.PLANAR_MODE: {\r\n Matrix.IdentityToRef(this._cachedReflectionTextureMatrix);\r\n (this._cachedReflectionTextureMatrix)[0] = this.uScale;\r\n (this._cachedReflectionTextureMatrix)[5] = this.vScale;\r\n (this._cachedReflectionTextureMatrix)[12] = this.uOffset;\r\n (this._cachedReflectionTextureMatrix)[13] = this.vOffset;\r\n break;\r\n }\r\n case Texture.PROJECTION_MODE: {\r\n Matrix.FromValuesToRef(0.5, 0.0, 0.0, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 1.0, 1.0, this._projectionModeMatrix);\r\n\r\n const projectionMatrix = scene.getProjectionMatrix();\r\n this._cachedReflectionProjectionMatrixId = projectionMatrix.updateFlag;\r\n projectionMatrix.multiplyToRef(this._projectionModeMatrix, this._cachedReflectionTextureMatrix);\r\n break;\r\n }\r\n default:\r\n Matrix.IdentityToRef(this._cachedReflectionTextureMatrix);\r\n break;\r\n }\r\n\r\n if (flagMaterialsAsTextureDirty) {\r\n // We flag the materials that are using this texture as \"texture dirty\" if the coordinatesMode has changed.\r\n // Indeed, this property is used to set the value of some defines used to generate the effect (in material.isReadyForSubMesh), so we must make sure this code will be re-executed and the effect recreated if necessary\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => {\r\n return mat.getActiveTextures().indexOf(this) !== -1;\r\n });\r\n }\r\n\r\n return this._cachedReflectionTextureMatrix;\r\n }\r\n\r\n /**\r\n * Clones the texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): Texture {\r\n const options: ITextureCreationOptions = {\r\n noMipmap: this._noMipmap,\r\n invertY: this._invertY,\r\n samplingMode: this.samplingMode,\r\n onLoad: undefined,\r\n onError: undefined,\r\n buffer: this._texture ? this._texture._buffer : undefined,\r\n deleteBuffer: this._deleteBuffer,\r\n format: this.textureFormat,\r\n mimeType: this.mimeType,\r\n loaderOptions: this._loaderOptions,\r\n creationFlags: this._creationFlags,\r\n useSRGBBuffer: this._useSRGBBuffer,\r\n };\r\n\r\n return SerializationHelper.Clone(() => {\r\n return new Texture(this._texture ? this._texture.url : null, this.getScene(), options);\r\n }, this);\r\n }\r\n\r\n /**\r\n * Serialize the texture to a JSON representation we can easily use in the respective Parse function.\r\n * @returns The JSON representation of the texture\r\n */\r\n public serialize(): any {\r\n const savedName = this.name;\r\n\r\n if (!Texture.SerializeBuffers) {\r\n if (this.name.startsWith(\"data:\")) {\r\n this.name = \"\";\r\n }\r\n }\r\n\r\n if (this.name.startsWith(\"data:\") && this.url === this.name) {\r\n this.url = \"\";\r\n }\r\n\r\n const serializationObject = super.serialize(Texture._SerializeInternalTextureUniqueId);\r\n\r\n if (!serializationObject) {\r\n return null;\r\n }\r\n\r\n if (Texture.SerializeBuffers || Texture.ForceSerializeBuffers) {\r\n if (typeof this._buffer === \"string\" && (this._buffer as string).substr(0, 5) === \"data:\") {\r\n serializationObject.base64String = this._buffer;\r\n serializationObject.name = serializationObject.name.replace(\"data:\", \"\");\r\n } else if (this.url && this.url.startsWith(\"data:\") && this._buffer instanceof Uint8Array) {\r\n serializationObject.base64String = \"data:image/png;base64,\" + EncodeArrayBufferToBase64(this._buffer);\r\n } else if (Texture.ForceSerializeBuffers || (this.url && this.url.startsWith(\"blob:\")) || this._forceSerialize) {\r\n serializationObject.base64String =\r\n !this._engine || this._engine._features.supportSyncTextureRead ? GenerateBase64StringFromTexture(this) : GenerateBase64StringFromTextureAsync(this);\r\n }\r\n }\r\n\r\n serializationObject.invertY = this._invertY;\r\n serializationObject.samplingMode = this.samplingMode;\r\n serializationObject._creationFlags = this._creationFlags;\r\n serializationObject._useSRGBBuffer = this._useSRGBBuffer;\r\n if (Texture._SerializeInternalTextureUniqueId) {\r\n serializationObject.internalTextureUniqueId = this._texture?.uniqueId ?? undefined;\r\n }\r\n\r\n this.name = savedName;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"Texture\"\r\n */\r\n public getClassName(): string {\r\n return \"Texture\";\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n\r\n this.onLoadObservable.clear();\r\n\r\n this._delayedOnLoad = null;\r\n this._delayedOnError = null;\r\n this._buffer = null;\r\n }\r\n\r\n /**\r\n * Parse the JSON representation of a texture in order to recreate the texture in the given scene.\r\n * @param parsedTexture Define the JSON representation of the texture\r\n * @param scene Define the scene the parsed texture should be instantiated in\r\n * @param rootUrl Define the root url of the parsing sequence in the case of relative dependencies\r\n * @returns The parsed texture if successful\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable {\r\n if (parsedTexture.customType) {\r\n const customTexture = InstantiationTools.Instantiate(parsedTexture.customType);\r\n // Update Sampling Mode\r\n const parsedCustomTexture: any = customTexture.Parse(parsedTexture, scene, rootUrl);\r\n if (parsedTexture.samplingMode && parsedCustomTexture.updateSamplingMode && parsedCustomTexture._samplingMode) {\r\n if (parsedCustomTexture._samplingMode !== parsedTexture.samplingMode) {\r\n parsedCustomTexture.updateSamplingMode(parsedTexture.samplingMode);\r\n }\r\n }\r\n return parsedCustomTexture;\r\n }\r\n\r\n if (parsedTexture.isCube && !parsedTexture.isRenderTarget) {\r\n return Texture._CubeTextureParser(parsedTexture, scene, rootUrl);\r\n }\r\n\r\n const hasInternalTextureUniqueId = parsedTexture.internalTextureUniqueId !== undefined;\r\n\r\n if (!parsedTexture.name && !parsedTexture.isRenderTarget && !hasInternalTextureUniqueId) {\r\n return null;\r\n }\r\n\r\n let internalTexture: InternalTexture | undefined;\r\n\r\n if (hasInternalTextureUniqueId) {\r\n const cache = scene.getEngine().getLoadedTexturesCache();\r\n for (const texture of cache) {\r\n if (texture.uniqueId === parsedTexture.internalTextureUniqueId) {\r\n internalTexture = texture;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const onLoaded = (texture: Texture | null) => {\r\n // Clear cache\r\n if (texture && texture._texture) {\r\n texture._texture._cachedWrapU = null;\r\n texture._texture._cachedWrapV = null;\r\n texture._texture._cachedWrapR = null;\r\n }\r\n\r\n // Update Sampling Mode\r\n if (parsedTexture.samplingMode) {\r\n const sampling: number = parsedTexture.samplingMode;\r\n if (texture && texture.samplingMode !== sampling) {\r\n texture.updateSamplingMode(sampling);\r\n }\r\n }\r\n // Animations\r\n if (texture && parsedTexture.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedTexture.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n texture.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n }\r\n\r\n if (hasInternalTextureUniqueId && !internalTexture) {\r\n texture?._texture?._setUniqueId(parsedTexture.internalTextureUniqueId);\r\n }\r\n };\r\n\r\n const texture = SerializationHelper.Parse(\r\n () => {\r\n let generateMipMaps: boolean = true;\r\n if (parsedTexture.noMipmap) {\r\n generateMipMaps = false;\r\n }\r\n if (parsedTexture.mirrorPlane) {\r\n const mirrorTexture = Texture._CreateMirror(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);\r\n mirrorTexture._waitingRenderList = parsedTexture.renderList;\r\n mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);\r\n onLoaded(mirrorTexture);\r\n return mirrorTexture;\r\n } else if (parsedTexture.isRenderTarget) {\r\n let renderTargetTexture: Nullable = null;\r\n if (parsedTexture.isCube) {\r\n // Search for an existing reflection probe (which contains a cube render target texture)\r\n if (scene.reflectionProbes) {\r\n for (let index = 0; index < scene.reflectionProbes.length; index++) {\r\n const probe = scene.reflectionProbes[index];\r\n if (probe.name === parsedTexture.name) {\r\n return probe.cubeTexture;\r\n }\r\n }\r\n }\r\n } else {\r\n renderTargetTexture = Texture._CreateRenderTargetTexture(\r\n parsedTexture.name,\r\n parsedTexture.renderTargetSize,\r\n scene,\r\n generateMipMaps,\r\n parsedTexture._creationFlags ?? 0\r\n );\r\n renderTargetTexture._waitingRenderList = parsedTexture.renderList;\r\n }\r\n onLoaded(renderTargetTexture);\r\n return renderTargetTexture;\r\n } else {\r\n let texture: Texture;\r\n\r\n if (parsedTexture.base64String && !internalTexture) {\r\n // name and url are the same to ensure caching happens from the actual base64 string\r\n texture = Texture.CreateFromBase64String(\r\n parsedTexture.base64String,\r\n parsedTexture.base64String,\r\n scene,\r\n !generateMipMaps,\r\n parsedTexture.invertY,\r\n parsedTexture.samplingMode,\r\n () => {\r\n onLoaded(texture);\r\n },\r\n parsedTexture._creationFlags ?? 0,\r\n parsedTexture._useSRGBBuffer ?? false\r\n );\r\n\r\n // prettier name to fit with the loaded data\r\n texture.name = parsedTexture.name;\r\n } else {\r\n let url: string;\r\n if (parsedTexture.name && (parsedTexture.name.indexOf(\"://\") > 0 || parsedTexture.name.startsWith(\"data:\"))) {\r\n url = parsedTexture.name;\r\n } else {\r\n url = rootUrl + parsedTexture.name;\r\n }\r\n\r\n if (parsedTexture.url && (parsedTexture.url.startsWith(\"data:\") || Texture.UseSerializedUrlIfAny)) {\r\n url = parsedTexture.url;\r\n }\r\n\r\n const options: ITextureCreationOptions = {\r\n noMipmap: !generateMipMaps,\r\n invertY: parsedTexture.invertY,\r\n samplingMode: parsedTexture.samplingMode,\r\n onLoad: () => {\r\n onLoaded(texture);\r\n },\r\n internalTexture,\r\n };\r\n\r\n texture = new Texture(url, scene, options);\r\n }\r\n\r\n return texture;\r\n }\r\n },\r\n parsedTexture,\r\n scene\r\n );\r\n\r\n return texture;\r\n }\r\n\r\n /**\r\n * Creates a texture from its base 64 representation.\r\n * @param data Define the base64 payload without the data: prefix\r\n * @param name Define the name of the texture in the scene useful fo caching purpose for instance\r\n * @param scene Define the scene the texture should belong to\r\n * @param noMipmapOrOptions defines if the texture will require mip maps or not or set of all options to create the texture\r\n * @param invertY define if the texture needs to be inverted on the y axis during loading\r\n * @param samplingMode define the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)\r\n * @param onLoad define a callback triggered when the texture has been loaded\r\n * @param onError define a callback triggered when an error occurred during the loading session\r\n * @param format define the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @returns the created texture\r\n */\r\n public static CreateFromBase64String(\r\n data: string,\r\n name: string,\r\n scene: Scene,\r\n noMipmapOrOptions?: boolean | ITextureCreationOptions,\r\n invertY?: boolean,\r\n samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<() => void> = null,\r\n format: number = Constants.TEXTUREFORMAT_RGBA,\r\n creationFlags?: number\r\n ): Texture {\r\n return new Texture(\"data:\" + name, scene, noMipmapOrOptions, invertY, samplingMode, onLoad, onError, data, false, format, undefined, undefined, creationFlags);\r\n }\r\n\r\n /**\r\n * Creates a texture from its data: representation. (data: will be added in case only the payload has been passed in)\r\n * @param name Define the name of the texture in the scene useful fo caching purpose for instance\r\n * @param buffer define the buffer to load the texture from in case the texture is loaded from a buffer representation\r\n * @param scene Define the scene the texture should belong to\r\n * @param deleteBuffer define if the buffer we are loading the texture from should be deleted after load\r\n * @param noMipmapOrOptions defines if the texture will require mip maps or not or set of all options to create the texture\r\n * @param invertY define if the texture needs to be inverted on the y axis during loading\r\n * @param samplingMode define the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)\r\n * @param onLoad define a callback triggered when the texture has been loaded\r\n * @param onError define a callback triggered when an error occurred during the loading session\r\n * @param format define the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @returns the created texture\r\n */\r\n public static LoadFromDataString(\r\n name: string,\r\n buffer: any,\r\n scene: Scene,\r\n deleteBuffer: boolean = false,\r\n noMipmapOrOptions?: boolean | ITextureCreationOptions,\r\n invertY: boolean = true,\r\n samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n format: number = Constants.TEXTUREFORMAT_RGBA,\r\n creationFlags?: number\r\n ): Texture {\r\n if (name.substr(0, 5) !== \"data:\") {\r\n name = \"data:\" + name;\r\n }\r\n\r\n return new Texture(name, scene, noMipmapOrOptions, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer, format, undefined, undefined, creationFlags);\r\n }\r\n}\r\n\r\n// References the dependencies.\r\nRegisterClass(\"BABYLON.Texture\", Texture);\r\nSerializationHelper._TextureParser = Texture.Parse;\r\n","import type { Matrix } from \"../Maths/math.vector\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\n/**\r\n * Configuration needed for prepass-capable materials\r\n */\r\nexport class PrePassConfiguration {\r\n /**\r\n * Previous world matrices of meshes carrying this material\r\n * Used for computing velocity\r\n */\r\n public previousWorldMatrices: { [index: number]: Matrix } = {};\r\n /**\r\n * Previous view project matrix\r\n * Used for computing velocity\r\n */\r\n public previousViewProjection: Matrix;\r\n /**\r\n * Current view projection matrix\r\n * Used for computing velocity\r\n */\r\n public currentViewProjection: Matrix;\r\n /**\r\n * Previous bones of meshes carrying this material\r\n * Used for computing velocity\r\n */\r\n public previousBones: { [index: number]: Float32Array } = {};\r\n\r\n private _lastUpdateFrameId: number;\r\n\r\n /**\r\n * Add the required uniforms to the current list.\r\n * @param uniforms defines the current uniform list.\r\n */\r\n public static AddUniforms(uniforms: string[]): void {\r\n uniforms.push(\"previousWorld\", \"previousViewProjection\", \"mPreviousBones\");\r\n }\r\n\r\n /**\r\n * Add the required samplers to the current list.\r\n * @param samplers defines the current sampler list.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static AddSamplers(samplers: string[]): void {\r\n // pass\r\n }\r\n\r\n /**\r\n * Binds the material data.\r\n * @param effect defines the effect to update\r\n * @param scene defines the scene the material belongs to.\r\n * @param mesh The mesh\r\n * @param world World matrix of this mesh\r\n * @param isFrozen Is the material frozen\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bindForSubMesh(effect: Effect, scene: Scene, mesh: Mesh, world: Matrix, isFrozen: boolean): void {\r\n if (scene.prePassRenderer && scene.prePassRenderer.enabled && scene.prePassRenderer.currentRTisSceneRT) {\r\n if (scene.prePassRenderer.getIndex(Constants.PREPASS_VELOCITY_TEXTURE_TYPE) !== -1) {\r\n if (!this.previousWorldMatrices[mesh.uniqueId]) {\r\n this.previousWorldMatrices[mesh.uniqueId] = world.clone();\r\n }\r\n\r\n if (!this.previousViewProjection) {\r\n this.previousViewProjection = scene.getTransformMatrix().clone();\r\n this.currentViewProjection = scene.getTransformMatrix().clone();\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n if (this.currentViewProjection.updateFlag !== scene.getTransformMatrix().updateFlag) {\r\n // First update of the prepass configuration for this rendering pass\r\n this._lastUpdateFrameId = engine.frameId;\r\n this.previousViewProjection.copyFrom(this.currentViewProjection);\r\n this.currentViewProjection.copyFrom(scene.getTransformMatrix());\r\n } else if (this._lastUpdateFrameId !== engine.frameId) {\r\n // The scene transformation did not change from the previous frame (so no camera motion), we must update previousViewProjection accordingly\r\n this._lastUpdateFrameId = engine.frameId;\r\n this.previousViewProjection.copyFrom(this.currentViewProjection);\r\n }\r\n\r\n effect.setMatrix(\"previousWorld\", this.previousWorldMatrices[mesh.uniqueId]);\r\n effect.setMatrix(\"previousViewProjection\", this.previousViewProjection);\r\n\r\n this.previousWorldMatrices[mesh.uniqueId] = world.clone();\r\n }\r\n }\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { Material } from \"../Materials/material\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\n/**\r\n * Base class of materials working in push mode in babylon JS\r\n * @internal\r\n */\r\nexport class PushMaterial extends Material {\r\n protected _activeEffect?: Effect;\r\n\r\n protected _normalMatrix: Matrix = new Matrix();\r\n\r\n constructor(name: string, scene?: Scene, storeEffectOnSubMeshes = true) {\r\n super(name, scene);\r\n this._storeEffectOnSubMeshes = storeEffectOnSubMeshes;\r\n }\r\n\r\n public getEffect(): Effect {\r\n return this._storeEffectOnSubMeshes ? this._activeEffect! : super.getEffect()!;\r\n }\r\n\r\n public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {\r\n if (!mesh) {\r\n return false;\r\n }\r\n\r\n if (!this._storeEffectOnSubMeshes) {\r\n return true;\r\n }\r\n\r\n if (!mesh.subMeshes || mesh.subMeshes.length === 0) {\r\n return true;\r\n }\r\n\r\n return this.isReadyForSubMesh(mesh, mesh.subMeshes[0], useInstances);\r\n }\r\n\r\n protected _isReadyForSubMesh(subMesh: SubMesh) {\r\n const defines = subMesh.materialDefines;\r\n if (!this.checkReadyOnEveryCall && subMesh.effect && defines) {\r\n if (defines._renderId === this.getScene().getRenderId()) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Binds the given world matrix to the active effect\r\n *\r\n * @param world the matrix to bind\r\n */\r\n public bindOnlyWorldMatrix(world: Matrix): void {\r\n this._activeEffect!.setMatrix(\"world\", world);\r\n }\r\n\r\n /**\r\n * Binds the given normal matrix to the active effect\r\n *\r\n * @param normalMatrix the matrix to bind\r\n */\r\n public bindOnlyNormalMatrix(normalMatrix: Matrix): void {\r\n this._activeEffect!.setMatrix(\"normalMatrix\", normalMatrix);\r\n }\r\n\r\n public bind(world: Matrix, mesh?: Mesh): void {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n this.bindForSubMesh(world, mesh, mesh.subMeshes[0]);\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable = null): void {\r\n super._afterBind(mesh, effect);\r\n this.getScene()._cachedEffect = effect;\r\n if (effect) {\r\n effect._forceRebindOnNextCall = false;\r\n }\r\n }\r\n\r\n protected _mustRebind(scene: Scene, effect: Effect, visibility: number = 1) {\r\n return scene.isCachedMaterialInvalid(this, effect, visibility);\r\n }\r\n\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, notBoundToMesh?: boolean) {\r\n this._activeEffect = undefined;\r\n super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);\r\n }\r\n}\r\n","import { Engine } from \"../Engines/engine\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\n/**\r\n * This groups all the flags used to control the materials channel.\r\n */\r\nexport class MaterialFlags {\r\n // Flags used to enable or disable a type of texture for all Standard Materials\r\n private static _DiffuseTextureEnabled = true;\r\n /**\r\n * Are diffuse textures enabled in the application.\r\n */\r\n public static get DiffuseTextureEnabled(): boolean {\r\n return this._DiffuseTextureEnabled;\r\n }\r\n public static set DiffuseTextureEnabled(value: boolean) {\r\n if (this._DiffuseTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._DiffuseTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _DetailTextureEnabled = true;\r\n /**\r\n * Are detail textures enabled in the application.\r\n */\r\n public static get DetailTextureEnabled(): boolean {\r\n return this._DetailTextureEnabled;\r\n }\r\n public static set DetailTextureEnabled(value: boolean) {\r\n if (this._DetailTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._DetailTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _DecalMapEnabled = true;\r\n /**\r\n * Are decal maps enabled in the application.\r\n */\r\n public static get DecalMapEnabled(): boolean {\r\n return this._DecalMapEnabled;\r\n }\r\n public static set DecalMapEnabled(value: boolean) {\r\n if (this._DecalMapEnabled === value) {\r\n return;\r\n }\r\n\r\n this._DecalMapEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _AmbientTextureEnabled = true;\r\n /**\r\n * Are ambient textures enabled in the application.\r\n */\r\n public static get AmbientTextureEnabled(): boolean {\r\n return this._AmbientTextureEnabled;\r\n }\r\n public static set AmbientTextureEnabled(value: boolean) {\r\n if (this._AmbientTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._AmbientTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _OpacityTextureEnabled = true;\r\n /**\r\n * Are opacity textures enabled in the application.\r\n */\r\n public static get OpacityTextureEnabled(): boolean {\r\n return this._OpacityTextureEnabled;\r\n }\r\n public static set OpacityTextureEnabled(value: boolean) {\r\n if (this._OpacityTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._OpacityTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _ReflectionTextureEnabled = true;\r\n /**\r\n * Are reflection textures enabled in the application.\r\n */\r\n public static get ReflectionTextureEnabled(): boolean {\r\n return this._ReflectionTextureEnabled;\r\n }\r\n public static set ReflectionTextureEnabled(value: boolean) {\r\n if (this._ReflectionTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ReflectionTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _EmissiveTextureEnabled = true;\r\n /**\r\n * Are emissive textures enabled in the application.\r\n */\r\n public static get EmissiveTextureEnabled(): boolean {\r\n return this._EmissiveTextureEnabled;\r\n }\r\n public static set EmissiveTextureEnabled(value: boolean) {\r\n if (this._EmissiveTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._EmissiveTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _SpecularTextureEnabled = true;\r\n /**\r\n * Are specular textures enabled in the application.\r\n */\r\n public static get SpecularTextureEnabled(): boolean {\r\n return this._SpecularTextureEnabled;\r\n }\r\n public static set SpecularTextureEnabled(value: boolean) {\r\n if (this._SpecularTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._SpecularTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _BumpTextureEnabled = true;\r\n /**\r\n * Are bump textures enabled in the application.\r\n */\r\n public static get BumpTextureEnabled(): boolean {\r\n return this._BumpTextureEnabled;\r\n }\r\n public static set BumpTextureEnabled(value: boolean) {\r\n if (this._BumpTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._BumpTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _LightmapTextureEnabled = true;\r\n /**\r\n * Are lightmap textures enabled in the application.\r\n */\r\n public static get LightmapTextureEnabled(): boolean {\r\n return this._LightmapTextureEnabled;\r\n }\r\n public static set LightmapTextureEnabled(value: boolean) {\r\n if (this._LightmapTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._LightmapTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _RefractionTextureEnabled = true;\r\n /**\r\n * Are refraction textures enabled in the application.\r\n */\r\n public static get RefractionTextureEnabled(): boolean {\r\n return this._RefractionTextureEnabled;\r\n }\r\n public static set RefractionTextureEnabled(value: boolean) {\r\n if (this._RefractionTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._RefractionTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _ColorGradingTextureEnabled = true;\r\n /**\r\n * Are color grading textures enabled in the application.\r\n */\r\n public static get ColorGradingTextureEnabled(): boolean {\r\n return this._ColorGradingTextureEnabled;\r\n }\r\n public static set ColorGradingTextureEnabled(value: boolean) {\r\n if (this._ColorGradingTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ColorGradingTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _FresnelEnabled = true;\r\n /**\r\n * Are fresnels enabled in the application.\r\n */\r\n public static get FresnelEnabled(): boolean {\r\n return this._FresnelEnabled;\r\n }\r\n public static set FresnelEnabled(value: boolean) {\r\n if (this._FresnelEnabled === value) {\r\n return;\r\n }\r\n\r\n this._FresnelEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_FresnelDirtyFlag);\r\n }\r\n\r\n private static _ClearCoatTextureEnabled = true;\r\n /**\r\n * Are clear coat textures enabled in the application.\r\n */\r\n public static get ClearCoatTextureEnabled(): boolean {\r\n return this._ClearCoatTextureEnabled;\r\n }\r\n public static set ClearCoatTextureEnabled(value: boolean) {\r\n if (this._ClearCoatTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ClearCoatTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _ClearCoatBumpTextureEnabled = true;\r\n /**\r\n * Are clear coat bump textures enabled in the application.\r\n */\r\n public static get ClearCoatBumpTextureEnabled(): boolean {\r\n return this._ClearCoatBumpTextureEnabled;\r\n }\r\n public static set ClearCoatBumpTextureEnabled(value: boolean) {\r\n if (this._ClearCoatBumpTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ClearCoatBumpTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _ClearCoatTintTextureEnabled = true;\r\n /**\r\n * Are clear coat tint textures enabled in the application.\r\n */\r\n public static get ClearCoatTintTextureEnabled(): boolean {\r\n return this._ClearCoatTintTextureEnabled;\r\n }\r\n public static set ClearCoatTintTextureEnabled(value: boolean) {\r\n if (this._ClearCoatTintTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ClearCoatTintTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _SheenTextureEnabled = true;\r\n /**\r\n * Are sheen textures enabled in the application.\r\n */\r\n public static get SheenTextureEnabled(): boolean {\r\n return this._SheenTextureEnabled;\r\n }\r\n public static set SheenTextureEnabled(value: boolean) {\r\n if (this._SheenTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._SheenTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _AnisotropicTextureEnabled = true;\r\n /**\r\n * Are anisotropic textures enabled in the application.\r\n */\r\n public static get AnisotropicTextureEnabled(): boolean {\r\n return this._AnisotropicTextureEnabled;\r\n }\r\n public static set AnisotropicTextureEnabled(value: boolean) {\r\n if (this._AnisotropicTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._AnisotropicTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _ThicknessTextureEnabled = true;\r\n /**\r\n * Are thickness textures enabled in the application.\r\n */\r\n public static get ThicknessTextureEnabled(): boolean {\r\n return this._ThicknessTextureEnabled;\r\n }\r\n public static set ThicknessTextureEnabled(value: boolean) {\r\n if (this._ThicknessTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._ThicknessTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _RefractionIntensityTextureEnabled = true;\r\n /**\r\n * Are refraction intensity textures enabled in the application.\r\n */\r\n public static get RefractionIntensityTextureEnabled(): boolean {\r\n return this._ThicknessTextureEnabled;\r\n }\r\n public static set RefractionIntensityTextureEnabled(value: boolean) {\r\n if (this._RefractionIntensityTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._RefractionIntensityTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _TranslucencyIntensityTextureEnabled = true;\r\n /**\r\n * Are translucency intensity textures enabled in the application.\r\n */\r\n public static get TranslucencyIntensityTextureEnabled(): boolean {\r\n return this._ThicknessTextureEnabled;\r\n }\r\n public static set TranslucencyIntensityTextureEnabled(value: boolean) {\r\n if (this._TranslucencyIntensityTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._TranslucencyIntensityTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private static _IridescenceTextureEnabled = true;\r\n /**\r\n * Are translucency intensity textures enabled in the application.\r\n */\r\n public static get IridescenceTextureEnabled(): boolean {\r\n return this._IridescenceTextureEnabled;\r\n }\r\n public static set IridescenceTextureEnabled(value: boolean) {\r\n if (this._IridescenceTextureEnabled === value) {\r\n return;\r\n }\r\n\r\n this._IridescenceTextureEnabled = value;\r\n Engine.MarkAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"decalFragmentDeclaration\";\nconst shader = `#ifdef DECAL\nuniform vec4 vDecalInfos;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const decalFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalFragmentDeclaration\";\n\nconst name = \"defaultFragmentDeclaration\";\nconst shader = `uniform vec4 vEyePosition;uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;uniform vec3 vAmbientColor;uniform float visibility;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#ifdef ALPHATEST\nuniform float alphaCutOff;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION) || defined(PREPASS)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;uniform vec4 refractionRightColor;\n#endif\n#if defined(USE_LOCAL_REFRACTIONMAP_CUBIC) && defined(REFRACTIONMAP_3D)\nuniform vec3 vRefractionPosition;uniform vec3 vRefractionSize; \n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;uniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;uniform vec4 emissiveRightColor;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION) || defined(REFLECTIONMAP_EQUIRECTANGULAR) || defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_SKYBOX)\nuniform mat4 reflectionMatrix;\n#endif\n#ifndef REFLECTIONMAP_SKYBOX\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;uniform vec3 vReflectionSize; \n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;uniform vec4 reflectionRightColor;\n#endif\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;\n#endif\n#include\n#define ADDITIONAL_FRAGMENT_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const defaultFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"sceneUboDeclaration\";\nconst shader = `layout(std140,column_major) uniform;uniform Scene {mat4 viewProjection;\n#ifdef MULTIVIEW\nmat4 viewProjectionR;\n#endif \nmat4 view;mat4 projection;vec4 vEyePosition;};\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const sceneUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"meshUboDeclaration\";\nconst shader = `#ifdef WEBGL2\nuniform mat4 world;uniform float visibility;\n#else\nlayout(std140,column_major) uniform;uniform Mesh\n{mat4 world;float visibility;};\n#endif\n#define WORLD_UBO\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const meshUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./sceneUboDeclaration\";\nimport \"./meshUboDeclaration\";\n\nconst name = \"defaultUboDeclaration\";\nconst shader = `layout(std140,column_major) uniform;uniform Material\n{vec4 diffuseLeftColor;vec4 diffuseRightColor;vec4 opacityParts;vec4 reflectionLeftColor;vec4 reflectionRightColor;vec4 refractionLeftColor;vec4 refractionRightColor;vec4 emissiveLeftColor;vec4 emissiveRightColor;vec2 vDiffuseInfos;vec2 vAmbientInfos;vec2 vOpacityInfos;vec2 vReflectionInfos;vec3 vReflectionPosition;vec3 vReflectionSize;vec2 vEmissiveInfos;vec2 vLightmapInfos;vec2 vSpecularInfos;vec3 vBumpInfos;mat4 diffuseMatrix;mat4 ambientMatrix;mat4 opacityMatrix;mat4 reflectionMatrix;mat4 emissiveMatrix;mat4 lightmapMatrix;mat4 specularMatrix;mat4 bumpMatrix;vec2 vTangentSpaceParams;float pointSize;float alphaCutOff;mat4 refractionMatrix;vec4 vRefractionInfos;vec3 vRefractionPosition;vec3 vRefractionSize;vec4 vSpecularColor;vec3 vEmissiveColor;vec4 vDiffuseColor;vec3 vAmbientColor;\n#define ADDITIONAL_UBO_DECLARATION\n};\n#include\n#include\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const defaultUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"prePassDeclaration\";\nconst shader = `#ifdef PREPASS\n#extension GL_EXT_draw_buffers : require\nlayout(location=0) out highp vec4 glFragData[{X}];highp vec4 gl_FragColor;\n#ifdef PREPASS_DEPTH\nvarying highp vec3 vViewPos;\n#endif\n#ifdef PREPASS_VELOCITY\nvarying highp vec4 vCurrentPosition;varying highp vec4 vPreviousPosition;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const prePassDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"oitDeclaration\";\nconst shader = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY\n#extension GL_EXT_draw_buffers : require\nlayout(location=0) out vec2 depth; \nlayout(location=1) out vec4 frontColor;layout(location=2) out vec4 backColor;\n#define MAX_DEPTH 99999.0\nhighp vec4 gl_FragColor;uniform sampler2D oitDepthSampler;uniform sampler2D oitFrontColorSampler;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const oitDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"mainUVVaryingDeclaration\";\nconst shader = `#ifdef MAINUV{X}\nvarying vec2 vMainUV{X};\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const mainUVVaryingDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"helperFunctions\";\nconst shader = `const float PI=3.1415926535897932384626433832795;const float HALF_MIN=5.96046448e-08; \nconst float LinearEncodePowerApprox=2.2;const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);const float Epsilon=0.0000001;\n#define saturate(x) clamp(x,0.0,1.0)\n#define absEps(x) abs(x)+Epsilon\n#define maxEps(x) max(x,Epsilon)\n#define saturateEps(x) clamp(x,Epsilon,1.0)\nmat3 transposeMat3(mat3 inMatrix) {vec3 i0=inMatrix[0];vec3 i1=inMatrix[1];vec3 i2=inMatrix[2];mat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);return outMatrix;}\nmat3 inverseMat3(mat3 inMatrix) {float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}\n#if USE_EXACT_SRGB_CONVERSIONS\nvec3 toLinearSpaceExact(vec3 color)\n{vec3 nearZeroSection=0.0773993808*color;vec3 remainingSection=pow(0.947867299*(color+vec3(0.055)),vec3(2.4));\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nreturn mix(remainingSection,nearZeroSection,lessThanEqual(color,vec3(0.04045)));\n#else\nreturn\nvec3(\ncolor.r<=0.04045 ? nearZeroSection.r : remainingSection.r,\ncolor.g<=0.04045 ? nearZeroSection.g : remainingSection.g,\ncolor.b<=0.04045 ? nearZeroSection.b : remainingSection.b);\n#endif\n}\nvec3 toGammaSpaceExact(vec3 color)\n{vec3 nearZeroSection=12.92*color;vec3 remainingSection=1.055*pow(color,vec3(0.41666))-vec3(0.055);\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nreturn mix(remainingSection,nearZeroSection,lessThanEqual(color,vec3(0.0031308)));\n#else\nreturn\nvec3(\ncolor.r<=0.0031308 ? nearZeroSection.r : remainingSection.r,\ncolor.g<=0.0031308 ? nearZeroSection.g : remainingSection.g,\ncolor.b<=0.0031308 ? nearZeroSection.b : remainingSection.b);\n#endif\n}\n#endif\nfloat toLinearSpace(float color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nfloat nearZeroSection=0.0773993808*color;float remainingSection=pow(0.947867299*(color+0.055),2.4);return color<=0.04045 ? nearZeroSection : remainingSection;\n#else\nreturn pow(color,LinearEncodePowerApprox);\n#endif\n}\nvec3 toLinearSpace(vec3 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn toLinearSpaceExact(color);\n#else\nreturn pow(color,vec3(LinearEncodePowerApprox));\n#endif\n}\nvec4 toLinearSpace(vec4 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn vec4(toLinearSpaceExact(color.rgb),color.a);\n#else\nreturn vec4(pow(color.rgb,vec3(LinearEncodePowerApprox)),color.a);\n#endif\n}\nfloat toGammaSpace(float color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nfloat nearZeroSection=12.92*color;float remainingSection=1.055*pow(color,0.41666)-0.055;return color<=0.0031308 ? nearZeroSection : remainingSection;\n#else\nreturn pow(color,GammaEncodePowerApprox);\n#endif\n}\nvec3 toGammaSpace(vec3 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn toGammaSpaceExact(color);\n#else\nreturn pow(color,vec3(GammaEncodePowerApprox));\n#endif\n}\nvec4 toGammaSpace(vec4 color)\n{\n#if USE_EXACT_SRGB_CONVERSIONS\nreturn vec4(toGammaSpaceExact(color.rgb),color.a);\n#else\nreturn vec4(pow(color.rgb,vec3(GammaEncodePowerApprox)),color.a);\n#endif\n}\nfloat square(float value)\n{return value*value;}\nvec3 square(vec3 value)\n{return value*value;}\nfloat pow5(float value) {float sq=value*value;return sq*sq*value;}\nfloat getLuminance(vec3 color)\n{return clamp(dot(color,LuminanceEncodeApprox),0.,1.);}\nfloat getRand(vec2 seed) {return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);}\nfloat dither(vec2 seed,float varianceAmount) {float rand=getRand(seed);float normVariance=varianceAmount/255.0;float dither=mix(-normVariance,normVariance,rand);return dither;}\nconst float rgbdMaxRange=255.0;vec4 toRGBD(vec3 color) {float maxRGB=maxEps(max(color.r,max(color.g,color.b)));float D =max(rgbdMaxRange/maxRGB,1.);D =clamp(floor(D)/255.0,0.,1.);vec3 rgb=color.rgb*D;rgb=toGammaSpace(rgb);return vec4(clamp(rgb,0.,1.),D); }\nvec3 fromRGBD(vec4 rgbd) {rgbd.rgb=toLinearSpace(rgbd.rgb);return rgbd.rgb/rgbd.a;}\nvec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {vec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;vec3 halfSize=cubeSize*0.5;vec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)*invOrigVec;vec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)*invOrigVec;vec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);float distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);vec3 intersectPositionWS=vertexPos+origVec*distance;return intersectPositionWS-cubePos;}\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const helperFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"lightFragmentDeclaration\";\nconst shader = `#ifdef LIGHT{X}\nuniform vec4 vLightData{X};uniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec4 vLightSpecular{X};\n#else\nvec4 vLightSpecular{X}=vec4(0.);\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];uniform float viewFrustumZ{X}[SHADOWCSMNUM_CASCADES{X}];uniform float frustumLengths{X}[SHADOWCSMNUM_CASCADES{X}];uniform float cascadeBlendFactor{X};varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};uniform highp sampler2DArray depthSampler{X};uniform vec2 lightSizeUVCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float depthCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float penumbraDarkness{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};\n#else\nuniform highp sampler2DArray shadowSampler{X};\n#endif\n#ifdef SHADOWCSMDEBUG{X}\nconst vec3 vCascadeColorsMultiplier{X}[8]=vec3[8]\n(\nvec3 ( 1.5,0.0,0.0 ),\nvec3 ( 0.0,1.5,0.0 ),\nvec3 ( 0.0,0.0,5.5 ),\nvec3 ( 1.5,0.0,5.5 ),\nvec3 ( 1.5,1.5,0.0 ),\nvec3 ( 1.0,1.0,1.0 ),\nvec3 ( 0.0,1.0,5.5 ),\nvec3 ( 0.5,3.5,0.75 )\n);vec3 shadowDebug{X};\n#endif\n#ifdef SHADOWCSMUSESHADOWMAXZ{X}\nint index{X}=-1;\n#else\nint index{X}=SHADOWCSMNUM_CASCADES{X}-1;\n#endif\nfloat diff{X}=0.;\n#elif defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};uniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};uniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};uniform vec4 vLightFalloff{X};\n#elif defined(POINTLIGHT{X})\nuniform vec4 vLightFalloff{X};\n#elif defined(HEMILIGHT{X})\nuniform vec3 vLightGround{X};\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};uniform sampler2D projectionLightSampler{X};\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const lightFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"lightUboDeclaration\";\nconst shader = `#ifdef LIGHT{X}\nuniform Light{X}\n{vec4 vLightData;vec4 vLightDiffuse;vec4 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;vec4 vLightFalloff;\n#elif defined(POINTLIGHT{X})\nvec4 vLightFalloff;\n#elif defined(HEMILIGHT{X})\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;vec2 depthValues;} light{X};\n#ifdef PROJECTEDLIGHTTEXTURE{X}\nuniform mat4 textureProjectionMatrix{X};uniform sampler2D projectionLightSampler{X};\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];uniform float viewFrustumZ{X}[SHADOWCSMNUM_CASCADES{X}];uniform float frustumLengths{X}[SHADOWCSMNUM_CASCADES{X}];uniform float cascadeBlendFactor{X};varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};uniform highp sampler2DArray depthSampler{X};uniform vec2 lightSizeUVCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float depthCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float penumbraDarkness{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DArrayShadow shadowSampler{X};\n#else\nuniform highp sampler2DArray shadowSampler{X};\n#endif\n#ifdef SHADOWCSMDEBUG{X}\nconst vec3 vCascadeColorsMultiplier{X}[8]=vec3[8]\n(\nvec3 ( 1.5,0.0,0.0 ),\nvec3 ( 0.0,1.5,0.0 ),\nvec3 ( 0.0,0.0,5.5 ),\nvec3 ( 1.5,0.0,5.5 ),\nvec3 ( 1.5,1.5,0.0 ),\nvec3 ( 1.0,1.0,1.0 ),\nvec3 ( 0.0,1.0,5.5 ),\nvec3 ( 0.5,3.5,0.75 )\n);vec3 shadowDebug{X};\n#endif\n#ifdef SHADOWCSMUSESHADOWMAXZ{X}\nint index{X}=-1;\n#else\nint index{X}=SHADOWCSMNUM_CASCADES{X}-1;\n#endif\nfloat diff{X}=0.;\n#elif defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X}; \n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};\n#if defined(SHADOWPCSS{X})\nuniform highp sampler2DShadow shadowSampler{X};uniform highp sampler2D depthSampler{X};\n#elif defined(SHADOWPCF{X})\nuniform highp sampler2DShadow shadowSampler{X};\n#else\nuniform sampler2D shadowSampler{X};\n#endif\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const lightUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"lightsFragmentFunctions\";\nconst shader = `struct lightingInfo\n{vec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};lightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {lightingInfo result;vec3 lightVectorW;float attenuation=1.0;if (lightData.w==0.)\n{vec3 direction=lightData.xyz-vPositionW;attenuation=max(0.,1.0-length(direction)/range);lightVectorW=normalize(direction);}\nelse\n{lightVectorW=normalize(-lightData.xyz);}\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\nvec3 angleW=normalize(viewDirectionW+lightVectorW);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {lightingInfo result;vec3 direction=lightData.xyz-vPositionW;vec3 lightVectorW=normalize(direction);float attenuation=max(0.,1.0-length(direction)/range);float cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));if (cosAngle>=lightDirection.w)\n{cosAngle=max(0.,pow(cosAngle,lightData.w));attenuation*=cosAngle;float ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\nvec3 angleW=normalize(viewDirectionW+lightVectorW);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {lightingInfo result;float ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor;\n#endif\nreturn result;}\n#define inline\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);strq/=strq.w;vec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;return textureColor;}`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const lightsFragmentFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowsFragmentFunctions\";\nconst shader = `#ifdef SHADOWS\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)\n#else\n#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)\n#endif\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{const vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);return dot(color,bit_shift);}\n#endif\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{float mask=smoothstep(1.0-frustumEdgeFalloff,1.00000012,clamp(dot(clipSpace,clipSpace),0.,1.));return mix(value,1.0,mask);}\n#define inline\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{vec3 directionToLight=vPositionW-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);depth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nreturn depth>shadow ? darkness : 1.0;}\n#define inline\nfloat computeShadowWithPoissonSamplingCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{vec3 directionToLight=vPositionW-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);depth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;float visibility=1.;vec3 poissonDisk[4];poissonDisk[0]=vec3(-1.0,1.0,-1.0);poissonDisk[1]=vec3(1.0,-1.0,-1.0);poissonDisk[2]=vec3(-1.0,-1.0,-1.0);poissonDisk[3]=vec3(1.0,-1.0,1.0);\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))shadow ? computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff) : 1.;}\n#endif\n#define inline\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(TEXTUREFUNC(shadowSampler,uv,0.));\n#else\nfloat shadow=TEXTUREFUNC(shadowSampler,uv,0.).x;\n#endif\nreturn shadowPixelDepth>shadow ? computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff) : 1.;}}\n#define inline\nfloat computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0);float visibility=1.;vec2 poissonDisk[4];poissonDisk[0]=vec2(-0.94201624,-0.39906216);poissonDisk[1]=vec2(0.94558609,-0.76890725);poissonDisk[2]=vec2(-0.094184101,-0.92938870);poissonDisk[3]=vec2(0.34495938,0.29387760);\n#ifndef SHADOWFLOAT\nif (unpack(TEXTUREFUNC(shadowSampler,uv+poissonDisk[0]*mapSize,0.))1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(TEXTUREFUNC(shadowSampler,uv,0.));\n#else\nfloat shadowMapSample=TEXTUREFUNC(shadowSampler,uv,0.).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}\n#define inline\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{return 1.0;}\nelse\n{float shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(TEXTUREFUNC(shadowSampler,uv,0.));\n#else\nfloat shadowMapSample=TEXTUREFUNC(shadowSampler,uv,0.).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}\n#ifdef IS_NDC_HALF_ZRANGE\n#define ZINCLIP clipSpace.z\n#else\n#define ZINCLIP uvDepth.z\n#endif\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define GREATEST_LESS_THAN_ONE 0.99999994\n#define inline\nfloat computeShadowWithCSMPCF1(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec4 uvDepthLayer=vec4(uvDepth.x,uvDepth.y,layer,uvDepth.z);float shadow=texture2D(shadowSampler,uvDepthLayer);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}\n#define inline\nfloat computeShadowWithCSMPCF3(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=3.-2.*st;vec2 uvw1=1.+2.*st;vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[0]),layer,uvDepth.z));shadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[0]),layer,uvDepth.z));shadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[1]),layer,uvDepth.z));shadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[1]),layer,uvDepth.z));shadow=shadow/16.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}\n#define inline\nfloat computeShadowWithCSMPCF5(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=4.-3.*st;vec2 uvw1=vec2(7.);vec2 uvw2=1.+3.*st;vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[0]),layer,uvDepth.z));shadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[0]),layer,uvDepth.z));shadow+=uvw2.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[0]),layer,uvDepth.z));shadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[1]),layer,uvDepth.z));shadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[1]),layer,uvDepth.z));shadow+=uvw2.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[1]),layer,uvDepth.z));shadow+=uvw0.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[2]),layer,uvDepth.z));shadow+=uvw1.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[2]),layer,uvDepth.z));shadow+=uvw2.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[2]),layer,uvDepth.z));shadow=shadow/144.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}\n#define inline\nfloat computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)\n{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;float shadow=TEXTUREFUNC(shadowSampler,uvDepth,0.);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}\n#define inline\nfloat computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=3.-2.*st;vec2 uvw1=1.+2.*st;vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z),0.);shadow+=uvw1.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z),0.);shadow+=uvw0.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z),0.);shadow+=uvw1.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z),0.);shadow=shadow/16.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}\n#define inline\nfloat computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)\n{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; \nuv+=0.5; \nvec2 st=fract(uv); \nvec2 base_uv=floor(uv)-0.5; \nbase_uv*=shadowMapSizeAndInverse.y; \nvec2 uvw0=4.-3.*st;vec2 uvw1=vec2(7.);vec2 uvw2=1.+3.*st;vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z),0.);shadow+=uvw1.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z),0.);shadow+=uvw2.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z),0.);shadow+=uvw0.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z),0.);shadow+=uvw1.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z),0.);shadow+=uvw2.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z),0.);shadow+=uvw0.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z),0.);shadow+=uvw1.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z),0.);shadow+=uvw2.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z),0.);shadow=shadow/144.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}\nconst vec3 PoissonSamplers32[64]=vec3[64](\nvec3(0.06407013,0.05409927,0.),\nvec3(0.7366577,0.5789394,0.),\nvec3(-0.6270542,-0.5320278,0.),\nvec3(-0.4096107,0.8411095,0.),\nvec3(0.6849564,-0.4990818,0.),\nvec3(-0.874181,-0.04579735,0.),\nvec3(0.9989998,0.0009880066,0.),\nvec3(-0.004920578,-0.9151649,0.),\nvec3(0.1805763,0.9747483,0.),\nvec3(-0.2138451,0.2635818,0.),\nvec3(0.109845,0.3884785,0.),\nvec3(0.06876755,-0.3581074,0.),\nvec3(0.374073,-0.7661266,0.),\nvec3(0.3079132,-0.1216763,0.),\nvec3(-0.3794335,-0.8271583,0.),\nvec3(-0.203878,-0.07715034,0.),\nvec3(0.5912697,0.1469799,0.),\nvec3(-0.88069,0.3031784,0.),\nvec3(0.5040108,0.8283722,0.),\nvec3(-0.5844124,0.5494877,0.),\nvec3(0.6017799,-0.1726654,0.),\nvec3(-0.5554981,0.1559997,0.),\nvec3(-0.3016369,-0.3900928,0.),\nvec3(-0.5550632,-0.1723762,0.),\nvec3(0.925029,0.2995041,0.),\nvec3(-0.2473137,0.5538505,0.),\nvec3(0.9183037,-0.2862392,0.),\nvec3(0.2469421,0.6718712,0.),\nvec3(0.3916397,-0.4328209,0.),\nvec3(-0.03576927,-0.6220032,0.),\nvec3(-0.04661255,0.7995201,0.),\nvec3(0.4402924,0.3640312,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.),\nvec3(0.,0.,0.)\n);const vec3 PoissonSamplers64[64]=vec3[64](\nvec3(-0.613392,0.617481,0.),\nvec3(0.170019,-0.040254,0.),\nvec3(-0.299417,0.791925,0.),\nvec3(0.645680,0.493210,0.),\nvec3(-0.651784,0.717887,0.),\nvec3(0.421003,0.027070,0.),\nvec3(-0.817194,-0.271096,0.),\nvec3(-0.705374,-0.668203,0.),\nvec3(0.977050,-0.108615,0.),\nvec3(0.063326,0.142369,0.),\nvec3(0.203528,0.214331,0.),\nvec3(-0.667531,0.326090,0.),\nvec3(-0.098422,-0.295755,0.),\nvec3(-0.885922,0.215369,0.),\nvec3(0.566637,0.605213,0.),\nvec3(0.039766,-0.396100,0.),\nvec3(0.751946,0.453352,0.),\nvec3(0.078707,-0.715323,0.),\nvec3(-0.075838,-0.529344,0.),\nvec3(0.724479,-0.580798,0.),\nvec3(0.222999,-0.215125,0.),\nvec3(-0.467574,-0.405438,0.),\nvec3(-0.248268,-0.814753,0.),\nvec3(0.354411,-0.887570,0.),\nvec3(0.175817,0.382366,0.),\nvec3(0.487472,-0.063082,0.),\nvec3(-0.084078,0.898312,0.),\nvec3(0.488876,-0.783441,0.),\nvec3(0.470016,0.217933,0.),\nvec3(-0.696890,-0.549791,0.),\nvec3(-0.149693,0.605762,0.),\nvec3(0.034211,0.979980,0.),\nvec3(0.503098,-0.308878,0.),\nvec3(-0.016205,-0.872921,0.),\nvec3(0.385784,-0.393902,0.),\nvec3(-0.146886,-0.859249,0.),\nvec3(0.643361,0.164098,0.),\nvec3(0.634388,-0.049471,0.),\nvec3(-0.688894,0.007843,0.),\nvec3(0.464034,-0.188818,0.),\nvec3(-0.440840,0.137486,0.),\nvec3(0.364483,0.511704,0.),\nvec3(0.034028,0.325968,0.),\nvec3(0.099094,-0.308023,0.),\nvec3(0.693960,-0.366253,0.),\nvec3(0.678884,-0.204688,0.),\nvec3(0.001801,0.780328,0.),\nvec3(0.145177,-0.898984,0.),\nvec3(0.062655,-0.611866,0.),\nvec3(0.315226,-0.604297,0.),\nvec3(-0.780145,0.486251,0.),\nvec3(-0.371868,0.882138,0.),\nvec3(0.200476,0.494430,0.),\nvec3(-0.494552,-0.711051,0.),\nvec3(0.612476,0.705252,0.),\nvec3(-0.578845,-0.768792,0.),\nvec3(-0.772454,-0.090976,0.),\nvec3(0.504440,0.372295,0.),\nvec3(0.155736,0.065157,0.),\nvec3(0.391522,0.849605,0.),\nvec3(-0.620106,-0.328104,0.),\nvec3(0.789239,-0.419965,0.),\nvec3(-0.545396,0.538133,0.),\nvec3(-0.178564,-0.596057,0.)\n);\n#define inline\nfloat computeShadowWithCSMPCSS(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray depthSampler,highp sampler2DArrayShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers,vec2 lightSizeUVCorrection,float depthCorrection,float penumbraDarkness)\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec4 uvDepthLayer=vec4(uvDepth.x,uvDepth.y,layer,uvDepth.z);float blockerDepth=0.0;float sumBlockerDepth=0.0;float numBlocker=0.0;for (int i=0; i1.0 || depthMetric<0.0) {return 1.0;}\nelse\n{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;float blockerDepth=0.0;float sumBlockerDepth=0.0;float numBlocker=0.0;for (int i=0; i(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_SAMPLERNAME_,bump)\n#endif\n#if defined(DETAIL)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)\n#endif\n#if defined(BUMP) && defined(PARALLAX)\nconst float minSamples=4.;const float maxSamples=15.;const int iMaxSamples=15;vec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {float parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;parallaxLimit*=parallaxScale;vec2 vOffsetDir=normalize(vViewDirCoT.xy);vec2 vMaxOffset=vOffsetDir*parallaxLimit;float numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));float stepSize=1.0/numSamples;float currRayHeight=1.0;vec2 vCurrOffset=vec2(0,0);vec2 vLastOffset=vec2(0,0);float lastSampledHeight=1.0;float currSampledHeight=1.0;bool keepWorking=true;for (int i=0; icurrRayHeight)\n{float delta1=currSampledHeight-currRayHeight;float delta2=(currRayHeight+stepSize)-lastSampledHeight;float ratio=delta1/(delta1+delta2);vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;keepWorking=false;}\nelse\n{currRayHeight-=stepSize;vLastOffset=vCurrOffset;vCurrOffset+=stepSize*vMaxOffset;lastSampledHeight=currSampledHeight;}}\nreturn vCurrOffset;}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{float height=texture2D(bumpSampler,vBumpUV).w;vec2 texCoordOffset=heightScale*viewDir.xy*height;return -texCoordOffset;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpFragmentFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"clipPlaneFragmentDeclaration\";\nconst shader = `#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nvarying float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nvarying float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nvarying float fClipDistance4;\n#endif\n#ifdef CLIPPLANE5\nvarying float fClipDistance5;\n#endif\n#ifdef CLIPPLANE6\nvarying float fClipDistance6;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const clipPlaneFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"logDepthDeclaration\";\nconst shader = `#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;varying float vFragmentDepth;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const logDepthDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"fogFragmentDeclaration\";\nconst shader = `#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;uniform vec3 vFogColor;varying vec3 vFogDistance;float CalcFogFactor()\n{float fogCoeff=1.0;float fogStart=vFogInfos.y;float fogEnd=vFogInfos.z;float fogDensity=vFogInfos.w;float fogDistance=length(vFogDistance);if (FOGMODE_LINEAR==vFogInfos.x)\n{fogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);}\nelse if (FOGMODE_EXP==vFogInfos.x)\n{fogCoeff=1.0/pow(E,fogDistance*fogDensity);}\nelse if (FOGMODE_EXP2==vFogInfos.x)\n{fogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);}\nreturn clamp(fogCoeff,0.0,1.0);}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const fogFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"clipPlaneFragment\";\nconst shader = `#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)\nif (false) {}\n#endif\n#ifdef CLIPPLANE\nelse if (fClipDistance>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE2\nelse if (fClipDistance2>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE3\nelse if (fClipDistance3>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE4\nelse if (fClipDistance4>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE5\nelse if (fClipDistance5>0.0)\n{discard;}\n#endif\n#ifdef CLIPPLANE6\nelse if (fClipDistance6>0.0)\n{discard;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const clipPlaneFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpFragment\";\nconst shader = `vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#elif defined(BUMP)\nfloat normalScale=vBumpInfos.y;\n#else\nfloat normalScale=1.0;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#elif defined(BUMP)\nvec2 TBNUV=gl_FrontFacing ? vBumpUV : -vBumpUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vTangentSpaceParams);\n#else\nvec2 TBNUV=gl_FrontFacing ? vDetailUV : -vDetailUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vec2(1.,1.));\n#endif\n#elif defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nvec2 TBNUV=gl_FrontFacing ? vMainUV1 : -vMainUV1;mat3 TBN=cotangent_frame(normalW,vPositionW,TBNUV,vec2(1.,1.));\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef DETAIL\nvec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);vec2 detailNormalRG=detailColor.wy*2.0-1.0;float detailNormalB=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));vec3 detailNormal=vec3(detailNormalRG,detailNormalB);\n#endif\n#ifdef BUMP\n#ifdef OBJECTSPACE_NORMALMAP\n#define CUSTOM_FRAGMENT_BUMP_FRAGMENT\nnormalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);normalW=normalize(mat3(normalMatrix)*normalW);\n#elif !defined(DETAIL)\nnormalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);\n#else\nvec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;\n#if DETAIL_NORMALBLENDMETHOD==0 \ndetailNormal.xy*=vDetailInfos.z;vec3 blendedNormal=normalize(vec3(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));\n#elif DETAIL_NORMALBLENDMETHOD==1 \ndetailNormal.xy*=vDetailInfos.z;bumpNormal+=vec3(0.0,0.0,1.0);detailNormal*=vec3(-1.0,-1.0,1.0);vec3 blendedNormal=bumpNormal*dot(bumpNormal,detailNormal)/bumpNormal.z-detailNormal;\n#endif\nnormalW=perturbNormalBase(TBN,blendedNormal,vBumpInfos.y);\n#endif\n#elif defined(DETAIL)\ndetailNormal.xy*=vDetailInfos.z;normalW=perturbNormalBase(TBN,detailNormal,vDetailInfos.z);\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"decalFragment\";\nconst shader = `#ifdef DECAL\n#ifdef GAMMADECAL\ndecalColor.rgb=toLinearSpace(decalColor.rgb);\n#endif\n#ifdef DECAL_SMOOTHALPHA\ndecalColor.a*=decalColor.a;\n#endif\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,decalColor.rgb,decalColor.a);\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const decalFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"depthPrePass\";\nconst shader = `#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);return;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const depthPrePass = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"lightFragment\";\nconst shader = `#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\npreInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#elif defined(POINTLIGHT{X})\npreInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#elif defined(HEMILIGHT{X})\npreInfo=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#elif defined(DIRLIGHT{X})\npreInfo=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);\n#endif\npreInfo.NdotV=NdotV;\n#ifdef SPOTLIGHT{X}\n#ifdef LIGHT_FALLOFF_GLTF{X}\npreInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);preInfo.attenuation*=computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);\n#elif defined(LIGHT_FALLOFF_PHYSICAL{X})\npreInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);preInfo.attenuation*=computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w);\n#elif defined(LIGHT_FALLOFF_STANDARD{X})\npreInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);preInfo.attenuation*=computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w);\n#else\npreInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);preInfo.attenuation*=computeDirectionalLightFalloff(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);\n#endif\n#elif defined(POINTLIGHT{X})\n#ifdef LIGHT_FALLOFF_GLTF{X}\npreInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);\n#elif defined(LIGHT_FALLOFF_PHYSICAL{X})\npreInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);\n#elif defined(LIGHT_FALLOFF_STANDARD{X})\npreInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);\n#else\npreInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);\n#endif\n#else\npreInfo.attenuation=1.0;\n#endif\n#ifdef HEMILIGHT{X}\npreInfo.roughness=roughness;\n#else\npreInfo.roughness=adjustRoughnessFromLightProperties(roughness,light{X}.vLightSpecular.a,preInfo.lightDistance);\n#endif\n#ifdef IRIDESCENCE\npreInfo.iridescenceIntensity=iridescenceIntensity;\n#endif\n#ifdef HEMILIGHT{X}\ninfo.diffuse=computeHemisphericDiffuseLighting(preInfo,light{X}.vLightDiffuse.rgb,light{X}.vLightGround);\n#elif defined(SS_TRANSLUCENCY)\ninfo.diffuse=computeDiffuseAndTransmittedLighting(preInfo,light{X}.vLightDiffuse.rgb,subSurfaceOut.transmittance);\n#else\ninfo.diffuse=computeDiffuseLighting(preInfo,light{X}.vLightDiffuse.rgb);\n#endif\n#ifdef SPECULARTERM\n#ifdef ANISOTROPIC\ninfo.specular=computeAnisotropicSpecularLighting(preInfo,viewDirectionW,normalW,anisotropicOut.anisotropicTangent,anisotropicOut.anisotropicBitangent,anisotropicOut.anisotropy,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,AARoughnessFactors.x,light{X}.vLightDiffuse.rgb);\n#else\ninfo.specular=computeSpecularLighting(preInfo,normalW,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,AARoughnessFactors.x,light{X}.vLightDiffuse.rgb);\n#endif\n#endif\n#ifdef SHEEN\n#ifdef SHEEN_LINKWITHALBEDO\npreInfo.roughness=sheenOut.sheenIntensity;\n#else\n#ifdef HEMILIGHT{X}\npreInfo.roughness=sheenOut.sheenRoughness;\n#else\npreInfo.roughness=adjustRoughnessFromLightProperties(sheenOut.sheenRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);\n#endif\n#endif\ninfo.sheen=computeSheenLighting(preInfo,normalW,sheenOut.sheenColor,specularEnvironmentR90,AARoughnessFactors.x,light{X}.vLightDiffuse.rgb);\n#endif\n#ifdef CLEARCOAT\n#ifdef HEMILIGHT{X}\npreInfo.roughness=clearcoatOut.clearCoatRoughness;\n#else\npreInfo.roughness=adjustRoughnessFromLightProperties(clearcoatOut.clearCoatRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);\n#endif\ninfo.clearCoat=computeClearCoatLighting(preInfo,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatAARoughnessFactors.x,clearcoatOut.clearCoatIntensity,light{X}.vLightDiffuse.rgb);\n#ifdef CLEARCOAT_TINT\nabsorption=computeClearCoatLightingAbsorption(clearcoatOut.clearCoatNdotVRefract,preInfo.L,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatColor,clearcoatOut.clearCoatThickness,clearcoatOut.clearCoatIntensity);info.diffuse*=absorption;\n#ifdef SPECULARTERM\ninfo.specular*=absorption;\n#endif\n#endif\ninfo.diffuse*=info.clearCoat.w;\n#ifdef SPECULARTERM\ninfo.specular*=info.clearCoat.w;\n#endif\n#ifdef SHEEN\ninfo.sheen*=info.clearCoat.w;\n#endif\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightDiffuse.a,glossiness);\n#elif defined(HEMILIGHT{X})\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightGround,glossiness);\n#elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#ifdef PROJECTEDLIGHTTEXTURE{X}\ninfo.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler{X},textureProjectionMatrix{X});\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nfor (int i=0; i=0.) {index{X}=i;break;}}\n#ifdef SHADOWCSMUSESHADOWMAXZ{X}\nif (index{X}>=0)\n#endif\n{\n#if defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithCSMPCF1(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithCSMPCF3(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithCSMPCF5(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithCSMPCSS16(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithCSMPCSS32(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#else\nshadow=computeShadowWithCSMPCSS64(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#endif\n#else\nshadow=computeShadowCSM(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#ifdef SHADOWCSMDEBUG{X}\nshadowDebug{X}=vec3(shadow)*vCascadeColorsMultiplier{X}[index{X}];\n#endif\n#ifndef SHADOWCSMNOBLEND{X}\nfloat frustumLength=frustumLengths{X}[index{X}];float diffRatio=clamp(diff{X}/frustumLength,0.,1.)*cascadeBlendFactor{X};if (index{X}<(SHADOWCSMNUM_CASCADES{X}-1) && diffRatio<1.)\n{index{X}+=1;float nextShadow=0.;\n#if defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nnextShadow=computeShadowWithCSMPCF1(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nnextShadow=computeShadowWithCSMPCF3(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nnextShadow=computeShadowWithCSMPCF5(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nnextShadow=computeShadowWithCSMPCSS16(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#elif defined(SHADOWMEDIUMQUALITY{X})\nnextShadow=computeShadowWithCSMPCSS32(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#else\nnextShadow=computeShadowWithCSMPCSS64(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});\n#endif\n#else\nnextShadow=computeShadowCSM(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\nshadow=mix(nextShadow,shadow,diffRatio);\n#ifdef SHADOWCSMDEBUG{X}\nshadowDebug{X}=mix(vec3(nextShadow)*vCascadeColorsMultiplier{X}[index{X}],shadowDebug{X},diffRatio);\n#endif\n}\n#endif\n}\n#elif defined(SHADOWCLOSEESM{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWESM{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPOISSON{X})\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPoissonSamplingCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPoissonSampling(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCF{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCF1(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCF3(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCF5(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#elif defined(SHADOWPCSS{X})\n#if defined(SHADOWLOWQUALITY{X})\nshadow=computeShadowWithPCSS16(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#elif defined(SHADOWMEDIUMQUALITY{X})\nshadow=computeShadowWithPCSS32(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#else\nshadow=computeShadowWithPCSS64(vPositionFromLight{X},vDepthMetric{X},depthSampler{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;shadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor.rgb*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor.rgb;\n#endif\n#endif\n#ifdef CLEARCOAT\n#ifndef LIGHTMAPNOSPECULAR{X}\nclearCoatBase+=info.clearCoat.rgb*shadow*lightmapColor.rgb;\n#endif\n#endif\n#ifdef SHEEN\n#ifndef LIGHTMAPNOSPECULAR{X}\nsheenBase+=info.sheen.rgb*shadow;\n#endif\n#endif\n#else\n#ifdef SHADOWCSMDEBUG{X}\ndiffuseBase+=info.diffuse*shadowDebug{X};\n#else \ndiffuseBase+=info.diffuse*shadow;\n#endif\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#ifdef CLEARCOAT\nclearCoatBase+=info.clearCoat.rgb*shadow;\n#endif\n#ifdef SHEEN\nsheenBase+=info.sheen.rgb*shadow;\n#endif\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const lightFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"logDepthFragment\";\nconst shader = `#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const logDepthFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"fogFragment\";\nconst shader = `#ifdef FOG\nfloat fog=CalcFogFactor();\n#ifdef PBR\nfog=toLinearSpace(fog);\n#endif\ncolor.rgb=mix(vFogColor,color.rgb,fog);\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const fogFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"oitFragment\";\nconst shader = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY\nfloat fragDepth=gl_FragCoord.z; \n#ifdef ORDER_INDEPENDENT_TRANSPARENCY_16BITS\nuint halfFloat=packHalf2x16(vec2(fragDepth));vec2 full=unpackHalf2x16(halfFloat);fragDepth=full.x;\n#endif\nivec2 fragCoord=ivec2(gl_FragCoord.xy);vec2 lastDepth=texelFetch(oitDepthSampler,fragCoord,0).rg;vec4 lastFrontColor=texelFetch(oitFrontColorSampler,fragCoord,0);depth.rg=vec2(-MAX_DEPTH);frontColor=lastFrontColor;backColor=vec4(0.0);\n#ifdef USE_REVERSE_DEPTHBUFFER\nfloat furthestDepth=-lastDepth.x;float nearestDepth=lastDepth.y;\n#else\nfloat nearestDepth=-lastDepth.x;float furthestDepth=lastDepth.y;\n#endif\nfloat alphaMultiplier=1.0-lastFrontColor.a;\n#ifdef USE_REVERSE_DEPTHBUFFER\nif (fragDepth>nearestDepth || fragDepthfurthestDepth) {\n#endif\nreturn;}\n#ifdef USE_REVERSE_DEPTHBUFFER\nif (fragDepthfurthestDepth) {\n#else\nif (fragDepth>nearestDepth && fragDepth\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include[SCENE_MRT_COUNT]\n#include\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#define RECIPROCAL_PI2 0.15915494\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include[1..7]\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_SAMPLERNAME_,diffuse)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULARTERM)\n#include(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_SAMPLERNAME_,specular)\n#endif\n#include\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#if defined(ALPHATEST) && !defined(ALPHATEST_AFTERALLALPHACOMPUTATIONS)\nif (baseColor.a(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#include\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef DETAIL\nbaseColor.rgb=baseColor.rgb*2.0*mix(0.5,detailColor.r,vDetailInfos.y);\n#endif\n#if defined(DECAL) && defined(DECAL_AFTER_DETAIL)\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#include(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);\n#ifdef RGBDLIGHTMAP\nlightmapColor.rgb=fromRGBD(lightmapColor);\n#endif\nlightmapColor.rgb*=vLightmapInfos.y;\n#endif\n#include[0..maxSimultaneousLights]\nvec4 refractionColor=vec4(0.,0.,0.,1.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\n#ifdef USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,vRefractionSize,vRefractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec4 refractionLookup=textureCube(refractionCubeSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=texture2D(refraction2DSampler,refractionCoords);\n#endif\n#ifdef RGBDREFRACTION\nrefractionColor.rgb=fromRGBD(refractionColor);\n#endif\n#ifdef IS_REFRACTION_LINEAR\nrefractionColor.rgb=toGammaSpace(refractionColor.rgb);\n#endif\nrefractionColor.rgb*=vRefractionInfos.x;\n#endif\nvec4 reflectionColor=vec4(0.,0.,0.,1.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nvReflectionUVW.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias);\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW);\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;reflectionColor=texture2D(reflection2DSampler,coords);\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef IS_REFLECTION_LINEAR\nreflectionColor.rgb=toGammaSpace(reflectionColor.rgb);\n#endif\nreflectionColor.rgb*=vReflectionInfos.x;\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor.rgb*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);refractionColor.rgb*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n#ifdef ALPHATEST\n#ifdef ALPHATEST_AFTERALLALPHACOMPUTATIONS\nif (alpha\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);\n#endif\n#endif\ncolor.a*=visibility;\n#ifdef PREMULTIPLYALPHA\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\n#ifdef PREPASS\nfloat writeGeometryInfo=color.a>0.4 ? 1.0 : 0.0;gl_FragData[0]=color; \n#ifdef PREPASS_POSITION\ngl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);\n#endif\n#ifdef PREPASS_VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);\n#endif\n#ifdef PREPASS_IRRADIANCE\ngl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_DEPTH\ngl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_NORMAL\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo); \n#endif\n#ifdef PREPASS_ALBEDO_SQRT\ngl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_REFLECTIVITY\n#if defined(SPECULARTERM)\n#if defined(SPECULAR)\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularMapColor))*writeGeometryInfo; \n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularColor),1.0)*writeGeometryInfo;\n#endif\n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(0.0,0.0,0.0,1.0)*writeGeometryInfo;\n#endif\n#endif\n#endif\n#if !defined(PREPASS) || defined(WEBGL2)\ngl_FragColor=color;\n#endif\n#include\n#if ORDER_INDEPENDENT_TRANSPARENCY\nif (fragDepth==nearestDepth) {frontColor.rgb+=color.rgb*color.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-color.a);} else {backColor+=color;}\n#endif\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const defaultPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"decalVertexDeclaration\";\nconst shader = `#ifdef DECAL\nuniform vec4 vDecalInfos;uniform mat4 decalMatrix;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const decalVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalVertexDeclaration\";\n\nconst name = \"defaultVertexDeclaration\";\nconst shader = `uniform mat4 viewProjection;uniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;uniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef REFLECTION\nuniform mat4 reflectionMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const defaultVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"uvAttributeDeclaration\";\nconst shader = `#ifdef UV{X}\nattribute vec2 uv{X};\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const uvAttributeDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bonesDeclaration\";\nconst shader = `#if NUM_BONE_INFLUENCERS>0\nattribute vec4 matricesIndices;attribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;attribute vec4 matricesWeightsExtra;\n#endif\n#ifndef BAKED_VERTEX_ANIMATION_TEXTURE\n#ifdef BONETEXTURE\nuniform sampler2D boneSampler;uniform float boneTextureWidth;\n#else\nuniform mat4 mBones[BonesPerMesh];\n#ifdef BONES_VELOCITY_ENABLED\nuniform mat4 mPreviousBones[BonesPerMesh];\n#endif\n#endif\n#ifdef BONETEXTURE\n#define inline\nmat4 readMatrixFromRawSampler(sampler2D smp,float index)\n{float offset=index *4.0;float dx=1.0/boneTextureWidth;vec4 m0=texture2D(smp,vec2(dx*(offset+0.5),0.));vec4 m1=texture2D(smp,vec2(dx*(offset+1.5),0.));vec4 m2=texture2D(smp,vec2(dx*(offset+2.5),0.));vec4 m3=texture2D(smp,vec2(dx*(offset+3.5),0.));return mat4(m0,m1,m2,m3);}\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bonesDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bakedVertexAnimationDeclaration\";\nconst shader = `#ifdef BAKED_VERTEX_ANIMATION_TEXTURE\nuniform float bakedVertexAnimationTime;uniform vec2 bakedVertexAnimationTextureSizeInverted;uniform vec4 bakedVertexAnimationSettings;uniform sampler2D bakedVertexAnimationTexture;\n#ifdef INSTANCES\nattribute vec4 bakedVertexAnimationSettingsInstanced;\n#endif\n#define inline\nmat4 readMatrixFromRawSamplerVAT(sampler2D smp,float index,float frame)\n{float offset=index*4.0;float frameUV=(frame+0.5)*bakedVertexAnimationTextureSizeInverted.y;float dx=bakedVertexAnimationTextureSizeInverted.x;vec4 m0=texture2D(smp,vec2(dx*(offset+0.5),frameUV));vec4 m1=texture2D(smp,vec2(dx*(offset+1.5),frameUV));vec4 m2=texture2D(smp,vec2(dx*(offset+2.5),frameUV));vec4 m3=texture2D(smp,vec2(dx*(offset+3.5),frameUV));return mat4(m0,m1,m2,m3);}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bakedVertexAnimationDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"instancesDeclaration\";\nconst shader = `#ifdef INSTANCES\nattribute vec4 world0;attribute vec4 world1;attribute vec4 world2;attribute vec4 world3;\n#ifdef INSTANCESCOLOR\nattribute vec4 instanceColor;\n#endif\n#if defined(THIN_INSTANCES) && !defined(WORLD_UBO)\nuniform mat4 world;\n#endif\n#if defined(VELOCITY) || defined(PREPASS_VELOCITY)\nattribute vec4 previousWorld0;attribute vec4 previousWorld1;attribute vec4 previousWorld2;attribute vec4 previousWorld3;\n#ifdef THIN_INSTANCES\nuniform mat4 previousWorld;\n#endif\n#endif\n#else\n#if !defined(WORLD_UBO)\nuniform mat4 world;\n#endif\n#if defined(VELOCITY) || defined(PREPASS_VELOCITY)\nuniform mat4 previousWorld;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const instancesDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"prePassVertexDeclaration\";\nconst shader = `#ifdef PREPASS\n#ifdef PREPASS_DEPTH\nvarying vec3 vViewPos;\n#endif\n#ifdef PREPASS_VELOCITY\nuniform mat4 previousViewProjection;varying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const prePassVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"samplerVertexDeclaration\";\nconst shader = `#if defined(_DEFINENAME_) && _DEFINENAME_DIRECTUV==0\nvarying vec2 v_VARYINGNAME_UV;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const samplerVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpVertexDeclaration\";\nconst shader = `#if defined(BUMP) || defined(PARALLAX) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"clipPlaneVertexDeclaration\";\nconst shader = `#ifdef CLIPPLANE\nuniform vec4 vClipPlane;varying float fClipDistance;\n#endif\n#ifdef CLIPPLANE2\nuniform vec4 vClipPlane2;varying float fClipDistance2;\n#endif\n#ifdef CLIPPLANE3\nuniform vec4 vClipPlane3;varying float fClipDistance3;\n#endif\n#ifdef CLIPPLANE4\nuniform vec4 vClipPlane4;varying float fClipDistance4;\n#endif\n#ifdef CLIPPLANE5\nuniform vec4 vClipPlane5;varying float fClipDistance5;\n#endif\n#ifdef CLIPPLANE6\nuniform vec4 vClipPlane6;varying float fClipDistance6;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const clipPlaneVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"fogVertexDeclaration\";\nconst shader = `#ifdef FOG\nvarying vec3 vFogDistance;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const fogVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"lightVxFragmentDeclaration\";\nconst shader = `#ifdef LIGHT{X}\nuniform vec4 vLightData{X};uniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec4 vLightSpecular{X};\n#else\nvec4 vLightSpecular{X}=vec4(0.);\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#elif defined(SHADOWCUBE{X})\n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};uniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};uniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};uniform vec4 vLightFalloff{X};\n#elif defined(POINTLIGHT{X})\nuniform vec4 vLightFalloff{X};\n#elif defined(HEMILIGHT{X})\nuniform vec3 vLightGround{X};\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const lightVxFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"lightVxUboDeclaration\";\nconst shader = `#ifdef LIGHT{X}\nuniform Light{X}\n{vec4 vLightData;vec4 vLightDiffuse;vec4 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;vec4 vLightFalloff;\n#elif defined(POINTLIGHT{X})\nvec4 vLightFalloff;\n#elif defined(HEMILIGHT{X})\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;vec2 depthValues;} light{X};\n#ifdef SHADOW{X}\n#ifdef SHADOWCSM{X}\nuniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};\n#elif defined(SHADOWCUBE{X})\n#else\nvarying vec4 vPositionFromLight{X};varying float vDepthMetric{X};uniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const lightVxUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"morphTargetsVertexGlobalDeclaration\";\nconst shader = `#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#ifdef MORPHTARGETS_TEXTURE \nprecision mediump sampler2DArray; \nuniform float morphTargetTextureIndices[NUM_MORPH_INFLUENCERS];uniform vec3 morphTargetTextureInfo;uniform sampler2DArray morphTargets;vec3 readVector3FromRawSampler(int targetIndex,float vertexIndex)\n{ \nfloat y=floor(vertexIndex/morphTargetTextureInfo.y);float x=vertexIndex-y*morphTargetTextureInfo.y;vec3 textureUV=vec3((x+0.5)/morphTargetTextureInfo.y,(y+0.5)/morphTargetTextureInfo.z,morphTargetTextureIndices[targetIndex]);return texture(morphTargets,textureUV).xyz;}\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const morphTargetsVertexGlobalDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"morphTargetsVertexDeclaration\";\nconst shader = `#ifdef MORPHTARGETS\n#ifndef MORPHTARGETS_TEXTURE\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#ifdef MORPHTARGETS_UV\nattribute vec2 uv_{X};\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const morphTargetsVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"morphTargetsVertexGlobal\";\nconst shader = `#ifdef MORPHTARGETS\n#ifdef MORPHTARGETS_TEXTURE\nfloat vertexID;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const morphTargetsVertexGlobal = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"morphTargetsVertex\";\nconst shader = `#ifdef MORPHTARGETS\n#ifdef MORPHTARGETS_TEXTURE \nvertexID=float(gl_VertexID)*morphTargetTextureInfo.x;positionUpdated+=(readVector3FromRawSampler({X},vertexID)-position)*morphTargetInfluences[{X}];vertexID+=1.0;\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(readVector3FromRawSampler({X},vertexID) -normal)*morphTargetInfluences[{X}];vertexID+=1.0;\n#endif\n#ifdef MORPHTARGETS_UV\nuvUpdated+=(readVector3FromRawSampler({X},vertexID).xy-uv)*morphTargetInfluences[{X}];vertexID+=1.0;\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(readVector3FromRawSampler({X},vertexID) -tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#else\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_UV\nuvUpdated+=(uv_{X}-uv)*morphTargetInfluences[{X}];\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const morphTargetsVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"instancesVertex\";\nconst shader = `#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#if defined(PREPASS_VELOCITY) || defined(VELOCITY)\nmat4 finalPreviousWorld=mat4(previousWorld0,previousWorld1,previousWorld2,previousWorld3);\n#endif\n#ifdef THIN_INSTANCES\nfinalWorld=world*finalWorld;\n#if defined(PREPASS_VELOCITY) || defined(VELOCITY)\nfinalPreviousWorld=previousWorld*finalPreviousWorld;\n#endif\n#endif\n#else\nmat4 finalWorld=world;\n#if defined(PREPASS_VELOCITY) || defined(VELOCITY)\nmat4 finalPreviousWorld=previousWorld;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const instancesVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bonesVertex\";\nconst shader = `#ifndef BAKED_VERTEX_ANIMATION_TEXTURE\n#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\n#ifdef BONETEXTURE\ninfluence=readMatrixFromRawSampler(boneSampler,matricesIndices[0])*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndices[1])*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndices[2])*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndices[3])*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[0])*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[1])*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[2])*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\ninfluence+=readMatrixFromRawSampler(boneSampler,matricesIndicesExtra[3])*matricesWeightsExtra[3];\n#endif\n#else\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\n#endif\nfinalWorld=finalWorld*influence;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bonesVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bakedVertexAnimation\";\nconst shader = `#ifdef BAKED_VERTEX_ANIMATION_TEXTURE\n{\n#ifdef INSTANCES\n#define BVASNAME bakedVertexAnimationSettingsInstanced\n#else\n#define BVASNAME bakedVertexAnimationSettings\n#endif\nfloat VATStartFrame=BVASNAME.x;float VATEndFrame=BVASNAME.y;float VATOffsetFrame=BVASNAME.z;float VATSpeed=BVASNAME.w;float totalFrames=VATEndFrame-VATStartFrame+1.0;float time=bakedVertexAnimationTime*VATSpeed/totalFrames;float frameCorrection=time<1.0 ? 0.0 : 1.0;float numOfFrames=totalFrames-frameCorrection;float VATFrameNum=fract(time)*numOfFrames;VATFrameNum=mod(VATFrameNum+VATOffsetFrame,numOfFrames);VATFrameNum=floor(VATFrameNum);VATFrameNum+=VATStartFrame+frameCorrection;mat4 VATInfluence;VATInfluence=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[0],VATFrameNum)*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[1],VATFrameNum)*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[2],VATFrameNum)*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndices[3],VATFrameNum)*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[0],VATFrameNum)*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[1],VATFrameNum)*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[2],VATFrameNum)*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\nVATInfluence+=readMatrixFromRawSamplerVAT(bakedVertexAnimationTexture,matricesIndicesExtra[3],VATFrameNum)*matricesWeightsExtra[3];\n#endif\nfinalWorld=finalWorld*VATInfluence;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bakedVertexAnimation = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"prePassVertex\";\nconst shader = `#ifdef PREPASS_DEPTH\nvViewPos=(view*worldPos).rgb;\n#endif\n#if defined(PREPASS_VELOCITY) && defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*worldPos;\n#if NUM_BONE_INFLUENCERS>0\nmat4 previousInfluence;previousInfluence=mPreviousBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\npreviousInfluence+=mPreviousBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\npreviousInfluence+=mPreviousBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\npreviousInfluence+=mPreviousBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\nvPreviousPosition=previousViewProjection*finalPreviousWorld*previousInfluence*vec4(positionUpdated,1.0);\n#else\nvPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const prePassVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"uvVariableDeclaration\";\nconst shader = `#if !defined(UV{X}) && defined(MAINUV{X})\nvec2 uv{X}=vec2(0.,0.);\n#endif\n#ifdef MAINUV{X}\nvMainUV{X}=uv{X};\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const uvVariableDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"samplerVertexImplementation\";\nconst shader = `#if defined(_DEFINENAME_) && _DEFINENAME_DIRECTUV==0\nif (v_INFONAME_==0.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uvUpdated,1.0,0.0));}\n#ifdef UV2\nelse if (v_INFONAME_==1.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv2,1.0,0.0));}\n#endif\n#ifdef UV3\nelse if (v_INFONAME_==2.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv3,1.0,0.0));}\n#endif\n#ifdef UV4\nelse if (v_INFONAME_==3.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv4,1.0,0.0));}\n#endif\n#ifdef UV5\nelse if (v_INFONAME_==4.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv5,1.0,0.0));}\n#endif\n#ifdef UV6\nelse if (v_INFONAME_==5.)\n{v_VARYINGNAME_UV=vec2(_MATRIXNAME_Matrix*vec4(uv6,1.0,0.0));}\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const samplerVertexImplementation = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bumpVertex\";\nconst shader = `#if defined(BUMP) || defined(PARALLAX) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);vec3 tbnTangent=normalize(tangentUpdated.xyz);vec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;vTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bumpVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"clipPlaneVertex\";\nconst shader = `#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n#ifdef CLIPPLANE2\nfClipDistance2=dot(worldPos,vClipPlane2);\n#endif\n#ifdef CLIPPLANE3\nfClipDistance3=dot(worldPos,vClipPlane3);\n#endif\n#ifdef CLIPPLANE4\nfClipDistance4=dot(worldPos,vClipPlane4);\n#endif\n#ifdef CLIPPLANE5\nfClipDistance5=dot(worldPos,vClipPlane5);\n#endif\n#ifdef CLIPPLANE6\nfClipDistance6=dot(worldPos,vClipPlane6);\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const clipPlaneVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"fogVertex\";\nconst shader = `#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const fogVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowsVertex\";\nconst shader = `#ifdef SHADOWS\n#if defined(SHADOWCSM{X})\nvPositionFromCamera{X}=view*worldPos;for (int i=0; i\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#include[2..7]\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n#include\n#include\n#include\n#include[1..7]\n#include(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap)\n#if defined(SPECULARTERM)\n#include(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular)\n#endif\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal)\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightVxFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif\n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include\n#if defined(PREPASS) && defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#if defined(INSTANCES) && defined(THIN_INSTANCES)\nvNormalW=normalUpdated/vec3(dot(normalWorld[0],normalWorld[0]),dot(normalWorld[1],normalWorld[1]),dot(normalWorld[2],normalWorld[2]));vNormalW=normalize(normalWorld*vNormalW);\n#else\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#endif\n#define CUSTOM_VERTEX_UPDATE_WORLDPOS\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\nvPositionW=vec3(worldPos);\n#include\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n#ifndef UV1\nvec2 uvUpdated=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uvUpdated;\n#endif\n#include[2..7]\n#include(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_MATRIXNAME_,diffuse,_INFONAME_,DiffuseInfos.x)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_MATRIXNAME_,detail,_INFONAME_,DetailInfos.x)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_MATRIXNAME_,ambient,_INFONAME_,AmbientInfos.x)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_MATRIXNAME_,opacity,_INFONAME_,OpacityInfos.x)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_MATRIXNAME_,emissive,_INFONAME_,EmissiveInfos.x)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_MATRIXNAME_,lightmap,_INFONAME_,LightmapInfos.x)\n#if defined(SPECULARTERM)\n#include(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_MATRIXNAME_,specular,_INFONAME_,SpecularInfos.x)\n#endif\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_MATRIXNAME_,bump,_INFONAME_,BumpInfos.x)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_MATRIXNAME_,decal,_INFONAME_,DecalInfos.x)\n#include\n#include\n#include\n#include[0..maxSimultaneousLights]\n#include\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const defaultVertexShader = { name, shader };\n","import type { Nullable } from \"../types\";\r\nimport type { IEffectFallbacks } from \"./iEffectFallbacks\";\r\n\r\nimport type { Effect } from \"./effect\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n\r\n/**\r\n * EffectFallbacks can be used to add fallbacks (properties to disable) to certain properties when desired to improve performance.\r\n * (Eg. Start at high quality with reflection and fog, if fps is low, remove reflection, if still low remove fog)\r\n */\r\nexport class EffectFallbacks implements IEffectFallbacks {\r\n private _defines: { [key: string]: Array } = {};\r\n\r\n private _currentRank = 32;\r\n private _maxRank = -1;\r\n\r\n private _mesh: Nullable = null;\r\n\r\n /**\r\n * Removes the fallback from the bound mesh.\r\n */\r\n public unBindMesh() {\r\n this._mesh = null;\r\n }\r\n\r\n /**\r\n * Adds a fallback on the specified property.\r\n * @param rank The rank of the fallback (Lower ranks will be fallbacked to first)\r\n * @param define The name of the define in the shader\r\n */\r\n public addFallback(rank: number, define: string): void {\r\n if (!this._defines[rank]) {\r\n if (rank < this._currentRank) {\r\n this._currentRank = rank;\r\n }\r\n\r\n if (rank > this._maxRank) {\r\n this._maxRank = rank;\r\n }\r\n\r\n this._defines[rank] = new Array();\r\n }\r\n\r\n this._defines[rank].push(define);\r\n }\r\n\r\n /**\r\n * Sets the mesh to use CPU skinning when needing to fallback.\r\n * @param rank The rank of the fallback (Lower ranks will be fallbacked to first)\r\n * @param mesh The mesh to use the fallbacks.\r\n */\r\n public addCPUSkinningFallback(rank: number, mesh: AbstractMesh) {\r\n this._mesh = mesh;\r\n\r\n if (rank < this._currentRank) {\r\n this._currentRank = rank;\r\n }\r\n if (rank > this._maxRank) {\r\n this._maxRank = rank;\r\n }\r\n }\r\n\r\n /**\r\n * Checks to see if more fallbacks are still available.\r\n */\r\n public get hasMoreFallbacks(): boolean {\r\n return this._currentRank <= this._maxRank;\r\n }\r\n\r\n /**\r\n * Removes the defines that should be removed when falling back.\r\n * @param currentDefines defines the current define statements for the shader.\r\n * @param effect defines the current effect we try to compile\r\n * @returns The resulting defines with defines of the current rank removed.\r\n */\r\n public reduce(currentDefines: string, effect: Effect): string {\r\n // First we try to switch to CPU skinning\r\n if (this._mesh && this._mesh.computeBonesUsingShaders && this._mesh.numBoneInfluencers > 0) {\r\n this._mesh.computeBonesUsingShaders = false;\r\n currentDefines = currentDefines.replace(\"#define NUM_BONE_INFLUENCERS \" + this._mesh.numBoneInfluencers, \"#define NUM_BONE_INFLUENCERS 0\");\r\n effect._bonesComputationForcedToCPU = true;\r\n\r\n const scene = this._mesh.getScene();\r\n for (let index = 0; index < scene.meshes.length; index++) {\r\n const otherMesh = scene.meshes[index];\r\n\r\n if (!otherMesh.material) {\r\n if (!this._mesh.material && otherMesh.computeBonesUsingShaders && otherMesh.numBoneInfluencers > 0) {\r\n otherMesh.computeBonesUsingShaders = false;\r\n }\r\n continue;\r\n }\r\n\r\n if (!otherMesh.computeBonesUsingShaders || otherMesh.numBoneInfluencers === 0) {\r\n continue;\r\n }\r\n\r\n if (otherMesh.material.getEffect() === effect) {\r\n otherMesh.computeBonesUsingShaders = false;\r\n } else if (otherMesh.subMeshes) {\r\n for (const subMesh of otherMesh.subMeshes) {\r\n const subMeshEffect = subMesh.effect;\r\n\r\n if (subMeshEffect === effect) {\r\n otherMesh.computeBonesUsingShaders = false;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n const currentFallbacks = this._defines[this._currentRank];\r\n if (currentFallbacks) {\r\n for (let index = 0; index < currentFallbacks.length; index++) {\r\n currentDefines = currentDefines.replace(\"#define \" + currentFallbacks[index], \"\");\r\n }\r\n }\r\n\r\n this._currentRank++;\r\n }\r\n\r\n return currentDefines;\r\n }\r\n}\r\n","import type { ProcessingOptions, ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"./material\";\r\nimport type {\r\n MaterialPluginPrepareEffect,\r\n MaterialPluginBindForSubMesh,\r\n MaterialPluginDisposed,\r\n MaterialPluginGetActiveTextures,\r\n MaterialPluginGetAnimatables,\r\n MaterialPluginGetDefineNames,\r\n MaterialPluginHasTexture,\r\n MaterialPluginIsReadyForSubMesh,\r\n MaterialPluginPrepareDefines,\r\n MaterialPluginPrepareUniformBuffer,\r\n MaterialPluginHardBindForSubMesh,\r\n MaterialPluginHasRenderTargetTextures,\r\n MaterialPluginFillRenderTargetTextures,\r\n} from \"./materialPluginEvent\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\n\r\ndeclare module \"./material\" {\r\n export interface Material {\r\n /**\r\n * Plugin manager for this material\r\n */\r\n pluginManager?: MaterialPluginManager;\r\n }\r\n}\r\n\r\nconst rxOption = new RegExp(\"^([gimus]+)!\");\r\n\r\n/**\r\n * Class that manages the plugins of a material\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginManager {\r\n /** Map a plugin class name to a #define name (used in the vertex/fragment shaders as a marker of the plugin usage) */\r\n private static _MaterialPluginClassToMainDefine: { [name: string]: string } = {};\r\n private static _MaterialPluginCounter: number = 0;\r\n\r\n protected _material: Material;\r\n protected _scene: Scene;\r\n protected _engine: Engine;\r\n /** @internal */\r\n public _plugins: MaterialPluginBase[] = [];\r\n protected _activePlugins: MaterialPluginBase[] = [];\r\n protected _activePluginsForExtraEvents: MaterialPluginBase[] = [];\r\n protected _codeInjectionPoints: { [shaderType: string]: { [codeName: string]: boolean } };\r\n protected _defineNamesFromPlugins?: { [name: string]: { type: string; default: any } };\r\n protected _uboDeclaration: string;\r\n protected _vertexDeclaration: string;\r\n protected _fragmentDeclaration: string;\r\n protected _uniformList: string[];\r\n protected _samplerList: string[];\r\n protected _uboList: string[];\r\n\r\n static {\r\n EngineStore.OnEnginesDisposedObservable.add(() => {\r\n UnregisterAllMaterialPlugins();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a new instance of the plugin manager\r\n * @param material material that this manager will manage the plugins for\r\n */\r\n constructor(material: Material) {\r\n this._material = material;\r\n this._scene = material.getScene();\r\n this._engine = this._scene.getEngine();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _addPlugin(plugin: MaterialPluginBase): boolean {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === plugin.name) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._material._uniformBufferLayoutBuilt) {\r\n throw `The plugin \"${plugin.name}\" can't be added to the material \"${this._material.name}\" because this material has already been used for rendering! Please add plugins to materials before any rendering with this material occurs.`;\r\n }\r\n\r\n const pluginClassName = plugin.getClassName();\r\n if (!MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]) {\r\n MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName] = \"MATERIALPLUGIN_\" + ++MaterialPluginManager._MaterialPluginCounter;\r\n }\r\n\r\n this._material._callbackPluginEventGeneric = this._handlePluginEvent.bind(this);\r\n\r\n this._plugins.push(plugin);\r\n this._plugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._codeInjectionPoints = {};\r\n\r\n const defineNamesFromPlugins: { [name: string]: { type: string; default: any } } = {};\r\n defineNamesFromPlugins[MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]] = {\r\n type: \"boolean\",\r\n default: true,\r\n };\r\n\r\n for (const plugin of this._plugins) {\r\n plugin.collectDefines(defineNamesFromPlugins);\r\n this._collectPointNames(\"vertex\", plugin.getCustomCode(\"vertex\"));\r\n this._collectPointNames(\"fragment\", plugin.getCustomCode(\"fragment\"));\r\n }\r\n\r\n this._defineNamesFromPlugins = defineNamesFromPlugins;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _activatePlugin(plugin: MaterialPluginBase): void {\r\n if (this._activePlugins.indexOf(plugin) === -1) {\r\n this._activePlugins.push(plugin);\r\n this._activePlugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._material._callbackPluginEventIsReadyForSubMesh = this._handlePluginEventIsReadyForSubMesh.bind(this);\r\n this._material._callbackPluginEventPrepareDefinesBeforeAttributes = this._handlePluginEventPrepareDefinesBeforeAttributes.bind(this);\r\n this._material._callbackPluginEventPrepareDefines = this._handlePluginEventPrepareDefines.bind(this);\r\n this._material._callbackPluginEventBindForSubMesh = this._handlePluginEventBindForSubMesh.bind(this);\r\n\r\n if (plugin.registerForExtraEvents) {\r\n this._activePluginsForExtraEvents.push(plugin);\r\n this._activePluginsForExtraEvents.sort((a, b) => a.priority - b.priority);\r\n this._material._callbackPluginEventHasRenderTargetTextures = this._handlePluginEventHasRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventFillRenderTargetTextures = this._handlePluginEventFillRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventHardBindForSubMesh = this._handlePluginEventHardBindForSubMesh.bind(this);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a plugin from the list of plugins managed by this manager\r\n * @param name name of the plugin\r\n * @returns the plugin if found, else null\r\n */\r\n public getPlugin(name: string): Nullable {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === name) {\r\n return this._plugins[i];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n protected _handlePluginEventIsReadyForSubMesh(eventData: MaterialPluginIsReadyForSubMesh): void {\r\n let isReady = true;\r\n for (const plugin of this._activePlugins) {\r\n isReady = isReady && plugin.isReadyForSubMesh(eventData.defines, this._scene, this._engine, eventData.subMesh);\r\n }\r\n eventData.isReadyForSubMesh = isReady;\r\n }\r\n\r\n protected _handlePluginEventPrepareDefinesBeforeAttributes(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefinesBeforeAttributes(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventPrepareDefines(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefines(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHardBindForSubMesh(eventData: MaterialPluginHardBindForSubMesh): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.hardBindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventBindForSubMesh(eventData: MaterialPluginBindForSubMesh): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.bindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHasRenderTargetTextures(eventData: MaterialPluginHasRenderTargetTextures): void {\r\n let hasRenderTargetTextures = false;\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n hasRenderTargetTextures = plugin.hasRenderTargetTextures();\r\n if (hasRenderTargetTextures) {\r\n break;\r\n }\r\n }\r\n eventData.hasRenderTargetTextures = hasRenderTargetTextures;\r\n }\r\n\r\n protected _handlePluginEventFillRenderTargetTextures(eventData: MaterialPluginFillRenderTargetTextures): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.fillRenderTargetTextures(eventData.renderTargets);\r\n }\r\n }\r\n\r\n protected _handlePluginEvent(\r\n id: number,\r\n info:\r\n | MaterialPluginGetActiveTextures\r\n | MaterialPluginGetAnimatables\r\n | MaterialPluginHasTexture\r\n | MaterialPluginDisposed\r\n | MaterialPluginGetDefineNames\r\n | MaterialPluginPrepareEffect\r\n | MaterialPluginPrepareUniformBuffer\r\n ): void {\r\n switch (id) {\r\n case MaterialPluginEvent.GetActiveTextures: {\r\n const eventData = info as MaterialPluginGetActiveTextures;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getActiveTextures(eventData.activeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetAnimatables: {\r\n const eventData = info as MaterialPluginGetAnimatables;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getAnimatables(eventData.animatables);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.HasTexture: {\r\n const eventData = info as MaterialPluginHasTexture;\r\n let hasTexture = false;\r\n for (const plugin of this._activePlugins) {\r\n hasTexture = plugin.hasTexture(eventData.texture);\r\n if (hasTexture) {\r\n break;\r\n }\r\n }\r\n eventData.hasTexture = hasTexture;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.Disposed: {\r\n const eventData = info as MaterialPluginDisposed;\r\n for (const plugin of this._plugins) {\r\n plugin.dispose(eventData.forceDisposeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetDefineNames: {\r\n const eventData = info as MaterialPluginGetDefineNames;\r\n eventData.defineNames = this._defineNamesFromPlugins;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareEffect: {\r\n const eventData = info as MaterialPluginPrepareEffect;\r\n for (const plugin of this._activePlugins) {\r\n eventData.fallbackRank = plugin.addFallbacks(eventData.defines, eventData.fallbacks, eventData.fallbackRank);\r\n plugin.getAttributes(eventData.attributes, this._scene, eventData.mesh);\r\n }\r\n if (this._uniformList.length > 0) {\r\n eventData.uniforms.push(...this._uniformList);\r\n }\r\n if (this._samplerList.length > 0) {\r\n eventData.samplers.push(...this._samplerList);\r\n }\r\n if (this._uboList.length > 0) {\r\n eventData.uniformBuffersNames.push(...this._uboList);\r\n }\r\n eventData.customCode = this._injectCustomCode(eventData, eventData.customCode);\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareUniformBuffer: {\r\n const eventData = info as MaterialPluginPrepareUniformBuffer;\r\n this._uboDeclaration = \"\";\r\n this._vertexDeclaration = \"\";\r\n this._fragmentDeclaration = \"\";\r\n this._uniformList = [];\r\n this._samplerList = [];\r\n this._uboList = [];\r\n for (const plugin of this._plugins) {\r\n const uniforms = plugin.getUniforms();\r\n if (uniforms) {\r\n if (uniforms.ubo) {\r\n for (const uniform of uniforms.ubo) {\r\n if (uniform.size && uniform.type) {\r\n const arraySize = uniform.arraySize ?? 0;\r\n eventData.ubo.addUniform(uniform.name, uniform.size, arraySize);\r\n this._uboDeclaration += `${uniform.type} ${uniform.name}${arraySize > 0 ? `[${arraySize}]` : \"\"};\\n`;\r\n }\r\n this._uniformList.push(uniform.name);\r\n }\r\n }\r\n if (uniforms.vertex) {\r\n this._vertexDeclaration += uniforms.vertex + \"\\n\";\r\n }\r\n if (uniforms.fragment) {\r\n this._fragmentDeclaration += uniforms.fragment + \"\\n\";\r\n }\r\n }\r\n plugin.getSamplers(this._samplerList);\r\n plugin.getUniformBuffersNames(this._uboList);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n protected _collectPointNames(shaderType: string, customCode: Nullable<{ [pointName: string]: string }> | undefined): void {\r\n if (!customCode) {\r\n return;\r\n }\r\n for (const pointName in customCode) {\r\n if (!this._codeInjectionPoints[shaderType]) {\r\n this._codeInjectionPoints[shaderType] = {};\r\n }\r\n this._codeInjectionPoints[shaderType][pointName] = true;\r\n }\r\n }\r\n\r\n protected _injectCustomCode(eventData: MaterialPluginPrepareEffect, existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction {\r\n return (shaderType: string, code: string) => {\r\n if (existingCallback) {\r\n code = existingCallback(shaderType, code);\r\n }\r\n if (this._uboDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_UBO_DECLARATION\", this._uboDeclaration);\r\n }\r\n if (this._vertexDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_VERTEX_DECLARATION\", this._vertexDeclaration);\r\n }\r\n if (this._fragmentDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_FRAGMENT_DECLARATION\", this._fragmentDeclaration);\r\n }\r\n const points = this._codeInjectionPoints?.[shaderType];\r\n if (!points) {\r\n return code;\r\n }\r\n let processorOptions: Nullable = null;\r\n for (let pointName in points) {\r\n let injectedCode = \"\";\r\n for (const plugin of this._activePlugins) {\r\n let customCode = plugin.getCustomCode(shaderType)?.[pointName];\r\n if (!customCode) {\r\n continue;\r\n }\r\n if (plugin.resolveIncludes) {\r\n if (processorOptions === null) {\r\n const shaderLanguage = ShaderLanguage.GLSL;\r\n processorOptions = {\r\n defines: [], // not used by _ProcessIncludes\r\n indexParameters: eventData.indexParameters,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\r\n processor: undefined as any, // not used by _ProcessIncludes\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: ShaderStore.GetShadersRepository(shaderLanguage),\r\n includesShadersStore: ShaderStore.GetIncludesShadersStore(shaderLanguage),\r\n version: undefined as any, // not used by _ProcessIncludes\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: undefined as any, // not used by _ProcessIncludes\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n processCodeAfterIncludes: undefined as any, // not used by _ProcessIncludes\r\n };\r\n }\r\n processorOptions.isFragment = shaderType === \"fragment\";\r\n ShaderProcessor._ProcessIncludes(customCode, processorOptions, (code) => (customCode = code));\r\n }\r\n injectedCode += customCode + \"\\n\";\r\n }\r\n if (injectedCode.length > 0) {\r\n if (pointName.charAt(0) === \"!\") {\r\n // pointName is a regular expression\r\n pointName = pointName.substring(1);\r\n\r\n let regexFlags = \"g\";\r\n if (pointName.charAt(0) === \"!\") {\r\n // no flags\r\n regexFlags = \"\";\r\n pointName = pointName.substring(1);\r\n } else {\r\n // get the flag(s)\r\n const matchOption = rxOption.exec(pointName);\r\n if (matchOption && matchOption.length >= 2) {\r\n regexFlags = matchOption[1];\r\n pointName = pointName.substring(regexFlags.length + 1);\r\n }\r\n }\r\n\r\n if (regexFlags.indexOf(\"g\") < 0) {\r\n // we force the \"g\" flag so that the regexp object is stateful!\r\n regexFlags += \"g\";\r\n }\r\n\r\n const sourceCode = code;\r\n const rx = new RegExp(pointName, regexFlags);\r\n let match = rx.exec(sourceCode);\r\n while (match !== null) {\r\n let newCode = injectedCode;\r\n for (let i = 0; i < match.length; ++i) {\r\n newCode = newCode.replace(\"$\" + i, match[i]);\r\n }\r\n code = code.replace(match[0], newCode);\r\n match = rx.exec(sourceCode);\r\n }\r\n } else {\r\n const fullPointName = \"#define \" + pointName;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n }\r\n return code;\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Type for plugin material factories.\r\n */\r\nexport type PluginMaterialFactory = (material: Material) => Nullable;\r\n\r\nconst plugins: Array<[string, PluginMaterialFactory]> = [];\r\nlet inited = false;\r\nlet observer: Nullable> = null;\r\n\r\n/**\r\n * Registers a new material plugin through a factory, or updates it. This makes the plugin available to all materials instantiated after its registration.\r\n * @param pluginName The plugin name\r\n * @param factory The factory function which allows to create the plugin\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterMaterialPlugin(pluginName: string, factory: PluginMaterialFactory): void {\r\n if (!inited) {\r\n observer = Material.OnEventObservable.add((material: Material) => {\r\n for (const [, factory] of plugins) {\r\n factory(material);\r\n }\r\n }, MaterialPluginEvent.Created);\r\n inited = true;\r\n }\r\n const existing = plugins.filter(([name, _factory]) => name === pluginName);\r\n if (existing.length > 0) {\r\n existing[0][1] = factory;\r\n } else {\r\n plugins.push([pluginName, factory]);\r\n }\r\n}\r\n\r\n/**\r\n * Removes a material plugin from the list of global plugins.\r\n * @param pluginName The plugin name\r\n * @returns true if the plugin has been removed, else false\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterMaterialPlugin(pluginName: string): boolean {\r\n for (let i = 0; i < plugins.length; ++i) {\r\n if (plugins[i][0] === pluginName) {\r\n plugins.splice(i, 1);\r\n if (plugins.length === 0) {\r\n UnregisterAllMaterialPlugins();\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Clear the list of global material plugins\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterAllMaterialPlugins(): void {\r\n plugins.length = 0;\r\n inited = false;\r\n Material.OnEventObservable.remove(observer);\r\n observer = null;\r\n}\r\n","import { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport { MaterialPluginManager } from \"./materialPluginManager\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { MaterialDefines } from \"./materialDefines\";\r\nimport type { Material } from \"./material\";\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { RenderTargetTexture } from \"./Textures/renderTargetTexture\";\r\n\r\n/**\r\n * Base class for material plugins.\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginBase {\r\n /**\r\n * Defines the name of the plugin\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Defines the priority of the plugin. Lower numbers run first.\r\n */\r\n @serialize()\r\n public priority: number = 500;\r\n\r\n /**\r\n * Indicates that any #include directive in the plugin code must be replaced by the corresponding code.\r\n */\r\n @serialize()\r\n public resolveIncludes: boolean = false;\r\n\r\n /**\r\n * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)\r\n */\r\n @serialize()\r\n public registerForExtraEvents: boolean = false;\r\n\r\n protected _material: Material;\r\n protected _pluginManager: MaterialPluginManager;\r\n protected _pluginDefineNames?: { [name: string]: any };\r\n\r\n protected _enable(enable: boolean) {\r\n if (enable) {\r\n this._pluginManager._activatePlugin(this);\r\n }\r\n }\r\n\r\n /**\r\n * Helper function to mark defines as being dirty.\r\n */\r\n public readonly markAllDefinesAsDirty: () => void;\r\n\r\n /**\r\n * Creates a new material plugin\r\n * @param material parent material of the plugin\r\n * @param name name of the plugin\r\n * @param priority priority of the plugin\r\n * @param defines list of defines used by the plugin. The value of the property is the default value for this property\r\n * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)\r\n * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)\r\n * @param resolveIncludes Indicates that any #include directive in the plugin code must be replaced by the corresponding code (default: false)\r\n */\r\n constructor(material: Material, name: string, priority: number, defines?: { [key: string]: any }, addToPluginList = true, enable = false, resolveIncludes = false) {\r\n this._material = material;\r\n this.name = name;\r\n this.priority = priority;\r\n this.resolveIncludes = resolveIncludes;\r\n\r\n if (!material.pluginManager) {\r\n material.pluginManager = new MaterialPluginManager(material);\r\n material.onDisposeObservable.add(() => {\r\n material.pluginManager = undefined;\r\n });\r\n }\r\n\r\n this._pluginDefineNames = defines;\r\n this._pluginManager = material.pluginManager;\r\n\r\n if (addToPluginList) {\r\n this._pluginManager._addPlugin(this);\r\n }\r\n\r\n if (enable) {\r\n this._enable(true);\r\n }\r\n\r\n this.markAllDefinesAsDirty = material._dirtyCallbacks[Constants.MATERIAL_AllDirtyFlag];\r\n }\r\n\r\n /**\r\n * Gets the current class name useful for serialization or dynamic coding.\r\n * @returns The class name.\r\n */\r\n public getClassName(): string {\r\n return \"MaterialPluginBase\";\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used.\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine the engine this scene belongs to.\r\n * @param subMesh the submesh to check for readiness\r\n * @returns - boolean indicating that the submesh is ready or not.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isReadyForSubMesh(defines: MaterialDefines, scene: Scene, engine: Engine, subMesh: SubMesh): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Binds the material data (this function is called even if mustRebind() returns false)\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine defines the engine the material belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {}\r\n\r\n /**\r\n * Binds the material data.\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine the engine this scene belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {}\r\n\r\n /**\r\n * Disposes the resources of the material.\r\n * @param forceDisposeTextures - Forces the disposal of all textures.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public dispose(forceDisposeTextures?: boolean): void {}\r\n\r\n /**\r\n * Returns a list of custom shader code fragments to customize the shader.\r\n * @param shaderType \"vertex\" or \"fragment\"\r\n * @returns null if no code to be added, or a list of pointName =\\> code.\r\n * Note that `pointName` can also be a regular expression if it starts with a `!`.\r\n * In that case, the string found by the regular expression (if any) will be\r\n * replaced by the code provided.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getCustomCode(shaderType: string): Nullable<{ [pointName: string]: string }> {\r\n return null;\r\n }\r\n\r\n /**\r\n * Collects all defines.\r\n * @param defines The object to append to.\r\n */\r\n public collectDefines(defines: { [name: string]: { type: string; default: any } }): void {\r\n if (!this._pluginDefineNames) {\r\n return;\r\n }\r\n for (const key of Object.keys(this._pluginDefineNames)) {\r\n if (key[0] === \"_\") {\r\n continue;\r\n }\r\n\r\n const type = typeof this._pluginDefineNames[key];\r\n defines[key] = {\r\n type: type === \"number\" ? \"number\" : type === \"string\" ? \"string\" : type === \"boolean\" ? \"boolean\" : \"object\",\r\n default: this._pluginDefineNames[key],\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Sets the defines for the next rendering. Called before MaterialHelper.PrepareDefinesForAttributes is called.\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene to the material belongs to.\r\n * @param mesh the mesh being rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefinesBeforeAttributes(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Sets the defines for the next rendering\r\n * @param defines the list of \"defines\" to update.\r\n * @param scene defines the scene to the material belongs to.\r\n * @param mesh the mesh being rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefines(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Checks to see if a texture is used in the material.\r\n * @param texture - Base texture to use.\r\n * @returns - Boolean specifying if a texture is used in the material.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public hasTexture(texture: BaseTexture): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n * @returns true if this uses a render target otherwise false.\r\n */\r\n public hasRenderTargetTextures(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Fills the list of render target textures.\r\n * @param renderTargets the list of render targets to update\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public fillRenderTargetTextures(renderTargets: SmartArray): void {}\r\n\r\n /**\r\n * Returns an array of the actively used textures.\r\n * @param activeTextures Array of BaseTextures\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {}\r\n\r\n /**\r\n * Returns the animatable textures.\r\n * @param animatables Array of animatable textures.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getAnimatables(animatables: IAnimatable[]): void {}\r\n\r\n /**\r\n * Add fallbacks to the effect fallbacks list.\r\n * @param defines defines the Base texture to use.\r\n * @param fallbacks defines the current fallback list.\r\n * @param currentRank defines the current fallback rank.\r\n * @returns the new fallback rank.\r\n */\r\n public addFallbacks(defines: MaterialDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n return currentRank;\r\n }\r\n\r\n /**\r\n * Gets the samplers used by the plugin.\r\n * @param samplers list that the sampler names should be added to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getSamplers(samplers: string[]): void {}\r\n\r\n /**\r\n * Gets the attributes used by the plugin.\r\n * @param attributes list that the attribute names should be added to.\r\n * @param scene the scene that the material belongs to.\r\n * @param mesh the mesh being rendered.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getAttributes(attributes: string[], scene: Scene, mesh: AbstractMesh): void {}\r\n\r\n /**\r\n * Gets the uniform buffers names added by the plugin.\r\n * @param ubos list that the ubo names should be added to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getUniformBuffersNames(ubos: string[]): void {}\r\n\r\n /**\r\n * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)\r\n * @returns the description of the uniforms\r\n */\r\n public getUniforms(): { ubo?: Array<{ name: string; size?: number; type?: string; arraySize?: number }>; vertex?: string; fragment?: string } {\r\n return {};\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the current configuration into another one.\r\n * @param plugin define the config where to copy the info\r\n */\r\n public copyTo(plugin: MaterialPluginBase): void {\r\n SerializationHelper.Clone(() => plugin, this);\r\n }\r\n\r\n /**\r\n * Serializes this plugin configuration.\r\n * @returns - An object with the serialized config.\r\n */\r\n public serialize(): any {\r\n return SerializationHelper.Serialize(this);\r\n }\r\n\r\n /**\r\n * Parses a plugin configuration from a serialized object.\r\n * @param source - Serialized object.\r\n * @param scene Defines the scene we are parsing for\r\n * @param rootUrl Defines the rootUrl to load from\r\n */\r\n public parse(source: any, scene: Scene, rootUrl: string): void {\r\n SerializationHelper.Parse(() => this, source, scene, rootUrl);\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"./material\";\r\nimport { serialize, expandToProperty, serializeAsTexture } from \"../Misc/decorators\";\r\nimport { MaterialFlags } from \"./materialFlags\";\r\nimport { MaterialHelper } from \"./materialHelper\";\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport { MaterialDefines } from \"./materialDefines\";\r\nimport { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { StandardMaterial } from \"./standardMaterial\";\r\nimport type { PBRBaseMaterial } from \"./PBR/pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialDetailMapDefines extends MaterialDefines {\r\n DETAIL = false;\r\n DETAILDIRECTUV = 0;\r\n DETAIL_NORMALBLENDMETHOD = 0;\r\n}\r\n\r\n/**\r\n * Plugin that implements the detail map component of a material\r\n *\r\n * Inspired from:\r\n * Unity: https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@9.0/manual/Mask-Map-and-Detail-Map.html and https://docs.unity3d.com/Manual/StandardShaderMaterialParameterDetail.html\r\n * Unreal: https://docs.unrealengine.com/en-US/Engine/Rendering/Materials/HowTo/DetailTexturing/index.html\r\n * Cryengine: https://docs.cryengine.com/display/SDKDOC2/Detail+Maps\r\n */\r\nexport class DetailMapConfiguration extends MaterialPluginBase {\r\n private _texture: Nullable = null;\r\n /**\r\n * The detail texture of the material.\r\n */\r\n @serializeAsTexture(\"detailTexture\")\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public texture: Nullable;\r\n\r\n /**\r\n * Defines how strongly the detail diffuse/albedo channel is blended with the regular diffuse/albedo texture\r\n * Bigger values mean stronger blending\r\n */\r\n @serialize()\r\n public diffuseBlendLevel = 1;\r\n\r\n /**\r\n * Defines how strongly the detail roughness channel is blended with the regular roughness value\r\n * Bigger values mean stronger blending. Only used with PBR materials\r\n */\r\n @serialize()\r\n public roughnessBlendLevel = 1;\r\n\r\n /**\r\n * Defines how strong the bump effect from the detail map is\r\n * Bigger values mean stronger effect\r\n */\r\n @serialize()\r\n public bumpLevel = 1;\r\n\r\n private _normalBlendMethod = Material.MATERIAL_NORMALBLENDMETHOD_WHITEOUT;\r\n /**\r\n * The method used to blend the bump and detail normals together\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public normalBlendMethod: number;\r\n\r\n private _isEnabled = false;\r\n /**\r\n * Enable or disable the detail map on this material\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial | StandardMaterial, addToPluginList = true) {\r\n super(material, \"DetailMap\", 140, new MaterialDetailMapDefines(), addToPluginList);\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: MaterialDetailMapDefines, scene: Scene, engine: Engine): boolean {\r\n if (!this._isEnabled) {\r\n return true;\r\n }\r\n\r\n if (defines._areTexturesDirty && scene.texturesEnabled) {\r\n if (engine.getCaps().standardDerivatives && this._texture && MaterialFlags.DetailTextureEnabled) {\r\n // Detail texture cannot be not blocking.\r\n if (!this._texture.isReady()) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public prepareDefines(defines: MaterialDetailMapDefines, scene: Scene): void {\r\n if (this._isEnabled) {\r\n defines.DETAIL_NORMALBLENDMETHOD = this._normalBlendMethod;\r\n\r\n const engine = scene.getEngine();\r\n\r\n if (defines._areTexturesDirty) {\r\n if (engine.getCaps().standardDerivatives && this._texture && MaterialFlags.DetailTextureEnabled && this._isEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"DETAIL\");\r\n defines.DETAIL_NORMALBLENDMETHOD = this._normalBlendMethod;\r\n } else {\r\n defines.DETAIL = false;\r\n }\r\n }\r\n } else {\r\n defines.DETAIL = false;\r\n }\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene): void {\r\n if (!this._isEnabled) {\r\n return;\r\n }\r\n\r\n const isFrozen = this._material.isFrozen;\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n if (this._texture && MaterialFlags.DetailTextureEnabled) {\r\n uniformBuffer.updateFloat4(\"vDetailInfos\", this._texture.coordinatesIndex, this.diffuseBlendLevel, this.bumpLevel, this.roughnessBlendLevel);\r\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"detail\");\r\n }\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.DetailTextureEnabled) {\r\n uniformBuffer.setTexture(\"detailSampler\", this._texture);\r\n }\r\n }\r\n }\r\n\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (this._texture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._texture) {\r\n activeTextures.push(this._texture);\r\n }\r\n }\r\n\r\n public getAnimatables(animatables: IAnimatable[]): void {\r\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\r\n animatables.push(this._texture);\r\n }\r\n }\r\n\r\n public dispose(forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n this._texture?.dispose();\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return \"DetailMapConfiguration\";\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"detailSampler\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vDetailInfos\", size: 4, type: \"vec4\" },\r\n { name: \"detailMatrix\", size: 16, type: \"mat4\" },\r\n ],\r\n };\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { serialize, SerializationHelper, serializeAsColor3, expandToProperty, serializeAsFresnelParameters, serializeAsTexture } from \"../Misc/decorators\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { SmartArray } from \"../Misc/smartArray\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\n\r\nimport type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport { Matrix } from \"../Maths/math.vector\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { PrePassConfiguration } from \"./prePassConfiguration\";\r\n\r\nimport type { IImageProcessingConfigurationDefines } from \"./imageProcessingConfiguration\";\r\nimport { ImageProcessingConfiguration } from \"./imageProcessingConfiguration\";\r\nimport type { ColorCurves } from \"./colorCurves\";\r\nimport type { FresnelParameters } from \"./fresnelParameters\";\r\nimport type { ICustomShaderNameResolveOptions } from \"../Materials/material\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport { MaterialDefines } from \"../Materials/materialDefines\";\r\nimport { PushMaterial } from \"./pushMaterial\";\r\nimport { MaterialHelper } from \"./materialHelper\";\r\n\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { CubeTexture } from \"../Materials/Textures/cubeTexture\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport { MaterialFlags } from \"./materialFlags\";\r\n\r\nimport \"../Shaders/default.fragment\";\r\nimport \"../Shaders/default.vertex\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectFallbacks } from \"./effectFallbacks\";\r\nimport type { Effect, IEffectCreationOptions } from \"./effect\";\r\nimport { DetailMapConfiguration } from \"./material.detailMapConfiguration\";\r\nimport { addClipPlaneUniforms, bindClipPlane } from \"./clipPlaneMaterialHelper\";\r\n\r\nconst onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable };\r\n\r\n/** @internal */\r\nexport class StandardMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {\r\n public MAINUV1 = false;\r\n public MAINUV2 = false;\r\n public MAINUV3 = false;\r\n public MAINUV4 = false;\r\n public MAINUV5 = false;\r\n public MAINUV6 = false;\r\n public DIFFUSE = false;\r\n public DIFFUSEDIRECTUV = 0;\r\n public BAKED_VERTEX_ANIMATION_TEXTURE = false;\r\n public AMBIENT = false;\r\n public AMBIENTDIRECTUV = 0;\r\n public OPACITY = false;\r\n public OPACITYDIRECTUV = 0;\r\n public OPACITYRGB = false;\r\n public REFLECTION = false;\r\n public EMISSIVE = false;\r\n public EMISSIVEDIRECTUV = 0;\r\n public SPECULAR = false;\r\n public SPECULARDIRECTUV = 0;\r\n public BUMP = false;\r\n public BUMPDIRECTUV = 0;\r\n public PARALLAX = false;\r\n public PARALLAXOCCLUSION = false;\r\n public SPECULAROVERALPHA = false;\r\n public CLIPPLANE = false;\r\n public CLIPPLANE2 = false;\r\n public CLIPPLANE3 = false;\r\n public CLIPPLANE4 = false;\r\n public CLIPPLANE5 = false;\r\n public CLIPPLANE6 = false;\r\n public ALPHATEST = false;\r\n public DEPTHPREPASS = false;\r\n public ALPHAFROMDIFFUSE = false;\r\n public POINTSIZE = false;\r\n public FOG = false;\r\n public SPECULARTERM = false;\r\n public DIFFUSEFRESNEL = false;\r\n public OPACITYFRESNEL = false;\r\n public REFLECTIONFRESNEL = false;\r\n public REFRACTIONFRESNEL = false;\r\n public EMISSIVEFRESNEL = false;\r\n public FRESNEL = false;\r\n public NORMAL = false;\r\n public TANGENT = false;\r\n public UV1 = false;\r\n public UV2 = false;\r\n public UV3 = false;\r\n public UV4 = false;\r\n public UV5 = false;\r\n public UV6 = false;\r\n public VERTEXCOLOR = false;\r\n public VERTEXALPHA = false;\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public BONETEXTURE = false;\r\n public BONES_VELOCITY_ENABLED = false;\r\n public INSTANCES = false;\r\n public THIN_INSTANCES = false;\r\n public INSTANCESCOLOR = false;\r\n public GLOSSINESS = false;\r\n public ROUGHNESS = false;\r\n public EMISSIVEASILLUMINATION = false;\r\n public LINKEMISSIVEWITHDIFFUSE = false;\r\n public REFLECTIONFRESNELFROMSPECULAR = false;\r\n public LIGHTMAP = false;\r\n public LIGHTMAPDIRECTUV = 0;\r\n public OBJECTSPACE_NORMALMAP = false;\r\n public USELIGHTMAPASSHADOWMAP = false;\r\n public REFLECTIONMAP_3D = false;\r\n public REFLECTIONMAP_SPHERICAL = false;\r\n public REFLECTIONMAP_PLANAR = false;\r\n public REFLECTIONMAP_CUBIC = false;\r\n public USE_LOCAL_REFLECTIONMAP_CUBIC = false;\r\n public USE_LOCAL_REFRACTIONMAP_CUBIC = false;\r\n public REFLECTIONMAP_PROJECTION = false;\r\n public REFLECTIONMAP_SKYBOX = false;\r\n public REFLECTIONMAP_EXPLICIT = false;\r\n public REFLECTIONMAP_EQUIRECTANGULAR = false;\r\n public REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\r\n public REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\r\n public REFLECTIONMAP_OPPOSITEZ = false;\r\n public INVERTCUBICMAP = false;\r\n public LOGARITHMICDEPTH = false;\r\n public REFRACTION = false;\r\n public REFRACTIONMAP_3D = false;\r\n public REFLECTIONOVERALPHA = false;\r\n public TWOSIDEDLIGHTING = false;\r\n public SHADOWFLOAT = false;\r\n public MORPHTARGETS = false;\r\n public MORPHTARGETS_NORMAL = false;\r\n public MORPHTARGETS_TANGENT = false;\r\n public MORPHTARGETS_UV = false;\r\n public NUM_MORPH_INFLUENCERS = 0;\r\n public MORPHTARGETS_TEXTURE = false;\r\n public NONUNIFORMSCALING = false; // https://playground.babylonjs.com#V6DWIH\r\n public PREMULTIPLYALPHA = false; // https://playground.babylonjs.com#LNVJJ7\r\n public ALPHATEST_AFTERALLALPHACOMPUTATIONS = false;\r\n public ALPHABLEND = true;\r\n\r\n public PREPASS = false;\r\n public PREPASS_IRRADIANCE = false;\r\n public PREPASS_IRRADIANCE_INDEX = -1;\r\n public PREPASS_ALBEDO_SQRT = false;\r\n public PREPASS_ALBEDO_SQRT_INDEX = -1;\r\n public PREPASS_DEPTH = false;\r\n public PREPASS_DEPTH_INDEX = -1;\r\n public PREPASS_NORMAL = false;\r\n public PREPASS_NORMAL_INDEX = -1;\r\n public PREPASS_POSITION = false;\r\n public PREPASS_POSITION_INDEX = -1;\r\n public PREPASS_VELOCITY = false;\r\n public PREPASS_VELOCITY_INDEX = -1;\r\n public PREPASS_REFLECTIVITY = false;\r\n public PREPASS_REFLECTIVITY_INDEX = -1;\r\n public SCENE_MRT_COUNT = 0;\r\n\r\n public RGBDLIGHTMAP = false;\r\n public RGBDREFLECTION = false;\r\n public RGBDREFRACTION = false;\r\n\r\n public IMAGEPROCESSING = false;\r\n public VIGNETTE = false;\r\n public VIGNETTEBLENDMODEMULTIPLY = false;\r\n public VIGNETTEBLENDMODEOPAQUE = false;\r\n public TONEMAPPING = false;\r\n public TONEMAPPING_ACES = false;\r\n public CONTRAST = false;\r\n public COLORCURVES = false;\r\n public COLORGRADING = false;\r\n public COLORGRADING3D = false;\r\n public SAMPLER3DGREENDEPTH = false;\r\n public SAMPLER3DBGRMAP = false;\r\n public DITHER = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n public MULTIVIEW = false;\r\n public ORDER_INDEPENDENT_TRANSPARENCY = false;\r\n public ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;\r\n public CAMERA_ORTHOGRAPHIC = false;\r\n public CAMERA_PERSPECTIVE = false;\r\n\r\n /**\r\n * If the reflection texture on this material is in linear color space\r\n * @internal\r\n */\r\n public IS_REFLECTION_LINEAR = false;\r\n /**\r\n * If the refraction texture on this material is in linear color space\r\n * @internal\r\n */\r\n public IS_REFRACTION_LINEAR = false;\r\n public EXPOSURE = false;\r\n\r\n public DECAL_AFTER_DETAIL = false;\r\n\r\n /**\r\n * Initializes the Standard Material defines.\r\n * @param externalProperties The external properties\r\n */\r\n constructor(externalProperties?: { [name: string]: { type: string; default: any } }) {\r\n super(externalProperties);\r\n this.rebuild();\r\n }\r\n\r\n public setReflectionMode(modeToEnable: string) {\r\n const modes = [\r\n \"REFLECTIONMAP_CUBIC\",\r\n \"REFLECTIONMAP_EXPLICIT\",\r\n \"REFLECTIONMAP_PLANAR\",\r\n \"REFLECTIONMAP_PROJECTION\",\r\n \"REFLECTIONMAP_PROJECTION\",\r\n \"REFLECTIONMAP_SKYBOX\",\r\n \"REFLECTIONMAP_SPHERICAL\",\r\n \"REFLECTIONMAP_EQUIRECTANGULAR\",\r\n \"REFLECTIONMAP_EQUIRECTANGULAR_FIXED\",\r\n \"REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\",\r\n ];\r\n\r\n for (const mode of modes) {\r\n (this)[mode] = mode === modeToEnable;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * This is the default material used in Babylon. It is the best trade off between quality\r\n * and performances.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction\r\n */\r\nexport class StandardMaterial extends PushMaterial {\r\n @serializeAsTexture(\"diffuseTexture\")\r\n private _diffuseTexture: Nullable = null;\r\n /**\r\n * The basic texture of the material as viewed under a light.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public diffuseTexture: Nullable;\r\n\r\n @serializeAsTexture(\"ambientTexture\")\r\n private _ambientTexture: Nullable = null;\r\n /**\r\n * AKA Occlusion Texture in other nomenclature, it helps adding baked shadows into your material.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public ambientTexture: Nullable;\r\n\r\n @serializeAsTexture(\"opacityTexture\")\r\n private _opacityTexture: Nullable = null;\r\n /**\r\n * Define the transparency of the material from a texture.\r\n * The final alpha value can be read either from the red channel (if texture.getAlphaFromRGB is false)\r\n * or from the luminance or the current texel (if texture.getAlphaFromRGB is true)\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public opacityTexture: Nullable;\r\n\r\n @serializeAsTexture(\"reflectionTexture\")\r\n private _reflectionTexture: Nullable = null;\r\n /**\r\n * Define the texture used to display the reflection.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#how-to-obtain-reflections-and-refractions\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionTexture: Nullable;\r\n\r\n @serializeAsTexture(\"emissiveTexture\")\r\n private _emissiveTexture: Nullable = null;\r\n /**\r\n * Define texture of the material as if self lit.\r\n * This will be mixed in the final result even in the absence of light.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public emissiveTexture: Nullable;\r\n\r\n @serializeAsTexture(\"specularTexture\")\r\n private _specularTexture: Nullable = null;\r\n /**\r\n * Define how the color and intensity of the highlight given by the light in the material.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public specularTexture: Nullable;\r\n\r\n @serializeAsTexture(\"bumpTexture\")\r\n private _bumpTexture: Nullable = null;\r\n /**\r\n * Bump mapping is a technique to simulate bump and dents on a rendered surface.\r\n * These are made by creating a normal map from an image. The means to do this can be found on the web, a search for 'normal map generator' will bring up free and paid for methods of doing this.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/moreMaterials#bump-map\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public bumpTexture: Nullable;\r\n\r\n @serializeAsTexture(\"lightmapTexture\")\r\n private _lightmapTexture: Nullable = null;\r\n /**\r\n * Complex lighting can be computationally expensive to compute at runtime.\r\n * To save on computation, lightmaps may be used to store calculated lighting in a texture which will be applied to a given mesh.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction#lightmaps\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public lightmapTexture: Nullable;\r\n\r\n @serializeAsTexture(\"refractionTexture\")\r\n private _refractionTexture: Nullable = null;\r\n /**\r\n * Define the texture used to display the refraction.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#how-to-obtain-reflections-and-refractions\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public refractionTexture: Nullable;\r\n\r\n /**\r\n * The color of the material lit by the environmental background lighting.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#ambient-color-example\r\n */\r\n @serializeAsColor3(\"ambient\")\r\n public ambientColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * The basic color of the material as viewed under a light.\r\n */\r\n @serializeAsColor3(\"diffuse\")\r\n public diffuseColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * Define how the color and intensity of the highlight given by the light in the material.\r\n */\r\n @serializeAsColor3(\"specular\")\r\n public specularColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * Define the color of the material as if self lit.\r\n * This will be mixed in the final result even in the absence of light.\r\n */\r\n @serializeAsColor3(\"emissive\")\r\n public emissiveColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * Defines how sharp are the highlights in the material.\r\n * The bigger the value the sharper giving a more glossy feeling to the result.\r\n * Reversely, the smaller the value the blurrier giving a more rough feeling to the result.\r\n */\r\n @serialize()\r\n public specularPower = 64;\r\n\r\n @serialize(\"useAlphaFromDiffuseTexture\")\r\n private _useAlphaFromDiffuseTexture = false;\r\n /**\r\n * Does the transparency come from the diffuse texture alpha channel.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public useAlphaFromDiffuseTexture: boolean;\r\n\r\n @serialize(\"useEmissiveAsIllumination\")\r\n private _useEmissiveAsIllumination = false;\r\n /**\r\n * If true, the emissive value is added into the end result, otherwise it is multiplied in.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useEmissiveAsIllumination: boolean;\r\n\r\n @serialize(\"linkEmissiveWithDiffuse\")\r\n private _linkEmissiveWithDiffuse = false;\r\n /**\r\n * If true, some kind of energy conservation will prevent the end result to be more than 1 by reducing\r\n * the emissive level when the final color is close to one.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public linkEmissiveWithDiffuse: boolean;\r\n\r\n @serialize(\"useSpecularOverAlpha\")\r\n private _useSpecularOverAlpha = false;\r\n /**\r\n * Specifies that the material will keep the specular highlights over a transparent surface (only the most luminous ones).\r\n * A car glass is a good exemple of that. When sun reflects on it you can not see what is behind.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useSpecularOverAlpha: boolean;\r\n\r\n @serialize(\"useReflectionOverAlpha\")\r\n private _useReflectionOverAlpha = false;\r\n /**\r\n * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most luminous ones).\r\n * A car glass is a good exemple of that. When the street lights reflects on it you can not see what is behind.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useReflectionOverAlpha: boolean;\r\n\r\n @serialize(\"disableLighting\")\r\n private _disableLighting = false;\r\n /**\r\n * Does lights from the scene impacts this material.\r\n * It can be a nice trick for performance to disable lighting on a fully emissive material.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public disableLighting: boolean;\r\n\r\n @serialize(\"useObjectSpaceNormalMap\")\r\n private _useObjectSpaceNormalMap = false;\r\n /**\r\n * Allows using an object space normal map (instead of tangent space).\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useObjectSpaceNormalMap: boolean;\r\n\r\n @serialize(\"useParallax\")\r\n private _useParallax = false;\r\n /**\r\n * Is parallax enabled or not.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/parallaxMapping\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useParallax: boolean;\r\n\r\n @serialize(\"useParallaxOcclusion\")\r\n private _useParallaxOcclusion = false;\r\n /**\r\n * Is parallax occlusion enabled or not.\r\n * If true, the outcome is way more realistic than traditional Parallax but you can expect a performance hit that worthes consideration.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/parallaxMapping\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useParallaxOcclusion: boolean;\r\n\r\n /**\r\n * Apply a scaling factor that determine which \"depth\" the height map should reprensent. A value between 0.05 and 0.1 is reasonnable in Parallax, you can reach 0.2 using Parallax Occlusion.\r\n */\r\n @serialize()\r\n public parallaxScaleBias = 0.05;\r\n\r\n @serialize(\"roughness\")\r\n private _roughness = 0;\r\n /**\r\n * Helps to define how blurry the reflections should appears in the material.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public roughness: number;\r\n\r\n /**\r\n * In case of refraction, define the value of the index of refraction.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#how-to-obtain-reflections-and-refractions\r\n */\r\n @serialize()\r\n public indexOfRefraction = 0.98;\r\n\r\n /**\r\n * Invert the refraction texture alongside the y axis.\r\n * It can be useful with procedural textures or probe for instance.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#how-to-obtain-reflections-and-refractions\r\n */\r\n @serialize()\r\n public invertRefractionY = true;\r\n\r\n /**\r\n * Defines the alpha limits in alpha test mode.\r\n */\r\n @serialize()\r\n public alphaCutOff = 0.4;\r\n\r\n @serialize(\"useLightmapAsShadowmap\")\r\n private _useLightmapAsShadowmap = false;\r\n /**\r\n * In case of light mapping, define whether the map contains light or shadow informations.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useLightmapAsShadowmap: boolean;\r\n\r\n // Fresnel\r\n @serializeAsFresnelParameters(\"diffuseFresnelParameters\")\r\n private _diffuseFresnelParameters: FresnelParameters;\r\n /**\r\n * Define the diffuse fresnel parameters of the material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/fresnelParameters\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\r\n public diffuseFresnelParameters: FresnelParameters;\r\n\r\n @serializeAsFresnelParameters(\"opacityFresnelParameters\")\r\n private _opacityFresnelParameters: FresnelParameters;\r\n /**\r\n * Define the opacity fresnel parameters of the material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/fresnelParameters\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsFresnelAndMiscDirty\")\r\n public opacityFresnelParameters: FresnelParameters;\r\n\r\n @serializeAsFresnelParameters(\"reflectionFresnelParameters\")\r\n private _reflectionFresnelParameters: FresnelParameters;\r\n /**\r\n * Define the reflection fresnel parameters of the material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/fresnelParameters\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\r\n public reflectionFresnelParameters: FresnelParameters;\r\n\r\n @serializeAsFresnelParameters(\"refractionFresnelParameters\")\r\n private _refractionFresnelParameters: FresnelParameters;\r\n /**\r\n * Define the refraction fresnel parameters of the material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/fresnelParameters\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\r\n public refractionFresnelParameters: FresnelParameters;\r\n\r\n @serializeAsFresnelParameters(\"emissiveFresnelParameters\")\r\n private _emissiveFresnelParameters: FresnelParameters;\r\n /**\r\n * Define the emissive fresnel parameters of the material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/fresnelParameters\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\r\n public emissiveFresnelParameters: FresnelParameters;\r\n\r\n @serialize(\"useReflectionFresnelFromSpecular\")\r\n private _useReflectionFresnelFromSpecular = false;\r\n /**\r\n * If true automatically deducts the fresnels values from the material specularity.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/fresnelParameters\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsFresnelDirty\")\r\n public useReflectionFresnelFromSpecular: boolean;\r\n\r\n @serialize(\"useGlossinessFromSpecularMapAlpha\")\r\n private _useGlossinessFromSpecularMapAlpha = false;\r\n /**\r\n * Defines if the glossiness/roughness of the material should be read from the specular map alpha channel\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useGlossinessFromSpecularMapAlpha: boolean;\r\n\r\n @serialize(\"maxSimultaneousLights\")\r\n private _maxSimultaneousLights = 4;\r\n /**\r\n * Defines the maximum number of lights that can be used in the material\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public maxSimultaneousLights: number;\r\n\r\n @serialize(\"invertNormalMapX\")\r\n private _invertNormalMapX = false;\r\n /**\r\n * If sets to true, x component of normal map value will invert (x = 1.0 - x).\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public invertNormalMapX: boolean;\r\n\r\n @serialize(\"invertNormalMapY\")\r\n private _invertNormalMapY = false;\r\n /**\r\n * If sets to true, y component of normal map value will invert (y = 1.0 - y).\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public invertNormalMapY: boolean;\r\n\r\n @serialize(\"twoSidedLighting\")\r\n private _twoSidedLighting = false;\r\n /**\r\n * If sets to true and backfaceCulling is false, normals will be flipped on the backside.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public twoSidedLighting: boolean;\r\n\r\n @serialize(\"applyDecalMapAfterDetailMap\")\r\n private _applyDecalMapAfterDetailMap = false;\r\n /**\r\n * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public applyDecalMapAfterDetailMap: boolean;\r\n\r\n /**\r\n * Default configuration related to image processing available in the standard Material.\r\n */\r\n protected _imageProcessingConfiguration: ImageProcessingConfiguration;\r\n\r\n /**\r\n * Gets the image processing configuration used either in this material.\r\n */\r\n public get imageProcessingConfiguration(): ImageProcessingConfiguration {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n /**\r\n * Sets the Default image processing configuration used either in the this material.\r\n *\r\n * If sets to null, the scene one is in use.\r\n */\r\n public set imageProcessingConfiguration(value: ImageProcessingConfiguration) {\r\n this._attachImageProcessingConfiguration(value);\r\n\r\n // Ensure the effect will be rebuilt.\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /**\r\n * Keep track of the image processing observer to allow dispose and replace.\r\n */\r\n private _imageProcessingObserver: Nullable>;\r\n\r\n /**\r\n * Attaches a new image processing configuration to the Standard Material.\r\n * @param configuration\r\n */\r\n protected _attachImageProcessingConfiguration(configuration: Nullable): void {\r\n if (configuration === this._imageProcessingConfiguration) {\r\n return;\r\n }\r\n\r\n // Detaches observer\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n // Pick the scene configuration if needed\r\n if (!configuration) {\r\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\r\n } else {\r\n this._imageProcessingConfiguration = configuration;\r\n }\r\n\r\n // Attaches observer\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\r\n this._markAllSubMeshesAsImageProcessingDirty();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Defines additional PrePass parameters for the material.\r\n */\r\n public readonly prePassConfiguration: PrePassConfiguration;\r\n\r\n /**\r\n * Can this material render to prepass\r\n */\r\n public get isPrePassCapable(): boolean {\r\n return !this.disableDepthWrite;\r\n }\r\n\r\n /**\r\n * Gets whether the color curves effect is enabled.\r\n */\r\n public get cameraColorCurvesEnabled(): boolean {\r\n return this.imageProcessingConfiguration.colorCurvesEnabled;\r\n }\r\n /**\r\n * Sets whether the color curves effect is enabled.\r\n */\r\n public set cameraColorCurvesEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public get cameraColorGradingEnabled(): boolean {\r\n return this.imageProcessingConfiguration.colorGradingEnabled;\r\n }\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public set cameraColorGradingEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.colorGradingEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets whether tonemapping is enabled or not.\r\n */\r\n public get cameraToneMappingEnabled(): boolean {\r\n return this._imageProcessingConfiguration.toneMappingEnabled;\r\n }\r\n /**\r\n * Sets whether tonemapping is enabled or not\r\n */\r\n public set cameraToneMappingEnabled(value: boolean) {\r\n this._imageProcessingConfiguration.toneMappingEnabled = value;\r\n }\r\n\r\n /**\r\n * The camera exposure used on this material.\r\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\r\n * This corresponds to a photographic exposure.\r\n */\r\n public get cameraExposure(): number {\r\n return this._imageProcessingConfiguration.exposure;\r\n }\r\n /**\r\n * The camera exposure used on this material.\r\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\r\n * This corresponds to a photographic exposure.\r\n */\r\n public set cameraExposure(value: number) {\r\n this._imageProcessingConfiguration.exposure = value;\r\n }\r\n\r\n /**\r\n * Gets The camera contrast used on this material.\r\n */\r\n public get cameraContrast(): number {\r\n return this._imageProcessingConfiguration.contrast;\r\n }\r\n\r\n /**\r\n * Sets The camera contrast used on this material.\r\n */\r\n public set cameraContrast(value: number) {\r\n this._imageProcessingConfiguration.contrast = value;\r\n }\r\n\r\n /**\r\n * Gets the Color Grading 2D Lookup Texture.\r\n */\r\n public get cameraColorGradingTexture(): Nullable {\r\n return this._imageProcessingConfiguration.colorGradingTexture;\r\n }\r\n /**\r\n * Sets the Color Grading 2D Lookup Texture.\r\n */\r\n public set cameraColorGradingTexture(value: Nullable) {\r\n this._imageProcessingConfiguration.colorGradingTexture = value;\r\n }\r\n\r\n /**\r\n * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\n public get cameraColorCurves(): Nullable {\r\n return this._imageProcessingConfiguration.colorCurves;\r\n }\r\n /**\r\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\n public set cameraColorCurves(value: Nullable) {\r\n this._imageProcessingConfiguration.colorCurves = value;\r\n }\r\n\r\n /**\r\n * Can this material render to several textures at once\r\n */\r\n public get canRenderToMRT() {\r\n return true;\r\n }\r\n\r\n /**\r\n * Defines the detail map parameters for the material.\r\n */\r\n public readonly detailMap: DetailMapConfiguration;\r\n\r\n protected _renderTargets = new SmartArray(16);\r\n protected _worldViewProjectionMatrix = Matrix.Zero();\r\n protected _globalAmbientColor = new Color3(0, 0, 0);\r\n protected _useLogarithmicDepth: boolean;\r\n protected _cacheHasRenderTargetTextures = false;\r\n\r\n /**\r\n * Instantiates a new standard material.\r\n * This is the default material used in Babylon. It is the best trade off between quality\r\n * and performances.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction\r\n * @param name Define the name of the material in the scene\r\n * @param scene Define the scene the material belong to\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n\r\n this.detailMap = new DetailMapConfiguration(this);\r\n\r\n // Setup the default processing configuration to the scene.\r\n this._attachImageProcessingConfiguration(null);\r\n this.prePassConfiguration = new PrePassConfiguration();\r\n\r\n this.getRenderTargetTextures = (): SmartArray => {\r\n this._renderTargets.reset();\r\n\r\n if (StandardMaterial.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n this._renderTargets.push(this._reflectionTexture);\r\n }\r\n\r\n if (StandardMaterial.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\r\n this._renderTargets.push(this._refractionTexture);\r\n }\r\n\r\n this._eventInfo.renderTargets = this._renderTargets;\r\n this._callbackPluginEventFillRenderTargetTextures(this._eventInfo);\r\n\r\n return this._renderTargets;\r\n };\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n */\r\n public get hasRenderTargetTextures(): boolean {\r\n if (StandardMaterial.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n return true;\r\n }\r\n\r\n if (StandardMaterial.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\r\n return true;\r\n }\r\n\r\n return this._cacheHasRenderTargetTextures;\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"StandardMaterial\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"StandardMaterial\";\r\n }\r\n\r\n /**\r\n * In case the depth buffer does not allow enough depth precision for your scene (might be the case in large scenes)\r\n * You can try switching to logarithmic depth.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/logarithmicDepthBuffer\r\n */\r\n @serialize()\r\n public get useLogarithmicDepth(): boolean {\r\n return this._useLogarithmicDepth;\r\n }\r\n\r\n public set useLogarithmicDepth(value: boolean) {\r\n this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;\r\n\r\n this._markAllSubMeshesAsMiscDirty();\r\n }\r\n\r\n /**\r\n * Specifies if the material will require alpha blending\r\n * @returns a boolean specifying if alpha blending is needed\r\n */\r\n public needAlphaBlending(): boolean {\r\n if (this._disableAlphaBlending) {\r\n return false;\r\n }\r\n\r\n return (\r\n this.alpha < 1.0 ||\r\n this._opacityTexture != null ||\r\n this._shouldUseAlphaFromDiffuseTexture() ||\r\n (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled)\r\n );\r\n }\r\n\r\n /**\r\n * Specifies if this material should be rendered in alpha test mode\r\n * @returns a boolean specifying if an alpha test is needed.\r\n */\r\n public needAlphaTesting(): boolean {\r\n if (this._forceAlphaTest) {\r\n return true;\r\n }\r\n\r\n return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST);\r\n }\r\n\r\n /**\r\n * Specifies whether or not the alpha value of the diffuse texture should be used for alpha blending.\r\n */\r\n protected _shouldUseAlphaFromDiffuseTexture(): boolean {\r\n return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture && this._transparencyMode !== Material.MATERIAL_OPAQUE;\r\n }\r\n\r\n /**\r\n * Specifies whether or not there is a usable alpha channel for transparency.\r\n */\r\n protected _hasAlphaChannel(): boolean {\r\n return (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._opacityTexture != null;\r\n }\r\n\r\n /**\r\n * Get the texture used for alpha test purpose.\r\n * @returns the diffuse texture in case of the standard material.\r\n */\r\n public getAlphaTestTexture(): Nullable {\r\n return this._diffuseTexture;\r\n }\r\n\r\n /**\r\n * Get if the submesh is ready to be used and all its information available.\r\n * Child classes can use it to update shaders\r\n * @param mesh defines the mesh to check\r\n * @param subMesh defines which submesh to check\r\n * @param useInstances specifies that instances should be used\r\n * @returns a boolean indicating that the submesh is ready or not\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances: boolean = false): boolean {\r\n if (!this._uniformBufferLayoutBuilt) {\r\n this.buildUniformLayout();\r\n }\r\n\r\n if (subMesh.effect && this.isFrozen) {\r\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetDefineNames, this._eventInfo);\r\n subMesh.materialDefines = new StandardMaterialDefines(this._eventInfo.defineNames);\r\n }\r\n\r\n const scene = this.getScene();\r\n const defines = subMesh.materialDefines;\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n // Lights\r\n defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);\r\n\r\n // Multiview\r\n MaterialHelper.PrepareDefinesForMultiview(scene, defines);\r\n\r\n // PrePass\r\n const oit = this.needAlphaBlendingForMesh(mesh) && this.getScene().useOrderIndependentTransparency;\r\n MaterialHelper.PrepareDefinesForPrePass(scene, defines, this.canRenderToMRT && !oit);\r\n\r\n // Order independant transparency\r\n MaterialHelper.PrepareDefinesForOIT(scene, defines, oit);\r\n\r\n // Textures\r\n if (defines._areTexturesDirty) {\r\n this._eventInfo.hasRenderTargetTextures = false;\r\n this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);\r\n this._cacheHasRenderTargetTextures = this._eventInfo.hasRenderTargetTextures;\r\n defines._needUVs = false;\r\n for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {\r\n defines[\"MAINUV\" + i] = false;\r\n }\r\n if (scene.texturesEnabled) {\r\n defines.DIFFUSEDIRECTUV = 0;\r\n defines.BUMPDIRECTUV = 0;\r\n defines.AMBIENTDIRECTUV = 0;\r\n defines.OPACITYDIRECTUV = 0;\r\n defines.EMISSIVEDIRECTUV = 0;\r\n defines.SPECULARDIRECTUV = 0;\r\n defines.LIGHTMAPDIRECTUV = 0;\r\n\r\n if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {\r\n if (!this._diffuseTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture, defines, \"DIFFUSE\");\r\n }\r\n } else {\r\n defines.DIFFUSE = false;\r\n }\r\n\r\n if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {\r\n if (!this._ambientTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture, defines, \"AMBIENT\");\r\n }\r\n } else {\r\n defines.AMBIENT = false;\r\n }\r\n\r\n if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {\r\n if (!this._opacityTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture, defines, \"OPACITY\");\r\n defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;\r\n }\r\n } else {\r\n defines.OPACITY = false;\r\n }\r\n\r\n if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {\r\n if (!this._reflectionTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n defines._needNormals = true;\r\n defines.REFLECTION = true;\r\n\r\n defines.ROUGHNESS = this._roughness > 0;\r\n defines.REFLECTIONOVERALPHA = this._useReflectionOverAlpha;\r\n defines.INVERTCUBICMAP = this._reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE;\r\n defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;\r\n defines.REFLECTIONMAP_OPPOSITEZ =\r\n defines.REFLECTIONMAP_3D && this.getScene().useRightHandedSystem ? !this._reflectionTexture.invertZ : this._reflectionTexture.invertZ;\r\n defines.RGBDREFLECTION = this._reflectionTexture.isRGBD;\r\n\r\n switch (this._reflectionTexture.coordinatesMode) {\r\n case Texture.EXPLICIT_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_EXPLICIT\");\r\n break;\r\n case Texture.PLANAR_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_PLANAR\");\r\n break;\r\n case Texture.PROJECTION_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_PROJECTION\");\r\n break;\r\n case Texture.SKYBOX_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_SKYBOX\");\r\n break;\r\n case Texture.SPHERICAL_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_SPHERICAL\");\r\n break;\r\n case Texture.EQUIRECTANGULAR_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_EQUIRECTANGULAR\");\r\n break;\r\n case Texture.FIXED_EQUIRECTANGULAR_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_EQUIRECTANGULAR_FIXED\");\r\n break;\r\n case Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:\r\n defines.setReflectionMode(\"REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\");\r\n break;\r\n case Texture.CUBIC_MODE:\r\n case Texture.INVCUBIC_MODE:\r\n default:\r\n defines.setReflectionMode(\"REFLECTIONMAP_CUBIC\");\r\n break;\r\n }\r\n\r\n defines.USE_LOCAL_REFLECTIONMAP_CUBIC = (this._reflectionTexture).boundingBoxSize ? true : false;\r\n }\r\n } else {\r\n defines.REFLECTION = false;\r\n defines.REFLECTIONMAP_OPPOSITEZ = false;\r\n }\r\n\r\n if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {\r\n if (!this._emissiveTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture, defines, \"EMISSIVE\");\r\n }\r\n } else {\r\n defines.EMISSIVE = false;\r\n }\r\n\r\n if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {\r\n if (!this._lightmapTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture, defines, \"LIGHTMAP\");\r\n defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;\r\n defines.RGBDLIGHTMAP = this._lightmapTexture.isRGBD;\r\n }\r\n } else {\r\n defines.LIGHTMAP = false;\r\n }\r\n\r\n if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {\r\n if (!this._specularTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._specularTexture, defines, \"SPECULAR\");\r\n defines.GLOSSINESS = this._useGlossinessFromSpecularMapAlpha;\r\n }\r\n } else {\r\n defines.SPECULAR = false;\r\n }\r\n\r\n if (scene.getEngine().getCaps().standardDerivatives && this._bumpTexture && StandardMaterial.BumpTextureEnabled) {\r\n // Bump texture can not be not blocking.\r\n if (!this._bumpTexture.isReady()) {\r\n return false;\r\n } else {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, \"BUMP\");\r\n\r\n defines.PARALLAX = this._useParallax;\r\n defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;\r\n }\r\n\r\n defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;\r\n } else {\r\n defines.BUMP = false;\r\n defines.PARALLAX = false;\r\n defines.PARALLAXOCCLUSION = false;\r\n }\r\n\r\n if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {\r\n if (!this._refractionTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n } else {\r\n defines._needUVs = true;\r\n defines.REFRACTION = true;\r\n\r\n defines.REFRACTIONMAP_3D = this._refractionTexture.isCube;\r\n defines.RGBDREFRACTION = this._refractionTexture.isRGBD;\r\n defines.USE_LOCAL_REFRACTIONMAP_CUBIC = (this._refractionTexture).boundingBoxSize ? true : false;\r\n }\r\n } else {\r\n defines.REFRACTION = false;\r\n }\r\n\r\n defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;\r\n } else {\r\n defines.DIFFUSE = false;\r\n defines.AMBIENT = false;\r\n defines.OPACITY = false;\r\n defines.REFLECTION = false;\r\n defines.EMISSIVE = false;\r\n defines.LIGHTMAP = false;\r\n defines.BUMP = false;\r\n defines.REFRACTION = false;\r\n }\r\n\r\n defines.ALPHAFROMDIFFUSE = this._shouldUseAlphaFromDiffuseTexture();\r\n\r\n defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;\r\n\r\n defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;\r\n\r\n defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;\r\n\r\n defines.PREMULTIPLYALPHA = this.alphaMode === Constants.ALPHA_PREMULTIPLIED || this.alphaMode === Constants.ALPHA_PREMULTIPLIED_PORTERDUFF;\r\n\r\n defines.ALPHATEST_AFTERALLALPHACOMPUTATIONS = this.transparencyMode !== null;\r\n\r\n defines.ALPHABLEND = this.transparencyMode === null || this.needAlphaBlendingForMesh(mesh); // check on null for backward compatibility\r\n }\r\n\r\n this._eventInfo.isReadyForSubMesh = true;\r\n this._eventInfo.defines = defines;\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);\r\n\r\n if (!this._eventInfo.isReadyForSubMesh) {\r\n return false;\r\n }\r\n\r\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\r\n if (!this._imageProcessingConfiguration.isReady()) {\r\n return false;\r\n }\r\n\r\n this._imageProcessingConfiguration.prepareDefines(defines);\r\n\r\n defines.IS_REFLECTION_LINEAR = this.reflectionTexture != null && !this.reflectionTexture.gammaSpace;\r\n defines.IS_REFRACTION_LINEAR = this.refractionTexture != null && !this.refractionTexture.gammaSpace;\r\n }\r\n\r\n if (defines._areFresnelDirty) {\r\n if (StandardMaterial.FresnelEnabled) {\r\n // Fresnel\r\n if (\r\n this._diffuseFresnelParameters ||\r\n this._opacityFresnelParameters ||\r\n this._emissiveFresnelParameters ||\r\n this._refractionFresnelParameters ||\r\n this._reflectionFresnelParameters\r\n ) {\r\n defines.DIFFUSEFRESNEL = this._diffuseFresnelParameters && this._diffuseFresnelParameters.isEnabled;\r\n\r\n defines.OPACITYFRESNEL = this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;\r\n\r\n defines.REFLECTIONFRESNEL = this._reflectionFresnelParameters && this._reflectionFresnelParameters.isEnabled;\r\n\r\n defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;\r\n\r\n defines.REFRACTIONFRESNEL = this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled;\r\n\r\n defines.EMISSIVEFRESNEL = this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled;\r\n\r\n defines._needNormals = true;\r\n defines.FRESNEL = true;\r\n }\r\n } else {\r\n defines.FRESNEL = false;\r\n }\r\n }\r\n\r\n // Misc.\r\n MaterialHelper.PrepareDefinesForMisc(\r\n mesh,\r\n scene,\r\n this._useLogarithmicDepth,\r\n this.pointsCloud,\r\n this.fogEnabled,\r\n this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest,\r\n defines,\r\n this._applyDecalMapAfterDetailMap\r\n );\r\n\r\n // Values that need to be evaluated on every frame\r\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);\r\n\r\n // External config\r\n this._eventInfo.defines = defines;\r\n this._eventInfo.mesh = mesh;\r\n this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);\r\n\r\n // Attribs\r\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);\r\n\r\n // External config\r\n this._callbackPluginEventPrepareDefines(this._eventInfo);\r\n\r\n // Get correct effect\r\n let forceWasNotReadyPreviously = false;\r\n\r\n if (defines.isDirty) {\r\n const lightDisposed = defines._areLightsDisposed;\r\n defines.markAsProcessed();\r\n\r\n // Fallbacks\r\n const fallbacks = new EffectFallbacks();\r\n if (defines.REFLECTION) {\r\n fallbacks.addFallback(0, \"REFLECTION\");\r\n }\r\n\r\n if (defines.SPECULAR) {\r\n fallbacks.addFallback(0, \"SPECULAR\");\r\n }\r\n\r\n if (defines.BUMP) {\r\n fallbacks.addFallback(0, \"BUMP\");\r\n }\r\n\r\n if (defines.PARALLAX) {\r\n fallbacks.addFallback(1, \"PARALLAX\");\r\n }\r\n\r\n if (defines.PARALLAXOCCLUSION) {\r\n fallbacks.addFallback(0, \"PARALLAXOCCLUSION\");\r\n }\r\n\r\n if (defines.SPECULAROVERALPHA) {\r\n fallbacks.addFallback(0, \"SPECULAROVERALPHA\");\r\n }\r\n\r\n if (defines.FOG) {\r\n fallbacks.addFallback(1, \"FOG\");\r\n }\r\n\r\n if (defines.POINTSIZE) {\r\n fallbacks.addFallback(0, \"POINTSIZE\");\r\n }\r\n\r\n if (defines.LOGARITHMICDEPTH) {\r\n fallbacks.addFallback(0, \"LOGARITHMICDEPTH\");\r\n }\r\n\r\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);\r\n\r\n if (defines.SPECULARTERM) {\r\n fallbacks.addFallback(0, \"SPECULARTERM\");\r\n }\r\n\r\n if (defines.DIFFUSEFRESNEL) {\r\n fallbacks.addFallback(1, \"DIFFUSEFRESNEL\");\r\n }\r\n\r\n if (defines.OPACITYFRESNEL) {\r\n fallbacks.addFallback(2, \"OPACITYFRESNEL\");\r\n }\r\n\r\n if (defines.REFLECTIONFRESNEL) {\r\n fallbacks.addFallback(3, \"REFLECTIONFRESNEL\");\r\n }\r\n\r\n if (defines.EMISSIVEFRESNEL) {\r\n fallbacks.addFallback(4, \"EMISSIVEFRESNEL\");\r\n }\r\n\r\n if (defines.FRESNEL) {\r\n fallbacks.addFallback(4, \"FRESNEL\");\r\n }\r\n\r\n if (defines.MULTIVIEW) {\r\n fallbacks.addFallback(0, \"MULTIVIEW\");\r\n }\r\n\r\n //Attributes\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n if (defines.NORMAL) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n }\r\n\r\n if (defines.TANGENT) {\r\n attribs.push(VertexBuffer.TangentKind);\r\n }\r\n\r\n for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {\r\n if (defines[\"UV\" + i]) {\r\n attribs.push(`uv${i === 1 ? \"\" : i}`);\r\n }\r\n }\r\n\r\n if (defines.VERTEXCOLOR) {\r\n attribs.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\r\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\r\n MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);\r\n MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\r\n\r\n let shaderName = \"default\";\r\n\r\n const uniforms = [\r\n \"world\",\r\n \"view\",\r\n \"viewProjection\",\r\n \"vEyePosition\",\r\n \"vLightsType\",\r\n \"vAmbientColor\",\r\n \"vDiffuseColor\",\r\n \"vSpecularColor\",\r\n \"vEmissiveColor\",\r\n \"visibility\",\r\n \"vFogInfos\",\r\n \"vFogColor\",\r\n \"pointSize\",\r\n \"vDiffuseInfos\",\r\n \"vAmbientInfos\",\r\n \"vOpacityInfos\",\r\n \"vReflectionInfos\",\r\n \"vEmissiveInfos\",\r\n \"vSpecularInfos\",\r\n \"vBumpInfos\",\r\n \"vLightmapInfos\",\r\n \"vRefractionInfos\",\r\n \"mBones\",\r\n \"diffuseMatrix\",\r\n \"ambientMatrix\",\r\n \"opacityMatrix\",\r\n \"reflectionMatrix\",\r\n \"emissiveMatrix\",\r\n \"specularMatrix\",\r\n \"bumpMatrix\",\r\n \"normalMatrix\",\r\n \"lightmapMatrix\",\r\n \"refractionMatrix\",\r\n \"diffuseLeftColor\",\r\n \"diffuseRightColor\",\r\n \"opacityParts\",\r\n \"reflectionLeftColor\",\r\n \"reflectionRightColor\",\r\n \"emissiveLeftColor\",\r\n \"emissiveRightColor\",\r\n \"refractionLeftColor\",\r\n \"refractionRightColor\",\r\n \"vReflectionPosition\",\r\n \"vReflectionSize\",\r\n \"vRefractionPosition\",\r\n \"vRefractionSize\",\r\n \"logarithmicDepthConstant\",\r\n \"vTangentSpaceParams\",\r\n \"alphaCutOff\",\r\n \"boneTextureWidth\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n ];\r\n\r\n const samplers = [\r\n \"diffuseSampler\",\r\n \"ambientSampler\",\r\n \"opacitySampler\",\r\n \"reflectionCubeSampler\",\r\n \"reflection2DSampler\",\r\n \"emissiveSampler\",\r\n \"specularSampler\",\r\n \"bumpSampler\",\r\n \"lightmapSampler\",\r\n \"refractionCubeSampler\",\r\n \"refraction2DSampler\",\r\n \"boneSampler\",\r\n \"morphTargets\",\r\n \"oitDepthSampler\",\r\n \"oitFrontColorSampler\",\r\n ];\r\n\r\n const uniformBuffers = [\"Material\", \"Scene\", \"Mesh\"];\r\n\r\n const indexParameters = { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS };\r\n\r\n this._eventInfo.fallbacks = fallbacks;\r\n this._eventInfo.fallbackRank = 0;\r\n this._eventInfo.defines = defines;\r\n this._eventInfo.uniforms = uniforms;\r\n this._eventInfo.attributes = attribs;\r\n this._eventInfo.samplers = samplers;\r\n this._eventInfo.uniformBuffersNames = uniformBuffers;\r\n this._eventInfo.customCode = undefined;\r\n this._eventInfo.mesh = mesh;\r\n this._eventInfo.indexParameters = indexParameters;\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareEffect, this._eventInfo);\r\n\r\n PrePassConfiguration.AddUniforms(uniforms);\r\n PrePassConfiguration.AddSamplers(samplers);\r\n\r\n if (ImageProcessingConfiguration) {\r\n ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);\r\n ImageProcessingConfiguration.PrepareSamplers(samplers, defines);\r\n }\r\n\r\n MaterialHelper.PrepareUniformsAndSamplersList({\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: defines,\r\n maxSimultaneousLights: this._maxSimultaneousLights,\r\n });\r\n\r\n addClipPlaneUniforms(uniforms);\r\n\r\n const csnrOptions: ICustomShaderNameResolveOptions = {};\r\n\r\n if (this.customShaderNameResolve) {\r\n shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs, csnrOptions);\r\n }\r\n\r\n const join = defines.toString();\r\n\r\n const previousEffect = subMesh.effect;\r\n let effect = scene.getEngine().createEffect(\r\n shaderName,\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters,\r\n processFinalCode: csnrOptions.processFinalCode,\r\n processCodeAfterIncludes: this._eventInfo.customCode,\r\n multiTarget: defines.PREPASS,\r\n },\r\n engine\r\n );\r\n\r\n this._eventInfo.customCode = undefined;\r\n\r\n if (effect) {\r\n if (this._onEffectCreatedObservable) {\r\n onCreatedEffectParameters.effect = effect;\r\n onCreatedEffectParameters.subMesh = subMesh;\r\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);\r\n }\r\n\r\n // Use previous effect while new one is compiling\r\n if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {\r\n effect = previousEffect;\r\n defines.markAsUnprocessed();\r\n\r\n forceWasNotReadyPreviously = this.isFrozen;\r\n\r\n if (lightDisposed) {\r\n // re register in case it takes more than one frame.\r\n defines._areLightsDisposed = true;\r\n return false;\r\n }\r\n } else {\r\n scene.resetCachedMaterial();\r\n subMesh.setEffect(effect, defines, this._materialContext);\r\n }\r\n }\r\n }\r\n\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = forceWasNotReadyPreviously ? false : true;\r\n subMesh.effect._wasPreviouslyUsingInstances = useInstances;\r\n\r\n this._checkScenePerformancePriority();\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Builds the material UBO layouts.\r\n * Used internally during the effect preparation.\r\n */\r\n public buildUniformLayout(): void {\r\n // Order is important !\r\n const ubo = this._uniformBuffer;\r\n ubo.addUniform(\"diffuseLeftColor\", 4);\r\n ubo.addUniform(\"diffuseRightColor\", 4);\r\n ubo.addUniform(\"opacityParts\", 4);\r\n ubo.addUniform(\"reflectionLeftColor\", 4);\r\n ubo.addUniform(\"reflectionRightColor\", 4);\r\n ubo.addUniform(\"refractionLeftColor\", 4);\r\n ubo.addUniform(\"refractionRightColor\", 4);\r\n ubo.addUniform(\"emissiveLeftColor\", 4);\r\n ubo.addUniform(\"emissiveRightColor\", 4);\r\n\r\n ubo.addUniform(\"vDiffuseInfos\", 2);\r\n ubo.addUniform(\"vAmbientInfos\", 2);\r\n ubo.addUniform(\"vOpacityInfos\", 2);\r\n ubo.addUniform(\"vReflectionInfos\", 2);\r\n ubo.addUniform(\"vReflectionPosition\", 3);\r\n ubo.addUniform(\"vReflectionSize\", 3);\r\n ubo.addUniform(\"vEmissiveInfos\", 2);\r\n ubo.addUniform(\"vLightmapInfos\", 2);\r\n ubo.addUniform(\"vSpecularInfos\", 2);\r\n ubo.addUniform(\"vBumpInfos\", 3);\r\n\r\n ubo.addUniform(\"diffuseMatrix\", 16);\r\n ubo.addUniform(\"ambientMatrix\", 16);\r\n ubo.addUniform(\"opacityMatrix\", 16);\r\n ubo.addUniform(\"reflectionMatrix\", 16);\r\n ubo.addUniform(\"emissiveMatrix\", 16);\r\n ubo.addUniform(\"lightmapMatrix\", 16);\r\n ubo.addUniform(\"specularMatrix\", 16);\r\n ubo.addUniform(\"bumpMatrix\", 16);\r\n ubo.addUniform(\"vTangentSpaceParams\", 2);\r\n ubo.addUniform(\"pointSize\", 1);\r\n ubo.addUniform(\"alphaCutOff\", 1);\r\n ubo.addUniform(\"refractionMatrix\", 16);\r\n ubo.addUniform(\"vRefractionInfos\", 4);\r\n ubo.addUniform(\"vRefractionPosition\", 3);\r\n ubo.addUniform(\"vRefractionSize\", 3);\r\n ubo.addUniform(\"vSpecularColor\", 4);\r\n ubo.addUniform(\"vEmissiveColor\", 3);\r\n ubo.addUniform(\"vDiffuseColor\", 4);\r\n ubo.addUniform(\"vAmbientColor\", 3);\r\n\r\n super.buildUniformLayout();\r\n }\r\n\r\n /**\r\n * Binds the submesh to this material by preparing the effect and shader to draw\r\n * @param world defines the world transformation matrix\r\n * @param mesh defines the mesh containing the submesh\r\n * @param subMesh defines the submesh to bind the material to\r\n */\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n\r\n const defines = subMesh.materialDefines;\r\n if (!defines) {\r\n return;\r\n }\r\n\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n this._activeEffect = effect;\r\n\r\n // Matrices Mesh.\r\n mesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\r\n mesh.transferToEffect(world);\r\n\r\n // Binding unconditionally\r\n this._uniformBuffer.bindToEffect(effect, \"Material\");\r\n\r\n this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);\r\n\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventHardBindForSubMesh(this._eventInfo);\r\n\r\n // Normal Matrix\r\n if (defines.OBJECTSPACE_NORMALMAP) {\r\n world.toNormalMatrix(this._normalMatrix);\r\n this.bindOnlyNormalMatrix(this._normalMatrix);\r\n }\r\n\r\n const mustRebind = effect._forceRebindOnNextCall || this._mustRebind(scene, effect, mesh.visibility);\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, effect);\r\n const ubo = this._uniformBuffer;\r\n if (mustRebind) {\r\n this.bindViewProjection(effect);\r\n if (!ubo.useUbo || !this.isFrozen || !ubo.isSync || effect._forceRebindOnNextCall) {\r\n if (StandardMaterial.FresnelEnabled && defines.FRESNEL) {\r\n // Fresnel\r\n if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {\r\n ubo.updateColor4(\"diffuseLeftColor\", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);\r\n ubo.updateColor4(\"diffuseRightColor\", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);\r\n }\r\n\r\n if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {\r\n ubo.updateColor4(\r\n \"opacityParts\",\r\n new Color3(\r\n this.opacityFresnelParameters.leftColor.toLuminance(),\r\n this.opacityFresnelParameters.rightColor.toLuminance(),\r\n this.opacityFresnelParameters.bias\r\n ),\r\n this.opacityFresnelParameters.power\r\n );\r\n }\r\n\r\n if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {\r\n ubo.updateColor4(\"reflectionLeftColor\", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);\r\n ubo.updateColor4(\"reflectionRightColor\", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);\r\n }\r\n\r\n if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {\r\n ubo.updateColor4(\"refractionLeftColor\", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);\r\n ubo.updateColor4(\"refractionRightColor\", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);\r\n }\r\n\r\n if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {\r\n ubo.updateColor4(\"emissiveLeftColor\", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);\r\n ubo.updateColor4(\"emissiveRightColor\", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);\r\n }\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {\r\n ubo.updateFloat2(\"vDiffuseInfos\", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._diffuseTexture, ubo, \"diffuse\");\r\n }\r\n\r\n if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {\r\n ubo.updateFloat2(\"vAmbientInfos\", this._ambientTexture.coordinatesIndex, this._ambientTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._ambientTexture, ubo, \"ambient\");\r\n }\r\n\r\n if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {\r\n ubo.updateFloat2(\"vOpacityInfos\", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._opacityTexture, ubo, \"opacity\");\r\n }\r\n\r\n if (this._hasAlphaChannel()) {\r\n ubo.updateFloat(\"alphaCutOff\", this.alphaCutOff);\r\n }\r\n\r\n if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {\r\n ubo.updateFloat2(\"vReflectionInfos\", this._reflectionTexture.level, this.roughness);\r\n ubo.updateMatrix(\"reflectionMatrix\", this._reflectionTexture.getReflectionTextureMatrix());\r\n\r\n if ((this._reflectionTexture).boundingBoxSize) {\r\n const cubeTexture = this._reflectionTexture;\r\n\r\n ubo.updateVector3(\"vReflectionPosition\", cubeTexture.boundingBoxPosition);\r\n ubo.updateVector3(\"vReflectionSize\", cubeTexture.boundingBoxSize);\r\n }\r\n }\r\n\r\n if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {\r\n ubo.updateFloat2(\"vEmissiveInfos\", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._emissiveTexture, ubo, \"emissive\");\r\n }\r\n\r\n if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {\r\n ubo.updateFloat2(\"vLightmapInfos\", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._lightmapTexture, ubo, \"lightmap\");\r\n }\r\n\r\n if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {\r\n ubo.updateFloat2(\"vSpecularInfos\", this._specularTexture.coordinatesIndex, this._specularTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._specularTexture, ubo, \"specular\");\r\n }\r\n\r\n if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {\r\n ubo.updateFloat3(\"vBumpInfos\", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);\r\n MaterialHelper.BindTextureMatrix(this._bumpTexture, ubo, \"bump\");\r\n\r\n if (scene._mirroredCameraPosition) {\r\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);\r\n } else {\r\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);\r\n }\r\n }\r\n\r\n if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {\r\n let depth = 1.0;\r\n if (!this._refractionTexture.isCube) {\r\n ubo.updateMatrix(\"refractionMatrix\", this._refractionTexture.getReflectionTextureMatrix());\r\n\r\n if ((this._refractionTexture).depth) {\r\n depth = (this._refractionTexture).depth;\r\n }\r\n }\r\n ubo.updateFloat4(\"vRefractionInfos\", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);\r\n\r\n if ((this._refractionTexture).boundingBoxSize) {\r\n const cubeTexture = this._refractionTexture;\r\n\r\n ubo.updateVector3(\"vRefractionPosition\", cubeTexture.boundingBoxPosition);\r\n ubo.updateVector3(\"vRefractionSize\", cubeTexture.boundingBoxSize);\r\n }\r\n }\r\n }\r\n\r\n // Point size\r\n if (this.pointsCloud) {\r\n ubo.updateFloat(\"pointSize\", this.pointSize);\r\n }\r\n\r\n if (defines.SPECULARTERM) {\r\n ubo.updateColor4(\"vSpecularColor\", this.specularColor, this.specularPower);\r\n }\r\n\r\n ubo.updateColor3(\"vEmissiveColor\", StandardMaterial.EmissiveTextureEnabled ? this.emissiveColor : Color3.BlackReadOnly);\r\n ubo.updateColor4(\"vDiffuseColor\", this.diffuseColor, this.alpha);\r\n\r\n scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);\r\n ubo.updateColor3(\"vAmbientColor\", this._globalAmbientColor);\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {\r\n effect.setTexture(\"diffuseSampler\", this._diffuseTexture);\r\n }\r\n\r\n if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {\r\n effect.setTexture(\"ambientSampler\", this._ambientTexture);\r\n }\r\n\r\n if (this._opacityTexture && StandardMaterial.OpacityTextureEnabled) {\r\n effect.setTexture(\"opacitySampler\", this._opacityTexture);\r\n }\r\n\r\n if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {\r\n if (this._reflectionTexture.isCube) {\r\n effect.setTexture(\"reflectionCubeSampler\", this._reflectionTexture);\r\n } else {\r\n effect.setTexture(\"reflection2DSampler\", this._reflectionTexture);\r\n }\r\n }\r\n\r\n if (this._emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {\r\n effect.setTexture(\"emissiveSampler\", this._emissiveTexture);\r\n }\r\n\r\n if (this._lightmapTexture && StandardMaterial.LightmapTextureEnabled) {\r\n effect.setTexture(\"lightmapSampler\", this._lightmapTexture);\r\n }\r\n\r\n if (this._specularTexture && StandardMaterial.SpecularTextureEnabled) {\r\n effect.setTexture(\"specularSampler\", this._specularTexture);\r\n }\r\n\r\n if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {\r\n effect.setTexture(\"bumpSampler\", this._bumpTexture);\r\n }\r\n\r\n if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {\r\n if (this._refractionTexture.isCube) {\r\n effect.setTexture(\"refractionCubeSampler\", this._refractionTexture);\r\n } else {\r\n effect.setTexture(\"refraction2DSampler\", this._refractionTexture);\r\n }\r\n }\r\n }\r\n\r\n // OIT with depth peeling\r\n if (this.getScene().useOrderIndependentTransparency && this.needAlphaBlendingForMesh(mesh)) {\r\n this.getScene().depthPeelingRenderer!.bind(effect);\r\n }\r\n\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventBindForSubMesh(this._eventInfo);\r\n\r\n // Clip plane\r\n bindClipPlane(effect, this, scene);\r\n\r\n // Colors\r\n this.bindEyePosition(effect);\r\n } else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {\r\n this._needToBindSceneUbo = true;\r\n }\r\n\r\n if (mustRebind || !this.isFrozen) {\r\n // Lights\r\n if (scene.lightsEnabled && !this._disableLighting) {\r\n MaterialHelper.BindLights(scene, mesh, effect, defines, this._maxSimultaneousLights);\r\n }\r\n\r\n // View\r\n if (\r\n (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) ||\r\n this._reflectionTexture ||\r\n this._refractionTexture ||\r\n mesh.receiveShadows ||\r\n defines.PREPASS\r\n ) {\r\n this.bindView(effect);\r\n }\r\n\r\n // Fog\r\n MaterialHelper.BindFogParameters(scene, mesh, effect);\r\n\r\n // Morph targets\r\n if (defines.NUM_MORPH_INFLUENCERS) {\r\n MaterialHelper.BindMorphTargetParameters(mesh, effect);\r\n }\r\n\r\n if (defines.BAKED_VERTEX_ANIMATION_TEXTURE) {\r\n mesh.bakedVertexAnimationManager?.bind(effect, defines.INSTANCES);\r\n }\r\n\r\n // Log. depth\r\n if (this.useLogarithmicDepth) {\r\n MaterialHelper.BindLogDepth(defines, effect, scene);\r\n }\r\n\r\n // image processing\r\n if (this._imageProcessingConfiguration && !this._imageProcessingConfiguration.applyByPostProcess) {\r\n this._imageProcessingConfiguration.bind(this._activeEffect);\r\n }\r\n }\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n ubo.update();\r\n }\r\n\r\n /**\r\n * Get the list of animatables in the material.\r\n * @returns the list of animatables object used in the material\r\n */\r\n public getAnimatables(): IAnimatable[] {\r\n const results = super.getAnimatables();\r\n\r\n if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {\r\n results.push(this._diffuseTexture);\r\n }\r\n\r\n if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {\r\n results.push(this._ambientTexture);\r\n }\r\n\r\n if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {\r\n results.push(this._opacityTexture);\r\n }\r\n\r\n if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {\r\n results.push(this._reflectionTexture);\r\n }\r\n\r\n if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {\r\n results.push(this._emissiveTexture);\r\n }\r\n\r\n if (this._specularTexture && this._specularTexture.animations && this._specularTexture.animations.length > 0) {\r\n results.push(this._specularTexture);\r\n }\r\n\r\n if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {\r\n results.push(this._bumpTexture);\r\n }\r\n\r\n if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {\r\n results.push(this._lightmapTexture);\r\n }\r\n\r\n if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {\r\n results.push(this._refractionTexture);\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Gets the active textures from the material\r\n * @returns an array of textures\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n const activeTextures = super.getActiveTextures();\r\n\r\n if (this._diffuseTexture) {\r\n activeTextures.push(this._diffuseTexture);\r\n }\r\n\r\n if (this._ambientTexture) {\r\n activeTextures.push(this._ambientTexture);\r\n }\r\n\r\n if (this._opacityTexture) {\r\n activeTextures.push(this._opacityTexture);\r\n }\r\n\r\n if (this._reflectionTexture) {\r\n activeTextures.push(this._reflectionTexture);\r\n }\r\n\r\n if (this._emissiveTexture) {\r\n activeTextures.push(this._emissiveTexture);\r\n }\r\n\r\n if (this._specularTexture) {\r\n activeTextures.push(this._specularTexture);\r\n }\r\n\r\n if (this._bumpTexture) {\r\n activeTextures.push(this._bumpTexture);\r\n }\r\n\r\n if (this._lightmapTexture) {\r\n activeTextures.push(this._lightmapTexture);\r\n }\r\n\r\n if (this._refractionTexture) {\r\n activeTextures.push(this._refractionTexture);\r\n }\r\n\r\n return activeTextures;\r\n }\r\n\r\n /**\r\n * Specifies if the material uses a texture\r\n * @param texture defines the texture to check against the material\r\n * @returns a boolean specifying if the 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 if (this._diffuseTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._ambientTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._opacityTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._reflectionTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._emissiveTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._specularTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._bumpTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._lightmapTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._refractionTexture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Disposes the material\r\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\r\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n this._diffuseTexture?.dispose();\r\n this._ambientTexture?.dispose();\r\n this._opacityTexture?.dispose();\r\n this._reflectionTexture?.dispose();\r\n this._emissiveTexture?.dispose();\r\n this._specularTexture?.dispose();\r\n this._bumpTexture?.dispose();\r\n this._lightmapTexture?.dispose();\r\n this._refractionTexture?.dispose();\r\n }\r\n\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n super.dispose(forceDisposeEffect, forceDisposeTextures);\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the material, and gives it a new name\r\n * @param name defines the new name for the duplicated material\r\n * @param cloneTexturesOnlyOnce - if a texture is used in more than one channel (e.g diffuse and opacity), only clone it once and reuse it on the other channels. Default false.\r\n * @param rootUrl defines the root URL to use to load textures\r\n * @returns the cloned material\r\n */\r\n public clone(name: string, cloneTexturesOnlyOnce: boolean = true, rootUrl = \"\"): StandardMaterial {\r\n const result = SerializationHelper.Clone(() => new StandardMaterial(name, this.getScene()), this, { cloneTexturesOnlyOnce });\r\n\r\n result.name = name;\r\n result.id = name;\r\n\r\n this.stencil.copyTo(result.stencil);\r\n\r\n this._clonePlugins(result, rootUrl);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a standard material from parsed material data\r\n * @param source defines the JSON representation of the material\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new standard material\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): StandardMaterial {\r\n const material = SerializationHelper.Parse(() => new StandardMaterial(source.name, scene), source, scene, rootUrl);\r\n\r\n if (source.stencil) {\r\n material.stencil.parse(source.stencil, scene, rootUrl);\r\n }\r\n\r\n Material._parsePlugins(source, material, scene, rootUrl);\r\n\r\n return material;\r\n }\r\n\r\n // Flags used to enable or disable a type of texture for all Standard Materials\r\n /**\r\n * Are diffuse textures enabled in the application.\r\n */\r\n public static get DiffuseTextureEnabled(): boolean {\r\n return MaterialFlags.DiffuseTextureEnabled;\r\n }\r\n public static set DiffuseTextureEnabled(value: boolean) {\r\n MaterialFlags.DiffuseTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are detail textures enabled in the application.\r\n */\r\n public static get DetailTextureEnabled(): boolean {\r\n return MaterialFlags.DetailTextureEnabled;\r\n }\r\n public static set DetailTextureEnabled(value: boolean) {\r\n MaterialFlags.DetailTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are ambient textures enabled in the application.\r\n */\r\n public static get AmbientTextureEnabled(): boolean {\r\n return MaterialFlags.AmbientTextureEnabled;\r\n }\r\n public static set AmbientTextureEnabled(value: boolean) {\r\n MaterialFlags.AmbientTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are opacity textures enabled in the application.\r\n */\r\n public static get OpacityTextureEnabled(): boolean {\r\n return MaterialFlags.OpacityTextureEnabled;\r\n }\r\n public static set OpacityTextureEnabled(value: boolean) {\r\n MaterialFlags.OpacityTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are reflection textures enabled in the application.\r\n */\r\n public static get ReflectionTextureEnabled(): boolean {\r\n return MaterialFlags.ReflectionTextureEnabled;\r\n }\r\n public static set ReflectionTextureEnabled(value: boolean) {\r\n MaterialFlags.ReflectionTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are emissive textures enabled in the application.\r\n */\r\n public static get EmissiveTextureEnabled(): boolean {\r\n return MaterialFlags.EmissiveTextureEnabled;\r\n }\r\n public static set EmissiveTextureEnabled(value: boolean) {\r\n MaterialFlags.EmissiveTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are specular textures enabled in the application.\r\n */\r\n public static get SpecularTextureEnabled(): boolean {\r\n return MaterialFlags.SpecularTextureEnabled;\r\n }\r\n public static set SpecularTextureEnabled(value: boolean) {\r\n MaterialFlags.SpecularTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are bump textures enabled in the application.\r\n */\r\n public static get BumpTextureEnabled(): boolean {\r\n return MaterialFlags.BumpTextureEnabled;\r\n }\r\n public static set BumpTextureEnabled(value: boolean) {\r\n MaterialFlags.BumpTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are lightmap textures enabled in the application.\r\n */\r\n public static get LightmapTextureEnabled(): boolean {\r\n return MaterialFlags.LightmapTextureEnabled;\r\n }\r\n public static set LightmapTextureEnabled(value: boolean) {\r\n MaterialFlags.LightmapTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are refraction textures enabled in the application.\r\n */\r\n public static get RefractionTextureEnabled(): boolean {\r\n return MaterialFlags.RefractionTextureEnabled;\r\n }\r\n public static set RefractionTextureEnabled(value: boolean) {\r\n MaterialFlags.RefractionTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are color grading textures enabled in the application.\r\n */\r\n public static get ColorGradingTextureEnabled(): boolean {\r\n return MaterialFlags.ColorGradingTextureEnabled;\r\n }\r\n public static set ColorGradingTextureEnabled(value: boolean) {\r\n MaterialFlags.ColorGradingTextureEnabled = value;\r\n }\r\n\r\n /**\r\n * Are fresnels enabled in the application.\r\n */\r\n public static get FresnelEnabled(): boolean {\r\n return MaterialFlags.FresnelEnabled;\r\n }\r\n public static set FresnelEnabled(value: boolean) {\r\n MaterialFlags.FresnelEnabled = value;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.StandardMaterial\", StandardMaterial);\r\n\r\nScene.DefaultMaterialFactory = (scene: Scene) => {\r\n return new StandardMaterial(\"default material\", scene);\r\n};\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"postprocessVertexShader\";\nconst shader = `attribute vec2 position;uniform vec2 scale;varying vec2 vUV;const vec2 madd=vec2(0.5,0.5);\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvUV=(position*madd+madd)*scale;gl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const postprocessVertexShader = { name, shader };\n","import type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport type { TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Engine } from \"../engine\";\r\nimport { RenderTargetWrapper } from \"../renderTargetWrapper\";\r\nimport type { ThinEngine } from \"../thinEngine\";\r\n\r\n/** @internal */\r\nexport class WebGLRenderTargetWrapper extends RenderTargetWrapper {\r\n private _context: WebGLRenderingContext;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _framebuffer: Nullable = null;\r\n /**\r\n * @internal\r\n */\r\n public _depthStencilBuffer: Nullable = null;\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n /**\r\n * @internal\r\n */\r\n public _MSAAFramebuffer: Nullable = null;\r\n\r\n // Multiview\r\n /**\r\n * @internal\r\n */\r\n public _colorTextureArray: Nullable = null;\r\n /**\r\n * @internal\r\n */\r\n public _depthStencilTextureArray: Nullable = null;\r\n /**\r\n * @internal\r\n */\r\n public _disposeOnlyFramebuffers = false;\r\n\r\n constructor(isMulti: boolean, isCube: boolean, size: TextureSize, engine: ThinEngine, context: WebGLRenderingContext) {\r\n super(isMulti, isCube, size, engine);\r\n\r\n this._context = context;\r\n }\r\n\r\n protected _cloneRenderTargetWrapper(): Nullable {\r\n let rtw: Nullable = null;\r\n\r\n if (this._colorTextureArray && this._depthStencilTextureArray) {\r\n rtw = (this._engine as Engine).createMultiviewRenderTargetTexture(this.width, this.height);\r\n rtw.texture!.isReady = true;\r\n } else {\r\n rtw = super._cloneRenderTargetWrapper();\r\n }\r\n\r\n return rtw;\r\n }\r\n\r\n protected _swapRenderTargetWrapper(target: WebGLRenderTargetWrapper): void {\r\n super._swapRenderTargetWrapper(target);\r\n\r\n target._framebuffer = this._framebuffer;\r\n target._depthStencilBuffer = this._depthStencilBuffer;\r\n target._MSAAFramebuffer = this._MSAAFramebuffer;\r\n target._colorTextureArray = this._colorTextureArray;\r\n target._depthStencilTextureArray = this._depthStencilTextureArray;\r\n\r\n this._framebuffer = this._depthStencilBuffer = this._MSAAFramebuffer = this._colorTextureArray = this._depthStencilTextureArray = null;\r\n }\r\n\r\n /**\r\n * Shares the depth buffer of this render target with another render target.\r\n * @internal\r\n * @param renderTarget Destination renderTarget\r\n */\r\n public _shareDepth(renderTarget: WebGLRenderTargetWrapper): void {\r\n super._shareDepth(renderTarget);\r\n\r\n const gl = this._context;\r\n const depthbuffer = this._depthStencilBuffer;\r\n const framebuffer = renderTarget._MSAAFramebuffer || renderTarget._framebuffer;\r\n\r\n if (renderTarget._depthStencilBuffer) {\r\n gl.deleteRenderbuffer(renderTarget._depthStencilBuffer);\r\n }\r\n renderTarget._depthStencilBuffer = this._depthStencilBuffer;\r\n\r\n this._engine._bindUnboundFramebuffer(framebuffer);\r\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthbuffer);\r\n this._engine._bindUnboundFramebuffer(null);\r\n }\r\n\r\n /**\r\n * Binds a texture to this render target on a specific attachment\r\n * @param texture The texture to bind to the framebuffer\r\n * @param attachmentIndex Index of the attachment\r\n * @param faceIndexOrLayer The face or layer of the texture to render to in case of cube texture or array texture\r\n * @param lodLevel defines the lod level to bind to the frame buffer\r\n */\r\n private _bindTextureRenderTarget(texture: InternalTexture, attachmentIndex: number = 0, faceIndexOrLayer?: number, lodLevel: number = 0) {\r\n if (!texture._hardwareTexture) {\r\n return;\r\n }\r\n\r\n const framebuffer = this._framebuffer;\r\n\r\n const currentFB = this._engine._currentFramebuffer;\r\n this._engine._bindUnboundFramebuffer(framebuffer);\r\n\r\n if (this._engine.webGLVersion > 1) {\r\n const gl = this._context as WebGL2RenderingContext;\r\n\r\n const attachment = (gl)[\"COLOR_ATTACHMENT\" + attachmentIndex];\r\n if (texture.is2DArray || texture.is3D) {\r\n faceIndexOrLayer = faceIndexOrLayer ?? this.layerIndices?.[attachmentIndex] ?? 0;\r\n gl.framebufferTextureLayer(gl.FRAMEBUFFER, attachment, texture._hardwareTexture.underlyingResource, lodLevel, faceIndexOrLayer);\r\n } else if (texture.isCube) {\r\n // if face index is not specified, try to query it from faceIndices\r\n // default is face 0\r\n faceIndexOrLayer = faceIndexOrLayer ?? this.faceIndices?.[attachmentIndex] ?? 0;\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndexOrLayer, texture._hardwareTexture.underlyingResource, lodLevel);\r\n } else {\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, texture._hardwareTexture.underlyingResource, lodLevel);\r\n }\r\n } else {\r\n // Default behavior (WebGL)\r\n const gl = this._context;\r\n\r\n const attachment = (gl)[\"COLOR_ATTACHMENT\" + attachmentIndex + \"_WEBGL\"];\r\n const target = faceIndexOrLayer !== undefined ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndexOrLayer : gl.TEXTURE_2D;\r\n\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, target, texture._hardwareTexture.underlyingResource, lodLevel);\r\n }\r\n\r\n this._engine._bindUnboundFramebuffer(currentFB);\r\n }\r\n\r\n /**\r\n * Set a texture in the textures array\r\n * @param texture the texture to set\r\n * @param index the index in the textures array to set\r\n * @param disposePrevious If this function should dispose the previous texture\r\n */\r\n public setTexture(texture: InternalTexture, index: number = 0, disposePrevious: boolean = true) {\r\n super.setTexture(texture, index, disposePrevious);\r\n this._bindTextureRenderTarget(texture, index);\r\n }\r\n\r\n /**\r\n * Sets the layer and face indices of every render target texture\r\n * @param layers The layer of the texture to be set (make negative to not modify)\r\n * @param faces The face of the texture to be set (make negative to not modify)\r\n */\r\n public setLayerAndFaceIndices(layers: number[], faces: number[]) {\r\n super.setLayerAndFaceIndices(layers, faces);\r\n\r\n if (!this.textures || !this.layerIndices || !this.faceIndices) {\r\n return;\r\n }\r\n\r\n // the length of this._attachments is the right one as it does not count the depth texture, in case we generated it\r\n const textureCount = this._attachments?.length ?? this.textures.length;\r\n for (let index = 0; index < textureCount; index++) {\r\n const texture = this.textures[index];\r\n if (!texture) {\r\n // The target type was probably -1 at creation time and setTexture has not been called yet for this index\r\n continue;\r\n }\r\n if (texture.is2DArray || texture.is3D) {\r\n this._bindTextureRenderTarget(texture, index, this.layerIndices[index]);\r\n } else if (texture.isCube) {\r\n this._bindTextureRenderTarget(texture, index, this.faceIndices[index]);\r\n } else {\r\n this._bindTextureRenderTarget(texture, index);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Set the face and layer indices of a texture in the textures array\r\n * @param index The index of the texture in the textures array to modify\r\n * @param layer The layer of the texture to be set\r\n * @param face The face of the texture to be set\r\n */\r\n public setLayerAndFaceIndex(index: number = 0, layer?: number, face?: number): void {\r\n super.setLayerAndFaceIndex(index, layer, face);\r\n\r\n if (!this.textures || !this.layerIndices || !this.faceIndices) {\r\n return;\r\n }\r\n\r\n const texture = this.textures[index];\r\n if (texture.is2DArray || texture.is3D) {\r\n this._bindTextureRenderTarget(this.textures[index], index, this.layerIndices[index]);\r\n } else if (texture.isCube) {\r\n this._bindTextureRenderTarget(this.textures[index], index, this.faceIndices[index]);\r\n }\r\n }\r\n\r\n public dispose(disposeOnlyFramebuffers = this._disposeOnlyFramebuffers): void {\r\n const gl = this._context;\r\n\r\n if (!disposeOnlyFramebuffers) {\r\n if (this._colorTextureArray) {\r\n this._context.deleteTexture(this._colorTextureArray);\r\n this._colorTextureArray = null;\r\n }\r\n if (this._depthStencilTextureArray) {\r\n this._context.deleteTexture(this._depthStencilTextureArray);\r\n this._depthStencilTextureArray = null;\r\n }\r\n }\r\n\r\n if (this._framebuffer) {\r\n gl.deleteFramebuffer(this._framebuffer);\r\n this._framebuffer = null;\r\n }\r\n\r\n if (this._depthStencilBuffer) {\r\n gl.deleteRenderbuffer(this._depthStencilBuffer);\r\n this._depthStencilBuffer = null;\r\n }\r\n\r\n if (this._MSAAFramebuffer) {\r\n gl.deleteFramebuffer(this._MSAAFramebuffer);\r\n this._MSAAFramebuffer = null;\r\n }\r\n\r\n super.dispose(disposeOnlyFramebuffers);\r\n }\r\n}\r\n","import type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport type { RenderTargetCreationOptions, TextureSize } from \"../Materials/Textures/textureCreationOptions\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Constants } from \"./constants\";\r\nimport type { ThinEngine } from \"./thinEngine\";\r\nimport type { IMultiRenderTargetOptions } from \"../Materials/Textures/multiRenderTarget\";\r\n\r\n/**\r\n * An interface enforcing the renderTarget accessor to used by render target textures.\r\n */\r\nexport interface IRenderTargetTexture {\r\n /**\r\n * Entry point to access the wrapper on a texture.\r\n */\r\n renderTarget: Nullable;\r\n}\r\n\r\n/**\r\n * Wrapper around a render target (either single or multi textures)\r\n */\r\nexport class RenderTargetWrapper {\r\n protected _engine: ThinEngine;\r\n private _size: TextureSize;\r\n private _isCube: boolean;\r\n private _isMulti: boolean;\r\n private _textures: Nullable = null;\r\n private _faceIndices: Nullable = null;\r\n private _layerIndices: Nullable = null;\r\n /** @internal */\r\n public _samples = 1;\r\n\r\n /** @internal */\r\n public _attachments: Nullable = null;\r\n /** @internal */\r\n public _generateStencilBuffer: boolean = false;\r\n /** @internal */\r\n public _generateDepthBuffer: boolean = false;\r\n\r\n /** @internal */\r\n public _depthStencilTexture: Nullable;\r\n /** @internal */\r\n public _depthStencilTextureWithStencil: boolean = false;\r\n\r\n /**\r\n * Gets the depth/stencil texture (if created by a createDepthStencilTexture() call)\r\n */\r\n public get depthStencilTexture() {\r\n return this._depthStencilTexture;\r\n }\r\n\r\n /**\r\n * Indicates if the depth/stencil texture has a stencil aspect\r\n */\r\n public get depthStencilTextureWithStencil() {\r\n return this._depthStencilTextureWithStencil;\r\n }\r\n\r\n /**\r\n * Defines if the render target wrapper is for a cube texture or if false a 2d texture\r\n */\r\n public get isCube(): boolean {\r\n return this._isCube;\r\n }\r\n\r\n /**\r\n * Defines if the render target wrapper is for a single or multi target render wrapper\r\n */\r\n public get isMulti(): boolean {\r\n return this._isMulti;\r\n }\r\n\r\n /**\r\n * Defines if the render target wrapper is for a single or an array of textures\r\n */\r\n public get is2DArray(): boolean {\r\n return this.layers > 0;\r\n }\r\n\r\n /**\r\n * Gets the size of the render target wrapper (used for cubes, as width=height in this case)\r\n */\r\n public get size(): number {\r\n return this.width;\r\n }\r\n\r\n /**\r\n * Gets the width of the render target wrapper\r\n */\r\n public get width(): number {\r\n return (<{ width: number; height: number }>this._size).width || this._size;\r\n }\r\n\r\n /**\r\n * Gets the height of the render target wrapper\r\n */\r\n public get height(): number {\r\n return (<{ width: number; height: number }>this._size).height || this._size;\r\n }\r\n\r\n /**\r\n * Gets the number of layers of the render target wrapper (only used if is2DArray is true and wrapper is not a multi render target)\r\n */\r\n public get layers(): number {\r\n return (<{ width: number; height: number; layers?: number }>this._size).layers || 0;\r\n }\r\n\r\n /**\r\n * Gets the render texture. If this is a multi render target, gets the first texture\r\n */\r\n public get texture(): Nullable {\r\n return this._textures?.[0] ?? null;\r\n }\r\n\r\n /**\r\n * Gets the list of render textures. If we are not in a multi render target, the list will be null (use the texture getter instead)\r\n */\r\n public get textures(): Nullable {\r\n return this._textures;\r\n }\r\n\r\n /**\r\n * Gets the face indices that correspond to the list of render textures. If we are not in a multi render target, the list will be null\r\n */\r\n public get faceIndices(): Nullable {\r\n return this._faceIndices;\r\n }\r\n\r\n /**\r\n * Gets the layer indices that correspond to the list of render textures. If we are not in a multi render target, the list will be null\r\n */\r\n public get layerIndices(): Nullable {\r\n return this._layerIndices;\r\n }\r\n\r\n /**\r\n * Gets the sample count of the render target\r\n */\r\n public get samples(): number {\r\n return this._samples;\r\n }\r\n\r\n /**\r\n * Sets the sample count of the render target\r\n * @param value sample count\r\n * @param initializeBuffers If set to true, the engine will make an initializing call to drawBuffers (only used when isMulti=true).\r\n * @param force true to force calling the update sample count engine function even if the current sample count is equal to value\r\n * @returns the sample count that has been set\r\n */\r\n public setSamples(value: number, initializeBuffers = true, force = false): number {\r\n if (this.samples === value && !force) {\r\n return value;\r\n }\r\n\r\n const result = this._isMulti\r\n ? this._engine.updateMultipleRenderTargetTextureSampleCount(this, value, initializeBuffers)\r\n : this._engine.updateRenderTargetTextureSampleCount(this, value);\r\n this._samples = value;\r\n return result;\r\n }\r\n\r\n /**\r\n * Initializes the render target wrapper\r\n * @param isMulti true if the wrapper is a multi render target\r\n * @param isCube true if the wrapper should render to a cube texture\r\n * @param size size of the render target (width/height/layers)\r\n * @param engine engine used to create the render target\r\n */\r\n constructor(isMulti: boolean, isCube: boolean, size: TextureSize, engine: ThinEngine) {\r\n this._isMulti = isMulti;\r\n this._isCube = isCube;\r\n this._size = size;\r\n this._engine = engine;\r\n this._depthStencilTexture = null;\r\n }\r\n\r\n /**\r\n * Sets the render target texture(s)\r\n * @param textures texture(s) to set\r\n */\r\n public setTextures(textures: Nullable | Nullable): void {\r\n if (Array.isArray(textures)) {\r\n this._textures = textures;\r\n } else if (textures) {\r\n this._textures = [textures];\r\n } else {\r\n this._textures = null;\r\n }\r\n }\r\n\r\n /**\r\n * Set a texture in the textures array\r\n * @param texture The texture to set\r\n * @param index The index in the textures array to set\r\n * @param disposePrevious If this function should dispose the previous texture\r\n */\r\n public setTexture(texture: InternalTexture, index: number = 0, disposePrevious: boolean = true): void {\r\n if (!this._textures) {\r\n this._textures = [];\r\n }\r\n if (this._textures[index] && disposePrevious) {\r\n this._textures[index].dispose();\r\n }\r\n\r\n this._textures[index] = texture;\r\n }\r\n\r\n /**\r\n * Sets the layer and face indices of every render target texture bound to each color attachment\r\n * @param layers The layers of each texture to be set\r\n * @param faces The faces of each texture to be set\r\n */\r\n public setLayerAndFaceIndices(layers: number[], faces: number[]) {\r\n this._layerIndices = layers;\r\n this._faceIndices = faces;\r\n }\r\n\r\n /**\r\n * Sets the layer and face indices of a texture in the textures array that should be bound to each color attachment\r\n * @param index The index of the texture in the textures array to modify\r\n * @param layer The layer of the texture to be set\r\n * @param face The face of the texture to be set\r\n */\r\n public setLayerAndFaceIndex(index: number = 0, layer?: number, face?: number): void {\r\n if (!this._layerIndices) {\r\n this._layerIndices = [];\r\n }\r\n if (!this._faceIndices) {\r\n this._faceIndices = [];\r\n }\r\n\r\n if (layer !== undefined && layer >= 0) {\r\n this._layerIndices[index] = layer;\r\n }\r\n if (face !== undefined && face >= 0) {\r\n this._faceIndices[index] = face;\r\n }\r\n }\r\n\r\n /**\r\n * Creates the depth/stencil texture\r\n * @param comparisonFunction Comparison function to use for the texture\r\n * @param bilinearFiltering true if bilinear filtering should be used when sampling the texture\r\n * @param generateStencil true if the stencil aspect should also be created\r\n * @param samples sample count to use when creating the texture\r\n * @param format format of the depth texture\r\n * @param label defines the label to use for the texture (for debugging purpose only)\r\n * @returns the depth/stencil created texture\r\n */\r\n public createDepthStencilTexture(\r\n comparisonFunction: number = 0,\r\n bilinearFiltering: boolean = true,\r\n generateStencil: boolean = false,\r\n samples: number = 1,\r\n format: number = Constants.TEXTUREFORMAT_DEPTH32_FLOAT,\r\n label?: string\r\n ): InternalTexture {\r\n this._depthStencilTexture?.dispose();\r\n\r\n this._depthStencilTextureWithStencil = generateStencil;\r\n this._depthStencilTexture = this._engine.createDepthStencilTexture(\r\n this._size,\r\n {\r\n bilinearFiltering,\r\n comparisonFunction,\r\n generateStencil,\r\n isCube: this._isCube,\r\n samples,\r\n depthTextureFormat: format,\r\n label,\r\n },\r\n this\r\n );\r\n\r\n return this._depthStencilTexture;\r\n }\r\n\r\n /**\r\n * Shares the depth buffer of this render target with another render target.\r\n * @internal\r\n * @param renderTarget Destination renderTarget\r\n */\r\n public _shareDepth(renderTarget: RenderTargetWrapper): void {\r\n if (this._depthStencilTexture) {\r\n if (renderTarget._depthStencilTexture) {\r\n renderTarget._depthStencilTexture.dispose();\r\n }\r\n\r\n renderTarget._depthStencilTexture = this._depthStencilTexture;\r\n this._depthStencilTexture.incrementReferences();\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _swapAndDie(target: InternalTexture): void {\r\n if (this.texture) {\r\n this.texture._swapAndDie(target);\r\n }\r\n this._textures = null;\r\n this.dispose(true);\r\n }\r\n\r\n protected _cloneRenderTargetWrapper(): Nullable {\r\n let rtw: Nullable = null;\r\n\r\n if (this._isMulti) {\r\n const textureArray = this.textures;\r\n if (textureArray && textureArray.length > 0) {\r\n let generateDepthTexture = false;\r\n let textureCount = textureArray.length;\r\n\r\n const lastTextureSource = textureArray[textureArray.length - 1]._source;\r\n if (lastTextureSource === InternalTextureSource.Depth || lastTextureSource === InternalTextureSource.DepthStencil) {\r\n generateDepthTexture = true;\r\n textureCount--;\r\n }\r\n\r\n const samplingModes: number[] = [];\r\n const types: number[] = [];\r\n const formats: number[] = [];\r\n const targetTypes: number[] = [];\r\n const faceIndex: number[] = [];\r\n const layerIndex: number[] = [];\r\n const layerCounts: number[] = [];\r\n const internalTexture2Index: { [id: number]: number } = {};\r\n\r\n for (let i = 0; i < textureCount; ++i) {\r\n const texture = textureArray[i];\r\n\r\n samplingModes.push(texture.samplingMode);\r\n types.push(texture.type);\r\n formats.push(texture.format);\r\n\r\n const index = internalTexture2Index[texture.uniqueId];\r\n if (index !== undefined) {\r\n targetTypes.push(-1);\r\n layerCounts.push(0);\r\n } else {\r\n internalTexture2Index[texture.uniqueId] = i;\r\n if (texture.is2DArray) {\r\n targetTypes.push(Constants.TEXTURE_2D_ARRAY);\r\n layerCounts.push(texture.depth);\r\n } else if (texture.isCube) {\r\n targetTypes.push(Constants.TEXTURE_CUBE_MAP);\r\n layerCounts.push(0);\r\n } /*else if (texture.isCubeArray) {\r\n targetTypes.push(Constants.TEXTURE_CUBE_MAP_ARRAY);\r\n layerCounts.push(texture.depth);\r\n }*/ else if (texture.is3D) {\r\n targetTypes.push(Constants.TEXTURE_3D);\r\n layerCounts.push(texture.depth);\r\n } else {\r\n targetTypes.push(Constants.TEXTURE_2D);\r\n layerCounts.push(0);\r\n }\r\n }\r\n\r\n if (this._faceIndices) {\r\n faceIndex.push(this._faceIndices[i] ?? 0);\r\n }\r\n if (this._layerIndices) {\r\n layerIndex.push(this._layerIndices[i] ?? 0);\r\n }\r\n }\r\n\r\n const optionsMRT: IMultiRenderTargetOptions = {\r\n samplingModes,\r\n generateMipMaps: textureArray[0].generateMipMaps,\r\n generateDepthBuffer: this._generateDepthBuffer,\r\n generateStencilBuffer: this._generateStencilBuffer,\r\n generateDepthTexture,\r\n types,\r\n formats,\r\n textureCount,\r\n targetTypes,\r\n faceIndex,\r\n layerIndex,\r\n layerCounts,\r\n };\r\n const size = {\r\n width: this.width,\r\n height: this.height,\r\n };\r\n\r\n rtw = this._engine.createMultipleRenderTarget(size, optionsMRT);\r\n\r\n for (let i = 0; i < textureCount; ++i) {\r\n if (targetTypes[i] !== -1) {\r\n continue;\r\n }\r\n const index = internalTexture2Index[textureArray[i].uniqueId];\r\n rtw.setTexture(rtw.textures![index], i);\r\n }\r\n }\r\n } else {\r\n const options: RenderTargetCreationOptions = {};\r\n\r\n options.generateDepthBuffer = this._generateDepthBuffer;\r\n options.generateMipMaps = this.texture?.generateMipMaps ?? false;\r\n options.generateStencilBuffer = this._generateStencilBuffer;\r\n options.samplingMode = this.texture?.samplingMode;\r\n options.type = this.texture?.type;\r\n options.format = this.texture?.format;\r\n\r\n if (this.isCube) {\r\n rtw = this._engine.createRenderTargetCubeTexture(this.width, options);\r\n } else {\r\n const size = {\r\n width: this.width,\r\n height: this.height,\r\n layers: this.is2DArray ? this.texture?.depth : undefined,\r\n };\r\n\r\n rtw = this._engine.createRenderTargetTexture(size, options);\r\n }\r\n rtw.texture!.isReady = true;\r\n }\r\n\r\n return rtw;\r\n }\r\n\r\n protected _swapRenderTargetWrapper(target: RenderTargetWrapper): void {\r\n if (this._textures && target._textures) {\r\n for (let i = 0; i < this._textures.length; ++i) {\r\n this._textures[i]._swapAndDie(target._textures[i], false);\r\n target._textures[i].isReady = true;\r\n }\r\n }\r\n if (this._depthStencilTexture && target._depthStencilTexture) {\r\n this._depthStencilTexture._swapAndDie(target._depthStencilTexture);\r\n target._depthStencilTexture.isReady = true;\r\n }\r\n\r\n this._textures = null;\r\n this._depthStencilTexture = null;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n const rtw = this._cloneRenderTargetWrapper();\r\n if (!rtw) {\r\n return;\r\n }\r\n\r\n if (this._depthStencilTexture) {\r\n const samplingMode = this._depthStencilTexture.samplingMode;\r\n const bilinear =\r\n samplingMode === Constants.TEXTURE_BILINEAR_SAMPLINGMODE ||\r\n samplingMode === Constants.TEXTURE_TRILINEAR_SAMPLINGMODE ||\r\n samplingMode === Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST;\r\n rtw.createDepthStencilTexture(this._depthStencilTexture._comparisonFunction, bilinear, this._depthStencilTextureWithStencil, this._depthStencilTexture.samples);\r\n }\r\n\r\n if (this.samples > 1) {\r\n rtw.setSamples(this.samples);\r\n }\r\n\r\n rtw._swapRenderTargetWrapper(this);\r\n rtw.dispose();\r\n }\r\n\r\n /**\r\n * Releases the internal render textures\r\n */\r\n public releaseTextures(): void {\r\n if (this._textures) {\r\n for (let i = 0; i < this._textures?.length ?? 0; ++i) {\r\n this._textures[i].dispose();\r\n }\r\n }\r\n this._textures = null;\r\n }\r\n\r\n /**\r\n * Disposes the whole render target wrapper\r\n * @param disposeOnlyFramebuffers true if only the frame buffers should be released (used for the WebGL engine). If false, all the textures will also be released\r\n */\r\n public dispose(disposeOnlyFramebuffers = false): void {\r\n if (!disposeOnlyFramebuffers) {\r\n this._depthStencilTexture?.dispose();\r\n this._depthStencilTexture = null;\r\n this.releaseTextures();\r\n }\r\n\r\n this._engine._releaseRenderTargetWrapper(this);\r\n }\r\n}\r\n","import { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { RenderTargetCreationOptions, DepthTextureCreationOptions, TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport { ThinEngine } from \"../thinEngine\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { RenderTargetWrapper } from \"../renderTargetWrapper\";\r\nimport { WebGLRenderTargetWrapper } from \"../WebGL/webGLRenderTargetWrapper\";\r\nimport type { WebGLHardwareTexture } from \"../WebGL/webGLHardwareTexture\";\r\n\r\nimport { Constants } from \"../constants\";\r\n\r\n/**\r\n * Type used to define a texture size (either with a number or with a rect width and height)\r\n * @deprecated please use TextureSize instead\r\n */\r\nexport type RenderTargetTextureSize = TextureSize;\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a new render target texture\r\n * @param size defines the size of the texture\r\n * @param options defines the options used to create the texture\r\n * @returns a new render target wrapper ready to render texture\r\n */\r\n createRenderTargetTexture(size: TextureSize, options: boolean | RenderTargetCreationOptions): RenderTargetWrapper;\r\n\r\n /**\r\n * Creates a depth stencil texture.\r\n * This is only available in WebGL 2 or with the depth texture extension available.\r\n * @param size The size of face edge in the texture.\r\n * @param options The options defining the texture.\r\n * @param rtWrapper The render target wrapper for which the depth/stencil texture must be created\r\n * @returns The texture\r\n */\r\n createDepthStencilTexture(size: TextureSize, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture;\r\n\r\n /**\r\n * Updates the sample count of a render target texture\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#multisample-render-targets\r\n * @param rtWrapper defines the render target wrapper to update\r\n * @param samples defines the sample count to set\r\n * @returns the effective sample count (could be 0 if multisample render targets are not supported)\r\n */\r\n updateRenderTargetTextureSampleCount(rtWrapper: Nullable, samples: number): number;\r\n\r\n /** @internal */\r\n _createDepthStencilTexture(size: TextureSize, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture;\r\n\r\n /** @internal */\r\n _createHardwareRenderTargetWrapper(isMulti: boolean, isCube: boolean, size: TextureSize): RenderTargetWrapper;\r\n }\r\n}\r\n\r\nThinEngine.prototype._createHardwareRenderTargetWrapper = function (isMulti: boolean, isCube: boolean, size: TextureSize): RenderTargetWrapper {\r\n const rtWrapper = new WebGLRenderTargetWrapper(isMulti, isCube, size, this, this._gl);\r\n this._renderTargetWrapperCache.push(rtWrapper);\r\n return rtWrapper;\r\n};\r\n\r\nThinEngine.prototype.createRenderTargetTexture = function (this: ThinEngine, size: TextureSize, options: boolean | RenderTargetCreationOptions): RenderTargetWrapper {\r\n const rtWrapper = this._createHardwareRenderTargetWrapper(false, false, size) as WebGLRenderTargetWrapper;\r\n\r\n let generateDepthBuffer = true;\r\n let generateStencilBuffer = false;\r\n let noColorAttachment = false;\r\n let colorAttachment: InternalTexture | undefined = undefined;\r\n let samples = 1;\r\n if (options !== undefined && typeof options === \"object\") {\r\n generateDepthBuffer = options.generateDepthBuffer ?? true;\r\n generateStencilBuffer = !!options.generateStencilBuffer;\r\n noColorAttachment = !!options.noColorAttachment;\r\n colorAttachment = options.colorAttachment;\r\n samples = options.samples ?? 1;\r\n }\r\n\r\n const texture = colorAttachment || (noColorAttachment ? null : this._createInternalTexture(size, options, true, InternalTextureSource.RenderTarget));\r\n const width = (<{ width: number; height: number; layers?: number }>size).width || size;\r\n const height = (<{ width: number; height: number; layers?: number }>size).height || size;\r\n\r\n const currentFrameBuffer = this._currentFramebuffer;\r\n const gl = this._gl;\r\n\r\n // Create the framebuffer\r\n const framebuffer = gl.createFramebuffer();\r\n this._bindUnboundFramebuffer(framebuffer);\r\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(generateStencilBuffer, generateDepthBuffer, width, height);\r\n\r\n // No need to rebind on every frame\r\n if (texture && !texture.is2DArray) {\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture._hardwareTexture!.underlyingResource, 0);\r\n }\r\n\r\n this._bindUnboundFramebuffer(currentFrameBuffer);\r\n\r\n rtWrapper._framebuffer = framebuffer;\r\n rtWrapper._generateDepthBuffer = generateDepthBuffer;\r\n rtWrapper._generateStencilBuffer = generateStencilBuffer;\r\n\r\n rtWrapper.setTextures(texture);\r\n\r\n this.updateRenderTargetTextureSampleCount(rtWrapper, samples);\r\n\r\n return rtWrapper;\r\n};\r\n\r\nThinEngine.prototype.createDepthStencilTexture = function (size: TextureSize, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture {\r\n if (options.isCube) {\r\n const width = (<{ width: number; height: number }>size).width || size;\r\n return this._createDepthStencilCubeTexture(width, options, rtWrapper);\r\n } else {\r\n return this._createDepthStencilTexture(size, options, rtWrapper);\r\n }\r\n};\r\n\r\nThinEngine.prototype._createDepthStencilTexture = function (size: TextureSize, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture {\r\n const gl = this._gl;\r\n const layers = (<{ width: number; height: number; layers?: number }>size).layers || 0;\r\n const target = layers !== 0 ? gl.TEXTURE_2D_ARRAY : gl.TEXTURE_2D;\r\n const internalTexture = new InternalTexture(this, InternalTextureSource.DepthStencil);\r\n if (!this._caps.depthTextureExtension) {\r\n Logger.Error(\"Depth texture is not supported by your browser or hardware.\");\r\n return internalTexture;\r\n }\r\n\r\n const internalOptions = {\r\n bilinearFiltering: false,\r\n comparisonFunction: 0,\r\n generateStencil: false,\r\n ...options,\r\n };\r\n\r\n this._bindTextureDirectly(target, internalTexture, true);\r\n\r\n this._setupDepthStencilTexture(\r\n internalTexture,\r\n size,\r\n internalOptions.generateStencil,\r\n internalOptions.comparisonFunction === 0 ? false : internalOptions.bilinearFiltering,\r\n internalOptions.comparisonFunction,\r\n internalOptions.samples\r\n );\r\n\r\n if (internalOptions.depthTextureFormat !== undefined) {\r\n if (\r\n internalOptions.depthTextureFormat !== Constants.TEXTUREFORMAT_DEPTH16 &&\r\n internalOptions.depthTextureFormat !== Constants.TEXTUREFORMAT_DEPTH24 &&\r\n internalOptions.depthTextureFormat !== Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 &&\r\n internalOptions.depthTextureFormat !== Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 &&\r\n internalOptions.depthTextureFormat !== Constants.TEXTUREFORMAT_DEPTH32_FLOAT &&\r\n internalOptions.depthTextureFormat !== Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8\r\n ) {\r\n Logger.Error(\"Depth texture format is not supported.\");\r\n return internalTexture;\r\n }\r\n internalTexture.format = internalOptions.depthTextureFormat;\r\n } else {\r\n internalTexture.format = internalOptions.generateStencil ? Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 : Constants.TEXTUREFORMAT_DEPTH24;\r\n }\r\n\r\n const hasStencil =\r\n internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 ||\r\n internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 ||\r\n internalTexture.format === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8;\r\n\r\n rtWrapper._depthStencilTexture = internalTexture;\r\n rtWrapper._depthStencilTextureWithStencil = hasStencil;\r\n\r\n let type: GLenum = gl.UNSIGNED_INT;\r\n if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH16) {\r\n type = gl.UNSIGNED_SHORT;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 || internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8) {\r\n type = gl.UNSIGNED_INT_24_8;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH32_FLOAT) {\r\n type = gl.FLOAT;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8) {\r\n type = gl.FLOAT_32_UNSIGNED_INT_24_8_REV;\r\n }\r\n\r\n const format: GLenum = hasStencil ? gl.DEPTH_STENCIL : gl.DEPTH_COMPONENT;\r\n let internalFormat = format;\r\n if (this.webGLVersion > 1) {\r\n if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH16) {\r\n internalFormat = gl.DEPTH_COMPONENT16;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24) {\r\n internalFormat = gl.DEPTH_COMPONENT24;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 || internalTexture.format === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8) {\r\n internalFormat = gl.DEPTH24_STENCIL8;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH32_FLOAT) {\r\n internalFormat = gl.DEPTH_COMPONENT32F;\r\n } else if (internalTexture.format === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8) {\r\n internalFormat = gl.DEPTH32F_STENCIL8;\r\n }\r\n }\r\n\r\n if (internalTexture.is2DArray) {\r\n gl.texImage3D(target, 0, internalFormat, internalTexture.width, internalTexture.height, layers, 0, format, type, null);\r\n } else {\r\n gl.texImage2D(target, 0, internalFormat, internalTexture.width, internalTexture.height, 0, format, type, null);\r\n }\r\n\r\n this._bindTextureDirectly(target, null);\r\n\r\n this._internalTexturesCache.push(internalTexture);\r\n\r\n // Dispose previous depth/stencil render buffers and clear the corresponding attachment.\r\n // Next time this framebuffer is bound, the new depth/stencil texture will be attached.\r\n const glRtWrapper = (rtWrapper as any);\r\n if (glRtWrapper._depthStencilBuffer) {\r\n const currentFrameBuffer = this._currentFramebuffer;\r\n this._bindUnboundFramebuffer(glRtWrapper._framebuffer);\r\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);\r\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null);\r\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);\r\n this._bindUnboundFramebuffer(currentFrameBuffer);\r\n\r\n gl.deleteRenderbuffer(glRtWrapper._depthStencilBuffer);\r\n glRtWrapper._depthStencilBuffer = null;\r\n }\r\n\r\n return internalTexture;\r\n};\r\n\r\nThinEngine.prototype.updateRenderTargetTextureSampleCount = function (rtWrapper: Nullable, samples: number): number {\r\n if (this.webGLVersion < 2 || !rtWrapper || !rtWrapper.texture) {\r\n return 1;\r\n }\r\n\r\n if (rtWrapper.samples === samples) {\r\n return samples;\r\n }\r\n\r\n const gl = this._gl;\r\n\r\n samples = Math.min(samples, this.getCaps().maxMSAASamples);\r\n\r\n // Dispose previous render buffers\r\n if (rtWrapper._depthStencilBuffer) {\r\n gl.deleteRenderbuffer(rtWrapper._depthStencilBuffer);\r\n rtWrapper._depthStencilBuffer = null;\r\n }\r\n\r\n if (rtWrapper._MSAAFramebuffer) {\r\n gl.deleteFramebuffer(rtWrapper._MSAAFramebuffer);\r\n rtWrapper._MSAAFramebuffer = null;\r\n }\r\n\r\n const hardwareTexture = rtWrapper.texture._hardwareTexture as WebGLHardwareTexture;\r\n hardwareTexture.releaseMSAARenderBuffers();\r\n\r\n if (samples > 1 && typeof gl.renderbufferStorageMultisample === \"function\") {\r\n const framebuffer = gl.createFramebuffer();\r\n\r\n if (!framebuffer) {\r\n throw new Error(\"Unable to create multi sampled framebuffer\");\r\n }\r\n\r\n rtWrapper._MSAAFramebuffer = framebuffer;\r\n this._bindUnboundFramebuffer(rtWrapper._MSAAFramebuffer);\r\n\r\n const colorRenderbuffer = this._createRenderBuffer(\r\n rtWrapper.texture.width,\r\n rtWrapper.texture.height,\r\n samples,\r\n -1 /* not used */,\r\n this._getRGBAMultiSampleBufferFormat(rtWrapper.texture.type),\r\n gl.COLOR_ATTACHMENT0,\r\n false\r\n );\r\n\r\n if (!colorRenderbuffer) {\r\n throw new Error(\"Unable to create multi sampled framebuffer\");\r\n }\r\n\r\n hardwareTexture.addMSAARenderBuffer(colorRenderbuffer);\r\n } else {\r\n this._bindUnboundFramebuffer(rtWrapper._framebuffer);\r\n }\r\n\r\n rtWrapper.texture.samples = samples;\r\n rtWrapper._samples = samples;\r\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(\r\n rtWrapper._generateStencilBuffer,\r\n rtWrapper._generateDepthBuffer,\r\n rtWrapper.texture.width,\r\n rtWrapper.texture.height,\r\n samples\r\n );\r\n\r\n this._bindUnboundFramebuffer(null);\r\n\r\n return samples;\r\n};\r\n","import type { Nullable } from \"../types\";\r\nimport { SmartArray } from \"../Misc/smartArray\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Vector2 } from \"../Maths/math.vector\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { RenderTargetCreationOptions } from \"../Materials/Textures/textureCreationOptions\";\r\nimport \"../Shaders/postprocess.vertex\";\r\nimport type { IInspectable } from \"../Misc/iInspectable\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport type { Color4 } from \"../Maths/math.color\";\r\n\r\nimport \"../Engines/Extensions/engine.renderTarget\";\r\nimport type { NodeMaterial } from \"../Materials/Node/nodeMaterial\";\r\nimport { serialize, serializeAsColor4, SerializationHelper } from \"../Misc/decorators\";\r\nimport { GetClass, RegisterClass } from \"../Misc/typeStore\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport type { AbstractScene } from \"../abstractScene\";\r\nimport type { RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { WebVRFreeCamera } from \"../Cameras/VR/webVRCamera\";\r\nimport type { Animation } from \"../Animations/animation\";\r\nimport type { PrePassRenderer } from \"../Rendering/prePassRenderer\";\r\nimport type { PrePassEffectConfiguration } from \"../Rendering/prePassEffectConfiguration\";\r\n\r\n/**\r\n * Allows for custom processing of the shader code used by a post process\r\n */\r\nexport type PostProcessCustomShaderCodeProcessing = {\r\n /**\r\n * If provided, will be called two times with the vertex and fragment code so that this code can be updated after the #include have been processed\r\n */\r\n processCodeAfterIncludes?: (postProcessName: string, shaderType: string, code: string) => string;\r\n /**\r\n * If provided, will be called two times with the vertex and fragment code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: (postProcessName: string, shaderType: string, code: string) => string;\r\n /**\r\n * If provided, will be called before creating the effect to collect additional custom bindings (defines, uniforms, samplers)\r\n */\r\n defineCustomBindings?: (postProcessName: string, defines: Nullable, uniforms: string[], samplers: string[]) => Nullable;\r\n /**\r\n * If provided, will be called when binding inputs to the shader code to allow the user to add custom bindings\r\n */\r\n bindCustomBindings?: (postProcessName: string, effect: Effect) => void;\r\n};\r\n\r\n/**\r\n * Size options for a post process\r\n */\r\nexport type PostProcessOptions = { width: number; height: number };\r\n\r\ntype TextureCache = { texture: RenderTargetWrapper; postProcessChannel: number; lastUsedRenderId: number };\r\n\r\n/**\r\n * PostProcess can be used to apply a shader to a texture after it has been rendered\r\n * See https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses\r\n */\r\nexport class PostProcess {\r\n /** @internal */\r\n public _parentContainer: Nullable = null;\r\n\r\n private static _CustomShaderCodeProcessing: { [postProcessName: string]: PostProcessCustomShaderCodeProcessing } = {};\r\n\r\n /**\r\n * Registers a shader code processing with a post process name.\r\n * @param postProcessName name of the post process. Use null for the fallback shader code processing. This is the shader code processing that will be used in case no specific shader code processing has been associated to a post process name\r\n * @param customShaderCodeProcessing shader code processing to associate to the post process name\r\n * @returns\r\n */\r\n public static RegisterShaderCodeProcessing(postProcessName: Nullable, customShaderCodeProcessing?: PostProcessCustomShaderCodeProcessing) {\r\n if (!customShaderCodeProcessing) {\r\n delete PostProcess._CustomShaderCodeProcessing[postProcessName ?? \"\"];\r\n return;\r\n }\r\n\r\n PostProcess._CustomShaderCodeProcessing[postProcessName ?? \"\"] = customShaderCodeProcessing;\r\n }\r\n\r\n private static _GetShaderCodeProcessing(postProcessName: string) {\r\n return PostProcess._CustomShaderCodeProcessing[postProcessName] ?? PostProcess._CustomShaderCodeProcessing[\"\"];\r\n }\r\n\r\n /**\r\n * Gets or sets the unique id of the post process\r\n */\r\n @serialize()\r\n public uniqueId: number;\r\n\r\n /** Name of the PostProcess. */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * Width of the texture to apply the post process on\r\n */\r\n @serialize()\r\n public width = -1;\r\n\r\n /**\r\n * Height of the texture to apply the post process on\r\n */\r\n @serialize()\r\n public height = -1;\r\n\r\n /**\r\n * Gets the node material used to create this postprocess (null if the postprocess was manually created)\r\n */\r\n public nodeMaterialSource: Nullable = null;\r\n\r\n /**\r\n * Internal, reference to the location where this postprocess was output to. (Typically the texture on the next postprocess in the chain)\r\n * @internal\r\n */\r\n public _outputTexture: Nullable = null;\r\n /**\r\n * Sampling mode used by the shader\r\n * See https://doc.babylonjs.com/classes/3.1/texture\r\n */\r\n @serialize()\r\n public renderTargetSamplingMode: number;\r\n /**\r\n * Clear color to use when screen clearing\r\n */\r\n @serializeAsColor4()\r\n public clearColor: Color4;\r\n /**\r\n * If the buffer needs to be cleared before applying the post process. (default: true)\r\n * Should be set to false if shader will overwrite all previous pixels.\r\n */\r\n @serialize()\r\n public autoClear = true;\r\n /**\r\n * If clearing the buffer should be forced in autoClear mode, even when alpha mode is enabled (default: false).\r\n * By default, the buffer will only be cleared if alpha mode is disabled (and autoClear is true).\r\n */\r\n @serialize()\r\n public forceAutoClearInAlphaMode = false;\r\n /**\r\n * Type of alpha mode to use when performing the post process (default: Engine.ALPHA_DISABLE)\r\n */\r\n @serialize()\r\n public alphaMode = Constants.ALPHA_DISABLE;\r\n /**\r\n * Sets the setAlphaBlendConstants of the babylon engine\r\n */\r\n @serialize()\r\n public alphaConstants: Color4;\r\n /**\r\n * Animations to be used for the post processing\r\n */\r\n public animations = new Array();\r\n\r\n /**\r\n * Enable Pixel Perfect mode where texture is not scaled to be power of 2.\r\n * Can only be used on a single postprocess or on the last one of a chain. (default: false)\r\n */\r\n @serialize()\r\n public enablePixelPerfectMode = false;\r\n\r\n /**\r\n * Force the postprocess to be applied without taking in account viewport\r\n */\r\n @serialize()\r\n public forceFullscreenViewport = true;\r\n\r\n /**\r\n * List of inspectable custom properties (used by the Inspector)\r\n * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility\r\n */\r\n public inspectableCustomProperties: IInspectable[];\r\n\r\n /**\r\n * Scale mode for the post process (default: Engine.SCALEMODE_FLOOR)\r\n *\r\n * | Value | Type | Description |\r\n * | ----- | ----------------------------------- | ----------- |\r\n * | 1 | SCALEMODE_FLOOR | [engine.scalemode_floor](https://doc.babylonjs.com/api/classes/babylon.engine#scalemode_floor) |\r\n * | 2 | SCALEMODE_NEAREST | [engine.scalemode_nearest](https://doc.babylonjs.com/api/classes/babylon.engine#scalemode_nearest) |\r\n * | 3 | SCALEMODE_CEILING | [engine.scalemode_ceiling](https://doc.babylonjs.com/api/classes/babylon.engine#scalemode_ceiling) |\r\n *\r\n */\r\n @serialize()\r\n public scaleMode = Constants.SCALEMODE_FLOOR;\r\n /**\r\n * Force textures to be a power of two (default: false)\r\n */\r\n @serialize()\r\n public alwaysForcePOT = false;\r\n\r\n @serialize(\"samples\")\r\n private _samples = 1;\r\n\r\n /**\r\n * Number of sample textures (default: 1)\r\n */\r\n public get samples() {\r\n return this._samples;\r\n }\r\n\r\n public set samples(n: number) {\r\n this._samples = Math.min(n, this._engine.getCaps().maxMSAASamples);\r\n\r\n this._textures.forEach((texture) => {\r\n texture.setSamples(this._samples);\r\n });\r\n }\r\n\r\n /**\r\n * Modify the scale of the post process to be the same as the viewport (default: false)\r\n */\r\n @serialize()\r\n public adaptScaleToCurrentViewport = false;\r\n\r\n private _camera: Camera;\r\n protected _scene: Scene;\r\n private _engine: Engine;\r\n\r\n private _options: number | PostProcessOptions;\r\n private _reusable = false;\r\n private _renderId = 0;\r\n private _textureType: number;\r\n private _textureFormat: number;\r\n private _shaderLanguage: ShaderLanguage;\r\n\r\n /**\r\n * if externalTextureSamplerBinding is true, the \"apply\" method won't bind the textureSampler texture, it is expected to be done by the \"outside\" (by the onApplyObservable observer most probably).\r\n * counter-productive in some cases because if the texture bound by \"apply\" is different from the currently texture bound, (the one set by the onApplyObservable observer, for eg) some\r\n * internal structures (materialContext) will be dirtified, which may impact performances\r\n */\r\n public externalTextureSamplerBinding = false;\r\n\r\n /**\r\n * Smart array of input and output textures for the post process.\r\n * @internal\r\n */\r\n public _textures = new SmartArray(2);\r\n /**\r\n * Smart array of input and output textures for the post process.\r\n * @internal\r\n */\r\n private _textureCache: TextureCache[] = [];\r\n /**\r\n * The index in _textures that corresponds to the output texture.\r\n * @internal\r\n */\r\n public _currentRenderTextureInd = 0;\r\n private _drawWrapper: DrawWrapper;\r\n private _samplers: string[];\r\n private _fragmentUrl: string;\r\n private _vertexUrl: string;\r\n private _parameters: string[];\r\n protected _postProcessDefines: Nullable;\r\n private _scaleRatio = new Vector2(1, 1);\r\n protected _indexParameters: any;\r\n private _shareOutputWithPostProcess: Nullable;\r\n private _texelSize = Vector2.Zero();\r\n\r\n /** @internal */\r\n public _forcedOutputTexture: Nullable;\r\n\r\n /**\r\n * Prepass configuration in case this post process needs a texture from prepass\r\n * @internal\r\n */\r\n public _prePassEffectConfiguration: PrePassEffectConfiguration;\r\n\r\n /**\r\n * Returns the fragment url or shader name used in the post process.\r\n * @returns the fragment url or name in the shader store.\r\n */\r\n public getEffectName(): string {\r\n return this._fragmentUrl;\r\n }\r\n\r\n // Events\r\n\r\n /**\r\n * An event triggered when the postprocess is activated.\r\n */\r\n public onActivateObservable = new Observable();\r\n\r\n private _onActivateObserver: Nullable>;\r\n /**\r\n * A function that is added to the onActivateObservable\r\n */\r\n public set onActivate(callback: Nullable<(camera: Camera) => void>) {\r\n if (this._onActivateObserver) {\r\n this.onActivateObservable.remove(this._onActivateObserver);\r\n }\r\n if (callback) {\r\n this._onActivateObserver = this.onActivateObservable.add(callback);\r\n }\r\n }\r\n\r\n /**\r\n * An event triggered when the postprocess changes its size.\r\n */\r\n public onSizeChangedObservable = new Observable();\r\n\r\n private _onSizeChangedObserver: Nullable>;\r\n /**\r\n * A function that is added to the onSizeChangedObservable\r\n */\r\n public set onSizeChanged(callback: (postProcess: PostProcess) => void) {\r\n if (this._onSizeChangedObserver) {\r\n this.onSizeChangedObservable.remove(this._onSizeChangedObserver);\r\n }\r\n this._onSizeChangedObserver = this.onSizeChangedObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when the postprocess applies its effect.\r\n */\r\n public onApplyObservable = new Observable();\r\n\r\n private _onApplyObserver: Nullable>;\r\n /**\r\n * A function that is added to the onApplyObservable\r\n */\r\n public set onApply(callback: (effect: Effect) => void) {\r\n if (this._onApplyObserver) {\r\n this.onApplyObservable.remove(this._onApplyObserver);\r\n }\r\n this._onApplyObserver = this.onApplyObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered before rendering the postprocess\r\n */\r\n public onBeforeRenderObservable = new Observable();\r\n\r\n private _onBeforeRenderObserver: Nullable>;\r\n /**\r\n * A function that is added to the onBeforeRenderObservable\r\n */\r\n public set onBeforeRender(callback: (effect: Effect) => void) {\r\n if (this._onBeforeRenderObserver) {\r\n this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\r\n }\r\n this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered after rendering the postprocess\r\n */\r\n public onAfterRenderObservable = new Observable();\r\n\r\n private _onAfterRenderObserver: Nullable>;\r\n /**\r\n * A function that is added to the onAfterRenderObservable\r\n */\r\n public set onAfterRender(callback: (efect: Effect) => void) {\r\n if (this._onAfterRenderObserver) {\r\n this.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n }\r\n this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);\r\n }\r\n\r\n /**\r\n * The input texture for this post process and the output texture of the previous post process. When added to a pipeline the previous post process will\r\n * render it's output into this texture and this texture will be used as textureSampler in the fragment shader of this post process.\r\n */\r\n public get inputTexture(): RenderTargetWrapper {\r\n return this._textures.data[this._currentRenderTextureInd];\r\n }\r\n\r\n public set inputTexture(value: RenderTargetWrapper) {\r\n this._forcedOutputTexture = value;\r\n }\r\n\r\n /**\r\n * Since inputTexture should always be defined, if we previously manually set `inputTexture`,\r\n * the only way to unset it is to use this function to restore its internal state\r\n */\r\n public restoreDefaultInputTexture() {\r\n if (this._forcedOutputTexture) {\r\n this._forcedOutputTexture = null;\r\n this.markTextureDirty();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the camera which post process is applied to.\r\n * @returns The camera the post process is applied to.\r\n */\r\n public getCamera(): Camera {\r\n return this._camera;\r\n }\r\n\r\n /**\r\n * Gets the texel size of the postprocess.\r\n * See https://en.wikipedia.org/wiki/Texel_(graphics)\r\n */\r\n public get texelSize(): Vector2 {\r\n if (this._shareOutputWithPostProcess) {\r\n return this._shareOutputWithPostProcess.texelSize;\r\n }\r\n\r\n if (this._forcedOutputTexture) {\r\n this._texelSize.copyFromFloats(1.0 / this._forcedOutputTexture.width, 1.0 / this._forcedOutputTexture.height);\r\n }\r\n\r\n return this._texelSize;\r\n }\r\n\r\n /**\r\n * Creates a new instance PostProcess\r\n * @param name The name of the PostProcess.\r\n * @param fragmentUrl The url of the fragment shader to be used.\r\n * @param parameters Array of the names of uniform non-sampler2D variables that will be passed to the shader.\r\n * @param samplers Array of the names of uniform sampler2D variables that will be passed to the shader.\r\n * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)\r\n * @param camera The camera to apply the render pass to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\r\n * @param engine The engine which the post process will be applied. (default: current engine)\r\n * @param reusable If the post process can be reused on the same frame. (default: false)\r\n * @param defines String of defines that will be set when running the fragment shader. (default: null)\r\n * @param textureType Type of textures used when performing the post process. (default: 0)\r\n * @param vertexUrl The url of the vertex shader to be used. (default: \"postprocess\")\r\n * @param indexParameters The index parameters to be used for babylons include syntax \"#include[0..varyingCount]\". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx\r\n * @param blockCompilation If the shader should not be compiled immediatly. (default: false)\r\n * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)\r\n */\r\n constructor(\r\n name: string,\r\n fragmentUrl: string,\r\n parameters: Nullable,\r\n samplers: Nullable,\r\n options: number | PostProcessOptions,\r\n camera: Nullable,\r\n samplingMode: number = Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n defines: Nullable = null,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n vertexUrl: string = \"postprocess\",\r\n indexParameters?: any,\r\n blockCompilation = false,\r\n textureFormat = Constants.TEXTUREFORMAT_RGBA,\r\n shaderLanguage = ShaderLanguage.GLSL\r\n ) {\r\n this.name = name;\r\n if (camera != null) {\r\n this._camera = camera;\r\n this._scene = camera.getScene();\r\n camera.attachPostProcess(this);\r\n this._engine = this._scene.getEngine();\r\n\r\n this._scene.postProcesses.push(this);\r\n this.uniqueId = this._scene.getUniqueId();\r\n } else if (engine) {\r\n this._engine = engine;\r\n this._engine.postProcesses.push(this);\r\n }\r\n this._options = options;\r\n this.renderTargetSamplingMode = samplingMode ? samplingMode : Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n this._reusable = reusable || false;\r\n this._textureType = textureType;\r\n this._textureFormat = textureFormat;\r\n this._shaderLanguage = shaderLanguage;\r\n\r\n this._samplers = samplers || [];\r\n this._samplers.push(\"textureSampler\");\r\n\r\n this._fragmentUrl = fragmentUrl;\r\n this._vertexUrl = vertexUrl;\r\n this._parameters = parameters || [];\r\n\r\n this._parameters.push(\"scale\");\r\n\r\n this._indexParameters = indexParameters;\r\n this._drawWrapper = new DrawWrapper(this._engine);\r\n\r\n if (!blockCompilation) {\r\n this.updateEffect(defines);\r\n }\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"PostProcess\" string\r\n */\r\n public getClassName(): string {\r\n return \"PostProcess\";\r\n }\r\n\r\n /**\r\n * Gets the engine which this post process belongs to.\r\n * @returns The engine the post process was enabled with.\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The effect that is created when initializing the post process.\r\n * @returns The created effect corresponding the the postprocess.\r\n */\r\n public getEffect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n /**\r\n * To avoid multiple redundant textures for multiple post process, the output the output texture for this post process can be shared with another.\r\n * @param postProcess The post process to share the output with.\r\n * @returns This post process.\r\n */\r\n public shareOutputWith(postProcess: PostProcess): PostProcess {\r\n this._disposeTextures();\r\n\r\n this._shareOutputWithPostProcess = postProcess;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Reverses the effect of calling shareOutputWith and returns the post process back to its original state.\r\n * This should be called if the post process that shares output with this post process is disabled/disposed.\r\n */\r\n public useOwnOutput() {\r\n if (this._textures.length == 0) {\r\n this._textures = new SmartArray(2);\r\n }\r\n\r\n this._shareOutputWithPostProcess = null;\r\n }\r\n\r\n /**\r\n * Updates the effect with the current post process compile time values and recompiles the shader.\r\n * @param defines Define statements that should be added at the beginning of the shader. (default: null)\r\n * @param uniforms Set of uniform variables that will be passed to the shader. (default: null)\r\n * @param samplers Set of Texture2D variables that will be passed to the shader. (default: null)\r\n * @param indexParameters The index parameters to be used for babylons include syntax \"#include[0..varyingCount]\". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx\r\n * @param onCompiled Called when the shader has been compiled.\r\n * @param onError Called if there is an error when compiling a shader.\r\n * @param vertexUrl The url of the vertex shader to be used (default: the one given at construction time)\r\n * @param fragmentUrl The url of the fragment shader to be used (default: the one given at construction time)\r\n */\r\n public updateEffect(\r\n defines: Nullable = null,\r\n uniforms: Nullable = null,\r\n samplers: Nullable = null,\r\n indexParameters?: any,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void,\r\n vertexUrl?: string,\r\n fragmentUrl?: string\r\n ) {\r\n const customShaderCodeProcessing = PostProcess._GetShaderCodeProcessing(this.name);\r\n if (customShaderCodeProcessing?.defineCustomBindings) {\r\n const newUniforms = uniforms?.slice() ?? [];\r\n newUniforms.push(...this._parameters);\r\n\r\n const newSamplers = samplers?.slice() ?? [];\r\n newSamplers.push(...this._samplers);\r\n\r\n defines = customShaderCodeProcessing.defineCustomBindings(this.name, defines, newUniforms, newSamplers);\r\n uniforms = newUniforms;\r\n samplers = newSamplers;\r\n }\r\n this._postProcessDefines = defines;\r\n this._drawWrapper.effect = this._engine.createEffect(\r\n { vertex: vertexUrl ?? this._vertexUrl, fragment: fragmentUrl ?? this._fragmentUrl },\r\n {\r\n attributes: [\"position\"],\r\n uniformsNames: uniforms || this._parameters,\r\n uniformBuffersNames: [],\r\n samplers: samplers || this._samplers,\r\n defines: defines !== null ? defines : \"\",\r\n fallbacks: null,\r\n onCompiled: onCompiled ?? null,\r\n onError: onError ?? null,\r\n indexParameters: indexParameters || this._indexParameters,\r\n processCodeAfterIncludes: customShaderCodeProcessing?.processCodeAfterIncludes\r\n ? (shaderType: string, code: string) => customShaderCodeProcessing!.processCodeAfterIncludes!(this.name, shaderType, code)\r\n : null,\r\n processFinalCode: customShaderCodeProcessing?.processFinalCode\r\n ? (shaderType: string, code: string) => customShaderCodeProcessing!.processFinalCode!(this.name, shaderType, code)\r\n : null,\r\n shaderLanguage: this._shaderLanguage,\r\n },\r\n this._engine\r\n );\r\n }\r\n\r\n /**\r\n * The post process is reusable if it can be used multiple times within one frame.\r\n * @returns If the post process is reusable\r\n */\r\n public isReusable(): boolean {\r\n return this._reusable;\r\n }\r\n\r\n /** invalidate frameBuffer to hint the postprocess to create a depth buffer */\r\n public markTextureDirty(): void {\r\n this.width = -1;\r\n }\r\n\r\n private _createRenderTargetTexture(textureSize: { width: number; height: number }, textureOptions: RenderTargetCreationOptions, channel = 0) {\r\n for (let i = 0; i < this._textureCache.length; i++) {\r\n if (\r\n this._textureCache[i].texture.width === textureSize.width &&\r\n this._textureCache[i].texture.height === textureSize.height &&\r\n this._textureCache[i].postProcessChannel === channel &&\r\n this._textureCache[i].texture._generateDepthBuffer === textureOptions.generateDepthBuffer &&\r\n this._textureCache[i].texture.samples === textureOptions.samples\r\n ) {\r\n return this._textureCache[i].texture;\r\n }\r\n }\r\n\r\n const tex = this._engine.createRenderTargetTexture(textureSize, textureOptions);\r\n this._textureCache.push({ texture: tex, postProcessChannel: channel, lastUsedRenderId: -1 });\r\n\r\n return tex;\r\n }\r\n\r\n private _flushTextureCache() {\r\n const currentRenderId = this._renderId;\r\n\r\n for (let i = this._textureCache.length - 1; i >= 0; i--) {\r\n if (currentRenderId - this._textureCache[i].lastUsedRenderId > 100) {\r\n let currentlyUsed = false;\r\n for (let j = 0; j < this._textures.length; j++) {\r\n if (this._textures.data[j] === this._textureCache[i].texture) {\r\n currentlyUsed = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!currentlyUsed) {\r\n this._textureCache[i].texture.dispose();\r\n this._textureCache.splice(i, 1);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _resize(width: number, height: number, camera: Camera, needMipMaps: boolean, forceDepthStencil?: boolean) {\r\n if (this._textures.length > 0) {\r\n this._textures.reset();\r\n }\r\n\r\n this.width = width;\r\n this.height = height;\r\n\r\n let firstPP = null;\r\n for (let i = 0; i < camera._postProcesses.length; i++) {\r\n if (camera._postProcesses[i] !== null) {\r\n firstPP = camera._postProcesses[i];\r\n break;\r\n }\r\n }\r\n\r\n const textureSize = { width: this.width, height: this.height };\r\n const textureOptions = {\r\n generateMipMaps: needMipMaps,\r\n generateDepthBuffer: forceDepthStencil || firstPP === this,\r\n generateStencilBuffer: (forceDepthStencil || firstPP === this) && this._engine.isStencilEnable,\r\n samplingMode: this.renderTargetSamplingMode,\r\n type: this._textureType,\r\n format: this._textureFormat,\r\n samples: this._samples,\r\n label: \"PostProcessRTT-\" + this.name,\r\n };\r\n\r\n this._textures.push(this._createRenderTargetTexture(textureSize, textureOptions, 0));\r\n\r\n if (this._reusable) {\r\n this._textures.push(this._createRenderTargetTexture(textureSize, textureOptions, 1));\r\n }\r\n\r\n this._texelSize.copyFromFloats(1.0 / this.width, 1.0 / this.height);\r\n\r\n this.onSizeChangedObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Activates the post process by intializing the textures to be used when executed. Notifies onActivateObservable.\r\n * When this post process is used in a pipeline, this is call will bind the input texture of this post process to the output of the previous.\r\n * @param camera The camera that will be used in the post process. This camera will be used when calling onActivateObservable.\r\n * @param sourceTexture The source texture to be inspected to get the width and height if not specified in the post process constructor. (default: null)\r\n * @param forceDepthStencil If true, a depth and stencil buffer will be generated. (default: false)\r\n * @returns The render target wrapper that was bound to be written to.\r\n */\r\n public activate(camera: Nullable, sourceTexture: Nullable = null, forceDepthStencil?: boolean): RenderTargetWrapper {\r\n camera = camera || this._camera;\r\n\r\n const scene = camera.getScene();\r\n const engine = scene.getEngine();\r\n const maxSize = engine.getCaps().maxTextureSize;\r\n\r\n let requiredWidth = ((sourceTexture ? sourceTexture.width : this._engine.getRenderWidth(true)) * this._options) | 0;\r\n const requiredHeight = ((sourceTexture ? sourceTexture.height : this._engine.getRenderHeight(true)) * this._options) | 0;\r\n\r\n // If rendering to a webvr camera's left or right eye only half the width should be used to avoid resize when rendered to screen\r\n const webVRCamera = camera.parent;\r\n if (webVRCamera && (webVRCamera.leftCamera == camera || webVRCamera.rightCamera == camera)) {\r\n requiredWidth /= 2;\r\n }\r\n\r\n let desiredWidth = (this._options).width || requiredWidth;\r\n let desiredHeight = (this._options).height || requiredHeight;\r\n\r\n const needMipMaps =\r\n this.renderTargetSamplingMode !== Constants.TEXTURE_NEAREST_LINEAR &&\r\n this.renderTargetSamplingMode !== Constants.TEXTURE_NEAREST_NEAREST &&\r\n this.renderTargetSamplingMode !== Constants.TEXTURE_LINEAR_LINEAR;\r\n\r\n if (!this._shareOutputWithPostProcess && !this._forcedOutputTexture) {\r\n if (this.adaptScaleToCurrentViewport) {\r\n const currentViewport = engine.currentViewport;\r\n\r\n if (currentViewport) {\r\n desiredWidth *= currentViewport.width;\r\n desiredHeight *= currentViewport.height;\r\n }\r\n }\r\n\r\n if (needMipMaps || this.alwaysForcePOT) {\r\n if (!(this._options).width) {\r\n desiredWidth = engine.needPOTTextures ? Engine.GetExponentOfTwo(desiredWidth, maxSize, this.scaleMode) : desiredWidth;\r\n }\r\n\r\n if (!(this._options).height) {\r\n desiredHeight = engine.needPOTTextures ? Engine.GetExponentOfTwo(desiredHeight, maxSize, this.scaleMode) : desiredHeight;\r\n }\r\n }\r\n\r\n if (this.width !== desiredWidth || this.height !== desiredHeight) {\r\n this._resize(desiredWidth, desiredHeight, camera, needMipMaps, forceDepthStencil);\r\n }\r\n\r\n this._textures.forEach((texture) => {\r\n if (texture.samples !== this.samples) {\r\n this._engine.updateRenderTargetTextureSampleCount(texture, this.samples);\r\n }\r\n });\r\n\r\n this._flushTextureCache();\r\n this._renderId++;\r\n }\r\n\r\n let target: RenderTargetWrapper;\r\n\r\n if (this._shareOutputWithPostProcess) {\r\n target = this._shareOutputWithPostProcess.inputTexture;\r\n } else if (this._forcedOutputTexture) {\r\n target = this._forcedOutputTexture;\r\n\r\n this.width = this._forcedOutputTexture.width;\r\n this.height = this._forcedOutputTexture.height;\r\n } else {\r\n target = this.inputTexture;\r\n\r\n let cache;\r\n for (let i = 0; i < this._textureCache.length; i++) {\r\n if (this._textureCache[i].texture === target) {\r\n cache = this._textureCache[i];\r\n break;\r\n }\r\n }\r\n\r\n if (cache) {\r\n cache.lastUsedRenderId = this._renderId;\r\n }\r\n }\r\n\r\n // Bind the input of this post process to be used as the output of the previous post process.\r\n if (this.enablePixelPerfectMode) {\r\n this._scaleRatio.copyFromFloats(requiredWidth / desiredWidth, requiredHeight / desiredHeight);\r\n this._engine.bindFramebuffer(target, 0, requiredWidth, requiredHeight, this.forceFullscreenViewport);\r\n } else {\r\n this._scaleRatio.copyFromFloats(1, 1);\r\n this._engine.bindFramebuffer(target, 0, undefined, undefined, this.forceFullscreenViewport);\r\n }\r\n\r\n this._engine._debugInsertMarker?.(`post process ${this.name} input`);\r\n\r\n this.onActivateObservable.notifyObservers(camera);\r\n\r\n // Clear\r\n if (this.autoClear && (this.alphaMode === Constants.ALPHA_DISABLE || this.forceAutoClearInAlphaMode)) {\r\n this._engine.clear(this.clearColor ? this.clearColor : scene.clearColor, scene._allowPostProcessClearColor, true, true);\r\n }\r\n\r\n if (this._reusable) {\r\n this._currentRenderTextureInd = (this._currentRenderTextureInd + 1) % 2;\r\n }\r\n return target;\r\n }\r\n\r\n /**\r\n * If the post process is supported.\r\n */\r\n public get isSupported(): boolean {\r\n return this._drawWrapper.effect!.isSupported;\r\n }\r\n\r\n /**\r\n * The aspect ratio of the output texture.\r\n */\r\n public get aspectRatio(): number {\r\n if (this._shareOutputWithPostProcess) {\r\n return this._shareOutputWithPostProcess.aspectRatio;\r\n }\r\n\r\n if (this._forcedOutputTexture) {\r\n return this._forcedOutputTexture.width / this._forcedOutputTexture.height;\r\n }\r\n return this.width / this.height;\r\n }\r\n\r\n /**\r\n * Get a value indicating if the post-process is ready to be used\r\n * @returns true if the post-process is ready (shader is compiled)\r\n */\r\n public isReady(): boolean {\r\n return this._drawWrapper.effect?.isReady() ?? false;\r\n }\r\n\r\n /**\r\n * Binds all textures and uniforms to the shader, this will be run on every pass.\r\n * @returns the effect corresponding to this post process. Null if not compiled or not ready.\r\n */\r\n public apply(): Nullable {\r\n // Check\r\n if (!this._drawWrapper.effect?.isReady()) {\r\n return null;\r\n }\r\n\r\n // States\r\n this._engine.enableEffect(this._drawWrapper);\r\n this._engine.setState(false);\r\n this._engine.setDepthBuffer(false);\r\n this._engine.setDepthWrite(false);\r\n\r\n // Alpha\r\n this._engine.setAlphaMode(this.alphaMode);\r\n if (this.alphaConstants) {\r\n this.getEngine().setAlphaConstants(this.alphaConstants.r, this.alphaConstants.g, this.alphaConstants.b, this.alphaConstants.a);\r\n }\r\n\r\n // Bind the output texture of the preivous post process as the input to this post process.\r\n let source: RenderTargetWrapper;\r\n if (this._shareOutputWithPostProcess) {\r\n source = this._shareOutputWithPostProcess.inputTexture;\r\n } else if (this._forcedOutputTexture) {\r\n source = this._forcedOutputTexture;\r\n } else {\r\n source = this.inputTexture;\r\n }\r\n\r\n if (!this.externalTextureSamplerBinding) {\r\n this._drawWrapper.effect._bindTexture(\"textureSampler\", source?.texture);\r\n }\r\n\r\n // Parameters\r\n this._drawWrapper.effect.setVector2(\"scale\", this._scaleRatio);\r\n this.onApplyObservable.notifyObservers(this._drawWrapper.effect);\r\n\r\n PostProcess._GetShaderCodeProcessing(this.name)?.bindCustomBindings?.(this.name, this._drawWrapper.effect);\r\n\r\n return this._drawWrapper.effect;\r\n }\r\n\r\n private _disposeTextures() {\r\n if (this._shareOutputWithPostProcess || this._forcedOutputTexture) {\r\n this._disposeTextureCache();\r\n return;\r\n }\r\n\r\n this._disposeTextureCache();\r\n this._textures.dispose();\r\n }\r\n\r\n private _disposeTextureCache() {\r\n for (let i = this._textureCache.length - 1; i >= 0; i--) {\r\n this._textureCache[i].texture.dispose();\r\n }\r\n\r\n this._textureCache.length = 0;\r\n }\r\n\r\n /**\r\n * Sets the required values to the prepass renderer.\r\n * @param prePassRenderer defines the prepass renderer to setup.\r\n * @returns true if the pre pass is needed.\r\n */\r\n public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {\r\n if (this._prePassEffectConfiguration) {\r\n this._prePassEffectConfiguration = prePassRenderer.addEffectConfiguration(this._prePassEffectConfiguration);\r\n this._prePassEffectConfiguration.enabled = true;\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Disposes the post process.\r\n * @param camera The camera to dispose the post process on.\r\n */\r\n public dispose(camera?: Camera): void {\r\n camera = camera || this._camera;\r\n\r\n this._disposeTextures();\r\n\r\n let index;\r\n if (this._scene) {\r\n index = this._scene.postProcesses.indexOf(this);\r\n if (index !== -1) {\r\n this._scene.postProcesses.splice(index, 1);\r\n }\r\n }\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.postProcesses.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.postProcesses.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n index = this._engine.postProcesses.indexOf(this);\r\n if (index !== -1) {\r\n this._engine.postProcesses.splice(index, 1);\r\n }\r\n\r\n if (!camera) {\r\n return;\r\n }\r\n camera.detachPostProcess(this);\r\n\r\n index = camera._postProcesses.indexOf(this);\r\n if (index === 0 && camera._postProcesses.length > 0) {\r\n const firstPostProcess = this._camera._getFirstPostProcess();\r\n if (firstPostProcess) {\r\n firstPostProcess.markTextureDirty();\r\n }\r\n }\r\n\r\n this.onActivateObservable.clear();\r\n this.onAfterRenderObservable.clear();\r\n this.onApplyObservable.clear();\r\n this.onBeforeRenderObservable.clear();\r\n this.onSizeChangedObservable.clear();\r\n }\r\n\r\n /**\r\n * Serializes the post process to a JSON object\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n const camera = this.getCamera() || (this._scene && this._scene.activeCamera);\r\n serializationObject.customType = \"BABYLON.\" + this.getClassName();\r\n serializationObject.cameraId = camera ? camera.id : null;\r\n serializationObject.reusable = this._reusable;\r\n serializationObject.textureType = this._textureType;\r\n serializationObject.fragmentUrl = this._fragmentUrl;\r\n serializationObject.parameters = this._parameters;\r\n serializationObject.samplers = this._samplers;\r\n serializationObject.options = this._options;\r\n serializationObject.defines = this._postProcessDefines;\r\n serializationObject.textureFormat = this._textureFormat;\r\n serializationObject.vertexUrl = this._vertexUrl;\r\n serializationObject.indexParameters = this._indexParameters;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Clones this post process\r\n * @returns a new post process similar to this one\r\n */\r\n public clone(): Nullable {\r\n const serializationObject = this.serialize();\r\n serializationObject._engine = this._engine;\r\n serializationObject.cameraId = null;\r\n\r\n const result = PostProcess.Parse(serializationObject, this._scene, \"\");\r\n\r\n if (!result) {\r\n return null;\r\n }\r\n\r\n result.onActivateObservable = this.onActivateObservable.clone();\r\n result.onSizeChangedObservable = this.onSizeChangedObservable.clone();\r\n result.onApplyObservable = this.onApplyObservable.clone();\r\n result.onBeforeRenderObservable = this.onBeforeRenderObservable.clone();\r\n result.onAfterRenderObservable = this.onAfterRenderObservable.clone();\r\n\r\n result._prePassEffectConfiguration = this._prePassEffectConfiguration;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a material from parsed material data\r\n * @param parsedPostProcess defines parsed post process data\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures\r\n * @returns a new post process\r\n */\r\n public static Parse(parsedPostProcess: any, scene: Scene, rootUrl: string): Nullable {\r\n const postProcessType = GetClass(parsedPostProcess.customType);\r\n\r\n if (!postProcessType || !postProcessType._Parse) {\r\n return null;\r\n }\r\n\r\n const camera = scene ? scene.getCameraById(parsedPostProcess.cameraId) : null;\r\n return postProcessType._Parse(parsedPostProcess, camera, scene, rootUrl);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): Nullable {\r\n return SerializationHelper.Parse(\r\n () => {\r\n return new PostProcess(\r\n parsedPostProcess.name,\r\n parsedPostProcess.fragmentUrl,\r\n parsedPostProcess.parameters,\r\n parsedPostProcess.samplers,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n parsedPostProcess._engine,\r\n parsedPostProcess.reusable,\r\n parsedPostProcess.defines,\r\n parsedPostProcess.textureType,\r\n parsedPostProcess.vertexUrl,\r\n parsedPostProcess.indexParameters,\r\n false,\r\n parsedPostProcess.textureFormat\r\n );\r\n },\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PostProcess\", PostProcess);\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/helperFunctions\";\n\nconst name = \"rgbdDecodePixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{gl_FragColor=vec4(fromRGBD(texture2D(textureSampler,vUV)),1.0);}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const rgbdDecodePixelShader = { name, shader };\n","import { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { Constants } from \"../constants\";\r\nimport { ThinEngine } from \"../thinEngine\";\r\nimport type { RenderTargetWrapper } from \"../renderTargetWrapper\";\r\nimport type { WebGLRenderTargetWrapper } from \"../WebGL/webGLRenderTargetWrapper\";\r\nimport type { RenderTargetCreationOptions } from \"../../Materials/Textures/textureCreationOptions\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a new render target cube wrapper\r\n * @param size defines the size of the texture\r\n * @param options defines the options used to create the texture\r\n * @returns a new render target cube wrapper\r\n */\r\n createRenderTargetCubeTexture(size: number, options?: RenderTargetCreationOptions): RenderTargetWrapper;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createRenderTargetCubeTexture = function (size: number, options?: RenderTargetCreationOptions): RenderTargetWrapper {\r\n const rtWrapper = this._createHardwareRenderTargetWrapper(false, true, size) as WebGLRenderTargetWrapper;\r\n\r\n const fullOptions = {\r\n generateMipMaps: true,\r\n generateDepthBuffer: true,\r\n generateStencilBuffer: false,\r\n type: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n samplingMode: Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n ...options,\r\n };\r\n fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;\r\n\r\n if (fullOptions.type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {\r\n // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE\r\n fullOptions.samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n } else if (fullOptions.type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {\r\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\r\n fullOptions.samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n const gl = this._gl;\r\n\r\n const texture = new InternalTexture(this, InternalTextureSource.RenderTarget);\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\r\n\r\n const filters = this._getSamplingParameters(fullOptions.samplingMode, fullOptions.generateMipMaps);\r\n\r\n if (fullOptions.type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {\r\n fullOptions.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n Logger.Warn(\"Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type\");\r\n }\r\n\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n\r\n for (let face = 0; face < 6; face++) {\r\n gl.texImage2D(\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_X + face,\r\n 0,\r\n this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format),\r\n size,\r\n size,\r\n 0,\r\n this._getInternalFormat(fullOptions.format),\r\n this._getWebGLTextureType(fullOptions.type),\r\n null\r\n );\r\n }\r\n\r\n // Create the framebuffer\r\n const framebuffer = gl.createFramebuffer();\r\n this._bindUnboundFramebuffer(framebuffer);\r\n\r\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(fullOptions.generateStencilBuffer, fullOptions.generateDepthBuffer, size, size);\r\n\r\n // MipMaps\r\n if (fullOptions.generateMipMaps) {\r\n gl.generateMipmap(gl.TEXTURE_CUBE_MAP);\r\n }\r\n\r\n // Unbind\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n this._bindUnboundFramebuffer(null);\r\n\r\n rtWrapper._framebuffer = framebuffer;\r\n rtWrapper._generateDepthBuffer = fullOptions.generateDepthBuffer;\r\n rtWrapper._generateStencilBuffer = fullOptions.generateStencilBuffer;\r\n\r\n texture.width = size;\r\n texture.height = size;\r\n texture.isReady = true;\r\n texture.isCube = true;\r\n texture.samples = 1;\r\n texture.generateMipMaps = fullOptions.generateMipMaps;\r\n texture.samplingMode = fullOptions.samplingMode;\r\n texture.type = fullOptions.type;\r\n texture.format = fullOptions.format;\r\n\r\n this._internalTexturesCache.push(texture);\r\n rtWrapper.setTextures(texture);\r\n\r\n return rtWrapper;\r\n};\r\n","import type { Nullable } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Effect } from \"./effect\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n// Prevents ES6 Crash if not imported.\r\nimport \"../Shaders/postprocess.vertex\";\r\n\r\n/**\r\n * Effect Render Options\r\n */\r\nexport interface IEffectRendererOptions {\r\n /**\r\n * Defines the vertices positions.\r\n */\r\n positions?: number[];\r\n /**\r\n * Defines the indices.\r\n */\r\n indices?: number[];\r\n}\r\n\r\n// Fullscreen quad buffers by default.\r\nconst defaultOptions = {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 1, 2, 0, 2, 3],\r\n};\r\n\r\n/**\r\n * Helper class to render one or more effects.\r\n * You can access the previous rendering in your shader by declaring a sampler named textureSampler\r\n */\r\nexport class EffectRenderer {\r\n /**\r\n * The engine the effect renderer has been created for.\r\n */\r\n public readonly engine: ThinEngine;\r\n\r\n private _vertexBuffers: { [key: string]: VertexBuffer };\r\n private _indexBuffer: DataBuffer;\r\n\r\n private _fullscreenViewport = new Viewport(0, 0, 1, 1);\r\n private _onContextRestoredObserver: Nullable>;\r\n\r\n private _savedStateDepthTest: boolean;\r\n private _savedStateStencilTest: boolean;\r\n\r\n /**\r\n * Creates an effect renderer\r\n * @param engine the engine to use for rendering\r\n * @param options defines the options of the effect renderer\r\n */\r\n constructor(engine: ThinEngine, options: IEffectRendererOptions = defaultOptions) {\r\n const positions = options.positions ?? defaultOptions.positions;\r\n const indices = options.indices ?? defaultOptions.indices;\r\n\r\n this.engine = engine;\r\n this._vertexBuffers = {\r\n [VertexBuffer.PositionKind]: new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false, false, 2),\r\n };\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n this._onContextRestoredObserver = engine.onContextRestoredObservable.add(() => {\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n\r\n for (const key in this._vertexBuffers) {\r\n const vertexBuffer = this._vertexBuffers[key];\r\n vertexBuffer._rebuild();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Sets the current viewport in normalized coordinates 0-1\r\n * @param viewport Defines the viewport to set (defaults to 0 0 1 1)\r\n */\r\n public setViewport(viewport = this._fullscreenViewport): void {\r\n this.engine.setViewport(viewport);\r\n }\r\n\r\n /**\r\n * Binds the embedded attributes buffer to the effect.\r\n * @param effect Defines the effect to bind the attributes for\r\n */\r\n public bindBuffers(effect: Effect): void {\r\n this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n /**\r\n * Sets the current effect wrapper to use during draw.\r\n * The effect needs to be ready before calling this api.\r\n * This also sets the default full screen position attribute.\r\n * @param effectWrapper Defines the effect to draw with\r\n */\r\n public applyEffectWrapper(effectWrapper: EffectWrapper): void {\r\n this.engine.setState(true);\r\n this.engine.depthCullingState.depthTest = false;\r\n this.engine.stencilState.stencilTest = false;\r\n this.engine.enableEffect(effectWrapper._drawWrapper);\r\n this.bindBuffers(effectWrapper.effect);\r\n effectWrapper.onApplyObservable.notifyObservers({});\r\n }\r\n\r\n /**\r\n * Saves engine states\r\n */\r\n public saveStates(): void {\r\n this._savedStateDepthTest = this.engine.depthCullingState.depthTest;\r\n this._savedStateStencilTest = this.engine.stencilState.stencilTest;\r\n }\r\n\r\n /**\r\n * Restores engine states\r\n */\r\n public restoreStates(): void {\r\n this.engine.depthCullingState.depthTest = this._savedStateDepthTest;\r\n this.engine.stencilState.stencilTest = this._savedStateStencilTest;\r\n }\r\n\r\n /**\r\n * Draws a full screen quad.\r\n */\r\n public draw(): void {\r\n this.engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, 6);\r\n }\r\n\r\n private _isRenderTargetTexture(texture: RenderTargetWrapper | IRenderTargetTexture): texture is IRenderTargetTexture {\r\n return (texture as IRenderTargetTexture).renderTarget !== undefined;\r\n }\r\n\r\n /**\r\n * renders one or more effects to a specified texture\r\n * @param effectWrapper the effect to renderer\r\n * @param outputTexture texture to draw to, if null it will render to the screen.\r\n */\r\n public render(effectWrapper: EffectWrapper, outputTexture: Nullable = null) {\r\n // Ensure effect is ready\r\n if (!effectWrapper.effect.isReady()) {\r\n return;\r\n }\r\n\r\n this.saveStates();\r\n\r\n // Reset state\r\n this.setViewport();\r\n\r\n const out = outputTexture === null ? null : this._isRenderTargetTexture(outputTexture) ? outputTexture.renderTarget! : outputTexture;\r\n\r\n if (out) {\r\n this.engine.bindFramebuffer(out);\r\n }\r\n\r\n this.applyEffectWrapper(effectWrapper);\r\n\r\n this.draw();\r\n\r\n if (out) {\r\n this.engine.unBindFramebuffer(out);\r\n }\r\n\r\n this.restoreStates();\r\n }\r\n\r\n /**\r\n * Disposes of the effect renderer\r\n */\r\n dispose() {\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n delete this._vertexBuffers[VertexBuffer.PositionKind];\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this.engine._releaseBuffer(this._indexBuffer);\r\n }\r\n\r\n if (this._onContextRestoredObserver) {\r\n this.engine.onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to create an EffectWrapper\r\n */\r\ninterface EffectWrapperCreationOptions {\r\n /**\r\n * Engine to use to create the effect\r\n */\r\n engine: ThinEngine;\r\n /**\r\n * Fragment shader for the effect\r\n */\r\n fragmentShader: string;\r\n /**\r\n * Use the shader store instead of direct source code\r\n */\r\n useShaderStore?: boolean;\r\n /**\r\n * Vertex shader for the effect\r\n */\r\n vertexShader?: string;\r\n /**\r\n * Attributes to use in the shader\r\n */\r\n attributeNames?: Array;\r\n /**\r\n * Uniforms to use in the shader\r\n */\r\n uniformNames?: Array;\r\n /**\r\n * Texture sampler names to use in the shader\r\n */\r\n samplerNames?: Array;\r\n /**\r\n * Defines to use in the shader\r\n */\r\n defines?: Array;\r\n /**\r\n * Callback when effect is compiled\r\n */\r\n onCompiled?: Nullable<(effect: Effect) => void>;\r\n /**\r\n * The friendly name of the effect displayed in Spector.\r\n */\r\n name?: string;\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n}\r\n\r\n/**\r\n * Wraps an effect to be used for rendering\r\n */\r\nexport class EffectWrapper {\r\n /**\r\n * Event that is fired right before the effect is drawn (should be used to update uniforms)\r\n */\r\n public onApplyObservable = new Observable<{}>();\r\n /**\r\n * The underlying effect\r\n */\r\n public get effect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n public set effect(effect: Effect) {\r\n this._drawWrapper.effect = effect;\r\n }\r\n\r\n /** @internal */\r\n public _drawWrapper: DrawWrapper;\r\n\r\n private _onContextRestoredObserver: Nullable>;\r\n\r\n /**\r\n * Creates an effect to be renderer\r\n * @param creationOptions options to create the effect\r\n */\r\n constructor(creationOptions: EffectWrapperCreationOptions) {\r\n let effectCreationOptions: any;\r\n const uniformNames = creationOptions.uniformNames || [];\r\n\r\n if (creationOptions.vertexShader) {\r\n effectCreationOptions = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertexSource: creationOptions.vertexShader,\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n } else {\r\n // Default scale to use in post process vertex shader.\r\n uniformNames.push(\"scale\");\r\n\r\n effectCreationOptions = {\r\n fragmentSource: creationOptions.fragmentShader,\r\n vertex: \"postprocess\",\r\n spectorName: creationOptions.name || \"effectWrapper\",\r\n };\r\n\r\n // Sets the default scale to identity for the post process vertex shader.\r\n this.onApplyObservable.add(() => {\r\n this.effect.setFloat2(\"scale\", 1, 1);\r\n });\r\n }\r\n\r\n const defines = creationOptions.defines ? creationOptions.defines.join(\"\\n\") : \"\";\r\n this._drawWrapper = new DrawWrapper(creationOptions.engine);\r\n\r\n if (creationOptions.useShaderStore) {\r\n effectCreationOptions.fragment = effectCreationOptions.fragmentSource;\r\n if (!effectCreationOptions.vertex) {\r\n effectCreationOptions.vertex = effectCreationOptions.vertexSource;\r\n }\r\n\r\n delete effectCreationOptions.fragmentSource;\r\n delete effectCreationOptions.vertexSource;\r\n\r\n this.effect = creationOptions.engine.createEffect(\r\n effectCreationOptions,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage\r\n );\r\n } else {\r\n this.effect = new Effect(\r\n effectCreationOptions,\r\n creationOptions.attributeNames || [\"position\"],\r\n uniformNames,\r\n creationOptions.samplerNames,\r\n creationOptions.engine,\r\n defines,\r\n undefined,\r\n creationOptions.onCompiled,\r\n undefined,\r\n undefined,\r\n undefined,\r\n creationOptions.shaderLanguage\r\n );\r\n\r\n this._onContextRestoredObserver = creationOptions.engine.onContextRestoredObservable.add(() => {\r\n this.effect._pipelineContext = null; // because _prepareEffect will try to dispose this pipeline before recreating it and that would lead to webgl errors\r\n this.effect._wasPreviouslyReady = false;\r\n this.effect._prepareEffect();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the effect wrapper\r\n */\r\n public dispose() {\r\n if (this._onContextRestoredObserver) {\r\n this.effect.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n this.effect.dispose();\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"passPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{gl_FragColor=texture2D(textureSampler,vUV);}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const passPixelShader = { name, shader };\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { _WarnImport } from \"./devTools\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\nimport { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\n\r\nimport { passPixelShader } from \"../Shaders/pass.fragment\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\n\r\ntype DumpToolsEngine = {\r\n canvas: HTMLCanvasElement | OffscreenCanvas;\r\n engine: ThinEngine;\r\n renderer: EffectRenderer;\r\n wrapper: EffectWrapper;\r\n};\r\n\r\n/**\r\n * Class containing a set of static utilities functions to dump data from a canvas\r\n */\r\nexport class DumpTools {\r\n private static _DumpToolsEngine: Nullable;\r\n\r\n private static _CreateDumpRenderer(): DumpToolsEngine {\r\n if (!DumpTools._DumpToolsEngine) {\r\n let canvas: HTMLCanvasElement | OffscreenCanvas = new OffscreenCanvas(100, 100); // will be resized later\r\n let engine: Nullable = null;\r\n const options = {\r\n preserveDrawingBuffer: true,\r\n depth: false,\r\n stencil: false,\r\n alpha: true,\r\n premultipliedAlpha: false,\r\n antialias: false,\r\n failIfMajorPerformanceCaveat: false,\r\n };\r\n try {\r\n engine = new ThinEngine(canvas, false, options);\r\n } catch (e) {\r\n // The browser does not support WebGL context in OffscreenCanvas, fallback on a regular canvas\r\n canvas = document.createElement(\"canvas\");\r\n engine = new ThinEngine(canvas, false, options);\r\n }\r\n engine.getCaps().parallelShaderCompile = undefined;\r\n const renderer = new EffectRenderer(engine);\r\n const wrapper = new EffectWrapper({\r\n engine,\r\n name: passPixelShader.name,\r\n fragmentShader: passPixelShader.shader,\r\n samplerNames: [\"textureSampler\"],\r\n });\r\n DumpTools._DumpToolsEngine = {\r\n canvas,\r\n engine,\r\n renderer,\r\n wrapper,\r\n };\r\n }\r\n return DumpTools._DumpToolsEngine!;\r\n }\r\n\r\n /**\r\n * Dumps the current bound framebuffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param engine defines the hosting engine\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a void promise\r\n */\r\n public static async DumpFramebuffer(\r\n width: number,\r\n height: number,\r\n engine: Engine,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n ) {\r\n // Read the contents of the framebuffer\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n\r\n const data = new Uint8Array(bufferView.buffer);\r\n\r\n DumpTools.DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n }\r\n\r\n /**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a promise that resolve to the final data\r\n */\r\n public static DumpDataAsync(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n ): Promise {\r\n return new Promise((resolve) => {\r\n DumpTools.DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);\r\n });\r\n }\r\n\r\n /**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n public static DumpData(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n successCallback?: (data: string | ArrayBuffer) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n ) {\r\n const renderer = DumpTools._CreateDumpRenderer();\r\n renderer.engine.setSize(width, height, true);\r\n\r\n // Convert if data are float32\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Scalar.Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n // Create the image\r\n const texture = renderer.engine.createRawTexture(data, width, height, Constants.TEXTUREFORMAT_RGBA, false, !invertY, Constants.TEXTURE_NEAREST_NEAREST);\r\n\r\n renderer.renderer.setViewport();\r\n renderer.renderer.applyEffectWrapper(renderer.wrapper);\r\n renderer.wrapper.effect._bindTexture(\"textureSampler\", texture);\r\n renderer.renderer.draw();\r\n\r\n if (toArrayBuffer) {\r\n Tools.ToBlob(\r\n renderer.canvas,\r\n (blob) => {\r\n const fileReader = new FileReader();\r\n fileReader.onload = (event: any) => {\r\n const arrayBuffer = event.target!.result as ArrayBuffer;\r\n if (successCallback) {\r\n successCallback(arrayBuffer);\r\n }\r\n };\r\n fileReader.readAsArrayBuffer(blob!);\r\n },\r\n mimeType,\r\n quality\r\n );\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);\r\n }\r\n\r\n texture.dispose();\r\n }\r\n\r\n /**\r\n * Dispose the dump tools associated resources\r\n */\r\n public static Dispose() {\r\n if (DumpTools._DumpToolsEngine) {\r\n DumpTools._DumpToolsEngine.wrapper.dispose();\r\n DumpTools._DumpToolsEngine.renderer.dispose();\r\n DumpTools._DumpToolsEngine.engine.dispose();\r\n }\r\n DumpTools._DumpToolsEngine = null;\r\n }\r\n}\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.DumpData = DumpTools.DumpData;\r\n Tools.DumpDataAsync = DumpTools.DumpDataAsync;\r\n Tools.DumpFramebuffer = DumpTools.DumpFramebuffer;\r\n};\r\n\r\ninitSideEffects();\r\n","import type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { SmartArray } from \"../../Misc/smartArray\";\r\nimport type { Nullable, Immutable } from \"../../types\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Color4 } from \"../../Maths/math.color\";\r\nimport type { RenderTargetCreationOptions, TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { PostProcessManager } from \"../../PostProcesses/postProcessManager\";\r\nimport type { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport { RenderingManager } from \"../../Rendering/renderingManager\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../../Engines/renderTargetWrapper\";\r\n\r\nimport \"../../Engines/Extensions/engine.renderTarget\";\r\nimport \"../../Engines/Extensions/engine.renderTargetCube\";\r\nimport { Engine } from \"../../Engines/engine\";\r\nimport { _ObserveArray } from \"../../Misc/arrayTools\";\r\nimport { DumpTools } from \"../../Misc/dumpTools\";\r\n\r\nimport type { Material } from \"../material\";\r\n\r\n/**\r\n * Options for the RenderTargetTexture constructor\r\n */\r\nexport interface RenderTargetTextureOptions {\r\n /** True (default: false) if mipmaps need to be generated after render */\r\n generateMipMaps?: boolean;\r\n\r\n /** True (default) to not change the aspect ratio of the scene in the RTT */\r\n doNotChangeAspectRatio?: boolean;\r\n\r\n /** The type of the buffer in the RTT (byte (default), half float, float...) */\r\n type?: number;\r\n\r\n /** True (default: false) if a cube texture needs to be created */\r\n isCube?: boolean;\r\n\r\n /** The sampling mode to be used with the render target (Trilinear (default), Linear, Nearest...) */\r\n samplingMode?: number;\r\n\r\n /** True (default) to generate a depth buffer */\r\n generateDepthBuffer?: boolean;\r\n\r\n /** True (default: false) to generate a stencil buffer */\r\n generateStencilBuffer?: boolean;\r\n\r\n /** True (default: false) if multiple textures need to be created (Draw Buffers) */\r\n isMulti?: boolean;\r\n\r\n /** The internal format of the buffer in the RTT (RED, RG, RGB, RGBA (default), ALPHA...) */\r\n format?: number;\r\n\r\n /** True (default: false) if the texture allocation should be delayed */\r\n delayAllocation?: boolean;\r\n\r\n /** Sample count to use when creating the RTT */\r\n samples?: number;\r\n\r\n /** specific flags to use when creating the texture (e.g., Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures) */\r\n creationFlags?: number;\r\n\r\n /** True (default: false) to indicate that no color target should be created. (e.g., if you only want to write to the depth buffer) */\r\n noColorAttachment?: boolean;\r\n\r\n /** Specifies the internal texture to use directly instead of creating one (ignores `noColorAttachment` flag when set) **/\r\n colorAttachment?: InternalTexture;\r\n\r\n /** True (default: false) to create a SRGB texture */\r\n useSRGBBuffer?: boolean;\r\n}\r\n\r\n/**\r\n * This Helps creating a texture that will be created from a camera in your scene.\r\n * It is basically a dynamic texture that could be used to create special effects for instance.\r\n * Actually, It is the base of lot of effects in the framework like post process, shadows, effect layers and rendering pipelines...\r\n */\r\nexport class RenderTargetTexture extends Texture implements IRenderTargetTexture {\r\n /**\r\n * The texture will only be rendered once which can be useful to improve performance if everything in your render is static for instance.\r\n */\r\n public static readonly REFRESHRATE_RENDER_ONCE: number = 0;\r\n /**\r\n * The texture will only be rendered rendered every frame and is recommended for dynamic contents.\r\n */\r\n public static readonly REFRESHRATE_RENDER_ONEVERYFRAME: number = 1;\r\n /**\r\n * The texture will be rendered every 2 frames which could be enough if your dynamic objects are not\r\n * the central point of your effect and can save a lot of performances.\r\n */\r\n public static readonly REFRESHRATE_RENDER_ONEVERYTWOFRAMES: number = 2;\r\n\r\n /**\r\n * Use this predicate to dynamically define the list of mesh you want to render.\r\n * If set, the renderList property will be overwritten.\r\n */\r\n public renderListPredicate: (AbstractMesh: AbstractMesh) => boolean;\r\n\r\n private _renderList: Nullable>;\r\n private _unObserveRenderList: Nullable<() => void> = null;\r\n\r\n /**\r\n * Use this list to define the list of mesh you want to render.\r\n */\r\n public get renderList(): Nullable> {\r\n return this._renderList;\r\n }\r\n\r\n public set renderList(value: Nullable>) {\r\n if (this._unObserveRenderList) {\r\n this._unObserveRenderList();\r\n this._unObserveRenderList = null;\r\n }\r\n\r\n if (value) {\r\n this._unObserveRenderList = _ObserveArray(value, this._renderListHasChanged);\r\n }\r\n\r\n this._renderList = value;\r\n }\r\n\r\n private _renderListHasChanged = (_functionName: String, previousLength: number) => {\r\n const newLength = this._renderList ? this._renderList.length : 0;\r\n if ((previousLength === 0 && newLength > 0) || newLength === 0) {\r\n this.getScene()?.meshes.forEach((mesh) => {\r\n mesh._markSubMeshesAsLightDirty();\r\n });\r\n }\r\n };\r\n\r\n /**\r\n * Use this function to overload the renderList array at rendering time.\r\n * Return null to render with the current renderList, else return the list of meshes to use for rendering.\r\n * For 2DArray RTT, layerOrFace is the index of the layer that is going to be rendered, else it is the faceIndex of\r\n * the cube (if the RTT is a cube, else layerOrFace=0).\r\n * The renderList passed to the function is the current render list (the one that will be used if the function returns null).\r\n * The length of this list is passed through renderListLength: don't use renderList.length directly because the array can\r\n * hold dummy elements!\r\n */\r\n public getCustomRenderList: (layerOrFace: number, renderList: Nullable>>, renderListLength: number) => Nullable>;\r\n\r\n /**\r\n * Define if particles should be rendered in your texture.\r\n */\r\n public renderParticles = true;\r\n /**\r\n * Define if sprites should be rendered in your texture.\r\n */\r\n public renderSprites = false;\r\n\r\n /**\r\n * Force checking the layerMask property even if a custom list of meshes is provided (ie. if renderList is not undefined)\r\n */\r\n public forceLayerMaskCheck = false;\r\n\r\n /**\r\n * Define the camera used to render the texture.\r\n */\r\n public activeCamera: Nullable;\r\n /**\r\n * Override the mesh isReady function with your own one.\r\n */\r\n public customIsReadyFunction: (mesh: AbstractMesh, refreshRate: number, preWarm?: boolean) => boolean;\r\n /**\r\n * Override the render function of the texture with your own one.\r\n */\r\n public customRenderFunction: (\r\n opaqueSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray,\r\n beforeTransparents?: () => void\r\n ) => void;\r\n /**\r\n * Define if camera post processes should be use while rendering the texture.\r\n */\r\n public useCameraPostProcesses: boolean;\r\n /**\r\n * Define if the camera viewport should be respected while rendering the texture or if the render should be done to the entire texture.\r\n */\r\n public ignoreCameraViewport: boolean = false;\r\n\r\n private _postProcessManager: Nullable;\r\n\r\n /**\r\n * Post-processes for this render target\r\n */\r\n public get postProcesses() {\r\n return this._postProcesses;\r\n }\r\n private _postProcesses: PostProcess[];\r\n private _resizeObserver: Nullable>;\r\n\r\n private get _prePassEnabled() {\r\n return !!this._prePassRenderTarget && this._prePassRenderTarget.enabled;\r\n }\r\n\r\n /**\r\n * An event triggered when the texture is unbind.\r\n */\r\n public onBeforeBindObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the texture is unbind.\r\n */\r\n public onAfterUnbindObservable = new Observable();\r\n\r\n private _onAfterUnbindObserver: Nullable>;\r\n /**\r\n * Set a after unbind callback in the texture.\r\n * This has been kept for backward compatibility and use of onAfterUnbindObservable is recommended.\r\n */\r\n public set onAfterUnbind(callback: () => void) {\r\n if (this._onAfterUnbindObserver) {\r\n this.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\r\n }\r\n this._onAfterUnbindObserver = this.onAfterUnbindObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered before rendering the texture\r\n */\r\n public onBeforeRenderObservable = new Observable();\r\n\r\n private _onBeforeRenderObserver: Nullable>;\r\n /**\r\n * Set a before render callback in the texture.\r\n * This has been kept for backward compatibility and use of onBeforeRenderObservable is recommended.\r\n */\r\n public set onBeforeRender(callback: (faceIndex: number) => void) {\r\n if (this._onBeforeRenderObserver) {\r\n this.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\r\n }\r\n this._onBeforeRenderObserver = this.onBeforeRenderObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered after rendering the texture\r\n */\r\n public onAfterRenderObservable = new Observable();\r\n\r\n private _onAfterRenderObserver: Nullable>;\r\n /**\r\n * Set a after render callback in the texture.\r\n * This has been kept for backward compatibility and use of onAfterRenderObservable is recommended.\r\n */\r\n public set onAfterRender(callback: (faceIndex: number) => void) {\r\n if (this._onAfterRenderObserver) {\r\n this.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n }\r\n this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered after the texture clear\r\n */\r\n public onClearObservable = new Observable();\r\n\r\n private _onClearObserver: Nullable>;\r\n /**\r\n * Set a clear callback in the texture.\r\n * This has been kept for backward compatibility and use of onClearObservable is recommended.\r\n */\r\n public set onClear(callback: (Engine: Engine) => void) {\r\n if (this._onClearObserver) {\r\n this.onClearObservable.remove(this._onClearObserver);\r\n }\r\n this._onClearObserver = this.onClearObservable.add(callback);\r\n }\r\n\r\n /**\r\n * An event triggered when the texture is resized.\r\n */\r\n public onResizeObservable = new Observable();\r\n\r\n /**\r\n * Define the clear color of the Render Target if it should be different from the scene.\r\n */\r\n public clearColor: Color4;\r\n protected _size: TextureSize;\r\n protected _initialSizeParameter: number | { width: number; height: number } | { ratio: number };\r\n protected _sizeRatio: Nullable;\r\n /** @internal */\r\n public _generateMipMaps: boolean;\r\n /** @internal */\r\n public _cleared = false;\r\n /**\r\n * Skip the initial clear of the rtt at the beginning of the frame render loop\r\n */\r\n public skipInitialClear = false;\r\n protected _renderingManager: RenderingManager;\r\n /** @internal */\r\n public _waitingRenderList?: string[];\r\n protected _doNotChangeAspectRatio: boolean;\r\n protected _currentRefreshId = -1;\r\n protected _refreshRate = 1;\r\n protected _textureMatrix: Matrix;\r\n protected _samples = 1;\r\n protected _renderTargetOptions: RenderTargetCreationOptions;\r\n private _canRescale = true;\r\n protected _renderTarget: Nullable = null;\r\n /**\r\n * Current render pass id of the render target texture. Note it can change over the rendering as there's a separate id for each face of a cube / each layer of an array layer!\r\n */\r\n public renderPassId: number;\r\n private _renderPassIds: number[];\r\n /**\r\n * Gets the render pass ids used by the render target texture. For a single render target the array length will be 1, for a cube texture it will be 6 and for\r\n * a 2D texture array it will return an array of ids the size of the 2D texture array\r\n */\r\n public get renderPassIds(): readonly number[] {\r\n return this._renderPassIds;\r\n }\r\n\r\n /**\r\n * Gets the current value of the refreshId counter\r\n */\r\n public get currentRefreshId() {\r\n return this._currentRefreshId;\r\n }\r\n\r\n /**\r\n * Sets a specific material to be used to render a mesh/a list of meshes in this render target texture\r\n * @param mesh mesh or array of meshes\r\n * @param material material or array of materials to use for this render pass. If undefined is passed, no specific material will be used but the regular material instead (mesh.material). It's possible to provide an array of materials to use a different material for each rendering in the case of a cube texture (6 rendering) and a 2D texture array (as many rendering as the length of the array)\r\n */\r\n public setMaterialForRendering(mesh: AbstractMesh | AbstractMesh[], material?: Material | Material[]): void {\r\n let meshes;\r\n if (!Array.isArray(mesh)) {\r\n meshes = [mesh];\r\n } else {\r\n meshes = mesh;\r\n }\r\n for (let j = 0; j < meshes.length; ++j) {\r\n for (let i = 0; i < this._renderPassIds.length; ++i) {\r\n meshes[j].setMaterialForRenderPass(this._renderPassIds[i], material !== undefined ? (Array.isArray(material) ? material[i] : material) : undefined);\r\n }\r\n }\r\n }\r\n\r\n private _isCubeData: boolean;\r\n\r\n /**\r\n * Define if the texture has multiple draw buffers or if false a single draw buffer.\r\n */\r\n public get isMulti(): boolean {\r\n return this._renderTarget?.isMulti ?? false;\r\n }\r\n\r\n /**\r\n * Gets render target creation options that were used.\r\n */\r\n public get renderTargetOptions(): RenderTargetCreationOptions {\r\n return this._renderTargetOptions;\r\n }\r\n\r\n /**\r\n * Gets the render target wrapper associated with this render target\r\n */\r\n public get renderTarget(): Nullable {\r\n return this._renderTarget;\r\n }\r\n\r\n protected _onRatioRescale(): void {\r\n if (this._sizeRatio) {\r\n this.resize(this._initialSizeParameter);\r\n }\r\n }\r\n\r\n /**\r\n * Gets or sets the center of the bounding box associated with the texture (when in cube mode)\r\n * It must define where the camera used to render the texture is set\r\n */\r\n public boundingBoxPosition = Vector3.Zero();\r\n\r\n private _boundingBoxSize: Vector3;\r\n\r\n /**\r\n * Gets or sets the size of the bounding box associated with the texture (when in cube mode)\r\n * When defined, the cubemap will switch to local mode\r\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\r\n * @example https://www.babylonjs-playground.com/#RNASML\r\n */\r\n public set boundingBoxSize(value: Vector3) {\r\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\r\n return;\r\n }\r\n this._boundingBoxSize = value;\r\n const scene = this.getScene();\r\n if (scene) {\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n }\r\n public get boundingBoxSize(): Vector3 {\r\n return this._boundingBoxSize;\r\n }\r\n\r\n /**\r\n * In case the RTT has been created with a depth texture, get the associated\r\n * depth texture.\r\n * Otherwise, return null.\r\n */\r\n public get depthStencilTexture(): Nullable {\r\n return this._renderTarget?._depthStencilTexture ?? null;\r\n }\r\n\r\n /**\r\n * Instantiate a render target texture. This is mainly used to render of screen the scene to for instance apply post process\r\n * or used a shadow, depth texture...\r\n * @param name The friendly name of the texture\r\n * @param size The size of the RTT (number if square, or {width: number, height:number} or {ratio:} to define a ratio from the main scene)\r\n * @param scene The scene the RTT belongs to. Default is the last created scene.\r\n * @param options The options for creating the render target texture.\r\n */\r\n constructor(name: string, size: number | { width: number; height: number; layers?: number } | { ratio: number }, scene?: Nullable, options?: RenderTargetTextureOptions);\r\n\r\n /**\r\n * Instantiate a render target texture. This is mainly used to render of screen the scene to for instance apply post process\r\n * or used a shadow, depth texture...\r\n * @param name The friendly name of the texture\r\n * @param size The size of the RTT (number if square, or {width: number, height:number} or {ratio:} to define a ratio from the main scene)\r\n * @param scene The scene the RTT belongs to. Default is the last created scene\r\n * @param generateMipMaps True (default: false) if mipmaps need to be generated after render\r\n * @param doNotChangeAspectRatio True (default) to not change the aspect ratio of the scene in the RTT\r\n * @param type The type of the buffer in the RTT (byte (default), half float, float...)\r\n * @param isCube True (default: false) if a cube texture needs to be created\r\n * @param samplingMode The sampling mode to be used with the render target (Trilinear (default), Linear, Nearest...)\r\n * @param generateDepthBuffer True (default) to generate a depth buffer\r\n * @param generateStencilBuffer True (default: false) to generate a stencil buffer\r\n * @param isMulti True (default: false) if multiple textures need to be created (Draw Buffers)\r\n * @param format The internal format of the buffer in the RTT (RED, RG, RGB, RGBA (default), ALPHA...)\r\n * @param delayAllocation True (default: false) if the texture allocation should be delayed\r\n * @param samples Sample count to use when creating the RTT\r\n * @param creationFlags specific flags to use when creating the texture (e.g., Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures)\r\n * @param noColorAttachment True (default: false) to indicate that no color target should be created. (e.g., if you only want to write to the depth buffer)\r\n * @param useSRGBBuffer True (default: false) to create a SRGB texture\r\n */\r\n constructor(\r\n name: string,\r\n size: number | { width: number; height: number; layers?: number } | { ratio: number },\r\n scene?: Nullable,\r\n generateMipMaps?: boolean,\r\n doNotChangeAspectRatio?: boolean,\r\n type?: number,\r\n isCube?: boolean,\r\n samplingMode?: number,\r\n generateDepthBuffer?: boolean,\r\n generateStencilBuffer?: boolean,\r\n isMulti?: boolean,\r\n format?: number,\r\n delayAllocation?: boolean,\r\n samples?: number,\r\n creationFlags?: number,\r\n noColorAttachment?: boolean,\r\n useSRGBBuffer?: boolean\r\n );\r\n\r\n /** @internal */\r\n constructor(\r\n name: string,\r\n size: number | { width: number; height: number; layers?: number } | { ratio: number },\r\n scene?: Nullable,\r\n generateMipMaps: boolean | RenderTargetTextureOptions = false,\r\n doNotChangeAspectRatio: boolean = true,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n isCube = false,\r\n samplingMode = Texture.TRILINEAR_SAMPLINGMODE,\r\n generateDepthBuffer = true,\r\n generateStencilBuffer = false,\r\n isMulti = false,\r\n format = Constants.TEXTUREFORMAT_RGBA,\r\n delayAllocation = false,\r\n samples?: number,\r\n creationFlags?: number,\r\n noColorAttachment = false,\r\n useSRGBBuffer = false\r\n ) {\r\n let colorAttachment: InternalTexture | undefined = undefined;\r\n if (typeof generateMipMaps === \"object\") {\r\n const options = generateMipMaps;\r\n generateMipMaps = !!options.generateMipMaps;\r\n doNotChangeAspectRatio = options.doNotChangeAspectRatio ?? true;\r\n type = options.type ?? Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n isCube = !!options.isCube;\r\n samplingMode = options.samplingMode ?? Texture.TRILINEAR_SAMPLINGMODE;\r\n generateDepthBuffer = options.generateDepthBuffer ?? true;\r\n generateStencilBuffer = !!options.generateStencilBuffer;\r\n isMulti = !!options.isMulti;\r\n format = options.format ?? Constants.TEXTUREFORMAT_RGBA;\r\n delayAllocation = !!options.delayAllocation;\r\n samples = options.samples;\r\n creationFlags = options.creationFlags;\r\n noColorAttachment = !!options.noColorAttachment;\r\n useSRGBBuffer = !!options.useSRGBBuffer;\r\n colorAttachment = options.colorAttachment;\r\n }\r\n\r\n super(null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format);\r\n\r\n scene = this.getScene();\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const engine = this.getScene()!.getEngine();\r\n\r\n this._coordinatesMode = Texture.PROJECTION_MODE;\r\n this.renderList = new Array();\r\n this.name = name;\r\n this.isRenderTarget = true;\r\n this._initialSizeParameter = size;\r\n this._renderPassIds = [];\r\n this._isCubeData = isCube;\r\n\r\n this._processSizeParameter(size);\r\n\r\n this.renderPassId = this._renderPassIds[0];\r\n\r\n this._resizeObserver = engine.onResizeObservable.add(() => {});\r\n\r\n this._generateMipMaps = generateMipMaps ? true : false;\r\n this._doNotChangeAspectRatio = doNotChangeAspectRatio;\r\n\r\n // Rendering groups\r\n this._renderingManager = new RenderingManager(scene);\r\n this._renderingManager._useSceneAutoClearSetup = true;\r\n\r\n if (isMulti) {\r\n return;\r\n }\r\n\r\n this._renderTargetOptions = {\r\n generateMipMaps: generateMipMaps,\r\n type: type,\r\n format: this._format ?? undefined,\r\n samplingMode: this.samplingMode,\r\n generateDepthBuffer: generateDepthBuffer,\r\n generateStencilBuffer: generateStencilBuffer,\r\n samples,\r\n creationFlags,\r\n noColorAttachment: noColorAttachment,\r\n useSRGBBuffer,\r\n colorAttachment: colorAttachment,\r\n label: this.name,\r\n };\r\n\r\n if (this.samplingMode === Texture.NEAREST_SAMPLINGMODE) {\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n }\r\n\r\n if (!delayAllocation) {\r\n if (isCube) {\r\n this._renderTarget = scene.getEngine().createRenderTargetCubeTexture(this.getRenderSize(), this._renderTargetOptions);\r\n this.coordinatesMode = Texture.INVCUBIC_MODE;\r\n this._textureMatrix = Matrix.Identity();\r\n } else {\r\n this._renderTarget = scene.getEngine().createRenderTargetTexture(this._size, this._renderTargetOptions);\r\n }\r\n this._texture = this._renderTarget.texture;\r\n if (samples !== undefined) {\r\n this.samples = samples;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a depth stencil texture.\r\n * This is only available in WebGL 2 or with the depth texture extension available.\r\n * @param comparisonFunction Specifies the comparison function to set on the texture. If 0 or undefined, the texture is not in comparison mode (default: 0)\r\n * @param bilinearFiltering Specifies whether or not bilinear filtering is enable on the texture (default: true)\r\n * @param generateStencil Specifies whether or not a stencil should be allocated in the texture (default: false)\r\n * @param samples sample count of the depth/stencil texture (default: 1)\r\n * @param format format of the depth texture (default: Constants.TEXTUREFORMAT_DEPTH32_FLOAT)\r\n */\r\n public createDepthStencilTexture(\r\n comparisonFunction: number = 0,\r\n bilinearFiltering: boolean = true,\r\n generateStencil: boolean = false,\r\n samples: number = 1,\r\n format: number = Constants.TEXTUREFORMAT_DEPTH32_FLOAT\r\n ): void {\r\n this._renderTarget?.createDepthStencilTexture(comparisonFunction, bilinearFiltering, generateStencil, samples, format);\r\n }\r\n\r\n private _releaseRenderPassId(): void {\r\n if (this._scene) {\r\n const engine = this._scene.getEngine();\r\n for (let i = 0; i < this._renderPassIds.length; ++i) {\r\n engine.releaseRenderPassId(this._renderPassIds[i]);\r\n }\r\n }\r\n this._renderPassIds = [];\r\n }\r\n\r\n private _createRenderPassId(): void {\r\n this._releaseRenderPassId();\r\n\r\n const engine = this._scene!.getEngine(); // scene can't be null in a RenderTargetTexture, see constructor\r\n const numPasses = this._isCubeData ? 6 : this.getRenderLayers() || 1;\r\n\r\n for (let i = 0; i < numPasses; ++i) {\r\n this._renderPassIds[i] = engine.createRenderPassId(`RenderTargetTexture - ${this.name}#${i}`);\r\n }\r\n }\r\n\r\n protected _processSizeParameter(size: number | { width: number; height: number } | { ratio: number }, createRenderPassIds = true): void {\r\n if ((<{ ratio: number }>size).ratio) {\r\n this._sizeRatio = (<{ ratio: number }>size).ratio;\r\n const engine = this._getEngine()!;\r\n this._size = {\r\n width: this._bestReflectionRenderTargetDimension(engine.getRenderWidth(), this._sizeRatio),\r\n height: this._bestReflectionRenderTargetDimension(engine.getRenderHeight(), this._sizeRatio),\r\n };\r\n } else {\r\n this._size = size;\r\n }\r\n\r\n if (createRenderPassIds) {\r\n this._createRenderPassId();\r\n }\r\n }\r\n\r\n /**\r\n * Define the number of samples to use in case of MSAA.\r\n * It defaults to one meaning no MSAA has been enabled.\r\n */\r\n public get samples(): number {\r\n return this._renderTarget?.samples ?? this._samples;\r\n }\r\n\r\n public set samples(value: number) {\r\n if (this._renderTarget) {\r\n this._samples = this._renderTarget.setSamples(value);\r\n }\r\n }\r\n\r\n /**\r\n * Resets the refresh counter of the texture and start bak from scratch.\r\n * Could be useful to regenerate the texture if it is setup to render only once.\r\n */\r\n public resetRefreshCounter(): void {\r\n this._currentRefreshId = -1;\r\n }\r\n\r\n /**\r\n * Define the refresh rate of the texture or the rendering frequency.\r\n * Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...\r\n */\r\n public get refreshRate(): number {\r\n return this._refreshRate;\r\n }\r\n public set refreshRate(value: number) {\r\n this._refreshRate = value;\r\n this.resetRefreshCounter();\r\n }\r\n\r\n /**\r\n * Adds a post process to the render target rendering passes.\r\n * @param postProcess define the post process to add\r\n */\r\n public addPostProcess(postProcess: PostProcess): void {\r\n if (!this._postProcessManager) {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n this._postProcessManager = new PostProcessManager(scene);\r\n this._postProcesses = new Array();\r\n }\r\n\r\n this._postProcesses.push(postProcess);\r\n this._postProcesses[0].autoClear = false;\r\n }\r\n\r\n /**\r\n * Clear all the post processes attached to the render target\r\n * @param dispose define if the cleared post processes should also be disposed (false by default)\r\n */\r\n public clearPostProcesses(dispose: boolean = false): void {\r\n if (!this._postProcesses) {\r\n return;\r\n }\r\n\r\n if (dispose) {\r\n for (const postProcess of this._postProcesses) {\r\n postProcess.dispose();\r\n }\r\n }\r\n\r\n this._postProcesses = [];\r\n }\r\n\r\n /**\r\n * Remove one of the post process from the list of attached post processes to the texture\r\n * @param postProcess define the post process to remove from the list\r\n */\r\n public removePostProcess(postProcess: PostProcess): void {\r\n if (!this._postProcesses) {\r\n return;\r\n }\r\n\r\n const index = this._postProcesses.indexOf(postProcess);\r\n\r\n if (index === -1) {\r\n return;\r\n }\r\n\r\n this._postProcesses.splice(index, 1);\r\n\r\n if (this._postProcesses.length > 0) {\r\n this._postProcesses[0].autoClear = false;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _shouldRender(): boolean {\r\n if (this._currentRefreshId === -1) {\r\n // At least render once\r\n this._currentRefreshId = 1;\r\n return true;\r\n }\r\n\r\n if (this.refreshRate === this._currentRefreshId) {\r\n this._currentRefreshId = 1;\r\n return true;\r\n }\r\n\r\n this._currentRefreshId++;\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets the actual render size of the texture.\r\n * @returns the width of the render size\r\n */\r\n public getRenderSize(): number {\r\n return this.getRenderWidth();\r\n }\r\n\r\n /**\r\n * Gets the actual render width of the texture.\r\n * @returns the width of the render size\r\n */\r\n public getRenderWidth(): number {\r\n if ((<{ width: number; height: number }>this._size).width) {\r\n return (<{ width: number; height: number }>this._size).width;\r\n }\r\n\r\n return this._size;\r\n }\r\n\r\n /**\r\n * Gets the actual render height of the texture.\r\n * @returns the height of the render size\r\n */\r\n public getRenderHeight(): number {\r\n if ((<{ width: number; height: number }>this._size).width) {\r\n return (<{ width: number; height: number }>this._size).height;\r\n }\r\n\r\n return this._size;\r\n }\r\n\r\n /**\r\n * Gets the actual number of layers of the texture.\r\n * @returns the number of layers\r\n */\r\n public getRenderLayers(): number {\r\n const layers = (<{ width: number; height: number; layers?: number }>this._size).layers;\r\n if (layers) {\r\n return layers;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n /**\r\n * Don't allow this render target texture to rescale. Mainly used to prevent rescaling by the scene optimizer.\r\n */\r\n public disableRescaling() {\r\n this._canRescale = false;\r\n }\r\n\r\n /**\r\n * Get if the texture can be rescaled or not.\r\n */\r\n public get canRescale(): boolean {\r\n return this._canRescale;\r\n }\r\n\r\n /**\r\n * Resize the texture using a ratio.\r\n * @param ratio the ratio to apply to the texture size in order to compute the new target size\r\n */\r\n public scale(ratio: number): void {\r\n const newSize = Math.max(1, this.getRenderSize() * ratio);\r\n\r\n this.resize(newSize);\r\n }\r\n\r\n /**\r\n * Get the texture reflection matrix used to rotate/transform the reflection.\r\n * @returns the reflection matrix\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n if (this.isCube) {\r\n return this._textureMatrix;\r\n }\r\n\r\n return super.getReflectionTextureMatrix();\r\n }\r\n\r\n /**\r\n * Resize the texture to a new desired size.\r\n * Be careful as it will recreate all the data in the new texture.\r\n * @param size Define the new size. It can be:\r\n * - a number for squared texture,\r\n * - an object containing { width: number, height: number }\r\n * - or an object containing a ratio { ratio: number }\r\n */\r\n public resize(size: number | { width: number; height: number } | { ratio: number }): void {\r\n const wasCube = this.isCube;\r\n\r\n this._renderTarget?.dispose();\r\n this._renderTarget = null;\r\n\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this._processSizeParameter(size, false);\r\n\r\n if (wasCube) {\r\n this._renderTarget = scene.getEngine().createRenderTargetCubeTexture(this.getRenderSize(), this._renderTargetOptions);\r\n } else {\r\n this._renderTarget = scene.getEngine().createRenderTargetTexture(this._size, this._renderTargetOptions);\r\n }\r\n this._texture = this._renderTarget.texture;\r\n\r\n if (this._renderTargetOptions.samples !== undefined) {\r\n this.samples = this._renderTargetOptions.samples;\r\n }\r\n\r\n if (this.onResizeObservable.hasObservers()) {\r\n this.onResizeObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n private _defaultRenderListPrepared: boolean;\r\n\r\n /**\r\n * Renders all the objects from the render list into the texture.\r\n * @param useCameraPostProcess Define if camera post processes should be used during the rendering\r\n * @param dumpForDebug Define if the rendering result should be dumped (copied) for debugging purpose\r\n */\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n this._render(useCameraPostProcess, dumpForDebug);\r\n }\r\n\r\n /**\r\n * This function will check if the render target texture can be rendered (textures are loaded, shaders are compiled)\r\n * @returns true if all required resources are ready\r\n */\r\n public isReadyForRendering(): boolean {\r\n return this._render(false, false, true);\r\n }\r\n\r\n private _render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false, checkReadiness: boolean = false): boolean {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return checkReadiness;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n if (this.useCameraPostProcesses !== undefined) {\r\n useCameraPostProcess = this.useCameraPostProcesses;\r\n }\r\n\r\n if (this._waitingRenderList) {\r\n this.renderList = [];\r\n for (let index = 0; index < this._waitingRenderList.length; index++) {\r\n const id = this._waitingRenderList[index];\r\n const mesh = scene.getMeshById(id);\r\n if (mesh) {\r\n this.renderList.push(mesh);\r\n }\r\n }\r\n\r\n this._waitingRenderList = undefined;\r\n }\r\n\r\n // Is predicate defined?\r\n if (this.renderListPredicate) {\r\n if (this.renderList) {\r\n this.renderList.length = 0; // Clear previous renderList\r\n } else {\r\n this.renderList = [];\r\n }\r\n\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return checkReadiness;\r\n }\r\n\r\n const sceneMeshes = scene.meshes;\r\n\r\n for (let index = 0; index < sceneMeshes.length; index++) {\r\n const mesh = sceneMeshes[index];\r\n if (this.renderListPredicate(mesh)) {\r\n this.renderList.push(mesh);\r\n }\r\n }\r\n }\r\n\r\n const currentRenderPassId = engine.currentRenderPassId;\r\n\r\n this.onBeforeBindObservable.notifyObservers(this);\r\n\r\n // Set custom projection.\r\n // Needs to be before binding to prevent changing the aspect ratio.\r\n const camera: Nullable = this.activeCamera ?? scene.activeCamera;\r\n const sceneCamera = scene.activeCamera;\r\n\r\n if (camera) {\r\n if (camera !== scene.activeCamera) {\r\n scene.setTransformMatrix(camera.getViewMatrix(), camera.getProjectionMatrix(true));\r\n scene.activeCamera = camera;\r\n }\r\n engine.setViewport(camera.rigParent ? camera.rigParent.viewport : camera.viewport, this.getRenderWidth(), this.getRenderHeight());\r\n }\r\n\r\n this._defaultRenderListPrepared = false;\r\n\r\n let returnValue = checkReadiness;\r\n\r\n if (!checkReadiness) {\r\n if (this.is2DArray && !this.isMulti) {\r\n for (let layer = 0; layer < this.getRenderLayers(); layer++) {\r\n this._renderToTarget(0, useCameraPostProcess, dumpForDebug, layer, camera);\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n }\r\n } else if (this.isCube && !this.isMulti) {\r\n for (let face = 0; face < 6; face++) {\r\n this._renderToTarget(face, useCameraPostProcess, dumpForDebug, undefined, camera);\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n }\r\n } else {\r\n this._renderToTarget(0, useCameraPostProcess, dumpForDebug, undefined, camera);\r\n }\r\n } else {\r\n if (!scene.getViewMatrix()) {\r\n // We probably didn't execute scene.render() yet, so make sure we have a view/projection matrix setup for the scene\r\n scene.updateTransformMatrix();\r\n }\r\n const numLayers = this.is2DArray ? this.getRenderLayers() : this.isCube ? 6 : 1;\r\n for (let layer = 0; layer < numLayers && returnValue; layer++) {\r\n let currentRenderList: Nullable> = null;\r\n const defaultRenderList = this.renderList ? this.renderList : scene.getActiveMeshes().data;\r\n const defaultRenderListLength = this.renderList ? this.renderList.length : scene.getActiveMeshes().length;\r\n\r\n engine.currentRenderPassId = this._renderPassIds[layer];\r\n\r\n this.onBeforeRenderObservable.notifyObservers(layer);\r\n\r\n if (this.getCustomRenderList) {\r\n currentRenderList = this.getCustomRenderList(layer, defaultRenderList, defaultRenderListLength);\r\n }\r\n\r\n if (!currentRenderList) {\r\n currentRenderList = defaultRenderList;\r\n }\r\n\r\n if (!this._doNotChangeAspectRatio) {\r\n scene.updateTransformMatrix(true);\r\n }\r\n\r\n for (let i = 0; i < currentRenderList.length && returnValue; ++i) {\r\n const mesh = currentRenderList[i];\r\n\r\n if (!mesh.isEnabled() || mesh.isBlocked || !mesh.isVisible || !mesh.subMeshes) {\r\n continue;\r\n }\r\n\r\n if (this.customIsReadyFunction) {\r\n if (!this.customIsReadyFunction(mesh, this.refreshRate, checkReadiness)) {\r\n returnValue = false;\r\n continue;\r\n }\r\n } else if (!mesh.isReady(true)) {\r\n returnValue = false;\r\n continue;\r\n }\r\n }\r\n\r\n this.onAfterRenderObservable.notifyObservers(layer);\r\n\r\n if (this.is2DArray || this.isCube) {\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n }\r\n }\r\n }\r\n\r\n this.onAfterUnbindObservable.notifyObservers(this);\r\n\r\n engine.currentRenderPassId = currentRenderPassId;\r\n\r\n if (sceneCamera) {\r\n scene.activeCamera = sceneCamera;\r\n // Do not avoid setting uniforms when multiple scenes are active as another camera may have overwrite these\r\n if (scene.getEngine().scenes.length > 1 || (this.activeCamera && this.activeCamera !== scene.activeCamera)) {\r\n scene.setTransformMatrix(scene.activeCamera.getViewMatrix(), scene.activeCamera.getProjectionMatrix(true));\r\n }\r\n engine.setViewport(scene.activeCamera.viewport);\r\n }\r\n\r\n scene.resetCachedMaterial();\r\n\r\n return returnValue;\r\n }\r\n\r\n private _bestReflectionRenderTargetDimension(renderDimension: number, scale: number): number {\r\n const minimum = 128;\r\n const x = renderDimension * scale;\r\n const curved = Engine.NearestPOT(x + (minimum * minimum) / (minimum + x));\r\n\r\n // Ensure we don't exceed the render dimension (while staying POT)\r\n return Math.min(Engine.FloorPOT(renderDimension), curved);\r\n }\r\n\r\n private _prepareRenderingManager(currentRenderList: Array, currentRenderListLength: number, camera: Nullable, checkLayerMask: boolean): void {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this._renderingManager.reset();\r\n\r\n const sceneRenderId = scene.getRenderId();\r\n for (let meshIndex = 0; meshIndex < currentRenderListLength; meshIndex++) {\r\n const mesh = currentRenderList[meshIndex];\r\n\r\n if (mesh && !mesh.isBlocked) {\r\n if (this.customIsReadyFunction) {\r\n if (!this.customIsReadyFunction(mesh, this.refreshRate, false)) {\r\n this.resetRefreshCounter();\r\n continue;\r\n }\r\n } else if (!mesh.isReady(this.refreshRate === 0)) {\r\n this.resetRefreshCounter();\r\n continue;\r\n }\r\n\r\n if (!mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate && scene.activeCamera) {\r\n mesh._internalAbstractMeshDataInfo._currentLOD = scene.customLODSelector\r\n ? scene.customLODSelector(mesh, this.activeCamera || scene.activeCamera)\r\n : mesh.getLOD(this.activeCamera || scene.activeCamera);\r\n mesh._internalAbstractMeshDataInfo._currentLODIsUpToDate = true;\r\n }\r\n if (!mesh._internalAbstractMeshDataInfo._currentLOD) {\r\n continue;\r\n }\r\n\r\n let meshToRender = mesh._internalAbstractMeshDataInfo._currentLOD;\r\n\r\n meshToRender._preActivateForIntermediateRendering(sceneRenderId);\r\n\r\n let isMasked;\r\n if (checkLayerMask && camera) {\r\n isMasked = (mesh.layerMask & camera.layerMask) === 0;\r\n } else {\r\n isMasked = false;\r\n }\r\n\r\n if (mesh.isEnabled() && mesh.isVisible && mesh.subMeshes && !isMasked) {\r\n if (meshToRender !== mesh) {\r\n meshToRender._activate(sceneRenderId, true);\r\n }\r\n if (mesh._activate(sceneRenderId, true) && mesh.subMeshes.length) {\r\n if (!mesh.isAnInstance) {\r\n meshToRender._internalAbstractMeshDataInfo._onlyForInstancesIntermediate = false;\r\n } else {\r\n if (mesh._internalAbstractMeshDataInfo._actAsRegularMesh) {\r\n meshToRender = mesh;\r\n }\r\n }\r\n meshToRender._internalAbstractMeshDataInfo._isActiveIntermediate = true;\r\n\r\n for (let subIndex = 0; subIndex < meshToRender.subMeshes.length; subIndex++) {\r\n const subMesh = meshToRender.subMeshes[subIndex];\r\n this._renderingManager.dispatch(subMesh, meshToRender);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n for (let particleIndex = 0; particleIndex < scene.particleSystems.length; particleIndex++) {\r\n const particleSystem = scene.particleSystems[particleIndex];\r\n\r\n const emitter: any = particleSystem.emitter;\r\n\r\n if (!particleSystem.isStarted() || !emitter || (emitter.position && !emitter.isEnabled())) {\r\n continue;\r\n }\r\n\r\n this._renderingManager.dispatchParticles(particleSystem);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * @param faceIndex face index to bind to if this is a cubetexture\r\n * @param layer defines the index of the texture to bind in the array\r\n */\r\n public _bindFrameBuffer(faceIndex: number = 0, layer = 0) {\r\n const scene = this.getScene();\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n if (this._renderTarget) {\r\n engine.bindFramebuffer(this._renderTarget, this.isCube ? faceIndex : undefined, undefined, undefined, this.ignoreCameraViewport, 0, layer);\r\n }\r\n }\r\n\r\n protected _unbindFrameBuffer(engine: Engine, faceIndex: number): void {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n engine.unBindFramebuffer(this._renderTarget, this.isCube, () => {\r\n this.onAfterRenderObservable.notifyObservers(faceIndex);\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _prepareFrame(scene: Scene, faceIndex?: number, layer?: number, useCameraPostProcess?: boolean) {\r\n if (this._postProcessManager) {\r\n if (!this._prePassEnabled) {\r\n this._postProcessManager._prepareFrame(this._texture, this._postProcesses);\r\n }\r\n } else if (!useCameraPostProcess || !scene.postProcessManager._prepareFrame(this._texture)) {\r\n this._bindFrameBuffer(faceIndex, layer);\r\n }\r\n }\r\n\r\n private _renderToTarget(faceIndex: number, useCameraPostProcess: boolean, dumpForDebug: boolean, layer = 0, camera: Nullable = null): void {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n engine._debugPushGroup?.(`render to face #${faceIndex} layer #${layer}`, 1);\r\n\r\n // Bind\r\n this._prepareFrame(scene, faceIndex, layer, useCameraPostProcess);\r\n\r\n if (this.is2DArray) {\r\n engine.currentRenderPassId = this._renderPassIds[layer];\r\n this.onBeforeRenderObservable.notifyObservers(layer);\r\n } else {\r\n engine.currentRenderPassId = this._renderPassIds[faceIndex];\r\n this.onBeforeRenderObservable.notifyObservers(faceIndex);\r\n }\r\n\r\n const fastPath = engine.snapshotRendering && engine.snapshotRenderingMode === Constants.SNAPSHOTRENDERING_FAST;\r\n\r\n if (!fastPath) {\r\n // Get the list of meshes to render\r\n let currentRenderList: Nullable> = null;\r\n const defaultRenderList = this.renderList ? this.renderList : scene.getActiveMeshes().data;\r\n const defaultRenderListLength = this.renderList ? this.renderList.length : scene.getActiveMeshes().length;\r\n\r\n if (this.getCustomRenderList) {\r\n currentRenderList = this.getCustomRenderList(this.is2DArray ? layer : faceIndex, defaultRenderList, defaultRenderListLength);\r\n }\r\n\r\n if (!currentRenderList) {\r\n // No custom render list provided, we prepare the rendering for the default list, but check\r\n // first if we did not already performed the preparation before so as to avoid re-doing it several times\r\n if (!this._defaultRenderListPrepared) {\r\n this._prepareRenderingManager(defaultRenderList, defaultRenderListLength, camera, !this.renderList || this.forceLayerMaskCheck);\r\n this._defaultRenderListPrepared = true;\r\n }\r\n currentRenderList = defaultRenderList;\r\n } else {\r\n // Prepare the rendering for the custom render list provided\r\n this._prepareRenderingManager(currentRenderList, currentRenderList.length, camera, this.forceLayerMaskCheck);\r\n }\r\n\r\n // Before clear\r\n for (const step of scene._beforeRenderTargetClearStage) {\r\n step.action(this, faceIndex, layer);\r\n }\r\n\r\n // Clear\r\n if (this.onClearObservable.hasObservers()) {\r\n this.onClearObservable.notifyObservers(engine);\r\n } else {\r\n if (!this.skipInitialClear) {\r\n engine.clear(this.clearColor || scene.clearColor, true, true, true);\r\n }\r\n }\r\n\r\n if (!this._doNotChangeAspectRatio) {\r\n scene.updateTransformMatrix(true);\r\n }\r\n\r\n // Before Camera Draw\r\n for (const step of scene._beforeRenderTargetDrawStage) {\r\n step.action(this, faceIndex, layer);\r\n }\r\n\r\n // Render\r\n this._renderingManager.render(this.customRenderFunction, currentRenderList, this.renderParticles, this.renderSprites);\r\n\r\n // After Camera Draw\r\n for (const step of scene._afterRenderTargetDrawStage) {\r\n step.action(this, faceIndex, layer);\r\n }\r\n\r\n const saveGenerateMipMaps = this._texture?.generateMipMaps ?? false;\r\n\r\n if (this._texture) {\r\n this._texture.generateMipMaps = false; // if left true, the mipmaps will be generated (if this._texture.generateMipMaps = true) when the first post process binds its own RTT: by doing so it will unbind the current RTT,\r\n // which will trigger a mipmap generation. We don't want this because it's a wasted work, we will do an unbind of the current RTT at the end of the process (see unbindFrameBuffer) which will\r\n // trigger the generation of the final mipmaps\r\n }\r\n\r\n if (this._postProcessManager) {\r\n this._postProcessManager._finalizeFrame(false, this._renderTarget ?? undefined, faceIndex, this._postProcesses, this.ignoreCameraViewport);\r\n } else if (useCameraPostProcess) {\r\n scene.postProcessManager._finalizeFrame(false, this._renderTarget ?? undefined, faceIndex);\r\n }\r\n\r\n for (const step of scene._afterRenderTargetPostProcessStage) {\r\n step.action(this, faceIndex, layer);\r\n }\r\n\r\n if (this._texture) {\r\n this._texture.generateMipMaps = saveGenerateMipMaps;\r\n }\r\n\r\n if (!this._doNotChangeAspectRatio) {\r\n scene.updateTransformMatrix(true);\r\n }\r\n\r\n // Dump ?\r\n if (dumpForDebug) {\r\n DumpTools.DumpFramebuffer(this.getRenderWidth(), this.getRenderHeight(), engine);\r\n }\r\n } else {\r\n // Clear\r\n if (this.onClearObservable.hasObservers()) {\r\n this.onClearObservable.notifyObservers(engine);\r\n } else {\r\n if (!this.skipInitialClear) {\r\n engine.clear(this.clearColor || scene.clearColor, true, true, true);\r\n }\r\n }\r\n }\r\n\r\n // Unbind\r\n this._unbindFrameBuffer(engine, faceIndex);\r\n\r\n if (this._texture && this.isCube && faceIndex === 5) {\r\n engine.generateMipMapsForCubemap(this._texture);\r\n }\r\n\r\n engine._debugPopGroup?.(1);\r\n }\r\n\r\n /**\r\n * Overrides the default sort function applied in the rendering group to prepare the meshes.\r\n * This allowed control for front to back rendering or reversely depending of the special needs.\r\n *\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param opaqueSortCompareFn The opaque queue comparison function use to sort.\r\n * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.\r\n * @param transparentSortCompareFn The transparent queue comparison function use to sort.\r\n */\r\n public setRenderingOrder(\r\n renderingGroupId: number,\r\n opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null,\r\n transparentSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number> = null\r\n ): void {\r\n this._renderingManager.setRenderingOrder(renderingGroupId, opaqueSortCompareFn, alphaTestSortCompareFn, transparentSortCompareFn);\r\n }\r\n\r\n /**\r\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.\r\n *\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\r\n */\r\n public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {\r\n this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);\r\n this._renderingManager._useSceneAutoClearSetup = false;\r\n }\r\n\r\n /**\r\n * Clones the texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): RenderTargetTexture {\r\n const textureSize = this.getSize();\r\n const newTexture = new RenderTargetTexture(\r\n this.name,\r\n textureSize,\r\n this.getScene(),\r\n this._renderTargetOptions.generateMipMaps,\r\n this._doNotChangeAspectRatio,\r\n this._renderTargetOptions.type,\r\n this.isCube,\r\n this._renderTargetOptions.samplingMode,\r\n this._renderTargetOptions.generateDepthBuffer,\r\n this._renderTargetOptions.generateStencilBuffer,\r\n undefined,\r\n this._renderTargetOptions.format,\r\n undefined,\r\n this._renderTargetOptions.samples\r\n );\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // RenderTarget Texture\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n if (this.renderList) {\r\n newTexture.renderList = this.renderList.slice(0);\r\n }\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Serialize the texture to a JSON representation we can easily use in the respective Parse function.\r\n * @returns The JSON representation of the texture\r\n */\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.renderTargetSize = this.getRenderSize();\r\n serializationObject.renderList = [];\r\n\r\n if (this.renderList) {\r\n for (let index = 0; index < this.renderList.length; index++) {\r\n serializationObject.renderList.push(this.renderList[index].id);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * This will remove the attached framebuffer objects. The texture will not be able to be used as render target anymore\r\n */\r\n public disposeFramebufferObjects(): void {\r\n this._renderTarget?.dispose(true);\r\n }\r\n\r\n /**\r\n * Release and destroy the underlying lower level texture aka internalTexture.\r\n */\r\n public releaseInternalTexture(): void {\r\n this._renderTarget?.releaseTextures();\r\n this._texture = null;\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n this.onResizeObservable.clear();\r\n this.onClearObservable.clear();\r\n this.onAfterRenderObservable.clear();\r\n this.onAfterUnbindObservable.clear();\r\n this.onBeforeBindObservable.clear();\r\n this.onBeforeRenderObservable.clear();\r\n\r\n if (this._postProcessManager) {\r\n this._postProcessManager.dispose();\r\n this._postProcessManager = null;\r\n }\r\n\r\n if (this._prePassRenderTarget) {\r\n this._prePassRenderTarget.dispose();\r\n }\r\n\r\n this._releaseRenderPassId();\r\n this.clearPostProcesses(true);\r\n\r\n if (this._resizeObserver) {\r\n this.getScene()!.getEngine().onResizeObservable.remove(this._resizeObserver);\r\n this._resizeObserver = null;\r\n }\r\n\r\n this.renderList = null;\r\n\r\n // Remove from custom render targets\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n let index = scene.customRenderTargets.indexOf(this);\r\n\r\n if (index >= 0) {\r\n scene.customRenderTargets.splice(index, 1);\r\n }\r\n\r\n for (const camera of scene.cameras) {\r\n index = camera.customRenderTargets.indexOf(this);\r\n\r\n if (index >= 0) {\r\n camera.customRenderTargets.splice(index, 1);\r\n }\r\n }\r\n\r\n this._renderTarget?.dispose();\r\n this._renderTarget = null;\r\n this._texture = null;\r\n\r\n super.dispose();\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (this.refreshRate === RenderTargetTexture.REFRESHRATE_RENDER_ONCE) {\r\n this.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;\r\n }\r\n\r\n if (this._postProcessManager) {\r\n this._postProcessManager._rebuild();\r\n }\r\n }\r\n\r\n /**\r\n * Clear the info related to rendering groups preventing retention point in material dispose.\r\n */\r\n public freeRenderingGroups(): void {\r\n if (this._renderingManager) {\r\n this._renderingManager.freeRenderingGroups();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a MultiviewRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 1;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nTexture._CreateRenderTargetTexture = (name: string, renderTargetSize: number, scene: Scene, generateMipMaps: boolean, creationFlags?: number) => {\r\n return new RenderTargetTexture(name, renderTargetSize, scene, generateMipMaps);\r\n};\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"passCubePixelShader\";\nconst shader = `varying vec2 vUV;uniform samplerCube textureSampler;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{vec2 uv=vUV*2.0-1.0;\n#ifdef POSITIVEX\ngl_FragColor=textureCube(textureSampler,vec3(1.001,uv.y,uv.x));\n#endif\n#ifdef NEGATIVEX\ngl_FragColor=textureCube(textureSampler,vec3(-1.001,uv.y,uv.x));\n#endif\n#ifdef POSITIVEY\ngl_FragColor=textureCube(textureSampler,vec3(uv.y,1.001,uv.x));\n#endif\n#ifdef NEGATIVEY\ngl_FragColor=textureCube(textureSampler,vec3(uv.y,-1.001,uv.x));\n#endif\n#ifdef POSITIVEZ\ngl_FragColor=textureCube(textureSampler,vec3(uv,1.001));\n#endif\n#ifdef NEGATIVEZ\ngl_FragColor=textureCube(textureSampler,vec3(uv,-1.001));\n#endif\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const passCubePixelShader = { name, shader };\n","import type { Nullable } from \"../types\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { PostProcessOptions } from \"./postProcess\";\r\nimport { PostProcess } from \"./postProcess\";\r\nimport { Engine } from \"../Engines/engine\";\r\n\r\nimport \"../Shaders/pass.fragment\";\r\nimport \"../Shaders/passCube.fragment\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport { SerializationHelper } from \"../Misc/decorators\";\r\n\r\nimport type { Scene } from \"../scene\";\r\n\r\n/**\r\n * PassPostProcess which produces an output the same as it's input\r\n */\r\nexport class PassPostProcess extends PostProcess {\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"PassPostProcess\" string\r\n */\r\n public getClassName(): string {\r\n return \"PassPostProcess\";\r\n }\r\n\r\n /**\r\n * Creates the PassPostProcess\r\n * @param name The name of the effect.\r\n * @param options The required width/height ratio to downsize to before computing the render pass.\r\n * @param camera The camera to apply the render pass to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\r\n * @param engine The engine which the post process will be applied. (default: current engine)\r\n * @param reusable If the post process can be reused on the same frame. (default: false)\r\n * @param textureType The type of texture to be used when performing the post processing.\r\n * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)\r\n */\r\n constructor(\r\n name: string,\r\n options: number | PostProcessOptions,\r\n camera: Nullable = null,\r\n samplingMode?: number,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n blockCompilation = false\r\n ) {\r\n super(name, \"pass\", null, null, options, camera, samplingMode, engine, reusable, undefined, textureType, undefined, null, blockCompilation);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {\r\n return SerializationHelper.Parse(\r\n () => {\r\n return new PassPostProcess(\r\n parsedPostProcess.name,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n parsedPostProcess._engine,\r\n parsedPostProcess.reusable\r\n );\r\n },\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PassPostProcess\", PassPostProcess);\r\n\r\n/**\r\n * PassCubePostProcess which produces an output the same as it's input (which must be a cube texture)\r\n */\r\nexport class PassCubePostProcess extends PostProcess {\r\n private _face = 0;\r\n\r\n /**\r\n * Gets or sets the cube face to display.\r\n * * 0 is +X\r\n * * 1 is -X\r\n * * 2 is +Y\r\n * * 3 is -Y\r\n * * 4 is +Z\r\n * * 5 is -Z\r\n */\r\n public get face(): number {\r\n return this._face;\r\n }\r\n\r\n public set face(value: number) {\r\n if (value < 0 || value > 5) {\r\n return;\r\n }\r\n\r\n this._face = value;\r\n switch (this._face) {\r\n case 0:\r\n this.updateEffect(\"#define POSITIVEX\");\r\n break;\r\n case 1:\r\n this.updateEffect(\"#define NEGATIVEX\");\r\n break;\r\n case 2:\r\n this.updateEffect(\"#define POSITIVEY\");\r\n break;\r\n case 3:\r\n this.updateEffect(\"#define NEGATIVEY\");\r\n break;\r\n case 4:\r\n this.updateEffect(\"#define POSITIVEZ\");\r\n break;\r\n case 5:\r\n this.updateEffect(\"#define NEGATIVEZ\");\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"PassCubePostProcess\" string\r\n */\r\n public getClassName(): string {\r\n return \"PassCubePostProcess\";\r\n }\r\n\r\n /**\r\n * Creates the PassCubePostProcess\r\n * @param name The name of the effect.\r\n * @param options The required width/height ratio to downsize to before computing the render pass.\r\n * @param camera The camera to apply the render pass to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\r\n * @param engine The engine which the post process will be applied. (default: current engine)\r\n * @param reusable If the post process can be reused on the same frame. (default: false)\r\n * @param textureType The type of texture to be used when performing the post processing.\r\n * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)\r\n */\r\n constructor(\r\n name: string,\r\n options: number | PostProcessOptions,\r\n camera: Nullable = null,\r\n samplingMode?: number,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n blockCompilation = false\r\n ) {\r\n super(name, \"passCube\", null, null, options, camera, samplingMode, engine, reusable, \"#define POSITIVEX\", textureType, undefined, null, blockCompilation);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {\r\n return SerializationHelper.Parse(\r\n () => {\r\n return new PassCubePostProcess(\r\n parsedPostProcess.name,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n parsedPostProcess._engine,\r\n parsedPostProcess.reusable\r\n );\r\n },\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nEngine._RescalePostProcessFactory = (engine: Engine) => {\r\n return new PassPostProcess(\"rescale\", 1, null, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, engine, false, Constants.TEXTURETYPE_UNSIGNED_INT);\r\n};\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.getEffect().executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number,\r\n width?: number,\r\n height?: number\r\n): Promise {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine() as Engine;\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n width = width ?? internalTexture.width;\r\n height = height ?? internalTexture.height;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: width as number, height: height as number },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.getEffect().executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess!], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n};\r\n","import { Constants } from \"../Engines/constants\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport \"../Shaders/rgbdDecode.fragment\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\nimport \"../Engines/Extensions/engine.renderTarget\";\r\nimport { ApplyPostProcess } from \"./textureTools\";\r\n\r\nimport type { Texture } from \"../Materials/Textures/texture\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { Scene } from \"../scene\";\r\n\r\n/**\r\n * Class used to host RGBD texture specific utilities\r\n */\r\nexport class RGBDTextureTools {\r\n /**\r\n * Expand the RGBD Texture from RGBD to Half Float if possible.\r\n * @param texture the texture to expand.\r\n */\r\n public static ExpandRGBDTexture(texture: Texture) {\r\n const internalTexture = texture._texture;\r\n if (!internalTexture || !texture.isRGBD) {\r\n return;\r\n }\r\n\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine() as Engine;\r\n const caps = engine.getCaps();\r\n const isReady = internalTexture.isReady;\r\n let expandTexture = false;\r\n\r\n // If half float available we can uncompress the texture\r\n if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\r\n expandTexture = true;\r\n internalTexture.type = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n // If full float available we can uncompress the texture\r\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\r\n expandTexture = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n if (expandTexture) {\r\n // Do not use during decode.\r\n internalTexture.isReady = false;\r\n internalTexture._isRGBD = false;\r\n internalTexture.invertY = false;\r\n }\r\n\r\n const expandRGBDTexture = () => {\r\n // Expand the texture if possible\r\n if (expandTexture) {\r\n // Simply run through the decode PP.\r\n const rgbdPostProcess = new PostProcess(\r\n \"rgbdDecode\",\r\n \"rgbdDecode\",\r\n null,\r\n null,\r\n 1,\r\n null,\r\n Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n undefined,\r\n internalTexture.type,\r\n undefined,\r\n null,\r\n false\r\n );\r\n rgbdPostProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const expandedTexture = engine.createRenderTargetTexture(internalTexture.width, {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode: internalTexture.samplingMode,\r\n type: internalTexture.type,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n });\r\n\r\n rgbdPostProcess.getEffect().executeWhenCompiled(() => {\r\n // PP Render Pass\r\n rgbdPostProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n texture.getScene()!.postProcessManager.directRender([rgbdPostProcess!], expandedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (rgbdPostProcess) {\r\n rgbdPostProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n expandedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.isReady = true;\r\n });\r\n }\r\n };\r\n\r\n if (isReady) {\r\n expandRGBDTexture();\r\n } else {\r\n texture.onLoadObservable.addOnce(expandRGBDTexture);\r\n }\r\n }\r\n\r\n /**\r\n * Encode the texture to RGBD if possible.\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param outputTextureType type of the texture in which the encoding is performed\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n public static EncodeTextureToRGBD(internalTexture: InternalTexture, scene: Scene, outputTextureType = Constants.TEXTURETYPE_UNSIGNED_BYTE): Promise {\r\n return ApplyPostProcess(\"rgbdEncode\", internalTexture, scene, outputTextureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\r\n }\r\n}\r\n","import type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { Scene } from \"../scene\";\r\nimport { RGBDTextureTools } from \"./rgbdTextureTools\";\r\nimport { Tools } from \"./tools\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst _environmentBRDFBase64Texture =\r\n \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAgAElEQVR42u29yY5tWXIlZnbuiSaTbZFUkZRKrCKhElASQA0EoQABgn6hJvoXzfUP+gP9hWb6Bg00IgRoQJaKqUxmZmTEe8/v0uB2u7Fm2T7HIyIrnz88uPvt3f2a2WrMbOvf/u3PvvzP/sUf/N6//i8vf/lv/3v5H//d//Sb//Uq/5u8yf8hV/m/5Cp/L1f5hVzlG7nKJ7mKyJuIXN/hPwqXI/g++zq6rPI5u8z+WqfLre+zy7PrVv9L8brsMiGvk8XLmM/sdfHXal4e3ad6GXPdyu2ij8u/+uv/5cuf/OSLfdtEfvUr+dnf/d0X//t3H/7bf/hP//N/928h/0Yg/4VA/kogfyGQP5Wr/IFAvhbIlwK5CGQTPP+9z5uPeePJSW+yo2+s/GtN30Rnv1E+f5zxof9R/lSXv/nr//mrr3+i+5dfyX7ZZQP07Tffys//8R/l/9TtX7790T/7r/8G8pdy+/8XAvnnAvkzgfwzgfyxQP5AIL8vkJ8K5KsmMVzu1U7p5PA5AXxOAJ8TwPf7sX/51ZeXfcemqnp9w/W77/S7X/6T/vzf/7383RWCX3/z05/9i3/13/0PX//eX/2FyP8tIv+PiPy9iPy/IvIzEfm5iPxCRH4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u3dtJ/ylW1Tik4ElUPmR9RqII+pVhD9ychABMQ51gOIZg+/G+5mGIzLB1JJC5WhzYjhJ7IWmLDpA8jzsAafUPkB2WnFBF4iSxkq1ty7f25rv/+EQLOxs2oUdTSA9HIR9swdBlCcFe9owPC3XWDDC0ISVzsEVbSCF/sWdA5Fu4HJqankp2SeQCYYrImNalfmhpVxYrGkUS4LeSUjg8dD7+D7w/ybIfy7vlB9/HJ978zr7/45Qgajzj+4EjIK/ULHPRAOlKr/aG0AFcqCyu0GcW45Igh6JMJmhA49/U+cEssHNJhtXDC1MOya3j/sAiAGcrEtqtgjBD6wEzSDc7D8o6C8rIqAZyPk+NQoNLAZ1hR64Yl1FBY648smUYKnSg1Xwk/0DyRyArByMUobyByhCcPnOaPyoegREFS4jNfYAw+IHCjdC1J2WDZBke/OyN85J24WiXwDYPoJyYuCD238ulvuzwt6KgHf0shWKsqCFFGjB/w8HU8eeTED9wAAAAABJRU5ErkJggg==\";\r\n\r\nlet _instanceNumber = 0;\r\n\r\n/**\r\n * Gets a default environment BRDF for MS-BRDF Height Correlated BRDF\r\n * @param scene defines the hosting scene\r\n * @returns the environment BRDF texture\r\n */\r\nexport const GetEnvironmentBRDFTexture = (scene: Scene): BaseTexture => {\r\n if (!scene.environmentBRDFTexture) {\r\n // Forces Delayed Texture Loading to prevent undefined error whilst setting RGBD values.\r\n const useDelayedTextureLoading = scene.useDelayedTextureLoading;\r\n scene.useDelayedTextureLoading = false;\r\n\r\n const previousState = scene._blockEntityCollection;\r\n scene._blockEntityCollection = false;\r\n const texture = Texture.CreateFromBase64String(\r\n _environmentBRDFBase64Texture,\r\n \"EnvironmentBRDFTexture\" + _instanceNumber++,\r\n scene,\r\n true,\r\n false,\r\n Texture.BILINEAR_SAMPLINGMODE\r\n );\r\n scene._blockEntityCollection = previousState;\r\n // BRDF Texture should not be cached here due to pre processing and redundant scene caches.\r\n const texturesCache = scene.getEngine().getLoadedTexturesCache();\r\n const index = texturesCache.indexOf(texture.getInternalTexture()!);\r\n if (index !== -1) {\r\n texturesCache.splice(index, 1);\r\n }\r\n\r\n texture.isRGBD = true;\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n scene.environmentBRDFTexture = texture;\r\n\r\n scene.useDelayedTextureLoading = useDelayedTextureLoading;\r\n\r\n RGBDTextureTools.ExpandRGBDTexture(texture);\r\n\r\n const observer = scene.getEngine().onContextRestoredObservable.add(() => {\r\n texture.isRGBD = true;\r\n const checkReady = () => {\r\n if (texture.isReady()) {\r\n RGBDTextureTools.ExpandRGBDTexture(texture);\r\n } else {\r\n Tools.SetImmediate(checkReady);\r\n }\r\n };\r\n checkReady();\r\n });\r\n\r\n scene.onDisposeObservable.add(() => {\r\n scene.getEngine().onContextRestoredObservable.remove(observer);\r\n });\r\n }\r\n\r\n return scene.environmentBRDFTexture;\r\n};\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const BRDFTextureTools = {\r\n /**\r\n * Gets a default environment BRDF for MS-BRDF Height Correlated BRDF\r\n * @param scene defines the hosting scene\r\n * @returns the environment BRDF texture\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n GetEnvironmentBRDFTexture,\r\n};\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { serialize, expandToProperty } from \"../../Misc/decorators\";\r\nimport { MaterialDefines } from \"../materialDefines\";\r\nimport { MaterialPluginBase } from \"../materialPluginBase\";\r\nimport type { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialBRDFDefines extends MaterialDefines {\r\n BRDF_V_HEIGHT_CORRELATED = false;\r\n MS_BRDF_ENERGY_CONSERVATION = false;\r\n SPHERICAL_HARMONICS = false;\r\n SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the BRDF component of the PBR material\r\n */\r\nexport class PBRBRDFConfiguration extends MaterialPluginBase {\r\n /**\r\n * Default value used for the energy conservation.\r\n * This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.\r\n */\r\n public static DEFAULT_USE_ENERGY_CONSERVATION = true;\r\n\r\n /**\r\n * Default value used for the Smith Visibility Height Correlated mode.\r\n * This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.\r\n */\r\n public static DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED = true;\r\n\r\n /**\r\n * Default value used for the IBL diffuse part.\r\n * This can help switching back to the polynomials mode globally which is a tiny bit\r\n * less GPU intensive at the drawback of a lower quality.\r\n */\r\n public static DEFAULT_USE_SPHERICAL_HARMONICS = true;\r\n\r\n /**\r\n * Default value used for activating energy conservation for the specular workflow.\r\n * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).\r\n * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.\r\n */\r\n public static DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION = true;\r\n\r\n private _useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;\r\n /**\r\n * Defines if the material uses energy conservation.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;\r\n\r\n private _useSmithVisibilityHeightCorrelated = PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED;\r\n /**\r\n * LEGACY Mode set to false\r\n * Defines if the material uses height smith correlated visibility term.\r\n * If you intent to not use our default BRDF, you need to load a separate BRDF Texture for the PBR\r\n * You can either load https://assets.babylonjs.com/environments/uncorrelatedBRDF.png\r\n * or https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds to have more precision\r\n * Not relying on height correlated will also disable energy conservation.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public useSmithVisibilityHeightCorrelated = PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED;\r\n\r\n private _useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;\r\n /**\r\n * LEGACY Mode set to false\r\n * Defines if the material uses spherical harmonics vs spherical polynomials for the\r\n * diffuse part of the IBL.\r\n * The harmonics despite a tiny bigger cost has been proven to provide closer results\r\n * to the ground truth.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;\r\n\r\n private _useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;\r\n /**\r\n * Defines if the material uses energy conservation, when the specular workflow is active.\r\n * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).\r\n * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.\r\n * In the deactivated case, the material author has to ensure energy conservation, for a physically plausible rendering.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsMiscDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsMiscDirty(): void {\r\n this._internalMarkAllSubMeshesAsMiscDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial, addToPluginList = true) {\r\n super(material, \"PBRBRDF\", 90, new MaterialBRDFDefines(), addToPluginList);\r\n\r\n this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[Constants.MATERIAL_MiscDirtyFlag];\r\n this._enable(true);\r\n }\r\n\r\n public prepareDefines(defines: MaterialBRDFDefines): void {\r\n defines.BRDF_V_HEIGHT_CORRELATED = this._useSmithVisibilityHeightCorrelated;\r\n defines.MS_BRDF_ENERGY_CONSERVATION = this._useEnergyConservation && this._useSmithVisibilityHeightCorrelated;\r\n defines.SPHERICAL_HARMONICS = this._useSphericalHarmonics;\r\n defines.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = this._useSpecularGlossinessInputEnergyConservation;\r\n }\r\n\r\n public getClassName(): string {\r\n return \"PBRBRDFConfiguration\";\r\n }\r\n}\r\n","import { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { SphericalPolynomial, SphericalHarmonics } from \"../../Maths/sphericalPolynomial\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { ToLinearSpace } from \"../../Maths/math.constants\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\n\r\nclass FileFaceOrientation {\r\n public name: string;\r\n public worldAxisForNormal: Vector3; // the world axis corresponding to the normal to the face\r\n public worldAxisForFileX: Vector3; // the world axis corresponding to texture right x-axis in file\r\n public worldAxisForFileY: Vector3; // the world axis corresponding to texture down y-axis in file\r\n\r\n public constructor(name: string, worldAxisForNormal: Vector3, worldAxisForFileX: Vector3, worldAxisForFileY: Vector3) {\r\n this.name = name;\r\n this.worldAxisForNormal = worldAxisForNormal;\r\n this.worldAxisForFileX = worldAxisForFileX;\r\n this.worldAxisForFileY = worldAxisForFileY;\r\n }\r\n}\r\n\r\n/**\r\n * Helper class dealing with the extraction of spherical polynomial dataArray\r\n * from a cube map.\r\n */\r\nexport class CubeMapToSphericalPolynomialTools {\r\n private static _FileFaces: FileFaceOrientation[] = [\r\n new FileFaceOrientation(\"right\", new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)), // +X east\r\n new FileFaceOrientation(\"left\", new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, -1, 0)), // -X west\r\n new FileFaceOrientation(\"up\", new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)), // +Y north\r\n new FileFaceOrientation(\"down\", new Vector3(0, -1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1)), // -Y south\r\n new FileFaceOrientation(\"front\", new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0)), // +Z top\r\n new FileFaceOrientation(\"back\", new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0)), // -Z bottom\r\n ];\r\n\r\n /** @internal */\r\n public static MAX_HDRI_VALUE = 4096;\r\n /** @internal */\r\n public static PRESERVE_CLAMPED_COLORS = false;\r\n\r\n /**\r\n * Converts a texture to the according Spherical Polynomial data.\r\n * This extracts the first 3 orders only as they are the only one used in the lighting.\r\n *\r\n * @param texture The texture to extract the information from.\r\n * @returns The Spherical Polynomial data.\r\n */\r\n public static ConvertCubeMapTextureToSphericalPolynomial(texture: BaseTexture): Nullable> {\r\n if (!texture.isCube) {\r\n // Only supports cube Textures currently.\r\n return null;\r\n }\r\n\r\n texture.getScene()?.getEngine().flushFramebuffer();\r\n\r\n const size = texture.getSize().width;\r\n const rightPromise = texture.readPixels(0, undefined, undefined, false);\r\n const leftPromise = texture.readPixels(1, undefined, undefined, false);\r\n\r\n let upPromise: Nullable>;\r\n let downPromise: Nullable>;\r\n if (texture.isRenderTarget) {\r\n upPromise = texture.readPixels(3, undefined, undefined, false);\r\n downPromise = texture.readPixels(2, undefined, undefined, false);\r\n } else {\r\n upPromise = texture.readPixels(2, undefined, undefined, false);\r\n downPromise = texture.readPixels(3, undefined, undefined, false);\r\n }\r\n\r\n const frontPromise = texture.readPixels(4, undefined, undefined, false);\r\n const backPromise = texture.readPixels(5, undefined, undefined, false);\r\n\r\n const gammaSpace = texture.gammaSpace;\r\n // Always read as RGBA.\r\n const format = Constants.TEXTUREFORMAT_RGBA;\r\n let type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n if (texture.textureType == Constants.TEXTURETYPE_FLOAT || texture.textureType == Constants.TEXTURETYPE_HALF_FLOAT) {\r\n type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n Promise.all([leftPromise, rightPromise, upPromise, downPromise, frontPromise, backPromise]).then(([left, right, up, down, front, back]) => {\r\n const cubeInfo: CubeMapInfo = {\r\n size,\r\n right,\r\n left,\r\n up,\r\n down,\r\n front,\r\n back,\r\n format,\r\n type,\r\n gammaSpace,\r\n };\r\n\r\n resolve(this.ConvertCubeMapToSphericalPolynomial(cubeInfo));\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Compute the area on the unit sphere of the rectangle defined by (x,y) and the origin\r\n * See https://www.rorydriscoll.com/2012/01/15/cubemap-texel-solid-angle/\r\n * @param x\r\n * @param y\r\n */\r\n private static _AreaElement(x: number, y: number): number {\r\n return Math.atan2(x * y, Math.sqrt(x * x + y * y + 1));\r\n }\r\n\r\n /**\r\n * Converts a cubemap to the according Spherical Polynomial data.\r\n * This extracts the first 3 orders only as they are the only one used in the lighting.\r\n *\r\n * @param cubeInfo The Cube map to extract the information from.\r\n * @returns The Spherical Polynomial data.\r\n */\r\n public static ConvertCubeMapToSphericalPolynomial(cubeInfo: CubeMapInfo): SphericalPolynomial {\r\n const sphericalHarmonics = new SphericalHarmonics();\r\n let totalSolidAngle = 0.0;\r\n\r\n // The (u,v) range is [-1,+1], so the distance between each texel is 2/Size.\r\n const du = 2.0 / cubeInfo.size;\r\n const dv = du;\r\n\r\n const halfTexel = 0.5 * du;\r\n\r\n // The (u,v) of the first texel is half a texel from the corner (-1,-1).\r\n const minUV = halfTexel - 1.0;\r\n\r\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\r\n const fileFace = this._FileFaces[faceIndex];\r\n const dataArray = (cubeInfo)[fileFace.name];\r\n let v = minUV;\r\n\r\n // TODO: we could perform the summation directly into a SphericalPolynomial (SP), which is more efficient than SphericalHarmonic (SH).\r\n // This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.\r\n // Because SP is still linear, so summation is fine in that basis.\r\n const stride = cubeInfo.format === Constants.TEXTUREFORMAT_RGBA ? 4 : 3;\r\n for (let y = 0; y < cubeInfo.size; y++) {\r\n let u = minUV;\r\n\r\n for (let x = 0; x < cubeInfo.size; x++) {\r\n // World direction (not normalised)\r\n const worldDirection = fileFace.worldAxisForFileX.scale(u).add(fileFace.worldAxisForFileY.scale(v)).add(fileFace.worldAxisForNormal);\r\n worldDirection.normalize();\r\n\r\n const deltaSolidAngle =\r\n this._AreaElement(u - halfTexel, v - halfTexel) -\r\n this._AreaElement(u - halfTexel, v + halfTexel) -\r\n this._AreaElement(u + halfTexel, v - halfTexel) +\r\n this._AreaElement(u + halfTexel, v + halfTexel);\r\n\r\n let r = dataArray[y * cubeInfo.size * stride + x * stride + 0];\r\n let g = dataArray[y * cubeInfo.size * stride + x * stride + 1];\r\n let b = dataArray[y * cubeInfo.size * stride + x * stride + 2];\r\n\r\n // Prevent NaN harmonics with extreme HDRI data.\r\n if (isNaN(r)) {\r\n r = 0;\r\n }\r\n if (isNaN(g)) {\r\n g = 0;\r\n }\r\n if (isNaN(b)) {\r\n b = 0;\r\n }\r\n\r\n // Handle Integer types.\r\n if (cubeInfo.type === Constants.TEXTURETYPE_UNSIGNED_INT) {\r\n r /= 255;\r\n g /= 255;\r\n b /= 255;\r\n }\r\n\r\n // Handle Gamma space textures.\r\n if (cubeInfo.gammaSpace) {\r\n r = Math.pow(Scalar.Clamp(r), ToLinearSpace);\r\n g = Math.pow(Scalar.Clamp(g), ToLinearSpace);\r\n b = Math.pow(Scalar.Clamp(b), ToLinearSpace);\r\n }\r\n\r\n // Prevent to explode in case of really high dynamic ranges.\r\n // sh 3 would not be enough to accurately represent it.\r\n const max = this.MAX_HDRI_VALUE;\r\n if (this.PRESERVE_CLAMPED_COLORS) {\r\n const currentMax = Math.max(r, g, b);\r\n if (currentMax > max) {\r\n const factor = max / currentMax;\r\n r *= factor;\r\n g *= factor;\r\n b *= factor;\r\n }\r\n } else {\r\n r = Scalar.Clamp(r, 0, max);\r\n g = Scalar.Clamp(g, 0, max);\r\n b = Scalar.Clamp(b, 0, max);\r\n }\r\n\r\n const color = new Color3(r, g, b);\r\n\r\n sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);\r\n\r\n totalSolidAngle += deltaSolidAngle;\r\n\r\n u += du;\r\n }\r\n\r\n v += dv;\r\n }\r\n }\r\n\r\n // Solid angle for entire sphere is 4*pi\r\n const sphereSolidAngle = 4.0 * Math.PI;\r\n\r\n // Adjust the solid angle to allow for how many faces we processed.\r\n const facesProcessed = 6.0;\r\n const expectedSolidAngle = (sphereSolidAngle * facesProcessed) / 6.0;\r\n\r\n // Adjust the harmonics so that the accumulated solid angle matches the expected solid angle.\r\n // This is needed because the numerical integration over the cube uses a\r\n // small angle approximation of solid angle for each texel (see deltaSolidAngle),\r\n // and also to compensate for accumulative error due to float precision in the summation.\r\n const correctionFactor = expectedSolidAngle / totalSolidAngle;\r\n sphericalHarmonics.scaleInPlace(correctionFactor);\r\n\r\n sphericalHarmonics.convertIncidentRadianceToIrradiance();\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n\r\n return SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport { CubeMapToSphericalPolynomialTools } from \"../../Misc/HighDynamicRange/cubemapToSphericalPolynomial\";\r\nimport type { SphericalPolynomial } from \"../../Maths/sphericalPolynomial\";\r\nimport { BaseTexture } from \"./baseTexture\";\r\n\r\ndeclare module \"./baseTexture\" {\r\n export interface BaseTexture {\r\n /**\r\n * Get the polynomial representation of the texture data.\r\n * This is mainly use as a fast way to recover IBL Diffuse irradiance data.\r\n * @see https://learnopengl.com/PBR/IBL/Diffuse-irradiance\r\n */\r\n sphericalPolynomial: Nullable;\r\n\r\n /**\r\n * Force recomputation of spherical polynomials.\r\n * Can be useful if you generate a cubemap multiple times (from a probe for eg) and you need the proper polynomials each time\r\n */\r\n forceSphericalPolynomialsRecompute(): void;\r\n }\r\n}\r\n\r\nBaseTexture.prototype.forceSphericalPolynomialsRecompute = function (): void {\r\n if (this._texture) {\r\n this._texture._sphericalPolynomial = null;\r\n this._texture._sphericalPolynomialPromise = null;\r\n this._texture._sphericalPolynomialComputed = false;\r\n }\r\n};\r\n\r\nObject.defineProperty(BaseTexture.prototype, \"sphericalPolynomial\", {\r\n get: function (this: BaseTexture) {\r\n if (this._texture) {\r\n if (this._texture._sphericalPolynomial || this._texture._sphericalPolynomialComputed) {\r\n return this._texture._sphericalPolynomial;\r\n }\r\n\r\n if (this._texture.isReady) {\r\n if (!this._texture._sphericalPolynomialPromise) {\r\n this._texture._sphericalPolynomialPromise = CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this);\r\n if (this._texture._sphericalPolynomialPromise === null) {\r\n this._texture._sphericalPolynomialComputed = true;\r\n } else {\r\n this._texture._sphericalPolynomialPromise.then((sphericalPolynomial) => {\r\n this._texture!._sphericalPolynomial = sphericalPolynomial;\r\n this._texture!._sphericalPolynomialComputed = true;\r\n });\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n }\r\n\r\n return null;\r\n },\r\n set: function (this: BaseTexture, value: Nullable) {\r\n if (this._texture) {\r\n this._texture._sphericalPolynomial = value;\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalFragmentDeclaration\";\n\nconst name = \"pbrFragmentDeclaration\";\nconst shader = `uniform vec4 vEyePosition;uniform vec3 vReflectionColor;uniform vec4 vAlbedoColor;uniform vec4 vLightingIntensity;uniform vec4 vReflectivityColor;uniform vec4 vMetallicReflectanceFactors;uniform vec3 vEmissiveColor;uniform float visibility;uniform vec3 vAmbientColor;\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec4 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef REFLECTIVITY\nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(SS_REFRACTION) || defined(PREPASS)\nuniform mat4 view;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REALTIME_FILTERING\nuniform vec2 vReflectionFilteringInfo;\n#endif\nuniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;\n#if defined(USE_LOCAL_REFLECTIONMAP_CUBIC) && defined(REFLECTIONMAP_CUBIC)\nuniform vec3 vReflectionPosition;uniform vec3 vReflectionSize; \n#endif\n#endif\n#if defined(SS_REFRACTION) && defined(SS_USE_LOCAL_REFRACTIONMAP_CUBIC)\nuniform vec3 vRefractionPosition;uniform vec3 vRefractionSize; \n#endif\n#ifdef CLEARCOAT\nuniform vec2 vClearCoatParams;uniform vec4 vClearCoatRefractionParams;\n#if defined(CLEARCOAT_TEXTURE) || defined(CLEARCOAT_TEXTURE_ROUGHNESS)\nuniform vec4 vClearCoatInfos;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nuniform mat4 clearCoatMatrix;\n#endif\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS\nuniform mat4 clearCoatRoughnessMatrix;\n#endif\n#ifdef CLEARCOAT_BUMP\nuniform vec2 vClearCoatBumpInfos;uniform vec2 vClearCoatTangentSpaceParams;uniform mat4 clearCoatBumpMatrix;\n#endif\n#ifdef CLEARCOAT_TINT\nuniform vec4 vClearCoatTintParams;uniform float clearCoatColorAtDistance;\n#ifdef CLEARCOAT_TINT_TEXTURE\nuniform vec2 vClearCoatTintInfos;uniform mat4 clearCoatTintMatrix;\n#endif\n#endif\n#endif\n#ifdef IRIDESCENCE\nuniform vec4 vIridescenceParams;\n#if defined(IRIDESCENCE_TEXTURE) || defined(IRIDESCENCE_THICKNESS_TEXTURE)\nuniform vec4 vIridescenceInfos;\n#endif\n#ifdef IRIDESCENCE_TEXTURE\nuniform mat4 iridescenceMatrix;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nuniform mat4 iridescenceThicknessMatrix;\n#endif\n#endif\n#ifdef ANISOTROPIC\nuniform vec3 vAnisotropy;\n#ifdef ANISOTROPIC_TEXTURE\nuniform vec2 vAnisotropyInfos;uniform mat4 anisotropyMatrix;\n#endif\n#endif\n#ifdef SHEEN\nuniform vec4 vSheenColor;\n#ifdef SHEEN_ROUGHNESS\nuniform float vSheenRoughness;\n#endif\n#if defined(SHEEN_TEXTURE) || defined(SHEEN_TEXTURE_ROUGHNESS)\nuniform vec4 vSheenInfos;\n#endif\n#ifdef SHEEN_TEXTURE\nuniform mat4 sheenMatrix;\n#endif\n#ifdef SHEEN_TEXTURE_ROUGHNESS\nuniform mat4 sheenRoughnessMatrix;\n#endif\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\nuniform vec4 vRefractionMicrosurfaceInfos;uniform vec4 vRefractionInfos;uniform mat4 refractionMatrix;\n#ifdef REALTIME_FILTERING\nuniform vec2 vRefractionFilteringInfo;\n#endif\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nuniform vec2 vThicknessInfos;uniform mat4 thicknessMatrix;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nuniform vec2 vRefractionIntensityInfos;uniform mat4 refractionIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nuniform vec2 vTranslucencyIntensityInfos;uniform mat4 translucencyIntensityMatrix;\n#endif\nuniform vec2 vThicknessParam;uniform vec3 vDiffusionDistance;uniform vec4 vTintColor;uniform vec3 vSubSurfaceIntensity;\n#endif\n#ifdef PREPASS\n#ifdef SS_SCATTERING\nuniform float scatteringDiffusionProfile;\n#endif\n#endif\n#if DEBUGMODE>0\nuniform vec2 vDebugMode;\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;\n#endif\n#include\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nuniform vec3 vSphericalL00;uniform vec3 vSphericalL1_1;uniform vec3 vSphericalL10;uniform vec3 vSphericalL11;uniform vec3 vSphericalL2_2;uniform vec3 vSphericalL2_1;uniform vec3 vSphericalL20;uniform vec3 vSphericalL21;uniform vec3 vSphericalL22;\n#else\nuniform vec3 vSphericalX;uniform vec3 vSphericalY;uniform vec3 vSphericalZ;uniform vec3 vSphericalXX_ZZ;uniform vec3 vSphericalYY_ZZ;uniform vec3 vSphericalZZ;uniform vec3 vSphericalXY;uniform vec3 vSphericalYZ;uniform vec3 vSphericalZX;\n#endif\n#endif\n#define ADDITIONAL_FRAGMENT_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./sceneUboDeclaration\";\nimport \"./meshUboDeclaration\";\n\nconst name = \"pbrUboDeclaration\";\nconst shader = `layout(std140,column_major) uniform;uniform Material {vec2 vAlbedoInfos;vec4 vAmbientInfos;vec2 vOpacityInfos;vec2 vEmissiveInfos;vec2 vLightmapInfos;vec3 vReflectivityInfos;vec2 vMicroSurfaceSamplerInfos;vec2 vReflectionInfos;vec2 vReflectionFilteringInfo;vec3 vReflectionPosition;vec3 vReflectionSize;vec3 vBumpInfos;mat4 albedoMatrix;mat4 ambientMatrix;mat4 opacityMatrix;mat4 emissiveMatrix;mat4 lightmapMatrix;mat4 reflectivityMatrix;mat4 microSurfaceSamplerMatrix;mat4 bumpMatrix;vec2 vTangentSpaceParams;mat4 reflectionMatrix;vec3 vReflectionColor;vec4 vAlbedoColor;vec4 vLightingIntensity;vec3 vReflectionMicrosurfaceInfos;float pointSize;vec4 vReflectivityColor;vec3 vEmissiveColor;vec3 vAmbientColor;vec2 vDebugMode;vec4 vMetallicReflectanceFactors;vec2 vMetallicReflectanceInfos;mat4 metallicReflectanceMatrix;vec2 vReflectanceInfos;mat4 reflectanceMatrix;vec3 vSphericalL00;vec3 vSphericalL1_1;vec3 vSphericalL10;vec3 vSphericalL11;vec3 vSphericalL2_2;vec3 vSphericalL2_1;vec3 vSphericalL20;vec3 vSphericalL21;vec3 vSphericalL22;vec3 vSphericalX;vec3 vSphericalY;vec3 vSphericalZ;vec3 vSphericalXX_ZZ;vec3 vSphericalYY_ZZ;vec3 vSphericalZZ;vec3 vSphericalXY;vec3 vSphericalYZ;vec3 vSphericalZX;\n#define ADDITIONAL_UBO_DECLARATION\n};\n#include\n#include\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./mainUVVaryingDeclaration\";\n\nconst name = \"pbrFragmentExtraDeclaration\";\nconst shader = `varying vec3 vPositionW;\n#if DEBUGMODE>0\nvarying vec4 vClipSpacePosition;\n#endif\n#include[1..7]\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#endif\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrFragmentExtraDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"samplerFragmentAlternateDeclaration\";\nconst shader = `#ifdef _DEFINENAME_\n#if _DEFINENAME_DIRECTUV==1\n#define v_VARYINGNAME_UV vMainUV1\n#elif _DEFINENAME_DIRECTUV==2\n#define v_VARYINGNAME_UV vMainUV2\n#elif _DEFINENAME_DIRECTUV==3\n#define v_VARYINGNAME_UV vMainUV3\n#elif _DEFINENAME_DIRECTUV==4\n#define v_VARYINGNAME_UV vMainUV4\n#elif _DEFINENAME_DIRECTUV==5\n#define v_VARYINGNAME_UV vMainUV5\n#elif _DEFINENAME_DIRECTUV==6\n#define v_VARYINGNAME_UV vMainUV6\n#else\nvarying vec2 v_VARYINGNAME_UV;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const samplerFragmentAlternateDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./samplerFragmentDeclaration\";\nimport \"./samplerFragmentAlternateDeclaration\";\n\nconst name = \"pbrFragmentSamplersDeclaration\";\nconst shader = `#include(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo,_SAMPLERNAME_,albedo)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)\n#include(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity,_SAMPLERNAME_,reflectivity)\n#include(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler,_SAMPLERNAME_,microSurface)\n#include(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance,_SAMPLERNAME_,metallicReflectance)\n#include(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance,_SAMPLERNAME_,reflectance)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)\n#ifdef CLEARCOAT\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat,_SAMPLERNAME_,clearCoat)\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness)\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL)\nuniform sampler2D clearCoatRoughnessSampler;\n#endif\n#include(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump,_SAMPLERNAME_,clearCoatBump)\n#include(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint,_SAMPLERNAME_,clearCoatTint)\n#endif\n#ifdef IRIDESCENCE\n#include(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence,_SAMPLERNAME_,iridescence)\n#include(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness,_SAMPLERNAME_,iridescenceThickness)\n#endif\n#ifdef SHEEN\n#include(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen,_SAMPLERNAME_,sheen)\n#include(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness)\n#if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL)\nuniform sampler2D sheenRoughnessSampler;\n#endif\n#endif\n#ifdef ANISOTROPIC\n#include(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy,_SAMPLERNAME_,anisotropy)\n#endif\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;\n#endif\n#ifdef USEIRRADIANCEMAP\nuniform samplerCube irradianceSampler;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform sampler2D reflectionSamplerLow;uniform sampler2D reflectionSamplerHigh;\n#endif\n#ifdef USEIRRADIANCEMAP\nuniform sampler2D irradianceSampler;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#endif\n#ifdef ENVIRONMENTBRDF\nuniform sampler2D environmentBrdfSampler;\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\n#ifdef SS_REFRACTIONMAP_3D\n#define sampleRefraction(s,c) textureCube(s,c)\nuniform samplerCube refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube refractionSamplerLow;uniform samplerCube refractionSamplerHigh;\n#endif\n#else\n#define sampleRefraction(s,c) texture2D(s,c)\nuniform sampler2D refractionSampler;\n#ifdef LODBASEDMICROSFURACE\n#define sampleRefractionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform sampler2D refractionSamplerLow;uniform sampler2D refractionSamplerHigh;\n#endif\n#endif\n#endif\n#include(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness,_SAMPLERNAME_,thickness)\n#include(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity,_SAMPLERNAME_,refractionIntensity)\n#include(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity,_SAMPLERNAME_,translucencyIntensity)\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrFragmentSamplersDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"subSurfaceScatteringFunctions\";\nconst shader = `bool testLightingForSSS(float diffusionProfile)\n{return diffusionProfile<1.;}`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const subSurfaceScatteringFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"importanceSampling\";\nconst shader = `vec3 hemisphereCosSample(vec2 u) {float phi=2.*PI*u.x;float cosTheta2=1.-u.y;float cosTheta=sqrt(cosTheta2);float sinTheta=sqrt(1.-cosTheta2);return vec3(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}\nvec3 hemisphereImportanceSampleDggx(vec2 u,float a) {float phi=2.*PI*u.x;float cosTheta2=(1.-u.y)/(1.+(a+1.)*((a-1.)*u.y));float cosTheta=sqrt(cosTheta2);float sinTheta=sqrt(1.-cosTheta2);return vec3(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}\nvec3 hemisphereImportanceSampleDCharlie(vec2 u,float a) { \nfloat phi=2.*PI*u.x;float sinTheta=pow(u.y,a/(2.*a+1.));float cosTheta=sqrt(1.-sinTheta*sinTheta);return vec3(sinTheta*cos(phi),sinTheta*sin(phi),cosTheta);}`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const importanceSampling = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrHelperFunctions\";\nconst shader = `#define RECIPROCAL_PI2 0.15915494\n#define RECIPROCAL_PI 0.31830988618\n#define MINIMUMVARIANCE 0.0005\nfloat convertRoughnessToAverageSlope(float roughness)\n{return square(roughness)+MINIMUMVARIANCE;}\nfloat fresnelGrazingReflectance(float reflectance0) {float reflectance90=saturate(reflectance0*25.0);return reflectance90;}\nvec2 getAARoughnessFactors(vec3 normalVector) {\n#ifdef SPECULARAA\nvec3 nDfdx=dFdx(normalVector.xyz);vec3 nDfdy=dFdy(normalVector.xyz);float slopeSquare=max(dot(nDfdx,nDfdx),dot(nDfdy,nDfdy));float geometricRoughnessFactor=pow(saturate(slopeSquare),0.333);float geometricAlphaGFactor=sqrt(slopeSquare);geometricAlphaGFactor*=0.75;return vec2(geometricRoughnessFactor,geometricAlphaGFactor);\n#else\nreturn vec2(0.);\n#endif\n}\n#ifdef ANISOTROPIC\n#ifdef ANISOTROPIC_LEGACY\nvec2 getAnisotropicRoughness(float alphaG,float anisotropy) {float alphaT=max(alphaG*(1.0+anisotropy),MINIMUMVARIANCE);float alphaB=max(alphaG*(1.0-anisotropy),MINIMUMVARIANCE);return vec2(alphaT,alphaB);}\nvec3 getAnisotropicBentNormals(const vec3 T,const vec3 B,const vec3 N,const vec3 V,float anisotropy,float roughness) {vec3 anisotropicFrameDirection=anisotropy>=0.0 ? B : T;vec3 anisotropicFrameTangent=cross(normalize(anisotropicFrameDirection),V);vec3 anisotropicFrameNormal=cross(anisotropicFrameTangent,anisotropicFrameDirection);vec3 anisotropicNormal=normalize(mix(N,anisotropicFrameNormal,abs(anisotropy)));return anisotropicNormal;}\n#else\nvec2 getAnisotropicRoughness(float alphaG,float anisotropy) {float alphaT=max(mix(alphaG,1.0,anisotropy*anisotropy),MINIMUMVARIANCE);float alphaB=max(alphaG,MINIMUMVARIANCE);return vec2(alphaT,alphaB);}\nvec3 getAnisotropicBentNormals(const vec3 T,const vec3 B,const vec3 N,const vec3 V,float anisotropy,float roughness) {vec3 bentNormal=cross(B,V);bentNormal=normalize(cross(bentNormal,B));float a=square(square(1.0-anisotropy*(1.0-roughness)));bentNormal=normalize(mix(bentNormal,N,a));return bentNormal;}\n#endif\n#endif\n#if defined(CLEARCOAT) || defined(SS_REFRACTION)\nvec3 cocaLambert(vec3 alpha,float distance) {return exp(-alpha*distance);}\nvec3 cocaLambert(float NdotVRefract,float NdotLRefract,vec3 alpha,float thickness) {return cocaLambert(alpha,(thickness*((NdotLRefract+NdotVRefract)/(NdotLRefract*NdotVRefract))));}\nvec3 computeColorAtDistanceInMedia(vec3 color,float distance) {return -log(color)/distance;}\nvec3 computeClearCoatAbsorption(float NdotVRefract,float NdotLRefract,vec3 clearCoatColor,float clearCoatThickness,float clearCoatIntensity) {vec3 clearCoatAbsorption=mix(vec3(1.0),\ncocaLambert(NdotVRefract,NdotLRefract,clearCoatColor,clearCoatThickness),\nclearCoatIntensity);return clearCoatAbsorption;}\n#endif\n#ifdef MICROSURFACEAUTOMATIC\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{const float kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;float reflectivityLuminance=getLuminance(reflectivityColor);float reflectivityLuma=sqrt(reflectivityLuminance);microSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;return microSurface;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrHelperFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"harmonicsFunctions\";\nconst shader = `#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nvec3 computeEnvironmentIrradiance(vec3 normal) {return vSphericalL00\n+ vSphericalL1_1*(normal.y)\n+ vSphericalL10*(normal.z)\n+ vSphericalL11*(normal.x)\n+ vSphericalL2_2*(normal.y*normal.x)\n+ vSphericalL2_1*(normal.y*normal.z)\n+ vSphericalL20*((3.0*normal.z*normal.z)-1.0)\n+ vSphericalL21*(normal.z*normal.x)\n+ vSphericalL22*(normal.x*normal.x-(normal.y*normal.y));}\n#else\nvec3 computeEnvironmentIrradiance(vec3 normal) {float Nx=normal.x;float Ny=normal.y;float Nz=normal.z;vec3 C1=vSphericalZZ.rgb;vec3 Cx=vSphericalX.rgb;vec3 Cy=vSphericalY.rgb;vec3 Cz=vSphericalZ.rgb;vec3 Cxx_zz=vSphericalXX_ZZ.rgb;vec3 Cyy_zz=vSphericalYY_ZZ.rgb;vec3 Cxy=vSphericalXY.rgb;vec3 Cyz=vSphericalYZ.rgb;vec3 Czx=vSphericalZX.rgb;vec3 a1=Cyy_zz*Ny+Cy;vec3 a2=Cyz*Nz+a1;vec3 b1=Czx*Nz+Cx;vec3 b2=Cxy*Ny+b1;vec3 b3=Cxx_zz*Nx+b2;vec3 t1=Cz *Nz+C1;vec3 t2=a2 *Ny+t1;vec3 t3=b3 *Nx+t2;return t3;}\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const harmonicsFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrDirectLightingSetupFunctions\";\nconst shader = `struct preLightingInfo\n{vec3 lightOffset;float lightDistanceSquared;float lightDistance;float attenuation;vec3 L;vec3 H;float NdotV;float NdotLUnclamped;float NdotL;float VdotH;float roughness;\n#ifdef IRIDESCENCE\nfloat iridescenceIntensity;\n#endif\n};preLightingInfo computePointAndSpotPreLightingInfo(vec4 lightData,vec3 V,vec3 N) {preLightingInfo result;result.lightOffset=lightData.xyz-vPositionW;result.lightDistanceSquared=dot(result.lightOffset,result.lightOffset);result.lightDistance=sqrt(result.lightDistanceSquared);result.L=normalize(result.lightOffset);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);return result;}\npreLightingInfo computeDirectionalPreLightingInfo(vec4 lightData,vec3 V,vec3 N) {preLightingInfo result;result.lightDistance=length(-lightData.xyz);result.L=normalize(-lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);return result;}\npreLightingInfo computeHemisphericPreLightingInfo(vec4 lightData,vec3 V,vec3 N) {preLightingInfo result;result.NdotL=dot(N,lightData.xyz)*0.5+0.5;result.NdotL=saturateEps(result.NdotL);result.NdotLUnclamped=result.NdotL;\n#ifdef SPECULARTERM\nresult.L=normalize(lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));\n#endif\nreturn result;}`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrDirectLightingSetupFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrDirectLightingFalloffFunctions\";\nconst shader = `float computeDistanceLightFalloff_Standard(vec3 lightOffset,float range)\n{return max(0.,1.0-length(lightOffset)/range);}\nfloat computeDistanceLightFalloff_Physical(float lightDistanceSquared)\n{return 1.0/maxEps(lightDistanceSquared);}\nfloat computeDistanceLightFalloff_GLTF(float lightDistanceSquared,float inverseSquaredRange)\n{float lightDistanceFalloff=1.0/maxEps(lightDistanceSquared);float factor=lightDistanceSquared*inverseSquaredRange;float attenuation=saturate(1.0-factor*factor);attenuation*=attenuation;lightDistanceFalloff*=attenuation;return lightDistanceFalloff;}\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range,float inverseSquaredRange)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nreturn computeDistanceLightFalloff_Physical(lightDistanceSquared);\n#elif defined(USEGLTFLIGHTFALLOFF)\nreturn computeDistanceLightFalloff_GLTF(lightDistanceSquared,inverseSquaredRange);\n#else\nreturn computeDistanceLightFalloff_Standard(lightOffset,range);\n#endif\n}\nfloat computeDirectionalLightFalloff_Standard(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent)\n{float falloff=0.0;float cosAngle=maxEps(dot(-lightDirection,directionToLightCenterW));if (cosAngle>=cosHalfAngle)\n{falloff=max(0.,pow(cosAngle,exponent));}\nreturn falloff;}\nfloat computeDirectionalLightFalloff_Physical(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle)\n{const float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);vec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);float falloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));return falloff;}\nfloat computeDirectionalLightFalloff_GLTF(vec3 lightDirection,vec3 directionToLightCenterW,float lightAngleScale,float lightAngleOffset)\n{float cd=dot(-lightDirection,directionToLightCenterW);float falloff=saturate(cd*lightAngleScale+lightAngleOffset);falloff*=falloff;return falloff;}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent,float lightAngleScale,float lightAngleOffset)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nreturn computeDirectionalLightFalloff_Physical(lightDirection,directionToLightCenterW,cosHalfAngle);\n#elif defined(USEGLTFLIGHTFALLOFF)\nreturn computeDirectionalLightFalloff_GLTF(lightDirection,directionToLightCenterW,lightAngleScale,lightAngleOffset);\n#else\nreturn computeDirectionalLightFalloff_Standard(lightDirection,directionToLightCenterW,cosHalfAngle,exponent);\n#endif\n}`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrDirectLightingFalloffFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBRDFFunctions\";\nconst shader = `#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n#ifdef MS_BRDF_ENERGY_CONSERVATION\nvec3 getEnergyConservationFactor(const vec3 specularEnvironmentR0,const vec3 environmentBrdf) {return 1.0+specularEnvironmentR0*(1.0/environmentBrdf.y-1.0);}\n#endif\n#ifdef ENVIRONMENTBRDF\nvec3 getBRDFLookup(float NdotV,float perceptualRoughness) {vec2 UV=vec2(NdotV,perceptualRoughness);vec4 brdfLookup=texture2D(environmentBrdfSampler,UV);\n#ifdef ENVIRONMENTBRDF_RGBD\nbrdfLookup.rgb=fromRGBD(brdfLookup.rgba);\n#endif\nreturn brdfLookup.rgb;}\nvec3 getReflectanceFromBRDFLookup(const vec3 specularEnvironmentR0,const vec3 specularEnvironmentR90,const vec3 environmentBrdf) {\n#ifdef BRDF_V_HEIGHT_CORRELATED\nvec3 reflectance=(specularEnvironmentR90-specularEnvironmentR0)*environmentBrdf.x+specularEnvironmentR0*environmentBrdf.y;\n#else\nvec3 reflectance=specularEnvironmentR0*environmentBrdf.x+specularEnvironmentR90*environmentBrdf.y;\n#endif\nreturn reflectance;}\nvec3 getReflectanceFromBRDFLookup(const vec3 specularEnvironmentR0,const vec3 environmentBrdf) {\n#ifdef BRDF_V_HEIGHT_CORRELATED\nvec3 reflectance=mix(environmentBrdf.xxx,environmentBrdf.yyy,specularEnvironmentR0);\n#else\nvec3 reflectance=specularEnvironmentR0*environmentBrdf.x+environmentBrdf.y;\n#endif\nreturn reflectance;}\n#endif\n/* NOT USED\n#if defined(SHEEN) && defined(SHEEN_SOFTER)\nfloat getBRDFLookupCharlieSheen(float NdotV,float perceptualRoughness)\n{float c=1.0-NdotV;float c3=c*c*c;return 0.65584461*c3+1.0/(4.16526551+exp(-7.97291361*perceptualRoughness+6.33516894));}\n#endif\n*/\n#if !defined(ENVIRONMENTBRDF) || defined(REFLECTIONMAP_SKYBOX) || defined(ALPHAFRESNEL)\nvec3 getReflectanceFromAnalyticalBRDFLookup_Jones(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{float weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);return reflectance0+weight*(reflectance90-reflectance0)*pow5(saturate(1.0-VdotN));}\n#endif\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF)\n/**\n* The sheen BRDF not containing F can be easily stored in the blue channel of the BRDF texture.\n* The blue channel contains DCharlie*VAshikhmin*NdotL as a lokkup table\n*/\nvec3 getSheenReflectanceFromBRDFLookup(const vec3 reflectance0,const vec3 environmentBrdf) {vec3 sheenEnvironmentReflectance=reflectance0*environmentBrdf.b;return sheenEnvironmentReflectance;}\n#endif\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{return reflectance0+(reflectance90-reflectance0)*pow5(1.0-VdotH);}\nfloat fresnelSchlickGGX(float VdotH,float reflectance0,float reflectance90)\n{return reflectance0+(reflectance90-reflectance0)*pow5(1.0-VdotH);}\n#ifdef CLEARCOAT\nvec3 getR0RemappedForClearCoat(vec3 f0) {\n#ifdef CLEARCOAT_DEFAULTIOR\n#ifdef MOBILE\nreturn saturate(f0*(f0*0.526868+0.529324)-0.0482256);\n#else\nreturn saturate(f0*(f0*(0.941892-0.263008*f0)+0.346479)-0.0285998);\n#endif\n#else\nvec3 s=sqrt(f0);vec3 t=(vClearCoatRefractionParams.z+vClearCoatRefractionParams.w*s)/(vClearCoatRefractionParams.w+vClearCoatRefractionParams.z*s);return square(t);\n#endif\n}\n#endif\n#ifdef IRIDESCENCE\nconst mat3 XYZ_TO_REC709=mat3(\n3.2404542,-0.9692660, 0.0556434,\n-1.5371385, 1.8760108,-0.2040259,\n-0.4985314, 0.0415560, 1.0572252\n);vec3 getIORTfromAirToSurfaceR0(vec3 f0) {vec3 sqrtF0=sqrt(f0);return (1.+sqrtF0)/(1.-sqrtF0);}\nvec3 getR0fromIORs(vec3 iorT,float iorI) {return square((iorT-vec3(iorI))/(iorT+vec3(iorI)));}\nfloat getR0fromIORs(float iorT,float iorI) {return square((iorT-iorI)/(iorT+iorI));}\nvec3 evalSensitivity(float opd,vec3 shift) {float phase=2.0*PI*opd*1.0e-9;const vec3 val=vec3(5.4856e-13,4.4201e-13,5.2481e-13);const vec3 pos=vec3(1.6810e+06,1.7953e+06,2.2084e+06);const vec3 var=vec3(4.3278e+09,9.3046e+09,6.6121e+09);vec3 xyz=val*sqrt(2.0*PI*var)*cos(pos*phase+shift)*exp(-square(phase)*var);xyz.x+=9.7470e-14*sqrt(2.0*PI*4.5282e+09)*cos(2.2399e+06*phase+shift[0])*exp(-4.5282e+09*square(phase));xyz/=1.0685e-7;vec3 srgb=XYZ_TO_REC709*xyz;return srgb;}\nvec3 evalIridescence(float outsideIOR,float eta2,float cosTheta1,float thinFilmThickness,vec3 baseF0) {vec3 I=vec3(1.0);float iridescenceIOR=mix(outsideIOR,eta2,smoothstep(0.0,0.03,thinFilmThickness));float sinTheta2Sq=square(outsideIOR/iridescenceIOR)*(1.0-square(cosTheta1));float cosTheta2Sq=1.0-sinTheta2Sq;if (cosTheta2Sq<0.0) {return I;}\nfloat cosTheta2=sqrt(cosTheta2Sq);float R0=getR0fromIORs(iridescenceIOR,outsideIOR);float R12=fresnelSchlickGGX(cosTheta1,R0,1.);float R21=R12;float T121=1.0-R12;float phi12=0.0;if (iridescenceIOR0\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nfloat radicalInverse_VdC(uint bits) \n{bits=(bits<<16u) | (bits>>16u);bits=((bits & 0x55555555u)<<1u) | ((bits & 0xAAAAAAAAu)>>1u);bits=((bits & 0x33333333u)<<2u) | ((bits & 0xCCCCCCCCu)>>2u);bits=((bits & 0x0F0F0F0Fu)<<4u) | ((bits & 0xF0F0F0F0u)>>4u);bits=((bits & 0x00FF00FFu)<<8u) | ((bits & 0xFF00FF00u)>>8u);return float(bits)*2.3283064365386963e-10; }\nvec2 hammersley(uint i,uint N)\n{return vec2(float(i)/float(N),radicalInverse_VdC(i));}\n#else\nfloat vanDerCorpus(int n,int base)\n{float invBase=1.0/float(base);float denom =1.0;float result =0.0;for(int i=0; i<32; ++i)\n{if(n>0)\n{denom =mod(float(n),2.0);result+=denom*invBase;invBase=invBase/2.0;n =int(float(n)/2.0);}}\nreturn result;}\nvec2 hammersley(int i,int N)\n{return vec2(float(i)/float(N),vanDerCorpus(i,2));}\n#endif\nfloat log4(float x) {return log2(x)/2.;}\nconst float NUM_SAMPLES_FLOAT=float(NUM_SAMPLES);const float NUM_SAMPLES_FLOAT_INVERSED=1./NUM_SAMPLES_FLOAT;const float K=4.;\n#define inline\nvec3 irradiance(samplerCube inputTexture,vec3 inputN,vec2 filteringInfo)\n{vec3 n=normalize(inputN);vec3 result=vec3(0.0);vec3 tangent=abs(n.z)<0.999 ? vec3(0.,0.,1.) : vec3(1.,0.,0.);tangent=normalize(cross(tangent,n));vec3 bitangent=cross(n,tangent);mat3 tbn=mat3(tangent,bitangent,n);float maxLevel=filteringInfo.y;float dim0=filteringInfo.x;float omegaP=(4.*PI)/(6.*dim0*dim0);\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nfor(uint i=0u; i0.) {float pdf_inversed=PI/NoL;float omegaS=NUM_SAMPLES_FLOAT_INVERSED*pdf_inversed;float l=log4(omegaS)-log4(omegaP)+log4(K);float mipLevel=clamp(l,0.0,maxLevel);vec3 c=textureCubeLodEXT(inputTexture,tbn*Ls,mipLevel).rgb;\n#ifdef GAMMA_INPUT\nc=toLinearSpace(c);\n#endif\nresult+=c;}}\nresult=result*NUM_SAMPLES_FLOAT_INVERSED;return result;}\n#define inline\nvec3 radiance(float alphaG,samplerCube inputTexture,vec3 inputN,vec2 filteringInfo)\n{vec3 n=normalize(inputN);if (alphaG==0.) {vec3 c=textureCube(inputTexture,n).rgb;\n#ifdef GAMMA_INPUT\nc=toLinearSpace(c);\n#endif\nreturn c;} else {vec3 result=vec3(0.);vec3 tangent=abs(n.z)<0.999 ? vec3(0.,0.,1.) : vec3(1.,0.,0.);tangent=normalize(cross(tangent,n));vec3 bitangent=cross(n,tangent);mat3 tbn=mat3(tangent,bitangent,n);float maxLevel=filteringInfo.y;float dim0=filteringInfo.x;float omegaP=(4.*PI)/(6.*dim0*dim0);float weight=0.;\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nfor(uint i=0u; i0.) {float pdf_inversed=4./normalDistributionFunction_TrowbridgeReitzGGX(NoH,alphaG);float omegaS=NUM_SAMPLES_FLOAT_INVERSED*pdf_inversed;float l=log4(omegaS)-log4(omegaP)+log4(K);float mipLevel=clamp(float(l),0.0,maxLevel);weight+=NoL;vec3 c=textureCubeLodEXT(inputTexture,tbn*L,mipLevel).rgb;\n#ifdef GAMMA_INPUT\nc=toLinearSpace(c);\n#endif\nresult+=c*NoL;}}\nresult=result/weight;return result;}}\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const hdrFilteringFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrDirectLightingFunctions\";\nconst shader = `#define CLEARCOATREFLECTANCE90 1.0\nstruct lightingInfo\n{vec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef CLEARCOAT\nvec4 clearCoat;\n#endif\n#ifdef SHEEN\nvec3 sheen;\n#endif\n};float adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance) {\n#if defined(USEPHYSICALLIGHTFALLOFF) || defined(USEGLTFLIGHTFALLOFF)\nfloat lightRoughness=lightRadius/lightDistance;float totalRoughness=saturate(lightRoughness+roughness);return totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nvec3 computeHemisphericDiffuseLighting(preLightingInfo info,vec3 lightColor,vec3 groundColor) {return mix(groundColor,lightColor,info.NdotL);}\nvec3 computeDiffuseLighting(preLightingInfo info,vec3 lightColor) {float diffuseTerm=diffuseBRDF_Burley(info.NdotL,info.NdotV,info.VdotH,info.roughness);return diffuseTerm*info.attenuation*info.NdotL*lightColor;}\n#define inline\nvec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);strq/=strq.w;vec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;return toLinearSpace(textureColor);}\n#ifdef SS_TRANSLUCENCY\nvec3 computeDiffuseAndTransmittedLighting(preLightingInfo info,vec3 lightColor,vec3 transmittance) {float NdotL=absEps(info.NdotLUnclamped);float wrapNdotL=computeWrappedDiffuseNdotL(NdotL,0.02);float trAdapt=step(0.,info.NdotLUnclamped);vec3 transmittanceNdotL=mix(transmittance*wrapNdotL,vec3(wrapNdotL),trAdapt);float diffuseTerm=diffuseBRDF_Burley(NdotL,info.NdotV,info.VdotH,info.roughness);return diffuseTerm*transmittanceNdotL*info.attenuation*lightColor;}\n#endif\n#ifdef SPECULARTERM\nvec3 computeSpecularLighting(preLightingInfo info,vec3 N,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,vec3 lightColor) {float NdotH=saturateEps(dot(N,info.H));float roughness=max(info.roughness,geometricRoughnessFactor);float alphaG=convertRoughnessToAverageSlope(roughness);vec3 fresnel=fresnelSchlickGGX(info.VdotH,reflectance0,reflectance90);\n#ifdef IRIDESCENCE\nfresnel=mix(fresnel,reflectance0,info.iridescenceIntensity);\n#endif\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\n#ifdef BRDF_V_HEIGHT_CORRELATED\nfloat smithVisibility=smithVisibility_GGXCorrelated(info.NdotL,info.NdotV,alphaG);\n#else\nfloat smithVisibility=smithVisibility_TrowbridgeReitzGGXFast(info.NdotL,info.NdotV,alphaG);\n#endif\nvec3 specTerm=fresnel*distribution*smithVisibility;return specTerm*info.attenuation*info.NdotL*lightColor;}\n#endif\n#ifdef ANISOTROPIC\nvec3 computeAnisotropicSpecularLighting(preLightingInfo info,vec3 V,vec3 N,vec3 T,vec3 B,float anisotropy,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,vec3 lightColor) {float NdotH=saturateEps(dot(N,info.H));float TdotH=dot(T,info.H);float BdotH=dot(B,info.H);float TdotV=dot(T,V);float BdotV=dot(B,V);float TdotL=dot(T,info.L);float BdotL=dot(B,info.L);float alphaG=convertRoughnessToAverageSlope(info.roughness);vec2 alphaTB=getAnisotropicRoughness(alphaG,anisotropy);alphaTB=max(alphaTB,square(geometricRoughnessFactor));vec3 fresnel=fresnelSchlickGGX(info.VdotH,reflectance0,reflectance90);\n#ifdef IRIDESCENCE\nfresnel=mix(fresnel,reflectance0,info.iridescenceIntensity);\n#endif\nfloat distribution=normalDistributionFunction_BurleyGGX_Anisotropic(NdotH,TdotH,BdotH,alphaTB);float smithVisibility=smithVisibility_GGXCorrelated_Anisotropic(info.NdotL,info.NdotV,TdotV,BdotV,TdotL,BdotL,alphaTB);vec3 specTerm=fresnel*distribution*smithVisibility;return specTerm*info.attenuation*info.NdotL*lightColor;}\n#endif\n#ifdef CLEARCOAT\nvec4 computeClearCoatLighting(preLightingInfo info,vec3 Ncc,float geometricRoughnessFactor,float clearCoatIntensity,vec3 lightColor) {float NccdotL=saturateEps(dot(Ncc,info.L));float NccdotH=saturateEps(dot(Ncc,info.H));float clearCoatRoughness=max(info.roughness,geometricRoughnessFactor);float alphaG=convertRoughnessToAverageSlope(clearCoatRoughness);float fresnel=fresnelSchlickGGX(info.VdotH,vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnel*=clearCoatIntensity;float distribution=normalDistributionFunction_TrowbridgeReitzGGX(NccdotH,alphaG);float kelemenVisibility=visibility_Kelemen(info.VdotH);float clearCoatTerm=fresnel*distribution*kelemenVisibility;return vec4(\nclearCoatTerm*info.attenuation*NccdotL*lightColor,\n1.0-fresnel\n);}\nvec3 computeClearCoatLightingAbsorption(float NdotVRefract,vec3 L,vec3 Ncc,vec3 clearCoatColor,float clearCoatThickness,float clearCoatIntensity) {vec3 LRefract=-refract(L,Ncc,vClearCoatRefractionParams.y);float NdotLRefract=saturateEps(dot(Ncc,LRefract));vec3 absorption=computeClearCoatAbsorption(NdotVRefract,NdotLRefract,clearCoatColor,clearCoatThickness,clearCoatIntensity);return absorption;}\n#endif\n#ifdef SHEEN\nvec3 computeSheenLighting(preLightingInfo info,vec3 N,vec3 reflectance0,vec3 reflectance90,float geometricRoughnessFactor,vec3 lightColor) {float NdotH=saturateEps(dot(N,info.H));float roughness=max(info.roughness,geometricRoughnessFactor);float alphaG=convertRoughnessToAverageSlope(roughness);float fresnel=1.;float distribution=normalDistributionFunction_CharlieSheen(NdotH,alphaG);/*#ifdef SHEEN_SOFTER\nfloat visibility=visibility_CharlieSheen(info.NdotL,info.NdotV,alphaG);\n#else */\nfloat visibility=visibility_Ashikhmin(info.NdotL,info.NdotV);/* #endif */\nfloat sheenTerm=fresnel*distribution*visibility;return sheenTerm*info.attenuation*info.NdotL*lightColor;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrDirectLightingFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrIBLFunctions\";\nconst shader = `#if defined(REFLECTION) || defined(SS_REFRACTION)\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float microsurfaceAverageSlope) {float microsurfaceAverageSlopeTexels=cubeMapDimensionPixels*microsurfaceAverageSlope;float lod=log2(microsurfaceAverageSlopeTexels);return lod;}\nfloat getLinearLodFromRoughness(float cubeMapDimensionPixels,float roughness) {float lod=log2(cubeMapDimensionPixels)*roughness;return lod;}\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(RADIANCEOCCLUSION)\nfloat environmentRadianceOcclusion(float ambientOcclusion,float NdotVUnclamped) {float temp=NdotVUnclamped+ambientOcclusion;return saturate(square(temp)-1.0+ambientOcclusion);}\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(HORIZONOCCLUSION)\nfloat environmentHorizonOcclusion(vec3 view,vec3 normal,vec3 geometricNormal) {vec3 reflection=reflect(view,normal);float temp=saturate(1.0+1.1*dot(reflection,geometricNormal));return square(temp);}\n#endif\n#if defined(LODINREFLECTIONALPHA) || defined(SS_LODINREFRACTIONALPHA)\n#define UNPACK_LOD(x) (1.0-x)*255.0\nfloat getLodFromAlphaG(float cubeMapDimensionPixels,float alphaG,float NdotV) {float microsurfaceAverageSlope=alphaG;microsurfaceAverageSlope*=sqrt(abs(NdotV));return getLodFromAlphaG(cubeMapDimensionPixels,microsurfaceAverageSlope);}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrIBLFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalFragment\";\n\nconst name = \"pbrBlockAlbedoOpacity\";\nconst shader = `struct albedoOpacityOutParams\n{vec3 surfaceAlbedo;float alpha;};\n#define pbr_inline\nvoid albedoOpacityBlock(\nin vec4 vAlbedoColor,\n#ifdef ALBEDO\nin vec4 albedoTexture,\nin vec2 albedoInfos,\n#endif\n#ifdef OPACITY\nin vec4 opacityMap,\nin vec2 vOpacityInfos,\n#endif\n#ifdef DETAIL\nin vec4 detailColor,\nin vec4 vDetailInfos,\n#endif\n#ifdef DECAL\nin vec4 decalColor,\nin vec4 vDecalInfos,\n#endif\nout albedoOpacityOutParams outParams\n)\n{vec3 surfaceAlbedo=vAlbedoColor.rgb;float alpha=vAlbedoColor.a;\n#ifdef ALBEDO\n#if defined(ALPHAFROMALBEDO) || defined(ALPHATEST)\nalpha*=albedoTexture.a;\n#endif\n#ifdef GAMMAALBEDO\nsurfaceAlbedo*=toLinearSpace(albedoTexture.rgb);\n#else\nsurfaceAlbedo*=albedoTexture.rgb;\n#endif\nsurfaceAlbedo*=albedoInfos.y;\n#endif\n#ifndef DECAL_AFTER_DETAIL\n#include\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nsurfaceAlbedo*=vColor.rgb;\n#endif\n#ifdef DETAIL\nfloat detailAlbedo=2.0*mix(0.5,detailColor.r,vDetailInfos.y);surfaceAlbedo.rgb=surfaceAlbedo.rgb*detailAlbedo*detailAlbedo; \n#endif\n#ifdef DECAL_AFTER_DETAIL\n#include\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_ALBEDO\n#ifdef OPACITY\n#ifdef OPACITYRGB\nalpha=getLuminance(opacityMap.rgb);\n#else\nalpha*=opacityMap.a;\n#endif\nalpha*=vOpacityInfos.y;\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#if !defined(SS_LINKREFRACTIONTOTRANSPARENCY) && !defined(ALPHAFRESNEL)\n#ifdef ALPHATEST \n#if DEBUGMODE != 88\nif (alpha0\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness;\n#ifdef REFLECTIVITY\nvec4 surfaceMetallicColorMap;\n#endif\n#ifndef FROSTBITE_REFLECTANCE\nvec3 metallicF0;\n#endif\n#else\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap;\n#endif\n#endif\n#endif\n};\n#define pbr_inline\nvoid reflectivityBlock(\nin vec4 vReflectivityColor,\n#ifdef METALLICWORKFLOW\nin vec3 surfaceAlbedo,\nin vec4 metallicReflectanceFactors,\n#endif\n#ifdef REFLECTIVITY\nin vec3 reflectivityInfos,\nin vec4 surfaceMetallicOrReflectivityColorMap,\n#endif\n#if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)\nin vec3 ambientOcclusionColorIn,\n#endif\n#ifdef MICROSURFACEMAP\nin vec4 microSurfaceTexel,\n#endif\n#ifdef DETAIL\nin vec4 detailColor,\nin vec4 vDetailInfos,\n#endif\nout reflectivityOutParams outParams\n)\n{float microSurface=vReflectivityColor.a;vec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef REFLECTIVITY\n#if DEBUGMODE>0\noutParams.surfaceMetallicColorMap=surfaceMetallicOrReflectivityColorMap;\n#endif\n#ifdef AOSTOREINMETALMAPRED\nvec3 aoStoreInMetalMap=vec3(surfaceMetallicOrReflectivityColorMap.r,surfaceMetallicOrReflectivityColorMap.r,surfaceMetallicOrReflectivityColorMap.r);outParams.ambientOcclusionColor=mix(ambientOcclusionColorIn,aoStoreInMetalMap,reflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicOrReflectivityColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicOrReflectivityColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicOrReflectivityColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicOrReflectivityColorMap.g;\n#endif\n#endif\n#endif\n#ifdef DETAIL\nfloat detailRoughness=mix(0.5,detailColor.b,vDetailInfos.w);float loLerp=mix(0.,metallicRoughness.g,detailRoughness*2.);float hiLerp=mix(metallicRoughness.g,1.,(detailRoughness-0.5)*2.);metallicRoughness.g=mix(loLerp,hiLerp,step(detailRoughness,0.5));\n#endif\n#ifdef MICROSURFACEMAP\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n#if DEBUGMODE>0\noutParams.metallicRoughness=metallicRoughness;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS\nmicroSurface=1.0-metallicRoughness.g;vec3 baseColor=surfaceAlbedo;\n#ifdef FROSTBITE_REFLECTANCE\noutParams.surfaceAlbedo=baseColor.rgb*(1.0-metallicRoughness.r);surfaceReflectivityColor=mix(0.16*reflectance*reflectance,baseColor,metallicRoughness.r);\n#else\nvec3 metallicF0=metallicReflectanceFactors.rgb;\n#if DEBUGMODE>0\noutParams.metallicF0=metallicF0;\n#endif\noutParams.surfaceAlbedo=mix(baseColor.rgb*(1.0-metallicF0),vec3(0.,0.,0.),metallicRoughness.r);surfaceReflectivityColor=mix(metallicF0,baseColor,metallicRoughness.r);\n#endif\n#else\n#ifdef REFLECTIVITY\nsurfaceReflectivityColor*=surfaceMetallicOrReflectivityColorMap.rgb;\n#if DEBUGMODE>0\noutParams.surfaceReflectivityColorMap=surfaceMetallicOrReflectivityColorMap;\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface*=surfaceMetallicOrReflectivityColorMap.a;microSurface*=reflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface*=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#ifdef MICROSURFACEMAP\nmicroSurface*=microSurfaceTexel.r;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_MICROSURFACE\n#endif\n#endif\n#endif\nmicroSurface=saturate(microSurface);float roughness=1.-microSurface;outParams.microSurface=microSurface;outParams.roughness=roughness;outParams.surfaceReflectivityColor=surfaceReflectivityColor;}\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockReflectivity = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockAmbientOcclusion\";\nconst shader = `struct ambientOcclusionOutParams\n{vec3 ambientOcclusionColor;\n#if DEBUGMODE>0 && defined(AMBIENT)\nvec3 ambientOcclusionColorMap;\n#endif\n};\n#define pbr_inline\nvoid ambientOcclusionBlock(\n#ifdef AMBIENT\nin vec3 ambientOcclusionColorMap_,\nin vec4 vAmbientInfos,\n#endif\nout ambientOcclusionOutParams outParams\n)\n{vec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=ambientOcclusionColorMap_*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE\nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#if DEBUGMODE>0\noutParams.ambientOcclusionColorMap=ambientOcclusionColorMap;\n#endif\n#endif\noutParams.ambientOcclusionColor=ambientOcclusionColor;}\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockAmbientOcclusion = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockAlphaFresnel\";\nconst shader = `#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\nstruct alphaFresnelOutParams\n{float alpha;};\n#define pbr_inline\nvoid alphaFresnelBlock(\nin vec3 normalW,\nin vec3 viewDirectionW,\nin float alpha,\nin float microSurface,\nout alphaFresnelOutParams outParams\n)\n{float opacityPerceptual=alpha;\n#ifdef LINEARALPHAFRESNEL\nfloat opacity0=opacityPerceptual;\n#else\nfloat opacity0=opacityPerceptual*opacityPerceptual;\n#endif\nfloat opacity90=fresnelGrazingReflectance(opacity0);vec3 normalForward=faceforward(normalW,-viewDirectionW,normalW);outParams.alpha=getReflectanceFromAnalyticalBRDFLookup_Jones(saturate(dot(viewDirectionW,normalForward)),vec3(opacity0),vec3(opacity90),sqrt(microSurface)).x;\n#ifdef ALPHATEST\nif (outParams.alpha0 && defined(ANISOTROPIC_TEXTURE)\nvec3 anisotropyMapData;\n#endif\n};\n#define pbr_inline\nvoid anisotropicBlock(\nin vec3 vAnisotropy,\nin float roughness,\n#ifdef ANISOTROPIC_TEXTURE\nin vec3 anisotropyMapData,\n#endif\nin mat3 TBN,\nin vec3 normalW,\nin vec3 viewDirectionW,\nout anisotropicOutParams outParams\n)\n{float anisotropy=vAnisotropy.b;vec3 anisotropyDirection=vec3(vAnisotropy.xy,0.);\n#ifdef ANISOTROPIC_TEXTURE\nanisotropy*=anisotropyMapData.b;\n#if DEBUGMODE>0\noutParams.anisotropyMapData=anisotropyMapData;\n#endif\nanisotropyMapData.rg=anisotropyMapData.rg*2.0-1.0;\n#ifdef ANISOTROPIC_LEGACY\nanisotropyDirection.rg*=anisotropyMapData.rg;\n#else\nanisotropyDirection.xy=mat2(anisotropyDirection.x,anisotropyDirection.y,-anisotropyDirection.y,anisotropyDirection.x)*normalize(anisotropyMapData.rg);\n#endif\n#endif\nmat3 anisoTBN=mat3(normalize(TBN[0]),normalize(TBN[1]),normalize(TBN[2]));vec3 anisotropicTangent=normalize(anisoTBN*anisotropyDirection);vec3 anisotropicBitangent=normalize(cross(anisoTBN[2],anisotropicTangent));outParams.anisotropy=anisotropy;outParams.anisotropicTangent=anisotropicTangent;outParams.anisotropicBitangent=anisotropicBitangent;outParams.anisotropicNormal=getAnisotropicBentNormals(anisotropicTangent,anisotropicBitangent,normalW,viewDirectionW,anisotropy,roughness);}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockAnisotropic = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockReflection\";\nconst shader = `#ifdef REFLECTION\nstruct reflectionOutParams\n{vec4 environmentRadiance;vec3 environmentIrradiance;\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords;\n#else\nvec2 reflectionCoords;\n#endif\n#ifdef SS_TRANSLUCENCY\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nvec3 irradianceVector;\n#endif\n#endif\n#endif\n};\n#define pbr_inline\nvoid createReflectionCoords(\nin vec3 vPositionW,\nin vec3 normalW,\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#ifdef REFLECTIONMAP_3D\nout vec3 reflectionCoords\n#else\nout vec2 reflectionCoords\n#endif\n)\n{\n#ifdef ANISOTROPIC\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),anisotropicOut.anisotropicNormal);\n#else\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#endif\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\nreflectionCoords=reflectionVector;\n#else\nreflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n}\n#define pbr_inline\n#define inline\nvoid sampleReflectionTexture(\nin float alphaG,\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nin float NdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nin float roughness,\n#endif\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\nconst vec3 reflectionCoords,\n#else\nin sampler2D reflectionSampler,\nconst vec2 reflectionCoords,\n#endif\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\nout vec4 environmentRadiance\n)\n{\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG,NdotVUnclamped);\n#elif defined(LINEARSPECULARREFLECTION)\nfloat reflectionLOD=getLinearLodFromRoughness(vReflectionMicrosurfaceInfos.x,roughness);\n#else\nfloat reflectionLOD=getLodFromAlphaG(vReflectionMicrosurfaceInfos.x,alphaG);\n#endif\n#ifdef LODBASEDMICROSFURACE\nreflectionLOD=reflectionLOD*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\n#ifdef LODINREFLECTIONALPHA\nfloat automaticReflectionLOD=UNPACK_LOD(sampleReflection(reflectionSampler,reflectionCoords).a);float requestedReflectionLOD=max(automaticReflectionLOD,reflectionLOD);\n#else\nfloat requestedReflectionLOD=reflectionLOD;\n#endif\n#ifdef REALTIME_FILTERING\nenvironmentRadiance=vec4(radiance(alphaG,reflectionSampler,reflectionCoords,vReflectionFilteringInfo),1.0);\n#else\nenvironmentRadiance=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);\n#endif\n#else\nfloat lodReflectionNormalized=saturate(reflectionLOD/log2(vReflectionMicrosurfaceInfos.x));float lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;vec4 environmentMid=sampleReflection(reflectionSampler,reflectionCoords);if (lodReflectionNormalizedDoubled<1.0){environmentRadiance=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords),\nenvironmentMid,\nlodReflectionNormalizedDoubled\n);} else {environmentRadiance=mix(\nenvironmentMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords),\nlodReflectionNormalizedDoubled-1.0\n);}\n#endif\n#ifdef RGBDREFLECTION\nenvironmentRadiance.rgb=fromRGBD(environmentRadiance);\n#endif\n#ifdef GAMMAREFLECTION\nenvironmentRadiance.rgb=toLinearSpace(environmentRadiance.rgb);\n#endif\nenvironmentRadiance.rgb*=vReflectionInfos.x;environmentRadiance.rgb*=vReflectionColor.rgb;}\n#define pbr_inline\n#define inline\nvoid reflectionBlock(\nin vec3 vPositionW,\nin vec3 normalW,\nin float alphaG,\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nin float NdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nin float roughness,\n#endif\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\n#else\nin sampler2D reflectionSampler,\n#endif\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nin vec3 vEnvironmentIrradiance,\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nin mat4 reflectionMatrix,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\n#ifdef REFLECTIONMAP_3D\nin samplerCube irradianceSampler,\n#else\nin sampler2D irradianceSampler,\n#endif\n#endif\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\nout reflectionOutParams outParams\n)\n{vec4 environmentRadiance=vec4(0.,0.,0.,0.);\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=vec3(0.);\n#else\nvec2 reflectionCoords=vec2(0.);\n#endif\ncreateReflectionCoords(\nvPositionW,\nnormalW,\n#ifdef ANISOTROPIC\nanisotropicOut,\n#endif\nreflectionCoords\n);sampleReflectionTexture(\nalphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nroughness,\n#endif\n#ifdef REFLECTIONMAP_3D\nreflectionSampler,\nreflectionCoords,\n#else\nreflectionSampler,\nreflectionCoords,\n#endif\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nenvironmentRadiance\n);vec3 environmentIrradiance=vec3(0.,0.,0.);\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nenvironmentIrradiance=vEnvironmentIrradiance;\n#else\n#ifdef ANISOTROPIC\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(anisotropicOut.anisotropicNormal,0)).xyz;\n#else\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#endif\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\n#ifdef INVERTCUBICMAP\nirradianceVector.y*=-1.0;\n#endif\n#if defined(REALTIME_FILTERING)\nenvironmentIrradiance=irradiance(reflectionSampler,irradianceVector,vReflectionFilteringInfo);\n#else\nenvironmentIrradiance=computeEnvironmentIrradiance(irradianceVector);\n#endif\n#ifdef SS_TRANSLUCENCY\noutParams.irradianceVector=irradianceVector;\n#endif\n#endif\n#elif defined(USEIRRADIANCEMAP)\nvec4 environmentIrradiance4=sampleReflection(irradianceSampler,reflectionCoords);environmentIrradiance=environmentIrradiance4.rgb;\n#ifdef RGBDREFLECTION\nenvironmentIrradiance.rgb=fromRGBD(environmentIrradiance4);\n#endif\n#ifdef GAMMAREFLECTION\nenvironmentIrradiance.rgb=toLinearSpace(environmentIrradiance.rgb);\n#endif\n#endif\nenvironmentIrradiance*=vReflectionColor.rgb;outParams.environmentRadiance=environmentRadiance;outParams.environmentIrradiance=environmentIrradiance;outParams.reflectionCoords=reflectionCoords;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockReflection = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockSheen\";\nconst shader = `#ifdef SHEEN\nstruct sheenOutParams\n{float sheenIntensity;vec3 sheenColor;float sheenRoughness;\n#ifdef SHEEN_LINKWITHALBEDO\nvec3 surfaceAlbedo;\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\nfloat sheenAlbedoScaling;\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nvec3 finalSheenRadianceScaled;\n#endif\n#if DEBUGMODE>0\n#ifdef SHEEN_TEXTURE\nvec4 sheenMapData;\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nvec3 sheenEnvironmentReflectance;\n#endif\n#endif\n};\n#define pbr_inline\n#define inline\nvoid sheenBlock(\nin vec4 vSheenColor,\n#ifdef SHEEN_ROUGHNESS\nin float vSheenRoughness,\n#if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)\nin vec4 sheenMapRoughnessData,\n#endif\n#endif\nin float roughness,\n#ifdef SHEEN_TEXTURE\nin vec4 sheenMapData,\nin float sheenMapLevel,\n#endif\nin float reflectance,\n#ifdef SHEEN_LINKWITHALBEDO\nin vec3 baseColor,\nin vec3 surfaceAlbedo,\n#endif\n#ifdef ENVIRONMENTBRDF\nin float NdotV,\nin vec3 environmentBrdf,\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nin vec2 AARoughnessFactors,\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\nin vec4 vLightingIntensity,\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\nin vec3 reflectionCoords,\n#else\nin sampler2D reflectionSampler,\nin vec2 reflectionCoords,\n#endif\nin float NdotVUnclamped,\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)\nin float seo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)\nin float eho,\n#endif\n#endif\nout sheenOutParams outParams\n)\n{float sheenIntensity=vSheenColor.a;\n#ifdef SHEEN_TEXTURE\n#if DEBUGMODE>0\noutParams.sheenMapData=sheenMapData;\n#endif\n#endif\n#ifdef SHEEN_LINKWITHALBEDO\nfloat sheenFactor=pow5(1.0-sheenIntensity);vec3 sheenColor=baseColor.rgb*(1.0-sheenFactor);float sheenRoughness=sheenIntensity;outParams.surfaceAlbedo=surfaceAlbedo*sheenFactor;\n#ifdef SHEEN_TEXTURE\nsheenIntensity*=sheenMapData.a;\n#endif\n#else\nvec3 sheenColor=vSheenColor.rgb;\n#ifdef SHEEN_TEXTURE\n#ifdef SHEEN_GAMMATEXTURE\nsheenColor.rgb*=toLinearSpace(sheenMapData.rgb);\n#else\nsheenColor.rgb*=sheenMapData.rgb;\n#endif\nsheenColor.rgb*=sheenMapLevel;\n#endif\n#ifdef SHEEN_ROUGHNESS\nfloat sheenRoughness=vSheenRoughness;\n#ifdef SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE\n#if defined(SHEEN_TEXTURE)\nsheenRoughness*=sheenMapData.a;\n#endif\n#elif defined(SHEEN_TEXTURE_ROUGHNESS)\n#ifdef SHEEN_TEXTURE_ROUGHNESS_IDENTICAL\nsheenRoughness*=sheenMapData.a;\n#else\nsheenRoughness*=sheenMapRoughnessData.a;\n#endif\n#endif\n#else\nfloat sheenRoughness=roughness;\n#ifdef SHEEN_TEXTURE\nsheenIntensity*=sheenMapData.a;\n#endif\n#endif\n#if !defined(SHEEN_ALBEDOSCALING)\nsheenIntensity*=(1.-reflectance);\n#endif\nsheenColor*=sheenIntensity;\n#endif\n#ifdef ENVIRONMENTBRDF\n/*#ifdef SHEEN_SOFTER\nvec3 environmentSheenBrdf=vec3(0.,0.,getBRDFLookupCharlieSheen(NdotV,sheenRoughness));\n#else*/\n#ifdef SHEEN_ROUGHNESS\nvec3 environmentSheenBrdf=getBRDFLookup(NdotV,sheenRoughness);\n#else\nvec3 environmentSheenBrdf=environmentBrdf;\n#endif\n/*#endif*/\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nfloat sheenAlphaG=convertRoughnessToAverageSlope(sheenRoughness);\n#ifdef SPECULARAA\nsheenAlphaG+=AARoughnessFactors.y;\n#endif\nvec4 environmentSheenRadiance=vec4(0.,0.,0.,0.);sampleReflectionTexture(\nsheenAlphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nsheenRoughness,\n#endif\nreflectionSampler,\nreflectionCoords,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nenvironmentSheenRadiance\n);vec3 sheenEnvironmentReflectance=getSheenReflectanceFromBRDFLookup(sheenColor,environmentSheenBrdf);\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)\nsheenEnvironmentReflectance*=seo;\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)\nsheenEnvironmentReflectance*=eho;\n#endif\n#if DEBUGMODE>0\noutParams.sheenEnvironmentReflectance=sheenEnvironmentReflectance;\n#endif\noutParams.finalSheenRadianceScaled=\nenvironmentSheenRadiance.rgb *\nsheenEnvironmentReflectance *\nvLightingIntensity.z;\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\noutParams.sheenAlbedoScaling=1.0-sheenIntensity*max(max(sheenColor.r,sheenColor.g),sheenColor.b)*environmentSheenBrdf.b;\n#endif\noutParams.sheenIntensity=sheenIntensity;outParams.sheenColor=sheenColor;outParams.sheenRoughness=sheenRoughness;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockSheen = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockClearcoat\";\nconst shader = `struct clearcoatOutParams\n{vec3 specularEnvironmentR0;float conservationFactor;vec3 clearCoatNormalW;vec2 clearCoatAARoughnessFactors;float clearCoatIntensity;float clearCoatRoughness;\n#ifdef REFLECTION\nvec3 finalClearCoatRadianceScaled;\n#endif\n#ifdef CLEARCOAT_TINT\nvec3 absorption;float clearCoatNdotVRefract;vec3 clearCoatColor;float clearCoatThickness;\n#endif\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nvec3 energyConservationFactorClearCoat;\n#endif\n#if DEBUGMODE>0\n#ifdef CLEARCOAT_BUMP\nmat3 TBNClearCoat;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nvec2 clearCoatMapData;\n#endif\n#if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)\nvec4 clearCoatTintMapData;\n#endif\n#ifdef REFLECTION\nvec4 environmentClearCoatRadiance;vec3 clearCoatEnvironmentReflectance;\n#endif\nfloat clearCoatNdotV;\n#endif\n};\n#ifdef CLEARCOAT\n#define pbr_inline\n#define inline\nvoid clearcoatBlock(\nin vec3 vPositionW,\nin vec3 geometricNormalW,\nin vec3 viewDirectionW,\nin vec2 vClearCoatParams,\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\nin vec4 clearCoatMapRoughnessData,\n#endif\nin vec3 specularEnvironmentR0,\n#ifdef CLEARCOAT_TEXTURE\nin vec2 clearCoatMapData,\n#endif\n#ifdef CLEARCOAT_TINT\nin vec4 vClearCoatTintParams,\nin float clearCoatColorAtDistance,\nin vec4 vClearCoatRefractionParams,\n#ifdef CLEARCOAT_TINT_TEXTURE\nin vec4 clearCoatTintMapData,\n#endif\n#endif\n#ifdef CLEARCOAT_BUMP\nin vec2 vClearCoatBumpInfos,\nin vec4 clearCoatBumpMapData,\nin vec2 vClearCoatBumpUV,\n#if defined(TANGENT) && defined(NORMAL)\nin mat3 vTBN,\n#else\nin vec2 vClearCoatTangentSpaceParams,\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nin mat4 normalMatrix,\n#endif\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nin vec3 faceNormal,\n#endif\n#ifdef REFLECTION\nin vec3 vReflectionMicrosurfaceInfos,\nin vec2 vReflectionInfos,\nin vec3 vReflectionColor,\nin vec4 vLightingIntensity,\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSampler,\n#else\nin sampler2D reflectionSampler,\n#endif\n#ifndef LODBASEDMICROSFURACE\n#ifdef REFLECTIONMAP_3D\nin samplerCube reflectionSamplerLow,\nin samplerCube reflectionSamplerHigh,\n#else\nin sampler2D reflectionSamplerLow,\nin sampler2D reflectionSamplerHigh,\n#endif\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vReflectionFilteringInfo,\n#endif\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n#ifdef RADIANCEOCCLUSION\nin float ambientMonochrome,\n#endif\n#endif\n#if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)\nin float frontFacingMultiplier,\n#endif\nout clearcoatOutParams outParams\n)\n{float clearCoatIntensity=vClearCoatParams.x;float clearCoatRoughness=vClearCoatParams.y;\n#ifdef CLEARCOAT_TEXTURE\nclearCoatIntensity*=clearCoatMapData.x;\n#ifdef CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE\nclearCoatRoughness*=clearCoatMapData.y;\n#endif\n#if DEBUGMODE>0\noutParams.clearCoatMapData=clearCoatMapData;\n#endif\n#endif\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL\nclearCoatRoughness*=clearCoatMapData.y;\n#else\nclearCoatRoughness*=clearCoatMapRoughnessData.y;\n#endif\n#endif\noutParams.clearCoatIntensity=clearCoatIntensity;outParams.clearCoatRoughness=clearCoatRoughness;\n#ifdef CLEARCOAT_TINT\nvec3 clearCoatColor=vClearCoatTintParams.rgb;float clearCoatThickness=vClearCoatTintParams.a;\n#ifdef CLEARCOAT_TINT_TEXTURE\n#ifdef CLEARCOAT_TINT_GAMMATEXTURE\nclearCoatColor*=toLinearSpace(clearCoatTintMapData.rgb);\n#else\nclearCoatColor*=clearCoatTintMapData.rgb;\n#endif\nclearCoatThickness*=clearCoatTintMapData.a;\n#if DEBUGMODE>0\noutParams.clearCoatTintMapData=clearCoatTintMapData;\n#endif\n#endif\noutParams.clearCoatColor=computeColorAtDistanceInMedia(clearCoatColor,clearCoatColorAtDistance);outParams.clearCoatThickness=clearCoatThickness;\n#endif\n#ifdef CLEARCOAT_REMAP_F0\nvec3 specularEnvironmentR0Updated=getR0RemappedForClearCoat(specularEnvironmentR0);\n#else\nvec3 specularEnvironmentR0Updated=specularEnvironmentR0;\n#endif\noutParams.specularEnvironmentR0=mix(specularEnvironmentR0,specularEnvironmentR0Updated,clearCoatIntensity);vec3 clearCoatNormalW=geometricNormalW;\n#ifdef CLEARCOAT_BUMP\n#ifdef NORMALXYSCALE\nfloat clearCoatNormalScale=1.0;\n#else\nfloat clearCoatNormalScale=vClearCoatBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBNClearCoat=vTBN;\n#else\nvec2 TBNClearCoatUV=vClearCoatBumpUV*frontFacingMultiplier;mat3 TBNClearCoat=cotangent_frame(clearCoatNormalW*clearCoatNormalScale,vPositionW,TBNClearCoatUV,vClearCoatTangentSpaceParams);\n#endif\n#if DEBUGMODE>0\noutParams.TBNClearCoat=TBNClearCoat;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nclearCoatNormalW=normalize(clearCoatBumpMapData.xyz *2.0-1.0);clearCoatNormalW=normalize(mat3(normalMatrix)*clearCoatNormalW);\n#else\nclearCoatNormalW=perturbNormal(TBNClearCoat,clearCoatBumpMapData.xyz,vClearCoatBumpInfos.y);\n#endif\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nclearCoatNormalW*=sign(dot(clearCoatNormalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nclearCoatNormalW=clearCoatNormalW*frontFacingMultiplier;\n#endif\noutParams.clearCoatNormalW=clearCoatNormalW;outParams.clearCoatAARoughnessFactors=getAARoughnessFactors(clearCoatNormalW.xyz);float clearCoatNdotVUnclamped=dot(clearCoatNormalW,viewDirectionW);float clearCoatNdotV=absEps(clearCoatNdotVUnclamped);\n#if DEBUGMODE>0\noutParams.clearCoatNdotV=clearCoatNdotV;\n#endif\n#ifdef CLEARCOAT_TINT\nvec3 clearCoatVRefract=refract(-viewDirectionW,clearCoatNormalW,vClearCoatRefractionParams.y);outParams.clearCoatNdotVRefract=absEps(dot(clearCoatNormalW,clearCoatVRefract));\n#endif\n#if defined(ENVIRONMENTBRDF) && (!defined(REFLECTIONMAP_SKYBOX) || defined(MS_BRDF_ENERGY_CONSERVATION))\nvec3 environmentClearCoatBrdf=getBRDFLookup(clearCoatNdotV,clearCoatRoughness);\n#endif\n#if defined(REFLECTION)\nfloat clearCoatAlphaG=convertRoughnessToAverageSlope(clearCoatRoughness);\n#ifdef SPECULARAA\nclearCoatAlphaG+=outParams.clearCoatAARoughnessFactors.y;\n#endif\nvec4 environmentClearCoatRadiance=vec4(0.,0.,0.,0.);vec3 clearCoatReflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),clearCoatNormalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nclearCoatReflectionVector.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\nvec3 clearCoatReflectionCoords=clearCoatReflectionVector;\n#else\nvec2 clearCoatReflectionCoords=clearCoatReflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nclearCoatReflectionCoords/=clearCoatReflectionVector.z;\n#endif\nclearCoatReflectionCoords.y=1.0-clearCoatReflectionCoords.y;\n#endif\nsampleReflectionTexture(\nclearCoatAlphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nclearCoatNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nclearCoatRoughness,\n#endif\nreflectionSampler,\nclearCoatReflectionCoords,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nenvironmentClearCoatRadiance\n);\n#if DEBUGMODE>0\noutParams.environmentClearCoatRadiance=environmentClearCoatRadiance;\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\nvec3 clearCoatEnvironmentReflectance=getReflectanceFromBRDFLookup(vec3(vClearCoatRefractionParams.x),environmentClearCoatBrdf);\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat clearCoatEho=environmentHorizonOcclusion(-viewDirectionW,clearCoatNormalW,geometricNormalW);clearCoatEnvironmentReflectance*=clearCoatEho;\n#endif\n#endif\n#endif\n#else\nvec3 clearCoatEnvironmentReflectance=getReflectanceFromAnalyticalBRDFLookup_Jones(clearCoatNdotV,vec3(1.),vec3(1.),sqrt(1.-clearCoatRoughness));\n#endif\nclearCoatEnvironmentReflectance*=clearCoatIntensity;\n#if DEBUGMODE>0\noutParams.clearCoatEnvironmentReflectance=clearCoatEnvironmentReflectance;\n#endif\noutParams.finalClearCoatRadianceScaled=\nenvironmentClearCoatRadiance.rgb *\nclearCoatEnvironmentReflectance *\nvLightingIntensity.z;\n#endif\n#if defined(CLEARCOAT_TINT)\noutParams.absorption=computeClearCoatAbsorption(outParams.clearCoatNdotVRefract,outParams.clearCoatNdotVRefract,outParams.clearCoatColor,clearCoatThickness,clearCoatIntensity);\n#endif\nfloat fresnelIBLClearCoat=fresnelSchlickGGX(clearCoatNdotV,vClearCoatRefractionParams.x,CLEARCOATREFLECTANCE90);fresnelIBLClearCoat*=clearCoatIntensity;outParams.conservationFactor=(1.-fresnelIBLClearCoat);\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\noutParams.energyConservationFactorClearCoat=getEnergyConservationFactor(outParams.specularEnvironmentR0,environmentClearCoatBrdf);\n#endif\n}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockClearcoat = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockIridescence\";\nconst shader = `struct iridescenceOutParams\n{float iridescenceIntensity;float iridescenceIOR;float iridescenceThickness;vec3 specularEnvironmentR0;};\n#ifdef IRIDESCENCE\n#define pbr_inline\n#define inline\nvoid iridescenceBlock(\nin vec4 vIridescenceParams,\nin float viewAngle,\nin vec3 specularEnvironmentR0,\n#ifdef IRIDESCENCE_TEXTURE\nin vec2 iridescenceMapData,\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nin vec2 iridescenceThicknessMapData,\n#endif\n#ifdef CLEARCOAT\nin float NdotVUnclamped,\n#ifdef CLEARCOAT_TEXTURE\nin vec2 clearCoatMapData,\n#endif\n#endif\nout iridescenceOutParams outParams\n)\n{float iridescenceIntensity=vIridescenceParams.x;float iridescenceIOR=vIridescenceParams.y;float iridescenceThicknessMin=vIridescenceParams.z;float iridescenceThicknessMax=vIridescenceParams.w;float iridescenceThicknessWeight=1.;\n#ifdef IRIDESCENCE_TEXTURE\niridescenceIntensity*=iridescenceMapData.x;\n#ifdef IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE\niridescenceThicknessWeight=iridescenceMapData.g;\n#endif\n#endif\n#if defined(IRIDESCENCE_THICKNESS_TEXTURE)\niridescenceThicknessWeight=iridescenceThicknessMapData.g;\n#endif\nfloat iridescenceThickness=mix(iridescenceThicknessMin,iridescenceThicknessMax,iridescenceThicknessWeight);float topIor=1.; \n#ifdef CLEARCOAT\nfloat clearCoatIntensity=vClearCoatParams.x;\n#ifdef CLEARCOAT_TEXTURE\nclearCoatIntensity*=clearCoatMapData.x;\n#endif\ntopIor=mix(1.0,vClearCoatRefractionParams.w-1.,clearCoatIntensity);viewAngle=sqrt(1.0+square(1.0/topIor)*(square(NdotVUnclamped)-1.0));\n#endif\nvec3 iridescenceFresnel=evalIridescence(topIor,iridescenceIOR,viewAngle,iridescenceThickness,specularEnvironmentR0);outParams.specularEnvironmentR0=mix(specularEnvironmentR0,iridescenceFresnel,iridescenceIntensity);outParams.iridescenceIntensity=iridescenceIntensity;outParams.iridescenceThickness=iridescenceThickness;outParams.iridescenceIOR=iridescenceIOR;}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockIridescence = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockSubSurface\";\nconst shader = `struct subSurfaceOutParams\n{vec3 specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nvec3 finalRefraction;vec3 surfaceAlbedo;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nfloat alpha;\n#endif\n#ifdef REFLECTION\nfloat refractionFactorForIrradiance;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nvec3 transmittance;float translucencyIntensity;\n#ifdef REFLECTION\nvec3 refractionIrradiance;\n#endif\n#endif\n#if DEBUGMODE>0\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec4 thicknessMap;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction;vec3 refractionTransmittance;\n#endif\n#endif\n};\n#ifdef SUBSURFACE\n#define pbr_inline\n#define inline\nvoid subSurfaceBlock(\nin vec3 vSubSurfaceIntensity,\nin vec2 vThicknessParam,\nin vec4 vTintColor,\nin vec3 normalW,\nin vec3 specularEnvironmentReflectance,\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nin vec4 thicknessMap,\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nin vec4 refractionIntensityMap,\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nin vec4 translucencyIntensityMap,\n#endif\n#ifdef REFLECTION\n#ifdef SS_TRANSLUCENCY\nin mat4 reflectionMatrix,\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nin vec3 irradianceVector_,\n#endif\n#if defined(REALTIME_FILTERING)\nin samplerCube reflectionSampler,\nin vec2 vReflectionFilteringInfo,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\n#ifdef REFLECTIONMAP_3D\nin samplerCube irradianceSampler,\n#else\nin sampler2D irradianceSampler,\n#endif\n#endif\n#endif\n#endif\n#if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)\nin vec3 surfaceAlbedo,\n#endif\n#ifdef SS_REFRACTION\nin vec3 vPositionW,\nin vec3 viewDirectionW,\nin mat4 view,\nin vec4 vRefractionInfos,\nin mat4 refractionMatrix,\nin vec4 vRefractionMicrosurfaceInfos,\nin vec4 vLightingIntensity,\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nin float alpha,\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nin float NdotVUnclamped,\n#endif\n#ifdef SS_LINEARSPECULARREFRACTION\nin float roughness,\n#endif\nin float alphaG,\n#ifdef SS_REFRACTIONMAP_3D\nin samplerCube refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin samplerCube refractionSamplerLow,\nin samplerCube refractionSamplerHigh,\n#endif\n#else\nin sampler2D refractionSampler,\n#ifndef LODBASEDMICROSFURACE\nin sampler2D refractionSamplerLow,\nin sampler2D refractionSamplerHigh,\n#endif\n#endif\n#ifdef ANISOTROPIC\nin anisotropicOutParams anisotropicOut,\n#endif\n#ifdef REALTIME_FILTERING\nin vec2 vRefractionFilteringInfo,\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nin vec3 refractionPosition,\nin vec3 refractionSize,\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nin vec3 vDiffusionDistance,\n#endif\nout subSurfaceOutParams outParams\n)\n{outParams.specularEnvironmentReflectance=specularEnvironmentReflectance;\n#ifdef SS_REFRACTION\nfloat refractionIntensity=vSubSurfaceIntensity.x;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nrefractionIntensity*=(1.0-alpha);outParams.alpha=1.0;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nfloat translucencyIntensity=vSubSurfaceIntensity.y;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\n#if defined(SS_USE_GLTF_TEXTURES)\nfloat thickness=thicknessMap.g*vThicknessParam.y+vThicknessParam.x;\n#else\nfloat thickness=thicknessMap.r*vThicknessParam.y+vThicknessParam.x;\n#endif\n#if DEBUGMODE>0\noutParams.thicknessMap=thicknessMap;\n#endif\n#ifdef SS_MASK_FROM_THICKNESS_TEXTURE\n#if defined(SS_REFRACTION) && defined(SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE)\n#if defined(SS_USE_GLTF_TEXTURES)\nrefractionIntensity*=thicknessMap.r;\n#else\nrefractionIntensity*=thicknessMap.g;\n#endif\n#endif\n#if defined(SS_TRANSLUCENCY) && defined(SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE)\ntranslucencyIntensity*=thicknessMap.b;\n#endif\n#endif\n#else\nfloat thickness=vThicknessParam.y;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\n#ifdef SS_USE_GLTF_TEXTURES\nrefractionIntensity*=refractionIntensityMap.r;\n#else\nrefractionIntensity*=refractionIntensityMap.g;\n#endif\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\ntranslucencyIntensity*=translucencyIntensityMap.b;\n#endif\n#ifdef SS_TRANSLUCENCY\nthickness=maxEps(thickness);vec3 transmittance=transmittanceBRDF_Burley(vTintColor.rgb,vDiffusionDistance,thickness);transmittance*=translucencyIntensity;outParams.transmittance=transmittance;outParams.translucencyIntensity=translucencyIntensity;\n#endif\n#ifdef SS_REFRACTION\nvec4 environmentRefraction=vec4(0.,0.,0.,0.);\n#ifdef ANISOTROPIC\nvec3 refractionVector=refract(-viewDirectionW,anisotropicOut.anisotropicNormal,vRefractionInfos.y);\n#else\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#endif\n#ifdef SS_REFRACTIONMAP_OPPOSITEZ\nrefractionVector.z*=-1.0;\n#endif\n#ifdef SS_REFRACTIONMAP_3D\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,refractionSize,refractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec3 refractionCoords=refractionVector;refractionCoords=vec3(refractionMatrix*vec4(refractionCoords,0));\n#else\n#ifdef SS_USE_THICKNESS_AS_DEPTH\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*thickness,1.0)));\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n#endif\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;\n#endif\n#ifdef SS_HAS_THICKNESS\nfloat ior=vRefractionInfos.y;\n#else\nfloat ior=vRefractionMicrosurfaceInfos.w;\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG,NdotVUnclamped);\n#elif defined(SS_LINEARSPECULARREFRACTION)\nfloat refractionRoughness=alphaG;refractionRoughness=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLinearLodFromRoughness(vRefractionMicrosurfaceInfos.x,refractionRoughness);\n#else\nfloat refractionAlphaG=alphaG;refractionAlphaG=mix(alphaG,0.0,clamp(ior*3.0-2.0,0.0,1.0));float refractionLOD=getLodFromAlphaG(vRefractionMicrosurfaceInfos.x,refractionAlphaG);\n#endif\n#ifdef LODBASEDMICROSFURACE\nrefractionLOD=refractionLOD*vRefractionMicrosurfaceInfos.y+vRefractionMicrosurfaceInfos.z;\n#ifdef SS_LODINREFRACTIONALPHA\nfloat automaticRefractionLOD=UNPACK_LOD(sampleRefraction(refractionSampler,refractionCoords).a);float requestedRefractionLOD=max(automaticRefractionLOD,refractionLOD);\n#else\nfloat requestedRefractionLOD=refractionLOD;\n#endif\n#if defined(REALTIME_FILTERING) && defined(SS_REFRACTIONMAP_3D)\nenvironmentRefraction=vec4(radiance(alphaG,refractionSampler,refractionCoords,vRefractionFilteringInfo),1.0);\n#else\nenvironmentRefraction=sampleRefractionLod(refractionSampler,refractionCoords,requestedRefractionLOD);\n#endif\n#else\nfloat lodRefractionNormalized=saturate(refractionLOD/log2(vRefractionMicrosurfaceInfos.x));float lodRefractionNormalizedDoubled=lodRefractionNormalized*2.0;vec4 environmentRefractionMid=sampleRefraction(refractionSampler,refractionCoords);if (lodRefractionNormalizedDoubled<1.0){environmentRefraction=mix(\nsampleRefraction(refractionSamplerHigh,refractionCoords),\nenvironmentRefractionMid,\nlodRefractionNormalizedDoubled\n);} else {environmentRefraction=mix(\nenvironmentRefractionMid,\nsampleRefraction(refractionSamplerLow,refractionCoords),\nlodRefractionNormalizedDoubled-1.0\n);}\n#endif\n#ifdef SS_RGBDREFRACTION\nenvironmentRefraction.rgb=fromRGBD(environmentRefraction);\n#endif\n#ifdef SS_GAMMAREFRACTION\nenvironmentRefraction.rgb=toLinearSpace(environmentRefraction.rgb);\n#endif\nenvironmentRefraction.rgb*=vRefractionInfos.x;\n#endif\n#ifdef SS_REFRACTION\nvec3 refractionTransmittance=vec3(refractionIntensity);\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,thickness);\n#elif defined(SS_LINKREFRACTIONTOTRANSPARENCY)\nfloat maxChannel=max(max(surfaceAlbedo.r,surfaceAlbedo.g),surfaceAlbedo.b);vec3 volumeAlbedo=saturate(maxChannel*surfaceAlbedo);environmentRefraction.rgb*=volumeAlbedo;\n#else\nvec3 volumeAlbedo=computeColorAtDistanceInMedia(vTintColor.rgb,vTintColor.w);refractionTransmittance*=cocaLambert(volumeAlbedo,vThicknessParam.y);\n#endif\n#ifdef SS_ALBEDOFORREFRACTIONTINT\nenvironmentRefraction.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.surfaceAlbedo=surfaceAlbedo*(1.-refractionIntensity);\n#ifdef REFLECTION\noutParams.refractionFactorForIrradiance=(1.-refractionIntensity);\n#endif\n#ifdef UNUSED_MULTIPLEBOUNCES\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);outParams.specularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,refractionIntensity);\n#endif\nrefractionTransmittance*=1.0-outParams.specularEnvironmentReflectance;\n#if DEBUGMODE>0\noutParams.refractionTransmittance=refractionTransmittance;\n#endif\noutParams.finalRefraction=environmentRefraction.rgb*refractionTransmittance*vLightingIntensity.z;\n#if DEBUGMODE>0\noutParams.environmentRefraction=environmentRefraction;\n#endif\n#endif\n#if defined(REFLECTION) && defined(SS_TRANSLUCENCY)\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX) || !defined(USESPHERICALFROMREFLECTIONMAP)\nvec3 irradianceVector=vec3(reflectionMatrix*vec4(normalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nirradianceVector.z*=-1.0;\n#endif\n#ifdef INVERTCUBICMAP\nirradianceVector.y*=-1.0;\n#endif\n#else\nvec3 irradianceVector=irradianceVector_;\n#endif\n#if defined(USESPHERICALFROMREFLECTIONMAP)\n#if defined(REALTIME_FILTERING)\nvec3 refractionIrradiance=irradiance(reflectionSampler,-irradianceVector,vReflectionFilteringInfo);\n#else\nvec3 refractionIrradiance=computeEnvironmentIrradiance(-irradianceVector);\n#endif\n#elif defined(USEIRRADIANCEMAP)\n#ifdef REFLECTIONMAP_3D\nvec3 irradianceCoords=irradianceVector;\n#else\nvec2 irradianceCoords=irradianceVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nirradianceCoords/=irradianceVector.z;\n#endif\nirradianceCoords.y=1.0-irradianceCoords.y;\n#endif\nvec4 refractionIrradiance=sampleReflection(irradianceSampler,-irradianceCoords);\n#ifdef RGBDREFLECTION\nrefractionIrradiance.rgb=fromRGBD(refractionIrradiance);\n#endif\n#ifdef GAMMAREFLECTION\nrefractionIrradiance.rgb=toLinearSpace(refractionIrradiance.rgb);\n#endif\n#else\nvec4 refractionIrradiance=vec4(0.);\n#endif\nrefractionIrradiance.rgb*=transmittance;\n#ifdef SS_ALBEDOFORTRANSLUCENCYTINT\nrefractionIrradiance.rgb*=surfaceAlbedo.rgb;\n#endif\noutParams.refractionIrradiance=refractionIrradiance.rgb;\n#endif\n}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockSubSurface = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockNormalGeometric\";\nconst shader = `vec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#endif\nvec3 geometricNormalW=normalW;\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\ngeometricNormalW=gl_FrontFacing ? geometricNormalW : -geometricNormalW;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockNormalGeometric = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockNormalFinal\";\nconst shader = `#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nvec3 faceNormal=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)))*vEyePosition.w;\n#if defined(TWOSIDEDLIGHTING)\nfaceNormal=gl_FrontFacing ? faceNormal : -faceNormal;\n#endif\nnormalW*=sign(dot(normalW,faceNormal));\n#endif\n#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockNormalFinal = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockLightmapInit\";\nconst shader = `#ifdef LIGHTMAP\nvec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);\n#ifdef RGBDLIGHTMAP\nlightmapColor.rgb=fromRGBD(lightmapColor);\n#endif\n#ifdef GAMMALIGHTMAP\nlightmapColor.rgb=toLinearSpace(lightmapColor.rgb);\n#endif\nlightmapColor.rgb*=vLightmapInfos.y;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockLightmapInit = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockGeometryInfo\";\nconst shader = `float NdotVUnclamped=dot(normalW,viewDirectionW);float NdotV=absEps(NdotVUnclamped);float alphaG=convertRoughnessToAverageSlope(roughness);vec2 AARoughnessFactors=getAARoughnessFactors(normalW.xyz);\n#ifdef SPECULARAA\nalphaG+=AARoughnessFactors.y;\n#endif\n#if defined(ENVIRONMENTBRDF)\nvec3 environmentBrdf=getBRDFLookup(NdotV,roughness);\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n#ifdef RADIANCEOCCLUSION\n#ifdef AMBIENTINGRAYSCALE\nfloat ambientMonochrome=aoOut.ambientOcclusionColor.r;\n#else\nfloat ambientMonochrome=getLuminance(aoOut.ambientOcclusionColor);\n#endif\nfloat seo=environmentRadianceOcclusion(ambientMonochrome,NdotVUnclamped);\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nfloat eho=environmentHorizonOcclusion(-viewDirectionW,normalW,geometricNormalW);\n#endif\n#endif\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockGeometryInfo = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockReflectance0\";\nconst shader = `float reflectance=max(max(reflectivityOut.surfaceReflectivityColor.r,reflectivityOut.surfaceReflectivityColor.g),reflectivityOut.surfaceReflectivityColor.b);vec3 specularEnvironmentR0=reflectivityOut.surfaceReflectivityColor.rgb;\n#ifdef METALLICWORKFLOW\nvec3 specularEnvironmentR90=vec3(metallicReflectanceFactors.a);\n#else \nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\n#endif\n#ifdef ALPHAFRESNEL\nfloat reflectance90=fresnelGrazingReflectance(reflectance);specularEnvironmentR90=specularEnvironmentR90*reflectance90;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockReflectance0 = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockReflectance\";\nconst shader = `#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\nvec3 specularEnvironmentReflectance=getReflectanceFromBRDFLookup(clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,environmentBrdf);\n#ifdef RADIANCEOCCLUSION\nspecularEnvironmentReflectance*=seo;\n#endif\n#ifdef HORIZONOCCLUSION\n#ifdef BUMP\n#ifdef REFLECTIONMAP_3D\nspecularEnvironmentReflectance*=eho;\n#endif\n#endif\n#endif\n#else\nvec3 specularEnvironmentReflectance=getReflectanceFromAnalyticalBRDFLookup_Jones(NdotV,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n#endif\n#ifdef CLEARCOAT\nspecularEnvironmentReflectance*=clearcoatOut.conservationFactor;\n#if defined(CLEARCOAT_TINT)\nspecularEnvironmentReflectance*=clearcoatOut.absorption;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockReflectance = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockDirectLighting\";\nconst shader = `vec3 diffuseBase=vec3(0.,0.,0.);\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#ifdef CLEARCOAT\nvec3 clearCoatBase=vec3(0.,0.,0.);\n#endif\n#ifdef SHEEN\nvec3 sheenBase=vec3(0.,0.,0.);\n#endif\npreLightingInfo preInfo;lightingInfo info;float shadow=1.; \n#if defined(CLEARCOAT) && defined(CLEARCOAT_TINT)\nvec3 absorption=vec3(0.);\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockDirectLighting = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockFinalLitComponents\";\nconst shader = `#if defined(ENVIRONMENTBRDF)\n#ifdef MS_BRDF_ENERGY_CONSERVATION\nvec3 energyConservationFactor=getEnergyConservationFactor(clearcoatOut.specularEnvironmentR0,environmentBrdf);\n#endif\n#endif\n#ifndef METALLICWORKFLOW\n#ifdef SPECULAR_GLOSSINESS_ENERGY_CONSERVATION\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\n#endif\n#endif\n#if defined(SHEEN) && defined(SHEEN_ALBEDOSCALING) && defined(ENVIRONMENTBRDF)\nsurfaceAlbedo.rgb=sheenOut.sheenAlbedoScaling*surfaceAlbedo.rgb;\n#endif\n#ifdef REFLECTION\nvec3 finalIrradiance=reflectionOut.environmentIrradiance;\n#if defined(CLEARCOAT)\nfinalIrradiance*=clearcoatOut.conservationFactor;\n#if defined(CLEARCOAT_TINT)\nfinalIrradiance*=clearcoatOut.absorption;\n#endif\n#endif\n#if defined(SS_REFRACTION)\nfinalIrradiance*=subSurfaceOut.refractionFactorForIrradiance;\n#endif\n#if defined(SS_TRANSLUCENCY)\nfinalIrradiance*=(1.0-subSurfaceOut.translucencyIntensity);finalIrradiance+=subSurfaceOut.refractionIrradiance;\n#endif\nfinalIrradiance*=surfaceAlbedo.rgb;finalIrradiance*=vLightingIntensity.z;finalIrradiance*=aoOut.ambientOcclusionColor;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase;finalSpecular=max(finalSpecular,0.0);vec3 finalSpecularScaled=finalSpecular*vLightingIntensity.x*vLightingIntensity.w;\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nfinalSpecularScaled*=energyConservationFactor;\n#endif\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\nfinalSpecularScaled*=sheenOut.sheenAlbedoScaling;\n#endif\n#endif\n#ifdef REFLECTION\nvec3 finalRadiance=reflectionOut.environmentRadiance.rgb;finalRadiance*=subSurfaceOut.specularEnvironmentReflectance;vec3 finalRadianceScaled=finalRadiance*vLightingIntensity.z;\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nfinalRadianceScaled*=energyConservationFactor;\n#endif\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)\nfinalRadianceScaled*=sheenOut.sheenAlbedoScaling;\n#endif\n#endif\n#ifdef SHEEN\nvec3 finalSheen=sheenBase*sheenOut.sheenColor;finalSheen=max(finalSheen,0.0);vec3 finalSheenScaled=finalSheen*vLightingIntensity.x*vLightingIntensity.w;\n#if defined(CLEARCOAT) && defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nsheenOut.finalSheenRadianceScaled*=clearcoatOut.conservationFactor;\n#if defined(CLEARCOAT_TINT)\nsheenOut.finalSheenRadianceScaled*=clearcoatOut.absorption;\n#endif\n#endif\n#endif\n#ifdef CLEARCOAT\nvec3 finalClearCoat=clearCoatBase;finalClearCoat=max(finalClearCoat,0.0);vec3 finalClearCoatScaled=finalClearCoat*vLightingIntensity.x*vLightingIntensity.w;\n#if defined(ENVIRONMENTBRDF) && defined(MS_BRDF_ENERGY_CONSERVATION)\nfinalClearCoatScaled*=clearcoatOut.energyConservationFactorClearCoat;\n#endif\n#ifdef SS_REFRACTION\nsubSurfaceOut.finalRefraction*=clearcoatOut.conservationFactor;\n#ifdef CLEARCOAT_TINT\nsubSurfaceOut.finalRefraction*=clearcoatOut.absorption;\n#endif\n#endif\n#endif\n#ifdef ALPHABLEND\nfloat luminanceOverAlpha=0.0;\n#if defined(REFLECTION) && defined(RADIANCEOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalRadianceScaled);\n#if defined(CLEARCOAT)\nluminanceOverAlpha+=getLuminance(clearcoatOut.finalClearCoatRadianceScaled);\n#endif\n#endif\n#if defined(SPECULARTERM) && defined(SPECULAROVERALPHA)\nluminanceOverAlpha+=getLuminance(finalSpecularScaled);\n#endif\n#if defined(CLEARCOAT) && defined(CLEARCOATOVERALPHA)\nluminanceOverAlpha+=getLuminance(finalClearCoatScaled);\n#endif\n#if defined(RADIANCEOVERALPHA) || defined(SPECULAROVERALPHA) || defined(CLEARCOATOVERALPHA)\nalpha=saturate(alpha+luminanceOverAlpha*luminanceOverAlpha);\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockFinalLitComponents = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockFinalUnlitComponents\";\nconst shader = `vec3 finalDiffuse=diffuseBase;finalDiffuse*=surfaceAlbedo.rgb;finalDiffuse=max(finalDiffuse,0.0);finalDiffuse*=vLightingIntensity.x;vec3 finalAmbient=vAmbientColor;finalAmbient*=surfaceAlbedo.rgb;vec3 finalEmissive=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\n#ifdef GAMMAEMISSIVE\nfinalEmissive*=toLinearSpace(emissiveColorTex.rgb);\n#else\nfinalEmissive*=emissiveColorTex.rgb;\n#endif\nfinalEmissive*= vEmissiveInfos.y;\n#endif\nfinalEmissive*=vLightingIntensity.y;\n#ifdef AMBIENT\nvec3 ambientOcclusionForDirectDiffuse=mix(vec3(1.),aoOut.ambientOcclusionColor,vAmbientInfos.w);\n#else\nvec3 ambientOcclusionForDirectDiffuse=aoOut.ambientOcclusionColor;\n#endif\nfinalAmbient*=aoOut.ambientOcclusionColor;finalDiffuse*=ambientOcclusionForDirectDiffuse;\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockFinalUnlitComponents = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockFinalColorComposition\";\nconst shader = `vec4 finalColor=vec4(\n#ifndef UNLIT\n#ifdef REFLECTION\nfinalIrradiance +\n#endif\n#ifdef SPECULARTERM\nfinalSpecularScaled +\n#endif\n#ifdef SHEEN\nfinalSheenScaled +\n#endif\n#ifdef CLEARCOAT\nfinalClearCoatScaled +\n#endif\n#ifdef REFLECTION\nfinalRadianceScaled +\n#if defined(SHEEN) && defined(ENVIRONMENTBRDF)\nsheenOut.finalSheenRadianceScaled +\n#endif\n#ifdef CLEARCOAT\nclearcoatOut.finalClearCoatRadianceScaled +\n#endif\n#endif\n#ifdef SS_REFRACTION\nsubSurfaceOut.finalRefraction +\n#endif\n#endif\nfinalAmbient +\nfinalDiffuse,\nalpha);\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor.rgb;\n#else\nfinalColor.rgb+=lightmapColor.rgb;\n#endif\n#endif\n#endif\nfinalColor.rgb+=finalEmissive;\n#define CUSTOM_FRAGMENT_BEFORE_FOG\nfinalColor=max(finalColor,0.0);\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockFinalColorComposition = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrBlockImageProcessing\";\nconst shader = `#if defined(IMAGEPROCESSINGPOSTPROCESS) || defined(SS_SCATTERING)\n#if !defined(SKIPFINALCOLORCLAMP)\nfinalColor.rgb=clamp(finalColor.rgb,0.,30.0);\n#endif\n#else\nfinalColor=applyImageProcessing(finalColor);\n#endif\nfinalColor.a*=visibility;\n#ifdef PREMULTIPLYALPHA\nfinalColor.rgb*=finalColor.a;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrBlockImageProcessing = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"pbrDebug\";\nconst shader = `#if DEBUGMODE>0\nif (vClipSpacePosition.x/vClipSpacePosition.w>=vDebugMode.x) {\n#if DEBUGMODE==1\ngl_FragColor.rgb=vPositionW.rgb;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==2 && defined(NORMAL)\ngl_FragColor.rgb=vNormalW.rgb;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==3 && defined(BUMP) || DEBUGMODE==3 && defined(PARALLAX) || DEBUGMODE==3 && defined(ANISOTROPIC)\ngl_FragColor.rgb=TBN[0];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==4 && defined(BUMP) || DEBUGMODE==4 && defined(PARALLAX) || DEBUGMODE==4 && defined(ANISOTROPIC)\ngl_FragColor.rgb=TBN[1];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==5\ngl_FragColor.rgb=normalW;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==6 && defined(MAINUV1)\ngl_FragColor.rgb=vec3(vMainUV1,0.0);\n#elif DEBUGMODE==7 && defined(MAINUV2)\ngl_FragColor.rgb=vec3(vMainUV2,0.0);\n#elif DEBUGMODE==8 && defined(CLEARCOAT) && defined(CLEARCOAT_BUMP)\ngl_FragColor.rgb=clearcoatOut.TBNClearCoat[0];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==9 && defined(CLEARCOAT) && defined(CLEARCOAT_BUMP)\ngl_FragColor.rgb=clearcoatOut.TBNClearCoat[1];\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==10 && defined(CLEARCOAT)\ngl_FragColor.rgb=clearcoatOut.clearCoatNormalW;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==11 && defined(ANISOTROPIC)\ngl_FragColor.rgb=anisotropicOut.anisotropicNormal;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==12 && defined(ANISOTROPIC)\ngl_FragColor.rgb=anisotropicOut.anisotropicTangent;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==13 && defined(ANISOTROPIC)\ngl_FragColor.rgb=anisotropicOut.anisotropicBitangent;\n#define DEBUGMODE_NORMALIZE\n#elif DEBUGMODE==20 && defined(ALBEDO)\ngl_FragColor.rgb=albedoTexture.rgb;\n#ifndef GAMMAALBEDO\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==21 && defined(AMBIENT)\ngl_FragColor.rgb=aoOut.ambientOcclusionColorMap.rgb;\n#elif DEBUGMODE==22 && defined(OPACITY)\ngl_FragColor.rgb=opacityMap.rgb;\n#elif DEBUGMODE==23 && defined(EMISSIVE)\ngl_FragColor.rgb=emissiveColorTex.rgb;\n#ifndef GAMMAEMISSIVE\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==24 && defined(LIGHTMAP)\ngl_FragColor.rgb=lightmapColor.rgb;\n#ifndef GAMMALIGHTMAP\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==25 && defined(REFLECTIVITY) && defined(METALLICWORKFLOW)\ngl_FragColor.rgb=reflectivityOut.surfaceMetallicColorMap.rgb;\n#elif DEBUGMODE==26 && defined(REFLECTIVITY) && !defined(METALLICWORKFLOW)\ngl_FragColor.rgb=reflectivityOut.surfaceReflectivityColorMap.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==27 && defined(CLEARCOAT) && defined(CLEARCOAT_TEXTURE)\ngl_FragColor.rgb=vec3(clearcoatOut.clearCoatMapData.rg,0.0);\n#elif DEBUGMODE==28 && defined(CLEARCOAT) && defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)\ngl_FragColor.rgb=clearcoatOut.clearCoatTintMapData.rgb;\n#elif DEBUGMODE==29 && defined(SHEEN) && defined(SHEEN_TEXTURE)\ngl_FragColor.rgb=sheenOut.sheenMapData.rgb;\n#elif DEBUGMODE==30 && defined(ANISOTROPIC) && defined(ANISOTROPIC_TEXTURE)\ngl_FragColor.rgb=anisotropicOut.anisotropyMapData.rgb;\n#elif DEBUGMODE==31 && defined(SUBSURFACE) && defined(SS_THICKNESSANDMASK_TEXTURE)\ngl_FragColor.rgb=subSurfaceOut.thicknessMap.rgb;\n#elif DEBUGMODE==32 && defined(BUMP)\ngl_FragColor.rgb=texture2D(bumpSampler,vBumpUV).rgb;\n#elif DEBUGMODE==40 && defined(SS_REFRACTION)\ngl_FragColor.rgb=subSurfaceOut.environmentRefraction.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==41 && defined(REFLECTION)\ngl_FragColor.rgb=reflectionOut.environmentRadiance.rgb;\n#ifndef GAMMAREFLECTION\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==42 && defined(CLEARCOAT) && defined(REFLECTION)\ngl_FragColor.rgb=clearcoatOut.environmentClearCoatRadiance.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==50\ngl_FragColor.rgb=diffuseBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==51 && defined(SPECULARTERM)\ngl_FragColor.rgb=specularBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==52 && defined(CLEARCOAT)\ngl_FragColor.rgb=clearCoatBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==53 && defined(SHEEN)\ngl_FragColor.rgb=sheenBase.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==54 && defined(REFLECTION)\ngl_FragColor.rgb=reflectionOut.environmentIrradiance.rgb;\n#ifndef GAMMAREFLECTION\n#define DEBUGMODE_GAMMA\n#endif\n#elif DEBUGMODE==60\ngl_FragColor.rgb=surfaceAlbedo.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==61\ngl_FragColor.rgb=clearcoatOut.specularEnvironmentR0;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==62 && defined(METALLICWORKFLOW)\ngl_FragColor.rgb=vec3(reflectivityOut.metallicRoughness.r);\n#elif DEBUGMODE==71 && defined(METALLICWORKFLOW)\ngl_FragColor.rgb=reflectivityOut.metallicF0;\n#elif DEBUGMODE==63\ngl_FragColor.rgb=vec3(roughness);\n#elif DEBUGMODE==64\ngl_FragColor.rgb=vec3(alphaG);\n#elif DEBUGMODE==65\ngl_FragColor.rgb=vec3(NdotV);\n#elif DEBUGMODE==66 && defined(CLEARCOAT) && defined(CLEARCOAT_TINT)\ngl_FragColor.rgb=clearcoatOut.clearCoatColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==67 && defined(CLEARCOAT)\ngl_FragColor.rgb=vec3(clearcoatOut.clearCoatRoughness);\n#elif DEBUGMODE==68 && defined(CLEARCOAT)\ngl_FragColor.rgb=vec3(clearcoatOut.clearCoatNdotV);\n#elif DEBUGMODE==69 && defined(SUBSURFACE) && defined(SS_TRANSLUCENCY)\ngl_FragColor.rgb=subSurfaceOut.transmittance;\n#elif DEBUGMODE==70 && defined(SUBSURFACE) && defined(SS_REFRACTION)\ngl_FragColor.rgb=subSurfaceOut.refractionTransmittance;\n#elif DEBUGMODE==72\ngl_FragColor.rgb=vec3(microSurface);\n#elif DEBUGMODE==73\ngl_FragColor.rgb=vAlbedoColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==74 && !defined(METALLICWORKFLOW)\ngl_FragColor.rgb=vReflectivityColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==75\ngl_FragColor.rgb=vEmissiveColor.rgb;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==80 && defined(RADIANCEOCCLUSION)\ngl_FragColor.rgb=vec3(seo);\n#elif DEBUGMODE==81 && defined(HORIZONOCCLUSION)\ngl_FragColor.rgb=vec3(eho);\n#elif DEBUGMODE==82 && defined(MS_BRDF_ENERGY_CONSERVATION)\ngl_FragColor.rgb=vec3(energyConservationFactor);\n#elif DEBUGMODE==83 && defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\ngl_FragColor.rgb=specularEnvironmentReflectance;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==84 && defined(CLEARCOAT) && defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\ngl_FragColor.rgb=clearcoatOut.clearCoatEnvironmentReflectance;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==85 && defined(SHEEN) && defined(REFLECTION)\ngl_FragColor.rgb=sheenOut.sheenEnvironmentReflectance;\n#define DEBUGMODE_GAMMA\n#elif DEBUGMODE==86 && defined(ALPHABLEND)\ngl_FragColor.rgb=vec3(luminanceOverAlpha);\n#elif DEBUGMODE==87\ngl_FragColor.rgb=vec3(alpha);\n#elif DEBUGMODE==88 && defined(ALBEDO)\ngl_FragColor.rgb=vec3(albedoTexture.a);\n#else\nfloat stripeWidth=30.;float stripePos=floor((gl_FragCoord.x+gl_FragCoord.y)/stripeWidth);float whichColor=mod(stripePos,2.);vec3 color1=vec3(.6,.2,.2);vec3 color2=vec3(.3,.1,.1);gl_FragColor.rgb=mix(color1,color2,whichColor);\n#endif\ngl_FragColor.rgb*=vDebugMode.y;\n#ifdef DEBUGMODE_NORMALIZE\ngl_FragColor.rgb=normalize(gl_FragColor.rgb)*0.5+0.5;\n#endif\n#ifdef DEBUGMODE_GAMMA\ngl_FragColor.rgb=toGammaSpace(gl_FragColor.rgb);\n#endif\ngl_FragColor.a=1.0;\n#ifdef PREPASS\ngl_FragData[0]=toLinearSpace(gl_FragColor); \ngl_FragData[1]=vec4(0.,0.,0.,0.); \n#endif\n}\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrDebug = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/prePassDeclaration\";\nimport \"./ShadersInclude/oitDeclaration\";\nimport \"./ShadersInclude/pbrFragmentDeclaration\";\nimport \"./ShadersInclude/pbrUboDeclaration\";\nimport \"./ShadersInclude/pbrFragmentExtraDeclaration\";\nimport \"./ShadersInclude/lightFragmentDeclaration\";\nimport \"./ShadersInclude/lightUboDeclaration\";\nimport \"./ShadersInclude/pbrFragmentSamplersDeclaration\";\nimport \"./ShadersInclude/imageProcessingDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/subSurfaceScatteringFunctions\";\nimport \"./ShadersInclude/importanceSampling\";\nimport \"./ShadersInclude/pbrHelperFunctions\";\nimport \"./ShadersInclude/imageProcessingFunctions\";\nimport \"./ShadersInclude/shadowsFragmentFunctions\";\nimport \"./ShadersInclude/harmonicsFunctions\";\nimport \"./ShadersInclude/pbrDirectLightingSetupFunctions\";\nimport \"./ShadersInclude/pbrDirectLightingFalloffFunctions\";\nimport \"./ShadersInclude/pbrBRDFFunctions\";\nimport \"./ShadersInclude/hdrFilteringFunctions\";\nimport \"./ShadersInclude/pbrDirectLightingFunctions\";\nimport \"./ShadersInclude/pbrIBLFunctions\";\nimport \"./ShadersInclude/bumpFragmentMainFunctions\";\nimport \"./ShadersInclude/bumpFragmentFunctions\";\nimport \"./ShadersInclude/reflectionFunction\";\nimport \"./ShadersInclude/pbrBlockAlbedoOpacity\";\nimport \"./ShadersInclude/pbrBlockReflectivity\";\nimport \"./ShadersInclude/pbrBlockAmbientOcclusion\";\nimport \"./ShadersInclude/pbrBlockAlphaFresnel\";\nimport \"./ShadersInclude/pbrBlockAnisotropic\";\nimport \"./ShadersInclude/pbrBlockReflection\";\nimport \"./ShadersInclude/pbrBlockSheen\";\nimport \"./ShadersInclude/pbrBlockClearcoat\";\nimport \"./ShadersInclude/pbrBlockIridescence\";\nimport \"./ShadersInclude/pbrBlockSubSurface\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/pbrBlockNormalGeometric\";\nimport \"./ShadersInclude/bumpFragment\";\nimport \"./ShadersInclude/pbrBlockNormalFinal\";\nimport \"./ShadersInclude/depthPrePass\";\nimport \"./ShadersInclude/pbrBlockLightmapInit\";\nimport \"./ShadersInclude/pbrBlockGeometryInfo\";\nimport \"./ShadersInclude/pbrBlockReflectance0\";\nimport \"./ShadersInclude/pbrBlockReflectance\";\nimport \"./ShadersInclude/pbrBlockDirectLighting\";\nimport \"./ShadersInclude/lightFragment\";\nimport \"./ShadersInclude/pbrBlockFinalLitComponents\";\nimport \"./ShadersInclude/pbrBlockFinalUnlitComponents\";\nimport \"./ShadersInclude/pbrBlockFinalColorComposition\";\nimport \"./ShadersInclude/logDepthFragment\";\nimport \"./ShadersInclude/fogFragment\";\nimport \"./ShadersInclude/pbrBlockImageProcessing\";\nimport \"./ShadersInclude/oitFragment\";\nimport \"./ShadersInclude/pbrDebug\";\n\nconst name = \"pbrPixelShader\";\nconst shader = `#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD) || defined(SPECULARAA) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#include[SCENE_MRT_COUNT]\nprecision highp float;\n#include\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE\n#endif\n#include<__decl__pbrFragment>\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#ifdef REFLECTION\n#include\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\n#include\n#include\n#include\nalbedoOpacityOutParams albedoOpacityOut;\n#ifdef ALBEDO\nvec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#endif\n#ifdef DECAL\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#endif\nalbedoOpacityBlock(\nvAlbedoColor,\n#ifdef ALBEDO\nalbedoTexture,\nvAlbedoInfos,\n#endif\n#ifdef OPACITY\nopacityMap,\nvOpacityInfos,\n#endif\n#ifdef DETAIL\ndetailColor,\nvDetailInfos,\n#endif\n#ifdef DECAL\ndecalColor,\nvDecalInfos,\n#endif\nalbedoOpacityOut\n);vec3 surfaceAlbedo=albedoOpacityOut.surfaceAlbedo;float alpha=albedoOpacityOut.alpha;\n#define CUSTOM_FRAGMENT_UPDATE_ALPHA\n#include\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\nambientOcclusionOutParams aoOut;\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb;\n#endif\nambientOcclusionBlock(\n#ifdef AMBIENT\nambientOcclusionColorMap,\nvAmbientInfos,\n#endif\naoOut\n);\n#include\n#ifdef UNLIT\nvec3 diffuseBase=vec3(1.,1.,1.);\n#else\nvec3 baseColor=surfaceAlbedo;reflectivityOutParams reflectivityOut;\n#if defined(REFLECTIVITY)\nvec4 surfaceMetallicOrReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);vec4 baseReflectivity=surfaceMetallicOrReflectivityColorMap;\n#ifndef METALLICWORKFLOW\n#ifdef REFLECTIVITY_GAMMA\nsurfaceMetallicOrReflectivityColorMap=toLinearSpace(surfaceMetallicOrReflectivityColorMap);\n#endif\nsurfaceMetallicOrReflectivityColorMap.rgb*=vReflectivityInfos.y;\n#endif\n#endif\n#if defined(MICROSURFACEMAP)\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\n#endif\n#ifdef METALLICWORKFLOW\nvec4 metallicReflectanceFactors=vMetallicReflectanceFactors;\n#ifdef REFLECTANCE\nvec4 reflectanceFactorsMap=texture2D(reflectanceSampler,vReflectanceUV+uvOffset);\n#ifdef REFLECTANCE_GAMMA\nreflectanceFactorsMap=toLinearSpace(reflectanceFactorsMap);\n#endif\nmetallicReflectanceFactors.rgb*=reflectanceFactorsMap.rgb;\n#endif\n#ifdef METALLIC_REFLECTANCE\nvec4 metallicReflectanceFactorsMap=texture2D(metallicReflectanceSampler,vMetallicReflectanceUV+uvOffset);\n#ifdef METALLIC_REFLECTANCE_GAMMA\nmetallicReflectanceFactorsMap=toLinearSpace(metallicReflectanceFactorsMap);\n#endif\n#ifndef METALLIC_REFLECTANCE_USE_ALPHA_ONLY\nmetallicReflectanceFactors.rgb*=metallicReflectanceFactorsMap.rgb;\n#endif\nmetallicReflectanceFactors*=metallicReflectanceFactorsMap.a;\n#endif\n#endif\nreflectivityBlock(\nvReflectivityColor,\n#ifdef METALLICWORKFLOW\nsurfaceAlbedo,\nmetallicReflectanceFactors,\n#endif\n#ifdef REFLECTIVITY\nvReflectivityInfos,\nsurfaceMetallicOrReflectivityColorMap,\n#endif\n#if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)\naoOut.ambientOcclusionColor,\n#endif\n#ifdef MICROSURFACEMAP\nmicroSurfaceTexel,\n#endif\n#ifdef DETAIL\ndetailColor,\nvDetailInfos,\n#endif\nreflectivityOut\n);float microSurface=reflectivityOut.microSurface;float roughness=reflectivityOut.roughness;\n#ifdef METALLICWORKFLOW\nsurfaceAlbedo=reflectivityOut.surfaceAlbedo;\n#endif\n#if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)\naoOut.ambientOcclusionColor=reflectivityOut.ambientOcclusionColor;\n#endif\n#ifdef ALPHAFRESNEL\n#if defined(ALPHATEST) || defined(ALPHABLEND)\nalphaFresnelOutParams alphaFresnelOut;alphaFresnelBlock(\nnormalW,\nviewDirectionW,\nalpha,\nmicroSurface,\nalphaFresnelOut\n);alpha=alphaFresnelOut.alpha;\n#endif\n#endif\n#include\n#ifdef ANISOTROPIC\nanisotropicOutParams anisotropicOut;\n#ifdef ANISOTROPIC_TEXTURE\nvec3 anisotropyMapData=texture2D(anisotropySampler,vAnisotropyUV+uvOffset).rgb*vAnisotropyInfos.y;\n#endif\nanisotropicBlock(\nvAnisotropy,\nroughness,\n#ifdef ANISOTROPIC_TEXTURE\nanisotropyMapData,\n#endif\nTBN,\nnormalW,\nviewDirectionW,\nanisotropicOut\n);\n#endif\n#ifdef REFLECTION\nreflectionOutParams reflectionOut;\n#ifndef USE_CUSTOM_REFLECTION\nreflectionBlock(\nvPositionW,\nnormalW,\nalphaG,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\n#ifdef ANISOTROPIC\nanisotropicOut,\n#endif\n#if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)\nNdotVUnclamped,\n#endif\n#ifdef LINEARSPECULARREFLECTION\nroughness,\n#endif\nreflectionSampler,\n#if defined(NORMAL) && defined(USESPHERICALINVERTEX)\nvEnvironmentIrradiance,\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nreflectionMatrix,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\nirradianceSampler,\n#endif\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\nreflectionOut\n);\n#else\n#define CUSTOM_REFLECTION\n#endif\n#endif\n#include\n#ifdef SHEEN\nsheenOutParams sheenOut;\n#ifdef SHEEN_TEXTURE\nvec4 sheenMapData=texture2D(sheenSampler,vSheenUV+uvOffset);\n#endif\n#if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)\nvec4 sheenMapRoughnessData=texture2D(sheenRoughnessSampler,vSheenRoughnessUV+uvOffset)*vSheenInfos.w;\n#endif\nsheenBlock(\nvSheenColor,\n#ifdef SHEEN_ROUGHNESS\nvSheenRoughness,\n#if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)\nsheenMapRoughnessData,\n#endif\n#endif\nroughness,\n#ifdef SHEEN_TEXTURE\nsheenMapData,\nvSheenInfos.y,\n#endif\nreflectance,\n#ifdef SHEEN_LINKWITHALBEDO\nbaseColor,\nsurfaceAlbedo,\n#endif\n#ifdef ENVIRONMENTBRDF\nNdotV,\nenvironmentBrdf,\n#endif\n#if defined(REFLECTION) && defined(ENVIRONMENTBRDF)\nAARoughnessFactors,\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\nvLightingIntensity,\nreflectionSampler,\nreflectionOut.reflectionCoords,\nNdotVUnclamped,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)\nseo,\n#endif\n#if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)\neho,\n#endif\n#endif\nsheenOut\n);\n#ifdef SHEEN_LINKWITHALBEDO\nsurfaceAlbedo=sheenOut.surfaceAlbedo;\n#endif\n#endif\n#ifdef CLEARCOAT\n#ifdef CLEARCOAT_TEXTURE\nvec2 clearCoatMapData=texture2D(clearCoatSampler,vClearCoatUV+uvOffset).rg*vClearCoatInfos.y;\n#endif\n#endif\n#ifdef IRIDESCENCE\niridescenceOutParams iridescenceOut;\n#ifdef IRIDESCENCE_TEXTURE\nvec2 iridescenceMapData=texture2D(iridescenceSampler,vIridescenceUV+uvOffset).rg*vIridescenceInfos.y;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nvec2 iridescenceThicknessMapData=texture2D(iridescenceThicknessSampler,vIridescenceThicknessUV+uvOffset).rg*vIridescenceInfos.w;\n#endif\niridescenceBlock(\nvIridescenceParams,\nNdotV,\nspecularEnvironmentR0,\n#ifdef IRIDESCENCE_TEXTURE\niridescenceMapData,\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\niridescenceThicknessMapData,\n#endif\n#ifdef CLEARCOAT\nNdotVUnclamped,\n#ifdef CLEARCOAT_TEXTURE\nclearCoatMapData,\n#endif\n#endif\niridescenceOut\n);float iridescenceIntensity=iridescenceOut.iridescenceIntensity;specularEnvironmentR0=iridescenceOut.specularEnvironmentR0;\n#endif\nclearcoatOutParams clearcoatOut;\n#ifdef CLEARCOAT\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\nvec4 clearCoatMapRoughnessData=texture2D(clearCoatRoughnessSampler,vClearCoatRoughnessUV+uvOffset)*vClearCoatInfos.w;\n#endif\n#if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)\nvec4 clearCoatTintMapData=texture2D(clearCoatTintSampler,vClearCoatTintUV+uvOffset);\n#endif\n#ifdef CLEARCOAT_BUMP\nvec4 clearCoatBumpMapData=texture2D(clearCoatBumpSampler,vClearCoatBumpUV+uvOffset);\n#endif\nclearcoatBlock(\nvPositionW,\ngeometricNormalW,\nviewDirectionW,\nvClearCoatParams,\n#if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)\nclearCoatMapRoughnessData,\n#endif\nspecularEnvironmentR0,\n#ifdef CLEARCOAT_TEXTURE\nclearCoatMapData,\n#endif\n#ifdef CLEARCOAT_TINT\nvClearCoatTintParams,\nclearCoatColorAtDistance,\nvClearCoatRefractionParams,\n#ifdef CLEARCOAT_TINT_TEXTURE\nclearCoatTintMapData,\n#endif\n#endif\n#ifdef CLEARCOAT_BUMP\nvClearCoatBumpInfos,\nclearCoatBumpMapData,\nvClearCoatBumpUV,\n#if defined(TANGENT) && defined(NORMAL)\nvTBN,\n#else\nvClearCoatTangentSpaceParams,\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\nnormalMatrix,\n#endif\n#endif\n#if defined(FORCENORMALFORWARD) && defined(NORMAL)\nfaceNormal,\n#endif\n#ifdef REFLECTION\nvReflectionMicrosurfaceInfos,\nvReflectionInfos,\nvReflectionColor,\nvLightingIntensity,\nreflectionSampler,\n#ifndef LODBASEDMICROSFURACE\nreflectionSamplerLow,\nreflectionSamplerHigh,\n#endif\n#ifdef REALTIME_FILTERING\nvReflectionFilteringInfo,\n#endif\n#endif\n#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)\n#ifdef RADIANCEOCCLUSION\nambientMonochrome,\n#endif\n#endif\n#if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)\n(gl_FrontFacing ? 1. : -1.),\n#endif\nclearcoatOut\n);\n#else\nclearcoatOut.specularEnvironmentR0=specularEnvironmentR0;\n#endif\n#include\nsubSurfaceOutParams subSurfaceOut;\n#ifdef SUBSURFACE\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nvec4 thicknessMap=texture2D(thicknessSampler,vThicknessUV+uvOffset);\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nvec4 refractionIntensityMap=texture2D(refractionIntensitySampler,vRefractionIntensityUV+uvOffset);\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nvec4 translucencyIntensityMap=texture2D(translucencyIntensitySampler,vTranslucencyIntensityUV+uvOffset);\n#endif\nsubSurfaceBlock(\nvSubSurfaceIntensity,\nvThicknessParam,\nvTintColor,\nnormalW,\nspecularEnvironmentReflectance,\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nthicknessMap,\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nrefractionIntensityMap,\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\ntranslucencyIntensityMap,\n#endif\n#ifdef REFLECTION\n#ifdef SS_TRANSLUCENCY\nreflectionMatrix,\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)\nreflectionOut.irradianceVector,\n#endif\n#if defined(REALTIME_FILTERING)\nreflectionSampler,\nvReflectionFilteringInfo,\n#endif\n#endif\n#ifdef USEIRRADIANCEMAP\nirradianceSampler,\n#endif\n#endif\n#endif\n#if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)\nsurfaceAlbedo,\n#endif\n#ifdef SS_REFRACTION\nvPositionW,\nviewDirectionW,\nview,\nvRefractionInfos,\nrefractionMatrix,\nvRefractionMicrosurfaceInfos,\nvLightingIntensity,\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nalpha,\n#endif\n#ifdef SS_LODINREFRACTIONALPHA\nNdotVUnclamped,\n#endif\n#ifdef SS_LINEARSPECULARREFRACTION\nroughness,\n#endif\nalphaG,\nrefractionSampler,\n#ifndef LODBASEDMICROSFURACE\nrefractionSamplerLow,\nrefractionSamplerHigh,\n#endif\n#ifdef ANISOTROPIC\nanisotropicOut,\n#endif\n#ifdef REALTIME_FILTERING\nvRefractionFilteringInfo,\n#endif\n#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC\nvRefractionPosition,\nvRefractionSize,\n#endif\n#endif\n#ifdef SS_TRANSLUCENCY\nvDiffusionDistance,\n#endif\nsubSurfaceOut\n);\n#ifdef SS_REFRACTION\nsurfaceAlbedo=subSurfaceOut.surfaceAlbedo;\n#ifdef SS_LINKREFRACTIONTOTRANSPARENCY\nalpha=subSurfaceOut.alpha;\n#endif\n#endif\n#else\nsubSurfaceOut.specularEnvironmentReflectance=specularEnvironmentReflectance;\n#endif\n#include\n#include[0..maxSimultaneousLights]\n#include\n#endif \n#include\n#define CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\n#include\n#include\n#include(color,finalColor)\n#include\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\n#ifdef PREPASS\nfloat writeGeometryInfo=finalColor.a>0.4 ? 1.0 : 0.0;\n#ifdef PREPASS_POSITION\ngl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);\n#endif\n#ifdef PREPASS_VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);\n#endif\n#ifdef PREPASS_ALBEDO_SQRT\nvec3 sqAlbedo=sqrt(surfaceAlbedo); \n#endif\n#ifdef PREPASS_IRRADIANCE\nvec3 irradiance=finalDiffuse;\n#ifndef UNLIT\n#ifdef REFLECTION\nirradiance+=finalIrradiance;\n#endif\n#endif\n#ifdef SS_SCATTERING\ngl_FragData[0]=vec4(finalColor.rgb-irradiance,finalColor.a); \nirradiance/=sqAlbedo;\n#else\ngl_FragData[0]=finalColor; \nfloat scatteringDiffusionProfile=255.;\n#endif\ngl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(clamp(irradiance,vec3(0.),vec3(1.)),writeGeometryInfo*scatteringDiffusionProfile/255.); \n#else\ngl_FragData[0]=vec4(finalColor.rgb,finalColor.a);\n#endif\n#ifdef PREPASS_DEPTH\ngl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_NORMAL\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo); \n#endif\n#ifdef PREPASS_ALBEDO_SQRT\ngl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(sqAlbedo,writeGeometryInfo); \n#endif\n#ifdef PREPASS_REFLECTIVITY\n#ifndef UNLIT\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(specularEnvironmentR0,microSurface)*writeGeometryInfo;\n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4( 0.0,0.0,0.0,1.0 )*writeGeometryInfo;\n#endif\n#endif\n#endif\n#if !defined(PREPASS) || defined(WEBGL2)\ngl_FragColor=finalColor;\n#endif\n#include\n#if ORDER_INDEPENDENT_TRANSPARENCY\nif (fragDepth==nearestDepth) {frontColor.rgb+=finalColor.rgb*finalColor.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-finalColor.a);} else {backColor+=finalColor;}\n#endif\n#include\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const pbrPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalVertexDeclaration\";\n\nconst name = \"pbrVertexDeclaration\";\nconst shader = `uniform mat4 view;uniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;uniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec4 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;uniform mat4 reflectivityMatrix;\n#endif\n#ifdef METALLIC_REFLECTANCE\nuniform vec2 vMetallicReflectanceInfos;uniform mat4 metallicReflectanceMatrix;\n#endif\n#ifdef REFLECTANCE\nuniform vec2 vReflectanceInfos;uniform mat4 reflectanceMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;uniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;\n#endif\n#ifdef CLEARCOAT\n#if defined(CLEARCOAT_TEXTURE) || defined(CLEARCOAT_TEXTURE_ROUGHNESS)\nuniform vec4 vClearCoatInfos;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nuniform mat4 clearCoatMatrix;\n#endif\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS\nuniform mat4 clearCoatRoughnessMatrix;\n#endif\n#ifdef CLEARCOAT_BUMP\nuniform vec2 vClearCoatBumpInfos;uniform mat4 clearCoatBumpMatrix;\n#endif\n#ifdef CLEARCOAT_TINT_TEXTURE\nuniform vec2 vClearCoatTintInfos;uniform mat4 clearCoatTintMatrix;\n#endif\n#endif\n#ifdef IRIDESCENCE\n#if defined(IRIDESCENCE_TEXTURE) || defined(IRIDESCENCE_THICKNESS_TEXTURE)\nuniform vec4 vIridescenceInfos;\n#endif\n#ifdef IRIDESCENCE_TEXTURE\nuniform mat4 iridescenceMatrix;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nuniform mat4 iridescenceThicknessMatrix;\n#endif\n#endif\n#ifdef ANISOTROPIC\n#ifdef ANISOTROPIC_TEXTURE\nuniform vec2 vAnisotropyInfos;uniform mat4 anisotropyMatrix;\n#endif\n#endif\n#ifdef SHEEN\n#if defined(SHEEN_TEXTURE) || defined(SHEEN_TEXTURE_ROUGHNESS)\nuniform vec4 vSheenInfos;\n#endif\n#ifdef SHEEN_TEXTURE\nuniform mat4 sheenMatrix;\n#endif\n#ifdef SHEEN_TEXTURE_ROUGHNESS\nuniform mat4 sheenRoughnessMatrix;\n#endif\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\nuniform vec4 vRefractionInfos;uniform mat4 refractionMatrix;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nuniform vec2 vThicknessInfos;uniform mat4 thicknessMatrix;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nuniform vec2 vRefractionIntensityInfos;uniform mat4 refractionIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nuniform vec2 vTranslucencyIntensityInfos;uniform mat4 translucencyIntensityMatrix;\n#endif\n#endif\n#ifdef NORMAL\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nuniform vec3 vSphericalL00;uniform vec3 vSphericalL1_1;uniform vec3 vSphericalL10;uniform vec3 vSphericalL11;uniform vec3 vSphericalL2_2;uniform vec3 vSphericalL2_1;uniform vec3 vSphericalL20;uniform vec3 vSphericalL21;uniform vec3 vSphericalL22;\n#else\nuniform vec3 vSphericalX;uniform vec3 vSphericalY;uniform vec3 vSphericalZ;uniform vec3 vSphericalXX_ZZ;uniform vec3 vSphericalYY_ZZ;uniform vec3 vSphericalZZ;uniform vec3 vSphericalXY;uniform vec3 vSphericalYZ;uniform vec3 vSphericalZX;\n#endif\n#endif\n#endif\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/pbrVertexDeclaration\";\nimport \"./ShadersInclude/pbrUboDeclaration\";\nimport \"./ShadersInclude/uvAttributeDeclaration\";\nimport \"./ShadersInclude/mainUVVaryingDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/prePassVertexDeclaration\";\nimport \"./ShadersInclude/samplerVertexDeclaration\";\nimport \"./ShadersInclude/harmonicsFunctions\";\nimport \"./ShadersInclude/bumpVertexDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/fogVertexDeclaration\";\nimport \"./ShadersInclude/lightVxFragmentDeclaration\";\nimport \"./ShadersInclude/lightVxUboDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobal\";\nimport \"./ShadersInclude/morphTargetsVertex\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/prePassVertex\";\nimport \"./ShadersInclude/uvVariableDeclaration\";\nimport \"./ShadersInclude/samplerVertexImplementation\";\nimport \"./ShadersInclude/bumpVertex\";\nimport \"./ShadersInclude/clipPlaneVertex\";\nimport \"./ShadersInclude/fogVertex\";\nimport \"./ShadersInclude/shadowsVertex\";\nimport \"./ShadersInclude/vertexColorMixing\";\nimport \"./ShadersInclude/logDepthVertex\";\n\nconst name = \"pbrVertexShader\";\nconst shader = `precision highp float;\n#include<__decl__pbrVertex>\n#define CUSTOM_VERTEX_BEGIN\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#include[2..7]\n#include[1..7]\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n#include\n#include\n#include\n#include(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap)\n#include(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity)\n#include(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler)\n#include(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance)\n#include(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance)\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal)\n#ifdef CLEARCOAT\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat)\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness)\n#include(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump)\n#include(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint)\n#endif\n#ifdef IRIDESCENCE\n#include(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence)\n#include(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness)\n#endif\n#ifdef SHEEN\n#include(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen)\n#include(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness)\n#endif\n#ifdef ANISOTROPIC\n#include(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy)\n#endif\n#ifdef SUBSURFACE\n#include(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness)\n#include(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity)\n#include(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity)\n#endif\nvarying vec3 vPositionW;\n#if DEBUGMODE>0\nvarying vec4 vClipSpacePosition;\n#endif\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvarying vec3 vEnvironmentIrradiance;\n#include\n#endif\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include\n#include<__decl__lightVxFragment>[0..maxSimultaneousLights]\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif\n#define CUSTOM_VERTEX_UPDATE_POSITION\n#define CUSTOM_VERTEX_UPDATE_NORMAL\n#include\n#if defined(PREPASS) && defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);vPositionW=vec3(worldPos);\n#include\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#if defined(INSTANCES) && defined(THIN_INSTANCES)\nvNormalW=normalUpdated/vec3(dot(normalWorld[0],normalWorld[0]),dot(normalWorld[1],normalWorld[1]),dot(normalWorld[2],normalWorld[2]));vNormalW=normalize(normalWorld*vNormalW);\n#else\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\nvec3 reflectionVector=vec3(reflectionMatrix*vec4(vNormalW,0)).xyz;\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\nvEnvironmentIrradiance=computeEnvironmentIrradiance(reflectionVector);\n#endif\n#endif\n#define CUSTOM_VERTEX_UPDATE_WORLDPOS\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\n#if DEBUGMODE>0\nvClipSpacePosition=gl_Position;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n#ifndef UV1\nvec2 uvUpdated=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uvUpdated;\n#endif\n#include[2..7]\n#include(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo,_MATRIXNAME_,albedo,_INFONAME_,AlbedoInfos.x)\n#include(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_MATRIXNAME_,detail,_INFONAME_,DetailInfos.x)\n#include(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_MATRIXNAME_,ambient,_INFONAME_,AmbientInfos.x)\n#include(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_MATRIXNAME_,opacity,_INFONAME_,OpacityInfos.x)\n#include(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_MATRIXNAME_,emissive,_INFONAME_,EmissiveInfos.x)\n#include(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_MATRIXNAME_,lightmap,_INFONAME_,LightmapInfos.x)\n#include(_DEFINENAME_,REFLECTIVITY,_VARYINGNAME_,Reflectivity,_MATRIXNAME_,reflectivity,_INFONAME_,ReflectivityInfos.x)\n#include(_DEFINENAME_,MICROSURFACEMAP,_VARYINGNAME_,MicroSurfaceSampler,_MATRIXNAME_,microSurfaceSampler,_INFONAME_,MicroSurfaceSamplerInfos.x)\n#include(_DEFINENAME_,METALLIC_REFLECTANCE,_VARYINGNAME_,MetallicReflectance,_MATRIXNAME_,metallicReflectance,_INFONAME_,MetallicReflectanceInfos.x)\n#include(_DEFINENAME_,REFLECTANCE,_VARYINGNAME_,Reflectance,_MATRIXNAME_,reflectance,_INFONAME_,ReflectanceInfos.x)\n#include(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_MATRIXNAME_,bump,_INFONAME_,BumpInfos.x)\n#include(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_MATRIXNAME_,decal,_INFONAME_,DecalInfos.x)\n#ifdef CLEARCOAT\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE,_VARYINGNAME_,ClearCoat,_MATRIXNAME_,clearCoat,_INFONAME_,ClearCoatInfos.x)\n#include(_DEFINENAME_,CLEARCOAT_TEXTURE_ROUGHNESS,_VARYINGNAME_,ClearCoatRoughness,_MATRIXNAME_,clearCoatRoughness,_INFONAME_,ClearCoatInfos.z)\n#include(_DEFINENAME_,CLEARCOAT_BUMP,_VARYINGNAME_,ClearCoatBump,_MATRIXNAME_,clearCoatBump,_INFONAME_,ClearCoatBumpInfos.x)\n#include(_DEFINENAME_,CLEARCOAT_TINT_TEXTURE,_VARYINGNAME_,ClearCoatTint,_MATRIXNAME_,clearCoatTint,_INFONAME_,ClearCoatTintInfos.x)\n#endif\n#ifdef IRIDESCENCE\n#include(_DEFINENAME_,IRIDESCENCE_TEXTURE,_VARYINGNAME_,Iridescence,_MATRIXNAME_,iridescence,_INFONAME_,IridescenceInfos.x)\n#include(_DEFINENAME_,IRIDESCENCE_THICKNESS_TEXTURE,_VARYINGNAME_,IridescenceThickness,_MATRIXNAME_,iridescenceThickness,_INFONAME_,IridescenceInfos.z)\n#endif\n#ifdef SHEEN\n#include(_DEFINENAME_,SHEEN_TEXTURE,_VARYINGNAME_,Sheen,_MATRIXNAME_,sheen,_INFONAME_,SheenInfos.x)\n#include(_DEFINENAME_,SHEEN_TEXTURE_ROUGHNESS,_VARYINGNAME_,SheenRoughness,_MATRIXNAME_,sheen,_INFONAME_,SheenInfos.z)\n#endif\n#ifdef ANISOTROPIC\n#include(_DEFINENAME_,ANISOTROPIC_TEXTURE,_VARYINGNAME_,Anisotropy,_MATRIXNAME_,anisotropy,_INFONAME_,AnisotropyInfos.x)\n#endif\n#ifdef SUBSURFACE\n#include(_DEFINENAME_,SS_THICKNESSANDMASK_TEXTURE,_VARYINGNAME_,Thickness,_MATRIXNAME_,thickness,_INFONAME_,ThicknessInfos.x)\n#include(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity,_MATRIXNAME_,refractionIntensity,_INFONAME_,RefractionIntensityInfos.x)\n#include(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity,_MATRIXNAME_,translucencyIntensity,_INFONAME_,TranslucencyIntensityInfos.x)\n#endif\n#include\n#include\n#include\n#include[0..maxSimultaneousLights]\n#include\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const pbrVertexShader = { name, shader };\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../../types\";\r\nimport { serialize, serializeAsTexture, expandToProperty, serializeAsColor3 } from \"../../Misc/decorators\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { MaterialFlags } from \"../materialFlags\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\nimport type { EffectFallbacks } from \"../effectFallbacks\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { MaterialPluginBase } from \"../materialPluginBase\";\r\nimport { MaterialDefines } from \"../materialDefines\";\r\n\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialClearCoatDefines extends MaterialDefines {\r\n public CLEARCOAT = false;\r\n public CLEARCOAT_DEFAULTIOR = false;\r\n public CLEARCOAT_TEXTURE = false;\r\n public CLEARCOAT_TEXTURE_ROUGHNESS = false;\r\n public CLEARCOAT_TEXTUREDIRECTUV = 0;\r\n public CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV = 0;\r\n public CLEARCOAT_BUMP = false;\r\n public CLEARCOAT_BUMPDIRECTUV = 0;\r\n public CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\r\n public CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL = false;\r\n public CLEARCOAT_REMAP_F0 = false;\r\n\r\n public CLEARCOAT_TINT = false;\r\n public CLEARCOAT_TINT_TEXTURE = false;\r\n public CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;\r\n public CLEARCOAT_TINT_GAMMATEXTURE = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the clear coat component of the PBR material\r\n */\r\nexport class PBRClearCoatConfiguration extends MaterialPluginBase {\r\n protected _material: PBRBaseMaterial;\r\n\r\n /**\r\n * This defaults to 1.5 corresponding to a 0.04 f0 or a 4% reflectance at normal incidence\r\n * The default fits with a polyurethane material.\r\n * @internal\r\n */\r\n public static readonly _DefaultIndexOfRefraction = 1.5;\r\n\r\n private _isEnabled = false;\r\n /**\r\n * Defines if the clear coat is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n /**\r\n * Defines the clear coat layer strength (between 0 and 1) it defaults to 1.\r\n */\r\n @serialize()\r\n public intensity: number = 1;\r\n\r\n /**\r\n * Defines the clear coat layer roughness.\r\n */\r\n @serialize()\r\n public roughness: number = 0;\r\n\r\n private _indexOfRefraction = PBRClearCoatConfiguration._DefaultIndexOfRefraction;\r\n /**\r\n * Defines the index of refraction of the clear coat.\r\n * This defaults to 1.5 corresponding to a 0.04 f0 or a 4% reflectance at normal incidence\r\n * The default fits with a polyurethane material.\r\n * Changing the default value is more performance intensive.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public indexOfRefraction = PBRClearCoatConfiguration._DefaultIndexOfRefraction;\r\n\r\n private _texture: Nullable = null;\r\n /**\r\n * Stores the clear coat values in a texture (red channel is intensity and green channel is roughness)\r\n * If useRoughnessFromMainTexture is false, the green channel of texture is not used and the green channel of textureRoughness is used instead\r\n * if textureRoughness is not empty, else no texture roughness is used\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public texture: Nullable = null;\r\n\r\n private _useRoughnessFromMainTexture = true;\r\n /**\r\n * Indicates that the green channel of the texture property will be used for roughness (default: true)\r\n * If false, the green channel from textureRoughness is used for roughness\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRoughnessFromMainTexture = true;\r\n\r\n private _textureRoughness: Nullable = null;\r\n /**\r\n * Stores the clear coat roughness in a texture (green channel)\r\n * Not used if useRoughnessFromMainTexture is true\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public textureRoughness: Nullable = null;\r\n\r\n private _remapF0OnInterfaceChange = true;\r\n /**\r\n * Defines if the F0 value should be remapped to account for the interface change in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public remapF0OnInterfaceChange = true;\r\n\r\n private _bumpTexture: Nullable = null;\r\n /**\r\n * Define the clear coat specific bump texture.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public bumpTexture: Nullable = null;\r\n\r\n private _isTintEnabled = false;\r\n /**\r\n * Defines if the clear coat tint is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isTintEnabled = false;\r\n\r\n /**\r\n * Defines the clear coat tint of the material.\r\n * This is only use if tint is enabled\r\n */\r\n @serializeAsColor3()\r\n public tintColor = Color3.White();\r\n\r\n /**\r\n * Defines the distance at which the tint color should be found in the\r\n * clear coat media.\r\n * This is only use if tint is enabled\r\n */\r\n @serialize()\r\n public tintColorAtDistance = 1;\r\n\r\n /**\r\n * Defines the clear coat layer thickness.\r\n * This is only use if tint is enabled\r\n */\r\n @serialize()\r\n public tintThickness: number = 1;\r\n\r\n private _tintTexture: Nullable = null;\r\n /**\r\n * Stores the clear tint values in a texture.\r\n * rgb is tint\r\n * a is a thickness factor\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public tintTexture: Nullable = null;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial, addToPluginList = true) {\r\n super(material, \"PBRClearCoat\", 100, new MaterialClearCoatDefines(), addToPluginList);\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: MaterialClearCoatDefines, scene: Scene, engine: Engine): boolean {\r\n if (!this._isEnabled) {\r\n return true;\r\n }\r\n\r\n const disableBumpMap = this._material._disableBumpMap;\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {\r\n if (!this._texture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._textureRoughness && MaterialFlags.ClearCoatTextureEnabled) {\r\n if (!this._textureRoughness.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.ClearCoatBumpTextureEnabled && !disableBumpMap) {\r\n // Bump texture cannot be not blocking.\r\n if (!this._bumpTexture.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._isTintEnabled && this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\r\n if (!this._tintTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public prepareDefinesBeforeAttributes(defines: MaterialClearCoatDefines, scene: Scene): void {\r\n if (this._isEnabled) {\r\n defines.CLEARCOAT = true;\r\n defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = this._useRoughnessFromMainTexture;\r\n defines.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL =\r\n this._texture !== null && this._texture._texture === this._textureRoughness?._texture && this._texture.checkTransformsAreIdentical(this._textureRoughness);\r\n defines.CLEARCOAT_REMAP_F0 = this._remapF0OnInterfaceChange;\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"CLEARCOAT_TEXTURE\");\r\n } else {\r\n defines.CLEARCOAT_TEXTURE = false;\r\n }\r\n\r\n if (this._textureRoughness && MaterialFlags.ClearCoatTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._textureRoughness, defines, \"CLEARCOAT_TEXTURE_ROUGHNESS\");\r\n } else {\r\n defines.CLEARCOAT_TEXTURE_ROUGHNESS = false;\r\n }\r\n\r\n if (this._bumpTexture && MaterialFlags.ClearCoatBumpTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, \"CLEARCOAT_BUMP\");\r\n } else {\r\n defines.CLEARCOAT_BUMP = false;\r\n }\r\n\r\n defines.CLEARCOAT_DEFAULTIOR = this._indexOfRefraction === PBRClearCoatConfiguration._DefaultIndexOfRefraction;\r\n\r\n if (this._isTintEnabled) {\r\n defines.CLEARCOAT_TINT = true;\r\n if (this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._tintTexture, defines, \"CLEARCOAT_TINT_TEXTURE\");\r\n defines.CLEARCOAT_TINT_GAMMATEXTURE = this._tintTexture.gammaSpace;\r\n } else {\r\n defines.CLEARCOAT_TINT_TEXTURE = false;\r\n }\r\n } else {\r\n defines.CLEARCOAT_TINT = false;\r\n defines.CLEARCOAT_TINT_TEXTURE = false;\r\n }\r\n }\r\n }\r\n } else {\r\n defines.CLEARCOAT = false;\r\n defines.CLEARCOAT_TEXTURE = false;\r\n defines.CLEARCOAT_TEXTURE_ROUGHNESS = false;\r\n defines.CLEARCOAT_BUMP = false;\r\n defines.CLEARCOAT_TINT = false;\r\n defines.CLEARCOAT_TINT_TEXTURE = false;\r\n defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\r\n defines.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL = false;\r\n defines.CLEARCOAT_DEFAULTIOR = false;\r\n defines.CLEARCOAT_TEXTUREDIRECTUV = 0;\r\n defines.CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV = 0;\r\n defines.CLEARCOAT_BUMPDIRECTUV = 0;\r\n defines.CLEARCOAT_REMAP_F0 = false;\r\n defines.CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;\r\n defines.CLEARCOAT_TINT_GAMMATEXTURE = false;\r\n }\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {\r\n if (!this._isEnabled) {\r\n return;\r\n }\r\n\r\n const defines = subMesh!.materialDefines as unknown as MaterialClearCoatDefines;\r\n\r\n const isFrozen = this._material.isFrozen;\r\n\r\n const disableBumpMap = this._material._disableBumpMap;\r\n const invertNormalMapX = this._material._invertNormalMapX;\r\n const invertNormalMapY = this._material._invertNormalMapY;\r\n\r\n const identicalTextures = defines.CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL;\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n if (identicalTextures && MaterialFlags.ClearCoatTextureEnabled) {\r\n uniformBuffer.updateFloat4(\"vClearCoatInfos\", this._texture!.coordinatesIndex, this._texture!.level, -1, -1);\r\n MaterialHelper.BindTextureMatrix(this._texture!, uniformBuffer, \"clearCoat\");\r\n } else if ((this._texture || this._textureRoughness) && MaterialFlags.ClearCoatTextureEnabled) {\r\n uniformBuffer.updateFloat4(\r\n \"vClearCoatInfos\",\r\n this._texture?.coordinatesIndex ?? 0,\r\n this._texture?.level ?? 0,\r\n this._textureRoughness?.coordinatesIndex ?? 0,\r\n this._textureRoughness?.level ?? 0\r\n );\r\n if (this._texture) {\r\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"clearCoat\");\r\n }\r\n if (this._textureRoughness && !identicalTextures && !defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE) {\r\n MaterialHelper.BindTextureMatrix(this._textureRoughness, uniformBuffer, \"clearCoatRoughness\");\r\n }\r\n }\r\n\r\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.ClearCoatTextureEnabled && !disableBumpMap) {\r\n uniformBuffer.updateFloat2(\"vClearCoatBumpInfos\", this._bumpTexture.coordinatesIndex, this._bumpTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._bumpTexture, uniformBuffer, \"clearCoatBump\");\r\n\r\n if (scene._mirroredCameraPosition) {\r\n uniformBuffer.updateFloat2(\"vClearCoatTangentSpaceParams\", invertNormalMapX ? 1.0 : -1.0, invertNormalMapY ? 1.0 : -1.0);\r\n } else {\r\n uniformBuffer.updateFloat2(\"vClearCoatTangentSpaceParams\", invertNormalMapX ? -1.0 : 1.0, invertNormalMapY ? -1.0 : 1.0);\r\n }\r\n }\r\n\r\n if (this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\r\n uniformBuffer.updateFloat2(\"vClearCoatTintInfos\", this._tintTexture.coordinatesIndex, this._tintTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._tintTexture, uniformBuffer, \"clearCoatTint\");\r\n }\r\n\r\n // Clear Coat General params\r\n uniformBuffer.updateFloat2(\"vClearCoatParams\", this.intensity, this.roughness);\r\n\r\n // Clear Coat Refraction params\r\n const a = 1 - this._indexOfRefraction;\r\n const b = 1 + this._indexOfRefraction;\r\n const f0 = Math.pow(-a / b, 2); // Schlicks approx: (ior1 - ior2) / (ior1 + ior2) where ior2 for air is close to vacuum = 1.\r\n const eta = 1 / this._indexOfRefraction;\r\n uniformBuffer.updateFloat4(\"vClearCoatRefractionParams\", f0, eta, a, b);\r\n\r\n if (this._isTintEnabled) {\r\n uniformBuffer.updateFloat4(\"vClearCoatTintParams\", this.tintColor.r, this.tintColor.g, this.tintColor.b, Math.max(0.00001, this.tintThickness));\r\n uniformBuffer.updateFloat(\"clearCoatColorAtDistance\", Math.max(0.00001, this.tintColorAtDistance));\r\n }\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {\r\n uniformBuffer.setTexture(\"clearCoatSampler\", this._texture);\r\n }\r\n\r\n if (this._textureRoughness && !identicalTextures && !defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE && MaterialFlags.ClearCoatTextureEnabled) {\r\n uniformBuffer.setTexture(\"clearCoatRoughnessSampler\", this._textureRoughness);\r\n }\r\n\r\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.ClearCoatBumpTextureEnabled && !disableBumpMap) {\r\n uniformBuffer.setTexture(\"clearCoatBumpSampler\", this._bumpTexture);\r\n }\r\n\r\n if (this._isTintEnabled && this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {\r\n uniformBuffer.setTexture(\"clearCoatTintSampler\", this._tintTexture);\r\n }\r\n }\r\n }\r\n\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (this._texture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._textureRoughness === texture) {\r\n return true;\r\n }\r\n\r\n if (this._bumpTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._tintTexture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._texture) {\r\n activeTextures.push(this._texture);\r\n }\r\n\r\n if (this._textureRoughness) {\r\n activeTextures.push(this._textureRoughness);\r\n }\r\n\r\n if (this._bumpTexture) {\r\n activeTextures.push(this._bumpTexture);\r\n }\r\n\r\n if (this._tintTexture) {\r\n activeTextures.push(this._tintTexture);\r\n }\r\n }\r\n\r\n public getAnimatables(animatables: IAnimatable[]): void {\r\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\r\n animatables.push(this._texture);\r\n }\r\n\r\n if (this._textureRoughness && this._textureRoughness.animations && this._textureRoughness.animations.length > 0) {\r\n animatables.push(this._textureRoughness);\r\n }\r\n\r\n if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {\r\n animatables.push(this._bumpTexture);\r\n }\r\n\r\n if (this._tintTexture && this._tintTexture.animations && this._tintTexture.animations.length > 0) {\r\n animatables.push(this._tintTexture);\r\n }\r\n }\r\n\r\n public dispose(forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n this._texture?.dispose();\r\n this._textureRoughness?.dispose();\r\n this._bumpTexture?.dispose();\r\n this._tintTexture?.dispose();\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return \"PBRClearCoatConfiguration\";\r\n }\r\n\r\n public addFallbacks(defines: MaterialClearCoatDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n if (defines.CLEARCOAT_BUMP) {\r\n fallbacks.addFallback(currentRank++, \"CLEARCOAT_BUMP\");\r\n }\r\n if (defines.CLEARCOAT_TINT) {\r\n fallbacks.addFallback(currentRank++, \"CLEARCOAT_TINT\");\r\n }\r\n if (defines.CLEARCOAT) {\r\n fallbacks.addFallback(currentRank++, \"CLEARCOAT\");\r\n }\r\n return currentRank;\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"clearCoatSampler\", \"clearCoatRoughnessSampler\", \"clearCoatBumpSampler\", \"clearCoatTintSampler\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vClearCoatParams\", size: 2, type: \"vec2\" },\r\n { name: \"vClearCoatRefractionParams\", size: 4, type: \"vec4\" },\r\n { name: \"vClearCoatInfos\", size: 4, type: \"vec4\" },\r\n { name: \"clearCoatMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"clearCoatRoughnessMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"vClearCoatBumpInfos\", size: 2, type: \"vec2\" },\r\n { name: \"vClearCoatTangentSpaceParams\", size: 2, type: \"vec2\" },\r\n { name: \"clearCoatBumpMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"vClearCoatTintParams\", size: 4, type: \"vec4\" },\r\n { name: \"clearCoatColorAtDistance\", size: 1, type: \"float\" },\r\n { name: \"vClearCoatTintInfos\", size: 2, type: \"vec2\" },\r\n { name: \"clearCoatTintMatrix\", size: 16, type: \"mat4\" },\r\n ],\r\n };\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../../types\";\r\nimport { serialize, serializeAsTexture, expandToProperty } from \"../../Misc/decorators\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { MaterialFlags } from \"../materialFlags\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\nimport type { EffectFallbacks } from \"../effectFallbacks\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { MaterialPluginBase } from \"../materialPluginBase\";\r\nimport { MaterialDefines } from \"../materialDefines\";\r\n\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialIridescenceDefines extends MaterialDefines {\r\n public IRIDESCENCE = false;\r\n public IRIDESCENCE_TEXTURE = false;\r\n public IRIDESCENCE_TEXTUREDIRECTUV = 0;\r\n public IRIDESCENCE_THICKNESS_TEXTURE = false;\r\n public IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV = 0;\r\n public IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the iridescence (thin film) component of the PBR material\r\n */\r\nexport class PBRIridescenceConfiguration extends MaterialPluginBase {\r\n protected _material: PBRBaseMaterial;\r\n\r\n /**\r\n * The default minimum thickness of the thin-film layer given in nanometers (nm).\r\n * Defaults to 100 nm.\r\n * @internal\r\n */\r\n public static readonly _DefaultMinimumThickness = 100;\r\n\r\n /**\r\n * The default maximum thickness of the thin-film layer given in nanometers (nm).\r\n * Defaults to 400 nm.\r\n * @internal\r\n */\r\n public static readonly _DefaultMaximumThickness = 400;\r\n\r\n /**\r\n * The default index of refraction of the thin-film layer.\r\n * Defaults to 1.3\r\n * @internal\r\n */\r\n public static readonly _DefaultIndexOfRefraction = 1.3;\r\n\r\n private _isEnabled = false;\r\n /**\r\n * Defines if the iridescence is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n /**\r\n * Defines the iridescence layer strength (between 0 and 1) it defaults to 1.\r\n */\r\n @serialize()\r\n public intensity: number = 1;\r\n\r\n /**\r\n * Defines the minimum thickness of the thin-film layer given in nanometers (nm).\r\n */\r\n @serialize()\r\n public minimumThickness: number = PBRIridescenceConfiguration._DefaultMinimumThickness;\r\n\r\n /**\r\n * Defines the maximum thickness of the thin-film layer given in nanometers (nm). This will be the thickness used if not thickness texture has been set.\r\n */\r\n @serialize()\r\n public maximumThickness: number = PBRIridescenceConfiguration._DefaultMaximumThickness;\r\n\r\n /**\r\n * Defines the maximum thickness of the thin-film layer given in nanometers (nm).\r\n */\r\n @serialize()\r\n public indexOfRefraction: number = PBRIridescenceConfiguration._DefaultIndexOfRefraction;\r\n\r\n private _texture: Nullable = null;\r\n /**\r\n * Stores the iridescence intensity in a texture (red channel)\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public texture: Nullable = null;\r\n\r\n private _thicknessTexture: Nullable = null;\r\n /**\r\n * Stores the iridescence thickness in a texture (green channel)\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public thicknessTexture: Nullable = null;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial, addToPluginList = true) {\r\n super(material, \"PBRIridescence\", 110, new MaterialIridescenceDefines(), addToPluginList);\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: MaterialIridescenceDefines, scene: Scene): boolean {\r\n if (!this._isEnabled) {\r\n return true;\r\n }\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.IridescenceTextureEnabled) {\r\n if (!this._texture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {\r\n if (!this._thicknessTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public prepareDefinesBeforeAttributes(defines: MaterialIridescenceDefines, scene: Scene): void {\r\n if (this._isEnabled) {\r\n defines.IRIDESCENCE = true;\r\n defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE =\r\n this._texture !== null && this._texture._texture === this._thicknessTexture?._texture && this._texture.checkTransformsAreIdentical(this._thicknessTexture);\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.IridescenceTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"IRIDESCENCE_TEXTURE\");\r\n } else {\r\n defines.IRIDESCENCE_TEXTURE = false;\r\n }\r\n\r\n if (!defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE && this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._thicknessTexture, defines, \"IRIDESCENCE_THICKNESS_TEXTURE\");\r\n } else {\r\n defines.IRIDESCENCE_THICKNESS_TEXTURE = false;\r\n }\r\n }\r\n }\r\n } else {\r\n defines.IRIDESCENCE = false;\r\n defines.IRIDESCENCE_TEXTURE = false;\r\n defines.IRIDESCENCE_THICKNESS_TEXTURE = false;\r\n defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE = false;\r\n defines.IRIDESCENCE_TEXTUREDIRECTUV = 0;\r\n defines.IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV = 0;\r\n }\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {\r\n if (!this._isEnabled) {\r\n return;\r\n }\r\n\r\n const defines = subMesh!.materialDefines as unknown as MaterialIridescenceDefines;\r\n\r\n const isFrozen = this._material.isFrozen;\r\n\r\n const identicalTextures = defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE;\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n if (identicalTextures && MaterialFlags.IridescenceTextureEnabled) {\r\n uniformBuffer.updateFloat4(\"vIridescenceInfos\", this._texture!.coordinatesIndex, this._texture!.level, -1, -1);\r\n MaterialHelper.BindTextureMatrix(this._texture!, uniformBuffer, \"iridescence\");\r\n } else if ((this._texture || this._thicknessTexture) && MaterialFlags.IridescenceTextureEnabled) {\r\n uniformBuffer.updateFloat4(\r\n \"vIridescenceInfos\",\r\n this._texture?.coordinatesIndex ?? 0,\r\n this._texture?.level ?? 0,\r\n this._thicknessTexture?.coordinatesIndex ?? 0,\r\n this._thicknessTexture?.level ?? 0\r\n );\r\n if (this._texture) {\r\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"iridescence\");\r\n }\r\n if (this._thicknessTexture && !identicalTextures && !defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE) {\r\n MaterialHelper.BindTextureMatrix(this._thicknessTexture, uniformBuffer, \"iridescenceThickness\");\r\n }\r\n }\r\n\r\n // Clear Coat General params\r\n uniformBuffer.updateFloat4(\"vIridescenceParams\", this.intensity, this.indexOfRefraction, this.minimumThickness, this.maximumThickness);\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.IridescenceTextureEnabled) {\r\n uniformBuffer.setTexture(\"iridescenceSampler\", this._texture);\r\n }\r\n\r\n if (this._thicknessTexture && !identicalTextures && !defines.IRIDESCENCE_USE_THICKNESS_FROM_MAINTEXTURE && MaterialFlags.IridescenceTextureEnabled) {\r\n uniformBuffer.setTexture(\"iridescenceThicknessSampler\", this._thicknessTexture);\r\n }\r\n }\r\n }\r\n\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (this._texture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._thicknessTexture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._texture) {\r\n activeTextures.push(this._texture);\r\n }\r\n\r\n if (this._thicknessTexture) {\r\n activeTextures.push(this._thicknessTexture);\r\n }\r\n }\r\n\r\n public getAnimatables(animatables: IAnimatable[]): void {\r\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\r\n animatables.push(this._texture);\r\n }\r\n\r\n if (this._thicknessTexture && this._thicknessTexture.animations && this._thicknessTexture.animations.length > 0) {\r\n animatables.push(this._thicknessTexture);\r\n }\r\n }\r\n\r\n public dispose(forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n this._texture?.dispose();\r\n this._thicknessTexture?.dispose();\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return \"PBRIridescenceConfiguration\";\r\n }\r\n\r\n public addFallbacks(defines: MaterialIridescenceDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n if (defines.IRIDESCENCE) {\r\n fallbacks.addFallback(currentRank++, \"IRIDESCENCE\");\r\n }\r\n return currentRank;\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"iridescenceSampler\", \"iridescenceThicknessSampler\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vIridescenceParams\", size: 4, type: \"vec4\" },\r\n { name: \"vIridescenceInfos\", size: 4, type: \"vec4\" },\r\n { name: \"iridescenceMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"iridescenceThicknessMatrix\", size: 16, type: \"mat4\" },\r\n ],\r\n };\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { serialize, expandToProperty, serializeAsVector2, serializeAsTexture } from \"../../Misc/decorators\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { Vector2 } from \"../../Maths/math.vector\";\r\nimport { MaterialFlags } from \"../../Materials/materialFlags\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\nimport type { EffectFallbacks } from \"../effectFallbacks\";\r\nimport { MaterialPluginBase } from \"../materialPluginBase\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { MaterialDefines } from \"../materialDefines\";\r\n\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialAnisotropicDefines extends MaterialDefines {\r\n public ANISOTROPIC = false;\r\n public ANISOTROPIC_TEXTURE = false;\r\n public ANISOTROPIC_TEXTUREDIRECTUV = 0;\r\n public ANISOTROPIC_LEGACY = false;\r\n public MAINUV1 = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the anisotropic component of the PBR material\r\n */\r\nexport class PBRAnisotropicConfiguration extends MaterialPluginBase {\r\n private _isEnabled = false;\r\n /**\r\n * Defines if the anisotropy is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n /**\r\n * Defines the anisotropy strength (between 0 and 1) it defaults to 1.\r\n */\r\n @serialize()\r\n public intensity: number = 1;\r\n\r\n /**\r\n * Defines if the effect is along the tangents, bitangents or in between.\r\n * By default, the effect is \"stretching\" the highlights along the tangents.\r\n */\r\n @serializeAsVector2()\r\n public direction = new Vector2(1, 0);\r\n\r\n /**\r\n * Sets the anisotropy direction as an angle.\r\n */\r\n public set angle(value: number) {\r\n this.direction.x = Math.cos(value);\r\n this.direction.y = Math.sin(value);\r\n }\r\n\r\n /**\r\n * Gets the anisotropy angle value in radians.\r\n * @returns the anisotropy angle value in radians.\r\n */\r\n public get angle(): number {\r\n return Math.atan2(this.direction.y, this.direction.x);\r\n }\r\n\r\n private _texture: Nullable = null;\r\n /**\r\n * Stores the anisotropy values in a texture.\r\n * rg is direction (like normal from -1 to 1)\r\n * b is a intensity\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public texture: Nullable = null;\r\n\r\n private _legacy = false;\r\n /**\r\n * Defines if the anisotropy is in legacy mode for backwards compatibility before 6.4.0.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public legacy: boolean = false;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsMiscDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsMiscDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsMiscDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial, addToPluginList = true) {\r\n super(material, \"PBRAnisotropic\", 110, new MaterialAnisotropicDefines(), addToPluginList);\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[Constants.MATERIAL_MiscDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: MaterialAnisotropicDefines, scene: Scene): boolean {\r\n if (!this._isEnabled) {\r\n return true;\r\n }\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\r\n if (!this._texture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public prepareDefinesBeforeAttributes(defines: MaterialAnisotropicDefines, scene: Scene, mesh: AbstractMesh): void {\r\n if (this._isEnabled) {\r\n defines.ANISOTROPIC = this._isEnabled;\r\n if (this._isEnabled && !mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {\r\n defines._needUVs = true;\r\n defines.MAINUV1 = true;\r\n }\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"ANISOTROPIC_TEXTURE\");\r\n } else {\r\n defines.ANISOTROPIC_TEXTURE = false;\r\n }\r\n }\r\n }\r\n\r\n if (defines._areMiscDirty) {\r\n defines.ANISOTROPIC_LEGACY = this._legacy;\r\n }\r\n } else {\r\n defines.ANISOTROPIC = false;\r\n defines.ANISOTROPIC_TEXTURE = false;\r\n defines.ANISOTROPIC_TEXTUREDIRECTUV = 0;\r\n defines.ANISOTROPIC_LEGACY = false;\r\n }\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene): void {\r\n if (!this._isEnabled) {\r\n return;\r\n }\r\n\r\n const isFrozen = this._material.isFrozen;\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\r\n uniformBuffer.updateFloat2(\"vAnisotropyInfos\", this._texture.coordinatesIndex, this._texture.level);\r\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"anisotropy\");\r\n }\r\n\r\n // Anisotropy\r\n uniformBuffer.updateFloat3(\"vAnisotropy\", this.direction.x, this.direction.y, this.intensity);\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {\r\n uniformBuffer.setTexture(\"anisotropySampler\", this._texture);\r\n }\r\n }\r\n }\r\n\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (this._texture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._texture) {\r\n activeTextures.push(this._texture);\r\n }\r\n }\r\n\r\n public getAnimatables(animatables: IAnimatable[]): void {\r\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\r\n animatables.push(this._texture);\r\n }\r\n }\r\n\r\n public dispose(forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n if (this._texture) {\r\n this._texture.dispose();\r\n }\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return \"PBRAnisotropicConfiguration\";\r\n }\r\n\r\n public addFallbacks(defines: MaterialAnisotropicDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n if (defines.ANISOTROPIC) {\r\n fallbacks.addFallback(currentRank++, \"ANISOTROPIC\");\r\n }\r\n return currentRank;\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"anisotropySampler\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vAnisotropy\", size: 3, type: \"vec3\" },\r\n { name: \"vAnisotropyInfos\", size: 2, type: \"vec2\" },\r\n { name: \"anisotropyMatrix\", size: 16, type: \"mat4\" },\r\n ],\r\n };\r\n }\r\n\r\n /**\r\n * Parses a anisotropy Configuration from a serialized object.\r\n * @param source - Serialized object.\r\n * @param scene Defines the scene we are parsing for\r\n * @param rootUrl Defines the rootUrl to load from\r\n */\r\n public parse(source: any, scene: Scene, rootUrl: string): void {\r\n super.parse(source, scene, rootUrl);\r\n\r\n // Backward compatibility\r\n if (source.legacy === undefined) {\r\n this.legacy = true;\r\n }\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { serialize, expandToProperty, serializeAsColor3, serializeAsTexture } from \"../../Misc/decorators\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { MaterialFlags } from \"../../Materials/materialFlags\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\nimport type { EffectFallbacks } from \"../effectFallbacks\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { MaterialPluginBase } from \"../materialPluginBase\";\r\nimport { MaterialDefines } from \"../materialDefines\";\r\n\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialSheenDefines extends MaterialDefines {\r\n public SHEEN = false;\r\n public SHEEN_TEXTURE = false;\r\n public SHEEN_GAMMATEXTURE = false;\r\n public SHEEN_TEXTURE_ROUGHNESS = false;\r\n public SHEEN_TEXTUREDIRECTUV = 0;\r\n public SHEEN_TEXTURE_ROUGHNESSDIRECTUV = 0;\r\n public SHEEN_LINKWITHALBEDO = false;\r\n public SHEEN_ROUGHNESS = false;\r\n public SHEEN_ALBEDOSCALING = false;\r\n public SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\r\n public SHEEN_TEXTURE_ROUGHNESS_IDENTICAL = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the sheen component of the PBR material.\r\n */\r\nexport class PBRSheenConfiguration extends MaterialPluginBase {\r\n private _isEnabled = false;\r\n /**\r\n * Defines if the material uses sheen.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n private _linkSheenWithAlbedo = false;\r\n /**\r\n * Defines if the sheen is linked to the sheen color.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public linkSheenWithAlbedo = false;\r\n\r\n /**\r\n * Defines the sheen intensity.\r\n */\r\n @serialize()\r\n public intensity = 1;\r\n\r\n /**\r\n * Defines the sheen color.\r\n */\r\n @serializeAsColor3()\r\n public color = Color3.White();\r\n\r\n private _texture: Nullable = null;\r\n /**\r\n * Stores the sheen tint values in a texture.\r\n * rgb is tint\r\n * a is a intensity or roughness if the roughness property has been defined and useRoughnessFromTexture is true (in that case, textureRoughness won't be used)\r\n * If the roughness property has been defined and useRoughnessFromTexture is false then the alpha channel is not used to modulate roughness\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public texture: Nullable = null;\r\n\r\n private _useRoughnessFromMainTexture = true;\r\n /**\r\n * Indicates that the alpha channel of the texture property will be used for roughness.\r\n * Has no effect if the roughness (and texture!) property is not defined\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRoughnessFromMainTexture = true;\r\n\r\n private _roughness: Nullable = null;\r\n /**\r\n * Defines the sheen roughness.\r\n * It is not taken into account if linkSheenWithAlbedo is true.\r\n * To stay backward compatible, material roughness is used instead if sheen roughness = null\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public roughness: Nullable = null;\r\n\r\n private _textureRoughness: Nullable = null;\r\n /**\r\n * Stores the sheen roughness in a texture.\r\n * alpha channel is the roughness. This texture won't be used if the texture property is not empty and useRoughnessFromTexture is true\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public textureRoughness: Nullable = null;\r\n\r\n private _albedoScaling = false;\r\n /**\r\n * If true, the sheen effect is layered above the base BRDF with the albedo-scaling technique.\r\n * It allows the strength of the sheen effect to not depend on the base color of the material,\r\n * making it easier to setup and tweak the effect\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public albedoScaling = false;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial, addToPluginList = true) {\r\n super(material, \"Sheen\", 120, new MaterialSheenDefines(), addToPluginList);\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: MaterialSheenDefines, scene: Scene): boolean {\r\n if (!this._isEnabled) {\r\n return true;\r\n }\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.SheenTextureEnabled) {\r\n if (!this._texture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._textureRoughness && MaterialFlags.SheenTextureEnabled) {\r\n if (!this._textureRoughness.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public prepareDefinesBeforeAttributes(defines: MaterialSheenDefines, scene: Scene): void {\r\n if (this._isEnabled) {\r\n defines.SHEEN = true;\r\n defines.SHEEN_LINKWITHALBEDO = this._linkSheenWithAlbedo;\r\n defines.SHEEN_ROUGHNESS = this._roughness !== null;\r\n defines.SHEEN_ALBEDOSCALING = this._albedoScaling;\r\n defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = this._useRoughnessFromMainTexture;\r\n defines.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL =\r\n this._texture !== null && this._texture._texture === this._textureRoughness?._texture && this._texture.checkTransformsAreIdentical(this._textureRoughness);\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.SheenTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._texture, defines, \"SHEEN_TEXTURE\");\r\n defines.SHEEN_GAMMATEXTURE = this._texture.gammaSpace;\r\n } else {\r\n defines.SHEEN_TEXTURE = false;\r\n }\r\n\r\n if (this._textureRoughness && MaterialFlags.SheenTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._textureRoughness, defines, \"SHEEN_TEXTURE_ROUGHNESS\");\r\n } else {\r\n defines.SHEEN_TEXTURE_ROUGHNESS = false;\r\n }\r\n }\r\n }\r\n } else {\r\n defines.SHEEN = false;\r\n defines.SHEEN_TEXTURE = false;\r\n defines.SHEEN_TEXTURE_ROUGHNESS = false;\r\n defines.SHEEN_LINKWITHALBEDO = false;\r\n defines.SHEEN_ROUGHNESS = false;\r\n defines.SHEEN_ALBEDOSCALING = false;\r\n defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = false;\r\n defines.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL = false;\r\n defines.SHEEN_GAMMATEXTURE = false;\r\n defines.SHEEN_TEXTUREDIRECTUV = 0;\r\n defines.SHEEN_TEXTURE_ROUGHNESSDIRECTUV = 0;\r\n }\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {\r\n if (!this._isEnabled) {\r\n return;\r\n }\r\n\r\n const defines = subMesh!.materialDefines as unknown as MaterialSheenDefines;\r\n\r\n const isFrozen = this._material.isFrozen;\r\n\r\n const identicalTextures = defines.SHEEN_TEXTURE_ROUGHNESS_IDENTICAL;\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n if (identicalTextures && MaterialFlags.SheenTextureEnabled) {\r\n uniformBuffer.updateFloat4(\"vSheenInfos\", this._texture!.coordinatesIndex, this._texture!.level, -1, -1);\r\n MaterialHelper.BindTextureMatrix(this._texture!, uniformBuffer, \"sheen\");\r\n } else if ((this._texture || this._textureRoughness) && MaterialFlags.SheenTextureEnabled) {\r\n uniformBuffer.updateFloat4(\r\n \"vSheenInfos\",\r\n this._texture?.coordinatesIndex ?? 0,\r\n this._texture?.level ?? 0,\r\n this._textureRoughness?.coordinatesIndex ?? 0,\r\n this._textureRoughness?.level ?? 0\r\n );\r\n if (this._texture) {\r\n MaterialHelper.BindTextureMatrix(this._texture, uniformBuffer, \"sheen\");\r\n }\r\n if (this._textureRoughness && !identicalTextures && !defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE) {\r\n MaterialHelper.BindTextureMatrix(this._textureRoughness, uniformBuffer, \"sheenRoughness\");\r\n }\r\n }\r\n\r\n // Sheen\r\n uniformBuffer.updateFloat4(\"vSheenColor\", this.color.r, this.color.g, this.color.b, this.intensity);\r\n\r\n if (this._roughness !== null) {\r\n uniformBuffer.updateFloat(\"vSheenRoughness\", this._roughness);\r\n }\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._texture && MaterialFlags.SheenTextureEnabled) {\r\n uniformBuffer.setTexture(\"sheenSampler\", this._texture);\r\n }\r\n\r\n if (this._textureRoughness && !identicalTextures && !defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE && MaterialFlags.SheenTextureEnabled) {\r\n uniformBuffer.setTexture(\"sheenRoughnessSampler\", this._textureRoughness);\r\n }\r\n }\r\n }\r\n\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (this._texture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._textureRoughness === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._texture) {\r\n activeTextures.push(this._texture);\r\n }\r\n\r\n if (this._textureRoughness) {\r\n activeTextures.push(this._textureRoughness);\r\n }\r\n }\r\n\r\n public getAnimatables(animatables: IAnimatable[]): void {\r\n if (this._texture && this._texture.animations && this._texture.animations.length > 0) {\r\n animatables.push(this._texture);\r\n }\r\n\r\n if (this._textureRoughness && this._textureRoughness.animations && this._textureRoughness.animations.length > 0) {\r\n animatables.push(this._textureRoughness);\r\n }\r\n }\r\n\r\n public dispose(forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n this._texture?.dispose();\r\n this._textureRoughness?.dispose();\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return \"PBRSheenConfiguration\";\r\n }\r\n\r\n public addFallbacks(defines: MaterialSheenDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n if (defines.SHEEN) {\r\n fallbacks.addFallback(currentRank++, \"SHEEN\");\r\n }\r\n return currentRank;\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"sheenSampler\", \"sheenRoughnessSampler\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vSheenColor\", size: 4, type: \"vec4\" },\r\n { name: \"vSheenRoughness\", size: 1, type: \"float\" },\r\n { name: \"vSheenInfos\", size: 4, type: \"vec4\" },\r\n { name: \"sheenMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"sheenRoughnessMatrix\", size: 16, type: \"mat4\" },\r\n ],\r\n };\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\nimport { serialize, serializeAsTexture, expandToProperty, serializeAsColor3 } from \"../../Misc/decorators\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport type { SmartArray } from \"../../Misc/smartArray\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { MaterialFlags } from \"../materialFlags\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport type { EffectFallbacks } from \"../effectFallbacks\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { CubeTexture } from \"../Textures/cubeTexture\";\r\nimport { TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport { MaterialPluginBase } from \"../materialPluginBase\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { MaterialDefines } from \"../materialDefines\";\r\n\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialSubSurfaceDefines extends MaterialDefines {\r\n public SUBSURFACE = false;\r\n\r\n public SS_REFRACTION = false;\r\n public SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = false;\r\n public SS_TRANSLUCENCY = false;\r\n public SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = false;\r\n public SS_SCATTERING = false;\r\n\r\n public SS_THICKNESSANDMASK_TEXTURE = false;\r\n public SS_THICKNESSANDMASK_TEXTUREDIRECTUV = 0;\r\n public SS_HAS_THICKNESS = false;\r\n public SS_REFRACTIONINTENSITY_TEXTURE = false;\r\n public SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV = 0;\r\n public SS_TRANSLUCENCYINTENSITY_TEXTURE = false;\r\n public SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV = 0;\r\n\r\n public SS_REFRACTIONMAP_3D = false;\r\n public SS_REFRACTIONMAP_OPPOSITEZ = false;\r\n public SS_LODINREFRACTIONALPHA = false;\r\n public SS_GAMMAREFRACTION = false;\r\n public SS_RGBDREFRACTION = false;\r\n public SS_LINEARSPECULARREFRACTION = false;\r\n public SS_LINKREFRACTIONTOTRANSPARENCY = false;\r\n public SS_ALBEDOFORREFRACTIONTINT = false;\r\n public SS_ALBEDOFORTRANSLUCENCYTINT = false;\r\n public SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;\r\n public SS_USE_THICKNESS_AS_DEPTH = false;\r\n\r\n public SS_MASK_FROM_THICKNESS_TEXTURE = false;\r\n public SS_USE_GLTF_TEXTURES = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the sub surface component of the PBR material\r\n */\r\nexport class PBRSubSurfaceConfiguration extends MaterialPluginBase {\r\n protected _material: PBRBaseMaterial;\r\n\r\n private _isRefractionEnabled = false;\r\n /**\r\n * Defines if the refraction is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isRefractionEnabled = false;\r\n\r\n private _isTranslucencyEnabled = false;\r\n /**\r\n * Defines if the translucency is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isTranslucencyEnabled = false;\r\n\r\n private _isScatteringEnabled = false;\r\n /**\r\n * Defines if the sub surface scattering is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markScenePrePassDirty\")\r\n public isScatteringEnabled = false;\r\n\r\n @serialize()\r\n private _scatteringDiffusionProfileIndex = 0;\r\n\r\n /**\r\n * Diffusion profile for subsurface scattering.\r\n * Useful for better scattering in the skins or foliages.\r\n */\r\n public get scatteringDiffusionProfile(): Nullable {\r\n if (!this._scene.subSurfaceConfiguration) {\r\n return null;\r\n }\r\n\r\n return this._scene.subSurfaceConfiguration.ssDiffusionProfileColors[this._scatteringDiffusionProfileIndex];\r\n }\r\n\r\n public set scatteringDiffusionProfile(c: Nullable) {\r\n if (!this._scene.enableSubSurfaceForPrePass()) {\r\n // Not supported\r\n return;\r\n }\r\n\r\n // addDiffusionProfile automatically checks for doubles\r\n if (c) {\r\n this._scatteringDiffusionProfileIndex = this._scene.subSurfaceConfiguration!.addDiffusionProfile(c);\r\n }\r\n }\r\n\r\n /**\r\n * Defines the refraction intensity of the material.\r\n * The refraction when enabled replaces the Diffuse part of the material.\r\n * The intensity helps transitioning between diffuse and refraction.\r\n */\r\n @serialize()\r\n public refractionIntensity: number = 1;\r\n\r\n /**\r\n * Defines the translucency intensity of the material.\r\n * When translucency has been enabled, this defines how much of the \"translucency\"\r\n * is added to the diffuse part of the material.\r\n */\r\n @serialize()\r\n public translucencyIntensity: number = 1;\r\n\r\n /**\r\n * When enabled, transparent surfaces will be tinted with the albedo colour (independent of thickness)\r\n */\r\n @serialize()\r\n public useAlbedoToTintRefraction: boolean = false;\r\n\r\n /**\r\n * When enabled, translucent surfaces will be tinted with the albedo colour (independent of thickness)\r\n */\r\n @serialize()\r\n public useAlbedoToTintTranslucency: boolean = false;\r\n\r\n private _thicknessTexture: Nullable = null;\r\n /**\r\n * Stores the average thickness of a mesh in a texture (The texture is holding the values linearly).\r\n * The red (or green if useGltfStyleTextures=true) channel of the texture should contain the thickness remapped between 0 and 1.\r\n * 0 would mean minimumThickness\r\n * 1 would mean maximumThickness\r\n * The other channels might be use as a mask to vary the different effects intensity.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public thicknessTexture: Nullable = null;\r\n\r\n private _refractionTexture: Nullable = null;\r\n /**\r\n * Defines the texture to use for refraction.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public refractionTexture: Nullable = null;\r\n\r\n /** @internal */\r\n public _indexOfRefraction = 1.5;\r\n /**\r\n * Index of refraction of the material base layer.\r\n * https://en.wikipedia.org/wiki/List_of_refractive_indices\r\n *\r\n * This does not only impact refraction but also the Base F0 of Dielectric Materials.\r\n *\r\n * From dielectric fresnel rules: F0 = square((iorT - iorI) / (iorT + iorI))\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public indexOfRefraction = 1.5;\r\n\r\n @serialize()\r\n private _volumeIndexOfRefraction = -1.0;\r\n\r\n /**\r\n * Index of refraction of the material's volume.\r\n * https://en.wikipedia.org/wiki/List_of_refractive_indices\r\n *\r\n * This ONLY impacts refraction. If not provided or given a non-valid value,\r\n * the volume will use the same IOR as the surface.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public get volumeIndexOfRefraction(): number {\r\n if (this._volumeIndexOfRefraction >= 1.0) {\r\n return this._volumeIndexOfRefraction;\r\n }\r\n return this._indexOfRefraction;\r\n }\r\n public set volumeIndexOfRefraction(value: number) {\r\n if (value >= 1.0) {\r\n this._volumeIndexOfRefraction = value;\r\n } else {\r\n this._volumeIndexOfRefraction = -1.0;\r\n }\r\n }\r\n\r\n private _invertRefractionY = false;\r\n /**\r\n * Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public invertRefractionY = false;\r\n\r\n /** @internal */\r\n public _linkRefractionWithTransparency = false;\r\n /**\r\n * This parameters will make the material used its opacity to control how much it is refracting against not.\r\n * Materials half opaque for instance using refraction could benefit from this control.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public linkRefractionWithTransparency = false;\r\n\r\n /**\r\n * Defines the minimum thickness stored in the thickness map.\r\n * If no thickness map is defined, this value will be used to simulate thickness.\r\n */\r\n @serialize()\r\n public minimumThickness: number = 0;\r\n\r\n /**\r\n * Defines the maximum thickness stored in the thickness map.\r\n */\r\n @serialize()\r\n public maximumThickness: number = 1;\r\n\r\n /**\r\n * Defines that the thickness should be used as a measure of the depth volume.\r\n */\r\n @serialize()\r\n public useThicknessAsDepth = false;\r\n\r\n /**\r\n * Defines the volume tint of the material.\r\n * This is used for both translucency and scattering.\r\n */\r\n @serializeAsColor3()\r\n public tintColor = Color3.White();\r\n\r\n /**\r\n * Defines the distance at which the tint color should be found in the media.\r\n * This is used for refraction only.\r\n */\r\n @serialize()\r\n public tintColorAtDistance = 1;\r\n\r\n /**\r\n * Defines how far each channel transmit through the media.\r\n * It is defined as a color to simplify it selection.\r\n */\r\n @serializeAsColor3()\r\n public diffusionDistance = Color3.White();\r\n\r\n private _useMaskFromThicknessTexture = false;\r\n /**\r\n * Stores the intensity of the different subsurface effects in the thickness texture.\r\n * Note that if refractionIntensityTexture and/or translucencyIntensityTexture is provided it takes precedence over thicknessTexture + useMaskFromThicknessTexture\r\n * * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.\r\n * * the blue channel is the translucency intensity.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useMaskFromThicknessTexture: boolean = false;\r\n\r\n private _refractionIntensityTexture: Nullable = null;\r\n /**\r\n * Stores the intensity of the refraction. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture\r\n * * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public refractionIntensityTexture: Nullable = null;\r\n\r\n private _translucencyIntensityTexture: Nullable = null;\r\n /**\r\n * Stores the intensity of the translucency. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture\r\n * * the blue channel is the translucency intensity.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public translucencyIntensityTexture: Nullable = null;\r\n\r\n private _scene: Scene;\r\n private _useGltfStyleTextures = false;\r\n /**\r\n * Use channels layout used by glTF:\r\n * * thicknessTexture: the green (instead of red) channel is the thickness\r\n * * thicknessTexture/refractionIntensityTexture: the red (instead of green) channel is the refraction intensity\r\n * * thicknessTexture/translucencyIntensityTexture: no change, use the blue channel for the translucency intensity\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useGltfStyleTextures: boolean = false;\r\n\r\n /** @internal */\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n private _internalMarkScenePrePassDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isRefractionEnabled || this._isTranslucencyEnabled || this._isScatteringEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n /** @internal */\r\n public _markScenePrePassDirty(): void {\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n this._internalMarkScenePrePassDirty();\r\n }\r\n\r\n constructor(material: PBRBaseMaterial, addToPluginList = true) {\r\n super(material, \"PBRSubSurface\", 130, new MaterialSubSurfaceDefines(), addToPluginList);\r\n\r\n this._scene = material.getScene();\r\n this.registerForExtraEvents = true;\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n this._internalMarkScenePrePassDirty = material._dirtyCallbacks[Constants.MATERIAL_PrePassDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: MaterialSubSurfaceDefines, scene: Scene): boolean {\r\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\r\n return true;\r\n }\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\r\n if (!this._thicknessTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n const refractionTexture = this._getRefractionTexture(scene);\r\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\r\n if (!refractionTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public prepareDefinesBeforeAttributes(defines: MaterialSubSurfaceDefines, scene: Scene): void {\r\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\r\n defines.SUBSURFACE = false;\r\n defines.SS_TRANSLUCENCY = false;\r\n defines.SS_SCATTERING = false;\r\n defines.SS_REFRACTION = false;\r\n defines.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = false;\r\n defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = false;\r\n defines.SS_THICKNESSANDMASK_TEXTURE = false;\r\n defines.SS_THICKNESSANDMASK_TEXTUREDIRECTUV = 0;\r\n defines.SS_HAS_THICKNESS = false;\r\n defines.SS_REFRACTIONINTENSITY_TEXTURE = false;\r\n defines.SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV = 0;\r\n defines.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;\r\n defines.SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV = 0;\r\n defines.SS_REFRACTIONMAP_3D = false;\r\n defines.SS_REFRACTIONMAP_OPPOSITEZ = false;\r\n defines.SS_LODINREFRACTIONALPHA = false;\r\n defines.SS_GAMMAREFRACTION = false;\r\n defines.SS_RGBDREFRACTION = false;\r\n defines.SS_LINEARSPECULARREFRACTION = false;\r\n defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;\r\n defines.SS_ALBEDOFORREFRACTIONTINT = false;\r\n defines.SS_ALBEDOFORTRANSLUCENCYTINT = false;\r\n defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;\r\n defines.SS_USE_THICKNESS_AS_DEPTH = false;\r\n defines.SS_MASK_FROM_THICKNESS_TEXTURE = false;\r\n defines.SS_USE_GLTF_TEXTURES = false;\r\n return;\r\n }\r\n\r\n if (defines._areTexturesDirty) {\r\n defines.SUBSURFACE = true;\r\n\r\n defines.SS_TRANSLUCENCY = this._isTranslucencyEnabled;\r\n defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = false;\r\n defines.SS_SCATTERING = this._isScatteringEnabled;\r\n defines.SS_THICKNESSANDMASK_TEXTURE = false;\r\n defines.SS_REFRACTIONINTENSITY_TEXTURE = false;\r\n defines.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;\r\n defines.SS_HAS_THICKNESS = false;\r\n defines.SS_MASK_FROM_THICKNESS_TEXTURE = false;\r\n defines.SS_USE_GLTF_TEXTURES = false;\r\n defines.SS_REFRACTION = false;\r\n defines.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = false;\r\n defines.SS_REFRACTIONMAP_3D = false;\r\n defines.SS_GAMMAREFRACTION = false;\r\n defines.SS_RGBDREFRACTION = false;\r\n defines.SS_LINEARSPECULARREFRACTION = false;\r\n defines.SS_REFRACTIONMAP_OPPOSITEZ = false;\r\n defines.SS_LODINREFRACTIONALPHA = false;\r\n defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;\r\n defines.SS_ALBEDOFORREFRACTIONTINT = false;\r\n defines.SS_ALBEDOFORTRANSLUCENCYTINT = false;\r\n defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;\r\n defines.SS_USE_THICKNESS_AS_DEPTH = false;\r\n\r\n const refractionIntensityTextureIsThicknessTexture =\r\n !!this._thicknessTexture &&\r\n !!this._refractionIntensityTexture &&\r\n this._refractionIntensityTexture.checkTransformsAreIdentical(this._thicknessTexture) &&\r\n this._refractionIntensityTexture._texture === this._thicknessTexture._texture;\r\n\r\n const translucencyIntensityTextureIsThicknessTexture =\r\n !!this._thicknessTexture &&\r\n !!this._translucencyIntensityTexture &&\r\n this._translucencyIntensityTexture.checkTransformsAreIdentical(this._thicknessTexture) &&\r\n this._translucencyIntensityTexture._texture === this._thicknessTexture._texture;\r\n\r\n // if true, it means the refraction/translucency textures are the same than the thickness texture so there's no need to pass them to the shader, only thicknessTexture\r\n const useOnlyThicknessTexture =\r\n (refractionIntensityTextureIsThicknessTexture || !this._refractionIntensityTexture) &&\r\n (translucencyIntensityTextureIsThicknessTexture || !this._translucencyIntensityTexture);\r\n\r\n if (defines._areTexturesDirty) {\r\n if (scene.texturesEnabled) {\r\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._thicknessTexture, defines, \"SS_THICKNESSANDMASK_TEXTURE\");\r\n }\r\n\r\n if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && !useOnlyThicknessTexture) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._refractionIntensityTexture, defines, \"SS_REFRACTIONINTENSITY_TEXTURE\");\r\n }\r\n\r\n if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && !useOnlyThicknessTexture) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._translucencyIntensityTexture, defines, \"SS_TRANSLUCENCYINTENSITY_TEXTURE\");\r\n }\r\n }\r\n }\r\n\r\n defines.SS_HAS_THICKNESS = this.maximumThickness - this.minimumThickness !== 0.0;\r\n defines.SS_MASK_FROM_THICKNESS_TEXTURE =\r\n (this._useMaskFromThicknessTexture || !!this._refractionIntensityTexture || !!this._translucencyIntensityTexture) && useOnlyThicknessTexture;\r\n defines.SS_USE_GLTF_TEXTURES = this._useGltfStyleTextures;\r\n defines.SS_REFRACTION_USE_INTENSITY_FROM_TEXTURE = (this._useMaskFromThicknessTexture || !!this._refractionIntensityTexture) && useOnlyThicknessTexture;\r\n defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_TEXTURE = (this._useMaskFromThicknessTexture || !!this._translucencyIntensityTexture) && useOnlyThicknessTexture;\r\n\r\n if (this._isRefractionEnabled) {\r\n if (scene.texturesEnabled) {\r\n const refractionTexture = this._getRefractionTexture(scene);\r\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\r\n defines.SS_REFRACTION = true;\r\n defines.SS_REFRACTIONMAP_3D = refractionTexture.isCube;\r\n defines.SS_GAMMAREFRACTION = refractionTexture.gammaSpace;\r\n defines.SS_RGBDREFRACTION = refractionTexture.isRGBD;\r\n defines.SS_LINEARSPECULARREFRACTION = refractionTexture.linearSpecularLOD;\r\n defines.SS_REFRACTIONMAP_OPPOSITEZ = this._scene.useRightHandedSystem && refractionTexture.isCube ? !refractionTexture.invertZ : refractionTexture.invertZ;\r\n defines.SS_LODINREFRACTIONALPHA = refractionTexture.lodLevelInAlpha;\r\n defines.SS_LINKREFRACTIONTOTRANSPARENCY = this._linkRefractionWithTransparency;\r\n defines.SS_ALBEDOFORREFRACTIONTINT = this.useAlbedoToTintRefraction;\r\n defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = refractionTexture.isCube && (refractionTexture).boundingBoxSize;\r\n defines.SS_USE_THICKNESS_AS_DEPTH = this.useThicknessAsDepth;\r\n }\r\n }\r\n }\r\n\r\n if (this._isTranslucencyEnabled) {\r\n defines.SS_ALBEDOFORTRANSLUCENCYTINT = this.useAlbedoToTintTranslucency;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Binds the material data (this function is called even if mustRebind() returns false)\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n * @param scene defines the scene the material belongs to.\r\n * @param engine defines the engine the material belongs to.\r\n * @param subMesh the submesh to bind data for\r\n */\r\n public hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {\r\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\r\n return;\r\n }\r\n\r\n subMesh.getRenderingMesh().getWorldMatrix().decompose(TmpVectors.Vector3[0]);\r\n\r\n const thicknessScale = Math.max(Math.abs(TmpVectors.Vector3[0].x), Math.abs(TmpVectors.Vector3[0].y), Math.abs(TmpVectors.Vector3[0].z));\r\n\r\n uniformBuffer.updateFloat2(\"vThicknessParam\", this.minimumThickness * thicknessScale, (this.maximumThickness - this.minimumThickness) * thicknessScale);\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: Engine, subMesh: SubMesh): void {\r\n if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {\r\n return;\r\n }\r\n\r\n const defines = subMesh!.materialDefines as unknown as MaterialSubSurfaceDefines;\r\n\r\n const isFrozen = this._material.isFrozen;\r\n const realTimeFiltering = this._material.realTimeFiltering;\r\n const lodBasedMicrosurface = defines.LODBASEDMICROSFURACE;\r\n\r\n const refractionTexture = this._getRefractionTexture(scene);\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\r\n uniformBuffer.updateFloat2(\"vThicknessInfos\", this._thicknessTexture.coordinatesIndex, this._thicknessTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._thicknessTexture, uniformBuffer, \"thickness\");\r\n }\r\n\r\n if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && defines.SS_REFRACTIONINTENSITY_TEXTURE) {\r\n uniformBuffer.updateFloat2(\"vRefractionIntensityInfos\", this._refractionIntensityTexture.coordinatesIndex, this._refractionIntensityTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._refractionIntensityTexture, uniformBuffer, \"refractionIntensity\");\r\n }\r\n\r\n if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && defines.SS_TRANSLUCENCYINTENSITY_TEXTURE) {\r\n uniformBuffer.updateFloat2(\"vTranslucencyIntensityInfos\", this._translucencyIntensityTexture.coordinatesIndex, this._translucencyIntensityTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._translucencyIntensityTexture, uniformBuffer, \"translucencyIntensity\");\r\n }\r\n\r\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\r\n uniformBuffer.updateMatrix(\"refractionMatrix\", refractionTexture.getRefractionTextureMatrix());\r\n\r\n let depth = 1.0;\r\n if (!refractionTexture.isCube) {\r\n if ((refractionTexture).depth) {\r\n depth = (refractionTexture).depth;\r\n }\r\n }\r\n\r\n const width = refractionTexture.getSize().width;\r\n const refractionIor = this.volumeIndexOfRefraction;\r\n uniformBuffer.updateFloat4(\"vRefractionInfos\", refractionTexture.level, 1 / refractionIor, depth, this._invertRefractionY ? -1 : 1);\r\n uniformBuffer.updateFloat4(\r\n \"vRefractionMicrosurfaceInfos\",\r\n width,\r\n refractionTexture.lodGenerationScale,\r\n refractionTexture.lodGenerationOffset,\r\n 1.0 / this.indexOfRefraction\r\n );\r\n\r\n if (realTimeFiltering) {\r\n uniformBuffer.updateFloat2(\"vRefractionFilteringInfo\", width, Scalar.Log2(width));\r\n }\r\n\r\n if ((refractionTexture).boundingBoxSize) {\r\n const cubeTexture = refractionTexture;\r\n\r\n uniformBuffer.updateVector3(\"vRefractionPosition\", cubeTexture.boundingBoxPosition);\r\n uniformBuffer.updateVector3(\"vRefractionSize\", cubeTexture.boundingBoxSize);\r\n }\r\n }\r\n\r\n if (this._isScatteringEnabled) {\r\n uniformBuffer.updateFloat(\"scatteringDiffusionProfile\", this._scatteringDiffusionProfileIndex);\r\n }\r\n uniformBuffer.updateColor3(\"vDiffusionDistance\", this.diffusionDistance);\r\n\r\n uniformBuffer.updateFloat4(\"vTintColor\", this.tintColor.r, this.tintColor.g, this.tintColor.b, Math.max(0.00001, this.tintColorAtDistance));\r\n\r\n uniformBuffer.updateFloat3(\"vSubSurfaceIntensity\", this.refractionIntensity, this.translucencyIntensity, 0);\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {\r\n uniformBuffer.setTexture(\"thicknessSampler\", this._thicknessTexture);\r\n }\r\n\r\n if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && defines.SS_REFRACTIONINTENSITY_TEXTURE) {\r\n uniformBuffer.setTexture(\"refractionIntensitySampler\", this._refractionIntensityTexture);\r\n }\r\n\r\n if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && defines.SS_TRANSLUCENCYINTENSITY_TEXTURE) {\r\n uniformBuffer.setTexture(\"translucencyIntensitySampler\", this._translucencyIntensityTexture);\r\n }\r\n\r\n if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {\r\n if (lodBasedMicrosurface) {\r\n uniformBuffer.setTexture(\"refractionSampler\", refractionTexture);\r\n } else {\r\n uniformBuffer.setTexture(\"refractionSampler\", refractionTexture._lodTextureMid || refractionTexture);\r\n uniformBuffer.setTexture(\"refractionSamplerLow\", refractionTexture._lodTextureLow || refractionTexture);\r\n uniformBuffer.setTexture(\"refractionSamplerHigh\", refractionTexture._lodTextureHigh || refractionTexture);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Returns the texture used for refraction or null if none is used.\r\n * @param scene defines the scene the material belongs to.\r\n * @returns - Refraction texture if present. If no refraction texture and refraction\r\n * is linked with transparency, returns environment texture. Otherwise, returns null.\r\n */\r\n private _getRefractionTexture(scene: Scene): Nullable {\r\n if (this._refractionTexture) {\r\n return this._refractionTexture;\r\n }\r\n\r\n if (this._isRefractionEnabled) {\r\n return scene.environmentTexture;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Returns true if alpha blending should be disabled.\r\n */\r\n public get disableAlphaBlending(): boolean {\r\n return this._isRefractionEnabled && this._linkRefractionWithTransparency;\r\n }\r\n\r\n /**\r\n * Fills the list of render target textures.\r\n * @param renderTargets the list of render targets to update\r\n */\r\n public fillRenderTargetTextures(renderTargets: SmartArray): void {\r\n if (MaterialFlags.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\r\n renderTargets.push(this._refractionTexture);\r\n }\r\n }\r\n\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (this._thicknessTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._refractionTexture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public hasRenderTargetTextures(): boolean {\r\n if (MaterialFlags.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._thicknessTexture) {\r\n activeTextures.push(this._thicknessTexture);\r\n }\r\n\r\n if (this._refractionTexture) {\r\n activeTextures.push(this._refractionTexture);\r\n }\r\n }\r\n\r\n public getAnimatables(animatables: IAnimatable[]): void {\r\n if (this._thicknessTexture && this._thicknessTexture.animations && this._thicknessTexture.animations.length > 0) {\r\n animatables.push(this._thicknessTexture);\r\n }\r\n\r\n if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {\r\n animatables.push(this._refractionTexture);\r\n }\r\n }\r\n\r\n public dispose(forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n if (this._thicknessTexture) {\r\n this._thicknessTexture.dispose();\r\n }\r\n\r\n if (this._refractionTexture) {\r\n this._refractionTexture.dispose();\r\n }\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return \"PBRSubSurfaceConfiguration\";\r\n }\r\n\r\n public addFallbacks(defines: MaterialSubSurfaceDefines, fallbacks: EffectFallbacks, currentRank: number): number {\r\n if (defines.SS_SCATTERING) {\r\n fallbacks.addFallback(currentRank++, \"SS_SCATTERING\");\r\n }\r\n if (defines.SS_TRANSLUCENCY) {\r\n fallbacks.addFallback(currentRank++, \"SS_TRANSLUCENCY\");\r\n }\r\n return currentRank;\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"thicknessSampler\", \"refractionIntensitySampler\", \"translucencyIntensitySampler\", \"refractionSampler\", \"refractionSamplerLow\", \"refractionSamplerHigh\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vRefractionMicrosurfaceInfos\", size: 4, type: \"vec4\" },\r\n { name: \"vRefractionFilteringInfo\", size: 2, type: \"vec2\" },\r\n { name: \"vTranslucencyIntensityInfos\", size: 2, type: \"vec2\" },\r\n { name: \"vRefractionInfos\", size: 4, type: \"vec4\" },\r\n { name: \"refractionMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"vThicknessInfos\", size: 2, type: \"vec2\" },\r\n { name: \"vRefractionIntensityInfos\", size: 2, type: \"vec2\" },\r\n { name: \"thicknessMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"refractionIntensityMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"translucencyIntensityMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"vThicknessParam\", size: 2, type: \"vec2\" },\r\n { name: \"vDiffusionDistance\", size: 3, type: \"vec3\" },\r\n { name: \"vTintColor\", size: 4, type: \"vec4\" },\r\n { name: \"vSubSurfaceIntensity\", size: 3, type: \"vec3\" },\r\n { name: \"vRefractionPosition\", size: 3, type: \"vec3\" },\r\n { name: \"vRefractionSize\", size: 3, type: \"vec3\" },\r\n { name: \"scatteringDiffusionProfile\", size: 1, type: \"float\" },\r\n ],\r\n };\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { serialize, serializeAsImageProcessingConfiguration, expandToProperty } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SmartArray } from \"../../Misc/smartArray\";\r\nimport { GetEnvironmentBRDFTexture } from \"../../Misc/brdfTextureTools\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Scene } from \"../../scene\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport { PBRBRDFConfiguration } from \"./pbrBRDFConfiguration\";\r\nimport { PrePassConfiguration } from \"../prePassConfiguration\";\r\nimport { Color3, TmpColors } from \"../../Maths/math.color\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\n\r\nimport type { IImageProcessingConfigurationDefines } from \"../../Materials/imageProcessingConfiguration\";\r\nimport { ImageProcessingConfiguration } from \"../../Materials/imageProcessingConfiguration\";\r\nimport type { Effect, IEffectCreationOptions } from \"../../Materials/effect\";\r\nimport type { IMaterialCompilationOptions, ICustomShaderNameResolveOptions } from \"../../Materials/material\";\r\nimport { Material } from \"../../Materials/material\";\r\nimport { MaterialPluginEvent } from \"../materialPluginEvent\";\r\nimport { MaterialDefines } from \"../../Materials/materialDefines\";\r\nimport { PushMaterial } from \"../../Materials/pushMaterial\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\n\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { CubeTexture } from \"../../Materials/Textures/cubeTexture\";\r\n\r\nimport { MaterialFlags } from \"../materialFlags\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { IAnimatable } from \"../../Animations/animatable.interface\";\r\n\r\nimport \"../../Materials/Textures/baseTexture.polynomial\";\r\nimport \"../../Shaders/pbr.fragment\";\r\nimport \"../../Shaders/pbr.vertex\";\r\n\r\nimport { EffectFallbacks } from \"../effectFallbacks\";\r\nimport { PBRClearCoatConfiguration } from \"./pbrClearCoatConfiguration\";\r\nimport { PBRIridescenceConfiguration } from \"./pbrIridescenceConfiguration\";\r\nimport { PBRAnisotropicConfiguration } from \"./pbrAnisotropicConfiguration\";\r\nimport { PBRSheenConfiguration } from \"./pbrSheenConfiguration\";\r\nimport { PBRSubSurfaceConfiguration } from \"./pbrSubSurfaceConfiguration\";\r\nimport { DetailMapConfiguration } from \"../material.detailMapConfiguration\";\r\nimport { addClipPlaneUniforms, bindClipPlane } from \"../clipPlaneMaterialHelper\";\r\n\r\nconst onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable };\r\n\r\n/**\r\n * Manages the defines for the PBR Material.\r\n * @internal\r\n */\r\nexport class PBRMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {\r\n public PBR = true;\r\n\r\n public NUM_SAMPLES = \"0\";\r\n public REALTIME_FILTERING = false;\r\n\r\n public MAINUV1 = false;\r\n public MAINUV2 = false;\r\n public MAINUV3 = false;\r\n public MAINUV4 = false;\r\n public MAINUV5 = false;\r\n public MAINUV6 = false;\r\n public UV1 = false;\r\n public UV2 = false;\r\n public UV3 = false;\r\n public UV4 = false;\r\n public UV5 = false;\r\n public UV6 = false;\r\n\r\n public ALBEDO = false;\r\n public GAMMAALBEDO = false;\r\n public ALBEDODIRECTUV = 0;\r\n public VERTEXCOLOR = false;\r\n\r\n public BAKED_VERTEX_ANIMATION_TEXTURE = false;\r\n\r\n public AMBIENT = false;\r\n public AMBIENTDIRECTUV = 0;\r\n public AMBIENTINGRAYSCALE = false;\r\n\r\n public OPACITY = false;\r\n public VERTEXALPHA = false;\r\n public OPACITYDIRECTUV = 0;\r\n public OPACITYRGB = false;\r\n public ALPHATEST = false;\r\n public DEPTHPREPASS = false;\r\n public ALPHABLEND = false;\r\n public ALPHAFROMALBEDO = false;\r\n public ALPHATESTVALUE = \"0.5\";\r\n public SPECULAROVERALPHA = false;\r\n public RADIANCEOVERALPHA = false;\r\n public ALPHAFRESNEL = false;\r\n public LINEARALPHAFRESNEL = false;\r\n public PREMULTIPLYALPHA = false;\r\n\r\n public EMISSIVE = false;\r\n public EMISSIVEDIRECTUV = 0;\r\n public GAMMAEMISSIVE = false;\r\n\r\n public REFLECTIVITY = false;\r\n public REFLECTIVITY_GAMMA = false;\r\n public REFLECTIVITYDIRECTUV = 0;\r\n public SPECULARTERM = false;\r\n\r\n public MICROSURFACEFROMREFLECTIVITYMAP = false;\r\n public MICROSURFACEAUTOMATIC = false;\r\n public LODBASEDMICROSFURACE = false;\r\n public MICROSURFACEMAP = false;\r\n public MICROSURFACEMAPDIRECTUV = 0;\r\n\r\n public METALLICWORKFLOW = false;\r\n public ROUGHNESSSTOREINMETALMAPALPHA = false;\r\n public ROUGHNESSSTOREINMETALMAPGREEN = false;\r\n public METALLNESSSTOREINMETALMAPBLUE = false;\r\n public AOSTOREINMETALMAPRED = false;\r\n public METALLIC_REFLECTANCE = false;\r\n public METALLIC_REFLECTANCE_GAMMA = false;\r\n public METALLIC_REFLECTANCEDIRECTUV = 0;\r\n public METALLIC_REFLECTANCE_USE_ALPHA_ONLY = false;\r\n public REFLECTANCE = false;\r\n public REFLECTANCE_GAMMA = false;\r\n public REFLECTANCEDIRECTUV = 0;\r\n\r\n public ENVIRONMENTBRDF = false;\r\n public ENVIRONMENTBRDF_RGBD = false;\r\n\r\n public NORMAL = false;\r\n public TANGENT = false;\r\n public BUMP = false;\r\n public BUMPDIRECTUV = 0;\r\n public OBJECTSPACE_NORMALMAP = false;\r\n public PARALLAX = false;\r\n public PARALLAXOCCLUSION = false;\r\n public NORMALXYSCALE = true;\r\n\r\n public LIGHTMAP = false;\r\n public LIGHTMAPDIRECTUV = 0;\r\n public USELIGHTMAPASSHADOWMAP = false;\r\n public GAMMALIGHTMAP = false;\r\n public RGBDLIGHTMAP = false;\r\n\r\n public REFLECTION = false;\r\n public REFLECTIONMAP_3D = false;\r\n public REFLECTIONMAP_SPHERICAL = false;\r\n public REFLECTIONMAP_PLANAR = false;\r\n public REFLECTIONMAP_CUBIC = false;\r\n public USE_LOCAL_REFLECTIONMAP_CUBIC = false;\r\n public REFLECTIONMAP_PROJECTION = false;\r\n public REFLECTIONMAP_SKYBOX = false;\r\n public REFLECTIONMAP_EXPLICIT = false;\r\n public REFLECTIONMAP_EQUIRECTANGULAR = false;\r\n public REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\r\n public REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\r\n public INVERTCUBICMAP = false;\r\n public USESPHERICALFROMREFLECTIONMAP = false;\r\n public USEIRRADIANCEMAP = false;\r\n public USESPHERICALINVERTEX = false;\r\n public REFLECTIONMAP_OPPOSITEZ = false;\r\n public LODINREFLECTIONALPHA = false;\r\n public GAMMAREFLECTION = false;\r\n public RGBDREFLECTION = false;\r\n public LINEARSPECULARREFLECTION = false;\r\n public RADIANCEOCCLUSION = false;\r\n public HORIZONOCCLUSION = false;\r\n\r\n public INSTANCES = false;\r\n public THIN_INSTANCES = false;\r\n public INSTANCESCOLOR = false;\r\n\r\n public PREPASS = false;\r\n public PREPASS_IRRADIANCE = false;\r\n public PREPASS_IRRADIANCE_INDEX = -1;\r\n public PREPASS_ALBEDO_SQRT = false;\r\n public PREPASS_ALBEDO_SQRT_INDEX = -1;\r\n public PREPASS_DEPTH = false;\r\n public PREPASS_DEPTH_INDEX = -1;\r\n public PREPASS_NORMAL = false;\r\n public PREPASS_NORMAL_INDEX = -1;\r\n public PREPASS_POSITION = false;\r\n public PREPASS_POSITION_INDEX = -1;\r\n public PREPASS_VELOCITY = false;\r\n public PREPASS_VELOCITY_INDEX = -1;\r\n public PREPASS_REFLECTIVITY = false;\r\n public PREPASS_REFLECTIVITY_INDEX = -1;\r\n public SCENE_MRT_COUNT = 0;\r\n\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public BONETEXTURE = false;\r\n public BONES_VELOCITY_ENABLED = false;\r\n\r\n public NONUNIFORMSCALING = false;\r\n\r\n public MORPHTARGETS = false;\r\n public MORPHTARGETS_NORMAL = false;\r\n public MORPHTARGETS_TANGENT = false;\r\n public MORPHTARGETS_UV = false;\r\n public NUM_MORPH_INFLUENCERS = 0;\r\n public MORPHTARGETS_TEXTURE = false;\r\n\r\n public IMAGEPROCESSING = false;\r\n public VIGNETTE = false;\r\n public VIGNETTEBLENDMODEMULTIPLY = false;\r\n public VIGNETTEBLENDMODEOPAQUE = false;\r\n public TONEMAPPING = false;\r\n public TONEMAPPING_ACES = false;\r\n public CONTRAST = false;\r\n public COLORCURVES = false;\r\n public COLORGRADING = false;\r\n public COLORGRADING3D = false;\r\n public SAMPLER3DGREENDEPTH = false;\r\n public SAMPLER3DBGRMAP = false;\r\n public DITHER = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n public EXPOSURE = false;\r\n public MULTIVIEW = false;\r\n public ORDER_INDEPENDENT_TRANSPARENCY = false;\r\n public ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;\r\n\r\n public USEPHYSICALLIGHTFALLOFF = false;\r\n public USEGLTFLIGHTFALLOFF = false;\r\n public TWOSIDEDLIGHTING = false;\r\n public SHADOWFLOAT = false;\r\n public CLIPPLANE = false;\r\n public CLIPPLANE2 = false;\r\n public CLIPPLANE3 = false;\r\n public CLIPPLANE4 = false;\r\n public CLIPPLANE5 = false;\r\n public CLIPPLANE6 = false;\r\n public POINTSIZE = false;\r\n public FOG = false;\r\n public LOGARITHMICDEPTH = false;\r\n public CAMERA_ORTHOGRAPHIC = false;\r\n public CAMERA_PERSPECTIVE = false;\r\n\r\n public FORCENORMALFORWARD = false;\r\n\r\n public SPECULARAA = false;\r\n\r\n public UNLIT = false;\r\n\r\n public DECAL_AFTER_DETAIL = false;\r\n\r\n public DEBUGMODE = 0;\r\n\r\n /**\r\n * Initializes the PBR Material defines.\r\n * @param externalProperties The external properties\r\n */\r\n constructor(externalProperties?: { [name: string]: { type: string; default: any } }) {\r\n super(externalProperties);\r\n this.rebuild();\r\n }\r\n\r\n /**\r\n * Resets the PBR Material defines.\r\n */\r\n public reset(): void {\r\n super.reset();\r\n this.ALPHATESTVALUE = \"0.5\";\r\n this.PBR = true;\r\n this.NORMALXYSCALE = true;\r\n }\r\n}\r\n\r\n/**\r\n * The Physically based material base class of BJS.\r\n *\r\n * This offers the main features of a standard PBR material.\r\n * For more information, please refer to the documentation :\r\n * https://doc.babylonjs.com/features/featuresDeepDive/materials/using/introToPBR\r\n */\r\nexport abstract class PBRBaseMaterial extends PushMaterial {\r\n /**\r\n * PBRMaterialTransparencyMode: No transparency mode, Alpha channel is not use.\r\n */\r\n public static readonly PBRMATERIAL_OPAQUE = Material.MATERIAL_OPAQUE;\r\n\r\n /**\r\n * PBRMaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.\r\n */\r\n public static readonly PBRMATERIAL_ALPHATEST = Material.MATERIAL_ALPHATEST;\r\n\r\n /**\r\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\r\n */\r\n public static readonly PBRMATERIAL_ALPHABLEND = Material.MATERIAL_ALPHABLEND;\r\n\r\n /**\r\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\r\n * They are also discarded below the alpha cutoff threshold to improve performances.\r\n */\r\n public static readonly PBRMATERIAL_ALPHATESTANDBLEND = Material.MATERIAL_ALPHATESTANDBLEND;\r\n\r\n /**\r\n * Defines the default value of how much AO map is occluding the analytical lights\r\n * (point spot...).\r\n */\r\n public static DEFAULT_AO_ON_ANALYTICAL_LIGHTS = 0;\r\n\r\n /**\r\n * PBRMaterialLightFalloff Physical: light is falling off following the inverse squared distance law.\r\n */\r\n public static readonly LIGHTFALLOFF_PHYSICAL = 0;\r\n\r\n /**\r\n * PBRMaterialLightFalloff gltf: light is falling off as described in the gltf moving to PBR document\r\n * to enhance interoperability with other engines.\r\n */\r\n public static readonly LIGHTFALLOFF_GLTF = 1;\r\n\r\n /**\r\n * PBRMaterialLightFalloff Standard: light is falling off like in the standard material\r\n * to enhance interoperability with other materials.\r\n */\r\n public static readonly LIGHTFALLOFF_STANDARD = 2;\r\n\r\n /**\r\n * Intensity of the direct lights e.g. the four lights available in your scene.\r\n * This impacts both the direct diffuse and specular highlights.\r\n * @internal\r\n */\r\n public _directIntensity: number = 1.0;\r\n\r\n /**\r\n * Intensity of the emissive part of the material.\r\n * This helps controlling the emissive effect without modifying the emissive color.\r\n * @internal\r\n */\r\n public _emissiveIntensity: number = 1.0;\r\n\r\n /**\r\n * Intensity of the environment e.g. how much the environment will light the object\r\n * either through harmonics for rough material or through the reflection for shiny ones.\r\n * @internal\r\n */\r\n public _environmentIntensity: number = 1.0;\r\n\r\n /**\r\n * This is a special control allowing the reduction of the specular highlights coming from the\r\n * four lights of the scene. Those highlights may not be needed in full environment lighting.\r\n * @internal\r\n */\r\n public _specularIntensity: number = 1.0;\r\n\r\n /**\r\n * This stores the direct, emissive, environment, and specular light intensities into a Vector4.\r\n */\r\n private _lightingInfos: Vector4 = new Vector4(this._directIntensity, this._emissiveIntensity, this._environmentIntensity, this._specularIntensity);\r\n\r\n /**\r\n * Debug Control allowing disabling the bump map on this material.\r\n * @internal\r\n */\r\n public _disableBumpMap: boolean = false;\r\n\r\n /**\r\n * AKA Diffuse Texture in standard nomenclature.\r\n * @internal\r\n */\r\n public _albedoTexture: Nullable = null;\r\n\r\n /**\r\n * AKA Occlusion Texture in other nomenclature.\r\n * @internal\r\n */\r\n public _ambientTexture: Nullable = null;\r\n\r\n /**\r\n * AKA Occlusion Texture Intensity in other nomenclature.\r\n * @internal\r\n */\r\n public _ambientTextureStrength: number = 1.0;\r\n\r\n /**\r\n * Defines how much the AO map is occluding the analytical lights (point spot...).\r\n * 1 means it completely occludes it\r\n * 0 mean it has no impact\r\n * @internal\r\n */\r\n public _ambientTextureImpactOnAnalyticalLights: number = PBRBaseMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;\r\n\r\n /**\r\n * Stores the alpha values in a texture.\r\n * @internal\r\n */\r\n public _opacityTexture: Nullable = null;\r\n\r\n /**\r\n * Stores the reflection values in a texture.\r\n * @internal\r\n */\r\n public _reflectionTexture: Nullable = null;\r\n\r\n /**\r\n * Stores the emissive values in a texture.\r\n * @internal\r\n */\r\n public _emissiveTexture: Nullable = null;\r\n\r\n /**\r\n * AKA Specular texture in other nomenclature.\r\n * @internal\r\n */\r\n public _reflectivityTexture: Nullable = null;\r\n\r\n /**\r\n * Used to switch from specular/glossiness to metallic/roughness workflow.\r\n * @internal\r\n */\r\n public _metallicTexture: Nullable = null;\r\n\r\n /**\r\n * Specifies the metallic scalar of the metallic/roughness workflow.\r\n * Can also be used to scale the metalness values of the metallic texture.\r\n * @internal\r\n */\r\n public _metallic: Nullable = null;\r\n\r\n /**\r\n * Specifies the roughness scalar of the metallic/roughness workflow.\r\n * Can also be used to scale the roughness values of the metallic texture.\r\n * @internal\r\n */\r\n public _roughness: Nullable = null;\r\n\r\n /**\r\n * In metallic workflow, specifies an F0 factor to help configuring the material F0.\r\n * By default the indexOfrefraction is used to compute F0;\r\n *\r\n * This is used as a factor against the default reflectance at normal incidence to tweak it.\r\n *\r\n * F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor;\r\n * F90 = metallicReflectanceColor;\r\n * @internal\r\n */\r\n public _metallicF0Factor = 1;\r\n\r\n /**\r\n * In metallic workflow, specifies an F0 color.\r\n * By default the F90 is always 1;\r\n *\r\n * Please note that this factor is also used as a factor against the default reflectance at normal incidence.\r\n *\r\n * F0 = defaultF0_from_IOR * metallicF0Factor * metallicReflectanceColor\r\n * F90 = metallicF0Factor;\r\n * @internal\r\n */\r\n public _metallicReflectanceColor = Color3.White();\r\n\r\n /**\r\n * Specifies that only the A channel from _metallicReflectanceTexture should be used.\r\n * If false, both RGB and A channels will be used\r\n * @internal\r\n */\r\n public _useOnlyMetallicFromMetallicReflectanceTexture = false;\r\n\r\n /**\r\n * Defines to store metallicReflectanceColor in RGB and metallicF0Factor in A\r\n * This is multiply against the scalar values defined in the material.\r\n * @internal\r\n */\r\n public _metallicReflectanceTexture: Nullable = null;\r\n\r\n /**\r\n * Defines to store reflectanceColor in RGB\r\n * This is multiplied against the scalar values defined in the material.\r\n * If both _reflectanceTexture and _metallicReflectanceTexture textures are provided and _useOnlyMetallicFromMetallicReflectanceTexture\r\n * is false, _metallicReflectanceTexture takes precedence and _reflectanceTexture is not used\r\n * @internal\r\n */\r\n public _reflectanceTexture: Nullable = null;\r\n\r\n /**\r\n * Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.\r\n * Gray Scale represents roughness in metallic mode and glossiness in specular mode.\r\n * @internal\r\n */\r\n public _microSurfaceTexture: Nullable = null;\r\n\r\n /**\r\n * Stores surface normal data used to displace a mesh in a texture.\r\n * @internal\r\n */\r\n public _bumpTexture: Nullable = null;\r\n\r\n /**\r\n * Stores the pre-calculated light information of a mesh in a texture.\r\n * @internal\r\n */\r\n public _lightmapTexture: Nullable = null;\r\n\r\n /**\r\n * The color of a material in ambient lighting.\r\n * @internal\r\n */\r\n public _ambientColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * AKA Diffuse Color in other nomenclature.\r\n * @internal\r\n */\r\n public _albedoColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * AKA Specular Color in other nomenclature.\r\n * @internal\r\n */\r\n public _reflectivityColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * The color applied when light is reflected from a material.\r\n * @internal\r\n */\r\n public _reflectionColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * The color applied when light is emitted from a material.\r\n * @internal\r\n */\r\n public _emissiveColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * AKA Glossiness in other nomenclature.\r\n * @internal\r\n */\r\n public _microSurface = 0.9;\r\n\r\n /**\r\n * Specifies that the material will use the light map as a show map.\r\n * @internal\r\n */\r\n public _useLightmapAsShadowmap = false;\r\n\r\n /**\r\n * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal\r\n * makes the reflect vector face the model (under horizon).\r\n * @internal\r\n */\r\n public _useHorizonOcclusion = true;\r\n\r\n /**\r\n * This parameters will enable/disable radiance occlusion by preventing the radiance to lit\r\n * too much the area relying on ambient texture to define their ambient occlusion.\r\n * @internal\r\n */\r\n public _useRadianceOcclusion = true;\r\n\r\n /**\r\n * Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.\r\n * @internal\r\n */\r\n public _useAlphaFromAlbedoTexture = false;\r\n\r\n /**\r\n * Specifies that the material will keeps the specular highlights over a transparent surface (only the most luminous ones).\r\n * A car glass is a good example of that. When sun reflects on it you can not see what is behind.\r\n * @internal\r\n */\r\n public _useSpecularOverAlpha = true;\r\n\r\n /**\r\n * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.\r\n * @internal\r\n */\r\n public _useMicroSurfaceFromReflectivityMapAlpha = false;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the roughness information in its alpha channel.\r\n * @internal\r\n */\r\n public _useRoughnessFromMetallicTextureAlpha = true;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the roughness information in its green channel.\r\n * @internal\r\n */\r\n public _useRoughnessFromMetallicTextureGreen = false;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the metallness information in its blue channel.\r\n * @internal\r\n */\r\n public _useMetallnessFromMetallicTextureBlue = false;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the ambient occlusion information in its red channel.\r\n * @internal\r\n */\r\n public _useAmbientOcclusionFromMetallicTextureRed = false;\r\n\r\n /**\r\n * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.\r\n * @internal\r\n */\r\n public _useAmbientInGrayScale = false;\r\n\r\n /**\r\n * In case the reflectivity map does not contain the microsurface information in its alpha channel,\r\n * The material will try to infer what glossiness each pixel should be.\r\n * @internal\r\n */\r\n public _useAutoMicroSurfaceFromReflectivityMap = false;\r\n\r\n /**\r\n * Defines the falloff type used in this material.\r\n * It by default is Physical.\r\n * @internal\r\n */\r\n public _lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL;\r\n\r\n /**\r\n * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most luminous ones).\r\n * A car glass is a good example of that. When the street lights reflects on it you can not see what is behind.\r\n * @internal\r\n */\r\n public _useRadianceOverAlpha = true;\r\n\r\n /**\r\n * Allows using an object space normal map (instead of tangent space).\r\n * @internal\r\n */\r\n public _useObjectSpaceNormalMap = false;\r\n\r\n /**\r\n * Allows using the bump map in parallax mode.\r\n * @internal\r\n */\r\n public _useParallax = false;\r\n\r\n /**\r\n * Allows using the bump map in parallax occlusion mode.\r\n * @internal\r\n */\r\n public _useParallaxOcclusion = false;\r\n\r\n /**\r\n * Controls the scale bias of the parallax mode.\r\n * @internal\r\n */\r\n public _parallaxScaleBias = 0.05;\r\n\r\n /**\r\n * If sets to true, disables all the lights affecting the material.\r\n * @internal\r\n */\r\n public _disableLighting = false;\r\n\r\n /**\r\n * Number of Simultaneous lights allowed on the material.\r\n * @internal\r\n */\r\n public _maxSimultaneousLights = 4;\r\n\r\n /**\r\n * If sets to true, x component of normal map value will be inverted (x = 1.0 - x).\r\n * @internal\r\n */\r\n public _invertNormalMapX = false;\r\n\r\n /**\r\n * If sets to true, y component of normal map value will be inverted (y = 1.0 - y).\r\n * @internal\r\n */\r\n public _invertNormalMapY = false;\r\n\r\n /**\r\n * If sets to true and backfaceCulling is false, normals will be flipped on the backside.\r\n * @internal\r\n */\r\n public _twoSidedLighting = false;\r\n\r\n /**\r\n * Defines the alpha limits in alpha test mode.\r\n * @internal\r\n */\r\n public _alphaCutOff = 0.4;\r\n\r\n /**\r\n * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.\r\n * @internal\r\n */\r\n public _forceAlphaTest = false;\r\n\r\n /**\r\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\r\n * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)\r\n * @internal\r\n */\r\n public _useAlphaFresnel = false;\r\n\r\n /**\r\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\r\n * And/Or occlude the blended part. (alpha stays linear to compute the fresnel)\r\n * @internal\r\n */\r\n public _useLinearAlphaFresnel = false;\r\n\r\n /**\r\n * Specifies the environment BRDF texture used to compute the scale and offset roughness values\r\n * from cos theta and roughness:\r\n * http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf\r\n * @internal\r\n */\r\n public _environmentBRDFTexture: Nullable = null;\r\n\r\n /**\r\n * Force the shader to compute irradiance in the fragment shader in order to take bump in account.\r\n * @internal\r\n */\r\n public _forceIrradianceInFragment = false;\r\n\r\n private _realTimeFiltering: boolean = false;\r\n /**\r\n * Enables realtime filtering on the texture.\r\n */\r\n public get realTimeFiltering() {\r\n return this._realTimeFiltering;\r\n }\r\n public set realTimeFiltering(b: boolean) {\r\n this._realTimeFiltering = b;\r\n this.markAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n private _realTimeFilteringQuality: number = Constants.TEXTURE_FILTERING_QUALITY_LOW;\r\n /**\r\n * Quality switch for realtime filtering\r\n */\r\n public get realTimeFilteringQuality(): number {\r\n return this._realTimeFilteringQuality;\r\n }\r\n public set realTimeFilteringQuality(n: number) {\r\n this._realTimeFilteringQuality = n;\r\n this.markAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n\r\n /**\r\n * Can this material render to several textures at once\r\n */\r\n public get canRenderToMRT() {\r\n return true;\r\n }\r\n\r\n /**\r\n * Force normal to face away from face.\r\n * @internal\r\n */\r\n public _forceNormalForward = false;\r\n\r\n /**\r\n * Enables specular anti aliasing in the PBR shader.\r\n * It will both interacts on the Geometry for analytical and IBL lighting.\r\n * It also prefilter the roughness map based on the bump values.\r\n * @internal\r\n */\r\n public _enableSpecularAntiAliasing = false;\r\n\r\n /**\r\n * Default configuration related to image processing available in the PBR Material.\r\n */\r\n @serializeAsImageProcessingConfiguration()\r\n protected _imageProcessingConfiguration: ImageProcessingConfiguration;\r\n\r\n /**\r\n * Keep track of the image processing observer to allow dispose and replace.\r\n */\r\n private _imageProcessingObserver: Nullable> = null;\r\n\r\n /**\r\n * Attaches a new image processing configuration to the PBR Material.\r\n * @param configuration\r\n */\r\n protected _attachImageProcessingConfiguration(configuration: Nullable): void {\r\n if (configuration === this._imageProcessingConfiguration) {\r\n return;\r\n }\r\n\r\n // Detaches observer.\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n // Pick the scene configuration if needed.\r\n if (!configuration) {\r\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\r\n } else {\r\n this._imageProcessingConfiguration = configuration;\r\n }\r\n\r\n // Attaches observer.\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\r\n this._markAllSubMeshesAsImageProcessingDirty();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stores the available render targets.\r\n */\r\n private _renderTargets = new SmartArray(16);\r\n\r\n /**\r\n * Sets the global ambient color for the material used in lighting calculations.\r\n */\r\n private _globalAmbientColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * Enables the use of logarithmic depth buffers, which is good for wide depth buffers.\r\n */\r\n private _useLogarithmicDepth: boolean = false;\r\n\r\n /**\r\n * If set to true, no lighting calculations will be applied.\r\n */\r\n private _unlit = false;\r\n\r\n /**\r\n * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)\r\n */\r\n private _applyDecalMapAfterDetailMap = false;\r\n\r\n private _debugMode = 0;\r\n /**\r\n * @internal\r\n * This is reserved for the inspector.\r\n * Defines the material debug mode.\r\n * It helps seeing only some components of the material while troubleshooting.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public debugMode = 0;\r\n\r\n /**\r\n * @internal\r\n * This is reserved for the inspector.\r\n * Specify from where on screen the debug mode should start.\r\n * The value goes from -1 (full screen) to 1 (not visible)\r\n * It helps with side by side comparison against the final render\r\n * This defaults to -1\r\n */\r\n public debugLimit = -1;\r\n\r\n /**\r\n * @internal\r\n * This is reserved for the inspector.\r\n * As the default viewing range might not be enough (if the ambient is really small for instance)\r\n * You can use the factor to better multiply the final value.\r\n */\r\n public debugFactor = 1;\r\n\r\n /**\r\n * Defines the clear coat layer parameters for the material.\r\n */\r\n public readonly clearCoat: PBRClearCoatConfiguration;\r\n\r\n /**\r\n * Defines the iridescence layer parameters for the material.\r\n */\r\n public readonly iridescence: PBRIridescenceConfiguration;\r\n\r\n /**\r\n * Defines the anisotropic parameters for the material.\r\n */\r\n public readonly anisotropy: PBRAnisotropicConfiguration;\r\n\r\n /**\r\n * Defines the BRDF parameters for the material.\r\n */\r\n public readonly brdf: PBRBRDFConfiguration;\r\n\r\n /**\r\n * Defines the Sheen parameters for the material.\r\n */\r\n public readonly sheen: PBRSheenConfiguration;\r\n\r\n /**\r\n * Defines the SubSurface parameters for the material.\r\n */\r\n public readonly subSurface: PBRSubSurfaceConfiguration;\r\n\r\n /**\r\n * Defines additional PrePass parameters for the material.\r\n */\r\n public readonly prePassConfiguration: PrePassConfiguration;\r\n\r\n /**\r\n * Defines the detail map parameters for the material.\r\n */\r\n public readonly detailMap: DetailMapConfiguration;\r\n\r\n protected _cacheHasRenderTargetTextures = false;\r\n\r\n /**\r\n * Instantiates a new PBRMaterial instance.\r\n *\r\n * @param name The material name\r\n * @param scene The scene the material will be use in.\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n\r\n this.brdf = new PBRBRDFConfiguration(this);\r\n this.clearCoat = new PBRClearCoatConfiguration(this);\r\n this.iridescence = new PBRIridescenceConfiguration(this);\r\n this.anisotropy = new PBRAnisotropicConfiguration(this);\r\n this.sheen = new PBRSheenConfiguration(this);\r\n this.subSurface = new PBRSubSurfaceConfiguration(this);\r\n this.detailMap = new DetailMapConfiguration(this);\r\n\r\n // Setup the default processing configuration to the scene.\r\n this._attachImageProcessingConfiguration(null);\r\n\r\n this.getRenderTargetTextures = (): SmartArray => {\r\n this._renderTargets.reset();\r\n\r\n if (MaterialFlags.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n this._renderTargets.push(this._reflectionTexture);\r\n }\r\n\r\n this._eventInfo.renderTargets = this._renderTargets;\r\n this._callbackPluginEventFillRenderTargetTextures(this._eventInfo);\r\n\r\n return this._renderTargets;\r\n };\r\n\r\n this._environmentBRDFTexture = GetEnvironmentBRDFTexture(this.getScene());\r\n this.prePassConfiguration = new PrePassConfiguration();\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n */\r\n public get hasRenderTargetTextures(): boolean {\r\n if (MaterialFlags.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n return true;\r\n }\r\n\r\n return this._cacheHasRenderTargetTextures;\r\n }\r\n\r\n /**\r\n * Can this material render to prepass\r\n */\r\n public get isPrePassCapable(): boolean {\r\n return !this.disableDepthWrite;\r\n }\r\n\r\n /**\r\n * Gets the name of the material class.\r\n */\r\n public getClassName(): string {\r\n return \"PBRBaseMaterial\";\r\n }\r\n\r\n /**\r\n * Enabled the use of logarithmic depth buffers, which is good for wide depth buffers.\r\n */\r\n @serialize()\r\n public get useLogarithmicDepth(): boolean {\r\n return this._useLogarithmicDepth;\r\n }\r\n\r\n /**\r\n * Enabled the use of logarithmic depth buffers, which is good for wide depth buffers.\r\n */\r\n public set useLogarithmicDepth(value: boolean) {\r\n this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;\r\n }\r\n\r\n /**\r\n * Returns true if alpha blending should be disabled.\r\n */\r\n protected get _disableAlphaBlending(): boolean {\r\n return (\r\n this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_OPAQUE ||\r\n this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST ||\r\n this.subSurface?.disableAlphaBlending\r\n );\r\n }\r\n\r\n /**\r\n * Specifies whether or not this material should be rendered in alpha blend mode.\r\n */\r\n public needAlphaBlending(): boolean {\r\n if (this._disableAlphaBlending) {\r\n return false;\r\n }\r\n\r\n return this.alpha < 1.0 || this._opacityTexture != null || this._shouldUseAlphaFromAlbedoTexture();\r\n }\r\n\r\n /**\r\n * Specifies whether or not this material should be rendered in alpha test mode.\r\n */\r\n public needAlphaTesting(): boolean {\r\n if (this._forceAlphaTest) {\r\n return true;\r\n }\r\n\r\n if (this.subSurface?.disableAlphaBlending) {\r\n return false;\r\n }\r\n\r\n return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST);\r\n }\r\n\r\n /**\r\n * Specifies whether or not the alpha value of the albedo texture should be used for alpha blending.\r\n */\r\n protected _shouldUseAlphaFromAlbedoTexture(): boolean {\r\n return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE;\r\n }\r\n\r\n /**\r\n * Specifies whether or not there is a usable alpha channel for transparency.\r\n */\r\n protected _hasAlphaChannel(): boolean {\r\n return (this._albedoTexture != null && this._albedoTexture.hasAlpha) || this._opacityTexture != null;\r\n }\r\n\r\n /**\r\n * Gets the texture used for the alpha test.\r\n */\r\n public getAlphaTestTexture(): Nullable {\r\n return this._albedoTexture;\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used.\r\n * @param mesh - BJS mesh.\r\n * @param subMesh - A submesh of the BJS mesh. Used to check if it is ready.\r\n * @param useInstances - Specifies that instances should be used.\r\n * @returns - boolean indicating that the submesh is ready or not.\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n if (!this._uniformBufferLayoutBuilt) {\r\n this.buildUniformLayout();\r\n }\r\n\r\n if (subMesh.effect && this.isFrozen) {\r\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetDefineNames, this._eventInfo);\r\n subMesh.materialDefines = new PBRMaterialDefines(this._eventInfo.defineNames);\r\n }\r\n\r\n const defines = subMesh.materialDefines;\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const scene = this.getScene();\r\n const engine = scene.getEngine();\r\n\r\n if (defines._areTexturesDirty) {\r\n this._eventInfo.hasRenderTargetTextures = false;\r\n this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);\r\n this._cacheHasRenderTargetTextures = this._eventInfo.hasRenderTargetTextures;\r\n if (scene.texturesEnabled) {\r\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n if (!this._albedoTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\r\n if (!this._ambientTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\r\n if (!this._opacityTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n const reflectionTexture = this._getReflectionTexture();\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n if (!reflectionTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n if (reflectionTexture.irradianceTexture) {\r\n if (!reflectionTexture.irradianceTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n } else {\r\n // Not ready until spherical are ready too.\r\n if (!reflectionTexture.sphericalPolynomial && reflectionTexture.getInternalTexture()?._sphericalPolynomialPromise) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\r\n if (!this._lightmapTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\r\n if (!this._emissiveTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (MaterialFlags.SpecularTextureEnabled) {\r\n if (this._metallicTexture) {\r\n if (!this._metallicTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n } else if (this._reflectivityTexture) {\r\n if (!this._reflectivityTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._metallicReflectanceTexture) {\r\n if (!this._metallicReflectanceTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._reflectanceTexture) {\r\n if (!this._reflectanceTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._microSurfaceTexture) {\r\n if (!this._microSurfaceTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\r\n // Bump texture cannot be not blocking.\r\n if (!this._bumpTexture.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n // This is blocking.\r\n if (!this._environmentBRDFTexture.isReady()) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n\r\n this._eventInfo.isReadyForSubMesh = true;\r\n this._eventInfo.defines = defines;\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);\r\n\r\n if (!this._eventInfo.isReadyForSubMesh) {\r\n return false;\r\n }\r\n\r\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\r\n if (!this._imageProcessingConfiguration.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (!engine.getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n mesh.createNormals(true);\r\n Logger.Warn(\"PBRMaterial: Normals have been created for the mesh: \" + mesh.name);\r\n }\r\n\r\n const previousEffect = subMesh.effect;\r\n const lightDisposed = defines._areLightsDisposed;\r\n let effect = this._prepareEffect(mesh, defines, this.onCompiled, this.onError, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);\r\n\r\n let forceWasNotReadyPreviously = false;\r\n\r\n if (effect) {\r\n if (this._onEffectCreatedObservable) {\r\n onCreatedEffectParameters.effect = effect;\r\n onCreatedEffectParameters.subMesh = subMesh;\r\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);\r\n }\r\n\r\n // Use previous effect while new one is compiling\r\n if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {\r\n effect = previousEffect;\r\n defines.markAsUnprocessed();\r\n\r\n forceWasNotReadyPreviously = this.isFrozen;\r\n\r\n if (lightDisposed) {\r\n // re register in case it takes more than one frame.\r\n defines._areLightsDisposed = true;\r\n return false;\r\n }\r\n } else {\r\n scene.resetCachedMaterial();\r\n subMesh.setEffect(effect, defines, this._materialContext);\r\n }\r\n }\r\n\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = forceWasNotReadyPreviously ? false : true;\r\n subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;\r\n\r\n this._checkScenePerformancePriority();\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Specifies if the material uses metallic roughness workflow.\r\n * @returns boolean specifying if the material uses metallic roughness workflow.\r\n */\r\n public isMetallicWorkflow(): boolean {\r\n if (this._metallic != null || this._roughness != null || this._metallicTexture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _prepareEffect(\r\n mesh: AbstractMesh,\r\n defines: PBRMaterialDefines,\r\n onCompiled: Nullable<(effect: Effect) => void> = null,\r\n onError: Nullable<(effect: Effect, errors: string) => void> = null,\r\n useInstances: Nullable = null,\r\n useClipPlane: Nullable = null,\r\n useThinInstances: boolean\r\n ): Nullable {\r\n this._prepareDefines(mesh, defines, useInstances, useClipPlane, useThinInstances);\r\n\r\n if (!defines.isDirty) {\r\n return null;\r\n }\r\n\r\n defines.markAsProcessed();\r\n\r\n const scene = this.getScene();\r\n const engine = scene.getEngine();\r\n\r\n // Fallbacks\r\n const fallbacks = new EffectFallbacks();\r\n let fallbackRank = 0;\r\n if (defines.USESPHERICALINVERTEX) {\r\n fallbacks.addFallback(fallbackRank++, \"USESPHERICALINVERTEX\");\r\n }\r\n\r\n if (defines.FOG) {\r\n fallbacks.addFallback(fallbackRank, \"FOG\");\r\n }\r\n if (defines.SPECULARAA) {\r\n fallbacks.addFallback(fallbackRank, \"SPECULARAA\");\r\n }\r\n if (defines.POINTSIZE) {\r\n fallbacks.addFallback(fallbackRank, \"POINTSIZE\");\r\n }\r\n if (defines.LOGARITHMICDEPTH) {\r\n fallbacks.addFallback(fallbackRank, \"LOGARITHMICDEPTH\");\r\n }\r\n if (defines.PARALLAX) {\r\n fallbacks.addFallback(fallbackRank, \"PARALLAX\");\r\n }\r\n if (defines.PARALLAXOCCLUSION) {\r\n fallbacks.addFallback(fallbackRank++, \"PARALLAXOCCLUSION\");\r\n }\r\n\r\n if (defines.ENVIRONMENTBRDF) {\r\n fallbacks.addFallback(fallbackRank++, \"ENVIRONMENTBRDF\");\r\n }\r\n\r\n if (defines.TANGENT) {\r\n fallbacks.addFallback(fallbackRank++, \"TANGENT\");\r\n }\r\n\r\n if (defines.BUMP) {\r\n fallbacks.addFallback(fallbackRank++, \"BUMP\");\r\n }\r\n\r\n fallbackRank = MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights, fallbackRank++);\r\n\r\n if (defines.SPECULARTERM) {\r\n fallbacks.addFallback(fallbackRank++, \"SPECULARTERM\");\r\n }\r\n\r\n if (defines.USESPHERICALFROMREFLECTIONMAP) {\r\n fallbacks.addFallback(fallbackRank++, \"USESPHERICALFROMREFLECTIONMAP\");\r\n }\r\n\r\n if (defines.USEIRRADIANCEMAP) {\r\n fallbacks.addFallback(fallbackRank++, \"USEIRRADIANCEMAP\");\r\n }\r\n\r\n if (defines.LIGHTMAP) {\r\n fallbacks.addFallback(fallbackRank++, \"LIGHTMAP\");\r\n }\r\n\r\n if (defines.NORMAL) {\r\n fallbacks.addFallback(fallbackRank++, \"NORMAL\");\r\n }\r\n\r\n if (defines.AMBIENT) {\r\n fallbacks.addFallback(fallbackRank++, \"AMBIENT\");\r\n }\r\n\r\n if (defines.EMISSIVE) {\r\n fallbacks.addFallback(fallbackRank++, \"EMISSIVE\");\r\n }\r\n\r\n if (defines.VERTEXCOLOR) {\r\n fallbacks.addFallback(fallbackRank++, \"VERTEXCOLOR\");\r\n }\r\n\r\n if (defines.MORPHTARGETS) {\r\n fallbacks.addFallback(fallbackRank++, \"MORPHTARGETS\");\r\n }\r\n\r\n if (defines.MULTIVIEW) {\r\n fallbacks.addFallback(0, \"MULTIVIEW\");\r\n }\r\n\r\n //Attributes\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n if (defines.NORMAL) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n }\r\n\r\n if (defines.TANGENT) {\r\n attribs.push(VertexBuffer.TangentKind);\r\n }\r\n\r\n for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {\r\n if (defines[\"UV\" + i]) {\r\n attribs.push(`uv${i === 1 ? \"\" : i}`);\r\n }\r\n }\r\n\r\n if (defines.VERTEXCOLOR) {\r\n attribs.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n if (defines.INSTANCESCOLOR) {\r\n attribs.push(VertexBuffer.ColorInstanceKind);\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\r\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\r\n MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);\r\n MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\r\n\r\n let shaderName = \"pbr\";\r\n\r\n const uniforms = [\r\n \"world\",\r\n \"view\",\r\n \"viewProjection\",\r\n \"vEyePosition\",\r\n \"vLightsType\",\r\n \"vAmbientColor\",\r\n \"vAlbedoColor\",\r\n \"vReflectivityColor\",\r\n \"vMetallicReflectanceFactors\",\r\n \"vEmissiveColor\",\r\n \"visibility\",\r\n \"vReflectionColor\",\r\n \"vFogInfos\",\r\n \"vFogColor\",\r\n \"pointSize\",\r\n \"vAlbedoInfos\",\r\n \"vAmbientInfos\",\r\n \"vOpacityInfos\",\r\n \"vReflectionInfos\",\r\n \"vReflectionPosition\",\r\n \"vReflectionSize\",\r\n \"vEmissiveInfos\",\r\n \"vReflectivityInfos\",\r\n \"vReflectionFilteringInfo\",\r\n \"vMetallicReflectanceInfos\",\r\n \"vReflectanceInfos\",\r\n \"vMicroSurfaceSamplerInfos\",\r\n \"vBumpInfos\",\r\n \"vLightmapInfos\",\r\n \"mBones\",\r\n \"albedoMatrix\",\r\n \"ambientMatrix\",\r\n \"opacityMatrix\",\r\n \"reflectionMatrix\",\r\n \"emissiveMatrix\",\r\n \"reflectivityMatrix\",\r\n \"normalMatrix\",\r\n \"microSurfaceSamplerMatrix\",\r\n \"bumpMatrix\",\r\n \"lightmapMatrix\",\r\n \"metallicReflectanceMatrix\",\r\n \"reflectanceMatrix\",\r\n \"vLightingIntensity\",\r\n \"logarithmicDepthConstant\",\r\n \"vSphericalX\",\r\n \"vSphericalY\",\r\n \"vSphericalZ\",\r\n \"vSphericalXX_ZZ\",\r\n \"vSphericalYY_ZZ\",\r\n \"vSphericalZZ\",\r\n \"vSphericalXY\",\r\n \"vSphericalYZ\",\r\n \"vSphericalZX\",\r\n \"vSphericalL00\",\r\n \"vSphericalL1_1\",\r\n \"vSphericalL10\",\r\n \"vSphericalL11\",\r\n \"vSphericalL2_2\",\r\n \"vSphericalL2_1\",\r\n \"vSphericalL20\",\r\n \"vSphericalL21\",\r\n \"vSphericalL22\",\r\n \"vReflectionMicrosurfaceInfos\",\r\n \"vTangentSpaceParams\",\r\n \"boneTextureWidth\",\r\n \"vDebugMode\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n ];\r\n\r\n const samplers = [\r\n \"albedoSampler\",\r\n \"reflectivitySampler\",\r\n \"ambientSampler\",\r\n \"emissiveSampler\",\r\n \"bumpSampler\",\r\n \"lightmapSampler\",\r\n \"opacitySampler\",\r\n \"reflectionSampler\",\r\n \"reflectionSamplerLow\",\r\n \"reflectionSamplerHigh\",\r\n \"irradianceSampler\",\r\n \"microSurfaceSampler\",\r\n \"environmentBrdfSampler\",\r\n \"boneSampler\",\r\n \"metallicReflectanceSampler\",\r\n \"reflectanceSampler\",\r\n \"morphTargets\",\r\n \"oitDepthSampler\",\r\n \"oitFrontColorSampler\",\r\n ];\r\n\r\n const uniformBuffers = [\"Material\", \"Scene\", \"Mesh\"];\r\n\r\n const indexParameters = { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS };\r\n\r\n this._eventInfo.fallbacks = fallbacks;\r\n this._eventInfo.fallbackRank = fallbackRank;\r\n this._eventInfo.defines = defines;\r\n this._eventInfo.uniforms = uniforms;\r\n this._eventInfo.attributes = attribs;\r\n this._eventInfo.samplers = samplers;\r\n this._eventInfo.uniformBuffersNames = uniformBuffers;\r\n this._eventInfo.customCode = undefined;\r\n this._eventInfo.mesh = mesh;\r\n this._eventInfo.indexParameters = indexParameters;\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareEffect, this._eventInfo);\r\n\r\n PrePassConfiguration.AddUniforms(uniforms);\r\n PrePassConfiguration.AddSamplers(samplers);\r\n addClipPlaneUniforms(uniforms);\r\n\r\n if (ImageProcessingConfiguration) {\r\n ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);\r\n ImageProcessingConfiguration.PrepareSamplers(samplers, defines);\r\n }\r\n\r\n MaterialHelper.PrepareUniformsAndSamplersList({\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: defines,\r\n maxSimultaneousLights: this._maxSimultaneousLights,\r\n });\r\n\r\n const csnrOptions: ICustomShaderNameResolveOptions = {};\r\n\r\n if (this.customShaderNameResolve) {\r\n shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs, csnrOptions);\r\n }\r\n\r\n const join = defines.toString();\r\n const effect = engine.createEffect(\r\n shaderName,\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: onCompiled,\r\n onError: onError,\r\n indexParameters,\r\n processFinalCode: csnrOptions.processFinalCode,\r\n processCodeAfterIncludes: this._eventInfo.customCode,\r\n multiTarget: defines.PREPASS,\r\n },\r\n engine\r\n );\r\n\r\n this._eventInfo.customCode = undefined;\r\n\r\n return effect;\r\n }\r\n\r\n private _prepareDefines(\r\n mesh: AbstractMesh,\r\n defines: PBRMaterialDefines,\r\n useInstances: Nullable = null,\r\n useClipPlane: Nullable = null,\r\n useThinInstances: boolean = false\r\n ): void {\r\n const scene = this.getScene();\r\n const engine = scene.getEngine();\r\n\r\n // Lights\r\n MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);\r\n defines._needNormals = true;\r\n\r\n // Multiview\r\n MaterialHelper.PrepareDefinesForMultiview(scene, defines);\r\n\r\n // PrePass\r\n const oit = this.needAlphaBlendingForMesh(mesh) && this.getScene().useOrderIndependentTransparency;\r\n MaterialHelper.PrepareDefinesForPrePass(scene, defines, this.canRenderToMRT && !oit);\r\n\r\n // Order independant transparency\r\n MaterialHelper.PrepareDefinesForOIT(scene, defines, oit);\r\n\r\n // Textures\r\n defines.METALLICWORKFLOW = this.isMetallicWorkflow();\r\n if (defines._areTexturesDirty) {\r\n defines._needUVs = false;\r\n for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {\r\n defines[\"MAINUV\" + i] = false;\r\n }\r\n if (scene.texturesEnabled) {\r\n defines.ALBEDODIRECTUV = 0;\r\n defines.AMBIENTDIRECTUV = 0;\r\n defines.OPACITYDIRECTUV = 0;\r\n defines.EMISSIVEDIRECTUV = 0;\r\n defines.REFLECTIVITYDIRECTUV = 0;\r\n defines.MICROSURFACEMAPDIRECTUV = 0;\r\n defines.METALLIC_REFLECTANCEDIRECTUV = 0;\r\n defines.REFLECTANCEDIRECTUV = 0;\r\n defines.BUMPDIRECTUV = 0;\r\n defines.LIGHTMAPDIRECTUV = 0;\r\n\r\n if (engine.getCaps().textureLOD) {\r\n defines.LODBASEDMICROSFURACE = true;\r\n }\r\n\r\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._albedoTexture, defines, \"ALBEDO\");\r\n defines.GAMMAALBEDO = this._albedoTexture.gammaSpace;\r\n } else {\r\n defines.ALBEDO = false;\r\n }\r\n\r\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._ambientTexture, defines, \"AMBIENT\");\r\n defines.AMBIENTINGRAYSCALE = this._useAmbientInGrayScale;\r\n } else {\r\n defines.AMBIENT = false;\r\n }\r\n\r\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._opacityTexture, defines, \"OPACITY\");\r\n defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;\r\n } else {\r\n defines.OPACITY = false;\r\n }\r\n\r\n const reflectionTexture = this._getReflectionTexture();\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n defines.REFLECTION = true;\r\n defines.GAMMAREFLECTION = reflectionTexture.gammaSpace;\r\n defines.RGBDREFLECTION = reflectionTexture.isRGBD;\r\n defines.LODINREFLECTIONALPHA = reflectionTexture.lodLevelInAlpha;\r\n defines.LINEARSPECULARREFLECTION = reflectionTexture.linearSpecularLOD;\r\n\r\n if (this.realTimeFiltering && this.realTimeFilteringQuality > 0) {\r\n defines.NUM_SAMPLES = \"\" + this.realTimeFilteringQuality;\r\n if (engine._features.needTypeSuffixInShaderConstants) {\r\n defines.NUM_SAMPLES = defines.NUM_SAMPLES + \"u\";\r\n }\r\n\r\n defines.REALTIME_FILTERING = true;\r\n } else {\r\n defines.REALTIME_FILTERING = false;\r\n }\r\n\r\n defines.INVERTCUBICMAP = reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE;\r\n defines.REFLECTIONMAP_3D = reflectionTexture.isCube;\r\n defines.REFLECTIONMAP_OPPOSITEZ = defines.REFLECTIONMAP_3D && this.getScene().useRightHandedSystem ? !reflectionTexture.invertZ : reflectionTexture.invertZ;\r\n\r\n defines.REFLECTIONMAP_CUBIC = false;\r\n defines.REFLECTIONMAP_EXPLICIT = false;\r\n defines.REFLECTIONMAP_PLANAR = false;\r\n defines.REFLECTIONMAP_PROJECTION = false;\r\n defines.REFLECTIONMAP_SKYBOX = false;\r\n defines.REFLECTIONMAP_SPHERICAL = false;\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR = false;\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\r\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\r\n\r\n switch (reflectionTexture.coordinatesMode) {\r\n case Texture.EXPLICIT_MODE:\r\n defines.REFLECTIONMAP_EXPLICIT = true;\r\n break;\r\n case Texture.PLANAR_MODE:\r\n defines.REFLECTIONMAP_PLANAR = true;\r\n break;\r\n case Texture.PROJECTION_MODE:\r\n defines.REFLECTIONMAP_PROJECTION = true;\r\n break;\r\n case Texture.SKYBOX_MODE:\r\n defines.REFLECTIONMAP_SKYBOX = true;\r\n break;\r\n case Texture.SPHERICAL_MODE:\r\n defines.REFLECTIONMAP_SPHERICAL = true;\r\n break;\r\n case Texture.EQUIRECTANGULAR_MODE:\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR = true;\r\n break;\r\n case Texture.FIXED_EQUIRECTANGULAR_MODE:\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;\r\n break;\r\n case Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:\r\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;\r\n break;\r\n case Texture.CUBIC_MODE:\r\n case Texture.INVCUBIC_MODE:\r\n default:\r\n defines.REFLECTIONMAP_CUBIC = true;\r\n defines.USE_LOCAL_REFLECTIONMAP_CUBIC = (reflectionTexture).boundingBoxSize ? true : false;\r\n break;\r\n }\r\n\r\n if (reflectionTexture.coordinatesMode !== Texture.SKYBOX_MODE) {\r\n if (reflectionTexture.irradianceTexture) {\r\n defines.USEIRRADIANCEMAP = true;\r\n defines.USESPHERICALFROMREFLECTIONMAP = false;\r\n }\r\n // Assume using spherical polynomial if the reflection texture is a cube map\r\n else if (reflectionTexture.isCube) {\r\n defines.USESPHERICALFROMREFLECTIONMAP = true;\r\n defines.USEIRRADIANCEMAP = false;\r\n if (this._forceIrradianceInFragment || this.realTimeFiltering || engine.getCaps().maxVaryingVectors <= 8) {\r\n defines.USESPHERICALINVERTEX = false;\r\n } else {\r\n defines.USESPHERICALINVERTEX = true;\r\n }\r\n }\r\n }\r\n } else {\r\n defines.REFLECTION = false;\r\n defines.REFLECTIONMAP_3D = false;\r\n defines.REFLECTIONMAP_SPHERICAL = false;\r\n defines.REFLECTIONMAP_PLANAR = false;\r\n defines.REFLECTIONMAP_CUBIC = false;\r\n defines.USE_LOCAL_REFLECTIONMAP_CUBIC = false;\r\n defines.REFLECTIONMAP_PROJECTION = false;\r\n defines.REFLECTIONMAP_SKYBOX = false;\r\n defines.REFLECTIONMAP_EXPLICIT = false;\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR = false;\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\r\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\r\n defines.INVERTCUBICMAP = false;\r\n defines.USESPHERICALFROMREFLECTIONMAP = false;\r\n defines.USEIRRADIANCEMAP = false;\r\n defines.USESPHERICALINVERTEX = false;\r\n defines.REFLECTIONMAP_OPPOSITEZ = false;\r\n defines.LODINREFLECTIONALPHA = false;\r\n defines.GAMMAREFLECTION = false;\r\n defines.RGBDREFLECTION = false;\r\n defines.LINEARSPECULARREFLECTION = false;\r\n }\r\n\r\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._lightmapTexture, defines, \"LIGHTMAP\");\r\n defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;\r\n defines.GAMMALIGHTMAP = this._lightmapTexture.gammaSpace;\r\n defines.RGBDLIGHTMAP = this._lightmapTexture.isRGBD;\r\n } else {\r\n defines.LIGHTMAP = false;\r\n }\r\n\r\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._emissiveTexture, defines, \"EMISSIVE\");\r\n defines.GAMMAEMISSIVE = this._emissiveTexture.gammaSpace;\r\n } else {\r\n defines.EMISSIVE = false;\r\n }\r\n\r\n if (MaterialFlags.SpecularTextureEnabled) {\r\n if (this._metallicTexture) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._metallicTexture, defines, \"REFLECTIVITY\");\r\n defines.ROUGHNESSSTOREINMETALMAPALPHA = this._useRoughnessFromMetallicTextureAlpha;\r\n defines.ROUGHNESSSTOREINMETALMAPGREEN = !this._useRoughnessFromMetallicTextureAlpha && this._useRoughnessFromMetallicTextureGreen;\r\n defines.METALLNESSSTOREINMETALMAPBLUE = this._useMetallnessFromMetallicTextureBlue;\r\n defines.AOSTOREINMETALMAPRED = this._useAmbientOcclusionFromMetallicTextureRed;\r\n defines.REFLECTIVITY_GAMMA = false;\r\n } else if (this._reflectivityTexture) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._reflectivityTexture, defines, \"REFLECTIVITY\");\r\n defines.MICROSURFACEFROMREFLECTIVITYMAP = this._useMicroSurfaceFromReflectivityMapAlpha;\r\n defines.MICROSURFACEAUTOMATIC = this._useAutoMicroSurfaceFromReflectivityMap;\r\n defines.REFLECTIVITY_GAMMA = this._reflectivityTexture.gammaSpace;\r\n } else {\r\n defines.REFLECTIVITY = false;\r\n }\r\n\r\n if (this._metallicReflectanceTexture || this._reflectanceTexture) {\r\n const identicalTextures =\r\n this._metallicReflectanceTexture !== null &&\r\n this._metallicReflectanceTexture._texture === this._reflectanceTexture?._texture &&\r\n this._metallicReflectanceTexture.checkTransformsAreIdentical(this._reflectanceTexture);\r\n\r\n defines.METALLIC_REFLECTANCE_USE_ALPHA_ONLY = this._useOnlyMetallicFromMetallicReflectanceTexture && !identicalTextures;\r\n if (this._metallicReflectanceTexture) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._metallicReflectanceTexture, defines, \"METALLIC_REFLECTANCE\");\r\n defines.METALLIC_REFLECTANCE_GAMMA = this._metallicReflectanceTexture.gammaSpace;\r\n } else {\r\n defines.METALLIC_REFLECTANCE = false;\r\n }\r\n if (\r\n this._reflectanceTexture &&\r\n !identicalTextures &&\r\n (!this._metallicReflectanceTexture || (this._metallicReflectanceTexture && this._useOnlyMetallicFromMetallicReflectanceTexture))\r\n ) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._reflectanceTexture, defines, \"REFLECTANCE\");\r\n defines.REFLECTANCE_GAMMA = this._reflectanceTexture.gammaSpace;\r\n } else {\r\n defines.REFLECTANCE = false;\r\n }\r\n } else {\r\n defines.METALLIC_REFLECTANCE = false;\r\n defines.REFLECTANCE = false;\r\n }\r\n\r\n if (this._microSurfaceTexture) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._microSurfaceTexture, defines, \"MICROSURFACEMAP\");\r\n } else {\r\n defines.MICROSURFACEMAP = false;\r\n }\r\n } else {\r\n defines.REFLECTIVITY = false;\r\n defines.MICROSURFACEMAP = false;\r\n }\r\n\r\n if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\r\n MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, \"BUMP\");\r\n\r\n if (this._useParallax && this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n defines.PARALLAX = true;\r\n defines.PARALLAXOCCLUSION = !!this._useParallaxOcclusion;\r\n } else {\r\n defines.PARALLAX = false;\r\n }\r\n\r\n defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;\r\n } else {\r\n defines.BUMP = false;\r\n defines.PARALLAX = false;\r\n defines.PARALLAXOCCLUSION = false;\r\n defines.OBJECTSPACE_NORMALMAP = false;\r\n }\r\n\r\n if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n defines.ENVIRONMENTBRDF = true;\r\n defines.ENVIRONMENTBRDF_RGBD = this._environmentBRDFTexture.isRGBD;\r\n } else {\r\n defines.ENVIRONMENTBRDF = false;\r\n defines.ENVIRONMENTBRDF_RGBD = false;\r\n }\r\n\r\n if (this._shouldUseAlphaFromAlbedoTexture()) {\r\n defines.ALPHAFROMALBEDO = true;\r\n } else {\r\n defines.ALPHAFROMALBEDO = false;\r\n }\r\n }\r\n\r\n defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;\r\n\r\n if (this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_STANDARD) {\r\n defines.USEPHYSICALLIGHTFALLOFF = false;\r\n defines.USEGLTFLIGHTFALLOFF = false;\r\n } else if (this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_GLTF) {\r\n defines.USEPHYSICALLIGHTFALLOFF = false;\r\n defines.USEGLTFLIGHTFALLOFF = true;\r\n } else {\r\n defines.USEPHYSICALLIGHTFALLOFF = true;\r\n defines.USEGLTFLIGHTFALLOFF = false;\r\n }\r\n\r\n defines.RADIANCEOVERALPHA = this._useRadianceOverAlpha;\r\n\r\n if (!this.backFaceCulling && this._twoSidedLighting) {\r\n defines.TWOSIDEDLIGHTING = true;\r\n } else {\r\n defines.TWOSIDEDLIGHTING = false;\r\n }\r\n\r\n defines.SPECULARAA = engine.getCaps().standardDerivatives && this._enableSpecularAntiAliasing;\r\n }\r\n\r\n if (defines._areTexturesDirty || defines._areMiscDirty) {\r\n defines.ALPHATESTVALUE = `${this._alphaCutOff}${this._alphaCutOff % 1 === 0 ? \".\" : \"\"}`;\r\n defines.PREMULTIPLYALPHA = this.alphaMode === Constants.ALPHA_PREMULTIPLIED || this.alphaMode === Constants.ALPHA_PREMULTIPLIED_PORTERDUFF;\r\n defines.ALPHABLEND = this.needAlphaBlendingForMesh(mesh);\r\n defines.ALPHAFRESNEL = this._useAlphaFresnel || this._useLinearAlphaFresnel;\r\n defines.LINEARALPHAFRESNEL = this._useLinearAlphaFresnel;\r\n }\r\n\r\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\r\n this._imageProcessingConfiguration.prepareDefines(defines);\r\n }\r\n\r\n defines.FORCENORMALFORWARD = this._forceNormalForward;\r\n\r\n defines.RADIANCEOCCLUSION = this._useRadianceOcclusion;\r\n\r\n defines.HORIZONOCCLUSION = this._useHorizonOcclusion;\r\n\r\n // Misc.\r\n if (defines._areMiscDirty) {\r\n MaterialHelper.PrepareDefinesForMisc(\r\n mesh,\r\n scene,\r\n this._useLogarithmicDepth,\r\n this.pointsCloud,\r\n this.fogEnabled,\r\n this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest,\r\n defines,\r\n this._applyDecalMapAfterDetailMap\r\n );\r\n defines.UNLIT = this._unlit || ((this.pointsCloud || this.wireframe) && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind));\r\n defines.DEBUGMODE = this._debugMode;\r\n }\r\n\r\n // Values that need to be evaluated on every frame\r\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false, useClipPlane, useThinInstances);\r\n\r\n // External config\r\n this._eventInfo.defines = defines;\r\n this._eventInfo.mesh = mesh;\r\n this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);\r\n\r\n // Attribs\r\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE);\r\n\r\n // External config\r\n this._callbackPluginEventPrepareDefines(this._eventInfo);\r\n }\r\n\r\n /**\r\n * Force shader compilation\r\n * @param mesh\r\n * @param onCompiled\r\n * @param options\r\n */\r\n public forceCompilation(mesh: AbstractMesh, onCompiled?: (material: Material) => void, options?: Partial): void {\r\n const localOptions = {\r\n clipPlane: false,\r\n useInstances: false,\r\n ...options,\r\n };\r\n\r\n if (!this._uniformBufferLayoutBuilt) {\r\n this.buildUniformLayout();\r\n }\r\n\r\n this._callbackPluginEventGeneric(MaterialPluginEvent.GetDefineNames, this._eventInfo);\r\n const defines = new PBRMaterialDefines(this._eventInfo.defineNames);\r\n const effect = this._prepareEffect(mesh, defines, undefined, undefined, localOptions.useInstances, localOptions.clipPlane, mesh.hasThinInstances)!;\r\n if (this._onEffectCreatedObservable) {\r\n onCreatedEffectParameters.effect = effect;\r\n onCreatedEffectParameters.subMesh = null;\r\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);\r\n }\r\n if (effect.isReady()) {\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n } else {\r\n effect.onCompileObservable.add(() => {\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Initializes the uniform buffer layout for the shader.\r\n */\r\n public buildUniformLayout(): void {\r\n // Order is important !\r\n const ubo = this._uniformBuffer;\r\n ubo.addUniform(\"vAlbedoInfos\", 2);\r\n ubo.addUniform(\"vAmbientInfos\", 4);\r\n ubo.addUniform(\"vOpacityInfos\", 2);\r\n ubo.addUniform(\"vEmissiveInfos\", 2);\r\n ubo.addUniform(\"vLightmapInfos\", 2);\r\n ubo.addUniform(\"vReflectivityInfos\", 3);\r\n ubo.addUniform(\"vMicroSurfaceSamplerInfos\", 2);\r\n ubo.addUniform(\"vReflectionInfos\", 2);\r\n ubo.addUniform(\"vReflectionFilteringInfo\", 2);\r\n ubo.addUniform(\"vReflectionPosition\", 3);\r\n ubo.addUniform(\"vReflectionSize\", 3);\r\n ubo.addUniform(\"vBumpInfos\", 3);\r\n ubo.addUniform(\"albedoMatrix\", 16);\r\n ubo.addUniform(\"ambientMatrix\", 16);\r\n ubo.addUniform(\"opacityMatrix\", 16);\r\n ubo.addUniform(\"emissiveMatrix\", 16);\r\n ubo.addUniform(\"lightmapMatrix\", 16);\r\n ubo.addUniform(\"reflectivityMatrix\", 16);\r\n ubo.addUniform(\"microSurfaceSamplerMatrix\", 16);\r\n ubo.addUniform(\"bumpMatrix\", 16);\r\n ubo.addUniform(\"vTangentSpaceParams\", 2);\r\n ubo.addUniform(\"reflectionMatrix\", 16);\r\n\r\n ubo.addUniform(\"vReflectionColor\", 3);\r\n ubo.addUniform(\"vAlbedoColor\", 4);\r\n ubo.addUniform(\"vLightingIntensity\", 4);\r\n\r\n ubo.addUniform(\"vReflectionMicrosurfaceInfos\", 3);\r\n ubo.addUniform(\"pointSize\", 1);\r\n ubo.addUniform(\"vReflectivityColor\", 4);\r\n ubo.addUniform(\"vEmissiveColor\", 3);\r\n ubo.addUniform(\"vAmbientColor\", 3);\r\n\r\n ubo.addUniform(\"vDebugMode\", 2);\r\n\r\n ubo.addUniform(\"vMetallicReflectanceFactors\", 4);\r\n ubo.addUniform(\"vMetallicReflectanceInfos\", 2);\r\n ubo.addUniform(\"metallicReflectanceMatrix\", 16);\r\n ubo.addUniform(\"vReflectanceInfos\", 2);\r\n ubo.addUniform(\"reflectanceMatrix\", 16);\r\n\r\n ubo.addUniform(\"vSphericalL00\", 3);\r\n ubo.addUniform(\"vSphericalL1_1\", 3);\r\n ubo.addUniform(\"vSphericalL10\", 3);\r\n ubo.addUniform(\"vSphericalL11\", 3);\r\n ubo.addUniform(\"vSphericalL2_2\", 3);\r\n ubo.addUniform(\"vSphericalL2_1\", 3);\r\n ubo.addUniform(\"vSphericalL20\", 3);\r\n ubo.addUniform(\"vSphericalL21\", 3);\r\n ubo.addUniform(\"vSphericalL22\", 3);\r\n\r\n ubo.addUniform(\"vSphericalX\", 3);\r\n ubo.addUniform(\"vSphericalY\", 3);\r\n ubo.addUniform(\"vSphericalZ\", 3);\r\n ubo.addUniform(\"vSphericalXX_ZZ\", 3);\r\n ubo.addUniform(\"vSphericalYY_ZZ\", 3);\r\n ubo.addUniform(\"vSphericalZZ\", 3);\r\n ubo.addUniform(\"vSphericalXY\", 3);\r\n ubo.addUniform(\"vSphericalYZ\", 3);\r\n ubo.addUniform(\"vSphericalZX\", 3);\r\n\r\n super.buildUniformLayout();\r\n }\r\n\r\n /**\r\n * Binds the submesh data.\r\n * @param world - The world matrix.\r\n * @param mesh - The BJS mesh.\r\n * @param subMesh - A submesh of the BJS mesh.\r\n */\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n\r\n const defines = subMesh.materialDefines;\r\n if (!defines) {\r\n return;\r\n }\r\n\r\n const effect = subMesh.effect;\r\n\r\n if (!effect) {\r\n return;\r\n }\r\n\r\n this._activeEffect = effect;\r\n\r\n // Matrices Mesh.\r\n mesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\r\n mesh.transferToEffect(world);\r\n\r\n const engine = scene.getEngine();\r\n\r\n // Binding unconditionally\r\n this._uniformBuffer.bindToEffect(effect, \"Material\");\r\n\r\n this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);\r\n\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventHardBindForSubMesh(this._eventInfo);\r\n\r\n // Normal Matrix\r\n if (defines.OBJECTSPACE_NORMALMAP) {\r\n world.toNormalMatrix(this._normalMatrix);\r\n this.bindOnlyNormalMatrix(this._normalMatrix);\r\n }\r\n\r\n const mustRebind = effect._forceRebindOnNextCall || this._mustRebind(scene, effect, mesh.visibility);\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect, this.prePassConfiguration);\r\n\r\n let reflectionTexture: Nullable = null;\r\n const ubo = this._uniformBuffer;\r\n if (mustRebind) {\r\n this.bindViewProjection(effect);\r\n reflectionTexture = this._getReflectionTexture();\r\n\r\n if (!ubo.useUbo || !this.isFrozen || !ubo.isSync || effect._forceRebindOnNextCall) {\r\n // Texture uniforms\r\n if (scene.texturesEnabled) {\r\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n ubo.updateFloat2(\"vAlbedoInfos\", this._albedoTexture.coordinatesIndex, this._albedoTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._albedoTexture, ubo, \"albedo\");\r\n }\r\n\r\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\r\n ubo.updateFloat4(\r\n \"vAmbientInfos\",\r\n this._ambientTexture.coordinatesIndex,\r\n this._ambientTexture.level,\r\n this._ambientTextureStrength,\r\n this._ambientTextureImpactOnAnalyticalLights\r\n );\r\n MaterialHelper.BindTextureMatrix(this._ambientTexture, ubo, \"ambient\");\r\n }\r\n\r\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\r\n ubo.updateFloat2(\"vOpacityInfos\", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._opacityTexture, ubo, \"opacity\");\r\n }\r\n\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n ubo.updateMatrix(\"reflectionMatrix\", reflectionTexture.getReflectionTextureMatrix());\r\n ubo.updateFloat2(\"vReflectionInfos\", reflectionTexture.level, 0);\r\n\r\n if ((reflectionTexture).boundingBoxSize) {\r\n const cubeTexture = reflectionTexture;\r\n\r\n ubo.updateVector3(\"vReflectionPosition\", cubeTexture.boundingBoxPosition);\r\n ubo.updateVector3(\"vReflectionSize\", cubeTexture.boundingBoxSize);\r\n }\r\n\r\n if (this.realTimeFiltering) {\r\n const width = reflectionTexture.getSize().width;\r\n ubo.updateFloat2(\"vReflectionFilteringInfo\", width, Scalar.Log2(width));\r\n }\r\n\r\n if (!defines.USEIRRADIANCEMAP) {\r\n const polynomials = reflectionTexture.sphericalPolynomial;\r\n if (defines.USESPHERICALFROMREFLECTIONMAP && polynomials) {\r\n if (defines.SPHERICAL_HARMONICS) {\r\n const preScaledHarmonics = polynomials.preScaledHarmonics;\r\n ubo.updateVector3(\"vSphericalL00\", preScaledHarmonics.l00);\r\n ubo.updateVector3(\"vSphericalL1_1\", preScaledHarmonics.l1_1);\r\n ubo.updateVector3(\"vSphericalL10\", preScaledHarmonics.l10);\r\n ubo.updateVector3(\"vSphericalL11\", preScaledHarmonics.l11);\r\n ubo.updateVector3(\"vSphericalL2_2\", preScaledHarmonics.l2_2);\r\n ubo.updateVector3(\"vSphericalL2_1\", preScaledHarmonics.l2_1);\r\n ubo.updateVector3(\"vSphericalL20\", preScaledHarmonics.l20);\r\n ubo.updateVector3(\"vSphericalL21\", preScaledHarmonics.l21);\r\n ubo.updateVector3(\"vSphericalL22\", preScaledHarmonics.l22);\r\n } else {\r\n ubo.updateFloat3(\"vSphericalX\", polynomials.x.x, polynomials.x.y, polynomials.x.z);\r\n ubo.updateFloat3(\"vSphericalY\", polynomials.y.x, polynomials.y.y, polynomials.y.z);\r\n ubo.updateFloat3(\"vSphericalZ\", polynomials.z.x, polynomials.z.y, polynomials.z.z);\r\n ubo.updateFloat3(\r\n \"vSphericalXX_ZZ\",\r\n polynomials.xx.x - polynomials.zz.x,\r\n polynomials.xx.y - polynomials.zz.y,\r\n polynomials.xx.z - polynomials.zz.z\r\n );\r\n ubo.updateFloat3(\r\n \"vSphericalYY_ZZ\",\r\n polynomials.yy.x - polynomials.zz.x,\r\n polynomials.yy.y - polynomials.zz.y,\r\n polynomials.yy.z - polynomials.zz.z\r\n );\r\n ubo.updateFloat3(\"vSphericalZZ\", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);\r\n ubo.updateFloat3(\"vSphericalXY\", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);\r\n ubo.updateFloat3(\"vSphericalYZ\", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);\r\n ubo.updateFloat3(\"vSphericalZX\", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);\r\n }\r\n }\r\n }\r\n\r\n ubo.updateFloat3(\r\n \"vReflectionMicrosurfaceInfos\",\r\n reflectionTexture.getSize().width,\r\n reflectionTexture.lodGenerationScale,\r\n reflectionTexture.lodGenerationOffset\r\n );\r\n }\r\n\r\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\r\n ubo.updateFloat2(\"vEmissiveInfos\", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._emissiveTexture, ubo, \"emissive\");\r\n }\r\n\r\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\r\n ubo.updateFloat2(\"vLightmapInfos\", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._lightmapTexture, ubo, \"lightmap\");\r\n }\r\n\r\n if (MaterialFlags.SpecularTextureEnabled) {\r\n if (this._metallicTexture) {\r\n ubo.updateFloat3(\"vReflectivityInfos\", this._metallicTexture.coordinatesIndex, this._metallicTexture.level, this._ambientTextureStrength);\r\n MaterialHelper.BindTextureMatrix(this._metallicTexture, ubo, \"reflectivity\");\r\n } else if (this._reflectivityTexture) {\r\n ubo.updateFloat3(\"vReflectivityInfos\", this._reflectivityTexture.coordinatesIndex, this._reflectivityTexture.level, 1.0);\r\n MaterialHelper.BindTextureMatrix(this._reflectivityTexture, ubo, \"reflectivity\");\r\n }\r\n\r\n if (this._metallicReflectanceTexture) {\r\n ubo.updateFloat2(\"vMetallicReflectanceInfos\", this._metallicReflectanceTexture.coordinatesIndex, this._metallicReflectanceTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._metallicReflectanceTexture, ubo, \"metallicReflectance\");\r\n }\r\n\r\n if (this._reflectanceTexture && defines.REFLECTANCE) {\r\n ubo.updateFloat2(\"vReflectanceInfos\", this._reflectanceTexture.coordinatesIndex, this._reflectanceTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._reflectanceTexture, ubo, \"reflectance\");\r\n }\r\n\r\n if (this._microSurfaceTexture) {\r\n ubo.updateFloat2(\"vMicroSurfaceSamplerInfos\", this._microSurfaceTexture.coordinatesIndex, this._microSurfaceTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._microSurfaceTexture, ubo, \"microSurfaceSampler\");\r\n }\r\n }\r\n\r\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\r\n ubo.updateFloat3(\"vBumpInfos\", this._bumpTexture.coordinatesIndex, this._bumpTexture.level, this._parallaxScaleBias);\r\n MaterialHelper.BindTextureMatrix(this._bumpTexture, ubo, \"bump\");\r\n\r\n if (scene._mirroredCameraPosition) {\r\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);\r\n } else {\r\n ubo.updateFloat2(\"vTangentSpaceParams\", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);\r\n }\r\n }\r\n }\r\n\r\n // Point size\r\n if (this.pointsCloud) {\r\n ubo.updateFloat(\"pointSize\", this.pointSize);\r\n }\r\n\r\n // Colors\r\n if (defines.METALLICWORKFLOW) {\r\n TmpColors.Color3[0].r = this._metallic === undefined || this._metallic === null ? 1 : this._metallic;\r\n TmpColors.Color3[0].g = this._roughness === undefined || this._roughness === null ? 1 : this._roughness;\r\n ubo.updateColor4(\"vReflectivityColor\", TmpColors.Color3[0], 1);\r\n\r\n const ior = this.subSurface?._indexOfRefraction ?? 1.5;\r\n const outsideIOR = 1; // consider air as clear coat and other layers would remap in the shader.\r\n\r\n // We are here deriving our default reflectance from a common value for none metallic surface.\r\n // Based of the schlick fresnel approximation model\r\n // for dielectrics.\r\n const f0 = Math.pow((ior - outsideIOR) / (ior + outsideIOR), 2);\r\n\r\n // Tweak the default F0 and F90 based on our given setup\r\n this._metallicReflectanceColor.scaleToRef(f0 * this._metallicF0Factor, TmpColors.Color3[0]);\r\n const metallicF90 = this._metallicF0Factor;\r\n\r\n ubo.updateColor4(\"vMetallicReflectanceFactors\", TmpColors.Color3[0], metallicF90);\r\n } else {\r\n ubo.updateColor4(\"vReflectivityColor\", this._reflectivityColor, this._microSurface);\r\n }\r\n\r\n ubo.updateColor3(\"vEmissiveColor\", MaterialFlags.EmissiveTextureEnabled ? this._emissiveColor : Color3.BlackReadOnly);\r\n ubo.updateColor3(\"vReflectionColor\", this._reflectionColor);\r\n if (!defines.SS_REFRACTION && this.subSurface?._linkRefractionWithTransparency) {\r\n ubo.updateColor4(\"vAlbedoColor\", this._albedoColor, 1);\r\n } else {\r\n ubo.updateColor4(\"vAlbedoColor\", this._albedoColor, this.alpha);\r\n }\r\n\r\n // Misc\r\n this._lightingInfos.x = this._directIntensity;\r\n this._lightingInfos.y = this._emissiveIntensity;\r\n this._lightingInfos.z = this._environmentIntensity * scene.environmentIntensity;\r\n this._lightingInfos.w = this._specularIntensity;\r\n\r\n ubo.updateVector4(\"vLightingIntensity\", this._lightingInfos);\r\n\r\n // Colors\r\n scene.ambientColor.multiplyToRef(this._ambientColor, this._globalAmbientColor);\r\n\r\n ubo.updateColor3(\"vAmbientColor\", this._globalAmbientColor);\r\n\r\n ubo.updateFloat2(\"vDebugMode\", this.debugLimit, this.debugFactor);\r\n }\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n ubo.setTexture(\"albedoSampler\", this._albedoTexture);\r\n }\r\n\r\n if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {\r\n ubo.setTexture(\"ambientSampler\", this._ambientTexture);\r\n }\r\n\r\n if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {\r\n ubo.setTexture(\"opacitySampler\", this._opacityTexture);\r\n }\r\n\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n if (defines.LODBASEDMICROSFURACE) {\r\n ubo.setTexture(\"reflectionSampler\", reflectionTexture);\r\n } else {\r\n ubo.setTexture(\"reflectionSampler\", reflectionTexture._lodTextureMid || reflectionTexture);\r\n ubo.setTexture(\"reflectionSamplerLow\", reflectionTexture._lodTextureLow || reflectionTexture);\r\n ubo.setTexture(\"reflectionSamplerHigh\", reflectionTexture._lodTextureHigh || reflectionTexture);\r\n }\r\n\r\n if (defines.USEIRRADIANCEMAP) {\r\n ubo.setTexture(\"irradianceSampler\", reflectionTexture.irradianceTexture);\r\n }\r\n }\r\n\r\n if (defines.ENVIRONMENTBRDF) {\r\n ubo.setTexture(\"environmentBrdfSampler\", this._environmentBRDFTexture);\r\n }\r\n\r\n if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {\r\n ubo.setTexture(\"emissiveSampler\", this._emissiveTexture);\r\n }\r\n\r\n if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {\r\n ubo.setTexture(\"lightmapSampler\", this._lightmapTexture);\r\n }\r\n\r\n if (MaterialFlags.SpecularTextureEnabled) {\r\n if (this._metallicTexture) {\r\n ubo.setTexture(\"reflectivitySampler\", this._metallicTexture);\r\n } else if (this._reflectivityTexture) {\r\n ubo.setTexture(\"reflectivitySampler\", this._reflectivityTexture);\r\n }\r\n\r\n if (this._metallicReflectanceTexture) {\r\n ubo.setTexture(\"metallicReflectanceSampler\", this._metallicReflectanceTexture);\r\n }\r\n\r\n if (this._reflectanceTexture && defines.REFLECTANCE) {\r\n ubo.setTexture(\"reflectanceSampler\", this._reflectanceTexture);\r\n }\r\n\r\n if (this._microSurfaceTexture) {\r\n ubo.setTexture(\"microSurfaceSampler\", this._microSurfaceTexture);\r\n }\r\n }\r\n\r\n if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {\r\n ubo.setTexture(\"bumpSampler\", this._bumpTexture);\r\n }\r\n }\r\n\r\n // OIT with depth peeling\r\n if (this.getScene().useOrderIndependentTransparency && this.needAlphaBlendingForMesh(mesh)) {\r\n this.getScene().depthPeelingRenderer!.bind(effect);\r\n }\r\n\r\n this._eventInfo.subMesh = subMesh;\r\n this._callbackPluginEventBindForSubMesh(this._eventInfo);\r\n\r\n // Clip plane\r\n bindClipPlane(this._activeEffect, this, scene);\r\n\r\n this.bindEyePosition(effect);\r\n } else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {\r\n this._needToBindSceneUbo = true;\r\n }\r\n\r\n if (mustRebind || !this.isFrozen) {\r\n // Lights\r\n if (scene.lightsEnabled && !this._disableLighting) {\r\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);\r\n }\r\n\r\n // View\r\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || reflectionTexture || mesh.receiveShadows || defines.PREPASS) {\r\n this.bindView(effect);\r\n }\r\n\r\n // Fog\r\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect, true);\r\n\r\n // Morph targets\r\n if (defines.NUM_MORPH_INFLUENCERS) {\r\n MaterialHelper.BindMorphTargetParameters(mesh, this._activeEffect);\r\n }\r\n\r\n if (defines.BAKED_VERTEX_ANIMATION_TEXTURE) {\r\n mesh.bakedVertexAnimationManager?.bind(effect, defines.INSTANCES);\r\n }\r\n\r\n // image processing\r\n this._imageProcessingConfiguration!.bind(this._activeEffect);\r\n\r\n // Log. depth\r\n MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);\r\n }\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n\r\n ubo.update();\r\n }\r\n\r\n /**\r\n * Returns the animatable textures.\r\n * If material have animatable metallic texture, then reflectivity texture will not be returned, even if it has animations.\r\n * @returns - Array of animatable textures.\r\n */\r\n public getAnimatables(): IAnimatable[] {\r\n const results = super.getAnimatables();\r\n\r\n if (this._albedoTexture && this._albedoTexture.animations && this._albedoTexture.animations.length > 0) {\r\n results.push(this._albedoTexture);\r\n }\r\n\r\n if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {\r\n results.push(this._ambientTexture);\r\n }\r\n\r\n if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {\r\n results.push(this._opacityTexture);\r\n }\r\n\r\n if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {\r\n results.push(this._reflectionTexture);\r\n }\r\n\r\n if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {\r\n results.push(this._emissiveTexture);\r\n }\r\n\r\n if (this._metallicTexture && this._metallicTexture.animations && this._metallicTexture.animations.length > 0) {\r\n results.push(this._metallicTexture);\r\n } else if (this._reflectivityTexture && this._reflectivityTexture.animations && this._reflectivityTexture.animations.length > 0) {\r\n results.push(this._reflectivityTexture);\r\n }\r\n\r\n if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {\r\n results.push(this._bumpTexture);\r\n }\r\n\r\n if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {\r\n results.push(this._lightmapTexture);\r\n }\r\n\r\n if (this._metallicReflectanceTexture && this._metallicReflectanceTexture.animations && this._metallicReflectanceTexture.animations.length > 0) {\r\n results.push(this._metallicReflectanceTexture);\r\n }\r\n\r\n if (this._reflectanceTexture && this._reflectanceTexture.animations && this._reflectanceTexture.animations.length > 0) {\r\n results.push(this._reflectanceTexture);\r\n }\r\n\r\n if (this._microSurfaceTexture && this._microSurfaceTexture.animations && this._microSurfaceTexture.animations.length > 0) {\r\n results.push(this._microSurfaceTexture);\r\n }\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Returns the texture used for reflections.\r\n * @returns - Reflection texture if present. Otherwise, returns the environment texture.\r\n */\r\n private _getReflectionTexture(): Nullable {\r\n if (this._reflectionTexture) {\r\n return this._reflectionTexture;\r\n }\r\n\r\n return this.getScene().environmentTexture;\r\n }\r\n\r\n /**\r\n * Returns an array of the actively used textures.\r\n * @returns - Array of BaseTextures\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n const activeTextures = super.getActiveTextures();\r\n\r\n if (this._albedoTexture) {\r\n activeTextures.push(this._albedoTexture);\r\n }\r\n\r\n if (this._ambientTexture) {\r\n activeTextures.push(this._ambientTexture);\r\n }\r\n\r\n if (this._opacityTexture) {\r\n activeTextures.push(this._opacityTexture);\r\n }\r\n\r\n if (this._reflectionTexture) {\r\n activeTextures.push(this._reflectionTexture);\r\n }\r\n\r\n if (this._emissiveTexture) {\r\n activeTextures.push(this._emissiveTexture);\r\n }\r\n\r\n if (this._reflectivityTexture) {\r\n activeTextures.push(this._reflectivityTexture);\r\n }\r\n\r\n if (this._metallicTexture) {\r\n activeTextures.push(this._metallicTexture);\r\n }\r\n\r\n if (this._metallicReflectanceTexture) {\r\n activeTextures.push(this._metallicReflectanceTexture);\r\n }\r\n\r\n if (this._reflectanceTexture) {\r\n activeTextures.push(this._reflectanceTexture);\r\n }\r\n\r\n if (this._microSurfaceTexture) {\r\n activeTextures.push(this._microSurfaceTexture);\r\n }\r\n\r\n if (this._bumpTexture) {\r\n activeTextures.push(this._bumpTexture);\r\n }\r\n\r\n if (this._lightmapTexture) {\r\n activeTextures.push(this._lightmapTexture);\r\n }\r\n\r\n return activeTextures;\r\n }\r\n\r\n /**\r\n * Checks to see if a texture is used in the material.\r\n * @param texture - Base texture to use.\r\n * @returns - Boolean specifying if a texture is used in the material.\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 if (this._albedoTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._ambientTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._opacityTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._reflectionTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._emissiveTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._reflectivityTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._metallicTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._metallicReflectanceTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._reflectanceTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._microSurfaceTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._bumpTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._lightmapTexture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Sets the required values to the prepass renderer.\r\n * It can't be sets when subsurface scattering of this material is disabled.\r\n * When scene have ability to enable subsurface prepass effect, it will enable.\r\n */\r\n public setPrePassRenderer(): boolean {\r\n if (!this.subSurface?.isScatteringEnabled) {\r\n return false;\r\n }\r\n\r\n const subSurfaceConfiguration = this.getScene().enableSubSurfaceForPrePass();\r\n if (subSurfaceConfiguration) {\r\n subSurfaceConfiguration.enabled = true;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Disposes the resources of the material.\r\n * @param forceDisposeEffect - Forces the disposal of effects.\r\n * @param forceDisposeTextures - Forces the disposal of all textures.\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean): void {\r\n if (forceDisposeTextures) {\r\n if (this._environmentBRDFTexture && this.getScene().environmentBRDFTexture !== this._environmentBRDFTexture) {\r\n this._environmentBRDFTexture.dispose();\r\n }\r\n\r\n this._albedoTexture?.dispose();\r\n this._ambientTexture?.dispose();\r\n this._opacityTexture?.dispose();\r\n this._reflectionTexture?.dispose();\r\n this._emissiveTexture?.dispose();\r\n this._metallicTexture?.dispose();\r\n this._reflectivityTexture?.dispose();\r\n this._bumpTexture?.dispose();\r\n this._lightmapTexture?.dispose();\r\n this._metallicReflectanceTexture?.dispose();\r\n this._reflectanceTexture?.dispose();\r\n this._microSurfaceTexture?.dispose();\r\n }\r\n\r\n this._renderTargets.dispose();\r\n\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n super.dispose(forceDisposeEffect, forceDisposeTextures);\r\n }\r\n}\r\n","import { serialize, SerializationHelper, serializeAsColor3, expandToProperty, serializeAsTexture } from \"../../Misc/decorators\";\r\nimport { GetEnvironmentBRDFTexture } from \"../../Misc/brdfTextureTools\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport type { ImageProcessingConfiguration } from \"../../Materials/imageProcessingConfiguration\";\r\nimport type { ColorCurves } from \"../../Materials/colorCurves\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { PBRBaseMaterial } from \"./pbrBaseMaterial\";\r\nimport { RegisterClass } from \"../../Misc/typeStore\";\r\nimport { Material } from \"../material\";\r\n\r\n/**\r\n * The Physically based material of BJS.\r\n *\r\n * This offers the main features of a standard PBR material.\r\n * For more information, please refer to the documentation :\r\n * https://doc.babylonjs.com/features/featuresDeepDive/materials/using/introToPBR\r\n */\r\nexport class PBRMaterial extends PBRBaseMaterial {\r\n /**\r\n * PBRMaterialTransparencyMode: No transparency mode, Alpha channel is not use.\r\n */\r\n public static readonly PBRMATERIAL_OPAQUE = PBRBaseMaterial.PBRMATERIAL_OPAQUE;\r\n\r\n /**\r\n * PBRMaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.\r\n */\r\n public static readonly PBRMATERIAL_ALPHATEST = PBRBaseMaterial.PBRMATERIAL_ALPHATEST;\r\n\r\n /**\r\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\r\n */\r\n public static readonly PBRMATERIAL_ALPHABLEND = PBRBaseMaterial.PBRMATERIAL_ALPHABLEND;\r\n\r\n /**\r\n * PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.\r\n * They are also discarded below the alpha cutoff threshold to improve performances.\r\n */\r\n public static readonly PBRMATERIAL_ALPHATESTANDBLEND = PBRBaseMaterial.PBRMATERIAL_ALPHATESTANDBLEND;\r\n\r\n /**\r\n * Defines the default value of how much AO map is occluding the analytical lights\r\n * (point spot...).\r\n */\r\n public static DEFAULT_AO_ON_ANALYTICAL_LIGHTS = PBRBaseMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;\r\n\r\n /**\r\n * Intensity of the direct lights e.g. the four lights available in your scene.\r\n * This impacts both the direct diffuse and specular highlights.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public directIntensity: number = 1.0;\r\n\r\n /**\r\n * Intensity of the emissive part of the material.\r\n * This helps controlling the emissive effect without modifying the emissive color.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public emissiveIntensity: number = 1.0;\r\n\r\n /**\r\n * Intensity of the environment e.g. how much the environment will light the object\r\n * either through harmonics for rough material or through the reflection for shiny ones.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public environmentIntensity: number = 1.0;\r\n\r\n /**\r\n * This is a special control allowing the reduction of the specular highlights coming from the\r\n * four lights of the scene. Those highlights may not be needed in full environment lighting.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public specularIntensity: number = 1.0;\r\n\r\n /**\r\n * Debug Control allowing disabling the bump map on this material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public disableBumpMap: boolean = false;\r\n\r\n /**\r\n * AKA Diffuse Texture in standard nomenclature.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public albedoTexture: Nullable;\r\n\r\n /**\r\n * AKA Occlusion Texture in other nomenclature.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public ambientTexture: Nullable;\r\n\r\n /**\r\n * AKA Occlusion Texture Intensity in other nomenclature.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public ambientTextureStrength: number = 1.0;\r\n\r\n /**\r\n * Defines how much the AO map is occluding the analytical lights (point spot...).\r\n * 1 means it completely occludes it\r\n * 0 mean it has no impact\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public ambientTextureImpactOnAnalyticalLights: number = PBRMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;\r\n\r\n /**\r\n * Stores the alpha values in a texture. Use luminance if texture.getAlphaFromRGB is true.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public opacityTexture: Nullable;\r\n\r\n /**\r\n * Stores the reflection values in a texture.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionTexture: Nullable;\r\n\r\n /**\r\n * Stores the emissive values in a texture.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public emissiveTexture: Nullable;\r\n\r\n /**\r\n * AKA Specular texture in other nomenclature.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectivityTexture: Nullable;\r\n\r\n /**\r\n * Used to switch from specular/glossiness to metallic/roughness workflow.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public metallicTexture: Nullable;\r\n\r\n /**\r\n * Specifies the metallic scalar of the metallic/roughness workflow.\r\n * Can also be used to scale the metalness values of the metallic texture.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public metallic: Nullable;\r\n\r\n /**\r\n * Specifies the roughness scalar of the metallic/roughness workflow.\r\n * Can also be used to scale the roughness values of the metallic texture.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public roughness: Nullable;\r\n\r\n /**\r\n * In metallic workflow, specifies an F0 factor to help configuring the material F0.\r\n * By default the indexOfrefraction is used to compute F0;\r\n *\r\n * This is used as a factor against the default reflectance at normal incidence to tweak it.\r\n *\r\n * F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor;\r\n * F90 = metallicReflectanceColor;\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public metallicF0Factor = 1;\r\n\r\n /**\r\n * In metallic workflow, specifies an F0 color.\r\n * By default the F90 is always 1;\r\n *\r\n * Please note that this factor is also used as a factor against the default reflectance at normal incidence.\r\n *\r\n * F0 = defaultF0_from_IOR * metallicF0Factor * metallicReflectanceColor\r\n * F90 = metallicF0Factor;\r\n */\r\n @serializeAsColor3()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public metallicReflectanceColor = Color3.White();\r\n\r\n /**\r\n * Specifies that only the A channel from metallicReflectanceTexture should be used.\r\n * If false, both RGB and A channels will be used\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useOnlyMetallicFromMetallicReflectanceTexture = false;\r\n\r\n /**\r\n * Defines to store metallicReflectanceColor in RGB and metallicF0Factor in A\r\n * This is multiplied against the scalar values defined in the material.\r\n * If useOnlyMetallicFromMetallicReflectanceTexture is true, don't use the RGB channels, only A\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public metallicReflectanceTexture: Nullable;\r\n\r\n /**\r\n * Defines to store reflectanceColor in RGB\r\n * This is multiplied against the scalar values defined in the material.\r\n * If both reflectanceTexture and metallicReflectanceTexture textures are provided and useOnlyMetallicFromMetallicReflectanceTexture\r\n * is false, metallicReflectanceTexture takes priority and reflectanceTexture is not used\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectanceTexture: Nullable;\r\n\r\n /**\r\n * Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.\r\n * Gray Scale represents roughness in metallic mode and glossiness in specular mode.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public microSurfaceTexture: Nullable;\r\n\r\n /**\r\n * Stores surface normal data used to displace a mesh in a texture.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public bumpTexture: Nullable;\r\n\r\n /**\r\n * Stores the pre-calculated light information of a mesh in a texture.\r\n */\r\n @serializeAsTexture()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\", null)\r\n public lightmapTexture: Nullable;\r\n\r\n /**\r\n * Stores the refracted light information in a texture.\r\n */\r\n public get refractionTexture(): Nullable {\r\n return this.subSurface.refractionTexture;\r\n }\r\n public set refractionTexture(value: Nullable) {\r\n this.subSurface.refractionTexture = value;\r\n if (value) {\r\n this.subSurface.isRefractionEnabled = true;\r\n } else if (!this.subSurface.linkRefractionWithTransparency) {\r\n this.subSurface.isRefractionEnabled = false;\r\n }\r\n }\r\n\r\n /**\r\n * The color of a material in ambient lighting.\r\n */\r\n @serializeAsColor3(\"ambient\")\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public ambientColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * AKA Diffuse Color in other nomenclature.\r\n */\r\n @serializeAsColor3(\"albedo\")\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public albedoColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * AKA Specular Color in other nomenclature.\r\n */\r\n @serializeAsColor3(\"reflectivity\")\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectivityColor = new Color3(1, 1, 1);\r\n\r\n /**\r\n * The color reflected from the material.\r\n */\r\n @serializeAsColor3(\"reflection\")\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionColor = new Color3(1.0, 1.0, 1.0);\r\n\r\n /**\r\n * The color emitted from the material.\r\n */\r\n @serializeAsColor3(\"emissive\")\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public emissiveColor = new Color3(0, 0, 0);\r\n\r\n /**\r\n * AKA Glossiness in other nomenclature.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public microSurface = 1.0;\r\n\r\n /**\r\n * Index of refraction of the material base layer.\r\n * https://en.wikipedia.org/wiki/List_of_refractive_indices\r\n *\r\n * This does not only impact refraction but also the Base F0 of Dielectric Materials.\r\n *\r\n * From dielectric fresnel rules: F0 = square((iorT - iorI) / (iorT + iorI))\r\n */\r\n public get indexOfRefraction(): number {\r\n return this.subSurface.indexOfRefraction;\r\n }\r\n public set indexOfRefraction(value: number) {\r\n this.subSurface.indexOfRefraction = value;\r\n }\r\n\r\n /**\r\n * Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.\r\n */\r\n public get invertRefractionY(): boolean {\r\n return this.subSurface.invertRefractionY;\r\n }\r\n public set invertRefractionY(value: boolean) {\r\n this.subSurface.invertRefractionY = value;\r\n }\r\n\r\n /**\r\n * This parameters will make the material used its opacity to control how much it is refracting against not.\r\n * Materials half opaque for instance using refraction could benefit from this control.\r\n */\r\n public get linkRefractionWithTransparency(): boolean {\r\n return this.subSurface.linkRefractionWithTransparency;\r\n }\r\n public set linkRefractionWithTransparency(value: boolean) {\r\n this.subSurface.linkRefractionWithTransparency = value;\r\n if (value) {\r\n this.subSurface.isRefractionEnabled = true;\r\n }\r\n }\r\n\r\n /**\r\n * If true, the light map contains occlusion information instead of lighting info.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useLightmapAsShadowmap = false;\r\n\r\n /**\r\n * Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public useAlphaFromAlbedoTexture = false;\r\n\r\n /**\r\n * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public forceAlphaTest = false;\r\n\r\n /**\r\n * Defines the alpha limits in alpha test mode.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesAndMiscDirty\")\r\n public alphaCutOff = 0.4;\r\n\r\n /**\r\n * Specifies that the material will keep the specular highlights over a transparent surface (only the most luminous ones).\r\n * A car glass is a good example of that. When sun reflects on it you can not see what is behind.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useSpecularOverAlpha = true;\r\n\r\n /**\r\n * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useMicroSurfaceFromReflectivityMapAlpha = false;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the roughness information in its alpha channel.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRoughnessFromMetallicTextureAlpha = true;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the roughness information in its green channel.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRoughnessFromMetallicTextureGreen = false;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the metallness information in its blue channel.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useMetallnessFromMetallicTextureBlue = false;\r\n\r\n /**\r\n * Specifies if the metallic texture contains the ambient occlusion information in its red channel.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useAmbientOcclusionFromMetallicTextureRed = false;\r\n\r\n /**\r\n * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useAmbientInGrayScale = false;\r\n\r\n /**\r\n * In case the reflectivity map does not contain the microsurface information in its alpha channel,\r\n * The material will try to infer what glossiness each pixel should be.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useAutoMicroSurfaceFromReflectivityMap = false;\r\n\r\n /**\r\n * BJS is using an hardcoded light falloff based on a manually sets up range.\r\n * In PBR, one way to represents the falloff is to use the inverse squared root algorithm.\r\n * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.\r\n */\r\n @serialize()\r\n public get usePhysicalLightFalloff(): boolean {\r\n return this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL;\r\n }\r\n\r\n /**\r\n * BJS is using an hardcoded light falloff based on a manually sets up range.\r\n * In PBR, one way to represents the falloff is to use the inverse squared root algorithm.\r\n * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.\r\n */\r\n public set usePhysicalLightFalloff(value: boolean) {\r\n if (value !== this.usePhysicalLightFalloff) {\r\n // Ensure the effect will be rebuilt.\r\n this._markAllSubMeshesAsTexturesDirty();\r\n\r\n if (value) {\r\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL;\r\n } else {\r\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_STANDARD;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * In order to support the falloff compatibility with gltf, a special mode has been added\r\n * to reproduce the gltf light falloff.\r\n */\r\n @serialize()\r\n public get useGLTFLightFalloff(): boolean {\r\n return this._lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_GLTF;\r\n }\r\n\r\n /**\r\n * In order to support the falloff compatibility with gltf, a special mode has been added\r\n * to reproduce the gltf light falloff.\r\n */\r\n public set useGLTFLightFalloff(value: boolean) {\r\n if (value !== this.useGLTFLightFalloff) {\r\n // Ensure the effect will be rebuilt.\r\n this._markAllSubMeshesAsTexturesDirty();\r\n\r\n if (value) {\r\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_GLTF;\r\n } else {\r\n this._lightFalloff = PBRBaseMaterial.LIGHTFALLOFF_STANDARD;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most luminous ones).\r\n * A car glass is a good example of that. When the street lights reflects on it you can not see what is behind.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRadianceOverAlpha = true;\r\n\r\n /**\r\n * Allows using an object space normal map (instead of tangent space).\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useObjectSpaceNormalMap = false;\r\n\r\n /**\r\n * Allows using the bump map in parallax mode.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useParallax = false;\r\n\r\n /**\r\n * Allows using the bump map in parallax occlusion mode.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useParallaxOcclusion = false;\r\n\r\n /**\r\n * Controls the scale bias of the parallax mode.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public parallaxScaleBias = 0.05;\r\n\r\n /**\r\n * If sets to true, disables all the lights affecting the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public disableLighting = false;\r\n\r\n /**\r\n * Force the shader to compute irradiance in the fragment shader in order to take bump in account.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public forceIrradianceInFragment = false;\r\n\r\n /**\r\n * Number of Simultaneous lights allowed on the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public maxSimultaneousLights = 4;\r\n\r\n /**\r\n * If sets to true, x component of normal map value will invert (x = 1.0 - x).\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public invertNormalMapX = false;\r\n\r\n /**\r\n * If sets to true, y component of normal map value will invert (y = 1.0 - y).\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public invertNormalMapY = false;\r\n\r\n /**\r\n * If sets to true and backfaceCulling is false, normals will be flipped on the backside.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public twoSidedLighting = false;\r\n\r\n /**\r\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\r\n * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useAlphaFresnel = false;\r\n\r\n /**\r\n * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.\r\n * And/Or occlude the blended part. (alpha stays linear to compute the fresnel)\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useLinearAlphaFresnel = false;\r\n\r\n /**\r\n * Let user defines the brdf lookup texture used for IBL.\r\n * A default 8bit version is embedded but you could point at :\r\n * * Default texture: https://assets.babylonjs.com/environments/correlatedMSBRDF_RGBD.png\r\n * * Default 16bit pixel depth texture: https://assets.babylonjs.com/environments/correlatedMSBRDF.dds\r\n * * LEGACY Default None correlated https://assets.babylonjs.com/environments/uncorrelatedBRDF_RGBD.png\r\n * * LEGACY Default None correlated 16bit pixel depth https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public environmentBRDFTexture: Nullable = null;\r\n\r\n /**\r\n * Force normal to face away from face.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public forceNormalForward = false;\r\n\r\n /**\r\n * Enables specular anti aliasing in the PBR shader.\r\n * It will both interacts on the Geometry for analytical and IBL lighting.\r\n * It also prefilter the roughness map based on the bump values.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public enableSpecularAntiAliasing = false;\r\n\r\n /**\r\n * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal\r\n * makes the reflect vector face the model (under horizon).\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useHorizonOcclusion = true;\r\n\r\n /**\r\n * This parameters will enable/disable radiance occlusion by preventing the radiance to lit\r\n * too much the area relying on ambient texture to define their ambient occlusion.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRadianceOcclusion = true;\r\n\r\n /**\r\n * If set to true, no lighting calculations will be applied.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public unlit = false;\r\n\r\n /**\r\n * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsMiscDirty\")\r\n public applyDecalMapAfterDetailMap = false;\r\n\r\n /**\r\n * Gets the image processing configuration used either in this material.\r\n */\r\n public get imageProcessingConfiguration(): ImageProcessingConfiguration {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n /**\r\n * Sets the Default image processing configuration used either in the this material.\r\n *\r\n * If sets to null, the scene one is in use.\r\n */\r\n public set imageProcessingConfiguration(value: ImageProcessingConfiguration) {\r\n this._attachImageProcessingConfiguration(value);\r\n\r\n // Ensure the effect will be rebuilt.\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /**\r\n * Gets whether the color curves effect is enabled.\r\n */\r\n public get cameraColorCurvesEnabled(): boolean {\r\n return this.imageProcessingConfiguration.colorCurvesEnabled;\r\n }\r\n /**\r\n * Sets whether the color curves effect is enabled.\r\n */\r\n public set cameraColorCurvesEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public get cameraColorGradingEnabled(): boolean {\r\n return this.imageProcessingConfiguration.colorGradingEnabled;\r\n }\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public set cameraColorGradingEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.colorGradingEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets whether tonemapping is enabled or not.\r\n */\r\n public get cameraToneMappingEnabled(): boolean {\r\n return this._imageProcessingConfiguration.toneMappingEnabled;\r\n }\r\n /**\r\n * Sets whether tonemapping is enabled or not\r\n */\r\n public set cameraToneMappingEnabled(value: boolean) {\r\n this._imageProcessingConfiguration.toneMappingEnabled = value;\r\n }\r\n\r\n /**\r\n * The camera exposure used on this material.\r\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\r\n * This corresponds to a photographic exposure.\r\n */\r\n public get cameraExposure(): number {\r\n return this._imageProcessingConfiguration.exposure;\r\n }\r\n /**\r\n * The camera exposure used on this material.\r\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\r\n * This corresponds to a photographic exposure.\r\n */\r\n public set cameraExposure(value: number) {\r\n this._imageProcessingConfiguration.exposure = value;\r\n }\r\n\r\n /**\r\n * Gets The camera contrast used on this material.\r\n */\r\n public get cameraContrast(): number {\r\n return this._imageProcessingConfiguration.contrast;\r\n }\r\n\r\n /**\r\n * Sets The camera contrast used on this material.\r\n */\r\n public set cameraContrast(value: number) {\r\n this._imageProcessingConfiguration.contrast = value;\r\n }\r\n\r\n /**\r\n * Gets the Color Grading 2D Lookup Texture.\r\n */\r\n public get cameraColorGradingTexture(): Nullable {\r\n return this._imageProcessingConfiguration.colorGradingTexture;\r\n }\r\n /**\r\n * Sets the Color Grading 2D Lookup Texture.\r\n */\r\n public set cameraColorGradingTexture(value: Nullable) {\r\n this._imageProcessingConfiguration.colorGradingTexture = value;\r\n }\r\n\r\n /**\r\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\n public get cameraColorCurves(): Nullable {\r\n return this._imageProcessingConfiguration.colorCurves;\r\n }\r\n /**\r\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\n public set cameraColorCurves(value: Nullable) {\r\n this._imageProcessingConfiguration.colorCurves = value;\r\n }\r\n\r\n /**\r\n * Instantiates a new PBRMaterial instance.\r\n *\r\n * @param name The material name\r\n * @param scene The scene the material will be use in.\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n\r\n this._environmentBRDFTexture = GetEnvironmentBRDFTexture(this.getScene());\r\n }\r\n\r\n /**\r\n * Returns the name of this material class.\r\n */\r\n public getClassName(): string {\r\n return \"PBRMaterial\";\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the current material.\r\n * @param name - name to use for the new material.\r\n * @param cloneTexturesOnlyOnce - if a texture is used in more than one channel (e.g diffuse and opacity), only clone it once and reuse it on the other channels. Default false.\r\n * @param rootUrl defines the root URL to use to load textures\r\n */\r\n public clone(name: string, cloneTexturesOnlyOnce: boolean = true, rootUrl = \"\"): PBRMaterial {\r\n const clone = SerializationHelper.Clone(() => new PBRMaterial(name, this.getScene()), this, { cloneTexturesOnlyOnce });\r\n\r\n clone.id = name;\r\n clone.name = name;\r\n\r\n this.stencil.copyTo(clone.stencil);\r\n\r\n this._clonePlugins(clone, rootUrl);\r\n\r\n return clone;\r\n }\r\n\r\n /**\r\n * Serializes this PBR Material.\r\n * @returns - An object with the serialized material.\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n serializationObject.customType = \"BABYLON.PBRMaterial\";\r\n\r\n return serializationObject;\r\n }\r\n\r\n // Statics\r\n /**\r\n * Parses a PBR Material from a serialized object.\r\n * @param source - Serialized object.\r\n * @param scene - BJS scene instance.\r\n * @param rootUrl - url for the scene object\r\n * @returns - PBRMaterial\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): PBRMaterial {\r\n const material = SerializationHelper.Parse(() => new PBRMaterial(source.name, scene), source, scene, rootUrl);\r\n\r\n if (source.stencil) {\r\n material.stencil.parse(source.stencil, scene, rootUrl);\r\n }\r\n\r\n Material._parsePlugins(source, material, scene, rootUrl);\r\n\r\n // The code block below ensures backward compatibility with serialized materials before plugins are automatically serialized.\r\n if (source.clearCoat) {\r\n material.clearCoat.parse(source.clearCoat, scene, rootUrl);\r\n }\r\n if (source.anisotropy) {\r\n material.anisotropy.parse(source.anisotropy, scene, rootUrl);\r\n }\r\n if (source.brdf) {\r\n material.brdf.parse(source.brdf, scene, rootUrl);\r\n }\r\n if (source.sheen) {\r\n material.sheen.parse(source.sheen, scene, rootUrl);\r\n }\r\n if (source.subSurface) {\r\n material.subSurface.parse(source.subSurface, scene, rootUrl);\r\n }\r\n if (source.iridescence) {\r\n material.iridescence.parse(source.iridescence, scene, rootUrl);\r\n }\r\n\r\n return material;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PBRMaterial\", PBRMaterial);\r\n","import { serialize, SerializationHelper, serializeAsColor3, expandToProperty } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Color3, TmpColors } from \"../Maths/math.color\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { IShadowGenerator } from \"./Shadows/shadowGenerator\";\r\nimport { GetClass } from \"../Misc/typeStore\";\r\nimport type { ISortableLight } from \"./lightConstants\";\r\nimport { LightConstants } from \"./lightConstants\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\n\r\n/**\r\n * Base class of all the lights in Babylon. It groups all the generic information about lights.\r\n * Lights are used, as you would expect, to affect how meshes are seen, in terms of both illumination and colour.\r\n * All meshes allow light to pass through them unless shadow generation is activated. The default number of lights allowed is four but this can be increased.\r\n */\r\nexport abstract class Light extends Node implements ISortableLight {\r\n /**\r\n * Falloff Default: light is falling off following the material specification:\r\n * standard material is using standard falloff whereas pbr material can request special falloff per materials.\r\n */\r\n public static readonly FALLOFF_DEFAULT = LightConstants.FALLOFF_DEFAULT;\r\n\r\n /**\r\n * Falloff Physical: light is falling off following the inverse squared distance law.\r\n */\r\n public static readonly FALLOFF_PHYSICAL = LightConstants.FALLOFF_PHYSICAL;\r\n\r\n /**\r\n * Falloff gltf: light is falling off as described in the gltf moving to PBR document\r\n * to enhance interoperability with other engines.\r\n */\r\n public static readonly FALLOFF_GLTF = LightConstants.FALLOFF_GLTF;\r\n\r\n /**\r\n * Falloff Standard: light is falling off like in the standard material\r\n * to enhance interoperability with other materials.\r\n */\r\n public static readonly FALLOFF_STANDARD = LightConstants.FALLOFF_STANDARD;\r\n\r\n //lightmapMode Consts\r\n /**\r\n * If every light affecting the material is in this lightmapMode,\r\n * material.lightmapTexture adds or multiplies\r\n * (depends on material.useLightmapAsShadowmap)\r\n * after every other light calculations.\r\n */\r\n public static readonly LIGHTMAP_DEFAULT = LightConstants.LIGHTMAP_DEFAULT;\r\n /**\r\n * material.lightmapTexture as only diffuse lighting from this light\r\n * adds only specular lighting from this light\r\n * adds dynamic shadows\r\n */\r\n public static readonly LIGHTMAP_SPECULAR = LightConstants.LIGHTMAP_SPECULAR;\r\n /**\r\n * material.lightmapTexture as only lighting\r\n * no light calculation from this light\r\n * only adds dynamic shadows from this light\r\n */\r\n public static readonly LIGHTMAP_SHADOWSONLY = LightConstants.LIGHTMAP_SHADOWSONLY;\r\n\r\n // Intensity Mode Consts\r\n /**\r\n * Each light type uses the default quantity according to its type:\r\n * point/spot lights use luminous intensity\r\n * directional lights use illuminance\r\n */\r\n public static readonly INTENSITYMODE_AUTOMATIC = LightConstants.INTENSITYMODE_AUTOMATIC;\r\n /**\r\n * lumen (lm)\r\n */\r\n public static readonly INTENSITYMODE_LUMINOUSPOWER = LightConstants.INTENSITYMODE_LUMINOUSPOWER;\r\n /**\r\n * candela (lm/sr)\r\n */\r\n public static readonly INTENSITYMODE_LUMINOUSINTENSITY = LightConstants.INTENSITYMODE_LUMINOUSINTENSITY;\r\n /**\r\n * lux (lm/m^2)\r\n */\r\n public static readonly INTENSITYMODE_ILLUMINANCE = LightConstants.INTENSITYMODE_ILLUMINANCE;\r\n /**\r\n * nit (cd/m^2)\r\n */\r\n public static readonly INTENSITYMODE_LUMINANCE = LightConstants.INTENSITYMODE_LUMINANCE;\r\n\r\n // Light types ids const.\r\n /**\r\n * Light type const id of the point light.\r\n */\r\n public static readonly LIGHTTYPEID_POINTLIGHT = LightConstants.LIGHTTYPEID_POINTLIGHT;\r\n /**\r\n * Light type const id of the directional light.\r\n */\r\n public static readonly LIGHTTYPEID_DIRECTIONALLIGHT = LightConstants.LIGHTTYPEID_DIRECTIONALLIGHT;\r\n /**\r\n * Light type const id of the spot light.\r\n */\r\n public static readonly LIGHTTYPEID_SPOTLIGHT = LightConstants.LIGHTTYPEID_SPOTLIGHT;\r\n /**\r\n * Light type const id of the hemispheric light.\r\n */\r\n public static readonly LIGHTTYPEID_HEMISPHERICLIGHT = LightConstants.LIGHTTYPEID_HEMISPHERICLIGHT;\r\n\r\n /**\r\n * Diffuse gives the basic color to an object.\r\n */\r\n @serializeAsColor3()\r\n public diffuse = new Color3(1.0, 1.0, 1.0);\r\n\r\n /**\r\n * Specular produces a highlight color on an object.\r\n * Note: This is not affecting PBR materials.\r\n */\r\n @serializeAsColor3()\r\n public specular = new Color3(1.0, 1.0, 1.0);\r\n\r\n /**\r\n * Defines the falloff type for this light. This lets overriding how punctual light are\r\n * falling off base on range or angle.\r\n * This can be set to any values in Light.FALLOFF_x.\r\n *\r\n * Note: This is only useful for PBR Materials at the moment. This could be extended if required to\r\n * other types of materials.\r\n */\r\n @serialize()\r\n public falloffType = Light.FALLOFF_DEFAULT;\r\n\r\n /**\r\n * Strength of the light.\r\n * Note: By default it is define in the framework own unit.\r\n * Note: In PBR materials the intensityMode can be use to chose what unit the intensity is defined in.\r\n */\r\n @serialize()\r\n public intensity = 1.0;\r\n\r\n private _range = Number.MAX_VALUE;\r\n protected _inverseSquaredRange = 0;\r\n\r\n /**\r\n * Defines how far from the source the light is impacting in scene units.\r\n * Note: Unused in PBR material as the distance light falloff is defined following the inverse squared falloff.\r\n */\r\n @serialize()\r\n public get range(): number {\r\n return this._range;\r\n }\r\n /**\r\n * Defines how far from the source the light is impacting in scene units.\r\n * Note: Unused in PBR material as the distance light falloff is defined following the inverse squared falloff.\r\n */\r\n public set range(value: number) {\r\n this._range = value;\r\n this._inverseSquaredRange = 1.0 / (this.range * this.range);\r\n }\r\n\r\n /**\r\n * Cached photometric scale default to 1.0 as the automatic intensity mode defaults to 1.0 for every type\r\n * of light.\r\n */\r\n private _photometricScale = 1.0;\r\n\r\n private _intensityMode: number = Light.INTENSITYMODE_AUTOMATIC;\r\n /**\r\n * Gets the photometric scale used to interpret the intensity.\r\n * This is only relevant with PBR Materials where the light intensity can be defined in a physical way.\r\n */\r\n @serialize()\r\n public get intensityMode(): number {\r\n return this._intensityMode;\r\n }\r\n /**\r\n * Sets the photometric scale used to interpret the intensity.\r\n * This is only relevant with PBR Materials where the light intensity can be defined in a physical way.\r\n */\r\n public set intensityMode(value: number) {\r\n this._intensityMode = value;\r\n this._computePhotometricScale();\r\n }\r\n\r\n private _radius = 0.00001;\r\n /**\r\n * Gets the light radius used by PBR Materials to simulate soft area lights.\r\n */\r\n @serialize()\r\n public get radius(): number {\r\n return this._radius;\r\n }\r\n /**\r\n * sets the light radius used by PBR Materials to simulate soft area lights.\r\n */\r\n public set radius(value: number) {\r\n this._radius = value;\r\n this._computePhotometricScale();\r\n }\r\n\r\n @serialize()\r\n private _renderPriority: number;\r\n /**\r\n * Defines the rendering priority of the lights. It can help in case of fallback or number of lights\r\n * exceeding the number allowed of the materials.\r\n */\r\n @expandToProperty(\"_reorderLightsInScene\")\r\n public renderPriority: number = 0;\r\n\r\n @serialize(\"shadowEnabled\")\r\n private _shadowEnabled: boolean = true;\r\n /**\r\n * Gets whether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching\r\n * the current shadow generator.\r\n */\r\n public get shadowEnabled(): boolean {\r\n return this._shadowEnabled;\r\n }\r\n /**\r\n * Sets whether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching\r\n * the current shadow generator.\r\n */\r\n public set shadowEnabled(value: boolean) {\r\n if (this._shadowEnabled === value) {\r\n return;\r\n }\r\n\r\n this._shadowEnabled = value;\r\n this._markMeshesAsLightDirty();\r\n }\r\n\r\n private _includedOnlyMeshes: AbstractMesh[];\r\n /**\r\n * Gets the only meshes impacted by this light.\r\n */\r\n public get includedOnlyMeshes(): AbstractMesh[] {\r\n return this._includedOnlyMeshes;\r\n }\r\n /**\r\n * Sets the only meshes impacted by this light.\r\n */\r\n public set includedOnlyMeshes(value: AbstractMesh[]) {\r\n this._includedOnlyMeshes = value;\r\n this._hookArrayForIncludedOnly(value);\r\n }\r\n\r\n private _excludedMeshes: AbstractMesh[];\r\n /**\r\n * Gets the meshes not impacted by this light.\r\n */\r\n public get excludedMeshes(): AbstractMesh[] {\r\n return this._excludedMeshes;\r\n }\r\n /**\r\n * Sets the meshes not impacted by this light.\r\n */\r\n public set excludedMeshes(value: AbstractMesh[]) {\r\n this._excludedMeshes = value;\r\n this._hookArrayForExcluded(value);\r\n }\r\n\r\n @serialize(\"excludeWithLayerMask\")\r\n private _excludeWithLayerMask = 0;\r\n /**\r\n * Gets the layer id use to find what meshes are not impacted by the light.\r\n * Inactive if 0\r\n */\r\n public get excludeWithLayerMask(): number {\r\n return this._excludeWithLayerMask;\r\n }\r\n /**\r\n * Sets the layer id use to find what meshes are not impacted by the light.\r\n * Inactive if 0\r\n */\r\n public set excludeWithLayerMask(value: number) {\r\n this._excludeWithLayerMask = value;\r\n this._resyncMeshes();\r\n }\r\n\r\n @serialize(\"includeOnlyWithLayerMask\")\r\n private _includeOnlyWithLayerMask = 0;\r\n /**\r\n * Gets the layer id use to find what meshes are impacted by the light.\r\n * Inactive if 0\r\n */\r\n public get includeOnlyWithLayerMask(): number {\r\n return this._includeOnlyWithLayerMask;\r\n }\r\n /**\r\n * Sets the layer id use to find what meshes are impacted by the light.\r\n * Inactive if 0\r\n */\r\n public set includeOnlyWithLayerMask(value: number) {\r\n this._includeOnlyWithLayerMask = value;\r\n this._resyncMeshes();\r\n }\r\n\r\n @serialize(\"lightmapMode\")\r\n private _lightmapMode = 0;\r\n /**\r\n * Gets the lightmap mode of this light (should be one of the constants defined by Light.LIGHTMAP_x)\r\n */\r\n public get lightmapMode(): number {\r\n return this._lightmapMode;\r\n }\r\n /**\r\n * Sets the lightmap mode of this light (should be one of the constants defined by Light.LIGHTMAP_x)\r\n */\r\n public set lightmapMode(value: number) {\r\n if (this._lightmapMode === value) {\r\n return;\r\n }\r\n\r\n this._lightmapMode = value;\r\n this._markMeshesAsLightDirty();\r\n }\r\n\r\n /**\r\n * Shadow generators associated to the light.\r\n * @internal Internal use only.\r\n */\r\n public _shadowGenerators: Nullable, IShadowGenerator>> = null;\r\n\r\n /**\r\n * @internal Internal use only.\r\n */\r\n public _excludedMeshesIds = new Array();\r\n\r\n /**\r\n * @internal Internal use only.\r\n */\r\n public _includedOnlyMeshesIds = new Array();\r\n\r\n /**\r\n * The current light uniform buffer.\r\n * @internal Internal use only.\r\n */\r\n public _uniformBuffer: UniformBuffer;\r\n\r\n /** @internal */\r\n public _renderId: number;\r\n\r\n private _lastUseSpecular: boolean;\r\n\r\n /**\r\n * Creates a Light object in the scene.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The friendly name of the light\r\n * @param scene The scene the light belongs too\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.getScene().addLight(this);\r\n this._uniformBuffer = new UniformBuffer(this.getScene().getEngine(), undefined, undefined, name);\r\n this._buildUniformLayout();\r\n\r\n this.includedOnlyMeshes = new Array();\r\n this.excludedMeshes = new Array();\r\n\r\n this._resyncMeshes();\r\n }\r\n\r\n protected abstract _buildUniformLayout(): void;\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the Light information.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The light\r\n */\r\n public abstract transferToEffect(effect: Effect, lightIndex: string): Light;\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the Light textures.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The light\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public transferTexturesToEffect(effect: Effect, lightIndex: string): Light {\r\n // Do nothing by default.\r\n return this;\r\n }\r\n\r\n /**\r\n * Binds the lights information from the scene to the effect for the given mesh.\r\n * @param lightIndex Light index\r\n * @param scene The scene where the light belongs to\r\n * @param effect The effect we are binding the data to\r\n * @param useSpecular Defines if specular is supported\r\n * @param receiveShadows Defines if the effect (mesh) we bind the light for receives shadows\r\n */\r\n public _bindLight(lightIndex: number, scene: Scene, effect: Effect, useSpecular: boolean, receiveShadows = true): void {\r\n const iAsString = lightIndex.toString();\r\n let needUpdate = false;\r\n\r\n this._uniformBuffer.bindToEffect(effect, \"Light\" + iAsString);\r\n\r\n if (this._renderId !== scene.getRenderId() || this._lastUseSpecular !== useSpecular || !this._uniformBuffer.useUbo) {\r\n this._renderId = scene.getRenderId();\r\n this._lastUseSpecular = useSpecular;\r\n\r\n const scaledIntensity = this.getScaledIntensity();\r\n\r\n this.transferToEffect(effect, iAsString);\r\n\r\n this.diffuse.scaleToRef(scaledIntensity, TmpColors.Color3[0]);\r\n this._uniformBuffer.updateColor4(\"vLightDiffuse\", TmpColors.Color3[0], this.range, iAsString);\r\n if (useSpecular) {\r\n this.specular.scaleToRef(scaledIntensity, TmpColors.Color3[1]);\r\n this._uniformBuffer.updateColor4(\"vLightSpecular\", TmpColors.Color3[1], this.radius, iAsString);\r\n }\r\n needUpdate = true;\r\n }\r\n\r\n // Textures might still need to be rebound.\r\n this.transferTexturesToEffect(effect, iAsString);\r\n\r\n // Shadows\r\n if (scene.shadowsEnabled && this.shadowEnabled && receiveShadows) {\r\n const shadowGenerator = this.getShadowGenerator(scene.activeCamera) ?? this.getShadowGenerator();\r\n if (shadowGenerator) {\r\n shadowGenerator.bindShadowLight(iAsString, effect);\r\n needUpdate = true;\r\n }\r\n }\r\n\r\n if (needUpdate) {\r\n this._uniformBuffer.update();\r\n } else {\r\n this._uniformBuffer.bindUniformBuffer();\r\n }\r\n }\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the Light information.\r\n * @param effect The effect to update\r\n * @param lightDataUniformName The uniform used to store light data (position or direction)\r\n * @returns The light\r\n */\r\n public abstract transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string): Light;\r\n\r\n /**\r\n * Returns the string \"Light\".\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"Light\";\r\n }\r\n\r\n /** @internal */\r\n public readonly _isLight = true;\r\n\r\n /**\r\n * Converts the light information to a readable string for debug purpose.\r\n * @param fullDetails Supports for multiple levels of logging within scene loading\r\n * @returns the human readable light info\r\n */\r\n public toString(fullDetails?: boolean): string {\r\n let ret = \"Name: \" + this.name;\r\n ret += \", type: \" + [\"Point\", \"Directional\", \"Spot\", \"Hemispheric\"][this.getTypeID()];\r\n if (this.animations) {\r\n for (let i = 0; i < this.animations.length; i++) {\r\n ret += \", animation[0]: \" + this.animations[i].toString(fullDetails);\r\n }\r\n }\r\n return ret;\r\n }\r\n\r\n /** @internal */\r\n protected _syncParentEnabledState() {\r\n super._syncParentEnabledState();\r\n if (!this.isDisposed()) {\r\n this._resyncMeshes();\r\n }\r\n }\r\n\r\n /**\r\n * Set the enabled state of this node.\r\n * @param value - the new enabled state\r\n */\r\n public setEnabled(value: boolean): void {\r\n super.setEnabled(value);\r\n\r\n this._resyncMeshes();\r\n }\r\n\r\n /**\r\n * Returns the Light associated shadow generator if any.\r\n * @param camera Camera for which the shadow generator should be retrieved (default: null). If null, retrieves the default shadow generator\r\n * @returns the associated shadow generator.\r\n */\r\n public getShadowGenerator(camera: Nullable = null): Nullable {\r\n if (this._shadowGenerators === null) {\r\n return null;\r\n }\r\n\r\n return this._shadowGenerators.get(camera) ?? null;\r\n }\r\n\r\n /**\r\n * Returns all the shadow generators associated to this light\r\n * @returns\r\n */\r\n public getShadowGenerators(): Nullable, IShadowGenerator>> {\r\n return this._shadowGenerators;\r\n }\r\n\r\n /**\r\n * Returns a Vector3, the absolute light position in the World.\r\n * @returns the world space position of the light\r\n */\r\n public getAbsolutePosition(): Vector3 {\r\n return Vector3.Zero();\r\n }\r\n\r\n /**\r\n * Specifies if the light will affect the passed mesh.\r\n * @param mesh The mesh to test against the light\r\n * @returns true the mesh is affected otherwise, false.\r\n */\r\n public canAffectMesh(mesh: AbstractMesh): boolean {\r\n if (!mesh) {\r\n return true;\r\n }\r\n\r\n if (this.includedOnlyMeshes && this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {\r\n return false;\r\n }\r\n\r\n if (this.excludedMeshes && this.excludedMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {\r\n return false;\r\n }\r\n\r\n if (this.includeOnlyWithLayerMask !== 0 && (this.includeOnlyWithLayerMask & mesh.layerMask) === 0) {\r\n return false;\r\n }\r\n\r\n if (this.excludeWithLayerMask !== 0 && this.excludeWithLayerMask & mesh.layerMask) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Releases resources associated with this node.\r\n * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)\r\n * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n if (this._shadowGenerators) {\r\n const iterator = this._shadowGenerators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const shadowGenerator = key.value;\r\n shadowGenerator.dispose();\r\n }\r\n this._shadowGenerators = null;\r\n }\r\n\r\n // Animations\r\n this.getScene().stopAnimation(this);\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.lights.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.lights.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n // Remove from meshes\r\n for (const mesh of this.getScene().meshes) {\r\n mesh._removeLightSource(this, true);\r\n }\r\n\r\n this._uniformBuffer.dispose();\r\n\r\n // Remove from scene\r\n this.getScene().removeLight(this);\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n\r\n /**\r\n * Returns the light type ID (integer).\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public getTypeID(): number {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Returns the intensity scaled by the Photometric Scale according to the light type and intensity mode.\r\n * @returns the scaled intensity in intensity mode unit\r\n */\r\n public getScaledIntensity() {\r\n return this._photometricScale * this.intensity;\r\n }\r\n\r\n /**\r\n * Returns a new Light object, named \"name\", from the current one.\r\n * @param name The name of the cloned light\r\n * @param newParent The parent of this light, if it has one\r\n * @returns the new created light\r\n */\r\n public clone(name: string, newParent: Nullable = null): Nullable {\r\n const constructor = Light.GetConstructorFromName(this.getTypeID(), name, this.getScene());\r\n\r\n if (!constructor) {\r\n return null;\r\n }\r\n const clonedLight = SerializationHelper.Clone(constructor, this);\r\n if (name) {\r\n clonedLight.name = name;\r\n }\r\n if (newParent) {\r\n clonedLight.parent = newParent;\r\n }\r\n clonedLight.setEnabled(this.isEnabled());\r\n\r\n this.onClonedObservable.notifyObservers(clonedLight);\r\n\r\n return clonedLight;\r\n }\r\n\r\n /**\r\n * Serializes the current light into a Serialization object.\r\n * @returns the serialized object.\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n serializationObject.uniqueId = this.uniqueId;\r\n\r\n // Type\r\n serializationObject.type = this.getTypeID();\r\n\r\n // Parent\r\n if (this.parent) {\r\n this.parent._serializeAsParent(serializationObject);\r\n }\r\n\r\n // Inclusion / exclusions\r\n if (this.excludedMeshes.length > 0) {\r\n serializationObject.excludedMeshesIds = [];\r\n this.excludedMeshes.forEach((mesh: AbstractMesh) => {\r\n serializationObject.excludedMeshesIds.push(mesh.id);\r\n });\r\n }\r\n\r\n if (this.includedOnlyMeshes.length > 0) {\r\n serializationObject.includedOnlyMeshesIds = [];\r\n this.includedOnlyMeshes.forEach((mesh: AbstractMesh) => {\r\n serializationObject.includedOnlyMeshesIds.push(mesh.id);\r\n });\r\n }\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\r\n serializationObject.ranges = this.serializeAnimationRanges();\r\n\r\n serializationObject.isEnabled = this.isEnabled();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a new typed light from the passed type (integer) : point light = 0, directional light = 1, spot light = 2, hemispheric light = 3.\r\n * This new light is named \"name\" and added to the passed scene.\r\n * @param type Type according to the types available in Light.LIGHTTYPEID_x\r\n * @param name The friendly name of the light\r\n * @param scene The scene the new light will belong to\r\n * @returns the constructor function\r\n */\r\n static GetConstructorFromName(type: number, name: string, scene: Scene): Nullable<() => Light> {\r\n const constructorFunc = Node.Construct(\"Light_Type_\" + type, name, scene);\r\n\r\n if (constructorFunc) {\r\n return <() => Light>constructorFunc;\r\n }\r\n\r\n // Default to no light for none present once.\r\n return null;\r\n }\r\n\r\n /**\r\n * Parses the passed \"parsedLight\" and returns a new instanced Light from this parsing.\r\n * @param parsedLight The JSON representation of the light\r\n * @param scene The scene to create the parsed light in\r\n * @returns the created light after parsing\r\n */\r\n public static Parse(parsedLight: any, scene: Scene): Nullable {\r\n const constructor = Light.GetConstructorFromName(parsedLight.type, parsedLight.name, scene);\r\n\r\n if (!constructor) {\r\n return null;\r\n }\r\n\r\n const light = SerializationHelper.Parse(constructor, parsedLight, scene);\r\n\r\n // Inclusion / exclusions\r\n if (parsedLight.excludedMeshesIds) {\r\n light._excludedMeshesIds = parsedLight.excludedMeshesIds;\r\n }\r\n\r\n if (parsedLight.includedOnlyMeshesIds) {\r\n light._includedOnlyMeshesIds = parsedLight.includedOnlyMeshesIds;\r\n }\r\n\r\n // Parent\r\n if (parsedLight.parentId !== undefined) {\r\n light._waitingParentId = parsedLight.parentId;\r\n }\r\n\r\n if (parsedLight.parentInstanceIndex !== undefined) {\r\n light._waitingParentInstanceIndex = parsedLight.parentInstanceIndex;\r\n }\r\n\r\n // Falloff\r\n if (parsedLight.falloffType !== undefined) {\r\n light.falloffType = parsedLight.falloffType;\r\n }\r\n\r\n // Lightmaps\r\n if (parsedLight.lightmapMode !== undefined) {\r\n light.lightmapMode = parsedLight.lightmapMode;\r\n }\r\n\r\n // Animations\r\n if (parsedLight.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedLight.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedLight.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n light.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n Node.ParseAnimationRanges(light, parsedLight, scene);\r\n }\r\n\r\n if (parsedLight.autoAnimate) {\r\n scene.beginAnimation(light, parsedLight.autoAnimateFrom, parsedLight.autoAnimateTo, parsedLight.autoAnimateLoop, parsedLight.autoAnimateSpeed || 1.0);\r\n }\r\n\r\n // Check if isEnabled is defined to be back compatible with prior serialized versions.\r\n if (parsedLight.isEnabled !== undefined) {\r\n light.setEnabled(parsedLight.isEnabled);\r\n }\r\n\r\n return light;\r\n }\r\n\r\n private _hookArrayForExcluded(array: AbstractMesh[]): void {\r\n const oldPush = array.push;\r\n array.push = (...items: AbstractMesh[]) => {\r\n const result = oldPush.apply(array, items);\r\n\r\n for (const item of items) {\r\n item._resyncLightSource(this);\r\n }\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 for (const item of deleted) {\r\n item._resyncLightSource(this);\r\n }\r\n\r\n return deleted;\r\n };\r\n\r\n for (const item of array) {\r\n item._resyncLightSource(this);\r\n }\r\n }\r\n\r\n private _hookArrayForIncludedOnly(array: AbstractMesh[]): void {\r\n const oldPush = array.push;\r\n array.push = (...items: AbstractMesh[]) => {\r\n const result = oldPush.apply(array, items);\r\n\r\n this._resyncMeshes();\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._resyncMeshes();\r\n\r\n return deleted;\r\n };\r\n\r\n this._resyncMeshes();\r\n }\r\n\r\n private _resyncMeshes() {\r\n for (const mesh of this.getScene().meshes) {\r\n mesh._resyncLightSource(this);\r\n }\r\n }\r\n\r\n /**\r\n * Forces the meshes to update their light related information in their rendering used effects\r\n * @internal Internal Use Only\r\n */\r\n public _markMeshesAsLightDirty() {\r\n for (const mesh of this.getScene().meshes) {\r\n if (mesh.lightSources.indexOf(this) !== -1) {\r\n mesh._markSubMeshesAsLightDirty();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Recomputes the cached photometric scale if needed.\r\n */\r\n private _computePhotometricScale(): void {\r\n this._photometricScale = this._getPhotometricScale();\r\n this.getScene().resetCachedMaterial();\r\n }\r\n\r\n /**\r\n * Returns the Photometric Scale according to the light type and intensity mode.\r\n */\r\n private _getPhotometricScale() {\r\n let photometricScale = 0.0;\r\n const lightTypeID = this.getTypeID();\r\n\r\n //get photometric mode\r\n let photometricMode = this.intensityMode;\r\n if (photometricMode === Light.INTENSITYMODE_AUTOMATIC) {\r\n if (lightTypeID === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {\r\n photometricMode = Light.INTENSITYMODE_ILLUMINANCE;\r\n } else {\r\n photometricMode = Light.INTENSITYMODE_LUMINOUSINTENSITY;\r\n }\r\n }\r\n\r\n //compute photometric scale\r\n switch (lightTypeID) {\r\n case Light.LIGHTTYPEID_POINTLIGHT:\r\n case Light.LIGHTTYPEID_SPOTLIGHT:\r\n switch (photometricMode) {\r\n case Light.INTENSITYMODE_LUMINOUSPOWER:\r\n photometricScale = 1.0 / (4.0 * Math.PI);\r\n break;\r\n case Light.INTENSITYMODE_LUMINOUSINTENSITY:\r\n photometricScale = 1.0;\r\n break;\r\n case Light.INTENSITYMODE_LUMINANCE:\r\n photometricScale = this.radius * this.radius;\r\n break;\r\n }\r\n break;\r\n\r\n case Light.LIGHTTYPEID_DIRECTIONALLIGHT:\r\n switch (photometricMode) {\r\n case Light.INTENSITYMODE_ILLUMINANCE:\r\n photometricScale = 1.0;\r\n break;\r\n case Light.INTENSITYMODE_LUMINANCE: {\r\n // When radius (and therefore solid angle) is non-zero a directional lights brightness can be specified via central (peak) luminance.\r\n // For a directional light the 'radius' defines the angular radius (in radians) rather than world-space radius (e.g. in metres).\r\n let apexAngleRadians = this.radius;\r\n // Impose a minimum light angular size to avoid the light becoming an infinitely small angular light source (i.e. a dirac delta function).\r\n apexAngleRadians = Math.max(apexAngleRadians, 0.001);\r\n const solidAngle = 2.0 * Math.PI * (1.0 - Math.cos(apexAngleRadians));\r\n photometricScale = solidAngle;\r\n break;\r\n }\r\n }\r\n break;\r\n\r\n case Light.LIGHTTYPEID_HEMISPHERICLIGHT:\r\n // No fall off in hemispheric light.\r\n photometricScale = 1.0;\r\n break;\r\n }\r\n return photometricScale;\r\n }\r\n\r\n /**\r\n * Reorder the light in the scene according to their defined priority.\r\n * @internal Internal Use Only\r\n */\r\n public _reorderLightsInScene(): void {\r\n const scene = this.getScene();\r\n if (this._renderPriority != 0) {\r\n scene.requireLightSorting = true;\r\n }\r\n this.getScene().sortLightsByPriority();\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public abstract prepareLightSpecificDefines(defines: any, lightIndex: number): void;\r\n}\r\n","import { serializeAsColor3, serializeAsVector3 } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport { Node } from \"../node\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Light } from \"./light\";\r\nimport type { IShadowGenerator } from \"./Shadows/shadowGenerator\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_3\", (name, scene) => {\r\n return () => new HemisphericLight(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * The HemisphericLight simulates the ambient environment light,\r\n * so the passed direction is the light reflection direction, not the incoming direction.\r\n */\r\nexport class HemisphericLight extends Light {\r\n /**\r\n * The groundColor is the light in the opposite direction to the one specified during creation.\r\n * You can think of the diffuse and specular light as coming from the centre of the object in the given direction and the groundColor light in the opposite direction.\r\n */\r\n @serializeAsColor3()\r\n public groundColor = new Color3(0.0, 0.0, 0.0);\r\n\r\n /**\r\n * The light reflection direction, not the incoming direction.\r\n */\r\n @serializeAsVector3()\r\n public direction: Vector3;\r\n\r\n /**\r\n * Creates a HemisphericLight object in the scene according to the passed direction (Vector3).\r\n * The HemisphericLight simulates the ambient environment light, so the passed direction is the light reflection direction, not the incoming direction.\r\n * The HemisphericLight can't cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The friendly name of the light\r\n * @param direction The direction of the light reflection\r\n * @param scene The scene the light belongs to\r\n */\r\n constructor(name: string, direction: Vector3, scene?: Scene) {\r\n super(name, scene);\r\n this.direction = direction || Vector3.Up();\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"vLightGround\", 3);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Returns the string \"HemisphericLight\".\r\n * @returns The class name\r\n */\r\n public getClassName(): string {\r\n return \"HemisphericLight\";\r\n }\r\n\r\n /**\r\n * Sets the HemisphericLight direction towards the passed target (Vector3).\r\n * Returns the updated direction.\r\n * @param target The target the direction should point to\r\n * @returns The computed direction\r\n */\r\n public setDirectionToTarget(target: Vector3): Vector3 {\r\n this.direction = Vector3.Normalize(target.subtract(Vector3.Zero()));\r\n return this.direction;\r\n }\r\n\r\n /**\r\n * Returns the shadow generator associated to the light.\r\n * @returns Always null for hemispheric lights because it does not support shadows.\r\n */\r\n public getShadowGenerator(): Nullable {\r\n return null;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the HemisphericLight normalized direction and color and the passed name (string).\r\n * @param _effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The hemispheric light\r\n */\r\n public transferToEffect(_effect: Effect, lightIndex: string): HemisphericLight {\r\n const normalizeDirection = Vector3.Normalize(this.direction);\r\n this._uniformBuffer.updateFloat4(\"vLightData\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0.0, lightIndex);\r\n this._uniformBuffer.updateColor3(\"vLightGround\", this.groundColor.scale(this.intensity), lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string) {\r\n const normalizeDirection = Vector3.Normalize(this.direction);\r\n effect.setFloat3(lightDataUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Computes the world matrix of the node\r\n * @returns the world matrix\r\n */\r\n public computeWorldMatrix(): Matrix {\r\n if (!this._worldMatrix) {\r\n this._worldMatrix = Matrix.Identity();\r\n }\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * Returns the integer 3.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public getTypeID(): number {\r\n return Light.LIGHTTYPEID_HEMISPHERICLIGHT;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"HEMILIGHT\" + lightIndex] = true;\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"kernelBlurVaryingDeclaration\";\nconst shader = `varying vec2 sampleCoord{X};`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const kernelBlurVaryingDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"packingFunctions\";\nconst shader = `vec4 pack(float depth)\n{const vec4 bit_shift=vec4(255.0*255.0*255.0,255.0*255.0,255.0,1.0);const vec4 bit_mask=vec4(0.0,1.0/255.0,1.0/255.0,1.0/255.0);vec4 res=fract(depth*bit_shift);res-=res.xxyz*bit_mask;return res;}\nfloat unpack(vec4 color)\n{const vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);return dot(color,bit_shift);}`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const packingFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"kernelBlurFragment\";\nconst shader = `#ifdef DOF\nfactor=sampleCoC(sampleCoord{X}); \ncomputedWeight=KERNEL_WEIGHT{X}*factor;sumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCoord{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCoord{X})*computedWeight;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const kernelBlurFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"kernelBlurFragment2\";\nconst shader = `#ifdef DOF\nfactor=sampleCoC(sampleCenter+delta*KERNEL_DEP_OFFSET{X});computedWeight=KERNEL_DEP_WEIGHT{X}*factor;sumOfWeights+=computedWeight;\n#else\ncomputedWeight=KERNEL_DEP_WEIGHT{X};\n#endif\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X}))*computedWeight;\n#else\nblend+=texture2D(textureSampler,sampleCenter+delta*KERNEL_DEP_OFFSET{X})*computedWeight;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const kernelBlurFragment2 = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/kernelBlurVaryingDeclaration\";\nimport \"./ShadersInclude/packingFunctions\";\nimport \"./ShadersInclude/kernelBlurFragment\";\nimport \"./ShadersInclude/kernelBlurFragment2\";\n\nconst name = \"kernelBlurPixelShader\";\nconst shader = `uniform sampler2D textureSampler;uniform vec2 delta;varying vec2 sampleCenter;\n#ifdef DOF\nuniform sampler2D circleOfConfusionSampler;float sampleCoC(in vec2 offset) {float coc=texture2D(circleOfConfusionSampler,offset).r;return coc; }\n#endif\n#include[0..varyingCount]\n#ifdef PACKEDFLOAT\n#include\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{float computedWeight=0.0;\n#ifdef PACKEDFLOAT\nfloat blend=0.;\n#else\nvec4 blend=vec4(0.);\n#endif\n#ifdef DOF\nfloat sumOfWeights=CENTER_WEIGHT; \nfloat factor=0.0;\n#ifdef PACKEDFLOAT\nblend+=unpack(texture2D(textureSampler,sampleCenter))*CENTER_WEIGHT;\n#else\nblend+=texture2D(textureSampler,sampleCenter)*CENTER_WEIGHT;\n#endif\n#endif\n#include[0..varyingCount]\n#include[0..depCount]\n#ifdef PACKEDFLOAT\ngl_FragColor=pack(blend);\n#else\ngl_FragColor=blend;\n#endif\n#ifdef DOF\ngl_FragColor/=sumOfWeights;\n#endif\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const kernelBlurPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"kernelBlurVertex\";\nconst shader = `sampleCoord{X}=sampleCenter+delta*KERNEL_OFFSET{X};`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const kernelBlurVertex = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/kernelBlurVaryingDeclaration\";\nimport \"./ShadersInclude/kernelBlurVertex\";\n\nconst name = \"kernelBlurVertexShader\";\nconst shader = `attribute vec2 position;uniform vec2 delta;varying vec2 sampleCenter;\n#include[0..varyingCount]\nconst vec2 madd=vec2(0.5,0.5);\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nsampleCenter=(position*madd+madd);\n#include[0..varyingCount]\ngl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const kernelBlurVertexShader = { name, shader };\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Vector2 } from \"../Maths/math.vector\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { PostProcessOptions } from \"./postProcess\";\r\nimport { PostProcess } from \"./postProcess\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport \"../Shaders/kernelBlur.fragment\";\r\nimport \"../Shaders/kernelBlur.vertex\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport { serialize, serializeAsVector2, SerializationHelper } from \"../Misc/decorators\";\r\n\r\nimport type { Scene } from \"../scene\";\r\n\r\n/**\r\n * The Blur Post Process which blurs an image based on a kernel and direction.\r\n * Can be used twice in x and y directions to perform a gaussian blur in two passes.\r\n */\r\nexport class BlurPostProcess extends PostProcess {\r\n @serialize(\"kernel\")\r\n protected _kernel: number;\r\n protected _idealKernel: number;\r\n @serialize(\"packedFloat\")\r\n protected _packedFloat: boolean = false;\r\n private _staticDefines: string = \"\";\r\n\r\n /** The direction in which to blur the image. */\r\n @serializeAsVector2()\r\n public direction: Vector2;\r\n\r\n /**\r\n * Sets the length in pixels of the blur sample region\r\n */\r\n public set kernel(v: number) {\r\n if (this._idealKernel === v) {\r\n return;\r\n }\r\n\r\n v = Math.max(v, 1);\r\n this._idealKernel = v;\r\n this._kernel = this._nearestBestKernel(v);\r\n if (!this._blockCompilation) {\r\n this._updateParameters();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the length in pixels of the blur sample region\r\n */\r\n public get kernel(): number {\r\n return this._idealKernel;\r\n }\r\n\r\n /**\r\n * Sets whether or not the blur needs to unpack/repack floats\r\n */\r\n public set packedFloat(v: boolean) {\r\n if (this._packedFloat === v) {\r\n return;\r\n }\r\n this._packedFloat = v;\r\n if (!this._blockCompilation) {\r\n this._updateParameters();\r\n }\r\n }\r\n\r\n /**\r\n * Gets whether or not the blur is unpacking/repacking floats\r\n */\r\n public get packedFloat(): boolean {\r\n return this._packedFloat;\r\n }\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"BlurPostProcess\" string\r\n */\r\n public getClassName(): string {\r\n return \"BlurPostProcess\";\r\n }\r\n\r\n /**\r\n * Creates a new instance BlurPostProcess\r\n * @param name The name of the effect.\r\n * @param direction The direction in which to blur the image.\r\n * @param kernel The size of the kernel to be used when computing the blur. eg. Size of 3 will blur the center pixel by 2 pixels surrounding it.\r\n * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)\r\n * @param camera The camera to apply the render pass to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\r\n * @param engine The engine which the post process will be applied. (default: current engine)\r\n * @param reusable If the post process can be reused on the same frame. (default: false)\r\n * @param textureType Type of textures used when performing the post process. (default: 0)\r\n * @param defines\r\n * @param _blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)\r\n * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)\r\n */\r\n constructor(\r\n name: string,\r\n direction: Vector2,\r\n kernel: number,\r\n options: number | PostProcessOptions,\r\n camera: Nullable,\r\n samplingMode: number = Texture.BILINEAR_SAMPLINGMODE,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n defines = \"\",\r\n private _blockCompilation = false,\r\n textureFormat = Constants.TEXTUREFORMAT_RGBA\r\n ) {\r\n super(\r\n name,\r\n \"kernelBlur\",\r\n [\"delta\", \"direction\"],\r\n [\"circleOfConfusionSampler\"],\r\n options,\r\n camera,\r\n samplingMode,\r\n engine,\r\n reusable,\r\n null,\r\n textureType,\r\n \"kernelBlur\",\r\n { varyingCount: 0, depCount: 0 },\r\n true,\r\n textureFormat\r\n );\r\n this._staticDefines = defines;\r\n this.direction = direction;\r\n this.onApplyObservable.add((effect: Effect) => {\r\n if (this._outputTexture) {\r\n effect.setFloat2(\"delta\", (1 / this._outputTexture.width) * this.direction.x, (1 / this._outputTexture.height) * this.direction.y);\r\n } else {\r\n effect.setFloat2(\"delta\", (1 / this.width) * this.direction.x, (1 / this.height) * this.direction.y);\r\n }\r\n });\r\n\r\n this.kernel = kernel;\r\n }\r\n\r\n /**\r\n * Updates the effect with the current post process compile time values and recompiles the shader.\r\n * @param defines Define statements that should be added at the beginning of the shader. (default: null)\r\n * @param uniforms Set of uniform variables that will be passed to the shader. (default: null)\r\n * @param samplers Set of Texture2D variables that will be passed to the shader. (default: null)\r\n * @param indexParameters The index parameters to be used for babylons include syntax \"#include[0..varyingCount]\". (default: undefined) See usage in babylon.blurPostProcess.ts and kernelBlur.vertex.fx\r\n * @param onCompiled Called when the shader has been compiled.\r\n * @param onError Called if there is an error when compiling a shader.\r\n */\r\n public updateEffect(\r\n defines: Nullable = null,\r\n uniforms: Nullable = null,\r\n samplers: Nullable = null,\r\n indexParameters?: any,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void\r\n ) {\r\n this._updateParameters(onCompiled, onError);\r\n }\r\n\r\n protected _updateParameters(onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void): void {\r\n // Generate sampling offsets and weights\r\n const N = this._kernel;\r\n const centerIndex = (N - 1) / 2;\r\n\r\n // Generate Gaussian sampling weights over kernel\r\n let offsets = [];\r\n let weights = [];\r\n let totalWeight = 0;\r\n for (let i = 0; i < N; i++) {\r\n const u = i / (N - 1);\r\n const w = this._gaussianWeight(u * 2.0 - 1);\r\n offsets[i] = i - centerIndex;\r\n weights[i] = w;\r\n totalWeight += w;\r\n }\r\n\r\n // Normalize weights\r\n for (let i = 0; i < weights.length; i++) {\r\n weights[i] /= totalWeight;\r\n }\r\n\r\n // Optimize: combine samples to take advantage of hardware linear sampling\r\n // Walk from left to center, combining pairs (symmetrically)\r\n const linearSamplingWeights = [];\r\n const linearSamplingOffsets = [];\r\n\r\n const linearSamplingMap = [];\r\n\r\n for (let i = 0; i <= centerIndex; i += 2) {\r\n const j = Math.min(i + 1, Math.floor(centerIndex));\r\n\r\n const singleCenterSample = i === j;\r\n\r\n if (singleCenterSample) {\r\n linearSamplingMap.push({ o: offsets[i], w: weights[i] });\r\n } else {\r\n const sharedCell = j === centerIndex;\r\n\r\n const weightLinear = weights[i] + weights[j] * (sharedCell ? 0.5 : 1);\r\n const offsetLinear = offsets[i] + 1 / (1 + weights[i] / weights[j]);\r\n\r\n if (offsetLinear === 0) {\r\n linearSamplingMap.push({ o: offsets[i], w: weights[i] });\r\n linearSamplingMap.push({ o: offsets[i + 1], w: weights[i + 1] });\r\n } else {\r\n linearSamplingMap.push({ o: offsetLinear, w: weightLinear });\r\n linearSamplingMap.push({ o: -offsetLinear, w: weightLinear });\r\n }\r\n }\r\n }\r\n\r\n for (let i = 0; i < linearSamplingMap.length; i++) {\r\n linearSamplingOffsets[i] = linearSamplingMap[i].o;\r\n linearSamplingWeights[i] = linearSamplingMap[i].w;\r\n }\r\n\r\n // Replace with optimized\r\n offsets = linearSamplingOffsets;\r\n weights = linearSamplingWeights;\r\n\r\n // Generate shaders\r\n const maxVaryingRows = this.getEngine().getCaps().maxVaryingVectors;\r\n const freeVaryingVec2 = Math.max(maxVaryingRows, 0) - 1; // Because of sampleCenter\r\n\r\n let varyingCount = Math.min(offsets.length, freeVaryingVec2);\r\n\r\n let defines = \"\";\r\n defines += this._staticDefines;\r\n\r\n // The DOF fragment should ignore the center pixel when looping as it is handled manually in the fragment shader.\r\n if (this._staticDefines.indexOf(\"DOF\") != -1) {\r\n defines += `#define CENTER_WEIGHT ${this._glslFloat(weights[varyingCount - 1])}\\n`;\r\n varyingCount--;\r\n }\r\n\r\n for (let i = 0; i < varyingCount; i++) {\r\n defines += `#define KERNEL_OFFSET${i} ${this._glslFloat(offsets[i])}\\n`;\r\n defines += `#define KERNEL_WEIGHT${i} ${this._glslFloat(weights[i])}\\n`;\r\n }\r\n\r\n let depCount = 0;\r\n for (let i = freeVaryingVec2; i < offsets.length; i++) {\r\n defines += `#define KERNEL_DEP_OFFSET${depCount} ${this._glslFloat(offsets[i])}\\n`;\r\n defines += `#define KERNEL_DEP_WEIGHT${depCount} ${this._glslFloat(weights[i])}\\n`;\r\n depCount++;\r\n }\r\n\r\n if (this.packedFloat) {\r\n defines += `#define PACKEDFLOAT 1`;\r\n }\r\n\r\n this._blockCompilation = false;\r\n super.updateEffect(\r\n defines,\r\n null,\r\n null,\r\n {\r\n varyingCount: varyingCount,\r\n depCount: depCount,\r\n },\r\n onCompiled,\r\n onError\r\n );\r\n }\r\n\r\n /**\r\n * Best kernels are odd numbers that when divided by 2, their integer part is even, so 5, 9 or 13.\r\n * Other odd kernels optimize correctly but require proportionally more samples, even kernels are\r\n * possible but will produce minor visual artifacts. Since each new kernel requires a new shader we\r\n * want to minimize kernel changes, having gaps between physical kernels is helpful in that regard.\r\n * The gaps between physical kernels are compensated for in the weighting of the samples\r\n * @param idealKernel Ideal blur kernel.\r\n * @returns Nearest best kernel.\r\n */\r\n protected _nearestBestKernel(idealKernel: number): number {\r\n const v = Math.round(idealKernel);\r\n for (const k of [v, v - 1, v + 1, v - 2, v + 2]) {\r\n if (k % 2 !== 0 && Math.floor(k / 2) % 2 === 0 && k > 0) {\r\n return Math.max(k, 3);\r\n }\r\n }\r\n return Math.max(v, 3);\r\n }\r\n\r\n /**\r\n * Calculates the value of a Gaussian distribution with sigma 3 at a given point.\r\n * @param x The point on the Gaussian distribution to sample.\r\n * @returns the value of the Gaussian function at x.\r\n */\r\n protected _gaussianWeight(x: number): number {\r\n //reference: Engines/ImageProcessingBlur.cpp #dcc760\r\n // We are evaluating the Gaussian (normal) distribution over a kernel parameter space of [-1,1],\r\n // so we truncate at three standard deviations by setting stddev (sigma) to 1/3.\r\n // The choice of 3-sigma truncation is common but arbitrary, and means that the signal is\r\n // truncated at around 1.3% of peak strength.\r\n\r\n //the distribution is scaled to account for the difference between the actual kernel size and the requested kernel size\r\n const sigma = 1 / 3;\r\n const denominator = Math.sqrt(2.0 * Math.PI) * sigma;\r\n const exponent = -((x * x) / (2.0 * sigma * sigma));\r\n const weight = (1.0 / denominator) * Math.exp(exponent);\r\n return weight;\r\n }\r\n\r\n /**\r\n * Generates a string that can be used as a floating point number in GLSL.\r\n * @param x Value to print.\r\n * @param decimalFigures Number of decimal places to print the number to (excluding trailing 0s).\r\n * @returns GLSL float string.\r\n */\r\n protected _glslFloat(x: number, decimalFigures = 8) {\r\n return x.toFixed(decimalFigures).replace(/0+$/, \"\");\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): Nullable {\r\n return SerializationHelper.Parse(\r\n () => {\r\n return new BlurPostProcess(\r\n parsedPostProcess.name,\r\n parsedPostProcess.direction,\r\n parsedPostProcess.kernel,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n scene.getEngine(),\r\n parsedPostProcess.reusable,\r\n parsedPostProcess.textureType,\r\n undefined,\r\n false\r\n );\r\n },\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.BlurPostProcess\", BlurPostProcess);\r\n","import type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { ImageProcessingConfiguration } from \"../../Materials/imageProcessingConfiguration\";\r\nimport { BlurPostProcess } from \"../../PostProcesses/blurPostProcess\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { Plane } from \"../../Maths/math.plane\";\r\nimport type { UniformBuffer } from \"../uniformBuffer\";\r\n/**\r\n * Mirror texture can be used to simulate the view from a mirror in a scene.\r\n * It will dynamically be rendered every frame to adapt to the camera point of view.\r\n * You can then easily use it as a reflectionTexture on a flat surface.\r\n * In case the surface is not a plane, please consider relying on reflection probes.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#mirrortexture\r\n */\r\nexport class MirrorTexture extends RenderTargetTexture {\r\n /**\r\n * Define the reflection plane we want to use. The mirrorPlane is usually set to the constructed reflector.\r\n * It is possible to directly set the mirrorPlane by directly using a Plane(a, b, c, d) where a, b and c give the plane normal vector (a, b, c) and d is a scalar displacement from the mirrorPlane to the origin. However in all but the very simplest of situations it is more straight forward to set it to the reflector as stated in the doc.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#mirrors\r\n */\r\n public mirrorPlane = new Plane(0, 1, 0, 1);\r\n\r\n /**\r\n * Define the blur ratio used to blur the reflection if needed.\r\n */\r\n public set blurRatio(value: number) {\r\n if (this._blurRatio === value) {\r\n return;\r\n }\r\n\r\n this._blurRatio = value;\r\n this._preparePostProcesses();\r\n }\r\n\r\n public get blurRatio(): number {\r\n return this._blurRatio;\r\n }\r\n\r\n /**\r\n * Define the adaptive blur kernel used to blur the reflection if needed.\r\n * This will autocompute the closest best match for the `blurKernel`\r\n */\r\n public set adaptiveBlurKernel(value: number) {\r\n this._adaptiveBlurKernel = value;\r\n this._autoComputeBlurKernel();\r\n }\r\n\r\n /**\r\n * Define the blur kernel used to blur the reflection if needed.\r\n * Please consider using `adaptiveBlurKernel` as it could find the closest best value for you.\r\n */\r\n public set blurKernel(value: number) {\r\n this.blurKernelX = value;\r\n this.blurKernelY = value;\r\n }\r\n\r\n /**\r\n * Define the blur kernel on the X Axis used to blur the reflection if needed.\r\n * Please consider using `adaptiveBlurKernel` as it could find the closest best value for you.\r\n */\r\n public set blurKernelX(value: number) {\r\n if (this._blurKernelX === value) {\r\n return;\r\n }\r\n\r\n this._blurKernelX = value;\r\n this._preparePostProcesses();\r\n }\r\n\r\n public get blurKernelX(): number {\r\n return this._blurKernelX;\r\n }\r\n\r\n /**\r\n * Define the blur kernel on the Y Axis used to blur the reflection if needed.\r\n * Please consider using `adaptiveBlurKernel` as it could find the closest best value for you.\r\n */\r\n public set blurKernelY(value: number) {\r\n if (this._blurKernelY === value) {\r\n return;\r\n }\r\n\r\n this._blurKernelY = value;\r\n this._preparePostProcesses();\r\n }\r\n\r\n public get blurKernelY(): number {\r\n return this._blurKernelY;\r\n }\r\n\r\n private _autoComputeBlurKernel(): void {\r\n const engine = this.getScene()!.getEngine();\r\n\r\n const dw = this.getRenderWidth() / engine.getRenderWidth();\r\n const dh = this.getRenderHeight() / engine.getRenderHeight();\r\n this.blurKernelX = this._adaptiveBlurKernel * dw;\r\n this.blurKernelY = this._adaptiveBlurKernel * dh;\r\n }\r\n\r\n protected _onRatioRescale(): void {\r\n if (this._sizeRatio) {\r\n this.resize(this._initialSizeParameter);\r\n if (!this._adaptiveBlurKernel) {\r\n this._preparePostProcesses();\r\n }\r\n }\r\n\r\n if (this._adaptiveBlurKernel) {\r\n this._autoComputeBlurKernel();\r\n }\r\n }\r\n\r\n private _updateGammaSpace() {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.gammaSpace = !scene.imageProcessingConfiguration.isEnabled || !scene.imageProcessingConfiguration.applyByPostProcess;\r\n }\r\n\r\n private _imageProcessingConfigChangeObserver: Nullable>;\r\n\r\n private _transformMatrix = Matrix.Zero();\r\n private _mirrorMatrix = Matrix.Zero();\r\n\r\n private _blurX: Nullable;\r\n private _blurY: Nullable;\r\n private _adaptiveBlurKernel = 0;\r\n private _blurKernelX = 0;\r\n private _blurKernelY = 0;\r\n private _blurRatio = 1.0;\r\n private _sceneUBO: UniformBuffer;\r\n private _currentSceneUBO: UniformBuffer;\r\n\r\n /**\r\n * Instantiates a Mirror Texture.\r\n * Mirror texture can be used to simulate the view from a mirror in a scene.\r\n * It will dynamically be rendered every frame to adapt to the camera point of view.\r\n * You can then easily use it as a reflectionTexture on a flat surface.\r\n * In case the surface is not a plane, please consider relying on reflection probes.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#mirrors\r\n * @param name\r\n * @param size\r\n * @param scene\r\n * @param generateMipMaps\r\n * @param type\r\n * @param samplingMode\r\n * @param generateDepthBuffer\r\n */\r\n constructor(\r\n name: string,\r\n size: number | { width: number; height: number } | { ratio: number },\r\n scene?: Scene,\r\n generateMipMaps?: boolean,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n samplingMode = Texture.BILINEAR_SAMPLINGMODE,\r\n generateDepthBuffer = true\r\n ) {\r\n super(name, size, scene, generateMipMaps, true, type, false, samplingMode, generateDepthBuffer);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this;\r\n }\r\n this.ignoreCameraViewport = true;\r\n\r\n this._updateGammaSpace();\r\n this._imageProcessingConfigChangeObserver = scene.imageProcessingConfiguration.onUpdateParameters.add(() => {\r\n this._updateGammaSpace();\r\n });\r\n\r\n const engine = scene.getEngine();\r\n\r\n if (engine.supportsUniformBuffers) {\r\n this._sceneUBO = scene.createSceneUniformBuffer(`Scene for Mirror Texture (name \"${name}\")`);\r\n }\r\n\r\n this.onBeforeBindObservable.add(() => {\r\n engine._debugPushGroup?.(`mirror generation for ${name}`, 1);\r\n });\r\n\r\n this.onAfterUnbindObservable.add(() => {\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n let saveClipPlane: Nullable;\r\n\r\n this.onBeforeRenderObservable.add(() => {\r\n if (this._sceneUBO) {\r\n this._currentSceneUBO = scene!.getSceneUniformBuffer();\r\n scene!.setSceneUniformBuffer(this._sceneUBO);\r\n scene!.getSceneUniformBuffer().unbindEffect();\r\n }\r\n\r\n Matrix.ReflectionToRef(this.mirrorPlane, this._mirrorMatrix);\r\n this._mirrorMatrix.multiplyToRef(scene!.getViewMatrix(), this._transformMatrix);\r\n\r\n scene!.setTransformMatrix(this._transformMatrix, scene!.getProjectionMatrix());\r\n\r\n saveClipPlane = scene!.clipPlane;\r\n scene!.clipPlane = this.mirrorPlane;\r\n\r\n scene!._mirroredCameraPosition = Vector3.TransformCoordinates((scene!.activeCamera).globalPosition, this._mirrorMatrix);\r\n });\r\n\r\n this.onAfterRenderObservable.add(() => {\r\n if (this._sceneUBO) {\r\n scene!.setSceneUniformBuffer(this._currentSceneUBO);\r\n }\r\n scene!.updateTransformMatrix();\r\n scene!._mirroredCameraPosition = null;\r\n\r\n scene!.clipPlane = saveClipPlane;\r\n });\r\n }\r\n\r\n private _preparePostProcesses(): void {\r\n this.clearPostProcesses(true);\r\n\r\n if (this._blurKernelX && this._blurKernelY) {\r\n const engine = (this.getScene()).getEngine();\r\n\r\n const textureType =\r\n engine.getCaps().textureFloatRender && engine.getCaps().textureFloatLinearFiltering ? Constants.TEXTURETYPE_FLOAT : Constants.TEXTURETYPE_HALF_FLOAT;\r\n\r\n this._blurX = new BlurPostProcess(\r\n \"horizontal blur\",\r\n new Vector2(1.0, 0),\r\n this._blurKernelX,\r\n this._blurRatio,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n textureType\r\n );\r\n this._blurX.autoClear = false;\r\n\r\n if (this._blurRatio === 1 && this.samples < 2 && this._texture) {\r\n this._blurX.inputTexture = this._renderTarget!;\r\n } else {\r\n this._blurX.alwaysForcePOT = true;\r\n }\r\n\r\n this._blurY = new BlurPostProcess(\r\n \"vertical blur\",\r\n new Vector2(0, 1.0),\r\n this._blurKernelY,\r\n this._blurRatio,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n textureType\r\n );\r\n this._blurY.autoClear = false;\r\n this._blurY.alwaysForcePOT = this._blurRatio !== 1;\r\n\r\n this.addPostProcess(this._blurX);\r\n this.addPostProcess(this._blurY);\r\n } else {\r\n if (this._blurY) {\r\n this.removePostProcess(this._blurY);\r\n this._blurY.dispose();\r\n this._blurY = null;\r\n }\r\n if (this._blurX) {\r\n this.removePostProcess(this._blurX);\r\n this._blurX.dispose();\r\n this._blurX = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clone the mirror texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): MirrorTexture {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const textureSize = this.getSize();\r\n const newTexture = new MirrorTexture(\r\n this.name,\r\n textureSize.width,\r\n scene,\r\n this._renderTargetOptions.generateMipMaps,\r\n this._renderTargetOptions.type,\r\n this._renderTargetOptions.samplingMode,\r\n this._renderTargetOptions.generateDepthBuffer\r\n );\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // Mirror Texture\r\n newTexture.mirrorPlane = this.mirrorPlane.clone();\r\n if (this.renderList) {\r\n newTexture.renderList = this.renderList.slice(0);\r\n }\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Serialize the texture to a JSON representation you could use in Parse later on\r\n * @returns the serialized JSON representation\r\n */\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.mirrorPlane = this.mirrorPlane.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose() {\r\n super.dispose();\r\n const scene = this.getScene();\r\n\r\n if (scene) {\r\n scene.imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingConfigChangeObserver);\r\n }\r\n this._sceneUBO?.dispose();\r\n }\r\n}\r\n\r\nTexture._CreateMirror = (name: string, renderTargetSize: number, scene: Scene, generateMipMaps: boolean): MirrorTexture => {\r\n return new MirrorTexture(name, renderTargetSize, scene, generateMipMaps);\r\n};\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { IInternalTextureLoader } from \"../../Materials/Textures/internalTextureLoader\";\r\nimport { LoadImage } from \"../../Misc/fileTools\";\r\nimport { RandomGUID } from \"../../Misc/guid\";\r\nimport type { IWebRequest } from \"../../Misc/interfaces/iWebRequest\";\r\nimport { Constants } from \"../constants\";\r\nimport type { DepthTextureCreationOptions } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport type { RenderTargetWrapper } from \"../renderTargetWrapper\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a depth stencil cube texture.\r\n * This is only available in WebGL 2.\r\n * @param size The size of face edge in the cube texture.\r\n * @param options The options defining the cube texture.\r\n * @param rtWrapper The render target wrapper for which the depth/stencil texture must be created\r\n * @returns The cube texture\r\n */\r\n _createDepthStencilCubeTexture(size: number, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture;\r\n\r\n /**\r\n * Creates a cube texture\r\n * @param rootUrl defines the url where the files to load is located\r\n * @param scene defines the current scene\r\n * @param files defines the list of files to load (1 per face)\r\n * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)\r\n * @param onLoad defines an optional callback raised when the texture is loaded\r\n * @param onError defines an optional callback raised if there is an issue to load the texture\r\n * @param format defines the format of the data\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n * @param createPolynomials if a polynomial sphere should be created for the cube texture\r\n * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness\r\n * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness\r\n * @param fallback defines texture to use while falling back when (compressed) texture file not found.\r\n * @param loaderOptions options to be passed to the loader\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createCubeTexture(\r\n rootUrl: string,\r\n scene: Nullable,\r\n files: Nullable,\r\n noMipmap: boolean | undefined,\r\n onLoad: Nullable<(data?: any) => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>,\r\n format: number | undefined,\r\n forcedExtension: any,\r\n createPolynomials: boolean,\r\n lodScale: number,\r\n lodOffset: number,\r\n fallback: Nullable,\r\n loaderOptions: any,\r\n useSRGBBuffer: boolean\r\n ): InternalTexture;\r\n\r\n /**\r\n * Creates a cube texture\r\n * @param rootUrl defines the url where the files to load is located\r\n * @param scene defines the current scene\r\n * @param files defines the list of files to load (1 per face)\r\n * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)\r\n * @param onLoad defines an optional callback raised when the texture is loaded\r\n * @param onError defines an optional callback raised if there is an issue to load the texture\r\n * @param format defines the format of the data\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createCubeTexture(\r\n rootUrl: string,\r\n scene: Nullable,\r\n files: Nullable,\r\n noMipmap: boolean,\r\n onLoad: Nullable<(data?: any) => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>,\r\n format: number | undefined,\r\n forcedExtension: any\r\n ): InternalTexture;\r\n\r\n /**\r\n * Creates a cube texture\r\n * @param rootUrl defines the url where the files to load is located\r\n * @param scene defines the current scene\r\n * @param files defines the list of files to load (1 per face)\r\n * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)\r\n * @param onLoad defines an optional callback raised when the texture is loaded\r\n * @param onError defines an optional callback raised if there is an issue to load the texture\r\n * @param format defines the format of the data\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n * @param createPolynomials if a polynomial sphere should be created for the cube texture\r\n * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness\r\n * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createCubeTexture(\r\n rootUrl: string,\r\n scene: Nullable,\r\n files: Nullable,\r\n noMipmap: boolean,\r\n onLoad: Nullable<(data?: any) => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>,\r\n format: number | undefined,\r\n forcedExtension: any,\r\n createPolynomials: boolean,\r\n lodScale: number,\r\n lodOffset: number\r\n ): InternalTexture;\r\n\r\n /** @internal */\r\n createCubeTextureBase(\r\n rootUrl: string,\r\n scene: Nullable,\r\n files: Nullable,\r\n noMipmap: boolean,\r\n onLoad: Nullable<(data?: any) => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>,\r\n format: number | undefined,\r\n forcedExtension: any,\r\n createPolynomials: boolean,\r\n lodScale: number,\r\n lodOffset: number,\r\n fallback: Nullable,\r\n beforeLoadCubeDataCallback: Nullable<(texture: InternalTexture, data: ArrayBufferView | ArrayBufferView[]) => void>,\r\n imageHandler: Nullable<(texture: InternalTexture, imgs: HTMLImageElement[] | ImageBitmap[]) => void>,\r\n useSRGBBuffer: boolean\r\n ): InternalTexture;\r\n\r\n /** @internal */\r\n _partialLoadFile(\r\n url: string,\r\n index: number,\r\n loadedFiles: ArrayBuffer[],\r\n onfinish: (files: ArrayBuffer[]) => void,\r\n onErrorCallBack: Nullable<(message?: string, exception?: any) => void>\r\n ): void;\r\n\r\n /** @internal */\r\n _cascadeLoadFiles(scene: Nullable, onfinish: (images: ArrayBuffer[]) => void, files: string[], onError: Nullable<(message?: string, exception?: any) => void>): void;\r\n\r\n /** @internal */\r\n _cascadeLoadImgs(\r\n scene: Nullable,\r\n texture: InternalTexture,\r\n onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[] | ImageBitmap[]) => void>,\r\n files: string[],\r\n onError: Nullable<(message?: string, exception?: any) => void>,\r\n mimeType?: string\r\n ): void;\r\n\r\n /** @internal */\r\n _partialLoadImg(\r\n url: string,\r\n index: number,\r\n loadedImages: HTMLImageElement[] | ImageBitmap[],\r\n scene: Nullable,\r\n texture: InternalTexture,\r\n onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[] | ImageBitmap[]) => void>,\r\n onErrorCallBack: Nullable<(message?: string, exception?: any) => void>,\r\n mimeType?: string\r\n ): void;\r\n\r\n /**\r\n * @internal\r\n */\r\n _setCubeMapTextureParams(texture: InternalTexture, loadMipmap: boolean, maxLevel?: number): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype._createDepthStencilCubeTexture = function (size: number, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture {\r\n const internalTexture = new InternalTexture(this, InternalTextureSource.DepthStencil);\r\n internalTexture.isCube = true;\r\n\r\n if (this.webGLVersion === 1) {\r\n Logger.Error(\"Depth cube texture is not supported by WebGL 1.\");\r\n return internalTexture;\r\n }\r\n\r\n const internalOptions = {\r\n bilinearFiltering: false,\r\n comparisonFunction: 0,\r\n generateStencil: false,\r\n ...options,\r\n };\r\n\r\n const gl = this._gl;\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, internalTexture, true);\r\n\r\n this._setupDepthStencilTexture(internalTexture, size, internalOptions.generateStencil, internalOptions.bilinearFiltering, internalOptions.comparisonFunction);\r\n\r\n rtWrapper._depthStencilTexture = internalTexture;\r\n rtWrapper._depthStencilTextureWithStencil = internalOptions.generateStencil;\r\n\r\n // Create the depth/stencil buffer\r\n for (let face = 0; face < 6; face++) {\r\n if (internalOptions.generateStencil) {\r\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, gl.DEPTH24_STENCIL8, size, size, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, null);\r\n } else {\r\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, gl.DEPTH_COMPONENT24, size, size, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);\r\n }\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n\r\n this._internalTexturesCache.push(internalTexture);\r\n\r\n return internalTexture;\r\n};\r\n\r\nThinEngine.prototype._partialLoadFile = function (\r\n url: string,\r\n index: number,\r\n loadedFiles: ArrayBuffer[],\r\n onfinish: (files: ArrayBuffer[]) => void,\r\n onErrorCallBack: Nullable<(message?: string, exception?: any) => void> = null\r\n): void {\r\n const onload = (data: ArrayBuffer) => {\r\n loadedFiles[index] = data;\r\n (loadedFiles)._internalCount++;\r\n\r\n if ((loadedFiles)._internalCount === 6) {\r\n onfinish(loadedFiles);\r\n }\r\n };\r\n\r\n const onerror = (request?: IWebRequest, exception?: any) => {\r\n if (onErrorCallBack && request) {\r\n onErrorCallBack(request.status + \" \" + request.statusText, exception);\r\n }\r\n };\r\n\r\n this._loadFile(url, onload as (data: string | ArrayBuffer) => void, undefined, undefined, true, onerror);\r\n};\r\n\r\nThinEngine.prototype._cascadeLoadFiles = function (\r\n scene: Nullable,\r\n onfinish: (images: ArrayBuffer[]) => void,\r\n files: string[],\r\n onError: Nullable<(message?: string, exception?: any) => void> = null\r\n): void {\r\n const loadedFiles: ArrayBuffer[] = [];\r\n (loadedFiles)._internalCount = 0;\r\n\r\n for (let index = 0; index < 6; index++) {\r\n this._partialLoadFile(files[index], index, loadedFiles, onfinish, onError);\r\n }\r\n};\r\n\r\nThinEngine.prototype._cascadeLoadImgs = function (\r\n scene: Nullable,\r\n texture: InternalTexture,\r\n onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[] | ImageBitmap[]) => void>,\r\n files: string[],\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n mimeType?: string\r\n) {\r\n const loadedImages: HTMLImageElement[] | ImageBitmap[] = [];\r\n (loadedImages)._internalCount = 0;\r\n\r\n for (let index = 0; index < 6; index++) {\r\n this._partialLoadImg(files[index], index, loadedImages, scene, texture, onfinish, onError, mimeType);\r\n }\r\n};\r\n\r\nThinEngine.prototype._partialLoadImg = function (\r\n url: string,\r\n index: number,\r\n loadedImages: HTMLImageElement[] | ImageBitmap[],\r\n scene: Nullable,\r\n texture: InternalTexture,\r\n onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[] | ImageBitmap[]) => void>,\r\n onErrorCallBack: Nullable<(message?: string, exception?: any) => void> = null,\r\n mimeType?: string\r\n) {\r\n const tokenPendingData = RandomGUID();\r\n\r\n const onload = (img: HTMLImageElement | ImageBitmap) => {\r\n loadedImages[index] = img;\r\n (loadedImages)._internalCount++;\r\n\r\n if (scene) {\r\n scene.removePendingData(tokenPendingData);\r\n }\r\n\r\n if ((loadedImages)._internalCount === 6 && onfinish) {\r\n onfinish(texture, loadedImages);\r\n }\r\n };\r\n\r\n const onerror = (message?: string, exception?: any) => {\r\n if (scene) {\r\n scene.removePendingData(tokenPendingData);\r\n }\r\n\r\n if (onErrorCallBack) {\r\n onErrorCallBack(message, exception);\r\n }\r\n };\r\n\r\n LoadImage(url, onload, onerror, scene ? scene.offlineProvider : null, mimeType);\r\n if (scene) {\r\n scene.addPendingData(tokenPendingData);\r\n }\r\n};\r\n\r\nThinEngine.prototype._setCubeMapTextureParams = function (texture: InternalTexture, loadMipmap: boolean, maxLevel?: number): void {\r\n const gl = this._gl;\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, loadMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n texture.samplingMode = loadMipmap ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : Constants.TEXTURE_LINEAR_LINEAR;\r\n\r\n if (loadMipmap && this.getCaps().textureMaxLevel && maxLevel !== undefined && maxLevel > 0) {\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAX_LEVEL, maxLevel);\r\n texture._maxLodLevel = maxLevel;\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n};\r\n\r\nThinEngine.prototype.createCubeTextureBase = function (\r\n rootUrl: string,\r\n scene: Nullable,\r\n files: Nullable,\r\n noMipmap?: boolean,\r\n onLoad: Nullable<(data?: any) => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n format?: number,\r\n forcedExtension: any = null,\r\n createPolynomials: boolean = false,\r\n lodScale: number = 0,\r\n lodOffset: number = 0,\r\n fallback: Nullable = null,\r\n beforeLoadCubeDataCallback: Nullable<(texture: InternalTexture, data: ArrayBufferView | ArrayBufferView[]) => void> = null,\r\n imageHandler: Nullable<(texture: InternalTexture, imgs: HTMLImageElement[] | ImageBitmap[]) => void> = null,\r\n useSRGBBuffer = false\r\n): InternalTexture {\r\n const texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube);\r\n texture.isCube = true;\r\n texture.url = rootUrl;\r\n texture.generateMipMaps = !noMipmap;\r\n texture._lodGenerationScale = lodScale;\r\n texture._lodGenerationOffset = lodOffset;\r\n texture._useSRGBBuffer = !!useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU || !!noMipmap);\r\n if (texture !== fallback) {\r\n texture.label = rootUrl.substring(0, 60); // default label, can be overriden by the caller\r\n }\r\n\r\n if (!this._doNotHandleContextLost) {\r\n texture._extension = forcedExtension;\r\n texture._files = files;\r\n }\r\n\r\n const originalRootUrl = rootUrl;\r\n if (this._transformTextureUrl && !fallback) {\r\n rootUrl = this._transformTextureUrl(rootUrl);\r\n }\r\n\r\n const rootUrlWithoutUriParams = rootUrl.split(\"?\")[0];\r\n const lastDot = rootUrlWithoutUriParams.lastIndexOf(\".\");\r\n const extension = forcedExtension ? forcedExtension : lastDot > -1 ? rootUrlWithoutUriParams.substring(lastDot).toLowerCase() : \"\";\r\n\r\n let loader: Nullable = null;\r\n for (const availableLoader of ThinEngine._TextureLoaders) {\r\n if (availableLoader.canLoad(extension)) {\r\n loader = availableLoader;\r\n break;\r\n }\r\n }\r\n\r\n const onInternalError = (request?: IWebRequest, exception?: any) => {\r\n if (rootUrl === originalRootUrl) {\r\n if (onError && request) {\r\n onError(request.status + \" \" + request.statusText, exception);\r\n }\r\n } else {\r\n // fall back to the original url if the transformed url fails to load\r\n Logger.Warn(`Failed to load ${rootUrl}, falling back to the ${originalRootUrl}`);\r\n this.createCubeTextureBase(\r\n originalRootUrl,\r\n scene,\r\n files,\r\n !!noMipmap,\r\n onLoad,\r\n onError,\r\n format,\r\n forcedExtension,\r\n createPolynomials,\r\n lodScale,\r\n lodOffset,\r\n texture,\r\n beforeLoadCubeDataCallback,\r\n imageHandler,\r\n useSRGBBuffer\r\n );\r\n }\r\n };\r\n\r\n if (loader) {\r\n const onloaddata = (data: ArrayBufferView | ArrayBufferView[]) => {\r\n if (beforeLoadCubeDataCallback) {\r\n beforeLoadCubeDataCallback(texture, data);\r\n }\r\n loader!.loadCubeData(data, texture, createPolynomials, onLoad, onError);\r\n };\r\n if (files && files.length === 6) {\r\n if (loader.supportCascades) {\r\n this._cascadeLoadFiles(scene, (images) => onloaddata(images.map((image) => new Uint8Array(image))), files, onError);\r\n } else {\r\n if (onError) {\r\n onError(\"Textures type does not support cascades.\");\r\n } else {\r\n Logger.Warn(\"Texture loader does not support cascades.\");\r\n }\r\n }\r\n } else {\r\n this._loadFile(rootUrl, (data) => onloaddata(new Uint8Array(data as ArrayBuffer)), undefined, undefined, true, onInternalError);\r\n }\r\n } else {\r\n if (!files) {\r\n throw new Error(\"Cannot load cubemap because files were not defined\");\r\n }\r\n\r\n this._cascadeLoadImgs(\r\n scene,\r\n texture,\r\n (texture: InternalTexture, imgs: HTMLImageElement[] | ImageBitmap[]) => {\r\n if (imageHandler) {\r\n imageHandler(texture, imgs);\r\n }\r\n },\r\n files,\r\n onError\r\n );\r\n }\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n return texture;\r\n};\r\n\r\nThinEngine.prototype.createCubeTexture = function (\r\n rootUrl: string,\r\n scene: Nullable,\r\n files: Nullable,\r\n noMipmap?: boolean,\r\n onLoad: Nullable<(data?: any) => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n format?: number,\r\n forcedExtension: any = null,\r\n createPolynomials: boolean = false,\r\n lodScale: number = 0,\r\n lodOffset: number = 0,\r\n fallback: Nullable = null,\r\n loaderOptions?: any,\r\n useSRGBBuffer = false\r\n): InternalTexture {\r\n const gl = this._gl;\r\n\r\n return this.createCubeTextureBase(\r\n rootUrl,\r\n scene,\r\n files,\r\n !!noMipmap,\r\n onLoad,\r\n onError,\r\n format,\r\n forcedExtension,\r\n createPolynomials,\r\n lodScale,\r\n lodOffset,\r\n fallback,\r\n (texture: InternalTexture) => this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true),\r\n (texture: InternalTexture, imgs: HTMLImageElement[] | ImageBitmap[]) => {\r\n const width = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(imgs[0].width, this._caps.maxCubemapTextureSize) : imgs[0].width;\r\n const height = width;\r\n\r\n const faces = [\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_X,\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_Y,\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_Z,\r\n gl.TEXTURE_CUBE_MAP_NEGATIVE_X,\r\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,\r\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,\r\n ];\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\r\n this._unpackFlipY(false);\r\n\r\n const internalFormat = format ? this._getInternalFormat(format, texture._useSRGBBuffer) : texture._useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : gl.RGBA;\r\n let texelFormat = format ? this._getInternalFormat(format) : gl.RGBA;\r\n\r\n if (texture._useSRGBBuffer && this.webGLVersion === 1) {\r\n texelFormat = internalFormat;\r\n }\r\n\r\n for (let index = 0; index < faces.length; index++) {\r\n if (imgs[index].width !== width || imgs[index].height !== height) {\r\n this._prepareWorkingCanvas();\r\n\r\n if (!this._workingCanvas || !this._workingContext) {\r\n Logger.Warn(\"Cannot create canvas to resize texture.\");\r\n return;\r\n }\r\n this._workingCanvas.width = width;\r\n this._workingCanvas.height = height;\r\n\r\n this._workingContext.drawImage(imgs[index], 0, 0, imgs[index].width, imgs[index].height, 0, 0, width, height);\r\n gl.texImage2D(faces[index], 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, this._workingCanvas as TexImageSource);\r\n } else {\r\n gl.texImage2D(faces[index], 0, internalFormat, texelFormat, gl.UNSIGNED_BYTE, imgs[index]);\r\n }\r\n }\r\n\r\n if (!noMipmap) {\r\n gl.generateMipmap(gl.TEXTURE_CUBE_MAP);\r\n }\r\n\r\n this._setCubeMapTextureParams(texture, !noMipmap);\r\n\r\n texture.width = width;\r\n texture.height = height;\r\n texture.isReady = true;\r\n if (format) {\r\n texture.format = format;\r\n }\r\n\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n },\r\n !!useSRGBBuffer\r\n );\r\n};\r\n","import { serialize, serializeAsMatrix, SerializationHelper, serializeAsVector3 } from \"../../Misc/decorators\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { GetClass, RegisterClass } from \"../../Misc/typeStore\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\n\r\nimport \"../../Engines/Extensions/engine.cubeTexture\";\r\nimport { Observable } from \"../../Misc/observable\";\r\n\r\n/**\r\n * Class for creating a cube texture\r\n */\r\nexport class CubeTexture extends BaseTexture {\r\n private _delayedOnLoad: Nullable<() => void>;\r\n private _delayedOnError: Nullable<(message?: string, exception?: any) => void>;\r\n private _lodScale: number = 0.8;\r\n private _lodOffset: number = 0;\r\n\r\n /**\r\n * Observable triggered once the texture has been loaded.\r\n */\r\n public onLoadObservable: Observable = new Observable();\r\n\r\n /**\r\n * The url of the texture\r\n */\r\n @serialize()\r\n public url: string;\r\n\r\n /**\r\n * Gets or sets the center of the bounding box associated with the cube texture.\r\n * It must define where the camera used to render the texture was set\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#using-local-cubemap-mode\r\n */\r\n @serializeAsVector3()\r\n public boundingBoxPosition = Vector3.Zero();\r\n\r\n private _boundingBoxSize: Vector3;\r\n\r\n /**\r\n * Gets or sets the size of the bounding box associated with the cube texture\r\n * When defined, the cubemap will switch to local mode\r\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\r\n * @example https://www.babylonjs-playground.com/#RNASML\r\n */\r\n public set boundingBoxSize(value: Vector3) {\r\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\r\n return;\r\n }\r\n this._boundingBoxSize = value;\r\n const scene = this.getScene();\r\n if (scene) {\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n }\r\n /**\r\n * Returns the bounding box size\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#using-local-cubemap-mode\r\n */\r\n @serializeAsVector3()\r\n public get boundingBoxSize(): Vector3 {\r\n return this._boundingBoxSize;\r\n }\r\n\r\n protected _rotationY: number = 0;\r\n\r\n /**\r\n * Sets texture matrix rotation angle around Y axis in radians.\r\n */\r\n @serialize(\"rotationY\")\r\n public set rotationY(value: number) {\r\n this._rotationY = value;\r\n this.setReflectionTextureMatrix(Matrix.RotationY(this._rotationY));\r\n }\r\n /**\r\n * Gets texture matrix rotation angle around Y axis radians.\r\n */\r\n public get rotationY(): number {\r\n return this._rotationY;\r\n }\r\n\r\n /**\r\n * Are mip maps generated for this texture or not.\r\n */\r\n public get noMipmap(): boolean {\r\n return this._noMipmap;\r\n }\r\n\r\n private _noMipmap: boolean;\r\n\r\n /** @internal */\r\n @serialize(\"files\")\r\n public _files: Nullable = null;\r\n\r\n @serialize(\"forcedExtension\")\r\n protected _forcedExtension: Nullable = null;\r\n\r\n /**\r\n * Gets the forced extension (if any)\r\n */\r\n public get forcedExtension(): Nullable {\r\n return this._forcedExtension;\r\n }\r\n\r\n @serialize(\"extensions\")\r\n private _extensions: Nullable = null;\r\n\r\n @serializeAsMatrix(\"textureMatrix\")\r\n private _textureMatrix: Matrix;\r\n\r\n @serializeAsMatrix(\"textureMatrixRefraction\")\r\n private _textureMatrixRefraction: Matrix = new Matrix();\r\n\r\n private _format: number;\r\n private _createPolynomials: boolean;\r\n private _loaderOptions: any;\r\n private _useSRGBBuffer?: boolean;\r\n\r\n /**\r\n * Creates a cube texture from an array of image urls\r\n * @param files defines an array of image urls\r\n * @param scene defines the hosting scene\r\n * @param noMipmap specifies if mip maps are not used\r\n * @returns a cube texture\r\n */\r\n public static CreateFromImages(files: string[], scene: Scene, noMipmap?: boolean): CubeTexture {\r\n let rootUrlKey = \"\";\r\n\r\n files.forEach((url) => (rootUrlKey += url));\r\n\r\n return new CubeTexture(rootUrlKey, scene, null, noMipmap, files);\r\n }\r\n\r\n /**\r\n * Creates and return a texture created from prefilterd data by tools like IBL Baker or Lys.\r\n * @param url defines the url of the prefiltered texture\r\n * @param scene defines the scene the texture is attached to\r\n * @param forcedExtension defines the extension of the file if different from the url\r\n * @param createPolynomials defines whether or not to create polynomial harmonics from the texture data if necessary\r\n * @returns the prefiltered texture\r\n */\r\n public static CreateFromPrefilteredData(url: string, scene: Scene, forcedExtension: any = null, createPolynomials: boolean = true) {\r\n const oldValue = scene.useDelayedTextureLoading;\r\n scene.useDelayedTextureLoading = false;\r\n\r\n const result = new CubeTexture(url, scene, null, false, null, null, null, undefined, true, forcedExtension, createPolynomials);\r\n\r\n scene.useDelayedTextureLoading = oldValue;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a cube texture to use with reflection for instance. It can be based upon dds or six images as well\r\n * as prefiltered data.\r\n * @param rootUrl defines the url of the texture or the root name of the six images\r\n * @param sceneOrEngine defines the scene or engine the texture is attached to\r\n * @param extensions defines the suffixes add to the picture name in case six images are in use like _px.jpg...\r\n * @param noMipmap defines if mipmaps should be created or not\r\n * @param files defines the six files to load for the different faces in that order: px, py, pz, nx, ny, nz\r\n * @param onLoad defines a callback triggered at the end of the file load if no errors occurred\r\n * @param onError defines a callback triggered in case of error during load\r\n * @param format defines the internal format to use for the texture once loaded\r\n * @param prefiltered defines whether or not the texture is created from prefiltered data\r\n * @param forcedExtension defines the extensions to use (force a special type of file to load) in case it is different from the file name\r\n * @param createPolynomials defines whether or not to create polynomial harmonics from the texture data if necessary\r\n * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness\r\n * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness\r\n * @param loaderOptions options to be passed to the loader\r\n * @param useSRGBBuffer Defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU) (default: false)\r\n * @returns the cube texture\r\n */\r\n constructor(\r\n rootUrl: string,\r\n sceneOrEngine: Scene | ThinEngine,\r\n extensions: Nullable = null,\r\n noMipmap: boolean = false,\r\n files: Nullable = null,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n format: number = Constants.TEXTUREFORMAT_RGBA,\r\n prefiltered = false,\r\n forcedExtension: any = null,\r\n createPolynomials: boolean = false,\r\n lodScale: number = 0.8,\r\n lodOffset: number = 0,\r\n loaderOptions?: any,\r\n useSRGBBuffer?: boolean\r\n ) {\r\n super(sceneOrEngine);\r\n\r\n this.name = rootUrl;\r\n this.url = rootUrl;\r\n this._noMipmap = noMipmap;\r\n this.hasAlpha = false;\r\n this._format = format;\r\n this.isCube = true;\r\n this._textureMatrix = Matrix.Identity();\r\n this._createPolynomials = createPolynomials;\r\n this.coordinatesMode = Texture.CUBIC_MODE;\r\n this._extensions = extensions;\r\n this._files = files;\r\n this._forcedExtension = forcedExtension;\r\n this._loaderOptions = loaderOptions;\r\n this._useSRGBBuffer = useSRGBBuffer;\r\n this._lodScale = lodScale;\r\n this._lodOffset = lodOffset;\r\n\r\n if (!rootUrl && !files) {\r\n return;\r\n }\r\n\r\n this.updateURL(rootUrl, forcedExtension, onLoad, prefiltered, onError, extensions, this.getScene()?.useDelayedTextureLoading, files);\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"CubeTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"CubeTexture\";\r\n }\r\n\r\n /**\r\n * Update the url (and optional buffer) of this texture if url was null during construction.\r\n * @param url the url of the texture\r\n * @param forcedExtension defines the extension to use\r\n * @param onLoad callback called when the texture is loaded (defaults to null)\r\n * @param prefiltered Defines whether the updated texture is prefiltered or not\r\n * @param onError callback called if there was an error during the loading process (defaults to null)\r\n * @param extensions defines the suffixes add to the picture name in case six images are in use like _px.jpg...\r\n * @param delayLoad defines if the texture should be loaded now (false by default)\r\n * @param files defines the six files to load for the different faces in that order: px, py, pz, nx, ny, nz\r\n */\r\n public updateURL(\r\n url: string,\r\n forcedExtension?: string,\r\n onLoad: Nullable<() => void> = null,\r\n prefiltered: boolean = false,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n extensions: Nullable = null,\r\n delayLoad = false,\r\n files: Nullable = null\r\n ): void {\r\n if (!this.name || this.name.startsWith(\"data:\")) {\r\n this.name = url;\r\n }\r\n this.url = url;\r\n\r\n if (forcedExtension) {\r\n this._forcedExtension = forcedExtension;\r\n }\r\n\r\n const lastDot = url.lastIndexOf(\".\");\r\n const extension = forcedExtension ? forcedExtension : lastDot > -1 ? url.substring(lastDot).toLowerCase() : \"\";\r\n const isDDS = extension.indexOf(\".dds\") === 0;\r\n const isEnv = extension.indexOf(\".env\") === 0;\r\n const isBasis = extension.indexOf(\".basis\") === 0;\r\n\r\n if (isEnv) {\r\n this.gammaSpace = false;\r\n this._prefiltered = false;\r\n this.anisotropicFilteringLevel = 1;\r\n } else {\r\n this._prefiltered = prefiltered;\r\n\r\n if (prefiltered) {\r\n this.gammaSpace = false;\r\n this.anisotropicFilteringLevel = 1;\r\n }\r\n }\r\n\r\n if (files) {\r\n this._files = files;\r\n } else {\r\n if (!isBasis && !isEnv && !isDDS && !extensions) {\r\n extensions = [\"_px.jpg\", \"_py.jpg\", \"_pz.jpg\", \"_nx.jpg\", \"_ny.jpg\", \"_nz.jpg\"];\r\n }\r\n\r\n this._files = this._files || [];\r\n this._files.length = 0;\r\n\r\n if (extensions) {\r\n for (let index = 0; index < extensions.length; index++) {\r\n this._files.push(url + extensions[index]);\r\n }\r\n this._extensions = extensions;\r\n }\r\n }\r\n\r\n if (delayLoad) {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n this._delayedOnLoad = onLoad;\r\n this._delayedOnError = onError;\r\n } else {\r\n this._loadTexture(onLoad, onError);\r\n }\r\n }\r\n\r\n /**\r\n * Delays loading of the cube texture\r\n * @param forcedExtension defines the extension to use\r\n */\r\n public delayLoad(forcedExtension?: string): void {\r\n if (this.delayLoadState !== Constants.DELAYLOADSTATE_NOTLOADED) {\r\n return;\r\n }\r\n if (forcedExtension) {\r\n this._forcedExtension = forcedExtension;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._loadTexture(this._delayedOnLoad, this._delayedOnError);\r\n }\r\n\r\n /**\r\n * Returns the reflection texture matrix\r\n * @returns the reflection texture matrix\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n return this._textureMatrix;\r\n }\r\n\r\n /**\r\n * Sets the reflection texture matrix\r\n * @param value Reflection texture matrix\r\n */\r\n public setReflectionTextureMatrix(value: Matrix): void {\r\n if (value.updateFlag === this._textureMatrix.updateFlag) {\r\n return;\r\n }\r\n\r\n if (value.isIdentity() !== this._textureMatrix.isIdentity()) {\r\n this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);\r\n }\r\n\r\n this._textureMatrix = value;\r\n\r\n if (!this.getScene()?.useRightHandedSystem) {\r\n return;\r\n }\r\n\r\n const scale = TmpVectors.Vector3[0];\r\n const quat = TmpVectors.Quaternion[0];\r\n const trans = TmpVectors.Vector3[1];\r\n\r\n this._textureMatrix.decompose(scale, quat, trans);\r\n\r\n quat.z *= -1; // these two operations correspond to negating the x and y euler angles\r\n quat.w *= -1;\r\n\r\n Matrix.ComposeToRef(scale, quat, trans, this._textureMatrixRefraction);\r\n }\r\n\r\n /**\r\n * Gets a suitable rotate/transform matrix when the texture is used for refraction.\r\n * There's a separate function from getReflectionTextureMatrix because refraction requires a special configuration of the matrix in right-handed mode.\r\n * @returns The refraction matrix\r\n */\r\n public getRefractionTextureMatrix(): Matrix {\r\n return this.getScene()?.useRightHandedSystem ? this._textureMatrixRefraction : this._textureMatrix;\r\n }\r\n\r\n private _loadTexture(onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null) {\r\n const scene = this.getScene();\r\n const oldTexture = this._texture;\r\n this._texture = this._getFromCache(this.url, this._noMipmap, undefined, undefined, this._useSRGBBuffer, this.isCube);\r\n\r\n const onLoadProcessing = () => {\r\n this.onLoadObservable.notifyObservers(this);\r\n if (oldTexture) {\r\n oldTexture.dispose();\r\n this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n };\r\n\r\n const errorHandler = (message?: string, exception?: any) => {\r\n this._loadingError = true;\r\n this._errorObject = { message, exception };\r\n if (onError) {\r\n onError(message, exception);\r\n }\r\n Texture.OnTextureLoadErrorObservable.notifyObservers(this);\r\n };\r\n\r\n if (!this._texture) {\r\n if (this._prefiltered) {\r\n this._texture = this._getEngine()!.createPrefilteredCubeTexture(\r\n this.url,\r\n scene,\r\n this._lodScale,\r\n this._lodOffset,\r\n onLoad,\r\n errorHandler,\r\n this._format,\r\n this._forcedExtension,\r\n this._createPolynomials\r\n );\r\n } else {\r\n this._texture = this._getEngine()!.createCubeTexture(\r\n this.url,\r\n scene,\r\n this._files,\r\n this._noMipmap,\r\n onLoad,\r\n errorHandler,\r\n this._format,\r\n this._forcedExtension,\r\n false,\r\n this._lodScale,\r\n this._lodOffset,\r\n null,\r\n this._loaderOptions,\r\n !!this._useSRGBBuffer\r\n );\r\n }\r\n\r\n this._texture?.onLoadedObservable.add(() => this.onLoadObservable.notifyObservers(this));\r\n } else {\r\n if (this._texture.isReady) {\r\n Tools.SetImmediate(() => onLoadProcessing());\r\n } else {\r\n this._texture.onLoadedObservable.add(() => onLoadProcessing());\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Parses text to create a cube texture\r\n * @param parsedTexture define the serialized text to read from\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root url of the cube texture\r\n * @returns a cube texture\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): CubeTexture {\r\n const texture = SerializationHelper.Parse(\r\n () => {\r\n let prefiltered: boolean = false;\r\n if (parsedTexture.prefiltered) {\r\n prefiltered = parsedTexture.prefiltered;\r\n }\r\n return new CubeTexture(\r\n rootUrl + (parsedTexture.url ?? parsedTexture.name),\r\n scene,\r\n parsedTexture.extensions,\r\n false,\r\n parsedTexture.files || null,\r\n null,\r\n null,\r\n undefined,\r\n prefiltered,\r\n parsedTexture.forcedExtension\r\n );\r\n },\r\n parsedTexture,\r\n scene\r\n );\r\n\r\n // Local Cubemaps\r\n if (parsedTexture.boundingBoxPosition) {\r\n texture.boundingBoxPosition = Vector3.FromArray(parsedTexture.boundingBoxPosition);\r\n }\r\n if (parsedTexture.boundingBoxSize) {\r\n texture.boundingBoxSize = Vector3.FromArray(parsedTexture.boundingBoxSize);\r\n }\r\n\r\n // Animations\r\n if (parsedTexture.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedTexture.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n texture.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n }\r\n\r\n return texture;\r\n }\r\n\r\n /**\r\n * Makes a clone, or deep copy, of the cube texture\r\n * @returns a new cube texture\r\n */\r\n public clone(): CubeTexture {\r\n let uniqueId = 0;\r\n\r\n const newCubeTexture = SerializationHelper.Clone(() => {\r\n const cubeTexture = new CubeTexture(this.url, this.getScene() || this._getEngine()!, this._extensions, this._noMipmap, this._files);\r\n uniqueId = cubeTexture.uniqueId;\r\n\r\n return cubeTexture;\r\n }, this);\r\n\r\n newCubeTexture.uniqueId = uniqueId;\r\n\r\n return newCubeTexture;\r\n }\r\n}\r\n\r\nTexture._CubeTextureParser = CubeTexture.Parse;\r\n// Some exporters relies on Tools.Instantiate\r\nRegisterClass(\"BABYLON.CubeTexture\", CubeTexture);\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"backgroundFragmentDeclaration\";\nconst shader = `uniform vec4 vEyePosition;uniform vec4 vPrimaryColor;\n#ifdef USEHIGHLIGHTANDSHADOWCOLORS\nuniform vec4 vPrimaryColorShadow;\n#endif\nuniform float shadowLevel;uniform float alpha;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const backgroundFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./sceneUboDeclaration\";\n\nconst name = \"backgroundUboDeclaration\";\nconst shader = `layout(std140,column_major) uniform;uniform Material\n{uniform vec4 vPrimaryColor;uniform vec4 vPrimaryColorShadow;uniform vec2 vDiffuseInfos;uniform vec2 vReflectionInfos;uniform mat4 diffuseMatrix;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;uniform float fFovMultiplier;uniform float pointSize;uniform float shadowLevel;uniform float alpha;\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n};\n#include\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const backgroundUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/backgroundFragmentDeclaration\";\nimport \"./ShadersInclude/backgroundUboDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/reflectionFunction\";\nimport \"./ShadersInclude/imageProcessingDeclaration\";\nimport \"./ShadersInclude/lightFragmentDeclaration\";\nimport \"./ShadersInclude/lightUboDeclaration\";\nimport \"./ShadersInclude/lightsFragmentFunctions\";\nimport \"./ShadersInclude/shadowsFragmentFunctions\";\nimport \"./ShadersInclude/imageProcessingFunctions\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/lightFragment\";\nimport \"./ShadersInclude/fogFragment\";\n\nconst name = \"backgroundPixelShader\";\nconst shader = `#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n#include\n#define RECIPROCAL_PI2 0.15915494\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV==1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV==2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;uniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include\n#endif\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#include\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{float weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);return reflectance0+weight*(reflectance90-reflectance0)*pow5(saturate(1.0-VdotN));}\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\nfloat shadow=1.;float globalShadow=0.;float shadowLightCount=0.;\n#include[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n#ifndef BACKMAT_SHADOWONLY\nvec4 reflectionColor=vec4(1.,1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;reflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD);\n#else\nfloat lodReflectionNormalized=saturate(reflectionLOD);float lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;vec4 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords);if(lodReflectionNormalizedDoubled<1.0){reflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords),\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);} else {reflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords),\nlodReflectionNormalizedDoubled-1.0\n);}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);reflectionColor=reflectionSample;\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor.rgb=toLinearSpace(reflectionColor.rgb);\n#endif\n#ifdef REFLECTIONBGR\nreflectionColor.rgb=reflectionColor.bgr;\n#endif\nreflectionColor.rgb*=vReflectionInfos.x;\n#endif\nvec3 diffuseColor=vec3(1.,1.,1.);float finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor.rgb*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\n#ifdef USEHIGHLIGHTANDSHADOWCOLORS\nvec3 mainColor=mix(vPrimaryColorShadow.rgb,vPrimaryColor.rgb,colorBase);\n#else\nvec3 mainColor=vPrimaryColor.rgb;\n#endif\nvec3 finalColor=colorBase*mainColor;\n#endif\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;vec3 reflectionReflectance0=vReflectionControl.yyy;vec3 reflectionReflectance90=vReflectionControl.zzz;float VdotN=dot(normalize(vEyePosition.xyz),normalW);vec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(saturate(VdotN),reflectionReflectance0,reflectionReflectance90,1.0);reflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-saturate(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w);reflectionDistanceFalloff*=reflectionDistanceFalloff;reflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor.rgb,saturate(reflectionAmount));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition.xyz-vBackgroundCenter));const float startAngle=0.1;float fadeFactor=saturate(viewAngleToFloor/startAngle);finalAlpha*=fadeFactor*fadeFactor;\n#endif\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\nvec4 color=vec4(finalColor,finalAlpha);\n#else\nvec4 color=vec4(vPrimaryColor.rgb,(1.0-clamp(globalShadow,0.,1.))*alpha);\n#endif\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n#if !defined(SKIPFINALCOLORCLAMP)\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#endif\n#else\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\ncolor.rgb*=color.a;\n#endif\n#ifdef NOISE\ncolor.rgb+=dither(vPositionW.xy,0.5);color=max(color,0.0);\n#endif\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const backgroundPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"backgroundVertexDeclaration\";\nconst shader = `uniform mat4 view;uniform mat4 viewProjection;uniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;uniform float fFovMultiplier;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const backgroundVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/backgroundVertexDeclaration\";\nimport \"./ShadersInclude/backgroundUboDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/fogVertexDeclaration\";\nimport \"./ShadersInclude/lightVxFragmentDeclaration\";\nimport \"./ShadersInclude/lightVxUboDeclaration\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/clipPlaneVertex\";\nimport \"./ShadersInclude/fogVertex\";\nimport \"./ShadersInclude/shadowsVertex\";\n\nconst name = \"backgroundVertexShader\";\nconst shader = `precision highp float;\n#include<__decl__backgroundVertex>\n#include\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n#include\n#include\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV==0\nvarying vec2 vDiffuseUV;\n#endif\n#include\n#include\n#include<__decl__lightVxFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif\n#include\n#include\n#include\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*finalWorld*vec4(position,1.0);} else {gl_Position=viewProjectionR*finalWorld*vec4(position,1.0);}\n#else\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#endif\nvec4 worldPos=finalWorld*vec4(position,1.0);vPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#ifdef EQUIRECTANGULAR_RELFECTION_FOV\nmat3 screenToWorld=inverseMat3(mat3(finalWorld*viewProjection));vec3 segment=mix(vDirectionW,screenToWorld*vec3(0.0,0.0,1.0),abs(fFovMultiplier-1.0));if (fFovMultiplier<=1.0) {vDirectionW=normalize(segment);} else {vDirectionW=normalize(vDirectionW+(vDirectionW-segment));}\n#endif\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV==0\nif (vDiffuseInfos.x==0.)\n{vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));}\nelse\n{vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));}\n#endif\n#include\n#include\n#include[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const backgroundVertexShader = { name, shader };\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport {\r\n SerializationHelper,\r\n serialize,\r\n serializeAsColor3,\r\n expandToProperty,\r\n serializeAsTexture,\r\n serializeAsVector3,\r\n serializeAsImageProcessingConfiguration,\r\n} from \"../../Misc/decorators\";\r\nimport { SmartArray } from \"../../Misc/smartArray\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable, int, float } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, Vector4 } from \"../../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { IEffectCreationOptions } from \"../../Materials/effect\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport { MaterialDefines } from \"../../Materials/materialDefines\";\r\nimport { PushMaterial } from \"../../Materials/pushMaterial\";\r\nimport type { ColorCurves } from \"../../Materials/colorCurves\";\r\nimport type { IImageProcessingConfigurationDefines } from \"../../Materials/imageProcessingConfiguration\";\r\nimport { ImageProcessingConfiguration } from \"../../Materials/imageProcessingConfiguration\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { IShadowLight } from \"../../Lights/shadowLight\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { RegisterClass } from \"../../Misc/typeStore\";\r\nimport { MaterialFlags } from \"../materialFlags\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\n\r\nimport \"../../Shaders/background.fragment\";\r\nimport \"../../Shaders/background.vertex\";\r\nimport { EffectFallbacks } from \"../effectFallbacks\";\r\nimport { addClipPlaneUniforms, bindClipPlane } from \"../clipPlaneMaterialHelper\";\r\n\r\n/**\r\n * Background material defines definition.\r\n * @internal Mainly internal Use\r\n */\r\nclass BackgroundMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {\r\n /**\r\n * True if the diffuse texture is in use.\r\n */\r\n public DIFFUSE = false;\r\n\r\n /**\r\n * The direct UV channel to use.\r\n */\r\n public DIFFUSEDIRECTUV = 0;\r\n\r\n /**\r\n * True if the diffuse texture is in gamma space.\r\n */\r\n public GAMMADIFFUSE = false;\r\n\r\n /**\r\n * True if the diffuse texture has opacity in the alpha channel.\r\n */\r\n public DIFFUSEHASALPHA = false;\r\n\r\n /**\r\n * True if you want the material to fade to transparent at grazing angle.\r\n */\r\n public OPACITYFRESNEL = false;\r\n\r\n /**\r\n * True if an extra blur needs to be added in the reflection.\r\n */\r\n public REFLECTIONBLUR = false;\r\n\r\n /**\r\n * True if you want the material to fade to reflection at grazing angle.\r\n */\r\n public REFLECTIONFRESNEL = false;\r\n\r\n /**\r\n * True if you want the material to falloff as far as you move away from the scene center.\r\n */\r\n public REFLECTIONFALLOFF = false;\r\n\r\n /**\r\n * False if the current Webgl implementation does not support the texture lod extension.\r\n */\r\n public TEXTURELODSUPPORT = false;\r\n\r\n /**\r\n * True to ensure the data are premultiplied.\r\n */\r\n public PREMULTIPLYALPHA = false;\r\n\r\n /**\r\n * True if the texture contains cooked RGB values and not gray scaled multipliers.\r\n */\r\n public USERGBCOLOR = false;\r\n\r\n /**\r\n * True if highlight and shadow levels have been specified. It can help ensuring the main perceived color\r\n * stays aligned with the desired configuration.\r\n */\r\n public USEHIGHLIGHTANDSHADOWCOLORS = false;\r\n\r\n /**\r\n * True if only shadows must be rendered\r\n */\r\n public BACKMAT_SHADOWONLY = false;\r\n\r\n /**\r\n * True to add noise in order to reduce the banding effect.\r\n */\r\n public NOISE = false;\r\n\r\n /**\r\n * is the reflection texture in BGR color scheme?\r\n * Mainly used to solve a bug in ios10 video tag\r\n */\r\n public REFLECTIONBGR = false;\r\n\r\n public IMAGEPROCESSING = false;\r\n public VIGNETTE = false;\r\n public VIGNETTEBLENDMODEMULTIPLY = false;\r\n public VIGNETTEBLENDMODEOPAQUE = false;\r\n public TONEMAPPING = false;\r\n public TONEMAPPING_ACES = false;\r\n public CONTRAST = false;\r\n public COLORCURVES = false;\r\n public COLORGRADING = false;\r\n public COLORGRADING3D = false;\r\n public SAMPLER3DGREENDEPTH = false;\r\n public SAMPLER3DBGRMAP = false;\r\n public DITHER = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n public EXPOSURE = false;\r\n public MULTIVIEW = false;\r\n\r\n // Reflection.\r\n public REFLECTION = false;\r\n public REFLECTIONMAP_3D = false;\r\n public REFLECTIONMAP_SPHERICAL = false;\r\n public REFLECTIONMAP_PLANAR = false;\r\n public REFLECTIONMAP_CUBIC = false;\r\n public REFLECTIONMAP_PROJECTION = false;\r\n public REFLECTIONMAP_SKYBOX = false;\r\n public REFLECTIONMAP_EXPLICIT = false;\r\n public REFLECTIONMAP_EQUIRECTANGULAR = false;\r\n public REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\r\n public REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\r\n public INVERTCUBICMAP = false;\r\n public REFLECTIONMAP_OPPOSITEZ = false;\r\n public LODINREFLECTIONALPHA = false;\r\n public GAMMAREFLECTION = false;\r\n public RGBDREFLECTION = false;\r\n public EQUIRECTANGULAR_RELFECTION_FOV = false;\r\n\r\n // Default BJS.\r\n public MAINUV1 = false;\r\n public MAINUV2 = false;\r\n public UV1 = false;\r\n public UV2 = false;\r\n public CLIPPLANE = false;\r\n public CLIPPLANE2 = false;\r\n public CLIPPLANE3 = false;\r\n public CLIPPLANE4 = false;\r\n public CLIPPLANE5 = false;\r\n public CLIPPLANE6 = false;\r\n public POINTSIZE = false;\r\n public FOG = false;\r\n public NORMAL = false;\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public INSTANCES = false;\r\n public SHADOWFLOAT = false;\r\n public LOGARITHMICDEPTH = false;\r\n public NONUNIFORMSCALING = false;\r\n public ALPHATEST = false;\r\n\r\n /**\r\n * Constructor of the defines.\r\n */\r\n constructor() {\r\n super();\r\n this.rebuild();\r\n }\r\n}\r\n\r\n/**\r\n * Background material used to create an efficient environment around your scene.\r\n */\r\nexport class BackgroundMaterial extends PushMaterial {\r\n /**\r\n * Standard reflectance value at parallel view angle.\r\n */\r\n public static StandardReflectance0 = 0.05;\r\n\r\n /**\r\n * Standard reflectance value at grazing angle.\r\n */\r\n public static StandardReflectance90 = 0.5;\r\n\r\n @serializeAsColor3()\r\n protected _primaryColor: Color3;\r\n /**\r\n * Key light Color (multiply against the environment texture)\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public primaryColor = Color3.White();\r\n\r\n @serializeAsColor3()\r\n protected __perceptualColor: Nullable;\r\n /**\r\n * Experimental Internal Use Only.\r\n *\r\n * Key light Color in \"perceptual value\" meaning the color you would like to see on screen.\r\n * This acts as a helper to set the primary color to a more \"human friendly\" value.\r\n * Conversion to linear space as well as exposure and tone mapping correction will be applied to keep the\r\n * output color as close as possible from the chosen value.\r\n * (This does not account for contrast color grading and color curves as they are considered post effect and not directly\r\n * part of lighting setup.)\r\n */\r\n public get _perceptualColor(): Nullable {\r\n return this.__perceptualColor;\r\n }\r\n public set _perceptualColor(value: Nullable) {\r\n this.__perceptualColor = value;\r\n this._computePrimaryColorFromPerceptualColor();\r\n this._markAllSubMeshesAsLightsDirty();\r\n }\r\n\r\n @serialize()\r\n protected _primaryColorShadowLevel: float = 0;\r\n /**\r\n * Defines the level of the shadows (dark area of the reflection map) in order to help scaling the colors.\r\n * The color opposite to the primary color is used at the level chosen to define what the black area would look.\r\n */\r\n public get primaryColorShadowLevel(): float {\r\n return this._primaryColorShadowLevel;\r\n }\r\n public set primaryColorShadowLevel(value: float) {\r\n this._primaryColorShadowLevel = value;\r\n this._computePrimaryColors();\r\n this._markAllSubMeshesAsLightsDirty();\r\n }\r\n\r\n @serialize()\r\n protected _primaryColorHighlightLevel: float = 0;\r\n /**\r\n * Defines the level of the highlights (highlight area of the reflection map) in order to help scaling the colors.\r\n * The primary color is used at the level chosen to define what the white area would look.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public get primaryColorHighlightLevel(): float {\r\n return this._primaryColorHighlightLevel;\r\n }\r\n public set primaryColorHighlightLevel(value: float) {\r\n this._primaryColorHighlightLevel = value;\r\n this._computePrimaryColors();\r\n this._markAllSubMeshesAsLightsDirty();\r\n }\r\n\r\n @serializeAsTexture()\r\n protected _reflectionTexture: Nullable;\r\n /**\r\n * Reflection Texture used in the material.\r\n * Should be author in a specific way for the best result (refer to the documentation).\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionTexture: Nullable = null;\r\n\r\n @serialize()\r\n protected _reflectionBlur: float;\r\n /**\r\n * Reflection Texture level of blur.\r\n *\r\n * Can be use to reuse an existing HDR Texture and target a specific LOD to prevent authoring the\r\n * texture twice.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionBlur: float = 0;\r\n\r\n @serializeAsTexture()\r\n protected _diffuseTexture: Nullable;\r\n /**\r\n * Diffuse Texture used in the material.\r\n * Should be author in a specific way for the best result (refer to the documentation).\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public diffuseTexture: Nullable = null;\r\n\r\n protected _shadowLights: Nullable = null;\r\n /**\r\n * Specify the list of lights casting shadow on the material.\r\n * All scene shadow lights will be included if null.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public shadowLights: Nullable = null;\r\n\r\n @serialize()\r\n protected _shadowLevel: float;\r\n /**\r\n * Helps adjusting the shadow to a softer level if required.\r\n * 0 means black shadows and 1 means no shadows.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public shadowLevel: float = 0;\r\n\r\n @serializeAsVector3()\r\n protected _sceneCenter: Vector3;\r\n /**\r\n * In case of opacity Fresnel or reflection falloff, this is use as a scene center.\r\n * It is usually zero but might be interesting to modify according to your setup.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public sceneCenter: Vector3 = Vector3.Zero();\r\n\r\n @serialize()\r\n protected _opacityFresnel: boolean;\r\n /**\r\n * This helps specifying that the material is falling off to the sky box at grazing angle.\r\n * This helps ensuring a nice transition when the camera goes under the ground.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public opacityFresnel: boolean = true;\r\n\r\n @serialize()\r\n protected _reflectionFresnel: boolean;\r\n /**\r\n * This helps specifying that the material is falling off from diffuse to the reflection texture at grazing angle.\r\n * This helps adding a mirror texture on the ground.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionFresnel: boolean = false;\r\n\r\n @serialize()\r\n protected _reflectionFalloffDistance: number;\r\n /**\r\n * This helps specifying the falloff radius off the reflection texture from the sceneCenter.\r\n * This helps adding a nice falloff effect to the reflection if used as a mirror for instance.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionFalloffDistance: number = 0.0;\r\n\r\n @serialize()\r\n protected _reflectionAmount: number;\r\n /**\r\n * This specifies the weight of the reflection against the background in case of reflection Fresnel.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionAmount: number = 1.0;\r\n\r\n @serialize()\r\n protected _reflectionReflectance0: number;\r\n /**\r\n * This specifies the weight of the reflection at grazing angle.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionReflectance0: number = 0.05;\r\n\r\n @serialize()\r\n protected _reflectionReflectance90: number;\r\n /**\r\n * This specifies the weight of the reflection at a perpendicular point of view.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public reflectionReflectance90: number = 0.5;\r\n\r\n /**\r\n * Sets the reflection reflectance fresnel values according to the default standard\r\n * empirically know to work well :-)\r\n */\r\n public set reflectionStandardFresnelWeight(value: number) {\r\n let reflectionWeight = value;\r\n\r\n if (reflectionWeight < 0.5) {\r\n reflectionWeight = reflectionWeight * 2.0;\r\n this.reflectionReflectance0 = BackgroundMaterial.StandardReflectance0 * reflectionWeight;\r\n this.reflectionReflectance90 = BackgroundMaterial.StandardReflectance90 * reflectionWeight;\r\n } else {\r\n reflectionWeight = reflectionWeight * 2.0 - 1.0;\r\n this.reflectionReflectance0 = BackgroundMaterial.StandardReflectance0 + (1.0 - BackgroundMaterial.StandardReflectance0) * reflectionWeight;\r\n this.reflectionReflectance90 = BackgroundMaterial.StandardReflectance90 + (1.0 - BackgroundMaterial.StandardReflectance90) * reflectionWeight;\r\n }\r\n }\r\n\r\n @serialize()\r\n protected _useRGBColor: boolean;\r\n /**\r\n * Helps to directly use the maps channels instead of their level.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public useRGBColor: boolean = true;\r\n\r\n @serialize()\r\n protected _enableNoise: boolean;\r\n /**\r\n * This helps reducing the banding effect that could occur on the background.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public enableNoise: boolean = false;\r\n\r\n /**\r\n * The current fov(field of view) multiplier, 0.0 - 2.0. Defaults to 1.0. Lower values \"zoom in\" and higher values \"zoom out\".\r\n * Best used when trying to implement visual zoom effects like fish-eye or binoculars while not adjusting camera fov.\r\n * Recommended to be keep at 1.0 except for special cases.\r\n */\r\n public get fovMultiplier(): number {\r\n return this._fovMultiplier;\r\n }\r\n public set fovMultiplier(value: number) {\r\n if (isNaN(value)) {\r\n value = 1.0;\r\n }\r\n this._fovMultiplier = Math.max(0.0, Math.min(2.0, value));\r\n }\r\n private _fovMultiplier: float = 1.0;\r\n\r\n /**\r\n * Enable the FOV adjustment feature controlled by fovMultiplier.\r\n */\r\n public useEquirectangularFOV: boolean = false;\r\n\r\n @serialize()\r\n private _maxSimultaneousLights: int = 4;\r\n /**\r\n * Number of Simultaneous lights allowed on the material.\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public maxSimultaneousLights: int = 4;\r\n\r\n @serialize()\r\n private _shadowOnly: boolean = false;\r\n /**\r\n * Make the material only render shadows\r\n */\r\n @expandToProperty(\"_markAllSubMeshesAsLightsDirty\")\r\n public shadowOnly: boolean = false;\r\n\r\n /**\r\n * Default configuration related to image processing available in the Background Material.\r\n */\r\n @serializeAsImageProcessingConfiguration()\r\n protected _imageProcessingConfiguration: ImageProcessingConfiguration;\r\n\r\n /**\r\n * Keep track of the image processing observer to allow dispose and replace.\r\n */\r\n private _imageProcessingObserver: Nullable> = null;\r\n\r\n /**\r\n * Attaches a new image processing configuration to the PBR Material.\r\n * @param configuration (if null the scene configuration will be use)\r\n */\r\n protected _attachImageProcessingConfiguration(configuration: Nullable): void {\r\n if (configuration === this._imageProcessingConfiguration) {\r\n return;\r\n }\r\n\r\n // Detaches observer.\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n // Pick the scene configuration if needed.\r\n if (!configuration) {\r\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\r\n } else {\r\n this._imageProcessingConfiguration = configuration;\r\n }\r\n\r\n // Attaches observer.\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\r\n this._computePrimaryColorFromPerceptualColor();\r\n this._markAllSubMeshesAsImageProcessingDirty();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Gets the image processing configuration used either in this material.\r\n */\r\n public get imageProcessingConfiguration(): Nullable {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n /**\r\n * Sets the Default image processing configuration used either in the this material.\r\n *\r\n * If sets to null, the scene one is in use.\r\n */\r\n public set imageProcessingConfiguration(value: Nullable) {\r\n this._attachImageProcessingConfiguration(value);\r\n\r\n // Ensure the effect will be rebuilt.\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /**\r\n * Gets whether the color curves effect is enabled.\r\n */\r\n public get cameraColorCurvesEnabled(): boolean {\r\n return (this.imageProcessingConfiguration).colorCurvesEnabled;\r\n }\r\n /**\r\n * Sets whether the color curves effect is enabled.\r\n */\r\n public set cameraColorCurvesEnabled(value: boolean) {\r\n (this.imageProcessingConfiguration).colorCurvesEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public get cameraColorGradingEnabled(): boolean {\r\n return (this.imageProcessingConfiguration).colorGradingEnabled;\r\n }\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public set cameraColorGradingEnabled(value: boolean) {\r\n (this.imageProcessingConfiguration).colorGradingEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets whether tonemapping is enabled or not.\r\n */\r\n public get cameraToneMappingEnabled(): boolean {\r\n return this._imageProcessingConfiguration.toneMappingEnabled;\r\n }\r\n /**\r\n * Sets whether tonemapping is enabled or not\r\n */\r\n public set cameraToneMappingEnabled(value: boolean) {\r\n this._imageProcessingConfiguration.toneMappingEnabled = value;\r\n }\r\n\r\n /**\r\n * The camera exposure used on this material.\r\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\r\n * This corresponds to a photographic exposure.\r\n */\r\n public get cameraExposure(): float {\r\n return this._imageProcessingConfiguration.exposure;\r\n }\r\n /**\r\n * The camera exposure used on this material.\r\n * This property is here and not in the camera to allow controlling exposure without full screen post process.\r\n * This corresponds to a photographic exposure.\r\n */\r\n public set cameraExposure(value: float) {\r\n this._imageProcessingConfiguration.exposure = value;\r\n }\r\n\r\n /**\r\n * Gets The camera contrast used on this material.\r\n */\r\n public get cameraContrast(): float {\r\n return this._imageProcessingConfiguration.contrast;\r\n }\r\n\r\n /**\r\n * Sets The camera contrast used on this material.\r\n */\r\n public set cameraContrast(value: float) {\r\n this._imageProcessingConfiguration.contrast = value;\r\n }\r\n\r\n /**\r\n * Gets the Color Grading 2D Lookup Texture.\r\n */\r\n public get cameraColorGradingTexture(): Nullable {\r\n return this._imageProcessingConfiguration.colorGradingTexture;\r\n }\r\n /**\r\n * Sets the Color Grading 2D Lookup Texture.\r\n */\r\n public set cameraColorGradingTexture(value: Nullable) {\r\n (this.imageProcessingConfiguration).colorGradingTexture = value;\r\n }\r\n\r\n /**\r\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\n public get cameraColorCurves(): Nullable {\r\n return (this.imageProcessingConfiguration).colorCurves;\r\n }\r\n /**\r\n * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).\r\n * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.\r\n * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;\r\n * corresponding to low luminance, medium luminance, and high luminance areas respectively.\r\n */\r\n public set cameraColorCurves(value: Nullable) {\r\n (this.imageProcessingConfiguration).colorCurves = value;\r\n }\r\n\r\n /**\r\n * Due to a bug in iOS10, video tags (which are using the background material) are in BGR and not RGB.\r\n * Setting this flag to true (not done automatically!) will convert it back to RGB.\r\n */\r\n public switchToBGR: boolean = false;\r\n\r\n // Temp values kept as cache in the material.\r\n private _renderTargets = new SmartArray(16);\r\n private _reflectionControls = Vector4.Zero();\r\n private _white = Color3.White();\r\n private _primaryShadowColor = Color3.Black();\r\n private _primaryHighlightColor = Color3.Black();\r\n\r\n /**\r\n * Instantiates a Background Material in the given scene\r\n * @param name The friendly name of the material\r\n * @param scene The scene to add the material to\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n\r\n // Setup the default processing configuration to the scene.\r\n this._attachImageProcessingConfiguration(null);\r\n\r\n this.getRenderTargetTextures = (): SmartArray => {\r\n this._renderTargets.reset();\r\n\r\n if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {\r\n this._renderTargets.push(this._diffuseTexture as RenderTargetTexture);\r\n }\r\n\r\n if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n this._renderTargets.push(this._reflectionTexture as RenderTargetTexture);\r\n }\r\n\r\n return this._renderTargets;\r\n };\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that current material needs to register RTT\r\n */\r\n public get hasRenderTargetTextures(): boolean {\r\n if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {\r\n return true;\r\n }\r\n\r\n if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * The entire material has been created in order to prevent overdraw.\r\n * @returns false\r\n */\r\n public needAlphaTesting(): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * The entire material has been created in order to prevent overdraw.\r\n * @returns true if blending is enable\r\n */\r\n public needAlphaBlending(): boolean {\r\n return this.alpha < 1 || (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._shadowOnly;\r\n }\r\n\r\n /**\r\n * Checks whether the material is ready to be rendered for a given mesh.\r\n * @param mesh The mesh to render\r\n * @param subMesh The submesh to check against\r\n * @param useInstances Specify wether or not the material is used with instances\r\n * @returns true if all the dependencies are ready (Textures, Effects...)\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances: boolean = false): boolean {\r\n if (subMesh.effect && this.isFrozen) {\r\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n subMesh.materialDefines = new BackgroundMaterialDefines();\r\n }\r\n\r\n const scene = this.getScene();\r\n const defines = subMesh.materialDefines;\r\n\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n // Lights\r\n MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);\r\n defines._needNormals = true;\r\n\r\n // Multiview\r\n MaterialHelper.PrepareDefinesForMultiview(scene, defines);\r\n\r\n // Textures\r\n if (defines._areTexturesDirty) {\r\n defines._needUVs = false;\r\n if (scene.texturesEnabled) {\r\n if (scene.getEngine().getCaps().textureLOD) {\r\n defines.TEXTURELODSUPPORT = true;\r\n }\r\n\r\n if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n if (!this._diffuseTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n\r\n MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture, defines, \"DIFFUSE\");\r\n defines.DIFFUSEHASALPHA = this._diffuseTexture.hasAlpha;\r\n defines.GAMMADIFFUSE = this._diffuseTexture.gammaSpace;\r\n defines.OPACITYFRESNEL = this._opacityFresnel;\r\n } else {\r\n defines.DIFFUSE = false;\r\n defines.DIFFUSEDIRECTUV = 0;\r\n defines.DIFFUSEHASALPHA = false;\r\n defines.GAMMADIFFUSE = false;\r\n defines.OPACITYFRESNEL = false;\r\n }\r\n\r\n const reflectionTexture = this._reflectionTexture;\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n if (!reflectionTexture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n\r\n defines.REFLECTION = true;\r\n defines.GAMMAREFLECTION = reflectionTexture.gammaSpace;\r\n defines.RGBDREFLECTION = reflectionTexture.isRGBD;\r\n defines.REFLECTIONBLUR = this._reflectionBlur > 0;\r\n defines.LODINREFLECTIONALPHA = reflectionTexture.lodLevelInAlpha;\r\n defines.EQUIRECTANGULAR_RELFECTION_FOV = this.useEquirectangularFOV;\r\n defines.REFLECTIONBGR = this.switchToBGR;\r\n\r\n if (reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {\r\n defines.INVERTCUBICMAP = true;\r\n }\r\n\r\n defines.REFLECTIONMAP_3D = reflectionTexture.isCube;\r\n defines.REFLECTIONMAP_OPPOSITEZ = defines.REFLECTIONMAP_3D && this.getScene().useRightHandedSystem ? !reflectionTexture.invertZ : reflectionTexture.invertZ;\r\n\r\n switch (reflectionTexture.coordinatesMode) {\r\n case Texture.EXPLICIT_MODE:\r\n defines.REFLECTIONMAP_EXPLICIT = true;\r\n break;\r\n case Texture.PLANAR_MODE:\r\n defines.REFLECTIONMAP_PLANAR = true;\r\n break;\r\n case Texture.PROJECTION_MODE:\r\n defines.REFLECTIONMAP_PROJECTION = true;\r\n break;\r\n case Texture.SKYBOX_MODE:\r\n defines.REFLECTIONMAP_SKYBOX = true;\r\n break;\r\n case Texture.SPHERICAL_MODE:\r\n defines.REFLECTIONMAP_SPHERICAL = true;\r\n break;\r\n case Texture.EQUIRECTANGULAR_MODE:\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR = true;\r\n break;\r\n case Texture.FIXED_EQUIRECTANGULAR_MODE:\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;\r\n break;\r\n case Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:\r\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;\r\n break;\r\n case Texture.CUBIC_MODE:\r\n case Texture.INVCUBIC_MODE:\r\n default:\r\n defines.REFLECTIONMAP_CUBIC = true;\r\n break;\r\n }\r\n\r\n if (this.reflectionFresnel) {\r\n defines.REFLECTIONFRESNEL = true;\r\n defines.REFLECTIONFALLOFF = this.reflectionFalloffDistance > 0;\r\n\r\n this._reflectionControls.x = this.reflectionAmount;\r\n this._reflectionControls.y = this.reflectionReflectance0;\r\n this._reflectionControls.z = this.reflectionReflectance90;\r\n this._reflectionControls.w = 1 / this.reflectionFalloffDistance;\r\n } else {\r\n defines.REFLECTIONFRESNEL = false;\r\n defines.REFLECTIONFALLOFF = false;\r\n }\r\n } else {\r\n defines.REFLECTION = false;\r\n defines.REFLECTIONFRESNEL = false;\r\n defines.REFLECTIONFALLOFF = false;\r\n defines.REFLECTIONBLUR = false;\r\n defines.REFLECTIONMAP_3D = false;\r\n defines.REFLECTIONMAP_SPHERICAL = false;\r\n defines.REFLECTIONMAP_PLANAR = false;\r\n defines.REFLECTIONMAP_CUBIC = false;\r\n defines.REFLECTIONMAP_PROJECTION = false;\r\n defines.REFLECTIONMAP_SKYBOX = false;\r\n defines.REFLECTIONMAP_EXPLICIT = false;\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR = false;\r\n defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;\r\n defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;\r\n defines.INVERTCUBICMAP = false;\r\n defines.REFLECTIONMAP_OPPOSITEZ = false;\r\n defines.LODINREFLECTIONALPHA = false;\r\n defines.GAMMAREFLECTION = false;\r\n defines.RGBDREFLECTION = false;\r\n }\r\n }\r\n\r\n defines.PREMULTIPLYALPHA = this.alphaMode === Constants.ALPHA_PREMULTIPLIED || this.alphaMode === Constants.ALPHA_PREMULTIPLIED_PORTERDUFF;\r\n defines.USERGBCOLOR = this._useRGBColor;\r\n defines.NOISE = this._enableNoise;\r\n }\r\n\r\n if (defines._areLightsDirty) {\r\n defines.USEHIGHLIGHTANDSHADOWCOLORS = !this._useRGBColor && (this._primaryColorShadowLevel !== 0 || this._primaryColorHighlightLevel !== 0);\r\n defines.BACKMAT_SHADOWONLY = this._shadowOnly;\r\n }\r\n\r\n if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {\r\n if (!this._imageProcessingConfiguration.isReady()) {\r\n return false;\r\n }\r\n\r\n this._imageProcessingConfiguration.prepareDefines(defines);\r\n }\r\n\r\n // Misc.\r\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);\r\n\r\n // Values that need to be evaluated on every frame\r\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);\r\n\r\n // Attribs\r\n if (MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {\r\n if (mesh) {\r\n if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n mesh.createNormals(true);\r\n Logger.Warn(\"BackgroundMaterial: Normals have been created for the mesh: \" + mesh.name);\r\n }\r\n }\r\n }\r\n\r\n // Get correct effect\r\n if (defines.isDirty) {\r\n defines.markAsProcessed();\r\n scene.resetCachedMaterial();\r\n\r\n // Fallbacks\r\n const fallbacks = new EffectFallbacks();\r\n if (defines.FOG) {\r\n fallbacks.addFallback(0, \"FOG\");\r\n }\r\n\r\n if (defines.POINTSIZE) {\r\n fallbacks.addFallback(1, \"POINTSIZE\");\r\n }\r\n\r\n if (defines.MULTIVIEW) {\r\n fallbacks.addFallback(0, \"MULTIVIEW\");\r\n }\r\n\r\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);\r\n\r\n //Attributes\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n if (defines.NORMAL) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n }\r\n\r\n if (defines.UV1) {\r\n attribs.push(VertexBuffer.UVKind);\r\n }\r\n\r\n if (defines.UV2) {\r\n attribs.push(VertexBuffer.UV2Kind);\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\r\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\r\n\r\n const uniforms = [\r\n \"world\",\r\n \"view\",\r\n \"viewProjection\",\r\n \"vEyePosition\",\r\n \"vLightsType\",\r\n \"vFogInfos\",\r\n \"vFogColor\",\r\n \"pointSize\",\r\n \"mBones\",\r\n\r\n \"vPrimaryColor\",\r\n \"vPrimaryColorShadow\",\r\n \"vReflectionInfos\",\r\n \"reflectionMatrix\",\r\n \"vReflectionMicrosurfaceInfos\",\r\n \"fFovMultiplier\",\r\n\r\n \"shadowLevel\",\r\n \"alpha\",\r\n\r\n \"vBackgroundCenter\",\r\n \"vReflectionControl\",\r\n\r\n \"vDiffuseInfos\",\r\n \"diffuseMatrix\",\r\n ];\r\n\r\n addClipPlaneUniforms(uniforms);\r\n const samplers = [\"diffuseSampler\", \"reflectionSampler\", \"reflectionSamplerLow\", \"reflectionSamplerHigh\"];\r\n const uniformBuffers = [\"Material\", \"Scene\"];\r\n\r\n if (ImageProcessingConfiguration) {\r\n ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);\r\n ImageProcessingConfiguration.PrepareSamplers(samplers, defines);\r\n }\r\n\r\n MaterialHelper.PrepareUniformsAndSamplersList({\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: defines,\r\n maxSimultaneousLights: this._maxSimultaneousLights,\r\n });\r\n\r\n const join = defines.toString();\r\n const effect = scene.getEngine().createEffect(\r\n \"background\",\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights },\r\n },\r\n engine\r\n );\r\n subMesh.setEffect(effect, defines, this._materialContext);\r\n\r\n this.buildUniformLayout();\r\n }\r\n\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = true;\r\n subMesh.effect._wasPreviouslyUsingInstances = useInstances;\r\n\r\n this._checkScenePerformancePriority();\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Compute the primary color according to the chosen perceptual color.\r\n */\r\n private _computePrimaryColorFromPerceptualColor(): void {\r\n if (!this.__perceptualColor) {\r\n return;\r\n }\r\n\r\n this._primaryColor.copyFrom(this.__perceptualColor);\r\n\r\n // Revert gamma space.\r\n this._primaryColor.toLinearSpaceToRef(this._primaryColor, this.getScene().getEngine().useExactSrgbConversions);\r\n\r\n // Revert image processing configuration.\r\n if (this._imageProcessingConfiguration) {\r\n // Revert Exposure.\r\n this._primaryColor.scaleToRef(1 / this._imageProcessingConfiguration.exposure, this._primaryColor);\r\n }\r\n\r\n this._computePrimaryColors();\r\n }\r\n\r\n /**\r\n * Compute the highlights and shadow colors according to their chosen levels.\r\n */\r\n private _computePrimaryColors(): void {\r\n if (this._primaryColorShadowLevel === 0 && this._primaryColorHighlightLevel === 0) {\r\n return;\r\n }\r\n\r\n // Find the highlight color based on the configuration.\r\n this._primaryColor.scaleToRef(this._primaryColorShadowLevel, this._primaryShadowColor);\r\n this._primaryColor.subtractToRef(this._primaryShadowColor, this._primaryShadowColor);\r\n\r\n // Find the shadow color based on the configuration.\r\n this._white.subtractToRef(this._primaryColor, this._primaryHighlightColor);\r\n this._primaryHighlightColor.scaleToRef(this._primaryColorHighlightLevel, this._primaryHighlightColor);\r\n this._primaryColor.addToRef(this._primaryHighlightColor, this._primaryHighlightColor);\r\n }\r\n\r\n /**\r\n * Build the uniform buffer used in the material.\r\n */\r\n public buildUniformLayout(): void {\r\n // Order is important !\r\n this._uniformBuffer.addUniform(\"vPrimaryColor\", 4);\r\n this._uniformBuffer.addUniform(\"vPrimaryColorShadow\", 4);\r\n this._uniformBuffer.addUniform(\"vDiffuseInfos\", 2);\r\n this._uniformBuffer.addUniform(\"vReflectionInfos\", 2);\r\n this._uniformBuffer.addUniform(\"diffuseMatrix\", 16);\r\n this._uniformBuffer.addUniform(\"reflectionMatrix\", 16);\r\n this._uniformBuffer.addUniform(\"vReflectionMicrosurfaceInfos\", 3);\r\n this._uniformBuffer.addUniform(\"fFovMultiplier\", 1);\r\n this._uniformBuffer.addUniform(\"pointSize\", 1);\r\n this._uniformBuffer.addUniform(\"shadowLevel\", 1);\r\n this._uniformBuffer.addUniform(\"alpha\", 1);\r\n this._uniformBuffer.addUniform(\"vBackgroundCenter\", 3);\r\n this._uniformBuffer.addUniform(\"vReflectionControl\", 4);\r\n\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Unbind the material.\r\n */\r\n public unbind(): void {\r\n if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {\r\n this._uniformBuffer.setTexture(\"diffuseSampler\", null);\r\n }\r\n\r\n if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {\r\n this._uniformBuffer.setTexture(\"reflectionSampler\", null);\r\n }\r\n\r\n super.unbind();\r\n }\r\n\r\n /**\r\n * Bind only the world matrix to the material.\r\n * @param world The world matrix to bind.\r\n */\r\n public bindOnlyWorldMatrix(world: Matrix): void {\r\n this._activeEffect!.setMatrix(\"world\", world);\r\n }\r\n\r\n /**\r\n * Bind the material for a dedicated submeh (every used meshes will be considered opaque).\r\n * @param world The world matrix to bind.\r\n * @param mesh\r\n * @param subMesh The submesh to bind for.\r\n */\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n\r\n const defines = subMesh.materialDefines;\r\n if (!defines) {\r\n return;\r\n }\r\n\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n this._activeEffect = effect;\r\n\r\n // Matrices\r\n this.bindOnlyWorldMatrix(world);\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect);\r\n\r\n const mustRebind = this._mustRebind(scene, effect, mesh.visibility);\r\n if (mustRebind) {\r\n this._uniformBuffer.bindToEffect(effect, \"Material\");\r\n\r\n this.bindViewProjection(effect);\r\n\r\n const reflectionTexture = this._reflectionTexture;\r\n if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {\r\n // Texture uniforms\r\n if (scene.texturesEnabled) {\r\n if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n this._uniformBuffer.updateFloat2(\"vDiffuseInfos\", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);\r\n MaterialHelper.BindTextureMatrix(this._diffuseTexture, this._uniformBuffer, \"diffuse\");\r\n }\r\n\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n this._uniformBuffer.updateMatrix(\"reflectionMatrix\", reflectionTexture.getReflectionTextureMatrix());\r\n this._uniformBuffer.updateFloat2(\"vReflectionInfos\", reflectionTexture.level, this._reflectionBlur);\r\n\r\n this._uniformBuffer.updateFloat3(\r\n \"vReflectionMicrosurfaceInfos\",\r\n reflectionTexture.getSize().width,\r\n reflectionTexture.lodGenerationScale,\r\n reflectionTexture.lodGenerationOffset\r\n );\r\n }\r\n }\r\n\r\n if (this.shadowLevel > 0) {\r\n this._uniformBuffer.updateFloat(\"shadowLevel\", this.shadowLevel);\r\n }\r\n this._uniformBuffer.updateFloat(\"alpha\", this.alpha);\r\n\r\n // Point size\r\n if (this.pointsCloud) {\r\n this._uniformBuffer.updateFloat(\"pointSize\", this.pointSize);\r\n }\r\n\r\n if (defines.USEHIGHLIGHTANDSHADOWCOLORS) {\r\n this._uniformBuffer.updateColor4(\"vPrimaryColor\", this._primaryHighlightColor, 1.0);\r\n this._uniformBuffer.updateColor4(\"vPrimaryColorShadow\", this._primaryShadowColor, 1.0);\r\n } else {\r\n this._uniformBuffer.updateColor4(\"vPrimaryColor\", this._primaryColor, 1.0);\r\n }\r\n }\r\n\r\n this._uniformBuffer.updateFloat(\"fFovMultiplier\", this._fovMultiplier);\r\n\r\n // Textures\r\n if (scene.texturesEnabled) {\r\n if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {\r\n this._uniformBuffer.setTexture(\"diffuseSampler\", this._diffuseTexture);\r\n }\r\n\r\n if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {\r\n if (defines.REFLECTIONBLUR && defines.TEXTURELODSUPPORT) {\r\n this._uniformBuffer.setTexture(\"reflectionSampler\", reflectionTexture);\r\n } else if (!defines.REFLECTIONBLUR) {\r\n this._uniformBuffer.setTexture(\"reflectionSampler\", reflectionTexture);\r\n } else {\r\n this._uniformBuffer.setTexture(\"reflectionSampler\", reflectionTexture._lodTextureMid || reflectionTexture);\r\n this._uniformBuffer.setTexture(\"reflectionSamplerLow\", reflectionTexture._lodTextureLow || reflectionTexture);\r\n this._uniformBuffer.setTexture(\"reflectionSamplerHigh\", reflectionTexture._lodTextureHigh || reflectionTexture);\r\n }\r\n\r\n if (defines.REFLECTIONFRESNEL) {\r\n this._uniformBuffer.updateFloat3(\"vBackgroundCenter\", this.sceneCenter.x, this.sceneCenter.y, this.sceneCenter.z);\r\n this._uniformBuffer.updateFloat4(\r\n \"vReflectionControl\",\r\n this._reflectionControls.x,\r\n this._reflectionControls.y,\r\n this._reflectionControls.z,\r\n this._reflectionControls.w\r\n );\r\n }\r\n }\r\n }\r\n\r\n // Clip plane\r\n bindClipPlane(this._activeEffect, this, scene);\r\n\r\n scene.bindEyePosition(effect);\r\n } else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {\r\n this._uniformBuffer.bindToEffect(effect, \"Material\");\r\n this._needToBindSceneUbo = true;\r\n }\r\n\r\n if (mustRebind || !this.isFrozen) {\r\n if (scene.lightsEnabled) {\r\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);\r\n }\r\n\r\n // View\r\n this.bindView(effect);\r\n\r\n // Fog\r\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect, true);\r\n\r\n // image processing\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingConfiguration.bind(this._activeEffect);\r\n }\r\n }\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n\r\n this._uniformBuffer.update();\r\n }\r\n\r\n /**\r\n * Checks to see if a texture is used in the material.\r\n * @param texture - Base texture to use.\r\n * @returns - Boolean specifying if a texture is used in the material.\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 if (this._reflectionTexture === texture) {\r\n return true;\r\n }\r\n\r\n if (this._diffuseTexture === texture) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Dispose the material.\r\n * @param forceDisposeEffect Force disposal of the associated effect.\r\n * @param forceDisposeTextures Force disposal of the associated textures.\r\n */\r\n public dispose(forceDisposeEffect: boolean = false, forceDisposeTextures: boolean = false): void {\r\n if (forceDisposeTextures) {\r\n if (this.diffuseTexture) {\r\n this.diffuseTexture.dispose();\r\n }\r\n if (this.reflectionTexture) {\r\n this.reflectionTexture.dispose();\r\n }\r\n }\r\n\r\n this._renderTargets.dispose();\r\n\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n super.dispose(forceDisposeEffect);\r\n }\r\n\r\n /**\r\n * Clones the material.\r\n * @param name The cloned name.\r\n * @returns The cloned material.\r\n */\r\n public clone(name: string): BackgroundMaterial {\r\n return SerializationHelper.Clone(() => new BackgroundMaterial(name, this.getScene()), this);\r\n }\r\n\r\n /**\r\n * Serializes the current material to its JSON representation.\r\n * @returns The JSON representation.\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n serializationObject.customType = \"BABYLON.BackgroundMaterial\";\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Gets the class name of the material\r\n * @returns \"BackgroundMaterial\"\r\n */\r\n public getClassName(): string {\r\n return \"BackgroundMaterial\";\r\n }\r\n\r\n /**\r\n * Parse a JSON input to create back a background material.\r\n * @param source The JSON data to parse\r\n * @param scene The scene to create the parsed material in\r\n * @param rootUrl The root url of the assets the material depends upon\r\n * @returns the instantiated BackgroundMaterial.\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): BackgroundMaterial {\r\n return SerializationHelper.Parse(() => new BackgroundMaterial(source.name, scene), source, scene, rootUrl);\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.BackgroundMaterial\", BackgroundMaterial);\r\n","import type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a Plane\r\n * @param options an object used to set the following optional parameters for the plane, required but can be empty\r\n * * size sets the width and height of the plane to the value of size, optional default 1\r\n * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the box\r\n */\r\nexport function CreatePlaneVertexData(options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 }): VertexData {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n const width: number = options.width || options.size || 1;\r\n const height: number = options.height || options.size || 1;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // Vertices\r\n const halfWidth = width / 2.0;\r\n const halfHeight = height / 2.0;\r\n\r\n positions.push(-halfWidth, -halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(0.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 : 0.0);\r\n\r\n positions.push(halfWidth, -halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(1.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 : 0.0);\r\n\r\n positions.push(halfWidth, halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(1.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 0.0 : 1.0);\r\n\r\n positions.push(-halfWidth, halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(0.0, CompatibilityOptions.UseOpenGLOrientationForUV ? 0.0 : 1.0);\r\n\r\n // Indices\r\n indices.push(0);\r\n indices.push(1);\r\n indices.push(2);\r\n\r\n indices.push(0);\r\n indices.push(2);\r\n indices.push(3);\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a plane mesh\r\n * * The parameter `size` sets the size (float) of both sides of the plane at once (default 1)\r\n * * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value of `size`)\r\n * * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.updatable\r\n * @param options.sourcePlane\r\n * @param scene defines the hosting scene\r\n * @returns the plane mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#plane\r\n */\r\nexport function CreatePlane(\r\n name: string,\r\n options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4; updatable?: boolean; sourcePlane?: Plane } = {},\r\n scene: Nullable = null\r\n): Mesh {\r\n const plane = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n plane._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreatePlaneVertexData(options);\r\n\r\n vertexData.applyToMesh(plane, options.updatable);\r\n\r\n if (options.sourcePlane) {\r\n plane.translate(options.sourcePlane.normal, -options.sourcePlane.d);\r\n plane.setDirection(options.sourcePlane.normal.scale(-1));\r\n }\r\n\r\n return plane;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const PlaneBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreatePlane,\r\n};\r\n\r\nVertexData.CreatePlane = CreatePlaneVertexData;\r\nMesh.CreatePlane = (name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n size,\r\n width: size,\r\n height: size,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreatePlane(name, options, scene);\r\n};\r\n","import type { Scene } from \"../scene\";\r\nimport { Vector3, Vector2, TmpVectors, Vector4 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\n\r\nMesh._GroundMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n return GroundMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Mesh representing the ground\r\n */\r\nexport class GroundMesh extends Mesh {\r\n /** If octree should be generated */\r\n public generateOctree = false;\r\n\r\n private _heightQuads: { slope: Vector2; facet1: Vector4; facet2: Vector4 }[];\r\n\r\n /** @internal */\r\n public _subdivisionsX: number;\r\n /** @internal */\r\n public _subdivisionsY: number;\r\n /** @internal */\r\n public _width: number;\r\n /** @internal */\r\n public _height: number;\r\n /** @internal */\r\n public _minX: number;\r\n /** @internal */\r\n public _maxX: number;\r\n /** @internal */\r\n public _minZ: number;\r\n /** @internal */\r\n public _maxZ: number;\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n }\r\n\r\n /**\r\n * \"GroundMesh\"\r\n * @returns \"GroundMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"GroundMesh\";\r\n }\r\n\r\n /**\r\n * The minimum of x and y subdivisions\r\n */\r\n public get subdivisions(): number {\r\n return Math.min(this._subdivisionsX, this._subdivisionsY);\r\n }\r\n\r\n /**\r\n * X subdivisions\r\n */\r\n public get subdivisionsX(): number {\r\n return this._subdivisionsX;\r\n }\r\n\r\n /**\r\n * Y subdivisions\r\n */\r\n public get subdivisionsY(): number {\r\n return this._subdivisionsY;\r\n }\r\n\r\n /**\r\n * This function will divide the mesh into submeshes and update an octree to help to select the right submeshes\r\n * for rendering, picking and collision computations. Please note that you must have a decent number of submeshes\r\n * to get performance improvements when using an octree.\r\n * @param chunksCount the number of submeshes the mesh will be divided into\r\n * @param octreeBlocksSize the maximum size of the octree blocks (Default: 32)\r\n */\r\n public optimize(chunksCount: number, octreeBlocksSize = 32): void {\r\n this._subdivisionsX = chunksCount;\r\n this._subdivisionsY = chunksCount;\r\n this.subdivide(chunksCount);\r\n\r\n // Call the octree system optimization if it is defined.\r\n const thisAsAny = this as any;\r\n if (thisAsAny.createOrUpdateSubmeshesOctree) {\r\n thisAsAny.createOrUpdateSubmeshesOctree(octreeBlocksSize);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a height (y) value in the World system :\r\n * the ground altitude at the coordinates (x, z) expressed in the World system.\r\n * @param x x coordinate\r\n * @param z z coordinate\r\n * @returns the ground y position if (x, z) are outside the ground surface.\r\n */\r\n public getHeightAtCoordinates(x: number, z: number): number {\r\n const world = this.getWorldMatrix();\r\n const invMat = TmpVectors.Matrix[5];\r\n world.invertToRef(invMat);\r\n const tmpVect = TmpVectors.Vector3[8];\r\n Vector3.TransformCoordinatesFromFloatsToRef(x, 0.0, z, invMat, tmpVect); // transform x,z in the mesh local space\r\n x = tmpVect.x;\r\n z = tmpVect.z;\r\n if (x < this._minX || x >= this._maxX || z <= this._minZ || z > this._maxZ) {\r\n return this.position.y;\r\n }\r\n if (!this._heightQuads || this._heightQuads.length == 0) {\r\n this._initHeightQuads();\r\n this._computeHeightQuads();\r\n }\r\n const facet = this._getFacetAt(x, z);\r\n const y = -(facet.x * x + facet.z * z + facet.w) / facet.y;\r\n // return y in the World system\r\n Vector3.TransformCoordinatesFromFloatsToRef(0.0, y, 0.0, world, tmpVect);\r\n return tmpVect.y;\r\n }\r\n\r\n /**\r\n * Returns a normalized vector (Vector3) orthogonal to the ground\r\n * at the ground coordinates (x, z) expressed in the World system.\r\n * @param x x coordinate\r\n * @param z z coordinate\r\n * @returns Vector3(0.0, 1.0, 0.0) if (x, z) are outside the ground surface.\r\n */\r\n public getNormalAtCoordinates(x: number, z: number): Vector3 {\r\n const normal = new Vector3(0.0, 1.0, 0.0);\r\n this.getNormalAtCoordinatesToRef(x, z, normal);\r\n return normal;\r\n }\r\n\r\n /**\r\n * Updates the Vector3 passed a reference with a normalized vector orthogonal to the ground\r\n * at the ground coordinates (x, z) expressed in the World system.\r\n * Doesn't update the reference Vector3 if (x, z) are outside the ground surface.\r\n * @param x x coordinate\r\n * @param z z coordinate\r\n * @param ref vector to store the result\r\n * @returns the GroundMesh.\r\n */\r\n public getNormalAtCoordinatesToRef(x: number, z: number, ref: Vector3): GroundMesh {\r\n const world = this.getWorldMatrix();\r\n const tmpMat = TmpVectors.Matrix[5];\r\n world.invertToRef(tmpMat);\r\n const tmpVect = TmpVectors.Vector3[8];\r\n Vector3.TransformCoordinatesFromFloatsToRef(x, 0.0, z, tmpMat, tmpVect); // transform x,z in the mesh local space\r\n x = tmpVect.x;\r\n z = tmpVect.z;\r\n if (x < this._minX || x > this._maxX || z < this._minZ || z > this._maxZ) {\r\n return this;\r\n }\r\n if (!this._heightQuads || this._heightQuads.length == 0) {\r\n this._initHeightQuads();\r\n this._computeHeightQuads();\r\n }\r\n const facet = this._getFacetAt(x, z);\r\n Vector3.TransformNormalFromFloatsToRef(facet.x, facet.y, facet.z, world, ref);\r\n return this;\r\n }\r\n\r\n /**\r\n * Force the heights to be recomputed for getHeightAtCoordinates() or getNormalAtCoordinates()\r\n * if the ground has been updated.\r\n * This can be used in the render loop.\r\n * @returns the GroundMesh.\r\n */\r\n public updateCoordinateHeights(): GroundMesh {\r\n if (!this._heightQuads || this._heightQuads.length == 0) {\r\n this._initHeightQuads();\r\n }\r\n this._computeHeightQuads();\r\n return this;\r\n }\r\n\r\n // Returns the element \"facet\" from the heightQuads array relative to (x, z) local coordinates\r\n private _getFacetAt(x: number, z: number): Vector4 {\r\n // retrieve col and row from x, z coordinates in the ground local system\r\n const col = Math.floor(((x + this._maxX) * this._subdivisionsX) / this._width);\r\n const row = Math.floor((-(z + this._maxZ) * this._subdivisionsY) / this._height + this._subdivisionsY);\r\n const quad = this._heightQuads[row * this._subdivisionsX + col];\r\n let facet;\r\n if (z < quad.slope.x * x + quad.slope.y) {\r\n facet = quad.facet1;\r\n } else {\r\n facet = quad.facet2;\r\n }\r\n return facet;\r\n }\r\n\r\n // Creates and populates the heightMap array with \"facet\" elements :\r\n // a quad is two triangular facets separated by a slope, so a \"facet\" element is 1 slope + 2 facets\r\n // slope : Vector2(c, h) = 2D diagonal line equation setting apart two triangular facets in a quad : z = cx + h\r\n // facet1 : Vector4(a, b, c, d) = first facet 3D plane equation : ax + by + cz + d = 0\r\n // facet2 : Vector4(a, b, c, d) = second facet 3D plane equation : ax + by + cz + d = 0\r\n // Returns the GroundMesh.\r\n private _initHeightQuads(): GroundMesh {\r\n const subdivisionsX = this._subdivisionsX;\r\n const subdivisionsY = this._subdivisionsY;\r\n this._heightQuads = new Array();\r\n for (let row = 0; row < subdivisionsY; row++) {\r\n for (let col = 0; col < subdivisionsX; col++) {\r\n const quad = { slope: Vector2.Zero(), facet1: new Vector4(0.0, 0.0, 0.0, 0.0), facet2: new Vector4(0.0, 0.0, 0.0, 0.0) };\r\n this._heightQuads[row * subdivisionsX + col] = quad;\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n // Compute each quad element values and update the the heightMap array :\r\n // slope : Vector2(c, h) = 2D diagonal line equation setting apart two triangular facets in a quad : z = cx + h\r\n // facet1 : Vector4(a, b, c, d) = first facet 3D plane equation : ax + by + cz + d = 0\r\n // facet2 : Vector4(a, b, c, d) = second facet 3D plane equation : ax + by + cz + d = 0\r\n // Returns the GroundMesh.\r\n private _computeHeightQuads(): GroundMesh {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (!positions) {\r\n return this;\r\n }\r\n\r\n const v1 = TmpVectors.Vector3[3];\r\n const v2 = TmpVectors.Vector3[2];\r\n const v3 = TmpVectors.Vector3[1];\r\n const v4 = TmpVectors.Vector3[0];\r\n const v1v2 = TmpVectors.Vector3[4];\r\n const v1v3 = TmpVectors.Vector3[5];\r\n const v1v4 = TmpVectors.Vector3[6];\r\n const norm1 = TmpVectors.Vector3[7];\r\n const norm2 = TmpVectors.Vector3[8];\r\n let i = 0;\r\n let j = 0;\r\n let k = 0;\r\n let cd = 0; // 2D slope coefficient : z = cd * x + h\r\n let h = 0;\r\n let d1 = 0; // facet plane equation : ax + by + cz + d = 0\r\n let d2 = 0;\r\n\r\n const subdivisionsX = this._subdivisionsX;\r\n const subdivisionsY = this._subdivisionsY;\r\n\r\n for (let row = 0; row < subdivisionsY; row++) {\r\n for (let col = 0; col < subdivisionsX; col++) {\r\n i = col * 3;\r\n j = row * (subdivisionsX + 1) * 3;\r\n k = (row + 1) * (subdivisionsX + 1) * 3;\r\n v1.x = positions[j + i];\r\n v1.y = positions[j + i + 1];\r\n v1.z = positions[j + i + 2];\r\n v2.x = positions[j + i + 3];\r\n v2.y = positions[j + i + 4];\r\n v2.z = positions[j + i + 5];\r\n v3.x = positions[k + i];\r\n v3.y = positions[k + i + 1];\r\n v3.z = positions[k + i + 2];\r\n v4.x = positions[k + i + 3];\r\n v4.y = positions[k + i + 4];\r\n v4.z = positions[k + i + 5];\r\n\r\n // 2D slope V1V4\r\n cd = (v4.z - v1.z) / (v4.x - v1.x);\r\n h = v1.z - cd * v1.x; // v1 belongs to the slope\r\n\r\n // facet equations :\r\n // we compute each facet normal vector\r\n // the equation of the facet plane is : norm.x * x + norm.y * y + norm.z * z + d = 0\r\n // we compute the value d by applying the equation to v1 which belongs to the plane\r\n // then we store the facet equation in a Vector4\r\n v2.subtractToRef(v1, v1v2);\r\n v3.subtractToRef(v1, v1v3);\r\n v4.subtractToRef(v1, v1v4);\r\n Vector3.CrossToRef(v1v4, v1v3, norm1); // caution : CrossToRef uses the Tmp class\r\n Vector3.CrossToRef(v1v2, v1v4, norm2);\r\n norm1.normalize();\r\n norm2.normalize();\r\n d1 = -(norm1.x * v1.x + norm1.y * v1.y + norm1.z * v1.z);\r\n d2 = -(norm2.x * v2.x + norm2.y * v2.y + norm2.z * v2.z);\r\n\r\n const quad = this._heightQuads[row * subdivisionsX + col];\r\n quad.slope.copyFromFloats(cd, h);\r\n quad.facet1.copyFromFloats(norm1.x, norm1.y, norm1.z, d1);\r\n quad.facet2.copyFromFloats(norm2.x, norm2.y, norm2.z, d2);\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Serializes this ground mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.subdivisionsX = this._subdivisionsX;\r\n serializationObject.subdivisionsY = this._subdivisionsY;\r\n\r\n serializationObject.minX = this._minX;\r\n serializationObject.maxX = this._maxX;\r\n\r\n serializationObject.minZ = this._minZ;\r\n serializationObject.maxZ = this._maxZ;\r\n\r\n serializationObject.width = this._width;\r\n serializationObject.height = this._height;\r\n }\r\n\r\n /**\r\n * Parses a serialized ground mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the ground mesh in\r\n * @returns the created ground mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): GroundMesh {\r\n const result = new GroundMesh(parsedMesh.name, scene);\r\n\r\n result._subdivisionsX = parsedMesh.subdivisionsX || 1;\r\n result._subdivisionsY = parsedMesh.subdivisionsY || 1;\r\n\r\n result._minX = parsedMesh.minX;\r\n result._maxX = parsedMesh.maxX;\r\n\r\n result._minZ = parsedMesh.minZ;\r\n result._maxZ = parsedMesh.maxZ;\r\n\r\n result._width = parsedMesh.width;\r\n result._height = parsedMesh.height;\r\n\r\n return result;\r\n }\r\n}\r\n","import type { Scene } from \"../../scene\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { GroundMesh } from \"../groundMesh\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport { Epsilon } from \"../../Maths/math.constants\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a Ground\r\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\r\n * - width the width (x direction) of the ground, optional, default 1\r\n * - height the height (z direction) of the ground, optional, default 1\r\n * - subdivisions the number of subdivisions per side, optional, default 1\r\n * @param options.width\r\n * @param options.height\r\n * @param options.subdivisions\r\n * @param options.subdivisionsX\r\n * @param options.subdivisionsY\r\n * @returns the VertexData of the Ground\r\n */\r\nexport function CreateGroundVertexData(options: { width?: number; height?: number; subdivisions?: number; subdivisionsX?: number; subdivisionsY?: number }): VertexData {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n let row: number, col: number;\r\n\r\n const width: number = options.width || 1;\r\n const height: number = options.height || 1;\r\n const subdivisionsX: number = (options.subdivisionsX || options.subdivisions || 1) | 0;\r\n const subdivisionsY: number = (options.subdivisionsY || options.subdivisions || 1) | 0;\r\n\r\n for (row = 0; row <= subdivisionsY; row++) {\r\n for (col = 0; col <= subdivisionsX; col++) {\r\n const position = new Vector3((col * width) / subdivisionsX - width / 2.0, 0, ((subdivisionsY - row) * height) / subdivisionsY - height / 2.0);\r\n const normal = new Vector3(0, 1.0, 0);\r\n\r\n positions.push(position.x, position.y, position.z);\r\n normals.push(normal.x, normal.y, normal.z);\r\n uvs.push(col / subdivisionsX, CompatibilityOptions.UseOpenGLOrientationForUV ? row / subdivisionsY : 1.0 - row / subdivisionsY);\r\n }\r\n }\r\n\r\n for (row = 0; row < subdivisionsY; row++) {\r\n for (col = 0; col < subdivisionsX; col++) {\r\n indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));\r\n indices.push(col + 1 + row * (subdivisionsX + 1));\r\n indices.push(col + row * (subdivisionsX + 1));\r\n\r\n indices.push(col + (row + 1) * (subdivisionsX + 1));\r\n indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));\r\n indices.push(col + row * (subdivisionsX + 1));\r\n }\r\n }\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates the VertexData for a TiledGround by subdividing the ground into tiles\r\n * @param options an object used to set the following optional parameters for the Ground, required but can be empty\r\n * * xmin the ground minimum X coordinate, optional, default -1\r\n * * zmin the ground minimum Z coordinate, optional, default -1\r\n * * xmax the ground maximum X coordinate, optional, default 1\r\n * * zmax the ground maximum Z coordinate, optional, default 1\r\n * * subdivisions a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the ground width and height creating 'tiles', default {w: 6, h: 6}\r\n * * precision a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the tile width and height, default {w: 2, h: 2}\r\n * @param options.xmin\r\n * @param options.zmin\r\n * @param options.xmax\r\n * @param options.zmax\r\n * @param options.subdivisions\r\n * @param options.subdivisions.w\r\n * @param options.subdivisions.h\r\n * @param options.precision\r\n * @param options.precision.w\r\n * @param options.precision.h\r\n * @returns the VertexData of the TiledGround\r\n */\r\nexport function CreateTiledGroundVertexData(options: {\r\n xmin: number;\r\n zmin: number;\r\n xmax: number;\r\n zmax: number;\r\n subdivisions?: { w: number; h: number };\r\n precision?: { w: number; h: number };\r\n}): VertexData {\r\n const xmin = options.xmin !== undefined && options.xmin !== null ? options.xmin : -1.0;\r\n const zmin = options.zmin !== undefined && options.zmin !== null ? options.zmin : -1.0;\r\n const xmax = options.xmax !== undefined && options.xmax !== null ? options.xmax : 1.0;\r\n const zmax = options.zmax !== undefined && options.zmax !== null ? options.zmax : 1.0;\r\n const subdivisions = options.subdivisions || { w: 1, h: 1 };\r\n const precision = options.precision || { w: 1, h: 1 };\r\n\r\n const indices = new Array();\r\n const positions = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n let row: number, col: number, tileRow: number, tileCol: number;\r\n\r\n subdivisions.h = subdivisions.h < 1 ? 1 : subdivisions.h;\r\n subdivisions.w = subdivisions.w < 1 ? 1 : subdivisions.w;\r\n precision.w = precision.w < 1 ? 1 : precision.w;\r\n precision.h = precision.h < 1 ? 1 : precision.h;\r\n\r\n const tileSize = {\r\n w: (xmax - xmin) / subdivisions.w,\r\n h: (zmax - zmin) / subdivisions.h,\r\n };\r\n\r\n function applyTile(xTileMin: number, zTileMin: number, xTileMax: number, zTileMax: number) {\r\n // Indices\r\n const base = positions.length / 3;\r\n const rowLength = precision.w + 1;\r\n for (row = 0; row < precision.h; row++) {\r\n for (col = 0; col < precision.w; col++) {\r\n const square = [base + col + row * rowLength, base + (col + 1) + row * rowLength, base + (col + 1) + (row + 1) * rowLength, base + col + (row + 1) * rowLength];\r\n\r\n indices.push(square[1]);\r\n indices.push(square[2]);\r\n indices.push(square[3]);\r\n indices.push(square[0]);\r\n indices.push(square[1]);\r\n indices.push(square[3]);\r\n }\r\n }\r\n\r\n // Position, normals and uvs\r\n const position = Vector3.Zero();\r\n const normal = new Vector3(0, 1.0, 0);\r\n for (row = 0; row <= precision.h; row++) {\r\n position.z = (row * (zTileMax - zTileMin)) / precision.h + zTileMin;\r\n for (col = 0; col <= precision.w; col++) {\r\n position.x = (col * (xTileMax - xTileMin)) / precision.w + xTileMin;\r\n position.y = 0;\r\n\r\n positions.push(position.x, position.y, position.z);\r\n normals.push(normal.x, normal.y, normal.z);\r\n uvs.push(col / precision.w, row / precision.h);\r\n }\r\n }\r\n }\r\n\r\n for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {\r\n for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {\r\n applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);\r\n }\r\n }\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates the VertexData of the Ground designed from a heightmap\r\n * @param options an object used to set the following parameters for the Ground, required and provided by CreateGroundFromHeightMap\r\n * * width the width (x direction) of the ground\r\n * * height the height (z direction) of the ground\r\n * * subdivisions the number of subdivisions per side\r\n * * minHeight the minimum altitude on the ground, optional, default 0\r\n * * maxHeight the maximum altitude on the ground, optional default 1\r\n * * colorFilter the filter to apply to the image pixel colors to compute the height, optional Color3, default (0.3, 0.59, 0.11)\r\n * * buffer the array holding the image color data\r\n * * bufferWidth the width of image\r\n * * bufferHeight the height of image\r\n * * alphaFilter Remove any data where the alpha channel is below this value, defaults 0 (all data visible)\r\n * @param options.width\r\n * @param options.height\r\n * @param options.subdivisions\r\n * @param options.minHeight\r\n * @param options.maxHeight\r\n * @param options.colorFilter\r\n * @param options.buffer\r\n * @param options.bufferWidth\r\n * @param options.bufferHeight\r\n * @param options.alphaFilter\r\n * @returns the VertexData of the Ground designed from a heightmap\r\n */\r\nexport function CreateGroundFromHeightMapVertexData(options: {\r\n width: number;\r\n height: number;\r\n subdivisions: number;\r\n minHeight: number;\r\n maxHeight: number;\r\n colorFilter: Color3;\r\n buffer: Uint8Array;\r\n bufferWidth: number;\r\n bufferHeight: number;\r\n alphaFilter: number;\r\n}): VertexData {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n let row, col;\r\n const filter = options.colorFilter || new Color3(0.3, 0.59, 0.11);\r\n const alphaFilter = options.alphaFilter || 0.0;\r\n let invert = false;\r\n\r\n if (options.minHeight > options.maxHeight) {\r\n invert = true;\r\n const temp = options.maxHeight;\r\n options.maxHeight = options.minHeight;\r\n options.minHeight = temp;\r\n }\r\n\r\n // Vertices\r\n for (row = 0; row <= options.subdivisions; row++) {\r\n for (col = 0; col <= options.subdivisions; col++) {\r\n const position = new Vector3(\r\n (col * options.width) / options.subdivisions - options.width / 2.0,\r\n 0,\r\n ((options.subdivisions - row) * options.height) / options.subdivisions - options.height / 2.0\r\n );\r\n\r\n // Compute height\r\n const heightMapX = (((position.x + options.width / 2) / options.width) * (options.bufferWidth - 1)) | 0;\r\n const heightMapY = ((1.0 - (position.z + options.height / 2) / options.height) * (options.bufferHeight - 1)) | 0;\r\n\r\n const pos = (heightMapX + heightMapY * options.bufferWidth) * 4;\r\n let r = options.buffer[pos] / 255.0;\r\n let g = options.buffer[pos + 1] / 255.0;\r\n let b = options.buffer[pos + 2] / 255.0;\r\n const a = options.buffer[pos + 3] / 255.0;\r\n\r\n if (invert) {\r\n r = 1.0 - r;\r\n g = 1.0 - g;\r\n b = 1.0 - b;\r\n }\r\n\r\n const gradient = r * filter.r + g * filter.g + b * filter.b;\r\n\r\n // If our alpha channel is not within our filter then we will assign a 'special' height\r\n // Then when building the indices, we will ignore any vertex that is using the special height\r\n if (a >= alphaFilter) {\r\n position.y = options.minHeight + (options.maxHeight - options.minHeight) * gradient;\r\n } else {\r\n position.y = options.minHeight - Epsilon; // We can't have a height below minHeight, normally.\r\n }\r\n\r\n // Add vertex\r\n positions.push(position.x, position.y, position.z);\r\n normals.push(0, 0, 0);\r\n uvs.push(col / options.subdivisions, 1.0 - row / options.subdivisions);\r\n }\r\n }\r\n\r\n // Indices\r\n for (row = 0; row < options.subdivisions; row++) {\r\n for (col = 0; col < options.subdivisions; col++) {\r\n // Calculate Indices\r\n const idx1 = col + 1 + (row + 1) * (options.subdivisions + 1);\r\n const idx2 = col + 1 + row * (options.subdivisions + 1);\r\n const idx3 = col + row * (options.subdivisions + 1);\r\n const idx4 = col + (row + 1) * (options.subdivisions + 1);\r\n\r\n // Check that all indices are visible (based on our special height)\r\n // Only display the vertex if all Indices are visible\r\n // Positions are stored x,y,z for each vertex, hence the * 3 and + 1 for height\r\n const isVisibleIdx1 = positions[idx1 * 3 + 1] >= options.minHeight;\r\n const isVisibleIdx2 = positions[idx2 * 3 + 1] >= options.minHeight;\r\n const isVisibleIdx3 = positions[idx3 * 3 + 1] >= options.minHeight;\r\n if (isVisibleIdx1 && isVisibleIdx2 && isVisibleIdx3) {\r\n indices.push(idx1);\r\n indices.push(idx2);\r\n indices.push(idx3);\r\n }\r\n\r\n const isVisibleIdx4 = positions[idx4 * 3 + 1] >= options.minHeight;\r\n if (isVisibleIdx4 && isVisibleIdx1 && isVisibleIdx3) {\r\n indices.push(idx4);\r\n indices.push(idx1);\r\n indices.push(idx3);\r\n }\r\n }\r\n }\r\n\r\n // Normals\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a ground mesh\r\n * * The parameters `width` and `height` (floats, default 1) set the width and height sizes of the ground\r\n * * The parameter `subdivisions` (positive integer) sets the number of subdivisions per side\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.width\r\n * @param options.height\r\n * @param options.subdivisions\r\n * @param options.subdivisionsX\r\n * @param options.subdivisionsY\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the ground mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#ground\r\n */\r\nexport function CreateGround(\r\n name: string,\r\n options: { width?: number; height?: number; subdivisions?: number; subdivisionsX?: number; subdivisionsY?: number; updatable?: boolean } = {},\r\n scene?: Scene\r\n): GroundMesh {\r\n const ground = new GroundMesh(name, scene);\r\n ground._setReady(false);\r\n ground._subdivisionsX = options.subdivisionsX || options.subdivisions || 1;\r\n ground._subdivisionsY = options.subdivisionsY || options.subdivisions || 1;\r\n ground._width = options.width || 1;\r\n ground._height = options.height || 1;\r\n ground._maxX = ground._width / 2;\r\n ground._maxZ = ground._height / 2;\r\n ground._minX = -ground._maxX;\r\n ground._minZ = -ground._maxZ;\r\n\r\n const vertexData = CreateGroundVertexData(options);\r\n\r\n vertexData.applyToMesh(ground, options.updatable);\r\n\r\n ground._setReady(true);\r\n\r\n return ground;\r\n}\r\n\r\n/**\r\n * Creates a tiled ground mesh\r\n * * The parameters `xmin` and `xmax` (floats, default -1 and 1) set the ground minimum and maximum X coordinates\r\n * * The parameters `zmin` and `zmax` (floats, default -1 and 1) set the ground minimum and maximum Z coordinates\r\n * * The parameter `subdivisions` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the numbers of subdivisions on the ground width and height. Each subdivision is called a tile\r\n * * The parameter `precision` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the numbers of subdivisions on the ground width and height of each tile\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.xmin\r\n * @param options.zmin\r\n * @param options.xmax\r\n * @param options.zmax\r\n * @param options.subdivisions\r\n * @param options.subdivisions.w\r\n * @param options.subdivisions.h\r\n * @param options.precision\r\n * @param options.precision.w\r\n * @param options.precision.h\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the tiled ground mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#tiled-ground\r\n */\r\nexport function CreateTiledGround(\r\n name: string,\r\n options: { xmin: number; zmin: number; xmax: number; zmax: number; subdivisions?: { w: number; h: number }; precision?: { w: number; h: number }; updatable?: boolean },\r\n scene: Nullable = null\r\n): Mesh {\r\n const tiledGround = new Mesh(name, scene);\r\n\r\n const vertexData = CreateTiledGroundVertexData(options);\r\n\r\n vertexData.applyToMesh(tiledGround, options.updatable);\r\n\r\n return tiledGround;\r\n}\r\n\r\n/**\r\n * Creates a ground mesh from a height map\r\n * * The parameter `url` sets the URL of the height map image resource.\r\n * * The parameters `width` and `height` (positive floats, default 10) set the ground width and height sizes.\r\n * * The parameter `subdivisions` (positive integer, default 1) sets the number of subdivision per side.\r\n * * The parameter `minHeight` (float, default 0) is the minimum altitude on the ground.\r\n * * The parameter `maxHeight` (float, default 1) is the maximum altitude on the ground.\r\n * * The parameter `colorFilter` (optional Color3, default (0.3, 0.59, 0.11) ) is the filter to apply to the image pixel colors to compute the height.\r\n * * The parameter `onReady` is a javascript callback function that will be called once the mesh is just built (the height map download can last some time).\r\n * * The parameter `alphaFilter` will filter any data where the alpha channel is below this value, defaults 0 (all data visible)\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param url defines the url to the height map\r\n * @param options defines the options used to create the mesh\r\n * @param options.width\r\n * @param options.height\r\n * @param options.subdivisions\r\n * @param options.minHeight\r\n * @param options.maxHeight\r\n * @param options.colorFilter\r\n * @param options.alphaFilter\r\n * @param options.updatable\r\n * @param options.onReady\r\n * @param scene defines the hosting scene\r\n * @returns the ground mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/height_map\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#ground-from-a-height-map\r\n */\r\nexport function CreateGroundFromHeightMap(\r\n name: string,\r\n url: string,\r\n options: {\r\n width?: number;\r\n height?: number;\r\n subdivisions?: number;\r\n minHeight?: number;\r\n maxHeight?: number;\r\n colorFilter?: Color3;\r\n alphaFilter?: number;\r\n updatable?: boolean;\r\n onReady?: (mesh: GroundMesh) => void;\r\n } = {},\r\n scene: Nullable = null\r\n): GroundMesh {\r\n const width = options.width || 10.0;\r\n const height = options.height || 10.0;\r\n const subdivisions = options.subdivisions || 1 | 0;\r\n const minHeight = options.minHeight || 0.0;\r\n const maxHeight = options.maxHeight || 1.0;\r\n const filter = options.colorFilter || new Color3(0.3, 0.59, 0.11);\r\n const alphaFilter = options.alphaFilter || 0.0;\r\n const updatable = options.updatable;\r\n const onReady = options.onReady;\r\n\r\n scene = scene || EngineStore.LastCreatedScene!;\r\n\r\n const ground = new GroundMesh(name, scene);\r\n ground._subdivisionsX = subdivisions;\r\n ground._subdivisionsY = subdivisions;\r\n ground._width = width;\r\n ground._height = height;\r\n ground._maxX = ground._width / 2.0;\r\n ground._maxZ = ground._height / 2.0;\r\n ground._minX = -ground._maxX;\r\n ground._minZ = -ground._maxZ;\r\n\r\n ground._setReady(false);\r\n\r\n const onload = (img: HTMLImageElement | ImageBitmap) => {\r\n const bufferWidth = img.width;\r\n const bufferHeight = img.height;\r\n\r\n if (scene!.isDisposed) {\r\n return;\r\n }\r\n\r\n const buffer = scene?.getEngine().resizeImageBitmap(img, bufferWidth, bufferHeight);\r\n\r\n const vertexData = CreateGroundFromHeightMapVertexData({\r\n width: width,\r\n height: height,\r\n subdivisions: subdivisions,\r\n minHeight: minHeight,\r\n maxHeight: maxHeight,\r\n colorFilter: filter,\r\n buffer: buffer,\r\n bufferWidth: bufferWidth,\r\n bufferHeight: bufferHeight,\r\n alphaFilter: alphaFilter,\r\n });\r\n\r\n vertexData.applyToMesh(ground, updatable);\r\n\r\n //execute ready callback, if set\r\n if (onReady) {\r\n onReady(ground);\r\n }\r\n\r\n ground._setReady(true);\r\n };\r\n\r\n Tools.LoadImage(url, onload, () => {}, scene.offlineProvider);\r\n\r\n return ground;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const GroundBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateGround,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateGroundFromHeightMap,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTiledGround,\r\n};\r\n\r\nVertexData.CreateGround = CreateGroundVertexData;\r\nVertexData.CreateTiledGround = CreateTiledGroundVertexData;\r\nVertexData.CreateGroundFromHeightMap = CreateGroundFromHeightMapVertexData;\r\n\r\nMesh.CreateGround = (name: string, width: number, height: number, subdivisions: number, scene?: Scene, updatable?: boolean): Mesh => {\r\n const options = {\r\n width,\r\n height,\r\n subdivisions,\r\n updatable,\r\n };\r\n\r\n return CreateGround(name, options, scene);\r\n};\r\n\r\nMesh.CreateTiledGround = (\r\n name: string,\r\n xmin: number,\r\n zmin: number,\r\n xmax: number,\r\n zmax: number,\r\n subdivisions: { w: number; h: number },\r\n precision: { w: number; h: number },\r\n scene: Scene,\r\n updatable?: boolean\r\n): Mesh => {\r\n const options = {\r\n xmin,\r\n zmin,\r\n xmax,\r\n zmax,\r\n subdivisions,\r\n precision,\r\n updatable,\r\n };\r\n\r\n return CreateTiledGround(name, options, scene);\r\n};\r\n\r\nMesh.CreateGroundFromHeightMap = (\r\n name: string,\r\n url: string,\r\n width: number,\r\n height: number,\r\n subdivisions: number,\r\n minHeight: number,\r\n maxHeight: number,\r\n scene: Scene,\r\n updatable?: boolean,\r\n onReady?: (mesh: GroundMesh) => void,\r\n alphaFilter?: number\r\n): GroundMesh => {\r\n const options = {\r\n width,\r\n height,\r\n subdivisions,\r\n minHeight,\r\n maxHeight,\r\n updatable,\r\n onReady,\r\n alphaFilter,\r\n };\r\n\r\n return CreateGroundFromHeightMap(name, url, options, scene);\r\n};\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\nimport { CreateGroundVertexData } from \"./groundBuilder\";\r\n\r\n/**\r\n * Creates the VertexData for a box\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * size sets the width, height and depth of the box to the value of size, optional default 1\r\n * * width sets the width (x direction) of the box, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the box, overwrites the height set by size, optional, default size\r\n * * depth sets the depth (z direction) of the box, overwrites the depth set by size, optional, default size\r\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\r\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.wrap\r\n * @param options.topBaseAt\r\n * @param options.bottomBaseAt\r\n * @returns the VertexData of the box\r\n */\r\nexport function CreateBoxVertexData(options: {\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n topBaseAt?: number;\r\n bottomBaseAt?: number;\r\n}): VertexData {\r\n const nbFaces = 6;\r\n let indices = [0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23];\r\n const normals = [\r\n 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0,\r\n 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0,\r\n ];\r\n const uvs = [];\r\n let positions = [];\r\n const width = options.width || options.size || 1;\r\n const height = options.height || options.size || 1;\r\n const depth = options.depth || options.size || 1;\r\n const wrap = options.wrap || false;\r\n let topBaseAt = options.topBaseAt === void 0 ? 1 : options.topBaseAt;\r\n let bottomBaseAt = options.bottomBaseAt === void 0 ? 0 : options.bottomBaseAt;\r\n topBaseAt = (topBaseAt + 4) % 4; // places values as 0 to 3\r\n bottomBaseAt = (bottomBaseAt + 4) % 4; // places values as 0 to 3\r\n const topOrder = [2, 0, 3, 1];\r\n const bottomOrder = [2, 0, 1, 3];\r\n let topIndex = topOrder[topBaseAt];\r\n let bottomIndex = bottomOrder[bottomBaseAt];\r\n let basePositions = [\r\n 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1,\r\n 1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1,\r\n ];\r\n if (wrap) {\r\n indices = [2, 3, 0, 2, 0, 1, 4, 5, 6, 4, 6, 7, 9, 10, 11, 9, 11, 8, 12, 14, 15, 12, 13, 14];\r\n basePositions = [\r\n -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1,\r\n ];\r\n let topFaceBase: any = [\r\n [1, 1, 1],\r\n [-1, 1, 1],\r\n [-1, 1, -1],\r\n [1, 1, -1],\r\n ];\r\n let bottomFaceBase: any = [\r\n [-1, -1, 1],\r\n [1, -1, 1],\r\n [1, -1, -1],\r\n [-1, -1, -1],\r\n ];\r\n const topFaceOrder: any = [17, 18, 19, 16];\r\n const bottomFaceOrder: any = [22, 23, 20, 21];\r\n while (topIndex > 0) {\r\n topFaceBase.unshift(topFaceBase.pop());\r\n topFaceOrder.unshift(topFaceOrder.pop());\r\n topIndex--;\r\n }\r\n while (bottomIndex > 0) {\r\n bottomFaceBase.unshift(bottomFaceBase.pop());\r\n bottomFaceOrder.unshift(bottomFaceOrder.pop());\r\n bottomIndex--;\r\n }\r\n topFaceBase = topFaceBase.flat();\r\n bottomFaceBase = bottomFaceBase.flat();\r\n basePositions = basePositions.concat(topFaceBase).concat(bottomFaceBase);\r\n indices.push(topFaceOrder[0], topFaceOrder[2], topFaceOrder[3], topFaceOrder[0], topFaceOrder[1], topFaceOrder[2]);\r\n indices.push(bottomFaceOrder[0], bottomFaceOrder[2], bottomFaceOrder[3], bottomFaceOrder[0], bottomFaceOrder[1], bottomFaceOrder[2]);\r\n }\r\n const scaleArray = [width / 2, height / 2, depth / 2];\r\n positions = basePositions.reduce((accumulator: Array, currentValue, currentIndex) => accumulator.concat(currentValue * scaleArray[currentIndex % 3]), []);\r\n\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n const faceUV: Vector4[] = options.faceUV || new Array(6);\r\n const faceColors = options.faceColors;\r\n const colors = [];\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < 6; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n // Create each face in turn.\r\n for (let index = 0; index < nbFaces; index++) {\r\n uvs.push(faceUV[index].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].w : faceUV[index].w);\r\n uvs.push(faceUV[index].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].w : faceUV[index].w);\r\n uvs.push(faceUV[index].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].y : faceUV[index].y);\r\n uvs.push(faceUV[index].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[index].y : faceUV[index].y);\r\n if (faceColors) {\r\n for (let c = 0; c < 4; c++) {\r\n colors.push(faceColors[index].r, faceColors[index].g, faceColors[index].b, faceColors[index].a);\r\n }\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates the VertexData for a segmented box\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * size sets the width, height and depth of the box to the value of size, optional default 1\r\n * * width sets the width (x direction) of the box, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the box, overwrites the height set by size, optional, default size\r\n * * depth sets the depth (z direction) of the box, overwrites the depth set by size, optional, default size\r\n * * segments sets the number of segments on the all axis (1 by default)\r\n * * widthSegments sets the number of segments on the x axis (1 by default)\r\n * * heightSegments sets the number of segments on the y axis (1 by default)\r\n * * depthSegments sets the number of segments on the z axis (1 by default)\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.segments\r\n * @param options.widthSegments\r\n * @param options.heightSegments\r\n * @param options.depthSegments\r\n * @returns the VertexData of the box\r\n */\r\nexport function CreateSegmentedBoxVertexData(options: {\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n segments?: number;\r\n widthSegments?: number;\r\n heightSegments?: number;\r\n depthSegments?: number;\r\n}): VertexData {\r\n const width = options.width || options.size || 1;\r\n const height = options.height || options.size || 1;\r\n const depth = options.depth || options.size || 1;\r\n const widthSegments = (options.widthSegments || options.segments || 1) | 0;\r\n const heightSegments = (options.heightSegments || options.segments || 1) | 0;\r\n const depthSegments = (options.depthSegments || options.segments || 1) | 0;\r\n const rotationMatrix = new Matrix();\r\n const translationMatrix = new Matrix();\r\n const transformMatrix = new Matrix();\r\n\r\n const bottomPlane = CreateGroundVertexData({ width: width, height: depth, subdivisionsX: widthSegments, subdivisionsY: depthSegments });\r\n Matrix.TranslationToRef(0, -height / 2, 0, translationMatrix);\r\n Matrix.RotationZToRef(Math.PI, rotationMatrix);\r\n rotationMatrix.multiplyToRef(translationMatrix, transformMatrix);\r\n bottomPlane.transform(transformMatrix);\r\n\r\n const topPlane = CreateGroundVertexData({ width: width, height: depth, subdivisionsX: widthSegments, subdivisionsY: depthSegments });\r\n Matrix.TranslationToRef(0, height / 2, 0, transformMatrix);\r\n topPlane.transform(transformMatrix);\r\n\r\n const negXPlane = CreateGroundVertexData({ width: height, height: depth, subdivisionsX: heightSegments, subdivisionsY: depthSegments });\r\n Matrix.TranslationToRef(-width / 2, 0, 0, translationMatrix);\r\n Matrix.RotationZToRef(Math.PI / 2, rotationMatrix);\r\n rotationMatrix.multiplyToRef(translationMatrix, transformMatrix);\r\n negXPlane.transform(transformMatrix);\r\n\r\n const posXPlane = CreateGroundVertexData({ width: height, height: depth, subdivisionsX: heightSegments, subdivisionsY: depthSegments });\r\n Matrix.TranslationToRef(width / 2, 0, 0, translationMatrix);\r\n Matrix.RotationZToRef(-Math.PI / 2, rotationMatrix);\r\n rotationMatrix.multiplyToRef(translationMatrix, transformMatrix);\r\n posXPlane.transform(transformMatrix);\r\n\r\n const negZPlane = CreateGroundVertexData({ width: width, height: height, subdivisionsX: widthSegments, subdivisionsY: heightSegments });\r\n Matrix.TranslationToRef(0, 0, -depth / 2, translationMatrix);\r\n Matrix.RotationXToRef(-Math.PI / 2, rotationMatrix);\r\n rotationMatrix.multiplyToRef(translationMatrix, transformMatrix);\r\n negZPlane.transform(transformMatrix);\r\n\r\n const posZPlane = CreateGroundVertexData({ width: width, height: height, subdivisionsX: widthSegments, subdivisionsY: heightSegments });\r\n Matrix.TranslationToRef(0, 0, depth / 2, translationMatrix);\r\n Matrix.RotationXToRef(Math.PI / 2, rotationMatrix);\r\n rotationMatrix.multiplyToRef(translationMatrix, transformMatrix);\r\n posZPlane.transform(transformMatrix);\r\n\r\n // Result\r\n bottomPlane.merge([topPlane, posXPlane, negXPlane, negZPlane, posZPlane], true);\r\n\r\n return bottomPlane;\r\n}\r\n\r\n/**\r\n * Creates a box mesh\r\n * * The parameter `size` sets the size (float) of each box side (default 1)\r\n * * You can set some different box dimensions by using the parameters `width`, `height` and `depth` (all by default have the same value of `size`)\r\n * * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of 6 Color3 elements) and `faceUV` (an array of 6 Vector4 elements)\r\n * * Please read this tutorial : https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#box\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.wrap\r\n * @param options.topBaseAt\r\n * @param options.bottomBaseAt\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the box mesh\r\n */\r\nexport function CreateBox(\r\n name: string,\r\n options: {\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n topBaseAt?: number;\r\n bottomBaseAt?: number;\r\n updatable?: boolean;\r\n } = {},\r\n scene: Nullable = null\r\n): Mesh {\r\n const box = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n box._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateBoxVertexData(options);\r\n\r\n vertexData.applyToMesh(box, options.updatable);\r\n\r\n return box;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated please use CreateBox directly\r\n */\r\nexport const BoxBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateBox,\r\n};\r\n\r\n// Side effects\r\nVertexData.CreateBox = CreateBoxVertexData;\r\n\r\nMesh.CreateBox = (name: string, size: number, scene: Nullable = null, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n size,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateBox(name, options, scene);\r\n};\r\n","import { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport { ArcRotateCamera } from \"../Cameras/arcRotateCamera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { MirrorTexture } from \"../Materials/Textures/mirrorTexture\";\r\nimport { CubeTexture } from \"../Materials/Textures/cubeTexture\";\r\nimport { BackgroundMaterial } from \"../Materials/Background/backgroundMaterial\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport { CreatePlane } from \"../Meshes/Builders/planeBuilder\";\r\nimport { CreateBox } from \"../Meshes/Builders/boxBuilder\";\r\nimport { Plane } from \"../Maths/math.plane\";\r\n\r\n/**\r\n * Represents the different options available during the creation of\r\n * a Environment helper.\r\n *\r\n * This can control the default ground, skybox and image processing setup of your scene.\r\n */\r\nexport interface IEnvironmentHelperOptions {\r\n /**\r\n * Specifies whether or not to create a ground.\r\n * True by default.\r\n */\r\n createGround: boolean;\r\n /**\r\n * Specifies the ground size.\r\n * 15 by default.\r\n */\r\n groundSize: number;\r\n /**\r\n * The texture used on the ground for the main color.\r\n * Comes from the BabylonJS CDN by default.\r\n *\r\n * Remarks: Can be either a texture or a url.\r\n */\r\n groundTexture: string | BaseTexture;\r\n /**\r\n * The color mixed in the ground texture by default.\r\n * BabylonJS clearColor by default.\r\n */\r\n groundColor: Color3;\r\n /**\r\n * Specifies the ground opacity.\r\n * 1 by default.\r\n */\r\n groundOpacity: number;\r\n /**\r\n * Enables the ground to receive shadows.\r\n * True by default.\r\n */\r\n enableGroundShadow: boolean;\r\n /**\r\n * Helps preventing the shadow to be fully black on the ground.\r\n * 0.5 by default.\r\n */\r\n groundShadowLevel: number;\r\n /**\r\n * Creates a mirror texture attach to the ground.\r\n * false by default.\r\n */\r\n enableGroundMirror: boolean;\r\n /**\r\n * Specifies the ground mirror size ratio.\r\n * 0.3 by default as the default kernel is 64.\r\n */\r\n groundMirrorSizeRatio: number;\r\n /**\r\n * Specifies the ground mirror blur kernel size.\r\n * 64 by default.\r\n */\r\n groundMirrorBlurKernel: number;\r\n /**\r\n * Specifies the ground mirror visibility amount.\r\n * 1 by default\r\n */\r\n groundMirrorAmount: number;\r\n /**\r\n * Specifies the ground mirror reflectance weight.\r\n * This uses the standard weight of the background material to setup the fresnel effect\r\n * of the mirror.\r\n * 1 by default.\r\n */\r\n groundMirrorFresnelWeight: number;\r\n /**\r\n * Specifies the ground mirror Falloff distance.\r\n * This can helps reducing the size of the reflection.\r\n * 0 by Default.\r\n */\r\n groundMirrorFallOffDistance: number;\r\n /**\r\n * Specifies the ground mirror texture type.\r\n * Unsigned Int by Default.\r\n */\r\n groundMirrorTextureType: number;\r\n /**\r\n * Specifies a bias applied to the ground vertical position to prevent z-fighting with\r\n * the shown objects.\r\n */\r\n groundYBias: number;\r\n\r\n /**\r\n * Specifies whether or not to create a skybox.\r\n * True by default.\r\n */\r\n createSkybox: boolean;\r\n /**\r\n * Specifies the skybox size.\r\n * 20 by default.\r\n */\r\n skyboxSize: number;\r\n /**\r\n * The texture used on the skybox for the main color.\r\n * Comes from the BabylonJS CDN by default.\r\n *\r\n * Remarks: Can be either a texture or a url.\r\n */\r\n skyboxTexture: string | BaseTexture;\r\n /**\r\n * The color mixed in the skybox texture by default.\r\n * BabylonJS clearColor by default.\r\n */\r\n skyboxColor: Color3;\r\n\r\n /**\r\n * The background rotation around the Y axis of the scene.\r\n * This helps aligning the key lights of your scene with the background.\r\n * 0 by default.\r\n */\r\n backgroundYRotation: number;\r\n\r\n /**\r\n * Compute automatically the size of the elements to best fit with the scene.\r\n */\r\n sizeAuto: boolean;\r\n\r\n /**\r\n * Default position of the rootMesh if autoSize is not true.\r\n */\r\n rootPosition: Vector3;\r\n\r\n /**\r\n * Sets up the image processing in the scene.\r\n * true by default.\r\n */\r\n setupImageProcessing: boolean;\r\n\r\n /**\r\n * The texture used as your environment texture in the scene.\r\n * Comes from the BabylonJS CDN by default and in use if setupImageProcessing is true.\r\n *\r\n * Remarks: Can be either a texture or a url.\r\n */\r\n environmentTexture: string | BaseTexture;\r\n\r\n /**\r\n * The value of the exposure to apply to the scene.\r\n * 0.6 by default if setupImageProcessing is true.\r\n */\r\n cameraExposure: number;\r\n\r\n /**\r\n * The value of the contrast to apply to the scene.\r\n * 1.6 by default if setupImageProcessing is true.\r\n */\r\n cameraContrast: number;\r\n\r\n /**\r\n * Specifies whether or not tonemapping should be enabled in the scene.\r\n * true by default if setupImageProcessing is true.\r\n */\r\n toneMappingEnabled: boolean;\r\n}\r\n\r\ninterface ISceneSize {\r\n groundSize: number;\r\n skyboxSize: number;\r\n rootPosition: Vector3;\r\n}\r\n\r\n/**\r\n * The EnvironmentHelper class can be used to add a fully featured non-expensive background to your scene.\r\n * It includes by default a skybox and a ground relying on the BackgroundMaterial.\r\n * It also helps with the default setup of your ImageProcessingConfiguration.\r\n */\r\nexport class EnvironmentHelper {\r\n /**\r\n * Default ground texture URL.\r\n */\r\n private static _GroundTextureCDNUrl = \"https://assets.babylonjs.com/environments/backgroundGround.png\";\r\n\r\n /**\r\n * Default skybox texture URL.\r\n */\r\n private static _SkyboxTextureCDNUrl = \"https://assets.babylonjs.com/environments/backgroundSkybox.dds\";\r\n\r\n /**\r\n * Default environment texture URL.\r\n */\r\n private static _EnvironmentTextureCDNUrl = \"https://assets.babylonjs.com/environments/environmentSpecular.env\";\r\n\r\n /**\r\n * Creates the default options for the helper.\r\n * @param scene The scene the environment helper belongs to.\r\n */\r\n private static _GetDefaultOptions(scene: Scene): IEnvironmentHelperOptions {\r\n return {\r\n createGround: true,\r\n groundSize: 15,\r\n groundTexture: this._GroundTextureCDNUrl,\r\n groundColor: new Color3(0.2, 0.2, 0.3).toLinearSpace(scene.getEngine().useExactSrgbConversions).scale(3),\r\n groundOpacity: 0.9,\r\n enableGroundShadow: true,\r\n groundShadowLevel: 0.5,\r\n\r\n enableGroundMirror: false,\r\n groundMirrorSizeRatio: 0.3,\r\n groundMirrorBlurKernel: 64,\r\n groundMirrorAmount: 1,\r\n groundMirrorFresnelWeight: 1,\r\n groundMirrorFallOffDistance: 0,\r\n groundMirrorTextureType: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n\r\n groundYBias: 0.00001,\r\n\r\n createSkybox: true,\r\n skyboxSize: 20,\r\n skyboxTexture: this._SkyboxTextureCDNUrl,\r\n skyboxColor: new Color3(0.2, 0.2, 0.3).toLinearSpace(scene.getEngine().useExactSrgbConversions).scale(3),\r\n\r\n backgroundYRotation: 0,\r\n sizeAuto: true,\r\n rootPosition: Vector3.Zero(),\r\n\r\n setupImageProcessing: true,\r\n environmentTexture: this._EnvironmentTextureCDNUrl,\r\n cameraExposure: 0.8,\r\n cameraContrast: 1.2,\r\n toneMappingEnabled: true,\r\n };\r\n }\r\n\r\n private _rootMesh: Mesh;\r\n /**\r\n * Gets the root mesh created by the helper.\r\n */\r\n public get rootMesh(): Mesh {\r\n return this._rootMesh;\r\n }\r\n\r\n private _skybox: Nullable;\r\n /**\r\n * Gets the skybox created by the helper.\r\n */\r\n public get skybox(): Nullable {\r\n return this._skybox;\r\n }\r\n\r\n private _skyboxTexture: Nullable;\r\n /**\r\n * Gets the skybox texture created by the helper.\r\n */\r\n public get skyboxTexture(): Nullable {\r\n return this._skyboxTexture;\r\n }\r\n\r\n private _skyboxMaterial: Nullable;\r\n /**\r\n * Gets the skybox material created by the helper.\r\n */\r\n public get skyboxMaterial(): Nullable {\r\n return this._skyboxMaterial;\r\n }\r\n\r\n private _ground: Nullable;\r\n /**\r\n * Gets the ground mesh created by the helper.\r\n */\r\n public get ground(): Nullable {\r\n return this._ground;\r\n }\r\n\r\n private _groundTexture: Nullable;\r\n /**\r\n * Gets the ground texture created by the helper.\r\n */\r\n public get groundTexture(): Nullable {\r\n return this._groundTexture;\r\n }\r\n\r\n private _groundMirror: Nullable;\r\n /**\r\n * Gets the ground mirror created by the helper.\r\n */\r\n public get groundMirror(): Nullable {\r\n return this._groundMirror;\r\n }\r\n\r\n /**\r\n * Gets the ground mirror render list to helps pushing the meshes\r\n * you wish in the ground reflection.\r\n */\r\n public get groundMirrorRenderList(): Nullable {\r\n if (this._groundMirror) {\r\n return this._groundMirror.renderList;\r\n }\r\n return null;\r\n }\r\n\r\n private _groundMaterial: Nullable;\r\n /**\r\n * Gets the ground material created by the helper.\r\n */\r\n public get groundMaterial(): Nullable {\r\n return this._groundMaterial;\r\n }\r\n\r\n /**\r\n * Stores the creation options.\r\n */\r\n private readonly _scene: Scene;\r\n private _options: IEnvironmentHelperOptions;\r\n\r\n /**\r\n * This observable will be notified with any error during the creation of the environment,\r\n * mainly texture creation errors.\r\n */\r\n public onErrorObservable: Observable<{ message?: string; exception?: any }>;\r\n\r\n /**\r\n * constructor\r\n * @param options Defines the options we want to customize the helper\r\n * @param scene The scene to add the material to\r\n */\r\n constructor(options: Partial, scene: Scene) {\r\n this._options = {\r\n ...EnvironmentHelper._GetDefaultOptions(scene),\r\n ...options,\r\n };\r\n this._scene = scene;\r\n this.onErrorObservable = new Observable();\r\n\r\n this._setupBackground();\r\n this._setupImageProcessing();\r\n }\r\n\r\n /**\r\n * Updates the background according to the new options\r\n * @param options\r\n */\r\n public updateOptions(options: Partial) {\r\n const newOptions = {\r\n ...this._options,\r\n ...options,\r\n };\r\n\r\n if (this._ground && !newOptions.createGround) {\r\n this._ground.dispose();\r\n this._ground = null;\r\n }\r\n\r\n if (this._groundMaterial && !newOptions.createGround) {\r\n this._groundMaterial.dispose();\r\n this._groundMaterial = null;\r\n }\r\n\r\n if (this._groundTexture) {\r\n if (this._options.groundTexture != newOptions.groundTexture) {\r\n this._groundTexture.dispose();\r\n this._groundTexture = null;\r\n }\r\n }\r\n\r\n if (this._skybox && !newOptions.createSkybox) {\r\n this._skybox.dispose();\r\n this._skybox = null;\r\n }\r\n\r\n if (this._skyboxMaterial && !newOptions.createSkybox) {\r\n this._skyboxMaterial.dispose();\r\n this._skyboxMaterial = null;\r\n }\r\n\r\n if (this._skyboxTexture) {\r\n if (this._options.skyboxTexture != newOptions.skyboxTexture) {\r\n this._skyboxTexture.dispose();\r\n this._skyboxTexture = null;\r\n }\r\n }\r\n\r\n if (this._groundMirror && !newOptions.enableGroundMirror) {\r\n this._groundMirror.dispose();\r\n this._groundMirror = null;\r\n }\r\n\r\n if (this._scene.environmentTexture) {\r\n if (this._options.environmentTexture != newOptions.environmentTexture) {\r\n this._scene.environmentTexture.dispose();\r\n }\r\n }\r\n\r\n this._options = newOptions;\r\n\r\n this._setupBackground();\r\n this._setupImageProcessing();\r\n }\r\n\r\n /**\r\n * Sets the primary color of all the available elements.\r\n * @param color the main color to affect to the ground and the background\r\n */\r\n public setMainColor(color: Color3): void {\r\n if (this.groundMaterial) {\r\n this.groundMaterial.primaryColor = color;\r\n }\r\n\r\n if (this.skyboxMaterial) {\r\n this.skyboxMaterial.primaryColor = color;\r\n }\r\n\r\n if (this.groundMirror) {\r\n this.groundMirror.clearColor = new Color4(color.r, color.g, color.b, 1.0);\r\n }\r\n }\r\n\r\n /**\r\n * Setup the image processing according to the specified options.\r\n */\r\n private _setupImageProcessing(): void {\r\n if (this._options.setupImageProcessing) {\r\n this._scene.imageProcessingConfiguration.contrast = this._options.cameraContrast;\r\n this._scene.imageProcessingConfiguration.exposure = this._options.cameraExposure;\r\n this._scene.imageProcessingConfiguration.toneMappingEnabled = this._options.toneMappingEnabled;\r\n this._setupEnvironmentTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Setup the environment texture according to the specified options.\r\n */\r\n private _setupEnvironmentTexture(): void {\r\n if (this._scene.environmentTexture) {\r\n return;\r\n }\r\n\r\n if (this._options.environmentTexture instanceof BaseTexture) {\r\n this._scene.environmentTexture = this._options.environmentTexture;\r\n return;\r\n }\r\n\r\n const environmentTexture = CubeTexture.CreateFromPrefilteredData(this._options.environmentTexture, this._scene);\r\n this._scene.environmentTexture = environmentTexture;\r\n }\r\n\r\n /**\r\n * Setup the background according to the specified options.\r\n */\r\n private _setupBackground(): void {\r\n if (!this._rootMesh) {\r\n this._rootMesh = new Mesh(\"BackgroundHelper\", this._scene);\r\n }\r\n this._rootMesh.rotation.y = this._options.backgroundYRotation;\r\n\r\n const sceneSize = this._getSceneSize();\r\n if (this._options.createGround) {\r\n this._setupGround(sceneSize);\r\n this._setupGroundMaterial();\r\n this._setupGroundDiffuseTexture();\r\n\r\n if (this._options.enableGroundMirror) {\r\n this._setupGroundMirrorTexture(sceneSize);\r\n }\r\n this._setupMirrorInGroundMaterial();\r\n }\r\n\r\n if (this._options.createSkybox) {\r\n this._setupSkybox(sceneSize);\r\n this._setupSkyboxMaterial();\r\n this._setupSkyboxReflectionTexture();\r\n }\r\n\r\n this._rootMesh.position.x = sceneSize.rootPosition.x;\r\n this._rootMesh.position.z = sceneSize.rootPosition.z;\r\n this._rootMesh.position.y = sceneSize.rootPosition.y;\r\n }\r\n\r\n /**\r\n * Get the scene sizes according to the setup.\r\n */\r\n private _getSceneSize(): ISceneSize {\r\n let groundSize = this._options.groundSize;\r\n let skyboxSize = this._options.skyboxSize;\r\n let rootPosition = this._options.rootPosition;\r\n if (!this._scene.meshes || this._scene.meshes.length === 1) {\r\n // 1 only means the root of the helper.\r\n return { groundSize, skyboxSize, rootPosition };\r\n }\r\n\r\n const sceneExtends = this._scene.getWorldExtends((mesh) => {\r\n return mesh !== this._ground && mesh !== this._rootMesh && mesh !== this._skybox;\r\n });\r\n const sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);\r\n\r\n if (this._options.sizeAuto) {\r\n if (this._scene.activeCamera instanceof ArcRotateCamera && this._scene.activeCamera.upperRadiusLimit) {\r\n groundSize = this._scene.activeCamera.upperRadiusLimit * 2;\r\n skyboxSize = groundSize;\r\n }\r\n\r\n const sceneDiagonalLenght = sceneDiagonal.length();\r\n if (sceneDiagonalLenght > groundSize) {\r\n groundSize = sceneDiagonalLenght * 2;\r\n skyboxSize = groundSize;\r\n }\r\n\r\n // 10 % bigger.\r\n groundSize *= 1.1;\r\n skyboxSize *= 1.5;\r\n rootPosition = sceneExtends.min.add(sceneDiagonal.scale(0.5));\r\n rootPosition.y = sceneExtends.min.y - this._options.groundYBias;\r\n }\r\n\r\n return { groundSize, skyboxSize, rootPosition };\r\n }\r\n\r\n /**\r\n * Setup the ground according to the specified options.\r\n * @param sceneSize\r\n */\r\n private _setupGround(sceneSize: ISceneSize): void {\r\n if (!this._ground || this._ground.isDisposed()) {\r\n this._ground = CreatePlane(\"BackgroundPlane\", { size: sceneSize.groundSize }, this._scene);\r\n this._ground.rotation.x = Math.PI / 2; // Face up by default.\r\n this._ground.parent = this._rootMesh;\r\n this._ground.onDisposeObservable.add(() => {\r\n this._ground = null;\r\n });\r\n }\r\n\r\n this._ground.receiveShadows = this._options.enableGroundShadow;\r\n }\r\n\r\n /**\r\n * Setup the ground material according to the specified options.\r\n */\r\n private _setupGroundMaterial(): void {\r\n if (!this._groundMaterial) {\r\n this._groundMaterial = new BackgroundMaterial(\"BackgroundPlaneMaterial\", this._scene);\r\n }\r\n this._groundMaterial.alpha = this._options.groundOpacity;\r\n this._groundMaterial.alphaMode = Constants.ALPHA_PREMULTIPLIED_PORTERDUFF;\r\n this._groundMaterial.shadowLevel = this._options.groundShadowLevel;\r\n this._groundMaterial.primaryColor = this._options.groundColor;\r\n this._groundMaterial.useRGBColor = false;\r\n this._groundMaterial.enableNoise = true;\r\n\r\n if (this._ground) {\r\n this._ground.material = this._groundMaterial;\r\n }\r\n }\r\n\r\n /**\r\n * Setup the ground diffuse texture according to the specified options.\r\n */\r\n private _setupGroundDiffuseTexture(): void {\r\n if (!this._groundMaterial) {\r\n return;\r\n }\r\n\r\n if (this._groundTexture) {\r\n return;\r\n }\r\n\r\n if (this._options.groundTexture instanceof BaseTexture) {\r\n this._groundMaterial.diffuseTexture = this._options.groundTexture;\r\n return;\r\n }\r\n\r\n this._groundTexture = new Texture(this._options.groundTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);\r\n this._groundTexture.gammaSpace = false;\r\n this._groundTexture.hasAlpha = true;\r\n this._groundMaterial.diffuseTexture = this._groundTexture;\r\n }\r\n\r\n /**\r\n * Setup the ground mirror texture according to the specified options.\r\n * @param sceneSize\r\n */\r\n private _setupGroundMirrorTexture(sceneSize: ISceneSize): void {\r\n const wrapping = Texture.CLAMP_ADDRESSMODE;\r\n if (!this._groundMirror) {\r\n this._groundMirror = new MirrorTexture(\r\n \"BackgroundPlaneMirrorTexture\",\r\n { ratio: this._options.groundMirrorSizeRatio },\r\n this._scene,\r\n false,\r\n this._options.groundMirrorTextureType,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n true\r\n );\r\n this._groundMirror.mirrorPlane = new Plane(0, -1, 0, sceneSize.rootPosition.y);\r\n this._groundMirror.anisotropicFilteringLevel = 1;\r\n this._groundMirror.wrapU = wrapping;\r\n this._groundMirror.wrapV = wrapping;\r\n\r\n if (this._groundMirror.renderList) {\r\n for (let i = 0; i < this._scene.meshes.length; i++) {\r\n const mesh = this._scene.meshes[i];\r\n if (mesh !== this._ground && mesh !== this._skybox && mesh !== this._rootMesh) {\r\n this._groundMirror.renderList.push(mesh);\r\n }\r\n }\r\n }\r\n }\r\n\r\n const gammaGround = this._options.groundColor.toGammaSpace(this._scene.getEngine().useExactSrgbConversions);\r\n this._groundMirror.clearColor = new Color4(gammaGround.r, gammaGround.g, gammaGround.b, 1);\r\n this._groundMirror.adaptiveBlurKernel = this._options.groundMirrorBlurKernel;\r\n }\r\n\r\n /**\r\n * Setup the ground to receive the mirror texture.\r\n */\r\n private _setupMirrorInGroundMaterial(): void {\r\n if (this._groundMaterial) {\r\n this._groundMaterial.reflectionTexture = this._groundMirror;\r\n this._groundMaterial.reflectionFresnel = true;\r\n this._groundMaterial.reflectionAmount = this._options.groundMirrorAmount;\r\n this._groundMaterial.reflectionStandardFresnelWeight = this._options.groundMirrorFresnelWeight;\r\n this._groundMaterial.reflectionFalloffDistance = this._options.groundMirrorFallOffDistance;\r\n }\r\n }\r\n\r\n /**\r\n * Setup the skybox according to the specified options.\r\n * @param sceneSize\r\n */\r\n private _setupSkybox(sceneSize: ISceneSize): void {\r\n if (!this._skybox || this._skybox.isDisposed()) {\r\n this._skybox = CreateBox(\"BackgroundSkybox\", { size: sceneSize.skyboxSize, sideOrientation: Mesh.BACKSIDE }, this._scene);\r\n this._skybox.onDisposeObservable.add(() => {\r\n this._skybox = null;\r\n });\r\n }\r\n this._skybox.parent = this._rootMesh;\r\n }\r\n\r\n /**\r\n * Setup the skybox material according to the specified options.\r\n */\r\n private _setupSkyboxMaterial(): void {\r\n if (!this._skybox) {\r\n return;\r\n }\r\n\r\n if (!this._skyboxMaterial) {\r\n this._skyboxMaterial = new BackgroundMaterial(\"BackgroundSkyboxMaterial\", this._scene);\r\n }\r\n this._skyboxMaterial.useRGBColor = false;\r\n this._skyboxMaterial.primaryColor = this._options.skyboxColor;\r\n this._skyboxMaterial.enableNoise = true;\r\n\r\n this._skybox.material = this._skyboxMaterial;\r\n }\r\n\r\n /**\r\n * Setup the skybox reflection texture according to the specified options.\r\n */\r\n private _setupSkyboxReflectionTexture(): void {\r\n if (!this._skyboxMaterial) {\r\n return;\r\n }\r\n\r\n if (this._skyboxTexture) {\r\n return;\r\n }\r\n\r\n if (this._options.skyboxTexture instanceof BaseTexture) {\r\n this._skyboxMaterial.reflectionTexture = this._options.skyboxTexture;\r\n return;\r\n }\r\n\r\n this._skyboxTexture = new CubeTexture(this._options.skyboxTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);\r\n this._skyboxTexture.coordinatesMode = Texture.SKYBOX_MODE;\r\n this._skyboxTexture.gammaSpace = false;\r\n this._skyboxMaterial.reflectionTexture = this._skyboxTexture;\r\n }\r\n\r\n private _errorHandler = (message?: string, exception?: any) => {\r\n this.onErrorObservable.notifyObservers({ message: message, exception: exception });\r\n };\r\n\r\n /**\r\n * Dispose all the elements created by the Helper.\r\n */\r\n public dispose(): void {\r\n if (this._groundMaterial) {\r\n this._groundMaterial.dispose(true, true);\r\n }\r\n if (this._skyboxMaterial) {\r\n this._skyboxMaterial.dispose(true, true);\r\n }\r\n this._rootMesh.dispose(false);\r\n }\r\n}\r\n","import { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport type { KeyboardInfo } from \"../../Events/keyboardEvents\";\r\nimport { KeyboardEventTypes } from \"../../Events/keyboardEvents\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n/**\r\n * Manage the keyboard inputs to control the movement of a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraKeyboardMoveInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: FreeCamera;\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the forward move of the camera.\r\n */\r\n @serialize()\r\n public keysUp = [38];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the upward move of the camera.\r\n */\r\n @serialize()\r\n public keysUpward = [33];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the backward move of the camera.\r\n */\r\n @serialize()\r\n public keysDown = [40];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the downward move of the camera.\r\n */\r\n @serialize()\r\n public keysDownward = [34];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.\r\n */\r\n @serialize()\r\n public keysLeft = [37];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the right strafe move of the camera.\r\n */\r\n @serialize()\r\n public keysRight = [39];\r\n\r\n /**\r\n * Defines the pointer angular sensibility along the X and Y axis or how fast is the camera rotating.\r\n */\r\n @serialize()\r\n public rotationSpeed = 0.5;\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the left rotation move of the camera.\r\n */\r\n @serialize()\r\n public keysRotateLeft: number[] = [];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the right rotation move of the camera.\r\n */\r\n @serialize()\r\n public keysRotateRight: number[] = [];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the up rotation move of the camera.\r\n */\r\n @serialize()\r\n public keysRotateUp: number[] = [];\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the down rotation move of the camera.\r\n */\r\n @serialize()\r\n public keysRotateDown: number[] = [];\r\n\r\n private _keys = new Array();\r\n private _onCanvasBlurObserver: Nullable>;\r\n private _onKeyboardObserver: Nullable>;\r\n private _engine: Engine;\r\n private _scene: Scene;\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n if (this._onCanvasBlurObserver) {\r\n return;\r\n }\r\n\r\n this._scene = this.camera.getScene();\r\n this._engine = this._scene.getEngine();\r\n\r\n this._onCanvasBlurObserver = this._engine.onCanvasBlurObservable.add(() => {\r\n this._keys.length = 0;\r\n });\r\n\r\n this._onKeyboardObserver = this._scene.onKeyboardObservable.add((info) => {\r\n const evt = info.event;\r\n if (!evt.metaKey) {\r\n if (info.type === KeyboardEventTypes.KEYDOWN) {\r\n if (\r\n this.keysUp.indexOf(evt.keyCode) !== -1 ||\r\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\r\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\r\n this.keysUpward.indexOf(evt.keyCode) !== -1 ||\r\n this.keysDownward.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateLeft.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateRight.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateUp.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateDown.indexOf(evt.keyCode) !== -1\r\n ) {\r\n const index = this._keys.indexOf(evt.keyCode);\r\n\r\n if (index === -1) {\r\n this._keys.push(evt.keyCode);\r\n }\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n }\r\n } else {\r\n if (\r\n this.keysUp.indexOf(evt.keyCode) !== -1 ||\r\n this.keysDown.indexOf(evt.keyCode) !== -1 ||\r\n this.keysLeft.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRight.indexOf(evt.keyCode) !== -1 ||\r\n this.keysUpward.indexOf(evt.keyCode) !== -1 ||\r\n this.keysDownward.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateLeft.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateRight.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateUp.indexOf(evt.keyCode) !== -1 ||\r\n this.keysRotateDown.indexOf(evt.keyCode) !== -1\r\n ) {\r\n const index = this._keys.indexOf(evt.keyCode);\r\n\r\n if (index >= 0) {\r\n this._keys.splice(index, 1);\r\n }\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n }\r\n }\r\n }\r\n });\r\n }\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._scene) {\r\n if (this._onKeyboardObserver) {\r\n this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);\r\n }\r\n\r\n if (this._onCanvasBlurObserver) {\r\n this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);\r\n }\r\n this._onKeyboardObserver = null;\r\n this._onCanvasBlurObserver = null;\r\n }\r\n this._keys.length = 0;\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (this._onKeyboardObserver) {\r\n const camera = this.camera;\r\n // Keyboard\r\n for (let index = 0; index < this._keys.length; index++) {\r\n const keyCode = this._keys[index];\r\n const speed = camera._computeLocalCameraSpeed();\r\n\r\n if (this.keysLeft.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(-speed, 0, 0);\r\n } else if (this.keysUp.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, 0, speed);\r\n } else if (this.keysRight.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(speed, 0, 0);\r\n } else if (this.keysDown.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, 0, -speed);\r\n } else if (this.keysUpward.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, speed, 0);\r\n } else if (this.keysDownward.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, -speed, 0);\r\n } else if (this.keysRotateLeft.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, 0, 0);\r\n camera.cameraRotation.y -= this._getLocalRotation();\r\n } else if (this.keysRotateRight.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, 0, 0);\r\n camera.cameraRotation.y += this._getLocalRotation();\r\n } else if (this.keysRotateUp.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, 0, 0);\r\n camera.cameraRotation.x -= this._getLocalRotation();\r\n } else if (this.keysRotateDown.indexOf(keyCode) !== -1) {\r\n camera._localDirection.copyFromFloats(0, 0, 0);\r\n camera.cameraRotation.x += this._getLocalRotation();\r\n }\r\n\r\n if (camera.getScene().useRightHandedSystem) {\r\n camera._localDirection.z *= -1;\r\n }\r\n\r\n camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);\r\n Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);\r\n camera.cameraDirection.addInPlace(camera._transformedDirection);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCameraKeyboardMoveInput\";\r\n }\r\n\r\n /** @internal */\r\n public _onLostFocus(): void {\r\n this._keys.length = 0;\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"keyboard\";\r\n }\r\n\r\n private _getLocalRotation(): number {\r\n let rotation = (this.rotationSpeed * this._engine.getDeltaTime()) / 1000;\r\n if (this.camera.getScene().useRightHandedSystem) {\r\n rotation *= -1;\r\n }\r\n if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) {\r\n rotation *= -1;\r\n }\r\n return rotation;\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"FreeCameraKeyboardMoveInput\"] = FreeCameraKeyboardMoveInput;\r\n","import type { Observer, EventState } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { IMouseEvent, IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n/**\r\n * Manage the mouse inputs to control the movement of a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraMouseInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: FreeCamera;\r\n\r\n /**\r\n * Defines the buttons associated with the input to handle camera move.\r\n */\r\n @serialize()\r\n public buttons = [0, 1, 2];\r\n\r\n /**\r\n * Defines the pointer angular sensibility along the X and Y axis or how fast is the camera rotating.\r\n */\r\n @serialize()\r\n public angularSensibility = 2000.0;\r\n\r\n private _pointerInput: (p: PointerInfo, s: EventState) => void;\r\n private _onMouseMove: Nullable<(e: IMouseEvent) => any>;\r\n private _observer: Nullable>;\r\n private _previousPosition: Nullable<{ x: number; y: number }> = null;\r\n\r\n /**\r\n * Observable for when a pointer move event occurs containing the move offset\r\n */\r\n public onPointerMovedObservable = new Observable<{ offsetX: number; offsetY: number }>();\r\n /**\r\n * @internal\r\n * If the camera should be rotated automatically based on pointer movement\r\n */\r\n public _allowCameraRotation = true;\r\n\r\n private _currentActiveButton: number = -1;\r\n private _activePointerId: number = -1;\r\n private _contextMenuBind: () => void;\r\n\r\n /**\r\n * Manage the mouse inputs to control the movement of a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n * @param touchEnabled Defines if touch is enabled or not\r\n */\r\n constructor(\r\n /**\r\n * Define if touch is enabled in the mouse input\r\n */\r\n public touchEnabled = true\r\n ) {}\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n const engine = this.camera.getEngine();\r\n const element = engine.getInputElement();\r\n\r\n if (!this._pointerInput) {\r\n this._pointerInput = (p) => {\r\n const evt = p.event;\r\n const isTouch = evt.pointerType === \"touch\";\r\n\r\n if (engine.isInVRExclusivePointerMode) {\r\n return;\r\n }\r\n\r\n if (!this.touchEnabled && isTouch) {\r\n return;\r\n }\r\n\r\n if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {\r\n return;\r\n }\r\n\r\n const srcElement = evt.target;\r\n\r\n if (p.type === PointerEventTypes.POINTERDOWN) {\r\n // If the input is touch with more than one touch OR if the input is mouse and there is already an active button, return\r\n if ((isTouch && this._activePointerId !== -1) || (!isTouch && this._currentActiveButton !== -1)) {\r\n return;\r\n }\r\n\r\n this._activePointerId = evt.pointerId;\r\n try {\r\n srcElement?.setPointerCapture(evt.pointerId);\r\n } catch (e) {\r\n //Nothing to do with the error. Execution will continue.\r\n }\r\n\r\n if (this._currentActiveButton === -1) {\r\n this._currentActiveButton = evt.button;\r\n }\r\n\r\n this._previousPosition = {\r\n x: evt.clientX,\r\n y: evt.clientY,\r\n };\r\n\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n element && element.focus();\r\n }\r\n\r\n // This is required to move while pointer button is down\r\n if (engine.isPointerLock && this._onMouseMove) {\r\n this._onMouseMove(p.event);\r\n }\r\n } else if (p.type === PointerEventTypes.POINTERUP) {\r\n // If input is touch with a different touch id OR if input is mouse with a different button, return\r\n if ((isTouch && this._activePointerId !== evt.pointerId) || (!isTouch && this._currentActiveButton !== evt.button)) {\r\n return;\r\n }\r\n\r\n try {\r\n srcElement?.releasePointerCapture(evt.pointerId);\r\n } catch (e) {\r\n //Nothing to do with the error.\r\n }\r\n this._currentActiveButton = -1;\r\n\r\n this._previousPosition = null;\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n\r\n this._activePointerId = -1;\r\n } else if (p.type === PointerEventTypes.POINTERMOVE && (this._activePointerId === evt.pointerId || !isTouch)) {\r\n if (engine.isPointerLock && this._onMouseMove) {\r\n this._onMouseMove(p.event);\r\n } else if (this._previousPosition) {\r\n let offsetX = evt.clientX - this._previousPosition.x;\r\n const offsetY = evt.clientY - this._previousPosition.y;\r\n if (this.camera.getScene().useRightHandedSystem) {\r\n offsetX *= -1;\r\n }\r\n if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) {\r\n offsetX *= -1;\r\n }\r\n\r\n if (this._allowCameraRotation) {\r\n this.camera.cameraRotation.y += offsetX / this.angularSensibility;\r\n this.camera.cameraRotation.x += offsetY / this.angularSensibility;\r\n }\r\n this.onPointerMovedObservable.notifyObservers({ offsetX: offsetX, offsetY: offsetY });\r\n\r\n this._previousPosition = {\r\n x: evt.clientX,\r\n y: evt.clientY,\r\n };\r\n\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n }\r\n }\r\n };\r\n }\r\n\r\n this._onMouseMove = (evt) => {\r\n if (!engine.isPointerLock) {\r\n return;\r\n }\r\n\r\n if (engine.isInVRExclusivePointerMode) {\r\n return;\r\n }\r\n\r\n let offsetX = evt.movementX;\r\n if (this.camera.getScene().useRightHandedSystem) {\r\n offsetX *= -1;\r\n }\r\n if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) {\r\n offsetX *= -1;\r\n }\r\n this.camera.cameraRotation.y += offsetX / this.angularSensibility;\r\n\r\n const offsetY = evt.movementY;\r\n this.camera.cameraRotation.x += offsetY / this.angularSensibility;\r\n\r\n this._previousPosition = null;\r\n\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n };\r\n\r\n this._observer = this.camera\r\n .getScene()\r\n ._inputManager._addCameraPointerObserver(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);\r\n\r\n if (element) {\r\n this._contextMenuBind = this.onContextMenu.bind(this);\r\n element.addEventListener(\"contextmenu\", this._contextMenuBind, false); // TODO: We need to figure out how to handle this for Native\r\n }\r\n }\r\n\r\n /**\r\n * Called on JS contextmenu event.\r\n * Override this method to provide functionality.\r\n * @param evt\r\n */\r\n public onContextMenu(evt: PointerEvent): void {\r\n evt.preventDefault();\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n\r\n if (this._contextMenuBind) {\r\n const engine = this.camera.getEngine();\r\n const element = engine.getInputElement();\r\n element && element.removeEventListener(\"contextmenu\", this._contextMenuBind);\r\n }\r\n\r\n if (this.onPointerMovedObservable) {\r\n this.onPointerMovedObservable.clear();\r\n }\r\n\r\n this._observer = null;\r\n this._onMouseMove = null;\r\n this._previousPosition = null;\r\n }\r\n\r\n this._activePointerId = -1;\r\n this._currentActiveButton = -1;\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCameraMouseInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"mouse\";\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"FreeCameraMouseInput\"] = FreeCameraMouseInput;\r\n","import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport type { IWheelEvent } from \"../../Events/deviceInputEvents\";\r\nimport { EventConstants } from \"../../Events/deviceInputEvents\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Base class for mouse wheel input..\r\n * See FollowCameraMouseWheelInput in src/Cameras/Inputs/freeCameraMouseWheelInput.ts\r\n * for example usage.\r\n */\r\nexport abstract class BaseCameraMouseWheelInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public abstract camera: Camera;\r\n\r\n /**\r\n * How fast is the camera moves in relation to X axis mouseWheel events.\r\n * Use negative value to reverse direction.\r\n */\r\n @serialize()\r\n public wheelPrecisionX = 3.0;\r\n\r\n /**\r\n * How fast is the camera moves in relation to Y axis mouseWheel events.\r\n * Use negative value to reverse direction.\r\n */\r\n @serialize()\r\n public wheelPrecisionY = 3.0;\r\n\r\n /**\r\n * How fast is the camera moves in relation to Z axis mouseWheel events.\r\n * Use negative value to reverse direction.\r\n */\r\n @serialize()\r\n public wheelPrecisionZ = 3.0;\r\n\r\n /**\r\n * Observable for when a mouse wheel move event occurs.\r\n */\r\n public onChangedObservable = new Observable<{ wheelDeltaX: number; wheelDeltaY: number; wheelDeltaZ: number }>();\r\n\r\n private _wheel: Nullable<(pointer: PointerInfo) => void>;\r\n private _observer: Nullable>;\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls\r\n * should call preventdefault().\r\n * (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n\r\n this._wheel = (pointer) => {\r\n // sanity check - this should be a PointerWheel event.\r\n if (pointer.type !== PointerEventTypes.POINTERWHEEL) {\r\n return;\r\n }\r\n\r\n const event = pointer.event;\r\n\r\n const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? this._ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly\r\n\r\n this._wheelDeltaX += (this.wheelPrecisionX * platformScale * event.deltaX) / this._normalize;\r\n this._wheelDeltaY -= (this.wheelPrecisionY * platformScale * event.deltaY) / this._normalize;\r\n this._wheelDeltaZ += (this.wheelPrecisionZ * platformScale * event.deltaZ) / this._normalize;\r\n\r\n if (event.preventDefault) {\r\n if (!noPreventDefault) {\r\n event.preventDefault();\r\n }\r\n }\r\n };\r\n\r\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel, PointerEventTypes.POINTERWHEEL);\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n this._observer = null;\r\n this._wheel = null;\r\n }\r\n if (this.onChangedObservable) {\r\n this.onChangedObservable.clear();\r\n }\r\n }\r\n\r\n /**\r\n * Called for each rendered frame.\r\n */\r\n public checkInputs(): void {\r\n this.onChangedObservable.notifyObservers({\r\n wheelDeltaX: this._wheelDeltaX,\r\n wheelDeltaY: this._wheelDeltaY,\r\n wheelDeltaZ: this._wheelDeltaZ,\r\n });\r\n\r\n // Clear deltas.\r\n this._wheelDeltaX = 0;\r\n this._wheelDeltaY = 0;\r\n this._wheelDeltaZ = 0;\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"BaseCameraMouseWheelInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"mousewheel\";\r\n }\r\n\r\n /**\r\n * Incremental value of multiple mouse wheel movements of the X axis.\r\n * Should be zero-ed when read.\r\n */\r\n protected _wheelDeltaX: number = 0;\r\n\r\n /**\r\n * Incremental value of multiple mouse wheel movements of the Y axis.\r\n * Should be zero-ed when read.\r\n */\r\n protected _wheelDeltaY: number = 0;\r\n\r\n /**\r\n * Incremental value of multiple mouse wheel movements of the Z axis.\r\n * Should be zero-ed when read.\r\n */\r\n protected _wheelDeltaZ: number = 0;\r\n\r\n /**\r\n * Firefox uses a different scheme to report scroll distances to other\r\n * browsers. Rather than use complicated methods to calculate the exact\r\n * multiple we need to apply, let's just cheat and use a constant.\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode\r\n * https://stackoverflow.com/questions/20110224/what-is-the-height-of-a-line-in-a-wheel-event-deltamode-dom-delta-line\r\n */\r\n private readonly _ffMultiplier = 12;\r\n\r\n /**\r\n * Different event attributes for wheel data fall into a few set ranges.\r\n * Some relevant but dated date here:\r\n * https://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers\r\n */\r\n private readonly _normalize = 120;\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport { BaseCameraMouseWheelInput } from \"../../Cameras/Inputs/BaseCameraMouseWheelInput\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Coordinate } from \"../../Maths/math.axis\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nenum _CameraProperty {\r\n MoveRelative,\r\n RotateRelative,\r\n MoveScene,\r\n}\r\n\r\n/**\r\n * Manage the mouse wheel inputs to control a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraMouseWheelInput extends BaseCameraMouseWheelInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: FreeCamera;\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCameraMouseWheelInput\";\r\n }\r\n\r\n /**\r\n * Set which movement axis (relative to camera's orientation) the mouse\r\n * wheel's X axis controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelXMoveRelative(axis: Nullable) {\r\n if (axis === null && this._wheelXAction !== _CameraProperty.MoveRelative) {\r\n // Attempting to clear different _wheelXAction.\r\n return;\r\n }\r\n this._wheelXAction = _CameraProperty.MoveRelative;\r\n this._wheelXActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured movement axis (relative to camera's orientation) the\r\n * mouse wheel's X axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelXMoveRelative(): Nullable {\r\n if (this._wheelXAction !== _CameraProperty.MoveRelative) {\r\n return null;\r\n }\r\n return this._wheelXActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which movement axis (relative to camera's orientation) the mouse\r\n * wheel's Y axis controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelYMoveRelative(axis: Nullable) {\r\n if (axis === null && this._wheelYAction !== _CameraProperty.MoveRelative) {\r\n // Attempting to clear different _wheelYAction.\r\n return;\r\n }\r\n this._wheelYAction = _CameraProperty.MoveRelative;\r\n this._wheelYActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured movement axis (relative to camera's orientation) the\r\n * mouse wheel's Y axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelYMoveRelative(): Nullable {\r\n if (this._wheelYAction !== _CameraProperty.MoveRelative) {\r\n return null;\r\n }\r\n return this._wheelYActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which movement axis (relative to camera's orientation) the mouse\r\n * wheel's Z axis controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelZMoveRelative(axis: Nullable) {\r\n if (axis === null && this._wheelZAction !== _CameraProperty.MoveRelative) {\r\n // Attempting to clear different _wheelZAction.\r\n return;\r\n }\r\n this._wheelZAction = _CameraProperty.MoveRelative;\r\n this._wheelZActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured movement axis (relative to camera's orientation) the\r\n * mouse wheel's Z axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelZMoveRelative(): Nullable {\r\n if (this._wheelZAction !== _CameraProperty.MoveRelative) {\r\n return null;\r\n }\r\n return this._wheelZActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which rotation axis (relative to camera's orientation) the mouse\r\n * wheel's X axis controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelXRotateRelative(axis: Nullable) {\r\n if (axis === null && this._wheelXAction !== _CameraProperty.RotateRelative) {\r\n // Attempting to clear different _wheelXAction.\r\n return;\r\n }\r\n this._wheelXAction = _CameraProperty.RotateRelative;\r\n this._wheelXActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured rotation axis (relative to camera's orientation) the\r\n * mouse wheel's X axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelXRotateRelative(): Nullable {\r\n if (this._wheelXAction !== _CameraProperty.RotateRelative) {\r\n return null;\r\n }\r\n return this._wheelXActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which rotation axis (relative to camera's orientation) the mouse\r\n * wheel's Y axis controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelYRotateRelative(axis: Nullable) {\r\n if (axis === null && this._wheelYAction !== _CameraProperty.RotateRelative) {\r\n // Attempting to clear different _wheelYAction.\r\n return;\r\n }\r\n this._wheelYAction = _CameraProperty.RotateRelative;\r\n this._wheelYActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured rotation axis (relative to camera's orientation) the\r\n * mouse wheel's Y axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelYRotateRelative(): Nullable {\r\n if (this._wheelYAction !== _CameraProperty.RotateRelative) {\r\n return null;\r\n }\r\n return this._wheelYActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which rotation axis (relative to camera's orientation) the mouse\r\n * wheel's Z axis controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelZRotateRelative(axis: Nullable) {\r\n if (axis === null && this._wheelZAction !== _CameraProperty.RotateRelative) {\r\n // Attempting to clear different _wheelZAction.\r\n return;\r\n }\r\n this._wheelZAction = _CameraProperty.RotateRelative;\r\n this._wheelZActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured rotation axis (relative to camera's orientation) the\r\n * mouse wheel's Z axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelZRotateRelative(): Nullable {\r\n if (this._wheelZAction !== _CameraProperty.RotateRelative) {\r\n return null;\r\n }\r\n return this._wheelZActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which movement axis (relative to the scene) the mouse wheel's X axis\r\n * controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelXMoveScene(axis: Nullable) {\r\n if (axis === null && this._wheelXAction !== _CameraProperty.MoveScene) {\r\n // Attempting to clear different _wheelXAction.\r\n return;\r\n }\r\n this._wheelXAction = _CameraProperty.MoveScene;\r\n this._wheelXActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured movement axis (relative to the scene) the mouse wheel's\r\n * X axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelXMoveScene(): Nullable {\r\n if (this._wheelXAction !== _CameraProperty.MoveScene) {\r\n return null;\r\n }\r\n return this._wheelXActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which movement axis (relative to the scene) the mouse wheel's Y axis\r\n * controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelYMoveScene(axis: Nullable) {\r\n if (axis === null && this._wheelYAction !== _CameraProperty.MoveScene) {\r\n // Attempting to clear different _wheelYAction.\r\n return;\r\n }\r\n this._wheelYAction = _CameraProperty.MoveScene;\r\n this._wheelYActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured movement axis (relative to the scene) the mouse wheel's\r\n * Y axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelYMoveScene(): Nullable {\r\n if (this._wheelYAction !== _CameraProperty.MoveScene) {\r\n return null;\r\n }\r\n return this._wheelYActionCoordinate;\r\n }\r\n\r\n /**\r\n * Set which movement axis (relative to the scene) the mouse wheel's Z axis\r\n * controls.\r\n * @param axis The axis to be moved. Set null to clear.\r\n */\r\n @serialize()\r\n public set wheelZMoveScene(axis: Nullable) {\r\n if (axis === null && this._wheelZAction !== _CameraProperty.MoveScene) {\r\n // Attempting to clear different _wheelZAction.\r\n return;\r\n }\r\n this._wheelZAction = _CameraProperty.MoveScene;\r\n this._wheelZActionCoordinate = axis;\r\n }\r\n\r\n /**\r\n * Get the configured movement axis (relative to the scene) the mouse wheel's\r\n * Z axis controls.\r\n * @returns The configured axis or null if none.\r\n */\r\n public get wheelZMoveScene(): Nullable {\r\n if (this._wheelZAction !== _CameraProperty.MoveScene) {\r\n return null;\r\n }\r\n return this._wheelZActionCoordinate;\r\n }\r\n\r\n /**\r\n * Called for each rendered frame.\r\n */\r\n public checkInputs(): void {\r\n if (this._wheelDeltaX === 0 && this._wheelDeltaY === 0 && this._wheelDeltaZ == 0) {\r\n return;\r\n }\r\n\r\n // Clear the camera properties that we might be updating.\r\n this._moveRelative.setAll(0);\r\n this._rotateRelative.setAll(0);\r\n this._moveScene.setAll(0);\r\n\r\n // Set the camera properties that are to be updated.\r\n this._updateCamera();\r\n\r\n if (this.camera.getScene().useRightHandedSystem) {\r\n // TODO: Does this need done for worldUpdate too?\r\n this._moveRelative.z *= -1;\r\n }\r\n\r\n // Convert updates relative to camera to world position update.\r\n const cameraTransformMatrix = Matrix.Zero();\r\n this.camera.getViewMatrix().invertToRef(cameraTransformMatrix);\r\n\r\n const transformedDirection = Vector3.Zero();\r\n Vector3.TransformNormalToRef(this._moveRelative, cameraTransformMatrix, transformedDirection);\r\n\r\n // Apply updates to camera position.\r\n this.camera.cameraRotation.x += this._rotateRelative.x / 200;\r\n this.camera.cameraRotation.y += this._rotateRelative.y / 200;\r\n this.camera.cameraDirection.addInPlace(transformedDirection);\r\n this.camera.cameraDirection.addInPlace(this._moveScene);\r\n\r\n // Call the base class implementation to handle observers and do cleanup.\r\n super.checkInputs();\r\n }\r\n\r\n private _moveRelative = Vector3.Zero();\r\n private _rotateRelative = Vector3.Zero();\r\n private _moveScene = Vector3.Zero();\r\n\r\n /**\r\n * These are set to the desired default behaviour.\r\n */\r\n private _wheelXAction: Nullable<_CameraProperty> = _CameraProperty.MoveRelative;\r\n private _wheelXActionCoordinate: Nullable = Coordinate.X;\r\n private _wheelYAction: Nullable<_CameraProperty> = _CameraProperty.MoveRelative;\r\n private _wheelYActionCoordinate: Nullable = Coordinate.Z;\r\n private _wheelZAction: Nullable<_CameraProperty> = null;\r\n private _wheelZActionCoordinate: Nullable = null;\r\n\r\n /**\r\n * Update the camera according to any configured properties for the 3\r\n * mouse-wheel axis.\r\n */\r\n private _updateCamera(): void {\r\n // Do the camera updates for each of the 3 touch-wheel axis.\r\n this._updateCameraProperty(this._wheelDeltaX, this._wheelXAction, this._wheelXActionCoordinate);\r\n this._updateCameraProperty(this._wheelDeltaY, this._wheelYAction, this._wheelYActionCoordinate);\r\n this._updateCameraProperty(this._wheelDeltaZ, this._wheelZAction, this._wheelZActionCoordinate);\r\n }\r\n\r\n /**\r\n * Update one property of the camera.\r\n * @param value\r\n * @param cameraProperty\r\n * @param coordinate\r\n */\r\n private _updateCameraProperty(\r\n /* Mouse-wheel delta. */\r\n value: number,\r\n /* Camera property to be changed. */\r\n cameraProperty: Nullable<_CameraProperty>,\r\n /* Axis of Camera property to be changed. */\r\n coordinate: Nullable\r\n ): void {\r\n if (value === 0) {\r\n // Mouse wheel has not moved.\r\n return;\r\n }\r\n if (cameraProperty === null || coordinate === null) {\r\n // Mouse wheel axis not configured.\r\n return;\r\n }\r\n\r\n let action = null;\r\n switch (cameraProperty) {\r\n case _CameraProperty.MoveRelative:\r\n action = this._moveRelative;\r\n break;\r\n case _CameraProperty.RotateRelative:\r\n action = this._rotateRelative;\r\n break;\r\n case _CameraProperty.MoveScene:\r\n action = this._moveScene;\r\n break;\r\n }\r\n\r\n switch (coordinate) {\r\n case Coordinate.X:\r\n action.set(value, 0, 0);\r\n break;\r\n case Coordinate.Y:\r\n action.set(0, value, 0);\r\n break;\r\n case Coordinate.Z:\r\n action.set(0, 0, value);\r\n break;\r\n }\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"FreeCameraMouseWheelInput\"] = FreeCameraMouseWheelInput;\r\n","import { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer, EventState } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n/**\r\n * Manage the touch inputs to control the movement of a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraTouchInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: FreeCamera;\r\n\r\n /**\r\n * Defines the touch sensibility for rotation.\r\n * The lower the faster.\r\n */\r\n @serialize()\r\n public touchAngularSensibility: number = 200000.0;\r\n\r\n /**\r\n * Defines the touch sensibility for move.\r\n * The lower the faster.\r\n */\r\n @serialize()\r\n public touchMoveSensibility: number = 250.0;\r\n\r\n /**\r\n * Swap touch actions so that one touch is used for rotation and multiple for movement\r\n */\r\n public singleFingerRotate: boolean = false;\r\n\r\n private _offsetX: Nullable = null;\r\n private _offsetY: Nullable = null;\r\n\r\n private _pointerPressed = new Array();\r\n private _pointerInput?: (p: PointerInfo, s: EventState) => void;\r\n private _observer: Nullable>;\r\n private _onLostFocus: Nullable<(e: FocusEvent) => any>;\r\n private _isSafari: boolean;\r\n\r\n /**\r\n * Manage the touch inputs to control the movement of a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n * @param allowMouse Defines if mouse events can be treated as touch events\r\n */\r\n constructor(\r\n /**\r\n * Define if mouse events can be treated as touch events\r\n */\r\n public allowMouse = false\r\n ) {\r\n this._isSafari = Tools.IsSafari();\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n let previousPosition: Nullable<{ x: number; y: number }> = null;\r\n\r\n if (this._pointerInput === undefined) {\r\n this._onLostFocus = () => {\r\n this._offsetX = null;\r\n this._offsetY = null;\r\n };\r\n\r\n this._pointerInput = (p) => {\r\n const evt = p.event;\r\n\r\n const isMouseEvent = evt.pointerType === \"mouse\" || (this._isSafari && typeof evt.pointerType === \"undefined\");\r\n\r\n if (!this.allowMouse && isMouseEvent) {\r\n return;\r\n }\r\n\r\n if (p.type === PointerEventTypes.POINTERDOWN) {\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n\r\n this._pointerPressed.push(evt.pointerId);\r\n\r\n if (this._pointerPressed.length !== 1) {\r\n return;\r\n }\r\n\r\n previousPosition = {\r\n x: evt.clientX,\r\n y: evt.clientY,\r\n };\r\n } else if (p.type === PointerEventTypes.POINTERUP) {\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n\r\n const index: number = this._pointerPressed.indexOf(evt.pointerId);\r\n\r\n if (index === -1) {\r\n return;\r\n }\r\n this._pointerPressed.splice(index, 1);\r\n\r\n if (index != 0) {\r\n return;\r\n }\r\n previousPosition = null;\r\n this._offsetX = null;\r\n this._offsetY = null;\r\n } else if (p.type === PointerEventTypes.POINTERMOVE) {\r\n if (!noPreventDefault) {\r\n evt.preventDefault();\r\n }\r\n\r\n if (!previousPosition) {\r\n return;\r\n }\r\n\r\n const index: number = this._pointerPressed.indexOf(evt.pointerId);\r\n\r\n if (index != 0) {\r\n return;\r\n }\r\n\r\n this._offsetX = evt.clientX - previousPosition.x;\r\n this._offsetY = -(evt.clientY - previousPosition.y);\r\n }\r\n };\r\n }\r\n\r\n this._observer = this.camera\r\n .getScene()\r\n ._inputManager._addCameraPointerObserver(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);\r\n\r\n if (this._onLostFocus) {\r\n const engine = this.camera.getEngine();\r\n const element = engine.getInputElement();\r\n element && element.addEventListener(\"blur\", this._onLostFocus);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._pointerInput) {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n this._observer = null;\r\n }\r\n\r\n if (this._onLostFocus) {\r\n const engine = this.camera.getEngine();\r\n const element = engine.getInputElement();\r\n element && element.removeEventListener(\"blur\", this._onLostFocus);\r\n this._onLostFocus = null;\r\n }\r\n this._pointerPressed.length = 0;\r\n this._offsetX = null;\r\n this._offsetY = null;\r\n }\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (this._offsetX === null || this._offsetY === null) {\r\n return;\r\n }\r\n if (this._offsetX === 0 && this._offsetY === 0) {\r\n return;\r\n }\r\n\r\n const camera = this.camera;\r\n camera.cameraRotation.y = this._offsetX / this.touchAngularSensibility;\r\n\r\n const rotateCamera = (this.singleFingerRotate && this._pointerPressed.length === 1) || (!this.singleFingerRotate && this._pointerPressed.length > 1);\r\n\r\n if (rotateCamera) {\r\n camera.cameraRotation.x = -this._offsetY / this.touchAngularSensibility;\r\n } else {\r\n const speed = camera._computeLocalCameraSpeed();\r\n const direction = new Vector3(0, 0, this.touchMoveSensibility !== 0 ? (speed * this._offsetY) / this.touchMoveSensibility : 0);\r\n\r\n Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);\r\n camera.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCameraTouchInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"touch\";\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"FreeCameraTouchInput\"] = FreeCameraTouchInput;\r\n","import type { FreeCamera } from \"./freeCamera\";\r\nimport { CameraInputsManager } from \"./cameraInputsManager\";\r\nimport { FreeCameraKeyboardMoveInput } from \"../Cameras/Inputs/freeCameraKeyboardMoveInput\";\r\nimport { FreeCameraMouseInput } from \"../Cameras/Inputs/freeCameraMouseInput\";\r\nimport { FreeCameraMouseWheelInput } from \"../Cameras/Inputs/freeCameraMouseWheelInput\";\r\nimport { FreeCameraTouchInput } from \"../Cameras/Inputs/freeCameraTouchInput\";\r\nimport type { Nullable } from \"../types\";\r\n\r\n/**\r\n * Default Inputs manager for the FreeCamera.\r\n * It groups all the default supported inputs for ease of use.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraInputsManager extends CameraInputsManager {\r\n /**\r\n * @internal\r\n */\r\n public _mouseInput: Nullable = null;\r\n /**\r\n * @internal\r\n */\r\n public _mouseWheelInput: Nullable = null;\r\n /**\r\n * Instantiates a new FreeCameraInputsManager.\r\n * @param camera Defines the camera the inputs belong to\r\n */\r\n constructor(camera: FreeCamera) {\r\n super(camera);\r\n }\r\n\r\n /**\r\n * Add keyboard input support to the input manager.\r\n * @returns the current input manager\r\n */\r\n addKeyboard(): FreeCameraInputsManager {\r\n this.add(new FreeCameraKeyboardMoveInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Add mouse input support to the input manager.\r\n * @param touchEnabled if the FreeCameraMouseInput should support touch (default: true)\r\n * @returns the current input manager\r\n */\r\n addMouse(touchEnabled = true): FreeCameraInputsManager {\r\n if (!this._mouseInput) {\r\n this._mouseInput = new FreeCameraMouseInput(touchEnabled);\r\n this.add(this._mouseInput);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes the mouse input support from the manager\r\n * @returns the current input manager\r\n */\r\n removeMouse(): FreeCameraInputsManager {\r\n if (this._mouseInput) {\r\n this.remove(this._mouseInput);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Add mouse wheel input support to the input manager.\r\n * @returns the current input manager\r\n */\r\n addMouseWheel(): FreeCameraInputsManager {\r\n if (!this._mouseWheelInput) {\r\n this._mouseWheelInput = new FreeCameraMouseWheelInput();\r\n this.add(this._mouseWheelInput);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes the mouse wheel input support from the manager\r\n * @returns the current input manager\r\n */\r\n removeMouseWheel(): FreeCameraInputsManager {\r\n if (this._mouseWheelInput) {\r\n this.remove(this._mouseWheelInput);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Add touch input support to the input manager.\r\n * @returns the current input manager\r\n */\r\n addTouch(): FreeCameraInputsManager {\r\n this.add(new FreeCameraTouchInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove all attached input methods from a camera\r\n */\r\n public clear(): void {\r\n super.clear();\r\n this._mouseInput = null;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { serializeAsVector3, serialize } from \"../Misc/decorators\";\r\nimport { Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport { TargetCamera } from \"./targetCamera\";\r\nimport { FreeCameraInputsManager } from \"./freeCameraInputsManager\";\r\nimport type { FreeCameraMouseInput } from \"../Cameras/Inputs/freeCameraMouseInput\";\r\nimport type { FreeCameraKeyboardMoveInput } from \"../Cameras/Inputs/freeCameraKeyboardMoveInput\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\nimport type { Collider } from \"../Collisions/collider\";\r\n\r\n/**\r\n * This represents a free type of camera. It can be useful in First Person Shooter game for instance.\r\n * Please consider using the new UniversalCamera instead as it adds more functionality like the gamepad.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\r\n */\r\nexport class FreeCamera extends TargetCamera {\r\n /**\r\n * Define the collision ellipsoid of the camera.\r\n * This is helpful to simulate a camera body like the player body around the camera\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#arcrotatecamera\r\n */\r\n @serializeAsVector3()\r\n public ellipsoid = new Vector3(0.5, 1, 0.5);\r\n\r\n /**\r\n * Define an offset for the position of the ellipsoid around the camera.\r\n * This can be helpful to determine the center of the body near the gravity center of the body\r\n * instead of its head.\r\n */\r\n @serializeAsVector3()\r\n public ellipsoidOffset = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * Enable or disable collisions of the camera with the rest of the scene objects.\r\n */\r\n @serialize()\r\n public checkCollisions = false;\r\n\r\n /**\r\n * Enable or disable gravity on the camera.\r\n */\r\n @serialize()\r\n public applyGravity = false;\r\n\r\n /**\r\n * Define the input manager associated to the camera.\r\n */\r\n public inputs: FreeCameraInputsManager;\r\n\r\n /**\r\n * Gets the input sensibility for a mouse input. (default is 2000.0)\r\n * Higher values reduce sensitivity.\r\n */\r\n public get angularSensibility(): number {\r\n const mouse = this.inputs.attached[\"mouse\"];\r\n if (mouse) {\r\n return mouse.angularSensibility;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n /**\r\n * Sets the input sensibility for a mouse input. (default is 2000.0)\r\n * Higher values reduce sensitivity.\r\n */\r\n public set angularSensibility(value: number) {\r\n const mouse = this.inputs.attached[\"mouse\"];\r\n if (mouse) {\r\n mouse.angularSensibility = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the forward move of the camera.\r\n */\r\n public get keysUp(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysUp;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysUp(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysUp = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the upward move of the camera.\r\n */\r\n public get keysUpward(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysUpward;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysUpward(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysUpward = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the backward move of the camera.\r\n */\r\n public get keysDown(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysDown;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysDown(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysDown = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the downward move of the camera.\r\n */\r\n public get keysDownward(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysDownward;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysDownward(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysDownward = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.\r\n */\r\n public get keysLeft(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysLeft;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysLeft(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysLeft = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the right strafe move of the camera.\r\n */\r\n public get keysRight(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysRight;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysRight(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysRight = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the left rotation move of the camera.\r\n */\r\n public get keysRotateLeft(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysRotateLeft;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysRotateLeft(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysRotateLeft = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the right rotation move of the camera.\r\n */\r\n public get keysRotateRight(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysRotateRight;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysRotateRight(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysRotateRight = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the up rotation move of the camera.\r\n */\r\n public get keysRotateUp(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysRotateUp;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysRotateUp(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysRotateUp = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets or Set the list of keyboard keys used to control the down rotation move of the camera.\r\n */\r\n public get keysRotateDown(): number[] {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n return keyboard.keysRotateDown;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public set keysRotateDown(value: number[]) {\r\n const keyboard = this.inputs.attached[\"keyboard\"];\r\n if (keyboard) {\r\n keyboard.keysRotateDown = value;\r\n }\r\n }\r\n\r\n /**\r\n * Event raised when the camera collide with a mesh in the scene.\r\n */\r\n public onCollide: (collidedMesh: AbstractMesh) => void;\r\n\r\n private _collider: Collider;\r\n private _needMoveForGravity = false;\r\n private _oldPosition = Vector3.Zero();\r\n private _diffPosition = Vector3.Zero();\r\n private _newPosition = Vector3.Zero();\r\n\r\n /** @internal */\r\n public _localDirection: Vector3;\r\n /** @internal */\r\n public _transformedDirection: Vector3;\r\n\r\n /**\r\n * Instantiates a Free Camera.\r\n * This represents a free type of camera. It can be useful in First Person Shooter game for instance.\r\n * Please consider using the new UniversalCamera instead as it adds more functionality like touch to this camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\r\n * @param name Define the name of the camera in the scene\r\n * @param position Define the start position of the camera in the scene\r\n * @param scene Define the scene the camera belongs to\r\n * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene, setActiveOnSceneIfNoneActive = true) {\r\n super(name, position, scene, setActiveOnSceneIfNoneActive);\r\n this.inputs = new FreeCameraInputsManager(this);\r\n this.inputs.addKeyboard().addMouse();\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(noPreventDefault?: boolean): void;\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n * BACK COMPAT SIGNATURE ONLY.\r\n */\r\n public attachControl(ignored: any, noPreventDefault?: boolean): void;\r\n /**\r\n * Attached controls to the current camera.\r\n * @param ignored defines an ignored parameter kept for backward compatibility.\r\n * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)\r\n */\r\n public attachControl(ignored?: any, noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n this.inputs.attachElement(noPreventDefault);\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n this.inputs.detachElement();\r\n\r\n this.cameraDirection = new Vector3(0, 0, 0);\r\n this.cameraRotation = new Vector2(0, 0);\r\n }\r\n\r\n // Collisions\r\n private _collisionMask = -1;\r\n\r\n /**\r\n * Define a collision mask to limit the list of object the camera can collide with\r\n */\r\n public get collisionMask(): number {\r\n return this._collisionMask;\r\n }\r\n\r\n public set collisionMask(mask: number) {\r\n this._collisionMask = !isNaN(mask) ? mask : -1;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _collideWithWorld(displacement: Vector3): void {\r\n let globalPosition: Vector3;\r\n\r\n if (this.parent) {\r\n globalPosition = Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());\r\n } else {\r\n globalPosition = this.position;\r\n }\r\n\r\n globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);\r\n this._oldPosition.addInPlace(this.ellipsoidOffset);\r\n\r\n const coordinator = this.getScene().collisionCoordinator;\r\n if (!this._collider) {\r\n this._collider = coordinator.createCollider();\r\n }\r\n\r\n this._collider._radius = this.ellipsoid;\r\n this._collider.collisionMask = this._collisionMask;\r\n\r\n //no need for clone, as long as gravity is not on.\r\n let actualDisplacement = displacement;\r\n\r\n //add gravity to the direction to prevent the dual-collision checking\r\n if (this.applyGravity) {\r\n //this prevents mending with cameraDirection, a global variable of the free camera class.\r\n actualDisplacement = displacement.add(this.getScene().gravity);\r\n }\r\n\r\n coordinator.getNewPosition(this._oldPosition, actualDisplacement, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);\r\n }\r\n\r\n private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable = null) => {\r\n this._newPosition.copyFrom(newPosition);\r\n\r\n this._newPosition.subtractToRef(this._oldPosition, this._diffPosition);\r\n\r\n if (this._diffPosition.length() > Engine.CollisionsEpsilon) {\r\n this.position.addToRef(this._diffPosition, this._deferredPositionUpdate);\r\n if (!this._deferOnly) {\r\n this.position.copyFrom(this._deferredPositionUpdate);\r\n } else {\r\n this._deferredUpdated = true;\r\n }\r\n // call onCollide, if defined. Note that in case of deferred update, the actual position change might happen in the next frame.\r\n if (this.onCollide && collidedMesh) {\r\n this.onCollide(collidedMesh);\r\n }\r\n }\r\n };\r\n\r\n /** @internal */\r\n public _checkInputs(): void {\r\n if (!this._localDirection) {\r\n this._localDirection = Vector3.Zero();\r\n this._transformedDirection = Vector3.Zero();\r\n }\r\n\r\n this.inputs.checkInputs();\r\n\r\n super._checkInputs();\r\n }\r\n\r\n /**\r\n * Enable movement without a user input. This allows gravity to always be applied.\r\n */\r\n public set needMoveForGravity(value: boolean) {\r\n this._needMoveForGravity = value;\r\n }\r\n\r\n /**\r\n * When true, gravity is applied whether there is user input or not.\r\n */\r\n public get needMoveForGravity(): boolean {\r\n return this._needMoveForGravity;\r\n }\r\n\r\n /** @internal */\r\n public _decideIfNeedsToMove(): boolean {\r\n return this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;\r\n }\r\n\r\n /** @internal */\r\n public _updatePosition(): void {\r\n if (this.checkCollisions && this.getScene().collisionsEnabled) {\r\n this._collideWithWorld(this.cameraDirection);\r\n } else {\r\n super._updatePosition();\r\n }\r\n }\r\n\r\n /**\r\n * Destroy the camera and release the current resources hold by it.\r\n */\r\n public dispose(): void {\r\n this.inputs.clear();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Gets the current object class name.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCamera\";\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { FreeCameraInputsManager } from \"../../Cameras/freeCameraInputsManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\n\r\n// Module augmentation to abstract orientation inputs from camera.\r\ndeclare module \"../../Cameras/freeCameraInputsManager\" {\r\n export interface FreeCameraInputsManager {\r\n /**\r\n * @internal\r\n */\r\n _deviceOrientationInput: Nullable;\r\n /**\r\n * Add orientation input support to the input manager.\r\n * @param smoothFactor deviceOrientation smoothing. 0: no smoothing, 1: new data ignored, 0.9 recommended for smoothing\r\n * @returns the current input manager\r\n */\r\n addDeviceOrientation(smoothFactor?: number): FreeCameraInputsManager;\r\n }\r\n}\r\n\r\n/**\r\n * Add orientation input support to the input manager.\r\n * @param smoothFactor deviceOrientation smoothing. 0: no smoothing, 1: new data ignored, 0.9 recommended for smoothing\r\n * @returns the current input manager\r\n */\r\nFreeCameraInputsManager.prototype.addDeviceOrientation = function (smoothFactor?: number): FreeCameraInputsManager {\r\n if (!this._deviceOrientationInput) {\r\n this._deviceOrientationInput = new FreeCameraDeviceOrientationInput();\r\n if (smoothFactor) {\r\n this._deviceOrientationInput.smoothFactor = smoothFactor;\r\n }\r\n this.add(this._deviceOrientationInput);\r\n }\r\n\r\n return this;\r\n};\r\n\r\n/**\r\n * Takes information about the orientation of the device as reported by the deviceorientation event to orient the camera.\r\n * Screen rotation is taken into account.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraDeviceOrientationInput implements ICameraInput {\r\n private _camera: FreeCamera;\r\n\r\n private _screenOrientationAngle: number = 0;\r\n\r\n private _constantTranform: Quaternion;\r\n private _screenQuaternion: Quaternion = new Quaternion();\r\n\r\n private _alpha: number = 0;\r\n private _beta: number = 0;\r\n private _gamma: number = 0;\r\n\r\n /** alpha+beta+gamma smoothing. 0: no smoothing, 1: new data ignored, 0.9 recommended for smoothing */\r\n public smoothFactor: number = 0;\r\n\r\n /**\r\n * Can be used to detect if a device orientation sensor is available on a device\r\n * @param timeout amount of time in milliseconds to wait for a response from the sensor (default: infinite)\r\n * @returns a promise that will resolve on orientation change\r\n */\r\n public static WaitForOrientationChangeAsync(timeout?: number): Promise {\r\n return new Promise((res, rej) => {\r\n let gotValue = false;\r\n const eventHandler = () => {\r\n window.removeEventListener(\"deviceorientation\", eventHandler);\r\n gotValue = true;\r\n res();\r\n };\r\n\r\n // If timeout is populated reject the promise\r\n if (timeout) {\r\n setTimeout(() => {\r\n if (!gotValue) {\r\n window.removeEventListener(\"deviceorientation\", eventHandler);\r\n rej(\"WaitForOrientationChangeAsync timed out\");\r\n }\r\n }, timeout);\r\n }\r\n\r\n if (typeof DeviceOrientationEvent !== \"undefined\" && typeof (DeviceOrientationEvent).requestPermission === \"function\") {\r\n (DeviceOrientationEvent)\r\n .requestPermission()\r\n .then((response: string) => {\r\n if (response == \"granted\") {\r\n window.addEventListener(\"deviceorientation\", eventHandler);\r\n } else {\r\n Tools.Warn(\"Permission not granted.\");\r\n }\r\n })\r\n .catch((error: any) => {\r\n Tools.Error(error);\r\n });\r\n } else {\r\n window.addEventListener(\"deviceorientation\", eventHandler);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _onDeviceOrientationChangedObservable = new Observable();\r\n /**\r\n * Instantiates a new input\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\n constructor() {\r\n this._constantTranform = new Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));\r\n this._orientationChanged();\r\n }\r\n\r\n /**\r\n * Define the camera controlled by the input.\r\n */\r\n public get camera(): FreeCamera {\r\n return this._camera;\r\n }\r\n\r\n public set camera(camera: FreeCamera) {\r\n this._camera = camera;\r\n if (this._camera != null && !this._camera.rotationQuaternion) {\r\n this._camera.rotationQuaternion = new Quaternion();\r\n }\r\n if (this._camera) {\r\n this._camera.onDisposeObservable.add(() => {\r\n this._onDeviceOrientationChangedObservable.clear();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n */\r\n public attachControl(): void {\r\n const hostWindow = this.camera.getScene().getEngine().getHostWindow();\r\n\r\n if (hostWindow) {\r\n const eventHandler = () => {\r\n hostWindow!.addEventListener(\"orientationchange\", this._orientationChanged);\r\n hostWindow!.addEventListener(\"deviceorientation\", this._deviceOrientation);\r\n //In certain cases, the attach control is called AFTER orientation was changed,\r\n //So this is needed.\r\n this._orientationChanged();\r\n };\r\n if (typeof DeviceOrientationEvent !== \"undefined\" && typeof (DeviceOrientationEvent).requestPermission === \"function\") {\r\n (DeviceOrientationEvent)\r\n .requestPermission()\r\n .then((response: string) => {\r\n if (response === \"granted\") {\r\n eventHandler();\r\n } else {\r\n Tools.Warn(\"Permission not granted.\");\r\n }\r\n })\r\n .catch((error: any) => {\r\n Tools.Error(error);\r\n });\r\n } else {\r\n eventHandler();\r\n }\r\n }\r\n }\r\n\r\n private _orientationChanged = () => {\r\n this._screenOrientationAngle =\r\n window.orientation !== undefined\r\n ? +(window.orientation)\r\n : (window.screen).orientation && (window.screen).orientation[\"angle\"]\r\n ? (window.screen).orientation.angle\r\n : 0;\r\n this._screenOrientationAngle = -Tools.ToRadians(this._screenOrientationAngle / 2);\r\n this._screenQuaternion.copyFromFloats(0, Math.sin(this._screenOrientationAngle), 0, Math.cos(this._screenOrientationAngle));\r\n };\r\n\r\n private _deviceOrientation = (evt: DeviceOrientationEvent) => {\r\n if (this.smoothFactor) {\r\n this._alpha = evt.alpha !== null ? Tools.SmoothAngleChange(this._alpha, evt.alpha, this.smoothFactor) : 0;\r\n this._beta = evt.beta !== null ? Tools.SmoothAngleChange(this._beta, evt.beta, this.smoothFactor) : 0;\r\n this._gamma = evt.gamma !== null ? Tools.SmoothAngleChange(this._gamma, evt.gamma, this.smoothFactor) : 0;\r\n } else {\r\n this._alpha = evt.alpha !== null ? evt.alpha : 0;\r\n this._beta = evt.beta !== null ? evt.beta : 0;\r\n this._gamma = evt.gamma !== null ? evt.gamma : 0;\r\n }\r\n\r\n if (evt.alpha !== null) {\r\n this._onDeviceOrientationChangedObservable.notifyObservers();\r\n }\r\n };\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n window.removeEventListener(\"orientationchange\", this._orientationChanged);\r\n window.removeEventListener(\"deviceorientation\", this._deviceOrientation);\r\n this._alpha = 0;\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n //if no device orientation provided, don't update the rotation.\r\n //Only testing against alpha under the assumption thatnorientation will never be so exact when set.\r\n if (!this._alpha) {\r\n return;\r\n }\r\n Quaternion.RotationYawPitchRollToRef(Tools.ToRadians(this._alpha), Tools.ToRadians(this._beta), -Tools.ToRadians(this._gamma), this.camera.rotationQuaternion);\r\n this._camera.rotationQuaternion.multiplyInPlace(this._screenQuaternion);\r\n this._camera.rotationQuaternion.multiplyInPlace(this._constantTranform);\r\n //Mirror on XY Plane\r\n this._camera.rotationQuaternion.z *= -1;\r\n this._camera.rotationQuaternion.w *= -1;\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCameraDeviceOrientationInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"deviceOrientation\";\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"FreeCameraDeviceOrientationInput\"] = FreeCameraDeviceOrientationInput;\r\n","import { FreeCamera } from \"./freeCamera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\n\r\nimport \"./Inputs/freeCameraDeviceOrientationInput\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\n\r\nNode.AddNodeConstructor(\"DeviceOrientationCamera\", (name, scene) => {\r\n return () => new DeviceOrientationCamera(name, Vector3.Zero(), scene);\r\n});\r\n\r\n// We're mainly based on the logic defined into the FreeCamera code\r\n/**\r\n * This is a camera specifically designed to react to device orientation events such as a modern mobile device\r\n * being tilted forward or back and left or right.\r\n */\r\nexport class DeviceOrientationCamera extends FreeCamera {\r\n private _initialQuaternion: Quaternion;\r\n private _quaternionCache: Quaternion;\r\n private _tmpDragQuaternion = new Quaternion();\r\n private _disablePointerInputWhenUsingDeviceOrientation = true;\r\n\r\n /**\r\n * Creates a new device orientation camera\r\n * @param name The name of the camera\r\n * @param position The start position camera\r\n * @param scene The scene the camera belongs to\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene) {\r\n super(name, position, scene);\r\n this._quaternionCache = new Quaternion();\r\n this.inputs.addDeviceOrientation();\r\n\r\n // When the orientation sensor fires it's first event, disable mouse input\r\n if (this.inputs._deviceOrientationInput) {\r\n this.inputs._deviceOrientationInput._onDeviceOrientationChangedObservable.addOnce(() => {\r\n if (this._disablePointerInputWhenUsingDeviceOrientation) {\r\n if (this.inputs._mouseInput) {\r\n this.inputs._mouseInput._allowCameraRotation = false;\r\n this.inputs._mouseInput.onPointerMovedObservable.add((e) => {\r\n if (this._dragFactor != 0) {\r\n if (!this._initialQuaternion) {\r\n this._initialQuaternion = new Quaternion();\r\n }\r\n // Rotate the initial space around the y axis to allow users to \"turn around\" via touch/mouse\r\n Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);\r\n this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);\r\n }\r\n });\r\n }\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that pointer input must be disabled on first orientation sensor update (Default: true)\r\n */\r\n public get disablePointerInputWhenUsingDeviceOrientation() {\r\n return this._disablePointerInputWhenUsingDeviceOrientation;\r\n }\r\n\r\n public set disablePointerInputWhenUsingDeviceOrientation(value: boolean) {\r\n this._disablePointerInputWhenUsingDeviceOrientation = value;\r\n }\r\n\r\n private _dragFactor = 0;\r\n /**\r\n * Enabled turning on the y axis when the orientation sensor is active\r\n * @param dragFactor the factor that controls the turn speed (default: 1/300)\r\n */\r\n public enableHorizontalDragging(dragFactor = 1 / 300) {\r\n this._dragFactor = dragFactor;\r\n }\r\n\r\n /**\r\n * Gets the current instance class name (\"DeviceOrientationCamera\").\r\n * This helps avoiding instanceof at run time.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"DeviceOrientationCamera\";\r\n }\r\n\r\n /**\r\n * @internal\r\n * Checks and applies the current values of the inputs to the camera. (Internal use only)\r\n */\r\n public _checkInputs(): void {\r\n super._checkInputs();\r\n this._quaternionCache.copyFrom(this.rotationQuaternion);\r\n if (this._initialQuaternion) {\r\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\r\n }\r\n }\r\n\r\n /**\r\n * Reset the camera to its default orientation on the specified axis only.\r\n * @param axis The axis to reset\r\n */\r\n public resetToCurrentRotation(axis: Axis = Axis.Y): void {\r\n //can only work if this camera has a rotation quaternion already.\r\n if (!this.rotationQuaternion) {\r\n return;\r\n }\r\n\r\n if (!this._initialQuaternion) {\r\n this._initialQuaternion = new Quaternion();\r\n }\r\n\r\n this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);\r\n\r\n [\"x\", \"y\", \"z\"].forEach((axisName) => {\r\n if (!(axis)[axisName]) {\r\n (this._initialQuaternion)[axisName] = 0;\r\n } else {\r\n (this._initialQuaternion)[axisName] *= -1;\r\n }\r\n });\r\n this._initialQuaternion.normalize();\r\n //force rotation update\r\n this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);\r\n }\r\n}\r\n","import { Matrix } from \"../../Maths/math.vector\";\r\n/**\r\n * This represents all the required metrics to create a VR camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#device-orientation-camera\r\n */\r\nexport class VRCameraMetrics {\r\n /**\r\n * Define the horizontal resolution off the screen.\r\n */\r\n public hResolution: number;\r\n /**\r\n * Define the vertical resolution off the screen.\r\n */\r\n public vResolution: number;\r\n /**\r\n * Define the horizontal screen size.\r\n */\r\n public hScreenSize: number;\r\n /**\r\n * Define the vertical screen size.\r\n */\r\n public vScreenSize: number;\r\n /**\r\n * Define the vertical screen center position.\r\n */\r\n public vScreenCenter: number;\r\n /**\r\n * Define the distance of the eyes to the screen.\r\n */\r\n public eyeToScreenDistance: number;\r\n /**\r\n * Define the distance between both lenses\r\n */\r\n public lensSeparationDistance: number;\r\n /**\r\n * Define the distance between both viewer's eyes.\r\n */\r\n public interpupillaryDistance: number;\r\n /**\r\n * Define the distortion factor of the VR postprocess.\r\n * Please, touch with care.\r\n */\r\n public distortionK: number[];\r\n /**\r\n * Define the chromatic aberration correction factors for the VR post process.\r\n */\r\n public chromaAbCorrection: number[];\r\n /**\r\n * Define the scale factor of the post process.\r\n * The smaller the better but the slower.\r\n */\r\n public postProcessScaleFactor: number;\r\n /**\r\n * Define an offset for the lens center.\r\n */\r\n public lensCenterOffset: number;\r\n /**\r\n * Define if the current vr camera should compensate the distortion of the lens or not.\r\n */\r\n public compensateDistortion = true;\r\n\r\n /**\r\n * Defines if multiview should be enabled when rendering (Default: false)\r\n */\r\n public multiviewEnabled = false;\r\n\r\n /**\r\n * Gets the rendering aspect ratio based on the provided resolutions.\r\n */\r\n public get aspectRatio(): number {\r\n return this.hResolution / (2 * this.vResolution);\r\n }\r\n\r\n /**\r\n * Gets the aspect ratio based on the FOV, scale factors, and real screen sizes.\r\n */\r\n public get aspectRatioFov(): number {\r\n return 2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance));\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get leftHMatrix(): Matrix {\r\n const meters = this.hScreenSize / 4 - this.lensSeparationDistance / 2;\r\n const h = (4 * meters) / this.hScreenSize;\r\n\r\n return Matrix.Translation(h, 0, 0);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get rightHMatrix(): Matrix {\r\n const meters = this.hScreenSize / 4 - this.lensSeparationDistance / 2;\r\n const h = (4 * meters) / this.hScreenSize;\r\n\r\n return Matrix.Translation(-h, 0, 0);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get leftPreViewMatrix(): Matrix {\r\n return Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get rightPreViewMatrix(): Matrix {\r\n return Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);\r\n }\r\n\r\n /**\r\n * Get the default VRMetrics based on the most generic setup.\r\n * @returns the default vr metrics\r\n */\r\n public static GetDefault(): VRCameraMetrics {\r\n const result = new VRCameraMetrics();\r\n\r\n result.hResolution = 1280;\r\n result.vResolution = 800;\r\n result.hScreenSize = 0.149759993;\r\n result.vScreenSize = 0.0935999975;\r\n result.vScreenCenter = 0.0467999987;\r\n result.eyeToScreenDistance = 0.0410000011;\r\n result.lensSeparationDistance = 0.063500002;\r\n result.interpupillaryDistance = 0.064000003;\r\n result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];\r\n result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];\r\n result.postProcessScaleFactor = 1.714605507808412;\r\n result.lensCenterOffset = 0.151976421;\r\n\r\n return result;\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"vrDistortionCorrectionPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform vec2 LensCenter;uniform vec2 Scale;uniform vec2 ScaleIn;uniform vec4 HmdWarpParam;vec2 HmdWarp(vec2 in01) {vec2 theta=(in01-LensCenter)*ScaleIn; \nfloat rSq=theta.x*theta.x+theta.y*theta.y;vec2 rvector=theta*(HmdWarpParam.x+HmdWarpParam.y*rSq+HmdWarpParam.z*rSq*rSq+HmdWarpParam.w*rSq*rSq*rSq);return LensCenter+Scale*rvector;}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec2 tc=HmdWarp(vUV);if (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\ngl_FragColor=vec4(0.0,0.0,0.0,0.0);else{gl_FragColor=texture2D(textureSampler,tc);}}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const vrDistortionCorrectionPixelShader = { name, shader };\n","import { Vector2 } from \"../Maths/math.vector\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { VRCameraMetrics } from \"../Cameras/VR/vrCameraMetrics\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { PostProcess } from \"./postProcess\";\r\n\r\nimport \"../Shaders/vrDistortionCorrection.fragment\";\r\nimport type { Nullable } from \"../types\";\r\n\r\n/**\r\n * VRDistortionCorrectionPostProcess used for mobile VR\r\n */\r\nexport class VRDistortionCorrectionPostProcess extends PostProcess {\r\n private _isRightEye: boolean;\r\n private _distortionFactors: number[];\r\n private _postProcessScaleFactor: number;\r\n private _lensCenterOffset: number;\r\n private _scaleIn: Vector2;\r\n private _scaleFactor: Vector2;\r\n private _lensCenter: Vector2;\r\n\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"VRDistortionCorrectionPostProcess\" string\r\n */\r\n public getClassName(): string {\r\n return \"VRDistortionCorrectionPostProcess\";\r\n }\r\n\r\n /**\r\n * Initializes the VRDistortionCorrectionPostProcess\r\n * @param name The name of the effect.\r\n * @param camera The camera to apply the render pass to.\r\n * @param isRightEye If this is for the right eye distortion\r\n * @param vrMetrics All the required metrics for the VR camera\r\n */\r\n constructor(name: string, camera: Nullable, isRightEye: boolean, vrMetrics: VRCameraMetrics) {\r\n super(name, \"vrDistortionCorrection\", [\"LensCenter\", \"Scale\", \"ScaleIn\", \"HmdWarpParam\"], null, vrMetrics.postProcessScaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);\r\n\r\n this._isRightEye = isRightEye;\r\n this._distortionFactors = vrMetrics.distortionK;\r\n this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;\r\n this._lensCenterOffset = vrMetrics.lensCenterOffset;\r\n this.adaptScaleToCurrentViewport = true;\r\n\r\n this.onSizeChangedObservable.add(() => {\r\n this._scaleIn = new Vector2(2, 2 / this.aspectRatio);\r\n this._scaleFactor = new Vector2(0.5 * (1 / this._postProcessScaleFactor), 0.5 * (1 / this._postProcessScaleFactor) * this.aspectRatio);\r\n this._lensCenter = new Vector2(this._isRightEye ? 0.5 - this._lensCenterOffset * 0.5 : 0.5 + this._lensCenterOffset * 0.5, 0.5);\r\n });\r\n this.onApplyObservable.add((effect: Effect) => {\r\n effect.setFloat2(\"LensCenter\", this._lensCenter.x, this._lensCenter.y);\r\n effect.setFloat2(\"Scale\", this._scaleFactor.x, this._scaleFactor.y);\r\n effect.setFloat2(\"ScaleIn\", this._scaleIn.x, this._scaleIn.y);\r\n effect.setFloat4(\"HmdWarpParam\", this._distortionFactors[0], this._distortionFactors[1], this._distortionFactors[2], this._distortionFactors[3]);\r\n });\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"vrMultiviewToSingleviewPixelShader\";\nconst shader = `precision mediump sampler2DArray;varying vec2 vUV;uniform sampler2DArray multiviewSampler;uniform int imageIndex;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{gl_FragColor=texture2D(multiviewSampler,vec3(vUV,imageIndex));}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const vrMultiviewToSingleviewPixelShader = { name, shader };\n","import { RenderTargetTexture } from \"../Textures/renderTargetTexture\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\n/**\r\n * Renders to multiple views with a single draw call\r\n * @see https://www.khronos.org/registry/webgl/extensions/OVR_multiview2/\r\n */\r\nexport class MultiviewRenderTarget extends RenderTargetTexture {\r\n public set samples(value: number) {\r\n // We override this setter because multisampling is handled by framebufferTextureMultisampleMultiviewOVR\r\n this._samples = value;\r\n }\r\n\r\n public get samples(): number {\r\n return this._samples;\r\n }\r\n\r\n /**\r\n * Creates a multiview render target\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"multiview rtt\", size, scene, false, true, Constants.TEXTURETYPE_UNSIGNED_INT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = this.getScene()!.getEngine().createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight());\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n this.samples = this._getEngine()!.getCaps().maxSamples || this.samples;\r\n this._texture.samples = this._samples;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n this.getScene()!.getEngine().bindMultiviewFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a MultiviewRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n}\r\n","import { Camera } from \"../../Cameras/camera\";\r\nimport { Engine } from \"../../Engines/engine\";\r\nimport { Scene } from \"../../scene\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Matrix, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport { MultiviewRenderTarget } from \"../../Materials/Textures/MultiviewRenderTarget\";\r\nimport { Frustum } from \"../../Maths/math.frustum\";\r\nimport type { WebGLRenderTargetWrapper } from \"../WebGL/webGLRenderTargetWrapper\";\r\nimport type { RenderTargetWrapper } from \"../renderTargetWrapper\";\r\n\r\ndeclare module \"../../Engines/engine\" {\r\n export interface Engine {\r\n /**\r\n * Creates a new multiview render target\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @returns the created multiview render target wrapper\r\n */\r\n createMultiviewRenderTargetTexture(width: number, height: number, colorTexture?: WebGLTexture, depthStencilTexture?: WebGLTexture): RenderTargetWrapper;\r\n\r\n /**\r\n * Binds a multiview render target wrapper to be drawn to\r\n * @param multiviewTexture render target wrapper to bind\r\n */\r\n bindMultiviewFramebuffer(multiviewTexture: RenderTargetWrapper): void;\r\n\r\n /**\r\n * Binds a Space Warp render target wrapper to be drawn to\r\n * @param spaceWarpTexture render target wrapper to bind\r\n */\r\n bindSpaceWarpFramebuffer(spaceWarpTexture: RenderTargetWrapper): void;\r\n }\r\n}\r\n\r\nEngine.prototype.createMultiviewRenderTargetTexture = function (width: number, height: number, colorTexture?: WebGLTexture, depthStencilTexture?: WebGLTexture) {\r\n const gl = this._gl;\r\n\r\n if (!this.getCaps().multiview) {\r\n throw \"Multiview is not supported\";\r\n }\r\n\r\n const rtWrapper = this._createHardwareRenderTargetWrapper(false, false, { width, height }) as WebGLRenderTargetWrapper;\r\n\r\n rtWrapper._framebuffer = gl.createFramebuffer();\r\n\r\n const internalTexture = new InternalTexture(this, InternalTextureSource.Unknown, true);\r\n internalTexture.width = width;\r\n internalTexture.height = height;\r\n internalTexture.isMultiview = true;\r\n\r\n if (!colorTexture) {\r\n colorTexture = gl.createTexture() as WebGLTexture;\r\n gl.bindTexture(gl.TEXTURE_2D_ARRAY, colorTexture);\r\n (gl as any).texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RGBA8, width, height, 2);\r\n }\r\n\r\n rtWrapper._colorTextureArray = colorTexture;\r\n\r\n if (!depthStencilTexture) {\r\n depthStencilTexture = gl.createTexture() as WebGLTexture;\r\n gl.bindTexture(gl.TEXTURE_2D_ARRAY, depthStencilTexture);\r\n (gl as any).texStorage3D(gl.TEXTURE_2D_ARRAY, 1, (gl as any).DEPTH24_STENCIL8, width, height, 2);\r\n }\r\n\r\n rtWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n internalTexture.isReady = true;\r\n\r\n rtWrapper.setTextures(internalTexture);\r\n rtWrapper._depthStencilTexture = internalTexture;\r\n\r\n return rtWrapper;\r\n};\r\n\r\nEngine.prototype.bindMultiviewFramebuffer = function (_multiviewTexture: RenderTargetWrapper) {\r\n const multiviewTexture = _multiviewTexture as WebGLRenderTargetWrapper;\r\n\r\n const gl: any = this._gl;\r\n const ext = this.getCaps().oculusMultiview || this.getCaps().multiview;\r\n\r\n this.bindFramebuffer(multiviewTexture, undefined, undefined, undefined, true);\r\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, multiviewTexture._framebuffer);\r\n if (multiviewTexture._colorTextureArray && multiviewTexture._depthStencilTextureArray) {\r\n if (this.getCaps().oculusMultiview) {\r\n ext.framebufferTextureMultisampleMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, multiviewTexture._colorTextureArray, 0, multiviewTexture.samples, 0, 2);\r\n ext.framebufferTextureMultisampleMultiviewOVR(\r\n gl.DRAW_FRAMEBUFFER,\r\n gl.DEPTH_STENCIL_ATTACHMENT,\r\n multiviewTexture._depthStencilTextureArray,\r\n 0,\r\n multiviewTexture.samples,\r\n 0,\r\n 2\r\n );\r\n } else {\r\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, multiviewTexture._colorTextureArray, 0, 0, 2);\r\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, multiviewTexture._depthStencilTextureArray, 0, 0, 2);\r\n }\r\n } else {\r\n throw \"Invalid multiview frame buffer\";\r\n }\r\n};\r\n\r\nEngine.prototype.bindSpaceWarpFramebuffer = function (_spaceWarpTexture: RenderTargetWrapper) {\r\n const spaceWarpTexture = _spaceWarpTexture as WebGLRenderTargetWrapper;\r\n\r\n const gl: any = this._gl;\r\n const ext = this.getCaps().oculusMultiview || this.getCaps().multiview;\r\n\r\n this.bindFramebuffer(spaceWarpTexture, undefined, undefined, undefined, true);\r\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, spaceWarpTexture._framebuffer);\r\n if (spaceWarpTexture._colorTextureArray && spaceWarpTexture._depthStencilTextureArray) {\r\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, spaceWarpTexture._colorTextureArray, 0, 0, 2);\r\n ext.framebufferTextureMultiviewOVR(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, spaceWarpTexture._depthStencilTextureArray, 0, 0, 2);\r\n } else {\r\n throw new Error(\"Invalid Space Warp framebuffer\");\r\n }\r\n};\r\n\r\ndeclare module \"../../Cameras/camera\" {\r\n export interface Camera {\r\n /**\r\n * @internal\r\n * For cameras that cannot use multiview images to display directly. (e.g. webVR camera will render to multiview texture, then copy to each eye texture and go from there)\r\n */\r\n _useMultiviewToSingleView: boolean;\r\n /**\r\n * @internal\r\n * For cameras that cannot use multiview images to display directly. (e.g. webVR camera will render to multiview texture, then copy to each eye texture and go from there)\r\n */\r\n _multiviewTexture: Nullable;\r\n\r\n /**\r\n * @internal\r\n * For WebXR cameras that are rendering to multiview texture arrays.\r\n */\r\n _renderingMultiview: boolean;\r\n\r\n /**\r\n * @internal\r\n * ensures the multiview texture of the camera exists and has the specified width/height\r\n * @param width height to set on the multiview texture\r\n * @param height width to set on the multiview texture\r\n */\r\n _resizeOrCreateMultiviewTexture(width: number, height: number): void;\r\n }\r\n}\r\n\r\nCamera.prototype._useMultiviewToSingleView = false;\r\n\r\nCamera.prototype._multiviewTexture = null;\r\n\r\nCamera.prototype._resizeOrCreateMultiviewTexture = function (width: number, height: number) {\r\n if (!this._multiviewTexture) {\r\n this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), { width: width, height: height });\r\n } else if (this._multiviewTexture.getRenderWidth() != width || this._multiviewTexture.getRenderHeight() != height) {\r\n this._multiviewTexture.dispose();\r\n this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), { width: width, height: height });\r\n }\r\n};\r\n\r\ndeclare module \"../../scene\" {\r\n export interface Scene {\r\n /** @internal */\r\n _transformMatrixR: Matrix;\r\n /** @internal */\r\n _multiviewSceneUbo: Nullable;\r\n /** @internal */\r\n _createMultiviewUbo(): void;\r\n /** @internal */\r\n _updateMultiviewUbo(viewR?: Matrix, projectionR?: Matrix): void;\r\n /** @internal */\r\n _renderMultiviewToSingleView(camera: Camera): void;\r\n }\r\n}\r\n\r\nfunction createMultiviewUbo(engine: Engine, name?: string) {\r\n const ubo = new UniformBuffer(engine, undefined, true, name);\r\n ubo.addUniform(\"viewProjection\", 16);\r\n ubo.addUniform(\"viewProjectionR\", 16);\r\n ubo.addUniform(\"view\", 16);\r\n ubo.addUniform(\"projection\", 16);\r\n ubo.addUniform(\"vEyePosition\", 4);\r\n return ubo;\r\n}\r\n\r\nconst currentCreateSceneUniformBuffer = Scene.prototype.createSceneUniformBuffer;\r\n\r\nScene.prototype._transformMatrixR = Matrix.Zero();\r\nScene.prototype._multiviewSceneUbo = null;\r\nScene.prototype._createMultiviewUbo = function () {\r\n this._multiviewSceneUbo = createMultiviewUbo(this.getEngine(), \"scene_multiview\");\r\n};\r\nScene.prototype.createSceneUniformBuffer = function (name?: string): UniformBuffer {\r\n if (this._multiviewSceneUbo) {\r\n return createMultiviewUbo(this.getEngine(), name);\r\n }\r\n return currentCreateSceneUniformBuffer.bind(this)(name);\r\n};\r\nScene.prototype._updateMultiviewUbo = function (viewR?: Matrix, projectionR?: Matrix) {\r\n if (viewR && projectionR) {\r\n viewR.multiplyToRef(projectionR, this._transformMatrixR);\r\n }\r\n\r\n if (viewR && projectionR) {\r\n viewR.multiplyToRef(projectionR, TmpVectors.Matrix[0]);\r\n Frustum.GetRightPlaneToRef(TmpVectors.Matrix[0], this._frustumPlanes[3]); // Replace right plane by second camera right plane\r\n }\r\n\r\n if (this._multiviewSceneUbo) {\r\n this._multiviewSceneUbo.updateMatrix(\"viewProjection\", this.getTransformMatrix());\r\n this._multiviewSceneUbo.updateMatrix(\"viewProjectionR\", this._transformMatrixR);\r\n this._multiviewSceneUbo.updateMatrix(\"view\", this._viewMatrix);\r\n this._multiviewSceneUbo.updateMatrix(\"projection\", this._projectionMatrix);\r\n }\r\n};\r\nScene.prototype._renderMultiviewToSingleView = function (camera: Camera) {\r\n // Multiview is only able to be displayed directly for API's such as webXR\r\n // This displays a multiview image by rendering to the multiview image and then\r\n // copying the result into the sub cameras instead of rendering them and proceeding as normal from there\r\n\r\n // Render to a multiview texture\r\n camera._resizeOrCreateMultiviewTexture(\r\n camera._rigPostProcess && camera._rigPostProcess && camera._rigPostProcess.width > 0 ? camera._rigPostProcess.width : this.getEngine().getRenderWidth(true),\r\n camera._rigPostProcess && camera._rigPostProcess && camera._rigPostProcess.height > 0 ? camera._rigPostProcess.height : this.getEngine().getRenderHeight(true)\r\n );\r\n if (!this._multiviewSceneUbo) {\r\n this._createMultiviewUbo();\r\n }\r\n camera.outputRenderTarget = camera._multiviewTexture;\r\n this._renderForCamera(camera);\r\n camera.outputRenderTarget = null;\r\n\r\n // Consume the multiview texture through a shader for each eye\r\n for (let index = 0; index < camera._rigCameras.length; index++) {\r\n const engine = this.getEngine();\r\n this._activeCamera = camera._rigCameras[index];\r\n engine.setViewport(this._activeCamera.viewport);\r\n if (this.postProcessManager) {\r\n this.postProcessManager._prepareFrame();\r\n this.postProcessManager._finalizeFrame(this._activeCamera.isIntermediate);\r\n }\r\n }\r\n};\r\n","import type { Camera } from \"../Cameras/camera\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { PostProcess } from \"./postProcess\";\r\n\r\nimport \"../Shaders/vrMultiviewToSingleview.fragment\";\r\nimport \"../Engines/Extensions/engine.multiview\";\r\nimport type { Nullable } from \"../types\";\r\n\r\n/**\r\n * VRMultiviewToSingleview used to convert multiview texture arrays to standard textures for scenarios such as webVR\r\n * This will not be used for webXR as it supports displaying texture arrays directly\r\n */\r\nexport class VRMultiviewToSingleviewPostProcess extends PostProcess {\r\n /**\r\n * Gets a string identifying the name of the class\r\n * @returns \"VRMultiviewToSingleviewPostProcess\" string\r\n */\r\n public getClassName(): string {\r\n return \"VRMultiviewToSingleviewPostProcess\";\r\n }\r\n\r\n /**\r\n * Initializes a VRMultiviewToSingleview\r\n * @param name name of the post process\r\n * @param camera camera to be applied to\r\n * @param scaleFactor scaling factor to the size of the output texture\r\n */\r\n constructor(name: string, camera: Nullable, scaleFactor: number) {\r\n super(name, \"vrMultiviewToSingleview\", [\"imageIndex\"], [\"multiviewSampler\"], scaleFactor, camera, Texture.BILINEAR_SAMPLINGMODE);\r\n\r\n const cam = camera ?? this.getCamera();\r\n this.onSizeChangedObservable.add(() => {});\r\n this.onApplyObservable.add((effect: Effect) => {\r\n if (cam._scene.activeCamera && cam._scene.activeCamera.isLeftCamera) {\r\n effect.setInt(\"imageIndex\", 0);\r\n } else {\r\n effect.setInt(\"imageIndex\", 1);\r\n }\r\n effect.setTexture(\"multiviewSampler\", cam._multiviewTexture);\r\n });\r\n }\r\n}\r\n","import type { Camera } from \"../camera\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { VRDistortionCorrectionPostProcess } from \"../../PostProcesses/vrDistortionCorrectionPostProcess\";\r\nimport { VRMultiviewToSingleviewPostProcess } from \"../../PostProcesses/vrMultiviewToSingleviewPostProcess\";\r\nimport { VRCameraMetrics } from \"../VR/vrCameraMetrics\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { Viewport } from \"../../Maths/math.viewport\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function setVRRigMode(camera: Camera, rigParams: any) {\r\n const metrics = rigParams.vrCameraMetrics || VRCameraMetrics.GetDefault();\r\n\r\n camera._rigCameras[0]._cameraRigParams.vrMetrics = metrics;\r\n camera._rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\r\n camera._rigCameras[0]._cameraRigParams.vrWorkMatrix = new Matrix();\r\n camera._rigCameras[0]._cameraRigParams.vrHMatrix = metrics.leftHMatrix;\r\n camera._rigCameras[0]._cameraRigParams.vrPreViewMatrix = metrics.leftPreViewMatrix;\r\n camera._rigCameras[0].getProjectionMatrix = camera._rigCameras[0]._getVRProjectionMatrix;\r\n\r\n camera._rigCameras[1]._cameraRigParams.vrMetrics = metrics;\r\n camera._rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\r\n camera._rigCameras[1]._cameraRigParams.vrWorkMatrix = new Matrix();\r\n camera._rigCameras[1]._cameraRigParams.vrHMatrix = metrics.rightHMatrix;\r\n camera._rigCameras[1]._cameraRigParams.vrPreViewMatrix = metrics.rightPreViewMatrix;\r\n camera._rigCameras[1].getProjectionMatrix = camera._rigCameras[1]._getVRProjectionMatrix;\r\n\r\n // For multiview on a webVR camera\r\n // First multiview will be rendered to camera._multiviewTexture\r\n // Then this postprocess will run on each eye to copy the right texture to each eye\r\n if (metrics.multiviewEnabled) {\r\n if (!camera.getScene().getEngine().getCaps().multiview) {\r\n Logger.Warn(\"Multiview is not supported, falling back to standard rendering\");\r\n metrics.multiviewEnabled = false;\r\n } else {\r\n camera._useMultiviewToSingleView = true;\r\n camera._rigPostProcess = new VRMultiviewToSingleviewPostProcess(\"VRMultiviewToSingleview\", camera, metrics.postProcessScaleFactor);\r\n }\r\n }\r\n\r\n if (metrics.compensateDistortion) {\r\n camera._rigCameras[0]._rigPostProcess = new VRDistortionCorrectionPostProcess(\"VR_Distort_Compensation_Left\", camera._rigCameras[0], false, metrics);\r\n camera._rigCameras[1]._rigPostProcess = new VRDistortionCorrectionPostProcess(\"VR_Distort_Compensation_Right\", camera._rigCameras[1], true, metrics);\r\n }\r\n}\r\n","import { Camera } from \"../../Cameras/camera\";\r\nimport { DeviceOrientationCamera } from \"../../Cameras/deviceOrientationCamera\";\r\nimport { VRCameraMetrics } from \"./vrCameraMetrics\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Node } from \"../../node\";\r\nimport { setVRRigMode } from \"../RigModes/vrRigMode\";\r\n\r\nNode.AddNodeConstructor(\"VRDeviceOrientationFreeCamera\", (name, scene) => {\r\n return () => new VRDeviceOrientationFreeCamera(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * Camera used to simulate VR rendering (based on FreeCamera)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#vr-device-orientation-cameras\r\n */\r\nexport class VRDeviceOrientationFreeCamera extends DeviceOrientationCamera {\r\n /**\r\n * Creates a new VRDeviceOrientationFreeCamera\r\n * @param name defines camera name\r\n * @param position defines the start position of the camera\r\n * @param scene defines the scene the camera belongs to\r\n * @param compensateDistortion defines if the camera needs to compensate the lens distortion\r\n * @param vrCameraMetrics defines the vr metrics associated to the camera\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene, compensateDistortion = true, vrCameraMetrics: VRCameraMetrics = VRCameraMetrics.GetDefault()) {\r\n super(name, position, scene);\r\n\r\n vrCameraMetrics.compensateDistortion = compensateDistortion;\r\n this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });\r\n }\r\n\r\n /**\r\n * Gets camera class name\r\n * @returns VRDeviceOrientationFreeCamera\r\n */\r\n public getClassName(): string {\r\n return \"VRDeviceOrientationFreeCamera\";\r\n }\r\n\r\n protected _setRigMode = setVRRigMode.bind(null, this);\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\n\r\n/**\r\n * Represents a gamepad control stick position\r\n */\r\nexport class StickValues {\r\n /**\r\n * Initializes the gamepad x and y control stick values\r\n * @param x The x component of the gamepad control stick value\r\n * @param y The y component of the gamepad control stick value\r\n */\r\n constructor(\r\n /**\r\n * The x component of the control stick\r\n */\r\n public x: number,\r\n /**\r\n * The y component of the control stick\r\n */\r\n public y: number\r\n ) {}\r\n}\r\n\r\n/**\r\n * An interface which manages callbacks for gamepad button changes\r\n */\r\nexport interface GamepadButtonChanges {\r\n /**\r\n * Called when a gamepad has been changed\r\n */\r\n changed: boolean;\r\n /**\r\n * Called when a gamepad press event has been triggered\r\n */\r\n pressChanged: boolean;\r\n /**\r\n * Called when a touch event has been triggered\r\n */\r\n touchChanged: boolean;\r\n /**\r\n * Called when a value has changed\r\n */\r\n valueChanged: boolean;\r\n}\r\n\r\n/**\r\n * Represents a gamepad\r\n */\r\nexport class Gamepad {\r\n /**\r\n * Specifies what type of gamepad this represents\r\n */\r\n public type: number;\r\n\r\n private _leftStick: StickValues = { x: 0, y: 0 };\r\n private _rightStick: StickValues = { x: 0, y: 0 };\r\n\r\n /** @internal */\r\n public _isConnected = true;\r\n\r\n private _leftStickAxisX: number;\r\n private _leftStickAxisY: number;\r\n private _rightStickAxisX: number;\r\n private _rightStickAxisY: number;\r\n\r\n /**\r\n * Triggered when the left control stick has been changed\r\n */\r\n private _onleftstickchanged: (values: StickValues) => void;\r\n\r\n /**\r\n * Triggered when the right control stick has been changed\r\n */\r\n private _onrightstickchanged: (values: StickValues) => void;\r\n\r\n /**\r\n * Represents a gamepad controller\r\n */\r\n public static GAMEPAD = 0;\r\n /**\r\n * Represents a generic controller\r\n */\r\n public static GENERIC = 1;\r\n /**\r\n * Represents an XBox controller\r\n */\r\n public static XBOX = 2;\r\n /**\r\n * Represents a pose-enabled controller\r\n */\r\n public static POSE_ENABLED = 3;\r\n /**\r\n * Represents an Dual Shock controller\r\n */\r\n public static DUALSHOCK = 4;\r\n\r\n /**\r\n * Specifies whether the left control stick should be Y-inverted\r\n */\r\n protected _invertLeftStickY: boolean = false;\r\n\r\n /**\r\n * Specifies if the gamepad has been connected\r\n */\r\n public get isConnected(): boolean {\r\n return this._isConnected;\r\n }\r\n\r\n /**\r\n * Initializes the gamepad\r\n * @param id The id of the gamepad\r\n * @param index The index of the gamepad\r\n * @param browserGamepad The browser gamepad\r\n * @param leftStickX The x component of the left joystick\r\n * @param leftStickY The y component of the left joystick\r\n * @param rightStickX The x component of the right joystick\r\n * @param rightStickY The y component of the right joystick\r\n */\r\n constructor(\r\n /**\r\n * The id of the gamepad\r\n */\r\n public id: string,\r\n /**\r\n * The index of the gamepad\r\n */\r\n public index: number,\r\n /**\r\n * The browser gamepad\r\n */\r\n public browserGamepad: any,\r\n leftStickX: number = 0,\r\n leftStickY: number = 1,\r\n rightStickX: number = 2,\r\n rightStickY: number = 3\r\n ) {\r\n this.type = Gamepad.GAMEPAD;\r\n this._leftStickAxisX = leftStickX;\r\n this._leftStickAxisY = leftStickY;\r\n this._rightStickAxisX = rightStickX;\r\n this._rightStickAxisY = rightStickY;\r\n if (this.browserGamepad.axes.length >= 2) {\r\n this._leftStick = { x: this.browserGamepad.axes[this._leftStickAxisX], y: this.browserGamepad.axes[this._leftStickAxisY] };\r\n }\r\n if (this.browserGamepad.axes.length >= 4) {\r\n this._rightStick = { x: this.browserGamepad.axes[this._rightStickAxisX], y: this.browserGamepad.axes[this._rightStickAxisY] };\r\n }\r\n }\r\n\r\n /**\r\n * Callback triggered when the left joystick has changed\r\n * @param callback\r\n */\r\n public onleftstickchanged(callback: (values: StickValues) => void) {\r\n this._onleftstickchanged = callback;\r\n }\r\n\r\n /**\r\n * Callback triggered when the right joystick has changed\r\n * @param callback\r\n */\r\n public onrightstickchanged(callback: (values: StickValues) => void) {\r\n this._onrightstickchanged = callback;\r\n }\r\n\r\n /**\r\n * Gets the left joystick\r\n */\r\n public get leftStick(): StickValues {\r\n return this._leftStick;\r\n }\r\n /**\r\n * Sets the left joystick values\r\n */\r\n public set leftStick(newValues: StickValues) {\r\n if (this._onleftstickchanged && (this._leftStick.x !== newValues.x || this._leftStick.y !== newValues.y)) {\r\n this._onleftstickchanged(newValues);\r\n }\r\n this._leftStick = newValues;\r\n }\r\n /**\r\n * Gets the right joystick\r\n */\r\n public get rightStick(): StickValues {\r\n return this._rightStick;\r\n }\r\n /**\r\n * Sets the right joystick value\r\n */\r\n public set rightStick(newValues: StickValues) {\r\n if (this._onrightstickchanged && (this._rightStick.x !== newValues.x || this._rightStick.y !== newValues.y)) {\r\n this._onrightstickchanged(newValues);\r\n }\r\n this._rightStick = newValues;\r\n }\r\n\r\n /**\r\n * Updates the gamepad joystick positions\r\n */\r\n\r\n public update() {\r\n if (this._leftStick) {\r\n this.leftStick = { x: this.browserGamepad.axes[this._leftStickAxisX], y: this.browserGamepad.axes[this._leftStickAxisY] };\r\n if (this._invertLeftStickY) {\r\n this.leftStick.y *= -1;\r\n }\r\n }\r\n if (this._rightStick) {\r\n this.rightStick = { x: this.browserGamepad.axes[this._rightStickAxisX], y: this.browserGamepad.axes[this._rightStickAxisY] };\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the gamepad\r\n */\r\n public dispose() {}\r\n}\r\n\r\n/**\r\n * Represents a generic gamepad\r\n */\r\nexport class GenericPad extends Gamepad {\r\n private _buttons: Array;\r\n private _onbuttondown: (buttonPressed: number) => void;\r\n private _onbuttonup: (buttonReleased: number) => void;\r\n\r\n /**\r\n * Observable triggered when a button has been pressed\r\n */\r\n public onButtonDownObservable = new Observable();\r\n /**\r\n * Observable triggered when a button has been released\r\n */\r\n public onButtonUpObservable = new Observable();\r\n\r\n /**\r\n * Callback triggered when a button has been pressed\r\n * @param callback Called when a button has been pressed\r\n */\r\n public onbuttondown(callback: (buttonPressed: number) => void) {\r\n this._onbuttondown = callback;\r\n }\r\n /**\r\n * Callback triggered when a button has been released\r\n * @param callback Called when a button has been released\r\n */\r\n public onbuttonup(callback: (buttonReleased: number) => void) {\r\n this._onbuttonup = callback;\r\n }\r\n\r\n /**\r\n * Initializes the generic gamepad\r\n * @param id The id of the generic gamepad\r\n * @param index The index of the generic gamepad\r\n * @param browserGamepad The browser gamepad\r\n */\r\n constructor(id: string, index: number, browserGamepad: any) {\r\n super(id, index, browserGamepad);\r\n this.type = Gamepad.GENERIC;\r\n this._buttons = new Array(browserGamepad.buttons.length);\r\n }\r\n\r\n private _setButtonValue(newValue: number, currentValue: number, buttonIndex: number): number {\r\n if (newValue !== currentValue) {\r\n if (newValue === 1) {\r\n if (this._onbuttondown) {\r\n this._onbuttondown(buttonIndex);\r\n }\r\n\r\n this.onButtonDownObservable.notifyObservers(buttonIndex);\r\n }\r\n if (newValue === 0) {\r\n if (this._onbuttonup) {\r\n this._onbuttonup(buttonIndex);\r\n }\r\n\r\n this.onButtonUpObservable.notifyObservers(buttonIndex);\r\n }\r\n }\r\n return newValue;\r\n }\r\n\r\n /**\r\n * Updates the generic gamepad\r\n */\r\n public update() {\r\n super.update();\r\n for (let index = 0; index < this._buttons.length; index++) {\r\n this._buttons[index] = this._setButtonValue(this.browserGamepad.buttons[index].value, this._buttons[index], index);\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the generic gamepad\r\n */\r\n public dispose() {\r\n super.dispose();\r\n this.onButtonDownObservable.clear();\r\n this.onButtonUpObservable.clear();\r\n }\r\n}\r\n","import { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Matrix, Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Node } from \"../../node\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Ray } from \"../../Culling/ray\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\n\r\nimport { Gamepad } from \"../../Gamepads/gamepad\";\r\nimport type { WebVRFreeCamera, PoseControlled, DevicePose } from \"../../Cameras/VR/webVRCamera\";\r\nimport type { TargetCamera } from \"../../Cameras/targetCamera\";\r\n\r\n/**\r\n * Defines the types of pose enabled controllers that are supported\r\n */\r\nexport enum PoseEnabledControllerType {\r\n /**\r\n * HTC Vive\r\n */\r\n VIVE,\r\n /**\r\n * Oculus Rift\r\n */\r\n OCULUS,\r\n /**\r\n * Windows mixed reality\r\n */\r\n WINDOWS,\r\n /**\r\n * Samsung gear VR\r\n */\r\n GEAR_VR,\r\n /**\r\n * Google Daydream\r\n */\r\n DAYDREAM,\r\n /**\r\n * Generic\r\n */\r\n GENERIC,\r\n}\r\n\r\n/**\r\n * Defines the MutableGamepadButton interface for the state of a gamepad button\r\n */\r\nexport interface MutableGamepadButton {\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n}\r\n\r\n/**\r\n * Defines the ExtendedGamepadButton interface for a gamepad button which includes state provided by a pose controller\r\n * @internal\r\n */\r\nexport interface ExtendedGamepadButton extends GamepadButton {\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n readonly pressed: boolean;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n readonly touched: boolean;\r\n /**\r\n * Value of the button/trigger\r\n */\r\n readonly value: number;\r\n}\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface _GamePadFactory {\r\n /**\r\n * Returns whether or not the current gamepad can be created for this type of controller.\r\n * @param gamepadInfo Defines the gamepad info as received from the controller APIs.\r\n * @returns true if it can be created, otherwise false\r\n */\r\n canCreate(gamepadInfo: any): boolean;\r\n\r\n /**\r\n * Creates a new instance of the Gamepad.\r\n * @param gamepadInfo Defines the gamepad info as received from the controller APIs.\r\n * @returns the new gamepad instance\r\n */\r\n create(gamepadInfo: any): Gamepad;\r\n}\r\n\r\n/**\r\n * Defines the PoseEnabledControllerHelper object that is used initialize a gamepad as the controller type it is specified as (eg. windows mixed reality controller)\r\n */\r\nexport class PoseEnabledControllerHelper {\r\n /** @internal */\r\n public static _ControllerFactories: _GamePadFactory[] = [];\r\n\r\n /** @internal */\r\n public static _DefaultControllerFactory: Nullable<(gamepadInfo: any) => Gamepad> = null;\r\n\r\n /**\r\n * Initializes a gamepad as the controller type it is specified as (eg. windows mixed reality controller)\r\n * @param vrGamepad the gamepad to initialized\r\n * @returns a vr controller of the type the gamepad identified as\r\n */\r\n public static InitiateController(vrGamepad: any) {\r\n for (const factory of this._ControllerFactories) {\r\n if (factory.canCreate(vrGamepad)) {\r\n return factory.create(vrGamepad);\r\n }\r\n }\r\n\r\n if (this._DefaultControllerFactory) {\r\n return this._DefaultControllerFactory(vrGamepad);\r\n }\r\n\r\n throw \"The type of gamepad you are trying to load needs to be imported first or is not supported.\";\r\n }\r\n}\r\n\r\n/**\r\n * Defines the PoseEnabledController object that contains state of a vr capable controller\r\n */\r\nexport class PoseEnabledController extends Gamepad implements PoseControlled {\r\n /**\r\n * If the controller is used in a webXR session\r\n */\r\n public isXR = false;\r\n // Represents device position and rotation in room space. Should only be used to help calculate babylon space values\r\n private _deviceRoomPosition = Vector3.Zero();\r\n private _deviceRoomRotationQuaternion = new Quaternion();\r\n\r\n /**\r\n * The device position in babylon space\r\n */\r\n public devicePosition = Vector3.Zero();\r\n /**\r\n * The device rotation in babylon space\r\n */\r\n public deviceRotationQuaternion = new Quaternion();\r\n /**\r\n * The scale factor of the device in babylon space\r\n */\r\n public deviceScaleFactor: number = 1;\r\n\r\n /**\r\n * (Likely devicePosition should be used instead) The device position in its room space\r\n */\r\n public position: Vector3;\r\n /**\r\n * (Likely deviceRotationQuaternion should be used instead) The device rotation in its room space\r\n */\r\n public rotationQuaternion: Quaternion;\r\n /**\r\n * The type of controller (Eg. Windows mixed reality)\r\n */\r\n public controllerType: PoseEnabledControllerType;\r\n\r\n protected _calculatedPosition: Vector3;\r\n private _calculatedRotation: Quaternion;\r\n\r\n /**\r\n * The raw pose from the device\r\n */\r\n public rawPose: DevicePose; //GamepadPose;\r\n\r\n // Used to convert 6dof controllers to 3dof\r\n private _trackPosition = true;\r\n private _maxRotationDistFromHeadset = Math.PI / 5;\r\n private _draggedRoomRotation = 0;\r\n /**\r\n * @internal\r\n */\r\n public _disableTrackPosition(fixedPosition: Vector3) {\r\n if (this._trackPosition) {\r\n this._calculatedPosition.copyFrom(fixedPosition);\r\n this._trackPosition = false;\r\n }\r\n }\r\n\r\n /**\r\n * Internal, the mesh attached to the controller\r\n * @internal\r\n */\r\n public _mesh: Nullable; // a node that will be attached to this Gamepad\r\n private _poseControlledCamera: TargetCamera;\r\n\r\n private _leftHandSystemQuaternion: Quaternion = new Quaternion();\r\n\r\n /**\r\n * Internal, matrix used to convert room space to babylon space\r\n * @internal\r\n */\r\n public _deviceToWorld = Matrix.Identity();\r\n\r\n /**\r\n * Node to be used when casting a ray from the controller\r\n * @internal\r\n */\r\n public _pointingPoseNode: Nullable = null;\r\n /**\r\n * Name of the child mesh that can be used to cast a ray from the controller\r\n */\r\n public static readonly POINTING_POSE = \"POINTING_POSE\";\r\n /**\r\n * Creates a new PoseEnabledController from a gamepad\r\n * @param browserGamepad the gamepad that the PoseEnabledController should be created from\r\n */\r\n constructor(browserGamepad: any) {\r\n super(browserGamepad.id, browserGamepad.index, browserGamepad);\r\n this.type = Gamepad.POSE_ENABLED;\r\n this.controllerType = PoseEnabledControllerType.GENERIC;\r\n this.position = Vector3.Zero();\r\n this.rotationQuaternion = new Quaternion();\r\n\r\n this._calculatedPosition = Vector3.Zero();\r\n this._calculatedRotation = new Quaternion();\r\n Quaternion.RotationYawPitchRollToRef(Math.PI, 0, 0, this._leftHandSystemQuaternion);\r\n }\r\n\r\n private _workingMatrix = Matrix.Identity();\r\n /**\r\n * Updates the state of the pose enabled controller and mesh based on the current position and rotation of the controller\r\n */\r\n public update() {\r\n super.update();\r\n this._updatePoseAndMesh();\r\n }\r\n\r\n /**\r\n * Updates only the pose device and mesh without doing any button event checking\r\n */\r\n protected _updatePoseAndMesh() {\r\n if (this.isXR) {\r\n return;\r\n }\r\n const pose: DevicePose = this.browserGamepad.pose;\r\n this.updateFromDevice(pose);\r\n\r\n if (\r\n !this._trackPosition &&\r\n EngineStore.LastCreatedScene &&\r\n EngineStore.LastCreatedScene.activeCamera &&\r\n (EngineStore.LastCreatedScene.activeCamera).devicePosition\r\n ) {\r\n const camera = EngineStore.LastCreatedScene.activeCamera;\r\n camera._computeDevicePosition();\r\n\r\n this._deviceToWorld.setTranslation(camera.devicePosition);\r\n if (camera.deviceRotationQuaternion) {\r\n camera._deviceRoomRotationQuaternion.toEulerAnglesToRef(TmpVectors.Vector3[0]);\r\n\r\n // Find the radian distance away that the headset is from the controllers rotation\r\n const distanceAway = Math.atan2(Math.sin(TmpVectors.Vector3[0].y - this._draggedRoomRotation), Math.cos(TmpVectors.Vector3[0].y - this._draggedRoomRotation));\r\n if (Math.abs(distanceAway) > this._maxRotationDistFromHeadset) {\r\n // Only rotate enouph to be within the _maxRotationDistFromHeadset\r\n const rotationAmount = distanceAway - (distanceAway < 0 ? -this._maxRotationDistFromHeadset : this._maxRotationDistFromHeadset);\r\n this._draggedRoomRotation += rotationAmount;\r\n\r\n // Rotate controller around headset\r\n const sin = Math.sin(-rotationAmount);\r\n const cos = Math.cos(-rotationAmount);\r\n this._calculatedPosition.x = this._calculatedPosition.x * cos - this._calculatedPosition.z * sin;\r\n this._calculatedPosition.z = this._calculatedPosition.x * sin + this._calculatedPosition.z * cos;\r\n }\r\n }\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(this._calculatedPosition, this._deviceToWorld, this.devicePosition);\r\n this._deviceToWorld.getRotationMatrixToRef(this._workingMatrix);\r\n Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);\r\n this.deviceRotationQuaternion.multiplyInPlace(this._calculatedRotation);\r\n\r\n if (this._mesh) {\r\n this._mesh.position.copyFrom(this.devicePosition);\r\n\r\n if (this._mesh.rotationQuaternion) {\r\n this._mesh.rotationQuaternion.copyFrom(this.deviceRotationQuaternion);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Updates the state of the pose enbaled controller based on the raw pose data from the device\r\n * @param poseData raw pose fromthe device\r\n */\r\n updateFromDevice(poseData: DevicePose) {\r\n if (this.isXR) {\r\n return;\r\n }\r\n if (poseData) {\r\n this.rawPose = poseData;\r\n if (poseData.position) {\r\n this._deviceRoomPosition.copyFromFloats(poseData.position[0], poseData.position[1], -poseData.position[2]);\r\n if (this._mesh && this._mesh.getScene().useRightHandedSystem) {\r\n this._deviceRoomPosition.z *= -1;\r\n }\r\n if (this._trackPosition) {\r\n this._deviceRoomPosition.scaleToRef(this.deviceScaleFactor, this._calculatedPosition);\r\n }\r\n this._calculatedPosition.addInPlace(this.position);\r\n }\r\n const pose = this.rawPose;\r\n if (poseData.orientation && pose.orientation && pose.orientation.length === 4) {\r\n this._deviceRoomRotationQuaternion.copyFromFloats(pose.orientation[0], pose.orientation[1], -pose.orientation[2], -pose.orientation[3]);\r\n if (this._mesh) {\r\n if (this._mesh.getScene().useRightHandedSystem) {\r\n this._deviceRoomRotationQuaternion.z *= -1;\r\n this._deviceRoomRotationQuaternion.w *= -1;\r\n } else {\r\n this._deviceRoomRotationQuaternion.multiplyToRef(this._leftHandSystemQuaternion, this._deviceRoomRotationQuaternion);\r\n }\r\n }\r\n\r\n // if the camera is set, rotate to the camera's rotation\r\n this._deviceRoomRotationQuaternion.multiplyToRef(this.rotationQuaternion, this._calculatedRotation);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _meshAttachedObservable = new Observable();\r\n\r\n /**\r\n * Attaches a mesh to the controller\r\n * @param mesh the mesh to be attached\r\n */\r\n public attachToMesh(mesh: AbstractMesh) {\r\n if (this._mesh) {\r\n this._mesh.parent = null;\r\n }\r\n this._mesh = mesh;\r\n if (this._poseControlledCamera) {\r\n this._mesh.parent = this._poseControlledCamera;\r\n }\r\n if (!this._mesh.rotationQuaternion) {\r\n this._mesh.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n // Sync controller mesh and pointing pose node's state with controller, this is done to avoid a frame where position is 0,0,0 when attaching mesh\r\n if (!this.isXR) {\r\n this._updatePoseAndMesh();\r\n if (this._pointingPoseNode) {\r\n const parents = [];\r\n let obj: Node = this._pointingPoseNode;\r\n while (obj.parent) {\r\n parents.push(obj.parent);\r\n obj = obj.parent;\r\n }\r\n parents.reverse().forEach((p) => {\r\n p.computeWorldMatrix(true);\r\n });\r\n }\r\n }\r\n\r\n this._meshAttachedObservable.notifyObservers(mesh);\r\n }\r\n\r\n /**\r\n * Attaches the controllers mesh to a camera\r\n * @param camera the camera the mesh should be attached to\r\n */\r\n public attachToPoseControlledCamera(camera: TargetCamera) {\r\n this._poseControlledCamera = camera;\r\n if (this._mesh) {\r\n this._mesh.parent = this._poseControlledCamera;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the controller\r\n */\r\n public dispose() {\r\n if (this._mesh) {\r\n this._mesh.dispose();\r\n }\r\n this._mesh = null;\r\n\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * The mesh that is attached to the controller\r\n */\r\n public get mesh(): Nullable {\r\n return this._mesh;\r\n }\r\n\r\n /**\r\n * Gets the ray of the controller in the direction the controller is pointing\r\n * @param length the length the resulting ray should be\r\n * @returns a ray in the direction the controller is pointing\r\n */\r\n public getForwardRay(length = 100): Ray {\r\n if (!this.mesh) {\r\n return new Ray(Vector3.Zero(), new Vector3(0, 0, 1), length);\r\n }\r\n\r\n const m = this._pointingPoseNode ? this._pointingPoseNode.getWorldMatrix() : this.mesh.getWorldMatrix();\r\n const origin = m.getTranslation();\r\n\r\n const forward = new Vector3(0, 0, -1);\r\n const forwardWorld = Vector3.TransformNormal(forward, m);\r\n\r\n const direction = Vector3.Normalize(forwardWorld);\r\n\r\n return new Ray(origin, direction, length);\r\n }\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\nimport { Gamepad } from \"../Gamepads/gamepad\";\r\n/**\r\n * Defines supported buttons for XBox360 compatible gamepads\r\n */\r\nexport enum Xbox360Button {\r\n /** A */\r\n A = 0,\r\n /** B */\r\n B = 1,\r\n /** X */\r\n X = 2,\r\n /** Y */\r\n Y = 3,\r\n /** Left button */\r\n LB = 4,\r\n /** Right button */\r\n RB = 5,\r\n /** Back */\r\n Back = 8,\r\n /** Start */\r\n Start = 9,\r\n /** Left stick */\r\n LeftStick = 10,\r\n /** Right stick */\r\n RightStick = 11,\r\n}\r\n\r\n/** Defines values for XBox360 DPad */\r\nexport enum Xbox360Dpad {\r\n /** Up */\r\n Up = 12,\r\n /** Down */\r\n Down = 13,\r\n /** Left */\r\n Left = 14,\r\n /** Right */\r\n Right = 15,\r\n}\r\n\r\n/**\r\n * Defines a XBox360 gamepad\r\n */\r\nexport class Xbox360Pad extends Gamepad {\r\n private _leftTrigger: number = 0;\r\n private _rightTrigger: number = 0;\r\n\r\n private _onlefttriggerchanged: (value: number) => void;\r\n private _onrighttriggerchanged: (value: number) => void;\r\n\r\n private _onbuttondown: (buttonPressed: Xbox360Button) => void;\r\n private _onbuttonup: (buttonReleased: Xbox360Button) => void;\r\n private _ondpaddown: (dPadPressed: Xbox360Dpad) => void;\r\n private _ondpadup: (dPadReleased: Xbox360Dpad) => void;\r\n\r\n /** Observable raised when a button is pressed */\r\n public onButtonDownObservable = new Observable();\r\n /** Observable raised when a button is released */\r\n public onButtonUpObservable = new Observable();\r\n /** Observable raised when a pad is pressed */\r\n public onPadDownObservable = new Observable();\r\n /** Observable raised when a pad is released */\r\n public onPadUpObservable = new Observable();\r\n\r\n private _buttonA: number = 0;\r\n private _buttonB: number = 0;\r\n private _buttonX: number = 0;\r\n private _buttonY: number = 0;\r\n private _buttonBack: number = 0;\r\n private _buttonStart: number = 0;\r\n private _buttonLB: number = 0;\r\n private _buttonRB: number = 0;\r\n\r\n private _buttonLeftStick: number = 0;\r\n private _buttonRightStick: number = 0;\r\n private _dPadUp: number = 0;\r\n private _dPadDown: number = 0;\r\n private _dPadLeft: number = 0;\r\n private _dPadRight: number = 0;\r\n\r\n private _isXboxOnePad: boolean = false;\r\n\r\n /**\r\n * Creates a new XBox360 gamepad object\r\n * @param id defines the id of this gamepad\r\n * @param index defines its index\r\n * @param gamepad defines the internal HTML gamepad object\r\n * @param xboxOne defines if it is a XBox One gamepad\r\n */\r\n constructor(id: string, index: number, gamepad: any, xboxOne: boolean = false) {\r\n super(id, index, gamepad, 0, 1, 2, 3);\r\n this.type = Gamepad.XBOX;\r\n this._isXboxOnePad = xboxOne;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when left trigger is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public onlefttriggerchanged(callback: (value: number) => void) {\r\n this._onlefttriggerchanged = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when right trigger is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public onrighttriggerchanged(callback: (value: number) => void) {\r\n this._onrighttriggerchanged = callback;\r\n }\r\n\r\n /**\r\n * Gets the left trigger value\r\n */\r\n public get leftTrigger(): number {\r\n return this._leftTrigger;\r\n }\r\n /**\r\n * Sets the left trigger value\r\n */\r\n public set leftTrigger(newValue: number) {\r\n if (this._onlefttriggerchanged && this._leftTrigger !== newValue) {\r\n this._onlefttriggerchanged(newValue);\r\n }\r\n this._leftTrigger = newValue;\r\n }\r\n\r\n /**\r\n * Gets the right trigger value\r\n */\r\n public get rightTrigger(): number {\r\n return this._rightTrigger;\r\n }\r\n /**\r\n * Sets the right trigger value\r\n */\r\n public set rightTrigger(newValue: number) {\r\n if (this._onrighttriggerchanged && this._rightTrigger !== newValue) {\r\n this._onrighttriggerchanged(newValue);\r\n }\r\n this._rightTrigger = newValue;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a button is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public onbuttondown(callback: (buttonPressed: Xbox360Button) => void) {\r\n this._onbuttondown = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a button is released\r\n * @param callback defines the callback to use\r\n */\r\n public onbuttonup(callback: (buttonReleased: Xbox360Button) => void) {\r\n this._onbuttonup = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a pad is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public ondpaddown(callback: (dPadPressed: Xbox360Dpad) => void) {\r\n this._ondpaddown = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a pad is released\r\n * @param callback defines the callback to use\r\n */\r\n public ondpadup(callback: (dPadReleased: Xbox360Dpad) => void) {\r\n this._ondpadup = callback;\r\n }\r\n\r\n private _setButtonValue(newValue: number, currentValue: number, buttonType: Xbox360Button): number {\r\n if (newValue !== currentValue) {\r\n if (newValue === 1) {\r\n if (this._onbuttondown) {\r\n this._onbuttondown(buttonType);\r\n }\r\n\r\n this.onButtonDownObservable.notifyObservers(buttonType);\r\n }\r\n if (newValue === 0) {\r\n if (this._onbuttonup) {\r\n this._onbuttonup(buttonType);\r\n }\r\n\r\n this.onButtonUpObservable.notifyObservers(buttonType);\r\n }\r\n }\r\n return newValue;\r\n }\r\n\r\n private _setDPadValue(newValue: number, currentValue: number, buttonType: Xbox360Dpad): number {\r\n if (newValue !== currentValue) {\r\n if (newValue === 1) {\r\n if (this._ondpaddown) {\r\n this._ondpaddown(buttonType);\r\n }\r\n\r\n this.onPadDownObservable.notifyObservers(buttonType);\r\n }\r\n if (newValue === 0) {\r\n if (this._ondpadup) {\r\n this._ondpadup(buttonType);\r\n }\r\n\r\n this.onPadUpObservable.notifyObservers(buttonType);\r\n }\r\n }\r\n return newValue;\r\n }\r\n\r\n /**\r\n * Gets the value of the `A` button\r\n */\r\n public get buttonA(): number {\r\n return this._buttonA;\r\n }\r\n /**\r\n * Sets the value of the `A` button\r\n */\r\n public set buttonA(value) {\r\n this._buttonA = this._setButtonValue(value, this._buttonA, Xbox360Button.A);\r\n }\r\n\r\n /**\r\n * Gets the value of the `B` button\r\n */\r\n public get buttonB(): number {\r\n return this._buttonB;\r\n }\r\n /**\r\n * Sets the value of the `B` button\r\n */\r\n public set buttonB(value) {\r\n this._buttonB = this._setButtonValue(value, this._buttonB, Xbox360Button.B);\r\n }\r\n\r\n /**\r\n * Gets the value of the `X` button\r\n */\r\n public get buttonX(): number {\r\n return this._buttonX;\r\n }\r\n /**\r\n * Sets the value of the `X` button\r\n */\r\n public set buttonX(value) {\r\n this._buttonX = this._setButtonValue(value, this._buttonX, Xbox360Button.X);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Y` button\r\n */\r\n public get buttonY(): number {\r\n return this._buttonY;\r\n }\r\n /**\r\n * Sets the value of the `Y` button\r\n */\r\n public set buttonY(value) {\r\n this._buttonY = this._setButtonValue(value, this._buttonY, Xbox360Button.Y);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Start` button\r\n */\r\n public get buttonStart(): number {\r\n return this._buttonStart;\r\n }\r\n /**\r\n * Sets the value of the `Start` button\r\n */\r\n public set buttonStart(value) {\r\n this._buttonStart = this._setButtonValue(value, this._buttonStart, Xbox360Button.Start);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Back` button\r\n */\r\n public get buttonBack(): number {\r\n return this._buttonBack;\r\n }\r\n /**\r\n * Sets the value of the `Back` button\r\n */\r\n public set buttonBack(value) {\r\n this._buttonBack = this._setButtonValue(value, this._buttonBack, Xbox360Button.Back);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Left` button\r\n */\r\n public get buttonLB(): number {\r\n return this._buttonLB;\r\n }\r\n /**\r\n * Sets the value of the `Left` button\r\n */\r\n public set buttonLB(value) {\r\n this._buttonLB = this._setButtonValue(value, this._buttonLB, Xbox360Button.LB);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Right` button\r\n */\r\n public get buttonRB(): number {\r\n return this._buttonRB;\r\n }\r\n /**\r\n * Sets the value of the `Right` button\r\n */\r\n public set buttonRB(value) {\r\n this._buttonRB = this._setButtonValue(value, this._buttonRB, Xbox360Button.RB);\r\n }\r\n\r\n /**\r\n * Gets the value of the Left joystick\r\n */\r\n public get buttonLeftStick(): number {\r\n return this._buttonLeftStick;\r\n }\r\n /**\r\n * Sets the value of the Left joystick\r\n */\r\n public set buttonLeftStick(value) {\r\n this._buttonLeftStick = this._setButtonValue(value, this._buttonLeftStick, Xbox360Button.LeftStick);\r\n }\r\n\r\n /**\r\n * Gets the value of the Right joystick\r\n */\r\n public get buttonRightStick(): number {\r\n return this._buttonRightStick;\r\n }\r\n /**\r\n * Sets the value of the Right joystick\r\n */\r\n public set buttonRightStick(value) {\r\n this._buttonRightStick = this._setButtonValue(value, this._buttonRightStick, Xbox360Button.RightStick);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad up\r\n */\r\n public get dPadUp(): number {\r\n return this._dPadUp;\r\n }\r\n /**\r\n * Sets the value of D-pad up\r\n */\r\n public set dPadUp(value) {\r\n this._dPadUp = this._setDPadValue(value, this._dPadUp, Xbox360Dpad.Up);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad down\r\n */\r\n public get dPadDown(): number {\r\n return this._dPadDown;\r\n }\r\n /**\r\n * Sets the value of D-pad down\r\n */\r\n public set dPadDown(value) {\r\n this._dPadDown = this._setDPadValue(value, this._dPadDown, Xbox360Dpad.Down);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad left\r\n */\r\n public get dPadLeft(): number {\r\n return this._dPadLeft;\r\n }\r\n /**\r\n * Sets the value of D-pad left\r\n */\r\n public set dPadLeft(value) {\r\n this._dPadLeft = this._setDPadValue(value, this._dPadLeft, Xbox360Dpad.Left);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad right\r\n */\r\n public get dPadRight(): number {\r\n return this._dPadRight;\r\n }\r\n /**\r\n * Sets the value of D-pad right\r\n */\r\n public set dPadRight(value) {\r\n this._dPadRight = this._setDPadValue(value, this._dPadRight, Xbox360Dpad.Right);\r\n }\r\n\r\n /**\r\n * Force the gamepad to synchronize with device values\r\n */\r\n public update() {\r\n super.update();\r\n if (this._isXboxOnePad) {\r\n this.buttonA = this.browserGamepad.buttons[0].value;\r\n this.buttonB = this.browserGamepad.buttons[1].value;\r\n this.buttonX = this.browserGamepad.buttons[2].value;\r\n this.buttonY = this.browserGamepad.buttons[3].value;\r\n this.buttonLB = this.browserGamepad.buttons[4].value;\r\n this.buttonRB = this.browserGamepad.buttons[5].value;\r\n this.leftTrigger = this.browserGamepad.buttons[6].value;\r\n this.rightTrigger = this.browserGamepad.buttons[7].value;\r\n this.buttonBack = this.browserGamepad.buttons[8].value;\r\n this.buttonStart = this.browserGamepad.buttons[9].value;\r\n this.buttonLeftStick = this.browserGamepad.buttons[10].value;\r\n this.buttonRightStick = this.browserGamepad.buttons[11].value;\r\n this.dPadUp = this.browserGamepad.buttons[12].value;\r\n this.dPadDown = this.browserGamepad.buttons[13].value;\r\n this.dPadLeft = this.browserGamepad.buttons[14].value;\r\n this.dPadRight = this.browserGamepad.buttons[15].value;\r\n } else {\r\n this.buttonA = this.browserGamepad.buttons[0].value;\r\n this.buttonB = this.browserGamepad.buttons[1].value;\r\n this.buttonX = this.browserGamepad.buttons[2].value;\r\n this.buttonY = this.browserGamepad.buttons[3].value;\r\n this.buttonLB = this.browserGamepad.buttons[4].value;\r\n this.buttonRB = this.browserGamepad.buttons[5].value;\r\n this.leftTrigger = this.browserGamepad.buttons[6].value;\r\n this.rightTrigger = this.browserGamepad.buttons[7].value;\r\n this.buttonBack = this.browserGamepad.buttons[8].value;\r\n this.buttonStart = this.browserGamepad.buttons[9].value;\r\n this.buttonLeftStick = this.browserGamepad.buttons[10].value;\r\n this.buttonRightStick = this.browserGamepad.buttons[11].value;\r\n this.dPadUp = this.browserGamepad.buttons[12].value;\r\n this.dPadDown = this.browserGamepad.buttons[13].value;\r\n this.dPadLeft = this.browserGamepad.buttons[14].value;\r\n this.dPadRight = this.browserGamepad.buttons[15].value;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the gamepad\r\n */\r\n public dispose() {\r\n super.dispose();\r\n this.onButtonDownObservable.clear();\r\n this.onButtonUpObservable.clear();\r\n this.onPadDownObservable.clear();\r\n this.onPadUpObservable.clear();\r\n }\r\n}\r\n","import type { Camera } from \"../camera\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { Viewport } from \"../../Maths/math.viewport\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function setWebVRRigMode(camera: Camera, rigParams: any) {\r\n if (rigParams.vrDisplay) {\r\n const leftEye = rigParams.vrDisplay.getEyeParameters(\"left\");\r\n const rightEye = rigParams.vrDisplay.getEyeParameters(\"right\");\r\n\r\n //Left eye\r\n camera._rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\r\n camera._rigCameras[0].setCameraRigParameter(\"left\", true);\r\n //leaving this for future reference\r\n camera._rigCameras[0].setCameraRigParameter(\"specs\", rigParams.specs);\r\n camera._rigCameras[0].setCameraRigParameter(\"eyeParameters\", leftEye);\r\n camera._rigCameras[0].setCameraRigParameter(\"frameData\", rigParams.frameData);\r\n camera._rigCameras[0].setCameraRigParameter(\"parentCamera\", rigParams.parentCamera);\r\n camera._rigCameras[0]._cameraRigParams.vrWorkMatrix = new Matrix();\r\n camera._rigCameras[0].getProjectionMatrix = camera._getWebVRProjectionMatrix;\r\n camera._rigCameras[0].parent = camera;\r\n camera._rigCameras[0]._getViewMatrix = camera._getWebVRViewMatrix;\r\n\r\n //Right eye\r\n camera._rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\r\n camera._rigCameras[1].setCameraRigParameter(\"eyeParameters\", rightEye);\r\n camera._rigCameras[1].setCameraRigParameter(\"specs\", rigParams.specs);\r\n camera._rigCameras[1].setCameraRigParameter(\"frameData\", rigParams.frameData);\r\n camera._rigCameras[1].setCameraRigParameter(\"parentCamera\", rigParams.parentCamera);\r\n camera._rigCameras[1]._cameraRigParams.vrWorkMatrix = new Matrix();\r\n camera._rigCameras[1].getProjectionMatrix = camera._getWebVRProjectionMatrix;\r\n camera._rigCameras[1].parent = camera;\r\n camera._rigCameras[1]._getViewMatrix = camera._getWebVRViewMatrix;\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport type { IDisplayChangedEventArgs } from \"../../Engines/engine\";\r\nimport { Engine } from \"../../Engines/engine\";\r\nimport { Size } from \"../../Maths/math.size\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { IsWindowObjectExist } from \"../../Misc/domManagement\";\r\nimport type { WebVROptions } from \"../../Cameras/VR/webVRCamera\";\r\n\r\n/**\r\n * Interface used to define additional presentation attributes\r\n */\r\nexport interface IVRPresentationAttributes {\r\n /**\r\n * Defines a boolean indicating that we want to get 72hz mode on Oculus Browser (default is off eg. 60hz)\r\n */\r\n highRefreshRate: boolean;\r\n /**\r\n * Enables foveation in VR to improve perf. 0 none, 1 low, 2 medium, 3 high (Default is 1)\r\n */\r\n foveationLevel: number;\r\n}\r\n\r\ndeclare module \"../../Engines/engine\" {\r\n export interface Engine {\r\n /** @internal */\r\n _vrDisplay: any;\r\n /** @internal */\r\n _vrSupported: boolean;\r\n /** @internal */\r\n _oldSize: Size;\r\n /** @internal */\r\n _oldHardwareScaleFactor: number;\r\n /** @internal */\r\n _vrExclusivePointerMode: boolean;\r\n /** @internal */\r\n _webVRInitPromise: Promise;\r\n\r\n /** @internal */\r\n _onVRDisplayPointerRestricted: () => void;\r\n /** @internal */\r\n _onVRDisplayPointerUnrestricted: () => void;\r\n\r\n /** @internal */\r\n _onVrDisplayConnect: Nullable<(display: any) => void>;\r\n /** @internal */\r\n _onVrDisplayDisconnect: Nullable<() => void>;\r\n /** @internal */\r\n _onVrDisplayPresentChange: Nullable<() => void>;\r\n\r\n /**\r\n * Observable signaled when VR display mode changes\r\n */\r\n onVRDisplayChangedObservable: Observable;\r\n /**\r\n * Observable signaled when VR request present is complete\r\n */\r\n onVRRequestPresentComplete: Observable;\r\n /**\r\n * Observable signaled when VR request present starts\r\n */\r\n onVRRequestPresentStart: Observable;\r\n\r\n /**\r\n * Gets a boolean indicating that the engine is currently in VR exclusive mode for the pointers\r\n * @see https://docs.microsoft.com/en-us/microsoft-edge/webvr/essentials#mouse-input\r\n */\r\n isInVRExclusivePointerMode: boolean;\r\n\r\n /**\r\n * Gets a boolean indicating if a webVR device was detected\r\n * @returns true if a webVR device was detected\r\n */\r\n isVRDevicePresent(): boolean;\r\n\r\n /**\r\n * Gets the current webVR device\r\n * @returns the current webVR device (or null)\r\n */\r\n getVRDevice(): any;\r\n\r\n /**\r\n * Initializes a webVR display and starts listening to display change events\r\n * The onVRDisplayChangedObservable will be notified upon these changes\r\n * @returns A promise containing a VRDisplay and if vr is supported\r\n */\r\n initWebVRAsync(): Promise;\r\n\r\n /** @internal */\r\n _getVRDisplaysAsync(): Promise;\r\n\r\n /**\r\n * Gets or sets the presentation attributes used to configure VR rendering\r\n */\r\n vrPresentationAttributes?: IVRPresentationAttributes;\r\n\r\n /**\r\n * Call this function to switch to webVR mode\r\n * Will do nothing if webVR is not supported or if there is no webVR device\r\n * @param options the webvr options provided to the camera. mainly used for multiview\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRCamera\r\n */\r\n enableVR(options: WebVROptions): void;\r\n\r\n /** @internal */\r\n _onVRFullScreenTriggered(): void;\r\n }\r\n}\r\n\r\nObject.defineProperty(Engine.prototype, \"isInVRExclusivePointerMode\", {\r\n get: function (this: Engine) {\r\n return this._vrExclusivePointerMode;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\nEngine.prototype._prepareVRComponent = function () {\r\n this._vrSupported = false;\r\n this._vrExclusivePointerMode = false;\r\n this.onVRDisplayChangedObservable = new Observable();\r\n this.onVRRequestPresentComplete = new Observable();\r\n this.onVRRequestPresentStart = new Observable();\r\n};\r\n\r\nEngine.prototype.isVRDevicePresent = function () {\r\n return !!this._vrDisplay;\r\n};\r\n\r\nEngine.prototype.getVRDevice = function (): any {\r\n return this._vrDisplay;\r\n};\r\n\r\nEngine.prototype.initWebVR = function (): Observable {\r\n this.initWebVRAsync();\r\n return this.onVRDisplayChangedObservable;\r\n};\r\n\r\nEngine.prototype.initWebVRAsync = function (): Promise {\r\n const notifyObservers = () => {\r\n const eventArgs = {\r\n vrDisplay: this._vrDisplay,\r\n vrSupported: this._vrSupported,\r\n };\r\n this.onVRDisplayChangedObservable.notifyObservers(eventArgs);\r\n this._webVRInitPromise = new Promise((res) => {\r\n res(eventArgs);\r\n });\r\n };\r\n\r\n if (!this._onVrDisplayConnect) {\r\n this._onVrDisplayConnect = (event) => {\r\n this._vrDisplay = event.display;\r\n notifyObservers();\r\n };\r\n this._onVrDisplayDisconnect = () => {\r\n this._vrDisplay.cancelAnimationFrame(this._frameHandler);\r\n this._vrDisplay = undefined;\r\n this._frameHandler = Engine.QueueNewFrame(this._boundRenderFunction);\r\n notifyObservers();\r\n };\r\n this._onVrDisplayPresentChange = () => {\r\n this._vrExclusivePointerMode = this._vrDisplay && this._vrDisplay.isPresenting;\r\n };\r\n const hostWindow = this.getHostWindow();\r\n if (hostWindow) {\r\n hostWindow.addEventListener(\"vrdisplayconnect\", this._onVrDisplayConnect);\r\n hostWindow.addEventListener(\"vrdisplaydisconnect\", this._onVrDisplayDisconnect);\r\n hostWindow.addEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChange);\r\n }\r\n }\r\n this._webVRInitPromise = this._webVRInitPromise || this._getVRDisplaysAsync();\r\n this._webVRInitPromise.then(notifyObservers);\r\n return this._webVRInitPromise;\r\n};\r\n\r\nEngine.prototype._getVRDisplaysAsync = function (): Promise {\r\n return new Promise((res) => {\r\n if (navigator.getVRDisplays) {\r\n navigator.getVRDisplays().then((devices: Array) => {\r\n this._vrSupported = true;\r\n // note that devices may actually be an empty array. This is fine;\r\n // we expect this._vrDisplay to be undefined in this case.\r\n this._vrDisplay = devices[0];\r\n res({\r\n vrDisplay: this._vrDisplay,\r\n vrSupported: this._vrSupported,\r\n });\r\n });\r\n } else {\r\n this._vrDisplay = undefined;\r\n this._vrSupported = false;\r\n res({\r\n vrDisplay: this._vrDisplay,\r\n vrSupported: this._vrSupported,\r\n });\r\n }\r\n });\r\n};\r\n\r\nEngine.prototype.enableVR = function (options: WebVROptions) {\r\n if (this._vrDisplay && !this._vrDisplay.isPresenting) {\r\n const onResolved = () => {\r\n this.onVRRequestPresentComplete.notifyObservers(true);\r\n this._onVRFullScreenTriggered();\r\n };\r\n const onRejected = () => {\r\n this.onVRRequestPresentComplete.notifyObservers(false);\r\n };\r\n\r\n this.onVRRequestPresentStart.notifyObservers(this);\r\n\r\n const presentationAttributes = {\r\n highRefreshRate: this.vrPresentationAttributes ? this.vrPresentationAttributes.highRefreshRate : false,\r\n foveationLevel: this.vrPresentationAttributes ? this.vrPresentationAttributes.foveationLevel : 1,\r\n multiview: (this.getCaps().multiview || this.getCaps().oculusMultiview) && options.useMultiview,\r\n };\r\n\r\n this._vrDisplay\r\n .requestPresent([\r\n {\r\n source: this.getRenderingCanvas(),\r\n attributes: presentationAttributes,\r\n ...presentationAttributes,\r\n },\r\n ])\r\n .then(onResolved)\r\n .catch(onRejected);\r\n }\r\n};\r\n\r\nEngine.prototype._onVRFullScreenTriggered = function () {\r\n if (this._vrDisplay && this._vrDisplay.isPresenting) {\r\n //get the old size before we change\r\n this._oldSize = new Size(this.getRenderWidth(), this.getRenderHeight());\r\n this._oldHardwareScaleFactor = this.getHardwareScalingLevel();\r\n\r\n //get the width and height, change the render size\r\n const leftEye = this._vrDisplay.getEyeParameters(\"left\");\r\n this.setHardwareScalingLevel(1);\r\n this.setSize(leftEye.renderWidth * 2, leftEye.renderHeight);\r\n } else {\r\n this.setHardwareScalingLevel(this._oldHardwareScaleFactor);\r\n this.setSize(this._oldSize.width, this._oldSize.height);\r\n }\r\n};\r\n\r\nEngine.prototype.disableVR = function () {\r\n if (this._vrDisplay && this._vrDisplay.isPresenting) {\r\n this._vrDisplay\r\n .exitPresent()\r\n .then(() => this._onVRFullScreenTriggered())\r\n .catch(() => this._onVRFullScreenTriggered());\r\n }\r\n\r\n if (IsWindowObjectExist()) {\r\n window.removeEventListener(\"vrdisplaypointerrestricted\", this._onVRDisplayPointerRestricted);\r\n window.removeEventListener(\"vrdisplaypointerunrestricted\", this._onVRDisplayPointerUnrestricted);\r\n\r\n if (this._onVrDisplayConnect) {\r\n window.removeEventListener(\"vrdisplayconnect\", this._onVrDisplayConnect);\r\n if (this._onVrDisplayDisconnect) {\r\n window.removeEventListener(\"vrdisplaydisconnect\", this._onVrDisplayDisconnect);\r\n }\r\n\r\n if (this._onVrDisplayPresentChange) {\r\n window.removeEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChange);\r\n }\r\n this._onVrDisplayConnect = null;\r\n this._onVrDisplayDisconnect = null;\r\n }\r\n }\r\n};\r\n\r\nEngine.prototype._connectVREvents = function (canvas?: HTMLCanvasElement, document?: any) {\r\n this._onVRDisplayPointerRestricted = () => {\r\n if (canvas) {\r\n canvas.requestPointerLock();\r\n }\r\n };\r\n\r\n this._onVRDisplayPointerUnrestricted = () => {\r\n // Edge fix - for some reason document is not present and this is window\r\n if (!document) {\r\n const hostWindow = this.getHostWindow()!;\r\n if (hostWindow.document && hostWindow.document.exitPointerLock) {\r\n hostWindow.document.exitPointerLock();\r\n }\r\n return;\r\n }\r\n if (!document.exitPointerLock) {\r\n return;\r\n }\r\n document.exitPointerLock();\r\n };\r\n\r\n if (IsWindowObjectExist()) {\r\n const hostWindow = this.getHostWindow()!;\r\n hostWindow.addEventListener(\"vrdisplaypointerrestricted\", this._onVRDisplayPointerRestricted, false);\r\n hostWindow.addEventListener(\"vrdisplaypointerunrestricted\", this._onVRDisplayPointerUnrestricted, false);\r\n }\r\n};\r\n\r\nEngine.prototype._submitVRFrame = function () {\r\n // Submit frame to the vr device, if enabled\r\n if (this._vrDisplay && this._vrDisplay.isPresenting) {\r\n // TODO: We should only submit the frame if we read frameData successfully.\r\n try {\r\n this._vrDisplay.submitFrame();\r\n } catch (e) {\r\n Tools.Warn(\"webVR submitFrame has had an unexpected failure: \" + e);\r\n }\r\n }\r\n};\r\n\r\nEngine.prototype.isVRPresenting = function () {\r\n return this._vrDisplay && this._vrDisplay.isPresenting;\r\n};\r\n\r\nEngine.prototype._requestVRFrame = function () {\r\n this._frameHandler = Engine.QueueNewFrame(this._boundRenderFunction, this._vrDisplay);\r\n};\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport type { TargetCamera } from \"../../Cameras/targetCamera\";\r\nimport { Camera } from \"../../Cameras/camera\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Quaternion, Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Gamepad } from \"../../Gamepads/gamepad\";\r\nimport { PoseEnabledControllerType } from \"../../Gamepads/Controllers/poseEnabledController\";\r\nimport type { WebVRController } from \"../../Gamepads/Controllers/webVRController\";\r\nimport type { IDisplayChangedEventArgs } from \"../../Engines/engine\";\r\nimport { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Ray } from \"../../Culling/ray\";\r\nimport { HemisphericLight } from \"../../Lights/hemisphericLight\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { VRMultiviewToSingleviewPostProcess } from \"../../PostProcesses/vrMultiviewToSingleviewPostProcess\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { setWebVRRigMode } from \"../RigModes/webVRRigMode\";\r\n\r\n// Side effect import to add webvr support to engine\r\nimport \"../../Engines/Extensions/engine.webVR\";\r\n\r\nNode.AddNodeConstructor(\"WebVRFreeCamera\", (name, scene) => {\r\n return () => new WebVRFreeCamera(name, Vector3.Zero(), scene);\r\n});\r\n\r\nNode.AddNodeConstructor(\"WebVRGamepadCamera\", (name, scene) => {\r\n return () => new WebVRFreeCamera(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * This is a copy of VRPose. See https://developer.mozilla.org/en-US/docs/Web/API/VRPose\r\n * IMPORTANT!! The data is right-hand data.\r\n * @export\r\n * @interface DevicePose\r\n */\r\nexport interface DevicePose {\r\n /**\r\n * The position of the device, values in array are [x,y,z].\r\n */\r\n readonly position: Nullable;\r\n /**\r\n * The linearVelocity of the device, values in array are [x,y,z].\r\n */\r\n readonly linearVelocity: Nullable;\r\n /**\r\n * The linearAcceleration of the device, values in array are [x,y,z].\r\n */\r\n readonly linearAcceleration: Nullable;\r\n\r\n /**\r\n * The orientation of the device in a quaternion array, values in array are [x,y,z,w].\r\n */\r\n readonly orientation: Nullable;\r\n /**\r\n * The angularVelocity of the device, values in array are [x,y,z].\r\n */\r\n readonly angularVelocity: Nullable;\r\n /**\r\n * The angularAcceleration of the device, values in array are [x,y,z].\r\n */\r\n readonly angularAcceleration: Nullable;\r\n}\r\n\r\n/**\r\n * Interface representing a pose controlled object in Babylon.\r\n * A pose controlled object has both regular pose values as well as pose values\r\n * from an external device such as a VR head mounted display\r\n */\r\nexport interface PoseControlled {\r\n /**\r\n * The position of the object in babylon space.\r\n */\r\n position: Vector3;\r\n /**\r\n * The rotation quaternion of the object in babylon space.\r\n */\r\n rotationQuaternion: Quaternion;\r\n /**\r\n * The position of the device in babylon space.\r\n */\r\n devicePosition?: Vector3;\r\n /**\r\n * The rotation quaternion of the device in babylon space.\r\n */\r\n deviceRotationQuaternion: Quaternion;\r\n /**\r\n * The raw pose coming from the device.\r\n */\r\n rawPose: Nullable;\r\n /**\r\n * The scale of the device to be used when translating from device space to babylon space.\r\n */\r\n deviceScaleFactor: number;\r\n /**\r\n * Updates the poseControlled values based on the input device pose.\r\n * @param poseData the pose data to update the object with\r\n */\r\n updateFromDevice(poseData: DevicePose): void;\r\n}\r\n\r\n/**\r\n * Set of options to customize the webVRCamera\r\n */\r\nexport interface WebVROptions {\r\n /**\r\n * Sets if the webVR camera should be tracked to the vrDevice. (default: true)\r\n */\r\n trackPosition?: boolean;\r\n /**\r\n * Sets the scale of the vrDevice in babylon space. (default: 1)\r\n */\r\n positionScale?: number;\r\n /**\r\n * If there are more than one VRDisplays, this will choose the display matching this name. (default: pick first vrDisplay)\r\n */\r\n displayName?: string;\r\n /**\r\n * Should the native controller meshes be initialized. (default: true)\r\n */\r\n controllerMeshes?: boolean;\r\n /**\r\n * Creating a default HemiLight only on controllers. (default: true)\r\n */\r\n defaultLightingOnControllers?: boolean;\r\n /**\r\n * If you don't want to use the default VR button of the helper. (default: false)\r\n */\r\n useCustomVRButton?: boolean;\r\n\r\n /**\r\n * If you'd like to provide your own button to the VRHelper. (default: standard babylon vr button)\r\n */\r\n customVRButton?: HTMLButtonElement;\r\n\r\n /**\r\n * To change the length of the ray for gaze/controllers. Will be scaled by positionScale. (default: 100)\r\n */\r\n rayLength?: number;\r\n\r\n /**\r\n * To change the default offset from the ground to account for user's height in meters. Will be scaled by positionScale. (default: 1.7)\r\n */\r\n defaultHeight?: number;\r\n\r\n /**\r\n * If multiview should be used if available (default: false)\r\n */\r\n useMultiview?: boolean;\r\n}\r\n\r\n/**\r\n * This represents a WebVR camera.\r\n * The WebVR camera is Babylon's simple interface to interaction with Windows Mixed Reality, HTC Vive and Oculus Rift.\r\n * @deprecated Use WebXR instead - https://doc.babylonjs.com/features/featuresDeepDive/webXR\r\n * @example https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRCamera\r\n */\r\nexport class WebVRFreeCamera extends FreeCamera implements PoseControlled {\r\n /**\r\n * @internal\r\n * The vrDisplay tied to the camera. See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay\r\n */\r\n public _vrDevice: any = null;\r\n /**\r\n * The rawPose of the vrDevice.\r\n */\r\n public rawPose: Nullable = null;\r\n private _onVREnabled: (success: boolean) => void;\r\n private _specsVersion: string = \"1.1\";\r\n private _attached: boolean = false;\r\n\r\n private _frameData: any;\r\n\r\n protected _descendants: Array = [];\r\n\r\n // Represents device position and rotation in room space. Should only be used to help calculate babylon space values\r\n private _deviceRoomPosition = Vector3.Zero();\r\n /** @internal */\r\n public _deviceRoomRotationQuaternion = Quaternion.Identity();\r\n\r\n private _standingMatrix: Nullable = null;\r\n\r\n /**\r\n * Represents device position in babylon space.\r\n */\r\n public devicePosition = Vector3.Zero();\r\n /**\r\n * Represents device rotation in babylon space.\r\n */\r\n public deviceRotationQuaternion = Quaternion.Identity();\r\n\r\n /**\r\n * The scale of the device to be used when translating from device space to babylon space.\r\n */\r\n public deviceScaleFactor: number = 1;\r\n\r\n private _deviceToWorld = Matrix.Identity();\r\n private _worldToDevice = Matrix.Identity();\r\n\r\n /**\r\n * References to the webVR controllers for the vrDevice.\r\n */\r\n public controllers: Array = [];\r\n /**\r\n * Emits an event when a controller is attached.\r\n */\r\n public onControllersAttachedObservable = new Observable>();\r\n /**\r\n * Emits an event when a controller's mesh has been loaded;\r\n */\r\n public onControllerMeshLoadedObservable = new Observable();\r\n /**\r\n * Emits an event when the HMD's pose has been updated.\r\n */\r\n public onPoseUpdatedFromDeviceObservable = new Observable();\r\n private _poseSet = false;\r\n /**\r\n * If the rig cameras be used as parent instead of this camera.\r\n */\r\n public rigParenting: boolean = true;\r\n\r\n private _lightOnControllers: HemisphericLight;\r\n\r\n private _defaultHeight?: number = undefined;\r\n\r\n /**\r\n * Instantiates a WebVRFreeCamera.\r\n * @param name The name of the WebVRFreeCamera\r\n * @param position The starting anchor position for the camera\r\n * @param scene The scene the camera belongs to\r\n * @param _webVROptions a set of customizable options for the webVRCamera\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene, private _webVROptions: WebVROptions = {}) {\r\n super(name, position, scene);\r\n this._cache.position = Vector3.Zero();\r\n if (_webVROptions.defaultHeight) {\r\n this._defaultHeight = _webVROptions.defaultHeight;\r\n this.position.y = this._defaultHeight;\r\n }\r\n\r\n this.minZ = 0.1;\r\n\r\n //legacy support - the compensation boolean was removed.\r\n if (arguments.length === 5) {\r\n // eslint-disable-next-line prefer-rest-params\r\n this._webVROptions = arguments[4];\r\n }\r\n\r\n // default webVR options\r\n if (this._webVROptions.trackPosition == undefined) {\r\n this._webVROptions.trackPosition = true;\r\n }\r\n if (this._webVROptions.controllerMeshes == undefined) {\r\n this._webVROptions.controllerMeshes = true;\r\n }\r\n if (this._webVROptions.defaultLightingOnControllers == undefined) {\r\n this._webVROptions.defaultLightingOnControllers = true;\r\n }\r\n\r\n this.rotationQuaternion = new Quaternion();\r\n\r\n if (this._webVROptions && this._webVROptions.positionScale) {\r\n this.deviceScaleFactor = this._webVROptions.positionScale;\r\n }\r\n\r\n //enable VR\r\n const engine = this.getEngine();\r\n this._onVREnabled = (success: boolean) => {\r\n if (success) {\r\n this.initControllers();\r\n }\r\n };\r\n engine.onVRRequestPresentComplete.add(this._onVREnabled);\r\n engine.initWebVR().add((event: IDisplayChangedEventArgs) => {\r\n if (!event.vrDisplay || this._vrDevice === event.vrDisplay) {\r\n return;\r\n }\r\n\r\n this._vrDevice = event.vrDisplay;\r\n\r\n //reset the rig parameters.\r\n this.setCameraRigMode(Camera.RIG_MODE_WEBVR, { parentCamera: this, vrDisplay: this._vrDevice, frameData: this._frameData, specs: this._specsVersion });\r\n\r\n if (this._attached) {\r\n this.getEngine().enableVR(this._webVROptions);\r\n }\r\n });\r\n\r\n if (typeof VRFrameData !== \"undefined\") {\r\n this._frameData = new VRFrameData();\r\n }\r\n\r\n if (_webVROptions.useMultiview) {\r\n if (!this.getScene().getEngine().getCaps().multiview) {\r\n Logger.Warn(\"Multiview is not supported, falling back to standard rendering\");\r\n this._useMultiviewToSingleView = false;\r\n } else {\r\n this._useMultiviewToSingleView = true;\r\n this._rigPostProcess = new VRMultiviewToSingleviewPostProcess(\"VRMultiviewToSingleview\", this, 1.0);\r\n }\r\n }\r\n\r\n /**\r\n * The idea behind the following lines:\r\n * objects that have the camera as parent should actually have the rig cameras as a parent.\r\n * BUT, each of those cameras has a different view matrix, which means that if we set the parent to the first rig camera,\r\n * the second will not show it correctly.\r\n *\r\n * To solve this - each object that has the camera as parent will be added to a protected array.\r\n * When the rig camera renders, it will take this array and set all of those to be its children.\r\n * This way, the right camera will be used as a parent, and the mesh will be rendered correctly.\r\n * Amazing!\r\n */\r\n this.getScene().onBeforeCameraRenderObservable.add((camera) => {\r\n if (camera.parent === this && this.rigParenting) {\r\n this._descendants = this.getDescendants(true, (n) => {\r\n // don't take the cameras or the controllers!\r\n const isController = this.controllers.some((controller) => {\r\n return controller._mesh === n;\r\n });\r\n const isRigCamera = this._rigCameras.indexOf(n) !== -1;\r\n return !isController && !isRigCamera;\r\n });\r\n this._descendants.forEach((node) => {\r\n node.parent = camera;\r\n });\r\n }\r\n });\r\n\r\n this.getScene().onAfterCameraRenderObservable.add((camera) => {\r\n if (camera.parent === this && this.rigParenting) {\r\n this._descendants.forEach((node) => {\r\n node.parent = this;\r\n });\r\n }\r\n });\r\n }\r\n\r\n protected _setRigMode = setWebVRRigMode.bind(null, this);\r\n\r\n /**\r\n * Gets the device distance from the ground in meters.\r\n * @returns the distance in meters from the vrDevice to ground in device space. If standing matrix is not supported for the vrDevice 0 is returned.\r\n */\r\n public deviceDistanceToRoomGround(): number {\r\n if (this._standingMatrix) {\r\n // Add standing matrix offset to get real offset from ground in room\r\n this._standingMatrix.getTranslationToRef(this._workingVector);\r\n return this._deviceRoomPosition.y + this._workingVector.y;\r\n }\r\n //If VRDisplay does not inform stage parameters and no default height is set we fallback to zero.\r\n return this._defaultHeight || 0;\r\n }\r\n\r\n /**\r\n * Enables the standing matrix when supported. This can be used to position the user's view the correct height from the ground.\r\n * @param callback will be called when the standing matrix is set. Callback parameter is if the standing matrix is supported.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public useStandingMatrix(callback = (bool: boolean) => {}) {\r\n // Use standing matrix if available\r\n this.getEngine()\r\n .initWebVRAsync()\r\n .then((result) => {\r\n if (!result.vrDisplay || !result.vrDisplay.stageParameters || !result.vrDisplay.stageParameters.sittingToStandingTransform || !this._webVROptions.trackPosition) {\r\n callback(false);\r\n } else {\r\n this._standingMatrix = new Matrix();\r\n Matrix.FromFloat32ArrayToRefScaled(result.vrDisplay.stageParameters.sittingToStandingTransform, 0, 1, this._standingMatrix);\r\n if (!this.getScene().useRightHandedSystem) {\r\n if (this._standingMatrix) {\r\n this._standingMatrix.toggleModelMatrixHandInPlace();\r\n }\r\n }\r\n callback(true);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Enables the standing matrix when supported. This can be used to position the user's view the correct height from the ground.\r\n * @returns A promise with a boolean set to if the standing matrix is supported.\r\n */\r\n public useStandingMatrixAsync(): Promise {\r\n return new Promise((res) => {\r\n this.useStandingMatrix((supported) => {\r\n res(supported);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Disposes the camera\r\n */\r\n public dispose(): void {\r\n this._detachIfAttached();\r\n this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);\r\n if (this._updateCacheWhenTrackingDisabledObserver) {\r\n this._scene.onBeforeRenderObservable.remove(this._updateCacheWhenTrackingDisabledObserver);\r\n }\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Gets a vrController by name.\r\n * @param name The name of the controller to retrieve\r\n * @returns the controller matching the name specified or null if not found\r\n */\r\n public getControllerByName(name: string): Nullable {\r\n for (const gp of this.controllers) {\r\n if (gp.hand === name) {\r\n return gp;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _leftController: Nullable;\r\n /**\r\n * The controller corresponding to the users left hand.\r\n */\r\n public get leftController(): Nullable {\r\n if (!this._leftController) {\r\n this._leftController = this.getControllerByName(\"left\");\r\n }\r\n\r\n return this._leftController;\r\n }\r\n\r\n private _rightController: Nullable;\r\n /**\r\n * The controller corresponding to the users right hand.\r\n */\r\n public get rightController(): Nullable {\r\n if (!this._rightController) {\r\n this._rightController = this.getControllerByName(\"right\");\r\n }\r\n\r\n return this._rightController;\r\n }\r\n\r\n /**\r\n * Casts a ray forward from the vrCamera's gaze.\r\n * @param length Length of the ray (default: 100)\r\n * @returns the ray corresponding to the gaze\r\n */\r\n public getForwardRay(length = 100): Ray {\r\n if (this.leftCamera) {\r\n // Use left eye to avoid computation to compute center on every call\r\n return super.getForwardRay(length, this.leftCamera.getWorldMatrix(), this.leftCamera.globalPosition); // Need the actual rendered camera\r\n } else {\r\n return super.getForwardRay(length);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Updates the camera based on device's frame data\r\n */\r\n public _checkInputs(): void {\r\n if (this._vrDevice && this._vrDevice.isPresenting) {\r\n this._vrDevice.getFrameData(this._frameData);\r\n\r\n this.updateFromDevice(this._frameData.pose);\r\n }\r\n\r\n super._checkInputs();\r\n }\r\n\r\n /**\r\n * Updates the poseControlled values based on the input device pose.\r\n * @param poseData Pose coming from the device\r\n */\r\n updateFromDevice(poseData: DevicePose) {\r\n if (poseData && poseData.orientation && poseData.orientation.length === 4) {\r\n this.rawPose = poseData;\r\n this._deviceRoomRotationQuaternion.copyFromFloats(poseData.orientation[0], poseData.orientation[1], -poseData.orientation[2], -poseData.orientation[3]);\r\n\r\n if (this.getScene().useRightHandedSystem) {\r\n this._deviceRoomRotationQuaternion.z *= -1;\r\n this._deviceRoomRotationQuaternion.w *= -1;\r\n }\r\n if (this._webVROptions.trackPosition && this.rawPose.position) {\r\n this._deviceRoomPosition.copyFromFloats(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2]);\r\n if (this.getScene().useRightHandedSystem) {\r\n this._deviceRoomPosition.z *= -1;\r\n }\r\n }\r\n this._poseSet = true;\r\n }\r\n }\r\n\r\n private _detachIfAttached = () => {\r\n const vrDisplay = this.getEngine().getVRDevice();\r\n if (vrDisplay && !vrDisplay.isPresenting) {\r\n this.detachControl();\r\n }\r\n };\r\n\r\n /**\r\n * WebVR's attach control will start broadcasting frames to the device.\r\n * Note that in certain browsers (chrome for example) this function must be called\r\n * within a user-interaction callback. Example:\r\n *
 scene.onPointerDown = function() { camera.attachControl(canvas); }
\r\n *\r\n * @param noPreventDefault prevent the default html element operation when attaching the vrDevice\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n super.attachControl(noPreventDefault);\r\n this._attached = true;\r\n\r\n noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;\r\n\r\n if (this._vrDevice) {\r\n this.getEngine().enableVR(this._webVROptions);\r\n }\r\n\r\n const hostWindow = this._scene.getEngine().getHostWindow();\r\n\r\n if (hostWindow) {\r\n hostWindow.addEventListener(\"vrdisplaypresentchange\", this._detachIfAttached);\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);\r\n this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);\r\n\r\n super.detachControl();\r\n this._attached = false;\r\n this.getEngine().disableVR();\r\n window.removeEventListener(\"vrdisplaypresentchange\", this._detachIfAttached);\r\n }\r\n\r\n /**\r\n * @returns the name of this class\r\n */\r\n public getClassName(): string {\r\n return \"WebVRFreeCamera\";\r\n }\r\n\r\n /**\r\n * Calls resetPose on the vrDisplay\r\n * See: https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/resetPose\r\n */\r\n public resetToCurrentRotation() {\r\n //uses the vrDisplay's \"resetPose()\".\r\n //pitch and roll won't be affected.\r\n this._vrDevice.resetPose();\r\n }\r\n\r\n /**\r\n * @internal\r\n * Updates the rig cameras (left and right eye)\r\n */\r\n public _updateRigCameras() {\r\n const camLeft = this._rigCameras[0];\r\n const camRight = this._rigCameras[1];\r\n camLeft.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion);\r\n camRight.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion);\r\n\r\n camLeft.position.copyFrom(this._deviceRoomPosition);\r\n camRight.position.copyFrom(this._deviceRoomPosition);\r\n }\r\n\r\n private _workingVector = Vector3.Zero();\r\n private _oneVector = Vector3.One();\r\n private _workingMatrix = Matrix.Identity();\r\n\r\n private _updateCacheCalled: boolean;\r\n\r\n // Remove translation from 6dof headset if trackposition is set to false\r\n private _correctPositionIfNotTrackPosition(matrix: Matrix, isViewMatrix = false) {\r\n if (this.rawPose && this.rawPose.position && !this._webVROptions.trackPosition) {\r\n Matrix.TranslationToRef(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2], this._tmpMatrix);\r\n if (!isViewMatrix) {\r\n this._tmpMatrix.invert();\r\n }\r\n this._tmpMatrix.multiplyToRef(matrix, matrix);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Updates the cached values of the camera\r\n * @param ignoreParentClass ignores updating the parent class's cache (default: false)\r\n */\r\n public _updateCache(ignoreParentClass?: boolean): void {\r\n if (!this.rotationQuaternion.equals(this._cache.rotationQuaternion) || !this.position.equals(this._cache.position)) {\r\n // Update to ensure devicePosition is up to date with most recent _deviceRoomPosition\r\n if (!this._updateCacheCalled) {\r\n // make sure it is only called once per loop. this.update() might cause an infinite loop.\r\n this._updateCacheCalled = true;\r\n this.update();\r\n }\r\n\r\n // Set working vector to the device position in room space rotated by the new rotation\r\n this.rotationQuaternion.toRotationMatrix(this._workingMatrix);\r\n Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._workingMatrix, this._workingVector);\r\n\r\n // Subtract this vector from the current device position in world to get the translation for the device world matrix\r\n this.devicePosition.subtractToRef(this._workingVector, this._workingVector);\r\n Matrix.ComposeToRef(this._oneVector, this.rotationQuaternion, this._workingVector, this._deviceToWorld);\r\n\r\n // Add translation from anchor position\r\n this._deviceToWorld.getTranslationToRef(this._workingVector);\r\n this._workingVector.addInPlace(this.position);\r\n this._workingVector.subtractInPlace(this._cache.position);\r\n this._deviceToWorld.setTranslation(this._workingVector);\r\n\r\n // Set an inverted matrix to be used when updating the camera\r\n this._deviceToWorld.invertToRef(this._worldToDevice);\r\n\r\n // Update the gamepad to ensure the mesh is updated on the same frame as camera\r\n this.controllers.forEach((controller) => {\r\n controller._deviceToWorld.copyFrom(this._deviceToWorld);\r\n this._correctPositionIfNotTrackPosition(controller._deviceToWorld);\r\n controller.update();\r\n });\r\n }\r\n\r\n if (!ignoreParentClass) {\r\n super._updateCache();\r\n }\r\n this._updateCacheCalled = false;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Get current device position in babylon world\r\n */\r\n public _computeDevicePosition() {\r\n Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._deviceToWorld, this.devicePosition);\r\n }\r\n\r\n /**\r\n * Updates the current device position and rotation in the babylon world\r\n */\r\n public update() {\r\n this._computeDevicePosition();\r\n\r\n // Get current device rotation in babylon world\r\n Matrix.FromQuaternionToRef(this._deviceRoomRotationQuaternion, this._workingMatrix);\r\n this._workingMatrix.multiplyToRef(this._deviceToWorld, this._workingMatrix);\r\n Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);\r\n\r\n if (this._poseSet) {\r\n this.onPoseUpdatedFromDeviceObservable.notifyObservers(null);\r\n }\r\n super.update();\r\n }\r\n\r\n /**\r\n * @internal\r\n * Gets the view matrix of this camera (Always set to identity as left and right eye cameras contain the actual view matrix)\r\n * @returns an identity matrix\r\n */\r\n public _getViewMatrix(): Matrix {\r\n return Matrix.Identity();\r\n }\r\n\r\n private _tmpMatrix = new Matrix();\r\n /**\r\n * This function is called by the two RIG cameras.\r\n * 'this' is the left or right camera (and NOT (!!!) the WebVRFreeCamera instance)\r\n * @internal\r\n */\r\n public _getWebVRViewMatrix(): Matrix {\r\n // Update the parent camera prior to using a child camera to avoid desynchronization\r\n const parentCamera: WebVRFreeCamera = this._cameraRigParams[\"parentCamera\"];\r\n parentCamera._updateCache();\r\n\r\n //WebVR 1.1\r\n const viewArray = this._cameraRigParams[\"left\"] ? this._cameraRigParams[\"frameData\"].leftViewMatrix : this._cameraRigParams[\"frameData\"].rightViewMatrix;\r\n\r\n Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);\r\n\r\n if (!this.getScene().useRightHandedSystem) {\r\n this._webvrViewMatrix.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n // update the camera rotation matrix\r\n this._webvrViewMatrix.getRotationMatrixToRef(this._cameraRotationMatrix);\r\n Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);\r\n\r\n // Computing target and final matrix\r\n this.position.addToRef(this._transformedReferencePoint, this._currentTarget);\r\n\r\n // should the view matrix be updated with scale and position offset?\r\n if (parentCamera.deviceScaleFactor !== 1) {\r\n this._webvrViewMatrix.invert();\r\n // scale the position, if set\r\n if (parentCamera.deviceScaleFactor) {\r\n this._webvrViewMatrix.multiplyAtIndex(12, parentCamera.deviceScaleFactor);\r\n this._webvrViewMatrix.multiplyAtIndex(13, parentCamera.deviceScaleFactor);\r\n this._webvrViewMatrix.multiplyAtIndex(14, parentCamera.deviceScaleFactor);\r\n }\r\n\r\n this._webvrViewMatrix.invert();\r\n }\r\n\r\n // Remove translation from 6dof headset if trackposition is set to false\r\n parentCamera._correctPositionIfNotTrackPosition(this._webvrViewMatrix, true);\r\n\r\n parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);\r\n\r\n // Compute global position\r\n this._workingMatrix = this._workingMatrix || Matrix.Identity();\r\n this._webvrViewMatrix.invertToRef(this._workingMatrix);\r\n this._workingMatrix.multiplyToRef(parentCamera.getWorldMatrix(), this._workingMatrix);\r\n this._workingMatrix.getTranslationToRef(this._globalPosition);\r\n this._markSyncedWithParent();\r\n\r\n return this._webvrViewMatrix;\r\n }\r\n\r\n /** @internal */\r\n public _getWebVRProjectionMatrix(): Matrix {\r\n const parentCamera = this.parent;\r\n\r\n parentCamera._vrDevice.depthNear = parentCamera.minZ;\r\n parentCamera._vrDevice.depthFar = parentCamera.maxZ;\r\n\r\n const projectionArray = this._cameraRigParams[\"left\"] ? this._cameraRigParams[\"frameData\"].leftProjectionMatrix : this._cameraRigParams[\"frameData\"].rightProjectionMatrix;\r\n Matrix.FromArrayToRef(projectionArray, 0, this._projectionMatrix);\r\n\r\n //babylon compatible matrix\r\n if (!this.getScene().useRightHandedSystem) {\r\n this._projectionMatrix.toggleProjectionMatrixHandInPlace();\r\n }\r\n\r\n return this._projectionMatrix;\r\n }\r\n\r\n private _onGamepadConnectedObserver: Nullable>;\r\n private _onGamepadDisconnectedObserver: Nullable>;\r\n private _updateCacheWhenTrackingDisabledObserver: Nullable>;\r\n /**\r\n * Initializes the controllers and their meshes\r\n */\r\n public initControllers() {\r\n this.controllers.length = 0;\r\n\r\n const manager = this.getScene().gamepadManager;\r\n this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add((gamepad) => {\r\n if (gamepad.type === Gamepad.POSE_ENABLED) {\r\n const webVrController: WebVRController = gamepad;\r\n\r\n if (webVrController.defaultModel) {\r\n webVrController.defaultModel.setEnabled(false);\r\n }\r\n\r\n if (webVrController.hand === \"right\") {\r\n this._rightController = null;\r\n }\r\n if (webVrController.hand === \"left\") {\r\n this._leftController = null;\r\n }\r\n const controllerIndex = this.controllers.indexOf(webVrController);\r\n if (controllerIndex !== -1) {\r\n this.controllers.splice(controllerIndex, 1);\r\n }\r\n }\r\n });\r\n\r\n this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {\r\n if (gamepad.type === Gamepad.POSE_ENABLED) {\r\n const webVrController: WebVRController = gamepad;\r\n if (!this._webVROptions.trackPosition) {\r\n webVrController._disableTrackPosition(new Vector3(webVrController.hand == \"left\" ? -0.15 : 0.15, -0.5, 0.25));\r\n // Cache must be updated before rendering controllers to avoid them being one frame behind\r\n if (!this._updateCacheWhenTrackingDisabledObserver) {\r\n this._updateCacheWhenTrackingDisabledObserver = this._scene.onBeforeRenderObservable.add(() => {\r\n this._updateCache();\r\n });\r\n }\r\n }\r\n webVrController.deviceScaleFactor = this.deviceScaleFactor;\r\n webVrController._deviceToWorld.copyFrom(this._deviceToWorld);\r\n this._correctPositionIfNotTrackPosition(webVrController._deviceToWorld);\r\n\r\n if (this._webVROptions.controllerMeshes) {\r\n if (webVrController.defaultModel) {\r\n webVrController.defaultModel.setEnabled(true);\r\n } else {\r\n // Load the meshes\r\n webVrController.initControllerMesh(this.getScene(), (loadedMesh) => {\r\n loadedMesh.scaling.scaleInPlace(this.deviceScaleFactor);\r\n this.onControllerMeshLoadedObservable.notifyObservers(webVrController);\r\n if (this._webVROptions.defaultLightingOnControllers) {\r\n if (!this._lightOnControllers) {\r\n this._lightOnControllers = new HemisphericLight(\"vrControllersLight\", new Vector3(0, 1, 0), this.getScene());\r\n }\r\n const activateLightOnSubMeshes = function (mesh: AbstractMesh, light: HemisphericLight) {\r\n const children = mesh.getChildren();\r\n if (children && children.length !== 0) {\r\n children.forEach((mesh) => {\r\n light.includedOnlyMeshes.push(mesh);\r\n activateLightOnSubMeshes(mesh, light);\r\n });\r\n }\r\n };\r\n this._lightOnControllers.includedOnlyMeshes.push(loadedMesh);\r\n activateLightOnSubMeshes(loadedMesh, this._lightOnControllers);\r\n }\r\n });\r\n }\r\n }\r\n webVrController.attachToPoseControlledCamera(this);\r\n\r\n // since this is async - sanity check. Is the controller already stored?\r\n if (this.controllers.indexOf(webVrController) === -1) {\r\n //add to the controllers array\r\n this.controllers.push(webVrController);\r\n\r\n // Forced to add some control code for Vive as it doesn't always fill properly the \"hand\" property\r\n // Sometimes, both controllers are set correctly (left and right), sometimes none, sometimes only one of them...\r\n // So we're overriding setting left & right manually to be sure\r\n let firstViveWandDetected = false;\r\n\r\n for (let i = 0; i < this.controllers.length; i++) {\r\n if (this.controllers[i].controllerType === PoseEnabledControllerType.VIVE) {\r\n if (!firstViveWandDetected) {\r\n firstViveWandDetected = true;\r\n this.controllers[i].hand = \"left\";\r\n } else {\r\n this.controllers[i].hand = \"right\";\r\n }\r\n }\r\n }\r\n\r\n //did we find enough controllers? Great! let the developer know.\r\n if (this.controllers.length >= 2) {\r\n this.onControllersAttachedObservable.notifyObservers(this.controllers);\r\n }\r\n }\r\n }\r\n });\r\n }\r\n}\r\n","import { Observable } from \"../../Misc/observable\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { ExtendedGamepadButton, MutableGamepadButton } from \"./poseEnabledController\";\r\nimport { PoseEnabledController } from \"./poseEnabledController\";\r\nimport type { StickValues, GamepadButtonChanges } from \"../../Gamepads/gamepad\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Defines the WebVRController object that represents controllers tracked in 3D space\r\n * @deprecated Use WebXR instead\r\n */\r\nexport abstract class WebVRController extends PoseEnabledController {\r\n /**\r\n * Internal, the default controller model for the controller\r\n */\r\n protected _defaultModel: Nullable;\r\n\r\n // Observables\r\n /**\r\n * Fired when the trigger state has changed\r\n */\r\n public onTriggerStateChangedObservable = new Observable();\r\n /**\r\n * Fired when the main button state has changed\r\n */\r\n public onMainButtonStateChangedObservable = new Observable();\r\n /**\r\n * Fired when the secondary button state has changed\r\n */\r\n public onSecondaryButtonStateChangedObservable = new Observable();\r\n /**\r\n * Fired when the pad state has changed\r\n */\r\n public onPadStateChangedObservable = new Observable();\r\n /**\r\n * Fired when controllers stick values have changed\r\n */\r\n public onPadValuesChangedObservable = new Observable();\r\n\r\n /**\r\n * Array of button available on the controller\r\n */\r\n protected _buttons: Array;\r\n\r\n private _onButtonStateChange: (controlledIndex: number, buttonIndex: number, state: ExtendedGamepadButton) => void;\r\n\r\n /**\r\n * Fired when a controller button's state has changed\r\n * @param callback the callback containing the button that was modified\r\n */\r\n public onButtonStateChange(callback: (controlledIndex: number, buttonIndex: number, state: ExtendedGamepadButton) => void) {\r\n this._onButtonStateChange = callback;\r\n }\r\n\r\n /**\r\n * X and Y axis corresponding to the controllers joystick\r\n */\r\n public pad: StickValues = { x: 0, y: 0 };\r\n\r\n /**\r\n * 'left' or 'right', see https://w3c.github.io/gamepad/extensions.html#gamepadhand-enum\r\n */\r\n public hand: string;\r\n\r\n /**\r\n * The default controller model for the controller\r\n */\r\n public get defaultModel(): Nullable {\r\n return this._defaultModel;\r\n }\r\n\r\n /**\r\n * Creates a new WebVRController from a gamepad\r\n * @param vrGamepad the gamepad that the WebVRController should be created from\r\n */\r\n constructor(vrGamepad: any) {\r\n super(vrGamepad);\r\n this._buttons = new Array(vrGamepad.buttons.length);\r\n this.hand = vrGamepad.hand;\r\n }\r\n\r\n /**\r\n * Updates the state of the controller and mesh based on the current position and rotation of the controller\r\n */\r\n public update() {\r\n super.update();\r\n for (let index = 0; index < this._buttons.length; index++) {\r\n this._setButtonValue(this.browserGamepad.buttons[index], this._buttons[index], index);\r\n }\r\n if (this.leftStick.x !== this.pad.x || this.leftStick.y !== this.pad.y) {\r\n this.pad.x = this.leftStick.x;\r\n this.pad.y = this.leftStick.y;\r\n this.onPadValuesChangedObservable.notifyObservers(this.pad);\r\n }\r\n }\r\n\r\n /**\r\n * Function to be called when a button is modified\r\n */\r\n protected abstract _handleButtonChange(buttonIdx: number, value: ExtendedGamepadButton, changes: GamepadButtonChanges): void;\r\n\r\n /**\r\n * Loads a mesh and attaches it to the controller\r\n * @param scene the scene the mesh should be added to\r\n * @param meshLoaded callback for when the mesh has been loaded\r\n */\r\n public abstract initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void): void;\r\n\r\n private _setButtonValue(newState: ExtendedGamepadButton, currentState: ExtendedGamepadButton, buttonIndex: number) {\r\n if (!newState) {\r\n newState = {\r\n pressed: false,\r\n touched: false,\r\n value: 0,\r\n };\r\n }\r\n if (!currentState) {\r\n this._buttons[buttonIndex] = {\r\n pressed: newState.pressed,\r\n touched: newState.touched,\r\n value: newState.value,\r\n };\r\n return;\r\n }\r\n this._checkChanges(newState, currentState);\r\n if (this._changes.changed) {\r\n this._onButtonStateChange && this._onButtonStateChange(this.index, buttonIndex, newState);\r\n\r\n this._handleButtonChange(buttonIndex, newState, this._changes);\r\n }\r\n this._buttons[buttonIndex].pressed = newState.pressed;\r\n this._buttons[buttonIndex].touched = newState.touched;\r\n // oculus triggers are never 0, thou not touched.\r\n this._buttons[buttonIndex].value = newState.value < 0.00000001 ? 0 : newState.value;\r\n }\r\n\r\n // avoid GC, store state in a tmp object\r\n private _changes: GamepadButtonChanges = {\r\n pressChanged: false,\r\n touchChanged: false,\r\n valueChanged: false,\r\n changed: false,\r\n };\r\n\r\n private _checkChanges(newState: ExtendedGamepadButton, currentState: ExtendedGamepadButton) {\r\n this._changes.pressChanged = newState.pressed !== currentState.pressed;\r\n this._changes.touchChanged = newState.touched !== currentState.touched;\r\n this._changes.valueChanged = newState.value !== currentState.value;\r\n this._changes.changed = this._changes.pressChanged || this._changes.touchChanged || this._changes.valueChanged;\r\n return this._changes;\r\n }\r\n\r\n /**\r\n * Disposes of th webVRController\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n\r\n this._defaultModel = null;\r\n\r\n this.onTriggerStateChangedObservable.clear();\r\n this.onMainButtonStateChangedObservable.clear();\r\n this.onSecondaryButtonStateChangedObservable.clear();\r\n this.onPadStateChangedObservable.clear();\r\n this.onPadValuesChangedObservable.clear();\r\n }\r\n}\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICanvas } from \"../ICanvas\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a dynamic texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param generateMipMaps defines if the engine should generate the mip levels\r\n * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)\r\n * @returns the dynamic texture inside an InternalTexture\r\n */\r\n createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): InternalTexture;\r\n\r\n /**\r\n * Update the content of a dynamic texture\r\n * @param texture defines the texture to update\r\n * @param source defines the source containing the data\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param premulAlpha defines if alpha is stored as premultiplied\r\n * @param format defines the format of the data\r\n * @param forceBindTexture if the texture should be forced to be bound eg. after a graphics context loss (Default: false)\r\n * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature \"allowGPUOptimizationsForGUI\" being true)\r\n */\r\n updateDynamicTexture(\r\n texture: Nullable,\r\n source: ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | ICanvas,\r\n invertY?: boolean,\r\n premulAlpha?: boolean,\r\n format?: number,\r\n forceBindTexture?: boolean,\r\n allowGPUOptimization?: boolean\r\n ): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createDynamicTexture = function (width: number, height: number, generateMipMaps: boolean, samplingMode: number): InternalTexture {\r\n const texture = new InternalTexture(this, InternalTextureSource.Dynamic);\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n\r\n if (generateMipMaps) {\r\n width = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(width, this._caps.maxTextureSize) : width;\r\n height = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(height, this._caps.maxTextureSize) : height;\r\n }\r\n\r\n // this.resetTextureCache();\r\n texture.width = width;\r\n texture.height = height;\r\n texture.isReady = false;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n\r\n this.updateTextureSamplingMode(samplingMode, texture);\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n return texture;\r\n};\r\n\r\nThinEngine.prototype.updateDynamicTexture = function (\r\n texture: Nullable,\r\n source: ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas,\r\n invertY?: boolean,\r\n premulAlpha: boolean = false,\r\n format?: number,\r\n forceBindTexture: boolean = false,\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n allowGPUOptimization: boolean = false\r\n): void {\r\n if (!texture) {\r\n return;\r\n }\r\n\r\n const gl = this._gl;\r\n const target = gl.TEXTURE_2D;\r\n\r\n const wasPreviouslyBound = this._bindTextureDirectly(target, texture, true, forceBindTexture);\r\n\r\n this._unpackFlipY(invertY === undefined ? texture.invertY : invertY);\r\n\r\n if (premulAlpha) {\r\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);\r\n }\r\n\r\n const textureType = this._getWebGLTextureType(texture.type);\r\n const glformat = this._getInternalFormat(format ? format : texture.format);\r\n const internalFormat = this._getRGBABufferInternalSizedFormat(texture.type, glformat);\r\n\r\n gl.texImage2D(target, 0, internalFormat, glformat, textureType, source as TexImageSource);\r\n\r\n if (texture.generateMipMaps) {\r\n gl.generateMipmap(target);\r\n }\r\n\r\n if (!wasPreviouslyBound) {\r\n this._bindTextureDirectly(target, null);\r\n }\r\n\r\n if (premulAlpha) {\r\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);\r\n }\r\n\r\n texture.isReady = true;\r\n};\r\n","import { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { ISize } from \"../../Maths/math.size\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport \"../../Engines/Extensions/engine.dynamicTexture\";\r\nimport type { ICanvas, ICanvasRenderingContext } from \"../../Engines/ICanvas\";\r\n\r\n/**\r\n * A class extending Texture allowing drawing on a texture\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/dynamicTexture\r\n */\r\nexport class DynamicTexture extends Texture {\r\n private _generateMipMaps: boolean;\r\n private _canvas: ICanvas;\r\n private _context: ICanvasRenderingContext;\r\n\r\n /**\r\n * Creates a DynamicTexture\r\n * @param name defines the name of the texture\r\n * @param options provides 3 alternatives for width and height of texture, a canvas, object with width and height properties, number for both width and height\r\n * @param scene defines the scene where you want the texture\r\n * @param generateMipMaps defines the use of MinMaps or not (default is false)\r\n * @param samplingMode defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)\r\n * @param format defines the texture format to use (default is Engine.TEXTUREFORMAT_RGBA)\r\n * @param invertY defines if the texture needs to be inverted on the y axis during loading\r\n */\r\n\r\n constructor(\r\n name: string,\r\n options: any,\r\n scene: Nullable = null,\r\n generateMipMaps: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n format: number = Constants.TEXTUREFORMAT_RGBA,\r\n invertY?: boolean\r\n ) {\r\n super(null, scene, !generateMipMaps, invertY, samplingMode, undefined, undefined, undefined, undefined, format);\r\n\r\n this.name = name;\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n this._generateMipMaps = generateMipMaps;\r\n\r\n const engine = this._getEngine();\r\n if (!engine) {\r\n return;\r\n }\r\n\r\n if (options.getContext) {\r\n this._canvas = options;\r\n this._texture = engine.createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);\r\n } else {\r\n this._canvas = engine.createCanvas(1, 1);\r\n\r\n if (options.width || options.width === 0) {\r\n this._texture = engine.createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);\r\n } else {\r\n this._texture = engine.createDynamicTexture(options, options, generateMipMaps, samplingMode);\r\n }\r\n }\r\n\r\n const textureSize = this.getSize();\r\n\r\n if (this._canvas.width !== textureSize.width) {\r\n this._canvas.width = textureSize.width;\r\n }\r\n if (this._canvas.height !== textureSize.height) {\r\n this._canvas.height = textureSize.height;\r\n }\r\n this._context = this._canvas.getContext(\"2d\");\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"DynamicTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"DynamicTexture\";\r\n }\r\n\r\n /**\r\n * Gets the current state of canRescale\r\n */\r\n public get canRescale(): boolean {\r\n return true;\r\n }\r\n\r\n private _recreate(textureSize: ISize): void {\r\n this._canvas.width = textureSize.width;\r\n this._canvas.height = textureSize.height;\r\n\r\n this.releaseInternalTexture();\r\n\r\n this._texture = this._getEngine()!.createDynamicTexture(textureSize.width, textureSize.height, this._generateMipMaps, this.samplingMode);\r\n }\r\n\r\n /**\r\n * Scales the texture\r\n * @param ratio the scale factor to apply to both width and height\r\n */\r\n public scale(ratio: number): void {\r\n const textureSize = this.getSize();\r\n\r\n textureSize.width *= ratio;\r\n textureSize.height *= ratio;\r\n\r\n this._recreate(textureSize);\r\n }\r\n\r\n /**\r\n * Resizes the texture\r\n * @param width the new width\r\n * @param height the new height\r\n */\r\n public scaleTo(width: number, height: number): void {\r\n const textureSize = this.getSize();\r\n\r\n textureSize.width = width;\r\n textureSize.height = height;\r\n\r\n this._recreate(textureSize);\r\n }\r\n\r\n /**\r\n * Gets the context of the canvas used by the texture\r\n * @returns the canvas context of the dynamic texture\r\n */\r\n public getContext(): ICanvasRenderingContext {\r\n return this._context;\r\n }\r\n\r\n /**\r\n * Clears the texture\r\n */\r\n public clear(): void {\r\n const size = this.getSize();\r\n this._context.fillRect(0, 0, size.width, size.height);\r\n }\r\n\r\n /**\r\n * Updates the texture\r\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\r\n * @param premulAlpha defines if alpha is stored as premultiplied (default is false)\r\n * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature \"allowGPUOptimizationsForGUI\" being true)\r\n */\r\n public update(invertY?: boolean, premulAlpha = false, allowGPUOptimization = false): void {\r\n this._getEngine()!.updateDynamicTexture(\r\n this._texture,\r\n this._canvas,\r\n invertY === undefined ? true : invertY,\r\n premulAlpha,\r\n this._format || undefined,\r\n undefined,\r\n allowGPUOptimization\r\n );\r\n }\r\n\r\n /**\r\n * Draws text onto the texture\r\n * @param text defines the text to be drawn\r\n * @param x defines the placement of the text from the left\r\n * @param y defines the placement of the text from the top when invertY is true and from the bottom when false\r\n * @param font defines the font to be used with font-style, font-size, font-name\r\n * @param color defines the color used for the text\r\n * @param clearColor defines the color for the canvas, use null to not overwrite canvas\r\n * @param invertY defines the direction for the Y axis (default is true - y increases downwards)\r\n * @param update defines whether texture is immediately update (default is true)\r\n */\r\n public drawText(\r\n text: string,\r\n x: number | null | undefined,\r\n y: number | null | undefined,\r\n font: string,\r\n color: string | null,\r\n clearColor: string | null,\r\n invertY?: boolean,\r\n update = true\r\n ) {\r\n const size = this.getSize();\r\n if (clearColor) {\r\n this._context.fillStyle = clearColor;\r\n this._context.fillRect(0, 0, size.width, size.height);\r\n }\r\n\r\n this._context.font = font;\r\n if (x === null || x === undefined) {\r\n const textSize = this._context.measureText(text);\r\n x = (size.width - textSize.width) / 2;\r\n }\r\n if (y === null || y === undefined) {\r\n const fontSize = parseInt(font.replace(/\\D/g, \"\"));\r\n y = size.height / 2 + fontSize / 3.65;\r\n }\r\n\r\n this._context.fillStyle = color || \"\";\r\n this._context.fillText(text, x, y);\r\n\r\n if (update) {\r\n this.update(invertY);\r\n }\r\n }\r\n\r\n /**\r\n * Clones the texture\r\n * @returns the clone of the texture.\r\n */\r\n public clone(): DynamicTexture {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const textureSize = this.getSize();\r\n const newTexture = new DynamicTexture(this.name, textureSize, scene, this._generateMipMaps);\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // Dynamic Texture\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Serializes the dynamic texture. The scene should be ready before the dynamic texture is serialized\r\n * @returns a serialized dynamic texture object\r\n */\r\n public serialize(): any {\r\n const scene = this.getScene();\r\n if (scene && !scene.isReady()) {\r\n Logger.Warn(\"The scene must be ready before serializing the dynamic texture\");\r\n }\r\n\r\n const serializationObject = super.serialize();\r\n if (DynamicTexture._IsCanvasElement(this._canvas)) {\r\n serializationObject.base64String = this._canvas.toDataURL();\r\n }\r\n\r\n serializationObject.invertY = this._invertY;\r\n serializationObject.samplingMode = this.samplingMode;\r\n\r\n return serializationObject;\r\n }\r\n\r\n private static _IsCanvasElement(canvas: HTMLCanvasElement | OffscreenCanvas | ICanvas): canvas is HTMLCanvasElement {\r\n return (canvas as HTMLCanvasElement).toDataURL !== undefined;\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n this.update();\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/imageProcessingDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/imageProcessingFunctions\";\n\nconst name = \"imageProcessingPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec4 result=texture2D(textureSampler,vUV);\n#ifdef IMAGEPROCESSING\n#ifndef FROMLINEARSPACE\nresult.rgb=toLinearSpace(result.rgb);\n#endif\nresult=applyImageProcessing(result);\n#else\n#ifdef FROMLINEARSPACE\nresult=applyImageProcessing(result);\n#endif\n#endif\ngl_FragColor=result;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const imageProcessingPixelShader = { name, shader };\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { serialize } from \"../Misc/decorators\";\r\nimport type { Color4 } from \"../Maths/math.color\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport type { ColorCurves } from \"../Materials/colorCurves\";\r\nimport type { IImageProcessingConfigurationDefines } from \"../Materials/imageProcessingConfiguration\";\r\nimport { ImageProcessingConfiguration } from \"../Materials/imageProcessingConfiguration\";\r\nimport type { PostProcessOptions } from \"./postProcess\";\r\nimport { PostProcess } from \"./postProcess\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport \"../Shaders/imageProcessing.fragment\";\r\nimport \"../Shaders/postprocess.vertex\";\r\n\r\n/**\r\n * ImageProcessingPostProcess\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses#imageprocessing\r\n */\r\nexport class ImageProcessingPostProcess extends PostProcess {\r\n /**\r\n * Default configuration related to image processing available in the PBR Material.\r\n */\r\n protected _imageProcessingConfiguration: ImageProcessingConfiguration;\r\n\r\n /**\r\n * Gets the image processing configuration used either in this material.\r\n */\r\n public get imageProcessingConfiguration(): ImageProcessingConfiguration {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n /**\r\n * Sets the Default image processing configuration used either in the this material.\r\n *\r\n * If sets to null, the scene one is in use.\r\n */\r\n public set imageProcessingConfiguration(value: ImageProcessingConfiguration) {\r\n // We are almost sure it is applied by post process as\r\n // We are in the post process :-)\r\n value.applyByPostProcess = true;\r\n this._attachImageProcessingConfiguration(value);\r\n }\r\n\r\n /**\r\n * Keep track of the image processing observer to allow dispose and replace.\r\n */\r\n private _imageProcessingObserver: Nullable>;\r\n\r\n /**\r\n * Attaches a new image processing configuration to the PBR Material.\r\n * @param configuration\r\n * @param doNotBuild\r\n */\r\n protected _attachImageProcessingConfiguration(configuration: Nullable, doNotBuild = false): void {\r\n if (configuration === this._imageProcessingConfiguration) {\r\n return;\r\n }\r\n\r\n // Detaches observer.\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n // Pick the scene configuration if needed.\r\n if (!configuration) {\r\n let scene = null;\r\n const engine = this.getEngine();\r\n const camera = this.getCamera();\r\n\r\n if (camera) {\r\n scene = camera.getScene();\r\n } else if (engine && engine.scenes) {\r\n const scenes = engine.scenes;\r\n scene = scenes[scenes.length - 1];\r\n } else {\r\n scene = EngineStore.LastCreatedScene;\r\n }\r\n\r\n if (scene) {\r\n this._imageProcessingConfiguration = scene.imageProcessingConfiguration;\r\n } else {\r\n this._imageProcessingConfiguration = new ImageProcessingConfiguration();\r\n }\r\n } else {\r\n this._imageProcessingConfiguration = configuration;\r\n }\r\n\r\n // Attaches observer.\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\r\n this._updateParameters();\r\n });\r\n }\r\n\r\n // Ensure the effect will be rebuilt.\r\n if (!doNotBuild) {\r\n this._updateParameters();\r\n }\r\n }\r\n\r\n /**\r\n * If the post process is supported.\r\n */\r\n public get isSupported(): boolean {\r\n const effect = this.getEffect();\r\n return !effect || effect.isSupported;\r\n }\r\n\r\n /**\r\n * Gets Color curves setup used in the effect if colorCurvesEnabled is set to true .\r\n */\r\n public get colorCurves(): Nullable {\r\n return this.imageProcessingConfiguration.colorCurves;\r\n }\r\n /**\r\n * Sets Color curves setup used in the effect if colorCurvesEnabled is set to true .\r\n */\r\n public set colorCurves(value: Nullable) {\r\n this.imageProcessingConfiguration.colorCurves = value;\r\n }\r\n\r\n /**\r\n * Gets whether the color curves effect is enabled.\r\n */\r\n public get colorCurvesEnabled(): boolean {\r\n return this.imageProcessingConfiguration.colorCurvesEnabled;\r\n }\r\n /**\r\n * Sets whether the color curves effect is enabled.\r\n */\r\n public set colorCurvesEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.colorCurvesEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.\r\n */\r\n public get colorGradingTexture(): Nullable {\r\n return this.imageProcessingConfiguration.colorGradingTexture;\r\n }\r\n /**\r\n * Sets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.\r\n */\r\n public set colorGradingTexture(value: Nullable) {\r\n this.imageProcessingConfiguration.colorGradingTexture = value;\r\n }\r\n\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public get colorGradingEnabled(): boolean {\r\n return this.imageProcessingConfiguration.colorGradingEnabled;\r\n }\r\n /**\r\n * Gets whether the color grading effect is enabled.\r\n */\r\n public set colorGradingEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.colorGradingEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets exposure used in the effect.\r\n */\r\n public get exposure(): number {\r\n return this.imageProcessingConfiguration.exposure;\r\n }\r\n /**\r\n * Sets exposure used in the effect.\r\n */\r\n public set exposure(value: number) {\r\n this.imageProcessingConfiguration.exposure = value;\r\n }\r\n\r\n /**\r\n * Gets whether tonemapping is enabled or not.\r\n */\r\n public get toneMappingEnabled(): boolean {\r\n return this._imageProcessingConfiguration.toneMappingEnabled;\r\n }\r\n /**\r\n * Sets whether tonemapping is enabled or not\r\n */\r\n public set toneMappingEnabled(value: boolean) {\r\n this._imageProcessingConfiguration.toneMappingEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets the type of tone mapping effect.\r\n */\r\n public get toneMappingType(): number {\r\n return this._imageProcessingConfiguration.toneMappingType;\r\n }\r\n /**\r\n * Sets the type of tone mapping effect.\r\n */\r\n public set toneMappingType(value: number) {\r\n this._imageProcessingConfiguration.toneMappingType = value;\r\n }\r\n\r\n /**\r\n * Gets contrast used in the effect.\r\n */\r\n public get contrast(): number {\r\n return this.imageProcessingConfiguration.contrast;\r\n }\r\n /**\r\n * Sets contrast used in the effect.\r\n */\r\n public set contrast(value: number) {\r\n this.imageProcessingConfiguration.contrast = value;\r\n }\r\n\r\n /**\r\n * Gets Vignette stretch size.\r\n */\r\n public get vignetteStretch(): number {\r\n return this.imageProcessingConfiguration.vignetteStretch;\r\n }\r\n /**\r\n * Sets Vignette stretch size.\r\n */\r\n public set vignetteStretch(value: number) {\r\n this.imageProcessingConfiguration.vignetteStretch = value;\r\n }\r\n\r\n /**\r\n * Gets Vignette center X Offset.\r\n * @deprecated use vignetteCenterX instead\r\n */\r\n public get vignetteCentreX(): number {\r\n return this.imageProcessingConfiguration.vignetteCenterX;\r\n }\r\n /**\r\n * Sets Vignette center X Offset.\r\n * @deprecated use vignetteCenterX instead\r\n */\r\n public set vignetteCentreX(value: number) {\r\n this.imageProcessingConfiguration.vignetteCenterX = value;\r\n }\r\n\r\n /**\r\n * Gets Vignette center Y Offset.\r\n * @deprecated use vignetteCenterY instead\r\n */\r\n public get vignetteCentreY(): number {\r\n return this.imageProcessingConfiguration.vignetteCenterY;\r\n }\r\n /**\r\n * Sets Vignette center Y Offset.\r\n * @deprecated use vignetteCenterY instead\r\n */\r\n public set vignetteCentreY(value: number) {\r\n this.imageProcessingConfiguration.vignetteCenterY = value;\r\n }\r\n\r\n /**\r\n * Vignette center Y Offset.\r\n */\r\n public get vignetteCenterY(): number {\r\n return this.imageProcessingConfiguration.vignetteCenterY;\r\n }\r\n public set vignetteCenterY(value: number) {\r\n this.imageProcessingConfiguration.vignetteCenterY = value;\r\n }\r\n\r\n /**\r\n * Vignette center X Offset.\r\n */\r\n public get vignetteCenterX(): number {\r\n return this.imageProcessingConfiguration.vignetteCenterX;\r\n }\r\n public set vignetteCenterX(value: number) {\r\n this.imageProcessingConfiguration.vignetteCenterX = value;\r\n }\r\n\r\n /**\r\n * Gets Vignette weight or intensity of the vignette effect.\r\n */\r\n public get vignetteWeight(): number {\r\n return this.imageProcessingConfiguration.vignetteWeight;\r\n }\r\n /**\r\n * Sets Vignette weight or intensity of the vignette effect.\r\n */\r\n public set vignetteWeight(value: number) {\r\n this.imageProcessingConfiguration.vignetteWeight = value;\r\n }\r\n\r\n /**\r\n * Gets Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)\r\n * if vignetteEnabled is set to true.\r\n */\r\n public get vignetteColor(): Color4 {\r\n return this.imageProcessingConfiguration.vignetteColor;\r\n }\r\n /**\r\n * Sets Color of the vignette applied on the screen through the chosen blend mode (vignetteBlendMode)\r\n * if vignetteEnabled is set to true.\r\n */\r\n public set vignetteColor(value: Color4) {\r\n this.imageProcessingConfiguration.vignetteColor = value;\r\n }\r\n\r\n /**\r\n * Gets Camera field of view used by the Vignette effect.\r\n */\r\n public get vignetteCameraFov(): number {\r\n return this.imageProcessingConfiguration.vignetteCameraFov;\r\n }\r\n /**\r\n * Sets Camera field of view used by the Vignette effect.\r\n */\r\n public set vignetteCameraFov(value: number) {\r\n this.imageProcessingConfiguration.vignetteCameraFov = value;\r\n }\r\n\r\n /**\r\n * Gets the vignette blend mode allowing different kind of effect.\r\n */\r\n public get vignetteBlendMode(): number {\r\n return this.imageProcessingConfiguration.vignetteBlendMode;\r\n }\r\n /**\r\n * Sets the vignette blend mode allowing different kind of effect.\r\n */\r\n public set vignetteBlendMode(value: number) {\r\n this.imageProcessingConfiguration.vignetteBlendMode = value;\r\n }\r\n\r\n /**\r\n * Gets whether the vignette effect is enabled.\r\n */\r\n public get vignetteEnabled(): boolean {\r\n return this.imageProcessingConfiguration.vignetteEnabled;\r\n }\r\n /**\r\n * Sets whether the vignette effect is enabled.\r\n */\r\n public set vignetteEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.vignetteEnabled = value;\r\n }\r\n\r\n /**\r\n * Gets intensity of the dithering effect.\r\n */\r\n public get ditheringIntensity(): number {\r\n return this.imageProcessingConfiguration.ditheringIntensity;\r\n }\r\n /**\r\n * Sets intensity of the dithering effect.\r\n */\r\n public set ditheringIntensity(value: number) {\r\n this.imageProcessingConfiguration.ditheringIntensity = value;\r\n }\r\n\r\n /**\r\n * Gets whether the dithering effect is enabled.\r\n */\r\n public get ditheringEnabled(): boolean {\r\n return this.imageProcessingConfiguration.ditheringEnabled;\r\n }\r\n /**\r\n * Sets whether the dithering effect is enabled.\r\n */\r\n public set ditheringEnabled(value: boolean) {\r\n this.imageProcessingConfiguration.ditheringEnabled = value;\r\n }\r\n\r\n @serialize()\r\n private _fromLinearSpace = true;\r\n /**\r\n * Gets whether the input of the processing is in Gamma or Linear Space.\r\n */\r\n public get fromLinearSpace(): boolean {\r\n return this._fromLinearSpace;\r\n }\r\n /**\r\n * Sets whether the input of the processing is in Gamma or Linear Space.\r\n */\r\n public set fromLinearSpace(value: boolean) {\r\n if (this._fromLinearSpace === value) {\r\n return;\r\n }\r\n\r\n this._fromLinearSpace = value;\r\n this._updateParameters();\r\n }\r\n\r\n /**\r\n * Defines cache preventing GC.\r\n */\r\n private _defines: IImageProcessingConfigurationDefines & { FROMLINEARSPACE: boolean } = {\r\n IMAGEPROCESSING: false,\r\n VIGNETTE: false,\r\n VIGNETTEBLENDMODEMULTIPLY: false,\r\n VIGNETTEBLENDMODEOPAQUE: false,\r\n TONEMAPPING: false,\r\n TONEMAPPING_ACES: false,\r\n CONTRAST: false,\r\n COLORCURVES: false,\r\n COLORGRADING: false,\r\n COLORGRADING3D: false,\r\n FROMLINEARSPACE: false,\r\n SAMPLER3DGREENDEPTH: false,\r\n SAMPLER3DBGRMAP: false,\r\n DITHER: false,\r\n IMAGEPROCESSINGPOSTPROCESS: false,\r\n EXPOSURE: false,\r\n SKIPFINALCOLORCLAMP: false,\r\n };\r\n\r\n constructor(\r\n name: string,\r\n options: number | PostProcessOptions,\r\n camera: Nullable = null,\r\n samplingMode?: number,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n imageProcessingConfiguration?: ImageProcessingConfiguration\r\n ) {\r\n super(name, \"imageProcessing\", [], [], options, camera, samplingMode, engine, reusable, null, textureType, \"postprocess\", null, true);\r\n\r\n // Setup the configuration as forced by the constructor. This would then not force the\r\n // scene materials output in linear space and let untouched the default forward pass.\r\n if (imageProcessingConfiguration) {\r\n imageProcessingConfiguration.applyByPostProcess = true;\r\n this._attachImageProcessingConfiguration(imageProcessingConfiguration, true);\r\n // This will cause the shader to be compiled\r\n this._updateParameters();\r\n }\r\n // Setup the default processing configuration to the scene.\r\n else {\r\n this._attachImageProcessingConfiguration(null, true);\r\n this.imageProcessingConfiguration.applyByPostProcess = true;\r\n }\r\n\r\n this.onApply = (effect: Effect) => {\r\n this.imageProcessingConfiguration.bind(effect, this.aspectRatio);\r\n };\r\n }\r\n /**\r\n * \"ImageProcessingPostProcess\"\r\n * @returns \"ImageProcessingPostProcess\"\r\n */\r\n public getClassName(): string {\r\n return \"ImageProcessingPostProcess\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateParameters(): void {\r\n this._defines.FROMLINEARSPACE = this._fromLinearSpace;\r\n this.imageProcessingConfiguration.prepareDefines(this._defines, true);\r\n let defines = \"\";\r\n for (const define in this._defines) {\r\n if ((this._defines)[define]) {\r\n defines += `#define ${define};\\n`;\r\n }\r\n }\r\n\r\n const samplers = [\"textureSampler\"];\r\n const uniforms = [\"scale\"];\r\n\r\n if (ImageProcessingConfiguration) {\r\n ImageProcessingConfiguration.PrepareSamplers(samplers, this._defines);\r\n ImageProcessingConfiguration.PrepareUniforms(uniforms, this._defines);\r\n }\r\n\r\n this.updateEffect(defines, uniforms, samplers);\r\n }\r\n\r\n public dispose(camera?: Camera): void {\r\n super.dispose(camera);\r\n\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n if (this._imageProcessingConfiguration) {\r\n this.imageProcessingConfiguration.applyByPostProcess = false;\r\n }\r\n }\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\nimport { Gamepad } from \"./gamepad\";\r\n\r\n/**\r\n * Defines supported buttons for DualShock compatible gamepads\r\n */\r\nexport enum DualShockButton {\r\n /** Cross */\r\n Cross = 0,\r\n /** Circle */\r\n Circle = 1,\r\n /** Square */\r\n Square = 2,\r\n /** Triangle */\r\n Triangle = 3,\r\n /** L1 */\r\n L1 = 4,\r\n /** R1 */\r\n R1 = 5,\r\n /** Share */\r\n Share = 8,\r\n /** Options */\r\n Options = 9,\r\n /** Left stick */\r\n LeftStick = 10,\r\n /** Right stick */\r\n RightStick = 11,\r\n}\r\n\r\n/** Defines values for DualShock DPad */\r\nexport enum DualShockDpad {\r\n /** Up */\r\n Up = 12,\r\n /** Down */\r\n Down = 13,\r\n /** Left */\r\n Left = 14,\r\n /** Right */\r\n Right = 15,\r\n}\r\n\r\n/**\r\n * Defines a DualShock gamepad\r\n */\r\nexport class DualShockPad extends Gamepad {\r\n private _leftTrigger: number = 0;\r\n private _rightTrigger: number = 0;\r\n\r\n private _onlefttriggerchanged: (value: number) => void;\r\n private _onrighttriggerchanged: (value: number) => void;\r\n\r\n private _onbuttondown: (buttonPressed: DualShockButton) => void;\r\n private _onbuttonup: (buttonReleased: DualShockButton) => void;\r\n private _ondpaddown: (dPadPressed: DualShockDpad) => void;\r\n private _ondpadup: (dPadReleased: DualShockDpad) => void;\r\n\r\n /** Observable raised when a button is pressed */\r\n public onButtonDownObservable = new Observable();\r\n /** Observable raised when a button is released */\r\n public onButtonUpObservable = new Observable();\r\n /** Observable raised when a pad is pressed */\r\n public onPadDownObservable = new Observable();\r\n /** Observable raised when a pad is released */\r\n public onPadUpObservable = new Observable();\r\n\r\n private _buttonCross: number = 0;\r\n private _buttonCircle: number = 0;\r\n private _buttonSquare: number = 0;\r\n private _buttonTriangle: number = 0;\r\n private _buttonShare: number = 0;\r\n private _buttonOptions: number = 0;\r\n private _buttonL1: number = 0;\r\n private _buttonR1: number = 0;\r\n\r\n private _buttonLeftStick: number = 0;\r\n private _buttonRightStick: number = 0;\r\n private _dPadUp: number = 0;\r\n private _dPadDown: number = 0;\r\n private _dPadLeft: number = 0;\r\n private _dPadRight: number = 0;\r\n\r\n /**\r\n * Creates a new DualShock gamepad object\r\n * @param id defines the id of this gamepad\r\n * @param index defines its index\r\n * @param gamepad defines the internal HTML gamepad object\r\n */\r\n constructor(id: string, index: number, gamepad: any) {\r\n super(id.replace(\"STANDARD GAMEPAD\", \"SONY PLAYSTATION DUALSHOCK\"), index, gamepad, 0, 1, 2, 3);\r\n this.type = Gamepad.DUALSHOCK;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when left trigger is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public onlefttriggerchanged(callback: (value: number) => void) {\r\n this._onlefttriggerchanged = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when right trigger is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public onrighttriggerchanged(callback: (value: number) => void) {\r\n this._onrighttriggerchanged = callback;\r\n }\r\n\r\n /**\r\n * Gets the left trigger value\r\n */\r\n public get leftTrigger(): number {\r\n return this._leftTrigger;\r\n }\r\n /**\r\n * Sets the left trigger value\r\n */\r\n public set leftTrigger(newValue: number) {\r\n if (this._onlefttriggerchanged && this._leftTrigger !== newValue) {\r\n this._onlefttriggerchanged(newValue);\r\n }\r\n this._leftTrigger = newValue;\r\n }\r\n\r\n /**\r\n * Gets the right trigger value\r\n */\r\n public get rightTrigger(): number {\r\n return this._rightTrigger;\r\n }\r\n /**\r\n * Sets the right trigger value\r\n */\r\n public set rightTrigger(newValue: number) {\r\n if (this._onrighttriggerchanged && this._rightTrigger !== newValue) {\r\n this._onrighttriggerchanged(newValue);\r\n }\r\n this._rightTrigger = newValue;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a button is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public onbuttondown(callback: (buttonPressed: DualShockButton) => void) {\r\n this._onbuttondown = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a button is released\r\n * @param callback defines the callback to use\r\n */\r\n public onbuttonup(callback: (buttonReleased: DualShockButton) => void) {\r\n this._onbuttonup = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a pad is pressed\r\n * @param callback defines the callback to use\r\n */\r\n public ondpaddown(callback: (dPadPressed: DualShockDpad) => void) {\r\n this._ondpaddown = callback;\r\n }\r\n\r\n /**\r\n * Defines the callback to call when a pad is released\r\n * @param callback defines the callback to use\r\n */\r\n public ondpadup(callback: (dPadReleased: DualShockDpad) => void) {\r\n this._ondpadup = callback;\r\n }\r\n\r\n private _setButtonValue(newValue: number, currentValue: number, buttonType: DualShockButton): number {\r\n if (newValue !== currentValue) {\r\n if (newValue === 1) {\r\n if (this._onbuttondown) {\r\n this._onbuttondown(buttonType);\r\n }\r\n\r\n this.onButtonDownObservable.notifyObservers(buttonType);\r\n }\r\n if (newValue === 0) {\r\n if (this._onbuttonup) {\r\n this._onbuttonup(buttonType);\r\n }\r\n\r\n this.onButtonUpObservable.notifyObservers(buttonType);\r\n }\r\n }\r\n return newValue;\r\n }\r\n\r\n private _setDPadValue(newValue: number, currentValue: number, buttonType: DualShockDpad): number {\r\n if (newValue !== currentValue) {\r\n if (newValue === 1) {\r\n if (this._ondpaddown) {\r\n this._ondpaddown(buttonType);\r\n }\r\n\r\n this.onPadDownObservable.notifyObservers(buttonType);\r\n }\r\n if (newValue === 0) {\r\n if (this._ondpadup) {\r\n this._ondpadup(buttonType);\r\n }\r\n\r\n this.onPadUpObservable.notifyObservers(buttonType);\r\n }\r\n }\r\n return newValue;\r\n }\r\n\r\n /**\r\n * Gets the value of the `Cross` button\r\n */\r\n public get buttonCross(): number {\r\n return this._buttonCross;\r\n }\r\n /**\r\n * Sets the value of the `Cross` button\r\n */\r\n public set buttonCross(value) {\r\n this._buttonCross = this._setButtonValue(value, this._buttonCross, DualShockButton.Cross);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Circle` button\r\n */\r\n public get buttonCircle(): number {\r\n return this._buttonCircle;\r\n }\r\n /**\r\n * Sets the value of the `Circle` button\r\n */\r\n public set buttonCircle(value) {\r\n this._buttonCircle = this._setButtonValue(value, this._buttonCircle, DualShockButton.Circle);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Square` button\r\n */\r\n public get buttonSquare(): number {\r\n return this._buttonSquare;\r\n }\r\n /**\r\n * Sets the value of the `Square` button\r\n */\r\n public set buttonSquare(value) {\r\n this._buttonSquare = this._setButtonValue(value, this._buttonSquare, DualShockButton.Square);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Triangle` button\r\n */\r\n public get buttonTriangle(): number {\r\n return this._buttonTriangle;\r\n }\r\n /**\r\n * Sets the value of the `Triangle` button\r\n */\r\n public set buttonTriangle(value) {\r\n this._buttonTriangle = this._setButtonValue(value, this._buttonTriangle, DualShockButton.Triangle);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Options` button\r\n */\r\n public get buttonOptions(): number {\r\n return this._buttonOptions;\r\n }\r\n /**\r\n * Sets the value of the `Options` button\r\n */\r\n public set buttonOptions(value) {\r\n this._buttonOptions = this._setButtonValue(value, this._buttonOptions, DualShockButton.Options);\r\n }\r\n\r\n /**\r\n * Gets the value of the `Share` button\r\n */\r\n public get buttonShare(): number {\r\n return this._buttonShare;\r\n }\r\n /**\r\n * Sets the value of the `Share` button\r\n */\r\n public set buttonShare(value) {\r\n this._buttonShare = this._setButtonValue(value, this._buttonShare, DualShockButton.Share);\r\n }\r\n\r\n /**\r\n * Gets the value of the `L1` button\r\n */\r\n public get buttonL1(): number {\r\n return this._buttonL1;\r\n }\r\n /**\r\n * Sets the value of the `L1` button\r\n */\r\n public set buttonL1(value) {\r\n this._buttonL1 = this._setButtonValue(value, this._buttonL1, DualShockButton.L1);\r\n }\r\n\r\n /**\r\n * Gets the value of the `R1` button\r\n */\r\n public get buttonR1(): number {\r\n return this._buttonR1;\r\n }\r\n /**\r\n * Sets the value of the `R1` button\r\n */\r\n public set buttonR1(value) {\r\n this._buttonR1 = this._setButtonValue(value, this._buttonR1, DualShockButton.R1);\r\n }\r\n\r\n /**\r\n * Gets the value of the Left joystick\r\n */\r\n public get buttonLeftStick(): number {\r\n return this._buttonLeftStick;\r\n }\r\n /**\r\n * Sets the value of the Left joystick\r\n */\r\n public set buttonLeftStick(value) {\r\n this._buttonLeftStick = this._setButtonValue(value, this._buttonLeftStick, DualShockButton.LeftStick);\r\n }\r\n\r\n /**\r\n * Gets the value of the Right joystick\r\n */\r\n public get buttonRightStick(): number {\r\n return this._buttonRightStick;\r\n }\r\n /**\r\n * Sets the value of the Right joystick\r\n */\r\n public set buttonRightStick(value) {\r\n this._buttonRightStick = this._setButtonValue(value, this._buttonRightStick, DualShockButton.RightStick);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad up\r\n */\r\n public get dPadUp(): number {\r\n return this._dPadUp;\r\n }\r\n /**\r\n * Sets the value of D-pad up\r\n */\r\n public set dPadUp(value) {\r\n this._dPadUp = this._setDPadValue(value, this._dPadUp, DualShockDpad.Up);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad down\r\n */\r\n public get dPadDown(): number {\r\n return this._dPadDown;\r\n }\r\n /**\r\n * Sets the value of D-pad down\r\n */\r\n public set dPadDown(value) {\r\n this._dPadDown = this._setDPadValue(value, this._dPadDown, DualShockDpad.Down);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad left\r\n */\r\n public get dPadLeft(): number {\r\n return this._dPadLeft;\r\n }\r\n /**\r\n * Sets the value of D-pad left\r\n */\r\n public set dPadLeft(value) {\r\n this._dPadLeft = this._setDPadValue(value, this._dPadLeft, DualShockDpad.Left);\r\n }\r\n\r\n /**\r\n * Gets the value of D-pad right\r\n */\r\n public get dPadRight(): number {\r\n return this._dPadRight;\r\n }\r\n /**\r\n * Sets the value of D-pad right\r\n */\r\n public set dPadRight(value) {\r\n this._dPadRight = this._setDPadValue(value, this._dPadRight, DualShockDpad.Right);\r\n }\r\n\r\n /**\r\n * Force the gamepad to synchronize with device values\r\n */\r\n public update() {\r\n super.update();\r\n this.buttonCross = this.browserGamepad.buttons[0].value;\r\n this.buttonCircle = this.browserGamepad.buttons[1].value;\r\n this.buttonSquare = this.browserGamepad.buttons[2].value;\r\n this.buttonTriangle = this.browserGamepad.buttons[3].value;\r\n this.buttonL1 = this.browserGamepad.buttons[4].value;\r\n this.buttonR1 = this.browserGamepad.buttons[5].value;\r\n this.leftTrigger = this.browserGamepad.buttons[6].value;\r\n this.rightTrigger = this.browserGamepad.buttons[7].value;\r\n this.buttonShare = this.browserGamepad.buttons[8].value;\r\n this.buttonOptions = this.browserGamepad.buttons[9].value;\r\n this.buttonLeftStick = this.browserGamepad.buttons[10].value;\r\n this.buttonRightStick = this.browserGamepad.buttons[11].value;\r\n this.dPadUp = this.browserGamepad.buttons[12].value;\r\n this.dPadDown = this.browserGamepad.buttons[13].value;\r\n this.dPadLeft = this.browserGamepad.buttons[14].value;\r\n this.dPadRight = this.browserGamepad.buttons[15].value;\r\n }\r\n\r\n /**\r\n * Disposes the gamepad\r\n */\r\n public dispose() {\r\n super.dispose();\r\n this.onButtonDownObservable.clear();\r\n this.onButtonUpObservable.clear();\r\n this.onPadDownObservable.clear();\r\n this.onPadUpObservable.clear();\r\n }\r\n}\r\n","import { Observable } from \"../Misc/observable\";\r\nimport { IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { PoseEnabledControllerHelper } from \"../Gamepads/Controllers/poseEnabledController\";\r\nimport { Xbox360Pad } from \"./xboxGamepad\";\r\nimport { Gamepad, GenericPad } from \"./gamepad\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport { DualShockPad } from \"./dualShockGamepad\";\r\nimport { Tools } from \"../Misc/tools\";\r\n/**\r\n * Manager for handling gamepads\r\n */\r\nexport class GamepadManager {\r\n private _babylonGamepads: Array = [];\r\n private _oneGamepadConnected: boolean = false;\r\n\r\n /** @internal */\r\n public _isMonitoring: boolean = false;\r\n private _gamepadEventSupported: boolean;\r\n private _gamepadSupport?: () => Array;\r\n\r\n /**\r\n * observable to be triggered when the gamepad controller has been connected\r\n */\r\n public onGamepadConnectedObservable: Observable;\r\n\r\n /**\r\n * observable to be triggered when the gamepad controller has been disconnected\r\n */\r\n public onGamepadDisconnectedObservable = new Observable();\r\n\r\n private _onGamepadConnectedEvent: Nullable<(evt: any) => void>;\r\n private _onGamepadDisconnectedEvent: Nullable<(evt: any) => void>;\r\n\r\n /**\r\n * Initializes the gamepad manager\r\n * @param _scene BabylonJS scene\r\n */\r\n constructor(private _scene?: Scene) {\r\n if (!IsWindowObjectExist()) {\r\n this._gamepadEventSupported = false;\r\n } else {\r\n this._gamepadEventSupported = \"GamepadEvent\" in window;\r\n this._gamepadSupport = navigator && navigator.getGamepads;\r\n }\r\n\r\n this.onGamepadConnectedObservable = new Observable((observer) => {\r\n // This will be used to raise the onGamepadConnected for all gamepads ALREADY connected\r\n for (const i in this._babylonGamepads) {\r\n const gamepad = this._babylonGamepads[i];\r\n if (gamepad && gamepad._isConnected) {\r\n this.onGamepadConnectedObservable.notifyObserver(observer, gamepad);\r\n }\r\n }\r\n });\r\n\r\n this._onGamepadConnectedEvent = (evt) => {\r\n const gamepad = evt.gamepad;\r\n\r\n if (gamepad.index in this._babylonGamepads) {\r\n if (this._babylonGamepads[gamepad.index].isConnected) {\r\n return;\r\n }\r\n }\r\n\r\n let newGamepad: Gamepad;\r\n\r\n if (this._babylonGamepads[gamepad.index]) {\r\n newGamepad = this._babylonGamepads[gamepad.index];\r\n newGamepad.browserGamepad = gamepad;\r\n newGamepad._isConnected = true;\r\n } else {\r\n newGamepad = this._addNewGamepad(gamepad);\r\n }\r\n this.onGamepadConnectedObservable.notifyObservers(newGamepad);\r\n this._startMonitoringGamepads();\r\n };\r\n\r\n this._onGamepadDisconnectedEvent = (evt) => {\r\n const gamepad = evt.gamepad;\r\n\r\n // Remove the gamepad from the list of gamepads to monitor.\r\n for (const i in this._babylonGamepads) {\r\n if (this._babylonGamepads[i].index === gamepad.index) {\r\n const disconnectedGamepad = this._babylonGamepads[i];\r\n disconnectedGamepad._isConnected = false;\r\n\r\n this.onGamepadDisconnectedObservable.notifyObservers(disconnectedGamepad);\r\n disconnectedGamepad.dispose && disconnectedGamepad.dispose();\r\n break;\r\n }\r\n }\r\n };\r\n\r\n if (this._gamepadSupport) {\r\n //first add already-connected gamepads\r\n this._updateGamepadObjects();\r\n if (this._babylonGamepads.length) {\r\n this._startMonitoringGamepads();\r\n }\r\n // Checking if the gamepad connected event is supported (like in Firefox)\r\n if (this._gamepadEventSupported) {\r\n const hostWindow = this._scene ? this._scene.getEngine().getHostWindow() : window;\r\n\r\n if (hostWindow) {\r\n hostWindow.addEventListener(\"gamepadconnected\", this._onGamepadConnectedEvent, false);\r\n hostWindow.addEventListener(\"gamepaddisconnected\", this._onGamepadDisconnectedEvent, false);\r\n }\r\n } else {\r\n this._startMonitoringGamepads();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * The gamepads in the game pad manager\r\n */\r\n public get gamepads(): Gamepad[] {\r\n return this._babylonGamepads;\r\n }\r\n\r\n /**\r\n * Get the gamepad controllers based on type\r\n * @param type The type of gamepad controller\r\n * @returns Nullable gamepad\r\n */\r\n public getGamepadByType(type: number = Gamepad.XBOX): Nullable {\r\n for (const gamepad of this._babylonGamepads) {\r\n if (gamepad && gamepad.type === type) {\r\n return gamepad;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Disposes the gamepad manager\r\n */\r\n public dispose() {\r\n if (this._gamepadEventSupported) {\r\n if (this._onGamepadConnectedEvent) {\r\n window.removeEventListener(\"gamepadconnected\", this._onGamepadConnectedEvent);\r\n }\r\n\r\n if (this._onGamepadDisconnectedEvent) {\r\n window.removeEventListener(\"gamepaddisconnected\", this._onGamepadDisconnectedEvent);\r\n }\r\n this._onGamepadConnectedEvent = null;\r\n this._onGamepadDisconnectedEvent = null;\r\n }\r\n\r\n this._babylonGamepads.forEach((gamepad) => {\r\n gamepad.dispose();\r\n });\r\n\r\n this.onGamepadConnectedObservable.clear();\r\n this.onGamepadDisconnectedObservable.clear();\r\n\r\n this._oneGamepadConnected = false;\r\n this._stopMonitoringGamepads();\r\n this._babylonGamepads = [];\r\n }\r\n\r\n private _addNewGamepad(gamepad: any): Gamepad {\r\n if (!this._oneGamepadConnected) {\r\n this._oneGamepadConnected = true;\r\n }\r\n\r\n let newGamepad;\r\n const dualShock: boolean = (gamepad.id).search(\"054c\") !== -1 && (gamepad.id).search(\"0ce6\") === -1;\r\n const xboxOne: boolean = (gamepad.id).search(\"Xbox One\") !== -1;\r\n if (\r\n xboxOne ||\r\n (gamepad.id).search(\"Xbox 360\") !== -1 ||\r\n (gamepad.id).search(\"xinput\") !== -1 ||\r\n ((gamepad.id).search(\"045e\") !== -1 && (gamepad.id).search(\"Surface Dock\") === -1)\r\n ) {\r\n // make sure the Surface Dock Extender is not detected as an xbox controller\r\n newGamepad = new Xbox360Pad(gamepad.id, gamepad.index, gamepad, xboxOne);\r\n } else if (dualShock) {\r\n newGamepad = new DualShockPad(gamepad.id, gamepad.index, gamepad);\r\n }\r\n // if pose is supported, use the (WebVR) pose enabled controller\r\n else if (gamepad.pose) {\r\n newGamepad = PoseEnabledControllerHelper.InitiateController(gamepad);\r\n } else {\r\n newGamepad = new GenericPad(gamepad.id, gamepad.index, gamepad);\r\n }\r\n this._babylonGamepads[newGamepad.index] = newGamepad;\r\n return newGamepad;\r\n }\r\n\r\n private _startMonitoringGamepads() {\r\n if (!this._isMonitoring) {\r\n this._isMonitoring = true;\r\n //back-comp\r\n this._checkGamepadsStatus();\r\n }\r\n }\r\n\r\n private _stopMonitoringGamepads() {\r\n this._isMonitoring = false;\r\n }\r\n\r\n private _loggedErrors: number[];\r\n\r\n /** @internal */\r\n public _checkGamepadsStatus() {\r\n // Hack to be compatible Chrome\r\n this._updateGamepadObjects();\r\n\r\n for (const i in this._babylonGamepads) {\r\n const gamepad = this._babylonGamepads[i];\r\n if (!gamepad || !gamepad.isConnected) {\r\n continue;\r\n }\r\n try {\r\n gamepad.update();\r\n } catch {\r\n if (this._loggedErrors.indexOf(gamepad.index) === -1) {\r\n Tools.Warn(`Error updating gamepad ${gamepad.id}`);\r\n this._loggedErrors.push(gamepad.index);\r\n }\r\n }\r\n }\r\n\r\n if (this._isMonitoring) {\r\n Engine.QueueNewFrame(() => {\r\n this._checkGamepadsStatus();\r\n });\r\n }\r\n }\r\n\r\n // This function is called only on Chrome, which does not properly support\r\n // connection/disconnection events and forces you to recopy again the gamepad object\r\n private _updateGamepadObjects() {\r\n const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];\r\n for (let i = 0; i < gamepads.length; i++) {\r\n const gamepad = gamepads[i];\r\n if (gamepad) {\r\n if (!this._babylonGamepads[gamepad.index]) {\r\n const newGamepad = this._addNewGamepad(gamepad);\r\n this.onGamepadConnectedObservable.notifyObservers(newGamepad);\r\n } else {\r\n // Forced to copy again this object for Chrome for unknown reason\r\n this._babylonGamepads[i].browserGamepad = gamepad;\r\n\r\n if (!this._babylonGamepads[i].isConnected) {\r\n this._babylonGamepads[i]._isConnected = true;\r\n this.onGamepadConnectedObservable.notifyObservers(this._babylonGamepads[i]);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n","import { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport { Matrix, Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Gamepad } from \"../../Gamepads/gamepad\";\r\n\r\n/**\r\n * Manage the gamepad inputs to control a free camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FreeCameraGamepadInput implements ICameraInput {\r\n /**\r\n * Define the camera the input is attached to.\r\n */\r\n public camera: FreeCamera;\r\n\r\n /**\r\n * Define the Gamepad controlling the input\r\n */\r\n public gamepad: Nullable;\r\n\r\n /**\r\n * Defines the gamepad rotation sensibility.\r\n * This is the threshold from when rotation starts to be accounted for to prevent jittering.\r\n */\r\n @serialize()\r\n public gamepadAngularSensibility = 200;\r\n\r\n /**\r\n * Defines the gamepad move sensibility.\r\n * This is the threshold from when moving starts to be accounted for for to prevent jittering.\r\n */\r\n @serialize()\r\n public gamepadMoveSensibility = 40;\r\n\r\n /**\r\n * Defines the minimum value at which any analog stick input is ignored.\r\n * Note: This value should only be a value between 0 and 1.\r\n */\r\n public deadzoneDelta = 0.1;\r\n\r\n private _yAxisScale = 1.0;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that Yaxis (for right stick) should be inverted\r\n */\r\n public get invertYAxis() {\r\n return this._yAxisScale !== 1.0;\r\n }\r\n\r\n public set invertYAxis(value: boolean) {\r\n this._yAxisScale = value ? -1.0 : 1.0;\r\n }\r\n\r\n // private members\r\n private _onGamepadConnectedObserver: Nullable>;\r\n private _onGamepadDisconnectedObserver: Nullable>;\r\n private _cameraTransform: Matrix = Matrix.Identity();\r\n private _deltaTransform: Vector3 = Vector3.Zero();\r\n private _vector3: Vector3 = Vector3.Zero();\r\n private _vector2: Vector2 = Vector2.Zero();\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n */\r\n public attachControl(): void {\r\n const manager = this.camera.getScene().gamepadManager;\r\n this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {\r\n if (gamepad.type !== Gamepad.POSE_ENABLED) {\r\n // prioritize XBOX gamepads.\r\n if (!this.gamepad || gamepad.type === Gamepad.XBOX) {\r\n this.gamepad = gamepad;\r\n }\r\n }\r\n });\r\n\r\n this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add((gamepad) => {\r\n if (this.gamepad === gamepad) {\r\n this.gamepad = null;\r\n }\r\n });\r\n\r\n // check if there are already other controllers connected\r\n this.gamepad = manager.getGamepadByType(Gamepad.XBOX);\r\n // if no xbox controller was found, but there are gamepad controllers, take the first one\r\n if (!this.gamepad && manager.gamepads.length) {\r\n this.gamepad = manager.gamepads[0];\r\n }\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);\r\n this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);\r\n this.gamepad = null;\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (this.gamepad && this.gamepad.leftStick) {\r\n const camera = this.camera;\r\n const lsValues = this.gamepad.leftStick;\r\n if (this.gamepadMoveSensibility !== 0) {\r\n lsValues.x = Math.abs(lsValues.x) > this.deadzoneDelta ? lsValues.x / this.gamepadMoveSensibility : 0;\r\n lsValues.y = Math.abs(lsValues.y) > this.deadzoneDelta ? lsValues.y / this.gamepadMoveSensibility : 0;\r\n }\r\n\r\n let rsValues = this.gamepad.rightStick;\r\n if (rsValues && this.gamepadAngularSensibility !== 0) {\r\n rsValues.x = Math.abs(rsValues.x) > this.deadzoneDelta ? rsValues.x / this.gamepadAngularSensibility : 0;\r\n rsValues.y = (Math.abs(rsValues.y) > this.deadzoneDelta ? rsValues.y / this.gamepadAngularSensibility : 0) * this._yAxisScale;\r\n } else {\r\n rsValues = { x: 0, y: 0 };\r\n }\r\n\r\n if (!camera.rotationQuaternion) {\r\n Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, this._cameraTransform);\r\n } else {\r\n camera.rotationQuaternion.toRotationMatrix(this._cameraTransform);\r\n }\r\n\r\n const speed = camera._computeLocalCameraSpeed() * 50.0;\r\n this._vector3.copyFromFloats(lsValues.x * speed, 0, -lsValues.y * speed);\r\n\r\n Vector3.TransformCoordinatesToRef(this._vector3, this._cameraTransform, this._deltaTransform);\r\n camera.cameraDirection.addInPlace(this._deltaTransform);\r\n this._vector2.copyFromFloats(rsValues.y, rsValues.x);\r\n camera.cameraRotation.addInPlace(this._vector2);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"FreeCameraGamepadInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"gamepad\";\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"FreeCameraGamepadInput\"] = FreeCameraGamepadInput;\r\n","import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport { Gamepad } from \"../../Gamepads/gamepad\";\r\n/**\r\n * Manage the gamepad inputs to control an arc rotate camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class ArcRotateCameraGamepadInput implements ICameraInput {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: ArcRotateCamera;\r\n\r\n /**\r\n * Defines the gamepad the input is gathering event from.\r\n */\r\n public gamepad: Nullable;\r\n\r\n /**\r\n * Defines the gamepad rotation sensibility.\r\n * This is the threshold from when rotation starts to be accounted for to prevent jittering.\r\n */\r\n @serialize()\r\n public gamepadRotationSensibility = 80;\r\n\r\n /**\r\n * Defines the gamepad move sensibility.\r\n * This is the threshold from when moving starts to be accounted for for to prevent jittering.\r\n */\r\n @serialize()\r\n public gamepadMoveSensibility = 40;\r\n\r\n private _yAxisScale = 1.0;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that Yaxis (for right stick) should be inverted\r\n */\r\n public get invertYAxis() {\r\n return this._yAxisScale !== 1.0;\r\n }\r\n\r\n public set invertYAxis(value: boolean) {\r\n this._yAxisScale = value ? -1.0 : 1.0;\r\n }\r\n\r\n private _onGamepadConnectedObserver: Nullable>;\r\n private _onGamepadDisconnectedObserver: Nullable>;\r\n\r\n /**\r\n * Attach the input controls to a specific dom element to get the input from.\r\n */\r\n public attachControl(): void {\r\n const manager = this.camera.getScene().gamepadManager;\r\n this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {\r\n if (gamepad.type !== Gamepad.POSE_ENABLED) {\r\n // prioritize XBOX gamepads.\r\n if (!this.gamepad || gamepad.type === Gamepad.XBOX) {\r\n this.gamepad = gamepad;\r\n }\r\n }\r\n });\r\n\r\n this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add((gamepad) => {\r\n if (this.gamepad === gamepad) {\r\n this.gamepad = null;\r\n }\r\n });\r\n\r\n this.gamepad = manager.getGamepadByType(Gamepad.XBOX);\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);\r\n this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);\r\n this.gamepad = null;\r\n }\r\n\r\n /**\r\n * Update the current camera state depending on the inputs that have been used this frame.\r\n * This is a dynamically created lambda to avoid the performance penalty of looping for inputs in the render loop.\r\n */\r\n public checkInputs(): void {\r\n if (this.gamepad) {\r\n const camera = this.camera;\r\n const rsValues = this.gamepad.rightStick;\r\n\r\n if (rsValues) {\r\n if (rsValues.x != 0) {\r\n const normalizedRX = rsValues.x / this.gamepadRotationSensibility;\r\n if (normalizedRX != 0 && Math.abs(normalizedRX) > 0.005) {\r\n camera.inertialAlphaOffset += normalizedRX;\r\n }\r\n }\r\n\r\n if (rsValues.y != 0) {\r\n const normalizedRY = (rsValues.y / this.gamepadRotationSensibility) * this._yAxisScale;\r\n if (normalizedRY != 0 && Math.abs(normalizedRY) > 0.005) {\r\n camera.inertialBetaOffset += normalizedRY;\r\n }\r\n }\r\n }\r\n\r\n const lsValues = this.gamepad.leftStick;\r\n if (lsValues && lsValues.y != 0) {\r\n const normalizedLY = lsValues.y / this.gamepadMoveSensibility;\r\n if (normalizedLY != 0 && Math.abs(normalizedLY) > 0.005) {\r\n this.camera.inertialRadiusOffset -= normalizedLY;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current intput.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ArcRotateCameraGamepadInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input friendly name\r\n */\r\n public getSimpleName(): string {\r\n return \"gamepad\";\r\n }\r\n}\r\n\r\n(CameraInputTypes)[\"ArcRotateCameraGamepadInput\"] = ArcRotateCameraGamepadInput;\r\n","import type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { GamepadManager } from \"./gamepadManager\";\r\n\r\nimport { FreeCameraInputsManager } from \"../Cameras/freeCameraInputsManager\";\r\nimport { FreeCameraGamepadInput } from \"../Cameras/Inputs/freeCameraGamepadInput\";\r\nimport { ArcRotateCameraInputsManager } from \"../Cameras/arcRotateCameraInputsManager\";\r\nimport { ArcRotateCameraGamepadInput } from \"../Cameras/Inputs/arcRotateCameraGamepadInput\";\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal */\r\n _gamepadManager: Nullable;\r\n\r\n /**\r\n * Gets the gamepad manager associated with the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/input/gamepads\r\n */\r\n gamepadManager: GamepadManager;\r\n }\r\n}\r\n\r\nObject.defineProperty(Scene.prototype, \"gamepadManager\", {\r\n get: function (this: Scene) {\r\n if (!this._gamepadManager) {\r\n this._gamepadManager = new GamepadManager(this);\r\n let component = this._getComponent(SceneComponentConstants.NAME_GAMEPAD) as GamepadSystemSceneComponent;\r\n if (!component) {\r\n component = new GamepadSystemSceneComponent(this);\r\n this._addComponent(component);\r\n }\r\n }\r\n\r\n return this._gamepadManager;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\ndeclare module \"../Cameras/freeCameraInputsManager\" {\r\n /**\r\n * Interface representing a free camera inputs manager\r\n */\r\n export interface FreeCameraInputsManager {\r\n /**\r\n * Adds gamepad input support to the FreeCameraInputsManager.\r\n * @returns the FreeCameraInputsManager\r\n */\r\n addGamepad(): FreeCameraInputsManager;\r\n }\r\n}\r\n\r\n/**\r\n * Adds a gamepad to the free camera inputs manager\r\n */\r\nFreeCameraInputsManager.prototype.addGamepad = function (): FreeCameraInputsManager {\r\n this.add(new FreeCameraGamepadInput());\r\n return this;\r\n};\r\n\r\ndeclare module \"../Cameras/arcRotateCameraInputsManager\" {\r\n /**\r\n * Interface representing an arc rotate camera inputs manager\r\n */\r\n export interface ArcRotateCameraInputsManager {\r\n /**\r\n * Adds gamepad input support to the ArcRotateCamera InputManager.\r\n * @returns the camera inputs manager\r\n */\r\n addGamepad(): ArcRotateCameraInputsManager;\r\n }\r\n}\r\n\r\n/**\r\n * Adds a gamepad to the arc rotate camera inputs manager\r\n */\r\nArcRotateCameraInputsManager.prototype.addGamepad = function (): ArcRotateCameraInputsManager {\r\n this.add(new ArcRotateCameraGamepadInput());\r\n return this;\r\n};\r\n\r\n/**\r\n * Defines the gamepad scene component responsible to manage gamepads in a given scene\r\n */\r\nexport class GamepadSystemSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpfull to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_GAMEPAD;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._beforeCameraUpdateStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERAUPDATE_GAMEPAD, this, this._beforeCameraUpdate);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for gamepads\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n const gamepadManager = this.scene._gamepadManager;\r\n if (gamepadManager) {\r\n gamepadManager.dispose();\r\n this.scene._gamepadManager = null;\r\n }\r\n }\r\n\r\n private _beforeCameraUpdate(): void {\r\n const gamepadManager = this.scene._gamepadManager;\r\n\r\n if (gamepadManager && gamepadManager._isMonitoring) {\r\n gamepadManager._checkGamepadsStatus();\r\n }\r\n }\r\n}\r\n","import type { DeepImmutable, Nullable } from \"../types\";\r\nimport { Quaternion, Vector3, Vector2, Matrix } from \"../Maths/math.vector\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { _IAnimationState } from \"./animation\";\r\nimport { Animation } from \"./animation\";\r\nimport type { AnimationEvent } from \"./animationEvent\";\r\n\r\nimport type { Animatable } from \"./animatable\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { IAnimationKey } from \"./animationKey\";\r\nimport { Size } from \"../Maths/math.size\";\r\n\r\n// Static values to help the garbage collector\r\n\r\n// Quaternion\r\nconst _staticOffsetValueQuaternion: DeepImmutable = Object.freeze(new Quaternion(0, 0, 0, 0));\r\n\r\n// Vector3\r\nconst _staticOffsetValueVector3: DeepImmutable = Object.freeze(Vector3.Zero());\r\n\r\n// Vector2\r\nconst _staticOffsetValueVector2: DeepImmutable = Object.freeze(Vector2.Zero());\r\n\r\n// Size\r\nconst _staticOffsetValueSize: DeepImmutable = Object.freeze(Size.Zero());\r\n\r\n// Color3\r\nconst _staticOffsetValueColor3: DeepImmutable = Object.freeze(Color3.Black());\r\n\r\n/**\r\n * Defines a runtime animation\r\n */\r\nexport class RuntimeAnimation {\r\n private _events = new Array();\r\n\r\n /**\r\n * The current frame of the runtime animation\r\n */\r\n private _currentFrame: number = 0;\r\n\r\n /**\r\n * The animation used by the runtime animation\r\n */\r\n private _animation: Animation;\r\n\r\n /**\r\n * The target of the runtime animation\r\n */\r\n private _target: any;\r\n\r\n /**\r\n * The initiating animatable\r\n */\r\n private _host: Animatable;\r\n\r\n /**\r\n * The original value of the runtime animation\r\n */\r\n private _originalValue = new Array();\r\n\r\n /**\r\n * The original blend value of the runtime animation\r\n */\r\n private _originalBlendValue: Nullable = null;\r\n\r\n /**\r\n * The offsets cache of the runtime animation\r\n */\r\n private _offsetsCache: { [key: string]: any } = {};\r\n\r\n /**\r\n * The high limits cache of the runtime animation\r\n */\r\n private _highLimitsCache: { [key: string]: any } = {};\r\n\r\n /**\r\n * Specifies if the runtime animation has been stopped\r\n */\r\n private _stopped = false;\r\n\r\n /**\r\n * The blending factor of the runtime animation\r\n */\r\n private _blendingFactor = 0;\r\n\r\n /**\r\n * The BabylonJS scene\r\n */\r\n private _scene: Scene;\r\n\r\n /**\r\n * The current value of the runtime animation\r\n */\r\n private _currentValue: Nullable = null;\r\n\r\n /** @internal */\r\n public _animationState: _IAnimationState;\r\n\r\n /**\r\n * The active target of the runtime animation\r\n */\r\n private _activeTargets: any[];\r\n private _currentActiveTarget: Nullable = null;\r\n private _directTarget: Nullable = null;\r\n\r\n /**\r\n * The target path of the runtime animation\r\n */\r\n private _targetPath: string = \"\";\r\n\r\n /**\r\n * The weight of the runtime animation\r\n */\r\n private _weight = 1.0;\r\n\r\n /**\r\n * The absolute frame offset of the runtime animation\r\n */\r\n private _absoluteFrameOffset = 0;\r\n\r\n /**\r\n * The previous elapsed time (since start of animation) of the runtime animation\r\n */\r\n private _previousElapsedTime: number = 0;\r\n\r\n /**\r\n * The previous absolute frame of the runtime animation (meaning, without taking into account the from/to values, only the elapsed time and the fps)\r\n */\r\n private _previousAbsoluteFrame: number = 0;\r\n\r\n private _enableBlending: boolean;\r\n\r\n private _keys: IAnimationKey[];\r\n private _minFrame: number;\r\n private _maxFrame: number;\r\n private _minValue: any;\r\n private _maxValue: any;\r\n private _targetIsArray = false;\r\n\r\n /**\r\n * Gets the current frame of the runtime animation\r\n */\r\n public get currentFrame(): number {\r\n return this._currentFrame;\r\n }\r\n\r\n /**\r\n * Gets the weight of the runtime animation\r\n */\r\n public get weight(): number {\r\n return this._weight;\r\n }\r\n\r\n /**\r\n * Gets the current value of the runtime animation\r\n */\r\n public get currentValue(): any {\r\n return this._currentValue;\r\n }\r\n\r\n /**\r\n * Gets or sets the target path of the runtime animation\r\n */\r\n public get targetPath(): string {\r\n return this._targetPath;\r\n }\r\n\r\n /**\r\n * Gets the actual target of the runtime animation\r\n */\r\n public get target(): any {\r\n return this._currentActiveTarget;\r\n }\r\n\r\n /**\r\n * Gets the additive state of the runtime animation\r\n */\r\n public get isAdditive(): boolean {\r\n return this._host && this._host.isAdditive;\r\n }\r\n\r\n /** @internal */\r\n public _onLoop: () => void;\r\n\r\n /**\r\n * Create a new RuntimeAnimation object\r\n * @param target defines the target of the animation\r\n * @param animation defines the source animation object\r\n * @param scene defines the hosting scene\r\n * @param host defines the initiating Animatable\r\n */\r\n public constructor(target: any, animation: Animation, scene: Scene, host: Animatable) {\r\n this._animation = animation;\r\n this._target = target;\r\n this._scene = scene;\r\n this._host = host;\r\n this._activeTargets = [];\r\n\r\n animation._runtimeAnimations.push(this);\r\n\r\n // State\r\n this._animationState = {\r\n key: 0,\r\n repeatCount: 0,\r\n loopMode: this._getCorrectLoopMode(),\r\n };\r\n\r\n if (this._animation.dataType === Animation.ANIMATIONTYPE_MATRIX) {\r\n this._animationState.workValue = Matrix.Zero();\r\n }\r\n\r\n // Limits\r\n this._keys = this._animation.getKeys();\r\n this._minFrame = this._keys[0].frame;\r\n this._maxFrame = this._keys[this._keys.length - 1].frame;\r\n this._minValue = this._keys[0].value;\r\n this._maxValue = this._keys[this._keys.length - 1].value;\r\n\r\n // Add a start key at frame 0 if missing\r\n if (this._minFrame !== 0) {\r\n const newKey = { frame: 0, value: this._minValue };\r\n this._keys.splice(0, 0, newKey);\r\n }\r\n\r\n // Check data\r\n if (this._target instanceof Array) {\r\n let index = 0;\r\n for (const target of this._target) {\r\n this._preparePath(target, index);\r\n this._getOriginalValues(index);\r\n index++;\r\n }\r\n this._targetIsArray = true;\r\n } else {\r\n this._preparePath(this._target);\r\n this._getOriginalValues();\r\n this._targetIsArray = false;\r\n this._directTarget = this._activeTargets[0];\r\n }\r\n\r\n // Cloning events locally\r\n const events = animation.getEvents();\r\n if (events && events.length > 0) {\r\n events.forEach((e) => {\r\n this._events.push(e._clone());\r\n });\r\n }\r\n\r\n this._enableBlending = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.enableBlending : this._animation.enableBlending;\r\n }\r\n\r\n private _preparePath(target: any, targetIndex = 0) {\r\n const targetPropertyPath = this._animation.targetPropertyPath;\r\n\r\n if (targetPropertyPath.length > 1) {\r\n let property = target[targetPropertyPath[0]];\r\n\r\n for (let index = 1; index < targetPropertyPath.length - 1; index++) {\r\n property = property[targetPropertyPath[index]];\r\n }\r\n\r\n this._targetPath = targetPropertyPath[targetPropertyPath.length - 1];\r\n this._activeTargets[targetIndex] = property;\r\n } else {\r\n this._targetPath = targetPropertyPath[0];\r\n this._activeTargets[targetIndex] = target;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the animation from the runtime animation\r\n */\r\n public get animation(): Animation {\r\n return this._animation;\r\n }\r\n\r\n /**\r\n * Resets the runtime animation to the beginning\r\n * @param restoreOriginal defines whether to restore the target property to the original value\r\n */\r\n public reset(restoreOriginal = false): void {\r\n if (restoreOriginal) {\r\n if (this._target instanceof Array) {\r\n let index = 0;\r\n for (const target of this._target) {\r\n if (this._originalValue[index] !== undefined) {\r\n this._setValue(target, this._activeTargets[index], this._originalValue[index], -1, index);\r\n }\r\n index++;\r\n }\r\n } else {\r\n if (this._originalValue[0] !== undefined) {\r\n this._setValue(this._target, this._directTarget, this._originalValue[0], -1, 0);\r\n }\r\n }\r\n }\r\n\r\n this._offsetsCache = {};\r\n this._highLimitsCache = {};\r\n this._currentFrame = 0;\r\n this._blendingFactor = 0;\r\n\r\n // Events\r\n for (let index = 0; index < this._events.length; index++) {\r\n this._events[index].isDone = false;\r\n }\r\n }\r\n\r\n /**\r\n * Specifies if the runtime animation is stopped\r\n * @returns Boolean specifying if the runtime animation is stopped\r\n */\r\n public isStopped(): boolean {\r\n return this._stopped;\r\n }\r\n\r\n /**\r\n * Disposes of the runtime animation\r\n */\r\n public dispose(): void {\r\n const index = this._animation.runtimeAnimations.indexOf(this);\r\n\r\n if (index > -1) {\r\n this._animation.runtimeAnimations.splice(index, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Apply the interpolated value to the target\r\n * @param currentValue defines the value computed by the animation\r\n * @param weight defines the weight to apply to this value (Defaults to 1.0)\r\n */\r\n public setValue(currentValue: any, weight: number) {\r\n if (this._targetIsArray) {\r\n for (let index = 0; index < this._target.length; index++) {\r\n const target = this._target[index];\r\n this._setValue(target, this._activeTargets[index], currentValue, weight, index);\r\n }\r\n return;\r\n }\r\n this._setValue(this._target, this._directTarget, currentValue, weight, 0);\r\n }\r\n\r\n private _getOriginalValues(targetIndex = 0) {\r\n let originalValue: any;\r\n const target = this._activeTargets[targetIndex];\r\n\r\n if (target.getRestPose && this._targetPath === \"_matrix\") {\r\n // For bones\r\n originalValue = target.getRestPose();\r\n } else {\r\n originalValue = target[this._targetPath];\r\n }\r\n\r\n if (originalValue && originalValue.clone) {\r\n this._originalValue[targetIndex] = originalValue.clone();\r\n } else {\r\n this._originalValue[targetIndex] = originalValue;\r\n }\r\n }\r\n\r\n private _setValue(target: any, destination: any, currentValue: any, weight: number, targetIndex: number): void {\r\n // Set value\r\n this._currentActiveTarget = destination;\r\n\r\n this._weight = weight;\r\n\r\n if (this._enableBlending && this._blendingFactor <= 1.0) {\r\n if (!this._originalBlendValue) {\r\n const originalValue = destination[this._targetPath];\r\n\r\n if (originalValue.clone) {\r\n this._originalBlendValue = originalValue.clone();\r\n } else {\r\n this._originalBlendValue = originalValue;\r\n }\r\n }\r\n\r\n if (this._originalBlendValue.m) {\r\n // Matrix\r\n if (Animation.AllowMatrixDecomposeForInterpolation) {\r\n if (this._currentValue) {\r\n Matrix.DecomposeLerpToRef(this._originalBlendValue, currentValue, this._blendingFactor, this._currentValue);\r\n } else {\r\n this._currentValue = Matrix.DecomposeLerp(this._originalBlendValue, currentValue, this._blendingFactor);\r\n }\r\n } else {\r\n if (this._currentValue) {\r\n Matrix.LerpToRef(this._originalBlendValue, currentValue, this._blendingFactor, this._currentValue);\r\n } else {\r\n this._currentValue = Matrix.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);\r\n }\r\n }\r\n } else {\r\n this._currentValue = Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);\r\n }\r\n\r\n const blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;\r\n this._blendingFactor += blendingSpeed;\r\n } else {\r\n if (!this._currentValue) {\r\n if (currentValue?.clone) {\r\n this._currentValue = currentValue.clone();\r\n } else {\r\n this._currentValue = currentValue;\r\n }\r\n } else if (this._currentValue.copyFrom) {\r\n this._currentValue.copyFrom(currentValue);\r\n } else {\r\n this._currentValue = currentValue;\r\n }\r\n }\r\n\r\n if (weight !== -1.0) {\r\n this._scene._registerTargetForLateAnimationBinding(this, this._originalValue[targetIndex]);\r\n } else {\r\n destination[this._targetPath] = this._currentValue;\r\n }\r\n\r\n if (target.markAsDirty) {\r\n target.markAsDirty(this._animation.targetProperty);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the loop pmode of the runtime animation\r\n * @returns Loop Mode\r\n */\r\n private _getCorrectLoopMode(): number | undefined {\r\n if (this._target && this._target.animationPropertiesOverride) {\r\n return this._target.animationPropertiesOverride.loopMode;\r\n }\r\n\r\n return this._animation.loopMode;\r\n }\r\n\r\n /**\r\n * Move the current animation to a given frame\r\n * @param frame defines the frame to move to\r\n */\r\n public goToFrame(frame: number): void {\r\n const keys = this._animation.getKeys();\r\n\r\n if (frame < keys[0].frame) {\r\n frame = keys[0].frame;\r\n } else if (frame > keys[keys.length - 1].frame) {\r\n frame = keys[keys.length - 1].frame;\r\n }\r\n\r\n // Need to reset animation events\r\n const events = this._events;\r\n if (events.length) {\r\n for (let index = 0; index < events.length; index++) {\r\n if (!events[index].onlyOnce) {\r\n // reset events in the future\r\n events[index].isDone = events[index].frame < frame;\r\n }\r\n }\r\n }\r\n\r\n this._currentFrame = frame;\r\n const currentValue = this._animation._interpolate(frame, this._animationState);\r\n\r\n this.setValue(currentValue, -1);\r\n }\r\n\r\n /**\r\n * @internal Internal use only\r\n */\r\n public _prepareForSpeedRatioChange(newSpeedRatio: number): void {\r\n const newAbsoluteFrame = (this._previousElapsedTime * (this._animation.framePerSecond * newSpeedRatio)) / 1000.0;\r\n\r\n this._absoluteFrameOffset = this._previousAbsoluteFrame - newAbsoluteFrame;\r\n }\r\n\r\n /**\r\n * Execute the current animation\r\n * @param elapsedTimeSinceAnimationStart defines the elapsed time (in milliseconds) since the animation was started\r\n * @param from defines the lower frame of the animation range\r\n * @param to defines the upper frame of the animation range\r\n * @param loop defines if the current animation must loop\r\n * @param speedRatio defines the current speed ratio\r\n * @param weight defines the weight of the animation (default is -1 so no weight)\r\n * @returns a boolean indicating if the animation is running\r\n */\r\n public animate(elapsedTimeSinceAnimationStart: number, from: number, to: number, loop: boolean, speedRatio: number, weight = -1.0): boolean {\r\n const animation = this._animation;\r\n const targetPropertyPath = animation.targetPropertyPath;\r\n if (!targetPropertyPath || targetPropertyPath.length < 1) {\r\n this._stopped = true;\r\n return false;\r\n }\r\n\r\n let returnValue = true;\r\n\r\n // Check limits\r\n if (from < this._minFrame || from > this._maxFrame) {\r\n from = this._minFrame;\r\n }\r\n if (to < this._minFrame || to > this._maxFrame) {\r\n to = this._maxFrame;\r\n }\r\n\r\n const frameRange = to - from;\r\n let offsetValue: any;\r\n\r\n // Compute the frame according to the elapsed time and the fps of the animation (\"from\" and \"to\" are not factored in!)\r\n let absoluteFrame = (elapsedTimeSinceAnimationStart * (animation.framePerSecond * speedRatio)) / 1000.0 + this._absoluteFrameOffset;\r\n let highLimitValue = 0;\r\n\r\n // Apply the yoyo function if required\r\n if (loop && this._animationState.loopMode === Animation.ANIMATIONLOOPMODE_YOYO) {\r\n const position = (absoluteFrame - from) / frameRange;\r\n\r\n // Apply the yoyo curve\r\n const yoyoPosition = Math.abs(Math.sin(position * Math.PI));\r\n\r\n // Map the yoyo position back to the range\r\n absoluteFrame = yoyoPosition * frameRange + from;\r\n }\r\n\r\n this._previousElapsedTime = elapsedTimeSinceAnimationStart;\r\n this._previousAbsoluteFrame = absoluteFrame;\r\n\r\n if (!loop && to >= from && absoluteFrame >= frameRange) {\r\n // If we are out of range and not looping get back to caller\r\n returnValue = false;\r\n highLimitValue = animation._getKeyValue(this._maxValue);\r\n } else if (!loop && from >= to && absoluteFrame <= frameRange) {\r\n returnValue = false;\r\n highLimitValue = animation._getKeyValue(this._minValue);\r\n } else if (this._animationState.loopMode !== Animation.ANIMATIONLOOPMODE_CYCLE) {\r\n const keyOffset = to.toString() + from.toString();\r\n if (!this._offsetsCache[keyOffset]) {\r\n this._animationState.repeatCount = 0;\r\n this._animationState.loopMode = Animation.ANIMATIONLOOPMODE_CYCLE; // force a specific codepath in animation._interpolate()!\r\n const fromValue = animation._interpolate(from, this._animationState);\r\n const toValue = animation._interpolate(to, this._animationState);\r\n\r\n this._animationState.loopMode = this._getCorrectLoopMode();\r\n switch (animation.dataType) {\r\n // Float\r\n case Animation.ANIMATIONTYPE_FLOAT:\r\n this._offsetsCache[keyOffset] = toValue - fromValue;\r\n break;\r\n // Quaternion\r\n case Animation.ANIMATIONTYPE_QUATERNION:\r\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\r\n break;\r\n // Vector3\r\n case Animation.ANIMATIONTYPE_VECTOR3:\r\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\r\n break;\r\n // Vector2\r\n case Animation.ANIMATIONTYPE_VECTOR2:\r\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\r\n break;\r\n // Size\r\n case Animation.ANIMATIONTYPE_SIZE:\r\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\r\n break;\r\n // Color3\r\n case Animation.ANIMATIONTYPE_COLOR3:\r\n this._offsetsCache[keyOffset] = toValue.subtract(fromValue);\r\n break;\r\n default:\r\n break;\r\n }\r\n\r\n this._highLimitsCache[keyOffset] = toValue;\r\n }\r\n\r\n highLimitValue = this._highLimitsCache[keyOffset];\r\n offsetValue = this._offsetsCache[keyOffset];\r\n }\r\n\r\n if (offsetValue === undefined) {\r\n switch (animation.dataType) {\r\n // Float\r\n case Animation.ANIMATIONTYPE_FLOAT:\r\n offsetValue = 0;\r\n break;\r\n // Quaternion\r\n case Animation.ANIMATIONTYPE_QUATERNION:\r\n offsetValue = _staticOffsetValueQuaternion;\r\n break;\r\n // Vector3\r\n case Animation.ANIMATIONTYPE_VECTOR3:\r\n offsetValue = _staticOffsetValueVector3;\r\n break;\r\n // Vector2\r\n case Animation.ANIMATIONTYPE_VECTOR2:\r\n offsetValue = _staticOffsetValueVector2;\r\n break;\r\n // Size\r\n case Animation.ANIMATIONTYPE_SIZE:\r\n offsetValue = _staticOffsetValueSize;\r\n break;\r\n // Color3\r\n case Animation.ANIMATIONTYPE_COLOR3:\r\n offsetValue = _staticOffsetValueColor3;\r\n }\r\n }\r\n\r\n // Compute value\r\n let currentFrame: number;\r\n\r\n if (this._host && this._host.syncRoot) {\r\n // If we must sync with an animatable, calculate the current frame based on the frame of the root animatable\r\n const syncRoot = this._host.syncRoot;\r\n const hostNormalizedFrame = (syncRoot.masterFrame - syncRoot.fromFrame) / (syncRoot.toFrame - syncRoot.fromFrame);\r\n currentFrame = from + frameRange * hostNormalizedFrame;\r\n } else {\r\n if ((absoluteFrame > 0 && from > to) || (absoluteFrame < 0 && from < to)) {\r\n currentFrame = returnValue && frameRange !== 0 ? to + (absoluteFrame % frameRange) : from;\r\n } else {\r\n currentFrame = returnValue && frameRange !== 0 ? from + (absoluteFrame % frameRange) : to;\r\n }\r\n }\r\n\r\n const events = this._events;\r\n\r\n // Reset event/state if looping\r\n if ((speedRatio > 0 && this.currentFrame > currentFrame) || (speedRatio < 0 && this.currentFrame < currentFrame)) {\r\n this._onLoop();\r\n\r\n // Need to reset animation events\r\n for (let index = 0; index < events.length; index++) {\r\n if (!events[index].onlyOnce) {\r\n // reset event, the animation is looping\r\n events[index].isDone = false;\r\n }\r\n }\r\n\r\n this._animationState.key = speedRatio > 0 ? 0 : animation.getKeys().length - 1;\r\n }\r\n this._currentFrame = currentFrame;\r\n this._animationState.repeatCount = frameRange === 0 ? 0 : (absoluteFrame / frameRange) >> 0;\r\n this._animationState.highLimitValue = highLimitValue;\r\n this._animationState.offsetValue = offsetValue;\r\n\r\n const currentValue = animation._interpolate(currentFrame, this._animationState);\r\n\r\n // Set value\r\n this.setValue(currentValue, weight);\r\n\r\n // Check events\r\n if (events.length) {\r\n for (let index = 0; index < events.length; index++) {\r\n // Make sure current frame has passed event frame and that event frame is within the current range\r\n // Also, handle both forward and reverse animations\r\n if (\r\n (frameRange > 0 && currentFrame >= events[index].frame && events[index].frame >= from) ||\r\n (frameRange < 0 && currentFrame <= events[index].frame && events[index].frame <= from)\r\n ) {\r\n const event = events[index];\r\n if (!event.isDone) {\r\n // If event should be done only once, remove it.\r\n if (event.onlyOnce) {\r\n events.splice(index, 1);\r\n index--;\r\n }\r\n event.isDone = true;\r\n event.action(currentFrame);\r\n } // Don't do anything if the event has already been done.\r\n }\r\n }\r\n }\r\n\r\n if (!returnValue) {\r\n this._stopped = true;\r\n }\r\n\r\n return returnValue;\r\n }\r\n}\r\n","import type { Skeleton } from \"./skeleton\";\r\nimport { Vector3, Quaternion, Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\nimport { Node } from \"../node\";\r\nimport { Space } from \"../Maths/math.axis\";\r\n\r\nimport type { Animation } from \"../Animations/animation\";\r\nimport type { AnimationPropertiesOverride } from \"../Animations/animationPropertiesOverride\";\r\n\r\n/**\r\n * Class used to store bone information\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons\r\n */\r\nexport class Bone extends Node {\r\n private static _TmpVecs: Vector3[] = ArrayTools.BuildArray(2, Vector3.Zero);\r\n private static _TmpQuat = Quaternion.Identity();\r\n private static _TmpMats: Matrix[] = ArrayTools.BuildArray(5, Matrix.Identity);\r\n\r\n /**\r\n * Gets the list of child bones\r\n */\r\n public children = new Array();\r\n\r\n /** Gets the animations associated with this bone */\r\n public animations = new Array();\r\n\r\n /**\r\n * Gets or sets bone length\r\n */\r\n public length: number;\r\n\r\n /**\r\n * @internal Internal only\r\n * Set this value to map this bone to a different index in the transform matrices\r\n * Set this value to -1 to exclude the bone from the transform matrices\r\n */\r\n public _index: Nullable = null;\r\n\r\n private _skeleton: Skeleton;\r\n private _localMatrix: Matrix; // transformation of the bone, in local space\r\n private _absoluteMatrix: Matrix; // transformation of the bone, in world space (relative to the skeleton root)\r\n private _bindMatrix: Matrix; // the bind matrix, in local space\r\n private _absoluteBindMatrix: Matrix; // the bind matrix, in world space (relative to the skeleton root)\r\n private _absoluteInverseBindMatrix: Matrix; // the inverse of the bind matrix, in world space (relative to the skeleton root)\r\n private _finalMatrix: Matrix; // the final matrix used to transform vertices of the mesh according to the bone, in world space (relative to the skeleton root). It is the multiplication of _absoluteInverseBindMatrix with _absoluteMatrix.\r\n private _restMatrix: Matrix; // a matrix for the exclusive use of the end user (not used internally by the framework), in local space\r\n private _scalingDeterminant = 1;\r\n\r\n private _localScaling: Vector3;\r\n private _localRotation: Quaternion;\r\n private _localPosition: Vector3;\r\n private _needToDecompose = true;\r\n private _needToCompose = false;\r\n\r\n /** @internal */\r\n public _linkedTransformNode: Nullable = null;\r\n\r\n /** @internal */\r\n public _waitingTransformNodeId: Nullable = null;\r\n\r\n /** @internal */\r\n get _matrix(): Matrix {\r\n this._compose();\r\n return this._localMatrix;\r\n }\r\n\r\n /** @internal */\r\n set _matrix(value: Matrix) {\r\n // skip if the matrices are the same\r\n if (value.updateFlag === this._localMatrix.updateFlag && !this._needToCompose) {\r\n return;\r\n }\r\n\r\n this._needToCompose = false; // in case there was a pending compose\r\n\r\n this._localMatrix.copyFrom(value);\r\n this._markAsDirtyAndDecompose();\r\n }\r\n\r\n /**\r\n * Create a new bone\r\n * @param name defines the bone name\r\n * @param skeleton defines the parent skeleton\r\n * @param parentBone defines the parent (can be null if the bone is the root)\r\n * @param localMatrix defines the local matrix (default: identity)\r\n * @param restMatrix defines the rest matrix (default: localMatrix)\r\n * @param bindMatrix defines the bind matrix (default: localMatrix)\r\n * @param index defines index of the bone in the hierarchy (default: null)\r\n */\r\n constructor(\r\n /**\r\n * defines the bone name\r\n */\r\n public name: string,\r\n skeleton: Skeleton,\r\n parentBone: Nullable = null,\r\n localMatrix: Nullable = null,\r\n restMatrix: Nullable = null,\r\n bindMatrix: Nullable = null,\r\n index: Nullable = null\r\n ) {\r\n super(name, skeleton.getScene());\r\n this._skeleton = skeleton;\r\n this._localMatrix = localMatrix?.clone() ?? Matrix.Identity();\r\n this._restMatrix = restMatrix ?? this._localMatrix.clone();\r\n this._bindMatrix = bindMatrix ?? this._localMatrix.clone();\r\n this._index = index;\r\n\r\n this._absoluteMatrix = new Matrix();\r\n this._absoluteBindMatrix = new Matrix();\r\n this._absoluteInverseBindMatrix = new Matrix();\r\n this._finalMatrix = new Matrix();\r\n\r\n skeleton.bones.push(this);\r\n\r\n this.setParent(parentBone, false);\r\n\r\n this._updateAbsoluteBindMatrices();\r\n }\r\n\r\n /**\r\n * Gets the current object class name.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"Bone\";\r\n }\r\n\r\n // Members\r\n\r\n /**\r\n * Gets the parent skeleton\r\n * @returns a skeleton\r\n */\r\n public getSkeleton(): Skeleton {\r\n return this._skeleton;\r\n }\r\n\r\n public get parent(): Bone {\r\n return this._parentNode as Bone;\r\n }\r\n\r\n /**\r\n * Gets parent bone\r\n * @returns a bone or null if the bone is the root of the bone hierarchy\r\n */\r\n public getParent(): Nullable {\r\n return this.parent;\r\n }\r\n\r\n /**\r\n * Returns an array containing the children of the bone\r\n * @returns an array containing the children of the bone (can be empty if the bone has no children)\r\n */\r\n public getChildren(): Array {\r\n return this.children;\r\n }\r\n\r\n /**\r\n * Gets the node index in matrix array generated for rendering\r\n * @returns the node index\r\n */\r\n public getIndex(): number {\r\n return this._index === null ? this.getSkeleton().bones.indexOf(this) : this._index;\r\n }\r\n\r\n public set parent(newParent: Nullable) {\r\n this.setParent(newParent);\r\n }\r\n\r\n /**\r\n * Sets the parent bone\r\n * @param parent defines the parent (can be null if the bone is the root)\r\n * @param updateAbsoluteBindMatrices defines if the absolute bind and absolute inverse bind matrices must be updated\r\n */\r\n public setParent(parent: Nullable, updateAbsoluteBindMatrices: boolean = true): void {\r\n if (this.parent === parent) {\r\n return;\r\n }\r\n\r\n if (this.parent) {\r\n const index = this.parent.children.indexOf(this);\r\n if (index !== -1) {\r\n this.parent.children.splice(index, 1);\r\n }\r\n }\r\n\r\n this._parentNode = parent;\r\n\r\n if (this.parent) {\r\n this.parent.children.push(this);\r\n }\r\n\r\n if (updateAbsoluteBindMatrices) {\r\n this._updateAbsoluteBindMatrices();\r\n }\r\n\r\n this.markAsDirty();\r\n }\r\n\r\n /**\r\n * Gets the local matrix\r\n * @returns the local matrix\r\n */\r\n public getLocalMatrix(): Matrix {\r\n this._compose();\r\n return this._localMatrix;\r\n }\r\n\r\n /**\r\n * Gets the bind matrix\r\n * @returns the bind matrix\r\n */\r\n public getBindMatrix(): Matrix {\r\n return this._bindMatrix;\r\n }\r\n\r\n /**\r\n * Gets the bind matrix.\r\n * @returns the bind matrix\r\n * @deprecated Please use getBindMatrix instead\r\n */\r\n public getBaseMatrix(): Matrix {\r\n return this.getBindMatrix();\r\n }\r\n\r\n /**\r\n * Gets the rest matrix\r\n * @returns the rest matrix\r\n */\r\n public getRestMatrix(): Matrix {\r\n return this._restMatrix;\r\n }\r\n\r\n /**\r\n * Gets the rest matrix\r\n * @returns the rest matrix\r\n * @deprecated Please use getRestMatrix instead\r\n */\r\n public getRestPose(): Matrix {\r\n return this.getRestMatrix();\r\n }\r\n\r\n /**\r\n * Sets the rest matrix\r\n * @param matrix the local-space rest matrix to set for this bone\r\n */\r\n public setRestMatrix(matrix: Matrix): void {\r\n this._restMatrix.copyFrom(matrix);\r\n }\r\n\r\n /**\r\n * Sets the rest matrix\r\n * @param matrix the local-space rest to set for this bone\r\n * @deprecated Please use setRestMatrix instead\r\n */\r\n public setRestPose(matrix: Matrix): void {\r\n this.setRestMatrix(matrix);\r\n }\r\n\r\n /**\r\n * Gets the bind matrix\r\n * @returns the bind matrix\r\n * @deprecated Please use getBindMatrix instead\r\n */\r\n public getBindPose(): Matrix {\r\n return this.getBindMatrix();\r\n }\r\n\r\n /**\r\n * Sets the bind matrix\r\n * This will trigger a recomputation of the absolute bind and absolute inverse bind matrices for this bone and its children\r\n * Note that the local matrix will also be set with the matrix passed in parameter!\r\n * @param matrix the local-space bind matrix to set for this bone\r\n */\r\n public setBindMatrix(matrix: Matrix): void {\r\n this.updateMatrix(matrix);\r\n }\r\n\r\n /**\r\n * Sets the bind matrix\r\n * @param matrix the local-space bind to set for this bone\r\n * @deprecated Please use setBindMatrix instead\r\n */\r\n public setBindPose(matrix: Matrix): void {\r\n this.setBindMatrix(matrix);\r\n }\r\n\r\n /**\r\n * Gets the matrix used to store the final world transformation of the bone (ie. the matrix sent to shaders)\r\n */\r\n public getFinalMatrix(): Matrix {\r\n return this._finalMatrix;\r\n }\r\n\r\n /**\r\n * Gets the matrix used to store the final world transformation of the bone (ie. the matrix sent to shaders)\r\n * @deprecated Please use getFinalMatrix instead\r\n */\r\n public getWorldMatrix(): Matrix {\r\n return this.getFinalMatrix();\r\n }\r\n\r\n /**\r\n * Sets the local matrix to the rest matrix\r\n */\r\n public returnToRest(): void {\r\n if (this._linkedTransformNode) {\r\n const localScaling = TmpVectors.Vector3[0];\r\n const localRotation = TmpVectors.Quaternion[0];\r\n const localPosition = TmpVectors.Vector3[1];\r\n\r\n this.getRestMatrix().decompose(localScaling, localRotation, localPosition);\r\n\r\n this._linkedTransformNode.position.copyFrom(localPosition);\r\n this._linkedTransformNode.rotationQuaternion = this._linkedTransformNode.rotationQuaternion ?? Quaternion.Identity();\r\n this._linkedTransformNode.rotationQuaternion.copyFrom(localRotation);\r\n this._linkedTransformNode.scaling.copyFrom(localScaling);\r\n } else {\r\n this._matrix = this._restMatrix;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the inverse of the bind matrix, in world space (relative to the skeleton root)\r\n * @returns the inverse bind matrix, in world space\r\n */\r\n public getAbsoluteInverseBindMatrix(): Matrix {\r\n return this._absoluteInverseBindMatrix;\r\n }\r\n\r\n /**\r\n * Gets the inverse of the bind matrix, in world space (relative to the skeleton root)\r\n * @returns the inverse bind matrix, in world space\r\n * @deprecated Please use getAbsoluteInverseBindMatrix instead\r\n */\r\n public getInvertedAbsoluteTransform(): Matrix {\r\n return this.getAbsoluteInverseBindMatrix();\r\n }\r\n\r\n /**\r\n * Gets the bone matrix, in world space (relative to the skeleton root)\r\n * @returns the bone matrix, in world space\r\n */\r\n public getAbsoluteMatrix(): Matrix {\r\n return this._absoluteMatrix;\r\n }\r\n\r\n /**\r\n * Gets the bone matrix, in world space (relative to the skeleton root)\r\n * @returns the bone matrix, in world space\r\n * @deprecated Please use getAbsoluteMatrix instead\r\n */\r\n public getAbsoluteTransform(): Matrix {\r\n return this._absoluteMatrix;\r\n }\r\n\r\n /**\r\n * Links with the given transform node.\r\n * The local matrix of this bone is overwritten by the transform of the node every frame.\r\n * @param transformNode defines the transform node to link to\r\n */\r\n public linkTransformNode(transformNode: Nullable): void {\r\n if (this._linkedTransformNode) {\r\n this._skeleton._numBonesWithLinkedTransformNode--;\r\n }\r\n\r\n this._linkedTransformNode = transformNode;\r\n\r\n if (this._linkedTransformNode) {\r\n this._skeleton._numBonesWithLinkedTransformNode++;\r\n }\r\n }\r\n\r\n // Properties (matches TransformNode properties)\r\n\r\n /**\r\n * Gets the node used to drive the bone's transformation\r\n * @returns a transform node or null\r\n */\r\n public getTransformNode() {\r\n return this._linkedTransformNode;\r\n }\r\n\r\n /** Gets or sets current position (in local space) */\r\n public get position(): Vector3 {\r\n this._decompose();\r\n return this._localPosition;\r\n }\r\n\r\n public set position(newPosition: Vector3) {\r\n this._decompose();\r\n this._localPosition.copyFrom(newPosition);\r\n\r\n this._markAsDirtyAndCompose();\r\n }\r\n\r\n /** Gets or sets current rotation (in local space) */\r\n public get rotation(): Vector3 {\r\n return this.getRotation();\r\n }\r\n\r\n public set rotation(newRotation: Vector3) {\r\n this.setRotation(newRotation);\r\n }\r\n\r\n /** Gets or sets current rotation quaternion (in local space) */\r\n public get rotationQuaternion() {\r\n this._decompose();\r\n return this._localRotation;\r\n }\r\n\r\n public set rotationQuaternion(newRotation: Quaternion) {\r\n this.setRotationQuaternion(newRotation);\r\n }\r\n\r\n /** Gets or sets current scaling (in local space) */\r\n public get scaling(): Vector3 {\r\n return this.getScale();\r\n }\r\n\r\n public set scaling(newScaling: Vector3) {\r\n this.setScale(newScaling);\r\n }\r\n\r\n /**\r\n * Gets the animation properties override\r\n */\r\n public get animationPropertiesOverride(): Nullable {\r\n return this._skeleton.animationPropertiesOverride;\r\n }\r\n\r\n // Methods\r\n private _decompose() {\r\n if (!this._needToDecompose) {\r\n return;\r\n }\r\n\r\n this._needToDecompose = false;\r\n\r\n if (!this._localScaling) {\r\n this._localScaling = Vector3.Zero();\r\n this._localRotation = Quaternion.Zero();\r\n this._localPosition = Vector3.Zero();\r\n }\r\n this._localMatrix.decompose(this._localScaling, this._localRotation, this._localPosition);\r\n }\r\n\r\n private _compose() {\r\n if (!this._needToCompose) {\r\n return;\r\n }\r\n\r\n if (!this._localScaling) {\r\n this._needToCompose = false;\r\n return;\r\n }\r\n\r\n this._needToCompose = false;\r\n Matrix.ComposeToRef(this._localScaling, this._localRotation, this._localPosition, this._localMatrix);\r\n }\r\n\r\n /**\r\n * Update the bind (and optionally the local) matrix\r\n * @param bindMatrix defines the new matrix to set to the bind/local matrix, in local space\r\n * @param updateAbsoluteBindMatrices defines if the absolute bind and absolute inverse bind matrices must be recomputed (default: true)\r\n * @param updateLocalMatrix defines if the local matrix should also be updated with the matrix passed in parameter (default: true)\r\n */\r\n public updateMatrix(bindMatrix: Matrix, updateAbsoluteBindMatrices = true, updateLocalMatrix = true): void {\r\n this._bindMatrix.copyFrom(bindMatrix);\r\n\r\n if (updateAbsoluteBindMatrices) {\r\n this._updateAbsoluteBindMatrices();\r\n }\r\n\r\n if (updateLocalMatrix) {\r\n this._matrix = bindMatrix;\r\n } else {\r\n this.markAsDirty();\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _updateAbsoluteBindMatrices(bindMatrix?: Matrix, updateChildren = true): void {\r\n if (!bindMatrix) {\r\n bindMatrix = this._bindMatrix;\r\n }\r\n\r\n if (this.parent) {\r\n bindMatrix.multiplyToRef(this.parent._absoluteBindMatrix, this._absoluteBindMatrix);\r\n } else {\r\n this._absoluteBindMatrix.copyFrom(bindMatrix);\r\n }\r\n\r\n this._absoluteBindMatrix.invertToRef(this._absoluteInverseBindMatrix);\r\n\r\n if (updateChildren) {\r\n for (let index = 0; index < this.children.length; index++) {\r\n this.children[index]._updateAbsoluteBindMatrices();\r\n }\r\n }\r\n\r\n this._scalingDeterminant = this._absoluteBindMatrix.determinant() < 0 ? -1 : 1;\r\n }\r\n\r\n /**\r\n * Flag the bone as dirty (Forcing it to update everything)\r\n * @returns this bone\r\n */\r\n public markAsDirty(): Bone {\r\n this._currentRenderId++;\r\n this._childUpdateId++;\r\n this._skeleton._markAsDirty();\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n public _markAsDirtyAndCompose() {\r\n this.markAsDirty();\r\n this._needToCompose = true;\r\n }\r\n\r\n private _markAsDirtyAndDecompose() {\r\n this.markAsDirty();\r\n this._needToDecompose = true;\r\n }\r\n\r\n private _updatePosition(vec: Vector3, space = Space.LOCAL, tNode?: TransformNode, translationMode = true): void {\r\n const lm = this.getLocalMatrix();\r\n\r\n if (space == Space.LOCAL) {\r\n if (translationMode) {\r\n lm.addAtIndex(12, vec.x);\r\n lm.addAtIndex(13, vec.y);\r\n lm.addAtIndex(14, vec.z);\r\n } else {\r\n lm.setTranslationFromFloats(vec.x, vec.y, vec.z);\r\n }\r\n } else {\r\n let wm: Nullable = null;\r\n\r\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\r\n if (tNode) {\r\n wm = tNode.getWorldMatrix();\r\n }\r\n\r\n this._skeleton.computeAbsoluteMatrices();\r\n\r\n const tmat = Bone._TmpMats[0];\r\n const tvec = Bone._TmpVecs[0];\r\n\r\n if (this.parent) {\r\n if (tNode && wm) {\r\n tmat.copyFrom(this.parent.getAbsoluteMatrix());\r\n tmat.multiplyToRef(wm, tmat);\r\n } else {\r\n tmat.copyFrom(this.parent.getAbsoluteMatrix());\r\n }\r\n } else {\r\n Matrix.IdentityToRef(tmat);\r\n }\r\n\r\n if (translationMode) {\r\n tmat.setTranslationFromFloats(0, 0, 0);\r\n }\r\n tmat.invert();\r\n Vector3.TransformCoordinatesToRef(vec, tmat, tvec);\r\n\r\n if (translationMode) {\r\n lm.addAtIndex(12, tvec.x);\r\n lm.addAtIndex(13, tvec.y);\r\n lm.addAtIndex(14, tvec.z);\r\n } else {\r\n lm.setTranslationFromFloats(tvec.x, tvec.y, tvec.z);\r\n }\r\n }\r\n\r\n this._markAsDirtyAndDecompose();\r\n }\r\n\r\n /**\r\n * Translate the bone in local or world space\r\n * @param vec The amount to translate the bone\r\n * @param space The space that the translation is in (default: Space.LOCAL)\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public translate(vec: Vector3, space = Space.LOCAL, tNode?: TransformNode): void {\r\n this._updatePosition(vec, space, tNode, true);\r\n }\r\n\r\n /**\r\n * Set the position of the bone in local or world space\r\n * @param position The position to set the bone\r\n * @param space The space that the position is in (default: Space.LOCAL)\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setPosition(position: Vector3, space = Space.LOCAL, tNode?: TransformNode): void {\r\n this._updatePosition(position, space, tNode, false);\r\n }\r\n\r\n /**\r\n * Set the absolute position of the bone (world space)\r\n * @param position The position to set the bone\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setAbsolutePosition(position: Vector3, tNode?: TransformNode) {\r\n this.setPosition(position, Space.WORLD, tNode);\r\n }\r\n\r\n /**\r\n * Scale the bone on the x, y and z axes (in local space)\r\n * @param x The amount to scale the bone on the x axis\r\n * @param y The amount to scale the bone on the y axis\r\n * @param z The amount to scale the bone on the z axis\r\n * @param scaleChildren sets this to true if children of the bone should be scaled as well (false by default)\r\n */\r\n public scale(x: number, y: number, z: number, scaleChildren = false): void {\r\n const locMat = this.getLocalMatrix();\r\n\r\n // Apply new scaling on top of current local matrix\r\n const scaleMat = Bone._TmpMats[0];\r\n Matrix.ScalingToRef(x, y, z, scaleMat);\r\n scaleMat.multiplyToRef(locMat, locMat);\r\n\r\n // Invert scaling matrix and apply the inverse to all children\r\n scaleMat.invert();\r\n\r\n for (const child of this.children) {\r\n const cm = child.getLocalMatrix();\r\n cm.multiplyToRef(scaleMat, cm);\r\n cm.multiplyAtIndex(12, x);\r\n cm.multiplyAtIndex(13, y);\r\n cm.multiplyAtIndex(14, z);\r\n\r\n child._markAsDirtyAndDecompose();\r\n }\r\n\r\n this._markAsDirtyAndDecompose();\r\n\r\n if (scaleChildren) {\r\n for (const child of this.children) {\r\n child.scale(x, y, z, scaleChildren);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Set the bone scaling in local space\r\n * @param scale defines the scaling vector\r\n */\r\n public setScale(scale: Vector3): void {\r\n this._decompose();\r\n this._localScaling.copyFrom(scale);\r\n this._markAsDirtyAndCompose();\r\n }\r\n\r\n /**\r\n * Gets the current scaling in local space\r\n * @returns the current scaling vector\r\n */\r\n public getScale(): Vector3 {\r\n this._decompose();\r\n return this._localScaling;\r\n }\r\n\r\n /**\r\n * Gets the current scaling in local space and stores it in a target vector\r\n * @param result defines the target vector\r\n */\r\n public getScaleToRef(result: Vector3) {\r\n this._decompose();\r\n result.copyFrom(this._localScaling);\r\n }\r\n\r\n /**\r\n * Set the yaw, pitch, and roll of the bone in local or world space\r\n * @param yaw The rotation of the bone on the y axis\r\n * @param pitch The rotation of the bone on the x axis\r\n * @param roll The rotation of the bone on the z axis\r\n * @param space The space that the axes of rotation are in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setYawPitchRoll(yaw: number, pitch: number, roll: number, space = Space.LOCAL, tNode?: TransformNode): void {\r\n if (space === Space.LOCAL) {\r\n const quat = Bone._TmpQuat;\r\n Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, quat);\r\n this.setRotationQuaternion(quat, space, tNode);\r\n return;\r\n }\r\n\r\n const rotMatInv = Bone._TmpMats[0];\r\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\r\n return;\r\n }\r\n\r\n const rotMat = Bone._TmpMats[1];\r\n Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);\r\n\r\n rotMatInv.multiplyToRef(rotMat, rotMat);\r\n this._rotateWithMatrix(rotMat, space, tNode);\r\n }\r\n\r\n /**\r\n * Add a rotation to the bone on an axis in local or world space\r\n * @param axis The axis to rotate the bone on\r\n * @param amount The amount to rotate the bone\r\n * @param space The space that the axis is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public rotate(axis: Vector3, amount: number, space = Space.LOCAL, tNode?: TransformNode): void {\r\n const rmat = Bone._TmpMats[0];\r\n rmat.setTranslationFromFloats(0, 0, 0);\r\n Matrix.RotationAxisToRef(axis, amount, rmat);\r\n this._rotateWithMatrix(rmat, space, tNode);\r\n }\r\n\r\n /**\r\n * Set the rotation of the bone to a particular axis angle in local or world space\r\n * @param axis The axis to rotate the bone on\r\n * @param angle The angle that the bone should be rotated to\r\n * @param space The space that the axis is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setAxisAngle(axis: Vector3, angle: number, space = Space.LOCAL, tNode?: TransformNode): void {\r\n if (space === Space.LOCAL) {\r\n const quat = Bone._TmpQuat;\r\n Quaternion.RotationAxisToRef(axis, angle, quat);\r\n\r\n this.setRotationQuaternion(quat, space, tNode);\r\n return;\r\n }\r\n\r\n const rotMatInv = Bone._TmpMats[0];\r\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\r\n return;\r\n }\r\n\r\n const rotMat = Bone._TmpMats[1];\r\n Matrix.RotationAxisToRef(axis, angle, rotMat);\r\n\r\n rotMatInv.multiplyToRef(rotMat, rotMat);\r\n this._rotateWithMatrix(rotMat, space, tNode);\r\n }\r\n\r\n /**\r\n * Set the euler rotation of the bone in local or world space\r\n * @param rotation The euler rotation that the bone should be set to\r\n * @param space The space that the rotation is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setRotation(rotation: Vector3, space = Space.LOCAL, tNode?: TransformNode): void {\r\n this.setYawPitchRoll(rotation.y, rotation.x, rotation.z, space, tNode);\r\n }\r\n\r\n /**\r\n * Set the quaternion rotation of the bone in local or world space\r\n * @param quat The quaternion rotation that the bone should be set to\r\n * @param space The space that the rotation is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setRotationQuaternion(quat: Quaternion, space = Space.LOCAL, tNode?: TransformNode): void {\r\n if (space === Space.LOCAL) {\r\n this._decompose();\r\n this._localRotation.copyFrom(quat);\r\n\r\n this._markAsDirtyAndCompose();\r\n\r\n return;\r\n }\r\n\r\n const rotMatInv = Bone._TmpMats[0];\r\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\r\n return;\r\n }\r\n\r\n const rotMat = Bone._TmpMats[1];\r\n Matrix.FromQuaternionToRef(quat, rotMat);\r\n\r\n rotMatInv.multiplyToRef(rotMat, rotMat);\r\n\r\n this._rotateWithMatrix(rotMat, space, tNode);\r\n }\r\n\r\n /**\r\n * Set the rotation matrix of the bone in local or world space\r\n * @param rotMat The rotation matrix that the bone should be set to\r\n * @param space The space that the rotation is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n */\r\n public setRotationMatrix(rotMat: Matrix, space = Space.LOCAL, tNode?: TransformNode): void {\r\n if (space === Space.LOCAL) {\r\n const quat = Bone._TmpQuat;\r\n Quaternion.FromRotationMatrixToRef(rotMat, quat);\r\n this.setRotationQuaternion(quat, space, tNode);\r\n return;\r\n }\r\n\r\n const rotMatInv = Bone._TmpMats[0];\r\n if (!this._getAbsoluteInverseMatrixUnscaledToRef(rotMatInv, tNode)) {\r\n return;\r\n }\r\n\r\n const rotMat2 = Bone._TmpMats[1];\r\n rotMat2.copyFrom(rotMat);\r\n\r\n rotMatInv.multiplyToRef(rotMat, rotMat2);\r\n\r\n this._rotateWithMatrix(rotMat2, space, tNode);\r\n }\r\n\r\n private _rotateWithMatrix(rmat: Matrix, space = Space.LOCAL, tNode?: TransformNode): void {\r\n const lmat = this.getLocalMatrix();\r\n const lx = lmat.m[12];\r\n const ly = lmat.m[13];\r\n const lz = lmat.m[14];\r\n const parent = this.getParent();\r\n const parentScale = Bone._TmpMats[3];\r\n const parentScaleInv = Bone._TmpMats[4];\r\n\r\n if (parent && space == Space.WORLD) {\r\n if (tNode) {\r\n parentScale.copyFrom(tNode.getWorldMatrix());\r\n parent.getAbsoluteMatrix().multiplyToRef(parentScale, parentScale);\r\n } else {\r\n parentScale.copyFrom(parent.getAbsoluteMatrix());\r\n }\r\n parentScaleInv.copyFrom(parentScale);\r\n parentScaleInv.invert();\r\n lmat.multiplyToRef(parentScale, lmat);\r\n lmat.multiplyToRef(rmat, lmat);\r\n lmat.multiplyToRef(parentScaleInv, lmat);\r\n } else {\r\n if (space == Space.WORLD && tNode) {\r\n parentScale.copyFrom(tNode.getWorldMatrix());\r\n parentScaleInv.copyFrom(parentScale);\r\n parentScaleInv.invert();\r\n lmat.multiplyToRef(parentScale, lmat);\r\n lmat.multiplyToRef(rmat, lmat);\r\n lmat.multiplyToRef(parentScaleInv, lmat);\r\n } else {\r\n lmat.multiplyToRef(rmat, lmat);\r\n }\r\n }\r\n\r\n lmat.setTranslationFromFloats(lx, ly, lz);\r\n\r\n this.computeAbsoluteMatrices();\r\n this._markAsDirtyAndDecompose();\r\n }\r\n\r\n private _getAbsoluteInverseMatrixUnscaledToRef(rotMatInv: Matrix, tNode?: TransformNode): boolean {\r\n const scaleMatrix = Bone._TmpMats[2];\r\n rotMatInv.copyFrom(this.getAbsoluteMatrix());\r\n\r\n if (tNode) {\r\n rotMatInv.multiplyToRef(tNode.getWorldMatrix(), rotMatInv);\r\n Matrix.ScalingToRef(tNode.scaling.x, tNode.scaling.y, tNode.scaling.z, scaleMatrix);\r\n } else {\r\n Matrix.IdentityToRef(scaleMatrix);\r\n }\r\n\r\n rotMatInv.invert();\r\n if (isNaN(rotMatInv.m[0])) {\r\n // Matrix failed to invert.\r\n // This can happen if scale is zero for example.\r\n return false;\r\n }\r\n\r\n scaleMatrix.multiplyAtIndex(0, this._scalingDeterminant);\r\n rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Get the position of the bone in local or world space\r\n * @param space The space that the returned position is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The position of the bone\r\n */\r\n public getPosition(space = Space.LOCAL, tNode: Nullable = null): Vector3 {\r\n const pos = Vector3.Zero();\r\n\r\n this.getPositionToRef(space, tNode, pos);\r\n\r\n return pos;\r\n }\r\n\r\n /**\r\n * Copy the position of the bone to a vector3 in local or world space\r\n * @param space The space that the returned position is in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The vector3 to copy the position to\r\n */\r\n public getPositionToRef(space = Space.LOCAL, tNode: Nullable, result: Vector3): void {\r\n if (space == Space.LOCAL) {\r\n const lm = this.getLocalMatrix();\r\n\r\n result.x = lm.m[12];\r\n result.y = lm.m[13];\r\n result.z = lm.m[14];\r\n } else {\r\n let wm: Nullable = null;\r\n\r\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\r\n if (tNode) {\r\n wm = tNode.getWorldMatrix();\r\n }\r\n\r\n this._skeleton.computeAbsoluteMatrices();\r\n\r\n let tmat = Bone._TmpMats[0];\r\n\r\n if (tNode && wm) {\r\n tmat.copyFrom(this.getAbsoluteMatrix());\r\n tmat.multiplyToRef(wm, tmat);\r\n } else {\r\n tmat = this.getAbsoluteMatrix();\r\n }\r\n\r\n result.x = tmat.m[12];\r\n result.y = tmat.m[13];\r\n result.z = tmat.m[14];\r\n }\r\n }\r\n\r\n /**\r\n * Get the absolute position of the bone (world space)\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The absolute position of the bone\r\n */\r\n public getAbsolutePosition(tNode: Nullable = null): Vector3 {\r\n const pos = Vector3.Zero();\r\n\r\n this.getPositionToRef(Space.WORLD, tNode, pos);\r\n\r\n return pos;\r\n }\r\n\r\n /**\r\n * Copy the absolute position of the bone (world space) to the result param\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The vector3 to copy the absolute position to\r\n */\r\n public getAbsolutePositionToRef(tNode: TransformNode, result: Vector3) {\r\n this.getPositionToRef(Space.WORLD, tNode, result);\r\n }\r\n\r\n /**\r\n * Compute the absolute matrices of this bone and its children\r\n */\r\n public computeAbsoluteMatrices(): void {\r\n this._compose();\r\n\r\n if (this.parent) {\r\n this._localMatrix.multiplyToRef(this.parent._absoluteMatrix, this._absoluteMatrix);\r\n } else {\r\n this._absoluteMatrix.copyFrom(this._localMatrix);\r\n\r\n const poseMatrix = this._skeleton.getPoseMatrix();\r\n\r\n if (poseMatrix) {\r\n this._absoluteMatrix.multiplyToRef(poseMatrix, this._absoluteMatrix);\r\n }\r\n }\r\n\r\n const children = this.children;\r\n const len = children.length;\r\n\r\n for (let i = 0; i < len; i++) {\r\n children[i].computeAbsoluteMatrices();\r\n }\r\n }\r\n\r\n /**\r\n * Compute the absolute matrices of this bone and its children\r\n * @deprecated Please use computeAbsoluteMatrices instead\r\n */\r\n public computeAbsoluteTransforms(): void {\r\n this.computeAbsoluteMatrices();\r\n }\r\n\r\n /**\r\n * Get the world direction from an axis that is in the local space of the bone\r\n * @param localAxis The local direction that is used to compute the world direction\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The world direction\r\n */\r\n public getDirection(localAxis: Vector3, tNode: Nullable = null): Vector3 {\r\n const result = Vector3.Zero();\r\n\r\n this.getDirectionToRef(localAxis, tNode, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Copy the world direction to a vector3 from an axis that is in the local space of the bone\r\n * @param localAxis The local direction that is used to compute the world direction\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The vector3 that the world direction will be copied to\r\n */\r\n public getDirectionToRef(localAxis: Vector3, tNode: Nullable = null, result: Vector3): void {\r\n let wm: Nullable = null;\r\n\r\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\r\n if (tNode) {\r\n wm = tNode.getWorldMatrix();\r\n }\r\n\r\n this._skeleton.computeAbsoluteMatrices();\r\n\r\n const mat = Bone._TmpMats[0];\r\n\r\n mat.copyFrom(this.getAbsoluteMatrix());\r\n\r\n if (tNode && wm) {\r\n mat.multiplyToRef(wm, mat);\r\n }\r\n\r\n Vector3.TransformNormalToRef(localAxis, mat, result);\r\n\r\n result.normalize();\r\n }\r\n\r\n /**\r\n * Get the euler rotation of the bone in local or world space\r\n * @param space The space that the rotation should be in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The euler rotation\r\n */\r\n public getRotation(space = Space.LOCAL, tNode: Nullable = null): Vector3 {\r\n const result = Vector3.Zero();\r\n\r\n this.getRotationToRef(space, tNode, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Copy the euler rotation of the bone to a vector3. The rotation can be in either local or world space\r\n * @param space The space that the rotation should be in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The vector3 that the rotation should be copied to\r\n */\r\n public getRotationToRef(space = Space.LOCAL, tNode: Nullable = null, result: Vector3): void {\r\n const quat = Bone._TmpQuat;\r\n\r\n this.getRotationQuaternionToRef(space, tNode, quat);\r\n\r\n quat.toEulerAnglesToRef(result);\r\n }\r\n\r\n /**\r\n * Get the quaternion rotation of the bone in either local or world space\r\n * @param space The space that the rotation should be in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The quaternion rotation\r\n */\r\n public getRotationQuaternion(space = Space.LOCAL, tNode: Nullable = null): Quaternion {\r\n const result = Quaternion.Identity();\r\n\r\n this.getRotationQuaternionToRef(space, tNode, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Copy the quaternion rotation of the bone to a quaternion. The rotation can be in either local or world space\r\n * @param space The space that the rotation should be in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The quaternion that the rotation should be copied to\r\n */\r\n public getRotationQuaternionToRef(space = Space.LOCAL, tNode: Nullable = null, result: Quaternion): void {\r\n if (space == Space.LOCAL) {\r\n this._decompose();\r\n result.copyFrom(this._localRotation);\r\n } else {\r\n const mat = Bone._TmpMats[0];\r\n const amat = this.getAbsoluteMatrix();\r\n\r\n if (tNode) {\r\n amat.multiplyToRef(tNode.getWorldMatrix(), mat);\r\n } else {\r\n mat.copyFrom(amat);\r\n }\r\n\r\n mat.multiplyAtIndex(0, this._scalingDeterminant);\r\n mat.multiplyAtIndex(1, this._scalingDeterminant);\r\n mat.multiplyAtIndex(2, this._scalingDeterminant);\r\n\r\n mat.decompose(undefined, result, undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Get the rotation matrix of the bone in local or world space\r\n * @param space The space that the rotation should be in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The rotation matrix\r\n */\r\n public getRotationMatrix(space = Space.LOCAL, tNode: TransformNode): Matrix {\r\n const result = Matrix.Identity();\r\n\r\n this.getRotationMatrixToRef(space, tNode, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Copy the rotation matrix of the bone to a matrix. The rotation can be in either local or world space\r\n * @param space The space that the rotation should be in\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The quaternion that the rotation should be copied to\r\n */\r\n public getRotationMatrixToRef(space = Space.LOCAL, tNode: TransformNode, result: Matrix): void {\r\n if (space == Space.LOCAL) {\r\n this.getLocalMatrix().getRotationMatrixToRef(result);\r\n } else {\r\n const mat = Bone._TmpMats[0];\r\n const amat = this.getAbsoluteMatrix();\r\n\r\n if (tNode) {\r\n amat.multiplyToRef(tNode.getWorldMatrix(), mat);\r\n } else {\r\n mat.copyFrom(amat);\r\n }\r\n\r\n mat.multiplyAtIndex(0, this._scalingDeterminant);\r\n mat.multiplyAtIndex(1, this._scalingDeterminant);\r\n mat.multiplyAtIndex(2, this._scalingDeterminant);\r\n\r\n mat.getRotationMatrixToRef(result);\r\n }\r\n }\r\n\r\n /**\r\n * Get the world position of a point that is in the local space of the bone\r\n * @param position The local position\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The world position\r\n */\r\n public getAbsolutePositionFromLocal(position: Vector3, tNode: Nullable = null): Vector3 {\r\n const result = Vector3.Zero();\r\n\r\n this.getAbsolutePositionFromLocalToRef(position, tNode, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Get the world position of a point that is in the local space of the bone and copy it to the result param\r\n * @param position The local position\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The vector3 that the world position should be copied to\r\n */\r\n public getAbsolutePositionFromLocalToRef(position: Vector3, tNode: Nullable = null, result: Vector3): void {\r\n let wm: Nullable = null;\r\n\r\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\r\n if (tNode) {\r\n wm = tNode.getWorldMatrix();\r\n }\r\n\r\n this._skeleton.computeAbsoluteMatrices();\r\n\r\n const tmat = Bone._TmpMats[0];\r\n\r\n tmat.copyFrom(this.getAbsoluteMatrix());\r\n\r\n if (tNode && wm) {\r\n tmat.multiplyToRef(wm, tmat);\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(position, tmat, result);\r\n }\r\n\r\n /**\r\n * Get the local position of a point that is in world space\r\n * @param position The world position\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @returns The local position\r\n */\r\n public getLocalPositionFromAbsolute(position: Vector3, tNode: Nullable = null): Vector3 {\r\n const result = Vector3.Zero();\r\n\r\n this.getLocalPositionFromAbsoluteToRef(position, tNode, result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Get the local position of a point that is in world space and copy it to the result param\r\n * @param position The world position\r\n * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD\r\n * @param result The vector3 that the local position should be copied to\r\n */\r\n public getLocalPositionFromAbsoluteToRef(position: Vector3, tNode: Nullable = null, result: Vector3): void {\r\n let wm: Nullable = null;\r\n\r\n //tNode.getWorldMatrix() needs to be called before skeleton.computeAbsoluteMatrices()\r\n if (tNode) {\r\n wm = tNode.getWorldMatrix();\r\n }\r\n\r\n this._skeleton.computeAbsoluteMatrices();\r\n\r\n const tmat = Bone._TmpMats[0];\r\n\r\n tmat.copyFrom(this.getAbsoluteMatrix());\r\n\r\n if (tNode && wm) {\r\n tmat.multiplyToRef(wm, tmat);\r\n }\r\n\r\n tmat.invert();\r\n\r\n Vector3.TransformCoordinatesToRef(position, tmat, result);\r\n }\r\n\r\n /**\r\n * Set the current local matrix as the restMatrix for this bone.\r\n */\r\n public setCurrentPoseAsRest(): void {\r\n this.setRestMatrix(this.getLocalMatrix());\r\n }\r\n}\r\n","import { Animation } from \"./animation\";\r\nimport { RuntimeAnimation } from \"./runtimeAnimation\";\r\n\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Scene } from \"../scene\";\r\nimport { Matrix, Quaternion, Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport { PrecisionDate } from \"../Misc/precisionDate\";\r\nimport { Bone } from \"../Bones/bone\";\r\nimport type { Node } from \"../node\";\r\n\r\n/**\r\n * Class used to store an actual running animation\r\n */\r\nexport class Animatable {\r\n private _localDelayOffset: Nullable = null;\r\n private _pausedDelay: Nullable = null;\r\n private _manualJumpDelay: Nullable = null;\r\n /** @hidden */\r\n public _runtimeAnimations = new Array();\r\n private _paused = false;\r\n private _scene: Scene;\r\n private _speedRatio = 1;\r\n private _weight = -1.0;\r\n private _syncRoot: Nullable = null;\r\n private _frameToSyncFromJump: Nullable = null;\r\n private _goToFrame: Nullable = null;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the animatable must be disposed and removed at the end of the animation.\r\n * This will only apply for non looping animation (default is true)\r\n */\r\n public disposeOnEnd = true;\r\n\r\n /**\r\n * Gets a boolean indicating if the animation has started\r\n */\r\n public animationStarted = false;\r\n\r\n /**\r\n * Observer raised when the animation ends\r\n */\r\n public onAnimationEndObservable = new Observable();\r\n\r\n /**\r\n * Observer raised when the animation loops\r\n */\r\n public onAnimationLoopObservable = new Observable();\r\n\r\n /**\r\n * Gets the root Animatable used to synchronize and normalize animations\r\n */\r\n public get syncRoot(): Nullable {\r\n return this._syncRoot;\r\n }\r\n\r\n /**\r\n * Gets the current frame of the first RuntimeAnimation\r\n * Used to synchronize Animatables\r\n */\r\n public get masterFrame(): number {\r\n if (this._runtimeAnimations.length === 0) {\r\n return 0;\r\n }\r\n\r\n return this._runtimeAnimations[0].currentFrame;\r\n }\r\n\r\n /**\r\n * Gets or sets the animatable weight (-1.0 by default meaning not weighted)\r\n */\r\n public get weight(): number {\r\n return this._weight;\r\n }\r\n\r\n public set weight(value: number) {\r\n if (value === -1) {\r\n // -1 is ok and means no weight\r\n this._weight = -1;\r\n return;\r\n }\r\n\r\n // Else weight must be in [0, 1] range\r\n this._weight = Math.min(Math.max(value, 0), 1.0);\r\n }\r\n\r\n /**\r\n * Gets or sets the speed ratio to apply to the animatable (1.0 by default)\r\n */\r\n public get speedRatio(): number {\r\n return this._speedRatio;\r\n }\r\n\r\n public set speedRatio(value: number) {\r\n for (let index = 0; index < this._runtimeAnimations.length; index++) {\r\n const animation = this._runtimeAnimations[index];\r\n\r\n animation._prepareForSpeedRatioChange(value);\r\n }\r\n this._speedRatio = value;\r\n\r\n // Resync _manualJumpDelay in case goToFrame was called before speedRatio was set.\r\n if (this._goToFrame !== null) {\r\n this.goToFrame(this._goToFrame);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new Animatable\r\n * @param scene defines the hosting scene\r\n * @param target defines the target object\r\n * @param fromFrame defines the starting frame number (default is 0)\r\n * @param toFrame defines the ending frame number (default is 100)\r\n * @param loopAnimation defines if the animation must loop (default is false)\r\n * @param speedRatio defines the factor to apply to animation speed (default is 1)\r\n * @param onAnimationEnd defines a callback to call when animation ends if it is not looping\r\n * @param animations defines a group of animation to add to the new Animatable\r\n * @param onAnimationLoop defines a callback to call when animation loops\r\n * @param isAdditive defines whether the animation should be evaluated additively\r\n * @param playOrder defines the order in which this animatable should be processed in the list of active animatables (default: 0)\r\n */\r\n constructor(\r\n scene: Scene,\r\n /** defines the target object */\r\n public target: any,\r\n /** defines the starting frame number (default is 0) */\r\n public fromFrame: number = 0,\r\n /** defines the ending frame number (default is 100) */\r\n public toFrame: number = 100,\r\n /** defines if the animation must loop (default is false) */\r\n public loopAnimation: boolean = false,\r\n speedRatio: number = 1.0,\r\n /** defines a callback to call when animation ends if it is not looping */\r\n public onAnimationEnd?: Nullable<() => void>,\r\n animations?: Animation[],\r\n /** defines a callback to call when animation loops */\r\n public onAnimationLoop?: Nullable<() => void>,\r\n /** defines whether the animation should be evaluated additively */\r\n public isAdditive: boolean = false,\r\n /** defines the order in which this animatable should be processed in the list of active animatables (default: 0) */\r\n public playOrder = 0\r\n ) {\r\n this._scene = scene;\r\n if (animations) {\r\n this.appendAnimations(target, animations);\r\n }\r\n\r\n this._speedRatio = speedRatio;\r\n scene._activeAnimatables.push(this);\r\n }\r\n\r\n // Methods\r\n /**\r\n * Synchronize and normalize current Animatable with a source Animatable\r\n * This is useful when using animation weights and when animations are not of the same length\r\n * @param root defines the root Animatable to synchronize with (null to stop synchronizing)\r\n * @returns the current Animatable\r\n */\r\n public syncWith(root: Nullable): Animatable {\r\n this._syncRoot = root;\r\n\r\n if (root) {\r\n // Make sure this animatable will animate after the root\r\n const index = this._scene._activeAnimatables.indexOf(this);\r\n if (index > -1) {\r\n this._scene._activeAnimatables.splice(index, 1);\r\n this._scene._activeAnimatables.push(this);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the list of runtime animations\r\n * @returns an array of RuntimeAnimation\r\n */\r\n public getAnimations(): RuntimeAnimation[] {\r\n return this._runtimeAnimations;\r\n }\r\n\r\n /**\r\n * Adds more animations to the current animatable\r\n * @param target defines the target of the animations\r\n * @param animations defines the new animations to add\r\n */\r\n public appendAnimations(target: any, animations: Animation[]): void {\r\n for (let index = 0; index < animations.length; index++) {\r\n const animation = animations[index];\r\n\r\n const newRuntimeAnimation = new RuntimeAnimation(target, animation, this._scene, this);\r\n newRuntimeAnimation._onLoop = () => {\r\n this.onAnimationLoopObservable.notifyObservers(this);\r\n if (this.onAnimationLoop) {\r\n this.onAnimationLoop();\r\n }\r\n };\r\n\r\n this._runtimeAnimations.push(newRuntimeAnimation);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the source animation for a specific property\r\n * @param property defines the property to look for\r\n * @returns null or the source animation for the given property\r\n */\r\n public getAnimationByTargetProperty(property: string): Nullable {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n if (runtimeAnimations[index].animation.targetProperty === property) {\r\n return runtimeAnimations[index].animation;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets the runtime animation for a specific property\r\n * @param property defines the property to look for\r\n * @returns null or the runtime animation for the given property\r\n */\r\n public getRuntimeAnimationByTargetProperty(property: string): Nullable {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n if (runtimeAnimations[index].animation.targetProperty === property) {\r\n return runtimeAnimations[index];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Resets the animatable to its original state\r\n */\r\n public reset(): void {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n runtimeAnimations[index].reset(true);\r\n }\r\n\r\n this._localDelayOffset = null;\r\n this._pausedDelay = null;\r\n }\r\n\r\n /**\r\n * Allows the animatable to blend with current running animations\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending\r\n * @param blendingSpeed defines the blending speed to use\r\n */\r\n public enableBlending(blendingSpeed: number): void {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n runtimeAnimations[index].animation.enableBlending = true;\r\n runtimeAnimations[index].animation.blendingSpeed = blendingSpeed;\r\n }\r\n }\r\n\r\n /**\r\n * Disable animation blending\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending\r\n */\r\n public disableBlending(): void {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n runtimeAnimations[index].animation.enableBlending = false;\r\n }\r\n }\r\n\r\n /**\r\n * Jump directly to a given frame\r\n * @param frame defines the frame to jump to\r\n */\r\n public goToFrame(frame: number): void {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n if (runtimeAnimations[0]) {\r\n const fps = runtimeAnimations[0].animation.framePerSecond;\r\n this._frameToSyncFromJump = this._frameToSyncFromJump ?? runtimeAnimations[0].currentFrame;\r\n const delay = this.speedRatio === 0 ? 0 : (((frame - this._frameToSyncFromJump) / fps) * 1000) / this.speedRatio;\r\n this._manualJumpDelay = -delay;\r\n }\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n runtimeAnimations[index].goToFrame(frame);\r\n }\r\n\r\n this._goToFrame = frame;\r\n }\r\n\r\n /**\r\n * Pause the animation\r\n */\r\n public pause(): void {\r\n if (this._paused) {\r\n return;\r\n }\r\n this._paused = true;\r\n }\r\n\r\n /**\r\n * Restart the animation\r\n */\r\n public restart(): void {\r\n this._paused = false;\r\n }\r\n\r\n private _raiseOnAnimationEnd() {\r\n if (this.onAnimationEnd) {\r\n this.onAnimationEnd();\r\n }\r\n\r\n this.onAnimationEndObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Stop and delete the current animation\r\n * @param animationName defines a string used to only stop some of the runtime animations instead of all\r\n * @param targetMask a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)\r\n * @param useGlobalSplice if true, the animatables will be removed by the caller of this function (false by default)\r\n */\r\n public stop(animationName?: string, targetMask?: (target: any) => boolean, useGlobalSplice = false): void {\r\n if (animationName || targetMask) {\r\n const idx = this._scene._activeAnimatables.indexOf(this);\r\n\r\n if (idx > -1) {\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = runtimeAnimations.length - 1; index >= 0; index--) {\r\n const runtimeAnimation = runtimeAnimations[index];\r\n if (animationName && runtimeAnimation.animation.name != animationName) {\r\n continue;\r\n }\r\n if (targetMask && !targetMask(runtimeAnimation.target)) {\r\n continue;\r\n }\r\n\r\n runtimeAnimation.dispose();\r\n runtimeAnimations.splice(index, 1);\r\n }\r\n\r\n if (runtimeAnimations.length == 0) {\r\n if (!useGlobalSplice) {\r\n this._scene._activeAnimatables.splice(idx, 1);\r\n }\r\n this._raiseOnAnimationEnd();\r\n }\r\n }\r\n } else {\r\n const index = this._scene._activeAnimatables.indexOf(this);\r\n\r\n if (index > -1) {\r\n if (!useGlobalSplice) {\r\n this._scene._activeAnimatables.splice(index, 1);\r\n }\r\n const runtimeAnimations = this._runtimeAnimations;\r\n\r\n for (let index = 0; index < runtimeAnimations.length; index++) {\r\n runtimeAnimations[index].dispose();\r\n }\r\n\r\n this._runtimeAnimations.length = 0;\r\n\r\n this._raiseOnAnimationEnd();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Wait asynchronously for the animation to end\r\n * @returns a promise which will be fulfilled when the animation ends\r\n */\r\n public waitAsync(): Promise {\r\n return new Promise((resolve) => {\r\n this.onAnimationEndObservable.add(\r\n () => {\r\n resolve(this);\r\n },\r\n undefined,\r\n undefined,\r\n this,\r\n true\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _animate(delay: number): boolean {\r\n if (this._paused) {\r\n this.animationStarted = false;\r\n if (this._pausedDelay === null) {\r\n this._pausedDelay = delay;\r\n }\r\n return true;\r\n }\r\n\r\n if (this._localDelayOffset === null) {\r\n this._localDelayOffset = delay;\r\n this._pausedDelay = null;\r\n } else if (this._pausedDelay !== null) {\r\n this._localDelayOffset += delay - this._pausedDelay;\r\n this._pausedDelay = null;\r\n }\r\n\r\n if (this._manualJumpDelay !== null) {\r\n this._localDelayOffset += this._manualJumpDelay;\r\n this._manualJumpDelay = null;\r\n this._frameToSyncFromJump = null;\r\n }\r\n\r\n this._goToFrame = null;\r\n\r\n if (this._weight === 0) {\r\n // We consider that an animation with a weight === 0 is \"actively\" paused\r\n return true;\r\n }\r\n\r\n // Animating\r\n let running = false;\r\n const runtimeAnimations = this._runtimeAnimations;\r\n let index: number;\r\n\r\n for (index = 0; index < runtimeAnimations.length; index++) {\r\n const animation = runtimeAnimations[index];\r\n const isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this._speedRatio, this._weight);\r\n running = running || isRunning;\r\n }\r\n\r\n this.animationStarted = running;\r\n\r\n if (!running) {\r\n if (this.disposeOnEnd) {\r\n // Remove from active animatables\r\n index = this._scene._activeAnimatables.indexOf(this);\r\n this._scene._activeAnimatables.splice(index, 1);\r\n\r\n // Dispose all runtime animations\r\n for (index = 0; index < runtimeAnimations.length; index++) {\r\n runtimeAnimations[index].dispose();\r\n }\r\n }\r\n\r\n this._raiseOnAnimationEnd();\r\n\r\n if (this.disposeOnEnd) {\r\n this.onAnimationEnd = null;\r\n this.onAnimationLoop = null;\r\n this.onAnimationLoopObservable.clear();\r\n this.onAnimationEndObservable.clear();\r\n }\r\n }\r\n\r\n return running;\r\n }\r\n}\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal */\r\n _registerTargetForLateAnimationBinding(runtimeAnimation: RuntimeAnimation, originalValue: any): void;\r\n\r\n /** @internal */\r\n _processLateAnimationBindingsForMatrices(holder: {\r\n totalWeight: number;\r\n totalAdditiveWeight: number;\r\n animations: RuntimeAnimation[];\r\n additiveAnimations: RuntimeAnimation[];\r\n originalValue: Matrix;\r\n }): any;\r\n\r\n /** @internal */\r\n _processLateAnimationBindingsForQuaternions(\r\n holder: {\r\n totalWeight: number;\r\n totalAdditiveWeight: number;\r\n animations: RuntimeAnimation[];\r\n additiveAnimations: RuntimeAnimation[];\r\n originalValue: Quaternion;\r\n },\r\n refQuaternion: Quaternion\r\n ): Quaternion;\r\n\r\n /** @internal */\r\n _processLateAnimationBindings(): void;\r\n\r\n /**\r\n * Sort active animatables based on their playOrder property\r\n */\r\n sortActiveAnimatables(): void;\r\n\r\n /**\r\n * Will start the animation sequence of a given target\r\n * @param target defines the target\r\n * @param from defines from which frame should animation start\r\n * @param to defines until which frame should animation run.\r\n * @param weight defines the weight to apply to the animation (1.0 by default)\r\n * @param loop defines if the animation loops\r\n * @param speedRatio defines the speed in which to run the animation (1.0 by default)\r\n * @param onAnimationEnd defines the function to be executed when the animation ends\r\n * @param animatable defines an animatable object. If not provided a new one will be created from the given params\r\n * @param targetMask defines if the target should be animated if animations are present (this is called recursively on descendant animatables regardless of return value)\r\n * @param onAnimationLoop defines the callback to call when an animation loops\r\n * @param isAdditive defines whether the animation should be evaluated additively (false by default)\r\n * @returns the animatable object created for this animation\r\n */\r\n beginWeightedAnimation(\r\n target: any,\r\n from: number,\r\n to: number,\r\n weight: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n animatable?: Animatable,\r\n targetMask?: (target: any) => boolean,\r\n onAnimationLoop?: () => void,\r\n isAdditive?: boolean\r\n ): Animatable;\r\n\r\n /**\r\n * Will start the animation sequence of a given target\r\n * @param target defines the target\r\n * @param from defines from which frame should animation start\r\n * @param to defines until which frame should animation run.\r\n * @param loop defines if the animation loops\r\n * @param speedRatio defines the speed in which to run the animation (1.0 by default)\r\n * @param onAnimationEnd defines the function to be executed when the animation ends\r\n * @param animatable defines an animatable object. If not provided a new one will be created from the given params\r\n * @param stopCurrent defines if the current animations must be stopped first (true by default)\r\n * @param targetMask defines if the target should be animate if animations are present (this is called recursively on descendant animatables regardless of return value)\r\n * @param onAnimationLoop defines the callback to call when an animation loops\r\n * @param isAdditive defines whether the animation should be evaluated additively (false by default)\r\n * @returns the animatable object created for this animation\r\n */\r\n beginAnimation(\r\n target: any,\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n animatable?: Animatable,\r\n stopCurrent?: boolean,\r\n targetMask?: (target: any) => boolean,\r\n onAnimationLoop?: () => void,\r\n isAdditive?: boolean\r\n ): Animatable;\r\n\r\n /**\r\n * Will start the animation sequence of a given target and its hierarchy\r\n * @param target defines the target\r\n * @param directDescendantsOnly if true only direct descendants will be used, if false direct and also indirect (children of children, an so on in a recursive manner) descendants will be used.\r\n * @param from defines from which frame should animation start\r\n * @param to defines until which frame should animation run.\r\n * @param loop defines if the animation loops\r\n * @param speedRatio defines the speed in which to run the animation (1.0 by default)\r\n * @param onAnimationEnd defines the function to be executed when the animation ends\r\n * @param animatable defines an animatable object. If not provided a new one will be created from the given params\r\n * @param stopCurrent defines if the current animations must be stopped first (true by default)\r\n * @param targetMask defines if the target should be animated if animations are present (this is called recursively on descendant animatables regardless of return value)\r\n * @param onAnimationLoop defines the callback to call when an animation loops\r\n * @param isAdditive defines whether the animation should be evaluated additively (false by default)\r\n * @returns the list of created animatables\r\n */\r\n beginHierarchyAnimation(\r\n target: any,\r\n directDescendantsOnly: boolean,\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n animatable?: Animatable,\r\n stopCurrent?: boolean,\r\n targetMask?: (target: any) => boolean,\r\n onAnimationLoop?: () => void,\r\n isAdditive?: boolean\r\n ): Animatable[];\r\n\r\n /**\r\n * Begin a new animation on a given node\r\n * @param target defines the target where the animation will take place\r\n * @param animations defines the list of animations to start\r\n * @param from defines the initial value\r\n * @param to defines the final value\r\n * @param loop defines if you want animation to loop (off by default)\r\n * @param speedRatio defines the speed ratio to apply to all animations\r\n * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)\r\n * @param onAnimationLoop defines the callback to call when an animation loops\r\n * @param isAdditive defines whether the animation should be evaluated additively (false by default)\r\n * @returns the list of created animatables\r\n */\r\n beginDirectAnimation(\r\n target: any,\r\n animations: Animation[],\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n onAnimationLoop?: () => void,\r\n isAdditive?: boolean\r\n ): Animatable;\r\n\r\n /**\r\n * Begin a new animation on a given node and its hierarchy\r\n * @param target defines the root node where the animation will take place\r\n * @param directDescendantsOnly if true only direct descendants will be used, if false direct and also indirect (children of children, an so on in a recursive manner) descendants will be used.\r\n * @param animations defines the list of animations to start\r\n * @param from defines the initial value\r\n * @param to defines the final value\r\n * @param loop defines if you want animation to loop (off by default)\r\n * @param speedRatio defines the speed ratio to apply to all animations\r\n * @param onAnimationEnd defines the callback to call when an animation ends (will be called once per node)\r\n * @param onAnimationLoop defines the callback to call when an animation loops\r\n * @param isAdditive defines whether the animation should be evaluated additively (false by default)\r\n * @returns the list of animatables created for all nodes\r\n */\r\n beginDirectHierarchyAnimation(\r\n target: Node,\r\n directDescendantsOnly: boolean,\r\n animations: Animation[],\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n onAnimationLoop?: () => void,\r\n isAdditive?: boolean\r\n ): Animatable[];\r\n\r\n /**\r\n * Gets the animatable associated with a specific target\r\n * @param target defines the target of the animatable\r\n * @returns the required animatable if found\r\n */\r\n getAnimatableByTarget(target: any): Nullable;\r\n\r\n /**\r\n * Gets all animatables associated with a given target\r\n * @param target defines the target to look animatables for\r\n * @returns an array of Animatables\r\n */\r\n getAllAnimatablesByTarget(target: any): Array;\r\n\r\n /**\r\n * Stops and removes all animations that have been applied to the scene\r\n */\r\n stopAllAnimations(): void;\r\n\r\n /**\r\n * Gets the current delta time used by animation engine\r\n */\r\n deltaTime: number;\r\n }\r\n}\r\n\r\nScene.prototype._animate = function (): void {\r\n if (!this.animationsEnabled) {\r\n return;\r\n }\r\n\r\n // Getting time\r\n const now = PrecisionDate.Now;\r\n if (!this._animationTimeLast) {\r\n if (this._pendingData.length > 0) {\r\n return;\r\n }\r\n this._animationTimeLast = now;\r\n }\r\n\r\n this.deltaTime = this.useConstantAnimationDeltaTime ? 16.0 : (now - this._animationTimeLast) * this.animationTimeScale;\r\n this._animationTimeLast = now;\r\n\r\n const animatables = this._activeAnimatables;\r\n if (animatables.length === 0) {\r\n return;\r\n }\r\n\r\n this._animationTime += this.deltaTime;\r\n const animationTime = this._animationTime;\r\n\r\n for (let index = 0; index < animatables.length; index++) {\r\n const animatable = animatables[index];\r\n\r\n if (!animatable._animate(animationTime) && animatable.disposeOnEnd) {\r\n index--; // Array was updated\r\n }\r\n }\r\n\r\n // Late animation bindings\r\n this._processLateAnimationBindings();\r\n};\r\n\r\nScene.prototype.sortActiveAnimatables = function (): void {\r\n this._activeAnimatables.sort((a, b) => {\r\n return a.playOrder - b.playOrder;\r\n });\r\n};\r\n\r\nScene.prototype.beginWeightedAnimation = function (\r\n target: any,\r\n from: number,\r\n to: number,\r\n weight = 1.0,\r\n loop?: boolean,\r\n speedRatio: number = 1.0,\r\n onAnimationEnd?: () => void,\r\n animatable?: Animatable,\r\n targetMask?: (target: any) => boolean,\r\n onAnimationLoop?: () => void,\r\n isAdditive = false\r\n): Animatable {\r\n const returnedAnimatable = this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, false, targetMask, onAnimationLoop, isAdditive);\r\n returnedAnimatable.weight = weight;\r\n\r\n return returnedAnimatable;\r\n};\r\n\r\nScene.prototype.beginAnimation = function (\r\n target: any,\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio: number = 1.0,\r\n onAnimationEnd?: () => void,\r\n animatable?: Animatable,\r\n stopCurrent = true,\r\n targetMask?: (target: any) => boolean,\r\n onAnimationLoop?: () => void,\r\n isAdditive = false\r\n): Animatable {\r\n if (from > to && speedRatio > 0) {\r\n speedRatio *= -1;\r\n }\r\n\r\n if (stopCurrent) {\r\n this.stopAnimation(target, undefined, targetMask);\r\n }\r\n\r\n if (!animatable) {\r\n animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, undefined, onAnimationLoop, isAdditive);\r\n }\r\n\r\n const shouldRunTargetAnimations = targetMask ? targetMask(target) : true;\r\n // Local animations\r\n if (target.animations && shouldRunTargetAnimations) {\r\n animatable.appendAnimations(target, target.animations);\r\n }\r\n\r\n // Children animations\r\n if (target.getAnimatables) {\r\n const animatables = target.getAnimatables();\r\n for (let index = 0; index < animatables.length; index++) {\r\n this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, onAnimationLoop);\r\n }\r\n }\r\n\r\n animatable.reset();\r\n\r\n return animatable;\r\n};\r\n\r\nScene.prototype.beginHierarchyAnimation = function (\r\n target: any,\r\n directDescendantsOnly: boolean,\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio: number = 1.0,\r\n onAnimationEnd?: () => void,\r\n animatable?: Animatable,\r\n stopCurrent = true,\r\n targetMask?: (target: any) => boolean,\r\n onAnimationLoop?: () => void,\r\n isAdditive = false\r\n): Animatable[] {\r\n const children = target.getDescendants(directDescendantsOnly);\r\n\r\n const result = [];\r\n result.push(this.beginAnimation(target, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, undefined, isAdditive));\r\n for (const child of children) {\r\n result.push(this.beginAnimation(child, from, to, loop, speedRatio, onAnimationEnd, animatable, stopCurrent, targetMask, undefined, isAdditive));\r\n }\r\n\r\n return result;\r\n};\r\n\r\nScene.prototype.beginDirectAnimation = function (\r\n target: any,\r\n animations: Animation[],\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n onAnimationLoop?: () => void,\r\n isAdditive = false\r\n): Animatable {\r\n if (speedRatio === undefined) {\r\n speedRatio = 1.0;\r\n }\r\n\r\n if (from > to && speedRatio > 0) {\r\n speedRatio *= -1;\r\n } else if (to > from && speedRatio < 0) {\r\n const temp = to;\r\n to = from;\r\n from = temp;\r\n }\r\n\r\n const animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations, onAnimationLoop, isAdditive);\r\n\r\n return animatable;\r\n};\r\n\r\nScene.prototype.beginDirectHierarchyAnimation = function (\r\n target: Node,\r\n directDescendantsOnly: boolean,\r\n animations: Animation[],\r\n from: number,\r\n to: number,\r\n loop?: boolean,\r\n speedRatio?: number,\r\n onAnimationEnd?: () => void,\r\n onAnimationLoop?: () => void,\r\n isAdditive = false\r\n): Animatable[] {\r\n const children = target.getDescendants(directDescendantsOnly);\r\n\r\n const result = [];\r\n result.push(this.beginDirectAnimation(target, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive));\r\n for (const child of children) {\r\n result.push(this.beginDirectAnimation(child, animations, from, to, loop, speedRatio, onAnimationEnd, onAnimationLoop, isAdditive));\r\n }\r\n\r\n return result;\r\n};\r\n\r\nScene.prototype.getAnimatableByTarget = function (target: any): Nullable {\r\n for (let index = 0; index < this._activeAnimatables.length; index++) {\r\n if (this._activeAnimatables[index].target === target) {\r\n return this._activeAnimatables[index];\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\nScene.prototype.getAllAnimatablesByTarget = function (target: any): Array {\r\n const result = [];\r\n for (let index = 0; index < this._activeAnimatables.length; index++) {\r\n if (this._activeAnimatables[index].target === target) {\r\n result.push(this._activeAnimatables[index]);\r\n }\r\n }\r\n\r\n return result;\r\n};\r\n\r\n/**\r\n * Will stop the animation of the given target\r\n * @param target - the target\r\n * @param animationName - the name of the animation to stop (all animations will be stopped if both this and targetMask are empty)\r\n * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)\r\n */\r\nScene.prototype.stopAnimation = function (target: any, animationName?: string, targetMask?: (target: any) => boolean): void {\r\n const animatables = this.getAllAnimatablesByTarget(target);\r\n\r\n for (const animatable of animatables) {\r\n animatable.stop(animationName, targetMask);\r\n }\r\n};\r\n\r\n/**\r\n * Stops and removes all animations that have been applied to the scene\r\n */\r\nScene.prototype.stopAllAnimations = function (): void {\r\n if (this._activeAnimatables) {\r\n for (let i = 0; i < this._activeAnimatables.length; i++) {\r\n this._activeAnimatables[i].stop(undefined, undefined, true);\r\n }\r\n this._activeAnimatables.length = 0;\r\n }\r\n\r\n for (const group of this.animationGroups) {\r\n group.stop();\r\n }\r\n};\r\n\r\nScene.prototype._registerTargetForLateAnimationBinding = function (runtimeAnimation: RuntimeAnimation, originalValue: any): void {\r\n const target = runtimeAnimation.target;\r\n this._registeredForLateAnimationBindings.pushNoDuplicate(target);\r\n\r\n if (!target._lateAnimationHolders) {\r\n target._lateAnimationHolders = {};\r\n }\r\n\r\n if (!target._lateAnimationHolders[runtimeAnimation.targetPath]) {\r\n target._lateAnimationHolders[runtimeAnimation.targetPath] = {\r\n totalWeight: 0,\r\n totalAdditiveWeight: 0,\r\n animations: [],\r\n additiveAnimations: [],\r\n originalValue: originalValue,\r\n };\r\n }\r\n\r\n if (runtimeAnimation.isAdditive) {\r\n target._lateAnimationHolders[runtimeAnimation.targetPath].additiveAnimations.push(runtimeAnimation);\r\n target._lateAnimationHolders[runtimeAnimation.targetPath].totalAdditiveWeight += runtimeAnimation.weight;\r\n } else {\r\n target._lateAnimationHolders[runtimeAnimation.targetPath].animations.push(runtimeAnimation);\r\n target._lateAnimationHolders[runtimeAnimation.targetPath].totalWeight += runtimeAnimation.weight;\r\n }\r\n};\r\n\r\nScene.prototype._processLateAnimationBindingsForMatrices = function (holder: {\r\n totalWeight: number;\r\n totalAdditiveWeight: number;\r\n animations: RuntimeAnimation[];\r\n additiveAnimations: RuntimeAnimation[];\r\n originalValue: Matrix;\r\n}): any {\r\n if (holder.totalWeight === 0 && holder.totalAdditiveWeight === 0) {\r\n return holder.originalValue;\r\n }\r\n\r\n let normalizer = 1.0;\r\n const finalPosition = TmpVectors.Vector3[0];\r\n const finalScaling = TmpVectors.Vector3[1];\r\n const finalQuaternion = TmpVectors.Quaternion[0];\r\n let startIndex = 0;\r\n const originalAnimation = holder.animations[0];\r\n const originalValue = holder.originalValue;\r\n\r\n let scale = 1;\r\n let skipOverride = false;\r\n if (holder.totalWeight < 1.0) {\r\n // We need to mix the original value in\r\n scale = 1.0 - holder.totalWeight;\r\n originalValue.decompose(finalScaling, finalQuaternion, finalPosition);\r\n } else {\r\n startIndex = 1;\r\n // We need to normalize the weights\r\n normalizer = holder.totalWeight;\r\n scale = originalAnimation.weight / normalizer;\r\n if (scale == 1) {\r\n if (holder.totalAdditiveWeight) {\r\n skipOverride = true;\r\n } else {\r\n return originalAnimation.currentValue;\r\n }\r\n }\r\n\r\n originalAnimation.currentValue.decompose(finalScaling, finalQuaternion, finalPosition);\r\n }\r\n\r\n // Add up the override animations\r\n if (!skipOverride) {\r\n finalScaling.scaleInPlace(scale);\r\n finalPosition.scaleInPlace(scale);\r\n finalQuaternion.scaleInPlace(scale);\r\n\r\n for (let animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {\r\n const runtimeAnimation = holder.animations[animIndex];\r\n if (runtimeAnimation.weight === 0) {\r\n continue;\r\n }\r\n\r\n scale = runtimeAnimation.weight / normalizer;\r\n const currentPosition = TmpVectors.Vector3[2];\r\n const currentScaling = TmpVectors.Vector3[3];\r\n const currentQuaternion = TmpVectors.Quaternion[1];\r\n\r\n runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);\r\n\r\n currentScaling.scaleAndAddToRef(scale, finalScaling);\r\n currentQuaternion.scaleAndAddToRef(Quaternion.Dot(finalQuaternion, currentQuaternion) > 0 ? scale : -scale, finalQuaternion);\r\n currentPosition.scaleAndAddToRef(scale, finalPosition);\r\n }\r\n\r\n finalQuaternion.normalize();\r\n }\r\n\r\n // Add up the additive animations\r\n for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {\r\n const runtimeAnimation = holder.additiveAnimations[animIndex];\r\n if (runtimeAnimation.weight === 0) {\r\n continue;\r\n }\r\n\r\n const currentPosition = TmpVectors.Vector3[2];\r\n const currentScaling = TmpVectors.Vector3[3];\r\n const currentQuaternion = TmpVectors.Quaternion[1];\r\n\r\n runtimeAnimation.currentValue.decompose(currentScaling, currentQuaternion, currentPosition);\r\n currentScaling.multiplyToRef(finalScaling, currentScaling);\r\n Vector3.LerpToRef(finalScaling, currentScaling, runtimeAnimation.weight, finalScaling);\r\n finalQuaternion.multiplyToRef(currentQuaternion, currentQuaternion);\r\n Quaternion.SlerpToRef(finalQuaternion, currentQuaternion, runtimeAnimation.weight, finalQuaternion);\r\n currentPosition.scaleAndAddToRef(runtimeAnimation.weight, finalPosition);\r\n }\r\n\r\n const workValue = originalAnimation ? originalAnimation._animationState.workValue : TmpVectors.Matrix[0].clone();\r\n Matrix.ComposeToRef(finalScaling, finalQuaternion, finalPosition, workValue);\r\n return workValue;\r\n};\r\n\r\nScene.prototype._processLateAnimationBindingsForQuaternions = function (\r\n holder: {\r\n totalWeight: number;\r\n totalAdditiveWeight: number;\r\n animations: RuntimeAnimation[];\r\n additiveAnimations: RuntimeAnimation[];\r\n originalValue: Quaternion;\r\n },\r\n refQuaternion: Quaternion\r\n): Quaternion {\r\n if (holder.totalWeight === 0 && holder.totalAdditiveWeight === 0) {\r\n return refQuaternion;\r\n }\r\n\r\n const originalAnimation = holder.animations[0];\r\n const originalValue = holder.originalValue;\r\n let cumulativeQuaternion = refQuaternion;\r\n\r\n if (holder.totalWeight === 0 && holder.totalAdditiveWeight > 0) {\r\n cumulativeQuaternion.copyFrom(originalValue);\r\n } else if (holder.animations.length === 1) {\r\n Quaternion.SlerpToRef(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight), cumulativeQuaternion);\r\n\r\n if (holder.totalAdditiveWeight === 0) {\r\n return cumulativeQuaternion;\r\n }\r\n } else if (holder.animations.length > 1) {\r\n // Add up the override animations\r\n let normalizer = 1.0;\r\n let quaternions: Array;\r\n let weights: Array;\r\n\r\n if (holder.totalWeight < 1.0) {\r\n const scale = 1.0 - holder.totalWeight;\r\n\r\n quaternions = [];\r\n weights = [];\r\n\r\n quaternions.push(originalValue);\r\n weights.push(scale);\r\n } else {\r\n if (holder.animations.length === 2) {\r\n // Slerp as soon as we can\r\n Quaternion.SlerpToRef(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight, refQuaternion);\r\n\r\n if (holder.totalAdditiveWeight === 0) {\r\n return refQuaternion;\r\n }\r\n }\r\n\r\n quaternions = [];\r\n weights = [];\r\n normalizer = holder.totalWeight;\r\n }\r\n\r\n for (let animIndex = 0; animIndex < holder.animations.length; animIndex++) {\r\n const runtimeAnimation = holder.animations[animIndex];\r\n quaternions.push(runtimeAnimation.currentValue);\r\n weights.push(runtimeAnimation.weight / normalizer);\r\n }\r\n\r\n // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions\r\n\r\n let cumulativeAmount = 0;\r\n for (let index = 0; index < quaternions.length; ) {\r\n if (!index) {\r\n Quaternion.SlerpToRef(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]), refQuaternion);\r\n cumulativeQuaternion = refQuaternion;\r\n cumulativeAmount = weights[index] + weights[index + 1];\r\n index += 2;\r\n continue;\r\n }\r\n cumulativeAmount += weights[index];\r\n Quaternion.SlerpToRef(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount, cumulativeQuaternion);\r\n index++;\r\n }\r\n }\r\n\r\n // Add up the additive animations\r\n for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {\r\n const runtimeAnimation = holder.additiveAnimations[animIndex];\r\n if (runtimeAnimation.weight === 0) {\r\n continue;\r\n }\r\n\r\n cumulativeQuaternion.multiplyToRef(runtimeAnimation.currentValue, TmpVectors.Quaternion[0]);\r\n Quaternion.SlerpToRef(cumulativeQuaternion, TmpVectors.Quaternion[0], runtimeAnimation.weight, cumulativeQuaternion);\r\n }\r\n\r\n return cumulativeQuaternion!;\r\n};\r\n\r\nScene.prototype._processLateAnimationBindings = function (): void {\r\n if (!this._registeredForLateAnimationBindings.length) {\r\n return;\r\n }\r\n for (let index = 0; index < this._registeredForLateAnimationBindings.length; index++) {\r\n const target = this._registeredForLateAnimationBindings.data[index];\r\n\r\n for (const path in target._lateAnimationHolders) {\r\n const holder = target._lateAnimationHolders[path];\r\n const originalAnimation: RuntimeAnimation = holder.animations[0];\r\n const originalValue = holder.originalValue;\r\n if (originalValue === undefined || originalValue === null) {\r\n continue;\r\n }\r\n const matrixDecomposeMode = Animation.AllowMatrixDecomposeForInterpolation && originalValue.m; // ie. data is matrix\r\n\r\n let finalValue: any = target[path];\r\n if (matrixDecomposeMode) {\r\n finalValue = this._processLateAnimationBindingsForMatrices(holder);\r\n } else {\r\n const quaternionMode = originalValue.w !== undefined;\r\n if (quaternionMode) {\r\n finalValue = this._processLateAnimationBindingsForQuaternions(holder, finalValue || Quaternion.Identity());\r\n } else {\r\n let startIndex = 0;\r\n let normalizer = 1.0;\r\n\r\n if (holder.totalWeight < 1.0) {\r\n // We need to mix the original value in\r\n if (originalAnimation && originalValue.scale) {\r\n finalValue = originalValue.scale(1.0 - holder.totalWeight);\r\n } else if (originalAnimation) {\r\n finalValue = originalValue * (1.0 - holder.totalWeight);\r\n } else if (originalValue.clone) {\r\n finalValue = originalValue.clone();\r\n } else {\r\n finalValue = originalValue;\r\n }\r\n } else if (originalAnimation) {\r\n // We need to normalize the weights\r\n normalizer = holder.totalWeight;\r\n const scale = originalAnimation.weight / normalizer;\r\n if (scale !== 1) {\r\n if (originalAnimation.currentValue.scale) {\r\n finalValue = originalAnimation.currentValue.scale(scale);\r\n } else {\r\n finalValue = originalAnimation.currentValue * scale;\r\n }\r\n } else {\r\n finalValue = originalAnimation.currentValue;\r\n }\r\n\r\n startIndex = 1;\r\n }\r\n\r\n // Add up the override animations\r\n for (let animIndex = startIndex; animIndex < holder.animations.length; animIndex++) {\r\n const runtimeAnimation = holder.animations[animIndex];\r\n const scale = runtimeAnimation.weight / normalizer;\r\n\r\n if (!scale) {\r\n continue;\r\n } else if (runtimeAnimation.currentValue.scaleAndAddToRef) {\r\n runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);\r\n } else {\r\n finalValue += runtimeAnimation.currentValue * scale;\r\n }\r\n }\r\n\r\n // Add up the additive animations\r\n for (let animIndex = 0; animIndex < holder.additiveAnimations.length; animIndex++) {\r\n const runtimeAnimation = holder.additiveAnimations[animIndex];\r\n const scale: number = runtimeAnimation.weight;\r\n\r\n if (!scale) {\r\n continue;\r\n } else if (runtimeAnimation.currentValue.scaleAndAddToRef) {\r\n runtimeAnimation.currentValue.scaleAndAddToRef(scale, finalValue);\r\n } else {\r\n finalValue += runtimeAnimation.currentValue * scale;\r\n }\r\n }\r\n }\r\n }\r\n target[path] = finalValue;\r\n }\r\n\r\n target._lateAnimationHolders = {};\r\n }\r\n this._registeredForLateAnimationBindings.reset();\r\n};\r\n\r\ndeclare module \"../Bones/bone\" {\r\n export interface Bone {\r\n /**\r\n * Copy an animation range from another bone\r\n * @param source defines the source bone\r\n * @param rangeName defines the range name to copy\r\n * @param frameOffset defines the frame offset\r\n * @param rescaleAsRequired defines if rescaling must be applied if required\r\n * @param skelDimensionsRatio defines the scaling ratio\r\n * @returns true if operation was successful\r\n */\r\n copyAnimationRange(source: Bone, rangeName: string, frameOffset: number, rescaleAsRequired: boolean, skelDimensionsRatio: Nullable): boolean;\r\n }\r\n}\r\n\r\nBone.prototype.copyAnimationRange = function (\r\n source: Bone,\r\n rangeName: string,\r\n frameOffset: number,\r\n rescaleAsRequired = false,\r\n skelDimensionsRatio: Nullable = null\r\n): boolean {\r\n // all animation may be coming from a library skeleton, so may need to create animation\r\n if (this.animations.length === 0) {\r\n this.animations.push(new Animation(this.name, \"_matrix\", source.animations[0].framePerSecond, Animation.ANIMATIONTYPE_MATRIX, 0));\r\n this.animations[0].setKeys([]);\r\n }\r\n\r\n // get animation info / verify there is such a range from the source bone\r\n const sourceRange = source.animations[0].getRange(rangeName);\r\n if (!sourceRange) {\r\n return false;\r\n }\r\n const from = sourceRange.from;\r\n const to = sourceRange.to;\r\n const sourceKeys = source.animations[0].getKeys();\r\n\r\n // rescaling prep\r\n const sourceBoneLength = source.length;\r\n const sourceParent = source.getParent();\r\n const parent = this.getParent();\r\n const parentScalingReqd = rescaleAsRequired && sourceParent && sourceBoneLength && this.length && sourceBoneLength !== this.length;\r\n const parentRatio = parentScalingReqd && parent && sourceParent ? parent.length / sourceParent.length : 1;\r\n\r\n const dimensionsScalingReqd =\r\n rescaleAsRequired && !parent && skelDimensionsRatio && (skelDimensionsRatio.x !== 1 || skelDimensionsRatio.y !== 1 || skelDimensionsRatio.z !== 1);\r\n\r\n const destKeys = this.animations[0].getKeys();\r\n\r\n // loop vars declaration\r\n let orig: { frame: number; value: Matrix };\r\n let origTranslation: Vector3;\r\n let mat: Matrix;\r\n\r\n for (let key = 0, nKeys = sourceKeys.length; key < nKeys; key++) {\r\n orig = sourceKeys[key];\r\n if (orig.frame >= from && orig.frame <= to) {\r\n if (rescaleAsRequired) {\r\n mat = orig.value.clone();\r\n\r\n // scale based on parent ratio, when bone has parent\r\n if (parentScalingReqd) {\r\n origTranslation = mat.getTranslation();\r\n mat.setTranslation(origTranslation.scaleInPlace(parentRatio));\r\n\r\n // scale based on skeleton dimension ratio when root bone, and value is passed\r\n } else if (dimensionsScalingReqd && skelDimensionsRatio) {\r\n origTranslation = mat.getTranslation();\r\n mat.setTranslation(origTranslation.multiplyInPlace(skelDimensionsRatio));\r\n\r\n // use original when root bone, and no data for skelDimensionsRatio\r\n } else {\r\n mat = orig.value;\r\n }\r\n } else {\r\n mat = orig.value;\r\n }\r\n destKeys.push({ frame: orig.frame + frameOffset, value: mat });\r\n }\r\n }\r\n this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);\r\n return true;\r\n};\r\n","import type { Nullable } from \"../types\";\r\nimport type { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\n\r\n/** Covers all supported subclasses of WebXR's XRCompositionLayer */\r\n// TODO (rgerd): Extend for all other subclasses of XRCompositionLayer.\r\nexport type WebXRCompositionLayerType = \"XRProjectionLayer\";\r\n\r\n/** Covers all supported subclasses of WebXR's XRLayer */\r\nexport type WebXRLayerType = \"XRWebGLLayer\" | WebXRCompositionLayerType;\r\n\r\n/**\r\n * Wrapper over subclasses of XRLayer.\r\n * @internal\r\n */\r\nexport class WebXRLayerWrapper {\r\n /**\r\n * Check if fixed foveation is supported on this device\r\n */\r\n public get isFixedFoveationSupported(): boolean {\r\n return this.layerType == \"XRWebGLLayer\" && typeof (this.layer as XRWebGLLayer).fixedFoveation == \"number\";\r\n }\r\n\r\n /**\r\n * Get the fixed foveation currently set, as specified by the webxr specs\r\n * If this returns null, then fixed foveation is not supported\r\n */\r\n public get fixedFoveation(): Nullable {\r\n if (this.isFixedFoveationSupported) {\r\n return (this.layer as XRWebGLLayer).fixedFoveation!;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Set the fixed foveation to the specified value, as specified by the webxr specs\r\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\r\n */\r\n public set fixedFoveation(value: Nullable) {\r\n if (this.isFixedFoveationSupported) {\r\n const val = Math.max(0, Math.min(1, value || 0));\r\n (this.layer as XRWebGLLayer).fixedFoveation = val;\r\n }\r\n }\r\n\r\n protected constructor(\r\n /** The width of the layer's framebuffer. */\r\n public getWidth: () => number,\r\n /** The height of the layer's framebuffer. */\r\n public getHeight: () => number,\r\n /** The XR layer that this WebXRLayerWrapper wraps. */\r\n public readonly layer: XRLayer,\r\n /** The type of XR layer that is being wrapped. */\r\n public readonly layerType: WebXRLayerType,\r\n /** Create a render target provider for the wrapped layer. */\r\n public createRenderTargetTextureProvider: (xrSessionManager: WebXRSessionManager) => WebXRLayerRenderTargetTextureProvider\r\n ) {}\r\n}\r\n","import type { Engine } from \"../Engines/engine\";\r\nimport { WebGLHardwareTexture } from \"../Engines/WebGL/webGLHardwareTexture\";\r\nimport type { WebGLRenderTargetWrapper } from \"../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { MultiviewRenderTarget } from \"../Materials/Textures/MultiviewRenderTarget\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\n\r\n/**\r\n * An interface for objects that provide render target textures for XR rendering.\r\n */\r\nexport interface IWebXRRenderTargetTextureProvider extends IDisposable {\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n getRenderTargetTextureForEye(eye: XREye): Nullable;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n getRenderTargetTextureForView(view: XRView): Nullable;\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRLayer.\r\n * @internal\r\n */\r\nexport abstract class WebXRLayerRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n public abstract trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n public abstract getRenderTargetTextureForEye(eye: XREye): Nullable;\r\n public abstract getRenderTargetTextureForView(view: XRView): Nullable;\r\n\r\n protected _renderTargetTextures = new Array();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n\r\n private _engine: Engine;\r\n\r\n constructor(private readonly _scene: Scene, public readonly layerWrapper: WebXRLayerWrapper) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _createInternalTexture(textureSize: { width: number; height: number }, texture: WebGLTexture): InternalTexture {\r\n const internalTexture = new InternalTexture(this._engine, InternalTextureSource.Unknown, true);\r\n internalTexture.width = textureSize.width;\r\n internalTexture.height = textureSize.height;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, this._engine._gl);\r\n internalTexture.isReady = true;\r\n return internalTexture;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable,\r\n colorTexture?: WebGLTexture,\r\n depthStencilTexture?: WebGLTexture,\r\n multiview?: boolean\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = multiview ? new MultiviewRenderTarget(this._scene, textureSize) : new RenderTargetTexture(\"XR renderTargetTexture\", textureSize, this._scene);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n renderTargetWrapper._samples = renderTargetTexture.samples;\r\n // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers\r\n if (framebuffer || !colorTexture) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n if (colorTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._colorTextureArray = colorTexture;\r\n } else {\r\n const internalTexture = this._createInternalTexture(textureSize, colorTexture);\r\n renderTargetWrapper.setTexture(internalTexture, 0);\r\n renderTargetTexture._texture = internalTexture;\r\n }\r\n }\r\n\r\n if (depthStencilTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n } else {\r\n renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture);\r\n }\r\n }\r\n\r\n renderTargetTexture.disableRescaling();\r\n // Firefox reality fails if skipInitialClear is set to true, so make sure only modern XR implementations set it.\r\n if (typeof XRWebGLBinding !== \"undefined\") {\r\n // WebXR pre-clears textures\r\n renderTargetTexture.skipInitialClear = true;\r\n }\r\n\r\n this._renderTargetTextures.push(renderTargetTexture);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _destroyRenderTargetTexture(renderTargetTexture: RenderTargetTexture) {\r\n this._renderTargetTextures.splice(this._renderTargetTextures.indexOf(renderTargetTexture), 1);\r\n renderTargetTexture.dispose();\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return this._framebufferDimensions;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.length = 0;\r\n }\r\n}\r\n","import type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\n\r\n/**\r\n * Wraps xr webgl layers.\r\n * @internal\r\n */\r\nexport class WebXRWebGLLayerWrapper extends WebXRLayerWrapper {\r\n /**\r\n * @param layer is the layer to be wrapped.\r\n * @returns a new WebXRLayerWrapper wrapping the provided XRWebGLLayer.\r\n */\r\n constructor(public readonly layer: XRWebGLLayer) {\r\n super(\r\n () => layer.framebufferWidth,\r\n () => layer.framebufferHeight,\r\n layer,\r\n \"XRWebGLLayer\",\r\n (sessionManager) => new WebXRWebGLLayerRenderTargetTextureProvider(sessionManager.scene, this)\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRWebGLLayer.\r\n * @internal\r\n */\r\nexport class WebXRWebGLLayerRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\r\n // The dimensions will always be defined in this class.\r\n protected _framebufferDimensions: { framebufferWidth: number; framebufferHeight: number };\r\n private _rtt: Nullable;\r\n private _framebuffer: WebGLFramebuffer;\r\n private _layer: XRWebGLLayer;\r\n\r\n constructor(scene: Scene, public readonly layerWrapper: WebXRWebGLLayerWrapper) {\r\n super(scene, layerWrapper);\r\n this._layer = layerWrapper.layer;\r\n this._framebufferDimensions = {\r\n framebufferWidth: this._layer.framebufferWidth,\r\n framebufferHeight: this._layer.framebufferHeight,\r\n };\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const xrViewport = this._layer.getViewport(view);\r\n if (!xrViewport) {\r\n return false;\r\n }\r\n const framebufferWidth = this._framebufferDimensions.framebufferWidth;\r\n const framebufferHeight = this._framebufferDimensions.framebufferHeight;\r\n viewport.x = xrViewport.x / framebufferWidth;\r\n viewport.y = xrViewport.y / framebufferHeight;\r\n viewport.width = xrViewport.width / framebufferWidth;\r\n viewport.height = xrViewport.height / framebufferHeight;\r\n return true;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable {\r\n const layerWidth = this._layer.framebufferWidth;\r\n const layerHeight = this._layer.framebufferHeight;\r\n const framebuffer = this._layer.framebuffer;\r\n\r\n if (\r\n !this._rtt ||\r\n layerWidth !== this._framebufferDimensions.framebufferWidth ||\r\n layerHeight !== this._framebufferDimensions.framebufferHeight ||\r\n framebuffer !== this._framebuffer\r\n ) {\r\n this._rtt = this._createRenderTargetTexture(layerWidth, layerHeight, framebuffer);\r\n this._framebufferDimensions.framebufferWidth = layerWidth;\r\n this._framebufferDimensions.framebufferHeight = layerHeight;\r\n this._framebuffer = framebuffer;\r\n }\r\n\r\n return this._rtt;\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable {\r\n return this.getRenderTargetTextureForEye(view.eye);\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { WebXRWebGLLayerWrapper } from \"./webXRWebGLLayer\";\r\n\r\n/**\r\n * Configuration object for WebXR output canvas\r\n */\r\nexport class WebXRManagedOutputCanvasOptions {\r\n /**\r\n * An optional canvas in case you wish to create it yourself and provide it here.\r\n * If not provided, a new canvas will be created\r\n */\r\n public canvasElement?: HTMLCanvasElement;\r\n /**\r\n * Options for this XR Layer output\r\n */\r\n public canvasOptions?: XRWebGLLayerInit;\r\n /**\r\n * CSS styling for a newly created canvas (if not provided)\r\n */\r\n public newCanvasCssStyle?: string;\r\n\r\n /**\r\n * Get the default values of the configuration object\r\n * @param engine defines the engine to use (can be null)\r\n * @returns default values of this configuration object\r\n */\r\n public static GetDefaults(engine?: ThinEngine): WebXRManagedOutputCanvasOptions {\r\n const defaults = new WebXRManagedOutputCanvasOptions();\r\n defaults.canvasOptions = {\r\n antialias: true,\r\n depth: true,\r\n stencil: engine ? engine.isStencilEnable : true,\r\n alpha: true,\r\n framebufferScaleFactor: 1,\r\n };\r\n\r\n defaults.newCanvasCssStyle = \"position:absolute; bottom:0px;right:0px;z-index:10;width:90%;height:100%;background-color: #000000;\";\r\n\r\n return defaults;\r\n }\r\n}\r\n/**\r\n * Creates a canvas that is added/removed from the webpage when entering/exiting XR\r\n */\r\nexport class WebXRManagedOutputCanvas implements WebXRRenderTarget {\r\n private _canvas: Nullable = null;\r\n private _engine: Nullable = null;\r\n private _originalCanvasSize: {\r\n width: number;\r\n height: number;\r\n };\r\n\r\n /**\r\n * Rendering context of the canvas which can be used to display/mirror xr content\r\n */\r\n public canvasContext: WebGLRenderingContext;\r\n\r\n /**\r\n * xr layer for the canvas\r\n */\r\n public xrLayer: Nullable = null;\r\n\r\n private _xrLayerWrapper: Nullable = null;\r\n\r\n /**\r\n * Observers registered here will be triggered when the xr layer was initialized\r\n */\r\n public onXRLayerInitObservable: Observable = new Observable();\r\n\r\n /**\r\n * Initializes the canvas to be added/removed upon entering/exiting xr\r\n * @param _xrSessionManager The XR Session manager\r\n * @param _options optional configuration for this canvas output. defaults will be used if not provided\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private _options: WebXRManagedOutputCanvasOptions = WebXRManagedOutputCanvasOptions.GetDefaults()) {\r\n this._engine = _xrSessionManager.scene.getEngine();\r\n this._engine.onDisposeObservable.addOnce(() => {\r\n this._engine = null;\r\n });\r\n\r\n if (!_options.canvasElement) {\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.style.cssText = this._options.newCanvasCssStyle || \"position:absolute; bottom:0px;right:0px;\";\r\n this._setManagedOutputCanvas(canvas);\r\n } else {\r\n this._setManagedOutputCanvas(_options.canvasElement);\r\n }\r\n\r\n _xrSessionManager.onXRSessionInit.add(() => {\r\n this._addCanvas();\r\n });\r\n\r\n _xrSessionManager.onXRSessionEnded.add(() => {\r\n this._removeCanvas();\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this._removeCanvas();\r\n this._setManagedOutputCanvas(null);\r\n }\r\n\r\n /**\r\n * Initializes a XRWebGLLayer to be used as the session's baseLayer.\r\n * @param xrSession xr session\r\n * @returns a promise that will resolve once the XR Layer has been created\r\n */\r\n public async initializeXRLayerAsync(xrSession: XRSession): Promise {\r\n const createLayer = () => {\r\n this.xrLayer = new XRWebGLLayer(xrSession, this.canvasContext, this._options.canvasOptions);\r\n this._xrLayerWrapper = new WebXRWebGLLayerWrapper(this.xrLayer);\r\n this.onXRLayerInitObservable.notifyObservers(this.xrLayer);\r\n return this.xrLayer;\r\n };\r\n\r\n // support canvases without makeXRCompatible\r\n if (!(this.canvasContext as any).makeXRCompatible) {\r\n return Promise.resolve(createLayer());\r\n }\r\n\r\n return (this.canvasContext as any)\r\n .makeXRCompatible()\r\n .then(\r\n // catch any error and continue. When using the emulator is throws this error for no apparent reason.\r\n () => {},\r\n () => {\r\n // log the error, continue nonetheless!\r\n Tools.Warn(\"Error executing makeXRCompatible. This does not mean that the session will work incorrectly.\");\r\n }\r\n )\r\n .then(() => {\r\n return createLayer();\r\n });\r\n }\r\n\r\n private _addCanvas() {\r\n if (this._canvas && this._engine && this._canvas !== this._engine.getRenderingCanvas()) {\r\n document.body.appendChild(this._canvas);\r\n }\r\n if (this.xrLayer) {\r\n this._setCanvasSize(true);\r\n } else {\r\n this.onXRLayerInitObservable.addOnce(() => {\r\n this._setCanvasSize(true);\r\n });\r\n }\r\n }\r\n\r\n private _removeCanvas() {\r\n if (this._canvas && this._engine && document.body.contains(this._canvas) && this._canvas !== this._engine.getRenderingCanvas()) {\r\n document.body.removeChild(this._canvas);\r\n }\r\n this._setCanvasSize(false);\r\n }\r\n\r\n private _setCanvasSize(init: boolean = true, xrLayer = this._xrLayerWrapper) {\r\n if (!this._canvas || !this._engine) {\r\n return;\r\n }\r\n if (init) {\r\n if (xrLayer) {\r\n if (this._canvas !== this._engine.getRenderingCanvas()) {\r\n this._canvas.style.width = xrLayer.getWidth() + \"px\";\r\n this._canvas.style.height = xrLayer.getHeight() + \"px\";\r\n } else {\r\n this._engine.setSize(xrLayer.getWidth(), xrLayer.getHeight());\r\n }\r\n }\r\n } else {\r\n if (this._originalCanvasSize) {\r\n if (this._canvas !== this._engine.getRenderingCanvas()) {\r\n this._canvas.style.width = this._originalCanvasSize.width + \"px\";\r\n this._canvas.style.height = this._originalCanvasSize.height + \"px\";\r\n } else {\r\n this._engine.setSize(this._originalCanvasSize.width, this._originalCanvasSize.height);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _setManagedOutputCanvas(canvas: Nullable) {\r\n this._removeCanvas();\r\n if (!canvas) {\r\n this._canvas = null;\r\n (this.canvasContext as any) = null;\r\n } else {\r\n this._originalCanvasSize = {\r\n width: canvas.offsetWidth,\r\n height: canvas.offsetHeight,\r\n };\r\n this._canvas = canvas;\r\n this.canvasContext = this._canvas.getContext(\"webgl2\");\r\n if (!this.canvasContext) {\r\n this.canvasContext = this._canvas.getContext(\"webgl\");\r\n }\r\n }\r\n }\r\n}\r\n","import type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { WebXRLayerWrapper } from \"../webXRLayerWrapper\";\r\nimport { WebXRLayerRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { WebXRRenderTarget } from \"../webXRTypes\";\r\n\r\n/**\r\n * Wraps XRWebGLLayer's created by Babylon Native.\r\n * @internal\r\n */\r\nexport class NativeXRLayerWrapper extends WebXRLayerWrapper {\r\n constructor(public readonly layer: XRWebGLLayer) {\r\n super(\r\n () => layer.framebufferWidth,\r\n () => layer.framebufferHeight,\r\n layer,\r\n \"XRWebGLLayer\",\r\n (sessionManager) => new NativeXRLayerRenderTargetTextureProvider(sessionManager, this)\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Provides render target textures for layers created by Babylon Native.\r\n * @internal\r\n */\r\nexport class NativeXRLayerRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\r\n private _nativeRTTProvider: WebXRLayerRenderTargetTextureProvider;\r\n private _nativeLayer: XRWebGLLayer;\r\n\r\n constructor(sessionManager: WebXRSessionManager, public readonly layerWrapper: NativeXRLayerWrapper) {\r\n super(sessionManager.scene, layerWrapper);\r\n this._nativeRTTProvider = (navigator as any).xr.getNativeRenderTargetProvider(\r\n sessionManager.session,\r\n this._createRenderTargetTexture.bind(this),\r\n this._destroyRenderTargetTexture.bind(this)\r\n );\r\n this._nativeLayer = layerWrapper.layer;\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport): boolean {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = 1;\r\n viewport.height = 1;\r\n return true;\r\n }\r\n\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable {\r\n // TODO (rgerd): Update the contract on the BabylonNative side to call this \"getRenderTargetTextureForEye\"\r\n return (this._nativeRTTProvider as any).getRenderTargetForEye(eye);\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable {\r\n return (this._nativeRTTProvider as any).getRenderTargetForEye(view.eye);\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return {\r\n framebufferWidth: this._nativeLayer.framebufferWidth,\r\n framebufferHeight: this._nativeLayer.framebufferHeight,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Creates the xr layer that will be used as the xr session's base layer.\r\n * @internal\r\n */\r\nexport class NativeXRRenderTarget implements WebXRRenderTarget {\r\n public canvasContext: WebGLRenderingContext;\r\n public xrLayer: Nullable;\r\n\r\n private _nativeRenderTarget: WebXRRenderTarget;\r\n\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n this._nativeRenderTarget = (navigator as any).xr.getWebXRRenderTarget(_xrSessionManager.scene.getEngine());\r\n }\r\n\r\n public async initializeXRLayerAsync(xrSession: XRSession): Promise {\r\n await this._nativeRenderTarget.initializeXRLayerAsync(xrSession);\r\n this.xrLayer = this._nativeRenderTarget.xrLayer!;\r\n return this.xrLayer;\r\n }\r\n\r\n dispose(): void {\r\n /* empty */\r\n }\r\n}\r\n","import { Logger } from \"../Misc/logger\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRManagedOutputCanvas, WebXRManagedOutputCanvasOptions } from \"./webXRManagedOutputCanvas\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { IWebXRRenderTargetTextureProvider, WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { NativeXRLayerWrapper, NativeXRRenderTarget } from \"./native/nativeXRRenderTarget\";\r\nimport { WebXRWebGLLayerWrapper } from \"./webXRWebGLLayer\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\n\r\n/**\r\n * Manages an XRSession to work with Babylon's engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRSessionManagers\r\n */\r\nexport class WebXRSessionManager implements IDisposable, IWebXRRenderTargetTextureProvider {\r\n private _engine: Nullable;\r\n private _referenceSpace: XRReferenceSpace;\r\n private _baseLayerWrapper: Nullable;\r\n private _baseLayerRTTProvider: Nullable;\r\n private _xrNavigator: any;\r\n private _sessionMode: XRSessionMode;\r\n private _onEngineDisposedObserver: Nullable>;\r\n\r\n /**\r\n * The base reference space from which the session started. good if you want to reset your\r\n * reference space\r\n */\r\n public baseReferenceSpace: XRReferenceSpace;\r\n /**\r\n * Current XR frame\r\n */\r\n public currentFrame: Nullable;\r\n /** WebXR timestamp updated every frame */\r\n public currentTimestamp: number = -1;\r\n /**\r\n * Used just in case of a failure to initialize an immersive session.\r\n * The viewer reference space is compensated using this height, creating a kind of \"viewer-floor\" reference space\r\n */\r\n public defaultHeightCompensation = 1.7;\r\n /**\r\n * Fires every time a new xrFrame arrives which can be used to update the camera\r\n */\r\n public onXRFrameObservable: Observable = new Observable();\r\n /**\r\n * Fires when the reference space changed\r\n */\r\n public onXRReferenceSpaceChanged: Observable = new Observable();\r\n /**\r\n * Fires when the xr session is ended either by the device or manually done\r\n */\r\n public onXRSessionEnded: Observable = new Observable();\r\n /**\r\n * Fires when the xr session is initialized: right after requestSession was called and returned with a successful result\r\n */\r\n public onXRSessionInit: Observable = new Observable();\r\n /**\r\n * Underlying xr session\r\n */\r\n public session: XRSession;\r\n /**\r\n * The viewer (head position) reference space. This can be used to get the XR world coordinates\r\n * or get the offset the player is currently at.\r\n */\r\n public viewerReferenceSpace: XRReferenceSpace;\r\n /**\r\n * Are we currently in the XR loop?\r\n */\r\n public inXRFrameLoop: boolean = false;\r\n /**\r\n * Are we in an XR session?\r\n */\r\n public inXRSession: boolean = false;\r\n\r\n /**\r\n * Constructs a WebXRSessionManager, this must be initialized within a user action before usage\r\n * @param scene The scene which the session should be created for\r\n */\r\n constructor(\r\n /** The scene which the session should be created for */\r\n public scene: Scene\r\n ) {\r\n this._engine = scene.getEngine();\r\n this._onEngineDisposedObserver = this._engine.onDisposeObservable.addOnce(() => {\r\n this._engine = null;\r\n });\r\n scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * The current reference space used in this session. This reference space can constantly change!\r\n * It is mainly used to offset the camera's position.\r\n */\r\n public get referenceSpace(): XRReferenceSpace {\r\n return this._referenceSpace;\r\n }\r\n\r\n /**\r\n * Set a new reference space and triggers the observable\r\n */\r\n public set referenceSpace(newReferenceSpace: XRReferenceSpace) {\r\n this._referenceSpace = newReferenceSpace;\r\n this.onXRReferenceSpaceChanged.notifyObservers(this._referenceSpace);\r\n }\r\n\r\n /**\r\n * The mode for the managed XR session\r\n */\r\n public get sessionMode(): XRSessionMode {\r\n return this._sessionMode;\r\n }\r\n\r\n /**\r\n * Disposes of the session manager\r\n * This should be called explicitly by the dev, if required.\r\n */\r\n public dispose() {\r\n // disposing without leaving XR? Exit XR first\r\n if (this.inXRSession) {\r\n this.exitXRAsync();\r\n }\r\n this.onXRFrameObservable.clear();\r\n this.onXRSessionEnded.clear();\r\n this.onXRReferenceSpaceChanged.clear();\r\n this.onXRSessionInit.clear();\r\n this._engine?.onDisposeObservable.remove(this._onEngineDisposedObserver);\r\n this._engine = null;\r\n }\r\n\r\n /**\r\n * Stops the xrSession and restores the render loop\r\n * @returns Promise which resolves after it exits XR\r\n */\r\n public exitXRAsync() {\r\n if (this.session && this.inXRSession) {\r\n this.inXRSession = false;\r\n return this.session.end().catch(() => {\r\n Logger.Warn(\"Could not end XR session.\");\r\n });\r\n }\r\n return Promise.resolve();\r\n }\r\n\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n return this._baseLayerRTTProvider?.trySetViewportForView(viewport, view) || false;\r\n }\r\n\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable {\r\n return this._baseLayerRTTProvider?.getRenderTargetTextureForEye(eye) || null;\r\n }\r\n\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable {\r\n return this._baseLayerRTTProvider?.getRenderTargetTextureForView(view) || null;\r\n }\r\n\r\n /**\r\n * Creates a WebXRRenderTarget object for the XR session\r\n * @param options optional options to provide when creating a new render target\r\n * @returns a WebXR render target to which the session can render\r\n */\r\n public getWebXRRenderTarget(options?: WebXRManagedOutputCanvasOptions): WebXRRenderTarget {\r\n const engine = this.scene.getEngine();\r\n if (this._xrNavigator.xr.native) {\r\n return new NativeXRRenderTarget(this);\r\n } else {\r\n options = options || WebXRManagedOutputCanvasOptions.GetDefaults(engine);\r\n options.canvasElement = options.canvasElement || engine.getRenderingCanvas() || undefined;\r\n return new WebXRManagedOutputCanvas(this, options);\r\n }\r\n }\r\n\r\n /**\r\n * Initializes the manager\r\n * After initialization enterXR can be called to start an XR session\r\n * @returns Promise which resolves after it is initialized\r\n */\r\n public initializeAsync(): Promise {\r\n // Check if the browser supports webXR\r\n this._xrNavigator = navigator;\r\n if (!this._xrNavigator.xr) {\r\n return Promise.reject(\"WebXR not available\");\r\n }\r\n return Promise.resolve();\r\n }\r\n\r\n /**\r\n * Initializes an xr session\r\n * @param xrSessionMode mode to initialize\r\n * @param xrSessionInit defines optional and required values to pass to the session builder\r\n * @returns a promise which will resolve once the session has been initialized\r\n */\r\n public initializeSessionAsync(xrSessionMode: XRSessionMode = \"immersive-vr\", xrSessionInit: XRSessionInit = {}): Promise {\r\n return this._xrNavigator.xr.requestSession(xrSessionMode, xrSessionInit).then((session: XRSession) => {\r\n this.session = session;\r\n this._sessionMode = xrSessionMode;\r\n this.onXRSessionInit.notifyObservers(session);\r\n this.inXRSession = true;\r\n\r\n // handle when the session is ended (By calling session.end or device ends its own session eg. pressing home button on phone)\r\n this.session.addEventListener(\r\n \"end\",\r\n () => {\r\n this.inXRSession = false;\r\n\r\n // Notify frame observers\r\n this.onXRSessionEnded.notifyObservers(null);\r\n\r\n if (this._engine) {\r\n // make sure dimensions object is restored\r\n this._engine.framebufferDimensionsObject = null;\r\n\r\n // Restore frame buffer to avoid clear on xr framebuffer after session end\r\n this._engine.restoreDefaultFramebuffer();\r\n\r\n // Need to restart render loop as after the session is ended the last request for new frame will never call callback\r\n this._engine.customAnimationFrameRequester = null;\r\n this._engine._renderLoop();\r\n }\r\n\r\n // Dispose render target textures.\r\n // Only dispose on native because we can't destroy opaque textures on browser.\r\n if (this.isNative) {\r\n this._baseLayerRTTProvider?.dispose();\r\n }\r\n this._baseLayerRTTProvider = null;\r\n this._baseLayerWrapper = null;\r\n },\r\n { once: true }\r\n );\r\n\r\n return this.session;\r\n });\r\n }\r\n\r\n /**\r\n * Checks if a session would be supported for the creation options specified\r\n * @param sessionMode session mode to check if supported eg. immersive-vr\r\n * @returns A Promise that resolves to true if supported and false if not\r\n */\r\n public isSessionSupportedAsync(sessionMode: XRSessionMode): Promise {\r\n return WebXRSessionManager.IsSessionSupportedAsync(sessionMode);\r\n }\r\n\r\n /**\r\n * Resets the reference space to the one started the session\r\n */\r\n public resetReferenceSpace() {\r\n this.referenceSpace = this.baseReferenceSpace;\r\n }\r\n\r\n /**\r\n * Starts rendering to the xr layer\r\n */\r\n public runXRRenderLoop() {\r\n if (!this.inXRSession || !this._engine) {\r\n return;\r\n }\r\n\r\n // Tell the engine's render loop to be driven by the xr session's refresh rate and provide xr pose information\r\n this._engine.customAnimationFrameRequester = {\r\n requestAnimationFrame: this.session.requestAnimationFrame.bind(this.session),\r\n renderFunction: (timestamp: number, xrFrame: Nullable) => {\r\n if (!this.inXRSession || !this._engine) {\r\n return;\r\n }\r\n // Store the XR frame and timestamp in the session manager\r\n this.currentFrame = xrFrame;\r\n this.currentTimestamp = timestamp;\r\n if (xrFrame) {\r\n this.inXRFrameLoop = true;\r\n this._engine.framebufferDimensionsObject = this._baseLayerRTTProvider?.getFramebufferDimensions() || null;\r\n this.onXRFrameObservable.notifyObservers(xrFrame);\r\n this._engine._renderLoop();\r\n this._engine.framebufferDimensionsObject = null;\r\n this.inXRFrameLoop = false;\r\n }\r\n },\r\n };\r\n\r\n this._engine.framebufferDimensionsObject = this._baseLayerRTTProvider?.getFramebufferDimensions() || null;\r\n\r\n // Stop window's animation frame and trigger sessions animation frame\r\n if (typeof window !== \"undefined\" && window.cancelAnimationFrame) {\r\n window.cancelAnimationFrame(this._engine._frameHandler);\r\n }\r\n this._engine._renderLoop();\r\n }\r\n\r\n /**\r\n * Sets the reference space on the xr session\r\n * @param referenceSpaceType space to set\r\n * @returns a promise that will resolve once the reference space has been set\r\n */\r\n public setReferenceSpaceTypeAsync(referenceSpaceType: XRReferenceSpaceType = \"local-floor\"): Promise {\r\n return this.session\r\n .requestReferenceSpace(referenceSpaceType)\r\n .then(\r\n (referenceSpace) => {\r\n return referenceSpace as XRReferenceSpace;\r\n },\r\n (rejectionReason) => {\r\n Logger.Error(\"XR.requestReferenceSpace failed for the following reason: \");\r\n Logger.Error(rejectionReason);\r\n Logger.Log('Defaulting to universally-supported \"viewer\" reference space type.');\r\n\r\n return this.session.requestReferenceSpace(\"viewer\").then(\r\n (referenceSpace) => {\r\n const heightCompensation = new XRRigidTransform({ x: 0, y: -this.defaultHeightCompensation, z: 0 });\r\n return (referenceSpace as XRReferenceSpace).getOffsetReferenceSpace(heightCompensation);\r\n },\r\n (rejectionReason) => {\r\n Logger.Error(rejectionReason);\r\n throw 'XR initialization failed: required \"viewer\" reference space type not supported.';\r\n }\r\n );\r\n }\r\n )\r\n .then((referenceSpace) => {\r\n // create viewer reference space before setting the first reference space\r\n return this.session.requestReferenceSpace(\"viewer\").then((viewerReferenceSpace) => {\r\n this.viewerReferenceSpace = viewerReferenceSpace as XRReferenceSpace;\r\n return referenceSpace;\r\n });\r\n })\r\n .then((referenceSpace) => {\r\n // initialize the base and offset (currently the same)\r\n this.referenceSpace = this.baseReferenceSpace = referenceSpace;\r\n return this.referenceSpace;\r\n });\r\n }\r\n\r\n /**\r\n * Updates the render state of the session.\r\n * Note that this is deprecated in favor of WebXRSessionManager.updateRenderState().\r\n * @param state state to set\r\n * @returns a promise that resolves once the render state has been updated\r\n * @deprecated\r\n */\r\n public updateRenderStateAsync(state: XRRenderState): Promise {\r\n return Promise.resolve(this.session.updateRenderState(state));\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setBaseLayerWrapper(baseLayerWrapper: Nullable): void {\r\n if (this.isNative) {\r\n this._baseLayerRTTProvider?.dispose();\r\n }\r\n this._baseLayerWrapper = baseLayerWrapper;\r\n this._baseLayerRTTProvider = this._baseLayerWrapper?.createRenderTargetTextureProvider(this) || null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getBaseLayerWrapper(): Nullable {\r\n return this._baseLayerWrapper;\r\n }\r\n\r\n /**\r\n * Updates the render state of the session\r\n * @param state state to set\r\n */\r\n public updateRenderState(state: XRRenderStateInit): void {\r\n if (state.baseLayer) {\r\n this._setBaseLayerWrapper(this.isNative ? new NativeXRLayerWrapper(state.baseLayer) : new WebXRWebGLLayerWrapper(state.baseLayer));\r\n }\r\n\r\n this.session.updateRenderState(state);\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves with a boolean indicating if the provided session mode is supported by this browser\r\n * @param sessionMode defines the session to test\r\n * @returns a promise with boolean as final value\r\n */\r\n public static IsSessionSupportedAsync(sessionMode: XRSessionMode): Promise {\r\n if (!(navigator as any).xr) {\r\n return Promise.resolve(false);\r\n }\r\n // When the specs are final, remove supportsSession!\r\n const functionToUse = (navigator as any).xr.isSessionSupported || (navigator as any).xr.supportsSession;\r\n if (!functionToUse) {\r\n return Promise.resolve(false);\r\n } else {\r\n return functionToUse\r\n .call((navigator as any).xr, sessionMode)\r\n .then((result: boolean) => {\r\n const returnValue = typeof result === \"undefined\" ? true : result;\r\n return Promise.resolve(returnValue);\r\n })\r\n .catch((e: any) => {\r\n Logger.Warn(e);\r\n return Promise.resolve(false);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Returns true if Babylon.js is using the BabylonNative backend, otherwise false\r\n */\r\n public get isNative(): boolean {\r\n return this._xrNavigator.xr.native ?? false;\r\n }\r\n\r\n /**\r\n * The current frame rate as reported by the device\r\n */\r\n public get currentFrameRate(): number | undefined {\r\n return this.session?.frameRate;\r\n }\r\n\r\n /**\r\n * A list of supported frame rates (only available in-session!\r\n */\r\n public get supportedFrameRates(): Float32Array | undefined {\r\n return this.session?.supportedFrameRates;\r\n }\r\n\r\n /**\r\n * Set the framerate of the session.\r\n * @param rate the new framerate. This value needs to be in the supportedFrameRates array\r\n * @returns a promise that resolves once the framerate has been set\r\n */\r\n public updateTargetFrameRate(rate: number): Promise {\r\n return this.session.updateTargetFrameRate(rate);\r\n }\r\n\r\n /**\r\n * Run a callback in the xr render loop\r\n * @param callback the callback to call when in XR Frame\r\n * @param ignoreIfNotInSession if no session is currently running, run it first thing on the next session\r\n */\r\n public runInXRFrame(callback: () => void, ignoreIfNotInSession = true): void {\r\n if (this.inXRFrameLoop) {\r\n callback();\r\n } else if (this.inXRSession || !ignoreIfNotInSession) {\r\n this.onXRFrameObservable.addOnce(callback);\r\n }\r\n }\r\n\r\n /**\r\n * Check if fixed foveation is supported on this device\r\n */\r\n public get isFixedFoveationSupported(): boolean {\r\n return this._baseLayerWrapper?.isFixedFoveationSupported || false;\r\n }\r\n\r\n /**\r\n * Get the fixed foveation currently set, as specified by the webxr specs\r\n * If this returns null, then fixed foveation is not supported\r\n */\r\n public get fixedFoveation(): Nullable {\r\n return this._baseLayerWrapper?.fixedFoveation || null;\r\n }\r\n\r\n /**\r\n * Set the fixed foveation to the specified value, as specified by the webxr specs\r\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\r\n */\r\n public set fixedFoveation(value: Nullable) {\r\n const val = Math.max(0, Math.min(1, value || 0));\r\n if (this._baseLayerWrapper) {\r\n this._baseLayerWrapper.fixedFoveation = val;\r\n }\r\n }\r\n\r\n /**\r\n * Get the features enabled on the current session\r\n * This is only available in-session!\r\n * @see https://www.w3.org/TR/webxr/#dom-xrsession-enabledfeatures\r\n */\r\n public get enabledFeatures(): Nullable {\r\n return this.session?.enabledFeatures ?? null;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { IDisposable } from \"../scene\";\r\n\r\n/**\r\n * States of the webXR experience\r\n */\r\nexport enum WebXRState {\r\n /**\r\n * Transitioning to being in XR mode\r\n */\r\n ENTERING_XR,\r\n /**\r\n * Transitioning to non XR mode\r\n */\r\n EXITING_XR,\r\n /**\r\n * In XR mode and presenting\r\n */\r\n IN_XR,\r\n /**\r\n * Not entered XR mode\r\n */\r\n NOT_IN_XR,\r\n}\r\n\r\n/**\r\n * The state of the XR camera's tracking\r\n */\r\nexport enum WebXRTrackingState {\r\n /**\r\n * No transformation received, device is not being tracked\r\n */\r\n NOT_TRACKING,\r\n /**\r\n * Tracking lost - using emulated position\r\n */\r\n TRACKING_LOST,\r\n /**\r\n * Transformation tracking works normally\r\n */\r\n TRACKING,\r\n}\r\n\r\n/**\r\n * Abstraction of the XR render target\r\n */\r\nexport interface WebXRRenderTarget extends IDisposable {\r\n /**\r\n * xrpresent context of the canvas which can be used to display/mirror xr content\r\n */\r\n canvasContext: WebGLRenderingContext;\r\n\r\n /**\r\n * xr layer for the canvas\r\n */\r\n xrLayer: Nullable;\r\n\r\n /**\r\n * Initializes a XRWebGLLayer to be used as the session's baseLayer.\r\n * @param xrSession xr session\r\n * @returns a promise that will resolve once the XR Layer has been created\r\n */\r\n initializeXRLayerAsync(xrSession: XRSession): Promise;\r\n}\r\n","import { Vector4, Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Axis } from \"../../Maths/math.axis\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a cylinder, cone or prism\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * height sets the height (y direction) of the cylinder, optional, default 2\r\n * * diameterTop sets the diameter of the top of the cone, overwrites diameter, optional, default diameter\r\n * * diameterBottom sets the diameter of the bottom of the cone, overwrites diameter, optional, default diameter\r\n * * diameter sets the diameter of the top and bottom of the cone, optional default 1\r\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\r\n * * subdivisions` the number of rings along the cylinder height, optional, default 1\r\n * * arc a number from 0 to 1, to create an unclosed cylinder based on the fraction of the circumference given by the arc value, optional, default 1\r\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * * hasRings when true makes each subdivision independently treated as a face for faceUV and faceColors, optional, default false\r\n * * enclose when true closes an open cylinder by adding extra flat faces between the height axis and vertical edges, think cut cake\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.height\r\n * @param options.diameterTop\r\n * @param options.diameterBottom\r\n * @param options.diameter\r\n * @param options.tessellation\r\n * @param options.subdivisions\r\n * @param options.arc\r\n * @param options.faceColors\r\n * @param options.faceUV\r\n * @param options.hasRings\r\n * @param options.enclose\r\n * @param options.cap\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the cylinder, cone or prism\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function CreateCylinderVertexData(options: {\r\n height?: number;\r\n diameterTop?: number;\r\n diameterBottom?: number;\r\n diameter?: number;\r\n tessellation?: number;\r\n subdivisions?: number;\r\n arc?: number;\r\n faceColors?: Color4[];\r\n faceUV?: Vector4[];\r\n hasRings?: boolean;\r\n enclose?: boolean;\r\n cap?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const height: number = options.height || 2;\r\n let diameterTop: number = options.diameterTop === 0 ? 0 : options.diameterTop || options.diameter || 1;\r\n let diameterBottom: number = options.diameterBottom === 0 ? 0 : options.diameterBottom || options.diameter || 1;\r\n diameterTop = diameterTop || 0.00001; // Prevent broken normals\r\n diameterBottom = diameterBottom || 0.00001; // Prevent broken normals\r\n const tessellation: number = (options.tessellation || 24) | 0;\r\n const subdivisions: number = (options.subdivisions || 1) | 0;\r\n const hasRings: boolean = options.hasRings ? true : false;\r\n const enclose: boolean = options.enclose ? true : false;\r\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.CAP_ALL;\r\n const arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n const sideOrientation: number = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n const faceUV: Vector4[] = options.faceUV || new Array(3);\r\n const faceColors = options.faceColors;\r\n // default face colors and UV if undefined\r\n const quadNb: number = arc !== 1 && enclose ? 2 : 0;\r\n const ringNb: number = hasRings ? subdivisions : 1;\r\n const surfaceNb: number = 2 + (1 + quadNb) * ringNb;\r\n let f: number;\r\n\r\n for (f = 0; f < surfaceNb; f++) {\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n for (f = 0; f < surfaceNb; f++) {\r\n if (faceUV && faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n }\r\n\r\n const indices = new Array();\r\n const positions = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n const colors = new Array();\r\n\r\n const angleStep = (Math.PI * 2 * arc) / tessellation;\r\n let angle: number;\r\n let h: number;\r\n let radius: number;\r\n const tan = (diameterBottom - diameterTop) / 2 / height;\r\n const ringVertex: Vector3 = Vector3.Zero();\r\n const ringNormal: Vector3 = Vector3.Zero();\r\n const ringFirstVertex: Vector3 = Vector3.Zero();\r\n const ringFirstNormal: Vector3 = Vector3.Zero();\r\n const quadNormal: Vector3 = Vector3.Zero();\r\n const Y: Vector3 = Axis.Y;\r\n\r\n // positions, normals, uvs\r\n let i: number;\r\n let j: number;\r\n let r: number;\r\n let ringIdx: number = 1;\r\n let s: number = 1; // surface index\r\n let cs: number = 0;\r\n let v: number = 0;\r\n\r\n for (i = 0; i <= subdivisions; i++) {\r\n h = i / subdivisions;\r\n radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;\r\n ringIdx = hasRings && i !== 0 && i !== subdivisions ? 2 : 1;\r\n for (r = 0; r < ringIdx; r++) {\r\n if (hasRings) {\r\n s += r;\r\n }\r\n if (enclose) {\r\n s += 2 * r;\r\n }\r\n for (j = 0; j <= tessellation; j++) {\r\n angle = j * angleStep;\r\n\r\n // position\r\n ringVertex.x = Math.cos(-angle) * radius;\r\n ringVertex.y = -height / 2 + h * height;\r\n ringVertex.z = Math.sin(-angle) * radius;\r\n\r\n // normal\r\n if (diameterTop === 0 && i === subdivisions) {\r\n // if no top cap, reuse former normals\r\n ringNormal.x = normals[normals.length - (tessellation + 1) * 3];\r\n ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];\r\n ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];\r\n } else {\r\n ringNormal.x = ringVertex.x;\r\n ringNormal.z = ringVertex.z;\r\n ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;\r\n ringNormal.normalize();\r\n }\r\n\r\n // keep first ring vertex values for enclose\r\n if (j === 0) {\r\n ringFirstVertex.copyFrom(ringVertex);\r\n ringFirstNormal.copyFrom(ringNormal);\r\n }\r\n\r\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\r\n normals.push(ringNormal.x, ringNormal.y, ringNormal.z);\r\n if (hasRings) {\r\n v = cs !== s ? faceUV[s].y : faceUV[s].w;\r\n } else {\r\n v = faceUV[s].y + (faceUV[s].w - faceUV[s].y) * h;\r\n }\r\n uvs.push(faceUV[s].x + ((faceUV[s].z - faceUV[s].x) * j) / tessellation, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n if (faceColors) {\r\n colors.push(faceColors[s].r, faceColors[s].g, faceColors[s].b, faceColors[s].a);\r\n }\r\n }\r\n\r\n // if enclose, add four vertices and their dedicated normals\r\n if (arc !== 1 && enclose) {\r\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\r\n positions.push(0, ringVertex.y, 0);\r\n positions.push(0, ringVertex.y, 0);\r\n positions.push(ringFirstVertex.x, ringFirstVertex.y, ringFirstVertex.z);\r\n Vector3.CrossToRef(Y, ringNormal, quadNormal);\r\n quadNormal.normalize();\r\n normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);\r\n Vector3.CrossToRef(ringFirstNormal, Y, quadNormal);\r\n quadNormal.normalize();\r\n normals.push(quadNormal.x, quadNormal.y, quadNormal.z, quadNormal.x, quadNormal.y, quadNormal.z);\r\n if (hasRings) {\r\n v = cs !== s ? faceUV[s + 1].y : faceUV[s + 1].w;\r\n } else {\r\n v = faceUV[s + 1].y + (faceUV[s + 1].w - faceUV[s + 1].y) * h;\r\n }\r\n uvs.push(faceUV[s + 1].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n uvs.push(faceUV[s + 1].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n if (hasRings) {\r\n v = cs !== s ? faceUV[s + 2].y : faceUV[s + 2].w;\r\n } else {\r\n v = faceUV[s + 2].y + (faceUV[s + 2].w - faceUV[s + 2].y) * h;\r\n }\r\n uvs.push(faceUV[s + 2].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n uvs.push(faceUV[s + 2].z, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n if (faceColors) {\r\n colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);\r\n colors.push(faceColors[s + 1].r, faceColors[s + 1].g, faceColors[s + 1].b, faceColors[s + 1].a);\r\n colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);\r\n colors.push(faceColors[s + 2].r, faceColors[s + 2].g, faceColors[s + 2].b, faceColors[s + 2].a);\r\n }\r\n }\r\n if (cs !== s) {\r\n cs = s;\r\n }\r\n }\r\n }\r\n\r\n // indices\r\n const e: number = arc !== 1 && enclose ? tessellation + 4 : tessellation; // correction of number of iteration if enclose\r\n i = 0;\r\n for (s = 0; s < subdivisions; s++) {\r\n let i0: number = 0;\r\n let i1: number = 0;\r\n let i2: number = 0;\r\n let i3: number = 0;\r\n for (j = 0; j < tessellation; j++) {\r\n i0 = i * (e + 1) + j;\r\n i1 = (i + 1) * (e + 1) + j;\r\n i2 = i * (e + 1) + (j + 1);\r\n i3 = (i + 1) * (e + 1) + (j + 1);\r\n indices.push(i0, i1, i2);\r\n indices.push(i3, i2, i1);\r\n }\r\n if (arc !== 1 && enclose) {\r\n // if enclose, add two quads\r\n indices.push(i0 + 2, i1 + 2, i2 + 2);\r\n indices.push(i3 + 2, i2 + 2, i1 + 2);\r\n indices.push(i0 + 4, i1 + 4, i2 + 4);\r\n indices.push(i3 + 4, i2 + 4, i1 + 4);\r\n }\r\n i = hasRings ? i + 2 : i + 1;\r\n }\r\n\r\n // Caps\r\n const createCylinderCap = (isTop: boolean) => {\r\n const radius = isTop ? diameterTop / 2 : diameterBottom / 2;\r\n if (radius === 0) {\r\n return;\r\n }\r\n\r\n // Cap positions, normals & uvs\r\n let angle;\r\n let circleVector;\r\n let i: number;\r\n const u: Vector4 = isTop ? faceUV[surfaceNb - 1] : faceUV[0];\r\n let c: Nullable = null;\r\n if (faceColors) {\r\n c = isTop ? faceColors[surfaceNb - 1] : faceColors[0];\r\n }\r\n // cap center\r\n const vbase = positions.length / 3;\r\n const offset = isTop ? height / 2 : -height / 2;\r\n const center = new Vector3(0, offset, 0);\r\n positions.push(center.x, center.y, center.z);\r\n normals.push(0, isTop ? 1 : -1, 0);\r\n const v = u.y + (u.w - u.y) * 0.5;\r\n uvs.push(u.x + (u.z - u.x) * 0.5, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n if (c) {\r\n colors.push(c.r, c.g, c.b, c.a);\r\n }\r\n\r\n const textureScale = new Vector2(0.5, 0.5);\r\n for (i = 0; i <= tessellation; i++) {\r\n angle = (Math.PI * 2 * i * arc) / tessellation;\r\n const cos = Math.cos(-angle);\r\n const sin = Math.sin(-angle);\r\n circleVector = new Vector3(cos * radius, offset, sin * radius);\r\n const textureCoordinate = new Vector2(cos * textureScale.x + 0.5, sin * textureScale.y + 0.5);\r\n positions.push(circleVector.x, circleVector.y, circleVector.z);\r\n normals.push(0, isTop ? 1 : -1, 0);\r\n const v = u.y + (u.w - u.y) * textureCoordinate.y;\r\n uvs.push(u.x + (u.z - u.x) * textureCoordinate.x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n if (c) {\r\n colors.push(c.r, c.g, c.b, c.a);\r\n }\r\n }\r\n // Cap indices\r\n for (i = 0; i < tessellation; i++) {\r\n if (!isTop) {\r\n indices.push(vbase);\r\n indices.push(vbase + (i + 1));\r\n indices.push(vbase + (i + 2));\r\n } else {\r\n indices.push(vbase);\r\n indices.push(vbase + (i + 2));\r\n indices.push(vbase + (i + 1));\r\n }\r\n }\r\n };\r\n\r\n // add caps to geometry based on cap parameter\r\n if (cap === Mesh.CAP_START || cap === Mesh.CAP_ALL) {\r\n createCylinderCap(false);\r\n }\r\n if (cap === Mesh.CAP_END || cap === Mesh.CAP_ALL) {\r\n createCylinderCap(true);\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n if (faceColors) {\r\n vertexData.colors = colors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a cylinder or a cone mesh\r\n * * The parameter `height` sets the height size (float) of the cylinder/cone (float, default 2).\r\n * * The parameter `diameter` sets the diameter of the top and bottom cap at once (float, default 1).\r\n * * The parameters `diameterTop` and `diameterBottom` overwrite the parameter `diameter` and set respectively the top cap and bottom cap diameter (floats, default 1). The parameter \"diameterBottom\" can't be zero.\r\n * * The parameter `tessellation` sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance.\r\n * * The parameter `subdivisions` sets the number of rings along the cylinder height (positive integer, default 1).\r\n * * The parameter `hasRings` (boolean, default false) makes the subdivisions independent from each other, so they become different faces.\r\n * * The parameter `enclose` (boolean, default false) adds two extra faces per subdivision to a sliced cylinder to close it around its height axis.\r\n * * The parameter `cap` sets the way the cylinder is capped. Possible values : BABYLON.Mesh.NO_CAP, BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL (default).\r\n * * The parameter `arc` (float, default 1) is the ratio (max 1) to apply to the circumference to slice the cylinder.\r\n * * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of n Color3 elements) and `faceUV` (an array of n Vector4 elements).\r\n * * The value of n is the number of cylinder faces. If the cylinder has only 1 subdivisions, n equals : top face + cylinder surface + bottom face = 3\r\n * * Now, if the cylinder has 5 independent subdivisions (hasRings = true), n equals : top face + 5 stripe surfaces + bottom face = 2 + 5 = 7\r\n * * Finally, if the cylinder has 5 independent subdivisions and is enclose, n equals : top face + 5 x (stripe surface + 2 closing faces) + bottom face = 2 + 5 * 3 = 17\r\n * * Each array (color or UVs) is always ordered the same way : the first element is the bottom cap, the last element is the top cap. The other elements are each a ring surface.\r\n * * If `enclose` is false, a ring surface is one element.\r\n * * If `enclose` is true, a ring surface is 3 successive elements in the array : the tubular surface, then the two closing faces.\r\n * * Example how to set colors and textures on a sliced cylinder : https://www.html5gamedevs.com/topic/17945-creating-a-closed-slice-of-a-cylinder/#comment-106379\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.height\r\n * @param options.diameterTop\r\n * @param options.diameterBottom\r\n * @param options.diameter\r\n * @param options.tessellation\r\n * @param options.subdivisions\r\n * @param options.arc\r\n * @param options.faceColors\r\n * @param options.faceUV\r\n * @param options.updatable\r\n * @param options.hasRings\r\n * @param options.enclose\r\n * @param options.cap\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param scene defines the hosting scene\r\n * @returns the cylinder mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#cylinder-or-cone\r\n */\r\nexport function CreateCylinder(\r\n name: string,\r\n options: {\r\n height?: number;\r\n diameterTop?: number;\r\n diameterBottom?: number;\r\n diameter?: number;\r\n tessellation?: number;\r\n subdivisions?: number;\r\n arc?: number;\r\n faceColors?: Color4[];\r\n faceUV?: Vector4[];\r\n updatable?: boolean;\r\n hasRings?: boolean;\r\n enclose?: boolean;\r\n cap?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n } = {},\r\n scene?: Nullable\r\n): Mesh {\r\n const cylinder = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n cylinder._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateCylinderVertexData(options);\r\n\r\n vertexData.applyToMesh(cylinder, options.updatable);\r\n\r\n return cylinder;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated Please use CreateCylinder directly\r\n */\r\nexport const CylinderBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateCylinder,\r\n};\r\n\r\nVertexData.CreateCylinder = CreateCylinderVertexData;\r\n\r\nMesh.CreateCylinder = (\r\n name: string,\r\n height: number,\r\n diameterTop: number,\r\n diameterBottom: number,\r\n tessellation: number,\r\n subdivisions: any,\r\n scene?: Scene,\r\n updatable?: any,\r\n sideOrientation?: number\r\n): Mesh => {\r\n if (scene === undefined || !(scene instanceof Scene)) {\r\n if (scene !== undefined) {\r\n sideOrientation = updatable || Mesh.DEFAULTSIDE;\r\n updatable = scene;\r\n }\r\n scene = subdivisions;\r\n subdivisions = 1;\r\n }\r\n\r\n const options = {\r\n height,\r\n diameterTop,\r\n diameterBottom,\r\n tessellation,\r\n subdivisions,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateCylinder(name, options, scene);\r\n};\r\n","import type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Matrix, Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a torus\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * diameter the diameter of the torus, optional default 1\r\n * * thickness the diameter of the tube forming the torus, optional default 0.5\r\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.diameter\r\n * @param options.thickness\r\n * @param options.tessellation\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the torus\r\n */\r\nexport function CreateTorusVertexData(options: { diameter?: number; thickness?: number; tessellation?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 }) {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n const diameter = options.diameter || 1;\r\n const thickness = options.thickness || 0.5;\r\n const tessellation = (options.tessellation || 16) | 0;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n const stride = tessellation + 1;\r\n\r\n for (let i = 0; i <= tessellation; i++) {\r\n const u = i / tessellation;\r\n\r\n const outerAngle = (i * Math.PI * 2.0) / tessellation - Math.PI / 2.0;\r\n\r\n const transform = Matrix.Translation(diameter / 2.0, 0, 0).multiply(Matrix.RotationY(outerAngle));\r\n\r\n for (let j = 0; j <= tessellation; j++) {\r\n const v = 1 - j / tessellation;\r\n\r\n const innerAngle = (j * Math.PI * 2.0) / tessellation + Math.PI;\r\n const dx = Math.cos(innerAngle);\r\n const dy = Math.sin(innerAngle);\r\n\r\n // Create a vertex.\r\n let normal = new Vector3(dx, dy, 0);\r\n let position = normal.scale(thickness / 2);\r\n const textureCoordinate = new Vector2(u, v);\r\n\r\n position = Vector3.TransformCoordinates(position, transform);\r\n normal = Vector3.TransformNormal(normal, transform);\r\n\r\n positions.push(position.x, position.y, position.z);\r\n normals.push(normal.x, normal.y, normal.z);\r\n uvs.push(textureCoordinate.x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - textureCoordinate.y : textureCoordinate.y);\r\n\r\n // And create indices for two triangles.\r\n const nextI = (i + 1) % stride;\r\n const nextJ = (j + 1) % stride;\r\n\r\n indices.push(i * stride + j);\r\n indices.push(i * stride + nextJ);\r\n indices.push(nextI * stride + j);\r\n\r\n indices.push(i * stride + nextJ);\r\n indices.push(nextI * stride + nextJ);\r\n indices.push(nextI * stride + j);\r\n }\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a torus mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\r\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\r\n * * The parameter `tessellation` sets the number of torus sides (positive integer, default 16)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.diameter\r\n * @param options.thickness\r\n * @param options.tessellation\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param scene defines the hosting scene\r\n * @returns the torus mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus\r\n */\r\nexport function CreateTorus(\r\n name: string,\r\n options: { diameter?: number; thickness?: number; tessellation?: number; updatable?: boolean; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 } = {},\r\n scene?: Scene\r\n): Mesh {\r\n const torus = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n torus._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateTorusVertexData(options);\r\n\r\n vertexData.applyToMesh(torus, options.updatable);\r\n\r\n return torus;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTorus instead\r\n */\r\nexport const TorusBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTorus,\r\n};\r\n\r\nVertexData.CreateTorus = CreateTorusVertexData;\r\n\r\nMesh.CreateTorus = (name: string, diameter: number, thickness: number, tessellation: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n diameter,\r\n thickness,\r\n tessellation,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateTorus(name, options, scene);\r\n};\r\n","import { Logger } from \"../../Misc/logger\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport { FreeCamera } from \"../../Cameras/freeCamera\";\r\nimport { TargetCamera } from \"../../Cameras/targetCamera\";\r\nimport { DeviceOrientationCamera } from \"../../Cameras/deviceOrientationCamera\";\r\nimport { VRDeviceOrientationFreeCamera } from \"../../Cameras/VR/vrDeviceOrientationFreeCamera\";\r\nimport type { WebVROptions } from \"../../Cameras/VR/webVRCamera\";\r\nimport { WebVRFreeCamera } from \"../../Cameras/VR/webVRCamera\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport type { Scene, IDisposable } from \"../../scene\";\r\nimport { Quaternion, Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Color3, Color4 } from \"../../Maths/math.color\";\r\nimport type { StickValues } from \"../../Gamepads/gamepad\";\r\nimport { Gamepad } from \"../../Gamepads/gamepad\";\r\nimport { PoseEnabledController, PoseEnabledControllerType } from \"../../Gamepads/Controllers/poseEnabledController\";\r\nimport { WebVRController } from \"../../Gamepads/Controllers/webVRController\";\r\nimport type { Xbox360Pad } from \"../../Gamepads/xboxGamepad\";\r\nimport { Xbox360Button } from \"../../Gamepads/xboxGamepad\";\r\nimport type { IDisplayChangedEventArgs } from \"../../Engines/engine\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport type { PickingInfo } from \"../../Collisions/pickingInfo\";\r\nimport { Ray } from \"../../Culling/ray\";\r\nimport { ImageProcessingConfiguration } from \"../../Materials/imageProcessingConfiguration\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { DynamicTexture } from \"../../Materials/Textures/dynamicTexture\";\r\nimport { ImageProcessingPostProcess } from \"../../PostProcesses/imageProcessingPostProcess\";\r\nimport { SineEase, EasingFunction, CircleEase } from \"../../Animations/easing\";\r\nimport { Animation } from \"../../Animations/animation\";\r\nimport { VRCameraMetrics } from \"../../Cameras/VR/vrCameraMetrics\";\r\nimport \"../../Gamepads/gamepadSceneComponent\";\r\nimport \"../../Animations/animatable\";\r\nimport { Axis } from \"../../Maths/math.axis\";\r\nimport { WebXRSessionManager } from \"../../XR/webXRSessionManager\";\r\nimport type { WebXRDefaultExperience } from \"../../XR/webXRDefaultExperience\";\r\nimport { WebXRState } from \"../../XR/webXRTypes\";\r\nimport { CreateCylinder } from \"../../Meshes/Builders/cylinderBuilder\";\r\nimport { CreateTorus } from \"../../Meshes/Builders/torusBuilder\";\r\nimport { CreateGround } from \"../../Meshes/Builders/groundBuilder\";\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Options to modify the vr teleportation behavior.\r\n */\r\nexport interface VRTeleportationOptions {\r\n /**\r\n * The name of the mesh which should be used as the teleportation floor. (default: null)\r\n */\r\n floorMeshName?: string;\r\n /**\r\n * A list of meshes to be used as the teleportation floor. (default: empty)\r\n */\r\n floorMeshes?: Mesh[];\r\n /**\r\n * The teleportation mode. (default: TELEPORTATIONMODE_CONSTANTTIME)\r\n */\r\n teleportationMode?: number;\r\n /**\r\n * The duration of the animation in ms, apply when animationMode is TELEPORTATIONMODE_CONSTANTTIME. (default 122ms)\r\n */\r\n teleportationTime?: number;\r\n /**\r\n * The speed of the animation in distance/sec, apply when animationMode is TELEPORTATIONMODE_CONSTANTSPEED. (default 20 units / sec)\r\n */\r\n teleportationSpeed?: number;\r\n /**\r\n * The easing function used in the animation or null for Linear. (default CircleEase)\r\n */\r\n easingFunction?: EasingFunction;\r\n}\r\n\r\n/**\r\n * Options to modify the vr experience helper's behavior.\r\n */\r\nexport interface VRExperienceHelperOptions extends WebVROptions {\r\n /**\r\n * Create a DeviceOrientationCamera to be used as your out of vr camera. (default: true)\r\n */\r\n createDeviceOrientationCamera?: boolean;\r\n /**\r\n * Create a VRDeviceOrientationFreeCamera to be used for VR when no external HMD is found. (default: true)\r\n */\r\n createFallbackVRDeviceOrientationFreeCamera?: boolean;\r\n /**\r\n * Uses the main button on the controller to toggle the laser casted. (default: true)\r\n */\r\n laserToggle?: boolean;\r\n /**\r\n * A list of meshes to be used as the teleportation floor. If specified, teleportation will be enabled (default: undefined)\r\n */\r\n floorMeshes?: Mesh[];\r\n /**\r\n * Distortion metrics for the fallback vrDeviceOrientationCamera (default: VRCameraMetrics.Default)\r\n */\r\n vrDeviceOrientationCameraMetrics?: VRCameraMetrics;\r\n /**\r\n * Defines if WebXR should be used instead of WebVR (if available)\r\n */\r\n useXR?: boolean;\r\n}\r\n\r\nclass VRExperienceHelperGazer implements IDisposable {\r\n /** @internal */\r\n public _gazeTracker: Mesh;\r\n\r\n /** @internal */\r\n public _currentMeshSelected: Nullable;\r\n /** @internal */\r\n public _currentHit: Nullable;\r\n\r\n public static _IdCounter = 0;\r\n /** @internal */\r\n public _id: number;\r\n\r\n /** @internal */\r\n public _pointerDownOnMeshAsked: boolean = false;\r\n /** @internal */\r\n public _isActionableMesh: boolean = false;\r\n\r\n /** @internal */\r\n public _interactionsEnabled: boolean;\r\n /** @internal */\r\n public _teleportationEnabled: boolean;\r\n /** @internal */\r\n public _teleportationRequestInitiated = false;\r\n /** @internal */\r\n public _teleportationBackRequestInitiated = false;\r\n /** @internal */\r\n public _rotationRightAsked = false;\r\n /** @internal */\r\n public _rotationLeftAsked = false;\r\n /** @internal */\r\n public _dpadPressed = true;\r\n\r\n /** @internal */\r\n public _activePointer = false;\r\n\r\n constructor(public scene: Scene, gazeTrackerToClone: Nullable = null) {\r\n this._id = VRExperienceHelperGazer._IdCounter++;\r\n\r\n // Gaze tracker\r\n if (!gazeTrackerToClone) {\r\n this._gazeTracker = CreateTorus(\r\n \"gazeTracker\",\r\n {\r\n diameter: 0.0035,\r\n thickness: 0.0025,\r\n tessellation: 20,\r\n updatable: false,\r\n },\r\n scene\r\n );\r\n this._gazeTracker.bakeCurrentTransformIntoVertices();\r\n this._gazeTracker.isPickable = false;\r\n this._gazeTracker.isVisible = false;\r\n const targetMat = new StandardMaterial(\"targetMat\", scene);\r\n targetMat.specularColor = Color3.Black();\r\n targetMat.emissiveColor = new Color3(0.7, 0.7, 0.7);\r\n targetMat.backFaceCulling = false;\r\n this._gazeTracker.material = targetMat;\r\n } else {\r\n this._gazeTracker = gazeTrackerToClone.clone(\"gazeTracker\") as Mesh;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getForwardRay(length: number): Ray {\r\n return new Ray(Vector3.Zero(), new Vector3(0, 0, length));\r\n }\r\n\r\n /** @internal */\r\n public _selectionPointerDown() {\r\n this._pointerDownOnMeshAsked = true;\r\n if (this._currentHit) {\r\n this.scene.simulatePointerDown(this._currentHit, { pointerId: this._id });\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _selectionPointerUp() {\r\n if (this._currentHit) {\r\n this.scene.simulatePointerUp(this._currentHit, { pointerId: this._id });\r\n }\r\n this._pointerDownOnMeshAsked = false;\r\n }\r\n\r\n /** @internal */\r\n public _activatePointer() {\r\n this._activePointer = true;\r\n }\r\n\r\n /** @internal */\r\n public _deactivatePointer() {\r\n this._activePointer = false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _updatePointerDistance(distance: number = 100) {}\r\n\r\n public dispose() {\r\n this._interactionsEnabled = false;\r\n this._teleportationEnabled = false;\r\n if (this._gazeTracker) {\r\n this._gazeTracker.dispose();\r\n }\r\n }\r\n}\r\n\r\nclass VRExperienceHelperControllerGazer extends VRExperienceHelperGazer {\r\n private _laserPointer: Mesh;\r\n private _meshAttachedObserver: Nullable>;\r\n constructor(public webVRController: WebVRController, scene: Scene, gazeTrackerToClone: Mesh) {\r\n super(scene, gazeTrackerToClone);\r\n // Laser pointer\r\n this._laserPointer = CreateCylinder(\r\n \"laserPointer\",\r\n {\r\n updatable: false,\r\n height: 1,\r\n diameterTop: 0.004,\r\n diameterBottom: 0.0002,\r\n tessellation: 20,\r\n subdivisions: 1,\r\n },\r\n scene\r\n );\r\n const laserPointerMaterial = new StandardMaterial(\"laserPointerMat\", scene);\r\n laserPointerMaterial.emissiveColor = new Color3(0.7, 0.7, 0.7);\r\n laserPointerMaterial.alpha = 0.6;\r\n this._laserPointer.material = laserPointerMaterial;\r\n this._laserPointer.rotation.x = Math.PI / 2;\r\n this._laserPointer.position.z = -0.5;\r\n this._laserPointer.isVisible = false;\r\n this._laserPointer.isPickable = false;\r\n\r\n if (!webVRController.mesh) {\r\n // Create an empty mesh that is used prior to loading the high quality model\r\n const preloadMesh = new Mesh(\"preloadControllerMesh\", scene);\r\n const preloadPointerPose = new Mesh(PoseEnabledController.POINTING_POSE, scene);\r\n preloadPointerPose.rotation.x = -0.7;\r\n preloadMesh.addChild(preloadPointerPose);\r\n webVRController.attachToMesh(preloadMesh);\r\n }\r\n\r\n this._setLaserPointerParent(webVRController.mesh!);\r\n\r\n this._meshAttachedObserver = webVRController._meshAttachedObservable.add((mesh) => {\r\n this._setLaserPointerParent(mesh);\r\n });\r\n }\r\n\r\n _getForwardRay(length: number): Ray {\r\n return this.webVRController.getForwardRay(length);\r\n }\r\n\r\n /** @internal */\r\n public _activatePointer() {\r\n super._activatePointer();\r\n this._laserPointer.isVisible = true;\r\n }\r\n\r\n /** @internal */\r\n public _deactivatePointer() {\r\n super._deactivatePointer();\r\n this._laserPointer.isVisible = false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setLaserPointerColor(color: Color3) {\r\n (this._laserPointer.material).emissiveColor = color;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setLaserPointerLightingDisabled(disabled: boolean) {\r\n (this._laserPointer.material).disableLighting = disabled;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setLaserPointerParent(mesh: AbstractMesh) {\r\n const makeNotPick = (root: AbstractMesh) => {\r\n root.isPickable = false;\r\n root.getChildMeshes().forEach((c) => {\r\n makeNotPick(c);\r\n });\r\n };\r\n makeNotPick(mesh);\r\n const meshChildren = mesh.getChildren(undefined, false);\r\n\r\n let laserParent: TransformNode = mesh;\r\n this.webVRController._pointingPoseNode = null;\r\n for (let i = 0; i < meshChildren.length; i++) {\r\n if (meshChildren[i].name && meshChildren[i].name.indexOf(PoseEnabledController.POINTING_POSE) >= 0) {\r\n laserParent = meshChildren[i];\r\n this.webVRController._pointingPoseNode = laserParent;\r\n break;\r\n }\r\n }\r\n this._laserPointer.parent = laserParent;\r\n }\r\n\r\n public _updatePointerDistance(distance: number = 100) {\r\n this._laserPointer.scaling.y = distance;\r\n this._laserPointer.position.z = -distance / 2;\r\n }\r\n\r\n dispose() {\r\n super.dispose();\r\n this._laserPointer.dispose();\r\n if (this._meshAttachedObserver) {\r\n this.webVRController._meshAttachedObservable.remove(this._meshAttachedObserver);\r\n }\r\n }\r\n}\r\n\r\nclass VRExperienceHelperCameraGazer extends VRExperienceHelperGazer {\r\n constructor(private _getCamera: () => Nullable, scene: Scene) {\r\n super(scene);\r\n }\r\n\r\n _getForwardRay(length: number): Ray {\r\n const camera = this._getCamera();\r\n if (camera) {\r\n return camera.getForwardRay(length);\r\n } else {\r\n return new Ray(Vector3.Zero(), Vector3.Forward());\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Event containing information after VR has been entered\r\n */\r\nexport class OnAfterEnteringVRObservableEvent {\r\n /**\r\n * If entering vr was successful\r\n */\r\n public success: boolean;\r\n}\r\n\r\n/**\r\n * Helps to quickly add VR support to an existing scene.\r\n * See https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRHelper\r\n * @deprecated\r\n */\r\nexport class VRExperienceHelper {\r\n private _scene: Scene;\r\n private _position: Vector3;\r\n private _btnVR: Nullable;\r\n private _btnVRDisplayed: boolean;\r\n\r\n // Can the system support WebVR, even if a headset isn't plugged in?\r\n private _webVRsupported = false;\r\n // If WebVR is supported, is a headset plugged in and are we ready to present?\r\n private _webVRready = false;\r\n // Are we waiting for the requestPresent callback to complete?\r\n private _webVRrequesting = false;\r\n // Are we presenting to the headset right now? (this is the vrDevice state)\r\n private _webVRpresenting = false;\r\n // Have we entered VR? (this is the VRExperienceHelper state)\r\n private _hasEnteredVR: boolean;\r\n\r\n // Are we presenting in the fullscreen fallback?\r\n private _fullscreenVRpresenting = false;\r\n\r\n private _inputElement: Nullable;\r\n private _webVRCamera: WebVRFreeCamera;\r\n private _vrDeviceOrientationCamera: Nullable;\r\n private _deviceOrientationCamera: Nullable;\r\n private _existingCamera: Camera;\r\n\r\n private _onKeyDown: (event: KeyboardEvent) => void;\r\n private _onVrDisplayPresentChangeBind: any;\r\n private _onVRDisplayChangedBind: (eventArgs: IDisplayChangedEventArgs) => void;\r\n private _onVRRequestPresentStart: () => void;\r\n private _onVRRequestPresentComplete: (success: boolean) => void;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that gaze can be enabled even if pointer lock is not engage (useful on iOS where fullscreen mode and pointer lock are not supported)\r\n */\r\n public enableGazeEvenWhenNoPointerLock = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the VREXperienceHelper will exit VR if double tap is detected\r\n */\r\n public exitVROnDoubleTap = true;\r\n\r\n /**\r\n * Observable raised right before entering VR.\r\n */\r\n public onEnteringVRObservable = new Observable();\r\n\r\n /**\r\n * Observable raised when entering VR has completed.\r\n */\r\n public onAfterEnteringVRObservable = new Observable();\r\n\r\n /**\r\n * Observable raised when exiting VR.\r\n */\r\n public onExitingVRObservable = new Observable();\r\n\r\n /**\r\n * Observable raised when controller mesh is loaded.\r\n */\r\n public onControllerMeshLoadedObservable = new Observable();\r\n\r\n /** Return this.onEnteringVRObservable\r\n * Note: This one is for backward compatibility. Please use onEnteringVRObservable directly\r\n */\r\n public get onEnteringVR(): Observable {\r\n return this.onEnteringVRObservable;\r\n }\r\n\r\n /** Return this.onExitingVRObservable\r\n * Note: This one is for backward compatibility. Please use onExitingVRObservable directly\r\n */\r\n public get onExitingVR(): Observable {\r\n return this.onExitingVRObservable;\r\n }\r\n\r\n /** Return this.onControllerMeshLoadedObservable\r\n * Note: This one is for backward compatibility. Please use onControllerMeshLoadedObservable directly\r\n */\r\n public get onControllerMeshLoaded(): Observable {\r\n return this.onControllerMeshLoadedObservable;\r\n }\r\n\r\n private _rayLength: number;\r\n private _useCustomVRButton: boolean = false;\r\n private _teleportationRequested: boolean = false;\r\n private _teleportActive = false;\r\n private _floorMeshName: string;\r\n private _floorMeshesCollection: Mesh[] = [];\r\n private _teleportationMode: number = VRExperienceHelper.TELEPORTATIONMODE_CONSTANTTIME;\r\n private _teleportationTime: number = 122;\r\n private _teleportationSpeed: number = 20;\r\n private _teleportationEasing: EasingFunction;\r\n private _rotationAllowed: boolean = true;\r\n private _teleportBackwardsVector = new Vector3(0, -1, -1);\r\n private _teleportationTarget: Mesh;\r\n private _isDefaultTeleportationTarget = true;\r\n private _postProcessMove: ImageProcessingPostProcess;\r\n private _teleportationFillColor: string = \"#444444\";\r\n private _teleportationBorderColor: string = \"#FFFFFF\";\r\n private _rotationAngle: number = 0;\r\n private _haloCenter = new Vector3(0, 0, 0);\r\n private _cameraGazer: VRExperienceHelperCameraGazer;\r\n private _padSensibilityUp = 0.65;\r\n private _padSensibilityDown = 0.35;\r\n\r\n private _leftController: Nullable = null;\r\n private _rightController: Nullable = null;\r\n\r\n private _gazeColor: Color3 = new Color3(0.7, 0.7, 0.7);\r\n private _laserColor: Color3 = new Color3(0.7, 0.7, 0.7);\r\n private _pickedLaserColor: Color3 = new Color3(0.2, 0.2, 1);\r\n private _pickedGazeColor: Color3 = new Color3(0, 0, 1);\r\n\r\n /**\r\n * Observable raised when a new mesh is selected based on meshSelectionPredicate\r\n */\r\n public onNewMeshSelected = new Observable();\r\n\r\n /**\r\n * Observable raised when a new mesh is selected based on meshSelectionPredicate.\r\n * This observable will provide the mesh and the controller used to select the mesh\r\n */\r\n public onMeshSelectedWithController = new Observable<{ mesh: AbstractMesh; controller: WebVRController }>();\r\n\r\n /**\r\n * Observable raised when a new mesh is picked based on meshSelectionPredicate\r\n */\r\n public onNewMeshPicked = new Observable();\r\n\r\n private _circleEase: CircleEase;\r\n\r\n /**\r\n * Observable raised before camera teleportation\r\n */\r\n public onBeforeCameraTeleport = new Observable();\r\n\r\n /**\r\n * Observable raised after camera teleportation\r\n */\r\n public onAfterCameraTeleport = new Observable();\r\n\r\n /**\r\n * Observable raised when current selected mesh gets unselected\r\n */\r\n public onSelectedMeshUnselected = new Observable();\r\n\r\n private _raySelectionPredicate: (mesh: AbstractMesh) => boolean;\r\n\r\n /**\r\n * To be optionally changed by user to define custom ray selection\r\n */\r\n public raySelectionPredicate: (mesh: AbstractMesh) => boolean;\r\n\r\n /**\r\n * To be optionally changed by user to define custom selection logic (after ray selection)\r\n */\r\n public meshSelectionPredicate: (mesh: AbstractMesh) => boolean;\r\n\r\n /**\r\n * Set teleportation enabled. If set to false camera teleportation will be disabled but camera rotation will be kept.\r\n */\r\n public teleportationEnabled: boolean = true;\r\n\r\n private _defaultHeight: number;\r\n private _teleportationInitialized = false;\r\n private _interactionsEnabled = false;\r\n private _interactionsRequested = false;\r\n private _displayGaze = true;\r\n private _displayLaserPointer = true;\r\n\r\n /**\r\n * The mesh used to display where the user is going to teleport.\r\n */\r\n public get teleportationTarget(): Mesh {\r\n return this._teleportationTarget;\r\n }\r\n\r\n /**\r\n * Sets the mesh to be used to display where the user is going to teleport.\r\n */\r\n public set teleportationTarget(value: Mesh) {\r\n if (value) {\r\n value.name = \"teleportationTarget\";\r\n this._isDefaultTeleportationTarget = false;\r\n this._teleportationTarget = value;\r\n }\r\n }\r\n\r\n /**\r\n * The mesh used to display where the user is selecting, this mesh will be cloned and set as the gazeTracker for the left and right controller\r\n * when set bakeCurrentTransformIntoVertices will be called on the mesh.\r\n * See https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/center_origin/bakingTransforms\r\n */\r\n public get gazeTrackerMesh(): Mesh {\r\n return this._cameraGazer._gazeTracker;\r\n }\r\n\r\n public set gazeTrackerMesh(value: Mesh) {\r\n if (value) {\r\n // Dispose of existing meshes\r\n if (this._cameraGazer._gazeTracker) {\r\n this._cameraGazer._gazeTracker.dispose();\r\n }\r\n if (this._leftController && this._leftController._gazeTracker) {\r\n this._leftController._gazeTracker.dispose();\r\n }\r\n if (this._rightController && this._rightController._gazeTracker) {\r\n this._rightController._gazeTracker.dispose();\r\n }\r\n\r\n // Set and create gaze trackers on head and controllers\r\n this._cameraGazer._gazeTracker = value;\r\n this._cameraGazer._gazeTracker.bakeCurrentTransformIntoVertices();\r\n this._cameraGazer._gazeTracker.isPickable = false;\r\n this._cameraGazer._gazeTracker.isVisible = false;\r\n this._cameraGazer._gazeTracker.name = \"gazeTracker\";\r\n if (this._leftController) {\r\n this._leftController._gazeTracker = this._cameraGazer._gazeTracker.clone(\"gazeTracker\") as Mesh;\r\n }\r\n\r\n if (this._rightController) {\r\n this._rightController._gazeTracker = this._cameraGazer._gazeTracker.clone(\"gazeTracker\") as Mesh;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * If the gaze trackers scale should be updated to be constant size when pointing at near/far meshes\r\n */\r\n public updateGazeTrackerScale = true;\r\n /**\r\n * If the gaze trackers color should be updated when selecting meshes\r\n */\r\n public updateGazeTrackerColor = true;\r\n /**\r\n * If the controller laser color should be updated when selecting meshes\r\n */\r\n public updateControllerLaserColor = true;\r\n\r\n /**\r\n * The gaze tracking mesh corresponding to the left controller\r\n */\r\n public get leftControllerGazeTrackerMesh(): Nullable {\r\n if (this._leftController) {\r\n return this._leftController._gazeTracker;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * The gaze tracking mesh corresponding to the right controller\r\n */\r\n public get rightControllerGazeTrackerMesh(): Nullable {\r\n if (this._rightController) {\r\n return this._rightController._gazeTracker;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * If the ray of the gaze should be displayed.\r\n */\r\n public get displayGaze(): boolean {\r\n return this._displayGaze;\r\n }\r\n\r\n /**\r\n * Sets if the ray of the gaze should be displayed.\r\n */\r\n public set displayGaze(value: boolean) {\r\n this._displayGaze = value;\r\n if (!value) {\r\n this._cameraGazer._gazeTracker.isVisible = false;\r\n\r\n if (this._leftController) {\r\n this._leftController._gazeTracker.isVisible = false;\r\n }\r\n\r\n if (this._rightController) {\r\n this._rightController._gazeTracker.isVisible = false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * If the ray of the LaserPointer should be displayed.\r\n */\r\n public get displayLaserPointer(): boolean {\r\n return this._displayLaserPointer;\r\n }\r\n\r\n /**\r\n * Sets if the ray of the LaserPointer should be displayed.\r\n */\r\n public set displayLaserPointer(value: boolean) {\r\n this._displayLaserPointer = value;\r\n if (!value) {\r\n if (this._rightController) {\r\n this._rightController._deactivatePointer();\r\n this._rightController._gazeTracker.isVisible = false;\r\n }\r\n if (this._leftController) {\r\n this._leftController._deactivatePointer();\r\n this._leftController._gazeTracker.isVisible = false;\r\n }\r\n } else {\r\n if (this._rightController) {\r\n this._rightController._activatePointer();\r\n }\r\n if (this._leftController) {\r\n this._leftController._activatePointer();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * The deviceOrientationCamera used as the camera when not in VR.\r\n */\r\n public get deviceOrientationCamera(): Nullable {\r\n return this._deviceOrientationCamera;\r\n }\r\n\r\n /**\r\n * Based on the current WebVR support, returns the current VR camera used.\r\n */\r\n public get currentVRCamera(): Nullable {\r\n if (this._webVRready) {\r\n return this._webVRCamera;\r\n } else {\r\n return this._scene.activeCamera;\r\n }\r\n }\r\n\r\n /**\r\n * The webVRCamera which is used when in VR.\r\n */\r\n public get webVRCamera(): WebVRFreeCamera {\r\n return this._webVRCamera;\r\n }\r\n\r\n /**\r\n * The deviceOrientationCamera that is used as a fallback when vr device is not connected.\r\n */\r\n public get vrDeviceOrientationCamera(): Nullable {\r\n return this._vrDeviceOrientationCamera;\r\n }\r\n\r\n /**\r\n * The html button that is used to trigger entering into VR.\r\n */\r\n public get vrButton(): Nullable {\r\n return this._btnVR;\r\n }\r\n\r\n private get _teleportationRequestInitiated(): boolean {\r\n const result =\r\n this._cameraGazer._teleportationRequestInitiated ||\r\n (this._leftController !== null && this._leftController._teleportationRequestInitiated) ||\r\n (this._rightController !== null && this._rightController._teleportationRequestInitiated);\r\n return result;\r\n }\r\n\r\n /**\r\n * Defines whether or not Pointer lock should be requested when switching to\r\n * full screen.\r\n */\r\n public requestPointerLockOnFullScreen = true;\r\n\r\n // XR\r\n\r\n /**\r\n * If asking to force XR, this will be populated with the default xr experience\r\n */\r\n public xr: WebXRDefaultExperience;\r\n\r\n /**\r\n * Was the XR test done already. If this is true AND this.xr exists, xr is initialized.\r\n * If this is true and no this.xr, xr exists but is not supported, using WebVR.\r\n */\r\n public xrTestDone: boolean = false;\r\n\r\n /**\r\n * Instantiates a VRExperienceHelper.\r\n * Helps to quickly add VR support to an existing scene.\r\n * @param scene The scene the VRExperienceHelper belongs to.\r\n * @param webVROptions Options to modify the vr experience helper's behavior.\r\n */\r\n constructor(\r\n scene: Scene,\r\n /** Options to modify the vr experience helper's behavior. */\r\n public webVROptions: VRExperienceHelperOptions = {}\r\n ) {\r\n Logger.Warn(\"WebVR is deprecated. Please avoid using this experience helper and use the WebXR experience helper instead\");\r\n this._scene = scene;\r\n this._inputElement = scene.getEngine().getInputElement();\r\n\r\n // check for VR support:\r\n\r\n const vrSupported = \"getVRDisplays\" in navigator;\r\n // no VR support? force XR but only when it is not set because web vr can work without the getVRDisplays\r\n if (!vrSupported && webVROptions.useXR === undefined) {\r\n webVROptions.useXR = true;\r\n }\r\n\r\n // Parse options\r\n if (webVROptions.createFallbackVRDeviceOrientationFreeCamera === undefined) {\r\n webVROptions.createFallbackVRDeviceOrientationFreeCamera = true;\r\n }\r\n if (webVROptions.createDeviceOrientationCamera === undefined) {\r\n webVROptions.createDeviceOrientationCamera = true;\r\n }\r\n if (webVROptions.laserToggle === undefined) {\r\n webVROptions.laserToggle = true;\r\n }\r\n if (webVROptions.defaultHeight === undefined) {\r\n webVROptions.defaultHeight = 1.7;\r\n }\r\n if (webVROptions.useCustomVRButton) {\r\n this._useCustomVRButton = true;\r\n if (webVROptions.customVRButton) {\r\n this._btnVR = webVROptions.customVRButton;\r\n }\r\n }\r\n if (webVROptions.rayLength) {\r\n this._rayLength = webVROptions.rayLength;\r\n }\r\n this._defaultHeight = webVROptions.defaultHeight;\r\n\r\n if (webVROptions.positionScale) {\r\n this._rayLength *= webVROptions.positionScale;\r\n this._defaultHeight *= webVROptions.positionScale;\r\n }\r\n\r\n this._hasEnteredVR = false;\r\n\r\n // Set position\r\n if (this._scene.activeCamera) {\r\n this._position = this._scene.activeCamera.position.clone();\r\n } else {\r\n this._position = new Vector3(0, this._defaultHeight, 0);\r\n }\r\n\r\n // Set non-vr camera\r\n if (webVROptions.createDeviceOrientationCamera || !this._scene.activeCamera) {\r\n this._deviceOrientationCamera = new DeviceOrientationCamera(\"deviceOrientationVRHelper\", this._position.clone(), scene);\r\n\r\n // Copy data from existing camera\r\n if (this._scene.activeCamera) {\r\n this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;\r\n this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;\r\n // Set rotation from previous camera\r\n if (this._scene.activeCamera instanceof TargetCamera && this._scene.activeCamera.rotation) {\r\n const targetCamera = this._scene.activeCamera;\r\n if (targetCamera.rotationQuaternion) {\r\n this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);\r\n } else {\r\n this._deviceOrientationCamera.rotationQuaternion.copyFrom(\r\n Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z)\r\n );\r\n }\r\n this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();\r\n }\r\n }\r\n\r\n this._scene.activeCamera = this._deviceOrientationCamera;\r\n if (this._inputElement) {\r\n this._scene.activeCamera.attachControl();\r\n }\r\n } else {\r\n this._existingCamera = this._scene.activeCamera;\r\n }\r\n\r\n if (this.webVROptions.useXR && (navigator as any).xr) {\r\n // force-check XR session support\r\n WebXRSessionManager.IsSessionSupportedAsync(\"immersive-vr\").then((supported) => {\r\n if (supported) {\r\n Logger.Log(\"Using WebXR. It is recommended to use the WebXRDefaultExperience directly\");\r\n // it is possible to use XR, let's do it!\r\n scene\r\n .createDefaultXRExperienceAsync({\r\n floorMeshes: webVROptions.floorMeshes || [],\r\n })\r\n .then((xr) => {\r\n this.xr = xr;\r\n // connect observables\r\n this.xrTestDone = true;\r\n\r\n this._cameraGazer = new VRExperienceHelperCameraGazer(() => {\r\n return this.xr.baseExperience.camera;\r\n }, scene);\r\n\r\n this.xr.baseExperience.onStateChangedObservable.add((state) => {\r\n // support for entering / exiting\r\n switch (state) {\r\n case WebXRState.ENTERING_XR:\r\n this.onEnteringVRObservable.notifyObservers(this);\r\n if (!this._interactionsEnabled) {\r\n this.xr.pointerSelection.detach();\r\n }\r\n this.xr.pointerSelection.displayLaserPointer = this._displayLaserPointer;\r\n break;\r\n case WebXRState.EXITING_XR:\r\n this.onExitingVRObservable.notifyObservers(this);\r\n\r\n // resize to update width and height when exiting vr exits fullscreen\r\n this._scene.getEngine().resize();\r\n break;\r\n case WebXRState.IN_XR:\r\n this._hasEnteredVR = true;\r\n break;\r\n case WebXRState.NOT_IN_XR:\r\n this._hasEnteredVR = false;\r\n break;\r\n }\r\n });\r\n });\r\n } else {\r\n // XR not supported (thou exists), continue WebVR init\r\n this._completeVRInit(scene, webVROptions);\r\n }\r\n });\r\n } else {\r\n // no XR, continue init synchronous\r\n this._completeVRInit(scene, webVROptions);\r\n }\r\n }\r\n\r\n private _completeVRInit(scene: Scene, webVROptions: VRExperienceHelperOptions): void {\r\n this.xrTestDone = true;\r\n // Create VR cameras\r\n if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {\r\n if (webVROptions.useMultiview) {\r\n if (!webVROptions.vrDeviceOrientationCameraMetrics) {\r\n webVROptions.vrDeviceOrientationCameraMetrics = VRCameraMetrics.GetDefault();\r\n }\r\n webVROptions.vrDeviceOrientationCameraMetrics.multiviewEnabled = true;\r\n }\r\n this._vrDeviceOrientationCamera = new VRDeviceOrientationFreeCamera(\r\n \"VRDeviceOrientationVRHelper\",\r\n this._position,\r\n this._scene,\r\n true,\r\n webVROptions.vrDeviceOrientationCameraMetrics\r\n );\r\n this._vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;\r\n }\r\n this._webVRCamera = new WebVRFreeCamera(\"WebVRHelper\", this._position, this._scene, webVROptions);\r\n this._webVRCamera.useStandingMatrix();\r\n\r\n this._cameraGazer = new VRExperienceHelperCameraGazer(() => {\r\n return this.currentVRCamera;\r\n }, scene);\r\n // Create default button\r\n if (!this._useCustomVRButton) {\r\n this._btnVR = document.createElement(\"BUTTON\");\r\n this._btnVR.className = \"babylonVRicon\";\r\n this._btnVR.id = \"babylonVRiconbtn\";\r\n this._btnVR.title = \"Click to switch to VR\";\r\n const url = !window.SVGSVGElement\r\n ? \"https://cdn.babylonjs.com/Assets/vrButton.png\"\r\n : \"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A\";\r\n let css =\r\n \".babylonVRicon { position: absolute; right: 20px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(\" +\r\n url +\r\n \"); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }\";\r\n css += \".babylonVRicon.vrdisplaypresenting { display: none; }\";\r\n // TODO: Add user feedback so that they know what state the VRDisplay is in (disconnected, connected, entering-VR)\r\n // css += \".babylonVRicon.vrdisplaysupported { }\";\r\n // css += \".babylonVRicon.vrdisplayready { }\";\r\n // css += \".babylonVRicon.vrdisplayrequesting { }\";\r\n\r\n const style = document.createElement(\"style\");\r\n style.appendChild(document.createTextNode(css));\r\n document.getElementsByTagName(\"head\")[0].appendChild(style);\r\n\r\n this._moveButtonToBottomRight();\r\n }\r\n\r\n // VR button click event\r\n if (this._btnVR) {\r\n this._btnVR.addEventListener(\"click\", () => {\r\n if (!this.isInVRMode) {\r\n this.enterVR();\r\n } else {\r\n this._scene.getEngine().disableVR();\r\n }\r\n });\r\n }\r\n\r\n // Window events\r\n\r\n const hostWindow = this._scene.getEngine().getHostWindow();\r\n if (!hostWindow) {\r\n return;\r\n }\r\n\r\n hostWindow.addEventListener(\"resize\", this._onResize);\r\n document.addEventListener(\"fullscreenchange\", this._onFullscreenChange, false);\r\n\r\n // Display vr button when headset is connected\r\n if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {\r\n this._displayVRButton();\r\n } else {\r\n this._scene.getEngine().onVRDisplayChangedObservable.add((e) => {\r\n if (e.vrDisplay) {\r\n this._displayVRButton();\r\n }\r\n });\r\n }\r\n\r\n // Exiting VR mode using 'ESC' key on desktop\r\n this._onKeyDown = (event: KeyboardEvent) => {\r\n if (event.keyCode === 27 && this.isInVRMode) {\r\n this.exitVR();\r\n }\r\n };\r\n document.addEventListener(\"keydown\", this._onKeyDown);\r\n\r\n // Exiting VR mode double tapping the touch screen\r\n this._scene.onPrePointerObservable.add(\r\n () => {\r\n if (this._hasEnteredVR && this.exitVROnDoubleTap) {\r\n this.exitVR();\r\n if (this._fullscreenVRpresenting) {\r\n this._scene.getEngine().exitFullscreen();\r\n }\r\n }\r\n },\r\n PointerEventTypes.POINTERDOUBLETAP,\r\n false\r\n );\r\n\r\n // Listen for WebVR display changes\r\n this._onVRDisplayChangedBind = (eventArgs: IDisplayChangedEventArgs) => this._onVRDisplayChanged(eventArgs);\r\n this._onVrDisplayPresentChangeBind = () => this._onVrDisplayPresentChange();\r\n this._onVRRequestPresentStart = () => {\r\n this._webVRrequesting = true;\r\n this._updateButtonVisibility();\r\n };\r\n this._onVRRequestPresentComplete = () => {\r\n this._webVRrequesting = false;\r\n this._updateButtonVisibility();\r\n };\r\n scene.getEngine().onVRDisplayChangedObservable.add(this._onVRDisplayChangedBind);\r\n scene.getEngine().onVRRequestPresentStart.add(this._onVRRequestPresentStart);\r\n scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);\r\n hostWindow.addEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChangeBind);\r\n\r\n scene.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n\r\n // Gamepad connection events\r\n this._webVRCamera.onControllerMeshLoadedObservable.add((webVRController) => this._onDefaultMeshLoaded(webVRController));\r\n this._scene.gamepadManager.onGamepadConnectedObservable.add(this._onNewGamepadConnected);\r\n this._scene.gamepadManager.onGamepadDisconnectedObservable.add(this._onNewGamepadDisconnected);\r\n\r\n this._updateButtonVisibility();\r\n\r\n //create easing functions\r\n this._circleEase = new CircleEase();\r\n this._circleEase.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\r\n this._teleportationEasing = this._circleEase;\r\n\r\n // Allow clicking in the vrDeviceOrientationCamera\r\n scene.onPointerObservable.add((e) => {\r\n if (this._interactionsEnabled) {\r\n if (scene.activeCamera === this.vrDeviceOrientationCamera && (e.event as IPointerEvent).pointerType === \"mouse\") {\r\n if (e.type === PointerEventTypes.POINTERDOWN) {\r\n this._cameraGazer._selectionPointerDown();\r\n } else if (e.type === PointerEventTypes.POINTERUP) {\r\n this._cameraGazer._selectionPointerUp();\r\n }\r\n }\r\n }\r\n });\r\n\r\n if (this.webVROptions.floorMeshes) {\r\n this.enableTeleportation({ floorMeshes: this.webVROptions.floorMeshes });\r\n }\r\n }\r\n\r\n // Raised when one of the controller has loaded successfully its associated default mesh\r\n private _onDefaultMeshLoaded(webVRController: WebVRController) {\r\n if (this._leftController && this._leftController.webVRController == webVRController) {\r\n if (webVRController.mesh) {\r\n this._leftController._setLaserPointerParent(webVRController.mesh);\r\n }\r\n }\r\n if (this._rightController && this._rightController.webVRController == webVRController) {\r\n if (webVRController.mesh) {\r\n this._rightController._setLaserPointerParent(webVRController.mesh);\r\n }\r\n }\r\n\r\n try {\r\n this.onControllerMeshLoadedObservable.notifyObservers(webVRController);\r\n } catch (err) {\r\n Logger.Warn(\"Error in your custom logic onControllerMeshLoaded: \" + err);\r\n }\r\n }\r\n\r\n private _onResize = () => {\r\n this._moveButtonToBottomRight();\r\n if (this._fullscreenVRpresenting && this._webVRready) {\r\n this.exitVR();\r\n }\r\n };\r\n\r\n private _onFullscreenChange = () => {\r\n this._fullscreenVRpresenting = !!document.fullscreenElement;\r\n if (!this._fullscreenVRpresenting && this._inputElement) {\r\n this.exitVR();\r\n if (!this._useCustomVRButton && this._btnVR) {\r\n this._btnVR.style.top = this._inputElement.offsetTop + this._inputElement.offsetHeight - 70 + \"px\";\r\n this._btnVR.style.left = this._inputElement.offsetLeft + this._inputElement.offsetWidth - 100 + \"px\";\r\n // make sure the button is visible after setting its position\r\n this._updateButtonVisibility();\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Gets a value indicating if we are currently in VR mode.\r\n */\r\n public get isInVRMode(): boolean {\r\n return (this.xr && this.webVROptions.useXR && this.xr.baseExperience.state === WebXRState.IN_XR) || this._webVRpresenting || this._fullscreenVRpresenting;\r\n }\r\n\r\n private _onVrDisplayPresentChange() {\r\n const vrDisplay = this._scene.getEngine().getVRDevice();\r\n if (vrDisplay) {\r\n const wasPresenting = this._webVRpresenting;\r\n this._webVRpresenting = vrDisplay.isPresenting;\r\n\r\n if (wasPresenting && !this._webVRpresenting) {\r\n this.exitVR();\r\n }\r\n } else {\r\n Logger.Warn(\"Detected VRDisplayPresentChange on an unknown VRDisplay. Did you can enterVR on the vrExperienceHelper?\");\r\n }\r\n\r\n this._updateButtonVisibility();\r\n }\r\n\r\n private _onVRDisplayChanged(eventArgs: IDisplayChangedEventArgs) {\r\n this._webVRsupported = eventArgs.vrSupported;\r\n this._webVRready = !!eventArgs.vrDisplay;\r\n this._webVRpresenting = eventArgs.vrDisplay && eventArgs.vrDisplay.isPresenting;\r\n\r\n this._updateButtonVisibility();\r\n }\r\n\r\n private _moveButtonToBottomRight() {\r\n if (this._inputElement && !this._useCustomVRButton && this._btnVR) {\r\n const rect: ClientRect = this._inputElement.getBoundingClientRect();\r\n this._btnVR.style.top = rect.top + rect.height - 70 + \"px\";\r\n this._btnVR.style.left = rect.left + rect.width - 100 + \"px\";\r\n }\r\n }\r\n\r\n private _displayVRButton() {\r\n if (!this._useCustomVRButton && !this._btnVRDisplayed && this._btnVR) {\r\n document.body.appendChild(this._btnVR);\r\n this._btnVRDisplayed = true;\r\n }\r\n }\r\n\r\n private _updateButtonVisibility() {\r\n if (!this._btnVR || this._useCustomVRButton) {\r\n return;\r\n }\r\n this._btnVR.className = \"babylonVRicon\";\r\n if (this.isInVRMode) {\r\n this._btnVR.className += \" vrdisplaypresenting\";\r\n } else {\r\n if (this._webVRready) {\r\n this._btnVR.className += \" vrdisplayready\";\r\n }\r\n if (this._webVRsupported) {\r\n this._btnVR.className += \" vrdisplaysupported\";\r\n }\r\n if (this._webVRrequesting) {\r\n this._btnVR.className += \" vrdisplayrequesting\";\r\n }\r\n }\r\n }\r\n\r\n private _cachedAngularSensibility = { angularSensibilityX: null, angularSensibilityY: null, angularSensibility: null };\r\n /**\r\n * Attempt to enter VR. If a headset is connected and ready, will request present on that.\r\n * Otherwise, will use the fullscreen API.\r\n */\r\n public enterVR() {\r\n if (this.xr) {\r\n this.xr.baseExperience.enterXRAsync(\"immersive-vr\", \"local-floor\", this.xr.renderTarget);\r\n return;\r\n }\r\n if (this.onEnteringVRObservable) {\r\n try {\r\n this.onEnteringVRObservable.notifyObservers(this);\r\n } catch (err) {\r\n Logger.Warn(\"Error in your custom logic onEnteringVR: \" + err);\r\n }\r\n }\r\n\r\n if (this._scene.activeCamera) {\r\n this._position = this._scene.activeCamera.position.clone();\r\n\r\n if (this.vrDeviceOrientationCamera) {\r\n this.vrDeviceOrientationCamera.rotation = Quaternion.FromRotationMatrix(this._scene.activeCamera.getWorldMatrix().getRotationMatrix()).toEulerAngles();\r\n this.vrDeviceOrientationCamera.angularSensibility = 2000;\r\n }\r\n if (this.webVRCamera) {\r\n const currentYRotation = this.webVRCamera.deviceRotationQuaternion.toEulerAngles().y;\r\n const desiredYRotation = Quaternion.FromRotationMatrix(this._scene.activeCamera.getWorldMatrix().getRotationMatrix()).toEulerAngles().y;\r\n const delta = desiredYRotation - currentYRotation;\r\n const currentGlobalRotation = this.webVRCamera.rotationQuaternion.toEulerAngles().y;\r\n this.webVRCamera.rotationQuaternion = Quaternion.FromEulerAngles(0, currentGlobalRotation + delta, 0);\r\n }\r\n\r\n // make sure that we return to the last active camera\r\n this._existingCamera = this._scene.activeCamera;\r\n\r\n // Remove and cache angular sensability to avoid camera rotation when in VR\r\n if ((this._existingCamera).angularSensibilityX) {\r\n this._cachedAngularSensibility.angularSensibilityX = (this._existingCamera).angularSensibilityX;\r\n (this._existingCamera).angularSensibilityX = Number.MAX_VALUE;\r\n }\r\n if ((this._existingCamera).angularSensibilityY) {\r\n this._cachedAngularSensibility.angularSensibilityY = (this._existingCamera).angularSensibilityY;\r\n (this._existingCamera).angularSensibilityY = Number.MAX_VALUE;\r\n }\r\n if ((this._existingCamera).angularSensibility) {\r\n this._cachedAngularSensibility.angularSensibility = (this._existingCamera).angularSensibility;\r\n (this._existingCamera).angularSensibility = Number.MAX_VALUE;\r\n }\r\n }\r\n\r\n if (this._webVRrequesting) {\r\n return;\r\n }\r\n\r\n // If WebVR is supported and a headset is connected\r\n if (this._webVRready) {\r\n if (!this._webVRpresenting) {\r\n this._scene.getEngine().onVRRequestPresentComplete.addOnce((result) => {\r\n this.onAfterEnteringVRObservable.notifyObservers({ success: result });\r\n });\r\n this._webVRCamera.position = this._position;\r\n this._scene.activeCamera = this._webVRCamera;\r\n }\r\n } else if (this._vrDeviceOrientationCamera) {\r\n this._vrDeviceOrientationCamera.position = this._position;\r\n if (this._scene.activeCamera) {\r\n this._vrDeviceOrientationCamera.minZ = this._scene.activeCamera.minZ;\r\n }\r\n this._scene.activeCamera = this._vrDeviceOrientationCamera;\r\n this._scene.getEngine().enterFullscreen(this.requestPointerLockOnFullScreen);\r\n this._updateButtonVisibility();\r\n this._vrDeviceOrientationCamera.onViewMatrixChangedObservable.addOnce(() => {\r\n this.onAfterEnteringVRObservable.notifyObservers({ success: true });\r\n });\r\n }\r\n\r\n if (this._scene.activeCamera && this._inputElement) {\r\n this._scene.activeCamera.attachControl();\r\n }\r\n\r\n if (this._interactionsEnabled) {\r\n this._scene.registerBeforeRender(this._beforeRender);\r\n }\r\n\r\n if (this._displayLaserPointer) {\r\n [this._leftController, this._rightController].forEach((controller) => {\r\n if (controller) {\r\n controller._activatePointer();\r\n }\r\n });\r\n }\r\n\r\n this._hasEnteredVR = true;\r\n }\r\n\r\n /**\r\n * Attempt to exit VR, or fullscreen.\r\n */\r\n public exitVR() {\r\n if (this.xr) {\r\n this.xr.baseExperience.exitXRAsync();\r\n return;\r\n }\r\n if (this._hasEnteredVR) {\r\n if (this.onExitingVRObservable) {\r\n try {\r\n this.onExitingVRObservable.notifyObservers(this);\r\n } catch (err) {\r\n Logger.Warn(\"Error in your custom logic onExitingVR: \" + err);\r\n }\r\n }\r\n if (this._webVRpresenting) {\r\n this._scene.getEngine().disableVR();\r\n }\r\n if (this._scene.activeCamera) {\r\n this._position = this._scene.activeCamera.position.clone();\r\n }\r\n\r\n if (this.vrDeviceOrientationCamera) {\r\n this.vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;\r\n }\r\n\r\n if (this._deviceOrientationCamera) {\r\n this._deviceOrientationCamera.position = this._position;\r\n this._scene.activeCamera = this._deviceOrientationCamera;\r\n\r\n // Restore angular sensibility\r\n if (this._cachedAngularSensibility.angularSensibilityX) {\r\n (this._deviceOrientationCamera).angularSensibilityX = this._cachedAngularSensibility.angularSensibilityX;\r\n this._cachedAngularSensibility.angularSensibilityX = null;\r\n }\r\n if (this._cachedAngularSensibility.angularSensibilityY) {\r\n (this._deviceOrientationCamera).angularSensibilityY = this._cachedAngularSensibility.angularSensibilityY;\r\n this._cachedAngularSensibility.angularSensibilityY = null;\r\n }\r\n if (this._cachedAngularSensibility.angularSensibility) {\r\n (this._deviceOrientationCamera).angularSensibility = this._cachedAngularSensibility.angularSensibility;\r\n this._cachedAngularSensibility.angularSensibility = null;\r\n }\r\n } else if (this._existingCamera) {\r\n this._existingCamera.position = this._position;\r\n this._scene.activeCamera = this._existingCamera;\r\n if (this._inputElement) {\r\n this._scene.activeCamera.attachControl();\r\n }\r\n\r\n // Restore angular sensibility\r\n if (this._cachedAngularSensibility.angularSensibilityX) {\r\n (this._existingCamera).angularSensibilityX = this._cachedAngularSensibility.angularSensibilityX;\r\n this._cachedAngularSensibility.angularSensibilityX = null;\r\n }\r\n if (this._cachedAngularSensibility.angularSensibilityY) {\r\n (this._existingCamera).angularSensibilityY = this._cachedAngularSensibility.angularSensibilityY;\r\n this._cachedAngularSensibility.angularSensibilityY = null;\r\n }\r\n if (this._cachedAngularSensibility.angularSensibility) {\r\n (this._existingCamera).angularSensibility = this._cachedAngularSensibility.angularSensibility;\r\n this._cachedAngularSensibility.angularSensibility = null;\r\n }\r\n }\r\n\r\n this._updateButtonVisibility();\r\n\r\n if (this._interactionsEnabled) {\r\n this._scene.unregisterBeforeRender(this._beforeRender);\r\n this._cameraGazer._gazeTracker.isVisible = false;\r\n if (this._leftController) {\r\n this._leftController._gazeTracker.isVisible = false;\r\n }\r\n if (this._rightController) {\r\n this._rightController._gazeTracker.isVisible = false;\r\n }\r\n }\r\n\r\n // resize to update width and height when exiting vr exits fullscreen\r\n this._scene.getEngine().resize();\r\n\r\n [this._leftController, this._rightController].forEach((controller) => {\r\n if (controller) {\r\n controller._deactivatePointer();\r\n }\r\n });\r\n\r\n this._hasEnteredVR = false;\r\n\r\n // Update engine state to re enable non-vr camera input\r\n const engine = this._scene.getEngine();\r\n if (engine._onVrDisplayPresentChange) {\r\n engine._onVrDisplayPresentChange();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * The position of the vr experience helper.\r\n */\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n\r\n /**\r\n * Sets the position of the vr experience helper.\r\n */\r\n public set position(value: Vector3) {\r\n this._position = value;\r\n\r\n if (this._scene.activeCamera) {\r\n this._scene.activeCamera.position = value;\r\n }\r\n }\r\n\r\n /**\r\n * Enables controllers and user interactions such as selecting and object or clicking on an object.\r\n */\r\n public enableInteractions() {\r\n if (!this._interactionsEnabled) {\r\n this._interactionsRequested = true;\r\n\r\n // in XR it is enabled by default, but just to make sure, re-attach\r\n if (this.xr) {\r\n if (this.xr.baseExperience.state === WebXRState.IN_XR) {\r\n this.xr.pointerSelection.attach();\r\n }\r\n return;\r\n }\r\n\r\n if (this._leftController) {\r\n this._enableInteractionOnController(this._leftController);\r\n }\r\n\r\n if (this._rightController) {\r\n this._enableInteractionOnController(this._rightController);\r\n }\r\n\r\n this.raySelectionPredicate = (mesh) => {\r\n return mesh.isVisible && (mesh.isPickable || mesh.name === this._floorMeshName);\r\n };\r\n\r\n this.meshSelectionPredicate = () => {\r\n return true;\r\n };\r\n\r\n this._raySelectionPredicate = (mesh) => {\r\n if (\r\n this._isTeleportationFloor(mesh) ||\r\n (mesh.name.indexOf(\"gazeTracker\") === -1 && mesh.name.indexOf(\"teleportationTarget\") === -1 && mesh.name.indexOf(\"torusTeleportation\") === -1)\r\n ) {\r\n return this.raySelectionPredicate(mesh);\r\n }\r\n return false;\r\n };\r\n\r\n this._interactionsEnabled = true;\r\n }\r\n }\r\n\r\n private get _noControllerIsActive() {\r\n return !(this._leftController && this._leftController._activePointer) && !(this._rightController && this._rightController._activePointer);\r\n }\r\n\r\n private _beforeRender = () => {\r\n if (this._leftController && this._leftController._activePointer) {\r\n this._castRayAndSelectObject(this._leftController);\r\n }\r\n\r\n if (this._rightController && this._rightController._activePointer) {\r\n this._castRayAndSelectObject(this._rightController);\r\n }\r\n\r\n if (this._noControllerIsActive && (this._scene.getEngine().isPointerLock || this.enableGazeEvenWhenNoPointerLock)) {\r\n this._castRayAndSelectObject(this._cameraGazer);\r\n } else {\r\n this._cameraGazer._gazeTracker.isVisible = false;\r\n }\r\n };\r\n\r\n private _isTeleportationFloor(mesh: AbstractMesh): boolean {\r\n for (let i = 0; i < this._floorMeshesCollection.length; i++) {\r\n if (this._floorMeshesCollection[i].id === mesh.id) {\r\n return true;\r\n }\r\n }\r\n if (this._floorMeshName && mesh.name === this._floorMeshName) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Adds a floor mesh to be used for teleportation.\r\n * @param floorMesh the mesh to be used for teleportation.\r\n */\r\n public addFloorMesh(floorMesh: Mesh): void {\r\n if (!this._floorMeshesCollection) {\r\n return;\r\n }\r\n\r\n if (this._floorMeshesCollection.indexOf(floorMesh) > -1) {\r\n return;\r\n }\r\n\r\n this._floorMeshesCollection.push(floorMesh);\r\n }\r\n\r\n /**\r\n * Removes a floor mesh from being used for teleportation.\r\n * @param floorMesh the mesh to be removed.\r\n */\r\n public removeFloorMesh(floorMesh: Mesh): void {\r\n if (!this._floorMeshesCollection) {\r\n return;\r\n }\r\n\r\n const meshIndex = this._floorMeshesCollection.indexOf(floorMesh);\r\n if (meshIndex !== -1) {\r\n this._floorMeshesCollection.splice(meshIndex, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Enables interactions and teleportation using the VR controllers and gaze.\r\n * @param vrTeleportationOptions options to modify teleportation behavior.\r\n */\r\n public enableTeleportation(vrTeleportationOptions: VRTeleportationOptions = {}) {\r\n if (!this._teleportationInitialized) {\r\n this._teleportationRequested = true;\r\n\r\n this.enableInteractions();\r\n\r\n if (this.webVROptions.useXR && (vrTeleportationOptions.floorMeshes || vrTeleportationOptions.floorMeshName)) {\r\n const floorMeshes: AbstractMesh[] = vrTeleportationOptions.floorMeshes || [];\r\n if (!floorMeshes.length) {\r\n const floorMesh = this._scene.getMeshByName(vrTeleportationOptions.floorMeshName!);\r\n if (floorMesh) {\r\n floorMeshes.push(floorMesh);\r\n }\r\n }\r\n if (this.xr) {\r\n floorMeshes.forEach((mesh) => {\r\n this.xr.teleportation.addFloorMesh(mesh);\r\n });\r\n if (!this.xr.teleportation.attached) {\r\n this.xr.teleportation.attach();\r\n }\r\n return;\r\n } else if (!this.xrTestDone) {\r\n const waitForXr = () => {\r\n if (this.xrTestDone) {\r\n this._scene.unregisterBeforeRender(waitForXr);\r\n if (this.xr) {\r\n if (!this.xr.teleportation.attached) {\r\n this.xr.teleportation.attach();\r\n }\r\n } else {\r\n this.enableTeleportation(vrTeleportationOptions);\r\n }\r\n }\r\n };\r\n this._scene.registerBeforeRender(waitForXr);\r\n return;\r\n }\r\n }\r\n\r\n if (vrTeleportationOptions.floorMeshName) {\r\n this._floorMeshName = vrTeleportationOptions.floorMeshName;\r\n }\r\n if (vrTeleportationOptions.floorMeshes) {\r\n this._floorMeshesCollection = vrTeleportationOptions.floorMeshes;\r\n }\r\n\r\n if (vrTeleportationOptions.teleportationMode) {\r\n this._teleportationMode = vrTeleportationOptions.teleportationMode;\r\n }\r\n if (vrTeleportationOptions.teleportationTime && vrTeleportationOptions.teleportationTime > 0) {\r\n this._teleportationTime = vrTeleportationOptions.teleportationTime;\r\n }\r\n if (vrTeleportationOptions.teleportationSpeed && vrTeleportationOptions.teleportationSpeed > 0) {\r\n this._teleportationSpeed = vrTeleportationOptions.teleportationSpeed;\r\n }\r\n if (vrTeleportationOptions.easingFunction !== undefined) {\r\n this._teleportationEasing = vrTeleportationOptions.easingFunction;\r\n }\r\n\r\n if (this._leftController != null) {\r\n this._enableTeleportationOnController(this._leftController);\r\n }\r\n if (this._rightController != null) {\r\n this._enableTeleportationOnController(this._rightController);\r\n }\r\n\r\n // Creates an image processing post process for the vignette not relying\r\n // on the main scene configuration for image processing to reduce setup and spaces\r\n // (gamma/linear) conflicts.\r\n const imageProcessingConfiguration = new ImageProcessingConfiguration();\r\n imageProcessingConfiguration.vignetteColor = new Color4(0, 0, 0, 0);\r\n imageProcessingConfiguration.vignetteEnabled = true;\r\n this._postProcessMove = new ImageProcessingPostProcess(\r\n \"postProcessMove\",\r\n 1.0,\r\n this._webVRCamera,\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n imageProcessingConfiguration\r\n );\r\n\r\n this._webVRCamera.detachPostProcess(this._postProcessMove);\r\n this._teleportationInitialized = true;\r\n if (this._isDefaultTeleportationTarget) {\r\n this._createTeleportationCircles();\r\n this._teleportationTarget.scaling.scaleInPlace(this._webVRCamera.deviceScaleFactor);\r\n }\r\n }\r\n }\r\n\r\n private _onNewGamepadConnected = (gamepad: Gamepad) => {\r\n if (gamepad.type !== Gamepad.POSE_ENABLED) {\r\n if (gamepad.leftStick) {\r\n gamepad.onleftstickchanged((stickValues) => {\r\n if (this._teleportationInitialized && this.teleportationEnabled) {\r\n // Listening to classic/xbox gamepad only if no VR controller is active\r\n if (\r\n (!this._leftController && !this._rightController) ||\r\n (this._leftController && !this._leftController._activePointer && this._rightController && !this._rightController._activePointer)\r\n ) {\r\n this._checkTeleportWithRay(stickValues, this._cameraGazer);\r\n this._checkTeleportBackwards(stickValues, this._cameraGazer);\r\n }\r\n }\r\n });\r\n }\r\n if (gamepad.rightStick) {\r\n gamepad.onrightstickchanged((stickValues) => {\r\n if (this._teleportationInitialized) {\r\n this._checkRotate(stickValues, this._cameraGazer);\r\n }\r\n });\r\n }\r\n if (gamepad.type === Gamepad.XBOX) {\r\n (gamepad).onbuttondown((buttonPressed: Xbox360Button) => {\r\n if (this._interactionsEnabled && buttonPressed === Xbox360Button.A) {\r\n this._cameraGazer._selectionPointerDown();\r\n }\r\n });\r\n (gamepad).onbuttonup((buttonPressed: Xbox360Button) => {\r\n if (this._interactionsEnabled && buttonPressed === Xbox360Button.A) {\r\n this._cameraGazer._selectionPointerUp();\r\n }\r\n });\r\n }\r\n } else {\r\n const webVRController = gamepad;\r\n const controller = new VRExperienceHelperControllerGazer(webVRController, this._scene, this._cameraGazer._gazeTracker);\r\n\r\n if (webVRController.hand === \"right\" || (this._leftController && this._leftController.webVRController != webVRController)) {\r\n this._rightController = controller;\r\n } else {\r\n this._leftController = controller;\r\n }\r\n\r\n this._tryEnableInteractionOnController(controller);\r\n }\r\n };\r\n\r\n // This only succeeds if the controller's mesh exists for the controller so this must be called whenever new controller is connected or when mesh is loaded\r\n private _tryEnableInteractionOnController = (controller: VRExperienceHelperControllerGazer) => {\r\n if (this._interactionsRequested && !controller._interactionsEnabled) {\r\n this._enableInteractionOnController(controller);\r\n }\r\n if (this._teleportationRequested && !controller._teleportationEnabled) {\r\n this._enableTeleportationOnController(controller);\r\n }\r\n };\r\n\r\n private _onNewGamepadDisconnected = (gamepad: Gamepad) => {\r\n if (gamepad instanceof WebVRController) {\r\n if (gamepad.hand === \"left\" && this._leftController != null) {\r\n this._leftController.dispose();\r\n this._leftController = null;\r\n }\r\n if (gamepad.hand === \"right\" && this._rightController != null) {\r\n this._rightController.dispose();\r\n this._rightController = null;\r\n }\r\n }\r\n };\r\n\r\n private _enableInteractionOnController(controller: VRExperienceHelperControllerGazer) {\r\n const controllerMesh = controller.webVRController.mesh;\r\n if (controllerMesh) {\r\n controller._interactionsEnabled = true;\r\n if (this.isInVRMode && this._displayLaserPointer) {\r\n controller._activatePointer();\r\n }\r\n if (this.webVROptions.laserToggle) {\r\n controller.webVRController.onMainButtonStateChangedObservable.add((stateObject) => {\r\n // Enabling / disabling laserPointer\r\n if (this._displayLaserPointer && stateObject.value === 1) {\r\n if (controller._activePointer) {\r\n controller._deactivatePointer();\r\n } else {\r\n controller._activatePointer();\r\n }\r\n if (this.displayGaze) {\r\n controller._gazeTracker.isVisible = controller._activePointer;\r\n }\r\n }\r\n });\r\n }\r\n controller.webVRController.onTriggerStateChangedObservable.add((stateObject) => {\r\n let gazer: VRExperienceHelperGazer = controller;\r\n if (this._noControllerIsActive) {\r\n gazer = this._cameraGazer;\r\n }\r\n if (!gazer._pointerDownOnMeshAsked) {\r\n if (stateObject.value > this._padSensibilityUp) {\r\n gazer._selectionPointerDown();\r\n }\r\n } else if (stateObject.value < this._padSensibilityDown) {\r\n gazer._selectionPointerUp();\r\n }\r\n });\r\n }\r\n }\r\n\r\n private _checkTeleportWithRay(stateObject: StickValues, gazer: VRExperienceHelperGazer) {\r\n // Dont teleport if another gaze already requested teleportation\r\n if (this._teleportationRequestInitiated && !gazer._teleportationRequestInitiated) {\r\n return;\r\n }\r\n if (!gazer._teleportationRequestInitiated) {\r\n if (stateObject.y < -this._padSensibilityUp && gazer._dpadPressed) {\r\n gazer._activatePointer();\r\n gazer._teleportationRequestInitiated = true;\r\n }\r\n } else {\r\n // Listening to the proper controller values changes to confirm teleportation\r\n if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {\r\n if (this._teleportActive) {\r\n this.teleportCamera(this._haloCenter);\r\n }\r\n\r\n gazer._teleportationRequestInitiated = false;\r\n }\r\n }\r\n }\r\n private _checkRotate(stateObject: StickValues, gazer: VRExperienceHelperGazer) {\r\n // Only rotate when user is not currently selecting a teleportation location\r\n if (gazer._teleportationRequestInitiated) {\r\n return;\r\n }\r\n\r\n if (!gazer._rotationLeftAsked) {\r\n if (stateObject.x < -this._padSensibilityUp && gazer._dpadPressed) {\r\n gazer._rotationLeftAsked = true;\r\n if (this._rotationAllowed) {\r\n this._rotateCamera(false);\r\n }\r\n }\r\n } else {\r\n if (stateObject.x > -this._padSensibilityDown) {\r\n gazer._rotationLeftAsked = false;\r\n }\r\n }\r\n\r\n if (!gazer._rotationRightAsked) {\r\n if (stateObject.x > this._padSensibilityUp && gazer._dpadPressed) {\r\n gazer._rotationRightAsked = true;\r\n if (this._rotationAllowed) {\r\n this._rotateCamera(true);\r\n }\r\n }\r\n } else {\r\n if (stateObject.x < this._padSensibilityDown) {\r\n gazer._rotationRightAsked = false;\r\n }\r\n }\r\n }\r\n private _checkTeleportBackwards(stateObject: StickValues, gazer: VRExperienceHelperGazer) {\r\n // Only teleport backwards when user is not currently selecting a teleportation location\r\n if (gazer._teleportationRequestInitiated) {\r\n return;\r\n }\r\n // Teleport backwards\r\n if (stateObject.y > this._padSensibilityUp && gazer._dpadPressed) {\r\n if (!gazer._teleportationBackRequestInitiated) {\r\n if (!this.currentVRCamera) {\r\n return;\r\n }\r\n\r\n // Get rotation and position of the current camera\r\n let rotation = Quaternion.FromRotationMatrix(this.currentVRCamera.getWorldMatrix().getRotationMatrix());\r\n let position = this.currentVRCamera.position;\r\n\r\n // If the camera has device position, use that instead\r\n if ((this.currentVRCamera).devicePosition && (this.currentVRCamera).deviceRotationQuaternion) {\r\n rotation = (this.currentVRCamera).deviceRotationQuaternion;\r\n position = (this.currentVRCamera).devicePosition;\r\n }\r\n\r\n // Get matrix with only the y rotation of the device rotation\r\n rotation.toEulerAnglesToRef(this._workingVector);\r\n this._workingVector.z = 0;\r\n this._workingVector.x = 0;\r\n Quaternion.RotationYawPitchRollToRef(this._workingVector.y, this._workingVector.x, this._workingVector.z, this._workingQuaternion);\r\n this._workingQuaternion.toRotationMatrix(this._workingMatrix);\r\n\r\n // Rotate backwards ray by device rotation to cast at the ground behind the user\r\n Vector3.TransformCoordinatesToRef(this._teleportBackwardsVector, this._workingMatrix, this._workingVector);\r\n\r\n // Teleport if ray hit the ground and is not to far away eg. backwards off a cliff\r\n const ray = new Ray(position, this._workingVector);\r\n const hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);\r\n if (hit && hit.pickedPoint && hit.pickedMesh && this._isTeleportationFloor(hit.pickedMesh) && hit.distance < 5) {\r\n this.teleportCamera(hit.pickedPoint);\r\n }\r\n\r\n gazer._teleportationBackRequestInitiated = true;\r\n }\r\n } else {\r\n gazer._teleportationBackRequestInitiated = false;\r\n }\r\n }\r\n\r\n private _enableTeleportationOnController(controller: VRExperienceHelperControllerGazer) {\r\n const controllerMesh = controller.webVRController.mesh;\r\n if (controllerMesh) {\r\n if (!controller._interactionsEnabled) {\r\n this._enableInteractionOnController(controller);\r\n }\r\n controller._interactionsEnabled = true;\r\n controller._teleportationEnabled = true;\r\n if (controller.webVRController.controllerType === PoseEnabledControllerType.VIVE) {\r\n controller._dpadPressed = false;\r\n controller.webVRController.onPadStateChangedObservable.add((stateObject) => {\r\n controller._dpadPressed = stateObject.pressed;\r\n if (!controller._dpadPressed) {\r\n controller._rotationLeftAsked = false;\r\n controller._rotationRightAsked = false;\r\n controller._teleportationBackRequestInitiated = false;\r\n }\r\n });\r\n }\r\n controller.webVRController.onPadValuesChangedObservable.add((stateObject) => {\r\n if (this.teleportationEnabled) {\r\n this._checkTeleportBackwards(stateObject, controller);\r\n this._checkTeleportWithRay(stateObject, controller);\r\n }\r\n this._checkRotate(stateObject, controller);\r\n });\r\n }\r\n }\r\n\r\n private _createTeleportationCircles() {\r\n this._teleportationTarget = CreateGround(\"teleportationTarget\", { width: 2, height: 2, subdivisions: 2 }, this._scene);\r\n this._teleportationTarget.isPickable = false;\r\n\r\n const length = 512;\r\n const dynamicTexture = new DynamicTexture(\"DynamicTexture\", length, this._scene, true);\r\n dynamicTexture.hasAlpha = true;\r\n const context = dynamicTexture.getContext();\r\n\r\n const centerX = length / 2;\r\n const centerY = length / 2;\r\n const radius = 200;\r\n\r\n context.beginPath();\r\n context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);\r\n context.fillStyle = this._teleportationFillColor;\r\n context.fill();\r\n context.lineWidth = 10;\r\n context.strokeStyle = this._teleportationBorderColor;\r\n context.stroke();\r\n context.closePath();\r\n dynamicTexture.update();\r\n\r\n const teleportationCircleMaterial = new StandardMaterial(\"TextPlaneMaterial\", this._scene);\r\n teleportationCircleMaterial.diffuseTexture = dynamicTexture;\r\n this._teleportationTarget.material = teleportationCircleMaterial;\r\n\r\n const torus = CreateTorus(\r\n \"torusTeleportation\",\r\n {\r\n diameter: 0.75,\r\n thickness: 0.1,\r\n tessellation: 25,\r\n updatable: false,\r\n },\r\n this._scene\r\n );\r\n torus.isPickable = false;\r\n torus.parent = this._teleportationTarget;\r\n\r\n const animationInnerCircle = new Animation(\"animationInnerCircle\", \"position.y\", 30, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);\r\n\r\n const keys = [];\r\n keys.push({\r\n frame: 0,\r\n value: 0,\r\n });\r\n keys.push({\r\n frame: 30,\r\n value: 0.4,\r\n });\r\n keys.push({\r\n frame: 60,\r\n value: 0,\r\n });\r\n\r\n animationInnerCircle.setKeys(keys);\r\n\r\n const easingFunction = new SineEase();\r\n easingFunction.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\r\n animationInnerCircle.setEasingFunction(easingFunction);\r\n\r\n torus.animations = [];\r\n torus.animations.push(animationInnerCircle);\r\n\r\n this._scene.beginAnimation(torus, 0, 60, true);\r\n\r\n this._hideTeleportationTarget();\r\n }\r\n\r\n private _displayTeleportationTarget() {\r\n this._teleportActive = true;\r\n if (this._teleportationInitialized) {\r\n this._teleportationTarget.isVisible = true;\r\n if (this._isDefaultTeleportationTarget) {\r\n (this._teleportationTarget.getChildren()[0]).isVisible = true;\r\n }\r\n }\r\n }\r\n\r\n private _hideTeleportationTarget() {\r\n this._teleportActive = false;\r\n if (this._teleportationInitialized) {\r\n this._teleportationTarget.isVisible = false;\r\n if (this._isDefaultTeleportationTarget) {\r\n (this._teleportationTarget.getChildren()[0]).isVisible = false;\r\n }\r\n }\r\n }\r\n\r\n private _rotateCamera(right: boolean) {\r\n if (!(this.currentVRCamera instanceof FreeCamera)) {\r\n return;\r\n }\r\n\r\n if (right) {\r\n this._rotationAngle++;\r\n } else {\r\n this._rotationAngle--;\r\n }\r\n\r\n this.currentVRCamera.animations = [];\r\n\r\n const target = Quaternion.FromRotationMatrix(Matrix.RotationY((Math.PI / 4) * this._rotationAngle));\r\n\r\n const animationRotation = new Animation(\"animationRotation\", \"rotationQuaternion\", 90, Animation.ANIMATIONTYPE_QUATERNION, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n const animationRotationKeys = [];\r\n animationRotationKeys.push({\r\n frame: 0,\r\n value: this.currentVRCamera.rotationQuaternion,\r\n });\r\n animationRotationKeys.push({\r\n frame: 6,\r\n value: target,\r\n });\r\n\r\n animationRotation.setKeys(animationRotationKeys);\r\n\r\n animationRotation.setEasingFunction(this._circleEase);\r\n\r\n this.currentVRCamera.animations.push(animationRotation);\r\n\r\n this._postProcessMove.animations = [];\r\n\r\n const animationPP = new Animation(\"animationPP\", \"vignetteWeight\", 90, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n const vignetteWeightKeys = [];\r\n vignetteWeightKeys.push({\r\n frame: 0,\r\n value: 0,\r\n });\r\n vignetteWeightKeys.push({\r\n frame: 3,\r\n value: 4,\r\n });\r\n vignetteWeightKeys.push({\r\n frame: 6,\r\n value: 0,\r\n });\r\n\r\n animationPP.setKeys(vignetteWeightKeys);\r\n animationPP.setEasingFunction(this._circleEase);\r\n this._postProcessMove.animations.push(animationPP);\r\n\r\n const animationPP2 = new Animation(\"animationPP2\", \"vignetteStretch\", 90, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n const vignetteStretchKeys = [];\r\n vignetteStretchKeys.push({\r\n frame: 0,\r\n value: 0,\r\n });\r\n vignetteStretchKeys.push({\r\n frame: 3,\r\n value: 10,\r\n });\r\n vignetteStretchKeys.push({\r\n frame: 6,\r\n value: 0,\r\n });\r\n\r\n animationPP2.setKeys(vignetteStretchKeys);\r\n animationPP2.setEasingFunction(this._circleEase);\r\n this._postProcessMove.animations.push(animationPP2);\r\n\r\n this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;\r\n this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;\r\n this._postProcessMove.samples = 4;\r\n this._webVRCamera.attachPostProcess(this._postProcessMove);\r\n this._scene.beginAnimation(this._postProcessMove, 0, 6, false, 1, () => {\r\n this._webVRCamera.detachPostProcess(this._postProcessMove);\r\n });\r\n this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);\r\n }\r\n\r\n private _moveTeleportationSelectorTo(hit: PickingInfo, gazer: VRExperienceHelperGazer, ray: Ray) {\r\n if (hit.pickedPoint) {\r\n if (gazer._teleportationRequestInitiated) {\r\n this._displayTeleportationTarget();\r\n this._haloCenter.copyFrom(hit.pickedPoint);\r\n this._teleportationTarget.position.copyFrom(hit.pickedPoint);\r\n }\r\n\r\n const pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(true, false), ray);\r\n if (pickNormal) {\r\n const axis1 = Vector3.Cross(Axis.Y, pickNormal);\r\n const axis2 = Vector3.Cross(pickNormal, axis1);\r\n Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, this._teleportationTarget.rotation);\r\n }\r\n this._teleportationTarget.position.y += 0.1;\r\n }\r\n }\r\n private _workingVector = Vector3.Zero();\r\n private _workingQuaternion = Quaternion.Identity();\r\n private _workingMatrix = Matrix.Identity();\r\n\r\n /**\r\n * Time Constant Teleportation Mode\r\n */\r\n public static readonly TELEPORTATIONMODE_CONSTANTTIME = 0;\r\n /**\r\n * Speed Constant Teleportation Mode\r\n */\r\n public static readonly TELEPORTATIONMODE_CONSTANTSPEED = 1;\r\n\r\n /**\r\n * Teleports the users feet to the desired location\r\n * @param location The location where the user's feet should be placed\r\n */\r\n public teleportCamera(location: Vector3) {\r\n if (!(this.currentVRCamera instanceof FreeCamera)) {\r\n return;\r\n }\r\n // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the\r\n // offset of the headset from the anchor.\r\n if (this.webVRCamera.leftCamera) {\r\n this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);\r\n this._workingVector.subtractInPlace(this.webVRCamera.position);\r\n location.subtractToRef(this._workingVector, this._workingVector);\r\n } else {\r\n this._workingVector.copyFrom(location);\r\n }\r\n // Add height to account for user's height offset\r\n if (this.isInVRMode) {\r\n this._workingVector.y += this.webVRCamera.deviceDistanceToRoomGround() * this._webVRCamera.deviceScaleFactor;\r\n } else {\r\n this._workingVector.y += this._defaultHeight;\r\n }\r\n\r\n this.onBeforeCameraTeleport.notifyObservers(this._workingVector);\r\n\r\n // Animations FPS\r\n const FPS = 90;\r\n let speedRatio, lastFrame;\r\n if (this._teleportationMode == VRExperienceHelper.TELEPORTATIONMODE_CONSTANTSPEED) {\r\n lastFrame = FPS;\r\n const dist = Vector3.Distance(this.currentVRCamera.position, this._workingVector);\r\n speedRatio = this._teleportationSpeed / dist;\r\n } else {\r\n // teleportationMode is TELEPORTATIONMODE_CONSTANTTIME\r\n lastFrame = Math.round((this._teleportationTime * FPS) / 1000);\r\n speedRatio = 1;\r\n }\r\n\r\n // Create animation from the camera's position to the new location\r\n this.currentVRCamera.animations = [];\r\n const animationCameraTeleportation = new Animation(\"animationCameraTeleportation\", \"position\", FPS, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n const animationCameraTeleportationKeys = [\r\n {\r\n frame: 0,\r\n value: this.currentVRCamera.position,\r\n },\r\n {\r\n frame: lastFrame,\r\n value: this._workingVector,\r\n },\r\n ];\r\n\r\n animationCameraTeleportation.setKeys(animationCameraTeleportationKeys);\r\n animationCameraTeleportation.setEasingFunction(this._teleportationEasing);\r\n this.currentVRCamera.animations.push(animationCameraTeleportation);\r\n\r\n this._postProcessMove.animations = [];\r\n\r\n // Calculate the mid frame for vignette animations\r\n const midFrame = Math.round(lastFrame / 2);\r\n\r\n const animationPP = new Animation(\"animationPP\", \"vignetteWeight\", FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n const vignetteWeightKeys = [];\r\n vignetteWeightKeys.push({\r\n frame: 0,\r\n value: 0,\r\n });\r\n vignetteWeightKeys.push({\r\n frame: midFrame,\r\n value: 8,\r\n });\r\n vignetteWeightKeys.push({\r\n frame: lastFrame,\r\n value: 0,\r\n });\r\n\r\n animationPP.setKeys(vignetteWeightKeys);\r\n this._postProcessMove.animations.push(animationPP);\r\n\r\n const animationPP2 = new Animation(\"animationPP2\", \"vignetteStretch\", FPS, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n const vignetteStretchKeys = [];\r\n vignetteStretchKeys.push({\r\n frame: 0,\r\n value: 0,\r\n });\r\n vignetteStretchKeys.push({\r\n frame: midFrame,\r\n value: 10,\r\n });\r\n vignetteStretchKeys.push({\r\n frame: lastFrame,\r\n value: 0,\r\n });\r\n\r\n animationPP2.setKeys(vignetteStretchKeys);\r\n this._postProcessMove.animations.push(animationPP2);\r\n\r\n this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;\r\n this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;\r\n\r\n this._webVRCamera.attachPostProcess(this._postProcessMove);\r\n this._scene.beginAnimation(this._postProcessMove, 0, lastFrame, false, speedRatio, () => {\r\n this._webVRCamera.detachPostProcess(this._postProcessMove);\r\n });\r\n this._scene.beginAnimation(this.currentVRCamera, 0, lastFrame, false, speedRatio, () => {\r\n this.onAfterCameraTeleport.notifyObservers(this._workingVector);\r\n });\r\n\r\n this._hideTeleportationTarget();\r\n }\r\n\r\n private _convertNormalToDirectionOfRay(normal: Nullable, ray: Ray) {\r\n if (normal) {\r\n const angle = Math.acos(Vector3.Dot(normal, ray.direction));\r\n if (angle < Math.PI / 2) {\r\n normal.scaleInPlace(-1);\r\n }\r\n }\r\n return normal;\r\n }\r\n\r\n private _castRayAndSelectObject(gazer: VRExperienceHelperGazer) {\r\n if (!(this.currentVRCamera instanceof FreeCamera)) {\r\n return;\r\n }\r\n\r\n const ray = gazer._getForwardRay(this._rayLength);\r\n const hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);\r\n\r\n if (hit) {\r\n this._scene.simulatePointerMove(hit, { pointerId: gazer._id });\r\n }\r\n gazer._currentHit = hit;\r\n\r\n // Moving the gazeTracker on the mesh face targetted\r\n if (hit && hit.pickedPoint) {\r\n if (this._displayGaze) {\r\n let multiplier = 1;\r\n\r\n gazer._gazeTracker.isVisible = true;\r\n\r\n if (gazer._isActionableMesh) {\r\n multiplier = 3;\r\n }\r\n if (this.updateGazeTrackerScale) {\r\n gazer._gazeTracker.scaling.x = hit.distance * multiplier;\r\n gazer._gazeTracker.scaling.y = hit.distance * multiplier;\r\n gazer._gazeTracker.scaling.z = hit.distance * multiplier;\r\n }\r\n\r\n const pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);\r\n // To avoid z-fighting\r\n const deltaFighting = 0.002;\r\n\r\n if (pickNormal) {\r\n const axis1 = Vector3.Cross(Axis.Y, pickNormal);\r\n const axis2 = Vector3.Cross(pickNormal, axis1);\r\n Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, gazer._gazeTracker.rotation);\r\n }\r\n gazer._gazeTracker.position.copyFrom(hit.pickedPoint);\r\n\r\n if (gazer._gazeTracker.position.x < 0) {\r\n gazer._gazeTracker.position.x += deltaFighting;\r\n } else {\r\n gazer._gazeTracker.position.x -= deltaFighting;\r\n }\r\n if (gazer._gazeTracker.position.y < 0) {\r\n gazer._gazeTracker.position.y += deltaFighting;\r\n } else {\r\n gazer._gazeTracker.position.y -= deltaFighting;\r\n }\r\n if (gazer._gazeTracker.position.z < 0) {\r\n gazer._gazeTracker.position.z += deltaFighting;\r\n } else {\r\n gazer._gazeTracker.position.z -= deltaFighting;\r\n }\r\n }\r\n\r\n // Changing the size of the laser pointer based on the distance from the targetted point\r\n gazer._updatePointerDistance(hit.distance);\r\n } else {\r\n gazer._updatePointerDistance();\r\n gazer._gazeTracker.isVisible = false;\r\n }\r\n\r\n if (hit && hit.pickedMesh) {\r\n // The object selected is the floor, we're in a teleportation scenario\r\n if (this._teleportationInitialized && this._isTeleportationFloor(hit.pickedMesh) && hit.pickedPoint) {\r\n // Moving the teleportation area to this targetted point\r\n\r\n //Raise onSelectedMeshUnselected observable if ray collided floor mesh/meshes and a non floor mesh was previously selected\r\n if (gazer._currentMeshSelected && !this._isTeleportationFloor(gazer._currentMeshSelected)) {\r\n this._notifySelectedMeshUnselected(gazer._currentMeshSelected);\r\n }\r\n\r\n gazer._currentMeshSelected = null;\r\n if (gazer._teleportationRequestInitiated) {\r\n this._moveTeleportationSelectorTo(hit, gazer, ray);\r\n }\r\n return;\r\n }\r\n // If not, we're in a selection scenario\r\n //this._teleportationAllowed = false;\r\n if (hit.pickedMesh !== gazer._currentMeshSelected) {\r\n if (this.meshSelectionPredicate(hit.pickedMesh)) {\r\n this.onNewMeshPicked.notifyObservers(hit);\r\n gazer._currentMeshSelected = hit.pickedMesh;\r\n if (hit.pickedMesh.isPickable && hit.pickedMesh.actionManager) {\r\n this.changeGazeColor(this._pickedGazeColor);\r\n this.changeLaserColor(this._pickedLaserColor);\r\n gazer._isActionableMesh = true;\r\n } else {\r\n this.changeGazeColor(this._gazeColor);\r\n this.changeLaserColor(this._laserColor);\r\n gazer._isActionableMesh = false;\r\n }\r\n try {\r\n this.onNewMeshSelected.notifyObservers(hit.pickedMesh);\r\n const gazerAsControllerGazer = gazer as VRExperienceHelperControllerGazer;\r\n if (gazerAsControllerGazer.webVRController) {\r\n this.onMeshSelectedWithController.notifyObservers({ mesh: hit.pickedMesh, controller: gazerAsControllerGazer.webVRController });\r\n }\r\n } catch (err) {\r\n Logger.Warn(\"Error while raising onNewMeshSelected or onMeshSelectedWithController: \" + err);\r\n }\r\n } else {\r\n this._notifySelectedMeshUnselected(gazer._currentMeshSelected);\r\n gazer._currentMeshSelected = null;\r\n this.changeGazeColor(this._gazeColor);\r\n this.changeLaserColor(this._laserColor);\r\n }\r\n }\r\n } else {\r\n this._notifySelectedMeshUnselected(gazer._currentMeshSelected);\r\n gazer._currentMeshSelected = null;\r\n //this._teleportationAllowed = false;\r\n this.changeGazeColor(this._gazeColor);\r\n this.changeLaserColor(this._laserColor);\r\n }\r\n }\r\n\r\n private _notifySelectedMeshUnselected(mesh: Nullable) {\r\n if (mesh) {\r\n this.onSelectedMeshUnselected.notifyObservers(mesh);\r\n }\r\n }\r\n\r\n /**\r\n * Permanently set new colors for the laser pointer\r\n * @param color the new laser color\r\n * @param pickedColor the new laser color when picked mesh detected\r\n */\r\n public setLaserColor(color: Color3, pickedColor: Color3 = this._pickedLaserColor) {\r\n this._laserColor = color;\r\n this._pickedLaserColor = pickedColor;\r\n }\r\n\r\n /**\r\n * Set lighting enabled / disabled on the laser pointer of both controllers\r\n * @param enabled should the lighting be enabled on the laser pointer\r\n */\r\n public setLaserLightingState(enabled: boolean = true) {\r\n if (this._leftController) {\r\n this._leftController._setLaserPointerLightingDisabled(!enabled);\r\n }\r\n if (this._rightController) {\r\n this._rightController._setLaserPointerLightingDisabled(!enabled);\r\n }\r\n }\r\n\r\n /**\r\n * Permanently set new colors for the gaze pointer\r\n * @param color the new gaze color\r\n * @param pickedColor the new gaze color when picked mesh detected\r\n */\r\n public setGazeColor(color: Color3, pickedColor: Color3 = this._pickedGazeColor) {\r\n this._gazeColor = color;\r\n this._pickedGazeColor = pickedColor;\r\n }\r\n\r\n /**\r\n * Sets the color of the laser ray from the vr controllers.\r\n * @param color new color for the ray.\r\n */\r\n public changeLaserColor(color: Color3) {\r\n if (!this.updateControllerLaserColor) {\r\n return;\r\n }\r\n\r\n if (this._leftController) {\r\n this._leftController._setLaserPointerColor(color);\r\n }\r\n if (this._rightController) {\r\n this._rightController._setLaserPointerColor(color);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the color of the ray from the vr headsets gaze.\r\n * @param color new color for the ray.\r\n */\r\n public changeGazeColor(color: Color3) {\r\n if (!this.updateGazeTrackerColor) {\r\n return;\r\n }\r\n if (!(this._cameraGazer._gazeTracker.material)) {\r\n return;\r\n }\r\n (this._cameraGazer._gazeTracker.material).emissiveColor = color;\r\n if (this._leftController) {\r\n (this._leftController._gazeTracker.material).emissiveColor = color;\r\n }\r\n if (this._rightController) {\r\n (this._rightController._gazeTracker.material).emissiveColor = color;\r\n }\r\n }\r\n\r\n /**\r\n * Exits VR and disposes of the vr experience helper\r\n */\r\n public dispose() {\r\n if (this.isInVRMode) {\r\n this.exitVR();\r\n }\r\n\r\n if (this._postProcessMove) {\r\n this._postProcessMove.dispose();\r\n }\r\n\r\n if (this._webVRCamera) {\r\n this._webVRCamera.dispose();\r\n }\r\n if (this._vrDeviceOrientationCamera) {\r\n this._vrDeviceOrientationCamera.dispose();\r\n }\r\n if (!this._useCustomVRButton && this._btnVR && this._btnVR.parentNode) {\r\n document.body.removeChild(this._btnVR);\r\n }\r\n\r\n if (this._deviceOrientationCamera && this._scene.activeCamera != this._deviceOrientationCamera) {\r\n this._deviceOrientationCamera.dispose();\r\n }\r\n\r\n if (this._cameraGazer) {\r\n this._cameraGazer.dispose();\r\n }\r\n if (this._leftController) {\r\n this._leftController.dispose();\r\n }\r\n if (this._rightController) {\r\n this._rightController.dispose();\r\n }\r\n\r\n if (this._teleportationTarget) {\r\n this._teleportationTarget.dispose();\r\n }\r\n\r\n if (this.xr) {\r\n this.xr.dispose();\r\n }\r\n\r\n this._floorMeshesCollection.length = 0;\r\n\r\n document.removeEventListener(\"keydown\", this._onKeyDown);\r\n window.removeEventListener(\"vrdisplaypresentchange\", this._onVrDisplayPresentChangeBind);\r\n\r\n window.removeEventListener(\"resize\", this._onResize);\r\n document.removeEventListener(\"fullscreenchange\", this._onFullscreenChange);\r\n\r\n this._scene.getEngine().onVRDisplayChangedObservable.removeCallback(this._onVRDisplayChangedBind);\r\n this._scene.getEngine().onVRRequestPresentStart.removeCallback(this._onVRRequestPresentStart);\r\n this._scene.getEngine().onVRRequestPresentComplete.removeCallback(this._onVRRequestPresentComplete);\r\n\r\n this._scene.gamepadManager.onGamepadConnectedObservable.removeCallback(this._onNewGamepadConnected);\r\n this._scene.gamepadManager.onGamepadDisconnectedObservable.removeCallback(this._onNewGamepadDisconnected);\r\n\r\n this._scene.unregisterBeforeRender(this._beforeRender);\r\n }\r\n\r\n /**\r\n * Gets the name of the VRExperienceHelper class\r\n * @returns \"VRExperienceHelper\"\r\n */\r\n public getClassName(): string {\r\n return \"VRExperienceHelper\";\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { SphericalPolynomial } from \"../Maths/sphericalPolynomial\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { CubeMapToSphericalPolynomialTools } from \"../Misc/HighDynamicRange/cubemapToSphericalPolynomial\";\r\nimport type { Scene } from \"../scene\";\r\nimport { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { FromHalfFloat, ToHalfFloat } from \"./textureTools\";\r\n\r\nimport \"../Engines/Extensions/engine.cubeTexture\";\r\n\r\n// Based on demo done by Brandon Jones - http://media.tojicode.com/webgl-samples/dds.html\r\n// All values and structures referenced from:\r\n// http://msdn.microsoft.com/en-us/library/bb943991.aspx/\r\nconst DDS_MAGIC = 0x20534444;\r\n\r\nconst //DDSD_CAPS = 0x1,\r\n //DDSD_HEIGHT = 0x2,\r\n //DDSD_WIDTH = 0x4,\r\n //DDSD_PITCH = 0x8,\r\n //DDSD_PIXELFORMAT = 0x1000,\r\n DDSD_MIPMAPCOUNT = 0x20000;\r\n//DDSD_LINEARSIZE = 0x80000,\r\n//DDSD_DEPTH = 0x800000;\r\n\r\n// var DDSCAPS_COMPLEX = 0x8,\r\n// DDSCAPS_MIPMAP = 0x400000,\r\n// DDSCAPS_TEXTURE = 0x1000;\r\n\r\nconst DDSCAPS2_CUBEMAP = 0x200;\r\n// DDSCAPS2_CUBEMAP_POSITIVEX = 0x400,\r\n// DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800,\r\n// DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000,\r\n// DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000,\r\n// DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000,\r\n// DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000,\r\n// DDSCAPS2_VOLUME = 0x200000;\r\n\r\nconst //DDPF_ALPHAPIXELS = 0x1,\r\n //DDPF_ALPHA = 0x2,\r\n DDPF_FOURCC = 0x4,\r\n DDPF_RGB = 0x40,\r\n //DDPF_YUV = 0x200,\r\n DDPF_LUMINANCE = 0x20000;\r\n\r\nfunction FourCCToInt32(value: string) {\r\n return value.charCodeAt(0) + (value.charCodeAt(1) << 8) + (value.charCodeAt(2) << 16) + (value.charCodeAt(3) << 24);\r\n}\r\n\r\nfunction Int32ToFourCC(value: number) {\r\n return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff);\r\n}\r\n\r\nconst FOURCC_DXT1 = FourCCToInt32(\"DXT1\");\r\nconst FOURCC_DXT3 = FourCCToInt32(\"DXT3\");\r\nconst FOURCC_DXT5 = FourCCToInt32(\"DXT5\");\r\nconst FOURCC_DX10 = FourCCToInt32(\"DX10\");\r\nconst FOURCC_D3DFMT_R16G16B16A16F = 113;\r\nconst FOURCC_D3DFMT_R32G32B32A32F = 116;\r\n\r\nconst DXGI_FORMAT_R32G32B32A32_FLOAT = 2;\r\nconst DXGI_FORMAT_R16G16B16A16_FLOAT = 10;\r\nconst DXGI_FORMAT_B8G8R8X8_UNORM = 88;\r\n\r\nconst headerLengthInt = 31; // The header length in 32 bit ints\r\n\r\n// Offsets into the header array\r\nconst off_magic = 0;\r\n\r\nconst off_size = 1;\r\nconst off_flags = 2;\r\nconst off_height = 3;\r\nconst off_width = 4;\r\n\r\nconst off_mipmapCount = 7;\r\n\r\nconst off_pfFlags = 20;\r\nconst off_pfFourCC = 21;\r\nconst off_RGBbpp = 22;\r\nconst off_RMask = 23;\r\nconst off_GMask = 24;\r\nconst off_BMask = 25;\r\nconst off_AMask = 26;\r\n// var off_caps1 = 27;\r\nconst off_caps2 = 28;\r\n// var off_caps3 = 29;\r\n// var off_caps4 = 30;\r\nconst off_dxgiFormat = 32;\r\n\r\n/**\r\n * Direct draw surface info\r\n * @see https://docs.microsoft.com/en-us/windows/desktop/direct3ddds/dx-graphics-dds-pguide\r\n */\r\nexport interface DDSInfo {\r\n /**\r\n * Width of the texture\r\n */\r\n width: number;\r\n /**\r\n * Width of the texture\r\n */\r\n height: number;\r\n /**\r\n * Number of Mipmaps for the texture\r\n * @see https://en.wikipedia.org/wiki/Mipmap\r\n */\r\n mipmapCount: number;\r\n /**\r\n * If the textures format is a known fourCC format\r\n * @see https://www.fourcc.org/\r\n */\r\n isFourCC: boolean;\r\n /**\r\n * If the texture is an RGB format eg. DXGI_FORMAT_B8G8R8X8_UNORM format\r\n */\r\n isRGB: boolean;\r\n /**\r\n * If the texture is a lumincance format\r\n */\r\n isLuminance: boolean;\r\n /**\r\n * If this is a cube texture\r\n * @see https://docs.microsoft.com/en-us/windows/desktop/direct3ddds/dds-file-layout-for-cubic-environment-maps\r\n */\r\n isCube: boolean;\r\n /**\r\n * If the texture is a compressed format eg. FOURCC_DXT1\r\n */\r\n isCompressed: boolean;\r\n /**\r\n * The dxgiFormat of the texture\r\n * @see https://docs.microsoft.com/en-us/windows/desktop/api/dxgiformat/ne-dxgiformat-dxgi_format\r\n */\r\n dxgiFormat: number;\r\n /**\r\n * Texture type eg. Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT\r\n */\r\n textureType: number;\r\n /**\r\n * Sphericle polynomial created for the dds texture\r\n */\r\n sphericalPolynomial?: SphericalPolynomial;\r\n}\r\n\r\n/**\r\n * Class used to provide DDS decompression tools\r\n */\r\nexport class DDSTools {\r\n /**\r\n * Gets or sets a boolean indicating that LOD info is stored in alpha channel (false by default)\r\n */\r\n public static StoreLODInAlphaChannel = false;\r\n\r\n /**\r\n * Gets DDS information from an array buffer\r\n * @param data defines the array buffer view to read data from\r\n * @returns the DDS information\r\n */\r\n public static GetDDSInfo(data: ArrayBufferView): DDSInfo {\r\n const header = new Int32Array(data.buffer, data.byteOffset, headerLengthInt);\r\n const extendedHeader = new Int32Array(data.buffer, data.byteOffset, headerLengthInt + 4);\r\n\r\n let mipmapCount = 1;\r\n if (header[off_flags] & DDSD_MIPMAPCOUNT) {\r\n mipmapCount = Math.max(1, header[off_mipmapCount]);\r\n }\r\n\r\n const fourCC = header[off_pfFourCC];\r\n const dxgiFormat = fourCC === FOURCC_DX10 ? extendedHeader[off_dxgiFormat] : 0;\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n\r\n switch (fourCC) {\r\n case FOURCC_D3DFMT_R16G16B16A16F:\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n break;\r\n case FOURCC_D3DFMT_R32G32B32A32F:\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n break;\r\n case FOURCC_DX10:\r\n if (dxgiFormat === DXGI_FORMAT_R16G16B16A16_FLOAT) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n break;\r\n }\r\n if (dxgiFormat === DXGI_FORMAT_R32G32B32A32_FLOAT) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n break;\r\n }\r\n }\r\n\r\n return {\r\n width: header[off_width],\r\n height: header[off_height],\r\n mipmapCount: mipmapCount,\r\n isFourCC: (header[off_pfFlags] & DDPF_FOURCC) === DDPF_FOURCC,\r\n isRGB: (header[off_pfFlags] & DDPF_RGB) === DDPF_RGB,\r\n isLuminance: (header[off_pfFlags] & DDPF_LUMINANCE) === DDPF_LUMINANCE,\r\n isCube: (header[off_caps2] & DDSCAPS2_CUBEMAP) === DDSCAPS2_CUBEMAP,\r\n isCompressed: fourCC === FOURCC_DXT1 || fourCC === FOURCC_DXT3 || fourCC === FOURCC_DXT5,\r\n dxgiFormat: dxgiFormat,\r\n textureType: textureType,\r\n };\r\n }\r\n\r\n private static _GetHalfFloatAsFloatRGBAArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number): Float32Array {\r\n const destArray = new Float32Array(dataLength);\r\n const srcData = new Uint16Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 4;\r\n destArray[index] = FromHalfFloat(srcData[srcPos]);\r\n destArray[index + 1] = FromHalfFloat(srcData[srcPos + 1]);\r\n destArray[index + 2] = FromHalfFloat(srcData[srcPos + 2]);\r\n if (DDSTools.StoreLODInAlphaChannel) {\r\n destArray[index + 3] = lod;\r\n } else {\r\n destArray[index + 3] = FromHalfFloat(srcData[srcPos + 3]);\r\n }\r\n index += 4;\r\n }\r\n }\r\n\r\n return destArray;\r\n }\r\n\r\n private static _GetHalfFloatRGBAArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number): Uint16Array {\r\n if (DDSTools.StoreLODInAlphaChannel) {\r\n const destArray = new Uint16Array(dataLength);\r\n const srcData = new Uint16Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 4;\r\n destArray[index] = srcData[srcPos];\r\n destArray[index + 1] = srcData[srcPos + 1];\r\n destArray[index + 2] = srcData[srcPos + 2];\r\n destArray[index + 3] = ToHalfFloat(lod);\r\n index += 4;\r\n }\r\n }\r\n\r\n return destArray;\r\n }\r\n\r\n return new Uint16Array(arrayBuffer, dataOffset, dataLength);\r\n }\r\n\r\n private static _GetFloatRGBAArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number): Float32Array {\r\n if (DDSTools.StoreLODInAlphaChannel) {\r\n const destArray = new Float32Array(dataLength);\r\n const srcData = new Float32Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 4;\r\n destArray[index] = srcData[srcPos];\r\n destArray[index + 1] = srcData[srcPos + 1];\r\n destArray[index + 2] = srcData[srcPos + 2];\r\n destArray[index + 3] = lod;\r\n index += 4;\r\n }\r\n }\r\n\r\n return destArray;\r\n }\r\n return new Float32Array(arrayBuffer, dataOffset, dataLength);\r\n }\r\n\r\n private static _GetFloatAsHalfFloatRGBAArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number): Uint16Array {\r\n const destArray = new Uint16Array(dataLength);\r\n const srcData = new Float32Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n destArray[index] = ToHalfFloat(srcData[index]);\r\n destArray[index + 1] = ToHalfFloat(srcData[index + 1]);\r\n destArray[index + 2] = ToHalfFloat(srcData[index + 2]);\r\n if (DDSTools.StoreLODInAlphaChannel) {\r\n destArray[index + 3] = ToHalfFloat(lod);\r\n } else {\r\n destArray[index + 3] = ToHalfFloat(srcData[index + 3]);\r\n }\r\n index += 4;\r\n }\r\n }\r\n\r\n return destArray;\r\n }\r\n\r\n private static _GetFloatAsUIntRGBAArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number): Uint8Array {\r\n const destArray = new Uint8Array(dataLength);\r\n const srcData = new Float32Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 4;\r\n destArray[index] = Scalar.Clamp(srcData[srcPos]) * 255;\r\n destArray[index + 1] = Scalar.Clamp(srcData[srcPos + 1]) * 255;\r\n destArray[index + 2] = Scalar.Clamp(srcData[srcPos + 2]) * 255;\r\n if (DDSTools.StoreLODInAlphaChannel) {\r\n destArray[index + 3] = lod;\r\n } else {\r\n destArray[index + 3] = Scalar.Clamp(srcData[srcPos + 3]) * 255;\r\n }\r\n index += 4;\r\n }\r\n }\r\n\r\n return destArray;\r\n }\r\n\r\n private static _GetHalfFloatAsUIntRGBAArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number): Uint8Array {\r\n const destArray = new Uint8Array(dataLength);\r\n const srcData = new Uint16Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 4;\r\n destArray[index] = Scalar.Clamp(FromHalfFloat(srcData[srcPos])) * 255;\r\n destArray[index + 1] = Scalar.Clamp(FromHalfFloat(srcData[srcPos + 1])) * 255;\r\n destArray[index + 2] = Scalar.Clamp(FromHalfFloat(srcData[srcPos + 2])) * 255;\r\n if (DDSTools.StoreLODInAlphaChannel) {\r\n destArray[index + 3] = lod;\r\n } else {\r\n destArray[index + 3] = Scalar.Clamp(FromHalfFloat(srcData[srcPos + 3])) * 255;\r\n }\r\n index += 4;\r\n }\r\n }\r\n\r\n return destArray;\r\n }\r\n\r\n private static _GetRGBAArrayBuffer(\r\n width: number,\r\n height: number,\r\n dataOffset: number,\r\n dataLength: number,\r\n arrayBuffer: ArrayBuffer,\r\n rOffset: number,\r\n gOffset: number,\r\n bOffset: number,\r\n aOffset: number\r\n ): Uint8Array {\r\n const byteArray = new Uint8Array(dataLength);\r\n const srcData = new Uint8Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 4;\r\n\r\n byteArray[index] = srcData[srcPos + rOffset];\r\n byteArray[index + 1] = srcData[srcPos + gOffset];\r\n byteArray[index + 2] = srcData[srcPos + bOffset];\r\n byteArray[index + 3] = srcData[srcPos + aOffset];\r\n index += 4;\r\n }\r\n }\r\n\r\n return byteArray;\r\n }\r\n\r\n private static _ExtractLongWordOrder(value: number): number {\r\n if (value === 0 || value === 255 || value === -16777216) {\r\n return 0;\r\n }\r\n\r\n return 1 + DDSTools._ExtractLongWordOrder(value >> 8);\r\n }\r\n\r\n private static _GetRGBArrayBuffer(\r\n width: number,\r\n height: number,\r\n dataOffset: number,\r\n dataLength: number,\r\n arrayBuffer: ArrayBuffer,\r\n rOffset: number,\r\n gOffset: number,\r\n bOffset: number\r\n ): Uint8Array {\r\n const byteArray = new Uint8Array(dataLength);\r\n const srcData = new Uint8Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = (x + y * width) * 3;\r\n\r\n byteArray[index] = srcData[srcPos + rOffset];\r\n byteArray[index + 1] = srcData[srcPos + gOffset];\r\n byteArray[index + 2] = srcData[srcPos + bOffset];\r\n index += 3;\r\n }\r\n }\r\n\r\n return byteArray;\r\n }\r\n\r\n private static _GetLuminanceArrayBuffer(width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer): Uint8Array {\r\n const byteArray = new Uint8Array(dataLength);\r\n const srcData = new Uint8Array(arrayBuffer, dataOffset);\r\n let index = 0;\r\n for (let y = 0; y < height; y++) {\r\n for (let x = 0; x < width; x++) {\r\n const srcPos = x + y * width;\r\n byteArray[index] = srcData[srcPos];\r\n index++;\r\n }\r\n }\r\n\r\n return byteArray;\r\n }\r\n\r\n /**\r\n * Uploads DDS Levels to a Babylon Texture\r\n * @internal\r\n */\r\n public static UploadDDSLevels(\r\n engine: ThinEngine,\r\n texture: InternalTexture,\r\n data: ArrayBufferView,\r\n info: DDSInfo,\r\n loadMipmaps: boolean,\r\n faces: number,\r\n lodIndex = -1,\r\n currentFace?: number,\r\n destTypeMustBeFilterable = true\r\n ) {\r\n let sphericalPolynomialFaces: Nullable> = null;\r\n if (info.sphericalPolynomial) {\r\n sphericalPolynomialFaces = new Array();\r\n }\r\n const ext = !!engine.getCaps().s3tc;\r\n\r\n // TODO WEBGPU Once generateMipMaps is split into generateMipMaps + hasMipMaps in InternalTexture this line can be removed\r\n texture.generateMipMaps = loadMipmaps;\r\n\r\n const header = new Int32Array(data.buffer, data.byteOffset, headerLengthInt);\r\n let fourCC: number,\r\n width: number,\r\n height: number,\r\n dataLength: number = 0,\r\n dataOffset: number;\r\n let byteArray: Uint8Array, mipmapCount: number, mip: number;\r\n let internalCompressedFormat = 0;\r\n let blockBytes = 1;\r\n\r\n if (header[off_magic] !== DDS_MAGIC) {\r\n Logger.Error(\"Invalid magic number in DDS header\");\r\n return;\r\n }\r\n\r\n if (!info.isFourCC && !info.isRGB && !info.isLuminance) {\r\n Logger.Error(\"Unsupported format, must contain a FourCC, RGB or LUMINANCE code\");\r\n return;\r\n }\r\n\r\n if (info.isCompressed && !ext) {\r\n Logger.Error(\"Compressed textures are not supported on this platform.\");\r\n return;\r\n }\r\n\r\n let bpp = header[off_RGBbpp];\r\n dataOffset = header[off_size] + 4;\r\n\r\n let computeFormats = false;\r\n\r\n if (info.isFourCC) {\r\n fourCC = header[off_pfFourCC];\r\n switch (fourCC) {\r\n case FOURCC_DXT1:\r\n blockBytes = 8;\r\n internalCompressedFormat = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1;\r\n break;\r\n case FOURCC_DXT3:\r\n blockBytes = 16;\r\n internalCompressedFormat = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3;\r\n break;\r\n case FOURCC_DXT5:\r\n blockBytes = 16;\r\n internalCompressedFormat = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5;\r\n break;\r\n case FOURCC_D3DFMT_R16G16B16A16F:\r\n computeFormats = true;\r\n bpp = 64;\r\n break;\r\n case FOURCC_D3DFMT_R32G32B32A32F:\r\n computeFormats = true;\r\n bpp = 128;\r\n break;\r\n case FOURCC_DX10: {\r\n // There is an additionnal header so dataOffset need to be changed\r\n dataOffset += 5 * 4; // 5 uints\r\n\r\n let supported = false;\r\n switch (info.dxgiFormat) {\r\n case DXGI_FORMAT_R16G16B16A16_FLOAT:\r\n computeFormats = true;\r\n bpp = 64;\r\n supported = true;\r\n break;\r\n case DXGI_FORMAT_R32G32B32A32_FLOAT:\r\n computeFormats = true;\r\n bpp = 128;\r\n supported = true;\r\n break;\r\n case DXGI_FORMAT_B8G8R8X8_UNORM:\r\n info.isRGB = true;\r\n info.isFourCC = false;\r\n bpp = 32;\r\n supported = true;\r\n break;\r\n }\r\n\r\n if (supported) {\r\n break;\r\n }\r\n }\r\n // eslint-disable-next-line no-fallthrough\r\n default:\r\n console.error(\"Unsupported FourCC code:\", Int32ToFourCC(fourCC));\r\n return;\r\n }\r\n }\r\n\r\n const rOffset = DDSTools._ExtractLongWordOrder(header[off_RMask]);\r\n const gOffset = DDSTools._ExtractLongWordOrder(header[off_GMask]);\r\n const bOffset = DDSTools._ExtractLongWordOrder(header[off_BMask]);\r\n const aOffset = DDSTools._ExtractLongWordOrder(header[off_AMask]);\r\n\r\n if (computeFormats) {\r\n internalCompressedFormat = engine._getRGBABufferInternalSizedFormat(info.textureType);\r\n }\r\n\r\n mipmapCount = 1;\r\n if (header[off_flags] & DDSD_MIPMAPCOUNT && loadMipmaps !== false) {\r\n mipmapCount = Math.max(1, header[off_mipmapCount]);\r\n }\r\n\r\n const startFace = currentFace || 0;\r\n const caps = engine.getCaps();\r\n for (let face = startFace; face < faces; face++) {\r\n width = header[off_width];\r\n height = header[off_height];\r\n\r\n for (mip = 0; mip < mipmapCount; ++mip) {\r\n if (lodIndex === -1 || lodIndex === mip) {\r\n // In case of fixed LOD, if the lod has just been uploaded, early exit.\r\n const i = lodIndex === -1 ? mip : 0;\r\n\r\n if (!info.isCompressed && info.isFourCC) {\r\n texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n dataLength = width * height * 4;\r\n let floatArray: Nullable = null;\r\n\r\n if (engine._badOS || engine._badDesktopOS || (!caps.textureHalfFloat && !caps.textureFloat)) {\r\n // Required because iOS has many issues with float and half float generation\r\n if (bpp === 128) {\r\n floatArray = DDSTools._GetFloatAsUIntRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i);\r\n if (sphericalPolynomialFaces && i == 0) {\r\n sphericalPolynomialFaces.push(DDSTools._GetFloatRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i));\r\n }\r\n } else if (bpp === 64) {\r\n floatArray = DDSTools._GetHalfFloatAsUIntRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i);\r\n if (sphericalPolynomialFaces && i == 0) {\r\n sphericalPolynomialFaces.push(\r\n DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i)\r\n );\r\n }\r\n }\r\n\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n } else {\r\n const floatAvailable = caps.textureFloat && ((destTypeMustBeFilterable && caps.textureFloatLinearFiltering) || !destTypeMustBeFilterable);\r\n const halfFloatAvailable = caps.textureHalfFloat && ((destTypeMustBeFilterable && caps.textureHalfFloatLinearFiltering) || !destTypeMustBeFilterable);\r\n\r\n const destType =\r\n (bpp === 128 || (bpp === 64 && !halfFloatAvailable)) && floatAvailable\r\n ? Constants.TEXTURETYPE_FLOAT\r\n : (bpp === 64 || (bpp === 128 && !floatAvailable)) && halfFloatAvailable\r\n ? Constants.TEXTURETYPE_HALF_FLOAT\r\n : Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n\r\n let dataGetter: (width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number) => ArrayBufferView;\r\n let dataGetterPolynomial: Nullable<\r\n (width: number, height: number, dataOffset: number, dataLength: number, arrayBuffer: ArrayBuffer, lod: number) => ArrayBufferView\r\n > = null;\r\n\r\n switch (bpp) {\r\n case 128: {\r\n switch (destType) {\r\n case Constants.TEXTURETYPE_FLOAT:\r\n dataGetter = DDSTools._GetFloatRGBAArrayBuffer;\r\n dataGetterPolynomial = null;\r\n break;\r\n case Constants.TEXTURETYPE_HALF_FLOAT:\r\n dataGetter = DDSTools._GetFloatAsHalfFloatRGBAArrayBuffer;\r\n dataGetterPolynomial = DDSTools._GetFloatRGBAArrayBuffer;\r\n break;\r\n case Constants.TEXTURETYPE_UNSIGNED_BYTE:\r\n dataGetter = DDSTools._GetFloatAsUIntRGBAArrayBuffer;\r\n dataGetterPolynomial = DDSTools._GetFloatRGBAArrayBuffer;\r\n break;\r\n }\r\n break;\r\n }\r\n default: {\r\n // 64 bpp\r\n switch (destType) {\r\n case Constants.TEXTURETYPE_FLOAT:\r\n dataGetter = DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer;\r\n dataGetterPolynomial = null;\r\n break;\r\n case Constants.TEXTURETYPE_HALF_FLOAT:\r\n dataGetter = DDSTools._GetHalfFloatRGBAArrayBuffer;\r\n dataGetterPolynomial = DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer;\r\n break;\r\n case Constants.TEXTURETYPE_UNSIGNED_BYTE:\r\n dataGetter = DDSTools._GetHalfFloatAsUIntRGBAArrayBuffer;\r\n dataGetterPolynomial = DDSTools._GetHalfFloatAsFloatRGBAArrayBuffer;\r\n break;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n texture.type = destType;\r\n\r\n floatArray = dataGetter(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i);\r\n\r\n if (sphericalPolynomialFaces && i == 0) {\r\n sphericalPolynomialFaces.push(\r\n dataGetterPolynomial ? dataGetterPolynomial(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, i) : floatArray\r\n );\r\n }\r\n }\r\n\r\n if (floatArray) {\r\n engine._uploadDataToTextureDirectly(texture, floatArray, face, i);\r\n }\r\n } else if (info.isRGB) {\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n if (bpp === 24) {\r\n texture.format = Constants.TEXTUREFORMAT_RGB;\r\n dataLength = width * height * 3;\r\n byteArray = DDSTools._GetRGBArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, rOffset, gOffset, bOffset);\r\n engine._uploadDataToTextureDirectly(texture, byteArray, face, i);\r\n } else {\r\n // 32\r\n texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n dataLength = width * height * 4;\r\n byteArray = DDSTools._GetRGBAArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer, rOffset, gOffset, bOffset, aOffset);\r\n engine._uploadDataToTextureDirectly(texture, byteArray, face, i);\r\n }\r\n } else if (info.isLuminance) {\r\n const unpackAlignment = engine._getUnpackAlignement();\r\n const unpaddedRowSize = width;\r\n const paddedRowSize = Math.floor((width + unpackAlignment - 1) / unpackAlignment) * unpackAlignment;\r\n dataLength = paddedRowSize * (height - 1) + unpaddedRowSize;\r\n\r\n byteArray = DDSTools._GetLuminanceArrayBuffer(width, height, data.byteOffset + dataOffset, dataLength, data.buffer);\r\n texture.format = Constants.TEXTUREFORMAT_LUMINANCE;\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n\r\n engine._uploadDataToTextureDirectly(texture, byteArray, face, i);\r\n } else {\r\n dataLength = (((Math.max(4, width) / 4) * Math.max(4, height)) / 4) * blockBytes;\r\n byteArray = new Uint8Array(data.buffer, data.byteOffset + dataOffset, dataLength);\r\n\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n engine._uploadCompressedDataToTextureDirectly(texture, internalCompressedFormat, width, height, byteArray, face, i);\r\n }\r\n }\r\n dataOffset += bpp ? width * height * (bpp / 8) : dataLength;\r\n width *= 0.5;\r\n height *= 0.5;\r\n\r\n width = Math.max(1.0, width);\r\n height = Math.max(1.0, height);\r\n }\r\n\r\n if (currentFace !== undefined) {\r\n // Loading a single face\r\n break;\r\n }\r\n }\r\n if (sphericalPolynomialFaces && sphericalPolynomialFaces.length > 0) {\r\n info.sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial({\r\n size: header[off_width],\r\n right: sphericalPolynomialFaces[0],\r\n left: sphericalPolynomialFaces[1],\r\n up: sphericalPolynomialFaces[2],\r\n down: sphericalPolynomialFaces[3],\r\n front: sphericalPolynomialFaces[4],\r\n back: sphericalPolynomialFaces[5],\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n gammaSpace: false,\r\n });\r\n } else {\r\n info.sphericalPolynomial = undefined;\r\n }\r\n }\r\n}\r\n\r\ndeclare module \"../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)\r\n * @param rootUrl defines the url where the file to load is located\r\n * @param scene defines the current scene\r\n * @param lodScale defines scale to apply to the mip map selection\r\n * @param lodOffset defines offset to apply to the mip map selection\r\n * @param onLoad defines an optional callback raised when the texture is loaded\r\n * @param onError defines an optional callback raised if there is an issue to load the texture\r\n * @param format defines the format of the data\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n * @param createPolynomials defines wheter or not to create polynomails harmonics for the texture\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createPrefilteredCubeTexture(\r\n rootUrl: string,\r\n scene: Nullable,\r\n lodScale: number,\r\n lodOffset: number,\r\n onLoad?: Nullable<(internalTexture: Nullable) => void>,\r\n onError?: Nullable<(message?: string, exception?: any) => void>,\r\n format?: number,\r\n forcedExtension?: any,\r\n createPolynomials?: boolean\r\n ): InternalTexture;\r\n }\r\n}\r\n\r\n/**\r\n * Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)\r\n * @param rootUrl defines the url where the file to load is located\r\n * @param scene defines the current scene\r\n * @param lodScale defines scale to apply to the mip map selection\r\n * @param lodOffset defines offset to apply to the mip map selection\r\n * @param onLoad defines an optional callback raised when the texture is loaded\r\n * @param onError defines an optional callback raised if there is an issue to load the texture\r\n * @param format defines the format of the data\r\n * @param forcedExtension defines the extension to use to pick the right loader\r\n * @param createPolynomials defines wheter or not to create polynomails harmonics for the texture\r\n * @returns the cube texture as an InternalTexture\r\n */\r\nThinEngine.prototype.createPrefilteredCubeTexture = function (\r\n rootUrl: string,\r\n scene: Nullable,\r\n lodScale: number,\r\n lodOffset: number,\r\n onLoad: Nullable<(internalTexture: Nullable) => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n format?: number,\r\n forcedExtension: any = null,\r\n createPolynomials: boolean = true\r\n): InternalTexture {\r\n const callback = (loadData: any) => {\r\n if (!loadData) {\r\n if (onLoad) {\r\n onLoad(null);\r\n }\r\n return;\r\n }\r\n\r\n const texture = loadData.texture as InternalTexture;\r\n if (!createPolynomials) {\r\n texture._sphericalPolynomial = new SphericalPolynomial();\r\n } else if (loadData.info.sphericalPolynomial) {\r\n texture._sphericalPolynomial = loadData.info.sphericalPolynomial;\r\n }\r\n texture._source = InternalTextureSource.CubePrefiltered;\r\n\r\n if (this.getCaps().textureLOD) {\r\n // Do not add extra process if texture lod is supported.\r\n if (onLoad) {\r\n onLoad(texture);\r\n }\r\n return;\r\n }\r\n\r\n const mipSlices = 3;\r\n\r\n const gl = this._gl;\r\n const width = loadData.width;\r\n if (!width) {\r\n return;\r\n }\r\n\r\n const textures: BaseTexture[] = [];\r\n for (let i = 0; i < mipSlices; i++) {\r\n //compute LOD from even spacing in smoothness (matching shader calculation)\r\n const smoothness = i / (mipSlices - 1);\r\n const roughness = 1 - smoothness;\r\n\r\n const minLODIndex = lodOffset; // roughness = 0\r\n const maxLODIndex = Scalar.Log2(width) * lodScale + lodOffset; // roughness = 1\r\n\r\n const lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;\r\n const mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));\r\n\r\n const glTextureFromLod = new InternalTexture(this, InternalTextureSource.Temp);\r\n glTextureFromLod.type = texture.type;\r\n glTextureFromLod.format = texture.format;\r\n glTextureFromLod.width = Math.pow(2, Math.max(Scalar.Log2(width) - mipmapIndex, 0));\r\n glTextureFromLod.height = glTextureFromLod.width;\r\n glTextureFromLod.isCube = true;\r\n glTextureFromLod._cachedWrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n glTextureFromLod._cachedWrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod, true);\r\n\r\n glTextureFromLod.samplingMode = Constants.TEXTURE_LINEAR_LINEAR;\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n\r\n if (loadData.isDDS) {\r\n const info: DDSInfo = loadData.info;\r\n const data: any = loadData.data;\r\n this._unpackFlipY(info.isCompressed);\r\n\r\n DDSTools.UploadDDSLevels(this, glTextureFromLod, data, info, true, 6, mipmapIndex);\r\n } else {\r\n Logger.Warn(\"DDS is the only prefiltered cube map supported so far.\");\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n\r\n // Wrap in a base texture for easy binding.\r\n const lodTexture = new BaseTexture(scene);\r\n lodTexture._isCube = true;\r\n lodTexture._texture = glTextureFromLod;\r\n\r\n glTextureFromLod.isReady = true;\r\n textures.push(lodTexture);\r\n }\r\n\r\n texture._lodTextureHigh = textures[2];\r\n texture._lodTextureMid = textures[1];\r\n texture._lodTextureLow = textures[0];\r\n\r\n if (onLoad) {\r\n onLoad(texture);\r\n }\r\n };\r\n\r\n return this.createCubeTexture(rootUrl, scene, null, false, callback, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset);\r\n};\r\n","import type { Nullable } from \"../../../types\";\r\nimport { SphericalPolynomial } from \"../../../Maths/sphericalPolynomial\";\r\nimport { Engine } from \"../../../Engines/engine\";\r\nimport type { InternalTexture } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IInternalTextureLoader } from \"../../../Materials/Textures/internalTextureLoader\";\r\nimport type { DDSInfo } from \"../../../Misc/dds\";\r\nimport { DDSTools } from \"../../../Misc/dds\";\r\n\r\n/**\r\n * Implementation of the DDS Texture Loader.\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _DDSTextureLoader implements IInternalTextureLoader {\r\n /**\r\n * Defines whether the loader supports cascade loading the different faces.\r\n */\r\n public readonly supportCascades = true;\r\n\r\n /**\r\n * This returns if the loader support the current file information.\r\n * @param extension defines the file extension of the file being loaded\r\n * @returns true if the loader can load the specified file\r\n */\r\n public canLoad(extension: string): boolean {\r\n return extension.endsWith(\".dds\");\r\n }\r\n\r\n /**\r\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\r\n * @param imgs contains the cube maps\r\n * @param texture defines the BabylonJS internal texture\r\n * @param createPolynomials will be true if polynomials have been requested\r\n * @param onLoad defines the callback to trigger once the texture is ready\r\n */\r\n public loadCubeData(imgs: ArrayBufferView | ArrayBufferView[], texture: InternalTexture, createPolynomials: boolean, onLoad: Nullable<(data?: any) => void>): void {\r\n const engine = texture.getEngine() as Engine;\r\n let info: DDSInfo | undefined;\r\n let loadMipmap: boolean = false;\r\n let maxLevel: number = 1000;\r\n if (Array.isArray(imgs)) {\r\n for (let index = 0; index < imgs.length; index++) {\r\n const data = imgs[index];\r\n info = DDSTools.GetDDSInfo(data);\r\n\r\n texture.width = info.width;\r\n texture.height = info.height;\r\n\r\n loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && texture.generateMipMaps;\r\n\r\n engine._unpackFlipY(info.isCompressed);\r\n\r\n DDSTools.UploadDDSLevels(engine, texture, data, info, loadMipmap, 6, -1, index);\r\n\r\n if (!info.isFourCC && info.mipmapCount === 1) {\r\n engine.generateMipMapsForCubemap(texture);\r\n } else {\r\n maxLevel = info.mipmapCount - 1;\r\n }\r\n }\r\n } else {\r\n const data = imgs;\r\n info = DDSTools.GetDDSInfo(data);\r\n\r\n texture.width = info.width;\r\n texture.height = info.height;\r\n\r\n if (createPolynomials) {\r\n info.sphericalPolynomial = new SphericalPolynomial();\r\n }\r\n\r\n loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && texture.generateMipMaps;\r\n engine._unpackFlipY(info.isCompressed);\r\n\r\n DDSTools.UploadDDSLevels(engine, texture, data, info, loadMipmap, 6);\r\n\r\n if (!info.isFourCC && info.mipmapCount === 1) {\r\n // Do not unbind as we still need to set the parameters.\r\n engine.generateMipMapsForCubemap(texture, false);\r\n } else {\r\n maxLevel = info.mipmapCount - 1;\r\n }\r\n }\r\n engine._setCubeMapTextureParams(texture, loadMipmap, maxLevel);\r\n texture.isReady = true;\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n\r\n if (onLoad) {\r\n onLoad({ isDDS: true, width: texture.width, info, data: imgs, texture });\r\n }\r\n }\r\n\r\n /**\r\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param callback defines the method to call once ready to upload\r\n */\r\n public loadData(\r\n data: ArrayBufferView,\r\n texture: InternalTexture,\r\n callback: (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void) => void\r\n ): void {\r\n const info = DDSTools.GetDDSInfo(data);\r\n\r\n const loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && texture.generateMipMaps && info.width >> (info.mipmapCount - 1) === 1;\r\n callback(info.width, info.height, loadMipmap, info.isFourCC, () => {\r\n DDSTools.UploadDDSLevels(texture.getEngine(), texture, data, info, loadMipmap, 1);\r\n });\r\n }\r\n}\r\n\r\n// Register the loader.\r\nEngine._TextureLoaders.push(new _DDSTextureLoader());\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/helperFunctions\";\n\nconst name = \"rgbdEncodePixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{gl_FragColor=toRGBD(texture2D(textureSampler,vUV).rgb);}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const rgbdEncodePixelShader = { name, shader };\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../types\";\r\nimport { Tools } from \"./tools\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { SphericalPolynomial } from \"../Maths/sphericalPolynomial\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { RGBDTextureTools } from \"./rgbdTextureTools\";\r\nimport type { RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\n\r\nimport \"../Engines/Extensions/engine.renderTargetCube\";\r\nimport \"../Engines/Extensions/engine.readTexture\";\r\nimport \"../Materials/Textures/baseTexture.polynomial\";\r\n\r\nimport \"../Shaders/rgbdEncode.fragment\";\r\nimport \"../Shaders/rgbdDecode.fragment\";\r\nimport { DumpTools } from \"../Misc/dumpTools\";\r\n\r\nconst DefaultEnvironmentTextureImageType = \"image/png\";\r\nconst CurrentVersion = 2;\r\n\r\n/**\r\n * Raw texture data and descriptor sufficient for WebGL texture upload\r\n */\r\nexport type EnvironmentTextureInfo = EnvironmentTextureInfoV1 | EnvironmentTextureInfoV2;\r\n\r\n/**\r\n * v1 of EnvironmentTextureInfo\r\n */\r\ninterface EnvironmentTextureInfoV1 {\r\n /**\r\n * Version of the environment map\r\n */\r\n version: 1;\r\n\r\n /**\r\n * Width of image\r\n */\r\n width: number;\r\n\r\n /**\r\n * Irradiance information stored in the file.\r\n */\r\n irradiance: any;\r\n\r\n /**\r\n * Specular information stored in the file.\r\n */\r\n specular: any;\r\n}\r\n\r\n/**\r\n * v2 of EnvironmentTextureInfo\r\n */\r\ninterface EnvironmentTextureInfoV2 {\r\n /**\r\n * Version of the environment map\r\n */\r\n version: 2;\r\n\r\n /**\r\n * Width of image\r\n */\r\n width: number;\r\n\r\n /**\r\n * Irradiance information stored in the file.\r\n */\r\n irradiance: any;\r\n\r\n /**\r\n * Specular information stored in the file.\r\n */\r\n specular: any;\r\n\r\n /**\r\n * The mime type used to encode the image data.\r\n */\r\n imageType: string;\r\n}\r\n\r\n/**\r\n * Defines One Image in the file. It requires only the position in the file\r\n * as well as the length.\r\n */\r\ninterface BufferImageData {\r\n /**\r\n * Length of the image data.\r\n */\r\n length: number;\r\n /**\r\n * Position of the data from the null terminator delimiting the end of the JSON.\r\n */\r\n position: number;\r\n}\r\n\r\n/**\r\n * Defines the specular data enclosed in the file.\r\n * This corresponds to the version 1 of the data.\r\n */\r\nexport interface EnvironmentTextureSpecularInfoV1 {\r\n /**\r\n * Defines where the specular Payload is located. It is a runtime value only not stored in the file.\r\n */\r\n specularDataPosition?: number;\r\n /**\r\n * This contains all the images data needed to reconstruct the cubemap.\r\n */\r\n mipmaps: Array;\r\n /**\r\n * Defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness.\r\n */\r\n lodGenerationScale: number;\r\n}\r\n\r\n/**\r\n * Defines the required storage to save the environment irradiance information.\r\n */\r\ninterface EnvironmentTextureIrradianceInfoV1 {\r\n x: Array;\r\n y: Array;\r\n z: Array;\r\n\r\n xx: Array;\r\n yy: Array;\r\n zz: Array;\r\n\r\n yz: Array;\r\n zx: Array;\r\n xy: Array;\r\n}\r\n\r\n/**\r\n * Options for creating environment textures\r\n */\r\nexport interface CreateEnvTextureOptions {\r\n /**\r\n * The mime type of encoded images.\r\n */\r\n imageType?: string;\r\n\r\n /**\r\n * the image quality of encoded WebP images.\r\n */\r\n imageQuality?: number;\r\n}\r\n\r\n/**\r\n * Magic number identifying the env file.\r\n */\r\nconst MagicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];\r\n\r\n/**\r\n * Gets the environment info from an env file.\r\n * @param data The array buffer containing the .env bytes.\r\n * @returns the environment file info (the json header) if successfully parsed, normalized to the latest supported version.\r\n */\r\nexport function GetEnvInfo(data: ArrayBufferView): Nullable {\r\n const dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);\r\n let pos = 0;\r\n\r\n for (let i = 0; i < MagicBytes.length; i++) {\r\n if (dataView.getUint8(pos++) !== MagicBytes[i]) {\r\n Logger.Error(\"Not a babylon environment map\");\r\n return null;\r\n }\r\n }\r\n\r\n // Read json manifest - collect characters up to null terminator\r\n let manifestString = \"\";\r\n let charCode = 0x00;\r\n while ((charCode = dataView.getUint8(pos++))) {\r\n manifestString += String.fromCharCode(charCode);\r\n }\r\n\r\n let manifest: EnvironmentTextureInfo = JSON.parse(manifestString);\r\n manifest = normalizeEnvInfo(manifest);\r\n if (manifest.specular) {\r\n // Extend the header with the position of the payload.\r\n manifest.specular.specularDataPosition = pos;\r\n // Fallback to 0.8 exactly if lodGenerationScale is not defined for backward compatibility.\r\n manifest.specular.lodGenerationScale = manifest.specular.lodGenerationScale || 0.8;\r\n }\r\n\r\n return manifest;\r\n}\r\n\r\n/**\r\n * Normalizes any supported version of the environment file info to the latest version\r\n * @param info environment file info on any supported version\r\n * @returns environment file info in the latest supported version\r\n * @private\r\n */\r\nexport function normalizeEnvInfo(info: EnvironmentTextureInfo): EnvironmentTextureInfoV2 {\r\n if (info.version > CurrentVersion) {\r\n throw new Error(`Unsupported babylon environment map version \"${info.version}\". Latest supported version is \"${CurrentVersion}\".`);\r\n }\r\n\r\n if (info.version === 2) {\r\n return info;\r\n }\r\n\r\n // Migrate a v1 info to v2\r\n info = { ...info, version: 2, imageType: DefaultEnvironmentTextureImageType };\r\n\r\n return info;\r\n}\r\n\r\n/**\r\n * Creates an environment texture from a loaded cube texture.\r\n * @param texture defines the cube texture to convert in env file\r\n * @param options options for the conversion process\r\n * @param options.imageType the mime type for the encoded images, with support for \"image/png\" (default) and \"image/webp\"\r\n * @param options.imageQuality the image quality of encoded WebP images.\r\n * @returns a promise containing the environment data if successful.\r\n */\r\nexport async function CreateEnvTextureAsync(texture: BaseTexture, options: CreateEnvTextureOptions = {}): Promise {\r\n const internalTexture = texture.getInternalTexture();\r\n if (!internalTexture) {\r\n return Promise.reject(\"The cube texture is invalid.\");\r\n }\r\n\r\n const imageType = options.imageType ?? DefaultEnvironmentTextureImageType;\r\n\r\n const engine = internalTexture.getEngine() as Engine;\r\n\r\n if (\r\n texture.textureType !== Constants.TEXTURETYPE_HALF_FLOAT &&\r\n texture.textureType !== Constants.TEXTURETYPE_FLOAT &&\r\n texture.textureType !== Constants.TEXTURETYPE_UNSIGNED_BYTE &&\r\n texture.textureType !== Constants.TEXTURETYPE_UNSIGNED_INT &&\r\n texture.textureType !== Constants.TEXTURETYPE_UNSIGNED_INTEGER &&\r\n texture.textureType !== -1\r\n ) {\r\n return Promise.reject(\"The cube texture should allow HDR (Full Float or Half Float).\");\r\n }\r\n\r\n let textureType = Constants.TEXTURETYPE_FLOAT;\r\n if (!engine.getCaps().textureFloatRender) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n if (!engine.getCaps().textureHalfFloatRender) {\r\n return Promise.reject(\"Env texture can only be created when the browser supports half float or full float rendering.\");\r\n }\r\n }\r\n\r\n // sphericalPolynomial is lazy loaded so simply accessing it should trigger the computation.\r\n texture.sphericalPolynomial;\r\n\r\n // Lets keep track of the polynomial promise so we can wait for it to be ready before generating the pixels.\r\n const sphericalPolynomialPromise = texture.getInternalTexture()?._sphericalPolynomialPromise;\r\n\r\n const cubeWidth = internalTexture.width;\r\n const hostingScene = new Scene(engine);\r\n const specularTextures: { [key: number]: ArrayBuffer } = {};\r\n\r\n // As we are going to readPixels the faces of the cube, make sure the drawing/update commands for the cube texture are fully sent to the GPU in case it is drawn for the first time in this very frame!\r\n engine.flushFramebuffer();\r\n\r\n // Read and collect all mipmaps data from the cube.\r\n const mipmapsCount = Scalar.ILog2(internalTexture.width);\r\n for (let i = 0; i <= mipmapsCount; i++) {\r\n const faceWidth = Math.pow(2, mipmapsCount - i);\r\n\r\n // All faces of the cube.\r\n for (let face = 0; face < 6; face++) {\r\n let faceData = await texture.readPixels(face, i, undefined, false);\r\n if (faceData && faceData.byteLength === (faceData as Uint8Array).length) {\r\n const faceDataFloat = new Float32Array(faceData!.byteLength * 4);\r\n for (let i = 0; i < faceData.byteLength; i++) {\r\n faceDataFloat[i] = (faceData as Uint8Array)[i] / 255;\r\n // Gamma to linear\r\n faceDataFloat[i] = Math.pow(faceDataFloat[i], 2.2);\r\n }\r\n faceData = faceDataFloat;\r\n } else if (faceData && texture.gammaSpace) {\r\n const floatData = faceData as Float32Array;\r\n for (let i = 0; i < floatData.length; i++) {\r\n // Gamma to linear\r\n floatData[i] = Math.pow(floatData[i], 2.2);\r\n }\r\n }\r\n\r\n const tempTexture = engine.createRawTexture(\r\n faceData,\r\n faceWidth,\r\n faceWidth,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n false,\r\n true,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n null,\r\n textureType\r\n );\r\n\r\n await RGBDTextureTools.EncodeTextureToRGBD(tempTexture, hostingScene, textureType);\r\n\r\n const rgbdEncodedData = await engine._readTexturePixels(tempTexture, faceWidth, faceWidth);\r\n\r\n const imageEncodedData = await DumpTools.DumpDataAsync(faceWidth, faceWidth, rgbdEncodedData, imageType, undefined, false, true, options.imageQuality);\r\n\r\n specularTextures[i * 6 + face] = imageEncodedData as ArrayBuffer;\r\n\r\n tempTexture.dispose();\r\n }\r\n }\r\n\r\n // We can delete the hosting scene keeping track of all the creation objects\r\n hostingScene.dispose();\r\n\r\n // Ensure completion of the polynomial creation promise.\r\n if (sphericalPolynomialPromise) {\r\n await sphericalPolynomialPromise;\r\n }\r\n\r\n // Creates the json header for the env texture\r\n const info: EnvironmentTextureInfo = {\r\n version: CurrentVersion,\r\n width: cubeWidth,\r\n imageType,\r\n irradiance: _CreateEnvTextureIrradiance(texture),\r\n specular: {\r\n mipmaps: [],\r\n lodGenerationScale: texture.lodGenerationScale,\r\n },\r\n };\r\n\r\n // Sets the specular image data information\r\n let position = 0;\r\n for (let i = 0; i <= mipmapsCount; i++) {\r\n for (let face = 0; face < 6; face++) {\r\n const byteLength = specularTextures[i * 6 + face].byteLength;\r\n info.specular.mipmaps.push({\r\n length: byteLength,\r\n position: position,\r\n });\r\n position += byteLength;\r\n }\r\n }\r\n\r\n // Encode the JSON as an array buffer\r\n const infoString = JSON.stringify(info);\r\n const infoBuffer = new ArrayBuffer(infoString.length + 1);\r\n const infoView = new Uint8Array(infoBuffer); // Limited to ascii subset matching unicode.\r\n for (let i = 0, strLen = infoString.length; i < strLen; i++) {\r\n infoView[i] = infoString.charCodeAt(i);\r\n }\r\n // Ends up with a null terminator for easier parsing\r\n infoView[infoString.length] = 0x00;\r\n\r\n // Computes the final required size and creates the storage\r\n const totalSize = MagicBytes.length + position + infoBuffer.byteLength;\r\n const finalBuffer = new ArrayBuffer(totalSize);\r\n const finalBufferView = new Uint8Array(finalBuffer);\r\n const dataView = new DataView(finalBuffer);\r\n\r\n // Copy the magic bytes identifying the file in\r\n let pos = 0;\r\n for (let i = 0; i < MagicBytes.length; i++) {\r\n dataView.setUint8(pos++, MagicBytes[i]);\r\n }\r\n\r\n // Add the json info\r\n finalBufferView.set(new Uint8Array(infoBuffer), pos);\r\n pos += infoBuffer.byteLength;\r\n\r\n // Finally inserts the texture data\r\n for (let i = 0; i <= mipmapsCount; i++) {\r\n for (let face = 0; face < 6; face++) {\r\n const dataBuffer = specularTextures[i * 6 + face];\r\n finalBufferView.set(new Uint8Array(dataBuffer), pos);\r\n pos += dataBuffer.byteLength;\r\n }\r\n }\r\n\r\n // Voila\r\n return finalBuffer;\r\n}\r\n\r\n/**\r\n * Creates a JSON representation of the spherical data.\r\n * @param texture defines the texture containing the polynomials\r\n * @returns the JSON representation of the spherical info\r\n */\r\nfunction _CreateEnvTextureIrradiance(texture: BaseTexture): Nullable {\r\n const polynmials = texture.sphericalPolynomial;\r\n if (polynmials == null) {\r\n return null;\r\n }\r\n\r\n return {\r\n x: [polynmials.x.x, polynmials.x.y, polynmials.x.z],\r\n y: [polynmials.y.x, polynmials.y.y, polynmials.y.z],\r\n z: [polynmials.z.x, polynmials.z.y, polynmials.z.z],\r\n\r\n xx: [polynmials.xx.x, polynmials.xx.y, polynmials.xx.z],\r\n yy: [polynmials.yy.x, polynmials.yy.y, polynmials.yy.z],\r\n zz: [polynmials.zz.x, polynmials.zz.y, polynmials.zz.z],\r\n\r\n yz: [polynmials.yz.x, polynmials.yz.y, polynmials.yz.z],\r\n zx: [polynmials.zx.x, polynmials.zx.y, polynmials.zx.z],\r\n xy: [polynmials.xy.x, polynmials.xy.y, polynmials.xy.z],\r\n } as any;\r\n}\r\n\r\n/**\r\n * Creates the ArrayBufferViews used for initializing environment texture image data.\r\n * @param data the image data\r\n * @param info parameters that determine what views will be created for accessing the underlying buffer\r\n * @returns the views described by info providing access to the underlying buffer\r\n */\r\nexport function CreateImageDataArrayBufferViews(data: ArrayBufferView, info: EnvironmentTextureInfo): Array> {\r\n info = normalizeEnvInfo(info);\r\n\r\n const specularInfo = info.specular as EnvironmentTextureSpecularInfoV1;\r\n\r\n // Double checks the enclosed info\r\n let mipmapsCount = Scalar.Log2(info.width);\r\n mipmapsCount = Math.round(mipmapsCount) + 1;\r\n if (specularInfo.mipmaps.length !== 6 * mipmapsCount) {\r\n throw new Error(`Unsupported specular mipmaps number \"${specularInfo.mipmaps.length}\"`);\r\n }\r\n\r\n const imageData = new Array>(mipmapsCount);\r\n for (let i = 0; i < mipmapsCount; i++) {\r\n imageData[i] = new Array(6);\r\n for (let face = 0; face < 6; face++) {\r\n const imageInfo = specularInfo.mipmaps[i * 6 + face];\r\n imageData[i][face] = new Uint8Array(data.buffer, data.byteOffset + specularInfo.specularDataPosition! + imageInfo.position, imageInfo.length);\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * Uploads the texture info contained in the env file to the GPU.\r\n * @param texture defines the internal texture to upload to\r\n * @param data defines the data to load\r\n * @param info defines the texture info retrieved through the GetEnvInfo method\r\n * @returns a promise\r\n */\r\nexport function UploadEnvLevelsAsync(texture: InternalTexture, data: ArrayBufferView, info: EnvironmentTextureInfo): Promise {\r\n info = normalizeEnvInfo(info);\r\n\r\n const specularInfo = info.specular as EnvironmentTextureSpecularInfoV1;\r\n if (!specularInfo) {\r\n // Nothing else parsed so far\r\n return Promise.resolve();\r\n }\r\n\r\n texture._lodGenerationScale = specularInfo.lodGenerationScale;\r\n\r\n const imageData = CreateImageDataArrayBufferViews(data, info);\r\n\r\n return UploadLevelsAsync(texture, imageData, info.imageType);\r\n}\r\n\r\nfunction _OnImageReadyAsync(\r\n image: HTMLImageElement | ImageBitmap,\r\n engine: Engine,\r\n expandTexture: boolean,\r\n rgbdPostProcess: Nullable,\r\n url: string,\r\n face: number,\r\n i: number,\r\n generateNonLODTextures: boolean,\r\n lodTextures: Nullable<{ [lod: number]: BaseTexture }>,\r\n cubeRtt: Nullable,\r\n texture: InternalTexture\r\n): Promise {\r\n return new Promise((resolve, reject) => {\r\n if (expandTexture) {\r\n const tempTexture = engine.createTexture(\r\n null,\r\n true,\r\n true,\r\n null,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n null,\r\n (message) => {\r\n reject(message);\r\n },\r\n image\r\n );\r\n\r\n rgbdPostProcess!.getEffect().executeWhenCompiled(() => {\r\n // Uncompress the data to a RTT\r\n rgbdPostProcess!.externalTextureSamplerBinding = true;\r\n rgbdPostProcess!.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", tempTexture);\r\n effect.setFloat2(\"scale\", 1, engine._features.needsInvertingBitmap && image instanceof ImageBitmap ? -1 : 1);\r\n };\r\n\r\n if (!engine.scenes.length) {\r\n return;\r\n }\r\n\r\n engine.scenes[0].postProcessManager.directRender([rgbdPostProcess!], cubeRtt, true, face, i);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n tempTexture.dispose();\r\n URL.revokeObjectURL(url);\r\n resolve();\r\n });\r\n } else {\r\n engine._uploadImageToTexture(texture, image, face, i);\r\n\r\n // Upload the face to the non lod texture support\r\n if (generateNonLODTextures) {\r\n const lodTexture = lodTextures![i];\r\n if (lodTexture) {\r\n engine._uploadImageToTexture(lodTexture._texture!, image, face, 0);\r\n }\r\n }\r\n resolve();\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Uploads the levels of image data to the GPU.\r\n * @param texture defines the internal texture to upload to\r\n * @param imageData defines the array buffer views of image data [mipmap][face]\r\n * @param imageType the mime type of the image data\r\n * @returns a promise\r\n */\r\nexport function UploadLevelsAsync(texture: InternalTexture, imageData: ArrayBufferView[][], imageType: string = DefaultEnvironmentTextureImageType): Promise {\r\n if (!Tools.IsExponentOfTwo(texture.width)) {\r\n throw new Error(\"Texture size must be a power of two\");\r\n }\r\n\r\n const mipmapsCount = Scalar.ILog2(texture.width) + 1;\r\n\r\n // Gets everything ready.\r\n const engine = texture.getEngine() as Engine;\r\n let expandTexture = false;\r\n let generateNonLODTextures = false;\r\n let rgbdPostProcess: Nullable = null;\r\n let cubeRtt: Nullable = null;\r\n let lodTextures: Nullable<{ [lod: number]: BaseTexture }> = null;\r\n const caps = engine.getCaps();\r\n\r\n texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n texture.generateMipMaps = true;\r\n texture._cachedAnisotropicFilteringLevel = null;\r\n engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, texture);\r\n\r\n // Add extra process if texture lod is not supported\r\n if (!caps.textureLOD) {\r\n expandTexture = false;\r\n generateNonLODTextures = true;\r\n lodTextures = {};\r\n }\r\n // in webgl 1 there are no ways to either render or copy lod level information for float textures.\r\n else if (!engine._features.supportRenderAndCopyToLodForFloatTextures) {\r\n expandTexture = false;\r\n }\r\n // If half float available we can uncompress the texture\r\n else if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\r\n expandTexture = true;\r\n texture.type = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n // If full float available we can uncompress the texture\r\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\r\n expandTexture = true;\r\n texture.type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n // Expand the texture if possible\r\n if (expandTexture) {\r\n // Simply run through the decode PP\r\n rgbdPostProcess = new PostProcess(\r\n \"rgbdDecode\",\r\n \"rgbdDecode\",\r\n null,\r\n null,\r\n 1,\r\n null,\r\n Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n undefined,\r\n texture.type,\r\n undefined,\r\n null,\r\n false\r\n );\r\n\r\n texture._isRGBD = false;\r\n texture.invertY = false;\r\n cubeRtt = engine.createRenderTargetCubeTexture(texture.width, {\r\n generateDepthBuffer: false,\r\n generateMipMaps: true,\r\n generateStencilBuffer: false,\r\n samplingMode: Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n type: texture.type,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n });\r\n } else {\r\n texture._isRGBD = true;\r\n texture.invertY = true;\r\n\r\n // In case of missing support, applies the same patch than DDS files.\r\n if (generateNonLODTextures) {\r\n const mipSlices = 3;\r\n const scale = texture._lodGenerationScale;\r\n const offset = texture._lodGenerationOffset;\r\n\r\n for (let i = 0; i < mipSlices; i++) {\r\n //compute LOD from even spacing in smoothness (matching shader calculation)\r\n const smoothness = i / (mipSlices - 1);\r\n const roughness = 1 - smoothness;\r\n\r\n const minLODIndex = offset; // roughness = 0\r\n const maxLODIndex = (mipmapsCount - 1) * scale + offset; // roughness = 1 (mipmaps start from 0)\r\n\r\n const lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;\r\n const mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));\r\n\r\n const glTextureFromLod = new InternalTexture(engine, InternalTextureSource.Temp);\r\n glTextureFromLod.isCube = true;\r\n glTextureFromLod.invertY = true;\r\n glTextureFromLod.generateMipMaps = false;\r\n engine.updateTextureSamplingMode(Constants.TEXTURE_LINEAR_LINEAR, glTextureFromLod);\r\n\r\n // Wrap in a base texture for easy binding.\r\n const lodTexture = new BaseTexture(null);\r\n lodTexture._isCube = true;\r\n lodTexture._texture = glTextureFromLod;\r\n lodTextures![mipmapIndex] = lodTexture;\r\n\r\n switch (i) {\r\n case 0:\r\n texture._lodTextureLow = lodTexture;\r\n break;\r\n case 1:\r\n texture._lodTextureMid = lodTexture;\r\n break;\r\n case 2:\r\n texture._lodTextureHigh = lodTexture;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n const promises: Promise[] = [];\r\n // All mipmaps up to provided number of images\r\n for (let i = 0; i < imageData.length; i++) {\r\n // All faces\r\n for (let face = 0; face < 6; face++) {\r\n // Constructs an image element from image data\r\n const bytes = imageData[i][face];\r\n const blob = new Blob([bytes], { type: imageType });\r\n const url = URL.createObjectURL(blob);\r\n let promise: Promise;\r\n\r\n if (typeof Image === \"undefined\" || engine._features.forceBitmapOverHTMLImageElement) {\r\n promise = engine.createImageBitmap(blob, { premultiplyAlpha: \"none\" }).then((img) => {\r\n return _OnImageReadyAsync(img, engine, expandTexture, rgbdPostProcess, url, face, i, generateNonLODTextures, lodTextures, cubeRtt, texture);\r\n });\r\n } else {\r\n const image = new Image();\r\n image.src = url;\r\n\r\n // Enqueue promise to upload to the texture.\r\n promise = new Promise((resolve, reject) => {\r\n image.onload = () => {\r\n _OnImageReadyAsync(image, engine, expandTexture, rgbdPostProcess, url, face, i, generateNonLODTextures, lodTextures, cubeRtt, texture)\r\n .then(() => resolve())\r\n .catch((reason) => {\r\n reject(reason);\r\n });\r\n };\r\n image.onerror = (error) => {\r\n reject(error);\r\n };\r\n });\r\n }\r\n promises.push(promise);\r\n }\r\n }\r\n\r\n // Fill remaining mipmaps with black textures.\r\n if (imageData.length < mipmapsCount) {\r\n let data: ArrayBufferView;\r\n const size = Math.pow(2, mipmapsCount - 1 - imageData.length);\r\n const dataLength = size * size * 4;\r\n switch (texture.type) {\r\n case Constants.TEXTURETYPE_UNSIGNED_INT: {\r\n data = new Uint8Array(dataLength);\r\n break;\r\n }\r\n case Constants.TEXTURETYPE_HALF_FLOAT: {\r\n data = new Uint16Array(dataLength);\r\n break;\r\n }\r\n case Constants.TEXTURETYPE_FLOAT: {\r\n data = new Float32Array(dataLength);\r\n break;\r\n }\r\n }\r\n for (let i = imageData.length; i < mipmapsCount; i++) {\r\n for (let face = 0; face < 6; face++) {\r\n engine._uploadArrayBufferViewToTexture(texture, data!, face, i);\r\n }\r\n }\r\n }\r\n\r\n // Once all done, finishes the cleanup and return\r\n return Promise.all(promises).then(() => {\r\n // Release temp RTT.\r\n if (cubeRtt) {\r\n engine._releaseTexture(texture);\r\n cubeRtt._swapAndDie(texture);\r\n }\r\n // Release temp Post Process.\r\n if (rgbdPostProcess) {\r\n rgbdPostProcess.dispose();\r\n }\r\n // Flag internal texture as ready in case they are in use.\r\n if (generateNonLODTextures) {\r\n if (texture._lodTextureHigh && texture._lodTextureHigh._texture) {\r\n texture._lodTextureHigh._texture.isReady = true;\r\n }\r\n if (texture._lodTextureMid && texture._lodTextureMid._texture) {\r\n texture._lodTextureMid._texture.isReady = true;\r\n }\r\n if (texture._lodTextureLow && texture._lodTextureLow._texture) {\r\n texture._lodTextureLow._texture.isReady = true;\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Uploads spherical polynomials information to the texture.\r\n * @param texture defines the texture we are trying to upload the information to\r\n * @param info defines the environment texture info retrieved through the GetEnvInfo method\r\n */\r\nexport function UploadEnvSpherical(texture: InternalTexture, info: EnvironmentTextureInfo): void {\r\n info = normalizeEnvInfo(info);\r\n\r\n const irradianceInfo = info.irradiance as EnvironmentTextureIrradianceInfoV1;\r\n if (!irradianceInfo) {\r\n return;\r\n }\r\n\r\n const sp = new SphericalPolynomial();\r\n Vector3.FromArrayToRef(irradianceInfo.x, 0, sp.x);\r\n Vector3.FromArrayToRef(irradianceInfo.y, 0, sp.y);\r\n Vector3.FromArrayToRef(irradianceInfo.z, 0, sp.z);\r\n Vector3.FromArrayToRef(irradianceInfo.xx, 0, sp.xx);\r\n Vector3.FromArrayToRef(irradianceInfo.yy, 0, sp.yy);\r\n Vector3.FromArrayToRef(irradianceInfo.zz, 0, sp.zz);\r\n Vector3.FromArrayToRef(irradianceInfo.yz, 0, sp.yz);\r\n Vector3.FromArrayToRef(irradianceInfo.zx, 0, sp.zx);\r\n Vector3.FromArrayToRef(irradianceInfo.xy, 0, sp.xy);\r\n texture._sphericalPolynomial = sp;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _UpdateRGBDAsync(\r\n internalTexture: InternalTexture,\r\n data: ArrayBufferView[][],\r\n sphericalPolynomial: Nullable,\r\n lodScale: number,\r\n lodOffset: number\r\n): Promise {\r\n const proxy = internalTexture\r\n .getEngine()\r\n .createRawCubeTexture(\r\n null,\r\n internalTexture.width,\r\n internalTexture.format,\r\n internalTexture.type,\r\n internalTexture.generateMipMaps,\r\n internalTexture.invertY,\r\n internalTexture.samplingMode,\r\n internalTexture._compression\r\n );\r\n const proxyPromise = UploadLevelsAsync(proxy, data).then(() => internalTexture);\r\n internalTexture.onRebuildCallback = (_internalTexture) => {\r\n return {\r\n proxy: proxyPromise,\r\n isReady: true,\r\n isAsync: true,\r\n };\r\n };\r\n internalTexture._source = InternalTextureSource.CubeRawRGBD;\r\n internalTexture._bufferViewArrayArray = data;\r\n internalTexture._lodGenerationScale = lodScale;\r\n internalTexture._lodGenerationOffset = lodOffset;\r\n internalTexture._sphericalPolynomial = sphericalPolynomial;\r\n\r\n return UploadLevelsAsync(internalTexture, data).then(() => {\r\n internalTexture.isReady = true;\r\n return internalTexture;\r\n });\r\n}\r\n\r\n/**\r\n * Sets of helpers addressing the serialization and deserialization of environment texture\r\n * stored in a BabylonJS env file.\r\n * Those files are usually stored as .env files.\r\n */\r\nexport const EnvironmentTextureTools = {\r\n /**\r\n * Gets the environment info from an env file.\r\n * @param data The array buffer containing the .env bytes.\r\n * @returns the environment file info (the json header) if successfully parsed, normalized to the latest supported version.\r\n */\r\n GetEnvInfo,\r\n\r\n /**\r\n * Creates an environment texture from a loaded cube texture.\r\n * @param texture defines the cube texture to convert in env file\r\n * @param options options for the conversion process\r\n * @param options.imageType the mime type for the encoded images, with support for \"image/png\" (default) and \"image/webp\"\r\n * @param options.imageQuality the image quality of encoded WebP images.\r\n * @returns a promise containing the environment data if successful.\r\n */\r\n CreateEnvTextureAsync,\r\n\r\n /**\r\n * Creates the ArrayBufferViews used for initializing environment texture image data.\r\n * @param data the image data\r\n * @param info parameters that determine what views will be created for accessing the underlying buffer\r\n * @returns the views described by info providing access to the underlying buffer\r\n */\r\n CreateImageDataArrayBufferViews,\r\n\r\n /**\r\n * Uploads the texture info contained in the env file to the GPU.\r\n * @param texture defines the internal texture to upload to\r\n * @param data defines the data to load\r\n * @param info defines the texture info retrieved through the GetEnvInfo method\r\n * @returns a promise\r\n */\r\n UploadEnvLevelsAsync,\r\n\r\n /**\r\n * Uploads the levels of image data to the GPU.\r\n * @param texture defines the internal texture to upload to\r\n * @param imageData defines the array buffer views of image data [mipmap][face]\r\n * @param imageType the mime type of the image data\r\n * @returns a promise\r\n */\r\n UploadLevelsAsync,\r\n\r\n /**\r\n * Uploads spherical polynomials information to the texture.\r\n * @param texture defines the texture we are trying to upload the information to\r\n * @param info defines the environment texture info retrieved through the GetEnvInfo method\r\n */\r\n UploadEnvSpherical,\r\n};\r\n","import { GetEnvInfo, UploadEnvLevelsAsync, UploadEnvSpherical } from \"../../../Misc/environmentTextureTools\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { Engine } from \"../../../Engines/engine\";\r\nimport type { InternalTexture } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IInternalTextureLoader } from \"../../../Materials/Textures/internalTextureLoader\";\r\n\r\n/**\r\n * Implementation of the ENV Texture Loader.\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _ENVTextureLoader implements IInternalTextureLoader {\r\n /**\r\n * Defines whether the loader supports cascade loading the different faces.\r\n */\r\n public readonly supportCascades = false;\r\n\r\n /**\r\n * This returns if the loader support the current file information.\r\n * @param extension defines the file extension of the file being loaded\r\n * @returns true if the loader can load the specified file\r\n */\r\n public canLoad(extension: string): boolean {\r\n return extension.endsWith(\".env\");\r\n }\r\n\r\n /**\r\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param createPolynomials will be true if polynomials have been requested\r\n * @param onLoad defines the callback to trigger once the texture is ready\r\n * @param onError defines the callback to trigger in case of error\r\n */\r\n public loadCubeData(\r\n data: ArrayBufferView | ArrayBufferView[],\r\n texture: InternalTexture,\r\n createPolynomials: boolean,\r\n onLoad: Nullable<(data?: any) => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>\r\n ): void {\r\n if (Array.isArray(data)) {\r\n return;\r\n }\r\n\r\n const info = GetEnvInfo(data);\r\n if (info) {\r\n texture.width = info.width;\r\n texture.height = info.width;\r\n\r\n try {\r\n UploadEnvSpherical(texture, info);\r\n UploadEnvLevelsAsync(texture, data, info).then(\r\n () => {\r\n texture.isReady = true;\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n },\r\n (reason) => {\r\n onError?.(\"Can not upload environment levels\", reason);\r\n }\r\n );\r\n } catch (e) {\r\n onError?.(\"Can not upload environment file\", e);\r\n }\r\n } else if (onError) {\r\n onError(\"Can not parse the environment file\", null);\r\n }\r\n }\r\n\r\n /**\r\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\r\n */\r\n public loadData(): void {\r\n throw \".env not supported in 2d.\";\r\n }\r\n}\r\n\r\n// Register the loader.\r\nEngine._TextureLoaders.push(new _ENVTextureLoader());\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\n\r\n/**\r\n * for description see https://www.khronos.org/opengles/sdk/tools/KTX/\r\n * for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/\r\n */\r\nexport class KhronosTextureContainer {\r\n private static HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)\r\n\r\n // load types\r\n private static COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()\r\n private static COMPRESSED_3D = 1; // uses a gl.compressedTexImage3D()\r\n private static TEX_2D = 2; // uses a gl.texImage2D()\r\n private static TEX_3D = 3; // uses a gl.texImage3D()\r\n\r\n // elements of the header\r\n /**\r\n * Gets the openGL type\r\n */\r\n public glType: number;\r\n /**\r\n * Gets the openGL type size\r\n */\r\n public glTypeSize: number;\r\n /**\r\n * Gets the openGL format\r\n */\r\n public glFormat: number;\r\n /**\r\n * Gets the openGL internal format\r\n */\r\n public glInternalFormat: number;\r\n /**\r\n * Gets the base internal format\r\n */\r\n public glBaseInternalFormat: number;\r\n /**\r\n * Gets image width in pixel\r\n */\r\n public pixelWidth: number;\r\n /**\r\n * Gets image height in pixel\r\n */\r\n public pixelHeight: number;\r\n /**\r\n * Gets image depth in pixels\r\n */\r\n public pixelDepth: number;\r\n /**\r\n * Gets the number of array elements\r\n */\r\n public numberOfArrayElements: number;\r\n /**\r\n * Gets the number of faces\r\n */\r\n public numberOfFaces: number;\r\n /**\r\n * Gets the number of mipmap levels\r\n */\r\n public numberOfMipmapLevels: number;\r\n /**\r\n * Gets the bytes of key value data\r\n */\r\n public bytesOfKeyValueData: number;\r\n /**\r\n * Gets the load type\r\n */\r\n public loadType: number;\r\n /**\r\n * If the container has been made invalid (eg. constructor failed to correctly load array buffer)\r\n */\r\n public isInvalid = false;\r\n\r\n /**\r\n * Creates a new KhronosTextureContainer\r\n * @param data contents of the KTX container file\r\n * @param facesExpected should be either 1 or 6, based whether a cube texture or or\r\n */\r\n public constructor(\r\n /** contents of the KTX container file */\r\n public data: ArrayBufferView,\r\n facesExpected: number\r\n ) {\r\n if (!KhronosTextureContainer.IsValid(data)) {\r\n this.isInvalid = true;\r\n Logger.Error(\"texture missing KTX identifier\");\r\n return;\r\n }\r\n\r\n // load the reset of the header in native 32 bit uint\r\n const dataSize = Uint32Array.BYTES_PER_ELEMENT;\r\n const headerDataView = new DataView(this.data.buffer, this.data.byteOffset + 12, 13 * dataSize);\r\n const endianness = headerDataView.getUint32(0, true);\r\n const littleEndian = endianness === 0x04030201;\r\n\r\n this.glType = headerDataView.getUint32(1 * dataSize, littleEndian); // must be 0 for compressed textures\r\n this.glTypeSize = headerDataView.getUint32(2 * dataSize, littleEndian); // must be 1 for compressed textures\r\n this.glFormat = headerDataView.getUint32(3 * dataSize, littleEndian); // must be 0 for compressed textures\r\n this.glInternalFormat = headerDataView.getUint32(4 * dataSize, littleEndian); // the value of arg passed to gl.compressedTexImage2D(,,x,,,,)\r\n this.glBaseInternalFormat = headerDataView.getUint32(5 * dataSize, littleEndian); // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only)\r\n this.pixelWidth = headerDataView.getUint32(6 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,)\r\n this.pixelHeight = headerDataView.getUint32(7 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,)\r\n this.pixelDepth = headerDataView.getUint32(8 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,)\r\n this.numberOfArrayElements = headerDataView.getUint32(9 * dataSize, littleEndian); // used for texture arrays\r\n this.numberOfFaces = headerDataView.getUint32(10 * dataSize, littleEndian); // used for cubemap textures, should either be 1 or 6\r\n this.numberOfMipmapLevels = headerDataView.getUint32(11 * dataSize, littleEndian); // number of levels; disregard possibility of 0 for compressed textures\r\n this.bytesOfKeyValueData = headerDataView.getUint32(12 * dataSize, littleEndian); // the amount of space after the header for meta-data\r\n\r\n // Make sure we have a compressed type. Not only reduces work, but probably better to let dev know they are not compressing.\r\n if (this.glType !== 0) {\r\n Logger.Error(\"only compressed formats currently supported\");\r\n this.isInvalid = true;\r\n return;\r\n } else {\r\n // value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.\r\n this.numberOfMipmapLevels = Math.max(1, this.numberOfMipmapLevels);\r\n }\r\n\r\n if (this.pixelHeight === 0 || this.pixelDepth !== 0) {\r\n Logger.Error(\"only 2D textures currently supported\");\r\n this.isInvalid = true;\r\n return;\r\n }\r\n\r\n if (this.numberOfArrayElements !== 0) {\r\n Logger.Error(\"texture arrays not currently supported\");\r\n this.isInvalid = true;\r\n return;\r\n }\r\n\r\n if (this.numberOfFaces !== facesExpected) {\r\n Logger.Error(\"number of faces expected\" + facesExpected + \", but found \" + this.numberOfFaces);\r\n this.isInvalid = true;\r\n return;\r\n }\r\n\r\n // we now have a completely validated file, so could use existence of loadType as success\r\n // would need to make this more elaborate & adjust checks above to support more than one load type\r\n this.loadType = KhronosTextureContainer.COMPRESSED_2D;\r\n }\r\n\r\n /**\r\n * Uploads KTX content to a Babylon Texture.\r\n * It is assumed that the texture has already been created & is currently bound\r\n * @internal\r\n */\r\n public uploadLevels(texture: InternalTexture, loadMipmaps: boolean): void {\r\n switch (this.loadType) {\r\n case KhronosTextureContainer.COMPRESSED_2D:\r\n this._upload2DCompressedLevels(texture, loadMipmaps);\r\n break;\r\n\r\n case KhronosTextureContainer.TEX_2D:\r\n case KhronosTextureContainer.COMPRESSED_3D:\r\n case KhronosTextureContainer.TEX_3D:\r\n }\r\n }\r\n\r\n private _upload2DCompressedLevels(texture: InternalTexture, loadMipmaps: boolean): void {\r\n // initialize width & height for level 1\r\n let dataOffset = KhronosTextureContainer.HEADER_LEN + this.bytesOfKeyValueData;\r\n let width = this.pixelWidth;\r\n let height = this.pixelHeight;\r\n\r\n const mipmapCount = loadMipmaps ? this.numberOfMipmapLevels : 1;\r\n for (let level = 0; level < mipmapCount; level++) {\r\n const imageSize = new Int32Array(this.data.buffer, this.data.byteOffset + dataOffset, 1)[0]; // size per face, since not supporting array cubemaps\r\n dataOffset += 4; //image data starts from next multiple of 4 offset. Each face refers to same imagesize field above.\r\n for (let face = 0; face < this.numberOfFaces; face++) {\r\n const byteArray = new Uint8Array(this.data.buffer, this.data.byteOffset + dataOffset, imageSize);\r\n\r\n const engine = texture.getEngine();\r\n engine._uploadCompressedDataToTextureDirectly(texture, texture.format, width, height, byteArray, face, level);\r\n\r\n dataOffset += imageSize; // add size of the image for the next face/mipmap\r\n dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image\r\n }\r\n width = Math.max(1.0, width * 0.5);\r\n height = Math.max(1.0, height * 0.5);\r\n }\r\n }\r\n\r\n /**\r\n * Checks if the given data starts with a KTX file identifier.\r\n * @param data the data to check\r\n * @returns true if the data is a KTX file or false otherwise\r\n */\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '1', '1', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x31 &&\r\n identifier[6] === 0x31 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n","import type { IDisposable } from \"../scene\";\r\n\r\n/** @ignore */\r\ninterface WorkerInfo {\r\n workerPromise: Promise;\r\n idle: boolean;\r\n timeoutId?: ReturnType;\r\n}\r\n\r\n/**\r\n * Helper class to push actions to a pool of workers.\r\n */\r\nexport class WorkerPool implements IDisposable {\r\n protected _workerInfos: Array;\r\n protected _pendingActions = new Array<(worker: Worker, onComplete: () => void) => void>();\r\n\r\n /**\r\n * Constructor\r\n * @param workers Array of workers to use for actions\r\n */\r\n constructor(workers: Array) {\r\n this._workerInfos = workers.map((worker) => ({\r\n workerPromise: Promise.resolve(worker),\r\n idle: true,\r\n }));\r\n }\r\n\r\n /**\r\n * Terminates all workers and clears any pending actions.\r\n */\r\n public dispose(): void {\r\n for (const workerInfo of this._workerInfos) {\r\n workerInfo.workerPromise.then((worker) => {\r\n worker.terminate();\r\n });\r\n }\r\n\r\n this._workerInfos.length = 0;\r\n this._pendingActions.length = 0;\r\n }\r\n\r\n /**\r\n * Pushes an action to the worker pool. If all the workers are active, the action will be\r\n * pended until a worker has completed its action.\r\n * @param action The action to perform. Call onComplete when the action is complete.\r\n */\r\n public push(action: (worker: Worker, onComplete: () => void) => void): void {\r\n if (!this._executeOnIdleWorker(action)) {\r\n this._pendingActions.push(action);\r\n }\r\n }\r\n\r\n protected _executeOnIdleWorker(action: (worker: Worker, onComplete: () => void) => void): boolean {\r\n for (const workerInfo of this._workerInfos) {\r\n if (workerInfo.idle) {\r\n this._execute(workerInfo, action);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n protected _execute(workerInfo: WorkerInfo, action: (worker: Worker, onComplete: () => void) => void): void {\r\n workerInfo.idle = false;\r\n workerInfo.workerPromise.then((worker) => {\r\n action(worker, () => {\r\n const nextAction = this._pendingActions.shift();\r\n if (nextAction) {\r\n this._execute(workerInfo, nextAction);\r\n } else {\r\n workerInfo.idle = true;\r\n }\r\n });\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Options for AutoReleaseWorkerPool\r\n */\r\nexport interface AutoReleaseWorkerPoolOptions {\r\n /**\r\n * Idle time elapsed before workers are terminated.\r\n */\r\n idleTimeElapsedBeforeRelease: number;\r\n}\r\n\r\n/**\r\n * Similar to the WorkerPool class except it creates and destroys workers automatically with a maximum of `maxWorkers` workers.\r\n * Workers are terminated when it is idle for at least `idleTimeElapsedBeforeRelease` milliseconds.\r\n */\r\nexport class AutoReleaseWorkerPool extends WorkerPool {\r\n /**\r\n * Default options for the constructor.\r\n * Override to change the defaults.\r\n */\r\n public static DefaultOptions: AutoReleaseWorkerPoolOptions = {\r\n idleTimeElapsedBeforeRelease: 1000,\r\n };\r\n\r\n private readonly _maxWorkers: number;\r\n private readonly _createWorkerAsync: () => Promise;\r\n private readonly _options: AutoReleaseWorkerPoolOptions;\r\n\r\n constructor(maxWorkers: number, createWorkerAsync: () => Promise, options = AutoReleaseWorkerPool.DefaultOptions) {\r\n super([]);\r\n\r\n this._maxWorkers = maxWorkers;\r\n this._createWorkerAsync = createWorkerAsync;\r\n this._options = options;\r\n }\r\n\r\n public push(action: (worker: Worker, onComplete: () => void) => void): void {\r\n if (!this._executeOnIdleWorker(action)) {\r\n if (this._workerInfos.length < this._maxWorkers) {\r\n const workerInfo: WorkerInfo = {\r\n workerPromise: this._createWorkerAsync(),\r\n idle: false,\r\n };\r\n this._workerInfos.push(workerInfo);\r\n this._execute(workerInfo, action);\r\n } else {\r\n this._pendingActions.push(action);\r\n }\r\n }\r\n }\r\n\r\n protected _execute(workerInfo: WorkerInfo, action: (worker: Worker, onComplete: () => void) => void): void {\r\n // Reset the idle timeout.\r\n if (workerInfo.timeoutId) {\r\n clearTimeout(workerInfo.timeoutId);\r\n delete workerInfo.timeoutId;\r\n }\r\n\r\n super._execute(workerInfo, (worker, onComplete) => {\r\n action(worker, () => {\r\n onComplete();\r\n\r\n if (workerInfo.idle) {\r\n // Schedule the worker to be terminated after the elapsed time.\r\n workerInfo.timeoutId = setTimeout(() => {\r\n workerInfo.workerPromise.then((worker) => {\r\n worker.terminate();\r\n });\r\n\r\n const indexOf = this._workerInfos.indexOf(workerInfo);\r\n if (indexOf !== -1) {\r\n this._workerInfos.splice(indexOf, 1);\r\n }\r\n }, this._options.idleTimeElapsedBeforeRelease);\r\n }\r\n });\r\n });\r\n }\r\n}\r\n","export enum SourceTextureFormat {\r\n ETC1S,\r\n UASTC4x4,\r\n}\r\n\r\nexport enum TranscodeTarget {\r\n ASTC_4X4_RGBA,\r\n BC7_RGBA,\r\n BC3_RGBA,\r\n BC1_RGB,\r\n PVRTC1_4_RGBA,\r\n PVRTC1_4_RGB,\r\n ETC2_RGBA,\r\n ETC1_RGB,\r\n RGBA32,\r\n R8,\r\n RG8,\r\n}\r\n\r\nexport enum EngineFormat {\r\n COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8e8c,\r\n COMPRESSED_RGBA_ASTC_4X4_KHR = 0x93b0,\r\n COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83f0,\r\n COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83f3,\r\n COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8c02,\r\n COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8c00,\r\n COMPRESSED_RGBA8_ETC2_EAC = 0x9278,\r\n COMPRESSED_RGB8_ETC2 = 0x9274,\r\n COMPRESSED_RGB_ETC1_WEBGL = 0x8d64,\r\n RGBA8Format = 0x8058,\r\n R8Format = 0x8229,\r\n RG8Format = 0x822b,\r\n}\r\n\r\n/**\r\n * Leaf node of a decision tree\r\n * It defines the transcoding format to use to transcode the texture as well as the corresponding format to use at the engine level when creating the texture\r\n */\r\nexport interface ILeaf {\r\n /**\r\n * The format to transcode to\r\n */\r\n transcodeFormat: TranscodeTarget;\r\n\r\n /**\r\n * The format to use when creating the texture at the engine level after it has been transcoded to transcodeFormat\r\n */\r\n engineFormat: EngineFormat;\r\n\r\n /**\r\n * Whether the texture must be rounded to a multiple of 4 (should normally be the case for all compressed formats). Default: true\r\n */\r\n roundToMultiple4?: boolean;\r\n}\r\n\r\n/**\r\n * Regular node of a decision tree\r\n *\r\n * Each property (except for \"yes\" and \"no\"), if not empty, will be checked in order to determine the next node to select.\r\n * If all checks are successful, the \"yes\" node will be selected, else the \"no\" node will be selected.\r\n */\r\nexport interface INode {\r\n /**\r\n * The name of the capability to check. Can be one of the following:\r\n * astc\r\n * bptc\r\n * s3tc\r\n * pvrtc\r\n * etc2\r\n * etc1\r\n */\r\n cap?: string;\r\n\r\n /**\r\n * The name of the option to check from the options object passed to the KTX2 decode function. {@link IKTX2DecoderOptions}\r\n */\r\n option?: string;\r\n\r\n /**\r\n * Checks if alpha is present in the texture\r\n */\r\n alpha?: boolean;\r\n\r\n /**\r\n * Checks the currently selected transcoding format.\r\n */\r\n transcodeFormat?: TranscodeTarget | TranscodeTarget[];\r\n\r\n /**\r\n * Checks that the texture is a power of two\r\n */\r\n needsPowerOfTwo?: boolean;\r\n\r\n /**\r\n * The node to select if all checks are successful\r\n */\r\n yes?: INode | ILeaf;\r\n\r\n /**\r\n * The node to select if at least one check is not successful\r\n */\r\n no?: INode | ILeaf;\r\n}\r\n\r\n/**\r\n * Decision tree used to determine the transcoding format to use for a given source texture format\r\n */\r\nexport interface IDecisionTree {\r\n /**\r\n * textureFormat can be either UASTC or ETC1S\r\n */\r\n [textureFormat: string]: INode;\r\n}\r\n\r\n/**\r\n * Result of the KTX2 decode function\r\n */\r\nexport interface IDecodedData {\r\n /**\r\n * Width of the texture\r\n */\r\n width: number;\r\n\r\n /**\r\n * Height of the texture\r\n */\r\n height: number;\r\n\r\n /**\r\n * The format to use when creating the texture at the engine level\r\n * This corresponds to the engineFormat property of the leaf node of the decision tree\r\n */\r\n transcodedFormat: number;\r\n\r\n /**\r\n * List of mipmap levels.\r\n * The first element is the base level, the last element is the smallest mipmap level (if more than one mipmap level is present)\r\n */\r\n mipmaps: Array;\r\n\r\n /**\r\n * Whether the texture data is in gamma space or not\r\n */\r\n isInGammaSpace: boolean;\r\n\r\n /**\r\n * Whether the texture has an alpha channel or not\r\n */\r\n hasAlpha: boolean;\r\n\r\n /**\r\n * The name of the transcoder used to transcode the texture\r\n */\r\n transcoderName: string;\r\n\r\n /**\r\n * The errors (if any) encountered during the decoding process\r\n */\r\n errors?: string;\r\n}\r\n\r\n/**\r\n * Defines a mipmap level\r\n */\r\nexport interface IMipmap {\r\n /**\r\n * The data of the mipmap level\r\n */\r\n data: Uint8Array | null;\r\n\r\n /**\r\n * The width of the mipmap level\r\n */\r\n width: number;\r\n\r\n /**\r\n * The height of the mipmap level\r\n */\r\n height: number;\r\n}\r\n\r\n/**\r\n * The compressed texture formats supported by the browser\r\n */\r\nexport interface ICompressedFormatCapabilities {\r\n /**\r\n * Whether the browser supports ASTC\r\n */\r\n astc?: boolean;\r\n\r\n /**\r\n * Whether the browser supports BPTC\r\n */\r\n bptc?: boolean;\r\n\r\n /**\r\n * Whether the browser supports S3TC\r\n */\r\n s3tc?: boolean;\r\n\r\n /**\r\n * Whether the browser supports PVRTC\r\n */\r\n pvrtc?: boolean;\r\n\r\n /**\r\n * Whether the browser supports ETC2\r\n */\r\n etc2?: boolean;\r\n\r\n /**\r\n * Whether the browser supports ETC1\r\n */\r\n etc1?: boolean;\r\n}\r\n\r\n/**\r\n * Options passed to the KTX2 decode function\r\n */\r\nexport interface IKTX2DecoderOptions {\r\n /** use RGBA format if ASTC and BC7 are not available as transcoded format */\r\n useRGBAIfASTCBC7NotAvailableWhenUASTC?: boolean;\r\n\r\n /** force to always use (uncompressed) RGBA for transcoded format */\r\n forceRGBA?: boolean;\r\n\r\n /** force to always use (uncompressed) R8 for transcoded format */\r\n forceR8?: boolean;\r\n\r\n /** force to always use (uncompressed) RG8 for transcoded format */\r\n forceRG8?: boolean;\r\n\r\n /**\r\n * list of transcoders to bypass when looking for a suitable transcoder. The available transcoders are:\r\n * UniversalTranscoder_UASTC_ASTC\r\n * UniversalTranscoder_UASTC_BC7\r\n * UniversalTranscoder_UASTC_RGBA_UNORM\r\n * UniversalTranscoder_UASTC_RGBA_SRGB\r\n * UniversalTranscoder_UASTC_R8_UNORM\r\n * UniversalTranscoder_UASTC_RG8_UNORM\r\n * MSCTranscoder\r\n */\r\n bypassTranscoders?: string[];\r\n\r\n /**\r\n * Custom decision tree to apply after the default decision tree has selected a transcoding format.\r\n * Allows the user to override the default decision tree selection.\r\n * The decision tree can use the INode.transcodeFormat property to base its decision on the transcoding format selected by the default decision tree.\r\n */\r\n transcodeFormatDecisionTree?: IDecisionTree;\r\n}\r\n","import { Tools } from \"../Misc/tools\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { AnimationGroup } from \"../Animations/animationGroup\";\r\nimport type { AssetContainer } from \"../assetContainer\";\r\nimport type { IParticleSystem } from \"../Particles/IParticleSystem\";\r\nimport type { Skeleton } from \"../Bones/skeleton\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { SceneLoaderFlags } from \"./sceneLoaderFlags\";\r\nimport type { IFileRequest } from \"../Misc/fileRequest\";\r\nimport type { WebRequest } from \"../Misc/webRequest\";\r\nimport type { LoadFileError } from \"../Misc/fileTools\";\r\nimport { IsBase64DataUrl } from \"../Misc/fileTools\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { Geometry } from \"../Meshes/geometry\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { RuntimeError, ErrorCodes } from \"../Misc/error\";\r\n\r\n/**\r\n * Type used for the success callback of ImportMesh\r\n */\r\nexport type SceneLoaderSuccessCallback = (\r\n meshes: AbstractMesh[],\r\n particleSystems: IParticleSystem[],\r\n skeletons: Skeleton[],\r\n animationGroups: AnimationGroup[],\r\n transformNodes: TransformNode[],\r\n geometries: Geometry[],\r\n lights: Light[]\r\n) => void;\r\n\r\n/**\r\n * Interface used for the result of ImportMeshAsync\r\n */\r\nexport interface ISceneLoaderAsyncResult {\r\n /**\r\n * The array of loaded meshes\r\n */\r\n readonly meshes: AbstractMesh[];\r\n\r\n /**\r\n * The array of loaded particle systems\r\n */\r\n readonly particleSystems: IParticleSystem[];\r\n\r\n /**\r\n * The array of loaded skeletons\r\n */\r\n readonly skeletons: Skeleton[];\r\n\r\n /**\r\n * The array of loaded animation groups\r\n */\r\n readonly animationGroups: AnimationGroup[];\r\n\r\n /**\r\n * The array of loaded transform nodes\r\n */\r\n readonly transformNodes: TransformNode[];\r\n\r\n /**\r\n * The array of loaded geometries\r\n */\r\n readonly geometries: Geometry[];\r\n\r\n /**\r\n * The array of loaded lights\r\n */\r\n readonly lights: Light[];\r\n}\r\n\r\n/**\r\n * Interface used to represent data loading progression\r\n */\r\nexport interface ISceneLoaderProgressEvent {\r\n /**\r\n * Defines if data length to load can be evaluated\r\n */\r\n readonly lengthComputable: boolean;\r\n\r\n /**\r\n * Defines the loaded data length\r\n */\r\n readonly loaded: number;\r\n\r\n /**\r\n * Defines the data length to load\r\n */\r\n readonly total: number;\r\n}\r\n\r\n/**\r\n * Interface used by SceneLoader plugins to define supported file extensions\r\n */\r\nexport interface ISceneLoaderPluginExtensions {\r\n /**\r\n * Defines the list of supported extensions\r\n */\r\n [extension: string]: {\r\n isBinary: boolean;\r\n };\r\n}\r\n\r\n/**\r\n * Interface used by SceneLoader plugin factory\r\n */\r\nexport interface ISceneLoaderPluginFactory {\r\n /**\r\n * Defines the name of the factory\r\n */\r\n name: string;\r\n\r\n /**\r\n * Function called to create a new plugin\r\n * @returns the new plugin\r\n */\r\n createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;\r\n\r\n /**\r\n * The callback that returns true if the data can be directly loaded.\r\n * @param data string containing the file data\r\n * @returns if the data can be loaded directly\r\n */\r\n canDirectLoad?(data: string): boolean;\r\n}\r\n\r\n/**\r\n * Interface used to define the base of ISceneLoaderPlugin and ISceneLoaderPluginAsync\r\n */\r\nexport interface ISceneLoaderPluginBase {\r\n /**\r\n * The friendly name of this plugin.\r\n */\r\n name: string;\r\n\r\n /**\r\n * The file extensions supported by this plugin.\r\n */\r\n extensions: string | ISceneLoaderPluginExtensions;\r\n\r\n /**\r\n * The callback called when loading from a url.\r\n * @param scene scene loading this url\r\n * @param fileOrUrl file or url to load\r\n * @param onSuccess callback called when the file successfully loads\r\n * @param onProgress callback called while file is loading (if the server supports this mode)\r\n * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer\r\n * @param onError callback called when the file fails to load\r\n * @returns a file request object\r\n */\r\n loadFile?(\r\n scene: Scene,\r\n fileOrUrl: File | string | ArrayBufferView,\r\n rootUrl: string,\r\n onSuccess: (data: any, responseURL?: string) => void,\r\n onProgress?: (ev: ISceneLoaderProgressEvent) => void,\r\n useArrayBuffer?: boolean,\r\n onError?: (request?: WebRequest, exception?: LoadFileError) => void,\r\n name?: string\r\n ): Nullable;\r\n\r\n /**\r\n * The callback that returns true if the data can be directly loaded.\r\n * @param data string containing the file data\r\n * @returns if the data can be loaded directly\r\n */\r\n canDirectLoad?(data: string): boolean;\r\n\r\n /**\r\n * The callback that returns the data to pass to the plugin if the data can be directly loaded.\r\n * @param scene scene loading this data\r\n * @param data string containing the data\r\n * @returns data to pass to the plugin\r\n */\r\n directLoad?(scene: Scene, data: string): any;\r\n\r\n /**\r\n * The callback that allows custom handling of the root url based on the response url.\r\n * @param rootUrl the original root url\r\n * @param responseURL the response url if available\r\n * @returns the new root url\r\n */\r\n rewriteRootURL?(rootUrl: string, responseURL?: string): string;\r\n}\r\n\r\n/**\r\n * Interface used to define a SceneLoader plugin\r\n */\r\nexport interface ISceneLoaderPlugin extends ISceneLoaderPluginBase {\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param meshes The meshes array to import into\r\n * @param particleSystems The particle systems array to import into\r\n * @param skeletons The skeletons array to import into\r\n * @param onError The callback when import fails\r\n * @returns True if successful or false otherwise\r\n */\r\n importMesh(\r\n meshesNames: any,\r\n scene: Scene,\r\n data: any,\r\n rootUrl: string,\r\n meshes: AbstractMesh[],\r\n particleSystems: IParticleSystem[],\r\n skeletons: Skeleton[],\r\n onError?: (message: string, exception?: any) => void\r\n ): boolean;\r\n\r\n /**\r\n * Load into a scene.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param onError The callback when import fails\r\n * @returns True if successful or false otherwise\r\n */\r\n load(scene: Scene, data: any, rootUrl: string, onError?: (message: string, exception?: any) => void): boolean;\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param onError The callback when import fails\r\n * @returns The loaded asset container\r\n */\r\n loadAssetContainer(scene: Scene, data: any, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;\r\n}\r\n\r\n/**\r\n * Interface used to define an async SceneLoader plugin\r\n */\r\nexport interface ISceneLoaderPluginAsync extends ISceneLoaderPluginBase {\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param onProgress The callback when the load progresses\r\n * @param fileName Defines the name of the file to load\r\n * @returns The loaded objects (e.g. meshes, particle systems, skeletons, animation groups, etc.)\r\n */\r\n importMeshAsync(\r\n meshesNames: any,\r\n scene: Scene,\r\n data: any,\r\n rootUrl: string,\r\n onProgress?: (event: ISceneLoaderProgressEvent) => void,\r\n fileName?: string\r\n ): Promise;\r\n\r\n /**\r\n * Load into a scene.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param onProgress The callback when the load progresses\r\n * @param fileName Defines the name of the file to load\r\n * @returns Nothing\r\n */\r\n loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise;\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param onProgress The callback when the load progresses\r\n * @param fileName Defines the name of the file to load\r\n * @returns The loaded asset container\r\n */\r\n loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise;\r\n}\r\n\r\n/**\r\n * Mode that determines how to handle old animation groups before loading new ones.\r\n */\r\nexport enum SceneLoaderAnimationGroupLoadingMode {\r\n /**\r\n * Reset all old animations to initial state then dispose them.\r\n */\r\n Clean = 0,\r\n\r\n /**\r\n * Stop all old animations.\r\n */\r\n Stop = 1,\r\n\r\n /**\r\n * Restart old animations from first frame.\r\n */\r\n Sync = 2,\r\n\r\n /**\r\n * Old animations remains untouched.\r\n */\r\n NoSync = 3,\r\n}\r\n\r\n/**\r\n * Defines a plugin registered by the SceneLoader\r\n */\r\ninterface IRegisteredPlugin {\r\n /**\r\n * Defines the plugin to use\r\n */\r\n plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory;\r\n /**\r\n * Defines if the plugin supports binary data\r\n */\r\n isBinary: boolean;\r\n}\r\n\r\n/**\r\n * Defines file information\r\n */\r\ninterface IFileInfo {\r\n /**\r\n * Gets the file url\r\n */\r\n url: string;\r\n /**\r\n * Gets the root url\r\n */\r\n rootUrl: string;\r\n /**\r\n * Gets filename\r\n */\r\n name: string;\r\n /**\r\n * Gets the file\r\n */\r\n file: Nullable;\r\n\r\n /**\r\n * Gets raw binary data.\r\n */\r\n rawData: Nullable;\r\n}\r\n\r\n/**\r\n * Class used to load scene from various file formats using registered plugins\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes\r\n */\r\nexport class SceneLoader {\r\n /**\r\n * No logging while loading\r\n */\r\n public static readonly NO_LOGGING = Constants.SCENELOADER_NO_LOGGING;\r\n\r\n /**\r\n * Minimal logging while loading\r\n */\r\n public static readonly MINIMAL_LOGGING = Constants.SCENELOADER_MINIMAL_LOGGING;\r\n\r\n /**\r\n * Summary logging while loading\r\n */\r\n public static readonly SUMMARY_LOGGING = Constants.SCENELOADER_SUMMARY_LOGGING;\r\n\r\n /**\r\n * Detailed logging while loading\r\n */\r\n public static readonly DETAILED_LOGGING = Constants.SCENELOADER_DETAILED_LOGGING;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if entire scene must be loaded even if scene contains incremental data\r\n */\r\n public static get ForceFullSceneLoadingForIncremental() {\r\n return SceneLoaderFlags.ForceFullSceneLoadingForIncremental;\r\n }\r\n\r\n public static set ForceFullSceneLoadingForIncremental(value: boolean) {\r\n SceneLoaderFlags.ForceFullSceneLoadingForIncremental = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if loading screen must be displayed while loading a scene\r\n */\r\n public static get ShowLoadingScreen(): boolean {\r\n return SceneLoaderFlags.ShowLoadingScreen;\r\n }\r\n\r\n public static set ShowLoadingScreen(value: boolean) {\r\n SceneLoaderFlags.ShowLoadingScreen = value;\r\n }\r\n\r\n /**\r\n * Defines the current logging level (while loading the scene)\r\n * @ignorenaming\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static get loggingLevel(): number {\r\n return SceneLoaderFlags.loggingLevel;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static set loggingLevel(value: number) {\r\n SceneLoaderFlags.loggingLevel = value;\r\n }\r\n\r\n /**\r\n * Gets or set a boolean indicating if matrix weights must be cleaned upon loading\r\n */\r\n public static get CleanBoneMatrixWeights(): boolean {\r\n return SceneLoaderFlags.CleanBoneMatrixWeights;\r\n }\r\n\r\n public static set CleanBoneMatrixWeights(value: boolean) {\r\n SceneLoaderFlags.CleanBoneMatrixWeights = value;\r\n }\r\n\r\n // Members\r\n\r\n /**\r\n * Event raised when a plugin is used to load a scene\r\n */\r\n public static OnPluginActivatedObservable = new Observable();\r\n\r\n private static _RegisteredPlugins: { [extension: string]: IRegisteredPlugin } = {};\r\n\r\n private static _ShowingLoadingScreen = false;\r\n\r\n /**\r\n * Gets the default plugin (used to load Babylon files)\r\n * @returns the .babylon plugin\r\n */\r\n public static GetDefaultPlugin(): IRegisteredPlugin {\r\n return SceneLoader._RegisteredPlugins[\".babylon\"];\r\n }\r\n\r\n private static _GetPluginForExtension(extension: string): IRegisteredPlugin {\r\n const registeredPlugin = SceneLoader._RegisteredPlugins[extension];\r\n if (registeredPlugin) {\r\n return registeredPlugin;\r\n }\r\n Logger.Warn(\r\n \"Unable to find a plugin to load \" +\r\n extension +\r\n \" files. Trying to use .babylon default plugin. To load from a specific filetype (eg. gltf) see: https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes\"\r\n );\r\n return SceneLoader.GetDefaultPlugin();\r\n }\r\n\r\n private static _GetPluginForDirectLoad(data: string): IRegisteredPlugin {\r\n for (const extension in SceneLoader._RegisteredPlugins) {\r\n const plugin = SceneLoader._RegisteredPlugins[extension].plugin;\r\n\r\n if (plugin.canDirectLoad && plugin.canDirectLoad(data)) {\r\n return SceneLoader._RegisteredPlugins[extension];\r\n }\r\n }\r\n\r\n return SceneLoader.GetDefaultPlugin();\r\n }\r\n\r\n private static _GetPluginForFilename(sceneFilename: string): IRegisteredPlugin {\r\n const queryStringPosition = sceneFilename.indexOf(\"?\");\r\n\r\n if (queryStringPosition !== -1) {\r\n sceneFilename = sceneFilename.substring(0, queryStringPosition);\r\n }\r\n\r\n const dotPosition = sceneFilename.lastIndexOf(\".\");\r\n\r\n const extension = sceneFilename.substring(dotPosition, sceneFilename.length).toLowerCase();\r\n return SceneLoader._GetPluginForExtension(extension);\r\n }\r\n\r\n private static _GetDirectLoad(sceneFilename: string): Nullable {\r\n if (sceneFilename.substr(0, 5) === \"data:\") {\r\n return sceneFilename.substr(5);\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private static _FormatErrorMessage(fileInfo: IFileInfo, message?: string, exception?: any): string {\r\n const fromLoad = fileInfo.rawData ? \"binary data\" : fileInfo.url;\r\n let errorMessage = \"Unable to load from \" + fromLoad;\r\n\r\n if (message) {\r\n errorMessage += `: ${message}`;\r\n } else if (exception) {\r\n errorMessage += `: ${exception}`;\r\n }\r\n\r\n return errorMessage;\r\n }\r\n\r\n private static _LoadData(\r\n fileInfo: IFileInfo,\r\n scene: Scene,\r\n onSuccess: (plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync, data: any, responseURL?: string) => void,\r\n onProgress: ((event: ISceneLoaderProgressEvent) => void) | undefined,\r\n onError: (message?: string, exception?: any) => void,\r\n onDispose: () => void,\r\n pluginExtension: Nullable,\r\n name: string\r\n ): Nullable {\r\n const directLoad = SceneLoader._GetDirectLoad(fileInfo.url);\r\n\r\n if (fileInfo.rawData && !pluginExtension) {\r\n throw \"When using ArrayBufferView to load data the file extension must be provided.\";\r\n }\r\n\r\n const registeredPlugin = pluginExtension\r\n ? SceneLoader._GetPluginForExtension(pluginExtension)\r\n : directLoad\r\n ? SceneLoader._GetPluginForDirectLoad(fileInfo.url)\r\n : SceneLoader._GetPluginForFilename(fileInfo.url);\r\n\r\n if (fileInfo.rawData && !registeredPlugin.isBinary) {\r\n throw \"Loading from ArrayBufferView can not be used with plugins that don't support binary loading.\";\r\n }\r\n\r\n let plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync;\r\n\r\n if ((registeredPlugin.plugin as ISceneLoaderPluginFactory).createPlugin !== undefined) {\r\n plugin = (registeredPlugin.plugin as ISceneLoaderPluginFactory).createPlugin();\r\n } else {\r\n plugin = registeredPlugin.plugin;\r\n }\r\n\r\n if (!plugin) {\r\n throw \"The loader plugin corresponding to the file type you are trying to load has not been found. If using es6, please import the plugin you wish to use before.\";\r\n }\r\n\r\n SceneLoader.OnPluginActivatedObservable.notifyObservers(plugin);\r\n\r\n // Check if we have a direct load url. If the plugin is registered to handle\r\n // it or it's not a base64 data url, then pass it through the direct load path.\r\n if (directLoad && ((plugin.canDirectLoad && plugin.canDirectLoad(fileInfo.url)) || !IsBase64DataUrl(fileInfo.url))) {\r\n if (plugin.directLoad) {\r\n const result = plugin.directLoad(scene, directLoad);\r\n if (result.then) {\r\n result\r\n .then((data: any) => {\r\n onSuccess(plugin, data);\r\n })\r\n .catch((error: any) => {\r\n onError(\"Error in directLoad of _loadData: \" + error, error);\r\n });\r\n } else {\r\n onSuccess(plugin, result);\r\n }\r\n } else {\r\n onSuccess(plugin, directLoad);\r\n }\r\n return plugin;\r\n }\r\n\r\n const useArrayBuffer = registeredPlugin.isBinary;\r\n\r\n const dataCallback = (data: any, responseURL?: string) => {\r\n if (scene.isDisposed) {\r\n onError(\"Scene has been disposed\");\r\n return;\r\n }\r\n\r\n onSuccess(plugin, data, responseURL);\r\n };\r\n\r\n let request: Nullable = null;\r\n let pluginDisposed = false;\r\n const onDisposeObservable = (plugin as any).onDisposeObservable as Observable;\r\n if (onDisposeObservable) {\r\n onDisposeObservable.add(() => {\r\n pluginDisposed = true;\r\n\r\n if (request) {\r\n request.abort();\r\n request = null;\r\n }\r\n\r\n onDispose();\r\n });\r\n }\r\n\r\n const manifestChecked = () => {\r\n if (pluginDisposed) {\r\n return;\r\n }\r\n\r\n const errorCallback = (request?: WebRequest, exception?: LoadFileError) => {\r\n onError(request?.statusText, exception);\r\n };\r\n\r\n if (!plugin.loadFile && fileInfo.rawData) {\r\n throw \"Plugin does not support loading ArrayBufferView.\";\r\n }\r\n\r\n request = plugin.loadFile\r\n ? plugin.loadFile(scene, fileInfo.rawData || fileInfo.file || fileInfo.url, fileInfo.rootUrl, dataCallback, onProgress, useArrayBuffer, errorCallback, name)\r\n : scene._loadFile(fileInfo.file || fileInfo.url, dataCallback, onProgress, true, useArrayBuffer, errorCallback);\r\n };\r\n\r\n const engine = scene.getEngine();\r\n let canUseOfflineSupport = engine.enableOfflineSupport;\r\n if (canUseOfflineSupport) {\r\n // Also check for exceptions\r\n let exceptionFound = false;\r\n for (const regex of scene.disableOfflineSupportExceptionRules) {\r\n if (regex.test(fileInfo.url)) {\r\n exceptionFound = true;\r\n break;\r\n }\r\n }\r\n\r\n canUseOfflineSupport = !exceptionFound;\r\n }\r\n\r\n if (canUseOfflineSupport && Engine.OfflineProviderFactory) {\r\n // Checking if a manifest file has been set for this scene and if offline mode has been requested\r\n scene.offlineProvider = Engine.OfflineProviderFactory(fileInfo.url, manifestChecked, engine.disableManifestCheck);\r\n } else {\r\n manifestChecked();\r\n }\r\n\r\n return plugin;\r\n }\r\n\r\n private static _GetFileInfo(rootUrl: string, sceneFilename: string | File | ArrayBufferView): Nullable {\r\n let url: string;\r\n let name: string;\r\n let file: Nullable = null;\r\n let rawData: Nullable = null;\r\n\r\n if (!sceneFilename) {\r\n url = rootUrl;\r\n name = Tools.GetFilename(rootUrl);\r\n rootUrl = Tools.GetFolderPath(rootUrl);\r\n } else if ((sceneFilename as File).name) {\r\n const sceneFile = sceneFilename as File;\r\n url = `file:${sceneFile.name}`;\r\n name = sceneFile.name;\r\n file = sceneFile;\r\n } else if (ArrayBuffer.isView(sceneFilename)) {\r\n url = \"\";\r\n name = \"arrayBuffer\";\r\n rawData = sceneFilename as ArrayBufferView;\r\n } else if (typeof sceneFilename === \"string\" && sceneFilename.startsWith(\"data:\")) {\r\n url = sceneFilename;\r\n name = \"\";\r\n } else {\r\n const filename = sceneFilename as string;\r\n if (filename.substr(0, 1) === \"/\") {\r\n Tools.Error(\"Wrong sceneFilename parameter\");\r\n return null;\r\n }\r\n\r\n url = rootUrl + filename;\r\n name = filename;\r\n }\r\n\r\n return {\r\n url: url,\r\n rootUrl: rootUrl,\r\n name: name,\r\n file: file,\r\n rawData,\r\n };\r\n }\r\n\r\n // Public functions\r\n\r\n /**\r\n * Gets a plugin that can load the given extension\r\n * @param extension defines the extension to load\r\n * @returns a plugin or null if none works\r\n */\r\n public static GetPluginForExtension(extension: string): ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory {\r\n return SceneLoader._GetPluginForExtension(extension).plugin;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the given extension can be loaded\r\n * @param extension defines the extension to load\r\n * @returns true if the extension is supported\r\n */\r\n public static IsPluginForExtensionAvailable(extension: string): boolean {\r\n return !!SceneLoader._RegisteredPlugins[extension];\r\n }\r\n\r\n /**\r\n * Adds a new plugin to the list of registered plugins\r\n * @param plugin defines the plugin to add\r\n */\r\n public static RegisterPlugin(plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync): void {\r\n if (typeof plugin.extensions === \"string\") {\r\n const extension = plugin.extensions;\r\n SceneLoader._RegisteredPlugins[extension.toLowerCase()] = {\r\n plugin: plugin,\r\n isBinary: false,\r\n };\r\n } else {\r\n const extensions = plugin.extensions;\r\n Object.keys(extensions).forEach((extension) => {\r\n SceneLoader._RegisteredPlugins[extension.toLowerCase()] = {\r\n plugin: plugin,\r\n isBinary: extensions[extension].isBinary,\r\n };\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Import meshes into a scene\r\n * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene the instance of BABYLON.Scene to append to\r\n * @param onSuccess a callback with a list of imported meshes, particleSystems, skeletons, and animationGroups when import succeeds\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded plugin\r\n */\r\n public static ImportMesh(\r\n meshNames: any,\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n onSuccess: Nullable = null,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Nullable {\r\n if (!scene) {\r\n Logger.Error(\"No scene available to import mesh to\");\r\n return null;\r\n }\r\n\r\n const fileInfo = SceneLoader._GetFileInfo(rootUrl, sceneFilename);\r\n if (!fileInfo) {\r\n return null;\r\n }\r\n\r\n const loadingToken = {};\r\n scene.addPendingData(loadingToken);\r\n\r\n const disposeHandler = () => {\r\n scene.removePendingData(loadingToken);\r\n };\r\n\r\n const errorHandler = (message?: string, exception?: any) => {\r\n const errorMessage = SceneLoader._FormatErrorMessage(fileInfo, message, exception);\r\n\r\n if (onError) {\r\n onError(scene, errorMessage, new RuntimeError(errorMessage, ErrorCodes.SceneLoaderError, exception));\r\n } else {\r\n Logger.Error(errorMessage);\r\n // should the exception be thrown?\r\n }\r\n\r\n disposeHandler();\r\n };\r\n\r\n const progressHandler = onProgress\r\n ? (event: ISceneLoaderProgressEvent) => {\r\n try {\r\n onProgress(event);\r\n } catch (e) {\r\n errorHandler(\"Error in onProgress callback: \" + e, e);\r\n }\r\n }\r\n : undefined;\r\n\r\n const successHandler: SceneLoaderSuccessCallback = (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights) => {\r\n scene.importedMeshesFiles.push(fileInfo.url);\r\n\r\n if (onSuccess) {\r\n try {\r\n onSuccess(meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights);\r\n } catch (e) {\r\n errorHandler(\"Error in onSuccess callback: \" + e, e);\r\n }\r\n }\r\n\r\n scene.removePendingData(loadingToken);\r\n };\r\n\r\n return SceneLoader._LoadData(\r\n fileInfo,\r\n scene,\r\n (plugin, data, responseURL) => {\r\n if (plugin.rewriteRootURL) {\r\n fileInfo.rootUrl = plugin.rewriteRootURL(fileInfo.rootUrl, responseURL);\r\n }\r\n\r\n if ((plugin).importMesh) {\r\n const syncedPlugin = plugin;\r\n const meshes = new Array();\r\n const particleSystems = new Array();\r\n const skeletons = new Array();\r\n\r\n if (!syncedPlugin.importMesh(meshNames, scene, data, fileInfo.rootUrl, meshes, particleSystems, skeletons, errorHandler)) {\r\n return;\r\n }\r\n\r\n scene.loadingPluginName = plugin.name;\r\n successHandler(meshes, particleSystems, skeletons, [], [], [], []);\r\n } else {\r\n const asyncedPlugin = plugin;\r\n asyncedPlugin\r\n .importMeshAsync(meshNames, scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name)\r\n .then((result) => {\r\n scene.loadingPluginName = plugin.name;\r\n successHandler(\r\n result.meshes,\r\n result.particleSystems,\r\n result.skeletons,\r\n result.animationGroups,\r\n result.transformNodes,\r\n result.geometries,\r\n result.lights\r\n );\r\n })\r\n .catch((error) => {\r\n errorHandler(error.message, error);\r\n });\r\n }\r\n },\r\n progressHandler,\r\n errorHandler,\r\n disposeHandler,\r\n pluginExtension,\r\n name\r\n );\r\n }\r\n\r\n /**\r\n * Import meshes into a scene\r\n * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene the instance of BABYLON.Scene to append to\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded list of imported meshes, particle systems, skeletons, and animation groups\r\n */\r\n public static ImportMeshAsync(\r\n meshNames: any,\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n SceneLoader.ImportMesh(\r\n meshNames,\r\n rootUrl,\r\n sceneFilename,\r\n scene,\r\n (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights) => {\r\n resolve({\r\n meshes: meshes,\r\n particleSystems: particleSystems,\r\n skeletons: skeletons,\r\n animationGroups: animationGroups,\r\n transformNodes: transformNodes,\r\n geometries: geometries,\r\n lights: lights,\r\n });\r\n },\r\n onProgress,\r\n (scene, message, exception) => {\r\n reject(exception || new Error(message));\r\n },\r\n pluginExtension,\r\n name\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Load a scene\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param engine is the instance of BABYLON.Engine to use to create the scene\r\n * @param onSuccess a callback with the scene when import succeeds\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded plugin\r\n */\r\n public static Load(\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n engine: Nullable = EngineStore.LastCreatedEngine,\r\n onSuccess: Nullable<(scene: Scene) => void> = null,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Nullable {\r\n if (!engine) {\r\n Tools.Error(\"No engine available\");\r\n return null;\r\n }\r\n\r\n return SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension, name);\r\n }\r\n\r\n /**\r\n * Load a scene\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param engine is the instance of BABYLON.Engine to use to create the scene\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded scene\r\n */\r\n public static LoadAsync(\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n engine: Nullable = EngineStore.LastCreatedEngine,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n SceneLoader.Load(\r\n rootUrl,\r\n sceneFilename,\r\n engine,\r\n (scene) => {\r\n resolve(scene);\r\n },\r\n onProgress,\r\n (scene, message, exception) => {\r\n reject(exception || new Error(message));\r\n },\r\n pluginExtension,\r\n name\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Append a scene\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene is the instance of BABYLON.Scene to append to\r\n * @param onSuccess a callback with the scene when import succeeds\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded plugin\r\n */\r\n public static Append(\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n onSuccess: Nullable<(scene: Scene) => void> = null,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Nullable {\r\n if (!scene) {\r\n Logger.Error(\"No scene available to append to\");\r\n return null;\r\n }\r\n\r\n const fileInfo = SceneLoader._GetFileInfo(rootUrl, sceneFilename);\r\n if (!fileInfo) {\r\n return null;\r\n }\r\n\r\n const loadingToken = {};\r\n scene.addPendingData(loadingToken);\r\n\r\n const disposeHandler = () => {\r\n scene.removePendingData(loadingToken);\r\n };\r\n\r\n if (SceneLoader.ShowLoadingScreen && !this._ShowingLoadingScreen) {\r\n this._ShowingLoadingScreen = true;\r\n scene.getEngine().displayLoadingUI();\r\n scene.executeWhenReady(() => {\r\n scene.getEngine().hideLoadingUI();\r\n this._ShowingLoadingScreen = false;\r\n });\r\n }\r\n\r\n const errorHandler = (message?: string, exception?: any) => {\r\n const errorMessage = SceneLoader._FormatErrorMessage(fileInfo, message, exception);\r\n\r\n if (onError) {\r\n onError(scene, errorMessage, new RuntimeError(errorMessage, ErrorCodes.SceneLoaderError, exception));\r\n } else {\r\n Logger.Error(errorMessage);\r\n // should the exception be thrown?\r\n }\r\n\r\n disposeHandler();\r\n };\r\n\r\n const progressHandler = onProgress\r\n ? (event: ISceneLoaderProgressEvent) => {\r\n try {\r\n onProgress(event);\r\n } catch (e) {\r\n errorHandler(\"Error in onProgress callback\", e);\r\n }\r\n }\r\n : undefined;\r\n\r\n const successHandler = () => {\r\n if (onSuccess) {\r\n try {\r\n onSuccess(scene);\r\n } catch (e) {\r\n errorHandler(\"Error in onSuccess callback\", e);\r\n }\r\n }\r\n\r\n scene.removePendingData(loadingToken);\r\n };\r\n\r\n return SceneLoader._LoadData(\r\n fileInfo,\r\n scene,\r\n (plugin, data) => {\r\n if ((plugin).load) {\r\n const syncedPlugin = plugin;\r\n if (!syncedPlugin.load(scene, data, fileInfo.rootUrl, errorHandler)) {\r\n return;\r\n }\r\n\r\n scene.loadingPluginName = plugin.name;\r\n successHandler();\r\n } else {\r\n const asyncedPlugin = plugin;\r\n asyncedPlugin\r\n .loadAsync(scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name)\r\n .then(() => {\r\n scene.loadingPluginName = plugin.name;\r\n successHandler();\r\n })\r\n .catch((error) => {\r\n errorHandler(error.message, error);\r\n });\r\n }\r\n },\r\n progressHandler,\r\n errorHandler,\r\n disposeHandler,\r\n pluginExtension,\r\n name\r\n );\r\n }\r\n\r\n /**\r\n * Append a scene\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene is the instance of BABYLON.Scene to append to\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The given scene\r\n */\r\n public static AppendAsync(\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n SceneLoader.Append(\r\n rootUrl,\r\n sceneFilename,\r\n scene,\r\n (scene) => {\r\n resolve(scene);\r\n },\r\n onProgress,\r\n (scene, message, exception) => {\r\n reject(exception || new Error(message));\r\n },\r\n pluginExtension,\r\n name\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Load a scene into an asset container\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)\r\n * @param onSuccess a callback with the scene when import succeeds\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded plugin\r\n */\r\n public static LoadAssetContainer(\r\n rootUrl: string,\r\n sceneFilename: string | File | ArrayBufferView = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n onSuccess: Nullable<(assets: AssetContainer) => void> = null,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,\r\n pluginExtension: Nullable = null,\r\n name: string = \"\"\r\n ): Nullable {\r\n if (!scene) {\r\n Logger.Error(\"No scene available to load asset container to\");\r\n return null;\r\n }\r\n\r\n const fileInfo = SceneLoader._GetFileInfo(rootUrl, sceneFilename);\r\n if (!fileInfo) {\r\n return null;\r\n }\r\n\r\n const loadingToken = {};\r\n scene.addPendingData(loadingToken);\r\n\r\n const disposeHandler = () => {\r\n scene.removePendingData(loadingToken);\r\n };\r\n\r\n const errorHandler = (message?: string, exception?: any) => {\r\n const errorMessage = SceneLoader._FormatErrorMessage(fileInfo, message, exception);\r\n\r\n if (onError) {\r\n onError(scene, errorMessage, new RuntimeError(errorMessage, ErrorCodes.SceneLoaderError, exception));\r\n } else {\r\n Logger.Error(errorMessage);\r\n // should the exception be thrown?\r\n }\r\n\r\n disposeHandler();\r\n };\r\n\r\n const progressHandler = onProgress\r\n ? (event: ISceneLoaderProgressEvent) => {\r\n try {\r\n onProgress(event);\r\n } catch (e) {\r\n errorHandler(\"Error in onProgress callback\", e);\r\n }\r\n }\r\n : undefined;\r\n\r\n const successHandler = (assets: AssetContainer) => {\r\n if (onSuccess) {\r\n try {\r\n onSuccess(assets);\r\n } catch (e) {\r\n errorHandler(\"Error in onSuccess callback\", e);\r\n }\r\n }\r\n\r\n scene.removePendingData(loadingToken);\r\n };\r\n\r\n return SceneLoader._LoadData(\r\n fileInfo,\r\n scene,\r\n (plugin, data) => {\r\n if ((plugin).loadAssetContainer) {\r\n const syncedPlugin = plugin;\r\n const assetContainer = syncedPlugin.loadAssetContainer(scene, data, fileInfo.rootUrl, errorHandler);\r\n if (!assetContainer) {\r\n return;\r\n }\r\n assetContainer.populateRootNodes();\r\n scene.loadingPluginName = plugin.name;\r\n successHandler(assetContainer);\r\n } else if ((plugin).loadAssetContainerAsync) {\r\n const asyncedPlugin = plugin;\r\n asyncedPlugin\r\n .loadAssetContainerAsync(scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name)\r\n .then((assetContainer) => {\r\n assetContainer.populateRootNodes();\r\n scene.loadingPluginName = plugin.name;\r\n successHandler(assetContainer);\r\n })\r\n .catch((error) => {\r\n errorHandler(error.message, error);\r\n });\r\n } else {\r\n errorHandler(\"LoadAssetContainer is not supported by this plugin. Plugin did not provide a loadAssetContainer or loadAssetContainerAsync method.\");\r\n }\r\n },\r\n progressHandler,\r\n errorHandler,\r\n disposeHandler,\r\n pluginExtension,\r\n name\r\n );\r\n }\r\n\r\n /**\r\n * Load a scene into an asset container\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene (default: empty string)\r\n * @param scene is the instance of Scene to append to\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns The loaded asset container\r\n */\r\n public static LoadAssetContainerAsync(\r\n rootUrl: string,\r\n sceneFilename: string | File = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n pluginExtension: Nullable = null\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n SceneLoader.LoadAssetContainer(\r\n rootUrl,\r\n sceneFilename,\r\n scene,\r\n (assetContainer) => {\r\n resolve(assetContainer);\r\n },\r\n onProgress,\r\n (scene, message, exception) => {\r\n reject(exception || new Error(message));\r\n },\r\n pluginExtension\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Import animations from a file into a scene\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)\r\n * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise\r\n * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones\r\n * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)\r\n * @param onSuccess a callback with the scene when import succeeds\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\r\n * @param pluginExtension the extension used to determine the plugin\r\n */\r\n public static ImportAnimations(\r\n rootUrl: string,\r\n sceneFilename: string | File = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n overwriteAnimations = true,\r\n animationGroupLoadingMode = SceneLoaderAnimationGroupLoadingMode.Clean,\r\n targetConverter: Nullable<(target: any) => any> = null,\r\n onSuccess: Nullable<(scene: Scene) => void> = null,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,\r\n pluginExtension: Nullable = null\r\n ): void {\r\n if (!scene) {\r\n Logger.Error(\"No scene available to load animations to\");\r\n return;\r\n }\r\n\r\n if (overwriteAnimations) {\r\n // Reset, stop and dispose all animations before loading new ones\r\n for (const animatable of scene.animatables) {\r\n animatable.reset();\r\n }\r\n scene.stopAllAnimations();\r\n scene.animationGroups.slice().forEach((animationGroup) => {\r\n animationGroup.dispose();\r\n });\r\n const nodes = scene.getNodes();\r\n nodes.forEach((node) => {\r\n if (node.animations) {\r\n node.animations = [];\r\n }\r\n });\r\n } else {\r\n switch (animationGroupLoadingMode) {\r\n case SceneLoaderAnimationGroupLoadingMode.Clean:\r\n scene.animationGroups.slice().forEach((animationGroup) => {\r\n animationGroup.dispose();\r\n });\r\n break;\r\n case SceneLoaderAnimationGroupLoadingMode.Stop:\r\n scene.animationGroups.forEach((animationGroup) => {\r\n animationGroup.stop();\r\n });\r\n break;\r\n case SceneLoaderAnimationGroupLoadingMode.Sync:\r\n scene.animationGroups.forEach((animationGroup) => {\r\n animationGroup.reset();\r\n animationGroup.restart();\r\n });\r\n break;\r\n case SceneLoaderAnimationGroupLoadingMode.NoSync:\r\n // nothing to do\r\n break;\r\n default:\r\n Logger.Error(\"Unknown animation group loading mode value '\" + animationGroupLoadingMode + \"'\");\r\n return;\r\n }\r\n }\r\n\r\n const startingIndexForNewAnimatables = scene.animatables.length;\r\n\r\n const onAssetContainerLoaded = (container: AssetContainer) => {\r\n container.mergeAnimationsTo(scene, scene.animatables.slice(startingIndexForNewAnimatables), targetConverter);\r\n\r\n container.dispose();\r\n\r\n scene.onAnimationFileImportedObservable.notifyObservers(scene);\r\n\r\n if (onSuccess) {\r\n onSuccess(scene);\r\n }\r\n };\r\n\r\n this.LoadAssetContainer(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError, pluginExtension);\r\n }\r\n\r\n /**\r\n * Import animations from a file into a scene\r\n * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)\r\n * @param sceneFilename a string that defines the name of the scene file or starts with \"data:\" following by the stringified version of the scene or a File object (default: empty string)\r\n * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)\r\n * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise\r\n * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones\r\n * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)\r\n * @param onSuccess a callback with the scene when import succeeds\r\n * @param onProgress a callback with a progress event for each file being loaded\r\n * @param onError a callback with the scene, a message, and possibly an exception when import fails\r\n * @param pluginExtension the extension used to determine the plugin\r\n * @returns the updated scene with imported animations\r\n */\r\n public static ImportAnimationsAsync(\r\n rootUrl: string,\r\n sceneFilename: string | File = \"\",\r\n scene: Nullable = EngineStore.LastCreatedScene,\r\n overwriteAnimations = true,\r\n animationGroupLoadingMode = SceneLoaderAnimationGroupLoadingMode.Clean,\r\n targetConverter: Nullable<(target: any) => any> = null,\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n onSuccess: Nullable<(scene: Scene) => void> = null,\r\n onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void> = null,\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,\r\n pluginExtension: Nullable = null\r\n ): Promise {\r\n return new Promise((resolve, reject) => {\r\n SceneLoader.ImportAnimations(\r\n rootUrl,\r\n sceneFilename,\r\n scene,\r\n overwriteAnimations,\r\n animationGroupLoadingMode,\r\n targetConverter,\r\n (_scene: Scene) => {\r\n resolve(_scene);\r\n },\r\n onProgress,\r\n (_scene: Scene, message: string, exception: any) => {\r\n reject(exception || new Error(message));\r\n },\r\n pluginExtension\r\n );\r\n });\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { AutoReleaseWorkerPool } from \"./workerPool\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { ICompressedFormatCapabilities, IDecodedData, IKTX2DecoderOptions } from \"core/Materials/Textures/ktx2decoderTypes\";\r\nimport { EngineFormat, TranscodeTarget } from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\ndeclare let KTX2DECODER: any;\r\n\r\nfunction getAbsoluteUrlOrNull(url: Nullable): Nullable {\r\n return url ? Tools.GetAbsoluteUrl(url) : null;\r\n}\r\n\r\nfunction applyConfig(urls: typeof KhronosTextureContainer2.URLConfig): void {\r\n if (urls.wasmUASTCToASTC !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;\r\n }\r\n\r\n if (urls.wasmUASTCToBC7 !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;\r\n }\r\n\r\n if (urls.wasmUASTCToRGBA_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = urls.wasmUASTCToRGBA_UNORM;\r\n }\r\n\r\n if (urls.wasmUASTCToRGBA_SRGB !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = urls.wasmUASTCToRGBA_SRGB;\r\n }\r\n\r\n if (urls.wasmUASTCToR8_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_R8_UNORM.WasmModuleURL = urls.wasmUASTCToR8_UNORM;\r\n }\r\n\r\n if (urls.wasmUASTCToRG8_UNORM !== null) {\r\n KTX2DECODER.LiteTranscoder_UASTC_RG8_UNORM.WasmModuleURL = urls.wasmUASTCToRG8_UNORM;\r\n }\r\n\r\n if (urls.jsMSCTranscoder !== null) {\r\n KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;\r\n }\r\n\r\n if (urls.wasmMSCTranscoder !== null) {\r\n KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;\r\n }\r\n\r\n if (urls.wasmZSTDDecoder !== null) {\r\n KTX2DECODER.ZSTDDecoder.WasmModuleURL = urls.wasmZSTDDecoder;\r\n }\r\n}\r\n\r\n/**\r\n * Class that defines the default KTX2 decoder options.\r\n *\r\n * This class is useful for providing options to the KTX2 decoder to control how the source data is transcoded.\r\n */\r\nexport class DefaultKTX2DecoderOptions {\r\n private _isDirty = true;\r\n\r\n /**\r\n * Gets the dirty flag\r\n */\r\n public get isDirty() {\r\n return this._isDirty;\r\n }\r\n\r\n private _useRGBAIfASTCBC7NotAvailableWhenUASTC?: boolean;\r\n /**\r\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and ASTC + BC7 are not available as a compressed transcoded format\r\n */\r\n public get useRGBAIfASTCBC7NotAvailableWhenUASTC() {\r\n return this._useRGBAIfASTCBC7NotAvailableWhenUASTC;\r\n }\r\n\r\n public set useRGBAIfASTCBC7NotAvailableWhenUASTC(value: boolean | undefined) {\r\n if (this._useRGBAIfASTCBC7NotAvailableWhenUASTC === value) {\r\n return;\r\n }\r\n this._useRGBAIfASTCBC7NotAvailableWhenUASTC = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _useRGBAIfOnlyBC1BC3AvailableWhenUASTC?: boolean = true;\r\n /**\r\n * force a (uncompressed) RGBA transcoded format if transcoding a UASTC source format and only BC1 or BC3 are available as a compressed transcoded format.\r\n * This property is true by default to favor speed over memory, because currently transcoding from UASTC to BC1/3 is slow because the transcoder transcodes\r\n * to uncompressed and then recompresses the texture\r\n */\r\n public get useRGBAIfOnlyBC1BC3AvailableWhenUASTC() {\r\n return this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC;\r\n }\r\n\r\n public set useRGBAIfOnlyBC1BC3AvailableWhenUASTC(value: boolean | undefined) {\r\n if (this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC === value) {\r\n return;\r\n }\r\n this._useRGBAIfOnlyBC1BC3AvailableWhenUASTC = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceRGBA?: boolean;\r\n /**\r\n * force to always use (uncompressed) RGBA for transcoded format\r\n */\r\n public get forceRGBA() {\r\n return this._forceRGBA;\r\n }\r\n\r\n public set forceRGBA(value: boolean | undefined) {\r\n if (this._forceRGBA === value) {\r\n return;\r\n }\r\n this._forceRGBA = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceR8?: boolean;\r\n /**\r\n * force to always use (uncompressed) R8 for transcoded format\r\n */\r\n public get forceR8() {\r\n return this._forceR8;\r\n }\r\n\r\n public set forceR8(value: boolean | undefined) {\r\n if (this._forceR8 === value) {\r\n return;\r\n }\r\n this._forceR8 = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _forceRG8?: boolean;\r\n /**\r\n * force to always use (uncompressed) RG8 for transcoded format\r\n */\r\n public get forceRG8() {\r\n return this._forceRG8;\r\n }\r\n\r\n public set forceRG8(value: boolean | undefined) {\r\n if (this._forceRG8 === value) {\r\n return;\r\n }\r\n this._forceRG8 = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _bypassTranscoders?: string[];\r\n /**\r\n * list of transcoders to bypass when looking for a suitable transcoder. The available transcoders are:\r\n * UniversalTranscoder_UASTC_ASTC\r\n * UniversalTranscoder_UASTC_BC7\r\n * UniversalTranscoder_UASTC_RGBA_UNORM\r\n * UniversalTranscoder_UASTC_RGBA_SRGB\r\n * UniversalTranscoder_UASTC_R8_UNORM\r\n * UniversalTranscoder_UASTC_RG8_UNORM\r\n * MSCTranscoder\r\n */\r\n public get bypassTranscoders() {\r\n return this._bypassTranscoders;\r\n }\r\n\r\n public set bypassTranscoders(value: string[] | undefined) {\r\n if (this._bypassTranscoders === value) {\r\n return;\r\n }\r\n this._bypassTranscoders = value;\r\n this._isDirty = true;\r\n }\r\n\r\n private _ktx2DecoderOptions: IKTX2DecoderOptions = {};\r\n\r\n /** @internal */\r\n public _getKTX2DecoderOptions(): IKTX2DecoderOptions {\r\n if (!this._isDirty) {\r\n return this._ktx2DecoderOptions;\r\n }\r\n\r\n this._isDirty = false;\r\n\r\n const options: IKTX2DecoderOptions = {\r\n useRGBAIfASTCBC7NotAvailableWhenUASTC: this._useRGBAIfASTCBC7NotAvailableWhenUASTC,\r\n forceRGBA: this._forceRGBA,\r\n forceR8: this._forceR8,\r\n forceRG8: this._forceRG8,\r\n bypassTranscoders: this._bypassTranscoders,\r\n };\r\n\r\n if (this.useRGBAIfOnlyBC1BC3AvailableWhenUASTC) {\r\n options.transcodeFormatDecisionTree = {\r\n UASTC: {\r\n transcodeFormat: [TranscodeTarget.BC1_RGB, TranscodeTarget.BC3_RGBA],\r\n yes: {\r\n transcodeFormat: TranscodeTarget.RGBA32,\r\n engineFormat: EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n };\r\n }\r\n\r\n this._ktx2DecoderOptions = options;\r\n\r\n return options;\r\n }\r\n}\r\n\r\n/**\r\n * Class for loading KTX2 files\r\n */\r\nexport class KhronosTextureContainer2 {\r\n private static _WorkerPoolPromise?: Promise;\r\n private static _DecoderModulePromise?: Promise;\r\n\r\n /**\r\n * URLs to use when loading the KTX2 decoder module as well as its dependencies\r\n * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)\r\n * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary\r\n * Urls you can change:\r\n * URLConfig.jsDecoderModule\r\n * URLConfig.wasmUASTCToASTC\r\n * URLConfig.wasmUASTCToBC7\r\n * URLConfig.wasmUASTCToRGBA_UNORM\r\n * URLConfig.wasmUASTCToRGBA_SRGB\r\n * URLConfig.wasmUASTCToR8_UNORM\r\n * URLConfig.wasmUASTCToRG8_UNORM\r\n * URLConfig.jsMSCTranscoder\r\n * URLConfig.wasmMSCTranscoder\r\n * URLConfig.wasmZSTDDecoder\r\n * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#29\r\n */\r\n public static URLConfig: {\r\n jsDecoderModule: string;\r\n wasmUASTCToASTC: Nullable;\r\n wasmUASTCToBC7: Nullable;\r\n wasmUASTCToRGBA_UNORM: Nullable;\r\n wasmUASTCToRGBA_SRGB: Nullable;\r\n wasmUASTCToR8_UNORM: Nullable;\r\n wasmUASTCToRG8_UNORM: Nullable;\r\n jsMSCTranscoder: Nullable;\r\n wasmMSCTranscoder: Nullable;\r\n wasmZSTDDecoder: Nullable;\r\n } = {\r\n jsDecoderModule: \"https://preview.babylonjs.com/babylon.ktx2Decoder.js\",\r\n wasmUASTCToASTC: null,\r\n wasmUASTCToBC7: null,\r\n wasmUASTCToRGBA_UNORM: null,\r\n wasmUASTCToRGBA_SRGB: null,\r\n wasmUASTCToR8_UNORM: null,\r\n wasmUASTCToRG8_UNORM: null,\r\n jsMSCTranscoder: null,\r\n wasmMSCTranscoder: null,\r\n wasmZSTDDecoder: null,\r\n };\r\n\r\n /**\r\n * Default number of workers used to handle data decoding\r\n */\r\n public static DefaultNumWorkers = KhronosTextureContainer2.GetDefaultNumWorkers();\r\n\r\n /**\r\n * Default configuration for the KTX2 decoder.\r\n * The options defined in this way have priority over those passed when creating a KTX2 texture with new Texture(...).\r\n */\r\n public static DefaultDecoderOptions = new DefaultKTX2DecoderOptions();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private _engine: ThinEngine;\r\n\r\n private static _Initialize(numWorkers: number): void {\r\n if (KhronosTextureContainer2._WorkerPoolPromise || KhronosTextureContainer2._DecoderModulePromise) {\r\n return;\r\n }\r\n\r\n const urls = {\r\n jsDecoderModule: Tools.GetAbsoluteUrl(this.URLConfig.jsDecoderModule),\r\n wasmUASTCToASTC: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToASTC),\r\n wasmUASTCToBC7: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToBC7),\r\n wasmUASTCToRGBA_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_UNORM),\r\n wasmUASTCToRGBA_SRGB: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRGBA_SRGB),\r\n wasmUASTCToR8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToR8_UNORM),\r\n wasmUASTCToRG8_UNORM: getAbsoluteUrlOrNull(this.URLConfig.wasmUASTCToRG8_UNORM),\r\n jsMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.jsMSCTranscoder),\r\n wasmMSCTranscoder: getAbsoluteUrlOrNull(this.URLConfig.wasmMSCTranscoder),\r\n wasmZSTDDecoder: getAbsoluteUrlOrNull(this.URLConfig.wasmZSTDDecoder),\r\n };\r\n\r\n if (numWorkers && typeof Worker === \"function\" && typeof URL !== \"undefined\") {\r\n KhronosTextureContainer2._WorkerPoolPromise = new Promise((resolve) => {\r\n const workerContent = `${applyConfig}(${workerFunc})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n resolve(\r\n new AutoReleaseWorkerPool(\r\n numWorkers,\r\n () =>\r\n new Promise((resolve, reject) => {\r\n const worker = new Worker(workerBlobUrl);\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data.action === \"init\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({\r\n action: \"init\",\r\n urls: urls,\r\n });\r\n })\r\n )\r\n );\r\n });\r\n } else if (typeof KTX2DECODER === \"undefined\") {\r\n KhronosTextureContainer2._DecoderModulePromise = Tools.LoadScriptAsync(urls.jsDecoderModule).then(() => {\r\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\r\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\r\n applyConfig(urls);\r\n return new KTX2DECODER.KTX2Decoder();\r\n });\r\n } else {\r\n KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;\r\n KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;\r\n KhronosTextureContainer2._DecoderModulePromise = Promise.resolve(new KTX2DECODER.KTX2Decoder());\r\n }\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param engine The engine to use\r\n * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n public constructor(engine: ThinEngine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {\r\n this._engine = engine;\r\n\r\n KhronosTextureContainer2._Initialize(numWorkers);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): Promise {\r\n const caps = this._engine.getCaps();\r\n\r\n const compressedTexturesCaps: ICompressedFormatCapabilities = {\r\n astc: !!caps.astc,\r\n bptc: !!caps.bptc,\r\n s3tc: !!caps.s3tc,\r\n pvrtc: !!caps.pvrtc,\r\n etc2: !!caps.etc2,\r\n etc1: !!caps.etc1,\r\n };\r\n\r\n if (KhronosTextureContainer2._WorkerPoolPromise) {\r\n return KhronosTextureContainer2._WorkerPoolPromise.then((workerPool) => {\r\n return new Promise((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent) => {\r\n if (message.data.action === \"decoded\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n if (!message.data.success) {\r\n reject({ message: message.data.msg });\r\n } else {\r\n try {\r\n this._createTexture(message.data.decodedData, internalTexture, options);\r\n resolve();\r\n } catch (err) {\r\n reject({ message: err });\r\n }\r\n }\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n worker.postMessage({ action: \"setDefaultDecoderOptions\", options: KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions() });\r\n\r\n const dataCopy = new Uint8Array(data.byteLength);\r\n dataCopy.set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\r\n\r\n worker.postMessage({ action: \"decode\", data: dataCopy, caps: compressedTexturesCaps, options }, [dataCopy.buffer]);\r\n });\r\n });\r\n });\r\n } else if (KhronosTextureContainer2._DecoderModulePromise) {\r\n return KhronosTextureContainer2._DecoderModulePromise.then((decoder) => {\r\n if (KhronosTextureContainer2.DefaultDecoderOptions.isDirty) {\r\n KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions();\r\n }\r\n return new Promise((resolve, reject) => {\r\n decoder\r\n .decode(data, caps)\r\n .then((data: IDecodedData) => {\r\n this._createTexture(data, internalTexture);\r\n resolve();\r\n })\r\n .catch((reason: any) => {\r\n reject({ message: reason });\r\n });\r\n });\r\n });\r\n }\r\n\r\n throw new Error(\"KTX2 decoder module is not available\");\r\n }\r\n\r\n protected _createTexture(data: IDecodedData, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): void {\r\n const oglTexture2D = 3553; // gl.TEXTURE_2D\r\n\r\n this._engine._bindTextureDirectly(oglTexture2D, internalTexture);\r\n\r\n if (options) {\r\n // return back some information about the decoded data\r\n options.transcodedFormat = data.transcodedFormat;\r\n options.isInGammaSpace = data.isInGammaSpace;\r\n options.hasAlpha = data.hasAlpha;\r\n options.transcoderName = data.transcoderName;\r\n }\r\n\r\n let isUncompressedFormat = true;\r\n\r\n switch (data.transcodedFormat) {\r\n case 0x8058 /* RGBA8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n break;\r\n case 0x8229 /* R8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_R;\r\n break;\r\n case 0x822b /* RG8 */:\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RG;\r\n break;\r\n default:\r\n internalTexture.format = data.transcodedFormat;\r\n isUncompressedFormat = false;\r\n break;\r\n }\r\n\r\n internalTexture._gammaSpace = data.isInGammaSpace;\r\n internalTexture.generateMipMaps = data.mipmaps.length > 1;\r\n\r\n if (data.errors) {\r\n throw new Error(\"KTX2 container - could not transcode the data. \" + data.errors);\r\n }\r\n\r\n for (let t = 0; t < data.mipmaps.length; ++t) {\r\n const mipmap = data.mipmaps[t];\r\n\r\n if (!mipmap || !mipmap.data) {\r\n throw new Error(\"KTX2 container - could not transcode one of the image\");\r\n }\r\n\r\n if (isUncompressedFormat) {\r\n // uncompressed RGBA / R8 / RG8\r\n internalTexture.width = mipmap.width; // need to set width/height so that the call to _uploadDataToTextureDirectly uses the right dimensions\r\n internalTexture.height = mipmap.height;\r\n\r\n this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);\r\n } else {\r\n this._engine._uploadCompressedDataToTextureDirectly(internalTexture, data.transcodedFormat, mipmap.width, mipmap.height, mipmap.data, 0, t);\r\n }\r\n }\r\n\r\n internalTexture._extension = \".ktx2\";\r\n internalTexture.width = data.mipmaps[0].width;\r\n internalTexture.height = data.mipmaps[0].height;\r\n internalTexture.isReady = true;\r\n\r\n this._engine._bindTextureDirectly(oglTexture2D, null);\r\n }\r\n\r\n /**\r\n * Checks if the given data starts with a KTX2 file identifier.\r\n * @param data the data to check\r\n * @returns true if the data is a KTX2 file or false otherwise\r\n */\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x32 &&\r\n identifier[6] === 0x30 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction workerFunc(): void {\r\n let ktx2Decoder: any;\r\n\r\n onmessage = (event) => {\r\n if (!event.data) {\r\n return;\r\n }\r\n switch (event.data.action) {\r\n case \"init\": {\r\n const urls = event.data.urls;\r\n importScripts(urls.jsDecoderModule);\r\n applyConfig(urls);\r\n ktx2Decoder = new KTX2DECODER.KTX2Decoder();\r\n postMessage({ action: \"init\" });\r\n break;\r\n }\r\n case \"setDefaultDecoderOptions\": {\r\n KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = event.data.options;\r\n break;\r\n }\r\n case \"decode\":\r\n ktx2Decoder\r\n .decode(event.data.data, event.data.caps, event.data.options)\r\n .then((data: IDecodedData) => {\r\n const buffers = [];\r\n for (let mip = 0; mip < data.mipmaps.length; ++mip) {\r\n const mipmap = data.mipmaps[mip];\r\n if (mipmap && mipmap.data) {\r\n buffers.push(mipmap.data.buffer);\r\n }\r\n }\r\n postMessage({ action: \"decoded\", success: true, decodedData: data }, buffers);\r\n })\r\n .catch((reason: any) => {\r\n postMessage({ action: \"decoded\", success: false, msg: reason });\r\n });\r\n break;\r\n }\r\n };\r\n}\r\n","import { KhronosTextureContainer } from \"../../../Misc/khronosTextureContainer\";\r\nimport { KhronosTextureContainer2 } from \"../../../Misc/khronosTextureContainer2\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { Engine } from \"../../../Engines/engine\";\r\nimport type { InternalTexture } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IInternalTextureLoader } from \"../../../Materials/Textures/internalTextureLoader\";\r\nimport { Logger } from \"../../../Misc/logger\";\r\nimport { Constants } from \"../../../Engines/constants\";\r\n\r\nfunction mapSRGBToLinear(format: number): Nullable {\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4;\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:\r\n return Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM;\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/**\r\n * Implementation of the KTX Texture Loader.\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _KTXTextureLoader implements IInternalTextureLoader {\r\n /**\r\n * Defines whether the loader supports cascade loading the different faces.\r\n */\r\n public readonly supportCascades = false;\r\n\r\n /**\r\n * This returns if the loader support the current file information.\r\n * @param extension defines the file extension of the file being loaded\r\n * @param mimeType defines the optional mime type of the file being loaded\r\n * @returns true if the loader can load the specified file\r\n */\r\n public canLoad(extension: string, mimeType?: string): boolean {\r\n // The \".ktx2\" file extension is still up for debate: https://github.com/KhronosGroup/KTX-Specification/issues/18\r\n return extension.endsWith(\".ktx\") || extension.endsWith(\".ktx2\") || mimeType === \"image/ktx\" || mimeType === \"image/ktx2\";\r\n }\r\n\r\n /**\r\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param createPolynomials will be true if polynomials have been requested\r\n * @param onLoad defines the callback to trigger once the texture is ready\r\n */\r\n public loadCubeData(data: ArrayBufferView | ArrayBufferView[], texture: InternalTexture, createPolynomials: boolean, onLoad: Nullable<(data?: any) => void>): void {\r\n if (Array.isArray(data)) {\r\n return;\r\n }\r\n\r\n // Need to invert vScale as invertY via UNPACK_FLIP_Y_WEBGL is not supported by compressed texture\r\n texture._invertVScale = !texture.invertY;\r\n const engine = texture.getEngine() as Engine;\r\n const ktx = new KhronosTextureContainer(data, 6);\r\n\r\n const loadMipmap = ktx.numberOfMipmapLevels > 1 && texture.generateMipMaps;\r\n\r\n engine._unpackFlipY(true);\r\n\r\n ktx.uploadLevels(texture, texture.generateMipMaps);\r\n\r\n texture.width = ktx.pixelWidth;\r\n texture.height = ktx.pixelHeight;\r\n\r\n engine._setCubeMapTextureParams(texture, loadMipmap, ktx.numberOfMipmapLevels - 1);\r\n texture.isReady = true;\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n }\r\n\r\n /**\r\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param callback defines the method to call once ready to upload\r\n * @param options\r\n */\r\n public loadData(\r\n data: ArrayBufferView,\r\n texture: InternalTexture,\r\n callback: (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void, loadFailed: boolean) => void,\r\n options?: any\r\n ): void {\r\n if (KhronosTextureContainer.IsValid(data)) {\r\n // Need to invert vScale as invertY via UNPACK_FLIP_Y_WEBGL is not supported by compressed texture\r\n texture._invertVScale = !texture.invertY;\r\n const ktx = new KhronosTextureContainer(data, 1);\r\n\r\n const mappedFormat = mapSRGBToLinear(ktx.glInternalFormat);\r\n if (mappedFormat) {\r\n texture.format = mappedFormat;\r\n texture._useSRGBBuffer = texture.getEngine()._getUseSRGBBuffer(true, texture.generateMipMaps);\r\n texture._gammaSpace = true;\r\n } else {\r\n texture.format = ktx.glInternalFormat;\r\n }\r\n\r\n callback(\r\n ktx.pixelWidth,\r\n ktx.pixelHeight,\r\n texture.generateMipMaps,\r\n true,\r\n () => {\r\n ktx.uploadLevels(texture, texture.generateMipMaps);\r\n },\r\n ktx.isInvalid\r\n );\r\n } else if (KhronosTextureContainer2.IsValid(data)) {\r\n const ktx2 = new KhronosTextureContainer2(texture.getEngine());\r\n ktx2.uploadAsync(data, texture, options).then(\r\n () => {\r\n callback(texture.width, texture.height, texture.generateMipMaps, true, () => {}, false);\r\n },\r\n (error) => {\r\n Logger.Warn(`Failed to load KTX2 texture data: ${error.message}`);\r\n callback(0, 0, false, false, () => {}, true);\r\n }\r\n );\r\n } else {\r\n Logger.Error(\"texture missing KTX identifier\");\r\n callback(0, 0, false, false, () => {}, true);\r\n }\r\n }\r\n}\r\n\r\n// Register the loader.\r\nEngine._TextureLoaders.unshift(new _KTXTextureLoader());\r\n","import { Vector3, Matrix, Quaternion, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { FreeCamera } from \"../Cameras/freeCamera\";\r\nimport { TargetCamera } from \"../Cameras/targetCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Viewport } from \"../Maths/math.viewport\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { WebXRTrackingState } from \"./webXRTypes\";\r\n\r\n/**\r\n * WebXR Camera which holds the views for the xrSession\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRCamera\r\n */\r\nexport class WebXRCamera extends FreeCamera {\r\n private static _ScaleReadOnly = Vector3.One();\r\n\r\n private _firstFrame = false;\r\n private _referenceQuaternion: Quaternion = Quaternion.Identity();\r\n private _referencedPosition: Vector3 = new Vector3();\r\n private _trackingState: WebXRTrackingState = WebXRTrackingState.NOT_TRACKING;\r\n\r\n /**\r\n * Observable raised before camera teleportation\r\n */\r\n public onBeforeCameraTeleport = new Observable();\r\n\r\n /**\r\n * Observable raised after camera teleportation\r\n */\r\n public onAfterCameraTeleport = new Observable();\r\n\r\n /**\r\n * Notifies when the camera's tracking state has changed.\r\n * Notice - will also be triggered when tracking has started (at the beginning of the session)\r\n */\r\n public onTrackingStateChanged = new Observable();\r\n /**\r\n * Should position compensation execute on first frame.\r\n * This is used when copying the position from a native (non XR) camera\r\n */\r\n public compensateOnFirstFrame: boolean = true;\r\n\r\n /**\r\n * The last XRViewerPose from the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRViewerPose?: XRViewerPose;\r\n\r\n /**\r\n * Creates a new webXRCamera, this should only be set at the camera after it has been updated by the xrSessionManager\r\n * @param name the name of the camera\r\n * @param scene the scene to add the camera to\r\n * @param _xrSessionManager a constructed xr session manager\r\n */\r\n constructor(name: string, scene: Scene, private _xrSessionManager: WebXRSessionManager) {\r\n super(name, Vector3.Zero(), scene);\r\n\r\n // Initial camera configuration\r\n this.minZ = 0.1;\r\n this.rotationQuaternion = new Quaternion();\r\n this.cameraRigMode = Camera.RIG_MODE_CUSTOM;\r\n this.updateUpVectorFromRotation = true;\r\n this._updateNumberOfRigCameras(1);\r\n // freeze projection matrix, which will be copied later\r\n this.freezeProjectionMatrix();\r\n this._deferOnly = true;\r\n\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this._referencedPosition.copyFromFloats(0, 0, 0);\r\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\r\n // first frame - camera's y position should be 0 for the correct offset\r\n this._firstFrame = this.compensateOnFirstFrame;\r\n });\r\n\r\n // Check transformation changes on each frame. Callback is added to be first so that the transformation will be\r\n // applied to the rest of the elements using the referenceSpace object\r\n this._xrSessionManager.onXRFrameObservable.add(\r\n () => {\r\n if (this._firstFrame) {\r\n this._updateFromXRSession();\r\n }\r\n\r\n if (this._deferredUpdated) {\r\n this.position.copyFrom(this._deferredPositionUpdate);\r\n this.rotationQuaternion.copyFrom(this._deferredRotationQuaternionUpdate);\r\n }\r\n\r\n this._updateReferenceSpace();\r\n this._updateFromXRSession();\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n\r\n /**\r\n * Get the current XR tracking state of the camera\r\n */\r\n public get trackingState(): WebXRTrackingState {\r\n return this._trackingState;\r\n }\r\n\r\n private _setTrackingState(newState: WebXRTrackingState) {\r\n if (this._trackingState !== newState) {\r\n this._trackingState = newState;\r\n this.onTrackingStateChanged.notifyObservers(newState);\r\n }\r\n }\r\n\r\n /**\r\n * Return the user's height, unrelated to the current ground.\r\n * This will be the y position of this camera, when ground level is 0.\r\n */\r\n public get realWorldHeight(): number {\r\n const basePose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.baseReferenceSpace);\r\n if (basePose && basePose.transform) {\r\n return basePose.transform.position.y;\r\n } else {\r\n return 0;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _updateForDualEyeDebugging(/*pupilDistance = 0.01*/) {\r\n // Create initial camera rigs\r\n this._updateNumberOfRigCameras(2);\r\n this.rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);\r\n // this.rigCameras[0].position.x = -pupilDistance / 2;\r\n this.rigCameras[0].outputRenderTarget = null;\r\n this.rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);\r\n // this.rigCameras[1].position.x = pupilDistance / 2;\r\n this.rigCameras[1].outputRenderTarget = null;\r\n }\r\n\r\n /**\r\n * Sets this camera's transformation based on a non-vr camera\r\n * @param otherCamera the non-vr camera to copy the transformation from\r\n * @param resetToBaseReferenceSpace should XR reset to the base reference space\r\n */\r\n public setTransformationFromNonVRCamera(otherCamera: Camera = this.getScene().activeCamera!, resetToBaseReferenceSpace: boolean = true) {\r\n if (!otherCamera || otherCamera === this) {\r\n return;\r\n }\r\n const mat = otherCamera.computeWorldMatrix();\r\n mat.decompose(undefined, this.rotationQuaternion, this.position);\r\n // set the ground level\r\n this.position.y = 0;\r\n Quaternion.FromEulerAnglesToRef(0, this.rotationQuaternion.toEulerAngles().y, 0, this.rotationQuaternion);\r\n this._firstFrame = true;\r\n if (resetToBaseReferenceSpace) {\r\n this._xrSessionManager.resetReferenceSpace();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current instance class name (\"WebXRCamera\").\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"WebXRCamera\";\r\n }\r\n\r\n /**\r\n * Set the target for the camera to look at.\r\n * Note that this only rotates around the Y axis, as opposed to the default behavior of other cameras\r\n * @param target the target to set the camera to look at\r\n */\r\n public setTarget(target: Vector3): void {\r\n // only rotate around the y axis!\r\n const tmpVector = TmpVectors.Vector3[1];\r\n target.subtractToRef(this.position, tmpVector);\r\n tmpVector.y = 0;\r\n tmpVector.normalize();\r\n const yRotation = Math.atan2(tmpVector.x, tmpVector.z);\r\n this.rotationQuaternion.toEulerAnglesToRef(tmpVector);\r\n Quaternion.FromEulerAnglesToRef(tmpVector.x, yRotation, tmpVector.z, this.rotationQuaternion);\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n this._lastXRViewerPose = undefined;\r\n }\r\n\r\n private _rotate180 = new Quaternion(0, 1, 0, 0);\r\n\r\n private _updateFromXRSession() {\r\n const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n this._lastXRViewerPose = pose || undefined;\r\n if (!pose) {\r\n this._setTrackingState(WebXRTrackingState.NOT_TRACKING);\r\n return;\r\n }\r\n\r\n // Set the tracking state. if it didn't change it is a no-op\r\n const trackingState = pose.emulatedPosition ? WebXRTrackingState.TRACKING_LOST : WebXRTrackingState.TRACKING;\r\n this._setTrackingState(trackingState);\r\n\r\n // check min/max Z and update if not the same as in cache\r\n if (this.minZ !== this._cache.minZ || this.maxZ !== this._cache.maxZ) {\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.maxZ || 10000,\r\n depthNear: this.minZ,\r\n };\r\n\r\n this._xrSessionManager.updateRenderState(xrRenderState);\r\n this._cache.minZ = this.minZ;\r\n this._cache.maxZ = this.maxZ;\r\n }\r\n\r\n if (pose.transform) {\r\n const orientation = pose.transform.orientation;\r\n if (pose.transform.orientation.x === undefined) {\r\n // Babylon native polyfill can return an undefined orientation value\r\n // When not initialized\r\n return;\r\n }\r\n const pos = pose.transform.position;\r\n this._referencedPosition.set(pos.x, pos.y, pos.z);\r\n\r\n this._referenceQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this._referencedPosition.z *= -1;\r\n this._referenceQuaternion.z *= -1;\r\n this._referenceQuaternion.w *= -1;\r\n }\r\n\r\n if (this._firstFrame) {\r\n this._firstFrame = false;\r\n // we have the XR reference, now use this to find the offset to get the camera to be\r\n // in the right position\r\n\r\n // set the height to correlate to the current height\r\n this.position.y += this._referencedPosition.y;\r\n // avoid using the head rotation on the first frame.\r\n this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);\r\n } else {\r\n // update position and rotation as reference\r\n this.rotationQuaternion.copyFrom(this._referenceQuaternion);\r\n this.position.copyFrom(this._referencedPosition);\r\n }\r\n }\r\n\r\n // Update camera rigs\r\n if (this.rigCameras.length !== pose.views.length) {\r\n this._updateNumberOfRigCameras(pose.views.length);\r\n }\r\n\r\n pose.views.forEach((view: XRView, i: number) => {\r\n const currentRig = this.rigCameras[i];\r\n // update right and left, where applicable\r\n if (!currentRig.isLeftCamera && !currentRig.isRightCamera) {\r\n if (view.eye === \"right\") {\r\n currentRig._isRightCamera = true;\r\n } else if (view.eye === \"left\") {\r\n currentRig._isLeftCamera = true;\r\n }\r\n }\r\n // Update view/projection matrix\r\n const pos = view.transform.position;\r\n const orientation = view.transform.orientation;\r\n\r\n currentRig.parent = this.parent;\r\n\r\n currentRig.position.set(pos.x, pos.y, pos.z);\r\n currentRig.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n currentRig.position.z *= -1;\r\n currentRig.rotationQuaternion.z *= -1;\r\n currentRig.rotationQuaternion.w *= -1;\r\n } else {\r\n currentRig.rotationQuaternion.multiplyInPlace(this._rotate180);\r\n }\r\n Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, currentRig._projectionMatrix);\r\n\r\n if (!this._scene.useRightHandedSystem) {\r\n currentRig._projectionMatrix.toggleProjectionMatrixHandInPlace();\r\n }\r\n\r\n // first camera?\r\n if (i === 0) {\r\n this._projectionMatrix.copyFrom(currentRig._projectionMatrix);\r\n }\r\n\r\n const renderTargetTexture = this._xrSessionManager.getRenderTargetTextureForView(view);\r\n this._renderingMultiview = renderTargetTexture?._texture?.isMultiview || false;\r\n if (this._renderingMultiview) {\r\n // For multiview, the render target texture is the same per-view (just the slice index is different),\r\n // so we only need to set the output render target once for the rig parent.\r\n if (i == 0) {\r\n this._xrSessionManager.trySetViewportForView(this.viewport, view);\r\n this.outputRenderTarget = renderTargetTexture;\r\n }\r\n } else {\r\n // Update viewport\r\n this._xrSessionManager.trySetViewportForView(currentRig.viewport, view);\r\n\r\n // Set cameras to render to the session's render target\r\n currentRig.outputRenderTarget = renderTargetTexture || this._xrSessionManager.getRenderTargetTextureForView(view);\r\n }\r\n\r\n // Replicate parent rig camera behavior\r\n currentRig.layerMask = this.layerMask;\r\n });\r\n }\r\n\r\n private _updateNumberOfRigCameras(viewCount = 1) {\r\n while (this.rigCameras.length < viewCount) {\r\n const newCamera = new TargetCamera(\"XR-RigCamera: \" + this.rigCameras.length, Vector3.Zero(), this.getScene());\r\n newCamera.minZ = 0.1;\r\n newCamera.rotationQuaternion = new Quaternion();\r\n newCamera.updateUpVectorFromRotation = true;\r\n newCamera.isRigCamera = true;\r\n newCamera.rigParent = this;\r\n // do not compute projection matrix, provided by XR\r\n newCamera.freezeProjectionMatrix();\r\n this.rigCameras.push(newCamera);\r\n }\r\n while (this.rigCameras.length > viewCount) {\r\n const removedCamera = this.rigCameras.pop();\r\n if (removedCamera) {\r\n removedCamera.dispose();\r\n }\r\n }\r\n }\r\n\r\n private _updateReferenceSpace() {\r\n // were position & rotation updated OUTSIDE of the xr update loop\r\n if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {\r\n const referencedMat = TmpVectors.Matrix[0];\r\n const poseMat = TmpVectors.Matrix[1];\r\n const transformMat = TmpVectors.Matrix[2];\r\n\r\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this._referenceQuaternion, this._referencedPosition, referencedMat);\r\n Matrix.ComposeToRef(WebXRCamera._ScaleReadOnly, this.rotationQuaternion, this.position, poseMat);\r\n referencedMat.invert().multiplyToRef(poseMat, transformMat);\r\n transformMat.invert();\r\n\r\n if (!this._scene.useRightHandedSystem) {\r\n transformMat.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n transformMat.decompose(undefined, this._referenceQuaternion, this._referencedPosition);\r\n const transform = new XRRigidTransform(\r\n {\r\n x: this._referencedPosition.x,\r\n y: this._referencedPosition.y,\r\n z: this._referencedPosition.z,\r\n },\r\n {\r\n x: this._referenceQuaternion.x,\r\n y: this._referenceQuaternion.y,\r\n z: this._referenceQuaternion.z,\r\n w: this._referenceQuaternion.w,\r\n }\r\n );\r\n this._xrSessionManager.referenceSpace = this._xrSessionManager.referenceSpace.getOffsetReferenceSpace(transform);\r\n }\r\n }\r\n}\r\n","import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\";\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\";\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\";\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\";\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\";\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\";\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\";\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\";\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\";\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\";\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\";\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\";\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\";\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\";\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\";\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\";\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\";\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\";\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\";\r\n /**\r\n * The name of the WebXR Space Warp feature\r\n */\r\n public static readonly SPACE_WARP = \"xr-space-warp\";\r\n}\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n });\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n feature.featureImplementation.attach();\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n feature.featureImplementation.detach();\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n this.getEnabledFeatures().forEach((feature) => {\r\n this.disableFeature(feature);\r\n });\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: string | { Name: string },\r\n version: number | string = \"latest\",\r\n moduleOptions: any = {},\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): IWebXRFeature {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature(featureName: string): IWebXRFeature {\r\n return this._features[featureName] && this._features[featureName].featureImplementation;\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n","import { FreeCamera } from \"./freeCamera\";\r\nimport type { FreeCameraTouchInput } from \"../Cameras/Inputs/freeCameraTouchInput\";\r\nimport type { FreeCameraMouseInput } from \"../Cameras/Inputs/freeCameraMouseInput\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\n\r\nNode.AddNodeConstructor(\"TouchCamera\", (name, scene) => {\r\n return () => new TouchCamera(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * This represents a FPS type of camera controlled by touch.\r\n * This is like a universal camera minus the Gamepad controls.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\r\n */\r\nexport class TouchCamera extends FreeCamera {\r\n /**\r\n * Defines the touch sensibility for rotation.\r\n * The higher the faster.\r\n */\r\n public get touchAngularSensibility(): number {\r\n const touch = this.inputs.attached[\"touch\"];\r\n if (touch) {\r\n return touch.touchAngularSensibility;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set touchAngularSensibility(value: number) {\r\n const touch = this.inputs.attached[\"touch\"];\r\n if (touch) {\r\n touch.touchAngularSensibility = value;\r\n }\r\n }\r\n\r\n /**\r\n * Defines the touch sensibility for move.\r\n * The higher the faster.\r\n */\r\n public get touchMoveSensibility(): number {\r\n const touch = this.inputs.attached[\"touch\"];\r\n if (touch) {\r\n return touch.touchMoveSensibility;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set touchMoveSensibility(value: number) {\r\n const touch = this.inputs.attached[\"touch\"];\r\n if (touch) {\r\n touch.touchMoveSensibility = value;\r\n }\r\n }\r\n\r\n /**\r\n * Instantiates a new touch camera.\r\n * This represents a FPS type of camera controlled by touch.\r\n * This is like a universal camera minus the Gamepad controls.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\r\n * @param name Define the name of the camera in the scene\r\n * @param position Define the start position of the camera in the scene\r\n * @param scene Define the scene the camera belongs to\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene) {\r\n super(name, position, scene);\r\n this.inputs.addTouch();\r\n\r\n this._setupInputs();\r\n }\r\n\r\n /**\r\n * Gets the current object class name.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"TouchCamera\";\r\n }\r\n\r\n /** @internal */\r\n public _setupInputs() {\r\n const touch = this.inputs.attached[\"touch\"];\r\n const mouse = this.inputs.attached[\"mouse\"];\r\n if (mouse) {\r\n mouse.touchEnabled = false;\r\n } else {\r\n touch.allowMouse = true;\r\n }\r\n }\r\n}\r\n","import { TouchCamera } from \"./touchCamera\";\r\nimport { Node } from \"../node\";\r\nimport type { FreeCameraGamepadInput } from \"../Cameras/Inputs/freeCameraGamepadInput\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Camera } from \"./camera\";\r\n\r\nimport \"../Gamepads/gamepadSceneComponent\";\r\n\r\nNode.AddNodeConstructor(\"FreeCamera\", (name, scene) => {\r\n // Forcing to use the Universal camera\r\n return () => new UniversalCamera(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * The Universal Camera is the one to choose for first person shooter type games, and works with all the keyboard, mouse, touch and gamepads. This replaces the earlier Free Camera,\r\n * which still works and will still be found in many Playgrounds.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\r\n */\r\nexport class UniversalCamera extends TouchCamera {\r\n /**\r\n * Defines the gamepad rotation sensibility.\r\n * This is the threshold from when rotation starts to be accounted for to prevent jittering.\r\n */\r\n public get gamepadAngularSensibility(): number {\r\n const gamepad = this.inputs.attached[\"gamepad\"];\r\n if (gamepad) {\r\n return gamepad.gamepadAngularSensibility;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set gamepadAngularSensibility(value: number) {\r\n const gamepad = this.inputs.attached[\"gamepad\"];\r\n if (gamepad) {\r\n gamepad.gamepadAngularSensibility = value;\r\n }\r\n }\r\n\r\n /**\r\n * Defines the gamepad move sensibility.\r\n * This is the threshold from when moving starts to be accounted for to prevent jittering.\r\n */\r\n public get gamepadMoveSensibility(): number {\r\n const gamepad = this.inputs.attached[\"gamepad\"];\r\n if (gamepad) {\r\n return gamepad.gamepadMoveSensibility;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n public set gamepadMoveSensibility(value: number) {\r\n const gamepad = this.inputs.attached[\"gamepad\"];\r\n if (gamepad) {\r\n gamepad.gamepadMoveSensibility = value;\r\n }\r\n }\r\n\r\n /**\r\n * The Universal Camera is the one to choose for first person shooter type games, and works with all the keyboard, mouse, touch and gamepads. This replaces the earlier Free Camera,\r\n * which still works and will still be found in many Playgrounds.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera\r\n * @param name Define the name of the camera in the scene\r\n * @param position Define the start position of the camera in the scene\r\n * @param scene Define the scene the camera belongs to\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene) {\r\n super(name, position, scene);\r\n this.inputs.addGamepad();\r\n }\r\n\r\n /**\r\n * Gets the current object class name.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"UniversalCamera\";\r\n }\r\n}\r\n\r\nCamera._CreateDefaultParsedCamera = (name: string, scene: Scene) => {\r\n return new UniversalCamera(name, Vector3.Zero(), scene);\r\n};\r\n","import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"./webXRFeaturesManager\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { UniversalCamera } from \"../Cameras/universalCamera\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\nexport interface WebXRSpectatorModeOption {\r\n /**\r\n * Expected refresh rate (frames per sec) for a spectator camera.\r\n */\r\n fps?: number;\r\n /**\r\n * The index of rigCameras array in a WebXR camera.\r\n */\r\n preferredCameraIndex?: number;\r\n}\r\n\r\n/**\r\n * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers\r\n */\r\nexport class WebXRExperienceHelper implements IDisposable {\r\n private _nonVRCamera: Nullable = null;\r\n private _attachedToElement: boolean = false;\r\n private _spectatorCamera: Nullable = null;\r\n private _originalSceneAutoClear = true;\r\n private _supported = false;\r\n private _spectatorMode = false;\r\n private _lastTimestamp = 0;\r\n\r\n /**\r\n * Camera used to render xr content\r\n */\r\n public camera: WebXRCamera;\r\n /** A features manager for this xr session */\r\n public featuresManager: WebXRFeaturesManager;\r\n /**\r\n * Observers registered here will be triggered after the camera's initial transformation is set\r\n * This can be used to set a different ground level or an extra rotation.\r\n *\r\n * Note that ground level is considered to be at 0. The height defined by the XR camera will be added\r\n * to the position set after this observable is done executing.\r\n */\r\n public onInitialXRPoseSetObservable = new Observable();\r\n /**\r\n * Fires when the state of the experience helper has changed\r\n */\r\n public onStateChangedObservable = new Observable();\r\n /** Session manager used to keep track of xr session */\r\n public sessionManager: WebXRSessionManager;\r\n /**\r\n * The current state of the XR experience (eg. transitioning, in XR or not in XR)\r\n */\r\n public state: WebXRState = WebXRState.NOT_IN_XR;\r\n\r\n /**\r\n * Creates a WebXRExperienceHelper\r\n * @param _scene The scene the helper should be created in\r\n */\r\n private constructor(private _scene: Scene) {\r\n this.sessionManager = new WebXRSessionManager(_scene);\r\n this.camera = new WebXRCamera(\"webxr\", _scene, this.sessionManager);\r\n this.featuresManager = new WebXRFeaturesManager(this.sessionManager);\r\n\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Creates the experience helper\r\n * @param scene the scene to attach the experience helper to\r\n * @returns a promise for the experience helper\r\n */\r\n public static CreateAsync(scene: Scene): Promise {\r\n const helper = new WebXRExperienceHelper(scene);\r\n return helper.sessionManager\r\n .initializeAsync()\r\n .then(() => {\r\n helper._supported = true;\r\n return helper;\r\n })\r\n .catch((e) => {\r\n helper._setState(WebXRState.NOT_IN_XR);\r\n helper.dispose();\r\n throw e;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n this.exitXRAsync();\r\n this.camera.dispose();\r\n this.onStateChangedObservable.clear();\r\n this.onInitialXRPoseSetObservable.clear();\r\n this.sessionManager.dispose();\r\n this._spectatorCamera?.dispose();\r\n if (this._nonVRCamera) {\r\n this._scene.activeCamera = this._nonVRCamera;\r\n }\r\n }\r\n\r\n /**\r\n * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)\r\n * @param sessionMode options for the XR session\r\n * @param referenceSpaceType frame of reference of the XR session\r\n * @param renderTarget the output canvas that will be used to enter XR mode\r\n * @param sessionCreationOptions optional XRSessionInit object to init the session with\r\n * @returns promise that resolves after xr mode has entered\r\n */\r\n public async enterXRAsync(\r\n sessionMode: XRSessionMode,\r\n referenceSpaceType: XRReferenceSpaceType,\r\n renderTarget: WebXRRenderTarget = this.sessionManager.getWebXRRenderTarget(),\r\n sessionCreationOptions: XRSessionInit = {}\r\n ): Promise {\r\n if (!this._supported) {\r\n throw \"WebXR not supported in this browser or environment\";\r\n }\r\n this._setState(WebXRState.ENTERING_XR);\r\n if (referenceSpaceType !== \"viewer\" && referenceSpaceType !== \"local\") {\r\n sessionCreationOptions.optionalFeatures = sessionCreationOptions.optionalFeatures || [];\r\n sessionCreationOptions.optionalFeatures.push(referenceSpaceType);\r\n }\r\n sessionCreationOptions = await this.featuresManager._extendXRSessionInitObject(sessionCreationOptions);\r\n // we currently recommend \"unbounded\" space in AR (#7959)\r\n if (sessionMode === \"immersive-ar\" && referenceSpaceType !== \"unbounded\") {\r\n Logger.Warn(\"We recommend using 'unbounded' reference space type when using 'immersive-ar' session mode\");\r\n }\r\n // make sure that the session mode is supported\r\n try {\r\n await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);\r\n await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);\r\n const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);\r\n\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.camera.maxZ || 10000,\r\n depthNear: this.camera.minZ,\r\n };\r\n\r\n // The layers feature will have already initialized the xr session's layers on session init.\r\n if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {\r\n xrRenderState.baseLayer = baseLayer;\r\n }\r\n\r\n this.sessionManager.updateRenderState(xrRenderState);\r\n // run the render loop\r\n this.sessionManager.runXRRenderLoop();\r\n // Cache pre xr scene settings\r\n this._originalSceneAutoClear = this._scene.autoClear;\r\n this._nonVRCamera = this._scene.activeCamera;\r\n this._attachedToElement = !!this._nonVRCamera?.inputs?.attachedToElement;\r\n this._nonVRCamera?.detachControl();\r\n\r\n this._scene.activeCamera = this.camera;\r\n // do not compensate when AR session is used\r\n if (sessionMode !== \"immersive-ar\") {\r\n this._nonXRToXRCamera();\r\n } else {\r\n // Kept here, TODO - check if needed\r\n this._scene.autoClear = false;\r\n this.camera.compensateOnFirstFrame = false;\r\n // reset the camera's position to the origin\r\n this.camera.position.set(0, 0, 0);\r\n this.camera.rotationQuaternion.set(0, 0, 0, 1);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n this.sessionManager.onXRSessionEnded.addOnce(() => {\r\n // when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set\r\n if (this.state !== WebXRState.EXITING_XR) {\r\n this._setState(WebXRState.EXITING_XR);\r\n }\r\n // Reset camera rigs output render target to ensure sessions render target is not drawn after it ends\r\n this.camera.rigCameras.forEach((c) => {\r\n c.outputRenderTarget = null;\r\n });\r\n\r\n // Restore scene settings\r\n this._scene.autoClear = this._originalSceneAutoClear;\r\n this._scene.activeCamera = this._nonVRCamera;\r\n if (this._attachedToElement && this._nonVRCamera) {\r\n this._nonVRCamera.attachControl(!!this._nonVRCamera.inputs.noPreventDefault);\r\n }\r\n if (sessionMode !== \"immersive-ar\" && this.camera.compensateOnFirstFrame) {\r\n if ((this._nonVRCamera).setPosition) {\r\n (this._nonVRCamera).setPosition(this.camera.position);\r\n } else {\r\n this._nonVRCamera!.position.copyFrom(this.camera.position);\r\n }\r\n }\r\n\r\n this._setState(WebXRState.NOT_IN_XR);\r\n });\r\n\r\n // Wait until the first frame arrives before setting state to in xr\r\n this.sessionManager.onXRFrameObservable.addOnce(() => {\r\n this._setState(WebXRState.IN_XR);\r\n });\r\n return this.sessionManager;\r\n } catch (e) {\r\n console.log(e);\r\n console.log(e.message);\r\n this._setState(WebXRState.NOT_IN_XR);\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Exits XR mode and returns the scene to its original state\r\n * @returns promise that resolves after xr mode has exited\r\n */\r\n public exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return Promise.resolve();\r\n }\r\n this._setState(WebXRState.EXITING_XR);\r\n return this.sessionManager.exitXRAsync();\r\n }\r\n\r\n /**\r\n * Enable spectator mode for desktop VR experiences.\r\n * When spectator mode is enabled a camera will be attached to the desktop canvas and will\r\n * display the first rig camera's view on the desktop canvas.\r\n * Please note that this will degrade performance, as it requires another camera render.\r\n * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.\r\n * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.\r\n */\r\n public enableSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n if (!this._spectatorMode) {\r\n this._spectatorMode = true;\r\n this._switchSpectatorMode(options);\r\n }\r\n }\r\n\r\n /**\r\n * Disable spectator mode for desktop VR experiences.\r\n */\r\n public disableSpecatatorMode(): void {\r\n if (this._spectatorMode) {\r\n this._spectatorMode = false;\r\n this._switchSpectatorMode();\r\n }\r\n }\r\n\r\n private _switchSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n const fps = options?.fps ? options.fps : 1000.0;\r\n const refreshRate = (1.0 / fps) * 1000.0;\r\n const cameraIndex = options?.preferredCameraIndex ? options?.preferredCameraIndex : 0;\r\n\r\n const updateSpectatorCamera = () => {\r\n if (this._spectatorCamera) {\r\n const delta = this.sessionManager.currentTimestamp - this._lastTimestamp;\r\n if (delta >= refreshRate) {\r\n this._lastTimestamp = this.sessionManager.currentTimestamp;\r\n this._spectatorCamera.position.copyFrom(this.camera.rigCameras[cameraIndex].globalPosition);\r\n this._spectatorCamera.rotationQuaternion.copyFrom(this.camera.rigCameras[cameraIndex].absoluteRotation);\r\n }\r\n }\r\n };\r\n if (this._spectatorMode) {\r\n if (cameraIndex >= this.camera.rigCameras.length) {\r\n throw new Error(\"the preferred camera index is beyond the length of rig camera array.\");\r\n }\r\n const onStateChanged = () => {\r\n if (this.state === WebXRState.IN_XR) {\r\n this._spectatorCamera = new UniversalCamera(\"webxr-spectator\", Vector3.Zero(), this._scene);\r\n this._spectatorCamera.rotationQuaternion = new Quaternion();\r\n this._scene.activeCameras = [this.camera, this._spectatorCamera];\r\n this.sessionManager.onXRFrameObservable.add(updateSpectatorCamera);\r\n this._scene.onAfterRenderCameraObservable.add((camera) => {\r\n if (camera === this.camera) {\r\n // reset the dimensions object for correct resizing\r\n this._scene.getEngine().framebufferDimensionsObject = null;\r\n }\r\n });\r\n } else if (this.state === WebXRState.EXITING_XR) {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = null;\r\n }\r\n };\r\n this.onStateChangedObservable.add(onStateChanged);\r\n onStateChanged();\r\n } else {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = [this.camera];\r\n }\r\n }\r\n\r\n private _nonXRToXRCamera() {\r\n this.camera.setTransformationFromNonVRCamera(this._nonVRCamera!);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n private _setState(val: WebXRState) {\r\n if (this.state === val) {\r\n return;\r\n }\r\n this.state = val;\r\n this.onStateChangedObservable.notifyObservers(this.state);\r\n }\r\n}\r\n","import type { IMinimalMotionControllerObject, MotionControllerComponentType } from \"./webXRAbstractMotionController\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { IDisposable } from \"../../scene\";\r\n\r\n/**\r\n * X-Y values for axes in WebXR\r\n */\r\nexport interface IWebXRMotionControllerAxesValue {\r\n /**\r\n * The value of the x axis\r\n */\r\n x: number;\r\n /**\r\n * The value of the y-axis\r\n */\r\n y: number;\r\n}\r\n\r\n/**\r\n * changed / previous values for the values of this component\r\n */\r\nexport interface IWebXRMotionControllerComponentChangesValues {\r\n /**\r\n * current (this frame) value\r\n */\r\n current: T;\r\n /**\r\n * previous (last change) value\r\n */\r\n previous: T;\r\n}\r\n\r\n/**\r\n * Represents changes in the component between current frame and last values recorded\r\n */\r\nexport interface IWebXRMotionControllerComponentChanges {\r\n /**\r\n * will be populated with previous and current values if axes changed\r\n */\r\n axes?: IWebXRMotionControllerComponentChangesValues;\r\n /**\r\n * will be populated with previous and current values if pressed changed\r\n */\r\n pressed?: IWebXRMotionControllerComponentChangesValues;\r\n /**\r\n * will be populated with previous and current values if touched changed\r\n */\r\n touched?: IWebXRMotionControllerComponentChangesValues;\r\n /**\r\n * will be populated with previous and current values if value changed\r\n */\r\n value?: IWebXRMotionControllerComponentChangesValues;\r\n}\r\n/**\r\n * This class represents a single component (for example button or thumbstick) of a motion controller\r\n */\r\nexport class WebXRControllerComponent implements IDisposable {\r\n private _axes: IWebXRMotionControllerAxesValue = {\r\n x: 0,\r\n y: 0,\r\n };\r\n private _changes: IWebXRMotionControllerComponentChanges = {};\r\n private _currentValue: number = 0;\r\n private _hasChanges: boolean = false;\r\n private _pressed: boolean = false;\r\n private _touched: boolean = false;\r\n\r\n /**\r\n * button component type\r\n */\r\n public static BUTTON_TYPE: MotionControllerComponentType = \"button\";\r\n /**\r\n * squeeze component type\r\n */\r\n public static SQUEEZE_TYPE: MotionControllerComponentType = \"squeeze\";\r\n /**\r\n * Thumbstick component type\r\n */\r\n public static THUMBSTICK_TYPE: MotionControllerComponentType = \"thumbstick\";\r\n /**\r\n * Touchpad component type\r\n */\r\n public static TOUCHPAD_TYPE: MotionControllerComponentType = \"touchpad\";\r\n /**\r\n * trigger component type\r\n */\r\n public static TRIGGER_TYPE: MotionControllerComponentType = \"trigger\";\r\n\r\n /**\r\n * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when\r\n * the axes data changes\r\n */\r\n public onAxisValueChangedObservable: Observable<{ x: number; y: number }> = new Observable();\r\n /**\r\n * Observers registered here will be triggered when the state of a button changes\r\n * State change is either pressed / touched / value\r\n */\r\n public onButtonStateChangedObservable: Observable = new Observable();\r\n\r\n /**\r\n * Creates a new component for a motion controller.\r\n * It is created by the motion controller itself\r\n *\r\n * @param id the id of this component\r\n * @param type the type of the component\r\n * @param _buttonIndex index in the buttons array of the gamepad\r\n * @param _axesIndices indices of the values in the axes array of the gamepad\r\n */\r\n constructor(\r\n /**\r\n * the id of this component\r\n */\r\n public id: string,\r\n /**\r\n * the type of the component\r\n */\r\n public type: MotionControllerComponentType,\r\n private _buttonIndex: number = -1,\r\n private _axesIndices: number[] = []\r\n ) {}\r\n\r\n /**\r\n * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }\r\n */\r\n public get axes(): IWebXRMotionControllerAxesValue {\r\n return this._axes;\r\n }\r\n\r\n /**\r\n * Get the changes. Elements will be populated only if they changed with their previous and current value\r\n */\r\n public get changes(): IWebXRMotionControllerComponentChanges {\r\n return this._changes;\r\n }\r\n\r\n /**\r\n * Return whether or not the component changed the last frame\r\n */\r\n public get hasChanges(): boolean {\r\n return this._hasChanges;\r\n }\r\n\r\n /**\r\n * is the button currently pressed\r\n */\r\n public get pressed(): boolean {\r\n return this._pressed;\r\n }\r\n\r\n /**\r\n * is the button currently touched\r\n */\r\n public get touched(): boolean {\r\n return this._touched;\r\n }\r\n\r\n /**\r\n * Get the current value of this component\r\n */\r\n public get value(): number {\r\n return this._currentValue;\r\n }\r\n\r\n /**\r\n * Dispose this component\r\n */\r\n public dispose(): void {\r\n this.onAxisValueChangedObservable.clear();\r\n this.onButtonStateChangedObservable.clear();\r\n }\r\n\r\n /**\r\n * Are there axes correlating to this component\r\n * @returns true is axes data is available\r\n */\r\n public isAxes(): boolean {\r\n return this._axesIndices.length !== 0;\r\n }\r\n\r\n /**\r\n * Is this component a button (hence - pressable)\r\n * @returns true if can be pressed\r\n */\r\n public isButton(): boolean {\r\n return this._buttonIndex !== -1;\r\n }\r\n\r\n /**\r\n * update this component using the gamepad object it is in. Called on every frame\r\n * @param nativeController the native gamepad controller object\r\n */\r\n public update(nativeController: IMinimalMotionControllerObject) {\r\n let buttonUpdated = false;\r\n let axesUpdate = false;\r\n this._hasChanges = false;\r\n this._changes = {};\r\n\r\n if (this.isButton()) {\r\n const button = nativeController.buttons[this._buttonIndex];\r\n // defensive, in case a profile was forced\r\n if (!button) {\r\n return;\r\n }\r\n if (this._currentValue !== button.value) {\r\n this.changes.value = {\r\n current: button.value,\r\n previous: this._currentValue,\r\n };\r\n buttonUpdated = true;\r\n this._currentValue = button.value;\r\n }\r\n if (this._touched !== button.touched) {\r\n this.changes.touched = {\r\n current: button.touched,\r\n previous: this._touched,\r\n };\r\n buttonUpdated = true;\r\n this._touched = button.touched;\r\n }\r\n if (this._pressed !== button.pressed) {\r\n this.changes.pressed = {\r\n current: button.pressed,\r\n previous: this._pressed,\r\n };\r\n buttonUpdated = true;\r\n this._pressed = button.pressed;\r\n }\r\n }\r\n\r\n if (this.isAxes()) {\r\n if (this._axes.x !== nativeController.axes[this._axesIndices[0]]) {\r\n this.changes.axes = {\r\n current: {\r\n x: nativeController.axes[this._axesIndices[0]],\r\n y: this._axes.y,\r\n },\r\n previous: {\r\n x: this._axes.x,\r\n y: this._axes.y,\r\n },\r\n };\r\n this._axes.x = nativeController.axes[this._axesIndices[0]];\r\n axesUpdate = true;\r\n }\r\n\r\n if (this._axes.y !== nativeController.axes[this._axesIndices[1]]) {\r\n if (this.changes.axes) {\r\n this.changes.axes.current.y = nativeController.axes[this._axesIndices[1]];\r\n } else {\r\n this.changes.axes = {\r\n current: {\r\n x: this._axes.x,\r\n y: nativeController.axes[this._axesIndices[1]],\r\n },\r\n previous: {\r\n x: this._axes.x,\r\n y: this._axes.y,\r\n },\r\n };\r\n }\r\n this._axes.y = nativeController.axes[this._axesIndices[1]];\r\n axesUpdate = true;\r\n }\r\n }\r\n\r\n if (buttonUpdated) {\r\n this._hasChanges = true;\r\n this.onButtonStateChangedObservable.notifyObservers(this);\r\n }\r\n if (axesUpdate) {\r\n this._hasChanges = true;\r\n this.onAxisValueChangedObservable.notifyObservers(this._axes);\r\n }\r\n }\r\n}\r\n","import type { IDisposable, Scene } from \"../../scene\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\n\r\n/**\r\n * Handedness type in xrInput profiles. These can be used to define layouts in the Layout Map.\r\n */\r\nexport type MotionControllerHandedness = \"none\" | \"left\" | \"right\";\r\n/**\r\n * The type of components available in motion controllers.\r\n * This is not the name of the component.\r\n */\r\nexport type MotionControllerComponentType = \"trigger\" | \"squeeze\" | \"touchpad\" | \"thumbstick\" | \"button\";\r\n\r\n/**\r\n * The state of a controller component\r\n */\r\nexport type MotionControllerComponentStateType = \"default\" | \"touched\" | \"pressed\";\r\n\r\n/**\r\n * The schema of motion controller layout.\r\n * No object will be initialized using this interface\r\n * This is used just to define the profile.\r\n */\r\nexport interface IMotionControllerLayout {\r\n /**\r\n * Path to load the assets. Usually relative to the base path\r\n */\r\n assetPath: string;\r\n /**\r\n * Available components (unsorted)\r\n */\r\n components: {\r\n /**\r\n * A map of component Ids\r\n */\r\n [componentId: string]: {\r\n /**\r\n * The type of input the component outputs\r\n */\r\n type: MotionControllerComponentType;\r\n /**\r\n * The indices of this component in the gamepad object\r\n */\r\n gamepadIndices: {\r\n /**\r\n * Index of button\r\n */\r\n button?: number;\r\n /**\r\n * If available, index of x-axis\r\n */\r\n xAxis?: number;\r\n /**\r\n * If available, index of y-axis\r\n */\r\n yAxis?: number;\r\n };\r\n /**\r\n * The mesh's root node name\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Animation definitions for this model\r\n */\r\n visualResponses: {\r\n [stateKey: string]: {\r\n /**\r\n * What property will be animated\r\n */\r\n componentProperty: \"xAxis\" | \"yAxis\" | \"button\" | \"state\";\r\n /**\r\n * What states influence this visual response\r\n */\r\n states: MotionControllerComponentStateType[];\r\n /**\r\n * Type of animation - movement or visibility\r\n */\r\n valueNodeProperty: \"transform\" | \"visibility\";\r\n /**\r\n * Base node name to move. Its position will be calculated according to the min and max nodes\r\n */\r\n valueNodeName?: string;\r\n /**\r\n * Minimum movement node\r\n */\r\n minNodeName?: string;\r\n /**\r\n * Max movement node\r\n */\r\n maxNodeName?: string;\r\n };\r\n };\r\n /**\r\n * If touch enabled, what is the name of node to display user feedback\r\n */\r\n touchPointNodeName?: string;\r\n };\r\n };\r\n /**\r\n * Is it xr standard mapping or not\r\n */\r\n gamepadMapping: \"\" | \"xr-standard\";\r\n /**\r\n * Base root node of this entire model\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Defines the main button component id\r\n */\r\n selectComponentId: string;\r\n}\r\n\r\n/**\r\n * A definition for the layout map in the input profile\r\n */\r\nexport interface IMotionControllerLayoutMap {\r\n /**\r\n * Layouts with handedness type as a key\r\n */\r\n [handedness: string /* handedness */]: IMotionControllerLayout;\r\n}\r\n\r\n/**\r\n * The XR Input profile schema\r\n * Profiles can be found here:\r\n * https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/registry/profiles\r\n */\r\nexport interface IMotionControllerProfile {\r\n /**\r\n * fallback profiles for this profileId\r\n */\r\n fallbackProfileIds: string[];\r\n /**\r\n * The layout map, with handedness as key\r\n */\r\n layouts: IMotionControllerLayoutMap;\r\n /**\r\n * The id of this profile\r\n * correlates to the profile(s) in the xrInput.profiles array\r\n */\r\n profileId: string;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller button animation\r\n * The meshes are provided to the _lerpButtonTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerButtonMeshMap {\r\n /**\r\n * the mesh that defines the pressed value mesh position.\r\n * This is used to find the max-position of this button\r\n */\r\n pressedMesh: AbstractMesh;\r\n /**\r\n * the mesh that defines the unpressed value mesh position.\r\n * This is used to find the min (or initial) position of this button\r\n */\r\n unpressedMesh: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when value changes\r\n */\r\n valueMesh: AbstractMesh;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller axis animation.\r\n * This will be expanded when touchpad animations are fully supported\r\n * The meshes are provided to the _lerpAxisTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerMeshMap {\r\n /**\r\n * the mesh that defines the maximum value mesh position.\r\n */\r\n maxMesh?: AbstractMesh;\r\n /**\r\n * the mesh that defines the minimum value mesh position.\r\n */\r\n minMesh?: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when axis value changes\r\n */\r\n valueMesh?: AbstractMesh;\r\n}\r\n\r\n/**\r\n * The elements needed for change-detection of the gamepad objects in motion controllers\r\n */\r\nexport interface IMinimalMotionControllerObject {\r\n /**\r\n * Available axes of this controller\r\n */\r\n axes: number[];\r\n /**\r\n * An array of available buttons\r\n */\r\n buttons: Array<{\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n }>;\r\n\r\n /**\r\n * EXPERIMENTAL haptic support.\r\n */\r\n hapticActuators?: Array<{\r\n pulse: (value: number, duration: number) => Promise;\r\n }>;\r\n}\r\n\r\n/**\r\n * An Abstract Motion controller\r\n * This class receives an xrInput and a profile layout and uses those to initialize the components\r\n * Each component has an observable to check for changes in value and state\r\n */\r\nexport abstract class WebXRAbstractMotionController implements IDisposable {\r\n private _initComponent = (id: string) => {\r\n if (!id) {\r\n return;\r\n }\r\n const componentDef = this.layout.components[id];\r\n const type = componentDef.type;\r\n const buttonIndex = componentDef.gamepadIndices.button;\r\n // search for axes\r\n const axes: number[] = [];\r\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\r\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\r\n }\r\n\r\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\r\n };\r\n\r\n private _modelReady: boolean = false;\r\n\r\n /**\r\n * A map of components (WebXRControllerComponent) in this motion controller\r\n * Components have a ComponentType and can also have both button and axis definitions\r\n */\r\n public readonly components: {\r\n [id: string]: WebXRControllerComponent;\r\n } = {};\r\n\r\n /**\r\n * Disable the model's animation. Can be set at any time.\r\n */\r\n public disableAnimation: boolean = false;\r\n /**\r\n * Observers registered here will be triggered when the model of this controller is done loading\r\n */\r\n public onModelLoadedObservable: Observable = new Observable();\r\n /**\r\n * The profile id of this motion controller\r\n */\r\n public abstract profileId: string;\r\n /**\r\n * The root mesh of the model. It is null if the model was not yet initialized\r\n */\r\n public rootMesh: Nullable;\r\n\r\n /**\r\n * constructs a new abstract motion controller\r\n * @param scene the scene to which the model of the controller will be added\r\n * @param layout The profile layout to load\r\n * @param gamepadObject The gamepad object correlating to this controller\r\n * @param handedness handedness (left/right/none) of this controller\r\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\r\n * @param _controllerCache a cache holding controller models already loaded in this session\r\n */\r\n constructor(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected scene: Scene,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected layout: IMotionControllerLayout,\r\n /**\r\n * The gamepad object correlating to this controller\r\n */\r\n public gamepadObject: IMinimalMotionControllerObject,\r\n /**\r\n * handedness (left/right/none) of this controller\r\n */\r\n public handedness: MotionControllerHandedness,\r\n /**\r\n * @internal\r\n */\r\n public _doNotLoadControllerMesh: boolean = false,\r\n private _controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n // initialize the components\r\n if (layout.components) {\r\n Object.keys(layout.components).forEach(this._initComponent);\r\n }\r\n // Model is loaded in WebXRInput\r\n }\r\n\r\n /**\r\n * Dispose this controller, the model mesh and all its components\r\n */\r\n public dispose(): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).dispose());\r\n if (this.rootMesh) {\r\n this.rootMesh.getChildren(undefined, true).forEach((node) => {\r\n node.setEnabled(false);\r\n });\r\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\r\n }\r\n }\r\n\r\n /**\r\n * Returns all components of specific type\r\n * @param type the type to search for\r\n * @returns an array of components with this type\r\n */\r\n public getAllComponentsOfType(type: MotionControllerComponentType): WebXRControllerComponent[] {\r\n return this.getComponentIds()\r\n .map((id) => this.components[id])\r\n .filter((component) => component.type === type);\r\n }\r\n\r\n /**\r\n * get a component based an its component id as defined in layout.components\r\n * @param id the id of the component\r\n * @returns the component correlates to the id or undefined if not found\r\n */\r\n public getComponent(id: string): WebXRControllerComponent {\r\n return this.components[id];\r\n }\r\n\r\n /**\r\n * Get the list of components available in this motion controller\r\n * @returns an array of strings correlating to available components\r\n */\r\n public getComponentIds(): string[] {\r\n return Object.keys(this.components);\r\n }\r\n\r\n /**\r\n * Get the first component of specific type\r\n * @param type type of component to find\r\n * @returns a controller component or null if not found\r\n */\r\n public getComponentOfType(type: MotionControllerComponentType): Nullable {\r\n return this.getAllComponentsOfType(type)[0] || null;\r\n }\r\n\r\n /**\r\n * Get the main (Select) component of this controller as defined in the layout\r\n * @returns the main component of this controller\r\n */\r\n public getMainComponent(): WebXRControllerComponent {\r\n return this.getComponent(this.layout.selectComponentId);\r\n }\r\n\r\n /**\r\n * Loads the model correlating to this controller\r\n * When the mesh is loaded, the onModelLoadedObservable will be triggered\r\n * @returns A promise fulfilled with the result of the model loading\r\n */\r\n public async loadModel(): Promise {\r\n const useGeneric = !this._getModelLoadingConstraints();\r\n let loadingParams = this._getGenericFilenameAndPath();\r\n // Checking if GLB loader is present\r\n if (useGeneric) {\r\n Logger.Warn(\"Falling back to generic models\");\r\n } else {\r\n loadingParams = this._getFilenameAndPath();\r\n }\r\n return new Promise((resolve, reject) => {\r\n const meshesLoaded = (meshes: AbstractMesh[]) => {\r\n if (useGeneric) {\r\n this._getGenericParentMesh(meshes);\r\n } else {\r\n this._setRootMesh(meshes);\r\n }\r\n this._processLoadedModel(meshes);\r\n this._modelReady = true;\r\n this.onModelLoadedObservable.notifyObservers(this);\r\n resolve(true);\r\n };\r\n if (this._controllerCache) {\r\n // look for it in the cache\r\n const found = this._controllerCache.filter((c) => {\r\n return c.filename === loadingParams.filename && c.path === loadingParams.path;\r\n });\r\n if (found[0]) {\r\n found[0].meshes.forEach((mesh) => mesh.setEnabled(true));\r\n meshesLoaded(found[0].meshes);\r\n return;\r\n // found, don't continue to load\r\n }\r\n }\r\n SceneLoader.ImportMesh(\r\n \"\",\r\n loadingParams.path,\r\n loadingParams.filename,\r\n this.scene,\r\n (meshes) => {\r\n if (this._controllerCache) {\r\n this._controllerCache.push({\r\n ...loadingParams,\r\n meshes,\r\n });\r\n }\r\n meshesLoaded(meshes);\r\n },\r\n null,\r\n (_scene: Scene, message: string) => {\r\n Logger.Log(message);\r\n Logger.Warn(`Failed to retrieve controller model of type ${this.profileId} from the remote server: ${loadingParams.path}${loadingParams.filename}`);\r\n reject(message);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Update this model using the current XRFrame\r\n * @param xrFrame the current xr frame to use and update the model\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).update(this.gamepadObject));\r\n this.updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Backwards compatibility due to a deeply-integrated typo\r\n */\r\n public get handness() {\r\n return this.handedness;\r\n }\r\n\r\n /**\r\n * Pulse (vibrate) this controller\r\n * If the controller does not support pulses, this function will fail silently and return Promise directly after called\r\n * Consecutive calls to this function will cancel the last pulse call\r\n *\r\n * @param value the strength of the pulse in 0.0...1.0 range\r\n * @param duration Duration of the pulse in milliseconds\r\n * @param hapticActuatorIndex optional index of actuator (will usually be 0)\r\n * @returns a promise that will send true when the pulse has ended and false if the device doesn't support pulse or an error accrued\r\n */\r\n public pulse(value: number, duration: number, hapticActuatorIndex: number = 0): Promise {\r\n if (this.gamepadObject.hapticActuators && this.gamepadObject.hapticActuators[hapticActuatorIndex]) {\r\n return this.gamepadObject.hapticActuators[hapticActuatorIndex].pulse(value, duration);\r\n } else {\r\n return Promise.resolve(false);\r\n }\r\n }\r\n\r\n // Look through all children recursively. This will return null if no mesh exists with the given name.\r\n protected _getChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return node.getChildren((n) => n.name === name, false)[0];\r\n }\r\n\r\n // Look through only immediate children. This will return null if no mesh exists with the given name.\r\n protected _getImmediateChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return node.getChildren((n) => n.name == name, true)[0];\r\n }\r\n\r\n /**\r\n * Moves the axis on the controller mesh based on its current state\r\n * @param axisMap\r\n * @param axisValue the value of the axis which determines the meshes new position\r\n * @internal\r\n */\r\n protected _lerpTransform(axisMap: IMotionControllerMeshMap, axisValue: number, fixValueCoordinates?: boolean): void {\r\n if (!axisMap.minMesh || !axisMap.maxMesh || !axisMap.valueMesh) {\r\n return;\r\n }\r\n\r\n if (!axisMap.minMesh.rotationQuaternion || !axisMap.maxMesh.rotationQuaternion || !axisMap.valueMesh.rotationQuaternion) {\r\n return;\r\n }\r\n\r\n // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)\r\n const lerpValue = fixValueCoordinates ? axisValue * 0.5 + 0.5 : axisValue;\r\n Quaternion.SlerpToRef(axisMap.minMesh.rotationQuaternion, axisMap.maxMesh.rotationQuaternion, lerpValue, axisMap.valueMesh.rotationQuaternion);\r\n Vector3.LerpToRef(axisMap.minMesh.position, axisMap.maxMesh.position, lerpValue, axisMap.valueMesh.position);\r\n }\r\n\r\n /**\r\n * Update the model itself with the current frame data\r\n * @param xrFrame the frame to use for updating the model mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected updateModel(xrFrame: XRFrame): void {\r\n if (!this._modelReady) {\r\n return;\r\n }\r\n this._updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Get the filename and path for this controller's model\r\n * @returns a map of filename and path\r\n */\r\n protected abstract _getFilenameAndPath(): { filename: string; path: string };\r\n /**\r\n * This function is called before the mesh is loaded. It checks for loading constraints.\r\n * For example, this function can check if the GLB loader is available\r\n * If this function returns false, the generic controller will be loaded instead\r\n * @returns Is the client ready to load the mesh\r\n */\r\n protected abstract _getModelLoadingConstraints(): boolean;\r\n /**\r\n * This function will be called after the model was successfully loaded and can be used\r\n * for mesh transformations before it is available for the user\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _processLoadedModel(meshes: AbstractMesh[]): void;\r\n /**\r\n * Set the root mesh for this controller. Important for the WebXR controller class\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _setRootMesh(meshes: AbstractMesh[]): void;\r\n /**\r\n * A function executed each frame that updates the mesh (if needed)\r\n * @param xrFrame the current xrFrame\r\n */\r\n protected abstract _updateModel(xrFrame: XRFrame): void;\r\n\r\n private _getGenericFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n private _getGenericParentMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n meshes.forEach((mesh) => {\r\n if (!mesh.parent) {\r\n mesh.isPickable = false;\r\n mesh.setParent(this.rootMesh);\r\n }\r\n });\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n}\r\n","import type { IMinimalMotionControllerObject, MotionControllerHandedness, IMotionControllerLayoutMap } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\n\r\n/**\r\n * A generic trigger-only motion controller for WebXR\r\n */\r\nexport class WebXRGenericTriggerMotionController extends WebXRAbstractMotionController {\r\n /**\r\n * Static version of the profile id of this controller\r\n */\r\n public static ProfileId = \"generic-trigger\";\r\n\r\n public profileId = WebXRGenericTriggerMotionController.ProfileId;\r\n\r\n constructor(scene: Scene, gamepadObject: IMinimalMotionControllerObject, handedness: MotionControllerHandedness) {\r\n super(scene, GenericTriggerLayout[handedness], gamepadObject, handedness);\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n return true;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _processLoadedModel(meshes: AbstractMesh[]): void {\r\n // nothing to do\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n meshes.forEach((mesh) => {\r\n mesh.isPickable = false;\r\n if (!mesh.parent) {\r\n mesh.setParent(this.rootMesh);\r\n }\r\n });\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n\r\n protected _updateModel(): void {\r\n // no-op\r\n }\r\n}\r\n\r\n// https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/generic/generic-trigger-touchpad-thumbstick.json\r\nconst GenericTriggerLayout: IMotionControllerLayoutMap = {\r\n left: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"generic-trigger-left\",\r\n assetPath: \"left.glb\",\r\n },\r\n right: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"generic-trigger-right\",\r\n assetPath: \"right.glb\",\r\n },\r\n none: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"generic-trigger-none\",\r\n assetPath: \"none.glb\",\r\n },\r\n};\r\n","import type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3, Matrix } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for an ellipsoid, defaults to a sphere\r\n * @param options an object used to set the following optional parameters for the box, required but can be empty\r\n * * segments sets the number of horizontal strips optional, default 32\r\n * * diameter sets the axes dimensions, diameterX, diameterY and diameterZ to the value of diameter, optional default 1\r\n * * diameterX sets the diameterX (x direction) of the ellipsoid, overwrites the diameterX set by diameter, optional, default diameter\r\n * * diameterY sets the diameterY (y direction) of the ellipsoid, overwrites the diameterY set by diameter, optional, default diameter\r\n * * diameterZ sets the diameterZ (z direction) of the ellipsoid, overwrites the diameterZ set by diameter, optional, default diameter\r\n * * arc a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the circumference (latitude) given by the arc value, optional, default 1\r\n * * slice a number from 0 to 1, to create an unclosed ellipsoid based on the fraction of the height (latitude) given by the arc value, optional, default 1\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.segments\r\n * @param options.diameter\r\n * @param options.diameterX\r\n * @param options.diameterY\r\n * @param options.diameterZ\r\n * @param options.arc\r\n * @param options.slice\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.dedupTopBottomIndices\r\n * @returns the VertexData of the ellipsoid\r\n */\r\nexport function CreateSphereVertexData(options: {\r\n segments?: number;\r\n diameter?: number;\r\n diameterX?: number;\r\n diameterY?: number;\r\n diameterZ?: number;\r\n arc?: number;\r\n slice?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n dedupTopBottomIndices?: boolean;\r\n}): VertexData {\r\n const segments: number = (options.segments || 32) | 0;\r\n const diameterX: number = options.diameterX || options.diameter || 1;\r\n const diameterY: number = options.diameterY || options.diameter || 1;\r\n const diameterZ: number = options.diameterZ || options.diameter || 1;\r\n const arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n const slice: number = options.slice && options.slice <= 0 ? 1.0 : options.slice || 1.0;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n const dedupTopBottomIndices = !!options.dedupTopBottomIndices;\r\n\r\n const radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);\r\n\r\n const totalZRotationSteps = 2 + segments;\r\n const totalYRotationSteps = 2 * totalZRotationSteps;\r\n\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {\r\n const normalizedZ = zRotationStep / totalZRotationSteps;\r\n const angleZ = normalizedZ * Math.PI * slice;\r\n\r\n for (let yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {\r\n const normalizedY = yRotationStep / totalYRotationSteps;\r\n\r\n const angleY = normalizedY * Math.PI * 2 * arc;\r\n\r\n const rotationZ = Matrix.RotationZ(-angleZ);\r\n const rotationY = Matrix.RotationY(angleY);\r\n const afterRotZ = Vector3.TransformCoordinates(Vector3.Up(), rotationZ);\r\n const complete = Vector3.TransformCoordinates(afterRotZ, rotationY);\r\n\r\n const vertex = complete.multiply(radius);\r\n const normal = complete.divide(radius).normalize();\r\n\r\n positions.push(vertex.x, vertex.y, vertex.z);\r\n normals.push(normal.x, normal.y, normal.z);\r\n uvs.push(normalizedY, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - normalizedZ : normalizedZ);\r\n }\r\n\r\n if (zRotationStep > 0) {\r\n const verticesCount = positions.length / 3;\r\n for (let firstIndex = verticesCount - 2 * (totalYRotationSteps + 1); firstIndex + totalYRotationSteps + 2 < verticesCount; firstIndex++) {\r\n if (dedupTopBottomIndices) {\r\n if (zRotationStep > 1) {\r\n indices.push(firstIndex);\r\n indices.push(firstIndex + 1);\r\n indices.push(firstIndex + totalYRotationSteps + 1);\r\n }\r\n if (zRotationStep < totalZRotationSteps || slice < 1.0) {\r\n indices.push(firstIndex + totalYRotationSteps + 1);\r\n indices.push(firstIndex + 1);\r\n indices.push(firstIndex + totalYRotationSteps + 2);\r\n }\r\n } else {\r\n indices.push(firstIndex);\r\n indices.push(firstIndex + 1);\r\n indices.push(firstIndex + totalYRotationSteps + 1);\r\n\r\n indices.push(firstIndex + totalYRotationSteps + 1);\r\n indices.push(firstIndex + 1);\r\n indices.push(firstIndex + totalYRotationSteps + 2);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a sphere mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the sphere (default 1)\r\n * * You can set some different sphere dimensions, for instance to build an ellipsoid, by using the parameters `diameterX`, `diameterY` and `diameterZ` (all by default have the same value of `diameter`)\r\n * * The parameter `segments` sets the sphere number of horizontal stripes (positive integer, default 32)\r\n * * You can create an unclosed sphere with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference (latitude) : 2 x PI x ratio\r\n * * You can create an unclosed sphere on its height with the parameter `slice` (positive float, default1), valued between 0 and 1, what is the height ratio (longitude)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.segments\r\n * @param options.diameter\r\n * @param options.diameterX\r\n * @param options.diameterY\r\n * @param options.diameterZ\r\n * @param options.arc\r\n * @param options.slice\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the sphere mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#sphere\r\n */\r\nexport function CreateSphere(\r\n name: string,\r\n options: {\r\n segments?: number;\r\n diameter?: number;\r\n diameterX?: number;\r\n diameterY?: number;\r\n diameterZ?: number;\r\n arc?: number;\r\n slice?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n } = {},\r\n scene: Nullable = null\r\n): Mesh {\r\n const sphere = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n sphere._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateSphereVertexData(options);\r\n\r\n vertexData.applyToMesh(sphere, options.updatable);\r\n\r\n return sphere;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateSphere directly\r\n */\r\nexport const SphereBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateSphere,\r\n};\r\n\r\nVertexData.CreateSphere = CreateSphereVertexData;\r\n\r\nMesh.CreateSphere = (name: string, segments: number, diameter: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n segments: segments,\r\n diameterX: diameter,\r\n diameterY: diameter,\r\n diameterZ: diameter,\r\n sideOrientation: sideOrientation,\r\n updatable: updatable,\r\n };\r\n\r\n return CreateSphere(name, options, scene);\r\n};\r\n","import type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { IMotionControllerProfile, IMotionControllerMeshMap } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Axis, Space } from \"../../Maths/math.axis\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { CreateSphere } from \"../../Meshes/Builders/sphereBuilder\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { Logger } from \"../../Misc/logger\";\r\n\r\n/**\r\n * A profiled motion controller has its profile loaded from an online repository.\r\n * The class is responsible of loading the model, mapping the keys and enabling model-animations\r\n */\r\nexport class WebXRProfiledMotionController extends WebXRAbstractMotionController {\r\n private _buttonMeshMapping: {\r\n [buttonName: string]: {\r\n mainMesh?: AbstractMesh;\r\n states: {\r\n [state: string]: IMotionControllerMeshMap;\r\n };\r\n };\r\n } = {};\r\n private _touchDots: { [visKey: string]: AbstractMesh } = {};\r\n\r\n /**\r\n * The profile ID of this controller. Will be populated when the controller initializes.\r\n */\r\n public profileId: string;\r\n\r\n constructor(\r\n scene: Scene,\r\n xrInput: XRInputSource,\r\n _profile: IMotionControllerProfile,\r\n private _repositoryUrl: string,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n super(scene, _profile.layouts[xrInput.handedness || \"none\"], xrInput.gamepad as any, xrInput.handedness, undefined, controllerCache);\r\n this.profileId = _profile.profileId;\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n if (!this.controllerCache) {\r\n Object.keys(this._touchDots).forEach((visResKey) => {\r\n this._touchDots[visResKey].dispose();\r\n });\r\n }\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: this.layout.assetPath,\r\n path: `${this._repositoryUrl}/profiles/${this.profileId}/`,\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n const glbLoaded = SceneLoader.IsPluginForExtensionAvailable(\".glb\");\r\n if (!glbLoaded) {\r\n Logger.Warn(\"glTF / glb loader was not registered, using generic controller instead\");\r\n }\r\n return glbLoaded;\r\n }\r\n\r\n protected _processLoadedModel(_meshes: AbstractMesh[]): void {\r\n this.getComponentIds().forEach((type) => {\r\n const componentInLayout = this.layout.components[type];\r\n this._buttonMeshMapping[type] = {\r\n mainMesh: this._getChildByName(this.rootMesh!, componentInLayout.rootNodeName),\r\n states: {},\r\n };\r\n Object.keys(componentInLayout.visualResponses).forEach((visualResponseKey) => {\r\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\r\n if (visResponse.valueNodeProperty === \"transform\") {\r\n this._buttonMeshMapping[type].states[visualResponseKey] = {\r\n valueMesh: this._getChildByName(this.rootMesh!, visResponse.valueNodeName!),\r\n minMesh: this._getChildByName(this.rootMesh!, visResponse.minNodeName!),\r\n maxMesh: this._getChildByName(this.rootMesh!, visResponse.maxNodeName!),\r\n };\r\n } else {\r\n // visibility, usually for touchpads\r\n const nameOfMesh =\r\n componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && componentInLayout.touchPointNodeName\r\n ? componentInLayout.touchPointNodeName\r\n : visResponse.valueNodeName!;\r\n this._buttonMeshMapping[type].states[visualResponseKey] = {\r\n valueMesh: this._getChildByName(this.rootMesh!, nameOfMesh),\r\n };\r\n if (componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && !this._touchDots[visualResponseKey]) {\r\n const dot = CreateSphere(\r\n visualResponseKey + \"dot\",\r\n {\r\n diameter: 0.0015,\r\n segments: 8,\r\n },\r\n this.scene\r\n );\r\n dot.material = new StandardMaterial(visualResponseKey + \"mat\", this.scene);\r\n (dot.material).diffuseColor = Color3.Red();\r\n dot.parent = this._buttonMeshMapping[type].states[visualResponseKey].valueMesh || null;\r\n dot.isVisible = false;\r\n this._touchDots[visualResponseKey] = dot;\r\n }\r\n }\r\n });\r\n });\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \"-\" + this.handedness, this.scene);\r\n this.rootMesh.isPickable = false;\r\n let rootMesh;\r\n // Find the root node in the loaded glTF scene, and attach it as a child of 'parentMesh'\r\n for (let i = 0; i < meshes.length; i++) {\r\n const mesh = meshes[i];\r\n\r\n mesh.isPickable = false;\r\n\r\n if (!mesh.parent) {\r\n // Handle root node, attach to the new parentMesh\r\n rootMesh = mesh;\r\n }\r\n }\r\n\r\n if (rootMesh) {\r\n rootMesh.setParent(this.rootMesh);\r\n }\r\n if (!this.scene.useRightHandedSystem) {\r\n this.rootMesh.rotate(Axis.Y, Math.PI, Space.WORLD);\r\n }\r\n }\r\n\r\n protected _updateModel(_xrFrame: XRFrame): void {\r\n if (this.disableAnimation) {\r\n return;\r\n }\r\n this.getComponentIds().forEach((id) => {\r\n const component = this.getComponent(id);\r\n if (!component.hasChanges) {\r\n return;\r\n }\r\n const meshes = this._buttonMeshMapping[id];\r\n const componentInLayout = this.layout.components[id];\r\n Object.keys(componentInLayout.visualResponses).forEach((visualResponseKey) => {\r\n const visResponse = componentInLayout.visualResponses[visualResponseKey];\r\n let value = component.value;\r\n if (visResponse.componentProperty === \"xAxis\") {\r\n value = component.axes.x;\r\n } else if (visResponse.componentProperty === \"yAxis\") {\r\n value = component.axes.y;\r\n }\r\n if (visResponse.valueNodeProperty === \"transform\") {\r\n this._lerpTransform(meshes.states[visualResponseKey], value, visResponse.componentProperty !== \"button\");\r\n } else {\r\n // visibility\r\n const valueMesh = meshes.states[visualResponseKey].valueMesh;\r\n if (valueMesh) {\r\n valueMesh.isVisible = component.touched || component.pressed;\r\n }\r\n if (this._touchDots[visualResponseKey]) {\r\n this._touchDots[visualResponseKey].isVisible = component.touched || component.pressed;\r\n }\r\n }\r\n });\r\n });\r\n }\r\n}\r\n","import type { WebXRAbstractMotionController, IMotionControllerProfile } from \"./webXRAbstractMotionController\";\r\nimport { WebXRGenericTriggerMotionController } from \"./webXRGenericMotionController\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { WebXRProfiledMotionController } from \"./webXRProfiledMotionController\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\n\r\n/**\r\n * A construction function type to create a new controller based on an xrInput object\r\n */\r\nexport type MotionControllerConstructor = (xrInput: XRInputSource, scene: Scene) => WebXRAbstractMotionController;\r\n\r\n/**\r\n * The MotionController Manager manages all registered motion controllers and loads the right one when needed.\r\n *\r\n * When this repository is complete: https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/assets\r\n * it should be replaced with auto-loaded controllers.\r\n *\r\n * When using a model try to stay as generic as possible. Eventually there will be no need in any of the controller classes\r\n */\r\n\r\nconst controllerCache: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n}> = [];\r\n\r\n/**\r\n * Motion controller manager is managing the different webxr profiles and makes sure the right\r\n * controller is being loaded.\r\n */\r\nexport class WebXRMotionControllerManager {\r\n private static _AvailableControllers: { [type: string]: MotionControllerConstructor } = {};\r\n private static _Fallbacks: { [profileId: string]: string[] } = {};\r\n // cache for loading\r\n private static _ProfileLoadingPromises: { [profileName: string]: Promise } = {};\r\n private static _ProfilesList: Nullable>;\r\n\r\n /**\r\n * The base URL of the online controller repository. Can be changed at any time.\r\n */\r\n public static BaseRepositoryUrl = \"https://immersive-web.github.io/webxr-input-profiles/packages/viewer/dist\";\r\n /**\r\n * Which repository gets priority - local or online\r\n */\r\n public static PrioritizeOnlineRepository: boolean = true;\r\n /**\r\n * Use the online repository, or use only locally-defined controllers\r\n */\r\n public static UseOnlineRepository: boolean = true;\r\n\r\n /**\r\n * Disable the controller cache and load the models each time a new WebXRProfileMotionController is loaded.\r\n * Defaults to true.\r\n */\r\n public static DisableControllerCache: boolean = true;\r\n\r\n /**\r\n * Clear the cache used for profile loading and reload when requested again\r\n */\r\n public static ClearProfilesCache() {\r\n this._ProfilesList = null;\r\n this._ProfileLoadingPromises = {};\r\n }\r\n\r\n /**\r\n * Register the default fallbacks.\r\n * This function is called automatically when this file is imported.\r\n */\r\n public static DefaultFallbacks() {\r\n this.RegisterFallbacksForProfileId(\"google-daydream\", [\"generic-touchpad\"]);\r\n this.RegisterFallbacksForProfileId(\"htc-vive-focus\", [\"generic-trigger-touchpad\"]);\r\n this.RegisterFallbacksForProfileId(\"htc-vive\", [\"generic-trigger-squeeze-touchpad\"]);\r\n this.RegisterFallbacksForProfileId(\"magicleap-one\", [\"generic-trigger-squeeze-touchpad\"]);\r\n this.RegisterFallbacksForProfileId(\"windows-mixed-reality\", [\"generic-trigger-squeeze-touchpad-thumbstick\"]);\r\n this.RegisterFallbacksForProfileId(\"microsoft-mixed-reality\", [\"windows-mixed-reality\", \"generic-trigger-squeeze-touchpad-thumbstick\"]);\r\n this.RegisterFallbacksForProfileId(\"oculus-go\", [\"generic-trigger-touchpad\"]);\r\n this.RegisterFallbacksForProfileId(\"oculus-touch-v2\", [\"oculus-touch\", \"generic-trigger-squeeze-thumbstick\"]);\r\n this.RegisterFallbacksForProfileId(\"oculus-touch\", [\"generic-trigger-squeeze-thumbstick\"]);\r\n this.RegisterFallbacksForProfileId(\"samsung-gearvr\", [\"windows-mixed-reality\", \"generic-trigger-squeeze-touchpad-thumbstick\"]);\r\n this.RegisterFallbacksForProfileId(\"samsung-odyssey\", [\"generic-touchpad\"]);\r\n this.RegisterFallbacksForProfileId(\"valve-index\", [\"generic-trigger-squeeze-touchpad-thumbstick\"]);\r\n this.RegisterFallbacksForProfileId(\"generic-hand-select\", [\"generic-trigger\"]);\r\n }\r\n\r\n /**\r\n * Find a fallback profile if the profile was not found. There are a few predefined generic profiles.\r\n * @param profileId the profile to which a fallback needs to be found\r\n * @returns an array with corresponding fallback profiles\r\n */\r\n public static FindFallbackWithProfileId(profileId: string): string[] {\r\n const returnArray = this._Fallbacks[profileId] || [];\r\n\r\n returnArray.unshift(profileId);\r\n return returnArray;\r\n }\r\n\r\n /**\r\n * When acquiring a new xrInput object (usually by the WebXRInput class), match it with the correct profile.\r\n * The order of search:\r\n *\r\n * 1) Iterate the profiles array of the xr input and try finding a corresponding motion controller\r\n * 2) (If not found) search in the gamepad id and try using it (legacy versions only)\r\n * 3) search for registered fallbacks (should be redundant, nonetheless it makes sense to check)\r\n * 4) return the generic trigger controller if none were found\r\n *\r\n * @param xrInput the xrInput to which a new controller is initialized\r\n * @param scene the scene to which the model will be added\r\n * @param forceProfile force a certain profile for this controller\r\n * @returns A promise that fulfils with the motion controller class for this profile id or the generic standard class if none was found\r\n */\r\n public static GetMotionControllerWithXRInput(xrInput: XRInputSource, scene: Scene, forceProfile?: string): Promise {\r\n const profileArray: string[] = [];\r\n if (forceProfile) {\r\n profileArray.push(forceProfile);\r\n }\r\n profileArray.push(...(xrInput.profiles || []));\r\n\r\n // emulator support\r\n if (profileArray.length && !profileArray[0]) {\r\n // remove the first \"undefined\" that the emulator is adding\r\n profileArray.pop();\r\n }\r\n\r\n // legacy support - try using the gamepad id\r\n if (xrInput.gamepad && xrInput.gamepad.id) {\r\n switch (xrInput.gamepad.id) {\r\n case xrInput.gamepad.id.match(/oculus touch/gi) ? xrInput.gamepad.id : undefined:\r\n // oculus in gamepad id\r\n profileArray.push(\"oculus-touch-v2\");\r\n break;\r\n }\r\n }\r\n\r\n // make sure microsoft/windows mixed reality works correctly\r\n const windowsMRIdx = profileArray.indexOf(\"windows-mixed-reality\");\r\n if (windowsMRIdx !== -1) {\r\n profileArray.splice(windowsMRIdx, 0, \"microsoft-mixed-reality\");\r\n }\r\n\r\n if (!profileArray.length) {\r\n profileArray.push(\"generic-trigger\");\r\n }\r\n\r\n if (this.UseOnlineRepository) {\r\n const firstFunction = this.PrioritizeOnlineRepository ? this._LoadProfileFromRepository : this._LoadProfilesFromAvailableControllers;\r\n const secondFunction = this.PrioritizeOnlineRepository ? this._LoadProfilesFromAvailableControllers : this._LoadProfileFromRepository;\r\n\r\n return firstFunction.call(this, profileArray, xrInput, scene).catch(() => {\r\n return secondFunction.call(this, profileArray, xrInput, scene);\r\n });\r\n } else {\r\n // use only available functions\r\n return this._LoadProfilesFromAvailableControllers(profileArray, xrInput, scene);\r\n }\r\n }\r\n\r\n /**\r\n * Register a new controller based on its profile. This function will be called by the controller classes themselves.\r\n *\r\n * If you are missing a profile, make sure it is imported in your source, otherwise it will not register.\r\n *\r\n * @param type the profile type to register\r\n * @param constructFunction the function to be called when loading this profile\r\n */\r\n public static RegisterController(type: string, constructFunction: MotionControllerConstructor) {\r\n this._AvailableControllers[type] = constructFunction;\r\n }\r\n\r\n /**\r\n * Register a fallback to a specific profile.\r\n * @param profileId the profileId that will receive the fallbacks\r\n * @param fallbacks A list of fallback profiles\r\n */\r\n public static RegisterFallbacksForProfileId(profileId: string, fallbacks: string[]): void {\r\n if (this._Fallbacks[profileId]) {\r\n this._Fallbacks[profileId].push(...fallbacks);\r\n } else {\r\n this._Fallbacks[profileId] = fallbacks;\r\n }\r\n }\r\n\r\n /**\r\n * Will update the list of profiles available in the repository\r\n * @returns a promise that resolves to a map of profiles available online\r\n */\r\n public static UpdateProfilesList() {\r\n this._ProfilesList = Tools.LoadFileAsync(this.BaseRepositoryUrl + \"/profiles/profilesList.json\", false).then((data) => {\r\n return JSON.parse(data.toString());\r\n });\r\n return this._ProfilesList;\r\n }\r\n\r\n /**\r\n * Clear the controller's cache (usually happens at the end of a session)\r\n */\r\n public static ClearControllerCache() {\r\n controllerCache.forEach((cacheItem) => {\r\n cacheItem.meshes.forEach((mesh) => {\r\n mesh.dispose(false, true);\r\n });\r\n });\r\n controllerCache.length = 0;\r\n }\r\n\r\n private static _LoadProfileFromRepository(profileArray: string[], xrInput: XRInputSource, scene: Scene): Promise {\r\n return Promise.resolve()\r\n .then(() => {\r\n if (!this._ProfilesList) {\r\n return this.UpdateProfilesList();\r\n } else {\r\n return this._ProfilesList;\r\n }\r\n })\r\n .then((profilesList: { [profile: string]: string }) => {\r\n // load the right profile\r\n for (let i = 0; i < profileArray.length; ++i) {\r\n // defensive\r\n if (!profileArray[i]) {\r\n continue;\r\n }\r\n if (profilesList[profileArray[i]]) {\r\n return profileArray[i];\r\n }\r\n }\r\n\r\n throw new Error(`neither controller ${profileArray[0]} nor all fallbacks were found in the repository,`);\r\n })\r\n .then((profileToLoad: string) => {\r\n // load the profile\r\n if (!this._ProfileLoadingPromises[profileToLoad]) {\r\n this._ProfileLoadingPromises[profileToLoad] = Tools.LoadFileAsync(`${this.BaseRepositoryUrl}/profiles/${profileToLoad}/profile.json`, false).then(\r\n (data) => JSON.parse(data as string)\r\n );\r\n }\r\n return this._ProfileLoadingPromises[profileToLoad];\r\n })\r\n .then((profile: IMotionControllerProfile) => {\r\n return new WebXRProfiledMotionController(scene, xrInput, profile, this.BaseRepositoryUrl, this.DisableControllerCache ? undefined : controllerCache);\r\n });\r\n }\r\n\r\n private static _LoadProfilesFromAvailableControllers(profileArray: string[], xrInput: XRInputSource, scene: Scene) {\r\n // check fallbacks\r\n for (let i = 0; i < profileArray.length; ++i) {\r\n // defensive\r\n if (!profileArray[i]) {\r\n continue;\r\n }\r\n const fallbacks = this.FindFallbackWithProfileId(profileArray[i]);\r\n for (let j = 0; j < fallbacks.length; ++j) {\r\n const constructionFunction = this._AvailableControllers[fallbacks[j]];\r\n if (constructionFunction) {\r\n return Promise.resolve(constructionFunction(xrInput, scene));\r\n }\r\n }\r\n }\r\n\r\n throw new Error(`no controller requested was found in the available controllers list`);\r\n }\r\n}\r\n\r\n// register the generic profile(s) here so we will at least have them\r\nWebXRMotionControllerManager.RegisterController(WebXRGenericTriggerMotionController.ProfileId, (xrInput: XRInputSource, scene: Scene) => {\r\n return new WebXRGenericTriggerMotionController(scene, xrInput.gamepad, xrInput.handedness);\r\n});\r\n\r\n// register fallbacks\r\nWebXRMotionControllerManager.DefaultFallbacks();\r\n","import { Observable } from \"../Misc/observable\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { WebXRAbstractMotionController } from \"./motionController/webXRAbstractMotionController\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\n\r\nlet idCount = 0;\r\n\r\n/**\r\n * Configuration options for the WebXR controller creation\r\n */\r\nexport interface IWebXRControllerOptions {\r\n /**\r\n * Should the controller mesh be animated when a user interacts with it\r\n * The pressed buttons / thumbstick and touchpad animations will be disabled\r\n */\r\n disableMotionControllerAnimation?: boolean;\r\n /**\r\n * Do not load the controller mesh, in case a different mesh needs to be loaded.\r\n */\r\n doNotLoadControllerMesh?: boolean;\r\n /**\r\n * Force a specific controller type for this controller.\r\n * This can be used when creating your own profile or when testing different controllers\r\n */\r\n forceControllerProfile?: string;\r\n /**\r\n * Defines a rendering group ID for meshes that will be loaded.\r\n * This is for the default controllers only.\r\n */\r\n renderingGroupId?: number;\r\n}\r\n\r\n/**\r\n * Represents an XR controller\r\n */\r\nexport class WebXRInputSource {\r\n private _tmpVector = new Vector3();\r\n private _uniqueId: string;\r\n private _disposed = false;\r\n\r\n /**\r\n * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if that's the case only the pointer from the head will be available\r\n */\r\n public grip?: AbstractMesh;\r\n /**\r\n * If available, this is the gamepad object related to this controller.\r\n * Using this object it is possible to get click events and trackpad changes of the\r\n * webxr controller that is currently being used.\r\n */\r\n public motionController?: WebXRAbstractMotionController;\r\n /**\r\n * Event that fires when the controller is removed/disposed.\r\n * The object provided as event data is this controller, after associated assets were disposed.\r\n * uniqueId is still available.\r\n */\r\n public onDisposeObservable = new Observable();\r\n /**\r\n * Will be triggered when the mesh associated with the motion controller is done loading.\r\n * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh\r\n * A shortened version of controller -> motion controller -> on mesh loaded.\r\n */\r\n public onMeshLoadedObservable = new Observable();\r\n /**\r\n * Observers registered here will trigger when a motion controller profile was assigned to this xr controller\r\n */\r\n public onMotionControllerInitObservable = new Observable();\r\n /**\r\n * Pointer which can be used to select objects or attach a visible laser to\r\n */\r\n public pointer: AbstractMesh;\r\n\r\n /**\r\n * The last XRPose the was calculated on the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRPose?: XRPose;\r\n\r\n /**\r\n * Creates the input source object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport\r\n * @param _scene the scene which the controller should be associated to\r\n * @param inputSource the underlying input source for the controller\r\n * @param _options options for this controller creation\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n /** The underlying input source for the controller */\r\n public inputSource: XRInputSource,\r\n private _options: IWebXRControllerOptions = {}\r\n ) {\r\n this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;\r\n\r\n this.pointer = new AbstractMesh(`${this._uniqueId}-pointer`, _scene);\r\n this.pointer.rotationQuaternion = new Quaternion();\r\n\r\n if (this.inputSource.gripSpace) {\r\n this.grip = new AbstractMesh(`${this._uniqueId}-grip`, this._scene);\r\n this.grip.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);\r\n\r\n // for now only load motion controllers if gamepad object available\r\n if (this.inputSource.gamepad && this.inputSource.targetRayMode === \"tracked-pointer\") {\r\n WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then(\r\n (motionController) => {\r\n this.motionController = motionController;\r\n this.onMotionControllerInitObservable.notifyObservers(motionController);\r\n // should the model be loaded?\r\n if (!this._options.doNotLoadControllerMesh && !this.motionController._doNotLoadControllerMesh) {\r\n this.motionController.loadModel().then((success) => {\r\n if (success && this.motionController && this.motionController.rootMesh) {\r\n if (this._options.renderingGroupId) {\r\n // anything other than 0?\r\n this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;\r\n this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => (mesh.renderingGroupId = this._options.renderingGroupId!));\r\n }\r\n this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);\r\n this.motionController.rootMesh.parent = this.grip || this.pointer;\r\n this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;\r\n }\r\n // make sure to dispose is the controller is already disposed\r\n if (this._disposed) {\r\n this.motionController?.dispose();\r\n }\r\n });\r\n }\r\n },\r\n () => {\r\n Tools.Warn(`Could not find a matching motion controller for the registered input source`);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Get this controllers unique id\r\n */\r\n public get uniqueId() {\r\n return this._uniqueId;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n if (this.grip) {\r\n this.grip.dispose(true);\r\n }\r\n if (this.motionController) {\r\n this.motionController.dispose();\r\n }\r\n this.pointer.dispose(true);\r\n this.onMotionControllerInitObservable.clear();\r\n this.onMeshLoadedObservable.clear();\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n this._disposed = true;\r\n }\r\n\r\n /**\r\n * Gets a world space ray coming from the pointer or grip\r\n * @param result the resulting ray\r\n * @param gripIfAvailable use the grip mesh instead of the pointer, if available\r\n */\r\n public getWorldPointerRayToRef(result: Ray, gripIfAvailable: boolean = false) {\r\n const object = gripIfAvailable && this.grip ? this.grip : this.pointer;\r\n Vector3.TransformNormalToRef(this._tmpVector, object.getWorldMatrix(), result.direction);\r\n result.direction.normalize();\r\n result.origin.copyFrom(object.absolutePosition);\r\n result.length = 1000;\r\n }\r\n\r\n /**\r\n * Updates the controller pose based on the given XRFrame\r\n * @param xrFrame xr frame to update the pose with\r\n * @param referenceSpace reference space to use\r\n * @param xrCamera the xr camera, used for parenting\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame, referenceSpace: XRReferenceSpace, xrCamera: WebXRCamera) {\r\n const pose = xrFrame.getPose(this.inputSource.targetRaySpace, referenceSpace);\r\n this._lastXRPose = pose;\r\n\r\n // Update the pointer mesh\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n this.pointer.position.set(pos.x, pos.y, pos.z);\r\n const orientation = pose.transform.orientation;\r\n this.pointer.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.pointer.position.z *= -1;\r\n this.pointer.rotationQuaternion!.z *= -1;\r\n this.pointer.rotationQuaternion!.w *= -1;\r\n }\r\n this.pointer.parent = xrCamera.parent;\r\n }\r\n\r\n // Update the grip mesh if it exists\r\n if (this.inputSource.gripSpace && this.grip) {\r\n const pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n const orientation = pose.transform.orientation;\r\n this.grip.position.set(pos.x, pos.y, pos.z);\r\n this.grip.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.grip.position.z *= -1;\r\n this.grip.rotationQuaternion!.z *= -1;\r\n this.grip.rotationQuaternion!.w *= -1;\r\n }\r\n }\r\n this.grip.parent = xrCamera.parent;\r\n }\r\n if (this.motionController) {\r\n // either update buttons only or also position, if in gamepad mode\r\n this.motionController.updateFromXRFrame(xrFrame);\r\n }\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport type { IWebXRControllerOptions } from \"./webXRInputSource\";\r\nimport { WebXRInputSource } from \"./webXRInputSource\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\n\r\n/**\r\n * The schema for initialization options of the XR Input class\r\n */\r\nexport interface IWebXRInputOptions {\r\n /**\r\n * If set to true no model will be automatically loaded\r\n */\r\n doNotLoadControllerMeshes?: boolean;\r\n\r\n /**\r\n * If set, this profile will be used for all controllers loaded (for example \"microsoft-mixed-reality\")\r\n * If not found, the xr input profile data will be used.\r\n * Profiles are defined here - https://github.com/immersive-web/webxr-input-profiles/\r\n */\r\n forceInputProfile?: string;\r\n\r\n /**\r\n * Do not send a request to the controller repository to load the profile.\r\n *\r\n * Instead, use the controllers available in babylon itself.\r\n */\r\n disableOnlineControllerRepository?: boolean;\r\n\r\n /**\r\n * A custom URL for the controllers repository\r\n */\r\n customControllersRepositoryURL?: string;\r\n\r\n /**\r\n * Should the controller model's components not move according to the user input\r\n */\r\n disableControllerAnimation?: boolean;\r\n\r\n /**\r\n * Optional options to pass to the controller. Will be overridden by the Input options where applicable\r\n */\r\n controllerOptions?: IWebXRControllerOptions;\r\n}\r\n/**\r\n * XR input used to track XR inputs such as controllers/rays\r\n */\r\nexport class WebXRInput implements IDisposable {\r\n /**\r\n * XR controllers being tracked\r\n */\r\n public controllers: Array = [];\r\n private _frameObserver: Nullable>;\r\n private _sessionEndedObserver: Nullable>;\r\n private _sessionInitObserver: Nullable>;\r\n /**\r\n * Event when a controller has been connected/added\r\n */\r\n public onControllerAddedObservable = new Observable();\r\n /**\r\n * Event when a controller has been removed/disconnected\r\n */\r\n public onControllerRemovedObservable = new Observable();\r\n\r\n /**\r\n * Initializes the WebXRInput\r\n * @param xrSessionManager the xr session manager for this session\r\n * @param xrCamera the WebXR camera for this session. Mainly used for teleportation\r\n * @param _options = initialization options for this xr input\r\n */\r\n public constructor(\r\n /**\r\n * the xr session manager for this session\r\n */\r\n public xrSessionManager: WebXRSessionManager,\r\n /**\r\n * the WebXR camera for this session. Mainly used for teleportation\r\n */\r\n public xrCamera: WebXRCamera,\r\n private readonly _options: IWebXRInputOptions = {}\r\n ) {\r\n // Remove controllers when exiting XR\r\n this._sessionEndedObserver = this.xrSessionManager.onXRSessionEnded.add(() => {\r\n this._addAndRemoveControllers(\r\n [],\r\n this.controllers.map((c) => {\r\n return c.inputSource;\r\n })\r\n );\r\n });\r\n\r\n this._sessionInitObserver = this.xrSessionManager.onXRSessionInit.add((session) => {\r\n session.addEventListener(\"inputsourceschange\", this._onInputSourcesChange);\r\n });\r\n\r\n this._frameObserver = this.xrSessionManager.onXRFrameObservable.add((frame) => {\r\n // Update controller pose info\r\n this.controllers.forEach((controller) => {\r\n controller.updateFromXRFrame(frame, this.xrSessionManager.referenceSpace, this.xrCamera);\r\n });\r\n });\r\n\r\n if (this._options.customControllersRepositoryURL) {\r\n WebXRMotionControllerManager.BaseRepositoryUrl = this._options.customControllersRepositoryURL;\r\n }\r\n\r\n WebXRMotionControllerManager.UseOnlineRepository = !this._options.disableOnlineControllerRepository;\r\n if (WebXRMotionControllerManager.UseOnlineRepository) {\r\n // pre-load the profiles list to load the controllers quicker afterwards\r\n try {\r\n WebXRMotionControllerManager.UpdateProfilesList().catch(() => {\r\n WebXRMotionControllerManager.UseOnlineRepository = false;\r\n });\r\n } catch (e) {\r\n WebXRMotionControllerManager.UseOnlineRepository = false;\r\n }\r\n }\r\n }\r\n\r\n private _onInputSourcesChange = (event: XRInputSourceChangeEvent) => {\r\n this._addAndRemoveControllers(event.added, event.removed);\r\n };\r\n\r\n private _addAndRemoveControllers(addInputs: readonly XRInputSource[], removeInputs: readonly XRInputSource[]) {\r\n // Add controllers if they don't already exist\r\n const sources = this.controllers.map((c) => {\r\n return c.inputSource;\r\n });\r\n for (const input of addInputs) {\r\n if (sources.indexOf(input) === -1) {\r\n const controller = new WebXRInputSource(this.xrSessionManager.scene, input, {\r\n ...(this._options.controllerOptions || {}),\r\n forceControllerProfile: this._options.forceInputProfile,\r\n doNotLoadControllerMesh: this._options.doNotLoadControllerMeshes,\r\n disableMotionControllerAnimation: this._options.disableControllerAnimation,\r\n });\r\n this.controllers.push(controller);\r\n this.onControllerAddedObservable.notifyObservers(controller);\r\n }\r\n }\r\n\r\n // Remove and dispose of controllers to be disposed\r\n const keepControllers: Array = [];\r\n const removedControllers: Array = [];\r\n this.controllers.forEach((c) => {\r\n if (removeInputs.indexOf(c.inputSource) === -1) {\r\n keepControllers.push(c);\r\n } else {\r\n removedControllers.push(c);\r\n }\r\n });\r\n this.controllers = keepControllers;\r\n removedControllers.forEach((c) => {\r\n this.onControllerRemovedObservable.notifyObservers(c);\r\n c.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this.controllers.forEach((c) => {\r\n c.dispose();\r\n });\r\n this.xrSessionManager.onXRFrameObservable.remove(this._frameObserver);\r\n this.xrSessionManager.onXRSessionInit.remove(this._sessionInitObserver);\r\n this.xrSessionManager.onXRSessionEnded.remove(this._sessionEndedObserver);\r\n this.onControllerAddedObservable.clear();\r\n this.onControllerRemovedObservable.clear();\r\n\r\n // clear the controller cache\r\n WebXRMotionControllerManager.ClearControllerCache();\r\n }\r\n}\r\n","import type { IWebXRFeature } from \"../webXRFeaturesManager\";\r\nimport type { Observer, Observable, EventState } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\n\r\n/**\r\n * This is the base class for all WebXR features.\r\n * Since most features require almost the same resources and callbacks, this class can be used to simplify the development\r\n * Note that since the features manager is using the `IWebXRFeature` you are in no way obligated to use this class\r\n */\r\nexport abstract class WebXRAbstractFeature implements IWebXRFeature {\r\n private _attached: boolean = false;\r\n private _removeOnDetach: {\r\n observer: Nullable>;\r\n observable: Observable;\r\n }[] = [];\r\n\r\n /**\r\n * Is this feature disposed?\r\n */\r\n public isDisposed: boolean = false;\r\n\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n public disableAutoAttach: boolean = false;\r\n\r\n /**\r\n * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)\r\n */\r\n public xrNativeFeatureName: string = \"\";\r\n\r\n /**\r\n * Construct a new (abstract) WebXR feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(protected _xrSessionManager: WebXRSessionManager) {}\r\n\r\n /**\r\n * Is this feature attached\r\n */\r\n public get attached() {\r\n return this._attached;\r\n }\r\n\r\n /**\r\n * attach this feature\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful, false is failed or already attached\r\n */\r\n public attach(force?: boolean): boolean {\r\n // do not attach a disposed feature\r\n if (this.isDisposed) {\r\n return false;\r\n }\r\n if (!force) {\r\n if (this.attached) {\r\n return false;\r\n }\r\n } else {\r\n if (this.attached) {\r\n // detach first, to be sure\r\n this.detach();\r\n }\r\n }\r\n\r\n this._attached = true;\r\n this._addNewAttachObserver(this._xrSessionManager.onXRFrameObservable, (frame) => this._onXRFrame(frame));\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n *\r\n * @returns true if successful, false if failed or already detached\r\n */\r\n public detach(): boolean {\r\n if (!this._attached) {\r\n this.disableAutoAttach = true;\r\n return false;\r\n }\r\n this._attached = false;\r\n this._removeOnDetach.forEach((toRemove) => {\r\n toRemove.observable.remove(toRemove.observer);\r\n });\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n this.detach();\r\n this.isDisposed = true;\r\n }\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n public isCompatible(): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * This is used to register callbacks that will automatically be removed when detach is called.\r\n * @param observable the observable to which the observer will be attached\r\n * @param callback the callback to register\r\n */\r\n protected _addNewAttachObserver(observable: Observable, callback: (eventData: T, eventState: EventState) => void) {\r\n this._removeOnDetach.push({\r\n observable,\r\n observer: observable.add(callback),\r\n });\r\n }\r\n\r\n /**\r\n * Code in this function will be executed on each xrFrame received from the browser.\r\n * This function will not execute after the feature is detached.\r\n * @param _xrFrame the current frame\r\n */\r\n protected abstract _onXRFrame(_xrFrame: XRFrame): void;\r\n}\r\n","import type { IDisposable } from \"../scene\";\r\nimport { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { PointerInfoPre } from \"../Events/pointerEvents\";\r\nimport { PointerInfo, PointerEventTypes } from \"../Events/pointerEvents\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { HemisphericLight } from \"../Lights/hemisphericLight\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { IPointerEvent } from \"../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Renders a layer on top of an existing scene\r\n */\r\nexport class UtilityLayerRenderer implements IDisposable {\r\n private _pointerCaptures: { [pointerId: number]: boolean } = {};\r\n private _lastPointerEvents: { [pointerId: number]: boolean } = {};\r\n /** @internal */\r\n public static _DefaultUtilityLayer: Nullable = null;\r\n /** @internal */\r\n public static _DefaultKeepDepthUtilityLayer: Nullable = null;\r\n private _sharedGizmoLight: Nullable = null;\r\n\r\n private _renderCamera: Nullable = null;\r\n\r\n /**\r\n * Gets the camera that is used to render the utility layer (when not set, this will be the last active camera)\r\n * @param getRigParentIfPossible if the current active camera is a rig camera, should its parent camera be returned\r\n * @returns the camera that is used when rendering the utility layer\r\n */\r\n public getRenderCamera(getRigParentIfPossible?: boolean) {\r\n if (this._renderCamera) {\r\n return this._renderCamera;\r\n } else {\r\n let activeCam: Camera;\r\n if (this.originalScene.activeCameras && this.originalScene.activeCameras.length > 1) {\r\n activeCam = this.originalScene.activeCameras[this.originalScene.activeCameras.length - 1];\r\n } else {\r\n activeCam = this.originalScene.activeCamera!;\r\n }\r\n\r\n if (getRigParentIfPossible && activeCam && activeCam.isRigCamera) {\r\n return activeCam.rigParent!;\r\n }\r\n return activeCam;\r\n }\r\n }\r\n /**\r\n * Sets the camera that should be used when rendering the utility layer (If set to null the last active camera will be used)\r\n * @param cam the camera that should be used when rendering the utility layer\r\n */\r\n public setRenderCamera(cam: Nullable) {\r\n this._renderCamera = cam;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Light which used by gizmos to get light shading\r\n */\r\n public _getSharedGizmoLight(): HemisphericLight {\r\n if (!this._sharedGizmoLight) {\r\n this._sharedGizmoLight = new HemisphericLight(\"shared gizmo light\", new Vector3(0, 1, 0), this.utilityLayerScene);\r\n this._sharedGizmoLight.intensity = 2;\r\n this._sharedGizmoLight.groundColor = Color3.Gray();\r\n }\r\n return this._sharedGizmoLight;\r\n }\r\n\r\n /**\r\n * If the picking should be done on the utility layer prior to the actual scene (Default: true)\r\n */\r\n public pickUtilitySceneFirst = true;\r\n /**\r\n * A shared utility layer that can be used to overlay objects into a scene (Depth map of the previous scene is cleared before drawing on top of it)\r\n */\r\n public static get DefaultUtilityLayer(): UtilityLayerRenderer {\r\n if (UtilityLayerRenderer._DefaultUtilityLayer == null) {\r\n return UtilityLayerRenderer._CreateDefaultUtilityLayerFromScene(EngineStore.LastCreatedScene!);\r\n }\r\n\r\n return UtilityLayerRenderer._DefaultUtilityLayer;\r\n }\r\n\r\n /**\r\n * Creates an utility layer, and set it as a default utility layer\r\n * @param scene associated scene\r\n * @internal\r\n */\r\n public static _CreateDefaultUtilityLayerFromScene(scene: Scene): UtilityLayerRenderer {\r\n UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(scene);\r\n UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\r\n UtilityLayerRenderer._DefaultUtilityLayer = null;\r\n });\r\n\r\n return UtilityLayerRenderer._DefaultUtilityLayer;\r\n }\r\n /**\r\n * A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)\r\n */\r\n public static get DefaultKeepDepthUtilityLayer(): UtilityLayerRenderer {\r\n if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(EngineStore.LastCreatedScene!);\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;\r\n });\r\n }\r\n return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;\r\n }\r\n\r\n /**\r\n * The scene that is rendered on top of the original scene\r\n */\r\n public utilityLayerScene: Scene;\r\n\r\n /**\r\n * If the utility layer should automatically be rendered on top of existing scene\r\n */\r\n public shouldRender: boolean = true;\r\n /**\r\n * If set to true, only pointer down onPointerObservable events will be blocked when picking is occluded by original scene\r\n */\r\n public onlyCheckPointerDownEvents = true;\r\n\r\n /**\r\n * If set to false, only pointerUp, pointerDown and pointerMove will be sent to the utilityLayerScene (false by default)\r\n */\r\n public processAllEvents = false;\r\n\r\n /**\r\n * Set to false to disable picking\r\n */\r\n public pickingEnabled = true;\r\n\r\n /**\r\n * Observable raised when the pointer moves from the utility layer scene to the main scene\r\n */\r\n public onPointerOutObservable = new Observable();\r\n\r\n /** Gets or sets a predicate that will be used to indicate utility meshes present in the main scene */\r\n public mainSceneTrackerPredicate: (mesh: Nullable) => boolean;\r\n\r\n private _afterRenderObserver: Nullable>;\r\n private _sceneDisposeObserver: Nullable>;\r\n private _originalPointerObserver: Nullable>;\r\n /**\r\n * Instantiates a UtilityLayerRenderer\r\n * @param originalScene the original scene that will be rendered on top of\r\n * @param handleEvents boolean indicating if the utility layer should handle events\r\n */\r\n constructor(\r\n /** the original scene that will be rendered on top of */\r\n public originalScene: Scene,\r\n handleEvents: boolean = true\r\n ) {\r\n // Create scene which will be rendered in the foreground and remove it from being referenced by engine to avoid interfering with existing app\r\n this.utilityLayerScene = new Scene(originalScene.getEngine(), { virtual: true });\r\n this.utilityLayerScene.useRightHandedSystem = originalScene.useRightHandedSystem;\r\n this.utilityLayerScene._allowPostProcessClearColor = false;\r\n\r\n // Deactivate post processes\r\n this.utilityLayerScene.postProcessesEnabled = false;\r\n\r\n // Detach controls on utility scene, events will be fired by logic below to handle picking priority\r\n this.utilityLayerScene.detachControl();\r\n\r\n if (handleEvents) {\r\n this._originalPointerObserver = originalScene.onPrePointerObservable.add((prePointerInfo) => {\r\n if (!this.utilityLayerScene.activeCamera) {\r\n return;\r\n }\r\n if (!this.pickingEnabled) {\r\n return;\r\n }\r\n\r\n if (!this.processAllEvents) {\r\n if (\r\n prePointerInfo.type !== PointerEventTypes.POINTERMOVE &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERUP &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERDOWN &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERDOUBLETAP\r\n ) {\r\n return;\r\n }\r\n }\r\n this.utilityLayerScene.pointerX = originalScene.pointerX;\r\n this.utilityLayerScene.pointerY = originalScene.pointerY;\r\n const pointerEvent = prePointerInfo.event;\r\n if (originalScene!.isPointerCaptured(pointerEvent.pointerId)) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n return;\r\n }\r\n\r\n const getNearPickDataForScene = (scene: Scene) => {\r\n let scenePick = null;\r\n\r\n if (prePointerInfo.nearInteractionPickingInfo) {\r\n if (prePointerInfo.nearInteractionPickingInfo.pickedMesh!.getScene() == scene) {\r\n scenePick = prePointerInfo.nearInteractionPickingInfo;\r\n } else {\r\n scenePick = new PickingInfo();\r\n }\r\n } else if (scene !== this.utilityLayerScene && prePointerInfo.originalPickingInfo) {\r\n scenePick = prePointerInfo.originalPickingInfo;\r\n } else {\r\n let previousActiveCamera: Nullable = null;\r\n // If a camera is set for rendering with this layer\r\n // it will also be used for the ray computation\r\n // To preserve back compat and because scene.pick always use activeCamera\r\n // it's substituted temporarily and a new scenePick is forced.\r\n // otherwise, the ray with previously active camera is always used.\r\n // It's set back to previous activeCamera after operation.\r\n if (this._renderCamera) {\r\n previousActiveCamera = scene._activeCamera;\r\n scene._activeCamera = this._renderCamera;\r\n prePointerInfo.ray = null;\r\n }\r\n scenePick = prePointerInfo.ray ? scene.pickWithRay(prePointerInfo.ray) : scene.pick(originalScene.pointerX, originalScene.pointerY);\r\n if (previousActiveCamera) {\r\n scene._activeCamera = previousActiveCamera;\r\n }\r\n }\r\n\r\n return scenePick;\r\n };\r\n\r\n const utilityScenePick = getNearPickDataForScene(this.utilityLayerScene);\r\n\r\n if (!prePointerInfo.ray && utilityScenePick) {\r\n prePointerInfo.ray = utilityScenePick.ray;\r\n }\r\n\r\n // always fire the prepointer observable\r\n this.utilityLayerScene.onPrePointerObservable.notifyObservers(prePointerInfo);\r\n\r\n // allow every non pointer down event to flow to the utility layer\r\n if (this.onlyCheckPointerDownEvents && prePointerInfo.type != PointerEventTypes.POINTERDOWN) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(\r\n new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick),\r\n prePointerInfo.type\r\n );\r\n }\r\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n }\r\n return;\r\n }\r\n\r\n if (this.utilityLayerScene.autoClearDepthAndStencil || this.pickUtilitySceneFirst) {\r\n // If this layer is an overlay, check if this layer was hit and if so, skip pointer events for the main scene\r\n if (utilityScenePick && utilityScenePick.hit) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(\r\n new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick),\r\n prePointerInfo.type\r\n );\r\n }\r\n prePointerInfo.skipOnPointerObservable = true;\r\n }\r\n } else {\r\n const originalScenePick = getNearPickDataForScene(originalScene);\r\n const pointerEvent = prePointerInfo.event;\r\n\r\n // If the layer can be occluded by the original scene, only fire pointer events to the first layer that hit they ray\r\n if (originalScenePick && utilityScenePick) {\r\n // No pick in utility scene\r\n if (utilityScenePick.distance === 0 && originalScenePick.pickedMesh) {\r\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\r\n // We touched an utility mesh present in the main scene\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n prePointerInfo.skipOnPointerObservable = true;\r\n } else if (prePointerInfo.type === PointerEventTypes.POINTERDOWN) {\r\n this._pointerCaptures[pointerEvent.pointerId] = true;\r\n } else if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\r\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\r\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\r\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\r\n delete this._lastPointerEvents[pointerEvent.pointerId];\r\n }\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n }\r\n } else if (!this._pointerCaptures[pointerEvent.pointerId] && (utilityScenePick.distance < originalScenePick.distance || originalScenePick.distance === 0)) {\r\n // We pick something in utility scene or the pick in utility is closer than the one in main scene\r\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\r\n // If a previous utility layer set this, do not unset this\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n prePointerInfo.skipOnPointerObservable = utilityScenePick.distance > 0;\r\n }\r\n } else if (!this._pointerCaptures[pointerEvent.pointerId] && utilityScenePick.distance >= originalScenePick.distance) {\r\n // We have a pick in both scenes but main is closer than utility\r\n\r\n // We touched an utility mesh present in the main scene\r\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n prePointerInfo.skipOnPointerObservable = true;\r\n } else {\r\n if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\r\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\r\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\r\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\r\n delete this._lastPointerEvents[pointerEvent.pointerId];\r\n }\r\n }\r\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\r\n }\r\n }\r\n\r\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n }\r\n }\r\n }\r\n });\r\n\r\n // As a newly added utility layer will be rendered over the screen last, it's pointer events should be processed first\r\n if (this._originalPointerObserver) {\r\n originalScene.onPrePointerObservable.makeObserverTopPriority(this._originalPointerObserver);\r\n }\r\n }\r\n\r\n // Render directly on top of existing scene without clearing\r\n this.utilityLayerScene.autoClear = false;\r\n\r\n this._afterRenderObserver = this.originalScene.onAfterRenderCameraObservable.add((camera) => {\r\n // Only render when the render camera finishes rendering\r\n if (this.shouldRender && camera == this.getRenderCamera()) {\r\n this.render();\r\n }\r\n });\r\n\r\n this._sceneDisposeObserver = this.originalScene.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n\r\n this._updateCamera();\r\n }\r\n\r\n private _notifyObservers(prePointerInfo: PointerInfoPre, pickInfo: PickingInfo, pointerEvent: IPointerEvent) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(new PointerInfo(prePointerInfo.type, prePointerInfo.event, pickInfo), prePointerInfo.type);\r\n this._lastPointerEvents[pointerEvent.pointerId] = true;\r\n }\r\n }\r\n\r\n /**\r\n * Renders the utility layers scene on top of the original scene\r\n */\r\n public render() {\r\n this._updateCamera();\r\n if (this.utilityLayerScene.activeCamera) {\r\n // Set the camera's scene to utility layers scene\r\n const oldScene = this.utilityLayerScene.activeCamera.getScene();\r\n const camera = this.utilityLayerScene.activeCamera;\r\n camera._scene = this.utilityLayerScene;\r\n if (camera.leftCamera) {\r\n camera.leftCamera._scene = this.utilityLayerScene;\r\n }\r\n if (camera.rightCamera) {\r\n camera.rightCamera._scene = this.utilityLayerScene;\r\n }\r\n\r\n this.utilityLayerScene.render(false);\r\n\r\n // Reset camera's scene back to original\r\n camera._scene = oldScene;\r\n if (camera.leftCamera) {\r\n camera.leftCamera._scene = oldScene;\r\n }\r\n if (camera.rightCamera) {\r\n camera.rightCamera._scene = oldScene;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the renderer\r\n */\r\n public dispose() {\r\n this.onPointerOutObservable.clear();\r\n\r\n if (this._afterRenderObserver) {\r\n this.originalScene.onAfterCameraRenderObservable.remove(this._afterRenderObserver);\r\n }\r\n if (this._sceneDisposeObserver) {\r\n this.originalScene.onDisposeObservable.remove(this._sceneDisposeObserver);\r\n }\r\n if (this._originalPointerObserver) {\r\n this.originalScene.onPrePointerObservable.remove(this._originalPointerObserver);\r\n }\r\n this.utilityLayerScene.dispose();\r\n }\r\n\r\n private _updateCamera() {\r\n this.utilityLayerScene.cameraToUseForPointers = this.getRenderCamera();\r\n this.utilityLayerScene.activeCamera = this.getRenderCamera();\r\n }\r\n}\r\n","import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { Axis } from \"../../Maths/math.axis\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { CreateCylinder } from \"../../Meshes/Builders/cylinderBuilder\";\r\nimport { CreateTorus } from \"../../Meshes/Builders/torusBuilder\";\r\nimport { Ray } from \"../../Culling/ray\";\r\nimport { PickingInfo } from \"../../Collisions/pickingInfo\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { UtilityLayerRenderer } from \"../../Rendering/utilityLayerRenderer\";\r\nimport type { WebXRAbstractMotionController } from \"../motionController/webXRAbstractMotionController\";\r\nimport type { WebXRCamera } from \"../webXRCamera\";\r\nimport type { Node } from \"../../node\";\r\nimport { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Options interface for the pointer selection module\r\n */\r\nexport interface IWebXRControllerPointerSelectionOptions {\r\n /**\r\n * if provided, this scene will be used to render meshes.\r\n */\r\n customUtilityLayerScene?: Scene;\r\n /**\r\n * Disable the pointer up event when the xr controller in screen and gaze mode is disposed (meaning - when the user removed the finger from the screen)\r\n * If not disabled, the last picked point will be used to execute a pointer up event\r\n * If disabled, pointer up event will be triggered right after the pointer down event.\r\n * Used in screen and gaze target ray mode only\r\n */\r\n disablePointerUpOnTouchOut: boolean;\r\n /**\r\n * For gaze mode for tracked-pointer / controllers (time to select instead of button press)\r\n */\r\n forceGazeMode: boolean;\r\n /**\r\n * Factor to be applied to the pointer-moved function in the gaze mode. How sensitive should the gaze mode be when checking if the pointer moved\r\n * to start a new countdown to the pointer down event.\r\n * Defaults to 1.\r\n */\r\n gazeModePointerMovedFactor?: number;\r\n /**\r\n * Different button type to use instead of the main component\r\n */\r\n overrideButtonId?: string;\r\n /**\r\n * use this rendering group id for the meshes (optional)\r\n */\r\n renderingGroupId?: number;\r\n /**\r\n * The amount of time in milliseconds it takes between pick found something to a pointer down event.\r\n * Used in gaze modes. Tracked pointer uses the trigger, screen uses touch events\r\n * 3000 means 3 seconds between pointing at something and selecting it\r\n */\r\n timeToSelect?: number;\r\n /**\r\n * Should meshes created here be added to a utility layer or the main scene\r\n */\r\n useUtilityLayer?: boolean;\r\n /**\r\n * Optional WebXR camera to be used for gaze selection\r\n */\r\n gazeCamera?: WebXRCamera;\r\n /**\r\n * the xr input to use with this pointer selection\r\n */\r\n xrInput: WebXRInput;\r\n\r\n /**\r\n * Should the scene pointerX and pointerY update be disabled\r\n * This is required for fullscreen AR GUI, but might slow down other experiences.\r\n * Disable in VR, if not needed.\r\n * The first rig camera (left eye) will be used to calculate the projection\r\n */\r\n disableScenePointerVectorUpdate: boolean;\r\n\r\n /**\r\n * Enable pointer selection on all controllers instead of switching between them\r\n */\r\n enablePointerSelectionOnAllControllers?: boolean;\r\n\r\n /**\r\n * The preferred hand to give the pointer selection to. This will be prioritized when the controller initialize.\r\n * If switch is enabled, it will still allow the user to switch between the different controllers\r\n */\r\n preferredHandedness?: XRHandedness;\r\n\r\n /**\r\n * Disable switching the pointer selection from one controller to the other.\r\n * If the preferred hand is set it will be fixed on this hand, and if not it will be fixed on the first controller added to the scene\r\n */\r\n disableSwitchOnClick?: boolean;\r\n\r\n /**\r\n * The maximum distance of the pointer selection feature. Defaults to 100.\r\n */\r\n maxPointerDistance?: number;\r\n\r\n /**\r\n * A function that will be called when a new selection mesh is generated.\r\n * This function should return a mesh that will be used as the selection mesh.\r\n * The default is a torus with a 0.01 diameter and 0.0075 thickness .\r\n */\r\n customSelectionMeshGenerator?: () => Mesh;\r\n\r\n /**\r\n * A function that will be called when a new laser pointer mesh is generated.\r\n * This function should return a mesh that will be used as the laser pointer mesh.\r\n * The height (y) of the mesh must be 1.\r\n */\r\n customLasterPointerMeshGenerator?: () => AbstractMesh;\r\n}\r\n\r\n/**\r\n * A module that will enable pointer selection for motion controllers of XR Input Sources\r\n */\r\nexport class WebXRControllerPointerSelection extends WebXRAbstractFeature {\r\n private static _IdCounter = 200;\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n\r\n const { laserPointer, selectionMesh } = this._generateNewMeshPair(xrController.pointer);\r\n\r\n // get two new meshes\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n laserPointer,\r\n selectionMesh,\r\n meshUnderPointer: null,\r\n pick: null,\r\n tmpRay: new Ray(new Vector3(), new Vector3()),\r\n disabledByNearInteraction: false,\r\n id: WebXRControllerPointerSelection._IdCounter++,\r\n };\r\n\r\n if (this._attachedController) {\r\n if (\r\n !this._options.enablePointerSelectionOnAllControllers &&\r\n this._options.preferredHandedness &&\r\n xrController.inputSource.handedness === this._options.preferredHandedness\r\n ) {\r\n this._attachedController = xrController.uniqueId;\r\n }\r\n } else {\r\n if (!this._options.enablePointerSelectionOnAllControllers) {\r\n this._attachedController = xrController.uniqueId;\r\n }\r\n }\r\n\r\n switch (xrController.inputSource.targetRayMode) {\r\n case \"tracked-pointer\":\r\n return this._attachTrackedPointerRayMode(xrController);\r\n case \"gaze\":\r\n return this._attachGazeMode(xrController);\r\n case \"screen\":\r\n return this._attachScreenRayMode(xrController);\r\n }\r\n };\r\n\r\n private _controllers: {\r\n [controllerUniqueId: string]: {\r\n xrController?: WebXRInputSource;\r\n webXRCamera?: WebXRCamera;\r\n selectionComponent?: WebXRControllerComponent;\r\n onButtonChangedObserver?: Nullable>;\r\n onFrameObserver?: Nullable>;\r\n laserPointer: AbstractMesh;\r\n selectionMesh: AbstractMesh;\r\n meshUnderPointer: Nullable;\r\n pick: Nullable;\r\n id: number;\r\n tmpRay: Ray;\r\n disabledByNearInteraction: boolean;\r\n // event support\r\n eventListeners?: { [event in XREventType]?: (event: XRInputSourceEvent) => void };\r\n screenCoordinates?: { x: number; y: number };\r\n pointerDownTriggered?: boolean;\r\n finalPointerUpTriggered?: boolean;\r\n };\r\n } = {};\r\n private _scene: Scene;\r\n private _tmpVectorForPickCompare = new Vector3();\r\n\r\n private _attachedController: string;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.POINTER_SELECTION;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Disable lighting on the laser pointer (so it will always be visible)\r\n */\r\n public disablePointerLighting: boolean = true;\r\n /**\r\n * Disable lighting on the selection mesh (so it will always be visible)\r\n */\r\n public disableSelectionMeshLighting: boolean = true;\r\n /**\r\n * Should the laser pointer be displayed\r\n */\r\n public displayLaserPointer: boolean = true;\r\n /**\r\n * Should the selection mesh be displayed (The ring at the end of the laser pointer)\r\n */\r\n public displaySelectionMesh: boolean = true;\r\n /**\r\n * This color will be set to the laser pointer when selection is triggered\r\n */\r\n public laserPointerPickedColor: Color3 = new Color3(0.9, 0.9, 0.9);\r\n /**\r\n * Default color of the laser pointer\r\n */\r\n public laserPointerDefaultColor: Color3 = new Color3(0.7, 0.7, 0.7);\r\n /**\r\n * default color of the selection ring\r\n */\r\n public selectionMeshDefaultColor: Color3 = new Color3(0.8, 0.8, 0.8);\r\n /**\r\n * This color will be applied to the selection ring when selection is triggered\r\n */\r\n public selectionMeshPickedColor: Color3 = new Color3(0.3, 0.3, 1.0);\r\n\r\n /**\r\n * Optional filter to be used for ray selection. This predicate shares behavior with\r\n * scene.pointerMovePredicate which takes priority if it is also assigned.\r\n */\r\n public raySelectionPredicate: (mesh: AbstractMesh) => boolean;\r\n\r\n /**\r\n * constructs a new background remover module\r\n * @param _xrSessionManager the session manager for this module\r\n * @param _options read-only options to be used in this module\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private readonly _options: IWebXRControllerPointerSelectionOptions) {\r\n super(_xrSessionManager);\r\n this._scene = this._xrSessionManager.scene;\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n this._options.xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n this._scene.constantlyUpdateMeshUnderPointer = true;\r\n\r\n if (this._options.gazeCamera) {\r\n const webXRCamera = this._options.gazeCamera;\r\n\r\n const { laserPointer, selectionMesh } = this._generateNewMeshPair(webXRCamera);\r\n\r\n this._controllers[\"camera\"] = {\r\n webXRCamera,\r\n laserPointer,\r\n selectionMesh,\r\n meshUnderPointer: null,\r\n pick: null,\r\n tmpRay: new Ray(new Vector3(), new Vector3()),\r\n disabledByNearInteraction: false,\r\n id: WebXRControllerPointerSelection._IdCounter++,\r\n };\r\n this._attachGazeMode();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Will get the mesh under a specific pointer.\r\n * `scene.meshUnderPointer` will only return one mesh - either left or right.\r\n * @param controllerId the controllerId to check\r\n * @returns The mesh under pointer or null if no mesh is under the pointer\r\n */\r\n public getMeshUnderPointer(controllerId: string): Nullable {\r\n if (this._controllers[controllerId]) {\r\n return this._controllers[controllerId].meshUnderPointer;\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Get the xr controller that correlates to the pointer id in the pointer event\r\n *\r\n * @param id the pointer id to search for\r\n * @returns the controller that correlates to this id or null if not found\r\n */\r\n public getXRControllerByPointerId(id: number): Nullable {\r\n const keys = Object.keys(this._controllers);\r\n\r\n for (let i = 0; i < keys.length; ++i) {\r\n if (this._controllers[keys[i]].id === id) {\r\n return this._controllers[keys[i]].xrController || null;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getPointerSelectionDisabledByPointerId(id: number): boolean {\r\n const keys = Object.keys(this._controllers);\r\n\r\n for (let i = 0; i < keys.length; ++i) {\r\n if (this._controllers[keys[i]].id === id) {\r\n return this._controllers[keys[i]].disabledByNearInteraction;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setPointerSelectionDisabledByPointerId(id: number, state: boolean) {\r\n const keys = Object.keys(this._controllers);\r\n\r\n for (let i = 0; i < keys.length; ++i) {\r\n if (this._controllers[keys[i]].id === id) {\r\n this._controllers[keys[i]].disabledByNearInteraction = state;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n private _identityMatrix = Matrix.Identity();\r\n private _screenCoordinatesRef = Vector3.Zero();\r\n private _viewportRef = new Viewport(0, 0, 0, 0);\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n Object.keys(this._controllers).forEach((id) => {\r\n // only do this for the selected pointer\r\n const controllerData = this._controllers[id];\r\n if ((!this._options.enablePointerSelectionOnAllControllers && id !== this._attachedController) || controllerData.disabledByNearInteraction) {\r\n controllerData.selectionMesh.isVisible = false;\r\n controllerData.laserPointer.isVisible = false;\r\n controllerData.pick = null;\r\n return;\r\n }\r\n\r\n controllerData.laserPointer.isVisible = this.displayLaserPointer;\r\n\r\n let controllerGlobalPosition: Vector3;\r\n\r\n // Every frame check collisions/input\r\n if (controllerData.xrController) {\r\n controllerGlobalPosition = controllerData.xrController.pointer.position;\r\n controllerData.xrController.getWorldPointerRayToRef(controllerData.tmpRay);\r\n } else if (controllerData.webXRCamera) {\r\n controllerGlobalPosition = controllerData.webXRCamera.position;\r\n controllerData.webXRCamera.getForwardRayToRef(controllerData.tmpRay);\r\n } else {\r\n return;\r\n }\r\n\r\n if (this._options.maxPointerDistance) {\r\n controllerData.tmpRay.length = this._options.maxPointerDistance;\r\n }\r\n // update pointerX and pointerY of the scene. Only if the flag is set to true!\r\n if (!this._options.disableScenePointerVectorUpdate && controllerGlobalPosition) {\r\n const scene = this._xrSessionManager.scene;\r\n const camera = this._options.xrInput.xrCamera;\r\n if (camera) {\r\n camera.viewport.toGlobalToRef(scene.getEngine().getRenderWidth(), scene.getEngine().getRenderHeight(), this._viewportRef);\r\n Vector3.ProjectToRef(controllerGlobalPosition, this._identityMatrix, scene.getTransformMatrix(), this._viewportRef, this._screenCoordinatesRef);\r\n // stay safe\r\n if (\r\n typeof this._screenCoordinatesRef.x === \"number\" &&\r\n typeof this._screenCoordinatesRef.y === \"number\" &&\r\n !isNaN(this._screenCoordinatesRef.x) &&\r\n !isNaN(this._screenCoordinatesRef.y)\r\n ) {\r\n scene.pointerX = this._screenCoordinatesRef.x;\r\n scene.pointerY = this._screenCoordinatesRef.y;\r\n\r\n controllerData.screenCoordinates = {\r\n x: this._screenCoordinatesRef.x,\r\n y: this._screenCoordinatesRef.y,\r\n };\r\n }\r\n }\r\n }\r\n\r\n let utilityScenePick = null;\r\n if (this._utilityLayerScene) {\r\n utilityScenePick = this._utilityLayerScene.pickWithRay(controllerData.tmpRay, this._utilityLayerScene.pointerMovePredicate || this.raySelectionPredicate);\r\n }\r\n\r\n const originalScenePick = this._scene.pickWithRay(controllerData.tmpRay, this._scene.pointerMovePredicate || this.raySelectionPredicate);\r\n if (!utilityScenePick || !utilityScenePick.hit) {\r\n // No hit in utility scene\r\n controllerData.pick = originalScenePick;\r\n } else if (!originalScenePick || !originalScenePick.hit) {\r\n // No hit in original scene\r\n controllerData.pick = utilityScenePick;\r\n } else if (utilityScenePick.distance < originalScenePick.distance) {\r\n // Hit is closer in utility scene\r\n controllerData.pick = utilityScenePick;\r\n } else {\r\n // Hit is closer in original scene\r\n controllerData.pick = originalScenePick;\r\n }\r\n\r\n if (controllerData.pick && controllerData.xrController) {\r\n controllerData.pick.aimTransform = controllerData.xrController.pointer;\r\n controllerData.pick.gripTransform = controllerData.xrController.grip || null;\r\n }\r\n\r\n const pick = controllerData.pick;\r\n\r\n if (pick && pick.pickedPoint && pick.hit) {\r\n // Update laser state\r\n this._updatePointerDistance(controllerData.laserPointer, pick.distance);\r\n\r\n // Update cursor state\r\n controllerData.selectionMesh.position.copyFrom(pick.pickedPoint);\r\n controllerData.selectionMesh.scaling.x = Math.sqrt(pick.distance);\r\n controllerData.selectionMesh.scaling.y = Math.sqrt(pick.distance);\r\n controllerData.selectionMesh.scaling.z = Math.sqrt(pick.distance);\r\n\r\n // To avoid z-fighting\r\n const pickNormal = this._convertNormalToDirectionOfRay(pick.getNormal(true), controllerData.tmpRay);\r\n const deltaFighting = 0.001;\r\n controllerData.selectionMesh.position.copyFrom(pick.pickedPoint);\r\n if (pickNormal) {\r\n const axis1 = Vector3.Cross(Axis.Y, pickNormal);\r\n const axis2 = Vector3.Cross(pickNormal, axis1);\r\n Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, controllerData.selectionMesh.rotation);\r\n controllerData.selectionMesh.position.addInPlace(pickNormal.scale(deltaFighting));\r\n }\r\n controllerData.selectionMesh.isVisible = true && this.displaySelectionMesh;\r\n controllerData.meshUnderPointer = pick.pickedMesh;\r\n } else {\r\n controllerData.selectionMesh.isVisible = false;\r\n this._updatePointerDistance(controllerData.laserPointer, 1);\r\n controllerData.meshUnderPointer = null;\r\n }\r\n });\r\n }\r\n\r\n private get _utilityLayerScene() {\r\n return this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;\r\n }\r\n\r\n private _attachGazeMode(xrController?: WebXRInputSource) {\r\n const controllerData = this._controllers[(xrController && xrController.uniqueId) || \"camera\"];\r\n // attached when touched, detaches when raised\r\n const timeToSelect = this._options.timeToSelect || 3000;\r\n const sceneToRenderTo = this._options.useUtilityLayer ? this._utilityLayerScene : this._scene;\r\n let oldPick = new PickingInfo();\r\n const discMesh = CreateTorus(\r\n \"selection\",\r\n {\r\n diameter: 0.0035 * 15,\r\n thickness: 0.0025 * 6,\r\n tessellation: 20,\r\n },\r\n sceneToRenderTo\r\n );\r\n discMesh.isVisible = false;\r\n discMesh.isPickable = false;\r\n discMesh.parent = controllerData.selectionMesh;\r\n let timer = 0;\r\n let downTriggered = false;\r\n const pointerEventInit: PointerEventInit = {\r\n pointerId: controllerData.id,\r\n pointerType: \"xr\",\r\n };\r\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\r\n if (!controllerData.pick) {\r\n return;\r\n }\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n controllerData.laserPointer.material!.alpha = 0;\r\n discMesh.isVisible = false;\r\n if (controllerData.pick.hit) {\r\n if (!this._pickingMoved(oldPick, controllerData.pick)) {\r\n if (timer > timeToSelect / 10) {\r\n discMesh.isVisible = true;\r\n }\r\n\r\n timer += this._scene.getEngine().getDeltaTime();\r\n if (timer >= timeToSelect) {\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n // this pointerdown event is not setting the controllerData.pointerDownTriggered to avoid a pointerUp event when this feature is detached\r\n downTriggered = true;\r\n // pointer up right after down, if disable on touch out\r\n if (this._options.disablePointerUpOnTouchOut) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n }\r\n discMesh.isVisible = false;\r\n } else {\r\n const scaleFactor = 1 - timer / timeToSelect;\r\n discMesh.scaling.set(scaleFactor, scaleFactor, scaleFactor);\r\n }\r\n } else {\r\n if (downTriggered) {\r\n if (!this._options.disablePointerUpOnTouchOut) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n }\r\n }\r\n downTriggered = false;\r\n timer = 0;\r\n }\r\n } else {\r\n downTriggered = false;\r\n timer = 0;\r\n }\r\n\r\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\r\n\r\n oldPick = controllerData.pick;\r\n });\r\n\r\n if (this._options.renderingGroupId !== undefined) {\r\n discMesh.renderingGroupId = this._options.renderingGroupId;\r\n }\r\n if (xrController) {\r\n xrController.onDisposeObservable.addOnce(() => {\r\n if (controllerData.pick && !this._options.disablePointerUpOnTouchOut && downTriggered) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n controllerData.finalPointerUpTriggered = true;\r\n }\r\n discMesh.dispose();\r\n });\r\n }\r\n }\r\n\r\n private _attachScreenRayMode(xrController: WebXRInputSource) {\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n let downTriggered = false;\r\n const pointerEventInit: PointerEventInit = {\r\n pointerId: controllerData.id,\r\n pointerType: \"xr\",\r\n };\r\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n if (!controllerData.pick || (this._options.disablePointerUpOnTouchOut && downTriggered)) {\r\n return;\r\n }\r\n if (!downTriggered) {\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n controllerData.pointerDownTriggered = true;\r\n downTriggered = true;\r\n if (this._options.disablePointerUpOnTouchOut) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n }\r\n } else {\r\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\r\n }\r\n });\r\n xrController.onDisposeObservable.addOnce(() => {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n this._xrSessionManager.runInXRFrame(() => {\r\n if (controllerData.pick && !controllerData.finalPointerUpTriggered && downTriggered && !this._options.disablePointerUpOnTouchOut) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n controllerData.finalPointerUpTriggered = true;\r\n }\r\n });\r\n });\r\n }\r\n\r\n private _attachTrackedPointerRayMode(xrController: WebXRInputSource) {\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n if (this._options.forceGazeMode) {\r\n return this._attachGazeMode(xrController);\r\n }\r\n const pointerEventInit: PointerEventInit = {\r\n pointerId: controllerData.id,\r\n pointerType: \"xr\",\r\n };\r\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\r\n (controllerData.laserPointer.material).disableLighting = this.disablePointerLighting;\r\n (controllerData.selectionMesh.material).disableLighting = this.disableSelectionMeshLighting;\r\n\r\n if (controllerData.pick) {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\r\n }\r\n });\r\n if (xrController.inputSource.gamepad) {\r\n const init = (motionController: WebXRAbstractMotionController) => {\r\n if (this._options.overrideButtonId) {\r\n controllerData.selectionComponent = motionController.getComponent(this._options.overrideButtonId);\r\n }\r\n if (!controllerData.selectionComponent) {\r\n controllerData.selectionComponent = motionController.getMainComponent();\r\n }\r\n\r\n controllerData.onButtonChangedObserver = controllerData.selectionComponent.onButtonStateChangedObservable.add((component) => {\r\n if (component.changes.pressed) {\r\n const pressed = component.changes.pressed.current;\r\n if (controllerData.pick) {\r\n if (this._options.enablePointerSelectionOnAllControllers || xrController.uniqueId === this._attachedController) {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n if (pressed) {\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n controllerData.pointerDownTriggered = true;\r\n (controllerData.selectionMesh.material).emissiveColor = this.selectionMeshPickedColor;\r\n (controllerData.laserPointer.material).emissiveColor = this.laserPointerPickedColor;\r\n } else {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n (controllerData.selectionMesh.material).emissiveColor = this.selectionMeshDefaultColor;\r\n (controllerData.laserPointer.material).emissiveColor = this.laserPointerDefaultColor;\r\n }\r\n }\r\n } else {\r\n if (pressed && !this._options.enablePointerSelectionOnAllControllers && !this._options.disableSwitchOnClick) {\r\n this._attachedController = xrController.uniqueId;\r\n }\r\n }\r\n }\r\n });\r\n };\r\n if (xrController.motionController) {\r\n init(xrController.motionController);\r\n } else {\r\n xrController.onMotionControllerInitObservable.add(init);\r\n }\r\n } else {\r\n // use the select and squeeze events\r\n const selectStartListener = (event: XRInputSourceEvent) => {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n if (controllerData.xrController && event.inputSource === controllerData.xrController.inputSource && controllerData.pick) {\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n controllerData.pointerDownTriggered = true;\r\n (controllerData.selectionMesh.material).emissiveColor = this.selectionMeshPickedColor;\r\n (controllerData.laserPointer.material).emissiveColor = this.laserPointerPickedColor;\r\n }\r\n };\r\n\r\n const selectEndListener = (event: XRInputSourceEvent) => {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n if (controllerData.xrController && event.inputSource === controllerData.xrController.inputSource && controllerData.pick) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n (controllerData.selectionMesh.material).emissiveColor = this.selectionMeshDefaultColor;\r\n (controllerData.laserPointer.material).emissiveColor = this.laserPointerDefaultColor;\r\n }\r\n };\r\n\r\n controllerData.eventListeners = {\r\n selectend: selectEndListener,\r\n selectstart: selectStartListener,\r\n };\r\n\r\n this._xrSessionManager.session.addEventListener(\"selectstart\", selectStartListener);\r\n this._xrSessionManager.session.addEventListener(\"selectend\", selectEndListener);\r\n }\r\n }\r\n\r\n private _convertNormalToDirectionOfRay(normal: Nullable, ray: Ray) {\r\n if (normal) {\r\n const angle = Math.acos(Vector3.Dot(normal, ray.direction));\r\n if (angle < Math.PI / 2) {\r\n normal.scaleInPlace(-1);\r\n }\r\n }\r\n return normal;\r\n }\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n if (controllerData.selectionComponent) {\r\n if (controllerData.onButtonChangedObserver) {\r\n controllerData.selectionComponent.onButtonStateChangedObservable.remove(controllerData.onButtonChangedObserver);\r\n }\r\n }\r\n if (controllerData.onFrameObserver) {\r\n this._xrSessionManager.onXRFrameObservable.remove(controllerData.onFrameObserver);\r\n }\r\n if (controllerData.eventListeners) {\r\n Object.keys(controllerData.eventListeners).forEach((eventName: string) => {\r\n const func = controllerData.eventListeners && controllerData.eventListeners[eventName as XREventType];\r\n if (func) {\r\n // For future reference - this is an issue in the WebXR typings.\r\n this._xrSessionManager.session.removeEventListener(eventName as XREventType, func as any);\r\n }\r\n });\r\n }\r\n\r\n if (!controllerData.finalPointerUpTriggered && controllerData.pointerDownTriggered) {\r\n // Stay safe and fire a pointerup, in case it wasn't already triggered\r\n const pointerEventInit: PointerEventInit = {\r\n pointerId: controllerData.id,\r\n pointerType: \"xr\",\r\n };\r\n this._xrSessionManager.runInXRFrame(() => {\r\n this._augmentPointerInit(pointerEventInit, controllerData.id, controllerData.screenCoordinates);\r\n this._scene.simulatePointerUp(controllerData.pick || new PickingInfo(), pointerEventInit);\r\n controllerData.finalPointerUpTriggered = true;\r\n });\r\n }\r\n this._xrSessionManager.scene.onBeforeRenderObservable.addOnce(() => {\r\n try {\r\n controllerData.selectionMesh.dispose();\r\n controllerData.laserPointer.dispose();\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n if (this._attachedController === xrControllerUniqueId) {\r\n // check for other controllers\r\n const keys = Object.keys(this._controllers);\r\n if (keys.length) {\r\n this._attachedController = keys[0];\r\n } else {\r\n this._attachedController = \"\";\r\n }\r\n }\r\n } catch (e) {\r\n Tools.Warn(\"controller already detached.\");\r\n }\r\n });\r\n }\r\n\r\n private _generateNewMeshPair(meshParent: Node) {\r\n const sceneToRenderTo = this._options.useUtilityLayer ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene : this._scene;\r\n const laserPointer = this._options.customLasterPointerMeshGenerator\r\n ? this._options.customLasterPointerMeshGenerator()\r\n : CreateCylinder(\r\n \"laserPointer\",\r\n {\r\n height: 1,\r\n diameterTop: 0.0002,\r\n diameterBottom: 0.004,\r\n tessellation: 20,\r\n subdivisions: 1,\r\n },\r\n sceneToRenderTo\r\n );\r\n laserPointer.parent = meshParent;\r\n const laserPointerMaterial = new StandardMaterial(\"laserPointerMat\", sceneToRenderTo);\r\n laserPointerMaterial.emissiveColor = this.laserPointerDefaultColor;\r\n laserPointerMaterial.alpha = 0.7;\r\n laserPointer.material = laserPointerMaterial;\r\n laserPointer.rotation.x = Math.PI / 2;\r\n this._updatePointerDistance(laserPointer, 1);\r\n laserPointer.isPickable = false;\r\n laserPointer.isVisible = false;\r\n\r\n // Create a gaze tracker for the XR controller\r\n const selectionMesh = this._options.customSelectionMeshGenerator\r\n ? this._options.customSelectionMeshGenerator()\r\n : CreateTorus(\r\n \"gazeTracker\",\r\n {\r\n diameter: 0.0035 * 3,\r\n thickness: 0.0025 * 3,\r\n tessellation: 20,\r\n },\r\n sceneToRenderTo\r\n );\r\n selectionMesh.bakeCurrentTransformIntoVertices();\r\n selectionMesh.isPickable = false;\r\n selectionMesh.isVisible = false;\r\n const targetMat = new StandardMaterial(\"targetMat\", sceneToRenderTo);\r\n targetMat.specularColor = Color3.Black();\r\n targetMat.emissiveColor = this.selectionMeshDefaultColor;\r\n targetMat.backFaceCulling = false;\r\n selectionMesh.material = targetMat;\r\n\r\n if (this._options.renderingGroupId !== undefined) {\r\n laserPointer.renderingGroupId = this._options.renderingGroupId;\r\n selectionMesh.renderingGroupId = this._options.renderingGroupId;\r\n }\r\n\r\n return {\r\n laserPointer,\r\n selectionMesh,\r\n };\r\n }\r\n\r\n private _pickingMoved(oldPick: PickingInfo, newPick: PickingInfo) {\r\n if (!oldPick.hit || !newPick.hit) {\r\n return true;\r\n }\r\n if (!oldPick.pickedMesh || !oldPick.pickedPoint || !newPick.pickedMesh || !newPick.pickedPoint) {\r\n return true;\r\n }\r\n if (oldPick.pickedMesh !== newPick.pickedMesh) {\r\n return true;\r\n }\r\n oldPick.pickedPoint?.subtractToRef(newPick.pickedPoint, this._tmpVectorForPickCompare);\r\n this._tmpVectorForPickCompare.set(Math.abs(this._tmpVectorForPickCompare.x), Math.abs(this._tmpVectorForPickCompare.y), Math.abs(this._tmpVectorForPickCompare.z));\r\n const delta = (this._options.gazeModePointerMovedFactor || 1) * 0.01 * newPick.distance;\r\n const length = this._tmpVectorForPickCompare.length();\r\n if (length > delta) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private _updatePointerDistance(_laserPointer: AbstractMesh, distance: number = 100) {\r\n _laserPointer.scaling.y = distance;\r\n // a bit of distance from the controller\r\n if (this._scene.useRightHandedSystem) {\r\n distance *= -1;\r\n }\r\n _laserPointer.position.z = distance / 2 + 0.05;\r\n }\r\n\r\n private _augmentPointerInit(pointerEventInit: PointerEventInit, id: number, screenCoordinates?: { x: number; y: number }): void {\r\n pointerEventInit.pointerId = id;\r\n pointerEventInit.pointerType = \"xr\";\r\n if (screenCoordinates) {\r\n pointerEventInit.screenX = screenCoordinates.x;\r\n pointerEventInit.screenY = screenCoordinates.y;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public get lasterPointerDefaultColor(): Color3 {\r\n // here due to a typo\r\n return this.laserPointerDefaultColor;\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerPointerSelection.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerPointerSelection(xrSessionManager, options);\r\n },\r\n WebXRControllerPointerSelection.Version,\r\n true\r\n);\r\n","/**\r\n * Defines the kind of connection point for node based material\r\n */\r\nexport enum NodeMaterialBlockConnectionPointTypes {\r\n /** Float */\r\n Float = 0x0001,\r\n /** Int */\r\n Int = 0x0002,\r\n /** Vector2 */\r\n Vector2 = 0x0004,\r\n /** Vector3 */\r\n Vector3 = 0x0008,\r\n /** Vector4 */\r\n Vector4 = 0x0010,\r\n /** Color3 */\r\n Color3 = 0x0020,\r\n /** Color4 */\r\n Color4 = 0x0040,\r\n /** Matrix */\r\n Matrix = 0x0080,\r\n /** Custom object */\r\n Object = 0x0100,\r\n /** Detect type based on connection */\r\n AutoDetect = 0x0400,\r\n /** Output type that will be defined by input type */\r\n BasedOnInput = 0x0800,\r\n /** Bitmask of all types */\r\n All = 0x0fff,\r\n}\r\n","/**\r\n * Enum used to define the target of a block\r\n */\r\nexport enum NodeMaterialBlockTargets {\r\n /** Vertex shader */\r\n Vertex = 1,\r\n /** Fragment shader */\r\n Fragment = 2,\r\n /** Neutral */\r\n Neutral = 4,\r\n /** Vertex and Fragment */\r\n VertexAndFragment = Vertex | Fragment,\r\n}\r\n","import { NodeMaterialBlockConnectionPointTypes } from \"./Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport { NodeMaterialBlockTargets } from \"./Enums/nodeMaterialBlockTargets\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { InputBlock } from \"./Blocks/Input/inputBlock\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { NodeMaterialBlock } from \"./nodeMaterialBlock\";\r\n\r\n/**\r\n * Enum used to define the compatibility state between two connection points\r\n */\r\nexport enum NodeMaterialConnectionPointCompatibilityStates {\r\n /** Points are compatibles */\r\n Compatible,\r\n /** Points are incompatible because of their types */\r\n TypeIncompatible,\r\n /** Points are incompatible because of their targets (vertex vs fragment) */\r\n TargetIncompatible,\r\n /** Points are incompatible because they are in the same hierarchy **/\r\n HierarchyIssue,\r\n}\r\n\r\n/**\r\n * Defines the direction of a connection point\r\n */\r\nexport enum NodeMaterialConnectionPointDirection {\r\n /** Input */\r\n Input,\r\n /** Output */\r\n Output,\r\n}\r\n\r\n/**\r\n * Defines a connection point for a block\r\n */\r\nexport class NodeMaterialConnectionPoint {\r\n /**\r\n * Checks if two types are equivalent\r\n * @param type1 type 1 to check\r\n * @param type2 type 2 to check\r\n * @returns true if both types are equivalent, else false\r\n */\r\n public static AreEquivalentTypes(type1: number, type2: number): boolean {\r\n switch (type1) {\r\n case NodeMaterialBlockConnectionPointTypes.Vector3: {\r\n if (type2 === NodeMaterialBlockConnectionPointTypes.Color3) {\r\n return true;\r\n }\r\n break;\r\n }\r\n case NodeMaterialBlockConnectionPointTypes.Vector4: {\r\n if (type2 === NodeMaterialBlockConnectionPointTypes.Color4) {\r\n return true;\r\n }\r\n break;\r\n }\r\n case NodeMaterialBlockConnectionPointTypes.Color3: {\r\n if (type2 === NodeMaterialBlockConnectionPointTypes.Vector3) {\r\n return true;\r\n }\r\n break;\r\n }\r\n case NodeMaterialBlockConnectionPointTypes.Color4: {\r\n if (type2 === NodeMaterialBlockConnectionPointTypes.Vector4) {\r\n return true;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /** @internal */\r\n public _ownerBlock: NodeMaterialBlock;\r\n /** @internal */\r\n public _connectedPoint: Nullable = null;\r\n\r\n private _endpoints = new Array();\r\n private _associatedVariableName: string;\r\n private _direction: NodeMaterialConnectionPointDirection;\r\n\r\n /** @internal */\r\n public _typeConnectionSource: Nullable = null;\r\n\r\n /** @internal */\r\n public _defaultConnectionPointType: Nullable = null;\r\n\r\n /** @internal */\r\n public _linkedConnectionSource: Nullable = null;\r\n\r\n /** @internal */\r\n public _acceptedConnectionPointType: Nullable = null;\r\n\r\n private _type = NodeMaterialBlockConnectionPointTypes.Float;\r\n\r\n /** @internal */\r\n public _enforceAssociatedVariableName = false;\r\n\r\n /** Gets the direction of the point */\r\n public get direction() {\r\n return this._direction;\r\n }\r\n\r\n /** Indicates that this connection point needs dual validation before being connected to another point */\r\n public needDualDirectionValidation: boolean = false;\r\n\r\n /**\r\n * Gets or sets the additional types supported by this connection point\r\n */\r\n public acceptedConnectionPointTypes = new Array();\r\n\r\n /**\r\n * Gets or sets the additional types excluded by this connection point\r\n */\r\n public excludedConnectionPointTypes = new Array();\r\n\r\n /**\r\n * Observable triggered when this point is connected\r\n */\r\n public onConnectionObservable = new Observable();\r\n\r\n /**\r\n * Gets or sets the associated variable name in the shader\r\n */\r\n public get associatedVariableName(): string {\r\n if (this._ownerBlock.isInput) {\r\n return (this._ownerBlock as InputBlock).associatedVariableName;\r\n }\r\n\r\n if ((!this._enforceAssociatedVariableName || !this._associatedVariableName) && this._connectedPoint) {\r\n return this._connectedPoint.associatedVariableName;\r\n }\r\n\r\n return this._associatedVariableName;\r\n }\r\n\r\n public set associatedVariableName(value: string) {\r\n this._associatedVariableName = value;\r\n }\r\n\r\n /** Get the inner type (ie AutoDetect for instance instead of the inferred one) */\r\n public get innerType() {\r\n if (this._linkedConnectionSource && this._linkedConnectionSource.isConnected) {\r\n return this.type;\r\n }\r\n return this._type;\r\n }\r\n\r\n /**\r\n * Gets or sets the connection point type (default is float)\r\n */\r\n public get type(): NodeMaterialBlockConnectionPointTypes {\r\n if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {\r\n if (this._ownerBlock.isInput) {\r\n return (this._ownerBlock as InputBlock).type;\r\n }\r\n\r\n if (this._connectedPoint) {\r\n return this._connectedPoint.type;\r\n }\r\n\r\n if (this._linkedConnectionSource && this._linkedConnectionSource.isConnected) {\r\n return this._linkedConnectionSource.type;\r\n }\r\n }\r\n\r\n if (this._type === NodeMaterialBlockConnectionPointTypes.BasedOnInput) {\r\n if (this._typeConnectionSource) {\r\n if (!this._typeConnectionSource.isConnected && this._defaultConnectionPointType) {\r\n return this._defaultConnectionPointType;\r\n }\r\n return this._typeConnectionSource.type;\r\n } else if (this._defaultConnectionPointType) {\r\n return this._defaultConnectionPointType;\r\n }\r\n }\r\n\r\n return this._type;\r\n }\r\n\r\n public set type(value: NodeMaterialBlockConnectionPointTypes) {\r\n this._type = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the connection point name\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Gets or sets the connection point name\r\n */\r\n public displayName: string;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this connection point can be omitted\r\n */\r\n public isOptional: boolean;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this connection point is exposed on a frame\r\n */\r\n public isExposedOnFrame: boolean = false;\r\n\r\n /**\r\n * Gets or sets number indicating the position that the port is exposed to on a frame\r\n */\r\n public exposedPortPosition: number = -1;\r\n\r\n /**\r\n * Gets or sets a string indicating that this uniform must be defined under a #ifdef\r\n */\r\n public define: string;\r\n\r\n /** @internal */\r\n public _prioritizeVertex = false;\r\n\r\n private _target: NodeMaterialBlockTargets = NodeMaterialBlockTargets.VertexAndFragment;\r\n\r\n /** Gets or sets the target of that connection point */\r\n public get target(): NodeMaterialBlockTargets {\r\n if (!this._prioritizeVertex || !this._ownerBlock) {\r\n return this._target;\r\n }\r\n\r\n if (this._target !== NodeMaterialBlockTargets.VertexAndFragment) {\r\n return this._target;\r\n }\r\n\r\n if (this._ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\r\n return NodeMaterialBlockTargets.Fragment;\r\n }\r\n\r\n return NodeMaterialBlockTargets.Vertex;\r\n }\r\n\r\n public set target(value: NodeMaterialBlockTargets) {\r\n this._target = value;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the current point is connected to another NodeMaterialBlock\r\n */\r\n public get isConnected(): boolean {\r\n return this.connectedPoint !== null || this.hasEndpoints;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the current point is connected to an input block\r\n */\r\n public get isConnectedToInputBlock(): boolean {\r\n return this.connectedPoint !== null && this.connectedPoint.ownerBlock.isInput;\r\n }\r\n\r\n /**\r\n * Gets a the connected input block (if any)\r\n */\r\n public get connectInputBlock(): Nullable {\r\n if (!this.isConnectedToInputBlock) {\r\n return null;\r\n }\r\n\r\n return this.connectedPoint!.ownerBlock as InputBlock;\r\n }\r\n\r\n /** Get the other side of the connection (if any) */\r\n public get connectedPoint(): Nullable {\r\n return this._connectedPoint;\r\n }\r\n\r\n /** Get the block that owns this connection point */\r\n public get ownerBlock(): NodeMaterialBlock {\r\n return this._ownerBlock;\r\n }\r\n\r\n /** Get the block connected on the other side of this connection (if any) */\r\n public get sourceBlock(): Nullable {\r\n if (!this._connectedPoint) {\r\n return null;\r\n }\r\n\r\n return this._connectedPoint.ownerBlock;\r\n }\r\n\r\n /** Get the block connected on the endpoints of this connection (if any) */\r\n public get connectedBlocks(): Array {\r\n if (this._endpoints.length === 0) {\r\n return [];\r\n }\r\n\r\n return this._endpoints.map((e) => e.ownerBlock);\r\n }\r\n\r\n /** Gets the list of connected endpoints */\r\n public get endpoints() {\r\n return this._endpoints;\r\n }\r\n\r\n /** Gets a boolean indicating if that output point is connected to at least one input */\r\n public get hasEndpoints(): boolean {\r\n return this._endpoints && this._endpoints.length > 0;\r\n }\r\n\r\n /** Gets a boolean indicating that this connection has a path to the vertex output*/\r\n public get isDirectlyConnectedToVertexOutput(): boolean {\r\n if (!this.hasEndpoints) {\r\n return false;\r\n }\r\n\r\n for (const endpoint of this._endpoints) {\r\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Vertex) {\r\n return true;\r\n }\r\n\r\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Neutral || endpoint.ownerBlock.target === NodeMaterialBlockTargets.VertexAndFragment) {\r\n if (endpoint.ownerBlock.outputs.some((o) => o.isDirectlyConnectedToVertexOutput)) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /** Gets a boolean indicating that this connection will be used in the vertex shader */\r\n public get isConnectedInVertexShader(): boolean {\r\n if (this.target === NodeMaterialBlockTargets.Vertex) {\r\n return true;\r\n }\r\n\r\n if (!this.hasEndpoints) {\r\n return false;\r\n }\r\n\r\n for (const endpoint of this._endpoints) {\r\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Vertex) {\r\n return true;\r\n }\r\n\r\n if (endpoint.target === NodeMaterialBlockTargets.Vertex) {\r\n return true;\r\n }\r\n\r\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Neutral || endpoint.ownerBlock.target === NodeMaterialBlockTargets.VertexAndFragment) {\r\n if (endpoint.ownerBlock.outputs.some((o) => o.isConnectedInVertexShader)) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /** Gets a boolean indicating that this connection will be used in the fragment shader */\r\n public get isConnectedInFragmentShader(): boolean {\r\n if (this.target === NodeMaterialBlockTargets.Fragment) {\r\n return true;\r\n }\r\n\r\n if (!this.hasEndpoints) {\r\n return false;\r\n }\r\n\r\n for (const endpoint of this._endpoints) {\r\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\r\n return true;\r\n }\r\n\r\n if (endpoint.ownerBlock.target === NodeMaterialBlockTargets.Neutral || endpoint.ownerBlock.target === NodeMaterialBlockTargets.VertexAndFragment) {\r\n if (endpoint.ownerBlock.isConnectedInFragmentShader()) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Creates a block suitable to be used as an input for this input point.\r\n * If null is returned, a block based on the point type will be created.\r\n * @returns The returned string parameter is the name of the output point of NodeMaterialBlock (first parameter of the returned array) that can be connected to the input\r\n */\r\n public createCustomInputBlock(): Nullable<[NodeMaterialBlock, string]> {\r\n return null;\r\n }\r\n\r\n /**\r\n * Creates a new connection point\r\n * @param name defines the connection point name\r\n * @param ownerBlock defines the block hosting this connection point\r\n * @param direction defines the direction of the connection point\r\n */\r\n public constructor(name: string, ownerBlock: NodeMaterialBlock, direction: NodeMaterialConnectionPointDirection) {\r\n this._ownerBlock = ownerBlock;\r\n this.name = name;\r\n this._direction = direction;\r\n }\r\n\r\n /**\r\n * Gets the current class name e.g. \"NodeMaterialConnectionPoint\"\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"NodeMaterialConnectionPoint\";\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the current point can be connected to another point\r\n * @param connectionPoint defines the other connection point\r\n * @returns a boolean\r\n */\r\n public canConnectTo(connectionPoint: NodeMaterialConnectionPoint) {\r\n return this.checkCompatibilityState(connectionPoint) === NodeMaterialConnectionPointCompatibilityStates.Compatible;\r\n }\r\n\r\n /**\r\n * Gets a number indicating if the current point can be connected to another point\r\n * @param connectionPoint defines the other connection point\r\n * @returns a number defining the compatibility state\r\n */\r\n public checkCompatibilityState(connectionPoint: NodeMaterialConnectionPoint): NodeMaterialConnectionPointCompatibilityStates {\r\n const ownerBlock = this._ownerBlock;\r\n const otherBlock = connectionPoint.ownerBlock;\r\n\r\n if (ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\r\n // Let's check we are not going reverse\r\n\r\n if (otherBlock.target === NodeMaterialBlockTargets.Vertex) {\r\n return NodeMaterialConnectionPointCompatibilityStates.TargetIncompatible;\r\n }\r\n\r\n for (const output of otherBlock.outputs) {\r\n if (output.ownerBlock.target != NodeMaterialBlockTargets.Neutral && output.isConnectedInVertexShader) {\r\n return NodeMaterialConnectionPointCompatibilityStates.TargetIncompatible;\r\n }\r\n }\r\n }\r\n\r\n if (this.type !== connectionPoint.type && connectionPoint.innerType !== NodeMaterialBlockConnectionPointTypes.AutoDetect) {\r\n // Equivalents\r\n if (NodeMaterialConnectionPoint.AreEquivalentTypes(this.type, connectionPoint.type)) {\r\n return NodeMaterialConnectionPointCompatibilityStates.Compatible;\r\n }\r\n\r\n // Accepted types\r\n if (\r\n (connectionPoint.acceptedConnectionPointTypes && connectionPoint.acceptedConnectionPointTypes.indexOf(this.type) !== -1) ||\r\n (connectionPoint._acceptedConnectionPointType && NodeMaterialConnectionPoint.AreEquivalentTypes(connectionPoint._acceptedConnectionPointType.type, this.type))\r\n ) {\r\n return NodeMaterialConnectionPointCompatibilityStates.Compatible;\r\n } else {\r\n return NodeMaterialConnectionPointCompatibilityStates.TypeIncompatible;\r\n }\r\n }\r\n\r\n // Excluded\r\n if (connectionPoint.excludedConnectionPointTypes && connectionPoint.excludedConnectionPointTypes.indexOf(this.type) !== -1) {\r\n return NodeMaterialConnectionPointCompatibilityStates.TypeIncompatible;\r\n }\r\n\r\n // Check hierarchy\r\n let targetBlock = otherBlock;\r\n let sourceBlock = ownerBlock;\r\n if (this.direction === NodeMaterialConnectionPointDirection.Input) {\r\n targetBlock = ownerBlock;\r\n sourceBlock = otherBlock;\r\n }\r\n\r\n if (targetBlock.isAnAncestorOf(sourceBlock)) {\r\n return NodeMaterialConnectionPointCompatibilityStates.HierarchyIssue;\r\n }\r\n\r\n return NodeMaterialConnectionPointCompatibilityStates.Compatible;\r\n }\r\n\r\n /**\r\n * Connect this point to another connection point\r\n * @param connectionPoint defines the other connection point\r\n * @param ignoreConstraints defines if the system will ignore connection type constraints (default is false)\r\n * @returns the current connection point\r\n */\r\n public connectTo(connectionPoint: NodeMaterialConnectionPoint, ignoreConstraints = false): NodeMaterialConnectionPoint {\r\n if (!ignoreConstraints && !this.canConnectTo(connectionPoint)) {\r\n throw \"Cannot connect these two connectors.\";\r\n }\r\n\r\n this._endpoints.push(connectionPoint);\r\n connectionPoint._connectedPoint = this;\r\n\r\n this._enforceAssociatedVariableName = false;\r\n\r\n this.onConnectionObservable.notifyObservers(connectionPoint);\r\n connectionPoint.onConnectionObservable.notifyObservers(this);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Disconnect this point from one of his endpoint\r\n * @param endpoint defines the other connection point\r\n * @returns the current connection point\r\n */\r\n public disconnectFrom(endpoint: NodeMaterialConnectionPoint): NodeMaterialConnectionPoint {\r\n const index = this._endpoints.indexOf(endpoint);\r\n\r\n if (index === -1) {\r\n return this;\r\n }\r\n\r\n this._endpoints.splice(index, 1);\r\n endpoint._connectedPoint = null;\r\n this._enforceAssociatedVariableName = false;\r\n endpoint._enforceAssociatedVariableName = false;\r\n return this;\r\n }\r\n\r\n /**\r\n * Fill the list of excluded connection point types with all types other than those passed in the parameter\r\n * @param mask Types (ORed values of NodeMaterialBlockConnectionPointTypes) that are allowed, and thus will not be pushed to the excluded list\r\n */\r\n public addExcludedConnectionPointFromAllowedTypes(mask: number): void {\r\n let bitmask = 1;\r\n while (bitmask < NodeMaterialBlockConnectionPointTypes.All) {\r\n if (!(mask & bitmask)) {\r\n this.excludedConnectionPointTypes.push(bitmask);\r\n }\r\n bitmask = bitmask << 1;\r\n }\r\n }\r\n\r\n /**\r\n * Serializes this point in a JSON representation\r\n * @param isInput defines if the connection point is an input (default is true)\r\n * @returns the serialized point object\r\n */\r\n public serialize(isInput = true): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.name = this.name;\r\n serializationObject.displayName = this.displayName;\r\n\r\n if (isInput && this.connectedPoint) {\r\n serializationObject.inputName = this.name;\r\n serializationObject.targetBlockId = this.connectedPoint.ownerBlock.uniqueId;\r\n serializationObject.targetConnectionName = this.connectedPoint.name;\r\n serializationObject.isExposedOnFrame = true;\r\n serializationObject.exposedPortPosition = this.exposedPortPosition;\r\n }\r\n\r\n if (this.isExposedOnFrame || this.exposedPortPosition >= 0) {\r\n serializationObject.isExposedOnFrame = true;\r\n serializationObject.exposedPortPosition = this.exposedPortPosition;\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Release resources\r\n */\r\n public dispose() {\r\n this.onConnectionObservable.clear();\r\n }\r\n}\r\n","import type { Scene } from \"../scene\";\r\n\r\n/**\r\n * Enum defining the type of properties that can be edited in the property pages in the node editor\r\n */\r\nexport enum PropertyTypeForEdition {\r\n /** property is a boolean */\r\n Boolean,\r\n /** property is a float */\r\n Float,\r\n /** property is a int */\r\n Int,\r\n /** property is a Vector2 */\r\n Vector2,\r\n /** property is a list of values */\r\n List,\r\n}\r\n\r\n/**\r\n * Interface that defines an option in a variable of type list\r\n */\r\nexport interface IEditablePropertyListOption {\r\n /** label of the option */\r\n label: string;\r\n /** value of the option */\r\n value: number;\r\n}\r\n\r\n/**\r\n * Interface that defines the options available for an editable property\r\n */\r\nexport interface IEditablePropertyOption {\r\n /** min value */\r\n min?: number;\r\n /** max value */\r\n max?: number;\r\n /** notifiers: indicates which actions to take when the property is changed */\r\n notifiers?: {\r\n /** the entity should be rebuilt */\r\n rebuild?: boolean;\r\n /** the preview should be updated */\r\n update?: boolean;\r\n /** the onPreviewCommandActivated observer of the preview manager should be triggered */\r\n activatePreviewCommand?: boolean;\r\n /** a callback to trigger */\r\n callback?: (scene: Scene, block: any) => boolean | undefined | void;\r\n /** a callback to validate the property. Returns true if the property is ok, else false. If false, the rebuild/update/callback events won't be called */\r\n onValidation?: (block: any, propertyName: string) => boolean;\r\n };\r\n /** list of the options for a variable of type list */\r\n options?: IEditablePropertyListOption[];\r\n}\r\n\r\n/**\r\n * Interface that describes an editable property\r\n */\r\nexport interface IPropertyDescriptionForEdition {\r\n /** name of the property */\r\n propertyName: string;\r\n /** display name of the property */\r\n displayName: string;\r\n /** type of the property */\r\n type: PropertyTypeForEdition;\r\n /** group of the property - all properties with the same group value will be displayed in a specific section */\r\n groupName: string;\r\n /** options for the property */\r\n options: IEditablePropertyOption;\r\n}\r\n\r\n/**\r\n * Decorator that flags a property in a node block as being editable\r\n * @param displayName\r\n * @param propertyType\r\n * @param groupName\r\n * @param options\r\n */\r\nexport function editableInPropertyPage(\r\n displayName: string,\r\n propertyType: PropertyTypeForEdition = PropertyTypeForEdition.Boolean,\r\n groupName: string = \"PROPERTIES\",\r\n options?: IEditablePropertyOption\r\n) {\r\n return (target: any, propertyKey: string) => {\r\n let propStore: IPropertyDescriptionForEdition[] = target._propStore;\r\n if (!propStore) {\r\n propStore = [];\r\n target._propStore = propStore;\r\n }\r\n propStore.push({\r\n propertyName: propertyKey,\r\n displayName: displayName,\r\n type: propertyType,\r\n groupName: groupName,\r\n options: options ?? {},\r\n });\r\n };\r\n}\r\n","/**\r\n * Enum defining the mode of a NodeMaterialBlockConnectionPoint\r\n */\r\nexport enum NodeMaterialBlockConnectionPointMode {\r\n /** Value is an uniform */\r\n Uniform,\r\n /** Value is a mesh attribute */\r\n Attribute,\r\n /** Value is a varying between vertex and fragment shaders */\r\n Varying,\r\n /** Mode is undefined */\r\n Undefined,\r\n}\r\n","/**\r\n * Enum used to define system values e.g. values automatically provided by the system\r\n */\r\nexport enum NodeMaterialSystemValues {\r\n /** World */\r\n World = 1,\r\n /** View */\r\n View = 2,\r\n /** Projection */\r\n Projection = 3,\r\n /** ViewProjection */\r\n ViewProjection = 4,\r\n /** WorldView */\r\n WorldView = 5,\r\n /** WorldViewProjection */\r\n WorldViewProjection = 6,\r\n /** CameraPosition */\r\n CameraPosition = 7,\r\n /** Fog Color */\r\n FogColor = 8,\r\n /** Delta time */\r\n DeltaTime = 9,\r\n /** Camera parameters */\r\n CameraParameters = 10,\r\n /** Material alpha */\r\n MaterialAlpha = 11,\r\n}\r\n","/**\r\n * Enum defining the type of animations supported by InputBlock\r\n */\r\nexport enum AnimatedInputBlockTypes {\r\n /** No animation */\r\n None,\r\n /** Time based animation (is incremented by 0.6 each second). Will only work for floats */\r\n Time,\r\n /** Time elapsed (in seconds) since the engine was initialized. Will only work for floats */\r\n RealTime,\r\n}\r\n","import { NodeMaterialBlockConnectionPointTypes } from \"./Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport { NodeMaterialBlockTargets } from \"./Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialBuildStateSharedData } from \"./nodeMaterialBuildStateSharedData\";\r\nimport { Effect } from \"../effect\";\r\n\r\n/**\r\n * Class used to store node based material build state\r\n */\r\nexport class NodeMaterialBuildState {\r\n /** Gets or sets a boolean indicating if the current state can emit uniform buffers */\r\n public supportUniformBuffers = false;\r\n /**\r\n * Gets the list of emitted attributes\r\n */\r\n public attributes = new Array();\r\n /**\r\n * Gets the list of emitted uniforms\r\n */\r\n public uniforms = new Array();\r\n /**\r\n * Gets the list of emitted constants\r\n */\r\n public constants = new Array();\r\n /**\r\n * Gets the list of emitted samplers\r\n */\r\n public samplers = new Array();\r\n /**\r\n * Gets the list of emitted functions\r\n */\r\n public functions: { [key: string]: string } = {};\r\n /**\r\n * Gets the list of emitted extensions\r\n */\r\n public extensions: { [key: string]: string } = {};\r\n\r\n /**\r\n * Gets the target of the compilation state\r\n */\r\n public target: NodeMaterialBlockTargets;\r\n /**\r\n * Gets the list of emitted counters\r\n */\r\n public counters: { [key: string]: number } = {};\r\n\r\n /**\r\n * Shared data between multiple NodeMaterialBuildState instances\r\n */\r\n public sharedData: NodeMaterialBuildStateSharedData;\r\n\r\n /** @internal */\r\n public _vertexState: NodeMaterialBuildState;\r\n\r\n /** @internal */\r\n public _attributeDeclaration = \"\";\r\n /** @internal */\r\n public _uniformDeclaration = \"\";\r\n /** @internal */\r\n public _constantDeclaration = \"\";\r\n /** @internal */\r\n public _samplerDeclaration = \"\";\r\n /** @internal */\r\n public _varyingTransfer = \"\";\r\n /** @internal */\r\n public _injectAtEnd = \"\";\r\n\r\n private _repeatableContentAnchorIndex = 0;\r\n /** @internal */\r\n public _builtCompilationString = \"\";\r\n\r\n /**\r\n * Gets the emitted compilation strings\r\n */\r\n public compilationString = \"\";\r\n\r\n /**\r\n * Finalize the compilation strings\r\n * @param state defines the current compilation state\r\n */\r\n public finalize(state: NodeMaterialBuildState) {\r\n const emitComments = state.sharedData.emitComments;\r\n const isFragmentMode = this.target === NodeMaterialBlockTargets.Fragment;\r\n\r\n this.compilationString = `\\n${emitComments ? \"//Entry point\\n\" : \"\"}void main(void) {\\n${this.compilationString}`;\r\n\r\n if (this._constantDeclaration) {\r\n this.compilationString = `\\n${emitComments ? \"//Constants\\n\" : \"\"}${this._constantDeclaration}\\n${this.compilationString}`;\r\n }\r\n\r\n let functionCode = \"\";\r\n for (const functionName in this.functions) {\r\n functionCode += this.functions[functionName] + `\\n`;\r\n }\r\n this.compilationString = `\\n${functionCode}\\n${this.compilationString}`;\r\n\r\n if (!isFragmentMode && this._varyingTransfer) {\r\n this.compilationString = `${this.compilationString}\\n${this._varyingTransfer}`;\r\n }\r\n\r\n if (this._injectAtEnd) {\r\n this.compilationString = `${this.compilationString}\\n${this._injectAtEnd}`;\r\n }\r\n\r\n this.compilationString = `${this.compilationString}\\n}`;\r\n\r\n if (this.sharedData.varyingDeclaration) {\r\n this.compilationString = `\\n${emitComments ? \"//Varyings\\n\" : \"\"}${this.sharedData.varyingDeclaration}\\n${this.compilationString}`;\r\n }\r\n\r\n if (this._samplerDeclaration) {\r\n this.compilationString = `\\n${emitComments ? \"//Samplers\\n\" : \"\"}${this._samplerDeclaration}\\n${this.compilationString}`;\r\n }\r\n\r\n if (this._uniformDeclaration) {\r\n this.compilationString = `\\n${emitComments ? \"//Uniforms\\n\" : \"\"}${this._uniformDeclaration}\\n${this.compilationString}`;\r\n }\r\n\r\n if (this._attributeDeclaration && !isFragmentMode) {\r\n this.compilationString = `\\n${emitComments ? \"//Attributes\\n\" : \"\"}${this._attributeDeclaration}\\n${this.compilationString}`;\r\n }\r\n\r\n this.compilationString = \"precision highp float;\\n\" + this.compilationString;\r\n this.compilationString = \"#if defined(WEBGL2) || defines(WEBGPU)\\nprecision highp sampler2DArray;\\n#endif\\n\" + this.compilationString;\r\n\r\n for (const extensionName in this.extensions) {\r\n const extension = this.extensions[extensionName];\r\n this.compilationString = `\\n${extension}\\n${this.compilationString}`;\r\n }\r\n\r\n this._builtCompilationString = this.compilationString;\r\n }\r\n\r\n /** @internal */\r\n public get _repeatableContentAnchor(): string {\r\n return `###___ANCHOR${this._repeatableContentAnchorIndex++}___###`;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getFreeVariableName(prefix: string): string {\r\n prefix = prefix.replace(/[^a-zA-Z_]+/g, \"\");\r\n\r\n if (this.sharedData.variableNames[prefix] === undefined) {\r\n this.sharedData.variableNames[prefix] = 0;\r\n\r\n // Check reserved words\r\n if (prefix === \"output\" || prefix === \"texture\") {\r\n return prefix + this.sharedData.variableNames[prefix];\r\n }\r\n\r\n return prefix;\r\n } else {\r\n this.sharedData.variableNames[prefix]++;\r\n }\r\n\r\n return prefix + this.sharedData.variableNames[prefix];\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getFreeDefineName(prefix: string): string {\r\n if (this.sharedData.defineNames[prefix] === undefined) {\r\n this.sharedData.defineNames[prefix] = 0;\r\n } else {\r\n this.sharedData.defineNames[prefix]++;\r\n }\r\n\r\n return prefix + this.sharedData.defineNames[prefix];\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _excludeVariableName(name: string) {\r\n this.sharedData.variableNames[name] = 0;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emit2DSampler(name: string) {\r\n if (this.samplers.indexOf(name) < 0) {\r\n this._samplerDeclaration += `uniform sampler2D ${name};\\n`;\r\n this.samplers.push(name);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emit2DArraySampler(name: string) {\r\n if (this.samplers.indexOf(name) < 0) {\r\n this._samplerDeclaration += `uniform sampler2DArray ${name};\\n`;\r\n this.samplers.push(name);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getGLType(type: NodeMaterialBlockConnectionPointTypes): string {\r\n switch (type) {\r\n case NodeMaterialBlockConnectionPointTypes.Float:\r\n return \"float\";\r\n case NodeMaterialBlockConnectionPointTypes.Int:\r\n return \"int\";\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n return \"vec2\";\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n return \"vec3\";\r\n case NodeMaterialBlockConnectionPointTypes.Color4:\r\n case NodeMaterialBlockConnectionPointTypes.Vector4:\r\n return \"vec4\";\r\n case NodeMaterialBlockConnectionPointTypes.Matrix:\r\n return \"mat4\";\r\n }\r\n\r\n return \"\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitExtension(name: string, extension: string, define: string = \"\") {\r\n if (this.extensions[name]) {\r\n return;\r\n }\r\n\r\n if (define) {\r\n extension = `#if ${define}\\n${extension}\\n#endif`;\r\n }\r\n this.extensions[name] = extension;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitFunction(name: string, code: string, comments: string) {\r\n if (this.functions[name]) {\r\n return;\r\n }\r\n\r\n if (this.sharedData.emitComments) {\r\n code = comments + `\\n` + code;\r\n }\r\n\r\n this.functions[name] = code;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitCodeFromInclude(\r\n includeName: string,\r\n comments: string,\r\n options?: {\r\n replaceStrings?: { search: RegExp; replace: string }[];\r\n repeatKey?: string;\r\n substitutionVars?: string;\r\n }\r\n ) {\r\n if (options && options.repeatKey) {\r\n return `#include<${includeName}>${options.substitutionVars ? \"(\" + options.substitutionVars + \")\" : \"\"}[0..${options.repeatKey}]\\n`;\r\n }\r\n\r\n let code = Effect.IncludesShadersStore[includeName] + \"\\n\";\r\n\r\n if (this.sharedData.emitComments) {\r\n code = comments + `\\n` + code;\r\n }\r\n\r\n if (!options) {\r\n return code;\r\n }\r\n\r\n if (options.replaceStrings) {\r\n for (let index = 0; index < options.replaceStrings.length; index++) {\r\n const replaceString = options.replaceStrings[index];\r\n code = code.replace(replaceString.search, replaceString.replace);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitFunctionFromInclude(\r\n includeName: string,\r\n comments: string,\r\n options?: {\r\n repeatKey?: string;\r\n substitutionVars?: string;\r\n removeAttributes?: boolean;\r\n removeUniforms?: boolean;\r\n removeVaryings?: boolean;\r\n removeIfDef?: boolean;\r\n replaceStrings?: { search: RegExp; replace: string }[];\r\n },\r\n storeKey: string = \"\"\r\n ) {\r\n const key = includeName + storeKey;\r\n if (this.functions[key]) {\r\n return;\r\n }\r\n\r\n if (!options || (!options.removeAttributes && !options.removeUniforms && !options.removeVaryings && !options.removeIfDef && !options.replaceStrings)) {\r\n if (options && options.repeatKey) {\r\n this.functions[key] = `#include<${includeName}>${options.substitutionVars ? \"(\" + options.substitutionVars + \")\" : \"\"}[0..${options.repeatKey}]\\n`;\r\n } else {\r\n this.functions[key] = `#include<${includeName}>${options?.substitutionVars ? \"(\" + options?.substitutionVars + \")\" : \"\"}\\n`;\r\n }\r\n\r\n if (this.sharedData.emitComments) {\r\n this.functions[key] = comments + `\\n` + this.functions[key];\r\n }\r\n\r\n return;\r\n }\r\n\r\n this.functions[key] = Effect.IncludesShadersStore[includeName];\r\n\r\n if (this.sharedData.emitComments) {\r\n this.functions[key] = comments + `\\n` + this.functions[key];\r\n }\r\n\r\n if (options.removeIfDef) {\r\n this.functions[key] = this.functions[key].replace(/^\\s*?#ifdef.+$/gm, \"\");\r\n this.functions[key] = this.functions[key].replace(/^\\s*?#endif.*$/gm, \"\");\r\n this.functions[key] = this.functions[key].replace(/^\\s*?#else.*$/gm, \"\");\r\n this.functions[key] = this.functions[key].replace(/^\\s*?#elif.*$/gm, \"\");\r\n }\r\n\r\n if (options.removeAttributes) {\r\n this.functions[key] = this.functions[key].replace(/\\s*?attribute .+?;/g, \"\\n\");\r\n }\r\n\r\n if (options.removeUniforms) {\r\n this.functions[key] = this.functions[key].replace(/\\s*?uniform .*?;/g, \"\\n\");\r\n }\r\n\r\n if (options.removeVaryings) {\r\n this.functions[key] = this.functions[key].replace(/\\s*?(varying|in) .+?;/g, \"\\n\");\r\n }\r\n\r\n if (options.replaceStrings) {\r\n for (let index = 0; index < options.replaceStrings.length; index++) {\r\n const replaceString = options.replaceStrings[index];\r\n this.functions[key] = this.functions[key].replace(replaceString.search, replaceString.replace);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _registerTempVariable(name: string) {\r\n if (this.sharedData.temps.indexOf(name) !== -1) {\r\n return false;\r\n }\r\n\r\n this.sharedData.temps.push(name);\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitVaryingFromString(name: string, type: string, define: string = \"\", notDefine = false) {\r\n if (this.sharedData.varyings.indexOf(name) !== -1) {\r\n return false;\r\n }\r\n\r\n this.sharedData.varyings.push(name);\r\n\r\n if (define) {\r\n if (define.startsWith(\"defined(\")) {\r\n this.sharedData.varyingDeclaration += `#if ${define}\\n`;\r\n } else {\r\n this.sharedData.varyingDeclaration += `${notDefine ? \"#ifndef\" : \"#ifdef\"} ${define}\\n`;\r\n }\r\n }\r\n this.sharedData.varyingDeclaration += `varying ${type} ${name};\\n`;\r\n if (define) {\r\n this.sharedData.varyingDeclaration += `#endif\\n`;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitUniformFromString(name: string, type: string, define: string = \"\", notDefine = false) {\r\n if (this.uniforms.indexOf(name) !== -1) {\r\n return;\r\n }\r\n\r\n this.uniforms.push(name);\r\n\r\n if (define) {\r\n if (define.startsWith(\"defined(\")) {\r\n this._uniformDeclaration += `#if ${define}\\n`;\r\n } else {\r\n this._uniformDeclaration += `${notDefine ? \"#ifndef\" : \"#ifdef\"} ${define}\\n`;\r\n }\r\n }\r\n this._uniformDeclaration += `uniform ${type} ${name};\\n`;\r\n if (define) {\r\n this._uniformDeclaration += `#endif\\n`;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _emitFloat(value: number) {\r\n if (value.toString() === value.toFixed(0)) {\r\n return `${value}.0`;\r\n }\r\n\r\n return value.toString();\r\n }\r\n}\r\n","import type { NodeMaterialConnectionPoint } from \"./nodeMaterialBlockConnectionPoint\";\r\nimport type { NodeMaterialBlock } from \"./nodeMaterialBlock\";\r\nimport type { InputBlock } from \"./Blocks/Input/inputBlock\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Immutable } from \"../../types\";\r\nimport type { NodeMaterialTextureBlocks } from \"./nodeMaterial\";\r\n\r\n/**\r\n * Class used to store shared data between 2 NodeMaterialBuildState\r\n */\r\nexport class NodeMaterialBuildStateSharedData {\r\n /**\r\n * Gets the list of emitted varyings\r\n */\r\n public temps = new Array();\r\n\r\n /**\r\n * Gets the list of emitted varyings\r\n */\r\n public varyings = new Array();\r\n\r\n /**\r\n * Gets the varying declaration string\r\n */\r\n public varyingDeclaration = \"\";\r\n\r\n /**\r\n * List of the fragment output nodes\r\n */\r\n public fragmentOutputNodes: Immutable>;\r\n\r\n /**\r\n * Input blocks\r\n */\r\n public inputBlocks = new Array();\r\n\r\n /**\r\n * Input blocks\r\n */\r\n public textureBlocks = new Array();\r\n\r\n /**\r\n * Bindable blocks (Blocks that need to set data to the effect)\r\n */\r\n public bindableBlocks = new Array();\r\n\r\n /**\r\n * Bindable blocks (Blocks that need to set data to the effect) that will always be called (by bindForSubMesh), contrary to bindableBlocks that won't be called if _mustRebind() returns false\r\n */\r\n public forcedBindableBlocks = new Array();\r\n\r\n /**\r\n * List of blocks that can provide a compilation fallback\r\n */\r\n public blocksWithFallbacks = new Array();\r\n\r\n /**\r\n * List of blocks that can provide a define update\r\n */\r\n public blocksWithDefines = new Array();\r\n\r\n /**\r\n * List of blocks that can provide a repeatable content\r\n */\r\n public repeatableContentBlocks = new Array();\r\n\r\n /**\r\n * List of blocks that can provide a dynamic list of uniforms\r\n */\r\n public dynamicUniformBlocks = new Array();\r\n\r\n /**\r\n * List of blocks that can block the isReady function for the material\r\n */\r\n public blockingBlocks = new Array();\r\n\r\n /**\r\n * Gets the list of animated inputs\r\n */\r\n public animatedInputs = new Array();\r\n\r\n /**\r\n * Build Id used to avoid multiple recompilations\r\n */\r\n public buildId: number;\r\n\r\n /** List of emitted variables */\r\n public variableNames: { [key: string]: number } = {};\r\n\r\n /** List of emitted defines */\r\n public defineNames: { [key: string]: number } = {};\r\n\r\n /** Should emit comments? */\r\n public emitComments: boolean;\r\n\r\n /** Emit build activity */\r\n public verbose: boolean;\r\n\r\n /** Gets or sets the hosting scene */\r\n public scene: Scene;\r\n\r\n /**\r\n * Gets the compilation hints emitted at compilation time\r\n */\r\n public hints = {\r\n needWorldViewMatrix: false,\r\n needWorldViewProjectionMatrix: false,\r\n needAlphaBlending: false,\r\n needAlphaTesting: false,\r\n };\r\n\r\n /**\r\n * List of compilation checks\r\n */\r\n public checks = {\r\n emitVertex: false,\r\n emitFragment: false,\r\n notConnectedNonOptionalInputs: new Array(),\r\n };\r\n\r\n /**\r\n * Is vertex program allowed to be empty?\r\n */\r\n public allowEmptyVertexProgram: boolean = false;\r\n\r\n /** Creates a new shared data */\r\n public constructor() {\r\n // Exclude usual attributes from free variable names\r\n this.variableNames[\"position\"] = 0;\r\n this.variableNames[\"normal\"] = 0;\r\n this.variableNames[\"tangent\"] = 0;\r\n this.variableNames[\"uv\"] = 0;\r\n this.variableNames[\"uv2\"] = 0;\r\n this.variableNames[\"uv3\"] = 0;\r\n this.variableNames[\"uv4\"] = 0;\r\n this.variableNames[\"uv5\"] = 0;\r\n this.variableNames[\"uv6\"] = 0;\r\n this.variableNames[\"color\"] = 0;\r\n this.variableNames[\"matricesIndices\"] = 0;\r\n this.variableNames[\"matricesWeights\"] = 0;\r\n this.variableNames[\"matricesIndicesExtra\"] = 0;\r\n this.variableNames[\"matricesWeightsExtra\"] = 0;\r\n this.variableNames[\"diffuseBase\"] = 0;\r\n this.variableNames[\"specularBase\"] = 0;\r\n this.variableNames[\"worldPos\"] = 0;\r\n this.variableNames[\"shadow\"] = 0;\r\n this.variableNames[\"view\"] = 0;\r\n\r\n // Exclude known varyings\r\n this.variableNames[\"vTBN\"] = 0;\r\n\r\n // Exclude defines\r\n this.defineNames[\"MAINUV0\"] = 0;\r\n this.defineNames[\"MAINUV1\"] = 0;\r\n this.defineNames[\"MAINUV2\"] = 0;\r\n this.defineNames[\"MAINUV3\"] = 0;\r\n this.defineNames[\"MAINUV4\"] = 0;\r\n this.defineNames[\"MAINUV5\"] = 0;\r\n this.defineNames[\"MAINUV6\"] = 0;\r\n this.defineNames[\"MAINUV7\"] = 0;\r\n }\r\n\r\n /**\r\n * Emits console errors and exceptions if there is a failing check\r\n */\r\n public emitErrors() {\r\n let errorMessage = \"\";\r\n\r\n if (!this.checks.emitVertex && !this.allowEmptyVertexProgram) {\r\n errorMessage += \"NodeMaterial does not have a vertex output. You need to at least add a block that generates a glPosition value.\\n\";\r\n }\r\n if (!this.checks.emitFragment) {\r\n errorMessage += \"NodeMaterial does not have a fragment output. You need to at least add a block that generates a glFragColor value.\\n\";\r\n }\r\n for (const notConnectedInput of this.checks.notConnectedNonOptionalInputs) {\r\n errorMessage += `input ${notConnectedInput.name} from block ${\r\n notConnectedInput.ownerBlock.name\r\n }[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.\\n`;\r\n }\r\n\r\n if (errorMessage) {\r\n throw \"Build of NodeMaterial failed:\\n\" + errorMessage;\r\n }\r\n }\r\n}\r\n","import { NodeMaterialBlockConnectionPointTypes } from \"./Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"./nodeMaterialBuildState\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { NodeMaterialConnectionPoint, NodeMaterialConnectionPointDirection } from \"./nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"./Enums/nodeMaterialBlockTargets\";\r\nimport type { Effect } from \"../effect\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { NodeMaterial, NodeMaterialDefines } from \"./nodeMaterial\";\r\nimport type { InputBlock } from \"./Blocks/Input/inputBlock\";\r\nimport { UniqueIdGenerator } from \"../../Misc/uniqueIdGenerator\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { GetClass } from \"../../Misc/typeStore\";\r\nimport type { EffectFallbacks } from \"../effectFallbacks\";\r\n\r\n/**\r\n * Defines a block that can be used inside a node based material\r\n */\r\nexport class NodeMaterialBlock {\r\n private _buildId: number;\r\n private _buildTarget: NodeMaterialBlockTargets;\r\n protected _target: NodeMaterialBlockTargets;\r\n private _isFinalMerger = false;\r\n private _isInput = false;\r\n private _isTeleportOut = false;\r\n private _isTeleportIn = false;\r\n private _name = \"\";\r\n protected _isUnique = false;\r\n\r\n /** Gets or sets a boolean indicating that only one input can be connected at a time */\r\n public inputsAreExclusive = false;\r\n\r\n /** @internal */\r\n public _codeVariableName = \"\";\r\n\r\n /** @internal */\r\n public _inputs = new Array();\r\n /** @internal */\r\n public _outputs = new Array();\r\n\r\n /** @internal */\r\n public _preparationId: number;\r\n\r\n /** @internal */\r\n public readonly _originalTargetIsNeutral: boolean;\r\n\r\n /**\r\n * Gets the name of the block\r\n */\r\n public get name(): string {\r\n return this._name;\r\n }\r\n\r\n /**\r\n * Sets the name of the block. Will check if the name is valid.\r\n */\r\n public set name(newName: string) {\r\n if (!this.validateBlockName(newName)) {\r\n return;\r\n }\r\n\r\n this._name = newName;\r\n }\r\n\r\n /**\r\n * Gets or sets the unique id of the node\r\n */\r\n public uniqueId: number;\r\n\r\n /**\r\n * Gets or sets the comments associated with this block\r\n */\r\n public comments: string = \"\";\r\n\r\n /**\r\n * Gets a boolean indicating that this block can only be used once per NodeMaterial\r\n */\r\n public get isUnique() {\r\n return this._isUnique;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that this block is an end block (e.g. it is generating a system value)\r\n */\r\n public get isFinalMerger(): boolean {\r\n return this._isFinalMerger;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that this block is an input (e.g. it sends data to the shader)\r\n */\r\n public get isInput(): boolean {\r\n return this._isInput;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if this block is a teleport out\r\n */\r\n public get isTeleportOut(): boolean {\r\n return this._isTeleportOut;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if this block is a teleport in\r\n */\r\n public get isTeleportIn(): boolean {\r\n return this._isTeleportIn;\r\n }\r\n\r\n /**\r\n * Gets or sets the build Id\r\n */\r\n public get buildId(): number {\r\n return this._buildId;\r\n }\r\n\r\n public set buildId(value: number) {\r\n this._buildId = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the target of the block\r\n */\r\n public get target() {\r\n return this._target;\r\n }\r\n\r\n public set target(value: NodeMaterialBlockTargets) {\r\n if ((this._target & value) !== 0) {\r\n return;\r\n }\r\n this._target = value;\r\n }\r\n\r\n /**\r\n * Gets the list of input points\r\n */\r\n public get inputs(): NodeMaterialConnectionPoint[] {\r\n return this._inputs;\r\n }\r\n\r\n /** Gets the list of output points */\r\n public get outputs(): NodeMaterialConnectionPoint[] {\r\n return this._outputs;\r\n }\r\n\r\n /**\r\n * Find an input by its name\r\n * @param name defines the name of the input to look for\r\n * @returns the input or null if not found\r\n */\r\n public getInputByName(name: string) {\r\n const filter = this._inputs.filter((e) => e.name === name);\r\n\r\n if (filter.length) {\r\n return filter[0];\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Find an output by its name\r\n * @param name defines the name of the output to look for\r\n * @returns the output or null if not found\r\n */\r\n public getOutputByName(name: string) {\r\n const filter = this._outputs.filter((e) => e.name === name);\r\n\r\n if (filter.length) {\r\n return filter[0];\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /** Gets or sets a boolean indicating that this input can be edited in the Inspector (false by default) */\r\n public visibleInInspector = false;\r\n\r\n /** Gets or sets a boolean indicating that this input can be edited from a collapsed frame */\r\n public visibleOnFrame = false;\r\n\r\n /**\r\n * Creates a new NodeMaterialBlock\r\n * @param name defines the block name\r\n * @param target defines the target of that block (Vertex by default)\r\n * @param isFinalMerger defines a boolean indicating that this block is an end block (e.g. it is generating a system value). Default is false\r\n */\r\n public constructor(name: string, target = NodeMaterialBlockTargets.Vertex, isFinalMerger = false) {\r\n this._target = target;\r\n this._originalTargetIsNeutral = target === NodeMaterialBlockTargets.Neutral;\r\n this._isFinalMerger = isFinalMerger;\r\n this._isInput = this.getClassName() === \"InputBlock\";\r\n this._isTeleportOut = this.getClassName() === \"NodeMaterialTeleportOutBlock\";\r\n this._isTeleportIn = this.getClassName() === \"NodeMaterialTeleportInBlock\";\r\n this._name = name;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n }\r\n\r\n /** @internal */\r\n public _setInitialTarget(target: NodeMaterialBlockTargets): void {\r\n this._target = target;\r\n (this._originalTargetIsNeutral as boolean) = target === NodeMaterialBlockTargets.Neutral;\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public initialize(state: NodeMaterialBuildState) {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Bind data to effect. Will only be called for blocks with isBindable === true\r\n * @param effect defines the effect to bind data to\r\n * @param nodeMaterial defines the hosting NodeMaterial\r\n * @param mesh defines the mesh that will be rendered\r\n * @param subMesh defines the submesh that will be rendered\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public bind(effect: Effect, nodeMaterial: NodeMaterial, mesh?: Mesh, subMesh?: SubMesh) {\r\n // Do nothing\r\n }\r\n\r\n protected _declareOutput(output: NodeMaterialConnectionPoint, state: NodeMaterialBuildState): string {\r\n return `${state._getGLType(output.type)} ${output.associatedVariableName}`;\r\n }\r\n\r\n protected _writeVariable(currentPoint: NodeMaterialConnectionPoint): string {\r\n const connectionPoint = currentPoint.connectedPoint;\r\n\r\n if (connectionPoint) {\r\n return `${currentPoint.associatedVariableName}`;\r\n }\r\n\r\n return `0.`;\r\n }\r\n\r\n protected _writeFloat(value: number) {\r\n let stringVersion = value.toString();\r\n\r\n if (stringVersion.indexOf(\".\") === -1) {\r\n stringVersion += \".0\";\r\n }\r\n return `${stringVersion}`;\r\n }\r\n\r\n /**\r\n * Gets the current class name e.g. \"NodeMaterialBlock\"\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"NodeMaterialBlock\";\r\n }\r\n\r\n /** Gets a boolean indicating that this connection will be used in the fragment shader */\r\n public isConnectedInFragmentShader() {\r\n return this.outputs.some((o) => o.isConnectedInFragmentShader);\r\n }\r\n\r\n /**\r\n * Register a new input. Must be called inside a block constructor\r\n * @param name defines the connection point name\r\n * @param type defines the connection point type\r\n * @param isOptional defines a boolean indicating that this input can be omitted\r\n * @param target defines the target to use to limit the connection point (will be VertexAndFragment by default)\r\n * @param point an already created connection point. If not provided, create a new one\r\n * @returns the current block\r\n */\r\n public registerInput(\r\n name: string,\r\n type: NodeMaterialBlockConnectionPointTypes,\r\n isOptional: boolean = false,\r\n target?: NodeMaterialBlockTargets,\r\n point?: NodeMaterialConnectionPoint\r\n ) {\r\n point = point ?? new NodeMaterialConnectionPoint(name, this, NodeMaterialConnectionPointDirection.Input);\r\n point.type = type;\r\n point.isOptional = isOptional;\r\n if (target) {\r\n point.target = target;\r\n }\r\n\r\n this._inputs.push(point);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Register a new output. Must be called inside a block constructor\r\n * @param name defines the connection point name\r\n * @param type defines the connection point type\r\n * @param target defines the target to use to limit the connection point (will be VertexAndFragment by default)\r\n * @param point an already created connection point. If not provided, create a new one\r\n * @returns the current block\r\n */\r\n public registerOutput(name: string, type: NodeMaterialBlockConnectionPointTypes, target?: NodeMaterialBlockTargets, point?: NodeMaterialConnectionPoint) {\r\n point = point ?? new NodeMaterialConnectionPoint(name, this, NodeMaterialConnectionPointDirection.Output);\r\n point.type = type;\r\n if (target) {\r\n point.target = target;\r\n }\r\n\r\n this._outputs.push(point);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Will return the first available input e.g. the first one which is not an uniform or an attribute\r\n * @param forOutput defines an optional connection point to check compatibility with\r\n * @returns the first available input or null\r\n */\r\n public getFirstAvailableInput(forOutput: Nullable = null) {\r\n for (const input of this._inputs) {\r\n if (!input.connectedPoint) {\r\n if (!forOutput || forOutput.type === input.type || input.type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {\r\n return input;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Will return the first available output e.g. the first one which is not yet connected and not a varying\r\n * @param forBlock defines an optional block to check compatibility with\r\n * @returns the first available input or null\r\n */\r\n public getFirstAvailableOutput(forBlock: Nullable = null) {\r\n for (const output of this._outputs) {\r\n if (!forBlock || !forBlock.target || forBlock.target === NodeMaterialBlockTargets.Neutral || (forBlock.target & output.target) !== 0) {\r\n return output;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets the sibling of the given output\r\n * @param current defines the current output\r\n * @returns the next output in the list or null\r\n */\r\n public getSiblingOutput(current: NodeMaterialConnectionPoint) {\r\n const index = this._outputs.indexOf(current);\r\n\r\n if (index === -1 || index >= this._outputs.length) {\r\n return null;\r\n }\r\n\r\n return this._outputs[index + 1];\r\n }\r\n\r\n /**\r\n * Checks if the current block is an ancestor of a given block\r\n * @param block defines the potential descendant block to check\r\n * @returns true if block is a descendant\r\n */\r\n public isAnAncestorOf(block: NodeMaterialBlock): boolean {\r\n for (const output of this._outputs) {\r\n if (!output.hasEndpoints) {\r\n continue;\r\n }\r\n\r\n for (const endpoint of output.endpoints) {\r\n if (endpoint.ownerBlock === block) {\r\n return true;\r\n }\r\n if (endpoint.ownerBlock.isAnAncestorOf(block)) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Connect current block with another block\r\n * @param other defines the block to connect with\r\n * @param options define the various options to help pick the right connections\r\n * @param options.input\r\n * @param options.output\r\n * @param options.outputSwizzle\r\n * @returns the current block\r\n */\r\n public connectTo(\r\n other: NodeMaterialBlock,\r\n options?: {\r\n input?: string;\r\n output?: string;\r\n outputSwizzle?: string;\r\n }\r\n ) {\r\n if (this._outputs.length === 0) {\r\n return;\r\n }\r\n\r\n let output = options && options.output ? this.getOutputByName(options.output) : this.getFirstAvailableOutput(other);\r\n\r\n let notFound = true;\r\n while (notFound) {\r\n const input = options && options.input ? other.getInputByName(options.input) : other.getFirstAvailableInput(output);\r\n\r\n if (output && input && output.canConnectTo(input)) {\r\n output.connectTo(input);\r\n notFound = false;\r\n } else if (!output) {\r\n throw \"Unable to find a compatible match\";\r\n } else {\r\n output = this.getSiblingOutput(output);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n // Empty. Must be defined by child nodes\r\n }\r\n\r\n /**\r\n * Add uniforms, samplers and uniform buffers at compilation time\r\n * @param state defines the state to update\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param defines defines the material defines to update\r\n * @param uniformBuffers defines the list of uniform buffer names\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public updateUniformsAndSamples(state: NodeMaterialBuildState, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, uniformBuffers: string[]) {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Add potential fallbacks if shader compilation fails\r\n * @param mesh defines the mesh to be rendered\r\n * @param fallbacks defines the current prioritized list of fallbacks\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public provideFallbacks(mesh: AbstractMesh, fallbacks: EffectFallbacks) {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Initialize defines for shader compilation\r\n * @param mesh defines the mesh to be rendered\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param defines defines the material defines to update\r\n * @param useInstances specifies that instances should be used\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public initializeDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, useInstances: boolean = false) {}\r\n\r\n /**\r\n * Update defines for shader compilation\r\n * @param mesh defines the mesh to be rendered\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param defines defines the material defines to update\r\n * @param useInstances specifies that instances should be used\r\n * @param subMesh defines which submesh to render\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, useInstances: boolean = false, subMesh?: SubMesh) {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Lets the block try to connect some inputs automatically\r\n * @param material defines the hosting NodeMaterial\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public autoConfigure(material: NodeMaterial) {\r\n // Do nothing\r\n }\r\n\r\n /**\r\n * Function called when a block is declared as repeatable content generator\r\n * @param vertexShaderState defines the current compilation state for the vertex shader\r\n * @param fragmentShaderState defines the current compilation state for the fragment shader\r\n * @param mesh defines the mesh to be rendered\r\n * @param defines defines the material defines to update\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public replaceRepeatableContent(vertexShaderState: NodeMaterialBuildState, fragmentShaderState: NodeMaterialBuildState, mesh: AbstractMesh, defines: NodeMaterialDefines) {\r\n // Do nothing\r\n }\r\n\r\n /** Gets a boolean indicating that the code of this block will be promoted to vertex shader even if connected to fragment output */\r\n public get willBeGeneratedIntoVertexShaderFromFragmentShader(): boolean {\r\n if (this.isInput || this.isFinalMerger) {\r\n return false;\r\n }\r\n\r\n if (this._outputs.some((o) => o.isDirectlyConnectedToVertexOutput)) {\r\n return false;\r\n }\r\n\r\n if (this.target === NodeMaterialBlockTargets.Vertex) {\r\n return false;\r\n }\r\n\r\n if (this.target === NodeMaterialBlockTargets.VertexAndFragment || this.target === NodeMaterialBlockTargets.Neutral) {\r\n if (this._outputs.some((o) => o.isConnectedInVertexShader)) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Checks if the block is ready\r\n * @param mesh defines the mesh to be rendered\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param defines defines the material defines to update\r\n * @param useInstances specifies that instances should be used\r\n * @returns true if the block is ready\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public isReady(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, useInstances: boolean = false) {\r\n return true;\r\n }\r\n\r\n protected _linkConnectionTypes(inputIndex0: number, inputIndex1: number, looseCoupling = false) {\r\n if (looseCoupling) {\r\n this._inputs[inputIndex1]._acceptedConnectionPointType = this._inputs[inputIndex0];\r\n } else {\r\n this._inputs[inputIndex0]._linkedConnectionSource = this._inputs[inputIndex1];\r\n }\r\n this._inputs[inputIndex1]._linkedConnectionSource = this._inputs[inputIndex0];\r\n }\r\n\r\n private _processBuild(block: NodeMaterialBlock, state: NodeMaterialBuildState, input: NodeMaterialConnectionPoint, activeBlocks: NodeMaterialBlock[]) {\r\n block.build(state, activeBlocks);\r\n\r\n const localBlockIsFragment = state._vertexState != null;\r\n const otherBlockWasGeneratedInVertexShader = block._buildTarget === NodeMaterialBlockTargets.Vertex && block.target !== NodeMaterialBlockTargets.VertexAndFragment;\r\n\r\n if (\r\n localBlockIsFragment &&\r\n ((block.target & block._buildTarget) === 0 ||\r\n (block.target & input.target) === 0 ||\r\n (this.target !== NodeMaterialBlockTargets.VertexAndFragment && otherBlockWasGeneratedInVertexShader))\r\n ) {\r\n // context switch! We need a varying\r\n if (\r\n (!block.isInput && state.target !== block._buildTarget) || // block was already emitted by vertex shader\r\n (block.isInput && (block as InputBlock).isAttribute && !(block as InputBlock)._noContextSwitch) // block is an attribute\r\n ) {\r\n const connectedPoint = input.connectedPoint!;\r\n if (state._vertexState._emitVaryingFromString(\"v_\" + connectedPoint.associatedVariableName, state._getGLType(connectedPoint.type))) {\r\n state._vertexState.compilationString += `${\"v_\" + connectedPoint.associatedVariableName} = ${connectedPoint.associatedVariableName};\\n`;\r\n }\r\n input.associatedVariableName = \"v_\" + connectedPoint.associatedVariableName;\r\n input._enforceAssociatedVariableName = true;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Validates the new name for the block node.\r\n * @param newName the new name to be given to the node.\r\n * @returns false if the name is a reserve word, else true.\r\n */\r\n public validateBlockName(newName: string) {\r\n const reservedNames: Array = [\r\n \"position\",\r\n \"normal\",\r\n \"tangent\",\r\n \"particle_positionw\",\r\n \"uv\",\r\n \"uv2\",\r\n \"uv3\",\r\n \"uv4\",\r\n \"uv5\",\r\n \"uv6\",\r\n \"position2d\",\r\n \"particle_uv\",\r\n \"matricesIndices\",\r\n \"matricesWeights\",\r\n \"world0\",\r\n \"world1\",\r\n \"world2\",\r\n \"world3\",\r\n \"particle_color\",\r\n \"particle_texturemask\",\r\n ];\r\n for (const reservedName of reservedNames) {\r\n if (newName === reservedName) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _customBuildStep(state: NodeMaterialBuildState, activeBlocks: NodeMaterialBlock[]): void {\r\n // Must be implemented by children\r\n }\r\n\r\n /**\r\n * Compile the current node and generate the shader code\r\n * @param state defines the current compilation state (uniforms, samplers, current string)\r\n * @param activeBlocks defines the list of active blocks (i.e. blocks to compile)\r\n * @returns true if already built\r\n */\r\n public build(state: NodeMaterialBuildState, activeBlocks: NodeMaterialBlock[]): boolean {\r\n if (this._buildId === state.sharedData.buildId) {\r\n return true;\r\n }\r\n\r\n if (!this.isInput) {\r\n /** Prepare outputs */\r\n for (const output of this._outputs) {\r\n if (!output.associatedVariableName) {\r\n output.associatedVariableName = state._getFreeVariableName(output.name);\r\n }\r\n }\r\n }\r\n\r\n // Check if \"parent\" blocks are compiled\r\n for (const input of this._inputs) {\r\n if (!input.connectedPoint) {\r\n if (!input.isOptional) {\r\n // Emit a warning\r\n state.sharedData.checks.notConnectedNonOptionalInputs.push(input);\r\n }\r\n continue;\r\n }\r\n\r\n if (this.target !== NodeMaterialBlockTargets.Neutral) {\r\n if ((input.target & this.target!) === 0) {\r\n continue;\r\n }\r\n\r\n if ((input.target & state.target!) === 0) {\r\n continue;\r\n }\r\n }\r\n\r\n const block = input.connectedPoint.ownerBlock;\r\n if (block && block !== this) {\r\n this._processBuild(block, state, input, activeBlocks);\r\n }\r\n }\r\n\r\n this._customBuildStep(state, activeBlocks);\r\n\r\n if (this._buildId === state.sharedData.buildId) {\r\n return true; // Need to check again as inputs can be connected multiple time to this endpoint\r\n }\r\n\r\n // Logs\r\n if (state.sharedData.verbose) {\r\n console.log(`${state.target === NodeMaterialBlockTargets.Vertex ? \"Vertex shader\" : \"Fragment shader\"}: Building ${this.name} [${this.getClassName()}]`);\r\n }\r\n\r\n // Checks final outputs\r\n if (this.isFinalMerger) {\r\n switch (state.target) {\r\n case NodeMaterialBlockTargets.Vertex:\r\n state.sharedData.checks.emitVertex = true;\r\n break;\r\n case NodeMaterialBlockTargets.Fragment:\r\n state.sharedData.checks.emitFragment = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!this.isInput && state.sharedData.emitComments) {\r\n state.compilationString += `\\n//${this.name}\\n`;\r\n }\r\n\r\n this._buildBlock(state);\r\n\r\n this._buildId = state.sharedData.buildId;\r\n this._buildTarget = state.target;\r\n\r\n // Compile connected blocks\r\n for (const output of this._outputs) {\r\n if ((output.target & state.target) === 0) {\r\n continue;\r\n }\r\n\r\n for (const endpoint of output.endpoints) {\r\n const block = endpoint.ownerBlock;\r\n\r\n if (block && (block.target & state.target) !== 0 && activeBlocks.indexOf(block) !== -1) {\r\n this._processBuild(block, state, endpoint, activeBlocks);\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n protected _inputRename(name: string) {\r\n return name;\r\n }\r\n\r\n protected _outputRename(name: string) {\r\n return name;\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const variableName = this._codeVariableName;\r\n return `${variableName}.visibleInInspector = ${this.visibleInInspector};\\n${variableName}.visibleOnFrame = ${this.visibleOnFrame};\\n${variableName}.target = ${this.target};\\n`;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _dumpCode(uniqueNames: string[], alreadyDumped: NodeMaterialBlock[]) {\r\n alreadyDumped.push(this);\r\n\r\n // Get unique name\r\n const nameAsVariableName = this.name.replace(/[^A-Za-z_]+/g, \"\");\r\n this._codeVariableName = nameAsVariableName || `${this.getClassName()}_${this.uniqueId}`;\r\n\r\n if (uniqueNames.indexOf(this._codeVariableName) !== -1) {\r\n let index = 0;\r\n do {\r\n index++;\r\n this._codeVariableName = nameAsVariableName + index;\r\n } while (uniqueNames.indexOf(this._codeVariableName) !== -1);\r\n }\r\n\r\n uniqueNames.push(this._codeVariableName);\r\n\r\n // Declaration\r\n let codeString = `\\n// ${this.getClassName()}\\n`;\r\n if (this.comments) {\r\n codeString += `// ${this.comments}\\n`;\r\n }\r\n codeString += `var ${this._codeVariableName} = new BABYLON.${this.getClassName()}(\"${this.name}\");\\n`;\r\n\r\n // Properties\r\n codeString += this._dumpPropertiesCode();\r\n\r\n // Inputs\r\n for (const input of this.inputs) {\r\n if (!input.isConnected) {\r\n continue;\r\n }\r\n\r\n const connectedOutput = input.connectedPoint!;\r\n const connectedBlock = connectedOutput.ownerBlock;\r\n\r\n if (alreadyDumped.indexOf(connectedBlock) === -1) {\r\n codeString += connectedBlock._dumpCode(uniqueNames, alreadyDumped);\r\n }\r\n }\r\n\r\n // Outputs\r\n for (const output of this.outputs) {\r\n if (!output.hasEndpoints) {\r\n continue;\r\n }\r\n\r\n for (const endpoint of output.endpoints) {\r\n const connectedBlock = endpoint.ownerBlock;\r\n if (connectedBlock && alreadyDumped.indexOf(connectedBlock) === -1) {\r\n codeString += connectedBlock._dumpCode(uniqueNames, alreadyDumped);\r\n }\r\n }\r\n }\r\n\r\n return codeString;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _dumpCodeForOutputConnections(alreadyDumped: NodeMaterialBlock[]) {\r\n let codeString = \"\";\r\n\r\n if (alreadyDumped.indexOf(this) !== -1) {\r\n return codeString;\r\n }\r\n\r\n alreadyDumped.push(this);\r\n\r\n for (const input of this.inputs) {\r\n if (!input.isConnected) {\r\n continue;\r\n }\r\n\r\n const connectedOutput = input.connectedPoint!;\r\n const connectedBlock = connectedOutput.ownerBlock;\r\n\r\n codeString += connectedBlock._dumpCodeForOutputConnections(alreadyDumped);\r\n codeString += `${connectedBlock._codeVariableName}.${connectedBlock._outputRename(connectedOutput.name)}.connectTo(${this._codeVariableName}.${this._inputRename(\r\n input.name\r\n )});\\n`;\r\n }\r\n\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Clone the current block to a new identical block\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a copy of the current block\r\n */\r\n public clone(scene: Scene, rootUrl: string = \"\") {\r\n const serializationObject = this.serialize();\r\n\r\n const blockType = GetClass(serializationObject.customType);\r\n if (blockType) {\r\n const block: NodeMaterialBlock = new blockType();\r\n block._deserialize(serializationObject, scene, rootUrl);\r\n\r\n return block;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.customType = \"BABYLON.\" + this.getClassName();\r\n serializationObject.id = this.uniqueId;\r\n serializationObject.name = this.name;\r\n serializationObject.comments = this.comments;\r\n serializationObject.visibleInInspector = this.visibleInInspector;\r\n serializationObject.visibleOnFrame = this.visibleOnFrame;\r\n serializationObject.target = this.target;\r\n\r\n serializationObject.inputs = [];\r\n serializationObject.outputs = [];\r\n\r\n for (const input of this.inputs) {\r\n serializationObject.inputs.push(input.serialize());\r\n }\r\n\r\n for (const output of this.outputs) {\r\n serializationObject.outputs.push(output.serialize(false));\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n this.name = serializationObject.name;\r\n this.comments = serializationObject.comments;\r\n this.visibleInInspector = !!serializationObject.visibleInInspector;\r\n this.visibleOnFrame = !!serializationObject.visibleOnFrame;\r\n this._target = serializationObject.target ?? this.target;\r\n this._deserializePortDisplayNamesAndExposedOnFrame(serializationObject);\r\n }\r\n\r\n private _deserializePortDisplayNamesAndExposedOnFrame(serializationObject: any) {\r\n const serializedInputs = serializationObject.inputs;\r\n const serializedOutputs = serializationObject.outputs;\r\n if (serializedInputs) {\r\n serializedInputs.forEach((port: any, i: number) => {\r\n if (port.displayName) {\r\n this.inputs[i].displayName = port.displayName;\r\n }\r\n if (port.isExposedOnFrame) {\r\n this.inputs[i].isExposedOnFrame = port.isExposedOnFrame;\r\n this.inputs[i].exposedPortPosition = port.exposedPortPosition;\r\n }\r\n });\r\n }\r\n if (serializedOutputs) {\r\n serializedOutputs.forEach((port: any, i: number) => {\r\n if (port.displayName) {\r\n this.outputs[i].displayName = port.displayName;\r\n }\r\n if (port.isExposedOnFrame) {\r\n this.outputs[i].isExposedOnFrame = port.isExposedOnFrame;\r\n this.outputs[i].exposedPortPosition = port.exposedPortPosition;\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Release resources\r\n */\r\n public dispose() {\r\n for (const input of this.inputs) {\r\n input.dispose();\r\n }\r\n\r\n for (const output of this.outputs) {\r\n output.dispose();\r\n }\r\n }\r\n}\r\n","import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport type { Scene } from \"../../../scene\";\r\nimport type { InputBlock } from \"./Input/inputBlock\";\r\nimport type { AbstractMesh } from \"../../../Meshes/abstractMesh\";\r\nimport type { NodeMaterial, NodeMaterialDefines } from \"../nodeMaterial\";\r\n\r\n/**\r\n * Block used to transform a vector (2, 3 or 4) with a matrix. It will generate a Vector4\r\n */\r\nexport class TransformBlock extends NodeMaterialBlock {\r\n /**\r\n * Defines the value to use to complement W value to transform it to a Vector4\r\n */\r\n public complementW = 1;\r\n\r\n /**\r\n * Defines the value to use to complement z value to transform it to a Vector4\r\n */\r\n public complementZ = 0;\r\n\r\n /**\r\n * Creates a new TransformBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.target = NodeMaterialBlockTargets.Vertex;\r\n\r\n this.registerInput(\"vector\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"transform\", NodeMaterialBlockConnectionPointTypes.Matrix);\r\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Vector4);\r\n this.registerOutput(\"xyz\", NodeMaterialBlockConnectionPointTypes.Vector3);\r\n\r\n this._inputs[0].onConnectionObservable.add((other) => {\r\n if (other.ownerBlock.isInput) {\r\n const otherAsInput = other.ownerBlock as InputBlock;\r\n\r\n if (otherAsInput.name === \"normal\" || otherAsInput.name === \"tangent\") {\r\n this.complementW = 0;\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"TransformBlock\";\r\n }\r\n\r\n /**\r\n * Gets the vector input\r\n */\r\n public get vector(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the xyz output component\r\n */\r\n public get xyz(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the matrix transform input\r\n */\r\n public get transform(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const vector = this.vector;\r\n const transform = this.transform;\r\n\r\n if (vector.connectedPoint) {\r\n // None uniform scaling case.\r\n if (this.complementW === 0) {\r\n const comments = `//${this.name}`;\r\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\r\n state.sharedData.blocksWithDefines.push(this);\r\n\r\n const transformName = state._getFreeVariableName(`${transform.associatedVariableName}_NUS`);\r\n state.compilationString += `mat3 ${transformName} = mat3(${transform.associatedVariableName});\\n`;\r\n state.compilationString += `#ifdef NONUNIFORMSCALING\\n`;\r\n state.compilationString += `${transformName} = transposeMat3(inverseMat3(${transformName}));\\n`;\r\n state.compilationString += `#endif\\n`;\r\n switch (vector.connectedPoint.type) {\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n state.compilationString +=\r\n this._declareOutput(this.output, state) +\r\n ` = vec4(${transformName} * vec3(${vector.associatedVariableName}, ${this._writeFloat(this.complementZ)}), ${this._writeFloat(this.complementW)});\\n`;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n state.compilationString +=\r\n this._declareOutput(this.output, state) + ` = vec4(${transformName} * ${vector.associatedVariableName}, ${this._writeFloat(this.complementW)});\\n`;\r\n break;\r\n default:\r\n state.compilationString +=\r\n this._declareOutput(this.output, state) + ` = vec4(${transformName} * ${vector.associatedVariableName}.xyz, ${this._writeFloat(this.complementW)});\\n`;\r\n break;\r\n }\r\n } else {\r\n const transformName = transform.associatedVariableName;\r\n switch (vector.connectedPoint.type) {\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n state.compilationString +=\r\n this._declareOutput(this.output, state) +\r\n ` = ${transformName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementZ)}, ${this._writeFloat(this.complementW)});\\n`;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n state.compilationString +=\r\n this._declareOutput(this.output, state) + ` = ${transformName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementW)});\\n`;\r\n break;\r\n default:\r\n state.compilationString += this._declareOutput(this.output, state) + ` = ${transformName} * ${vector.associatedVariableName};\\n`;\r\n break;\r\n }\r\n }\r\n\r\n if (this.xyz.hasEndpoints) {\r\n state.compilationString += this._declareOutput(this.xyz, state) + ` = ${this.output.associatedVariableName}.xyz;\\n`;\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Update defines for shader compilation\r\n * @param mesh defines the mesh to be rendered\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param defines defines the material defines to update\r\n */\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {\r\n // Do nothing\r\n if (mesh.nonUniformScaling) {\r\n defines.setValue(\"NONUNIFORMSCALING\", true);\r\n }\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.complementZ = this.complementZ;\r\n serializationObject.complementW = this.complementW;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.complementZ = serializationObject.complementZ !== undefined ? serializationObject.complementZ : 0.0;\r\n this.complementW = serializationObject.complementW !== undefined ? serializationObject.complementW : 1.0;\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n let codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.complementZ = ${this.complementZ};\\n`;\r\n\r\n codeString += `${this._codeVariableName}.complementW = ${this.complementW};\\n`;\r\n\r\n return codeString;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.TransformBlock\", TransformBlock);\r\n","import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport type { Immutable } from \"../../../../types\";\r\n\r\nimport type { FragmentOutputBlock } from \"../Fragment/fragmentOutputBlock\";\r\n\r\n/**\r\n * Block used to output the vertex position\r\n */\r\nexport class VertexOutputBlock extends NodeMaterialBlock {\r\n /**\r\n * Creates a new VertexOutputBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Vertex, true);\r\n\r\n this.registerInput(\"vector\", NodeMaterialBlockConnectionPointTypes.Vector4);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"VertexOutputBlock\";\r\n }\r\n\r\n /**\r\n * Gets the vector input component\r\n */\r\n public get vector(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n private _isLogarithmicDepthEnabled(nodeList: Immutable): boolean {\r\n for (const node of nodeList) {\r\n if ((node as FragmentOutputBlock).useLogarithmicDepth) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const input = this.vector;\r\n\r\n state.compilationString += `gl_Position = ${input.associatedVariableName};\\n`;\r\n\r\n if (this._isLogarithmicDepthEnabled(state.sharedData.fragmentOutputNodes)) {\r\n state._emitUniformFromString(\"logarithmicDepthConstant\", \"float\");\r\n state._emitVaryingFromString(\"vFragmentDepth\", \"float\");\r\n\r\n state.compilationString += `vFragmentDepth = 1.0 + gl_Position.w;\\n`;\r\n state.compilationString += `gl_Position.z = log2(max(0.000001, vFragmentDepth)) * logarithmicDepthConstant;\\n`;\r\n }\r\n\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.VertexOutputBlock\", VertexOutputBlock);\r\n","import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport type { Scene } from \"../../../../scene\";\r\nimport type { AbstractMesh } from \"../../../../Meshes/abstractMesh\";\r\nimport type { NodeMaterialDefines } from \"../../nodeMaterial\";\r\nimport { editableInPropertyPage, PropertyTypeForEdition } from \"../../../../Decorators/nodeDecorator\";\r\nimport { MaterialHelper } from \"../../../materialHelper\";\r\n\r\nimport type { NodeMaterial } from \"../../nodeMaterial\";\r\nimport type { Effect } from \"../../../effect\";\r\nimport type { Mesh } from \"../../../../Meshes/mesh\";\r\n\r\n/**\r\n * Block used to output the final color\r\n */\r\nexport class FragmentOutputBlock extends NodeMaterialBlock {\r\n private _linearDefineName: string;\r\n private _gammaDefineName: string;\r\n\r\n /**\r\n * Create a new FragmentOutputBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Fragment, true);\r\n\r\n this.registerInput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, true);\r\n this.registerInput(\"rgb\", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);\r\n this.registerInput(\"a\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n\r\n this.rgb.addExcludedConnectionPointFromAllowedTypes(\r\n NodeMaterialBlockConnectionPointTypes.Color3 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Float\r\n );\r\n }\r\n\r\n /** Gets or sets a boolean indicating if content needs to be converted to gamma space */\r\n @editableInPropertyPage(\"Convert to gamma space\", PropertyTypeForEdition.Boolean, \"PROPERTIES\", { notifiers: { update: true } })\r\n public convertToGammaSpace = false;\r\n\r\n /** Gets or sets a boolean indicating if content needs to be converted to linear space */\r\n @editableInPropertyPage(\"Convert to linear space\", PropertyTypeForEdition.Boolean, \"PROPERTIES\", { notifiers: { update: true } })\r\n public convertToLinearSpace = false;\r\n\r\n /** Gets or sets a boolean indicating if logarithmic depth should be used */\r\n @editableInPropertyPage(\"Use logarithmic depth\", PropertyTypeForEdition.Boolean, \"PROPERTIES\")\r\n public useLogarithmicDepth = false;\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"FragmentOutputBlock\";\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"logarithmicDepthConstant\");\r\n state._excludeVariableName(\"vFragmentDepth\");\r\n }\r\n\r\n /**\r\n * Gets the rgba input component\r\n */\r\n public get rgba(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgb input component\r\n */\r\n public get rgb(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the a input component\r\n */\r\n public get a(): NodeMaterialConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {\r\n defines.setValue(this._linearDefineName, this.convertToLinearSpace, true);\r\n defines.setValue(this._gammaDefineName, this.convertToGammaSpace, true);\r\n }\r\n\r\n public bind(effect: Effect, nodeMaterial: NodeMaterial, mesh?: Mesh) {\r\n if (this.useLogarithmicDepth && mesh) {\r\n MaterialHelper.BindLogDepth(undefined, effect, mesh.getScene());\r\n }\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const rgba = this.rgba;\r\n const rgb = this.rgb;\r\n const a = this.a;\r\n\r\n state.sharedData.hints.needAlphaBlending = rgba.isConnected || a.isConnected;\r\n state.sharedData.blocksWithDefines.push(this);\r\n if (this.useLogarithmicDepth) {\r\n state._emitUniformFromString(\"logarithmicDepthConstant\", \"float\");\r\n state._emitVaryingFromString(\"vFragmentDepth\", \"float\");\r\n state.sharedData.bindableBlocks.push(this);\r\n }\r\n this._linearDefineName = state._getFreeDefineName(\"CONVERTTOLINEAR\");\r\n this._gammaDefineName = state._getFreeDefineName(\"CONVERTTOGAMMA\");\r\n\r\n const comments = `//${this.name}`;\r\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\r\n\r\n if (rgba.connectedPoint) {\r\n if (a.isConnected) {\r\n state.compilationString += `gl_FragColor = vec4(${rgba.associatedVariableName}.rgb, ${a.associatedVariableName});\\n`;\r\n } else {\r\n state.compilationString += `gl_FragColor = ${rgba.associatedVariableName};\\n`;\r\n }\r\n } else if (rgb.connectedPoint) {\r\n let aValue = \"1.0\";\r\n\r\n if (a.connectedPoint) {\r\n aValue = a.associatedVariableName;\r\n }\r\n\r\n if (rgb.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Float) {\r\n state.compilationString += `gl_FragColor = vec4(${rgb.associatedVariableName}, ${rgb.associatedVariableName}, ${rgb.associatedVariableName}, ${aValue});\\n`;\r\n } else {\r\n state.compilationString += `gl_FragColor = vec4(${rgb.associatedVariableName}, ${aValue});\\n`;\r\n }\r\n } else {\r\n state.sharedData.checks.notConnectedNonOptionalInputs.push(rgba);\r\n }\r\n\r\n state.compilationString += `#ifdef ${this._linearDefineName}\\n`;\r\n state.compilationString += `gl_FragColor = toLinearSpace(gl_FragColor);\\n`;\r\n state.compilationString += `#endif\\n`;\r\n\r\n state.compilationString += `#ifdef ${this._gammaDefineName}\\n`;\r\n state.compilationString += `gl_FragColor = toGammaSpace(gl_FragColor);\\n`;\r\n state.compilationString += `#endif\\n`;\r\n\r\n if (this.useLogarithmicDepth) {\r\n state.compilationString += `gl_FragDepthEXT = log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;\\n`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n let codeString = super._dumpPropertiesCode();\r\n codeString += `${this._codeVariableName}.convertToGammaSpace = ${this.convertToGammaSpace};\\n`;\r\n codeString += `${this._codeVariableName}.convertToLinearSpace = ${this.convertToLinearSpace};\\n`;\r\n codeString += `${this._codeVariableName}.useLogarithmicDepth = ${this.useLogarithmicDepth};\\n`;\r\n\r\n return codeString;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\r\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\r\n serializationObject.useLogarithmicDepth = this.useLogarithmicDepth;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.convertToGammaSpace = serializationObject.convertToGammaSpace;\r\n this.convertToLinearSpace = serializationObject.convertToLinearSpace;\r\n this.useLogarithmicDepth = serializationObject.useLogarithmicDepth ?? false;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.FragmentOutputBlock\", FragmentOutputBlock);\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport { NodeMaterialBlockConnectionPointMode } from \"../../Enums/nodeMaterialBlockConnectionPointMode\";\r\nimport { NodeMaterialSystemValues } from \"../../Enums/nodeMaterialSystemValues\";\r\nimport type { Nullable } from \"../../../../types\";\r\nimport type { Effect } from \"../../../../Materials/effect\";\r\nimport { Matrix, Vector2, Vector3, Vector4 } from \"../../../../Maths/math.vector\";\r\nimport type { Scene } from \"../../../../scene\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport { GetClass, RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { Color3, Color4, TmpColors } from \"../../../../Maths/math\";\r\nimport { AnimatedInputBlockTypes } from \"./animatedInputBlockTypes\";\r\nimport { Observable } from \"../../../../Misc/observable\";\r\nimport type { NodeMaterial } from \"../../nodeMaterial\";\r\nimport { PrecisionDate } from \"core/Misc/precisionDate\";\r\n\r\nconst remapAttributeName: { [name: string]: string } = {\r\n position2d: \"position\",\r\n particle_uv: \"vUV\",\r\n particle_color: \"vColor\",\r\n particle_texturemask: \"textureMask\",\r\n particle_positionw: \"vPositionW\",\r\n};\r\n\r\nconst attributeInFragmentOnly: { [name: string]: boolean } = {\r\n particle_uv: true,\r\n particle_color: true,\r\n particle_texturemask: true,\r\n particle_positionw: true,\r\n};\r\n\r\nconst attributeAsUniform: { [name: string]: boolean } = {\r\n particle_texturemask: true,\r\n};\r\n\r\n/**\r\n * Block used to expose an input value\r\n */\r\nexport class InputBlock extends NodeMaterialBlock {\r\n private _mode = NodeMaterialBlockConnectionPointMode.Undefined;\r\n private _associatedVariableName: string;\r\n private _storedValue: any;\r\n private _valueCallback: () => any;\r\n private _type: NodeMaterialBlockConnectionPointTypes;\r\n private _animationType = AnimatedInputBlockTypes.None;\r\n\r\n /** Gets or set a value used to limit the range of float values */\r\n public min: number = 0;\r\n\r\n /** Gets or set a value used to limit the range of float values */\r\n public max: number = 0;\r\n\r\n /** Gets or set a value indicating that this input can only get 0 and 1 values */\r\n public isBoolean: boolean = false;\r\n\r\n /** Gets or sets a value used by the Node Material editor to determine how to configure the current value if it is a matrix */\r\n public matrixMode: number = 0;\r\n\r\n /** @internal */\r\n public _systemValue: Nullable = null;\r\n\r\n /** Gets or sets a boolean indicating that the value of this input will not change after a build */\r\n public isConstant = false;\r\n\r\n /** Gets or sets the group to use to display this block in the Inspector */\r\n public groupInInspector = \"\";\r\n\r\n /** Gets an observable raised when the value is changed */\r\n public onValueChangedObservable = new Observable();\r\n\r\n /** Gets or sets a boolean indicating if content needs to be converted to gamma space (for color3/4 only) */\r\n public convertToGammaSpace = false;\r\n\r\n /** Gets or sets a boolean indicating if content needs to be converted to linear space (for color3/4 only) */\r\n public convertToLinearSpace = false;\r\n\r\n /**\r\n * Gets or sets the connection point type (default is float)\r\n */\r\n public get type(): NodeMaterialBlockConnectionPointTypes {\r\n if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {\r\n if (this.isUniform && this.value != null) {\r\n if (!isNaN(this.value)) {\r\n this._type = NodeMaterialBlockConnectionPointTypes.Float;\r\n return this._type;\r\n }\r\n\r\n switch (this.value.getClassName()) {\r\n case \"Vector2\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector2;\r\n return this._type;\r\n case \"Vector3\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector3;\r\n return this._type;\r\n case \"Vector4\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\r\n return this._type;\r\n case \"Color3\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Color3;\r\n return this._type;\r\n case \"Color4\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Color4;\r\n return this._type;\r\n case \"Matrix\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Matrix;\r\n return this._type;\r\n }\r\n }\r\n\r\n if (this.isAttribute) {\r\n switch (this.name) {\r\n case \"position\":\r\n case \"normal\":\r\n case \"particle_positionw\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector3;\r\n return this._type;\r\n case \"uv\":\r\n case \"uv2\":\r\n case \"uv3\":\r\n case \"uv4\":\r\n case \"uv5\":\r\n case \"uv6\":\r\n case \"position2d\":\r\n case \"particle_uv\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector2;\r\n return this._type;\r\n case \"matricesIndices\":\r\n case \"matricesWeights\":\r\n case \"matricesIndicesExtra\":\r\n case \"matricesWeightsExtra\":\r\n case \"world0\":\r\n case \"world1\":\r\n case \"world2\":\r\n case \"world3\":\r\n case \"tangent\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\r\n return this._type;\r\n case \"color\":\r\n case \"instanceColor\":\r\n case \"particle_color\":\r\n case \"particle_texturemask\":\r\n this._type = NodeMaterialBlockConnectionPointTypes.Color4;\r\n return this._type;\r\n }\r\n }\r\n\r\n if (this.isSystemValue) {\r\n switch (this._systemValue) {\r\n case NodeMaterialSystemValues.World:\r\n case NodeMaterialSystemValues.WorldView:\r\n case NodeMaterialSystemValues.WorldViewProjection:\r\n case NodeMaterialSystemValues.View:\r\n case NodeMaterialSystemValues.ViewProjection:\r\n case NodeMaterialSystemValues.Projection:\r\n this._type = NodeMaterialBlockConnectionPointTypes.Matrix;\r\n return this._type;\r\n case NodeMaterialSystemValues.CameraPosition:\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector3;\r\n return this._type;\r\n case NodeMaterialSystemValues.FogColor:\r\n this._type = NodeMaterialBlockConnectionPointTypes.Color3;\r\n return this._type;\r\n case NodeMaterialSystemValues.DeltaTime:\r\n case NodeMaterialSystemValues.MaterialAlpha:\r\n this._type = NodeMaterialBlockConnectionPointTypes.Float;\r\n return this._type;\r\n case NodeMaterialSystemValues.CameraParameters:\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\r\n return this._type;\r\n }\r\n }\r\n }\r\n\r\n return this._type;\r\n }\r\n\r\n /**\r\n * Creates a new InputBlock\r\n * @param name defines the block name\r\n * @param target defines the target of that block (Vertex by default)\r\n * @param type defines the type of the input (can be set to NodeMaterialBlockConnectionPointTypes.AutoDetect)\r\n */\r\n public constructor(name: string, target = NodeMaterialBlockTargets.Vertex, type: NodeMaterialBlockConnectionPointTypes = NodeMaterialBlockConnectionPointTypes.AutoDetect) {\r\n super(name, target, false);\r\n\r\n this._type = type;\r\n\r\n this.setDefaultValue();\r\n\r\n this.registerOutput(\"output\", type);\r\n }\r\n\r\n /**\r\n * Validates if a name is a reserve word.\r\n * @param newName the new name to be given to the node.\r\n * @returns false if the name is a reserve word, else true.\r\n */\r\n public validateBlockName(newName: string) {\r\n if (!this.isAttribute) {\r\n return super.validateBlockName(newName);\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Set the source of this connection point to a vertex attribute\r\n * @param attributeName defines the attribute name (position, uv, normal, etc...). If not specified it will take the connection point name\r\n * @returns the current connection point\r\n */\r\n public setAsAttribute(attributeName?: string): InputBlock {\r\n this._mode = NodeMaterialBlockConnectionPointMode.Attribute;\r\n if (attributeName) {\r\n this.name = attributeName;\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the source of this connection point to a system value\r\n * @param value define the system value to use (world, view, etc...) or null to switch to manual value\r\n * @returns the current connection point\r\n */\r\n public setAsSystemValue(value: Nullable): InputBlock {\r\n this.systemValue = value;\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets or sets the value of that point.\r\n * Please note that this value will be ignored if valueCallback is defined\r\n */\r\n public get value(): any {\r\n return this._storedValue;\r\n }\r\n\r\n public set value(value: any) {\r\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\r\n if (this.isBoolean) {\r\n value = value ? 1 : 0;\r\n } else if (this.min !== this.max) {\r\n value = Math.max(this.min, value);\r\n value = Math.min(this.max, value);\r\n }\r\n }\r\n\r\n this._storedValue = value;\r\n this._mode = NodeMaterialBlockConnectionPointMode.Uniform;\r\n\r\n this.onValueChangedObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Gets or sets a callback used to get the value of that point.\r\n * Please note that setting this value will force the connection point to ignore the value property\r\n */\r\n public get valueCallback(): () => any {\r\n return this._valueCallback;\r\n }\r\n\r\n public set valueCallback(value: () => any) {\r\n this._valueCallback = value;\r\n this._mode = NodeMaterialBlockConnectionPointMode.Uniform;\r\n }\r\n\r\n /**\r\n * Gets or sets the associated variable name in the shader\r\n */\r\n public get associatedVariableName(): string {\r\n return this._associatedVariableName;\r\n }\r\n\r\n public set associatedVariableName(value: string) {\r\n this._associatedVariableName = value;\r\n }\r\n\r\n /** Gets or sets the type of animation applied to the input */\r\n public get animationType() {\r\n return this._animationType;\r\n }\r\n\r\n public set animationType(value: AnimatedInputBlockTypes) {\r\n this._animationType = value;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that this connection point not defined yet\r\n */\r\n public get isUndefined(): boolean {\r\n return this._mode === NodeMaterialBlockConnectionPointMode.Undefined;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this connection point is coming from an uniform.\r\n * In this case the connection point name must be the name of the uniform to use.\r\n * Can only be set on inputs\r\n */\r\n public get isUniform(): boolean {\r\n return this._mode === NodeMaterialBlockConnectionPointMode.Uniform;\r\n }\r\n\r\n public set isUniform(value: boolean) {\r\n this._mode = value ? NodeMaterialBlockConnectionPointMode.Uniform : NodeMaterialBlockConnectionPointMode.Undefined;\r\n this.associatedVariableName = \"\";\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this connection point is coming from an attribute.\r\n * In this case the connection point name must be the name of the attribute to use\r\n * Can only be set on inputs\r\n */\r\n public get isAttribute(): boolean {\r\n return this._mode === NodeMaterialBlockConnectionPointMode.Attribute;\r\n }\r\n\r\n public set isAttribute(value: boolean) {\r\n this._mode = value ? NodeMaterialBlockConnectionPointMode.Attribute : NodeMaterialBlockConnectionPointMode.Undefined;\r\n this.associatedVariableName = \"\";\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this connection point is generating a varying variable.\r\n * Can only be set on exit points\r\n */\r\n public get isVarying(): boolean {\r\n return this._mode === NodeMaterialBlockConnectionPointMode.Varying;\r\n }\r\n\r\n public set isVarying(value: boolean) {\r\n this._mode = value ? NodeMaterialBlockConnectionPointMode.Varying : NodeMaterialBlockConnectionPointMode.Undefined;\r\n this.associatedVariableName = \"\";\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the current connection point is a system value\r\n */\r\n public get isSystemValue(): boolean {\r\n return this._systemValue != null;\r\n }\r\n\r\n /**\r\n * Gets or sets the current well known value or null if not defined as a system value\r\n */\r\n public get systemValue(): Nullable {\r\n return this._systemValue;\r\n }\r\n\r\n public set systemValue(value: Nullable) {\r\n this._mode = NodeMaterialBlockConnectionPointMode.Uniform;\r\n this.associatedVariableName = \"\";\r\n this._systemValue = value;\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"InputBlock\";\r\n }\r\n\r\n /**\r\n * Animate the input if animationType !== None\r\n * @param scene defines the rendering scene\r\n */\r\n public animate(scene: Scene) {\r\n switch (this._animationType) {\r\n case AnimatedInputBlockTypes.Time: {\r\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\r\n this.value += scene.getAnimationRatio() * 0.01;\r\n }\r\n break;\r\n }\r\n case AnimatedInputBlockTypes.RealTime: {\r\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\r\n this.value = (PrecisionDate.Now - scene.getEngine().startTime) / 1000;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n private _emitDefine(define: string): string {\r\n if (define[0] === \"!\") {\r\n return `#ifndef ${define.substring(1)}\\n`;\r\n }\r\n\r\n return `#ifdef ${define}\\n`;\r\n }\r\n\r\n public initialize() {\r\n this.associatedVariableName = \"\";\r\n }\r\n\r\n /**\r\n * Set the input block to its default value (based on its type)\r\n */\r\n public setDefaultValue() {\r\n switch (this.type) {\r\n case NodeMaterialBlockConnectionPointTypes.Float:\r\n this.value = 0;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n this.value = Vector2.Zero();\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n this.value = Vector3.Zero();\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector4:\r\n this.value = Vector4.Zero();\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n this.value = Color3.White();\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Color4:\r\n this.value = new Color4(1, 1, 1, 1);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Matrix:\r\n this.value = Matrix.Identity();\r\n break;\r\n }\r\n }\r\n\r\n private _emitConstant(state: NodeMaterialBuildState) {\r\n switch (this.type) {\r\n case NodeMaterialBlockConnectionPointTypes.Float:\r\n return `${state._emitFloat(this.value)}`;\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n return `vec2(${this.value.x}, ${this.value.y})`;\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n return `vec3(${this.value.x}, ${this.value.y}, ${this.value.z})`;\r\n case NodeMaterialBlockConnectionPointTypes.Vector4:\r\n return `vec4(${this.value.x}, ${this.value.y}, ${this.value.z}, ${this.value.w})`;\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n TmpColors.Color3[0].set(this.value.r, this.value.g, this.value.b);\r\n if (this.convertToGammaSpace) {\r\n TmpColors.Color3[0].toGammaSpaceToRef(TmpColors.Color3[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\r\n }\r\n if (this.convertToLinearSpace) {\r\n TmpColors.Color3[0].toLinearSpaceToRef(TmpColors.Color3[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\r\n }\r\n return `vec3(${TmpColors.Color3[0].r}, ${TmpColors.Color3[0].g}, ${TmpColors.Color3[0].b})`;\r\n case NodeMaterialBlockConnectionPointTypes.Color4:\r\n TmpColors.Color4[0].set(this.value.r, this.value.g, this.value.b, this.value.a);\r\n if (this.convertToGammaSpace) {\r\n TmpColors.Color4[0].toGammaSpaceToRef(TmpColors.Color4[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\r\n }\r\n if (this.convertToLinearSpace) {\r\n TmpColors.Color4[0].toLinearSpaceToRef(TmpColors.Color4[0], state.sharedData.scene.getEngine().useExactSrgbConversions);\r\n }\r\n return `vec4(${TmpColors.Color4[0].r}, ${TmpColors.Color4[0].g}, ${TmpColors.Color4[0].b}, ${TmpColors.Color4[0].a})`;\r\n }\r\n\r\n return \"\";\r\n }\r\n\r\n /** @internal */\r\n public get _noContextSwitch(): boolean {\r\n return attributeInFragmentOnly[this.name];\r\n }\r\n\r\n private _emit(state: NodeMaterialBuildState, define?: string) {\r\n // Uniforms\r\n if (this.isUniform) {\r\n if (!this.associatedVariableName) {\r\n this.associatedVariableName = state._getFreeVariableName(\"u_\" + this.name);\r\n }\r\n\r\n if (this.isConstant) {\r\n if (state.constants.indexOf(this.associatedVariableName) !== -1) {\r\n return;\r\n }\r\n state.constants.push(this.associatedVariableName);\r\n state._constantDeclaration += this._declareOutput(this.output, state) + ` = ${this._emitConstant(state)};\\n`;\r\n return;\r\n }\r\n\r\n if (state.uniforms.indexOf(this.associatedVariableName) !== -1) {\r\n return;\r\n }\r\n\r\n state.uniforms.push(this.associatedVariableName);\r\n if (define) {\r\n state._uniformDeclaration += this._emitDefine(define);\r\n }\r\n state._uniformDeclaration += `uniform ${state._getGLType(this.type)} ${this.associatedVariableName};\\n`;\r\n if (define) {\r\n state._uniformDeclaration += `#endif\\n`;\r\n }\r\n\r\n // well known\r\n const hints = state.sharedData.hints;\r\n if (this._systemValue !== null && this._systemValue !== undefined) {\r\n switch (this._systemValue) {\r\n case NodeMaterialSystemValues.WorldView:\r\n hints.needWorldViewMatrix = true;\r\n break;\r\n case NodeMaterialSystemValues.WorldViewProjection:\r\n hints.needWorldViewProjectionMatrix = true;\r\n break;\r\n }\r\n } else {\r\n if (this._animationType !== AnimatedInputBlockTypes.None) {\r\n state.sharedData.animatedInputs.push(this);\r\n }\r\n }\r\n\r\n return;\r\n }\r\n\r\n // Attribute\r\n if (this.isAttribute) {\r\n this.associatedVariableName = remapAttributeName[this.name] ?? this.name;\r\n\r\n if (this.target === NodeMaterialBlockTargets.Vertex && state._vertexState) {\r\n // Attribute for fragment need to be carried over by varyings\r\n if (attributeInFragmentOnly[this.name]) {\r\n if (attributeAsUniform[this.name]) {\r\n state._emitUniformFromString(this.associatedVariableName, state._getGLType(this.type), define);\r\n } else {\r\n state._emitVaryingFromString(this.associatedVariableName, state._getGLType(this.type), define);\r\n }\r\n } else {\r\n this._emit(state._vertexState, define);\r\n }\r\n return;\r\n }\r\n\r\n if (state.attributes.indexOf(this.associatedVariableName) !== -1) {\r\n return;\r\n }\r\n\r\n state.attributes.push(this.associatedVariableName);\r\n\r\n if (attributeInFragmentOnly[this.name]) {\r\n if (attributeAsUniform[this.name]) {\r\n state._emitUniformFromString(this.associatedVariableName, state._getGLType(this.type), define);\r\n } else {\r\n state._emitVaryingFromString(this.associatedVariableName, state._getGLType(this.type), define);\r\n }\r\n } else {\r\n if (define) {\r\n state._attributeDeclaration += this._emitDefine(define);\r\n }\r\n state._attributeDeclaration += `attribute ${state._getGLType(this.type)} ${this.associatedVariableName};\\n`;\r\n if (define) {\r\n state._attributeDeclaration += `#endif\\n`;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _transmitWorld(effect: Effect, world: Matrix, worldView: Matrix, worldViewProjection: Matrix) {\r\n if (!this._systemValue) {\r\n return;\r\n }\r\n\r\n const variableName = this.associatedVariableName;\r\n switch (this._systemValue) {\r\n case NodeMaterialSystemValues.World:\r\n effect.setMatrix(variableName, world);\r\n break;\r\n case NodeMaterialSystemValues.WorldView:\r\n effect.setMatrix(variableName, worldView);\r\n break;\r\n case NodeMaterialSystemValues.WorldViewProjection:\r\n effect.setMatrix(variableName, worldViewProjection);\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _transmit(effect: Effect, scene: Scene, material: NodeMaterial) {\r\n if (this.isAttribute) {\r\n return;\r\n }\r\n\r\n const variableName = this.associatedVariableName;\r\n if (this._systemValue) {\r\n switch (this._systemValue) {\r\n case NodeMaterialSystemValues.World:\r\n case NodeMaterialSystemValues.WorldView:\r\n case NodeMaterialSystemValues.WorldViewProjection:\r\n return;\r\n case NodeMaterialSystemValues.View:\r\n effect.setMatrix(variableName, scene.getViewMatrix());\r\n break;\r\n case NodeMaterialSystemValues.Projection:\r\n effect.setMatrix(variableName, scene.getProjectionMatrix());\r\n break;\r\n case NodeMaterialSystemValues.ViewProjection:\r\n effect.setMatrix(variableName, scene.getTransformMatrix());\r\n break;\r\n case NodeMaterialSystemValues.CameraPosition:\r\n scene.bindEyePosition(effect, variableName, true);\r\n break;\r\n case NodeMaterialSystemValues.FogColor:\r\n effect.setColor3(variableName, scene.fogColor);\r\n break;\r\n case NodeMaterialSystemValues.DeltaTime:\r\n effect.setFloat(variableName, scene.deltaTime / 1000.0);\r\n break;\r\n case NodeMaterialSystemValues.CameraParameters:\r\n if (scene.activeCamera) {\r\n effect.setFloat4(\r\n variableName,\r\n scene.getEngine().hasOriginBottomLeft ? -1 : 1,\r\n scene.activeCamera.minZ,\r\n scene.activeCamera.maxZ,\r\n 1 / scene.activeCamera.maxZ\r\n );\r\n }\r\n break;\r\n case NodeMaterialSystemValues.MaterialAlpha:\r\n effect.setFloat(variableName, material.alpha);\r\n break;\r\n }\r\n return;\r\n }\r\n\r\n const value = this._valueCallback ? this._valueCallback() : this._storedValue;\r\n\r\n if (value === null) {\r\n return;\r\n }\r\n\r\n switch (this.type) {\r\n case NodeMaterialBlockConnectionPointTypes.Float:\r\n effect.setFloat(variableName, value);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Int:\r\n effect.setInt(variableName, value);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n TmpColors.Color3[0].set(this.value.r, this.value.g, this.value.b);\r\n if (this.convertToGammaSpace) {\r\n TmpColors.Color3[0].toGammaSpaceToRef(TmpColors.Color3[0], scene.getEngine().useExactSrgbConversions);\r\n }\r\n if (this.convertToLinearSpace) {\r\n TmpColors.Color3[0].toLinearSpaceToRef(TmpColors.Color3[0], scene.getEngine().useExactSrgbConversions);\r\n }\r\n effect.setColor3(variableName, TmpColors.Color3[0]);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Color4:\r\n TmpColors.Color4[0].set(this.value.r, this.value.g, this.value.b, this.value.a);\r\n if (this.convertToGammaSpace) {\r\n TmpColors.Color4[0].toGammaSpaceToRef(TmpColors.Color4[0], scene.getEngine().useExactSrgbConversions);\r\n }\r\n if (this.convertToLinearSpace) {\r\n TmpColors.Color4[0].toLinearSpaceToRef(TmpColors.Color4[0], scene.getEngine().useExactSrgbConversions);\r\n }\r\n effect.setDirectColor4(variableName, TmpColors.Color4[0]);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n effect.setVector2(variableName, value);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n effect.setVector3(variableName, value);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector4:\r\n effect.setVector4(variableName, value);\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Matrix:\r\n effect.setMatrix(variableName, value);\r\n break;\r\n }\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n if (this.isUniform || this.isSystemValue) {\r\n state.sharedData.inputBlocks.push(this);\r\n }\r\n\r\n this._emit(state);\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const variableName = this._codeVariableName;\r\n\r\n if (this.isAttribute) {\r\n return super._dumpPropertiesCode() + `${variableName}.setAsAttribute(\"${this.name}\");\\n`;\r\n }\r\n if (this.isSystemValue) {\r\n return super._dumpPropertiesCode() + `${variableName}.setAsSystemValue(BABYLON.NodeMaterialSystemValues.${NodeMaterialSystemValues[this._systemValue!]});\\n`;\r\n }\r\n if (this.isUniform) {\r\n const codes: string[] = [];\r\n\r\n let valueString = \"\";\r\n\r\n switch (this.type) {\r\n case NodeMaterialBlockConnectionPointTypes.Float:\r\n valueString = `${this.value}`;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector2:\r\n valueString = `new BABYLON.Vector2(${this.value.x}, ${this.value.y})`;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector3:\r\n valueString = `new BABYLON.Vector3(${this.value.x}, ${this.value.y}, ${this.value.z})`;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Vector4:\r\n valueString = `new BABYLON.Vector4(${this.value.x}, ${this.value.y}, ${this.value.z}, ${this.value.w})`;\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Color3:\r\n valueString = `new BABYLON.Color3(${this.value.r}, ${this.value.g}, ${this.value.b})`;\r\n if (this.convertToGammaSpace) {\r\n valueString += \".toGammaSpace()\";\r\n }\r\n if (this.convertToLinearSpace) {\r\n valueString += \".toLinearSpace()\";\r\n }\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Color4:\r\n valueString = `new BABYLON.Color4(${this.value.r}, ${this.value.g}, ${this.value.b}, ${this.value.a})`;\r\n if (this.convertToGammaSpace) {\r\n valueString += \".toGammaSpace()\";\r\n }\r\n if (this.convertToLinearSpace) {\r\n valueString += \".toLinearSpace()\";\r\n }\r\n break;\r\n case NodeMaterialBlockConnectionPointTypes.Matrix:\r\n valueString = `BABYLON.Matrix.FromArray([${(this.value as Matrix).m}])`;\r\n break;\r\n }\r\n\r\n // Common Property \"Value\"\r\n codes.push(`${variableName}.value = ${valueString}`);\r\n\r\n // Float-Value-Specific Properties\r\n if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {\r\n codes.push(\r\n `${variableName}.min = ${this.min}`,\r\n `${variableName}.max = ${this.max}`,\r\n `${variableName}.isBoolean = ${this.isBoolean}`,\r\n `${variableName}.matrixMode = ${this.matrixMode}`,\r\n `${variableName}.animationType = BABYLON.AnimatedInputBlockTypes.${AnimatedInputBlockTypes[this.animationType]}`\r\n );\r\n }\r\n\r\n // Common Property \"Type\"\r\n codes.push(`${variableName}.isConstant = ${this.isConstant}`);\r\n\r\n codes.push(\"\");\r\n\r\n return super._dumpPropertiesCode() + codes.join(\";\\n\");\r\n }\r\n return super._dumpPropertiesCode();\r\n }\r\n\r\n public dispose() {\r\n this.onValueChangedObservable.clear();\r\n\r\n super.dispose();\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.type = this.type;\r\n serializationObject.mode = this._mode;\r\n serializationObject.systemValue = this._systemValue;\r\n serializationObject.animationType = this._animationType;\r\n serializationObject.min = this.min;\r\n serializationObject.max = this.max;\r\n serializationObject.isBoolean = this.isBoolean;\r\n serializationObject.matrixMode = this.matrixMode;\r\n serializationObject.isConstant = this.isConstant;\r\n serializationObject.groupInInspector = this.groupInInspector;\r\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\r\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\r\n\r\n if (this._storedValue != null && this._mode === NodeMaterialBlockConnectionPointMode.Uniform) {\r\n if (this._storedValue.asArray) {\r\n serializationObject.valueType = \"BABYLON.\" + this._storedValue.getClassName();\r\n serializationObject.value = this._storedValue.asArray();\r\n } else {\r\n serializationObject.valueType = \"number\";\r\n serializationObject.value = this._storedValue;\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n this._mode = serializationObject.mode;\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this._type = serializationObject.type;\r\n\r\n this._systemValue = serializationObject.systemValue || serializationObject.wellKnownValue;\r\n this._animationType = serializationObject.animationType;\r\n this.min = serializationObject.min || 0;\r\n this.max = serializationObject.max || 0;\r\n this.isBoolean = !!serializationObject.isBoolean;\r\n this.matrixMode = serializationObject.matrixMode || 0;\r\n this.isConstant = !!serializationObject.isConstant;\r\n this.groupInInspector = serializationObject.groupInInspector || \"\";\r\n this.convertToGammaSpace = !!serializationObject.convertToGammaSpace;\r\n this.convertToLinearSpace = !!serializationObject.convertToLinearSpace;\r\n\r\n // Tangents back compat\r\n if (\r\n serializationObject.name === \"tangent\" &&\r\n serializationObject.mode === NodeMaterialBlockConnectionPointMode.Attribute &&\r\n serializationObject.type === NodeMaterialBlockConnectionPointTypes.Vector3\r\n ) {\r\n this._type = NodeMaterialBlockConnectionPointTypes.Vector4;\r\n }\r\n\r\n if (!serializationObject.valueType) {\r\n return;\r\n }\r\n\r\n if (serializationObject.valueType === \"number\") {\r\n this._storedValue = serializationObject.value;\r\n } else {\r\n const valueType = GetClass(serializationObject.valueType);\r\n\r\n if (valueType) {\r\n this._storedValue = valueType.FromArray(serializationObject.value);\r\n }\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.InputBlock\", InputBlock);\r\n","import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport type { AbstractMesh } from \"../../../../Meshes/abstractMesh\";\r\nimport type { NodeMaterialDefines } from \"../../nodeMaterial\";\r\nimport type { BaseTexture } from \"../../../Textures/baseTexture\";\r\nimport type { Nullable } from \"../../../../types\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { Texture } from \"../../../Textures/texture\";\r\nimport type { Scene } from \"../../../../scene\";\r\nimport type { InputBlock } from \"../Input/inputBlock\";\r\n\r\nimport type { NodeMaterial } from \"../../nodeMaterial\";\r\n\r\n/**\r\n * Base block used as input for post process\r\n */\r\nexport class CurrentScreenBlock extends NodeMaterialBlock {\r\n private _samplerName = \"textureSampler\";\r\n private _linearDefineName: string;\r\n private _gammaDefineName: string;\r\n private _mainUVName: string;\r\n private _tempTextureRead: string;\r\n\r\n /**\r\n * Gets or sets the texture associated with the node\r\n */\r\n public texture: Nullable;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if content needs to be converted to gamma space\r\n */\r\n public convertToGammaSpace = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if content needs to be converted to linear space\r\n */\r\n public convertToLinearSpace = false;\r\n\r\n /**\r\n * Create a new CurrentScreenBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.VertexAndFragment);\r\n\r\n this._isUnique = false;\r\n\r\n this.registerInput(\"uv\", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);\r\n\r\n this.registerOutput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"rgb\", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"r\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"g\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"b\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"a\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n\r\n this._inputs[0].addExcludedConnectionPointFromAllowedTypes(\r\n NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4\r\n );\r\n\r\n this._inputs[0]._prioritizeVertex = false;\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"CurrentScreenBlock\";\r\n }\r\n\r\n /**\r\n * Gets the uv input component\r\n */\r\n public get uv(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgba output component\r\n */\r\n public get rgba(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgb output component\r\n */\r\n public get rgb(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the r output component\r\n */\r\n public get r(): NodeMaterialConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n\r\n /**\r\n * Gets the g output component\r\n */\r\n public get g(): NodeMaterialConnectionPoint {\r\n return this._outputs[3];\r\n }\r\n\r\n /**\r\n * Gets the b output component\r\n */\r\n public get b(): NodeMaterialConnectionPoint {\r\n return this._outputs[4];\r\n }\r\n\r\n /**\r\n * Gets the a output component\r\n */\r\n public get a(): NodeMaterialConnectionPoint {\r\n return this._outputs[5];\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"textureSampler\");\r\n }\r\n\r\n public get target() {\r\n if (!this.uv.isConnected) {\r\n return NodeMaterialBlockTargets.VertexAndFragment;\r\n }\r\n\r\n if (this.uv.sourceBlock!.isInput) {\r\n return NodeMaterialBlockTargets.VertexAndFragment;\r\n }\r\n\r\n return NodeMaterialBlockTargets.Fragment;\r\n }\r\n\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {\r\n defines.setValue(this._linearDefineName, this.convertToGammaSpace, true);\r\n defines.setValue(this._gammaDefineName, this.convertToLinearSpace, true);\r\n }\r\n\r\n public isReady() {\r\n if (this.texture && !this.texture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _injectVertexCode(state: NodeMaterialBuildState) {\r\n const uvInput = this.uv;\r\n\r\n if (uvInput.connectedPoint!.ownerBlock.isInput) {\r\n const uvInputOwnerBlock = uvInput.connectedPoint!.ownerBlock as InputBlock;\r\n\r\n if (!uvInputOwnerBlock.isAttribute) {\r\n state._emitUniformFromString(uvInput.associatedVariableName, \"vec2\");\r\n }\r\n }\r\n\r\n this._mainUVName = \"vMain\" + uvInput.associatedVariableName;\r\n\r\n state._emitVaryingFromString(this._mainUVName, \"vec2\");\r\n\r\n state.compilationString += `${this._mainUVName} = ${uvInput.associatedVariableName}.xy;\\n`;\r\n\r\n if (!this._outputs.some((o) => o.isConnectedInVertexShader)) {\r\n return;\r\n }\r\n\r\n this._writeTextureRead(state, true);\r\n\r\n for (const output of this._outputs) {\r\n if (output.hasEndpoints) {\r\n this._writeOutput(state, output, output.name, true);\r\n }\r\n }\r\n }\r\n\r\n private _writeTextureRead(state: NodeMaterialBuildState, vertexMode = false) {\r\n const uvInput = this.uv;\r\n\r\n if (vertexMode) {\r\n if (state.target === NodeMaterialBlockTargets.Fragment) {\r\n return;\r\n }\r\n\r\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${uvInput.associatedVariableName});\\n`;\r\n return;\r\n }\r\n\r\n if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\r\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${uvInput.associatedVariableName});\\n`;\r\n return;\r\n }\r\n\r\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${this._mainUVName});\\n`;\r\n }\r\n\r\n private _writeOutput(state: NodeMaterialBuildState, output: NodeMaterialConnectionPoint, swizzle: string, vertexMode = false) {\r\n if (vertexMode) {\r\n if (state.target === NodeMaterialBlockTargets.Fragment) {\r\n return;\r\n }\r\n\r\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\r\n\r\n return;\r\n }\r\n\r\n if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {\r\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\r\n return;\r\n }\r\n\r\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\r\n\r\n state.compilationString += `#ifdef ${this._linearDefineName}\\n`;\r\n state.compilationString += `${output.associatedVariableName} = toGammaSpace(${output.associatedVariableName});\\n`;\r\n state.compilationString += `#endif\\n`;\r\n\r\n state.compilationString += `#ifdef ${this._gammaDefineName}\\n`;\r\n state.compilationString += `${output.associatedVariableName} = toLinearSpace(${output.associatedVariableName});\\n`;\r\n state.compilationString += `#endif\\n`;\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n this._tempTextureRead = state._getFreeVariableName(\"tempTextureRead\");\r\n\r\n if (state.sharedData.blockingBlocks.indexOf(this) < 0) {\r\n state.sharedData.blockingBlocks.push(this);\r\n }\r\n if (state.sharedData.textureBlocks.indexOf(this) < 0) {\r\n state.sharedData.textureBlocks.push(this);\r\n }\r\n if (state.sharedData.blocksWithDefines.indexOf(this) < 0) {\r\n state.sharedData.blocksWithDefines.push(this);\r\n }\r\n\r\n if (state.target !== NodeMaterialBlockTargets.Fragment) {\r\n // Vertex\r\n state._emit2DSampler(this._samplerName);\r\n this._injectVertexCode(state);\r\n return;\r\n }\r\n\r\n // Fragment\r\n if (!this._outputs.some((o) => o.isConnectedInFragmentShader)) {\r\n return;\r\n }\r\n\r\n state._emit2DSampler(this._samplerName);\r\n\r\n this._linearDefineName = state._getFreeDefineName(\"ISLINEAR\");\r\n this._gammaDefineName = state._getFreeDefineName(\"ISGAMMA\");\r\n\r\n const comments = `//${this.name}`;\r\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\r\n\r\n this._writeTextureRead(state);\r\n\r\n for (const output of this._outputs) {\r\n if (output.hasEndpoints) {\r\n this._writeOutput(state, output, output.name);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\r\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\r\n if (this.texture && !this.texture.isRenderTarget) {\r\n serializationObject.texture = this.texture.serialize();\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.convertToGammaSpace = serializationObject.convertToGammaSpace;\r\n this.convertToLinearSpace = !!serializationObject.convertToLinearSpace;\r\n\r\n if (serializationObject.texture) {\r\n rootUrl = serializationObject.texture.url.indexOf(\"data:\") === 0 ? \"\" : rootUrl;\r\n this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl) as Texture;\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.CurrentScreenBlock\", CurrentScreenBlock);\r\n","import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport type { AbstractMesh } from \"../../../../Meshes/abstractMesh\";\r\nimport type { NodeMaterialDefines } from \"../../nodeMaterial\";\r\nimport { InputBlock } from \"../Input/inputBlock\";\r\nimport type { BaseTexture } from \"../../../Textures/baseTexture\";\r\nimport type { Nullable } from \"../../../../types\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { Texture } from \"../../../Textures/texture\";\r\nimport type { Scene } from \"../../../../scene\";\r\n\r\nimport type { NodeMaterial } from \"../../nodeMaterial\";\r\n\r\n/**\r\n * Base block used for the particle texture\r\n */\r\nexport class ParticleTextureBlock extends NodeMaterialBlock {\r\n private _samplerName = \"diffuseSampler\";\r\n private _linearDefineName: string;\r\n private _gammaDefineName: string;\r\n private _tempTextureRead: string;\r\n\r\n /**\r\n * Gets or sets the texture associated with the node\r\n */\r\n public texture: Nullable;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if content needs to be converted to gamma space\r\n */\r\n public convertToGammaSpace = false;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if content needs to be converted to linear space\r\n */\r\n public convertToLinearSpace = false;\r\n\r\n /**\r\n * Create a new ParticleTextureBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Fragment);\r\n\r\n this._isUnique = false;\r\n\r\n this.registerInput(\"uv\", NodeMaterialBlockConnectionPointTypes.AutoDetect, false, NodeMaterialBlockTargets.VertexAndFragment);\r\n\r\n this.registerOutput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"rgb\", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"r\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"g\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"b\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n this.registerOutput(\"a\", NodeMaterialBlockConnectionPointTypes.Float, NodeMaterialBlockTargets.Neutral);\r\n\r\n this._inputs[0].addExcludedConnectionPointFromAllowedTypes(\r\n NodeMaterialBlockConnectionPointTypes.Vector2 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4\r\n );\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"ParticleTextureBlock\";\r\n }\r\n\r\n /**\r\n * Gets the uv input component\r\n */\r\n public get uv(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgba output component\r\n */\r\n public get rgba(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgb output component\r\n */\r\n public get rgb(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the r output component\r\n */\r\n public get r(): NodeMaterialConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n\r\n /**\r\n * Gets the g output component\r\n */\r\n public get g(): NodeMaterialConnectionPoint {\r\n return this._outputs[3];\r\n }\r\n\r\n /**\r\n * Gets the b output component\r\n */\r\n public get b(): NodeMaterialConnectionPoint {\r\n return this._outputs[4];\r\n }\r\n\r\n /**\r\n * Gets the a output component\r\n */\r\n public get a(): NodeMaterialConnectionPoint {\r\n return this._outputs[5];\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"diffuseSampler\");\r\n }\r\n\r\n public autoConfigure(material: NodeMaterial) {\r\n if (!this.uv.isConnected) {\r\n let uvInput = material.getInputBlockByPredicate((b) => b.isAttribute && b.name === \"particle_uv\");\r\n\r\n if (!uvInput) {\r\n uvInput = new InputBlock(\"uv\");\r\n uvInput.setAsAttribute(\"particle_uv\");\r\n }\r\n uvInput.output.connectTo(this.uv);\r\n }\r\n }\r\n\r\n public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {\r\n defines.setValue(this._linearDefineName, this.convertToGammaSpace, true);\r\n defines.setValue(this._gammaDefineName, this.convertToLinearSpace, true);\r\n }\r\n\r\n public isReady() {\r\n if (this.texture && !this.texture.isReadyOrNotBlocking()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _writeOutput(state: NodeMaterialBuildState, output: NodeMaterialConnectionPoint, swizzle: string) {\r\n state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\\n`;\r\n\r\n state.compilationString += `#ifdef ${this._linearDefineName}\\n`;\r\n state.compilationString += `${output.associatedVariableName} = toGammaSpace(${output.associatedVariableName});\\n`;\r\n state.compilationString += `#endif\\n`;\r\n\r\n state.compilationString += `#ifdef ${this._gammaDefineName}\\n`;\r\n state.compilationString += `${output.associatedVariableName} = toLinearSpace(${output.associatedVariableName});\\n`;\r\n state.compilationString += `#endif\\n`;\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n if (state.target === NodeMaterialBlockTargets.Vertex) {\r\n return;\r\n }\r\n\r\n this._tempTextureRead = state._getFreeVariableName(\"tempTextureRead\");\r\n\r\n state._emit2DSampler(this._samplerName);\r\n\r\n state.sharedData.blockingBlocks.push(this);\r\n state.sharedData.textureBlocks.push(this);\r\n state.sharedData.blocksWithDefines.push(this);\r\n\r\n this._linearDefineName = state._getFreeDefineName(\"ISLINEAR\");\r\n this._gammaDefineName = state._getFreeDefineName(\"ISGAMMA\");\r\n\r\n const comments = `//${this.name}`;\r\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\r\n\r\n state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${this.uv.associatedVariableName});\\n`;\r\n\r\n for (const output of this._outputs) {\r\n if (output.hasEndpoints) {\r\n this._writeOutput(state, output, output.name);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.convertToGammaSpace = this.convertToGammaSpace;\r\n serializationObject.convertToLinearSpace = this.convertToLinearSpace;\r\n if (this.texture && !this.texture.isRenderTarget) {\r\n serializationObject.texture = this.texture.serialize();\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.convertToGammaSpace = serializationObject.convertToGammaSpace;\r\n this.convertToLinearSpace = !!serializationObject.convertToLinearSpace;\r\n\r\n if (serializationObject.texture) {\r\n rootUrl = serializationObject.texture.url.indexOf(\"data:\") === 0 ? \"\" : rootUrl;\r\n this.texture = Texture.Parse(serializationObject.texture, scene, rootUrl) as Texture;\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ParticleTextureBlock\", ParticleTextureBlock);\r\n","import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\n\r\n/**\r\n * Block used for the particle ramp gradient section\r\n */\r\nexport class ParticleRampGradientBlock extends NodeMaterialBlock {\r\n /**\r\n * Create a new ParticleRampGradientBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Fragment);\r\n\r\n this._isUnique = true;\r\n\r\n this.registerInput(\"color\", NodeMaterialBlockConnectionPointTypes.Color4, false, NodeMaterialBlockTargets.Fragment);\r\n\r\n this.registerOutput(\"rampColor\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Fragment);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"ParticleRampGradientBlock\";\r\n }\r\n\r\n /**\r\n * Gets the color input component\r\n */\r\n public get color(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rampColor output component\r\n */\r\n public get rampColor(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"remapRanges\");\r\n state._excludeVariableName(\"rampSampler\");\r\n state._excludeVariableName(\"baseColor\");\r\n state._excludeVariableName(\"alpha\");\r\n state._excludeVariableName(\"remappedColorIndex\");\r\n state._excludeVariableName(\"rampColor\");\r\n state._excludeVariableName(\"finalAlpha\");\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n if (state.target === NodeMaterialBlockTargets.Vertex) {\r\n return;\r\n }\r\n\r\n state._emit2DSampler(\"rampSampler\");\r\n state._emitVaryingFromString(\"remapRanges\", \"vec4\", \"RAMPGRADIENT\");\r\n\r\n state.compilationString += `\r\n #ifdef RAMPGRADIENT\r\n vec4 baseColor = ${this.color.associatedVariableName};\r\n float alpha = ${this.color.associatedVariableName}.a;\r\n\r\n float remappedColorIndex = clamp((alpha - remapRanges.x) / remapRanges.y, 0.0, 1.0);\r\n\r\n vec4 rampColor = texture2D(rampSampler, vec2(1.0 - remappedColorIndex, 0.));\r\n baseColor.rgb *= rampColor.rgb;\r\n\r\n // Remapped alpha\r\n float finalAlpha = baseColor.a;\r\n baseColor.a = clamp((alpha * rampColor.a - remapRanges.z) / remapRanges.w, 0.0, 1.0);\r\n\r\n ${this._declareOutput(this.rampColor, state)} = baseColor;\r\n #else\r\n ${this._declareOutput(this.rampColor, state)} = ${this.color.associatedVariableName};\r\n #endif\r\n `;\r\n\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ParticleRampGradientBlock\", ParticleRampGradientBlock);\r\n","import { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\n\r\n/**\r\n * Block used for the particle blend multiply section\r\n */\r\nexport class ParticleBlendMultiplyBlock extends NodeMaterialBlock {\r\n /**\r\n * Create a new ParticleBlendMultiplyBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Fragment);\r\n\r\n this._isUnique = true;\r\n\r\n this.registerInput(\"color\", NodeMaterialBlockConnectionPointTypes.Color4, false, NodeMaterialBlockTargets.Fragment);\r\n this.registerInput(\"alphaTexture\", NodeMaterialBlockConnectionPointTypes.Float, false, NodeMaterialBlockTargets.Fragment);\r\n this.registerInput(\"alphaColor\", NodeMaterialBlockConnectionPointTypes.Float, false, NodeMaterialBlockTargets.Fragment);\r\n\r\n this.registerOutput(\"blendColor\", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Fragment);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"ParticleBlendMultiplyBlock\";\r\n }\r\n\r\n /**\r\n * Gets the color input component\r\n */\r\n public get color(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the alphaTexture input component\r\n */\r\n public get alphaTexture(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the alphaColor input component\r\n */\r\n public get alphaColor(): NodeMaterialConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the blendColor output component\r\n */\r\n public get blendColor(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"sourceAlpha\");\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n if (state.target === NodeMaterialBlockTargets.Vertex) {\r\n return;\r\n }\r\n\r\n state.compilationString += `\r\n #ifdef BLENDMULTIPLYMODE\r\n ${this._declareOutput(this.blendColor, state)};\r\n float sourceAlpha = ${this.alphaColor.associatedVariableName} * ${this.alphaTexture.associatedVariableName};\r\n ${this.blendColor.associatedVariableName}.rgb = ${this.color.associatedVariableName}.rgb * sourceAlpha + vec3(1.0) * (1.0 - sourceAlpha);\r\n ${this.blendColor.associatedVariableName}.a = ${this.color.associatedVariableName}.a;\r\n #else\r\n ${this._declareOutput(this.blendColor, state)} = ${this.color.associatedVariableName};\r\n #endif\r\n `;\r\n\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ParticleBlendMultiplyBlock\", ParticleBlendMultiplyBlock);\r\n","import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport type { Scene } from \"../../../scene\";\r\n\r\n/**\r\n * Block used to create a Vector2/3/4 out of individual inputs (one for each component)\r\n */\r\nexport class VectorMergerBlock extends NodeMaterialBlock {\r\n /**\r\n * Gets or sets the swizzle for x (meaning which component to affect to the output.x)\r\n */\r\n public xSwizzle: \"x\" | \"y\" | \"z\" | \"w\" = \"x\";\r\n /**\r\n * Gets or sets the swizzle for y (meaning which component to affect to the output.y)\r\n */\r\n public ySwizzle: \"x\" | \"y\" | \"z\" | \"w\" = \"y\";\r\n /**\r\n * Gets or sets the swizzle for z (meaning which component to affect to the output.z)\r\n */\r\n public zSwizzle: \"x\" | \"y\" | \"z\" | \"w\" = \"z\";\r\n /**\r\n * Gets or sets the swizzle for w (meaning which component to affect to the output.w)\r\n */\r\n public wSwizzle: \"x\" | \"y\" | \"z\" | \"w\" = \"w\";\r\n\r\n /**\r\n * Create a new VectorMergerBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"xyzw \", NodeMaterialBlockConnectionPointTypes.Vector4, true);\r\n this.registerInput(\"xyz \", NodeMaterialBlockConnectionPointTypes.Vector3, true);\r\n this.registerInput(\"xy \", NodeMaterialBlockConnectionPointTypes.Vector2, true);\r\n this.registerInput(\"zw \", NodeMaterialBlockConnectionPointTypes.Vector2, true);\r\n this.registerInput(\"x\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n this.registerInput(\"y\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n this.registerInput(\"z\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n this.registerInput(\"w\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n\r\n this.registerOutput(\"xyzw\", NodeMaterialBlockConnectionPointTypes.Vector4);\r\n this.registerOutput(\"xyz\", NodeMaterialBlockConnectionPointTypes.Vector3);\r\n this.registerOutput(\"xy\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n this.registerOutput(\"zw\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"VectorMergerBlock\";\r\n }\r\n\r\n /**\r\n * Gets the xyzw component (input)\r\n */\r\n public get xyzwIn(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the xyz component (input)\r\n */\r\n public get xyzIn(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the xy component (input)\r\n */\r\n public get xyIn(): NodeMaterialConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the zw component (input)\r\n */\r\n public get zwIn(): NodeMaterialConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the x component (input)\r\n */\r\n public get x(): NodeMaterialConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the y component (input)\r\n */\r\n public get y(): NodeMaterialConnectionPoint {\r\n return this._inputs[5];\r\n }\r\n\r\n /**\r\n * Gets the z component (input)\r\n */\r\n public get z(): NodeMaterialConnectionPoint {\r\n return this._inputs[6];\r\n }\r\n\r\n /**\r\n * Gets the w component (input)\r\n */\r\n public get w(): NodeMaterialConnectionPoint {\r\n return this._inputs[7];\r\n }\r\n\r\n /**\r\n * Gets the xyzw component (output)\r\n */\r\n public get xyzw(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the xyz component (output)\r\n */\r\n public get xyzOut(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the xy component (output)\r\n */\r\n public get xyOut(): NodeMaterialConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n\r\n /**\r\n * Gets the zw component (output)\r\n */\r\n public get zwOut(): NodeMaterialConnectionPoint {\r\n return this._outputs[3];\r\n }\r\n\r\n /**\r\n * Gets the xy component (output)\r\n * @deprecated Please use xyOut instead.\r\n */\r\n public get xy(): NodeMaterialConnectionPoint {\r\n return this.xyOut;\r\n }\r\n\r\n /**\r\n * Gets the xyz component (output)\r\n * @deprecated Please use xyzOut instead.\r\n */\r\n public get xyz(): NodeMaterialConnectionPoint {\r\n return this.xyzOut;\r\n }\r\n\r\n protected _inputRename(name: string) {\r\n if (name === \"xyzw \") {\r\n return \"xyzwIn\";\r\n }\r\n if (name === \"xyz \") {\r\n return \"xyzIn\";\r\n }\r\n if (name === \"xy \") {\r\n return \"xyIn\";\r\n }\r\n if (name === \"zw \") {\r\n return \"zwIn\";\r\n }\r\n return name;\r\n }\r\n\r\n private _buildSwizzle(len: number) {\r\n const swizzle = this.xSwizzle + this.ySwizzle + this.zSwizzle + this.wSwizzle;\r\n\r\n return \".\" + swizzle.substr(0, len);\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const xInput = this.x;\r\n const yInput = this.y;\r\n const zInput = this.z;\r\n const wInput = this.w;\r\n const xyInput = this.xyIn;\r\n const zwInput = this.zwIn;\r\n const xyzInput = this.xyzIn;\r\n const xyzwInput = this.xyzwIn;\r\n\r\n const v4Output = this._outputs[0];\r\n const v3Output = this._outputs[1];\r\n const v2Output = this._outputs[2];\r\n const v2CompOutput = this._outputs[3];\r\n\r\n if (xyzwInput.isConnected) {\r\n if (v4Output.hasEndpoints) {\r\n state.compilationString += this._declareOutput(v4Output, state) + ` = ${xyzwInput.associatedVariableName}${this._buildSwizzle(4)};\\n`;\r\n }\r\n\r\n if (v3Output.hasEndpoints) {\r\n state.compilationString += this._declareOutput(v3Output, state) + ` = ${xyzwInput.associatedVariableName}${this._buildSwizzle(3)};\\n`;\r\n }\r\n\r\n if (v2Output.hasEndpoints) {\r\n state.compilationString += this._declareOutput(v2Output, state) + ` = ${xyzwInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\r\n }\r\n } else if (xyzInput.isConnected) {\r\n if (v4Output.hasEndpoints) {\r\n state.compilationString +=\r\n this._declareOutput(v4Output, state) +\r\n ` = vec4(${xyzInput.associatedVariableName}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(4)};\\n`;\r\n }\r\n\r\n if (v3Output.hasEndpoints) {\r\n state.compilationString += this._declareOutput(v3Output, state) + ` = ${xyzInput.associatedVariableName}${this._buildSwizzle(3)};\\n`;\r\n }\r\n\r\n if (v2Output.hasEndpoints) {\r\n state.compilationString += this._declareOutput(v2Output, state) + ` = ${xyzInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\r\n }\r\n } else if (xyInput.isConnected) {\r\n if (v4Output.hasEndpoints) {\r\n if (zwInput.isConnected) {\r\n state.compilationString +=\r\n this._declareOutput(v4Output, state) + ` = vec4(${xyInput.associatedVariableName}, ${zwInput.associatedVariableName})${this._buildSwizzle(4)};\\n`;\r\n } else {\r\n state.compilationString +=\r\n this._declareOutput(v4Output, state) +\r\n ` = vec4(${xyInput.associatedVariableName}, ${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${\r\n wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"\r\n })${this._buildSwizzle(4)};\\n`;\r\n }\r\n }\r\n\r\n if (v3Output.hasEndpoints) {\r\n state.compilationString +=\r\n this._declareOutput(v3Output, state) +\r\n ` = vec3(${xyInput.associatedVariableName}, ${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"})${this._buildSwizzle(3)};\\n`;\r\n }\r\n\r\n if (v2Output.hasEndpoints) {\r\n state.compilationString += this._declareOutput(v2Output, state) + ` = ${xyInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\r\n }\r\n\r\n if (v2CompOutput.hasEndpoints) {\r\n if (zwInput.isConnected) {\r\n state.compilationString += this._declareOutput(v2CompOutput, state) + ` = ${zwInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\r\n } else {\r\n state.compilationString +=\r\n this._declareOutput(v2CompOutput, state) +\r\n ` = vec2(${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(\r\n 2\r\n )};\\n`;\r\n }\r\n }\r\n } else {\r\n if (v4Output.hasEndpoints) {\r\n if (zwInput.isConnected) {\r\n state.compilationString +=\r\n this._declareOutput(v4Output, state) +\r\n ` = vec4(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"}, ${\r\n zwInput.associatedVariableName\r\n })${this._buildSwizzle(4)};\\n`;\r\n } else {\r\n state.compilationString +=\r\n this._declareOutput(v4Output, state) +\r\n ` = vec4(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"}, ${\r\n zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"\r\n }, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(4)};\\n`;\r\n }\r\n }\r\n\r\n if (v3Output.hasEndpoints) {\r\n state.compilationString +=\r\n this._declareOutput(v3Output, state) +\r\n ` = vec3(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"}, ${\r\n zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"\r\n })${this._buildSwizzle(3)};\\n`;\r\n }\r\n\r\n if (v2Output.hasEndpoints) {\r\n state.compilationString +=\r\n this._declareOutput(v2Output, state) +\r\n ` = vec2(${xInput.isConnected ? this._writeVariable(xInput) : \"0.0\"}, ${yInput.isConnected ? this._writeVariable(yInput) : \"0.0\"})${this._buildSwizzle(2)};\\n`;\r\n }\r\n\r\n if (v2CompOutput.hasEndpoints) {\r\n if (zwInput.isConnected) {\r\n state.compilationString += this._declareOutput(v2CompOutput, state) + ` = ${zwInput.associatedVariableName}${this._buildSwizzle(2)};\\n`;\r\n } else {\r\n state.compilationString +=\r\n this._declareOutput(v2CompOutput, state) +\r\n ` = vec2(${zInput.isConnected ? this._writeVariable(zInput) : \"0.0\"}, ${wInput.isConnected ? this._writeVariable(wInput) : \"0.0\"})${this._buildSwizzle(\r\n 2\r\n )};\\n`;\r\n }\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.xSwizzle = this.xSwizzle;\r\n serializationObject.ySwizzle = this.ySwizzle;\r\n serializationObject.zSwizzle = this.zSwizzle;\r\n serializationObject.wSwizzle = this.wSwizzle;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.xSwizzle = serializationObject.xSwizzle ?? \"x\";\r\n this.ySwizzle = serializationObject.ySwizzle ?? \"y\";\r\n this.zSwizzle = serializationObject.zSwizzle ?? \"z\";\r\n this.wSwizzle = serializationObject.wSwizzle ?? \"w\";\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n let codeString = super._dumpPropertiesCode();\r\n codeString += `${this._codeVariableName}.xSwizzle = \"${this.xSwizzle}\";\\n`;\r\n codeString += `${this._codeVariableName}.ySwizzle = \"${this.ySwizzle}\";\\n`;\r\n codeString += `${this._codeVariableName}.zSwizzle = \"${this.zSwizzle}\";\\n`;\r\n codeString += `${this._codeVariableName}.wSwizzle = \"${this.wSwizzle}\";\\n`;\r\n\r\n return codeString;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.VectorMergerBlock\", VectorMergerBlock);\r\n","import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { Vector2 } from \"../../../Maths/math.vector\";\r\nimport type { Scene } from \"../../../scene\";\r\nimport { editableInPropertyPage, PropertyTypeForEdition } from \"../../../Decorators/nodeDecorator\";\r\n/**\r\n * Block used to remap a float from a range to a new one\r\n */\r\nexport class RemapBlock extends NodeMaterialBlock {\r\n /**\r\n * Gets or sets the source range\r\n */\r\n @editableInPropertyPage(\"From\", PropertyTypeForEdition.Vector2)\r\n public sourceRange = new Vector2(-1, 1);\r\n\r\n /**\r\n * Gets or sets the target range\r\n */\r\n @editableInPropertyPage(\"To\", PropertyTypeForEdition.Vector2)\r\n public targetRange = new Vector2(0, 1);\r\n\r\n /**\r\n * Creates a new RemapBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"input\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"sourceMin\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n this.registerInput(\"sourceMax\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n this.registerInput(\"targetMin\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n this.registerInput(\"targetMax\", NodeMaterialBlockConnectionPointTypes.Float, true);\r\n\r\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"RemapBlock\";\r\n }\r\n\r\n /**\r\n * Gets the input component\r\n */\r\n public get input(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the source min input component\r\n */\r\n public get sourceMin(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the source max input component\r\n */\r\n public get sourceMax(): NodeMaterialConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the target min input component\r\n */\r\n public get targetMin(): NodeMaterialConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the target max input component\r\n */\r\n public get targetMax(): NodeMaterialConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const output = this._outputs[0];\r\n\r\n const sourceMin = this.sourceMin.isConnected ? this.sourceMin.associatedVariableName : this._writeFloat(this.sourceRange.x);\r\n const sourceMax = this.sourceMax.isConnected ? this.sourceMax.associatedVariableName : this._writeFloat(this.sourceRange.y);\r\n\r\n const targetMin = this.targetMin.isConnected ? this.targetMin.associatedVariableName : this._writeFloat(this.targetRange.x);\r\n const targetMax = this.targetMax.isConnected ? this.targetMax.associatedVariableName : this._writeFloat(this.targetRange.y);\r\n\r\n state.compilationString +=\r\n this._declareOutput(output, state) +\r\n ` = ${targetMin} + (${this._inputs[0].associatedVariableName} - ${sourceMin}) * (${targetMax} - ${targetMin}) / (${sourceMax} - ${sourceMin});\\n`;\r\n\r\n return this;\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n let codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.sourceRange = new BABYLON.Vector2(${this.sourceRange.x}, ${this.sourceRange.y});\\n`;\r\n\r\n codeString += `${this._codeVariableName}.targetRange = new BABYLON.Vector2(${this.targetRange.x}, ${this.targetRange.y});\\n`;\r\n\r\n return codeString;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.sourceRange = this.sourceRange.asArray();\r\n serializationObject.targetRange = this.targetRange.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.sourceRange = Vector2.FromArray(serializationObject.sourceRange);\r\n this.targetRange = Vector2.FromArray(serializationObject.targetRange);\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.RemapBlock\", RemapBlock);\r\n","import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\n/**\r\n * Block used to multiply 2 values\r\n */\r\nexport class MultiplyBlock extends NodeMaterialBlock {\r\n /**\r\n * Creates a new MultiplyBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"left\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"right\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\r\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._linkConnectionTypes(0, 1);\r\n\r\n this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);\r\n this._inputs[1].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"MultiplyBlock\";\r\n }\r\n\r\n /**\r\n * Gets the left operand input component\r\n */\r\n public get left(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the right operand input component\r\n */\r\n public get right(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const output = this._outputs[0];\r\n\r\n state.compilationString += this._declareOutput(output, state) + ` = ${this.left.associatedVariableName} * ${this.right.associatedVariableName};\\n`;\r\n\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.MultiplyBlock\", MultiplyBlock);\r\n","/**\r\n * Enum used to define the material modes\r\n */\r\nexport enum NodeMaterialModes {\r\n /** Regular material */\r\n Material = 0,\r\n /** For post process */\r\n PostProcess = 1,\r\n /** For particle system */\r\n Particle = 2,\r\n /** For procedural texture */\r\n ProceduralTexture = 3,\r\n}\r\n","import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a box.\r\n * It emits the particles randomly between 2 given directions.\r\n */\r\nexport class BoxParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction1 = new Vector3(0, 1.0, 0);\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction2 = new Vector3(0, 1.0, 0);\r\n\r\n /**\r\n * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\r\n */\r\n public minEmitBox = new Vector3(-0.5, -0.5, -0.5);\r\n /**\r\n * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\r\n */\r\n public maxEmitBox = new Vector3(0.5, 0.5, 0.5);\r\n\r\n /**\r\n * Creates a new instance BoxParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n\r\n if (isLocal) {\r\n directionToUpdate.x = randX;\r\n directionToUpdate.y = randY;\r\n directionToUpdate.z = randZ;\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randX = Scalar.RandomRange(this.minEmitBox.x, this.maxEmitBox.x);\r\n const randY = Scalar.RandomRange(this.minEmitBox.y, this.maxEmitBox.y);\r\n const randZ = Scalar.RandomRange(this.minEmitBox.z, this.maxEmitBox.z);\r\n\r\n if (isLocal) {\r\n positionToUpdate.x = randX;\r\n positionToUpdate.y = randY;\r\n positionToUpdate.z = randZ;\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): BoxParticleEmitter {\r\n const newOne = new BoxParticleEmitter();\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n uboOrEffect.setVector3(\"minEmitBox\", this.minEmitBox);\r\n uboOrEffect.setVector3(\"maxEmitBox\", this.maxEmitBox);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n ubo.addUniform(\"minEmitBox\", 3);\r\n ubo.addUniform(\"maxEmitBox\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define BOXEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"BoxParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"BoxParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n serializationObject.minEmitBox = this.minEmitBox.asArray();\r\n serializationObject.maxEmitBox = this.maxEmitBox.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n Vector3.FromArrayToRef(serializationObject.minEmitBox, 0, this.minEmitBox);\r\n Vector3.FromArrayToRef(serializationObject.maxEmitBox, 0, this.maxEmitBox);\r\n }\r\n}\r\n","import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a cone.\r\n * It emits the particles alongside the cone volume from the base to the particle.\r\n * The emission direction might be randomized.\r\n */\r\nexport class ConeParticleEmitter implements IParticleEmitterType {\r\n private _radius: number;\r\n private _angle: number;\r\n private _height: number;\r\n\r\n /**\r\n * Gets or sets a value indicating where on the radius the start position should be picked (1 = everywhere, 0 = only surface)\r\n */\r\n public radiusRange = 1;\r\n\r\n /**\r\n * Gets or sets a value indicating where on the height the start position should be picked (1 = everywhere, 0 = only surface)\r\n */\r\n public heightRange = 1;\r\n\r\n /**\r\n * Gets or sets a value indicating if all the particles should be emitted from the spawn point only (the base of the cone)\r\n */\r\n public emitFromSpawnPointOnly = false;\r\n\r\n /**\r\n * Gets or sets the radius of the emission cone\r\n */\r\n public get radius(): number {\r\n return this._radius;\r\n }\r\n\r\n public set radius(value: number) {\r\n this._radius = value;\r\n this._buildHeight();\r\n }\r\n\r\n /**\r\n * Gets or sets the angle of the emission cone\r\n */\r\n public get angle(): number {\r\n return this._angle;\r\n }\r\n\r\n public set angle(value: number) {\r\n this._angle = value;\r\n this._buildHeight();\r\n }\r\n\r\n private _buildHeight() {\r\n if (this._angle !== 0) {\r\n this._height = this._radius / Math.tan(this._angle / 2);\r\n } else {\r\n this._height = 1;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new instance ConeParticleEmitter\r\n * @param radius the radius of the emission cone (1 by default)\r\n * @param angle the cone base angle (PI by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1] (default is 0)\r\n */\r\n constructor(\r\n radius = 1,\r\n angle = Math.PI,\r\n /** defines how much to randomize the particle direction [0-1] (default is 0) */\r\n public directionRandomizer = 0\r\n ) {\r\n this.angle = angle;\r\n this.radius = radius;\r\n }\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (isLocal) {\r\n TmpVectors.Vector3[0].copyFrom(particle._localPosition!).normalize();\r\n } else {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), TmpVectors.Vector3[0]).normalize();\r\n }\r\n\r\n const randX = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randZ = Scalar.RandomRange(0, this.directionRandomizer);\r\n directionToUpdate.x = TmpVectors.Vector3[0].x + randX;\r\n directionToUpdate.y = TmpVectors.Vector3[0].y + randY;\r\n directionToUpdate.z = TmpVectors.Vector3[0].z + randZ;\r\n directionToUpdate.normalize();\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const s = Scalar.RandomRange(0, Math.PI * 2);\r\n let h: number;\r\n\r\n if (!this.emitFromSpawnPointOnly) {\r\n h = Scalar.RandomRange(0, this.heightRange);\r\n // Better distribution in a cone at normal angles.\r\n h = 1 - h * h;\r\n } else {\r\n h = 0.0001;\r\n }\r\n let radius = this._radius - Scalar.RandomRange(0, this._radius * this.radiusRange);\r\n radius = radius * h;\r\n\r\n const randX = radius * Math.sin(s);\r\n const randZ = radius * Math.cos(s);\r\n const randY = h * this._height;\r\n\r\n if (isLocal) {\r\n positionToUpdate.x = randX;\r\n positionToUpdate.y = randY;\r\n positionToUpdate.z = randZ;\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): ConeParticleEmitter {\r\n const newOne = new ConeParticleEmitter(this._radius, this._angle, this.directionRandomizer);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat2(\"radius\", this._radius, this.radiusRange);\r\n uboOrEffect.setFloat(\"coneAngle\", this._angle);\r\n uboOrEffect.setFloat2(\"height\", this._height, this.heightRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 2);\r\n ubo.addUniform(\"coneAngle\", 1);\r\n ubo.addUniform(\"height\", 2);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n let defines = \"#define CONEEMITTER\";\r\n\r\n if (this.emitFromSpawnPointOnly) {\r\n defines += \"\\n#define CONEEMITTERSPAWNPOINT\";\r\n }\r\n\r\n return defines;\r\n }\r\n\r\n /**\r\n * Returns the string \"ConeParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"ConeParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.radius = this._radius;\r\n serializationObject.angle = this._angle;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.heightRange = this.heightRange;\r\n serializationObject.emitFromSpawnPointOnly = this.emitFromSpawnPointOnly;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n this.radius = serializationObject.radius;\r\n this.angle = serializationObject.angle;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n\r\n this.radiusRange = serializationObject.radiusRange !== undefined ? serializationObject.radiusRange : 1;\r\n this.heightRange = serializationObject.radiusRange !== undefined ? serializationObject.heightRange : 1;\r\n this.emitFromSpawnPointOnly = serializationObject.emitFromSpawnPointOnly !== undefined ? serializationObject.emitFromSpawnPointOnly : false;\r\n }\r\n}\r\n","import type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles alongside the cylinder radius. The emission direction might be randomized.\r\n */\r\nexport class CylinderParticleEmitter implements IParticleEmitterType {\r\n private _tempVector = Vector3.Zero();\r\n\r\n /**\r\n * Creates a new instance CylinderParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * The radius of the emission cylinder.\r\n */\r\n public radius = 1,\r\n /**\r\n * The height of the emission cylinder.\r\n */\r\n public height = 1,\r\n /**\r\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\r\n ) {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n * @param inverseWorldMatrix defines the inverted world matrix to use if isLocal is false\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean, inverseWorldMatrix: Matrix): void {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);\r\n\r\n this._tempVector.normalize();\r\n\r\n Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);\r\n\r\n const randY = Scalar.RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);\r\n\r\n let angle = Math.atan2(this._tempVector.x, this._tempVector.z);\r\n angle += Scalar.RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;\r\n\r\n this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface\r\n this._tempVector.x = Math.sin(angle);\r\n this._tempVector.z = Math.cos(angle);\r\n this._tempVector.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(this._tempVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(this._tempVector.x, this._tempVector.y, this._tempVector.z, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const yPos = Scalar.RandomRange(-this.height / 2, this.height / 2);\r\n const angle = Scalar.RandomRange(0, 2 * Math.PI);\r\n\r\n // Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html\r\n const radiusDistribution = Scalar.RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);\r\n const positionRadius = Math.sqrt(radiusDistribution) * this.radius;\r\n const xPos = positionRadius * Math.cos(angle);\r\n const zPos = positionRadius * Math.sin(angle);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(xPos, yPos, zPos);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(xPos, yPos, zPos, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CylinderParticleEmitter {\r\n const newOne = new CylinderParticleEmitter(this.radius, this.directionRandomizer);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.height = this.height;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n this.radius = serializationObject.radius;\r\n this.height = serializationObject.height;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles randomly between two vectors.\r\n */\r\nexport class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {\r\n /**\r\n * Creates a new instance CylinderDirectedParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param direction1 the min limit of the emission direction (up vector by default)\r\n * @param direction2 the max limit of the emission direction (up vector by default)\r\n */\r\n constructor(\r\n radius = 1,\r\n height = 1,\r\n radiusRange = 1,\r\n /**\r\n * The min limit of the emission direction.\r\n */\r\n public direction1 = new Vector3(0, 1, 0),\r\n /**\r\n * The max limit of the emission direction.\r\n */\r\n public direction2 = new Vector3(0, 1, 0)\r\n ) {\r\n super(radius, height, radiusRange);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CylinderDirectedParticleEmitter {\r\n const newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, this.direction1, this.direction2);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CYLINDEREMITTER\\n#define DIRECTEDCYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderDirectedParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n super.parse(serializationObject);\r\n this.direction1.copyFrom(serializationObject.direction1);\r\n this.direction2.copyFrom(serializationObject.direction2);\r\n }\r\n}\r\n","import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a hemisphere.\r\n * It emits the particles alongside the hemisphere radius. The emission direction might be randomized.\r\n */\r\nexport class HemisphericParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Creates a new instance HemisphericParticleEmitter\r\n * @param radius the radius of the emission hemisphere (1 by default)\r\n * @param radiusRange the range of the emission hemisphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * The radius of the emission hemisphere.\r\n */\r\n public radius = 1,\r\n /**\r\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\r\n ) {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\r\n const randX = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randZ = Scalar.RandomRange(0, this.directionRandomizer);\r\n direction.x += randX;\r\n direction.y += randY;\r\n direction.z += randZ;\r\n direction.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(direction);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randRadius = this.radius - Scalar.RandomRange(0, this.radius * this.radiusRange);\r\n const v = Scalar.RandomRange(0, 1.0);\r\n const phi = Scalar.RandomRange(0, 2 * Math.PI);\r\n const theta = Math.acos(2 * v - 1);\r\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\r\n const randY = randRadius * Math.cos(theta);\r\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randX, Math.abs(randY), randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, Math.abs(randY), randZ, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): HemisphericParticleEmitter {\r\n const newOne = new HemisphericParticleEmitter(this.radius, this.directionRandomizer);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define HEMISPHERICEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"HemisphericParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"HemisphericParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n this.radius = serializationObject.radius;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n","import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from a point.\r\n * It emits the particles randomly between 2 given directions.\r\n */\r\nexport class PointParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction1 = new Vector3(0, 1.0, 0);\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction2 = new Vector3(0, 1.0, 0);\r\n\r\n /**\r\n * Creates a new instance PointParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(0, 0, 0);\r\n return;\r\n }\r\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): PointParticleEmitter {\r\n const newOne = new PointParticleEmitter();\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define POINTEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"PointParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"PointParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n }\r\n}\r\n","import type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a sphere.\r\n * It emits the particles alongside the sphere radius. The emission direction might be randomized.\r\n */\r\nexport class SphereParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Creates a new instance SphereParticleEmitter\r\n * @param radius the radius of the emission sphere (1 by default)\r\n * @param radiusRange the range of the emission sphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * The radius of the emission sphere.\r\n */\r\n public radius = 1,\r\n /**\r\n * The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\r\n ) {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\r\n const randX = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randZ = Scalar.RandomRange(0, this.directionRandomizer);\r\n direction.x += randX;\r\n direction.y += randY;\r\n direction.z += randZ;\r\n direction.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(direction);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randRadius = this.radius - Scalar.RandomRange(0, this.radius * this.radiusRange);\r\n const v = Scalar.RandomRange(0, 1.0);\r\n const phi = Scalar.RandomRange(0, 2 * Math.PI);\r\n const theta = Math.acos(2 * v - 1);\r\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\r\n const randY = randRadius * Math.cos(theta);\r\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): SphereParticleEmitter {\r\n const newOne = new SphereParticleEmitter(this.radius, this.directionRandomizer);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define SPHEREEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"SphereParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"SphereParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n this.radius = serializationObject.radius;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a sphere.\r\n * It emits the particles randomly between two vectors.\r\n */\r\nexport class SphereDirectedParticleEmitter extends SphereParticleEmitter {\r\n /**\r\n * Creates a new instance SphereDirectedParticleEmitter\r\n * @param radius the radius of the emission sphere (1 by default)\r\n * @param direction1 the min limit of the emission direction (up vector by default)\r\n * @param direction2 the max limit of the emission direction (up vector by default)\r\n */\r\n constructor(\r\n radius = 1,\r\n /**\r\n * The min limit of the emission direction.\r\n */\r\n public direction1 = new Vector3(0, 1, 0),\r\n /**\r\n * The max limit of the emission direction.\r\n */\r\n public direction2 = new Vector3(0, 1, 0)\r\n ) {\r\n super(radius);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): SphereDirectedParticleEmitter {\r\n const newOne = new SphereDirectedParticleEmitter(this.radius, this.direction1, this.direction2);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define SPHEREEMITTER\\n#define DIRECTEDSPHEREEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"SphereDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"SphereDirectedParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n super.parse(serializationObject);\r\n this.direction1.copyFrom(serializationObject.direction1);\r\n this.direction2.copyFrom(serializationObject.direction2);\r\n }\r\n}\r\n","import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { IndicesArray, Nullable, FloatArray } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a box.\r\n * It emits the particles randomly between 2 given directions.\r\n */\r\nexport class MeshParticleEmitter implements IParticleEmitterType {\r\n private _indices: Nullable = null;\r\n private _positions: Nullable = null;\r\n private _normals: Nullable = null;\r\n private _storedNormal = Vector3.Zero();\r\n private _mesh: Nullable = null;\r\n\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction1 = new Vector3(0, 1.0, 0);\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction2 = new Vector3(0, 1.0, 0);\r\n\r\n /**\r\n * Gets or sets a boolean indicating that particle directions must be built from mesh face normals\r\n */\r\n public useMeshNormalsForDirection = true;\r\n\r\n /** Defines the mesh to use as source */\r\n public get mesh(): Nullable {\r\n return this._mesh;\r\n }\r\n\r\n public set mesh(value: Nullable) {\r\n if (this._mesh === value) {\r\n return;\r\n }\r\n\r\n this._mesh = value;\r\n\r\n if (value) {\r\n this._indices = value.getIndices();\r\n this._positions = value.getVerticesData(VertexBuffer.PositionKind);\r\n this._normals = value.getVerticesData(VertexBuffer.NormalKind);\r\n } else {\r\n this._indices = null;\r\n this._positions = null;\r\n this._normals = null;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new instance MeshParticleEmitter\r\n * @param mesh defines the mesh to use as source\r\n */\r\n constructor(mesh: Nullable = null) {\r\n this.mesh = mesh;\r\n }\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (this.useMeshNormalsForDirection && this._normals) {\r\n Vector3.TransformNormalToRef(this._storedNormal, worldMatrix, directionToUpdate);\r\n return;\r\n }\r\n\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (!this._indices || !this._positions) {\r\n return;\r\n }\r\n\r\n const randomFaceIndex = (3 * Math.random() * (this._indices.length / 3)) | 0;\r\n const bu = Math.random();\r\n const bv = Math.random() * (1.0 - bu);\r\n const bw = 1.0 - bu - bv;\r\n\r\n const faceIndexA = this._indices[randomFaceIndex];\r\n const faceIndexB = this._indices[randomFaceIndex + 1];\r\n const faceIndexC = this._indices[randomFaceIndex + 2];\r\n const vertexA = TmpVectors.Vector3[0];\r\n const vertexB = TmpVectors.Vector3[1];\r\n const vertexC = TmpVectors.Vector3[2];\r\n const randomVertex = TmpVectors.Vector3[3];\r\n\r\n Vector3.FromArrayToRef(this._positions, faceIndexA * 3, vertexA);\r\n Vector3.FromArrayToRef(this._positions, faceIndexB * 3, vertexB);\r\n Vector3.FromArrayToRef(this._positions, faceIndexC * 3, vertexC);\r\n\r\n randomVertex.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\r\n randomVertex.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\r\n randomVertex.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randomVertex.x, randomVertex.y, randomVertex.z);\r\n } else {\r\n Vector3.TransformCoordinatesFromFloatsToRef(randomVertex.x, randomVertex.y, randomVertex.z, worldMatrix, positionToUpdate);\r\n }\r\n\r\n if (this.useMeshNormalsForDirection && this._normals) {\r\n Vector3.FromArrayToRef(this._normals, faceIndexA * 3, vertexA);\r\n Vector3.FromArrayToRef(this._normals, faceIndexB * 3, vertexB);\r\n Vector3.FromArrayToRef(this._normals, faceIndexC * 3, vertexC);\r\n\r\n this._storedNormal.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\r\n this._storedNormal.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\r\n this._storedNormal.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\r\n }\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): MeshParticleEmitter {\r\n const newOne = new MeshParticleEmitter(this.mesh);\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"\";\r\n }\r\n\r\n /**\r\n * Returns the string \"BoxParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"MeshParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n serializationObject.meshId = this.mesh?.id;\r\n serializationObject.useMeshNormalsForDirection = this.useMeshNormalsForDirection;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n * @param scene defines the hosting scene\r\n */\r\n public parse(serializationObject: any, scene: Nullable): void {\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n\r\n if (serializationObject.meshId && scene) {\r\n this.mesh = scene.getLastMeshById(serializationObject.meshId);\r\n }\r\n\r\n this.useMeshNormalsForDirection = serializationObject.useMeshNormalsForDirection;\r\n }\r\n}\r\n","/* eslint-disable import/no-internal-modules */\r\nimport type { Nullable } from \"../types\";\r\nimport { Vector2, Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ImageProcessingConfiguration } from \"../Materials/imageProcessingConfiguration\";\r\nimport { ImageProcessingConfigurationDefines } from \"../Materials/imageProcessingConfiguration\";\r\nimport type { ColorGradient, FactorGradient, Color3Gradient, IValueGradient } from \"../Misc/gradients\";\r\nimport type { IParticleEmitterType } from \"../Particles/EmitterTypes/index\";\r\nimport {\r\n BoxParticleEmitter,\r\n PointParticleEmitter,\r\n HemisphericParticleEmitter,\r\n SphereParticleEmitter,\r\n SphereDirectedParticleEmitter,\r\n CylinderParticleEmitter,\r\n CylinderDirectedParticleEmitter,\r\n ConeParticleEmitter,\r\n} from \"../Particles/EmitterTypes/index\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\n\r\nimport \"../Engines/Extensions/engine.dynamicBuffer\";\r\nimport type { IClipPlanesHolder } from \"../Misc/interfaces/iClipPlanesHolder\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport type { Animation } from \"../Animations/animation\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { ProceduralTexture } from \"../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { RawTexture } from \"../Materials/Textures/rawTexture\";\r\n\r\n/**\r\n * This represents the base class for particle system in Babylon.\r\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\r\n * Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.\r\n * @example https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro\r\n */\r\nexport class BaseParticleSystem implements IClipPlanesHolder {\r\n /**\r\n * Source color is added to the destination color without alpha affecting the result\r\n */\r\n public static BLENDMODE_ONEONE = 0;\r\n /**\r\n * Blend current color and particle color using particle’s alpha\r\n */\r\n public static BLENDMODE_STANDARD = 1;\r\n /**\r\n * Add current color and particle color multiplied by particle’s alpha\r\n */\r\n public static BLENDMODE_ADD = 2;\r\n /**\r\n * Multiply current color with particle color\r\n */\r\n public static BLENDMODE_MULTIPLY = 3;\r\n\r\n /**\r\n * Multiply current color with particle color then add current color and particle color multiplied by particle’s alpha\r\n */\r\n public static BLENDMODE_MULTIPLYADD = 4;\r\n\r\n /**\r\n * List of animations used by the particle system.\r\n */\r\n public animations: Animation[] = [];\r\n\r\n /**\r\n * Gets or sets the unique id of the particle system\r\n */\r\n public uniqueId: number;\r\n\r\n /**\r\n * The id of the Particle system.\r\n */\r\n public id: string;\r\n\r\n /**\r\n * The friendly name of the Particle system.\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Snippet ID if the particle system was created from the snippet server\r\n */\r\n public snippetId: string;\r\n\r\n /**\r\n * The rendering group used by the Particle system to chose when to render.\r\n */\r\n public renderingGroupId = 0;\r\n\r\n /**\r\n * The emitter represents the Mesh or position we are attaching the particle system to.\r\n */\r\n public emitter: Nullable = Vector3.Zero();\r\n\r\n /**\r\n * The maximum number of particles to emit per frame\r\n */\r\n public emitRate = 10;\r\n\r\n /**\r\n * If you want to launch only a few particles at once, that can be done, as well.\r\n */\r\n public manualEmitCount = -1;\r\n\r\n /**\r\n * The overall motion speed (0.01 is default update speed, faster updates = faster animation)\r\n */\r\n public updateSpeed = 0.01;\r\n\r\n /**\r\n * The amount of time the particle system is running (depends of the overall update speed).\r\n */\r\n public targetStopDuration = 0;\r\n\r\n /**\r\n * Specifies whether the particle system will be disposed once it reaches the end of the animation.\r\n */\r\n public disposeOnStop = false;\r\n\r\n /**\r\n * Minimum power of emitting particles.\r\n */\r\n public minEmitPower = 1;\r\n /**\r\n * Maximum power of emitting particles.\r\n */\r\n public maxEmitPower = 1;\r\n\r\n /**\r\n * Minimum life time of emitting particles.\r\n */\r\n public minLifeTime = 1;\r\n /**\r\n * Maximum life time of emitting particles.\r\n */\r\n public maxLifeTime = 1;\r\n\r\n /**\r\n * Minimum Size of emitting particles.\r\n */\r\n public minSize = 1;\r\n /**\r\n * Maximum Size of emitting particles.\r\n */\r\n public maxSize = 1;\r\n\r\n /**\r\n * Minimum scale of emitting particles on X axis.\r\n */\r\n public minScaleX = 1;\r\n /**\r\n * Maximum scale of emitting particles on X axis.\r\n */\r\n public maxScaleX = 1;\r\n\r\n /**\r\n * Minimum scale of emitting particles on Y axis.\r\n */\r\n public minScaleY = 1;\r\n /**\r\n * Maximum scale of emitting particles on Y axis.\r\n */\r\n public maxScaleY = 1;\r\n\r\n /**\r\n * Gets or sets the minimal initial rotation in radians.\r\n */\r\n public minInitialRotation = 0;\r\n /**\r\n * Gets or sets the maximal initial rotation in radians.\r\n */\r\n public maxInitialRotation = 0;\r\n\r\n /**\r\n * Minimum angular speed of emitting particles (Z-axis rotation for each particle).\r\n */\r\n public minAngularSpeed = 0;\r\n /**\r\n * Maximum angular speed of emitting particles (Z-axis rotation for each particle).\r\n */\r\n public maxAngularSpeed = 0;\r\n\r\n /**\r\n * The texture used to render each particle. (this can be a spritesheet)\r\n */\r\n public particleTexture: Nullable;\r\n\r\n /**\r\n * The layer mask we are rendering the particles through.\r\n */\r\n public layerMask: number = 0x0fffffff;\r\n\r\n /**\r\n * This can help using your own shader to render the particle system.\r\n * The according effect will be created\r\n */\r\n public customShader: any = null;\r\n\r\n /**\r\n * By default particle system starts as soon as they are created. This prevents the\r\n * automatic start to happen and let you decide when to start emitting particles.\r\n */\r\n public preventAutoStart: boolean = false;\r\n\r\n /** @internal */\r\n _wasDispatched = false;\r\n\r\n protected _rootUrl = \"\";\r\n private _noiseTexture: Nullable;\r\n\r\n /**\r\n * Gets or sets a texture used to add random noise to particle positions\r\n */\r\n public get noiseTexture(): Nullable {\r\n return this._noiseTexture;\r\n }\r\n\r\n public set noiseTexture(value: Nullable) {\r\n if (this._noiseTexture === value) {\r\n return;\r\n }\r\n\r\n this._noiseTexture = value;\r\n this._reset();\r\n }\r\n\r\n /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */\r\n public noiseStrength = new Vector3(10, 10, 10);\r\n\r\n /**\r\n * Callback triggered when the particle animation is ending.\r\n */\r\n public onAnimationEnd: Nullable<() => void> = null;\r\n\r\n /**\r\n * Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE or ParticleSystem.BLENDMODE_STANDARD.\r\n */\r\n public blendMode = BaseParticleSystem.BLENDMODE_ONEONE;\r\n\r\n /**\r\n * Forces the particle to write their depth information to the depth buffer. This can help preventing other draw calls\r\n * to override the particles.\r\n */\r\n public forceDepthWrite = false;\r\n\r\n /** Gets or sets a value indicating how many cycles (or frames) must be executed before first rendering (this value has to be set before starting the system). Default is 0 */\r\n public preWarmCycles = 0;\r\n\r\n /** Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1) */\r\n public preWarmStepOffset = 1;\r\n\r\n /**\r\n * If using a spritesheet (isAnimationSheetEnabled) defines the speed of the sprite loop (default is 1 meaning the animation will play once during the entire particle lifetime)\r\n */\r\n public spriteCellChangeSpeed = 1;\r\n /**\r\n * If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display\r\n */\r\n public startSpriteCellID = 0;\r\n /**\r\n * If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display\r\n */\r\n public endSpriteCellID = 0;\r\n /**\r\n * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use\r\n */\r\n public spriteCellWidth = 0;\r\n /**\r\n * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use\r\n */\r\n public spriteCellHeight = 0;\r\n /**\r\n * If using a spritesheet (isAnimationSheetEnabled), defines wether the sprite animation is looping\r\n */\r\n public spriteCellLoop = true;\r\n /**\r\n * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID\r\n */\r\n public spriteRandomStartCell = false;\r\n\r\n /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */\r\n public translationPivot = new Vector2(0, 0);\r\n\r\n /** @internal */\r\n public _isAnimationSheetEnabled: boolean;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that hosted animations (in the system.animations array) must be started when system.start() is called\r\n */\r\n public beginAnimationOnStart = false;\r\n\r\n /**\r\n * Gets or sets the frame to start the animation from when beginAnimationOnStart is true\r\n */\r\n public beginAnimationFrom = 0;\r\n\r\n /**\r\n * Gets or sets the frame to end the animation on when beginAnimationOnStart is true\r\n */\r\n public beginAnimationTo = 60;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if animations must loop when beginAnimationOnStart is true\r\n */\r\n public beginAnimationLoop = false;\r\n\r\n /**\r\n * Gets or sets a world offset applied to all particles\r\n */\r\n public worldOffset = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * Gets or sets the active clipplane 1\r\n */\r\n public clipPlane: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 2\r\n */\r\n public clipPlane2: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 3\r\n */\r\n public clipPlane3: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 4\r\n */\r\n public clipPlane4: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 5\r\n */\r\n public clipPlane5: Nullable;\r\n\r\n /**\r\n * Gets or sets the active clipplane 6\r\n */\r\n public clipPlane6: Nullable;\r\n\r\n /**\r\n * Gets or sets whether an animation sprite sheet is enabled or not on the particle system\r\n */\r\n public get isAnimationSheetEnabled(): boolean {\r\n return this._isAnimationSheetEnabled;\r\n }\r\n\r\n public set isAnimationSheetEnabled(value: boolean) {\r\n if (this._isAnimationSheetEnabled == value) {\r\n return;\r\n }\r\n\r\n this._isAnimationSheetEnabled = value;\r\n\r\n this._reset();\r\n }\r\n\r\n private _useLogarithmicDepth: boolean = false;\r\n\r\n /**\r\n * Gets or sets a boolean enabling the use of logarithmic depth buffers, which is good for wide depth buffers.\r\n */\r\n public get useLogarithmicDepth(): boolean {\r\n return this._useLogarithmicDepth;\r\n }\r\n\r\n public set useLogarithmicDepth(value: boolean) {\r\n this._useLogarithmicDepth = value && this.getScene()!.getEngine().getCaps().fragmentDepthSupported;\r\n }\r\n\r\n /**\r\n * Get hosting scene\r\n * @returns the scene\r\n */\r\n public getScene(): Nullable {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * You can use gravity if you want to give an orientation to your particles.\r\n */\r\n public gravity = Vector3.Zero();\r\n\r\n protected _colorGradients: Nullable> = null;\r\n protected _sizeGradients: Nullable> = null;\r\n protected _lifeTimeGradients: Nullable> = null;\r\n protected _angularSpeedGradients: Nullable> = null;\r\n protected _velocityGradients: Nullable> = null;\r\n protected _limitVelocityGradients: Nullable> = null;\r\n protected _dragGradients: Nullable> = null;\r\n protected _emitRateGradients: Nullable> = null;\r\n protected _startSizeGradients: Nullable> = null;\r\n protected _rampGradients: Nullable> = null;\r\n protected _colorRemapGradients: Nullable> = null;\r\n protected _alphaRemapGradients: Nullable> = null;\r\n\r\n protected _hasTargetStopDurationDependantGradient() {\r\n return (\r\n (this._startSizeGradients && this._startSizeGradients.length > 0) ||\r\n (this._emitRateGradients && this._emitRateGradients.length > 0) ||\r\n (this._lifeTimeGradients && this._lifeTimeGradients.length > 0)\r\n );\r\n }\r\n\r\n /**\r\n * Defines the delay in milliseconds before starting the system (0 by default)\r\n */\r\n public startDelay = 0;\r\n\r\n /**\r\n * Gets the current list of drag gradients.\r\n * You must use addDragGradient and removeDragGradient to update this list\r\n * @returns the list of drag gradients\r\n */\r\n public getDragGradients(): Nullable> {\r\n return this._dragGradients;\r\n }\r\n\r\n /** Gets or sets a value indicating the damping to apply if the limit velocity factor is reached */\r\n public limitVelocityDamping = 0.4;\r\n\r\n /**\r\n * Gets the current list of limit velocity gradients.\r\n * You must use addLimitVelocityGradient and removeLimitVelocityGradient to update this list\r\n * @returns the list of limit velocity gradients\r\n */\r\n public getLimitVelocityGradients(): Nullable> {\r\n return this._limitVelocityGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of color gradients.\r\n * You must use addColorGradient and removeColorGradient to update this list\r\n * @returns the list of color gradients\r\n */\r\n public getColorGradients(): Nullable> {\r\n return this._colorGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of size gradients.\r\n * You must use addSizeGradient and removeSizeGradient to update this list\r\n * @returns the list of size gradients\r\n */\r\n public getSizeGradients(): Nullable> {\r\n return this._sizeGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of color remap gradients.\r\n * You must use addColorRemapGradient and removeColorRemapGradient to update this list\r\n * @returns the list of color remap gradients\r\n */\r\n public getColorRemapGradients(): Nullable> {\r\n return this._colorRemapGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of alpha remap gradients.\r\n * You must use addAlphaRemapGradient and removeAlphaRemapGradient to update this list\r\n * @returns the list of alpha remap gradients\r\n */\r\n public getAlphaRemapGradients(): Nullable> {\r\n return this._alphaRemapGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of life time gradients.\r\n * You must use addLifeTimeGradient and removeLifeTimeGradient to update this list\r\n * @returns the list of life time gradients\r\n */\r\n public getLifeTimeGradients(): Nullable> {\r\n return this._lifeTimeGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of angular speed gradients.\r\n * You must use addAngularSpeedGradient and removeAngularSpeedGradient to update this list\r\n * @returns the list of angular speed gradients\r\n */\r\n public getAngularSpeedGradients(): Nullable> {\r\n return this._angularSpeedGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of velocity gradients.\r\n * You must use addVelocityGradient and removeVelocityGradient to update this list\r\n * @returns the list of velocity gradients\r\n */\r\n public getVelocityGradients(): Nullable> {\r\n return this._velocityGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of start size gradients.\r\n * You must use addStartSizeGradient and removeStartSizeGradient to update this list\r\n * @returns the list of start size gradients\r\n */\r\n public getStartSizeGradients(): Nullable> {\r\n return this._startSizeGradients;\r\n }\r\n\r\n /**\r\n * Gets the current list of emit rate gradients.\r\n * You must use addEmitRateGradient and removeEmitRateGradient to update this list\r\n * @returns the list of emit rate gradients\r\n */\r\n public getEmitRateGradients(): Nullable> {\r\n return this._emitRateGradients;\r\n }\r\n\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n * This only works when particleEmitterTyps is a BoxParticleEmitter\r\n */\r\n public get direction1(): Vector3 {\r\n if ((this.particleEmitterType).direction1) {\r\n return (this.particleEmitterType).direction1;\r\n }\r\n\r\n return Vector3.Zero();\r\n }\r\n\r\n public set direction1(value: Vector3) {\r\n if ((this.particleEmitterType).direction1) {\r\n (this.particleEmitterType).direction1 = value;\r\n }\r\n }\r\n\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n * This only works when particleEmitterTyps is a BoxParticleEmitter\r\n */\r\n public get direction2(): Vector3 {\r\n if ((this.particleEmitterType).direction2) {\r\n return (this.particleEmitterType).direction2;\r\n }\r\n\r\n return Vector3.Zero();\r\n }\r\n\r\n public set direction2(value: Vector3) {\r\n if ((this.particleEmitterType).direction2) {\r\n (this.particleEmitterType).direction2 = value;\r\n }\r\n }\r\n\r\n /**\r\n * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\r\n * This only works when particleEmitterTyps is a BoxParticleEmitter\r\n */\r\n public get minEmitBox(): Vector3 {\r\n if ((this.particleEmitterType).minEmitBox) {\r\n return (this.particleEmitterType).minEmitBox;\r\n }\r\n\r\n return Vector3.Zero();\r\n }\r\n\r\n public set minEmitBox(value: Vector3) {\r\n if ((this.particleEmitterType).minEmitBox) {\r\n (this.particleEmitterType).minEmitBox = value;\r\n }\r\n }\r\n\r\n /**\r\n * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\r\n * This only works when particleEmitterTyps is a BoxParticleEmitter\r\n */\r\n public get maxEmitBox(): Vector3 {\r\n if ((this.particleEmitterType).maxEmitBox) {\r\n return (this.particleEmitterType).maxEmitBox;\r\n }\r\n\r\n return Vector3.Zero();\r\n }\r\n\r\n public set maxEmitBox(value: Vector3) {\r\n if ((this.particleEmitterType).maxEmitBox) {\r\n (this.particleEmitterType).maxEmitBox = value;\r\n }\r\n }\r\n\r\n /**\r\n * Random color of each particle after it has been emitted, between color1 and color2 vectors\r\n */\r\n public color1 = new Color4(1.0, 1.0, 1.0, 1.0);\r\n /**\r\n * Random color of each particle after it has been emitted, between color1 and color2 vectors\r\n */\r\n public color2 = new Color4(1.0, 1.0, 1.0, 1.0);\r\n /**\r\n * Color the particle will have at the end of its lifetime\r\n */\r\n public colorDead = new Color4(0, 0, 0, 1.0);\r\n\r\n /**\r\n * An optional mask to filter some colors out of the texture, or filter a part of the alpha channel\r\n */\r\n public textureMask = new Color4(1.0, 1.0, 1.0, 1.0);\r\n\r\n /**\r\n * The particle emitter type defines the emitter used by the particle system.\r\n * It can be for example box, sphere, or cone...\r\n */\r\n public particleEmitterType: IParticleEmitterType;\r\n\r\n /** @internal */\r\n public _isSubEmitter = false;\r\n\r\n /** @internal */\r\n public _billboardMode = Constants.PARTICLES_BILLBOARDMODE_ALL;\r\n /**\r\n * Gets or sets the billboard mode to use when isBillboardBased = true.\r\n * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED\r\n */\r\n public get billboardMode(): number {\r\n return this._billboardMode;\r\n }\r\n\r\n public set billboardMode(value: number) {\r\n if (this._billboardMode === value) {\r\n return;\r\n }\r\n\r\n this._billboardMode = value;\r\n this._reset();\r\n }\r\n\r\n /** @internal */\r\n public _isBillboardBased = true;\r\n /**\r\n * Gets or sets a boolean indicating if the particles must be rendered as billboard or aligned with the direction\r\n */\r\n public get isBillboardBased(): boolean {\r\n return this._isBillboardBased;\r\n }\r\n\r\n public set isBillboardBased(value: boolean) {\r\n if (this._isBillboardBased === value) {\r\n return;\r\n }\r\n\r\n this._isBillboardBased = value;\r\n this._reset();\r\n }\r\n\r\n /**\r\n * The scene the particle system belongs to.\r\n */\r\n protected _scene: Nullable;\r\n\r\n /**\r\n * The engine the particle system belongs to.\r\n */\r\n protected _engine: ThinEngine;\r\n\r\n /**\r\n * Local cache of defines for image processing.\r\n */\r\n protected _imageProcessingConfigurationDefines = new ImageProcessingConfigurationDefines();\r\n\r\n /**\r\n * Default configuration related to image processing available in the standard Material.\r\n */\r\n protected _imageProcessingConfiguration: Nullable;\r\n\r\n /**\r\n * Gets the image processing configuration used either in this material.\r\n */\r\n public get imageProcessingConfiguration(): Nullable {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n /**\r\n * Sets the Default image processing configuration used either in the this material.\r\n *\r\n * If sets to null, the scene one is in use.\r\n */\r\n public set imageProcessingConfiguration(value: Nullable) {\r\n this._attachImageProcessingConfiguration(value);\r\n }\r\n\r\n /**\r\n * Attaches a new image processing configuration to the Standard Material.\r\n * @param configuration\r\n */\r\n protected _attachImageProcessingConfiguration(configuration: Nullable): void {\r\n if (configuration === this._imageProcessingConfiguration) {\r\n return;\r\n }\r\n\r\n // Pick the scene configuration if needed.\r\n if (!configuration && this._scene) {\r\n this._imageProcessingConfiguration = this._scene.imageProcessingConfiguration;\r\n } else {\r\n this._imageProcessingConfiguration = configuration;\r\n }\r\n }\r\n\r\n /** @internal */\r\n protected _reset() {}\r\n\r\n /**\r\n * @internal\r\n */\r\n protected _removeGradientAndTexture(gradient: number, gradients: Nullable, texture: Nullable): BaseParticleSystem {\r\n if (!gradients) {\r\n return this;\r\n }\r\n\r\n let index = 0;\r\n for (const valueGradient of gradients) {\r\n if (valueGradient.gradient === gradient) {\r\n gradients.splice(index, 1);\r\n break;\r\n }\r\n index++;\r\n }\r\n\r\n if (texture) {\r\n texture.dispose();\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Instantiates a particle system.\r\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\r\n * @param name The name of the particle system\r\n */\r\n public constructor(name: string) {\r\n this.id = name;\r\n this.name = name;\r\n }\r\n\r\n /**\r\n * Creates a Point Emitter for the particle system (emits directly from the emitter position)\r\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the box\r\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the box\r\n * @returns the emitter\r\n */\r\n public createPointEmitter(direction1: Vector3, direction2: Vector3): PointParticleEmitter {\r\n const particleEmitter = new PointParticleEmitter();\r\n particleEmitter.direction1 = direction1;\r\n particleEmitter.direction2 = direction2;\r\n\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)\r\n * @param radius The radius of the hemisphere to emit from\r\n * @param radiusRange The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius\r\n * @returns the emitter\r\n */\r\n public createHemisphericEmitter(radius = 1, radiusRange = 1): HemisphericParticleEmitter {\r\n const particleEmitter = new HemisphericParticleEmitter(radius, radiusRange);\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Sphere Emitter for the particle system (emits along the sphere radius)\r\n * @param radius The radius of the sphere to emit from\r\n * @param radiusRange The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius\r\n * @returns the emitter\r\n */\r\n public createSphereEmitter(radius = 1, radiusRange = 1): SphereParticleEmitter {\r\n const particleEmitter = new SphereParticleEmitter(radius, radiusRange);\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)\r\n * @param radius The radius of the sphere to emit from\r\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the sphere\r\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the sphere\r\n * @returns the emitter\r\n */\r\n public createDirectedSphereEmitter(radius = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)): SphereDirectedParticleEmitter {\r\n const particleEmitter = new SphereDirectedParticleEmitter(radius, direction1, direction2);\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)\r\n * @param radius The radius of the emission cylinder\r\n * @param height The height of the emission cylinder\r\n * @param radiusRange The range of emission [0-1] 0 Surface only, 1 Entire Radius\r\n * @param directionRandomizer How much to randomize the particle direction [0-1]\r\n * @returns the emitter\r\n */\r\n public createCylinderEmitter(radius = 1, height = 1, radiusRange = 1, directionRandomizer = 0): CylinderParticleEmitter {\r\n const particleEmitter = new CylinderParticleEmitter(radius, height, radiusRange, directionRandomizer);\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Directed Cylinder Emitter for the particle system (emits between direction1 and direction2)\r\n * @param radius The radius of the cylinder to emit from\r\n * @param height The height of the emission cylinder\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the cylinder\r\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the cylinder\r\n * @returns the emitter\r\n */\r\n public createDirectedCylinderEmitter(\r\n radius = 1,\r\n height = 1,\r\n radiusRange = 1,\r\n direction1 = new Vector3(0, 1.0, 0),\r\n direction2 = new Vector3(0, 1.0, 0)\r\n ): CylinderDirectedParticleEmitter {\r\n const particleEmitter = new CylinderDirectedParticleEmitter(radius, height, radiusRange, direction1, direction2);\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Cone Emitter for the particle system (emits from the cone to the particle position)\r\n * @param radius The radius of the cone to emit from\r\n * @param angle The base angle of the cone\r\n * @returns the emitter\r\n */\r\n public createConeEmitter(radius = 1, angle = Math.PI / 4): ConeParticleEmitter {\r\n const particleEmitter = new ConeParticleEmitter(radius, angle);\r\n this.particleEmitterType = particleEmitter;\r\n return particleEmitter;\r\n }\r\n\r\n /**\r\n * Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)\r\n * @param direction1 Particles are emitted between the direction1 and direction2 from within the box\r\n * @param direction2 Particles are emitted between the direction1 and direction2 from within the box\r\n * @param minEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox\r\n * @param maxEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox\r\n * @returns the emitter\r\n */\r\n public createBoxEmitter(direction1: Vector3, direction2: Vector3, minEmitBox: Vector3, maxEmitBox: Vector3): BoxParticleEmitter {\r\n const particleEmitter = new BoxParticleEmitter();\r\n this.particleEmitterType = particleEmitter;\r\n this.direction1 = direction1;\r\n this.direction2 = direction2;\r\n this.minEmitBox = minEmitBox;\r\n this.maxEmitBox = maxEmitBox;\r\n return particleEmitter;\r\n }\r\n}\r\n","import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\n\r\n/**\r\n * Block used to expand a Color3/4 into 4 outputs (one for each component)\r\n */\r\nexport class ColorSplitterBlock extends NodeMaterialBlock {\r\n /**\r\n * Create a new ColorSplitterBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"rgba\", NodeMaterialBlockConnectionPointTypes.Color4, true);\r\n this.registerInput(\"rgb \", NodeMaterialBlockConnectionPointTypes.Color3, true);\r\n\r\n this.registerOutput(\"rgb\", NodeMaterialBlockConnectionPointTypes.Color3);\r\n this.registerOutput(\"r\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"g\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"b\", NodeMaterialBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"a\", NodeMaterialBlockConnectionPointTypes.Float);\r\n\r\n this.inputsAreExclusive = true;\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"ColorSplitterBlock\";\r\n }\r\n\r\n /**\r\n * Gets the rgba component (input)\r\n */\r\n public get rgba(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the rgb component (input)\r\n */\r\n public get rgbIn(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the rgb component (output)\r\n */\r\n public get rgbOut(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the r component (output)\r\n */\r\n public get r(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Gets the g component (output)\r\n */\r\n public get g(): NodeMaterialConnectionPoint {\r\n return this._outputs[2];\r\n }\r\n /**\r\n * Gets the b component (output)\r\n */\r\n public get b(): NodeMaterialConnectionPoint {\r\n return this._outputs[3];\r\n }\r\n /**\r\n * Gets the a component (output)\r\n */\r\n public get a(): NodeMaterialConnectionPoint {\r\n return this._outputs[4];\r\n }\r\n\r\n protected _inputRename(name: string) {\r\n if (name === \"rgb \") {\r\n return \"rgbIn\";\r\n }\r\n return name;\r\n }\r\n\r\n protected _outputRename(name: string) {\r\n if (name === \"rgb\") {\r\n return \"rgbOut\";\r\n }\r\n return name;\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const input = this.rgba.isConnected ? this.rgba : this.rgbIn;\r\n\r\n if (!input.isConnected) {\r\n return;\r\n }\r\n\r\n const rgbOutput = this._outputs[0];\r\n const rOutput = this._outputs[1];\r\n const gOutput = this._outputs[2];\r\n const bOutput = this._outputs[3];\r\n const aOutput = this._outputs[4];\r\n\r\n if (rgbOutput.hasEndpoints) {\r\n state.compilationString += this._declareOutput(rgbOutput, state) + ` = ${input.associatedVariableName}.rgb;\\n`;\r\n }\r\n if (rOutput.hasEndpoints) {\r\n state.compilationString += this._declareOutput(rOutput, state) + ` = ${input.associatedVariableName}.r;\\n`;\r\n }\r\n if (gOutput.hasEndpoints) {\r\n state.compilationString += this._declareOutput(gOutput, state) + ` = ${input.associatedVariableName}.g;\\n`;\r\n }\r\n if (bOutput.hasEndpoints) {\r\n state.compilationString += this._declareOutput(bOutput, state) + ` = ${input.associatedVariableName}.b;\\n`;\r\n }\r\n if (aOutput.hasEndpoints) {\r\n state.compilationString += this._declareOutput(aOutput, state) + ` = ${input.associatedVariableName}.a;\\n`;\r\n }\r\n\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ColorSplitterBlock\", ColorSplitterBlock);\r\n","import { Tools } from \"../../../Misc/tools\";\r\nimport type { Scene } from \"../../../scene\";\r\nimport type { ISceneComponent } from \"../../../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../../../sceneComponent\";\r\n\r\nimport type { ProceduralTexture } from \"./proceduralTexture\";\r\n\r\ndeclare module \"../../../abstractScene\" {\r\n export interface AbstractScene {\r\n /**\r\n * The list of procedural textures added to the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/proceduralTextures\r\n */\r\n proceduralTextures: Array;\r\n }\r\n}\r\n/**\r\n * Defines the Procedural Texture scene component responsible to manage any Procedural Texture\r\n * in a given scene.\r\n */\r\nexport class ProceduralTextureSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_PROCEDURALTEXTURE;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n this.scene.proceduralTextures = new Array();\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._beforeClearStage.registerStep(SceneComponentConstants.STEP_BEFORECLEAR_PROCEDURALTEXTURE, this, this._beforeClear);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do here.\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources.\r\n */\r\n public dispose(): void {\r\n // Nothing to do here.\r\n }\r\n\r\n private _beforeClear(): void {\r\n if (this.scene.proceduralTexturesEnabled) {\r\n Tools.StartPerformanceCounter(\"Procedural textures\", this.scene.proceduralTextures.length > 0);\r\n for (let proceduralIndex = 0; proceduralIndex < this.scene.proceduralTextures.length; proceduralIndex++) {\r\n const proceduralTexture = this.scene.proceduralTextures[proceduralIndex];\r\n if (proceduralTexture._shouldRender()) {\r\n proceduralTexture.render();\r\n }\r\n }\r\n Tools.EndPerformanceCounter(\"Procedural textures\", this.scene.proceduralTextures.length > 0);\r\n }\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"proceduralVertexShader\";\nconst shader = `attribute vec2 position;varying vec2 vPosition;varying vec2 vUV;const vec2 madd=vec2(0.5,0.5);\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvPosition=position;vUV=position*madd+madd;gl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const proceduralVertexShader = { name, shader };\n","import { serialize } from \"../../../Misc/decorators\";\r\nimport { Observable } from \"../../../Misc/observable\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport type { Scene } from \"../../../scene\";\r\nimport type { Matrix, Vector3, Vector2 } from \"../../../Maths/math.vector\";\r\nimport type { Color4, Color3 } from \"../../../Maths/math.color\";\r\nimport type { Engine } from \"../../../Engines/engine\";\r\nimport { VertexBuffer } from \"../../../Buffers/buffer\";\r\nimport { SceneComponentConstants } from \"../../../sceneComponent\";\r\n\r\nimport { Material } from \"../../../Materials/material\";\r\nimport type { Effect } from \"../../../Materials/effect\";\r\nimport { Texture } from \"../../../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../../../Materials/Textures/renderTargetTexture\";\r\nimport { ProceduralTextureSceneComponent } from \"./proceduralTextureSceneComponent\";\r\n\r\nimport \"../../../Engines/Extensions/engine.renderTarget\";\r\nimport \"../../../Engines/Extensions/engine.renderTargetCube\";\r\nimport \"../../../Shaders/procedural.vertex\";\r\nimport type { DataBuffer } from \"../../../Buffers/dataBuffer\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport type { NodeMaterial } from \"../../Node/nodeMaterial\";\r\nimport type { TextureSize } from \"../../../Materials/Textures/textureCreationOptions\";\r\nimport { EngineStore } from \"../../../Engines/engineStore\";\r\nimport { Constants } from \"../../../Engines/constants\";\r\nimport { DrawWrapper } from \"../../drawWrapper\";\r\nimport type { RenderTargetWrapper } from \"../../../Engines/renderTargetWrapper\";\r\n\r\n/**\r\n * Procedural texturing is a way to programmatically create a texture. There are 2 types of procedural textures: code-only, and code that references some classic 2D images, sometimes calmpler' images.\r\n * This is the base class of any Procedural texture and contains most of the shareable code.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/proceduralTextures\r\n */\r\nexport class ProceduralTexture extends Texture {\r\n /**\r\n * Define if the texture is enabled or not (disabled texture will not render)\r\n */\r\n @serialize()\r\n public isEnabled = true;\r\n\r\n /**\r\n * Define if the texture must be cleared before rendering (default is true)\r\n */\r\n @serialize()\r\n public autoClear = true;\r\n\r\n /**\r\n * Callback called when the texture is generated\r\n */\r\n public onGenerated: () => void;\r\n\r\n /**\r\n * Event raised when the texture is generated\r\n */\r\n public onGeneratedObservable = new Observable();\r\n\r\n /**\r\n * Event raised before the texture is generated\r\n */\r\n public onBeforeGenerationObservable = new Observable();\r\n\r\n /**\r\n * Gets or sets the node material used to create this texture (null if the texture was manually created)\r\n */\r\n public nodeMaterialSource: Nullable = null;\r\n\r\n /** @internal */\r\n @serialize()\r\n public _generateMipMaps: boolean;\r\n\r\n private _drawWrapper: DrawWrapper;\r\n\r\n /** @internal */\r\n public _textures: { [key: string]: Texture } = {};\r\n\r\n /** @internal */\r\n protected _fallbackTexture: Nullable;\r\n\r\n @serialize()\r\n private _size: TextureSize;\r\n private _textureType: number;\r\n private _currentRefreshId = -1;\r\n private _frameId = -1;\r\n private _refreshRate = 1;\r\n private _vertexBuffers: { [key: string]: Nullable } = {};\r\n private _indexBuffer: Nullable;\r\n private _uniforms = new Array();\r\n private _samplers = new Array();\r\n private _fragment: any;\r\n\r\n private _floats: { [key: string]: number } = {};\r\n private _ints: { [key: string]: number } = {};\r\n private _floatsArrays: { [key: string]: number[] } = {};\r\n private _colors3: { [key: string]: Color3 } = {};\r\n private _colors4: { [key: string]: Color4 } = {};\r\n private _vectors2: { [key: string]: Vector2 } = {};\r\n private _vectors3: { [key: string]: Vector3 } = {};\r\n private _matrices: { [key: string]: Matrix } = {};\r\n\r\n private _fallbackTextureUsed = false;\r\n private _fullEngine: Engine;\r\n\r\n private _cachedDefines: Nullable = null;\r\n\r\n private _contentUpdateId = -1;\r\n private _contentData: Nullable>;\r\n\r\n private _rtWrapper: Nullable = null;\r\n\r\n /**\r\n * Instantiates a new procedural texture.\r\n * Procedural texturing is a way to programmatically create a texture. There are 2 types of procedural textures: code-only, and code that references some classic 2D images, sometimes called 'refMaps' or 'sampler' images.\r\n * This is the base class of any Procedural texture and contains most of the shareable code.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/proceduralTextures\r\n * @param name Define the name of the texture\r\n * @param size Define the size of the texture to create\r\n * @param fragment Define the fragment shader to use to generate the texture or null if it is defined later\r\n * @param scene Define the scene the texture belongs to\r\n * @param fallbackTexture Define a fallback texture in case there were issues to create the custom texture\r\n * @param generateMipMaps Define if the texture should creates mip maps or not\r\n * @param isCube Define if the texture is a cube texture or not (this will render each faces of the cube)\r\n * @param textureType The FBO internal texture type\r\n */\r\n constructor(\r\n name: string,\r\n size: TextureSize,\r\n fragment: any,\r\n scene: Nullable,\r\n fallbackTexture: Nullable = null,\r\n generateMipMaps = true,\r\n isCube = false,\r\n textureType = Constants.TEXTURETYPE_UNSIGNED_INT\r\n ) {\r\n super(null, scene, !generateMipMaps);\r\n\r\n scene = this.getScene() || EngineStore.LastCreatedScene!;\r\n let component = scene._getComponent(SceneComponentConstants.NAME_PROCEDURALTEXTURE);\r\n if (!component) {\r\n component = new ProceduralTextureSceneComponent(scene);\r\n scene._addComponent(component);\r\n }\r\n scene.proceduralTextures.push(this);\r\n\r\n this._fullEngine = scene.getEngine();\r\n\r\n this.name = name;\r\n this.isRenderTarget = true;\r\n this._size = size;\r\n this._textureType = textureType;\r\n this._generateMipMaps = generateMipMaps;\r\n this._drawWrapper = new DrawWrapper(this._fullEngine);\r\n\r\n this.setFragment(fragment);\r\n\r\n this._fallbackTexture = fallbackTexture;\r\n\r\n const rtWrapper = this._createRtWrapper(isCube, size, generateMipMaps, textureType);\r\n this._texture = rtWrapper.texture;\r\n\r\n // VBO\r\n const vertices = [];\r\n vertices.push(1, 1);\r\n vertices.push(-1, 1);\r\n vertices.push(-1, -1);\r\n vertices.push(1, -1);\r\n\r\n this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(this._fullEngine, vertices, VertexBuffer.PositionKind, false, false, 2);\r\n\r\n this._createIndexBuffer();\r\n }\r\n\r\n private _createRtWrapper(isCube: boolean, size: TextureSize, generateMipMaps: boolean, textureType: number) {\r\n if (isCube) {\r\n this._rtWrapper = this._fullEngine.createRenderTargetCubeTexture(size as number, {\r\n generateMipMaps: generateMipMaps,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n type: textureType,\r\n });\r\n this.setFloat(\"face\", 0);\r\n } else {\r\n this._rtWrapper = this._fullEngine.createRenderTargetTexture(size, {\r\n generateMipMaps: generateMipMaps,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n type: textureType,\r\n });\r\n }\r\n return this._rtWrapper;\r\n }\r\n\r\n /**\r\n * The effect that is created when initializing the post process.\r\n * @returns The created effect corresponding the the postprocess.\r\n */\r\n public getEffect(): Effect {\r\n return this._drawWrapper.effect!;\r\n }\r\n\r\n /**\r\n * @internal*\r\n */\r\n public _setEffect(effect: Effect) {\r\n this._drawWrapper.effect = effect;\r\n }\r\n\r\n /**\r\n * Gets texture content (Use this function wisely as reading from a texture can be slow)\r\n * @returns an ArrayBufferView promise (Uint8Array or Float32Array)\r\n */\r\n public getContent(): Nullable> {\r\n if (this._contentData && this._frameId === this._contentUpdateId) {\r\n return this._contentData;\r\n }\r\n\r\n if (this._contentData) {\r\n this._contentData.then((buffer) => {\r\n this._contentData = this.readPixels(0, 0, buffer);\r\n this._contentUpdateId = this._frameId;\r\n });\r\n } else {\r\n this._contentData = this.readPixels(0, 0);\r\n this._contentUpdateId = this._frameId;\r\n }\r\n\r\n return this._contentData;\r\n }\r\n\r\n private _createIndexBuffer(): void {\r\n const engine = this._fullEngine;\r\n\r\n // Indices\r\n const indices = [];\r\n indices.push(0);\r\n indices.push(1);\r\n indices.push(2);\r\n\r\n indices.push(0);\r\n indices.push(2);\r\n indices.push(3);\r\n\r\n this._indexBuffer = engine.createIndexBuffer(indices);\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\r\n\r\n if (vb) {\r\n vb._rebuild();\r\n }\r\n\r\n this._createIndexBuffer();\r\n\r\n if (this.refreshRate === RenderTargetTexture.REFRESHRATE_RENDER_ONCE) {\r\n this.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;\r\n }\r\n }\r\n\r\n /**\r\n * Resets the texture in order to recreate its associated resources.\r\n * This can be called in case of context loss\r\n */\r\n public reset(): void {\r\n this._drawWrapper.effect?.dispose();\r\n }\r\n\r\n protected _getDefines(): string {\r\n return \"\";\r\n }\r\n\r\n /**\r\n * Is the texture ready to be used ? (rendered at least once)\r\n * @returns true if ready, otherwise, false.\r\n */\r\n public isReady(): boolean {\r\n const engine = this._fullEngine;\r\n let shaders;\r\n\r\n if (this.nodeMaterialSource) {\r\n return this._drawWrapper.effect!.isReady();\r\n }\r\n\r\n if (!this._fragment) {\r\n return false;\r\n }\r\n\r\n if (this._fallbackTextureUsed) {\r\n return true;\r\n }\r\n\r\n if (!this._texture) {\r\n return false;\r\n }\r\n\r\n const defines = this._getDefines();\r\n if (this._drawWrapper.effect && defines === this._cachedDefines && this._drawWrapper.effect.isReady()) {\r\n return true;\r\n }\r\n\r\n if (this._fragment.fragmentElement !== undefined) {\r\n shaders = { vertex: \"procedural\", fragmentElement: this._fragment.fragmentElement };\r\n } else {\r\n shaders = { vertex: \"procedural\", fragment: this._fragment };\r\n }\r\n\r\n if (this._cachedDefines !== defines) {\r\n this._cachedDefines = defines;\r\n\r\n this._drawWrapper.effect = engine.createEffect(shaders, [VertexBuffer.PositionKind], this._uniforms, this._samplers, defines, undefined, undefined, () => {\r\n this._rtWrapper?.dispose();\r\n this._rtWrapper = this._texture = null;\r\n\r\n if (this._fallbackTexture) {\r\n this._texture = this._fallbackTexture._texture;\r\n\r\n if (this._texture) {\r\n this._texture.incrementReferences();\r\n }\r\n }\r\n\r\n this._fallbackTextureUsed = true;\r\n });\r\n }\r\n\r\n return this._drawWrapper.effect!.isReady();\r\n }\r\n\r\n /**\r\n * Resets the refresh counter of the texture and start bak from scratch.\r\n * Could be useful to regenerate the texture if it is setup to render only once.\r\n */\r\n public resetRefreshCounter(): void {\r\n this._currentRefreshId = -1;\r\n }\r\n\r\n /**\r\n * Set the fragment shader to use in order to render the texture.\r\n * @param fragment This can be set to a path (into the shader store) or to a json object containing a fragmentElement property.\r\n */\r\n public setFragment(fragment: any) {\r\n this._fragment = fragment;\r\n }\r\n\r\n /**\r\n * Define the refresh rate of the texture or the rendering frequency.\r\n * Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...\r\n */\r\n @serialize()\r\n public get refreshRate(): number {\r\n return this._refreshRate;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n this._refreshRate = value;\r\n this.resetRefreshCounter();\r\n }\r\n\r\n /** @internal */\r\n public _shouldRender(): boolean {\r\n if (!this.isEnabled || !this.isReady() || !this._texture) {\r\n if (this._texture) {\r\n this._texture.isReady = false;\r\n }\r\n return false;\r\n }\r\n\r\n if (this._fallbackTextureUsed) {\r\n return false;\r\n }\r\n\r\n if (this._currentRefreshId === -1) {\r\n // At least render once\r\n this._currentRefreshId = 1;\r\n this._frameId++;\r\n return true;\r\n }\r\n\r\n if (this.refreshRate === this._currentRefreshId) {\r\n this._currentRefreshId = 1;\r\n this._frameId++;\r\n return true;\r\n }\r\n\r\n this._currentRefreshId++;\r\n return false;\r\n }\r\n\r\n /**\r\n * Get the size the texture is rendering at.\r\n * @returns the size (on cube texture it is always squared)\r\n */\r\n public getRenderSize(): TextureSize {\r\n return this._size;\r\n }\r\n\r\n /**\r\n * Resize the texture to new value.\r\n * @param size Define the new size the texture should have\r\n * @param generateMipMaps Define whether the new texture should create mip maps\r\n */\r\n public resize(size: TextureSize, generateMipMaps: boolean): void {\r\n if (this._fallbackTextureUsed || !this._rtWrapper || !this._texture) {\r\n return;\r\n }\r\n\r\n const isCube = this._texture.isCube;\r\n this._rtWrapper.dispose();\r\n\r\n const rtWrapper = this._createRtWrapper(isCube, size, generateMipMaps, this._textureType);\r\n this._texture = rtWrapper.texture;\r\n\r\n // Update properties\r\n this._size = size;\r\n this._generateMipMaps = generateMipMaps;\r\n }\r\n\r\n private _checkUniform(uniformName: string): void {\r\n if (this._uniforms.indexOf(uniformName) === -1) {\r\n this._uniforms.push(uniformName);\r\n }\r\n }\r\n\r\n /**\r\n * Set a texture in the shader program used to render.\r\n * @param name Define the name of the uniform samplers as defined in the shader\r\n * @param texture Define the texture to bind to this sampler\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setTexture(name: string, texture: Texture): ProceduralTexture {\r\n if (this._samplers.indexOf(name) === -1) {\r\n this._samplers.push(name);\r\n }\r\n this._textures[name] = texture;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a float in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setFloat(name: string, value: number): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._floats[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a int in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setInt(name: string, value: number): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._ints[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set an array of floats in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setFloats(name: string, value: number[]): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._floatsArrays[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec3 in the shader from a Color3.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setColor3(name: string, value: Color3): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._colors3[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 in the shader from a Color4.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setColor4(name: string, value: Color4): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._colors4[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec2 in the shader from a Vector2.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setVector2(name: string, value: Vector2): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._vectors2[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec3 in the shader from a Vector3.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setVector3(name: string, value: Vector3): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._vectors3[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a mat4 in the shader from a MAtrix.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the texture itself allowing \"fluent\" like uniform updates\r\n */\r\n public setMatrix(name: string, value: Matrix): ProceduralTexture {\r\n this._checkUniform(name);\r\n this._matrices[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Render the texture to its associated render target.\r\n * @param useCameraPostProcess Define if camera post process should be applied to the texture\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public render(useCameraPostProcess?: boolean): void {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const engine = this._fullEngine;\r\n\r\n // Render\r\n engine.enableEffect(this._drawWrapper);\r\n this.onBeforeGenerationObservable.notifyObservers(this);\r\n engine.setState(false);\r\n\r\n if (!this.nodeMaterialSource) {\r\n // Texture\r\n for (const name in this._textures) {\r\n this._drawWrapper.effect!.setTexture(name, this._textures[name]);\r\n }\r\n\r\n // Float\r\n for (const name in this._ints) {\r\n this._drawWrapper.effect!.setInt(name, this._ints[name]);\r\n }\r\n\r\n // Float\r\n for (const name in this._floats) {\r\n this._drawWrapper.effect!.setFloat(name, this._floats[name]);\r\n }\r\n\r\n // Floats\r\n for (const name in this._floatsArrays) {\r\n this._drawWrapper.effect!.setArray(name, this._floatsArrays[name]);\r\n }\r\n\r\n // Color3\r\n for (const name in this._colors3) {\r\n this._drawWrapper.effect!.setColor3(name, this._colors3[name]);\r\n }\r\n\r\n // Color4\r\n for (const name in this._colors4) {\r\n const color = this._colors4[name];\r\n this._drawWrapper.effect!.setFloat4(name, color.r, color.g, color.b, color.a);\r\n }\r\n\r\n // Vector2\r\n for (const name in this._vectors2) {\r\n this._drawWrapper.effect!.setVector2(name, this._vectors2[name]);\r\n }\r\n\r\n // Vector3\r\n for (const name in this._vectors3) {\r\n this._drawWrapper.effect!.setVector3(name, this._vectors3[name]);\r\n }\r\n\r\n // Matrix\r\n for (const name in this._matrices) {\r\n this._drawWrapper.effect!.setMatrix(name, this._matrices[name]);\r\n }\r\n }\r\n\r\n if (!this._texture || !this._rtWrapper) {\r\n return;\r\n }\r\n\r\n engine._debugPushGroup?.(`procedural texture generation for ${this.name}`, 1);\r\n\r\n const viewPort = engine.currentViewport;\r\n if (this.isCube) {\r\n for (let face = 0; face < 6; face++) {\r\n engine.bindFramebuffer(this._rtWrapper, face, undefined, undefined, true);\r\n\r\n // VBOs\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._drawWrapper.effect!);\r\n\r\n this._drawWrapper.effect!.setFloat(\"face\", face);\r\n\r\n // Clear\r\n if (this.autoClear) {\r\n engine.clear(scene.clearColor, true, false, false);\r\n }\r\n\r\n // Draw order\r\n engine.drawElementsType(Material.TriangleFillMode, 0, 6);\r\n }\r\n } else {\r\n engine.bindFramebuffer(this._rtWrapper, 0, undefined, undefined, true);\r\n\r\n // VBOs\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._drawWrapper.effect!);\r\n\r\n // Clear\r\n if (this.autoClear) {\r\n engine.clear(scene.clearColor, true, false, false);\r\n }\r\n\r\n // Draw order\r\n engine.drawElementsType(Material.TriangleFillMode, 0, 6);\r\n }\r\n\r\n // Unbind and restore viewport\r\n engine.unBindFramebuffer(this._rtWrapper, this.isCube);\r\n if (viewPort) {\r\n engine.setViewport(viewPort);\r\n }\r\n\r\n // Mipmaps\r\n if (this.isCube) {\r\n engine.generateMipMapsForCubemap(this._texture);\r\n }\r\n\r\n engine._debugPopGroup?.(1);\r\n\r\n if (this.onGenerated) {\r\n this.onGenerated();\r\n }\r\n\r\n this.onGeneratedObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Clone the texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): ProceduralTexture {\r\n const textureSize = this.getSize();\r\n const newTexture = new ProceduralTexture(this.name, textureSize.width, this._fragment, this.getScene(), this._fallbackTexture, this._generateMipMaps);\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // RenderTarget Texture\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n const index = scene.proceduralTextures.indexOf(this);\r\n\r\n if (index >= 0) {\r\n scene.proceduralTextures.splice(index, 1);\r\n }\r\n\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\r\n }\r\n\r\n if (this._indexBuffer && this._fullEngine._releaseBuffer(this._indexBuffer)) {\r\n this._indexBuffer = null;\r\n }\r\n\r\n this.onGeneratedObservable.clear();\r\n this.onBeforeGenerationObservable.clear();\r\n\r\n super.dispose();\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ProceduralTexture\", ProceduralTexture);\r\n","import { NodeMaterialBlock } from \"../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport type { NodeMaterialBuildState } from \"../nodeMaterialBuildState\";\r\nimport type { NodeMaterialConnectionPoint } from \"../nodeMaterialBlockConnectionPoint\";\r\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport type { Scene } from \"../../../scene\";\r\n\r\n/**\r\n * Operations supported by the Trigonometry block\r\n */\r\nexport enum TrigonometryBlockOperations {\r\n /** Cos */\r\n Cos,\r\n /** Sin */\r\n Sin,\r\n /** Abs */\r\n Abs,\r\n /** Exp */\r\n Exp,\r\n /** Exp2 */\r\n Exp2,\r\n /** Round */\r\n Round,\r\n /** Floor */\r\n Floor,\r\n /** Ceiling */\r\n Ceiling,\r\n /** Square root */\r\n Sqrt,\r\n /** Log */\r\n Log,\r\n /** Tangent */\r\n Tan,\r\n /** Arc tangent */\r\n ArcTan,\r\n /** Arc cosinus */\r\n ArcCos,\r\n /** Arc sinus */\r\n ArcSin,\r\n /** Fraction */\r\n Fract,\r\n /** Sign */\r\n Sign,\r\n /** To radians (from degrees) */\r\n Radians,\r\n /** To degrees (from radians) */\r\n Degrees,\r\n}\r\n\r\n/**\r\n * Block used to apply trigonometry operation to floats\r\n */\r\nexport class TrigonometryBlock extends NodeMaterialBlock {\r\n /**\r\n * Gets or sets the operation applied by the block\r\n */\r\n public operation = TrigonometryBlockOperations.Cos;\r\n\r\n /**\r\n * Creates a new TrigonometryBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Neutral);\r\n\r\n this.registerInput(\"input\", NodeMaterialBlockConnectionPointTypes.AutoDetect);\r\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"TrigonometryBlock\";\r\n }\r\n\r\n /**\r\n * Gets the input component\r\n */\r\n public get input(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the output component\r\n */\r\n public get output(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n const output = this._outputs[0];\r\n let operation = \"\";\r\n\r\n switch (this.operation) {\r\n case TrigonometryBlockOperations.Cos: {\r\n operation = \"cos\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Sin: {\r\n operation = \"sin\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Abs: {\r\n operation = \"abs\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Exp: {\r\n operation = \"exp\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Exp2: {\r\n operation = \"exp2\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Round: {\r\n operation = \"round\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Floor: {\r\n operation = \"floor\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Ceiling: {\r\n operation = \"ceil\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Sqrt: {\r\n operation = \"sqrt\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Log: {\r\n operation = \"log\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Tan: {\r\n operation = \"tan\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.ArcTan: {\r\n operation = \"atan\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.ArcCos: {\r\n operation = \"acos\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.ArcSin: {\r\n operation = \"asin\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Fract: {\r\n operation = \"fract\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Sign: {\r\n operation = \"sign\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Radians: {\r\n operation = \"radians\";\r\n break;\r\n }\r\n case TrigonometryBlockOperations.Degrees: {\r\n operation = \"degrees\";\r\n break;\r\n }\r\n }\r\n\r\n state.compilationString += this._declareOutput(output, state) + ` = ${operation}(${this.input.associatedVariableName});\\n`;\r\n\r\n return this;\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.operation = this.operation;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {\r\n super._deserialize(serializationObject, scene, rootUrl);\r\n\r\n this.operation = serializationObject.operation;\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString =\r\n super._dumpPropertiesCode() + `${this._codeVariableName}.operation = BABYLON.TrigonometryBlockOperations.${TrigonometryBlockOperations[this.operation]};\\n`;\r\n return codeString;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.TrigonometryBlock\", TrigonometryBlock);\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { NodeMaterialBlock } from \"./nodeMaterialBlock\";\r\nimport { PushMaterial } from \"../pushMaterial\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Matrix, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Color3, Color4 } from \"../../Maths/math.color\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport { Engine } from \"../../Engines/engine\";\r\nimport { NodeMaterialBuildState } from \"./nodeMaterialBuildState\";\r\nimport type { IEffectCreationOptions } from \"../effect\";\r\nimport { Effect } from \"../effect\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { NodeMaterialBlockTargets } from \"./Enums/nodeMaterialBlockTargets\";\r\nimport { NodeMaterialBuildStateSharedData } from \"./nodeMaterialBuildStateSharedData\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport { MaterialDefines } from \"../../Materials/materialDefines\";\r\nimport type { NodeMaterialOptimizer } from \"./Optimizers/nodeMaterialOptimizer\";\r\nimport type { ImageProcessingConfiguration, IImageProcessingConfigurationDefines } from \"../imageProcessingConfiguration\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { TransformBlock } from \"./Blocks/transformBlock\";\r\nimport { VertexOutputBlock } from \"./Blocks/Vertex/vertexOutputBlock\";\r\nimport { FragmentOutputBlock } from \"./Blocks/Fragment/fragmentOutputBlock\";\r\nimport { InputBlock } from \"./Blocks/Input/inputBlock\";\r\nimport { GetClass, RegisterClass } from \"../../Misc/typeStore\";\r\nimport { serialize, SerializationHelper } from \"../../Misc/decorators\";\r\nimport type { TextureBlock } from \"./Blocks/Dual/textureBlock\";\r\nimport type { ReflectionTextureBaseBlock } from \"./Blocks/Dual/reflectionTextureBaseBlock\";\r\nimport type { RefractionBlock } from \"./Blocks/PBR/refractionBlock\";\r\nimport { CurrentScreenBlock } from \"./Blocks/Dual/currentScreenBlock\";\r\nimport { ParticleTextureBlock } from \"./Blocks/Particle/particleTextureBlock\";\r\nimport { ParticleRampGradientBlock } from \"./Blocks/Particle/particleRampGradientBlock\";\r\nimport { ParticleBlendMultiplyBlock } from \"./Blocks/Particle/particleBlendMultiplyBlock\";\r\nimport { EffectFallbacks } from \"../effectFallbacks\";\r\nimport { WebRequest } from \"../../Misc/webRequest\";\r\n\r\nimport type { PostProcessOptions } from \"../../PostProcesses/postProcess\";\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport { VectorMergerBlock } from \"./Blocks/vectorMergerBlock\";\r\nimport { RemapBlock } from \"./Blocks/remapBlock\";\r\nimport { MultiplyBlock } from \"./Blocks/multiplyBlock\";\r\nimport { NodeMaterialModes } from \"./Enums/nodeMaterialModes\";\r\nimport { Texture } from \"../Textures/texture\";\r\nimport type { IParticleSystem } from \"../../Particles/IParticleSystem\";\r\nimport { BaseParticleSystem } from \"../../Particles/baseParticleSystem\";\r\nimport { ColorSplitterBlock } from \"./Blocks/colorSplitterBlock\";\r\nimport { TimingTools } from \"../../Misc/timingTools\";\r\nimport { ProceduralTexture } from \"../Textures/Procedurals/proceduralTexture\";\r\nimport { AnimatedInputBlockTypes } from \"./Blocks/Input/animatedInputBlockTypes\";\r\nimport { TrigonometryBlock, TrigonometryBlockOperations } from \"./Blocks/trigonometryBlock\";\r\nimport { NodeMaterialSystemValues } from \"./Enums/nodeMaterialSystemValues\";\r\nimport type { ImageSourceBlock } from \"./Blocks/Dual/imageSourceBlock\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport type { Material } from \"../material\";\r\nimport { MaterialHelper } from \"../materialHelper\";\r\nimport type { TriPlanarBlock } from \"./Blocks/triPlanarBlock\";\r\nimport type { BiPlanarBlock } from \"./Blocks/biPlanarBlock\";\r\nimport type { NodeMaterialTeleportOutBlock } from \"./Blocks/Teleport/teleportOutBlock\";\r\nimport type { NodeMaterialTeleportInBlock } from \"./Blocks/Teleport/teleportInBlock\";\r\n\r\nconst onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable };\r\n\r\n// declare NODEEDITOR namespace for compilation issue\r\ndeclare let NODEEDITOR: any;\r\ndeclare let BABYLON: any;\r\n\r\n/**\r\n * Interface used to configure the node material editor\r\n */\r\nexport interface INodeMaterialEditorOptions {\r\n /** Define the URL to load node editor script from */\r\n editorURL?: string;\r\n /** Additional configuration for the NME */\r\n nodeEditorConfig?: {\r\n backgroundColor?: Color4;\r\n };\r\n}\r\n\r\n/** @internal */\r\nexport class NodeMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {\r\n public NORMAL = false;\r\n public TANGENT = false;\r\n public VERTEXCOLOR_NME = false;\r\n public UV1 = false;\r\n public UV2 = false;\r\n public UV3 = false;\r\n public UV4 = false;\r\n public UV5 = false;\r\n public UV6 = false;\r\n\r\n /** BONES */\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public BONETEXTURE = false;\r\n\r\n /** MORPH TARGETS */\r\n public MORPHTARGETS = false;\r\n public MORPHTARGETS_NORMAL = false;\r\n public MORPHTARGETS_TANGENT = false;\r\n public MORPHTARGETS_UV = false;\r\n public NUM_MORPH_INFLUENCERS = 0;\r\n public MORPHTARGETS_TEXTURE = false;\r\n\r\n /** IMAGE PROCESSING */\r\n public IMAGEPROCESSING = false;\r\n public VIGNETTE = false;\r\n public VIGNETTEBLENDMODEMULTIPLY = false;\r\n public VIGNETTEBLENDMODEOPAQUE = false;\r\n public TONEMAPPING = false;\r\n public TONEMAPPING_ACES = false;\r\n public CONTRAST = false;\r\n public EXPOSURE = false;\r\n public COLORCURVES = false;\r\n public COLORGRADING = false;\r\n public COLORGRADING3D = false;\r\n public SAMPLER3DGREENDEPTH = false;\r\n public SAMPLER3DBGRMAP = false;\r\n public DITHER = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n\r\n /** MISC. */\r\n public BUMPDIRECTUV = 0;\r\n public CAMERA_ORTHOGRAPHIC = false;\r\n public CAMERA_PERSPECTIVE = false;\r\n\r\n constructor() {\r\n super();\r\n this.rebuild();\r\n }\r\n\r\n public setValue(name: string, value: any, markAsUnprocessedIfDirty = false) {\r\n if (this[name] === undefined) {\r\n this._keys.push(name);\r\n }\r\n\r\n if (markAsUnprocessedIfDirty && this[name] !== value) {\r\n this.markAsUnprocessed();\r\n }\r\n\r\n this[name] = value;\r\n }\r\n}\r\n\r\n/**\r\n * Class used to configure NodeMaterial\r\n */\r\nexport interface INodeMaterialOptions {\r\n /**\r\n * Defines if blocks should emit comments\r\n */\r\n emitComments: boolean;\r\n}\r\n\r\n/**\r\n * Blocks that manage a texture\r\n */\r\nexport type NodeMaterialTextureBlocks =\r\n | TextureBlock\r\n | ReflectionTextureBaseBlock\r\n | RefractionBlock\r\n | CurrentScreenBlock\r\n | ParticleTextureBlock\r\n | ImageSourceBlock\r\n | TriPlanarBlock\r\n | BiPlanarBlock;\r\n\r\n/**\r\n * Class used to create a node based material built by assembling shader blocks\r\n */\r\nexport class NodeMaterial extends PushMaterial {\r\n private static _BuildIdGenerator: number = 0;\r\n private _options: INodeMaterialOptions;\r\n private _vertexCompilationState: NodeMaterialBuildState;\r\n private _fragmentCompilationState: NodeMaterialBuildState;\r\n private _sharedData: NodeMaterialBuildStateSharedData;\r\n private _buildId: number = NodeMaterial._BuildIdGenerator++;\r\n private _buildWasSuccessful = false;\r\n private _cachedWorldViewMatrix = new Matrix();\r\n private _cachedWorldViewProjectionMatrix = new Matrix();\r\n private _optimizers = new Array();\r\n private _animationFrame = -1;\r\n\r\n /** Define the Url to load node editor script */\r\n public static EditorURL = `https://unpkg.com/babylonjs-node-editor@${Engine.Version}/babylon.nodeEditor.js`;\r\n\r\n /** Define the Url to load snippets */\r\n public static SnippetUrl = Constants.SnippetUrl;\r\n\r\n /** Gets or sets a boolean indicating that node materials should not deserialize textures from json / snippet content */\r\n public static IgnoreTexturesAtLoadTime = false;\r\n\r\n /**\r\n * Checks if a block is a texture block\r\n * @param block The block to check\r\n * @returns True if the block is a texture block\r\n */\r\n public static _BlockIsTextureBlock(block: NodeMaterialBlock): block is NodeMaterialTextureBlocks {\r\n return (\r\n block.getClassName() === \"TextureBlock\" ||\r\n block.getClassName() === \"ReflectionTextureBaseBlock\" ||\r\n block.getClassName() === \"RefractionBlock\" ||\r\n block.getClassName() === \"CurrentScreenBlock\" ||\r\n block.getClassName() === \"ParticleTextureBlock\" ||\r\n block.getClassName() === \"ImageSourceBlock\" ||\r\n block.getClassName() === \"TriPlanarBlock\" ||\r\n block.getClassName() === \"BiPlanarBlock\"\r\n );\r\n }\r\n\r\n private BJSNODEMATERIALEDITOR = this._getGlobalNodeMaterialEditor();\r\n\r\n /** Get the inspector from bundle or global */\r\n private _getGlobalNodeMaterialEditor(): any {\r\n // UMD Global name detection from Webpack Bundle UMD Name.\r\n if (typeof NODEEDITOR !== \"undefined\") {\r\n return NODEEDITOR;\r\n }\r\n\r\n // In case of module let's check the global emitted from the editor entry point.\r\n if (typeof BABYLON !== \"undefined\" && typeof BABYLON.NodeEditor !== \"undefined\") {\r\n return BABYLON;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Snippet ID if the material was created from the snippet server\r\n */\r\n public snippetId: string;\r\n\r\n /**\r\n * Gets or sets data used by visual editor\r\n * @see https://nme.babylonjs.com\r\n */\r\n public editorData: any = null;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that alpha value must be ignored (This will turn alpha blending off even if an alpha value is produced by the material)\r\n */\r\n @serialize()\r\n public ignoreAlpha = false;\r\n\r\n /**\r\n * Defines the maximum number of lights that can be used in the material\r\n */\r\n @serialize()\r\n public maxSimultaneousLights = 4;\r\n\r\n /**\r\n * Observable raised when the material is built\r\n */\r\n public onBuildObservable = new Observable();\r\n\r\n /**\r\n * Gets or sets the root nodes of the material vertex shader\r\n */\r\n public _vertexOutputNodes = new Array();\r\n\r\n /**\r\n * Gets or sets the root nodes of the material fragment (pixel) shader\r\n */\r\n public _fragmentOutputNodes = new Array();\r\n\r\n /** Gets or sets options to control the node material overall behavior */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n public set options(options: INodeMaterialOptions) {\r\n this._options = options;\r\n }\r\n\r\n /**\r\n * Default configuration related to image processing available in the standard Material.\r\n */\r\n protected _imageProcessingConfiguration: ImageProcessingConfiguration;\r\n\r\n /**\r\n * Gets the image processing configuration used either in this material.\r\n */\r\n public get imageProcessingConfiguration(): ImageProcessingConfiguration {\r\n return this._imageProcessingConfiguration;\r\n }\r\n\r\n /**\r\n * Sets the Default image processing configuration used either in the this material.\r\n *\r\n * If sets to null, the scene one is in use.\r\n */\r\n public set imageProcessingConfiguration(value: ImageProcessingConfiguration) {\r\n this._attachImageProcessingConfiguration(value);\r\n\r\n // Ensure the effect will be rebuilt.\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /**\r\n * Gets an array of blocks that needs to be serialized even if they are not yet connected\r\n */\r\n public attachedBlocks = new Array();\r\n\r\n /**\r\n * Specifies the mode of the node material\r\n * @internal\r\n */\r\n @serialize(\"mode\")\r\n public _mode: NodeMaterialModes = NodeMaterialModes.Material;\r\n\r\n /**\r\n * Gets or sets the mode property\r\n */\r\n public get mode(): NodeMaterialModes {\r\n return this._mode;\r\n }\r\n\r\n public set mode(value: NodeMaterialModes) {\r\n this._mode = value;\r\n }\r\n\r\n /** Gets or sets the unique identifier used to identified the effect associated with the material */\r\n public get buildId() {\r\n return this._buildId;\r\n }\r\n\r\n public set buildId(value: number) {\r\n this._buildId = value;\r\n }\r\n\r\n /**\r\n * A free comment about the material\r\n */\r\n @serialize(\"comment\")\r\n public comment: string;\r\n\r\n /**\r\n * Create a new node based material\r\n * @param name defines the material name\r\n * @param scene defines the hosting scene\r\n * @param options defines creation option\r\n */\r\n constructor(name: string, scene?: Scene, options: Partial = {}) {\r\n super(name, scene || EngineStore.LastCreatedScene!);\r\n\r\n this._options = {\r\n emitComments: false,\r\n ...options,\r\n };\r\n\r\n // Setup the default processing configuration to the scene.\r\n this._attachImageProcessingConfiguration(null);\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"NodeMaterial\"\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"NodeMaterial\";\r\n }\r\n\r\n /**\r\n * Keep track of the image processing observer to allow dispose and replace.\r\n */\r\n private _imageProcessingObserver: Nullable>;\r\n\r\n /**\r\n * Attaches a new image processing configuration to the Standard Material.\r\n * @param configuration\r\n */\r\n protected _attachImageProcessingConfiguration(configuration: Nullable): void {\r\n if (configuration === this._imageProcessingConfiguration) {\r\n return;\r\n }\r\n\r\n // Detaches observer.\r\n if (this._imageProcessingConfiguration && this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n }\r\n\r\n // Pick the scene configuration if needed.\r\n if (!configuration) {\r\n this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;\r\n } else {\r\n this._imageProcessingConfiguration = configuration;\r\n }\r\n\r\n // Attaches observer.\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(() => {\r\n this._markAllSubMeshesAsImageProcessingDirty();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Get a block by its name\r\n * @param name defines the name of the block to retrieve\r\n * @returns the required block or null if not found\r\n */\r\n public getBlockByName(name: string) {\r\n let result = null;\r\n for (const block of this.attachedBlocks) {\r\n if (block.name === name) {\r\n if (!result) {\r\n result = block;\r\n } else {\r\n Tools.Warn(\"More than one block was found with the name `\" + name + \"`\");\r\n return result;\r\n }\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Get a block by its name\r\n * @param predicate defines the predicate used to find the good candidate\r\n * @returns the required block or null if not found\r\n */\r\n public getBlockByPredicate(predicate: (block: NodeMaterialBlock) => boolean) {\r\n for (const block of this.attachedBlocks) {\r\n if (predicate(block)) {\r\n return block;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Get an input block by its name\r\n * @param predicate defines the predicate used to find the good candidate\r\n * @returns the required input block or null if not found\r\n */\r\n public getInputBlockByPredicate(predicate: (block: InputBlock) => boolean): Nullable {\r\n for (const block of this.attachedBlocks) {\r\n if (block.isInput && predicate(block as InputBlock)) {\r\n return block as InputBlock;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets the list of input blocks attached to this material\r\n * @returns an array of InputBlocks\r\n */\r\n public getInputBlocks() {\r\n const blocks: InputBlock[] = [];\r\n for (const block of this.attachedBlocks) {\r\n if (block.isInput) {\r\n blocks.push(block as InputBlock);\r\n }\r\n }\r\n\r\n return blocks;\r\n }\r\n\r\n /**\r\n * Adds a new optimizer to the list of optimizers\r\n * @param optimizer defines the optimizers to add\r\n * @returns the current material\r\n */\r\n public registerOptimizer(optimizer: NodeMaterialOptimizer) {\r\n const index = this._optimizers.indexOf(optimizer);\r\n\r\n if (index > -1) {\r\n return;\r\n }\r\n\r\n this._optimizers.push(optimizer);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove an optimizer from the list of optimizers\r\n * @param optimizer defines the optimizers to remove\r\n * @returns the current material\r\n */\r\n public unregisterOptimizer(optimizer: NodeMaterialOptimizer) {\r\n const index = this._optimizers.indexOf(optimizer);\r\n\r\n if (index === -1) {\r\n return;\r\n }\r\n\r\n this._optimizers.splice(index, 1);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Add a new block to the list of output nodes\r\n * @param node defines the node to add\r\n * @returns the current material\r\n */\r\n public addOutputNode(node: NodeMaterialBlock) {\r\n if (node.target === null) {\r\n throw \"This node is not meant to be an output node. You may want to explicitly set its target value.\";\r\n }\r\n\r\n if ((node.target & NodeMaterialBlockTargets.Vertex) !== 0) {\r\n this._addVertexOutputNode(node);\r\n }\r\n\r\n if ((node.target & NodeMaterialBlockTargets.Fragment) !== 0) {\r\n this._addFragmentOutputNode(node);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a block from the list of root nodes\r\n * @param node defines the node to remove\r\n * @returns the current material\r\n */\r\n public removeOutputNode(node: NodeMaterialBlock) {\r\n if (node.target === null) {\r\n return this;\r\n }\r\n\r\n if ((node.target & NodeMaterialBlockTargets.Vertex) !== 0) {\r\n this._removeVertexOutputNode(node);\r\n }\r\n\r\n if ((node.target & NodeMaterialBlockTargets.Fragment) !== 0) {\r\n this._removeFragmentOutputNode(node);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n private _addVertexOutputNode(node: NodeMaterialBlock) {\r\n if (this._vertexOutputNodes.indexOf(node) !== -1) {\r\n return;\r\n }\r\n\r\n node.target = NodeMaterialBlockTargets.Vertex;\r\n this._vertexOutputNodes.push(node);\r\n\r\n return this;\r\n }\r\n\r\n private _removeVertexOutputNode(node: NodeMaterialBlock) {\r\n const index = this._vertexOutputNodes.indexOf(node);\r\n if (index === -1) {\r\n return;\r\n }\r\n\r\n this._vertexOutputNodes.splice(index, 1);\r\n\r\n return this;\r\n }\r\n\r\n private _addFragmentOutputNode(node: NodeMaterialBlock) {\r\n if (this._fragmentOutputNodes.indexOf(node) !== -1) {\r\n return;\r\n }\r\n\r\n node.target = NodeMaterialBlockTargets.Fragment;\r\n this._fragmentOutputNodes.push(node);\r\n\r\n return this;\r\n }\r\n\r\n private _removeFragmentOutputNode(node: NodeMaterialBlock) {\r\n const index = this._fragmentOutputNodes.indexOf(node);\r\n if (index === -1) {\r\n return;\r\n }\r\n\r\n this._fragmentOutputNodes.splice(index, 1);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating that alpha blending must be enabled no matter what alpha value or alpha channel of the FragmentBlock are\r\n */\r\n @serialize()\r\n public forceAlphaBlending = false;\r\n\r\n /**\r\n * Specifies if the material will require alpha blending\r\n * @returns a boolean specifying if alpha blending is needed\r\n */\r\n public needAlphaBlending(): boolean {\r\n if (this.ignoreAlpha) {\r\n return false;\r\n }\r\n return this.forceAlphaBlending || this.alpha < 1.0 || (this._sharedData && this._sharedData.hints.needAlphaBlending);\r\n }\r\n\r\n /**\r\n * Specifies if this material should be rendered in alpha test mode\r\n * @returns a boolean specifying if an alpha test is needed.\r\n */\r\n public needAlphaTesting(): boolean {\r\n return this._sharedData && this._sharedData.hints.needAlphaTesting;\r\n }\r\n\r\n private _processInitializeOnLink(block: NodeMaterialBlock, state: NodeMaterialBuildState, nodesToProcessForOtherBuildState: NodeMaterialBlock[], autoConfigure = true) {\r\n if (block.target === NodeMaterialBlockTargets.VertexAndFragment) {\r\n nodesToProcessForOtherBuildState.push(block);\r\n } else if (state.target === NodeMaterialBlockTargets.Fragment && block.target === NodeMaterialBlockTargets.Vertex && block._preparationId !== this._buildId) {\r\n nodesToProcessForOtherBuildState.push(block);\r\n }\r\n this._initializeBlock(block, state, nodesToProcessForOtherBuildState, autoConfigure);\r\n }\r\n\r\n private _initializeBlock(node: NodeMaterialBlock, state: NodeMaterialBuildState, nodesToProcessForOtherBuildState: NodeMaterialBlock[], autoConfigure = true) {\r\n node.initialize(state);\r\n if (autoConfigure) {\r\n node.autoConfigure(this);\r\n }\r\n node._preparationId = this._buildId;\r\n\r\n if (this.attachedBlocks.indexOf(node) === -1) {\r\n if (node.isUnique) {\r\n const className = node.getClassName();\r\n\r\n for (const other of this.attachedBlocks) {\r\n if (other.getClassName() === className) {\r\n throw `Cannot have multiple blocks of type ${className} in the same NodeMaterial`;\r\n }\r\n }\r\n }\r\n this.attachedBlocks.push(node);\r\n }\r\n\r\n for (const input of node.inputs) {\r\n input.associatedVariableName = \"\";\r\n\r\n const connectedPoint = input.connectedPoint;\r\n if (connectedPoint) {\r\n const block = connectedPoint.ownerBlock;\r\n if (block !== node) {\r\n this._processInitializeOnLink(block, state, nodesToProcessForOtherBuildState, autoConfigure);\r\n }\r\n }\r\n }\r\n\r\n // Teleportation\r\n if (node.isTeleportOut) {\r\n const teleport = node as NodeMaterialTeleportOutBlock;\r\n if (teleport.entryPoint) {\r\n this._processInitializeOnLink(teleport.entryPoint, state, nodesToProcessForOtherBuildState, autoConfigure);\r\n }\r\n }\r\n\r\n for (const output of node.outputs) {\r\n output.associatedVariableName = \"\";\r\n }\r\n }\r\n\r\n private _resetDualBlocks(node: NodeMaterialBlock, id: number) {\r\n if (node.target === NodeMaterialBlockTargets.VertexAndFragment) {\r\n node.buildId = id;\r\n }\r\n\r\n for (const inputs of node.inputs) {\r\n const connectedPoint = inputs.connectedPoint;\r\n if (connectedPoint) {\r\n const block = connectedPoint.ownerBlock;\r\n if (block !== node) {\r\n this._resetDualBlocks(block, id);\r\n }\r\n }\r\n }\r\n\r\n // If this is a teleport out, we need to reset the connected block\r\n if (node.isTeleportOut) {\r\n const teleportOut = node as NodeMaterialTeleportOutBlock;\r\n if (teleportOut.entryPoint) {\r\n this._resetDualBlocks(teleportOut.entryPoint, id);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Remove a block from the current node material\r\n * @param block defines the block to remove\r\n */\r\n public removeBlock(block: NodeMaterialBlock) {\r\n const attachedBlockIndex = this.attachedBlocks.indexOf(block);\r\n if (attachedBlockIndex > -1) {\r\n this.attachedBlocks.splice(attachedBlockIndex, 1);\r\n }\r\n\r\n if (block.isFinalMerger) {\r\n this.removeOutputNode(block);\r\n }\r\n }\r\n\r\n /**\r\n * Build the material and generates the inner effect\r\n * @param verbose defines if the build should log activity\r\n * @param updateBuildId defines if the internal build Id should be updated (default is true)\r\n * @param autoConfigure defines if the autoConfigure method should be called when initializing blocks (default is true)\r\n */\r\n public build(verbose: boolean = false, updateBuildId = true, autoConfigure = true) {\r\n this._buildWasSuccessful = false;\r\n const engine = this.getScene().getEngine();\r\n\r\n const allowEmptyVertexProgram = this._mode === NodeMaterialModes.Particle;\r\n\r\n if (this._vertexOutputNodes.length === 0 && !allowEmptyVertexProgram) {\r\n throw \"You must define at least one vertexOutputNode\";\r\n }\r\n\r\n if (this._fragmentOutputNodes.length === 0) {\r\n throw \"You must define at least one fragmentOutputNode\";\r\n }\r\n\r\n // Compilation state\r\n this._vertexCompilationState = new NodeMaterialBuildState();\r\n this._vertexCompilationState.supportUniformBuffers = engine.supportsUniformBuffers;\r\n this._vertexCompilationState.target = NodeMaterialBlockTargets.Vertex;\r\n this._fragmentCompilationState = new NodeMaterialBuildState();\r\n this._fragmentCompilationState.supportUniformBuffers = engine.supportsUniformBuffers;\r\n this._fragmentCompilationState.target = NodeMaterialBlockTargets.Fragment;\r\n\r\n // Shared data\r\n this._sharedData = new NodeMaterialBuildStateSharedData();\r\n this._sharedData.fragmentOutputNodes = this._fragmentOutputNodes;\r\n this._vertexCompilationState.sharedData = this._sharedData;\r\n this._fragmentCompilationState.sharedData = this._sharedData;\r\n this._sharedData.buildId = this._buildId;\r\n this._sharedData.emitComments = this._options.emitComments;\r\n this._sharedData.verbose = verbose;\r\n this._sharedData.scene = this.getScene();\r\n this._sharedData.allowEmptyVertexProgram = allowEmptyVertexProgram;\r\n\r\n // Initialize blocks\r\n const vertexNodes: NodeMaterialBlock[] = [];\r\n const fragmentNodes: NodeMaterialBlock[] = [];\r\n\r\n for (const vertexOutputNode of this._vertexOutputNodes) {\r\n vertexNodes.push(vertexOutputNode);\r\n this._initializeBlock(vertexOutputNode, this._vertexCompilationState, fragmentNodes, autoConfigure);\r\n }\r\n\r\n for (const fragmentOutputNode of this._fragmentOutputNodes) {\r\n fragmentNodes.push(fragmentOutputNode);\r\n this._initializeBlock(fragmentOutputNode, this._fragmentCompilationState, vertexNodes, autoConfigure);\r\n }\r\n\r\n // Optimize\r\n this.optimize();\r\n\r\n // Vertex\r\n for (const vertexOutputNode of vertexNodes) {\r\n vertexOutputNode.build(this._vertexCompilationState, vertexNodes);\r\n }\r\n\r\n // Fragment\r\n this._fragmentCompilationState.uniforms = this._vertexCompilationState.uniforms.slice(0);\r\n this._fragmentCompilationState._uniformDeclaration = this._vertexCompilationState._uniformDeclaration;\r\n this._fragmentCompilationState._constantDeclaration = this._vertexCompilationState._constantDeclaration;\r\n this._fragmentCompilationState._vertexState = this._vertexCompilationState;\r\n\r\n for (const fragmentOutputNode of fragmentNodes) {\r\n this._resetDualBlocks(fragmentOutputNode, this._buildId - 1);\r\n }\r\n\r\n for (const fragmentOutputNode of fragmentNodes) {\r\n fragmentOutputNode.build(this._fragmentCompilationState, fragmentNodes);\r\n }\r\n\r\n // Finalize\r\n this._vertexCompilationState.finalize(this._vertexCompilationState);\r\n this._fragmentCompilationState.finalize(this._fragmentCompilationState);\r\n\r\n if (updateBuildId) {\r\n this._buildId = NodeMaterial._BuildIdGenerator++;\r\n }\r\n\r\n // Errors\r\n this._sharedData.emitErrors();\r\n\r\n if (verbose) {\r\n console.log(\"Vertex shader:\");\r\n console.log(this._vertexCompilationState.compilationString);\r\n console.log(\"Fragment shader:\");\r\n console.log(this._fragmentCompilationState.compilationString);\r\n }\r\n\r\n this._buildWasSuccessful = true;\r\n this.onBuildObservable.notifyObservers(this);\r\n\r\n // Wipe defines\r\n const meshes = this.getScene().meshes;\r\n for (const mesh of meshes) {\r\n if (!mesh.subMeshes) {\r\n continue;\r\n }\r\n for (const subMesh of mesh.subMeshes) {\r\n if (subMesh.getMaterial() !== this) {\r\n continue;\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n continue;\r\n }\r\n\r\n const defines = subMesh.materialDefines;\r\n defines.markAllAsDirty();\r\n defines.reset();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Runs an otpimization phase to try to improve the shader code\r\n */\r\n public optimize() {\r\n for (const optimizer of this._optimizers) {\r\n optimizer.optimize(this._vertexOutputNodes, this._fragmentOutputNodes);\r\n }\r\n }\r\n\r\n private _prepareDefinesForAttributes(mesh: AbstractMesh, defines: NodeMaterialDefines) {\r\n const oldNormal = defines[\"NORMAL\"];\r\n const oldTangent = defines[\"TANGENT\"];\r\n const oldColor = defines[\"VERTEXCOLOR_NME\"];\r\n\r\n defines[\"NORMAL\"] = mesh.isVerticesDataPresent(VertexBuffer.NormalKind);\r\n defines[\"TANGENT\"] = mesh.isVerticesDataPresent(VertexBuffer.TangentKind);\r\n\r\n const hasVertexColors = mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind);\r\n defines[\"VERTEXCOLOR_NME\"] = hasVertexColors;\r\n\r\n let uvChanged = false;\r\n for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {\r\n const oldUV = defines[\"UV\" + i];\r\n defines[\"UV\" + i] = mesh.isVerticesDataPresent(`uv${i === 1 ? \"\" : i}`);\r\n uvChanged = uvChanged || defines[\"UV\" + i] !== oldUV;\r\n }\r\n\r\n if (oldNormal !== defines[\"NORMAL\"] || oldTangent !== defines[\"TANGENT\"] || oldColor !== defines[\"VERTEXCOLOR_NME\"] || uvChanged) {\r\n defines.markAsAttributesDirty();\r\n }\r\n }\r\n\r\n /**\r\n * Create a post process from the material\r\n * @param camera The camera to apply the render pass to.\r\n * @param options The required width/height ratio to downsize to before computing the render pass. (Use 1.0 for full size)\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)\r\n * @param engine The engine which the post process will be applied. (default: current engine)\r\n * @param reusable If the post process can be reused on the same frame. (default: false)\r\n * @param textureType Type of textures used when performing the post process. (default: 0)\r\n * @param textureFormat Format of textures used when performing the post process. (default: TEXTUREFORMAT_RGBA)\r\n * @returns the post process created\r\n */\r\n public createPostProcess(\r\n camera: Nullable,\r\n options: number | PostProcessOptions = 1,\r\n samplingMode: number = Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n textureFormat = Constants.TEXTUREFORMAT_RGBA\r\n ): Nullable {\r\n if (this.mode !== NodeMaterialModes.PostProcess) {\r\n console.log(\"Incompatible material mode\");\r\n return null;\r\n }\r\n return this._createEffectForPostProcess(null, camera, options, samplingMode, engine, reusable, textureType, textureFormat);\r\n }\r\n\r\n /**\r\n * Create the post process effect from the material\r\n * @param postProcess The post process to create the effect for\r\n */\r\n public createEffectForPostProcess(postProcess: PostProcess) {\r\n this._createEffectForPostProcess(postProcess);\r\n }\r\n\r\n private _createEffectForPostProcess(\r\n postProcess: Nullable,\r\n camera?: Nullable,\r\n options: number | PostProcessOptions = 1,\r\n samplingMode: number = Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n textureFormat = Constants.TEXTUREFORMAT_RGBA\r\n ): PostProcess {\r\n let tempName = this.name + this._buildId;\r\n\r\n const defines = new NodeMaterialDefines();\r\n\r\n const dummyMesh = new AbstractMesh(tempName + \"PostProcess\", this.getScene());\r\n\r\n let buildId = this._buildId;\r\n\r\n this._processDefines(dummyMesh, defines);\r\n\r\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\r\n\r\n if (!postProcess) {\r\n postProcess = new PostProcess(\r\n this.name + \"PostProcess\",\r\n tempName,\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n options,\r\n camera!,\r\n samplingMode,\r\n engine,\r\n reusable,\r\n defines.toString(),\r\n textureType,\r\n tempName,\r\n { maxSimultaneousLights: this.maxSimultaneousLights },\r\n false,\r\n textureFormat\r\n );\r\n } else {\r\n postProcess.updateEffect(\r\n defines.toString(),\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n { maxSimultaneousLights: this.maxSimultaneousLights },\r\n undefined,\r\n undefined,\r\n tempName,\r\n tempName\r\n );\r\n }\r\n\r\n postProcess.nodeMaterialSource = this;\r\n\r\n postProcess.onApplyObservable.add((effect) => {\r\n if (buildId !== this._buildId) {\r\n delete Effect.ShadersStore[tempName + \"VertexShader\"];\r\n delete Effect.ShadersStore[tempName + \"PixelShader\"];\r\n\r\n tempName = this.name + this._buildId;\r\n\r\n defines.markAllAsDirty();\r\n\r\n buildId = this._buildId;\r\n }\r\n\r\n const result = this._processDefines(dummyMesh, defines);\r\n\r\n if (result) {\r\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\r\n\r\n TimingTools.SetImmediate(() =>\r\n postProcess!.updateEffect(\r\n defines.toString(),\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n { maxSimultaneousLights: this.maxSimultaneousLights },\r\n undefined,\r\n undefined,\r\n tempName,\r\n tempName\r\n )\r\n );\r\n }\r\n\r\n this._checkInternals(effect);\r\n });\r\n\r\n return postProcess;\r\n }\r\n\r\n /**\r\n * Create a new procedural texture based on this node material\r\n * @param size defines the size of the texture\r\n * @param scene defines the hosting scene\r\n * @returns the new procedural texture attached to this node material\r\n */\r\n public createProceduralTexture(size: number | { width: number; height: number; layers?: number }, scene: Scene): Nullable {\r\n if (this.mode !== NodeMaterialModes.ProceduralTexture) {\r\n console.log(\"Incompatible material mode\");\r\n return null;\r\n }\r\n\r\n let tempName = this.name + this._buildId;\r\n\r\n const proceduralTexture = new ProceduralTexture(tempName, size, null, scene);\r\n\r\n const dummyMesh = new AbstractMesh(tempName + \"Procedural\", this.getScene());\r\n dummyMesh.reservedDataStore = {\r\n hidden: true,\r\n };\r\n\r\n const defines = new NodeMaterialDefines();\r\n const result = this._processDefines(dummyMesh, defines);\r\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\r\n\r\n let effect = this.getScene().getEngine().createEffect(\r\n {\r\n vertexElement: tempName,\r\n fragmentElement: tempName,\r\n },\r\n [VertexBuffer.PositionKind],\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n defines.toString(),\r\n result?.fallbacks,\r\n undefined\r\n );\r\n\r\n proceduralTexture.nodeMaterialSource = this;\r\n proceduralTexture._setEffect(effect);\r\n\r\n let buildId = this._buildId;\r\n proceduralTexture.onBeforeGenerationObservable.add(() => {\r\n if (buildId !== this._buildId) {\r\n delete Effect.ShadersStore[tempName + \"VertexShader\"];\r\n delete Effect.ShadersStore[tempName + \"PixelShader\"];\r\n\r\n tempName = this.name + this._buildId;\r\n\r\n defines.markAllAsDirty();\r\n\r\n buildId = this._buildId;\r\n }\r\n\r\n const result = this._processDefines(dummyMesh, defines);\r\n\r\n if (result) {\r\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString, this._vertexCompilationState._builtCompilationString);\r\n\r\n TimingTools.SetImmediate(() => {\r\n effect = this.getScene().getEngine().createEffect(\r\n {\r\n vertexElement: tempName,\r\n fragmentElement: tempName,\r\n },\r\n [VertexBuffer.PositionKind],\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n defines.toString(),\r\n result?.fallbacks,\r\n undefined\r\n );\r\n\r\n proceduralTexture._setEffect(effect);\r\n });\r\n }\r\n\r\n this._checkInternals(effect);\r\n });\r\n\r\n return proceduralTexture;\r\n }\r\n\r\n private _createEffectForParticles(\r\n particleSystem: IParticleSystem,\r\n blendMode: number,\r\n onCompiled?: (effect: Effect) => void,\r\n onError?: (effect: Effect, errors: string) => void,\r\n effect?: Effect,\r\n defines?: NodeMaterialDefines,\r\n dummyMesh?: Nullable,\r\n particleSystemDefinesJoined = \"\"\r\n ) {\r\n let tempName = this.name + this._buildId + \"_\" + blendMode;\r\n\r\n if (!defines) {\r\n defines = new NodeMaterialDefines();\r\n }\r\n\r\n if (!dummyMesh) {\r\n dummyMesh = this.getScene().getMeshByName(this.name + \"Particle\");\r\n if (!dummyMesh) {\r\n dummyMesh = new AbstractMesh(this.name + \"Particle\", this.getScene());\r\n dummyMesh.reservedDataStore = {\r\n hidden: true,\r\n };\r\n }\r\n }\r\n\r\n let buildId = this._buildId;\r\n\r\n const particleSystemDefines: Array = [];\r\n let join = particleSystemDefinesJoined;\r\n\r\n if (!effect) {\r\n const result = this._processDefines(dummyMesh, defines);\r\n\r\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString);\r\n\r\n particleSystem.fillDefines(particleSystemDefines, blendMode);\r\n\r\n join = particleSystemDefines.join(\"\\n\");\r\n\r\n effect = this.getScene()\r\n .getEngine()\r\n .createEffectForParticles(\r\n tempName,\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n defines.toString() + \"\\n\" + join,\r\n result?.fallbacks,\r\n onCompiled,\r\n onError,\r\n particleSystem\r\n );\r\n\r\n particleSystem.setCustomEffect(effect, blendMode);\r\n }\r\n\r\n effect.onBindObservable.add((effect) => {\r\n if (buildId !== this._buildId) {\r\n delete Effect.ShadersStore[tempName + \"PixelShader\"];\r\n\r\n tempName = this.name + this._buildId + \"_\" + blendMode;\r\n\r\n defines!.markAllAsDirty();\r\n\r\n buildId = this._buildId;\r\n }\r\n\r\n particleSystemDefines.length = 0;\r\n\r\n particleSystem.fillDefines(particleSystemDefines, blendMode);\r\n\r\n const particleSystemDefinesJoinedCurrent = particleSystemDefines.join(\"\\n\");\r\n\r\n if (particleSystemDefinesJoinedCurrent !== join) {\r\n defines!.markAllAsDirty();\r\n join = particleSystemDefinesJoinedCurrent;\r\n }\r\n\r\n const result = this._processDefines(dummyMesh!, defines!);\r\n\r\n if (result) {\r\n Effect.RegisterShader(tempName, this._fragmentCompilationState._builtCompilationString);\r\n\r\n effect = this.getScene()\r\n .getEngine()\r\n .createEffectForParticles(\r\n tempName,\r\n this._fragmentCompilationState.uniforms,\r\n this._fragmentCompilationState.samplers,\r\n defines!.toString() + \"\\n\" + join,\r\n result?.fallbacks,\r\n onCompiled,\r\n onError,\r\n particleSystem\r\n );\r\n particleSystem.setCustomEffect(effect, blendMode);\r\n this._createEffectForParticles(particleSystem, blendMode, onCompiled, onError, effect, defines, dummyMesh, particleSystemDefinesJoined); // add the effect.onBindObservable observer\r\n return;\r\n }\r\n\r\n this._checkInternals(effect);\r\n });\r\n }\r\n\r\n private _checkInternals(effect: Effect) {\r\n // Animated blocks\r\n if (this._sharedData.animatedInputs) {\r\n const scene = this.getScene();\r\n\r\n const frameId = scene.getFrameId();\r\n\r\n if (this._animationFrame !== frameId) {\r\n for (const input of this._sharedData.animatedInputs) {\r\n input.animate(scene);\r\n }\r\n\r\n this._animationFrame = frameId;\r\n }\r\n }\r\n\r\n // Bindable blocks\r\n for (const block of this._sharedData.bindableBlocks) {\r\n block.bind(effect, this);\r\n }\r\n\r\n // Connection points\r\n for (const inputBlock of this._sharedData.inputBlocks) {\r\n inputBlock._transmit(effect, this.getScene(), this);\r\n }\r\n }\r\n\r\n /**\r\n * Create the effect to be used as the custom effect for a particle system\r\n * @param particleSystem Particle system to create the effect for\r\n * @param onCompiled defines a function to call when the effect creation is successful\r\n * @param onError defines a function to call when the effect creation has failed\r\n */\r\n public createEffectForParticles(particleSystem: IParticleSystem, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void) {\r\n if (this.mode !== NodeMaterialModes.Particle) {\r\n console.log(\"Incompatible material mode\");\r\n return;\r\n }\r\n\r\n this._createEffectForParticles(particleSystem, BaseParticleSystem.BLENDMODE_ONEONE, onCompiled, onError);\r\n this._createEffectForParticles(particleSystem, BaseParticleSystem.BLENDMODE_MULTIPLY, onCompiled, onError);\r\n }\r\n\r\n /**\r\n * Use this material as the shadow depth wrapper of a target material\r\n * @param targetMaterial defines the target material\r\n */\r\n public createAsShadowDepthWrapper(targetMaterial: Material) {\r\n if (this.mode !== NodeMaterialModes.Material) {\r\n console.log(\"Incompatible material mode\");\r\n return;\r\n }\r\n\r\n targetMaterial.shadowDepthWrapper = new BABYLON.ShadowDepthWrapper(this, this.getScene());\r\n }\r\n\r\n private _processDefines(\r\n mesh: AbstractMesh,\r\n defines: NodeMaterialDefines,\r\n useInstances = false,\r\n subMesh?: SubMesh\r\n ): Nullable<{\r\n lightDisposed: boolean;\r\n uniformBuffers: string[];\r\n mergedUniforms: string[];\r\n mergedSamplers: string[];\r\n fallbacks: EffectFallbacks;\r\n }> {\r\n let result = null;\r\n\r\n // Global defines\r\n const scene = this.getScene();\r\n if (MaterialHelper.PrepareDefinesForCamera(scene, defines)) {\r\n defines.markAsMiscDirty();\r\n }\r\n\r\n // Shared defines\r\n this._sharedData.blocksWithDefines.forEach((b) => {\r\n b.initializeDefines(mesh, this, defines, useInstances);\r\n });\r\n\r\n this._sharedData.blocksWithDefines.forEach((b) => {\r\n b.prepareDefines(mesh, this, defines, useInstances, subMesh);\r\n });\r\n\r\n // Need to recompile?\r\n if (defines.isDirty) {\r\n const lightDisposed = defines._areLightsDisposed;\r\n defines.markAsProcessed();\r\n\r\n // Repeatable content generators\r\n this._vertexCompilationState.compilationString = this._vertexCompilationState._builtCompilationString;\r\n this._fragmentCompilationState.compilationString = this._fragmentCompilationState._builtCompilationString;\r\n\r\n this._sharedData.repeatableContentBlocks.forEach((b) => {\r\n b.replaceRepeatableContent(this._vertexCompilationState, this._fragmentCompilationState, mesh, defines);\r\n });\r\n\r\n // Uniforms\r\n const uniformBuffers: string[] = [];\r\n this._sharedData.dynamicUniformBlocks.forEach((b) => {\r\n b.updateUniformsAndSamples(this._vertexCompilationState, this, defines, uniformBuffers);\r\n });\r\n\r\n const mergedUniforms = this._vertexCompilationState.uniforms;\r\n\r\n this._fragmentCompilationState.uniforms.forEach((u) => {\r\n const index = mergedUniforms.indexOf(u);\r\n\r\n if (index === -1) {\r\n mergedUniforms.push(u);\r\n }\r\n });\r\n\r\n // Samplers\r\n const mergedSamplers = this._vertexCompilationState.samplers;\r\n\r\n this._fragmentCompilationState.samplers.forEach((s) => {\r\n const index = mergedSamplers.indexOf(s);\r\n\r\n if (index === -1) {\r\n mergedSamplers.push(s);\r\n }\r\n });\r\n\r\n const fallbacks = new EffectFallbacks();\r\n\r\n this._sharedData.blocksWithFallbacks.forEach((b) => {\r\n b.provideFallbacks(mesh, fallbacks);\r\n });\r\n\r\n result = {\r\n lightDisposed,\r\n uniformBuffers,\r\n mergedUniforms,\r\n mergedSamplers,\r\n fallbacks,\r\n };\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Get if the submesh is ready to be used and all its information available.\r\n * Child classes can use it to update shaders\r\n * @param mesh defines the mesh to check\r\n * @param subMesh defines which submesh to check\r\n * @param useInstances specifies that instances should be used\r\n * @returns a boolean indicating that the submesh is ready or not\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances: boolean = false): boolean {\r\n if (!this._buildWasSuccessful) {\r\n return false;\r\n }\r\n\r\n const scene = this.getScene();\r\n if (this._sharedData.animatedInputs) {\r\n const frameId = scene.getFrameId();\r\n\r\n if (this._animationFrame !== frameId) {\r\n for (const input of this._sharedData.animatedInputs) {\r\n input.animate(scene);\r\n }\r\n\r\n this._animationFrame = frameId;\r\n }\r\n }\r\n\r\n if (subMesh.effect && this.isFrozen) {\r\n if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n subMesh.materialDefines = new NodeMaterialDefines();\r\n }\r\n\r\n const defines = subMesh.materialDefines;\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n this._prepareDefinesForAttributes(mesh, defines);\r\n\r\n // Check if blocks are ready\r\n if (this._sharedData.blockingBlocks.some((b) => !b.isReady(mesh, this, defines, useInstances))) {\r\n return false;\r\n }\r\n\r\n const result = this._processDefines(mesh, defines, useInstances, subMesh);\r\n\r\n if (result) {\r\n const previousEffect = subMesh.effect;\r\n // Compilation\r\n const join = defines.toString();\r\n let effect = engine.createEffect(\r\n {\r\n vertex: \"nodeMaterial\" + this._buildId,\r\n fragment: \"nodeMaterial\" + this._buildId,\r\n vertexSource: this._vertexCompilationState.compilationString,\r\n fragmentSource: this._fragmentCompilationState.compilationString,\r\n },\r\n {\r\n attributes: this._vertexCompilationState.attributes,\r\n uniformsNames: result.mergedUniforms,\r\n uniformBuffersNames: result.uniformBuffers,\r\n samplers: result.mergedSamplers,\r\n defines: join,\r\n fallbacks: result.fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS },\r\n },\r\n engine\r\n );\r\n\r\n if (effect) {\r\n if (this._onEffectCreatedObservable) {\r\n onCreatedEffectParameters.effect = effect;\r\n onCreatedEffectParameters.subMesh = subMesh;\r\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);\r\n }\r\n\r\n // Use previous effect while new one is compiling\r\n if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {\r\n effect = previousEffect;\r\n defines.markAsUnprocessed();\r\n\r\n if (result.lightDisposed) {\r\n // re register in case it takes more than one frame.\r\n defines._areLightsDisposed = true;\r\n return false;\r\n }\r\n } else {\r\n scene.resetCachedMaterial();\r\n subMesh.setEffect(effect, defines, this._materialContext);\r\n }\r\n }\r\n }\r\n\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = true;\r\n subMesh.effect._wasPreviouslyUsingInstances = useInstances;\r\n\r\n this._checkScenePerformancePriority();\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Get a string representing the shaders built by the current node graph\r\n */\r\n public get compiledShaders() {\r\n return `// Vertex shader\\n${this._vertexCompilationState.compilationString}\\n\\n// Fragment shader\\n${this._fragmentCompilationState.compilationString}`;\r\n }\r\n\r\n /**\r\n * Binds the world matrix to the material\r\n * @param world defines the world transformation matrix\r\n */\r\n public bindOnlyWorldMatrix(world: Matrix): void {\r\n const scene = this.getScene();\r\n\r\n if (!this._activeEffect) {\r\n return;\r\n }\r\n\r\n const hints = this._sharedData.hints;\r\n\r\n if (hints.needWorldViewMatrix) {\r\n world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);\r\n }\r\n\r\n if (hints.needWorldViewProjectionMatrix) {\r\n world.multiplyToRef(scene.getTransformMatrix(), this._cachedWorldViewProjectionMatrix);\r\n }\r\n\r\n // Connection points\r\n for (const inputBlock of this._sharedData.inputBlocks) {\r\n inputBlock._transmitWorld(this._activeEffect, world, this._cachedWorldViewMatrix, this._cachedWorldViewProjectionMatrix);\r\n }\r\n }\r\n\r\n /**\r\n * Binds the submesh to this material by preparing the effect and shader to draw\r\n * @param world defines the world transformation matrix\r\n * @param mesh defines the mesh containing the submesh\r\n * @param subMesh defines the submesh to bind the material to\r\n */\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n this._activeEffect = effect;\r\n\r\n // Matrices\r\n this.bindOnlyWorldMatrix(world);\r\n\r\n const mustRebind = this._mustRebind(scene, effect, mesh.visibility);\r\n const sharedData = this._sharedData;\r\n\r\n if (mustRebind) {\r\n // Bindable blocks\r\n for (const block of sharedData.bindableBlocks) {\r\n block.bind(effect, this, mesh, subMesh);\r\n }\r\n\r\n for (const block of sharedData.forcedBindableBlocks) {\r\n block.bind(effect, this, mesh, subMesh);\r\n }\r\n\r\n // Connection points\r\n for (const inputBlock of sharedData.inputBlocks) {\r\n inputBlock._transmit(effect, scene, this);\r\n }\r\n } else if (!this.isFrozen) {\r\n for (const block of sharedData.forcedBindableBlocks) {\r\n block.bind(effect, this, mesh, subMesh);\r\n }\r\n }\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n }\r\n\r\n /**\r\n * Gets the active textures from the material\r\n * @returns an array of textures\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n const activeTextures = super.getActiveTextures();\r\n\r\n if (this._sharedData) {\r\n activeTextures.push(...this._sharedData.textureBlocks.filter((tb) => tb.texture).map((tb) => tb.texture!));\r\n }\r\n\r\n return activeTextures;\r\n }\r\n\r\n /**\r\n * Gets the list of texture blocks\r\n * Note that this method will only return blocks that are reachable from the final block(s) and only after the material has been built!\r\n * @returns an array of texture blocks\r\n */\r\n public getTextureBlocks(): NodeMaterialTextureBlocks[] {\r\n if (!this._sharedData) {\r\n return [];\r\n }\r\n\r\n return this._sharedData.textureBlocks;\r\n }\r\n\r\n /**\r\n * Gets the list of all texture blocks\r\n * Note that this method will scan all attachedBlocks and return blocks that are texture blocks\r\n * @returns\r\n */\r\n public getAllTextureBlocks(): NodeMaterialTextureBlocks[] {\r\n const textureBlocks: NodeMaterialTextureBlocks[] = [];\r\n\r\n for (const block of this.attachedBlocks) {\r\n if (NodeMaterial._BlockIsTextureBlock(block)) {\r\n textureBlocks.push(block);\r\n }\r\n }\r\n\r\n return textureBlocks;\r\n }\r\n\r\n /**\r\n * Specifies if the material uses a texture\r\n * @param texture defines the texture to check against the material\r\n * @returns a boolean specifying if the 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 if (!this._sharedData) {\r\n return false;\r\n }\r\n\r\n for (const t of this._sharedData.textureBlocks) {\r\n if (t.texture === texture) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Disposes the material\r\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\r\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\r\n * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, notBoundToMesh?: boolean): void {\r\n if (forceDisposeTextures) {\r\n for (const texture of this.getTextureBlocks()\r\n .filter((tb) => tb.texture)\r\n .map((tb) => tb.texture!)) {\r\n texture.dispose();\r\n }\r\n }\r\n\r\n for (const block of this.attachedBlocks) {\r\n block.dispose();\r\n }\r\n\r\n this.attachedBlocks.length = 0;\r\n (this._sharedData as any) = null;\r\n (this._vertexCompilationState as any) = null;\r\n (this._fragmentCompilationState as any) = null;\r\n\r\n this.onBuildObservable.clear();\r\n\r\n if (this._imageProcessingObserver) {\r\n this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);\r\n this._imageProcessingObserver = null;\r\n }\r\n\r\n super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);\r\n }\r\n\r\n /** Creates the node editor window. */\r\n private _createNodeEditor(additionalConfig?: any) {\r\n const nodeEditorConfig: any = {\r\n nodeMaterial: this,\r\n ...additionalConfig,\r\n };\r\n this.BJSNODEMATERIALEDITOR.NodeEditor.Show(nodeEditorConfig);\r\n }\r\n\r\n /**\r\n * Launch the node material editor\r\n * @param config Define the configuration of the editor\r\n * @returns a promise fulfilled when the node editor is visible\r\n */\r\n public edit(config?: INodeMaterialEditorOptions): Promise {\r\n return new Promise((resolve) => {\r\n this.BJSNODEMATERIALEDITOR = this.BJSNODEMATERIALEDITOR || this._getGlobalNodeMaterialEditor();\r\n if (typeof this.BJSNODEMATERIALEDITOR == \"undefined\") {\r\n const editorUrl = config && config.editorURL ? config.editorURL : NodeMaterial.EditorURL;\r\n\r\n // Load editor and add it to the DOM\r\n Tools.LoadScript(editorUrl, () => {\r\n this.BJSNODEMATERIALEDITOR = this.BJSNODEMATERIALEDITOR || this._getGlobalNodeMaterialEditor();\r\n this._createNodeEditor(config?.nodeEditorConfig);\r\n resolve();\r\n });\r\n } else {\r\n // Otherwise creates the editor\r\n this._createNodeEditor(config?.nodeEditorConfig);\r\n resolve();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Clear the current material\r\n */\r\n public clear() {\r\n this._vertexOutputNodes.length = 0;\r\n this._fragmentOutputNodes.length = 0;\r\n this.attachedBlocks.length = 0;\r\n }\r\n\r\n /**\r\n * Clear the current material and set it to a default state\r\n */\r\n public setToDefault() {\r\n this.clear();\r\n\r\n this.editorData = null;\r\n\r\n const positionInput = new InputBlock(\"Position\");\r\n positionInput.setAsAttribute(\"position\");\r\n\r\n const worldInput = new InputBlock(\"World\");\r\n worldInput.setAsSystemValue(NodeMaterialSystemValues.World);\r\n\r\n const worldPos = new TransformBlock(\"WorldPos\");\r\n positionInput.connectTo(worldPos);\r\n worldInput.connectTo(worldPos);\r\n\r\n const viewProjectionInput = new InputBlock(\"ViewProjection\");\r\n viewProjectionInput.setAsSystemValue(NodeMaterialSystemValues.ViewProjection);\r\n\r\n const worldPosdMultipliedByViewProjection = new TransformBlock(\"WorldPos * ViewProjectionTransform\");\r\n worldPos.connectTo(worldPosdMultipliedByViewProjection);\r\n viewProjectionInput.connectTo(worldPosdMultipliedByViewProjection);\r\n\r\n const vertexOutput = new VertexOutputBlock(\"VertexOutput\");\r\n worldPosdMultipliedByViewProjection.connectTo(vertexOutput);\r\n\r\n // Pixel\r\n const pixelColor = new InputBlock(\"color\");\r\n pixelColor.value = new Color4(0.8, 0.8, 0.8, 1);\r\n\r\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\r\n pixelColor.connectTo(fragmentOutput);\r\n\r\n // Add to nodes\r\n this.addOutputNode(vertexOutput);\r\n this.addOutputNode(fragmentOutput);\r\n\r\n this._mode = NodeMaterialModes.Material;\r\n }\r\n\r\n /**\r\n * Clear the current material and set it to a default state for post process\r\n */\r\n public setToDefaultPostProcess() {\r\n this.clear();\r\n\r\n this.editorData = null;\r\n\r\n const position = new InputBlock(\"Position\");\r\n position.setAsAttribute(\"position2d\");\r\n\r\n const const1 = new InputBlock(\"Constant1\");\r\n const1.isConstant = true;\r\n const1.value = 1;\r\n\r\n const vmerger = new VectorMergerBlock(\"Position3D\");\r\n\r\n position.connectTo(vmerger);\r\n const1.connectTo(vmerger, { input: \"w\" });\r\n\r\n const vertexOutput = new VertexOutputBlock(\"VertexOutput\");\r\n vmerger.connectTo(vertexOutput);\r\n\r\n // Pixel\r\n const scale = new InputBlock(\"Scale\");\r\n scale.visibleInInspector = true;\r\n scale.value = new Vector2(1, 1);\r\n\r\n const uv0 = new RemapBlock(\"uv0\");\r\n position.connectTo(uv0);\r\n\r\n const uv = new MultiplyBlock(\"UV scale\");\r\n uv0.connectTo(uv);\r\n scale.connectTo(uv);\r\n\r\n const currentScreen = new CurrentScreenBlock(\"CurrentScreen\");\r\n uv.connectTo(currentScreen);\r\n\r\n currentScreen.texture = new Texture(\"https://assets.babylonjs.com/nme/currentScreenPostProcess.png\", this.getScene());\r\n\r\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\r\n currentScreen.connectTo(fragmentOutput, { output: \"rgba\" });\r\n\r\n // Add to nodes\r\n this.addOutputNode(vertexOutput);\r\n this.addOutputNode(fragmentOutput);\r\n\r\n this._mode = NodeMaterialModes.PostProcess;\r\n }\r\n\r\n /**\r\n * Clear the current material and set it to a default state for procedural texture\r\n */\r\n public setToDefaultProceduralTexture() {\r\n this.clear();\r\n\r\n this.editorData = null;\r\n\r\n const position = new InputBlock(\"Position\");\r\n position.setAsAttribute(\"position2d\");\r\n\r\n const const1 = new InputBlock(\"Constant1\");\r\n const1.isConstant = true;\r\n const1.value = 1;\r\n\r\n const vmerger = new VectorMergerBlock(\"Position3D\");\r\n\r\n position.connectTo(vmerger);\r\n const1.connectTo(vmerger, { input: \"w\" });\r\n\r\n const vertexOutput = new VertexOutputBlock(\"VertexOutput\");\r\n vmerger.connectTo(vertexOutput);\r\n\r\n // Pixel\r\n const time = new InputBlock(\"Time\");\r\n time.value = 0;\r\n time.min = 0;\r\n time.max = 0;\r\n time.isBoolean = false;\r\n time.matrixMode = 0;\r\n time.animationType = AnimatedInputBlockTypes.Time;\r\n time.isConstant = false;\r\n\r\n const color = new InputBlock(\"Color3\");\r\n color.value = new Color3(1, 1, 1);\r\n color.isConstant = false;\r\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\r\n\r\n const vectorMerger = new VectorMergerBlock(\"VectorMerger\");\r\n vectorMerger.visibleInInspector = false;\r\n\r\n const cos = new TrigonometryBlock(\"Cos\");\r\n cos.operation = TrigonometryBlockOperations.Cos;\r\n\r\n position.connectTo(vectorMerger);\r\n time.output.connectTo(cos.input);\r\n cos.output.connectTo(vectorMerger.z);\r\n vectorMerger.xyzOut.connectTo(fragmentOutput.rgb);\r\n\r\n // Add to nodes\r\n this.addOutputNode(vertexOutput);\r\n this.addOutputNode(fragmentOutput);\r\n\r\n this._mode = NodeMaterialModes.ProceduralTexture;\r\n }\r\n\r\n /**\r\n * Clear the current material and set it to a default state for particle\r\n */\r\n public setToDefaultParticle() {\r\n this.clear();\r\n\r\n this.editorData = null;\r\n\r\n // Pixel\r\n const uv = new InputBlock(\"uv\");\r\n uv.setAsAttribute(\"particle_uv\");\r\n\r\n const texture = new ParticleTextureBlock(\"ParticleTexture\");\r\n uv.connectTo(texture);\r\n\r\n const color = new InputBlock(\"Color\");\r\n color.setAsAttribute(\"particle_color\");\r\n\r\n const multiply = new MultiplyBlock(\"Texture * Color\");\r\n texture.connectTo(multiply);\r\n color.connectTo(multiply);\r\n\r\n const rampGradient = new ParticleRampGradientBlock(\"ParticleRampGradient\");\r\n multiply.connectTo(rampGradient);\r\n\r\n const cSplitter = new ColorSplitterBlock(\"ColorSplitter\");\r\n color.connectTo(cSplitter);\r\n\r\n const blendMultiply = new ParticleBlendMultiplyBlock(\"ParticleBlendMultiply\");\r\n rampGradient.connectTo(blendMultiply);\r\n texture.connectTo(blendMultiply, { output: \"a\" });\r\n cSplitter.connectTo(blendMultiply, { output: \"a\" });\r\n\r\n const fragmentOutput = new FragmentOutputBlock(\"FragmentOutput\");\r\n blendMultiply.connectTo(fragmentOutput);\r\n\r\n // Add to nodes\r\n this.addOutputNode(fragmentOutput);\r\n\r\n this._mode = NodeMaterialModes.Particle;\r\n }\r\n\r\n /**\r\n * Loads the current Node Material from a url pointing to a file save by the Node Material Editor\r\n * @deprecated Please use NodeMaterial.ParseFromFileAsync instead\r\n * @param url defines the url to load from\r\n * @param rootUrl defines the root URL for nested url in the node material\r\n * @returns a promise that will fulfil when the material is fully loaded\r\n */\r\n public async loadAsync(url: string, rootUrl: string = \"\") {\r\n return NodeMaterial.ParseFromFileAsync(\"\", url, this.getScene(), rootUrl, true, this);\r\n }\r\n\r\n private _gatherBlocks(rootNode: NodeMaterialBlock, list: NodeMaterialBlock[]) {\r\n if (list.indexOf(rootNode) !== -1) {\r\n return;\r\n }\r\n list.push(rootNode);\r\n\r\n for (const input of rootNode.inputs) {\r\n const connectedPoint = input.connectedPoint;\r\n if (connectedPoint) {\r\n const block = connectedPoint.ownerBlock;\r\n if (block !== rootNode) {\r\n this._gatherBlocks(block, list);\r\n }\r\n }\r\n }\r\n\r\n // Teleportation\r\n if (rootNode.isTeleportOut) {\r\n const block = rootNode as NodeMaterialTeleportOutBlock;\r\n if (block.entryPoint) {\r\n this._gatherBlocks(block.entryPoint, list);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Generate a string containing the code declaration required to create an equivalent of this material\r\n * @returns a string\r\n */\r\n public generateCode() {\r\n let alreadyDumped: NodeMaterialBlock[] = [];\r\n const vertexBlocks: NodeMaterialBlock[] = [];\r\n const uniqueNames: string[] = [\"const\", \"var\", \"let\"];\r\n // Gets active blocks\r\n for (const outputNode of this._vertexOutputNodes) {\r\n this._gatherBlocks(outputNode, vertexBlocks);\r\n }\r\n\r\n const fragmentBlocks: NodeMaterialBlock[] = [];\r\n for (const outputNode of this._fragmentOutputNodes) {\r\n this._gatherBlocks(outputNode, fragmentBlocks);\r\n }\r\n\r\n // Generate vertex shader\r\n let codeString = `var nodeMaterial = new BABYLON.NodeMaterial(\"${this.name || \"node material\"}\");\\n`;\r\n codeString += `nodeMaterial.mode = BABYLON.NodeMaterialModes.${NodeMaterialModes[this.mode]};\\n`;\r\n for (const node of vertexBlocks) {\r\n if (node.isInput && alreadyDumped.indexOf(node) === -1) {\r\n codeString += node._dumpCode(uniqueNames, alreadyDumped);\r\n }\r\n }\r\n\r\n // Generate fragment shader\r\n for (const node of fragmentBlocks) {\r\n if (node.isInput && alreadyDumped.indexOf(node) === -1) {\r\n codeString += node._dumpCode(uniqueNames, alreadyDumped);\r\n }\r\n }\r\n\r\n // Connections\r\n alreadyDumped = [];\r\n codeString += \"\\n// Connections\\n\";\r\n for (const node of this._vertexOutputNodes) {\r\n codeString += node._dumpCodeForOutputConnections(alreadyDumped);\r\n }\r\n for (const node of this._fragmentOutputNodes) {\r\n codeString += node._dumpCodeForOutputConnections(alreadyDumped);\r\n }\r\n\r\n // Output nodes\r\n codeString += \"\\n// Output nodes\\n\";\r\n for (const node of this._vertexOutputNodes) {\r\n codeString += `nodeMaterial.addOutputNode(${node._codeVariableName});\\n`;\r\n }\r\n\r\n for (const node of this._fragmentOutputNodes) {\r\n codeString += `nodeMaterial.addOutputNode(${node._codeVariableName});\\n`;\r\n }\r\n\r\n codeString += `nodeMaterial.build();\\n`;\r\n\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this material in a JSON representation\r\n * @param selectedBlocks\r\n * @returns the serialized material object\r\n */\r\n public serialize(selectedBlocks?: NodeMaterialBlock[]): any {\r\n const serializationObject = selectedBlocks ? {} : SerializationHelper.Serialize(this);\r\n serializationObject.editorData = JSON.parse(JSON.stringify(this.editorData)); // Copy\r\n\r\n let blocks: NodeMaterialBlock[] = [];\r\n\r\n if (selectedBlocks) {\r\n blocks = selectedBlocks;\r\n } else {\r\n serializationObject.customType = \"BABYLON.NodeMaterial\";\r\n serializationObject.outputNodes = [];\r\n\r\n // Outputs\r\n for (const outputNode of this._vertexOutputNodes) {\r\n this._gatherBlocks(outputNode, blocks);\r\n serializationObject.outputNodes.push(outputNode.uniqueId);\r\n }\r\n\r\n for (const outputNode of this._fragmentOutputNodes) {\r\n this._gatherBlocks(outputNode, blocks);\r\n\r\n if (serializationObject.outputNodes.indexOf(outputNode.uniqueId) === -1) {\r\n serializationObject.outputNodes.push(outputNode.uniqueId);\r\n }\r\n }\r\n }\r\n\r\n // Blocks\r\n serializationObject.blocks = [];\r\n\r\n for (const block of blocks) {\r\n serializationObject.blocks.push(block.serialize());\r\n }\r\n\r\n if (!selectedBlocks) {\r\n for (const block of this.attachedBlocks) {\r\n if (blocks.indexOf(block) !== -1) {\r\n continue;\r\n }\r\n serializationObject.blocks.push(block.serialize());\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n private _restoreConnections(block: NodeMaterialBlock, source: any, map: { [key: number]: NodeMaterialBlock }) {\r\n for (const outputPoint of block.outputs) {\r\n for (const candidate of source.blocks) {\r\n const target = map[candidate.id];\r\n\r\n if (!target) {\r\n continue;\r\n }\r\n\r\n for (const input of candidate.inputs) {\r\n if (map[input.targetBlockId] === block && input.targetConnectionName === outputPoint.name) {\r\n const inputPoint = target.getInputByName(input.inputName);\r\n if (!inputPoint || inputPoint.isConnected) {\r\n continue;\r\n }\r\n\r\n outputPoint.connectTo(inputPoint, true);\r\n this._restoreConnections(target, source, map);\r\n continue;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clear the current graph and load a new one from a serialization object\r\n * @param source defines the JSON representation of the material\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @param merge defines whether or not the source must be merged or replace the current content\r\n */\r\n public parseSerializedObject(source: any, rootUrl: string = \"\", merge = false) {\r\n if (!merge) {\r\n this.clear();\r\n }\r\n\r\n const map: { [key: number]: NodeMaterialBlock } = {};\r\n\r\n // Create blocks\r\n for (const parsedBlock of source.blocks) {\r\n const blockType = GetClass(parsedBlock.customType);\r\n if (blockType) {\r\n const block: NodeMaterialBlock = new blockType();\r\n block._deserialize(parsedBlock, this.getScene(), rootUrl);\r\n map[parsedBlock.id] = block;\r\n\r\n this.attachedBlocks.push(block);\r\n }\r\n }\r\n\r\n // Reconnect teleportation\r\n for (const block of this.attachedBlocks) {\r\n if (block.isTeleportOut) {\r\n const teleportOut = block as NodeMaterialTeleportOutBlock;\r\n const id = teleportOut._tempEntryPointUniqueId;\r\n if (id) {\r\n const source = map[id] as NodeMaterialTeleportInBlock;\r\n source.attachToEndpoint(teleportOut);\r\n }\r\n }\r\n }\r\n\r\n // Connections - Starts with input blocks only (except if in \"merge\" mode where we scan all blocks)\r\n for (let blockIndex = 0; blockIndex < source.blocks.length; blockIndex++) {\r\n const parsedBlock = source.blocks[blockIndex];\r\n const block = map[parsedBlock.id];\r\n\r\n if (!block) {\r\n continue;\r\n }\r\n\r\n if (block.inputs.length && !merge) {\r\n continue;\r\n }\r\n this._restoreConnections(block, source, map);\r\n }\r\n\r\n // Outputs\r\n if (source.outputNodes) {\r\n for (const outputNodeId of source.outputNodes) {\r\n this.addOutputNode(map[outputNodeId]);\r\n }\r\n }\r\n\r\n // UI related info\r\n if (source.locations || (source.editorData && source.editorData.locations)) {\r\n const locations: {\r\n blockId: number;\r\n x: number;\r\n y: number;\r\n }[] = source.locations || source.editorData.locations;\r\n\r\n for (const location of locations) {\r\n if (map[location.blockId]) {\r\n location.blockId = map[location.blockId].uniqueId;\r\n }\r\n }\r\n\r\n if (merge && this.editorData && this.editorData.locations) {\r\n locations.concat(this.editorData.locations);\r\n }\r\n\r\n if (source.locations) {\r\n this.editorData = {\r\n locations: locations,\r\n };\r\n } else {\r\n this.editorData = source.editorData;\r\n this.editorData.locations = locations;\r\n }\r\n\r\n const blockMap: number[] = [];\r\n\r\n for (const key in map) {\r\n blockMap[key] = map[key].uniqueId;\r\n }\r\n\r\n this.editorData.map = blockMap;\r\n }\r\n\r\n this.comment = source.comment;\r\n\r\n if (source.forceAlphaBlending !== undefined) {\r\n this.forceAlphaBlending = source.forceAlphaBlending;\r\n }\r\n\r\n if (!merge) {\r\n this._mode = source.mode ?? NodeMaterialModes.Material;\r\n }\r\n }\r\n\r\n /**\r\n * Clear the current graph and load a new one from a serialization object\r\n * @param source defines the JSON representation of the material\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @param merge defines whether or not the source must be merged or replace the current content\r\n * @deprecated Please use the parseSerializedObject method instead\r\n */\r\n public loadFromSerialization(source: any, rootUrl: string = \"\", merge = false) {\r\n this.parseSerializedObject(source, rootUrl, merge);\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the current material.\r\n * @param name defines the name to use for the new material\r\n * @param shareEffect defines if the clone material should share the same effect (default is false)\r\n */\r\n public clone(name: string, shareEffect: boolean = false): NodeMaterial {\r\n const serializationObject = this.serialize();\r\n\r\n const clone = SerializationHelper.Clone(() => new NodeMaterial(name, this.getScene(), this.options), this);\r\n clone.id = name;\r\n clone.name = name;\r\n\r\n clone.parseSerializedObject(serializationObject);\r\n clone._buildId = this._buildId;\r\n clone.build(false, !shareEffect);\r\n\r\n return clone;\r\n }\r\n\r\n /**\r\n * Creates a node material from parsed material data\r\n * @param source defines the JSON representation of the material\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new node material\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string = \"\"): NodeMaterial {\r\n const nodeMaterial = SerializationHelper.Parse(() => new NodeMaterial(source.name, scene), source, scene, rootUrl);\r\n\r\n nodeMaterial.parseSerializedObject(source, rootUrl);\r\n nodeMaterial.build();\r\n\r\n return nodeMaterial;\r\n }\r\n\r\n /**\r\n * Creates a node material from a snippet saved in a remote file\r\n * @param name defines the name of the material to create\r\n * @param url defines the url to load from\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL for nested url in the node material\r\n * @param skipBuild defines whether to build the node material\r\n * @param targetMaterial defines a material to use instead of creating a new one\r\n * @returns a promise that will resolve to the new node material\r\n */\r\n public static async ParseFromFileAsync(\r\n name: string,\r\n url: string,\r\n scene: Scene,\r\n rootUrl: string = \"\",\r\n skipBuild: boolean = false,\r\n targetMaterial?: NodeMaterial\r\n ): Promise {\r\n const material = targetMaterial ?? new NodeMaterial(name, scene);\r\n\r\n const data = await scene._loadFileAsync(url);\r\n const serializationObject = JSON.parse(data as string);\r\n material.parseSerializedObject(serializationObject, rootUrl);\r\n if (!skipBuild) {\r\n material.build();\r\n }\r\n return material;\r\n }\r\n\r\n /**\r\n * Creates a node material from a snippet saved by the node material editor\r\n * @param snippetId defines the snippet to load\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @param nodeMaterial defines a node material to update (instead of creating a new one)\r\n * @param skipBuild defines whether to build the node material\r\n * @returns a promise that will resolve to the new node material\r\n */\r\n public static ParseFromSnippetAsync(\r\n snippetId: string,\r\n scene: Scene = EngineStore.LastCreatedScene!,\r\n rootUrl: string = \"\",\r\n nodeMaterial?: NodeMaterial,\r\n skipBuild: boolean = false\r\n ): Promise {\r\n if (snippetId === \"_BLANK\") {\r\n return Promise.resolve(NodeMaterial.CreateDefault(\"blank\", scene));\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n const request = new WebRequest();\r\n request.addEventListener(\"readystatechange\", () => {\r\n if (request.readyState == 4) {\r\n if (request.status == 200) {\r\n const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);\r\n const serializationObject = JSON.parse(snippet.nodeMaterial);\r\n\r\n if (!nodeMaterial) {\r\n nodeMaterial = SerializationHelper.Parse(() => new NodeMaterial(snippetId, scene), serializationObject, scene, rootUrl);\r\n nodeMaterial.uniqueId = scene.getUniqueId();\r\n }\r\n\r\n nodeMaterial.parseSerializedObject(serializationObject);\r\n nodeMaterial.snippetId = snippetId;\r\n\r\n try {\r\n if (!skipBuild) {\r\n nodeMaterial.build();\r\n }\r\n resolve(nodeMaterial);\r\n } catch (err) {\r\n reject(err);\r\n }\r\n } else {\r\n reject(\"Unable to load the snippet \" + snippetId);\r\n }\r\n }\r\n });\r\n\r\n request.open(\"GET\", this.SnippetUrl + \"/\" + snippetId.replace(/#/g, \"/\"));\r\n request.send();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a new node material set to default basic configuration\r\n * @param name defines the name of the material\r\n * @param scene defines the hosting scene\r\n * @returns a new NodeMaterial\r\n */\r\n public static CreateDefault(name: string, scene?: Scene) {\r\n const newMaterial = new NodeMaterial(name, scene);\r\n\r\n newMaterial.setToDefault();\r\n newMaterial.build();\r\n\r\n return newMaterial;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.NodeMaterial\", NodeMaterial);\r\n","import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRControllerPointerSelection } from \"./WebXRControllerPointerSelection\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { CreateSphere } from \"../../Meshes/Builders/sphereBuilder\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport type { IndicesArray, Nullable } from \"../../types\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Ray } from \"../../Culling/ray\";\r\nimport { PickingInfo } from \"../../Collisions/pickingInfo\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { UtilityLayerRenderer } from \"../../Rendering/utilityLayerRenderer\";\r\nimport type { WebXRAbstractMotionController } from \"../motionController/webXRAbstractMotionController\";\r\nimport { BoundingSphere } from \"../../Culling/boundingSphere\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\nimport { NodeMaterial } from \"../../Materials/Node/nodeMaterial\";\r\nimport type { Material } from \"../../Materials/material\";\r\nimport { Animation } from \"../../Animations/animation\";\r\nimport { QuadraticEase, EasingFunction } from \"../../Animations/easing\";\r\n// side effects\r\nimport \"../../Meshes/subMesh.project\";\r\n\r\ntype ControllerData = {\r\n xrController?: WebXRInputSource;\r\n squeezeComponent?: WebXRControllerComponent;\r\n selectionComponent?: WebXRControllerComponent;\r\n onButtonChangedObserver?: Nullable>;\r\n onSqueezeButtonChangedObserver?: Nullable>;\r\n onFrameObserver?: Nullable>;\r\n meshUnderPointer: Nullable;\r\n nearInteractionTargetMesh: Nullable;\r\n pick: Nullable;\r\n stalePick: Nullable;\r\n id: number;\r\n touchCollisionMesh: AbstractMesh;\r\n touchCollisionMeshFunction: (isTouch: boolean) => void;\r\n hydrateCollisionMeshFunction: (isHydration: boolean) => void;\r\n currentAnimationState: ControllerOrbAnimationState;\r\n grabRay: Ray;\r\n nearInteraction: boolean;\r\n hoverInteraction: boolean;\r\n grabInteraction: boolean;\r\n // event support\r\n eventListeners?: { [event in XREventType]?: (event: XRInputSourceEvent) => void };\r\n pickedPointVisualCue: AbstractMesh;\r\n};\r\n\r\n// Tracks the interaction animation state when using a motion controller with a near interaction orb\r\nenum ControllerOrbAnimationState {\r\n /**\r\n * Orb is invisible\r\n */\r\n DEHYDRATED,\r\n /**\r\n * Orb is visible and inside the hover range\r\n */\r\n HOVER,\r\n /**\r\n * Orb is visible and touching a near interaction target\r\n */\r\n TOUCH,\r\n}\r\n\r\n/**\r\n * Where should the near interaction mesh be attached to when using a motion controller for near interaction\r\n */\r\nexport enum WebXRNearControllerMode {\r\n /**\r\n * Motion controllers will not support near interaction\r\n */\r\n DISABLED = 0,\r\n /**\r\n * The interaction point for motion controllers will be inside of them\r\n */\r\n CENTERED_ON_CONTROLLER = 1,\r\n /**\r\n * The interaction point for motion controllers will be in front of the controller\r\n */\r\n CENTERED_IN_FRONT = 2,\r\n}\r\n\r\n/**\r\n * Options interface for the near interaction module\r\n */\r\nexport interface IWebXRNearInteractionOptions {\r\n /**\r\n * If provided, this scene will be used to render meshes.\r\n */\r\n customUtilityLayerScene?: Scene;\r\n /**\r\n * Should meshes created here be added to a utility layer or the main scene\r\n */\r\n useUtilityLayer?: boolean;\r\n /**\r\n * The xr input to use with this near interaction\r\n */\r\n xrInput: WebXRInput;\r\n /**\r\n * Enable near interaction on all controllers instead of switching between them\r\n */\r\n enableNearInteractionOnAllControllers?: boolean;\r\n /**\r\n * The preferred hand to give the near interaction to. This will be prioritized when the controller initialize.\r\n * If switch is enabled, it will still allow the user to switch between the different controllers\r\n */\r\n preferredHandedness?: XRHandedness;\r\n /**\r\n * Disable switching the near interaction from one controller to the other.\r\n * If the preferred hand is set it will be fixed on this hand, and if not it will be fixed on the first controller added to the scene\r\n */\r\n disableSwitchOnClick?: boolean;\r\n\r\n /**\r\n * Far interaction feature to toggle when near interaction takes precedence\r\n */\r\n farInteractionFeature?: WebXRControllerPointerSelection;\r\n\r\n /**\r\n * Near interaction mode for motion controllers\r\n */\r\n nearInteractionControllerMode?: WebXRNearControllerMode;\r\n\r\n /**\r\n * Optional material for the motion controller orb, if enabled\r\n */\r\n motionControllerOrbMaterial?: Material;\r\n}\r\n\r\n/**\r\n * A module that will enable near interaction near interaction for hands and motion controllers of XR Input Sources\r\n */\r\nexport class WebXRNearInteraction extends WebXRAbstractFeature {\r\n private static _IdCounter = 200;\r\n\r\n private _tmpRay: Ray = new Ray(new Vector3(), new Vector3());\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n // get two new meshes\r\n const { touchCollisionMesh, touchCollisionMeshFunction, hydrateCollisionMeshFunction } = this._generateNewTouchPointMesh();\r\n const selectionMesh = this._generateVisualCue();\r\n\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n meshUnderPointer: null,\r\n nearInteractionTargetMesh: null,\r\n pick: null,\r\n stalePick: null,\r\n touchCollisionMesh,\r\n touchCollisionMeshFunction: touchCollisionMeshFunction,\r\n hydrateCollisionMeshFunction: hydrateCollisionMeshFunction,\r\n currentAnimationState: ControllerOrbAnimationState.DEHYDRATED,\r\n grabRay: new Ray(new Vector3(), new Vector3()),\r\n hoverInteraction: false,\r\n nearInteraction: false,\r\n grabInteraction: false,\r\n id: WebXRNearInteraction._IdCounter++,\r\n pickedPointVisualCue: selectionMesh,\r\n };\r\n\r\n if (this._attachedController) {\r\n if (\r\n !this._options.enableNearInteractionOnAllControllers &&\r\n this._options.preferredHandedness &&\r\n xrController.inputSource.handedness === this._options.preferredHandedness\r\n ) {\r\n this._attachedController = xrController.uniqueId;\r\n }\r\n } else {\r\n if (!this._options.enableNearInteractionOnAllControllers) {\r\n this._attachedController = xrController.uniqueId;\r\n }\r\n }\r\n switch (xrController.inputSource.targetRayMode) {\r\n case \"tracked-pointer\":\r\n return this._attachNearInteractionMode(xrController);\r\n case \"gaze\":\r\n return null;\r\n case \"screen\":\r\n return null;\r\n }\r\n };\r\n\r\n private _controllers: {\r\n [controllerUniqueId: string]: ControllerData;\r\n } = {};\r\n private _scene: Scene;\r\n\r\n private _attachedController: string;\r\n\r\n private _farInteractionFeature: Nullable = null;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.NEAR_INTERACTION;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * default color of the selection ring\r\n */\r\n public selectionMeshDefaultColor: Color3 = new Color3(0.8, 0.8, 0.8);\r\n /**\r\n * This color will be applied to the selection ring when selection is triggered\r\n */\r\n public selectionMeshPickedColor: Color3 = new Color3(0.3, 0.3, 1.0);\r\n\r\n /**\r\n * constructs a new background remover module\r\n * @param _xrSessionManager the session manager for this module\r\n * @param _options read-only options to be used in this module\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private readonly _options: IWebXRNearInteractionOptions) {\r\n super(_xrSessionManager);\r\n this._scene = this._xrSessionManager.scene;\r\n if (this._options.nearInteractionControllerMode === undefined) {\r\n this._options.nearInteractionControllerMode = WebXRNearControllerMode.CENTERED_IN_FRONT;\r\n }\r\n\r\n if (this._options.farInteractionFeature) {\r\n this._farInteractionFeature = this._options.farInteractionFeature;\r\n }\r\n }\r\n\r\n /**\r\n * Attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n this._options.xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n this._scene.constantlyUpdateMeshUnderPointer = true;\r\n return true;\r\n }\r\n\r\n /**\r\n * Detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Will get the mesh under a specific pointer.\r\n * `scene.meshUnderPointer` will only return one mesh - either left or right.\r\n * @param controllerId the controllerId to check\r\n * @returns The mesh under pointer or null if no mesh is under the pointer\r\n */\r\n public getMeshUnderPointer(controllerId: string): Nullable {\r\n if (this._controllers[controllerId]) {\r\n return this._controllers[controllerId].meshUnderPointer;\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Get the xr controller that correlates to the pointer id in the pointer event\r\n *\r\n * @param id the pointer id to search for\r\n * @returns the controller that correlates to this id or null if not found\r\n */\r\n public getXRControllerByPointerId(id: number): Nullable {\r\n const keys = Object.keys(this._controllers);\r\n\r\n for (let i = 0; i < keys.length; ++i) {\r\n if (this._controllers[keys[i]].id === id) {\r\n return this._controllers[keys[i]].xrController || null;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * This function sets webXRControllerPointerSelection feature that will be disabled when\r\n * the hover range is reached for a mesh and will be reattached when not in hover range.\r\n * This is used to remove the selection rays when moving.\r\n * @param farInteractionFeature the feature to disable when finger is in hover range for a mesh\r\n */\r\n public setFarInteractionFeature(farInteractionFeature: Nullable) {\r\n this._farInteractionFeature = farInteractionFeature;\r\n }\r\n\r\n /**\r\n * Filter used for near interaction pick and hover\r\n * @param mesh\r\n */\r\n private _nearPickPredicate(mesh: AbstractMesh): boolean {\r\n return mesh.isEnabled() && mesh.isVisible && mesh.isPickable && mesh.isNearPickable;\r\n }\r\n\r\n /**\r\n * Filter used for near interaction grab\r\n * @param mesh\r\n */\r\n private _nearGrabPredicate(mesh: AbstractMesh): boolean {\r\n return mesh.isEnabled() && mesh.isVisible && mesh.isPickable && mesh.isNearGrabbable;\r\n }\r\n\r\n /**\r\n * Filter used for any near interaction\r\n * @param mesh\r\n */\r\n private _nearInteractionPredicate(mesh: AbstractMesh): boolean {\r\n return mesh.isEnabled() && mesh.isVisible && mesh.isPickable && (mesh.isNearPickable || mesh.isNearGrabbable);\r\n }\r\n\r\n private _controllerAvailablePredicate(mesh: AbstractMesh, controllerId: string): boolean {\r\n let parent: TransformNode = mesh;\r\n\r\n while (parent) {\r\n if (parent.reservedDataStore && parent.reservedDataStore.nearInteraction && parent.reservedDataStore.nearInteraction.excludedControllerId === controllerId) {\r\n return false;\r\n }\r\n parent = parent.parent as TransformNode;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _handleTransitionAnimation(controllerData: ControllerData, newState: ControllerOrbAnimationState) {\r\n if (\r\n controllerData.currentAnimationState === newState ||\r\n this._options.nearInteractionControllerMode !== WebXRNearControllerMode.CENTERED_IN_FRONT ||\r\n !!controllerData.xrController?.inputSource.hand\r\n ) {\r\n return;\r\n }\r\n\r\n // Don't always break to allow for animation fallthrough on rare cases of multi-transitions\r\n if (newState > controllerData.currentAnimationState) {\r\n switch (controllerData.currentAnimationState) {\r\n case ControllerOrbAnimationState.DEHYDRATED: {\r\n controllerData.hydrateCollisionMeshFunction(true);\r\n if (newState === ControllerOrbAnimationState.HOVER) {\r\n break;\r\n }\r\n }\r\n // eslint-disable-next-line no-fallthrough\r\n case ControllerOrbAnimationState.HOVER: {\r\n controllerData.touchCollisionMeshFunction(true);\r\n if (newState === ControllerOrbAnimationState.TOUCH) {\r\n break;\r\n }\r\n }\r\n }\r\n } else {\r\n switch (controllerData.currentAnimationState) {\r\n case ControllerOrbAnimationState.TOUCH: {\r\n controllerData.touchCollisionMeshFunction(false);\r\n if (newState === ControllerOrbAnimationState.HOVER) {\r\n break;\r\n }\r\n }\r\n // eslint-disable-next-line no-fallthrough\r\n case ControllerOrbAnimationState.HOVER: {\r\n controllerData.hydrateCollisionMeshFunction(false);\r\n if (newState === ControllerOrbAnimationState.DEHYDRATED) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n controllerData.currentAnimationState = newState;\r\n }\r\n\r\n private readonly _hoverRadius = 0.1;\r\n private readonly _pickRadius = 0.02;\r\n private readonly _controllerPickRadius = 0.03; // The radius is slightly larger here to make it easier to manipulate since it's not tied to the hand position\r\n private readonly _nearGrabLengthScale = 5;\r\n\r\n private _processTouchPoint(id: string, position: Vector3, orientation: Quaternion) {\r\n const controllerData = this._controllers[id];\r\n\r\n // Position and orientation could be temporary values, se we take care of them before calling any functions that use temporary vectors/quaternions\r\n controllerData.grabRay.origin.copyFrom(position);\r\n orientation.toEulerAnglesToRef(TmpVectors.Vector3[0]);\r\n controllerData.grabRay.direction.copyFrom(TmpVectors.Vector3[0]);\r\n\r\n if (this._options.nearInteractionControllerMode === WebXRNearControllerMode.CENTERED_IN_FRONT && !controllerData.xrController?.inputSource.hand) {\r\n // offset the touch point in the direction the transform is facing\r\n controllerData.xrController!.getWorldPointerRayToRef(this._tmpRay);\r\n controllerData.grabRay.origin.addInPlace(this._tmpRay.direction.scale(0.05));\r\n }\r\n\r\n controllerData.grabRay.length = this._nearGrabLengthScale * this._hoverRadius;\r\n controllerData.touchCollisionMesh.position.copyFrom(controllerData.grabRay.origin);\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n Object.keys(this._controllers).forEach((id) => {\r\n // only do this for the selected pointer\r\n const controllerData = this._controllers[id];\r\n const handData = controllerData.xrController?.inputSource.hand;\r\n // If near interaction is not enabled/available for this controller, return early\r\n if (\r\n (!this._options.enableNearInteractionOnAllControllers && id !== this._attachedController) ||\r\n !controllerData.xrController ||\r\n (!handData && (!this._options.nearInteractionControllerMode || !controllerData.xrController.inputSource.gamepad))\r\n ) {\r\n controllerData.pick = null;\r\n return;\r\n }\r\n controllerData.hoverInteraction = false;\r\n controllerData.nearInteraction = false;\r\n\r\n // Every frame check collisions/input\r\n if (controllerData.xrController) {\r\n if (handData) {\r\n const xrIndexTip = handData.get(\"index-finger-tip\");\r\n if (xrIndexTip) {\r\n const indexTipPose = _xrFrame.getJointPose!(xrIndexTip, this._xrSessionManager.referenceSpace);\r\n if (indexTipPose && indexTipPose.transform) {\r\n const axisRHSMultiplier = this._scene.useRightHandedSystem ? 1 : -1;\r\n TmpVectors.Vector3[0].set(indexTipPose.transform.position.x, indexTipPose.transform.position.y, indexTipPose.transform.position.z * axisRHSMultiplier);\r\n TmpVectors.Quaternion[0].set(\r\n indexTipPose.transform.orientation.x,\r\n indexTipPose.transform.orientation.y,\r\n indexTipPose.transform.orientation.z * axisRHSMultiplier,\r\n indexTipPose.transform.orientation.w * axisRHSMultiplier\r\n );\r\n\r\n this._processTouchPoint(id, TmpVectors.Vector3[0], TmpVectors.Quaternion[0]);\r\n }\r\n }\r\n } else if (controllerData.xrController.inputSource.gamepad && this._options.nearInteractionControllerMode !== WebXRNearControllerMode.DISABLED) {\r\n let controllerPose = controllerData.xrController.pointer;\r\n if (controllerData.xrController.grip && this._options.nearInteractionControllerMode === WebXRNearControllerMode.CENTERED_ON_CONTROLLER) {\r\n controllerPose = controllerData.xrController.grip;\r\n }\r\n\r\n this._processTouchPoint(id, controllerPose.position, controllerPose.rotationQuaternion!);\r\n }\r\n } else {\r\n return;\r\n }\r\n\r\n const accuratePickInfo = (originalScenePick: Nullable, utilityScenePick: Nullable): Nullable => {\r\n let pick = null;\r\n if (!utilityScenePick || !utilityScenePick.hit) {\r\n // No hit in utility scene\r\n pick = originalScenePick;\r\n } else if (!originalScenePick || !originalScenePick.hit) {\r\n // No hit in original scene\r\n pick = utilityScenePick;\r\n } else if (utilityScenePick.distance < originalScenePick.distance) {\r\n // Hit is closer in utility scene\r\n pick = utilityScenePick;\r\n } else {\r\n // Hit is closer in original scene\r\n pick = originalScenePick;\r\n }\r\n return pick;\r\n };\r\n const populateNearInteractionInfo = (nearInteractionInfo: Nullable): PickingInfo => {\r\n let result = new PickingInfo();\r\n\r\n let nearInteractionAtOrigin = false;\r\n const nearInteraction = nearInteractionInfo && nearInteractionInfo.pickedPoint && nearInteractionInfo.hit;\r\n if (nearInteractionInfo?.pickedPoint) {\r\n nearInteractionAtOrigin = nearInteractionInfo.pickedPoint.x === 0 && nearInteractionInfo.pickedPoint.y === 0 && nearInteractionInfo.pickedPoint.z === 0;\r\n }\r\n if (nearInteraction && !nearInteractionAtOrigin) {\r\n result = nearInteractionInfo!;\r\n }\r\n return result;\r\n };\r\n\r\n // Don't perform touch logic while grabbing, to prevent triggering touch interactions while in the middle of a grab interaction\r\n // Dont update cursor logic either - the cursor should already be visible for the grab to be in range,\r\n // and in order to maintain its position on the target mesh it is parented for the duration of the grab.\r\n if (!controllerData.grabInteraction) {\r\n let pick = null;\r\n\r\n // near interaction hover\r\n let utilitySceneHoverPick = null;\r\n if (this._options.useUtilityLayer && this._utilityLayerScene) {\r\n utilitySceneHoverPick = this._pickWithSphere(controllerData, this._hoverRadius, this._utilityLayerScene, (mesh: AbstractMesh) =>\r\n this._nearInteractionPredicate(mesh)\r\n );\r\n }\r\n const originalSceneHoverPick = this._pickWithSphere(controllerData, this._hoverRadius, this._scene, (mesh: AbstractMesh) => this._nearInteractionPredicate(mesh));\r\n\r\n const hoverPickInfo = accuratePickInfo(originalSceneHoverPick, utilitySceneHoverPick);\r\n if (hoverPickInfo && hoverPickInfo.hit) {\r\n pick = populateNearInteractionInfo(hoverPickInfo);\r\n if (pick.hit) {\r\n controllerData.hoverInteraction = true;\r\n }\r\n }\r\n\r\n // near interaction pick\r\n if (controllerData.hoverInteraction) {\r\n let utilitySceneNearPick = null;\r\n const radius = handData ? this._pickRadius : this._controllerPickRadius;\r\n if (this._options.useUtilityLayer && this._utilityLayerScene) {\r\n utilitySceneNearPick = this._pickWithSphere(controllerData, radius, this._utilityLayerScene, (mesh: AbstractMesh) => this._nearPickPredicate(mesh));\r\n }\r\n const originalSceneNearPick = this._pickWithSphere(controllerData, radius, this._scene, (mesh: AbstractMesh) => this._nearPickPredicate(mesh));\r\n const pickInfo = accuratePickInfo(originalSceneNearPick, utilitySceneNearPick);\r\n const nearPick = populateNearInteractionInfo(pickInfo);\r\n if (nearPick.hit) {\r\n // Near pick takes precedence over hover interaction\r\n pick = nearPick;\r\n controllerData.nearInteraction = true;\r\n }\r\n }\r\n\r\n controllerData.stalePick = controllerData.pick;\r\n controllerData.pick = pick;\r\n\r\n // Update mesh under pointer\r\n if (controllerData.pick && controllerData.pick.pickedPoint && controllerData.pick.hit) {\r\n controllerData.meshUnderPointer = controllerData.pick.pickedMesh;\r\n controllerData.pickedPointVisualCue.position.copyFrom(controllerData.pick.pickedPoint);\r\n controllerData.pickedPointVisualCue.isVisible = true;\r\n\r\n if (this._farInteractionFeature && this._farInteractionFeature.attached) {\r\n this._farInteractionFeature._setPointerSelectionDisabledByPointerId(controllerData.id, true);\r\n }\r\n } else {\r\n controllerData.meshUnderPointer = null;\r\n controllerData.pickedPointVisualCue.isVisible = false;\r\n\r\n if (this._farInteractionFeature && this._farInteractionFeature.attached) {\r\n this._farInteractionFeature._setPointerSelectionDisabledByPointerId(controllerData.id, false);\r\n }\r\n }\r\n }\r\n\r\n // Update the interaction animation. Only updates if the visible touch mesh is active\r\n let state = ControllerOrbAnimationState.DEHYDRATED;\r\n if (controllerData.grabInteraction || controllerData.nearInteraction) {\r\n state = ControllerOrbAnimationState.TOUCH;\r\n } else if (controllerData.hoverInteraction) {\r\n state = ControllerOrbAnimationState.HOVER;\r\n }\r\n this._handleTransitionAnimation(controllerData, state);\r\n });\r\n }\r\n\r\n private get _utilityLayerScene() {\r\n return this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;\r\n }\r\n\r\n private _generateVisualCue() {\r\n const sceneToRenderTo = this._options.useUtilityLayer ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene : this._scene;\r\n const selectionMesh = CreateSphere(\r\n \"nearInteraction\",\r\n {\r\n diameter: 0.0035 * 3,\r\n },\r\n sceneToRenderTo\r\n );\r\n selectionMesh.bakeCurrentTransformIntoVertices();\r\n selectionMesh.isPickable = false;\r\n selectionMesh.isVisible = false;\r\n selectionMesh.rotationQuaternion = Quaternion.Identity();\r\n const targetMat = new StandardMaterial(\"targetMat\", sceneToRenderTo);\r\n targetMat.specularColor = Color3.Black();\r\n targetMat.emissiveColor = this.selectionMeshDefaultColor;\r\n targetMat.backFaceCulling = false;\r\n selectionMesh.material = targetMat;\r\n\r\n return selectionMesh;\r\n }\r\n\r\n private _isControllerReadyForNearInteraction(id: number) {\r\n if (this._farInteractionFeature) {\r\n return this._farInteractionFeature._getPointerSelectionDisabledByPointerId(id);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _attachNearInteractionMode(xrController: WebXRInputSource) {\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n const pointerEventInit: PointerEventInit = {\r\n pointerId: controllerData.id,\r\n pointerType: \"xr-near\",\r\n };\r\n controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {\r\n if (\r\n (!this._options.enableNearInteractionOnAllControllers && xrController.uniqueId !== this._attachedController) ||\r\n !controllerData.xrController ||\r\n (!controllerData.xrController.inputSource.hand && (!this._options.nearInteractionControllerMode || !controllerData.xrController.inputSource.gamepad))\r\n ) {\r\n return;\r\n }\r\n if (controllerData.pick) {\r\n controllerData.pick.ray = controllerData.grabRay;\r\n }\r\n\r\n if (controllerData.pick && this._isControllerReadyForNearInteraction(controllerData.id)) {\r\n this._scene.simulatePointerMove(controllerData.pick, pointerEventInit);\r\n }\r\n\r\n // Near pick pointer event\r\n if (controllerData.nearInteraction && controllerData.pick && controllerData.pick.hit) {\r\n if (!controllerData.nearInteractionTargetMesh) {\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n controllerData.nearInteractionTargetMesh = controllerData.meshUnderPointer;\r\n }\r\n } else if (controllerData.nearInteractionTargetMesh && controllerData.stalePick) {\r\n this._scene.simulatePointerUp(controllerData.stalePick, pointerEventInit);\r\n controllerData.nearInteractionTargetMesh = null;\r\n }\r\n });\r\n\r\n const grabCheck = (pressed: boolean) => {\r\n if (\r\n this._options.enableNearInteractionOnAllControllers ||\r\n (xrController.uniqueId === this._attachedController && this._isControllerReadyForNearInteraction(controllerData.id))\r\n ) {\r\n if (controllerData.pick) {\r\n controllerData.pick.ray = controllerData.grabRay;\r\n }\r\n if (pressed && controllerData.pick && controllerData.meshUnderPointer && this._nearGrabPredicate(controllerData.meshUnderPointer)) {\r\n controllerData.grabInteraction = true;\r\n controllerData.pickedPointVisualCue.isVisible = false;\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n } else if (!pressed && controllerData.pick && controllerData.grabInteraction) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n controllerData.grabInteraction = false;\r\n controllerData.pickedPointVisualCue.isVisible = true;\r\n }\r\n } else {\r\n if (pressed && !this._options.enableNearInteractionOnAllControllers && !this._options.disableSwitchOnClick) {\r\n this._attachedController = xrController.uniqueId;\r\n }\r\n }\r\n };\r\n\r\n if (xrController.inputSource.gamepad) {\r\n const init = (motionController: WebXRAbstractMotionController) => {\r\n controllerData.squeezeComponent = motionController.getComponent(\"grasp\");\r\n if (controllerData.squeezeComponent) {\r\n controllerData.onSqueezeButtonChangedObserver = controllerData.squeezeComponent.onButtonStateChangedObservable.add((component) => {\r\n if (component.changes.pressed) {\r\n const pressed = component.changes.pressed.current;\r\n grabCheck(pressed);\r\n }\r\n });\r\n } else {\r\n controllerData.selectionComponent = motionController.getMainComponent();\r\n controllerData.onButtonChangedObserver = controllerData.selectionComponent.onButtonStateChangedObservable.add((component) => {\r\n if (component.changes.pressed) {\r\n const pressed = component.changes.pressed.current;\r\n grabCheck(pressed);\r\n }\r\n });\r\n }\r\n };\r\n if (xrController.motionController) {\r\n init(xrController.motionController);\r\n } else {\r\n xrController.onMotionControllerInitObservable.add(init);\r\n }\r\n } else {\r\n // use the select and squeeze events\r\n const selectStartListener = (event: XRInputSourceEvent) => {\r\n if (\r\n controllerData.xrController &&\r\n event.inputSource === controllerData.xrController.inputSource &&\r\n controllerData.pick &&\r\n this._isControllerReadyForNearInteraction(controllerData.id) &&\r\n controllerData.meshUnderPointer &&\r\n this._nearGrabPredicate(controllerData.meshUnderPointer)\r\n ) {\r\n controllerData.grabInteraction = true;\r\n controllerData.pickedPointVisualCue.isVisible = false;\r\n this._scene.simulatePointerDown(controllerData.pick, pointerEventInit);\r\n }\r\n };\r\n\r\n const selectEndListener = (event: XRInputSourceEvent) => {\r\n if (\r\n controllerData.xrController &&\r\n event.inputSource === controllerData.xrController.inputSource &&\r\n controllerData.pick &&\r\n this._isControllerReadyForNearInteraction(controllerData.id)\r\n ) {\r\n this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);\r\n controllerData.grabInteraction = false;\r\n controllerData.pickedPointVisualCue.isVisible = true;\r\n }\r\n };\r\n\r\n controllerData.eventListeners = {\r\n selectend: selectEndListener,\r\n selectstart: selectStartListener,\r\n };\r\n\r\n this._xrSessionManager.session.addEventListener(\"selectstart\", selectStartListener);\r\n this._xrSessionManager.session.addEventListener(\"selectend\", selectEndListener);\r\n }\r\n }\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n if (controllerData.squeezeComponent) {\r\n if (controllerData.onSqueezeButtonChangedObserver) {\r\n controllerData.squeezeComponent.onButtonStateChangedObservable.remove(controllerData.onSqueezeButtonChangedObserver);\r\n }\r\n }\r\n if (controllerData.selectionComponent) {\r\n if (controllerData.onButtonChangedObserver) {\r\n controllerData.selectionComponent.onButtonStateChangedObservable.remove(controllerData.onButtonChangedObserver);\r\n }\r\n }\r\n if (controllerData.onFrameObserver) {\r\n this._xrSessionManager.onXRFrameObservable.remove(controllerData.onFrameObserver);\r\n }\r\n if (controllerData.eventListeners) {\r\n Object.keys(controllerData.eventListeners).forEach((eventName: string) => {\r\n const func = controllerData.eventListeners && controllerData.eventListeners[eventName as XREventType];\r\n if (func) {\r\n this._xrSessionManager.session.removeEventListener(eventName as XREventType, func as any);\r\n }\r\n });\r\n }\r\n controllerData.touchCollisionMesh.dispose();\r\n controllerData.pickedPointVisualCue.dispose();\r\n\r\n this._xrSessionManager.runInXRFrame(() => {\r\n // Fire a pointerup\r\n const pointerEventInit: PointerEventInit = {\r\n pointerId: controllerData.id,\r\n pointerType: \"xr-near\",\r\n };\r\n this._scene.simulatePointerUp(new PickingInfo(), pointerEventInit);\r\n });\r\n\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n if (this._attachedController === xrControllerUniqueId) {\r\n // check for other controllers\r\n const keys = Object.keys(this._controllers);\r\n if (keys.length) {\r\n this._attachedController = keys[0];\r\n } else {\r\n this._attachedController = \"\";\r\n }\r\n }\r\n }\r\n\r\n private _generateNewTouchPointMesh() {\r\n // populate information for near hover, pick and pinch\r\n const meshCreationScene = this._options.useUtilityLayer ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene : this._scene;\r\n\r\n const touchCollisionMesh = CreateSphere(\"PickSphere\", { diameter: 1 }, meshCreationScene);\r\n touchCollisionMesh.isVisible = false;\r\n\r\n // Generate the material for the touch mesh visuals\r\n if (this._options.motionControllerOrbMaterial) {\r\n touchCollisionMesh.material = this._options.motionControllerOrbMaterial;\r\n } else {\r\n NodeMaterial.ParseFromSnippetAsync(\"8RUNKL#3\", meshCreationScene).then((nodeMaterial) => {\r\n touchCollisionMesh.material = nodeMaterial;\r\n });\r\n }\r\n\r\n const easingFunction = new QuadraticEase();\r\n easingFunction.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\r\n\r\n // Adjust the visual size based off of the size of the touch collision orb.\r\n // Having the size perfectly match for hover gives a more accurate tell for when the user will start interacting with the target\r\n // Sizes for other states are somewhat arbitrary, as they are based on what feels nice during an interaction\r\n const hoverSizeVec = new Vector3(this._controllerPickRadius, this._controllerPickRadius, this._controllerPickRadius);\r\n const touchSize = this._controllerPickRadius * (4 / 3);\r\n const touchSizeVec = new Vector3(touchSize, touchSize, touchSize);\r\n const hydrateTransitionSize = this._controllerPickRadius * (7 / 6);\r\n const hydrateTransitionSizeVec = new Vector3(hydrateTransitionSize, hydrateTransitionSize, hydrateTransitionSize);\r\n const touchHoverTransitionSize = this._controllerPickRadius * (4 / 5);\r\n const touchHoverTransitionSizeVec = new Vector3(touchHoverTransitionSize, touchHoverTransitionSize, touchHoverTransitionSize);\r\n const hoverTouchTransitionSize = this._controllerPickRadius * (3 / 2);\r\n const hoverTouchTransitionSizeVec = new Vector3(hoverTouchTransitionSize, hoverTouchTransitionSize, hoverTouchTransitionSize);\r\n\r\n const touchKeys = [\r\n { frame: 0, value: hoverSizeVec },\r\n { frame: 10, value: hoverTouchTransitionSizeVec },\r\n { frame: 18, value: touchSizeVec },\r\n ];\r\n const releaseKeys = [\r\n { frame: 0, value: touchSizeVec },\r\n { frame: 10, value: touchHoverTransitionSizeVec },\r\n { frame: 18, value: hoverSizeVec },\r\n ];\r\n const hydrateKeys = [\r\n { frame: 0, value: Vector3.ZeroReadOnly },\r\n { frame: 12, value: hydrateTransitionSizeVec },\r\n { frame: 15, value: hoverSizeVec },\r\n ];\r\n const dehydrateKeys = [\r\n { frame: 0, value: hoverSizeVec },\r\n { frame: 10, value: Vector3.ZeroReadOnly },\r\n { frame: 15, value: Vector3.ZeroReadOnly },\r\n ];\r\n\r\n const touchAction = new Animation(\"touch\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n const releaseAction = new Animation(\"release\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n const hydrateAction = new Animation(\"hydrate\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n const dehydrateAction = new Animation(\"dehydrate\", \"scaling\", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);\r\n\r\n touchAction.setEasingFunction(easingFunction);\r\n releaseAction.setEasingFunction(easingFunction);\r\n hydrateAction.setEasingFunction(easingFunction);\r\n dehydrateAction.setEasingFunction(easingFunction);\r\n\r\n touchAction.setKeys(touchKeys);\r\n releaseAction.setKeys(releaseKeys);\r\n hydrateAction.setKeys(hydrateKeys);\r\n dehydrateAction.setKeys(dehydrateKeys);\r\n\r\n const touchCollisionMeshFunction = (isTouch: boolean) => {\r\n const action = isTouch ? touchAction : releaseAction;\r\n meshCreationScene.beginDirectAnimation(touchCollisionMesh, [action], 0, 18, false, 1);\r\n };\r\n\r\n const hydrateCollisionMeshFunction = (isHydration: boolean) => {\r\n const action = isHydration ? hydrateAction : dehydrateAction;\r\n if (isHydration) {\r\n touchCollisionMesh.isVisible = true;\r\n }\r\n meshCreationScene.beginDirectAnimation(touchCollisionMesh, [action], 0, 15, false, 1, () => {\r\n if (!isHydration) {\r\n touchCollisionMesh.isVisible = false;\r\n }\r\n });\r\n };\r\n\r\n return { touchCollisionMesh, touchCollisionMeshFunction, hydrateCollisionMeshFunction };\r\n }\r\n\r\n private _pickWithSphere(controllerData: ControllerData, radius: number, sceneToUse: Scene, predicate: (mesh: AbstractMesh) => boolean): Nullable {\r\n const pickingInfo = new PickingInfo();\r\n pickingInfo.distance = +Infinity;\r\n\r\n if (controllerData.touchCollisionMesh && controllerData.xrController) {\r\n const position = controllerData.touchCollisionMesh.position;\r\n const sphere = BoundingSphere.CreateFromCenterAndRadius(position, radius);\r\n\r\n for (let meshIndex = 0; meshIndex < sceneToUse.meshes.length; meshIndex++) {\r\n const mesh = sceneToUse.meshes[meshIndex];\r\n if (!predicate(mesh) || !this._controllerAvailablePredicate(mesh, controllerData.xrController.uniqueId)) {\r\n continue;\r\n }\r\n const result = WebXRNearInteraction.PickMeshWithSphere(mesh, sphere);\r\n\r\n if (result && result.hit && result.distance < pickingInfo.distance) {\r\n pickingInfo.hit = result.hit;\r\n pickingInfo.pickedMesh = mesh;\r\n pickingInfo.pickedPoint = result.pickedPoint;\r\n pickingInfo.aimTransform = controllerData.xrController.pointer;\r\n pickingInfo.gripTransform = controllerData.xrController.grip || null;\r\n pickingInfo.originMesh = controllerData.touchCollisionMesh;\r\n pickingInfo.distance = result.distance;\r\n }\r\n }\r\n }\r\n return pickingInfo;\r\n }\r\n\r\n /**\r\n * Picks a mesh with a sphere\r\n * @param mesh the mesh to pick\r\n * @param sphere picking sphere in world coordinates\r\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\r\n * @returns the picking info\r\n */\r\n public static PickMeshWithSphere(mesh: AbstractMesh, sphere: BoundingSphere, skipBoundingInfo = false): PickingInfo {\r\n const subMeshes = mesh.subMeshes;\r\n const pi = new PickingInfo();\r\n const boundingInfo = mesh.getBoundingInfo();\r\n\r\n if (!mesh._generatePointsArray()) {\r\n return pi;\r\n }\r\n\r\n if (!mesh.subMeshes || !boundingInfo) {\r\n return pi;\r\n }\r\n\r\n if (!skipBoundingInfo && !BoundingSphere.Intersects(boundingInfo.boundingSphere, sphere)) {\r\n return pi;\r\n }\r\n\r\n const result = TmpVectors.Vector3[0];\r\n const tmpVec = TmpVectors.Vector3[1];\r\n\r\n let distance = +Infinity;\r\n let tmp, tmpDistanceSphereToCenter, tmpDistanceSurfaceToCenter;\r\n const center = TmpVectors.Vector3[2];\r\n const worldToMesh = TmpVectors.Matrix[0];\r\n worldToMesh.copyFrom(mesh.getWorldMatrix());\r\n worldToMesh.invert();\r\n Vector3.TransformCoordinatesToRef(sphere.center, worldToMesh, center);\r\n\r\n for (let index = 0; index < subMeshes.length; index++) {\r\n const subMesh = subMeshes[index];\r\n\r\n subMesh.projectToRef(center, mesh._positions, mesh.getIndices(), tmpVec);\r\n\r\n Vector3.TransformCoordinatesToRef(tmpVec, mesh.getWorldMatrix(), tmpVec);\r\n tmp = Vector3.Distance(tmpVec, sphere.center);\r\n\r\n // Check for finger inside of mesh\r\n tmpDistanceSurfaceToCenter = Vector3.Distance(tmpVec, mesh.getAbsolutePosition());\r\n tmpDistanceSphereToCenter = Vector3.Distance(sphere.center, mesh.getAbsolutePosition());\r\n if (tmpDistanceSphereToCenter !== -1 && tmpDistanceSurfaceToCenter !== -1 && tmpDistanceSurfaceToCenter > tmpDistanceSphereToCenter) {\r\n tmp = 0;\r\n tmpVec.copyFrom(sphere.center);\r\n }\r\n\r\n if (tmp !== -1 && tmp < distance) {\r\n distance = tmp;\r\n result.copyFrom(tmpVec);\r\n }\r\n }\r\n\r\n if (distance < sphere.radius) {\r\n pi.hit = true;\r\n pi.distance = distance;\r\n pi.pickedMesh = mesh;\r\n pi.pickedPoint = result.clone();\r\n }\r\n\r\n return pi;\r\n }\r\n}\r\n\r\n//Register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRNearInteraction.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRNearInteraction(xrSessionManager, options);\r\n },\r\n WebXRNearInteraction.Version,\r\n true\r\n);\r\n","import { Constants } from \"../Engines/constants\";\r\nimport { TmpVectors, Vector3 } from \"../Maths/math.vector\";\r\nimport type { IndicesArray } from \"../types\";\r\nimport { SubMesh } from \"./subMesh\";\r\n\r\ndeclare module \"./subMesh\" {\r\n export interface SubMesh {\r\n /** @internal */\r\n _projectOnTrianglesToRef(vector: Vector3, positions: Vector3[], indices: IndicesArray, step: number, checkStopper: boolean, ref: Vector3): number;\r\n /** @internal */\r\n _projectOnUnIndexedTrianglesToRef(vector: Vector3, positions: Vector3[], indices: IndicesArray, ref: Vector3): number;\r\n /**\r\n * Projects a point on this submesh and stores the result in \"ref\"\r\n *\r\n * @param vector point to project\r\n * @param positions defines mesh's positions array\r\n * @param indices defines mesh's indices array\r\n * @param ref vector that will store the result\r\n * @returns distance from the point and the submesh, or -1 if the mesh rendering mode doesn't support projections\r\n */\r\n projectToRef(vector: Vector3, positions: Vector3[], indices: IndicesArray, ref: Vector3): number;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nSubMesh.prototype._projectOnTrianglesToRef = function (vector: Vector3, positions: Vector3[], indices: IndicesArray, step: number, checkStopper: boolean, ref: Vector3): number {\r\n // Triangles test\r\n const proj = TmpVectors.Vector3[0];\r\n const tmp = TmpVectors.Vector3[1];\r\n let distance = +Infinity;\r\n\r\n for (let index = this.indexStart; index < this.indexStart + this.indexCount - (3 - step); index += step) {\r\n const indexA = indices[index];\r\n const indexB = indices[index + 1];\r\n const indexC = indices[index + 2];\r\n\r\n if (checkStopper && indexC === 0xffffffff) {\r\n index += 2;\r\n continue;\r\n }\r\n\r\n const p0 = positions[indexA];\r\n const p1 = positions[indexB];\r\n const p2 = positions[indexC];\r\n\r\n // stay defensive and don't check against undefined positions.\r\n if (!p0 || !p1 || !p2) {\r\n continue;\r\n }\r\n\r\n const tmpDist = Vector3.ProjectOnTriangleToRef(vector, p0, p1, p2, tmp);\r\n if (tmpDist < distance) {\r\n proj.copyFrom(tmp);\r\n distance = tmpDist;\r\n }\r\n }\r\n\r\n ref.copyFrom(proj);\r\n\r\n return distance;\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nSubMesh.prototype._projectOnUnIndexedTrianglesToRef = function (vector: Vector3, positions: Vector3[], indices: IndicesArray, ref: Vector3): number {\r\n // Triangles test\r\n const proj = TmpVectors.Vector3[0];\r\n const tmp = TmpVectors.Vector3[1];\r\n let distance = +Infinity;\r\n\r\n for (let index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 3) {\r\n const p0 = positions[index];\r\n const p1 = positions[index + 1];\r\n const p2 = positions[index + 2];\r\n\r\n const tmpDist = Vector3.ProjectOnTriangleToRef(vector, p0, p1, p2, tmp);\r\n if (tmpDist < distance) {\r\n proj.copyFrom(tmp);\r\n distance = tmpDist;\r\n }\r\n }\r\n\r\n ref.copyFrom(proj);\r\n\r\n return distance;\r\n};\r\n\r\nSubMesh.prototype.projectToRef = function (vector: Vector3, positions: Vector3[], indices: IndicesArray, ref: Vector3): number {\r\n const material = this.getMaterial();\r\n if (!material) {\r\n return -1;\r\n }\r\n let step = 3;\r\n let checkStopper = false;\r\n\r\n switch (material.fillMode) {\r\n case Constants.MATERIAL_PointListDrawMode:\r\n case Constants.MATERIAL_LineLoopDrawMode:\r\n case Constants.MATERIAL_LineStripDrawMode:\r\n case Constants.MATERIAL_TriangleFanDrawMode:\r\n return -1;\r\n case Constants.MATERIAL_TriangleStripDrawMode:\r\n step = 1;\r\n checkStopper = true;\r\n break;\r\n default:\r\n break;\r\n }\r\n\r\n // LineMesh first as it's also a Mesh...\r\n if (material.fillMode === Constants.MATERIAL_LineListDrawMode) {\r\n return -1;\r\n } else {\r\n // Check if mesh is unindexed\r\n if (!indices.length && (this as any)._mesh._unIndexed) {\r\n return this._projectOnUnIndexedTrianglesToRef(vector, positions, indices, ref);\r\n }\r\n\r\n return this._projectOnTrianglesToRef(vector, positions, indices, step, checkStopper, ref);\r\n }\r\n};\r\n","import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { WebXRExperienceHelper } from \"./webXRExperienceHelper\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { Tools } from \"../Misc/tools\";\r\n/**\r\n * Button which can be used to enter a different mode of XR\r\n */\r\nexport class WebXREnterExitUIButton {\r\n /**\r\n * Creates a WebXREnterExitUIButton\r\n * @param element button element\r\n * @param sessionMode XR initialization session mode\r\n * @param referenceSpaceType the type of reference space to be used\r\n */\r\n constructor(\r\n /** button element */\r\n public element: HTMLElement,\r\n /** XR initialization options for the button */\r\n public sessionMode: XRSessionMode,\r\n /** Reference space type */\r\n public referenceSpaceType: XRReferenceSpaceType\r\n ) {}\r\n\r\n /**\r\n * Extendable function which can be used to update the button's visuals when the state changes\r\n * @param activeButton the current active button in the UI\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public update(activeButton: Nullable) {}\r\n}\r\n\r\n/**\r\n * Options to create the webXR UI\r\n */\r\nexport class WebXREnterExitUIOptions {\r\n /**\r\n * User provided buttons to enable/disable WebXR. The system will provide default if not set\r\n */\r\n customButtons?: Array;\r\n /**\r\n * A reference space type to use when creating the default button.\r\n * Default is local-floor\r\n */\r\n referenceSpaceType?: XRReferenceSpaceType;\r\n /**\r\n * Context to enter xr with\r\n */\r\n renderTarget?: Nullable;\r\n /**\r\n * A session mode to use when creating the default button.\r\n * Default is immersive-vr\r\n */\r\n sessionMode?: XRSessionMode;\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n */\r\n optionalFeatures?: string[];\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n */\r\n requiredFeatures?: string[];\r\n\r\n /**\r\n * If set, the `sessiongranted` event will not be registered. `sessiongranted` is used to move seamlessly between WebXR experiences.\r\n * If set to true the user will be forced to press the \"enter XR\" button even if sessiongranted event was triggered.\r\n * If not set and a sessiongranted event was triggered, the XR session will start automatically.\r\n */\r\n ignoreSessionGrantedEvent?: boolean;\r\n\r\n /**\r\n * If defined, this function will be executed if the UI encounters an error when entering XR\r\n */\r\n onError?: (error: any) => void;\r\n}\r\n/**\r\n * UI to allow the user to enter/exit XR mode\r\n */\r\nexport class WebXREnterExitUI implements IDisposable {\r\n private _activeButton: Nullable = null;\r\n private _buttons: Array = [];\r\n private _helper: WebXRExperienceHelper;\r\n private _renderTarget?: WebXRRenderTarget;\r\n /**\r\n * The HTML Div Element to which buttons are added.\r\n */\r\n public readonly overlay: HTMLDivElement;\r\n\r\n /**\r\n * Fired every time the active button is changed.\r\n *\r\n * When xr is entered via a button that launches xr that button will be the callback parameter\r\n *\r\n * When exiting xr the callback parameter will be null)\r\n */\r\n public activeButtonChangedObservable = new Observable>();\r\n\r\n /**\r\n * Construct a new EnterExit UI class\r\n *\r\n * @param _scene babylon scene object to use\r\n * @param options (read-only) version of the options passed to this UI\r\n */\r\n public constructor(\r\n private _scene: Scene,\r\n /** version of the options passed to this UI */\r\n public options: WebXREnterExitUIOptions\r\n ) {\r\n this.overlay = document.createElement(\"div\");\r\n this.overlay.classList.add(\"xr-button-overlay\");\r\n\r\n // prepare for session granted event\r\n if (!options.ignoreSessionGrantedEvent && (navigator as any).xr) {\r\n (navigator as any).xr.addEventListener(\"sessiongranted\", this._onSessionGranted);\r\n }\r\n\r\n // if served over HTTP, warn people.\r\n // Hopefully the browsers will catch up\r\n if (typeof window !== \"undefined\") {\r\n if (window.location && window.location.protocol === \"http:\" && window.location.hostname !== \"localhost\") {\r\n Tools.Warn(\"WebXR can only be served over HTTPS\");\r\n throw new Error(\"WebXR can only be served over HTTPS\");\r\n }\r\n }\r\n\r\n if (options.customButtons) {\r\n this._buttons = options.customButtons;\r\n } else {\r\n this.overlay.style.cssText = \"z-index:11;position: absolute; right: 20px;bottom: 50px;\";\r\n const sessionMode = options.sessionMode || \"immersive-vr\";\r\n const referenceSpaceType = options.referenceSpaceType || \"local-floor\";\r\n const url =\r\n typeof SVGSVGElement === \"undefined\"\r\n ? \"https://cdn.babylonjs.com/Assets/vrButton.png\"\r\n : \"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A\";\r\n let css =\r\n \".babylonVRicon { color: #868686; border-color: #868686; border-style: solid; margin-left: 10px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(\" +\r\n url +\r\n \"); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }\";\r\n css += '.babylonVRicon.vrdisplaypresenting { background-image: none;} .vrdisplaypresenting::after { content: \"EXIT\"} .xr-error::after { content: \"ERROR\"}';\r\n\r\n const style = document.createElement(\"style\");\r\n style.appendChild(document.createTextNode(css));\r\n document.getElementsByTagName(\"head\")[0].appendChild(style);\r\n const hmdBtn = document.createElement(\"button\");\r\n hmdBtn.className = \"babylonVRicon\";\r\n hmdBtn.title = `${sessionMode} - ${referenceSpaceType}`;\r\n this._buttons.push(new WebXREnterExitUIButton(hmdBtn, sessionMode, referenceSpaceType));\r\n this._buttons[this._buttons.length - 1].update = function (activeButton: WebXREnterExitUIButton) {\r\n this.element.style.display = activeButton === null || activeButton === this ? \"\" : \"none\";\r\n hmdBtn.className = \"babylonVRicon\" + (activeButton === this ? \" vrdisplaypresenting\" : \"\");\r\n };\r\n this._updateButtons(null);\r\n }\r\n\r\n const renderCanvas = _scene.getEngine().getInputElement();\r\n if (renderCanvas && renderCanvas.parentNode) {\r\n renderCanvas.parentNode.appendChild(this.overlay);\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Set the helper to be used with this UI component.\r\n * The UI is bound to an experience helper. If not provided the UI can still be used but the events should be registered by the developer.\r\n *\r\n * @param helper the experience helper to attach\r\n * @param renderTarget an optional render target (in case it is created outside of the helper scope)\r\n * @returns a promise that resolves when the ui is ready\r\n */\r\n public async setHelperAsync(helper: WebXRExperienceHelper, renderTarget?: WebXRRenderTarget): Promise {\r\n this._helper = helper;\r\n this._renderTarget = renderTarget;\r\n const supportedPromises = this._buttons.map((btn) => {\r\n return helper.sessionManager.isSessionSupportedAsync(btn.sessionMode);\r\n });\r\n helper.onStateChangedObservable.add((state) => {\r\n if (state == WebXRState.NOT_IN_XR) {\r\n this._updateButtons(null);\r\n }\r\n });\r\n const results = await Promise.all(supportedPromises);\r\n results.forEach((supported, i) => {\r\n if (supported) {\r\n this.overlay.appendChild(this._buttons[i].element);\r\n this._buttons[i].element.onclick = this._enterXRWithButtonIndex.bind(this, i);\r\n } else {\r\n Tools.Warn(`Session mode \"${this._buttons[i].sessionMode}\" not supported in browser`);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Creates UI to allow the user to enter/exit XR mode\r\n * @param scene the scene to add the ui to\r\n * @param helper the xr experience helper to enter/exit xr with\r\n * @param options options to configure the UI\r\n * @returns the created ui\r\n */\r\n public static async CreateAsync(scene: Scene, helper: WebXRExperienceHelper, options: WebXREnterExitUIOptions): Promise {\r\n const ui = new WebXREnterExitUI(scene, options);\r\n await ui.setHelperAsync(helper, options.renderTarget || undefined);\r\n return ui;\r\n }\r\n\r\n private async _enterXRWithButtonIndex(idx: number = 0) {\r\n if (this._helper.state == WebXRState.IN_XR) {\r\n await this._helper.exitXRAsync();\r\n this._updateButtons(null);\r\n } else if (this._helper.state == WebXRState.NOT_IN_XR) {\r\n try {\r\n await this._helper.enterXRAsync(this._buttons[idx].sessionMode, this._buttons[idx].referenceSpaceType, this._renderTarget, {\r\n optionalFeatures: this.options.optionalFeatures,\r\n requiredFeatures: this.options.requiredFeatures,\r\n });\r\n this._updateButtons(this._buttons[idx]);\r\n } catch (e) {\r\n // make sure button is visible\r\n this._updateButtons(null);\r\n const element = this._buttons[idx].element;\r\n const prevTitle = element.title;\r\n element.title = \"Error entering XR session : \" + prevTitle;\r\n element.classList.add(\"xr-error\");\r\n if (this.options.onError) {\r\n this.options.onError(e);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the XR UI component\r\n */\r\n public dispose() {\r\n const renderCanvas = this._scene.getEngine().getInputElement();\r\n if (renderCanvas && renderCanvas.parentNode && renderCanvas.parentNode.contains(this.overlay)) {\r\n renderCanvas.parentNode.removeChild(this.overlay);\r\n }\r\n this.activeButtonChangedObservable.clear();\r\n (navigator as any).xr.removeEventListener(\"sessiongranted\", this._onSessionGranted);\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _onSessionGranted = (evt: { session: XRSession }) => {\r\n // This section is for future reference.\r\n // As per specs, evt.session.mode should have the supported session mode, but no browser supports it for now.\r\n\r\n // // check if the session granted is the same as the one requested\r\n // const grantedMode = (evt.session as any).mode;\r\n // if (grantedMode) {\r\n // this._buttons.some((btn, idx) => {\r\n // if (btn.sessionMode === grantedMode) {\r\n // this._enterXRWithButtonIndex(idx);\r\n // return true;\r\n // }\r\n // return false;\r\n // });\r\n // } else\r\n\r\n if (this._helper) {\r\n this._enterXRWithButtonIndex(0);\r\n }\r\n };\r\n\r\n private _updateButtons(activeButton: Nullable) {\r\n this._activeButton = activeButton;\r\n this._buttons.forEach((b) => {\r\n b.update(this._activeButton);\r\n });\r\n this.activeButtonChangedObservable.notifyObservers(this._activeButton);\r\n }\r\n}\r\n","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 /** @internal */\r\n public _indexInSourceMeshInstanceArray = -1;\r\n /** @internal */\r\n public _distanceToCamera: number = 0;\r\n /** @internal */\r\n public _previousWorldMatrix: Nullable;\r\n\r\n /**\r\n * Creates a new InstancedMesh object from the mesh source.\r\n * @param name defines the name of the instance\r\n * @param source the mesh to create the instance from\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 = source.animations.slice();\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 public set receiveShadows(_value: boolean) {\r\n if (this._sourceMesh?.receiveShadows !== _value) {\r\n Tools.Warn(\"Setting receiveShadows on an instanced mesh has no effect\");\r\n }\r\n }\r\n\r\n /**\r\n * The material of the source mesh\r\n */\r\n public get material(): Nullable {\r\n return this._sourceMesh.material;\r\n }\r\n\r\n public set material(_value: Nullable) {\r\n if (this._sourceMesh?.material !== _value) {\r\n Tools.Warn(\"Setting material on an instanced mesh has no effect\");\r\n }\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 public set visibility(_value: number) {\r\n if (this._sourceMesh?.visibility !== _value) {\r\n Tools.Warn(\"Setting visibility on an instanced mesh has no effect\");\r\n }\r\n }\r\n\r\n /**\r\n * Skeleton of the source mesh\r\n */\r\n public get skeleton(): Nullable {\r\n return this._sourceMesh.skeleton;\r\n }\r\n\r\n public set skeleton(_value: Nullable) {\r\n if (this._sourceMesh?.skeleton !== _value) {\r\n Tools.Warn(\"Setting skeleton on an instanced mesh has no effect\");\r\n }\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/features/featuresDeepDive/mesh/copies/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 * @returns {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 * @param forceCopy defines a boolean forcing the copy of the buffer no matter what the value of copyWhenShared is\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, forceCopy?: boolean): Nullable {\r\n return this._sourceMesh.getVerticesData(kind, copyWhenShared, forceCopy);\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 = 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 {\r\n return this._sourceMesh.getIndices();\r\n }\r\n\r\n public get _positions(): Nullable {\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 /** @internal */\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 * @internal\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 /** @internal */\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 = this.sourceMesh.getLOD(camera, boundingInfo.boundingSphere);\r\n }\r\n\r\n return this._currentLOD;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _preActivateForIntermediateRendering(renderId: number): Mesh {\r\n return this.sourceMesh._preActivateForIntermediateRendering(renderId);\r\n }\r\n\r\n /** @internal */\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 /** @internal */\r\n public _generatePointsArray(): boolean {\r\n return this._sourceMesh._generatePointsArray();\r\n }\r\n\r\n /** @internal */\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 *\r\n * Returns the clone.\r\n * @param name the cloned mesh name\r\n * @param newParent the optional Node to parent the clone to.\r\n * @param doNotCloneChildren if `true` the model children aren't cloned.\r\n * @param newSourceMesh if set this mesh will be used as the source mesh instead of ths instance's one\r\n * @returns the clone\r\n */\r\n public clone(name: string, newParent: Nullable = null, doNotCloneChildren?: boolean, newSourceMesh?: Mesh): InstancedMesh {\r\n const result = (newSourceMesh || 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\n * @internal\r\n */\r\n public _serializeAsParent(serializationObject: any) {\r\n super._serializeAsParent(serializationObject);\r\n\r\n serializationObject.parentId = this._sourceMesh.uniqueId;\r\n serializationObject.parentInstanceIndex = this._indexInSourceMeshInstanceArray;\r\n }\r\n\r\n /**\r\n * Instantiate (when possible) or clone that node with its hierarchy\r\n * @param newParent defines the new parent to use for the instance (or clone)\r\n * @param options defines options to configure how copy is done\r\n * @param options.doNotInstantiate defines if the model must be instantiated or just cloned\r\n * @param options.newSourcedMesh newSourcedMesh the new source mesh for the instance (or clone)\r\n * @param onNewNodeCreated defines an option callback to call when a clone or an instance is created\r\n * @returns an instance (or a clone) of the current node with its hierarchy\r\n */\r\n public instantiateHierarchy(\r\n newParent: Nullable = null,\r\n options?: { doNotInstantiate: boolean | ((node: TransformNode) => boolean); newSourcedMesh?: Mesh },\r\n onNewNodeCreated?: (source: TransformNode, clone: TransformNode) => void\r\n ): Nullable {\r\n const clone = this.clone(\"Clone of \" + (this.name || this.id), newParent || this.parent, true, options && options.newSourcedMesh);\r\n\r\n if (clone) {\r\n if (onNewNodeCreated) {\r\n onNewNodeCreated(this, clone);\r\n }\r\n }\r\n\r\n for (const child of this.getChildTransformNodes(true)) {\r\n child.instantiateHierarchy(clone, options, onNewNodeCreated);\r\n }\r\n\r\n return clone;\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/features/featuresDeepDive/mesh/copies/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 /** @internal */\r\n _userInstancedBuffersStorage: {\r\n data: { [key: string]: Float32Array };\r\n sizes: { [key: string]: number };\r\n vertexBuffers: { [key: string]: Nullable };\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/features/featuresDeepDive/mesh/copies/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 if (!this._userInstancedBuffersStorage) {\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\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 this._markSubMeshesAsAttributesDirty();\r\n};\r\n\r\nMesh.prototype._processInstancedBuffers = function (visibleInstances: Nullable, renderSelf: boolean) {\r\n const instanceCount = visibleInstances ? visibleInstances.length : 0;\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","import { SerializationHelper } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3, Vector2, Vector4, Quaternion } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { MaterialHelper } from \"./materialHelper\";\r\nimport type { Effect, IEffectCreationOptions } from \"./effect\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport { EffectFallbacks } from \"./effectFallbacks\";\r\nimport { WebRequest } from \"../Misc/webRequest\";\r\nimport type { ShaderLanguage } from \"./shaderLanguage\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { TextureSampler } from \"./Textures/textureSampler\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { PushMaterial } from \"./pushMaterial\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { addClipPlaneUniforms, bindClipPlane, prepareStringDefinesForClipPlanes } from \"./clipPlaneMaterialHelper\";\r\n\r\nimport type { ExternalTexture } from \"./Textures/externalTexture\";\r\n\r\nconst onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable };\r\n\r\n/**\r\n * Defines the options associated with the creation of a shader material.\r\n */\r\nexport interface IShaderMaterialOptions {\r\n /**\r\n * Does the material work in alpha blend mode\r\n */\r\n needAlphaBlending: boolean;\r\n\r\n /**\r\n * Does the material work in alpha test mode\r\n */\r\n needAlphaTesting: boolean;\r\n\r\n /**\r\n * The list of attribute names used in the shader\r\n */\r\n attributes: string[];\r\n\r\n /**\r\n * The list of uniform names used in the shader\r\n */\r\n uniforms: string[];\r\n\r\n /**\r\n * The list of UBO names used in the shader\r\n */\r\n uniformBuffers: string[];\r\n\r\n /**\r\n * The list of sampler (texture) names used in the shader\r\n */\r\n samplers: string[];\r\n\r\n /**\r\n * The list of external texture names used in the shader\r\n */\r\n externalTextures: string[];\r\n\r\n /**\r\n * The list of sampler object names used in the shader\r\n */\r\n samplerObjects: string[];\r\n\r\n /**\r\n * The list of storage buffer names used in the shader\r\n */\r\n storageBuffers: string[];\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines: string[];\r\n\r\n /**\r\n * Defines if clip planes have to be turned on: true to turn them on, false to turn them off and null to turn them on/off depending on the scene configuration (scene.clipPlaneX)\r\n */\r\n useClipPlane: Nullable;\r\n\r\n /**\r\n * The language the shader is written in (default: GLSL)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n}\r\n\r\n/**\r\n * The ShaderMaterial object has the necessary methods to pass data from your scene to the Vertex and Fragment Shaders and returns a material that can be applied to any mesh.\r\n *\r\n * This returned material effects how the mesh will look based on the code in the shaders.\r\n *\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial\r\n */\r\nexport class ShaderMaterial extends PushMaterial {\r\n private _shaderPath: any;\r\n private _options: IShaderMaterialOptions;\r\n private _textures: { [name: string]: BaseTexture } = {};\r\n private _textureArrays: { [name: string]: BaseTexture[] } = {};\r\n private _externalTextures: { [name: string]: ExternalTexture } = {};\r\n private _floats: { [name: string]: number } = {};\r\n private _ints: { [name: string]: number } = {};\r\n private _uints: { [name: string]: number } = {};\r\n private _floatsArrays: { [name: string]: number[] } = {};\r\n private _colors3: { [name: string]: Color3 } = {};\r\n private _colors3Arrays: { [name: string]: number[] } = {};\r\n private _colors4: { [name: string]: Color4 } = {};\r\n private _colors4Arrays: { [name: string]: number[] } = {};\r\n private _vectors2: { [name: string]: Vector2 } = {};\r\n private _vectors3: { [name: string]: Vector3 } = {};\r\n private _vectors4: { [name: string]: Vector4 } = {};\r\n private _quaternions: { [name: string]: Quaternion } = {};\r\n private _quaternionsArrays: { [name: string]: number[] } = {};\r\n private _matrices: { [name: string]: Matrix } = {};\r\n private _matrixArrays: { [name: string]: Float32Array | Array } = {};\r\n private _matrices3x3: { [name: string]: Float32Array | Array } = {};\r\n private _matrices2x2: { [name: string]: Float32Array | Array } = {};\r\n private _vectors2Arrays: { [name: string]: number[] } = {};\r\n private _vectors3Arrays: { [name: string]: number[] } = {};\r\n private _vectors4Arrays: { [name: string]: number[] } = {};\r\n private _uniformBuffers: { [name: string]: UniformBuffer } = {};\r\n private _textureSamplers: { [name: string]: TextureSampler } = {};\r\n private _storageBuffers: { [name: string]: StorageBuffer } = {};\r\n private _cachedWorldViewMatrix = new Matrix();\r\n private _cachedWorldViewProjectionMatrix = new Matrix();\r\n private _multiview = false;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _materialHelperNeedsPreviousMatrices = false;\r\n\r\n /** Define the Url to load snippets */\r\n public static SnippetUrl = Constants.SnippetUrl;\r\n\r\n /** Snippet ID if the material was created from the snippet server */\r\n public snippetId: string;\r\n\r\n /**\r\n * Instantiate a new shader material.\r\n * The ShaderMaterial object has the necessary methods to pass data from your scene to the Vertex and Fragment Shaders and returns a material that can be applied to any mesh.\r\n * This returned material effects how the mesh will look based on the code in the shaders.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial\r\n * @param name Define the name of the material in the scene\r\n * @param scene Define the scene the material belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ vertex: \"custom\", fragment: \"custom\" \\}, used with Effect.ShadersStore[\"customVertexShader\"] and Effect.ShadersStore[\"customFragmentShader\"]\r\n * * object: \\{ vertexElement: \"vertexShaderCode\", fragmentElement: \"fragmentShaderCode\" \\}, used with shader code in script tags\r\n * * object: \\{ vertexSource: \"vertex shader code string\", fragmentSource: \"fragment shader code string\" \\} using with strings containing the shaders code\r\n * * string: \"./COMMON_NAME\", used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n * @param storeEffectOnSubMeshes true to store effect on submeshes, false to store the effect directly in the material class.\r\n */\r\n constructor(name: string, scene: Scene, shaderPath: any, options: Partial = {}, storeEffectOnSubMeshes = true) {\r\n super(name, scene, storeEffectOnSubMeshes);\r\n this._shaderPath = shaderPath;\r\n\r\n this._options = {\r\n needAlphaBlending: false,\r\n needAlphaTesting: false,\r\n attributes: [\"position\", \"normal\", \"uv\"],\r\n uniforms: [\"worldViewProjection\"],\r\n uniformBuffers: [],\r\n samplers: [],\r\n externalTextures: [],\r\n samplerObjects: [],\r\n storageBuffers: [],\r\n defines: [],\r\n useClipPlane: false,\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the shader path used to define the shader code\r\n * It can be modified to trigger a new compilation\r\n */\r\n public get shaderPath(): any {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * Sets the shader path used to define the shader code\r\n * It can be modified to trigger a new compilation\r\n */\r\n public set shaderPath(shaderPath: any) {\r\n this._shaderPath = shaderPath;\r\n }\r\n\r\n /**\r\n * Gets the options used to compile the shader.\r\n * They can be modified to trigger a new compilation\r\n */\r\n public get options(): IShaderMaterialOptions {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * is multiview set to true?\r\n */\r\n public get isMultiview(): boolean {\r\n return this._multiview;\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ShaderMaterial\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ShaderMaterial\";\r\n }\r\n\r\n /**\r\n * Specifies if the material will require alpha blending\r\n * @returns a boolean specifying if alpha blending is needed\r\n */\r\n public needAlphaBlending(): boolean {\r\n return this.alpha < 1.0 || this._options.needAlphaBlending;\r\n }\r\n\r\n /**\r\n * Specifies if this material should be rendered in alpha test mode\r\n * @returns a boolean specifying if an alpha test is needed.\r\n */\r\n public needAlphaTesting(): boolean {\r\n return this._options.needAlphaTesting;\r\n }\r\n\r\n private _checkUniform(uniformName: string): void {\r\n if (this._options.uniforms.indexOf(uniformName) === -1) {\r\n this._options.uniforms.push(uniformName);\r\n }\r\n }\r\n\r\n /**\r\n * Set a texture in the shader.\r\n * @param name Define the name of the uniform samplers as defined in the shader\r\n * @param texture Define the texture to bind to this sampler\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setTexture(name: string, texture: BaseTexture): ShaderMaterial {\r\n if (this._options.samplers.indexOf(name) === -1) {\r\n this._options.samplers.push(name);\r\n }\r\n this._textures[name] = texture;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a texture array in the shader.\r\n * @param name Define the name of the uniform sampler array as defined in the shader\r\n * @param textures Define the list of textures to bind to this sampler\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setTextureArray(name: string, textures: BaseTexture[]): ShaderMaterial {\r\n if (this._options.samplers.indexOf(name) === -1) {\r\n this._options.samplers.push(name);\r\n }\r\n\r\n this._checkUniform(name);\r\n\r\n this._textureArrays[name] = textures;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set an internal texture in the shader.\r\n * @param name Define the name of the uniform samplers as defined in the shader\r\n * @param texture Define the texture to bind to this sampler\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setExternalTexture(name: string, texture: ExternalTexture): ShaderMaterial {\r\n if (this._options.externalTextures.indexOf(name) === -1) {\r\n this._options.externalTextures.push(name);\r\n }\r\n this._externalTextures[name] = texture;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a float in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setFloat(name: string, value: number): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._floats[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a int in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setInt(name: string, value: number): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._ints[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a unsigned int in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setUInt(name: string, value: number): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._uints[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set an array of floats in the shader.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setFloats(name: string, value: number[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._floatsArrays[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec3 in the shader from a Color3.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setColor3(name: string, value: Color3): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._colors3[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec3 array in the shader from a Color3 array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setColor3Array(name: string, value: Color3[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._colors3Arrays[name] = value.reduce((arr, color) => {\r\n color.toArray(arr, arr.length);\r\n return arr;\r\n }, []);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 in the shader from a Color4.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setColor4(name: string, value: Color4): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._colors4[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 array in the shader from a Color4 array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setColor4Array(name: string, value: Color4[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._colors4Arrays[name] = value.reduce((arr, color) => {\r\n color.toArray(arr, arr.length);\r\n return arr;\r\n }, []);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec2 in the shader from a Vector2.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setVector2(name: string, value: Vector2): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._vectors2[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec3 in the shader from a Vector3.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setVector3(name: string, value: Vector3): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._vectors3[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 in the shader from a Vector4.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setVector4(name: string, value: Vector4): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._vectors4[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 in the shader from a Quaternion.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setQuaternion(name: string, value: Quaternion): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._quaternions[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 array in the shader from a Quaternion array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setQuaternionArray(name: string, value: Quaternion[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._quaternionsArrays[name] = value.reduce((arr, quaternion) => {\r\n quaternion.toArray(arr, arr.length);\r\n return arr;\r\n }, []);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a mat4 in the shader from a Matrix.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setMatrix(name: string, value: Matrix): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._matrices[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a float32Array in the shader from a matrix array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setMatrices(name: string, value: Matrix[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n\r\n const float32Array = new Float32Array(value.length * 16);\r\n\r\n for (let index = 0; index < value.length; index++) {\r\n const matrix = value[index];\r\n\r\n matrix.copyToArray(float32Array, index * 16);\r\n }\r\n\r\n this._matrixArrays[name] = float32Array;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a mat3 in the shader from a Float32Array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setMatrix3x3(name: string, value: Float32Array | Array): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._matrices3x3[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a mat2 in the shader from a Float32Array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setMatrix2x2(name: string, value: Float32Array | Array): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._matrices2x2[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec2 array in the shader from a number array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setArray2(name: string, value: number[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._vectors2Arrays[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec3 array in the shader from a number array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setArray3(name: string, value: number[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._vectors3Arrays[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a vec4 array in the shader from a number array.\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param value Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setArray4(name: string, value: number[]): ShaderMaterial {\r\n this._checkUniform(name);\r\n this._vectors4Arrays[name] = value;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a uniform buffer in the shader\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param buffer Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer): ShaderMaterial {\r\n if (this._options.uniformBuffers.indexOf(name) === -1) {\r\n this._options.uniformBuffers.push(name);\r\n }\r\n this._uniformBuffers[name] = buffer;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a texture sampler in the shader\r\n * @param name Define the name of the uniform as defined in the shader\r\n * @param sampler Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): ShaderMaterial {\r\n if (this._options.samplerObjects.indexOf(name) === -1) {\r\n this._options.samplerObjects.push(name);\r\n }\r\n this._textureSamplers[name] = sampler;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set a storage buffer in the shader\r\n * @param name Define the name of the storage buffer as defined in the shader\r\n * @param buffer Define the value to give to the uniform\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer): ShaderMaterial {\r\n if (this._options.storageBuffers.indexOf(name) === -1) {\r\n this._options.storageBuffers.push(name);\r\n }\r\n this._storageBuffers[name] = buffer;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds, removes, or replaces the specified shader define and value.\r\n * * setDefine(\"MY_DEFINE\", true); // enables a boolean define\r\n * * setDefine(\"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)\r\n * * setDefine(\"MY_DEFINE\", false); // disables and removes the define\r\n * Note if the active defines do change, the shader will be recompiled and this can be expensive.\r\n * @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.\r\n * @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\r\n * @returns the material itself allowing \"fluent\" like uniform updates\r\n */\r\n public setDefine(define: string, value: boolean | string): ShaderMaterial {\r\n // First remove any existing define with this name.\r\n const defineName = define.trimEnd() + \" \";\r\n const existingDefineIdx = this.options.defines.findIndex((x) => x === define || x.startsWith(defineName));\r\n if (existingDefineIdx >= 0) {\r\n this.options.defines.splice(existingDefineIdx, 1);\r\n }\r\n\r\n // Then add the new define value. (If it's a boolean value and false, don't add it.)\r\n if (typeof value !== \"boolean\" || value) {\r\n this.options.defines.push(defineName + value);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used\r\n * @param mesh defines the mesh to check\r\n * @param subMesh defines which submesh to check\r\n * @param useInstances specifies that instances should be used\r\n * @returns a boolean indicating that the submesh is ready or not\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n return this.isReady(mesh, useInstances, subMesh);\r\n }\r\n\r\n /**\r\n * Checks if the material is ready to render the requested mesh\r\n * @param mesh Define the mesh to render\r\n * @param useInstances Define whether or not the material is used with instances\r\n * @param subMesh defines which submesh to render\r\n * @returns true if ready, otherwise false\r\n */\r\n public isReady(mesh?: AbstractMesh, useInstances?: boolean, subMesh?: SubMesh): boolean {\r\n const storeEffectOnSubMeshes = subMesh && this._storeEffectOnSubMeshes;\r\n\r\n if (this.isFrozen) {\r\n if (storeEffectOnSubMeshes) {\r\n if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {\r\n return true;\r\n }\r\n } else {\r\n const effect = this._drawWrapper.effect;\r\n if (effect && effect._wasPreviouslyReady && effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n const scene = this.getScene();\r\n const engine = scene.getEngine();\r\n\r\n // Instances\r\n const defines = [];\r\n const attribs = [];\r\n const fallbacks = new EffectFallbacks();\r\n\r\n let shaderName = this._shaderPath,\r\n uniforms = this._options.uniforms,\r\n uniformBuffers = this._options.uniformBuffers,\r\n samplers = this._options.samplers;\r\n\r\n // global multiview\r\n if (engine.getCaps().multiview && scene.activeCamera && scene.activeCamera.outputRenderTarget && scene.activeCamera.outputRenderTarget.getViewCount() > 1) {\r\n this._multiview = true;\r\n defines.push(\"#define MULTIVIEW\");\r\n if (this._options.uniforms.indexOf(\"viewProjection\") !== -1 && this._options.uniforms.indexOf(\"viewProjectionR\") === -1) {\r\n this._options.uniforms.push(\"viewProjectionR\");\r\n }\r\n }\r\n\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n const defineToAdd = this._options.defines[index].indexOf(\"#define\") === 0 ? this._options.defines[index] : `#define ${this._options.defines[index]}`;\r\n defines.push(defineToAdd);\r\n }\r\n\r\n for (let index = 0; index < this._options.attributes.length; index++) {\r\n attribs.push(this._options.attributes[index]);\r\n }\r\n\r\n if (mesh && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {\r\n attribs.push(VertexBuffer.ColorKind);\r\n defines.push(\"#define VERTEXCOLOR\");\r\n }\r\n\r\n if (useInstances) {\r\n defines.push(\"#define INSTANCES\");\r\n MaterialHelper.PushAttributesForInstances(attribs, this._materialHelperNeedsPreviousMatrices);\r\n if (mesh?.hasThinInstances) {\r\n defines.push(\"#define THIN_INSTANCES\");\r\n if (mesh && mesh.isVerticesDataPresent(VertexBuffer.ColorInstanceKind)) {\r\n attribs.push(VertexBuffer.ColorInstanceKind);\r\n defines.push(\"#define INSTANCESCOLOR\");\r\n }\r\n }\r\n }\r\n\r\n // Bones\r\n if (mesh && mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n\r\n const skeleton = mesh.skeleton;\r\n\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n\r\n if (skeleton.isUsingTextureForMatrices) {\r\n defines.push(\"#define BONETEXTURE\");\r\n\r\n if (this._options.uniforms.indexOf(\"boneTextureWidth\") === -1) {\r\n this._options.uniforms.push(\"boneTextureWidth\");\r\n }\r\n\r\n if (this._options.samplers.indexOf(\"boneSampler\") === -1) {\r\n this._options.samplers.push(\"boneSampler\");\r\n }\r\n } else {\r\n defines.push(\"#define BonesPerMesh \" + (skeleton.bones.length + 1));\r\n\r\n if (this._options.uniforms.indexOf(\"mBones\") === -1) {\r\n this._options.uniforms.push(\"mBones\");\r\n }\r\n }\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph\r\n let numInfluencers = 0;\r\n const manager = mesh ? (mesh).morphTargetManager : null;\r\n if (manager) {\r\n const uv = manager.supportsUVs && defines.indexOf(\"#define UV1\") !== -1;\r\n const tangent = manager.supportsTangents && defines.indexOf(\"#define TANGENT\") !== -1;\r\n const normal = manager.supportsNormals && defines.indexOf(\"#define NORMAL\") !== -1;\r\n numInfluencers = manager.numInfluencers;\r\n if (uv) {\r\n defines.push(\"#define MORPHTARGETS_UV\");\r\n }\r\n if (tangent) {\r\n defines.push(\"#define MORPHTARGETS_TANGENT\");\r\n }\r\n if (normal) {\r\n defines.push(\"#define MORPHTARGETS_NORMAL\");\r\n }\r\n if (numInfluencers > 0) {\r\n defines.push(\"#define MORPHTARGETS\");\r\n }\r\n if (manager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n\r\n if (this._options.uniforms.indexOf(\"morphTargetTextureIndices\") === -1) {\r\n this._options.uniforms.push(\"morphTargetTextureIndices\");\r\n }\r\n\r\n if (this._options.samplers.indexOf(\"morphTargets\") === -1) {\r\n this._options.samplers.push(\"morphTargets\");\r\n }\r\n }\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numInfluencers);\r\n for (let index = 0; index < numInfluencers; index++) {\r\n attribs.push(VertexBuffer.PositionKind + index);\r\n\r\n if (normal) {\r\n attribs.push(VertexBuffer.NormalKind + index);\r\n }\r\n\r\n if (tangent) {\r\n attribs.push(VertexBuffer.TangentKind + index);\r\n }\r\n\r\n if (uv) {\r\n attribs.push(VertexBuffer.UVKind + \"_\" + index);\r\n }\r\n }\r\n if (numInfluencers > 0) {\r\n uniforms = uniforms.slice();\r\n uniforms.push(\"morphTargetInfluences\");\r\n uniforms.push(\"morphTargetTextureInfo\");\r\n uniforms.push(\"morphTargetTextureIndices\");\r\n }\r\n } else {\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS 0\");\r\n }\r\n\r\n // Baked Vertex Animation\r\n if (mesh) {\r\n const bvaManager = (mesh).bakedVertexAnimationManager;\r\n\r\n if (bvaManager && bvaManager.isEnabled) {\r\n defines.push(\"#define BAKED_VERTEX_ANIMATION_TEXTURE\");\r\n if (this._options.uniforms.indexOf(\"bakedVertexAnimationSettings\") === -1) {\r\n this._options.uniforms.push(\"bakedVertexAnimationSettings\");\r\n }\r\n if (this._options.uniforms.indexOf(\"bakedVertexAnimationTextureSizeInverted\") === -1) {\r\n this._options.uniforms.push(\"bakedVertexAnimationTextureSizeInverted\");\r\n }\r\n if (this._options.uniforms.indexOf(\"bakedVertexAnimationTime\") === -1) {\r\n this._options.uniforms.push(\"bakedVertexAnimationTime\");\r\n }\r\n\r\n if (this._options.samplers.indexOf(\"bakedVertexAnimationTexture\") === -1) {\r\n this._options.samplers.push(\"bakedVertexAnimationTexture\");\r\n }\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\r\n }\r\n\r\n // Textures\r\n for (const name in this._textures) {\r\n if (!this._textures[name].isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n // Alpha test\r\n if (mesh && this._shouldTurnAlphaTestOn(mesh)) {\r\n defines.push(\"#define ALPHATEST\");\r\n }\r\n\r\n // Clip planes\r\n if (this._options.useClipPlane !== false) {\r\n addClipPlaneUniforms(uniforms);\r\n\r\n prepareStringDefinesForClipPlanes(this, scene, defines);\r\n }\r\n\r\n if (this.customShaderNameResolve) {\r\n uniforms = uniforms.slice();\r\n uniformBuffers = uniformBuffers.slice();\r\n samplers = samplers.slice();\r\n shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs);\r\n }\r\n\r\n const drawWrapper = storeEffectOnSubMeshes ? subMesh._getDrawWrapper() : this._drawWrapper;\r\n const previousEffect = drawWrapper?.effect ?? null;\r\n const previousDefines = drawWrapper?.defines ?? null;\r\n const join = defines.join(\"\\n\");\r\n\r\n let effect = previousEffect;\r\n if (previousDefines !== join) {\r\n effect = engine.createEffect(\r\n shaderName,\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters: { maxSimultaneousMorphTargets: numInfluencers },\r\n shaderLanguage: this._options.shaderLanguage,\r\n },\r\n engine\r\n );\r\n\r\n if (storeEffectOnSubMeshes) {\r\n subMesh.setEffect(effect, join, this._materialContext);\r\n } else if (drawWrapper) {\r\n drawWrapper.setEffect(effect, join);\r\n }\r\n\r\n if (this._onEffectCreatedObservable) {\r\n onCreatedEffectParameters.effect = effect;\r\n onCreatedEffectParameters.subMesh = subMesh ?? mesh?.subMeshes[0] ?? null;\r\n this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);\r\n }\r\n }\r\n\r\n effect!._wasPreviouslyUsingInstances = !!useInstances;\r\n\r\n if (!effect?.isReady() ?? true) {\r\n return false;\r\n }\r\n\r\n if (previousEffect !== effect) {\r\n scene.resetCachedMaterial();\r\n }\r\n\r\n effect._wasPreviouslyReady = true;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Binds the world matrix to the material\r\n * @param world defines the world transformation matrix\r\n * @param effectOverride - If provided, use this effect instead of internal effect\r\n */\r\n public bindOnlyWorldMatrix(world: Matrix, effectOverride?: Nullable): void {\r\n const scene = this.getScene();\r\n\r\n const effect = effectOverride ?? this.getEffect();\r\n\r\n if (!effect) {\r\n return;\r\n }\r\n\r\n if (this._options.uniforms.indexOf(\"world\") !== -1) {\r\n effect.setMatrix(\"world\", world);\r\n }\r\n\r\n if (this._options.uniforms.indexOf(\"worldView\") !== -1) {\r\n world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);\r\n effect.setMatrix(\"worldView\", this._cachedWorldViewMatrix);\r\n }\r\n\r\n if (this._options.uniforms.indexOf(\"worldViewProjection\") !== -1) {\r\n world.multiplyToRef(scene.getTransformMatrix(), this._cachedWorldViewProjectionMatrix);\r\n effect.setMatrix(\"worldViewProjection\", this._cachedWorldViewProjectionMatrix);\r\n }\r\n }\r\n\r\n /**\r\n * Binds the submesh to this material by preparing the effect and shader to draw\r\n * @param world defines the world transformation matrix\r\n * @param mesh defines the mesh containing the submesh\r\n * @param subMesh defines the submesh to bind the material to\r\n */\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n this.bind(world, mesh, subMesh._drawWrapperOverride?.effect, subMesh);\r\n }\r\n\r\n /**\r\n * Binds the material to the mesh\r\n * @param world defines the world transformation matrix\r\n * @param mesh defines the mesh to bind the material to\r\n * @param effectOverride - If provided, use this effect instead of internal effect\r\n * @param subMesh defines the submesh to bind the material to\r\n */\r\n public bind(world: Matrix, mesh?: Mesh, effectOverride?: Nullable, subMesh?: SubMesh): void {\r\n // Std values\r\n const storeEffectOnSubMeshes = subMesh && this._storeEffectOnSubMeshes;\r\n const effect = effectOverride ?? (storeEffectOnSubMeshes ? subMesh.effect : this.getEffect());\r\n\r\n if (!effect) {\r\n return;\r\n }\r\n\r\n this._activeEffect = effect;\r\n\r\n this.bindOnlyWorldMatrix(world, effectOverride);\r\n\r\n const uniformBuffers = this._options.uniformBuffers;\r\n\r\n let useSceneUBO = false;\r\n\r\n if (effect && uniformBuffers && uniformBuffers.length > 0 && this.getScene().getEngine().supportsUniformBuffers) {\r\n for (let i = 0; i < uniformBuffers.length; ++i) {\r\n const bufferName = uniformBuffers[i];\r\n switch (bufferName) {\r\n case \"Mesh\":\r\n if (mesh) {\r\n mesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\r\n mesh.transferToEffect(world);\r\n }\r\n break;\r\n case \"Scene\":\r\n MaterialHelper.BindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());\r\n this.getScene().finalizeSceneUbo();\r\n useSceneUBO = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const mustRebind = mesh && storeEffectOnSubMeshes ? this._mustRebind(this.getScene(), effect, mesh.visibility) : this.getScene().getCachedMaterial() !== this;\r\n\r\n if (effect && mustRebind) {\r\n if (!useSceneUBO && this._options.uniforms.indexOf(\"view\") !== -1) {\r\n effect.setMatrix(\"view\", this.getScene().getViewMatrix());\r\n }\r\n\r\n if (!useSceneUBO && this._options.uniforms.indexOf(\"projection\") !== -1) {\r\n effect.setMatrix(\"projection\", this.getScene().getProjectionMatrix());\r\n }\r\n\r\n if (!useSceneUBO && this._options.uniforms.indexOf(\"viewProjection\") !== -1) {\r\n effect.setMatrix(\"viewProjection\", this.getScene().getTransformMatrix());\r\n if (this._multiview) {\r\n effect.setMatrix(\"viewProjectionR\", this.getScene()._transformMatrixR);\r\n }\r\n }\r\n\r\n if (this.getScene().activeCamera && this._options.uniforms.indexOf(\"cameraPosition\") !== -1) {\r\n effect.setVector3(\"cameraPosition\", this.getScene().activeCamera!.globalPosition);\r\n }\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, effect);\r\n\r\n // Clip plane\r\n bindClipPlane(effect, this, this.getScene());\r\n\r\n let name: string;\r\n // Texture\r\n for (name in this._textures) {\r\n effect.setTexture(name, this._textures[name]);\r\n }\r\n\r\n // Texture arrays\r\n for (name in this._textureArrays) {\r\n effect.setTextureArray(name, this._textureArrays[name]);\r\n }\r\n\r\n // External texture\r\n for (name in this._externalTextures) {\r\n effect.setExternalTexture(name, this._externalTextures[name]);\r\n }\r\n\r\n // Int\r\n for (name in this._ints) {\r\n effect.setInt(name, this._ints[name]);\r\n }\r\n\r\n // UInt\r\n for (name in this._uints) {\r\n effect.setUInt(name, this._uints[name]);\r\n }\r\n\r\n // Float\r\n for (name in this._floats) {\r\n effect.setFloat(name, this._floats[name]);\r\n }\r\n\r\n // Floats\r\n for (name in this._floatsArrays) {\r\n effect.setArray(name, this._floatsArrays[name]);\r\n }\r\n\r\n // Color3\r\n for (name in this._colors3) {\r\n effect.setColor3(name, this._colors3[name]);\r\n }\r\n\r\n // Color3Array\r\n for (name in this._colors3Arrays) {\r\n effect.setArray3(name, this._colors3Arrays[name]);\r\n }\r\n\r\n // Color4\r\n for (name in this._colors4) {\r\n const color = this._colors4[name];\r\n effect.setFloat4(name, color.r, color.g, color.b, color.a);\r\n }\r\n\r\n // Color4Array\r\n for (name in this._colors4Arrays) {\r\n effect.setArray4(name, this._colors4Arrays[name]);\r\n }\r\n\r\n // Vector2\r\n for (name in this._vectors2) {\r\n effect.setVector2(name, this._vectors2[name]);\r\n }\r\n\r\n // Vector3\r\n for (name in this._vectors3) {\r\n effect.setVector3(name, this._vectors3[name]);\r\n }\r\n\r\n // Vector4\r\n for (name in this._vectors4) {\r\n effect.setVector4(name, this._vectors4[name]);\r\n }\r\n\r\n // Quaternion\r\n for (name in this._quaternions) {\r\n effect.setQuaternion(name, this._quaternions[name]);\r\n }\r\n\r\n // Matrix\r\n for (name in this._matrices) {\r\n effect.setMatrix(name, this._matrices[name]);\r\n }\r\n\r\n // MatrixArray\r\n for (name in this._matrixArrays) {\r\n effect.setMatrices(name, this._matrixArrays[name]);\r\n }\r\n\r\n // Matrix 3x3\r\n for (name in this._matrices3x3) {\r\n effect.setMatrix3x3(name, this._matrices3x3[name]);\r\n }\r\n\r\n // Matrix 2x2\r\n for (name in this._matrices2x2) {\r\n effect.setMatrix2x2(name, this._matrices2x2[name]);\r\n }\r\n\r\n // Vector2Array\r\n for (name in this._vectors2Arrays) {\r\n effect.setArray2(name, this._vectors2Arrays[name]);\r\n }\r\n\r\n // Vector3Array\r\n for (name in this._vectors3Arrays) {\r\n effect.setArray3(name, this._vectors3Arrays[name]);\r\n }\r\n\r\n // Vector4Array\r\n for (name in this._vectors4Arrays) {\r\n effect.setArray4(name, this._vectors4Arrays[name]);\r\n }\r\n\r\n // QuaternionArray\r\n for (name in this._quaternionsArrays) {\r\n effect.setArray4(name, this._quaternionsArrays[name]);\r\n }\r\n\r\n // Uniform buffers\r\n for (name in this._uniformBuffers) {\r\n const buffer = this._uniformBuffers[name].getBuffer();\r\n if (buffer) {\r\n effect.bindUniformBuffer(buffer, name);\r\n }\r\n }\r\n\r\n // Samplers\r\n for (name in this._textureSamplers) {\r\n effect.setTextureSampler(name, this._textureSamplers[name]);\r\n }\r\n\r\n // Storage buffers\r\n for (name in this._storageBuffers) {\r\n effect.setStorageBuffer(name, this._storageBuffers[name]);\r\n }\r\n }\r\n\r\n if (effect && mesh && (mustRebind || !this.isFrozen)) {\r\n // Morph targets\r\n const manager = (mesh).morphTargetManager;\r\n if (manager && manager.numInfluencers > 0) {\r\n MaterialHelper.BindMorphTargetParameters(mesh, effect);\r\n }\r\n\r\n const bvaManager = (mesh).bakedVertexAnimationManager;\r\n\r\n if (bvaManager && bvaManager.isEnabled) {\r\n mesh.bakedVertexAnimationManager?.bind(effect, !!effect._wasPreviouslyUsingInstances);\r\n }\r\n }\r\n\r\n this._afterBind(mesh, effect);\r\n }\r\n\r\n /**\r\n * Gets the active textures from the material\r\n * @returns an array of textures\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n const activeTextures = super.getActiveTextures();\r\n\r\n for (const name in this._textures) {\r\n activeTextures.push(this._textures[name]);\r\n }\r\n\r\n for (const name in this._textureArrays) {\r\n const array = this._textureArrays[name];\r\n for (let index = 0; index < array.length; index++) {\r\n activeTextures.push(array[index]);\r\n }\r\n }\r\n\r\n return activeTextures;\r\n }\r\n\r\n /**\r\n * Specifies if the material uses a texture\r\n * @param texture defines the texture to check against the material\r\n * @returns a boolean specifying if the 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 (const name in this._textures) {\r\n if (this._textures[name] === texture) {\r\n return true;\r\n }\r\n }\r\n\r\n for (const name in this._textureArrays) {\r\n const array = this._textureArrays[name];\r\n for (let index = 0; index < array.length; index++) {\r\n if (array[index] === texture) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Makes a duplicate of the material, and gives it a new name\r\n * @param name defines the new name for the duplicated material\r\n * @returns the cloned material\r\n */\r\n public clone(name: string): ShaderMaterial {\r\n const result = SerializationHelper.Clone(() => new ShaderMaterial(name, this.getScene(), this._shaderPath, this._options, this._storeEffectOnSubMeshes), this);\r\n\r\n result.name = name;\r\n result.id = name;\r\n\r\n // Shader code path\r\n if (typeof result._shaderPath === \"object\") {\r\n result._shaderPath = { ...result._shaderPath };\r\n }\r\n\r\n // Options\r\n this._options = { ...this._options };\r\n\r\n (Object.keys(this._options) as Array).forEach((propName) => {\r\n const propValue = this._options[propName];\r\n if (Array.isArray(propValue)) {\r\n (this._options[propName]) = propValue.slice(0);\r\n }\r\n });\r\n\r\n // Stencil\r\n this.stencil.copyTo(result.stencil);\r\n\r\n // Texture\r\n for (const key in this._textures) {\r\n result.setTexture(key, this._textures[key]);\r\n }\r\n\r\n // TextureArray\r\n for (const key in this._textureArrays) {\r\n result.setTextureArray(key, this._textureArrays[key]);\r\n }\r\n\r\n // External texture\r\n for (const key in this._externalTextures) {\r\n result.setExternalTexture(key, this._externalTextures[key]);\r\n }\r\n\r\n // Int\r\n for (const key in this._ints) {\r\n result.setInt(key, this._ints[key]);\r\n }\r\n\r\n // UInt\r\n for (const key in this._uints) {\r\n result.setUInt(key, this._uints[key]);\r\n }\r\n\r\n // Float\r\n for (const key in this._floats) {\r\n result.setFloat(key, this._floats[key]);\r\n }\r\n\r\n // Floats\r\n for (const key in this._floatsArrays) {\r\n result.setFloats(key, this._floatsArrays[key]);\r\n }\r\n\r\n // Color3\r\n for (const key in this._colors3) {\r\n result.setColor3(key, this._colors3[key]);\r\n }\r\n\r\n // Color3Array\r\n for (const key in this._colors3Arrays) {\r\n result._colors3Arrays[key] = this._colors3Arrays[key];\r\n }\r\n\r\n // Color4\r\n for (const key in this._colors4) {\r\n result.setColor4(key, this._colors4[key]);\r\n }\r\n\r\n // Color4Array\r\n for (const key in this._colors4Arrays) {\r\n result._colors4Arrays[key] = this._colors4Arrays[key];\r\n }\r\n\r\n // Vector2\r\n for (const key in this._vectors2) {\r\n result.setVector2(key, this._vectors2[key]);\r\n }\r\n\r\n // Vector3\r\n for (const key in this._vectors3) {\r\n result.setVector3(key, this._vectors3[key]);\r\n }\r\n\r\n // Vector4\r\n for (const key in this._vectors4) {\r\n result.setVector4(key, this._vectors4[key]);\r\n }\r\n\r\n // Quaternion\r\n for (const key in this._quaternions) {\r\n result.setQuaternion(key, this._quaternions[key]);\r\n }\r\n\r\n // QuaternionArray\r\n for (const key in this._quaternionsArrays) {\r\n result._quaternionsArrays[key] = this._quaternionsArrays[key];\r\n }\r\n\r\n // Matrix\r\n for (const key in this._matrices) {\r\n result.setMatrix(key, this._matrices[key]);\r\n }\r\n\r\n // MatrixArray\r\n for (const key in this._matrixArrays) {\r\n result._matrixArrays[key] = this._matrixArrays[key].slice();\r\n }\r\n\r\n // Matrix 3x3\r\n for (const key in this._matrices3x3) {\r\n result.setMatrix3x3(key, this._matrices3x3[key]);\r\n }\r\n\r\n // Matrix 2x2\r\n for (const key in this._matrices2x2) {\r\n result.setMatrix2x2(key, this._matrices2x2[key]);\r\n }\r\n\r\n // Vector2Array\r\n for (const key in this._vectors2Arrays) {\r\n result.setArray2(key, this._vectors2Arrays[key]);\r\n }\r\n\r\n // Vector3Array\r\n for (const key in this._vectors3Arrays) {\r\n result.setArray3(key, this._vectors3Arrays[key]);\r\n }\r\n\r\n // Vector4Array\r\n for (const key in this._vectors4Arrays) {\r\n result.setArray4(key, this._vectors4Arrays[key]);\r\n }\r\n\r\n // Uniform buffers\r\n for (const key in this._uniformBuffers) {\r\n result.setUniformBuffer(key, this._uniformBuffers[key]);\r\n }\r\n\r\n // Samplers\r\n for (const key in this._textureSamplers) {\r\n result.setTextureSampler(key, this._textureSamplers[key]);\r\n }\r\n\r\n // Storag buffers\r\n for (const key in this._storageBuffers) {\r\n result.setStorageBuffer(key, this._storageBuffers[key]);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Disposes the material\r\n * @param forceDisposeEffect specifies if effects should be forcefully disposed\r\n * @param forceDisposeTextures specifies if textures should be forcefully disposed\r\n * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, notBoundToMesh?: boolean): void {\r\n if (forceDisposeTextures) {\r\n let name: string;\r\n for (name in this._textures) {\r\n this._textures[name].dispose();\r\n }\r\n\r\n for (name in this._textureArrays) {\r\n const array = this._textureArrays[name];\r\n for (let index = 0; index < array.length; index++) {\r\n array[index].dispose();\r\n }\r\n }\r\n }\r\n\r\n this._textures = {};\r\n\r\n super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);\r\n }\r\n\r\n /**\r\n * Serializes this material in a JSON representation\r\n * @returns the serialized material object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n serializationObject.customType = \"BABYLON.ShaderMaterial\";\r\n serializationObject.uniqueId = this.uniqueId;\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.storeEffectOnSubMeshes = this._storeEffectOnSubMeshes;\r\n\r\n let name: string;\r\n\r\n // Stencil\r\n serializationObject.stencil = this.stencil.serialize();\r\n\r\n // Texture\r\n serializationObject.textures = {};\r\n for (name in this._textures) {\r\n serializationObject.textures[name] = this._textures[name].serialize();\r\n }\r\n\r\n // Texture arrays\r\n serializationObject.textureArrays = {};\r\n for (name in this._textureArrays) {\r\n serializationObject.textureArrays[name] = [];\r\n const array = this._textureArrays[name];\r\n for (let index = 0; index < array.length; index++) {\r\n serializationObject.textureArrays[name].push(array[index].serialize());\r\n }\r\n }\r\n\r\n // Int\r\n serializationObject.ints = {};\r\n for (name in this._ints) {\r\n serializationObject.ints[name] = this._ints[name];\r\n }\r\n\r\n // UInt\r\n serializationObject.uints = {};\r\n for (name in this._uints) {\r\n serializationObject.uints[name] = this._uints[name];\r\n }\r\n\r\n // Float\r\n serializationObject.floats = {};\r\n for (name in this._floats) {\r\n serializationObject.floats[name] = this._floats[name];\r\n }\r\n\r\n // Floats\r\n serializationObject.FloatArrays = {};\r\n for (name in this._floatsArrays) {\r\n serializationObject.FloatArrays[name] = this._floatsArrays[name];\r\n }\r\n\r\n // Color3\r\n serializationObject.colors3 = {};\r\n for (name in this._colors3) {\r\n serializationObject.colors3[name] = this._colors3[name].asArray();\r\n }\r\n\r\n // Color3 array\r\n serializationObject.colors3Arrays = {};\r\n for (name in this._colors3Arrays) {\r\n serializationObject.colors3Arrays[name] = this._colors3Arrays[name];\r\n }\r\n\r\n // Color4\r\n serializationObject.colors4 = {};\r\n for (name in this._colors4) {\r\n serializationObject.colors4[name] = this._colors4[name].asArray();\r\n }\r\n\r\n // Color4 array\r\n serializationObject.colors4Arrays = {};\r\n for (name in this._colors4Arrays) {\r\n serializationObject.colors4Arrays[name] = this._colors4Arrays[name];\r\n }\r\n\r\n // Vector2\r\n serializationObject.vectors2 = {};\r\n for (name in this._vectors2) {\r\n serializationObject.vectors2[name] = this._vectors2[name].asArray();\r\n }\r\n\r\n // Vector3\r\n serializationObject.vectors3 = {};\r\n for (name in this._vectors3) {\r\n serializationObject.vectors3[name] = this._vectors3[name].asArray();\r\n }\r\n\r\n // Vector4\r\n serializationObject.vectors4 = {};\r\n for (name in this._vectors4) {\r\n serializationObject.vectors4[name] = this._vectors4[name].asArray();\r\n }\r\n\r\n // Quaternion\r\n serializationObject.quaternions = {};\r\n for (name in this._quaternions) {\r\n serializationObject.quaternions[name] = this._quaternions[name].asArray();\r\n }\r\n\r\n // Matrix\r\n serializationObject.matrices = {};\r\n for (name in this._matrices) {\r\n serializationObject.matrices[name] = this._matrices[name].asArray();\r\n }\r\n\r\n // MatrixArray\r\n serializationObject.matrixArray = {};\r\n for (name in this._matrixArrays) {\r\n serializationObject.matrixArray[name] = this._matrixArrays[name];\r\n }\r\n\r\n // Matrix 3x3\r\n serializationObject.matrices3x3 = {};\r\n for (name in this._matrices3x3) {\r\n serializationObject.matrices3x3[name] = this._matrices3x3[name];\r\n }\r\n\r\n // Matrix 2x2\r\n serializationObject.matrices2x2 = {};\r\n for (name in this._matrices2x2) {\r\n serializationObject.matrices2x2[name] = this._matrices2x2[name];\r\n }\r\n\r\n // Vector2Array\r\n serializationObject.vectors2Arrays = {};\r\n for (name in this._vectors2Arrays) {\r\n serializationObject.vectors2Arrays[name] = this._vectors2Arrays[name];\r\n }\r\n\r\n // Vector3Array\r\n serializationObject.vectors3Arrays = {};\r\n for (name in this._vectors3Arrays) {\r\n serializationObject.vectors3Arrays[name] = this._vectors3Arrays[name];\r\n }\r\n\r\n // Vector4Array\r\n serializationObject.vectors4Arrays = {};\r\n for (name in this._vectors4Arrays) {\r\n serializationObject.vectors4Arrays[name] = this._vectors4Arrays[name];\r\n }\r\n\r\n // QuaternionArray\r\n serializationObject.quaternionsArrays = {};\r\n for (name in this._quaternionsArrays) {\r\n serializationObject.quaternionsArrays[name] = this._quaternionsArrays[name];\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a shader material from parsed shader material data\r\n * @param source defines the JSON representation of the material\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new material\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ShaderMaterial {\r\n const material = SerializationHelper.Parse(\r\n () => new ShaderMaterial(source.name, scene, source.shaderPath, source.options, source.storeEffectOnSubMeshes),\r\n source,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n let name: string;\r\n\r\n // Stencil\r\n if (source.stencil) {\r\n material.stencil.parse(source.stencil, scene, rootUrl);\r\n }\r\n\r\n // Texture\r\n for (name in source.textures) {\r\n material.setTexture(name, Texture.Parse(source.textures[name], scene, rootUrl));\r\n }\r\n\r\n // Texture arrays\r\n for (name in source.textureArrays) {\r\n const array = source.textureArrays[name];\r\n const textureArray = new Array();\r\n\r\n for (let index = 0; index < array.length; index++) {\r\n textureArray.push(Texture.Parse(array[index], scene, rootUrl));\r\n }\r\n material.setTextureArray(name, textureArray);\r\n }\r\n\r\n // Int\r\n for (name in source.ints) {\r\n material.setInt(name, source.ints[name]);\r\n }\r\n\r\n // UInt\r\n for (name in source.uints) {\r\n material.setUInt(name, source.uints[name]);\r\n }\r\n\r\n // Float\r\n for (name in source.floats) {\r\n material.setFloat(name, source.floats[name]);\r\n }\r\n\r\n // Floats\r\n for (name in source.floatsArrays) {\r\n material.setFloats(name, source.floatsArrays[name]);\r\n }\r\n\r\n // Color3\r\n for (name in source.colors3) {\r\n material.setColor3(name, Color3.FromArray(source.colors3[name]));\r\n }\r\n\r\n // Color3 arrays\r\n for (name in source.colors3Arrays) {\r\n const colors: Color3[] = source.colors3Arrays[name]\r\n .reduce((arr: Array>, num: number, i: number) => {\r\n if (i % 3 === 0) {\r\n arr.push([num]);\r\n } else {\r\n arr[arr.length - 1].push(num);\r\n }\r\n return arr;\r\n }, [])\r\n .map((color: ArrayLike) => Color3.FromArray(color));\r\n material.setColor3Array(name, colors);\r\n }\r\n\r\n // Color4\r\n for (name in source.colors4) {\r\n material.setColor4(name, Color4.FromArray(source.colors4[name]));\r\n }\r\n\r\n // Color4 arrays\r\n for (name in source.colors4Arrays) {\r\n const colors: Color4[] = source.colors4Arrays[name]\r\n .reduce((arr: Array>, num: number, i: number) => {\r\n if (i % 4 === 0) {\r\n arr.push([num]);\r\n } else {\r\n arr[arr.length - 1].push(num);\r\n }\r\n return arr;\r\n }, [])\r\n .map((color: ArrayLike) => Color4.FromArray(color));\r\n material.setColor4Array(name, colors);\r\n }\r\n\r\n // Vector2\r\n for (name in source.vectors2) {\r\n material.setVector2(name, Vector2.FromArray(source.vectors2[name]));\r\n }\r\n\r\n // Vector3\r\n for (name in source.vectors3) {\r\n material.setVector3(name, Vector3.FromArray(source.vectors3[name]));\r\n }\r\n\r\n // Vector4\r\n for (name in source.vectors4) {\r\n material.setVector4(name, Vector4.FromArray(source.vectors4[name]));\r\n }\r\n\r\n // Quaternion\r\n for (name in source.quaternions) {\r\n material.setQuaternion(name, Quaternion.FromArray(source.quaternions[name]));\r\n }\r\n\r\n // Matrix\r\n for (name in source.matrices) {\r\n material.setMatrix(name, Matrix.FromArray(source.matrices[name]));\r\n }\r\n\r\n // MatrixArray\r\n for (name in source.matrixArray) {\r\n material._matrixArrays[name] = new Float32Array(source.matrixArray[name]);\r\n }\r\n\r\n // Matrix 3x3\r\n for (name in source.matrices3x3) {\r\n material.setMatrix3x3(name, source.matrices3x3[name]);\r\n }\r\n\r\n // Matrix 2x2\r\n for (name in source.matrices2x2) {\r\n material.setMatrix2x2(name, source.matrices2x2[name]);\r\n }\r\n\r\n // Vector2Array\r\n for (name in source.vectors2Arrays) {\r\n material.setArray2(name, source.vectors2Arrays[name]);\r\n }\r\n\r\n // Vector3Array\r\n for (name in source.vectors3Arrays) {\r\n material.setArray3(name, source.vectors3Arrays[name]);\r\n }\r\n\r\n // Vector4Array\r\n for (name in source.vectors4Arrays) {\r\n material.setArray4(name, source.vectors4Arrays[name]);\r\n }\r\n\r\n // QuaternionArray\r\n for (name in source.quaternionsArrays) {\r\n material.setArray4(name, source.quaternionsArrays[name]);\r\n }\r\n\r\n return material;\r\n }\r\n\r\n /**\r\n * Creates a new ShaderMaterial from a snippet saved in a remote file\r\n * @param name defines the name of the ShaderMaterial to create (can be null or empty to use the one from the json data)\r\n * @param url defines the url to load from\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a promise that will resolve to the new ShaderMaterial\r\n */\r\n public static ParseFromFileAsync(name: Nullable, url: string, scene: Scene, rootUrl = \"\"): Promise {\r\n return new Promise((resolve, reject) => {\r\n const request = new WebRequest();\r\n request.addEventListener(\"readystatechange\", () => {\r\n if (request.readyState == 4) {\r\n if (request.status == 200) {\r\n const serializationObject = JSON.parse(request.responseText);\r\n const output = this.Parse(serializationObject, scene || EngineStore.LastCreatedScene, rootUrl);\r\n\r\n if (name) {\r\n output.name = name;\r\n }\r\n\r\n resolve(output);\r\n } else {\r\n reject(\"Unable to load the ShaderMaterial\");\r\n }\r\n }\r\n });\r\n\r\n request.open(\"GET\", url);\r\n request.send();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a ShaderMaterial from a snippet saved by the Inspector\r\n * @param snippetId defines the snippet to load\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a promise that will resolve to the new ShaderMaterial\r\n */\r\n public static ParseFromSnippetAsync(snippetId: string, scene: Scene, rootUrl = \"\"): Promise {\r\n return new Promise((resolve, reject) => {\r\n const request = new WebRequest();\r\n request.addEventListener(\"readystatechange\", () => {\r\n if (request.readyState == 4) {\r\n if (request.status == 200) {\r\n const snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);\r\n const serializationObject = JSON.parse(snippet.shaderMaterial);\r\n const output = this.Parse(serializationObject, scene || EngineStore.LastCreatedScene, rootUrl);\r\n\r\n output.snippetId = snippetId;\r\n\r\n resolve(output);\r\n } else {\r\n reject(\"Unable to load the snippet \" + snippetId);\r\n }\r\n }\r\n });\r\n\r\n request.open(\"GET\", this.SnippetUrl + \"/\" + snippetId.replace(/#/g, \"/\"));\r\n request.send();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a ShaderMaterial from a snippet saved by the Inspector\r\n * @deprecated Please use ParseFromSnippetAsync instead\r\n * @param snippetId defines the snippet to load\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a promise that will resolve to the new ShaderMaterial\r\n */\r\n public static CreateFromSnippetAsync = ShaderMaterial.ParseFromSnippetAsync;\r\n}\r\n\r\nRegisterClass(\"BABYLON.ShaderMaterial\", ShaderMaterial);\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\n\nconst name = \"colorPixelShader\";\nconst shader = `#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\n#define VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const colorPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/clipPlaneVertex\";\nimport \"./ShadersInclude/vertexColorMixing\";\n\nconst name = \"colorVertexShader\";\nconst shader = `attribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include\n#include\n#include\n#include\nuniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(position,1.0);\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const colorVertexShader = { name, shader };\n","import type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Color3, Color4 } from \"../Maths/math.color\";\r\nimport type { Node } from \"../node\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { InstancedMesh } from \"../Meshes/instancedMesh\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { ShaderMaterial } from \"../Materials/shaderMaterial\";\r\nimport type { Effect } from \"../Materials/effect\";\r\n\r\nimport \"../Shaders/color.fragment\";\r\nimport \"../Shaders/color.vertex\";\r\n\r\nMesh._LinesMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n return LinesMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Line mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n */\r\nexport class LinesMesh extends Mesh {\r\n /**\r\n * Color of the line (Default: White)\r\n */\r\n public color = new Color3(1, 1, 1);\r\n\r\n /**\r\n * Alpha of the line (Default: 1)\r\n */\r\n public alpha = 1;\r\n\r\n /**\r\n * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.\r\n * This margin is expressed in world space coordinates, so its value may vary.\r\n * Default value is 0.1\r\n */\r\n public intersectionThreshold: number;\r\n\r\n private _lineMaterial: Material;\r\n\r\n private _isShaderMaterial(shader: Material): shader is ShaderMaterial {\r\n return shader.getClassName() === \"ShaderMaterial\";\r\n }\r\n\r\n private _color4: Color4;\r\n\r\n /**\r\n * Creates a new LinesMesh\r\n * @param name defines the name\r\n * @param scene defines the hosting scene\r\n * @param parent defines the parent mesh if any\r\n * @param source defines the optional source LinesMesh used to clone data from\r\n * @param doNotCloneChildren When cloning, skip cloning child meshes of source, default False.\r\n * When false, achieved by calling a clone(), also passing False.\r\n * This will make creation of children, recursive.\r\n * @param useVertexColor defines if this LinesMesh supports vertex color\r\n * @param useVertexAlpha defines if this LinesMesh supports vertex alpha\r\n * @param material material to use to draw the line. If not provided, will create a new one\r\n */\r\n constructor(\r\n name: string,\r\n scene: Nullable = null,\r\n parent: Nullable = null,\r\n source: Nullable = null,\r\n doNotCloneChildren?: boolean,\r\n /**\r\n * If vertex color should be applied to the mesh\r\n */\r\n public readonly useVertexColor?: boolean,\r\n /**\r\n * If vertex alpha should be applied to the mesh\r\n */\r\n public readonly useVertexAlpha?: boolean,\r\n material?: Material\r\n ) {\r\n super(name, scene, parent, source, doNotCloneChildren);\r\n\r\n if (source) {\r\n this.color = source.color.clone();\r\n this.alpha = source.alpha;\r\n this.useVertexColor = source.useVertexColor;\r\n this.useVertexAlpha = source.useVertexAlpha;\r\n }\r\n\r\n this.intersectionThreshold = 0.1;\r\n\r\n const defines: string[] = [];\r\n const options = {\r\n attributes: [VertexBuffer.PositionKind],\r\n uniforms: [\"world\", \"viewProjection\"],\r\n needAlphaBlending: true,\r\n defines: defines,\r\n useClipPlane: null,\r\n };\r\n\r\n if (useVertexAlpha === false) {\r\n options.needAlphaBlending = false;\r\n } else {\r\n options.defines.push(\"#define VERTEXALPHA\");\r\n }\r\n\r\n if (!useVertexColor) {\r\n options.uniforms.push(\"color\");\r\n this._color4 = new Color4();\r\n } else {\r\n options.defines.push(\"#define VERTEXCOLOR\");\r\n options.attributes.push(VertexBuffer.ColorKind);\r\n }\r\n\r\n if (material) {\r\n this.material = material;\r\n } else {\r\n this.material = new ShaderMaterial(\"colorShader\", this.getScene(), \"color\", options, false);\r\n this.material.doNotSerialize = true;\r\n }\r\n }\r\n\r\n public isReady() {\r\n if (!this._lineMaterial.isReady(this, !!this._userInstancedBuffersStorage)) {\r\n return false;\r\n }\r\n\r\n return super.isReady();\r\n }\r\n\r\n /**\r\n * Returns the string \"LineMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"LinesMesh\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get material(): Material {\r\n return this._lineMaterial;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public set material(value: Material) {\r\n this._lineMaterial = value;\r\n this._lineMaterial.fillMode = Material.LineListDrawMode;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public get checkCollisions(): boolean {\r\n return false;\r\n }\r\n\r\n public set checkCollisions(value: boolean) {\r\n // Just ignore it\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bind(_subMesh: SubMesh, colorEffect: Effect): Mesh {\r\n if (!this._geometry) {\r\n return this;\r\n }\r\n\r\n // VBOs\r\n const indexToBind = this.isUnIndexed ? null : this._geometry.getIndexBuffer();\r\n if (!this._userInstancedBuffersStorage) {\r\n this._geometry._bind(colorEffect, indexToBind);\r\n } else {\r\n this._geometry._bind(colorEffect, indexToBind, this._userInstancedBuffersStorage.vertexBuffers, this._userInstancedBuffersStorage.vertexArrayObjects);\r\n }\r\n\r\n // Color\r\n if (!this.useVertexColor && this._isShaderMaterial(this._lineMaterial)) {\r\n const { r, g, b } = this.color;\r\n this._color4.set(r, g, b, this.alpha);\r\n this._lineMaterial.setColor4(\"color\", this._color4);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number): Mesh {\r\n if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {\r\n return this;\r\n }\r\n\r\n const engine = this.getScene().getEngine();\r\n\r\n // Draw order\r\n\r\n if (this._unIndexed) {\r\n engine.drawArraysType(Material.LineListDrawMode, subMesh.verticesStart, subMesh.verticesCount, instancesCount);\r\n } else {\r\n engine.drawElementsType(Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount, instancesCount);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes of the line mesh\r\n * @param doNotRecurse If children should be disposed\r\n * @param disposeMaterialAndTextures This parameter is not used by the LineMesh class\r\n * @param doNotDisposeMaterial If the material should not be disposed (default: false, meaning the material is disposed)\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false, doNotDisposeMaterial?: boolean): void {\r\n if (!doNotDisposeMaterial) {\r\n this._lineMaterial.dispose(false, false, true);\r\n }\r\n super.dispose(doNotRecurse);\r\n }\r\n\r\n /**\r\n * Returns a new LineMesh object cloned from the current one.\r\n * @param name\r\n * @param newParent\r\n * @param doNotCloneChildren\r\n */\r\n public clone(name: string, newParent: Nullable = null, doNotCloneChildren?: boolean): LinesMesh {\r\n return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);\r\n }\r\n\r\n /**\r\n * Creates a new InstancedLinesMesh object from the mesh model.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances\r\n * @param name defines the name of the new instance\r\n * @returns a new InstancedLinesMesh\r\n */\r\n public createInstance(name: string): InstancedLinesMesh {\r\n const instance = new InstancedLinesMesh(name, this);\r\n\r\n if (this.instancedBuffers) {\r\n instance.instancedBuffers = {};\r\n\r\n for (const key in this.instancedBuffers) {\r\n instance.instancedBuffers[key] = this.instancedBuffers[key];\r\n }\r\n }\r\n\r\n return instance;\r\n }\r\n\r\n /**\r\n * Serializes this ground mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.color = this.color.asArray();\r\n serializationObject.alpha = this.alpha;\r\n }\r\n\r\n /**\r\n * Parses a serialized ground mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the ground mesh in\r\n * @returns the created ground mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): LinesMesh {\r\n const result = new LinesMesh(parsedMesh.name, scene);\r\n\r\n result.color = Color3.FromArray(parsedMesh.color);\r\n result.alpha = parsedMesh.alpha;\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * Creates an instance based on a source LinesMesh\r\n */\r\nexport class InstancedLinesMesh extends InstancedMesh {\r\n /**\r\n * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.\r\n * This margin is expressed in world space coordinates, so its value may vary.\r\n * Initialized with the intersectionThreshold value of the source LinesMesh\r\n */\r\n public intersectionThreshold: number;\r\n\r\n constructor(name: string, source: LinesMesh) {\r\n super(name, source);\r\n this.intersectionThreshold = source.intersectionThreshold;\r\n }\r\n\r\n /**\r\n * Returns the string \"InstancedLinesMesh\".\r\n */\r\n public getClassName(): string {\r\n return \"InstancedLinesMesh\";\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Color4 } from \"../../Maths/math.color\";\r\nimport { _CreationDataStorage, Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { FloatArray, Nullable } from \"../../types\";\r\nimport { LinesMesh } from \"../../Meshes/linesMesh\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\n\r\nimport type { Material } from \"../../Materials/material\";\r\n\r\n/**\r\n * Creates the VertexData of the LineSystem\r\n * @param options an object used to set the following optional parameters for the LineSystem, required but can be empty\r\n * - lines an array of lines, each line being an array of successive Vector3\r\n * - colors an array of line colors, each of the line colors being an array of successive Color4, one per line point\r\n * @param options.lines\r\n * @param options.colors\r\n * @returns the VertexData of the LineSystem\r\n */\r\nexport function CreateLineSystemVertexData(options: { lines: Vector3[][]; colors?: Nullable }): VertexData {\r\n const indices = [];\r\n const positions = [];\r\n const lines = options.lines;\r\n const colors = options.colors;\r\n const vertexColors = [];\r\n let idx = 0;\r\n\r\n for (let l = 0; l < lines.length; l++) {\r\n const points = lines[l];\r\n for (let index = 0; index < points.length; index++) {\r\n positions.push(points[index].x, points[index].y, points[index].z);\r\n if (colors) {\r\n const color = colors[l];\r\n vertexColors.push(color[index].r, color[index].g, color[index].b, color[index].a);\r\n }\r\n if (index > 0) {\r\n indices.push(idx - 1);\r\n indices.push(idx);\r\n }\r\n idx++;\r\n }\r\n }\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n if (colors) {\r\n vertexData.colors = vertexColors;\r\n }\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Create the VertexData for a DashedLines\r\n * @param options an object used to set the following optional parameters for the DashedLines, required but can be empty\r\n * - points an array successive Vector3\r\n * - dashSize the size of the dashes relative to the dash number, optional, default 3\r\n * - gapSize the size of the gap between two successive dashes relative to the dash number, optional, default 1\r\n * - dashNb the intended total number of dashes, optional, default 200\r\n * @param options.points\r\n * @param options.dashSize\r\n * @param options.gapSize\r\n * @param options.dashNb\r\n * @returns the VertexData for the DashedLines\r\n */\r\nexport function CreateDashedLinesVertexData(options: { points: Vector3[]; dashSize?: number; gapSize?: number; dashNb?: number }): VertexData {\r\n const dashSize = options.dashSize || 3;\r\n const gapSize = options.gapSize || 1;\r\n const dashNb = options.dashNb || 200;\r\n const points = options.points;\r\n\r\n const positions = new Array();\r\n const indices = new Array();\r\n\r\n const curvect = Vector3.Zero();\r\n let lg = 0;\r\n let nb = 0;\r\n let shft = 0;\r\n let dashshft = 0;\r\n let curshft = 0;\r\n let idx = 0;\r\n let i = 0;\r\n for (i = 0; i < points.length - 1; i++) {\r\n points[i + 1].subtractToRef(points[i], curvect);\r\n lg += curvect.length();\r\n }\r\n shft = lg / dashNb;\r\n dashshft = (dashSize * shft) / (dashSize + gapSize);\r\n for (i = 0; i < points.length - 1; i++) {\r\n points[i + 1].subtractToRef(points[i], curvect);\r\n nb = Math.floor(curvect.length() / shft);\r\n curvect.normalize();\r\n for (let j = 0; j < nb; j++) {\r\n curshft = shft * j;\r\n positions.push(points[i].x + curshft * curvect.x, points[i].y + curshft * curvect.y, points[i].z + curshft * curvect.z);\r\n positions.push(points[i].x + (curshft + dashshft) * curvect.x, points[i].y + (curshft + dashshft) * curvect.y, points[i].z + (curshft + dashshft) * curvect.z);\r\n indices.push(idx, idx + 1);\r\n idx += 2;\r\n }\r\n }\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.positions = positions;\r\n vertexData.indices = indices;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a line system mesh. A line system is a pool of many lines gathered in a single mesh\r\n * * A line system mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of lines as an input parameter\r\n * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineSystem to this static function\r\n * * The parameter `lines` is an array of lines, each line being an array of successive Vector3\r\n * * The optional parameter `instance` is an instance of an existing LineSystem object to be updated with the passed `lines` parameter\r\n * * The optional parameter `colors` is an array of line colors, each line colors being an array of successive Color4, one per line point\r\n * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need the alpha blending (faster)\r\n * * The optional parameter `material` is the material to use to draw the lines if provided. If not, a default material will be created\r\n * * Updating a simple Line mesh, you just need to update every line in the `lines` array : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#lines-and-dashedlines\r\n * * When updating an instance, remember that only line point positions can change, not the number of points, neither the number of lines\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#line-system\r\n * @param name defines the name of the new line system\r\n * @param options defines the options used to create the line system\r\n * @param options.lines\r\n * @param options.updatable\r\n * @param options.instance\r\n * @param options.colors\r\n * @param options.useVertexAlpha\r\n * @param options.material\r\n * @param scene defines the hosting scene\r\n * @returns a new line system mesh\r\n */\r\nexport function CreateLineSystem(\r\n name: string,\r\n options: { lines: Vector3[][]; updatable?: boolean; instance?: Nullable; colors?: Nullable; useVertexAlpha?: boolean; material?: Material },\r\n scene: Nullable = null\r\n): LinesMesh {\r\n const instance = options.instance;\r\n const lines = options.lines;\r\n const colors = options.colors;\r\n\r\n if (instance) {\r\n // lines update\r\n const positions = instance.getVerticesData(VertexBuffer.PositionKind)!;\r\n let vertexColor;\r\n let lineColors;\r\n if (colors) {\r\n vertexColor = instance.getVerticesData(VertexBuffer.ColorKind)!;\r\n }\r\n let i = 0;\r\n let c = 0;\r\n for (let l = 0; l < lines.length; l++) {\r\n const points = lines[l];\r\n for (let p = 0; p < points.length; p++) {\r\n positions[i] = points[p].x;\r\n positions[i + 1] = points[p].y;\r\n positions[i + 2] = points[p].z;\r\n if (colors && vertexColor) {\r\n lineColors = colors[l];\r\n vertexColor[c] = lineColors[p].r;\r\n vertexColor[c + 1] = lineColors[p].g;\r\n vertexColor[c + 2] = lineColors[p].b;\r\n vertexColor[c + 3] = lineColors[p].a;\r\n c += 4;\r\n }\r\n i += 3;\r\n }\r\n }\r\n instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\r\n if (colors && vertexColor) {\r\n instance.updateVerticesData(VertexBuffer.ColorKind, vertexColor, false, false);\r\n }\r\n return instance;\r\n }\r\n\r\n // line system creation\r\n const useVertexColor = colors ? true : false;\r\n const lineSystem = new LinesMesh(name, scene, null, undefined, undefined, useVertexColor, options.useVertexAlpha, options.material);\r\n const vertexData = CreateLineSystemVertexData(options);\r\n vertexData.applyToMesh(lineSystem, options.updatable);\r\n return lineSystem;\r\n}\r\n\r\n/**\r\n * Creates a line mesh\r\n * A line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter\r\n * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function\r\n * * The parameter `points` is an array successive Vector3\r\n * * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#lines-and-dashedlines\r\n * * The optional parameter `colors` is an array of successive Color4, one per line point\r\n * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need alpha blending (faster)\r\n * * The optional parameter `material` is the material to use to draw the lines if provided. If not, a default material will be created\r\n * * When updating an instance, remember that only point positions can change, not the number of points\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#lines\r\n * @param name defines the name of the new line system\r\n * @param options defines the options used to create the line system\r\n * @param options.points\r\n * @param options.updatable\r\n * @param options.instance\r\n * @param options.colors\r\n * @param options.useVertexAlpha\r\n * @param options.material\r\n * @param scene defines the hosting scene\r\n * @returns a new line mesh\r\n */\r\nexport function CreateLines(\r\n name: string,\r\n options: { points: Vector3[]; updatable?: boolean; instance?: Nullable; colors?: Color4[]; useVertexAlpha?: boolean; material?: Material },\r\n scene: Nullable = null\r\n): LinesMesh {\r\n const colors = options.colors ? [options.colors] : null;\r\n const lines = CreateLineSystem(\r\n name,\r\n { lines: [options.points], updatable: options.updatable, instance: options.instance, colors: colors, useVertexAlpha: options.useVertexAlpha, material: options.material },\r\n scene\r\n );\r\n return lines;\r\n}\r\n\r\n/**\r\n * Creates a dashed line mesh\r\n * * A dashed line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter\r\n * * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function\r\n * * The parameter `points` is an array successive Vector3\r\n * * The parameter `dashNb` is the intended total number of dashes (positive integer, default 200)\r\n * * The parameter `dashSize` is the size of the dashes relatively the dash number (positive float, default 3)\r\n * * The parameter `gapSize` is the size of the gap between two successive dashes relatively the dash number (positive float, default 1)\r\n * * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#lines-and-dashedlines\r\n * * The optional parameter `useVertexAlpha` is to be set to `false` (default `true`) when you don't need the alpha blending (faster)\r\n * * The optional parameter `material` is the material to use to draw the lines if provided. If not, a default material will be created\r\n * * When updating an instance, remember that only point positions can change, not the number of points\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.points\r\n * @param options.dashSize\r\n * @param options.gapSize\r\n * @param options.dashNb\r\n * @param options.updatable\r\n * @param options.instance\r\n * @param options.useVertexAlpha\r\n * @param options.material\r\n * @param scene defines the hosting scene\r\n * @returns the dashed line mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#dashed-lines\r\n */\r\nexport function CreateDashedLines(\r\n name: string,\r\n options: { points: Vector3[]; dashSize?: number; gapSize?: number; dashNb?: number; updatable?: boolean; instance?: LinesMesh; useVertexAlpha?: boolean; material?: Material },\r\n scene: Nullable = null\r\n): LinesMesh {\r\n const points = options.points;\r\n const instance = options.instance;\r\n const gapSize = options.gapSize || 1;\r\n const dashSize = options.dashSize || 3;\r\n\r\n if (instance) {\r\n // dashed lines update\r\n const positionFunction = (positions: FloatArray): void => {\r\n const curvect = Vector3.Zero();\r\n const nbSeg = positions.length / 6;\r\n let lg = 0;\r\n let nb = 0;\r\n let shft = 0;\r\n let dashshft = 0;\r\n let curshft = 0;\r\n let p = 0;\r\n let i = 0;\r\n let j = 0;\r\n for (i = 0; i < points.length - 1; i++) {\r\n points[i + 1].subtractToRef(points[i], curvect);\r\n lg += curvect.length();\r\n }\r\n shft = lg / nbSeg;\r\n const dashSize = instance!._creationDataStorage!.dashSize;\r\n const gapSize = instance!._creationDataStorage!.gapSize;\r\n dashshft = (dashSize * shft) / (dashSize + gapSize);\r\n for (i = 0; i < points.length - 1; i++) {\r\n points[i + 1].subtractToRef(points[i], curvect);\r\n nb = Math.floor(curvect.length() / shft);\r\n curvect.normalize();\r\n j = 0;\r\n while (j < nb && p < positions.length) {\r\n curshft = shft * j;\r\n positions[p] = points[i].x + curshft * curvect.x;\r\n positions[p + 1] = points[i].y + curshft * curvect.y;\r\n positions[p + 2] = points[i].z + curshft * curvect.z;\r\n positions[p + 3] = points[i].x + (curshft + dashshft) * curvect.x;\r\n positions[p + 4] = points[i].y + (curshft + dashshft) * curvect.y;\r\n positions[p + 5] = points[i].z + (curshft + dashshft) * curvect.z;\r\n p += 6;\r\n j++;\r\n }\r\n }\r\n while (p < positions.length) {\r\n positions[p] = points[i].x;\r\n positions[p + 1] = points[i].y;\r\n positions[p + 2] = points[i].z;\r\n p += 3;\r\n }\r\n };\r\n if (options.dashNb || options.dashSize || options.gapSize || options.useVertexAlpha || options.material) {\r\n Logger.Warn(\"You have used an option other than points with the instance option. Please be aware that these other options will be ignored.\");\r\n }\r\n instance.updateMeshPositions(positionFunction, false);\r\n return instance;\r\n }\r\n // dashed lines creation\r\n const dashedLines = new LinesMesh(name, scene, null, undefined, undefined, undefined, options.useVertexAlpha, options.material);\r\n const vertexData = CreateDashedLinesVertexData(options);\r\n vertexData.applyToMesh(dashedLines, options.updatable);\r\n\r\n dashedLines._creationDataStorage = new _CreationDataStorage();\r\n dashedLines._creationDataStorage.dashSize = dashSize;\r\n dashedLines._creationDataStorage.gapSize = gapSize;\r\n return dashedLines;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const LinesBuilder = {\r\n CreateDashedLines,\r\n CreateLineSystem,\r\n CreateLines,\r\n};\r\n\r\nVertexData.CreateLineSystem = CreateLineSystemVertexData;\r\nVertexData.CreateDashedLines = CreateDashedLinesVertexData;\r\n\r\nMesh.CreateLines = (name: string, points: Vector3[], scene: Nullable = null, updatable: boolean = false, instance: Nullable = null): LinesMesh => {\r\n const options = {\r\n points,\r\n updatable,\r\n instance,\r\n };\r\n return CreateLines(name, options, scene);\r\n};\r\n\r\nMesh.CreateDashedLines = (\r\n name: string,\r\n points: Vector3[],\r\n dashSize: number,\r\n gapSize: number,\r\n dashNb: number,\r\n scene: Nullable = null,\r\n updatable?: boolean,\r\n instance?: LinesMesh\r\n): LinesMesh => {\r\n const options = {\r\n points,\r\n dashSize,\r\n gapSize,\r\n dashNb,\r\n updatable,\r\n instance,\r\n };\r\n return CreateDashedLines(name, options, scene);\r\n};\r\n","import type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { IDisposable } from \"../scene\";\r\n\r\n/**\r\n * Construction options for a timer\r\n */\r\nexport interface ITimerOptions {\r\n /**\r\n * Time-to-end\r\n */\r\n timeout: number;\r\n /**\r\n * The context observable is used to calculate time deltas and provides the context of the timer's callbacks. Will usually be OnBeforeRenderObservable.\r\n * Countdown calculation is done ONLY when the observable is notifying its observers, meaning that if\r\n * you choose an observable that doesn't trigger too often, the wait time might extend further than the requested max time\r\n */\r\n contextObservable: Observable;\r\n /**\r\n * Optional parameters when adding an observer to the observable\r\n */\r\n observableParameters?: {\r\n mask?: number;\r\n insertFirst?: boolean;\r\n scope?: any;\r\n };\r\n /**\r\n * An optional break condition that will stop the times prematurely. In this case onEnded will not be triggered!\r\n */\r\n breakCondition?: (data?: ITimerData) => boolean;\r\n /**\r\n * Will be triggered when the time condition has met\r\n */\r\n onEnded?: (data: ITimerData) => void;\r\n /**\r\n * Will be triggered when the break condition has met (prematurely ended)\r\n */\r\n onAborted?: (data: ITimerData) => void;\r\n /**\r\n * Optional function to execute on each tick (or count)\r\n */\r\n onTick?: (data: ITimerData) => void;\r\n}\r\n\r\n/**\r\n * An interface defining the data sent by the timer\r\n */\r\nexport interface ITimerData {\r\n /**\r\n * When did it start\r\n */\r\n startTime: number;\r\n /**\r\n * Time now\r\n */\r\n currentTime: number;\r\n /**\r\n * Time passed since started\r\n */\r\n deltaTime: number;\r\n /**\r\n * How much is completed, in [0.0...1.0].\r\n * Note that this CAN be higher than 1 due to the fact that we don't actually measure time but delta between observable calls\r\n */\r\n completeRate: number;\r\n /**\r\n * What the registered observable sent in the last count\r\n */\r\n payload: T;\r\n}\r\n\r\n/**\r\n * The current state of the timer\r\n */\r\nexport enum TimerState {\r\n /**\r\n * Timer initialized, not yet started\r\n */\r\n INIT,\r\n /**\r\n * Timer started and counting\r\n */\r\n STARTED,\r\n /**\r\n * Timer ended (whether aborted or time reached)\r\n */\r\n ENDED,\r\n}\r\n\r\n/**\r\n * A simple version of the timer. Will take options and start the timer immediately after calling it\r\n *\r\n * @param options options with which to initialize this timer\r\n */\r\nexport function setAndStartTimer(options: ITimerOptions): Nullable> {\r\n let timer = 0;\r\n const startTime = Date.now();\r\n options.observableParameters = options.observableParameters ?? {};\r\n const observer = options.contextObservable.add(\r\n (payload: any) => {\r\n const now = Date.now();\r\n timer = now - startTime;\r\n const data: ITimerData = {\r\n startTime,\r\n currentTime: now,\r\n deltaTime: timer,\r\n completeRate: timer / options.timeout,\r\n payload,\r\n };\r\n options.onTick && options.onTick(data);\r\n if (options.breakCondition && options.breakCondition()) {\r\n options.contextObservable.remove(observer);\r\n options.onAborted && options.onAborted(data);\r\n }\r\n if (timer >= options.timeout) {\r\n options.contextObservable.remove(observer);\r\n options.onEnded && options.onEnded(data);\r\n }\r\n },\r\n options.observableParameters.mask,\r\n options.observableParameters.insertFirst,\r\n options.observableParameters.scope\r\n );\r\n return observer;\r\n}\r\n\r\n/**\r\n * An advanced implementation of a timer class\r\n */\r\nexport class AdvancedTimer implements IDisposable {\r\n /**\r\n * Will notify each time the timer calculates the remaining time\r\n */\r\n public onEachCountObservable: Observable> = new Observable();\r\n /**\r\n * Will trigger when the timer was aborted due to the break condition\r\n */\r\n public onTimerAbortedObservable: Observable> = new Observable();\r\n /**\r\n * Will trigger when the timer ended successfully\r\n */\r\n public onTimerEndedObservable: Observable> = new Observable();\r\n /**\r\n * Will trigger when the timer state has changed\r\n */\r\n public onStateChangedObservable: Observable = new Observable();\r\n\r\n private _observer: Nullable> = null;\r\n private _contextObservable: Observable;\r\n private _observableParameters: {\r\n mask?: number;\r\n insertFirst?: boolean;\r\n scope?: any;\r\n };\r\n private _startTime: number;\r\n private _timer: number;\r\n private _state: TimerState;\r\n private _breakCondition: (data: ITimerData) => boolean;\r\n private _timeToEnd: number;\r\n private _breakOnNextTick: boolean = false;\r\n\r\n /**\r\n * Will construct a new advanced timer based on the options provided. Timer will not start until start() is called.\r\n * @param options construction options for this advanced timer\r\n */\r\n constructor(options: ITimerOptions) {\r\n this._setState(TimerState.INIT);\r\n this._contextObservable = options.contextObservable;\r\n this._observableParameters = options.observableParameters ?? {};\r\n this._breakCondition = options.breakCondition ?? (() => false);\r\n this._timeToEnd = options.timeout;\r\n if (options.onEnded) {\r\n this.onTimerEndedObservable.add(options.onEnded);\r\n }\r\n if (options.onTick) {\r\n this.onEachCountObservable.add(options.onTick);\r\n }\r\n if (options.onAborted) {\r\n this.onTimerAbortedObservable.add(options.onAborted);\r\n }\r\n }\r\n\r\n /**\r\n * set a breaking condition for this timer. Default is to never break during count\r\n * @param predicate the new break condition. Returns true to break, false otherwise\r\n */\r\n public set breakCondition(predicate: (data: ITimerData) => boolean) {\r\n this._breakCondition = predicate;\r\n }\r\n\r\n /**\r\n * Reset ALL associated observables in this advanced timer\r\n */\r\n public clearObservables() {\r\n this.onEachCountObservable.clear();\r\n this.onTimerAbortedObservable.clear();\r\n this.onTimerEndedObservable.clear();\r\n this.onStateChangedObservable.clear();\r\n }\r\n\r\n /**\r\n * Will start a new iteration of this timer. Only one instance of this timer can run at a time.\r\n *\r\n * @param timeToEnd how much time to measure until timer ended\r\n */\r\n public start(timeToEnd: number = this._timeToEnd) {\r\n if (this._state === TimerState.STARTED) {\r\n throw new Error(\"Timer already started. Please stop it before starting again\");\r\n }\r\n this._timeToEnd = timeToEnd;\r\n this._startTime = Date.now();\r\n this._timer = 0;\r\n this._observer = this._contextObservable.add(this._tick, this._observableParameters.mask, this._observableParameters.insertFirst, this._observableParameters.scope);\r\n this._setState(TimerState.STARTED);\r\n }\r\n\r\n /**\r\n * Will force a stop on the next tick.\r\n */\r\n public stop() {\r\n if (this._state !== TimerState.STARTED) {\r\n return;\r\n }\r\n this._breakOnNextTick = true;\r\n }\r\n\r\n /**\r\n * Dispose this timer, clearing all resources\r\n */\r\n public dispose() {\r\n if (this._observer) {\r\n this._contextObservable.remove(this._observer);\r\n }\r\n this.clearObservables();\r\n }\r\n\r\n private _setState(newState: TimerState) {\r\n this._state = newState;\r\n this.onStateChangedObservable.notifyObservers(this._state);\r\n }\r\n\r\n private _tick = (payload: T) => {\r\n const now = Date.now();\r\n this._timer = now - this._startTime;\r\n const data: ITimerData = {\r\n startTime: this._startTime,\r\n currentTime: now,\r\n deltaTime: this._timer,\r\n completeRate: this._timer / this._timeToEnd,\r\n payload,\r\n };\r\n const shouldBreak = this._breakOnNextTick || this._breakCondition(data);\r\n if (shouldBreak || this._timer >= this._timeToEnd) {\r\n this._stop(data, shouldBreak);\r\n } else {\r\n this.onEachCountObservable.notifyObservers(data);\r\n }\r\n };\r\n\r\n private _stop(data: ITimerData, aborted: boolean = false) {\r\n this._contextObservable.remove(this._observer);\r\n this._setState(TimerState.ENDED);\r\n if (aborted) {\r\n this.onTimerAbortedObservable.notifyObservers(data);\r\n } else {\r\n this.onTimerEndedObservable.notifyObservers(data);\r\n }\r\n }\r\n}\r\n","import type { IWebXRFeature } from \"../webXRFeaturesManager\";\r\nimport { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { IWebXRMotionControllerAxesValue } from \"../motionController/webXRControllerComponent\";\r\nimport { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport { Ray } from \"../../Culling/ray\";\r\nimport type { Material } from \"../../Materials/material\";\r\nimport { DynamicTexture } from \"../../Materials/Textures/dynamicTexture\";\r\nimport { CreateCylinder } from \"../../Meshes/Builders/cylinderBuilder\";\r\nimport { SineEase, EasingFunction } from \"../../Animations/easing\";\r\nimport { Animation } from \"../../Animations/animation\";\r\nimport { Axis } from \"../../Maths/math.axis\";\r\nimport { StandardMaterial } from \"../../Materials/standardMaterial\";\r\nimport { CreateGround } from \"../../Meshes/Builders/groundBuilder\";\r\nimport { CreateTorus } from \"../../Meshes/Builders/torusBuilder\";\r\nimport type { PickingInfo } from \"../../Collisions/pickingInfo\";\r\nimport { Curve3 } from \"../../Maths/math.path\";\r\nimport { CreateLines } from \"../../Meshes/Builders/linesBuilder\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Color3, Color4 } from \"../../Maths/math.color\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { UtilityLayerRenderer } from \"../../Rendering/utilityLayerRenderer\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { setAndStartTimer } from \"../../Misc/timer\";\r\nimport type { LinesMesh } from \"../../Meshes/linesMesh\";\r\n\r\n/**\r\n * The options container for the teleportation module\r\n */\r\nexport interface IWebXRTeleportationOptions {\r\n /**\r\n * if provided, this scene will be used to render meshes.\r\n */\r\n customUtilityLayerScene?: Scene;\r\n /**\r\n * Values to configure the default target mesh\r\n */\r\n defaultTargetMeshOptions?: {\r\n /**\r\n * Fill color of the teleportation area\r\n */\r\n teleportationFillColor?: string;\r\n /**\r\n * Border color for the teleportation area\r\n */\r\n teleportationBorderColor?: string;\r\n /**\r\n * Disable the mesh's animation sequence\r\n */\r\n disableAnimation?: boolean;\r\n /**\r\n * Disable lighting on the material or the ring and arrow\r\n */\r\n disableLighting?: boolean;\r\n /**\r\n * Override the default material of the torus and arrow\r\n */\r\n torusArrowMaterial?: Material;\r\n /**\r\n * Override the default material of the Landing Zone\r\n */\r\n teleportationCircleMaterial?: Material;\r\n };\r\n /**\r\n * A list of meshes to use as floor meshes.\r\n * Meshes can be added and removed after initializing the feature using the\r\n * addFloorMesh and removeFloorMesh functions\r\n * If empty, rotation will still work\r\n */\r\n floorMeshes?: AbstractMesh[];\r\n /**\r\n * use this rendering group id for the meshes (optional)\r\n */\r\n renderingGroupId?: number;\r\n /**\r\n * Should teleportation move only to snap points\r\n */\r\n snapPointsOnly?: boolean;\r\n /**\r\n * An array of points to which the teleportation will snap to.\r\n * If the teleportation ray is in the proximity of one of those points, it will be corrected to this point.\r\n */\r\n snapPositions?: Vector3[];\r\n /**\r\n * How close should the teleportation ray be in order to snap to position.\r\n * Default to 0.8 units (meters)\r\n */\r\n snapToPositionRadius?: number;\r\n /**\r\n * Provide your own teleportation mesh instead of babylon's wonderful doughnut.\r\n * If you want to support rotation, make sure your mesh has a direction indicator.\r\n *\r\n * When left untouched, the default mesh will be initialized.\r\n */\r\n teleportationTargetMesh?: AbstractMesh;\r\n /**\r\n * If main component is used (no thumbstick), how long should the \"long press\" take before teleport\r\n */\r\n timeToTeleport?: number;\r\n /**\r\n * Disable using the thumbstick and use the main component (usually trigger) on long press.\r\n * This will be automatically true if the controller doesn't have a thumbstick or touchpad.\r\n */\r\n useMainComponentOnly?: boolean;\r\n /**\r\n * Should meshes created here be added to a utility layer or the main scene\r\n */\r\n useUtilityLayer?: boolean;\r\n /**\r\n * Babylon XR Input class for controller\r\n */\r\n xrInput: WebXRInput;\r\n\r\n /**\r\n * Meshes that the teleportation ray cannot go through\r\n */\r\n pickBlockerMeshes?: AbstractMesh[];\r\n\r\n /**\r\n * Color of the teleportation ray when it is blocked by a mesh in the pickBlockerMeshes array\r\n * Defaults to red.\r\n */\r\n blockedRayColor?: Color4;\r\n\r\n /**\r\n * Should teleport work only on a specific hand?\r\n */\r\n forceHandedness?: XRHandedness;\r\n\r\n /**\r\n * If provided, this function will be used to generate the ray mesh instead of the lines mesh being used per default\r\n */\r\n generateRayPathMesh?: (points: Vector3[], pickingInfo: PickingInfo) => AbstractMesh;\r\n}\r\n\r\n/**\r\n * This is a teleportation feature to be used with WebXR-enabled motion controllers.\r\n * When enabled and attached, the feature will allow a user to move around and rotate in the scene using\r\n * the input of the attached controllers.\r\n */\r\nexport class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {\r\n private _controllers: {\r\n [controllerUniqueId: string]: {\r\n xrController: WebXRInputSource;\r\n teleportationComponent?: WebXRControllerComponent;\r\n teleportationState: {\r\n forward: boolean;\r\n backwards: boolean;\r\n currentRotation: number;\r\n baseRotation: number;\r\n rotating: boolean;\r\n blocked: boolean;\r\n };\r\n onAxisChangedObserver?: Nullable>;\r\n onButtonChangedObserver?: Nullable>;\r\n };\r\n } = {};\r\n private _currentTeleportationControllerId: string;\r\n private _floorMeshes: AbstractMesh[];\r\n private _quadraticBezierCurve: Nullable;\r\n private _selectionFeature: Nullable;\r\n private _snapToPositions: Vector3[];\r\n private _snappedToPoint: boolean = false;\r\n private _teleportationRingMaterial?: StandardMaterial;\r\n private _blockedRayColor: Color4;\r\n private _cachedColor4White = new Color4(1, 1, 1, 1);\r\n private _tmpRay = new Ray(new Vector3(), new Vector3());\r\n private _tmpVector = new Vector3();\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n /**\r\n * Skip the next teleportation. This can be controlled by the user to prevent the user from teleportation\r\n * to sections that are not yet \"unlocked\", but should still show the teleportation mesh.\r\n */\r\n public skipNextTeleportation = false;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.TELEPORTATION;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Is movement backwards enabled\r\n */\r\n public backwardsMovementEnabled = true;\r\n /**\r\n * Distance to travel when moving backwards\r\n */\r\n public backwardsTeleportationDistance: number = 0.7;\r\n /**\r\n * The distance from the user to the inspection point in the direction of the controller\r\n * A higher number will allow the user to move further\r\n * defaults to 5 (meters, in xr units)\r\n */\r\n public parabolicCheckRadius: number = 5;\r\n /**\r\n * Should the module support parabolic ray on top of direct ray\r\n * If enabled, the user will be able to point \"at the sky\" and move according to predefined radius distance\r\n * Very helpful when moving between floors / different heights\r\n */\r\n public parabolicRayEnabled: boolean = true;\r\n\r\n /**\r\n * The second type of ray - straight line.\r\n * Should it be enabled or should the parabolic line be the only one.\r\n */\r\n public straightRayEnabled: boolean = true;\r\n /**\r\n * How much rotation should be applied when rotating right and left\r\n */\r\n public rotationAngle: number = Math.PI / 8;\r\n\r\n /**\r\n * This observable will notify when the target mesh position was updated.\r\n * The picking info it provides contains the point to which the target mesh will move ()\r\n */\r\n public onTargetMeshPositionUpdatedObservable: Observable = new Observable();\r\n\r\n /**\r\n * Is teleportation enabled. Can be used to allow rotation only.\r\n */\r\n public teleportationEnabled: boolean = true;\r\n\r\n private _rotationEnabled: boolean = true;\r\n\r\n /**\r\n * Is rotation enabled when moving forward?\r\n * Disabling this feature will prevent the user from deciding the direction when teleporting\r\n */\r\n public get rotationEnabled(): boolean {\r\n return this._rotationEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether rotation is enabled or not\r\n * @param enabled is rotation enabled when teleportation is shown\r\n */\r\n public set rotationEnabled(enabled: boolean) {\r\n this._rotationEnabled = enabled;\r\n\r\n if (this._options.teleportationTargetMesh) {\r\n const children = this._options.teleportationTargetMesh.getChildMeshes(false, (node) => node.name === \"rotationCone\");\r\n if (children[0]) {\r\n children[0].setEnabled(enabled);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Exposes the currently set teleportation target mesh.\r\n */\r\n public get teleportationTargetMesh(): Nullable {\r\n return this._options.teleportationTargetMesh || null;\r\n }\r\n\r\n /**\r\n * constructs a new teleportation system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param _options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private _options: IWebXRTeleportationOptions) {\r\n super(_xrSessionManager);\r\n // create default mesh if not provided\r\n if (!this._options.teleportationTargetMesh) {\r\n this._createDefaultTargetMesh();\r\n }\r\n\r\n this._floorMeshes = this._options.floorMeshes || [];\r\n this._snapToPositions = this._options.snapPositions || [];\r\n this._blockedRayColor = this._options.blockedRayColor || new Color4(1, 0, 0, 0.75);\r\n\r\n this._setTargetMeshVisibility(false);\r\n }\r\n\r\n /**\r\n * Get the snapPointsOnly flag\r\n */\r\n public get snapPointsOnly(): boolean {\r\n return !!this._options.snapPointsOnly;\r\n }\r\n\r\n /**\r\n * Sets the snapPointsOnly flag\r\n * @param snapToPoints should teleportation be exclusively to snap points\r\n */\r\n public set snapPointsOnly(snapToPoints: boolean) {\r\n this._options.snapPointsOnly = snapToPoints;\r\n }\r\n\r\n /**\r\n * Add a new mesh to the floor meshes array\r\n * @param mesh the mesh to use as floor mesh\r\n */\r\n public addFloorMesh(mesh: AbstractMesh) {\r\n this._floorMeshes.push(mesh);\r\n }\r\n\r\n /**\r\n * Add a mesh to the list of meshes blocking the teleportation ray\r\n * @param mesh The mesh to add to the teleportation-blocking meshes\r\n */\r\n public addBlockerMesh(mesh: AbstractMesh) {\r\n this._options.pickBlockerMeshes = this._options.pickBlockerMeshes || [];\r\n this._options.pickBlockerMeshes.push(mesh);\r\n }\r\n\r\n /**\r\n * Add a new snap-to point to fix teleportation to this position\r\n * @param newSnapPoint The new Snap-To point\r\n */\r\n public addSnapPoint(newSnapPoint: Vector3) {\r\n this._snapToPositions.push(newSnapPoint);\r\n }\r\n\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n // Safety reset\r\n this._currentTeleportationControllerId = \"\";\r\n\r\n this._options.xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n this._setTargetMeshVisibility(false);\r\n this._currentTeleportationControllerId = \"\";\r\n this._controllers = {};\r\n\r\n return true;\r\n }\r\n\r\n public dispose(): void {\r\n super.dispose();\r\n this._options.teleportationTargetMesh && this._options.teleportationTargetMesh.dispose(false, true);\r\n }\r\n\r\n /**\r\n * Remove a mesh from the floor meshes array\r\n * @param mesh the mesh to remove\r\n */\r\n public removeFloorMesh(mesh: AbstractMesh) {\r\n const index = this._floorMeshes.indexOf(mesh);\r\n if (index !== -1) {\r\n this._floorMeshes.splice(index, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Remove a mesh from the blocker meshes array\r\n * @param mesh the mesh to remove\r\n */\r\n public removeBlockerMesh(mesh: AbstractMesh) {\r\n this._options.pickBlockerMeshes = this._options.pickBlockerMeshes || [];\r\n const index = this._options.pickBlockerMeshes.indexOf(mesh);\r\n if (index !== -1) {\r\n this._options.pickBlockerMeshes.splice(index, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Remove a mesh from the floor meshes array using its name\r\n * @param name the mesh name to remove\r\n */\r\n public removeFloorMeshByName(name: string) {\r\n const mesh = this._xrSessionManager.scene.getMeshByName(name);\r\n if (mesh) {\r\n this.removeFloorMesh(mesh);\r\n }\r\n }\r\n\r\n /**\r\n * This function will iterate through the array, searching for this point or equal to it. It will then remove it from the snap-to array\r\n * @param snapPointToRemove the point (or a clone of it) to be removed from the array\r\n * @returns was the point found and removed or not\r\n */\r\n public removeSnapPoint(snapPointToRemove: Vector3): boolean {\r\n // check if the object is in the array\r\n let index = this._snapToPositions.indexOf(snapPointToRemove);\r\n // if not found as an object, compare to the points\r\n if (index === -1) {\r\n for (let i = 0; i < this._snapToPositions.length; ++i) {\r\n // equals? index is i, break the loop\r\n if (this._snapToPositions[i].equals(snapPointToRemove)) {\r\n index = i;\r\n break;\r\n }\r\n }\r\n }\r\n // index is not -1? remove the object\r\n if (index !== -1) {\r\n this._snapToPositions.splice(index, 1);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * This function sets a selection feature that will be disabled when\r\n * the forward ray is shown and will be reattached when hidden.\r\n * This is used to remove the selection rays when moving.\r\n * @param selectionFeature the feature to disable when forward movement is enabled\r\n */\r\n public setSelectionFeature(selectionFeature: Nullable) {\r\n this._selectionFeature = selectionFeature;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n const frame = this._xrSessionManager.currentFrame;\r\n const scene = this._xrSessionManager.scene;\r\n if (!this.attach || !frame) {\r\n return;\r\n }\r\n\r\n // render target if needed\r\n const targetMesh = this._options.teleportationTargetMesh;\r\n if (this._currentTeleportationControllerId) {\r\n if (!targetMesh) {\r\n return;\r\n }\r\n targetMesh.rotationQuaternion = targetMesh.rotationQuaternion || new Quaternion();\r\n const controllerData = this._controllers[this._currentTeleportationControllerId];\r\n if (controllerData && controllerData.teleportationState.forward) {\r\n // set the rotation\r\n Quaternion.RotationYawPitchRollToRef(\r\n controllerData.teleportationState.currentRotation + controllerData.teleportationState.baseRotation,\r\n 0,\r\n 0,\r\n targetMesh.rotationQuaternion\r\n );\r\n // set the ray and position\r\n\r\n let hitPossible = false;\r\n controllerData.xrController.getWorldPointerRayToRef(this._tmpRay);\r\n if (this.straightRayEnabled) {\r\n // first check if direct ray possible\r\n // pick grounds that are LOWER only. upper will use parabolic path\r\n const pick = scene.pickWithRay(this._tmpRay, (o) => {\r\n // check for mesh-blockers\r\n if (this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(o) !== -1) {\r\n return true;\r\n }\r\n const index = this._floorMeshes.indexOf(o);\r\n if (index === -1) {\r\n return false;\r\n }\r\n return this._floorMeshes[index].absolutePosition.y < this._options.xrInput.xrCamera.globalPosition.y;\r\n });\r\n if (pick && pick.pickedMesh && this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(pick.pickedMesh) !== -1) {\r\n controllerData.teleportationState.blocked = true;\r\n this._setTargetMeshVisibility(false);\r\n this._showParabolicPath(pick);\r\n return;\r\n } else if (pick && pick.pickedPoint) {\r\n controllerData.teleportationState.blocked = false;\r\n hitPossible = true;\r\n this._setTargetMeshPosition(pick);\r\n this._setTargetMeshVisibility(true);\r\n this._showParabolicPath(pick);\r\n }\r\n }\r\n // straight ray is still the main ray, but disabling the straight line will force parabolic line.\r\n if (this.parabolicRayEnabled && !hitPossible) {\r\n // radius compensation according to pointer rotation around X\r\n const xRotation = controllerData.xrController.pointer.rotationQuaternion!.toEulerAngles().x;\r\n const compensation = 1 + (Math.PI / 2 - Math.abs(xRotation));\r\n // check parabolic ray\r\n const radius = this.parabolicCheckRadius * compensation;\r\n this._tmpRay.origin.addToRef(this._tmpRay.direction.scale(radius * 2), this._tmpVector);\r\n this._tmpVector.y = this._tmpRay.origin.y;\r\n this._tmpRay.origin.addInPlace(this._tmpRay.direction.scale(radius));\r\n this._tmpVector.subtractToRef(this._tmpRay.origin, this._tmpRay.direction);\r\n this._tmpRay.direction.normalize();\r\n\r\n const pick = scene.pickWithRay(this._tmpRay, (o) => {\r\n // check for mesh-blockers\r\n if (this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(o) !== -1) {\r\n return true;\r\n }\r\n return this._floorMeshes.indexOf(o) !== -1;\r\n });\r\n if (pick && pick.pickedMesh && this._options.pickBlockerMeshes && this._options.pickBlockerMeshes.indexOf(pick.pickedMesh) !== -1) {\r\n controllerData.teleportationState.blocked = true;\r\n this._setTargetMeshVisibility(false);\r\n this._showParabolicPath(pick);\r\n return;\r\n } else if (pick && pick.pickedPoint) {\r\n controllerData.teleportationState.blocked = false;\r\n hitPossible = true;\r\n this._setTargetMeshPosition(pick);\r\n this._setTargetMeshVisibility(true);\r\n this._showParabolicPath(pick);\r\n }\r\n }\r\n\r\n // if needed, set visible:\r\n this._setTargetMeshVisibility(hitPossible);\r\n } else {\r\n this._setTargetMeshVisibility(false);\r\n }\r\n } else {\r\n this._disposeBezierCurve();\r\n this._setTargetMeshVisibility(false);\r\n }\r\n }\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId] || (this._options.forceHandedness && xrController.inputSource.handedness !== this._options.forceHandedness)) {\r\n // already attached\r\n return;\r\n }\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n teleportationState: {\r\n forward: false,\r\n backwards: false,\r\n rotating: false,\r\n currentRotation: 0,\r\n baseRotation: 0,\r\n blocked: false,\r\n },\r\n };\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n // motion controller only available to gamepad-enabled input sources.\r\n if (controllerData.xrController.inputSource.targetRayMode === \"tracked-pointer\" && controllerData.xrController.inputSource.gamepad) {\r\n // motion controller support\r\n const initMotionController = () => {\r\n if (xrController.motionController) {\r\n const movementController =\r\n xrController.motionController.getComponentOfType(WebXRControllerComponent.THUMBSTICK_TYPE) ||\r\n xrController.motionController.getComponentOfType(WebXRControllerComponent.TOUCHPAD_TYPE);\r\n if (!movementController || this._options.useMainComponentOnly) {\r\n // use trigger to move on long press\r\n const mainComponent = xrController.motionController.getMainComponent();\r\n if (!mainComponent) {\r\n return;\r\n }\r\n controllerData.teleportationComponent = mainComponent;\r\n controllerData.onButtonChangedObserver = mainComponent.onButtonStateChangedObservable.add(() => {\r\n if (!this.teleportationEnabled) {\r\n return;\r\n }\r\n // did \"pressed\" changed?\r\n if (mainComponent.changes.pressed) {\r\n if (mainComponent.changes.pressed.current) {\r\n // simulate \"forward\" thumbstick push\r\n controllerData.teleportationState.forward = true;\r\n this._currentTeleportationControllerId = controllerData.xrController.uniqueId;\r\n controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;\r\n controllerData.teleportationState.currentRotation = 0;\r\n const timeToSelect = this._options.timeToTeleport || 3000;\r\n setAndStartTimer({\r\n timeout: timeToSelect,\r\n contextObservable: this._xrSessionManager.onXRFrameObservable,\r\n breakCondition: () => !mainComponent.pressed,\r\n onEnded: () => {\r\n if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {\r\n this._teleportForward(xrController.uniqueId);\r\n }\r\n },\r\n });\r\n } else {\r\n controllerData.teleportationState.forward = false;\r\n this._currentTeleportationControllerId = \"\";\r\n }\r\n }\r\n });\r\n } else {\r\n controllerData.teleportationComponent = movementController;\r\n // use thumbstick (or touchpad if thumbstick not available)\r\n controllerData.onAxisChangedObserver = movementController.onAxisValueChangedObservable.add((axesData) => {\r\n if (axesData.y <= 0.7 && controllerData.teleportationState.backwards) {\r\n controllerData.teleportationState.backwards = false;\r\n }\r\n if (axesData.y > 0.7 && !controllerData.teleportationState.forward && this.backwardsMovementEnabled && !this.snapPointsOnly) {\r\n // teleport backwards\r\n\r\n // General gist: Go Back N units, cast a ray towards the floor. If collided, move.\r\n if (!controllerData.teleportationState.backwards) {\r\n controllerData.teleportationState.backwards = true;\r\n // teleport backwards ONCE\r\n this._tmpQuaternion.copyFrom(this._options.xrInput.xrCamera.rotationQuaternion!);\r\n this._tmpQuaternion.toEulerAnglesToRef(this._tmpVector);\r\n // get only the y rotation\r\n this._tmpVector.x = 0;\r\n this._tmpVector.z = 0;\r\n // get the quaternion\r\n Quaternion.FromEulerVectorToRef(this._tmpVector, this._tmpQuaternion);\r\n this._tmpVector.set(0, 0, this.backwardsTeleportationDistance * (this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0));\r\n this._tmpVector.rotateByQuaternionToRef(this._tmpQuaternion, this._tmpVector);\r\n this._tmpVector.addInPlace(this._options.xrInput.xrCamera.position);\r\n this._tmpRay.origin.copyFrom(this._tmpVector);\r\n // This will prevent the user from \"falling\" to a lower platform!\r\n // TODO - should this be a flag? 'allow falling to lower platforms'?\r\n this._tmpRay.length = this._options.xrInput.xrCamera.realWorldHeight + 0.1;\r\n // Right handed system had here \"1\" instead of -1. This is unneeded.\r\n this._tmpRay.direction.set(0, -1, 0);\r\n const pick = this._xrSessionManager.scene.pickWithRay(this._tmpRay, (o) => {\r\n return this._floorMeshes.indexOf(o) !== -1;\r\n });\r\n\r\n // pick must exist, but stay safe\r\n if (pick && pick.pickedPoint) {\r\n // Teleport the users feet to where they targeted. Ignore the Y axis.\r\n // If the \"falling to lower platforms\" feature is implemented the Y axis should be set here as well\r\n this._options.xrInput.xrCamera.position.x = pick.pickedPoint.x;\r\n this._options.xrInput.xrCamera.position.z = pick.pickedPoint.z;\r\n }\r\n }\r\n }\r\n if (axesData.y < -0.7 && !this._currentTeleportationControllerId && !controllerData.teleportationState.rotating && this.teleportationEnabled) {\r\n controllerData.teleportationState.forward = true;\r\n this._currentTeleportationControllerId = controllerData.xrController.uniqueId;\r\n controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;\r\n }\r\n if (axesData.x) {\r\n if (!controllerData.teleportationState.forward) {\r\n if (!controllerData.teleportationState.rotating && Math.abs(axesData.x) > 0.7) {\r\n // rotate in the right direction positive is right\r\n controllerData.teleportationState.rotating = true;\r\n const rotation = this.rotationAngle * (axesData.x > 0 ? 1 : -1) * (this._xrSessionManager.scene.useRightHandedSystem ? -1 : 1);\r\n Quaternion.FromEulerAngles(0, rotation, 0).multiplyToRef(\r\n this._options.xrInput.xrCamera.rotationQuaternion,\r\n this._options.xrInput.xrCamera.rotationQuaternion\r\n );\r\n }\r\n } else {\r\n if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId) {\r\n // set the rotation of the forward movement\r\n if (this.rotationEnabled) {\r\n setTimeout(() => {\r\n controllerData.teleportationState.currentRotation = Math.atan2(\r\n axesData.x,\r\n axesData.y * (this._xrSessionManager.scene.useRightHandedSystem ? 1 : -1)\r\n );\r\n });\r\n } else {\r\n controllerData.teleportationState.currentRotation = 0;\r\n }\r\n }\r\n }\r\n } else {\r\n controllerData.teleportationState.rotating = false;\r\n }\r\n\r\n if (axesData.x === 0 && axesData.y === 0) {\r\n if (controllerData.teleportationState.blocked) {\r\n controllerData.teleportationState.blocked = false;\r\n this._setTargetMeshVisibility(false);\r\n }\r\n if (controllerData.teleportationState.forward) {\r\n this._teleportForward(xrController.uniqueId);\r\n }\r\n }\r\n });\r\n }\r\n }\r\n };\r\n if (xrController.motionController) {\r\n initMotionController();\r\n } else {\r\n xrController.onMotionControllerInitObservable.addOnce(() => {\r\n initMotionController();\r\n });\r\n }\r\n } else {\r\n this._xrSessionManager.scene.onPointerObservable.add((pointerInfo) => {\r\n if (pointerInfo.type === PointerEventTypes.POINTERDOWN) {\r\n controllerData.teleportationState.forward = true;\r\n this._currentTeleportationControllerId = controllerData.xrController.uniqueId;\r\n controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;\r\n controllerData.teleportationState.currentRotation = 0;\r\n const timeToSelect = this._options.timeToTeleport || 3000;\r\n setAndStartTimer({\r\n timeout: timeToSelect,\r\n contextObservable: this._xrSessionManager.onXRFrameObservable,\r\n onEnded: () => {\r\n if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {\r\n this._teleportForward(xrController.uniqueId);\r\n }\r\n },\r\n });\r\n } else if (pointerInfo.type === PointerEventTypes.POINTERUP) {\r\n controllerData.teleportationState.forward = false;\r\n this._currentTeleportationControllerId = \"\";\r\n }\r\n });\r\n }\r\n };\r\n\r\n private _createDefaultTargetMesh() {\r\n // set defaults\r\n this._options.defaultTargetMeshOptions = this._options.defaultTargetMeshOptions || {};\r\n const sceneToRenderTo = this._options.useUtilityLayer\r\n ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene\r\n : this._xrSessionManager.scene;\r\n const teleportationTarget = CreateGround(\"teleportationTarget\", { width: 2, height: 2, subdivisions: 2 }, sceneToRenderTo);\r\n teleportationTarget.isPickable = false;\r\n\r\n if (this._options.defaultTargetMeshOptions.teleportationCircleMaterial) {\r\n teleportationTarget.material = this._options.defaultTargetMeshOptions.teleportationCircleMaterial;\r\n } else {\r\n const length = 512;\r\n const dynamicTexture = new DynamicTexture(\"teleportationPlaneDynamicTexture\", length, sceneToRenderTo, true);\r\n dynamicTexture.hasAlpha = true;\r\n const context = dynamicTexture.getContext();\r\n const centerX = length / 2;\r\n const centerY = length / 2;\r\n const radius = 200;\r\n context.beginPath();\r\n context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);\r\n context.fillStyle = this._options.defaultTargetMeshOptions.teleportationFillColor || \"#444444\";\r\n context.fill();\r\n context.lineWidth = 10;\r\n context.strokeStyle = this._options.defaultTargetMeshOptions.teleportationBorderColor || \"#FFFFFF\";\r\n context.stroke();\r\n context.closePath();\r\n dynamicTexture.update();\r\n const teleportationCircleMaterial = new StandardMaterial(\"teleportationPlaneMaterial\", sceneToRenderTo);\r\n teleportationCircleMaterial.diffuseTexture = dynamicTexture;\r\n teleportationTarget.material = teleportationCircleMaterial;\r\n }\r\n\r\n const torus = CreateTorus(\r\n \"torusTeleportation\",\r\n {\r\n diameter: 0.75,\r\n thickness: 0.1,\r\n tessellation: 20,\r\n },\r\n sceneToRenderTo\r\n );\r\n torus.isPickable = false;\r\n torus.parent = teleportationTarget;\r\n if (!this._options.defaultTargetMeshOptions.disableAnimation) {\r\n const animationInnerCircle = new Animation(\"animationInnerCircle\", \"position.y\", 30, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);\r\n const keys = [];\r\n keys.push({\r\n frame: 0,\r\n value: 0,\r\n });\r\n keys.push({\r\n frame: 30,\r\n value: 0.4,\r\n });\r\n keys.push({\r\n frame: 60,\r\n value: 0,\r\n });\r\n animationInnerCircle.setKeys(keys);\r\n const easingFunction = new SineEase();\r\n easingFunction.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);\r\n animationInnerCircle.setEasingFunction(easingFunction);\r\n torus.animations = [];\r\n torus.animations.push(animationInnerCircle);\r\n sceneToRenderTo.beginAnimation(torus, 0, 60, true);\r\n }\r\n\r\n const cone = CreateCylinder(\"rotationCone\", { diameterTop: 0, tessellation: 4 }, sceneToRenderTo);\r\n cone.isPickable = false;\r\n cone.scaling.set(0.5, 0.12, 0.2);\r\n\r\n cone.rotate(Axis.X, Math.PI / 2);\r\n\r\n cone.position.z = 0.6;\r\n cone.parent = torus;\r\n\r\n if (this._options.defaultTargetMeshOptions.torusArrowMaterial) {\r\n torus.material = this._options.defaultTargetMeshOptions.torusArrowMaterial;\r\n cone.material = this._options.defaultTargetMeshOptions.torusArrowMaterial;\r\n } else {\r\n const torusConeMaterial = new StandardMaterial(\"torusConsMat\", sceneToRenderTo);\r\n torusConeMaterial.disableLighting = !!this._options.defaultTargetMeshOptions.disableLighting;\r\n if (torusConeMaterial.disableLighting) {\r\n torusConeMaterial.emissiveColor = new Color3(0.3, 0.3, 1.0);\r\n } else {\r\n torusConeMaterial.diffuseColor = new Color3(0.3, 0.3, 1.0);\r\n }\r\n torusConeMaterial.alpha = 0.9;\r\n torus.material = torusConeMaterial;\r\n cone.material = torusConeMaterial;\r\n this._teleportationRingMaterial = torusConeMaterial;\r\n }\r\n\r\n if (this._options.renderingGroupId !== undefined) {\r\n teleportationTarget.renderingGroupId = this._options.renderingGroupId;\r\n torus.renderingGroupId = this._options.renderingGroupId;\r\n cone.renderingGroupId = this._options.renderingGroupId;\r\n }\r\n\r\n this._options.teleportationTargetMesh = teleportationTarget;\r\n // hide the teleportation target mesh right after creating it.\r\n this._setTargetMeshVisibility(false);\r\n }\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n if (controllerData.teleportationComponent) {\r\n if (controllerData.onAxisChangedObserver) {\r\n controllerData.teleportationComponent.onAxisValueChangedObservable.remove(controllerData.onAxisChangedObserver);\r\n }\r\n if (controllerData.onButtonChangedObserver) {\r\n controllerData.teleportationComponent.onButtonStateChangedObservable.remove(controllerData.onButtonChangedObserver);\r\n }\r\n }\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n\r\n private _findClosestSnapPointWithRadius(realPosition: Vector3, radius: number = this._options.snapToPositionRadius || 0.8) {\r\n let closestPoint: Nullable = null;\r\n let closestDistance = Number.MAX_VALUE;\r\n if (this._snapToPositions.length) {\r\n const radiusSquared = radius * radius;\r\n this._snapToPositions.forEach((position) => {\r\n const dist = Vector3.DistanceSquared(position, realPosition);\r\n if (dist <= radiusSquared && dist < closestDistance) {\r\n closestDistance = dist;\r\n closestPoint = position;\r\n }\r\n });\r\n }\r\n return closestPoint;\r\n }\r\n\r\n private _setTargetMeshPosition(pickInfo: PickingInfo) {\r\n const newPosition = pickInfo.pickedPoint;\r\n if (!this._options.teleportationTargetMesh || !newPosition) {\r\n return;\r\n }\r\n const snapPosition = this._findClosestSnapPointWithRadius(newPosition);\r\n this._snappedToPoint = !!snapPosition;\r\n if (this.snapPointsOnly && !this._snappedToPoint && this._teleportationRingMaterial) {\r\n this._teleportationRingMaterial.diffuseColor.set(1.0, 0.3, 0.3);\r\n } else if (this.snapPointsOnly && this._snappedToPoint && this._teleportationRingMaterial) {\r\n this._teleportationRingMaterial.diffuseColor.set(0.3, 0.3, 1.0);\r\n }\r\n this._options.teleportationTargetMesh.position.copyFrom(snapPosition || newPosition);\r\n this._options.teleportationTargetMesh.position.y += 0.01;\r\n this.onTargetMeshPositionUpdatedObservable.notifyObservers(pickInfo);\r\n }\r\n\r\n private _setTargetMeshVisibility(visible: boolean, force?: boolean) {\r\n if (!this._options.teleportationTargetMesh) {\r\n return;\r\n }\r\n if (this._options.teleportationTargetMesh.isVisible === visible && !force) {\r\n return;\r\n }\r\n this._options.teleportationTargetMesh.isVisible = visible;\r\n this._options.teleportationTargetMesh.getChildren(undefined, false).forEach((m) => {\r\n (m).isVisible = visible;\r\n });\r\n\r\n if (!visible) {\r\n if (this._quadraticBezierCurve) {\r\n this._quadraticBezierCurve.dispose();\r\n this._quadraticBezierCurve = null;\r\n }\r\n if (this._selectionFeature) {\r\n this._selectionFeature.attach();\r\n }\r\n } else {\r\n if (this._selectionFeature) {\r\n this._selectionFeature.detach();\r\n }\r\n }\r\n }\r\n\r\n private _disposeBezierCurve() {\r\n if (this._quadraticBezierCurve) {\r\n this._quadraticBezierCurve.dispose();\r\n this._quadraticBezierCurve = null;\r\n }\r\n }\r\n\r\n private _showParabolicPath(pickInfo: PickingInfo) {\r\n if (!pickInfo.pickedPoint || !this._currentTeleportationControllerId) {\r\n return;\r\n }\r\n\r\n const sceneToRenderTo = this._options.useUtilityLayer\r\n ? this._options.customUtilityLayerScene || UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene\r\n : this._xrSessionManager.scene;\r\n\r\n const controllerData = this._controllers[this._currentTeleportationControllerId];\r\n\r\n const quadraticBezierVectors = Curve3.CreateQuadraticBezier(controllerData.xrController.pointer.absolutePosition, pickInfo.ray!.origin, pickInfo.pickedPoint, 25);\r\n const color = controllerData.teleportationState.blocked ? this._blockedRayColor : undefined;\r\n const colorsArray = new Array(26).fill(color || this._cachedColor4White);\r\n if (!this._options.generateRayPathMesh) {\r\n this._quadraticBezierCurve = CreateLines(\r\n \"teleportation path line\",\r\n { points: quadraticBezierVectors.getPoints(), instance: this._quadraticBezierCurve as LinesMesh, updatable: true, colors: colorsArray },\r\n sceneToRenderTo\r\n );\r\n } else {\r\n this._quadraticBezierCurve = this._options.generateRayPathMesh(quadraticBezierVectors.getPoints(), pickInfo);\r\n }\r\n this._quadraticBezierCurve.isPickable = false;\r\n if (this._options.renderingGroupId !== undefined) {\r\n this._quadraticBezierCurve.renderingGroupId = this._options.renderingGroupId;\r\n }\r\n }\r\n\r\n private _teleportForward(controllerId: string) {\r\n const controllerData = this._controllers[controllerId];\r\n if (!controllerData || !controllerData.teleportationState.forward || !this.teleportationEnabled) {\r\n return;\r\n }\r\n controllerData.teleportationState.forward = false;\r\n this._currentTeleportationControllerId = \"\";\r\n if (this.snapPointsOnly && !this._snappedToPoint) {\r\n return;\r\n }\r\n\r\n if (this.skipNextTeleportation) {\r\n this.skipNextTeleportation = false;\r\n return;\r\n }\r\n // do the movement forward here\r\n if (this._options.teleportationTargetMesh && this._options.teleportationTargetMesh.isVisible) {\r\n const height = this._options.xrInput.xrCamera.realWorldHeight;\r\n this._options.xrInput.xrCamera.onBeforeCameraTeleport.notifyObservers(this._options.xrInput.xrCamera.position);\r\n this._options.xrInput.xrCamera.position.copyFrom(this._options.teleportationTargetMesh.position);\r\n this._options.xrInput.xrCamera.position.y += height;\r\n Quaternion.FromEulerAngles(0, controllerData.teleportationState.currentRotation - (this._xrSessionManager.scene.useRightHandedSystem ? Math.PI : 0), 0).multiplyToRef(\r\n this._options.xrInput.xrCamera.rotationQuaternion,\r\n this._options.xrInput.xrCamera.rotationQuaternion\r\n );\r\n this._options.xrInput.xrCamera.onAfterCameraTeleport.notifyObservers(this._options.xrInput.xrCamera.position);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRMotionControllerTeleportation.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRMotionControllerTeleportation(xrSessionManager, options);\r\n },\r\n WebXRMotionControllerTeleportation.Version,\r\n true\r\n);\r\n","import { WebXRExperienceHelper } from \"./webXRExperienceHelper\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { IWebXRInputOptions } from \"./webXRInput\";\r\nimport { WebXRInput } from \"./webXRInput\";\r\nimport type { IWebXRControllerPointerSelectionOptions } from \"./features/WebXRControllerPointerSelection\";\r\nimport { WebXRControllerPointerSelection } from \"./features/WebXRControllerPointerSelection\";\r\nimport type { IWebXRNearInteractionOptions } from \"./features/WebXRNearInteraction\";\r\nimport { WebXRNearInteraction } from \"./features/WebXRNearInteraction\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport type { WebXREnterExitUIOptions } from \"./webXREnterExitUI\";\r\nimport { WebXREnterExitUI } from \"./webXREnterExitUI\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { WebXRManagedOutputCanvasOptions } from \"./webXRManagedOutputCanvas\";\r\nimport type { IWebXRTeleportationOptions } from \"./features/WebXRControllerTeleportation\";\r\nimport { WebXRMotionControllerTeleportation } from \"./features/WebXRControllerTeleportation\";\r\nimport { Logger } from \"../Misc/logger\";\r\n\r\n/**\r\n * Options for the default xr helper\r\n */\r\nexport class WebXRDefaultExperienceOptions {\r\n /**\r\n * Enable or disable default UI to enter XR\r\n */\r\n public disableDefaultUI?: boolean;\r\n /**\r\n * Should pointer selection not initialize.\r\n * Note that disabling pointer selection also disables teleportation.\r\n * Defaults to false.\r\n */\r\n public disablePointerSelection?: boolean;\r\n /**\r\n * Should teleportation not initialize. Defaults to false.\r\n */\r\n public disableTeleportation?: boolean;\r\n /**\r\n * Should nearInteraction not initialize. Defaults to false.\r\n */\r\n public disableNearInteraction?: boolean;\r\n /**\r\n * Floor meshes that will be used for teleport\r\n */\r\n public floorMeshes?: Array;\r\n /**\r\n * If set to true, the first frame will not be used to reset position\r\n * The first frame is mainly used when copying transformation from the old camera\r\n * Mainly used in AR\r\n */\r\n public ignoreNativeCameraTransformation?: boolean;\r\n /**\r\n * Optional configuration for the XR input object\r\n */\r\n public inputOptions?: Partial;\r\n /**\r\n * optional configuration for pointer selection\r\n */\r\n public pointerSelectionOptions?: Partial;\r\n /**\r\n * optional configuration for near interaction\r\n */\r\n public nearInteractionOptions?: Partial;\r\n /**\r\n * optional configuration for teleportation\r\n */\r\n public teleportationOptions?: Partial;\r\n /**\r\n * optional configuration for the output canvas\r\n */\r\n public outputCanvasOptions?: WebXRManagedOutputCanvasOptions;\r\n /**\r\n * optional UI options. This can be used among other to change session mode and reference space type\r\n */\r\n public uiOptions?: Partial;\r\n /**\r\n * When loading teleportation and pointer select, use stable versions instead of latest.\r\n */\r\n public useStablePlugins?: boolean;\r\n\r\n /**\r\n * An optional rendering group id that will be set globally for teleportation, pointer selection and default controller meshes\r\n */\r\n public renderingGroupId?: number;\r\n\r\n /**\r\n * A list of optional features to init the session with\r\n * If set to true, all features we support will be added\r\n */\r\n public optionalFeatures?: boolean | string[];\r\n}\r\n\r\n/**\r\n * Default experience which provides a similar setup to the previous webVRExperience\r\n */\r\nexport class WebXRDefaultExperience {\r\n /**\r\n * Base experience\r\n */\r\n public baseExperience: WebXRExperienceHelper;\r\n /**\r\n * Enables ui for entering/exiting xr\r\n */\r\n public enterExitUI: WebXREnterExitUI;\r\n /**\r\n * Input experience extension\r\n */\r\n public input: WebXRInput;\r\n /**\r\n * Enables laser pointer and selection\r\n */\r\n public pointerSelection: WebXRControllerPointerSelection;\r\n /**\r\n * Default target xr should render to\r\n */\r\n public renderTarget: WebXRRenderTarget;\r\n /**\r\n * Enables teleportation\r\n */\r\n public teleportation: WebXRMotionControllerTeleportation;\r\n\r\n /**\r\n * Enables near interaction for hands/controllers\r\n */\r\n public nearInteraction: WebXRNearInteraction;\r\n\r\n private constructor() {}\r\n\r\n /**\r\n * Creates the default xr experience\r\n * @param scene scene\r\n * @param options options for basic configuration\r\n * @returns resulting WebXRDefaultExperience\r\n */\r\n public static CreateAsync(scene: Scene, options: WebXRDefaultExperienceOptions = {}) {\r\n const result = new WebXRDefaultExperience();\r\n scene.onDisposeObservable.addOnce(() => {\r\n result.dispose();\r\n });\r\n // init the UI right after construction\r\n if (!options.disableDefaultUI) {\r\n const uiOptions: WebXREnterExitUIOptions = {\r\n renderTarget: result.renderTarget,\r\n ...(options.uiOptions || {}),\r\n };\r\n if (options.optionalFeatures) {\r\n if (typeof options.optionalFeatures === \"boolean\") {\r\n uiOptions.optionalFeatures = [\"hit-test\", \"anchors\", \"plane-detection\", \"hand-tracking\"];\r\n } else {\r\n uiOptions.optionalFeatures = options.optionalFeatures;\r\n }\r\n }\r\n result.enterExitUI = new WebXREnterExitUI(scene, uiOptions);\r\n }\r\n\r\n // Create base experience\r\n return WebXRExperienceHelper.CreateAsync(scene)\r\n .then((xrHelper) => {\r\n result.baseExperience = xrHelper;\r\n\r\n if (options.ignoreNativeCameraTransformation) {\r\n result.baseExperience.camera.compensateOnFirstFrame = false;\r\n }\r\n\r\n // Add controller support\r\n result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, {\r\n controllerOptions: {\r\n renderingGroupId: options.renderingGroupId,\r\n },\r\n ...(options.inputOptions || {}),\r\n });\r\n\r\n if (!options.disablePointerSelection) {\r\n // Add default pointer selection\r\n const pointerSelectionOptions = {\r\n ...options.pointerSelectionOptions,\r\n xrInput: result.input,\r\n renderingGroupId: options.renderingGroupId,\r\n };\r\n\r\n result.pointerSelection = (\r\n result.baseExperience.featuresManager.enableFeature(\r\n WebXRControllerPointerSelection.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n pointerSelectionOptions\r\n )\r\n );\r\n\r\n if (!options.disableTeleportation) {\r\n // Add default teleportation, including rotation\r\n result.teleportation = result.baseExperience.featuresManager.enableFeature(\r\n WebXRMotionControllerTeleportation.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n {\r\n floorMeshes: options.floorMeshes,\r\n xrInput: result.input,\r\n renderingGroupId: options.renderingGroupId,\r\n ...options.teleportationOptions,\r\n }\r\n );\r\n result.teleportation.setSelectionFeature(result.pointerSelection);\r\n }\r\n }\r\n\r\n if (!options.disableNearInteraction) {\r\n // Add default pointer selection\r\n result.nearInteraction = result.baseExperience.featuresManager.enableFeature(\r\n WebXRNearInteraction.Name,\r\n options.useStablePlugins ? \"stable\" : \"latest\",\r\n {\r\n xrInput: result.input,\r\n farInteractionFeature: result.pointerSelection,\r\n renderingGroupId: options.renderingGroupId,\r\n useUtilityLayer: true,\r\n enableNearInteractionOnAllControllers: true,\r\n ...options.nearInteractionOptions,\r\n }\r\n );\r\n }\r\n\r\n // Create the WebXR output target\r\n result.renderTarget = result.baseExperience.sessionManager.getWebXRRenderTarget(options.outputCanvasOptions);\r\n\r\n if (!options.disableDefaultUI) {\r\n // Create ui for entering/exiting xr\r\n return result.enterExitUI.setHelperAsync(result.baseExperience, result.renderTarget);\r\n } else {\r\n return;\r\n }\r\n })\r\n .then(() => {\r\n return result;\r\n })\r\n .catch((error) => {\r\n Logger.Error(\"Error initializing XR\");\r\n Logger.Error(error);\r\n return result;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n if (this.baseExperience) {\r\n this.baseExperience.dispose();\r\n }\r\n if (this.input) {\r\n this.input.dispose();\r\n }\r\n if (this.enterExitUI) {\r\n this.enterExitUI.dispose();\r\n }\r\n if (this.renderTarget) {\r\n this.renderTarget.dispose();\r\n }\r\n }\r\n}\r\n","import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"../Materials/standardMaterial\";\r\nimport { PBRMaterial } from \"../Materials/PBR/pbrMaterial\";\r\nimport { HemisphericLight } from \"../Lights/hemisphericLight\";\r\nimport type { IEnvironmentHelperOptions } from \"./environmentHelper\";\r\nimport { EnvironmentHelper } from \"./environmentHelper\";\r\nimport { FreeCamera } from \"../Cameras/freeCamera\";\r\nimport { ArcRotateCamera } from \"../Cameras/arcRotateCamera\";\r\nimport type { TargetCamera } from \"../Cameras/targetCamera\";\r\nimport type { VRExperienceHelperOptions } from \"../Cameras/VR/vrExperienceHelper\";\r\nimport { VRExperienceHelper } from \"../Cameras/VR/vrExperienceHelper\";\r\n\r\nimport \"../Materials/Textures/Loaders/ddsTextureLoader\";\r\nimport \"../Materials/Textures/Loaders/envTextureLoader\";\r\nimport \"../Materials/Textures/Loaders/ktxTextureLoader\";\r\nimport { CreateBox } from \"../Meshes/Builders/boxBuilder\";\r\nimport type { WebXRDefaultExperienceOptions } from \"../XR/webXRDefaultExperience\";\r\nimport { WebXRDefaultExperience } from \"../XR/webXRDefaultExperience\";\r\n\r\n/** @internal */\r\n// eslint-disable-next-line no-var\r\nexport var _forceSceneHelpersToBundle = true;\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /**\r\n * Creates a default light for the scene.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/fastBuildWorld#create-default-light\r\n * @param replace has the default false, when true replaces the existing lights in the scene with a hemispheric light\r\n */\r\n createDefaultLight(replace?: boolean): void;\r\n\r\n /**\r\n * Creates a default camera for the scene.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/fastBuildWorld#create-default-camera\r\n * @param createArcRotateCamera has the default false which creates a free camera, when true creates an arc rotate camera\r\n * @param replace has default false, when true replaces the active camera in the scene\r\n * @param attachCameraControls has default false, when true attaches camera controls to the canvas.\r\n */\r\n createDefaultCamera(createArcRotateCamera?: boolean, replace?: boolean, attachCameraControls?: boolean): void;\r\n\r\n /**\r\n * Creates a default camera and a default light.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/fastBuildWorld#create-default-camera-or-light\r\n * @param createArcRotateCamera has the default false which creates a free camera, when true creates an arc rotate camera\r\n * @param replace has the default false, when true replaces the active camera/light in the scene\r\n * @param attachCameraControls has the default false, when true attaches camera controls to the canvas.\r\n */\r\n createDefaultCameraOrLight(createArcRotateCamera?: boolean, replace?: boolean, attachCameraControls?: boolean): void;\r\n\r\n /**\r\n * Creates a new sky box\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/fastBuildWorld#create-default-skybox\r\n * @param environmentTexture defines the texture to use as environment texture\r\n * @param pbr has default false which requires the StandardMaterial to be used, when true PBRMaterial must be used\r\n * @param scale defines the overall scale of the skybox\r\n * @param blur is only available when pbr is true, default is 0, no blur, maximum value is 1\r\n * @param setGlobalEnvTexture has default true indicating that scene.environmentTexture must match the current skybox texture\r\n * @returns a new mesh holding the sky box\r\n */\r\n createDefaultSkybox(environmentTexture?: BaseTexture, pbr?: boolean, scale?: number, blur?: number, setGlobalEnvTexture?: boolean): Nullable;\r\n\r\n /**\r\n * Creates a new environment\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/fastBuildWorld#create-default-environment\r\n * @param options defines the options you can use to configure the environment\r\n * @returns the new EnvironmentHelper\r\n */\r\n createDefaultEnvironment(options?: Partial): Nullable;\r\n\r\n /**\r\n * Creates a new VREXperienceHelper\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/webVRHelper\r\n * @param webVROptions defines the options used to create the new VREXperienceHelper\r\n * @deprecated Please use createDefaultXRExperienceAsync instead\r\n * @returns a new VREXperienceHelper\r\n */\r\n createDefaultVRExperience(webVROptions?: VRExperienceHelperOptions): VRExperienceHelper;\r\n\r\n /**\r\n * Creates a new WebXRDefaultExperience\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/introToWebXR\r\n * @param options experience options\r\n * @returns a promise for a new WebXRDefaultExperience\r\n */\r\n createDefaultXRExperienceAsync(options?: WebXRDefaultExperienceOptions): Promise;\r\n }\r\n}\r\n\r\nScene.prototype.createDefaultLight = function (replace = false): void {\r\n // Dispose existing light in replace mode.\r\n if (replace) {\r\n if (this.lights) {\r\n for (let i = 0; i < this.lights.length; i++) {\r\n this.lights[i].dispose();\r\n }\r\n }\r\n }\r\n\r\n // Light\r\n if (this.lights.length === 0) {\r\n new HemisphericLight(\"default light\", Vector3.Up(), this);\r\n }\r\n};\r\n\r\nScene.prototype.createDefaultCamera = function (createArcRotateCamera = false, replace = false, attachCameraControls = false): void {\r\n // Dispose existing camera in replace mode.\r\n if (replace) {\r\n if (this.activeCamera) {\r\n this.activeCamera.dispose();\r\n this.activeCamera = null;\r\n }\r\n }\r\n\r\n // Camera\r\n if (!this.activeCamera) {\r\n const worldExtends = this.getWorldExtends((mesh) => mesh.isVisible && mesh.isEnabled());\r\n const worldSize = worldExtends.max.subtract(worldExtends.min);\r\n const worldCenter = worldExtends.min.add(worldSize.scale(0.5));\r\n\r\n let camera: TargetCamera;\r\n let radius = worldSize.length() * 1.5;\r\n // empty scene scenario!\r\n if (!isFinite(radius)) {\r\n radius = 1;\r\n worldCenter.copyFromFloats(0, 0, 0);\r\n }\r\n if (createArcRotateCamera) {\r\n const arcRotateCamera = new ArcRotateCamera(\"default camera\", -(Math.PI / 2), Math.PI / 2, radius, worldCenter, this);\r\n arcRotateCamera.lowerRadiusLimit = radius * 0.01;\r\n arcRotateCamera.wheelPrecision = 100 / radius;\r\n camera = arcRotateCamera;\r\n } else {\r\n const freeCamera = new FreeCamera(\"default camera\", new Vector3(worldCenter.x, worldCenter.y, -radius), this);\r\n freeCamera.setTarget(worldCenter);\r\n camera = freeCamera;\r\n }\r\n camera.minZ = radius * 0.01;\r\n camera.maxZ = radius * 1000;\r\n camera.speed = radius * 0.2;\r\n this.activeCamera = camera;\r\n\r\n if (attachCameraControls) {\r\n camera.attachControl();\r\n }\r\n }\r\n};\r\n\r\nScene.prototype.createDefaultCameraOrLight = function (createArcRotateCamera = false, replace = false, attachCameraControls = false): void {\r\n this.createDefaultLight(replace);\r\n this.createDefaultCamera(createArcRotateCamera, replace, attachCameraControls);\r\n};\r\n\r\nScene.prototype.createDefaultSkybox = function (environmentTexture?: BaseTexture, pbr = false, scale = 1000, blur = 0, setGlobalEnvTexture = true): Nullable {\r\n if (!environmentTexture) {\r\n Logger.Warn(\"Can not create default skybox without environment texture.\");\r\n return null;\r\n }\r\n\r\n if (setGlobalEnvTexture) {\r\n if (environmentTexture) {\r\n this.environmentTexture = environmentTexture;\r\n }\r\n }\r\n\r\n // Skybox\r\n const hdrSkybox = CreateBox(\"hdrSkyBox\", { size: scale }, this);\r\n if (pbr) {\r\n const hdrSkyboxMaterial = new PBRMaterial(\"skyBox\", this);\r\n hdrSkyboxMaterial.backFaceCulling = false;\r\n hdrSkyboxMaterial.reflectionTexture = environmentTexture.clone();\r\n if (hdrSkyboxMaterial.reflectionTexture) {\r\n hdrSkyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;\r\n }\r\n hdrSkyboxMaterial.microSurface = 1.0 - blur;\r\n hdrSkyboxMaterial.disableLighting = true;\r\n hdrSkyboxMaterial.twoSidedLighting = true;\r\n hdrSkybox.material = hdrSkyboxMaterial;\r\n } else {\r\n const skyboxMaterial = new StandardMaterial(\"skyBox\", this);\r\n skyboxMaterial.backFaceCulling = false;\r\n skyboxMaterial.reflectionTexture = environmentTexture.clone();\r\n if (skyboxMaterial.reflectionTexture) {\r\n skyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;\r\n }\r\n skyboxMaterial.disableLighting = true;\r\n hdrSkybox.material = skyboxMaterial;\r\n }\r\n hdrSkybox.isPickable = false;\r\n hdrSkybox.infiniteDistance = true;\r\n hdrSkybox.ignoreCameraMaxZ = true;\r\n return hdrSkybox;\r\n};\r\n\r\nScene.prototype.createDefaultEnvironment = function (options: Partial): Nullable {\r\n if (EnvironmentHelper) {\r\n return new EnvironmentHelper(options, this);\r\n }\r\n return null;\r\n};\r\n\r\nScene.prototype.createDefaultVRExperience = function (webVROptions: VRExperienceHelperOptions = {}): VRExperienceHelper {\r\n return new VRExperienceHelper(this, webVROptions);\r\n};\r\n\r\nScene.prototype.createDefaultXRExperienceAsync = function (options: WebXRDefaultExperienceOptions = {}): Promise {\r\n return WebXRDefaultExperience.CreateAsync(this, options).then((helper) => {\r\n return helper;\r\n });\r\n};\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\n\nconst name = \"glowMapGenerationPixelShader\";\nconst shader = `#if defined(DIFFUSE_ISLINEAR) || defined(EMISSIVE_ISLINEAR)\n#include\n#endif\n#ifdef DIFFUSE\nvarying vec2 vUVDiffuse;uniform sampler2D diffuseSampler;\n#endif\n#ifdef OPACITY\nvarying vec2 vUVOpacity;uniform sampler2D opacitySampler;uniform float opacityIntensity;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;uniform sampler2D emissiveSampler;\n#endif\n#ifdef VERTEXALPHA\nvarying vec4 vColor;\n#endif\nuniform vec4 glowColor;uniform float glowIntensity;\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#include\nvec4 finalColor=glowColor;\n#ifdef DIFFUSE\nvec4 albedoTexture=texture2D(diffuseSampler,vUVDiffuse);\n#ifdef DIFFUSE_ISLINEAR\nalbedoTexture=toGammaSpace(albedoTexture);\n#endif\n#ifdef GLOW\nfinalColor.a*=albedoTexture.a;\n#endif\n#ifdef HIGHLIGHT\nfinalColor.a=albedoTexture.a;\n#endif\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vUVOpacity);\n#ifdef OPACITYRGB\nfinalColor.a*=getLuminance(opacityMap.rgb);\n#else\nfinalColor.a*=opacityMap.a;\n#endif\nfinalColor.a*=opacityIntensity;\n#endif\n#ifdef VERTEXALPHA\nfinalColor.a*=vColor.a;\n#endif\n#ifdef ALPHATEST\nif (finalColor.a\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\nuniform mat4 viewProjection;varying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef DIFFUSE\nvarying vec2 vUVDiffuse;uniform mat4 diffuseMatrix;\n#endif\n#ifdef OPACITY\nvarying vec2 vUVOpacity;uniform mat4 opacityMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;uniform mat4 emissiveMatrix;\n#endif\n#ifdef VERTEXALPHA\nattribute vec4 color;varying vec4 vColor;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#ifdef CUBEMAP\nvPosition=worldPos;gl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*worldPos;gl_Position=vPosition;\n#endif\n#ifdef DIFFUSE\n#ifdef DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef OPACITY\n#ifdef OPACITYUV1\nvUVOpacity=vec2(opacityMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef OPACITYUV2\nvUVOpacity=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef VERTEXALPHA\nvColor=color;\n#endif\n#include\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const glowMapGenerationVertexShader = { name, shader };\n","import { serialize, serializeAsColor4, serializeAsCameraReference } from \"../Misc/decorators\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { ISize } from \"../Maths/math.size\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MaterialHelper } from \"../Materials/materialHelper\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport \"../Shaders/glowMapGeneration.fragment\";\r\nimport \"../Shaders/glowMapGeneration.vertex\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { EffectFallbacks } from \"../Materials/effectFallbacks\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport { addClipPlaneUniforms, bindClipPlane, prepareStringDefinesForClipPlanes } from \"../Materials/clipPlaneMaterialHelper\";\r\n\r\n/**\r\n * Effect layer options. This helps customizing the behaviour\r\n * of the effect layer.\r\n */\r\nexport interface IEffectLayerOptions {\r\n /**\r\n * Multiplication factor apply to the canvas size to compute the render target size\r\n * used to generated the objects (the smaller the faster). Default: 0.5\r\n */\r\n mainTextureRatio: number;\r\n\r\n /**\r\n * Enforces a fixed size texture to ensure effect stability across devices. Default: undefined\r\n */\r\n mainTextureFixedSize?: number;\r\n\r\n /**\r\n * Alpha blending mode used to apply the blur. Default depends of the implementation. Default: ALPHA_COMBINE\r\n */\r\n alphaBlendingMode: number;\r\n\r\n /**\r\n * The camera attached to the layer. Default: null\r\n */\r\n camera: Nullable;\r\n\r\n /**\r\n * The rendering group to draw the layer in. Default: -1\r\n */\r\n renderingGroupId: number;\r\n\r\n /**\r\n * The type of the main texture. Default: TEXTURETYPE_UNSIGNED_INT\r\n */\r\n mainTextureType: number;\r\n\r\n /**\r\n * Whether or not to generate a stencil buffer. Default: false\r\n */\r\n generateStencilBuffer: boolean;\r\n}\r\n\r\n/**\r\n * The effect layer Helps adding post process effect blended with the main pass.\r\n *\r\n * This can be for instance use to generate glow or highlight effects on the scene.\r\n *\r\n * The effect layer class can not be used directly and is intented to inherited from to be\r\n * customized per effects.\r\n */\r\nexport abstract class EffectLayer {\r\n private _vertexBuffers: { [key: string]: Nullable } = {};\r\n private _indexBuffer: Nullable;\r\n private _effectLayerOptions: IEffectLayerOptions;\r\n private _mergeDrawWrapper: DrawWrapper[];\r\n\r\n protected _scene: Scene;\r\n protected _engine: Engine;\r\n protected _maxSize: number = 0;\r\n protected _mainTextureDesiredSize: ISize = { width: 0, height: 0 };\r\n protected _mainTexture: RenderTargetTexture;\r\n protected _shouldRender = true;\r\n protected _postProcesses: PostProcess[] = [];\r\n protected _textures: BaseTexture[] = [];\r\n protected _emissiveTextureAndColor: { texture: Nullable; color: Color4 } = { texture: null, color: new Color4() };\r\n protected _effectIntensity: { [meshUniqueId: number]: number } = {};\r\n\r\n /**\r\n * The name of the layer\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The clear color of the texture used to generate the glow map.\r\n */\r\n @serializeAsColor4()\r\n public neutralColor: Color4 = new Color4();\r\n\r\n /**\r\n * Specifies whether the highlight layer is enabled or not.\r\n */\r\n @serialize()\r\n public isEnabled: boolean = true;\r\n\r\n /**\r\n * Gets the camera attached to the layer.\r\n */\r\n @serializeAsCameraReference()\r\n public get camera(): Nullable {\r\n return this._effectLayerOptions.camera;\r\n }\r\n\r\n /**\r\n * Gets the rendering group id the layer should render in.\r\n */\r\n @serialize()\r\n public get renderingGroupId(): number {\r\n return this._effectLayerOptions.renderingGroupId;\r\n }\r\n public set renderingGroupId(renderingGroupId: number) {\r\n this._effectLayerOptions.renderingGroupId = renderingGroupId;\r\n }\r\n\r\n /**\r\n * Specifies if the bounding boxes should be rendered normally or if they should undergo the effect of the layer\r\n */\r\n @serialize()\r\n public disableBoundingBoxesFromEffectLayer = false;\r\n\r\n /**\r\n * An event triggered when the effect layer has been disposed.\r\n */\r\n public onDisposeObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the effect layer is about rendering the main texture with the glowy parts.\r\n */\r\n public onBeforeRenderMainTextureObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the generated texture is being merged in the scene.\r\n */\r\n public onBeforeComposeObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the mesh is rendered into the effect render target.\r\n */\r\n public onBeforeRenderMeshToEffect = new Observable();\r\n\r\n /**\r\n * An event triggered after the mesh has been rendered into the effect render target.\r\n */\r\n public onAfterRenderMeshToEffect = new Observable();\r\n\r\n /**\r\n * An event triggered when the generated texture has been merged in the scene.\r\n */\r\n public onAfterComposeObservable = new Observable();\r\n\r\n /**\r\n * An event triggered when the effect layer changes its size.\r\n */\r\n public onSizeChangedObservable = new Observable();\r\n\r\n /**\r\n * Gets the main texture where the effect is rendered\r\n */\r\n public get mainTexture() {\r\n return this._mainTexture;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {\r\n throw _WarnImport(\"EffectLayerSceneComponent\");\r\n };\r\n\r\n private _materialForRendering: { [id: string]: [AbstractMesh, Material] } = {};\r\n\r\n /**\r\n * Sets a specific material to be used to render a mesh/a list of meshes in the layer\r\n * @param mesh mesh or array of meshes\r\n * @param material material to use by the layer when rendering the mesh(es). If undefined is passed, the specific material created by the layer will be used.\r\n */\r\n public setMaterialForRendering(mesh: AbstractMesh | AbstractMesh[], material?: Material): void {\r\n this._mainTexture.setMaterialForRendering(mesh, material);\r\n if (Array.isArray(mesh)) {\r\n for (let i = 0; i < mesh.length; ++i) {\r\n const currentMesh = mesh[i];\r\n if (!material) {\r\n delete this._materialForRendering[currentMesh.uniqueId];\r\n } else {\r\n this._materialForRendering[currentMesh.uniqueId] = [currentMesh, material];\r\n }\r\n }\r\n } else {\r\n if (!material) {\r\n delete this._materialForRendering[mesh.uniqueId];\r\n } else {\r\n this._materialForRendering[mesh.uniqueId] = [mesh, material];\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the intensity of the effect for a specific mesh.\r\n * @param mesh The mesh to get the effect intensity for\r\n * @returns The intensity of the effect for the mesh\r\n */\r\n public getEffectIntensity(mesh: AbstractMesh) {\r\n return this._effectIntensity[mesh.uniqueId] ?? 1;\r\n }\r\n\r\n /**\r\n * Sets the intensity of the effect for a specific mesh.\r\n * @param mesh The mesh to set the effect intensity for\r\n * @param intensity The intensity of the effect for the mesh\r\n */\r\n public setEffectIntensity(mesh: AbstractMesh, intensity: number): void {\r\n this._effectIntensity[mesh.uniqueId] = intensity;\r\n }\r\n\r\n /**\r\n * Instantiates a new effect Layer and references it in the scene.\r\n * @param name The name of the layer\r\n * @param scene The scene to use the layer in\r\n */\r\n constructor(\r\n /** The Friendly of the effect in the scene */\r\n name: string,\r\n scene?: Scene\r\n ) {\r\n this.name = name;\r\n\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n EffectLayer._SceneComponentInitialization(this._scene);\r\n\r\n this._engine = this._scene.getEngine();\r\n this._maxSize = this._engine.getCaps().maxTextureSize;\r\n this._scene.effectLayers.push(this);\r\n\r\n this._mergeDrawWrapper = [];\r\n\r\n // Generate Buffers\r\n this._generateIndexBuffer();\r\n this._generateVertexBuffer();\r\n }\r\n\r\n /**\r\n * Get the effect name of the layer.\r\n * @returns The effect name\r\n */\r\n public abstract getEffectName(): string;\r\n\r\n /**\r\n * Checks for the readiness of the element composing the layer.\r\n * @param subMesh the mesh to check for\r\n * @param useInstances specify whether or not to use instances to render the mesh\r\n * @returns true if ready otherwise, false\r\n */\r\n public abstract isReady(subMesh: SubMesh, useInstances: boolean): boolean;\r\n\r\n /**\r\n * Returns whether or not the layer needs stencil enabled during the mesh rendering.\r\n * @returns true if the effect requires stencil during the main canvas render pass.\r\n */\r\n public abstract needStencil(): boolean;\r\n\r\n /**\r\n * Create the merge effect. This is the shader use to blit the information back\r\n * to the main canvas at the end of the scene rendering.\r\n * @returns The effect containing the shader used to merge the effect on the main canvas\r\n */\r\n protected abstract _createMergeEffect(): Effect;\r\n\r\n /**\r\n * Creates the render target textures and post processes used in the effect layer.\r\n */\r\n protected abstract _createTextureAndPostProcesses(): void;\r\n\r\n /**\r\n * Implementation specific of rendering the generating effect on the main canvas.\r\n * @param effect The effect used to render through\r\n * @param renderNum Index of the _internalRender call (0 for the first time _internalRender is called, 1 for the second time, etc. _internalRender is called the number of times returned by _numInternalDraws())\r\n */\r\n protected abstract _internalRender(effect: Effect, renderIndex: number): void;\r\n\r\n /**\r\n * Sets the required values for both the emissive texture and and the main color.\r\n */\r\n protected abstract _setEmissiveTextureAndColor(mesh: Mesh, subMesh: SubMesh, material: Material): void;\r\n\r\n /**\r\n * Free any resources and references associated to a mesh.\r\n * Internal use\r\n * @param mesh The mesh to free.\r\n */\r\n public abstract _disposeMesh(mesh: Mesh): void;\r\n\r\n /**\r\n * Serializes this layer (Glow or Highlight for example)\r\n * @returns a serialized layer object\r\n */\r\n public abstract serialize?(): any;\r\n\r\n /**\r\n * Number of times _internalRender will be called. Some effect layers need to render the mesh several times, so they should override this method with the number of times the mesh should be rendered\r\n * @returns Number of times a mesh must be rendered in the layer\r\n */\r\n protected _numInternalDraws(): number {\r\n return 1;\r\n }\r\n\r\n /**\r\n * Initializes the effect layer with the required options.\r\n * @param options Sets of none mandatory options to use with the layer (see IEffectLayerOptions for more information)\r\n */\r\n protected _init(options: Partial): void {\r\n // Adapt options\r\n this._effectLayerOptions = {\r\n mainTextureRatio: 0.5,\r\n alphaBlendingMode: Constants.ALPHA_COMBINE,\r\n camera: null,\r\n renderingGroupId: -1,\r\n mainTextureType: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n generateStencilBuffer: false,\r\n ...options,\r\n };\r\n\r\n this._setMainTextureSize();\r\n this._createMainTexture();\r\n this._createTextureAndPostProcesses();\r\n }\r\n\r\n /**\r\n * Generates the index buffer of the full screen quad blending to the main canvas.\r\n */\r\n private _generateIndexBuffer(): void {\r\n // Indices\r\n const indices = [];\r\n indices.push(0);\r\n indices.push(1);\r\n indices.push(2);\r\n\r\n indices.push(0);\r\n indices.push(2);\r\n indices.push(3);\r\n\r\n this._indexBuffer = this._engine.createIndexBuffer(indices);\r\n }\r\n\r\n /**\r\n * Generates the vertex buffer of the full screen quad blending to the main canvas.\r\n */\r\n private _generateVertexBuffer(): void {\r\n // VBO\r\n const vertices = [];\r\n vertices.push(1, 1);\r\n vertices.push(-1, 1);\r\n vertices.push(-1, -1);\r\n vertices.push(1, -1);\r\n\r\n const vertexBuffer = new VertexBuffer(this._engine, vertices, VertexBuffer.PositionKind, false, false, 2);\r\n this._vertexBuffers[VertexBuffer.PositionKind] = vertexBuffer;\r\n }\r\n\r\n /**\r\n * Sets the main texture desired size which is the closest power of two\r\n * of the engine canvas size.\r\n */\r\n private _setMainTextureSize(): void {\r\n if (this._effectLayerOptions.mainTextureFixedSize) {\r\n this._mainTextureDesiredSize.width = this._effectLayerOptions.mainTextureFixedSize;\r\n this._mainTextureDesiredSize.height = this._effectLayerOptions.mainTextureFixedSize;\r\n } else {\r\n this._mainTextureDesiredSize.width = this._engine.getRenderWidth() * this._effectLayerOptions.mainTextureRatio;\r\n this._mainTextureDesiredSize.height = this._engine.getRenderHeight() * this._effectLayerOptions.mainTextureRatio;\r\n\r\n this._mainTextureDesiredSize.width = this._engine.needPOTTextures\r\n ? Engine.GetExponentOfTwo(this._mainTextureDesiredSize.width, this._maxSize)\r\n : this._mainTextureDesiredSize.width;\r\n this._mainTextureDesiredSize.height = this._engine.needPOTTextures\r\n ? Engine.GetExponentOfTwo(this._mainTextureDesiredSize.height, this._maxSize)\r\n : this._mainTextureDesiredSize.height;\r\n }\r\n\r\n this._mainTextureDesiredSize.width = Math.floor(this._mainTextureDesiredSize.width);\r\n this._mainTextureDesiredSize.height = Math.floor(this._mainTextureDesiredSize.height);\r\n }\r\n\r\n /**\r\n * Creates the main texture for the effect layer.\r\n */\r\n protected _createMainTexture(): void {\r\n this._mainTexture = new RenderTargetTexture(\r\n \"EffectLayerMainRTT\",\r\n {\r\n width: this._mainTextureDesiredSize.width,\r\n height: this._mainTextureDesiredSize.height,\r\n },\r\n this._scene,\r\n false,\r\n true,\r\n this._effectLayerOptions.mainTextureType,\r\n false,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n true,\r\n this._effectLayerOptions.generateStencilBuffer\r\n );\r\n this._mainTexture.activeCamera = this._effectLayerOptions.camera;\r\n this._mainTexture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this._mainTexture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n this._mainTexture.anisotropicFilteringLevel = 1;\r\n this._mainTexture.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\r\n this._mainTexture.renderParticles = false;\r\n this._mainTexture.renderList = null;\r\n this._mainTexture.ignoreCameraViewport = true;\r\n\r\n for (const id in this._materialForRendering) {\r\n const [mesh, material] = this._materialForRendering[id];\r\n this._mainTexture.setMaterialForRendering(mesh, material);\r\n }\r\n\r\n this._mainTexture.customIsReadyFunction = (mesh: AbstractMesh, refreshRate: number, preWarm?: boolean) => {\r\n if ((preWarm || refreshRate === 0) && mesh.subMeshes) {\r\n for (let i = 0; i < mesh.subMeshes.length; ++i) {\r\n const subMesh = mesh.subMeshes[i];\r\n const material = subMesh.getMaterial();\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n\r\n if (!material) {\r\n continue;\r\n }\r\n\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\r\n const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] || renderingMesh.hasThinInstances;\r\n\r\n this._setEmissiveTextureAndColor(renderingMesh, subMesh, material);\r\n\r\n if (!this._isReady(subMesh, hardwareInstancedRendering, this._emissiveTextureAndColor.texture)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n };\r\n\r\n // Custom render function\r\n this._mainTexture.customRenderFunction = (\r\n opaqueSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray\r\n ): void => {\r\n this.onBeforeRenderMainTextureObservable.notifyObservers(this);\r\n\r\n let index: number;\r\n\r\n const engine = this._scene.getEngine();\r\n\r\n if (depthOnlySubMeshes.length) {\r\n engine.setColorWrite(false);\r\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\r\n this._renderSubMesh(depthOnlySubMeshes.data[index]);\r\n }\r\n engine.setColorWrite(true);\r\n }\r\n\r\n for (index = 0; index < opaqueSubMeshes.length; index++) {\r\n this._renderSubMesh(opaqueSubMeshes.data[index]);\r\n }\r\n\r\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\r\n this._renderSubMesh(alphaTestSubMeshes.data[index]);\r\n }\r\n\r\n const previousAlphaMode = engine.getAlphaMode();\r\n\r\n for (index = 0; index < transparentSubMeshes.length; index++) {\r\n this._renderSubMesh(transparentSubMeshes.data[index], true);\r\n }\r\n\r\n engine.setAlphaMode(previousAlphaMode);\r\n };\r\n\r\n this._mainTexture.onClearObservable.add((engine: Engine) => {\r\n engine.clear(this.neutralColor, true, true, true);\r\n });\r\n\r\n // Prevent package size in es6 (getBoundingBoxRenderer might not be present)\r\n if (this._scene.getBoundingBoxRenderer) {\r\n const boundingBoxRendererEnabled = this._scene.getBoundingBoxRenderer().enabled;\r\n\r\n this._mainTexture.onBeforeBindObservable.add(() => {\r\n this._scene.getBoundingBoxRenderer().enabled = !this.disableBoundingBoxesFromEffectLayer && boundingBoxRendererEnabled;\r\n });\r\n\r\n this._mainTexture.onAfterUnbindObservable.add(() => {\r\n this._scene.getBoundingBoxRenderer().enabled = boundingBoxRendererEnabled;\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Adds specific effects defines.\r\n * @param defines The defines to add specifics to.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _addCustomEffectDefines(defines: string[]): void {\r\n // Nothing to add by default.\r\n }\r\n\r\n /**\r\n * Checks for the readiness of the element composing the layer.\r\n * @param subMesh the mesh to check for\r\n * @param useInstances specify whether or not to use instances to render the mesh\r\n * @param emissiveTexture the associated emissive texture used to generate the glow\r\n * @returns true if ready otherwise, false\r\n */\r\n protected _isReady(subMesh: SubMesh, useInstances: boolean, emissiveTexture: Nullable): boolean {\r\n const engine = this._scene.getEngine();\r\n const mesh = subMesh.getMesh();\r\n\r\n const renderingMaterial = mesh._internalAbstractMeshDataInfo._materialForRenderPass?.[engine.currentRenderPassId];\r\n\r\n if (renderingMaterial) {\r\n return renderingMaterial.isReadyForSubMesh(mesh, subMesh, useInstances);\r\n }\r\n\r\n const material = subMesh.getMaterial();\r\n\r\n if (!material) {\r\n return false;\r\n }\r\n\r\n if (this._useMeshMaterial(subMesh.getRenderingMesh())) {\r\n return material.isReadyForSubMesh(subMesh.getMesh(), subMesh, useInstances);\r\n }\r\n\r\n const defines: string[] = [];\r\n\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n let uv1 = false;\r\n let uv2 = false;\r\n\r\n // Diffuse\r\n if (material) {\r\n const needAlphaTest = material.needAlphaTesting();\r\n\r\n const diffuseTexture = material.getAlphaTestTexture();\r\n const needAlphaBlendFromDiffuse =\r\n diffuseTexture && diffuseTexture.hasAlpha && ((material as any).useAlphaFromDiffuseTexture || (material as any)._useAlphaFromAlbedoTexture);\r\n\r\n if (diffuseTexture && (needAlphaTest || needAlphaBlendFromDiffuse)) {\r\n defines.push(\"#define DIFFUSE\");\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && diffuseTexture.coordinatesIndex === 1) {\r\n defines.push(\"#define DIFFUSEUV2\");\r\n uv2 = true;\r\n } else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n defines.push(\"#define DIFFUSEUV1\");\r\n uv1 = true;\r\n }\r\n\r\n if (needAlphaTest) {\r\n defines.push(\"#define ALPHATEST\");\r\n defines.push(\"#define ALPHATESTVALUE 0.4\");\r\n }\r\n if (!diffuseTexture.gammaSpace) {\r\n defines.push(\"#define DIFFUSE_ISLINEAR\");\r\n }\r\n }\r\n\r\n const opacityTexture = (material as any).opacityTexture;\r\n if (opacityTexture) {\r\n defines.push(\"#define OPACITY\");\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && opacityTexture.coordinatesIndex === 1) {\r\n defines.push(\"#define OPACITYUV2\");\r\n uv2 = true;\r\n } else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n defines.push(\"#define OPACITYUV1\");\r\n uv1 = true;\r\n }\r\n }\r\n }\r\n\r\n // Emissive\r\n if (emissiveTexture) {\r\n defines.push(\"#define EMISSIVE\");\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && emissiveTexture.coordinatesIndex === 1) {\r\n defines.push(\"#define EMISSIVEUV2\");\r\n uv2 = true;\r\n } else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n defines.push(\"#define EMISSIVEUV1\");\r\n uv1 = true;\r\n }\r\n if (!emissiveTexture.gammaSpace) {\r\n defines.push(\"#define EMISSIVE_ISLINEAR\");\r\n }\r\n }\r\n\r\n // Vertex\r\n if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind) && mesh.hasVertexAlpha && material.transparencyMode !== Material.MATERIAL_OPAQUE) {\r\n attribs.push(VertexBuffer.ColorKind);\r\n defines.push(\"#define VERTEXALPHA\");\r\n }\r\n\r\n if (uv1) {\r\n attribs.push(VertexBuffer.UVKind);\r\n defines.push(\"#define UV1\");\r\n }\r\n if (uv2) {\r\n attribs.push(VertexBuffer.UV2Kind);\r\n defines.push(\"#define UV2\");\r\n }\r\n\r\n // Bones\r\n const fallbacks = new EffectFallbacks();\r\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n\r\n const skeleton = mesh.skeleton;\r\n if (skeleton && skeleton.isUsingTextureForMatrices) {\r\n defines.push(\"#define BONETEXTURE\");\r\n } else {\r\n defines.push(\"#define BonesPerMesh \" + (skeleton ? skeleton.bones.length + 1 : 0));\r\n }\r\n\r\n if (mesh.numBoneInfluencers > 0) {\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n }\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph targets\r\n const manager = (mesh).morphTargetManager;\r\n let morphInfluencers = 0;\r\n if (manager) {\r\n if (manager.numInfluencers > 0) {\r\n defines.push(\"#define MORPHTARGETS\");\r\n morphInfluencers = manager.numInfluencers;\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + morphInfluencers);\r\n if (manager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n }\r\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, morphInfluencers);\r\n }\r\n }\r\n\r\n // Instances\r\n if (useInstances) {\r\n defines.push(\"#define INSTANCES\");\r\n MaterialHelper.PushAttributesForInstances(attribs);\r\n if (subMesh.getRenderingMesh().hasThinInstances) {\r\n defines.push(\"#define THIN_INSTANCES\");\r\n }\r\n }\r\n\r\n // ClipPlanes\r\n prepareStringDefinesForClipPlanes(material, this._scene, defines);\r\n\r\n this._addCustomEffectDefines(defines);\r\n\r\n // Get correct effect\r\n const drawWrapper = subMesh._getDrawWrapper(undefined, true)!;\r\n const cachedDefines = drawWrapper.defines as string;\r\n const join = defines.join(\"\\n\");\r\n if (cachedDefines !== join) {\r\n const uniforms = [\r\n \"world\",\r\n \"mBones\",\r\n \"viewProjection\",\r\n \"glowColor\",\r\n \"morphTargetInfluences\",\r\n \"boneTextureWidth\",\r\n \"diffuseMatrix\",\r\n \"emissiveMatrix\",\r\n \"opacityMatrix\",\r\n \"opacityIntensity\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n \"glowIntensity\",\r\n ];\r\n\r\n addClipPlaneUniforms(uniforms);\r\n\r\n drawWrapper.setEffect(\r\n this._engine.createEffect(\r\n \"glowMapGeneration\",\r\n attribs,\r\n uniforms,\r\n [\"diffuseSampler\", \"emissiveSampler\", \"opacitySampler\", \"boneSampler\", \"morphTargets\"],\r\n join,\r\n fallbacks,\r\n undefined,\r\n undefined,\r\n { maxSimultaneousMorphTargets: morphInfluencers }\r\n ),\r\n join\r\n );\r\n }\r\n\r\n return drawWrapper.effect!.isReady();\r\n }\r\n\r\n /**\r\n * Renders the glowing part of the scene by blending the blurred glowing meshes on top of the rendered scene.\r\n */\r\n public render(): void {\r\n for (let i = 0; i < this._postProcesses.length; i++) {\r\n if (!this._postProcesses[i].isReady()) {\r\n return;\r\n }\r\n }\r\n\r\n const engine = this._scene.getEngine();\r\n const numDraws = this._numInternalDraws();\r\n\r\n // Check\r\n let isReady = true;\r\n for (let i = 0; i < numDraws; ++i) {\r\n let currentEffect = this._mergeDrawWrapper[i];\r\n if (!currentEffect) {\r\n currentEffect = this._mergeDrawWrapper[i] = new DrawWrapper(this._engine);\r\n currentEffect.setEffect(this._createMergeEffect());\r\n }\r\n isReady = isReady && currentEffect.effect!.isReady();\r\n }\r\n\r\n if (!isReady) {\r\n return;\r\n }\r\n\r\n this.onBeforeComposeObservable.notifyObservers(this);\r\n\r\n const previousAlphaMode = engine.getAlphaMode();\r\n\r\n for (let i = 0; i < numDraws; ++i) {\r\n const currentEffect = this._mergeDrawWrapper[i];\r\n\r\n // Render\r\n engine.enableEffect(currentEffect);\r\n engine.setState(false);\r\n\r\n // VBOs\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, currentEffect.effect!);\r\n\r\n // Go Blend.\r\n engine.setAlphaMode(this._effectLayerOptions.alphaBlendingMode);\r\n\r\n // Blends the map on the main canvas.\r\n this._internalRender(currentEffect.effect!, i);\r\n }\r\n\r\n // Restore Alpha\r\n engine.setAlphaMode(previousAlphaMode);\r\n\r\n this.onAfterComposeObservable.notifyObservers(this);\r\n\r\n // Handle size changes.\r\n const size = this._mainTexture.getSize();\r\n this._setMainTextureSize();\r\n if (\r\n (size.width !== this._mainTextureDesiredSize.width || size.height !== this._mainTextureDesiredSize.height) &&\r\n this._mainTextureDesiredSize.width !== 0 &&\r\n this._mainTextureDesiredSize.height !== 0\r\n ) {\r\n // Recreate RTT and post processes on size change.\r\n this.onSizeChangedObservable.notifyObservers(this);\r\n this._disposeTextureAndPostProcesses();\r\n this._createMainTexture();\r\n this._createTextureAndPostProcesses();\r\n }\r\n }\r\n\r\n /**\r\n * Determine if a given mesh will be used in the current effect.\r\n * @param mesh mesh to test\r\n * @returns true if the mesh will be used\r\n */\r\n public hasMesh(mesh: AbstractMesh): boolean {\r\n if (this.renderingGroupId === -1 || mesh.renderingGroupId === this.renderingGroupId) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Returns true if the layer contains information to display, otherwise false.\r\n * @returns true if the glow layer should be rendered\r\n */\r\n public shouldRender(): boolean {\r\n return this.isEnabled && this._shouldRender;\r\n }\r\n\r\n /**\r\n * Returns true if the mesh should render, otherwise false.\r\n * @param mesh The mesh to render\r\n * @returns true if it should render otherwise false\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _shouldRenderMesh(mesh: AbstractMesh): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns true if the mesh can be rendered, otherwise false.\r\n * @param mesh The mesh to render\r\n * @param material The material used on the mesh\r\n * @returns true if it can be rendered otherwise false\r\n */\r\n protected _canRenderMesh(mesh: AbstractMesh, material: Material): boolean {\r\n return !material.needAlphaBlendingForMesh(mesh);\r\n }\r\n\r\n /**\r\n * Returns true if the mesh should render, otherwise false.\r\n * @returns true if it should render otherwise false\r\n */\r\n protected _shouldRenderEmissiveTextureForMesh(): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Renders the submesh passed in parameter to the generation map.\r\n * @param subMesh\r\n * @param enableAlphaMode\r\n */\r\n protected _renderSubMesh(subMesh: SubMesh, enableAlphaMode: boolean = false): void {\r\n if (!this.shouldRender()) {\r\n return;\r\n }\r\n\r\n const material = subMesh.getMaterial();\r\n const ownerMesh = subMesh.getMesh();\r\n const replacementMesh = subMesh.getReplacementMesh();\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n const effectiveMesh = subMesh.getEffectiveMesh();\r\n const scene = this._scene;\r\n const engine = scene.getEngine();\r\n\r\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n\r\n if (!material) {\r\n return;\r\n }\r\n\r\n // Do not block in blend mode.\r\n if (!this._canRenderMesh(renderingMesh, material)) {\r\n return;\r\n }\r\n\r\n // Culling\r\n let sideOrientation = renderingMesh.overrideMaterialSideOrientation ?? material.sideOrientation;\r\n const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();\r\n if (mainDeterminant < 0) {\r\n sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;\r\n }\r\n\r\n const reverse = sideOrientation === Material.ClockWiseSideOrientation;\r\n engine.setState(material.backFaceCulling, material.zOffset, undefined, reverse, material.cullBackFaces, undefined, material.zOffsetUnits);\r\n\r\n // Managing instances\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!replacementMesh);\r\n if (batch.mustReturn) {\r\n return;\r\n }\r\n\r\n // Early Exit per mesh\r\n if (!this._shouldRenderMesh(renderingMesh)) {\r\n return;\r\n }\r\n\r\n const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] || renderingMesh.hasThinInstances;\r\n\r\n this._setEmissiveTextureAndColor(renderingMesh, subMesh, material);\r\n\r\n this.onBeforeRenderMeshToEffect.notifyObservers(ownerMesh);\r\n\r\n if (this._useMeshMaterial(renderingMesh)) {\r\n renderingMesh.render(subMesh, enableAlphaMode, replacementMesh || undefined);\r\n } else if (this._isReady(subMesh, hardwareInstancedRendering, this._emissiveTextureAndColor.texture)) {\r\n const renderingMaterial = effectiveMesh._internalAbstractMeshDataInfo._materialForRenderPass?.[engine.currentRenderPassId];\r\n\r\n let drawWrapper = subMesh._getDrawWrapper();\r\n if (!drawWrapper && renderingMaterial) {\r\n drawWrapper = renderingMaterial._getDrawWrapper();\r\n }\r\n\r\n if (!drawWrapper) {\r\n return;\r\n }\r\n\r\n const effect = drawWrapper.effect!;\r\n\r\n engine.enableEffect(drawWrapper);\r\n if (!hardwareInstancedRendering) {\r\n renderingMesh._bind(subMesh, effect, material.fillMode);\r\n }\r\n\r\n if (!renderingMaterial) {\r\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n effect.setMatrix(\"world\", effectiveMesh.getWorldMatrix());\r\n effect.setFloat4(\r\n \"glowColor\",\r\n this._emissiveTextureAndColor.color.r,\r\n this._emissiveTextureAndColor.color.g,\r\n this._emissiveTextureAndColor.color.b,\r\n this._emissiveTextureAndColor.color.a\r\n );\r\n } else {\r\n renderingMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), effectiveMesh as Mesh, subMesh);\r\n }\r\n\r\n if (!renderingMaterial) {\r\n const needAlphaTest = material.needAlphaTesting();\r\n\r\n const diffuseTexture = material.getAlphaTestTexture();\r\n const needAlphaBlendFromDiffuse =\r\n diffuseTexture && diffuseTexture.hasAlpha && ((material as any).useAlphaFromDiffuseTexture || (material as any)._useAlphaFromAlbedoTexture);\r\n\r\n if (diffuseTexture && (needAlphaTest || needAlphaBlendFromDiffuse)) {\r\n effect.setTexture(\"diffuseSampler\", diffuseTexture);\r\n const textureMatrix = diffuseTexture.getTextureMatrix();\r\n\r\n if (textureMatrix) {\r\n effect.setMatrix(\"diffuseMatrix\", textureMatrix);\r\n }\r\n }\r\n\r\n const opacityTexture = (material as any).opacityTexture;\r\n if (opacityTexture) {\r\n effect.setTexture(\"opacitySampler\", opacityTexture);\r\n effect.setFloat(\"opacityIntensity\", opacityTexture.level);\r\n const textureMatrix = opacityTexture.getTextureMatrix();\r\n if (textureMatrix) {\r\n effect.setMatrix(\"opacityMatrix\", textureMatrix);\r\n }\r\n }\r\n\r\n // Glow emissive only\r\n if (this._emissiveTextureAndColor.texture) {\r\n effect.setTexture(\"emissiveSampler\", this._emissiveTextureAndColor.texture);\r\n effect.setMatrix(\"emissiveMatrix\", this._emissiveTextureAndColor.texture.getTextureMatrix());\r\n }\r\n\r\n // Bones\r\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\r\n const skeleton = renderingMesh.skeleton;\r\n\r\n if (skeleton.isUsingTextureForMatrices) {\r\n const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);\r\n if (!boneTexture) {\r\n return;\r\n }\r\n\r\n effect.setTexture(\"boneSampler\", boneTexture);\r\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\r\n } else {\r\n effect.setMatrices(\"mBones\", skeleton.getTransformMatrices(renderingMesh));\r\n }\r\n }\r\n\r\n // Morph targets\r\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\r\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\r\n renderingMesh.morphTargetManager._bind(effect);\r\n }\r\n\r\n // Alpha mode\r\n if (enableAlphaMode) {\r\n engine.setAlphaMode(material.alphaMode);\r\n }\r\n\r\n // Intensity of effect\r\n effect.setFloat(\"glowIntensity\", this.getEffectIntensity(renderingMesh));\r\n\r\n // Clip planes\r\n bindClipPlane(effect, material, scene);\r\n }\r\n\r\n // Draw\r\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) =>\r\n effect.setMatrix(\"world\", world)\r\n );\r\n } else {\r\n // Need to reset refresh rate of the main map\r\n this._mainTexture.resetRefreshCounter();\r\n }\r\n\r\n this.onAfterRenderMeshToEffect.notifyObservers(ownerMesh);\r\n }\r\n\r\n /**\r\n * Defines whether the current material of the mesh should be use to render the effect.\r\n * @param mesh defines the current mesh to render\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _useMeshMaterial(mesh: AbstractMesh): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Rebuild the required buffers.\r\n * @internal Internal use only.\r\n */\r\n public _rebuild(): void {\r\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\r\n\r\n if (vb) {\r\n vb._rebuild();\r\n }\r\n\r\n this._generateIndexBuffer();\r\n }\r\n\r\n /**\r\n * Dispose only the render target textures and post process.\r\n */\r\n private _disposeTextureAndPostProcesses(): void {\r\n this._mainTexture.dispose();\r\n\r\n for (let i = 0; i < this._postProcesses.length; i++) {\r\n if (this._postProcesses[i]) {\r\n this._postProcesses[i].dispose();\r\n }\r\n }\r\n this._postProcesses = [];\r\n\r\n for (let i = 0; i < this._textures.length; i++) {\r\n if (this._textures[i]) {\r\n this._textures[i].dispose();\r\n }\r\n }\r\n this._textures = [];\r\n }\r\n\r\n /**\r\n * Dispose the highlight layer and free resources.\r\n */\r\n public dispose(): void {\r\n const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vertexBuffer) {\r\n vertexBuffer.dispose();\r\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this._scene.getEngine()._releaseBuffer(this._indexBuffer);\r\n this._indexBuffer = null;\r\n }\r\n\r\n for (const drawWrapper of this._mergeDrawWrapper) {\r\n drawWrapper.dispose();\r\n }\r\n this._mergeDrawWrapper = [];\r\n\r\n // Clean textures and post processes\r\n this._disposeTextureAndPostProcesses();\r\n\r\n // Remove from scene\r\n const index = this._scene.effectLayers.indexOf(this, 0);\r\n if (index > -1) {\r\n this._scene.effectLayers.splice(index, 1);\r\n }\r\n\r\n // Callback\r\n this.onDisposeObservable.notifyObservers(this);\r\n\r\n this.onDisposeObservable.clear();\r\n this.onBeforeRenderMainTextureObservable.clear();\r\n this.onBeforeComposeObservable.clear();\r\n this.onBeforeRenderMeshToEffect.clear();\r\n this.onAfterRenderMeshToEffect.clear();\r\n this.onAfterComposeObservable.clear();\r\n this.onSizeChangedObservable.clear();\r\n }\r\n\r\n /**\r\n * Gets the class name of the effect layer\r\n * @returns the string with the class name of the effect layer\r\n */\r\n public getClassName(): string {\r\n return \"EffectLayer\";\r\n }\r\n\r\n /**\r\n * Creates an effect layer from parsed effect layer data\r\n * @param parsedEffectLayer defines effect layer data\r\n * @param scene defines the current scene\r\n * @param rootUrl defines the root URL containing the effect layer information\r\n * @returns a parsed effect Layer\r\n */\r\n public static Parse(parsedEffectLayer: any, scene: Scene, rootUrl: string): EffectLayer {\r\n const effectLayerType = Tools.Instantiate(parsedEffectLayer.customType);\r\n\r\n return effectLayerType.Parse(parsedEffectLayer, scene, rootUrl);\r\n }\r\n}\r\n","import { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { ISceneSerializableComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { EffectLayer } from \"./effectLayer\";\r\nimport { AbstractScene } from \"../abstractScene\";\r\nimport type { AssetContainer } from \"../assetContainer\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n// Adds the parser to the scene parsers.\r\nAbstractScene.AddParser(SceneComponentConstants.NAME_EFFECTLAYER, (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => {\r\n if (parsedData.effectLayers) {\r\n if (!container.effectLayers) {\r\n container.effectLayers = new Array();\r\n }\r\n\r\n for (let index = 0; index < parsedData.effectLayers.length; index++) {\r\n const effectLayer = EffectLayer.Parse(parsedData.effectLayers[index], scene, rootUrl);\r\n container.effectLayers.push(effectLayer);\r\n }\r\n }\r\n});\r\n\r\ndeclare module \"../abstractScene\" {\r\n export interface AbstractScene {\r\n /**\r\n * The list of effect layers (highlights/glow) added to the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/highlightLayer\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/glowLayer\r\n */\r\n effectLayers: Array;\r\n\r\n /**\r\n * Removes the given effect layer from this scene.\r\n * @param toRemove defines the effect layer to remove\r\n * @returns the index of the removed effect layer\r\n */\r\n removeEffectLayer(toRemove: EffectLayer): number;\r\n\r\n /**\r\n * Adds the given effect layer to this scene\r\n * @param newEffectLayer defines the effect layer to add\r\n */\r\n addEffectLayer(newEffectLayer: EffectLayer): void;\r\n }\r\n}\r\n\r\nAbstractScene.prototype.removeEffectLayer = function (toRemove: EffectLayer): number {\r\n const index = this.effectLayers.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.effectLayers.splice(index, 1);\r\n }\r\n\r\n return index;\r\n};\r\n\r\nAbstractScene.prototype.addEffectLayer = function (newEffectLayer: EffectLayer): void {\r\n this.effectLayers.push(newEffectLayer);\r\n};\r\n\r\n/**\r\n * Defines the layer scene component responsible to manage any effect layers\r\n * in a given scene.\r\n */\r\nexport class EffectLayerSceneComponent implements ISceneSerializableComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_EFFECTLAYER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n private _engine: Engine;\r\n private _renderEffects = false;\r\n private _needStencil = false;\r\n private _previousStencilState = false;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene?: Scene) {\r\n this.scene = scene || EngineStore.LastCreatedScene;\r\n if (!this.scene) {\r\n return;\r\n }\r\n this._engine = this.scene.getEngine();\r\n this.scene.effectLayers = new Array();\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._isReadyForMeshStage.registerStep(SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER, this, this._isReadyForMesh);\r\n\r\n this.scene._cameraDrawRenderTargetStage.registerStep(SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER, this, this._renderMainTexture);\r\n\r\n this.scene._beforeCameraDrawStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER, this, this._setStencil);\r\n\r\n this.scene._afterRenderingGroupDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW, this, this._drawRenderingGroup);\r\n\r\n this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER, this, this._setStencilBack);\r\n this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW, this, this._drawCamera);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n const layers = this.scene.effectLayers;\r\n for (const effectLayer of layers) {\r\n effectLayer._rebuild();\r\n }\r\n }\r\n\r\n /**\r\n * Serializes the component data to the specified json object\r\n * @param serializationObject The object to serialize to\r\n */\r\n public serialize(serializationObject: any): void {\r\n // Effect layers\r\n serializationObject.effectLayers = [];\r\n\r\n const layers = this.scene.effectLayers;\r\n for (const effectLayer of layers) {\r\n if (effectLayer.serialize) {\r\n serializationObject.effectLayers.push(effectLayer.serialize());\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Adds all the elements from the container to the scene\r\n * @param container the container holding the elements\r\n */\r\n public addFromContainer(container: AbstractScene): void {\r\n if (!container.effectLayers) {\r\n return;\r\n }\r\n container.effectLayers.forEach((o) => {\r\n this.scene.addEffectLayer(o);\r\n });\r\n }\r\n\r\n /**\r\n * Removes all the elements in the container from the scene\r\n * @param container contains the elements to remove\r\n * @param dispose if the removed element should be disposed (default: false)\r\n */\r\n public removeFromContainer(container: AbstractScene, dispose?: boolean): void {\r\n if (!container.effectLayers) {\r\n return;\r\n }\r\n container.effectLayers.forEach((o) => {\r\n this.scene.removeEffectLayer(o);\r\n if (dispose) {\r\n o.dispose();\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources.\r\n */\r\n public dispose(): void {\r\n const layers = this.scene.effectLayers;\r\n while (layers.length) {\r\n layers[0].dispose();\r\n }\r\n }\r\n\r\n private _isReadyForMesh(mesh: AbstractMesh, hardwareInstancedRendering: boolean): boolean {\r\n const currentRenderPassId = this._engine.currentRenderPassId;\r\n const layers = this.scene.effectLayers;\r\n for (const layer of layers) {\r\n if (!layer.hasMesh(mesh)) {\r\n continue;\r\n }\r\n\r\n const renderTarget = (layer)._mainTexture;\r\n this._engine.currentRenderPassId = renderTarget.renderPassId;\r\n\r\n for (const subMesh of mesh.subMeshes) {\r\n if (!layer.isReady(subMesh, hardwareInstancedRendering)) {\r\n this._engine.currentRenderPassId = currentRenderPassId;\r\n return false;\r\n }\r\n }\r\n }\r\n this._engine.currentRenderPassId = currentRenderPassId;\r\n return true;\r\n }\r\n\r\n private _renderMainTexture(camera: Camera): boolean {\r\n this._renderEffects = false;\r\n this._needStencil = false;\r\n\r\n let needRebind = false;\r\n\r\n const layers = this.scene.effectLayers;\r\n if (layers && layers.length > 0) {\r\n this._previousStencilState = this._engine.getStencilBuffer();\r\n for (const effectLayer of layers) {\r\n if (\r\n effectLayer.shouldRender() &&\r\n (!effectLayer.camera ||\r\n (effectLayer.camera.cameraRigMode === Camera.RIG_MODE_NONE && camera === effectLayer.camera) ||\r\n (effectLayer.camera.cameraRigMode !== Camera.RIG_MODE_NONE && effectLayer.camera._rigCameras.indexOf(camera) > -1))\r\n ) {\r\n this._renderEffects = true;\r\n this._needStencil = this._needStencil || effectLayer.needStencil();\r\n\r\n const renderTarget = (effectLayer)._mainTexture;\r\n if (renderTarget._shouldRender()) {\r\n this.scene.incrementRenderId();\r\n renderTarget.render(false, false);\r\n needRebind = true;\r\n }\r\n }\r\n }\r\n\r\n this.scene.incrementRenderId();\r\n }\r\n\r\n return needRebind;\r\n }\r\n\r\n private _setStencil() {\r\n // Activate effect Layer stencil\r\n if (this._needStencil) {\r\n this._engine.setStencilBuffer(true);\r\n }\r\n }\r\n\r\n private _setStencilBack() {\r\n // Restore effect Layer stencil\r\n if (this._needStencil) {\r\n this._engine.setStencilBuffer(this._previousStencilState);\r\n }\r\n }\r\n\r\n private _draw(renderingGroupId: number): void {\r\n if (this._renderEffects) {\r\n this._engine.setDepthBuffer(false);\r\n\r\n const layers = this.scene.effectLayers;\r\n for (let i = 0; i < layers.length; i++) {\r\n const effectLayer = layers[i];\r\n if (effectLayer.renderingGroupId === renderingGroupId) {\r\n if (effectLayer.shouldRender()) {\r\n effectLayer.render();\r\n }\r\n }\r\n }\r\n this._engine.setDepthBuffer(true);\r\n }\r\n }\r\n\r\n private _drawCamera(): void {\r\n if (this._renderEffects) {\r\n this._draw(-1);\r\n }\r\n }\r\n private _drawRenderingGroup(index: number): void {\r\n if (!this.scene._isInIntermediateRendering() && this._renderEffects) {\r\n this._draw(index);\r\n }\r\n }\r\n}\r\n\r\nEffectLayer._SceneComponentInitialization = (scene: Scene) => {\r\n let component = scene._getComponent(SceneComponentConstants.NAME_EFFECTLAYER) as EffectLayerSceneComponent;\r\n if (!component) {\r\n component = new EffectLayerSceneComponent(scene);\r\n scene._addComponent(component);\r\n }\r\n};\r\n","import { serialize, serializeAsVector3 } from \"../Misc/decorators\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\n/**\r\n * Interface describing all the common properties and methods a shadow light needs to implement.\r\n * This helps both the shadow generator and materials to generate the corresponding shadow maps\r\n * as well as binding the different shadow properties to the effects.\r\n */\r\nexport interface IShadowLight extends Light {\r\n /**\r\n * The light id in the scene (used in scene.getLightById for instance)\r\n */\r\n id: string;\r\n /**\r\n * The position the shadow will be casted from.\r\n */\r\n position: Vector3;\r\n /**\r\n * In 2d mode (needCube being false), the direction used to cast the shadow.\r\n */\r\n direction: Vector3;\r\n /**\r\n * The transformed position. Position of the light in world space taking parenting in account.\r\n */\r\n transformedPosition: Vector3;\r\n /**\r\n * The transformed direction. Direction of the light in world space taking parenting in account.\r\n */\r\n transformedDirection: Vector3;\r\n /**\r\n * The friendly name of the light in the scene.\r\n */\r\n name: string;\r\n /**\r\n * Defines the shadow projection clipping minimum z value.\r\n */\r\n shadowMinZ: number;\r\n /**\r\n * Defines the shadow projection clipping maximum z value.\r\n */\r\n shadowMaxZ: number;\r\n\r\n /**\r\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\r\n * @returns true if the information has been computed, false if it does not need to (no parenting)\r\n */\r\n computeTransformedInformation(): boolean;\r\n\r\n /**\r\n * Gets the scene the light belongs to.\r\n * @returns The scene\r\n */\r\n getScene(): Scene;\r\n\r\n /**\r\n * Callback defining a custom Projection Matrix Builder.\r\n * This can be used to override the default projection matrix computation.\r\n */\r\n customProjectionMatrixBuilder: (viewMatrix: Matrix, renderList: Array, result: Matrix) => void;\r\n\r\n /**\r\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\r\n * @param matrix The matrix to updated with the projection information\r\n * @param viewMatrix The transform matrix of the light\r\n * @param renderList The list of mesh to render in the map\r\n * @returns The current light\r\n */\r\n setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): IShadowLight;\r\n\r\n /**\r\n * Gets the current depth scale used in ESM.\r\n * @returns The scale\r\n */\r\n getDepthScale(): number;\r\n\r\n /**\r\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\r\n * @returns true if a cube texture needs to be use\r\n */\r\n needCube(): boolean;\r\n\r\n /**\r\n * Detects if the projection matrix requires to be recomputed this frame.\r\n * @returns true if it requires to be recomputed otherwise, false.\r\n */\r\n needProjectionMatrixCompute(): boolean;\r\n\r\n /**\r\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\r\n */\r\n forceProjectionMatrixCompute(): void;\r\n\r\n /**\r\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n getShadowDirection(faceIndex?: number): Vector3;\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n getDepthMinZ(activeCamera: Camera): number;\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n getDepthMaxZ(activeCamera: Camera): number;\r\n}\r\n\r\n/**\r\n * Base implementation IShadowLight\r\n * It groups all the common behaviour in order to reduce duplication and better follow the DRY pattern.\r\n */\r\nexport abstract class ShadowLight extends Light implements IShadowLight {\r\n protected abstract _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): void;\r\n\r\n protected _position: Vector3;\r\n protected _setPosition(value: Vector3) {\r\n this._position = value;\r\n }\r\n /**\r\n * Sets the position the shadow will be casted from. Also use as the light position for both\r\n * point and spot lights.\r\n */\r\n @serializeAsVector3()\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n /**\r\n * Sets the position the shadow will be casted from. Also use as the light position for both\r\n * point and spot lights.\r\n */\r\n public set position(value: Vector3) {\r\n this._setPosition(value);\r\n }\r\n\r\n protected _direction: Vector3;\r\n protected _setDirection(value: Vector3) {\r\n this._direction = value;\r\n }\r\n /**\r\n * In 2d mode (needCube being false), gets the direction used to cast the shadow.\r\n * Also use as the light direction on spot and directional lights.\r\n */\r\n @serializeAsVector3()\r\n public get direction(): Vector3 {\r\n return this._direction;\r\n }\r\n /**\r\n * In 2d mode (needCube being false), sets the direction used to cast the shadow.\r\n * Also use as the light direction on spot and directional lights.\r\n */\r\n public set direction(value: Vector3) {\r\n this._setDirection(value);\r\n }\r\n\r\n protected _shadowMinZ: number;\r\n /**\r\n * Gets the shadow projection clipping minimum z value.\r\n */\r\n @serialize()\r\n public get shadowMinZ(): number {\r\n return this._shadowMinZ;\r\n }\r\n /**\r\n * Sets the shadow projection clipping minimum z value.\r\n */\r\n public set shadowMinZ(value: number) {\r\n this._shadowMinZ = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n protected _shadowMaxZ: number;\r\n /**\r\n * Sets the shadow projection clipping maximum z value.\r\n */\r\n @serialize()\r\n public get shadowMaxZ(): number {\r\n return this._shadowMaxZ;\r\n }\r\n /**\r\n * Gets the shadow projection clipping maximum z value.\r\n */\r\n public set shadowMaxZ(value: number) {\r\n this._shadowMaxZ = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Callback defining a custom Projection Matrix Builder.\r\n * This can be used to override the default projection matrix computation.\r\n */\r\n public customProjectionMatrixBuilder: (viewMatrix: Matrix, renderList: Array, result: Matrix) => void;\r\n\r\n /**\r\n * The transformed position. Position of the light in world space taking parenting in account.\r\n */\r\n public transformedPosition: Vector3;\r\n\r\n /**\r\n * The transformed direction. Direction of the light in world space taking parenting in account.\r\n */\r\n public transformedDirection: Vector3;\r\n\r\n private _needProjectionMatrixCompute: boolean = true;\r\n\r\n /**\r\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\r\n * @returns true if the information has been computed, false if it does not need to (no parenting)\r\n */\r\n public computeTransformedInformation(): boolean {\r\n if (this.parent && this.parent.getWorldMatrix) {\r\n if (!this.transformedPosition) {\r\n this.transformedPosition = Vector3.Zero();\r\n }\r\n Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);\r\n\r\n // In case the direction is present.\r\n if (this.direction) {\r\n if (!this.transformedDirection) {\r\n this.transformedDirection = Vector3.Zero();\r\n }\r\n Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this.transformedDirection);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Return the depth scale used for the shadow map.\r\n * @returns the depth scale.\r\n */\r\n public getDepthScale(): number {\r\n return 50.0;\r\n }\r\n\r\n /**\r\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getShadowDirection(faceIndex?: number): Vector3 {\r\n return this.transformedDirection ? this.transformedDirection : this.direction;\r\n }\r\n\r\n /**\r\n * Returns the ShadowLight absolute position in the World.\r\n * @returns the position vector in world space\r\n */\r\n public getAbsolutePosition(): Vector3 {\r\n return this.transformedPosition ? this.transformedPosition : this.position;\r\n }\r\n\r\n /**\r\n * Sets the ShadowLight direction toward the passed target.\r\n * @param target The point to target in local space\r\n * @returns the updated ShadowLight direction\r\n */\r\n public setDirectionToTarget(target: Vector3): Vector3 {\r\n this.direction = Vector3.Normalize(target.subtract(this.position));\r\n return this.direction;\r\n }\r\n\r\n /**\r\n * Returns the light rotation in euler definition.\r\n * @returns the x y z rotation in local space.\r\n */\r\n public getRotation(): Vector3 {\r\n this.direction.normalize();\r\n const xaxis = Vector3.Cross(this.direction, Axis.Y);\r\n const yaxis = Vector3.Cross(xaxis, this.direction);\r\n return Vector3.RotationFromAxis(xaxis, yaxis, this.direction);\r\n }\r\n\r\n /**\r\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\r\n * @returns true if a cube texture needs to be use\r\n */\r\n public needCube(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Detects if the projection matrix requires to be recomputed this frame.\r\n * @returns true if it requires to be recomputed otherwise, false.\r\n */\r\n public needProjectionMatrixCompute(): boolean {\r\n return this._needProjectionMatrixCompute;\r\n }\r\n\r\n /**\r\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\r\n */\r\n public forceProjectionMatrixCompute(): void {\r\n this._needProjectionMatrixCompute = true;\r\n }\r\n\r\n /** @internal */\r\n public _initCache() {\r\n super._initCache();\r\n\r\n this._cache.position = Vector3.Zero();\r\n }\r\n\r\n /** @internal */\r\n public _isSynchronized(): boolean {\r\n if (!this._cache.position.equals(this.position)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Computes the world matrix of the node\r\n * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\r\n * @returns the world matrix\r\n */\r\n public computeWorldMatrix(force?: boolean): Matrix {\r\n if (!force && this.isSynchronized()) {\r\n this._currentRenderId = this.getScene().getRenderId();\r\n return this._worldMatrix;\r\n }\r\n\r\n this._updateCache();\r\n this._cache.position.copyFrom(this.position);\r\n\r\n if (!this._worldMatrix) {\r\n this._worldMatrix = Matrix.Identity();\r\n }\r\n\r\n Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);\r\n\r\n if (this.parent && this.parent.getWorldMatrix) {\r\n this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);\r\n\r\n this._markSyncedWithParent();\r\n }\r\n\r\n // Cache the determinant\r\n this._worldMatrixDeterminantIsDirty = true;\r\n\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n public getDepthMinZ(activeCamera: Camera): number {\r\n return this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n public getDepthMaxZ(activeCamera: Camera): number {\r\n return this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n }\r\n\r\n /**\r\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\r\n * @param matrix The matrix to updated with the projection information\r\n * @param viewMatrix The transform matrix of the light\r\n * @param renderList The list of mesh to render in the map\r\n * @returns The current light\r\n */\r\n public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): IShadowLight {\r\n if (this.customProjectionMatrixBuilder) {\r\n this.customProjectionMatrixBuilder(viewMatrix, renderList, matrix);\r\n } else {\r\n this._setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList);\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n protected _syncParentEnabledState() {\r\n super._syncParentEnabledState();\r\n if (!this.parent || !this.parent.getWorldMatrix) {\r\n (this.transformedPosition as any) = null;\r\n (this.transformedDirection as any) = null;\r\n }\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"bayerDitherFunctions\";\nconst shader = `float bayerDither2(vec2 _P) {return mod(2.0*_P.y+_P.x+1.0,4.0);}\nfloat bayerDither4(vec2 _P) {vec2 P1=mod(_P,2.0); \nvec2 P2=floor(0.5*mod(_P,4.0)); \nreturn 4.0*bayerDither2(P1)+bayerDither2(P2);}\nfloat bayerDither8(vec2 _P) {vec2 P1=mod(_P,2.0); \nvec2 P2=floor(0.5 *mod(_P,4.0)); \nvec2 P4=floor(0.25*mod(_P,8.0)); \nreturn 4.0*(4.0*bayerDither2(P1)+bayerDither2(P2))+bayerDither2(P4);}\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const bayerDitherFunctions = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./packingFunctions\";\nimport \"./bayerDitherFunctions\";\n\nconst name = \"shadowMapFragmentExtraDeclaration\";\nconst shader = `#if SM_FLOAT==0\n#include\n#endif\n#if SM_SOFTTRANSPARENTSHADOW==1\n#include\nuniform float softTransparentShadowSM;\n#endif\nvarying float vDepthMetricSM;\n#if SM_USEDISTANCE==1\nuniform vec3 lightDataSM;varying vec3 vPositionWSM;\n#endif\nuniform vec3 biasAndScaleSM;uniform vec2 depthValuesSM;\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\nvarying float zSM;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapFragmentExtraDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowMapFragment\";\nconst shader = `float depthSM=vDepthMetricSM;\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\n#if SM_USEDISTANCE==1\ndepthSM=(length(vPositionWSM-lightDataSM)+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#else\n#ifdef USE_REVERSE_DEPTHBUFFER\ndepthSM=(-zSM+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#else\ndepthSM=(zSM+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#endif\n#endif\n#ifdef USE_REVERSE_DEPTHBUFFER\ngl_FragDepth=clamp(1.0-depthSM,0.0,1.0);\n#else\ngl_FragDepth=clamp(depthSM,0.0,1.0); \n#endif\n#elif SM_USEDISTANCE==1\ndepthSM=(length(vPositionWSM-lightDataSM)+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#endif\n#if SM_ESM==1\ndepthSM=clamp(exp(-min(87.,biasAndScaleSM.z*depthSM)),0.,1.);\n#endif\n#if SM_FLOAT==1\ngl_FragColor=vec4(depthSM,1.0,1.0,1.0);\n#else\ngl_FragColor=pack(depthSM);\n#endif\nreturn;`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapFragment = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/shadowMapFragmentExtraDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/shadowMapFragment\";\n\nconst name = \"shadowMapPixelShader\";\nconst shader = `#include\n#ifdef ALPHATEXTURE\nvarying vec2 vUV;uniform sampler2D diffuseSampler;\n#endif\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#include\n#ifdef ALPHATEXTURE\nfloat alphaFromAlphaTexture=texture2D(diffuseSampler,vUV).a;\n#ifdef ALPHATESTVALUE\nif (alphaFromAlphaTexture=softTransparentShadowSM*alphaFromAlphaTexture) discard;\n#else\nif ((bayerDither8(floor(mod(gl_FragCoord.xy,8.0))))/64.0>=softTransparentShadowSM) discard;\n#endif\n#endif\n#include\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"sceneVertexDeclaration\";\nconst shader = `uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\nuniform mat4 view;uniform mat4 projection;uniform vec4 vEyePosition;\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const sceneVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"meshVertexDeclaration\";\nconst shader = `uniform mat4 world;uniform float visibility;\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const meshVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./sceneVertexDeclaration\";\nimport \"./meshVertexDeclaration\";\n\nconst name = \"shadowMapVertexDeclaration\";\nconst shader = `#include\n#include\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./sceneUboDeclaration\";\nimport \"./meshUboDeclaration\";\n\nconst name = \"shadowMapUboDeclaration\";\nconst shader = `layout(std140,column_major) uniform;\n#include\n#include\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowMapVertexExtraDeclaration\";\nconst shader = `#if SM_NORMALBIAS==1\nuniform vec3 lightDataSM;\n#endif\nuniform vec3 biasAndScaleSM;uniform vec2 depthValuesSM;varying float vDepthMetricSM;\n#if SM_USEDISTANCE==1\nvarying vec3 vPositionWSM;\n#endif\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\nvarying float zSM;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapVertexExtraDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowMapVertexNormalBias\";\nconst shader = `#if SM_NORMALBIAS==1\n#if SM_DIRECTIONINLIGHTDATA==1\nvec3 worldLightDirSM=normalize(-lightDataSM.xyz);\n#else\nvec3 directionToLightSM=lightDataSM.xyz-worldPos.xyz;vec3 worldLightDirSM=normalize(directionToLightSM);\n#endif\nfloat ndlSM=dot(vNormalW,worldLightDirSM);float sinNLSM=sqrt(1.0-ndlSM*ndlSM);float normalBiasSM=biasAndScaleSM.y*sinNLSM;worldPos.xyz-=vNormalW*normalBiasSM;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapVertexNormalBias = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowMapVertexMetric\";\nconst shader = `#if SM_USEDISTANCE==1\nvPositionWSM=worldPos.xyz;\n#endif\n#if SM_DEPTHTEXTURE==1\n#ifdef IS_NDC_HALF_ZRANGE\n#define BIASFACTOR 0.5\n#else\n#define BIASFACTOR 1.0\n#endif\n#ifdef USE_REVERSE_DEPTHBUFFER\ngl_Position.z-=biasAndScaleSM.x*gl_Position.w*BIASFACTOR;\n#else\ngl_Position.z+=biasAndScaleSM.x*gl_Position.w*BIASFACTOR;\n#endif\n#endif\n#if defined(SM_DEPTHCLAMP) && SM_DEPTHCLAMP==1\nzSM=gl_Position.z;gl_Position.z=0.0;\n#elif SM_USEDISTANCE==0\n#ifdef USE_REVERSE_DEPTHBUFFER\nvDepthMetricSM=(-gl_Position.z+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#else\nvDepthMetricSM=(gl_Position.z+depthValuesSM.x)/depthValuesSM.y+biasAndScaleSM.x;\n#endif\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapVertexMetric = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/shadowMapVertexDeclaration\";\nimport \"./ShadersInclude/shadowMapUboDeclaration\";\nimport \"./ShadersInclude/shadowMapVertexExtraDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobal\";\nimport \"./ShadersInclude/morphTargetsVertex\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/shadowMapVertexNormalBias\";\nimport \"./ShadersInclude/shadowMapVertexMetric\";\nimport \"./ShadersInclude/clipPlaneVertex\";\n\nconst name = \"shadowMapVertexShader\";\nconst shader = `attribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#ifdef INSTANCES\nattribute vec4 world0;attribute vec4 world1;attribute vec4 world2;attribute vec4 world3;\n#endif\n#include\n#include<__decl__shadowMapVertex>\n#ifdef ALPHATEXTURE\nvarying vec2 vUV;uniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#ifdef NORMAL\nmat3 normWorldSM=mat3(finalWorld);\n#if defined(INSTANCES) && defined(THIN_INSTANCES)\nvec3 vNormalW=normalUpdated/vec3(dot(normWorldSM[0],normWorldSM[0]),dot(normWorldSM[1],normWorldSM[1]),dot(normWorldSM[2],normWorldSM[2]));vNormalW=normalize(normWorldSM*vNormalW);\n#else\n#ifdef NONUNIFORMSCALING\nnormWorldSM=transposeMat3(inverseMat3(normWorldSM));\n#endif\nvec3 vNormalW=normalize(normWorldSM*normalUpdated);\n#endif\n#endif\n#include\ngl_Position=viewProjection*worldPos;\n#include\n#ifdef ALPHATEXTURE\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapVertexShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"depthBoxBlurPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform vec2 screenSize;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec4 colorDepth=vec4(0.0);for (int x=-OFFSET; x<=OFFSET; x++)\nfor (int y=-OFFSET; y<=OFFSET; y++)\ncolorDepth+=texture2D(textureSampler,vUV+vec2(x,y)/screenSize);gl_FragColor=(colorDepth/float((OFFSET*2+1)*(OFFSET*2+1)));}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const depthBoxBlurPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"shadowMapFragmentSoftTransparentShadow\";\nconst shader = `#if SM_SOFTTRANSPARENTSHADOW==1\nif ((bayerDither8(floor(mod(gl_FragCoord.xy,8.0))))/64.0>=softTransparentShadowSM*alpha) discard;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const shadowMapFragmentSoftTransparentShadow = { name, shader };\n","import type { SmartArray } from \"../../Misc/smartArray\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\n\r\nimport type { IShadowLight } from \"../../Lights/shadowLight\";\r\nimport { Light } from \"../../Lights/light\";\r\nimport type { MaterialDefines } from \"../../Materials/materialDefines\";\r\nimport { MaterialHelper } from \"../../Materials/materialHelper\";\r\nimport type { Effect, IEffectCreationOptions } from \"../../Materials/effect\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\n\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport { BlurPostProcess } from \"../../PostProcesses/blurPostProcess\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport { EffectFallbacks } from \"../../Materials/effectFallbacks\";\r\nimport { RenderingManager } from \"../../Rendering/renderingManager\";\r\nimport { DrawWrapper } from \"../../Materials/drawWrapper\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\n\r\nimport \"../../Shaders/shadowMap.fragment\";\r\nimport \"../../Shaders/shadowMap.vertex\";\r\nimport \"../../Shaders/depthBoxBlur.fragment\";\r\nimport \"../../Shaders/ShadersInclude/shadowMapFragmentSoftTransparentShadow\";\r\nimport { addClipPlaneUniforms, bindClipPlane, prepareStringDefinesForClipPlanes } from \"../../Materials/clipPlaneMaterialHelper\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a custom shader for a shadow generator.\r\n */\r\nexport interface ICustomShaderOptions {\r\n /**\r\n * Gets or sets the custom shader name to use\r\n */\r\n shaderName: string;\r\n\r\n /**\r\n * The list of attribute names used in the shader\r\n */\r\n attributes?: string[];\r\n\r\n /**\r\n * The list of uniform names used in the shader\r\n */\r\n uniforms?: string[];\r\n\r\n /**\r\n * The list of sampler names used in the shader\r\n */\r\n samplers?: string[];\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n}\r\n\r\n/**\r\n * Interface to implement to create a shadow generator compatible with BJS.\r\n */\r\nexport interface IShadowGenerator {\r\n /** Gets or set the id of the shadow generator. It will be the one from the light if not defined */\r\n id: string;\r\n /**\r\n * Gets the main RTT containing the shadow map (usually storing depth from the light point of view).\r\n * @returns The render target texture if present otherwise, null\r\n */\r\n getShadowMap(): Nullable;\r\n\r\n /**\r\n * Determine whether the shadow generator is ready or not (mainly all effects and related post processes needs to be ready).\r\n * @param subMesh The submesh we want to render in the shadow map\r\n * @param useInstances Defines whether will draw in the map using instances\r\n * @param isTransparent Indicates that isReady is called for a transparent subMesh\r\n * @returns true if ready otherwise, false\r\n */\r\n isReady(subMesh: SubMesh, useInstances: boolean, isTransparent: boolean): boolean;\r\n\r\n /**\r\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\r\n * @param defines Defines of the material we want to update\r\n * @param lightIndex Index of the light in the enabled light list of the material\r\n */\r\n prepareDefines(defines: MaterialDefines, lightIndex: number): void;\r\n /**\r\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\r\n * defined in the generator but impacting the effect).\r\n * It implies the uniforms available on the materials are the standard BJS ones.\r\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\r\n * @param effect The effect we are binding the information for\r\n */\r\n bindShadowLight(lightIndex: string, effect: Effect): void;\r\n /**\r\n * Gets the transformation matrix used to project the meshes into the map from the light point of view.\r\n * (eq to shadow projection matrix * light transform matrix)\r\n * @returns The transform matrix used to create the shadow map\r\n */\r\n getTransformMatrix(): Matrix;\r\n\r\n /**\r\n * Recreates the shadow map dependencies like RTT and post processes. This can be used during the switch between\r\n * Cube and 2D textures for instance.\r\n */\r\n recreateShadowMap(): void;\r\n\r\n /**\r\n * Forces all the attached effect to compile to enable rendering only once ready vs. lazily compiling effects.\r\n * @param onCompiled Callback triggered at the and of the effects compilation\r\n * @param options Sets of optional options forcing the compilation with different modes\r\n */\r\n forceCompilation(onCompiled?: (generator: IShadowGenerator) => void, options?: Partial<{ useInstances: boolean }>): void;\r\n\r\n /**\r\n * Forces all the attached effect to compile to enable rendering only once ready vs. lazily compiling effects.\r\n * @param options Sets of optional options forcing the compilation with different modes\r\n * @returns A promise that resolves when the compilation completes\r\n */\r\n forceCompilationAsync(options?: Partial<{ useInstances: boolean }>): Promise;\r\n\r\n /**\r\n * Serializes the shadow generator setup to a json object.\r\n * @returns The serialized JSON object\r\n */\r\n serialize(): any;\r\n\r\n /**\r\n * Disposes the Shadow map and related Textures and effects.\r\n */\r\n dispose(): void;\r\n}\r\n\r\n/**\r\n * Default implementation IShadowGenerator.\r\n * This is the main object responsible of generating shadows in the framework.\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\r\n */\r\nexport class ShadowGenerator implements IShadowGenerator {\r\n /**\r\n * Name of the shadow generator class\r\n */\r\n public static CLASSNAME = \"ShadowGenerator\";\r\n\r\n /**\r\n * Shadow generator mode None: no filtering applied.\r\n */\r\n public static readonly FILTER_NONE = 0;\r\n /**\r\n * Shadow generator mode ESM: Exponential Shadow Mapping.\r\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\r\n */\r\n public static readonly FILTER_EXPONENTIALSHADOWMAP = 1;\r\n /**\r\n * Shadow generator mode Poisson Sampling: Percentage Closer Filtering.\r\n * (Multiple Tap around evenly distributed around the pixel are used to evaluate the shadow strength)\r\n */\r\n public static readonly FILTER_POISSONSAMPLING = 2;\r\n /**\r\n * Shadow generator mode ESM: Blurred Exponential Shadow Mapping.\r\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\r\n */\r\n public static readonly FILTER_BLUREXPONENTIALSHADOWMAP = 3;\r\n /**\r\n * Shadow generator mode ESM: Exponential Shadow Mapping using the inverse of the exponential preventing\r\n * edge artifacts on steep falloff.\r\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\r\n */\r\n public static readonly FILTER_CLOSEEXPONENTIALSHADOWMAP = 4;\r\n /**\r\n * Shadow generator mode ESM: Blurred Exponential Shadow Mapping using the inverse of the exponential preventing\r\n * edge artifacts on steep falloff.\r\n * (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)\r\n */\r\n public static readonly FILTER_BLURCLOSEEXPONENTIALSHADOWMAP = 5;\r\n /**\r\n * Shadow generator mode PCF: Percentage Closer Filtering\r\n * benefits from Webgl 2 shadow samplers. Fallback to Poisson Sampling in Webgl 1\r\n * (https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch11.html)\r\n */\r\n public static readonly FILTER_PCF = 6;\r\n /**\r\n * Shadow generator mode PCSS: Percentage Closering Soft Shadow.\r\n * benefits from Webgl 2 shadow samplers. Fallback to Poisson Sampling in Webgl 1\r\n * Contact Hardening\r\n */\r\n public static readonly FILTER_PCSS = 7;\r\n\r\n /**\r\n * Reserved for PCF and PCSS\r\n * Highest Quality.\r\n *\r\n * Execute PCF on a 5*5 kernel improving a lot the shadow aliasing artifacts.\r\n *\r\n * Execute PCSS with 32 taps blocker search and 64 taps PCF.\r\n */\r\n public static readonly QUALITY_HIGH = 0;\r\n /**\r\n * Reserved for PCF and PCSS\r\n * Good tradeoff for quality/perf cross devices\r\n *\r\n * Execute PCF on a 3*3 kernel.\r\n *\r\n * Execute PCSS with 16 taps blocker search and 32 taps PCF.\r\n */\r\n public static readonly QUALITY_MEDIUM = 1;\r\n /**\r\n * Reserved for PCF and PCSS\r\n * The lowest quality but the fastest.\r\n *\r\n * Execute PCF on a 1*1 kernel.\r\n *\r\n * Execute PCSS with 16 taps blocker search and 16 taps PCF.\r\n */\r\n public static readonly QUALITY_LOW = 2;\r\n\r\n /**\r\n * Defines the default alpha cutoff value used for transparent alpha tested materials.\r\n */\r\n public static DEFAULT_ALPHA_CUTOFF = 0.5;\r\n\r\n /** Gets or set the id of the shadow generator. It will be the one from the light if not defined */\r\n public id: string;\r\n\r\n /** Gets or sets the custom shader name to use */\r\n public customShaderOptions: ICustomShaderOptions;\r\n\r\n /** Gets or sets a custom function to allow/disallow rendering a sub mesh in the shadow map */\r\n public customAllowRendering: (subMesh: SubMesh) => boolean;\r\n\r\n /**\r\n * Observable triggered before the shadow is rendered. Can be used to update internal effect state\r\n */\r\n public onBeforeShadowMapRenderObservable = new Observable();\r\n\r\n /**\r\n * Observable triggered after the shadow is rendered. Can be used to restore internal effect state\r\n */\r\n public onAfterShadowMapRenderObservable = new Observable();\r\n\r\n /**\r\n * Observable triggered before a mesh is rendered in the shadow map.\r\n * Can be used to update internal effect state (that you can get from the onBeforeShadowMapRenderObservable)\r\n */\r\n public onBeforeShadowMapRenderMeshObservable = new Observable();\r\n\r\n /**\r\n * Observable triggered after a mesh is rendered in the shadow map.\r\n * Can be used to update internal effect state (that you can get from the onAfterShadowMapRenderObservable)\r\n */\r\n public onAfterShadowMapRenderMeshObservable = new Observable();\r\n\r\n protected _bias = 0.00005;\r\n /**\r\n * Gets the bias: offset applied on the depth preventing acnea (in light direction).\r\n */\r\n public get bias(): number {\r\n return this._bias;\r\n }\r\n /**\r\n * Sets the bias: offset applied on the depth preventing acnea (in light direction).\r\n */\r\n public set bias(bias: number) {\r\n this._bias = bias;\r\n }\r\n\r\n protected _normalBias = 0;\r\n /**\r\n * Gets the normalBias: offset applied on the depth preventing acnea (along side the normal direction and proportional to the light/normal angle).\r\n */\r\n public get normalBias(): number {\r\n return this._normalBias;\r\n }\r\n /**\r\n * Sets the normalBias: offset applied on the depth preventing acnea (along side the normal direction and proportional to the light/normal angle).\r\n */\r\n public set normalBias(normalBias: number) {\r\n this._normalBias = normalBias;\r\n }\r\n\r\n protected _blurBoxOffset = 1;\r\n /**\r\n * Gets the blur box offset: offset applied during the blur pass.\r\n * Only useful if useKernelBlur = false\r\n */\r\n public get blurBoxOffset(): number {\r\n return this._blurBoxOffset;\r\n }\r\n /**\r\n * Sets the blur box offset: offset applied during the blur pass.\r\n * Only useful if useKernelBlur = false\r\n */\r\n public set blurBoxOffset(value: number) {\r\n if (this._blurBoxOffset === value) {\r\n return;\r\n }\r\n\r\n this._blurBoxOffset = value;\r\n this._disposeBlurPostProcesses();\r\n }\r\n\r\n protected _blurScale = 2;\r\n /**\r\n * Gets the blur scale: scale of the blurred texture compared to the main shadow map.\r\n * 2 means half of the size.\r\n */\r\n public get blurScale(): number {\r\n return this._blurScale;\r\n }\r\n /**\r\n * Sets the blur scale: scale of the blurred texture compared to the main shadow map.\r\n * 2 means half of the size.\r\n */\r\n public set blurScale(value: number) {\r\n if (this._blurScale === value) {\r\n return;\r\n }\r\n\r\n this._blurScale = value;\r\n this._disposeBlurPostProcesses();\r\n }\r\n\r\n protected _blurKernel = 1;\r\n /**\r\n * Gets the blur kernel: kernel size of the blur pass.\r\n * Only useful if useKernelBlur = true\r\n */\r\n public get blurKernel(): number {\r\n return this._blurKernel;\r\n }\r\n /**\r\n * Sets the blur kernel: kernel size of the blur pass.\r\n * Only useful if useKernelBlur = true\r\n */\r\n public set blurKernel(value: number) {\r\n if (this._blurKernel === value) {\r\n return;\r\n }\r\n\r\n this._blurKernel = value;\r\n this._disposeBlurPostProcesses();\r\n }\r\n\r\n protected _useKernelBlur = false;\r\n /**\r\n * Gets whether the blur pass is a kernel blur (if true) or box blur.\r\n * Only useful in filtered mode (useBlurExponentialShadowMap...)\r\n */\r\n public get useKernelBlur(): boolean {\r\n return this._useKernelBlur;\r\n }\r\n /**\r\n * Sets whether the blur pass is a kernel blur (if true) or box blur.\r\n * Only useful in filtered mode (useBlurExponentialShadowMap...)\r\n */\r\n public set useKernelBlur(value: boolean) {\r\n if (this._useKernelBlur === value) {\r\n return;\r\n }\r\n\r\n this._useKernelBlur = value;\r\n this._disposeBlurPostProcesses();\r\n }\r\n\r\n protected _depthScale: number;\r\n /**\r\n * Gets the depth scale used in ESM mode.\r\n */\r\n public get depthScale(): number {\r\n return this._depthScale !== undefined ? this._depthScale : this._light.getDepthScale();\r\n }\r\n /**\r\n * Sets the depth scale used in ESM mode.\r\n * This can override the scale stored on the light.\r\n */\r\n public set depthScale(value: number) {\r\n this._depthScale = value;\r\n }\r\n\r\n protected _validateFilter(filter: number): number {\r\n return filter;\r\n }\r\n\r\n protected _filter = ShadowGenerator.FILTER_NONE;\r\n /**\r\n * Gets the current mode of the shadow generator (normal, PCF, ESM...).\r\n * The returned value is a number equal to one of the available mode defined in ShadowMap.FILTER_x like _FILTER_NONE\r\n */\r\n public get filter(): number {\r\n return this._filter;\r\n }\r\n /**\r\n * Sets the current mode of the shadow generator (normal, PCF, ESM...).\r\n * The returned value is a number equal to one of the available mode defined in ShadowMap.FILTER_x like _FILTER_NONE\r\n */\r\n public set filter(value: number) {\r\n value = this._validateFilter(value);\r\n\r\n // Blurring the cubemap is going to be too expensive. Reverting to unblurred version\r\n if (this._light.needCube()) {\r\n if (value === ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP) {\r\n this.useExponentialShadowMap = true;\r\n return;\r\n } else if (value === ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP) {\r\n this.useCloseExponentialShadowMap = true;\r\n return;\r\n }\r\n // PCF on cubemap would also be expensive\r\n else if (value === ShadowGenerator.FILTER_PCF || value === ShadowGenerator.FILTER_PCSS) {\r\n this.usePoissonSampling = true;\r\n return;\r\n }\r\n }\r\n\r\n // Weblg1 fallback for PCF.\r\n if (value === ShadowGenerator.FILTER_PCF || value === ShadowGenerator.FILTER_PCSS) {\r\n if (!this._scene.getEngine()._features.supportShadowSamplers) {\r\n this.usePoissonSampling = true;\r\n return;\r\n }\r\n }\r\n\r\n if (this._filter === value) {\r\n return;\r\n }\r\n\r\n this._filter = value;\r\n this._disposeBlurPostProcesses();\r\n this._applyFilterValues();\r\n this._light._markMeshesAsLightDirty();\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to Poisson Sampling.\r\n */\r\n public get usePoissonSampling(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_POISSONSAMPLING;\r\n }\r\n /**\r\n * Sets the current filter to Poisson Sampling.\r\n */\r\n public set usePoissonSampling(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_POISSONSAMPLING);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_POISSONSAMPLING) {\r\n return;\r\n }\r\n\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to ESM.\r\n */\r\n public get useExponentialShadowMap(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP;\r\n }\r\n /**\r\n * Sets the current filter is to ESM.\r\n */\r\n public set useExponentialShadowMap(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_EXPONENTIALSHADOWMAP) {\r\n return;\r\n }\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to filtered ESM.\r\n */\r\n public get useBlurExponentialShadowMap(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP;\r\n }\r\n /**\r\n * Gets if the current filter is set to filtered ESM.\r\n */\r\n public set useBlurExponentialShadowMap(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP) {\r\n return;\r\n }\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to \"close ESM\" (using the inverse of the\r\n * exponential to prevent steep falloff artifacts).\r\n */\r\n public get useCloseExponentialShadowMap(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP;\r\n }\r\n /**\r\n * Sets the current filter to \"close ESM\" (using the inverse of the\r\n * exponential to prevent steep falloff artifacts).\r\n */\r\n public set useCloseExponentialShadowMap(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_CLOSEEXPONENTIALSHADOWMAP) {\r\n return;\r\n }\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to filtered \"close ESM\" (using the inverse of the\r\n * exponential to prevent steep falloff artifacts).\r\n */\r\n public get useBlurCloseExponentialShadowMap(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP;\r\n }\r\n /**\r\n * Sets the current filter to filtered \"close ESM\" (using the inverse of the\r\n * exponential to prevent steep falloff artifacts).\r\n */\r\n public set useBlurCloseExponentialShadowMap(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP) {\r\n return;\r\n }\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to \"PCF\" (percentage closer filtering).\r\n */\r\n public get usePercentageCloserFiltering(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_PCF;\r\n }\r\n /**\r\n * Sets the current filter to \"PCF\" (percentage closer filtering).\r\n */\r\n public set usePercentageCloserFiltering(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_PCF);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_PCF) {\r\n return;\r\n }\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n protected _filteringQuality = ShadowGenerator.QUALITY_HIGH;\r\n /**\r\n * Gets the PCF or PCSS Quality.\r\n * Only valid if usePercentageCloserFiltering or usePercentageCloserFiltering is true.\r\n */\r\n public get filteringQuality(): number {\r\n return this._filteringQuality;\r\n }\r\n /**\r\n * Sets the PCF or PCSS Quality.\r\n * Only valid if usePercentageCloserFiltering or usePercentageCloserFiltering is true.\r\n */\r\n public set filteringQuality(filteringQuality: number) {\r\n if (this._filteringQuality === filteringQuality) {\r\n return;\r\n }\r\n\r\n this._filteringQuality = filteringQuality;\r\n\r\n this._disposeBlurPostProcesses();\r\n this._applyFilterValues();\r\n this._light._markMeshesAsLightDirty();\r\n }\r\n\r\n /**\r\n * Gets if the current filter is set to \"PCSS\" (contact hardening).\r\n */\r\n public get useContactHardeningShadow(): boolean {\r\n return this.filter === ShadowGenerator.FILTER_PCSS;\r\n }\r\n /**\r\n * Sets the current filter to \"PCSS\" (contact hardening).\r\n */\r\n public set useContactHardeningShadow(value: boolean) {\r\n const filter = this._validateFilter(ShadowGenerator.FILTER_PCSS);\r\n\r\n if (!value && this.filter !== ShadowGenerator.FILTER_PCSS) {\r\n return;\r\n }\r\n this.filter = value ? filter : ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n protected _contactHardeningLightSizeUVRatio = 0.1;\r\n /**\r\n * Gets the Light Size (in shadow map uv unit) used in PCSS to determine the blocker search area and the penumbra size.\r\n * Using a ratio helps keeping shape stability independently of the map size.\r\n *\r\n * It does not account for the light projection as it was having too much\r\n * instability during the light setup or during light position changes.\r\n *\r\n * Only valid if useContactHardeningShadow is true.\r\n */\r\n public get contactHardeningLightSizeUVRatio(): number {\r\n return this._contactHardeningLightSizeUVRatio;\r\n }\r\n /**\r\n * Sets the Light Size (in shadow map uv unit) used in PCSS to determine the blocker search area and the penumbra size.\r\n * Using a ratio helps keeping shape stability independently of the map size.\r\n *\r\n * It does not account for the light projection as it was having too much\r\n * instability during the light setup or during light position changes.\r\n *\r\n * Only valid if useContactHardeningShadow is true.\r\n */\r\n public set contactHardeningLightSizeUVRatio(contactHardeningLightSizeUVRatio: number) {\r\n this._contactHardeningLightSizeUVRatio = contactHardeningLightSizeUVRatio;\r\n }\r\n\r\n protected _darkness = 0;\r\n\r\n /** Gets or sets the actual darkness of a shadow */\r\n public get darkness() {\r\n return this._darkness;\r\n }\r\n\r\n public set darkness(value: number) {\r\n this.setDarkness(value);\r\n }\r\n\r\n /**\r\n * Returns the darkness value (float). This can only decrease the actual darkness of a shadow.\r\n * 0 means strongest and 1 would means no shadow.\r\n * @returns the darkness.\r\n */\r\n public getDarkness(): number {\r\n return this._darkness;\r\n }\r\n /**\r\n * Sets the darkness value (float). This can only decrease the actual darkness of a shadow.\r\n * @param darkness The darkness value 0 means strongest and 1 would means no shadow.\r\n * @returns the shadow generator allowing fluent coding.\r\n */\r\n public setDarkness(darkness: number): ShadowGenerator {\r\n if (darkness >= 1.0) {\r\n this._darkness = 1.0;\r\n } else if (darkness <= 0.0) {\r\n this._darkness = 0.0;\r\n } else {\r\n this._darkness = darkness;\r\n }\r\n return this;\r\n }\r\n\r\n protected _transparencyShadow = false;\r\n\r\n /** Gets or sets the ability to have transparent shadow */\r\n public get transparencyShadow() {\r\n return this._transparencyShadow;\r\n }\r\n\r\n public set transparencyShadow(value: boolean) {\r\n this.setTransparencyShadow(value);\r\n }\r\n\r\n /**\r\n * Sets the ability to have transparent shadow (boolean).\r\n * @param transparent True if transparent else False\r\n * @returns the shadow generator allowing fluent coding\r\n */\r\n public setTransparencyShadow(transparent: boolean): ShadowGenerator {\r\n this._transparencyShadow = transparent;\r\n return this;\r\n }\r\n\r\n /**\r\n * Enables or disables shadows with varying strength based on the transparency\r\n * When it is enabled, the strength of the shadow is taken equal to mesh.visibility\r\n * If you enabled an alpha texture on your material, the alpha value red from the texture is also combined to compute the strength:\r\n * mesh.visibility * alphaTexture.a\r\n * The texture used is the diffuse by default, but it can be set to the opacity by setting useOpacityTextureForTransparentShadow\r\n * Note that by definition transparencyShadow must be set to true for enableSoftTransparentShadow to work!\r\n */\r\n public enableSoftTransparentShadow: boolean = false;\r\n\r\n /**\r\n * If this is true, use the opacity texture's alpha channel for transparent shadows instead of the diffuse one\r\n */\r\n public useOpacityTextureForTransparentShadow: boolean = false;\r\n\r\n protected _shadowMap: Nullable;\r\n protected _shadowMap2: Nullable;\r\n\r\n /**\r\n * Gets the main RTT containing the shadow map (usually storing depth from the light point of view).\r\n * @returns The render target texture if present otherwise, null\r\n */\r\n public getShadowMap(): Nullable {\r\n return this._shadowMap;\r\n }\r\n\r\n /**\r\n * Gets the RTT used during rendering (can be a blurred version of the shadow map or the shadow map itself).\r\n * @returns The render target texture if the shadow map is present otherwise, null\r\n */\r\n public getShadowMapForRendering(): Nullable {\r\n if (this._shadowMap2) {\r\n return this._shadowMap2;\r\n }\r\n\r\n return this._shadowMap;\r\n }\r\n\r\n /**\r\n * Gets the class name of that object\r\n * @returns \"ShadowGenerator\"\r\n */\r\n public getClassName(): string {\r\n return ShadowGenerator.CLASSNAME;\r\n }\r\n\r\n /**\r\n * Helper function to add a mesh and its descendants to the list of shadow casters.\r\n * @param mesh Mesh to add\r\n * @param includeDescendants boolean indicating if the descendants should be added. Default to true\r\n * @returns the Shadow Generator itself\r\n */\r\n public addShadowCaster(mesh: AbstractMesh, includeDescendants = true): ShadowGenerator {\r\n if (!this._shadowMap) {\r\n return this;\r\n }\r\n\r\n if (!this._shadowMap.renderList) {\r\n this._shadowMap.renderList = [];\r\n }\r\n\r\n if (this._shadowMap.renderList.indexOf(mesh) === -1) {\r\n this._shadowMap.renderList.push(mesh);\r\n }\r\n\r\n if (includeDescendants) {\r\n for (const childMesh of mesh.getChildMeshes()) {\r\n if (this._shadowMap.renderList.indexOf(childMesh) === -1) {\r\n this._shadowMap.renderList.push(childMesh);\r\n }\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Helper function to remove a mesh and its descendants from the list of shadow casters\r\n * @param mesh Mesh to remove\r\n * @param includeDescendants boolean indicating if the descendants should be removed. Default to true\r\n * @returns the Shadow Generator itself\r\n */\r\n public removeShadowCaster(mesh: AbstractMesh, includeDescendants = true): ShadowGenerator {\r\n if (!this._shadowMap || !this._shadowMap.renderList) {\r\n return this;\r\n }\r\n\r\n const index = this._shadowMap.renderList.indexOf(mesh);\r\n\r\n if (index !== -1) {\r\n this._shadowMap.renderList.splice(index, 1);\r\n }\r\n\r\n if (includeDescendants) {\r\n for (const child of mesh.getChildren()) {\r\n this.removeShadowCaster(child);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Controls the extent to which the shadows fade out at the edge of the frustum\r\n */\r\n public frustumEdgeFalloff = 0;\r\n\r\n protected _light: IShadowLight;\r\n /**\r\n * Returns the associated light object.\r\n * @returns the light generating the shadow\r\n */\r\n public getLight(): IShadowLight {\r\n return this._light;\r\n }\r\n\r\n /**\r\n * If true the shadow map is generated by rendering the back face of the mesh instead of the front face.\r\n * This can help with self-shadowing as the geometry making up the back of objects is slightly offset.\r\n * It might on the other hand introduce peter panning.\r\n */\r\n public forceBackFacesOnly = false;\r\n\r\n protected _camera: Nullable;\r\n\r\n protected _getCamera() {\r\n return this._camera ?? this._scene.activeCamera;\r\n }\r\n\r\n protected _scene: Scene;\r\n protected _useRedTextureType: boolean;\r\n protected _lightDirection = Vector3.Zero();\r\n\r\n protected _viewMatrix = Matrix.Zero();\r\n protected _projectionMatrix = Matrix.Zero();\r\n protected _transformMatrix = Matrix.Zero();\r\n protected _cachedPosition: Vector3 = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n protected _cachedDirection: Vector3 = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n protected _cachedDefines: string;\r\n protected _currentRenderId: number;\r\n protected _boxBlurPostprocess: Nullable;\r\n protected _kernelBlurXPostprocess: Nullable;\r\n protected _kernelBlurYPostprocess: Nullable;\r\n protected _blurPostProcesses: PostProcess[];\r\n protected _mapSize: number;\r\n protected _currentFaceIndex = 0;\r\n protected _currentFaceIndexCache = 0;\r\n protected _textureType: number;\r\n protected _defaultTextureMatrix = Matrix.Identity();\r\n protected _storedUniqueId: Nullable;\r\n protected _useUBO: boolean;\r\n protected _sceneUBOs: UniformBuffer[];\r\n protected _currentSceneUBO: UniformBuffer;\r\n protected _opacityTexture: Nullable;\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {\r\n throw _WarnImport(\"ShadowGeneratorSceneComponent\");\r\n };\r\n\r\n /**\r\n * Gets or sets the size of the texture what stores the shadows\r\n */\r\n public get mapSize(): number {\r\n return this._mapSize;\r\n }\r\n\r\n public set mapSize(size: number) {\r\n this._mapSize = size;\r\n this._light._markMeshesAsLightDirty();\r\n this.recreateShadowMap();\r\n }\r\n\r\n /**\r\n * Creates a ShadowGenerator object.\r\n * A ShadowGenerator is the required tool to use the shadows.\r\n * Each light casting shadows needs to use its own ShadowGenerator.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\r\n * @param mapSize The size of the texture what stores the shadows. Example : 1024.\r\n * @param light The light object generating the shadows.\r\n * @param usefullFloatFirst By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.\r\n * @param camera Camera associated with this shadow generator (default: null). If null, takes the scene active camera at the time we need to access it\r\n * @param useRedTextureType Forces the generator to use a Red instead of a RGBA type for the shadow map texture format (default: false)\r\n */\r\n constructor(mapSize: number, light: IShadowLight, usefullFloatFirst?: boolean, camera?: Nullable, useRedTextureType?: boolean) {\r\n this._mapSize = mapSize;\r\n this._light = light;\r\n this._scene = light.getScene();\r\n this._camera = camera ?? null;\r\n this._useRedTextureType = !!useRedTextureType;\r\n\r\n let shadowGenerators = light._shadowGenerators;\r\n if (!shadowGenerators) {\r\n shadowGenerators = light._shadowGenerators = new Map();\r\n }\r\n shadowGenerators.set(this._camera, this);\r\n this.id = light.id;\r\n this._useUBO = this._scene.getEngine().supportsUniformBuffers;\r\n\r\n if (this._useUBO) {\r\n this._sceneUBOs = [];\r\n this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for Shadow Generator (light \"${this._light.name}\")`));\r\n }\r\n\r\n ShadowGenerator._SceneComponentInitialization(this._scene);\r\n\r\n // Texture type fallback from float to int if not supported.\r\n const caps = this._scene.getEngine().getCaps();\r\n\r\n if (!usefullFloatFirst) {\r\n if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\r\n this._textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\r\n this._textureType = Constants.TEXTURETYPE_FLOAT;\r\n } else {\r\n this._textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n }\r\n } else {\r\n if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\r\n this._textureType = Constants.TEXTURETYPE_FLOAT;\r\n } else if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\r\n this._textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else {\r\n this._textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n }\r\n }\r\n\r\n this._initializeGenerator();\r\n this._applyFilterValues();\r\n }\r\n\r\n protected _initializeGenerator(): void {\r\n this._light._markMeshesAsLightDirty();\r\n this._initializeShadowMap();\r\n }\r\n\r\n protected _createTargetRenderTexture(): void {\r\n const engine = this._scene.getEngine();\r\n if (engine._features.supportDepthStencilTexture) {\r\n this._shadowMap = new RenderTargetTexture(\r\n this._light.name + \"_shadowMap\",\r\n this._mapSize,\r\n this._scene,\r\n false,\r\n true,\r\n this._textureType,\r\n this._light.needCube(),\r\n undefined,\r\n false,\r\n false,\r\n undefined,\r\n this._useRedTextureType ? Constants.TEXTUREFORMAT_RED : Constants.TEXTUREFORMAT_RGBA\r\n );\r\n this._shadowMap.createDepthStencilTexture(engine.useReverseDepthBuffer ? Constants.GREATER : Constants.LESS, true);\r\n } else {\r\n this._shadowMap = new RenderTargetTexture(this._light.name + \"_shadowMap\", this._mapSize, this._scene, false, true, this._textureType, this._light.needCube());\r\n }\r\n this._shadowMap.noPrePassRenderer = true;\r\n }\r\n\r\n protected _initializeShadowMap(): void {\r\n this._createTargetRenderTexture();\r\n\r\n if (this._shadowMap === null) {\r\n return;\r\n }\r\n\r\n this._shadowMap.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this._shadowMap.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n this._shadowMap.anisotropicFilteringLevel = 1;\r\n this._shadowMap.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\r\n this._shadowMap.renderParticles = false;\r\n this._shadowMap.ignoreCameraViewport = true;\r\n if (this._storedUniqueId) {\r\n this._shadowMap.uniqueId = this._storedUniqueId;\r\n }\r\n\r\n // Custom render function.\r\n this._shadowMap.customRenderFunction = this._renderForShadowMap.bind(this);\r\n\r\n // Force the mesh is ready function to true as we are double checking it\r\n // in the custom render function. Also it prevents side effects and useless\r\n // shader variations in DEPTHPREPASS mode.\r\n this._shadowMap.customIsReadyFunction = () => {\r\n return true;\r\n };\r\n\r\n const engine = this._scene.getEngine();\r\n\r\n this._shadowMap.onBeforeBindObservable.add(() => {\r\n this._currentSceneUBO = this._scene.getSceneUniformBuffer();\r\n engine._debugPushGroup?.(`shadow map generation for pass id ${engine.currentRenderPassId}`, 1);\r\n });\r\n\r\n // Record Face Index before render.\r\n this._shadowMap.onBeforeRenderObservable.add((faceIndex: number) => {\r\n if (this._sceneUBOs) {\r\n this._scene.setSceneUniformBuffer(this._sceneUBOs[0]);\r\n }\r\n this._currentFaceIndex = faceIndex;\r\n if (this._filter === ShadowGenerator.FILTER_PCF) {\r\n engine.setColorWrite(false);\r\n }\r\n this.getTransformMatrix(); // generate the view/projection matrix\r\n this._scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);\r\n if (this._useUBO) {\r\n this._scene.getSceneUniformBuffer().unbindEffect();\r\n this._scene.finalizeSceneUbo();\r\n }\r\n });\r\n\r\n // Blur if required after render.\r\n this._shadowMap.onAfterUnbindObservable.add(() => {\r\n if (this._sceneUBOs) {\r\n this._scene.setSceneUniformBuffer(this._currentSceneUBO);\r\n }\r\n this._scene.updateTransformMatrix(); // restore the view/projection matrices of the active camera\r\n\r\n if (this._filter === ShadowGenerator.FILTER_PCF) {\r\n engine.setColorWrite(true);\r\n }\r\n if (!this.useBlurExponentialShadowMap && !this.useBlurCloseExponentialShadowMap) {\r\n engine._debugPopGroup?.(1);\r\n return;\r\n }\r\n const shadowMap = this.getShadowMapForRendering();\r\n\r\n if (shadowMap) {\r\n this._scene.postProcessManager.directRender(this._blurPostProcesses, shadowMap.renderTarget, true);\r\n engine.unBindFramebuffer(shadowMap.renderTarget!, true);\r\n engine._debugPopGroup?.(1);\r\n }\r\n });\r\n\r\n // Clear according to the chosen filter.\r\n const clearZero = new Color4(0, 0, 0, 0);\r\n const clearOne = new Color4(1.0, 1.0, 1.0, 1.0);\r\n this._shadowMap.onClearObservable.add((engine) => {\r\n if (this._filter === ShadowGenerator.FILTER_PCF) {\r\n engine.clear(clearOne, false, true, false);\r\n } else if (this.useExponentialShadowMap || this.useBlurExponentialShadowMap) {\r\n engine.clear(clearZero, true, true, false);\r\n } else {\r\n engine.clear(clearOne, true, true, false);\r\n }\r\n });\r\n\r\n // Recreate on resize.\r\n this._shadowMap.onResizeObservable.add((rtt) => {\r\n this._storedUniqueId = this._shadowMap!.uniqueId;\r\n this._mapSize = rtt.getRenderSize();\r\n this._light._markMeshesAsLightDirty();\r\n this.recreateShadowMap();\r\n });\r\n\r\n // Ensures rendering groupids do not erase the depth buffer\r\n // or we would lose the shadows information.\r\n for (let i = RenderingManager.MIN_RENDERINGGROUPS; i < RenderingManager.MAX_RENDERINGGROUPS; i++) {\r\n this._shadowMap.setRenderingAutoClearDepthStencil(i, false);\r\n }\r\n }\r\n\r\n protected _initializeBlurRTTAndPostProcesses(): void {\r\n const engine = this._scene.getEngine();\r\n const targetSize = this._mapSize / this.blurScale;\r\n\r\n if (!this.useKernelBlur || this.blurScale !== 1.0) {\r\n this._shadowMap2 = new RenderTargetTexture(this._light.name + \"_shadowMap2\", targetSize, this._scene, false, true, this._textureType, undefined, undefined, false);\r\n this._shadowMap2.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this._shadowMap2.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n this._shadowMap2.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\r\n }\r\n\r\n if (this.useKernelBlur) {\r\n this._kernelBlurXPostprocess = new BlurPostProcess(\r\n this._light.name + \"KernelBlurX\",\r\n new Vector2(1, 0),\r\n this.blurKernel,\r\n 1.0,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n this._textureType\r\n );\r\n this._kernelBlurXPostprocess.width = targetSize;\r\n this._kernelBlurXPostprocess.height = targetSize;\r\n this._kernelBlurXPostprocess.externalTextureSamplerBinding = true;\r\n this._kernelBlurXPostprocess.onApplyObservable.add((effect) => {\r\n effect.setTexture(\"textureSampler\", this._shadowMap);\r\n });\r\n\r\n this._kernelBlurYPostprocess = new BlurPostProcess(\r\n this._light.name + \"KernelBlurY\",\r\n new Vector2(0, 1),\r\n this.blurKernel,\r\n 1.0,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n this._textureType\r\n );\r\n\r\n this._kernelBlurXPostprocess.autoClear = false;\r\n this._kernelBlurYPostprocess.autoClear = false;\r\n\r\n if (this._textureType === Constants.TEXTURETYPE_UNSIGNED_INT) {\r\n (this._kernelBlurXPostprocess).packedFloat = true;\r\n (this._kernelBlurYPostprocess).packedFloat = true;\r\n }\r\n\r\n this._blurPostProcesses = [this._kernelBlurXPostprocess, this._kernelBlurYPostprocess];\r\n } else {\r\n this._boxBlurPostprocess = new PostProcess(\r\n this._light.name + \"DepthBoxBlur\",\r\n \"depthBoxBlur\",\r\n [\"screenSize\", \"boxOffset\"],\r\n [],\r\n 1.0,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n \"#define OFFSET \" + this._blurBoxOffset,\r\n this._textureType\r\n );\r\n this._boxBlurPostprocess.externalTextureSamplerBinding = true;\r\n this._boxBlurPostprocess.onApplyObservable.add((effect) => {\r\n effect.setFloat2(\"screenSize\", targetSize, targetSize);\r\n effect.setTexture(\"textureSampler\", this._shadowMap);\r\n });\r\n\r\n this._boxBlurPostprocess.autoClear = false;\r\n\r\n this._blurPostProcesses = [this._boxBlurPostprocess];\r\n }\r\n }\r\n\r\n protected _renderForShadowMap(\r\n opaqueSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray\r\n ): void {\r\n let index: number;\r\n\r\n if (depthOnlySubMeshes.length) {\r\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\r\n this._renderSubMeshForShadowMap(depthOnlySubMeshes.data[index]);\r\n }\r\n }\r\n\r\n for (index = 0; index < opaqueSubMeshes.length; index++) {\r\n this._renderSubMeshForShadowMap(opaqueSubMeshes.data[index]);\r\n }\r\n\r\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\r\n this._renderSubMeshForShadowMap(alphaTestSubMeshes.data[index]);\r\n }\r\n\r\n if (this._transparencyShadow) {\r\n for (index = 0; index < transparentSubMeshes.length; index++) {\r\n this._renderSubMeshForShadowMap(transparentSubMeshes.data[index], true);\r\n }\r\n } else {\r\n for (index = 0; index < transparentSubMeshes.length; index++) {\r\n transparentSubMeshes.data[index].getEffectiveMesh()._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n }\r\n }\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _bindCustomEffectForRenderSubMeshForShadowMap(subMesh: SubMesh, effect: Effect, mesh: AbstractMesh): void {\r\n effect.setMatrix(\"viewProjection\", this.getTransformMatrix());\r\n }\r\n\r\n protected _renderSubMeshForShadowMap(subMesh: SubMesh, isTransparent: boolean = false): void {\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n const effectiveMesh = subMesh.getEffectiveMesh();\r\n const scene = this._scene;\r\n const engine = scene.getEngine();\r\n const material = subMesh.getMaterial();\r\n\r\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n\r\n if (!material || subMesh.verticesCount === 0 || subMesh._renderId === scene.getRenderId()) {\r\n return;\r\n }\r\n\r\n // Culling\r\n const detNeg = effectiveMesh._getWorldMatrixDeterminant() < 0;\r\n let sideOrientation = renderingMesh.overrideMaterialSideOrientation ?? material.sideOrientation;\r\n if (detNeg) {\r\n sideOrientation =\r\n sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation ? Constants.MATERIAL_CounterClockWiseSideOrientation : Constants.MATERIAL_ClockWiseSideOrientation;\r\n }\r\n const reverseSideOrientation = sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation;\r\n\r\n engine.setState(material.backFaceCulling, undefined, undefined, reverseSideOrientation, material.cullBackFaces);\r\n\r\n // Managing instances\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\r\n if (batch.mustReturn) {\r\n return;\r\n }\r\n\r\n const hardwareInstancedRendering =\r\n engine.getCaps().instancedArrays &&\r\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || renderingMesh.hasThinInstances);\r\n\r\n if (this.customAllowRendering && !this.customAllowRendering(subMesh)) {\r\n return;\r\n }\r\n\r\n if (this.isReady(subMesh, hardwareInstancedRendering, isTransparent)) {\r\n subMesh._renderId = scene.getRenderId();\r\n\r\n const shadowDepthWrapper = material.shadowDepthWrapper;\r\n\r\n const drawWrapper = shadowDepthWrapper?.getEffect(subMesh, this, engine.currentRenderPassId) ?? subMesh._getDrawWrapper()!;\r\n const effect = DrawWrapper.GetEffect(drawWrapper)!;\r\n\r\n engine.enableEffect(drawWrapper);\r\n\r\n if (!hardwareInstancedRendering) {\r\n renderingMesh._bind(subMesh, effect, material.fillMode);\r\n }\r\n\r\n this.getTransformMatrix(); // make sure _cachedDirection et _cachedPosition are up to date\r\n\r\n effect.setFloat3(\"biasAndScaleSM\", this.bias, this.normalBias, this.depthScale);\r\n\r\n if (this.getLight().getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {\r\n effect.setVector3(\"lightDataSM\", this._cachedDirection);\r\n } else {\r\n effect.setVector3(\"lightDataSM\", this._cachedPosition);\r\n }\r\n\r\n const camera = this._getCamera();\r\n if (camera) {\r\n effect.setFloat2(\"depthValuesSM\", this.getLight().getDepthMinZ(camera), this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera));\r\n }\r\n\r\n if (isTransparent && this.enableSoftTransparentShadow) {\r\n effect.setFloat(\"softTransparentShadowSM\", effectiveMesh.visibility * material.alpha);\r\n }\r\n\r\n if (shadowDepthWrapper) {\r\n subMesh._setMainDrawWrapperOverride(drawWrapper);\r\n if (shadowDepthWrapper.standalone) {\r\n shadowDepthWrapper.baseMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);\r\n } else {\r\n material.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);\r\n }\r\n subMesh._setMainDrawWrapperOverride(null);\r\n } else {\r\n // Alpha test\r\n if (this._opacityTexture) {\r\n effect.setTexture(\"diffuseSampler\", this._opacityTexture);\r\n effect.setMatrix(\"diffuseMatrix\", this._opacityTexture.getTextureMatrix() || this._defaultTextureMatrix);\r\n }\r\n\r\n // Bones\r\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\r\n const skeleton = renderingMesh.skeleton;\r\n\r\n if (skeleton.isUsingTextureForMatrices) {\r\n const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);\r\n\r\n if (!boneTexture) {\r\n return;\r\n }\r\n\r\n effect.setTexture(\"boneSampler\", boneTexture);\r\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\r\n } else {\r\n effect.setMatrices(\"mBones\", skeleton.getTransformMatrices(renderingMesh));\r\n }\r\n }\r\n\r\n // Morph targets\r\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\r\n\r\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\r\n renderingMesh.morphTargetManager._bind(effect);\r\n }\r\n\r\n // Clip planes\r\n bindClipPlane(effect, material, scene);\r\n }\r\n\r\n if (!this._useUBO && !shadowDepthWrapper) {\r\n this._bindCustomEffectForRenderSubMeshForShadowMap(subMesh, effect, effectiveMesh);\r\n }\r\n\r\n MaterialHelper.BindSceneUniformBuffer(effect, this._scene.getSceneUniformBuffer());\r\n this._scene.getSceneUniformBuffer().bindUniformBuffer();\r\n\r\n const world = effectiveMesh.getWorldMatrix();\r\n\r\n // In the non hardware instanced mode, the Mesh ubo update is done by the callback passed to renderingMesh._processRendering (see below)\r\n if (hardwareInstancedRendering) {\r\n effectiveMesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\r\n effectiveMesh.transferToEffect(world);\r\n }\r\n\r\n if (this.forceBackFacesOnly) {\r\n engine.setState(true, 0, false, true, material.cullBackFaces);\r\n }\r\n\r\n // Observables\r\n this.onBeforeShadowMapRenderMeshObservable.notifyObservers(renderingMesh);\r\n this.onBeforeShadowMapRenderObservable.notifyObservers(effect);\r\n\r\n // Draw\r\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, worldOverride) => {\r\n if (effectiveMesh !== renderingMesh && !isInstance) {\r\n renderingMesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\r\n renderingMesh.transferToEffect(worldOverride);\r\n } else {\r\n effectiveMesh.getMeshUniformBuffer().bindToEffect(effect, \"Mesh\");\r\n effectiveMesh.transferToEffect(isInstance ? worldOverride : world);\r\n }\r\n });\r\n\r\n if (this.forceBackFacesOnly) {\r\n engine.setState(true, 0, false, false, material.cullBackFaces);\r\n }\r\n\r\n // Observables\r\n this.onAfterShadowMapRenderObservable.notifyObservers(effect);\r\n this.onAfterShadowMapRenderMeshObservable.notifyObservers(renderingMesh);\r\n } else {\r\n // Need to reset refresh rate of the shadowMap\r\n if (this._shadowMap) {\r\n this._shadowMap.resetRefreshCounter();\r\n }\r\n }\r\n }\r\n\r\n protected _applyFilterValues(): void {\r\n if (!this._shadowMap) {\r\n return;\r\n }\r\n\r\n if (this.filter === ShadowGenerator.FILTER_NONE || this.filter === ShadowGenerator.FILTER_PCSS) {\r\n this._shadowMap.updateSamplingMode(Texture.NEAREST_SAMPLINGMODE);\r\n } else {\r\n this._shadowMap.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);\r\n }\r\n }\r\n\r\n /**\r\n * Forces all the attached effect to compile to enable rendering only once ready vs. lazily compiling effects.\r\n * @param onCompiled Callback triggered at the and of the effects compilation\r\n * @param options Sets of optional options forcing the compilation with different modes\r\n */\r\n public forceCompilation(onCompiled?: (generator: IShadowGenerator) => void, options?: Partial<{ useInstances: boolean }>): void {\r\n const localOptions = {\r\n useInstances: false,\r\n ...options,\r\n };\r\n\r\n const shadowMap = this.getShadowMap();\r\n if (!shadowMap) {\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n return;\r\n }\r\n\r\n const renderList = shadowMap.renderList;\r\n if (!renderList) {\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n return;\r\n }\r\n\r\n const subMeshes = new Array();\r\n for (const mesh of renderList) {\r\n subMeshes.push(...mesh.subMeshes);\r\n }\r\n if (subMeshes.length === 0) {\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n return;\r\n }\r\n\r\n let currentIndex = 0;\r\n\r\n const checkReady = () => {\r\n if (!this._scene || !this._scene.getEngine()) {\r\n return;\r\n }\r\n\r\n while (\r\n this.isReady(\r\n subMeshes[currentIndex],\r\n localOptions.useInstances,\r\n subMeshes[currentIndex].getMaterial()?.needAlphaBlendingForMesh(subMeshes[currentIndex].getMesh()) ?? false\r\n )\r\n ) {\r\n currentIndex++;\r\n if (currentIndex >= subMeshes.length) {\r\n if (onCompiled) {\r\n onCompiled(this);\r\n }\r\n return;\r\n }\r\n }\r\n setTimeout(checkReady, 16);\r\n };\r\n\r\n checkReady();\r\n }\r\n\r\n /**\r\n * Forces all the attached effect to compile to enable rendering only once ready vs. lazily compiling effects.\r\n * @param options Sets of optional options forcing the compilation with different modes\r\n * @returns A promise that resolves when the compilation completes\r\n */\r\n public forceCompilationAsync(options?: Partial<{ useInstances: boolean }>): Promise {\r\n return new Promise((resolve) => {\r\n this.forceCompilation(() => {\r\n resolve();\r\n }, options);\r\n });\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _isReadyCustomDefines(defines: any, subMesh: SubMesh, useInstances: boolean): void {}\r\n\r\n private _prepareShadowDefines(subMesh: SubMesh, useInstances: boolean, defines: string[], isTransparent: boolean): string[] {\r\n defines.push(\"#define SM_LIGHTTYPE_\" + this._light.getClassName().toUpperCase());\r\n\r\n defines.push(\"#define SM_FLOAT \" + (this._textureType !== Constants.TEXTURETYPE_UNSIGNED_INT ? \"1\" : \"0\"));\r\n\r\n defines.push(\"#define SM_ESM \" + (this.useExponentialShadowMap || this.useBlurExponentialShadowMap ? \"1\" : \"0\"));\r\n\r\n defines.push(\"#define SM_DEPTHTEXTURE \" + (this.usePercentageCloserFiltering || this.useContactHardeningShadow ? \"1\" : \"0\"));\r\n\r\n const mesh = subMesh.getMesh();\r\n\r\n // Normal bias.\r\n defines.push(\"#define SM_NORMALBIAS \" + (this.normalBias && mesh.isVerticesDataPresent(VertexBuffer.NormalKind) ? \"1\" : \"0\"));\r\n defines.push(\"#define SM_DIRECTIONINLIGHTDATA \" + (this.getLight().getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT ? \"1\" : \"0\"));\r\n\r\n // Point light\r\n defines.push(\"#define SM_USEDISTANCE \" + (this._light.needCube() ? \"1\" : \"0\"));\r\n\r\n // Soft transparent shadows\r\n defines.push(\"#define SM_SOFTTRANSPARENTSHADOW \" + (this.enableSoftTransparentShadow && isTransparent ? \"1\" : \"0\"));\r\n\r\n this._isReadyCustomDefines(defines, subMesh, useInstances);\r\n\r\n return defines;\r\n }\r\n\r\n /**\r\n * Determine whether the shadow generator is ready or not (mainly all effects and related post processes needs to be ready).\r\n * @param subMesh The submesh we want to render in the shadow map\r\n * @param useInstances Defines whether will draw in the map using instances\r\n * @param isTransparent Indicates that isReady is called for a transparent subMesh\r\n * @returns true if ready otherwise, false\r\n */\r\n public isReady(subMesh: SubMesh, useInstances: boolean, isTransparent: boolean): boolean {\r\n const material = subMesh.getMaterial(),\r\n shadowDepthWrapper = material?.shadowDepthWrapper;\r\n\r\n this._opacityTexture = null;\r\n\r\n if (!material) {\r\n return false;\r\n }\r\n\r\n const defines: string[] = [];\r\n\r\n this._prepareShadowDefines(subMesh, useInstances, defines, isTransparent);\r\n\r\n if (shadowDepthWrapper) {\r\n if (!shadowDepthWrapper.isReadyForSubMesh(subMesh, defines, this, useInstances, this._scene.getEngine().currentRenderPassId)) {\r\n return false;\r\n }\r\n } else {\r\n const subMeshEffect = subMesh._getDrawWrapper(undefined, true)!;\r\n\r\n let effect = subMeshEffect.effect!;\r\n let cachedDefines = subMeshEffect.defines;\r\n\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n const mesh = subMesh.getMesh();\r\n\r\n // Normal bias.\r\n if (this.normalBias && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n defines.push(\"#define NORMAL\");\r\n if (mesh.nonUniformScaling) {\r\n defines.push(\"#define NONUNIFORMSCALING\");\r\n }\r\n }\r\n\r\n // Alpha test\r\n const needAlphaTesting = material.needAlphaTesting();\r\n\r\n if (needAlphaTesting || material.needAlphaBlending()) {\r\n if (this.useOpacityTextureForTransparentShadow) {\r\n this._opacityTexture = (material as any).opacityTexture;\r\n } else {\r\n this._opacityTexture = material.getAlphaTestTexture();\r\n }\r\n if (this._opacityTexture) {\r\n if (!this._opacityTexture.isReady()) {\r\n return false;\r\n }\r\n\r\n const alphaCutOff = (material as any).alphaCutOff ?? ShadowGenerator.DEFAULT_ALPHA_CUTOFF;\r\n\r\n defines.push(\"#define ALPHATEXTURE\");\r\n if (needAlphaTesting) {\r\n defines.push(`#define ALPHATESTVALUE ${alphaCutOff}${alphaCutOff % 1 === 0 ? \".\" : \"\"}`);\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n attribs.push(VertexBuffer.UVKind);\r\n defines.push(\"#define UV1\");\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\r\n if (this._opacityTexture.coordinatesIndex === 1) {\r\n attribs.push(VertexBuffer.UV2Kind);\r\n defines.push(\"#define UV2\");\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Bones\r\n const fallbacks = new EffectFallbacks();\r\n if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n const skeleton = mesh.skeleton;\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n if (mesh.numBoneInfluencers > 0) {\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n }\r\n\r\n if (skeleton.isUsingTextureForMatrices) {\r\n defines.push(\"#define BONETEXTURE\");\r\n } else {\r\n defines.push(\"#define BonesPerMesh \" + (skeleton.bones.length + 1));\r\n }\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph targets\r\n const manager = (mesh).morphTargetManager;\r\n let morphInfluencers = 0;\r\n if (manager) {\r\n if (manager.numInfluencers > 0) {\r\n defines.push(\"#define MORPHTARGETS\");\r\n morphInfluencers = manager.numInfluencers;\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + morphInfluencers);\r\n if (manager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n }\r\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, morphInfluencers);\r\n }\r\n }\r\n\r\n // ClipPlanes\r\n prepareStringDefinesForClipPlanes(material, this._scene, defines);\r\n\r\n // Instances\r\n if (useInstances) {\r\n defines.push(\"#define INSTANCES\");\r\n MaterialHelper.PushAttributesForInstances(attribs);\r\n if (subMesh.getRenderingMesh().hasThinInstances) {\r\n defines.push(\"#define THIN_INSTANCES\");\r\n }\r\n }\r\n\r\n if (this.customShaderOptions) {\r\n if (this.customShaderOptions.defines) {\r\n for (const define of this.customShaderOptions.defines) {\r\n if (defines.indexOf(define) === -1) {\r\n defines.push(define);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Get correct effect\r\n const join = defines.join(\"\\n\");\r\n if (cachedDefines !== join) {\r\n cachedDefines = join;\r\n\r\n let shaderName = \"shadowMap\";\r\n const uniforms = [\r\n \"world\",\r\n \"mBones\",\r\n \"viewProjection\",\r\n \"diffuseMatrix\",\r\n \"lightDataSM\",\r\n \"depthValuesSM\",\r\n \"biasAndScaleSM\",\r\n \"morphTargetInfluences\",\r\n \"boneTextureWidth\",\r\n \"softTransparentShadowSM\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n ];\r\n const samplers = [\"diffuseSampler\", \"boneSampler\", \"morphTargets\"];\r\n const uniformBuffers = [\"Scene\", \"Mesh\"];\r\n\r\n addClipPlaneUniforms(uniforms);\r\n\r\n // Custom shader?\r\n if (this.customShaderOptions) {\r\n shaderName = this.customShaderOptions.shaderName;\r\n\r\n if (this.customShaderOptions.attributes) {\r\n for (const attrib of this.customShaderOptions.attributes) {\r\n if (attribs.indexOf(attrib) === -1) {\r\n attribs.push(attrib);\r\n }\r\n }\r\n }\r\n\r\n if (this.customShaderOptions.uniforms) {\r\n for (const uniform of this.customShaderOptions.uniforms) {\r\n if (uniforms.indexOf(uniform) === -1) {\r\n uniforms.push(uniform);\r\n }\r\n }\r\n }\r\n\r\n if (this.customShaderOptions.samplers) {\r\n for (const sampler of this.customShaderOptions.samplers) {\r\n if (samplers.indexOf(sampler) === -1) {\r\n samplers.push(sampler);\r\n }\r\n }\r\n }\r\n }\r\n\r\n const engine = this._scene.getEngine();\r\n\r\n effect = engine.createEffect(\r\n shaderName,\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: null,\r\n onError: null,\r\n indexParameters: { maxSimultaneousMorphTargets: morphInfluencers },\r\n },\r\n engine\r\n );\r\n\r\n subMeshEffect.setEffect(effect, cachedDefines);\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this.useBlurExponentialShadowMap || this.useBlurCloseExponentialShadowMap) {\r\n if (!this._blurPostProcesses || !this._blurPostProcesses.length) {\r\n this._initializeBlurRTTAndPostProcesses();\r\n }\r\n }\r\n\r\n if (this._kernelBlurXPostprocess && !this._kernelBlurXPostprocess.isReady()) {\r\n return false;\r\n }\r\n if (this._kernelBlurYPostprocess && !this._kernelBlurYPostprocess.isReady()) {\r\n return false;\r\n }\r\n if (this._boxBlurPostprocess && !this._boxBlurPostprocess.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\r\n * @param defines Defines of the material we want to update\r\n * @param lightIndex Index of the light in the enabled light list of the material\r\n */\r\n public prepareDefines(defines: any, lightIndex: number): void {\r\n const scene = this._scene;\r\n const light = this._light;\r\n\r\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\r\n return;\r\n }\r\n\r\n defines[\"SHADOW\" + lightIndex] = true;\r\n\r\n if (this.useContactHardeningShadow) {\r\n defines[\"SHADOWPCSS\" + lightIndex] = true;\r\n if (this._filteringQuality === ShadowGenerator.QUALITY_LOW) {\r\n defines[\"SHADOWLOWQUALITY\" + lightIndex] = true;\r\n } else if (this._filteringQuality === ShadowGenerator.QUALITY_MEDIUM) {\r\n defines[\"SHADOWMEDIUMQUALITY\" + lightIndex] = true;\r\n }\r\n // else default to high.\r\n } else if (this.usePercentageCloserFiltering) {\r\n defines[\"SHADOWPCF\" + lightIndex] = true;\r\n if (this._filteringQuality === ShadowGenerator.QUALITY_LOW) {\r\n defines[\"SHADOWLOWQUALITY\" + lightIndex] = true;\r\n } else if (this._filteringQuality === ShadowGenerator.QUALITY_MEDIUM) {\r\n defines[\"SHADOWMEDIUMQUALITY\" + lightIndex] = true;\r\n }\r\n // else default to high.\r\n } else if (this.usePoissonSampling) {\r\n defines[\"SHADOWPOISSON\" + lightIndex] = true;\r\n } else if (this.useExponentialShadowMap || this.useBlurExponentialShadowMap) {\r\n defines[\"SHADOWESM\" + lightIndex] = true;\r\n } else if (this.useCloseExponentialShadowMap || this.useBlurCloseExponentialShadowMap) {\r\n defines[\"SHADOWCLOSEESM\" + lightIndex] = true;\r\n }\r\n\r\n if (light.needCube()) {\r\n defines[\"SHADOWCUBE\" + lightIndex] = true;\r\n }\r\n }\r\n\r\n /**\r\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\r\n * defined in the generator but impacting the effect).\r\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\r\n * @param effect The effect we are binding the information for\r\n */\r\n public bindShadowLight(lightIndex: string, effect: Effect): void {\r\n const light = this._light;\r\n const scene = this._scene;\r\n\r\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\r\n return;\r\n }\r\n\r\n const camera = this._getCamera();\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n const shadowMap = this.getShadowMap();\r\n\r\n if (!shadowMap) {\r\n return;\r\n }\r\n\r\n if (!light.needCube()) {\r\n effect.setMatrix(\"lightMatrix\" + lightIndex, this.getTransformMatrix());\r\n }\r\n\r\n // Only PCF uses depth stencil texture.\r\n if (this._filter === ShadowGenerator.FILTER_PCF) {\r\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, this.getShadowMapForRendering());\r\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), shadowMap.getSize().width, 1 / shadowMap.getSize().width, this.frustumEdgeFalloff, lightIndex);\r\n } else if (this._filter === ShadowGenerator.FILTER_PCSS) {\r\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, this.getShadowMapForRendering());\r\n effect.setTexture(\"depthSampler\" + lightIndex, this.getShadowMapForRendering());\r\n light._uniformBuffer.updateFloat4(\r\n \"shadowsInfo\",\r\n this.getDarkness(),\r\n 1 / shadowMap.getSize().width,\r\n this._contactHardeningLightSizeUVRatio * shadowMap.getSize().width,\r\n this.frustumEdgeFalloff,\r\n lightIndex\r\n );\r\n } else {\r\n effect.setTexture(\"shadowSampler\" + lightIndex, this.getShadowMapForRendering());\r\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), this.blurScale / shadowMap.getSize().width, this.depthScale, this.frustumEdgeFalloff, lightIndex);\r\n }\r\n\r\n light._uniformBuffer.updateFloat2(\r\n \"depthValues\",\r\n this.getLight().getDepthMinZ(camera),\r\n this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera),\r\n lightIndex\r\n );\r\n }\r\n\r\n /**\r\n * Gets the transformation matrix used to project the meshes into the map from the light point of view.\r\n * (eq to shadow projection matrix * light transform matrix)\r\n * @returns The transform matrix used to create the shadow map\r\n */\r\n public getTransformMatrix(): Matrix {\r\n const scene = this._scene;\r\n if (this._currentRenderId === scene.getRenderId() && this._currentFaceIndexCache === this._currentFaceIndex) {\r\n return this._transformMatrix;\r\n }\r\n\r\n this._currentRenderId = scene.getRenderId();\r\n this._currentFaceIndexCache = this._currentFaceIndex;\r\n\r\n let lightPosition = this._light.position;\r\n if (this._light.computeTransformedInformation()) {\r\n lightPosition = this._light.transformedPosition;\r\n }\r\n\r\n Vector3.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex), this._lightDirection);\r\n if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {\r\n this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\r\n }\r\n\r\n if (\r\n this._light.needProjectionMatrixCompute() ||\r\n !this._cachedPosition ||\r\n !this._cachedDirection ||\r\n !lightPosition.equals(this._cachedPosition) ||\r\n !this._lightDirection.equals(this._cachedDirection)\r\n ) {\r\n this._cachedPosition.copyFrom(lightPosition);\r\n this._cachedDirection.copyFrom(this._lightDirection);\r\n\r\n Matrix.LookAtLHToRef(lightPosition, lightPosition.add(this._lightDirection), Vector3.Up(), this._viewMatrix);\r\n\r\n const shadowMap = this.getShadowMap();\r\n\r\n if (shadowMap) {\r\n const renderList = shadowMap.renderList;\r\n\r\n if (renderList) {\r\n this._light.setShadowProjectionMatrix(this._projectionMatrix, this._viewMatrix, renderList);\r\n }\r\n }\r\n\r\n this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);\r\n }\r\n\r\n return this._transformMatrix;\r\n }\r\n\r\n /**\r\n * Recreates the shadow map dependencies like RTT and post processes. This can be used during the switch between\r\n * Cube and 2D textures for instance.\r\n */\r\n public recreateShadowMap(): void {\r\n const shadowMap = this._shadowMap;\r\n if (!shadowMap) {\r\n return;\r\n }\r\n\r\n // Track render list.\r\n const renderList = shadowMap.renderList;\r\n // Clean up existing data.\r\n this._disposeRTTandPostProcesses();\r\n // Reinitializes.\r\n this._initializeGenerator();\r\n // Reaffect the filter to ensure a correct fallback if necessary.\r\n this.filter = this._filter;\r\n // Reaffect the filter.\r\n this._applyFilterValues();\r\n // Reaffect Render List.\r\n if (renderList) {\r\n // Note: don't do this._shadowMap!.renderList = renderList;\r\n // The renderList hooked array is accessing the old RenderTargetTexture (see RenderTargetTexture._hookArray), which is disposed at this point (by the call to _disposeRTTandPostProcesses)\r\n if (!this._shadowMap!.renderList) {\r\n this._shadowMap!.renderList = [];\r\n }\r\n for (const mesh of renderList) {\r\n this._shadowMap!.renderList.push(mesh);\r\n }\r\n } else {\r\n this._shadowMap!.renderList = null;\r\n }\r\n }\r\n\r\n protected _disposeBlurPostProcesses(): void {\r\n if (this._shadowMap2) {\r\n this._shadowMap2.dispose();\r\n this._shadowMap2 = null;\r\n }\r\n\r\n if (this._boxBlurPostprocess) {\r\n this._boxBlurPostprocess.dispose();\r\n this._boxBlurPostprocess = null;\r\n }\r\n\r\n if (this._kernelBlurXPostprocess) {\r\n this._kernelBlurXPostprocess.dispose();\r\n this._kernelBlurXPostprocess = null;\r\n }\r\n\r\n if (this._kernelBlurYPostprocess) {\r\n this._kernelBlurYPostprocess.dispose();\r\n this._kernelBlurYPostprocess = null;\r\n }\r\n\r\n this._blurPostProcesses = [];\r\n }\r\n\r\n protected _disposeRTTandPostProcesses(): void {\r\n if (this._shadowMap) {\r\n this._shadowMap.dispose();\r\n this._shadowMap = null;\r\n }\r\n\r\n this._disposeBlurPostProcesses();\r\n }\r\n\r\n protected _disposeSceneUBOs(): void {\r\n if (this._sceneUBOs) {\r\n for (const ubo of this._sceneUBOs) {\r\n ubo.dispose();\r\n }\r\n this._sceneUBOs = [];\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the ShadowGenerator.\r\n * Returns nothing.\r\n */\r\n public dispose(): void {\r\n this._disposeRTTandPostProcesses();\r\n\r\n this._disposeSceneUBOs();\r\n\r\n if (this._light) {\r\n if (this._light._shadowGenerators) {\r\n const iterator = this._light._shadowGenerators.entries();\r\n for (let entry = iterator.next(); entry.done !== true; entry = iterator.next()) {\r\n const [camera, shadowGenerator] = entry.value;\r\n if (shadowGenerator === this) {\r\n this._light._shadowGenerators.delete(camera);\r\n }\r\n }\r\n if (this._light._shadowGenerators.size === 0) {\r\n this._light._shadowGenerators = null;\r\n }\r\n }\r\n this._light._markMeshesAsLightDirty();\r\n }\r\n\r\n this.onBeforeShadowMapRenderMeshObservable.clear();\r\n this.onBeforeShadowMapRenderObservable.clear();\r\n this.onAfterShadowMapRenderMeshObservable.clear();\r\n this.onAfterShadowMapRenderObservable.clear();\r\n }\r\n\r\n /**\r\n * Serializes the shadow generator setup to a json object.\r\n * @returns The serialized JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n const shadowMap = this.getShadowMap();\r\n\r\n if (!shadowMap) {\r\n return serializationObject;\r\n }\r\n\r\n serializationObject.className = this.getClassName();\r\n serializationObject.lightId = this._light.id;\r\n serializationObject.cameraId = this._camera?.id;\r\n serializationObject.id = this.id;\r\n serializationObject.mapSize = shadowMap.getRenderSize();\r\n serializationObject.forceBackFacesOnly = this.forceBackFacesOnly;\r\n serializationObject.darkness = this.getDarkness();\r\n serializationObject.transparencyShadow = this._transparencyShadow;\r\n serializationObject.frustumEdgeFalloff = this.frustumEdgeFalloff;\r\n serializationObject.bias = this.bias;\r\n serializationObject.normalBias = this.normalBias;\r\n serializationObject.usePercentageCloserFiltering = this.usePercentageCloserFiltering;\r\n serializationObject.useContactHardeningShadow = this.useContactHardeningShadow;\r\n serializationObject.contactHardeningLightSizeUVRatio = this.contactHardeningLightSizeUVRatio;\r\n serializationObject.filteringQuality = this.filteringQuality;\r\n serializationObject.useExponentialShadowMap = this.useExponentialShadowMap;\r\n serializationObject.useBlurExponentialShadowMap = this.useBlurExponentialShadowMap;\r\n serializationObject.useCloseExponentialShadowMap = this.useBlurExponentialShadowMap;\r\n serializationObject.useBlurCloseExponentialShadowMap = this.useBlurExponentialShadowMap;\r\n serializationObject.usePoissonSampling = this.usePoissonSampling;\r\n serializationObject.depthScale = this.depthScale;\r\n serializationObject.blurBoxOffset = this.blurBoxOffset;\r\n serializationObject.blurKernel = this.blurKernel;\r\n serializationObject.blurScale = this.blurScale;\r\n serializationObject.useKernelBlur = this.useKernelBlur;\r\n\r\n serializationObject.renderList = [];\r\n if (shadowMap.renderList) {\r\n for (let meshIndex = 0; meshIndex < shadowMap.renderList.length; meshIndex++) {\r\n const mesh = shadowMap.renderList[meshIndex];\r\n\r\n serializationObject.renderList.push(mesh.id);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parses a serialized ShadowGenerator and returns a new ShadowGenerator.\r\n * @param parsedShadowGenerator The JSON object to parse\r\n * @param scene The scene to create the shadow map for\r\n * @param constr A function that builds a shadow generator or undefined to create an instance of the default shadow generator\r\n * @returns The parsed shadow generator\r\n */\r\n public static Parse(parsedShadowGenerator: any, scene: Scene, constr?: (mapSize: number, light: IShadowLight, camera: Nullable) => ShadowGenerator): ShadowGenerator {\r\n const light = scene.getLightById(parsedShadowGenerator.lightId);\r\n const camera: Nullable = parsedShadowGenerator.cameraId !== undefined ? scene.getCameraById(parsedShadowGenerator.cameraId) : null;\r\n const shadowGenerator = constr ? constr(parsedShadowGenerator.mapSize, light, camera) : new ShadowGenerator(parsedShadowGenerator.mapSize, light, undefined, camera);\r\n const shadowMap = shadowGenerator.getShadowMap();\r\n\r\n for (let meshIndex = 0; meshIndex < parsedShadowGenerator.renderList.length; meshIndex++) {\r\n const meshes = scene.getMeshesById(parsedShadowGenerator.renderList[meshIndex]);\r\n meshes.forEach(function (mesh) {\r\n if (!shadowMap) {\r\n return;\r\n }\r\n if (!shadowMap.renderList) {\r\n shadowMap.renderList = [];\r\n }\r\n shadowMap.renderList.push(mesh);\r\n });\r\n }\r\n\r\n if (parsedShadowGenerator.id !== undefined) {\r\n shadowGenerator.id = parsedShadowGenerator.id;\r\n }\r\n\r\n shadowGenerator.forceBackFacesOnly = !!parsedShadowGenerator.forceBackFacesOnly;\r\n\r\n if (parsedShadowGenerator.darkness !== undefined) {\r\n shadowGenerator.setDarkness(parsedShadowGenerator.darkness);\r\n }\r\n\r\n if (parsedShadowGenerator.transparencyShadow) {\r\n shadowGenerator.setTransparencyShadow(true);\r\n }\r\n\r\n if (parsedShadowGenerator.frustumEdgeFalloff !== undefined) {\r\n shadowGenerator.frustumEdgeFalloff = parsedShadowGenerator.frustumEdgeFalloff;\r\n }\r\n\r\n if (parsedShadowGenerator.bias !== undefined) {\r\n shadowGenerator.bias = parsedShadowGenerator.bias;\r\n }\r\n\r\n if (parsedShadowGenerator.normalBias !== undefined) {\r\n shadowGenerator.normalBias = parsedShadowGenerator.normalBias;\r\n }\r\n\r\n if (parsedShadowGenerator.usePercentageCloserFiltering) {\r\n shadowGenerator.usePercentageCloserFiltering = true;\r\n } else if (parsedShadowGenerator.useContactHardeningShadow) {\r\n shadowGenerator.useContactHardeningShadow = true;\r\n } else if (parsedShadowGenerator.usePoissonSampling) {\r\n shadowGenerator.usePoissonSampling = true;\r\n } else if (parsedShadowGenerator.useExponentialShadowMap) {\r\n shadowGenerator.useExponentialShadowMap = true;\r\n } else if (parsedShadowGenerator.useBlurExponentialShadowMap) {\r\n shadowGenerator.useBlurExponentialShadowMap = true;\r\n } else if (parsedShadowGenerator.useCloseExponentialShadowMap) {\r\n shadowGenerator.useCloseExponentialShadowMap = true;\r\n } else if (parsedShadowGenerator.useBlurCloseExponentialShadowMap) {\r\n shadowGenerator.useBlurCloseExponentialShadowMap = true;\r\n }\r\n // Backward compat\r\n else if (parsedShadowGenerator.useVarianceShadowMap) {\r\n shadowGenerator.useExponentialShadowMap = true;\r\n } else if (parsedShadowGenerator.useBlurVarianceShadowMap) {\r\n shadowGenerator.useBlurExponentialShadowMap = true;\r\n }\r\n\r\n if (parsedShadowGenerator.contactHardeningLightSizeUVRatio !== undefined) {\r\n shadowGenerator.contactHardeningLightSizeUVRatio = parsedShadowGenerator.contactHardeningLightSizeUVRatio;\r\n }\r\n\r\n if (parsedShadowGenerator.filteringQuality !== undefined) {\r\n shadowGenerator.filteringQuality = parsedShadowGenerator.filteringQuality;\r\n }\r\n\r\n if (parsedShadowGenerator.depthScale) {\r\n shadowGenerator.depthScale = parsedShadowGenerator.depthScale;\r\n }\r\n\r\n if (parsedShadowGenerator.blurScale) {\r\n shadowGenerator.blurScale = parsedShadowGenerator.blurScale;\r\n }\r\n\r\n if (parsedShadowGenerator.blurBoxOffset) {\r\n shadowGenerator.blurBoxOffset = parsedShadowGenerator.blurBoxOffset;\r\n }\r\n\r\n if (parsedShadowGenerator.useKernelBlur) {\r\n shadowGenerator.useKernelBlur = parsedShadowGenerator.useKernelBlur;\r\n }\r\n\r\n if (parsedShadowGenerator.blurKernel) {\r\n shadowGenerator.blurKernel = parsedShadowGenerator.blurKernel;\r\n }\r\n\r\n return shadowGenerator;\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/packingFunctions\";\nimport \"./ShadersInclude/clipPlaneFragment\";\n\nconst name = \"depthPixelShader\";\nconst shader = `#ifdef ALPHATEST\nvarying vec2 vUV;uniform sampler2D diffuseSampler;\n#endif\n#include\nvarying float vDepthMetric;\n#ifdef PACKED\n#include\n#endif\n#ifdef STORE_CAMERASPACE_Z\nvarying vec4 vViewPos;\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#include\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#ifdef STORE_CAMERASPACE_Z\n#ifdef PACKED\ngl_FragColor=pack(vViewPos.z);\n#else\ngl_FragColor=vec4(vViewPos.z,0.0,0.0,1.0);\n#endif\n#else\n#ifdef NONLINEARDEPTH\n#ifdef PACKED\ngl_FragColor=pack(gl_FragCoord.z);\n#else\ngl_FragColor=vec4(gl_FragCoord.z,0.0,0.0,0.0);\n#endif\n#else\n#ifdef PACKED\ngl_FragColor=pack(vDepthMetric);\n#else\ngl_FragColor=vec4(vDepthMetric,0.0,0.0,1.0);\n#endif\n#endif\n#endif\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const depthPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobal\";\nimport \"./ShadersInclude/morphTargetsVertex\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/clipPlaneVertex\";\n\nconst name = \"depthVertexShader\";\nconst shader = `attribute vec3 position;\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\nuniform mat4 viewProjection;uniform vec2 depthValues;\n#if defined(ALPHATEST) || defined(NEED_UV)\nvarying vec2 vUV;uniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#ifdef STORE_CAMERASPACE_Z\nuniform mat4 view;varying vec4 vViewPos;\n#endif\nvarying float vDepthMetric;\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n#include\ngl_Position=viewProjection*worldPos;\n#ifdef STORE_CAMERASPACE_Z\nvViewPos=view*worldPos;\n#else\n#ifdef USE_REVERSE_DEPTHBUFFER\nvDepthMetric=((-gl_Position.z+depthValues.x)/(depthValues.y));\n#else\nvDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));\n#endif\n#endif\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const depthVertexShader = { name, shader };\n","import type { Nullable } from \"../types\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { MaterialHelper } from \"../Materials/materialHelper\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\nimport \"../Shaders/depth.fragment\";\r\nimport \"../Shaders/depth.vertex\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport { addClipPlaneUniforms, bindClipPlane, prepareStringDefinesForClipPlanes } from \"../Materials/clipPlaneMaterialHelper\";\r\n\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n\r\n/**\r\n * This represents a depth renderer in Babylon.\r\n * A depth renderer will render to it's depth map every frame which can be displayed or used in post processing\r\n */\r\nexport class DepthRenderer {\r\n private _scene: Scene;\r\n private _depthMap: RenderTargetTexture;\r\n private readonly _storeNonLinearDepth: boolean;\r\n private readonly _storeCameraSpaceZ: boolean;\r\n\r\n /** Color used to clear the depth texture. Default: (1,0,0,1) */\r\n public clearColor: Color4;\r\n\r\n /** Get if the depth renderer is using packed depth or not */\r\n public readonly isPacked: boolean;\r\n\r\n private _camera: Nullable;\r\n\r\n /** Enable or disable the depth renderer. When disabled, the depth texture is not updated */\r\n public enabled = true;\r\n\r\n /** Force writing the transparent objects into the depth map */\r\n public forceDepthWriteTransparentMeshes = false;\r\n\r\n /**\r\n * Specifies that the depth renderer will only be used within\r\n * the camera it is created for.\r\n * This can help forcing its rendering during the camera processing.\r\n */\r\n public useOnlyInActiveCamera: boolean = false;\r\n\r\n /** If true, reverse the culling of materials before writing to the depth texture.\r\n * So, basically, when \"true\", back facing instead of front facing faces are rasterized into the texture\r\n */\r\n public reverseCulling = false;\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {\r\n throw _WarnImport(\"DepthRendererSceneComponent\");\r\n };\r\n\r\n /**\r\n * Sets a specific material to be used to render a mesh/a list of meshes by the depth renderer\r\n * @param mesh mesh or array of meshes\r\n * @param material material to use by the depth render when rendering the mesh(es). If undefined is passed, the specific material created by the depth renderer will be used.\r\n */\r\n public setMaterialForRendering(mesh: AbstractMesh | AbstractMesh[], material?: Material): void {\r\n this._depthMap.setMaterialForRendering(mesh, material);\r\n }\r\n\r\n /**\r\n * Instantiates a depth renderer\r\n * @param scene The scene the renderer belongs to\r\n * @param type The texture type of the depth map (default: Engine.TEXTURETYPE_FLOAT)\r\n * @param camera The camera to be used to render the depth map (default: scene's active camera)\r\n * @param storeNonLinearDepth Defines whether the depth is stored linearly like in Babylon Shadows or directly like glFragCoord.z\r\n * @param samplingMode The sampling mode to be used with the render target (Linear, Nearest...) (default: TRILINEAR_SAMPLINGMODE)\r\n * @param storeCameraSpaceZ Defines whether the depth stored is the Z coordinate in camera space. If true, storeNonLinearDepth has no effect. (Default: false)\r\n * @param name Name of the render target (default: DepthRenderer)\r\n */\r\n constructor(\r\n scene: Scene,\r\n type: number = Constants.TEXTURETYPE_FLOAT,\r\n camera: Nullable = null,\r\n storeNonLinearDepth = false,\r\n samplingMode = Texture.TRILINEAR_SAMPLINGMODE,\r\n storeCameraSpaceZ = false,\r\n name?: string\r\n ) {\r\n this._scene = scene;\r\n this._storeNonLinearDepth = storeNonLinearDepth;\r\n this._storeCameraSpaceZ = storeCameraSpaceZ;\r\n this.isPacked = type === Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (this.isPacked) {\r\n this.clearColor = new Color4(1.0, 1.0, 1.0, 1.0);\r\n } else {\r\n this.clearColor = new Color4(storeCameraSpaceZ ? 1e8 : 1.0, 0.0, 0.0, 1.0);\r\n }\r\n\r\n DepthRenderer._SceneComponentInitialization(this._scene);\r\n\r\n const engine = scene.getEngine();\r\n\r\n this._camera = camera;\r\n\r\n if (samplingMode !== Texture.NEAREST_SAMPLINGMODE) {\r\n if (type === Constants.TEXTURETYPE_FLOAT && !engine._caps.textureFloatLinearFiltering) {\r\n samplingMode = Texture.NEAREST_SAMPLINGMODE;\r\n }\r\n if (type === Constants.TEXTURETYPE_HALF_FLOAT && !engine._caps.textureHalfFloatLinearFiltering) {\r\n samplingMode = Texture.NEAREST_SAMPLINGMODE;\r\n }\r\n }\r\n\r\n // Render target\r\n const format = this.isPacked || !engine._features.supportExtendedTextureFormats ? Constants.TEXTUREFORMAT_RGBA : Constants.TEXTUREFORMAT_R;\r\n this._depthMap = new RenderTargetTexture(\r\n name ?? \"DepthRenderer\",\r\n { width: engine.getRenderWidth(), height: engine.getRenderHeight() },\r\n this._scene,\r\n false,\r\n true,\r\n type,\r\n false,\r\n samplingMode,\r\n undefined,\r\n undefined,\r\n undefined,\r\n format\r\n );\r\n this._depthMap.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this._depthMap.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n this._depthMap.refreshRate = 1;\r\n this._depthMap.renderParticles = false;\r\n this._depthMap.renderList = null;\r\n this._depthMap.noPrePassRenderer = true;\r\n\r\n // Camera to get depth map from to support multiple concurrent cameras\r\n this._depthMap.activeCamera = this._camera;\r\n this._depthMap.ignoreCameraViewport = true;\r\n this._depthMap.useCameraPostProcesses = false;\r\n\r\n // set default depth value to 1.0 (far away)\r\n this._depthMap.onClearObservable.add((engine) => {\r\n engine.clear(this.clearColor, true, true, true);\r\n });\r\n\r\n this._depthMap.onBeforeBindObservable.add(() => {\r\n engine._debugPushGroup?.(\"depth renderer\", 1);\r\n });\r\n\r\n this._depthMap.onAfterUnbindObservable.add(() => {\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n this._depthMap.customIsReadyFunction = (mesh: AbstractMesh, refreshRate: number, preWarm?: boolean) => {\r\n if ((preWarm || refreshRate === 0) && mesh.subMeshes) {\r\n for (let i = 0; i < mesh.subMeshes.length; ++i) {\r\n const subMesh = mesh.subMeshes[i];\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\r\n const hardwareInstancedRendering =\r\n engine.getCaps().instancedArrays &&\r\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || renderingMesh.hasThinInstances);\r\n\r\n if (!this.isReady(subMesh, hardwareInstancedRendering)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n };\r\n\r\n // Custom render function\r\n const renderSubMesh = (subMesh: SubMesh): void => {\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n const effectiveMesh = subMesh.getEffectiveMesh();\r\n const scene = this._scene;\r\n const engine = scene.getEngine();\r\n const material = subMesh.getMaterial();\r\n\r\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n\r\n if (!material || effectiveMesh.infiniteDistance || material.disableDepthWrite || subMesh.verticesCount === 0 || subMesh._renderId === scene.getRenderId()) {\r\n return;\r\n }\r\n\r\n // Culling\r\n const detNeg = effectiveMesh._getWorldMatrixDeterminant() < 0;\r\n let sideOrientation = renderingMesh.overrideMaterialSideOrientation ?? material.sideOrientation;\r\n if (detNeg) {\r\n sideOrientation =\r\n sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation\r\n ? Constants.MATERIAL_CounterClockWiseSideOrientation\r\n : Constants.MATERIAL_ClockWiseSideOrientation;\r\n }\r\n const reverseSideOrientation = sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation;\r\n\r\n engine.setState(material.backFaceCulling, 0, false, reverseSideOrientation, this.reverseCulling ? !material.cullBackFaces : material.cullBackFaces);\r\n\r\n // Managing instances\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\r\n\r\n if (batch.mustReturn) {\r\n return;\r\n }\r\n\r\n const hardwareInstancedRendering =\r\n engine.getCaps().instancedArrays &&\r\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || renderingMesh.hasThinInstances);\r\n\r\n const camera = this._camera || scene.activeCamera;\r\n if (this.isReady(subMesh, hardwareInstancedRendering) && camera) {\r\n subMesh._renderId = scene.getRenderId();\r\n\r\n const renderingMaterial = effectiveMesh._internalAbstractMeshDataInfo._materialForRenderPass?.[engine.currentRenderPassId];\r\n\r\n let drawWrapper = subMesh._getDrawWrapper();\r\n if (!drawWrapper && renderingMaterial) {\r\n drawWrapper = renderingMaterial._getDrawWrapper();\r\n }\r\n const cameraIsOrtho = camera.mode === Camera.ORTHOGRAPHIC_CAMERA;\r\n\r\n if (!drawWrapper) {\r\n return;\r\n }\r\n\r\n const effect = drawWrapper.effect!;\r\n\r\n engine.enableEffect(drawWrapper);\r\n\r\n if (!hardwareInstancedRendering) {\r\n renderingMesh._bind(subMesh, effect, material.fillMode);\r\n }\r\n\r\n if (!renderingMaterial) {\r\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n effect.setMatrix(\"world\", effectiveMesh.getWorldMatrix());\r\n if (this._storeCameraSpaceZ) {\r\n effect.setMatrix(\"view\", scene.getViewMatrix());\r\n }\r\n } else {\r\n renderingMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), effectiveMesh as Mesh, subMesh);\r\n }\r\n\r\n let minZ: number, maxZ: number;\r\n\r\n if (cameraIsOrtho) {\r\n minZ = !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n maxZ = engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n } else {\r\n minZ = engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? camera.minZ : engine.isNDCHalfZRange ? 0 : camera.minZ;\r\n maxZ = engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : camera.maxZ;\r\n }\r\n\r\n effect.setFloat2(\"depthValues\", minZ, minZ + maxZ);\r\n\r\n if (!renderingMaterial) {\r\n // Alpha test\r\n if (material.needAlphaTesting()) {\r\n const alphaTexture = material.getAlphaTestTexture();\r\n\r\n if (alphaTexture) {\r\n effect.setTexture(\"diffuseSampler\", alphaTexture);\r\n effect.setMatrix(\"diffuseMatrix\", alphaTexture.getTextureMatrix());\r\n }\r\n }\r\n\r\n // Bones\r\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\r\n const skeleton = renderingMesh.skeleton;\r\n\r\n if (skeleton.isUsingTextureForMatrices) {\r\n const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);\r\n if (!boneTexture) {\r\n return;\r\n }\r\n\r\n effect.setTexture(\"boneSampler\", boneTexture);\r\n effect.setFloat(\"boneTextureWidth\", 4.0 * (skeleton.bones.length + 1));\r\n } else {\r\n effect.setMatrices(\"mBones\", skeleton.getTransformMatrices(renderingMesh));\r\n }\r\n }\r\n\r\n // Clip planes\r\n bindClipPlane(effect, material, scene);\r\n\r\n // Morph targets\r\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\r\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\r\n renderingMesh.morphTargetManager._bind(effect);\r\n }\r\n }\r\n\r\n // Draw\r\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) =>\r\n effect.setMatrix(\"world\", world)\r\n );\r\n }\r\n };\r\n\r\n this._depthMap.customRenderFunction = (\r\n opaqueSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray\r\n ): void => {\r\n let index;\r\n\r\n if (depthOnlySubMeshes.length) {\r\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\r\n renderSubMesh(depthOnlySubMeshes.data[index]);\r\n }\r\n }\r\n\r\n for (index = 0; index < opaqueSubMeshes.length; index++) {\r\n renderSubMesh(opaqueSubMeshes.data[index]);\r\n }\r\n\r\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\r\n renderSubMesh(alphaTestSubMeshes.data[index]);\r\n }\r\n\r\n if (this.forceDepthWriteTransparentMeshes) {\r\n for (index = 0; index < transparentSubMeshes.length; index++) {\r\n renderSubMesh(transparentSubMeshes.data[index]);\r\n }\r\n } else {\r\n for (index = 0; index < transparentSubMeshes.length; index++) {\r\n transparentSubMeshes.data[index].getEffectiveMesh()._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n }\r\n }\r\n };\r\n }\r\n\r\n /**\r\n * Creates the depth rendering effect and checks if the effect is ready.\r\n * @param subMesh The submesh to be used to render the depth map of\r\n * @param useInstances If multiple world instances should be used\r\n * @returns if the depth renderer is ready to render the depth map\r\n */\r\n public isReady(subMesh: SubMesh, useInstances: boolean): boolean {\r\n const engine = this._scene.getEngine();\r\n const mesh = subMesh.getMesh();\r\n const scene = mesh.getScene();\r\n\r\n const renderingMaterial = mesh._internalAbstractMeshDataInfo._materialForRenderPass?.[engine.currentRenderPassId];\r\n\r\n if (renderingMaterial) {\r\n return renderingMaterial.isReadyForSubMesh(mesh, subMesh, useInstances);\r\n }\r\n\r\n const material = subMesh.getMaterial();\r\n if (!material || material.disableDepthWrite) {\r\n return false;\r\n }\r\n\r\n const defines = [];\r\n\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n // Alpha test\r\n if (material && material.needAlphaTesting() && material.getAlphaTestTexture()) {\r\n defines.push(\"#define ALPHATEST\");\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n attribs.push(VertexBuffer.UVKind);\r\n defines.push(\"#define UV1\");\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\r\n attribs.push(VertexBuffer.UV2Kind);\r\n defines.push(\"#define UV2\");\r\n }\r\n }\r\n\r\n // Bones\r\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n defines.push(\"#define BonesPerMesh \" + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));\r\n\r\n const skeleton = subMesh.getRenderingMesh().skeleton;\r\n\r\n if (skeleton?.isUsingTextureForMatrices) {\r\n defines.push(\"#define BONETEXTURE\");\r\n }\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph targets\r\n const morphTargetManager = (mesh as Mesh).morphTargetManager;\r\n let numMorphInfluencers = 0;\r\n if (morphTargetManager) {\r\n if (morphTargetManager.numInfluencers > 0) {\r\n numMorphInfluencers = morphTargetManager.numInfluencers;\r\n\r\n defines.push(\"#define MORPHTARGETS\");\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numMorphInfluencers);\r\n\r\n if (morphTargetManager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, numMorphInfluencers);\r\n }\r\n }\r\n\r\n // Instances\r\n if (useInstances) {\r\n defines.push(\"#define INSTANCES\");\r\n MaterialHelper.PushAttributesForInstances(attribs);\r\n if (subMesh.getRenderingMesh().hasThinInstances) {\r\n defines.push(\"#define THIN_INSTANCES\");\r\n }\r\n }\r\n\r\n // None linear depth\r\n if (this._storeNonLinearDepth) {\r\n defines.push(\"#define NONLINEARDEPTH\");\r\n }\r\n\r\n // Store camera space Z coordinate instead of NDC Z\r\n if (this._storeCameraSpaceZ) {\r\n defines.push(\"#define STORE_CAMERASPACE_Z\");\r\n }\r\n\r\n // Float Mode\r\n if (this.isPacked) {\r\n defines.push(\"#define PACKED\");\r\n }\r\n\r\n // Clip planes\r\n prepareStringDefinesForClipPlanes(material, scene, defines);\r\n\r\n // Get correct effect\r\n const drawWrapper = subMesh._getDrawWrapper(undefined, true)!;\r\n const cachedDefines = drawWrapper.defines;\r\n const join = defines.join(\"\\n\");\r\n if (cachedDefines !== join) {\r\n const uniforms = [\r\n \"world\",\r\n \"mBones\",\r\n \"boneTextureWidth\",\r\n \"viewProjection\",\r\n \"view\",\r\n \"diffuseMatrix\",\r\n \"depthValues\",\r\n \"morphTargetInfluences\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n ];\r\n addClipPlaneUniforms(uniforms);\r\n\r\n drawWrapper.setEffect(\r\n engine.createEffect(\"depth\", attribs, uniforms, [\"diffuseSampler\", \"morphTargets\", \"boneSampler\"], join, undefined, undefined, undefined, {\r\n maxSimultaneousMorphTargets: numMorphInfluencers,\r\n }),\r\n join\r\n );\r\n }\r\n\r\n return drawWrapper.effect!.isReady();\r\n }\r\n\r\n /**\r\n * Gets the texture which the depth map will be written to.\r\n * @returns The depth map texture\r\n */\r\n public getDepthMap(): RenderTargetTexture {\r\n return this._depthMap;\r\n }\r\n\r\n /**\r\n * Disposes of the depth renderer.\r\n */\r\n public dispose(): void {\r\n const keysToDelete = [];\r\n for (const key in this._scene._depthRenderer) {\r\n const depthRenderer = this._scene._depthRenderer[key];\r\n if (depthRenderer === this) {\r\n keysToDelete.push(key);\r\n }\r\n }\r\n\r\n if (keysToDelete.length > 0) {\r\n this._depthMap.dispose();\r\n\r\n for (const key of keysToDelete) {\r\n delete this._scene._depthRenderer[key];\r\n }\r\n }\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"minmaxReduxPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;\n#if defined(INITIAL)\nuniform sampler2D sourceTexture;uniform vec2 texSize;void main(void)\n{ivec2 coord=ivec2(vUV*(texSize-1.0));float f1=texelFetch(sourceTexture,coord,0).r;float f2=texelFetch(sourceTexture,coord+ivec2(1,0),0).r;float f3=texelFetch(sourceTexture,coord+ivec2(1,1),0).r;float f4=texelFetch(sourceTexture,coord+ivec2(0,1),0).r;float minz=min(min(min(f1,f2),f3),f4);\n#ifdef DEPTH_REDUX\nfloat maxz=max(max(max(sign(1.0-f1)*f1,sign(1.0-f2)*f2),sign(1.0-f3)*f3),sign(1.0-f4)*f4);\n#else\nfloat maxz=max(max(max(f1,f2),f3),f4);\n#endif\nglFragColor=vec4(minz,maxz,0.,0.);}\n#elif defined(MAIN)\nuniform vec2 texSize;void main(void)\n{ivec2 coord=ivec2(vUV*(texSize-1.0));vec2 f1=texelFetch(textureSampler,coord,0).rg;vec2 f2=texelFetch(textureSampler,coord+ivec2(1,0),0).rg;vec2 f3=texelFetch(textureSampler,coord+ivec2(1,1),0).rg;vec2 f4=texelFetch(textureSampler,coord+ivec2(0,1),0).rg;float minz=min(min(min(f1.x,f2.x),f3.x),f4.x);float maxz=max(max(max(f1.y,f2.y),f3.y),f4.y);glFragColor=vec4(minz,maxz,0.,0.);}\n#elif defined(ONEBEFORELAST)\nuniform ivec2 texSize;void main(void)\n{ivec2 coord=ivec2(vUV*vec2(texSize-1));vec2 f1=texelFetch(textureSampler,coord % texSize,0).rg;vec2 f2=texelFetch(textureSampler,(coord+ivec2(1,0)) % texSize,0).rg;vec2 f3=texelFetch(textureSampler,(coord+ivec2(1,1)) % texSize,0).rg;vec2 f4=texelFetch(textureSampler,(coord+ivec2(0,1)) % texSize,0).rg;float minz=min(f1.x,f2.x);float maxz=max(f1.y,f2.y);glFragColor=vec4(minz,maxz,0.,0.);}\n#elif defined(LAST)\nvoid main(void)\n{glFragColor=vec4(0.);if (true) { \ndiscard;}}\n#endif\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const minmaxReduxPixelShader = { name, shader };\n","import type { Nullable } from \"../types\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { DepthRenderer } from \"../Rendering/depthRenderer\";\r\n\r\nimport { MinMaxReducer } from \"./minMaxReducer\";\r\n\r\n/**\r\n * This class is a small wrapper around the MinMaxReducer class to compute the min/max values of a depth texture\r\n */\r\nexport class DepthReducer extends MinMaxReducer {\r\n private _depthRenderer: Nullable;\r\n private _depthRendererId: string;\r\n\r\n /**\r\n * Gets the depth renderer used for the computation.\r\n * Note that the result is null if you provide your own renderer when calling setDepthRenderer.\r\n */\r\n public get depthRenderer(): Nullable {\r\n return this._depthRenderer;\r\n }\r\n\r\n /**\r\n * Creates a depth reducer\r\n * @param camera The camera used to render the depth texture\r\n */\r\n constructor(camera: Camera) {\r\n super(camera);\r\n }\r\n\r\n /**\r\n * Sets the depth renderer to use to generate the depth map\r\n * @param depthRenderer The depth renderer to use. If not provided, a new one will be created automatically\r\n * @param type The texture type of the depth map (default: TEXTURETYPE_HALF_FLOAT)\r\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\r\n */\r\n public setDepthRenderer(depthRenderer: Nullable = null, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n const scene = this._camera.getScene();\r\n\r\n if (this._depthRenderer) {\r\n delete scene._depthRenderer[this._depthRendererId];\r\n\r\n this._depthRenderer.dispose();\r\n this._depthRenderer = null;\r\n }\r\n\r\n if (depthRenderer === null) {\r\n if (!scene._depthRenderer) {\r\n scene._depthRenderer = {};\r\n }\r\n\r\n depthRenderer = this._depthRenderer = new DepthRenderer(scene, type, this._camera, false, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n depthRenderer.enabled = false;\r\n\r\n this._depthRendererId = \"minmax\" + this._camera.id;\r\n scene._depthRenderer[this._depthRendererId] = depthRenderer;\r\n }\r\n\r\n super.setSourceTexture(depthRenderer.getDepthMap(), true, type, forceFullscreenViewport);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public setSourceTexture(sourceTexture: RenderTargetTexture, depthRedux: boolean, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n super.setSourceTexture(sourceTexture, depthRedux, type, forceFullscreenViewport);\r\n }\r\n\r\n /**\r\n * Activates the reduction computation.\r\n * When activated, the observers registered in onAfterReductionPerformed are\r\n * called after the computation is performed\r\n */\r\n public activate(): void {\r\n if (this._depthRenderer) {\r\n this._depthRenderer.enabled = true;\r\n }\r\n\r\n super.activate();\r\n }\r\n\r\n /**\r\n * Deactivates the reduction computation.\r\n */\r\n public deactivate(): void {\r\n super.deactivate();\r\n\r\n if (this._depthRenderer) {\r\n this._depthRenderer.enabled = false;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the depth reducer\r\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\r\n */\r\n public dispose(disposeAll = true): void {\r\n super.dispose(disposeAll);\r\n\r\n if (this._depthRenderer && disposeAll) {\r\n const scene = this._depthRenderer.getDepthMap().getScene();\r\n if (scene) {\r\n delete scene._depthRenderer[this._depthRendererId];\r\n }\r\n\r\n this._depthRenderer.dispose();\r\n this._depthRenderer = null;\r\n }\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"./observable\";\r\nimport { Observable } from \"./observable\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { PostProcessManager } from \"../PostProcesses/postProcessManager\";\r\n\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\n\r\nimport \"../Shaders/minmaxRedux.fragment\";\r\n\r\n/**\r\n * This class computes a min/max reduction from a texture: it means it computes the minimum\r\n * and maximum values from all values of the texture.\r\n * It is performed on the GPU for better performances, thanks to a succession of post processes.\r\n * The source values are read from the red channel of the texture.\r\n */\r\nexport class MinMaxReducer {\r\n /**\r\n * Observable triggered when the computation has been performed\r\n */\r\n public onAfterReductionPerformed = new Observable<{ min: number; max: number }>();\r\n\r\n protected _camera: Camera;\r\n protected _sourceTexture: Nullable;\r\n protected _reductionSteps: Nullable>;\r\n protected _postProcessManager: PostProcessManager;\r\n protected _onAfterUnbindObserver: Nullable>;\r\n protected _forceFullscreenViewport = true;\r\n protected _onContextRestoredObserver: Nullable>;\r\n\r\n /**\r\n * Creates a min/max reducer\r\n * @param camera The camera to use for the post processes\r\n */\r\n constructor(camera: Camera) {\r\n this._camera = camera;\r\n this._postProcessManager = new PostProcessManager(camera.getScene());\r\n\r\n this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {\r\n this._postProcessManager._rebuild();\r\n });\r\n }\r\n\r\n /**\r\n * Gets the texture used to read the values from.\r\n */\r\n public get sourceTexture(): Nullable {\r\n return this._sourceTexture;\r\n }\r\n\r\n /**\r\n * Sets the source texture to read the values from.\r\n * One must indicate if the texture is a depth texture or not through the depthRedux parameter\r\n * because in such textures '1' value must not be taken into account to compute the maximum\r\n * as this value is used to clear the texture.\r\n * Note that the computation is not activated by calling this function, you must call activate() for that!\r\n * @param sourceTexture The texture to read the values from. The values should be in the red channel.\r\n * @param depthRedux Indicates if the texture is a depth texture or not\r\n * @param type The type of the textures created for the reduction (defaults to TEXTURETYPE_HALF_FLOAT)\r\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\r\n */\r\n public setSourceTexture(sourceTexture: RenderTargetTexture, depthRedux: boolean, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n if (sourceTexture === this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this.dispose(false);\r\n\r\n this._sourceTexture = sourceTexture;\r\n this._reductionSteps = [];\r\n this._forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n const scene = this._camera.getScene();\r\n\r\n // create the first step\r\n const reductionInitial = new PostProcess(\r\n \"Initial reduction phase\",\r\n \"minmaxRedux\", // shader\r\n [\"texSize\"],\r\n [\"sourceTexture\"], // textures\r\n 1.0, // options\r\n null, // camera\r\n Constants.TEXTURE_NEAREST_NEAREST, // sampling\r\n scene.getEngine(), // engine\r\n false, // reusable\r\n \"#define INITIAL\" + (depthRedux ? \"\\n#define DEPTH_REDUX\" : \"\"), // defines\r\n type,\r\n undefined,\r\n undefined,\r\n undefined,\r\n Constants.TEXTUREFORMAT_RG\r\n );\r\n\r\n reductionInitial.autoClear = false;\r\n reductionInitial.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n let w = this._sourceTexture.getRenderWidth(),\r\n h = this._sourceTexture.getRenderHeight();\r\n\r\n reductionInitial.onApply = ((w: number, h: number) => {\r\n return (effect: Effect) => {\r\n effect.setTexture(\"sourceTexture\", this._sourceTexture);\r\n effect.setFloat2(\"texSize\", w, h);\r\n };\r\n })(w, h);\r\n\r\n this._reductionSteps.push(reductionInitial);\r\n\r\n let index = 1;\r\n\r\n // create the additional steps\r\n while (w > 1 || h > 1) {\r\n w = Math.max(Math.round(w / 2), 1);\r\n h = Math.max(Math.round(h / 2), 1);\r\n\r\n const reduction = new PostProcess(\r\n \"Reduction phase \" + index,\r\n \"minmaxRedux\", // shader\r\n [\"texSize\"],\r\n null,\r\n { width: w, height: h }, // options\r\n null, // camera\r\n Constants.TEXTURE_NEAREST_NEAREST, // sampling\r\n scene.getEngine(), // engine\r\n false, // reusable\r\n \"#define \" + (w == 1 && h == 1 ? \"LAST\" : w == 1 || h == 1 ? \"ONEBEFORELAST\" : \"MAIN\"), // defines\r\n type,\r\n undefined,\r\n undefined,\r\n undefined,\r\n Constants.TEXTUREFORMAT_RG\r\n );\r\n\r\n reduction.autoClear = false;\r\n reduction.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n reduction.onApply = ((w: number, h: number) => {\r\n return (effect: Effect) => {\r\n if (w == 1 || h == 1) {\r\n effect.setInt2(\"texSize\", w, h);\r\n } else {\r\n effect.setFloat2(\"texSize\", w, h);\r\n }\r\n };\r\n })(w, h);\r\n\r\n this._reductionSteps.push(reduction);\r\n\r\n index++;\r\n\r\n if (w == 1 && h == 1) {\r\n const func = (w: number, h: number, reduction: PostProcess) => {\r\n const buffer = new Float32Array(4 * w * h),\r\n minmax = { min: 0, max: 0 };\r\n return () => {\r\n scene.getEngine()._readTexturePixels(reduction.inputTexture.texture!, w, h, -1, 0, buffer, false);\r\n minmax.min = buffer[0];\r\n minmax.max = buffer[1];\r\n this.onAfterReductionPerformed.notifyObservers(minmax);\r\n };\r\n };\r\n reduction.onAfterRenderObservable.add(func(w, h, reduction));\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Defines the refresh rate of the computation.\r\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\r\n */\r\n public get refreshRate(): number {\r\n return this._sourceTexture ? this._sourceTexture.refreshRate : -1;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n if (this._sourceTexture) {\r\n this._sourceTexture.refreshRate = value;\r\n }\r\n }\r\n\r\n protected _activated = false;\r\n\r\n /**\r\n * Gets the activation status of the reducer\r\n */\r\n public get activated(): boolean {\r\n return this._activated;\r\n }\r\n\r\n /**\r\n * Activates the reduction computation.\r\n * When activated, the observers registered in onAfterReductionPerformed are\r\n * called after the computation is performed\r\n */\r\n public activate(): void {\r\n if (this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._onAfterUnbindObserver = this._sourceTexture.onAfterUnbindObservable.add(() => {\r\n const engine = this._camera.getScene().getEngine();\r\n engine._debugPushGroup?.(`min max reduction`, 1);\r\n this._reductionSteps![0].activate(this._camera);\r\n this._postProcessManager.directRender(this._reductionSteps!, this._reductionSteps![0].inputTexture, this._forceFullscreenViewport);\r\n engine.unBindFramebuffer(this._reductionSteps![0].inputTexture, false);\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n this._activated = true;\r\n }\r\n\r\n /**\r\n * Deactivates the reduction computation.\r\n */\r\n public deactivate(): void {\r\n if (!this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._sourceTexture.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\r\n this._onAfterUnbindObserver = null;\r\n this._activated = false;\r\n }\r\n\r\n /**\r\n * Disposes the min/max reducer\r\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\r\n */\r\n public dispose(disposeAll = true): void {\r\n if (disposeAll) {\r\n this.onAfterReductionPerformed.clear();\r\n\r\n if (this._onContextRestoredObserver) {\r\n this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n\r\n this.deactivate();\r\n\r\n if (this._reductionSteps) {\r\n for (let i = 0; i < this._reductionSteps.length; ++i) {\r\n this._reductionSteps[i].dispose();\r\n }\r\n this._reductionSteps = null;\r\n }\r\n\r\n if (this._postProcessManager && disposeAll) {\r\n this._postProcessManager.dispose();\r\n }\r\n\r\n this._sourceTexture = null;\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\n\r\nimport type { IShadowLight } from \"../../Lights/shadowLight\";\r\nimport type { Effect } from \"../../Materials/effect\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\n\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\nimport \"../../Shaders/shadowMap.fragment\";\r\nimport \"../../Shaders/shadowMap.vertex\";\r\nimport \"../../Shaders/depthBoxBlur.fragment\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport { ShadowGenerator } from \"./shadowGenerator\";\r\nimport type { DirectionalLight } from \"../directionalLight\";\r\n\r\nimport { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { DepthRenderer } from \"../../Rendering/depthRenderer\";\r\nimport { DepthReducer } from \"../../Misc/depthReducer\";\r\n\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\n\r\ninterface ICascade {\r\n prevBreakDistance: number;\r\n breakDistance: number;\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst UpDir = Vector3.Up();\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst ZeroVec = Vector3.Zero();\r\n\r\nconst tmpv1 = new Vector3(),\r\n tmpv2 = new Vector3(),\r\n tmpMatrix = new Matrix();\r\n\r\n/**\r\n * A CSM implementation allowing casting shadows on large scenes.\r\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\r\n * Based on: https://github.com/TheRealMJP/Shadows and https://johanmedestrom.wordpress.com/2016/03/18/opengl-cascaded-shadow-maps/\r\n */\r\nexport class CascadedShadowGenerator extends ShadowGenerator {\r\n private static readonly _FrustumCornersNDCSpace = [\r\n new Vector3(-1.0, +1.0, -1.0),\r\n new Vector3(+1.0, +1.0, -1.0),\r\n new Vector3(+1.0, -1.0, -1.0),\r\n new Vector3(-1.0, -1.0, -1.0),\r\n new Vector3(-1.0, +1.0, +1.0),\r\n new Vector3(+1.0, +1.0, +1.0),\r\n new Vector3(+1.0, -1.0, +1.0),\r\n new Vector3(-1.0, -1.0, +1.0),\r\n ];\r\n\r\n /**\r\n * Name of the CSM class\r\n */\r\n public static CLASSNAME = \"CascadedShadowGenerator\";\r\n\r\n /**\r\n * Defines the default number of cascades used by the CSM.\r\n */\r\n public static readonly DEFAULT_CASCADES_COUNT = 4;\r\n /**\r\n * Defines the minimum number of cascades used by the CSM.\r\n */\r\n public static MIN_CASCADES_COUNT = 2;\r\n /**\r\n * Defines the maximum number of cascades used by the CSM.\r\n */\r\n public static MAX_CASCADES_COUNT = 4;\r\n\r\n protected _validateFilter(filter: number): number {\r\n if (filter === ShadowGenerator.FILTER_NONE || filter === ShadowGenerator.FILTER_PCF || filter === ShadowGenerator.FILTER_PCSS) {\r\n return filter;\r\n }\r\n\r\n console.error('Unsupported filter \"' + filter + '\"!');\r\n\r\n return ShadowGenerator.FILTER_NONE;\r\n }\r\n\r\n /**\r\n * Gets or sets the actual darkness of the soft shadows while using PCSS filtering (value between 0. and 1.)\r\n */\r\n public penumbraDarkness: number;\r\n\r\n private _numCascades: number;\r\n\r\n /**\r\n * Gets or set the number of cascades used by the CSM.\r\n */\r\n public get numCascades(): number {\r\n return this._numCascades;\r\n }\r\n\r\n public set numCascades(value: number) {\r\n value = Math.min(Math.max(value, CascadedShadowGenerator.MIN_CASCADES_COUNT), CascadedShadowGenerator.MAX_CASCADES_COUNT);\r\n if (value === this._numCascades) {\r\n return;\r\n }\r\n\r\n this._numCascades = value;\r\n this.recreateShadowMap();\r\n this._recreateSceneUBOs();\r\n }\r\n\r\n /**\r\n * Sets this to true if you want that the edges of the shadows don't \"swimm\" / \"shimmer\" when rotating the camera.\r\n * The trade off is that you lose some precision in the shadow rendering when enabling this setting.\r\n */\r\n public stabilizeCascades: boolean;\r\n\r\n private _freezeShadowCastersBoundingInfo: boolean;\r\n private _freezeShadowCastersBoundingInfoObservable: Nullable>;\r\n\r\n /**\r\n * Enables or disables the shadow casters bounding info computation.\r\n * If your shadow casters don't move, you can disable this feature.\r\n * If it is enabled, the bounding box computation is done every frame.\r\n */\r\n public get freezeShadowCastersBoundingInfo(): boolean {\r\n return this._freezeShadowCastersBoundingInfo;\r\n }\r\n\r\n public set freezeShadowCastersBoundingInfo(freeze: boolean) {\r\n if (this._freezeShadowCastersBoundingInfoObservable && freeze) {\r\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\r\n this._freezeShadowCastersBoundingInfoObservable = null;\r\n }\r\n\r\n if (!this._freezeShadowCastersBoundingInfoObservable && !freeze) {\r\n this._freezeShadowCastersBoundingInfoObservable = this._scene.onBeforeRenderObservable.add(this._computeShadowCastersBoundingInfo.bind(this));\r\n }\r\n\r\n this._freezeShadowCastersBoundingInfo = freeze;\r\n\r\n if (freeze) {\r\n this._computeShadowCastersBoundingInfo();\r\n }\r\n }\r\n\r\n private _scbiMin: Vector3;\r\n private _scbiMax: Vector3;\r\n\r\n protected _computeShadowCastersBoundingInfo(): void {\r\n this._scbiMin.copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n this._scbiMax.copyFromFloats(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);\r\n\r\n if (this._shadowMap && this._shadowMap.renderList) {\r\n const renderList = this._shadowMap.renderList;\r\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\r\n const mesh = renderList[meshIndex];\r\n\r\n if (!mesh) {\r\n continue;\r\n }\r\n\r\n const boundingInfo = mesh.getBoundingInfo(),\r\n boundingBox = boundingInfo.boundingBox;\r\n\r\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\r\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\r\n }\r\n\r\n const meshes = this._scene.meshes;\r\n for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {\r\n const mesh = meshes[meshIndex];\r\n\r\n if (!mesh || !mesh.isVisible || !mesh.isEnabled || !mesh.receiveShadows) {\r\n continue;\r\n }\r\n\r\n const boundingInfo = mesh.getBoundingInfo(),\r\n boundingBox = boundingInfo.boundingBox;\r\n\r\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\r\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\r\n }\r\n }\r\n\r\n this._shadowCastersBoundingInfo.reConstruct(this._scbiMin, this._scbiMax);\r\n }\r\n\r\n protected _shadowCastersBoundingInfo: BoundingInfo;\r\n\r\n /**\r\n * Gets or sets the shadow casters bounding info.\r\n * If you provide your own shadow casters bounding info, first enable freezeShadowCastersBoundingInfo\r\n * so that the system won't overwrite the bounds you provide\r\n */\r\n public get shadowCastersBoundingInfo(): BoundingInfo {\r\n return this._shadowCastersBoundingInfo;\r\n }\r\n\r\n public set shadowCastersBoundingInfo(boundingInfo: BoundingInfo) {\r\n this._shadowCastersBoundingInfo = boundingInfo;\r\n }\r\n\r\n protected _breaksAreDirty: boolean;\r\n\r\n protected _minDistance: number;\r\n protected _maxDistance: number;\r\n\r\n /**\r\n * Sets the minimal and maximal distances to use when computing the cascade breaks.\r\n *\r\n * The values of min / max are typically the depth zmin and zmax values of your scene, for a given frame.\r\n * If you don't know these values, simply leave them to their defaults and don't call this function.\r\n * @param min minimal distance for the breaks (default to 0.)\r\n * @param max maximal distance for the breaks (default to 1.)\r\n */\r\n public setMinMaxDistance(min: number, max: number): void {\r\n if (this._minDistance === min && this._maxDistance === max) {\r\n return;\r\n }\r\n\r\n if (min > max) {\r\n min = 0;\r\n max = 1;\r\n }\r\n\r\n if (min < 0) {\r\n min = 0;\r\n }\r\n\r\n if (max > 1) {\r\n max = 1;\r\n }\r\n\r\n this._minDistance = min;\r\n this._maxDistance = max;\r\n this._breaksAreDirty = true;\r\n }\r\n\r\n /** Gets the minimal distance used in the cascade break computation */\r\n public get minDistance(): number {\r\n return this._minDistance;\r\n }\r\n\r\n /** Gets the maximal distance used in the cascade break computation */\r\n public get maxDistance(): number {\r\n return this._maxDistance;\r\n }\r\n\r\n /**\r\n * Gets the class name of that object\r\n * @returns \"CascadedShadowGenerator\"\r\n */\r\n public getClassName(): string {\r\n return CascadedShadowGenerator.CLASSNAME;\r\n }\r\n\r\n private _cascadeMinExtents: Array;\r\n private _cascadeMaxExtents: Array;\r\n\r\n /**\r\n * Gets a cascade minimum extents\r\n * @param cascadeIndex index of the cascade\r\n * @returns the minimum cascade extents\r\n */\r\n public getCascadeMinExtents(cascadeIndex: number): Nullable {\r\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMinExtents[cascadeIndex] : null;\r\n }\r\n\r\n /**\r\n * Gets a cascade maximum extents\r\n * @param cascadeIndex index of the cascade\r\n * @returns the maximum cascade extents\r\n */\r\n public getCascadeMaxExtents(cascadeIndex: number): Nullable {\r\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMaxExtents[cascadeIndex] : null;\r\n }\r\n\r\n private _cascades: Array;\r\n private _currentLayer: number;\r\n private _viewSpaceFrustumsZ: Array;\r\n private _viewMatrices: Array;\r\n private _projectionMatrices: Array;\r\n private _transformMatrices: Array;\r\n private _transformMatricesAsArray: Float32Array;\r\n private _frustumLengths: Array;\r\n private _lightSizeUVCorrection: Array;\r\n private _depthCorrection: Array;\r\n private _frustumCornersWorldSpace: Array>;\r\n private _frustumCenter: Array;\r\n private _shadowCameraPos: Array;\r\n\r\n private _shadowMaxZ: number;\r\n /**\r\n * Gets the shadow max z distance. It's the limit beyond which shadows are not displayed.\r\n * It defaults to camera.maxZ\r\n */\r\n public get shadowMaxZ(): number {\r\n if (!this._getCamera()) {\r\n return 0;\r\n }\r\n return this._shadowMaxZ;\r\n }\r\n /**\r\n * Sets the shadow max z distance.\r\n */\r\n public set shadowMaxZ(value: number) {\r\n const camera = this._getCamera();\r\n if (!camera) {\r\n this._shadowMaxZ = value;\r\n return;\r\n }\r\n if (this._shadowMaxZ === value || value < camera.minZ || value > camera.maxZ) {\r\n return;\r\n }\r\n this._shadowMaxZ = value;\r\n this._light._markMeshesAsLightDirty();\r\n this._breaksAreDirty = true;\r\n }\r\n\r\n protected _debug: boolean;\r\n\r\n /**\r\n * Gets or sets the debug flag.\r\n * When enabled, the cascades are materialized by different colors on the screen.\r\n */\r\n public get debug(): boolean {\r\n return this._debug;\r\n }\r\n\r\n public set debug(dbg: boolean) {\r\n this._debug = dbg;\r\n this._light._markMeshesAsLightDirty();\r\n }\r\n\r\n private _depthClamp: boolean;\r\n\r\n /**\r\n * Gets or sets the depth clamping value.\r\n *\r\n * When enabled, it improves the shadow quality because the near z plane of the light frustum don't need to be adjusted\r\n * to account for the shadow casters far away.\r\n *\r\n * Note that this property is incompatible with PCSS filtering, so it won't be used in that case.\r\n */\r\n public get depthClamp(): boolean {\r\n return this._depthClamp;\r\n }\r\n\r\n public set depthClamp(value: boolean) {\r\n this._depthClamp = value;\r\n }\r\n\r\n private _cascadeBlendPercentage: number;\r\n\r\n /**\r\n * Gets or sets the percentage of blending between two cascades (value between 0. and 1.).\r\n * It defaults to 0.1 (10% blending).\r\n */\r\n public get cascadeBlendPercentage(): number {\r\n return this._cascadeBlendPercentage;\r\n }\r\n\r\n public set cascadeBlendPercentage(value: number) {\r\n this._cascadeBlendPercentage = value;\r\n this._light._markMeshesAsLightDirty();\r\n }\r\n\r\n private _lambda: number;\r\n\r\n /**\r\n * Gets or set the lambda parameter.\r\n * This parameter is used to split the camera frustum and create the cascades.\r\n * It's a value between 0. and 1.: If 0, the split is a uniform split of the frustum, if 1 it is a logarithmic split.\r\n * For all values in-between, it's a linear combination of the uniform and logarithm split algorithm.\r\n */\r\n public get lambda(): number {\r\n return this._lambda;\r\n }\r\n\r\n public set lambda(value: number) {\r\n const lambda = Math.min(Math.max(value, 0), 1);\r\n if (this._lambda == lambda) {\r\n return;\r\n }\r\n this._lambda = lambda;\r\n this._breaksAreDirty = true;\r\n }\r\n\r\n /**\r\n * Gets the view matrix corresponding to a given cascade\r\n * @param cascadeNum cascade to retrieve the view matrix from\r\n * @returns the cascade view matrix\r\n */\r\n public getCascadeViewMatrix(cascadeNum: number): Nullable {\r\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._viewMatrices[cascadeNum] : null;\r\n }\r\n\r\n /**\r\n * Gets the projection matrix corresponding to a given cascade\r\n * @param cascadeNum cascade to retrieve the projection matrix from\r\n * @returns the cascade projection matrix\r\n */\r\n public getCascadeProjectionMatrix(cascadeNum: number): Nullable {\r\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._projectionMatrices[cascadeNum] : null;\r\n }\r\n\r\n /**\r\n * Gets the transformation matrix corresponding to a given cascade\r\n * @param cascadeNum cascade to retrieve the transformation matrix from\r\n * @returns the cascade transformation matrix\r\n */\r\n public getCascadeTransformMatrix(cascadeNum: number): Nullable {\r\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._transformMatrices[cascadeNum] : null;\r\n }\r\n\r\n private _depthRenderer: Nullable;\r\n /**\r\n * Sets the depth renderer to use when autoCalcDepthBounds is enabled.\r\n *\r\n * Note that if no depth renderer is set, a new one will be automatically created internally when necessary.\r\n *\r\n * You should call this function if you already have a depth renderer enabled in your scene, to avoid\r\n * doing multiple depth rendering each frame. If you provide your own depth renderer, make sure it stores linear depth!\r\n * @param depthRenderer The depth renderer to use when autoCalcDepthBounds is enabled. If you pass null or don't call this function at all, a depth renderer will be automatically created\r\n */\r\n public setDepthRenderer(depthRenderer: Nullable): void {\r\n this._depthRenderer = depthRenderer;\r\n\r\n if (this._depthReducer) {\r\n this._depthReducer.setDepthRenderer(this._depthRenderer);\r\n }\r\n }\r\n\r\n private _depthReducer: Nullable;\r\n private _autoCalcDepthBounds: boolean;\r\n\r\n /**\r\n * Gets or sets the autoCalcDepthBounds property.\r\n *\r\n * When enabled, a depth rendering pass is first performed (with an internally created depth renderer or with the one\r\n * you provide by calling setDepthRenderer). Then, a min/max reducing is applied on the depth map to compute the\r\n * minimal and maximal depth of the map and those values are used as inputs for the setMinMaxDistance() function.\r\n * It can greatly enhance the shadow quality, at the expense of more GPU works.\r\n * When using this option, you should increase the value of the lambda parameter, and even set it to 1 for best results.\r\n */\r\n public get autoCalcDepthBounds(): boolean {\r\n return this._autoCalcDepthBounds;\r\n }\r\n\r\n public set autoCalcDepthBounds(value: boolean) {\r\n const camera = this._getCamera();\r\n\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n this._autoCalcDepthBounds = value;\r\n\r\n if (!value) {\r\n if (this._depthReducer) {\r\n this._depthReducer.deactivate();\r\n }\r\n this.setMinMaxDistance(0, 1);\r\n return;\r\n }\r\n\r\n if (!this._depthReducer) {\r\n this._depthReducer = new DepthReducer(camera);\r\n this._depthReducer.onAfterReductionPerformed.add((minmax: { min: number; max: number }) => {\r\n let min = minmax.min,\r\n max = minmax.max;\r\n if (min >= max) {\r\n min = 0;\r\n max = 1;\r\n }\r\n if (min != this._minDistance || max != this._maxDistance) {\r\n this.setMinMaxDistance(min, max);\r\n }\r\n });\r\n this._depthReducer.setDepthRenderer(this._depthRenderer);\r\n }\r\n\r\n this._depthReducer.activate();\r\n }\r\n\r\n /**\r\n * Defines the refresh rate of the min/max computation used when autoCalcDepthBounds is set to true\r\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\r\n * Note that if you provided your own depth renderer through a call to setDepthRenderer, you are responsible\r\n * for setting the refresh rate on the renderer yourself!\r\n */\r\n public get autoCalcDepthBoundsRefreshRate(): number {\r\n return this._depthReducer?.depthRenderer?.getDepthMap().refreshRate ?? -1;\r\n }\r\n\r\n public set autoCalcDepthBoundsRefreshRate(value: number) {\r\n if (this._depthReducer?.depthRenderer) {\r\n this._depthReducer.depthRenderer.getDepthMap().refreshRate = value;\r\n }\r\n }\r\n\r\n /**\r\n * Create the cascade breaks according to the lambda, shadowMaxZ and min/max distance properties, as well as the camera near and far planes.\r\n * This function is automatically called when updating lambda, shadowMaxZ and min/max distances, however you should call it yourself if\r\n * you change the camera near/far planes!\r\n */\r\n public splitFrustum(): void {\r\n this._breaksAreDirty = true;\r\n }\r\n\r\n private _splitFrustum(): void {\r\n const camera = this._getCamera();\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n const near = camera.minZ,\r\n far = camera.maxZ || this._shadowMaxZ, // account for infinite far plane (ie. maxZ = 0)\r\n cameraRange = far - near,\r\n minDistance = this._minDistance,\r\n maxDistance = this._shadowMaxZ < far && this._shadowMaxZ >= near ? Math.min((this._shadowMaxZ - near) / (far - near), this._maxDistance) : this._maxDistance;\r\n\r\n const minZ = near + minDistance * cameraRange,\r\n maxZ = near + maxDistance * cameraRange;\r\n\r\n const range = maxZ - minZ,\r\n ratio = maxZ / minZ;\r\n\r\n for (let cascadeIndex = 0; cascadeIndex < this._cascades.length; ++cascadeIndex) {\r\n const p = (cascadeIndex + 1) / this._numCascades,\r\n log = minZ * ratio ** p,\r\n uniform = minZ + range * p;\r\n\r\n const d = this._lambda * (log - uniform) + uniform;\r\n\r\n this._cascades[cascadeIndex].prevBreakDistance = cascadeIndex === 0 ? minDistance : this._cascades[cascadeIndex - 1].breakDistance;\r\n this._cascades[cascadeIndex].breakDistance = (d - near) / cameraRange;\r\n\r\n this._viewSpaceFrustumsZ[cascadeIndex] = d;\r\n this._frustumLengths[cascadeIndex] = (this._cascades[cascadeIndex].breakDistance - this._cascades[cascadeIndex].prevBreakDistance) * cameraRange;\r\n }\r\n\r\n this._breaksAreDirty = false;\r\n }\r\n\r\n private _computeMatrices(): void {\r\n const scene = this._scene;\r\n\r\n const camera = this._getCamera();\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n Vector3.NormalizeToRef(this._light.getShadowDirection(0), this._lightDirection);\r\n if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {\r\n this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\r\n }\r\n\r\n this._cachedDirection.copyFrom(this._lightDirection);\r\n\r\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\r\n\r\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\r\n this._computeFrustumInWorldSpace(cascadeIndex);\r\n this._computeCascadeFrustum(cascadeIndex);\r\n\r\n this._cascadeMaxExtents[cascadeIndex].subtractToRef(this._cascadeMinExtents[cascadeIndex], tmpv1); // tmpv1 = cascadeExtents\r\n\r\n // Get position of the shadow camera\r\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection.scale(this._cascadeMinExtents[cascadeIndex].z), this._shadowCameraPos[cascadeIndex]);\r\n\r\n // Come up with a new orthographic camera for the shadow caster\r\n Matrix.LookAtLHToRef(this._shadowCameraPos[cascadeIndex], this._frustumCenter[cascadeIndex], UpDir, this._viewMatrices[cascadeIndex]);\r\n\r\n let minZ = 0,\r\n maxZ = tmpv1.z;\r\n\r\n // Try to tighten minZ and maxZ based on the bounding box of the shadow casters\r\n const boundingInfo = this._shadowCastersBoundingInfo;\r\n\r\n boundingInfo.update(this._viewMatrices[cascadeIndex]);\r\n\r\n maxZ = Math.min(maxZ, boundingInfo.boundingBox.maximumWorld.z);\r\n\r\n if (!this._depthClamp || this.filter === ShadowGenerator.FILTER_PCSS) {\r\n // If we don't use depth clamping, we must set minZ so that all shadow casters are in the light frustum\r\n minZ = Math.min(minZ, boundingInfo.boundingBox.minimumWorld.z);\r\n } else {\r\n // If using depth clamping, we can adjust minZ to reduce the [minZ, maxZ] range (and get some additional precision in the shadow map)\r\n minZ = Math.max(minZ, boundingInfo.boundingBox.minimumWorld.z);\r\n }\r\n\r\n Matrix.OrthoOffCenterLHToRef(\r\n this._cascadeMinExtents[cascadeIndex].x,\r\n this._cascadeMaxExtents[cascadeIndex].x,\r\n this._cascadeMinExtents[cascadeIndex].y,\r\n this._cascadeMaxExtents[cascadeIndex].y,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n this._projectionMatrices[cascadeIndex],\r\n scene.getEngine().isNDCHalfZRange\r\n );\r\n\r\n this._cascadeMinExtents[cascadeIndex].z = minZ;\r\n this._cascadeMaxExtents[cascadeIndex].z = maxZ;\r\n\r\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\r\n\r\n // Create the rounding matrix, by projecting the world-space origin and determining\r\n // the fractional offset in texel space\r\n Vector3.TransformCoordinatesToRef(ZeroVec, this._transformMatrices[cascadeIndex], tmpv1); // tmpv1 = shadowOrigin\r\n tmpv1.scaleInPlace(this._mapSize / 2);\r\n\r\n tmpv2.copyFromFloats(Math.round(tmpv1.x), Math.round(tmpv1.y), Math.round(tmpv1.z)); // tmpv2 = roundedOrigin\r\n tmpv2.subtractInPlace(tmpv1).scaleInPlace(2 / this._mapSize); // tmpv2 = roundOffset\r\n\r\n Matrix.TranslationToRef(tmpv2.x, tmpv2.y, 0.0, tmpMatrix);\r\n\r\n this._projectionMatrices[cascadeIndex].multiplyToRef(tmpMatrix, this._projectionMatrices[cascadeIndex]);\r\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\r\n\r\n this._transformMatrices[cascadeIndex].copyToArray(this._transformMatricesAsArray, cascadeIndex * 16);\r\n }\r\n }\r\n\r\n // Get the 8 points of the view frustum in world space\r\n private _computeFrustumInWorldSpace(cascadeIndex: number): void {\r\n const camera = this._getCamera();\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n const prevSplitDist = this._cascades[cascadeIndex].prevBreakDistance,\r\n splitDist = this._cascades[cascadeIndex].breakDistance;\r\n\r\n const isNDCHalfZRange = this._scene.getEngine().isNDCHalfZRange;\r\n\r\n camera.getViewMatrix(); // make sure the transformation matrix we get when calling 'getTransformationMatrix()' is calculated with an up to date view matrix\r\n\r\n const cameraInfiniteFarPlane = camera.maxZ === 0;\r\n const saveCameraMaxZ = camera.maxZ;\r\n\r\n if (cameraInfiniteFarPlane) {\r\n camera.maxZ = this._shadowMaxZ;\r\n camera.getProjectionMatrix(true);\r\n }\r\n\r\n const invViewProj = Matrix.Invert(camera.getTransformationMatrix());\r\n\r\n if (cameraInfiniteFarPlane) {\r\n camera.maxZ = saveCameraMaxZ;\r\n camera.getProjectionMatrix(true);\r\n }\r\n\r\n const cornerIndexOffset = this._scene.getEngine().useReverseDepthBuffer ? 4 : 0;\r\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++cornerIndex) {\r\n tmpv1.copyFrom(CascadedShadowGenerator._FrustumCornersNDCSpace[(cornerIndex + cornerIndexOffset) % CascadedShadowGenerator._FrustumCornersNDCSpace.length]);\r\n if (isNDCHalfZRange && tmpv1.z === -1) {\r\n tmpv1.z = 0;\r\n }\r\n Vector3.TransformCoordinatesToRef(tmpv1, invViewProj, this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\r\n }\r\n\r\n // Get the corners of the current cascade slice of the view frustum\r\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length / 2; ++cornerIndex) {\r\n tmpv1.copyFrom(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4]).subtractInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\r\n tmpv2.copyFrom(tmpv1).scaleInPlace(prevSplitDist); // near corner ray\r\n tmpv1.scaleInPlace(splitDist); // far corner ray\r\n\r\n tmpv1.addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\r\n\r\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4].copyFrom(tmpv1);\r\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].addInPlace(tmpv2);\r\n }\r\n }\r\n\r\n private _computeCascadeFrustum(cascadeIndex: number): void {\r\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\r\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);\r\n this._frustumCenter[cascadeIndex].copyFromFloats(0, 0, 0);\r\n\r\n const camera = this._getCamera();\r\n\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n // Calculate the centroid of the view frustum slice\r\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\r\n this._frustumCenter[cascadeIndex].addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\r\n }\r\n\r\n this._frustumCenter[cascadeIndex].scaleInPlace(1 / this._frustumCornersWorldSpace[cascadeIndex].length);\r\n\r\n if (this.stabilizeCascades) {\r\n // Calculate the radius of a bounding sphere surrounding the frustum corners\r\n let sphereRadius = 0;\r\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\r\n const dist = this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].subtractToRef(this._frustumCenter[cascadeIndex], tmpv1).length();\r\n sphereRadius = Math.max(sphereRadius, dist);\r\n }\r\n\r\n sphereRadius = Math.ceil(sphereRadius * 16) / 16;\r\n\r\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(sphereRadius, sphereRadius, sphereRadius);\r\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(-sphereRadius, -sphereRadius, -sphereRadius);\r\n } else {\r\n // Create a temporary view matrix for the light\r\n const lightCameraPos = this._frustumCenter[cascadeIndex];\r\n\r\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection, tmpv1); // tmpv1 = look at\r\n\r\n Matrix.LookAtLHToRef(lightCameraPos, tmpv1, UpDir, tmpMatrix); // matrix = lightView\r\n\r\n // Calculate an AABB around the frustum corners\r\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\r\n Vector3.TransformCoordinatesToRef(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex], tmpMatrix, tmpv1);\r\n\r\n this._cascadeMinExtents[cascadeIndex].minimizeInPlace(tmpv1);\r\n this._cascadeMaxExtents[cascadeIndex].maximizeInPlace(tmpv1);\r\n }\r\n }\r\n }\r\n\r\n protected _recreateSceneUBOs(): void {\r\n this._disposeSceneUBOs();\r\n if (this._sceneUBOs) {\r\n for (let i = 0; i < this._numCascades; ++i) {\r\n this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for CSM Shadow Generator (light \"${this._light.name}\" cascade #${i})`));\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Support test.\r\n */\r\n public static get IsSupported(): boolean {\r\n const engine = EngineStore.LastCreatedEngine;\r\n if (!engine) {\r\n return false;\r\n }\r\n return engine._features.supportCSM;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {\r\n throw _WarnImport(\"ShadowGeneratorSceneComponent\");\r\n };\r\n\r\n /**\r\n * Creates a Cascaded Shadow Generator object.\r\n * A ShadowGenerator is the required tool to use the shadows.\r\n * Each directional light casting shadows needs to use its own ShadowGenerator.\r\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\r\n * @param mapSize The size of the texture what stores the shadows. Example : 1024.\r\n * @param light The directional light object generating the shadows.\r\n * @param usefulFloatFirst By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.\r\n * @param camera Camera associated with this shadow generator (default: null). If null, takes the scene active camera at the time we need to access it\r\n * @param useRedTextureType Forces the generator to use a Red instead of a RGBA type for the shadow map texture format (default: true)\r\n */\r\n constructor(mapSize: number, light: DirectionalLight, usefulFloatFirst?: boolean, camera?: Nullable, useRedTextureType = true) {\r\n if (!CascadedShadowGenerator.IsSupported) {\r\n Logger.Error(\"CascadedShadowMap is not supported by the current engine.\");\r\n return;\r\n }\r\n\r\n super(mapSize, light, usefulFloatFirst, camera, useRedTextureType);\r\n\r\n this.usePercentageCloserFiltering = true;\r\n }\r\n\r\n protected _initializeGenerator(): void {\r\n this.penumbraDarkness = this.penumbraDarkness ?? 1.0;\r\n this._numCascades = this._numCascades ?? CascadedShadowGenerator.DEFAULT_CASCADES_COUNT;\r\n this.stabilizeCascades = this.stabilizeCascades ?? false;\r\n this._freezeShadowCastersBoundingInfoObservable = this._freezeShadowCastersBoundingInfoObservable ?? null;\r\n this.freezeShadowCastersBoundingInfo = this.freezeShadowCastersBoundingInfo ?? false;\r\n this._scbiMin = this._scbiMin ?? new Vector3(0, 0, 0);\r\n this._scbiMax = this._scbiMax ?? new Vector3(0, 0, 0);\r\n this._shadowCastersBoundingInfo = this._shadowCastersBoundingInfo ?? new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0));\r\n this._breaksAreDirty = this._breaksAreDirty ?? true;\r\n this._minDistance = this._minDistance ?? 0;\r\n this._maxDistance = this._maxDistance ?? 1;\r\n this._currentLayer = this._currentLayer ?? 0;\r\n this._shadowMaxZ = this._shadowMaxZ ?? this._getCamera()?.maxZ ?? 10000;\r\n this._debug = this._debug ?? false;\r\n this._depthClamp = this._depthClamp ?? true;\r\n this._cascadeBlendPercentage = this._cascadeBlendPercentage ?? 0.1;\r\n this._lambda = this._lambda ?? 0.5;\r\n this._autoCalcDepthBounds = this._autoCalcDepthBounds ?? false;\r\n\r\n this._recreateSceneUBOs();\r\n\r\n super._initializeGenerator();\r\n }\r\n\r\n protected _createTargetRenderTexture(): void {\r\n const engine = this._scene.getEngine();\r\n const size = { width: this._mapSize, height: this._mapSize, layers: this.numCascades };\r\n this._shadowMap = new RenderTargetTexture(\r\n this._light.name + \"_CSMShadowMap\",\r\n size,\r\n this._scene,\r\n false,\r\n true,\r\n this._textureType,\r\n false,\r\n undefined,\r\n false,\r\n false,\r\n undefined,\r\n this._useRedTextureType ? Constants.TEXTUREFORMAT_RED : Constants.TEXTUREFORMAT_RGBA\r\n );\r\n this._shadowMap.createDepthStencilTexture(engine.useReverseDepthBuffer ? Constants.GREATER : Constants.LESS, true);\r\n this._shadowMap.noPrePassRenderer = true;\r\n }\r\n\r\n protected _initializeShadowMap(): void {\r\n super._initializeShadowMap();\r\n\r\n if (this._shadowMap === null) {\r\n return;\r\n }\r\n\r\n this._transformMatricesAsArray = new Float32Array(this._numCascades * 16);\r\n this._viewSpaceFrustumsZ = new Array(this._numCascades);\r\n this._frustumLengths = new Array(this._numCascades);\r\n this._lightSizeUVCorrection = new Array(this._numCascades * 2);\r\n this._depthCorrection = new Array(this._numCascades);\r\n\r\n this._cascades = [];\r\n this._viewMatrices = [];\r\n this._projectionMatrices = [];\r\n this._transformMatrices = [];\r\n this._cascadeMinExtents = [];\r\n this._cascadeMaxExtents = [];\r\n this._frustumCenter = [];\r\n this._shadowCameraPos = [];\r\n this._frustumCornersWorldSpace = [];\r\n\r\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\r\n this._cascades[cascadeIndex] = {\r\n prevBreakDistance: 0,\r\n breakDistance: 0,\r\n };\r\n\r\n this._viewMatrices[cascadeIndex] = Matrix.Zero();\r\n this._projectionMatrices[cascadeIndex] = Matrix.Zero();\r\n this._transformMatrices[cascadeIndex] = Matrix.Zero();\r\n this._cascadeMinExtents[cascadeIndex] = new Vector3();\r\n this._cascadeMaxExtents[cascadeIndex] = new Vector3();\r\n this._frustumCenter[cascadeIndex] = new Vector3();\r\n this._shadowCameraPos[cascadeIndex] = new Vector3();\r\n this._frustumCornersWorldSpace[cascadeIndex] = new Array(CascadedShadowGenerator._FrustumCornersNDCSpace.length);\r\n\r\n for (let i = 0; i < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++i) {\r\n this._frustumCornersWorldSpace[cascadeIndex][i] = new Vector3();\r\n }\r\n }\r\n\r\n const engine = this._scene.getEngine();\r\n\r\n this._shadowMap.onBeforeBindObservable.clear();\r\n this._shadowMap.onBeforeRenderObservable.clear();\r\n\r\n this._shadowMap.onBeforeRenderObservable.add((layer: number) => {\r\n if (this._sceneUBOs) {\r\n this._scene.setSceneUniformBuffer(this._sceneUBOs[layer]);\r\n }\r\n this._currentLayer = layer;\r\n if (this._filter === ShadowGenerator.FILTER_PCF) {\r\n engine.setColorWrite(false);\r\n }\r\n this._scene.setTransformMatrix(this.getCascadeViewMatrix(layer)!, this.getCascadeProjectionMatrix(layer)!);\r\n if (this._useUBO) {\r\n this._scene.getSceneUniformBuffer().unbindEffect();\r\n this._scene.finalizeSceneUbo();\r\n }\r\n });\r\n\r\n this._shadowMap.onBeforeBindObservable.add(() => {\r\n this._currentSceneUBO = this._scene.getSceneUniformBuffer();\r\n engine._debugPushGroup?.(`cascaded shadow map generation for pass id ${engine.currentRenderPassId}`, 1);\r\n if (this._breaksAreDirty) {\r\n this._splitFrustum();\r\n }\r\n this._computeMatrices();\r\n });\r\n\r\n this._splitFrustum();\r\n }\r\n\r\n protected _bindCustomEffectForRenderSubMeshForShadowMap(subMesh: SubMesh, effect: Effect): void {\r\n effect.setMatrix(\"viewProjection\", this.getCascadeTransformMatrix(this._currentLayer)!);\r\n }\r\n\r\n protected _isReadyCustomDefines(defines: any): void {\r\n defines.push(\"#define SM_DEPTHCLAMP \" + (this._depthClamp && this._filter !== ShadowGenerator.FILTER_PCSS ? \"1\" : \"0\"));\r\n }\r\n\r\n /**\r\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\r\n * @param defines Defines of the material we want to update\r\n * @param lightIndex Index of the light in the enabled light list of the material\r\n */\r\n public prepareDefines(defines: any, lightIndex: number): void {\r\n super.prepareDefines(defines, lightIndex);\r\n\r\n const scene = this._scene;\r\n const light = this._light;\r\n\r\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\r\n return;\r\n }\r\n\r\n defines[\"SHADOWCSM\" + lightIndex] = true;\r\n defines[\"SHADOWCSMDEBUG\" + lightIndex] = this.debug;\r\n defines[\"SHADOWCSMNUM_CASCADES\" + lightIndex] = this.numCascades;\r\n defines[\"SHADOWCSM_RIGHTHANDED\" + lightIndex] = scene.useRightHandedSystem;\r\n\r\n const camera = this._getCamera();\r\n\r\n if (camera && this._shadowMaxZ <= (camera.maxZ || this._shadowMaxZ)) {\r\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + lightIndex] = true;\r\n }\r\n\r\n if (this.cascadeBlendPercentage === 0) {\r\n defines[\"SHADOWCSMNOBLEND\" + lightIndex] = true;\r\n }\r\n }\r\n\r\n /**\r\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\r\n * defined in the generator but impacting the effect).\r\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\r\n * @param effect The effect we are binfing the information for\r\n */\r\n public bindShadowLight(lightIndex: string, effect: Effect): void {\r\n const light = this._light;\r\n const scene = this._scene;\r\n\r\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\r\n return;\r\n }\r\n\r\n const camera = this._getCamera();\r\n if (!camera) {\r\n return;\r\n }\r\n\r\n const shadowMap = this.getShadowMap();\r\n if (!shadowMap) {\r\n return;\r\n }\r\n\r\n const width = shadowMap.getSize().width;\r\n\r\n effect.setMatrices(\"lightMatrix\" + lightIndex, this._transformMatricesAsArray);\r\n effect.setArray(\"viewFrustumZ\" + lightIndex, this._viewSpaceFrustumsZ);\r\n effect.setFloat(\"cascadeBlendFactor\" + lightIndex, this.cascadeBlendPercentage === 0 ? 10000 : 1 / this.cascadeBlendPercentage);\r\n effect.setArray(\"frustumLengths\" + lightIndex, this._frustumLengths);\r\n\r\n // Only PCF uses depth stencil texture.\r\n if (this._filter === ShadowGenerator.FILTER_PCF) {\r\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, shadowMap);\r\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\r\n } else if (this._filter === ShadowGenerator.FILTER_PCSS) {\r\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\r\n this._lightSizeUVCorrection[cascadeIndex * 2 + 0] =\r\n cascadeIndex === 0\r\n ? 1\r\n : (this._cascadeMaxExtents[0].x - this._cascadeMinExtents[0].x) / (this._cascadeMaxExtents[cascadeIndex].x - this._cascadeMinExtents[cascadeIndex].x); // x correction\r\n this._lightSizeUVCorrection[cascadeIndex * 2 + 1] =\r\n cascadeIndex === 0\r\n ? 1\r\n : (this._cascadeMaxExtents[0].y - this._cascadeMinExtents[0].y) / (this._cascadeMaxExtents[cascadeIndex].y - this._cascadeMinExtents[cascadeIndex].y); // y correction\r\n this._depthCorrection[cascadeIndex] =\r\n cascadeIndex === 0\r\n ? 1\r\n : (this._cascadeMaxExtents[cascadeIndex].z - this._cascadeMinExtents[cascadeIndex].z) / (this._cascadeMaxExtents[0].z - this._cascadeMinExtents[0].z);\r\n }\r\n effect.setDepthStencilTexture(\"shadowSampler\" + lightIndex, shadowMap);\r\n effect.setTexture(\"depthSampler\" + lightIndex, shadowMap);\r\n effect.setArray2(\"lightSizeUVCorrection\" + lightIndex, this._lightSizeUVCorrection);\r\n effect.setArray(\"depthCorrection\" + lightIndex, this._depthCorrection);\r\n effect.setFloat(\"penumbraDarkness\" + lightIndex, this.penumbraDarkness);\r\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), 1 / width, this._contactHardeningLightSizeUVRatio * width, this.frustumEdgeFalloff, lightIndex);\r\n } else {\r\n effect.setTexture(\"shadowSampler\" + lightIndex, shadowMap);\r\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\r\n }\r\n\r\n light._uniformBuffer.updateFloat2(\r\n \"depthValues\",\r\n this.getLight().getDepthMinZ(camera),\r\n this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera),\r\n lightIndex\r\n );\r\n }\r\n\r\n /**\r\n * Gets the transformation matrix of the first cascade used to project the meshes into the map from the light point of view.\r\n * (eq to view projection * shadow projection matrices)\r\n * @returns The transform matrix used to create the shadow map\r\n */\r\n public getTransformMatrix(): Matrix {\r\n return this.getCascadeTransformMatrix(0)!;\r\n }\r\n\r\n /**\r\n * Disposes the ShadowGenerator.\r\n * Returns nothing.\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n\r\n if (this._freezeShadowCastersBoundingInfoObservable) {\r\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\r\n this._freezeShadowCastersBoundingInfoObservable = null;\r\n }\r\n\r\n if (this._depthReducer) {\r\n this._depthReducer.dispose();\r\n this._depthReducer = null;\r\n }\r\n }\r\n\r\n /**\r\n * Serializes the shadow generator setup to a json object.\r\n * @returns The serialized JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = super.serialize();\r\n const shadowMap = this.getShadowMap();\r\n\r\n if (!shadowMap) {\r\n return serializationObject;\r\n }\r\n\r\n serializationObject.numCascades = this._numCascades;\r\n serializationObject.debug = this._debug;\r\n serializationObject.stabilizeCascades = this.stabilizeCascades;\r\n serializationObject.lambda = this._lambda;\r\n serializationObject.cascadeBlendPercentage = this.cascadeBlendPercentage;\r\n serializationObject.depthClamp = this._depthClamp;\r\n serializationObject.autoCalcDepthBounds = this.autoCalcDepthBounds;\r\n serializationObject.shadowMaxZ = this._shadowMaxZ;\r\n serializationObject.penumbraDarkness = this.penumbraDarkness;\r\n\r\n serializationObject.freezeShadowCastersBoundingInfo = this._freezeShadowCastersBoundingInfo;\r\n serializationObject.minDistance = this.minDistance;\r\n serializationObject.maxDistance = this.maxDistance;\r\n\r\n serializationObject.renderList = [];\r\n if (shadowMap.renderList) {\r\n for (let meshIndex = 0; meshIndex < shadowMap.renderList.length; meshIndex++) {\r\n const mesh = shadowMap.renderList[meshIndex];\r\n\r\n serializationObject.renderList.push(mesh.id);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parses a serialized ShadowGenerator and returns a new ShadowGenerator.\r\n * @param parsedShadowGenerator The JSON object to parse\r\n * @param scene The scene to create the shadow map for\r\n * @returns The parsed shadow generator\r\n */\r\n public static Parse(parsedShadowGenerator: any, scene: Scene): ShadowGenerator {\r\n const shadowGenerator = ShadowGenerator.Parse(\r\n parsedShadowGenerator,\r\n scene,\r\n (mapSize: number, light: IShadowLight, camera: Nullable) => new CascadedShadowGenerator(mapSize, light, undefined, camera)\r\n ) as CascadedShadowGenerator;\r\n\r\n if (parsedShadowGenerator.numCascades !== undefined) {\r\n shadowGenerator.numCascades = parsedShadowGenerator.numCascades;\r\n }\r\n\r\n if (parsedShadowGenerator.debug !== undefined) {\r\n shadowGenerator.debug = parsedShadowGenerator.debug;\r\n }\r\n\r\n if (parsedShadowGenerator.stabilizeCascades !== undefined) {\r\n shadowGenerator.stabilizeCascades = parsedShadowGenerator.stabilizeCascades;\r\n }\r\n\r\n if (parsedShadowGenerator.lambda !== undefined) {\r\n shadowGenerator.lambda = parsedShadowGenerator.lambda;\r\n }\r\n\r\n if (parsedShadowGenerator.cascadeBlendPercentage !== undefined) {\r\n shadowGenerator.cascadeBlendPercentage = parsedShadowGenerator.cascadeBlendPercentage;\r\n }\r\n\r\n if (parsedShadowGenerator.depthClamp !== undefined) {\r\n shadowGenerator.depthClamp = parsedShadowGenerator.depthClamp;\r\n }\r\n\r\n if (parsedShadowGenerator.autoCalcDepthBounds !== undefined) {\r\n shadowGenerator.autoCalcDepthBounds = parsedShadowGenerator.autoCalcDepthBounds;\r\n }\r\n\r\n if (parsedShadowGenerator.shadowMaxZ !== undefined) {\r\n shadowGenerator.shadowMaxZ = parsedShadowGenerator.shadowMaxZ;\r\n }\r\n\r\n if (parsedShadowGenerator.penumbraDarkness !== undefined) {\r\n shadowGenerator.penumbraDarkness = parsedShadowGenerator.penumbraDarkness;\r\n }\r\n\r\n if (parsedShadowGenerator.freezeShadowCastersBoundingInfo !== undefined) {\r\n shadowGenerator.freezeShadowCastersBoundingInfo = parsedShadowGenerator.freezeShadowCastersBoundingInfo;\r\n }\r\n\r\n if (parsedShadowGenerator.minDistance !== undefined && parsedShadowGenerator.maxDistance !== undefined) {\r\n shadowGenerator.setMinMaxDistance(parsedShadowGenerator.minDistance, parsedShadowGenerator.maxDistance);\r\n }\r\n\r\n return shadowGenerator;\r\n }\r\n}\r\n","import type { SmartArrayNoDuplicate } from \"../../Misc/smartArray\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { ShadowGenerator } from \"./shadowGenerator\";\r\nimport { CascadedShadowGenerator } from \"./cascadedShadowGenerator\";\r\nimport type { ISceneSerializableComponent } from \"../../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../../sceneComponent\";\r\nimport { AbstractScene } from \"../../abstractScene\";\r\n// Adds the parser to the scene parsers.\r\nAbstractScene.AddParser(SceneComponentConstants.NAME_SHADOWGENERATOR, (parsedData: any, scene: Scene) => {\r\n // Shadows\r\n if (parsedData.shadowGenerators !== undefined && parsedData.shadowGenerators !== null) {\r\n for (let index = 0, cache = parsedData.shadowGenerators.length; index < cache; index++) {\r\n const parsedShadowGenerator = parsedData.shadowGenerators[index];\r\n if (parsedShadowGenerator.className === CascadedShadowGenerator.CLASSNAME) {\r\n CascadedShadowGenerator.Parse(parsedShadowGenerator, scene);\r\n } else {\r\n ShadowGenerator.Parse(parsedShadowGenerator, scene);\r\n }\r\n // SG would be available on their associated lights\r\n }\r\n }\r\n});\r\n\r\n/**\r\n * Defines the shadow generator component responsible to manage any shadow generators\r\n * in a given scene.\r\n */\r\nexport class ShadowGeneratorSceneComponent implements ISceneSerializableComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_SHADOWGENERATOR;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_SHADOWGENERATOR, this, this._gatherRenderTargets);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing To Do Here.\r\n }\r\n\r\n /**\r\n * Serializes the component data to the specified json object\r\n * @param serializationObject The object to serialize to\r\n */\r\n public serialize(serializationObject: any): void {\r\n // Shadows\r\n serializationObject.shadowGenerators = [];\r\n const lights = this.scene.lights;\r\n for (const light of lights) {\r\n const shadowGenerators = light.getShadowGenerators();\r\n if (shadowGenerators) {\r\n const iterator = shadowGenerators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const shadowGenerator = key.value;\r\n serializationObject.shadowGenerators.push(shadowGenerator.serialize());\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Adds all the elements from the container to the scene\r\n * @param container the container holding the elements\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public addFromContainer(container: AbstractScene): void {\r\n // Nothing To Do Here. (directly attached to a light)\r\n }\r\n\r\n /**\r\n * Removes all the elements in the container from the scene\r\n * @param container contains the elements to remove\r\n * @param dispose if the removed element should be disposed (default: false)\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public removeFromContainer(container: AbstractScene, dispose?: boolean): void {\r\n // Nothing To Do Here. (directly attached to a light)\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public dispose(): void {\r\n // Nothing To Do Here.\r\n }\r\n\r\n private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate): void {\r\n // Shadows\r\n const scene = this.scene;\r\n if (this.scene.shadowsEnabled) {\r\n for (let lightIndex = 0; lightIndex < scene.lights.length; lightIndex++) {\r\n const light = scene.lights[lightIndex];\r\n const shadowGenerators = light.getShadowGenerators();\r\n\r\n if (light.isEnabled() && light.shadowEnabled && shadowGenerators) {\r\n const iterator = shadowGenerators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const shadowGenerator = key.value;\r\n const shadowMap = shadowGenerator.getShadowMap();\r\n if (scene.textures.indexOf(shadowMap) !== -1) {\r\n renderTargets.push(shadowMap);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nShadowGenerator._SceneComponentInitialization = (scene: Scene) => {\r\n let component = scene._getComponent(SceneComponentConstants.NAME_SHADOWGENERATOR);\r\n if (!component) {\r\n component = new ShadowGeneratorSceneComponent(scene);\r\n scene._addComponent(component);\r\n }\r\n};\r\n","import { serialize } from \"../Misc/decorators\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nNode.AddNodeConstructor(\"Light_Type_1\", (name, scene) => {\r\n return () => new DirectionalLight(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * A directional light is defined by a direction (what a surprise!).\r\n * The light is emitted from everywhere in the specified direction, and has an infinite range.\r\n * An example of a directional light is when a distance planet is lit by the apparently parallel lines of light from its sun. Light in a downward direction will light the top of an object.\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class DirectionalLight extends ShadowLight {\r\n private _shadowFrustumSize = 0;\r\n /**\r\n * Fix frustum size for the shadow generation. This is disabled if the value is 0.\r\n */\r\n @serialize()\r\n public get shadowFrustumSize(): number {\r\n return this._shadowFrustumSize;\r\n }\r\n /**\r\n * Specifies a fix frustum size for the shadow generation.\r\n */\r\n public set shadowFrustumSize(value: number) {\r\n this._shadowFrustumSize = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n private _shadowOrthoScale = 0.1;\r\n /**\r\n * Gets the shadow projection scale against the optimal computed one.\r\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\r\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\r\n */\r\n @serialize()\r\n public get shadowOrthoScale(): number {\r\n return this._shadowOrthoScale;\r\n }\r\n /**\r\n * Sets the shadow projection scale against the optimal computed one.\r\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\r\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\r\n */\r\n public set shadowOrthoScale(value: number) {\r\n this._shadowOrthoScale = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Automatically compute the projection matrix to best fit (including all the casters)\r\n * on each frame.\r\n */\r\n @serialize()\r\n public autoUpdateExtends = true;\r\n\r\n /**\r\n * Automatically compute the shadowMinZ and shadowMaxZ for the projection matrix to best fit (including all the casters)\r\n * on each frame. autoUpdateExtends must be set to true for this to work\r\n */\r\n @serialize()\r\n public autoCalcShadowZBounds = false;\r\n\r\n // Cache\r\n @serialize(\"orthoLeft\")\r\n private _orthoLeft = Number.MAX_VALUE;\r\n @serialize(\"orthoRight\")\r\n private _orthoRight = Number.MIN_VALUE;\r\n @serialize(\"orthoTop\")\r\n private _orthoTop = Number.MIN_VALUE;\r\n @serialize(\"orthoBottom\")\r\n private _orthoBottom = Number.MAX_VALUE;\r\n\r\n /**\r\n * Gets or sets the orthoLeft property used to build the light frustum\r\n */\r\n public get orthoLeft(): number {\r\n return this._orthoLeft;\r\n }\r\n\r\n public set orthoLeft(left: number) {\r\n this._orthoLeft = left;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoRight property used to build the light frustum\r\n */\r\n public get orthoRight(): number {\r\n return this._orthoRight;\r\n }\r\n\r\n public set orthoRight(right: number) {\r\n this._orthoRight = right;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoTop property used to build the light frustum\r\n */\r\n public get orthoTop(): number {\r\n return this._orthoTop;\r\n }\r\n\r\n public set orthoTop(top: number) {\r\n this._orthoTop = top;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoBottom property used to build the light frustum\r\n */\r\n public get orthoBottom(): number {\r\n return this._orthoBottom;\r\n }\r\n\r\n public set orthoBottom(bottom: number) {\r\n this._orthoBottom = bottom;\r\n }\r\n\r\n /**\r\n * Creates a DirectionalLight object in the scene, oriented towards the passed direction (Vector3).\r\n * The directional light is emitted from everywhere in the given direction.\r\n * It can cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The friendly name of the light\r\n * @param direction The direction of the light\r\n * @param scene The scene the light belongs to\r\n */\r\n constructor(name: string, direction: Vector3, scene?: Scene) {\r\n super(name, scene);\r\n this.position = direction.scale(-1.0);\r\n this.direction = direction;\r\n }\r\n\r\n /**\r\n * Returns the string \"DirectionalLight\".\r\n * @returns The class name\r\n */\r\n public getClassName(): string {\r\n return \"DirectionalLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 1.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public getTypeID(): number {\r\n return Light.LIGHTTYPEID_DIRECTIONALLIGHT;\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): void {\r\n if (this.shadowFrustumSize > 0) {\r\n this._setDefaultFixedFrustumShadowProjectionMatrix(matrix);\r\n } else {\r\n this._setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as fixed frustum projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n */\r\n protected _setDefaultFixedFrustumShadowProjectionMatrix(matrix: Matrix): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n Matrix.OrthoLHToRef(\r\n this.shadowFrustumSize,\r\n this.shadowFrustumSize,\r\n this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ,\r\n this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ,\r\n matrix,\r\n this.getScene().getEngine().isNDCHalfZRange\r\n );\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as auto extend projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n protected _setDefaultAutoExtendShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n // Check extends\r\n if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {\r\n const tempVector3 = Vector3.Zero();\r\n\r\n this._orthoLeft = Number.MAX_VALUE;\r\n this._orthoRight = Number.MIN_VALUE;\r\n this._orthoTop = Number.MIN_VALUE;\r\n this._orthoBottom = Number.MAX_VALUE;\r\n\r\n let shadowMinZ = Number.MAX_VALUE;\r\n let shadowMaxZ = Number.MIN_VALUE;\r\n\r\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\r\n const mesh = renderList[meshIndex];\r\n\r\n if (!mesh) {\r\n continue;\r\n }\r\n\r\n const boundingInfo = mesh.getBoundingInfo();\r\n const boundingBox = boundingInfo.boundingBox;\r\n\r\n for (let index = 0; index < boundingBox.vectorsWorld.length; index++) {\r\n Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);\r\n\r\n if (tempVector3.x < this._orthoLeft) {\r\n this._orthoLeft = tempVector3.x;\r\n }\r\n if (tempVector3.y < this._orthoBottom) {\r\n this._orthoBottom = tempVector3.y;\r\n }\r\n\r\n if (tempVector3.x > this._orthoRight) {\r\n this._orthoRight = tempVector3.x;\r\n }\r\n if (tempVector3.y > this._orthoTop) {\r\n this._orthoTop = tempVector3.y;\r\n }\r\n if (this.autoCalcShadowZBounds) {\r\n if (tempVector3.z < shadowMinZ) {\r\n shadowMinZ = tempVector3.z;\r\n }\r\n if (tempVector3.z > shadowMaxZ) {\r\n shadowMaxZ = tempVector3.z;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (this.autoCalcShadowZBounds) {\r\n this._shadowMinZ = shadowMinZ;\r\n this._shadowMaxZ = shadowMaxZ;\r\n }\r\n }\r\n\r\n const xOffset = this._orthoRight - this._orthoLeft;\r\n const yOffset = this._orthoTop - this._orthoBottom;\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.OrthoOffCenterLHToRef(\r\n this._orthoLeft - xOffset * this.shadowOrthoScale,\r\n this._orthoRight + xOffset * this.shadowOrthoScale,\r\n this._orthoBottom - yOffset * this.shadowOrthoScale,\r\n this._orthoTop + yOffset * this.shadowOrthoScale,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n this.getScene().getEngine().isNDCHalfZRange\r\n );\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the DirectionalLight transformed position (or position if not parented) and the passed name.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The directional light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): DirectionalLight {\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z, 1, lightIndex);\r\n return this;\r\n }\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string): Light {\r\n if (this.computeTransformedInformation()) {\r\n effect.setFloat3(lightDataUniformName, this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z);\r\n return this;\r\n }\r\n\r\n effect.setFloat3(lightDataUniformName, this.direction.x, this.direction.y, this.direction.z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n *\r\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\r\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\r\n * (when not using reverse depth buffer / NDC half Z range)\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getDepthMinZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n return !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n *\r\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\r\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\r\n * (when not using reverse depth buffer / NDC half Z range)\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getDepthMaxZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"DIRLIGHT\" + lightIndex] = true;\r\n }\r\n}\r\n","import { serialize } from \"../Misc/decorators\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport type { Effect } from \"../Materials/effect\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_0\", (name, scene) => {\r\n return () => new PointLight(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * A point light is a light defined by an unique point in world space.\r\n * The light is emitted in every direction from this point.\r\n * A good example of a point light is a standard light bulb.\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class PointLight extends ShadowLight {\r\n private _shadowAngle = Math.PI / 2;\r\n /**\r\n * Getter: In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\r\n * This specifies what angle the shadow will use to be created.\r\n *\r\n * It default to 90 degrees to work nicely with the cube texture generation for point lights shadow maps.\r\n */\r\n @serialize()\r\n public get shadowAngle(): number {\r\n return this._shadowAngle;\r\n }\r\n /**\r\n * Setter: In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\r\n * This specifies what angle the shadow will use to be created.\r\n *\r\n * It default to 90 degrees to work nicely with the cube texture generation for point lights shadow maps.\r\n */\r\n public set shadowAngle(value: number) {\r\n this._shadowAngle = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Gets the direction if it has been set.\r\n * In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\r\n */\r\n public get direction(): Vector3 {\r\n return this._direction;\r\n }\r\n\r\n /**\r\n * In case of direction provided, the shadow will not use a cube texture but simulate a spot shadow as a fallback\r\n */\r\n public set direction(value: Vector3) {\r\n const previousNeedCube = this.needCube();\r\n this._direction = value;\r\n if (this.needCube() !== previousNeedCube && this._shadowGenerators) {\r\n const iterator = this._shadowGenerators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const shadowGenerator = key.value;\r\n shadowGenerator.recreateShadowMap();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a PointLight object from the passed name and position (Vector3) and adds it in the scene.\r\n * A PointLight emits the light in every direction.\r\n * It can cast shadows.\r\n * If the scene camera is already defined and you want to set your PointLight at the camera position, just set it :\r\n * ```javascript\r\n * var pointLight = new PointLight(\"pl\", camera.position, scene);\r\n * ```\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The light friendly name\r\n * @param position The position of the point light in the scene\r\n * @param scene The scene the lights belongs to\r\n */\r\n constructor(name: string, position: Vector3, scene?: Scene) {\r\n super(name, scene);\r\n this.position = position;\r\n }\r\n\r\n /**\r\n * Returns the string \"PointLight\"\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"PointLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 0.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public getTypeID(): number {\r\n return Light.LIGHTTYPEID_POINTLIGHT;\r\n }\r\n\r\n /**\r\n * Specifies whether or not the shadowmap should be a cube texture.\r\n * @returns true if the shadowmap needs to be a cube texture.\r\n */\r\n public needCube(): boolean {\r\n return !this.direction;\r\n }\r\n\r\n /**\r\n * Returns a new Vector3 aligned with the PointLight cube system according to the passed cube face index (integer).\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n public getShadowDirection(faceIndex?: number): Vector3 {\r\n if (this.direction) {\r\n return super.getShadowDirection(faceIndex);\r\n } else {\r\n switch (faceIndex) {\r\n case 0:\r\n return new Vector3(1.0, 0.0, 0.0);\r\n case 1:\r\n return new Vector3(-1.0, 0.0, 0.0);\r\n case 2:\r\n return new Vector3(0.0, -1.0, 0.0);\r\n case 3:\r\n return new Vector3(0.0, 1.0, 0.0);\r\n case 4:\r\n return new Vector3(0.0, 0.0, 1.0);\r\n case 5:\r\n return new Vector3(0.0, 0.0, -1.0);\r\n }\r\n }\r\n\r\n return Vector3.Zero();\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as a left-handed perspective projection matrix with the following settings :\r\n * - fov = PI / 2\r\n * - aspect ratio : 1.0\r\n * - z-near and far equal to the active camera minZ and maxZ.\r\n * Returns the PointLight.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.PerspectiveFovLHToRef(\r\n this.shadowAngle,\r\n 1.0,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n true,\r\n this._scene.getEngine().isNDCHalfZRange,\r\n undefined,\r\n useReverseDepthBuffer\r\n );\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"vLightFalloff\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the PointLight transformed position (or position, if none) and passed name (string).\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The point light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): PointLight {\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, 0.0, lightIndex);\r\n } else {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.position.x, this.position.y, this.position.z, 0, lightIndex);\r\n }\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightFalloff\", this.range, this._inverseSquaredRange, 0, 0, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string) {\r\n if (this.computeTransformedInformation()) {\r\n effect.setFloat3(lightDataUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z);\r\n } else {\r\n effect.setFloat3(lightDataUniformName, this.position.x, this.position.y, this.position.z);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"POINTLIGHT\" + lightIndex] = true;\r\n }\r\n}\r\n","import { serialize, serializeAsTexture } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { ProceduralTexture } from \"../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_2\", (name, scene) => {\r\n return () => new SpotLight(name, Vector3.Zero(), Vector3.Zero(), 0, 0, scene);\r\n});\r\n\r\n/**\r\n * A spot light is defined by a position, a direction, an angle, and an exponent.\r\n * These values define a cone of light starting from the position, emitting toward the direction.\r\n * The angle, in radians, defines the size (field of illumination) of the spotlight's conical beam,\r\n * and the exponent defines the speed of the decay of the light with distance (reach).\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class SpotLight extends ShadowLight {\r\n /*\r\n upVector , rightVector and direction will form the coordinate system for this spot light.\r\n These three vectors will be used as projection matrix when doing texture projection.\r\n\r\n Also we have the following rules always holds:\r\n direction cross up = right\r\n right cross direction = up\r\n up cross right = forward\r\n\r\n light_near and light_far will control the range of the texture projection. If a plane is\r\n out of the range in spot light space, there is no texture projection.\r\n */\r\n\r\n private _angle: number;\r\n private _innerAngle: number = 0;\r\n private _cosHalfAngle: number;\r\n\r\n private _lightAngleScale: number;\r\n private _lightAngleOffset: number;\r\n\r\n /**\r\n * Gets the cone angle of the spot light in Radians.\r\n */\r\n @serialize()\r\n public get angle(): number {\r\n return this._angle;\r\n }\r\n /**\r\n * Sets the cone angle of the spot light in Radians.\r\n */\r\n public set angle(value: number) {\r\n this._angle = value;\r\n this._cosHalfAngle = Math.cos(value * 0.5);\r\n this._projectionTextureProjectionLightDirty = true;\r\n this.forceProjectionMatrixCompute();\r\n this._computeAngleValues();\r\n }\r\n\r\n /**\r\n * Only used in gltf falloff mode, this defines the angle where\r\n * the directional falloff will start before cutting at angle which could be seen\r\n * as outer angle.\r\n */\r\n @serialize()\r\n public get innerAngle(): number {\r\n return this._innerAngle;\r\n }\r\n /**\r\n * Only used in gltf falloff mode, this defines the angle where\r\n * the directional falloff will start before cutting at angle which could be seen\r\n * as outer angle.\r\n */\r\n public set innerAngle(value: number) {\r\n this._innerAngle = value;\r\n this._computeAngleValues();\r\n }\r\n\r\n private _shadowAngleScale: number;\r\n /**\r\n * Allows scaling the angle of the light for shadow generation only.\r\n */\r\n @serialize()\r\n public get shadowAngleScale(): number {\r\n return this._shadowAngleScale;\r\n }\r\n /**\r\n * Allows scaling the angle of the light for shadow generation only.\r\n */\r\n public set shadowAngleScale(value: number) {\r\n this._shadowAngleScale = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * The light decay speed with the distance from the emission spot.\r\n */\r\n @serialize()\r\n public exponent: number;\r\n\r\n private _projectionTextureMatrix = Matrix.Zero();\r\n /**\r\n * Allows reading the projection texture\r\n */\r\n public get projectionTextureMatrix(): Matrix {\r\n return this._projectionTextureMatrix;\r\n }\r\n\r\n protected _projectionTextureLightNear: number = 1e-6;\r\n /**\r\n * Gets the near clip of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureLightNear(): number {\r\n return this._projectionTextureLightNear;\r\n }\r\n /**\r\n * Sets the near clip of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureLightNear(value: number) {\r\n this._projectionTextureLightNear = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n protected _projectionTextureLightFar: number = 1000.0;\r\n /**\r\n * Gets the far clip of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureLightFar(): number {\r\n return this._projectionTextureLightFar;\r\n }\r\n /**\r\n * Sets the far clip of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureLightFar(value: number) {\r\n this._projectionTextureLightFar = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n protected _projectionTextureUpDirection: Vector3 = Vector3.Up();\r\n /**\r\n * Gets the Up vector of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureUpDirection(): Vector3 {\r\n return this._projectionTextureUpDirection;\r\n }\r\n /**\r\n * Sets the Up vector of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureUpDirection(value: Vector3) {\r\n this._projectionTextureUpDirection = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n @serializeAsTexture(\"projectedLightTexture\")\r\n private _projectionTexture: Nullable;\r\n\r\n /**\r\n * Gets the projection texture of the light.\r\n */\r\n public get projectionTexture(): Nullable {\r\n return this._projectionTexture;\r\n }\r\n /**\r\n * Sets the projection texture of the light.\r\n */\r\n public set projectionTexture(value: Nullable) {\r\n if (this._projectionTexture === value) {\r\n return;\r\n }\r\n this._projectionTexture = value;\r\n this._projectionTextureDirty = true;\r\n if (this._projectionTexture && !this._projectionTexture.isReady()) {\r\n if (SpotLight._IsProceduralTexture(this._projectionTexture)) {\r\n this._projectionTexture.getEffect().executeWhenCompiled(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n } else if (SpotLight._IsTexture(this._projectionTexture)) {\r\n this._projectionTexture.onLoadObservable.addOnce(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n }\r\n }\r\n }\r\n\r\n private static _IsProceduralTexture(texture: BaseTexture): texture is ProceduralTexture {\r\n return (texture as ProceduralTexture).onGeneratedObservable !== undefined;\r\n }\r\n\r\n private static _IsTexture(texture: BaseTexture): texture is Texture {\r\n return (texture as Texture).onLoadObservable !== undefined;\r\n }\r\n\r\n private _projectionTextureViewLightDirty = true;\r\n private _projectionTextureProjectionLightDirty = true;\r\n private _projectionTextureDirty = true;\r\n private _projectionTextureViewTargetVector = Vector3.Zero();\r\n private _projectionTextureViewLightMatrix = Matrix.Zero();\r\n\r\n private _projectionTextureProjectionLightMatrix = Matrix.Zero();\r\n /**\r\n * Gets or sets the light projection matrix as used by the projection texture\r\n */\r\n public get projectionTextureProjectionLightMatrix(): Matrix {\r\n return this._projectionTextureProjectionLightMatrix;\r\n }\r\n\r\n public set projectionTextureProjectionLightMatrix(projection: Matrix) {\r\n this._projectionTextureProjectionLightMatrix = projection;\r\n this._projectionTextureProjectionLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n }\r\n\r\n private _projectionTextureScalingMatrix = Matrix.FromValues(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);\r\n\r\n /**\r\n * Creates a SpotLight object in the scene. A spot light is a simply light oriented cone.\r\n * It can cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The light friendly name\r\n * @param position The position of the spot light in the scene\r\n * @param direction The direction of the light in the scene\r\n * @param angle The cone angle of the light in Radians\r\n * @param exponent The light decay speed with the distance from the emission spot\r\n * @param scene The scene the lights belongs to\r\n */\r\n constructor(name: string, position: Vector3, direction: Vector3, angle: number, exponent: number, scene?: Scene) {\r\n super(name, scene);\r\n\r\n this.position = position;\r\n this.direction = direction;\r\n this.angle = angle;\r\n this.exponent = exponent;\r\n }\r\n\r\n /**\r\n * Returns the string \"SpotLight\".\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"SpotLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 2.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public getTypeID(): number {\r\n return Light.LIGHTTYPEID_SPOTLIGHT;\r\n }\r\n\r\n /**\r\n * Overrides the direction setter to recompute the projection texture view light Matrix.\r\n * @param value\r\n */\r\n protected _setDirection(value: Vector3) {\r\n super._setDirection(value);\r\n this._projectionTextureViewLightDirty = true;\r\n }\r\n\r\n /**\r\n * Overrides the position setter to recompute the projection texture view light Matrix.\r\n * @param value\r\n */\r\n protected _setPosition(value: Vector3) {\r\n super._setPosition(value);\r\n this._projectionTextureViewLightDirty = true;\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as perspective projection matrix for the shadows and the passed view matrix with the fov equal to the SpotLight angle and and aspect ratio of 1.0.\r\n * Returns the SpotLight.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n this._shadowAngleScale = this._shadowAngleScale || 1;\r\n const angle = this._shadowAngleScale * this._angle;\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.PerspectiveFovLHToRef(\r\n angle,\r\n 1.0,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n true,\r\n this._scene.getEngine().isNDCHalfZRange,\r\n undefined,\r\n useReverseDepthBuffer\r\n );\r\n }\r\n\r\n protected _computeProjectionTextureViewLightMatrix(): void {\r\n this._projectionTextureViewLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n\r\n this.getAbsolutePosition().addToRef(this.direction, this._projectionTextureViewTargetVector);\r\n Matrix.LookAtLHToRef(this.getAbsolutePosition(), this._projectionTextureViewTargetVector, this._projectionTextureUpDirection, this._projectionTextureViewLightMatrix);\r\n }\r\n\r\n protected _computeProjectionTextureProjectionLightMatrix(): void {\r\n this._projectionTextureProjectionLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n\r\n const lightFar = this.projectionTextureLightFar;\r\n const lightNear = this.projectionTextureLightNear;\r\n\r\n const P = lightFar / (lightFar - lightNear);\r\n const Q = -P * lightNear;\r\n const S = 1.0 / Math.tan(this._angle / 2.0);\r\n const A = 1.0;\r\n\r\n Matrix.FromValuesToRef(S / A, 0.0, 0.0, 0.0, 0.0, S, 0.0, 0.0, 0.0, 0.0, P, 1.0, 0.0, 0.0, Q, 0.0, this._projectionTextureProjectionLightMatrix);\r\n }\r\n\r\n /**\r\n * Main function for light texture projection matrix computing.\r\n */\r\n protected _computeProjectionTextureMatrix(): void {\r\n this._projectionTextureDirty = false;\r\n\r\n this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix, this._projectionTextureMatrix);\r\n if (this._projectionTexture instanceof Texture) {\r\n const u = this._projectionTexture.uScale / 2.0;\r\n const v = this._projectionTexture.vScale / 2.0;\r\n Matrix.FromValuesToRef(u, 0.0, 0.0, 0.0, 0.0, v, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, this._projectionTextureScalingMatrix);\r\n }\r\n this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix, this._projectionTextureMatrix);\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDirection\", 3);\r\n this._uniformBuffer.addUniform(\"vLightFalloff\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n private _computeAngleValues(): void {\r\n this._lightAngleScale = 1.0 / Math.max(0.001, Math.cos(this._innerAngle * 0.5) - this._cosHalfAngle);\r\n this._lightAngleOffset = -this._cosHalfAngle * this._lightAngleScale;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the Light textures.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The light\r\n */\r\n public transferTexturesToEffect(effect: Effect, lightIndex: string): Light {\r\n if (this.projectionTexture && this.projectionTexture.isReady()) {\r\n if (this._projectionTextureViewLightDirty) {\r\n this._computeProjectionTextureViewLightMatrix();\r\n }\r\n if (this._projectionTextureProjectionLightDirty) {\r\n this._computeProjectionTextureProjectionLightMatrix();\r\n }\r\n if (this._projectionTextureDirty) {\r\n this._computeProjectionTextureMatrix();\r\n }\r\n effect.setMatrix(\"textureProjectionMatrix\" + lightIndex, this._projectionTextureMatrix);\r\n effect.setTexture(\"projectionLightSampler\" + lightIndex, this.projectionTexture);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the SpotLight transformed position (or position if not parented) and normalized direction.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The spot light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): SpotLight {\r\n let normalizeDirection;\r\n\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent, lightIndex);\r\n\r\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\r\n } else {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.position.x, this.position.y, this.position.z, this.exponent, lightIndex);\r\n\r\n normalizeDirection = Vector3.Normalize(this.direction);\r\n }\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightDirection\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, this._cosHalfAngle, lightIndex);\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightFalloff\", this.range, this._inverseSquaredRange, this._lightAngleScale, this._lightAngleOffset, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string) {\r\n let normalizeDirection;\r\n\r\n if (this.computeTransformedInformation()) {\r\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\r\n } else {\r\n normalizeDirection = Vector3.Normalize(this.direction);\r\n }\r\n\r\n if (this.getScene().useRightHandedSystem) {\r\n effect.setFloat3(lightDataUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z);\r\n } else {\r\n effect.setFloat3(lightDataUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes the light and the associated resources.\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n if (this._projectionTexture) {\r\n this._projectionTexture.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n public getDepthMinZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? minZ : this._scene.getEngine().isNDCHalfZRange ? 0 : minZ;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n public getDepthMaxZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : maxZ;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"SPOTLIGHT\" + lightIndex] = true;\r\n defines[\"PROJECTEDLIGHTTEXTURE\" + lightIndex] = this.projectionTexture && this.projectionTexture.isReady() ? true : false;\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { Scene, IDisposable } from \"../scene\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"./observable\";\r\nimport { Observable } from \"./observable\";\r\n\r\n/**\r\n * Defines the root class used to create scene optimization to use with SceneOptimizer\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Creates the SceneOptimization object\r\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\r\n */\r\n constructor(\r\n /**\r\n * Defines the priority of this optimization (0 by default which means first in the list)\r\n */\r\n public priority: number = 0\r\n ) {}\r\n}\r\n\r\n/**\r\n * Defines an optimization used to reduce the size of render target textures\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class TextureOptimization extends SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Reducing render target texture size to \" + this.maximumSize;\r\n }\r\n\r\n /**\r\n * Creates the TextureOptimization object\r\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\r\n * @param maximumSize defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter\r\n * @param step defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.\r\n */\r\n constructor(\r\n /**\r\n * Defines the priority of this optimization (0 by default which means first in the list)\r\n */\r\n public priority: number = 0,\r\n /**\r\n * Defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter\r\n */\r\n public maximumSize: number = 1024,\r\n /**\r\n * Defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.\r\n */\r\n public step = 0.5\r\n ) {\r\n super(priority);\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n let allDone = true;\r\n for (let index = 0; index < scene.textures.length; index++) {\r\n const texture = scene.textures[index];\r\n\r\n if (!texture.canRescale || (texture).getContext) {\r\n continue;\r\n }\r\n\r\n const currentSize = texture.getSize();\r\n const maxDimension = Math.max(currentSize.width, currentSize.height);\r\n\r\n if (maxDimension > this.maximumSize) {\r\n texture.scale(this.step);\r\n allDone = false;\r\n }\r\n }\r\n\r\n return allDone;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to increase or decrease the rendering resolution\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class HardwareScalingOptimization extends SceneOptimization {\r\n private _currentScale = -1;\r\n private _directionOffset = 1;\r\n\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Setting hardware scaling level to \" + this._currentScale;\r\n }\r\n\r\n /**\r\n * Creates the HardwareScalingOptimization object\r\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\r\n * @param maximumScale defines the maximum scale to use (2 by default)\r\n * @param step defines the step to use between two passes (0.5 by default)\r\n */\r\n constructor(\r\n /**\r\n * Defines the priority of this optimization (0 by default which means first in the list)\r\n */\r\n public priority: number = 0,\r\n /**\r\n * Defines the maximum scale to use (2 by default)\r\n */\r\n public maximumScale: number = 2,\r\n /**\r\n * Defines the step to use between two passes (0.5 by default)\r\n */\r\n public step: number = 0.25\r\n ) {\r\n super(priority);\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n if (this._currentScale === -1) {\r\n this._currentScale = scene.getEngine().getHardwareScalingLevel();\r\n if (this._currentScale > this.maximumScale) {\r\n this._directionOffset = -1;\r\n }\r\n }\r\n\r\n this._currentScale += this._directionOffset * this.step;\r\n\r\n scene.getEngine().setHardwareScalingLevel(this._currentScale);\r\n\r\n return this._directionOffset === 1 ? this._currentScale >= this.maximumScale : this._currentScale <= this.maximumScale;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to remove shadows\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class ShadowsOptimization extends SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Turning shadows on/off\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n scene.shadowsEnabled = optimizer.isInImprovementMode;\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to turn post-processes off\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class PostProcessesOptimization extends SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Turning post-processes on/off\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n scene.postProcessesEnabled = optimizer.isInImprovementMode;\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to turn lens flares off\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class LensFlaresOptimization extends SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Turning lens flares on/off\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n scene.lensFlaresEnabled = optimizer.isInImprovementMode;\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization based on user defined callback.\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class CustomOptimization extends SceneOptimization {\r\n /**\r\n * Callback called to apply the custom optimization.\r\n */\r\n public onApply: (scene: Scene, optimizer: SceneOptimizer) => boolean;\r\n\r\n /**\r\n * Callback called to get custom description\r\n */\r\n public onGetDescription: () => string;\r\n\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n if (this.onGetDescription) {\r\n return this.onGetDescription();\r\n }\r\n\r\n return \"Running user defined callback\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n if (this.onApply) {\r\n return this.onApply(scene, optimizer);\r\n }\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to turn particles off\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class ParticlesOptimization extends SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Turning particles on/off\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n scene.particlesEnabled = optimizer.isInImprovementMode;\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to turn render targets off\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class RenderTargetsOptimization extends SceneOptimization {\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Turning render targets off\";\r\n }\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer): boolean {\r\n scene.renderTargetsEnabled = optimizer.isInImprovementMode;\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines an optimization used to merge meshes with compatible materials\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class MergeMeshesOptimization extends SceneOptimization {\r\n private static _UpdateSelectionTree = false;\r\n\r\n /**\r\n * Gets or sets a boolean which defines if optimization octree has to be updated\r\n */\r\n public static get UpdateSelectionTree(): boolean {\r\n return MergeMeshesOptimization._UpdateSelectionTree;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean which defines if optimization octree has to be updated\r\n */\r\n public static set UpdateSelectionTree(value: boolean) {\r\n MergeMeshesOptimization._UpdateSelectionTree = value;\r\n }\r\n\r\n /**\r\n * Gets a string describing the action executed by the current optimization\r\n * @returns description string\r\n */\r\n public getDescription(): string {\r\n return \"Merging similar meshes together\";\r\n }\r\n\r\n private _canBeMerged = (abstractMesh: AbstractMesh): boolean => {\r\n if (!(abstractMesh instanceof Mesh)) {\r\n return false;\r\n }\r\n\r\n const mesh = abstractMesh;\r\n\r\n if (mesh.isDisposed()) {\r\n return false;\r\n }\r\n\r\n if (!mesh.isVisible || !mesh.isEnabled()) {\r\n return false;\r\n }\r\n\r\n if (mesh.instances.length > 0) {\r\n return false;\r\n }\r\n\r\n if (mesh.skeleton || mesh.hasLODLevels) {\r\n return false;\r\n }\r\n\r\n if (mesh.getTotalVertices() === 0) {\r\n return false;\r\n }\r\n\r\n return true;\r\n };\r\n\r\n /**\r\n * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization\r\n * @param scene defines the current scene where to apply this optimization\r\n * @param optimizer defines the current optimizer\r\n * @param updateSelectionTree defines that the selection octree has to be updated (false by default)\r\n * @returns true if everything that can be done was applied\r\n */\r\n public apply(scene: Scene, optimizer: SceneOptimizer, updateSelectionTree?: boolean): boolean {\r\n const globalPool = scene.meshes.slice(0);\r\n let globalLength = globalPool.length;\r\n\r\n for (let index = 0; index < globalLength; index++) {\r\n const currentPool = new Array();\r\n const current = globalPool[index];\r\n\r\n // Checks\r\n if (!this._canBeMerged(current)) {\r\n continue;\r\n }\r\n\r\n currentPool.push(current);\r\n\r\n // Find compatible meshes\r\n for (let subIndex = index + 1; subIndex < globalLength; subIndex++) {\r\n const otherMesh = globalPool[subIndex];\r\n\r\n if (!this._canBeMerged(otherMesh)) {\r\n continue;\r\n }\r\n\r\n if (otherMesh.material !== current.material) {\r\n continue;\r\n }\r\n\r\n if (otherMesh.checkCollisions !== current.checkCollisions) {\r\n continue;\r\n }\r\n\r\n currentPool.push(otherMesh);\r\n globalLength--;\r\n\r\n globalPool.splice(subIndex, 1);\r\n\r\n subIndex--;\r\n }\r\n\r\n if (currentPool.length < 2) {\r\n continue;\r\n }\r\n\r\n // Merge meshes\r\n Mesh.MergeMeshes(currentPool, undefined, true);\r\n }\r\n\r\n // Call the octree system optimization if it is defined.\r\n const sceneAsAny = scene as any;\r\n if (sceneAsAny.createOrUpdateSelectionOctree) {\r\n if (updateSelectionTree != undefined) {\r\n if (updateSelectionTree) {\r\n sceneAsAny.createOrUpdateSelectionOctree();\r\n }\r\n } else if (MergeMeshesOptimization.UpdateSelectionTree) {\r\n sceneAsAny.createOrUpdateSelectionOctree();\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Defines a list of options used by SceneOptimizer\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class SceneOptimizerOptions {\r\n /**\r\n * Gets the list of optimizations to apply\r\n */\r\n public optimizations = new Array();\r\n\r\n /**\r\n * Creates a new list of options used by SceneOptimizer\r\n * @param targetFrameRate defines the target frame rate to reach (60 by default)\r\n * @param trackerDuration defines the interval between two checks (2000ms by default)\r\n */\r\n constructor(\r\n /**\r\n * Defines the target frame rate to reach (60 by default)\r\n */\r\n public targetFrameRate: number = 60,\r\n /**\r\n * Defines the interval between two checks (2000ms by default)\r\n */\r\n public trackerDuration: number = 2000\r\n ) {}\r\n\r\n /**\r\n * Add a new optimization\r\n * @param optimization defines the SceneOptimization to add to the list of active optimizations\r\n * @returns the current SceneOptimizerOptions\r\n */\r\n public addOptimization(optimization: SceneOptimization): SceneOptimizerOptions {\r\n this.optimizations.push(optimization);\r\n return this;\r\n }\r\n\r\n /**\r\n * Add a new custom optimization\r\n * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)\r\n * @param onGetDescription defines the callback called to get the description attached with the optimization.\r\n * @param priority defines the priority of this optimization (0 by default which means first in the list)\r\n * @returns the current SceneOptimizerOptions\r\n */\r\n public addCustomOptimization(onApply: (scene: Scene, optimizer: SceneOptimizer) => boolean, onGetDescription: () => string, priority: number = 0): SceneOptimizerOptions {\r\n const optimization = new CustomOptimization(priority);\r\n optimization.onApply = onApply;\r\n optimization.onGetDescription = onGetDescription;\r\n\r\n this.optimizations.push(optimization);\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a list of pre-defined optimizations aimed to reduce the visual impact on the scene\r\n * @param targetFrameRate defines the target frame rate (60 by default)\r\n * @returns a SceneOptimizerOptions object\r\n */\r\n public static LowDegradationAllowed(targetFrameRate?: number): SceneOptimizerOptions {\r\n const result = new SceneOptimizerOptions(targetFrameRate);\r\n\r\n let priority = 0;\r\n result.addOptimization(new MergeMeshesOptimization(priority));\r\n result.addOptimization(new ShadowsOptimization(priority));\r\n result.addOptimization(new LensFlaresOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new PostProcessesOptimization(priority));\r\n result.addOptimization(new ParticlesOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new TextureOptimization(priority, 1024));\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a list of pre-defined optimizations aimed to have a moderate impact on the scene visual\r\n * @param targetFrameRate defines the target frame rate (60 by default)\r\n * @returns a SceneOptimizerOptions object\r\n */\r\n public static ModerateDegradationAllowed(targetFrameRate?: number): SceneOptimizerOptions {\r\n const result = new SceneOptimizerOptions(targetFrameRate);\r\n\r\n let priority = 0;\r\n result.addOptimization(new MergeMeshesOptimization(priority));\r\n result.addOptimization(new ShadowsOptimization(priority));\r\n result.addOptimization(new LensFlaresOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new PostProcessesOptimization(priority));\r\n result.addOptimization(new ParticlesOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new TextureOptimization(priority, 512));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new RenderTargetsOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new HardwareScalingOptimization(priority, 2));\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a list of pre-defined optimizations aimed to have a big impact on the scene visual\r\n * @param targetFrameRate defines the target frame rate (60 by default)\r\n * @returns a SceneOptimizerOptions object\r\n */\r\n public static HighDegradationAllowed(targetFrameRate?: number): SceneOptimizerOptions {\r\n const result = new SceneOptimizerOptions(targetFrameRate);\r\n\r\n let priority = 0;\r\n result.addOptimization(new MergeMeshesOptimization(priority));\r\n result.addOptimization(new ShadowsOptimization(priority));\r\n result.addOptimization(new LensFlaresOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new PostProcessesOptimization(priority));\r\n result.addOptimization(new ParticlesOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new TextureOptimization(priority, 256));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new RenderTargetsOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n result.addOptimization(new HardwareScalingOptimization(priority, 4));\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/**\r\n * Class used to run optimizations in order to reach a target frame rate\r\n * @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer\r\n */\r\nexport class SceneOptimizer implements IDisposable {\r\n private _isRunning = false;\r\n private _options: SceneOptimizerOptions;\r\n private _scene: Scene;\r\n private _currentPriorityLevel = 0;\r\n private _targetFrameRate = 60;\r\n private _trackerDuration = 2000;\r\n private _currentFrameRate = 0;\r\n private _sceneDisposeObserver: Nullable>;\r\n private _improvementMode = false;\r\n\r\n /**\r\n * Defines an observable called when the optimizer reaches the target frame rate\r\n */\r\n public onSuccessObservable = new Observable();\r\n /**\r\n * Defines an observable called when the optimizer enables an optimization\r\n */\r\n public onNewOptimizationAppliedObservable = new Observable();\r\n /**\r\n * Defines an observable called when the optimizer is not able to reach the target frame rate\r\n */\r\n public onFailureObservable = new Observable();\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the optimizer is in improvement mode\r\n */\r\n public get isInImprovementMode(): boolean {\r\n return this._improvementMode;\r\n }\r\n\r\n public set isInImprovementMode(value: boolean) {\r\n this._improvementMode = value;\r\n }\r\n\r\n /**\r\n * Gets the current priority level (0 at start)\r\n */\r\n public get currentPriorityLevel(): number {\r\n return this._currentPriorityLevel;\r\n }\r\n\r\n /**\r\n * Gets the current frame rate checked by the SceneOptimizer\r\n */\r\n public get currentFrameRate(): number {\r\n return this._currentFrameRate;\r\n }\r\n\r\n /**\r\n * Gets or sets the current target frame rate (60 by default)\r\n */\r\n public get targetFrameRate(): number {\r\n return this._targetFrameRate;\r\n }\r\n\r\n /**\r\n * Gets or sets the current target frame rate (60 by default)\r\n */\r\n public set targetFrameRate(value: number) {\r\n this._targetFrameRate = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the current interval between two checks (every 2000ms by default)\r\n */\r\n public get trackerDuration(): number {\r\n return this._trackerDuration;\r\n }\r\n\r\n /**\r\n * Gets or sets the current interval between two checks (every 2000ms by default)\r\n */\r\n public set trackerDuration(value: number) {\r\n this._trackerDuration = value;\r\n }\r\n\r\n /**\r\n * Gets the list of active optimizations\r\n */\r\n public get optimizations(): SceneOptimization[] {\r\n return this._options.optimizations;\r\n }\r\n\r\n /**\r\n * Creates a new SceneOptimizer\r\n * @param scene defines the scene to work on\r\n * @param options defines the options to use with the SceneOptimizer\r\n * @param autoGeneratePriorities defines if priorities must be generated and not read from SceneOptimization property (true by default)\r\n * @param improvementMode defines if the scene optimizer must run the maximum optimization while staying over a target frame instead of trying to reach the target framerate (false by default)\r\n */\r\n public constructor(scene: Scene, options?: SceneOptimizerOptions, autoGeneratePriorities = true, improvementMode = false) {\r\n if (!options) {\r\n this._options = new SceneOptimizerOptions();\r\n } else {\r\n this._options = options;\r\n }\r\n\r\n if (this._options.targetFrameRate) {\r\n this._targetFrameRate = this._options.targetFrameRate;\r\n }\r\n\r\n if (this._options.trackerDuration) {\r\n this._trackerDuration = this._options.trackerDuration;\r\n }\r\n\r\n if (autoGeneratePriorities) {\r\n let priority = 0;\r\n for (const optim of this._options.optimizations) {\r\n optim.priority = priority++;\r\n }\r\n }\r\n\r\n this._improvementMode = improvementMode;\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n this._sceneDisposeObserver = this._scene.onDisposeObservable.add(() => {\r\n this._sceneDisposeObserver = null;\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Stops the current optimizer\r\n */\r\n public stop() {\r\n this._isRunning = false;\r\n }\r\n\r\n /**\r\n * Reset the optimizer to initial step (current priority level = 0)\r\n */\r\n public reset() {\r\n this._currentPriorityLevel = 0;\r\n }\r\n\r\n /**\r\n * Start the optimizer. By default it will try to reach a specific framerate\r\n * but if the optimizer is set with improvementMode === true then it will run all optimization while frame rate is above the target frame rate\r\n */\r\n public start() {\r\n if (this._isRunning) {\r\n return;\r\n }\r\n\r\n this._isRunning = true;\r\n\r\n // Let's wait for the scene to be ready before running our check\r\n this._scene.executeWhenReady(() => {\r\n setTimeout(() => {\r\n this._checkCurrentState();\r\n }, this._trackerDuration);\r\n });\r\n }\r\n\r\n private _checkCurrentState() {\r\n if (!this._isRunning) {\r\n return;\r\n }\r\n\r\n const scene = this._scene;\r\n const options = this._options;\r\n\r\n this._currentFrameRate = Math.round(scene.getEngine().getFps());\r\n\r\n if ((this._improvementMode && this._currentFrameRate <= this._targetFrameRate) || (!this._improvementMode && this._currentFrameRate >= this._targetFrameRate)) {\r\n this._isRunning = false;\r\n this.onSuccessObservable.notifyObservers(this);\r\n return;\r\n }\r\n\r\n // Apply current level of optimizations\r\n let allDone = true;\r\n let noOptimizationApplied = true;\r\n for (let index = 0; index < options.optimizations.length; index++) {\r\n const optimization = options.optimizations[index];\r\n\r\n if (optimization.priority === this._currentPriorityLevel) {\r\n noOptimizationApplied = false;\r\n allDone = allDone && optimization.apply(scene, this);\r\n this.onNewOptimizationAppliedObservable.notifyObservers(optimization);\r\n }\r\n }\r\n\r\n // If no optimization was applied, this is a failure :(\r\n if (noOptimizationApplied) {\r\n this._isRunning = false;\r\n this.onFailureObservable.notifyObservers(this);\r\n\r\n return;\r\n }\r\n\r\n // If all optimizations were done, move to next level\r\n if (allDone) {\r\n this._currentPriorityLevel++;\r\n }\r\n\r\n // Let's the system running for a specific amount of time before checking FPS\r\n scene.executeWhenReady(() => {\r\n setTimeout(() => {\r\n this._checkCurrentState();\r\n }, this._trackerDuration);\r\n });\r\n }\r\n\r\n /**\r\n * Release all resources\r\n */\r\n public dispose(): void {\r\n this.stop();\r\n this.onSuccessObservable.clear();\r\n this.onFailureObservable.clear();\r\n this.onNewOptimizationAppliedObservable.clear();\r\n if (this._sceneDisposeObserver) {\r\n this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Helper function to create a SceneOptimizer with one single line of code\r\n * @param scene defines the scene to work on\r\n * @param options defines the options to use with the SceneOptimizer\r\n * @param onSuccess defines a callback to call on success\r\n * @param onFailure defines a callback to call on failure\r\n * @returns the new SceneOptimizer object\r\n */\r\n public static OptimizeAsync(scene: Scene, options?: SceneOptimizerOptions, onSuccess?: () => void, onFailure?: () => void): SceneOptimizer {\r\n const optimizer = new SceneOptimizer(scene, options || SceneOptimizerOptions.ModerateDegradationAllowed(), false);\r\n\r\n if (onSuccess) {\r\n optimizer.onSuccessObservable.add(() => {\r\n onSuccess();\r\n });\r\n }\r\n\r\n if (onFailure) {\r\n optimizer.onFailureObservable.add(() => {\r\n onFailure();\r\n });\r\n }\r\n\r\n optimizer.start();\r\n\r\n return optimizer;\r\n }\r\n}\r\n","import type { Geometry } from \"../Meshes/geometry\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { SerializationHelper } from \"./decorators\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { CubeTexture } from \"../Materials/Textures/cubeTexture\";\r\nimport type { Node } from \"../node\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\n\r\nlet serializedGeometries: Geometry[] = [];\r\nconst SerializeGeometry = (geometry: Geometry, serializationGeometries: any): any => {\r\n if (geometry.doNotSerialize) {\r\n return;\r\n }\r\n\r\n serializationGeometries.vertexData.push(geometry.serializeVerticeData());\r\n\r\n (serializedGeometries)[geometry.id] = true;\r\n};\r\n\r\nconst SerializeMesh = (mesh: Mesh, serializationScene: any): any => {\r\n const serializationObject: any = {};\r\n\r\n // Geometry\r\n const geometry = mesh._geometry;\r\n if (geometry) {\r\n if (!mesh.getScene().getGeometryById(geometry.id)) {\r\n // Geometry was in the memory but not added to the scene, nevertheless it's better to serialize to be able to reload the mesh with its geometry\r\n SerializeGeometry(geometry, serializationScene.geometries);\r\n }\r\n }\r\n\r\n // Custom\r\n if (mesh.serialize) {\r\n mesh.serialize(serializationObject);\r\n }\r\n\r\n return serializationObject;\r\n};\r\n\r\nconst FinalizeSingleNode = (node: Node, serializationObject: any) => {\r\n if ((node as Mesh)._isMesh) {\r\n const mesh = node as Mesh;\r\n //only works if the mesh is already loaded\r\n if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {\r\n const serializeMaterial = (material: Material) => {\r\n serializationObject.materials = serializationObject.materials || [];\r\n if (mesh.material && !serializationObject.materials.some((mat: Material) => mat.id === (mesh.material).id)) {\r\n serializationObject.materials.push(material.serialize());\r\n }\r\n };\r\n\r\n //serialize material\r\n if (mesh.material && !mesh.material.doNotSerialize) {\r\n if (mesh.material instanceof MultiMaterial) {\r\n serializationObject.multiMaterials = serializationObject.multiMaterials || [];\r\n if (!serializationObject.multiMaterials.some((mat: Material) => mat.id === (mesh.material).id)) {\r\n serializationObject.multiMaterials.push(mesh.material.serialize());\r\n for (const submaterial of mesh.material.subMaterials) {\r\n if (submaterial) {\r\n serializeMaterial(submaterial);\r\n }\r\n }\r\n }\r\n } else {\r\n serializeMaterial(mesh.material);\r\n }\r\n } else if (!mesh.material) {\r\n serializeMaterial(mesh.getScene().defaultMaterial);\r\n }\r\n\r\n //serialize geometry\r\n const geometry = mesh._geometry;\r\n if (geometry) {\r\n if (!serializationObject.geometries) {\r\n serializationObject.geometries = {};\r\n\r\n serializationObject.geometries.boxes = [];\r\n serializationObject.geometries.spheres = [];\r\n serializationObject.geometries.cylinders = [];\r\n serializationObject.geometries.toruses = [];\r\n serializationObject.geometries.grounds = [];\r\n serializationObject.geometries.planes = [];\r\n serializationObject.geometries.torusKnots = [];\r\n serializationObject.geometries.vertexData = [];\r\n }\r\n\r\n SerializeGeometry(geometry, serializationObject.geometries);\r\n }\r\n // Skeletons\r\n if (mesh.skeleton && !mesh.skeleton.doNotSerialize) {\r\n serializationObject.skeletons = serializationObject.skeletons || [];\r\n serializationObject.skeletons.push(mesh.skeleton.serialize());\r\n }\r\n\r\n //serialize the actual mesh\r\n serializationObject.meshes = serializationObject.meshes || [];\r\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\r\n }\r\n } else if (node.getClassName() === \"TransformNode\") {\r\n const transformNode = node as TransformNode;\r\n serializationObject.transformNodes.push(transformNode.serialize());\r\n } else if (node.getClassName().indexOf(\"Camera\") !== -1) {\r\n const camera = node as Camera;\r\n serializationObject.cameras.push(camera.serialize());\r\n } else if (node.getClassName().indexOf(\"Light\") !== -1) {\r\n const light = node as Light;\r\n serializationObject.lights.push(light.serialize());\r\n }\r\n};\r\n\r\n/**\r\n * Class used to serialize a scene into a string\r\n */\r\nexport class SceneSerializer {\r\n /**\r\n * Clear cache used by a previous serialization\r\n */\r\n public static ClearCache(): void {\r\n serializedGeometries = [];\r\n }\r\n\r\n /**\r\n * Serialize a scene into a JSON compatible object\r\n * Note that if the current engine does not support synchronous texture reading (like WebGPU), you should use SerializeAsync instead\r\n * as else you may not retrieve the proper base64 encoded texture data (when using the Texture.ForceSerializeBuffers flag)\r\n * @param scene defines the scene to serialize\r\n * @returns a JSON compatible object\r\n */\r\n public static Serialize(scene: Scene): any {\r\n return SceneSerializer._Serialize(scene);\r\n }\r\n\r\n private static _Serialize(scene: Scene, checkSyncReadSupported = true): any {\r\n const serializationObject: any = {};\r\n\r\n if (checkSyncReadSupported && !scene.getEngine()._features.supportSyncTextureRead && Texture.ForceSerializeBuffers) {\r\n console.warn(\"The serialization object may not contain the proper base64 encoded texture data! You should use the SerializeAsync method instead.\");\r\n }\r\n\r\n SceneSerializer.ClearCache();\r\n\r\n // Scene\r\n serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;\r\n serializationObject.autoClear = scene.autoClear;\r\n serializationObject.clearColor = scene.clearColor.asArray();\r\n serializationObject.ambientColor = scene.ambientColor.asArray();\r\n serializationObject.gravity = scene.gravity.asArray();\r\n serializationObject.collisionsEnabled = scene.collisionsEnabled;\r\n serializationObject.useRightHandedSystem = scene.useRightHandedSystem;\r\n\r\n // Fog\r\n if (scene.fogMode && scene.fogMode !== 0) {\r\n serializationObject.fogMode = scene.fogMode;\r\n serializationObject.fogColor = scene.fogColor.asArray();\r\n serializationObject.fogStart = scene.fogStart;\r\n serializationObject.fogEnd = scene.fogEnd;\r\n serializationObject.fogDensity = scene.fogDensity;\r\n }\r\n\r\n //Physics\r\n if (scene.isPhysicsEnabled && scene.isPhysicsEnabled()) {\r\n const physicEngine = scene.getPhysicsEngine();\r\n\r\n if (physicEngine) {\r\n serializationObject.physicsEnabled = true;\r\n serializationObject.physicsGravity = physicEngine.gravity.asArray();\r\n serializationObject.physicsEngine = physicEngine.getPhysicsPluginName();\r\n }\r\n }\r\n\r\n // Metadata\r\n if (scene.metadata) {\r\n serializationObject.metadata = scene.metadata;\r\n }\r\n\r\n // Morph targets\r\n serializationObject.morphTargetManagers = [];\r\n for (const abstractMesh of scene.meshes) {\r\n const manager = (abstractMesh).morphTargetManager;\r\n\r\n if (manager) {\r\n serializationObject.morphTargetManagers.push(manager.serialize());\r\n }\r\n }\r\n\r\n // Lights\r\n serializationObject.lights = [];\r\n let index: number;\r\n let light: Light;\r\n for (index = 0; index < scene.lights.length; index++) {\r\n light = scene.lights[index];\r\n\r\n if (!light.doNotSerialize) {\r\n serializationObject.lights.push(light.serialize());\r\n }\r\n }\r\n\r\n // Cameras\r\n serializationObject.cameras = [];\r\n for (index = 0; index < scene.cameras.length; index++) {\r\n const camera = scene.cameras[index];\r\n\r\n if (!camera.doNotSerialize) {\r\n serializationObject.cameras.push(camera.serialize());\r\n }\r\n }\r\n\r\n if (scene.activeCamera) {\r\n serializationObject.activeCameraID = scene.activeCamera.id;\r\n }\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(scene, serializationObject);\r\n\r\n // Animation Groups\r\n if (scene.animationGroups && scene.animationGroups.length > 0) {\r\n serializationObject.animationGroups = [];\r\n for (let animationGroupIndex = 0; animationGroupIndex < scene.animationGroups.length; animationGroupIndex++) {\r\n const animationGroup = scene.animationGroups[animationGroupIndex];\r\n\r\n serializationObject.animationGroups.push(animationGroup.serialize());\r\n }\r\n }\r\n\r\n // Reflection probes\r\n if (scene.reflectionProbes && scene.reflectionProbes.length > 0) {\r\n serializationObject.reflectionProbes = [];\r\n\r\n for (index = 0; index < scene.reflectionProbes.length; index++) {\r\n const reflectionProbe = scene.reflectionProbes[index];\r\n serializationObject.reflectionProbes.push(reflectionProbe.serialize());\r\n }\r\n }\r\n\r\n // Materials\r\n serializationObject.materials = [];\r\n serializationObject.multiMaterials = [];\r\n let material: Material;\r\n for (index = 0; index < scene.materials.length; index++) {\r\n material = scene.materials[index];\r\n if (!material.doNotSerialize) {\r\n serializationObject.materials.push(material.serialize());\r\n }\r\n }\r\n\r\n // MultiMaterials\r\n serializationObject.multiMaterials = [];\r\n for (index = 0; index < scene.multiMaterials.length; index++) {\r\n const multiMaterial = scene.multiMaterials[index];\r\n serializationObject.multiMaterials.push(multiMaterial.serialize());\r\n }\r\n\r\n // Environment texture\r\n if (scene.environmentTexture) {\r\n if ((scene.environmentTexture as CubeTexture)._files) {\r\n serializationObject.environmentTexture = scene.environmentTexture.serialize();\r\n } else {\r\n serializationObject.environmentTexture = scene.environmentTexture.name;\r\n serializationObject.environmentTextureRotationY = (scene.environmentTexture as CubeTexture).rotationY;\r\n }\r\n }\r\n\r\n // Environment Intensity\r\n serializationObject.environmentIntensity = scene.environmentIntensity;\r\n\r\n // Skeletons\r\n serializationObject.skeletons = [];\r\n for (index = 0; index < scene.skeletons.length; index++) {\r\n const skeleton = scene.skeletons[index];\r\n if (!skeleton.doNotSerialize) {\r\n serializationObject.skeletons.push(skeleton.serialize());\r\n }\r\n }\r\n\r\n // Transform nodes\r\n serializationObject.transformNodes = [];\r\n for (index = 0; index < scene.transformNodes.length; index++) {\r\n if (!scene.transformNodes[index].doNotSerialize) {\r\n serializationObject.transformNodes.push(scene.transformNodes[index].serialize());\r\n }\r\n }\r\n\r\n // Geometries\r\n serializationObject.geometries = {};\r\n\r\n serializationObject.geometries.boxes = [];\r\n serializationObject.geometries.spheres = [];\r\n serializationObject.geometries.cylinders = [];\r\n serializationObject.geometries.toruses = [];\r\n serializationObject.geometries.grounds = [];\r\n serializationObject.geometries.planes = [];\r\n serializationObject.geometries.torusKnots = [];\r\n serializationObject.geometries.vertexData = [];\r\n\r\n serializedGeometries = [];\r\n const geometries = scene.getGeometries();\r\n for (index = 0; index < geometries.length; index++) {\r\n const geometry = geometries[index];\r\n\r\n if (geometry.isReady()) {\r\n SerializeGeometry(geometry, serializationObject.geometries);\r\n }\r\n }\r\n\r\n // Meshes\r\n serializationObject.meshes = [];\r\n for (index = 0; index < scene.meshes.length; index++) {\r\n const abstractMesh = scene.meshes[index];\r\n\r\n if (abstractMesh instanceof Mesh) {\r\n const mesh = abstractMesh;\r\n if (!mesh.doNotSerialize) {\r\n if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {\r\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Particles Systems\r\n serializationObject.particleSystems = [];\r\n for (index = 0; index < scene.particleSystems.length; index++) {\r\n serializationObject.particleSystems.push(scene.particleSystems[index].serialize(false));\r\n }\r\n\r\n // Post processes\r\n serializationObject.postProcesses = [];\r\n for (index = 0; index < scene.postProcesses.length; index++) {\r\n serializationObject.postProcesses.push(scene.postProcesses[index].serialize());\r\n }\r\n\r\n // Action Manager\r\n if (scene.actionManager) {\r\n serializationObject.actions = scene.actionManager.serialize(\"scene\");\r\n }\r\n\r\n // Components\r\n for (const component of scene._serializableComponents) {\r\n component.serialize(serializationObject);\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Serialize a scene into a JSON compatible object\r\n * @param scene defines the scene to serialize\r\n * @returns a JSON promise compatible object\r\n */\r\n public static SerializeAsync(scene: Scene): Promise {\r\n const serializationObject = SceneSerializer._Serialize(scene, false);\r\n\r\n const promises: Array> = [];\r\n\r\n this._CollectPromises(serializationObject, promises);\r\n\r\n return Promise.all(promises).then(() => serializationObject);\r\n }\r\n\r\n private static _CollectPromises(obj: any, promises: Array>): void {\r\n if (Array.isArray(obj)) {\r\n for (let i = 0; i < obj.length; ++i) {\r\n const o = obj[i];\r\n if (o instanceof Promise) {\r\n promises.push(o.then((res: any) => (obj[i] = res)));\r\n } else if (o instanceof Object || Array.isArray(o)) {\r\n this._CollectPromises(o, promises);\r\n }\r\n }\r\n } else if (obj instanceof Object) {\r\n for (const name in obj) {\r\n if (Object.prototype.hasOwnProperty.call(obj, name)) {\r\n const o = obj[name];\r\n if (o instanceof Promise) {\r\n promises.push(o.then((res: any) => (obj[name] = res)));\r\n } else if (o instanceof Object || Array.isArray(o)) {\r\n this._CollectPromises(o, promises);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serialize a mesh into a JSON compatible object\r\n * @param toSerialize defines the mesh to serialize\r\n * @param withParents defines if parents must be serialized as well\r\n * @param withChildren defines if children must be serialized as well\r\n * @returns a JSON compatible object\r\n */\r\n public static SerializeMesh(toSerialize: any /* Mesh || Mesh[] */, withParents: boolean = false, withChildren: boolean = false): any {\r\n const serializationObject: any = {};\r\n serializationObject.meshes = [];\r\n serializationObject.transformNodes = [];\r\n serializationObject.cameras = [];\r\n serializationObject.lights = [];\r\n\r\n SceneSerializer.ClearCache();\r\n\r\n toSerialize = toSerialize instanceof Array ? toSerialize : [toSerialize];\r\n\r\n if (withParents || withChildren) {\r\n //deliberate for loop! not for each, appended should be processed as well.\r\n for (let i = 0; i < toSerialize.length; ++i) {\r\n if (withChildren) {\r\n toSerialize[i].getDescendants().forEach((node: Node) => {\r\n if (toSerialize.indexOf(node) < 0 && !node.doNotSerialize) {\r\n toSerialize.push(node);\r\n }\r\n });\r\n }\r\n //make sure the array doesn't contain the object already\r\n if (withParents && toSerialize[i].parent && toSerialize.indexOf(toSerialize[i].parent) < 0 && !toSerialize[i].parent.doNotSerialize) {\r\n toSerialize.push(toSerialize[i].parent);\r\n }\r\n }\r\n }\r\n\r\n toSerialize.forEach((mesh: Node) => {\r\n FinalizeSingleNode(mesh, serializationObject);\r\n });\r\n\r\n return serializationObject;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport type { SmartArrayNoDuplicate } from \"../Misc/smartArray\";\r\nimport { DepthRenderer } from \"./depthRenderer\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _depthRenderer: { [id: string]: DepthRenderer };\r\n\r\n /**\r\n * Creates a depth renderer a given camera which contains a depth map which can be used for post processing.\r\n * @param camera The camera to create the depth renderer on (default: scene's active camera)\r\n * @param storeNonLinearDepth Defines whether the depth is stored linearly like in Babylon Shadows or directly like glFragCoord.z\r\n * @param force32bitsFloat Forces 32 bits float when supported (else 16 bits float is prioritized over 32 bits float if supported)\r\n * @param samplingMode The sampling mode to be used with the render target (Linear, Nearest...)\r\n * @param storeCameraSpaceZ Defines whether the depth stored is the Z coordinate in camera space. If true, storeNonLinearDepth has no effect. (Default: false)\r\n * @returns the created depth renderer\r\n */\r\n enableDepthRenderer(\r\n camera?: Nullable,\r\n storeNonLinearDepth?: boolean,\r\n force32bitsFloat?: boolean,\r\n samplingMode?: number,\r\n storeCameraSpaceZ?: boolean\r\n ): DepthRenderer;\r\n\r\n /**\r\n * Disables a depth renderer for a given camera\r\n * @param camera The camera to disable the depth renderer on (default: scene's active camera)\r\n */\r\n disableDepthRenderer(camera?: Nullable): void;\r\n }\r\n}\r\n\r\nScene.prototype.enableDepthRenderer = function (\r\n camera?: Nullable,\r\n storeNonLinearDepth = false,\r\n force32bitsFloat: boolean = false,\r\n samplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n storeCameraSpaceZ: boolean = false\r\n): DepthRenderer {\r\n camera = camera || this.activeCamera;\r\n if (!camera) {\r\n throw \"No camera available to enable depth renderer\";\r\n }\r\n if (!this._depthRenderer) {\r\n this._depthRenderer = {};\r\n }\r\n if (!this._depthRenderer[camera.id]) {\r\n const supportFullfloat = !!this.getEngine().getCaps().textureFloatRender;\r\n let textureType = 0;\r\n if (this.getEngine().getCaps().textureHalfFloatRender && (!force32bitsFloat || !supportFullfloat)) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else if (supportFullfloat) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n } else {\r\n textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n this._depthRenderer[camera.id] = new DepthRenderer(this, textureType, camera, storeNonLinearDepth, samplingMode, storeCameraSpaceZ);\r\n }\r\n\r\n return this._depthRenderer[camera.id];\r\n};\r\n\r\nScene.prototype.disableDepthRenderer = function (camera?: Nullable): void {\r\n camera = camera || this.activeCamera;\r\n if (!camera || !this._depthRenderer || !this._depthRenderer[camera.id]) {\r\n return;\r\n }\r\n\r\n this._depthRenderer[camera.id].dispose();\r\n};\r\n\r\n/**\r\n * Defines the Depth Renderer scene component responsible to manage a depth buffer useful\r\n * in several rendering techniques.\r\n */\r\nexport class DepthRendererSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_DEPTHRENDERER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_DEPTHRENDERER, this, this._gatherRenderTargets);\r\n this.scene._gatherActiveCameraRenderTargetsStage.registerStep(\r\n SceneComponentConstants.STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER,\r\n this,\r\n this._gatherActiveCameraRenderTargets\r\n );\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n for (const key in this.scene._depthRenderer) {\r\n this.scene._depthRenderer[key].dispose();\r\n }\r\n }\r\n\r\n private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate): void {\r\n if (this.scene._depthRenderer) {\r\n for (const key in this.scene._depthRenderer) {\r\n const depthRenderer = this.scene._depthRenderer[key];\r\n if (depthRenderer.enabled && !depthRenderer.useOnlyInActiveCamera) {\r\n renderTargets.push(depthRenderer.getDepthMap());\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _gatherActiveCameraRenderTargets(renderTargets: SmartArrayNoDuplicate): void {\r\n if (this.scene._depthRenderer) {\r\n for (const key in this.scene._depthRenderer) {\r\n const depthRenderer = this.scene._depthRenderer[key];\r\n if (depthRenderer.enabled && depthRenderer.useOnlyInActiveCamera && this.scene.activeCamera!.id === key) {\r\n renderTargets.push(depthRenderer.getDepthMap());\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nDepthRenderer._SceneComponentInitialization = (scene: Scene) => {\r\n // Register the G Buffer component to the scene.\r\n let component = scene._getComponent(SceneComponentConstants.NAME_DEPTHRENDERER) as DepthRendererSceneComponent;\r\n if (!component) {\r\n component = new DepthRendererSceneComponent(scene);\r\n scene._addComponent(component);\r\n }\r\n};\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\n\nconst name = \"linePixelShader\";\nconst shader = `#include\nuniform vec4 color;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const linePixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/clipPlaneVertex\";\n\nconst name = \"lineVertexShader\";\nconst shader = `#include\n#include\nattribute vec3 position;attribute vec4 normal;uniform mat4 viewProjection;uniform float width;uniform float aspectRatio;\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include\nmat4 worldViewProjection=viewProjection*finalWorld;vec4 viewPosition=worldViewProjection*vec4(position,1.0);vec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);vec2 currentScreen=viewPosition.xy/viewPosition.w;vec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;currentScreen.x*=aspectRatio;nextScreen.x*=aspectRatio;vec2 dir=normalize(nextScreen-currentScreen);vec2 normalDir=vec2(-dir.y,dir.x);normalDir*=width/2.0;normalDir.x/=aspectRatio;vec4 offset=vec4(normalDir*normal.w,0.0,0.0);gl_Position=viewPosition+offset;\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)\nvec4 worldPos=finalWorld*vec4(position,1.0);\n#include\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const lineVertexShader = { name, shader };\n","import type { Immutable, Nullable } from \"../types\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { LinesMesh, InstancedLinesMesh } from \"../Meshes/linesMesh\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { ShaderMaterial } from \"../Materials/shaderMaterial\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Node } from \"../node\";\r\n\r\nimport \"../Shaders/line.fragment\";\r\nimport \"../Shaders/line.vertex\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { SmartArray } from \"../Misc/smartArray\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal */\r\n _edgeRenderLineShader: Nullable;\r\n }\r\n}\r\n\r\ndeclare module \"../Meshes/abstractMesh\" {\r\n export interface AbstractMesh {\r\n /**\r\n * Gets the edgesRenderer associated with the mesh\r\n */\r\n edgesRenderer: Nullable;\r\n }\r\n}\r\nAbstractMesh.prototype.disableEdgesRendering = function (): AbstractMesh {\r\n if (this._edgesRenderer) {\r\n this._edgesRenderer.dispose();\r\n this._edgesRenderer = null;\r\n }\r\n return this;\r\n};\r\n\r\nAbstractMesh.prototype.enableEdgesRendering = function (epsilon = 0.95, checkVerticesInsteadOfIndices = false, options?: IEdgesRendererOptions): AbstractMesh {\r\n this.disableEdgesRendering();\r\n this._edgesRenderer = new EdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices, true, options);\r\n return this;\r\n};\r\n\r\nObject.defineProperty(AbstractMesh.prototype, \"edgesRenderer\", {\r\n get: function (this: AbstractMesh) {\r\n return this._edgesRenderer;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\ndeclare module \"../Meshes/linesMesh\" {\r\n export interface LinesMesh {\r\n /**\r\n * Enables the edge rendering mode on the mesh.\r\n * This mode makes the mesh edges visible\r\n * @param epsilon defines the maximal distance between two angles to detect a face\r\n * @param checkVerticesInsteadOfIndices indicates that we should check vertex list directly instead of faces\r\n * @returns the currentAbstractMesh\r\n * @see https://www.babylonjs-playground.com/#19O9TU#0\r\n */\r\n enableEdgesRendering(epsilon?: number, checkVerticesInsteadOfIndices?: boolean): AbstractMesh;\r\n }\r\n}\r\nLinesMesh.prototype.enableEdgesRendering = function (epsilon = 0.95, checkVerticesInsteadOfIndices = false): AbstractMesh {\r\n this.disableEdgesRendering();\r\n this._edgesRenderer = new LineEdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices);\r\n return this;\r\n};\r\n\r\ndeclare module \"../Meshes/linesMesh\" {\r\n export interface InstancedLinesMesh {\r\n /**\r\n * Enables the edge rendering mode on the mesh.\r\n * This mode makes the mesh edges visible\r\n * @param epsilon defines the maximal distance between two angles to detect a face\r\n * @param checkVerticesInsteadOfIndices indicates that we should check vertex list directly instead of faces\r\n * @returns the current InstancedLinesMesh\r\n * @see https://www.babylonjs-playground.com/#19O9TU#0\r\n */\r\n enableEdgesRendering(epsilon?: number, checkVerticesInsteadOfIndices?: boolean): InstancedLinesMesh;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nInstancedLinesMesh.prototype.enableEdgesRendering = function (epsilon = 0.95, checkVerticesInsteadOfIndices = false): InstancedLinesMesh {\r\n LinesMesh.prototype.enableEdgesRendering.apply(this, arguments);\r\n return this;\r\n};\r\n\r\n/**\r\n * FaceAdjacencies Helper class to generate edges\r\n */\r\nclass FaceAdjacencies {\r\n public edges = new Array();\r\n public p0: Vector3;\r\n public p1: Vector3;\r\n public p2: Vector3;\r\n public edgesConnectedCount = 0;\r\n}\r\n\r\n/**\r\n * Defines the minimum contract an Edges renderer should follow.\r\n */\r\nexport interface IEdgesRenderer extends IDisposable {\r\n /**\r\n * Gets or sets a boolean indicating if the edgesRenderer is active\r\n */\r\n isEnabled: boolean;\r\n\r\n /**\r\n * Renders the edges of the attached mesh,\r\n */\r\n render(): void;\r\n\r\n /**\r\n * Checks whether or not the edges renderer is ready to render.\r\n * @returns true if ready, otherwise false.\r\n */\r\n isReady(): boolean;\r\n\r\n /**\r\n * List of instances to render in case the source mesh has instances\r\n */\r\n customInstances: SmartArray;\r\n}\r\n\r\n/**\r\n * Defines the additional options of the edges renderer\r\n */\r\nexport interface IEdgesRendererOptions {\r\n /**\r\n * Gets or sets a boolean indicating that the alternate edge finder algorithm must be used\r\n * If not defined, the default value is true\r\n */\r\n useAlternateEdgeFinder?: boolean;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that the vertex merger fast processing must be used.\r\n * If not defined, the default value is true.\r\n * You should normally leave it undefined (or set it to true), except if you see some artifacts in the edges rendering (can happen with complex geometries)\r\n * This option is used only if useAlternateEdgeFinder = true\r\n */\r\n useFastVertexMerger?: boolean;\r\n\r\n /**\r\n * During edges processing, the vertices are merged if they are close enough: epsilonVertexMerge is the limit within which vertices are considered to be equal.\r\n * The default value is 1e-6\r\n * This option is used only if useAlternateEdgeFinder = true\r\n */\r\n epsilonVertexMerge?: number;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that tessellation should be applied before finding the edges. You may need to activate this option if your geometry is a bit\r\n * unusual, like having a vertex of a triangle in-between two vertices of an edge of another triangle. It happens often when using CSG to construct meshes.\r\n * This option is used only if useAlternateEdgeFinder = true\r\n */\r\n applyTessellation?: boolean;\r\n\r\n /**\r\n * The limit under which 3 vertices are considered to be aligned. 3 vertices PQR are considered aligned if distance(PQ) + distance(QR) - distance(PR) < epsilonVertexAligned\r\n * The default value is 1e-6\r\n * This option is used only if useAlternateEdgeFinder = true\r\n */\r\n epsilonVertexAligned?: number;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that degenerated triangles should not be processed.\r\n * Degenerated triangles are triangles that have 2 or 3 vertices with the same coordinates\r\n */\r\n removeDegeneratedTriangles?: boolean;\r\n}\r\n\r\n/**\r\n * This class is used to generate edges of the mesh that could then easily be rendered in a scene.\r\n */\r\nexport class EdgesRenderer implements IEdgesRenderer {\r\n /**\r\n * Define the size of the edges with an orthographic camera\r\n */\r\n public edgesWidthScalerForOrthographic = 1000.0;\r\n\r\n /**\r\n * Define the size of the edges with a perspective camera\r\n */\r\n public edgesWidthScalerForPerspective = 50.0;\r\n\r\n protected _source: AbstractMesh;\r\n protected _linesPositions = new Array();\r\n protected _linesNormals = new Array();\r\n protected _linesIndices = new Array();\r\n protected _epsilon: number;\r\n protected _indicesCount: number;\r\n protected _drawWrapper?: DrawWrapper;\r\n\r\n protected _lineShader: ShaderMaterial;\r\n protected _ib: DataBuffer;\r\n protected _buffers: { [key: string]: Nullable } = {};\r\n protected _buffersForInstances: { [key: string]: Nullable } = {};\r\n protected _checkVerticesInsteadOfIndices = false;\r\n protected _options: Nullable;\r\n\r\n private _meshRebuildObserver: Nullable>;\r\n private _meshDisposeObserver: Nullable>;\r\n\r\n /** Gets or sets a boolean indicating if the edgesRenderer is active */\r\n public isEnabled = true;\r\n\r\n /** Gets the vertices generated by the edge renderer */\r\n public get linesPositions(): Immutable> {\r\n return this._linesPositions;\r\n }\r\n\r\n /** Gets the normals generated by the edge renderer */\r\n public get linesNormals(): Immutable> {\r\n return this._linesNormals;\r\n }\r\n\r\n /** Gets the indices generated by the edge renderer */\r\n public get linesIndices(): Immutable> {\r\n return this._linesIndices;\r\n }\r\n\r\n /**\r\n * Gets or sets the shader used to draw the lines\r\n */\r\n public get lineShader(): ShaderMaterial {\r\n return this._lineShader;\r\n }\r\n\r\n public set lineShader(shader: ShaderMaterial) {\r\n this._lineShader = shader;\r\n }\r\n\r\n /**\r\n * List of instances to render in case the source mesh has instances\r\n */\r\n public customInstances = new SmartArray(32);\r\n\r\n private static _GetShader(scene: Scene): ShaderMaterial {\r\n if (!scene._edgeRenderLineShader) {\r\n const shader = new ShaderMaterial(\r\n \"lineShader\",\r\n scene,\r\n \"line\",\r\n {\r\n attributes: [\"position\", \"normal\"],\r\n uniforms: [\"world\", \"viewProjection\", \"color\", \"width\", \"aspectRatio\"],\r\n },\r\n false\r\n );\r\n\r\n shader.disableDepthWrite = true;\r\n shader.backFaceCulling = false;\r\n shader.checkReadyOnEveryCall = scene.getEngine().isWebGPU;\r\n\r\n scene._edgeRenderLineShader = shader;\r\n }\r\n\r\n return scene._edgeRenderLineShader;\r\n }\r\n\r\n /**\r\n * Creates an instance of the EdgesRenderer. It is primarily use to display edges of a mesh.\r\n * Beware when you use this class with complex objects as the adjacencies computation can be really long\r\n * @param source Mesh used to create edges\r\n * @param epsilon sum of angles in adjacency to check for edge\r\n * @param checkVerticesInsteadOfIndices bases the edges detection on vertices vs indices. Note that this parameter is not used if options.useAlternateEdgeFinder = true\r\n * @param generateEdgesLines - should generate Lines or only prepare resources.\r\n * @param options The options to apply when generating the edges\r\n */\r\n constructor(source: AbstractMesh, epsilon = 0.95, checkVerticesInsteadOfIndices = false, generateEdgesLines = true, options?: IEdgesRendererOptions) {\r\n this._source = source;\r\n this._checkVerticesInsteadOfIndices = checkVerticesInsteadOfIndices;\r\n this._options = options ?? null;\r\n\r\n this._epsilon = epsilon;\r\n if (this._source.getScene().getEngine().isWebGPU) {\r\n this._drawWrapper = new DrawWrapper(source.getEngine());\r\n }\r\n\r\n this._prepareRessources();\r\n if (generateEdgesLines) {\r\n if (options?.useAlternateEdgeFinder ?? true) {\r\n this._generateEdgesLinesAlternate();\r\n } else {\r\n this._generateEdgesLines();\r\n }\r\n }\r\n\r\n this._meshRebuildObserver = this._source.onRebuildObservable.add(() => {\r\n this._rebuild();\r\n });\r\n\r\n this._meshDisposeObserver = this._source.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n protected _prepareRessources(): void {\r\n if (this._lineShader) {\r\n return;\r\n }\r\n\r\n this._lineShader = EdgesRenderer._GetShader(this._source.getScene());\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n let buffer = this._buffers[VertexBuffer.PositionKind];\r\n if (buffer) {\r\n buffer._rebuild();\r\n }\r\n\r\n buffer = this._buffers[VertexBuffer.NormalKind];\r\n if (buffer) {\r\n buffer._rebuild();\r\n }\r\n\r\n const scene = this._source.getScene();\r\n const engine = scene.getEngine();\r\n this._ib = engine.createIndexBuffer(this._linesIndices);\r\n }\r\n\r\n /**\r\n * Releases the required resources for the edges renderer\r\n */\r\n public dispose(): void {\r\n this._source.onRebuildObservable.remove(this._meshRebuildObserver);\r\n this._source.onDisposeObservable.remove(this._meshDisposeObserver);\r\n\r\n let buffer = this._buffers[VertexBuffer.PositionKind];\r\n if (buffer) {\r\n buffer.dispose();\r\n this._buffers[VertexBuffer.PositionKind] = null;\r\n }\r\n buffer = this._buffers[VertexBuffer.NormalKind];\r\n if (buffer) {\r\n buffer.dispose();\r\n this._buffers[VertexBuffer.NormalKind] = null;\r\n }\r\n\r\n if (this._ib) {\r\n this._source.getScene().getEngine()._releaseBuffer(this._ib);\r\n }\r\n this._lineShader.dispose();\r\n\r\n this._drawWrapper?.dispose();\r\n }\r\n\r\n protected _processEdgeForAdjacencies(pa: number, pb: number, p0: number, p1: number, p2: number): number {\r\n if ((pa === p0 && pb === p1) || (pa === p1 && pb === p0)) {\r\n return 0;\r\n }\r\n\r\n if ((pa === p1 && pb === p2) || (pa === p2 && pb === p1)) {\r\n return 1;\r\n }\r\n\r\n if ((pa === p2 && pb === p0) || (pa === p0 && pb === p2)) {\r\n return 2;\r\n }\r\n\r\n return -1;\r\n }\r\n\r\n protected _processEdgeForAdjacenciesWithVertices(pa: Vector3, pb: Vector3, p0: Vector3, p1: Vector3, p2: Vector3): number {\r\n const eps = 1e-10;\r\n if ((pa.equalsWithEpsilon(p0, eps) && pb.equalsWithEpsilon(p1, eps)) || (pa.equalsWithEpsilon(p1, eps) && pb.equalsWithEpsilon(p0, eps))) {\r\n return 0;\r\n }\r\n\r\n if ((pa.equalsWithEpsilon(p1, eps) && pb.equalsWithEpsilon(p2, eps)) || (pa.equalsWithEpsilon(p2, eps) && pb.equalsWithEpsilon(p1, eps))) {\r\n return 1;\r\n }\r\n\r\n if ((pa.equalsWithEpsilon(p2, eps) && pb.equalsWithEpsilon(p0, eps)) || (pa.equalsWithEpsilon(p0, eps) && pb.equalsWithEpsilon(p2, eps))) {\r\n return 2;\r\n }\r\n\r\n return -1;\r\n }\r\n\r\n /**\r\n * Checks if the pair of p0 and p1 is en edge\r\n * @param faceIndex\r\n * @param edge\r\n * @param faceNormals\r\n * @param p0\r\n * @param p1\r\n * @private\r\n */\r\n protected _checkEdge(faceIndex: number, edge: number, faceNormals: Array, p0: Vector3, p1: Vector3): void {\r\n let needToCreateLine;\r\n\r\n if (edge === undefined) {\r\n needToCreateLine = true;\r\n } else {\r\n const dotProduct = Vector3.Dot(faceNormals[faceIndex], faceNormals[edge]);\r\n\r\n needToCreateLine = dotProduct < this._epsilon;\r\n }\r\n\r\n if (needToCreateLine) {\r\n this.createLine(p0, p1, this._linesPositions.length / 3);\r\n }\r\n }\r\n\r\n /**\r\n * push line into the position, normal and index buffer\r\n * @param p0\r\n * @param p1\r\n * @param offset\r\n * @protected\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected createLine(p0: Vector3, p1: Vector3, offset: number) {\r\n // Positions\r\n this._linesPositions.push(p0.x, p0.y, p0.z, p0.x, p0.y, p0.z, p1.x, p1.y, p1.z, p1.x, p1.y, p1.z);\r\n\r\n // Normals\r\n this._linesNormals.push(p1.x, p1.y, p1.z, -1, p1.x, p1.y, p1.z, 1, p0.x, p0.y, p0.z, -1, p0.x, p0.y, p0.z, 1);\r\n\r\n // Indices\r\n this._linesIndices.push(offset, offset + 1, offset + 2, offset, offset + 2, offset + 3);\r\n }\r\n\r\n /**\r\n * See https://playground.babylonjs.com/#R3JR6V#1 for a visual display of the algorithm\r\n * @param edgePoints\r\n * @param indexTriangle\r\n * @param indices\r\n * @param remapVertexIndices\r\n */\r\n private _tessellateTriangle(edgePoints: Array>, indexTriangle: number, indices: Array, remapVertexIndices: Array): void {\r\n const makePointList = (edgePoints: Array<[number, number]>, pointIndices: Array, firstIndex: number) => {\r\n if (firstIndex >= 0) {\r\n pointIndices.push(firstIndex);\r\n }\r\n\r\n for (let i = 0; i < edgePoints.length; ++i) {\r\n pointIndices.push(edgePoints[i][0]);\r\n }\r\n };\r\n\r\n let startEdge = 0;\r\n\r\n if (edgePoints[1].length >= edgePoints[0].length && edgePoints[1].length >= edgePoints[2].length) {\r\n startEdge = 1;\r\n } else if (edgePoints[2].length >= edgePoints[0].length && edgePoints[2].length >= edgePoints[1].length) {\r\n startEdge = 2;\r\n }\r\n\r\n for (let e = 0; e < 3; ++e) {\r\n if (e === startEdge) {\r\n edgePoints[e].sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));\r\n } else {\r\n edgePoints[e].sort((a, b) => (a[1] > b[1] ? -1 : a[1] < b[1] ? 1 : 0));\r\n }\r\n }\r\n\r\n const mainPointIndices: Array = [],\r\n otherPointIndices: Array = [];\r\n\r\n makePointList(edgePoints[startEdge], mainPointIndices, -1);\r\n\r\n const numMainPoints = mainPointIndices.length;\r\n\r\n for (let i = startEdge + 2; i >= startEdge + 1; --i) {\r\n makePointList(edgePoints[i % 3], otherPointIndices, i !== startEdge + 2 ? remapVertexIndices[indices[indexTriangle + ((i + 1) % 3)]] : -1);\r\n }\r\n\r\n const numOtherPoints = otherPointIndices.length;\r\n\r\n const idxMain = 0;\r\n const idxOther = 0;\r\n\r\n indices.push(remapVertexIndices[indices[indexTriangle + startEdge]], mainPointIndices[0], otherPointIndices[0]);\r\n indices.push(remapVertexIndices[indices[indexTriangle + ((startEdge + 1) % 3)]], otherPointIndices[numOtherPoints - 1], mainPointIndices[numMainPoints - 1]);\r\n\r\n const bucketIsMain = numMainPoints <= numOtherPoints;\r\n\r\n const bucketStep = bucketIsMain ? numMainPoints : numOtherPoints;\r\n const bucketLimit = bucketIsMain ? numOtherPoints : numMainPoints;\r\n const bucketIdxLimit = bucketIsMain ? numMainPoints - 1 : numOtherPoints - 1;\r\n const winding = bucketIsMain ? 0 : 1;\r\n\r\n let numTris = numMainPoints + numOtherPoints - 2;\r\n\r\n let bucketIdx = bucketIsMain ? idxMain : idxOther;\r\n let nbucketIdx = bucketIsMain ? idxOther : idxMain;\r\n const bucketPoints = bucketIsMain ? mainPointIndices : otherPointIndices;\r\n const nbucketPoints = bucketIsMain ? otherPointIndices : mainPointIndices;\r\n\r\n let bucket = 0;\r\n\r\n while (numTris-- > 0) {\r\n if (winding) {\r\n indices.push(bucketPoints[bucketIdx], nbucketPoints[nbucketIdx]);\r\n } else {\r\n indices.push(nbucketPoints[nbucketIdx], bucketPoints[bucketIdx]);\r\n }\r\n\r\n bucket += bucketStep;\r\n\r\n let lastIdx;\r\n\r\n if (bucket >= bucketLimit && bucketIdx < bucketIdxLimit) {\r\n lastIdx = bucketPoints[++bucketIdx];\r\n bucket -= bucketLimit;\r\n } else {\r\n lastIdx = nbucketPoints[++nbucketIdx];\r\n }\r\n\r\n indices.push(lastIdx);\r\n }\r\n\r\n indices[indexTriangle + 0] = indices[indices.length - 3];\r\n indices[indexTriangle + 1] = indices[indices.length - 2];\r\n indices[indexTriangle + 2] = indices[indices.length - 1];\r\n\r\n indices.length = indices.length - 3;\r\n }\r\n\r\n private _generateEdgesLinesAlternate(): void {\r\n const positions = this._source.getVerticesData(VertexBuffer.PositionKind);\r\n let indices = this._source.getIndices();\r\n\r\n if (!indices || !positions) {\r\n return;\r\n }\r\n\r\n if (!Array.isArray(indices)) {\r\n indices = Array.from(indices);\r\n }\r\n\r\n /**\r\n * Find all vertices that are at the same location (with an epsilon) and remapp them on the same vertex\r\n */\r\n const useFastVertexMerger = this._options?.useFastVertexMerger ?? true;\r\n const epsVertexMerge = useFastVertexMerger ? Math.round(-Math.log(this._options?.epsilonVertexMerge ?? 1e-6) / Math.log(10)) : this._options?.epsilonVertexMerge ?? 1e-6;\r\n const remapVertexIndices: Array = [];\r\n const uniquePositions: Array = []; // list of unique index of vertices - needed for tessellation\r\n\r\n if (useFastVertexMerger) {\r\n const mapVertices: { [key: string]: number } = {};\r\n for (let v1 = 0; v1 < positions.length; v1 += 3) {\r\n const x1 = positions[v1 + 0],\r\n y1 = positions[v1 + 1],\r\n z1 = positions[v1 + 2];\r\n\r\n const key = x1.toFixed(epsVertexMerge) + \"|\" + y1.toFixed(epsVertexMerge) + \"|\" + z1.toFixed(epsVertexMerge);\r\n\r\n if (mapVertices[key] !== undefined) {\r\n remapVertexIndices.push(mapVertices[key]);\r\n } else {\r\n const idx = v1 / 3;\r\n mapVertices[key] = idx;\r\n remapVertexIndices.push(idx);\r\n uniquePositions.push(idx);\r\n }\r\n }\r\n } else {\r\n for (let v1 = 0; v1 < positions.length; v1 += 3) {\r\n const x1 = positions[v1 + 0],\r\n y1 = positions[v1 + 1],\r\n z1 = positions[v1 + 2];\r\n let found = false;\r\n for (let v2 = 0; v2 < v1 && !found; v2 += 3) {\r\n const x2 = positions[v2 + 0],\r\n y2 = positions[v2 + 1],\r\n z2 = positions[v2 + 2];\r\n\r\n if (Math.abs(x1 - x2) < epsVertexMerge && Math.abs(y1 - y2) < epsVertexMerge && Math.abs(z1 - z2) < epsVertexMerge) {\r\n remapVertexIndices.push(v2 / 3);\r\n found = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!found) {\r\n remapVertexIndices.push(v1 / 3);\r\n uniquePositions.push(v1 / 3);\r\n }\r\n }\r\n }\r\n\r\n if (this._options?.applyTessellation) {\r\n /**\r\n * Tessellate triangles if necessary:\r\n *\r\n * A\r\n * +\r\n * |\\\r\n * | \\\r\n * | \\\r\n * E + \\\r\n * /| \\\r\n * / | \\\r\n * / | \\\r\n * +---+-------+ B\r\n * D C\r\n *\r\n * For the edges to be rendered correctly, the ABC triangle has to be split into ABE and BCE, else AC is considered to be an edge, whereas only AE should be.\r\n *\r\n * The tessellation process looks for the vertices like E that are in-between two other vertices making of an edge and create new triangles as necessary\r\n */\r\n\r\n // First step: collect the triangles to tessellate\r\n const epsVertexAligned = this._options?.epsilonVertexAligned ?? 1e-6;\r\n const mustTesselate: Array<{ index: number; edgesPoints: Array> }> = []; // liste of triangles that must be tessellated\r\n\r\n for (let index = 0; index < indices.length; index += 3) {\r\n // loop over all triangles\r\n let triangleToTessellate: { index: number; edgesPoints: Array> } | undefined;\r\n\r\n for (let i = 0; i < 3; ++i) {\r\n // loop over the 3 edges of the triangle\r\n const p0Index = remapVertexIndices[indices[index + i]];\r\n const p1Index = remapVertexIndices[indices[index + ((i + 1) % 3)]];\r\n const p2Index = remapVertexIndices[indices[index + ((i + 2) % 3)]];\r\n\r\n if (p0Index === p1Index) {\r\n continue;\r\n } // degenerated triangle - don't process\r\n\r\n const p0x = positions[p0Index * 3 + 0],\r\n p0y = positions[p0Index * 3 + 1],\r\n p0z = positions[p0Index * 3 + 2];\r\n const p1x = positions[p1Index * 3 + 0],\r\n p1y = positions[p1Index * 3 + 1],\r\n p1z = positions[p1Index * 3 + 2];\r\n\r\n const p0p1 = Math.sqrt((p1x - p0x) * (p1x - p0x) + (p1y - p0y) * (p1y - p0y) + (p1z - p0z) * (p1z - p0z));\r\n\r\n for (let v = 0; v < uniquePositions.length - 1; v++) {\r\n // loop over all (unique) vertices and look for the ones that would be in-between p0 and p1\r\n const vIndex = uniquePositions[v];\r\n\r\n if (vIndex === p0Index || vIndex === p1Index || vIndex === p2Index) {\r\n continue;\r\n } // don't handle the vertex if it is a vertex of the current triangle\r\n\r\n const x = positions[vIndex * 3 + 0],\r\n y = positions[vIndex * 3 + 1],\r\n z = positions[vIndex * 3 + 2];\r\n\r\n const p0p = Math.sqrt((x - p0x) * (x - p0x) + (y - p0y) * (y - p0y) + (z - p0z) * (z - p0z));\r\n const pp1 = Math.sqrt((x - p1x) * (x - p1x) + (y - p1y) * (y - p1y) + (z - p1z) * (z - p1z));\r\n\r\n if (Math.abs(p0p + pp1 - p0p1) < epsVertexAligned) {\r\n // vertices are aligned and p in-between p0 and p1 if distance(p0, p) + distance (p, p1) ~ distance(p0, p1)\r\n if (!triangleToTessellate) {\r\n triangleToTessellate = {\r\n index: index,\r\n edgesPoints: [[], [], []],\r\n };\r\n mustTesselate.push(triangleToTessellate);\r\n }\r\n triangleToTessellate.edgesPoints[i].push([vIndex, p0p]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Second step: tesselate the triangles\r\n for (let t = 0; t < mustTesselate.length; ++t) {\r\n const triangle = mustTesselate[t];\r\n\r\n this._tessellateTriangle(triangle.edgesPoints, triangle.index, indices, remapVertexIndices);\r\n }\r\n\r\n mustTesselate.length = 0;\r\n }\r\n\r\n /**\r\n * Collect the edges to render\r\n */\r\n const edges: { [key: string]: { normal: Vector3; done: boolean; index: number; i: number } } = {};\r\n\r\n for (let index = 0; index < indices.length; index += 3) {\r\n let faceNormal;\r\n for (let i = 0; i < 3; ++i) {\r\n let p0Index = remapVertexIndices[indices[index + i]];\r\n let p1Index = remapVertexIndices[indices[index + ((i + 1) % 3)]];\r\n const p2Index = remapVertexIndices[indices[index + ((i + 2) % 3)]];\r\n\r\n if (p0Index === p1Index || ((p0Index === p2Index || p1Index === p2Index) && this._options?.removeDegeneratedTriangles)) {\r\n continue;\r\n }\r\n\r\n TmpVectors.Vector3[0].copyFromFloats(positions[p0Index * 3 + 0], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);\r\n TmpVectors.Vector3[1].copyFromFloats(positions[p1Index * 3 + 0], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);\r\n TmpVectors.Vector3[2].copyFromFloats(positions[p2Index * 3 + 0], positions[p2Index * 3 + 1], positions[p2Index * 3 + 2]);\r\n\r\n if (!faceNormal) {\r\n TmpVectors.Vector3[1].subtractToRef(TmpVectors.Vector3[0], TmpVectors.Vector3[3]);\r\n TmpVectors.Vector3[2].subtractToRef(TmpVectors.Vector3[1], TmpVectors.Vector3[4]);\r\n faceNormal = Vector3.Cross(TmpVectors.Vector3[3], TmpVectors.Vector3[4]);\r\n faceNormal.normalize();\r\n }\r\n\r\n if (p0Index > p1Index) {\r\n const tmp = p0Index;\r\n p0Index = p1Index;\r\n p1Index = tmp;\r\n }\r\n\r\n const key = p0Index + \"_\" + p1Index;\r\n const ei = edges[key];\r\n\r\n if (ei) {\r\n if (!ei.done) {\r\n const dotProduct = Vector3.Dot(faceNormal, ei.normal);\r\n\r\n if (dotProduct < this._epsilon) {\r\n this.createLine(TmpVectors.Vector3[0], TmpVectors.Vector3[1], this._linesPositions.length / 3);\r\n }\r\n\r\n ei.done = true;\r\n }\r\n } else {\r\n edges[key] = { normal: faceNormal, done: false, index: index, i: i };\r\n }\r\n }\r\n }\r\n\r\n for (const key in edges) {\r\n const ei = edges[key];\r\n if (!ei.done) {\r\n // Orphaned edge - we must display it\r\n const p0Index = remapVertexIndices[indices[ei.index + ei.i]];\r\n const p1Index = remapVertexIndices[indices[ei.index + ((ei.i + 1) % 3)]];\r\n\r\n TmpVectors.Vector3[0].copyFromFloats(positions[p0Index * 3 + 0], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);\r\n TmpVectors.Vector3[1].copyFromFloats(positions[p1Index * 3 + 0], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);\r\n\r\n this.createLine(TmpVectors.Vector3[0], TmpVectors.Vector3[1], this._linesPositions.length / 3);\r\n }\r\n }\r\n\r\n /**\r\n * Merge into a single mesh\r\n */\r\n const engine = this._source.getScene().getEngine();\r\n\r\n this._buffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, this._linesPositions, VertexBuffer.PositionKind, false);\r\n this._buffers[VertexBuffer.NormalKind] = new VertexBuffer(engine, this._linesNormals, VertexBuffer.NormalKind, false, false, 4);\r\n\r\n this._buffersForInstances[VertexBuffer.PositionKind] = this._buffers[VertexBuffer.PositionKind];\r\n this._buffersForInstances[VertexBuffer.NormalKind] = this._buffers[VertexBuffer.NormalKind];\r\n\r\n this._ib = engine.createIndexBuffer(this._linesIndices);\r\n\r\n this._indicesCount = this._linesIndices.length;\r\n }\r\n\r\n /**\r\n * Generates lines edges from adjacencjes\r\n * @private\r\n */\r\n _generateEdgesLines(): void {\r\n const positions = this._source.getVerticesData(VertexBuffer.PositionKind);\r\n const indices = this._source.getIndices();\r\n\r\n if (!indices || !positions) {\r\n return;\r\n }\r\n\r\n // First let's find adjacencies\r\n const adjacencies = new Array();\r\n const faceNormals = new Array();\r\n let index: number;\r\n let faceAdjacencies: FaceAdjacencies;\r\n\r\n // Prepare faces\r\n for (index = 0; index < indices.length; index += 3) {\r\n faceAdjacencies = new FaceAdjacencies();\r\n const p0Index = indices[index];\r\n const p1Index = indices[index + 1];\r\n const p2Index = indices[index + 2];\r\n\r\n faceAdjacencies.p0 = new Vector3(positions[p0Index * 3], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);\r\n faceAdjacencies.p1 = new Vector3(positions[p1Index * 3], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);\r\n faceAdjacencies.p2 = new Vector3(positions[p2Index * 3], positions[p2Index * 3 + 1], positions[p2Index * 3 + 2]);\r\n const faceNormal = Vector3.Cross(faceAdjacencies.p1.subtract(faceAdjacencies.p0), faceAdjacencies.p2.subtract(faceAdjacencies.p1));\r\n\r\n faceNormal.normalize();\r\n\r\n faceNormals.push(faceNormal);\r\n adjacencies.push(faceAdjacencies);\r\n }\r\n\r\n // Scan\r\n for (index = 0; index < adjacencies.length; index++) {\r\n faceAdjacencies = adjacencies[index];\r\n\r\n for (let otherIndex = index + 1; otherIndex < adjacencies.length; otherIndex++) {\r\n const otherFaceAdjacencies = adjacencies[otherIndex];\r\n\r\n if (faceAdjacencies.edgesConnectedCount === 3) {\r\n // Full\r\n break;\r\n }\r\n\r\n if (otherFaceAdjacencies.edgesConnectedCount === 3) {\r\n // Full\r\n continue;\r\n }\r\n\r\n const otherP0 = indices[otherIndex * 3];\r\n const otherP1 = indices[otherIndex * 3 + 1];\r\n const otherP2 = indices[otherIndex * 3 + 2];\r\n\r\n for (let edgeIndex = 0; edgeIndex < 3; edgeIndex++) {\r\n let otherEdgeIndex: number = 0;\r\n\r\n if (faceAdjacencies.edges[edgeIndex] !== undefined) {\r\n continue;\r\n }\r\n\r\n switch (edgeIndex) {\r\n case 0:\r\n if (this._checkVerticesInsteadOfIndices) {\r\n otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(\r\n faceAdjacencies.p0,\r\n faceAdjacencies.p1,\r\n otherFaceAdjacencies.p0,\r\n otherFaceAdjacencies.p1,\r\n otherFaceAdjacencies.p2\r\n );\r\n } else {\r\n otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3], indices[index * 3 + 1], otherP0, otherP1, otherP2);\r\n }\r\n break;\r\n case 1:\r\n if (this._checkVerticesInsteadOfIndices) {\r\n otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(\r\n faceAdjacencies.p1,\r\n faceAdjacencies.p2,\r\n otherFaceAdjacencies.p0,\r\n otherFaceAdjacencies.p1,\r\n otherFaceAdjacencies.p2\r\n );\r\n } else {\r\n otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3 + 1], indices[index * 3 + 2], otherP0, otherP1, otherP2);\r\n }\r\n break;\r\n case 2:\r\n if (this._checkVerticesInsteadOfIndices) {\r\n otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(\r\n faceAdjacencies.p2,\r\n faceAdjacencies.p0,\r\n otherFaceAdjacencies.p0,\r\n otherFaceAdjacencies.p1,\r\n otherFaceAdjacencies.p2\r\n );\r\n } else {\r\n otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3 + 2], indices[index * 3], otherP0, otherP1, otherP2);\r\n }\r\n break;\r\n }\r\n\r\n if (otherEdgeIndex === -1) {\r\n continue;\r\n }\r\n\r\n faceAdjacencies.edges[edgeIndex] = otherIndex;\r\n otherFaceAdjacencies.edges[otherEdgeIndex] = index;\r\n\r\n faceAdjacencies.edgesConnectedCount++;\r\n otherFaceAdjacencies.edgesConnectedCount++;\r\n\r\n if (faceAdjacencies.edgesConnectedCount === 3) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Create lines\r\n for (index = 0; index < adjacencies.length; index++) {\r\n // We need a line when a face has no adjacency on a specific edge or if all the adjacencies has an angle greater than epsilon\r\n const current = adjacencies[index];\r\n\r\n this._checkEdge(index, current.edges[0], faceNormals, current.p0, current.p1);\r\n this._checkEdge(index, current.edges[1], faceNormals, current.p1, current.p2);\r\n this._checkEdge(index, current.edges[2], faceNormals, current.p2, current.p0);\r\n }\r\n\r\n // Merge into a single mesh\r\n const engine = this._source.getScene().getEngine();\r\n\r\n this._buffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, this._linesPositions, VertexBuffer.PositionKind, false);\r\n this._buffers[VertexBuffer.NormalKind] = new VertexBuffer(engine, this._linesNormals, VertexBuffer.NormalKind, false, false, 4);\r\n\r\n this._buffersForInstances[VertexBuffer.PositionKind] = this._buffers[VertexBuffer.PositionKind];\r\n this._buffersForInstances[VertexBuffer.NormalKind] = this._buffers[VertexBuffer.NormalKind];\r\n\r\n this._ib = engine.createIndexBuffer(this._linesIndices);\r\n\r\n this._indicesCount = this._linesIndices.length;\r\n }\r\n\r\n /**\r\n * Checks whether or not the edges renderer is ready to render.\r\n * @returns true if ready, otherwise false.\r\n */\r\n public isReady(): boolean {\r\n return this._lineShader.isReady(this._source, (this._source.hasInstances && this.customInstances.length > 0) || this._source.hasThinInstances);\r\n }\r\n\r\n /**\r\n * Renders the edges of the attached mesh,\r\n */\r\n public render(): void {\r\n const scene = this._source.getScene();\r\n\r\n const currentDrawWrapper = this._lineShader._getDrawWrapper();\r\n if (this._drawWrapper) {\r\n this._lineShader._setDrawWrapper(this._drawWrapper);\r\n }\r\n\r\n if (!this.isReady() || !scene.activeCamera) {\r\n this._lineShader._setDrawWrapper(currentDrawWrapper);\r\n return;\r\n }\r\n\r\n const hasInstances = this._source.hasInstances && this.customInstances.length > 0;\r\n const useBuffersWithInstances = hasInstances || this._source.hasThinInstances;\r\n\r\n let instanceCount = 0;\r\n\r\n if (useBuffersWithInstances) {\r\n this._buffersForInstances[\"world0\"] = (this._source as Mesh).getVertexBuffer(\"world0\");\r\n this._buffersForInstances[\"world1\"] = (this._source as Mesh).getVertexBuffer(\"world1\");\r\n this._buffersForInstances[\"world2\"] = (this._source as Mesh).getVertexBuffer(\"world2\");\r\n this._buffersForInstances[\"world3\"] = (this._source as Mesh).getVertexBuffer(\"world3\");\r\n\r\n if (hasInstances) {\r\n const instanceStorage = (this._source as Mesh)._instanceDataStorage;\r\n\r\n instanceCount = this.customInstances.length;\r\n\r\n if (!instanceStorage.instancesData) {\r\n if (!this._source.getScene()._activeMeshesFrozen) {\r\n this.customInstances.reset();\r\n }\r\n return;\r\n }\r\n\r\n if (!instanceStorage.isFrozen) {\r\n let offset = 0;\r\n\r\n for (let i = 0; i < instanceCount; ++i) {\r\n this.customInstances.data[i].copyToArray(instanceStorage.instancesData, offset);\r\n offset += 16;\r\n }\r\n\r\n instanceStorage.instancesBuffer!.updateDirectly(instanceStorage.instancesData, 0, instanceCount);\r\n }\r\n } else {\r\n instanceCount = (this._source as Mesh).thinInstanceCount;\r\n }\r\n }\r\n\r\n const engine = scene.getEngine();\r\n this._lineShader._preBind();\r\n\r\n if (this._source.edgesColor.a !== 1) {\r\n engine.setAlphaMode(Constants.ALPHA_COMBINE);\r\n } else {\r\n engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n }\r\n\r\n // VBOs\r\n engine.bindBuffers(useBuffersWithInstances ? this._buffersForInstances : this._buffers, this._ib, this._lineShader.getEffect());\r\n\r\n scene.resetCachedMaterial();\r\n this._lineShader.setColor4(\"color\", this._source.edgesColor);\r\n\r\n if (scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n this._lineShader.setFloat(\"width\", this._source.edgesWidth / this.edgesWidthScalerForOrthographic);\r\n } else {\r\n this._lineShader.setFloat(\"width\", this._source.edgesWidth / this.edgesWidthScalerForPerspective);\r\n }\r\n\r\n this._lineShader.setFloat(\"aspectRatio\", engine.getAspectRatio(scene.activeCamera));\r\n this._lineShader.bind(this._source.getWorldMatrix());\r\n\r\n // Draw order\r\n engine.drawElementsType(Material.TriangleFillMode, 0, this._indicesCount, instanceCount);\r\n this._lineShader.unbind();\r\n\r\n if (useBuffersWithInstances) {\r\n engine.unbindInstanceAttributes();\r\n }\r\n\r\n if (!this._source.getScene()._activeMeshesFrozen) {\r\n this.customInstances.reset();\r\n }\r\n\r\n this._lineShader._setDrawWrapper(currentDrawWrapper);\r\n }\r\n}\r\n\r\n/**\r\n * LineEdgesRenderer for LineMeshes to remove unnecessary triangulation\r\n */\r\nexport class LineEdgesRenderer extends EdgesRenderer {\r\n /**\r\n * This constructor turns off auto generating edges line in Edges Renderer to make it here.\r\n * @param source LineMesh used to generate edges\r\n * @param epsilon not important (specified angle for edge detection)\r\n * @param checkVerticesInsteadOfIndices not important for LineMesh\r\n */\r\n constructor(source: AbstractMesh, epsilon = 0.95, checkVerticesInsteadOfIndices = false) {\r\n super(source, epsilon, checkVerticesInsteadOfIndices, false);\r\n this._generateEdgesLines();\r\n }\r\n\r\n /**\r\n * Generate edges for each line in LinesMesh. Every Line should be rendered as edge.\r\n */\r\n _generateEdgesLines(): void {\r\n const positions = this._source.getVerticesData(VertexBuffer.PositionKind);\r\n const indices = this._source.getIndices();\r\n\r\n if (!indices || !positions) {\r\n return;\r\n }\r\n\r\n const p0 = TmpVectors.Vector3[0];\r\n const p1 = TmpVectors.Vector3[1];\r\n const len = indices.length - 1;\r\n for (let i = 0, offset = 0; i < len; i += 2, offset += 4) {\r\n Vector3.FromArrayToRef(positions, 3 * indices[i], p0);\r\n Vector3.FromArrayToRef(positions, 3 * indices[i + 1], p1);\r\n this.createLine(p0, p1, offset);\r\n }\r\n\r\n // Merge into a single mesh\r\n const engine = this._source.getScene().getEngine();\r\n\r\n this._buffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, this._linesPositions, VertexBuffer.PositionKind, false);\r\n this._buffers[VertexBuffer.NormalKind] = new VertexBuffer(engine, this._linesNormals, VertexBuffer.NormalKind, false, false, 4);\r\n\r\n this._ib = engine.createIndexBuffer(this._linesIndices);\r\n\r\n this._indicesCount = this._linesIndices.length;\r\n }\r\n}\r\n","import { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport type { IMultiRenderTargetOptions } from \"../../Materials/Textures/multiRenderTarget\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../constants\";\r\nimport { ThinEngine } from \"../thinEngine\";\r\nimport type { RenderTargetWrapper } from \"../renderTargetWrapper\";\r\nimport type { WebGLRenderTargetWrapper } from \"../WebGL/webGLRenderTargetWrapper\";\r\nimport type { WebGLHardwareTexture } from \"../WebGL/webGLHardwareTexture\";\r\nimport type { TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Unbind a list of render target textures from the webGL context\r\n * This is used only when drawBuffer extension or webGL2 are active\r\n * @param rtWrapper defines the render target wrapper to unbind\r\n * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated\r\n * @param onBeforeUnbind defines a function which will be called before the effective unbind\r\n */\r\n unBindMultiColorAttachmentFramebuffer(rtWrapper: RenderTargetWrapper, disableGenerateMipMaps: boolean, onBeforeUnbind?: () => void): void;\r\n\r\n /**\r\n * Create a multi render target texture\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#multiple-render-target\r\n * @param size defines the size of the texture\r\n * @param options defines the creation options\r\n * @param initializeBuffers if set to true, the engine will make an initializing call of drawBuffers\r\n * @returns a new render target wrapper ready to render textures\r\n */\r\n createMultipleRenderTarget(size: TextureSize, options: IMultiRenderTargetOptions, initializeBuffers?: boolean): RenderTargetWrapper;\r\n\r\n /**\r\n * Update the sample count for a given multiple render target texture\r\n * @see https://doc.babylonjs.com/setup/support/webGL2#multisample-render-targets\r\n * @param rtWrapper defines the render target wrapper to update\r\n * @param samples defines the sample count to set\r\n * @param initializeBuffers if set to true, the engine will make an initializing call of drawBuffers\r\n * @returns the effective sample count (could be 0 if multisample render targets are not supported)\r\n */\r\n updateMultipleRenderTargetTextureSampleCount(rtWrapper: Nullable, samples: number, initializeBuffers?: boolean): number;\r\n\r\n /**\r\n * Select a subsets of attachments to draw to.\r\n * @param attachments gl attachments\r\n */\r\n bindAttachments(attachments: number[]): void;\r\n\r\n /**\r\n * Creates a layout object to draw/clear on specific textures in a MRT\r\n * @param textureStatus textureStatus[i] indicates if the i-th is active\r\n * @returns A layout to be fed to the engine, calling `bindAttachments`.\r\n */\r\n buildTextureLayout(textureStatus: boolean[]): number[];\r\n\r\n /**\r\n * Restores the webgl state to only draw on the main color attachment\r\n * when the frame buffer associated is the canvas frame buffer\r\n */\r\n restoreSingleAttachment(): void;\r\n\r\n /**\r\n * Restores the webgl state to only draw on the main color attachment\r\n * when the frame buffer associated is not the canvas frame buffer\r\n */\r\n restoreSingleAttachmentForRenderTarget(): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.restoreSingleAttachment = function (): void {\r\n const gl = this._gl;\r\n\r\n this.bindAttachments([gl.BACK]);\r\n};\r\n\r\nThinEngine.prototype.restoreSingleAttachmentForRenderTarget = function (): void {\r\n const gl = this._gl;\r\n\r\n this.bindAttachments([gl.COLOR_ATTACHMENT0]);\r\n};\r\n\r\nThinEngine.prototype.buildTextureLayout = function (textureStatus: boolean[]): number[] {\r\n const gl = this._gl;\r\n\r\n const result = [];\r\n\r\n for (let i = 0; i < textureStatus.length; i++) {\r\n if (textureStatus[i]) {\r\n result.push((gl)[\"COLOR_ATTACHMENT\" + i]);\r\n } else {\r\n result.push(gl.NONE);\r\n }\r\n }\r\n\r\n return result;\r\n};\r\n\r\nThinEngine.prototype.bindAttachments = function (attachments: number[]): void {\r\n const gl = this._gl;\r\n\r\n gl.drawBuffers(attachments);\r\n};\r\n\r\nThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function (\r\n rtWrapper: WebGLRenderTargetWrapper,\r\n disableGenerateMipMaps: boolean = false,\r\n onBeforeUnbind?: () => void\r\n): void {\r\n this._currentRenderTarget = null;\r\n\r\n // If MSAA, we need to bitblt back to main texture\r\n const gl = this._gl;\r\n\r\n const attachments = rtWrapper._attachments!;\r\n const count = attachments.length;\r\n\r\n if (rtWrapper._MSAAFramebuffer) {\r\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, rtWrapper._MSAAFramebuffer);\r\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, rtWrapper._framebuffer);\r\n\r\n for (let i = 0; i < count; i++) {\r\n const texture = rtWrapper.textures![i];\r\n\r\n for (let j = 0; j < count; j++) {\r\n attachments[j] = gl.NONE;\r\n }\r\n\r\n attachments[i] = (gl)[this.webGLVersion > 1 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\r\n gl.readBuffer(attachments[i]);\r\n gl.drawBuffers(attachments);\r\n gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);\r\n }\r\n\r\n for (let i = 0; i < count; i++) {\r\n attachments[i] = (gl)[this.webGLVersion > 1 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\r\n }\r\n\r\n gl.drawBuffers(attachments);\r\n }\r\n\r\n for (let i = 0; i < count; i++) {\r\n const texture = rtWrapper.textures![i];\r\n if (texture?.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {\r\n this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);\r\n gl.generateMipmap(gl.TEXTURE_2D);\r\n this._bindTextureDirectly(gl.TEXTURE_2D, null);\r\n }\r\n }\r\n\r\n if (onBeforeUnbind) {\r\n if (rtWrapper._MSAAFramebuffer) {\r\n // Bind the correct framebuffer\r\n this._bindUnboundFramebuffer(rtWrapper._framebuffer);\r\n }\r\n onBeforeUnbind();\r\n }\r\n\r\n this._bindUnboundFramebuffer(null);\r\n};\r\n\r\nThinEngine.prototype.createMultipleRenderTarget = function (size: TextureSize, options: IMultiRenderTargetOptions, initializeBuffers: boolean = true): RenderTargetWrapper {\r\n let generateMipMaps = false;\r\n let generateDepthBuffer = true;\r\n let generateStencilBuffer = false;\r\n let generateDepthTexture = false;\r\n let depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH16;\r\n let textureCount = 1;\r\n\r\n const defaultType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n const defaultSamplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;\r\n const defaultUseSRGBBuffer = false;\r\n const defaultFormat = Constants.TEXTUREFORMAT_RGBA;\r\n const defaultTarget = Constants.TEXTURE_2D;\r\n\r\n let types = new Array();\r\n let samplingModes = new Array();\r\n let useSRGBBuffers = new Array();\r\n let formats = new Array();\r\n let targets = new Array();\r\n let faceIndex = new Array();\r\n let layerIndex = new Array();\r\n let layers = new Array();\r\n\r\n const rtWrapper = this._createHardwareRenderTargetWrapper(true, false, size) as WebGLRenderTargetWrapper;\r\n\r\n if (options !== undefined) {\r\n generateMipMaps = options.generateMipMaps === undefined ? false : options.generateMipMaps;\r\n generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;\r\n generateStencilBuffer = options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;\r\n generateDepthTexture = options.generateDepthTexture === undefined ? false : options.generateDepthTexture;\r\n textureCount = options.textureCount || 1;\r\n\r\n if (options.types) {\r\n types = options.types;\r\n }\r\n if (options.samplingModes) {\r\n samplingModes = options.samplingModes;\r\n }\r\n if (options.useSRGBBuffers) {\r\n useSRGBBuffers = options.useSRGBBuffers;\r\n }\r\n if (options.formats) {\r\n formats = options.formats;\r\n }\r\n if (options.targetTypes) {\r\n targets = options.targetTypes;\r\n }\r\n if (options.faceIndex) {\r\n faceIndex = options.faceIndex;\r\n }\r\n if (options.layerIndex) {\r\n layerIndex = options.layerIndex;\r\n }\r\n if (options.layerCounts) {\r\n layers = options.layerCounts;\r\n }\r\n if (\r\n this.webGLVersion > 1 &&\r\n (options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 ||\r\n options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 ||\r\n options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24 ||\r\n options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH32_FLOAT ||\r\n options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8)\r\n ) {\r\n depthTextureFormat = options.depthTextureFormat;\r\n }\r\n }\r\n const gl = this._gl;\r\n // Create the framebuffer\r\n const framebuffer = gl.createFramebuffer();\r\n this._bindUnboundFramebuffer(framebuffer);\r\n\r\n const width = (<{ width: number; height: number }>size).width || size;\r\n const height = (<{ width: number; height: number }>size).height || size;\r\n\r\n const textures: InternalTexture[] = [];\r\n const attachments: number[] = [];\r\n\r\n const useStencilTexture =\r\n this.webGLVersion > 1 &&\r\n generateDepthTexture &&\r\n (options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 ||\r\n options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 ||\r\n options.depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8);\r\n const depthStencilBuffer = this._setupFramebufferDepthAttachments(!useStencilTexture && generateStencilBuffer, !generateDepthTexture && generateDepthBuffer, width, height);\r\n\r\n rtWrapper._framebuffer = framebuffer;\r\n rtWrapper._depthStencilBuffer = depthStencilBuffer;\r\n rtWrapper._generateDepthBuffer = !generateDepthTexture && generateDepthBuffer;\r\n rtWrapper._generateStencilBuffer = !useStencilTexture && generateStencilBuffer;\r\n rtWrapper._attachments = attachments;\r\n\r\n for (let i = 0; i < textureCount; i++) {\r\n let samplingMode = samplingModes[i] || defaultSamplingMode;\r\n let type = types[i] || defaultType;\r\n let useSRGBBuffer = useSRGBBuffers[i] || defaultUseSRGBBuffer;\r\n const format = formats[i] || defaultFormat;\r\n\r\n const target = targets[i] || defaultTarget;\r\n const layerCount = layers[i] ?? 1;\r\n\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {\r\n // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n } else if (type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {\r\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n\r\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n Logger.Warn(\"Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type\");\r\n }\r\n\r\n useSRGBBuffer = useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU);\r\n\r\n const isWebGL2 = this.webGLVersion > 1;\r\n const attachment = (gl)[isWebGL2 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\r\n\r\n attachments.push(attachment);\r\n\r\n if (target === -1) {\r\n continue;\r\n }\r\n\r\n const texture = new InternalTexture(this, InternalTextureSource.MultiRenderTarget);\r\n textures[i] = texture;\r\n\r\n gl.activeTexture((gl)[\"TEXTURE\" + i]);\r\n gl.bindTexture(target, texture._hardwareTexture!.underlyingResource);\r\n\r\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, filters.mag);\r\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, filters.min);\r\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n\r\n const internalSizedFormat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);\r\n const internalFormat = this._getInternalFormat(format);\r\n const webGLTextureType = this._getWebGLTextureType(type);\r\n\r\n if (isWebGL2 && (target === Constants.TEXTURE_2D_ARRAY || target === Constants.TEXTURE_3D)) {\r\n if (target === Constants.TEXTURE_2D_ARRAY) {\r\n texture.is2DArray = true;\r\n } else {\r\n texture.is3D = true;\r\n }\r\n\r\n texture.baseDepth = texture.depth = layerCount;\r\n\r\n gl.texImage3D(target, 0, internalSizedFormat, width, height, layerCount, 0, internalFormat, webGLTextureType, null);\r\n } else if (target === Constants.TEXTURE_CUBE_MAP) {\r\n // We have to generate all faces to complete the framebuffer\r\n for (let i = 0; i < 6; i++) {\r\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalSizedFormat, width, height, 0, internalFormat, webGLTextureType, null);\r\n }\r\n texture.isCube = true;\r\n } else {\r\n gl.texImage2D(gl.TEXTURE_2D, 0, internalSizedFormat, width, height, 0, internalFormat, webGLTextureType, null);\r\n }\r\n\r\n if (generateMipMaps) {\r\n gl.generateMipmap(target);\r\n }\r\n\r\n // Unbind\r\n this._bindTextureDirectly(target, null);\r\n\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n texture.width = width;\r\n texture.height = height;\r\n texture.isReady = true;\r\n texture.samples = 1;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n texture.type = type;\r\n texture._useSRGBBuffer = useSRGBBuffer;\r\n texture.format = format;\r\n\r\n this._internalTexturesCache.push(texture);\r\n }\r\n\r\n if (generateDepthTexture && this._caps.depthTextureExtension) {\r\n // Depth texture\r\n const depthTexture = new InternalTexture(this, InternalTextureSource.Depth);\r\n\r\n let depthTextureType = Constants.TEXTURETYPE_UNSIGNED_SHORT;\r\n let glDepthTextureInternalFormat: GLenum = gl.DEPTH_COMPONENT16;\r\n let glDepthTextureFormat: GLenum = gl.DEPTH_COMPONENT;\r\n let glDepthTextureType: GLenum = gl.UNSIGNED_SHORT;\r\n let glDepthTextureAttachment: GLenum = gl.DEPTH_ATTACHMENT;\r\n if (this.webGLVersion < 2) {\r\n glDepthTextureInternalFormat = gl.DEPTH_COMPONENT;\r\n } else {\r\n if (depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH32_FLOAT) {\r\n depthTextureType = Constants.TEXTURETYPE_FLOAT;\r\n glDepthTextureType = gl.FLOAT;\r\n glDepthTextureInternalFormat = gl.DEPTH_COMPONENT32F;\r\n } else if (depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8) {\r\n depthTextureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n glDepthTextureType = gl.FLOAT_32_UNSIGNED_INT_24_8_REV;\r\n glDepthTextureInternalFormat = gl.DEPTH32F_STENCIL8;\r\n glDepthTextureFormat = gl.DEPTH_STENCIL;\r\n glDepthTextureAttachment = gl.DEPTH_STENCIL_ATTACHMENT;\r\n } else if (depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24) {\r\n depthTextureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n glDepthTextureType = gl.UNSIGNED_INT;\r\n glDepthTextureInternalFormat = gl.DEPTH_COMPONENT24;\r\n glDepthTextureAttachment = gl.DEPTH_ATTACHMENT;\r\n } else if (depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 || depthTextureFormat === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8) {\r\n depthTextureType = Constants.TEXTURETYPE_UNSIGNED_INT_24_8;\r\n glDepthTextureType = gl.UNSIGNED_INT_24_8;\r\n glDepthTextureInternalFormat = gl.DEPTH24_STENCIL8;\r\n glDepthTextureFormat = gl.DEPTH_STENCIL;\r\n glDepthTextureAttachment = gl.DEPTH_STENCIL_ATTACHMENT;\r\n }\r\n }\r\n\r\n gl.activeTexture(gl.TEXTURE0);\r\n gl.bindTexture(gl.TEXTURE_2D, depthTexture._hardwareTexture!.underlyingResource);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n gl.texImage2D(gl.TEXTURE_2D, 0, glDepthTextureInternalFormat, width, height, 0, glDepthTextureFormat, glDepthTextureType, null);\r\n\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, glDepthTextureAttachment, gl.TEXTURE_2D, depthTexture._hardwareTexture!.underlyingResource, 0);\r\n\r\n depthTexture.baseWidth = width;\r\n depthTexture.baseHeight = height;\r\n depthTexture.width = width;\r\n depthTexture.height = height;\r\n depthTexture.isReady = true;\r\n depthTexture.samples = 1;\r\n depthTexture.generateMipMaps = generateMipMaps;\r\n depthTexture.samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n depthTexture.format = depthTextureFormat;\r\n depthTexture.type = depthTextureType;\r\n\r\n textures[textureCount] = depthTexture;\r\n this._internalTexturesCache.push(depthTexture);\r\n }\r\n rtWrapper.setTextures(textures);\r\n if (initializeBuffers) {\r\n gl.drawBuffers(attachments);\r\n }\r\n\r\n this._bindUnboundFramebuffer(null);\r\n\r\n rtWrapper.setLayerAndFaceIndices(layerIndex, faceIndex);\r\n\r\n this.resetTextureCache();\r\n\r\n return rtWrapper;\r\n};\r\n\r\nThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function (\r\n rtWrapper: Nullable,\r\n samples: number,\r\n initializeBuffers: boolean = true\r\n): number {\r\n if (this.webGLVersion < 2 || !rtWrapper || !rtWrapper.texture) {\r\n return 1;\r\n }\r\n\r\n if (rtWrapper.samples === samples) {\r\n return samples;\r\n }\r\n\r\n const count = rtWrapper._attachments!.length;\r\n\r\n if (count === 0) {\r\n return 1;\r\n }\r\n\r\n const gl = this._gl;\r\n\r\n samples = Math.min(samples, this.getCaps().maxMSAASamples);\r\n\r\n // Dispose previous render buffers\r\n const useDepthStencil = !!rtWrapper._depthStencilBuffer;\r\n if (useDepthStencil) {\r\n gl.deleteRenderbuffer(rtWrapper._depthStencilBuffer);\r\n rtWrapper._depthStencilBuffer = null;\r\n }\r\n\r\n if (rtWrapper._MSAAFramebuffer) {\r\n gl.deleteFramebuffer(rtWrapper._MSAAFramebuffer);\r\n rtWrapper._MSAAFramebuffer = null;\r\n }\r\n\r\n if (samples > 1 && typeof gl.renderbufferStorageMultisample === \"function\") {\r\n const framebuffer = gl.createFramebuffer();\r\n\r\n if (!framebuffer) {\r\n throw new Error(\"Unable to create multi sampled framebuffer\");\r\n }\r\n\r\n rtWrapper._MSAAFramebuffer = framebuffer;\r\n this._bindUnboundFramebuffer(framebuffer);\r\n\r\n const attachments = [];\r\n\r\n for (let i = 0; i < count; i++) {\r\n const texture = rtWrapper.textures![i];\r\n const hardwareTexture = texture._hardwareTexture as WebGLHardwareTexture;\r\n\r\n hardwareTexture.releaseMSAARenderBuffers();\r\n }\r\n\r\n for (let i = 0; i < count; i++) {\r\n const texture = rtWrapper.textures![i];\r\n const hardwareTexture = texture._hardwareTexture as WebGLHardwareTexture;\r\n const attachment = (gl)[this.webGLVersion > 1 ? \"COLOR_ATTACHMENT\" + i : \"COLOR_ATTACHMENT\" + i + \"_WEBGL\"];\r\n\r\n const colorRenderbuffer = this._createRenderBuffer(\r\n texture.width,\r\n texture.height,\r\n samples,\r\n -1 /* not used */,\r\n this._getRGBAMultiSampleBufferFormat(texture.type, texture.format),\r\n attachment\r\n );\r\n\r\n if (!colorRenderbuffer) {\r\n throw new Error(\"Unable to create multi sampled framebuffer\");\r\n }\r\n\r\n hardwareTexture.addMSAARenderBuffer(colorRenderbuffer);\r\n texture.samples = samples;\r\n\r\n attachments.push(attachment);\r\n }\r\n if (initializeBuffers) {\r\n gl.drawBuffers(attachments);\r\n }\r\n } else {\r\n this._bindUnboundFramebuffer(rtWrapper._framebuffer);\r\n }\r\n\r\n if (useDepthStencil) {\r\n rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(\r\n rtWrapper._generateStencilBuffer,\r\n rtWrapper._generateDepthBuffer,\r\n rtWrapper.texture.width,\r\n rtWrapper.texture.height,\r\n samples\r\n );\r\n }\r\n\r\n this._bindUnboundFramebuffer(null);\r\n\r\n return samples;\r\n};\r\n","import type { Scene } from \"../../scene\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\nimport \"../../Engines/Extensions/engine.multiRender\";\r\nimport type { InternalTexture } from \"./internalTexture\";\r\n\r\n/**\r\n * Creation options of the multi render target texture.\r\n */\r\nexport interface IMultiRenderTargetOptions {\r\n /**\r\n * Define if the texture needs to create mip maps after render.\r\n */\r\n generateMipMaps?: boolean;\r\n /**\r\n * Define the types of all the draw buffers we want to create\r\n */\r\n types?: number[];\r\n /**\r\n * Define the sampling modes of all the draw buffers we want to create\r\n */\r\n samplingModes?: number[];\r\n /**\r\n * Define if sRGB format should be used for each of the draw buffers we want to create\r\n */\r\n useSRGBBuffers?: boolean[];\r\n /**\r\n * Define if a depth buffer is required\r\n */\r\n generateDepthBuffer?: boolean;\r\n /**\r\n * Define if a stencil buffer is required\r\n */\r\n generateStencilBuffer?: boolean;\r\n /**\r\n * Define if a depth texture is required instead of a depth buffer\r\n */\r\n generateDepthTexture?: boolean;\r\n /**\r\n * Define the internal format of the buffer in the RTT (RED, RG, RGB, RGBA (default), ALPHA...) of all the draw buffers we want to create\r\n */\r\n formats?: number[];\r\n /**\r\n * Define depth texture format to use\r\n */\r\n depthTextureFormat?: number;\r\n /**\r\n * Define the number of desired draw buffers\r\n */\r\n textureCount?: number;\r\n /**\r\n * Define if aspect ratio should be adapted to the texture or stay the scene one\r\n */\r\n doNotChangeAspectRatio?: boolean;\r\n /**\r\n * Define the default type of the buffers we are creating\r\n */\r\n defaultType?: number;\r\n /**\r\n * Define the default type of the buffers we are creating\r\n */\r\n drawOnlyOnFirstAttachmentByDefault?: boolean;\r\n /**\r\n * Define the type of texture at each attahment index (of Constants.TEXTURE_2D, .TEXTURE_2D_ARRAY, .TEXTURE_CUBE_MAP, .TEXTURE_CUBE_MAP_ARRAY, .TEXTURE_3D).\r\n * You can also use the -1 value to indicate that no texture should be created but that you will assign a texture to that attachment index later.\r\n * Can be useful when you want to attach several layers of the same 2DArrayTexture / 3DTexture or several faces of the same CubeMapTexture: Use the setInternalTexture\r\n * method for that purpose, after the MultiRenderTarget has been created.\r\n */\r\n targetTypes?: number[];\r\n /**\r\n * Define the face index of each texture in the textures array (if applicable, given the corresponding targetType) at creation time (for Constants.TEXTURE_CUBE_MAP and .TEXTURE_CUBE_MAP_ARRAY).\r\n * Can be changed at any time by calling setLayerAndFaceIndices or setLayerAndFaceIndex\r\n */\r\n faceIndex?: number[];\r\n /**\r\n * Define the layer index of each texture in the textures array (if applicable, given the corresponding targetType) at creation time (for Constants.TEXTURE_3D, .TEXTURE_2D_ARRAY, and .TEXTURE_CUBE_MAP_ARRAY).\r\n * Can be changed at any time by calling setLayerAndFaceIndices or setLayerAndFaceIndex\r\n */\r\n layerIndex?: number[];\r\n /**\r\n * Define the number of layer of each texture in the textures array (if applicable, given the corresponding targetType) (for Constants.TEXTURE_3D, .TEXTURE_2D_ARRAY, and .TEXTURE_CUBE_MAP_ARRAY)\r\n */\r\n layerCounts?: number[];\r\n}\r\n\r\n/**\r\n * A multi render target, like a render target provides the ability to render to a texture.\r\n * Unlike the render target, it can render to several draw buffers in one draw.\r\n * This is specially interesting in deferred rendering or for any effects requiring more than\r\n * just one color from a single pass.\r\n */\r\nexport class MultiRenderTarget extends RenderTargetTexture {\r\n private _textures: Texture[];\r\n private _multiRenderTargetOptions: IMultiRenderTargetOptions;\r\n private _count: number;\r\n private _drawOnlyOnFirstAttachmentByDefault: boolean;\r\n private _textureNames?: string[];\r\n\r\n /**\r\n * Get if draw buffers are currently supported by the used hardware and browser.\r\n */\r\n public get isSupported(): boolean {\r\n return this._engine?.getCaps().drawBuffersExtension ?? false;\r\n }\r\n\r\n /**\r\n * Get the list of textures generated by the multi render target.\r\n */\r\n public get textures(): Texture[] {\r\n return this._textures;\r\n }\r\n\r\n /**\r\n * Gets the number of textures in this MRT. This number can be different from `_textures.length` in case a depth texture is generated.\r\n */\r\n public get count(): number {\r\n return this._count;\r\n }\r\n\r\n /**\r\n * Get the depth texture generated by the multi render target if options.generateDepthTexture has been set\r\n */\r\n public get depthTexture(): Texture {\r\n return this._textures[this._textures.length - 1];\r\n }\r\n\r\n /**\r\n * Set the wrapping mode on U of all the textures we are rendering to.\r\n * Can be any of the Texture. (CLAMP_ADDRESSMODE, MIRROR_ADDRESSMODE or WRAP_ADDRESSMODE)\r\n */\r\n public set wrapU(wrap: number) {\r\n if (this._textures) {\r\n for (let i = 0; i < this._textures.length; i++) {\r\n this._textures[i].wrapU = wrap;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Set the wrapping mode on V of all the textures we are rendering to.\r\n * Can be any of the Texture. (CLAMP_ADDRESSMODE, MIRROR_ADDRESSMODE or WRAP_ADDRESSMODE)\r\n */\r\n public set wrapV(wrap: number) {\r\n if (this._textures) {\r\n for (let i = 0; i < this._textures.length; i++) {\r\n this._textures[i].wrapV = wrap;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Instantiate a new multi render target texture.\r\n * A multi render target, like a render target provides the ability to render to a texture.\r\n * Unlike the render target, it can render to several draw buffers in one draw.\r\n * This is specially interesting in deferred rendering or for any effects requiring more than\r\n * just one color from a single pass.\r\n * @param name Define the name of the texture\r\n * @param size Define the size of the buffers to render to\r\n * @param count Define the number of target we are rendering into\r\n * @param scene Define the scene the texture belongs to\r\n * @param options Define the options used to create the multi render target\r\n * @param textureNames Define the names to set to the textures (if count > 0 - optional)\r\n */\r\n constructor(name: string, size: any, count: number, scene?: Scene, options?: IMultiRenderTargetOptions, textureNames?: string[]) {\r\n const generateMipMaps = options && options.generateMipMaps ? options.generateMipMaps : false;\r\n const generateDepthTexture = options && options.generateDepthTexture ? options.generateDepthTexture : false;\r\n const depthTextureFormat = options && options.depthTextureFormat ? options.depthTextureFormat : Constants.TEXTUREFORMAT_DEPTH16;\r\n const doNotChangeAspectRatio = !options || options.doNotChangeAspectRatio === undefined ? true : options.doNotChangeAspectRatio;\r\n const drawOnlyOnFirstAttachmentByDefault = options && options.drawOnlyOnFirstAttachmentByDefault ? options.drawOnlyOnFirstAttachmentByDefault : false;\r\n super(name, size, scene, generateMipMaps, doNotChangeAspectRatio, undefined, undefined, undefined, undefined, undefined, undefined, undefined, true);\r\n\r\n if (!this.isSupported) {\r\n this.dispose();\r\n return;\r\n }\r\n\r\n this._textureNames = textureNames;\r\n\r\n const types: number[] = [];\r\n const samplingModes: number[] = [];\r\n const useSRGBBuffers: boolean[] = [];\r\n const formats: number[] = [];\r\n const targetTypes: number[] = [];\r\n const faceIndex: number[] = [];\r\n const layerIndex: number[] = [];\r\n const layerCounts: number[] = [];\r\n this._initTypes(count, types, samplingModes, useSRGBBuffers, formats, targetTypes, faceIndex, layerIndex, layerCounts, options);\r\n\r\n const generateDepthBuffer = !options || options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;\r\n const generateStencilBuffer = !options || options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;\r\n\r\n this._multiRenderTargetOptions = {\r\n samplingModes: samplingModes,\r\n generateMipMaps: generateMipMaps,\r\n generateDepthBuffer: generateDepthBuffer,\r\n generateStencilBuffer: generateStencilBuffer,\r\n generateDepthTexture: generateDepthTexture,\r\n depthTextureFormat: depthTextureFormat,\r\n types: types,\r\n textureCount: count,\r\n useSRGBBuffers: useSRGBBuffers,\r\n formats: formats,\r\n targetTypes: targetTypes,\r\n faceIndex: faceIndex,\r\n layerIndex: layerIndex,\r\n layerCounts: layerCounts,\r\n };\r\n\r\n this._count = count;\r\n this._drawOnlyOnFirstAttachmentByDefault = drawOnlyOnFirstAttachmentByDefault;\r\n\r\n if (count > 0) {\r\n this._createInternalTextures();\r\n this._createTextures(textureNames);\r\n }\r\n }\r\n\r\n private _initTypes(\r\n count: number,\r\n types: number[],\r\n samplingModes: number[],\r\n useSRGBBuffers: boolean[],\r\n formats: number[],\r\n targets: number[],\r\n faceIndex: number[],\r\n layerIndex: number[],\r\n layerCounts: number[],\r\n options?: IMultiRenderTargetOptions\r\n ) {\r\n for (let i = 0; i < count; i++) {\r\n if (options && options.types && options.types[i] !== undefined) {\r\n types.push(options.types[i]);\r\n } else {\r\n types.push(options && options.defaultType ? options.defaultType : Constants.TEXTURETYPE_UNSIGNED_INT);\r\n }\r\n\r\n if (options && options.samplingModes && options.samplingModes[i] !== undefined) {\r\n samplingModes.push(options.samplingModes[i]);\r\n } else {\r\n samplingModes.push(Texture.BILINEAR_SAMPLINGMODE);\r\n }\r\n\r\n if (options && options.useSRGBBuffers && options.useSRGBBuffers[i] !== undefined) {\r\n useSRGBBuffers.push(options.useSRGBBuffers[i]);\r\n } else {\r\n useSRGBBuffers.push(false);\r\n }\r\n\r\n if (options && options.formats && options.formats[i] !== undefined) {\r\n formats.push(options.formats[i]);\r\n } else {\r\n formats.push(Constants.TEXTUREFORMAT_RGBA);\r\n }\r\n\r\n if (options && options.targetTypes && options.targetTypes[i] !== undefined) {\r\n targets.push(options.targetTypes[i]);\r\n } else {\r\n targets.push(Constants.TEXTURE_2D);\r\n }\r\n\r\n if (options && options.faceIndex && options.faceIndex[i] !== undefined) {\r\n faceIndex.push(options.faceIndex[i]);\r\n } else {\r\n faceIndex.push(0);\r\n }\r\n\r\n if (options && options.layerIndex && options.layerIndex[i] !== undefined) {\r\n layerIndex.push(options.layerIndex[i]);\r\n } else {\r\n layerIndex.push(0);\r\n }\r\n\r\n if (options && options.layerCounts && options.layerCounts[i] !== undefined) {\r\n layerCounts.push(options.layerCounts[i]);\r\n } else {\r\n layerCounts.push(1);\r\n }\r\n }\r\n }\r\n\r\n private _createInternaTextureIndexMapping() {\r\n const mapMainInternalTexture2Index: { [key: number]: number } = {};\r\n const mapInternalTexture2MainIndex: number[] = [];\r\n\r\n if (!this._renderTarget) {\r\n return mapInternalTexture2MainIndex;\r\n }\r\n\r\n const internalTextures = this._renderTarget!.textures!;\r\n for (let i = 0; i < internalTextures.length; i++) {\r\n const texture = internalTextures[i];\r\n if (!texture) {\r\n continue;\r\n }\r\n const mainIndex = mapMainInternalTexture2Index[texture.uniqueId];\r\n if (mainIndex !== undefined) {\r\n mapInternalTexture2MainIndex[i] = mainIndex;\r\n } else {\r\n mapMainInternalTexture2Index[texture.uniqueId] = i;\r\n }\r\n }\r\n\r\n return mapInternalTexture2MainIndex;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _rebuild(forceFullRebuild: boolean = false, textureNames?: string[]): void {\r\n if (this._count < 1) {\r\n return;\r\n }\r\n\r\n const mapInternalTexture2MainIndex = this._createInternaTextureIndexMapping();\r\n\r\n this.releaseInternalTextures();\r\n this._createInternalTextures();\r\n\r\n if (forceFullRebuild) {\r\n this._releaseTextures();\r\n this._createTextures(textureNames);\r\n }\r\n\r\n const internalTextures = this._renderTarget!.textures!;\r\n for (let i = 0; i < internalTextures.length; i++) {\r\n const texture = this._textures[i];\r\n if (mapInternalTexture2MainIndex[i] !== undefined) {\r\n this._renderTarget!.setTexture(internalTextures[mapInternalTexture2MainIndex[i]], i);\r\n }\r\n texture._texture = internalTextures[i];\r\n if (texture._texture) {\r\n texture._noMipmap = !texture._texture.useMipMaps;\r\n texture._useSRGBBuffer = texture._texture._useSRGBBuffer;\r\n }\r\n }\r\n\r\n if (this.samples !== 1) {\r\n this._renderTarget!.setSamples(this.samples, !this._drawOnlyOnFirstAttachmentByDefault, true);\r\n }\r\n }\r\n\r\n private _createInternalTextures(): void {\r\n this._renderTarget = this._getEngine()!.createMultipleRenderTarget(this._size, this._multiRenderTargetOptions, !this._drawOnlyOnFirstAttachmentByDefault);\r\n this._texture = this._renderTarget.texture;\r\n }\r\n\r\n private _releaseTextures(): void {\r\n if (this._textures) {\r\n for (let i = 0; i < this._textures.length; i++) {\r\n this._textures[i]._texture = null; // internal textures are released by a call to releaseInternalTextures()\r\n this._textures[i].dispose();\r\n }\r\n }\r\n }\r\n\r\n private _createTextures(textureNames?: string[]): void {\r\n const internalTextures = this._renderTarget!.textures!;\r\n this._textures = [];\r\n for (let i = 0; i < internalTextures.length; i++) {\r\n const texture = new Texture(null, this.getScene());\r\n if (textureNames?.[i]) {\r\n texture.name = textureNames[i];\r\n }\r\n texture._texture = internalTextures[i];\r\n if (texture._texture) {\r\n texture._noMipmap = !texture._texture.useMipMaps;\r\n texture._useSRGBBuffer = texture._texture._useSRGBBuffer;\r\n }\r\n this._textures.push(texture);\r\n }\r\n }\r\n\r\n /**\r\n * Replaces an internal texture within the MRT. Useful to share textures between MultiRenderTarget.\r\n * @param texture The new texture to set in the MRT\r\n * @param index The index of the texture to replace\r\n * @param disposePrevious Set to true if the previous internal texture should be disposed\r\n */\r\n public setInternalTexture(texture: InternalTexture, index: number, disposePrevious: boolean = true) {\r\n if (!this.renderTarget) {\r\n return;\r\n }\r\n\r\n if (index === 0) {\r\n this._texture = texture;\r\n }\r\n\r\n this.renderTarget.setTexture(texture, index, disposePrevious);\r\n\r\n if (!this.textures[index]) {\r\n this.textures[index] = new Texture(null, this.getScene());\r\n this.textures[index].name = this._textureNames?.[index] ?? this.textures[index].name;\r\n }\r\n this.textures[index]._texture = texture;\r\n this.textures[index]._noMipmap = !texture.useMipMaps;\r\n this.textures[index]._useSRGBBuffer = texture._useSRGBBuffer;\r\n\r\n this._count = this.renderTarget.textures ? this.renderTarget.textures.length : 0;\r\n\r\n if (this._multiRenderTargetOptions.types) {\r\n this._multiRenderTargetOptions.types[index] = texture.type;\r\n }\r\n if (this._multiRenderTargetOptions.samplingModes) {\r\n this._multiRenderTargetOptions.samplingModes[index] = texture.samplingMode;\r\n }\r\n if (this._multiRenderTargetOptions.useSRGBBuffers) {\r\n this._multiRenderTargetOptions.useSRGBBuffers[index] = texture._useSRGBBuffer;\r\n }\r\n if (this._multiRenderTargetOptions.targetTypes && this._multiRenderTargetOptions.targetTypes[index] !== -1) {\r\n let target: number = 0;\r\n if (texture.is2DArray) {\r\n target = Constants.TEXTURE_2D_ARRAY;\r\n } else if (texture.isCube) {\r\n target = Constants.TEXTURE_CUBE_MAP;\r\n } /*else if (texture.isCubeArray) {\r\n target = Constants.TEXTURE_CUBE_MAP_ARRAY;\r\n }*/ else if (texture.is3D) {\r\n target = Constants.TEXTURE_3D;\r\n } else {\r\n target = Constants.TEXTURE_2D;\r\n }\r\n this._multiRenderTargetOptions.targetTypes[index] = target;\r\n }\r\n }\r\n\r\n /**\r\n * Changes an attached texture's face index or layer.\r\n * @param index The index of the texture to modify the attachment of\r\n * @param layerIndex The layer index of the texture to be attached to the framebuffer\r\n * @param faceIndex The face index of the texture to be attached to the framebuffer\r\n */\r\n public setLayerAndFaceIndex(index: number, layerIndex: number = -1, faceIndex: number = -1) {\r\n if (!this.textures[index] || !this.renderTarget) {\r\n return;\r\n }\r\n\r\n if (this._multiRenderTargetOptions.layerIndex) {\r\n this._multiRenderTargetOptions.layerIndex[index] = layerIndex;\r\n }\r\n if (this._multiRenderTargetOptions.faceIndex) {\r\n this._multiRenderTargetOptions.faceIndex[index] = faceIndex;\r\n }\r\n\r\n this.renderTarget.setLayerAndFaceIndex(index, layerIndex, faceIndex);\r\n }\r\n\r\n /**\r\n * Changes every attached texture's face index or layer.\r\n * @param layerIndices The layer indices of the texture to be attached to the framebuffer\r\n * @param faceIndices The face indices of the texture to be attached to the framebuffer\r\n */\r\n public setLayerAndFaceIndices(layerIndices: number[], faceIndices: number[]) {\r\n if (!this.renderTarget) {\r\n return;\r\n }\r\n\r\n this._multiRenderTargetOptions.layerIndex = layerIndices;\r\n this._multiRenderTargetOptions.faceIndex = faceIndices;\r\n\r\n this.renderTarget.setLayerAndFaceIndices(layerIndices, faceIndices);\r\n }\r\n\r\n /**\r\n * Define the number of samples used if MSAA is enabled.\r\n */\r\n public get samples(): number {\r\n return this._samples;\r\n }\r\n\r\n public set samples(value: number) {\r\n if (this._renderTarget) {\r\n this._samples = this._renderTarget.setSamples(value);\r\n } else {\r\n // In case samples are set with 0 textures created, we must save the desired samples value\r\n this._samples = value;\r\n }\r\n }\r\n\r\n /**\r\n * Resize all the textures in the multi render target.\r\n * Be careful as it will recreate all the data in the new texture.\r\n * @param size Define the new size\r\n */\r\n public resize(size: any) {\r\n this._processSizeParameter(size, false);\r\n this._rebuild(undefined, this._textureNames);\r\n }\r\n\r\n /**\r\n * Changes the number of render targets in this MRT\r\n * Be careful as it will recreate all the data in the new texture.\r\n * @param count new texture count\r\n * @param options Specifies texture types and sampling modes for new textures\r\n * @param textureNames Specifies the names of the textures (optional)\r\n */\r\n public updateCount(count: number, options?: IMultiRenderTargetOptions, textureNames?: string[]) {\r\n this._multiRenderTargetOptions.textureCount = count;\r\n this._count = count;\r\n\r\n const types: number[] = [];\r\n const samplingModes: number[] = [];\r\n const useSRGBBuffers: boolean[] = [];\r\n const formats: number[] = [];\r\n const targetTypes: number[] = [];\r\n const faceIndex: number[] = [];\r\n const layerIndex: number[] = [];\r\n const layerCounts: number[] = [];\r\n\r\n this._textureNames = textureNames;\r\n\r\n this._initTypes(count, types, samplingModes, useSRGBBuffers, formats, targetTypes, faceIndex, layerIndex, layerCounts, options);\r\n this._multiRenderTargetOptions.types = types;\r\n this._multiRenderTargetOptions.samplingModes = samplingModes;\r\n this._multiRenderTargetOptions.useSRGBBuffers = useSRGBBuffers;\r\n this._multiRenderTargetOptions.formats = formats;\r\n this._multiRenderTargetOptions.targetTypes = targetTypes;\r\n this._multiRenderTargetOptions.faceIndex = faceIndex;\r\n this._multiRenderTargetOptions.layerIndex = layerIndex;\r\n this._multiRenderTargetOptions.layerCounts = layerCounts;\r\n\r\n this._rebuild(true, textureNames);\r\n }\r\n\r\n protected _unbindFrameBuffer(engine: Engine, faceIndex: number): void {\r\n if (this._renderTarget) {\r\n engine.unBindMultiColorAttachmentFramebuffer(this._renderTarget, this.isCube, () => {\r\n this.onAfterRenderObservable.notifyObservers(faceIndex);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the render targets and their associated resources\r\n * @param doNotDisposeInternalTextures\r\n */\r\n public dispose(doNotDisposeInternalTextures = false): void {\r\n this._releaseTextures();\r\n if (!doNotDisposeInternalTextures) {\r\n this.releaseInternalTextures();\r\n } else {\r\n // Prevent internal texture dispose in super.dispose\r\n this._texture = null;\r\n }\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Release all the underlying texture used as draw buffers.\r\n */\r\n public releaseInternalTextures(): void {\r\n const internalTextures = this._renderTarget?.textures;\r\n\r\n if (!internalTextures) {\r\n return;\r\n }\r\n\r\n for (let i = internalTextures.length - 1; i >= 0; i--) {\r\n this._textures[i]._texture = null;\r\n }\r\n\r\n this._renderTarget?.dispose();\r\n this._renderTarget = null;\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"mrtFragmentDeclaration\";\nconst shader = `#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nlayout(location=0) out vec4 glFragData[{X}];\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const mrtFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/mrtFragmentDeclaration\";\nimport \"./ShadersInclude/bumpFragmentMainFunctions\";\nimport \"./ShadersInclude/bumpFragmentFunctions\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/bumpFragment\";\n\nconst name = \"geometryPixelShader\";\nconst shader = `#extension GL_EXT_draw_buffers : require\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\nprecision highp float;\n#ifdef BUMP\nvarying mat4 vWorldView;varying vec3 vNormalW;\n#else\nvarying vec3 vNormalV;\n#endif\nvarying vec4 vViewPos;\n#if defined(POSITION) || defined(BUMP)\nvarying vec3 vPositionW;\n#endif\n#ifdef VELOCITY\nvarying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#ifdef NEED_UV\nvarying vec2 vUV;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIVITY)\n#if defined(ORMTEXTURE) || defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)\nuniform sampler2D reflectivitySampler;varying vec2 vReflectivityUV;\n#endif\n#ifdef ALBEDOTEXTURE\nvarying vec2 vAlbedoUV;uniform sampler2D albedoSampler;\n#endif\n#ifdef REFLECTIVITYCOLOR\nuniform vec3 reflectivityColor;\n#endif\n#ifdef ALBEDOCOLOR\nuniform vec3 albedoColor;\n#endif\n#ifdef METALLIC\nuniform float metallic;\n#endif\n#if defined(ROUGHNESS) || defined(GLOSSINESS)\nuniform float glossiness;\n#endif\n#endif\n#if defined(ALPHATEST) && defined(NEED_UV)\nuniform sampler2D diffuseSampler;\n#endif\n#include\n#include[RENDER_TARGET_COUNT]\n#include\n#include\n#include\nvoid main() {\n#include\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nvec3 normalOutput;\n#ifdef BUMP\nvec3 normalW=normalize(vNormalW);\n#include\nnormalOutput=normalize(vec3(vWorldView*vec4(normalW,0.0)));\n#else\nnormalOutput=normalize(vNormalV);\n#endif\n#ifdef PREPASS\n#ifdef PREPASS_DEPTH\ngl_FragData[DEPTH_INDEX]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n#endif\n#ifdef PREPASS_NORMAL\ngl_FragData[NORMAL_INDEX]=vec4(normalOutput,1.0);\n#endif\n#else\ngl_FragData[0]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);gl_FragData[1]=vec4(normalOutput,1.0);\n#endif\n#ifdef POSITION\ngl_FragData[POSITION_INDEX]=vec4(vPositionW,1.0);\n#endif\n#ifdef VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[VELOCITY_INDEX]=vec4(velocity,0.0,1.0);\n#endif\n#ifdef REFLECTIVITY\nvec4 reflectivity=vec4(0.0,0.0,0.0,1.0);\n#ifdef METALLICWORKFLOW\nfloat metal=1.0;float roughness=1.0;\n#ifdef ORMTEXTURE\nmetal*=texture2D(reflectivitySampler,vReflectivityUV).b;roughness*=texture2D(reflectivitySampler,vReflectivityUV).g;\n#endif\n#ifdef METALLIC\nmetal*=metallic;\n#endif\n#ifdef ROUGHNESS\nroughness*=(1.0-glossiness); \n#endif\nreflectivity.a-=roughness;vec3 color=vec3(1.0);\n#ifdef ALBEDOTEXTURE\ncolor=texture2D(albedoSampler,vAlbedoUV).rgb;\n#ifdef GAMMAALBEDO\ncolor=toLinearSpace(color);\n#endif\n#endif\n#ifdef ALBEDOCOLOR\ncolor*=albedoColor.xyz;\n#endif\nreflectivity.rgb=mix(vec3(0.04),color,metal);\n#else\n#if defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)\nreflectivity=texture2D(reflectivitySampler,vReflectivityUV);\n#ifdef GAMMAREFLECTIVITYTEXTURE\nreflectivity.rgb=toLinearSpace(reflectivity.rgb);\n#endif\n#else \n#ifdef REFLECTIVITYCOLOR\nreflectivity.rgb=toLinearSpace(reflectivityColor.xyz);reflectivity.a=1.0;\n#endif\n#endif\n#ifdef GLOSSINESSS\nreflectivity.a*=glossiness; \n#endif\n#endif\ngl_FragData[REFLECTIVITY_INDEX]=reflectivity;\n#endif\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const geometryPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"geometryVertexDeclaration\";\nconst shader = `uniform mat4 viewProjection;uniform mat4 view;`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const geometryVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./sceneUboDeclaration\";\n\nconst name = \"geometryUboDeclaration\";\nconst shader = `#include\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const geometryUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/geometryVertexDeclaration\";\nimport \"./ShadersInclude/geometryUboDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobal\";\nimport \"./ShadersInclude/morphTargetsVertex\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/clipPlaneVertex\";\nimport \"./ShadersInclude/bumpVertex\";\n\nconst name = \"geometryVertexShader\";\nconst shader = `precision highp float;\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#include<__decl__geometryVertex>\n#include\nattribute vec3 position;attribute vec3 normal;\n#ifdef NEED_UV\nvarying vec2 vUV;\n#ifdef ALPHATEST\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef BUMP\nuniform mat4 bumpMatrix;varying vec2 vBumpUV;\n#endif\n#ifdef REFLECTIVITY\nuniform mat4 reflectivityMatrix;uniform mat4 albedoMatrix;varying vec2 vReflectivityUV;varying vec2 vAlbedoUV;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#ifdef BUMP\nvarying mat4 vWorldView;\n#endif\n#ifdef BUMP\nvarying vec3 vNormalW;\n#else\nvarying vec3 vNormalV;\n#endif\nvarying vec4 vViewPos;\n#if defined(POSITION) || defined(BUMP)\nvarying vec3 vPositionW;\n#endif\n#ifdef VELOCITY\nuniform mat4 previousViewProjection;varying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;vec3 normalUpdated=normal;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\n#if defined(VELOCITY) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include\n#include\nvec4 worldPos=vec4(finalWorld*vec4(positionUpdated,1.0));\n#ifdef BUMP\nvWorldView=view*finalWorld;vNormalW=normalUpdated;\n#else\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normalUpdated,0.0)));\n#endif\nvViewPos=view*worldPos;\n#if defined(VELOCITY) && defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n#if NUM_BONE_INFLUENCERS>0\nmat4 previousInfluence;previousInfluence=mPreviousBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\npreviousInfluence+=mPreviousBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\npreviousInfluence+=mPreviousBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\npreviousInfluence+=mPreviousBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\nvPreviousPosition=previousViewProjection*finalPreviousWorld*previousInfluence*vec4(positionUpdated,1.0);\n#else\nvPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#endif\n#if defined(POSITION) || defined(BUMP)\nvPositionW=worldPos.xyz/worldPos.w;\n#endif\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n#include\n#ifdef NEED_UV\n#ifdef UV1\n#if defined(ALPHATEST) && defined(ALPHATEST_UV1)\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#else\nvUV=uv;\n#endif\n#ifdef BUMP_UV1\nvBumpUV=vec2(bumpMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef REFLECTIVITY_UV1\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef ALBEDO_UV1\nvAlbedoUV=vec2(albedoMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#endif\n#ifdef UV2\n#if defined(ALPHATEST) && defined(ALPHATEST_UV2)\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#else\nvUV=uv2;\n#endif\n#ifdef BUMP_UV2\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n#endif\n#ifdef REFLECTIVITY_UV2\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n#endif\n#ifdef ALBEDO_UV2\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#endif\n#include\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const geometryVertexShader = { name, shader };\n","import { Matrix } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { SmartArray } from \"../Misc/smartArray\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { MultiRenderTarget } from \"../Materials/Textures/multiRenderTarget\";\r\nimport type { PrePassRenderer } from \"../Rendering/prePassRenderer\";\r\nimport { MaterialHelper } from \"../Materials/materialHelper\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"../Materials/material\";\r\n\r\nimport \"../Shaders/geometry.fragment\";\r\nimport \"../Shaders/geometry.vertex\";\r\nimport { MaterialFlags } from \"../Materials/materialFlags\";\r\nimport { addClipPlaneUniforms, bindClipPlane, prepareStringDefinesForClipPlanes } from \"../Materials/clipPlaneMaterialHelper\";\r\n\r\n/** @internal */\r\ninterface ISavedTransformationMatrix {\r\n world: Matrix;\r\n viewProjection: Matrix;\r\n}\r\n\r\n/** list the uniforms used by the geometry renderer */\r\nconst uniforms = [\r\n \"world\",\r\n \"mBones\",\r\n \"viewProjection\",\r\n \"diffuseMatrix\",\r\n \"view\",\r\n \"previousWorld\",\r\n \"previousViewProjection\",\r\n \"mPreviousBones\",\r\n \"bumpMatrix\",\r\n \"reflectivityMatrix\",\r\n \"albedoMatrix\",\r\n \"reflectivityColor\",\r\n \"albedoColor\",\r\n \"metallic\",\r\n \"glossiness\",\r\n \"vTangentSpaceParams\",\r\n \"vBumpInfos\",\r\n \"morphTargetInfluences\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n];\r\naddClipPlaneUniforms(uniforms);\r\n\r\n/**\r\n * This renderer is helpful to fill one of the render target with a geometry buffer.\r\n */\r\nexport class GeometryBufferRenderer {\r\n /**\r\n * Constant used to retrieve the depth texture index in the G-Buffer textures array\r\n * using getIndex(GeometryBufferRenderer.DEPTH_TEXTURE_INDEX)\r\n */\r\n public static readonly DEPTH_TEXTURE_TYPE = 0;\r\n /**\r\n * Constant used to retrieve the normal texture index in the G-Buffer textures array\r\n * using getIndex(GeometryBufferRenderer.NORMAL_TEXTURE_INDEX)\r\n */\r\n public static readonly NORMAL_TEXTURE_TYPE = 1;\r\n /**\r\n * Constant used to retrieve the position texture index in the G-Buffer textures array\r\n * using getIndex(GeometryBufferRenderer.POSITION_TEXTURE_INDEX)\r\n */\r\n public static readonly POSITION_TEXTURE_TYPE = 2;\r\n /**\r\n * Constant used to retrieve the velocity texture index in the G-Buffer textures array\r\n * using getIndex(GeometryBufferRenderer.VELOCITY_TEXTURE_INDEX)\r\n */\r\n public static readonly VELOCITY_TEXTURE_TYPE = 3;\r\n /**\r\n * Constant used to retrieve the reflectivity texture index in the G-Buffer textures array\r\n * using the getIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE)\r\n */\r\n public static readonly REFLECTIVITY_TEXTURE_TYPE = 4;\r\n\r\n /**\r\n * Dictionary used to store the previous transformation matrices of each rendered mesh\r\n * in order to compute objects velocities when enableVelocity is set to \"true\"\r\n * @internal\r\n */\r\n public _previousTransformationMatrices: { [index: number]: ISavedTransformationMatrix } = {};\r\n /**\r\n * Dictionary used to store the previous bones transformation matrices of each rendered mesh\r\n * in order to compute objects velocities when enableVelocity is set to \"true\"\r\n * @internal\r\n */\r\n public _previousBonesTransformationMatrices: { [index: number]: Float32Array } = {};\r\n /**\r\n * Array used to store the ignored skinned meshes while computing velocity map (typically used by the motion blur post-process).\r\n * Avoids computing bones velocities and computes only mesh's velocity itself (position, rotation, scaling).\r\n */\r\n public excludedSkinnedMeshesFromVelocity: AbstractMesh[] = [];\r\n\r\n /** Gets or sets a boolean indicating if transparent meshes should be rendered */\r\n public renderTransparentMeshes = true;\r\n\r\n private _scene: Scene;\r\n private _resizeObserver: Nullable> = null;\r\n private _multiRenderTarget: MultiRenderTarget;\r\n private _ratio: number;\r\n private _enablePosition: boolean = false;\r\n private _enableVelocity: boolean = false;\r\n private _enableReflectivity: boolean = false;\r\n private _depthFormat: number;\r\n private _clearColor = new Color4(0, 0, 0, 0);\r\n private _clearDepthColor = new Color4(1e8, 0, 0, 1); // \"infinity\" value - depth in the depth texture is view.z, not a 0..1 value!\r\n\r\n private _positionIndex: number = -1;\r\n private _velocityIndex: number = -1;\r\n private _reflectivityIndex: number = -1;\r\n private _depthIndex: number = -1;\r\n private _normalIndex: number = -1;\r\n\r\n private _linkedWithPrePass: boolean = false;\r\n private _prePassRenderer: PrePassRenderer;\r\n private _attachmentsFromPrePass: number[];\r\n private _useUbo: boolean;\r\n\r\n protected _cachedDefines: string;\r\n\r\n /**\r\n * @internal\r\n * Sets up internal structures to share outputs with PrePassRenderer\r\n * This method should only be called by the PrePassRenderer itself\r\n */\r\n public _linkPrePassRenderer(prePassRenderer: PrePassRenderer) {\r\n this._linkedWithPrePass = true;\r\n this._prePassRenderer = prePassRenderer;\r\n\r\n if (this._multiRenderTarget) {\r\n // prevents clearing of the RT since it's done by prepass\r\n this._multiRenderTarget.onClearObservable.clear();\r\n this._multiRenderTarget.onClearObservable.add(() => {\r\n // pass\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Separates internal structures from PrePassRenderer so the geometry buffer can now operate by itself.\r\n * This method should only be called by the PrePassRenderer itself\r\n */\r\n public _unlinkPrePassRenderer() {\r\n this._linkedWithPrePass = false;\r\n this._createRenderTargets();\r\n }\r\n\r\n /**\r\n * @internal\r\n * Resets the geometry buffer layout\r\n */\r\n public _resetLayout() {\r\n this._enablePosition = false;\r\n this._enableReflectivity = false;\r\n this._enableVelocity = false;\r\n this._attachmentsFromPrePass = [];\r\n }\r\n\r\n /**\r\n * @internal\r\n * Replaces a texture in the geometry buffer renderer\r\n * Useful when linking textures of the prepass renderer\r\n */\r\n public _forceTextureType(geometryBufferType: number, index: number) {\r\n if (geometryBufferType === GeometryBufferRenderer.POSITION_TEXTURE_TYPE) {\r\n this._positionIndex = index;\r\n this._enablePosition = true;\r\n } else if (geometryBufferType === GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE) {\r\n this._velocityIndex = index;\r\n this._enableVelocity = true;\r\n } else if (geometryBufferType === GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE) {\r\n this._reflectivityIndex = index;\r\n this._enableReflectivity = true;\r\n } else if (geometryBufferType === GeometryBufferRenderer.DEPTH_TEXTURE_TYPE) {\r\n this._depthIndex = index;\r\n } else if (geometryBufferType === GeometryBufferRenderer.NORMAL_TEXTURE_TYPE) {\r\n this._normalIndex = index;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Sets texture attachments\r\n * Useful when linking textures of the prepass renderer\r\n */\r\n public _setAttachments(attachments: number[]) {\r\n this._attachmentsFromPrePass = attachments;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Replaces the first texture which is hard coded as a depth texture in the geometry buffer\r\n * Useful when linking textures of the prepass renderer\r\n */\r\n public _linkInternalTexture(internalTexture: InternalTexture) {\r\n this._multiRenderTarget.setInternalTexture(internalTexture, 0, false);\r\n }\r\n\r\n /**\r\n * Gets the render list (meshes to be rendered) used in the G buffer.\r\n */\r\n public get renderList() {\r\n return this._multiRenderTarget.renderList;\r\n }\r\n\r\n /**\r\n * Set the render list (meshes to be rendered) used in the G buffer.\r\n */\r\n public set renderList(meshes: Nullable) {\r\n this._multiRenderTarget.renderList = meshes;\r\n }\r\n\r\n /**\r\n * Gets whether or not G buffer are supported by the running hardware.\r\n * This requires draw buffer supports\r\n */\r\n public get isSupported(): boolean {\r\n return this._multiRenderTarget.isSupported;\r\n }\r\n\r\n /**\r\n * Returns the index of the given texture type in the G-Buffer textures array\r\n * @param textureType The texture type constant. For example GeometryBufferRenderer.POSITION_TEXTURE_INDEX\r\n * @returns the index of the given texture type in the G-Buffer textures array\r\n */\r\n public getTextureIndex(textureType: number): number {\r\n switch (textureType) {\r\n case GeometryBufferRenderer.POSITION_TEXTURE_TYPE:\r\n return this._positionIndex;\r\n case GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE:\r\n return this._velocityIndex;\r\n case GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE:\r\n return this._reflectivityIndex;\r\n default:\r\n return -1;\r\n }\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if objects positions are enabled for the G buffer.\r\n */\r\n public get enablePosition(): boolean {\r\n return this._enablePosition;\r\n }\r\n\r\n /**\r\n * Sets whether or not objects positions are enabled for the G buffer.\r\n */\r\n public set enablePosition(enable: boolean) {\r\n this._enablePosition = enable;\r\n\r\n // PrePass handles index and texture links\r\n if (!this._linkedWithPrePass) {\r\n this.dispose();\r\n this._createRenderTargets();\r\n }\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if objects velocities are enabled for the G buffer.\r\n */\r\n public get enableVelocity(): boolean {\r\n return this._enableVelocity;\r\n }\r\n\r\n /**\r\n * Sets whether or not objects velocities are enabled for the G buffer.\r\n */\r\n public set enableVelocity(enable: boolean) {\r\n this._enableVelocity = enable;\r\n\r\n if (!enable) {\r\n this._previousTransformationMatrices = {};\r\n }\r\n\r\n if (!this._linkedWithPrePass) {\r\n this.dispose();\r\n this._createRenderTargets();\r\n }\r\n\r\n this._scene.needsPreviousWorldMatrices = enable;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if objects reflectivity are enabled in the G buffer.\r\n */\r\n public get enableReflectivity(): boolean {\r\n return this._enableReflectivity;\r\n }\r\n\r\n /**\r\n * Sets whether or not objects reflectivity are enabled for the G buffer.\r\n * For Metallic-Roughness workflow with ORM texture, we assume that ORM texture is defined according to the default layout:\r\n * pbr.useRoughnessFromMetallicTextureAlpha = false;\r\n * pbr.useRoughnessFromMetallicTextureGreen = true;\r\n * pbr.useMetallnessFromMetallicTextureBlue = true;\r\n */\r\n public set enableReflectivity(enable: boolean) {\r\n this._enableReflectivity = enable;\r\n\r\n if (!this._linkedWithPrePass) {\r\n this.dispose();\r\n this._createRenderTargets();\r\n }\r\n }\r\n\r\n /**\r\n * If set to true (default: false), the depth texture will be cleared with the depth value corresponding to the far plane (1 in normal mode, 0 in reverse depth buffer mode)\r\n * If set to false, the depth texture is always cleared with 0.\r\n */\r\n public useSpecificClearForDepthTexture = false;\r\n\r\n /**\r\n * Gets the scene associated with the buffer.\r\n */\r\n public get scene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Gets the ratio used by the buffer during its creation.\r\n * How big is the buffer related to the main canvas.\r\n */\r\n public get ratio(): number {\r\n return this._ratio;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {\r\n throw _WarnImport(\"GeometryBufferRendererSceneComponent\");\r\n };\r\n\r\n /**\r\n * Creates a new G Buffer for the scene\r\n * @param scene The scene the buffer belongs to\r\n * @param ratio How big is the buffer related to the main canvas (default: 1)\r\n * @param depthFormat Format of the depth texture (default: Constants.TEXTUREFORMAT_DEPTH16)\r\n */\r\n constructor(scene: Scene, ratio: number = 1, depthFormat = Constants.TEXTUREFORMAT_DEPTH16) {\r\n this._scene = scene;\r\n this._ratio = ratio;\r\n this._useUbo = scene.getEngine().supportsUniformBuffers;\r\n this._depthFormat = depthFormat;\r\n\r\n GeometryBufferRenderer._SceneComponentInitialization(this._scene);\r\n\r\n // Render target\r\n this._createRenderTargets();\r\n }\r\n\r\n /**\r\n * Checks whether everything is ready to render a submesh to the G buffer.\r\n * @param subMesh the submesh to check readiness for\r\n * @param useInstances is the mesh drawn using instance or not\r\n * @returns true if ready otherwise false\r\n */\r\n public isReady(subMesh: SubMesh, useInstances: boolean): boolean {\r\n const material = subMesh.getMaterial();\r\n\r\n if (material && material.disableDepthWrite) {\r\n return false;\r\n }\r\n\r\n const defines = [];\r\n const attribs = [VertexBuffer.PositionKind, VertexBuffer.NormalKind];\r\n const mesh = subMesh.getMesh();\r\n\r\n // Alpha test\r\n if (material) {\r\n let needUv = false;\r\n if (material.needAlphaTesting() && material.getAlphaTestTexture()) {\r\n defines.push(\"#define ALPHATEST\");\r\n defines.push(`#define ALPHATEST_UV${material.getAlphaTestTexture().coordinatesIndex + 1}`);\r\n needUv = true;\r\n }\r\n\r\n if (material.bumpTexture && MaterialFlags.BumpTextureEnabled) {\r\n defines.push(\"#define BUMP\");\r\n defines.push(`#define BUMP_UV${material.bumpTexture.coordinatesIndex + 1}`);\r\n needUv = true;\r\n }\r\n\r\n if (this._enableReflectivity) {\r\n let metallicWorkflow = false;\r\n // for PBR materials: cf. https://doc.babylonjs.com/features/featuresDeepDive/materials/using/masterPBR\r\n if (material.getClassName() === \"PBRMetallicRoughnessMaterial\") {\r\n // if it is a PBR material in MetallicRoughness Mode:\r\n if (material.metallicRoughnessTexture !== null) {\r\n defines.push(\"#define ORMTEXTURE\");\r\n defines.push(`#define REFLECTIVITY_UV${material.metallicRoughnessTexture.coordinatesIndex + 1}`);\r\n defines.push(\"#define METALLICWORKFLOW\");\r\n needUv = true;\r\n metallicWorkflow = true;\r\n }\r\n if (material.metallic !== null) {\r\n defines.push(\"#define METALLIC\");\r\n defines.push(\"#define METALLICWORKFLOW\");\r\n metallicWorkflow = true;\r\n }\r\n if (material.roughness !== null) {\r\n defines.push(\"#define ROUGHNESS\");\r\n defines.push(\"#define METALLICWORKFLOW\");\r\n metallicWorkflow = true;\r\n }\r\n if (metallicWorkflow) {\r\n if (material.baseTexture !== null) {\r\n defines.push(\"#define ALBEDOTEXTURE\");\r\n defines.push(`#define ALBEDO_UV${material.baseTexture.coordinatesIndex + 1}`);\r\n if (material.baseTexture.gammaSpace) {\r\n defines.push(\"#define GAMMAALBEDO\");\r\n }\r\n needUv = true;\r\n }\r\n if (material.baseColor !== null) {\r\n defines.push(\"#define ALBEDOCOLOR\");\r\n }\r\n }\r\n } else if (material.getClassName() === \"PBRSpecularGlossinessMaterial\") {\r\n // if it is a PBR material in Specular/Glossiness Mode:\r\n if (material.specularGlossinessTexture !== null) {\r\n defines.push(\"#define SPECULARGLOSSINESSTEXTURE\");\r\n defines.push(`#define REFLECTIVITY_UV${material.specularGlossinessTexture.coordinatesIndex + 1}`);\r\n needUv = true;\r\n if (material.specularGlossinessTexture.gammaSpace) {\r\n defines.push(\"#define GAMMAREFLECTIVITYTEXTURE\");\r\n }\r\n } else {\r\n if (material.specularColor !== null) {\r\n defines.push(\"#define REFLECTIVITYCOLOR\");\r\n }\r\n }\r\n if (material.glossiness !== null) {\r\n defines.push(\"#define GLOSSINESS\");\r\n }\r\n } else if (material.getClassName() === \"PBRMaterial\") {\r\n // if it is the bigger PBRMaterial\r\n if (material.metallicTexture !== null) {\r\n defines.push(\"#define ORMTEXTURE\");\r\n defines.push(`#define REFLECTIVITY_UV${material.metallicTexture.coordinatesIndex + 1}`);\r\n defines.push(\"#define METALLICWORKFLOW\");\r\n needUv = true;\r\n metallicWorkflow = true;\r\n }\r\n if (material.metallic !== null) {\r\n defines.push(\"#define METALLIC\");\r\n defines.push(\"#define METALLICWORKFLOW\");\r\n metallicWorkflow = true;\r\n }\r\n\r\n if (material.roughness !== null) {\r\n defines.push(\"#define ROUGHNESS\");\r\n defines.push(\"#define METALLICWORKFLOW\");\r\n metallicWorkflow = true;\r\n }\r\n\r\n if (metallicWorkflow) {\r\n if (material.albedoTexture !== null) {\r\n defines.push(\"#define ALBEDOTEXTURE\");\r\n defines.push(`#define ALBEDO_UV${material.albedoTexture.coordinatesIndex + 1}`);\r\n if (material.albedoTexture.gammaSpace) {\r\n defines.push(\"#define GAMMAALBEDO\");\r\n }\r\n needUv = true;\r\n }\r\n if (material.albedoColor !== null) {\r\n defines.push(\"#define ALBEDOCOLOR\");\r\n }\r\n } else {\r\n // SpecularGlossiness Model\r\n if (material.reflectivityTexture !== null) {\r\n defines.push(\"#define SPECULARGLOSSINESSTEXTURE\");\r\n defines.push(`#define REFLECTIVITY_UV${material.reflectivityTexture.coordinatesIndex + 1}`);\r\n if (material.reflectivityTexture.gammaSpace) {\r\n defines.push(\"#define GAMMAREFLECTIVITYTEXTURE\");\r\n }\r\n needUv = true;\r\n } else if (material.reflectivityColor !== null) {\r\n defines.push(\"#define REFLECTIVITYCOLOR\");\r\n }\r\n if (material.microSurface !== null) {\r\n defines.push(\"#define GLOSSINESS\");\r\n }\r\n }\r\n } else if (material.getClassName() === \"StandardMaterial\") {\r\n // if StandardMaterial:\r\n if (material.specularTexture !== null) {\r\n defines.push(\"#define REFLECTIVITYTEXTURE\");\r\n defines.push(`#define REFLECTIVITY_UV${material.specularTexture.coordinatesIndex + 1}`);\r\n if (material.specularTexture.gammaSpace) {\r\n defines.push(\"#define GAMMAREFLECTIVITYTEXTURE\");\r\n }\r\n needUv = true;\r\n }\r\n if (material.specularColor !== null) {\r\n defines.push(\"#define REFLECTIVITYCOLOR\");\r\n }\r\n }\r\n }\r\n\r\n if (needUv) {\r\n defines.push(\"#define NEED_UV\");\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n attribs.push(VertexBuffer.UVKind);\r\n defines.push(\"#define UV1\");\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\r\n attribs.push(VertexBuffer.UV2Kind);\r\n defines.push(\"#define UV2\");\r\n }\r\n }\r\n }\r\n\r\n // PrePass\r\n if (this._linkedWithPrePass) {\r\n defines.push(\"#define PREPASS\");\r\n if (this._depthIndex !== -1) {\r\n defines.push(\"#define DEPTH_INDEX \" + this._depthIndex);\r\n defines.push(\"#define PREPASS_DEPTH\");\r\n }\r\n if (this._normalIndex !== -1) {\r\n defines.push(\"#define NORMAL_INDEX \" + this._normalIndex);\r\n defines.push(\"#define PREPASS_NORMAL\");\r\n }\r\n }\r\n\r\n // Buffers\r\n if (this._enablePosition) {\r\n defines.push(\"#define POSITION\");\r\n defines.push(\"#define POSITION_INDEX \" + this._positionIndex);\r\n }\r\n\r\n if (this._enableVelocity) {\r\n defines.push(\"#define VELOCITY\");\r\n defines.push(\"#define VELOCITY_INDEX \" + this._velocityIndex);\r\n if (this.excludedSkinnedMeshesFromVelocity.indexOf(mesh) === -1) {\r\n defines.push(\"#define BONES_VELOCITY_ENABLED\");\r\n }\r\n }\r\n\r\n if (this._enableReflectivity) {\r\n defines.push(\"#define REFLECTIVITY\");\r\n defines.push(\"#define REFLECTIVITY_INDEX \" + this._reflectivityIndex);\r\n }\r\n\r\n // Bones\r\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n defines.push(\"#define BonesPerMesh \" + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph targets\r\n const morphTargetManager = (mesh as Mesh).morphTargetManager;\r\n let numMorphInfluencers = 0;\r\n if (morphTargetManager) {\r\n if (morphTargetManager.numInfluencers > 0) {\r\n numMorphInfluencers = morphTargetManager.numInfluencers;\r\n\r\n defines.push(\"#define MORPHTARGETS\");\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numMorphInfluencers);\r\n if (morphTargetManager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n }\r\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, numMorphInfluencers);\r\n }\r\n }\r\n\r\n // Instances\r\n if (useInstances) {\r\n defines.push(\"#define INSTANCES\");\r\n MaterialHelper.PushAttributesForInstances(attribs, this._enableVelocity);\r\n if (subMesh.getRenderingMesh().hasThinInstances) {\r\n defines.push(\"#define THIN_INSTANCES\");\r\n }\r\n }\r\n\r\n // Setup textures count\r\n if (this._linkedWithPrePass) {\r\n defines.push(\"#define RENDER_TARGET_COUNT \" + this._attachmentsFromPrePass.length);\r\n } else {\r\n defines.push(\"#define RENDER_TARGET_COUNT \" + this._multiRenderTarget.textures.length);\r\n }\r\n\r\n prepareStringDefinesForClipPlanes(material, this._scene, defines);\r\n\r\n // Get correct effect\r\n const engine = this._scene.getEngine();\r\n const drawWrapper = subMesh._getDrawWrapper(undefined, true)!;\r\n const cachedDefines = drawWrapper.defines;\r\n const join = defines.join(\"\\n\");\r\n if (cachedDefines !== join) {\r\n drawWrapper.setEffect(\r\n engine.createEffect(\r\n \"geometry\",\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n samplers: [\"diffuseSampler\", \"bumpSampler\", \"reflectivitySampler\", \"albedoSampler\", \"morphTargets\"],\r\n defines: join,\r\n onCompiled: null,\r\n fallbacks: null,\r\n onError: null,\r\n uniformBuffersNames: [\"Scene\"],\r\n indexParameters: { buffersCount: this._multiRenderTarget.textures.length - 1, maxSimultaneousMorphTargets: numMorphInfluencers },\r\n },\r\n engine\r\n ),\r\n join\r\n );\r\n }\r\n\r\n return drawWrapper.effect!.isReady();\r\n }\r\n\r\n /**\r\n * Gets the current underlying G Buffer.\r\n * @returns the buffer\r\n */\r\n public getGBuffer(): MultiRenderTarget {\r\n return this._multiRenderTarget;\r\n }\r\n\r\n /**\r\n * Gets the number of samples used to render the buffer (anti aliasing).\r\n */\r\n public get samples(): number {\r\n return this._multiRenderTarget.samples;\r\n }\r\n\r\n /**\r\n * Sets the number of samples used to render the buffer (anti aliasing).\r\n */\r\n public set samples(value: number) {\r\n this._multiRenderTarget.samples = value;\r\n }\r\n\r\n /**\r\n * Disposes the renderer and frees up associated resources.\r\n */\r\n public dispose(): void {\r\n if (this._resizeObserver) {\r\n const engine = this._scene.getEngine();\r\n engine.onResizeObservable.remove(this._resizeObserver);\r\n this._resizeObserver = null;\r\n }\r\n this.getGBuffer().dispose();\r\n }\r\n\r\n private _assignRenderTargetIndices(): [number, string[]] {\r\n const textureNames: string[] = [];\r\n let count = 2;\r\n\r\n textureNames.push(\"gBuffer_Depth\", \"gBuffer_Normal\");\r\n\r\n if (this._enablePosition) {\r\n this._positionIndex = count;\r\n count++;\r\n textureNames.push(\"gBuffer_Position\");\r\n }\r\n\r\n if (this._enableVelocity) {\r\n this._velocityIndex = count;\r\n count++;\r\n textureNames.push(\"gBuffer_Velocity\");\r\n }\r\n\r\n if (this._enableReflectivity) {\r\n this._reflectivityIndex = count;\r\n count++;\r\n textureNames.push(\"gBuffer_Reflectivity\");\r\n }\r\n\r\n return [count, textureNames];\r\n }\r\n\r\n protected _createRenderTargets(): void {\r\n const engine = this._scene.getEngine();\r\n const [count, textureNames] = this._assignRenderTargetIndices();\r\n\r\n let type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (engine._caps.textureFloat && engine._caps.textureFloatLinearFiltering) {\r\n type = Constants.TEXTURETYPE_FLOAT;\r\n } else if (engine._caps.textureHalfFloat && engine._caps.textureHalfFloatLinearFiltering) {\r\n type = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n\r\n this._multiRenderTarget = new MultiRenderTarget(\r\n \"gBuffer\",\r\n { width: engine.getRenderWidth() * this._ratio, height: engine.getRenderHeight() * this._ratio },\r\n count,\r\n this._scene,\r\n { generateMipMaps: false, generateDepthTexture: true, defaultType: type, depthTextureFormat: this._depthFormat },\r\n textureNames.concat(\"gBuffer_DepthBuffer\")\r\n );\r\n if (!this.isSupported) {\r\n return;\r\n }\r\n this._multiRenderTarget.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this._multiRenderTarget.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n this._multiRenderTarget.refreshRate = 1;\r\n this._multiRenderTarget.renderParticles = false;\r\n this._multiRenderTarget.renderList = null;\r\n\r\n // Depth is always the first texture in the geometry buffer renderer!\r\n const layoutAttachmentsAll = [true];\r\n const layoutAttachmentsAllButDepth = [false];\r\n const layoutAttachmentsDepthOnly = [true];\r\n\r\n for (let i = 1; i < count; ++i) {\r\n layoutAttachmentsAll.push(true);\r\n layoutAttachmentsDepthOnly.push(false);\r\n layoutAttachmentsAllButDepth.push(true);\r\n }\r\n\r\n const attachmentsAll = engine.buildTextureLayout(layoutAttachmentsAll);\r\n const attachmentsAllButDepth = engine.buildTextureLayout(layoutAttachmentsAllButDepth);\r\n const attachmentsDepthOnly = engine.buildTextureLayout(layoutAttachmentsDepthOnly);\r\n\r\n this._multiRenderTarget.onClearObservable.add((engine) => {\r\n engine.bindAttachments(this.useSpecificClearForDepthTexture ? attachmentsAllButDepth : attachmentsAll);\r\n engine.clear(this._clearColor, true, true, true);\r\n if (this.useSpecificClearForDepthTexture) {\r\n engine.bindAttachments(attachmentsDepthOnly);\r\n engine.clear(this._clearDepthColor, true, true, true);\r\n }\r\n engine.bindAttachments(attachmentsAll);\r\n });\r\n\r\n this._resizeObserver = engine.onResizeObservable.add(() => {\r\n if (this._multiRenderTarget) {\r\n this._multiRenderTarget.resize({ width: engine.getRenderWidth() * this._ratio, height: engine.getRenderHeight() * this._ratio });\r\n }\r\n });\r\n\r\n // Custom render function\r\n const renderSubMesh = (subMesh: SubMesh): void => {\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n const effectiveMesh = subMesh.getEffectiveMesh();\r\n const scene = this._scene;\r\n const engine = scene.getEngine();\r\n const material = subMesh.getMaterial();\r\n\r\n if (!material) {\r\n return;\r\n }\r\n\r\n effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;\r\n\r\n // Velocity\r\n if (this._enableVelocity && !this._previousTransformationMatrices[effectiveMesh.uniqueId]) {\r\n this._previousTransformationMatrices[effectiveMesh.uniqueId] = {\r\n world: Matrix.Identity(),\r\n viewProjection: scene.getTransformMatrix(),\r\n };\r\n\r\n if (renderingMesh.skeleton) {\r\n const bonesTransformations = renderingMesh.skeleton.getTransformMatrices(renderingMesh);\r\n this._previousBonesTransformationMatrices[renderingMesh.uniqueId] = this._copyBonesTransformationMatrices(\r\n bonesTransformations,\r\n new Float32Array(bonesTransformations.length)\r\n );\r\n }\r\n }\r\n\r\n // Managing instances\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\r\n\r\n if (batch.mustReturn) {\r\n return;\r\n }\r\n\r\n const hardwareInstancedRendering = engine.getCaps().instancedArrays && (batch.visibleInstances[subMesh._id] !== null || renderingMesh.hasThinInstances);\r\n const world = effectiveMesh.getWorldMatrix();\r\n\r\n if (this.isReady(subMesh, hardwareInstancedRendering)) {\r\n const drawWrapper = subMesh._getDrawWrapper();\r\n\r\n if (!drawWrapper) {\r\n return;\r\n }\r\n\r\n const effect = drawWrapper.effect!;\r\n\r\n engine.enableEffect(drawWrapper);\r\n if (!hardwareInstancedRendering) {\r\n renderingMesh._bind(subMesh, effect, material.fillMode);\r\n }\r\n\r\n if (!this._useUbo) {\r\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n effect.setMatrix(\"view\", scene.getViewMatrix());\r\n } else {\r\n MaterialHelper.BindSceneUniformBuffer(effect, this._scene.getSceneUniformBuffer());\r\n this._scene.finalizeSceneUbo();\r\n }\r\n\r\n let sideOrientation: Nullable;\r\n const instanceDataStorage = (renderingMesh as Mesh)._instanceDataStorage;\r\n\r\n if (!instanceDataStorage.isFrozen && (material.backFaceCulling || renderingMesh.overrideMaterialSideOrientation !== null)) {\r\n const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();\r\n sideOrientation = renderingMesh.overrideMaterialSideOrientation;\r\n if (sideOrientation === null) {\r\n sideOrientation = material.sideOrientation;\r\n }\r\n if (mainDeterminant < 0) {\r\n sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;\r\n }\r\n } else {\r\n sideOrientation = instanceDataStorage.sideOrientation;\r\n }\r\n\r\n material._preBind(drawWrapper, sideOrientation);\r\n\r\n // Alpha test\r\n if (material.needAlphaTesting()) {\r\n const alphaTexture = material.getAlphaTestTexture();\r\n if (alphaTexture) {\r\n effect.setTexture(\"diffuseSampler\", alphaTexture);\r\n effect.setMatrix(\"diffuseMatrix\", alphaTexture.getTextureMatrix());\r\n }\r\n }\r\n\r\n // Bump\r\n if (material.bumpTexture && scene.getEngine().getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled) {\r\n effect.setFloat3(\"vBumpInfos\", material.bumpTexture.coordinatesIndex, 1.0 / material.bumpTexture.level, material.parallaxScaleBias);\r\n effect.setMatrix(\"bumpMatrix\", material.bumpTexture.getTextureMatrix());\r\n effect.setTexture(\"bumpSampler\", material.bumpTexture);\r\n effect.setFloat2(\"vTangentSpaceParams\", material.invertNormalMapX ? -1.0 : 1.0, material.invertNormalMapY ? -1.0 : 1.0);\r\n }\r\n\r\n // Reflectivity\r\n if (this._enableReflectivity) {\r\n // for PBR materials: cf. https://doc.babylonjs.com/features/featuresDeepDive/materials/using/masterPBR\r\n if (material.getClassName() === \"PBRMetallicRoughnessMaterial\") {\r\n // if it is a PBR material in MetallicRoughness Mode:\r\n if (material.metallicRoughnessTexture !== null) {\r\n effect.setTexture(\"reflectivitySampler\", material.metallicRoughnessTexture);\r\n effect.setMatrix(\"reflectivityMatrix\", material.metallicRoughnessTexture.getTextureMatrix());\r\n }\r\n if (material.metallic !== null) {\r\n effect.setFloat(\"metallic\", material.metallic);\r\n }\r\n if (material.roughness !== null) {\r\n effect.setFloat(\"glossiness\", 1.0 - material.roughness);\r\n }\r\n if (material.baseTexture !== null) {\r\n effect.setTexture(\"albedoSampler\", material.baseTexture);\r\n effect.setMatrix(\"albedoMatrix\", material.baseTexture.getTextureMatrix());\r\n }\r\n if (material.baseColor !== null) {\r\n effect.setColor3(\"albedoColor\", material.baseColor);\r\n }\r\n } else if (material.getClassName() === \"PBRSpecularGlossinessMaterial\") {\r\n // if it is a PBR material in Specular/Glossiness Mode:\r\n if (material.specularGlossinessTexture !== null) {\r\n effect.setTexture(\"reflectivitySampler\", material.specularGlossinessTexture);\r\n effect.setMatrix(\"reflectivityMatrix\", material.specularGlossinessTexture.getTextureMatrix());\r\n } else {\r\n if (material.specularColor !== null) {\r\n effect.setColor3(\"reflectivityColor\", material.specularColor);\r\n }\r\n }\r\n if (material.glossiness !== null) {\r\n effect.setFloat(\"glossiness\", material.glossiness);\r\n }\r\n } else if (material.getClassName() === \"PBRMaterial\") {\r\n // if it is the bigger PBRMaterial\r\n if (material.metallicTexture !== null) {\r\n effect.setTexture(\"reflectivitySampler\", material.metallicTexture);\r\n effect.setMatrix(\"reflectivityMatrix\", material.metallicTexture.getTextureMatrix());\r\n }\r\n if (material.metallic !== null) {\r\n effect.setFloat(\"metallic\", material.metallic);\r\n }\r\n\r\n if (material.roughness !== null) {\r\n effect.setFloat(\"glossiness\", 1.0 - material.roughness);\r\n }\r\n\r\n if (material.roughness !== null || material.metallic !== null || material.metallicTexture !== null) {\r\n // MetallicRoughness Model\r\n if (material.albedoTexture !== null) {\r\n effect.setTexture(\"albedoSampler\", material.albedoTexture);\r\n effect.setMatrix(\"albedoMatrix\", material.albedoTexture.getTextureMatrix());\r\n }\r\n if (material.albedoColor !== null) {\r\n effect.setColor3(\"albedoColor\", material.albedoColor);\r\n }\r\n } else {\r\n // SpecularGlossiness Model\r\n if (material.reflectivityTexture !== null) {\r\n effect.setTexture(\"reflectivitySampler\", material.reflectivityTexture);\r\n effect.setMatrix(\"reflectivityMatrix\", material.reflectivityTexture.getTextureMatrix());\r\n } else if (material.reflectivityColor !== null) {\r\n effect.setColor3(\"reflectivityColor\", material.reflectivityColor);\r\n }\r\n if (material.microSurface !== null) {\r\n effect.setFloat(\"glossiness\", material.microSurface);\r\n }\r\n }\r\n } else if (material.getClassName() === \"StandardMaterial\") {\r\n // if StandardMaterial:\r\n if (material.specularTexture !== null) {\r\n effect.setTexture(\"reflectivitySampler\", material.specularTexture);\r\n effect.setMatrix(\"reflectivityMatrix\", material.specularTexture.getTextureMatrix());\r\n }\r\n if (material.specularColor !== null) {\r\n effect.setColor3(\"reflectivityColor\", material.specularColor);\r\n }\r\n }\r\n }\r\n\r\n // Clip plane\r\n bindClipPlane(effect, material, this._scene);\r\n\r\n // Bones\r\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\r\n effect.setMatrices(\"mBones\", renderingMesh.skeleton.getTransformMatrices(renderingMesh));\r\n if (this._enableVelocity) {\r\n effect.setMatrices(\"mPreviousBones\", this._previousBonesTransformationMatrices[renderingMesh.uniqueId]);\r\n }\r\n }\r\n\r\n // Morph targets\r\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\r\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\r\n renderingMesh.morphTargetManager._bind(effect);\r\n }\r\n\r\n // Velocity\r\n if (this._enableVelocity) {\r\n effect.setMatrix(\"previousWorld\", this._previousTransformationMatrices[effectiveMesh.uniqueId].world);\r\n effect.setMatrix(\"previousViewProjection\", this._previousTransformationMatrices[effectiveMesh.uniqueId].viewProjection);\r\n }\r\n\r\n if (hardwareInstancedRendering && renderingMesh.hasThinInstances) {\r\n effect.setMatrix(\"world\", world);\r\n }\r\n\r\n // Draw\r\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, w) => {\r\n if (!isInstance) {\r\n effect.setMatrix(\"world\", w);\r\n }\r\n });\r\n }\r\n\r\n // Velocity\r\n if (this._enableVelocity) {\r\n this._previousTransformationMatrices[effectiveMesh.uniqueId].world = world.clone();\r\n this._previousTransformationMatrices[effectiveMesh.uniqueId].viewProjection = this._scene.getTransformMatrix().clone();\r\n if (renderingMesh.skeleton) {\r\n this._copyBonesTransformationMatrices(\r\n renderingMesh.skeleton.getTransformMatrices(renderingMesh),\r\n this._previousBonesTransformationMatrices[effectiveMesh.uniqueId]\r\n );\r\n }\r\n }\r\n };\r\n\r\n this._multiRenderTarget.customIsReadyFunction = (mesh: AbstractMesh, refreshRate: number, preWarm?: boolean) => {\r\n if ((preWarm || refreshRate === 0) && mesh.subMeshes) {\r\n for (let i = 0; i < mesh.subMeshes.length; ++i) {\r\n const subMesh = mesh.subMeshes[i];\r\n const material = subMesh.getMaterial();\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n\r\n if (!material) {\r\n continue;\r\n }\r\n\r\n const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());\r\n const hardwareInstancedRendering = engine.getCaps().instancedArrays && (batch.visibleInstances[subMesh._id] !== null || renderingMesh.hasThinInstances);\r\n\r\n if (!this.isReady(subMesh, hardwareInstancedRendering)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n };\r\n\r\n this._multiRenderTarget.customRenderFunction = (\r\n opaqueSubMeshes: SmartArray,\r\n alphaTestSubMeshes: SmartArray,\r\n transparentSubMeshes: SmartArray,\r\n depthOnlySubMeshes: SmartArray\r\n ): void => {\r\n let index;\r\n\r\n if (this._linkedWithPrePass) {\r\n if (!this._prePassRenderer.enabled) {\r\n return;\r\n }\r\n this._scene.getEngine().bindAttachments(this._attachmentsFromPrePass);\r\n }\r\n\r\n if (depthOnlySubMeshes.length) {\r\n engine.setColorWrite(false);\r\n for (index = 0; index < depthOnlySubMeshes.length; index++) {\r\n renderSubMesh(depthOnlySubMeshes.data[index]);\r\n }\r\n engine.setColorWrite(true);\r\n }\r\n\r\n for (index = 0; index < opaqueSubMeshes.length; index++) {\r\n renderSubMesh(opaqueSubMeshes.data[index]);\r\n }\r\n\r\n engine.setDepthWrite(false);\r\n for (index = 0; index < alphaTestSubMeshes.length; index++) {\r\n renderSubMesh(alphaTestSubMeshes.data[index]);\r\n }\r\n\r\n if (this.renderTransparentMeshes) {\r\n for (index = 0; index < transparentSubMeshes.length; index++) {\r\n renderSubMesh(transparentSubMeshes.data[index]);\r\n }\r\n }\r\n engine.setDepthWrite(true);\r\n };\r\n }\r\n\r\n // Copies the bones transformation matrices into the target array and returns the target's reference\r\n private _copyBonesTransformationMatrices(source: Float32Array, target: Float32Array): Float32Array {\r\n for (let i = 0; i < source.length; i++) {\r\n target[i] = source[i];\r\n }\r\n\r\n return target;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport type { SmartArrayNoDuplicate } from \"../Misc/smartArray\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { GeometryBufferRenderer } from \"./geometryBufferRenderer\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _geometryBufferRenderer: Nullable;\r\n\r\n /**\r\n * Gets or Sets the current geometry buffer associated to the scene.\r\n */\r\n geometryBufferRenderer: Nullable;\r\n\r\n /**\r\n * Enables a GeometryBufferRender and associates it with the scene\r\n * @param ratio defines the scaling ratio to apply to the renderer (1 by default which means same resolution)\r\n * @param depthFormat Format of the depth texture (default: Constants.TEXTUREFORMAT_DEPTH16)\r\n * @returns the GeometryBufferRenderer\r\n */\r\n enableGeometryBufferRenderer(ratio?: number, depthFormat?: number): Nullable;\r\n\r\n /**\r\n * Disables the GeometryBufferRender associated with the scene\r\n */\r\n disableGeometryBufferRenderer(): void;\r\n }\r\n}\r\n\r\nObject.defineProperty(Scene.prototype, \"geometryBufferRenderer\", {\r\n get: function (this: Scene) {\r\n return this._geometryBufferRenderer;\r\n },\r\n set: function (this: Scene, value: Nullable) {\r\n if (value && value.isSupported) {\r\n this._geometryBufferRenderer = value;\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\nScene.prototype.enableGeometryBufferRenderer = function (ratio: number = 1, depthFormat = Constants.TEXTUREFORMAT_DEPTH16): Nullable {\r\n if (this._geometryBufferRenderer) {\r\n return this._geometryBufferRenderer;\r\n }\r\n\r\n this._geometryBufferRenderer = new GeometryBufferRenderer(this, ratio, depthFormat);\r\n if (!this._geometryBufferRenderer.isSupported) {\r\n this._geometryBufferRenderer = null;\r\n }\r\n\r\n return this._geometryBufferRenderer;\r\n};\r\n\r\nScene.prototype.disableGeometryBufferRenderer = function (): void {\r\n if (!this._geometryBufferRenderer) {\r\n return;\r\n }\r\n\r\n this._geometryBufferRenderer.dispose();\r\n this._geometryBufferRenderer = null;\r\n};\r\n\r\n/**\r\n * Defines the Geometry Buffer scene component responsible to manage a G-Buffer useful\r\n * in several rendering techniques.\r\n */\r\nexport class GeometryBufferRendererSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER, this, this._gatherRenderTargets);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate): void {\r\n if (this.scene._geometryBufferRenderer) {\r\n renderTargets.push(this.scene._geometryBufferRenderer.getGBuffer());\r\n }\r\n }\r\n}\r\n\r\nGeometryBufferRenderer._SceneComponentInitialization = (scene: Scene) => {\r\n // Register the G Buffer component to the scene.\r\n let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER) as GeometryBufferRendererSceneComponent;\r\n if (!component) {\r\n component = new GeometryBufferRendererSceneComponent(scene);\r\n scene._addComponent(component);\r\n }\r\n};\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/logDepthFragment\";\n\nconst name = \"outlinePixelShader\";\nconst shader = `#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;uniform sampler2D diffuseSampler;\n#endif\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const outlinePixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/bonesDeclaration\";\nimport \"./ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/instancesDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexGlobal\";\nimport \"./ShadersInclude/morphTargetsVertex\";\nimport \"./ShadersInclude/instancesVertex\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\nimport \"./ShadersInclude/clipPlaneVertex\";\nimport \"./ShadersInclude/logDepthVertex\";\n\nconst name = \"outlineVertexShader\";\nconst shader = `attribute vec3 position;attribute vec3 normal;\n#include\n#include\n#include\n#include[0..maxSimultaneousMorphTargets]\n#include\nuniform float offset;\n#include\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;uniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;vec3 normalUpdated=normal;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#include\n#include[0..maxSimultaneousMorphTargets]\nvec3 offsetPosition=positionUpdated+(normalUpdated*offset);\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(offsetPosition,1.0);gl_Position=viewProjection*worldPos;\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include\n#include\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const outlineVertexShader = { name, shader };\n","import { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { _InstancesBatch } from \"../Meshes/mesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport { MaterialHelper } from \"../Materials/materialHelper\";\r\n\r\nimport \"../Shaders/outline.fragment\";\r\nimport \"../Shaders/outline.vertex\";\r\nimport { addClipPlaneUniforms, bindClipPlane, prepareStringDefinesForClipPlanes } from \"core/Materials/clipPlaneMaterialHelper\";\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal */\r\n _outlineRenderer: OutlineRenderer;\r\n\r\n /**\r\n * Gets the outline renderer associated with the scene\r\n * @returns a OutlineRenderer\r\n */\r\n getOutlineRenderer(): OutlineRenderer;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the outline renderer associated with the scene\r\n * @returns a OutlineRenderer\r\n */\r\nScene.prototype.getOutlineRenderer = function (): OutlineRenderer {\r\n if (!this._outlineRenderer) {\r\n this._outlineRenderer = new OutlineRenderer(this);\r\n }\r\n return this._outlineRenderer;\r\n};\r\n\r\ndeclare module \"../Meshes/abstractMesh\" {\r\n export interface AbstractMesh {\r\n /** @internal (Backing field) */\r\n _renderOutline: boolean;\r\n /**\r\n * Gets or sets a boolean indicating if the outline must be rendered as well\r\n * @see https://www.babylonjs-playground.com/#10WJ5S#3\r\n */\r\n renderOutline: boolean;\r\n\r\n /** @internal (Backing field) */\r\n _renderOverlay: boolean;\r\n /**\r\n * Gets or sets a boolean indicating if the overlay must be rendered as well\r\n * @see https://www.babylonjs-playground.com/#10WJ5S#2\r\n */\r\n renderOverlay: boolean;\r\n }\r\n}\r\n\r\nObject.defineProperty(Mesh.prototype, \"renderOutline\", {\r\n get: function (this: Mesh) {\r\n return this._renderOutline;\r\n },\r\n set: function (this: Mesh, value: boolean) {\r\n if (value) {\r\n // Lazy Load the component.\r\n this.getScene().getOutlineRenderer();\r\n }\r\n this._renderOutline = value;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\nObject.defineProperty(Mesh.prototype, \"renderOverlay\", {\r\n get: function (this: Mesh) {\r\n return this._renderOverlay;\r\n },\r\n set: function (this: Mesh, value: boolean) {\r\n if (value) {\r\n // Lazy Load the component.\r\n this.getScene().getOutlineRenderer();\r\n }\r\n this._renderOverlay = value;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * This class is responsible to draw the outline/overlay of meshes.\r\n * It should not be used directly but through the available method on mesh.\r\n */\r\nexport class OutlineRenderer implements ISceneComponent {\r\n /**\r\n * Stencil value used to avoid outline being seen within the mesh when the mesh is transparent\r\n */\r\n private static _StencilReference = 0x04;\r\n /**\r\n * The name of the component. Each component must have a unique name.\r\n */\r\n public name = SceneComponentConstants.NAME_OUTLINERENDERER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Defines a zOffset default Factor to prevent zFighting between the overlay and the mesh.\r\n */\r\n public zOffset = 1;\r\n\r\n /**\r\n * Defines a zOffset default Unit to prevent zFighting between the overlay and the mesh.\r\n */\r\n public zOffsetUnits = 4; // 4 to account for projection a bit by default\r\n\r\n private _engine: Engine;\r\n private _savedDepthWrite: boolean;\r\n private _passIdForDrawWrapper: number[];\r\n\r\n /**\r\n * Instantiates a new outline renderer. (There could be only one per scene).\r\n * @param scene Defines the scene it belongs to\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n this._engine = scene.getEngine();\r\n this.scene._addComponent(this);\r\n this._passIdForDrawWrapper = [];\r\n for (let i = 0; i < 4; ++i) {\r\n this._passIdForDrawWrapper[i] = this._engine.createRenderPassId(`Outline Renderer (${i})`);\r\n }\r\n }\r\n\r\n /**\r\n * Register the component to one instance of a scene.\r\n */\r\n public register(): void {\r\n this.scene._beforeRenderingMeshStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERINGMESH_OUTLINE, this, this._beforeRenderingMesh);\r\n this.scene._afterRenderingMeshStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGMESH_OUTLINE, this, this._afterRenderingMesh);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do here.\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources.\r\n */\r\n public dispose(): void {\r\n for (let i = 0; i < this._passIdForDrawWrapper.length; ++i) {\r\n this._engine.releaseRenderPassId(this._passIdForDrawWrapper[i]);\r\n }\r\n }\r\n\r\n /**\r\n * Renders the outline in the canvas.\r\n * @param subMesh Defines the sumesh to render\r\n * @param batch Defines the batch of meshes in case of instances\r\n * @param useOverlay Defines if the rendering is for the overlay or the outline\r\n * @param renderPassId Render pass id to use to render the mesh\r\n */\r\n public render(subMesh: SubMesh, batch: _InstancesBatch, useOverlay: boolean = false, renderPassId?: number): void {\r\n renderPassId = renderPassId ?? this._passIdForDrawWrapper[0];\r\n\r\n const scene = this.scene;\r\n const engine = scene.getEngine();\r\n\r\n const hardwareInstancedRendering =\r\n engine.getCaps().instancedArrays &&\r\n ((batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined) || subMesh.getRenderingMesh().hasThinInstances);\r\n\r\n if (!this.isReady(subMesh, hardwareInstancedRendering, renderPassId)) {\r\n return;\r\n }\r\n\r\n const ownerMesh = subMesh.getMesh();\r\n const replacementMesh = ownerMesh._internalAbstractMeshDataInfo._actAsRegularMesh ? ownerMesh : null;\r\n const renderingMesh = subMesh.getRenderingMesh();\r\n const effectiveMesh = replacementMesh ? replacementMesh : renderingMesh;\r\n const material = subMesh.getMaterial();\r\n\r\n if (!material || !scene.activeCamera) {\r\n return;\r\n }\r\n\r\n const drawWrapper = subMesh._getDrawWrapper(renderPassId)!;\r\n const effect = DrawWrapper.GetEffect(drawWrapper)!;\r\n\r\n engine.enableEffect(drawWrapper);\r\n\r\n // Logarithmic depth\r\n if ((material).useLogarithmicDepth) {\r\n effect.setFloat(\"logarithmicDepthConstant\", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));\r\n }\r\n\r\n effect.setFloat(\"offset\", useOverlay ? 0 : renderingMesh.outlineWidth);\r\n effect.setColor4(\"color\", useOverlay ? renderingMesh.overlayColor : renderingMesh.outlineColor, useOverlay ? renderingMesh.overlayAlpha : material.alpha);\r\n effect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n effect.setMatrix(\"world\", effectiveMesh.getWorldMatrix());\r\n\r\n // Bones\r\n if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {\r\n effect.setMatrices(\"mBones\", renderingMesh.skeleton.getTransformMatrices(renderingMesh));\r\n }\r\n\r\n if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {\r\n renderingMesh.morphTargetManager._bind(effect);\r\n }\r\n\r\n // Morph targets\r\n MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);\r\n\r\n if (!hardwareInstancedRendering) {\r\n renderingMesh._bind(subMesh, effect, material.fillMode);\r\n }\r\n\r\n // Alpha test\r\n if (material && material.needAlphaTesting()) {\r\n const alphaTexture = material.getAlphaTestTexture();\r\n if (alphaTexture) {\r\n effect.setTexture(\"diffuseSampler\", alphaTexture);\r\n effect.setMatrix(\"diffuseMatrix\", alphaTexture.getTextureMatrix());\r\n }\r\n }\r\n\r\n // Clip plane\r\n bindClipPlane(effect, material, scene);\r\n\r\n engine.setZOffset(-this.zOffset);\r\n engine.setZOffsetUnits(-this.zOffsetUnits);\r\n\r\n renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) => {\r\n effect.setMatrix(\"world\", world);\r\n });\r\n\r\n engine.setZOffset(0);\r\n engine.setZOffsetUnits(0);\r\n }\r\n\r\n /**\r\n * Returns whether or not the outline renderer is ready for a given submesh.\r\n * All the dependencies e.g. submeshes, texture, effect... mus be ready\r\n * @param subMesh Defines the submesh to check readiness for\r\n * @param useInstances Defines whether wee are trying to render instances or not\r\n * @param renderPassId Render pass id to use to render the mesh\r\n * @returns true if ready otherwise false\r\n */\r\n public isReady(subMesh: SubMesh, useInstances: boolean, renderPassId?: number): boolean {\r\n renderPassId = renderPassId ?? this._passIdForDrawWrapper[0];\r\n\r\n const defines = [];\r\n const attribs = [VertexBuffer.PositionKind, VertexBuffer.NormalKind];\r\n\r\n const mesh = subMesh.getMesh();\r\n const material = subMesh.getMaterial();\r\n\r\n if (!material) {\r\n return false;\r\n }\r\n\r\n const scene = mesh.getScene();\r\n\r\n // Alpha test\r\n if (material.needAlphaTesting()) {\r\n defines.push(\"#define ALPHATEST\");\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n attribs.push(VertexBuffer.UVKind);\r\n defines.push(\"#define UV1\");\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {\r\n attribs.push(VertexBuffer.UV2Kind);\r\n defines.push(\"#define UV2\");\r\n }\r\n }\r\n //Logarithmic depth\r\n if ((material).useLogarithmicDepth) {\r\n defines.push(\"#define LOGARITHMICDEPTH\");\r\n }\r\n // Clip planes\r\n prepareStringDefinesForClipPlanes(material, scene, defines);\r\n\r\n // Bones\r\n if (mesh.useBones && mesh.computeBonesUsingShaders) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n defines.push(\"#define BonesPerMesh \" + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph targets\r\n const morphTargetManager = (mesh as Mesh).morphTargetManager;\r\n let numMorphInfluencers = 0;\r\n if (morphTargetManager) {\r\n if (morphTargetManager.numInfluencers > 0) {\r\n numMorphInfluencers = morphTargetManager.numInfluencers;\r\n\r\n defines.push(\"#define MORPHTARGETS\");\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numMorphInfluencers);\r\n\r\n if (morphTargetManager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, numMorphInfluencers);\r\n }\r\n }\r\n\r\n // Instances\r\n if (useInstances) {\r\n defines.push(\"#define INSTANCES\");\r\n MaterialHelper.PushAttributesForInstances(attribs);\r\n if (subMesh.getRenderingMesh().hasThinInstances) {\r\n defines.push(\"#define THIN_INSTANCES\");\r\n }\r\n }\r\n\r\n // Get correct effect\r\n const drawWrapper = subMesh._getDrawWrapper(renderPassId, true)!;\r\n const cachedDefines = drawWrapper.defines;\r\n const join = defines.join(\"\\n\");\r\n\r\n if (cachedDefines !== join) {\r\n const uniforms = [\r\n \"world\",\r\n \"mBones\",\r\n \"viewProjection\",\r\n \"diffuseMatrix\",\r\n \"offset\",\r\n \"color\",\r\n \"logarithmicDepthConstant\",\r\n \"morphTargetInfluences\",\r\n \"morphTargetTextureInfo\",\r\n \"morphTargetTextureIndices\",\r\n ];\r\n addClipPlaneUniforms(uniforms);\r\n\r\n drawWrapper.setEffect(\r\n this.scene.getEngine().createEffect(\"outline\", attribs, uniforms, [\"diffuseSampler\", \"morphTargets\"], join, undefined, undefined, undefined, {\r\n maxSimultaneousMorphTargets: numMorphInfluencers,\r\n }),\r\n join\r\n );\r\n }\r\n\r\n return drawWrapper.effect!.isReady();\r\n }\r\n\r\n private _beforeRenderingMesh(mesh: Mesh, subMesh: SubMesh, batch: _InstancesBatch): void {\r\n // Outline - step 1\r\n this._savedDepthWrite = this._engine.getDepthWrite();\r\n if (mesh.renderOutline) {\r\n const material = subMesh.getMaterial();\r\n if (material && material.needAlphaBlendingForMesh(mesh)) {\r\n this._engine.cacheStencilState();\r\n // Draw only to stencil buffer for the original mesh\r\n // The resulting stencil buffer will be used so the outline is not visible inside the mesh when the mesh is transparent\r\n this._engine.setDepthWrite(false);\r\n this._engine.setColorWrite(false);\r\n this._engine.setStencilBuffer(true);\r\n this._engine.setStencilOperationPass(Constants.REPLACE);\r\n this._engine.setStencilFunction(Constants.ALWAYS);\r\n this._engine.setStencilMask(OutlineRenderer._StencilReference);\r\n this._engine.setStencilFunctionReference(OutlineRenderer._StencilReference);\r\n this._engine.stencilStateComposer.useStencilGlobalOnly = true;\r\n this.render(subMesh, batch, /* This sets offset to 0 */ true, this._passIdForDrawWrapper[1]);\r\n\r\n this._engine.setColorWrite(true);\r\n this._engine.setStencilFunction(Constants.NOTEQUAL);\r\n }\r\n\r\n // Draw the outline using the above stencil if needed to avoid drawing within the mesh\r\n this._engine.setDepthWrite(false);\r\n this.render(subMesh, batch, false, this._passIdForDrawWrapper[0]);\r\n this._engine.setDepthWrite(this._savedDepthWrite);\r\n\r\n if (material && material.needAlphaBlendingForMesh(mesh)) {\r\n this._engine.stencilStateComposer.useStencilGlobalOnly = false;\r\n this._engine.restoreStencilState();\r\n }\r\n }\r\n }\r\n\r\n private _afterRenderingMesh(mesh: Mesh, subMesh: SubMesh, batch: _InstancesBatch): void {\r\n // Overlay\r\n if (mesh.renderOverlay) {\r\n const currentMode = this._engine.getAlphaMode();\r\n const alphaBlendState = this._engine.alphaState.alphaBlend;\r\n this._engine.setAlphaMode(Constants.ALPHA_COMBINE);\r\n this.render(subMesh, batch, true, this._passIdForDrawWrapper[3]);\r\n this._engine.setAlphaMode(currentMode);\r\n this._engine.setDepthWrite(this._savedDepthWrite);\r\n this._engine.alphaState.alphaBlend = alphaBlendState;\r\n }\r\n\r\n // Outline - step 2\r\n if (mesh.renderOutline && this._savedDepthWrite) {\r\n this._engine.setDepthWrite(true);\r\n this._engine.setColorWrite(false);\r\n this.render(subMesh, batch, false, this._passIdForDrawWrapper[2]);\r\n this._engine.setColorWrite(true);\r\n }\r\n }\r\n}\r\n","import type { IMultiRenderTargetOptions } from \"./multiRenderTarget\";\r\nimport { MultiRenderTarget } from \"./multiRenderTarget\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { RenderTargetTexture } from \"./renderTargetTexture\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport { ImageProcessingPostProcess } from \"../../PostProcesses/imageProcessingPostProcess\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * A multi render target designed to render the prepass.\r\n * Prepass is a scene component used to render information in multiple textures\r\n * alongside with the scene materials rendering.\r\n * Note : This is an internal class, and you should NOT need to instanciate this.\r\n * Only the `PrePassRenderer` should instanciate this class.\r\n * It is more likely that you need a regular `MultiRenderTarget`\r\n * @internal\r\n */\r\nexport class PrePassRenderTarget extends MultiRenderTarget {\r\n /**\r\n * @internal\r\n */\r\n public _beforeCompositionPostProcesses: PostProcess[] = [];\r\n /**\r\n * Image processing post process for composition\r\n */\r\n public imageProcessingPostProcess: ImageProcessingPostProcess;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _engine: Engine;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _scene: Scene;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _outputPostProcess: Nullable;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _internalTextureDirty = false;\r\n\r\n /**\r\n * Is this render target enabled for prepass rendering\r\n */\r\n public enabled: boolean = false;\r\n\r\n /**\r\n * Render target associated with this prePassRenderTarget\r\n * If this is `null`, it means this prePassRenderTarget is associated with the scene\r\n */\r\n public renderTargetTexture: Nullable = null;\r\n\r\n public constructor(name: string, renderTargetTexture: Nullable, size: any, count: number, scene?: Scene, options?: IMultiRenderTargetOptions | undefined) {\r\n super(name, size, count, scene, options);\r\n\r\n this.renderTargetTexture = renderTargetTexture;\r\n }\r\n\r\n /**\r\n * Creates a composition effect for this RT\r\n * @internal\r\n */\r\n public _createCompositionEffect() {\r\n this.imageProcessingPostProcess = new ImageProcessingPostProcess(\"prePassComposition\", 1, null, undefined, this._engine);\r\n this.imageProcessingPostProcess._updateParameters();\r\n }\r\n\r\n /**\r\n * Checks that the size of this RT is still adapted to the desired render size.\r\n * @internal\r\n */\r\n public _checkSize() {\r\n const requiredWidth = this._engine.getRenderWidth(true);\r\n const requiredHeight = this._engine.getRenderHeight(true);\r\n\r\n const width = this.getRenderWidth();\r\n const height = this.getRenderHeight();\r\n\r\n if (width !== requiredWidth || height !== requiredHeight) {\r\n this.resize({ width: requiredWidth, height: requiredHeight });\r\n\r\n this._internalTextureDirty = true;\r\n }\r\n }\r\n\r\n /**\r\n * Changes the number of render targets in this MRT\r\n * Be careful as it will recreate all the data in the new texture.\r\n * @param count new texture count\r\n * @param options Specifies texture types and sampling modes for new textures\r\n * @param textureNames Specifies the names of the textures (optional)\r\n */\r\n public updateCount(count: number, options?: IMultiRenderTargetOptions, textureNames?: string[]) {\r\n super.updateCount(count, options, textureNames);\r\n this._internalTextureDirty = true;\r\n }\r\n\r\n /**\r\n * Resets the post processes chains applied to this RT.\r\n * @internal\r\n */\r\n public _resetPostProcessChain() {\r\n this._beforeCompositionPostProcesses.length = 0;\r\n }\r\n\r\n /**\r\n * Diposes this render target\r\n */\r\n public dispose() {\r\n const scene = this._scene;\r\n\r\n super.dispose();\r\n\r\n if (scene && scene.prePassRenderer) {\r\n const index = scene.prePassRenderer.renderTargets.indexOf(this);\r\n\r\n if (index !== -1) {\r\n scene.prePassRenderer.renderTargets.splice(index, 1);\r\n }\r\n }\r\n\r\n if (this.imageProcessingPostProcess) {\r\n this.imageProcessingPostProcess.dispose();\r\n }\r\n\r\n if (this.renderTargetTexture) {\r\n this.renderTargetTexture._prePassRenderTarget = null;\r\n }\r\n\r\n if (this._outputPostProcess) {\r\n this._outputPostProcess.autoClear = true;\r\n this._outputPostProcess.restoreDefaultInputTexture();\r\n }\r\n }\r\n}\r\n","import { PrePassRenderTarget } from \"../Materials/Textures/prePassRenderTarget\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Material } from \"../Materials/material\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { PrePassEffectConfiguration } from \"./prePassEffectConfiguration\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { GeometryBufferRenderer } from \"../Rendering/geometryBufferRenderer\";\r\n\r\n/**\r\n * Renders a pre pass of the scene\r\n * This means every mesh in the scene will be rendered to a render target texture\r\n * And then this texture will be composited to the rendering canvas with post processes\r\n * It is necessary for effects like subsurface scattering or deferred shading\r\n */\r\nexport class PrePassRenderer {\r\n /**\r\n * @internal\r\n */\r\n public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {\r\n throw _WarnImport(\"PrePassRendererSceneComponent\");\r\n };\r\n\r\n /**\r\n * To save performance, we can excluded skinned meshes from the prepass\r\n */\r\n public excludedSkinnedMesh: AbstractMesh[] = [];\r\n\r\n /**\r\n * Force material to be excluded from the prepass\r\n * Can be useful when `useGeometryBufferFallback` is set to `true`\r\n * and you don't want a material to show in the effect.\r\n */\r\n public excludedMaterials: Material[] = [];\r\n\r\n private _scene: Scene;\r\n private _engine: Engine;\r\n\r\n /**\r\n * Number of textures in the multi render target texture where the scene is directly rendered\r\n */\r\n public mrtCount: number = 0;\r\n\r\n private _mrtTypes: number[] = [];\r\n private _mrtFormats: number[] = [];\r\n private _mrtLayout: number[] = [];\r\n private _mrtNames: string[] = [];\r\n private _textureIndices: number[] = [];\r\n\r\n private _multiRenderAttachments: number[];\r\n private _defaultAttachments: number[];\r\n private _clearAttachments: number[];\r\n private _clearDepthAttachments: number[];\r\n\r\n /**\r\n * Returns the index of a texture in the multi render target texture array.\r\n * @param type Texture type\r\n * @returns The index\r\n */\r\n public getIndex(type: number): number {\r\n return this._textureIndices[type];\r\n }\r\n\r\n /**\r\n * How many samples are used for MSAA of the scene render target\r\n */\r\n public get samples() {\r\n return this.defaultRT.samples;\r\n }\r\n\r\n public set samples(n: number) {\r\n this.defaultRT.samples = n;\r\n }\r\n\r\n private _useSpecificClearForDepthTexture = false;\r\n\r\n /**\r\n * If set to true (default: false), the depth texture will be cleared with the depth value corresponding to the far plane (1 in normal mode, 0 in reverse depth buffer mode)\r\n * If set to false, the depth texture is always cleared with 0.\r\n */\r\n public get useSpecificClearForDepthTexture() {\r\n return this._useSpecificClearForDepthTexture;\r\n }\r\n\r\n public set useSpecificClearForDepthTexture(value: boolean) {\r\n if (this._useSpecificClearForDepthTexture === value) {\r\n return;\r\n }\r\n\r\n this._useSpecificClearForDepthTexture = value;\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Describes the types and formats of the textures used by the pre-pass renderer\r\n */\r\n public static TextureFormats = [\r\n {\r\n purpose: Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Irradiance\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_POSITION_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Position\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_VELOCITY_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Velocity\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Reflectivity\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_COLOR_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Color\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_DEPTH_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n format: Constants.TEXTUREFORMAT_R,\r\n name: \"prePass_Depth\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_NORMAL_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Normal\",\r\n },\r\n {\r\n purpose: Constants.PREPASS_ALBEDO_SQRT_TEXTURE_TYPE,\r\n type: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n name: \"prePass_Albedo\",\r\n },\r\n ];\r\n\r\n private _isDirty: boolean = true;\r\n\r\n /**\r\n * The render target where the scene is directly rendered\r\n */\r\n public defaultRT: PrePassRenderTarget;\r\n\r\n /**\r\n * Configuration for prepass effects\r\n */\r\n private _effectConfigurations: PrePassEffectConfiguration[] = [];\r\n\r\n /**\r\n * @returns the prepass render target for the rendering pass.\r\n * If we are currently rendering a render target, it returns the PrePassRenderTarget\r\n * associated with that render target. Otherwise, it returns the scene default PrePassRenderTarget\r\n */\r\n public getRenderTarget(): PrePassRenderTarget {\r\n return this._currentTarget;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Managed by the scene component\r\n * @param prePassRenderTarget\r\n */\r\n public _setRenderTarget(prePassRenderTarget: Nullable): void {\r\n if (prePassRenderTarget) {\r\n this._currentTarget = prePassRenderTarget;\r\n } else {\r\n this._currentTarget = this.defaultRT;\r\n this._engine.currentRenderPassId = this._scene.activeCamera?.renderPassId ?? this._currentTarget.renderPassId;\r\n }\r\n }\r\n\r\n /**\r\n * Returns true if the currently rendered prePassRenderTarget is the one\r\n * associated with the scene.\r\n */\r\n public get currentRTisSceneRT(): boolean {\r\n return this._currentTarget === this.defaultRT;\r\n }\r\n\r\n private _geometryBuffer: Nullable;\r\n\r\n /**\r\n * Prevents the PrePassRenderer from using the GeometryBufferRenderer as a fallback\r\n */\r\n public doNotUseGeometryRendererFallback = true;\r\n\r\n private _refreshGeometryBufferRendererLink() {\r\n if (!this.doNotUseGeometryRendererFallback) {\r\n this._geometryBuffer = this._scene.enableGeometryBufferRenderer();\r\n\r\n if (!this._geometryBuffer) {\r\n // Not supported\r\n this.doNotUseGeometryRendererFallback = true;\r\n return;\r\n }\r\n\r\n this._geometryBuffer._linkPrePassRenderer(this);\r\n } else {\r\n if (this._geometryBuffer) {\r\n this._geometryBuffer._unlinkPrePassRenderer();\r\n }\r\n this._geometryBuffer = null;\r\n this._scene.disableGeometryBufferRenderer();\r\n }\r\n }\r\n\r\n private _currentTarget: PrePassRenderTarget;\r\n\r\n /**\r\n * All the render targets generated by prepass\r\n */\r\n public renderTargets: PrePassRenderTarget[] = [];\r\n\r\n private readonly _clearColor = new Color4(0, 0, 0, 0);\r\n private readonly _clearDepthColor = new Color4(1e8, 0, 0, 1); // \"infinity\" value - depth in the depth texture is view.z, not a 0..1 value!\r\n\r\n private _enabled: boolean = false;\r\n\r\n private _needsCompositionForThisPass = false;\r\n private _postProcessesSourceForThisPass: Nullable[];\r\n\r\n /**\r\n * Indicates if the prepass is enabled\r\n */\r\n public get enabled() {\r\n return this._enabled;\r\n }\r\n\r\n /**\r\n * Set to true to disable gamma transform in PrePass.\r\n * Can be useful in case you already proceed to gamma transform on a material level\r\n * and your post processes don't need to be in linear color space.\r\n */\r\n public disableGammaTransform = false;\r\n\r\n /**\r\n * Instantiates a prepass renderer\r\n * @param scene The scene\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n\r\n let type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (this._engine._caps.textureFloat && this._engine._caps.textureFloatLinearFiltering) {\r\n type = Constants.TEXTURETYPE_FLOAT;\r\n } else if (this._engine._caps.textureHalfFloat && this._engine._caps.textureHalfFloatLinearFiltering) {\r\n type = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n\r\n if (type !== Constants.TEXTURETYPE_FLOAT) {\r\n for (let i = 0; i < PrePassRenderer.TextureFormats.length; ++i) {\r\n if (PrePassRenderer.TextureFormats[i].type === Constants.TEXTURETYPE_FLOAT) {\r\n PrePassRenderer.TextureFormats[Constants.PREPASS_DEPTH_TEXTURE_TYPE].type = type;\r\n }\r\n }\r\n }\r\n\r\n PrePassRenderer._SceneComponentInitialization(this._scene);\r\n this.defaultRT = this._createRenderTarget(\"sceneprePassRT\", null);\r\n this._currentTarget = this.defaultRT;\r\n }\r\n\r\n /**\r\n * Creates a new PrePassRenderTarget\r\n * This should be the only way to instantiate a `PrePassRenderTarget`\r\n * @param name Name of the `PrePassRenderTarget`\r\n * @param renderTargetTexture RenderTarget the `PrePassRenderTarget` will be attached to.\r\n * Can be `null` if the created `PrePassRenderTarget` is attached to the scene (default framebuffer).\r\n * @internal\r\n */\r\n public _createRenderTarget(name: string, renderTargetTexture: Nullable): PrePassRenderTarget {\r\n const rt = new PrePassRenderTarget(name, renderTargetTexture, { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, 0, this._scene, {\r\n generateMipMaps: false,\r\n generateStencilBuffer: this._engine.isStencilEnable,\r\n defaultType: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n types: [],\r\n drawOnlyOnFirstAttachmentByDefault: true,\r\n });\r\n\r\n this.renderTargets.push(rt);\r\n\r\n if (this._enabled) {\r\n // The pre-pass renderer is already enabled, so make sure we create the render target with the correct number of textures\r\n this._update();\r\n }\r\n\r\n return rt;\r\n }\r\n\r\n /**\r\n * Indicates if rendering a prepass is supported\r\n */\r\n public get isSupported() {\r\n return this._scene.getEngine().getCaps().drawBuffersExtension;\r\n }\r\n\r\n /**\r\n * Sets the proper output textures to draw in the engine.\r\n * @param effect The effect that is drawn. It can be or not be compatible with drawing to several output textures.\r\n * @param subMesh Submesh on which the effect is applied\r\n */\r\n public bindAttachmentsForEffect(effect: Effect, subMesh: SubMesh) {\r\n const material = subMesh.getMaterial();\r\n const isPrePassCapable = material && material.isPrePassCapable;\r\n const excluded = material && this.excludedMaterials.indexOf(material) !== -1;\r\n\r\n if (this.enabled && this._currentTarget.enabled) {\r\n if (effect._multiTarget && isPrePassCapable && !excluded) {\r\n this._engine.bindAttachments(this._multiRenderAttachments);\r\n } else {\r\n if (this._engine._currentRenderTarget) {\r\n this._engine.bindAttachments(this._defaultAttachments);\r\n } else {\r\n this._engine.restoreSingleAttachment();\r\n }\r\n\r\n if (this._geometryBuffer && this.currentRTisSceneRT && !excluded) {\r\n this._geometryBuffer.renderList!.push(subMesh.getRenderingMesh());\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _reinitializeAttachments() {\r\n const multiRenderLayout = [];\r\n const clearLayout = [false];\r\n const clearDepthLayout = [false];\r\n const defaultLayout = [true];\r\n\r\n for (let i = 0; i < this.mrtCount; i++) {\r\n multiRenderLayout.push(true);\r\n\r\n if (i > 0) {\r\n if (this._useSpecificClearForDepthTexture && this._mrtLayout[i] === Constants.PREPASS_DEPTH_TEXTURE_TYPE) {\r\n clearLayout.push(false);\r\n clearDepthLayout.push(true);\r\n } else {\r\n clearLayout.push(true);\r\n clearDepthLayout.push(false);\r\n }\r\n defaultLayout.push(false);\r\n }\r\n }\r\n\r\n this._multiRenderAttachments = this._engine.buildTextureLayout(multiRenderLayout);\r\n this._clearAttachments = this._engine.buildTextureLayout(clearLayout);\r\n this._clearDepthAttachments = this._engine.buildTextureLayout(clearDepthLayout);\r\n this._defaultAttachments = this._engine.buildTextureLayout(defaultLayout);\r\n }\r\n\r\n private _resetLayout() {\r\n for (let i = 0; i < PrePassRenderer.TextureFormats.length; i++) {\r\n this._textureIndices[PrePassRenderer.TextureFormats[i].purpose] = -1;\r\n }\r\n\r\n this._textureIndices[Constants.PREPASS_COLOR_TEXTURE_TYPE] = 0;\r\n this._mrtLayout = [Constants.PREPASS_COLOR_TEXTURE_TYPE];\r\n this._mrtTypes = [PrePassRenderer.TextureFormats[Constants.PREPASS_COLOR_TEXTURE_TYPE].type];\r\n this._mrtFormats = [PrePassRenderer.TextureFormats[Constants.PREPASS_COLOR_TEXTURE_TYPE].format];\r\n this._mrtNames = [PrePassRenderer.TextureFormats[Constants.PREPASS_COLOR_TEXTURE_TYPE].name];\r\n this.mrtCount = 1;\r\n }\r\n\r\n private _updateGeometryBufferLayout() {\r\n this._refreshGeometryBufferRendererLink();\r\n\r\n if (this._geometryBuffer) {\r\n this._geometryBuffer._resetLayout();\r\n\r\n const texturesActivated = [];\r\n\r\n for (let i = 0; i < this._mrtLayout.length; i++) {\r\n texturesActivated.push(false);\r\n }\r\n\r\n this._geometryBuffer._linkInternalTexture(this.defaultRT.getInternalTexture()!);\r\n\r\n const matches = [\r\n {\r\n prePassConstant: Constants.PREPASS_DEPTH_TEXTURE_TYPE,\r\n geometryBufferConstant: GeometryBufferRenderer.DEPTH_TEXTURE_TYPE,\r\n },\r\n {\r\n prePassConstant: Constants.PREPASS_NORMAL_TEXTURE_TYPE,\r\n geometryBufferConstant: GeometryBufferRenderer.NORMAL_TEXTURE_TYPE,\r\n },\r\n {\r\n prePassConstant: Constants.PREPASS_POSITION_TEXTURE_TYPE,\r\n geometryBufferConstant: GeometryBufferRenderer.POSITION_TEXTURE_TYPE,\r\n },\r\n {\r\n prePassConstant: Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE,\r\n geometryBufferConstant: GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE,\r\n },\r\n {\r\n prePassConstant: Constants.PREPASS_VELOCITY_TEXTURE_TYPE,\r\n geometryBufferConstant: GeometryBufferRenderer.VELOCITY_TEXTURE_TYPE,\r\n },\r\n ];\r\n\r\n // replace textures in the geometryBuffer RT\r\n for (let i = 0; i < matches.length; i++) {\r\n const index = this._mrtLayout.indexOf(matches[i].prePassConstant);\r\n if (index !== -1) {\r\n this._geometryBuffer._forceTextureType(matches[i].geometryBufferConstant, index);\r\n texturesActivated[index] = true;\r\n }\r\n }\r\n\r\n this._geometryBuffer._setAttachments(this._engine.buildTextureLayout(texturesActivated));\r\n }\r\n }\r\n\r\n /**\r\n * Restores attachments for single texture draw.\r\n */\r\n public restoreAttachments() {\r\n if (this.enabled && this._currentTarget.enabled && this._defaultAttachments) {\r\n if (this._engine._currentRenderTarget) {\r\n this._engine.bindAttachments(this._defaultAttachments);\r\n } else {\r\n this._engine.restoreSingleAttachment();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public _beforeDraw(camera?: Camera, faceIndex?: number, layer?: number) {\r\n // const previousEnabled = this._enabled && this._currentTarget.enabled;\r\n\r\n if (this._isDirty) {\r\n this._update();\r\n }\r\n\r\n if (!this._enabled || !this._currentTarget.enabled) {\r\n return;\r\n }\r\n\r\n if (this._geometryBuffer) {\r\n this._geometryBuffer.renderList = [];\r\n }\r\n\r\n this._setupOutputForThisPass(this._currentTarget, camera);\r\n }\r\n\r\n private _prepareFrame(prePassRenderTarget: PrePassRenderTarget, faceIndex?: number, layer?: number) {\r\n if (prePassRenderTarget.renderTargetTexture) {\r\n prePassRenderTarget.renderTargetTexture._prepareFrame(this._scene, faceIndex, layer, prePassRenderTarget.renderTargetTexture.useCameraPostProcesses);\r\n } else if (this._postProcessesSourceForThisPass.length) {\r\n this._scene.postProcessManager._prepareFrame();\r\n } else {\r\n this._engine.restoreDefaultFramebuffer();\r\n }\r\n }\r\n\r\n /**\r\n * Sets an intermediary texture between prepass and postprocesses. This texture\r\n * will be used as input for post processes\r\n * @param rt\r\n * @returns true if there are postprocesses that will use this texture,\r\n * false if there is no postprocesses - and the function has no effect\r\n */\r\n public setCustomOutput(rt: RenderTargetTexture) {\r\n const firstPP = this._postProcessesSourceForThisPass[0];\r\n if (!firstPP) {\r\n return false;\r\n }\r\n\r\n firstPP.inputTexture = rt.renderTarget!;\r\n\r\n return true;\r\n }\r\n\r\n private _renderPostProcesses(prePassRenderTarget: PrePassRenderTarget, faceIndex?: number) {\r\n const firstPP = this._postProcessesSourceForThisPass[0];\r\n const outputTexture = firstPP ? firstPP.inputTexture : prePassRenderTarget.renderTargetTexture ? prePassRenderTarget.renderTargetTexture.renderTarget : null;\r\n\r\n // Build post process chain for this prepass post draw\r\n let postProcessChain = this._currentTarget._beforeCompositionPostProcesses;\r\n\r\n if (this._needsCompositionForThisPass) {\r\n postProcessChain = postProcessChain.concat([this._currentTarget.imageProcessingPostProcess]);\r\n }\r\n\r\n // Activates and renders the chain\r\n if (postProcessChain.length) {\r\n this._scene.postProcessManager._prepareFrame(this._currentTarget.renderTarget?.texture, postProcessChain);\r\n this._scene.postProcessManager.directRender(postProcessChain, outputTexture, false, faceIndex);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _afterDraw(faceIndex?: number, layer?: number) {\r\n if (this._enabled && this._currentTarget.enabled) {\r\n this._prepareFrame(this._currentTarget, faceIndex, layer);\r\n this._renderPostProcesses(this._currentTarget, faceIndex);\r\n }\r\n }\r\n\r\n /**\r\n * Clears the current prepass render target (in the sense of settings pixels to the scene clear color value)\r\n * @internal\r\n */\r\n public _clear() {\r\n if (this._enabled && this._currentTarget.enabled) {\r\n this._bindFrameBuffer(this._currentTarget);\r\n\r\n // Clearing other attachment with 0 on all other attachments\r\n this._engine.bindAttachments(this._clearAttachments);\r\n this._engine.clear(this._clearColor, true, false, false);\r\n if (this._useSpecificClearForDepthTexture) {\r\n this._engine.bindAttachments(this._clearDepthAttachments);\r\n this._engine.clear(this._clearDepthColor, true, false, false);\r\n }\r\n // Regular clear color with the scene clear color of the 1st attachment\r\n this._engine.bindAttachments(this._defaultAttachments);\r\n }\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n private _bindFrameBuffer(prePassRenderTarget: PrePassRenderTarget) {\r\n if (this._enabled && this._currentTarget.enabled) {\r\n this._currentTarget._checkSize();\r\n const internalTexture = this._currentTarget.renderTarget;\r\n if (internalTexture) {\r\n this._engine.bindFramebuffer(internalTexture);\r\n }\r\n }\r\n }\r\n\r\n private _setEnabled(enabled: boolean) {\r\n this._enabled = enabled;\r\n }\r\n\r\n private _setRenderTargetEnabled(prePassRenderTarget: PrePassRenderTarget, enabled: boolean) {\r\n prePassRenderTarget.enabled = enabled;\r\n if (!enabled) {\r\n this._unlinkInternalTexture(prePassRenderTarget);\r\n }\r\n }\r\n\r\n /**\r\n * Adds an effect configuration to the prepass render target.\r\n * If an effect has already been added, it won't add it twice and will return the configuration\r\n * already present.\r\n * @param cfg the effect configuration\r\n * @returns the effect configuration now used by the prepass\r\n */\r\n public addEffectConfiguration(cfg: PrePassEffectConfiguration): PrePassEffectConfiguration {\r\n // Do not add twice\r\n for (let i = 0; i < this._effectConfigurations.length; i++) {\r\n if (this._effectConfigurations[i].name === cfg.name) {\r\n return this._effectConfigurations[i];\r\n }\r\n }\r\n\r\n this._effectConfigurations.push(cfg);\r\n return cfg;\r\n }\r\n\r\n private _enable() {\r\n const previousMrtCount = this.mrtCount;\r\n\r\n for (let i = 0; i < this._effectConfigurations.length; i++) {\r\n if (this._effectConfigurations[i].enabled) {\r\n this._enableTextures(this._effectConfigurations[i].texturesRequired);\r\n }\r\n }\r\n\r\n for (let i = 0; i < this.renderTargets.length; i++) {\r\n if (this.mrtCount !== previousMrtCount || this.renderTargets[i].count !== this.mrtCount) {\r\n this.renderTargets[i].updateCount(this.mrtCount, { types: this._mrtTypes, formats: this._mrtFormats }, this._mrtNames.concat(\"prePass_DepthBuffer\"));\r\n }\r\n\r\n this.renderTargets[i]._resetPostProcessChain();\r\n\r\n for (let j = 0; j < this._effectConfigurations.length; j++) {\r\n if (this._effectConfigurations[j].enabled) {\r\n // TODO : subsurface scattering has 1 scene-wide effect configuration\r\n // solution : do not stock postProcess on effectConfiguration, but in the prepassRenderTarget (hashmap configuration => postProcess)\r\n // And call createPostProcess whenever the post process does not exist in the RT\r\n if (!this._effectConfigurations[j].postProcess && this._effectConfigurations[j].createPostProcess) {\r\n this._effectConfigurations[j].createPostProcess!();\r\n }\r\n\r\n if (this._effectConfigurations[j].postProcess) {\r\n this.renderTargets[i]._beforeCompositionPostProcesses.push(this._effectConfigurations[j].postProcess!);\r\n }\r\n }\r\n }\r\n }\r\n\r\n this._reinitializeAttachments();\r\n this._setEnabled(true);\r\n this._updateGeometryBufferLayout();\r\n }\r\n\r\n private _disable() {\r\n this._setEnabled(false);\r\n\r\n for (let i = 0; i < this.renderTargets.length; i++) {\r\n this._setRenderTargetEnabled(this.renderTargets[i], false);\r\n }\r\n\r\n this._resetLayout();\r\n\r\n for (let i = 0; i < this._effectConfigurations.length; i++) {\r\n this._effectConfigurations[i].enabled = false;\r\n }\r\n }\r\n\r\n private _getPostProcessesSource(prePassRenderTarget: PrePassRenderTarget, camera?: Camera): Nullable[] {\r\n if (camera) {\r\n return camera._postProcesses;\r\n } else if (prePassRenderTarget.renderTargetTexture) {\r\n if (prePassRenderTarget.renderTargetTexture.useCameraPostProcesses) {\r\n const camera = prePassRenderTarget.renderTargetTexture.activeCamera ? prePassRenderTarget.renderTargetTexture.activeCamera : this._scene.activeCamera;\r\n return camera ? camera._postProcesses : [];\r\n } else if (prePassRenderTarget.renderTargetTexture.postProcesses) {\r\n return prePassRenderTarget.renderTargetTexture.postProcesses;\r\n } else {\r\n return [];\r\n }\r\n } else {\r\n return this._scene.activeCamera ? this._scene.activeCamera._postProcesses : [];\r\n }\r\n }\r\n\r\n private _setupOutputForThisPass(prePassRenderTarget: PrePassRenderTarget, camera?: Camera) {\r\n // Order is : draw ===> prePassRenderTarget._postProcesses ==> ipp ==> camera._postProcesses\r\n const secondaryCamera = camera && this._scene.activeCameras && !!this._scene.activeCameras.length && this._scene.activeCameras.indexOf(camera) !== 0;\r\n this._postProcessesSourceForThisPass = this._getPostProcessesSource(prePassRenderTarget, camera);\r\n this._postProcessesSourceForThisPass = this._postProcessesSourceForThisPass.filter((pp) => {\r\n return pp != null;\r\n });\r\n this._scene.autoClear = true;\r\n\r\n const cameraHasImageProcessing = this._hasImageProcessing(this._postProcessesSourceForThisPass);\r\n this._needsCompositionForThisPass = !cameraHasImageProcessing && !this.disableGammaTransform && this._needsImageProcessing() && !secondaryCamera;\r\n\r\n const firstCameraPP = this._getFirstPostProcess(this._postProcessesSourceForThisPass);\r\n const firstPrePassPP = prePassRenderTarget._beforeCompositionPostProcesses && prePassRenderTarget._beforeCompositionPostProcesses[0];\r\n let firstPP = null;\r\n\r\n // Setting the scene-wide post process configuration\r\n this._scene.imageProcessingConfiguration.applyByPostProcess = this._needsCompositionForThisPass || cameraHasImageProcessing;\r\n\r\n // Create composition effect if needed\r\n if (this._needsCompositionForThisPass && !prePassRenderTarget.imageProcessingPostProcess) {\r\n prePassRenderTarget._createCompositionEffect();\r\n }\r\n\r\n // Setting the prePassRenderTarget as input texture of the first PP\r\n if (firstPrePassPP) {\r\n firstPP = firstPrePassPP;\r\n } else if (this._needsCompositionForThisPass) {\r\n firstPP = prePassRenderTarget.imageProcessingPostProcess;\r\n } else if (firstCameraPP) {\r\n firstPP = firstCameraPP;\r\n }\r\n\r\n this._bindFrameBuffer(prePassRenderTarget);\r\n this._linkInternalTexture(prePassRenderTarget, firstPP);\r\n }\r\n\r\n private _linkInternalTexture(prePassRenderTarget: PrePassRenderTarget, postProcess: Nullable) {\r\n if (postProcess) {\r\n postProcess.autoClear = false;\r\n postProcess.inputTexture = prePassRenderTarget.renderTarget!;\r\n }\r\n\r\n if (prePassRenderTarget._outputPostProcess !== postProcess) {\r\n if (prePassRenderTarget._outputPostProcess) {\r\n this._unlinkInternalTexture(prePassRenderTarget);\r\n }\r\n prePassRenderTarget._outputPostProcess = postProcess;\r\n }\r\n\r\n if (prePassRenderTarget._internalTextureDirty) {\r\n this._updateGeometryBufferLayout();\r\n prePassRenderTarget._internalTextureDirty = false;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _unlinkInternalTexture(prePassRenderTarget: PrePassRenderTarget) {\r\n if (prePassRenderTarget._outputPostProcess) {\r\n prePassRenderTarget._outputPostProcess.autoClear = true;\r\n prePassRenderTarget._outputPostProcess.restoreDefaultInputTexture();\r\n prePassRenderTarget._outputPostProcess = null;\r\n }\r\n }\r\n\r\n private _needsImageProcessing(): boolean {\r\n for (let i = 0; i < this._effectConfigurations.length; i++) {\r\n if (this._effectConfigurations[i].enabled && this._effectConfigurations[i].needsImageProcessing) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _hasImageProcessing(postProcesses: Nullable[]): boolean {\r\n let isIPPAlreadyPresent = false;\r\n if (postProcesses) {\r\n for (let i = 0; i < postProcesses.length; i++) {\r\n if (postProcesses[i]?.getClassName() === \"ImageProcessingPostProcess\") {\r\n isIPPAlreadyPresent = true;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return isIPPAlreadyPresent;\r\n }\r\n\r\n /**\r\n * Internal, gets the first post proces.\r\n * @param postProcesses\r\n * @returns the first post process to be run on this camera.\r\n */\r\n private _getFirstPostProcess(postProcesses: Nullable[]): Nullable {\r\n for (let ppIndex = 0; ppIndex < postProcesses.length; ppIndex++) {\r\n if (postProcesses[ppIndex] !== null) {\r\n return postProcesses[ppIndex];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Marks the prepass renderer as dirty, triggering a check if the prepass is necessary for the next rendering.\r\n */\r\n public markAsDirty() {\r\n this._isDirty = true;\r\n }\r\n\r\n /**\r\n * Enables a texture on the MultiRenderTarget for prepass\r\n * @param types\r\n */\r\n private _enableTextures(types: number[]) {\r\n // For velocity : enable storage of previous matrices for instances\r\n this._scene.needsPreviousWorldMatrices = false;\r\n\r\n for (let i = 0; i < types.length; i++) {\r\n const type = types[i];\r\n\r\n if (this._textureIndices[type] === -1) {\r\n this._textureIndices[type] = this._mrtLayout.length;\r\n this._mrtLayout.push(type);\r\n\r\n this._mrtTypes.push(PrePassRenderer.TextureFormats[type].type);\r\n this._mrtFormats.push(PrePassRenderer.TextureFormats[type].format);\r\n this._mrtNames.push(PrePassRenderer.TextureFormats[type].name);\r\n this.mrtCount++;\r\n }\r\n\r\n if (type === Constants.PREPASS_VELOCITY_TEXTURE_TYPE) {\r\n this._scene.needsPreviousWorldMatrices = true;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Makes sure that the prepass renderer is up to date if it has been dirtified.\r\n */\r\n public update() {\r\n if (this._isDirty) {\r\n this._update();\r\n }\r\n }\r\n\r\n private _update() {\r\n this._disable();\r\n let enablePrePass = false;\r\n this._scene.imageProcessingConfiguration.applyByPostProcess = false;\r\n\r\n if (this._scene._depthPeelingRenderer && this._scene.useOrderIndependentTransparency) {\r\n this._scene._depthPeelingRenderer.setPrePassRenderer(this);\r\n enablePrePass = true;\r\n }\r\n\r\n for (let i = 0; i < this._scene.materials.length; i++) {\r\n if (this._scene.materials[i].setPrePassRenderer(this)) {\r\n enablePrePass = true;\r\n }\r\n }\r\n\r\n if (enablePrePass) {\r\n this._setRenderTargetEnabled(this.defaultRT, true);\r\n }\r\n\r\n let postProcesses;\r\n\r\n for (let i = 0; i < this.renderTargets.length; i++) {\r\n if (this.renderTargets[i].renderTargetTexture) {\r\n postProcesses = this._getPostProcessesSource(this.renderTargets[i]);\r\n } else {\r\n const camera = this._scene.activeCamera;\r\n if (!camera) {\r\n continue;\r\n }\r\n\r\n postProcesses = camera._postProcesses;\r\n }\r\n\r\n if (!postProcesses) {\r\n continue;\r\n }\r\n\r\n postProcesses = >postProcesses.filter((pp) => {\r\n return pp != null;\r\n });\r\n\r\n if (postProcesses) {\r\n for (let j = 0; j < postProcesses.length; j++) {\r\n if (postProcesses[j].setPrePassRenderer(this)) {\r\n this._setRenderTargetEnabled(this.renderTargets[i], true);\r\n enablePrePass = true;\r\n }\r\n }\r\n\r\n if (this._hasImageProcessing(postProcesses)) {\r\n this._scene.imageProcessingConfiguration.applyByPostProcess = true;\r\n }\r\n }\r\n }\r\n\r\n this._markAllMaterialsAsPrePassDirty();\r\n this._isDirty = false;\r\n\r\n if (enablePrePass) {\r\n this._enable();\r\n }\r\n }\r\n\r\n private _markAllMaterialsAsPrePassDirty() {\r\n const materials = this._scene.materials;\r\n\r\n for (let i = 0; i < materials.length; i++) {\r\n materials[i].markAsDirty(Material.PrePassDirtyFlag);\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the prepass renderer.\r\n */\r\n public dispose() {\r\n for (let i = this.renderTargets.length - 1; i >= 0; i--) {\r\n this.renderTargets[i].dispose();\r\n }\r\n\r\n for (let i = 0; i < this._effectConfigurations.length; i++) {\r\n if (this._effectConfigurations[i].dispose) {\r\n this._effectConfigurations[i].dispose!();\r\n }\r\n }\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { Scene } from \"../scene\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { PrePassRenderer } from \"./prePassRenderer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { _InstancesBatch } from \"../Meshes/mesh\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { PrePassRenderTarget } from \"../Materials/Textures/prePassRenderTarget\";\r\n\r\ndeclare module \"../abstractScene\" {\r\n export interface AbstractScene {\r\n /** @internal (Backing field) */\r\n _prePassRenderer: Nullable;\r\n\r\n /**\r\n * Gets or Sets the current prepass renderer associated to the scene.\r\n */\r\n prePassRenderer: Nullable;\r\n\r\n /**\r\n * Enables the prepass and associates it with the scene\r\n * @returns the PrePassRenderer\r\n */\r\n enablePrePassRenderer(): Nullable;\r\n\r\n /**\r\n * Disables the prepass associated with the scene\r\n */\r\n disablePrePassRenderer(): void;\r\n }\r\n}\r\n\r\ndeclare module \"../Materials/Textures/renderTargetTexture\" {\r\n export interface RenderTargetTexture {\r\n /**\r\n * Gets or sets a boolean indicating that the prepass renderer should not be used with this render target\r\n */\r\n noPrePassRenderer: boolean;\r\n /** @internal */\r\n _prePassRenderTarget: Nullable;\r\n }\r\n}\r\n\r\nObject.defineProperty(Scene.prototype, \"prePassRenderer\", {\r\n get: function (this: Scene) {\r\n return this._prePassRenderer;\r\n },\r\n set: function (this: Scene, value: Nullable) {\r\n if (value && value.isSupported) {\r\n this._prePassRenderer = value;\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\nScene.prototype.enablePrePassRenderer = function (): Nullable {\r\n if (this._prePassRenderer) {\r\n return this._prePassRenderer;\r\n }\r\n\r\n this._prePassRenderer = new PrePassRenderer(this);\r\n\r\n if (!this._prePassRenderer.isSupported) {\r\n this._prePassRenderer = null;\r\n Logger.Error(\"PrePassRenderer needs WebGL 2 support.\\n\" + \"Maybe you tried to use the following features that need the PrePassRenderer :\\n\" + \" + Subsurface Scattering\");\r\n }\r\n\r\n return this._prePassRenderer;\r\n};\r\n\r\nScene.prototype.disablePrePassRenderer = function (): void {\r\n if (!this._prePassRenderer) {\r\n return;\r\n }\r\n\r\n this._prePassRenderer.dispose();\r\n this._prePassRenderer = null;\r\n};\r\n\r\n/**\r\n * Defines the Geometry Buffer scene component responsible to manage a G-Buffer useful\r\n * in several rendering techniques.\r\n */\r\nexport class PrePassRendererSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_PREPASSRENDERER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._beforeCameraDrawStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERADRAW_PREPASS, this, this._beforeCameraDraw);\r\n this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_PREPASS, this, this._afterCameraDraw);\r\n this.scene._beforeRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERTARGETDRAW_PREPASS, this, this._beforeRenderTargetDraw);\r\n this.scene._afterRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_PREPASS, this, this._afterRenderTargetDraw);\r\n\r\n this.scene._beforeClearStage.registerStep(SceneComponentConstants.STEP_BEFORECLEAR_PREPASS, this, this._beforeClearStage);\r\n this.scene._beforeRenderTargetClearStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERTARGETCLEAR_PREPASS, this, this._beforeRenderTargetClearStage);\r\n\r\n this.scene._beforeRenderingMeshStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERINGMESH_PREPASS, this, this._beforeRenderingMeshStage);\r\n this.scene._afterRenderingMeshStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGMESH_PREPASS, this, this._afterRenderingMeshStage);\r\n }\r\n\r\n private _beforeRenderTargetDraw(renderTarget: RenderTargetTexture, faceIndex?: number, layer?: number) {\r\n if (this.scene.prePassRenderer && !renderTarget.noPrePassRenderer) {\r\n this.scene.prePassRenderer._setRenderTarget(renderTarget._prePassRenderTarget);\r\n this.scene.prePassRenderer._beforeDraw(undefined, faceIndex, layer);\r\n }\r\n }\r\n\r\n private _afterRenderTargetDraw(renderTarget: RenderTargetTexture, faceIndex?: number, layer?: number) {\r\n if (this.scene.prePassRenderer && !renderTarget.noPrePassRenderer) {\r\n this.scene.prePassRenderer._afterDraw(faceIndex, layer);\r\n }\r\n }\r\n\r\n private _beforeRenderTargetClearStage(renderTarget: RenderTargetTexture) {\r\n if (this.scene.prePassRenderer && !renderTarget.noPrePassRenderer) {\r\n if (!renderTarget._prePassRenderTarget) {\r\n renderTarget._prePassRenderTarget = this.scene.prePassRenderer._createRenderTarget(renderTarget.name + \"_prePassRTT\", renderTarget);\r\n }\r\n this.scene.prePassRenderer._setRenderTarget(renderTarget._prePassRenderTarget);\r\n this.scene.prePassRenderer._clear();\r\n }\r\n }\r\n\r\n private _beforeCameraDraw(camera: Camera) {\r\n if (this.scene.prePassRenderer) {\r\n this.scene.prePassRenderer._setRenderTarget(null);\r\n this.scene.prePassRenderer._beforeDraw(camera);\r\n }\r\n }\r\n\r\n private _afterCameraDraw() {\r\n if (this.scene.prePassRenderer) {\r\n this.scene.prePassRenderer._afterDraw();\r\n }\r\n }\r\n\r\n private _beforeClearStage() {\r\n if (this.scene.prePassRenderer) {\r\n this.scene.prePassRenderer._setRenderTarget(null);\r\n this.scene.prePassRenderer._clear();\r\n }\r\n }\r\n\r\n private _beforeRenderingMeshStage(mesh: AbstractMesh, subMesh: SubMesh, batch: _InstancesBatch, effect: Nullable) {\r\n if (!effect) {\r\n return;\r\n }\r\n\r\n // Render to MRT\r\n const scene = mesh.getScene();\r\n if (scene.prePassRenderer) {\r\n scene.prePassRenderer.bindAttachmentsForEffect(effect, subMesh);\r\n }\r\n }\r\n\r\n private _afterRenderingMeshStage(mesh: AbstractMesh) {\r\n const scene = mesh.getScene();\r\n\r\n if (scene.prePassRenderer) {\r\n scene.prePassRenderer.restoreAttachments();\r\n }\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Release textures first\r\n this.scene.disablePrePassRenderer();\r\n\r\n // Re-enable\r\n this.scene.enablePrePassRenderer();\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n this.scene.disablePrePassRenderer();\r\n }\r\n}\r\n\r\nPrePassRenderer._SceneComponentInitialization = (scene: Scene) => {\r\n // Register the G Buffer component to the scene.\r\n let component = scene._getComponent(SceneComponentConstants.NAME_PREPASSRENDERER) as PrePassRendererSceneComponent;\r\n if (!component) {\r\n component = new PrePassRendererSceneComponent(scene);\r\n scene._addComponent(component);\r\n }\r\n};\r\n","import { eParentChangeBehavior, KbViewerSettings } from '@models/interfaces/settings';\r\n\r\nconst settingDefaults: KbViewerSettings = {\r\n parentChangeBehavior: eParentChangeBehavior.PRESERVE_POSITION,\r\n};\r\ntype KbViewerSettingsOptions = keyof KbViewerSettings;\r\nconst settingsKey = 'KBVIEWER_SETTINGS';\r\n\r\nconst savedSettings = localStorage.getItem(settingsKey);\r\nconst settings: KbViewerSettings = savedSettings\r\n ? { ...settingDefaults, ...JSON.parse(savedSettings) }\r\n : { ...settingDefaults };\r\n\r\nexport class SettingsManagerService {\r\n static get(name: keyof KbViewerSettings): KbViewerSettings[T] {\r\n return settings[name];\r\n }\r\n\r\n static set(name: keyof KbViewerSettings, value: KbViewerSettings[T]): void {\r\n settings[name] = value;\r\n localStorage.setItem(settingsKey, JSON.stringify(settings));\r\n }\r\n}\r\n","import type { Nullable, FloatArray } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Vector3, Vector2, Vector4 } from \"../../Maths/math.vector\";\r\nimport { TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh, _CreationDataStorage } from \"../mesh\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a Ribbon\r\n * @param options an object used to set the following optional parameters for the ribbon, required but can be empty\r\n * * pathArray array of paths, each of which an array of successive Vector3\r\n * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false\r\n * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false\r\n * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false\r\n * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional\r\n * * colors a linear array, of length 4 * number of vertices, of custom color values, optional\r\n * @param options.pathArray\r\n * @param options.closeArray\r\n * @param options.closePath\r\n * @param options.offset\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.invertUV\r\n * @param options.uvs\r\n * @param options.colors\r\n * @returns the VertexData of the ribbon\r\n */\r\nexport function CreateRibbonVertexData(options: {\r\n pathArray: Vector3[][];\r\n closeArray?: boolean;\r\n closePath?: boolean;\r\n offset?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n invertUV?: boolean;\r\n uvs?: Vector2[];\r\n colors?: Color4[];\r\n}): VertexData {\r\n let pathArray: Vector3[][] = options.pathArray;\r\n const closeArray: boolean = options.closeArray || false;\r\n const closePath: boolean = options.closePath || false;\r\n const invertUV: boolean = options.invertUV || false;\r\n const defaultOffset: number = Math.floor(pathArray[0].length / 2);\r\n let offset: number = options.offset || defaultOffset;\r\n offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset\r\n const sideOrientation: number = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n const customUV = options.uvs;\r\n const customColors = options.colors;\r\n\r\n const positions: number[] = [];\r\n const indices: number[] = [];\r\n const normals: number[] = [];\r\n const uvs: number[] = [];\r\n\r\n const us: number[][] = []; // us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id\r\n const vs: number[][] = []; // vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutive paths from pathArray\r\n const uTotalDistance: number[] = []; // uTotalDistance[p] : total distance of path p\r\n const vTotalDistance: number[] = []; // vTotalDistance[i] : total distance between points i of first and last path from pathArray\r\n let minlg: number; // minimal length among all paths from pathArray\r\n const lg: number[] = []; // array of path lengths : nb of vertex per path\r\n const idx: number[] = []; // array of path indexes : index of each path (first vertex) in the total vertex number\r\n let p: number; // path iterator\r\n let i: number; // point iterator\r\n let j: number; // point iterator\r\n\r\n // if single path in pathArray\r\n if (pathArray.length < 2) {\r\n const ar1: Vector3[] = [];\r\n const ar2: Vector3[] = [];\r\n for (i = 0; i < pathArray[0].length - offset; i++) {\r\n ar1.push(pathArray[0][i]);\r\n ar2.push(pathArray[0][i + offset]);\r\n }\r\n pathArray = [ar1, ar2];\r\n }\r\n\r\n // positions and horizontal distances (u)\r\n let idc: number = 0;\r\n const closePathCorr: number = closePath ? 1 : 0; // the final index will be +1 if closePath\r\n let path: Vector3[];\r\n let l: number;\r\n minlg = pathArray[0].length;\r\n let vectlg: number;\r\n let dist: number;\r\n for (p = 0; p < pathArray.length; p++) {\r\n uTotalDistance[p] = 0;\r\n us[p] = [0];\r\n path = pathArray[p];\r\n l = path.length;\r\n minlg = minlg < l ? minlg : l;\r\n\r\n j = 0;\r\n while (j < l) {\r\n positions.push(path[j].x, path[j].y, path[j].z);\r\n if (j > 0) {\r\n vectlg = path[j].subtract(path[j - 1]).length();\r\n dist = vectlg + uTotalDistance[p];\r\n us[p].push(dist);\r\n uTotalDistance[p] = dist;\r\n }\r\n j++;\r\n }\r\n\r\n if (closePath) {\r\n // an extra hidden vertex is added in the \"positions\" array\r\n j--;\r\n positions.push(path[0].x, path[0].y, path[0].z);\r\n vectlg = path[j].subtract(path[0]).length();\r\n dist = vectlg + uTotalDistance[p];\r\n us[p].push(dist);\r\n uTotalDistance[p] = dist;\r\n }\r\n\r\n lg[p] = l + closePathCorr;\r\n idx[p] = idc;\r\n idc += l + closePathCorr;\r\n }\r\n\r\n // vertical distances (v)\r\n let path1: Vector3[];\r\n let path2: Vector3[];\r\n let vertex1: Nullable = null;\r\n let vertex2: Nullable = null;\r\n for (i = 0; i < minlg + closePathCorr; i++) {\r\n vTotalDistance[i] = 0;\r\n vs[i] = [0];\r\n for (p = 0; p < pathArray.length - 1; p++) {\r\n path1 = pathArray[p];\r\n path2 = pathArray[p + 1];\r\n if (i === minlg) {\r\n // closePath\r\n vertex1 = path1[0];\r\n vertex2 = path2[0];\r\n } else {\r\n vertex1 = path1[i];\r\n vertex2 = path2[i];\r\n }\r\n vectlg = vertex2.subtract(vertex1).length();\r\n dist = vectlg + vTotalDistance[i];\r\n vs[i].push(dist);\r\n vTotalDistance[i] = dist;\r\n }\r\n\r\n if (closeArray && vertex2 && vertex1) {\r\n path1 = pathArray[p];\r\n path2 = pathArray[0];\r\n if (i === minlg) {\r\n // closePath\r\n vertex2 = path2[0];\r\n }\r\n vectlg = vertex2.subtract(vertex1).length();\r\n dist = vectlg + vTotalDistance[i];\r\n vTotalDistance[i] = dist;\r\n }\r\n }\r\n\r\n // uvs\r\n let u: number;\r\n let v: number;\r\n if (customUV) {\r\n for (p = 0; p < customUV.length; p++) {\r\n uvs.push(customUV[p].x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - customUV[p].y : customUV[p].y);\r\n }\r\n } else {\r\n for (p = 0; p < pathArray.length; p++) {\r\n for (i = 0; i < minlg + closePathCorr; i++) {\r\n u = uTotalDistance[p] != 0.0 ? us[p][i] / uTotalDistance[p] : 0.0;\r\n v = vTotalDistance[i] != 0.0 ? vs[i][p] / vTotalDistance[i] : 0.0;\r\n if (invertUV) {\r\n uvs.push(v, u);\r\n } else {\r\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - v : v);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // indices\r\n p = 0; // path index\r\n let pi: number = 0; // positions array index\r\n let l1: number = lg[p] - 1; // path1 length\r\n let l2: number = lg[p + 1] - 1; // path2 length\r\n let min: number = l1 < l2 ? l1 : l2; // current path stop index\r\n let shft: number = idx[1] - idx[0]; // shift\r\n const path1nb: number = closeArray ? lg.length : lg.length - 1; // number of path1 to iterate\ton\r\n\r\n while (pi <= min && p < path1nb) {\r\n // stay under min and don't go over next to last path\r\n // draw two triangles between path1 (p1) and path2 (p2) : (p1.pi, p2.pi, p1.pi+1) and (p2.pi+1, p1.pi+1, p2.pi) clockwise\r\n\r\n indices.push(pi, pi + shft, pi + 1);\r\n indices.push(pi + shft + 1, pi + 1, pi + shft);\r\n pi += 1;\r\n if (pi === min) {\r\n // if end of one of two consecutive paths reached, go to next existing path\r\n p++;\r\n if (p === lg.length - 1) {\r\n // last path of pathArray reached <=> closeArray == true\r\n shft = idx[0] - idx[p];\r\n l1 = lg[p] - 1;\r\n l2 = lg[0] - 1;\r\n } else {\r\n shft = idx[p + 1] - idx[p];\r\n l1 = lg[p] - 1;\r\n l2 = lg[p + 1] - 1;\r\n }\r\n pi = idx[p];\r\n min = l1 < l2 ? l1 + pi : l2 + pi;\r\n }\r\n }\r\n\r\n // normals\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n if (closePath) {\r\n // update both the first and last vertex normals to their average value\r\n let indexFirst: number = 0;\r\n let indexLast: number = 0;\r\n for (p = 0; p < pathArray.length; p++) {\r\n indexFirst = idx[p] * 3;\r\n if (p + 1 < pathArray.length) {\r\n indexLast = (idx[p + 1] - 1) * 3;\r\n } else {\r\n indexLast = normals.length - 3;\r\n }\r\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\r\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\r\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\r\n normals[indexLast] = normals[indexFirst];\r\n normals[indexLast + 1] = normals[indexFirst + 1];\r\n normals[indexLast + 2] = normals[indexFirst + 2];\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Colors\r\n let colors: Nullable = null;\r\n if (customColors) {\r\n colors = new Float32Array(customColors.length * 4);\r\n for (let c = 0; c < customColors.length; c++) {\r\n colors[c * 4] = customColors[c].r;\r\n colors[c * 4 + 1] = customColors[c].g;\r\n colors[c * 4 + 2] = customColors[c].b;\r\n colors[c * 4 + 3] = customColors[c].a;\r\n }\r\n }\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n const positions32 = new Float32Array(positions);\r\n const normals32 = new Float32Array(normals);\r\n const uvs32 = new Float32Array(uvs);\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions32;\r\n vertexData.normals = normals32;\r\n vertexData.uvs = uvs32;\r\n if (colors) {\r\n vertexData.set(colors, VertexBuffer.ColorKind);\r\n }\r\n\r\n if (closePath) {\r\n (vertexData)._idx = idx;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a ribbon mesh. The ribbon is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters\r\n * * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry\r\n * * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array\r\n * * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array\r\n * * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path\r\n * * It's the offset to join the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11\r\n * * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#ribbon\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\r\n * * The parameter `uvs` is an optional flat array of `Vector2` to update/set each ribbon vertex with its own custom UV values instead of the computed ones\r\n * * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values\r\n * * Note that if you use the parameters `uvs` or `colors`, the passed arrays must be populated with the right number of elements, it is to say the number of ribbon vertices. Remember that if you set `closePath` to `true`, there's one extra vertex per path in the geometry\r\n * * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.pathArray\r\n * @param options.closeArray\r\n * @param options.closePath\r\n * @param options.offset\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.instance\r\n * @param options.invertUV\r\n * @param options.uvs\r\n * @param options.colors\r\n * @param scene defines the hosting scene\r\n * @returns the ribbon mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/ribbon_extra\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n */\r\nexport function CreateRibbon(\r\n name: string,\r\n options: {\r\n pathArray: Vector3[][];\r\n closeArray?: boolean;\r\n closePath?: boolean;\r\n offset?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n instance?: Mesh;\r\n invertUV?: boolean;\r\n uvs?: Vector2[];\r\n colors?: Color4[];\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const pathArray = options.pathArray;\r\n const closeArray = options.closeArray;\r\n const closePath = options.closePath;\r\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const instance = options.instance;\r\n const updatable = options.updatable;\r\n\r\n if (instance) {\r\n // existing ribbon instance update\r\n // positionFunction : ribbon case\r\n // only pathArray and sideOrientation parameters are taken into account for positions update\r\n const minimum = TmpVectors.Vector3[0].setAll(Number.MAX_VALUE);\r\n const maximum = TmpVectors.Vector3[1].setAll(-Number.MAX_VALUE);\r\n const positionFunction = (positions: FloatArray) => {\r\n let minlg = pathArray[0].length;\r\n const mesh = instance;\r\n let i = 0;\r\n const ns = mesh._originalBuilderSideOrientation === Mesh.DOUBLESIDE ? 2 : 1;\r\n for (let si = 1; si <= ns; ++si) {\r\n for (let p = 0; p < pathArray.length; ++p) {\r\n const path = pathArray[p];\r\n const l = path.length;\r\n minlg = minlg < l ? minlg : l;\r\n for (let j = 0; j < minlg; ++j) {\r\n const pathPoint = path[j];\r\n positions[i] = pathPoint.x;\r\n positions[i + 1] = pathPoint.y;\r\n positions[i + 2] = pathPoint.z;\r\n minimum.minimizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\r\n maximum.maximizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\r\n i += 3;\r\n }\r\n if (mesh._creationDataStorage && mesh._creationDataStorage.closePath) {\r\n const pathPoint = path[0];\r\n positions[i] = pathPoint.x;\r\n positions[i + 1] = pathPoint.y;\r\n positions[i + 2] = pathPoint.z;\r\n i += 3;\r\n }\r\n }\r\n }\r\n };\r\n const positions = instance.getVerticesData(VertexBuffer.PositionKind);\r\n positionFunction(positions);\r\n if (instance.hasBoundingInfo) {\r\n instance.getBoundingInfo().reConstruct(minimum, maximum, instance._worldMatrix);\r\n } else {\r\n instance.buildBoundingInfo(minimum, maximum, instance._worldMatrix);\r\n }\r\n instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\r\n if (options.colors) {\r\n const colors = instance.getVerticesData(VertexBuffer.ColorKind);\r\n for (let c = 0, colorIndex = 0; c < options.colors.length; c++, colorIndex += 4) {\r\n const color = options.colors[c];\r\n colors[colorIndex] = color.r;\r\n colors[colorIndex + 1] = color.g;\r\n colors[colorIndex + 2] = color.b;\r\n colors[colorIndex + 3] = color.a;\r\n }\r\n instance.updateVerticesData(VertexBuffer.ColorKind, colors, false, false);\r\n }\r\n if (options.uvs) {\r\n const uvs = instance.getVerticesData(VertexBuffer.UVKind);\r\n for (let i = 0; i < options.uvs.length; i++) {\r\n uvs[i * 2] = options.uvs[i].x;\r\n uvs[i * 2 + 1] = CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - options.uvs[i].y : options.uvs[i].y;\r\n }\r\n instance.updateVerticesData(VertexBuffer.UVKind, uvs, false, false);\r\n }\r\n if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {\r\n const indices = instance.getIndices();\r\n const normals = instance.getVerticesData(VertexBuffer.NormalKind);\r\n const params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;\r\n VertexData.ComputeNormals(positions, indices, normals, params);\r\n\r\n if (instance._creationDataStorage && instance._creationDataStorage.closePath) {\r\n let indexFirst: number = 0;\r\n let indexLast: number = 0;\r\n for (let p = 0; p < pathArray.length; p++) {\r\n indexFirst = instance._creationDataStorage!.idx[p] * 3;\r\n if (p + 1 < pathArray.length) {\r\n indexLast = (instance._creationDataStorage!.idx[p + 1] - 1) * 3;\r\n } else {\r\n indexLast = normals.length - 3;\r\n }\r\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\r\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\r\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\r\n normals[indexLast] = normals[indexFirst];\r\n normals[indexLast + 1] = normals[indexFirst + 1];\r\n normals[indexLast + 2] = normals[indexFirst + 2];\r\n }\r\n }\r\n if (!instance.areNormalsFrozen) {\r\n instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);\r\n }\r\n }\r\n\r\n return instance;\r\n } else {\r\n // new ribbon creation\r\n\r\n const ribbon = new Mesh(name, scene);\r\n ribbon._originalBuilderSideOrientation = sideOrientation;\r\n ribbon._creationDataStorage = new _CreationDataStorage();\r\n\r\n const vertexData = CreateRibbonVertexData(options);\r\n if (closePath) {\r\n ribbon._creationDataStorage.idx = (vertexData)._idx;\r\n }\r\n ribbon._creationDataStorage.closePath = closePath;\r\n ribbon._creationDataStorage.closeArray = closeArray;\r\n\r\n vertexData.applyToMesh(ribbon, updatable);\r\n\r\n return ribbon;\r\n }\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateRibbon directly\r\n */\r\nexport const RibbonBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateRibbon,\r\n};\r\n\r\nVertexData.CreateRibbon = CreateRibbonVertexData;\r\n\r\nMesh.CreateRibbon = (\r\n name: string,\r\n pathArray: Vector3[][],\r\n closeArray: boolean = false,\r\n closePath: boolean,\r\n offset: number,\r\n scene?: Scene,\r\n updatable: boolean = false,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n) => {\r\n return CreateRibbon(\r\n name,\r\n {\r\n pathArray: pathArray,\r\n closeArray: closeArray,\r\n closePath: closePath,\r\n offset: offset,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n instance: instance,\r\n },\r\n scene\r\n );\r\n};\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData of the Disc or regular Polygon\r\n * @param options an object used to set the following optional parameters for the disc, required but can be empty\r\n * * radius the radius of the disc, optional default 0.5\r\n * * tessellation the number of polygon sides, optional, default 64\r\n * * arc a number from 0 to 1, to create an unclosed polygon based on the fraction of the circumference given by the arc value, optional, default 1\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.tessellation\r\n * @param options.arc\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the box\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function CreateDiscVertexData(options: {\r\n radius?: number;\r\n tessellation?: number;\r\n arc?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const positions = new Array();\r\n const indices = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n\r\n const radius = options.radius || 0.5;\r\n const tessellation = options.tessellation || 64;\r\n const arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // positions and uvs\r\n positions.push(0, 0, 0); // disc center first\r\n uvs.push(0.5, 0.5);\r\n\r\n const theta = Math.PI * 2 * arc;\r\n const step = arc === 1 ? theta / tessellation : theta / (tessellation - 1);\r\n let a = 0;\r\n for (let t = 0; t < tessellation; t++) {\r\n const x = Math.cos(a);\r\n const y = Math.sin(a);\r\n const u = (x + 1) / 2;\r\n const v = (1 - y) / 2;\r\n positions.push(radius * x, radius * y, 0);\r\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n a += step;\r\n }\r\n if (arc === 1) {\r\n positions.push(positions[3], positions[4], positions[5]); // close the circle\r\n uvs.push(uvs[2], CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - uvs[3] : uvs[3]);\r\n }\r\n\r\n //indices\r\n const vertexNb = positions.length / 3;\r\n for (let i = 1; i < vertexNb - 1; i++) {\r\n indices.push(i + 1, 0, i);\r\n }\r\n\r\n // result\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a plane polygonal mesh. By default, this is a disc\r\n * * The parameter `radius` sets the radius size (float) of the polygon (default 0.5)\r\n * * The parameter `tessellation` sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc\r\n * * You can create an unclosed polygon with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference : 2 x PI x ratio\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.radius\r\n * @param options.tessellation\r\n * @param options.arc\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param scene defines the hosting scene\r\n * @returns the plane polygonal mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#disc-or-regular-polygon\r\n */\r\nexport function CreateDisc(\r\n name: string,\r\n options: { radius?: number; tessellation?: number; arc?: number; updatable?: boolean; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 } = {},\r\n scene: Nullable = null\r\n): Mesh {\r\n const disc = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n disc._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateDiscVertexData(options);\r\n\r\n vertexData.applyToMesh(disc, options.updatable);\r\n\r\n return disc;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated please use CreateDisc directly\r\n */\r\nexport const DiscBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateDisc,\r\n};\r\n\r\nVertexData.CreateDisc = CreateDiscVertexData;\r\n\r\nMesh.CreateDisc = (name: string, radius: number, tessellation: number, scene: Nullable = null, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n radius,\r\n tessellation,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateDisc(name, options, scene);\r\n};\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\n\r\n/**\r\n * Creates the VertexData for a tiled plane\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_plane\r\n * @param options an object used to set the following optional parameters for the tiled plane, required but can be empty\r\n * * pattern a limited pattern arrangement depending on the number\r\n * * size of the box\r\n * * width of the box, overwrites size\r\n * * height of the box, overwrites size\r\n * * tileSize sets the width, height and depth of the tile to the value of size, optional default 1\r\n * * tileWidth sets the width (x direction) of the tile, overwrites the width set by size, optional, default size\r\n * * tileHeight sets the height (y direction) of the tile, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\r\n * * alignVertical places whole tiles aligned to the center, left or right of a column\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.pattern\r\n * @param options.tileSize\r\n * @param options.tileWidth\r\n * @param options.tileHeight\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.alignHorizontal\r\n * @param options.alignVertical\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @returns the VertexData of the tiled plane\r\n */\r\nexport function CreateTiledPlaneVertexData(options: {\r\n pattern?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const flipTile = options.pattern || Mesh.NO_FLIP;\r\n const tileWidth = options.tileWidth || options.tileSize || 1;\r\n const tileHeight = options.tileHeight || options.tileSize || 1;\r\n const alignH = options.alignHorizontal || 0;\r\n const alignV = options.alignVertical || 0;\r\n\r\n const width = options.width || options.size || 1;\r\n const tilesX = Math.floor(width / tileWidth);\r\n let offsetX = width - tilesX * tileWidth;\r\n\r\n const height = options.height || options.size || 1;\r\n const tilesY = Math.floor(height / tileHeight);\r\n let offsetY = height - tilesY * tileHeight;\r\n\r\n const halfWidth = (tileWidth * tilesX) / 2;\r\n const halfHeight = (tileHeight * tilesY) / 2;\r\n\r\n let adjustX = 0;\r\n let adjustY = 0;\r\n let startX = 0;\r\n let startY = 0;\r\n let endX = 0;\r\n let endY = 0;\r\n\r\n //Part Tiles\r\n if (offsetX > 0 || offsetY > 0) {\r\n startX = -halfWidth;\r\n startY = -halfHeight;\r\n endX = halfWidth;\r\n endY = halfHeight;\r\n\r\n switch (alignH) {\r\n case Mesh.CENTER:\r\n offsetX /= 2;\r\n startX -= offsetX;\r\n endX += offsetX;\r\n break;\r\n case Mesh.LEFT:\r\n endX += offsetX;\r\n adjustX = -offsetX / 2;\r\n break;\r\n case Mesh.RIGHT:\r\n startX -= offsetX;\r\n adjustX = offsetX / 2;\r\n break;\r\n }\r\n\r\n switch (alignV) {\r\n case Mesh.CENTER:\r\n offsetY /= 2;\r\n startY -= offsetY;\r\n endY += offsetY;\r\n break;\r\n case Mesh.BOTTOM:\r\n endY += offsetY;\r\n adjustY = -offsetY / 2;\r\n break;\r\n case Mesh.TOP:\r\n startY -= offsetY;\r\n adjustY = offsetY / 2;\r\n break;\r\n }\r\n }\r\n\r\n const positions = [];\r\n const normals = [];\r\n const uvBase = [];\r\n uvBase[0] = [0, 0, 1, 0, 1, 1, 0, 1];\r\n uvBase[1] = [0, 0, 1, 0, 1, 1, 0, 1];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBase[1] = [1, 1, 0, 1, 0, 0, 1, 0];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBase[1] = [1, 0, 0, 0, 0, 1, 1, 1];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBase[1] = [0, 1, 1, 1, 1, 0, 0, 0];\r\n }\r\n let uvs: Array = [];\r\n const colors = [];\r\n const indices = [];\r\n let index = 0;\r\n for (let y = 0; y < tilesY; y++) {\r\n for (let x = 0; x < tilesX; x++) {\r\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\r\n uvs = uvs.concat(uvBase[((x % 2) + (y % 2)) % 2]);\r\n } else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvs = uvs.concat(uvBase[y % 2]);\r\n } else {\r\n uvs = uvs.concat(uvBase[0]);\r\n }\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n index += 4;\r\n }\r\n }\r\n\r\n //Part Tiles\r\n if (offsetX > 0 || offsetY > 0) {\r\n const partialBottomRow: boolean = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.TOP);\r\n const partialTopRow: boolean = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.BOTTOM);\r\n const partialLeftCol: boolean = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.RIGHT);\r\n const partialRightCol: boolean = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.LEFT);\r\n let uvPart: Array = [];\r\n let a, b, c, d: number;\r\n\r\n //corners\r\n if (partialBottomRow && partialLeftCol) {\r\n //bottom left corner\r\n positions.push(startX + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, startY + offsetY + adjustY, 0);\r\n positions.push(startX + adjustX, startY + offsetY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 1 - offsetX / tileWidth;\r\n b = 1 - offsetY / tileHeight;\r\n c = 1;\r\n d = 1;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_ROW) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_ROW) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs = uvs.concat(uvPart);\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n\r\n if (partialBottomRow && partialRightCol) {\r\n //bottom right corner\r\n positions.push(halfWidth + adjustX, startY + adjustY, 0);\r\n positions.push(endX + adjustX, startY + adjustY, 0);\r\n positions.push(endX + adjustX, startY + offsetY + adjustY, 0);\r\n positions.push(halfWidth + adjustX, startY + offsetY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 0;\r\n b = 1 - offsetY / tileHeight;\r\n c = offsetX / tileWidth;\r\n d = 1;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_ROW || (flipTile === Mesh.ROTATE_TILE && tilesX % 2 === 0)) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_ROW || (flipTile === Mesh.FLIP_TILE && tilesX % 2 === 0)) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW || (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesX % 2 === 0)) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs = uvs.concat(uvPart);\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n\r\n if (partialTopRow && partialLeftCol) {\r\n //top left corner\r\n positions.push(startX + adjustX, halfHeight + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, halfHeight + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, endY + adjustY, 0);\r\n positions.push(startX + adjustX, endY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 1 - offsetX / tileWidth;\r\n b = 0;\r\n c = 1;\r\n d = offsetY / tileHeight;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if ((flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.ROTATE_TILE && tilesY % 1 === 0)) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if ((flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_TILE && tilesY % 2 === 0)) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if ((flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesY % 2 === 0)) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs = uvs.concat(uvPart);\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n\r\n if (partialTopRow && partialRightCol) {\r\n //top right corner\r\n positions.push(halfWidth + adjustX, halfHeight + adjustY, 0);\r\n positions.push(endX + adjustX, halfHeight + adjustY, 0);\r\n positions.push(endX + adjustX, endY + adjustY, 0);\r\n positions.push(halfWidth + adjustX, endY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 0;\r\n b = 0;\r\n c = offsetX / tileWidth;\r\n d = offsetY / tileHeight;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if ((flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.ROTATE_TILE && (tilesY + tilesX) % 2 === 1)) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if ((flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_TILE && (tilesY + tilesX) % 2 === 1)) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if ((flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) || (flipTile === Mesh.FLIP_N_ROTATE_TILE && (tilesY + tilesX) % 2 === 1)) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs = uvs.concat(uvPart);\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n\r\n //part rows\r\n if (partialBottomRow) {\r\n const uvBaseBR = [];\r\n a = 0;\r\n b = 1 - offsetY / tileHeight;\r\n c = 1;\r\n d = 1;\r\n uvBaseBR[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseBR[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseBR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseBR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseBR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let x = 0; x < tilesX; x++) {\r\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + offsetY + adjustY, 0);\r\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + offsetY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\r\n uvs = uvs.concat(uvBaseBR[(x + 1) % 2]);\r\n } else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvs = uvs.concat(uvBaseBR[1]);\r\n } else {\r\n uvs = uvs.concat(uvBaseBR[0]);\r\n }\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n }\r\n\r\n if (partialTopRow) {\r\n const uvBaseTR = [];\r\n a = 0;\r\n b = 0;\r\n c = 1;\r\n d = offsetY / tileHeight;\r\n uvBaseTR[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseTR[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseTR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseTR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseTR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let x = 0; x < tilesX; x++) {\r\n positions.push(-halfWidth + x * tileWidth + adjustX, endY - offsetY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY - offsetY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY + adjustY, 0);\r\n positions.push(-halfWidth + x * tileWidth + adjustX, endY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\r\n uvs = uvs.concat(uvBaseTR[(x + tilesY) % 2]);\r\n } else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvs = uvs.concat(uvBaseTR[tilesY % 2]);\r\n } else {\r\n uvs = uvs.concat(uvBaseTR[0]);\r\n }\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n }\r\n\r\n if (partialLeftCol) {\r\n const uvBaseLC = [];\r\n a = 1 - offsetX / tileWidth;\r\n b = 0;\r\n c = 1;\r\n d = 1;\r\n uvBaseLC[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseLC[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseLC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseLC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseLC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let y = 0; y < tilesY; y++) {\r\n positions.push(startX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(startX + offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(startX + offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n positions.push(startX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\r\n uvs = uvs.concat(uvBaseLC[(y + 1) % 2]);\r\n } else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvs = uvs.concat(uvBaseLC[y % 2]);\r\n } else {\r\n uvs = uvs.concat(uvBaseLC[0]);\r\n }\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n }\r\n\r\n if (partialRightCol) {\r\n const uvBaseRC = [];\r\n a = 0;\r\n b = 0;\r\n c = offsetX / tileHeight;\r\n d = 1;\r\n uvBaseRC[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseRC[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseRC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseRC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseRC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let y = 0; y < tilesY; y++) {\r\n positions.push(endX - offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(endX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(endX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n positions.push(endX - offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_TILE) {\r\n uvs = uvs.concat(uvBaseRC[(y + tilesX) % 2]);\r\n } else if (flipTile === Mesh.FLIP_ROW || flipTile === Mesh.ROTATE_ROW || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvs = uvs.concat(uvBaseRC[y % 2]);\r\n } else {\r\n uvs = uvs.concat(uvBaseRC[0]);\r\n }\r\n colors.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);\r\n normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);\r\n }\r\n }\r\n }\r\n\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a tiled plane mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_plane\r\n * @param name defines the name of the mesh\r\n * @param options an object used to set the following optional parameters for the tiled plane, required but can be empty\r\n * * pattern a limited pattern arrangement depending on the number\r\n * * size of the box\r\n * * width of the box, overwrites size\r\n * * height of the box, overwrites size\r\n * * tileSize sets the width, height and depth of the tile to the value of size, optional default 1\r\n * * tileWidth sets the width (x direction) of the tile, overwrites the width set by size, optional, default size\r\n * * tileHeight sets the height (y direction) of the tile, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\r\n * * alignVertical places whole tiles aligned to the center, left or right of a column\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.pattern\r\n * @param options.tileSize\r\n * @param options.tileWidth\r\n * @param options.tileHeight\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.alignHorizontal\r\n * @param options.alignVertical\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the box mesh\r\n */\r\nexport function CreateTiledPlane(\r\n name: string,\r\n options: {\r\n pattern?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const plane = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n plane._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateTiledPlaneVertexData(options);\r\n\r\n vertexData.applyToMesh(plane, options.updatable);\r\n\r\n return plane;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTiledPlane instead\r\n */\r\nexport const TiledPlaneBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTiledPlane,\r\n};\r\n\r\nVertexData.CreateTiledPlane = CreateTiledPlaneVertexData;\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { CreateTiledPlaneVertexData } from \"./tiledPlaneBuilder\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a tiled box\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_box\r\n * @param options an object used to set the following optional parameters for the tiled box, required but can be empty\r\n * * pattern sets the rotation or reflection pattern for the tiles,\r\n * * size of the box\r\n * * width of the box, overwrites size\r\n * * height of the box, overwrites size\r\n * * depth of the box, overwrites size\r\n * * tileSize sets the size of a tile\r\n * * tileWidth sets the tile width and overwrites tileSize\r\n * * tileHeight sets the tile width and overwrites tileSize\r\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\r\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\r\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\r\n * * alignVertical places whole tiles aligned to the center, left or right of a column\r\n * @param options.pattern\r\n * @param options.size\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.tileSize\r\n * @param options.tileWidth\r\n * @param options.tileHeight\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.alignHorizontal\r\n * @param options.alignVertical\r\n * @param options.sideOrientation\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @returns the VertexData of the TiledBox\r\n */\r\nexport function CreateTiledBoxVertexData(options: {\r\n pattern?: number;\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n sideOrientation?: number;\r\n}): VertexData {\r\n const nbFaces = 6;\r\n\r\n const faceUV: Vector4[] = options.faceUV || new Array(6);\r\n const faceColors = options.faceColors;\r\n\r\n const flipTile = options.pattern || Mesh.NO_FLIP;\r\n\r\n const width = options.width || options.size || 1;\r\n const height = options.height || options.size || 1;\r\n const depth = options.depth || options.size || 1;\r\n const tileWidth = options.tileWidth || options.tileSize || 1;\r\n const tileHeight = options.tileHeight || options.tileSize || 1;\r\n const alignH = options.alignHorizontal || 0;\r\n const alignV = options.alignVertical || 0;\r\n\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < nbFaces; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n const halfWidth = width / 2;\r\n const halfHeight = height / 2;\r\n const halfDepth = depth / 2;\r\n\r\n const faceVertexData: Array = [];\r\n\r\n for (let f = 0; f < 2; f++) {\r\n //front and back\r\n faceVertexData[f] = CreateTiledPlaneVertexData({\r\n pattern: flipTile,\r\n tileWidth: tileWidth,\r\n tileHeight: tileHeight,\r\n width: width,\r\n height: height,\r\n alignVertical: alignV,\r\n alignHorizontal: alignH,\r\n sideOrientation: sideOrientation,\r\n });\r\n }\r\n\r\n for (let f = 2; f < 4; f++) {\r\n //sides\r\n faceVertexData[f] = CreateTiledPlaneVertexData({\r\n pattern: flipTile,\r\n tileWidth: tileWidth,\r\n tileHeight: tileHeight,\r\n width: depth,\r\n height: height,\r\n alignVertical: alignV,\r\n alignHorizontal: alignH,\r\n sideOrientation: sideOrientation,\r\n });\r\n }\r\n\r\n let baseAlignV = alignV;\r\n if (alignV === Mesh.BOTTOM) {\r\n baseAlignV = Mesh.TOP;\r\n } else if (alignV === Mesh.TOP) {\r\n baseAlignV = Mesh.BOTTOM;\r\n }\r\n\r\n for (let f = 4; f < 6; f++) {\r\n //top and bottom\r\n faceVertexData[f] = CreateTiledPlaneVertexData({\r\n pattern: flipTile,\r\n tileWidth: tileWidth,\r\n tileHeight: tileHeight,\r\n width: width,\r\n height: depth,\r\n alignVertical: baseAlignV,\r\n alignHorizontal: alignH,\r\n sideOrientation: sideOrientation,\r\n });\r\n }\r\n\r\n let positions: Array = [];\r\n let normals: Array = [];\r\n let uvs: Array = [];\r\n let indices: Array = [];\r\n const colors: Array = [];\r\n const facePositions: Array> = [];\r\n const faceNormals: Array> = [];\r\n\r\n const newFaceUV: Array> = [];\r\n let lu: number = 0;\r\n\r\n let li: number = 0;\r\n\r\n for (let f = 0; f < nbFaces; f++) {\r\n const len = faceVertexData[f].positions!.length;\r\n facePositions[f] = [];\r\n faceNormals[f] = [];\r\n for (let p = 0; p < len / 3; p++) {\r\n facePositions[f].push(new Vector3(faceVertexData[f].positions![3 * p], faceVertexData[f].positions![3 * p + 1], faceVertexData[f].positions![3 * p + 2]));\r\n faceNormals[f].push(new Vector3(faceVertexData[f].normals![3 * p], faceVertexData[f].normals![3 * p + 1], faceVertexData[f].normals![3 * p + 2]));\r\n }\r\n // uvs\r\n lu = faceVertexData[f].uvs!.length;\r\n newFaceUV[f] = [];\r\n for (let i = 0; i < lu; i += 2) {\r\n newFaceUV[f][i] = faceUV[f].x + (faceUV[f].z - faceUV[f].x) * faceVertexData[f].uvs![i];\r\n newFaceUV[f][i + 1] = faceUV[f].y + (faceUV[f].w - faceUV[f].y) * faceVertexData[f].uvs![i + 1];\r\n\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n newFaceUV[f][i + 1] = 1.0 - newFaceUV[f][i + 1];\r\n }\r\n }\r\n uvs = uvs.concat(newFaceUV[f]);\r\n\r\n indices = indices.concat(>faceVertexData[f].indices!.map((x: number) => x + li));\r\n li += facePositions[f].length;\r\n if (faceColors) {\r\n for (let c = 0; c < 4; c++) {\r\n colors.push(faceColors[f].r, faceColors[f].g, faceColors[f].b, faceColors[f].a);\r\n }\r\n }\r\n }\r\n\r\n const vec0 = new Vector3(0, 0, halfDepth);\r\n const mtrx0 = Matrix.RotationY(Math.PI);\r\n positions = facePositions[0]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx0).add(vec0))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), []);\r\n normals = faceNormals[0]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx0))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), []);\r\n positions = positions.concat(\r\n facePositions[1]\r\n .map((entry) => entry.subtract(vec0))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n normals = normals.concat(faceNormals[1].map((entry) => [entry.x, entry.y, entry.z]).reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), []));\r\n\r\n const vec2 = new Vector3(halfWidth, 0, 0);\r\n const mtrx2 = Matrix.RotationY(-Math.PI / 2);\r\n positions = positions.concat(\r\n facePositions[2]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx2).add(vec2))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n normals = normals.concat(\r\n faceNormals[2]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx2))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n const mtrx3 = Matrix.RotationY(Math.PI / 2);\r\n positions = positions.concat(\r\n facePositions[3]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx3).subtract(vec2))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n normals = normals.concat(\r\n faceNormals[3]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx3))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n\r\n const vec4 = new Vector3(0, halfHeight, 0);\r\n const mtrx4 = Matrix.RotationX(Math.PI / 2);\r\n positions = positions.concat(\r\n facePositions[4]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx4).add(vec4))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n normals = normals.concat(\r\n faceNormals[4]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx4))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n const mtrx5 = Matrix.RotationX(-Math.PI / 2);\r\n positions = positions.concat(\r\n facePositions[5]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx5).subtract(vec4))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n normals = normals.concat(\r\n faceNormals[5]\r\n .map((entry) => Vector3.TransformNormal(entry, mtrx5))\r\n .map((entry) => [entry.x, entry.y, entry.z])\r\n .reduce((accumulator: Array, currentValue) => accumulator.concat(currentValue), [])\r\n );\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a tiled box mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/tiled_box\r\n * @param name defines the name of the mesh\r\n * @param options an object used to set the following optional parameters for the tiled box, required but can be empty\r\n * * pattern sets the rotation or reflection pattern for the tiles,\r\n * * size of the box\r\n * * width of the box, overwrites size\r\n * * height of the box, overwrites size\r\n * * depth of the box, overwrites size\r\n * * tileSize sets the size of a tile\r\n * * tileWidth sets the tile width and overwrites tileSize\r\n * * tileHeight sets the tile width and overwrites tileSize\r\n * * faceUV an array of 6 Vector4 elements used to set different images to each box side\r\n * * faceColors an array of 6 Color3 elements used to set different colors to each box side\r\n * * alignHorizontal places whole tiles aligned to the center, left or right of a row\r\n * * alignVertical places whole tiles aligned to the center, left or right of a column\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param options.pattern\r\n * @param options.width\r\n * @param options.height\r\n * @param options.depth\r\n * @param options.tileSize\r\n * @param options.tileWidth\r\n * @param options.tileHeight\r\n * @param options.alignHorizontal\r\n * @param options.alignVertical\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.sideOrientation\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the box mesh\r\n */\r\nexport function CreateTiledBox(\r\n name: string,\r\n options: {\r\n pattern?: number;\r\n width?: number;\r\n height?: number;\r\n depth?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n sideOrientation?: number;\r\n updatable?: boolean;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const box = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n box._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateTiledBoxVertexData(options);\r\n\r\n vertexData.applyToMesh(box, options.updatable);\r\n\r\n return box;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTiledBox instead\r\n */\r\nexport const TiledBoxBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTiledBox,\r\n};\r\n\r\nVertexData.CreateTiledBox = CreateTiledBoxVertexData;\r\n","import type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n// based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473\r\n/**\r\n * Creates the VertexData for a TorusKnot\r\n * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty\r\n * * radius the radius of the torus knot, optional, default 2\r\n * * tube the thickness of the tube, optional, default 0.5\r\n * * radialSegments the number of sides on each tube segments, optional, default 32\r\n * * tubularSegments the number of tubes to decompose the knot into, optional, default 32\r\n * * p the number of windings around the z axis, optional, default 2\r\n * * q the number of windings around the x axis, optional, default 3\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.tube\r\n * @param options.radialSegments\r\n * @param options.tubularSegments\r\n * @param options.p\r\n * @param options.q\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the Torus Knot\r\n */\r\nexport function CreateTorusKnotVertexData(options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const indices = new Array();\r\n const positions = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n\r\n const radius = options.radius || 2;\r\n const tube = options.tube || 0.5;\r\n const radialSegments = options.radialSegments || 32;\r\n const tubularSegments = options.tubularSegments || 32;\r\n const p = options.p || 2;\r\n const q = options.q || 3;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // Helper\r\n const getPos = (angle: number) => {\r\n const cu = Math.cos(angle);\r\n const su = Math.sin(angle);\r\n const quOverP = (q / p) * angle;\r\n const cs = Math.cos(quOverP);\r\n\r\n const tx = radius * (2 + cs) * 0.5 * cu;\r\n const ty = radius * (2 + cs) * su * 0.5;\r\n const tz = radius * Math.sin(quOverP) * 0.5;\r\n\r\n return new Vector3(tx, ty, tz);\r\n };\r\n\r\n // Vertices\r\n let i: number;\r\n let j: number;\r\n for (i = 0; i <= radialSegments; i++) {\r\n const modI = i % radialSegments;\r\n const u = (modI / radialSegments) * 2 * p * Math.PI;\r\n const p1 = getPos(u);\r\n const p2 = getPos(u + 0.01);\r\n const tang = p2.subtract(p1);\r\n let n = p2.add(p1);\r\n\r\n const bitan = Vector3.Cross(tang, n);\r\n n = Vector3.Cross(bitan, tang);\r\n\r\n bitan.normalize();\r\n n.normalize();\r\n\r\n for (j = 0; j < tubularSegments; j++) {\r\n const modJ = j % tubularSegments;\r\n const v = (modJ / tubularSegments) * 2 * Math.PI;\r\n const cx = -tube * Math.cos(v);\r\n const cy = tube * Math.sin(v);\r\n\r\n positions.push(p1.x + cx * n.x + cy * bitan.x);\r\n positions.push(p1.y + cx * n.y + cy * bitan.y);\r\n positions.push(p1.z + cx * n.z + cy * bitan.z);\r\n\r\n uvs.push(i / radialSegments);\r\n uvs.push(CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - j / tubularSegments : j / tubularSegments);\r\n }\r\n }\r\n\r\n for (i = 0; i < radialSegments; i++) {\r\n for (j = 0; j < tubularSegments; j++) {\r\n const jNext = (j + 1) % tubularSegments;\r\n const a = i * tubularSegments + j;\r\n const b = (i + 1) * tubularSegments + j;\r\n const c = (i + 1) * tubularSegments + jNext;\r\n const d = i * tubularSegments + jNext;\r\n\r\n indices.push(d);\r\n indices.push(b);\r\n indices.push(a);\r\n indices.push(d);\r\n indices.push(c);\r\n indices.push(b);\r\n }\r\n }\r\n\r\n // Normals\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a torus knot mesh\r\n * * The parameter `radius` sets the global radius size (float) of the torus knot (default 2)\r\n * * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32)\r\n * * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32)\r\n * * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.radius\r\n * @param options.tube\r\n * @param options.radialSegments\r\n * @param options.tubularSegments\r\n * @param options.p\r\n * @param options.q\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param scene defines the hosting scene\r\n * @returns the torus knot mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus-knot\r\n */\r\nexport function CreateTorusKnot(\r\n name: string,\r\n options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n } = {},\r\n scene?: Scene\r\n): Mesh {\r\n const torusKnot = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n torusKnot._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateTorusKnotVertexData(options);\r\n\r\n vertexData.applyToMesh(torusKnot, options.updatable);\r\n\r\n return torusKnot;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTorusKnot instead\r\n */\r\nexport const TorusKnotBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTorusKnot,\r\n};\r\n\r\nVertexData.CreateTorusKnot = CreateTorusKnotVertexData;\r\n\r\nMesh.CreateTorusKnot = (\r\n name: string,\r\n radius: number,\r\n tube: number,\r\n radialSegments: number,\r\n tubularSegments: number,\r\n p: number,\r\n q: number,\r\n scene?: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number\r\n): Mesh => {\r\n const options = {\r\n radius,\r\n tube,\r\n radialSegments,\r\n tubularSegments,\r\n p,\r\n q,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateTorusKnot(name, options, scene);\r\n};\r\n","import { Logger } from \"../Misc/logger\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Path2 } from \"../Maths/math.path\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\ndeclare let earcut: any;\r\n/**\r\n * Vector2 wth index property\r\n */\r\nclass IndexedVector2 extends Vector2 {\r\n constructor(\r\n original: Vector2,\r\n /** Index of the vector2 */\r\n public index: number\r\n ) {\r\n super(original.x, original.y);\r\n }\r\n}\r\n\r\n/**\r\n * Defines points to create a polygon\r\n */\r\nclass PolygonPoints {\r\n elements = new Array();\r\n\r\n add(originalPoints: Array): Array {\r\n const result = new Array();\r\n originalPoints.forEach((point) => {\r\n const newPoint = new IndexedVector2(point, this.elements.length);\r\n result.push(newPoint);\r\n this.elements.push(newPoint);\r\n });\r\n\r\n return result;\r\n }\r\n\r\n computeBounds(): { min: Vector2; max: Vector2; width: number; height: number } {\r\n const lmin = new Vector2(this.elements[0].x, this.elements[0].y);\r\n const lmax = new Vector2(this.elements[0].x, this.elements[0].y);\r\n\r\n this.elements.forEach((point) => {\r\n // x\r\n if (point.x < lmin.x) {\r\n lmin.x = point.x;\r\n } else if (point.x > lmax.x) {\r\n lmax.x = point.x;\r\n }\r\n\r\n // y\r\n if (point.y < lmin.y) {\r\n lmin.y = point.y;\r\n } else if (point.y > lmax.y) {\r\n lmax.y = point.y;\r\n }\r\n });\r\n\r\n return {\r\n min: lmin,\r\n max: lmax,\r\n width: lmax.x - lmin.x,\r\n height: lmax.y - lmin.y,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Polygon\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#non-regular-polygon\r\n */\r\nexport class Polygon {\r\n /**\r\n * Creates a rectangle\r\n * @param xmin bottom X coord\r\n * @param ymin bottom Y coord\r\n * @param xmax top X coord\r\n * @param ymax top Y coord\r\n * @returns points that make the resulting rectangle\r\n */\r\n static Rectangle(xmin: number, ymin: number, xmax: number, ymax: number): Vector2[] {\r\n return [new Vector2(xmin, ymin), new Vector2(xmax, ymin), new Vector2(xmax, ymax), new Vector2(xmin, ymax)];\r\n }\r\n\r\n /**\r\n * Creates a circle\r\n * @param radius radius of circle\r\n * @param cx scale in x\r\n * @param cy scale in y\r\n * @param numberOfSides number of sides that make up the circle\r\n * @returns points that make the resulting circle\r\n */\r\n static Circle(radius: number, cx: number = 0, cy: number = 0, numberOfSides: number = 32): Vector2[] {\r\n const result = new Array();\r\n\r\n let angle = 0;\r\n const increment = (Math.PI * 2) / numberOfSides;\r\n\r\n for (let i = 0; i < numberOfSides; i++) {\r\n result.push(new Vector2(cx + Math.cos(angle) * radius, cy + Math.sin(angle) * radius));\r\n angle -= increment;\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a polygon from input string\r\n * @param input Input polygon data\r\n * @returns the parsed points\r\n */\r\n static Parse(input: string): Vector2[] {\r\n const floats = input\r\n .split(/[^-+eE.\\d]+/)\r\n .map(parseFloat)\r\n .filter((val) => !isNaN(val));\r\n let i: number;\r\n const result = [];\r\n for (i = 0; i < (floats.length & 0x7ffffffe); i += 2) {\r\n result.push(new Vector2(floats[i], floats[i + 1]));\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Starts building a polygon from x and y coordinates\r\n * @param x x coordinate\r\n * @param y y coordinate\r\n * @returns the started path2\r\n */\r\n static StartingAt(x: number, y: number): Path2 {\r\n return Path2.StartingAt(x, y);\r\n }\r\n}\r\n\r\n/**\r\n * Builds a polygon\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/polyMeshBuilder\r\n */\r\nexport class PolygonMeshBuilder {\r\n private _points = new PolygonPoints();\r\n private _outlinepoints = new PolygonPoints();\r\n private _holes = new Array();\r\n\r\n private _name: string;\r\n private _scene: Nullable;\r\n\r\n private _epoints: number[] = new Array();\r\n private _eholes: number[] = new Array();\r\n\r\n private _addToepoint(points: Vector2[]) {\r\n for (const p of points) {\r\n this._epoints.push(p.x, p.y);\r\n }\r\n }\r\n\r\n /**\r\n * Babylon reference to the earcut plugin.\r\n */\r\n public bjsEarcut: any;\r\n\r\n /**\r\n * Creates a PolygonMeshBuilder\r\n * @param name name of the builder\r\n * @param contours Path of the polygon\r\n * @param scene scene to add to when creating the mesh\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n */\r\n constructor(name: string, contours: Path2 | Vector2[] | any, scene?: Scene, earcutInjection = earcut) {\r\n this.bjsEarcut = earcutInjection;\r\n this._name = name;\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n\r\n let points: Vector2[];\r\n if (contours instanceof Path2) {\r\n points = (contours).getPoints();\r\n } else {\r\n points = contours;\r\n }\r\n\r\n this._addToepoint(points);\r\n\r\n this._points.add(points);\r\n this._outlinepoints.add(points);\r\n\r\n if (typeof this.bjsEarcut === \"undefined\") {\r\n Logger.Warn(\"Earcut was not found, the polygon will not be built.\");\r\n }\r\n }\r\n\r\n /**\r\n * Adds a hole within the polygon\r\n * @param hole Array of points defining the hole\r\n * @returns this\r\n */\r\n addHole(hole: Vector2[]): PolygonMeshBuilder {\r\n this._points.add(hole);\r\n const holepoints = new PolygonPoints();\r\n holepoints.add(hole);\r\n this._holes.push(holepoints);\r\n\r\n this._eholes.push(this._epoints.length / 2);\r\n this._addToepoint(hole);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates the polygon\r\n * @param updatable If the mesh should be updatable\r\n * @param depth The depth of the mesh created\r\n * @param smoothingThreshold Dot product threshold for smoothed normals\r\n * @returns the created mesh\r\n */\r\n build(updatable: boolean = false, depth: number = 0, smoothingThreshold: number = 2): Mesh {\r\n const result = new Mesh(this._name, this._scene);\r\n\r\n const vertexData = this.buildVertexData(depth, smoothingThreshold);\r\n\r\n result.setVerticesData(VertexBuffer.PositionKind, vertexData.positions, updatable);\r\n result.setVerticesData(VertexBuffer.NormalKind, vertexData.normals, updatable);\r\n result.setVerticesData(VertexBuffer.UVKind, vertexData.uvs, updatable);\r\n result.setIndices(vertexData.indices);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates the polygon\r\n * @param depth The depth of the mesh created\r\n * @param smoothingThreshold Dot product threshold for smoothed normals\r\n * @returns the created VertexData\r\n */\r\n buildVertexData(depth: number = 0, smoothingThreshold: number = 2): VertexData {\r\n const result = new VertexData();\r\n\r\n const normals = new Array();\r\n const positions = new Array();\r\n const uvs = new Array();\r\n\r\n const bounds = this._points.computeBounds();\r\n this._points.elements.forEach((p) => {\r\n normals.push(0, 1.0, 0);\r\n positions.push(p.x, 0, p.y);\r\n uvs.push((p.x - bounds.min.x) / bounds.width, (p.y - bounds.min.y) / bounds.height);\r\n });\r\n\r\n const indices = new Array();\r\n\r\n const res = this.bjsEarcut(this._epoints, this._eholes, 2);\r\n\r\n for (let i = 0; i < res.length; i++) {\r\n indices.push(res[i]);\r\n }\r\n\r\n if (depth > 0) {\r\n const positionscount = positions.length / 3; //get the current pointcount\r\n\r\n this._points.elements.forEach((p) => {\r\n //add the elements at the depth\r\n normals.push(0, -1.0, 0);\r\n positions.push(p.x, -depth, p.y);\r\n uvs.push(1 - (p.x - bounds.min.x) / bounds.width, 1 - (p.y - bounds.min.y) / bounds.height);\r\n });\r\n\r\n const totalCount = indices.length;\r\n for (let i = 0; i < totalCount; i += 3) {\r\n const i0 = indices[i + 0];\r\n const i1 = indices[i + 1];\r\n const i2 = indices[i + 2];\r\n\r\n indices.push(i2 + positionscount);\r\n indices.push(i1 + positionscount);\r\n indices.push(i0 + positionscount);\r\n }\r\n\r\n //Add the sides\r\n this._addSide(positions, normals, uvs, indices, bounds, this._outlinepoints, depth, false, smoothingThreshold);\r\n\r\n this._holes.forEach((hole) => {\r\n this._addSide(positions, normals, uvs, indices, bounds, hole, depth, true, smoothingThreshold);\r\n });\r\n }\r\n\r\n result.indices = indices;\r\n result.positions = positions;\r\n result.normals = normals;\r\n result.uvs = uvs;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Adds a side to the polygon\r\n * @param positions points that make the polygon\r\n * @param normals normals of the polygon\r\n * @param uvs uvs of the polygon\r\n * @param indices indices of the polygon\r\n * @param bounds bounds of the polygon\r\n * @param points points of the polygon\r\n * @param depth depth of the polygon\r\n * @param flip flip of the polygon\r\n * @param smoothingThreshold\r\n */\r\n private _addSide(positions: any[], normals: any[], uvs: any[], indices: any[], bounds: any, points: PolygonPoints, depth: number, flip: boolean, smoothingThreshold: number) {\r\n let startIndex: number = positions.length / 3;\r\n let ulength: number = 0;\r\n for (let i: number = 0; i < points.elements.length; i++) {\r\n const p: IndexedVector2 = points.elements[i];\r\n const p1: IndexedVector2 = points.elements[(i + 1) % points.elements.length];\r\n\r\n positions.push(p.x, 0, p.y);\r\n positions.push(p.x, -depth, p.y);\r\n positions.push(p1.x, 0, p1.y);\r\n positions.push(p1.x, -depth, p1.y);\r\n\r\n const p0: IndexedVector2 = points.elements[(i + points.elements.length - 1) % points.elements.length];\r\n const p2: IndexedVector2 = points.elements[(i + 2) % points.elements.length];\r\n\r\n let vc = new Vector3(-(p1.y - p.y), 0, p1.x - p.x);\r\n let vp = new Vector3(-(p.y - p0.y), 0, p.x - p0.x);\r\n let vn = new Vector3(-(p2.y - p1.y), 0, p2.x - p1.x);\r\n\r\n if (!flip) {\r\n vc = vc.scale(-1);\r\n vp = vp.scale(-1);\r\n vn = vn.scale(-1);\r\n }\r\n\r\n const vc_norm = vc.normalizeToNew();\r\n let vp_norm = vp.normalizeToNew();\r\n let vn_norm = vn.normalizeToNew();\r\n\r\n const dotp = Vector3.Dot(vp_norm, vc_norm);\r\n if (dotp > smoothingThreshold) {\r\n if (dotp < Epsilon - 1) {\r\n vp_norm = new Vector3(p.x, 0, p.y).subtract(new Vector3(p1.x, 0, p1.y)).normalize();\r\n } else {\r\n // cheap average weighed by side length\r\n vp_norm = vp.add(vc).normalize();\r\n }\r\n } else {\r\n vp_norm = vc_norm;\r\n }\r\n\r\n const dotn = Vector3.Dot(vn, vc);\r\n if (dotn > smoothingThreshold) {\r\n if (dotn < Epsilon - 1) {\r\n // back to back\r\n vn_norm = new Vector3(p1.x, 0, p1.y).subtract(new Vector3(p.x, 0, p.y)).normalize();\r\n } else {\r\n // cheap average weighed by side length\r\n vn_norm = vn.add(vc).normalize();\r\n }\r\n } else {\r\n vn_norm = vc_norm;\r\n }\r\n\r\n uvs.push(ulength / bounds.width, 0);\r\n uvs.push(ulength / bounds.width, 1);\r\n ulength += vc.length();\r\n uvs.push(ulength / bounds.width, 0);\r\n uvs.push(ulength / bounds.width, 1);\r\n\r\n normals.push(vp_norm.x, vp_norm.y, vp_norm.z);\r\n normals.push(vp_norm.x, vp_norm.y, vp_norm.z);\r\n normals.push(vn_norm.x, vn_norm.y, vn_norm.z);\r\n normals.push(vn_norm.x, vn_norm.y, vn_norm.z);\r\n\r\n if (!flip) {\r\n indices.push(startIndex);\r\n indices.push(startIndex + 1);\r\n indices.push(startIndex + 2);\r\n\r\n indices.push(startIndex + 1);\r\n indices.push(startIndex + 3);\r\n indices.push(startIndex + 2);\r\n } else {\r\n indices.push(startIndex);\r\n indices.push(startIndex + 2);\r\n indices.push(startIndex + 1);\r\n\r\n indices.push(startIndex + 1);\r\n indices.push(startIndex + 2);\r\n indices.push(startIndex + 3);\r\n }\r\n startIndex += 4;\r\n }\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Vector2, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { PolygonMeshBuilder } from \"../polygonMesh\";\r\nimport type { FloatArray, IndicesArray, Nullable } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\ndeclare let earcut: any;\r\n\r\n/**\r\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\r\n * All parameters are provided by CreatePolygon as needed\r\n * @param polygon a mesh built from polygonTriangulation.build()\r\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param wrp a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\r\n * @returns the VertexData of the Polygon\r\n */\r\nexport function CreatePolygonVertexData(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4, wrp?: boolean) {\r\n const faceUV: Vector4[] = fUV || new Array(3);\r\n const faceColors = fColors;\r\n const colors = [];\r\n const wrap: boolean = wrp || false;\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < 3; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n const positions = polygon.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = polygon.getVerticesData(VertexBuffer.NormalKind);\r\n const uvs = polygon.getVerticesData(VertexBuffer.UVKind);\r\n const indices = polygon.getIndices();\r\n const startIndex = positions.length / 9;\r\n let disp = 0;\r\n let distX = 0;\r\n let distZ = 0;\r\n let dist = 0;\r\n let totalLen = 0;\r\n const cumulate = [0];\r\n if (wrap) {\r\n for (let idx = startIndex; idx < positions.length / 3; idx += 4) {\r\n distX = positions[3 * (idx + 2)] - positions[3 * idx];\r\n distZ = positions[3 * (idx + 2) + 2] - positions[3 * idx + 2];\r\n dist = Math.sqrt(distX * distX + distZ * distZ);\r\n totalLen += dist;\r\n cumulate.push(totalLen);\r\n }\r\n }\r\n // set face colours and textures\r\n let idx: number = 0;\r\n let face: number = 0;\r\n for (let index = 0; index < normals.length; index += 3) {\r\n //Edge Face no. 1\r\n if (Math.abs(normals[index + 1]) < 0.001) {\r\n face = 1;\r\n }\r\n //Top Face no. 0\r\n if (Math.abs(normals[index + 1] - 1) < 0.001) {\r\n face = 0;\r\n }\r\n //Bottom Face no. 2\r\n if (Math.abs(normals[index + 1] + 1) < 0.001) {\r\n face = 2;\r\n }\r\n idx = index / 3;\r\n if (face === 1) {\r\n disp = idx - startIndex;\r\n if (disp % 4 < 1.5) {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4)]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].x;\r\n }\r\n } else {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4) + 1]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].z;\r\n }\r\n }\r\n if (disp % 2 === 0) {\r\n uvs[2 * idx + 1] = CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[face].w : faceUV[face].w;\r\n } else {\r\n uvs[2 * idx + 1] = CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - faceUV[face].y : faceUV[face].y;\r\n }\r\n } else {\r\n uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;\r\n uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;\r\n\r\n if (CompatibilityOptions.UseOpenGLOrientationForUV) {\r\n uvs[2 * idx + 1] = 1.0 - uvs[2 * idx + 1];\r\n }\r\n }\r\n if (faceColors) {\r\n colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a polygon mesh\r\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh\r\n * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)\r\n * * Remember you can only change the shape positions, not their number when updating a polygon\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.shape\r\n * @param options.holes\r\n * @param options.depth\r\n * @param options.smoothingThreshold\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.wrap\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function CreatePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n smoothingThreshold?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const shape = options.shape;\r\n const holes = options.holes || [];\r\n const depth = options.depth || 0;\r\n const smoothingThreshold = options.smoothingThreshold || 2;\r\n const contours: Array = [];\r\n let hole: Array = [];\r\n\r\n for (let i = 0; i < shape.length; i++) {\r\n contours[i] = new Vector2(shape[i].x, shape[i].z);\r\n }\r\n const epsilon = 0.00000001;\r\n if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {\r\n contours.pop();\r\n }\r\n\r\n const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene!, earcutInjection);\r\n for (let hNb = 0; hNb < holes.length; hNb++) {\r\n hole = [];\r\n for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {\r\n hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));\r\n }\r\n polygonTriangulation.addHole(hole);\r\n }\r\n //updatability is set during applyToMesh; setting to true in triangulation build produces errors\r\n const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);\r\n polygon._originalBuilderSideOrientation = options.sideOrientation;\r\n const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(polygon, options.updatable);\r\n\r\n return polygon;\r\n}\r\n\r\n/**\r\n * Creates an extruded polygon mesh, with depth in the Y direction.\r\n * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.shape\r\n * @param options.holes\r\n * @param options.depth\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.wrap\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function ExtrudePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const PolygonBuilder = {\r\n ExtrudePolygon,\r\n CreatePolygon,\r\n};\r\n\r\nVertexData.CreatePolygon = CreatePolygonVertexData;\r\nMesh.CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number, earcutInjection = earcut): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n};\r\n\r\nMesh.ExtrudePolygon = (\r\n name: string,\r\n shape: Vector3[],\r\n depth: number,\r\n scene: Scene,\r\n holes?: Vector3[][],\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n earcutInjection = earcut\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n depth: depth,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return ExtrudePolygon(name, options, scene, earcutInjection);\r\n};\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors, Matrix } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { CreateRibbon } from \"./ribbonBuilder\";\r\nimport { Path3D } from \"../../Maths/math.path\";\r\n\r\n/**\r\n * Creates an extruded shape mesh. The extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.\r\n * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis.\r\n * * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.\r\n * * The parameter `rotation` (float, default 0 radians) is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve.\r\n * * The parameter `scale` (float, default 1) is the value to scale the shape.\r\n * * The parameter `closeShape` (boolean, default false) closes the shape when true, since v5.0.0.\r\n * * The parameter `closePath` (boolean, default false) closes the path when true and no caps, since v5.0.0.\r\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\r\n * * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#extruded-shape\r\n * * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * * The optional parameter `firstNormal` (Vector3) defines the direction of the first normal of the supplied path. Consider using this for any path that is straight, and particular for paths in the xy plane.\r\n * * The optional `adjustFrame` (boolean, default false) will cause the internally generated Path3D tangents, normals, and binormals to be adjusted so that a) they are always well-defined, and b) they do not reverse from one path point to the next. This prevents the extruded shape from being flipped and/or rotated with resulting mesh self-intersections. This is primarily useful for straight paths that can reverse direction.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.shape\r\n * @param options.path\r\n * @param options.scale\r\n * @param options.rotation\r\n * @param options.closeShape\r\n * @param options.closePath\r\n * @param options.cap\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.instance\r\n * @param options.invertUV\r\n * @param options.firstNormal\r\n * @param options.adjustFrame\r\n * @param scene defines the hosting scene\r\n * @returns the extruded shape mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\r\n */\r\nexport function ExtrudeShape(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n path: Vector3[];\r\n scale?: number;\r\n rotation?: number;\r\n closeShape?: boolean;\r\n closePath?: boolean;\r\n cap?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n instance?: Mesh;\r\n invertUV?: boolean;\r\n firstNormal?: Vector3;\r\n adjustFrame?: boolean;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const path = options.path;\r\n const shape = options.shape;\r\n const scale = options.scale || 1;\r\n const rotation = options.rotation || 0;\r\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.NO_CAP;\r\n const updatable = options.updatable;\r\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const instance = options.instance || null;\r\n const invertUV = options.invertUV || false;\r\n const closeShape = options.closeShape || false;\r\n const closePath = options.closePath || false;\r\n\r\n return _ExtrudeShapeGeneric(\r\n name,\r\n shape,\r\n path,\r\n scale,\r\n rotation,\r\n null,\r\n null,\r\n closePath,\r\n closeShape,\r\n cap,\r\n false,\r\n scene,\r\n updatable ? true : false,\r\n sideOrientation,\r\n instance,\r\n invertUV,\r\n options.frontUVs || null,\r\n options.backUVs || null,\r\n options.firstNormal || null,\r\n options.adjustFrame ? true : false\r\n );\r\n}\r\n\r\n/**\r\n * Creates an custom extruded shape mesh.\r\n * The custom extrusion is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters.\r\n * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be extruded along the Z axis.\r\n * * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.\r\n * * The parameter `rotationFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path and the distance of this point from the beginning of the path\r\n * * It must returns a float value that will be the rotation in radians applied to the shape on each path point.\r\n * * The parameter `scaleFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path and the distance of this point from the beginning of the path\r\n * * It must returns a float value that will be the scale value applied to the shape on each path point\r\n * * The parameter `closeShape` (boolean, default false) closes the shape when true, since v5.0.0.\r\n * * The parameter `closePath` (boolean, default false) closes the path when true and no caps, since v5.0.0.\r\n * * The parameter `ribbonClosePath` (boolean, default false) forces the extrusion underlying ribbon to close all the paths in its `pathArray` - depreciated in favor of closeShape\r\n * * The parameter `ribbonCloseArray` (boolean, default false) forces the extrusion underlying ribbon to close its `pathArray` - depreciated in favor of closePath\r\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\r\n * * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#extruded-shape\r\n * * Remember you can only change the shape or path point positions, not their number when updating an extruded shape\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * * The optional parameter `firstNormal` (Vector3) defines the direction of the first normal of the supplied path. It should be supplied when the path is in the xy plane, and particularly if these sections are straight, because the underlying Path3D object will pick a normal in the xy plane that causes the extrusion to be collapsed into the plane. This should be used for any path that is straight.\r\n * * The optional `adjustFrame` (boolean, default false) will cause the internally generated Path3D tangents, normals, and binormals to be adjusted so that a) they are always well-defined, and b) they do not reverse from one path point to the next. This prevents the extruded shape from being flipped and/or rotated with resulting mesh self-intersections. This is primarily useful for straight paths that can reverse direction.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.shape\r\n * @param options.path\r\n * @param options.scaleFunction\r\n * @param options.rotationFunction\r\n * @param options.ribbonCloseArray\r\n * @param options.ribbonClosePath\r\n * @param options.closeShape\r\n * @param options.closePath\r\n * @param options.cap\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.instance\r\n * @param options.invertUV\r\n * @param options.firstNormal\r\n * @param options.adjustFrame\r\n * @param scene defines the hosting scene\r\n * @returns the custom extruded shape mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#custom-extruded-shapes\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#extruded-shapes\r\n */\r\nexport function ExtrudeShapeCustom(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n path: Vector3[];\r\n scaleFunction?: Nullable<{ (i: number, distance: number): number }>;\r\n rotationFunction?: Nullable<{ (i: number, distance: number): number }>;\r\n ribbonCloseArray?: boolean;\r\n ribbonClosePath?: boolean;\r\n closeShape?: boolean;\r\n closePath?: boolean;\r\n cap?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n instance?: Mesh;\r\n invertUV?: boolean;\r\n firstNormal?: Vector3;\r\n adjustFrame?: boolean;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const path = options.path;\r\n const shape = options.shape;\r\n const scaleFunction =\r\n options.scaleFunction ||\r\n (() => {\r\n return 1;\r\n });\r\n const rotationFunction =\r\n options.rotationFunction ||\r\n (() => {\r\n return 0;\r\n });\r\n const ribbonCloseArray = options.closePath || options.ribbonCloseArray || false;\r\n const ribbonClosePath = options.closeShape || options.ribbonClosePath || false;\r\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.NO_CAP;\r\n const updatable = options.updatable;\r\n const firstNormal = options.firstNormal || null;\r\n const adjustFrame = options.adjustFrame || false;\r\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const instance = options.instance;\r\n const invertUV = options.invertUV || false;\r\n return _ExtrudeShapeGeneric(\r\n name,\r\n shape,\r\n path,\r\n null,\r\n null,\r\n scaleFunction,\r\n rotationFunction,\r\n ribbonCloseArray,\r\n ribbonClosePath,\r\n cap,\r\n true,\r\n scene,\r\n updatable ? true : false,\r\n sideOrientation,\r\n instance || null,\r\n invertUV,\r\n options.frontUVs || null,\r\n options.backUVs || null,\r\n firstNormal,\r\n adjustFrame\r\n );\r\n}\r\n\r\nfunction _ExtrudeShapeGeneric(\r\n name: string,\r\n shape: Vector3[],\r\n curve: Vector3[],\r\n scale: Nullable,\r\n rotation: Nullable,\r\n scaleFunction: Nullable<{ (i: number, distance: number): number }>,\r\n rotateFunction: Nullable<{ (i: number, distance: number): number }>,\r\n rbCA: boolean,\r\n rbCP: boolean,\r\n cap: number,\r\n custom: boolean,\r\n scene: Nullable,\r\n updtbl: boolean,\r\n side: number,\r\n instance: Nullable,\r\n invertUV: boolean,\r\n frontUVs: Nullable,\r\n backUVs: Nullable,\r\n firstNormal: Nullable,\r\n adjustFrame: boolean\r\n): Mesh {\r\n // extrusion geometry\r\n const extrusionPathArray = (\r\n shape: Vector3[],\r\n curve: Vector3[],\r\n path3D: Path3D,\r\n shapePaths: Vector3[][],\r\n scale: Nullable,\r\n rotation: Nullable,\r\n scaleFunction: Nullable<{ (i: number, distance: number): number }>,\r\n rotateFunction: Nullable<{ (i: number, distance: number): number }>,\r\n cap: number,\r\n custom: boolean,\r\n adjustFrame: boolean\r\n ) => {\r\n const tangents = path3D.getTangents();\r\n const normals = path3D.getNormals();\r\n const binormals = path3D.getBinormals();\r\n const distances = path3D.getDistances();\r\n if (adjustFrame) {\r\n /* fix tangents,normals, binormals */\r\n for (let i = 0; i < tangents.length; i++) {\r\n if (tangents[i].x == 0 && tangents[i].y == 0 && tangents[i].z == 0) {\r\n tangents[i].copyFrom(tangents[i - 1]);\r\n }\r\n if (normals[i].x == 0 && normals[i].y == 0 && normals[i].z == 0) {\r\n normals[i].copyFrom(normals[i - 1]);\r\n }\r\n if (binormals[i].x == 0 && binormals[i].y == 0 && binormals[i].z == 0) {\r\n binormals[i].copyFrom(binormals[i - 1]);\r\n }\r\n if (i > 0) {\r\n let v = tangents[i - 1];\r\n if (Vector3.Dot(v, tangents[i]) < 0) {\r\n tangents[i].scaleInPlace(-1);\r\n }\r\n v = normals[i - 1];\r\n if (Vector3.Dot(v, normals[i]) < 0) {\r\n normals[i].scaleInPlace(-1);\r\n }\r\n v = binormals[i - 1];\r\n if (Vector3.Dot(v, binormals[i]) < 0) {\r\n binormals[i].scaleInPlace(-1);\r\n }\r\n }\r\n }\r\n }\r\n let angle = 0;\r\n const returnScale = () => {\r\n return scale !== null ? scale : 1;\r\n };\r\n const returnRotation = () => {\r\n return rotation !== null ? rotation : 0;\r\n };\r\n const rotate: { (i: number, distance: number): number } = custom && rotateFunction ? rotateFunction : returnRotation;\r\n const scl: { (i: number, distance: number): number } = custom && scaleFunction ? scaleFunction : returnScale;\r\n let index = cap === Mesh.NO_CAP || cap === Mesh.CAP_END ? 0 : 2;\r\n const rotationMatrix: Matrix = TmpVectors.Matrix[0];\r\n\r\n for (let i = 0; i < curve.length; i++) {\r\n const shapePath = new Array();\r\n const angleStep = rotate(i, distances[i]);\r\n const scaleRatio = scl(i, distances[i]);\r\n Matrix.RotationAxisToRef(tangents[i], angle, rotationMatrix);\r\n for (let p = 0; p < shape.length; p++) {\r\n const planed = tangents[i].scale(shape[p].z).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y));\r\n const rotated = Vector3.Zero();\r\n Vector3.TransformCoordinatesToRef(planed, rotationMatrix, rotated);\r\n rotated.scaleInPlace(scaleRatio).addInPlace(curve[i]);\r\n shapePath[p] = rotated;\r\n }\r\n shapePaths[index] = shapePath;\r\n angle += angleStep;\r\n index++;\r\n }\r\n // cap\r\n const capPath = (shapePath: Vector3[]) => {\r\n const pointCap = Array();\r\n const barycenter = Vector3.Zero();\r\n let i: number;\r\n for (i = 0; i < shapePath.length; i++) {\r\n barycenter.addInPlace(shapePath[i]);\r\n }\r\n barycenter.scaleInPlace(1.0 / shapePath.length);\r\n for (i = 0; i < shapePath.length; i++) {\r\n pointCap.push(barycenter);\r\n }\r\n return pointCap;\r\n };\r\n switch (cap) {\r\n case Mesh.NO_CAP:\r\n break;\r\n case Mesh.CAP_START:\r\n shapePaths[0] = capPath(shapePaths[2]);\r\n shapePaths[1] = shapePaths[2];\r\n break;\r\n case Mesh.CAP_END:\r\n shapePaths[index] = shapePaths[index - 1];\r\n shapePaths[index + 1] = capPath(shapePaths[index - 1]);\r\n break;\r\n case Mesh.CAP_ALL:\r\n shapePaths[0] = capPath(shapePaths[2]);\r\n shapePaths[1] = shapePaths[2];\r\n shapePaths[index] = shapePaths[index - 1];\r\n shapePaths[index + 1] = capPath(shapePaths[index - 1]);\r\n break;\r\n default:\r\n break;\r\n }\r\n return shapePaths;\r\n };\r\n let path3D;\r\n let pathArray;\r\n if (instance) {\r\n // instance update\r\n const storage = instance._creationDataStorage!;\r\n path3D = firstNormal ? storage.path3D.update(curve, firstNormal) : storage.path3D.update(curve);\r\n pathArray = extrusionPathArray(shape, curve, storage.path3D, storage.pathArray, scale, rotation, scaleFunction, rotateFunction, storage.cap, custom, adjustFrame);\r\n instance = CreateRibbon(\"\", { pathArray, closeArray: false, closePath: false, offset: 0, updatable: false, sideOrientation: 0, instance }, scene || undefined);\r\n\r\n return instance;\r\n }\r\n // extruded shape creation\r\n path3D = firstNormal ? new Path3D(curve, firstNormal) : new Path3D(curve);\r\n const newShapePaths = new Array>();\r\n cap = cap < 0 || cap > 3 ? 0 : cap;\r\n pathArray = extrusionPathArray(shape, curve, path3D, newShapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom, adjustFrame);\r\n const extrudedGeneric = CreateRibbon(\r\n name,\r\n {\r\n pathArray: pathArray,\r\n closeArray: rbCA,\r\n closePath: rbCP,\r\n updatable: updtbl,\r\n sideOrientation: side,\r\n invertUV: invertUV,\r\n frontUVs: frontUVs || undefined,\r\n backUVs: backUVs || undefined,\r\n },\r\n scene\r\n );\r\n extrudedGeneric._creationDataStorage!.pathArray = pathArray;\r\n extrudedGeneric._creationDataStorage!.path3D = path3D;\r\n extrudedGeneric._creationDataStorage!.cap = cap;\r\n\r\n return extrudedGeneric;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated please use the functions directly from the module\r\n */\r\nexport const ShapeBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n ExtrudeShape,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n ExtrudeShapeCustom,\r\n};\r\n\r\nMesh.ExtrudeShape = (\r\n name: string,\r\n shape: Vector3[],\r\n path: Vector3[],\r\n scale: number,\r\n rotation: number,\r\n cap: number,\r\n scene: Nullable = null,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n path: path,\r\n scale: scale,\r\n rotation: rotation,\r\n cap: cap === 0 ? 0 : cap || Mesh.NO_CAP,\r\n sideOrientation: sideOrientation,\r\n instance: instance,\r\n updatable: updatable,\r\n };\r\n\r\n return ExtrudeShape(name, options, scene);\r\n};\r\n\r\nMesh.ExtrudeShapeCustom = (\r\n name: string,\r\n shape: Vector3[],\r\n path: Vector3[],\r\n scaleFunction: Nullable<{ (i: number, distance: number): number }>,\r\n rotationFunction: Nullable<{ (i: number, distance: number): number }>,\r\n ribbonCloseArray: boolean,\r\n ribbonClosePath: boolean,\r\n cap: number,\r\n scene: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n path: path,\r\n scaleFunction: scaleFunction,\r\n rotationFunction: rotationFunction,\r\n ribbonCloseArray: ribbonCloseArray,\r\n ribbonClosePath: ribbonClosePath,\r\n cap: cap === 0 ? 0 : cap || Mesh.NO_CAP,\r\n sideOrientation: sideOrientation,\r\n instance: instance,\r\n updatable: updatable,\r\n };\r\n\r\n return ExtrudeShapeCustom(name, options, scene);\r\n};\r\n","import type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { CreateRibbon } from \"./ribbonBuilder\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Creates lathe mesh.\r\n * The lathe is a shape with a symmetry axis : a 2D model shape is rotated around this axis to design the lathe\r\n * * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero\r\n * * The parameter `radius` (positive float, default 1) is the radius value of the lathe\r\n * * The parameter `tessellation` (positive integer, default 64) is the side number of the lathe\r\n * * The parameter `clip` (positive integer, default 0) is the number of sides to not create without effecting the general shape of the sides\r\n * * The parameter `arc` (positive float, default 1) is the ratio of the lathe. 0.5 builds for instance half a lathe, so an opened shape\r\n * * The parameter `closed` (boolean, default true) opens/closes the lathe circumference. This should be set to false when used with the parameter \"arc\"\r\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.shape\r\n * @param options.radius\r\n * @param options.tessellation\r\n * @param options.clip\r\n * @param options.arc\r\n * @param options.closed\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.cap\r\n * @param options.invertUV\r\n * @param scene defines the hosting scene\r\n * @returns the lathe mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param#lathe\r\n */\r\nexport function CreateLathe(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n radius?: number;\r\n tessellation?: number;\r\n clip?: number;\r\n arc?: number;\r\n closed?: boolean;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n cap?: number;\r\n invertUV?: boolean;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const arc: number = options.arc ? (options.arc <= 0 || options.arc > 1 ? 1.0 : options.arc) : 1.0;\r\n const closed: boolean = options.closed === undefined ? true : options.closed;\r\n const shape = options.shape;\r\n const radius = options.radius || 1;\r\n const tessellation = options.tessellation || 64;\r\n const clip = options.clip || 0;\r\n const updatable = options.updatable;\r\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const cap = options.cap || Mesh.NO_CAP;\r\n const pi2 = Math.PI * 2;\r\n const paths = new Array();\r\n const invertUV = options.invertUV || false;\r\n\r\n let i = 0;\r\n let p = 0;\r\n const step = (pi2 / tessellation) * arc;\r\n let rotated;\r\n let path: Array;\r\n for (i = 0; i <= tessellation - clip; i++) {\r\n path = [];\r\n if (cap == Mesh.CAP_START || cap == Mesh.CAP_ALL) {\r\n path.push(new Vector3(0, shape[0].y, 0));\r\n path.push(new Vector3(Math.cos(i * step) * shape[0].x * radius, shape[0].y, Math.sin(i * step) * shape[0].x * radius));\r\n }\r\n for (p = 0; p < shape.length; p++) {\r\n rotated = new Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y, Math.sin(i * step) * shape[p].x * radius);\r\n path.push(rotated);\r\n }\r\n if (cap == Mesh.CAP_END || cap == Mesh.CAP_ALL) {\r\n path.push(new Vector3(Math.cos(i * step) * shape[shape.length - 1].x * radius, shape[shape.length - 1].y, Math.sin(i * step) * shape[shape.length - 1].x * radius));\r\n path.push(new Vector3(0, shape[shape.length - 1].y, 0));\r\n }\r\n paths.push(path);\r\n }\r\n\r\n // lathe ribbon\r\n const lathe = CreateRibbon(\r\n name,\r\n { pathArray: paths, closeArray: closed, sideOrientation: sideOrientation, updatable: updatable, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs },\r\n scene\r\n );\r\n return lathe;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function direction from the module\r\n */\r\nexport const LatheBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateLathe,\r\n};\r\n\r\nMesh.CreateLathe = (name: string, shape: Vector3[], radius: number, tessellation: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n shape: shape,\r\n radius: radius,\r\n tessellation: tessellation,\r\n sideOrientation: sideOrientation,\r\n updatable: updatable,\r\n };\r\n\r\n return CreateLathe(name, options, scene);\r\n};\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors, Matrix } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { CreateRibbon } from \"./ribbonBuilder\";\r\nimport { Path3D } from \"../../Maths/math.path\";\r\n\r\n/**\r\n * Creates a tube mesh.\r\n * The tube is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters\r\n * * The parameter `path` is a required array of successive Vector3. It is the curve used as the axis of the tube\r\n * * The parameter `radius` (positive float, default 1) sets the tube radius size\r\n * * The parameter `tessellation` (positive float, default 64) is the number of sides on the tubular surface\r\n * * The parameter `radiusFunction` (javascript function, default null) is a vanilla javascript function. If it is not null, it overrides the parameter `radius`\r\n * * This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path. It must return a radius value (positive float)\r\n * * The parameter `arc` (positive float, maximum 1, default 1) is the ratio to apply to the tube circumference : 2 x PI x arc\r\n * * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL\r\n * * The optional parameter `instance` is an instance of an existing Tube object to be updated with the passed `pathArray` parameter. The `path`Array HAS to have the SAME number of points as the previous one: https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#tube\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created. The NUMBER of points CAN'T CHANGE, only their positions.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.path\r\n * @param options.radius\r\n * @param options.tessellation\r\n * @param options.radiusFunction\r\n * @param options.cap\r\n * @param options.arc\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.instance\r\n * @param options.invertUV\r\n * @param scene defines the hosting scene\r\n * @returns the tube mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#tube\r\n */\r\nexport function CreateTube(\r\n name: string,\r\n options: {\r\n path: Vector3[];\r\n radius?: number;\r\n tessellation?: number;\r\n radiusFunction?: { (i: number, distance: number): number };\r\n cap?: number;\r\n arc?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n instance?: Mesh;\r\n invertUV?: boolean;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const path = options.path;\r\n let instance = options.instance;\r\n let radius = 1.0;\r\n\r\n if (options.radius !== undefined) {\r\n radius = options.radius;\r\n } else if (instance) {\r\n radius = instance._creationDataStorage!.radius;\r\n }\r\n\r\n const tessellation = options.tessellation || 64 | 0;\r\n const radiusFunction = options.radiusFunction || null;\r\n let cap = options.cap || Mesh.NO_CAP;\r\n const invertUV = options.invertUV || false;\r\n const updatable = options.updatable;\r\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n options.arc = options.arc && (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;\r\n\r\n // tube geometry\r\n const tubePathArray = (\r\n path: Vector3[],\r\n path3D: Path3D,\r\n circlePaths: Vector3[][],\r\n radius: number,\r\n tessellation: number,\r\n radiusFunction: Nullable<{ (i: number, distance: number): number }>,\r\n cap: number,\r\n arc: number\r\n ) => {\r\n const tangents = path3D.getTangents();\r\n const normals = path3D.getNormals();\r\n const distances = path3D.getDistances();\r\n const pi2 = Math.PI * 2;\r\n const step = (pi2 / tessellation) * arc;\r\n const returnRadius: { (i: number, distance: number): number } = () => radius;\r\n const radiusFunctionFinal: { (i: number, distance: number): number } = radiusFunction || returnRadius;\r\n\r\n let circlePath: Vector3[];\r\n let rad: number;\r\n let normal: Vector3;\r\n let rotated: Vector3;\r\n const rotationMatrix: Matrix = TmpVectors.Matrix[0];\r\n let index = cap === Mesh.NO_CAP || cap === Mesh.CAP_END ? 0 : 2;\r\n for (let i = 0; i < path.length; i++) {\r\n rad = radiusFunctionFinal(i, distances[i]); // current radius\r\n circlePath = Array(); // current circle array\r\n normal = normals[i]; // current normal\r\n for (let t = 0; t < tessellation; t++) {\r\n Matrix.RotationAxisToRef(tangents[i], step * t, rotationMatrix);\r\n rotated = circlePath[t] ? circlePath[t] : Vector3.Zero();\r\n Vector3.TransformCoordinatesToRef(normal, rotationMatrix, rotated);\r\n rotated.scaleInPlace(rad).addInPlace(path[i]);\r\n circlePath[t] = rotated;\r\n }\r\n circlePaths[index] = circlePath;\r\n index++;\r\n }\r\n // cap\r\n const capPath = (nbPoints: number, pathIndex: number): Array => {\r\n const pointCap = Array();\r\n for (let i = 0; i < nbPoints; i++) {\r\n pointCap.push(path[pathIndex]);\r\n }\r\n return pointCap;\r\n };\r\n switch (cap) {\r\n case Mesh.NO_CAP:\r\n break;\r\n case Mesh.CAP_START:\r\n circlePaths[0] = capPath(tessellation, 0);\r\n circlePaths[1] = circlePaths[2].slice(0);\r\n break;\r\n case Mesh.CAP_END:\r\n circlePaths[index] = circlePaths[index - 1].slice(0);\r\n circlePaths[index + 1] = capPath(tessellation, path.length - 1);\r\n break;\r\n case Mesh.CAP_ALL:\r\n circlePaths[0] = capPath(tessellation, 0);\r\n circlePaths[1] = circlePaths[2].slice(0);\r\n circlePaths[index] = circlePaths[index - 1].slice(0);\r\n circlePaths[index + 1] = capPath(tessellation, path.length - 1);\r\n break;\r\n default:\r\n break;\r\n }\r\n return circlePaths;\r\n };\r\n\r\n let path3D;\r\n let pathArray;\r\n if (instance) {\r\n // tube update\r\n const storage = instance._creationDataStorage!;\r\n const arc = options.arc || storage.arc;\r\n path3D = storage.path3D.update(path);\r\n pathArray = tubePathArray(path, path3D, storage.pathArray, radius, storage.tessellation, radiusFunction, storage.cap, arc);\r\n instance = CreateRibbon(\"\", { pathArray: pathArray, instance: instance });\r\n // Update mode, no need to recreate the storage.\r\n storage.path3D = path3D;\r\n storage.pathArray = pathArray;\r\n storage.arc = arc;\r\n storage.radius = radius;\r\n\r\n return instance;\r\n }\r\n\r\n // tube creation\r\n path3D = new Path3D(path);\r\n const newPathArray = new Array>();\r\n cap = cap < 0 || cap > 3 ? 0 : cap;\r\n pathArray = tubePathArray(path, path3D, newPathArray, radius, tessellation, radiusFunction, cap, options.arc);\r\n const tube = CreateRibbon(\r\n name,\r\n {\r\n pathArray: pathArray,\r\n closePath: true,\r\n closeArray: false,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n invertUV: invertUV,\r\n frontUVs: options.frontUVs,\r\n backUVs: options.backUVs,\r\n },\r\n scene\r\n );\r\n tube._creationDataStorage!.pathArray = pathArray;\r\n tube._creationDataStorage!.path3D = path3D;\r\n tube._creationDataStorage!.tessellation = tessellation;\r\n tube._creationDataStorage!.cap = cap;\r\n tube._creationDataStorage!.arc = options.arc;\r\n tube._creationDataStorage!.radius = radius;\r\n\r\n return tube;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTube directly\r\n */\r\nexport const TubeBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTube,\r\n};\r\n\r\nMesh.CreateTube = (\r\n name: string,\r\n path: Vector3[],\r\n radius: number,\r\n tessellation: number,\r\n radiusFunction: { (i: number, distance: number): number },\r\n cap: number,\r\n scene: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n): Mesh => {\r\n const options = {\r\n path: path,\r\n radius: radius,\r\n tessellation: tessellation,\r\n radiusFunction: radiusFunction,\r\n arc: 1,\r\n cap: cap,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n instance: instance,\r\n };\r\n return CreateTube(name, options, scene);\r\n};\r\n","import type { Scene } from \"../../scene\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n// inspired from // http://stemkoski.github.io/Three.js/Polyhedra.html\r\n/**\r\n * Creates the VertexData for a Polyhedron\r\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\r\n * * type provided types are:\r\n * * 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)\r\n * * 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)\r\n * * size the size of the IcoSphere, optional default 1\r\n * * sizeX allows stretching in the x direction, optional, default size\r\n * * sizeY allows stretching in the y direction, optional, default size\r\n * * sizeZ allows stretching in the z direction, optional, default size\r\n * * custom a number that overwrites the type to create from an extended set of polyhedron from https://www.babylonjs-playground.com/#21QRSK#15 with minimised editor\r\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * * flat when true creates a flat shaded mesh, optional, default true\r\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.type\r\n * @param options.size\r\n * @param options.sizeX\r\n * @param options.sizeY\r\n * @param options.sizeZ\r\n * @param options.custom\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.flat\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the Polyhedron\r\n */\r\nexport function CreatePolyhedronVertexData(options: {\r\n type?: number;\r\n size?: number;\r\n sizeX?: number;\r\n sizeY?: number;\r\n sizeZ?: number;\r\n custom?: any;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n flat?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n // provided polyhedron types :\r\n // 0 : Tetrahedron, 1 : Octahedron, 2 : Dodecahedron, 3 : Icosahedron, 4 : Rhombicuboctahedron, 5 : Triangular Prism, 6 : Pentagonal Prism, 7 : Hexagonal Prism, 8 : Square Pyramid (J1)\r\n // 9 : Pentagonal Pyramid (J2), 10 : Triangular Dipyramid (J12), 11 : Pentagonal Dipyramid (J13), 12 : Elongated Square Dipyramid (J15), 13 : Elongated Pentagonal Dipyramid (J16), 14 : Elongated Pentagonal Cupola (J20)\r\n const polyhedra: { vertex: number[][]; face: number[][] }[] = [];\r\n polyhedra[0] = {\r\n vertex: [\r\n [0, 0, 1.732051],\r\n [1.632993, 0, -0.5773503],\r\n [-0.8164966, 1.414214, -0.5773503],\r\n [-0.8164966, -1.414214, -0.5773503],\r\n ],\r\n face: [\r\n [0, 1, 2],\r\n [0, 2, 3],\r\n [0, 3, 1],\r\n [1, 3, 2],\r\n ],\r\n };\r\n polyhedra[1] = {\r\n vertex: [\r\n [0, 0, 1.414214],\r\n [1.414214, 0, 0],\r\n [0, 1.414214, 0],\r\n [-1.414214, 0, 0],\r\n [0, -1.414214, 0],\r\n [0, 0, -1.414214],\r\n ],\r\n face: [\r\n [0, 1, 2],\r\n [0, 2, 3],\r\n [0, 3, 4],\r\n [0, 4, 1],\r\n [1, 4, 5],\r\n [1, 5, 2],\r\n [2, 5, 3],\r\n [3, 5, 4],\r\n ],\r\n };\r\n polyhedra[2] = {\r\n vertex: [\r\n [0, 0, 1.070466],\r\n [0.7136442, 0, 0.7978784],\r\n [-0.3568221, 0.618034, 0.7978784],\r\n [-0.3568221, -0.618034, 0.7978784],\r\n [0.7978784, 0.618034, 0.3568221],\r\n [0.7978784, -0.618034, 0.3568221],\r\n [-0.9341724, 0.381966, 0.3568221],\r\n [0.1362939, 1, 0.3568221],\r\n [0.1362939, -1, 0.3568221],\r\n [-0.9341724, -0.381966, 0.3568221],\r\n [0.9341724, 0.381966, -0.3568221],\r\n [0.9341724, -0.381966, -0.3568221],\r\n [-0.7978784, 0.618034, -0.3568221],\r\n [-0.1362939, 1, -0.3568221],\r\n [-0.1362939, -1, -0.3568221],\r\n [-0.7978784, -0.618034, -0.3568221],\r\n [0.3568221, 0.618034, -0.7978784],\r\n [0.3568221, -0.618034, -0.7978784],\r\n [-0.7136442, 0, -0.7978784],\r\n [0, 0, -1.070466],\r\n ],\r\n face: [\r\n [0, 1, 4, 7, 2],\r\n [0, 2, 6, 9, 3],\r\n [0, 3, 8, 5, 1],\r\n [1, 5, 11, 10, 4],\r\n [2, 7, 13, 12, 6],\r\n [3, 9, 15, 14, 8],\r\n [4, 10, 16, 13, 7],\r\n [5, 8, 14, 17, 11],\r\n [6, 12, 18, 15, 9],\r\n [10, 11, 17, 19, 16],\r\n [12, 13, 16, 19, 18],\r\n [14, 15, 18, 19, 17],\r\n ],\r\n };\r\n polyhedra[3] = {\r\n vertex: [\r\n [0, 0, 1.175571],\r\n [1.051462, 0, 0.5257311],\r\n [0.3249197, 1, 0.5257311],\r\n [-0.8506508, 0.618034, 0.5257311],\r\n [-0.8506508, -0.618034, 0.5257311],\r\n [0.3249197, -1, 0.5257311],\r\n [0.8506508, 0.618034, -0.5257311],\r\n [0.8506508, -0.618034, -0.5257311],\r\n [-0.3249197, 1, -0.5257311],\r\n [-1.051462, 0, -0.5257311],\r\n [-0.3249197, -1, -0.5257311],\r\n [0, 0, -1.175571],\r\n ],\r\n face: [\r\n [0, 1, 2],\r\n [0, 2, 3],\r\n [0, 3, 4],\r\n [0, 4, 5],\r\n [0, 5, 1],\r\n [1, 5, 7],\r\n [1, 7, 6],\r\n [1, 6, 2],\r\n [2, 6, 8],\r\n [2, 8, 3],\r\n [3, 8, 9],\r\n [3, 9, 4],\r\n [4, 9, 10],\r\n [4, 10, 5],\r\n [5, 10, 7],\r\n [6, 7, 11],\r\n [6, 11, 8],\r\n [7, 10, 11],\r\n [8, 11, 9],\r\n [9, 11, 10],\r\n ],\r\n };\r\n polyhedra[4] = {\r\n vertex: [\r\n [0, 0, 1.070722],\r\n [0.7148135, 0, 0.7971752],\r\n [-0.104682, 0.7071068, 0.7971752],\r\n [-0.6841528, 0.2071068, 0.7971752],\r\n [-0.104682, -0.7071068, 0.7971752],\r\n [0.6101315, 0.7071068, 0.5236279],\r\n [1.04156, 0.2071068, 0.1367736],\r\n [0.6101315, -0.7071068, 0.5236279],\r\n [-0.3574067, 1, 0.1367736],\r\n [-0.7888348, -0.5, 0.5236279],\r\n [-0.9368776, 0.5, 0.1367736],\r\n [-0.3574067, -1, 0.1367736],\r\n [0.3574067, 1, -0.1367736],\r\n [0.9368776, -0.5, -0.1367736],\r\n [0.7888348, 0.5, -0.5236279],\r\n [0.3574067, -1, -0.1367736],\r\n [-0.6101315, 0.7071068, -0.5236279],\r\n [-1.04156, -0.2071068, -0.1367736],\r\n [-0.6101315, -0.7071068, -0.5236279],\r\n [0.104682, 0.7071068, -0.7971752],\r\n [0.6841528, -0.2071068, -0.7971752],\r\n [0.104682, -0.7071068, -0.7971752],\r\n [-0.7148135, 0, -0.7971752],\r\n [0, 0, -1.070722],\r\n ],\r\n face: [\r\n [0, 2, 3],\r\n [1, 6, 5],\r\n [4, 9, 11],\r\n [7, 15, 13],\r\n [8, 16, 10],\r\n [12, 14, 19],\r\n [17, 22, 18],\r\n [20, 21, 23],\r\n [0, 1, 5, 2],\r\n [0, 3, 9, 4],\r\n [0, 4, 7, 1],\r\n [1, 7, 13, 6],\r\n [2, 5, 12, 8],\r\n [2, 8, 10, 3],\r\n [3, 10, 17, 9],\r\n [4, 11, 15, 7],\r\n [5, 6, 14, 12],\r\n [6, 13, 20, 14],\r\n [8, 12, 19, 16],\r\n [9, 17, 18, 11],\r\n [10, 16, 22, 17],\r\n [11, 18, 21, 15],\r\n [13, 15, 21, 20],\r\n [14, 20, 23, 19],\r\n [16, 19, 23, 22],\r\n [18, 22, 23, 21],\r\n ],\r\n };\r\n polyhedra[5] = {\r\n vertex: [\r\n [0, 0, 1.322876],\r\n [1.309307, 0, 0.1889822],\r\n [-0.9819805, 0.8660254, 0.1889822],\r\n [0.1636634, -1.299038, 0.1889822],\r\n [0.3273268, 0.8660254, -0.9449112],\r\n [-0.8183171, -0.4330127, -0.9449112],\r\n ],\r\n face: [\r\n [0, 3, 1],\r\n [2, 4, 5],\r\n [0, 1, 4, 2],\r\n [0, 2, 5, 3],\r\n [1, 3, 5, 4],\r\n ],\r\n };\r\n polyhedra[6] = {\r\n vertex: [\r\n [0, 0, 1.159953],\r\n [1.013464, 0, 0.5642542],\r\n [-0.3501431, 0.9510565, 0.5642542],\r\n [-0.7715208, -0.6571639, 0.5642542],\r\n [0.6633206, 0.9510565, -0.03144481],\r\n [0.8682979, -0.6571639, -0.3996071],\r\n [-1.121664, 0.2938926, -0.03144481],\r\n [-0.2348831, -1.063314, -0.3996071],\r\n [0.5181548, 0.2938926, -0.9953061],\r\n [-0.5850262, -0.112257, -0.9953061],\r\n ],\r\n face: [\r\n [0, 1, 4, 2],\r\n [0, 2, 6, 3],\r\n [1, 5, 8, 4],\r\n [3, 6, 9, 7],\r\n [5, 7, 9, 8],\r\n [0, 3, 7, 5, 1],\r\n [2, 4, 8, 9, 6],\r\n ],\r\n };\r\n polyhedra[7] = {\r\n vertex: [\r\n [0, 0, 1.118034],\r\n [0.8944272, 0, 0.6708204],\r\n [-0.2236068, 0.8660254, 0.6708204],\r\n [-0.7826238, -0.4330127, 0.6708204],\r\n [0.6708204, 0.8660254, 0.2236068],\r\n [1.006231, -0.4330127, -0.2236068],\r\n [-1.006231, 0.4330127, 0.2236068],\r\n [-0.6708204, -0.8660254, -0.2236068],\r\n [0.7826238, 0.4330127, -0.6708204],\r\n [0.2236068, -0.8660254, -0.6708204],\r\n [-0.8944272, 0, -0.6708204],\r\n [0, 0, -1.118034],\r\n ],\r\n face: [\r\n [0, 1, 4, 2],\r\n [0, 2, 6, 3],\r\n [1, 5, 8, 4],\r\n [3, 6, 10, 7],\r\n [5, 9, 11, 8],\r\n [7, 10, 11, 9],\r\n [0, 3, 7, 9, 5, 1],\r\n [2, 4, 8, 11, 10, 6],\r\n ],\r\n };\r\n polyhedra[8] = {\r\n vertex: [\r\n [-0.729665, 0.670121, 0.319155],\r\n [-0.655235, -0.29213, -0.754096],\r\n [-0.093922, -0.607123, 0.537818],\r\n [0.702196, 0.595691, 0.485187],\r\n [0.776626, -0.36656, -0.588064],\r\n ],\r\n face: [\r\n [1, 4, 2],\r\n [0, 1, 2],\r\n [3, 0, 2],\r\n [4, 3, 2],\r\n [4, 1, 0, 3],\r\n ],\r\n };\r\n polyhedra[9] = {\r\n vertex: [\r\n [-0.868849, -0.100041, 0.61257],\r\n [-0.329458, 0.976099, 0.28078],\r\n [-0.26629, -0.013796, -0.477654],\r\n [-0.13392, -1.034115, 0.229829],\r\n [0.738834, 0.707117, -0.307018],\r\n [0.859683, -0.535264, -0.338508],\r\n ],\r\n face: [\r\n [3, 0, 2],\r\n [5, 3, 2],\r\n [4, 5, 2],\r\n [1, 4, 2],\r\n [0, 1, 2],\r\n [0, 3, 5, 4, 1],\r\n ],\r\n };\r\n polyhedra[10] = {\r\n vertex: [\r\n [-0.610389, 0.243975, 0.531213],\r\n [-0.187812, -0.48795, -0.664016],\r\n [-0.187812, 0.9759, -0.664016],\r\n [0.187812, -0.9759, 0.664016],\r\n [0.798201, 0.243975, 0.132803],\r\n ],\r\n face: [\r\n [1, 3, 0],\r\n [3, 4, 0],\r\n [3, 1, 4],\r\n [0, 2, 1],\r\n [0, 4, 2],\r\n [2, 4, 1],\r\n ],\r\n };\r\n polyhedra[11] = {\r\n vertex: [\r\n [-1.028778, 0.392027, -0.048786],\r\n [-0.640503, -0.646161, 0.621837],\r\n [-0.125162, -0.395663, -0.540059],\r\n [0.004683, 0.888447, -0.651988],\r\n [0.125161, 0.395663, 0.540059],\r\n [0.632925, -0.791376, 0.433102],\r\n [1.031672, 0.157063, -0.354165],\r\n ],\r\n face: [\r\n [3, 2, 0],\r\n [2, 1, 0],\r\n [2, 5, 1],\r\n [0, 4, 3],\r\n [0, 1, 4],\r\n [4, 1, 5],\r\n [2, 3, 6],\r\n [3, 4, 6],\r\n [5, 2, 6],\r\n [4, 5, 6],\r\n ],\r\n };\r\n polyhedra[12] = {\r\n vertex: [\r\n [-0.669867, 0.334933, -0.529576],\r\n [-0.669867, 0.334933, 0.529577],\r\n [-0.4043, 1.212901, 0],\r\n [-0.334933, -0.669867, -0.529576],\r\n [-0.334933, -0.669867, 0.529577],\r\n [0.334933, 0.669867, -0.529576],\r\n [0.334933, 0.669867, 0.529577],\r\n [0.4043, -1.212901, 0],\r\n [0.669867, -0.334933, -0.529576],\r\n [0.669867, -0.334933, 0.529577],\r\n ],\r\n face: [\r\n [8, 9, 7],\r\n [6, 5, 2],\r\n [3, 8, 7],\r\n [5, 0, 2],\r\n [4, 3, 7],\r\n [0, 1, 2],\r\n [9, 4, 7],\r\n [1, 6, 2],\r\n [9, 8, 5, 6],\r\n [8, 3, 0, 5],\r\n [3, 4, 1, 0],\r\n [4, 9, 6, 1],\r\n ],\r\n };\r\n polyhedra[13] = {\r\n vertex: [\r\n [-0.931836, 0.219976, -0.264632],\r\n [-0.636706, 0.318353, 0.692816],\r\n [-0.613483, -0.735083, -0.264632],\r\n [-0.326545, 0.979634, 0],\r\n [-0.318353, -0.636706, 0.692816],\r\n [-0.159176, 0.477529, -0.856368],\r\n [0.159176, -0.477529, -0.856368],\r\n [0.318353, 0.636706, 0.692816],\r\n [0.326545, -0.979634, 0],\r\n [0.613482, 0.735082, -0.264632],\r\n [0.636706, -0.318353, 0.692816],\r\n [0.931835, -0.219977, -0.264632],\r\n ],\r\n face: [\r\n [11, 10, 8],\r\n [7, 9, 3],\r\n [6, 11, 8],\r\n [9, 5, 3],\r\n [2, 6, 8],\r\n [5, 0, 3],\r\n [4, 2, 8],\r\n [0, 1, 3],\r\n [10, 4, 8],\r\n [1, 7, 3],\r\n [10, 11, 9, 7],\r\n [11, 6, 5, 9],\r\n [6, 2, 0, 5],\r\n [2, 4, 1, 0],\r\n [4, 10, 7, 1],\r\n ],\r\n };\r\n polyhedra[14] = {\r\n vertex: [\r\n [-0.93465, 0.300459, -0.271185],\r\n [-0.838689, -0.260219, -0.516017],\r\n [-0.711319, 0.717591, 0.128359],\r\n [-0.710334, -0.156922, 0.080946],\r\n [-0.599799, 0.556003, -0.725148],\r\n [-0.503838, -0.004675, -0.969981],\r\n [-0.487004, 0.26021, 0.48049],\r\n [-0.460089, -0.750282, -0.512622],\r\n [-0.376468, 0.973135, -0.325605],\r\n [-0.331735, -0.646985, 0.084342],\r\n [-0.254001, 0.831847, 0.530001],\r\n [-0.125239, -0.494738, -0.966586],\r\n [0.029622, 0.027949, 0.730817],\r\n [0.056536, -0.982543, -0.262295],\r\n [0.08085, 1.087391, 0.076037],\r\n [0.125583, -0.532729, 0.485984],\r\n [0.262625, 0.599586, 0.780328],\r\n [0.391387, -0.726999, -0.716259],\r\n [0.513854, -0.868287, 0.139347],\r\n [0.597475, 0.85513, 0.326364],\r\n [0.641224, 0.109523, 0.783723],\r\n [0.737185, -0.451155, 0.538891],\r\n [0.848705, -0.612742, -0.314616],\r\n [0.976075, 0.365067, 0.32976],\r\n [1.072036, -0.19561, 0.084927],\r\n ],\r\n face: [\r\n [15, 18, 21],\r\n [12, 20, 16],\r\n [6, 10, 2],\r\n [3, 0, 1],\r\n [9, 7, 13],\r\n [2, 8, 4, 0],\r\n [0, 4, 5, 1],\r\n [1, 5, 11, 7],\r\n [7, 11, 17, 13],\r\n [13, 17, 22, 18],\r\n [18, 22, 24, 21],\r\n [21, 24, 23, 20],\r\n [20, 23, 19, 16],\r\n [16, 19, 14, 10],\r\n [10, 14, 8, 2],\r\n [15, 9, 13, 18],\r\n [12, 15, 21, 20],\r\n [6, 12, 16, 10],\r\n [3, 6, 2, 0],\r\n [9, 3, 1, 7],\r\n [9, 15, 12, 6, 3],\r\n [22, 17, 11, 5, 4, 8, 14, 19, 23, 24],\r\n ],\r\n };\r\n\r\n const type: number = options.type && (options.type < 0 || options.type >= polyhedra.length) ? 0 : options.type || 0;\r\n const size = options.size;\r\n const sizeX: number = options.sizeX || size || 1;\r\n const sizeY: number = options.sizeY || size || 1;\r\n const sizeZ: number = options.sizeZ || size || 1;\r\n const data: { vertex: number[][]; face: number[][]; name?: string; category?: string } = options.custom || polyhedra[type];\r\n const nbfaces = data.face.length;\r\n const faceUV = options.faceUV || new Array(nbfaces);\r\n const faceColors = options.faceColors;\r\n const flat = options.flat === undefined ? true : options.flat;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n const positions = new Array();\r\n const indices = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n const colors = new Array();\r\n let index = 0;\r\n let faceIdx = 0; // face cursor in the array \"indexes\"\r\n const indexes = new Array();\r\n let i = 0;\r\n let f = 0;\r\n let u: number, v: number, ang: number, x: number, y: number, tmp: number;\r\n\r\n // default face colors and UV if undefined\r\n if (flat) {\r\n for (f = 0; f < nbfaces; f++) {\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n if (faceUV && faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n }\r\n }\r\n\r\n if (!flat) {\r\n for (i = 0; i < data.vertex.length; i++) {\r\n positions.push(data.vertex[i][0] * sizeX, data.vertex[i][1] * sizeY, data.vertex[i][2] * sizeZ);\r\n uvs.push(0, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 : 0);\r\n }\r\n for (f = 0; f < nbfaces; f++) {\r\n for (i = 0; i < data.face[f].length - 2; i++) {\r\n indices.push(data.face[f][0], data.face[f][i + 2], data.face[f][i + 1]);\r\n }\r\n }\r\n } else {\r\n for (f = 0; f < nbfaces; f++) {\r\n const fl = data.face[f].length; // number of vertices of the current face\r\n ang = (2 * Math.PI) / fl;\r\n x = 0.5 * Math.tan(ang / 2);\r\n y = 0.5;\r\n\r\n // positions, uvs, colors\r\n for (i = 0; i < fl; i++) {\r\n // positions\r\n positions.push(data.vertex[data.face[f][i]][0] * sizeX, data.vertex[data.face[f][i]][1] * sizeY, data.vertex[data.face[f][i]][2] * sizeZ);\r\n indexes.push(index);\r\n index++;\r\n // uvs\r\n u = faceUV[f].x + (faceUV[f].z - faceUV[f].x) * (0.5 + x);\r\n v = faceUV[f].y + (faceUV[f].w - faceUV[f].y) * (y - 0.5);\r\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - v : v);\r\n tmp = x * Math.cos(ang) - y * Math.sin(ang);\r\n y = x * Math.sin(ang) + y * Math.cos(ang);\r\n x = tmp;\r\n // colors\r\n if (faceColors) {\r\n colors.push(faceColors[f].r, faceColors[f].g, faceColors[f].b, faceColors[f].a);\r\n }\r\n }\r\n\r\n // indices from indexes\r\n for (i = 0; i < fl - 2; i++) {\r\n indices.push(indexes[0 + faceIdx], indexes[i + 2 + faceIdx], indexes[i + 1 + faceIdx]);\r\n }\r\n faceIdx += fl;\r\n }\r\n }\r\n\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n const vertexData = new VertexData();\r\n vertexData.positions = positions;\r\n vertexData.indices = indices;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n if (faceColors && flat) {\r\n vertexData.colors = colors;\r\n }\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a polyhedron mesh\r\n * * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embbeded types. Please refer to the type sheet in the tutorial to choose the wanted type\r\n * * The parameter `size` (positive float, default 1) sets the polygon size\r\n * * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value)\r\n * * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overrides the parameter `type`\r\n * * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron\r\n * * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`)\r\n * * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.type\r\n * @param options.size\r\n * @param options.sizeX\r\n * @param options.sizeY\r\n * @param options.sizeZ\r\n * @param options.custom\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.flat\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param scene defines the hosting scene\r\n * @returns the polyhedron mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra\r\n */\r\nexport function CreatePolyhedron(\r\n name: string,\r\n options: {\r\n type?: number;\r\n size?: number;\r\n sizeX?: number;\r\n sizeY?: number;\r\n sizeZ?: number;\r\n custom?: any;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n flat?: boolean;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n } = {},\r\n scene: Nullable = null\r\n): Mesh {\r\n const polyhedron = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n polyhedron._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreatePolyhedronVertexData(options);\r\n\r\n vertexData.applyToMesh(polyhedron, options.updatable);\r\n\r\n return polyhedron;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const PolyhedronBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreatePolyhedron,\r\n};\r\n\r\nVertexData.CreatePolyhedron = CreatePolyhedronVertexData;\r\n\r\nMesh.CreatePolyhedron = (\r\n name: string,\r\n options: {\r\n type?: number;\r\n size?: number;\r\n sizeX?: number;\r\n sizeY?: number;\r\n sizeZ?: number;\r\n custom?: any;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n },\r\n scene: Scene\r\n): Mesh => {\r\n return CreatePolyhedron(name, options, scene);\r\n};\r\n","import type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3, Vector2 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData of the IcoSphere\r\n * @param options an object used to set the following optional parameters for the IcoSphere, required but can be empty\r\n * * radius the radius of the IcoSphere, optional default 1\r\n * * radiusX allows stretching in the x direction, optional, default radius\r\n * * radiusY allows stretching in the y direction, optional, default radius\r\n * * radiusZ allows stretching in the z direction, optional, default radius\r\n * * flat when true creates a flat shaded mesh, optional, default true\r\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.radiusX\r\n * @param options.radiusY\r\n * @param options.radiusZ\r\n * @param options.flat\r\n * @param options.subdivisions\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the IcoSphere\r\n */\r\nexport function CreateIcoSphereVertexData(options: {\r\n radius?: number;\r\n radiusX?: number;\r\n radiusY?: number;\r\n radiusZ?: number;\r\n flat?: boolean;\r\n subdivisions?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const sideOrientation = options.sideOrientation || VertexData.DEFAULTSIDE;\r\n const radius = options.radius || 1;\r\n const flat = options.flat === undefined ? true : options.flat;\r\n const subdivisions = (options.subdivisions || 4) | 0;\r\n const radiusX = options.radiusX || radius;\r\n const radiusY = options.radiusY || radius;\r\n const radiusZ = options.radiusZ || radius;\r\n\r\n const t = (1 + Math.sqrt(5)) / 2;\r\n\r\n // 12 vertex x,y,z\r\n const icoVertices = [\r\n -1,\r\n t,\r\n -0,\r\n 1,\r\n t,\r\n 0,\r\n -1,\r\n -t,\r\n 0,\r\n 1,\r\n -t,\r\n 0, // v0-3\r\n 0,\r\n -1,\r\n -t,\r\n 0,\r\n 1,\r\n -t,\r\n 0,\r\n -1,\r\n t,\r\n 0,\r\n 1,\r\n t, // v4-7\r\n t,\r\n 0,\r\n 1,\r\n t,\r\n 0,\r\n -1,\r\n -t,\r\n 0,\r\n 1,\r\n -t,\r\n 0,\r\n -1, // v8-11\r\n ];\r\n\r\n // index of 3 vertex makes a face of icopshere\r\n const ico_indices = [\r\n 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 12, 22, 23, 1, 5, 20, 5, 11, 4, 23, 22, 13, 22, 18, 6, 7, 1, 8, 14, 21, 4, 14, 4, 2, 16, 13, 6, 15, 6, 19, 3, 8, 9, 4, 21, 5, 13, 17,\r\n 23, 6, 13, 22, 19, 6, 18, 9, 8, 1,\r\n ];\r\n // vertex for uv have aliased position, not for UV\r\n const vertices_unalias_id = [\r\n 0,\r\n 1,\r\n 2,\r\n 3,\r\n 4,\r\n 5,\r\n 6,\r\n 7,\r\n 8,\r\n 9,\r\n 10,\r\n 11,\r\n // vertex alias\r\n 0, // 12: 0 + 12\r\n 2, // 13: 2 + 11\r\n 3, // 14: 3 + 11\r\n 3, // 15: 3 + 12\r\n 3, // 16: 3 + 13\r\n 4, // 17: 4 + 13\r\n 7, // 18: 7 + 11\r\n 8, // 19: 8 + 11\r\n 9, // 20: 9 + 11\r\n 9, // 21: 9 + 12\r\n 10, // 22: A + 12\r\n 11, // 23: B + 12\r\n ];\r\n\r\n // uv as integer step (not pixels !)\r\n const ico_vertexuv = [\r\n 5,\r\n 1,\r\n 3,\r\n 1,\r\n 6,\r\n 4,\r\n 0,\r\n 0, // v0-3\r\n 5,\r\n 3,\r\n 4,\r\n 2,\r\n 2,\r\n 2,\r\n 4,\r\n 0, // v4-7\r\n 2,\r\n 0,\r\n 1,\r\n 1,\r\n 6,\r\n 0,\r\n 6,\r\n 2, // v8-11\r\n // vertex alias (for same vertex on different faces)\r\n 0,\r\n 4, // 12: 0 + 12\r\n 3,\r\n 3, // 13: 2 + 11\r\n 4,\r\n 4, // 14: 3 + 11\r\n 3,\r\n 1, // 15: 3 + 12\r\n 4,\r\n 2, // 16: 3 + 13\r\n 4,\r\n 4, // 17: 4 + 13\r\n 0,\r\n 2, // 18: 7 + 11\r\n 1,\r\n 1, // 19: 8 + 11\r\n 2,\r\n 2, // 20: 9 + 11\r\n 3,\r\n 3, // 21: 9 + 12\r\n 1,\r\n 3, // 22: A + 12\r\n 2,\r\n 4, // 23: B + 12\r\n ];\r\n\r\n // Vertices[0, 1, ...9, A, B] : position on UV plane\r\n // '+' indicate duplicate position to be fixed (3,9:0,2,3,4,7,8,A,B)\r\n // First island of uv mapping\r\n // v = 4h 3+ 2\r\n // v = 3h 9+ 4\r\n // v = 2h 9+ 5 B\r\n // v = 1h 9 1 0\r\n // v = 0h 3 8 7 A\r\n // u = 0 1 2 3 4 5 6 *a\r\n\r\n // Second island of uv mapping\r\n // v = 4h 0+ B+ 4+\r\n // v = 3h A+ 2+\r\n // v = 2h 7+ 6 3+\r\n // v = 1h 8+ 3+\r\n // v = 0h\r\n // u = 0 1 2 3 4 5 6 *a\r\n\r\n // Face layout on texture UV mapping\r\n // ============\r\n // \\ 4 /\\ 16 / ======\r\n // \\ / \\ / /\\ 11 /\r\n // \\/ 7 \\/ / \\ /\r\n // ======= / 10 \\/\r\n // /\\ 17 /\\ =======\r\n // / \\ / \\ \\ 15 /\\\r\n // / 8 \\/ 12 \\ \\ / \\\r\n // ============ \\/ 6 \\\r\n // \\ 18 /\\ ============\r\n // \\ / \\ \\ 5 /\\ 0 /\r\n // \\/ 13 \\ \\ / \\ /\r\n // ======= \\/ 1 \\/\r\n // =============\r\n // /\\ 19 /\\ 2 /\\\r\n // / \\ / \\ / \\\r\n // / 14 \\/ 9 \\/ 3 \\\r\n // ===================\r\n\r\n // uv step is u:1 or 0.5, v:cos(30)=sqrt(3)/2, ratio approx is 84/97\r\n const ustep = 138 / 1024;\r\n const vstep = 239 / 1024;\r\n const uoffset = 60 / 1024;\r\n const voffset = 26 / 1024;\r\n // Second island should have margin, not to touch the first island\r\n // avoid any borderline artefact in pixel rounding\r\n const island_u_offset = -40 / 1024;\r\n const island_v_offset = +20 / 1024;\r\n // face is either island 0 or 1 :\r\n // second island is for faces : [4, 7, 8, 12, 13, 16, 17, 18]\r\n const island = [\r\n 0,\r\n 0,\r\n 0,\r\n 0,\r\n 1, // 0 - 4\r\n 0,\r\n 0,\r\n 1,\r\n 1,\r\n 0, // 5 - 9\r\n 0,\r\n 0,\r\n 1,\r\n 1,\r\n 0, // 10 - 14\r\n 0,\r\n 1,\r\n 1,\r\n 1,\r\n 0, // 15 - 19\r\n ];\r\n\r\n const indices = new Array();\r\n const positions = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n\r\n let current_indice = 0;\r\n // prepare array of 3 vector (empty) (to be worked in place, shared for each face)\r\n const face_vertex_pos = new Array(3);\r\n const face_vertex_uv = new Array(3);\r\n let v012;\r\n for (v012 = 0; v012 < 3; v012++) {\r\n face_vertex_pos[v012] = Vector3.Zero();\r\n face_vertex_uv[v012] = Vector2.Zero();\r\n }\r\n // create all with normals\r\n for (let face = 0; face < 20; face++) {\r\n // 3 vertex per face\r\n for (v012 = 0; v012 < 3; v012++) {\r\n // look up vertex 0,1,2 to its index in 0 to 11 (or 23 including alias)\r\n const v_id = ico_indices[3 * face + v012];\r\n // vertex have 3D position (x,y,z)\r\n face_vertex_pos[v012].copyFromFloats(\r\n icoVertices[3 * vertices_unalias_id[v_id]],\r\n icoVertices[3 * vertices_unalias_id[v_id] + 1],\r\n icoVertices[3 * vertices_unalias_id[v_id] + 2]\r\n );\r\n // Normalize to get normal\r\n face_vertex_pos[v012].normalize();\r\n\r\n // uv Coordinates from vertex ID\r\n face_vertex_uv[v012].copyFromFloats(\r\n ico_vertexuv[2 * v_id] * ustep + uoffset + island[face] * island_u_offset,\r\n ico_vertexuv[2 * v_id + 1] * vstep + voffset + island[face] * island_v_offset\r\n );\r\n }\r\n\r\n // Subdivide the face (interpolate pos, norm, uv)\r\n // - pos is linear interpolation, then projected to sphere (converge polyhedron to sphere)\r\n // - norm is linear interpolation of vertex corner normal\r\n // (to be checked if better to re-calc from face vertex, or if approximation is OK ??? )\r\n // - uv is linear interpolation\r\n //\r\n // Topology is as below for sub-divide by 2\r\n // vertex shown as v0,v1,v2\r\n // interp index is i1 to progress in range [v0,v1[\r\n // interp index is i2 to progress in range [v0,v2[\r\n // face index as (i1,i2) for /\\ : (i1,i2),(i1+1,i2),(i1,i2+1)\r\n // and (i1,i2)' for \\/ : (i1+1,i2),(i1+1,i2+1),(i1,i2+1)\r\n //\r\n //\r\n // i2 v2\r\n // ^ ^\r\n // / / \\\r\n // / / \\\r\n // / / \\\r\n // / / (0,1) \\\r\n // / #---------\\\r\n // / / \\ (0,0)'/ \\\r\n // / / \\ / \\\r\n // / / \\ / \\\r\n // / / (0,0) \\ / (1,0) \\\r\n // / #---------#---------\\\r\n // v0 v1\r\n //\r\n // --------------------> i1\r\n //\r\n // interp of (i1,i2):\r\n // along i2 : x0=lerp(v0,v2, i2/S) <---> x1=lerp(v1,v2, i2/S)\r\n // along i1 : lerp(x0,x1, i1/(S-i2))\r\n //\r\n // centroid of triangle is needed to get help normal computation\r\n // (c1,c2) are used for centroid location\r\n\r\n const interp_vertex = (i1: number, i2: number, c1: number, c2: number) => {\r\n // vertex is interpolated from\r\n // - face_vertex_pos[0..2]\r\n // - face_vertex_uv[0..2]\r\n const pos_x0 = Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], i2 / subdivisions);\r\n const pos_x1 = Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], i2 / subdivisions);\r\n const pos_interp = subdivisions === i2 ? face_vertex_pos[2] : Vector3.Lerp(pos_x0, pos_x1, i1 / (subdivisions - i2));\r\n pos_interp.normalize();\r\n\r\n let vertex_normal;\r\n if (flat) {\r\n // in flat mode, recalculate normal as face centroid normal\r\n const centroid_x0 = Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], c2 / subdivisions);\r\n const centroid_x1 = Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], c2 / subdivisions);\r\n vertex_normal = Vector3.Lerp(centroid_x0, centroid_x1, c1 / (subdivisions - c2));\r\n } else {\r\n // in smooth mode, recalculate normal from each single vertex position\r\n vertex_normal = new Vector3(pos_interp.x, pos_interp.y, pos_interp.z);\r\n }\r\n // Vertex normal need correction due to X,Y,Z radius scaling\r\n vertex_normal.x /= radiusX;\r\n vertex_normal.y /= radiusY;\r\n vertex_normal.z /= radiusZ;\r\n vertex_normal.normalize();\r\n\r\n const uv_x0 = Vector2.Lerp(face_vertex_uv[0], face_vertex_uv[2], i2 / subdivisions);\r\n const uv_x1 = Vector2.Lerp(face_vertex_uv[1], face_vertex_uv[2], i2 / subdivisions);\r\n const uv_interp = subdivisions === i2 ? face_vertex_uv[2] : Vector2.Lerp(uv_x0, uv_x1, i1 / (subdivisions - i2));\r\n positions.push(pos_interp.x * radiusX, pos_interp.y * radiusY, pos_interp.z * radiusZ);\r\n normals.push(vertex_normal.x, vertex_normal.y, vertex_normal.z);\r\n uvs.push(uv_interp.x, CompatibilityOptions.UseOpenGLOrientationForUV ? 1.0 - uv_interp.y : uv_interp.y);\r\n // push each vertex has member of a face\r\n // Same vertex can belong to multiple face, it is pushed multiple time (duplicate vertex are present)\r\n indices.push(current_indice);\r\n current_indice++;\r\n };\r\n\r\n for (let i2 = 0; i2 < subdivisions; i2++) {\r\n for (let i1 = 0; i1 + i2 < subdivisions; i1++) {\r\n // face : (i1,i2) for /\\ :\r\n // interp for : (i1,i2),(i1+1,i2),(i1,i2+1)\r\n interp_vertex(i1, i2, i1 + 1.0 / 3, i2 + 1.0 / 3);\r\n interp_vertex(i1 + 1, i2, i1 + 1.0 / 3, i2 + 1.0 / 3);\r\n interp_vertex(i1, i2 + 1, i1 + 1.0 / 3, i2 + 1.0 / 3);\r\n if (i1 + i2 + 1 < subdivisions) {\r\n // face : (i1,i2)' for \\/ :\r\n // interp for (i1+1,i2),(i1+1,i2+1),(i1,i2+1)\r\n interp_vertex(i1 + 1, i2, i1 + 2.0 / 3, i2 + 2.0 / 3);\r\n interp_vertex(i1 + 1, i2 + 1, i1 + 2.0 / 3, i2 + 2.0 / 3);\r\n interp_vertex(i1, i2 + 1, i1 + 2.0 / 3, i2 + 2.0 / 3);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided\r\n * * The parameter `radius` sets the radius size (float) of the icosphere (default 1)\r\n * * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value of `radius`)\r\n * * The parameter `subdivisions` sets the number of subdivisions (positive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size\r\n * * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.radius\r\n * @param options.radiusX\r\n * @param options.radiusY\r\n * @param options.radiusZ\r\n * @param options.flat\r\n * @param options.subdivisions\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.updatable\r\n * @param scene defines the hosting scene\r\n * @returns the icosahedron mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra#icosphere\r\n */\r\nexport function CreateIcoSphere(\r\n name: string,\r\n options: {\r\n radius?: number;\r\n radiusX?: number;\r\n radiusY?: number;\r\n radiusZ?: number;\r\n flat?: boolean;\r\n subdivisions?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n } = {},\r\n scene: Nullable = null\r\n): Mesh {\r\n const sphere = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n sphere._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateIcoSphereVertexData(options);\r\n\r\n vertexData.applyToMesh(sphere, options.updatable);\r\n\r\n return sphere;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const IcoSphereBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateIcoSphere,\r\n};\r\n\r\nVertexData.CreateIcoSphere = CreateIcoSphereVertexData;\r\n\r\nMesh.CreateIcoSphere = (name: string, options: { radius?: number; flat?: boolean; subdivisions?: number; sideOrientation?: number; updatable?: boolean }, scene: Scene): Mesh => {\r\n return CreateIcoSphere(name, options, scene);\r\n};\r\n","import type { Nullable, IndicesArray, FloatArray } from \"../../types\";\r\nimport { Vector3, Matrix, Vector2, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { AbstractMesh } from \"../abstractMesh\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\nconst xpAxis = new Vector3(1, 0, 0);\r\nconst xnAxis = new Vector3(-1, 0, 0);\r\nconst ypAxis = new Vector3(0, 1, 0);\r\nconst ynAxis = new Vector3(0, -1, 0);\r\nconst zpAxis = new Vector3(0, 0, 1);\r\nconst znAxis = new Vector3(0, 0, -1);\r\n\r\n/** @internal */\r\nclass DecalVertex {\r\n constructor(\r\n public position: Vector3 = Vector3.Zero(),\r\n public normal: Vector3 = Vector3.Up(),\r\n public uv: Vector2 = Vector2.Zero(),\r\n public vertexIdx: number = 0,\r\n public vertexIdxForBones: number = 0,\r\n public localPositionOverride: Nullable = null,\r\n public localNormalOverride: Nullable = null,\r\n public matrixIndicesOverride: Nullable = null,\r\n public matrixWeightsOverride: Nullable = null\r\n ) {}\r\n public clone(): DecalVertex {\r\n return new DecalVertex(\r\n this.position.clone(),\r\n this.normal.clone(),\r\n this.uv.clone(),\r\n this.vertexIdx,\r\n this.vertexIdxForBones,\r\n this.localPositionOverride?.slice(),\r\n this.localNormalOverride?.slice(),\r\n this.matrixIndicesOverride?.slice(),\r\n this.matrixWeightsOverride?.slice()\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Creates a decal mesh.\r\n * A decal is a mesh usually applied as a model onto the surface of another mesh. So don't forget the parameter `sourceMesh` depicting the decal\r\n * * The parameter `position` (Vector3, default `(0, 0, 0)`) sets the position of the decal in World coordinates\r\n * * The parameter `normal` (Vector3, default `Vector3.Up`) sets the normal of the mesh where the decal is applied onto in World coordinates\r\n * * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling\r\n * * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal\r\n * * The parameter `captureUVS` defines if we need to capture the uvs or compute them\r\n * * The parameter `cullBackFaces` defines if the back faces should be removed from the decal mesh\r\n * * The parameter `localMode` defines that the computations should be done with the local mesh coordinates instead of the world space coordinates.\r\n * * Use this mode if you want the decal to be parented to the sourceMesh and move/rotate with it.\r\n * Note: Meshes with morph targets are not supported!\r\n * @param name defines the name of the mesh\r\n * @param sourceMesh defines the mesh where the decal must be applied\r\n * @param options defines the options used to create the mesh\r\n * @param options.position\r\n * @param options.normal\r\n * @param options.size\r\n * @param options.angle\r\n * @param options.captureUVS\r\n * @param options.cullBackFaces\r\n * @param options.localMode\r\n * @returns the decal mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/decals\r\n */\r\nexport function CreateDecal(\r\n name: string,\r\n sourceMesh: AbstractMesh,\r\n options: { position?: Vector3; normal?: Vector3; size?: Vector3; angle?: number; captureUVS?: boolean; cullBackFaces?: boolean; localMode?: boolean }\r\n): Mesh {\r\n const hasSkeleton = !!sourceMesh.skeleton;\r\n const useLocalComputation = options.localMode || hasSkeleton;\r\n const meshHasOverridenMaterial = (sourceMesh as Mesh).overrideMaterialSideOrientation !== null && (sourceMesh as Mesh).overrideMaterialSideOrientation !== undefined;\r\n\r\n const indices = sourceMesh.getIndices();\r\n const positions = hasSkeleton ? sourceMesh.getPositionData(true, true) : sourceMesh.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = hasSkeleton ? sourceMesh.getNormalsData(true, true) : sourceMesh.getVerticesData(VertexBuffer.NormalKind);\r\n const localPositions = useLocalComputation ? (hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.PositionKind) : positions) : null;\r\n const localNormals = useLocalComputation ? (hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.NormalKind) : normals) : null;\r\n const uvs = sourceMesh.getVerticesData(VertexBuffer.UVKind);\r\n const matIndices = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesIndicesKind) : null;\r\n const matWeights = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesWeightsKind) : null;\r\n const matIndicesExtra = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;\r\n const matWeightsExtra = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;\r\n\r\n const position = options.position || Vector3.Zero();\r\n let normal = options.normal || Vector3.Up();\r\n const size = options.size || Vector3.One();\r\n const angle = options.angle || 0;\r\n\r\n // Getting correct rotation\r\n if (!normal) {\r\n const target = new Vector3(0, 0, 1);\r\n const camera = sourceMesh.getScene().activeCamera;\r\n const cameraWorldTarget = Vector3.TransformCoordinates(target, camera.getWorldMatrix());\r\n\r\n normal = camera.globalPosition.subtract(cameraWorldTarget);\r\n }\r\n\r\n const yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;\r\n const len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);\r\n const pitch = Math.atan2(normal.y, len);\r\n\r\n const vertexData = new VertexData();\r\n vertexData.indices = [];\r\n vertexData.positions = [];\r\n vertexData.normals = [];\r\n vertexData.uvs = [];\r\n vertexData.matricesIndices = hasSkeleton ? [] : null;\r\n vertexData.matricesWeights = hasSkeleton ? [] : null;\r\n vertexData.matricesIndicesExtra = matIndicesExtra ? [] : null;\r\n vertexData.matricesWeightsExtra = matWeightsExtra ? [] : null;\r\n\r\n let currentVertexDataIndex = 0;\r\n\r\n const extractDecalVector3 = (indexId: number, transformMatrix: Matrix): DecalVertex => {\r\n const result = new DecalVertex();\r\n if (!indices || !positions || !normals) {\r\n return result;\r\n }\r\n\r\n const vertexId = indices[indexId];\r\n\r\n result.vertexIdx = vertexId * 3;\r\n result.vertexIdxForBones = vertexId * 4;\r\n\r\n // Send vector to decal local world\r\n result.position = new Vector3(positions[vertexId * 3], positions[vertexId * 3 + 1], positions[vertexId * 3 + 2]);\r\n Vector3.TransformCoordinatesToRef(result.position, transformMatrix, result.position);\r\n\r\n // Get normal\r\n result.normal = new Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);\r\n Vector3.TransformNormalToRef(result.normal, transformMatrix, result.normal);\r\n\r\n if (options.captureUVS && uvs) {\r\n const v = uvs[vertexId * 2 + 1];\r\n result.uv = new Vector2(uvs[vertexId * 2], CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n }\r\n\r\n return result;\r\n };\r\n\r\n const emptyArray = [0, 0, 0, 0];\r\n\r\n // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js\r\n const clip = (vertices: DecalVertex[], axis: Vector3): Nullable => {\r\n if (vertices.length === 0) {\r\n return vertices;\r\n }\r\n\r\n const clipSize = 0.5 * Math.abs(Vector3.Dot(size, axis));\r\n\r\n const indexOf = (arr: FloatArray | number[], val: number, start: number, num: number) => {\r\n for (let i = 0; i < num; ++i) {\r\n if (arr[start + i] === val) {\r\n return start + i;\r\n }\r\n }\r\n return -1;\r\n };\r\n\r\n const clipVertices = (v0: DecalVertex, v1: DecalVertex): DecalVertex => {\r\n const clipFactor = Vector3.GetClipFactor(v0.position, v1.position, axis, clipSize);\r\n\r\n let indices = emptyArray;\r\n let weights = emptyArray;\r\n\r\n if (matIndices && matWeights) {\r\n const mat0Index = v0.matrixIndicesOverride ? 0 : v0.vertexIdxForBones;\r\n const v0Indices = v0.matrixIndicesOverride ?? matIndices;\r\n const v0Weights = v0.matrixWeightsOverride ?? matWeights;\r\n\r\n const mat1Index = v1.matrixIndicesOverride ? 0 : v1.vertexIdxForBones;\r\n const v1Indices = v1.matrixIndicesOverride ?? matIndices;\r\n const v1Weights = v1.matrixWeightsOverride ?? matWeights;\r\n\r\n indices = [0, 0, 0, 0];\r\n weights = [0, 0, 0, 0];\r\n\r\n let index = 0;\r\n for (let i = 0; i < 4; ++i) {\r\n if (v0Weights[mat0Index + i] > 0) {\r\n const idx = indexOf(v1Indices, v0Indices[mat0Index + i], mat1Index, 4);\r\n indices[index] = v0Indices[mat0Index + i];\r\n weights[index] = Scalar.Lerp(v0Weights[mat0Index + i], idx >= 0 ? v1Weights[idx] : 0, clipFactor);\r\n index++;\r\n }\r\n }\r\n\r\n for (let i = 0; i < 4 && index < 4; ++i) {\r\n const ind = v1Indices[mat1Index + i];\r\n if (indexOf(v0Indices, ind, mat0Index, 4) !== -1) continue;\r\n\r\n indices[index] = ind;\r\n weights[index] = Scalar.Lerp(0, v1Weights[mat1Index + i], clipFactor);\r\n index++;\r\n }\r\n\r\n const sumw = weights[0] + weights[1] + weights[2] + weights[3];\r\n\r\n weights[0] /= sumw;\r\n weights[1] /= sumw;\r\n weights[2] /= sumw;\r\n weights[3] /= sumw;\r\n }\r\n\r\n const v0LocalPositionX = v0.localPositionOverride ? v0.localPositionOverride[0] : localPositions?.[v0.vertexIdx] ?? 0;\r\n const v0LocalPositionY = v0.localPositionOverride ? v0.localPositionOverride[1] : localPositions?.[v0.vertexIdx + 1] ?? 0;\r\n const v0LocalPositionZ = v0.localPositionOverride ? v0.localPositionOverride[2] : localPositions?.[v0.vertexIdx + 2] ?? 0;\r\n\r\n const v1LocalPositionX = v1.localPositionOverride ? v1.localPositionOverride[0] : localPositions?.[v1.vertexIdx] ?? 0;\r\n const v1LocalPositionY = v1.localPositionOverride ? v1.localPositionOverride[1] : localPositions?.[v1.vertexIdx + 1] ?? 0;\r\n const v1LocalPositionZ = v1.localPositionOverride ? v1.localPositionOverride[2] : localPositions?.[v1.vertexIdx + 2] ?? 0;\r\n\r\n const v0LocalNormalX = v0.localNormalOverride ? v0.localNormalOverride[0] : localNormals?.[v0.vertexIdx] ?? 0;\r\n const v0LocalNormalY = v0.localNormalOverride ? v0.localNormalOverride[1] : localNormals?.[v0.vertexIdx + 1] ?? 0;\r\n const v0LocalNormalZ = v0.localNormalOverride ? v0.localNormalOverride[2] : localNormals?.[v0.vertexIdx + 2] ?? 0;\r\n\r\n const v1LocalNormalX = v1.localNormalOverride ? v1.localNormalOverride[0] : localNormals?.[v1.vertexIdx] ?? 0;\r\n const v1LocalNormalY = v1.localNormalOverride ? v1.localNormalOverride[1] : localNormals?.[v1.vertexIdx + 1] ?? 0;\r\n const v1LocalNormalZ = v1.localNormalOverride ? v1.localNormalOverride[2] : localNormals?.[v1.vertexIdx + 2] ?? 0;\r\n\r\n const interpNormalX = v0LocalNormalX + (v1LocalNormalX - v0LocalNormalX) * clipFactor;\r\n const interpNormalY = v0LocalNormalY + (v1LocalNormalY - v0LocalNormalY) * clipFactor;\r\n const interpNormalZ = v0LocalNormalZ + (v1LocalNormalZ - v0LocalNormalZ) * clipFactor;\r\n\r\n const norm = Math.sqrt(interpNormalX * interpNormalX + interpNormalY * interpNormalY + interpNormalZ * interpNormalZ);\r\n\r\n return new DecalVertex(\r\n Vector3.Lerp(v0.position, v1.position, clipFactor),\r\n Vector3.Lerp(v0.normal, v1.normal, clipFactor).normalize(),\r\n Vector2.Lerp(v0.uv, v1.uv, clipFactor),\r\n -1,\r\n -1,\r\n localPositions\r\n ? [\r\n v0LocalPositionX + (v1LocalPositionX - v0LocalPositionX) * clipFactor,\r\n v0LocalPositionY + (v1LocalPositionY - v0LocalPositionY) * clipFactor,\r\n v0LocalPositionZ + (v1LocalPositionZ - v0LocalPositionZ) * clipFactor,\r\n ]\r\n : null,\r\n localNormals ? [interpNormalX / norm, interpNormalY / norm, interpNormalZ / norm] : null,\r\n indices,\r\n weights\r\n );\r\n };\r\n\r\n let clipResult: Nullable = null;\r\n\r\n if (vertices.length > 3) {\r\n clipResult = new Array();\r\n }\r\n\r\n for (let index = 0; index < vertices.length; index += 3) {\r\n let total = 0;\r\n let nV1: Nullable = null;\r\n let nV2: Nullable = null;\r\n let nV3: Nullable = null;\r\n let nV4: Nullable = null;\r\n\r\n const d1 = Vector3.Dot(vertices[index].position, axis) - clipSize;\r\n const d2 = Vector3.Dot(vertices[index + 1].position, axis) - clipSize;\r\n const d3 = Vector3.Dot(vertices[index + 2].position, axis) - clipSize;\r\n\r\n const v1Out = d1 > 0;\r\n const v2Out = d2 > 0;\r\n const v3Out = d3 > 0;\r\n\r\n total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);\r\n\r\n switch (total) {\r\n case 0:\r\n if (vertices.length > 3) {\r\n clipResult!.push(vertices[index]);\r\n clipResult!.push(vertices[index + 1]);\r\n clipResult!.push(vertices[index + 2]);\r\n } else {\r\n clipResult = vertices;\r\n }\r\n break;\r\n case 1:\r\n clipResult = clipResult ?? new Array();\r\n if (v1Out) {\r\n nV1 = vertices[index + 1];\r\n nV2 = vertices[index + 2];\r\n nV3 = clipVertices(vertices[index], nV1);\r\n nV4 = clipVertices(vertices[index], nV2);\r\n }\r\n\r\n if (v2Out) {\r\n nV1 = vertices[index];\r\n nV2 = vertices[index + 2];\r\n nV3 = clipVertices(vertices[index + 1], nV1);\r\n nV4 = clipVertices(vertices[index + 1], nV2);\r\n\r\n clipResult.push(nV3);\r\n clipResult.push(nV2.clone());\r\n clipResult.push(nV1.clone());\r\n\r\n clipResult.push(nV2.clone());\r\n clipResult.push(nV3.clone());\r\n clipResult.push(nV4);\r\n break;\r\n }\r\n if (v3Out) {\r\n nV1 = vertices[index];\r\n nV2 = vertices[index + 1];\r\n nV3 = clipVertices(vertices[index + 2], nV1);\r\n nV4 = clipVertices(vertices[index + 2], nV2);\r\n }\r\n\r\n if (nV1 && nV2 && nV3 && nV4) {\r\n clipResult.push(nV1.clone());\r\n clipResult.push(nV2.clone());\r\n clipResult.push(nV3);\r\n\r\n clipResult.push(nV4);\r\n clipResult.push(nV3.clone());\r\n clipResult.push(nV2.clone());\r\n }\r\n break;\r\n case 2:\r\n clipResult = clipResult ?? new Array();\r\n if (!v1Out) {\r\n nV1 = vertices[index].clone();\r\n nV2 = clipVertices(nV1, vertices[index + 1]);\r\n nV3 = clipVertices(nV1, vertices[index + 2]);\r\n clipResult.push(nV1);\r\n clipResult.push(nV2);\r\n clipResult.push(nV3);\r\n }\r\n if (!v2Out) {\r\n nV1 = vertices[index + 1].clone();\r\n nV2 = clipVertices(nV1, vertices[index + 2]);\r\n nV3 = clipVertices(nV1, vertices[index]);\r\n clipResult.push(nV1);\r\n clipResult.push(nV2);\r\n clipResult.push(nV3);\r\n }\r\n if (!v3Out) {\r\n nV1 = vertices[index + 2].clone();\r\n nV2 = clipVertices(nV1, vertices[index]);\r\n nV3 = clipVertices(nV1, vertices[index + 1]);\r\n clipResult.push(nV1);\r\n clipResult.push(nV2);\r\n clipResult.push(nV3);\r\n }\r\n break;\r\n case 3:\r\n break;\r\n }\r\n }\r\n\r\n return clipResult;\r\n };\r\n\r\n const sourceMeshAsMesh = sourceMesh instanceof Mesh ? sourceMesh : null;\r\n const matrixData = sourceMeshAsMesh?._thinInstanceDataStorage.matrixData;\r\n\r\n const numMatrices = sourceMeshAsMesh?.thinInstanceCount || 1;\r\n const thinInstanceMatrix = TmpVectors.Matrix[0];\r\n\r\n thinInstanceMatrix.copyFrom(Matrix.IdentityReadOnly);\r\n\r\n for (let m = 0; m < numMatrices; ++m) {\r\n if (sourceMeshAsMesh?.hasThinInstances && matrixData) {\r\n const ofst = m * 16;\r\n\r\n thinInstanceMatrix.setRowFromFloats(0, matrixData[ofst + 0], matrixData[ofst + 1], matrixData[ofst + 2], matrixData[ofst + 3]);\r\n thinInstanceMatrix.setRowFromFloats(1, matrixData[ofst + 4], matrixData[ofst + 5], matrixData[ofst + 6], matrixData[ofst + 7]);\r\n thinInstanceMatrix.setRowFromFloats(2, matrixData[ofst + 8], matrixData[ofst + 9], matrixData[ofst + 10], matrixData[ofst + 11]);\r\n thinInstanceMatrix.setRowFromFloats(3, matrixData[ofst + 12], matrixData[ofst + 13], matrixData[ofst + 14], matrixData[ofst + 15]);\r\n }\r\n\r\n // Matrix\r\n const decalWorldMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(Matrix.Translation(position.x, position.y, position.z));\r\n const inverseDecalWorldMatrix = Matrix.Invert(decalWorldMatrix);\r\n const meshWorldMatrix = sourceMesh.getWorldMatrix();\r\n const transformMatrix = thinInstanceMatrix.multiply(meshWorldMatrix).multiply(inverseDecalWorldMatrix);\r\n\r\n const oneFaceVertices = new Array(3);\r\n\r\n for (let index = 0; index < indices.length; index += 3) {\r\n let faceVertices: Nullable = oneFaceVertices;\r\n\r\n faceVertices[0] = extractDecalVector3(index, transformMatrix);\r\n if (meshHasOverridenMaterial && useLocalComputation) {\r\n faceVertices[1] = extractDecalVector3(index + 2, transformMatrix);\r\n faceVertices[2] = extractDecalVector3(index + 1, transformMatrix);\r\n } else {\r\n faceVertices[1] = extractDecalVector3(index + 1, transformMatrix);\r\n faceVertices[2] = extractDecalVector3(index + 2, transformMatrix);\r\n }\r\n\r\n if (options.cullBackFaces) {\r\n // If all the normals of the vertices of the face are pointing away from the view direction we discard the face.\r\n // As computations are done in the decal coordinate space, the viewDirection is (0,0,1), so when dot(vertexNormal, -viewDirection) <= 0 the vertex is culled\r\n if (-faceVertices[0].normal.z <= 0 && -faceVertices[1].normal.z <= 0 && -faceVertices[2].normal.z <= 0) {\r\n continue;\r\n }\r\n }\r\n\r\n // Clip\r\n faceVertices = clip(faceVertices, xpAxis);\r\n if (!faceVertices) continue;\r\n faceVertices = clip(faceVertices, xnAxis);\r\n if (!faceVertices) continue;\r\n faceVertices = clip(faceVertices, ypAxis);\r\n if (!faceVertices) continue;\r\n faceVertices = clip(faceVertices, ynAxis);\r\n if (!faceVertices) continue;\r\n faceVertices = clip(faceVertices, zpAxis);\r\n if (!faceVertices) continue;\r\n faceVertices = clip(faceVertices, znAxis);\r\n if (!faceVertices) continue;\r\n\r\n // Add UVs and get back to world\r\n for (let vIndex = 0; vIndex < faceVertices.length; vIndex++) {\r\n const vertex = faceVertices[vIndex];\r\n\r\n //TODO check for Int32Array | Uint32Array | Uint16Array\r\n (vertexData.indices).push(currentVertexDataIndex);\r\n if (useLocalComputation) {\r\n if (vertex.localPositionOverride) {\r\n vertexData.positions[currentVertexDataIndex * 3] = vertex.localPositionOverride[0];\r\n vertexData.positions[currentVertexDataIndex * 3 + 1] = vertex.localPositionOverride[1];\r\n vertexData.positions[currentVertexDataIndex * 3 + 2] = vertex.localPositionOverride[2];\r\n } else if (localPositions) {\r\n vertexData.positions[currentVertexDataIndex * 3] = localPositions[vertex.vertexIdx];\r\n vertexData.positions[currentVertexDataIndex * 3 + 1] = localPositions[vertex.vertexIdx + 1];\r\n vertexData.positions[currentVertexDataIndex * 3 + 2] = localPositions[vertex.vertexIdx + 2];\r\n }\r\n if (vertex.localNormalOverride) {\r\n vertexData.normals[currentVertexDataIndex * 3] = vertex.localNormalOverride[0];\r\n vertexData.normals[currentVertexDataIndex * 3 + 1] = vertex.localNormalOverride[1];\r\n vertexData.normals[currentVertexDataIndex * 3 + 2] = vertex.localNormalOverride[2];\r\n } else if (localNormals) {\r\n vertexData.normals[currentVertexDataIndex * 3] = localNormals[vertex.vertexIdx];\r\n vertexData.normals[currentVertexDataIndex * 3 + 1] = localNormals[vertex.vertexIdx + 1];\r\n vertexData.normals[currentVertexDataIndex * 3 + 2] = localNormals[vertex.vertexIdx + 2];\r\n }\r\n } else {\r\n vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);\r\n vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);\r\n }\r\n if (vertexData.matricesIndices && vertexData.matricesWeights) {\r\n if (vertex.matrixIndicesOverride) {\r\n vertexData.matricesIndices[currentVertexDataIndex * 4] = vertex.matrixIndicesOverride[0];\r\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 1] = vertex.matrixIndicesOverride[1];\r\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 2] = vertex.matrixIndicesOverride[2];\r\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 3] = vertex.matrixIndicesOverride[3];\r\n } else {\r\n if (matIndices) {\r\n vertexData.matricesIndices[currentVertexDataIndex * 4] = matIndices[vertex.vertexIdxForBones];\r\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 1] = matIndices[vertex.vertexIdxForBones + 1];\r\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 2] = matIndices[vertex.vertexIdxForBones + 2];\r\n vertexData.matricesIndices[currentVertexDataIndex * 4 + 3] = matIndices[vertex.vertexIdxForBones + 3];\r\n }\r\n if (matIndicesExtra && vertexData.matricesIndicesExtra) {\r\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4] = matIndicesExtra[vertex.vertexIdxForBones];\r\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 1] = matIndicesExtra[vertex.vertexIdxForBones + 1];\r\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 2] = matIndicesExtra[vertex.vertexIdxForBones + 2];\r\n vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 3] = matIndicesExtra[vertex.vertexIdxForBones + 3];\r\n }\r\n }\r\n if (vertex.matrixWeightsOverride) {\r\n vertexData.matricesWeights[currentVertexDataIndex * 4] = vertex.matrixWeightsOverride[0];\r\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 1] = vertex.matrixWeightsOverride[1];\r\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 2] = vertex.matrixWeightsOverride[2];\r\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 3] = vertex.matrixWeightsOverride[3];\r\n } else {\r\n if (matWeights) {\r\n vertexData.matricesWeights[currentVertexDataIndex * 4] = matWeights[vertex.vertexIdxForBones];\r\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 1] = matWeights[vertex.vertexIdxForBones + 1];\r\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 2] = matWeights[vertex.vertexIdxForBones + 2];\r\n vertexData.matricesWeights[currentVertexDataIndex * 4 + 3] = matWeights[vertex.vertexIdxForBones + 3];\r\n }\r\n if (matWeightsExtra && vertexData.matricesWeightsExtra) {\r\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4] = matWeightsExtra[vertex.vertexIdxForBones];\r\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 1] = matWeightsExtra[vertex.vertexIdxForBones + 1];\r\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 2] = matWeightsExtra[vertex.vertexIdxForBones + 2];\r\n vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 3] = matWeightsExtra[vertex.vertexIdxForBones + 3];\r\n }\r\n }\r\n }\r\n\r\n if (!options.captureUVS) {\r\n (vertexData.uvs).push(0.5 + vertex.position.x / size.x);\r\n const v = 0.5 + vertex.position.y / size.y;\r\n (vertexData.uvs).push(CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);\r\n } else {\r\n vertex.uv.toArray(vertexData.uvs, currentVertexDataIndex * 2);\r\n }\r\n currentVertexDataIndex++;\r\n }\r\n }\r\n }\r\n\r\n // Avoid the \"Setting vertex data kind 'XXX' with an empty array\" warning when calling vertexData.applyToMesh\r\n if (vertexData.indices.length === 0) vertexData.indices = null;\r\n if (vertexData.positions.length === 0) vertexData.positions = null;\r\n if (vertexData.normals.length === 0) vertexData.normals = null;\r\n if (vertexData.uvs.length === 0) vertexData.uvs = null;\r\n if (vertexData.matricesIndices?.length === 0) vertexData.matricesIndices = null;\r\n if (vertexData.matricesWeights?.length === 0) vertexData.matricesWeights = null;\r\n if (vertexData.matricesIndicesExtra?.length === 0) vertexData.matricesIndicesExtra = null;\r\n if (vertexData.matricesWeightsExtra?.length === 0) vertexData.matricesWeightsExtra = null;\r\n\r\n // Return mesh\r\n const decal = new Mesh(name, sourceMesh.getScene());\r\n vertexData.applyToMesh(decal);\r\n\r\n if (useLocalComputation) {\r\n decal.skeleton = sourceMesh.skeleton;\r\n decal.parent = sourceMesh;\r\n } else {\r\n decal.position = position.clone();\r\n decal.rotation = new Vector3(pitch, yaw, angle);\r\n }\r\n\r\n decal.computeWorldMatrix(true);\r\n decal.refreshBoundingInfo(true, true);\r\n\r\n return decal;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const DecalBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateDecal,\r\n};\r\n\r\nMesh.CreateDecal = (name: string, sourceMesh: AbstractMesh, position: Vector3, normal: Vector3, size: Vector3, angle: number): Mesh => {\r\n const options = {\r\n position,\r\n normal,\r\n size,\r\n angle,\r\n };\r\n\r\n return CreateDecal(name, sourceMesh, options);\r\n};\r\n","import { VertexData } from \"../mesh.vertexData\";\r\nimport { Vector2, Vector3, Matrix } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n/**\r\n * Scripts based off of https://github.com/maximeq/three-js-capsule-geometry/blob/master/src/CapsuleBufferGeometry.js\r\n * @param options the constructors options used to shape the mesh.\r\n * @returns the capsule VertexData\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/capsule\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function CreateCapsuleVertexData(\r\n options: ICreateCapsuleOptions = {\r\n subdivisions: 2,\r\n tessellation: 16,\r\n height: 1,\r\n radius: 0.25,\r\n capSubdivisions: 6,\r\n }\r\n): VertexData {\r\n const subdivisions = Math.max(options.subdivisions ? options.subdivisions : 2, 1) | 0;\r\n const tessellation = Math.max(options.tessellation ? options.tessellation : 16, 3) | 0;\r\n const height = Math.max(options.height ? options.height : 1, 0);\r\n const radius = Math.max(options.radius ? options.radius : 0.25, 0);\r\n const capDetail = Math.max(options.capSubdivisions ? options.capSubdivisions : 6, 1) | 0;\r\n\r\n const radialSegments = tessellation;\r\n const heightSegments = subdivisions;\r\n\r\n const radiusTop = Math.max(options.radiusTop ? options.radiusTop : radius, 0);\r\n const radiusBottom = Math.max(options.radiusBottom ? options.radiusBottom : radius, 0);\r\n\r\n const heightMinusCaps = height - (radiusTop + radiusBottom);\r\n\r\n const thetaStart = 0.0;\r\n const thetaLength = 2.0 * Math.PI;\r\n\r\n const capsTopSegments = Math.max(options.topCapSubdivisions ? options.topCapSubdivisions : capDetail, 1);\r\n const capsBottomSegments = Math.max(options.bottomCapSubdivisions ? options.bottomCapSubdivisions : capDetail, 1);\r\n\r\n const alpha = Math.acos((radiusBottom - radiusTop) / height);\r\n\r\n let indices = [];\r\n const vertices = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n let index = 0;\r\n const indexArray = [],\r\n halfHeight = heightMinusCaps * 0.5;\r\n const pi2 = Math.PI * 0.5;\r\n\r\n let x, y;\r\n const normal = Vector3.Zero();\r\n const vertex = Vector3.Zero();\r\n\r\n const cosAlpha = Math.cos(alpha);\r\n const sinAlpha = Math.sin(alpha);\r\n\r\n const coneLength = new Vector2(radiusTop * sinAlpha, halfHeight + radiusTop * cosAlpha)\r\n .subtract(new Vector2(radiusBottom * sinAlpha, -halfHeight + radiusBottom * cosAlpha))\r\n .length();\r\n\r\n // Total length for v texture coord\r\n const vl = radiusTop * alpha + coneLength + radiusBottom * (pi2 - alpha);\r\n\r\n let v = 0;\r\n for (y = 0; y <= capsTopSegments; y++) {\r\n const indexRow = [];\r\n\r\n const a = pi2 - alpha * (y / capsTopSegments);\r\n\r\n v += (radiusTop * alpha) / capsTopSegments;\r\n\r\n const cosA = Math.cos(a);\r\n const sinA = Math.sin(a);\r\n\r\n // calculate the radius of the current row\r\n const _radius = cosA * radiusTop;\r\n\r\n for (x = 0; x <= radialSegments; x++) {\r\n const u = x / radialSegments;\r\n const theta = u * thetaLength + thetaStart;\r\n const sinTheta = Math.sin(theta);\r\n const cosTheta = Math.cos(theta);\r\n // vertex\r\n vertex.x = _radius * sinTheta;\r\n vertex.y = halfHeight + sinA * radiusTop;\r\n vertex.z = _radius * cosTheta;\r\n vertices.push(vertex.x, vertex.y, vertex.z);\r\n // normal\r\n normal.set(cosA * sinTheta, sinA, cosA * cosTheta);\r\n normals.push(normal.x, normal.y, normal.z);\r\n // uv\r\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? v / vl : 1 - v / vl);\r\n // save index of vertex in respective row\r\n indexRow.push(index);\r\n // increase index\r\n index++;\r\n }\r\n // now save vertices of the row in our index array\r\n indexArray.push(indexRow);\r\n }\r\n\r\n const coneHeight = height - radiusTop - radiusBottom + cosAlpha * radiusTop - cosAlpha * radiusBottom;\r\n const slope = (sinAlpha * (radiusBottom - radiusTop)) / coneHeight;\r\n\r\n for (y = 1; y <= heightSegments; y++) {\r\n const indexRow = [];\r\n v += coneLength / heightSegments;\r\n // calculate the radius of the current row\r\n const _radius = sinAlpha * ((y * (radiusBottom - radiusTop)) / heightSegments + radiusTop);\r\n for (x = 0; x <= radialSegments; x++) {\r\n const u = x / radialSegments;\r\n const theta = u * thetaLength + thetaStart;\r\n const sinTheta = Math.sin(theta);\r\n const cosTheta = Math.cos(theta);\r\n // vertex\r\n vertex.x = _radius * sinTheta;\r\n vertex.y = halfHeight + cosAlpha * radiusTop - (y * coneHeight) / heightSegments;\r\n vertex.z = _radius * cosTheta;\r\n vertices.push(vertex.x, vertex.y, vertex.z);\r\n // normal\r\n normal.set(sinTheta, slope, cosTheta).normalize();\r\n normals.push(normal.x, normal.y, normal.z);\r\n // uv\r\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? v / vl : 1 - v / vl);\r\n // save index of vertex in respective row\r\n indexRow.push(index);\r\n // increase index\r\n index++;\r\n }\r\n // now save vertices of the row in our index array\r\n indexArray.push(indexRow);\r\n }\r\n\r\n for (y = 1; y <= capsBottomSegments; y++) {\r\n const indexRow = [];\r\n const a = pi2 - alpha - (Math.PI - alpha) * (y / capsBottomSegments);\r\n v += (radiusBottom * alpha) / capsBottomSegments;\r\n const cosA = Math.cos(a);\r\n const sinA = Math.sin(a);\r\n // calculate the radius of the current row\r\n const _radius = cosA * radiusBottom;\r\n for (x = 0; x <= radialSegments; x++) {\r\n const u = x / radialSegments;\r\n const theta = u * thetaLength + thetaStart;\r\n const sinTheta = Math.sin(theta);\r\n const cosTheta = Math.cos(theta);\r\n // vertex\r\n vertex.x = _radius * sinTheta;\r\n vertex.y = -halfHeight + sinA * radiusBottom;\r\n vertex.z = _radius * cosTheta;\r\n vertices.push(vertex.x, vertex.y, vertex.z);\r\n // normal\r\n normal.set(cosA * sinTheta, sinA, cosA * cosTheta);\r\n normals.push(normal.x, normal.y, normal.z);\r\n // uv\r\n uvs.push(u, CompatibilityOptions.UseOpenGLOrientationForUV ? v / vl : 1 - v / vl);\r\n // save index of vertex in respective row\r\n indexRow.push(index);\r\n // increase index\r\n index++;\r\n }\r\n // now save vertices of the row in our index array\r\n indexArray.push(indexRow);\r\n }\r\n // generate indices\r\n for (x = 0; x < radialSegments; x++) {\r\n for (y = 0; y < capsTopSegments + heightSegments + capsBottomSegments; y++) {\r\n // we use the index array to access the correct indices\r\n const i1 = indexArray[y][x];\r\n const i2 = indexArray[y + 1][x];\r\n const i3 = indexArray[y + 1][x + 1];\r\n const i4 = indexArray[y][x + 1];\r\n // face one\r\n indices.push(i1);\r\n indices.push(i2);\r\n indices.push(i4);\r\n // face two\r\n indices.push(i2);\r\n indices.push(i3);\r\n indices.push(i4);\r\n }\r\n }\r\n\r\n indices = indices.reverse();\r\n\r\n if (options.orientation && !options.orientation.equals(Vector3.Up())) {\r\n const m = new Matrix();\r\n options.orientation\r\n .clone()\r\n .scale(Math.PI * 0.5)\r\n .cross(Vector3.Up())\r\n .toQuaternion()\r\n .toRotationMatrix(m);\r\n const v = Vector3.Zero();\r\n for (let i = 0; i < vertices.length; i += 3) {\r\n v.set(vertices[i], vertices[i + 1], vertices[i + 2]);\r\n Vector3.TransformCoordinatesToRef(v.clone(), m, v);\r\n vertices[i] = v.x;\r\n vertices[i + 1] = v.y;\r\n vertices[i + 2] = v.z;\r\n }\r\n }\r\n\r\n const vDat = new VertexData();\r\n vDat.positions = vertices;\r\n vDat.normals = normals;\r\n vDat.uvs = uvs;\r\n vDat.indices = indices;\r\n\r\n return vDat;\r\n}\r\n\r\n/**\r\n * The options Interface for creating a Capsule Mesh\r\n */\r\nexport interface ICreateCapsuleOptions {\r\n /** The Orientation of the capsule. Default : Vector3.Up() */\r\n orientation?: Vector3;\r\n\r\n /** Number of sub segments on the tube section of the capsule running parallel to orientation. */\r\n subdivisions?: number;\r\n\r\n /** Number of cylindrical segments on the capsule. */\r\n tessellation?: number;\r\n\r\n /** Height or Length of the capsule. */\r\n height?: number;\r\n\r\n /** Radius of the capsule. */\r\n radius?: number;\r\n\r\n /** Number of sub segments on the cap sections of the capsule running parallel to orientation. */\r\n capSubdivisions?: number;\r\n\r\n /** Overwrite for the top radius. */\r\n radiusTop?: number;\r\n\r\n /** Overwrite for the bottom radius. */\r\n radiusBottom?: number;\r\n\r\n /** Overwrite for the top capSubdivisions. */\r\n topCapSubdivisions?: number;\r\n\r\n /** Overwrite for the bottom capSubdivisions. */\r\n bottomCapSubdivisions?: number;\r\n\r\n /** Internal geometry is supposed to change once created. */\r\n updatable?: boolean;\r\n}\r\n\r\n/**\r\n * Creates a capsule or a pill mesh\r\n * @param name defines the name of the mesh\r\n * @param options The constructors options.\r\n * @param scene The scene the mesh is scoped to.\r\n * @returns Capsule Mesh\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function CreateCapsule(\r\n name: string,\r\n options: ICreateCapsuleOptions = {\r\n orientation: Vector3.Up(),\r\n subdivisions: 2,\r\n tessellation: 16,\r\n height: 1,\r\n radius: 0.25,\r\n capSubdivisions: 6,\r\n updatable: false,\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const capsule = new Mesh(name, scene);\r\n const vertexData = CreateCapsuleVertexData(options);\r\n vertexData.applyToMesh(capsule, options.updatable);\r\n return capsule;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated please use CreateCapsule directly\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport const CapsuleBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateCapsule,\r\n};\r\n\r\n/**\r\n * Creates a capsule or a pill mesh\r\n * @param name defines the name of the mesh.\r\n * @param options the constructors options used to shape the mesh.\r\n * @param scene defines the scene the mesh is scoped to.\r\n * @returns the capsule mesh\r\n * @see https://doc.babylonjs.com/how_to/capsule_shape\r\n */\r\nMesh.CreateCapsule = (name: string, options: ICreateCapsuleOptions, scene?: Nullable): Mesh => {\r\n return CreateCapsule(name, options, scene);\r\n};\r\n\r\nVertexData.CreateCapsule = CreateCapsuleVertexData;\r\n","import { Logger } from \"../Misc/logger\";\r\nimport { Vector3 } from \"./math.vector\";\r\n\r\n/**\r\n * Class representing an isovector a vector containing 2 INTEGER coordinates\r\n * x axis is horizontal\r\n * y axis is 60 deg counter clockwise from positive y axis\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _IsoVector {\r\n /**\r\n * Creates a new isovector from the given x and y coordinates\r\n * @param x defines the first coordinate, must be an integer\r\n * @param y defines the second coordinate, must be an integer\r\n */\r\n constructor(\r\n /** defines the first coordinate */\r\n public x: number = 0,\r\n /** defines the second coordinate */\r\n public y: number = 0\r\n ) {\r\n if (x !== Math.floor(x)) {\r\n x === Math.floor(x);\r\n Logger.Warn(\"x is not an integer, floor(x) used\");\r\n }\r\n if (y !== Math.floor(y)) {\r\n y === Math.floor(y);\r\n Logger.Warn(\"y is not an integer, floor(y) used\");\r\n }\r\n }\r\n\r\n // Operators\r\n\r\n /**\r\n * Gets a new IsoVector copied from the IsoVector\r\n * @returns a new IsoVector\r\n */\r\n public clone(): _IsoVector {\r\n return new _IsoVector(this.x, this.y);\r\n }\r\n\r\n /**\r\n * Rotates one IsoVector 60 degrees counter clockwise about another\r\n * Please note that this is an in place operation\r\n * @param other an IsoVector a center of rotation\r\n * @returns the rotated IsoVector\r\n */\r\n public rotate60About(other: _IsoVector) {\r\n //other IsoVector\r\n const x: number = this.x;\r\n this.x = other.x + other.y - this.y;\r\n this.y = x + this.y - other.x;\r\n return this;\r\n }\r\n\r\n /**\r\n * Rotates one IsoVector 60 degrees clockwise about another\r\n * Please note that this is an in place operation\r\n * @param other an IsoVector as center of rotation\r\n * @returns the rotated IsoVector\r\n */\r\n public rotateNeg60About(other: _IsoVector) {\r\n const x = this.x;\r\n this.x = x + this.y - other.y;\r\n this.y = other.x + other.y - x;\r\n return this;\r\n }\r\n\r\n /**\r\n * For an equilateral triangle OAB with O at isovector (0, 0) and A at isovector (m, n)\r\n * Rotates one IsoVector 120 degrees counter clockwise about the center of the triangle\r\n * Please note that this is an in place operation\r\n * @param m integer a measure a Primary triangle of order (m, n) m > n\r\n * @param n >= 0 integer a measure for a Primary triangle of order (m, n)\r\n * @returns the rotated IsoVector\r\n */\r\n public rotate120(m: number, n: number) {\r\n //m, n integers\r\n if (m !== Math.floor(m)) {\r\n m === Math.floor(m);\r\n Logger.Warn(\"m not an integer only floor(m) used\");\r\n }\r\n if (n !== Math.floor(n)) {\r\n n === Math.floor(n);\r\n Logger.Warn(\"n not an integer only floor(n) used\");\r\n }\r\n const x = this.x;\r\n this.x = m - x - this.y;\r\n this.y = n + x;\r\n return this;\r\n }\r\n\r\n /**\r\n * For an equilateral triangle OAB with O at isovector (0, 0) and A at isovector (m, n)\r\n * Rotates one IsoVector 120 degrees clockwise about the center of the triangle\r\n * Please note that this is an in place operation\r\n * @param m integer a measure a Primary triangle of order (m, n) m > n\r\n * @param n >= 0 integer a measure for a Primary triangle of order (m, n)\r\n * @returns the rotated IsoVector\r\n */\r\n public rotateNeg120(m: number, n: number) {\r\n //m, n integers\r\n if (m !== Math.floor(m)) {\r\n m === Math.floor(m);\r\n Logger.Warn(\"m is not an integer, floor(m) used\");\r\n }\r\n if (n !== Math.floor(n)) {\r\n n === Math.floor(n);\r\n Logger.Warn(\"n is not an integer, floor(n) used\");\r\n }\r\n const x = this.x;\r\n this.x = this.y - n;\r\n this.y = m + n - x - this.y;\r\n return this;\r\n }\r\n\r\n /**\r\n * Transforms an IsoVector to one in Cartesian 3D space based on an isovector\r\n * @param origin an IsoVector\r\n * @param isoGridSize\r\n * @returns Point as a Vector3\r\n */\r\n public toCartesianOrigin(origin: _IsoVector, isoGridSize: number) {\r\n const point = Vector3.Zero();\r\n point.x = origin.x + 2 * this.x * isoGridSize + this.y * isoGridSize;\r\n point.y = origin.y + Math.sqrt(3) * this.y * isoGridSize;\r\n return point;\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Gets a new IsoVector(0, 0)\r\n * @returns a new IsoVector\r\n */\r\n public static Zero(): _IsoVector {\r\n return new _IsoVector(0, 0);\r\n }\r\n}\r\n","import { Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { PHI } from \"../Maths/math.constants\";\r\nimport { _IsoVector } from \"../Maths/math.isovector\";\r\n\r\n/**\r\n * Class representing data for one face OAB of an equilateral icosahedron\r\n * When O is the isovector (0, 0), A is isovector (m, n)\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _PrimaryIsoTriangle {\r\n //properties\r\n public m: number;\r\n public n: number;\r\n public cartesian: Vector3[] = [];\r\n public vertices: _IsoVector[] = [];\r\n public max: number[] = [];\r\n public min: number[] = [];\r\n public vecToidx: { [key: string]: number };\r\n public vertByDist: { [key: string]: number[] };\r\n public closestTo: number[][] = [];\r\n\r\n public innerFacets: string[][] = [];\r\n public isoVecsABOB: _IsoVector[][] = [];\r\n public isoVecsOBOA: _IsoVector[][] = [];\r\n public isoVecsBAOA: _IsoVector[][] = [];\r\n public vertexTypes: number[][] = [];\r\n\r\n public coau: number;\r\n public cobu: number;\r\n public coav: number;\r\n public cobv: number;\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public IDATA: PolyhedronData = new PolyhedronData(\r\n \"icosahedron\",\r\n \"Regular\",\r\n [\r\n [0, PHI, -1],\r\n [-PHI, 1, 0],\r\n [-1, 0, -PHI],\r\n [1, 0, -PHI],\r\n [PHI, 1, 0],\r\n [0, PHI, 1],\r\n [-1, 0, PHI],\r\n [-PHI, -1, 0],\r\n [0, -PHI, -1],\r\n [PHI, -1, 0],\r\n [1, 0, PHI],\r\n [0, -PHI, 1],\r\n ],\r\n [\r\n [0, 2, 1],\r\n [0, 3, 2],\r\n [0, 4, 3],\r\n [0, 5, 4],\r\n [0, 1, 5],\r\n [7, 6, 1],\r\n [8, 7, 2],\r\n [9, 8, 3],\r\n [10, 9, 4],\r\n [6, 10, 5],\r\n [2, 7, 1],\r\n [3, 8, 2],\r\n [4, 9, 3],\r\n [5, 10, 4],\r\n [1, 6, 5],\r\n [11, 6, 7],\r\n [11, 7, 8],\r\n [11, 8, 9],\r\n [11, 9, 10],\r\n [11, 10, 6],\r\n ]\r\n );\r\n\r\n /**\r\n * Creates the PrimaryIsoTriangle Triangle OAB\r\n * @param m an integer\r\n * @param n an integer\r\n */\r\n\r\n //operators\r\n public setIndices() {\r\n let indexCount = 12; // 12 vertices already assigned\r\n const vecToidx: { [key: string]: number } = {}; //maps iso-vectors to indexCount;\r\n const m = this.m;\r\n const n = this.n;\r\n let g = m; // hcf of m, n when n != 0\r\n let m1 = 1;\r\n let n1 = 0;\r\n if (n !== 0) {\r\n g = Scalar.HCF(m, n);\r\n }\r\n m1 = m / g;\r\n n1 = n / g;\r\n\r\n let fr: number | string; //face to the right of current face\r\n let rot: number | string; //rotation about which vertex for fr\r\n let O: number;\r\n let A: number;\r\n let B: number;\r\n const oVec: _IsoVector = _IsoVector.Zero();\r\n const aVec = new _IsoVector(m, n);\r\n const bVec = new _IsoVector(-n, m + n);\r\n const oaVec: _IsoVector = _IsoVector.Zero();\r\n const abVec: _IsoVector = _IsoVector.Zero();\r\n const obVec: _IsoVector = _IsoVector.Zero();\r\n let verts: number[] = [];\r\n let idx: string;\r\n let idxR: string;\r\n let isoId: string;\r\n let isoIdR: string;\r\n\r\n const closestTo: number[][] = [];\r\n const vDist = this.vertByDist;\r\n\r\n const matchIdx = (f: number, fr: number, isoId: string, isoIdR: string) => {\r\n idx = f + \"|\" + isoId;\r\n idxR = fr + \"|\" + isoIdR;\r\n if (!(idx in vecToidx || idxR in vecToidx)) {\r\n vecToidx[idx] = indexCount;\r\n vecToidx[idxR] = indexCount;\r\n indexCount++;\r\n } else if (idx in vecToidx && !(idxR in vecToidx)) {\r\n vecToidx[idxR] = vecToidx[idx];\r\n } else if (idxR in vecToidx && !(idx in vecToidx)) {\r\n vecToidx[idx] = vecToidx[idxR];\r\n }\r\n if (vDist[isoId][0] > 2) {\r\n closestTo[vecToidx[idx]] = [-vDist[isoId][0], vDist[isoId][1], vecToidx[idx]];\r\n } else {\r\n closestTo[vecToidx[idx]] = [verts[vDist[isoId][0]], vDist[isoId][1], vecToidx[idx]];\r\n }\r\n };\r\n\r\n this.IDATA.edgematch = [\r\n [1, \"B\"],\r\n [2, \"B\"],\r\n [3, \"B\"],\r\n [4, \"B\"],\r\n [0, \"B\"],\r\n [10, \"O\", 14, \"A\"],\r\n [11, \"O\", 10, \"A\"],\r\n [12, \"O\", 11, \"A\"],\r\n [13, \"O\", 12, \"A\"],\r\n [14, \"O\", 13, \"A\"],\r\n [0, \"O\"],\r\n [1, \"O\"],\r\n [2, \"O\"],\r\n [3, \"O\"],\r\n [4, \"O\"],\r\n [19, \"B\", 5, \"A\"],\r\n [15, \"B\", 6, \"A\"],\r\n [16, \"B\", 7, \"A\"],\r\n [17, \"B\", 8, \"A\"],\r\n [18, \"B\", 9, \"A\"],\r\n ];\r\n\r\n /***edges AB to OB***** rotation about B*/\r\n for (let f = 0; f < 20; f++) {\r\n //f current face\r\n\r\n verts = this.IDATA.face[f];\r\n O = verts[2];\r\n A = verts[1];\r\n B = verts[0];\r\n\r\n isoId = oVec.x + \"|\" + oVec.y;\r\n idx = f + \"|\" + isoId;\r\n if (!(idx in vecToidx)) {\r\n vecToidx[idx] = O;\r\n closestTo[O] = [verts[vDist[isoId][0]], vDist[isoId][1]];\r\n }\r\n\r\n isoId = aVec.x + \"|\" + aVec.y;\r\n idx = f + \"|\" + isoId;\r\n if (!(idx in vecToidx)) {\r\n vecToidx[idx] = A;\r\n closestTo[A] = [verts[vDist[isoId][0]], vDist[isoId][1]];\r\n }\r\n\r\n isoId = bVec.x + \"|\" + bVec.y;\r\n idx = f + \"|\" + isoId;\r\n if (!(idx in vecToidx)) {\r\n vecToidx[idx] = B;\r\n closestTo[B] = [verts[vDist[isoId][0]], vDist[isoId][1]];\r\n }\r\n\r\n //for edge vertices\r\n fr = this.IDATA.edgematch[f][0];\r\n rot = this.IDATA.edgematch[f][1];\r\n if (rot === \"B\") {\r\n for (let i = 1; i < g; i++) {\r\n abVec.x = m - i * (m1 + n1);\r\n abVec.y = n + i * m1;\r\n obVec.x = -i * n1;\r\n obVec.y = i * (m1 + n1);\r\n isoId = abVec.x + \"|\" + abVec.y;\r\n isoIdR = obVec.x + \"|\" + obVec.y;\r\n matchIdx(f, fr, isoId, isoIdR);\r\n }\r\n }\r\n\r\n if (rot === \"O\") {\r\n for (let i = 1; i < g; i++) {\r\n obVec.x = -i * n1;\r\n obVec.y = i * (m1 + n1);\r\n oaVec.x = i * m1;\r\n oaVec.y = i * n1;\r\n isoId = obVec.x + \"|\" + obVec.y;\r\n isoIdR = oaVec.x + \"|\" + oaVec.y;\r\n matchIdx(f, fr, isoId, isoIdR);\r\n }\r\n }\r\n\r\n fr = this.IDATA.edgematch[f][2];\r\n rot = this.IDATA.edgematch[f][3];\r\n if (rot && rot === \"A\") {\r\n for (let i = 1; i < g; i++) {\r\n oaVec.x = i * m1;\r\n oaVec.y = i * n1;\r\n abVec.x = m - (g - i) * (m1 + n1); //reversed for BA\r\n abVec.y = n + (g - i) * m1; //reversed for BA\r\n isoId = oaVec.x + \"|\" + oaVec.y;\r\n isoIdR = abVec.x + \"|\" + abVec.y;\r\n matchIdx(f, fr, isoId, isoIdR);\r\n }\r\n }\r\n\r\n for (let i = 0; i < this.vertices.length; i++) {\r\n isoId = this.vertices[i].x + \"|\" + this.vertices[i].y;\r\n idx = f + \"|\" + isoId;\r\n if (!(idx in vecToidx)) {\r\n vecToidx[idx] = indexCount++;\r\n if (vDist[isoId][0] > 2) {\r\n closestTo[vecToidx[idx]] = [-vDist[isoId][0], vDist[isoId][1], vecToidx[idx]];\r\n } else {\r\n closestTo[vecToidx[idx]] = [verts[vDist[isoId][0]], vDist[isoId][1], vecToidx[idx]];\r\n }\r\n }\r\n }\r\n }\r\n\r\n this.closestTo = closestTo;\r\n this.vecToidx = vecToidx;\r\n }\r\n\r\n public calcCoeffs() {\r\n const m = this.m;\r\n const n = this.n;\r\n const thirdR3 = Math.sqrt(3) / 3;\r\n\r\n const LSQD = m * m + n * n + m * n;\r\n\r\n this.coau = (m + n) / LSQD;\r\n this.cobu = -n / LSQD;\r\n this.coav = (-thirdR3 * (m - n)) / LSQD;\r\n this.cobv = (thirdR3 * (2 * m + n)) / LSQD;\r\n }\r\n\r\n public createInnerFacets() {\r\n const m = this.m;\r\n const n = this.n;\r\n for (let y = 0; y < n + m + 1; y++) {\r\n for (let x = this.min[y]; x < this.max[y] + 1; x++) {\r\n if (x < this.max[y] && x < this.max[y + 1] + 1) {\r\n this.innerFacets.push([\"|\" + x + \"|\" + y, \"|\" + x + \"|\" + (y + 1), \"|\" + (x + 1) + \"|\" + y]);\r\n }\r\n if (y > 0 && x < this.max[y - 1] && x + 1 < this.max[y] + 1) {\r\n this.innerFacets.push([\"|\" + x + \"|\" + y, \"|\" + (x + 1) + \"|\" + y, \"|\" + (x + 1) + \"|\" + (y - 1)]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public edgeVecsABOB() {\r\n const m = this.m;\r\n const n = this.n;\r\n\r\n const B = new _IsoVector(-n, m + n);\r\n\r\n for (let y = 1; y < m + n; y++) {\r\n const point = new _IsoVector(this.min[y], y);\r\n const prev = new _IsoVector(this.min[y - 1], y - 1);\r\n const next = new _IsoVector(this.min[y + 1], y + 1);\r\n const pointR = point.clone();\r\n const prevR = prev.clone();\r\n const nextR = next.clone();\r\n\r\n pointR.rotate60About(B);\r\n prevR.rotate60About(B);\r\n nextR.rotate60About(B);\r\n\r\n const maxPoint = new _IsoVector(this.max[pointR.y], pointR.y);\r\n const maxPrev = new _IsoVector(this.max[pointR.y - 1], pointR.y - 1);\r\n const maxLeftPrev = new _IsoVector(this.max[pointR.y - 1] - 1, pointR.y - 1);\r\n\r\n if (pointR.x !== maxPoint.x || pointR.y !== maxPoint.y) {\r\n if (pointR.x !== maxPrev.x) {\r\n // type2\r\n //up\r\n this.vertexTypes.push([1, 0, 0]);\r\n this.isoVecsABOB.push([point, maxPrev, maxLeftPrev]);\r\n //down\r\n this.vertexTypes.push([1, 0, 0]);\r\n this.isoVecsABOB.push([point, maxLeftPrev, maxPoint]);\r\n } else if (pointR.y === nextR.y) {\r\n // type1\r\n //up\r\n this.vertexTypes.push([1, 1, 0]);\r\n this.isoVecsABOB.push([point, prev, maxPrev]);\r\n //down\r\n this.vertexTypes.push([1, 0, 1]);\r\n this.isoVecsABOB.push([point, maxPrev, next]);\r\n } else {\r\n // type 0\r\n //up\r\n this.vertexTypes.push([1, 1, 0]);\r\n this.isoVecsABOB.push([point, prev, maxPrev]);\r\n //down\r\n this.vertexTypes.push([1, 0, 0]);\r\n this.isoVecsABOB.push([point, maxPrev, maxPoint]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public mapABOBtoOBOA() {\r\n const point = new _IsoVector(0, 0);\r\n for (let i = 0; i < this.isoVecsABOB.length; i++) {\r\n const temp = [];\r\n for (let j = 0; j < 3; j++) {\r\n point.x = this.isoVecsABOB[i][j].x;\r\n point.y = this.isoVecsABOB[i][j].y;\r\n if (this.vertexTypes[i][j] === 0) {\r\n point.rotateNeg120(this.m, this.n);\r\n }\r\n temp.push(point.clone());\r\n }\r\n this.isoVecsOBOA.push(temp);\r\n }\r\n }\r\n\r\n public mapABOBtoBAOA() {\r\n const point = new _IsoVector(0, 0);\r\n for (let i = 0; i < this.isoVecsABOB.length; i++) {\r\n const temp = [];\r\n for (let j = 0; j < 3; j++) {\r\n point.x = this.isoVecsABOB[i][j].x;\r\n point.y = this.isoVecsABOB[i][j].y;\r\n if (this.vertexTypes[i][j] === 1) {\r\n point.rotate120(this.m, this.n);\r\n }\r\n temp.push(point.clone());\r\n }\r\n this.isoVecsBAOA.push(temp);\r\n }\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public MapToFace(faceNb: number, geodesicData: PolyhedronData) {\r\n const F = this.IDATA.face[faceNb];\r\n const oidx = F[2];\r\n const aidx = F[1];\r\n const bidx = F[0];\r\n\r\n const O = Vector3.FromArray(this.IDATA.vertex[oidx]);\r\n const A = Vector3.FromArray(this.IDATA.vertex[aidx]);\r\n const B = Vector3.FromArray(this.IDATA.vertex[bidx]);\r\n\r\n const OA = A.subtract(O);\r\n const OB = B.subtract(O);\r\n\r\n const x: Vector3 = OA.scale(this.coau).add(OB.scale(this.cobu));\r\n const y: Vector3 = OA.scale(this.coav).add(OB.scale(this.cobv));\r\n\r\n const mapped = [];\r\n\r\n let idx: string;\r\n let tempVec: Vector3 = TmpVectors.Vector3[0];\r\n for (let i = 0; i < this.cartesian.length; i++) {\r\n tempVec = x.scale(this.cartesian[i].x).add(y.scale(this.cartesian[i].y)).add(O);\r\n mapped[i] = [tempVec.x, tempVec.y, tempVec.z];\r\n idx = faceNb + \"|\" + this.vertices[i].x + \"|\" + this.vertices[i].y;\r\n geodesicData.vertex[this.vecToidx[idx]] = [tempVec.x, tempVec.y, tempVec.z];\r\n }\r\n }\r\n\r\n //statics\r\n /**Creates a primary triangle\r\n * @internal\r\n */\r\n\r\n public build(m: number, n: number) {\r\n const vertices = new Array<_IsoVector>();\r\n\r\n const O: _IsoVector = _IsoVector.Zero();\r\n const A: _IsoVector = new _IsoVector(m, n);\r\n const B: _IsoVector = new _IsoVector(-n, m + n);\r\n vertices.push(O, A, B);\r\n\r\n //max internal isoceles triangle vertices\r\n for (let y = n; y < m + 1; y++) {\r\n for (let x = 0; x < m + 1 - y; x++) {\r\n vertices.push(new _IsoVector(x, y));\r\n }\r\n }\r\n\r\n //shared vertices along edges when needed\r\n if (n > 0) {\r\n const g = Scalar.HCF(m, n);\r\n const m1 = m / g;\r\n const n1 = n / g;\r\n\r\n for (let i = 1; i < g; i++) {\r\n vertices.push(new _IsoVector(i * m1, i * n1)); //OA\r\n vertices.push(new _IsoVector(-i * n1, i * (m1 + n1))); //OB\r\n vertices.push(new _IsoVector(m - i * (m1 + n1), n + i * m1)); // AB\r\n }\r\n\r\n //lower rows vertices and their rotations\r\n const ratio = m / n;\r\n for (let y = 1; y < n; y++) {\r\n for (let x = 0; x < y * ratio; x++) {\r\n vertices.push(new _IsoVector(x, y));\r\n vertices.push(new _IsoVector(x, y).rotate120(m, n));\r\n vertices.push(new _IsoVector(x, y).rotateNeg120(m, n));\r\n }\r\n }\r\n }\r\n //order vertices by x and then y\r\n vertices.sort((a, b) => {\r\n return a.x - b.x;\r\n });\r\n\r\n vertices.sort((a, b) => {\r\n return a.y - b.y;\r\n });\r\n\r\n const min = new Array(m + n + 1);\r\n const max = new Array(m + n + 1);\r\n for (let i = 0; i < min.length; i++) {\r\n min[i] = Infinity;\r\n max[i] = -Infinity;\r\n }\r\n\r\n let y: number = 0;\r\n let x: number = 0;\r\n\r\n const len: number = vertices.length;\r\n for (let i = 0; i < len; i++) {\r\n x = vertices[i].x;\r\n y = vertices[i].y;\r\n min[y] = Math.min(x, min[y]);\r\n max[y] = Math.max(x, max[y]);\r\n }\r\n\r\n //calculates the distance of a vertex from a given primary vertex\r\n const distFrom = (vert: _IsoVector, primVert: string) => {\r\n const v = vert.clone();\r\n if (primVert === \"A\") {\r\n v.rotateNeg120(m, n);\r\n }\r\n if (primVert === \"B\") {\r\n v.rotate120(m, n);\r\n }\r\n if (v.x < 0) {\r\n return v.y;\r\n }\r\n return v.x + v.y;\r\n };\r\n\r\n const cartesian: Vector3[] = [];\r\n const distFromO: number[] = [];\r\n const distFromA: number[] = [];\r\n const distFromB: number[] = [];\r\n const vertByDist: { [key: string]: number[] } = {};\r\n const vertData: number[][] = [];\r\n let closest: number = -1;\r\n let dist: number = -1;\r\n for (let i = 0; i < len; i++) {\r\n cartesian[i] = vertices[i].toCartesianOrigin(new _IsoVector(0, 0), 0.5);\r\n distFromO[i] = distFrom(vertices[i], \"O\");\r\n distFromA[i] = distFrom(vertices[i], \"A\");\r\n distFromB[i] = distFrom(vertices[i], \"B\");\r\n\r\n if (distFromO[i] === distFromA[i] && distFromA[i] === distFromB[i]) {\r\n closest = 3;\r\n dist = distFromO[i];\r\n } else if (distFromO[i] === distFromA[i]) {\r\n closest = 4;\r\n dist = distFromO[i];\r\n } else if (distFromA[i] === distFromB[i]) {\r\n closest = 5;\r\n dist = distFromA[i];\r\n } else if (distFromB[i] === distFromO[i]) {\r\n closest = 6;\r\n dist = distFromO[i];\r\n }\r\n if (distFromO[i] < distFromA[i] && distFromO[i] < distFromB[i]) {\r\n closest = 2;\r\n dist = distFromO[i];\r\n }\r\n if (distFromA[i] < distFromO[i] && distFromA[i] < distFromB[i]) {\r\n closest = 1;\r\n dist = distFromA[i];\r\n }\r\n if (distFromB[i] < distFromA[i] && distFromB[i] < distFromO[i]) {\r\n closest = 0;\r\n dist = distFromB[i];\r\n }\r\n vertData.push([closest, dist, vertices[i].x, vertices[i].y]);\r\n }\r\n\r\n vertData.sort((a, b) => {\r\n return a[2] - b[2];\r\n });\r\n vertData.sort((a, b) => {\r\n return a[3] - b[3];\r\n });\r\n vertData.sort((a, b) => {\r\n return a[1] - b[1];\r\n });\r\n vertData.sort((a, b) => {\r\n return a[0] - b[0];\r\n });\r\n\r\n for (let v = 0; v < vertData.length; v++) {\r\n vertByDist[vertData[v][2] + \"|\" + vertData[v][3]] = [vertData[v][0], vertData[v][1], v];\r\n }\r\n\r\n this.m = m;\r\n this.n = n;\r\n this.vertices = vertices;\r\n this.vertByDist = vertByDist;\r\n this.cartesian = cartesian;\r\n this.min = min;\r\n this.max = max;\r\n\r\n return this;\r\n }\r\n}\r\n\r\n/** Builds Polyhedron Data\r\n * @internal\r\n */\r\n\r\nexport class PolyhedronData {\r\n public edgematch: (number | string)[][];\r\n\r\n constructor(public name: string, public category: string, public vertex: number[][], public face: number[][]) {}\r\n}\r\n\r\n/**\r\n * This class Extends the PolyhedronData Class to provide measures for a Geodesic Polyhedron\r\n */\r\nexport class GeodesicData extends PolyhedronData {\r\n /**\r\n * @internal\r\n */\r\n public edgematch: (number | string)[][];\r\n /**\r\n * @internal\r\n */\r\n public adjacentFaces: number[][];\r\n /**\r\n * @internal\r\n */\r\n public sharedNodes: number;\r\n /**\r\n * @internal\r\n */\r\n public poleNodes: number;\r\n /**\r\n * @internal\r\n */\r\n public innerToData(face: number, primTri: _PrimaryIsoTriangle) {\r\n for (let i = 0; i < primTri.innerFacets.length; i++) {\r\n this.face.push(primTri.innerFacets[i].map((el) => primTri.vecToidx[face + el]));\r\n }\r\n }\r\n /**\r\n * @internal\r\n */\r\n public mapABOBtoDATA(faceNb: number, primTri: _PrimaryIsoTriangle) {\r\n const fr = primTri.IDATA.edgematch[faceNb][0];\r\n for (let i = 0; i < primTri.isoVecsABOB.length; i++) {\r\n const temp = [];\r\n for (let j = 0; j < 3; j++) {\r\n if (primTri.vertexTypes[i][j] === 0) {\r\n temp.push(faceNb + \"|\" + primTri.isoVecsABOB[i][j].x + \"|\" + primTri.isoVecsABOB[i][j].y);\r\n } else {\r\n temp.push(fr + \"|\" + primTri.isoVecsABOB[i][j].x + \"|\" + primTri.isoVecsABOB[i][j].y);\r\n }\r\n }\r\n this.face.push([primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]]]);\r\n }\r\n }\r\n /**\r\n * @internal\r\n */\r\n public mapOBOAtoDATA(faceNb: number, primTri: _PrimaryIsoTriangle) {\r\n const fr = primTri.IDATA.edgematch[faceNb][0];\r\n for (let i = 0; i < primTri.isoVecsOBOA.length; i++) {\r\n const temp = [];\r\n for (let j = 0; j < 3; j++) {\r\n if (primTri.vertexTypes[i][j] === 1) {\r\n temp.push(faceNb + \"|\" + primTri.isoVecsOBOA[i][j].x + \"|\" + primTri.isoVecsOBOA[i][j].y);\r\n } else {\r\n temp.push(fr + \"|\" + primTri.isoVecsOBOA[i][j].x + \"|\" + primTri.isoVecsOBOA[i][j].y);\r\n }\r\n }\r\n this.face.push([primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]]]);\r\n }\r\n }\r\n /**\r\n * @internal\r\n */\r\n public mapBAOAtoDATA(faceNb: number, primTri: _PrimaryIsoTriangle) {\r\n const fr = primTri.IDATA.edgematch[faceNb][2];\r\n for (let i = 0; i < primTri.isoVecsBAOA.length; i++) {\r\n const temp = [];\r\n for (let j = 0; j < 3; j++) {\r\n if (primTri.vertexTypes[i][j] === 1) {\r\n temp.push(faceNb + \"|\" + primTri.isoVecsBAOA[i][j].x + \"|\" + primTri.isoVecsBAOA[i][j].y);\r\n } else {\r\n temp.push(fr + \"|\" + primTri.isoVecsBAOA[i][j].x + \"|\" + primTri.isoVecsBAOA[i][j].y);\r\n }\r\n }\r\n this.face.push([primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]]]);\r\n }\r\n }\r\n /**\r\n * @internal\r\n */\r\n public orderData(primTri: _PrimaryIsoTriangle) {\r\n const nearTo: number[][][] = [];\r\n for (let i = 0; i < 13; i++) {\r\n nearTo[i] = [];\r\n }\r\n const close: number[][] = primTri.closestTo;\r\n for (let i = 0; i < close.length; i++) {\r\n if (close[i][0] > -1) {\r\n if (close[i][1] > 0) {\r\n nearTo[close[i][0]].push([i, close[i][1]]);\r\n }\r\n } else {\r\n nearTo[12].push([i, close[i][0]]);\r\n }\r\n }\r\n\r\n const near: number[] = [];\r\n for (let i = 0; i < 12; i++) {\r\n near[i] = i;\r\n }\r\n let nearIndex = 12;\r\n for (let i = 0; i < 12; i++) {\r\n nearTo[i].sort((a: number[], b: number[]) => {\r\n return a[1] - b[1];\r\n });\r\n for (let j = 0; j < nearTo[i].length; j++) {\r\n near[nearTo[i][j][0]] = nearIndex++;\r\n }\r\n }\r\n\r\n for (let j = 0; j < nearTo[12].length; j++) {\r\n near[nearTo[12][j][0]] = nearIndex++;\r\n }\r\n\r\n for (let i = 0; i < this.vertex.length; i++) {\r\n this.vertex[i].push(near[i]);\r\n }\r\n\r\n this.vertex.sort((a, b) => {\r\n return a[3] - b[3];\r\n });\r\n\r\n for (let i = 0; i < this.vertex.length; i++) {\r\n this.vertex[i].pop();\r\n }\r\n\r\n for (let i = 0; i < this.face.length; i++) {\r\n for (let j = 0; j < this.face[i].length; j++) {\r\n this.face[i][j] = near[this.face[i][j]];\r\n }\r\n }\r\n\r\n this.sharedNodes = nearTo[12].length;\r\n this.poleNodes = this.vertex.length - this.sharedNodes;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public setOrder(m: number, faces: number[]) {\r\n const adjVerts: number[] = [];\r\n const dualFaces: number[] = [];\r\n let face: number = faces.pop();\r\n dualFaces.push(face);\r\n let index = this.face[face].indexOf(m);\r\n index = (index + 2) % 3;\r\n let v = this.face[face][index];\r\n adjVerts.push(v);\r\n let f = 0;\r\n while (faces.length > 0) {\r\n face = faces[f];\r\n if (this.face[face].indexOf(v) > -1) {\r\n // v is a vertex of face f\r\n index = (this.face[face].indexOf(v) + 1) % 3;\r\n v = this.face[face][index];\r\n adjVerts.push(v);\r\n dualFaces.push(face);\r\n faces.splice(f, 1);\r\n f = 0;\r\n } else {\r\n f++;\r\n }\r\n }\r\n this.adjacentFaces.push(adjVerts);\r\n return dualFaces;\r\n }\r\n /**\r\n * @internal\r\n */\r\n public toGoldbergPolyhedronData(): PolyhedronData {\r\n const goldbergPolyhedronData: PolyhedronData = new PolyhedronData(\"GeoDual\", \"Goldberg\", [], []);\r\n goldbergPolyhedronData.name = \"GD dual\";\r\n const verticesNb: number = this.vertex.length;\r\n const map = new Array(verticesNb);\r\n for (let v = 0; v < verticesNb; v++) {\r\n map[v] = [];\r\n }\r\n for (let f = 0; f < this.face.length; f++) {\r\n for (let i = 0; i < 3; i++) {\r\n map[this.face[f][i]].push(f);\r\n }\r\n }\r\n let cx = 0;\r\n let cy = 0;\r\n let cz = 0;\r\n let face = [];\r\n let vertex = [];\r\n this.adjacentFaces = [];\r\n for (let m = 0; m < map.length; m++) {\r\n goldbergPolyhedronData.face[m] = this.setOrder(m, map[m].concat([]));\r\n map[m].forEach((el: number) => {\r\n cx = 0;\r\n cy = 0;\r\n cz = 0;\r\n face = this.face[el];\r\n for (let i = 0; i < 3; i++) {\r\n vertex = this.vertex[face[i]];\r\n cx += vertex[0];\r\n cy += vertex[1];\r\n cz += vertex[2];\r\n }\r\n goldbergPolyhedronData.vertex[el] = [cx / 3, cy / 3, cz / 3];\r\n });\r\n }\r\n return goldbergPolyhedronData;\r\n }\r\n\r\n //statics\r\n /**Builds the data for a Geodesic Polyhedron from a primary triangle\r\n * @param primTri the primary triangle\r\n * @internal\r\n */\r\n\r\n public static BuildGeodesicData(primTri: _PrimaryIsoTriangle) {\r\n const geodesicData = new GeodesicData(\r\n \"Geodesic-m-n\",\r\n \"Geodesic\",\r\n [\r\n [0, PHI, -1],\r\n [-PHI, 1, 0],\r\n [-1, 0, -PHI],\r\n [1, 0, -PHI],\r\n [PHI, 1, 0],\r\n [0, PHI, 1],\r\n [-1, 0, PHI],\r\n [-PHI, -1, 0],\r\n [0, -PHI, -1],\r\n [PHI, -1, 0],\r\n [1, 0, PHI],\r\n [0, -PHI, 1],\r\n ],\r\n []\r\n );\r\n\r\n primTri.setIndices();\r\n primTri.calcCoeffs();\r\n primTri.createInnerFacets();\r\n primTri.edgeVecsABOB();\r\n primTri.mapABOBtoOBOA();\r\n primTri.mapABOBtoBAOA();\r\n\r\n for (let f = 0; f < primTri.IDATA.face.length; f++) {\r\n primTri.MapToFace(f, geodesicData);\r\n geodesicData.innerToData(f, primTri);\r\n if (primTri.IDATA.edgematch[f][1] === \"B\") {\r\n geodesicData.mapABOBtoDATA(f, primTri);\r\n }\r\n if (primTri.IDATA.edgematch[f][1] === \"O\") {\r\n geodesicData.mapOBOAtoDATA(f, primTri);\r\n }\r\n if (primTri.IDATA.edgematch[f][3] === \"A\") {\r\n geodesicData.mapBAOAtoDATA(f, primTri);\r\n }\r\n }\r\n\r\n geodesicData.orderData(primTri);\r\n const radius = 1;\r\n geodesicData.vertex = geodesicData.vertex.map(function (el) {\r\n const a = el[0];\r\n const b = el[1];\r\n const c = el[2];\r\n const d = Math.sqrt(a * a + b * b + c * c);\r\n el[0] *= radius / d;\r\n el[1] *= radius / d;\r\n el[2] *= radius / d;\r\n return el;\r\n });\r\n\r\n return geodesicData;\r\n }\r\n}\r\n","import type { Scene } from \"../scene\";\r\nimport type { Vector2 } from \"../Maths/math.vector\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { FloatArray } from \"../types\";\r\n\r\nMesh._GoldbergMeshParser = (parsedMesh: any, scene: Scene): GoldbergMesh => {\r\n return GoldbergMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Defines the set of goldberg data used to create the polygon\r\n */\r\nexport type GoldbergData = {\r\n /**\r\n * The list of Goldberg faces colors\r\n */\r\n faceColors: Color4[];\r\n /**\r\n * The list of Goldberg faces centers\r\n */\r\n faceCenters: Vector3[];\r\n /**\r\n * The list of Goldberg faces Z axis\r\n */\r\n faceZaxis: Vector3[];\r\n /**\r\n * The list of Goldberg faces Y axis\r\n */\r\n faceXaxis: Vector3[];\r\n /**\r\n * The list of Goldberg faces X axis\r\n */\r\n faceYaxis: Vector3[];\r\n /**\r\n * Defines the number of shared faces\r\n */\r\n nbSharedFaces: number;\r\n /**\r\n * Defines the number of unshared faces\r\n */\r\n nbUnsharedFaces: number;\r\n /**\r\n * Defines the total number of goldberg faces\r\n */\r\n nbFaces: number;\r\n /**\r\n * Defines the number of goldberg faces at the pole\r\n */\r\n nbFacesAtPole: number;\r\n /**\r\n * Defines the number of adjacent faces per goldberg faces\r\n */\r\n adjacentFaces: number[][];\r\n};\r\n\r\n/**\r\n * Mesh for a Goldberg Polyhedron which is made from 12 pentagonal and the rest hexagonal faces\r\n * @see https://en.wikipedia.org/wiki/Goldberg_polyhedron\r\n */\r\nexport class GoldbergMesh extends Mesh {\r\n /**\r\n * Defines the specific Goldberg data used in this mesh construction.\r\n */\r\n public goldbergData: GoldbergData = {\r\n faceColors: [],\r\n faceCenters: [],\r\n faceZaxis: [],\r\n faceXaxis: [],\r\n faceYaxis: [],\r\n nbSharedFaces: 0,\r\n nbUnsharedFaces: 0,\r\n nbFaces: 0,\r\n nbFacesAtPole: 0,\r\n adjacentFaces: [],\r\n };\r\n\r\n /**\r\n * Gets the related Goldberg face from pole infos\r\n * @param poleOrShared Defines the pole index or the shared face index if the fromPole parameter is passed in\r\n * @param fromPole Defines an optional pole index to find the related info from\r\n * @returns the goldberg face number\r\n */\r\n public relatedGoldbergFace(poleOrShared: number, fromPole?: number): number {\r\n if (fromPole === void 0) {\r\n if (poleOrShared > this.goldbergData.nbUnsharedFaces - 1) {\r\n Logger.Warn(\"Maximum number of unshared faces used\");\r\n poleOrShared = this.goldbergData.nbUnsharedFaces - 1;\r\n }\r\n return this.goldbergData.nbUnsharedFaces + poleOrShared;\r\n }\r\n if (poleOrShared > 11) {\r\n Logger.Warn(\"Last pole used\");\r\n poleOrShared = 11;\r\n }\r\n if (fromPole > this.goldbergData.nbFacesAtPole - 1) {\r\n Logger.Warn(\"Maximum number of faces at a pole used\");\r\n fromPole = this.goldbergData.nbFacesAtPole - 1;\r\n }\r\n\r\n return 12 + poleOrShared * this.goldbergData.nbFacesAtPole + fromPole;\r\n }\r\n\r\n private _changeGoldbergFaceColors(colorRange: (number | Color4)[][]): number[] {\r\n for (let i = 0; i < colorRange.length; i++) {\r\n const min: number = colorRange[i][0];\r\n const max: number = colorRange[i][1];\r\n const col: Color4 = colorRange[i][2];\r\n for (let f = min; f < max + 1; f++) {\r\n this.goldbergData.faceColors[f] = col;\r\n }\r\n }\r\n\r\n const newCols: number[] = [];\r\n for (let f = 0; f < 12; f++) {\r\n for (let i = 0; i < 5; i++) {\r\n newCols.push(this.goldbergData.faceColors[f].r, this.goldbergData.faceColors[f].g, this.goldbergData.faceColors[f].b, this.goldbergData.faceColors[f].a);\r\n }\r\n }\r\n for (let f = 12; f < this.goldbergData.faceColors.length; f++) {\r\n for (let i = 0; i < 6; i++) {\r\n newCols.push(this.goldbergData.faceColors[f].r, this.goldbergData.faceColors[f].g, this.goldbergData.faceColors[f].b, this.goldbergData.faceColors[f].a);\r\n }\r\n }\r\n return newCols;\r\n }\r\n\r\n /**\r\n * Set new goldberg face colors\r\n * @param colorRange the new color to apply to the mesh\r\n */\r\n public setGoldbergFaceColors(colorRange: (number | Color4)[][]) {\r\n const newCols = this._changeGoldbergFaceColors(colorRange);\r\n this.setVerticesData(VertexBuffer.ColorKind, newCols);\r\n }\r\n\r\n /**\r\n * Updates new goldberg face colors\r\n * @param colorRange the new color to apply to the mesh\r\n */\r\n public updateGoldbergFaceColors(colorRange: (number | Color4)[][]) {\r\n const newCols = this._changeGoldbergFaceColors(colorRange);\r\n this.updateVerticesData(VertexBuffer.ColorKind, newCols);\r\n }\r\n\r\n private _changeGoldbergFaceUVs(uvRange: (number | Vector2)[][]): FloatArray {\r\n const uvs: FloatArray = this.getVerticesData(VertexBuffer.UVKind)!!;\r\n for (let i = 0; i < uvRange.length; i++) {\r\n const min: number = uvRange[i][0];\r\n const max: number = uvRange[i][1];\r\n const center: Vector2 = uvRange[i][2];\r\n const radius: number = uvRange[i][3];\r\n const angle: number = uvRange[i][4];\r\n const points5: number[] = [];\r\n const points6: number[] = [];\r\n let u: number;\r\n let v: number;\r\n for (let p = 0; p < 5; p++) {\r\n u = center.x + radius * Math.cos(angle + (p * Math.PI) / 2.5);\r\n v = center.y + radius * Math.sin(angle + (p * Math.PI) / 2.5);\r\n if (u < 0) {\r\n u = 0;\r\n }\r\n if (u > 1) {\r\n u = 1;\r\n }\r\n points5.push(u, v);\r\n }\r\n for (let p = 0; p < 6; p++) {\r\n u = center.x + radius * Math.cos(angle + (p * Math.PI) / 3);\r\n v = center.y + radius * Math.sin(angle + (p * Math.PI) / 3);\r\n if (u < 0) {\r\n u = 0;\r\n }\r\n if (u > 1) {\r\n u = 1;\r\n }\r\n points6.push(u, v);\r\n }\r\n for (let f = min; f < Math.min(12, max + 1); f++) {\r\n for (let p = 0; p < 5; p++) {\r\n uvs[10 * f + 2 * p] = points5[2 * p];\r\n uvs[10 * f + 2 * p + 1] = points5[2 * p + 1];\r\n }\r\n }\r\n for (let f = Math.max(12, min); f < max + 1; f++) {\r\n for (let p = 0; p < 6; p++) {\r\n //120 + 12 * (f - 12) = 12 * f - 24\r\n uvs[12 * f - 24 + 2 * p] = points6[2 * p];\r\n uvs[12 * f - 23 + 2 * p] = points6[2 * p + 1];\r\n }\r\n }\r\n }\r\n return uvs;\r\n }\r\n\r\n /**\r\n * set new goldberg face UVs\r\n * @param uvRange the new UVs to apply to the mesh\r\n */\r\n public setGoldbergFaceUVs(uvRange: (number | Vector2)[][]) {\r\n const newUVs: FloatArray = this._changeGoldbergFaceUVs(uvRange);\r\n this.setVerticesData(VertexBuffer.UVKind, newUVs);\r\n }\r\n\r\n /**\r\n * Updates new goldberg face UVs\r\n * @param uvRange the new UVs to apply to the mesh\r\n */\r\n public updateGoldbergFaceUVs(uvRange: (number | Vector2)[][]) {\r\n const newUVs = this._changeGoldbergFaceUVs(uvRange);\r\n this.updateVerticesData(VertexBuffer.UVKind, newUVs);\r\n }\r\n\r\n /**\r\n * Places a mesh on a particular face of the goldberg polygon\r\n * @param mesh Defines the mesh to position\r\n * @param face Defines the face to position onto\r\n * @param position Defines the position relative to the face we are positioning the mesh onto\r\n */\r\n public placeOnGoldbergFaceAt(mesh: Mesh, face: number, position: Vector3) {\r\n const orientation = Vector3.RotationFromAxis(this.goldbergData.faceXaxis[face], this.goldbergData.faceYaxis[face], this.goldbergData.faceZaxis[face]);\r\n mesh.rotation = orientation;\r\n mesh.position = this.goldbergData.faceCenters[face]\r\n .add(this.goldbergData.faceXaxis[face].scale(position.x))\r\n .add(this.goldbergData.faceYaxis[face].scale(position.y))\r\n .add(this.goldbergData.faceZaxis[face].scale(position.z));\r\n }\r\n\r\n /**\r\n * Serialize current mesh\r\n * @param serializationObject defines the object which will receive the serialization data\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.type = \"GoldbergMesh\";\r\n\r\n const goldbergData: any = {};\r\n goldbergData.adjacentFaces = this.goldbergData.adjacentFaces;\r\n goldbergData.nbSharedFaces = this.goldbergData.nbSharedFaces;\r\n goldbergData.nbUnsharedFaces = this.goldbergData.nbUnsharedFaces;\r\n goldbergData.nbFaces = this.goldbergData.nbFaces;\r\n goldbergData.nbFacesAtPole = this.goldbergData.nbFacesAtPole;\r\n\r\n if (this.goldbergData.faceColors) {\r\n goldbergData.faceColors = [];\r\n for (const color of this.goldbergData.faceColors) {\r\n goldbergData.faceColors.push(color.asArray());\r\n }\r\n }\r\n if (this.goldbergData.faceCenters) {\r\n goldbergData.faceCenters = [];\r\n for (const vector of this.goldbergData.faceCenters) {\r\n goldbergData.faceCenters.push(vector.asArray());\r\n }\r\n }\r\n if (this.goldbergData.faceZaxis) {\r\n goldbergData.faceZaxis = [];\r\n for (const vector of this.goldbergData.faceZaxis) {\r\n goldbergData.faceZaxis.push(vector.asArray());\r\n }\r\n }\r\n if (this.goldbergData.faceYaxis) {\r\n goldbergData.faceYaxis = [];\r\n for (const vector of this.goldbergData.faceYaxis) {\r\n goldbergData.faceYaxis.push(vector.asArray());\r\n }\r\n }\r\n if (this.goldbergData.faceXaxis) {\r\n goldbergData.faceXaxis = [];\r\n for (const vector of this.goldbergData.faceXaxis) {\r\n goldbergData.faceXaxis.push(vector.asArray());\r\n }\r\n }\r\n\r\n serializationObject.goldbergData = goldbergData;\r\n }\r\n\r\n /**\r\n * Parses a serialized goldberg mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the goldberg mesh in\r\n * @returns the created goldberg mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): GoldbergMesh {\r\n const goldbergData = parsedMesh.goldbergData;\r\n goldbergData.faceColors = goldbergData.faceColors.map((el: number[]) => Color4.FromArray(el));\r\n goldbergData.faceCenters = goldbergData.faceCenters.map((el: number[]) => Vector3.FromArray(el));\r\n goldbergData.faceZaxis = goldbergData.faceZaxis.map((el: number[]) => Vector3.FromArray(el));\r\n goldbergData.faceXaxis = goldbergData.faceXaxis.map((el: number[]) => Vector3.FromArray(el));\r\n goldbergData.faceYaxis = goldbergData.faceYaxis.map((el: number[]) => Vector3.FromArray(el));\r\n\r\n const goldberg = new GoldbergMesh(parsedMesh.name, scene);\r\n goldberg.goldbergData = goldbergData;\r\n\r\n return goldberg;\r\n }\r\n}\r\n","import { Path2 } from \"../../Maths/math.path\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { ExtrudePolygon } from \"./polygonBuilder\";\r\n\r\ndeclare let earcut: any;\r\n\r\n/**\r\n * Parser inspired by https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/FontLoader.js\r\n */\r\n\r\n// Interfaces\r\n\r\n/**\r\n * Represents glyph data generated by http://gero3.github.io/facetype.js/\r\n */\r\nexport interface IGlyphData {\r\n /** Commands used to draw (line, move, curve, etc..) */\r\n o: string;\r\n\r\n /** Width */\r\n ha: number;\r\n}\r\n\r\n/**\r\n * Represents font data generated by http://gero3.github.io/facetype.js/\r\n */\r\nexport interface IFontData {\r\n /**\r\n * Font resolution\r\n */\r\n resolution: number;\r\n /** Underline tickness */\r\n underlineThickness: number;\r\n /** Bounding box */\r\n boundingBox: {\r\n yMax: number;\r\n yMin: number;\r\n };\r\n /** List of supported glyphs */\r\n glyphs: { [key: string]: IGlyphData };\r\n}\r\n\r\n// Shape functions\r\nclass ShapePath {\r\n private _paths: Path2[] = [];\r\n private _tempPaths: Path2[] = [];\r\n private _holes: Path2[] = [];\r\n private _currentPath: Path2;\r\n private _resolution: number;\r\n\r\n /** Create the ShapePath used to support glyphs */\r\n constructor(resolution: number) {\r\n this._resolution = resolution;\r\n }\r\n\r\n /** Move the virtual cursor to a coordinate */\r\n moveTo(x: number, y: number) {\r\n this._currentPath = new Path2(x, y);\r\n this._tempPaths.push(this._currentPath);\r\n }\r\n\r\n /** Draw a line from the virtual cursor to a given coordinate */\r\n lineTo(x: number, y: number) {\r\n this._currentPath.addLineTo(x, y);\r\n }\r\n\r\n /** Create a quadratic curve from the virtual cursor to a given coordinate */\r\n quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {\r\n this._currentPath.addQuadraticCurveTo(cpx, cpy, x, y, this._resolution);\r\n }\r\n\r\n /** Create a bezier curve from the virtual cursor to a given coordinate */\r\n bezierCurveTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number) {\r\n this._currentPath.addBezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y, this._resolution);\r\n }\r\n\r\n /** Extract holes based on CW / CCW */\r\n extractHoles() {\r\n for (const path of this._tempPaths) {\r\n if (path.area() > 0) {\r\n this._holes.push(path);\r\n } else {\r\n this._paths.push(path);\r\n }\r\n }\r\n\r\n if (!this._paths.length && this._holes.length) {\r\n const temp = this._holes;\r\n this._holes = this._paths;\r\n this._paths = temp;\r\n }\r\n\r\n this._tempPaths.length = 0;\r\n }\r\n\r\n /** Gets the list of paths */\r\n get paths() {\r\n return this._paths;\r\n }\r\n\r\n /** Gets the list of holes */\r\n get holes() {\r\n return this._holes;\r\n }\r\n}\r\n\r\n// Utility functions\r\nfunction CreateShapePath(\r\n char: string,\r\n scale: number,\r\n offsetX: number,\r\n offsetY: number,\r\n resolution: number,\r\n fontData: IFontData\r\n): Nullable<{\r\n offsetX: number;\r\n shapePath: ShapePath;\r\n}> {\r\n const glyph = fontData.glyphs[char] || fontData.glyphs[\"?\"];\r\n\r\n if (!glyph) {\r\n // return if there is no glyph data\r\n return null;\r\n }\r\n\r\n const shapePath = new ShapePath(resolution);\r\n\r\n if (glyph.o) {\r\n const outline = glyph.o.split(\" \");\r\n\r\n for (let i = 0, l = outline.length; i < l; ) {\r\n const action = outline[i++];\r\n\r\n switch (action) {\r\n case \"m\": {\r\n // moveTo\r\n const x = parseInt(outline[i++]) * scale + offsetX;\r\n const y = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.moveTo(x, y);\r\n break;\r\n }\r\n case \"l\": {\r\n // lineTo\r\n const x = parseInt(outline[i++]) * scale + offsetX;\r\n const y = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.lineTo(x, y);\r\n break;\r\n }\r\n case \"q\": {\r\n // quadraticCurveTo\r\n const cpx = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy = parseInt(outline[i++]) * scale + offsetY;\r\n const cpx1 = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy1 = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.quadraticCurveTo(cpx1, cpy1, cpx, cpy);\r\n break;\r\n }\r\n case \"b\": {\r\n // bezierCurveTo\r\n const cpx = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy = parseInt(outline[i++]) * scale + offsetY;\r\n const cpx1 = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy1 = parseInt(outline[i++]) * scale + offsetY;\r\n const cpx2 = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy2 = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Extract holes (based on clockwise data)\r\n shapePath.extractHoles();\r\n\r\n return { offsetX: glyph.ha * scale, shapePath: shapePath };\r\n}\r\n\r\n/**\r\n * Creates shape paths from a text and font\r\n * @param text the text\r\n * @param size size of the font\r\n * @param resolution resolution of the font\r\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\r\n * @returns array of ShapePath objects\r\n */\r\nexport function CreateTextShapePaths(text: string, size: number, resolution: number, fontData: IFontData) {\r\n const chars = Array.from(text);\r\n const scale = size / fontData.resolution;\r\n const line_height = (fontData.boundingBox.yMax - fontData.boundingBox.yMin + fontData.underlineThickness) * scale;\r\n\r\n const shapePaths: ShapePath[] = [];\r\n\r\n let offsetX = 0,\r\n offsetY = 0;\r\n\r\n for (let i = 0; i < chars.length; i++) {\r\n const char = chars[i];\r\n\r\n if (char === \"\\n\") {\r\n offsetX = 0;\r\n offsetY -= line_height;\r\n } else {\r\n const ret = CreateShapePath(char, scale, offsetX, offsetY, resolution, fontData);\r\n\r\n if (ret) {\r\n offsetX += ret.offsetX;\r\n shapePaths.push(ret.shapePath);\r\n }\r\n }\r\n }\r\n\r\n return shapePaths;\r\n}\r\n\r\n/**\r\n * Create a text mesh\r\n * @param name defines the name of the mesh\r\n * @param text defines the text to use to build the mesh\r\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\r\n * @param options defines options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns a new Mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/text\r\n */\r\nexport function CreateText(\r\n name: string,\r\n text: string,\r\n fontData: IFontData,\r\n options: {\r\n size?: number;\r\n resolution?: number;\r\n depth?: number;\r\n sideOrientation?: number;\r\n } = {\r\n size: 50,\r\n resolution: 8,\r\n depth: 1.0,\r\n },\r\n scene: Nullable = null,\r\n earcutInjection = earcut\r\n): Nullable {\r\n // First we need to generate the paths\r\n const shapePaths = CreateTextShapePaths(text, options.size || 50, options.resolution || 8, fontData);\r\n\r\n // And extrude them\r\n const meshes: Mesh[] = [];\r\n for (const shapePath of shapePaths) {\r\n if (!shapePath.paths.length) {\r\n continue;\r\n }\r\n\r\n const holes = shapePath.holes.slice(); // Copy it as we will update the copy\r\n for (const path of shapePath.paths) {\r\n const holeVectors: Vector3[][] = [];\r\n const shapeVectors: Vector3[] = [];\r\n const points = path.getPoints();\r\n for (const point of points) {\r\n shapeVectors.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\r\n }\r\n\r\n // Holes\r\n const localHolesCopy = holes.slice();\r\n for (const hole of localHolesCopy) {\r\n const points = hole.getPoints();\r\n\r\n let found = false;\r\n for (const point of points) {\r\n if (path.isPointInside(point)) {\r\n found = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!found) {\r\n continue;\r\n }\r\n\r\n const holePoints: Vector3[] = [];\r\n for (const point of points) {\r\n holePoints.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\r\n }\r\n holeVectors.push(holePoints);\r\n\r\n // Remove the hole as it was already used\r\n holes.splice(holes.indexOf(hole), 1);\r\n }\r\n\r\n // There is at least a hole but it was unaffected\r\n if (!holeVectors.length && holes.length) {\r\n for (const hole of holes) {\r\n const points = hole.getPoints();\r\n const holePoints: Vector3[] = [];\r\n for (const point of points) {\r\n holePoints.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\r\n }\r\n holeVectors.push(holePoints);\r\n }\r\n }\r\n\r\n // Extrusion!\r\n const mesh = ExtrudePolygon(\r\n name,\r\n {\r\n shape: shapeVectors,\r\n holes: holeVectors.length ? holeVectors : undefined,\r\n depth: options.depth || 1.0,\r\n sideOrientation: Mesh._GetDefaultSideOrientation(options.sideOrientation || Mesh.DOUBLESIDE),\r\n },\r\n scene,\r\n earcutInjection\r\n );\r\n meshes.push(mesh);\r\n }\r\n }\r\n\r\n // Then we can merge everyone into one single mesh\r\n const newMesh = Mesh.MergeMeshes(meshes, true, true);\r\n\r\n if (newMesh) {\r\n // Move pivot to center\r\n const bbox = newMesh?.getBoundingInfo();\r\n newMesh.position.x = -bbox?.boundingBox.extendSizeWorld._x;\r\n newMesh.position.y = -bbox?.boundingBox.extendSizeWorld._y;\r\n newMesh.position.z = -bbox?.boundingBox.extendSizeWorld._z;\r\n newMesh.name = name;\r\n\r\n newMesh.rotation.x = -Math.PI / 2;\r\n\r\n newMesh.bakeCurrentTransformIntoVertices();\r\n }\r\n\r\n return newMesh;\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { CreateRibbon } from \"./Builders/ribbonBuilder\";\r\nimport { CreateDisc } from \"./Builders/discBuilder\";\r\nimport { CreateBox } from \"./Builders/boxBuilder\";\r\nimport { CreateTiledBox } from \"./Builders/tiledBoxBuilder\";\r\nimport { CreateSphere } from \"./Builders/sphereBuilder\";\r\nimport { CreateCylinder } from \"./Builders/cylinderBuilder\";\r\nimport { CreateTorus } from \"./Builders/torusBuilder\";\r\nimport { CreateTorusKnot } from \"./Builders/torusKnotBuilder\";\r\nimport { CreateDashedLines, CreateLineSystem, CreateLines } from \"./Builders/linesBuilder\";\r\nimport { CreatePolygon, ExtrudePolygon } from \"./Builders/polygonBuilder\";\r\nimport { ExtrudeShape, ExtrudeShapeCustom } from \"./Builders/shapeBuilder\";\r\nimport { CreateLathe } from \"./Builders/latheBuilder\";\r\nimport { CreatePlane } from \"./Builders/planeBuilder\";\r\nimport { CreateTiledPlane } from \"./Builders/tiledPlaneBuilder\";\r\nimport { CreateGround, CreateGroundFromHeightMap, CreateTiledGround } from \"./Builders/groundBuilder\";\r\nimport { CreateTube } from \"./Builders/tubeBuilder\";\r\nimport { CreatePolyhedron } from \"./Builders/polyhedronBuilder\";\r\nimport { CreateIcoSphere } from \"./Builders/icoSphereBuilder\";\r\nimport { CreateDecal } from \"./Builders/decalBuilder\";\r\nimport { CreateCapsule } from \"./Builders/capsuleBuilder\";\r\nimport { CreateGeodesic } from \"./Builders/geodesicBuilder\";\r\nimport { CreateGoldberg } from \"./Builders/goldbergBuilder\";\r\nimport { CreateText } from \"./Builders/textBuilder\";\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n */\r\nexport const MeshBuilder = {\r\n CreateBox,\r\n CreateTiledBox,\r\n CreateSphere,\r\n CreateDisc,\r\n CreateIcoSphere,\r\n CreateRibbon,\r\n CreateCylinder,\r\n CreateTorus,\r\n CreateTorusKnot,\r\n CreateLineSystem,\r\n CreateLines,\r\n CreateDashedLines,\r\n ExtrudeShape,\r\n ExtrudeShapeCustom,\r\n CreateLathe,\r\n CreateTiledPlane,\r\n CreatePlane,\r\n CreateGround,\r\n CreateTiledGround,\r\n CreateGroundFromHeightMap,\r\n CreatePolygon,\r\n ExtrudePolygon,\r\n CreateTube,\r\n CreatePolyhedron,\r\n CreateGeodesic,\r\n CreateGoldberg,\r\n CreateDecal,\r\n CreateCapsule,\r\n CreateText,\r\n};\r\n","import type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport type { Color4 } from \"../../Maths/math.color\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport { CreatePolyhedron } from \"./polyhedronBuilder\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { _PrimaryIsoTriangle, GeodesicData } from \"../geodesicMesh\";\r\n\r\n/**\r\n * Creates the Mesh for a Geodesic Polyhedron\r\n * @see https://en.wikipedia.org/wiki/Geodesic_polyhedron\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra/geodesic_poly\r\n * @param name defines the name of the mesh\r\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\r\n * * m number of horizontal steps along an isogrid\r\n * * n number of angled steps along an isogrid\r\n * * size the size of the Geodesic, optional default 1\r\n * * sizeX allows stretching in the x direction, optional, default size\r\n * * sizeY allows stretching in the y direction, optional, default size\r\n * * sizeZ allows stretching in the z direction, optional, default size\r\n * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * * flat when true creates a flat shaded mesh, optional, default true\r\n * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.n\r\n * @param options.size\r\n * @param options.sizeX\r\n * @param options.sizeY\r\n * @param options.sizeZ\r\n * @param options.faceUV\r\n * @param options.faceColors\r\n * @param options.flat\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param options.m\r\n * @param scene defines the hosting scene\r\n * @returns Geodesic mesh\r\n */\r\nexport function CreateGeodesic(\r\n name: string,\r\n options: {\r\n m?: number;\r\n n?: number;\r\n size?: number;\r\n sizeX?: number;\r\n sizeY?: number;\r\n sizeZ?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n flat?: boolean;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n let m: number = options.m || 1;\r\n if (m !== Math.floor(m)) {\r\n m === Math.floor(m);\r\n Logger.Warn(\"m not an integer only floor(m) used\");\r\n }\r\n let n: number = options.n || 0;\r\n if (n !== Math.floor(n)) {\r\n n === Math.floor(n);\r\n Logger.Warn(\"n not an integer only floor(n) used\");\r\n }\r\n if (n > m) {\r\n const temp = n;\r\n n = m;\r\n m = temp;\r\n Logger.Warn(\"n > m therefore m and n swapped\");\r\n }\r\n const primTri: _PrimaryIsoTriangle = new _PrimaryIsoTriangle();\r\n primTri.build(m, n);\r\n const geodesicData = GeodesicData.BuildGeodesicData(primTri);\r\n\r\n const geoOptions: object = {\r\n custom: geodesicData,\r\n size: options.size,\r\n sizeX: options.sizeX,\r\n sizeY: options.sizeY,\r\n sizeZ: options.sizeZ,\r\n faceUV: options.faceUV,\r\n faceColors: options.faceColors,\r\n flat: options.flat,\r\n updatable: options.updatable,\r\n sideOrientation: options.sideOrientation,\r\n frontUVs: options.frontUVs,\r\n backUVs: options.backUVs,\r\n };\r\n const geodesic = CreatePolyhedron(name, geoOptions, scene);\r\n\r\n return geodesic;\r\n}\r\n","import type { Scene } from \"../../scene\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { PolyhedronData } from \"../geodesicMesh\";\r\nimport { _PrimaryIsoTriangle, GeodesicData } from \"../geodesicMesh\";\r\nimport { GoldbergMesh } from \"../goldbergMesh\";\r\nimport { CompatibilityOptions } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Defines the set of data required to create goldberg vertex data.\r\n */\r\nexport type GoldbergVertexDataOption = {\r\n /**\r\n * the size of the Goldberg, optional default 1\r\n */\r\n size?: number;\r\n /**\r\n * allows stretching in the x direction, optional, default size\r\n */\r\n sizeX?: number;\r\n /**\r\n * allows stretching in the y direction, optional, default size\r\n */\r\n sizeY?: number;\r\n /**\r\n * allows stretching in the z direction, optional, default size\r\n */\r\n sizeZ?: number;\r\n /**\r\n * optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n */\r\n sideOrientation?: number;\r\n};\r\n\r\n/**\r\n * Defines the set of data required to create a goldberg mesh.\r\n */\r\nexport type GoldbergCreationOption = {\r\n /**\r\n * number of horizontal steps along an isogrid\r\n */\r\n m?: number;\r\n /**\r\n * number of angled steps along an isogrid\r\n */\r\n n?: number;\r\n /**\r\n * defines if the mesh must be flagged as updatable\r\n */\r\n updatable?: boolean;\r\n} & GoldbergVertexDataOption;\r\n\r\n/**\r\n * Creates the Mesh for a Goldberg Polyhedron\r\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\r\n * @param goldbergData polyhedronData defining the Goldberg polyhedron\r\n * @returns GoldbergSphere mesh\r\n */\r\nexport function CreateGoldbergVertexData(options: GoldbergVertexDataOption, goldbergData: PolyhedronData): VertexData {\r\n const size = options.size;\r\n const sizeX: number = options.sizeX || size || 1;\r\n const sizeY: number = options.sizeY || size || 1;\r\n const sizeZ: number = options.sizeZ || size || 1;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n const positions = new Array();\r\n const indices = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n\r\n let minX = Infinity;\r\n let maxX = -Infinity;\r\n let minY = Infinity;\r\n let maxY = -Infinity;\r\n\r\n for (let v = 0; v < goldbergData.vertex.length; v++) {\r\n minX = Math.min(minX, goldbergData.vertex[v][0] * sizeX);\r\n maxX = Math.max(maxX, goldbergData.vertex[v][0] * sizeX);\r\n minY = Math.min(minY, goldbergData.vertex[v][1] * sizeY);\r\n maxY = Math.max(maxY, goldbergData.vertex[v][1] * sizeY);\r\n }\r\n\r\n let index: number = 0;\r\n for (let f = 0; f < goldbergData.face.length; f++) {\r\n const verts = goldbergData.face[f];\r\n const a = Vector3.FromArray(goldbergData.vertex[verts[0]]);\r\n const b = Vector3.FromArray(goldbergData.vertex[verts[2]]);\r\n const c = Vector3.FromArray(goldbergData.vertex[verts[1]]);\r\n const ba = b.subtract(a);\r\n const ca = c.subtract(a);\r\n const norm = Vector3.Cross(ca, ba).normalize();\r\n for (let v = 0; v < verts.length; v++) {\r\n normals.push(norm.x, norm.y, norm.z);\r\n const pdata = goldbergData.vertex[verts[v]];\r\n positions.push(pdata[0] * sizeX, pdata[1] * sizeY, pdata[2] * sizeZ);\r\n const vCoord = (pdata[1] * sizeY - minY) / (maxY - minY);\r\n uvs.push((pdata[0] * sizeX - minX) / (maxX - minX), CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - vCoord : vCoord);\r\n }\r\n for (let v = 0; v < verts.length - 2; v++) {\r\n indices.push(index, index + v + 2, index + v + 1);\r\n }\r\n index += verts.length;\r\n }\r\n\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs);\r\n\r\n const vertexData = new VertexData();\r\n vertexData.positions = positions;\r\n vertexData.indices = indices;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates the Mesh for a Goldberg Polyhedron which is made from 12 pentagonal and the rest hexagonal faces\r\n * @see https://en.wikipedia.org/wiki/Goldberg_polyhedron\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra/goldberg_poly\r\n * @param name defines the name of the mesh\r\n * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty\r\n * @param scene defines the hosting scene\r\n * @returns Goldberg mesh\r\n */\r\nexport function CreateGoldberg(name: string, options: GoldbergCreationOption, scene: Nullable = null): GoldbergMesh {\r\n const size = options.size;\r\n const sizeX: number = options.sizeX || size || 1;\r\n const sizeY: number = options.sizeY || size || 1;\r\n const sizeZ: number = options.sizeZ || size || 1;\r\n let m: number = options.m || 1;\r\n if (m !== Math.floor(m)) {\r\n m === Math.floor(m);\r\n Logger.Warn(\"m not an integer only floor(m) used\");\r\n }\r\n let n: number = options.n || 0;\r\n if (n !== Math.floor(n)) {\r\n n === Math.floor(n);\r\n Logger.Warn(\"n not an integer only floor(n) used\");\r\n }\r\n if (n > m) {\r\n const temp = n;\r\n n = m;\r\n m = temp;\r\n Logger.Warn(\"n > m therefore m and n swapped\");\r\n }\r\n const primTri: _PrimaryIsoTriangle = new _PrimaryIsoTriangle();\r\n primTri.build(m, n);\r\n const geodesicData = GeodesicData.BuildGeodesicData(primTri);\r\n const goldbergData = geodesicData.toGoldbergPolyhedronData();\r\n\r\n const goldberg = new GoldbergMesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n goldberg._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateGoldbergVertexData(options, goldbergData);\r\n\r\n vertexData.applyToMesh(goldberg, options.updatable);\r\n\r\n goldberg.goldbergData.nbSharedFaces = geodesicData.sharedNodes;\r\n goldberg.goldbergData.nbUnsharedFaces = geodesicData.poleNodes;\r\n goldberg.goldbergData.adjacentFaces = geodesicData.adjacentFaces;\r\n goldberg.goldbergData.nbFaces = goldberg.goldbergData.nbSharedFaces + goldberg.goldbergData.nbUnsharedFaces;\r\n goldberg.goldbergData.nbFacesAtPole = (goldberg.goldbergData.nbUnsharedFaces - 12) / 12;\r\n for (let f = 0; f < geodesicData.vertex.length; f++) {\r\n goldberg.goldbergData.faceCenters.push(Vector3.FromArray(geodesicData.vertex[f]));\r\n goldberg.goldbergData.faceCenters[f].x *= sizeX;\r\n goldberg.goldbergData.faceCenters[f].y *= sizeY;\r\n goldberg.goldbergData.faceCenters[f].z *= sizeZ;\r\n goldberg.goldbergData.faceColors.push(new Color4(1, 1, 1, 1));\r\n }\r\n\r\n for (let f = 0; f < goldbergData.face.length; f++) {\r\n const verts = goldbergData.face[f];\r\n const a = Vector3.FromArray(goldbergData.vertex[verts[0]]);\r\n const b = Vector3.FromArray(goldbergData.vertex[verts[2]]);\r\n const c = Vector3.FromArray(goldbergData.vertex[verts[1]]);\r\n const ba = b.subtract(a);\r\n const ca = c.subtract(a);\r\n const norm = Vector3.Cross(ca, ba).normalize();\r\n const z = Vector3.Cross(ca, norm).normalize();\r\n goldberg.goldbergData.faceXaxis.push(ca.normalize());\r\n goldberg.goldbergData.faceYaxis.push(norm);\r\n goldberg.goldbergData.faceZaxis.push(z);\r\n }\r\n\r\n return goldberg;\r\n}\r\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Color4, Vector3 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eAxis } from '@models/classes/enums';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { SceneNode } from '@models/classes/scene-node';\r\nimport { Highlighter } from '@view/modules/highlighter';\r\nimport { getCameraPositionWithOffset } from './math-helper';\r\n\r\nexport interface ITextLabelStyle {\r\n font?: string;\r\n}\r\nexport interface ITextLabel {\r\n id?: string;\r\n text: string;\r\n position: KbVector;\r\n style?: ITextLabelStyle;\r\n color: Color4;\r\n}\r\n\r\nexport class GuiHelper {\r\n private textLabelMap = new Map();\r\n private gridSettings: {\r\n gridMesh?: TransformNode;\r\n gridAxesMesh?: TransformNode;\r\n } = {};\r\n\r\n constructor(private scene: Scene, private highlighter: Highlighter) {\r\n const cameraPosition = new Vector3();\r\n scene.registerBeforeRender(() => {\r\n if (scene.activeCamera && this.textLabelMap.size > 0) {\r\n this.textLabelMap.forEach(mesh => {\r\n const camera = scene.activeCamera!;\r\n cameraPosition.copyFrom(getCameraPositionWithOffset(camera));\r\n mesh.lookAt(cameraPosition);\r\n if (camera.mode !== Camera.ORTHOGRAPHIC_CAMERA) {\r\n const size = cameraPosition.subtractInPlace(mesh.position).length() * 0.05;\r\n mesh.scaling = mesh.scaling.copyFromFloats(size, size, size);\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n enableGrid(sceneNode: SceneNode, skipOrigin = false) {\r\n if (this.gridSettings.gridMesh) {\r\n return;\r\n }\r\n const bgColor = sceneNode?.backgroundColor;\r\n let bgColor3: Color3;\r\n if (!bgColor) {\r\n bgColor3 = new Color3(this.scene.clearColor.r, this.scene.clearColor.g, this.scene.clearColor.b);\r\n } else {\r\n bgColor3 = bgColor.a === 0 ? Color3.Black() : new Color3(bgColor.r, bgColor.g, bgColor.b);\r\n }\r\n const gridStepSize = sceneNode.gridStepSize || 1;\r\n const gridSize = sceneNode.gridSize || 10;\r\n const gridNormal = sceneNode.gridNormal;\r\n const gridMajorInterval = sceneNode.gridMajorInterval || 0;\r\n\r\n const strongLineColor = Color4.FromColor3(bgColor3.toLuminance() > 0.5 ? Color3.Black() : Color3.White());\r\n const lightLineColor = strongLineColor.scale(0.4).add(Color4.FromColor3(bgColor3.scale(0.6)));\r\n\r\n const points = this.calculateGridPoints(gridStepSize, gridSize, gridNormal);\r\n const pointColors: Color4[][] = [];\r\n const linesPerSide = points.length / 2;\r\n for (let s = 0; s < 2; s++) {\r\n for (let i = 0; i < linesPerSide; i++) {\r\n if (gridMajorInterval === 0) {\r\n pointColors.push([lightLineColor, lightLineColor]);\r\n } else if (Math.ceil(i / 2) % gridMajorInterval === 0) {\r\n pointColors.push([strongLineColor, strongLineColor]);\r\n } else {\r\n pointColors.push([lightLineColor, lightLineColor]);\r\n }\r\n }\r\n }\r\n\r\n if (skipOrigin) {\r\n points.splice(linesPerSide, 1);\r\n points.splice(0, 1);\r\n pointColors.splice(linesPerSide, 1);\r\n pointColors.splice(0, 1);\r\n }\r\n\r\n const gridMesh = MeshBuilder.CreateLineSystem(\r\n 'grid',\r\n {\r\n lines: points,\r\n colors: pointColors,\r\n updatable: false,\r\n },\r\n this.scene\r\n );\r\n\r\n // gridMesh.color = lineColor.scale(0.4).add(bgColor3.scale(0.6));\r\n gridMesh.isPickable = false;\r\n\r\n this.gridSettings.gridMesh = gridMesh;\r\n }\r\n\r\n disableGrid() {\r\n if (this.gridSettings.gridMesh) {\r\n this.gridSettings.gridMesh.dispose();\r\n delete this.gridSettings.gridMesh;\r\n }\r\n }\r\n\r\n enableGridAxes(sceneNode: SceneNode) {\r\n if (this.gridSettings.gridAxesMesh) {\r\n return;\r\n }\r\n // const bgColor = sceneNode.backgroundColor;\r\n // let bgColor3: Color3;\r\n // if (!bgColor) {\r\n // bgColor3 = new Color3(this.scene.clearColor.r, this.scene.clearColor.g, this.scene.clearColor.b);\r\n // } else {\r\n // bgColor3 = bgColor.a === 0 ? Color3.Black() : new Color3(bgColor.r, bgColor.g, bgColor.b);\r\n // }\r\n\r\n // const lineColor = bgColor3.toLuminance() > 0.5 ? Color3.Black() : Color3.White();\r\n const gridStepSize = sceneNode.gridStepSize || 1;\r\n const gridSize = (sceneNode.gridSize || 10) * gridStepSize;\r\n\r\n const colors = [\r\n Color4.FromColor3(Color3.Red()),\r\n Color4.FromColor3(Color3.Green()),\r\n Color4.FromColor3(Color3.Blue()),\r\n ];\r\n const pointsAxes = [\r\n [new Vector3(-gridSize, 0, 0), new Vector3(gridSize, 0, 0)],\r\n [new Vector3(0, -gridSize, 0), new Vector3(0, gridSize, 0)],\r\n [new Vector3(0, 0, -gridSize), new Vector3(0, 0, gridSize)],\r\n ];\r\n\r\n const pointColors = [\r\n [colors[0], colors[0]],\r\n [colors[1], colors[1]],\r\n [colors[2], colors[2]],\r\n ];\r\n\r\n const gridMeshAxes = MeshBuilder.CreateLineSystem(\r\n 'gridAxes',\r\n {\r\n lines: pointsAxes,\r\n updatable: false,\r\n colors: pointColors,\r\n },\r\n this.scene\r\n );\r\n\r\n gridMeshAxes.isPickable = false;\r\n\r\n this.gridSettings.gridAxesMesh = gridMeshAxes;\r\n\r\n this.createTextLabels([\r\n { text: 'x', position: new KbVector(gridSize, 0.5, 0), color: colors[0] },\r\n { text: 'y', position: new KbVector(0.5, gridSize, 0), color: colors[1] },\r\n { text: 'z', position: new KbVector(0, 0.5, gridSize), color: colors[2] },\r\n ]);\r\n }\r\n\r\n disableGridAxes() {\r\n if (this.gridSettings.gridAxesMesh) {\r\n this.gridSettings.gridAxesMesh.dispose();\r\n delete this.gridSettings.gridAxesMesh;\r\n }\r\n }\r\n\r\n private createTextLabels(items: ITextLabel[], style: ITextLabelStyle = {}) {\r\n if (!style.font) {\r\n style.font = 'bold 32px sans-serif';\r\n }\r\n\r\n items.forEach(label => {\r\n const font = label.style && label.style.font ? label.style.font : style.font!;\r\n\r\n if (!label.id) {\r\n label.id = label.text;\r\n }\r\n\r\n if (this.textLabelMap.has(label.id)) {\r\n const labelMesh = this.textLabelMap.get(label.id)!;\r\n labelMesh.position = label.position.toVec3();\r\n } else {\r\n // Set height for plane\r\n const fontSize = parseInt(font.replace(/\\D+(\\d+)px.*/, '$1')) || 32;\r\n const planeHeight = fontSize / 32;\r\n const textureHeight = 2 * fontSize;\r\n const ratio = planeHeight / textureHeight;\r\n\r\n // Use a temporay canvas to calculate the length of the text\r\n const temp = document.createElement('canvas');\r\n temp.width = 64;\r\n temp.height = 64;\r\n const tmpctx = temp.getContext('2d');\r\n if (tmpctx) {\r\n tmpctx.font = font;\r\n const textureWidth = tmpctx.measureText(label.text).width + 8;\r\n temp.width = 0;\r\n temp.height = 0;\r\n\r\n // Create dynamic texture and write the text\r\n const dynamicId = `axisLabel${label.id}`;\r\n const planeWidth = textureWidth * ratio;\r\n const dynamicTexture = new DynamicTexture(\r\n dynamicId + '-labelTexture',\r\n { width: textureWidth, height: textureHeight },\r\n this.scene,\r\n false\r\n );\r\n const mat = new StandardMaterial(dynamicId + '-labelMaterial', this.scene);\r\n mat.emissiveTexture = dynamicTexture;\r\n mat.diffuseTexture = dynamicTexture;\r\n mat.sideOrientation = Mesh.BACKSIDE;\r\n dynamicTexture.hasAlpha = true;\r\n dynamicTexture.drawText(\r\n label.text,\r\n null,\r\n null,\r\n font,\r\n label.color.toHexString(),\r\n 'rgba(0,0,0,0)',\r\n true\r\n );\r\n\r\n // Create plane and set dynamic texture as material\r\n const plane = MeshBuilder.CreatePlane(\r\n dynamicId,\r\n { width: planeWidth, height: planeHeight },\r\n this.scene\r\n );\r\n plane.material = mat;\r\n plane.position = label.position.toVec3();\r\n plane.isPickable = false;\r\n\r\n this.textLabelMap.set(label.id, plane);\r\n }\r\n }\r\n });\r\n }\r\n\r\n private calculateGridPoints(stepSize: number, gridCount: number, normal: eAxis, gridFullSize?: number) {\r\n const points: Vector3[][] = [];\r\n const wV1 = new Vector3(),\r\n wV2 = new Vector3(),\r\n vStep = new Vector3();\r\n\r\n if (gridFullSize === undefined) {\r\n gridFullSize = gridCount;\r\n }\r\n\r\n let uVec: Vector3;\r\n let vVec: Vector3;\r\n switch (normal) {\r\n case eAxis.x:\r\n uVec = new Vector3(0, stepSize, 0);\r\n vVec = new Vector3(0, 0, stepSize);\r\n break;\r\n case eAxis.y:\r\n uVec = new Vector3(stepSize, 0, 0);\r\n vVec = new Vector3(0, 0, stepSize);\r\n break;\r\n case eAxis.z:\r\n uVec = new Vector3(stepSize, 0, 0);\r\n vVec = new Vector3(0, stepSize, 0);\r\n break;\r\n }\r\n\r\n wV1.setAll(0).addInPlace(vVec).scaleInPlace(-1).scaleInPlace(gridFullSize);\r\n wV2.setAll(0).scaleInPlace(-1).addInPlace(vVec).scaleInPlace(gridFullSize);\r\n for (let i = 0; i < gridCount * 2 + 1; i++) {\r\n const d = (2 * (i % 2) - 1) * Math.ceil(i / 2);\r\n vStep.copyFrom(uVec).scaleInPlace(d);\r\n points.push([wV1.add(vStep), wV2.add(vStep)]);\r\n }\r\n wV1.setAll(0).addInPlace(uVec).scaleInPlace(-1).scaleInPlace(gridFullSize);\r\n wV2.setAll(0).scaleInPlace(-1).addInPlace(uVec).scaleInPlace(gridFullSize);\r\n for (let i = 0; i < gridCount * 2 + 1; i++) {\r\n const d = (2 * (i % 2) - 1) * Math.ceil(i / 2);\r\n\r\n vStep.copyFrom(vVec).scaleInPlace(d);\r\n points.push([wV1.add(vStep), wV2.add(vStep)]);\r\n }\r\n\r\n return points;\r\n }\r\n}\r\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { Matrix, Vector3 } from '@babylonjs/core/Maths';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { WebXRCamera } from '@babylonjs/core/XR/webXRCamera';\r\n\r\nexport interface IScreenPosition {\r\n x: number;\r\n y: number;\r\n}\r\n\r\nexport interface IScreenBoundingBox extends IScreenPosition {\r\n top: number;\r\n left: number;\r\n width: number;\r\n height: number;\r\n}\r\n\r\n/**\r\n * Generic utilities for the babylon scene\r\n */\r\n\r\n/** returns the x,y pixel position of the node on the canvas */\r\nexport function nodeToScreen(bNode: TransformNode, camera: Camera) {\r\n camera = getCamera(camera);\r\n const nodeWorldPos = bNode.getAbsolutePosition(); // Vector3.TransformCoordinates(bNode.position, bNode.getWorldMatrix());\r\n return toScreen(nodeWorldPos, camera);\r\n}\r\n\r\n/** converts screen units */\r\nexport function toPixels(viewportUnits: IScreenPosition, camera: Camera) {\r\n camera = getCamera(camera);\r\n const canvasRect = camera.getEngine().getRenderingCanvasClientRect() as ClientRect;\r\n return {\r\n x: viewportUnits.x * canvasRect.width,\r\n y: viewportUnits.y * canvasRect.height,\r\n } as IScreenPosition;\r\n}\r\n\r\n/** returns the screen position as normalized device units a ratio from 0 to 1 */\r\nexport function toNDC(worldPos: Vector3, camera: Camera) {\r\n camera = getCamera(camera);\r\n const pos = Vector3.Project(worldPos, Matrix.IdentityReadOnly, camera.getTransformationMatrix(), camera.viewport);\r\n return {\r\n x: pos.x,\r\n y: pos.y,\r\n } as IScreenPosition;\r\n}\r\n\r\nexport function toScreen(worldPos: Vector3, camera: Camera) {\r\n camera = getCamera(camera);\r\n const scene = camera.getScene();\r\n const engine = scene.getEngine();\r\n const pos = Vector3.Project(\r\n worldPos,\r\n Matrix.IdentityReadOnly,\r\n scene.getTransformMatrix(),\r\n camera.viewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight())\r\n );\r\n return {\r\n x: pos.x,\r\n y: pos.y,\r\n } as IScreenPosition;\r\n}\r\n\r\nexport function getScreenBoundingBox(\r\n node: TransformNode,\r\n camera: Camera,\r\n includeDescendants = true\r\n): IScreenBoundingBox {\r\n camera = getCamera(camera);\r\n const bv = getHierarchyBoundingVectors(node, includeDescendants);\r\n return boundingVectorsToScreen(bv, camera);\r\n}\r\n\r\n// export function getBoundingVectors(bNode: AbstractMesh | TransformNode | undefined, scene: Scene, includeDescendants = true) {\r\n// let bv: { min: Vector3, max: Vector3 } | undefined;\r\n// if (!bNode) {\r\n// bv = scene.getWorldExtends();\r\n// } else {\r\n// bv = bNode.getHierarchyBoundingVectors(true);\r\n// if (bv.min.x == Number.MAX_VALUE && bv.min.y == Number.MAX_VALUE && bv.min.z == Number.MAX_VALUE && bv.max.x == -Number.MAX_VALUE && bv.max.y == -Number.MAX_VALUE && bv.max.z == -Number.MAX_VALUE) {\r\n// bv = {\r\n// min: bNode.absolutePosition.clone(),\r\n// max: bNode.absolutePosition.clone()\r\n// }\r\n// }\r\n// }\r\n\r\n// return bv;\r\n// }\r\n\r\n/**\r\n * Babylon's getHierarchyBoundingVectors has a bug that surfaces when called on a transformNode that has no real meshes in it's child hierarchy.\r\n * Use this wrapper instead\r\n * @param bNode\r\n * @param includeDescendants\r\n */\r\nexport function getHierarchyBoundingVectors(bNode: AbstractMesh | TransformNode, includeDescendants = true) {\r\n let bv = bNode.getHierarchyBoundingVectors(includeDescendants);\r\n //to handle a babylon bug that returns maxvalues when the node is an empty transformnode\r\n if (\r\n bv.min.x == Number.MAX_VALUE &&\r\n bv.min.y == Number.MAX_VALUE &&\r\n bv.min.z == Number.MAX_VALUE &&\r\n bv.max.x == -Number.MAX_VALUE &&\r\n bv.max.y == -Number.MAX_VALUE &&\r\n bv.max.z == -Number.MAX_VALUE\r\n ) {\r\n bv = {\r\n min: bNode.absolutePosition.clone(),\r\n max: bNode.absolutePosition.clone(),\r\n };\r\n }\r\n\r\n return bv;\r\n}\r\n\r\nexport function boundingVectorsToScreen(\r\n boundingVectors: { min: Vector3; max: Vector3 },\r\n camera: Camera\r\n): IScreenBoundingBox {\r\n camera = getCamera(camera);\r\n const bv = boundingVectors;\r\n const xs = new Array();\r\n const ys = new Array();\r\n\r\n for (let i = 0; i < 8; i++) {\r\n const x = bv[Math.floor(i / 4) ? 'max' : 'min'].x;\r\n const y = bv[Math.floor(i / 2) % 2 ? 'max' : 'min'].y;\r\n const z = bv[i % 2 ? 'max' : 'min'].z;\r\n const v = new Vector3(x, y, z);\r\n const sp = toNDC(v, camera);\r\n xs.push(sp.x);\r\n ys.push(sp.y);\r\n }\r\n\r\n const minx = Math.min(...xs);\r\n const maxx = Math.max(...xs);\r\n const miny = Math.min(...ys);\r\n const maxy = Math.max(...ys);\r\n\r\n const width = maxx - minx;\r\n const height = maxy - miny;\r\n const x = minx + width / 2;\r\n const y = miny + height / 2;\r\n const engine = camera.getEngine();\r\n const canvas = engine.getRenderingCanvas()!;\r\n const canvasWidth = canvas.width * engine.getHardwareScalingLevel();\r\n const canvasHeight = canvas.height * engine.getHardwareScalingLevel();\r\n\r\n return {\r\n x: x * canvasWidth,\r\n y: y * canvasHeight,\r\n top: miny * canvasHeight,\r\n left: minx * canvasWidth,\r\n width: width * canvasWidth,\r\n height: height * canvasHeight,\r\n } as IScreenBoundingBox;\r\n}\r\n\r\nexport function updateMatrixOfAncestorChain(ancestor: TransformNode, child: TransformNode) {\r\n while (child != ancestor && child instanceof TransformNode) {\r\n child.computeWorldMatrix(true);\r\n child = child.parent as TransformNode;\r\n }\r\n if (child) {\r\n child.computeWorldMatrix(true);\r\n }\r\n}\r\n\r\nfunction getCamera(camera: Camera) {\r\n if (camera instanceof WebXRCamera) {\r\n return camera.rigCameras[0];\r\n }\r\n return camera;\r\n}\r\n","import { Subject } from 'rxjs';\r\nimport { UUID } from '../models/classes/utilities';\r\n\r\nexport enum eWorkerTasks {\r\n usdConvertGeometry = 'usdConvertGeometry',\r\n usdPackage = 'usdPackageStart',\r\n}\r\n\r\nexport enum eKB3DMessageType {\r\n taskStart = 'taskStart',\r\n taskError = 'taskError',\r\n taskProgress = 'taskProgress',\r\n taskComplete = 'taskComplete',\r\n}\r\n\r\nexport interface IKB3DMessage {\r\n type: eKB3DMessageType;\r\n payload: T;\r\n}\r\n\r\nexport interface IKB3DTaskMessage extends IKB3DMessage {\r\n task: eWorkerTasks;\r\n taskId: string;\r\n}\r\n\r\nconst THREAD_COUNT = 2;\r\n\r\nexport class Kb3dWorker {\r\n workerPool: Worker[] = [];\r\n toggle = 0;\r\n requestsInFlight = new Map>();\r\n\r\n public static workerPath = '';\r\n\r\n constructor() {\r\n if (!Kb3dWorker.workerPath) {\r\n throw Error('Worker Script path not set');\r\n }\r\n const workerPath = Kb3dWorker.workerPath;\r\n\r\n const content = `importScripts( \"${workerPath}\" );`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([content], { type: 'text/javascript' }));\r\n\r\n const workerReturnMessage = (event: MessageEvent) => {\r\n if ('task' in event.data) {\r\n const data = event.data;\r\n const sub = this.requestsInFlight.get(data.taskId);\r\n\r\n if (sub) {\r\n // We have to remove the request from the inflight map first because the sub.next can trigger the dispose\r\n // But the sub.complete has to be after the sub.next\r\n if (data.type === eKB3DMessageType.taskComplete) {\r\n this.requestsInFlight.delete(data.taskId);\r\n }\r\n\r\n if (data.type === eKB3DMessageType.taskError) {\r\n sub.error(data.payload);\r\n } else {\r\n sub.next(data);\r\n }\r\n\r\n if (data.type === eKB3DMessageType.taskComplete) {\r\n sub.complete();\r\n }\r\n }\r\n }\r\n };\r\n\r\n for (let i = 0; i < THREAD_COUNT; i++) {\r\n const newWorker = new Worker(workerBlobUrl);\r\n newWorker.onmessage = workerReturnMessage;\r\n this.workerPool.push(newWorker);\r\n }\r\n URL.revokeObjectURL(workerBlobUrl);\r\n }\r\n\r\n startTask(task: eWorkerTasks, taskPayload: S, transfer?: ArrayBuffer[]) {\r\n const messagePayload: IKB3DTaskMessage = {\r\n type: eKB3DMessageType.taskStart,\r\n task,\r\n taskId: UUID.generate(),\r\n payload: taskPayload,\r\n };\r\n this.workerPool[this.toggle].postMessage(messagePayload, transfer ? { transfer } : undefined);\r\n\r\n const sub = new Subject>();\r\n this.requestsInFlight.set(messagePayload.taskId, sub);\r\n this.toggle = (this.toggle + 1) % THREAD_COUNT;\r\n\r\n return sub;\r\n }\r\n\r\n dispose() {\r\n this.workerPool.forEach(worker => {\r\n worker.terminate();\r\n });\r\n\r\n this.requestsInFlight.forEach(sub => {\r\n sub.error('Worker Terminated');\r\n sub.complete();\r\n });\r\n this.requestsInFlight.clear();\r\n }\r\n}\r\n","/*\r\n * Polyfill for createImageBitmap\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap\r\n *\r\n * Supports CanvasImageSource (img, video, canvas) sources, Blobs, and ImageData.\r\n *\r\n * From:\r\n * - https://dev.to/nektro/createimagebitmap-polyfill-for-safari-and-edge-228\r\n * - https://gist.github.com/MonsieurV/fb640c29084c171b4444184858a91bc7\r\n * Updated by:\r\n * - Yoan Tournade \r\n * - diachedelic, https://gist.github.com/diachedelic\r\n * - Paul Ellis, https://pseudosavant.com\r\n */\r\n\r\n(function createImageBitmapIIFE(global: any) {\r\n function isCanvasImageSource(el: any) {\r\n const validElements = ['img', 'video', 'canvas'];\r\n\r\n return el && el.tagName && validElements.includes(el.tagName.toLowerCase());\r\n }\r\n\r\n function idealSize(currentValue: number, newValue: number, numerator: number, denominator: number) {\r\n if (typeof newValue === 'number') return newValue;\r\n if (typeof numerator !== 'number' || typeof denominator !== 'number') return currentValue;\r\n\r\n return (numerator / denominator) * currentValue;\r\n }\r\n\r\n if (!('createImageBitmap' in global)) {\r\n global.createImageBitmap = async function polyfillCreateImageBitmap(data: any, opts: any): Promise {\r\n return new Promise((resolve, reject) => {\r\n opts = opts || {};\r\n\r\n let dataURL;\r\n const canvas = document.createElement('canvas');\r\n\r\n try {\r\n const ctx = canvas.getContext('2d')!;\r\n\r\n if (data instanceof Blob) {\r\n dataURL = URL.createObjectURL(data);\r\n } else if (isCanvasImageSource(data)) {\r\n const width = data.naturalWidth || data.videoWidth || data.clientWidth || data.width;\r\n const height = data.naturalHeight || data.videoHeight || data.clientHeight || data.height;\r\n canvas.width = idealSize(width, opts.resizeWidth, opts.resizeHeight, height);\r\n canvas.height = idealSize(height, opts.resizeHeight, opts.resizeWidth, width);\r\n\r\n ctx.drawImage(data, 0, 0, canvas.width, canvas.height);\r\n\r\n dataURL = canvas.toDataURL();\r\n } else if (data instanceof ImageData) {\r\n canvas.width = idealSize(data.width, opts.resizeWidth, opts.resizeHeight, data.height);\r\n canvas.height = idealSize(data.height, opts.resizeHeight, opts.resizeWidth, data.width);\r\n\r\n ctx.putImageData(data, 0, 0);\r\n\r\n dataURL = canvas.toDataURL();\r\n } else {\r\n reject('createImageBitmap does not handle the provided image source type');\r\n }\r\n\r\n const img = new Image();\r\n img.onerror = reject;\r\n img.onload = () => resolve(img);\r\n img.src = dataURL as string;\r\n } finally {\r\n // avoid memory leaks on iOS Safari, see https://stackoverflow.com/a/52586606\r\n canvas.width = 0;\r\n canvas.height = 0;\r\n }\r\n });\r\n };\r\n }\r\n})(window);\r\n","var version = '18.5.0';\n\n/**\n * Tween.js - Licensed under the MIT license\n * https://github.com/tweenjs/tween.js\n * ----------------------------------------------\n *\n * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.\n * Thank you all, you're awesome!\n */\n\n\nvar _Group = function () {\n\tthis._tweens = {};\n\tthis._tweensAddedDuringUpdate = {};\n};\n\n_Group.prototype = {\n\tgetAll: function () {\n\n\t\treturn Object.keys(this._tweens).map(function (tweenId) {\n\t\t\treturn this._tweens[tweenId];\n\t\t}.bind(this));\n\n\t},\n\n\tremoveAll: function () {\n\n\t\tthis._tweens = {};\n\n\t},\n\n\tadd: function (tween) {\n\n\t\tthis._tweens[tween.getId()] = tween;\n\t\tthis._tweensAddedDuringUpdate[tween.getId()] = tween;\n\n\t},\n\n\tremove: function (tween) {\n\n\t\tdelete this._tweens[tween.getId()];\n\t\tdelete this._tweensAddedDuringUpdate[tween.getId()];\n\n\t},\n\n\tupdate: function (time, preserve) {\n\n\t\tvar tweenIds = Object.keys(this._tweens);\n\n\t\tif (tweenIds.length === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttime = time !== undefined ? time : TWEEN.now();\n\n\t\t// Tweens are updated in \"batches\". If you add a new tween during an\n\t\t// update, then the new tween will be updated in the next batch.\n\t\t// If you remove a tween during an update, it may or may not be updated.\n\t\t// However, if the removed tween was added during the current batch,\n\t\t// then it will not be updated.\n\t\twhile (tweenIds.length > 0) {\n\t\t\tthis._tweensAddedDuringUpdate = {};\n\n\t\t\tfor (var i = 0; i < tweenIds.length; i++) {\n\n\t\t\t\tvar tween = this._tweens[tweenIds[i]];\n\n\t\t\t\tif (tween && tween.update(time) === false) {\n\t\t\t\t\ttween._isPlaying = false;\n\n\t\t\t\t\tif (!preserve) {\n\t\t\t\t\t\tdelete this._tweens[tweenIds[i]];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttweenIds = Object.keys(this._tweensAddedDuringUpdate);\n\t\t}\n\n\t\treturn true;\n\n\t}\n};\n\nvar TWEEN = new _Group();\n\nTWEEN.Group = _Group;\nTWEEN._nextId = 0;\nTWEEN.nextId = function () {\n\treturn TWEEN._nextId++;\n};\n\n\n// Include a performance.now polyfill.\n// In node.js, use process.hrtime.\nif (typeof (self) === 'undefined' && typeof (process) !== 'undefined' && process.hrtime) {\n\tTWEEN.now = function () {\n\t\tvar time = process.hrtime();\n\n\t\t// Convert [seconds, nanoseconds] to milliseconds.\n\t\treturn time[0] * 1000 + time[1] / 1000000;\n\t};\n}\n// In a browser, use self.performance.now if it is available.\nelse if (typeof (self) !== 'undefined' &&\n self.performance !== undefined &&\n\t\t self.performance.now !== undefined) {\n\t// This must be bound, because directly assigning this function\n\t// leads to an invocation exception in Chrome.\n\tTWEEN.now = self.performance.now.bind(self.performance);\n}\n// Use Date.now if it is available.\nelse if (Date.now !== undefined) {\n\tTWEEN.now = Date.now;\n}\n// Otherwise, use 'new Date().getTime()'.\nelse {\n\tTWEEN.now = function () {\n\t\treturn new Date().getTime();\n\t};\n}\n\n\nTWEEN.Tween = function (object, group) {\n\tthis._isPaused = false;\n\tthis._pauseStart = null;\n\tthis._object = object;\n\tthis._valuesStart = {};\n\tthis._valuesEnd = {};\n\tthis._valuesStartRepeat = {};\n\tthis._duration = 1000;\n\tthis._repeat = 0;\n\tthis._repeatDelayTime = undefined;\n\tthis._yoyo = false;\n\tthis._isPlaying = false;\n\tthis._reversed = false;\n\tthis._delayTime = 0;\n\tthis._startTime = null;\n\tthis._easingFunction = TWEEN.Easing.Linear.None;\n\tthis._interpolationFunction = TWEEN.Interpolation.Linear;\n\tthis._chainedTweens = [];\n\tthis._onStartCallback = null;\n\tthis._onStartCallbackFired = false;\n\tthis._onUpdateCallback = null;\n\tthis._onRepeatCallback = null;\n\tthis._onCompleteCallback = null;\n\tthis._onStopCallback = null;\n\tthis._group = group || TWEEN;\n\tthis._id = TWEEN.nextId();\n\n};\n\nTWEEN.Tween.prototype = {\n\tgetId: function () {\n\t\treturn this._id;\n\t},\n\n\tisPlaying: function () {\n\t\treturn this._isPlaying;\n\t},\n\n\tisPaused: function () {\n\t\treturn this._isPaused;\n\t},\n\n\tto: function (properties, duration) {\n\n\t\tthis._valuesEnd = Object.create(properties);\n\n\t\tif (duration !== undefined) {\n\t\t\tthis._duration = duration;\n\t\t}\n\n\t\treturn this;\n\n\t},\n\n\tduration: function duration(d) {\n\t\tthis._duration = d;\n\t\treturn this;\n\t},\n\n\tstart: function (time) {\n\n\t\tthis._group.add(this);\n\n\t\tthis._isPlaying = true;\n\n\t\tthis._isPaused = false;\n\n\t\tthis._onStartCallbackFired = false;\n\n\t\tthis._startTime = time !== undefined ? typeof time === 'string' ? TWEEN.now() + parseFloat(time) : time : TWEEN.now();\n\t\tthis._startTime += this._delayTime;\n\n\t\tfor (var property in this._valuesEnd) {\n\n\t\t\t// Check if an Array was provided as property value\n\t\t\tif (this._valuesEnd[property] instanceof Array) {\n\n\t\t\t\tif (this._valuesEnd[property].length === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Create a local copy of the Array with the start value at the front\n\t\t\t\tthis._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]);\n\n\t\t\t}\n\n\t\t\t// If `to()` specifies a property that doesn't exist in the source object,\n\t\t\t// we should not set that property in the object\n\t\t\tif (this._object[property] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Save the starting value, but only once.\n\t\t\tif (typeof(this._valuesStart[property]) === 'undefined') {\n\t\t\t\tthis._valuesStart[property] = this._object[property];\n\t\t\t}\n\n\t\t\tif ((this._valuesStart[property] instanceof Array) === false) {\n\t\t\t\tthis._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings\n\t\t\t}\n\n\t\t\tthis._valuesStartRepeat[property] = this._valuesStart[property] || 0;\n\n\t\t}\n\n\t\treturn this;\n\n\t},\n\n\tstop: function () {\n\n\t\tif (!this._isPlaying) {\n\t\t\treturn this;\n\t\t}\n\n\t\tthis._group.remove(this);\n\n\t\tthis._isPlaying = false;\n\n\t\tthis._isPaused = false;\n\n\t\tif (this._onStopCallback !== null) {\n\t\t\tthis._onStopCallback(this._object);\n\t\t}\n\n\t\tthis.stopChainedTweens();\n\t\treturn this;\n\n\t},\n\n\tend: function () {\n\n\t\tthis.update(Infinity);\n\t\treturn this;\n\n\t},\n\n\tpause: function(time) {\n\n\t\tif (this._isPaused || !this._isPlaying) {\n\t\t\treturn this;\n\t\t}\n\n\t\tthis._isPaused = true;\n\n\t\tthis._pauseStart = time === undefined ? TWEEN.now() : time;\n\n\t\tthis._group.remove(this);\n\n\t\treturn this;\n\n\t},\n\n\tresume: function(time) {\n\n\t\tif (!this._isPaused || !this._isPlaying) {\n\t\t\treturn this;\n\t\t}\n\n\t\tthis._isPaused = false;\n\n\t\tthis._startTime += (time === undefined ? TWEEN.now() : time)\n\t\t\t- this._pauseStart;\n\n\t\tthis._pauseStart = 0;\n\n\t\tthis._group.add(this);\n\n\t\treturn this;\n\n\t},\n\n\tstopChainedTweens: function () {\n\n\t\tfor (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {\n\t\t\tthis._chainedTweens[i].stop();\n\t\t}\n\n\t},\n\n\tgroup: function (group) {\n\t\tthis._group = group;\n\t\treturn this;\n\t},\n\n\tdelay: function (amount) {\n\n\t\tthis._delayTime = amount;\n\t\treturn this;\n\n\t},\n\n\trepeat: function (times) {\n\n\t\tthis._repeat = times;\n\t\treturn this;\n\n\t},\n\n\trepeatDelay: function (amount) {\n\n\t\tthis._repeatDelayTime = amount;\n\t\treturn this;\n\n\t},\n\n\tyoyo: function (yoyo) {\n\n\t\tthis._yoyo = yoyo;\n\t\treturn this;\n\n\t},\n\n\teasing: function (easingFunction) {\n\n\t\tthis._easingFunction = easingFunction;\n\t\treturn this;\n\n\t},\n\n\tinterpolation: function (interpolationFunction) {\n\n\t\tthis._interpolationFunction = interpolationFunction;\n\t\treturn this;\n\n\t},\n\n\tchain: function () {\n\n\t\tthis._chainedTweens = arguments;\n\t\treturn this;\n\n\t},\n\n\tonStart: function (callback) {\n\n\t\tthis._onStartCallback = callback;\n\t\treturn this;\n\n\t},\n\n\tonUpdate: function (callback) {\n\n\t\tthis._onUpdateCallback = callback;\n\t\treturn this;\n\n\t},\n\n\tonRepeat: function onRepeat(callback) {\n\n\t\tthis._onRepeatCallback = callback;\n\t\treturn this;\n\n\t},\n\n\tonComplete: function (callback) {\n\n\t\tthis._onCompleteCallback = callback;\n\t\treturn this;\n\n\t},\n\n\tonStop: function (callback) {\n\n\t\tthis._onStopCallback = callback;\n\t\treturn this;\n\n\t},\n\n\tupdate: function (time) {\n\n\t\tvar property;\n\t\tvar elapsed;\n\t\tvar value;\n\n\t\tif (time < this._startTime) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this._onStartCallbackFired === false) {\n\n\t\t\tif (this._onStartCallback !== null) {\n\t\t\t\tthis._onStartCallback(this._object);\n\t\t\t}\n\n\t\t\tthis._onStartCallbackFired = true;\n\t\t}\n\n\t\telapsed = (time - this._startTime) / this._duration;\n\t\telapsed = (this._duration === 0 || elapsed > 1) ? 1 : elapsed;\n\n\t\tvalue = this._easingFunction(elapsed);\n\n\t\tfor (property in this._valuesEnd) {\n\n\t\t\t// Don't update properties that do not exist in the source object\n\t\t\tif (this._valuesStart[property] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvar start = this._valuesStart[property] || 0;\n\t\t\tvar end = this._valuesEnd[property];\n\n\t\t\tif (end instanceof Array) {\n\n\t\t\t\tthis._object[property] = this._interpolationFunction(end, value);\n\n\t\t\t} else {\n\n\t\t\t\t// Parses relative end values with start as base (e.g.: +10, -3)\n\t\t\t\tif (typeof (end) === 'string') {\n\n\t\t\t\t\tif (end.charAt(0) === '+' || end.charAt(0) === '-') {\n\t\t\t\t\t\tend = start + parseFloat(end);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tend = parseFloat(end);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Protect against non numeric properties.\n\t\t\t\tif (typeof (end) === 'number') {\n\t\t\t\t\tthis._object[property] = start + (end - start) * value;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\tif (this._onUpdateCallback !== null) {\n\t\t\tthis._onUpdateCallback(this._object, elapsed);\n\t\t}\n\n\t\tif (elapsed === 1) {\n\n\t\t\tif (this._repeat > 0) {\n\n\t\t\t\tif (isFinite(this._repeat)) {\n\t\t\t\t\tthis._repeat--;\n\t\t\t\t}\n\n\t\t\t\t// Reassign starting values, restart by making startTime = now\n\t\t\t\tfor (property in this._valuesStartRepeat) {\n\n\t\t\t\t\tif (typeof (this._valuesEnd[property]) === 'string') {\n\t\t\t\t\t\tthis._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._yoyo) {\n\t\t\t\t\t\tvar tmp = this._valuesStartRepeat[property];\n\n\t\t\t\t\t\tthis._valuesStartRepeat[property] = this._valuesEnd[property];\n\t\t\t\t\t\tthis._valuesEnd[property] = tmp;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._valuesStart[property] = this._valuesStartRepeat[property];\n\n\t\t\t\t}\n\n\t\t\t\tif (this._yoyo) {\n\t\t\t\t\tthis._reversed = !this._reversed;\n\t\t\t\t}\n\n\t\t\t\tif (this._repeatDelayTime !== undefined) {\n\t\t\t\t\tthis._startTime = time + this._repeatDelayTime;\n\t\t\t\t} else {\n\t\t\t\t\tthis._startTime = time + this._delayTime;\n\t\t\t\t}\n\n\t\t\t\tif (this._onRepeatCallback !== null) {\n\t\t\t\t\tthis._onRepeatCallback(this._object);\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\n\t\t\t} else {\n\n\t\t\t\tif (this._onCompleteCallback !== null) {\n\n\t\t\t\t\tthis._onCompleteCallback(this._object);\n\t\t\t\t}\n\n\t\t\t\tfor (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {\n\t\t\t\t\t// Make the chained tweens start exactly at the time they should,\n\t\t\t\t\t// even if the `update()` method was called way past the duration of the tween\n\t\t\t\t\tthis._chainedTweens[i].start(this._startTime + this._duration);\n\t\t\t\t}\n\n\t\t\t\treturn false;\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn true;\n\n\t}\n};\n\n\nTWEEN.Easing = {\n\n\tLinear: {\n\n\t\tNone: function (k) {\n\n\t\t\treturn k;\n\n\t\t}\n\n\t},\n\n\tQuadratic: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn k * k;\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn k * (2 - k);\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn 0.5 * k * k;\n\t\t\t}\n\n\t\t\treturn - 0.5 * (--k * (k - 2) - 1);\n\n\t\t}\n\n\t},\n\n\tCubic: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn k * k * k;\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn --k * k * k + 1;\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn 0.5 * k * k * k;\n\t\t\t}\n\n\t\t\treturn 0.5 * ((k -= 2) * k * k + 2);\n\n\t\t}\n\n\t},\n\n\tQuartic: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn k * k * k * k;\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn 1 - (--k * k * k * k);\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn 0.5 * k * k * k * k;\n\t\t\t}\n\n\t\t\treturn - 0.5 * ((k -= 2) * k * k * k - 2);\n\n\t\t}\n\n\t},\n\n\tQuintic: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn k * k * k * k * k;\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn --k * k * k * k * k + 1;\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn 0.5 * k * k * k * k * k;\n\t\t\t}\n\n\t\t\treturn 0.5 * ((k -= 2) * k * k * k * k + 2);\n\n\t\t}\n\n\t},\n\n\tSinusoidal: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn 1 - Math.cos(k * Math.PI / 2);\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn Math.sin(k * Math.PI / 2);\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\treturn 0.5 * (1 - Math.cos(Math.PI * k));\n\n\t\t}\n\n\t},\n\n\tExponential: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn k === 0 ? 0 : Math.pow(1024, k - 1);\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn k === 1 ? 1 : 1 - Math.pow(2, - 10 * k);\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif (k === 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tif (k === 1) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn 0.5 * Math.pow(1024, k - 1);\n\t\t\t}\n\n\t\t\treturn 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2);\n\n\t\t}\n\n\t},\n\n\tCircular: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn 1 - Math.sqrt(1 - k * k);\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\treturn Math.sqrt(1 - (--k * k));\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn - 0.5 * (Math.sqrt(1 - k * k) - 1);\n\t\t\t}\n\n\t\t\treturn 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);\n\n\t\t}\n\n\t},\n\n\tElastic: {\n\n\t\tIn: function (k) {\n\n\t\t\tif (k === 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tif (k === 1) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\treturn -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\tif (k === 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tif (k === 1) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\treturn Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1;\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif (k === 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tif (k === 1) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tk *= 2;\n\n\t\t\tif (k < 1) {\n\t\t\t\treturn -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);\n\t\t\t}\n\n\t\t\treturn 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1;\n\n\t\t}\n\n\t},\n\n\tBack: {\n\n\t\tIn: function (k) {\n\n\t\t\tvar s = 1.70158;\n\n\t\t\treturn k * k * ((s + 1) * k - s);\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\tvar s = 1.70158;\n\n\t\t\treturn --k * k * ((s + 1) * k + s) + 1;\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tvar s = 1.70158 * 1.525;\n\n\t\t\tif ((k *= 2) < 1) {\n\t\t\t\treturn 0.5 * (k * k * ((s + 1) * k - s));\n\t\t\t}\n\n\t\t\treturn 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);\n\n\t\t}\n\n\t},\n\n\tBounce: {\n\n\t\tIn: function (k) {\n\n\t\t\treturn 1 - TWEEN.Easing.Bounce.Out(1 - k);\n\n\t\t},\n\n\t\tOut: function (k) {\n\n\t\t\tif (k < (1 / 2.75)) {\n\t\t\t\treturn 7.5625 * k * k;\n\t\t\t} else if (k < (2 / 2.75)) {\n\t\t\t\treturn 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;\n\t\t\t} else if (k < (2.5 / 2.75)) {\n\t\t\t\treturn 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;\n\t\t\t} else {\n\t\t\t\treturn 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;\n\t\t\t}\n\n\t\t},\n\n\t\tInOut: function (k) {\n\n\t\t\tif (k < 0.5) {\n\t\t\t\treturn TWEEN.Easing.Bounce.In(k * 2) * 0.5;\n\t\t\t}\n\n\t\t\treturn TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;\n\n\t\t}\n\n\t}\n\n};\n\nTWEEN.Interpolation = {\n\n\tLinear: function (v, k) {\n\n\t\tvar m = v.length - 1;\n\t\tvar f = m * k;\n\t\tvar i = Math.floor(f);\n\t\tvar fn = TWEEN.Interpolation.Utils.Linear;\n\n\t\tif (k < 0) {\n\t\t\treturn fn(v[0], v[1], f);\n\t\t}\n\n\t\tif (k > 1) {\n\t\t\treturn fn(v[m], v[m - 1], m - f);\n\t\t}\n\n\t\treturn fn(v[i], v[i + 1 > m ? m : i + 1], f - i);\n\n\t},\n\n\tBezier: function (v, k) {\n\n\t\tvar b = 0;\n\t\tvar n = v.length - 1;\n\t\tvar pw = Math.pow;\n\t\tvar bn = TWEEN.Interpolation.Utils.Bernstein;\n\n\t\tfor (var i = 0; i <= n; i++) {\n\t\t\tb += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);\n\t\t}\n\n\t\treturn b;\n\n\t},\n\n\tCatmullRom: function (v, k) {\n\n\t\tvar m = v.length - 1;\n\t\tvar f = m * k;\n\t\tvar i = Math.floor(f);\n\t\tvar fn = TWEEN.Interpolation.Utils.CatmullRom;\n\n\t\tif (v[0] === v[m]) {\n\n\t\t\tif (k < 0) {\n\t\t\t\ti = Math.floor(f = m * (1 + k));\n\t\t\t}\n\n\t\t\treturn fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);\n\n\t\t} else {\n\n\t\t\tif (k < 0) {\n\t\t\t\treturn v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);\n\t\t\t}\n\n\t\t\tif (k > 1) {\n\t\t\t\treturn v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);\n\t\t\t}\n\n\t\t\treturn fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);\n\n\t\t}\n\n\t},\n\n\tUtils: {\n\n\t\tLinear: function (p0, p1, t) {\n\n\t\t\treturn (p1 - p0) * t + p0;\n\n\t\t},\n\n\t\tBernstein: function (n, i) {\n\n\t\t\tvar fc = TWEEN.Interpolation.Utils.Factorial;\n\n\t\t\treturn fc(n) / fc(i) / fc(n - i);\n\n\t\t},\n\n\t\tFactorial: (function () {\n\n\t\t\tvar a = [1];\n\n\t\t\treturn function (n) {\n\n\t\t\t\tvar s = 1;\n\n\t\t\t\tif (a[n]) {\n\t\t\t\t\treturn a[n];\n\t\t\t\t}\n\n\t\t\t\tfor (var i = n; i > 1; i--) {\n\t\t\t\t\ts *= i;\n\t\t\t\t}\n\n\t\t\t\ta[n] = s;\n\t\t\t\treturn s;\n\n\t\t\t};\n\n\t\t})(),\n\n\t\tCatmullRom: function (p0, p1, p2, p3, t) {\n\n\t\t\tvar v0 = (p2 - p0) * 0.5;\n\t\t\tvar v1 = (p3 - p1) * 0.5;\n\t\t\tvar t2 = t * t;\n\t\t\tvar t3 = t * t2;\n\n\t\t\treturn (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;\n\n\t\t}\n\n\t}\n\n};\nTWEEN.version = version;\n\nexport default TWEEN;\n","import { Scene } from '@babylonjs/core/scene';\r\nimport { eEasing } from '@models/classes/enums';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Token } from '@models/classes/token';\r\nimport TWEEN from '@tweenjs/tween.js';\r\nimport { KbViewer } from '../kb-viewer';\r\n\r\nexport interface IAnimation {\r\n name?: string;\r\n /** the node to animate */\r\n node: Kb3dObject;\r\n /** the property of the node that will be animated */\r\n prop: string;\r\n /** the $type of the property value */\r\n propType?: string;\r\n /** the value to animate to */\r\n toValue: any;\r\n easing?: eEasing;\r\n /** the length of the animation */\r\n duration?: number;\r\n /** the number of iterations to run the animations. -1 for infinite */\r\n iterations?: number;\r\n /** the number of ms to wait before starting the animation */\r\n delay?: number;\r\n}\r\n\r\nexport interface IActiveAnimation {\r\n animation: IAnimation;\r\n tween: TWEEN.Tween;\r\n}\r\n\r\nexport class AnimationModule {\r\n constructor(private kbViewer: KbViewer, private scene: Scene) {}\r\n\r\n protected activeAnimations = new Set();\r\n\r\n public get animationsAreRunning() {\r\n return this.activeAnimations.size > 0;\r\n }\r\n\r\n public queue(a: IAnimation): Promise {\r\n if (!a.node) throw 'node required';\r\n if (a.toValue == null) throw 'value required';\r\n\r\n a = this.applyDefaults(a);\r\n\r\n return new Promise(resolve => {\r\n const origValue = (a.node as any)[a.prop];\r\n const origValueType = origValue?.$type;\r\n const val = this.valueIn(origValue);\r\n const toVal = this.valueIn(a.toValue);\r\n\r\n const tween = new TWEEN.Tween(val)\r\n .to(toVal, a.duration!)\r\n .delay(a.delay!)\r\n .repeat(a.iterations! < 0 ? Infinity : a.iterations! - 1)\r\n .easing(this.getTweenEasingFn(a.easing!))\r\n .onUpdate(() => {\r\n (a.node as any)[a.prop] = this.valueOut(val, origValueType);\r\n })\r\n .onComplete(() => {\r\n this.activeAnimations.delete(activeAnim);\r\n resolve();\r\n })\r\n .start();\r\n\r\n const activeAnim = { animation: a, tween };\r\n this.activeAnimations.add(activeAnim);\r\n this.kbViewer.animationWarningsNeedsUpdate.next(this.activeAnimations.size);\r\n });\r\n }\r\n\r\n public stop(name: string) {\r\n if (name != null) {\r\n const anims = [...this.activeAnimations.values()];\r\n for (const t of anims.filter(a => name.isEqual(a.animation.name))) {\r\n t.tween.stop();\r\n this.activeAnimations.delete(t);\r\n }\r\n }\r\n }\r\n\r\n public stopAll() {\r\n for (const a of this.activeAnimations) {\r\n a.tween.stop();\r\n }\r\n this.activeAnimations.clear();\r\n }\r\n\r\n /** should be called by the render loop */\r\n public update() {\r\n TWEEN.update(); //update all animations\r\n }\r\n\r\n protected applyDefaults(a: IAnimation) {\r\n return {\r\n duration: 1000,\r\n easing: eEasing.linear,\r\n iterations: 1,\r\n delay: 0,\r\n\r\n ...a,\r\n } as IAnimation;\r\n }\r\n\r\n protected valueIn(val: any) {\r\n if (val instanceof KbVector) {\r\n return val.toObject();\r\n } else if (val instanceof KbColor) {\r\n return val.toObject();\r\n } else if (val instanceof KbQuaternion) {\r\n return val.toObject();\r\n } else {\r\n return { value: val };\r\n }\r\n }\r\n\r\n protected valueOut(val: any, $type: string) {\r\n if (!$type) {\r\n return val.value;\r\n } else {\r\n if ($type == Token.KbVector.key) {\r\n return KbVector.From(val);\r\n } else if ($type == Token.KbColor.key) {\r\n return KbColor.From(val);\r\n } else if ($type == Token.KbQuaternion.key) {\r\n return KbQuaternion.From(val);\r\n } else {\r\n throw 'unrecognized type';\r\n }\r\n }\r\n }\r\n\r\n protected getTweenEasingFn(e: eEasing): (k: number) => number {\r\n const split = e.splitWords().map(s => s.capitalize());\r\n const inOut = split.length == 3 ? split[1] + split[2] : split.length == 2 ? split[1] : 'None';\r\n return (TWEEN.Easing as any)[split[0]][inOut];\r\n }\r\n}\r\n","import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Matrix, Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRHitResult } from \"./WebXRHitTest\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Configuration options of the anchor system\r\n */\r\nexport interface IWebXRAnchorSystemOptions {\r\n /**\r\n * a node that will be used to convert local to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n\r\n /**\r\n * If set to true a reference of the created anchors will be kept until the next session starts\r\n * If not defined, anchors will be removed from the array when the feature is detached or the session ended.\r\n */\r\n doNotRemoveAnchorsOnSessionEnded?: boolean;\r\n}\r\n\r\n/**\r\n * A babylon container for an XR Anchor\r\n */\r\nexport interface IWebXRAnchor {\r\n /**\r\n * A babylon-assigned ID for this anchor\r\n */\r\n id: number;\r\n /**\r\n * Transformation matrix to apply to an object attached to this anchor\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native anchor object\r\n */\r\n xrAnchor: XRAnchor;\r\n\r\n /**\r\n * if defined, this object will be constantly updated by the anchor's position and rotation\r\n */\r\n attachedNode?: TransformNode;\r\n\r\n /**\r\n * Remove this anchor from the scene\r\n */\r\n remove(): void;\r\n}\r\n\r\n/**\r\n * An internal interface for a future (promise based) anchor\r\n */\r\ninterface IWebXRFutureAnchor {\r\n /**\r\n * The native anchor\r\n */\r\n nativeAnchor?: XRAnchor;\r\n /**\r\n * Was this request submitted to the xr frame?\r\n */\r\n submitted: boolean;\r\n /**\r\n * Was this promise resolved already?\r\n */\r\n resolved: boolean;\r\n /**\r\n * A resolve function\r\n */\r\n resolve: (xrAnchor: IWebXRAnchor) => void;\r\n /**\r\n * A reject function\r\n */\r\n reject: (msg?: string) => void;\r\n /**\r\n * The XR Transformation of the future anchor\r\n */\r\n xrTransformation: XRRigidTransform;\r\n}\r\n\r\nlet anchorIdProvider = 0;\r\n\r\n/**\r\n * An implementation of the anchor system for WebXR.\r\n * For further information see https://github.com/immersive-web/anchors/\r\n */\r\nexport class WebXRAnchorSystem extends WebXRAbstractFeature {\r\n private _lastFrameDetected: XRAnchorSet = new Set();\r\n\r\n private _trackedAnchors: Array = [];\r\n\r\n private _referenceSpaceForFrameAnchors: XRReferenceSpace;\r\n\r\n private _futureAnchors: IWebXRFutureAnchor[] = [];\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.ANCHOR_SYSTEM;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Observers registered here will be executed when a new anchor was added to the session\r\n */\r\n public onAnchorAddedObservable: Observable = new Observable();\r\n /**\r\n * Observers registered here will be executed when an anchor was removed from the session\r\n */\r\n public onAnchorRemovedObservable: Observable = new Observable();\r\n /**\r\n * Observers registered here will be executed when an existing anchor updates\r\n * This can execute N times every frame\r\n */\r\n public onAnchorUpdatedObservable: Observable = new Observable();\r\n\r\n /**\r\n * Set the reference space to use for anchor creation, when not using a hit test.\r\n * Will default to the session's reference space if not defined\r\n */\r\n public set referenceSpaceForFrameAnchors(referenceSpace: XRReferenceSpace) {\r\n this._referenceSpaceForFrameAnchors = referenceSpace;\r\n }\r\n\r\n /**\r\n * constructs a new anchor system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param _options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private _options: IWebXRAnchorSystemOptions = {}) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"anchors\";\r\n }\r\n\r\n private _tmpVector = new Vector3();\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n private _populateTmpTransformation(position: Vector3, rotationQuaternion: Quaternion) {\r\n this._tmpVector.copyFrom(position);\r\n this._tmpQuaternion.copyFrom(rotationQuaternion);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpVector.z *= -1;\r\n this._tmpQuaternion.z *= -1;\r\n this._tmpQuaternion.w *= -1;\r\n }\r\n return {\r\n position: this._tmpVector,\r\n rotationQuaternion: this._tmpQuaternion,\r\n };\r\n }\r\n\r\n /**\r\n * Create a new anchor point using a hit test result at a specific point in the scene\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param hitTestResult The hit test result to use for this anchor creation\r\n * @param position an optional position offset for this anchor\r\n * @param rotationQuaternion an optional rotation offset for this anchor\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorPointUsingHitTestResultAsync(\r\n hitTestResult: IWebXRHitResult,\r\n position: Vector3 = new Vector3(),\r\n rotationQuaternion: Quaternion = new Quaternion()\r\n ): Promise {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const m = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n if (!hitTestResult.xrHitResult.createAnchor) {\r\n this.detach();\r\n throw new Error(\"Anchors not enabled in this environment/browser\");\r\n } else {\r\n try {\r\n const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\r\n return new Promise((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor,\r\n resolved: false,\r\n submitted: true,\r\n xrTransformation: m,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add a new anchor at a specific position and rotation\r\n * This function will add a new anchor per default in the next available frame. Unless forced, the createAnchor function\r\n * will be called in the next xrFrame loop to make sure that the anchor can be created correctly.\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param position the position in which to add an anchor\r\n * @param rotationQuaternion an optional rotation for the anchor transformation\r\n * @param forceCreateInCurrentFrame force the creation of this anchor in the current frame. Must be called inside xrFrame loop!\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorAtPositionAndRotationAsync(\r\n position: Vector3,\r\n rotationQuaternion: Quaternion = new Quaternion(),\r\n forceCreateInCurrentFrame = false\r\n ): Promise {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const xrTransformation = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n const xrAnchor =\r\n forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame\r\n ? await this._createAnchorAtTransformation(xrTransformation, this._xrSessionManager.currentFrame)\r\n : undefined;\r\n // add the transformation to the future anchors list\r\n return new Promise((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor: xrAnchor,\r\n resolved: false,\r\n submitted: false,\r\n xrTransformation,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Get the list of anchors currently being tracked by the system\r\n */\r\n public get anchors(): IWebXRAnchor[] {\r\n return this._trackedAnchors;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.doNotRemoveAnchorsOnSessionEnded) {\r\n while (this._trackedAnchors.length) {\r\n const toRemove = this._trackedAnchors.pop();\r\n if (toRemove) {\r\n try {\r\n // try to natively remove it as well\r\n toRemove.remove();\r\n } catch (e) {\r\n // no-op\r\n }\r\n // as the xr frame loop is removed, we need to notify manually\r\n this.onAnchorRemovedObservable.notifyObservers(toRemove);\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n this._futureAnchors.length = 0;\r\n super.dispose();\r\n this.onAnchorAddedObservable.clear();\r\n this.onAnchorRemovedObservable.clear();\r\n this.onAnchorUpdatedObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n if (!this.attached || !frame) {\r\n return;\r\n }\r\n\r\n const trackedAnchors = frame.trackedAnchors;\r\n if (trackedAnchors) {\r\n const toRemove = this._trackedAnchors\r\n .filter((anchor) => !trackedAnchors.has(anchor.xrAnchor))\r\n .map((anchor) => {\r\n const index = this._trackedAnchors.indexOf(anchor);\r\n return index;\r\n });\r\n let idxTracker = 0;\r\n toRemove.forEach((index) => {\r\n const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];\r\n this.onAnchorRemovedObservable.notifyObservers(anchor);\r\n idxTracker++;\r\n });\r\n // now check for new ones\r\n trackedAnchors.forEach((xrAnchor) => {\r\n if (!this._lastFrameDetected.has(xrAnchor)) {\r\n const newAnchor: Partial = {\r\n id: anchorIdProvider++,\r\n xrAnchor: xrAnchor,\r\n remove: () => xrAnchor.delete(),\r\n };\r\n const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);\r\n this._trackedAnchors.push(anchor);\r\n this.onAnchorAddedObservable.notifyObservers(anchor);\r\n // search for the future anchor promise that matches this\r\n const results = this._futureAnchors.filter((futureAnchor) => futureAnchor.nativeAnchor === xrAnchor);\r\n const result = results[0];\r\n if (result) {\r\n result.resolve(anchor);\r\n result.resolved = true;\r\n }\r\n } else {\r\n const index = this._findIndexInAnchorArray(xrAnchor);\r\n const anchor = this._trackedAnchors[index];\r\n try {\r\n // anchors update every frame\r\n this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);\r\n if (anchor.attachedNode) {\r\n anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();\r\n anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);\r\n }\r\n this.onAnchorUpdatedObservable.notifyObservers(anchor);\r\n } catch (e) {\r\n Tools.Warn(`Anchor could not be updated`);\r\n }\r\n }\r\n });\r\n this._lastFrameDetected = trackedAnchors;\r\n }\r\n\r\n // process future anchors\r\n this._futureAnchors.forEach((futureAnchor) => {\r\n if (!futureAnchor.resolved && !futureAnchor.submitted) {\r\n this._createAnchorAtTransformation(futureAnchor.xrTransformation, frame).then(\r\n (nativeAnchor) => {\r\n futureAnchor.nativeAnchor = nativeAnchor;\r\n },\r\n (error) => {\r\n futureAnchor.resolved = true;\r\n futureAnchor.reject(error);\r\n }\r\n );\r\n futureAnchor.submitted = true;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * avoiding using Array.find for global support.\r\n * @param xrAnchor the plane to find in the array\r\n */\r\n private _findIndexInAnchorArray(xrAnchor: XRAnchor) {\r\n for (let i = 0; i < this._trackedAnchors.length; ++i) {\r\n if (this._trackedAnchors[i].xrAnchor === xrAnchor) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n private _updateAnchorWithXRFrame(xrAnchor: XRAnchor, anchor: Partial, xrFrame: XRFrame): IWebXRAnchor {\r\n // matrix\r\n const pose = xrFrame.getPose(xrAnchor.anchorSpace, this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const mat = anchor.transformationMatrix || new Matrix();\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n anchor.transformationMatrix = mat;\r\n if (!this._options.worldParentNode) {\r\n // Logger.Warn(\"Please provide a world parent node to apply world transformation\");\r\n } else {\r\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n }\r\n\r\n return anchor;\r\n }\r\n\r\n private async _createAnchorAtTransformation(xrTransformation: XRRigidTransform, xrFrame: XRFrame) {\r\n if (xrFrame.createAnchor) {\r\n try {\r\n return xrFrame.createAnchor(xrTransformation, this._referenceSpaceForFrameAnchors ?? this._xrSessionManager.referenceSpace);\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n } else {\r\n this.detach();\r\n throw new Error(\"Anchors are not enabled in your browser\");\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRAnchorSystem.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRAnchorSystem(xrSessionManager, options);\r\n },\r\n WebXRAnchorSystem.Version\r\n);\r\n","import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3, Matrix, Quaternion } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRLegacyHitTestOptions, IWebXRLegacyHitResult, IWebXRHitTestFeature } from \"./WebXRHitTestLegacy\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Options used for hit testing (version 2)\r\n */\r\nexport interface IWebXRHitTestOptions extends IWebXRLegacyHitTestOptions {\r\n /**\r\n * Do not create a permanent hit test. Will usually be used when only\r\n * transient inputs are needed.\r\n */\r\n disablePermanentHitTest?: boolean;\r\n /**\r\n * Enable transient (for example touch-based) hit test inspections\r\n */\r\n enableTransientHitTest?: boolean;\r\n /**\r\n * Override the default transient hit test profile (generic-touchscreen).\r\n */\r\n transientHitTestProfile?: string;\r\n /**\r\n * Offset ray for the permanent hit test\r\n */\r\n offsetRay?: Vector3;\r\n /**\r\n * Offset ray for the transient hit test\r\n */\r\n transientOffsetRay?: Vector3;\r\n /**\r\n * Instead of using viewer space for hit tests, use the reference space defined in the session manager\r\n */\r\n useReferenceSpace?: boolean;\r\n\r\n /**\r\n * Override the default entity type(s) of the hit-test result\r\n */\r\n entityTypes?: XRHitTestTrackableType[];\r\n}\r\n\r\n/**\r\n * Interface defining the babylon result of hit-test\r\n */\r\nexport interface IWebXRHitResult extends IWebXRLegacyHitResult {\r\n /**\r\n * The input source that generated this hit test (if transient)\r\n */\r\n inputSource?: XRInputSource;\r\n /**\r\n * Is this a transient hit test\r\n */\r\n isTransient?: boolean;\r\n /**\r\n * Position of the hit test result\r\n */\r\n position: Vector3;\r\n /**\r\n * Rotation of the hit test result\r\n */\r\n rotationQuaternion: Quaternion;\r\n\r\n /**\r\n * The native hit test result\r\n */\r\n xrHitResult: XRHitTestResult;\r\n}\r\n\r\n/**\r\n * The currently-working hit-test module.\r\n * Hit test (or Ray-casting) is used to interact with the real world.\r\n * For further information read here - https://github.com/immersive-web/hit-test\r\n *\r\n * Tested on chrome (mobile) 80.\r\n */\r\nexport class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestFeature {\r\n private _tmpMat: Matrix = new Matrix();\r\n private _tmpPos: Vector3 = new Vector3();\r\n private _tmpQuat: Quaternion = new Quaternion();\r\n private _transientXrHitTestSource: Nullable;\r\n // in XR space z-forward is negative\r\n private _xrHitTestSource: Nullable;\r\n private _initHitTestSource = (referenceSpace: XRReferenceSpace) => {\r\n if (!referenceSpace) {\r\n return;\r\n }\r\n const offsetRay = new XRRay(this.options.offsetRay || {});\r\n const hitTestOptions: XRHitTestOptionsInit = {\r\n space: this.options.useReferenceSpace ? referenceSpace : this._xrSessionManager.viewerReferenceSpace,\r\n offsetRay: offsetRay,\r\n };\r\n if (this.options.entityTypes) {\r\n hitTestOptions.entityTypes = this.options.entityTypes;\r\n }\r\n if (!hitTestOptions.space) {\r\n Tools.Warn(\"waiting for viewer reference space to initialize\");\r\n return;\r\n }\r\n this._xrSessionManager.session.requestHitTestSource!(hitTestOptions).then((hitTestSource) => {\r\n if (this._xrHitTestSource) {\r\n this._xrHitTestSource.cancel();\r\n }\r\n this._xrHitTestSource = hitTestSource;\r\n });\r\n };\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.HIT_TEST;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 2;\r\n\r\n /**\r\n * When set to true, each hit test will have its own position/rotation objects\r\n * When set to false, position and rotation objects will be reused for each hit test. It is expected that\r\n * the developers will clone them or copy them as they see fit.\r\n */\r\n public autoCloneTransformation: boolean = false;\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n * Note - this will be called when results come back from the device. It can be an empty array!!\r\n */\r\n public onHitTestResultObservable: Observable = new Observable();\r\n /**\r\n * Use this to temporarily pause hit test checks.\r\n */\r\n public paused: boolean = false;\r\n\r\n /**\r\n * Creates a new instance of the hit test feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRHitTestOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"hit-test\";\r\n Tools.Warn(\"Hit test is an experimental and unstable feature.\");\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n // Feature enabled, but not available\r\n if (!this._xrSessionManager.session.requestHitTestSource) {\r\n return false;\r\n }\r\n\r\n if (!this.options.disablePermanentHitTest) {\r\n if (this._xrSessionManager.referenceSpace) {\r\n this._initHitTestSource(this._xrSessionManager.referenceSpace);\r\n }\r\n this._xrSessionManager.onXRReferenceSpaceChanged.add(this._initHitTestSource);\r\n }\r\n if (this.options.enableTransientHitTest) {\r\n const offsetRay = new XRRay(this.options.transientOffsetRay || {});\r\n this._xrSessionManager.session.requestHitTestSourceForTransientInput!({\r\n profile: this.options.transientHitTestProfile || \"generic-touchscreen\",\r\n offsetRay,\r\n entityTypes: this.options.entityTypes,\r\n }).then((hitSource) => {\r\n this._transientXrHitTestSource = hitSource;\r\n });\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n if (this._xrHitTestSource) {\r\n this._xrHitTestSource.cancel();\r\n this._xrHitTestSource = null;\r\n }\r\n this._xrSessionManager.onXRReferenceSpaceChanged.removeCallback(this._initHitTestSource);\r\n if (this._transientXrHitTestSource) {\r\n this._transientXrHitTestSource.cancel();\r\n this._transientXrHitTestSource = null;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this.onHitTestResultObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n // make sure we do nothing if (async) not attached\r\n if (!this.attached || this.paused) {\r\n return;\r\n }\r\n\r\n if (this._xrHitTestSource) {\r\n const results = frame.getHitTestResults(this._xrHitTestSource);\r\n this._processWebXRHitTestResult(results);\r\n }\r\n if (this._transientXrHitTestSource) {\r\n const hitTestResultsPerInputSource = frame.getHitTestResultsForTransientInput(this._transientXrHitTestSource);\r\n\r\n hitTestResultsPerInputSource.forEach((resultsPerInputSource) => {\r\n this._processWebXRHitTestResult(resultsPerInputSource.results, resultsPerInputSource.inputSource);\r\n });\r\n }\r\n }\r\n\r\n private _processWebXRHitTestResult(hitTestResults: readonly XRHitTestResult[], inputSource?: XRInputSource) {\r\n const results: IWebXRHitResult[] = [];\r\n hitTestResults.forEach((hitTestResult) => {\r\n const pose = hitTestResult.getPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n const pos = pose.transform.position;\r\n const quat = pose.transform.orientation;\r\n this._tmpPos.set(pos.x, pos.y, pos.z);\r\n this._tmpQuat.set(quat.x, quat.y, quat.z, quat.w);\r\n Matrix.FromFloat32ArrayToRefScaled(pose.transform.matrix, 0, 1, this._tmpMat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpPos.z *= -1;\r\n this._tmpQuat.z *= -1;\r\n this._tmpQuat.w *= -1;\r\n this._tmpMat.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n const result: IWebXRHitResult = {\r\n position: this.autoCloneTransformation ? this._tmpPos.clone() : this._tmpPos,\r\n rotationQuaternion: this.autoCloneTransformation ? this._tmpQuat.clone() : this._tmpQuat,\r\n transformationMatrix: this.autoCloneTransformation ? this._tmpMat.clone() : this._tmpMat,\r\n inputSource: inputSource,\r\n isTransient: !!inputSource,\r\n xrHitResult: hitTestResult,\r\n };\r\n results.push(result);\r\n });\r\n\r\n this.onHitTestResultObservable.notifyObservers(results);\r\n }\r\n}\r\n\r\n//register the plugin versions\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRHitTest.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRHitTest(xrSessionManager, options);\r\n },\r\n WebXRHitTest.Version,\r\n false\r\n);\r\n","import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3, Matrix } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\n\r\ndeclare const XRPlane: XRPlane;\r\n\r\n/**\r\n * Options used in the plane detector module\r\n */\r\nexport interface IWebXRPlaneDetectorOptions {\r\n /**\r\n * The node to use to transform the local results to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n /**\r\n * If set to true a reference of the created planes will be kept until the next session starts\r\n * If not defined, planes will be removed from the array when the feature is detached or the session ended.\r\n */\r\n doNotRemovePlanesOnSessionEnded?: boolean;\r\n /**\r\n * Preferred detector configuration, not all preferred options will be supported by all platforms.\r\n */\r\n preferredDetectorOptions?: XRGeometryDetectorOptions;\r\n}\r\n\r\n/**\r\n * A babylon interface for a WebXR plane.\r\n * A Plane is actually a polygon, built from N points in space\r\n *\r\n * Supported in chrome 79, not supported in canary 81 ATM\r\n */\r\nexport interface IWebXRPlane {\r\n /**\r\n * a babylon-assigned ID for this polygon\r\n */\r\n id: number;\r\n /**\r\n * an array of vector3 points in babylon space. right/left hand system is taken into account.\r\n */\r\n polygonDefinition: Array;\r\n /**\r\n * A transformation matrix to apply on the mesh that will be built using the polygonDefinition\r\n * Local vs. World are decided if worldParentNode was provided or not in the options when constructing the module\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * the native xr-plane object\r\n */\r\n xrPlane: XRPlane;\r\n}\r\n\r\nlet planeIdProvider = 0;\r\n\r\n/**\r\n * The plane detector is used to detect planes in the real world when in AR\r\n * For more information see https://github.com/immersive-web/real-world-geometry/\r\n */\r\nexport class WebXRPlaneDetector extends WebXRAbstractFeature {\r\n private _detectedPlanes: Array = [];\r\n private _enabled: boolean = false;\r\n private _lastFrameDetected: XRPlaneSet = new Set();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.PLANE_DETECTION;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Observers registered here will be executed when a new plane was added to the session\r\n */\r\n public onPlaneAddedObservable: Observable = new Observable();\r\n /**\r\n * Observers registered here will be executed when a plane is no longer detected in the session\r\n */\r\n public onPlaneRemovedObservable: Observable = new Observable();\r\n /**\r\n * Observers registered here will be executed when an existing plane updates (for example - expanded)\r\n * This can execute N times every frame\r\n */\r\n public onPlaneUpdatedObservable: Observable = new Observable();\r\n\r\n /**\r\n * construct a new Plane Detector\r\n * @param _xrSessionManager an instance of xr Session manager\r\n * @param _options configuration to use when constructing this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private _options: IWebXRPlaneDetectorOptions = {}) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"plane-detection\";\r\n if (this._xrSessionManager.session) {\r\n this._init();\r\n } else {\r\n this._xrSessionManager.onXRSessionInit.addOnce(() => {\r\n this._init();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.doNotRemovePlanesOnSessionEnded) {\r\n while (this._detectedPlanes.length) {\r\n const toRemove = this._detectedPlanes.pop();\r\n if (toRemove) {\r\n this.onPlaneRemovedObservable.notifyObservers(toRemove);\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this.onPlaneAddedObservable.clear();\r\n this.onPlaneRemovedObservable.clear();\r\n this.onPlaneUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * Check if the needed objects are defined.\r\n * This does not mean that the feature is enabled, but that the objects needed are well defined.\r\n */\r\n public isCompatible(): boolean {\r\n return typeof XRPlane !== \"undefined\";\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n if (!this.attached || !this._enabled || !frame) {\r\n return;\r\n }\r\n\r\n const detectedPlanes = frame.detectedPlanes || frame.worldInformation?.detectedPlanes;\r\n if (detectedPlanes) {\r\n // remove all planes that are not currently detected in the frame\r\n for (let planeIdx = 0; planeIdx < this._detectedPlanes.length; planeIdx++) {\r\n const plane = this._detectedPlanes[planeIdx];\r\n if (!detectedPlanes.has(plane.xrPlane)) {\r\n this._detectedPlanes.splice(planeIdx--, 1);\r\n this.onPlaneRemovedObservable.notifyObservers(plane);\r\n }\r\n }\r\n\r\n // now check for new ones\r\n detectedPlanes.forEach((xrPlane) => {\r\n if (!this._lastFrameDetected.has(xrPlane)) {\r\n const newPlane: Partial = {\r\n id: planeIdProvider++,\r\n xrPlane: xrPlane,\r\n polygonDefinition: [],\r\n };\r\n const plane = this._updatePlaneWithXRPlane(xrPlane, newPlane, frame);\r\n this._detectedPlanes.push(plane);\r\n this.onPlaneAddedObservable.notifyObservers(plane);\r\n } else {\r\n // updated?\r\n if (xrPlane.lastChangedTime === this._xrSessionManager.currentTimestamp) {\r\n const index = this._findIndexInPlaneArray(xrPlane);\r\n const plane = this._detectedPlanes[index];\r\n this._updatePlaneWithXRPlane(xrPlane, plane, frame);\r\n this.onPlaneUpdatedObservable.notifyObservers(plane);\r\n }\r\n }\r\n });\r\n this._lastFrameDetected = detectedPlanes;\r\n }\r\n }\r\n\r\n private _init() {\r\n const internalInit = () => {\r\n this._enabled = true;\r\n if (this._detectedPlanes.length) {\r\n this._detectedPlanes.length = 0;\r\n }\r\n };\r\n\r\n // Only supported by BabylonNative\r\n if (!!this._xrSessionManager.isNative && !!this._options.preferredDetectorOptions && !!this._xrSessionManager.session.trySetPreferredPlaneDetectorOptions) {\r\n this._xrSessionManager.session.trySetPreferredPlaneDetectorOptions(this._options.preferredDetectorOptions);\r\n }\r\n\r\n if (!this._xrSessionManager.session.updateWorldTrackingState) {\r\n internalInit();\r\n return;\r\n }\r\n this._xrSessionManager.session.updateWorldTrackingState({ planeDetectionState: { enabled: true } });\r\n internalInit();\r\n }\r\n\r\n private _updatePlaneWithXRPlane(xrPlane: XRPlane, plane: Partial, xrFrame: XRFrame): IWebXRPlane {\r\n plane.polygonDefinition = xrPlane.polygon.map((xrPoint) => {\r\n const rightHandedSystem = this._xrSessionManager.scene.useRightHandedSystem ? 1 : -1;\r\n return new Vector3(xrPoint.x, xrPoint.y, xrPoint.z * rightHandedSystem);\r\n });\r\n // matrix\r\n const pose = xrFrame.getPose(xrPlane.planeSpace, this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const mat = plane.transformationMatrix || new Matrix();\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n plane.transformationMatrix = mat;\r\n if (this._options.worldParentNode) {\r\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n }\r\n\r\n return plane;\r\n }\r\n\r\n /**\r\n * avoiding using Array.find for global support.\r\n * @param xrPlane the plane to find in the array\r\n */\r\n private _findIndexInPlaneArray(xrPlane: XRPlane) {\r\n for (let i = 0; i < this._detectedPlanes.length; ++i) {\r\n if (this._detectedPlanes[i].xrPlane === xrPlane) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRPlaneDetector.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRPlaneDetector(xrSessionManager, options);\r\n },\r\n WebXRPlaneDetector.Version\r\n);\r\n","import type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable, FloatArray } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { AnimationPropertiesOverride } from \"../Animations/animationPropertiesOverride\";\r\nimport { serialize, SerializationHelper } from \"../Misc/decorators\";\r\nimport { GetClass } from \"../Misc/typeStore\";\r\n\r\nimport type { Animation } from \"../Animations/animation\";\r\n\r\n/**\r\n * Defines a target to use with MorphTargetManager\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets\r\n */\r\nexport class MorphTarget implements IAnimatable {\r\n /**\r\n * Gets or sets the list of animations\r\n */\r\n public animations = new Array();\r\n\r\n private _scene: Nullable;\r\n private _positions: Nullable = null;\r\n private _normals: Nullable = null;\r\n private _tangents: Nullable = null;\r\n private _uvs: Nullable = null;\r\n private _influence: number;\r\n private _uniqueId = 0;\r\n\r\n /**\r\n * Observable raised when the influence changes\r\n */\r\n public onInfluenceChanged = new Observable();\r\n\r\n /** @internal */\r\n public _onDataLayoutChanged = new Observable();\r\n\r\n /**\r\n * Gets or sets the influence of this target (ie. its weight in the overall morphing)\r\n */\r\n public get influence(): number {\r\n return this._influence;\r\n }\r\n\r\n public set influence(influence: number) {\r\n if (this._influence === influence) {\r\n return;\r\n }\r\n\r\n const previous = this._influence;\r\n this._influence = influence;\r\n\r\n if (this.onInfluenceChanged.hasObservers()) {\r\n this.onInfluenceChanged.notifyObservers(previous === 0 || influence === 0);\r\n }\r\n }\r\n\r\n /**\r\n * Gets or sets the id of the morph Target\r\n */\r\n @serialize()\r\n public id: string;\r\n\r\n private _animationPropertiesOverride: Nullable = null;\r\n\r\n /**\r\n * Gets or sets the animation properties override\r\n */\r\n public get animationPropertiesOverride(): Nullable {\r\n if (!this._animationPropertiesOverride && this._scene) {\r\n return this._scene.animationPropertiesOverride;\r\n }\r\n return this._animationPropertiesOverride;\r\n }\r\n\r\n public set animationPropertiesOverride(value: Nullable) {\r\n this._animationPropertiesOverride = value;\r\n }\r\n\r\n /**\r\n * Creates a new MorphTarget\r\n * @param name defines the name of the target\r\n * @param influence defines the influence to use\r\n * @param scene defines the scene the morphtarget belongs to\r\n */\r\n public constructor(\r\n /** defines the name of the target */\r\n public name: string,\r\n influence = 0,\r\n scene: Nullable = null\r\n ) {\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n this.influence = influence;\r\n\r\n if (this._scene) {\r\n this._uniqueId = this._scene.getUniqueId();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the unique ID of this manager\r\n */\r\n public get uniqueId(): number {\r\n return this._uniqueId;\r\n }\r\n\r\n /**\r\n * Gets a boolean defining if the target contains position data\r\n */\r\n public get hasPositions(): boolean {\r\n return !!this._positions;\r\n }\r\n\r\n /**\r\n * Gets a boolean defining if the target contains normal data\r\n */\r\n public get hasNormals(): boolean {\r\n return !!this._normals;\r\n }\r\n\r\n /**\r\n * Gets a boolean defining if the target contains tangent data\r\n */\r\n public get hasTangents(): boolean {\r\n return !!this._tangents;\r\n }\r\n\r\n /**\r\n * Gets a boolean defining if the target contains texture coordinates data\r\n */\r\n public get hasUVs(): boolean {\r\n return !!this._uvs;\r\n }\r\n\r\n /**\r\n * Affects position data to this target\r\n * @param data defines the position data to use\r\n */\r\n public setPositions(data: Nullable) {\r\n const hadPositions = this.hasPositions;\r\n\r\n this._positions = data;\r\n\r\n if (hadPositions !== this.hasPositions) {\r\n this._onDataLayoutChanged.notifyObservers(undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the position data stored in this target\r\n * @returns a FloatArray containing the position data (or null if not present)\r\n */\r\n public getPositions(): Nullable {\r\n return this._positions;\r\n }\r\n\r\n /**\r\n * Affects normal data to this target\r\n * @param data defines the normal data to use\r\n */\r\n public setNormals(data: Nullable) {\r\n const hadNormals = this.hasNormals;\r\n\r\n this._normals = data;\r\n\r\n if (hadNormals !== this.hasNormals) {\r\n this._onDataLayoutChanged.notifyObservers(undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the normal data stored in this target\r\n * @returns a FloatArray containing the normal data (or null if not present)\r\n */\r\n public getNormals(): Nullable {\r\n return this._normals;\r\n }\r\n\r\n /**\r\n * Affects tangent data to this target\r\n * @param data defines the tangent data to use\r\n */\r\n public setTangents(data: Nullable) {\r\n const hadTangents = this.hasTangents;\r\n\r\n this._tangents = data;\r\n\r\n if (hadTangents !== this.hasTangents) {\r\n this._onDataLayoutChanged.notifyObservers(undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the tangent data stored in this target\r\n * @returns a FloatArray containing the tangent data (or null if not present)\r\n */\r\n public getTangents(): Nullable {\r\n return this._tangents;\r\n }\r\n\r\n /**\r\n * Affects texture coordinates data to this target\r\n * @param data defines the texture coordinates data to use\r\n */\r\n public setUVs(data: Nullable) {\r\n const hadUVs = this.hasUVs;\r\n\r\n this._uvs = data;\r\n\r\n if (hadUVs !== this.hasUVs) {\r\n this._onDataLayoutChanged.notifyObservers(undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture coordinates data stored in this target\r\n * @returns a FloatArray containing the texture coordinates data (or null if not present)\r\n */\r\n public getUVs(): Nullable {\r\n return this._uvs;\r\n }\r\n\r\n /**\r\n * Clone the current target\r\n * @returns a new MorphTarget\r\n */\r\n public clone(): MorphTarget {\r\n const newOne = SerializationHelper.Clone(() => new MorphTarget(this.name, this.influence, this._scene), this);\r\n\r\n newOne._positions = this._positions;\r\n newOne._normals = this._normals;\r\n newOne._tangents = this._tangents;\r\n newOne._uvs = this._uvs;\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Serializes the current target into a Serialization object\r\n * @returns the serialized object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.name = this.name;\r\n serializationObject.influence = this.influence;\r\n\r\n serializationObject.positions = Array.prototype.slice.call(this.getPositions());\r\n if (this.id != null) {\r\n serializationObject.id = this.id;\r\n }\r\n if (this.hasNormals) {\r\n serializationObject.normals = Array.prototype.slice.call(this.getNormals());\r\n }\r\n if (this.hasTangents) {\r\n serializationObject.tangents = Array.prototype.slice.call(this.getTangents());\r\n }\r\n if (this.hasUVs) {\r\n serializationObject.uvs = Array.prototype.slice.call(this.getUVs());\r\n }\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(this, serializationObject);\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Returns the string \"MorphTarget\"\r\n * @returns \"MorphTarget\"\r\n */\r\n public getClassName(): string {\r\n return \"MorphTarget\";\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Creates a new target from serialized data\r\n * @param serializationObject defines the serialized data to use\r\n * @param scene defines the hosting scene\r\n * @returns a new MorphTarget\r\n */\r\n public static Parse(serializationObject: any, scene?: Scene): MorphTarget {\r\n const result = new MorphTarget(serializationObject.name, serializationObject.influence);\r\n\r\n result.setPositions(serializationObject.positions);\r\n\r\n if (serializationObject.id != null) {\r\n result.id = serializationObject.id;\r\n }\r\n if (serializationObject.normals) {\r\n result.setNormals(serializationObject.normals);\r\n }\r\n if (serializationObject.tangents) {\r\n result.setTangents(serializationObject.tangents);\r\n }\r\n if (serializationObject.uvs) {\r\n result.setUVs(serializationObject.uvs);\r\n }\r\n\r\n // Animations\r\n if (serializationObject.animations) {\r\n for (let animationIndex = 0; animationIndex < serializationObject.animations.length; animationIndex++) {\r\n const parsedAnimation = serializationObject.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n result.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n\r\n if (serializationObject.autoAnimate && scene) {\r\n scene.beginAnimation(\r\n result,\r\n serializationObject.autoAnimateFrom,\r\n serializationObject.autoAnimateTo,\r\n serializationObject.autoAnimateLoop,\r\n serializationObject.autoAnimateSpeed || 1.0\r\n );\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a MorphTarget from mesh data\r\n * @param mesh defines the source mesh\r\n * @param name defines the name to use for the new target\r\n * @param influence defines the influence to attach to the target\r\n * @returns a new MorphTarget\r\n */\r\n public static FromMesh(mesh: AbstractMesh, name?: string, influence?: number): MorphTarget {\r\n if (!name) {\r\n name = mesh.name;\r\n }\r\n\r\n const result = new MorphTarget(name, influence, mesh.getScene());\r\n\r\n result.setPositions(mesh.getVerticesData(VertexBuffer.PositionKind));\r\n\r\n if (mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {\r\n result.setNormals(mesh.getVerticesData(VertexBuffer.NormalKind));\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {\r\n result.setTangents(mesh.getVerticesData(VertexBuffer.TangentKind));\r\n }\r\n if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {\r\n result.setUVs(mesh.getVerticesData(VertexBuffer.UVKind));\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n","import type { IBufferView, AccessorComponentType, IAccessor } from \"babylonjs-gltf2interface\";\r\nimport { AccessorType } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { FloatArray, Nullable } from \"core/types\";\r\nimport type { Vector4 } from \"core/Maths/math.vector\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class _GLTFUtilities {\r\n /**\r\n * Creates a buffer view based on the supplied arguments\r\n * @param bufferIndex index value of the specified buffer\r\n * @param byteOffset byte offset value\r\n * @param byteLength byte length of the bufferView\r\n * @param byteStride byte distance between conequential elements\r\n * @param name name of the buffer view\r\n * @returns bufferView for glTF\r\n */\r\n public static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView {\r\n const bufferview: IBufferView = { buffer: bufferIndex, byteLength: byteLength };\r\n if (byteOffset) {\r\n bufferview.byteOffset = byteOffset;\r\n }\r\n if (name) {\r\n bufferview.name = name;\r\n }\r\n if (byteStride) {\r\n bufferview.byteStride = byteStride;\r\n }\r\n\r\n return bufferview;\r\n }\r\n\r\n /**\r\n * Creates an accessor based on the supplied arguments\r\n * @param bufferviewIndex The index of the bufferview referenced by this accessor\r\n * @param name The name of the accessor\r\n * @param type The type of the accessor\r\n * @param componentType The datatype of components in the attribute\r\n * @param count The number of attributes referenced by this accessor\r\n * @param byteOffset The offset relative to the start of the bufferView in bytes\r\n * @param min Minimum value of each component in this attribute\r\n * @param max Maximum value of each component in this attribute\r\n * @returns accessor for glTF\r\n */\r\n public static _CreateAccessor(\r\n bufferviewIndex: number,\r\n name: string,\r\n type: AccessorType,\r\n componentType: AccessorComponentType,\r\n count: number,\r\n byteOffset: Nullable,\r\n min: Nullable,\r\n max: Nullable\r\n ): IAccessor {\r\n const accessor: IAccessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };\r\n\r\n if (min != null) {\r\n accessor.min = min;\r\n }\r\n if (max != null) {\r\n accessor.max = max;\r\n }\r\n if (byteOffset != null) {\r\n accessor.byteOffset = byteOffset;\r\n }\r\n\r\n return accessor;\r\n }\r\n\r\n /**\r\n * Calculates the minimum and maximum values of an array of position floats\r\n * @param positions Positions array of a mesh\r\n * @param vertexStart Starting vertex offset to calculate min and max values\r\n * @param vertexCount Number of vertices to check for min and max values\r\n * @returns min number array and max number array\r\n */\r\n public static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number): { min: number[]; max: number[] } {\r\n const min = [Infinity, Infinity, Infinity];\r\n const max = [-Infinity, -Infinity, -Infinity];\r\n const positionStrideSize = 3;\r\n let indexOffset: number;\r\n let position: Vector3;\r\n let vector: number[];\r\n\r\n if (vertexCount) {\r\n for (let i = vertexStart, length = vertexStart + vertexCount; i < length; ++i) {\r\n indexOffset = positionStrideSize * i;\r\n\r\n position = Vector3.FromArray(positions, indexOffset);\r\n vector = position.asArray();\r\n\r\n for (let j = 0; j < positionStrideSize; ++j) {\r\n const num = vector[j];\r\n if (num < min[j]) {\r\n min[j] = num;\r\n }\r\n if (num > max[j]) {\r\n max[j] = num;\r\n }\r\n ++indexOffset;\r\n }\r\n }\r\n }\r\n return { min, max };\r\n }\r\n\r\n public static _NormalizeTangentFromRef(tangent: Vector4) {\r\n const length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);\r\n if (length > 0) {\r\n tangent.x /= length;\r\n tangent.y /= length;\r\n tangent.z /= length;\r\n }\r\n }\r\n\r\n public static _GetDataAccessorElementCount(accessorType: AccessorType) {\r\n switch (accessorType) {\r\n case AccessorType.MAT2:\r\n return 4;\r\n case AccessorType.MAT3:\r\n return 9;\r\n case AccessorType.MAT4:\r\n return 16;\r\n case AccessorType.SCALAR:\r\n return 1;\r\n case AccessorType.VEC2:\r\n return 2;\r\n case AccessorType.VEC3:\r\n return 3;\r\n case AccessorType.VEC4:\r\n return 4;\r\n }\r\n }\r\n}\r\n","import type { IAnimation, INode, IBufferView, IAccessor, IAnimationSampler, IAnimationChannel } from \"babylonjs-gltf2interface\";\r\nimport { AnimationSamplerInterpolation, AnimationChannelTargetPath, AccessorType, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { Node } from \"core/node\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { Animation } from \"core/Animations/animation\";\r\nimport { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { MorphTarget } from \"core/Morph/morphTarget\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\n\r\nimport type { _BinaryWriter } from \"./glTFExporter\";\r\nimport { _GLTFUtilities } from \"./glTFUtilities\";\r\nimport type { IAnimationKey } from \"core/Animations/animationKey\";\r\nimport { AnimationKeyInterpolation } from \"core/Animations/animationKey\";\r\n\r\nimport { Camera } from \"core/Cameras/camera\";\r\nimport { Light } from \"core/Lights/light\";\r\n\r\n/**\r\n * @internal\r\n * Interface to store animation data.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface _IAnimationData {\r\n /**\r\n * Keyframe data.\r\n */\r\n inputs: number[];\r\n /**\r\n * Value data.\r\n */\r\n outputs: number[][];\r\n /**\r\n * Animation interpolation data.\r\n */\r\n samplerInterpolation: AnimationSamplerInterpolation;\r\n /**\r\n * Minimum keyframe value.\r\n */\r\n inputsMin: number;\r\n /**\r\n * Maximum keyframe value.\r\n */\r\n inputsMax: number;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface _IAnimationInfo {\r\n /**\r\n * The target channel for the animation\r\n */\r\n animationChannelTargetPath: AnimationChannelTargetPath;\r\n /**\r\n * The glTF accessor type for the data.\r\n */\r\n dataAccessorType: AccessorType.VEC3 | AccessorType.VEC4 | AccessorType.SCALAR;\r\n /**\r\n * Specifies if quaternions should be used.\r\n */\r\n useQuaternion: boolean;\r\n}\r\n\r\n/**\r\n * @internal\r\n * Enum for handling in tangent and out tangent.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nenum _TangentType {\r\n /**\r\n * Specifies that input tangents are used.\r\n */\r\n INTANGENT,\r\n /**\r\n * Specifies that output tangents are used.\r\n */\r\n OUTTANGENT,\r\n}\r\n\r\n/**\r\n * @internal\r\n * Utility class for generating glTF animation data from BabylonJS.\r\n */\r\nexport class _GLTFAnimation {\r\n /**\r\n * Determine if a node is transformable - ie has properties it should be part of animation of transformation.\r\n * @param babylonNode the node to test\r\n * @returns true if can be animated, false otherwise. False if the parameter is null or undefined.\r\n */\r\n private static _IsTransformable(babylonNode: Node): boolean {\r\n return babylonNode && (babylonNode instanceof TransformNode || babylonNode instanceof Camera || babylonNode instanceof Light);\r\n }\r\n\r\n /**\r\n * @ignore\r\n *\r\n * Creates glTF channel animation from BabylonJS animation.\r\n * @param babylonTransformNode - BabylonJS mesh.\r\n * @param animation - animation.\r\n * @param animationChannelTargetPath - The target animation channel.\r\n * @param useQuaternion - Specifies if quaternions are used.\r\n * @returns nullable IAnimationData\r\n */\r\n public static _CreateNodeAnimation(\r\n babylonTransformNode: Node,\r\n animation: Animation,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n useQuaternion: boolean,\r\n animationSampleRate: number\r\n ): Nullable<_IAnimationData> {\r\n if (this._IsTransformable(babylonTransformNode)) {\r\n const inputs: number[] = [];\r\n const outputs: number[][] = [];\r\n const keyFrames = animation.getKeys();\r\n const minMaxKeyFrames = _GLTFAnimation._CalculateMinMaxKeyFrames(keyFrames);\r\n const interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);\r\n\r\n const interpolation = interpolationOrBake.interpolationType;\r\n const shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;\r\n\r\n if (shouldBakeAnimation) {\r\n _GLTFAnimation._CreateBakedAnimation(\r\n babylonTransformNode,\r\n animation,\r\n animationChannelTargetPath,\r\n minMaxKeyFrames.min,\r\n minMaxKeyFrames.max,\r\n animation.framePerSecond,\r\n animationSampleRate,\r\n inputs,\r\n outputs,\r\n minMaxKeyFrames,\r\n useQuaternion\r\n );\r\n } else {\r\n if (interpolation === AnimationSamplerInterpolation.LINEAR || interpolation === AnimationSamplerInterpolation.STEP) {\r\n _GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion);\r\n } else if (interpolation === AnimationSamplerInterpolation.CUBICSPLINE) {\r\n _GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, inputs, outputs, useQuaternion);\r\n } else {\r\n _GLTFAnimation._CreateBakedAnimation(\r\n babylonTransformNode,\r\n animation,\r\n animationChannelTargetPath,\r\n minMaxKeyFrames.min,\r\n minMaxKeyFrames.max,\r\n animation.framePerSecond,\r\n animationSampleRate,\r\n inputs,\r\n outputs,\r\n minMaxKeyFrames,\r\n useQuaternion\r\n );\r\n }\r\n }\r\n\r\n if (inputs.length && outputs.length) {\r\n const result: _IAnimationData = {\r\n inputs: inputs,\r\n outputs: outputs,\r\n samplerInterpolation: interpolation,\r\n inputsMin: shouldBakeAnimation ? minMaxKeyFrames.min : Tools.FloatRound(minMaxKeyFrames.min / animation.framePerSecond),\r\n inputsMax: shouldBakeAnimation ? minMaxKeyFrames.max : Tools.FloatRound(minMaxKeyFrames.max / animation.framePerSecond),\r\n };\r\n\r\n return result;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private static _DeduceAnimationInfo(animation: Animation): Nullable<_IAnimationInfo> {\r\n let animationChannelTargetPath: Nullable = null;\r\n let dataAccessorType = AccessorType.VEC3;\r\n let useQuaternion: boolean = false;\r\n const property = animation.targetProperty.split(\".\");\r\n switch (property[0]) {\r\n case \"scaling\": {\r\n animationChannelTargetPath = AnimationChannelTargetPath.SCALE;\r\n break;\r\n }\r\n case \"position\": {\r\n animationChannelTargetPath = AnimationChannelTargetPath.TRANSLATION;\r\n break;\r\n }\r\n case \"rotation\": {\r\n dataAccessorType = AccessorType.VEC4;\r\n animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;\r\n break;\r\n }\r\n case \"rotationQuaternion\": {\r\n dataAccessorType = AccessorType.VEC4;\r\n useQuaternion = true;\r\n animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;\r\n break;\r\n }\r\n case \"influence\": {\r\n dataAccessorType = AccessorType.SCALAR;\r\n animationChannelTargetPath = AnimationChannelTargetPath.WEIGHTS;\r\n break;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported animatable property ${property[0]}`);\r\n }\r\n }\r\n if (animationChannelTargetPath) {\r\n return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };\r\n } else {\r\n Tools.Error(\"animation channel target path and data accessor type could be deduced\");\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * @ignore\r\n * Create node animations from the transform node animations\r\n * @param babylonNode\r\n * @param runtimeGLTFAnimation\r\n * @param idleGLTFAnimations\r\n * @param nodeMap\r\n * @param nodes\r\n * @param binaryWriter\r\n * @param bufferViews\r\n * @param accessors\r\n * @param animationSampleRate\r\n */\r\n public static _CreateNodeAnimationFromNodeAnimations(\r\n babylonNode: Node,\r\n runtimeGLTFAnimation: IAnimation,\r\n idleGLTFAnimations: IAnimation[],\r\n nodeMap: { [key: number]: number },\r\n nodes: INode[],\r\n binaryWriter: _BinaryWriter,\r\n bufferViews: IBufferView[],\r\n accessors: IAccessor[],\r\n animationSampleRate: number,\r\n shouldExportAnimation?: (animation: Animation) => boolean\r\n ) {\r\n let glTFAnimation: IAnimation;\r\n if (_GLTFAnimation._IsTransformable(babylonNode)) {\r\n if (babylonNode.animations) {\r\n for (const animation of babylonNode.animations) {\r\n if (shouldExportAnimation && !shouldExportAnimation(animation)) {\r\n continue;\r\n }\r\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);\r\n if (animationInfo) {\r\n glTFAnimation = {\r\n name: animation.name,\r\n samplers: [],\r\n channels: [],\r\n };\r\n _GLTFAnimation._AddAnimation(\r\n `${animation.name}`,\r\n animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation,\r\n babylonNode,\r\n animation,\r\n animationInfo.dataAccessorType,\r\n animationInfo.animationChannelTargetPath,\r\n nodeMap,\r\n binaryWriter,\r\n bufferViews,\r\n accessors,\r\n animationInfo.useQuaternion,\r\n animationSampleRate\r\n );\r\n if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {\r\n idleGLTFAnimations.push(glTFAnimation);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @ignore\r\n * Create individual morph animations from the mesh's morph target animation tracks\r\n * @param babylonNode\r\n * @param runtimeGLTFAnimation\r\n * @param idleGLTFAnimations\r\n * @param nodeMap\r\n * @param nodes\r\n * @param binaryWriter\r\n * @param bufferViews\r\n * @param accessors\r\n * @param animationSampleRate\r\n */\r\n public static _CreateMorphTargetAnimationFromMorphTargetAnimations(\r\n babylonNode: Node,\r\n runtimeGLTFAnimation: IAnimation,\r\n idleGLTFAnimations: IAnimation[],\r\n nodeMap: { [key: number]: number },\r\n nodes: INode[],\r\n binaryWriter: _BinaryWriter,\r\n bufferViews: IBufferView[],\r\n accessors: IAccessor[],\r\n animationSampleRate: number,\r\n shouldExportAnimation?: (animation: Animation) => boolean\r\n ) {\r\n let glTFAnimation: IAnimation;\r\n if (babylonNode instanceof Mesh) {\r\n const morphTargetManager = babylonNode.morphTargetManager;\r\n if (morphTargetManager) {\r\n for (let i = 0; i < morphTargetManager.numTargets; ++i) {\r\n const morphTarget = morphTargetManager.getTarget(i);\r\n for (const animation of morphTarget.animations) {\r\n if (shouldExportAnimation && !shouldExportAnimation(animation)) {\r\n continue;\r\n }\r\n const combinedAnimation = new Animation(\r\n `${animation.name}`,\r\n \"influence\",\r\n animation.framePerSecond,\r\n animation.dataType,\r\n animation.loopMode,\r\n animation.enableBlending\r\n );\r\n const combinedAnimationKeys: IAnimationKey[] = [];\r\n const animationKeys = animation.getKeys();\r\n\r\n for (let j = 0; j < animationKeys.length; ++j) {\r\n const animationKey = animationKeys[j];\r\n for (let k = 0; k < morphTargetManager.numTargets; ++k) {\r\n if (k == i) {\r\n combinedAnimationKeys.push(animationKey);\r\n } else {\r\n combinedAnimationKeys.push({ frame: animationKey.frame, value: 0 });\r\n }\r\n }\r\n }\r\n combinedAnimation.setKeys(combinedAnimationKeys);\r\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimation);\r\n if (animationInfo) {\r\n glTFAnimation = {\r\n name: combinedAnimation.name,\r\n samplers: [],\r\n channels: [],\r\n };\r\n _GLTFAnimation._AddAnimation(\r\n animation.name,\r\n animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation,\r\n babylonNode,\r\n combinedAnimation,\r\n animationInfo.dataAccessorType,\r\n animationInfo.animationChannelTargetPath,\r\n nodeMap,\r\n binaryWriter,\r\n bufferViews,\r\n accessors,\r\n animationInfo.useQuaternion,\r\n animationSampleRate,\r\n morphTargetManager.numTargets\r\n );\r\n if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {\r\n idleGLTFAnimations.push(glTFAnimation);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @ignore\r\n * Create node and morph animations from the animation groups\r\n * @param babylonScene\r\n * @param glTFAnimations\r\n * @param nodeMap\r\n * @param nodes\r\n * @param binaryWriter\r\n * @param bufferViews\r\n * @param accessors\r\n * @param animationSampleRate\r\n */\r\n public static _CreateNodeAndMorphAnimationFromAnimationGroups(\r\n babylonScene: Scene,\r\n glTFAnimations: IAnimation[],\r\n nodeMap: { [key: number]: number },\r\n binaryWriter: _BinaryWriter,\r\n bufferViews: IBufferView[],\r\n accessors: IAccessor[],\r\n animationSampleRate: number,\r\n shouldExportAnimation?: (animation: Animation) => boolean\r\n ) {\r\n let glTFAnimation: IAnimation;\r\n if (babylonScene.animationGroups) {\r\n const animationGroups = babylonScene.animationGroups;\r\n for (const animationGroup of animationGroups) {\r\n const morphAnimations: Map> = new Map();\r\n const sampleAnimations: Map = new Map();\r\n const morphAnimationMeshes: Set = new Set();\r\n const animationGroupFrameDiff = animationGroup.to - animationGroup.from;\r\n glTFAnimation = {\r\n name: animationGroup.name,\r\n channels: [],\r\n samplers: [],\r\n };\r\n for (let i = 0; i < animationGroup.targetedAnimations.length; ++i) {\r\n const targetAnimation = animationGroup.targetedAnimations[i];\r\n const target = targetAnimation.target;\r\n const animation = targetAnimation.animation;\r\n if (shouldExportAnimation && !shouldExportAnimation(animation)) {\r\n continue;\r\n }\r\n if (this._IsTransformable(target) || (target.length === 1 && this._IsTransformable(target[0]))) {\r\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);\r\n if (animationInfo) {\r\n const babylonTransformNode = this._IsTransformable(target) ? target : this._IsTransformable(target[0]) ? target[0] : null;\r\n if (babylonTransformNode) {\r\n _GLTFAnimation._AddAnimation(\r\n `${animation.name}`,\r\n glTFAnimation,\r\n babylonTransformNode,\r\n animation,\r\n animationInfo.dataAccessorType,\r\n animationInfo.animationChannelTargetPath,\r\n nodeMap,\r\n binaryWriter,\r\n bufferViews,\r\n accessors,\r\n animationInfo.useQuaternion,\r\n animationSampleRate\r\n );\r\n }\r\n }\r\n } else if (target instanceof MorphTarget || (target.length === 1 && target[0] instanceof MorphTarget)) {\r\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);\r\n if (animationInfo) {\r\n const babylonMorphTarget = target instanceof MorphTarget ? (target as MorphTarget) : (target[0] as MorphTarget);\r\n if (babylonMorphTarget) {\r\n const babylonMorphTargetManager = babylonScene.morphTargetManagers.find((morphTargetManager) => {\r\n for (let j = 0; j < morphTargetManager.numTargets; ++j) {\r\n if (morphTargetManager.getTarget(j) === babylonMorphTarget) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n });\r\n if (babylonMorphTargetManager) {\r\n const babylonMesh = babylonScene.meshes.find((mesh) => {\r\n return (mesh as Mesh).morphTargetManager === babylonMorphTargetManager;\r\n }) as Mesh;\r\n if (babylonMesh) {\r\n if (!morphAnimations.has(babylonMesh)) {\r\n morphAnimations.set(babylonMesh, new Map());\r\n }\r\n morphAnimations.get(babylonMesh)?.set(babylonMorphTarget, animation);\r\n morphAnimationMeshes.add(babylonMesh);\r\n sampleAnimations.set(babylonMesh, animation);\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n // this is the place for the KHR_animation_pointer.\r\n }\r\n }\r\n morphAnimationMeshes.forEach((mesh) => {\r\n const morphTargetManager = mesh.morphTargetManager!;\r\n let combinedAnimationGroup: Nullable = null;\r\n const animationKeys: IAnimationKey[] = [];\r\n const sampleAnimation = sampleAnimations.get(mesh)!;\r\n const sampleAnimationKeys = sampleAnimation.getKeys();\r\n const numAnimationKeys = sampleAnimationKeys.length;\r\n /*\r\n Due to how glTF expects morph target animation data to be formatted, we need to rearrange the individual morph target animation tracks,\r\n such that we have a single animation, where a given keyframe input value has successive output values for each morph target belonging to the manager.\r\n See: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations\r\n\r\n We do this via constructing a new Animation track, and interleaving the frames of each morph target animation track in the current Animation Group\r\n We reuse the Babylon Animation data structure for ease of handling export of cubic spline animation keys, and to reuse the\r\n existing _GLTFAnimation.AddAnimation codepath with minimal modification, however the constructed Babylon Animation is NOT intended for use in-engine.\r\n */\r\n for (let i = 0; i < numAnimationKeys; ++i) {\r\n for (let j = 0; j < morphTargetManager.numTargets; ++j) {\r\n const morphTarget = morphTargetManager.getTarget(j);\r\n const animationsByMorphTarget = morphAnimations.get(mesh);\r\n if (animationsByMorphTarget) {\r\n const morphTargetAnimation = animationsByMorphTarget.get(morphTarget);\r\n if (morphTargetAnimation) {\r\n if (!combinedAnimationGroup) {\r\n combinedAnimationGroup = new Animation(\r\n `${animationGroup.name}_${mesh.name}_MorphWeightAnimation`,\r\n \"influence\",\r\n morphTargetAnimation.framePerSecond,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n morphTargetAnimation.loopMode,\r\n morphTargetAnimation.enableBlending\r\n );\r\n }\r\n animationKeys.push(morphTargetAnimation.getKeys()[i]);\r\n } else {\r\n animationKeys.push({\r\n frame: animationGroup.from + (animationGroupFrameDiff / numAnimationKeys) * i,\r\n value: morphTarget.influence,\r\n inTangent: sampleAnimationKeys[0].inTangent ? 0 : undefined,\r\n outTangent: sampleAnimationKeys[0].outTangent ? 0 : undefined,\r\n });\r\n }\r\n }\r\n }\r\n }\r\n combinedAnimationGroup!.setKeys(animationKeys);\r\n const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup!);\r\n if (animationInfo) {\r\n _GLTFAnimation._AddAnimation(\r\n `${animationGroup.name}_${mesh.name}_MorphWeightAnimation`,\r\n glTFAnimation,\r\n mesh,\r\n combinedAnimationGroup!,\r\n animationInfo.dataAccessorType,\r\n animationInfo.animationChannelTargetPath,\r\n nodeMap,\r\n binaryWriter,\r\n bufferViews,\r\n accessors,\r\n animationInfo.useQuaternion,\r\n animationSampleRate,\r\n morphTargetManager?.numTargets\r\n );\r\n }\r\n });\r\n if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {\r\n glTFAnimations.push(glTFAnimation);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private static _AddAnimation(\r\n name: string,\r\n glTFAnimation: IAnimation,\r\n babylonTransformNode: Node,\r\n animation: Animation,\r\n dataAccessorType: AccessorType,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n nodeMap: { [key: number]: number },\r\n binaryWriter: _BinaryWriter,\r\n bufferViews: IBufferView[],\r\n accessors: IAccessor[],\r\n useQuaternion: boolean,\r\n animationSampleRate: number,\r\n morphAnimationChannels?: number\r\n ) {\r\n const animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, useQuaternion, animationSampleRate);\r\n let bufferView: IBufferView;\r\n let accessor: IAccessor;\r\n let keyframeAccessorIndex: number;\r\n let dataAccessorIndex: number;\r\n let outputLength: number;\r\n let animationSampler: IAnimationSampler;\r\n let animationChannel: IAnimationChannel;\r\n\r\n if (animationData) {\r\n /*\r\n * Now that we have the glTF converted morph target animation data,\r\n * we can remove redundant input data so that we have n input frames,\r\n * and morphAnimationChannels * n output frames\r\n */\r\n if (morphAnimationChannels) {\r\n let index = 0;\r\n let currentInput: number = 0;\r\n const newInputs: number[] = [];\r\n while (animationData.inputs.length > 0) {\r\n currentInput = animationData.inputs.shift()!;\r\n if (index % morphAnimationChannels == 0) {\r\n newInputs.push(currentInput);\r\n }\r\n index++;\r\n }\r\n animationData.inputs = newInputs;\r\n }\r\n\r\n const nodeIndex = nodeMap[babylonTransformNode.uniqueId];\r\n\r\n // Creates buffer view and accessor for key frames.\r\n let byteLength = animationData.inputs.length * 4;\r\n bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} keyframe data view`);\r\n bufferViews.push(bufferView);\r\n animationData.inputs.forEach(function (input) {\r\n binaryWriter.setFloat32(input);\r\n });\r\n\r\n accessor = _GLTFUtilities._CreateAccessor(\r\n bufferViews.length - 1,\r\n `${name} keyframes`,\r\n AccessorType.SCALAR,\r\n AccessorComponentType.FLOAT,\r\n animationData.inputs.length,\r\n null,\r\n [animationData.inputsMin],\r\n [animationData.inputsMax]\r\n );\r\n accessors.push(accessor);\r\n keyframeAccessorIndex = accessors.length - 1;\r\n\r\n // create bufferview and accessor for keyed values.\r\n outputLength = animationData.outputs.length;\r\n byteLength = _GLTFUtilities._GetDataAccessorElementCount(dataAccessorType) * 4 * animationData.outputs.length;\r\n\r\n // check for in and out tangents\r\n bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} data view`);\r\n bufferViews.push(bufferView);\r\n\r\n animationData.outputs.forEach(function (output) {\r\n output.forEach(function (entry) {\r\n binaryWriter.setFloat32(entry);\r\n });\r\n });\r\n\r\n accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} data`, dataAccessorType, AccessorComponentType.FLOAT, outputLength, null, null, null);\r\n accessors.push(accessor);\r\n dataAccessorIndex = accessors.length - 1;\r\n\r\n // create sampler\r\n animationSampler = {\r\n interpolation: animationData.samplerInterpolation,\r\n input: keyframeAccessorIndex,\r\n output: dataAccessorIndex,\r\n };\r\n glTFAnimation.samplers.push(animationSampler);\r\n\r\n // create channel\r\n animationChannel = {\r\n sampler: glTFAnimation.samplers.length - 1,\r\n target: {\r\n node: nodeIndex,\r\n path: animationChannelTargetPath,\r\n },\r\n };\r\n glTFAnimation.channels.push(animationChannel);\r\n }\r\n }\r\n\r\n /**\r\n * Create a baked animation\r\n * @param babylonTransformNode BabylonJS mesh\r\n * @param animation BabylonJS animation corresponding to the BabylonJS mesh\r\n * @param animationChannelTargetPath animation target channel\r\n * @param minFrame minimum animation frame\r\n * @param maxFrame maximum animation frame\r\n * @param fps frames per second of the animation\r\n * @param sampleRate\r\n * @param inputs input key frames of the animation\r\n * @param outputs output key frame data of the animation\r\n * @param minMaxFrames\r\n * @param minMaxFrames.min\r\n * @param minMaxFrames.max\r\n * @param useQuaternion specifies if quaternions should be used\r\n */\r\n private static _CreateBakedAnimation(\r\n babylonTransformNode: Node,\r\n animation: Animation,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n minFrame: number,\r\n maxFrame: number,\r\n fps: number,\r\n sampleRate: number,\r\n inputs: number[],\r\n outputs: number[][],\r\n minMaxFrames: { min: number; max: number },\r\n useQuaternion: boolean\r\n ) {\r\n let value: number | Vector3 | Quaternion;\r\n const quaternionCache: Quaternion = Quaternion.Identity();\r\n let previousTime: Nullable = null;\r\n let time: number;\r\n let maxUsedFrame: Nullable = null;\r\n let currKeyFrame: Nullable = null;\r\n let nextKeyFrame: Nullable = null;\r\n let prevKeyFrame: Nullable = null;\r\n let endFrame: Nullable = null;\r\n minMaxFrames.min = Tools.FloatRound(minFrame / fps);\r\n\r\n const keyFrames = animation.getKeys();\r\n\r\n for (let i = 0, length = keyFrames.length; i < length; ++i) {\r\n endFrame = null;\r\n currKeyFrame = keyFrames[i];\r\n\r\n if (i + 1 < length) {\r\n nextKeyFrame = keyFrames[i + 1];\r\n if ((currKeyFrame.value.equals && currKeyFrame.value.equals(nextKeyFrame.value)) || currKeyFrame.value === nextKeyFrame.value) {\r\n if (i === 0) {\r\n // set the first frame to itself\r\n endFrame = currKeyFrame.frame;\r\n } else {\r\n continue;\r\n }\r\n } else {\r\n endFrame = nextKeyFrame.frame;\r\n }\r\n } else {\r\n // at the last key frame\r\n prevKeyFrame = keyFrames[i - 1];\r\n if ((currKeyFrame.value.equals && currKeyFrame.value.equals(prevKeyFrame.value)) || currKeyFrame.value === prevKeyFrame.value) {\r\n continue;\r\n } else {\r\n endFrame = maxFrame;\r\n }\r\n }\r\n if (endFrame) {\r\n for (let f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {\r\n time = Tools.FloatRound(f / fps);\r\n if (time === previousTime) {\r\n continue;\r\n }\r\n previousTime = time;\r\n maxUsedFrame = time;\r\n const state = {\r\n key: 0,\r\n repeatCount: 0,\r\n loopMode: animation.loopMode,\r\n };\r\n value = animation._interpolate(f, state);\r\n\r\n _GLTFAnimation._SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, useQuaternion);\r\n }\r\n }\r\n }\r\n if (maxUsedFrame) {\r\n minMaxFrames.max = maxUsedFrame;\r\n }\r\n }\r\n\r\n private static _ConvertFactorToVector3OrQuaternion(\r\n factor: number,\r\n babylonTransformNode: Node,\r\n animation: Animation,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n useQuaternion: boolean\r\n ): Vector3 | Quaternion {\r\n const basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, useQuaternion);\r\n // handles single component x, y, z or w component animation by using a base property and animating over a component.\r\n const property = animation.targetProperty.split(\".\");\r\n const componentName = property ? property[1] : \"\"; // x, y, z, or w component\r\n const value = useQuaternion ? Quaternion.FromArray(basePositionRotationOrScale).normalize() : Vector3.FromArray(basePositionRotationOrScale);\r\n\r\n switch (componentName) {\r\n case \"x\":\r\n case \"y\":\r\n case \"z\": {\r\n value[componentName] = factor;\r\n break;\r\n }\r\n case \"w\": {\r\n (value as Quaternion).w = factor;\r\n break;\r\n }\r\n default: {\r\n Tools.Error(`glTFAnimation: Unsupported component name \"${componentName}\"!`);\r\n }\r\n }\r\n\r\n return value;\r\n }\r\n\r\n private static _SetInterpolatedValue(\r\n babylonTransformNode: Node,\r\n value: number | Vector3 | Quaternion,\r\n time: number,\r\n animation: Animation,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n quaternionCache: Quaternion,\r\n inputs: number[],\r\n outputs: number[][],\r\n useQuaternion: boolean\r\n ) {\r\n let cacheValue: Vector3 | Quaternion | number;\r\n inputs.push(time);\r\n\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.WEIGHTS) {\r\n outputs.push([value as number]);\r\n return;\r\n }\r\n\r\n if (animation.dataType === Animation.ANIMATIONTYPE_FLOAT) {\r\n value = this._ConvertFactorToVector3OrQuaternion(value as number, babylonTransformNode, animation, animationChannelTargetPath, useQuaternion);\r\n }\r\n\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {\r\n if (useQuaternion) {\r\n quaternionCache = value as Quaternion;\r\n } else {\r\n cacheValue = value as Vector3;\r\n Quaternion.RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);\r\n }\r\n outputs.push(quaternionCache.asArray());\r\n } else {\r\n // scaling and position animation\r\n cacheValue = value as Vector3;\r\n outputs.push(cacheValue.asArray());\r\n }\r\n }\r\n\r\n /**\r\n * Creates linear animation from the animation key frames\r\n * @param babylonTransformNode BabylonJS mesh\r\n * @param animation BabylonJS animation\r\n * @param animationChannelTargetPath The target animation channel\r\n * @param inputs Array to store the key frame times\r\n * @param outputs Array to store the key frame data\r\n * @param useQuaternion Specifies if quaternions are used in the animation\r\n */\r\n private static _CreateLinearOrStepAnimation(\r\n babylonTransformNode: Node,\r\n animation: Animation,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n inputs: number[],\r\n outputs: number[][],\r\n useQuaternion: boolean\r\n ) {\r\n for (const keyFrame of animation.getKeys()) {\r\n inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.\r\n _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, useQuaternion);\r\n }\r\n }\r\n\r\n /**\r\n * Creates cubic spline animation from the animation key frames\r\n * @param babylonTransformNode BabylonJS mesh\r\n * @param animation BabylonJS animation\r\n * @param animationChannelTargetPath The target animation channel\r\n * @param frameDelta The difference between the last and first frame of the animation\r\n * @param inputs Array to store the key frame times\r\n * @param outputs Array to store the key frame data\r\n * @param useQuaternion Specifies if quaternions are used in the animation\r\n */\r\n private static _CreateCubicSplineAnimation(\r\n babylonTransformNode: Node,\r\n animation: Animation,\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n inputs: number[],\r\n outputs: number[][],\r\n useQuaternion: boolean\r\n ) {\r\n animation.getKeys().forEach(function (keyFrame) {\r\n inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.\r\n _GLTFAnimation._AddSplineTangent(_TangentType.INTANGENT, outputs, animationChannelTargetPath, AnimationSamplerInterpolation.CUBICSPLINE, keyFrame, useQuaternion);\r\n _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, useQuaternion);\r\n\r\n _GLTFAnimation._AddSplineTangent(_TangentType.OUTTANGENT, outputs, animationChannelTargetPath, AnimationSamplerInterpolation.CUBICSPLINE, keyFrame, useQuaternion);\r\n });\r\n }\r\n\r\n private static _GetBasePositionRotationOrScale(babylonTransformNode: Node, animationChannelTargetPath: AnimationChannelTargetPath, useQuaternion: boolean) {\r\n let basePositionRotationOrScale: number[];\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {\r\n if (useQuaternion) {\r\n const q = (babylonTransformNode as TransformNode).rotationQuaternion;\r\n basePositionRotationOrScale = (q ?? Quaternion.Identity()).asArray();\r\n } else {\r\n const r: Vector3 = (babylonTransformNode as TransformNode).rotation;\r\n basePositionRotationOrScale = (r ?? Vector3.Zero()).asArray();\r\n }\r\n } else if (animationChannelTargetPath === AnimationChannelTargetPath.TRANSLATION) {\r\n const p: Vector3 = (babylonTransformNode as TransformNode).position;\r\n basePositionRotationOrScale = (p ?? Vector3.Zero()).asArray();\r\n } else {\r\n // scale\r\n const s: Vector3 = (babylonTransformNode as TransformNode).scaling;\r\n basePositionRotationOrScale = (s ?? Vector3.One()).asArray();\r\n }\r\n return basePositionRotationOrScale;\r\n }\r\n\r\n /**\r\n * Adds a key frame value\r\n * @param keyFrame\r\n * @param animation\r\n * @param outputs\r\n * @param animationChannelTargetPath\r\n * @param babylonTransformNode\r\n * @param useQuaternion\r\n */\r\n private static _AddKeyframeValue(\r\n keyFrame: IAnimationKey,\r\n animation: Animation,\r\n outputs: number[][],\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n babylonTransformNode: Node,\r\n useQuaternion: boolean\r\n ) {\r\n let newPositionRotationOrScale: Nullable;\r\n const animationType = animation.dataType;\r\n if (animationType === Animation.ANIMATIONTYPE_VECTOR3) {\r\n let value = keyFrame.value.asArray();\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {\r\n const array = Vector3.FromArray(value);\r\n const rotationQuaternion = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z);\r\n value = rotationQuaternion.asArray();\r\n }\r\n outputs.push(value); // scale vector.\r\n } else if (animationType === Animation.ANIMATIONTYPE_FLOAT) {\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.WEIGHTS) {\r\n outputs.push([keyFrame.value]);\r\n } else {\r\n // handles single component x, y, z or w component animation by using a base property and animating over a component.\r\n newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(\r\n keyFrame.value as number,\r\n babylonTransformNode,\r\n animation,\r\n animationChannelTargetPath,\r\n useQuaternion\r\n );\r\n if (newPositionRotationOrScale) {\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {\r\n const posRotScale = useQuaternion\r\n ? (newPositionRotationOrScale as Quaternion)\r\n : Quaternion.RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();\r\n outputs.push(posRotScale.asArray());\r\n }\r\n outputs.push(newPositionRotationOrScale.asArray());\r\n }\r\n }\r\n } else if (animationType === Animation.ANIMATIONTYPE_QUATERNION) {\r\n outputs.push((keyFrame.value as Quaternion).normalize().asArray());\r\n } else {\r\n Tools.Error(\"glTFAnimation: Unsupported key frame values for animation!\");\r\n }\r\n }\r\n\r\n /**\r\n * Determine the interpolation based on the key frames\r\n * @param keyFrames\r\n * @param animationChannelTargetPath\r\n * @param useQuaternion\r\n */\r\n private static _DeduceInterpolation(\r\n keyFrames: IAnimationKey[],\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n useQuaternion: boolean\r\n ): { interpolationType: AnimationSamplerInterpolation; shouldBakeAnimation: boolean } {\r\n let interpolationType: AnimationSamplerInterpolation | undefined;\r\n let shouldBakeAnimation = false;\r\n let key: IAnimationKey;\r\n\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION && !useQuaternion) {\r\n return { interpolationType: AnimationSamplerInterpolation.LINEAR, shouldBakeAnimation: true };\r\n }\r\n\r\n for (let i = 0, length = keyFrames.length; i < length; ++i) {\r\n key = keyFrames[i];\r\n if (key.inTangent || key.outTangent) {\r\n if (interpolationType) {\r\n if (interpolationType !== AnimationSamplerInterpolation.CUBICSPLINE) {\r\n interpolationType = AnimationSamplerInterpolation.LINEAR;\r\n shouldBakeAnimation = true;\r\n break;\r\n }\r\n } else {\r\n interpolationType = AnimationSamplerInterpolation.CUBICSPLINE;\r\n }\r\n } else {\r\n if (interpolationType) {\r\n if (\r\n interpolationType === AnimationSamplerInterpolation.CUBICSPLINE ||\r\n (key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP && interpolationType !== AnimationSamplerInterpolation.STEP)\r\n ) {\r\n interpolationType = AnimationSamplerInterpolation.LINEAR;\r\n shouldBakeAnimation = true;\r\n break;\r\n }\r\n } else {\r\n if (key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP) {\r\n interpolationType = AnimationSamplerInterpolation.STEP;\r\n } else {\r\n interpolationType = AnimationSamplerInterpolation.LINEAR;\r\n }\r\n }\r\n }\r\n }\r\n if (!interpolationType) {\r\n interpolationType = AnimationSamplerInterpolation.LINEAR;\r\n }\r\n\r\n return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };\r\n }\r\n\r\n /**\r\n * Adds an input tangent or output tangent to the output data\r\n * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion\r\n * @param babylonTransformNode\r\n * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)\r\n * @param outputs The animation data by keyframe\r\n * @param animationChannelTargetPath The target animation channel\r\n * @param interpolation The interpolation type\r\n * @param keyFrame The key frame with the animation data\r\n * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta\r\n * @param useQuaternion Specifies if quaternions are used\r\n */\r\n private static _AddSplineTangent(\r\n tangentType: _TangentType,\r\n outputs: number[][],\r\n animationChannelTargetPath: AnimationChannelTargetPath,\r\n interpolation: AnimationSamplerInterpolation,\r\n keyFrame: IAnimationKey,\r\n useQuaternion: boolean\r\n ) {\r\n let tangent: number[];\r\n const tangentValue: Vector3 | Quaternion | number = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;\r\n if (interpolation === AnimationSamplerInterpolation.CUBICSPLINE) {\r\n if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {\r\n if (tangentValue) {\r\n if (useQuaternion) {\r\n tangent = (tangentValue as Quaternion).asArray();\r\n } else {\r\n const array = tangentValue as Vector3;\r\n tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();\r\n }\r\n } else {\r\n tangent = [0, 0, 0, 0];\r\n }\r\n } else if (animationChannelTargetPath === AnimationChannelTargetPath.WEIGHTS) {\r\n if (tangentValue) {\r\n tangent = [tangentValue as number];\r\n } else {\r\n tangent = [0];\r\n }\r\n } else {\r\n if (tangentValue) {\r\n tangent = (tangentValue as Vector3).asArray();\r\n } else {\r\n tangent = [0, 0, 0];\r\n }\r\n }\r\n\r\n outputs.push(tangent);\r\n }\r\n }\r\n\r\n /**\r\n * Get the minimum and maximum key frames' frame values\r\n * @param keyFrames animation key frames\r\n * @returns the minimum and maximum key frame value\r\n */\r\n private static _CalculateMinMaxKeyFrames(keyFrames: IAnimationKey[]): { min: number; max: number } {\r\n let min: number = Infinity;\r\n let max: number = -Infinity;\r\n keyFrames.forEach(function (keyFrame) {\r\n min = Math.min(min, keyFrame.frame);\r\n max = Math.max(max, keyFrame.frame);\r\n });\r\n\r\n return { min: min, max: max };\r\n }\r\n}\r\n","import { ImageMimeType } from \"babylonjs-gltf2interface\";\r\n\r\n/**\r\n * Class for holding and downloading glTF file data\r\n */\r\nexport class GLTFData {\r\n /**\r\n * Object which contains the file name as the key and its data as the value\r\n */\r\n glTFFiles: { [fileName: string]: string | Blob };\r\n\r\n /**\r\n * Initializes the glTF file object\r\n */\r\n public constructor() {\r\n this.glTFFiles = {};\r\n }\r\n\r\n /**\r\n * Downloads the glTF data as files based on their names and data\r\n */\r\n public downloadFiles(): void {\r\n /**\r\n * Checks for a matching suffix at the end of a string (for ES5 and lower)\r\n * @param str Source string\r\n * @param suffix Suffix to search for in the source string\r\n * @returns Boolean indicating whether the suffix was found (true) or not (false)\r\n */\r\n function endsWith(str: string, suffix: string): boolean {\r\n return str.indexOf(suffix, str.length - suffix.length) !== -1;\r\n }\r\n\r\n for (const key in this.glTFFiles) {\r\n const link = document.createElement(\"a\");\r\n document.body.appendChild(link);\r\n link.setAttribute(\"type\", \"hidden\");\r\n link.download = key;\r\n const blob = this.glTFFiles[key];\r\n let mimeType;\r\n\r\n if (endsWith(key, \".glb\")) {\r\n mimeType = { type: \"model/gltf-binary\" };\r\n } else if (endsWith(key, \".bin\")) {\r\n mimeType = { type: \"application/octet-stream\" };\r\n } else if (endsWith(key, \".gltf\")) {\r\n mimeType = { type: \"model/gltf+json\" };\r\n } else if (endsWith(key, \".jpeg\") || endsWith(key, \".jpg\")) {\r\n mimeType = { type: ImageMimeType.JPEG };\r\n } else if (endsWith(key, \".png\")) {\r\n mimeType = { type: ImageMimeType.PNG };\r\n }\r\n\r\n link.href = window.URL.createObjectURL(new Blob([blob], mimeType));\r\n link.click();\r\n }\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Constants } from \"../constants\";\r\nimport { ThinEngine } from \"../thinEngine\";\r\nimport type { IWebRequest } from \"../../Misc/interfaces/iWebRequest\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a raw texture\r\n * @param data defines the data to store in the texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param format defines the format of the data\r\n * @param generateMipMaps defines if the engine should generate the mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)\r\n * @param compression defines the compression used (null by default)\r\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns the raw texture inside an InternalTexture\r\n */\r\n createRawTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable,\r\n type: number,\r\n creationFlags?: number,\r\n useSRGBBuffer?: boolean\r\n ): InternalTexture;\r\n\r\n /**\r\n * Update a raw texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store in the texture\r\n * @param format defines the format of the data\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n */\r\n updateRawTexture(texture: Nullable, data: Nullable, format: number, invertY: boolean): void;\r\n\r\n /**\r\n * Update a raw texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store in the texture\r\n * @param format defines the format of the data\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param compression defines the compression used (null by default)\r\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n */\r\n updateRawTexture(\r\n texture: Nullable,\r\n data: Nullable,\r\n format: number,\r\n invertY: boolean,\r\n compression: Nullable,\r\n type: number,\r\n useSRGBBuffer: boolean\r\n ): void;\r\n\r\n /**\r\n * Creates a new raw cube texture\r\n * @param data defines the array of data to use to create each face\r\n * @param size defines the size of the textures\r\n * @param format defines the format of the data\r\n * @param type defines the type of the data (like Engine.TEXTURETYPE_UNSIGNED_INT)\r\n * @param generateMipMaps defines if the engine should generate the mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param compression defines the compression used (null by default)\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createRawCubeTexture(\r\n data: Nullable,\r\n size: number,\r\n format: number,\r\n type: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable\r\n ): InternalTexture;\r\n\r\n /**\r\n * Update a raw cube texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n */\r\n updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean): void;\r\n\r\n /**\r\n * Update a raw cube texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param compression defines the compression used (null by default)\r\n */\r\n updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable): void;\r\n\r\n /**\r\n * Update a raw cube texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param compression defines the compression used (null by default)\r\n * @param level defines which level of the texture to update\r\n */\r\n updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable, level: number): void;\r\n\r\n /**\r\n * Creates a new raw cube texture from a specified url\r\n * @param url defines the url where the data is located\r\n * @param scene defines the current scene\r\n * @param size defines the size of the textures\r\n * @param format defines the format of the data\r\n * @param type defines the type fo the data (like Engine.TEXTURETYPE_UNSIGNED_INT)\r\n * @param noMipmap defines if the engine should avoid generating the mip levels\r\n * @param callback defines a callback used to extract texture data from loaded data\r\n * @param mipmapGenerator defines to provide an optional tool to generate mip levels\r\n * @param onLoad defines a callback called when texture is loaded\r\n * @param onError defines a callback called if there is an error\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createRawCubeTextureFromUrl(\r\n url: string,\r\n scene: Nullable,\r\n size: number,\r\n format: number,\r\n type: number,\r\n noMipmap: boolean,\r\n callback: (ArrayBuffer: ArrayBuffer) => Nullable,\r\n mipmapGenerator: Nullable<(faces: ArrayBufferView[]) => ArrayBufferView[][]>,\r\n onLoad: Nullable<() => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>\r\n ): InternalTexture;\r\n\r\n /**\r\n * Creates a new raw cube texture from a specified url\r\n * @param url defines the url where the data is located\r\n * @param scene defines the current scene\r\n * @param size defines the size of the textures\r\n * @param format defines the format of the data\r\n * @param type defines the type fo the data (like Engine.TEXTURETYPE_UNSIGNED_INT)\r\n * @param noMipmap defines if the engine should avoid generating the mip levels\r\n * @param callback defines a callback used to extract texture data from loaded data\r\n * @param mipmapGenerator defines to provide an optional tool to generate mip levels\r\n * @param onLoad defines a callback called when texture is loaded\r\n * @param onError defines a callback called if there is an error\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @returns the cube texture as an InternalTexture\r\n */\r\n createRawCubeTextureFromUrl(\r\n url: string,\r\n scene: Nullable,\r\n size: number,\r\n format: number,\r\n type: number,\r\n noMipmap: boolean,\r\n callback: (ArrayBuffer: ArrayBuffer) => Nullable,\r\n mipmapGenerator: Nullable<(faces: ArrayBufferView[]) => ArrayBufferView[][]>,\r\n onLoad: Nullable<() => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>,\r\n samplingMode: number,\r\n invertY: boolean\r\n ): InternalTexture;\r\n\r\n /**\r\n * Creates a new raw 3D texture\r\n * @param data defines the data used to create the texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param depth defines the depth of the texture\r\n * @param format defines the format of the texture\r\n * @param generateMipMaps defines if the engine must generate mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param compression defines the compressed used (can be null)\r\n * @param textureType defines the compressed used (can be null)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @returns a new raw 3D texture (stored in an InternalTexture)\r\n */\r\n createRawTexture3D(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable,\r\n textureType: number,\r\n creationFlags?: number\r\n ): InternalTexture;\r\n\r\n /**\r\n * Update a raw 3D texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n */\r\n updateRawTexture3D(texture: InternalTexture, data: Nullable, format: number, invertY: boolean): void;\r\n\r\n /**\r\n * Update a raw 3D texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param compression defines the used compression (can be null)\r\n * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)\r\n */\r\n updateRawTexture3D(texture: InternalTexture, data: Nullable, format: number, invertY: boolean, compression: Nullable, textureType: number): void;\r\n\r\n /**\r\n * Creates a new raw 2D array texture\r\n * @param data defines the data used to create the texture\r\n * @param width defines the width of the texture\r\n * @param height defines the height of the texture\r\n * @param depth defines the number of layers of the texture\r\n * @param format defines the format of the texture\r\n * @param generateMipMaps defines if the engine must generate mip levels\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)\r\n * @param compression defines the compressed used (can be null)\r\n * @param textureType defines the compressed used (can be null)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @returns a new raw 2D array texture (stored in an InternalTexture)\r\n */\r\n createRawTexture2DArray(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable,\r\n textureType: number,\r\n creationFlags?: number\r\n ): InternalTexture;\r\n\r\n /**\r\n * Update a raw 2D array texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n */\r\n updateRawTexture2DArray(texture: InternalTexture, data: Nullable, format: number, invertY: boolean): void;\r\n\r\n /**\r\n * Update a raw 2D array texture\r\n * @param texture defines the texture to update\r\n * @param data defines the data to store\r\n * @param format defines the data format\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n * @param compression defines the used compression (can be null)\r\n * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)\r\n */\r\n updateRawTexture2DArray(\r\n texture: InternalTexture,\r\n data: Nullable,\r\n format: number,\r\n invertY: boolean,\r\n compression: Nullable,\r\n textureType: number\r\n ): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.updateRawTexture = function (\r\n texture: Nullable,\r\n data: Nullable,\r\n format: number,\r\n invertY: boolean,\r\n compression: Nullable = null,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n useSRGBBuffer: boolean = false\r\n): void {\r\n if (!texture) {\r\n return;\r\n }\r\n // Babylon's internalSizedFomat but gl's texImage2D internalFormat\r\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);\r\n\r\n // Babylon's internalFormat but gl's texImage2D format\r\n const internalFormat = this._getInternalFormat(format);\r\n const textureType = this._getWebGLTextureType(type);\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\r\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\r\n\r\n if (!this._doNotHandleContextLost) {\r\n texture._bufferView = data;\r\n texture.format = format;\r\n texture.type = type;\r\n texture.invertY = invertY;\r\n texture._compression = compression;\r\n }\r\n\r\n if (texture.width % 4 !== 0) {\r\n this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);\r\n }\r\n\r\n if (compression && data) {\r\n this._gl.compressedTexImage2D(this._gl.TEXTURE_2D, 0, (this.getCaps().s3tc)[compression], texture.width, texture.height, 0, data);\r\n } else {\r\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, data);\r\n }\r\n\r\n if (texture.generateMipMaps) {\r\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\r\n }\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n // this.resetTextureCache();\r\n texture.isReady = true;\r\n};\r\n\r\nThinEngine.prototype.createRawTexture = function (\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n creationFlags = 0,\r\n useSRGBBuffer = false\r\n): InternalTexture {\r\n const texture = new InternalTexture(this, InternalTextureSource.Raw);\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n texture.width = width;\r\n texture.height = height;\r\n texture.format = format;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n texture.invertY = invertY;\r\n texture._compression = compression;\r\n texture.type = type;\r\n texture._useSRGBBuffer = this._getUseSRGBBuffer(useSRGBBuffer, !generateMipMaps);\r\n\r\n if (!this._doNotHandleContextLost) {\r\n texture._bufferView = data;\r\n }\r\n\r\n this.updateRawTexture(texture, data, format, invertY, compression, type, texture._useSRGBBuffer);\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\r\n\r\n // Filters\r\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\r\n\r\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);\r\n this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);\r\n\r\n if (generateMipMaps) {\r\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\r\n }\r\n\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n return texture;\r\n};\r\n\r\nThinEngine.prototype.createRawCubeTexture = function (\r\n data: Nullable,\r\n size: number,\r\n format: number,\r\n type: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null\r\n): InternalTexture {\r\n const gl = this._gl;\r\n const texture = new InternalTexture(this, InternalTextureSource.CubeRaw);\r\n texture.isCube = true;\r\n texture.format = format;\r\n texture.type = type;\r\n if (!this._doNotHandleContextLost) {\r\n texture._bufferViewArray = data;\r\n }\r\n\r\n const textureType = this._getWebGLTextureType(type);\r\n let internalFormat = this._getInternalFormat(format);\r\n\r\n if (internalFormat === gl.RGB) {\r\n internalFormat = gl.RGBA;\r\n }\r\n\r\n // Mipmap generation needs a sized internal format that is both color-renderable and texture-filterable\r\n if (textureType === gl.FLOAT && !this._caps.textureFloatLinearFiltering) {\r\n generateMipMaps = false;\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n Logger.Warn(\"Float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.\");\r\n } else if (textureType === this._gl.HALF_FLOAT_OES && !this._caps.textureHalfFloatLinearFiltering) {\r\n generateMipMaps = false;\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n Logger.Warn(\"Half float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.\");\r\n } else if (textureType === gl.FLOAT && !this._caps.textureFloatRender) {\r\n generateMipMaps = false;\r\n Logger.Warn(\"Render to float textures is not supported. Mipmap generation forced to false.\");\r\n } else if (textureType === gl.HALF_FLOAT && !this._caps.colorBufferFloat) {\r\n generateMipMaps = false;\r\n Logger.Warn(\"Render to half float textures is not supported. Mipmap generation forced to false.\");\r\n }\r\n\r\n const width = size;\r\n const height = width;\r\n\r\n texture.width = width;\r\n texture.height = height;\r\n texture.invertY = invertY;\r\n texture._compression = compression;\r\n\r\n // Double check on POT to generate Mips.\r\n const isPot = !this.needPOTTextures || (Tools.IsExponentOfTwo(texture.width) && Tools.IsExponentOfTwo(texture.height));\r\n if (!isPot) {\r\n generateMipMaps = false;\r\n }\r\n\r\n // Upload data if needed. The texture won't be ready until then.\r\n if (data) {\r\n this.updateRawCubeTexture(texture, data, format, type, invertY, compression);\r\n } else {\r\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);\r\n const level = 0;\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\r\n\r\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\r\n if (compression) {\r\n gl.compressedTexImage2D(\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex,\r\n level,\r\n (this.getCaps().s3tc)[compression],\r\n texture.width,\r\n texture.height,\r\n 0,\r\n undefined as any\r\n );\r\n } else {\r\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, null);\r\n }\r\n }\r\n\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\r\n }\r\n\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);\r\n\r\n // Filters\r\n if (data && generateMipMaps) {\r\n this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);\r\n }\r\n\r\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);\r\n\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n texture.isReady = true;\r\n\r\n return texture;\r\n};\r\n\r\nThinEngine.prototype.updateRawCubeTexture = function (\r\n texture: InternalTexture,\r\n data: ArrayBufferView[],\r\n format: number,\r\n type: number,\r\n invertY: boolean,\r\n compression: Nullable = null,\r\n level: number = 0\r\n): void {\r\n texture._bufferViewArray = data;\r\n texture.format = format;\r\n texture.type = type;\r\n texture.invertY = invertY;\r\n texture._compression = compression;\r\n\r\n const gl = this._gl;\r\n const textureType = this._getWebGLTextureType(type);\r\n let internalFormat = this._getInternalFormat(format);\r\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);\r\n\r\n let needConversion = false;\r\n if (internalFormat === gl.RGB) {\r\n internalFormat = gl.RGBA;\r\n needConversion = true;\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\r\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\r\n\r\n if (texture.width % 4 !== 0) {\r\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);\r\n }\r\n\r\n // Data are known to be in +X +Y +Z -X -Y -Z\r\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\r\n let faceData = data[faceIndex];\r\n\r\n if (compression) {\r\n gl.compressedTexImage2D(\r\n gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex,\r\n level,\r\n (this.getCaps().s3tc)[compression],\r\n texture.width,\r\n texture.height,\r\n 0,\r\n faceData\r\n );\r\n } else {\r\n if (needConversion) {\r\n faceData = _convertRGBtoRGBATextureData(faceData, texture.width, texture.height, type);\r\n }\r\n gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, faceData);\r\n }\r\n }\r\n\r\n const isPot = !this.needPOTTextures || (Tools.IsExponentOfTwo(texture.width) && Tools.IsExponentOfTwo(texture.height));\r\n if (isPot && texture.generateMipMaps && level === 0) {\r\n this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);\r\n }\r\n this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);\r\n\r\n // this.resetTextureCache();\r\n texture.isReady = true;\r\n};\r\n\r\nThinEngine.prototype.createRawCubeTextureFromUrl = function (\r\n url: string,\r\n scene: Nullable,\r\n size: number,\r\n format: number,\r\n type: number,\r\n noMipmap: boolean,\r\n callback: (ArrayBuffer: ArrayBuffer) => Nullable,\r\n mipmapGenerator: Nullable<(faces: ArrayBufferView[]) => ArrayBufferView[][]>,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n invertY: boolean = false\r\n): InternalTexture {\r\n const gl = this._gl;\r\n const texture = this.createRawCubeTexture(null, size, format, type, !noMipmap, invertY, samplingMode, null);\r\n scene?.addPendingData(texture);\r\n texture.url = url;\r\n texture.isReady = false;\r\n this._internalTexturesCache.push(texture);\r\n\r\n const onerror = (request?: IWebRequest, exception?: any) => {\r\n scene?.removePendingData(texture);\r\n if (onError && request) {\r\n onError(request.status + \" \" + request.statusText, exception);\r\n }\r\n };\r\n\r\n const internalCallback = (data: any) => {\r\n const width = texture.width;\r\n const faceDataArrays = callback(data);\r\n\r\n if (!faceDataArrays) {\r\n return;\r\n }\r\n\r\n if (mipmapGenerator) {\r\n const textureType = this._getWebGLTextureType(type);\r\n let internalFormat = this._getInternalFormat(format);\r\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);\r\n\r\n let needConversion = false;\r\n if (internalFormat === gl.RGB) {\r\n internalFormat = gl.RGBA;\r\n needConversion = true;\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);\r\n this._unpackFlipY(false);\r\n\r\n const mipData = mipmapGenerator(faceDataArrays);\r\n for (let level = 0; level < mipData.length; level++) {\r\n const mipSize = width >> level;\r\n\r\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\r\n let mipFaceData = mipData[level][faceIndex];\r\n if (needConversion) {\r\n mipFaceData = _convertRGBtoRGBATextureData(mipFaceData, mipSize, mipSize, type);\r\n }\r\n gl.texImage2D(faceIndex, level, internalSizedFomat, mipSize, mipSize, 0, internalFormat, textureType, mipFaceData);\r\n }\r\n }\r\n\r\n this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);\r\n } else {\r\n this.updateRawCubeTexture(texture, faceDataArrays, format, type, invertY);\r\n }\r\n\r\n texture.isReady = true;\r\n // this.resetTextureCache();\r\n scene?.removePendingData(texture);\r\n\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n };\r\n\r\n this._loadFile(\r\n url,\r\n (data) => {\r\n internalCallback(data);\r\n },\r\n undefined,\r\n scene?.offlineProvider,\r\n true,\r\n onerror\r\n );\r\n\r\n return texture;\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nfunction _convertRGBtoRGBATextureData(rgbData: any, width: number, height: number, textureType: number): ArrayBufferView {\r\n // Create new RGBA data container.\r\n let rgbaData: any;\r\n let val1 = 1;\r\n if (textureType === Constants.TEXTURETYPE_FLOAT) {\r\n rgbaData = new Float32Array(width * height * 4);\r\n } else if (textureType === Constants.TEXTURETYPE_HALF_FLOAT) {\r\n rgbaData = new Uint16Array(width * height * 4);\r\n val1 = 15360; // 15360 is the encoding of 1 in half float\r\n } else if (textureType === Constants.TEXTURETYPE_UNSIGNED_INTEGER) {\r\n rgbaData = new Uint32Array(width * height * 4);\r\n } else {\r\n rgbaData = new Uint8Array(width * height * 4);\r\n }\r\n\r\n // Convert each pixel.\r\n for (let x = 0; x < width; x++) {\r\n for (let y = 0; y < height; y++) {\r\n const index = (y * width + x) * 3;\r\n const newIndex = (y * width + x) * 4;\r\n\r\n // Map Old Value to new value.\r\n rgbaData[newIndex + 0] = rgbData[index + 0];\r\n rgbaData[newIndex + 1] = rgbData[index + 1];\r\n rgbaData[newIndex + 2] = rgbData[index + 2];\r\n\r\n // Add fully opaque alpha channel.\r\n rgbaData[newIndex + 3] = val1;\r\n }\r\n }\r\n\r\n return rgbaData;\r\n}\r\n\r\n/**\r\n * Create a function for createRawTexture3D/createRawTexture2DArray\r\n * @param is3D true for TEXTURE_3D and false for TEXTURE_2D_ARRAY\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nfunction _makeCreateRawTextureFunction(is3D: boolean) {\r\n return function (\r\n this: ThinEngine,\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n depth: number,\r\n format: number,\r\n generateMipMaps: boolean,\r\n invertY: boolean,\r\n samplingMode: number,\r\n compression: Nullable = null,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT\r\n ): InternalTexture {\r\n const target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;\r\n const source = is3D ? InternalTextureSource.Raw3D : InternalTextureSource.Raw2DArray;\r\n const texture = new InternalTexture(this, source);\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n texture.baseDepth = depth;\r\n texture.width = width;\r\n texture.height = height;\r\n texture.depth = depth;\r\n texture.format = format;\r\n texture.type = textureType;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n if (is3D) {\r\n texture.is3D = true;\r\n } else {\r\n texture.is2DArray = true;\r\n }\r\n\r\n if (!this._doNotHandleContextLost) {\r\n texture._bufferView = data;\r\n }\r\n\r\n if (is3D) {\r\n this.updateRawTexture3D(texture, data, format, invertY, compression, textureType);\r\n } else {\r\n this.updateRawTexture2DArray(texture, data, format, invertY, compression, textureType);\r\n }\r\n this._bindTextureDirectly(target, texture, true);\r\n\r\n // Filters\r\n const filters = this._getSamplingParameters(samplingMode, generateMipMaps);\r\n\r\n this._gl.texParameteri(target, this._gl.TEXTURE_MAG_FILTER, filters.mag);\r\n this._gl.texParameteri(target, this._gl.TEXTURE_MIN_FILTER, filters.min);\r\n\r\n if (generateMipMaps) {\r\n this._gl.generateMipmap(target);\r\n }\r\n\r\n this._bindTextureDirectly(target, null);\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n return texture;\r\n };\r\n}\r\n\r\nThinEngine.prototype.createRawTexture2DArray = _makeCreateRawTextureFunction(false);\r\nThinEngine.prototype.createRawTexture3D = _makeCreateRawTextureFunction(true);\r\n\r\n/**\r\n * Create a function for updateRawTexture3D/updateRawTexture2DArray\r\n * @param is3D true for TEXTURE_3D and false for TEXTURE_2D_ARRAY\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nfunction _makeUpdateRawTextureFunction(is3D: boolean) {\r\n return function (\r\n this: ThinEngine,\r\n texture: InternalTexture,\r\n data: Nullable,\r\n format: number,\r\n invertY: boolean,\r\n compression: Nullable = null,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT\r\n ): void {\r\n const target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;\r\n const internalType = this._getWebGLTextureType(textureType);\r\n const internalFormat = this._getInternalFormat(format);\r\n const internalSizedFomat = this._getRGBABufferInternalSizedFormat(textureType, format);\r\n\r\n this._bindTextureDirectly(target, texture, true);\r\n this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);\r\n\r\n if (!this._doNotHandleContextLost) {\r\n texture._bufferView = data;\r\n texture.format = format;\r\n texture.invertY = invertY;\r\n texture._compression = compression;\r\n }\r\n\r\n if (texture.width % 4 !== 0) {\r\n this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);\r\n }\r\n\r\n if (compression && data) {\r\n this._gl.compressedTexImage3D(target, 0, (this.getCaps().s3tc)[compression], texture.width, texture.height, texture.depth, 0, data);\r\n } else {\r\n this._gl.texImage3D(target, 0, internalSizedFomat, texture.width, texture.height, texture.depth, 0, internalFormat, internalType, data);\r\n }\r\n\r\n if (texture.generateMipMaps) {\r\n this._gl.generateMipmap(target);\r\n }\r\n this._bindTextureDirectly(target, null);\r\n // this.resetTextureCache();\r\n texture.isReady = true;\r\n };\r\n}\r\n\r\nThinEngine.prototype.updateRawTexture2DArray = _makeUpdateRawTextureFunction(false);\r\nThinEngine.prototype.updateRawTexture3D = _makeUpdateRawTextureFunction(true);\r\n","import { Texture } from \"./texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\n\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Raw texture can help creating a texture directly from an array of data.\r\n * This can be super useful if you either get the data from an uncompressed source or\r\n * if you wish to create your texture pixel by pixel.\r\n */\r\nexport class RawTexture extends Texture {\r\n /**\r\n * Instantiates a new RawTexture.\r\n * Raw texture can help creating a texture directly from an array of data.\r\n * This can be super useful if you either get the data from an uncompressed source or\r\n * if you wish to create your texture pixel by pixel.\r\n * @param data define the array of data to use to create the texture (null to create an empty texture)\r\n * @param width define the width of the texture\r\n * @param height define the height of the texture\r\n * @param format define the format of the data (RGB, RGBA... Engine.TEXTUREFORMAT_xxx)\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps define whether mip maps should be generated or not\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n */\r\n constructor(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n /**\r\n * Define the format of the data (RGB, RGBA... Engine.TEXTUREFORMAT_xxx)\r\n */\r\n public format: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n creationFlags?: number,\r\n useSRGBBuffer?: boolean\r\n ) {\r\n super(null, sceneOrEngine, !generateMipMaps, invertY, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, creationFlags);\r\n\r\n if (!this._engine) {\r\n return;\r\n }\r\n\r\n if (!this._engine._caps.textureFloatLinearFiltering && type === Constants.TEXTURETYPE_FLOAT) {\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n if (!this._engine._caps.textureHalfFloatLinearFiltering && type === Constants.TEXTURETYPE_HALF_FLOAT) {\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n\r\n this._texture = this._engine.createRawTexture(data, width, height, format, generateMipMaps, invertY, samplingMode, null, type, creationFlags ?? 0, useSRGBBuffer ?? false);\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n }\r\n\r\n /**\r\n * Updates the texture underlying data.\r\n * @param data Define the new data of the texture\r\n */\r\n public update(data: ArrayBufferView): void {\r\n this._getEngine()!.updateRawTexture(this._texture, data, this._texture!.format, this._texture!.invertY, null, this._texture!.type, this._texture!._useSRGBBuffer);\r\n }\r\n\r\n /**\r\n * Creates a luminance texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @returns the luminance texture\r\n */\r\n public static CreateLuminanceTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_LUMINANCE, sceneOrEngine, generateMipMaps, invertY, samplingMode);\r\n }\r\n\r\n /**\r\n * Creates a luminance alpha texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @returns the luminance alpha texture\r\n */\r\n public static CreateLuminanceAlphaTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_LUMINANCE_ALPHA, sceneOrEngine, generateMipMaps, invertY, samplingMode);\r\n }\r\n\r\n /**\r\n * Creates an alpha texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @returns the alpha texture\r\n */\r\n public static CreateAlphaTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_ALPHA, sceneOrEngine, generateMipMaps, invertY, samplingMode);\r\n }\r\n\r\n /**\r\n * Creates a RGB texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns the RGB alpha texture\r\n */\r\n public static CreateRGBTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n creationFlags: number = 0,\r\n useSRGBBuffer: boolean = false\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_RGB, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, creationFlags, useSRGBBuffer);\r\n }\r\n\r\n /**\r\n * Creates a RGBA texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\r\n * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns the RGBA texture\r\n */\r\n public static CreateRGBATexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n creationFlags: number = 0,\r\n useSRGBBuffer: boolean = false\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_RGBA, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, creationFlags, useSRGBBuffer);\r\n }\r\n\r\n /**\r\n * Creates a RGBA storage texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\r\n * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).\r\n * @returns the RGBA texture\r\n */\r\n public static CreateRGBAStorageTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n type: number = Constants.TEXTURETYPE_UNSIGNED_INT,\r\n useSRGBBuffer: boolean = false\r\n ): RawTexture {\r\n return new RawTexture(\r\n data,\r\n width,\r\n height,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n sceneOrEngine,\r\n generateMipMaps,\r\n invertY,\r\n samplingMode,\r\n type,\r\n Constants.TEXTURE_CREATIONFLAG_STORAGE,\r\n useSRGBBuffer\r\n );\r\n }\r\n\r\n /**\r\n * Creates a R texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\r\n * @returns the R texture\r\n */\r\n public static CreateRTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE,\r\n type: number = Constants.TEXTURETYPE_FLOAT\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_R, sceneOrEngine, generateMipMaps, invertY, samplingMode, type);\r\n }\r\n\r\n /**\r\n * Creates a R storage texture from some data.\r\n * @param data Define the texture data\r\n * @param width Define the width of the texture\r\n * @param height Define the height of the texture\r\n * @param sceneOrEngine defines the scene or engine the texture will belong to\r\n * @param generateMipMaps Define whether or not to create mip maps for the texture\r\n * @param invertY define if the data should be flipped on Y when uploaded to the GPU\r\n * @param samplingMode define the texture sampling mode (Texture.xxx_SAMPLINGMODE)\r\n * @param type define the format of the data (int, float... Engine.TEXTURETYPE_xxx)\r\n * @returns the R texture\r\n */\r\n public static CreateRStorageTexture(\r\n data: Nullable,\r\n width: number,\r\n height: number,\r\n sceneOrEngine: Nullable,\r\n generateMipMaps: boolean = true,\r\n invertY: boolean = false,\r\n samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE,\r\n type: number = Constants.TEXTURETYPE_FLOAT\r\n ): RawTexture {\r\n return new RawTexture(data, width, height, Constants.TEXTUREFORMAT_R, sceneOrEngine, generateMipMaps, invertY, samplingMode, type, Constants.TEXTURE_CREATIONFLAG_STORAGE);\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\n/** Defines the cross module used constants to avoid circular dependencies */\r\nexport class Constants {\r\n /** Defines that alpha blending is disabled */\r\n public static readonly ALPHA_DISABLE = 0;\r\n /** Defines that alpha blending is SRC ALPHA * SRC + DEST */\r\n public static readonly ALPHA_ADD = 1;\r\n /** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */\r\n public static readonly ALPHA_COMBINE = 2;\r\n /** Defines that alpha blending is DEST - SRC * DEST */\r\n public static readonly ALPHA_SUBTRACT = 3;\r\n /** Defines that alpha blending is SRC * DEST */\r\n public static readonly ALPHA_MULTIPLY = 4;\r\n /** Defines that alpha blending is SRC ALPHA * SRC + (1 - SRC) * DEST */\r\n public static readonly ALPHA_MAXIMIZED = 5;\r\n /** Defines that alpha blending is SRC + DEST */\r\n public static readonly ALPHA_ONEONE = 6;\r\n /** Defines that alpha blending is SRC + (1 - SRC ALPHA) * DEST */\r\n public static readonly ALPHA_PREMULTIPLIED = 7;\r\n /**\r\n * Defines that alpha blending is SRC + (1 - SRC ALPHA) * DEST\r\n * Alpha will be set to (1 - SRC ALPHA) * DEST ALPHA\r\n */\r\n public static readonly ALPHA_PREMULTIPLIED_PORTERDUFF = 8;\r\n /** Defines that alpha blending is CST * SRC + (1 - CST) * DEST */\r\n public static readonly ALPHA_INTERPOLATE = 9;\r\n /**\r\n * Defines that alpha blending is SRC + (1 - SRC) * DEST\r\n * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DEST ALPHA\r\n */\r\n public static readonly ALPHA_SCREENMODE = 10;\r\n /**\r\n * Defines that alpha blending is SRC + DST\r\n * Alpha will be set to SRC ALPHA + DST ALPHA\r\n */\r\n public static readonly ALPHA_ONEONE_ONEONE = 11;\r\n /**\r\n * Defines that alpha blending is SRC * DST ALPHA + DST\r\n * Alpha will be set to 0\r\n */\r\n public static readonly ALPHA_ALPHATOCOLOR = 12;\r\n /**\r\n * Defines that alpha blending is SRC * (1 - DST) + DST * (1 - SRC)\r\n */\r\n public static readonly ALPHA_REVERSEONEMINUS = 13;\r\n /**\r\n * Defines that alpha blending is SRC + DST * (1 - SRC ALPHA)\r\n * Alpha will be set to SRC ALPHA + DST ALPHA * (1 - SRC ALPHA)\r\n */\r\n public static readonly ALPHA_SRC_DSTONEMINUSSRCALPHA = 14;\r\n /**\r\n * Defines that alpha blending is SRC + DST\r\n * Alpha will be set to SRC ALPHA\r\n */\r\n public static readonly ALPHA_ONEONE_ONEZERO = 15;\r\n /**\r\n * Defines that alpha blending is SRC * (1 - DST) + DST * (1 - SRC)\r\n * Alpha will be set to DST ALPHA\r\n */\r\n public static readonly ALPHA_EXCLUSION = 16;\r\n /**\r\n * Defines that alpha blending is SRC * SRC ALPHA + DST * (1 - SRC ALPHA)\r\n * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DST ALPHA\r\n */\r\n public static readonly ALPHA_LAYER_ACCUMULATE = 17;\r\n\r\n /** Defines that alpha blending equation a SUM */\r\n public static readonly ALPHA_EQUATION_ADD = 0;\r\n /** Defines that alpha blending equation a SUBSTRACTION */\r\n public static readonly ALPHA_EQUATION_SUBSTRACT = 1;\r\n /** Defines that alpha blending equation a REVERSE SUBSTRACTION */\r\n public static readonly ALPHA_EQUATION_REVERSE_SUBTRACT = 2;\r\n /** Defines that alpha blending equation a MAX operation */\r\n public static readonly ALPHA_EQUATION_MAX = 3;\r\n /** Defines that alpha blending equation a MIN operation */\r\n public static readonly ALPHA_EQUATION_MIN = 4;\r\n /**\r\n * Defines that alpha blending equation a DARKEN operation:\r\n * It takes the min of the src and sums the alpha channels.\r\n */\r\n public static readonly ALPHA_EQUATION_DARKEN = 5;\r\n\r\n /** Defines that the resource is not delayed*/\r\n public static readonly DELAYLOADSTATE_NONE = 0;\r\n /** Defines that the resource was successfully delay loaded */\r\n public static readonly DELAYLOADSTATE_LOADED = 1;\r\n /** Defines that the resource is currently delay loading */\r\n public static readonly DELAYLOADSTATE_LOADING = 2;\r\n /** Defines that the resource is delayed and has not started loading */\r\n public static readonly DELAYLOADSTATE_NOTLOADED = 4;\r\n\r\n // Depth or Stencil test Constants.\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn */\r\n public static readonly NEVER = 0x0200;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */\r\n public static readonly ALWAYS = 0x0207;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value */\r\n public static readonly LESS = 0x0201;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value */\r\n public static readonly EQUAL = 0x0202;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value */\r\n public static readonly LEQUAL = 0x0203;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value */\r\n public static readonly GREATER = 0x0204;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value */\r\n public static readonly GEQUAL = 0x0206;\r\n /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value */\r\n public static readonly NOTEQUAL = 0x0205;\r\n\r\n // Stencil Actions Constants.\r\n /** Passed to stencilOperation to specify that stencil value must be kept */\r\n public static readonly KEEP = 0x1e00;\r\n /** Passed to stencilOperation to specify that stencil value must be zero */\r\n public static readonly ZERO = 0x0000;\r\n /** Passed to stencilOperation to specify that stencil value must be replaced */\r\n public static readonly REPLACE = 0x1e01;\r\n /** Passed to stencilOperation to specify that stencil value must be incremented */\r\n public static readonly INCR = 0x1e02;\r\n /** Passed to stencilOperation to specify that stencil value must be decremented */\r\n public static readonly DECR = 0x1e03;\r\n /** Passed to stencilOperation to specify that stencil value must be inverted */\r\n public static readonly INVERT = 0x150a;\r\n /** Passed to stencilOperation to specify that stencil value must be incremented with wrapping */\r\n public static readonly INCR_WRAP = 0x8507;\r\n /** Passed to stencilOperation to specify that stencil value must be decremented with wrapping */\r\n public static readonly DECR_WRAP = 0x8508;\r\n\r\n /** Texture is not repeating outside of 0..1 UVs */\r\n public static readonly TEXTURE_CLAMP_ADDRESSMODE = 0;\r\n /** Texture is repeating outside of 0..1 UVs */\r\n public static readonly TEXTURE_WRAP_ADDRESSMODE = 1;\r\n /** Texture is repeating and mirrored */\r\n public static readonly TEXTURE_MIRROR_ADDRESSMODE = 2;\r\n\r\n /** Flag to create a storage texture */\r\n public static readonly TEXTURE_CREATIONFLAG_STORAGE = 1;\r\n\r\n /** ALPHA */\r\n public static readonly TEXTUREFORMAT_ALPHA = 0;\r\n /** LUMINANCE */\r\n public static readonly TEXTUREFORMAT_LUMINANCE = 1;\r\n /** LUMINANCE_ALPHA */\r\n public static readonly TEXTUREFORMAT_LUMINANCE_ALPHA = 2;\r\n /** RGB */\r\n public static readonly TEXTUREFORMAT_RGB = 4;\r\n /** RGBA */\r\n public static readonly TEXTUREFORMAT_RGBA = 5;\r\n /** RED */\r\n public static readonly TEXTUREFORMAT_RED = 6;\r\n /** RED (2nd reference) */\r\n public static readonly TEXTUREFORMAT_R = 6;\r\n /** RG */\r\n public static readonly TEXTUREFORMAT_RG = 7;\r\n /** RED_INTEGER */\r\n public static readonly TEXTUREFORMAT_RED_INTEGER = 8;\r\n /** RED_INTEGER (2nd reference) */\r\n public static readonly TEXTUREFORMAT_R_INTEGER = 8;\r\n /** RG_INTEGER */\r\n public static readonly TEXTUREFORMAT_RG_INTEGER = 9;\r\n /** RGB_INTEGER */\r\n public static readonly TEXTUREFORMAT_RGB_INTEGER = 10;\r\n /** RGBA_INTEGER */\r\n public static readonly TEXTUREFORMAT_RGBA_INTEGER = 11;\r\n /** BGRA */\r\n public static readonly TEXTUREFORMAT_BGRA = 12;\r\n\r\n /** Depth 24 bits + Stencil 8 bits */\r\n public static readonly TEXTUREFORMAT_DEPTH24_STENCIL8 = 13;\r\n /** Depth 32 bits float */\r\n public static readonly TEXTUREFORMAT_DEPTH32_FLOAT = 14;\r\n /** Depth 16 bits */\r\n public static readonly TEXTUREFORMAT_DEPTH16 = 15;\r\n /** Depth 24 bits */\r\n public static readonly TEXTUREFORMAT_DEPTH24 = 16;\r\n /** Depth 24 bits unorm + Stencil 8 bits */\r\n public static readonly TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 = 17;\r\n /** Depth 32 bits float + Stencil 8 bits */\r\n public static readonly TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8 = 18;\r\n /** Stencil 8 bits */\r\n public static readonly TEXTUREFORMAT_STENCIL8 = 19;\r\n\r\n /** Compressed BC7 */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM = 36492;\r\n /** Compressed BC7 (SRGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 36493;\r\n /** Compressed BC6 unsigned float */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT = 36495;\r\n /** Compressed BC6 signed float */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT = 36494;\r\n /** Compressed BC3 */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5 = 33779;\r\n /** Compressed BC3 (SRGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 35919;\r\n /** Compressed BC2 */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3 = 33778;\r\n /** Compressed BC2 (SRGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 35918;\r\n /** Compressed BC1 (RGBA) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1 = 33777;\r\n /** Compressed BC1 (RGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1 = 33776;\r\n /** Compressed BC1 (SRGB+A) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 35917;\r\n /** Compressed BC1 (SRGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT = 35916;\r\n /** Compressed ASTC 4x4 */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4 = 37808;\r\n /** Compressed ASTC 4x4 (SRGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 37840;\r\n /** Compressed ETC1 (RGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL = 36196;\r\n /** Compressed ETC2 (RGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGB8_ETC2 = 37492;\r\n /** Compressed ETC2 (SRGB) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2 = 37493;\r\n /** Compressed ETC2 (RGB+A1) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37494;\r\n /** Compressed ETC2 (SRGB+A1)*/\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37495;\r\n /** Compressed ETC2 (RGB+A) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC = 37496;\r\n /** Compressed ETC2 (SRGB+1) */\r\n public static readonly TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 37497;\r\n\r\n /** UNSIGNED_BYTE */\r\n public static readonly TEXTURETYPE_UNSIGNED_BYTE = 0;\r\n /** UNSIGNED_BYTE (2nd reference) */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT = 0;\r\n /** FLOAT */\r\n public static readonly TEXTURETYPE_FLOAT = 1;\r\n /** HALF_FLOAT */\r\n public static readonly TEXTURETYPE_HALF_FLOAT = 2;\r\n /** BYTE */\r\n public static readonly TEXTURETYPE_BYTE = 3;\r\n /** SHORT */\r\n public static readonly TEXTURETYPE_SHORT = 4;\r\n /** UNSIGNED_SHORT */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT = 5;\r\n /** INT */\r\n public static readonly TEXTURETYPE_INT = 6;\r\n /** UNSIGNED_INT */\r\n public static readonly TEXTURETYPE_UNSIGNED_INTEGER = 7;\r\n /** UNSIGNED_SHORT_4_4_4_4 */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4 = 8;\r\n /** UNSIGNED_SHORT_5_5_5_1 */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1 = 9;\r\n /** UNSIGNED_SHORT_5_6_5 */\r\n public static readonly TEXTURETYPE_UNSIGNED_SHORT_5_6_5 = 10;\r\n /** UNSIGNED_INT_2_10_10_10_REV */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV = 11;\r\n /** UNSIGNED_INT_24_8 */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_24_8 = 12;\r\n /** UNSIGNED_INT_10F_11F_11F_REV */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV = 13;\r\n /** UNSIGNED_INT_5_9_9_9_REV */\r\n public static readonly TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV = 14;\r\n /** FLOAT_32_UNSIGNED_INT_24_8_REV */\r\n public static readonly TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV = 15;\r\n /** UNDEFINED */\r\n public static readonly TEXTURETYPE_UNDEFINED = 16;\r\n\r\n /** 2D Texture target*/\r\n public static readonly TEXTURE_2D = 3553;\r\n /** 2D Array Texture target */\r\n public static readonly TEXTURE_2D_ARRAY = 35866;\r\n /** Cube Map Texture target */\r\n public static readonly TEXTURE_CUBE_MAP = 34067;\r\n /** Cube Map Array Texture target */\r\n public static readonly TEXTURE_CUBE_MAP_ARRAY = 0xdeadbeef;\r\n /** 3D Texture target */\r\n public static readonly TEXTURE_3D = 32879;\r\n\r\n /** nearest is mag = nearest and min = nearest and no mip */\r\n public static readonly TEXTURE_NEAREST_SAMPLINGMODE = 1;\r\n /** mag = nearest and min = nearest and mip = none */\r\n public static readonly TEXTURE_NEAREST_NEAREST = 1;\r\n\r\n /** Bilinear is mag = linear and min = linear and no mip */\r\n public static readonly TEXTURE_BILINEAR_SAMPLINGMODE = 2;\r\n /** mag = linear and min = linear and mip = none */\r\n public static readonly TEXTURE_LINEAR_LINEAR = 2;\r\n\r\n /** Trilinear is mag = linear and min = linear and mip = linear */\r\n public static readonly TEXTURE_TRILINEAR_SAMPLINGMODE = 3;\r\n /** Trilinear is mag = linear and min = linear and mip = linear */\r\n public static readonly TEXTURE_LINEAR_LINEAR_MIPLINEAR = 3;\r\n\r\n /** mag = nearest and min = nearest and mip = nearest */\r\n public static readonly TEXTURE_NEAREST_NEAREST_MIPNEAREST = 4;\r\n /** mag = nearest and min = linear and mip = nearest */\r\n public static readonly TEXTURE_NEAREST_LINEAR_MIPNEAREST = 5;\r\n /** mag = nearest and min = linear and mip = linear */\r\n public static readonly TEXTURE_NEAREST_LINEAR_MIPLINEAR = 6;\r\n /** mag = nearest and min = linear and mip = none */\r\n public static readonly TEXTURE_NEAREST_LINEAR = 7;\r\n /** nearest is mag = nearest and min = nearest and mip = linear */\r\n public static readonly TEXTURE_NEAREST_NEAREST_MIPLINEAR = 8;\r\n /** mag = linear and min = nearest and mip = nearest */\r\n public static readonly TEXTURE_LINEAR_NEAREST_MIPNEAREST = 9;\r\n /** mag = linear and min = nearest and mip = linear */\r\n public static readonly TEXTURE_LINEAR_NEAREST_MIPLINEAR = 10;\r\n /** Bilinear is mag = linear and min = linear and mip = nearest */\r\n public static readonly TEXTURE_LINEAR_LINEAR_MIPNEAREST = 11;\r\n /** mag = linear and min = nearest and mip = none */\r\n public static readonly TEXTURE_LINEAR_NEAREST = 12;\r\n\r\n /** Explicit coordinates mode */\r\n public static readonly TEXTURE_EXPLICIT_MODE = 0;\r\n /** Spherical coordinates mode */\r\n public static readonly TEXTURE_SPHERICAL_MODE = 1;\r\n /** Planar coordinates mode */\r\n public static readonly TEXTURE_PLANAR_MODE = 2;\r\n /** Cubic coordinates mode */\r\n public static readonly TEXTURE_CUBIC_MODE = 3;\r\n /** Projection coordinates mode */\r\n public static readonly TEXTURE_PROJECTION_MODE = 4;\r\n /** Skybox coordinates mode */\r\n public static readonly TEXTURE_SKYBOX_MODE = 5;\r\n /** Inverse Cubic coordinates mode */\r\n public static readonly TEXTURE_INVCUBIC_MODE = 6;\r\n /** Equirectangular coordinates mode */\r\n public static readonly TEXTURE_EQUIRECTANGULAR_MODE = 7;\r\n /** Equirectangular Fixed coordinates mode */\r\n public static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MODE = 8;\r\n /** Equirectangular Fixed Mirrored coordinates mode */\r\n public static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;\r\n\r\n /** Offline (baking) quality for texture filtering */\r\n public static readonly TEXTURE_FILTERING_QUALITY_OFFLINE = 4096;\r\n\r\n /** High quality for texture filtering */\r\n public static readonly TEXTURE_FILTERING_QUALITY_HIGH = 64;\r\n\r\n /** Medium quality for texture filtering */\r\n public static readonly TEXTURE_FILTERING_QUALITY_MEDIUM = 16;\r\n\r\n /** Low quality for texture filtering */\r\n public static readonly TEXTURE_FILTERING_QUALITY_LOW = 8;\r\n\r\n // Texture rescaling mode\r\n /** Defines that texture rescaling will use a floor to find the closer power of 2 size */\r\n public static readonly SCALEMODE_FLOOR = 1;\r\n /** Defines that texture rescaling will look for the nearest power of 2 size */\r\n public static readonly SCALEMODE_NEAREST = 2;\r\n /** Defines that texture rescaling will use a ceil to find the closer power of 2 size */\r\n public static readonly SCALEMODE_CEILING = 3;\r\n\r\n /**\r\n * The dirty texture flag value\r\n */\r\n public static readonly MATERIAL_TextureDirtyFlag = 1;\r\n /**\r\n * The dirty light flag value\r\n */\r\n public static readonly MATERIAL_LightDirtyFlag = 2;\r\n /**\r\n * The dirty fresnel flag value\r\n */\r\n public static readonly MATERIAL_FresnelDirtyFlag = 4;\r\n /**\r\n * The dirty attribute flag value\r\n */\r\n public static readonly MATERIAL_AttributesDirtyFlag = 8;\r\n /**\r\n * The dirty misc flag value\r\n */\r\n public static readonly MATERIAL_MiscDirtyFlag = 16;\r\n /**\r\n * The dirty prepass flag value\r\n */\r\n public static readonly MATERIAL_PrePassDirtyFlag = 32;\r\n /**\r\n * The all dirty flag value\r\n */\r\n public static readonly MATERIAL_AllDirtyFlag = 63;\r\n\r\n /**\r\n * Returns the triangle fill mode\r\n */\r\n public static readonly MATERIAL_TriangleFillMode = 0;\r\n /**\r\n * Returns the wireframe mode\r\n */\r\n public static readonly MATERIAL_WireFrameFillMode = 1;\r\n /**\r\n * Returns the point fill mode\r\n */\r\n public static readonly MATERIAL_PointFillMode = 2;\r\n /**\r\n * Returns the point list draw mode\r\n */\r\n public static readonly MATERIAL_PointListDrawMode = 3;\r\n /**\r\n * Returns the line list draw mode\r\n */\r\n public static readonly MATERIAL_LineListDrawMode = 4;\r\n /**\r\n * Returns the line loop draw mode\r\n */\r\n public static readonly MATERIAL_LineLoopDrawMode = 5;\r\n /**\r\n * Returns the line strip draw mode\r\n */\r\n public static readonly MATERIAL_LineStripDrawMode = 6;\r\n\r\n /**\r\n * Returns the triangle strip draw mode\r\n */\r\n public static readonly MATERIAL_TriangleStripDrawMode = 7;\r\n /**\r\n * Returns the triangle fan draw mode\r\n */\r\n public static readonly MATERIAL_TriangleFanDrawMode = 8;\r\n\r\n /**\r\n * Stores the clock-wise side orientation\r\n */\r\n public static readonly MATERIAL_ClockWiseSideOrientation = 0;\r\n /**\r\n * Stores the counter clock-wise side orientation\r\n */\r\n public static readonly MATERIAL_CounterClockWiseSideOrientation = 1;\r\n\r\n /**\r\n * Nothing\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_NothingTrigger = 0;\r\n /**\r\n * On pick\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnPickTrigger = 1;\r\n /**\r\n * On left pick\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnLeftPickTrigger = 2;\r\n /**\r\n * On right pick\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnRightPickTrigger = 3;\r\n /**\r\n * On center pick\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnCenterPickTrigger = 4;\r\n /**\r\n * On pick down\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnPickDownTrigger = 5;\r\n /**\r\n * On double pick\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnDoublePickTrigger = 6;\r\n /**\r\n * On pick up\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnPickUpTrigger = 7;\r\n /**\r\n * On pick out.\r\n * This trigger will only be raised if you also declared a OnPickDown\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnPickOutTrigger = 16;\r\n /**\r\n * On long press\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnLongPressTrigger = 8;\r\n /**\r\n * On pointer over\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnPointerOverTrigger = 9;\r\n /**\r\n * On pointer out\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnPointerOutTrigger = 10;\r\n /**\r\n * On every frame\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnEveryFrameTrigger = 11;\r\n /**\r\n * On intersection enter\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnIntersectionEnterTrigger = 12;\r\n /**\r\n * On intersection exit\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnIntersectionExitTrigger = 13;\r\n /**\r\n * On key down\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnKeyDownTrigger = 14;\r\n /**\r\n * On key up\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers\r\n */\r\n public static readonly ACTION_OnKeyUpTrigger = 15;\r\n\r\n /**\r\n * Billboard mode will only apply to Y axis\r\n */\r\n public static readonly PARTICLES_BILLBOARDMODE_Y = 2;\r\n /**\r\n * Billboard mode will apply to all axes\r\n */\r\n public static readonly PARTICLES_BILLBOARDMODE_ALL = 7;\r\n /**\r\n * Special billboard mode where the particle will be biilboard to the camera but rotated to align with direction\r\n */\r\n public static readonly PARTICLES_BILLBOARDMODE_STRETCHED = 8;\r\n /**\r\n * Special billboard mode where the particle will be billboard to the camera but only around the axis of the direction of particle emission\r\n */\r\n public static readonly PARTICLES_BILLBOARDMODE_STRETCHED_LOCAL = 9;\r\n\r\n /** Default culling strategy : this is an exclusion test and it's the more accurate.\r\n * Test order :\r\n * Is the bounding sphere outside the frustum ?\r\n * If not, are the bounding box vertices outside the frustum ?\r\n * It not, then the cullable object is in the frustum.\r\n */\r\n public static readonly MESHES_CULLINGSTRATEGY_STANDARD = 0;\r\n /** Culling strategy : Bounding Sphere Only.\r\n * This is an exclusion test. It's faster than the standard strategy because the bounding box is not tested.\r\n * It's also less accurate than the standard because some not visible objects can still be selected.\r\n * Test : is the bounding sphere outside the frustum ?\r\n * If not, then the cullable object is in the frustum.\r\n */\r\n public static readonly MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = 1;\r\n /** Culling strategy : Optimistic Inclusion.\r\n * This in an inclusion test first, then the standard exclusion test.\r\n * This can be faster when a cullable object is expected to be almost always in the camera frustum.\r\n * This could also be a little slower than the standard test when the tested object center is not the frustum but one of its bounding box vertex is still inside.\r\n * Anyway, it's as accurate as the standard strategy.\r\n * Test :\r\n * Is the cullable object bounding sphere center in the frustum ?\r\n * If not, apply the default culling strategy.\r\n */\r\n public static readonly MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = 2;\r\n /** Culling strategy : Optimistic Inclusion then Bounding Sphere Only.\r\n * This in an inclusion test first, then the bounding sphere only exclusion test.\r\n * This can be the fastest test when a cullable object is expected to be almost always in the camera frustum.\r\n * This could also be a little slower than the BoundingSphereOnly strategy when the tested object center is not in the frustum but its bounding sphere still intersects it.\r\n * It's less accurate than the standard strategy and as accurate as the BoundingSphereOnly strategy.\r\n * Test :\r\n * Is the cullable object bounding sphere center in the frustum ?\r\n * If not, apply the Bounding Sphere Only strategy. No Bounding Box is tested here.\r\n */\r\n public static readonly MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = 3;\r\n\r\n /**\r\n * No logging while loading\r\n */\r\n public static readonly SCENELOADER_NO_LOGGING = 0;\r\n /**\r\n * Minimal logging while loading\r\n */\r\n public static readonly SCENELOADER_MINIMAL_LOGGING = 1;\r\n /**\r\n * Summary logging while loading\r\n */\r\n public static readonly SCENELOADER_SUMMARY_LOGGING = 2;\r\n /**\r\n * Detailed logging while loading\r\n */\r\n public static readonly SCENELOADER_DETAILED_LOGGING = 3;\r\n\r\n /**\r\n * Constant used to retrieve the irradiance texture index in the textures array in the prepass\r\n * using getIndex(Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE)\r\n */\r\n public static readonly PREPASS_IRRADIANCE_TEXTURE_TYPE = 0;\r\n /**\r\n * Constant used to retrieve the position texture index in the textures array in the prepass\r\n * using getIndex(Constants.PREPASS_POSITION_TEXTURE_INDEX)\r\n */\r\n public static readonly PREPASS_POSITION_TEXTURE_TYPE = 1;\r\n /**\r\n * Constant used to retrieve the velocity texture index in the textures array in the prepass\r\n * using getIndex(Constants.PREPASS_VELOCITY_TEXTURE_INDEX)\r\n */\r\n public static readonly PREPASS_VELOCITY_TEXTURE_TYPE = 2;\r\n /**\r\n * Constant used to retrieve the reflectivity texture index in the textures array in the prepass\r\n * using the getIndex(Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE)\r\n */\r\n public static readonly PREPASS_REFLECTIVITY_TEXTURE_TYPE = 3;\r\n /**\r\n * Constant used to retrieve the lit color texture index in the textures array in the prepass\r\n * using the getIndex(Constants.PREPASS_COLOR_TEXTURE_TYPE)\r\n */\r\n public static readonly PREPASS_COLOR_TEXTURE_TYPE = 4;\r\n /**\r\n * Constant used to retrieve depth index in the textures array in the prepass\r\n * using the getIndex(Constants.PREPASS_DEPTH_TEXTURE_TYPE)\r\n */\r\n public static readonly PREPASS_DEPTH_TEXTURE_TYPE = 5;\r\n /**\r\n * Constant used to retrieve normal index in the textures array in the prepass\r\n * using the getIndex(Constants.PREPASS_NORMAL_TEXTURE_TYPE)\r\n */\r\n public static readonly PREPASS_NORMAL_TEXTURE_TYPE = 6;\r\n /**\r\n * Constant used to retrieve albedo index in the textures array in the prepass\r\n * using the getIndex(Constants.PREPASS_ALBEDO_SQRT_TEXTURE_TYPE)\r\n */\r\n public static readonly PREPASS_ALBEDO_SQRT_TEXTURE_TYPE = 7;\r\n\r\n /** Flag to create a readable buffer (the buffer can be the source of a copy) */\r\n public static readonly BUFFER_CREATIONFLAG_READ = 1;\r\n /** Flag to create a writable buffer (the buffer can be the destination of a copy) */\r\n public static readonly BUFFER_CREATIONFLAG_WRITE = 2;\r\n /** Flag to create a readable and writable buffer */\r\n public static readonly BUFFER_CREATIONFLAG_READWRITE = 3;\r\n /** Flag to create a buffer suitable to be used as a uniform buffer */\r\n public static readonly BUFFER_CREATIONFLAG_UNIFORM = 4;\r\n /** Flag to create a buffer suitable to be used as a vertex buffer */\r\n public static readonly BUFFER_CREATIONFLAG_VERTEX = 8;\r\n /** Flag to create a buffer suitable to be used as an index buffer */\r\n public static readonly BUFFER_CREATIONFLAG_INDEX = 16;\r\n /** Flag to create a buffer suitable to be used as a storage buffer */\r\n public static readonly BUFFER_CREATIONFLAG_STORAGE = 32;\r\n\r\n /**\r\n * Prefixes used by the engine for sub mesh draw wrappers\r\n */\r\n\r\n /** @internal */\r\n public static readonly RENDERPASS_MAIN = 0;\r\n\r\n /**\r\n * Constant used as key code for Alt key\r\n */\r\n public static readonly INPUT_ALT_KEY = 18;\r\n\r\n /**\r\n * Constant used as key code for Ctrl key\r\n */\r\n public static readonly INPUT_CTRL_KEY = 17;\r\n\r\n /**\r\n * Constant used as key code for Meta key (Left Win, Left Cmd)\r\n */\r\n public static readonly INPUT_META_KEY1 = 91;\r\n\r\n /**\r\n * Constant used as key code for Meta key (Right Win)\r\n */\r\n public static readonly INPUT_META_KEY2 = 92;\r\n\r\n /**\r\n * Constant used as key code for Meta key (Right Win, Right Cmd)\r\n */\r\n public static readonly INPUT_META_KEY3 = 93;\r\n\r\n /**\r\n * Constant used as key code for Shift key\r\n */\r\n public static readonly INPUT_SHIFT_KEY = 16;\r\n\r\n /** Standard snapshot rendering. In this mode, some form of dynamic behavior is possible (for eg, uniform buffers are still updated) */\r\n public static readonly SNAPSHOTRENDERING_STANDARD = 0;\r\n\r\n /** Fast snapshot rendering. In this mode, everything is static and only some limited form of dynamic behaviour is possible */\r\n public static readonly SNAPSHOTRENDERING_FAST = 1;\r\n\r\n /**\r\n * This is the default projection mode used by the cameras.\r\n * It helps recreating a feeling of perspective and better appreciate depth.\r\n * This is the best way to simulate real life cameras.\r\n */\r\n public static readonly PERSPECTIVE_CAMERA = 0;\r\n /**\r\n * This helps creating camera with an orthographic mode.\r\n * Orthographic is commonly used in engineering as a means to produce object specifications that communicate dimensions unambiguously, each line of 1 unit length (cm, meter..whatever) will appear to have the same length everywhere on the drawing. This allows the drafter to dimension only a subset of lines and let the reader know that other lines of that length on the drawing are also that length in reality. Every parallel line in the drawing is also parallel in the object.\r\n */\r\n public static readonly ORTHOGRAPHIC_CAMERA = 1;\r\n\r\n /**\r\n * This is the default FOV mode for perspective cameras.\r\n * This setting aligns the upper and lower bounds of the viewport to the upper and lower bounds of the camera frustum.\r\n */\r\n public static readonly FOVMODE_VERTICAL_FIXED = 0;\r\n /**\r\n * This setting aligns the left and right bounds of the viewport to the left and right bounds of the camera frustum.\r\n */\r\n public static readonly FOVMODE_HORIZONTAL_FIXED = 1;\r\n\r\n /**\r\n * This specifies there is no need for a camera rig.\r\n * Basically only one eye is rendered corresponding to the camera.\r\n */\r\n public static readonly RIG_MODE_NONE = 0;\r\n /**\r\n * Simulates a camera Rig with one blue eye and one red eye.\r\n * This can be use with 3d blue and red glasses.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_ANAGLYPH = 10;\r\n /**\r\n * Defines that both eyes of the camera will be rendered side by side with a parallel target.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = 11;\r\n /**\r\n * Defines that both eyes of the camera will be rendered side by side with a none parallel target.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;\r\n /**\r\n * Defines that both eyes of the camera will be rendered over under each other.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;\r\n /**\r\n * Defines that both eyes of the camera will be rendered on successive lines interlaced for passive 3d monitors.\r\n */\r\n public static readonly RIG_MODE_STEREOSCOPIC_INTERLACED = 14;\r\n /**\r\n * Defines that both eyes of the camera should be renderered in a VR mode (carbox).\r\n */\r\n public static readonly RIG_MODE_VR = 20;\r\n /**\r\n * Defines that both eyes of the camera should be renderered in a VR mode (webVR).\r\n */\r\n public static readonly RIG_MODE_WEBVR = 21;\r\n /**\r\n * Custom rig mode allowing rig cameras to be populated manually with any number of cameras\r\n */\r\n public static readonly RIG_MODE_CUSTOM = 22;\r\n\r\n /**\r\n * Maximum number of uv sets supported\r\n */\r\n public static readonly MAX_SUPPORTED_UV_SETS = 6;\r\n\r\n /**\r\n * GL constants\r\n */\r\n /** Alpha blend equation: ADD */\r\n public static readonly GL_ALPHA_EQUATION_ADD = 0x8006;\r\n /** Alpha equation: MIN */\r\n public static readonly GL_ALPHA_EQUATION_MIN = 0x8007;\r\n /** Alpha equation: MAX */\r\n public static readonly GL_ALPHA_EQUATION_MAX = 0x8008;\r\n /** Alpha equation: SUBTRACT */\r\n public static readonly GL_ALPHA_EQUATION_SUBTRACT = 0x800a;\r\n /** Alpha equation: REVERSE_SUBTRACT */\r\n public static readonly GL_ALPHA_EQUATION_REVERSE_SUBTRACT = 0x800b;\r\n\r\n /** Alpha blend function: SRC */\r\n public static readonly GL_ALPHA_FUNCTION_SRC = 0x0300;\r\n /** Alpha blend function: ONE_MINUS_SRC */\r\n public static readonly GL_ALPHA_FUNCTION_ONE_MINUS_SRC_COLOR = 0x0301;\r\n /** Alpha blend function: SRC_ALPHA */\r\n public static readonly GL_ALPHA_FUNCTION_SRC_ALPHA = 0x0302;\r\n /** Alpha blend function: ONE_MINUS_SRC_ALPHA */\r\n public static readonly GL_ALPHA_FUNCTION_ONE_MINUS_SRC_ALPHA = 0x0303;\r\n /** Alpha blend function: DST_ALPHA */\r\n public static readonly GL_ALPHA_FUNCTION_DST_ALPHA = 0x0304;\r\n /** Alpha blend function: ONE_MINUS_DST_ALPHA */\r\n public static readonly GL_ALPHA_FUNCTION_ONE_MINUS_DST_ALPHA = 0x0305;\r\n /** Alpha blend function: ONE_MINUS_DST */\r\n public static readonly GL_ALPHA_FUNCTION_DST_COLOR = 0x0306;\r\n /** Alpha blend function: ONE_MINUS_DST */\r\n public static readonly GL_ALPHA_FUNCTION_ONE_MINUS_DST_COLOR = 0x0307;\r\n /** Alpha blend function: SRC_ALPHA_SATURATED */\r\n public static readonly GL_ALPHA_FUNCTION_SRC_ALPHA_SATURATED = 0x0308;\r\n /** Alpha blend function: CONSTANT */\r\n public static readonly GL_ALPHA_FUNCTION_CONSTANT_COLOR = 0x8001;\r\n /** Alpha blend function: ONE_MINUS_CONSTANT */\r\n public static readonly GL_ALPHA_FUNCTION_ONE_MINUS_CONSTANT_COLOR = 0x8002;\r\n /** Alpha blend function: CONSTANT_ALPHA */\r\n public static readonly GL_ALPHA_FUNCTION_CONSTANT_ALPHA = 0x8003;\r\n /** Alpha blend function: ONE_MINUS_CONSTANT_ALPHA */\r\n public static readonly GL_ALPHA_FUNCTION_ONE_MINUS_CONSTANT_ALPHA = 0x8004;\r\n\r\n /** URL to the snippet server. Points to the public snippet server by default */\r\n public static SnippetUrl = \"https://snippet.babylonjs.com\";\r\n}\r\n","import type { ITextureInfo, IMaterial, IMaterialPbrMetallicRoughness, IMaterialOcclusionTextureInfo, ISampler, IMaterialExtension } from \"babylonjs-gltf2interface\";\r\nimport { ImageMimeType, MaterialAlphaMode, TextureMagFilter, TextureMinFilter, TextureWrapMode } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { TextureTools } from \"core/Misc/textureTools\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RawTexture } from \"core/Materials/Textures/rawTexture\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\n\r\nimport type { _Exporter } from \"./glTFExporter\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { DumpTools } from \"core/Misc/dumpTools\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\n/**\r\n * Interface for storing specular glossiness factors\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IPBRSpecularGlossiness {\r\n /**\r\n * Represents the linear diffuse factors of the material\r\n */\r\n diffuseColor: Color3;\r\n /**\r\n * Represents the linear specular factors of the material\r\n */\r\n specularColor: Color3;\r\n /**\r\n * Represents the smoothness of the material\r\n */\r\n glossiness: number;\r\n}\r\n\r\n/**\r\n * Interface for storing metallic roughness factors\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IPBRMetallicRoughness {\r\n /**\r\n * Represents the albedo color of the material\r\n */\r\n baseColor: Color3;\r\n /**\r\n * Represents the metalness of the material\r\n */\r\n metallic: Nullable;\r\n /**\r\n * Represents the roughness of the material\r\n */\r\n roughness: Nullable;\r\n /**\r\n * The metallic roughness texture data\r\n */\r\n metallicRoughnessTextureData?: Nullable;\r\n /**\r\n * The base color texture data\r\n */\r\n baseColorTextureData?: Nullable;\r\n}\r\n\r\nfunction getFileExtensionFromMimeType(mimeType: ImageMimeType): string {\r\n switch (mimeType) {\r\n case ImageMimeType.JPEG:\r\n return \".jpg\";\r\n case ImageMimeType.PNG:\r\n return \".png\";\r\n case ImageMimeType.WEBP:\r\n return \".webp\";\r\n }\r\n}\r\n\r\n/**\r\n * Utility methods for working with glTF material conversion properties. This class should only be used internally\r\n * @internal\r\n */\r\nexport class _GLTFMaterialExporter {\r\n /**\r\n * Represents the dielectric specular values for R, G and B\r\n */\r\n private static readonly _DielectricSpecular: Color3 = new Color3(0.04, 0.04, 0.04);\r\n\r\n /**\r\n * Allows the maximum specular power to be defined for material calculations\r\n */\r\n private static readonly _MaxSpecularPower = 1024;\r\n\r\n /**\r\n * Mapping to store textures\r\n */\r\n private _textureMap: { [textureId: string]: ITextureInfo } = {};\r\n\r\n // Mapping of internal textures to images to avoid exporting duplicate images.\r\n private _internalTextureToImage: { [uniqueId: number]: { [mimeType: string]: Promise } } = {};\r\n\r\n /**\r\n * Numeric tolerance value\r\n */\r\n private static readonly _Epsilon = 1e-6;\r\n\r\n /**\r\n * Reference to the glTF Exporter\r\n */\r\n private _exporter: _Exporter;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._textureMap = {};\r\n this._exporter = exporter;\r\n }\r\n\r\n /**\r\n * Specifies if two colors are approximately equal in value\r\n * @param color1 first color to compare to\r\n * @param color2 second color to compare to\r\n * @param epsilon threshold value\r\n */\r\n private static _FuzzyEquals(color1: Color3, color2: Color3, epsilon: number): boolean {\r\n return Scalar.WithinEpsilon(color1.r, color2.r, epsilon) && Scalar.WithinEpsilon(color1.g, color2.g, epsilon) && Scalar.WithinEpsilon(color1.b, color2.b, epsilon);\r\n }\r\n\r\n /**\r\n * Gets the materials from a Babylon scene and converts them to glTF materials\r\n * @param exportMaterials\r\n * @param mimeType texture mime type\r\n * @param hasTextureCoords specifies if texture coordinates are present on the material\r\n */\r\n public _convertMaterialsToGLTFAsync(exportMaterials: Set, mimeType: ImageMimeType, hasTextureCoords: boolean) {\r\n const promises: Promise[] = [];\r\n exportMaterials.forEach((material) => {\r\n if (material.getClassName() === \"StandardMaterial\") {\r\n promises.push(this._convertStandardMaterialAsync(material as StandardMaterial, mimeType, hasTextureCoords));\r\n } else if (material.getClassName().indexOf(\"PBR\") !== -1) {\r\n promises.push(this._convertPBRMaterialAsync(material as PBRMaterial, mimeType, hasTextureCoords));\r\n } else {\r\n Tools.Warn(`Unsupported material type: ${material.name}`);\r\n }\r\n });\r\n\r\n return Promise.all(promises).then(() => {\r\n /* do nothing */\r\n });\r\n }\r\n\r\n /**\r\n * Makes a copy of the glTF material without the texture parameters\r\n * @param originalMaterial original glTF material\r\n * @returns glTF material without texture parameters\r\n */\r\n public _stripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial {\r\n const newMaterial: IMaterial = {};\r\n if (originalMaterial) {\r\n newMaterial.name = originalMaterial.name;\r\n newMaterial.doubleSided = originalMaterial.doubleSided;\r\n newMaterial.alphaMode = originalMaterial.alphaMode;\r\n newMaterial.alphaCutoff = originalMaterial.alphaCutoff;\r\n newMaterial.emissiveFactor = originalMaterial.emissiveFactor;\r\n const originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;\r\n if (originalPBRMetallicRoughness) {\r\n newMaterial.pbrMetallicRoughness = {};\r\n newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;\r\n newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;\r\n newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;\r\n }\r\n }\r\n return newMaterial;\r\n }\r\n\r\n /**\r\n * Specifies if the material has any texture parameters present\r\n * @param material glTF Material\r\n * @returns boolean specifying if texture parameters are present\r\n */\r\n public _hasTexturesPresent(material: IMaterial): boolean {\r\n if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {\r\n return true;\r\n }\r\n const pbrMat = material.pbrMetallicRoughness;\r\n if (pbrMat) {\r\n if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {\r\n return true;\r\n }\r\n }\r\n\r\n if (material.extensions) {\r\n for (const extension in material.extensions) {\r\n const extensionObject = material.extensions[extension];\r\n if (extensionObject as IMaterialExtension) {\r\n return extensionObject.hasTextures?.();\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public _getTextureInfo(babylonTexture: Nullable): Nullable {\r\n if (babylonTexture) {\r\n const textureUid = babylonTexture.uid;\r\n if (textureUid in this._textureMap) {\r\n return this._textureMap[textureUid];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material\r\n * @param babylonStandardMaterial\r\n * @returns glTF Metallic Roughness Material representation\r\n */\r\n public _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness {\r\n // Defines a cubic bezier curve where x is specular power and y is roughness\r\n const P0 = new Vector2(0, 1);\r\n const P1 = new Vector2(0, 0.1);\r\n const P2 = new Vector2(0, 0.1);\r\n const P3 = new Vector2(1300, 0.1);\r\n\r\n /**\r\n * Given the control points, solve for x based on a given t for a cubic bezier curve\r\n * @param t a value between 0 and 1\r\n * @param p0 first control point\r\n * @param p1 second control point\r\n * @param p2 third control point\r\n * @param p3 fourth control point\r\n * @returns number result of cubic bezier curve at the specified t\r\n */\r\n function cubicBezierCurve(t: number, p0: number, p1: number, p2: number, p3: number): number {\r\n return (1 - t) * (1 - t) * (1 - t) * p0 + 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t * p3;\r\n }\r\n\r\n /**\r\n * Evaluates a specified specular power value to determine the appropriate roughness value,\r\n * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)\r\n * and roughness on the ordinant axis (y-axis)\r\n * @param specularPower specular power of standard material\r\n * @returns Number representing the roughness value\r\n */\r\n function solveForRoughness(specularPower: number): number {\r\n // Given P0.x = 0, P1.x = 0, P2.x = 0\r\n // x = t * t * t * P3.x\r\n // t = (x / P3.x)^(1/3)\r\n const t = Math.pow(specularPower / P3.x, 0.333333);\r\n return cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);\r\n }\r\n\r\n const diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace(babylonStandardMaterial.getScene().getEngine().useExactSrgbConversions).scale(0.5);\r\n const opacity = babylonStandardMaterial.alpha;\r\n const specularPower = Scalar.Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);\r\n\r\n const roughness = solveForRoughness(specularPower);\r\n\r\n const glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness = {\r\n baseColorFactor: [diffuse.r, diffuse.g, diffuse.b, opacity],\r\n metallicFactor: 0,\r\n roughnessFactor: roughness,\r\n };\r\n\r\n return glTFPbrMetallicRoughness;\r\n }\r\n\r\n /**\r\n * Computes the metallic factor\r\n * @param diffuse diffused value\r\n * @param specular specular value\r\n * @param oneMinusSpecularStrength one minus the specular strength\r\n * @returns metallic value\r\n */\r\n public static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number {\r\n if (specular < this._DielectricSpecular.r) {\r\n this._DielectricSpecular;\r\n return 0;\r\n }\r\n\r\n const a = this._DielectricSpecular.r;\r\n const b = (diffuse * oneMinusSpecularStrength) / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;\r\n const c = this._DielectricSpecular.r - specular;\r\n const D = b * b - 4.0 * a * c;\r\n return Scalar.Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);\r\n }\r\n\r\n /**\r\n * Sets the glTF alpha mode to a glTF material from the Babylon Material\r\n * @param glTFMaterial glTF material\r\n * @param babylonMaterial Babylon material\r\n */\r\n private static _SetAlphaMode(glTFMaterial: IMaterial, babylonMaterial: Material & { alphaCutOff: number }): void {\r\n if (babylonMaterial.needAlphaBlending()) {\r\n glTFMaterial.alphaMode = MaterialAlphaMode.BLEND;\r\n } else if (babylonMaterial.needAlphaTesting()) {\r\n glTFMaterial.alphaMode = MaterialAlphaMode.MASK;\r\n glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;\r\n }\r\n }\r\n\r\n /**\r\n * Converts a Babylon Standard Material to a glTF Material\r\n * @param babylonStandardMaterial BJS Standard Material\r\n * @param mimeType mime type to use for the textures\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n */\r\n public _convertStandardMaterialAsync(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise {\r\n const materialMap = this._exporter._materialMap;\r\n const materials = this._exporter._materials;\r\n const promises = [];\r\n const pbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);\r\n\r\n const material: IMaterial = { name: babylonStandardMaterial.name };\r\n if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {\r\n if (!babylonStandardMaterial.twoSidedLighting) {\r\n Tools.Warn(babylonStandardMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\r\n }\r\n material.doubleSided = true;\r\n }\r\n if (hasTextureCoords) {\r\n if (babylonStandardMaterial.diffuseTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n pbrMetallicRoughness.baseColorTexture = textureInfo;\r\n }\r\n })\r\n );\r\n }\r\n const bumpTexture = babylonStandardMaterial.bumpTexture;\r\n if (bumpTexture) {\r\n promises.push(\r\n this._exportTextureAsync(bumpTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n material.normalTexture = textureInfo;\r\n if (bumpTexture.level !== 1) {\r\n material.normalTexture.scale = bumpTexture.level;\r\n }\r\n }\r\n })\r\n );\r\n }\r\n if (babylonStandardMaterial.emissiveTexture) {\r\n material.emissiveFactor = [1.0, 1.0, 1.0];\r\n\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n material.emissiveTexture = textureInfo;\r\n }\r\n })\r\n );\r\n }\r\n if (babylonStandardMaterial.ambientTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n const occlusionTexture: IMaterialOcclusionTextureInfo = {\r\n index: textureInfo.index,\r\n };\r\n material.occlusionTexture = occlusionTexture;\r\n }\r\n })\r\n );\r\n }\r\n }\r\n\r\n if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {\r\n if (babylonStandardMaterial.alphaMode === Constants.ALPHA_COMBINE) {\r\n material.alphaMode = MaterialAlphaMode.BLEND;\r\n } else {\r\n Tools.Warn(babylonStandardMaterial.name + \": glTF 2.0 does not support alpha mode: \" + babylonStandardMaterial.alphaMode.toString());\r\n }\r\n }\r\n if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter._FuzzyEquals(babylonStandardMaterial.emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\r\n material.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();\r\n }\r\n\r\n material.pbrMetallicRoughness = pbrMetallicRoughness;\r\n _GLTFMaterialExporter._SetAlphaMode(material, babylonStandardMaterial);\r\n\r\n materials.push(material);\r\n materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;\r\n\r\n return this._finishMaterial(promises, material, babylonStandardMaterial, mimeType);\r\n }\r\n\r\n private _finishMaterial(promises: Promise[], glTFMaterial: IMaterial, babylonMaterial: Material, mimeType: ImageMimeType) {\r\n return Promise.all(promises).then(() => {\r\n const textures = this._exporter._extensionsPostExportMaterialAdditionalTextures(\"exportMaterial\", glTFMaterial, babylonMaterial);\r\n let tasks: Nullable>[]> = null;\r\n\r\n for (const texture of textures) {\r\n if (!tasks) {\r\n tasks = [];\r\n }\r\n tasks.push(this._exportTextureAsync(texture, mimeType));\r\n }\r\n\r\n if (!tasks) {\r\n tasks = [Promise.resolve(null)];\r\n }\r\n\r\n return Promise.all(tasks).then(() => {\r\n const extensionWork = this._exporter._extensionsPostExportMaterialAsync(\"exportMaterial\", glTFMaterial, babylonMaterial);\r\n if (!extensionWork) {\r\n return glTFMaterial;\r\n }\r\n return extensionWork.then(() => glTFMaterial);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Converts an image typed array buffer to a base64 image\r\n * @param buffer typed array buffer\r\n * @param width width of the image\r\n * @param height height of the image\r\n * @param mimeType mimetype of the image\r\n * @returns base64 image string\r\n */\r\n private async _getImageDataAsync(buffer: Uint8Array | Float32Array, width: number, height: number, mimeType: ImageMimeType): Promise {\r\n const textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n\r\n const hostingScene = this._exporter._babylonScene;\r\n const engine = hostingScene.getEngine();\r\n\r\n // Create a temporary texture with the texture buffer data\r\n const tempTexture = engine.createRawTexture(buffer, width, height, Constants.TEXTUREFORMAT_RGBA, false, true, Texture.NEAREST_SAMPLINGMODE, null, textureType);\r\n\r\n await TextureTools.ApplyPostProcess(\"pass\", tempTexture, hostingScene, textureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\r\n\r\n const data = await engine._readTexturePixels(tempTexture, width, height);\r\n\r\n return (await DumpTools.DumpDataAsync(width, height, data, mimeType, undefined, true, true)) as ArrayBuffer;\r\n }\r\n\r\n /**\r\n * Generates a white texture based on the specified width and height\r\n * @param width width of the texture in pixels\r\n * @param height height of the texture in pixels\r\n * @param scene babylonjs scene\r\n * @returns white texture\r\n */\r\n private _createWhiteTexture(width: number, height: number, scene: Scene): Texture {\r\n const data = new Uint8Array(width * height * 4);\r\n\r\n for (let i = 0; i < data.length; i = i + 4) {\r\n data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xff;\r\n }\r\n\r\n const rawTexture = RawTexture.CreateRGBATexture(data, width, height, scene);\r\n\r\n return rawTexture;\r\n }\r\n\r\n /**\r\n * Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null\r\n * @param texture1 first texture to resize\r\n * @param texture2 second texture to resize\r\n * @param scene babylonjs scene\r\n * @returns resized textures or null\r\n */\r\n private _resizeTexturesToSameDimensions(texture1: Nullable, texture2: Nullable, scene: Scene): { texture1: BaseTexture; texture2: BaseTexture } {\r\n const texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };\r\n const texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };\r\n let resizedTexture1: BaseTexture;\r\n let resizedTexture2: BaseTexture;\r\n\r\n if (texture1Size.width < texture2Size.width) {\r\n if (texture1 && texture1 instanceof Texture) {\r\n resizedTexture1 = TextureTools.CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);\r\n } else {\r\n resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);\r\n }\r\n resizedTexture2 = texture2!;\r\n } else if (texture1Size.width > texture2Size.width) {\r\n if (texture2 && texture2 instanceof Texture) {\r\n resizedTexture2 = TextureTools.CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);\r\n } else {\r\n resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);\r\n }\r\n resizedTexture1 = texture1!;\r\n } else {\r\n resizedTexture1 = texture1!;\r\n resizedTexture2 = texture2!;\r\n }\r\n\r\n return {\r\n texture1: resizedTexture1!,\r\n texture2: resizedTexture2!,\r\n };\r\n }\r\n\r\n /**\r\n * Converts an array of pixels to a Float32Array\r\n * Throws an error if the pixel format is not supported\r\n * @param pixels - array buffer containing pixel values\r\n * @returns Float32 of pixels\r\n */\r\n private _convertPixelArrayToFloat32(pixels: ArrayBufferView): Float32Array {\r\n if (pixels instanceof Uint8Array) {\r\n const length = pixels.length;\r\n const buffer = new Float32Array(pixels.length);\r\n for (let i = 0; i < length; ++i) {\r\n buffer[i] = pixels[i] / 255;\r\n }\r\n return buffer;\r\n } else if (pixels instanceof Float32Array) {\r\n return pixels;\r\n } else {\r\n throw new Error(\"Unsupported pixel format!\");\r\n }\r\n }\r\n\r\n /**\r\n * Convert Specular Glossiness Textures to Metallic Roughness\r\n * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness\r\n * @link https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js\r\n * @param diffuseTexture texture used to store diffuse information\r\n * @param specularGlossinessTexture texture used to store specular and glossiness information\r\n * @param factors specular glossiness material factors\r\n * @param mimeType the mime type to use for the texture\r\n * @returns pbr metallic roughness interface or null\r\n */\r\n private async _convertSpecularGlossinessTexturesToMetallicRoughnessAsync(\r\n diffuseTexture: Nullable,\r\n specularGlossinessTexture: Nullable,\r\n factors: _IPBRSpecularGlossiness,\r\n mimeType: ImageMimeType\r\n ): Promise<_IPBRMetallicRoughness> {\r\n const promises = new Array>();\r\n if (!(diffuseTexture || specularGlossinessTexture)) {\r\n return Promise.reject(\"_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!\");\r\n }\r\n\r\n const scene: Nullable = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;\r\n if (scene) {\r\n const resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);\r\n\r\n const diffuseSize = resizedTextures.texture1?.getSize();\r\n\r\n let diffuseBuffer: Float32Array;\r\n let specularGlossinessBuffer: Float32Array;\r\n\r\n const width = diffuseSize.width;\r\n const height = diffuseSize.height;\r\n\r\n const diffusePixels = await resizedTextures.texture1.readPixels();\r\n const specularPixels = await resizedTextures.texture2.readPixels();\r\n\r\n if (diffusePixels) {\r\n diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);\r\n } else {\r\n return Promise.reject(\"Failed to retrieve pixels from diffuse texture!\");\r\n }\r\n if (specularPixels) {\r\n specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);\r\n } else {\r\n return Promise.reject(\"Failed to retrieve pixels from specular glossiness texture!\");\r\n }\r\n\r\n const byteLength = specularGlossinessBuffer.byteLength;\r\n\r\n const metallicRoughnessBuffer = new Uint8Array(byteLength);\r\n const baseColorBuffer = new Uint8Array(byteLength);\r\n\r\n const strideSize = 4;\r\n const maxBaseColor = Color3.Black();\r\n let maxMetallic = 0;\r\n let maxRoughness = 0;\r\n\r\n for (let h = 0; h < height; ++h) {\r\n for (let w = 0; w < width; ++w) {\r\n const offset = (width * h + w) * strideSize;\r\n\r\n const diffuseColor = new Color3(diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2])\r\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\r\n .multiply(factors.diffuseColor);\r\n const specularColor = new Color3(specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2])\r\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\r\n .multiply(factors.specularColor);\r\n const glossiness = specularGlossinessBuffer[offset + 3] * factors.glossiness;\r\n\r\n const specularGlossiness: _IPBRSpecularGlossiness = {\r\n diffuseColor: diffuseColor,\r\n specularColor: specularColor,\r\n glossiness: glossiness,\r\n };\r\n\r\n const metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);\r\n maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);\r\n maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);\r\n maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);\r\n maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic!);\r\n maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness!);\r\n\r\n baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;\r\n baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;\r\n baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;\r\n baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;\r\n\r\n metallicRoughnessBuffer[offset] = 0;\r\n metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness! * 255;\r\n metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic! * 255;\r\n metallicRoughnessBuffer[offset + 3] = 255;\r\n }\r\n }\r\n\r\n // Retrieves the metallic roughness factors from the maximum texture values.\r\n const metallicRoughnessFactors: _IPBRMetallicRoughness = {\r\n baseColor: maxBaseColor,\r\n metallic: maxMetallic,\r\n roughness: maxRoughness,\r\n };\r\n\r\n let writeOutMetallicRoughnessTexture = false;\r\n let writeOutBaseColorTexture = false;\r\n\r\n for (let h = 0; h < height; ++h) {\r\n for (let w = 0; w < width; ++w) {\r\n const destinationOffset = (width * h + w) * strideSize;\r\n\r\n baseColorBuffer[destinationOffset] /= metallicRoughnessFactors.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.r : 1;\r\n baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.g : 1;\r\n baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.b : 1;\r\n\r\n const linearBaseColorPixel = Color3.FromInts(\r\n baseColorBuffer[destinationOffset],\r\n baseColorBuffer[destinationOffset + 1],\r\n baseColorBuffer[destinationOffset + 2]\r\n );\r\n const sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace(scene.getEngine().useExactSrgbConversions);\r\n baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;\r\n baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;\r\n baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;\r\n\r\n if (!_GLTFMaterialExporter._FuzzyEquals(sRGBBaseColorPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\r\n writeOutBaseColorTexture = true;\r\n }\r\n\r\n metallicRoughnessBuffer[destinationOffset + 1] /=\r\n metallicRoughnessFactors.roughness! > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.roughness! : 1;\r\n metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors.metallic! > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.metallic! : 1;\r\n\r\n const metallicRoughnessPixel = Color3.FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);\r\n\r\n if (!_GLTFMaterialExporter._FuzzyEquals(metallicRoughnessPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\r\n writeOutMetallicRoughnessTexture = true;\r\n }\r\n }\r\n }\r\n\r\n if (writeOutMetallicRoughnessTexture) {\r\n promises.push(\r\n this._getImageDataAsync(metallicRoughnessBuffer, width, height, mimeType).then((data) => {\r\n metallicRoughnessFactors.metallicRoughnessTextureData = data;\r\n })\r\n );\r\n }\r\n if (writeOutBaseColorTexture) {\r\n promises.push(\r\n this._getImageDataAsync(baseColorBuffer, width, height, mimeType).then((data) => {\r\n metallicRoughnessFactors.baseColorTextureData = data;\r\n })\r\n );\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return metallicRoughnessFactors;\r\n });\r\n } else {\r\n return Promise.reject(\"_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!\");\r\n }\r\n }\r\n\r\n /**\r\n * Converts specular glossiness material properties to metallic roughness\r\n * @param specularGlossiness interface with specular glossiness material properties\r\n * @returns interface with metallic roughness material properties\r\n */\r\n private _convertSpecularGlossinessToMetallicRoughness(specularGlossiness: _IPBRSpecularGlossiness): _IPBRMetallicRoughness {\r\n const diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);\r\n const specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);\r\n const oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);\r\n const metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);\r\n const baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(\r\n oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon)\r\n );\r\n const baseColorFromSpecular = specularGlossiness.specularColor\r\n .subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic))\r\n .scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));\r\n let baseColor = Color3.Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);\r\n baseColor = baseColor.clampToRef(0, 1, baseColor);\r\n\r\n const metallicRoughness: _IPBRMetallicRoughness = {\r\n baseColor: baseColor,\r\n metallic: metallic,\r\n roughness: 1 - specularGlossiness.glossiness,\r\n };\r\n\r\n return metallicRoughness;\r\n }\r\n\r\n /**\r\n * Calculates the surface reflectance, independent of lighting conditions\r\n * @param color Color source to calculate brightness from\r\n * @returns number representing the perceived brightness, or zero if color is undefined\r\n */\r\n private _getPerceivedBrightness(color: Color3): number {\r\n if (color) {\r\n return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);\r\n }\r\n return 0;\r\n }\r\n\r\n /**\r\n * Returns the maximum color component value\r\n * @param color\r\n * @returns maximum color component value, or zero if color is null or undefined\r\n */\r\n private _getMaxComponent(color: Color3): number {\r\n if (color) {\r\n return Math.max(color.r, Math.max(color.g, color.b));\r\n }\r\n return 0;\r\n }\r\n\r\n /**\r\n * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors\r\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\r\n * @param mimeType mime type to use for the textures\r\n * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns glTF PBR Metallic Roughness factors\r\n */\r\n private _convertMetalRoughFactorsToMetallicRoughnessAsync(\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n mimeType: ImageMimeType,\r\n glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n hasTextureCoords: boolean\r\n ): Promise<_IPBRMetallicRoughness> {\r\n const promises = [];\r\n const baseColor = babylonPBRMaterial._albedoColor;\r\n const metallic = babylonPBRMaterial._metallic;\r\n const roughness = babylonPBRMaterial._roughness;\r\n const metallicRoughness: _IPBRMetallicRoughness = {\r\n baseColor: baseColor,\r\n metallic: metallic,\r\n roughness: roughness,\r\n };\r\n\r\n if (hasTextureCoords) {\r\n const albedoTexture = babylonPBRMaterial._albedoTexture;\r\n if (albedoTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonPBRMaterial._albedoTexture!, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;\r\n }\r\n })\r\n );\r\n }\r\n const metallicTexture = babylonPBRMaterial._metallicTexture;\r\n if (metallicTexture) {\r\n promises.push(\r\n this._exportTextureAsync(metallicTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;\r\n }\r\n })\r\n );\r\n }\r\n }\r\n return Promise.all(promises).then(() => {\r\n return metallicRoughness;\r\n });\r\n }\r\n\r\n private _getTextureSampler(texture: Nullable): ISampler {\r\n const sampler: ISampler = {};\r\n if (!texture || !(texture instanceof Texture)) {\r\n return sampler;\r\n }\r\n\r\n const wrapS = this._getGLTFTextureWrapMode(texture.wrapU);\r\n if (wrapS !== TextureWrapMode.REPEAT) {\r\n sampler.wrapS = wrapS;\r\n }\r\n\r\n const wrapT = this._getGLTFTextureWrapMode(texture.wrapV);\r\n if (wrapT !== TextureWrapMode.REPEAT) {\r\n sampler.wrapT = wrapT;\r\n }\r\n\r\n switch (texture.samplingMode) {\r\n case Texture.LINEAR_LINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_LINEAR_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_LINEAR_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_NEAREST;\r\n break;\r\n }\r\n }\r\n\r\n return sampler;\r\n }\r\n\r\n private _getGLTFTextureWrapMode(wrapMode: number): TextureWrapMode {\r\n switch (wrapMode) {\r\n case Texture.WRAP_ADDRESSMODE: {\r\n return TextureWrapMode.REPEAT;\r\n }\r\n case Texture.CLAMP_ADDRESSMODE: {\r\n return TextureWrapMode.CLAMP_TO_EDGE;\r\n }\r\n case Texture.MIRROR_ADDRESSMODE: {\r\n return TextureWrapMode.MIRRORED_REPEAT;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported Texture Wrap Mode ${wrapMode}!`);\r\n return TextureWrapMode.REPEAT;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors\r\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\r\n * @param mimeType mime type to use for the textures\r\n * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns glTF PBR Metallic Roughness factors\r\n */\r\n private _convertSpecGlossFactorsToMetallicRoughnessAsync(\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n mimeType: ImageMimeType,\r\n pbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n hasTextureCoords: boolean\r\n ): Promise<_IPBRMetallicRoughness> {\r\n return Promise.resolve().then(() => {\r\n const specGloss: _IPBRSpecularGlossiness = {\r\n diffuseColor: babylonPBRMaterial._albedoColor,\r\n specularColor: babylonPBRMaterial._reflectivityColor,\r\n glossiness: babylonPBRMaterial._microSurface,\r\n };\r\n const albedoTexture = babylonPBRMaterial._albedoTexture;\r\n const reflectivityTexture = babylonPBRMaterial._reflectivityTexture;\r\n const useMicrosurfaceFromReflectivityMapAlpha = babylonPBRMaterial._useMicroSurfaceFromReflectivityMapAlpha;\r\n if (reflectivityTexture && !useMicrosurfaceFromReflectivityMapAlpha) {\r\n return Promise.reject(\"_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported\");\r\n }\r\n if ((albedoTexture || reflectivityTexture) && hasTextureCoords) {\r\n const samplerIndex = this._exportTextureSampler(albedoTexture || reflectivityTexture);\r\n return this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(albedoTexture, reflectivityTexture, specGloss, mimeType).then((metallicRoughnessFactors) => {\r\n const textures = this._exporter._textures;\r\n if (metallicRoughnessFactors.baseColorTextureData) {\r\n const imageIndex = this._exportImage(`baseColor${textures.length}`, mimeType, metallicRoughnessFactors.baseColorTextureData);\r\n pbrMetallicRoughness.baseColorTexture = this._exportTextureInfo(imageIndex, samplerIndex, albedoTexture?.coordinatesIndex);\r\n }\r\n if (metallicRoughnessFactors.metallicRoughnessTextureData) {\r\n const imageIndex = this._exportImage(`metallicRoughness${textures.length}`, mimeType, metallicRoughnessFactors.metallicRoughnessTextureData);\r\n pbrMetallicRoughness.metallicRoughnessTexture = this._exportTextureInfo(imageIndex, samplerIndex, reflectivityTexture?.coordinatesIndex);\r\n }\r\n\r\n return metallicRoughnessFactors;\r\n });\r\n } else {\r\n return this._convertSpecularGlossinessToMetallicRoughness(specGloss);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Converts a Babylon PBR Base Material to a glTF Material\r\n * @param babylonPBRMaterial BJS PBR Base Material\r\n * @param mimeType mime type to use for the textures\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n */\r\n public _convertPBRMaterialAsync(babylonPBRMaterial: PBRBaseMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise {\r\n const glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness = {};\r\n const glTFMaterial: IMaterial = {\r\n name: babylonPBRMaterial.name,\r\n };\r\n const useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();\r\n\r\n if (useMetallicRoughness) {\r\n const albedoColor = babylonPBRMaterial._albedoColor;\r\n const alpha = babylonPBRMaterial.alpha;\r\n if (albedoColor) {\r\n glTFPbrMetallicRoughness.baseColorFactor = [albedoColor.r, albedoColor.g, albedoColor.b, alpha];\r\n }\r\n return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\r\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\r\n });\r\n } else {\r\n return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\r\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\r\n });\r\n }\r\n }\r\n\r\n private _setMetallicRoughnessPbrMaterial(\r\n metallicRoughness: Nullable<_IPBRMetallicRoughness>,\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n glTFMaterial: IMaterial,\r\n glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n mimeType: ImageMimeType,\r\n hasTextureCoords: boolean\r\n ): Promise {\r\n const materialMap = this._exporter._materialMap;\r\n const materials = this._exporter._materials;\r\n const promises = [];\r\n if (metallicRoughness) {\r\n _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial as PBRMaterial);\r\n if (\r\n !(\r\n _GLTFMaterialExporter._FuzzyEquals(metallicRoughness.baseColor, Color3.White(), _GLTFMaterialExporter._Epsilon) &&\r\n babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon\r\n )\r\n ) {\r\n glTFPbrMetallicRoughness.baseColorFactor = [metallicRoughness.baseColor.r, metallicRoughness.baseColor.g, metallicRoughness.baseColor.b, babylonPBRMaterial.alpha];\r\n }\r\n\r\n if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {\r\n glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;\r\n }\r\n if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {\r\n glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;\r\n }\r\n\r\n if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {\r\n if (!babylonPBRMaterial._twoSidedLighting) {\r\n Tools.Warn(babylonPBRMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\r\n }\r\n glTFMaterial.doubleSided = true;\r\n }\r\n\r\n if (hasTextureCoords) {\r\n const bumpTexture = babylonPBRMaterial._bumpTexture;\r\n if (bumpTexture) {\r\n const promise = this._exportTextureAsync(bumpTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFMaterial.normalTexture = glTFTexture;\r\n if (bumpTexture.level !== 1) {\r\n glTFMaterial.normalTexture.scale = bumpTexture.level;\r\n }\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n const ambientTexture = babylonPBRMaterial._ambientTexture;\r\n if (ambientTexture) {\r\n const promise = this._exportTextureAsync(ambientTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n const occlusionTexture: IMaterialOcclusionTextureInfo = {\r\n index: glTFTexture.index,\r\n texCoord: glTFTexture.texCoord,\r\n extensions: glTFTexture.extensions,\r\n };\r\n\r\n glTFMaterial.occlusionTexture = occlusionTexture;\r\n const ambientTextureStrength = babylonPBRMaterial._ambientTextureStrength;\r\n if (ambientTextureStrength) {\r\n occlusionTexture.strength = ambientTextureStrength;\r\n }\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n const emissiveTexture = babylonPBRMaterial._emissiveTexture;\r\n if (emissiveTexture) {\r\n const promise = this._exportTextureAsync(emissiveTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFMaterial.emissiveTexture = glTFTexture;\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n }\r\n const emissiveColor = babylonPBRMaterial._emissiveColor;\r\n if (!_GLTFMaterialExporter._FuzzyEquals(emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\r\n glTFMaterial.emissiveFactor = emissiveColor.asArray();\r\n }\r\n\r\n glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;\r\n materials.push(glTFMaterial);\r\n materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;\r\n }\r\n\r\n return this._finishMaterial(promises, glTFMaterial, babylonPBRMaterial, mimeType);\r\n }\r\n\r\n private _getPixelsFromTexture(babylonTexture: BaseTexture): Promise> {\r\n const pixels =\r\n babylonTexture.textureType === Constants.TEXTURETYPE_UNSIGNED_INT\r\n ? (babylonTexture.readPixels() as Promise)\r\n : (babylonTexture.readPixels() as Promise);\r\n return pixels;\r\n }\r\n\r\n /**\r\n * Extracts a texture from a Babylon texture into file data and glTF data\r\n * @param babylonTexture Babylon texture to extract\r\n * @param mimeType Mime Type of the babylonTexture\r\n * @returns glTF texture info, or null if the texture format is not supported\r\n */\r\n public _exportTextureAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise> {\r\n const extensionPromise = this._exporter._extensionsPreExportTextureAsync(\"exporter\", babylonTexture as Texture, mimeType);\r\n if (!extensionPromise) {\r\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\r\n }\r\n\r\n return extensionPromise.then((texture) => {\r\n if (!texture) {\r\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\r\n }\r\n return this._exportTextureInfoAsync(texture, mimeType);\r\n });\r\n }\r\n\r\n public async _exportTextureInfoAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise> {\r\n const textureUid = babylonTexture.uid;\r\n if (!(textureUid in this._textureMap)) {\r\n const pixels = await this._getPixelsFromTexture(babylonTexture);\r\n if (!pixels) {\r\n return null;\r\n }\r\n\r\n const samplerIndex = this._exportTextureSampler(babylonTexture);\r\n\r\n // Preserve texture mime type if defined\r\n const textureMimeType = (babylonTexture as Texture).mimeType;\r\n if (textureMimeType) {\r\n switch (textureMimeType) {\r\n case \"image/jpeg\":\r\n case \"image/png\":\r\n case \"image/webp\":\r\n mimeType = textureMimeType as ImageMimeType;\r\n break;\r\n default:\r\n Tools.Warn(`Unsupported media type: ${textureMimeType}`);\r\n break;\r\n }\r\n }\r\n\r\n const internalTextureToImage = this._internalTextureToImage;\r\n const internalTextureUniqueId = babylonTexture.getInternalTexture()!.uniqueId;\r\n internalTextureToImage[internalTextureUniqueId] ||= {};\r\n let imageIndexPromise = internalTextureToImage[internalTextureUniqueId][mimeType];\r\n if (imageIndexPromise === undefined) {\r\n const size = babylonTexture.getSize();\r\n imageIndexPromise = (async () => {\r\n const data = await this._getImageDataAsync(pixels, size.width, size.height, mimeType);\r\n return this._exportImage(babylonTexture.name, mimeType, data);\r\n })();\r\n internalTextureToImage[internalTextureUniqueId][mimeType] = imageIndexPromise;\r\n }\r\n\r\n const textureInfo = this._exportTextureInfo(await imageIndexPromise, samplerIndex, babylonTexture.coordinatesIndex);\r\n this._textureMap[textureUid] = textureInfo;\r\n this._exporter._extensionsPostExportTextures(\"exporter\", this._textureMap[textureUid], babylonTexture);\r\n }\r\n\r\n return this._textureMap[textureUid];\r\n }\r\n\r\n private _exportImage(name: string, mimeType: ImageMimeType, data: ArrayBuffer): number {\r\n const imageData = this._exporter._imageData;\r\n\r\n const baseName = name.replace(/\\.\\/|\\/|\\.\\\\|\\\\/g, \"_\");\r\n const extension = getFileExtensionFromMimeType(mimeType);\r\n let fileName = baseName + extension;\r\n if (fileName in imageData) {\r\n fileName = `${baseName}_${Tools.RandomId()}${extension}`;\r\n }\r\n\r\n imageData[fileName] = {\r\n data: data,\r\n mimeType: mimeType,\r\n };\r\n\r\n const images = this._exporter._images;\r\n images.push({\r\n name: name,\r\n uri: fileName,\r\n });\r\n\r\n return images.length - 1;\r\n }\r\n\r\n private _exportTextureInfo(imageIndex: number, samplerIndex: number, coordinatesIndex?: number): ITextureInfo {\r\n const textures = this._exporter._textures;\r\n let textureIndex = textures.findIndex((t) => t.sampler == samplerIndex && t.source === imageIndex);\r\n if (textureIndex === -1) {\r\n textureIndex = textures.length;\r\n textures.push({\r\n source: imageIndex,\r\n sampler: samplerIndex,\r\n });\r\n }\r\n\r\n const textureInfo: ITextureInfo = { index: textureIndex };\r\n if (coordinatesIndex) {\r\n textureInfo.texCoord = coordinatesIndex;\r\n }\r\n return textureInfo;\r\n }\r\n\r\n private _exportTextureSampler(texture: Nullable): number {\r\n const sampler = this._getTextureSampler(texture);\r\n\r\n // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler\r\n const samplers = this._exporter._samplers;\r\n const samplerIndex = samplers.findIndex(\r\n (s) => s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter && s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT\r\n );\r\n if (samplerIndex !== -1) {\r\n return samplerIndex;\r\n }\r\n\r\n samplers.push(sampler);\r\n return samplers.length - 1;\r\n }\r\n}\r\n","import type {\r\n IBufferView,\r\n IAccessor,\r\n INode,\r\n IScene,\r\n IMesh,\r\n IMaterial,\r\n ITexture,\r\n IImage,\r\n ISampler,\r\n IAnimation,\r\n IMeshPrimitive,\r\n IBuffer,\r\n IGLTF,\r\n ITextureInfo,\r\n ISkin,\r\n ICamera,\r\n} from \"babylonjs-gltf2interface\";\r\nimport { AccessorType, ImageMimeType, MeshPrimitiveMode, AccessorComponentType, CameraType } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { FloatArray, IndicesArray, Nullable } from \"core/types\";\r\nimport { Matrix, TmpVectors } from \"core/Maths/math.vector\";\r\nimport { Vector2, Vector3, Vector4, Quaternion } from \"core/Maths/math.vector\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { Node } from \"core/node\";\r\nimport { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"core/Meshes/subMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { MorphTarget } from \"core/Morph/morphTarget\";\r\nimport { LinesMesh } from \"core/Meshes/linesMesh\";\r\nimport { InstancedMesh } from \"core/Meshes/instancedMesh\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Material } from \"core/Materials/material\";\r\nimport { Engine } from \"core/Engines/engine\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\nimport type { IGLTFExporterExtensionV2 } from \"./glTFExporterExtension\";\r\nimport { _GLTFMaterialExporter } from \"./glTFMaterialExporter\";\r\nimport type { IExportOptions } from \"./glTFSerializer\";\r\nimport { _GLTFUtilities } from \"./glTFUtilities\";\r\nimport { GLTFData } from \"./glTFData\";\r\nimport { _GLTFAnimation } from \"./glTFAnimation\";\r\nimport { Camera } from \"core/Cameras/camera\";\r\nimport { EngineStore } from \"core/Engines/engineStore\";\r\nimport { MultiMaterial } from \"core/Materials/multiMaterial\";\r\n\r\n// Matrix that converts handedness on the X-axis.\r\nconst convertHandednessMatrix = Matrix.Compose(new Vector3(-1, 1, 1), Quaternion.Identity(), Vector3.Zero());\r\n\r\nfunction isNoopNode(node: Node, useRightHandedSystem: boolean): boolean {\r\n if (!(node instanceof TransformNode)) {\r\n return false;\r\n }\r\n\r\n // Transform\r\n if (useRightHandedSystem) {\r\n const matrix = node.getWorldMatrix();\r\n if (!matrix.isIdentity()) {\r\n return false;\r\n }\r\n } else {\r\n const matrix = node.getWorldMatrix().multiplyToRef(convertHandednessMatrix, TmpVectors.Matrix[0]);\r\n if (!matrix.isIdentity()) {\r\n return false;\r\n }\r\n }\r\n\r\n // Geometry\r\n if ((node instanceof Mesh && node.geometry) || (node instanceof InstancedMesh && node.sourceMesh.geometry)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n}\r\n\r\nfunction convertNodeHandedness(node: INode): void {\r\n const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);\r\n const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);\r\n const scale = Vector3.FromArrayToRef(node.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);\r\n const matrix = Matrix.ComposeToRef(scale, rotation, translation, TmpVectors.Matrix[0]).multiplyToRef(convertHandednessMatrix, TmpVectors.Matrix[0]);\r\n\r\n matrix.decompose(scale, rotation, translation);\r\n\r\n if (translation.equalsToFloats(0, 0, 0)) {\r\n delete node.translation;\r\n } else {\r\n node.translation = translation.asArray();\r\n }\r\n\r\n if (Quaternion.IsIdentity(rotation)) {\r\n delete node.rotation;\r\n } else {\r\n node.rotation = rotation.asArray();\r\n }\r\n\r\n if (scale.equalsToFloats(1, 1, 1)) {\r\n delete node.scale;\r\n } else {\r\n node.scale = scale.asArray();\r\n }\r\n}\r\n\r\n/**\r\n * Utility interface for storing vertex attribute data\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IVertexAttributeData {\r\n /**\r\n * Specifies the Babylon Vertex Buffer Type (Position, Normal, Color, etc.)\r\n */\r\n kind: string;\r\n\r\n /**\r\n * Specifies the glTF Accessor Type (VEC2, VEC3, etc.)\r\n */\r\n accessorType: AccessorType;\r\n\r\n /**\r\n * Specifies the glTF Accessor Component Type (BYTE, UNSIGNED_BYTE, FLOAT, SHORT, INT, etc..)\r\n */\r\n accessorComponentType: AccessorComponentType;\r\n\r\n /**\r\n * Specifies the BufferView index for the vertex attribute data\r\n */\r\n bufferViewIndex?: number;\r\n\r\n byteStride?: number;\r\n}\r\n/**\r\n * Converts Babylon Scene into glTF 2.0.\r\n * @internal\r\n */\r\nexport class _Exporter {\r\n /**\r\n * Stores the glTF to export\r\n */\r\n public _glTF: IGLTF;\r\n /**\r\n * Stores all generated buffer views, which represents views into the main glTF buffer data\r\n */\r\n public _bufferViews: IBufferView[];\r\n /**\r\n * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF\r\n */\r\n public _accessors: IAccessor[];\r\n /**\r\n * Stores all the generated nodes, which contains transform and/or mesh information per node\r\n */\r\n public _nodes: INode[];\r\n /**\r\n * Stores all the generated glTF scenes, which stores multiple node hierarchies\r\n */\r\n private _scenes: IScene[];\r\n /**\r\n * Stores all the generated glTF cameras\r\n */\r\n private _cameras: ICamera[];\r\n /**\r\n * Stores all the generated mesh information, each containing a set of primitives to render in glTF\r\n */\r\n private _meshes: IMesh[];\r\n /**\r\n * Stores all the generated material information, which represents the appearance of each primitive\r\n */\r\n public _materials: IMaterial[];\r\n\r\n public _materialMap: { [materialID: number]: number };\r\n /**\r\n * Stores all the generated texture information, which is referenced by glTF materials\r\n */\r\n public _textures: ITexture[];\r\n /**\r\n * Stores all the generated image information, which is referenced by glTF textures\r\n */\r\n public _images: IImage[];\r\n\r\n /**\r\n * Stores all the texture samplers\r\n */\r\n public _samplers: ISampler[];\r\n /**\r\n * Stores all the generated glTF skins\r\n */\r\n public _skins: ISkin[];\r\n /**\r\n * Stores all the generated animation samplers, which is referenced by glTF animations\r\n */\r\n /**\r\n * Stores the animations for glTF models\r\n */\r\n private _animations: IAnimation[];\r\n /**\r\n * Stores the total amount of bytes stored in the glTF buffer\r\n */\r\n private _totalByteLength: number;\r\n /**\r\n * Stores a reference to the Babylon scene containing the source geometry and material information\r\n */\r\n public _babylonScene: Scene;\r\n /**\r\n * Stores a map of the image data, where the key is the file name and the value\r\n * is the image data\r\n */\r\n public _imageData: { [fileName: string]: { data: ArrayBuffer; mimeType: ImageMimeType } };\r\n\r\n private _orderedImageData: Array<{ data: ArrayBuffer; mimeType: ImageMimeType }>;\r\n\r\n /**\r\n * Stores a map of the unique id of a node to its index in the node array\r\n */\r\n private _nodeMap: { [key: number]: number };\r\n\r\n /**\r\n * Baked animation sample rate\r\n */\r\n private _animationSampleRate: number;\r\n\r\n private _options: IExportOptions;\r\n\r\n private _localEngine: Engine;\r\n\r\n public _glTFMaterialExporter: _GLTFMaterialExporter;\r\n\r\n private _extensions: { [name: string]: IGLTFExporterExtensionV2 } = {};\r\n\r\n private static _ExtensionNames = new Array();\r\n private static _ExtensionFactories: { [name: string]: (exporter: _Exporter) => IGLTFExporterExtensionV2 } = {};\r\n\r\n private _applyExtension(\r\n node: Nullable,\r\n extensions: IGLTFExporterExtensionV2[],\r\n index: number,\r\n actionAsync: (extension: IGLTFExporterExtensionV2, node: Nullable) => Promise> | undefined\r\n ): Promise> {\r\n if (index >= extensions.length) {\r\n return Promise.resolve(node);\r\n }\r\n\r\n const currentPromise = actionAsync(extensions[index], node);\r\n\r\n if (!currentPromise) {\r\n return this._applyExtension(node, extensions, index + 1, actionAsync);\r\n }\r\n\r\n return currentPromise.then((newNode) => this._applyExtension(newNode, extensions, index + 1, actionAsync));\r\n }\r\n\r\n private _applyExtensions(\r\n node: Nullable,\r\n actionAsync: (extension: IGLTFExporterExtensionV2, node: Nullable) => Promise> | undefined\r\n ): Promise> {\r\n const extensions: IGLTFExporterExtensionV2[] = [];\r\n for (const name of _Exporter._ExtensionNames) {\r\n extensions.push(this._extensions[name]);\r\n }\r\n\r\n return this._applyExtension(node, extensions, 0, actionAsync);\r\n }\r\n\r\n public _extensionsPreExportTextureAsync(context: string, babylonTexture: Nullable, mimeType: ImageMimeType): Promise> {\r\n return this._applyExtensions(babylonTexture, (extension, node) => extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType));\r\n }\r\n\r\n public _extensionsPostExportMeshPrimitiveAsync(\r\n context: string,\r\n meshPrimitive: IMeshPrimitive,\r\n babylonSubMesh: SubMesh,\r\n binaryWriter: _BinaryWriter\r\n ): Promise> {\r\n return this._applyExtensions(\r\n meshPrimitive,\r\n (extension, node) => extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter)\r\n );\r\n }\r\n\r\n public _extensionsPostExportNodeAsync(\r\n context: string,\r\n node: Nullable,\r\n babylonNode: Node,\r\n nodeMap: { [key: number]: number },\r\n binaryWriter: _BinaryWriter\r\n ): Promise> {\r\n return this._applyExtensions(node, (extension, node) => extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter));\r\n }\r\n\r\n public _extensionsPostExportMaterialAsync(context: string, material: Nullable, babylonMaterial: Material): Promise> {\r\n return this._applyExtensions(material, (extension, node) => extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial));\r\n }\r\n\r\n public _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const output: BaseTexture[] = [];\r\n\r\n for (const name of _Exporter._ExtensionNames) {\r\n const extension = this._extensions[name];\r\n\r\n if (extension.postExportMaterialAdditionalTextures) {\r\n output.push(...extension.postExportMaterialAdditionalTextures(context, material, babylonMaterial));\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n public _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void {\r\n for (const name of _Exporter._ExtensionNames) {\r\n const extension = this._extensions[name];\r\n\r\n if (extension.postExportTexture) {\r\n extension.postExportTexture(context, textureInfo, babylonTexture);\r\n }\r\n }\r\n }\r\n\r\n private _forEachExtensions(action: (extension: IGLTFExporterExtensionV2) => void): void {\r\n for (const name of _Exporter._ExtensionNames) {\r\n const extension = this._extensions[name];\r\n if (extension.enabled) {\r\n action(extension);\r\n }\r\n }\r\n }\r\n\r\n private _extensionsOnExporting(): void {\r\n this._forEachExtensions((extension) => {\r\n if (extension.wasUsed) {\r\n if (this._glTF.extensionsUsed == null) {\r\n this._glTF.extensionsUsed = [];\r\n }\r\n\r\n if (this._glTF.extensionsUsed.indexOf(extension.name) === -1) {\r\n this._glTF.extensionsUsed.push(extension.name);\r\n }\r\n\r\n if (extension.required) {\r\n if (this._glTF.extensionsRequired == null) {\r\n this._glTF.extensionsRequired = [];\r\n }\r\n if (this._glTF.extensionsRequired.indexOf(extension.name) === -1) {\r\n this._glTF.extensionsRequired.push(extension.name);\r\n }\r\n }\r\n\r\n if (this._glTF.extensions == null) {\r\n this._glTF.extensions = {};\r\n }\r\n\r\n if (extension.onExporting) {\r\n extension.onExporting();\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Load glTF serializer extensions\r\n */\r\n private _loadExtensions(): void {\r\n for (const name of _Exporter._ExtensionNames) {\r\n const extension = _Exporter._ExtensionFactories[name](this);\r\n this._extensions[name] = extension;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a glTF Exporter instance, which can accept optional exporter options\r\n * @param babylonScene Babylon scene object\r\n * @param options Options to modify the behavior of the exporter\r\n */\r\n public constructor(babylonScene?: Nullable, options?: IExportOptions) {\r\n this._glTF = {\r\n asset: { generator: `Babylon.js v${Engine.Version}`, version: \"2.0\" },\r\n };\r\n babylonScene = babylonScene || EngineStore.LastCreatedScene;\r\n if (!babylonScene) {\r\n return;\r\n }\r\n this._babylonScene = babylonScene;\r\n this._bufferViews = [];\r\n this._accessors = [];\r\n this._meshes = [];\r\n this._scenes = [];\r\n this._cameras = [];\r\n this._nodes = [];\r\n this._images = [];\r\n this._materials = [];\r\n this._materialMap = [];\r\n this._textures = [];\r\n this._samplers = [];\r\n this._skins = [];\r\n this._animations = [];\r\n this._imageData = {};\r\n this._orderedImageData = [];\r\n this._options = options || {};\r\n this._animationSampleRate = this._options.animationSampleRate || 1 / 60;\r\n\r\n this._glTFMaterialExporter = new _GLTFMaterialExporter(this);\r\n this._loadExtensions();\r\n }\r\n\r\n public dispose() {\r\n for (const extensionKey in this._extensions) {\r\n const extension = this._extensions[extensionKey];\r\n\r\n extension.dispose();\r\n }\r\n }\r\n\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * Registers a glTF exporter extension\r\n * @param name Name of the extension to export\r\n * @param factory The factory function that creates the exporter extension\r\n */\r\n public static RegisterExtension(name: string, factory: (exporter: _Exporter) => IGLTFExporterExtensionV2): void {\r\n if (_Exporter.UnregisterExtension(name)) {\r\n Tools.Warn(`Extension with the name ${name} already exists`);\r\n }\r\n\r\n _Exporter._ExtensionFactories[name] = factory;\r\n _Exporter._ExtensionNames.push(name);\r\n }\r\n\r\n /**\r\n * Un-registers an exporter extension\r\n * @param name The name fo the exporter extension\r\n * @returns A boolean indicating whether the extension has been un-registered\r\n */\r\n public static UnregisterExtension(name: string): boolean {\r\n if (!_Exporter._ExtensionFactories[name]) {\r\n return false;\r\n }\r\n delete _Exporter._ExtensionFactories[name];\r\n\r\n const index = _Exporter._ExtensionNames.indexOf(name);\r\n if (index !== -1) {\r\n _Exporter._ExtensionNames.splice(index, 1);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _reorderIndicesBasedOnPrimitiveMode(submesh: SubMesh, primitiveMode: number, babylonIndices: IndicesArray, byteOffset: number, binaryWriter: _BinaryWriter) {\r\n switch (primitiveMode) {\r\n case Material.TriangleFillMode: {\r\n if (!byteOffset) {\r\n byteOffset = 0;\r\n }\r\n for (let i = submesh.indexStart, length = submesh.indexStart + submesh.indexCount; i < length; i = i + 3) {\r\n const index = byteOffset + i * 4;\r\n // swap the second and third indices\r\n const secondIndex = binaryWriter.getUInt32(index + 4);\r\n const thirdIndex = binaryWriter.getUInt32(index + 8);\r\n binaryWriter.setUInt32(thirdIndex, index + 4);\r\n binaryWriter.setUInt32(secondIndex, index + 8);\r\n }\r\n break;\r\n }\r\n case Material.TriangleFanDrawMode: {\r\n for (let i = submesh.indexStart + submesh.indexCount - 1, start = submesh.indexStart; i >= start; --i) {\r\n binaryWriter.setUInt32(babylonIndices[i], byteOffset);\r\n byteOffset += 4;\r\n }\r\n break;\r\n }\r\n case Material.TriangleStripDrawMode: {\r\n if (submesh.indexCount >= 3) {\r\n binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 2], byteOffset + 4);\r\n binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 1], byteOffset + 8);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is\r\n * clock-wise during export to glTF\r\n * @param submesh BabylonJS submesh\r\n * @param primitiveMode Primitive mode of the mesh\r\n * @param vertexBufferKind The type of vertex attribute\r\n * @param meshAttributeArray The vertex attribute data\r\n * @param byteOffset The offset to the binary data\r\n * @param binaryWriter The binary data for the glTF file\r\n */\r\n private _reorderVertexAttributeDataBasedOnPrimitiveMode(\r\n submesh: SubMesh,\r\n primitiveMode: number,\r\n vertexBufferKind: string,\r\n meshAttributeArray: FloatArray,\r\n byteOffset: number,\r\n binaryWriter: _BinaryWriter\r\n ): void {\r\n switch (primitiveMode) {\r\n case Material.TriangleFillMode: {\r\n this._reorderTriangleFillMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);\r\n break;\r\n }\r\n case Material.TriangleStripDrawMode: {\r\n this._reorderTriangleStripDrawMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);\r\n break;\r\n }\r\n case Material.TriangleFanDrawMode: {\r\n this._reorderTriangleFanMode(submesh, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is\r\n * clock-wise during export to glTF\r\n * @param submesh BabylonJS submesh\r\n * @param vertexBufferKind The type of vertex attribute\r\n * @param meshAttributeArray The vertex attribute data\r\n * @param byteOffset The offset to the binary data\r\n * @param binaryWriter The binary data for the glTF file\r\n */\r\n private _reorderTriangleFillMode(submesh: SubMesh, vertexBufferKind: string, meshAttributeArray: FloatArray, byteOffset: number, binaryWriter: _BinaryWriter) {\r\n const vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh() as Mesh);\r\n if (vertexBuffer) {\r\n const stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);\r\n if (submesh.verticesCount % 3 !== 0) {\r\n Tools.Error(\"The submesh vertices for the triangle fill mode is not divisible by 3!\");\r\n } else {\r\n const vertexData: Vector2[] | Vector3[] | Vector4[] = [];\r\n let index = 0;\r\n switch (vertexBufferKind) {\r\n case VertexBuffer.PositionKind:\r\n case VertexBuffer.NormalKind: {\r\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {\r\n index = x * stride;\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index));\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + stride));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.TangentKind: {\r\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {\r\n index = x * stride;\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index));\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + stride));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.ColorKind: {\r\n const size = vertexBuffer.getSize();\r\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {\r\n index = x * stride;\r\n if (size === 4) {\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index));\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + stride));\r\n } else {\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index));\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + stride));\r\n }\r\n }\r\n break;\r\n }\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind: {\r\n for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {\r\n index = x * stride;\r\n (vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index));\r\n (vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index + 2 * stride));\r\n (vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index + stride));\r\n }\r\n break;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported Vertex Buffer type: ${vertexBufferKind}`);\r\n }\r\n }\r\n this._writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, binaryWriter);\r\n }\r\n } else {\r\n Tools.Warn(`reorderTriangleFillMode: Vertex Buffer Kind ${vertexBufferKind} not present!`);\r\n }\r\n }\r\n\r\n /**\r\n * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is\r\n * clock-wise during export to glTF\r\n * @param submesh BabylonJS submesh\r\n * @param vertexBufferKind The type of vertex attribute\r\n * @param meshAttributeArray The vertex attribute data\r\n * @param byteOffset The offset to the binary data\r\n * @param binaryWriter The binary data for the glTF file\r\n */\r\n private _reorderTriangleStripDrawMode(submesh: SubMesh, vertexBufferKind: string, meshAttributeArray: FloatArray, byteOffset: number, binaryWriter: _BinaryWriter) {\r\n const vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh() as Mesh);\r\n if (vertexBuffer) {\r\n const stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);\r\n\r\n const vertexData: Vector2[] | Vector3[] | Vector4[] = [];\r\n let index = 0;\r\n switch (vertexBufferKind) {\r\n case VertexBuffer.PositionKind:\r\n case VertexBuffer.NormalKind: {\r\n index = submesh.verticesStart;\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + stride));\r\n break;\r\n }\r\n case VertexBuffer.TangentKind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.ColorKind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n vertexBuffer.getSize() === 4\r\n ? (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index))\r\n : (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n (vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported Vertex Buffer type: ${vertexBufferKind}`);\r\n }\r\n }\r\n this._writeVertexAttributeData(vertexData, byteOffset + 12, vertexBufferKind, binaryWriter);\r\n } else {\r\n Tools.Warn(`reorderTriangleStripDrawMode: Vertex buffer kind ${vertexBufferKind} not present!`);\r\n }\r\n }\r\n\r\n /**\r\n * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is\r\n * clock-wise during export to glTF\r\n * @param submesh BabylonJS submesh\r\n * @param vertexBufferKind The type of vertex attribute\r\n * @param meshAttributeArray The vertex attribute data\r\n * @param byteOffset The offset to the binary data\r\n * @param binaryWriter The binary data for the glTF file\r\n */\r\n private _reorderTriangleFanMode(submesh: SubMesh, vertexBufferKind: string, meshAttributeArray: FloatArray, byteOffset: number, binaryWriter: _BinaryWriter) {\r\n const vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh() as Mesh);\r\n if (vertexBuffer) {\r\n const stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);\r\n\r\n const vertexData: Vector2[] | Vector3[] | Vector4[] = [];\r\n let index = 0;\r\n switch (vertexBufferKind) {\r\n case VertexBuffer.PositionKind:\r\n case VertexBuffer.NormalKind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.TangentKind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.ColorKind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index));\r\n vertexBuffer.getSize() === 4\r\n ? (vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index))\r\n : (vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind: {\r\n for (let x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {\r\n index = x * stride;\r\n (vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index));\r\n }\r\n break;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported Vertex Buffer type: ${vertexBufferKind}`);\r\n }\r\n }\r\n this._writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, binaryWriter);\r\n } else {\r\n Tools.Warn(`reorderTriangleFanMode: Vertex buffer kind ${vertexBufferKind} not present!`);\r\n }\r\n }\r\n\r\n /**\r\n * Writes the vertex attribute data to binary\r\n * @param vertices The vertices to write to the binary writer\r\n * @param byteOffset The offset into the binary writer to overwrite binary data\r\n * @param vertexAttributeKind The vertex attribute type\r\n * @param binaryWriter The writer containing the binary data\r\n */\r\n private _writeVertexAttributeData(vertices: Vector2[] | Vector3[] | Vector4[], byteOffset: number, vertexAttributeKind: string, binaryWriter: _BinaryWriter) {\r\n for (const vertex of vertices) {\r\n if (vertexAttributeKind === VertexBuffer.NormalKind) {\r\n vertex.normalize();\r\n } else if (vertexAttributeKind === VertexBuffer.TangentKind && vertex instanceof Vector4) {\r\n _GLTFUtilities._NormalizeTangentFromRef(vertex);\r\n }\r\n\r\n for (const component of vertex.asArray()) {\r\n binaryWriter.setFloat32(component, byteOffset);\r\n byteOffset += 4;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Writes mesh attribute data to a data buffer\r\n * Returns the bytelength of the data\r\n * @param vertexBufferKind Indicates what kind of vertex data is being passed in\r\n * @param attributeComponentKind\r\n * @param meshAttributeArray Array containing the attribute data\r\n * @param stride Specifies the space between data\r\n * @param binaryWriter The buffer to write the binary data to\r\n * @param babylonTransformNode\r\n */\r\n public _writeAttributeData(\r\n vertexBufferKind: string,\r\n attributeComponentKind: AccessorComponentType,\r\n meshAttributeArray: FloatArray,\r\n stride: number,\r\n binaryWriter: _BinaryWriter,\r\n babylonTransformNode: TransformNode\r\n ) {\r\n let vertexAttributes: number[][] = [];\r\n let index: number;\r\n\r\n switch (vertexBufferKind) {\r\n case VertexBuffer.PositionKind: {\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n const vertexData = Vector3.FromArray(meshAttributeArray, index);\r\n vertexAttributes.push(vertexData.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.NormalKind: {\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n const vertexData = Vector3.FromArray(meshAttributeArray, index);\r\n vertexAttributes.push(vertexData.normalize().asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.TangentKind: {\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\r\n _GLTFUtilities._NormalizeTangentFromRef(vertexData);\r\n vertexAttributes.push(vertexData.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.ColorKind: {\r\n const meshMaterial = (babylonTransformNode as Mesh).material;\r\n const convertToLinear = meshMaterial ? meshMaterial.getClassName() === \"StandardMaterial\" : true;\r\n const vertexData: Color3 | Color4 = stride === 3 ? new Color3() : new Color4();\r\n const useExactSrgbConversions = this._babylonScene.getEngine().useExactSrgbConversions;\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n if (stride === 3) {\r\n Color3.FromArrayToRef(meshAttributeArray, index, vertexData as Color3);\r\n if (convertToLinear) {\r\n (vertexData as Color3).toLinearSpaceToRef(vertexData as Color3, useExactSrgbConversions);\r\n }\r\n } else {\r\n Color4.FromArrayToRef(meshAttributeArray, index, vertexData as Color4);\r\n if (convertToLinear) {\r\n (vertexData as Color4).toLinearSpaceToRef(vertexData as Color4, useExactSrgbConversions);\r\n }\r\n }\r\n vertexAttributes.push(vertexData.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind: {\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n const vertexData = Vector2.FromArray(meshAttributeArray, index);\r\n vertexAttributes.push(vertexData.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.MatricesIndicesKind:\r\n case VertexBuffer.MatricesIndicesExtraKind: {\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\r\n vertexAttributes.push(vertexData.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.MatricesWeightsKind:\r\n case VertexBuffer.MatricesWeightsExtraKind: {\r\n for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {\r\n index = k * stride;\r\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\r\n vertexAttributes.push(vertexData.asArray());\r\n }\r\n break;\r\n }\r\n default: {\r\n Tools.Warn(\"Unsupported Vertex Buffer Type: \" + vertexBufferKind);\r\n vertexAttributes = [];\r\n }\r\n }\r\n\r\n let writeBinaryFunc;\r\n switch (attributeComponentKind) {\r\n case AccessorComponentType.UNSIGNED_BYTE: {\r\n writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);\r\n break;\r\n }\r\n case AccessorComponentType.UNSIGNED_SHORT: {\r\n writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);\r\n break;\r\n }\r\n case AccessorComponentType.UNSIGNED_INT: {\r\n writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);\r\n break;\r\n }\r\n case AccessorComponentType.FLOAT: {\r\n writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);\r\n break;\r\n }\r\n default: {\r\n Tools.Warn(\"Unsupported Attribute Component kind: \" + attributeComponentKind);\r\n return;\r\n }\r\n }\r\n\r\n for (const vertexAttribute of vertexAttributes) {\r\n for (const component of vertexAttribute) {\r\n writeBinaryFunc(component);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Writes mesh attribute data to a data buffer\r\n * Returns the bytelength of the data\r\n * @param vertexBufferKind Indicates what kind of vertex data is being passed in\r\n * @param attributeComponentKind\r\n * @param meshPrimitive\r\n * @param morphTarget\r\n * @param meshAttributeArray Array containing the attribute data\r\n * @param morphTargetAttributeArray\r\n * @param stride Specifies the space between data\r\n * @param binaryWriter The buffer to write the binary data to\r\n * @param minMax\r\n */\r\n public writeMorphTargetAttributeData(\r\n vertexBufferKind: string,\r\n attributeComponentKind: AccessorComponentType,\r\n meshPrimitive: SubMesh,\r\n meshAttributeArray: FloatArray,\r\n morphTargetAttributeArray: FloatArray,\r\n stride: number,\r\n binaryWriter: _BinaryWriter,\r\n minMax?: any\r\n ) {\r\n let vertexAttributes: number[][] = [];\r\n let index: number;\r\n let difference: Vector3 = new Vector3();\r\n let difference4: Vector4 = new Vector4(0, 0, 0, 0);\r\n\r\n switch (vertexBufferKind) {\r\n case VertexBuffer.PositionKind: {\r\n for (let k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {\r\n index = meshPrimitive.indexStart + k * stride;\r\n const vertexData = Vector3.FromArray(meshAttributeArray, index);\r\n const morphData = Vector3.FromArray(morphTargetAttributeArray, index);\r\n difference = morphData.subtractToRef(vertexData, difference);\r\n if (minMax) {\r\n minMax.min.copyFromFloats(Math.min(difference.x, minMax.min.x), Math.min(difference.y, minMax.min.y), Math.min(difference.z, minMax.min.z));\r\n minMax.max.copyFromFloats(Math.max(difference.x, minMax.max.x), Math.max(difference.y, minMax.max.y), Math.max(difference.z, minMax.max.z));\r\n }\r\n vertexAttributes.push(difference.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.NormalKind: {\r\n for (let k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {\r\n index = meshPrimitive.indexStart + k * stride;\r\n const vertexData = Vector3.FromArray(meshAttributeArray, index).normalize();\r\n const morphData = Vector3.FromArray(morphTargetAttributeArray, index).normalize();\r\n difference = morphData.subtractToRef(vertexData, difference);\r\n vertexAttributes.push(difference.asArray());\r\n }\r\n break;\r\n }\r\n case VertexBuffer.TangentKind: {\r\n for (let k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {\r\n index = meshPrimitive.indexStart + k * (stride + 1);\r\n const vertexData = Vector4.FromArray(meshAttributeArray, index);\r\n _GLTFUtilities._NormalizeTangentFromRef(vertexData);\r\n const morphData = Vector4.FromArray(morphTargetAttributeArray, index);\r\n _GLTFUtilities._NormalizeTangentFromRef(morphData);\r\n difference4 = morphData.subtractToRef(vertexData, difference4);\r\n vertexAttributes.push([difference4.x, difference4.y, difference4.z]);\r\n }\r\n break;\r\n }\r\n default: {\r\n Tools.Warn(\"Unsupported Vertex Buffer Type: \" + vertexBufferKind);\r\n vertexAttributes = [];\r\n }\r\n }\r\n\r\n let writeBinaryFunc;\r\n switch (attributeComponentKind) {\r\n case AccessorComponentType.UNSIGNED_BYTE: {\r\n writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);\r\n break;\r\n }\r\n case AccessorComponentType.UNSIGNED_SHORT: {\r\n writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);\r\n break;\r\n }\r\n case AccessorComponentType.UNSIGNED_INT: {\r\n writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);\r\n break;\r\n }\r\n case AccessorComponentType.FLOAT: {\r\n writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);\r\n break;\r\n }\r\n default: {\r\n Tools.Warn(\"Unsupported Attribute Component kind: \" + attributeComponentKind);\r\n return;\r\n }\r\n }\r\n\r\n for (const vertexAttribute of vertexAttributes) {\r\n for (const component of vertexAttribute) {\r\n writeBinaryFunc(component);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Generates glTF json data\r\n * @param shouldUseGlb Indicates whether the json should be written for a glb file\r\n * @param glTFPrefix Text to use when prefixing a glTF file\r\n * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)\r\n * @returns json data as string\r\n */\r\n private _generateJSON(shouldUseGlb: boolean, glTFPrefix?: string, prettyPrint?: boolean): string {\r\n const buffer: IBuffer = { byteLength: this._totalByteLength };\r\n let imageName: string;\r\n let imageData: { data: ArrayBuffer; mimeType: ImageMimeType };\r\n let bufferView: IBufferView;\r\n let byteOffset: number = this._totalByteLength;\r\n\r\n if (buffer.byteLength) {\r\n this._glTF.buffers = [buffer];\r\n }\r\n if (this._nodes && this._nodes.length) {\r\n this._glTF.nodes = this._nodes;\r\n }\r\n if (this._meshes && this._meshes.length) {\r\n this._glTF.meshes = this._meshes;\r\n }\r\n if (this._scenes && this._scenes.length) {\r\n this._glTF.scenes = this._scenes;\r\n this._glTF.scene = 0;\r\n }\r\n if (this._cameras && this._cameras.length) {\r\n this._glTF.cameras = this._cameras;\r\n }\r\n if (this._bufferViews && this._bufferViews.length) {\r\n this._glTF.bufferViews = this._bufferViews;\r\n }\r\n if (this._accessors && this._accessors.length) {\r\n this._glTF.accessors = this._accessors;\r\n }\r\n if (this._animations && this._animations.length) {\r\n this._glTF.animations = this._animations;\r\n }\r\n if (this._materials && this._materials.length) {\r\n this._glTF.materials = this._materials;\r\n }\r\n if (this._textures && this._textures.length) {\r\n this._glTF.textures = this._textures;\r\n }\r\n if (this._samplers && this._samplers.length) {\r\n this._glTF.samplers = this._samplers;\r\n }\r\n if (this._skins && this._skins.length) {\r\n this._glTF.skins = this._skins;\r\n }\r\n if (this._images && this._images.length) {\r\n if (!shouldUseGlb) {\r\n this._glTF.images = this._images;\r\n } else {\r\n this._glTF.images = [];\r\n\r\n this._images.forEach((image) => {\r\n if (image.uri) {\r\n imageData = this._imageData[image.uri];\r\n this._orderedImageData.push(imageData);\r\n imageName = image.uri.split(\".\")[0] + \" image\";\r\n bufferView = _GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.byteLength, undefined, imageName);\r\n byteOffset += imageData.data.byteLength;\r\n this._bufferViews.push(bufferView);\r\n image.bufferView = this._bufferViews.length - 1;\r\n image.name = imageName;\r\n image.mimeType = imageData.mimeType;\r\n image.uri = undefined;\r\n if (!this._glTF.images) {\r\n this._glTF.images = [];\r\n }\r\n this._glTF.images.push(image);\r\n }\r\n });\r\n // Replace uri with bufferview and mime type for glb\r\n buffer.byteLength = byteOffset;\r\n }\r\n }\r\n\r\n if (!shouldUseGlb) {\r\n buffer.uri = glTFPrefix + \".bin\";\r\n }\r\n\r\n const jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);\r\n\r\n return jsonText;\r\n }\r\n\r\n /**\r\n * Generates data for .gltf and .bin files based on the glTF prefix string\r\n * @param glTFPrefix Text to use when prefixing a glTF file\r\n * @param dispose Dispose the exporter\r\n * @returns GLTFData with glTF file data\r\n */\r\n public _generateGLTFAsync(glTFPrefix: string, dispose = true): Promise {\r\n return this._generateBinaryAsync().then((binaryBuffer) => {\r\n this._extensionsOnExporting();\r\n const jsonText = this._generateJSON(false, glTFPrefix, true);\r\n const bin = new Blob([binaryBuffer], { type: \"application/octet-stream\" });\r\n\r\n const glTFFileName = glTFPrefix + \".gltf\";\r\n const glTFBinFile = glTFPrefix + \".bin\";\r\n\r\n const container = new GLTFData();\r\n\r\n container.glTFFiles[glTFFileName] = jsonText;\r\n container.glTFFiles[glTFBinFile] = bin;\r\n\r\n if (this._imageData) {\r\n for (const image in this._imageData) {\r\n container.glTFFiles[image] = new Blob([this._imageData[image].data], { type: this._imageData[image].mimeType });\r\n }\r\n }\r\n\r\n if (dispose) {\r\n this.dispose();\r\n }\r\n\r\n return container;\r\n });\r\n }\r\n\r\n /**\r\n * Creates a binary buffer for glTF\r\n * @returns array buffer for binary data\r\n */\r\n private _generateBinaryAsync(): Promise {\r\n const binaryWriter = new _BinaryWriter(4);\r\n return this._createSceneAsync(binaryWriter).then(() => {\r\n if (this._localEngine) {\r\n this._localEngine.dispose();\r\n }\r\n return binaryWriter.getArrayBuffer();\r\n });\r\n }\r\n\r\n /**\r\n * Pads the number to a multiple of 4\r\n * @param num number to pad\r\n * @returns padded number\r\n */\r\n private _getPadding(num: number): number {\r\n const remainder = num % 4;\r\n const padding = remainder === 0 ? remainder : 4 - remainder;\r\n\r\n return padding;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _generateGLBAsync(glTFPrefix: string, dispose = true): Promise {\r\n return this._generateBinaryAsync().then((binaryBuffer) => {\r\n this._extensionsOnExporting();\r\n const jsonText = this._generateJSON(true);\r\n const glbFileName = glTFPrefix + \".glb\";\r\n const headerLength = 12;\r\n const chunkLengthPrefix = 8;\r\n let jsonLength = jsonText.length;\r\n let encodedJsonText;\r\n let imageByteLength = 0;\r\n // make use of TextEncoder when available\r\n if (typeof TextEncoder !== \"undefined\") {\r\n const encoder = new TextEncoder();\r\n encodedJsonText = encoder.encode(jsonText);\r\n jsonLength = encodedJsonText.length;\r\n }\r\n for (let i = 0; i < this._orderedImageData.length; ++i) {\r\n imageByteLength += this._orderedImageData[i].data.byteLength;\r\n }\r\n const jsonPadding = this._getPadding(jsonLength);\r\n const binPadding = this._getPadding(binaryBuffer.byteLength);\r\n const imagePadding = this._getPadding(imageByteLength);\r\n\r\n const byteLength = headerLength + 2 * chunkLengthPrefix + jsonLength + jsonPadding + binaryBuffer.byteLength + binPadding + imageByteLength + imagePadding;\r\n\r\n //header\r\n const headerBuffer = new ArrayBuffer(headerLength);\r\n const headerBufferView = new DataView(headerBuffer);\r\n headerBufferView.setUint32(0, 0x46546c67, true); //glTF\r\n headerBufferView.setUint32(4, 2, true); // version\r\n headerBufferView.setUint32(8, byteLength, true); // total bytes in file\r\n\r\n //json chunk\r\n const jsonChunkBuffer = new ArrayBuffer(chunkLengthPrefix + jsonLength + jsonPadding);\r\n const jsonChunkBufferView = new DataView(jsonChunkBuffer);\r\n jsonChunkBufferView.setUint32(0, jsonLength + jsonPadding, true);\r\n jsonChunkBufferView.setUint32(4, 0x4e4f534a, true);\r\n\r\n //json chunk bytes\r\n const jsonData = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix);\r\n // if TextEncoder was available, we can simply copy the encoded array\r\n if (encodedJsonText) {\r\n jsonData.set(encodedJsonText);\r\n } else {\r\n const blankCharCode = \"_\".charCodeAt(0);\r\n for (let i = 0; i < jsonLength; ++i) {\r\n const charCode = jsonText.charCodeAt(i);\r\n // if the character doesn't fit into a single UTF-16 code unit, just put a blank character\r\n if (charCode != jsonText.codePointAt(i)) {\r\n jsonData[i] = blankCharCode;\r\n } else {\r\n jsonData[i] = charCode;\r\n }\r\n }\r\n }\r\n\r\n //json padding\r\n const jsonPaddingView = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix + jsonLength);\r\n for (let i = 0; i < jsonPadding; ++i) {\r\n jsonPaddingView[i] = 0x20;\r\n }\r\n\r\n //binary chunk\r\n const binaryChunkBuffer = new ArrayBuffer(chunkLengthPrefix);\r\n const binaryChunkBufferView = new DataView(binaryChunkBuffer);\r\n binaryChunkBufferView.setUint32(0, binaryBuffer.byteLength + imageByteLength + imagePadding, true);\r\n binaryChunkBufferView.setUint32(4, 0x004e4942, true);\r\n\r\n // binary padding\r\n const binPaddingBuffer = new ArrayBuffer(binPadding);\r\n const binPaddingView = new Uint8Array(binPaddingBuffer);\r\n for (let i = 0; i < binPadding; ++i) {\r\n binPaddingView[i] = 0;\r\n }\r\n\r\n const imagePaddingBuffer = new ArrayBuffer(imagePadding);\r\n const imagePaddingView = new Uint8Array(imagePaddingBuffer);\r\n for (let i = 0; i < imagePadding; ++i) {\r\n imagePaddingView[i] = 0;\r\n }\r\n\r\n const glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];\r\n\r\n // binary data\r\n for (let i = 0; i < this._orderedImageData.length; ++i) {\r\n glbData.push(this._orderedImageData[i].data);\r\n }\r\n\r\n glbData.push(binPaddingBuffer);\r\n\r\n glbData.push(imagePaddingBuffer);\r\n\r\n const glbFile = new Blob(glbData, { type: \"application/octet-stream\" });\r\n\r\n const container = new GLTFData();\r\n container.glTFFiles[glbFileName] = glbFile;\r\n\r\n if (this._localEngine != null) {\r\n this._localEngine.dispose();\r\n }\r\n\r\n if (dispose) {\r\n this.dispose();\r\n }\r\n\r\n return container;\r\n });\r\n }\r\n\r\n /**\r\n * Sets the TRS for each node\r\n * @param node glTF Node for storing the transformation data\r\n * @param babylonTransformNode Babylon mesh used as the source for the transformation data\r\n */\r\n private _setNodeTransformation(node: INode, babylonTransformNode: TransformNode): void {\r\n if (!babylonTransformNode.getPivotPoint().equalsToFloats(0, 0, 0)) {\r\n Tools.Warn(\"Pivot points are not supported in the glTF serializer\");\r\n }\r\n if (!babylonTransformNode.position.equalsToFloats(0, 0, 0)) {\r\n node.translation = babylonTransformNode.position.asArray();\r\n }\r\n\r\n if (!babylonTransformNode.scaling.equalsToFloats(1, 1, 1)) {\r\n node.scale = babylonTransformNode.scaling.asArray();\r\n }\r\n\r\n const rotationQuaternion = Quaternion.RotationYawPitchRoll(babylonTransformNode.rotation.y, babylonTransformNode.rotation.x, babylonTransformNode.rotation.z);\r\n if (babylonTransformNode.rotationQuaternion) {\r\n rotationQuaternion.multiplyInPlace(babylonTransformNode.rotationQuaternion);\r\n }\r\n if (!Quaternion.IsIdentity(rotationQuaternion)) {\r\n node.rotation = rotationQuaternion.normalize().asArray();\r\n }\r\n }\r\n\r\n private _setCameraTransformation(node: INode, babylonCamera: Camera): void {\r\n if (!babylonCamera.position.equalsToFloats(0, 0, 0)) {\r\n node.translation = babylonCamera.position.asArray();\r\n }\r\n\r\n const rotationQuaternion = (babylonCamera).rotationQuaternion; // we target the local transformation if one.\r\n\r\n if (rotationQuaternion && !Quaternion.IsIdentity(rotationQuaternion)) {\r\n node.rotation = rotationQuaternion.normalize().asArray();\r\n }\r\n }\r\n\r\n private _getVertexBufferFromMesh(attributeKind: string, bufferMesh: Mesh): Nullable {\r\n if (bufferMesh.isVerticesDataPresent(attributeKind, true)) {\r\n const vertexBuffer = bufferMesh.getVertexBuffer(attributeKind, true);\r\n if (vertexBuffer) {\r\n return vertexBuffer;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Creates a bufferview based on the vertices type for the Babylon mesh\r\n * @param kind Indicates the type of vertices data\r\n * @param attributeComponentKind Indicates the numerical type used to store the data\r\n * @param babylonTransformNode The Babylon mesh to get the vertices data from\r\n * @param binaryWriter The buffer to write the bufferview data to\r\n * @param byteStride\r\n */\r\n private _createBufferViewKind(\r\n kind: string,\r\n attributeComponentKind: AccessorComponentType,\r\n babylonTransformNode: TransformNode,\r\n binaryWriter: _BinaryWriter,\r\n byteStride: number\r\n ) {\r\n const bufferMesh =\r\n babylonTransformNode instanceof Mesh\r\n ? (babylonTransformNode as Mesh)\r\n : babylonTransformNode instanceof InstancedMesh\r\n ? (babylonTransformNode as InstancedMesh).sourceMesh\r\n : null;\r\n\r\n if (bufferMesh) {\r\n const vertexBuffer = bufferMesh.getVertexBuffer(kind, true);\r\n const vertexData = bufferMesh.getVerticesData(kind, undefined, undefined, true);\r\n\r\n if (vertexBuffer && vertexData) {\r\n const typeByteLength = VertexBuffer.GetTypeByteLength(attributeComponentKind);\r\n const byteLength = vertexData.length * typeByteLength;\r\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, kind + \" - \" + bufferMesh.name);\r\n this._bufferViews.push(bufferView);\r\n\r\n this._writeAttributeData(kind, attributeComponentKind, vertexData, byteStride / typeByteLength, binaryWriter, babylonTransformNode);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Creates a bufferview based on the vertices type for the Babylon mesh\r\n * @param babylonSubMesh The Babylon submesh that the morph target is applied to\r\n * @param meshPrimitive\r\n * @param babylonMorphTarget the morph target to be exported\r\n * @param binaryWriter The buffer to write the bufferview data to\r\n */\r\n private _setMorphTargetAttributes(babylonSubMesh: SubMesh, meshPrimitive: IMeshPrimitive, babylonMorphTarget: MorphTarget, binaryWriter: _BinaryWriter) {\r\n if (babylonMorphTarget) {\r\n if (!meshPrimitive.targets) {\r\n meshPrimitive.targets = [];\r\n }\r\n const target: { [attribute: string]: number } = {};\r\n const mesh = babylonSubMesh.getMesh() as Mesh;\r\n if (babylonMorphTarget.hasNormals) {\r\n const vertexNormals = mesh.getVerticesData(VertexBuffer.NormalKind, undefined, undefined, true)!;\r\n const morphNormals = babylonMorphTarget.getNormals()!;\r\n const count = babylonSubMesh.verticesCount;\r\n const byteStride = 12; // 3 x 4 byte floats\r\n const byteLength = count * byteStride;\r\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + \"_NORMAL\");\r\n this._bufferViews.push(bufferView);\r\n\r\n const bufferViewIndex = this._bufferViews.length - 1;\r\n const accessor = _GLTFUtilities._CreateAccessor(\r\n bufferViewIndex,\r\n babylonMorphTarget.name + \" - \" + \"NORMAL\",\r\n AccessorType.VEC3,\r\n AccessorComponentType.FLOAT,\r\n count,\r\n 0,\r\n null,\r\n null\r\n );\r\n this._accessors.push(accessor);\r\n target.NORMAL = this._accessors.length - 1;\r\n\r\n this.writeMorphTargetAttributeData(VertexBuffer.NormalKind, AccessorComponentType.FLOAT, babylonSubMesh, vertexNormals, morphNormals, byteStride / 4, binaryWriter);\r\n }\r\n if (babylonMorphTarget.hasPositions) {\r\n const vertexPositions = mesh.getVerticesData(VertexBuffer.PositionKind, undefined, undefined, true)!;\r\n const morphPositions = babylonMorphTarget.getPositions()!;\r\n const count = babylonSubMesh.verticesCount;\r\n const byteStride = 12; // 3 x 4 byte floats\r\n const byteLength = count * byteStride;\r\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + \"_POSITION\");\r\n this._bufferViews.push(bufferView);\r\n\r\n const bufferViewIndex = this._bufferViews.length - 1;\r\n const minMax = { min: new Vector3(Infinity, Infinity, Infinity), max: new Vector3(-Infinity, -Infinity, -Infinity) };\r\n const accessor = _GLTFUtilities._CreateAccessor(\r\n bufferViewIndex,\r\n babylonMorphTarget.name + \" - \" + \"POSITION\",\r\n AccessorType.VEC3,\r\n AccessorComponentType.FLOAT,\r\n count,\r\n 0,\r\n null,\r\n null\r\n );\r\n this._accessors.push(accessor);\r\n target.POSITION = this._accessors.length - 1;\r\n\r\n this.writeMorphTargetAttributeData(\r\n VertexBuffer.PositionKind,\r\n AccessorComponentType.FLOAT,\r\n babylonSubMesh,\r\n vertexPositions,\r\n morphPositions,\r\n byteStride / 4,\r\n binaryWriter,\r\n minMax\r\n );\r\n accessor.min = minMax.min!.asArray();\r\n accessor.max = minMax.max!.asArray();\r\n }\r\n if (babylonMorphTarget.hasTangents) {\r\n const vertexTangents = mesh.getVerticesData(VertexBuffer.TangentKind, undefined, undefined, true)!;\r\n const morphTangents = babylonMorphTarget.getTangents()!;\r\n const count = babylonSubMesh.verticesCount;\r\n const byteStride = 12; // 3 x 4 byte floats\r\n const byteLength = count * byteStride;\r\n const bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + \"_NORMAL\");\r\n this._bufferViews.push(bufferView);\r\n\r\n const bufferViewIndex = this._bufferViews.length - 1;\r\n const accessor = _GLTFUtilities._CreateAccessor(\r\n bufferViewIndex,\r\n babylonMorphTarget.name + \" - \" + \"TANGENT\",\r\n AccessorType.VEC3,\r\n AccessorComponentType.FLOAT,\r\n count,\r\n 0,\r\n null,\r\n null\r\n );\r\n this._accessors.push(accessor);\r\n target.TANGENT = this._accessors.length - 1;\r\n\r\n this.writeMorphTargetAttributeData(\r\n VertexBuffer.TangentKind,\r\n AccessorComponentType.FLOAT,\r\n babylonSubMesh,\r\n vertexTangents,\r\n morphTangents,\r\n byteStride / 4,\r\n binaryWriter\r\n );\r\n }\r\n meshPrimitive.targets.push(target);\r\n }\r\n }\r\n\r\n /**\r\n * The primitive mode of the Babylon mesh\r\n * @param babylonMesh The BabylonJS mesh\r\n */\r\n private _getMeshPrimitiveMode(babylonMesh: AbstractMesh): number {\r\n if (babylonMesh instanceof LinesMesh) {\r\n return Material.LineListDrawMode;\r\n }\r\n if (babylonMesh instanceof InstancedMesh || babylonMesh instanceof Mesh) {\r\n const baseMesh = babylonMesh instanceof Mesh ? babylonMesh : babylonMesh.sourceMesh;\r\n if (typeof baseMesh.overrideRenderingFillMode === \"number\") {\r\n return baseMesh.overrideRenderingFillMode;\r\n }\r\n }\r\n return babylonMesh.material ? babylonMesh.material.fillMode : Material.TriangleFillMode;\r\n }\r\n\r\n /**\r\n * Sets the primitive mode of the glTF mesh primitive\r\n * @param meshPrimitive glTF mesh primitive\r\n * @param primitiveMode The primitive mode\r\n */\r\n private _setPrimitiveMode(meshPrimitive: IMeshPrimitive, primitiveMode: number) {\r\n switch (primitiveMode) {\r\n case Material.TriangleFillMode: {\r\n // glTF defaults to using Triangle Mode\r\n break;\r\n }\r\n case Material.TriangleStripDrawMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.TRIANGLE_STRIP;\r\n break;\r\n }\r\n case Material.TriangleFanDrawMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.TRIANGLE_FAN;\r\n break;\r\n }\r\n case Material.PointListDrawMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.POINTS;\r\n break;\r\n }\r\n case Material.PointFillMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.POINTS;\r\n break;\r\n }\r\n case Material.LineLoopDrawMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.LINE_LOOP;\r\n break;\r\n }\r\n case Material.LineListDrawMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.LINES;\r\n break;\r\n }\r\n case Material.LineStripDrawMode: {\r\n meshPrimitive.mode = MeshPrimitiveMode.LINE_STRIP;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the vertex attribute accessor based of the glTF mesh primitive\r\n * @param meshPrimitive glTF mesh primitive\r\n * @param attributeKind vertex attribute\r\n * @returns boolean specifying if uv coordinates are present\r\n */\r\n private _setAttributeKind(meshPrimitive: IMeshPrimitive, attributeKind: string): void {\r\n switch (attributeKind) {\r\n case VertexBuffer.PositionKind: {\r\n meshPrimitive.attributes.POSITION = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.NormalKind: {\r\n meshPrimitive.attributes.NORMAL = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.ColorKind: {\r\n meshPrimitive.attributes.COLOR_0 = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.TangentKind: {\r\n meshPrimitive.attributes.TANGENT = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.UVKind: {\r\n meshPrimitive.attributes.TEXCOORD_0 = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.UV2Kind: {\r\n meshPrimitive.attributes.TEXCOORD_1 = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.MatricesIndicesKind: {\r\n meshPrimitive.attributes.JOINTS_0 = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.MatricesIndicesExtraKind: {\r\n meshPrimitive.attributes.JOINTS_1 = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.MatricesWeightsKind: {\r\n meshPrimitive.attributes.WEIGHTS_0 = this._accessors.length - 1;\r\n break;\r\n }\r\n case VertexBuffer.MatricesWeightsExtraKind: {\r\n meshPrimitive.attributes.WEIGHTS_1 = this._accessors.length - 1;\r\n break;\r\n }\r\n default: {\r\n Tools.Warn(\"Unsupported Vertex Buffer Type: \" + attributeKind);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets data for the primitive attributes of each submesh\r\n * @param mesh glTF Mesh object to store the primitive attribute information\r\n * @param babylonTransformNode Babylon mesh to get the primitive attribute data from\r\n * @param binaryWriter Buffer to write the attribute data to\r\n */\r\n private _setPrimitiveAttributesAsync(mesh: IMesh, babylonTransformNode: TransformNode, binaryWriter: _BinaryWriter): Promise {\r\n const promises: Promise[] = [];\r\n let bufferMesh: Nullable = null;\r\n let bufferView: IBufferView;\r\n let minMax: { min: Nullable; max: Nullable };\r\n\r\n if (babylonTransformNode instanceof Mesh) {\r\n bufferMesh = babylonTransformNode as Mesh;\r\n } else if (babylonTransformNode instanceof InstancedMesh) {\r\n bufferMesh = (babylonTransformNode as InstancedMesh).sourceMesh;\r\n }\r\n const attributeData: _IVertexAttributeData[] = [\r\n { kind: VertexBuffer.PositionKind, accessorType: AccessorType.VEC3, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 12 },\r\n { kind: VertexBuffer.NormalKind, accessorType: AccessorType.VEC3, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 12 },\r\n { kind: VertexBuffer.ColorKind, accessorType: AccessorType.VEC4, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 16 },\r\n { kind: VertexBuffer.TangentKind, accessorType: AccessorType.VEC4, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 16 },\r\n { kind: VertexBuffer.UVKind, accessorType: AccessorType.VEC2, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 8 },\r\n { kind: VertexBuffer.UV2Kind, accessorType: AccessorType.VEC2, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 8 },\r\n { kind: VertexBuffer.MatricesIndicesKind, accessorType: AccessorType.VEC4, accessorComponentType: AccessorComponentType.UNSIGNED_SHORT, byteStride: 8 },\r\n { kind: VertexBuffer.MatricesIndicesExtraKind, accessorType: AccessorType.VEC4, accessorComponentType: AccessorComponentType.UNSIGNED_SHORT, byteStride: 8 },\r\n { kind: VertexBuffer.MatricesWeightsKind, accessorType: AccessorType.VEC4, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 16 },\r\n { kind: VertexBuffer.MatricesWeightsExtraKind, accessorType: AccessorType.VEC4, accessorComponentType: AccessorComponentType.FLOAT, byteStride: 16 },\r\n ];\r\n\r\n if (bufferMesh) {\r\n let indexBufferViewIndex: Nullable = null;\r\n const primitiveMode = this._getMeshPrimitiveMode(bufferMesh);\r\n const vertexAttributeBufferViews: { [attributeKind: string]: number } = {};\r\n const morphTargetManager = bufferMesh.morphTargetManager;\r\n\r\n // For each BabylonMesh, create bufferviews for each 'kind'\r\n for (const attribute of attributeData) {\r\n const attributeKind = attribute.kind;\r\n const attributeComponentKind = attribute.accessorComponentType;\r\n if (bufferMesh.isVerticesDataPresent(attributeKind, true)) {\r\n const vertexBuffer = this._getVertexBufferFromMesh(attributeKind, bufferMesh);\r\n attribute.byteStride = vertexBuffer\r\n ? vertexBuffer.getSize() * VertexBuffer.GetTypeByteLength(attribute.accessorComponentType)\r\n : VertexBuffer.DeduceStride(attributeKind) * 4;\r\n if (attribute.byteStride === 12) {\r\n attribute.accessorType = AccessorType.VEC3;\r\n }\r\n\r\n this._createBufferViewKind(attributeKind, attributeComponentKind, babylonTransformNode, binaryWriter, attribute.byteStride);\r\n attribute.bufferViewIndex = this._bufferViews.length - 1;\r\n vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;\r\n }\r\n }\r\n\r\n if (bufferMesh.getTotalIndices()) {\r\n const indices = bufferMesh.getIndices();\r\n if (indices) {\r\n const byteLength = indices.length * 4;\r\n bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, \"Indices - \" + bufferMesh.name);\r\n this._bufferViews.push(bufferView);\r\n indexBufferViewIndex = this._bufferViews.length - 1;\r\n\r\n for (let k = 0, length = indices.length; k < length; ++k) {\r\n binaryWriter.setUInt32(indices[k]);\r\n }\r\n }\r\n }\r\n\r\n if (bufferMesh.subMeshes) {\r\n // go through all mesh primitives (submeshes)\r\n for (const submesh of bufferMesh.subMeshes) {\r\n let babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;\r\n\r\n let materialIndex: Nullable = null;\r\n if (babylonMaterial) {\r\n if (bufferMesh instanceof LinesMesh) {\r\n // get the color from the lines mesh and set it in the material\r\n const material: IMaterial = {\r\n name: bufferMesh.name + \" material\",\r\n };\r\n if (!bufferMesh.color.equals(Color3.White()) || bufferMesh.alpha < 1) {\r\n material.pbrMetallicRoughness = {\r\n baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha]),\r\n };\r\n }\r\n this._materials.push(material);\r\n materialIndex = this._materials.length - 1;\r\n } else if (babylonMaterial instanceof MultiMaterial) {\r\n const subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];\r\n if (subMaterial) {\r\n babylonMaterial = subMaterial;\r\n materialIndex = this._materialMap[babylonMaterial.uniqueId];\r\n }\r\n } else {\r\n materialIndex = this._materialMap[babylonMaterial.uniqueId];\r\n }\r\n }\r\n\r\n const glTFMaterial: Nullable = materialIndex != null ? this._materials[materialIndex] : null;\r\n\r\n const meshPrimitive: IMeshPrimitive = { attributes: {} };\r\n this._setPrimitiveMode(meshPrimitive, primitiveMode);\r\n\r\n for (const attribute of attributeData) {\r\n const attributeKind = attribute.kind;\r\n if ((attributeKind === VertexBuffer.UVKind || attributeKind === VertexBuffer.UV2Kind) && !this._options.exportUnusedUVs) {\r\n if (!glTFMaterial || !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {\r\n continue;\r\n }\r\n }\r\n const vertexData = bufferMesh.getVerticesData(attributeKind, undefined, undefined, true);\r\n if (vertexData) {\r\n const vertexBuffer = this._getVertexBufferFromMesh(attributeKind, bufferMesh);\r\n if (vertexBuffer) {\r\n const stride = vertexBuffer.getSize();\r\n const bufferViewIndex = attribute.bufferViewIndex;\r\n if (bufferViewIndex != undefined) {\r\n // check to see if bufferviewindex has a numeric value assigned.\r\n minMax = { min: null, max: null };\r\n if (attributeKind == VertexBuffer.PositionKind) {\r\n minMax = _GLTFUtilities._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride);\r\n }\r\n const accessor = _GLTFUtilities._CreateAccessor(\r\n bufferViewIndex,\r\n attributeKind + \" - \" + babylonTransformNode.name,\r\n attribute.accessorType,\r\n attribute.accessorComponentType,\r\n vertexData.length / stride,\r\n 0,\r\n minMax.min,\r\n minMax.max\r\n );\r\n this._accessors.push(accessor);\r\n this._setAttributeKind(meshPrimitive, attributeKind);\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (indexBufferViewIndex) {\r\n // Create accessor\r\n const accessor = _GLTFUtilities._CreateAccessor(\r\n indexBufferViewIndex,\r\n \"indices - \" + babylonTransformNode.name,\r\n AccessorType.SCALAR,\r\n AccessorComponentType.UNSIGNED_INT,\r\n submesh.indexCount,\r\n submesh.indexStart * 4,\r\n null,\r\n null\r\n );\r\n this._accessors.push(accessor);\r\n meshPrimitive.indices = this._accessors.length - 1;\r\n }\r\n\r\n if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {\r\n const sideOrientation = bufferMesh.overrideMaterialSideOrientation !== null ? bufferMesh.overrideMaterialSideOrientation : babylonMaterial.sideOrientation;\r\n\r\n if (sideOrientation === (this._babylonScene.useRightHandedSystem ? Material.ClockWiseSideOrientation : Material.CounterClockWiseSideOrientation)) {\r\n let byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;\r\n if (byteOffset == null) {\r\n byteOffset = 0;\r\n }\r\n let babylonIndices: Nullable = null;\r\n if (indexBufferViewIndex != null) {\r\n babylonIndices = bufferMesh.getIndices();\r\n }\r\n if (babylonIndices) {\r\n this._reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);\r\n } else {\r\n for (const attribute of attributeData) {\r\n const vertexData = bufferMesh.getVerticesData(attribute.kind, undefined, undefined, true);\r\n if (vertexData) {\r\n const byteOffset = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset || 0;\r\n this._reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, attribute.kind, vertexData, byteOffset, binaryWriter);\r\n }\r\n }\r\n }\r\n }\r\n\r\n meshPrimitive.material = materialIndex;\r\n }\r\n if (morphTargetManager) {\r\n let target;\r\n for (let i = 0; i < morphTargetManager.numTargets; ++i) {\r\n target = morphTargetManager.getTarget(i);\r\n this._setMorphTargetAttributes(submesh, meshPrimitive, target, binaryWriter);\r\n }\r\n }\r\n\r\n mesh.primitives.push(meshPrimitive);\r\n\r\n this._extensionsPostExportMeshPrimitiveAsync(\"postExport\", meshPrimitive, submesh, binaryWriter);\r\n promises.push();\r\n }\r\n }\r\n }\r\n return Promise.all(promises).then(() => {\r\n /* do nothing */\r\n });\r\n }\r\n\r\n /**\r\n * Creates a glTF scene based on the array of meshes\r\n * Returns the the total byte offset\r\n * @param babylonScene Babylon scene to get the mesh data from\r\n * @param binaryWriter Buffer to write binary data to\r\n */\r\n private _createSceneAsync(binaryWriter: _BinaryWriter): Promise {\r\n const scene: IScene = { nodes: [] };\r\n let glTFNodeIndex: number;\r\n let glTFNode: INode;\r\n let directDescendents: Node[];\r\n const nodes: Node[] = [...this._babylonScene.transformNodes, ...this._babylonScene.meshes, ...this._babylonScene.lights, ...this._babylonScene.cameras];\r\n const removedRootNodes = new Set();\r\n\r\n // Scene metadata\r\n if (this._babylonScene.metadata) {\r\n if (this._options.metadataSelector) {\r\n scene.extras = this._options.metadataSelector(this._babylonScene.metadata);\r\n } else if (this._babylonScene.metadata.gltf) {\r\n scene.extras = this._babylonScene.metadata.gltf.extras;\r\n }\r\n }\r\n\r\n // Remove no-op root nodes\r\n if ((this._options.removeNoopRootNodes ?? true) && !this._options.includeCoordinateSystemConversionNodes) {\r\n for (const rootNode of this._babylonScene.rootNodes) {\r\n if (isNoopNode(rootNode, this._babylonScene.useRightHandedSystem)) {\r\n removedRootNodes.add(rootNode);\r\n\r\n // Exclude the node from list of nodes to export\r\n nodes.splice(nodes.indexOf(rootNode), 1);\r\n }\r\n }\r\n }\r\n\r\n // Export babylon cameras to glTFCamera\r\n const cameraMap = new Map();\r\n this._babylonScene.cameras.forEach((camera) => {\r\n if (!this._options.shouldExportNode || this._options.shouldExportNode(camera)) {\r\n const glTFCamera: ICamera = {\r\n type: camera.mode === Camera.PERSPECTIVE_CAMERA ? CameraType.PERSPECTIVE : CameraType.ORTHOGRAPHIC,\r\n };\r\n\r\n if (camera.name) {\r\n glTFCamera.name = camera.name;\r\n }\r\n\r\n if (glTFCamera.type === CameraType.PERSPECTIVE) {\r\n glTFCamera.perspective = {\r\n aspectRatio: camera.getEngine().getAspectRatio(camera),\r\n yfov: camera.fovMode === Camera.FOVMODE_VERTICAL_FIXED ? camera.fov : camera.fov * camera.getEngine().getAspectRatio(camera),\r\n znear: camera.minZ,\r\n zfar: camera.maxZ,\r\n };\r\n } else if (glTFCamera.type === CameraType.ORTHOGRAPHIC) {\r\n const halfWidth = camera.orthoLeft && camera.orthoRight ? 0.5 * (camera.orthoRight - camera.orthoLeft) : camera.getEngine().getRenderWidth() * 0.5;\r\n const halfHeight = camera.orthoBottom && camera.orthoTop ? 0.5 * (camera.orthoTop - camera.orthoBottom) : camera.getEngine().getRenderHeight() * 0.5;\r\n glTFCamera.orthographic = {\r\n xmag: halfWidth,\r\n ymag: halfHeight,\r\n znear: camera.minZ,\r\n zfar: camera.maxZ,\r\n };\r\n }\r\n\r\n cameraMap.set(camera, this._cameras.length);\r\n this._cameras.push(glTFCamera);\r\n }\r\n });\r\n\r\n const [exportNodes, exportMaterials] = this._getExportNodes(nodes);\r\n return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(exportMaterials, ImageMimeType.PNG, true).then(() => {\r\n return this._createNodeMapAndAnimationsAsync(exportNodes, binaryWriter).then((nodeMap) => {\r\n return this._createSkinsAsync(nodeMap, binaryWriter).then((skinMap) => {\r\n this._nodeMap = nodeMap;\r\n\r\n this._totalByteLength = binaryWriter.getByteOffset();\r\n if (this._totalByteLength == undefined) {\r\n throw new Error(\"undefined byte length!\");\r\n }\r\n\r\n // Build Hierarchy with the node map.\r\n for (const babylonNode of nodes) {\r\n glTFNodeIndex = this._nodeMap[babylonNode.uniqueId];\r\n if (glTFNodeIndex !== undefined) {\r\n glTFNode = this._nodes[glTFNodeIndex];\r\n\r\n if (babylonNode.metadata) {\r\n if (this._options.metadataSelector) {\r\n glTFNode.extras = this._options.metadataSelector(babylonNode.metadata);\r\n } else if (babylonNode.metadata.gltf) {\r\n glTFNode.extras = babylonNode.metadata.gltf.extras;\r\n }\r\n }\r\n\r\n if (babylonNode instanceof Camera) {\r\n glTFNode.camera = cameraMap.get(babylonNode);\r\n }\r\n\r\n if (this._options.shouldExportNode && !this._options.shouldExportNode(babylonNode)) {\r\n Tools.Log(\"Omitting \" + babylonNode.name + \" from scene.\");\r\n } else {\r\n if (!babylonNode.parent && !this._babylonScene.useRightHandedSystem) {\r\n convertNodeHandedness(glTFNode);\r\n }\r\n\r\n if (!babylonNode.parent || removedRootNodes.has(babylonNode.parent)) {\r\n scene.nodes.push(glTFNodeIndex);\r\n }\r\n }\r\n\r\n if (babylonNode instanceof Mesh) {\r\n if (babylonNode.skeleton) {\r\n glTFNode.skin = skinMap[babylonNode.skeleton.uniqueId];\r\n }\r\n }\r\n\r\n directDescendents = babylonNode.getDescendants(true);\r\n if (!glTFNode.children && directDescendents && directDescendents.length) {\r\n const children: number[] = [];\r\n for (const descendent of directDescendents) {\r\n if (this._nodeMap[descendent.uniqueId] != null) {\r\n children.push(this._nodeMap[descendent.uniqueId]);\r\n }\r\n }\r\n if (children.length) {\r\n glTFNode.children = children;\r\n }\r\n }\r\n }\r\n }\r\n if (scene.nodes.length) {\r\n this._scenes.push(scene);\r\n }\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Getting the nodes and materials that would be exported.\r\n * @param nodes Babylon transform nodes\r\n * @returns Array of nodes which would be exported.\r\n * @returns Set of materials which would be exported.\r\n */\r\n private _getExportNodes(nodes: Node[]): [Node[], Set] {\r\n const exportNodes: Node[] = [];\r\n const exportMaterials: Set = new Set();\r\n\r\n for (const babylonNode of nodes) {\r\n if (!this._options.shouldExportNode || this._options.shouldExportNode(babylonNode)) {\r\n exportNodes.push(babylonNode);\r\n\r\n const babylonMesh = babylonNode as AbstractMesh;\r\n if (babylonMesh.subMeshes && babylonMesh.subMeshes.length > 0) {\r\n const material = babylonMesh.material || babylonMesh.getScene().defaultMaterial;\r\n if (material instanceof MultiMaterial) {\r\n for (const subMaterial of material.subMaterials) {\r\n if (subMaterial) {\r\n exportMaterials.add(subMaterial);\r\n }\r\n }\r\n } else {\r\n exportMaterials.add(material);\r\n }\r\n }\r\n } else {\r\n `Excluding node ${babylonNode.name}`;\r\n }\r\n }\r\n\r\n return [exportNodes, exportMaterials];\r\n }\r\n\r\n /**\r\n * Creates a mapping of Node unique id to node index and handles animations\r\n * @param nodes Babylon transform nodes\r\n * @param binaryWriter Buffer to write binary data to\r\n * @returns Node mapping of unique id to index\r\n */\r\n private _createNodeMapAndAnimationsAsync(nodes: Node[], binaryWriter: _BinaryWriter): Promise<{ [key: number]: number }> {\r\n let promiseChain = Promise.resolve();\r\n const nodeMap: { [key: number]: number } = {};\r\n let nodeIndex: number;\r\n const runtimeGLTFAnimation: IAnimation = {\r\n name: \"runtime animations\",\r\n channels: [],\r\n samplers: [],\r\n };\r\n const idleGLTFAnimations: IAnimation[] = [];\r\n\r\n for (const babylonNode of nodes) {\r\n promiseChain = promiseChain.then(() => {\r\n return this._createNodeAsync(babylonNode, binaryWriter).then((node) => {\r\n const promise = this._extensionsPostExportNodeAsync(\"createNodeAsync\", node, babylonNode, nodeMap, binaryWriter);\r\n if (promise == null) {\r\n Tools.Warn(`Not exporting node ${babylonNode.name}`);\r\n return Promise.resolve();\r\n } else {\r\n return promise.then((node) => {\r\n if (!node) {\r\n return;\r\n }\r\n this._nodes.push(node);\r\n nodeIndex = this._nodes.length - 1;\r\n nodeMap[babylonNode.uniqueId] = nodeIndex;\r\n\r\n if (!this._babylonScene.animationGroups.length) {\r\n _GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations(\r\n babylonNode,\r\n runtimeGLTFAnimation,\r\n idleGLTFAnimations,\r\n nodeMap,\r\n this._nodes,\r\n binaryWriter,\r\n this._bufferViews,\r\n this._accessors,\r\n this._animationSampleRate,\r\n this._options.shouldExportAnimation\r\n );\r\n if (babylonNode.animations.length) {\r\n _GLTFAnimation._CreateNodeAnimationFromNodeAnimations(\r\n babylonNode,\r\n runtimeGLTFAnimation,\r\n idleGLTFAnimations,\r\n nodeMap,\r\n this._nodes,\r\n binaryWriter,\r\n this._bufferViews,\r\n this._accessors,\r\n this._animationSampleRate,\r\n this._options.shouldExportAnimation\r\n );\r\n }\r\n }\r\n });\r\n }\r\n });\r\n });\r\n }\r\n\r\n return promiseChain.then(() => {\r\n if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {\r\n this._animations.push(runtimeGLTFAnimation);\r\n }\r\n idleGLTFAnimations.forEach((idleGLTFAnimation) => {\r\n if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {\r\n this._animations.push(idleGLTFAnimation);\r\n }\r\n });\r\n\r\n if (this._babylonScene.animationGroups.length) {\r\n _GLTFAnimation._CreateNodeAndMorphAnimationFromAnimationGroups(\r\n this._babylonScene,\r\n this._animations,\r\n nodeMap,\r\n binaryWriter,\r\n this._bufferViews,\r\n this._accessors,\r\n this._animationSampleRate,\r\n this._options.shouldExportAnimation\r\n );\r\n }\r\n\r\n return nodeMap;\r\n });\r\n }\r\n\r\n /**\r\n * Creates a glTF node from a Babylon mesh\r\n * @param babylonNode Source Babylon mesh\r\n * @param binaryWriter Buffer for storing geometry data\r\n * @returns glTF node\r\n */\r\n private _createNodeAsync(babylonNode: Node, binaryWriter: _BinaryWriter): Promise {\r\n return Promise.resolve().then(() => {\r\n // create node to hold translation/rotation/scale and the mesh\r\n const node: INode = {};\r\n // create mesh\r\n const mesh: IMesh = { primitives: [] };\r\n\r\n if (babylonNode.name) {\r\n node.name = babylonNode.name;\r\n }\r\n\r\n if (babylonNode instanceof TransformNode) {\r\n // Set transformation\r\n this._setNodeTransformation(node, babylonNode);\r\n if (babylonNode instanceof Mesh) {\r\n const morphTargetManager = babylonNode.morphTargetManager;\r\n if (morphTargetManager && morphTargetManager.numTargets > 0) {\r\n mesh.weights = [];\r\n for (let i = 0; i < morphTargetManager.numTargets; ++i) {\r\n mesh.weights.push(morphTargetManager.getTarget(i).influence);\r\n }\r\n }\r\n }\r\n return this._setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(() => {\r\n if (mesh.primitives.length) {\r\n this._meshes.push(mesh);\r\n node.mesh = this._meshes.length - 1;\r\n }\r\n return node;\r\n });\r\n } else if (babylonNode instanceof Camera) {\r\n this._setCameraTransformation(node, babylonNode);\r\n return node;\r\n } else {\r\n return node;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Creates a glTF skin from a Babylon skeleton\r\n * @param babylonScene Babylon Scene\r\n * @param nodeMap Babylon transform nodes\r\n * @param binaryWriter Buffer to write binary data to\r\n * @returns Node mapping of unique id to index\r\n */\r\n private _createSkinsAsync(nodeMap: { [key: number]: number }, binaryWriter: _BinaryWriter): Promise<{ [key: number]: number }> {\r\n const promiseChain = Promise.resolve();\r\n const skinMap: { [key: number]: number } = {};\r\n for (const skeleton of this._babylonScene.skeletons) {\r\n if (skeleton.bones.length <= 0) {\r\n continue;\r\n }\r\n // create skin\r\n const skin: ISkin = { joints: [] };\r\n const inverseBindMatrices: Matrix[] = [];\r\n\r\n const boneIndexMap: { [index: number]: Bone } = {};\r\n let maxBoneIndex = -1;\r\n for (let i = 0; i < skeleton.bones.length; ++i) {\r\n const bone = skeleton.bones[i];\r\n const boneIndex = bone.getIndex() ?? i;\r\n if (boneIndex !== -1) {\r\n boneIndexMap[boneIndex] = bone;\r\n if (boneIndex > maxBoneIndex) {\r\n maxBoneIndex = boneIndex;\r\n }\r\n }\r\n }\r\n\r\n for (let boneIndex = 0; boneIndex <= maxBoneIndex; ++boneIndex) {\r\n const bone = boneIndexMap[boneIndex];\r\n inverseBindMatrices.push(bone.getInvertedAbsoluteTransform());\r\n\r\n const transformNode = bone.getTransformNode();\r\n if (transformNode && nodeMap[transformNode.uniqueId] !== null && nodeMap[transformNode.uniqueId] !== undefined) {\r\n skin.joints.push(nodeMap[transformNode.uniqueId]);\r\n } else {\r\n Tools.Warn(\"Exporting a bone without a linked transform node is currently unsupported\");\r\n }\r\n }\r\n\r\n if (skin.joints.length > 0) {\r\n // create buffer view for inverse bind matrices\r\n const byteStride = 64; // 4 x 4 matrix of 32 bit float\r\n const byteLength = inverseBindMatrices.length * byteStride;\r\n const bufferViewOffset = binaryWriter.getByteOffset();\r\n const bufferView = _GLTFUtilities._CreateBufferView(0, bufferViewOffset, byteLength, undefined, \"InverseBindMatrices\" + \" - \" + skeleton.name);\r\n this._bufferViews.push(bufferView);\r\n const bufferViewIndex = this._bufferViews.length - 1;\r\n const bindMatrixAccessor = _GLTFUtilities._CreateAccessor(\r\n bufferViewIndex,\r\n \"InverseBindMatrices\" + \" - \" + skeleton.name,\r\n AccessorType.MAT4,\r\n AccessorComponentType.FLOAT,\r\n inverseBindMatrices.length,\r\n null,\r\n null,\r\n null\r\n );\r\n const inverseBindAccessorIndex = this._accessors.push(bindMatrixAccessor) - 1;\r\n skin.inverseBindMatrices = inverseBindAccessorIndex;\r\n this._skins.push(skin);\r\n skinMap[skeleton.uniqueId] = this._skins.length - 1;\r\n\r\n inverseBindMatrices.forEach((mat) => {\r\n mat.m.forEach((cell: number) => {\r\n binaryWriter.setFloat32(cell);\r\n });\r\n });\r\n }\r\n }\r\n return promiseChain.then(() => {\r\n return skinMap;\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n *\r\n * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically\r\n */\r\nexport class _BinaryWriter {\r\n /**\r\n * Array buffer which stores all binary data\r\n */\r\n private _arrayBuffer: ArrayBuffer;\r\n /**\r\n * View of the array buffer\r\n */\r\n private _dataView: DataView;\r\n /**\r\n * byte offset of data in array buffer\r\n */\r\n private _byteOffset: number;\r\n /**\r\n * Initialize binary writer with an initial byte length\r\n * @param byteLength Initial byte length of the array buffer\r\n */\r\n constructor(byteLength: number) {\r\n this._arrayBuffer = new ArrayBuffer(byteLength);\r\n this._dataView = new DataView(this._arrayBuffer);\r\n this._byteOffset = 0;\r\n }\r\n /**\r\n * Resize the array buffer to the specified byte length\r\n * @param byteLength\r\n */\r\n private _resizeBuffer(byteLength: number): ArrayBuffer {\r\n const newBuffer = new ArrayBuffer(byteLength);\r\n const copyOldBufferSize = Math.min(this._arrayBuffer.byteLength, byteLength);\r\n const oldUint8Array = new Uint8Array(this._arrayBuffer, 0, copyOldBufferSize);\r\n const newUint8Array = new Uint8Array(newBuffer);\r\n newUint8Array.set(oldUint8Array, 0);\r\n this._arrayBuffer = newBuffer;\r\n this._dataView = new DataView(this._arrayBuffer);\r\n\r\n return newBuffer;\r\n }\r\n /**\r\n * Get an array buffer with the length of the byte offset\r\n * @returns ArrayBuffer resized to the byte offset\r\n */\r\n public getArrayBuffer(): ArrayBuffer {\r\n return this._resizeBuffer(this.getByteOffset());\r\n }\r\n /**\r\n * Get the byte offset of the array buffer\r\n * @returns byte offset\r\n */\r\n public getByteOffset(): number {\r\n if (this._byteOffset == undefined) {\r\n throw new Error(\"Byte offset is undefined!\");\r\n }\r\n return this._byteOffset;\r\n }\r\n /**\r\n * Stores an UInt8 in the array buffer\r\n * @param entry\r\n * @param byteOffset If defined, specifies where to set the value as an offset.\r\n */\r\n public setUInt8(entry: number, byteOffset?: number) {\r\n if (byteOffset != null) {\r\n if (byteOffset < this._byteOffset) {\r\n this._dataView.setUint8(byteOffset, entry);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n }\r\n } else {\r\n if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {\r\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\r\n }\r\n this._dataView.setUint8(this._byteOffset, entry);\r\n this._byteOffset += 1;\r\n }\r\n }\r\n\r\n /**\r\n * Stores an UInt16 in the array buffer\r\n * @param entry\r\n * @param byteOffset If defined, specifies where to set the value as an offset.\r\n */\r\n public setUInt16(entry: number, byteOffset?: number) {\r\n if (byteOffset != null) {\r\n if (byteOffset < this._byteOffset) {\r\n this._dataView.setUint16(byteOffset, entry, true);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n }\r\n } else {\r\n if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {\r\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\r\n }\r\n this._dataView.setUint16(this._byteOffset, entry, true);\r\n this._byteOffset += 2;\r\n }\r\n }\r\n\r\n /**\r\n * Gets an UInt32 in the array buffer\r\n * @param byteOffset If defined, specifies where to set the value as an offset.\r\n */\r\n public getUInt32(byteOffset: number): number {\r\n if (byteOffset < this._byteOffset) {\r\n return this._dataView.getUint32(byteOffset, true);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n throw new Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n }\r\n }\r\n\r\n public getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void {\r\n if (byteOffset + 8 > this._byteOffset) {\r\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\r\n } else {\r\n vector3.x = this._dataView.getFloat32(byteOffset, true);\r\n vector3.y = this._dataView.getFloat32(byteOffset + 4, true);\r\n vector3.z = this._dataView.getFloat32(byteOffset + 8, true);\r\n }\r\n }\r\n\r\n public setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void {\r\n if (byteOffset + 8 > this._byteOffset) {\r\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\r\n } else {\r\n this._dataView.setFloat32(byteOffset, vector3.x, true);\r\n this._dataView.setFloat32(byteOffset + 4, vector3.y, true);\r\n this._dataView.setFloat32(byteOffset + 8, vector3.z, true);\r\n }\r\n }\r\n\r\n public getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void {\r\n if (byteOffset + 12 > this._byteOffset) {\r\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\r\n } else {\r\n vector4.x = this._dataView.getFloat32(byteOffset, true);\r\n vector4.y = this._dataView.getFloat32(byteOffset + 4, true);\r\n vector4.z = this._dataView.getFloat32(byteOffset + 8, true);\r\n vector4.w = this._dataView.getFloat32(byteOffset + 12, true);\r\n }\r\n }\r\n\r\n public setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void {\r\n if (byteOffset + 12 > this._byteOffset) {\r\n Tools.Error(`BinaryWriter: byteoffset is greater than the current binary buffer length!`);\r\n } else {\r\n this._dataView.setFloat32(byteOffset, vector4.x, true);\r\n this._dataView.setFloat32(byteOffset + 4, vector4.y, true);\r\n this._dataView.setFloat32(byteOffset + 8, vector4.z, true);\r\n this._dataView.setFloat32(byteOffset + 12, vector4.w, true);\r\n }\r\n }\r\n /**\r\n * Stores a Float32 in the array buffer\r\n * @param entry\r\n * @param byteOffset\r\n */\r\n public setFloat32(entry: number, byteOffset?: number) {\r\n if (isNaN(entry)) {\r\n Tools.Error(\"Invalid data being written!\");\r\n }\r\n if (byteOffset != null) {\r\n if (byteOffset < this._byteOffset) {\r\n this._dataView.setFloat32(byteOffset, entry, true);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary length!\");\r\n }\r\n }\r\n if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {\r\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\r\n }\r\n this._dataView.setFloat32(this._byteOffset, entry, true);\r\n this._byteOffset += 4;\r\n }\r\n /**\r\n * Stores an UInt32 in the array buffer\r\n * @param entry\r\n * @param byteOffset If defined, specifies where to set the value as an offset.\r\n */\r\n public setUInt32(entry: number, byteOffset?: number) {\r\n if (byteOffset != null) {\r\n if (byteOffset < this._byteOffset) {\r\n this._dataView.setUint32(byteOffset, entry, true);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n }\r\n } else {\r\n if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {\r\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\r\n }\r\n this._dataView.setUint32(this._byteOffset, entry, true);\r\n this._byteOffset += 4;\r\n }\r\n }\r\n /**\r\n * Stores an Int16 in the array buffer\r\n * @param entry\r\n * @param byteOffset If defined, specifies where to set the value as an offset.\r\n */\r\n public setInt16(entry: number, byteOffset?: number) {\r\n if (byteOffset != null) {\r\n if (byteOffset < this._byteOffset) {\r\n this._dataView.setInt16(byteOffset, entry, true);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n }\r\n } else {\r\n if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {\r\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\r\n }\r\n this._dataView.setInt16(this._byteOffset, entry, true);\r\n this._byteOffset += 2;\r\n }\r\n }\r\n /**\r\n * Stores a byte in the array buffer\r\n * @param entry\r\n * @param byteOffset If defined, specifies where to set the value as an offset.\r\n */\r\n public setByte(entry: number, byteOffset?: number) {\r\n if (byteOffset != null) {\r\n if (byteOffset < this._byteOffset) {\r\n this._dataView.setInt8(byteOffset, entry);\r\n } else {\r\n Tools.Error(\"BinaryWriter: byteoffset is greater than the current binary buffer length!\");\r\n }\r\n } else {\r\n if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {\r\n this._resizeBuffer(this._arrayBuffer.byteLength * 2);\r\n }\r\n this._dataView.setInt8(this._byteOffset, entry);\r\n this._byteOffset++;\r\n }\r\n }\r\n}\r\n","import type { Node } from \"core/node\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Animation } from \"core/Animations/animation\";\r\nimport type { GLTFData } from \"./glTFData\";\r\nimport { _Exporter } from \"./glTFExporter\";\r\n\r\n/**\r\n * Holds a collection of exporter options and parameters\r\n */\r\nexport interface IExportOptions {\r\n /**\r\n * Function which indicates whether a babylon node should be exported or not\r\n * @param node source Babylon node. It is used to check whether it should be exported to glTF or not\r\n * @returns boolean, which indicates whether the node should be exported (true) or not (false)\r\n */\r\n shouldExportNode?(node: Node): boolean;\r\n\r\n /**\r\n * Function which indicates whether an animation on the scene should be exported or not\r\n * @param animation source animation\r\n * @returns boolean, which indicates whether the animation should be exported (true) or not (false)\r\n */\r\n shouldExportAnimation?(animation: Animation): boolean;\r\n\r\n /**\r\n * Function used to extract the part of node's metadata that will be exported into glTF node extras\r\n * @param metadata source metadata to read from\r\n * @returns the data to store to glTF node extras\r\n */\r\n metadataSelector?(metadata: any): any;\r\n\r\n /**\r\n * The sample rate to bake animation curves. Defaults to 1 / 60.\r\n */\r\n animationSampleRate?: number;\r\n\r\n /**\r\n * Begin serialization without waiting for the scene to be ready. Defaults to false.\r\n */\r\n exportWithoutWaitingForScene?: boolean;\r\n\r\n /**\r\n * Indicates if unused vertex uv attributes should be included in export. Defaults to false.\r\n */\r\n exportUnusedUVs?: boolean;\r\n\r\n /**\r\n * Remove no-op root nodes when possible. Defaults to true.\r\n */\r\n removeNoopRootNodes?: boolean;\r\n\r\n /**\r\n * Indicates if coordinate system swapping root nodes should be included in export. Defaults to false.\r\n * @deprecated Please use removeNoopRootNodes instead\r\n */\r\n includeCoordinateSystemConversionNodes?: boolean;\r\n}\r\n\r\n/**\r\n * Class for generating glTF data from a Babylon scene.\r\n */\r\nexport class GLTF2Export {\r\n /**\r\n * Exports the geometry of the scene to .gltf file format asynchronously\r\n * @param scene Babylon scene with scene hierarchy information\r\n * @param filePrefix File prefix to use when generating the glTF file\r\n * @param options Exporter options\r\n * @returns Returns an object with a .gltf file and associates texture names\r\n * as keys and their data and paths as values\r\n */\r\n public static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise {\r\n return scene.whenReadyAsync().then(() => {\r\n const glTFPrefix = filePrefix.replace(/\\.[^/.]+$/, \"\");\r\n const gltfGenerator = new _Exporter(scene, options);\r\n return gltfGenerator._generateGLTFAsync(glTFPrefix);\r\n });\r\n }\r\n\r\n private static _PreExportAsync(scene: Scene, options?: IExportOptions): Promise {\r\n return Promise.resolve().then(() => {\r\n if (options && options.exportWithoutWaitingForScene) {\r\n return Promise.resolve();\r\n } else {\r\n return scene.whenReadyAsync();\r\n }\r\n });\r\n }\r\n\r\n private static _PostExportAsync(scene: Scene, glTFData: GLTFData, options?: IExportOptions): Promise {\r\n return Promise.resolve().then(() => {\r\n if (options && options.exportWithoutWaitingForScene) {\r\n return glTFData;\r\n } else {\r\n return glTFData;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Exports the geometry of the scene to .glb file format asychronously\r\n * @param scene Babylon scene with scene hierarchy information\r\n * @param filePrefix File prefix to use when generating glb file\r\n * @param options Exporter options\r\n * @returns Returns an object with a .glb filename as key and data as value\r\n */\r\n public static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise {\r\n return this._PreExportAsync(scene, options).then(() => {\r\n const glTFPrefix = filePrefix.replace(/\\.[^/.]+$/, \"\");\r\n const gltfGenerator = new _Exporter(scene, options);\r\n return gltfGenerator._generateGLBAsync(glTFPrefix).then((glTFData) => {\r\n return this._PostExportAsync(scene, glTFData, options);\r\n });\r\n });\r\n }\r\n}\r\n","import type { ITextureInfo, IKHRTextureTransform } from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_texture_transform implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n /** Reference to the glTF exporter */\r\n private _wasUsed = false;\r\n\r\n constructor() {}\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void {\r\n const canUseExtension =\r\n babylonTexture &&\r\n ((babylonTexture.uAng === 0 && babylonTexture.wAng === 0 && babylonTexture.vAng === 0) ||\r\n (babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0));\r\n\r\n if (canUseExtension) {\r\n const textureTransform: IKHRTextureTransform = {};\r\n let transformIsRequired = false;\r\n\r\n if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {\r\n textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.wAng !== 0) {\r\n textureTransform.rotation = -babylonTexture.wAng;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.coordinatesIndex !== 0) {\r\n textureTransform.texCoord = babylonTexture.coordinatesIndex;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (!transformIsRequired) {\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n if (!textureInfo.extensions) {\r\n textureInfo.extensions = {};\r\n }\r\n textureInfo.extensions[NAME] = textureTransform;\r\n }\r\n }\r\n\r\n public preExportTextureAsync(context: string, babylonTexture: Texture): Promise> {\r\n return new Promise((resolve, reject) => {\r\n const scene = babylonTexture.getScene();\r\n if (!scene) {\r\n reject(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}!`);\r\n return;\r\n }\r\n\r\n /*\r\n * The KHR_texture_transform schema only supports w rotation around the origin.\r\n * See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.\r\n */\r\n if (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);\r\n resolve(null);\r\n } else if (babylonTexture.wAng !== 0 && (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin cannot be exported with ${NAME}`);\r\n resolve(null);\r\n } else {\r\n resolve(babylonTexture);\r\n }\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, () => new KHR_texture_transform());\r\n","import type { SpotLight } from \"core/Lights/spotLight\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport type { Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { INode, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { _GLTFUtilities } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\r\n /** The name of this extension. */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled. */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n /** Reference to the glTF exporter */\r\n private _exporter: _Exporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onExporting(): void {\r\n this._exporter!._glTF.extensions![NAME] = this._lights;\r\n }\r\n /**\r\n * Define this method to modify the default behavior when exporting a node\r\n * @param context The context when exporting the node\r\n * @param node glTF node\r\n * @param babylonNode BabylonJS node\r\n * @param nodeMap Node mapping of unique id to glTF node index\r\n * @returns nullable INode promise\r\n */\r\n public postExportNodeAsync(context: string, node: Nullable, babylonNode: Node, nodeMap: { [key: number]: number }): Promise> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof ShadowLight) {\r\n let light: IKHRLightsPunctual_Light;\r\n\r\n const lightType =\r\n babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (lightType == null) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n } else {\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n node.translation = babylonNode.position.asArray();\r\n }\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonNode.direction;\r\n const yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;\r\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\r\n const pitch = -Math.atan2(localAxis.y, len);\r\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw + Math.PI, pitch, 0);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);\r\n }\r\n light = {\r\n type: lightType,\r\n };\r\n if (!babylonNode.diffuse.equals(Color3.White())) {\r\n light.color = babylonNode.diffuse.asArray();\r\n }\r\n if (babylonNode.intensity !== 1.0) {\r\n light.intensity = babylonNode.intensity;\r\n }\r\n if (babylonNode.range !== Number.MAX_VALUE) {\r\n light.range = babylonNode.range;\r\n }\r\n\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode as SpotLight;\r\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\r\n }\r\n if (babylonSpotLight.innerAngle !== 0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\r\n }\r\n }\r\n\r\n this._lights ||= {\r\n lights: [],\r\n };\r\n\r\n this._lights.lights.push(light);\r\n\r\n const lightReference: IKHRLightsPunctual_LightReference = {\r\n light: this._lights.lights.length - 1,\r\n };\r\n\r\n // Avoid duplicating the Light's parent node if possible.\r\n const parentBabylonNode = babylonNode.parent;\r\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\r\n const parentNode = this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];\r\n if (parentNode) {\r\n const parentTranslation = Vector3.FromArrayToRef(parentNode.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);\r\n const parentRotation = Quaternion.FromArrayToRef(parentNode.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);\r\n const parentScale = Vector3.FromArrayToRef(parentNode.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);\r\n const parentMatrix = Matrix.ComposeToRef(parentScale, parentRotation, parentTranslation, TmpVectors.Matrix[0]);\r\n\r\n const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[2]);\r\n const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]);\r\n const matrix = Matrix.ComposeToRef(Vector3.OneReadOnly, rotation, translation, TmpVectors.Matrix[1]);\r\n\r\n parentMatrix.multiplyToRef(matrix, matrix);\r\n matrix.decompose(parentScale, parentRotation, parentTranslation);\r\n\r\n if (parentTranslation.equalsToFloats(0, 0, 0)) {\r\n delete parentNode.translation;\r\n } else {\r\n parentNode.translation = parentTranslation.asArray();\r\n }\r\n\r\n if (Quaternion.IsIdentity(parentRotation)) {\r\n delete parentNode.rotation;\r\n } else {\r\n parentNode.rotation = parentRotation.asArray();\r\n }\r\n\r\n if (parentScale.equalsToFloats(1, 1, 1)) {\r\n delete parentNode.scale;\r\n } else {\r\n parentNode.scale = parentScale.asArray();\r\n }\r\n\r\n parentNode.extensions ||= {};\r\n parentNode.extensions[NAME] = lightReference;\r\n\r\n // Do not export the original node\r\n resolve(null);\r\n return;\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = lightReference;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n","import type { IMaterial, IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n hasTextures: () => {\r\n return clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null;\r\n },\r\n };\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n","import type { IMaterial, IKHRMaterialsIridescence } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_iridescence\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_iridescence implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.iridescence.isEnabled) {\r\n if (babylonMaterial.iridescence.texture) {\r\n additionalTextures.push(babylonMaterial.iridescence.texture);\r\n }\r\n if (babylonMaterial.iridescence.thicknessTexture && babylonMaterial.iridescence.thicknessTexture !== babylonMaterial.iridescence.texture) {\r\n additionalTextures.push(babylonMaterial.iridescence.thicknessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.iridescence.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const iridescenceTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.iridescence.texture);\r\n const iridescenceThicknessTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.iridescence.thicknessTexture);\r\n\r\n const iridescenceInfo: IKHRMaterialsIridescence = {\r\n iridescenceFactor: babylonMaterial.iridescence.intensity,\r\n iridescenceIor: babylonMaterial.iridescence.indexOfRefraction,\r\n iridescenceThicknessMinimum: babylonMaterial.iridescence.minimumThickness,\r\n iridescenceThicknessMaximum: babylonMaterial.iridescence.maximumThickness,\r\n\r\n iridescenceTexture: iridescenceTextureInfo ?? undefined,\r\n iridescenceThicknessTexture: iridescenceThicknessTextureInfo ?? undefined,\r\n hasTextures: () => {\r\n return iridescenceInfo.iridescenceTexture !== null || iridescenceInfo.iridescenceThicknessTexture !== null;\r\n },\r\n };\r\n\r\n node.extensions[NAME] = iridescenceInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_iridescence(exporter));\r\n","import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n hasTextures: () => {\r\n return anisotropyInfo.anisotropyTexture !== null;\r\n },\r\n };\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n","import type { IMaterial, IKHRMaterialsSheen } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_sheen\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_sheen implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (babylonMaterial.sheen.isEnabled && babylonMaterial.sheen.texture) {\r\n return [babylonMaterial.sheen.texture];\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (!babylonMaterial.sheen.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n const sheenInfo: IKHRMaterialsSheen = {\r\n sheenColorFactor: babylonMaterial.sheen.color.asArray(),\r\n sheenRoughnessFactor: babylonMaterial.sheen.roughness ?? 0,\r\n hasTextures: () => {\r\n return sheenInfo.sheenColorTexture !== null || sheenInfo.sheenRoughnessTexture !== null;\r\n },\r\n };\r\n\r\n if (babylonMaterial.sheen.texture) {\r\n sheenInfo.sheenColorTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture) ?? undefined;\r\n }\r\n\r\n if (babylonMaterial.sheen.textureRoughness && !babylonMaterial.sheen.useRoughnessFromMainTexture) {\r\n sheenInfo.sheenRoughnessTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.textureRoughness) ?? undefined;\r\n } else if (babylonMaterial.sheen.texture && babylonMaterial.sheen.useRoughnessFromMainTexture) {\r\n sheenInfo.sheenRoughnessTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture) ?? undefined;\r\n }\r\n\r\n node.extensions[NAME] = sheenInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_sheen(exporter));\r\n","import type { IMaterial } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nconst NAME = \"KHR_materials_unlit\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_unlit implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public dispose() {}\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n let unlitMaterial = false;\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n unlitMaterial = babylonMaterial.unlit;\r\n } else if (babylonMaterial instanceof StandardMaterial) {\r\n unlitMaterial = babylonMaterial.disableLighting;\r\n }\r\n\r\n if (unlitMaterial) {\r\n this._wasUsed = true;\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n\r\n node.extensions[NAME] = {};\r\n }\r\n\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, () => new KHR_materials_unlit());\r\n","import type { IMaterial, IKHRMaterialsIor } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\nconst NAME = \"KHR_materials_ior\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_ior/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_ior implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor() {}\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n return mat.indexOfRefraction != undefined && mat.indexOfRefraction != 1.5; // 1.5 is normative default value.\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const iorInfo: IKHRMaterialsIor = {\r\n ior: babylonMaterial.indexOfRefraction,\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = iorInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_ior());\r\n","import type { IMaterial, IKHRMaterialsSpecular } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_specular\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_specular implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.metallicReflectanceTexture) {\r\n additionalTextures.push(babylonMaterial.metallicReflectanceTexture);\r\n }\r\n if (babylonMaterial.reflectanceTexture) {\r\n additionalTextures.push(babylonMaterial.reflectanceTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n return (\r\n (mat.metallicF0Factor != undefined && mat.metallicF0Factor != 1.0) ||\r\n (mat.metallicReflectanceColor != undefined && !mat.metallicReflectanceColor.equalsFloats(1.0, 1.0, 1.0)) ||\r\n this._hasTexturesExtension(mat)\r\n );\r\n }\r\n\r\n private _hasTexturesExtension(mat: PBRMaterial): boolean {\r\n return mat.metallicReflectanceTexture != null || mat.reflectanceTexture != null;\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const metallicReflectanceTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.metallicReflectanceTexture) ?? undefined;\r\n const reflectanceTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.reflectanceTexture) ?? undefined;\r\n const metallicF0Factor = babylonMaterial.metallicF0Factor == 1.0 ? undefined : babylonMaterial.metallicF0Factor;\r\n const metallicReflectanceColor = babylonMaterial.metallicReflectanceColor.equalsFloats(1.0, 1.0, 1.0)\r\n ? undefined\r\n : babylonMaterial.metallicReflectanceColor.asArray();\r\n\r\n const specularInfo: IKHRMaterialsSpecular = {\r\n specularFactor: metallicF0Factor,\r\n specularTexture: metallicReflectanceTexture,\r\n specularColorFactor: metallicReflectanceColor,\r\n specularColorTexture: reflectanceTexture,\r\n hasTextures: () => {\r\n return this._hasTexturesExtension(babylonMaterial);\r\n },\r\n };\r\n node.extensions[NAME] = specularInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_specular(exporter));\r\n","import type { IMaterial, IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.thicknessTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n // this extension requires either the KHR_materials_transmission or KHR_materials_translucency extensions.\r\n if (!subs.isRefractionEnabled && !subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n return (\r\n (subs.maximumThickness != undefined && subs.maximumThickness != 0) ||\r\n (subs.tintColorAtDistance != undefined && subs.tintColorAtDistance != Number.POSITIVE_INFINITY) ||\r\n (subs.tintColor != undefined && subs.tintColor != Color3.White()) ||\r\n this._hasTexturesExtension(mat)\r\n );\r\n }\r\n\r\n private _hasTexturesExtension(mat: PBRMaterial): boolean {\r\n return mat.subSurface.thicknessTexture != null;\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const thicknessFactor = subs.maximumThickness == 0 ? undefined : subs.maximumThickness;\r\n const thicknessTexture = this._exporter._glTFMaterialExporter._getTextureInfo(subs.thicknessTexture) ?? undefined;\r\n const attenuationDistance = subs.tintColorAtDistance == Number.POSITIVE_INFINITY ? undefined : subs.tintColorAtDistance;\r\n const attenuationColor = subs.tintColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.tintColor.asArray();\r\n\r\n const volumeInfo: IKHRMaterialsVolume = {\r\n thicknessFactor: thicknessFactor,\r\n thicknessTexture: thicknessTexture,\r\n attenuationDistance: attenuationDistance,\r\n attenuationColor: attenuationColor,\r\n hasTextures: () => {\r\n return this._hasTexturesExtension(babylonMaterial);\r\n },\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_volume(exporter));\r\n","import type { IMaterial, IKHRMaterialsTransmission } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_transmission\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.thicknessTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n return (subs.isRefractionEnabled && subs.refractionIntensity != undefined && subs.refractionIntensity != 0) || this._hasTexturesExtension(mat);\r\n }\r\n\r\n private _hasTexturesExtension(mat: PBRMaterial): boolean {\r\n return mat.subSurface.refractionIntensityTexture != null;\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const transmissionFactor = subs.refractionIntensity === 0 ? undefined : subs.refractionIntensity;\r\n\r\n const transmissionTexture = this._exporter._glTFMaterialExporter._getTextureInfo(subs.refractionIntensityTexture) ?? undefined;\r\n\r\n const volumeInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: transmissionFactor,\r\n transmissionTexture: transmissionTexture,\r\n hasTextures: () => {\r\n return this._hasTexturesExtension(babylonMaterial);\r\n },\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));\r\n","import type { Nullable, DeepImmutableObject } from \"../types\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { VertexBuffer, Buffer } from \"../Buffers/buffer\";\r\nimport { Matrix, Vector3, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { BoundingInfo } from \"core/Culling/boundingInfo\";\r\n\r\ndeclare module \"./mesh\" {\r\n export interface Mesh {\r\n /**\r\n * Gets or sets a boolean defining if we want picking to pick thin instances as well\r\n */\r\n thinInstanceEnablePicking: boolean;\r\n /**\r\n * Creates a new thin instance\r\n * @param matrix the matrix or array of matrices (position, rotation, scale) of the thin instance(s) to create\r\n * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance\r\n * @returns the thin instance index number. If you pass an array of matrices, other instance indexes are index+1, index+2, etc\r\n */\r\n thinInstanceAdd(matrix: DeepImmutableObject | Array>, refresh?: boolean): number;\r\n\r\n /**\r\n * Adds the transformation (matrix) of the current mesh as a thin instance\r\n * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance\r\n * @returns the thin instance index number\r\n */\r\n thinInstanceAddSelf(refresh?: boolean): number;\r\n\r\n /**\r\n * Registers a custom attribute to be used with thin instances\r\n * @param kind name of the attribute\r\n * @param stride size in floats of the attribute\r\n */\r\n thinInstanceRegisterAttribute(kind: string, stride: number): void;\r\n\r\n /**\r\n * Sets the matrix of a thin instance\r\n * @param index index of the thin instance\r\n * @param matrix matrix to set\r\n * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance\r\n */\r\n thinInstanceSetMatrixAt(index: number, matrix: DeepImmutableObject, refresh?: boolean): void;\r\n\r\n /**\r\n * Sets the value of a custom attribute for a thin instance\r\n * @param kind name of the attribute\r\n * @param index index of the thin instance\r\n * @param value value to set\r\n * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance\r\n */\r\n thinInstanceSetAttributeAt(kind: string, index: number, value: Array, refresh?: boolean): void;\r\n\r\n /**\r\n * Gets / sets the number of thin instances to display. Note that you can't set a number higher than what the underlying buffer can handle.\r\n */\r\n thinInstanceCount: number;\r\n\r\n /**\r\n * Sets a buffer to be used with thin instances. This method is a faster way to setup multiple instances than calling thinInstanceAdd repeatedly\r\n * @param kind name of the attribute. Use \"matrix\" to setup the buffer of matrices\r\n * @param buffer buffer to set\r\n * @param stride size in floats of each value of the buffer\r\n * @param staticBuffer indicates that the buffer is static, so that you won't change it after it is set (better performances - false by default)\r\n */\r\n thinInstanceSetBuffer(kind: string, buffer: Nullable, stride?: number, staticBuffer?: boolean): void;\r\n\r\n /**\r\n * Gets the list of world matrices\r\n * @returns an array containing all the world matrices from the thin instances\r\n */\r\n thinInstanceGetWorldMatrices(): Matrix[];\r\n\r\n /**\r\n * Synchronize the gpu buffers with a thin instance buffer. Call this method if you update later on the buffers passed to thinInstanceSetBuffer\r\n * @param kind name of the attribute to update. Use \"matrix\" to update the buffer of matrices\r\n */\r\n thinInstanceBufferUpdated(kind: string): void;\r\n\r\n /**\r\n * Applies a partial update to a buffer directly on the GPU\r\n * Note that the buffer located on the CPU is NOT updated! It's up to you to update it (or not) with the same data you pass to this method\r\n * @param kind name of the attribute to update. Use \"matrix\" to update the buffer of matrices\r\n * @param data the data to set in the GPU buffer\r\n * @param offset the offset in the GPU buffer where to update the data\r\n */\r\n thinInstancePartialBufferUpdate(kind: string, data: Float32Array, offset: number): void;\r\n\r\n /**\r\n * Refreshes the bounding info, taking into account all the thin instances defined\r\n * @param forceRefreshParentInfo true to force recomputing the mesh bounding info and use it to compute the aggregated bounding info\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 */\r\n thinInstanceRefreshBoundingInfo(forceRefreshParentInfo?: boolean, applySkeleton?: boolean, applyMorph?: boolean): void;\r\n\r\n /** @internal */\r\n _thinInstanceInitializeUserStorage(): void;\r\n\r\n /** @internal */\r\n _thinInstanceUpdateBufferSize(kind: string, numInstances?: number): void;\r\n\r\n /** @internal */\r\n _thinInstanceCreateMatrixBuffer(kind: string, buffer: Nullable, staticBuffer: boolean): Buffer;\r\n\r\n /** @internal */\r\n _userThinInstanceBuffersStorage: {\r\n data: { [key: string]: Float32Array };\r\n sizes: { [key: string]: number };\r\n vertexBuffers: { [key: string]: Nullable };\r\n strides: { [key: string]: number };\r\n };\r\n }\r\n}\r\n\r\nMesh.prototype.thinInstanceAdd = function (matrix: DeepImmutableObject | Array>, refresh: boolean = true): number {\r\n if (!this.getScene().getEngine().getCaps().instancedArrays) {\r\n Logger.Error(\"Thin Instances are not supported on this device as Instanced Array extension not supported\");\r\n return -1;\r\n }\r\n\r\n this._thinInstanceUpdateBufferSize(\"matrix\", Array.isArray(matrix) ? matrix.length : 1);\r\n\r\n const index = this._thinInstanceDataStorage.instancesCount;\r\n\r\n if (Array.isArray(matrix)) {\r\n for (let i = 0; i < matrix.length; ++i) {\r\n this.thinInstanceSetMatrixAt(this._thinInstanceDataStorage.instancesCount++, matrix[i], i === matrix.length - 1 && refresh);\r\n }\r\n } else {\r\n this.thinInstanceSetMatrixAt(this._thinInstanceDataStorage.instancesCount++, matrix, refresh);\r\n }\r\n\r\n return index;\r\n};\r\n\r\nMesh.prototype.thinInstanceAddSelf = function (refresh: boolean = true): number {\r\n return this.thinInstanceAdd(Matrix.IdentityReadOnly, refresh);\r\n};\r\n\r\nMesh.prototype.thinInstanceRegisterAttribute = function (kind: string, stride: number): void {\r\n // preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n this.removeVerticesData(kind);\r\n\r\n this._thinInstanceInitializeUserStorage();\r\n\r\n this._userThinInstanceBuffersStorage.strides[kind] = stride;\r\n this._userThinInstanceBuffersStorage.sizes[kind] = stride * Math.max(32, this._thinInstanceDataStorage.instancesCount); // Initial size\r\n this._userThinInstanceBuffersStorage.data[kind] = new Float32Array(this._userThinInstanceBuffersStorage.sizes[kind]);\r\n this._userThinInstanceBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), this._userThinInstanceBuffersStorage.data[kind], kind, true, false, stride, true);\r\n\r\n this.setVerticesBuffer(this._userThinInstanceBuffersStorage.vertexBuffers[kind]!);\r\n};\r\n\r\nMesh.prototype.thinInstanceSetMatrixAt = function (index: number, matrix: DeepImmutableObject, refresh: boolean = true): boolean {\r\n if (!this._thinInstanceDataStorage.matrixData || index >= this._thinInstanceDataStorage.instancesCount) {\r\n return false;\r\n }\r\n\r\n const matrixData = this._thinInstanceDataStorage.matrixData;\r\n\r\n matrix.copyToArray(matrixData, index * 16);\r\n\r\n if (this._thinInstanceDataStorage.worldMatrices) {\r\n this._thinInstanceDataStorage.worldMatrices[index] = matrix as Matrix;\r\n }\r\n\r\n if (refresh) {\r\n this.thinInstanceBufferUpdated(\"matrix\");\r\n\r\n if (!this.doNotSyncBoundingInfo) {\r\n this.thinInstanceRefreshBoundingInfo(false);\r\n }\r\n }\r\n\r\n return true;\r\n};\r\n\r\nMesh.prototype.thinInstanceSetAttributeAt = function (kind: string, index: number, value: Array, refresh: boolean = true): boolean {\r\n // preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n if (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.data[kind] || index >= this._thinInstanceDataStorage.instancesCount) {\r\n return false;\r\n }\r\n\r\n this._thinInstanceUpdateBufferSize(kind, 0); // make sur the buffer for the kind attribute is big enough\r\n\r\n this._userThinInstanceBuffersStorage.data[kind].set(value, index * this._userThinInstanceBuffersStorage.strides[kind]);\r\n\r\n if (refresh) {\r\n this.thinInstanceBufferUpdated(kind);\r\n }\r\n\r\n return true;\r\n};\r\n\r\nObject.defineProperty(Mesh.prototype, \"thinInstanceCount\", {\r\n get: function (this: Mesh) {\r\n return this._thinInstanceDataStorage.instancesCount;\r\n },\r\n set: function (this: Mesh, value: number) {\r\n const matrixData = this._thinInstanceDataStorage.matrixData ?? this.source?._thinInstanceDataStorage.matrixData;\r\n const numMaxInstances = matrixData ? matrixData.length / 16 : 0;\r\n\r\n if (value <= numMaxInstances) {\r\n this._thinInstanceDataStorage.instancesCount = value;\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\nMesh.prototype._thinInstanceCreateMatrixBuffer = function (kind: string, buffer: Float32Array, staticBuffer: boolean = false): Buffer {\r\n // preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n const matrixBuffer = new Buffer(this.getEngine(), buffer, !staticBuffer, 16, false, true);\r\n\r\n for (let i = 0; i < 4; i++) {\r\n this.setVerticesBuffer(matrixBuffer.createVertexBuffer(kind + i, i * 4, 4));\r\n }\r\n\r\n return matrixBuffer;\r\n};\r\n\r\nMesh.prototype.thinInstanceSetBuffer = function (kind: string, buffer: Nullable, stride: number = 0, staticBuffer: boolean = false): void {\r\n stride = stride || 16;\r\n\r\n if (kind === \"matrix\") {\r\n this._thinInstanceDataStorage.matrixBuffer?.dispose();\r\n this._thinInstanceDataStorage.matrixBuffer = null;\r\n this._thinInstanceDataStorage.matrixBufferSize = buffer ? buffer.length : 32 * stride;\r\n this._thinInstanceDataStorage.matrixData = buffer;\r\n this._thinInstanceDataStorage.worldMatrices = null;\r\n\r\n if (buffer !== null) {\r\n this._thinInstanceDataStorage.instancesCount = buffer.length / stride;\r\n this._thinInstanceDataStorage.matrixBuffer = this._thinInstanceCreateMatrixBuffer(\"world\", buffer, staticBuffer);\r\n\r\n if (!this.doNotSyncBoundingInfo) {\r\n this.thinInstanceRefreshBoundingInfo(false);\r\n }\r\n } else {\r\n this._thinInstanceDataStorage.instancesCount = 0;\r\n if (!this.doNotSyncBoundingInfo) {\r\n // mesh has no more thin instances, so need to recompute the bounding box because it's the regular mesh that will now be displayed\r\n this.refreshBoundingInfo();\r\n }\r\n }\r\n } else if (kind === \"previousMatrix\") {\r\n this._thinInstanceDataStorage.previousMatrixBuffer?.dispose();\r\n this._thinInstanceDataStorage.previousMatrixBuffer = null;\r\n this._thinInstanceDataStorage.previousMatrixData = buffer;\r\n if (buffer !== null) {\r\n this._thinInstanceDataStorage.previousMatrixBuffer = this._thinInstanceCreateMatrixBuffer(\"previousWorld\", buffer, staticBuffer);\r\n }\r\n } else {\r\n // color for instanced mesh is ColorInstanceKind and not ColorKind because of native that needs to do the differenciation\r\n // hot switching kind here to preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n if (buffer === null) {\r\n if (this._userThinInstanceBuffersStorage?.data[kind]) {\r\n this.removeVerticesData(kind);\r\n delete this._userThinInstanceBuffersStorage.data[kind];\r\n delete this._userThinInstanceBuffersStorage.strides[kind];\r\n delete this._userThinInstanceBuffersStorage.sizes[kind];\r\n delete this._userThinInstanceBuffersStorage.vertexBuffers[kind];\r\n }\r\n } else {\r\n this._thinInstanceInitializeUserStorage();\r\n\r\n this._userThinInstanceBuffersStorage.data[kind] = buffer;\r\n this._userThinInstanceBuffersStorage.strides[kind] = stride;\r\n this._userThinInstanceBuffersStorage.sizes[kind] = buffer.length;\r\n this._userThinInstanceBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), buffer, kind, !staticBuffer, false, stride, true);\r\n\r\n this.setVerticesBuffer(this._userThinInstanceBuffersStorage.vertexBuffers[kind]!);\r\n }\r\n }\r\n};\r\n\r\nMesh.prototype.thinInstanceBufferUpdated = function (kind: string): void {\r\n if (kind === \"matrix\") {\r\n this._thinInstanceDataStorage.matrixBuffer?.updateDirectly(this._thinInstanceDataStorage.matrixData!, 0, this._thinInstanceDataStorage.instancesCount);\r\n } else if (kind === \"previousMatrix\") {\r\n this._thinInstanceDataStorage.previousMatrixBuffer?.updateDirectly(this._thinInstanceDataStorage.previousMatrixData!, 0, this._thinInstanceDataStorage.instancesCount);\r\n } else {\r\n // preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n if (this._userThinInstanceBuffersStorage?.vertexBuffers[kind]) {\r\n this._userThinInstanceBuffersStorage.vertexBuffers[kind]!.updateDirectly(this._userThinInstanceBuffersStorage.data[kind], 0);\r\n }\r\n }\r\n};\r\n\r\nMesh.prototype.thinInstancePartialBufferUpdate = function (kind: string, data: Float32Array, offset: number): void {\r\n if (kind === \"matrix\") {\r\n if (this._thinInstanceDataStorage.matrixBuffer) {\r\n this._thinInstanceDataStorage.matrixBuffer.updateDirectly(data, offset);\r\n }\r\n } else {\r\n // preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n if (this._userThinInstanceBuffersStorage?.vertexBuffers[kind]) {\r\n this._userThinInstanceBuffersStorage.vertexBuffers[kind]!.updateDirectly(data, offset);\r\n }\r\n }\r\n};\r\n\r\nMesh.prototype.thinInstanceGetWorldMatrices = function (): Matrix[] {\r\n if (!this._thinInstanceDataStorage.matrixData || !this._thinInstanceDataStorage.matrixBuffer) {\r\n return [];\r\n }\r\n const matrixData = this._thinInstanceDataStorage.matrixData;\r\n\r\n if (!this._thinInstanceDataStorage.worldMatrices) {\r\n this._thinInstanceDataStorage.worldMatrices = new Array();\r\n\r\n for (let i = 0; i < this._thinInstanceDataStorage.instancesCount; ++i) {\r\n this._thinInstanceDataStorage.worldMatrices[i] = Matrix.FromArray(matrixData, i * 16);\r\n }\r\n }\r\n\r\n return this._thinInstanceDataStorage.worldMatrices;\r\n};\r\n\r\nMesh.prototype.thinInstanceRefreshBoundingInfo = function (forceRefreshParentInfo: boolean = false, applySkeleton: boolean = false, applyMorph: boolean = false) {\r\n if (!this._thinInstanceDataStorage.matrixData || !this._thinInstanceDataStorage.matrixBuffer) {\r\n return;\r\n }\r\n\r\n const vectors = this._thinInstanceDataStorage.boundingVectors;\r\n\r\n if (forceRefreshParentInfo || !this.rawBoundingInfo) {\r\n vectors.length = 0;\r\n this.refreshBoundingInfo(applySkeleton, applyMorph);\r\n const boundingInfo = this.getBoundingInfo();\r\n this.rawBoundingInfo = new BoundingInfo(boundingInfo.minimum, boundingInfo.maximum);\r\n }\r\n\r\n const boundingInfo = this.getBoundingInfo();\r\n const matrixData = this._thinInstanceDataStorage.matrixData;\r\n\r\n if (vectors.length === 0) {\r\n for (let v = 0; v < boundingInfo.boundingBox.vectors.length; ++v) {\r\n vectors.push(boundingInfo.boundingBox.vectors[v].clone());\r\n }\r\n }\r\n\r\n TmpVectors.Vector3[0].setAll(Number.POSITIVE_INFINITY); // min\r\n TmpVectors.Vector3[1].setAll(Number.NEGATIVE_INFINITY); // max\r\n\r\n for (let i = 0; i < this._thinInstanceDataStorage.instancesCount; ++i) {\r\n Matrix.FromArrayToRef(matrixData, i * 16, TmpVectors.Matrix[0]);\r\n\r\n for (let v = 0; v < vectors.length; ++v) {\r\n Vector3.TransformCoordinatesToRef(vectors[v], TmpVectors.Matrix[0], TmpVectors.Vector3[2]);\r\n TmpVectors.Vector3[0].minimizeInPlace(TmpVectors.Vector3[2]);\r\n TmpVectors.Vector3[1].maximizeInPlace(TmpVectors.Vector3[2]);\r\n }\r\n }\r\n\r\n boundingInfo.reConstruct(TmpVectors.Vector3[0], TmpVectors.Vector3[1]);\r\n\r\n this._updateBoundingInfo();\r\n};\r\n\r\nMesh.prototype._thinInstanceUpdateBufferSize = function (kind: string, numInstances: number = 1) {\r\n // preserve backward compatibility\r\n if (kind === VertexBuffer.ColorKind) {\r\n kind = VertexBuffer.ColorInstanceKind;\r\n }\r\n\r\n const kindIsMatrix = kind === \"matrix\";\r\n\r\n if (!kindIsMatrix && (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.strides[kind])) {\r\n return;\r\n }\r\n\r\n const stride = kindIsMatrix ? 16 : this._userThinInstanceBuffersStorage.strides[kind];\r\n const currentSize = kindIsMatrix ? this._thinInstanceDataStorage.matrixBufferSize : this._userThinInstanceBuffersStorage.sizes[kind];\r\n let data = kindIsMatrix ? this._thinInstanceDataStorage.matrixData : this._userThinInstanceBuffersStorage.data[kind];\r\n\r\n const bufferSize = (this._thinInstanceDataStorage.instancesCount + numInstances) * stride;\r\n\r\n let newSize = currentSize;\r\n\r\n while (newSize < bufferSize) {\r\n newSize *= 2;\r\n }\r\n\r\n if (!data || currentSize != newSize) {\r\n if (!data) {\r\n data = new Float32Array(newSize);\r\n } else {\r\n const newData = new Float32Array(newSize);\r\n newData.set(data, 0);\r\n data = newData;\r\n }\r\n\r\n if (kindIsMatrix) {\r\n this._thinInstanceDataStorage.matrixBuffer?.dispose();\r\n this._thinInstanceDataStorage.matrixBuffer = this._thinInstanceCreateMatrixBuffer(\"world\", data, false);\r\n this._thinInstanceDataStorage.matrixData = data;\r\n this._thinInstanceDataStorage.matrixBufferSize = newSize;\r\n if (this._scene.needsPreviousWorldMatrices && !this._thinInstanceDataStorage.previousMatrixData) {\r\n this._thinInstanceDataStorage.previousMatrixBuffer?.dispose();\r\n this._thinInstanceDataStorage.previousMatrixBuffer = this._thinInstanceCreateMatrixBuffer(\"previousWorld\", data, false);\r\n }\r\n } else {\r\n this._userThinInstanceBuffersStorage.vertexBuffers[kind]?.dispose();\r\n\r\n this._userThinInstanceBuffersStorage.data[kind] = data;\r\n this._userThinInstanceBuffersStorage.sizes[kind] = newSize;\r\n this._userThinInstanceBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), data, kind, true, false, stride, true);\r\n\r\n this.setVerticesBuffer(this._userThinInstanceBuffersStorage.vertexBuffers[kind]!);\r\n }\r\n }\r\n};\r\n\r\nMesh.prototype._thinInstanceInitializeUserStorage = function () {\r\n if (!this._userThinInstanceBuffersStorage) {\r\n this._userThinInstanceBuffersStorage = {\r\n data: {},\r\n sizes: {},\r\n vertexBuffers: {},\r\n strides: {},\r\n };\r\n }\r\n};\r\n\r\nMesh.prototype._disposeThinInstanceSpecificData = function () {\r\n if (this._thinInstanceDataStorage?.matrixBuffer) {\r\n this._thinInstanceDataStorage.matrixBuffer.dispose();\r\n this._thinInstanceDataStorage.matrixBuffer = null;\r\n }\r\n};\r\n","import type { IBufferView, IAccessor, INode, IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\r\nimport { AccessorType, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport type { _BinaryWriter } from \"../glTFExporter\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Node } from \"core/node\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport \"core/Meshes/thinInstanceMesh\";\r\nimport { TmpVectors, Quaternion, Vector3 } from \"core/Maths/math.vector\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportNodeAsync(\r\n context: string,\r\n node: Nullable,\r\n babylonNode: Node,\r\n nodeMap: { [key: number]: number },\r\n binaryWriter: _BinaryWriter\r\n ): Promise> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof Mesh) {\r\n if (babylonNode.hasThinInstances && binaryWriter) {\r\n this._wasUsed = true;\r\n\r\n const noTranslation = Vector3.Zero();\r\n const noRotation = Quaternion.Identity();\r\n const noScale = Vector3.One();\r\n\r\n // retreive all the instance world matrix\r\n const matrix = babylonNode.thinInstanceGetWorldMatrices();\r\n\r\n const iwt = TmpVectors.Vector3[2];\r\n const iwr = TmpVectors.Quaternion[1];\r\n const iws = TmpVectors.Vector3[3];\r\n\r\n let hasAnyInstanceWorldTranslation = false;\r\n let hasAnyInstanceWorldRotation = false;\r\n let hasAnyInstanceWorldScale = false;\r\n\r\n // prepare temp buffers\r\n const translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n const rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);\r\n const scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n\r\n let i = 0;\r\n for (const m of matrix) {\r\n m.decompose(iws, iwr, iwt);\r\n\r\n // fill the temp buffer\r\n translationBuffer.set(iwt.asArray(), i * 3);\r\n rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized\r\n scaleBuffer.set(iws.asArray(), i * 3);\r\n\r\n // this is where we decide if there is any transformation\r\n hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);\r\n hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);\r\n hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);\r\n\r\n i++;\r\n }\r\n\r\n const extension: IEXTMeshGpuInstancing = {\r\n attributes: {},\r\n };\r\n\r\n // do we need to write TRANSLATION ?\r\n if (hasAnyInstanceWorldTranslation) {\r\n extension.attributes[\"TRANSLATION\"] = this._buildAccessor(\r\n translationBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n // do we need to write ROTATION ?\r\n if (hasAnyInstanceWorldRotation) {\r\n const componentType = AccessorComponentType.FLOAT; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495\r\n extension.attributes[\"ROTATION\"] = this._buildAccessor(rotationBuffer, AccessorType.VEC4, babylonNode.thinInstanceCount, binaryWriter, componentType);\r\n }\r\n // do we need to write SCALE ?\r\n if (hasAnyInstanceWorldScale) {\r\n extension.attributes[\"SCALE\"] = this._buildAccessor(\r\n scaleBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n\r\n /* eslint-enable @typescript-eslint/naming-convention*/\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = extension;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n\r\n private _buildAccessor(buffer: Float32Array, type: AccessorType, count: number, binaryWriter: _BinaryWriter, componentType: AccessorComponentType): number {\r\n // write the buffer\r\n const bufferOffset = binaryWriter.getByteOffset();\r\n switch (componentType) {\r\n case AccessorComponentType.FLOAT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setFloat32(buffer[i]);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.BYTE: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setByte(buffer[i] * 127);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.SHORT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setInt16(buffer[i] * 32767);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n // build the buffer view\r\n const bv: IBufferView = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };\r\n const bufferViewIndex = this._exporter._bufferViews.length;\r\n this._exporter._bufferViews.push(bv);\r\n\r\n // finally build the accessor\r\n const accessorIndex = this._exporter._accessors.length;\r\n const accessor: IAccessor = {\r\n bufferView: bufferViewIndex,\r\n componentType: componentType,\r\n count: count,\r\n type: type,\r\n normalized: componentType == AccessorComponentType.BYTE || componentType == AccessorComponentType.SHORT,\r\n };\r\n this._exporter._accessors.push(accessor);\r\n return accessorIndex;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n_Exporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));\r\n","import type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { IMaterial, IKHRMaterialsEmissiveStrength } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_emissive_strength\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_emissive_strength implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n public dispose() {}\r\n\r\n /** @interal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise {\r\n return new Promise((resolve) => {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n return resolve(node);\r\n }\r\n\r\n const emissiveColor = babylonMaterial.emissiveColor.asArray();\r\n const tempEmissiveStrength = Math.max(...emissiveColor);\r\n\r\n if (tempEmissiveStrength > 1) {\r\n this._wasUsed = true;\r\n\r\n node.extensions ||= {};\r\n\r\n const emissiveStrengthInfo: IKHRMaterialsEmissiveStrength = {\r\n emissiveStrength: tempEmissiveStrength,\r\n };\r\n\r\n // Normalize each value of the emissive factor to have a max value of 1\r\n const newEmissiveFactor = babylonMaterial.emissiveColor.scale(1 / emissiveStrengthInfo.emissiveStrength);\r\n\r\n node.emissiveFactor = newEmissiveFactor.asArray();\r\n node.extensions[NAME] = emissiveStrengthInfo;\r\n }\r\n\r\n return resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_emissive_strength());\r\n","import { Node } from '@babylonjs/core/node';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { GLTF2Export, GLTFData, IExportOptions } from '@babylonjs/serializers/glTF';\r\nimport { Connector, ViewpointNode } from '@models/classes';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\n\r\nexport class GLTFKb3dExporter {\r\n constructor(private scene: Scene) {}\r\n\r\n /** generates the current scene into a glb file and returns an object url for it */\r\n public generateGlb(filename = 'scene'): Promise {\r\n return GLTF2Export.GLBAsync(this.scene, filename, this._glbExportOptions).then(glbData => {\r\n return this.createGlbBlob(glbData);\r\n });\r\n }\r\n\r\n public exportGlb(filename = 'scene') {\r\n return GLTF2Export.GLBAsync(this.scene, filename, this._glbExportOptions).then(glbData => {\r\n const dispose = this.downloadBlob(`${filename}.glb`, this.createGlbBlob(glbData));\r\n setTimeout(() => dispose());\r\n });\r\n }\r\n\r\n public exportGltf(filename = 'scene') {\r\n return GLTF2Export.GLTFAsync(this.scene, filename, this._glbExportOptions).then(glbData => {\r\n const disposeFuncs: Array<() => void> = [];\r\n for (const key in glbData.glTFFiles) {\r\n const blob = glbData.glTFFiles[key];\r\n let mimeType;\r\n if (endsWith(key, '.glb')) {\r\n mimeType = { type: 'model/gltf-binary' };\r\n } else if (endsWith(key, '.bin')) {\r\n mimeType = { type: 'application/octet-stream' };\r\n } else if (endsWith(key, '.gltf')) {\r\n mimeType = { type: 'model/gltf+json' };\r\n } else if (endsWith(key, '.jpeg') || endsWith(key, '.jpg')) {\r\n mimeType = { type: 'image/jpeg' /* ImageMimeType.JPEG */ };\r\n } else if (endsWith(key, '.png')) {\r\n mimeType = { type: 'image/png' /* ImageMimeType.PNG */ };\r\n }\r\n\r\n disposeFuncs.push(this.downloadBlob(key, new Blob([blob], mimeType)));\r\n }\r\n setTimeout(() => disposeFuncs.forEach(dispose => dispose()));\r\n });\r\n\r\n function endsWith(str: string, suffix: string) {\r\n return str.indexOf(suffix, str.length - suffix.length) !== -1;\r\n }\r\n }\r\n\r\n private _glbExportOptions: IExportOptions = {\r\n shouldExportNode: n => this.shouldExportNode(n),\r\n };\r\n\r\n protected shouldExportNode(node: Node) {\r\n const kb3dNode = getByDynamicId(node.id);\r\n if (kb3dNode instanceof Connector) {\r\n return false;\r\n } else if (kb3dNode instanceof ViewpointNode) {\r\n return false;\r\n }\r\n return kb3dNode != null;\r\n }\r\n\r\n protected createGlbBlob(glbData: GLTFData) {\r\n //we're expecting one file since it's a GLB\r\n const key = Object.keys(glbData.glTFFiles)[0];\r\n const blob = glbData.glTFFiles[key];\r\n const mimeType = { type: 'model/gltf-binary' };\r\n return new Blob([blob], mimeType);\r\n }\r\n\r\n protected downloadBlob(fileName: string, blob: Blob) {\r\n const link = document.createElement('a');\r\n document.body.appendChild(link);\r\n link.setAttribute('type', 'hidden');\r\n link.download = fileName;\r\n link.href = window.URL.createObjectURL(blob);\r\n link.click();\r\n return dispose;\r\n\r\n function dispose() {\r\n window.URL.revokeObjectURL(link.href);\r\n link.remove();\r\n }\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { RegisterClass } from \"../../Misc/typeStore\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\n\r\n// Ensures Raw texture are included\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\n\r\n/**\r\n * This represents a color grading texture. This acts as a lookup table LUT, useful during post process\r\n * It can help converting any input color in a desired output one. This can then be used to create effects\r\n * from sepia, black and white to sixties or futuristic rendering...\r\n *\r\n * The only supported format is currently 3dl.\r\n * More information on LUT: https://en.wikipedia.org/wiki/3D_lookup_table\r\n */\r\nexport class ColorGradingTexture extends BaseTexture {\r\n /**\r\n * The texture URL.\r\n */\r\n public url: string;\r\n\r\n /**\r\n * Empty line regex stored for GC.\r\n */\r\n private static _NoneEmptyLineRegex = /\\S+/;\r\n\r\n private _textureMatrix: Matrix;\r\n private _onLoad: Nullable<() => void>;\r\n\r\n /**\r\n * Instantiates a ColorGradingTexture from the following parameters.\r\n *\r\n * @param url The location of the color grading data (currently only supporting 3dl)\r\n * @param sceneOrEngine The scene or engine the texture will be used in\r\n * @param onLoad defines a callback triggered when the texture has been loaded\r\n */\r\n constructor(url: string, sceneOrEngine: Scene | ThinEngine, onLoad: Nullable<() => void> = null) {\r\n super(sceneOrEngine);\r\n\r\n if (!url) {\r\n return;\r\n }\r\n\r\n this._textureMatrix = Matrix.Identity();\r\n this.name = url;\r\n this.url = url;\r\n this._onLoad = onLoad;\r\n\r\n this._texture = this._getFromCache(url, true);\r\n\r\n if (!this._texture) {\r\n const scene = this.getScene();\r\n if (scene) {\r\n if (!scene.useDelayedTextureLoading) {\r\n this._loadTexture();\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n }\r\n } else {\r\n this._loadTexture();\r\n }\r\n } else {\r\n this._triggerOnLoad();\r\n }\r\n }\r\n\r\n /**\r\n * Fires the onload event from the constructor if requested.\r\n */\r\n private _triggerOnLoad(): void {\r\n if (this._onLoad) {\r\n this._onLoad();\r\n }\r\n }\r\n\r\n /**\r\n * Returns the texture matrix used in most of the material.\r\n * This is not used in color grading but keep for troubleshooting purpose (easily swap diffuse by colorgrading to look in).\r\n */\r\n public getTextureMatrix(): Matrix {\r\n return this._textureMatrix;\r\n }\r\n\r\n /**\r\n * Occurs when the file being loaded is a .3dl LUT file.\r\n */\r\n private _load3dlTexture() {\r\n const engine = this._getEngine()!;\r\n let texture: InternalTexture;\r\n if (!engine._features.support3DTextures) {\r\n texture = engine.createRawTexture(\r\n null,\r\n 1,\r\n 1,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n false,\r\n false,\r\n Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n null,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n } else {\r\n texture = engine.createRawTexture3D(\r\n null,\r\n 1,\r\n 1,\r\n 1,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n false,\r\n false,\r\n Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n null,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n }\r\n\r\n this._texture = texture;\r\n this._texture.isReady = false;\r\n\r\n this.isCube = false;\r\n this.is3D = engine._features.support3DTextures;\r\n this.wrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n this.wrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n this.wrapR = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n this.anisotropicFilteringLevel = 1;\r\n\r\n const callback = (text: string | ArrayBuffer) => {\r\n if (typeof text !== \"string\") {\r\n return;\r\n }\r\n\r\n let data: Nullable = null;\r\n let tempData: Nullable = null;\r\n\r\n let line: string;\r\n const lines = text.split(\"\\n\");\r\n let size = 0,\r\n pixelIndexW = 0,\r\n pixelIndexH = 0,\r\n pixelIndexSlice = 0;\r\n let maxColor = 0;\r\n\r\n for (let i = 0; i < lines.length; i++) {\r\n line = lines[i];\r\n\r\n if (!ColorGradingTexture._NoneEmptyLineRegex.test(line)) {\r\n continue;\r\n }\r\n\r\n if (line.indexOf(\"#\") === 0) {\r\n continue;\r\n }\r\n\r\n const words = line.split(\" \");\r\n if (size === 0) {\r\n // Number of space + one\r\n size = words.length;\r\n data = new Uint8Array(size * size * size * 4); // volume texture of side size and rgb 8\r\n tempData = new Float32Array(size * size * size * 4);\r\n continue;\r\n }\r\n\r\n if (size != 0) {\r\n const r = Math.max(parseInt(words[0]), 0);\r\n const g = Math.max(parseInt(words[1]), 0);\r\n const b = Math.max(parseInt(words[2]), 0);\r\n\r\n maxColor = Math.max(r, maxColor);\r\n maxColor = Math.max(g, maxColor);\r\n maxColor = Math.max(b, maxColor);\r\n\r\n const pixelStorageIndex = (pixelIndexW + pixelIndexSlice * size + pixelIndexH * size * size) * 4;\r\n\r\n if (tempData) {\r\n tempData[pixelStorageIndex + 0] = r;\r\n tempData[pixelStorageIndex + 1] = g;\r\n tempData[pixelStorageIndex + 2] = b;\r\n }\r\n\r\n // Keep for reference in case of back compat problems.\r\n // pixelIndexSlice++;\r\n // if (pixelIndexSlice % size == 0) {\r\n // pixelIndexH++;\r\n // pixelIndexSlice = 0;\r\n // if (pixelIndexH % size == 0) {\r\n // pixelIndexW++;\r\n // pixelIndexH = 0;\r\n // }\r\n // }\r\n\r\n pixelIndexH++;\r\n if (pixelIndexH % size == 0) {\r\n pixelIndexSlice++;\r\n pixelIndexH = 0;\r\n if (pixelIndexSlice % size == 0) {\r\n pixelIndexW++;\r\n pixelIndexSlice = 0;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (tempData && data) {\r\n for (let i = 0; i < tempData.length; i++) {\r\n if (i > 0 && (i + 1) % 4 === 0) {\r\n data[i] = 255;\r\n } else {\r\n const value = tempData[i];\r\n data[i] = (value / maxColor) * 255;\r\n }\r\n }\r\n }\r\n\r\n if (texture.is3D) {\r\n texture.updateSize(size, size, size);\r\n engine.updateRawTexture3D(texture, data, Constants.TEXTUREFORMAT_RGBA, false);\r\n } else {\r\n texture.updateSize(size * size, size);\r\n engine.updateRawTexture(texture, data, Constants.TEXTUREFORMAT_RGBA, false);\r\n }\r\n\r\n texture.isReady = true;\r\n this._triggerOnLoad();\r\n };\r\n\r\n const scene = this.getScene();\r\n if (scene) {\r\n scene._loadFile(this.url, callback);\r\n } else {\r\n engine._loadFile(this.url, callback);\r\n }\r\n\r\n return this._texture;\r\n }\r\n\r\n /**\r\n * Starts the loading process of the texture.\r\n */\r\n private _loadTexture() {\r\n if (this.url && this.url.toLocaleLowerCase().indexOf(\".3dl\") == this.url.length - 4) {\r\n this._load3dlTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Clones the color grading texture.\r\n */\r\n public clone(): ColorGradingTexture {\r\n const newTexture = new ColorGradingTexture(this.url, this.getScene() || this._getEngine()!);\r\n\r\n // Base texture\r\n newTexture.level = this.level;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Called during delayed load for textures.\r\n */\r\n public delayLoad(): void {\r\n if (this.delayLoadState !== Constants.DELAYLOADSTATE_NOTLOADED) {\r\n return;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._texture = this._getFromCache(this.url, true);\r\n\r\n if (!this._texture) {\r\n this._loadTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Parses a color grading texture serialized by Babylon.\r\n * @param parsedTexture The texture information being parsedTexture\r\n * @param scene The scene to load the texture in\r\n * @returns A color grading texture\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene): Nullable {\r\n let texture = null;\r\n if (parsedTexture.name && !parsedTexture.isRenderTarget) {\r\n texture = new ColorGradingTexture(parsedTexture.name, scene);\r\n texture.name = parsedTexture.name;\r\n texture.level = parsedTexture.level;\r\n }\r\n return texture;\r\n }\r\n\r\n /**\r\n * Serializes the LUT texture to json format.\r\n */\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject: any = {};\r\n serializationObject.name = this.name;\r\n serializationObject.level = this.level;\r\n serializationObject.customType = \"BABYLON.ColorGradingTexture\";\r\n\r\n return serializationObject;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ColorGradingTexture\", ColorGradingTexture);\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../../types\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\n/**\r\n * CubeMap information grouping all the data for each faces as well as the cubemap size.\r\n */\r\nexport interface CubeMapInfo {\r\n /**\r\n * The pixel array for the front face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n front: Nullable;\r\n\r\n /**\r\n * The pixel array for the back face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n back: Nullable;\r\n\r\n /**\r\n * The pixel array for the left face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n left: Nullable;\r\n\r\n /**\r\n * The pixel array for the right face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n right: Nullable;\r\n\r\n /**\r\n * The pixel array for the up face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n up: Nullable;\r\n\r\n /**\r\n * The pixel array for the down face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n down: Nullable;\r\n\r\n /**\r\n * The size of the cubemap stored.\r\n *\r\n * Each faces will be size * size pixels.\r\n */\r\n size: number;\r\n\r\n /**\r\n * The format of the texture.\r\n *\r\n * RGBA, RGB.\r\n */\r\n format: number;\r\n\r\n /**\r\n * The type of the texture data.\r\n *\r\n * UNSIGNED_INT, FLOAT.\r\n */\r\n type: number;\r\n\r\n /**\r\n * Specifies whether the texture is in gamma space.\r\n */\r\n gammaSpace: boolean;\r\n}\r\n\r\n/**\r\n * Helper class useful to convert panorama picture to their cubemap representation in 6 faces.\r\n */\r\nexport class PanoramaToCubeMapTools {\r\n private static FACE_LEFT = [new Vector3(-1.0, -1.0, -1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(1.0, 1.0, -1.0)];\r\n private static FACE_RIGHT = [new Vector3(1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, 1.0)];\r\n private static FACE_FRONT = [new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0), new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0)];\r\n private static FACE_BACK = [new Vector3(-1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0)];\r\n private static FACE_DOWN = [new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(-1.0, 1.0, 1.0)];\r\n private static FACE_UP = [new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0)];\r\n\r\n /**\r\n * Converts a panorama stored in RGB right to left up to down format into a cubemap (6 faces).\r\n *\r\n * @param float32Array The source data.\r\n * @param inputWidth The width of the input panorama.\r\n * @param inputHeight The height of the input panorama.\r\n * @param size The willing size of the generated cubemap (each faces will be size * size pixels)\r\n * @returns The cubemap data\r\n */\r\n public static ConvertPanoramaToCubemap(float32Array: Float32Array, inputWidth: number, inputHeight: number, size: number, supersample = false): CubeMapInfo {\r\n if (!float32Array) {\r\n throw \"ConvertPanoramaToCubemap: input cannot be null\";\r\n }\r\n\r\n if (float32Array.length != inputWidth * inputHeight * 3) {\r\n throw \"ConvertPanoramaToCubemap: input size is wrong\";\r\n }\r\n\r\n const textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight, supersample);\r\n const textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight, supersample);\r\n const textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight, supersample);\r\n const textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight, supersample);\r\n const textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight, supersample);\r\n const textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight, supersample);\r\n\r\n return {\r\n front: textureFront,\r\n back: textureBack,\r\n left: textureLeft,\r\n right: textureRight,\r\n up: textureUp,\r\n down: textureDown,\r\n size: size,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGB,\r\n gammaSpace: false,\r\n };\r\n }\r\n\r\n private static CreateCubemapTexture(texSize: number, faceData: Vector3[], float32Array: Float32Array, inputWidth: number, inputHeight: number, supersample = false) {\r\n const buffer = new ArrayBuffer(texSize * texSize * 4 * 3);\r\n const textureArray = new Float32Array(buffer);\r\n\r\n // If supersampling, determine number of samples needed when source texture width is divided for 4 cube faces\r\n const samples = supersample ? Math.max(1, Math.round(inputWidth / 4 / texSize)) : 1;\r\n const sampleFactor = 1 / samples;\r\n const sampleFactorSqr = sampleFactor * sampleFactor;\r\n\r\n const rotDX1 = faceData[1].subtract(faceData[0]).scale(sampleFactor / texSize);\r\n const rotDX2 = faceData[3].subtract(faceData[2]).scale(sampleFactor / texSize);\r\n\r\n const dy = 1 / texSize;\r\n let fy = 0;\r\n\r\n for (let y = 0; y < texSize; y++) {\r\n for (let sy = 0; sy < samples; sy++) {\r\n let xv1 = faceData[0];\r\n let xv2 = faceData[2];\r\n\r\n for (let x = 0; x < texSize; x++) {\r\n for (let sx = 0; sx < samples; sx++) {\r\n const v = xv2.subtract(xv1).scale(fy).add(xv1);\r\n v.normalize();\r\n\r\n const color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);\r\n\r\n // 3 channels per pixels\r\n textureArray[y * texSize * 3 + x * 3 + 0] += color.r * sampleFactorSqr;\r\n textureArray[y * texSize * 3 + x * 3 + 1] += color.g * sampleFactorSqr;\r\n textureArray[y * texSize * 3 + x * 3 + 2] += color.b * sampleFactorSqr;\r\n\r\n xv1 = xv1.add(rotDX1);\r\n xv2 = xv2.add(rotDX2);\r\n }\r\n }\r\n\r\n fy += dy * sampleFactor;\r\n }\r\n }\r\n\r\n return textureArray;\r\n }\r\n\r\n private static CalcProjectionSpherical(vDir: Vector3, float32Array: Float32Array, inputWidth: number, inputHeight: number): any {\r\n let theta = Math.atan2(vDir.z, vDir.x);\r\n const phi = Math.acos(vDir.y);\r\n\r\n while (theta < -Math.PI) {\r\n theta += 2 * Math.PI;\r\n }\r\n while (theta > Math.PI) {\r\n theta -= 2 * Math.PI;\r\n }\r\n\r\n let dx = theta / Math.PI;\r\n const dy = phi / Math.PI;\r\n\r\n // recenter.\r\n dx = dx * 0.5 + 0.5;\r\n\r\n let px = Math.round(dx * inputWidth);\r\n if (px < 0) {\r\n px = 0;\r\n } else if (px >= inputWidth) {\r\n px = inputWidth - 1;\r\n }\r\n\r\n let py = Math.round(dy * inputHeight);\r\n if (py < 0) {\r\n py = 0;\r\n } else if (py >= inputHeight) {\r\n py = inputHeight - 1;\r\n }\r\n\r\n const inputY = inputHeight - py - 1;\r\n const r = float32Array[inputY * inputWidth * 3 + px * 3 + 0];\r\n const g = float32Array[inputY * inputWidth * 3 + px * 3 + 1];\r\n const b = float32Array[inputY * inputWidth * 3 + px * 3 + 2];\r\n\r\n return {\r\n r: r,\r\n g: g,\r\n b: b,\r\n };\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"hdrFilteringVertexShader\";\nconst shader = `attribute vec2 position;varying vec3 direction;uniform vec3 up;uniform vec3 right;uniform vec3 front;\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nmat3 view=mat3(up,right,front);direction=view*vec3(position,1.0);gl_Position=vec4(position,0.0,1.0);\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const hdrFilteringVertexShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/importanceSampling\";\nimport \"./ShadersInclude/pbrBRDFFunctions\";\nimport \"./ShadersInclude/hdrFilteringFunctions\";\n\nconst name = \"hdrFilteringPixelShader\";\nconst shader = `#include\n#include\n#include\n#include\nuniform float alphaG;uniform samplerCube inputTexture;uniform vec2 vFilteringInfo;uniform float hdrScale;varying vec3 direction;void main() {vec3 color=radiance(alphaG,inputTexture,direction,vFilteringInfo);gl_FragColor=vec4(color*hdrScale,1.0);}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const hdrFilteringPixelShader = { name, shader };\n","import { Vector3 } from \"../../../Maths/math\";\r\nimport { Scalar } from \"../../../Maths/math.scalar\";\r\nimport type { BaseTexture } from \"../baseTexture\";\r\nimport type { ThinEngine } from \"../../../Engines/thinEngine\";\r\nimport type { Effect } from \"../../../Materials/effect\";\r\nimport { Constants } from \"../../../Engines/constants\";\r\nimport { EffectWrapper, EffectRenderer } from \"../../../Materials/effectRenderer\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport type { RenderTargetWrapper } from \"../../../Engines/renderTargetWrapper\";\r\n\r\nimport \"../../../Shaders/hdrFiltering.vertex\";\r\nimport \"../../../Shaders/hdrFiltering.fragment\";\r\nimport { Logger } from \"../../../Misc/logger\";\r\n\r\n/**\r\n * Options for texture filtering\r\n */\r\ninterface IHDRFilteringOptions {\r\n /**\r\n * Scales pixel intensity for the input HDR map.\r\n */\r\n hdrScale?: number;\r\n\r\n /**\r\n * Quality of the filter. Should be `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` for prefiltering\r\n */\r\n quality?: number;\r\n}\r\n\r\n/**\r\n * Filters HDR maps to get correct renderings of PBR reflections\r\n */\r\nexport class HDRFiltering {\r\n private _engine: ThinEngine;\r\n private _effectRenderer: EffectRenderer;\r\n private _effectWrapper: EffectWrapper;\r\n\r\n private _lodGenerationOffset: number = 0;\r\n private _lodGenerationScale: number = 0.8;\r\n\r\n /**\r\n * Quality switch for prefiltering. Should be set to `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` unless\r\n * you care about baking speed.\r\n */\r\n public quality: number = Constants.TEXTURE_FILTERING_QUALITY_OFFLINE;\r\n\r\n /**\r\n * Scales pixel intensity for the input HDR map.\r\n */\r\n public hdrScale: number = 1;\r\n\r\n /**\r\n * Instantiates HDR filter for reflection maps\r\n *\r\n * @param engine Thin engine\r\n * @param options Options\r\n */\r\n constructor(engine: ThinEngine, options: IHDRFilteringOptions = {}) {\r\n // pass\r\n this._engine = engine;\r\n this.hdrScale = options.hdrScale || this.hdrScale;\r\n this.quality = options.quality || this.quality;\r\n }\r\n\r\n private _createRenderTarget(size: number): RenderTargetWrapper {\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (this._engine.getCaps().textureHalfFloatRender) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else if (this._engine.getCaps().textureFloatRender) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n const rtWrapper = this._engine.createRenderTargetCubeTexture(size, {\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n type: textureType,\r\n createMipMaps: true,\r\n generateMipMaps: false,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n });\r\n this._engine.updateTextureWrappingMode(rtWrapper.texture!, Constants.TEXTURE_CLAMP_ADDRESSMODE, Constants.TEXTURE_CLAMP_ADDRESSMODE, Constants.TEXTURE_CLAMP_ADDRESSMODE);\r\n\r\n this._engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, rtWrapper.texture!, true);\r\n\r\n return rtWrapper;\r\n }\r\n\r\n private _prefilterInternal(texture: BaseTexture): BaseTexture {\r\n const width = texture.getSize().width;\r\n const mipmapsCount = Scalar.ILog2(width) + 1;\r\n\r\n const effect = this._effectWrapper.effect;\r\n const outputTexture = this._createRenderTarget(width);\r\n this._effectRenderer.saveStates();\r\n this._effectRenderer.setViewport();\r\n\r\n const intTexture = texture.getInternalTexture();\r\n if (intTexture) {\r\n // Just in case generate fresh clean mips.\r\n this._engine.updateTextureSamplingMode(Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, intTexture, true);\r\n }\r\n\r\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\r\n\r\n const directions = [\r\n [new Vector3(0, 0, -1), new Vector3(0, -1, 0), new Vector3(1, 0, 0)], // PositiveX\r\n [new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector3(-1, 0, 0)], // NegativeX\r\n [new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)], // PositiveY\r\n [new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)], // NegativeY\r\n [new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1)], // PositiveZ\r\n [new Vector3(-1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, -1)], // NegativeZ\r\n ];\r\n\r\n effect.setFloat(\"hdrScale\", this.hdrScale);\r\n effect.setFloat2(\"vFilteringInfo\", texture.getSize().width, mipmapsCount);\r\n effect.setTexture(\"inputTexture\", texture);\r\n\r\n for (let face = 0; face < 6; face++) {\r\n effect.setVector3(\"up\", directions[face][0]);\r\n effect.setVector3(\"right\", directions[face][1]);\r\n effect.setVector3(\"front\", directions[face][2]);\r\n\r\n for (let lod = 0; lod < mipmapsCount; lod++) {\r\n this._engine.bindFramebuffer(outputTexture, face, undefined, undefined, true, lod);\r\n this._effectRenderer.applyEffectWrapper(this._effectWrapper);\r\n\r\n let alpha = Math.pow(2, (lod - this._lodGenerationOffset) / this._lodGenerationScale) / width;\r\n if (lod === 0) {\r\n alpha = 0;\r\n }\r\n\r\n effect.setFloat(\"alphaG\", alpha);\r\n\r\n this._effectRenderer.draw();\r\n }\r\n }\r\n\r\n // Cleanup\r\n this._effectRenderer.restoreStates();\r\n this._engine.restoreDefaultFramebuffer();\r\n this._engine._releaseTexture(texture._texture!);\r\n\r\n // Internal Swap\r\n const type = outputTexture.texture!.type;\r\n const format = outputTexture.texture!.format;\r\n\r\n outputTexture._swapAndDie(texture._texture!);\r\n\r\n texture._texture!.type = type;\r\n texture._texture!.format = format;\r\n\r\n // New settings\r\n texture.gammaSpace = false;\r\n texture.lodGenerationOffset = this._lodGenerationOffset;\r\n texture.lodGenerationScale = this._lodGenerationScale;\r\n texture._prefiltered = true;\r\n\r\n return texture;\r\n }\r\n\r\n private _createEffect(texture: BaseTexture, onCompiled?: Nullable<(effect: Effect) => void>): EffectWrapper {\r\n const defines = [];\r\n if (texture.gammaSpace) {\r\n defines.push(\"#define GAMMA_INPUT\");\r\n }\r\n\r\n defines.push(\"#define NUM_SAMPLES \" + this.quality + \"u\"); // unsigned int\r\n\r\n const effectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n name: \"hdrFiltering\",\r\n vertexShader: \"hdrFiltering\",\r\n fragmentShader: \"hdrFiltering\",\r\n samplerNames: [\"inputTexture\"],\r\n uniformNames: [\"vSampleDirections\", \"vWeights\", \"up\", \"right\", \"front\", \"vFilteringInfo\", \"hdrScale\", \"alphaG\"],\r\n useShaderStore: true,\r\n defines,\r\n onCompiled: onCompiled,\r\n });\r\n\r\n return effectWrapper;\r\n }\r\n\r\n /**\r\n * Get a value indicating if the filter is ready to be used\r\n * @param texture Texture to filter\r\n * @returns true if the filter is ready\r\n */\r\n public isReady(texture: BaseTexture) {\r\n return texture.isReady() && this._effectWrapper.effect.isReady();\r\n }\r\n\r\n /**\r\n * Prefilters a cube texture to have mipmap levels representing roughness values.\r\n * Prefiltering will be invoked at the end of next rendering pass.\r\n * This has to be done once the map is loaded, and has not been prefiltered by a third party software.\r\n * See http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf for more information\r\n * @param texture Texture to filter\r\n * @param onFinished Callback when filtering is done\r\n * @returns Promise called when prefiltering is done\r\n */\r\n public prefilter(texture: BaseTexture, onFinished: Nullable<() => void> = null): Promise {\r\n if (!this._engine._features.allowTexturePrefiltering) {\r\n Logger.Warn(\"HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.\");\r\n return Promise.reject(\"HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.\");\r\n }\r\n\r\n return new Promise((resolve) => {\r\n this._effectRenderer = new EffectRenderer(this._engine);\r\n this._effectWrapper = this._createEffect(texture);\r\n this._effectWrapper.effect.executeWhenCompiled(() => {\r\n this._prefilterInternal(texture);\r\n this._effectRenderer.dispose();\r\n this._effectWrapper.dispose();\r\n resolve();\r\n if (onFinished) {\r\n onFinished();\r\n }\r\n });\r\n });\r\n }\r\n}\r\n","import type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { PanoramaToCubeMapTools } from \"./panoramaToCubemap\";\r\n\r\n/**\r\n * Header information of HDR texture files.\r\n */\r\nexport interface HDRInfo {\r\n /**\r\n * The height of the texture in pixels.\r\n */\r\n height: number;\r\n\r\n /**\r\n * The width of the texture in pixels.\r\n */\r\n width: number;\r\n\r\n /**\r\n * The index of the beginning of the data in the binary file.\r\n */\r\n dataPosition: number;\r\n}\r\n\r\n/**\r\n * This groups tools to convert HDR texture to native colors array.\r\n */\r\nexport class HDRTools {\r\n private static _Ldexp(mantissa: number, exponent: number): number {\r\n if (exponent > 1023) {\r\n return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);\r\n }\r\n\r\n if (exponent < -1074) {\r\n return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);\r\n }\r\n\r\n return mantissa * Math.pow(2, exponent);\r\n }\r\n\r\n private static _Rgbe2float(float32array: Float32Array, red: number, green: number, blue: number, exponent: number, index: number) {\r\n if (exponent > 0) {\r\n /*nonzero pixel*/\r\n exponent = this._Ldexp(1.0, exponent - (128 + 8));\r\n\r\n float32array[index + 0] = red * exponent;\r\n float32array[index + 1] = green * exponent;\r\n float32array[index + 2] = blue * exponent;\r\n } else {\r\n float32array[index + 0] = 0;\r\n float32array[index + 1] = 0;\r\n float32array[index + 2] = 0;\r\n }\r\n }\r\n\r\n private static _ReadStringLine(uint8array: Uint8Array, startIndex: number): string {\r\n let line = \"\";\r\n let character = \"\";\r\n\r\n for (let i = startIndex; i < uint8array.length - startIndex; i++) {\r\n character = String.fromCharCode(uint8array[i]);\r\n\r\n if (character == \"\\n\") {\r\n break;\r\n }\r\n\r\n line += character;\r\n }\r\n\r\n return line;\r\n }\r\n\r\n /**\r\n * Reads header information from an RGBE texture stored in a native array.\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in native array.\r\n * @returns The header information.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo {\r\n let height: number = 0;\r\n let width: number = 0;\r\n\r\n let line = this._ReadStringLine(uint8array, 0);\r\n if (line[0] != \"#\" || line[1] != \"?\") {\r\n throw \"Bad HDR Format.\";\r\n }\r\n\r\n let endOfHeader = false;\r\n let findFormat = false;\r\n let lineIndex: number = 0;\r\n\r\n do {\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n if (line == \"FORMAT=32-bit_rle_rgbe\") {\r\n findFormat = true;\r\n } else if (line.length == 0) {\r\n endOfHeader = true;\r\n }\r\n } while (!endOfHeader);\r\n\r\n if (!findFormat) {\r\n throw \"HDR Bad header format, unsupported FORMAT\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n const sizeRegexp = /^-Y (.*) \\+X (.*)$/g;\r\n const match = sizeRegexp.exec(line);\r\n\r\n // TODO. Support +Y and -X if needed.\r\n if (!match || match.length < 3) {\r\n throw \"HDR Bad header format, no size\";\r\n }\r\n width = parseInt(match[2]);\r\n height = parseInt(match[1]);\r\n\r\n if (width < 8 || width > 0x7fff) {\r\n throw \"HDR Bad header format, unsupported size\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n\r\n return {\r\n height: height,\r\n width: width,\r\n dataPosition: lineIndex,\r\n };\r\n }\r\n\r\n /**\r\n * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.\r\n * This RGBE texture needs to store the information as a panorama.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param buffer The binary file stored in an array buffer.\r\n * @param size The expected size of the extracted cubemap.\r\n * @returns The Cube Map information.\r\n */\r\n public static GetCubeMapTextureData(buffer: ArrayBuffer, size: number, supersample = false): CubeMapInfo {\r\n const uint8array = new Uint8Array(buffer);\r\n const hdrInfo = this.RGBE_ReadHeader(uint8array);\r\n const data = this.RGBE_ReadPixels(uint8array, hdrInfo);\r\n\r\n const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);\r\n\r\n return cubeMapData;\r\n }\r\n\r\n /**\r\n * Returns the pixels data extracted from an RGBE texture.\r\n * This pixels will be stored left to right up to down in the R G B order in one array.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in an array buffer.\r\n * @param hdrInfo The header information of the file.\r\n * @returns The pixels data in RGB right to left up to down order.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n return this._RGBEReadPixelsRLE(uint8array, hdrInfo);\r\n }\r\n\r\n private static _RGBEReadPixelsRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, count: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n let index = 0,\r\n endIndex = 0,\r\n i = 0;\r\n\r\n const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E\r\n const scanLineArray = new Uint8Array(scanLineArrayBuffer);\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {\r\n return this._RGBEReadPixelsNOTRLE(uint8array, hdrInfo);\r\n }\r\n\r\n if (((c << 8) | d) != scanline_width) {\r\n throw \"HDR Bad header format, wrong scan line width\";\r\n }\r\n\r\n index = 0;\r\n\r\n // read each of the four channels for the scanline into the buffer\r\n for (i = 0; i < 4; i++) {\r\n endIndex = (i + 1) * scanline_width;\r\n\r\n while (index < endIndex) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n\r\n if (a > 128) {\r\n // a run of the same value\r\n count = a - 128;\r\n if (count == 0 || count > endIndex - index) {\r\n throw \"HDR Bad Format, bad scanline data (run)\";\r\n }\r\n\r\n while (count-- > 0) {\r\n scanLineArray[index++] = b;\r\n }\r\n } else {\r\n // a non-run\r\n count = a;\r\n if (count == 0 || count > endIndex - index) {\r\n throw \"HDR Bad Format, bad scanline data (non-run)\";\r\n }\r\n\r\n scanLineArray[index++] = b;\r\n if (--count > 0) {\r\n for (let j = 0; j < count; j++) {\r\n scanLineArray[index++] = uint8array[dataIndex++];\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // now convert data from buffer into floats\r\n for (i = 0; i < scanline_width; i++) {\r\n a = scanLineArray[i];\r\n b = scanLineArray[i + scanline_width];\r\n c = scanLineArray[i + 2 * scanline_width];\r\n d = scanLineArray[i + 3 * scanline_width];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n\r\n private static _RGBEReadPixelsNOTRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n // this file is not run length encoded\r\n // read values sequentially\r\n\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, i: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n for (i = 0; i < hdrInfo.width; i++) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { HDRTools } from \"../../Misc/HighDynamicRange/hdr\";\r\nimport { CubeMapToSphericalPolynomialTools } from \"../../Misc/HighDynamicRange/cubemapToSphericalPolynomial\";\r\nimport { RegisterClass } from \"../../Misc/typeStore\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { ToGammaSpace } from \"../../Maths/math.constants\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { HDRFiltering } from \"../../Materials/Textures/Filtering/hdrFiltering\";\r\nimport { ToHalfFloat } from \"../../Misc/textureTools\";\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\nimport \"../../Materials/Textures/baseTexture.polynomial\";\r\n\r\n/**\r\n * This represents a texture coming from an HDR input.\r\n *\r\n * The only supported format is currently panorama picture stored in RGBE format.\r\n * Example of such files can be found on Poly Haven: https://polyhaven.com/hdris\r\n */\r\nexport class HDRCubeTexture extends BaseTexture {\r\n private static _FacesMapping = [\"right\", \"left\", \"up\", \"down\", \"front\", \"back\"];\r\n\r\n private _generateHarmonics = true;\r\n private _noMipmap: boolean;\r\n private _prefilterOnLoad: boolean;\r\n private _textureMatrix: Matrix;\r\n private _size: number;\r\n private _supersample: boolean;\r\n private _onLoad: () => void;\r\n private _onError: Nullable<() => void> = null;\r\n\r\n /**\r\n * The texture URL.\r\n */\r\n public url: string;\r\n\r\n protected _isBlocking: boolean = true;\r\n /**\r\n * Sets whether or not the texture is blocking during loading.\r\n */\r\n public set isBlocking(value: boolean) {\r\n this._isBlocking = value;\r\n }\r\n /**\r\n * Gets whether or not the texture is blocking during loading.\r\n */\r\n public get isBlocking(): boolean {\r\n return this._isBlocking;\r\n }\r\n\r\n protected _rotationY: number = 0;\r\n /**\r\n * Sets texture matrix rotation angle around Y axis in radians.\r\n */\r\n public set rotationY(value: number) {\r\n this._rotationY = value;\r\n this.setReflectionTextureMatrix(Matrix.RotationY(this._rotationY));\r\n }\r\n /**\r\n * Gets texture matrix rotation angle around Y axis radians.\r\n */\r\n public get rotationY(): number {\r\n return this._rotationY;\r\n }\r\n\r\n /**\r\n * Gets or sets the center of the bounding box associated with the cube texture\r\n * It must define where the camera used to render the texture was set\r\n */\r\n public boundingBoxPosition = Vector3.Zero();\r\n\r\n private _boundingBoxSize: Vector3;\r\n\r\n /**\r\n * Gets or sets the size of the bounding box associated with the cube texture\r\n * When defined, the cubemap will switch to local mode\r\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\r\n * @example https://www.babylonjs-playground.com/#RNASML\r\n */\r\n public set boundingBoxSize(value: Vector3) {\r\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\r\n return;\r\n }\r\n this._boundingBoxSize = value;\r\n const scene = this.getScene();\r\n if (scene) {\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n }\r\n public get boundingBoxSize(): Vector3 {\r\n return this._boundingBoxSize;\r\n }\r\n\r\n /**\r\n * Observable triggered once the texture has been loaded.\r\n */\r\n public onLoadObservable: Observable = new Observable();\r\n\r\n /**\r\n * Instantiates an HDRTexture from the following parameters.\r\n *\r\n * @param url The location of the HDR raw data (Panorama stored in RGBE format)\r\n * @param sceneOrEngine The scene or engine the texture will be used in\r\n * @param size The cubemap desired size (the more it increases the longer the generation will be)\r\n * @param noMipmap Forces to not generate the mipmap if true\r\n * @param generateHarmonics Specifies whether you want to extract the polynomial harmonics during the generation process\r\n * @param gammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)\r\n * @param prefilterOnLoad Prefilters HDR texture to allow use of this texture as a PBR reflection texture.\r\n * @param onLoad\r\n * @param onError\r\n */\r\n constructor(\r\n url: string,\r\n sceneOrEngine: Scene | ThinEngine,\r\n size: number,\r\n noMipmap = false,\r\n generateHarmonics = true,\r\n gammaSpace = false,\r\n prefilterOnLoad = false,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n supersample = false\r\n ) {\r\n super(sceneOrEngine);\r\n\r\n if (!url) {\r\n return;\r\n }\r\n\r\n this._coordinatesMode = Texture.CUBIC_MODE;\r\n this.name = url;\r\n this.url = url;\r\n this.hasAlpha = false;\r\n this.isCube = true;\r\n this._textureMatrix = Matrix.Identity();\r\n this._prefilterOnLoad = prefilterOnLoad;\r\n this._onLoad = () => {\r\n this.onLoadObservable.notifyObservers(this);\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n };\r\n\r\n this._onError = onError;\r\n this.gammaSpace = gammaSpace;\r\n\r\n this._noMipmap = noMipmap;\r\n this._size = size;\r\n this._supersample = supersample;\r\n this._generateHarmonics = generateHarmonics;\r\n\r\n this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);\r\n\r\n if (!this._texture) {\r\n if (!this.getScene()?.useDelayedTextureLoading) {\r\n this._loadTexture();\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n }\r\n } else {\r\n if (this._texture.isReady) {\r\n Tools.SetImmediate(() => this._onLoad());\r\n } else {\r\n this._texture.onLoadedObservable.add(this._onLoad);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"HDRCubeTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"HDRCubeTexture\";\r\n }\r\n\r\n /**\r\n * Occurs when the file is raw .hdr file.\r\n */\r\n private _loadTexture() {\r\n const engine = this._getEngine()!;\r\n const caps = engine.getCaps();\r\n\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (caps.textureFloat && caps.textureFloatLinearFiltering) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n } else if (caps.textureHalfFloat && caps.textureHalfFloatLinearFiltering) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n\r\n const callback = (buffer: ArrayBuffer): Nullable => {\r\n this.lodGenerationOffset = 0.0;\r\n this.lodGenerationScale = 0.8;\r\n\r\n // Extract the raw linear data.\r\n const data = HDRTools.GetCubeMapTextureData(buffer, this._size, this._supersample);\r\n\r\n // Generate harmonics if needed.\r\n if (this._generateHarmonics) {\r\n const sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);\r\n this.sphericalPolynomial = sphericalPolynomial;\r\n }\r\n\r\n const results = [];\r\n\r\n let byteArray: Nullable = null;\r\n let shortArray: Nullable = null;\r\n\r\n // Push each faces.\r\n for (let j = 0; j < 6; j++) {\r\n // Create fallback array\r\n if (textureType === Constants.TEXTURETYPE_HALF_FLOAT) {\r\n shortArray = new Uint16Array(this._size * this._size * 3);\r\n } else if (textureType === Constants.TEXTURETYPE_UNSIGNED_BYTE) {\r\n // 3 channels of 1 bytes per pixel in bytes.\r\n byteArray = new Uint8Array(this._size * this._size * 3);\r\n }\r\n\r\n const dataFace = (data)[HDRCubeTexture._FacesMapping[j]];\r\n\r\n // If special cases.\r\n if (this.gammaSpace || shortArray || byteArray) {\r\n for (let i = 0; i < this._size * this._size; i++) {\r\n // Put in gamma space if requested.\r\n if (this.gammaSpace) {\r\n dataFace[i * 3 + 0] = Math.pow(dataFace[i * 3 + 0], ToGammaSpace);\r\n dataFace[i * 3 + 1] = Math.pow(dataFace[i * 3 + 1], ToGammaSpace);\r\n dataFace[i * 3 + 2] = Math.pow(dataFace[i * 3 + 2], ToGammaSpace);\r\n }\r\n\r\n // Convert to half float texture for fallback.\r\n if (shortArray) {\r\n shortArray[i * 3 + 0] = ToHalfFloat(dataFace[i * 3 + 0]);\r\n shortArray[i * 3 + 1] = ToHalfFloat(dataFace[i * 3 + 1]);\r\n shortArray[i * 3 + 2] = ToHalfFloat(dataFace[i * 3 + 2]);\r\n }\r\n\r\n // Convert to int texture for fallback.\r\n if (byteArray) {\r\n let r = Math.max(dataFace[i * 3 + 0] * 255, 0);\r\n let g = Math.max(dataFace[i * 3 + 1] * 255, 0);\r\n let b = Math.max(dataFace[i * 3 + 2] * 255, 0);\r\n\r\n // May use luminance instead if the result is not accurate.\r\n const max = Math.max(Math.max(r, g), b);\r\n if (max > 255) {\r\n const scale = 255 / max;\r\n r *= scale;\r\n g *= scale;\r\n b *= scale;\r\n }\r\n\r\n byteArray[i * 3 + 0] = r;\r\n byteArray[i * 3 + 1] = g;\r\n byteArray[i * 3 + 2] = b;\r\n }\r\n }\r\n }\r\n\r\n if (shortArray) {\r\n results.push(shortArray);\r\n } else if (byteArray) {\r\n results.push(byteArray);\r\n } else {\r\n results.push(dataFace);\r\n }\r\n }\r\n\r\n return results;\r\n };\r\n\r\n if (engine._features.allowTexturePrefiltering && this._prefilterOnLoad) {\r\n const previousOnLoad = this._onLoad;\r\n const hdrFiltering = new HDRFiltering(engine);\r\n this._onLoad = () => {\r\n hdrFiltering.prefilter(this, previousOnLoad);\r\n };\r\n }\r\n\r\n this._texture = engine.createRawCubeTextureFromUrl(\r\n this.url,\r\n this.getScene(),\r\n this._size,\r\n Constants.TEXTUREFORMAT_RGB,\r\n textureType,\r\n this._noMipmap,\r\n callback,\r\n null,\r\n this._onLoad,\r\n this._onError\r\n );\r\n }\r\n\r\n public clone(): HDRCubeTexture {\r\n const newTexture = new HDRCubeTexture(this.url, this.getScene() || this._getEngine()!, this._size, this._noMipmap, this._generateHarmonics, this.gammaSpace);\r\n\r\n // Base texture\r\n newTexture.level = this.level;\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n newTexture.coordinatesIndex = this.coordinatesIndex;\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n return newTexture;\r\n }\r\n\r\n // Methods\r\n public delayLoad(): void {\r\n if (this.delayLoadState !== Constants.DELAYLOADSTATE_NOTLOADED) {\r\n return;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._texture = this._getFromCache(this.url, this._noMipmap);\r\n\r\n if (!this._texture) {\r\n this._loadTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Get the texture reflection matrix used to rotate/transform the reflection.\r\n * @returns the reflection matrix\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n return this._textureMatrix;\r\n }\r\n\r\n /**\r\n * Set the texture reflection matrix used to rotate/transform the reflection.\r\n * @param value Define the reflection matrix to set\r\n */\r\n public setReflectionTextureMatrix(value: Matrix): void {\r\n this._textureMatrix = value;\r\n\r\n if (value.updateFlag === this._textureMatrix.updateFlag) {\r\n return;\r\n }\r\n\r\n if (value.isIdentity() !== this._textureMatrix.isIdentity()) {\r\n this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n this.onLoadObservable.clear();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Parses a JSON representation of an HDR Texture in order to create the texture\r\n * @param parsedTexture Define the JSON representation\r\n * @param scene Define the scene the texture should be created in\r\n * @param rootUrl Define the root url in case we need to load relative dependencies\r\n * @returns the newly created texture after parsing\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable {\r\n let texture = null;\r\n if (parsedTexture.name && !parsedTexture.isRenderTarget) {\r\n texture = new HDRCubeTexture(\r\n rootUrl + parsedTexture.name,\r\n scene,\r\n parsedTexture.size,\r\n parsedTexture.noMipmap,\r\n parsedTexture.generateHarmonics,\r\n parsedTexture.useInGammaSpace\r\n );\r\n texture.name = parsedTexture.name;\r\n texture.hasAlpha = parsedTexture.hasAlpha;\r\n texture.level = parsedTexture.level;\r\n texture.coordinatesMode = parsedTexture.coordinatesMode;\r\n texture.isBlocking = parsedTexture.isBlocking;\r\n }\r\n if (texture) {\r\n if (parsedTexture.boundingBoxPosition) {\r\n (texture).boundingBoxPosition = Vector3.FromArray(parsedTexture.boundingBoxPosition);\r\n }\r\n if (parsedTexture.boundingBoxSize) {\r\n (texture).boundingBoxSize = Vector3.FromArray(parsedTexture.boundingBoxSize);\r\n }\r\n if (parsedTexture.rotationY) {\r\n (texture).rotationY = parsedTexture.rotationY;\r\n }\r\n }\r\n return texture;\r\n }\r\n\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject: any = {};\r\n serializationObject.name = this.name;\r\n serializationObject.hasAlpha = this.hasAlpha;\r\n serializationObject.isCube = true;\r\n serializationObject.level = this.level;\r\n serializationObject.size = this._size;\r\n serializationObject.coordinatesMode = this.coordinatesMode;\r\n serializationObject.useInGammaSpace = this.gammaSpace;\r\n serializationObject.generateHarmonics = this._generateHarmonics;\r\n serializationObject.customType = \"BABYLON.HDRCubeTexture\";\r\n serializationObject.noMipmap = this._noMipmap;\r\n serializationObject.isBlocking = this._isBlocking;\r\n serializationObject.rotationY = this._rotationY;\r\n\r\n return serializationObject;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.HDRCubeTexture\", HDRCubeTexture);\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { InternalTexture } from \"../../Materials/Textures/internalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../constants\";\r\nimport type { ExternalTexture } from \"../../Materials/Textures/externalTexture\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Update a video texture\r\n * @param texture defines the texture to update\r\n * @param video defines the video element to use\r\n * @param invertY defines if data must be stored with Y axis inverted\r\n */\r\n updateVideoTexture(texture: Nullable, video: HTMLVideoElement | Nullable, invertY: boolean): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.updateVideoTexture = function (texture: Nullable, video: HTMLVideoElement, invertY: boolean): void {\r\n if (!texture || texture._isDisabled) {\r\n return;\r\n }\r\n\r\n const glformat = this._getInternalFormat(texture.format);\r\n const internalFormat = this._getRGBABufferInternalSizedFormat(Constants.TEXTURETYPE_UNSIGNED_BYTE, texture.format);\r\n\r\n const wasPreviouslyBound = this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);\r\n this._unpackFlipY(!invertY); // Video are upside down by default\r\n\r\n try {\r\n // Testing video texture support\r\n if (this._videoTextureSupported === undefined) {\r\n // clear old errors just in case.\r\n this._gl.getError();\r\n\r\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, glformat, this._gl.UNSIGNED_BYTE, video);\r\n\r\n if (this._gl.getError() !== 0) {\r\n this._videoTextureSupported = false;\r\n } else {\r\n this._videoTextureSupported = true;\r\n }\r\n }\r\n\r\n // Copy video through the current working canvas if video texture is not supported\r\n if (!this._videoTextureSupported) {\r\n if (!texture._workingCanvas) {\r\n texture._workingCanvas = this.createCanvas(texture.width, texture.height);\r\n const context = texture._workingCanvas.getContext(\"2d\");\r\n\r\n if (!context) {\r\n throw new Error(\"Unable to get 2d context\");\r\n }\r\n\r\n texture._workingContext = context;\r\n texture._workingCanvas.width = texture.width;\r\n texture._workingCanvas.height = texture.height;\r\n }\r\n\r\n texture._workingContext!.clearRect(0, 0, texture.width, texture.height);\r\n texture._workingContext!.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture.width, texture.height);\r\n\r\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, glformat, this._gl.UNSIGNED_BYTE, texture._workingCanvas as TexImageSource);\r\n } else {\r\n this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, glformat, this._gl.UNSIGNED_BYTE, video);\r\n }\r\n\r\n if (texture.generateMipMaps) {\r\n this._gl.generateMipmap(this._gl.TEXTURE_2D);\r\n }\r\n\r\n if (!wasPreviouslyBound) {\r\n this._bindTextureDirectly(this._gl.TEXTURE_2D, null);\r\n }\r\n // this.resetTextureCache();\r\n texture.isReady = true;\r\n } catch (ex) {\r\n // Something unexpected\r\n // Let's disable the texture\r\n texture._isDisabled = true;\r\n }\r\n};\r\n","import { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { ExternalTexture } from \"../../Materials/Textures/externalTexture\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates an external texture\r\n * @param video video element\r\n * @returns the external texture, or null if external textures are not supported by the engine\r\n */\r\n createExternalTexture(video: HTMLVideoElement): Nullable;\r\n\r\n /**\r\n * Sets an internal texture to the according uniform.\r\n * @param name The name of the uniform in the effect\r\n * @param texture The texture to apply\r\n */\r\n setExternalTexture(name: string, texture: Nullable): void;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nThinEngine.prototype.createExternalTexture = function (video: HTMLVideoElement): Nullable {\r\n return null;\r\n};\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nThinEngine.prototype.setExternalTexture = function (name: string, texture: Nullable): void {\r\n throw new Error(\"setExternalTexture: This engine does not support external textures!\");\r\n};\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Logger } from \"../Misc/logger\";\r\n\r\n//private static _TYPE_NO_DATA = 0;\r\nconst _TYPE_INDEXED = 1;\r\nconst _TYPE_RGB = 2;\r\nconst _TYPE_GREY = 3;\r\nconst _TYPE_RLE_INDEXED = 9;\r\nconst _TYPE_RLE_RGB = 10;\r\nconst _TYPE_RLE_GREY = 11;\r\nconst _ORIGIN_MASK = 0x30;\r\nconst _ORIGIN_SHIFT = 0x04;\r\nconst _ORIGIN_BL = 0x00;\r\nconst _ORIGIN_BR = 0x01;\r\nconst _ORIGIN_UL = 0x02;\r\nconst _ORIGIN_UR = 0x03;\r\n\r\n/**\r\n * Gets the header of a TGA file\r\n * @param data defines the TGA data\r\n * @returns the header\r\n */\r\nexport function GetTGAHeader(data: Uint8Array): any {\r\n let offset = 0;\r\n\r\n const header = {\r\n id_length: data[offset++],\r\n colormap_type: data[offset++],\r\n image_type: data[offset++],\r\n colormap_index: data[offset++] | (data[offset++] << 8),\r\n colormap_length: data[offset++] | (data[offset++] << 8),\r\n colormap_size: data[offset++],\r\n origin: [data[offset++] | (data[offset++] << 8), data[offset++] | (data[offset++] << 8)],\r\n width: data[offset++] | (data[offset++] << 8),\r\n height: data[offset++] | (data[offset++] << 8),\r\n pixel_size: data[offset++],\r\n flags: data[offset++],\r\n };\r\n\r\n return header;\r\n}\r\n\r\n/**\r\n * Uploads TGA content to a Babylon Texture\r\n * @internal\r\n */\r\nexport function UploadContent(texture: InternalTexture, data: Uint8Array): void {\r\n // Not enough data to contain header ?\r\n if (data.length < 19) {\r\n Logger.Error(\"Unable to load TGA file - Not enough data to contain header\");\r\n return;\r\n }\r\n\r\n // Read Header\r\n let offset = 18;\r\n const header = GetTGAHeader(data);\r\n\r\n // Assume it's a valid Targa file.\r\n if (header.id_length + offset > data.length) {\r\n Logger.Error(\"Unable to load TGA file - Not enough data\");\r\n return;\r\n }\r\n\r\n // Skip not needed data\r\n offset += header.id_length;\r\n\r\n let use_rle = false;\r\n let use_pal = false;\r\n let use_grey = false;\r\n\r\n // Get some informations.\r\n switch (header.image_type) {\r\n case _TYPE_RLE_INDEXED:\r\n use_rle = true;\r\n // eslint-disable-next-line no-fallthrough\r\n case _TYPE_INDEXED:\r\n use_pal = true;\r\n break;\r\n\r\n case _TYPE_RLE_RGB:\r\n use_rle = true;\r\n // eslint-disable-next-line no-fallthrough\r\n case _TYPE_RGB:\r\n // use_rgb = true;\r\n break;\r\n\r\n case _TYPE_RLE_GREY:\r\n use_rle = true;\r\n // eslint-disable-next-line no-fallthrough\r\n case _TYPE_GREY:\r\n use_grey = true;\r\n break;\r\n }\r\n\r\n let pixel_data;\r\n\r\n // var numAlphaBits = header.flags & 0xf;\r\n const pixel_size = header.pixel_size >> 3;\r\n const pixel_total = header.width * header.height * pixel_size;\r\n\r\n // Read palettes\r\n let palettes;\r\n\r\n if (use_pal) {\r\n palettes = data.subarray(offset, (offset += header.colormap_length * (header.colormap_size >> 3)));\r\n }\r\n\r\n // Read LRE\r\n if (use_rle) {\r\n pixel_data = new Uint8Array(pixel_total);\r\n\r\n let c, count, i;\r\n let localOffset = 0;\r\n const pixels = new Uint8Array(pixel_size);\r\n\r\n while (offset < pixel_total && localOffset < pixel_total) {\r\n c = data[offset++];\r\n count = (c & 0x7f) + 1;\r\n\r\n // RLE pixels\r\n if (c & 0x80) {\r\n // Bind pixel tmp array\r\n for (i = 0; i < pixel_size; ++i) {\r\n pixels[i] = data[offset++];\r\n }\r\n\r\n // Copy pixel array\r\n for (i = 0; i < count; ++i) {\r\n pixel_data.set(pixels, localOffset + i * pixel_size);\r\n }\r\n\r\n localOffset += pixel_size * count;\r\n }\r\n // Raw pixels\r\n else {\r\n count *= pixel_size;\r\n for (i = 0; i < count; ++i) {\r\n pixel_data[localOffset + i] = data[offset++];\r\n }\r\n localOffset += count;\r\n }\r\n }\r\n }\r\n // RAW Pixels\r\n else {\r\n pixel_data = data.subarray(offset, (offset += use_pal ? header.width * header.height : pixel_total));\r\n }\r\n\r\n // Load to texture\r\n let x_start, y_start, x_step, y_step, y_end, x_end;\r\n\r\n switch ((header.flags & _ORIGIN_MASK) >> _ORIGIN_SHIFT) {\r\n default:\r\n case _ORIGIN_UL:\r\n x_start = 0;\r\n x_step = 1;\r\n x_end = header.width;\r\n y_start = 0;\r\n y_step = 1;\r\n y_end = header.height;\r\n break;\r\n\r\n case _ORIGIN_BL:\r\n x_start = 0;\r\n x_step = 1;\r\n x_end = header.width;\r\n y_start = header.height - 1;\r\n y_step = -1;\r\n y_end = -1;\r\n break;\r\n\r\n case _ORIGIN_UR:\r\n x_start = header.width - 1;\r\n x_step = -1;\r\n x_end = -1;\r\n y_start = 0;\r\n y_step = 1;\r\n y_end = header.height;\r\n break;\r\n\r\n case _ORIGIN_BR:\r\n x_start = header.width - 1;\r\n x_step = -1;\r\n x_end = -1;\r\n y_start = header.height - 1;\r\n y_step = -1;\r\n y_end = -1;\r\n break;\r\n }\r\n\r\n // Load the specify method\r\n const func = \"_getImageData\" + (use_grey ? \"Grey\" : \"\") + header.pixel_size + \"bits\";\r\n const imageData = (TGATools)[func](header, palettes, pixel_data, y_start, y_step, y_end, x_start, x_step, x_end);\r\n\r\n const engine = texture.getEngine();\r\n engine._uploadDataToTextureDirectly(texture, imageData);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nfunction _getImageData8bits(\r\n header: any,\r\n palettes: Uint8Array,\r\n pixel_data: Uint8Array,\r\n y_start: number,\r\n y_step: number,\r\n y_end: number,\r\n x_start: number,\r\n x_step: number,\r\n x_end: number\r\n): Uint8Array {\r\n const image = pixel_data,\r\n colormap = palettes;\r\n const width = header.width,\r\n height = header.height;\r\n let color,\r\n i = 0,\r\n x,\r\n y;\r\n\r\n const imageData = new Uint8Array(width * height * 4);\r\n\r\n for (y = y_start; y !== y_end; y += y_step) {\r\n for (x = x_start; x !== x_end; x += x_step, i++) {\r\n color = image[i];\r\n imageData[(x + width * y) * 4 + 3] = 255;\r\n imageData[(x + width * y) * 4 + 2] = colormap[color * 3 + 0];\r\n imageData[(x + width * y) * 4 + 1] = colormap[color * 3 + 1];\r\n imageData[(x + width * y) * 4 + 0] = colormap[color * 3 + 2];\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nfunction _getImageData16bits(\r\n header: any,\r\n palettes: Uint8Array,\r\n pixel_data: Uint8Array,\r\n y_start: number,\r\n y_step: number,\r\n y_end: number,\r\n x_start: number,\r\n x_step: number,\r\n x_end: number\r\n): Uint8Array {\r\n const image = pixel_data;\r\n const width = header.width,\r\n height = header.height;\r\n let color,\r\n i = 0,\r\n x,\r\n y;\r\n\r\n const imageData = new Uint8Array(width * height * 4);\r\n\r\n for (y = y_start; y !== y_end; y += y_step) {\r\n for (x = x_start; x !== x_end; x += x_step, i += 2) {\r\n color = image[i + 0] + (image[i + 1] << 8); // Inversed ?\r\n const r = ((((color & 0x7c00) >> 10) * 255) / 0x1f) | 0;\r\n const g = ((((color & 0x03e0) >> 5) * 255) / 0x1f) | 0;\r\n const b = (((color & 0x001f) * 255) / 0x1f) | 0;\r\n\r\n imageData[(x + width * y) * 4 + 0] = r;\r\n imageData[(x + width * y) * 4 + 1] = g;\r\n imageData[(x + width * y) * 4 + 2] = b;\r\n imageData[(x + width * y) * 4 + 3] = color & 0x8000 ? 0 : 255;\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nfunction _getImageData24bits(\r\n header: any,\r\n palettes: Uint8Array,\r\n pixel_data: Uint8Array,\r\n y_start: number,\r\n y_step: number,\r\n y_end: number,\r\n x_start: number,\r\n x_step: number,\r\n x_end: number\r\n): Uint8Array {\r\n const image = pixel_data;\r\n const width = header.width,\r\n height = header.height;\r\n let i = 0,\r\n x,\r\n y;\r\n\r\n const imageData = new Uint8Array(width * height * 4);\r\n\r\n for (y = y_start; y !== y_end; y += y_step) {\r\n for (x = x_start; x !== x_end; x += x_step, i += 3) {\r\n imageData[(x + width * y) * 4 + 3] = 255;\r\n imageData[(x + width * y) * 4 + 2] = image[i + 0];\r\n imageData[(x + width * y) * 4 + 1] = image[i + 1];\r\n imageData[(x + width * y) * 4 + 0] = image[i + 2];\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nfunction _getImageData32bits(\r\n header: any,\r\n palettes: Uint8Array,\r\n pixel_data: Uint8Array,\r\n y_start: number,\r\n y_step: number,\r\n y_end: number,\r\n x_start: number,\r\n x_step: number,\r\n x_end: number\r\n): Uint8Array {\r\n const image = pixel_data;\r\n const width = header.width,\r\n height = header.height;\r\n let i = 0,\r\n x,\r\n y;\r\n\r\n const imageData = new Uint8Array(width * height * 4);\r\n\r\n for (y = y_start; y !== y_end; y += y_step) {\r\n for (x = x_start; x !== x_end; x += x_step, i += 4) {\r\n imageData[(x + width * y) * 4 + 2] = image[i + 0];\r\n imageData[(x + width * y) * 4 + 1] = image[i + 1];\r\n imageData[(x + width * y) * 4 + 0] = image[i + 2];\r\n imageData[(x + width * y) * 4 + 3] = image[i + 3];\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nfunction _getImageDataGrey8bits(\r\n header: any,\r\n palettes: Uint8Array,\r\n pixel_data: Uint8Array,\r\n y_start: number,\r\n y_step: number,\r\n y_end: number,\r\n x_start: number,\r\n x_step: number,\r\n x_end: number\r\n): Uint8Array {\r\n const image = pixel_data;\r\n const width = header.width,\r\n height = header.height;\r\n let color,\r\n i = 0,\r\n x,\r\n y;\r\n\r\n const imageData = new Uint8Array(width * height * 4);\r\n\r\n for (y = y_start; y !== y_end; y += y_step) {\r\n for (x = x_start; x !== x_end; x += x_step, i++) {\r\n color = image[i];\r\n imageData[(x + width * y) * 4 + 0] = color;\r\n imageData[(x + width * y) * 4 + 1] = color;\r\n imageData[(x + width * y) * 4 + 2] = color;\r\n imageData[(x + width * y) * 4 + 3] = 255;\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nfunction _getImageDataGrey16bits(\r\n header: any,\r\n palettes: Uint8Array,\r\n pixel_data: Uint8Array,\r\n y_start: number,\r\n y_step: number,\r\n y_end: number,\r\n x_start: number,\r\n x_step: number,\r\n x_end: number\r\n): Uint8Array {\r\n const image = pixel_data;\r\n const width = header.width,\r\n height = header.height;\r\n let i = 0,\r\n x,\r\n y;\r\n\r\n const imageData = new Uint8Array(width * height * 4);\r\n\r\n for (y = y_start; y !== y_end; y += y_step) {\r\n for (x = x_start; x !== x_end; x += x_step, i += 2) {\r\n imageData[(x + width * y) * 4 + 0] = image[i + 0];\r\n imageData[(x + width * y) * 4 + 1] = image[i + 0];\r\n imageData[(x + width * y) * 4 + 2] = image[i + 0];\r\n imageData[(x + width * y) * 4 + 3] = image[i + 1];\r\n }\r\n }\r\n\r\n return imageData;\r\n}\r\n\r\n/**\r\n * Based on jsTGALoader - Javascript loader for TGA file\r\n * By Vincent Thibault\r\n * @see http://blog.robrowser.com/javascript-tga-loader.html\r\n */\r\nexport const TGATools = {\r\n /**\r\n * Gets the header of a TGA file\r\n * @param data defines the TGA data\r\n * @returns the header\r\n */\r\n GetTGAHeader,\r\n\r\n /**\r\n * Uploads TGA content to a Babylon Texture\r\n * @internal\r\n */\r\n UploadContent,\r\n\r\n /** @internal */\r\n _getImageData8bits,\r\n\r\n /** @internal */\r\n _getImageData16bits,\r\n /** @internal */\r\n _getImageData24bits,\r\n\r\n /** @internal */\r\n _getImageData32bits,\r\n\r\n /** @internal */\r\n _getImageDataGrey8bits,\r\n /** @internal */\r\n _getImageDataGrey16bits,\r\n};\r\n","import { GetTGAHeader, UploadContent } from \"../../../Misc/tga\";\r\nimport { Engine } from \"../../../Engines/engine\";\r\nimport type { InternalTexture } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IInternalTextureLoader } from \"../../../Materials/Textures/internalTextureLoader\";\r\n\r\n/**\r\n * Implementation of the TGA Texture Loader.\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _TGATextureLoader implements IInternalTextureLoader {\r\n /**\r\n * Defines whether the loader supports cascade loading the different faces.\r\n */\r\n public readonly supportCascades = false;\r\n\r\n /**\r\n * This returns if the loader support the current file information.\r\n * @param extension defines the file extension of the file being loaded\r\n * @returns true if the loader can load the specified file\r\n */\r\n public canLoad(extension: string): boolean {\r\n return extension.endsWith(\".tga\");\r\n }\r\n\r\n /**\r\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\r\n */\r\n public loadCubeData(): void {\r\n throw \".env not supported in Cube.\";\r\n }\r\n\r\n /**\r\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param callback defines the method to call once ready to upload\r\n */\r\n public loadData(\r\n data: ArrayBufferView,\r\n texture: InternalTexture,\r\n callback: (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void) => void\r\n ): void {\r\n const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const header = GetTGAHeader(bytes);\r\n callback(header.width, header.height, texture.generateMipMaps, false, () => {\r\n UploadContent(texture, bytes);\r\n });\r\n }\r\n}\r\n\r\n// Register the loader.\r\nEngine._TextureLoaders.push(new _TGATextureLoader());\r\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../types\";\r\nimport { Tools } from \"./tools\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Info about the .basis files\r\n */\r\nclass BasisFileInfo {\r\n /**\r\n * If the file has alpha\r\n */\r\n public hasAlpha: boolean;\r\n /**\r\n * Info about each image of the basis file\r\n */\r\n public images: Array<{ levels: Array<{ width: number; height: number; transcodedPixels: ArrayBufferView }> }>;\r\n}\r\n\r\n/**\r\n * Result of transcoding a basis file\r\n */\r\nclass TranscodeResult {\r\n /**\r\n * Info about the .basis file\r\n */\r\n public fileInfo: BasisFileInfo;\r\n /**\r\n * Format to use when loading the file\r\n */\r\n public format: number;\r\n}\r\n\r\n/**\r\n * Configuration options for the Basis transcoder\r\n */\r\nexport class BasisTranscodeConfiguration {\r\n /**\r\n * Supported compression formats used to determine the supported output format of the transcoder\r\n */\r\n supportedCompressionFormats?: {\r\n /**\r\n * etc1 compression format\r\n */\r\n etc1?: boolean;\r\n /**\r\n * s3tc compression format\r\n */\r\n s3tc?: boolean;\r\n /**\r\n * pvrtc compression format\r\n */\r\n pvrtc?: boolean;\r\n /**\r\n * etc2 compression format\r\n */\r\n etc2?: boolean;\r\n /**\r\n * astc compression format\r\n */\r\n astc?: boolean;\r\n /**\r\n * bc7 compression format\r\n */\r\n bc7?: boolean;\r\n };\r\n /**\r\n * If mipmap levels should be loaded for transcoded images (Default: true)\r\n */\r\n loadMipmapLevels?: boolean;\r\n /**\r\n * Index of a single image to load (Default: all images)\r\n */\r\n loadSingleImage?: number;\r\n}\r\n\r\n/**\r\n * @internal\r\n * Enum of basis transcoder formats\r\n */\r\nenum BASIS_FORMATS {\r\n cTFETC1 = 0,\r\n cTFETC2 = 1,\r\n cTFBC1 = 2,\r\n cTFBC3 = 3,\r\n cTFBC4 = 4,\r\n cTFBC5 = 5,\r\n cTFBC7 = 6,\r\n cTFPVRTC1_4_RGB = 8,\r\n cTFPVRTC1_4_RGBA = 9,\r\n cTFASTC_4x4 = 10,\r\n cTFATC_RGB = 11,\r\n cTFATC_RGBA_INTERPOLATED_ALPHA = 12,\r\n cTFRGBA32 = 13,\r\n cTFRGB565 = 14,\r\n cTFBGR565 = 15,\r\n cTFRGBA4444 = 16,\r\n cTFFXT1_RGB = 17,\r\n cTFPVRTC2_4_RGB = 18,\r\n cTFPVRTC2_4_RGBA = 19,\r\n cTFETC2_EAC_R11 = 20,\r\n cTFETC2_EAC_RG11 = 21,\r\n}\r\n\r\n/**\r\n * Used to load .Basis files\r\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\r\n */\r\nexport const BasisToolsOptions = {\r\n /**\r\n * URL to use when loading the basis transcoder\r\n */\r\n JSModuleURL: \"https://cdn.babylonjs.com/basisTranscoder/1/basis_transcoder.js\",\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n WasmModuleURL: \"https://cdn.babylonjs.com/basisTranscoder/1/basis_transcoder.wasm\",\r\n};\r\n\r\n/**\r\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\r\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\r\n * @param engine\r\n * @returns internal format corresponding to the Basis format\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport const GetInternalFormatFromBasisFormat = (basisFormat: number, engine: Engine) => {\r\n let format;\r\n switch (basisFormat) {\r\n case BASIS_FORMATS.cTFETC1:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL;\r\n break;\r\n case BASIS_FORMATS.cTFBC1:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1;\r\n break;\r\n case BASIS_FORMATS.cTFBC4:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5;\r\n break;\r\n case BASIS_FORMATS.cTFASTC_4x4:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4;\r\n break;\r\n case BASIS_FORMATS.cTFETC2:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC;\r\n break;\r\n case BASIS_FORMATS.cTFBC7:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM;\r\n break;\r\n }\r\n\r\n if (format === undefined) {\r\n throw \"The chosen Basis transcoder format is not currently supported\";\r\n }\r\n\r\n return format;\r\n};\r\n\r\nlet _WorkerPromise: Nullable> = null;\r\nlet _Worker: Nullable = null;\r\nlet _actionId = 0;\r\nconst _IgnoreSupportedFormats = false;\r\nconst _CreateWorkerAsync = () => {\r\n if (!_WorkerPromise) {\r\n _WorkerPromise = new Promise((res, reject) => {\r\n if (_Worker) {\r\n res(_Worker);\r\n } else {\r\n Tools.LoadFileAsync(BasisToolsOptions.WasmModuleURL)\r\n .then((wasmBinary) => {\r\n if (typeof URL !== \"function\") {\r\n return reject(\"Basis transcoder requires an environment with a URL constructor\");\r\n }\r\n const workerBlobUrl = URL.createObjectURL(new Blob([`(${workerFunc})()`], { type: \"application/javascript\" }));\r\n _Worker = new Worker(workerBlobUrl);\r\n\r\n const initHandler = (msg: any) => {\r\n if (msg.data.action === \"init\") {\r\n _Worker!.removeEventListener(\"message\", initHandler);\r\n res(_Worker!);\r\n } else if (msg.data.action === \"error\") {\r\n reject(msg.data.error || \"error initializing worker\");\r\n }\r\n };\r\n _Worker.addEventListener(\"message\", initHandler);\r\n _Worker.postMessage({ action: \"init\", url: BasisToolsOptions.JSModuleURL, wasmBinary: wasmBinary });\r\n })\r\n .catch(reject);\r\n }\r\n });\r\n }\r\n return _WorkerPromise;\r\n};\r\n\r\n/**\r\n * Transcodes a loaded image file to compressed pixel data\r\n * @param data image data to transcode\r\n * @param config configuration options for the transcoding\r\n * @returns a promise resulting in the transcoded image\r\n */\r\nexport const TranscodeAsync = (data: ArrayBuffer | ArrayBufferView, config: BasisTranscodeConfiguration): Promise => {\r\n const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;\r\n\r\n return new Promise((res, rej) => {\r\n _CreateWorkerAsync().then(\r\n () => {\r\n const actionId = _actionId++;\r\n const messageHandler = (msg: any) => {\r\n if (msg.data.action === \"transcode\" && msg.data.id === actionId) {\r\n _Worker!.removeEventListener(\"message\", messageHandler);\r\n if (!msg.data.success) {\r\n rej(\"Transcode is not supported on this device\");\r\n } else {\r\n res(msg.data);\r\n }\r\n }\r\n };\r\n _Worker!.addEventListener(\"message\", messageHandler);\r\n\r\n const dataViewCopy = new Uint8Array(dataView.byteLength);\r\n dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));\r\n _Worker!.postMessage({ action: \"transcode\", id: actionId, imageData: dataViewCopy, config: config, ignoreSupportedFormats: _IgnoreSupportedFormats }, [\r\n dataViewCopy.buffer,\r\n ]);\r\n },\r\n (error) => {\r\n rej(error);\r\n }\r\n );\r\n });\r\n};\r\n\r\n/**\r\n * Binds a texture according to its underlying target.\r\n * @param texture texture to bind\r\n * @param engine the engine to bind the texture in\r\n */\r\nconst BindTexture = (texture: InternalTexture, engine: Engine): void => {\r\n let target: GLenum = engine._gl?.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = engine._gl?.TEXTURE_CUBE_MAP;\r\n }\r\n\r\n engine._bindTextureDirectly(target, texture, true);\r\n};\r\n\r\n/**\r\n * Loads a texture from the transcode result\r\n * @param texture texture load to\r\n * @param transcodeResult the result of transcoding the basis file to load from\r\n */\r\nexport const LoadTextureFromTranscodeResult = (texture: InternalTexture, transcodeResult: TranscodeResult) => {\r\n const engine = texture.getEngine() as Engine;\r\n for (let i = 0; i < transcodeResult.fileInfo.images.length; i++) {\r\n const rootImage = transcodeResult.fileInfo.images[i].levels[0];\r\n texture._invertVScale = texture.invertY;\r\n if (transcodeResult.format === -1 || transcodeResult.format === BASIS_FORMATS.cTFRGB565) {\r\n // No compatable compressed format found, fallback to RGB\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n texture.format = Constants.TEXTUREFORMAT_RGB;\r\n\r\n if (engine._features.basisNeedsPOT && (Scalar.Log2(rootImage.width) % 1 !== 0 || Scalar.Log2(rootImage.height) % 1 !== 0)) {\r\n // Create non power of two texture\r\n const source = new InternalTexture(engine, InternalTextureSource.Temp);\r\n\r\n texture._invertVScale = texture.invertY;\r\n source.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n source.format = Constants.TEXTUREFORMAT_RGB;\r\n // Fallback requires aligned width/height\r\n source.width = (rootImage.width + 3) & ~3;\r\n source.height = (rootImage.height + 3) & ~3;\r\n BindTexture(source, engine);\r\n engine._uploadDataToTextureDirectly(source, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, Constants.TEXTUREFORMAT_RGB, true);\r\n\r\n // Resize to power of two\r\n engine._rescaleTexture(source, texture, engine.scenes[0], engine._getInternalFormat(Constants.TEXTUREFORMAT_RGB), () => {\r\n engine._releaseTexture(source);\r\n BindTexture(texture, engine);\r\n });\r\n } else {\r\n // Fallback is already inverted\r\n texture._invertVScale = !texture.invertY;\r\n\r\n // Upload directly\r\n texture.width = (rootImage.width + 3) & ~3;\r\n texture.height = (rootImage.height + 3) & ~3;\r\n texture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR;\r\n BindTexture(texture, engine);\r\n engine._uploadDataToTextureDirectly(texture, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, Constants.TEXTUREFORMAT_RGB, true);\r\n }\r\n } else {\r\n texture.width = rootImage.width;\r\n texture.height = rootImage.height;\r\n texture.generateMipMaps = transcodeResult.fileInfo.images[i].levels.length > 1;\r\n\r\n const format = BasisTools.GetInternalFormatFromBasisFormat(transcodeResult.format!, engine);\r\n texture.format = format;\r\n\r\n BindTexture(texture, engine);\r\n\r\n // Upload all mip levels in the file\r\n transcodeResult.fileInfo.images[i].levels.forEach((level: any, index: number) => {\r\n engine._uploadCompressedDataToTextureDirectly(texture, format, level.width, level.height, level.transcodedPixels, i, index);\r\n });\r\n\r\n if (engine._features.basisNeedsPOT && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)) {\r\n Tools.Warn(\r\n \"Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.\"\r\n );\r\n texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture._cachedWrapV = Texture.CLAMP_ADDRESSMODE;\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Used to load .Basis files\r\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\r\n */\r\nexport const BasisTools = {\r\n /**\r\n * URL to use when loading the basis transcoder\r\n */\r\n JSModuleURL: BasisToolsOptions.JSModuleURL,\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n WasmModuleURL: BasisToolsOptions.WasmModuleURL,\r\n\r\n /**\r\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\r\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\r\n * @returns internal format corresponding to the Basis format\r\n */\r\n GetInternalFormatFromBasisFormat,\r\n\r\n /**\r\n * Transcodes a loaded image file to compressed pixel data\r\n * @param data image data to transcode\r\n * @param config configuration options for the transcoding\r\n * @returns a promise resulting in the transcoded image\r\n */\r\n TranscodeAsync,\r\n\r\n /**\r\n * Loads a texture from the transcode result\r\n * @param texture texture load to\r\n * @param transcodeResult the result of transcoding the basis file to load from\r\n */\r\n LoadTextureFromTranscodeResult,\r\n};\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\ndeclare let BASIS: any;\r\nfunction workerFunc(): void {\r\n const _BASIS_FORMAT = {\r\n cTFETC1: 0,\r\n cTFETC2: 1,\r\n cTFBC1: 2,\r\n cTFBC3: 3,\r\n cTFBC4: 4,\r\n cTFBC5: 5,\r\n cTFBC7: 6,\r\n cTFPVRTC1_4_RGB: 8,\r\n cTFPVRTC1_4_RGBA: 9,\r\n cTFASTC_4x4: 10,\r\n cTFATC_RGB: 11,\r\n cTFATC_RGBA_INTERPOLATED_ALPHA: 12,\r\n cTFRGBA32: 13,\r\n cTFRGB565: 14,\r\n cTFBGR565: 15,\r\n cTFRGBA4444: 16,\r\n cTFFXT1_RGB: 17,\r\n cTFPVRTC2_4_RGB: 18,\r\n cTFPVRTC2_4_RGBA: 19,\r\n cTFETC2_EAC_R11: 20,\r\n cTFETC2_EAC_RG11: 21,\r\n };\r\n let transcoderModulePromise: Nullable> = null;\r\n onmessage = (event) => {\r\n if (event.data.action === \"init\") {\r\n // Load the transcoder if it hasn't been yet\r\n if (!transcoderModulePromise) {\r\n // make sure we loaded the script correctly\r\n try {\r\n importScripts(event.data.url);\r\n } catch (e) {\r\n postMessage({ action: \"error\", error: e });\r\n }\r\n transcoderModulePromise = BASIS({\r\n // Override wasm binary\r\n wasmBinary: event.data.wasmBinary,\r\n });\r\n }\r\n if (transcoderModulePromise !== null) {\r\n transcoderModulePromise.then((m) => {\r\n BASIS = m;\r\n m.initializeBasis();\r\n postMessage({ action: \"init\" });\r\n });\r\n }\r\n } else if (event.data.action === \"transcode\") {\r\n // Transcode the basis image and return the resulting pixels\r\n const config: BasisTranscodeConfiguration = event.data.config;\r\n const imgData = event.data.imageData;\r\n const loadedFile = new BASIS.BasisFile(imgData);\r\n const fileInfo = GetFileInfo(loadedFile);\r\n let format = event.data.ignoreSupportedFormats ? null : GetSupportedTranscodeFormat(event.data.config, fileInfo);\r\n\r\n let needsConversion = false;\r\n if (format === null) {\r\n needsConversion = true;\r\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;\r\n }\r\n\r\n // Begin transcode\r\n let success = true;\r\n if (!loadedFile.startTranscoding()) {\r\n success = false;\r\n }\r\n\r\n const buffers: Array = [];\r\n for (let imageIndex = 0; imageIndex < fileInfo.images.length; imageIndex++) {\r\n if (!success) {\r\n break;\r\n }\r\n const image = fileInfo.images[imageIndex];\r\n if (config.loadSingleImage === undefined || config.loadSingleImage === imageIndex) {\r\n let mipCount = image.levels.length;\r\n if (config.loadMipmapLevels === false) {\r\n mipCount = 1;\r\n }\r\n for (let levelIndex = 0; levelIndex < mipCount; levelIndex++) {\r\n const levelInfo = image.levels[levelIndex];\r\n\r\n const pixels = TranscodeLevel(loadedFile, imageIndex, levelIndex, format!, needsConversion);\r\n if (!pixels) {\r\n success = false;\r\n break;\r\n }\r\n levelInfo.transcodedPixels = pixels;\r\n buffers.push(levelInfo.transcodedPixels.buffer);\r\n }\r\n }\r\n }\r\n // Close file\r\n loadedFile.close();\r\n loadedFile.delete();\r\n\r\n if (needsConversion) {\r\n format = -1;\r\n }\r\n if (!success) {\r\n postMessage({ action: \"transcode\", success: success, id: event.data.id });\r\n } else {\r\n postMessage({ action: \"transcode\", success: success, id: event.data.id, fileInfo: fileInfo, format: format }, buffers);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Detects the supported transcode format for the file\r\n * @param config transcode config\r\n * @param fileInfo info about the file\r\n * @returns the chosed format or null if none are supported\r\n */\r\n function GetSupportedTranscodeFormat(config: BasisTranscodeConfiguration, fileInfo: BasisFileInfo): Nullable {\r\n let format = null;\r\n if (config.supportedCompressionFormats) {\r\n if (config.supportedCompressionFormats.astc) {\r\n format = _BASIS_FORMAT.cTFASTC_4x4;\r\n } else if (config.supportedCompressionFormats.bc7) {\r\n format = _BASIS_FORMAT.cTFBC7;\r\n } else if (config.supportedCompressionFormats.s3tc) {\r\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;\r\n } else if (config.supportedCompressionFormats.pvrtc) {\r\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFPVRTC1_4_RGBA : _BASIS_FORMAT.cTFPVRTC1_4_RGB;\r\n } else if (config.supportedCompressionFormats.etc2) {\r\n format = _BASIS_FORMAT.cTFETC2;\r\n } else if (config.supportedCompressionFormats.etc1) {\r\n format = _BASIS_FORMAT.cTFETC1;\r\n } else {\r\n format = _BASIS_FORMAT.cTFRGB565;\r\n }\r\n }\r\n return format;\r\n }\r\n\r\n /**\r\n * Retrieves information about the basis file eg. dimensions\r\n * @param basisFile the basis file to get the info from\r\n * @returns information about the basis file\r\n */\r\n function GetFileInfo(basisFile: any): BasisFileInfo {\r\n const hasAlpha = basisFile.getHasAlpha();\r\n const imageCount = basisFile.getNumImages();\r\n const images = [];\r\n for (let i = 0; i < imageCount; i++) {\r\n const imageInfo = {\r\n levels: [] as Array,\r\n };\r\n const levelCount = basisFile.getNumLevels(i);\r\n for (let level = 0; level < levelCount; level++) {\r\n const levelInfo = {\r\n width: basisFile.getImageWidth(i, level),\r\n height: basisFile.getImageHeight(i, level),\r\n };\r\n imageInfo.levels.push(levelInfo);\r\n }\r\n images.push(imageInfo);\r\n }\r\n const info = { hasAlpha, images };\r\n return info;\r\n }\r\n\r\n function TranscodeLevel(loadedFile: any, imageIndex: number, levelIndex: number, format: number, convertToRgb565: boolean): Nullable {\r\n const dstSize = loadedFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, format);\r\n let dst: Uint8Array | Uint16Array = new Uint8Array(dstSize);\r\n if (!loadedFile.transcodeImage(dst, imageIndex, levelIndex, format, 1, 0)) {\r\n return null;\r\n }\r\n // If no supported format is found, load as dxt and convert to rgb565\r\n if (convertToRgb565) {\r\n const alignedWidth = (loadedFile.getImageWidth(imageIndex, levelIndex) + 3) & ~3;\r\n const alignedHeight = (loadedFile.getImageHeight(imageIndex, levelIndex) + 3) & ~3;\r\n dst = ConvertDxtToRgb565(dst, 0, alignedWidth, alignedHeight);\r\n }\r\n return dst;\r\n }\r\n\r\n /**\r\n * From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js\r\n * An unoptimized version of dxtToRgb565. Also, the floating\r\n * point math used to compute the colors actually results in\r\n * slightly different colors compared to hardware DXT decoders.\r\n * @param src dxt src pixels\r\n * @param srcByteOffset offset for the start of src\r\n * @param width aligned width of the image\r\n * @param height aligned height of the image\r\n * @returns the converted pixels\r\n */\r\n function ConvertDxtToRgb565(src: Uint8Array, srcByteOffset: number, width: number, height: number): Uint16Array {\r\n const c = new Uint16Array(4);\r\n const dst = new Uint16Array(width * height);\r\n\r\n const blockWidth = width / 4;\r\n const blockHeight = height / 4;\r\n for (let blockY = 0; blockY < blockHeight; blockY++) {\r\n for (let blockX = 0; blockX < blockWidth; blockX++) {\r\n const i = srcByteOffset + 8 * (blockY * blockWidth + blockX);\r\n c[0] = src[i] | (src[i + 1] << 8);\r\n c[1] = src[i + 2] | (src[i + 3] << 8);\r\n c[2] =\r\n ((2 * (c[0] & 0x1f) + 1 * (c[1] & 0x1f)) / 3) |\r\n (((2 * (c[0] & 0x7e0) + 1 * (c[1] & 0x7e0)) / 3) & 0x7e0) |\r\n (((2 * (c[0] & 0xf800) + 1 * (c[1] & 0xf800)) / 3) & 0xf800);\r\n c[3] =\r\n ((2 * (c[1] & 0x1f) + 1 * (c[0] & 0x1f)) / 3) |\r\n (((2 * (c[1] & 0x7e0) + 1 * (c[0] & 0x7e0)) / 3) & 0x7e0) |\r\n (((2 * (c[1] & 0xf800) + 1 * (c[0] & 0xf800)) / 3) & 0xf800);\r\n for (let row = 0; row < 4; row++) {\r\n const m = src[i + 4 + row];\r\n let dstI = (blockY * 4 + row) * width + blockX * 4;\r\n dst[dstI++] = c[m & 0x3];\r\n dst[dstI++] = c[(m >> 2) & 0x3];\r\n dst[dstI++] = c[(m >> 4) & 0x3];\r\n dst[dstI++] = c[(m >> 6) & 0x3];\r\n }\r\n }\r\n }\r\n return dst;\r\n }\r\n}\r\n\r\nObject.defineProperty(BasisTools, \"JSModuleURL\", {\r\n get: function (this: null) {\r\n return BasisToolsOptions.JSModuleURL;\r\n },\r\n set: function (this: null, value: string) {\r\n BasisToolsOptions.JSModuleURL = value;\r\n },\r\n});\r\n\r\nObject.defineProperty(BasisTools, \"WasmModuleURL\", {\r\n get: function (this: null) {\r\n return BasisToolsOptions.WasmModuleURL;\r\n },\r\n set: function (this: null, value: string) {\r\n BasisToolsOptions.WasmModuleURL = value;\r\n },\r\n});\r\n","import { HDRTools } from \"../../../Misc/HighDynamicRange/hdr\";\r\nimport { Engine } from \"../../../Engines/engine\";\r\nimport type { InternalTexture } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IInternalTextureLoader } from \"../../../Materials/Textures/internalTextureLoader\";\r\nimport { Constants } from \"../../../Engines/constants\";\r\n\r\n/**\r\n * Implementation of the HDR Texture Loader.\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _HDRTextureLoader implements IInternalTextureLoader {\r\n /**\r\n * Defines whether the loader supports cascade loading the different faces.\r\n */\r\n public readonly supportCascades = false;\r\n\r\n /**\r\n * This returns if the loader support the current file information.\r\n * @param extension defines the file extension of the file being loaded\r\n * @returns true if the loader can load the specified file\r\n */\r\n public canLoad(extension: string): boolean {\r\n return extension.endsWith(\".hdr\");\r\n }\r\n\r\n /**\r\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\r\n */\r\n public loadCubeData(): void {\r\n throw \".env not supported in Cube.\";\r\n }\r\n\r\n /**\r\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param callback defines the method to call once ready to upload\r\n */\r\n public loadData(\r\n data: ArrayBufferView,\r\n texture: InternalTexture,\r\n callback: (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void) => void\r\n ): void {\r\n const uint8array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\r\n const hdrInfo = HDRTools.RGBE_ReadHeader(uint8array);\r\n const pixelsDataRGB32 = HDRTools.RGBE_ReadPixels(uint8array, hdrInfo);\r\n\r\n const pixels = hdrInfo.width * hdrInfo.height;\r\n const pixelsDataRGBA32 = new Float32Array(pixels * 4);\r\n for (let i = 0; i < pixels; i += 1) {\r\n pixelsDataRGBA32[i * 4] = pixelsDataRGB32[i * 3];\r\n pixelsDataRGBA32[i * 4 + 1] = pixelsDataRGB32[i * 3 + 1];\r\n pixelsDataRGBA32[i * 4 + 2] = pixelsDataRGB32[i * 3 + 2];\r\n pixelsDataRGBA32[i * 4 + 3] = 1;\r\n }\r\n\r\n callback(hdrInfo.width, hdrInfo.height, texture.generateMipMaps, false, () => {\r\n const engine = texture.getEngine();\r\n texture.type = Constants.TEXTURETYPE_FLOAT;\r\n texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n texture._gammaSpace = false;\r\n engine._uploadDataToTextureDirectly(texture, pixelsDataRGBA32);\r\n });\r\n }\r\n}\r\n\r\n// Register the loader.\r\nEngine._TextureLoaders.push(new _HDRTextureLoader());\r\n","import type { Nullable } from \"../../../types\";\r\nimport { Engine } from \"../../../Engines/engine\";\r\nimport type { InternalTexture } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IInternalTextureLoader } from \"../../../Materials/Textures/internalTextureLoader\";\r\nimport { LoadTextureFromTranscodeResult, TranscodeAsync } from \"../../../Misc/basis\";\r\nimport { Tools } from \"../../../Misc/tools\";\r\n\r\n/**\r\n * Loader for .basis file format\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class _BasisTextureLoader implements IInternalTextureLoader {\r\n /**\r\n * Defines whether the loader supports cascade loading the different faces.\r\n */\r\n public readonly supportCascades = false;\r\n\r\n /**\r\n * This returns if the loader support the current file information.\r\n * @param extension defines the file extension of the file being loaded\r\n * @returns true if the loader can load the specified file\r\n */\r\n public canLoad(extension: string): boolean {\r\n return extension.endsWith(\".basis\");\r\n }\r\n\r\n /**\r\n * Uploads the cube texture data to the WebGL texture. It has already been bound.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param createPolynomials will be true if polynomials have been requested\r\n * @param onLoad defines the callback to trigger once the texture is ready\r\n * @param onError defines the callback to trigger in case of error\r\n */\r\n public loadCubeData(\r\n data: ArrayBufferView | ArrayBufferView[],\r\n texture: InternalTexture,\r\n createPolynomials: boolean,\r\n onLoad: Nullable<(data?: any) => void>,\r\n onError: Nullable<(message?: string, exception?: any) => void>\r\n ): void {\r\n if (Array.isArray(data)) {\r\n return;\r\n }\r\n const caps = texture.getEngine().getCaps();\r\n const transcodeConfig = {\r\n supportedCompressionFormats: {\r\n etc1: caps.etc1 ? true : false,\r\n s3tc: caps.s3tc ? true : false,\r\n pvrtc: caps.pvrtc ? true : false,\r\n etc2: caps.etc2 ? true : false,\r\n astc: caps.astc ? true : false,\r\n bc7: caps.bptc ? true : false,\r\n },\r\n };\r\n TranscodeAsync(data, transcodeConfig)\r\n .then((result) => {\r\n const hasMipmap = result.fileInfo.images[0].levels.length > 1 && texture.generateMipMaps;\r\n LoadTextureFromTranscodeResult(texture, result);\r\n (texture.getEngine() as Engine)._setCubeMapTextureParams(texture, hasMipmap);\r\n texture.isReady = true;\r\n texture.onLoadedObservable.notifyObservers(texture);\r\n texture.onLoadedObservable.clear();\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n })\r\n .catch((err) => {\r\n const errorMessage = \"Failed to transcode Basis file, transcoding may not be supported on this device\";\r\n Tools.Warn(errorMessage);\r\n texture.isReady = true;\r\n if (onError) {\r\n onError(err);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.\r\n * @param data contains the texture data\r\n * @param texture defines the BabylonJS internal texture\r\n * @param callback defines the method to call once ready to upload\r\n */\r\n public loadData(\r\n data: ArrayBufferView,\r\n texture: InternalTexture,\r\n callback: (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void, failedLoading?: boolean) => void\r\n ): void {\r\n const caps = texture.getEngine().getCaps();\r\n const transcodeConfig = {\r\n supportedCompressionFormats: {\r\n etc1: caps.etc1 ? true : false,\r\n s3tc: caps.s3tc ? true : false,\r\n pvrtc: caps.pvrtc ? true : false,\r\n etc2: caps.etc2 ? true : false,\r\n astc: caps.astc ? true : false,\r\n bc7: caps.bptc ? true : false,\r\n },\r\n };\r\n TranscodeAsync(data, transcodeConfig)\r\n .then((result) => {\r\n const rootImage = result.fileInfo.images[0].levels[0];\r\n const hasMipmap = result.fileInfo.images[0].levels.length > 1 && texture.generateMipMaps;\r\n callback(rootImage.width, rootImage.height, hasMipmap, result.format !== -1, () => {\r\n LoadTextureFromTranscodeResult(texture, result);\r\n });\r\n })\r\n .catch((err) => {\r\n Tools.Warn(\"Failed to transcode Basis file, transcoding may not be supported on this device\");\r\n Tools.Warn(`Failed to transcode Basis file: ${err}`);\r\n callback(0, 0, false, false, () => {}, true);\r\n });\r\n }\r\n}\r\n\r\n// Register the loader.\r\nEngine._TextureLoaders.push(new _BasisTextureLoader());\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"noisePixelShader\";\nconst shader = `uniform float brightness;uniform float persistence;uniform float timeScale;varying vec2 vUV;vec2 hash22(vec2 p)\n{p=p*mat2(127.1,311.7,269.5,183.3);p=-1.0+2.0*fract(sin(p)*43758.5453123);return sin(p*6.283+timeScale);}\nfloat interpolationNoise(vec2 p)\n{vec2 pi=floor(p);vec2 pf=p-pi;vec2 w=pf*pf*(3.-2.*pf);float f00=dot(hash22(pi+vec2(.0,.0)),pf-vec2(.0,.0));float f01=dot(hash22(pi+vec2(.0,1.)),pf-vec2(.0,1.));float f10=dot(hash22(pi+vec2(1.0,0.)),pf-vec2(1.0,0.));float f11=dot(hash22(pi+vec2(1.0,1.)),pf-vec2(1.0,1.));float xm1=mix(f00,f10,w.x);float xm2=mix(f01,f11,w.x);float ym=mix(xm1,xm2,w.y); \nreturn ym;}\nfloat perlinNoise2D(float x,float y)\n{float sum=0.0;float frequency=0.0;float amplitude=0.0;for(int i=0; i = EngineStore.LastCreatedScene, fallbackTexture?: Texture, generateMipMaps?: boolean) {\r\n super(name, size, \"noise\", scene, fallbackTexture, generateMipMaps);\r\n this.autoClear = false;\r\n this._updateShaderUniforms();\r\n }\r\n\r\n private _updateShaderUniforms() {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.time += scene.getAnimationRatio() * this.animationSpeedFactor * 0.01;\r\n\r\n this.setFloat(\"brightness\", this.brightness);\r\n this.setFloat(\"persistence\", this.persistence);\r\n this.setFloat(\"timeScale\", this.time);\r\n }\r\n\r\n protected _getDefines(): string {\r\n return \"#define OCTAVES \" + (this.octaves | 0);\r\n }\r\n\r\n /**\r\n * Generate the current state of the procedural texture\r\n * @param useCameraPostProcess\r\n */\r\n public render(useCameraPostProcess?: boolean) {\r\n this._updateShaderUniforms();\r\n super.render(useCameraPostProcess);\r\n }\r\n\r\n /**\r\n * Serializes this noise procedural texture\r\n * @returns a serialized noise procedural texture object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n serializationObject.customType = \"BABYLON.NoiseProceduralTexture\";\r\n\r\n serializationObject.brightness = this.brightness;\r\n serializationObject.octaves = this.octaves;\r\n serializationObject.persistence = this.persistence;\r\n serializationObject.animationSpeedFactor = this.animationSpeedFactor;\r\n serializationObject.size = this.getSize().width;\r\n serializationObject.generateMipMaps = this._generateMipMaps;\r\n serializationObject.time = this.time;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Clone the texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): NoiseProceduralTexture {\r\n const textureSize = this.getSize();\r\n const newTexture = new NoiseProceduralTexture(\r\n this.name,\r\n textureSize.width,\r\n this.getScene(),\r\n this._fallbackTexture ? this._fallbackTexture : undefined,\r\n this._generateMipMaps\r\n );\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // RenderTarget Texture\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n // Noise Specifics\r\n newTexture.brightness = this.brightness;\r\n newTexture.octaves = this.octaves;\r\n newTexture.persistence = this.persistence;\r\n newTexture.animationSpeedFactor = this.animationSpeedFactor;\r\n newTexture.time = this.time;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Creates a NoiseProceduralTexture from parsed noise procedural texture data\r\n * @param parsedTexture defines parsed texture data\r\n * @param scene defines the current scene\r\n * @returns a parsed NoiseProceduralTexture\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene): NoiseProceduralTexture {\r\n const texture = new NoiseProceduralTexture(parsedTexture.name, parsedTexture.size, scene, undefined, parsedTexture.generateMipMaps);\r\n\r\n texture.brightness = parsedTexture.brightness;\r\n texture.octaves = parsedTexture.octaves;\r\n texture.persistence = parsedTexture.persistence;\r\n texture.animationSpeedFactor = parsedTexture.animationSpeedFactor;\r\n texture.time = parsedTexture.time ?? 0;\r\n\r\n return texture;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.NoiseProceduralTexture\", NoiseProceduralTexture);\r\n","import type { Scene } from \"../../scene\";\r\nimport { Plane } from \"../../Maths/math.plane\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\n/**\r\n * Creates a refraction texture used by refraction channel of the standard material.\r\n * It is like a mirror but to see through a material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#refractiontexture\r\n */\r\nexport class RefractionTexture extends RenderTargetTexture {\r\n /**\r\n * Define the reflection plane we want to use. The refractionPlane is usually set to the constructed refractor.\r\n * It is possible to directly set the refractionPlane by directly using a Plane(a, b, c, d) where a, b and c give the plane normal vector (a, b, c) and d is a scalar displacement from the refractionPlane to the origin. However in all but the very simplest of situations it is more straight forward to set it to the refractor as stated in the doc.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#refraction\r\n */\r\n public refractionPlane = new Plane(0, 1, 0, 1);\r\n\r\n /**\r\n * Define how deep under the surface we should see.\r\n */\r\n public depth = 2.0;\r\n\r\n /**\r\n * Creates a refraction texture used by refraction channel of the standard material.\r\n * It is like a mirror but to see through a material.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#refraction\r\n * @param name Define the texture name\r\n * @param size Define the size of the underlying texture\r\n * @param scene Define the scene the refraction belongs to\r\n * @param generateMipMaps Define if we need to generate mips level for the refraction\r\n */\r\n constructor(name: string, size: number, scene?: Scene, generateMipMaps?: boolean) {\r\n super(name, size, scene, generateMipMaps, true);\r\n\r\n this.onBeforeRenderObservable.add(() => {\r\n this.getScene()!.clipPlane = this.refractionPlane;\r\n });\r\n\r\n this.onAfterRenderObservable.add(() => {\r\n this.getScene()!.clipPlane = null;\r\n });\r\n }\r\n\r\n /**\r\n * Clone the refraction texture.\r\n * @returns the cloned texture\r\n */\r\n public clone(): RefractionTexture {\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const textureSize = this.getSize();\r\n const newTexture = new RefractionTexture(this.name, textureSize.width, scene, this._generateMipMaps);\r\n\r\n // Base texture\r\n newTexture.hasAlpha = this.hasAlpha;\r\n newTexture.level = this.level;\r\n\r\n // Refraction Texture\r\n newTexture.refractionPlane = this.refractionPlane.clone();\r\n if (this.renderList) {\r\n newTexture.renderList = this.renderList.slice(0);\r\n }\r\n newTexture.depth = this.depth;\r\n\r\n return newTexture;\r\n }\r\n\r\n /**\r\n * Serialize the texture to a JSON representation you could use in Parse later on\r\n * @returns the serialized JSON representation\r\n */\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.mirrorPlane = this.refractionPlane.asArray();\r\n serializationObject.depth = this.depth;\r\n\r\n return serializationObject;\r\n }\r\n}\r\n","// DEFLATE is a complex format; to read this code, you should probably check the RFC first:\n// https://tools.ietf.org/html/rfc1951\n// You may also wish to take a look at the guide I made about this program:\n// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad\n// Some of the following code is similar to that of UZIP.js:\n// https://github.com/photopea/UZIP.js\n// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.\n// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint\n// is better for memory in most engines (I *think*).\nvar ch2 = {};\nvar wk = (function (c, id, msg, transfer, cb) {\n var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([\n c + ';addEventListener(\"error\",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'\n ], { type: 'text/javascript' }))));\n w.onmessage = function (e) {\n var d = e.data, ed = d.$e$;\n if (ed) {\n var err = new Error(ed[0]);\n err['code'] = ed[1];\n err.stack = ed[2];\n cb(err, null);\n }\n else\n cb(null, d);\n };\n w.postMessage(msg, transfer);\n return w;\n});\n\n// aliases for shorter compressed code (most minifers don't do this)\nvar u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;\n// fixed length extra bits\nvar fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);\n// fixed distance extra bits\n// see fleb note\nvar fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);\n// code length index map\nvar clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);\n// get base, reverse index map from extra bits\nvar freb = function (eb, start) {\n var b = new u16(31);\n for (var i = 0; i < 31; ++i) {\n b[i] = start += 1 << eb[i - 1];\n }\n // numbers here are at max 18 bits\n var r = new u32(b[30]);\n for (var i = 1; i < 30; ++i) {\n for (var j = b[i]; j < b[i + 1]; ++j) {\n r[j] = ((j - b[i]) << 5) | i;\n }\n }\n return [b, r];\n};\nvar _a = freb(fleb, 2), fl = _a[0], revfl = _a[1];\n// we can ignore the fact that the other numbers are wrong; they never happen anyway\nfl[28] = 258, revfl[258] = 28;\nvar _b = freb(fdeb, 0), fd = _b[0], revfd = _b[1];\n// map of value to reverse (assuming 16 bits)\nvar rev = new u16(32768);\nfor (var i = 0; i < 32768; ++i) {\n // reverse table algorithm from SO\n var x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);\n x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);\n x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);\n rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;\n}\n// create huffman tree from u8 \"map\": index -> code length for code index\n// mb (max bits) must be at most 15\n// TODO: optimize/split up?\nvar hMap = (function (cd, mb, r) {\n var s = cd.length;\n // index\n var i = 0;\n // u16 \"map\": index -> # of codes with bit length = index\n var l = new u16(mb);\n // length of cd must be 288 (total # of codes)\n for (; i < s; ++i) {\n if (cd[i])\n ++l[cd[i] - 1];\n }\n // u16 \"map\": index -> minimum code for bit length = index\n var le = new u16(mb);\n for (i = 0; i < mb; ++i) {\n le[i] = (le[i - 1] + l[i - 1]) << 1;\n }\n var co;\n if (r) {\n // u16 \"map\": index -> number of actual bits, symbol for code\n co = new u16(1 << mb);\n // bits to remove for reverser\n var rvb = 15 - mb;\n for (i = 0; i < s; ++i) {\n // ignore 0 lengths\n if (cd[i]) {\n // num encoding both symbol and bits read\n var sv = (i << 4) | cd[i];\n // free bits\n var r_1 = mb - cd[i];\n // start value\n var v = le[cd[i] - 1]++ << r_1;\n // m is end value\n for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {\n // every 16 bit value starting with the code yields the same result\n co[rev[v] >>> rvb] = sv;\n }\n }\n }\n }\n else {\n co = new u16(s);\n for (i = 0; i < s; ++i) {\n if (cd[i]) {\n co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);\n }\n }\n }\n return co;\n});\n// fixed length tree\nvar flt = new u8(288);\nfor (var i = 0; i < 144; ++i)\n flt[i] = 8;\nfor (var i = 144; i < 256; ++i)\n flt[i] = 9;\nfor (var i = 256; i < 280; ++i)\n flt[i] = 7;\nfor (var i = 280; i < 288; ++i)\n flt[i] = 8;\n// fixed distance tree\nvar fdt = new u8(32);\nfor (var i = 0; i < 32; ++i)\n fdt[i] = 5;\n// fixed length map\nvar flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);\n// fixed distance map\nvar fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);\n// find max of array\nvar max = function (a) {\n var m = a[0];\n for (var i = 1; i < a.length; ++i) {\n if (a[i] > m)\n m = a[i];\n }\n return m;\n};\n// read d, starting at bit p and mask with m\nvar bits = function (d, p, m) {\n var o = (p / 8) | 0;\n return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;\n};\n// read d, starting at bit p continuing for at least 16 bits\nvar bits16 = function (d, p) {\n var o = (p / 8) | 0;\n return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));\n};\n// get end of byte\nvar shft = function (p) { return ((p + 7) / 8) | 0; };\n// typed array slice - allows garbage collector to free original reference,\n// while being more compatible than .slice\nvar slc = function (v, s, e) {\n if (s == null || s < 0)\n s = 0;\n if (e == null || e > v.length)\n e = v.length;\n // can't use .constructor in case user-supplied\n var n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s);\n n.set(v.subarray(s, e));\n return n;\n};\n/**\n * Codes for errors generated within this library\n */\nexport var FlateErrorCode = {\n UnexpectedEOF: 0,\n InvalidBlockType: 1,\n InvalidLengthLiteral: 2,\n InvalidDistance: 3,\n StreamFinished: 4,\n NoStreamHandler: 5,\n InvalidHeader: 6,\n NoCallback: 7,\n InvalidUTF8: 8,\n ExtraFieldTooLong: 9,\n InvalidDate: 10,\n FilenameTooLong: 11,\n StreamFinishing: 12,\n InvalidZipData: 13,\n UnknownCompressionMethod: 14\n};\n// error codes\nvar ec = [\n 'unexpected EOF',\n 'invalid block type',\n 'invalid length/literal',\n 'invalid distance',\n 'stream finished',\n 'no stream handler',\n ,\n 'no callback',\n 'invalid UTF-8 data',\n 'extra field too long',\n 'date not in range 1980-2099',\n 'filename too long',\n 'stream finishing',\n 'invalid zip data'\n // determined by unknown compression method\n];\n;\nvar err = function (ind, msg, nt) {\n var e = new Error(msg || ec[ind]);\n e.code = ind;\n if (Error.captureStackTrace)\n Error.captureStackTrace(e, err);\n if (!nt)\n throw e;\n return e;\n};\n// expands raw DEFLATE data\nvar inflt = function (dat, buf, st) {\n // source length\n var sl = dat.length;\n if (!sl || (st && st.f && !st.l))\n return buf || new u8(0);\n // have to estimate size\n var noBuf = !buf || st;\n // no state\n var noSt = !st || st.i;\n if (!st)\n st = {};\n // Assumes roughly 33% compression ratio average\n if (!buf)\n buf = new u8(sl * 3);\n // ensure buffer can fit at least l elements\n var cbuf = function (l) {\n var bl = buf.length;\n // need to increase size to fit\n if (l > bl) {\n // Double or set to necessary, whichever is greater\n var nbuf = new u8(Math.max(bl * 2, l));\n nbuf.set(buf);\n buf = nbuf;\n }\n };\n // last chunk bitpos bytes\n var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;\n // total bits\n var tbts = sl * 8;\n do {\n if (!lm) {\n // BFINAL - this is only 1 when last chunk is next\n final = bits(dat, pos, 1);\n // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman\n var type = bits(dat, pos + 1, 3);\n pos += 3;\n if (!type) {\n // go to end of byte boundary\n var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;\n if (t > sl) {\n if (noSt)\n err(0);\n break;\n }\n // ensure size\n if (noBuf)\n cbuf(bt + l);\n // Copy over uncompressed data\n buf.set(dat.subarray(s, t), bt);\n // Get new bitpos, update byte count\n st.b = bt += l, st.p = pos = t * 8, st.f = final;\n continue;\n }\n else if (type == 1)\n lm = flrm, dm = fdrm, lbt = 9, dbt = 5;\n else if (type == 2) {\n // literal lengths\n var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;\n var tl = hLit + bits(dat, pos + 5, 31) + 1;\n pos += 14;\n // length+distance tree\n var ldt = new u8(tl);\n // code length tree\n var clt = new u8(19);\n for (var i = 0; i < hcLen; ++i) {\n // use index map to get real code\n clt[clim[i]] = bits(dat, pos + i * 3, 7);\n }\n pos += hcLen * 3;\n // code lengths bits\n var clb = max(clt), clbmsk = (1 << clb) - 1;\n // code lengths map\n var clm = hMap(clt, clb, 1);\n for (var i = 0; i < tl;) {\n var r = clm[bits(dat, pos, clbmsk)];\n // bits read\n pos += r & 15;\n // symbol\n var s = r >>> 4;\n // code length to copy\n if (s < 16) {\n ldt[i++] = s;\n }\n else {\n // copy count\n var c = 0, n = 0;\n if (s == 16)\n n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];\n else if (s == 17)\n n = 3 + bits(dat, pos, 7), pos += 3;\n else if (s == 18)\n n = 11 + bits(dat, pos, 127), pos += 7;\n while (n--)\n ldt[i++] = c;\n }\n }\n // length tree distance tree\n var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);\n // max length bits\n lbt = max(lt);\n // max dist bits\n dbt = max(dt);\n lm = hMap(lt, lbt, 1);\n dm = hMap(dt, dbt, 1);\n }\n else\n err(1);\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n }\n // Make sure the buffer can hold this + the largest possible addition\n // Maximum chunk size (practically, theoretically infinite) is 2^17;\n if (noBuf)\n cbuf(bt + 131072);\n var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;\n var lpos = pos;\n for (;; lpos = pos) {\n // bits read, code\n var c = lm[bits16(dat, pos) & lms], sym = c >>> 4;\n pos += c & 15;\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n if (!c)\n err(2);\n if (sym < 256)\n buf[bt++] = sym;\n else if (sym == 256) {\n lpos = pos, lm = null;\n break;\n }\n else {\n var add = sym - 254;\n // no extra bits needed if less\n if (sym > 264) {\n // index\n var i = sym - 257, b = fleb[i];\n add = bits(dat, pos, (1 << b) - 1) + fl[i];\n pos += b;\n }\n // dist\n var d = dm[bits16(dat, pos) & dms], dsym = d >>> 4;\n if (!d)\n err(3);\n pos += d & 15;\n var dt = fd[dsym];\n if (dsym > 3) {\n var b = fdeb[dsym];\n dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;\n }\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n if (noBuf)\n cbuf(bt + 131072);\n var end = bt + add;\n for (; bt < end; bt += 4) {\n buf[bt] = buf[bt - dt];\n buf[bt + 1] = buf[bt + 1 - dt];\n buf[bt + 2] = buf[bt + 2 - dt];\n buf[bt + 3] = buf[bt + 3 - dt];\n }\n bt = end;\n }\n }\n st.l = lm, st.p = lpos, st.b = bt, st.f = final;\n if (lm)\n final = 1, st.m = lbt, st.d = dm, st.n = dbt;\n } while (!final);\n return bt == buf.length ? buf : slc(buf, 0, bt);\n};\n// starting at p, write the minimum number of bits that can hold v to d\nvar wbits = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n};\n// starting at p, write the minimum number of bits (>8) that can hold v to d\nvar wbits16 = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n d[o + 2] |= v >>> 16;\n};\n// creates code lengths from a frequency table\nvar hTree = function (d, mb) {\n // Need extra info to make a tree\n var t = [];\n for (var i = 0; i < d.length; ++i) {\n if (d[i])\n t.push({ s: i, f: d[i] });\n }\n var s = t.length;\n var t2 = t.slice();\n if (!s)\n return [et, 0];\n if (s == 1) {\n var v = new u8(t[0].s + 1);\n v[t[0].s] = 1;\n return [v, 1];\n }\n t.sort(function (a, b) { return a.f - b.f; });\n // after i2 reaches last ind, will be stopped\n // freq must be greater than largest possible number of symbols\n t.push({ s: -1, f: 25001 });\n var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;\n t[0] = { s: -1, f: l.f + r.f, l: l, r: r };\n // efficient algorithm from UZIP.js\n // i0 is lookbehind, i2 is lookahead - after processing two low-freq\n // symbols that combined have high freq, will start processing i2 (high-freq,\n // non-composite) symbols instead\n // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/\n while (i1 != s - 1) {\n l = t[t[i0].f < t[i2].f ? i0++ : i2++];\n r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];\n t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };\n }\n var maxSym = t2[0].s;\n for (var i = 1; i < s; ++i) {\n if (t2[i].s > maxSym)\n maxSym = t2[i].s;\n }\n // code lengths\n var tr = new u16(maxSym + 1);\n // max bits in tree\n var mbt = ln(t[i1 - 1], tr, 0);\n if (mbt > mb) {\n // more algorithms from UZIP.js\n // TODO: find out how this code works (debt)\n // ind debt\n var i = 0, dt = 0;\n // left cost\n var lft = mbt - mb, cst = 1 << lft;\n t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });\n for (; i < s; ++i) {\n var i2_1 = t2[i].s;\n if (tr[i2_1] > mb) {\n dt += cst - (1 << (mbt - tr[i2_1]));\n tr[i2_1] = mb;\n }\n else\n break;\n }\n dt >>>= lft;\n while (dt > 0) {\n var i2_2 = t2[i].s;\n if (tr[i2_2] < mb)\n dt -= 1 << (mb - tr[i2_2]++ - 1);\n else\n ++i;\n }\n for (; i >= 0 && dt; --i) {\n var i2_3 = t2[i].s;\n if (tr[i2_3] == mb) {\n --tr[i2_3];\n ++dt;\n }\n }\n mbt = mb;\n }\n return [new u8(tr), mbt];\n};\n// get the max length and assign length codes\nvar ln = function (n, l, d) {\n return n.s == -1\n ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))\n : (l[n.s] = d);\n};\n// length codes generation\nvar lc = function (c) {\n var s = c.length;\n // Note that the semicolon was intentional\n while (s && !c[--s])\n ;\n var cl = new u16(++s);\n // ind num streak\n var cli = 0, cln = c[0], cls = 1;\n var w = function (v) { cl[cli++] = v; };\n for (var i = 1; i <= s; ++i) {\n if (c[i] == cln && i != s)\n ++cls;\n else {\n if (!cln && cls > 2) {\n for (; cls > 138; cls -= 138)\n w(32754);\n if (cls > 2) {\n w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);\n cls = 0;\n }\n }\n else if (cls > 3) {\n w(cln), --cls;\n for (; cls > 6; cls -= 6)\n w(8304);\n if (cls > 2)\n w(((cls - 3) << 5) | 8208), cls = 0;\n }\n while (cls--)\n w(cln);\n cls = 1;\n cln = c[i];\n }\n }\n return [cl.subarray(0, cli), s];\n};\n// calculate the length of output from tree, code lengths\nvar clen = function (cf, cl) {\n var l = 0;\n for (var i = 0; i < cl.length; ++i)\n l += cf[i] * cl[i];\n return l;\n};\n// writes a fixed block\n// returns the new bit pos\nvar wfblk = function (out, pos, dat) {\n // no need to write 00 as type: TypedArray defaults to 0\n var s = dat.length;\n var o = shft(pos + 2);\n out[o] = s & 255;\n out[o + 1] = s >>> 8;\n out[o + 2] = out[o] ^ 255;\n out[o + 3] = out[o + 1] ^ 255;\n for (var i = 0; i < s; ++i)\n out[o + i + 4] = dat[i];\n return (o + 4 + s) * 8;\n};\n// writes a block\nvar wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {\n wbits(out, p++, final);\n ++lf[256];\n var _a = hTree(lf, 15), dlt = _a[0], mlb = _a[1];\n var _b = hTree(df, 15), ddt = _b[0], mdb = _b[1];\n var _c = lc(dlt), lclt = _c[0], nlc = _c[1];\n var _d = lc(ddt), lcdt = _d[0], ndc = _d[1];\n var lcfreq = new u16(19);\n for (var i = 0; i < lclt.length; ++i)\n lcfreq[lclt[i] & 31]++;\n for (var i = 0; i < lcdt.length; ++i)\n lcfreq[lcdt[i] & 31]++;\n var _e = hTree(lcfreq, 7), lct = _e[0], mlcb = _e[1];\n var nlcc = 19;\n for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)\n ;\n var flen = (bl + 5) << 3;\n var ftlen = clen(lf, flt) + clen(df, fdt) + eb;\n var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + (2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18]);\n if (flen <= ftlen && flen <= dtlen)\n return wfblk(out, p, dat.subarray(bs, bs + bl));\n var lm, ll, dm, dl;\n wbits(out, p, 1 + (dtlen < ftlen)), p += 2;\n if (dtlen < ftlen) {\n lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;\n var llm = hMap(lct, mlcb, 0);\n wbits(out, p, nlc - 257);\n wbits(out, p + 5, ndc - 1);\n wbits(out, p + 10, nlcc - 4);\n p += 14;\n for (var i = 0; i < nlcc; ++i)\n wbits(out, p + 3 * i, lct[clim[i]]);\n p += 3 * nlcc;\n var lcts = [lclt, lcdt];\n for (var it = 0; it < 2; ++it) {\n var clct = lcts[it];\n for (var i = 0; i < clct.length; ++i) {\n var len = clct[i] & 31;\n wbits(out, p, llm[len]), p += lct[len];\n if (len > 15)\n wbits(out, p, (clct[i] >>> 5) & 127), p += clct[i] >>> 12;\n }\n }\n }\n else {\n lm = flm, ll = flt, dm = fdm, dl = fdt;\n }\n for (var i = 0; i < li; ++i) {\n if (syms[i] > 255) {\n var len = (syms[i] >>> 18) & 31;\n wbits16(out, p, lm[len + 257]), p += ll[len + 257];\n if (len > 7)\n wbits(out, p, (syms[i] >>> 23) & 31), p += fleb[len];\n var dst = syms[i] & 31;\n wbits16(out, p, dm[dst]), p += dl[dst];\n if (dst > 3)\n wbits16(out, p, (syms[i] >>> 5) & 8191), p += fdeb[dst];\n }\n else {\n wbits16(out, p, lm[syms[i]]), p += ll[syms[i]];\n }\n }\n wbits16(out, p, lm[256]);\n return p + ll[256];\n};\n// deflate options (nice << 13) | chain\nvar deo = /*#__PURE__*/ new u32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);\n// empty\nvar et = /*#__PURE__*/ new u8(0);\n// compresses data into a raw DEFLATE buffer\nvar dflt = function (dat, lvl, plvl, pre, post, lst) {\n var s = dat.length;\n var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);\n // writing to this writes to the output buffer\n var w = o.subarray(pre, o.length - post);\n var pos = 0;\n if (!lvl || s < 8) {\n for (var i = 0; i <= s; i += 65535) {\n // end\n var e = i + 65535;\n if (e >= s) {\n // write final block\n w[pos >> 3] = lst;\n }\n pos = wfblk(w, pos + 1, dat.subarray(i, e));\n }\n }\n else {\n var opt = deo[lvl - 1];\n var n = opt >>> 13, c = opt & 8191;\n var msk_1 = (1 << plvl) - 1;\n // prev 2-byte val map curr 2-byte val map\n var prev = new u16(32768), head = new u16(msk_1 + 1);\n var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;\n var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };\n // 24576 is an arbitrary number of maximum symbols per block\n // 424 buffer for last block\n var syms = new u32(25000);\n // length/literal freq distance freq\n var lf = new u16(288), df = new u16(32);\n // l/lcnt exbits index l/lind waitdx bitpos\n var lc_1 = 0, eb = 0, i = 0, li = 0, wi = 0, bs = 0;\n for (; i < s; ++i) {\n // hash value\n // deopt when i > s - 3 - at end, deopt acceptable\n var hv = hsh(i);\n // index mod 32768 previous index mod\n var imod = i & 32767, pimod = head[hv];\n prev[imod] = pimod;\n head[hv] = imod;\n // We always should modify head and prev, but only add symbols if\n // this data is not yet processed (\"wait\" for wait index)\n if (wi <= i) {\n // bytes remaining\n var rem = s - i;\n if ((lc_1 > 7000 || li > 24576) && rem > 423) {\n pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);\n li = lc_1 = eb = 0, bs = i;\n for (var j = 0; j < 286; ++j)\n lf[j] = 0;\n for (var j = 0; j < 30; ++j)\n df[j] = 0;\n }\n // len dist chain\n var l = 2, d = 0, ch_1 = c, dif = (imod - pimod) & 32767;\n if (rem > 2 && hv == hsh(i - dif)) {\n var maxn = Math.min(n, rem) - 1;\n var maxd = Math.min(32767, i);\n // max possible length\n // not capped at dif because decompressors implement \"rolling\" index population\n var ml = Math.min(258, rem);\n while (dif <= maxd && --ch_1 && imod != pimod) {\n if (dat[i + l] == dat[i + l - dif]) {\n var nl = 0;\n for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)\n ;\n if (nl > l) {\n l = nl, d = dif;\n // break out early when we reach \"nice\" (we are satisfied enough)\n if (nl > maxn)\n break;\n // now, find the rarest 2-byte sequence within this\n // length of literals and search for that instead.\n // Much faster than just using the start\n var mmd = Math.min(dif, nl - 2);\n var md = 0;\n for (var j = 0; j < mmd; ++j) {\n var ti = (i - dif + j + 32768) & 32767;\n var pti = prev[ti];\n var cd = (ti - pti + 32768) & 32767;\n if (cd > md)\n md = cd, pimod = ti;\n }\n }\n }\n // check the previous match\n imod = pimod, pimod = prev[imod];\n dif += (imod - pimod + 32768) & 32767;\n }\n }\n // d will be nonzero only when a match was found\n if (d) {\n // store both dist and len data in one Uint32\n // Make sure this is recognized as a len/dist with 28th bit (2^28)\n syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];\n var lin = revfl[l] & 31, din = revfd[d] & 31;\n eb += fleb[lin] + fdeb[din];\n ++lf[257 + lin];\n ++df[din];\n wi = i + l;\n ++lc_1;\n }\n else {\n syms[li++] = dat[i];\n ++lf[dat[i]];\n }\n }\n }\n pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);\n // this is the easiest way to avoid needing to maintain state\n if (!lst && pos & 7)\n pos = wfblk(w, pos + 1, et);\n }\n return slc(o, 0, pre + shft(pos) + post);\n};\n// CRC32 table\nvar crct = /*#__PURE__*/ (function () {\n var t = new Int32Array(256);\n for (var i = 0; i < 256; ++i) {\n var c = i, k = 9;\n while (--k)\n c = ((c & 1) && -306674912) ^ (c >>> 1);\n t[i] = c;\n }\n return t;\n})();\n// CRC32\nvar crc = function () {\n var c = -1;\n return {\n p: function (d) {\n // closures have awful performance\n var cr = c;\n for (var i = 0; i < d.length; ++i)\n cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);\n c = cr;\n },\n d: function () { return ~c; }\n };\n};\n// Alder32\nvar adler = function () {\n var a = 1, b = 0;\n return {\n p: function (d) {\n // closures have awful performance\n var n = a, m = b;\n var l = d.length | 0;\n for (var i = 0; i != l;) {\n var e = Math.min(i + 2655, l);\n for (; i < e; ++i)\n m += n += d[i];\n n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);\n }\n a = n, b = m;\n },\n d: function () {\n a %= 65521, b %= 65521;\n return (a & 255) << 24 | (a >>> 8) << 16 | (b & 255) << 8 | (b >>> 8);\n }\n };\n};\n;\n// deflate with opts\nvar dopt = function (dat, opt, pre, post, st) {\n return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : (12 + opt.mem), pre, post, !st);\n};\n// Walmart object spread\nvar mrg = function (a, b) {\n var o = {};\n for (var k in a)\n o[k] = a[k];\n for (var k in b)\n o[k] = b[k];\n return o;\n};\n// worker clone\n// This is possibly the craziest part of the entire codebase, despite how simple it may seem.\n// The only parameter to this function is a closure that returns an array of variables outside of the function scope.\n// We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.\n// We will return an object mapping of true variable name to value (basically, the current scope as a JS object).\n// The reason we can't just use the original variable names is minifiers mangling the toplevel scope.\n// This took me three weeks to figure out how to do.\nvar wcln = function (fn, fnStr, td) {\n var dt = fn();\n var st = fn.toString();\n var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/ /g, '').split(',');\n for (var i = 0; i < dt.length; ++i) {\n var v = dt[i], k = ks[i];\n if (typeof v == 'function') {\n fnStr += ';' + k + '=';\n var st_1 = v.toString();\n if (v.prototype) {\n // for global objects\n if (st_1.indexOf('[native code]') != -1) {\n var spInd = st_1.indexOf(' ', 8) + 1;\n fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));\n }\n else {\n fnStr += st_1;\n for (var t in v.prototype)\n fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();\n }\n }\n else\n fnStr += st_1;\n }\n else\n td[k] = v;\n }\n return [fnStr, td];\n};\nvar ch = [];\n// clone bufs\nvar cbfs = function (v) {\n var tl = [];\n for (var k in v) {\n if (v[k] instanceof u8 || v[k] instanceof u16 || v[k] instanceof u32)\n tl.push((v[k] = new v[k].constructor(v[k])).buffer);\n }\n return tl;\n};\n// use a worker to execute code\nvar wrkr = function (fns, init, id, cb) {\n var _a;\n if (!ch[id]) {\n var fnStr = '', td_1 = {}, m = fns.length - 1;\n for (var i = 0; i < m; ++i)\n _a = wcln(fns[i], fnStr, td_1), fnStr = _a[0], td_1 = _a[1];\n ch[id] = wcln(fns[m], fnStr, td_1);\n }\n var td = mrg({}, ch[id][1]);\n return wk(ch[id][0] + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);\n};\n// base async inflate fn\nvar bInflt = function () { return [u8, u16, u32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gu8]; };\nvar bDflt = function () { return [u8, u16, u32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; };\n// gzip extra\nvar gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };\n// gunzip extra\nvar guze = function () { return [gzs, gzl]; };\n// zlib extra\nvar zle = function () { return [zlh, wbytes, adler]; };\n// unzlib extra\nvar zule = function () { return [zlv]; };\n// post buf\nvar pbf = function (msg) { return postMessage(msg, [msg.buffer]); };\n// get u8\nvar gu8 = function (o) { return o && o.size && new u8(o.size); };\n// async helper\nvar cbify = function (dat, opts, fns, init, id, cb) {\n var w = wrkr(fns, init, id, function (err, dat) {\n w.terminate();\n cb(err, dat);\n });\n w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);\n return function () { w.terminate(); };\n};\n// auto stream\nvar astrm = function (strm) {\n strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };\n return function (ev) { return strm.push(ev.data[0], ev.data[1]); };\n};\n// async stream attach\nvar astrmify = function (fns, strm, opts, init, id) {\n var t;\n var w = wrkr(fns, init, id, function (err, dat) {\n if (err)\n w.terminate(), strm.ondata.call(strm, err);\n else {\n if (dat[1])\n w.terminate();\n strm.ondata.call(strm, err, dat[0], dat[1]);\n }\n });\n w.postMessage(opts);\n strm.push = function (d, f) {\n if (!strm.ondata)\n err(5);\n if (t)\n strm.ondata(err(4, 0, 1), null, !!f);\n w.postMessage([d, t = f], [d.buffer]);\n };\n strm.terminate = function () { w.terminate(); };\n};\n// read 2 bytes\nvar b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };\n// read 4 bytes\nvar b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };\nvar b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };\n// write bytes\nvar wbytes = function (d, b, v) {\n for (; v; ++b)\n d[b] = v, v >>>= 8;\n};\n// gzip header\nvar gzh = function (c, o) {\n var fn = o.filename;\n c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix\n if (o.mtime != 0)\n wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));\n if (fn) {\n c[3] = 8;\n for (var i = 0; i <= fn.length; ++i)\n c[i + 10] = fn.charCodeAt(i);\n }\n};\n// gzip footer: -8 to -4 = CRC, -4 to -0 is length\n// gzip start\nvar gzs = function (d) {\n if (d[0] != 31 || d[1] != 139 || d[2] != 8)\n err(6, 'invalid gzip data');\n var flg = d[3];\n var st = 10;\n if (flg & 4)\n st += d[10] | (d[11] << 8) + 2;\n for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])\n ;\n return st + (flg & 2);\n};\n// gzip length\nvar gzl = function (d) {\n var l = d.length;\n return ((d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16) | (d[l - 1] << 24)) >>> 0;\n};\n// gzip header length\nvar gzhl = function (o) { return 10 + ((o.filename && (o.filename.length + 1)) || 0); };\n// zlib header\nvar zlh = function (c, o) {\n var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;\n c[0] = 120, c[1] = (fl << 6) | (fl ? (32 - 2 * fl) : 1);\n};\n// zlib valid\nvar zlv = function (d) {\n if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31))\n err(6, 'invalid zlib data');\n if (d[1] & 32)\n err(6, 'invalid zlib data: preset dictionaries not supported');\n};\nfunction AsyncCmpStrm(opts, cb) {\n if (!cb && typeof opts == 'function')\n cb = opts, opts = {};\n this.ondata = cb;\n return opts;\n}\n// zlib footer: -4 to -0 is Adler32\n/**\n * Streaming DEFLATE compression\n */\nvar Deflate = /*#__PURE__*/ (function () {\n function Deflate(opts, cb) {\n if (!cb && typeof opts == 'function')\n cb = opts, opts = {};\n this.ondata = cb;\n this.o = opts || {};\n }\n Deflate.prototype.p = function (c, f) {\n this.ondata(dopt(c, this.o, 0, 0, !f), f);\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Deflate.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n this.d = final;\n this.p(chunk, final || false);\n };\n return Deflate;\n}());\nexport { Deflate };\n/**\n * Asynchronous streaming DEFLATE compression\n */\nvar AsyncDeflate = /*#__PURE__*/ (function () {\n function AsyncDeflate(opts, cb) {\n astrmify([\n bDflt,\n function () { return [astrm, Deflate]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Deflate(ev.data);\n onmessage = astrm(strm);\n }, 6);\n }\n return AsyncDeflate;\n}());\nexport { AsyncDeflate };\nexport function deflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);\n}\n/**\n * Compresses data with DEFLATE without any wrapper\n * @param data The data to compress\n * @param opts The compression options\n * @returns The deflated version of the data\n */\nexport function deflateSync(data, opts) {\n return dopt(data, opts || {}, 0, 0);\n}\n/**\n * Streaming DEFLATE decompression\n */\nvar Inflate = /*#__PURE__*/ (function () {\n /**\n * Creates an inflation stream\n * @param cb The callback to call whenever data is inflated\n */\n function Inflate(cb) {\n this.s = {};\n this.p = new u8(0);\n this.ondata = cb;\n }\n Inflate.prototype.e = function (c) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n var l = this.p.length;\n var n = new u8(l + c.length);\n n.set(this.p), n.set(c, l), this.p = n;\n };\n Inflate.prototype.c = function (final) {\n this.d = this.s.i = final || false;\n var bts = this.s.b;\n var dt = inflt(this.p, this.o, this.s);\n this.ondata(slc(dt, bts, this.s.b), this.d);\n this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;\n this.p = slc(this.p, (this.s.p / 8) | 0), this.s.p &= 7;\n };\n /**\n * Pushes a chunk to be inflated\n * @param chunk The chunk to push\n * @param final Whether this is the final chunk\n */\n Inflate.prototype.push = function (chunk, final) {\n this.e(chunk), this.c(final);\n };\n return Inflate;\n}());\nexport { Inflate };\n/**\n * Asynchronous streaming DEFLATE decompression\n */\nvar AsyncInflate = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous inflation stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncInflate(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n function () { return [astrm, Inflate]; }\n ], this, 0, function () {\n var strm = new Inflate();\n onmessage = astrm(strm);\n }, 7);\n }\n return AsyncInflate;\n}());\nexport { AsyncInflate };\nexport function inflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt\n ], function (ev) { return pbf(inflateSync(ev.data[0], gu8(ev.data[1]))); }, 1, cb);\n}\n/**\n * Expands DEFLATE data with no wrapper\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function inflateSync(data, out) {\n return inflt(data, out);\n}\n// before you yell at me for not just using extends, my reason is that TS inheritance is hard to workerize.\n/**\n * Streaming GZIP compression\n */\nvar Gzip = /*#__PURE__*/ (function () {\n function Gzip(opts, cb) {\n this.c = crc();\n this.l = 0;\n this.v = 1;\n Deflate.call(this, opts, cb);\n }\n /**\n * Pushes a chunk to be GZIPped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Gzip.prototype.push = function (chunk, final) {\n Deflate.prototype.push.call(this, chunk, final);\n };\n Gzip.prototype.p = function (c, f) {\n this.c.p(c);\n this.l += c.length;\n var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, !f);\n if (this.v)\n gzh(raw, this.o), this.v = 0;\n if (f)\n wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);\n this.ondata(raw, f);\n };\n return Gzip;\n}());\nexport { Gzip };\n/**\n * Asynchronous streaming GZIP compression\n */\nvar AsyncGzip = /*#__PURE__*/ (function () {\n function AsyncGzip(opts, cb) {\n astrmify([\n bDflt,\n gze,\n function () { return [astrm, Deflate, Gzip]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Gzip(ev.data);\n onmessage = astrm(strm);\n }, 8);\n }\n return AsyncGzip;\n}());\nexport { AsyncGzip };\nexport function gzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n gze,\n function () { return [gzipSync]; }\n ], function (ev) { return pbf(gzipSync(ev.data[0], ev.data[1])); }, 2, cb);\n}\n/**\n * Compresses data with GZIP\n * @param data The data to compress\n * @param opts The compression options\n * @returns The gzipped version of the data\n */\nexport function gzipSync(data, opts) {\n if (!opts)\n opts = {};\n var c = crc(), l = data.length;\n c.p(data);\n var d = dopt(data, opts, gzhl(opts), 8), s = d.length;\n return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;\n}\n/**\n * Streaming GZIP decompression\n */\nvar Gunzip = /*#__PURE__*/ (function () {\n /**\n * Creates a GUNZIP stream\n * @param cb The callback to call whenever data is inflated\n */\n function Gunzip(cb) {\n this.v = 1;\n Inflate.call(this, cb);\n }\n /**\n * Pushes a chunk to be GUNZIPped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Gunzip.prototype.push = function (chunk, final) {\n Inflate.prototype.e.call(this, chunk);\n if (this.v) {\n var s = this.p.length > 3 ? gzs(this.p) : 4;\n if (s >= this.p.length && !final)\n return;\n this.p = this.p.subarray(s), this.v = 0;\n }\n if (final) {\n if (this.p.length < 8)\n err(6, 'invalid gzip data');\n this.p = this.p.subarray(0, -8);\n }\n // necessary to prevent TS from using the closure value\n // This allows for workerization to function correctly\n Inflate.prototype.c.call(this, final);\n };\n return Gunzip;\n}());\nexport { Gunzip };\n/**\n * Asynchronous streaming GZIP decompression\n */\nvar AsyncGunzip = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous GUNZIP stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncGunzip(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n guze,\n function () { return [astrm, Inflate, Gunzip]; }\n ], this, 0, function () {\n var strm = new Gunzip();\n onmessage = astrm(strm);\n }, 9);\n }\n return AsyncGunzip;\n}());\nexport { AsyncGunzip };\nexport function gunzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt,\n guze,\n function () { return [gunzipSync]; }\n ], function (ev) { return pbf(gunzipSync(ev.data[0])); }, 3, cb);\n}\n/**\n * Expands GZIP data\n * @param data The data to decompress\n * @param out Where to write the data. GZIP already encodes the output size, so providing this doesn't save memory.\n * @returns The decompressed version of the data\n */\nexport function gunzipSync(data, out) {\n return inflt(data.subarray(gzs(data), -8), out || new u8(gzl(data)));\n}\n/**\n * Streaming Zlib compression\n */\nvar Zlib = /*#__PURE__*/ (function () {\n function Zlib(opts, cb) {\n this.c = adler();\n this.v = 1;\n Deflate.call(this, opts, cb);\n }\n /**\n * Pushes a chunk to be zlibbed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Zlib.prototype.push = function (chunk, final) {\n Deflate.prototype.push.call(this, chunk, final);\n };\n Zlib.prototype.p = function (c, f) {\n this.c.p(c);\n var raw = dopt(c, this.o, this.v && 2, f && 4, !f);\n if (this.v)\n zlh(raw, this.o), this.v = 0;\n if (f)\n wbytes(raw, raw.length - 4, this.c.d());\n this.ondata(raw, f);\n };\n return Zlib;\n}());\nexport { Zlib };\n/**\n * Asynchronous streaming Zlib compression\n */\nvar AsyncZlib = /*#__PURE__*/ (function () {\n function AsyncZlib(opts, cb) {\n astrmify([\n bDflt,\n zle,\n function () { return [astrm, Deflate, Zlib]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Zlib(ev.data);\n onmessage = astrm(strm);\n }, 10);\n }\n return AsyncZlib;\n}());\nexport { AsyncZlib };\nexport function zlib(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n zle,\n function () { return [zlibSync]; }\n ], function (ev) { return pbf(zlibSync(ev.data[0], ev.data[1])); }, 4, cb);\n}\n/**\n * Compress data with Zlib\n * @param data The data to compress\n * @param opts The compression options\n * @returns The zlib-compressed version of the data\n */\nexport function zlibSync(data, opts) {\n if (!opts)\n opts = {};\n var a = adler();\n a.p(data);\n var d = dopt(data, opts, 2, 4);\n return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;\n}\n/**\n * Streaming Zlib decompression\n */\nvar Unzlib = /*#__PURE__*/ (function () {\n /**\n * Creates a Zlib decompression stream\n * @param cb The callback to call whenever data is inflated\n */\n function Unzlib(cb) {\n this.v = 1;\n Inflate.call(this, cb);\n }\n /**\n * Pushes a chunk to be unzlibbed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Unzlib.prototype.push = function (chunk, final) {\n Inflate.prototype.e.call(this, chunk);\n if (this.v) {\n if (this.p.length < 2 && !final)\n return;\n this.p = this.p.subarray(2), this.v = 0;\n }\n if (final) {\n if (this.p.length < 4)\n err(6, 'invalid zlib data');\n this.p = this.p.subarray(0, -4);\n }\n // necessary to prevent TS from using the closure value\n // This allows for workerization to function correctly\n Inflate.prototype.c.call(this, final);\n };\n return Unzlib;\n}());\nexport { Unzlib };\n/**\n * Asynchronous streaming Zlib decompression\n */\nvar AsyncUnzlib = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous Zlib decompression stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncUnzlib(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n zule,\n function () { return [astrm, Inflate, Unzlib]; }\n ], this, 0, function () {\n var strm = new Unzlib();\n onmessage = astrm(strm);\n }, 11);\n }\n return AsyncUnzlib;\n}());\nexport { AsyncUnzlib };\nexport function unzlib(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt,\n zule,\n function () { return [unzlibSync]; }\n ], function (ev) { return pbf(unzlibSync(ev.data[0], gu8(ev.data[1]))); }, 5, cb);\n}\n/**\n * Expands Zlib data\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function unzlibSync(data, out) {\n return inflt((zlv(data), data.subarray(2, -4)), out);\n}\n// Default algorithm for compression (used because having a known output size allows faster decompression)\nexport { gzip as compress, AsyncGzip as AsyncCompress };\n// Default algorithm for compression (used because having a known output size allows faster decompression)\nexport { gzipSync as compressSync, Gzip as Compress };\n/**\n * Streaming GZIP, Zlib, or raw DEFLATE decompression\n */\nvar Decompress = /*#__PURE__*/ (function () {\n /**\n * Creates a decompression stream\n * @param cb The callback to call whenever data is decompressed\n */\n function Decompress(cb) {\n this.G = Gunzip;\n this.I = Inflate;\n this.Z = Unzlib;\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be decompressed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Decompress.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (!this.s) {\n if (this.p && this.p.length) {\n var n = new u8(this.p.length + chunk.length);\n n.set(this.p), n.set(chunk, this.p.length);\n }\n else\n this.p = chunk;\n if (this.p.length > 2) {\n var _this_1 = this;\n var cb = function () { _this_1.ondata.apply(_this_1, arguments); };\n this.s = (this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8)\n ? new this.G(cb)\n : ((this.p[0] & 15) != 8 || (this.p[0] >> 4) > 7 || ((this.p[0] << 8 | this.p[1]) % 31))\n ? new this.I(cb)\n : new this.Z(cb);\n this.s.push(this.p, final);\n this.p = null;\n }\n }\n else\n this.s.push(chunk, final);\n };\n return Decompress;\n}());\nexport { Decompress };\n/**\n * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression\n */\nvar AsyncDecompress = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous decompression stream\n * @param cb The callback to call whenever data is decompressed\n */\n function AsyncDecompress(cb) {\n this.G = AsyncGunzip;\n this.I = AsyncInflate;\n this.Z = AsyncUnzlib;\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be decompressed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n AsyncDecompress.prototype.push = function (chunk, final) {\n Decompress.prototype.push.call(this, chunk, final);\n };\n return AsyncDecompress;\n}());\nexport { AsyncDecompress };\nexport function decompress(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return (data[0] == 31 && data[1] == 139 && data[2] == 8)\n ? gunzip(data, opts, cb)\n : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))\n ? inflate(data, opts, cb)\n : unzlib(data, opts, cb);\n}\n/**\n * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function decompressSync(data, out) {\n return (data[0] == 31 && data[1] == 139 && data[2] == 8)\n ? gunzipSync(data, out)\n : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))\n ? inflateSync(data, out)\n : unzlibSync(data, out);\n}\n// flatten a directory structure\nvar fltn = function (d, p, t, o) {\n for (var k in d) {\n var val = d[k], n = p + k;\n if (val instanceof u8)\n t[n] = [val, o];\n else if (Array.isArray(val))\n t[n] = [val[0], mrg(o, val[1])];\n else\n fltn(val, n + '/', t, o);\n }\n};\n// text encoder\nvar te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();\n// text decoder\nvar td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();\n// text decoder stream\nvar tds = 0;\ntry {\n td.decode(et, { stream: true });\n tds = 1;\n}\ncatch (e) { }\n// decode UTF8\nvar dutf8 = function (d) {\n for (var r = '', i = 0;;) {\n var c = d[i++];\n var eb = (c > 127) + (c > 223) + (c > 239);\n if (i + eb > d.length)\n return [r, slc(d, i - 1)];\n if (!eb)\n r += String.fromCharCode(c);\n else if (eb == 3) {\n c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536,\n r += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023));\n }\n else if (eb & 1)\n r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));\n else\n r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));\n }\n};\n/**\n * Streaming UTF-8 decoding\n */\nvar DecodeUTF8 = /*#__PURE__*/ (function () {\n /**\n * Creates a UTF-8 decoding stream\n * @param cb The callback to call whenever data is decoded\n */\n function DecodeUTF8(cb) {\n this.ondata = cb;\n if (tds)\n this.t = new TextDecoder();\n else\n this.p = et;\n }\n /**\n * Pushes a chunk to be decoded from UTF-8 binary\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n DecodeUTF8.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n final = !!final;\n if (this.t) {\n this.ondata(this.t.decode(chunk, { stream: true }), final);\n if (final) {\n if (this.t.decode().length)\n err(8);\n this.t = null;\n }\n return;\n }\n if (!this.p)\n err(4);\n var dat = new u8(this.p.length + chunk.length);\n dat.set(this.p);\n dat.set(chunk, this.p.length);\n var _a = dutf8(dat), ch = _a[0], np = _a[1];\n if (final) {\n if (np.length)\n err(8);\n this.p = null;\n }\n else\n this.p = np;\n this.ondata(ch, final);\n };\n return DecodeUTF8;\n}());\nexport { DecodeUTF8 };\n/**\n * Streaming UTF-8 encoding\n */\nvar EncodeUTF8 = /*#__PURE__*/ (function () {\n /**\n * Creates a UTF-8 decoding stream\n * @param cb The callback to call whenever data is encoded\n */\n function EncodeUTF8(cb) {\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be encoded to UTF-8\n * @param chunk The string data to push\n * @param final Whether this is the last chunk\n */\n EncodeUTF8.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n this.ondata(strToU8(chunk), this.d = final || false);\n };\n return EncodeUTF8;\n}());\nexport { EncodeUTF8 };\n/**\n * Converts a string into a Uint8Array for use with compression/decompression methods\n * @param str The string to encode\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless decoding a binary string.\n * @returns The string encoded in UTF-8/Latin-1 binary\n */\nexport function strToU8(str, latin1) {\n if (latin1) {\n var ar_1 = new u8(str.length);\n for (var i = 0; i < str.length; ++i)\n ar_1[i] = str.charCodeAt(i);\n return ar_1;\n }\n if (te)\n return te.encode(str);\n var l = str.length;\n var ar = new u8(str.length + (str.length >> 1));\n var ai = 0;\n var w = function (v) { ar[ai++] = v; };\n for (var i = 0; i < l; ++i) {\n if (ai + 5 > ar.length) {\n var n = new u8(ai + 8 + ((l - i) << 1));\n n.set(ar);\n ar = n;\n }\n var c = str.charCodeAt(i);\n if (c < 128 || latin1)\n w(c);\n else if (c < 2048)\n w(192 | (c >> 6)), w(128 | (c & 63));\n else if (c > 55295 && c < 57344)\n c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),\n w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n else\n w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n }\n return slc(ar, 0, ai);\n}\n/**\n * Converts a Uint8Array to a string\n * @param dat The data to decode to string\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless encoding to binary string.\n * @returns The original UTF-8/Latin-1 string\n */\nexport function strFromU8(dat, latin1) {\n if (latin1) {\n var r = '';\n for (var i = 0; i < dat.length; i += 16384)\n r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));\n return r;\n }\n else if (td)\n return td.decode(dat);\n else {\n var _a = dutf8(dat), out = _a[0], ext = _a[1];\n if (ext.length)\n err(8);\n return out;\n }\n}\n;\n// deflate bit flag\nvar dbf = function (l) { return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0; };\n// skip local zip header\nvar slzh = function (d, b) { return b + 30 + b2(d, b + 26) + b2(d, b + 28); };\n// read zip header\nvar zh = function (d, b, z) {\n var fnl = b2(d, b + 28), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl, bs = b4(d, b + 20);\n var _a = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a[0], su = _a[1], off = _a[2];\n return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off];\n};\n// read zip64 extra field\nvar z64e = function (d, b) {\n for (; b2(d, b) != 1; b += 4 + b2(d, b + 2))\n ;\n return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)];\n};\n// extra field length\nvar exfl = function (ex) {\n var le = 0;\n if (ex) {\n for (var k in ex) {\n var l = ex[k].length;\n if (l > 65535)\n err(9);\n le += l + 4;\n }\n }\n return le;\n};\n// write zip header\nvar wzh = function (d, b, f, fn, u, c, ce, co) {\n var fl = fn.length, ex = f.extra, col = co && co.length;\n var exl = exfl(ex);\n wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;\n if (ce != null)\n d[b++] = 20, d[b++] = f.os;\n d[b] = 20, b += 2; // spec compliance? what's that?\n d[b++] = (f.flag << 1) | (c == null && 8), d[b++] = u && 8;\n d[b++] = f.compression & 255, d[b++] = f.compression >> 8;\n var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;\n if (y < 0 || y > 119)\n err(10);\n wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >>> 1)), b += 4;\n if (c != null) {\n wbytes(d, b, f.crc);\n wbytes(d, b + 4, c);\n wbytes(d, b + 8, f.size);\n }\n wbytes(d, b + 12, fl);\n wbytes(d, b + 14, exl), b += 16;\n if (ce != null) {\n wbytes(d, b, col);\n wbytes(d, b + 6, f.attrs);\n wbytes(d, b + 10, ce), b += 14;\n }\n d.set(fn, b);\n b += fl;\n if (exl) {\n for (var k in ex) {\n var exf = ex[k], l = exf.length;\n wbytes(d, b, +k);\n wbytes(d, b + 2, l);\n d.set(exf, b + 4), b += 4 + l;\n }\n }\n if (col)\n d.set(co, b), b += col;\n return b;\n};\n// write zip footer (end of central directory)\nvar wzf = function (o, b, c, d, e) {\n wbytes(o, b, 0x6054B50); // skip disk\n wbytes(o, b + 8, c);\n wbytes(o, b + 10, c);\n wbytes(o, b + 12, d);\n wbytes(o, b + 16, e);\n};\n/**\n * A pass-through stream to keep data uncompressed in a ZIP archive.\n */\nvar ZipPassThrough = /*#__PURE__*/ (function () {\n /**\n * Creates a pass-through stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n */\n function ZipPassThrough(filename) {\n this.filename = filename;\n this.c = crc();\n this.size = 0;\n this.compression = 0;\n }\n /**\n * Processes a chunk and pushes to the output stream. You can override this\n * method in a subclass for custom behavior, but by default this passes\n * the data through. You must call this.ondata(err, chunk, final) at some\n * point in this method.\n * @param chunk The chunk to process\n * @param final Whether this is the last chunk\n */\n ZipPassThrough.prototype.process = function (chunk, final) {\n this.ondata(null, chunk, final);\n };\n /**\n * Pushes a chunk to be added. If you are subclassing this with a custom\n * compression algorithm, note that you must push data from the source\n * file only, pre-compression.\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n ZipPassThrough.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n this.c.p(chunk);\n this.size += chunk.length;\n if (final)\n this.crc = this.c.d();\n this.process(chunk, final || false);\n };\n return ZipPassThrough;\n}());\nexport { ZipPassThrough };\n// I don't extend because TypeScript extension adds 1kB of runtime bloat\n/**\n * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate\n * for better performance\n */\nvar ZipDeflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n * @param opts The compression options\n */\n function ZipDeflate(filename, opts) {\n var _this_1 = this;\n if (!opts)\n opts = {};\n ZipPassThrough.call(this, filename);\n this.d = new Deflate(opts, function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n this.compression = 8;\n this.flag = dbf(opts.level);\n }\n ZipDeflate.prototype.process = function (chunk, final) {\n try {\n this.d.push(chunk, final);\n }\n catch (e) {\n this.ondata(e, null, final);\n }\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n ZipDeflate.prototype.push = function (chunk, final) {\n ZipPassThrough.prototype.push.call(this, chunk, final);\n };\n return ZipDeflate;\n}());\nexport { ZipDeflate };\n/**\n * Asynchronous streaming DEFLATE compression for ZIP archives\n */\nvar AsyncZipDeflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n * @param opts The compression options\n */\n function AsyncZipDeflate(filename, opts) {\n var _this_1 = this;\n if (!opts)\n opts = {};\n ZipPassThrough.call(this, filename);\n this.d = new AsyncDeflate(opts, function (err, dat, final) {\n _this_1.ondata(err, dat, final);\n });\n this.compression = 8;\n this.flag = dbf(opts.level);\n this.terminate = this.d.terminate;\n }\n AsyncZipDeflate.prototype.process = function (chunk, final) {\n this.d.push(chunk, final);\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n AsyncZipDeflate.prototype.push = function (chunk, final) {\n ZipPassThrough.prototype.push.call(this, chunk, final);\n };\n return AsyncZipDeflate;\n}());\nexport { AsyncZipDeflate };\n// TODO: Better tree shaking\n/**\n * A zippable archive to which files can incrementally be added\n */\nvar Zip = /*#__PURE__*/ (function () {\n /**\n * Creates an empty ZIP archive to which files can be added\n * @param cb The callback to call whenever data for the generated ZIP archive\n * is available\n */\n function Zip(cb) {\n this.ondata = cb;\n this.u = [];\n this.d = 1;\n }\n /**\n * Adds a file to the ZIP archive\n * @param file The file stream to add\n */\n Zip.prototype.add = function (file) {\n var _this_1 = this;\n if (!this.ondata)\n err(5);\n // finishing or finished\n if (this.d & 2)\n this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);\n else {\n var f = strToU8(file.filename), fl_1 = f.length;\n var com = file.comment, o = com && strToU8(com);\n var u = fl_1 != file.filename.length || (o && (com.length != o.length));\n var hl_1 = fl_1 + exfl(file.extra) + 30;\n if (fl_1 > 65535)\n this.ondata(err(11, 0, 1), null, false);\n var header = new u8(hl_1);\n wzh(header, 0, file, f, u);\n var chks_1 = [header];\n var pAll_1 = function () {\n for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {\n var chk = chks_2[_i];\n _this_1.ondata(null, chk, false);\n }\n chks_1 = [];\n };\n var tr_1 = this.d;\n this.d = 0;\n var ind_1 = this.u.length;\n var uf_1 = mrg(file, {\n f: f,\n u: u,\n o: o,\n t: function () {\n if (file.terminate)\n file.terminate();\n },\n r: function () {\n pAll_1();\n if (tr_1) {\n var nxt = _this_1.u[ind_1 + 1];\n if (nxt)\n nxt.r();\n else\n _this_1.d = 1;\n }\n tr_1 = 1;\n }\n });\n var cl_1 = 0;\n file.ondata = function (err, dat, final) {\n if (err) {\n _this_1.ondata(err, dat, final);\n _this_1.terminate();\n }\n else {\n cl_1 += dat.length;\n chks_1.push(dat);\n if (final) {\n var dd = new u8(16);\n wbytes(dd, 0, 0x8074B50);\n wbytes(dd, 4, file.crc);\n wbytes(dd, 8, cl_1);\n wbytes(dd, 12, file.size);\n chks_1.push(dd);\n uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;\n if (tr_1)\n uf_1.r();\n tr_1 = 1;\n }\n else if (tr_1)\n pAll_1();\n }\n };\n this.u.push(uf_1);\n }\n };\n /**\n * Ends the process of adding files and prepares to emit the final chunks.\n * This *must* be called after adding all desired files for the resulting\n * ZIP file to work properly.\n */\n Zip.prototype.end = function () {\n var _this_1 = this;\n if (this.d & 2) {\n this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);\n return;\n }\n if (this.d)\n this.e();\n else\n this.u.push({\n r: function () {\n if (!(_this_1.d & 1))\n return;\n _this_1.u.splice(-1, 1);\n _this_1.e();\n },\n t: function () { }\n });\n this.d = 3;\n };\n Zip.prototype.e = function () {\n var bt = 0, l = 0, tl = 0;\n for (var _i = 0, _a = this.u; _i < _a.length; _i++) {\n var f = _a[_i];\n tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);\n }\n var out = new u8(tl + 22);\n for (var _b = 0, _c = this.u; _b < _c.length; _b++) {\n var f = _c[_b];\n wzh(out, bt, f, f.f, f.u, f.c, l, f.o);\n bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;\n }\n wzf(out, bt, this.u.length, tl, l);\n this.ondata(null, out, true);\n this.d = 2;\n };\n /**\n * A method to terminate any internal workers used by the stream. Subsequent\n * calls to add() will fail.\n */\n Zip.prototype.terminate = function () {\n for (var _i = 0, _a = this.u; _i < _a.length; _i++) {\n var f = _a[_i];\n f.t();\n }\n this.d = 2;\n };\n return Zip;\n}());\nexport { Zip };\nexport function zip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var r = {};\n fltn(data, '', r, opts);\n var k = Object.keys(r);\n var lft = k.length, o = 0, tot = 0;\n var slft = lft, files = new Array(lft);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var cbf = function () {\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n tot = 0;\n for (var i = 0; i < slft; ++i) {\n var f = files[i];\n try {\n var l = f.c.length;\n wzh(out, tot, f, f.f, f.u, l);\n var badd = 30 + f.f.length + exfl(f.extra);\n var loc = tot + badd;\n out.set(f.c, loc);\n wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;\n }\n catch (e) {\n return cbd(e, null);\n }\n }\n wzf(out, o, files.length, cdl, oe);\n cbd(null, out);\n };\n if (!lft)\n cbf();\n var _loop_1 = function (i) {\n var fn = k[i];\n var _a = r[fn], file = _a[0], p = _a[1];\n var c = crc(), size = file.length;\n c.p(file);\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n var compression = p.level == 0 ? 0 : 8;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n var l = d.length;\n files[i] = mrg(p, {\n size: size,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n compression: compression\n });\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n if (!--lft)\n cbf();\n }\n };\n if (s > 65535)\n cbl(err(11, 0, 1), null);\n if (!compression)\n cbl(null, file);\n else if (size < 160000) {\n try {\n cbl(null, deflateSync(file, p));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(deflate(file, p, cbl));\n };\n // Cannot use lft because it can decrease\n for (var i = 0; i < slft; ++i) {\n _loop_1(i);\n }\n return tAll;\n}\n/**\n * Synchronously creates a ZIP file. Prefer using `zip` for better performance\n * with more than one file.\n * @param data The directory structure for the ZIP archive\n * @param opts The main options, merged with per-file options\n * @returns The generated ZIP archive\n */\nexport function zipSync(data, opts) {\n if (!opts)\n opts = {};\n var r = {};\n var files = [];\n fltn(data, '', r, opts);\n var o = 0;\n var tot = 0;\n for (var fn in r) {\n var _a = r[fn], file = _a[0], p = _a[1];\n var compression = p.level == 0 ? 0 : 8;\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n if (s > 65535)\n err(11);\n var d = compression ? deflateSync(file, p) : file, l = d.length;\n var c = crc();\n c.p(file);\n files.push(mrg(p, {\n size: file.length,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n o: o,\n compression: compression\n }));\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n }\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n for (var i = 0; i < files.length; ++i) {\n var f = files[i];\n wzh(out, f.o, f, f.f, f.u, f.c.length);\n var badd = 30 + f.f.length + exfl(f.extra);\n out.set(f.c, f.o + badd);\n wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);\n }\n wzf(out, o, files.length, cdl, oe);\n return out;\n}\n/**\n * Streaming pass-through decompression for ZIP archives\n */\nvar UnzipPassThrough = /*#__PURE__*/ (function () {\n function UnzipPassThrough() {\n }\n UnzipPassThrough.prototype.push = function (data, final) {\n this.ondata(null, data, final);\n };\n UnzipPassThrough.compression = 0;\n return UnzipPassThrough;\n}());\nexport { UnzipPassThrough };\n/**\n * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for\n * better performance.\n */\nvar UnzipInflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE decompression that can be used in ZIP archives\n */\n function UnzipInflate() {\n var _this_1 = this;\n this.i = new Inflate(function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n }\n UnzipInflate.prototype.push = function (data, final) {\n try {\n this.i.push(data, final);\n }\n catch (e) {\n this.ondata(e, null, final);\n }\n };\n UnzipInflate.compression = 8;\n return UnzipInflate;\n}());\nexport { UnzipInflate };\n/**\n * Asynchronous streaming DEFLATE decompression for ZIP archives\n */\nvar AsyncUnzipInflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE decompression that can be used in ZIP archives\n */\n function AsyncUnzipInflate(_, sz) {\n var _this_1 = this;\n if (sz < 320000) {\n this.i = new Inflate(function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n }\n else {\n this.i = new AsyncInflate(function (err, dat, final) {\n _this_1.ondata(err, dat, final);\n });\n this.terminate = this.i.terminate;\n }\n }\n AsyncUnzipInflate.prototype.push = function (data, final) {\n if (this.i.terminate)\n data = slc(data, 0);\n this.i.push(data, final);\n };\n AsyncUnzipInflate.compression = 8;\n return AsyncUnzipInflate;\n}());\nexport { AsyncUnzipInflate };\n/**\n * A ZIP archive decompression stream that emits files as they are discovered\n */\nvar Unzip = /*#__PURE__*/ (function () {\n /**\n * Creates a ZIP decompression stream\n * @param cb The callback to call whenever a file in the ZIP archive is found\n */\n function Unzip(cb) {\n this.onfile = cb;\n this.k = [];\n this.o = {\n 0: UnzipPassThrough\n };\n this.p = et;\n }\n /**\n * Pushes a chunk to be unzipped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Unzip.prototype.push = function (chunk, final) {\n var _this_1 = this;\n if (!this.onfile)\n err(5);\n if (!this.p)\n err(4);\n if (this.c > 0) {\n var len = Math.min(this.c, chunk.length);\n var toAdd = chunk.subarray(0, len);\n this.c -= len;\n if (this.d)\n this.d.push(toAdd, !this.c);\n else\n this.k[0].push(toAdd);\n chunk = chunk.subarray(len);\n if (chunk.length)\n return this.push(chunk, final);\n }\n else {\n var f = 0, i = 0, is = void 0, buf = void 0;\n if (!this.p.length)\n buf = chunk;\n else if (!chunk.length)\n buf = this.p;\n else {\n buf = new u8(this.p.length + chunk.length);\n buf.set(this.p), buf.set(chunk, this.p.length);\n }\n var l = buf.length, oc = this.c, add = oc && this.d;\n var _loop_2 = function () {\n var _a;\n var sig = b4(buf, i);\n if (sig == 0x4034B50) {\n f = 1, is = i;\n this_1.d = null;\n this_1.c = 0;\n var bf = b2(buf, i + 6), cmp_1 = b2(buf, i + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i + 26), es = b2(buf, i + 28);\n if (l > i + 30 + fnl + es) {\n var chks_3 = [];\n this_1.k.unshift(chks_3);\n f = 2;\n var sc_1 = b4(buf, i + 18), su_1 = b4(buf, i + 22);\n var fn_1 = strFromU8(buf.subarray(i + 30, i += 30 + fnl), !u);\n if (sc_1 == 4294967295) {\n _a = dd ? [-2] : z64e(buf, i), sc_1 = _a[0], su_1 = _a[1];\n }\n else if (dd)\n sc_1 = -1;\n i += es;\n this_1.c = sc_1;\n var d_1;\n var file_1 = {\n name: fn_1,\n compression: cmp_1,\n start: function () {\n if (!file_1.ondata)\n err(5);\n if (!sc_1)\n file_1.ondata(null, et, true);\n else {\n var ctr = _this_1.o[cmp_1];\n if (!ctr)\n file_1.ondata(err(14, 'unknown compression type ' + cmp_1, 1), null, false);\n d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);\n d_1.ondata = function (err, dat, final) { file_1.ondata(err, dat, final); };\n for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {\n var dat = chks_4[_i];\n d_1.push(dat, false);\n }\n if (_this_1.k[0] == chks_3 && _this_1.c)\n _this_1.d = d_1;\n else\n d_1.push(et, true);\n }\n },\n terminate: function () {\n if (d_1 && d_1.terminate)\n d_1.terminate();\n }\n };\n if (sc_1 >= 0)\n file_1.size = sc_1, file_1.originalSize = su_1;\n this_1.onfile(file_1);\n }\n return \"break\";\n }\n else if (oc) {\n if (sig == 0x8074B50) {\n is = i += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;\n return \"break\";\n }\n else if (sig == 0x2014B50) {\n is = i -= 4, f = 3, this_1.c = 0;\n return \"break\";\n }\n }\n };\n var this_1 = this;\n for (; i < l - 4; ++i) {\n var state_1 = _loop_2();\n if (state_1 === \"break\")\n break;\n }\n this.p = et;\n if (oc < 0) {\n var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 0x8074B50 && 4)) : buf.subarray(0, i);\n if (add)\n add.push(dat, !!f);\n else\n this.k[+(f == 2)].push(dat);\n }\n if (f & 2)\n return this.push(buf.subarray(i), final);\n this.p = buf.subarray(i);\n }\n if (final) {\n if (this.c)\n err(13);\n this.p = null;\n }\n };\n /**\n * Registers a decoder with the stream, allowing for files compressed with\n * the compression type provided to be expanded correctly\n * @param decoder The decoder constructor\n */\n Unzip.prototype.register = function (decoder) {\n this.o[decoder.compression] = decoder;\n };\n return Unzip;\n}());\nexport { Unzip };\nvar mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };\nexport function unzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var files = {};\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var e = data.length - 22;\n for (; b4(data, e) != 0x6054B50; --e) {\n if (!e || data.length - e > 65558) {\n cbd(err(13, 0, 1), null);\n return tAll;\n }\n }\n ;\n var lft = b2(data, e + 8);\n if (lft) {\n var c = lft;\n var o = b4(data, e + 16);\n var z = o == 4294967295;\n if (z) {\n e = b4(data, e - 12);\n if (b4(data, e) != 0x6064B50) {\n cbd(err(13, 0, 1), null);\n return tAll;\n }\n c = lft = b4(data, e + 32);\n o = b4(data, e + 48);\n }\n var fltr = opts && opts.filter;\n var _loop_3 = function (i) {\n var _a = zh(data, o, z), c_1 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);\n o = no;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n if (d)\n files[fn] = d;\n if (!--lft)\n cbd(null, files);\n }\n };\n if (!fltr || fltr({\n name: fn,\n size: sc,\n originalSize: su,\n compression: c_1\n })) {\n if (!c_1)\n cbl(null, slc(data, b, b + sc));\n else if (c_1 == 8) {\n var infl = data.subarray(b, b + sc);\n if (sc < 320000) {\n try {\n cbl(null, inflateSync(infl, new u8(su)));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(inflate(infl, { size: su }, cbl));\n }\n else\n cbl(err(14, 'unknown compression type ' + c_1, 1), null);\n }\n else\n cbl(null, null);\n };\n for (var i = 0; i < c; ++i) {\n _loop_3(i);\n }\n }\n else\n cbd(null, {});\n return tAll;\n}\n/**\n * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better\n * performance with more than one file.\n * @param data The raw compressed ZIP file\n * @param opts The ZIP extraction options\n * @returns The decompressed files\n */\nexport function unzipSync(data, opts) {\n var files = {};\n var e = data.length - 22;\n for (; b4(data, e) != 0x6054B50; --e) {\n if (!e || data.length - e > 65558)\n err(13);\n }\n ;\n var c = b2(data, e + 8);\n if (!c)\n return {};\n var o = b4(data, e + 16);\n var z = o == 4294967295;\n if (z) {\n e = b4(data, e - 12);\n if (b4(data, e) != 0x6064B50)\n err(13);\n c = b4(data, e + 32);\n o = b4(data, e + 48);\n }\n var fltr = opts && opts.filter;\n for (var i = 0; i < c; ++i) {\n var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);\n o = no;\n if (!fltr || fltr({\n name: fn,\n size: sc,\n originalSize: su,\n compression: c_2\n })) {\n if (!c_2)\n files[fn] = slc(data, b, b + sc);\n else if (c_2 == 8)\n files[fn] = inflateSync(data.subarray(b, b + sc), new u8(su));\n else\n err(14, 'unknown compression type ' + c_2);\n }\n }\n return files;\n}\n","import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { Matrix } from '@babylonjs/core/Maths/math.vector';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Geometry } from '@babylonjs/core/Meshes/geometry';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { DeepImmutable, FloatArray, IndicesArray, Nullable } from '@babylonjs/core/types';\r\nimport { AsyncZippable, strToU8, zip } from 'fflate';\r\nimport { SceneNode } from '../../../models/classes/scene-node';\r\n/** Be careful when adding dependencies in this file. Importing and using a constructor function or a barrel file will balloon the size of the worker js bundle */\r\n\r\nexport type TypeIntArray = Exclude;\r\nexport type TypedArray = TypeIntArray | Float32Array | Float64Array;\r\n\r\nexport interface GeometryTransferrable {\r\n payload: GeometryConversionPayload;\r\n transfer: ArrayBuffer[];\r\n}\r\n\r\nexport interface GeometryConversionPayload {\r\n options: USDOpts;\r\n id: string;\r\n indices: TypeIntArray;\r\n vertexBuffers: {\r\n [index: string]: Float32Array;\r\n };\r\n}\r\n\r\nexport interface USDOpts {\r\n unitsPerMeter: number;\r\n xrAllowScaling: boolean;\r\n}\r\n\r\nexport interface ConversionResult {\r\n file: Uint8Array;\r\n}\r\n\r\nexport class USDZConverter {\r\n parse(scene: Scene, sceneNode: SceneNode, useWorker = false): Promise {\r\n return Promise.reject();\r\n }\r\n\r\n convertGeometry(payload: GeometryConversionPayload) {\r\n const meshObject = this.buildGeometryFromBuffers(payload);\r\n return buildUSDAFile(payload.options, meshObject);\r\n }\r\n\r\n zipUSDZFiles(files: AsyncZippable) {\r\n return new Promise((resolve, reject) => {\r\n zip(\r\n files,\r\n {\r\n level: 0,\r\n },\r\n (err, res) => {\r\n if (err) {\r\n reject(err);\r\n } else {\r\n const blob = new Blob([res.buffer], { type: 'model/vnd.usdz+zip' });\r\n resolve(blob);\r\n }\r\n }\r\n );\r\n });\r\n }\r\n\r\n protected buildGeometryFromBuffers(payload: GeometryConversionPayload) {\r\n const positions = payload.vertexBuffers[VertexBuffer.PositionKind];\r\n if (!positions) {\r\n throw 'No indices in geometry';\r\n }\r\n const vertexCount = Math.floor(positions.length / 3);\r\n\r\n return buildGeometryFromData(\r\n payload.indices,\r\n vertexCount,\r\n positions,\r\n payload.vertexBuffers[VertexBuffer.NormalKind],\r\n payload.vertexBuffers[VertexBuffer.UVKind]\r\n );\r\n }\r\n\r\n protected buildGeometryFromObject(geometry: Geometry) {\r\n const indices = geometry.getIndices();\r\n const vertexCount = geometry.getTotalVertices();\r\n const positions = geometry.getVerticesData(VertexBuffer.PositionKind);\r\n if (!indices) {\r\n throw 'No indices in geometry';\r\n }\r\n if (!positions) {\r\n throw 'No indices in geometry';\r\n }\r\n return buildGeometryFromData(\r\n indices,\r\n vertexCount,\r\n positions,\r\n geometry.getVerticesData(VertexBuffer.NormalKind),\r\n geometry.getVerticesData(VertexBuffer.UVKind)\r\n );\r\n }\r\n}\r\n\r\nexport const PRECISION = 7;\r\n\r\nexport function buildHeader(opts: USDOpts) {\r\n return `#usda 1.0\r\n(\r\n customLayerData = {\r\n string creator = \"KB3D USDZConverter\"\r\n }\r\n metersPerUnit = ${1 / opts.unitsPerMeter}\r\n upAxis = \"Y\"\r\n)\r\n`;\r\n}\r\n\r\nexport function buildUSDAFile(opts: USDOpts, dataToInsert: string) {\r\n let output = buildHeader(opts);\r\n output += dataToInsert;\r\n return strToU8(output);\r\n}\r\n\r\n// Xform\r\nexport function buildXform(object: AbstractMesh, geometry: Geometry, material: PBRMaterial, appendFileName = '') {\r\n const name = 'Object__' + escapeGUID(object.id) + appendFileName;\r\n const worldMatrix = object.computeWorldMatrix(true);\r\n const transform = buildMatrix(worldMatrix);\r\n\r\n if (worldMatrix.determinant() < 0) {\r\n console.warn('USDZConverter: USDZ does not support negative scales', object);\r\n }\r\n\r\n return `def Xform \"${name}\" (\r\n prepend references = @./geometries/Geometry__${escapeGUID(geometry.id)}${appendFileName}.usd@
\r\n)\r\n{\r\n matrix4d xformOp:transform = ${transform}\r\n uniform token[] xformOpOrder = [\"xformOp:transform\"]\r\n rel material:binding = \r\n}\r\n`;\r\n}\r\n\r\nfunction buildMatrix(matrix: Matrix) {\r\n const array = matrix.toArray();\r\n return `( ${buildMatrixRow(array, 0)}, ${buildMatrixRow(array, 4)}, ${buildMatrixRow(array, 8)}, ${buildMatrixRow(\r\n array,\r\n 12\r\n )} )`;\r\n}\r\n\r\nfunction buildMatrixRow(array: DeepImmutable, offset: number) {\r\n return `(${array[offset + 0]}, ${array[offset + 1]}, ${array[offset + 2]}, ${array[offset + 3]})`;\r\n} // Mesh\r\n\r\nfunction buildGeometryFromData(\r\n indices: IndicesArray,\r\n verticesCount: number,\r\n positions: number[] | Float32Array,\r\n normals: Nullable,\r\n uvs: Nullable\r\n) {\r\n const vertexCounts = Array(Math.floor(indices.length / 3))\r\n .fill(3)\r\n .join(', ');\r\n\r\n const name = 'Geometry';\r\n\r\n return `\r\ndef \"Geometry\"\r\n{\r\n def Mesh \"${name}\"\r\n {\r\n int[] faceVertexCounts = [${vertexCounts}]\r\n int[] faceVertexIndices = [${stringifyIntArray(indices)}]\r\n normal3f[] normals = [${buildVector3Array(normals, verticesCount)}] (\r\n interpolation = \"vertex\"\r\n )\r\n point3f[] points = [${buildVector3Array(positions, verticesCount)}]\r\n float2[] primvars:st = [${buildVector2Array(uvs, verticesCount)}] (\r\n interpolation = \"vertex\"\r\n )\r\n uniform token subdivisionScheme = \"none\"\r\n uniform token orientation = \"leftHanded\"\r\n }\r\n}\r\n`;\r\n}\r\n\r\nfunction buildVector3Array(data: Nullable, count: number) {\r\n let res = '';\r\n if (!data) {\r\n console.warn('USDZConverter: Data missing.');\r\n for (let i = 0; i < count; i++) {\r\n res += '(0, 0, 0), ';\r\n }\r\n return res;\r\n }\r\n\r\n return stringifyFloatArray(data, count, 3);\r\n}\r\n\r\nfunction buildVector2Array(data: Nullable, count: number) {\r\n let res = '';\r\n if (!data) {\r\n console.warn('USDZConverter: Data missing.');\r\n for (let i = 0; i < count; i++) {\r\n res += '(0, 0), ';\r\n }\r\n return res;\r\n }\r\n\r\n return stringifyFloatArray(data, count, 2);\r\n}\r\n\r\nfunction stringifyIntArray(data: IndicesArray) {\r\n const count = data.length;\r\n let res = '';\r\n for (let i = 0; i < count; i++) {\r\n res += `${data[i]}, `;\r\n }\r\n\r\n return res.slice(0, -2);\r\n}\r\n\r\nfunction stringifyFloatArray(data: FloatArray, count: number, perStruc: number) {\r\n let res = '';\r\n if (perStruc === 2) {\r\n for (let i = 0; i < count; i++) {\r\n res += `(${data[i * 2].toPrecision(PRECISION)}, ${data[i * 2 + 1].toPrecision(PRECISION)}), `;\r\n }\r\n } else if (perStruc === 3) {\r\n for (let i = 0; i < count; i++) {\r\n res += `(${data[i * 3].toPrecision(PRECISION)}, ${data[i * 3 + 1].toPrecision(PRECISION)}, ${data[\r\n i * 3 + 2\r\n ].toPrecision(PRECISION)}), `;\r\n }\r\n } else {\r\n throw Error('Not supported');\r\n }\r\n return res.slice(0, -2);\r\n}\r\n\r\nexport function escapeGUID(guid: string) {\r\n return guid.replace(/[-\\s]+/g, '_');\r\n}\r\n","import { Material } from '@babylonjs/core/Materials/material';\r\nimport { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { BaseTexture, DynamicTexture, Texture } from '@babylonjs/core/Materials/Textures';\r\nimport { Color3, Matrix, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { Geometry } from '@babylonjs/core/Meshes/geometry';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { Node } from '@babylonjs/core/node';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { getBinClampedSize } from '@common-util/texture-util';\r\nimport { AsyncZippable, AsyncZippableFile, strToU8 } from 'fflate';\r\nimport { map, take } from 'rxjs/operators';\r\nimport { SceneNode } from '../../../models/classes/scene-node';\r\nimport { eWorkerTasks, Kb3dWorker } from '../../kb-worker';\r\nimport {\r\n buildHeader,\r\n buildUSDAFile,\r\n buildXform,\r\n ConversionResult,\r\n escapeGUID,\r\n GeometryConversionPayload,\r\n GeometryTransferrable,\r\n PRECISION,\r\n TypedArray,\r\n USDOpts,\r\n USDZConverter\r\n} from './usdz-converter';\r\n\r\nconst canvasResize = document.createElement('canvas');\r\n\r\nexport class USDZBabylonConverter extends USDZConverter {\r\n parse(scene: Scene, sceneNode: SceneNode, useWorker = false) {\r\n const toCleanup: Array = [];\r\n const files: Record = {};\r\n const modelFileName = 'model.usda'; // model file should be first in USDZ archive so we init it here\r\n\r\n files[modelFileName] = new Uint8Array(0);\r\n let output = buildHeader(sceneNode);\r\n const materials: Record = {};\r\n const textures: Record = {};\r\n\r\n const conversionWorker = useWorker ? new Kb3dWorker() : null;\r\n const asyncGenerators: Array> = [];\r\n\r\n scene.meshes.forEach(mesh => {\r\n if (\r\n mesh instanceof Mesh &&\r\n mesh.isEnabled() &&\r\n mesh.visibility > 0 &&\r\n mesh.geometry &&\r\n !(mesh instanceof LinesMesh) &&\r\n // for filtering out skyboxes\r\n !mesh.infiniteDistance\r\n ) {\r\n let subMeshes: Array>;\r\n let geometries: Array>;\r\n let meshMaterials: Array>;\r\n const baseGeometry = mesh.geometry;\r\n\r\n if (mesh.subMeshes && mesh.subMeshes.length > 1) {\r\n const splitGeometryByMaterialId = new Map<\r\n Material,\r\n { indices: number[]; positions: number[]; normals: number[]; uvs: number[] }\r\n >();\r\n\r\n const baseVertexData = VertexData.ExtractFromGeometry(baseGeometry);\r\n mesh.subMeshes.forEach((subMesh, index) => {\r\n const subMeshMaterial: Nullable = subMesh.getMaterial();\r\n if (subMeshMaterial) {\r\n let vertexData = splitGeometryByMaterialId.get(subMeshMaterial);\r\n if (!vertexData) {\r\n vertexData = { indices: [], positions: [], normals: [], uvs: [] };\r\n splitGeometryByMaterialId.set(subMeshMaterial, vertexData);\r\n }\r\n // Add polygons from this submesh to the mesh for this material\r\n let newIdx = vertexData.indices.length;\r\n const endIndex = subMesh.indexStart + subMesh.indexCount;\r\n for (let i = subMesh.indexStart; i < endIndex; i++) {\r\n if (baseVertexData.indices && baseVertexData.indices[i] !== undefined) {\r\n const oldIdx = baseVertexData.indices[i];\r\n\r\n vertexData.indices.push(newIdx);\r\n const i2 = oldIdx * 2;\r\n const i3 = oldIdx * 3;\r\n if (\r\n baseVertexData.positions &&\r\n typeof baseVertexData.positions[i3] !== 'undefined'\r\n ) {\r\n vertexData.positions.push(\r\n baseVertexData.positions[i3],\r\n baseVertexData.positions[i3 + 1],\r\n baseVertexData.positions[i3 + 2]\r\n );\r\n }\r\n if (baseVertexData.normals && typeof baseVertexData.normals[i3] !== 'undefined') {\r\n vertexData.normals.push(\r\n baseVertexData.normals[i3],\r\n baseVertexData.normals[i3 + 1],\r\n baseVertexData.normals[i3 + 2]\r\n );\r\n }\r\n if (baseVertexData.uvs && typeof baseVertexData.uvs[i2] !== 'undefined') {\r\n vertexData.uvs.push(baseVertexData.uvs[i2], baseVertexData.uvs[i2 + 1]);\r\n }\r\n\r\n newIdx++;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n });\r\n\r\n subMeshes = [];\r\n geometries = [];\r\n meshMaterials = [];\r\n splitGeometryByMaterialId.forEach((vertexData, material) => {\r\n if (material instanceof PBRMaterial) {\r\n const newMesh = mesh.clone();\r\n newMesh.id = mesh.id + '__' + material.id;\r\n newMesh.material = material;\r\n const newVertexData = new VertexData();\r\n newVertexData.indices = vertexData.indices;\r\n newVertexData.positions = vertexData.positions;\r\n newVertexData.normals = vertexData.normals;\r\n newVertexData.uvs = vertexData.uvs;\r\n const newGeometry = Geometry.CreateGeometryForMesh(newMesh);\r\n newGeometry.id = `sub-${newMesh.id}`;\r\n newVertexData.applyToGeometry(newGeometry);\r\n subMeshes.push(newMesh);\r\n geometries.push(newGeometry);\r\n meshMaterials.push(material);\r\n toCleanup.push(newGeometry, newMesh);\r\n } else {\r\n console.warn(`USDZExporter: No PBR material on submesh`);\r\n }\r\n });\r\n } else {\r\n subMeshes = [mesh];\r\n geometries = [baseGeometry];\r\n if (mesh.material instanceof PBRMaterial) {\r\n meshMaterials = [mesh.material];\r\n } else {\r\n meshMaterials = [];\r\n console.warn('USDZExporter: No PBR material on mesh');\r\n }\r\n }\r\n\r\n for (let i = 0; i < geometries.length; i++) {\r\n const subMesh = subMeshes[i];\r\n const geometry = geometries[i];\r\n const meshMaterial = meshMaterials[i];\r\n if (!subMesh || !geometry || !meshMaterial) {\r\n continue;\r\n }\r\n\r\n // const appendFileName = `__${i}`;\r\n const geometryFileName = 'geometries/Geometry__' + escapeGUID(geometry.id) + '.usd';\r\n\r\n if (!(geometryFileName in files)) {\r\n if (conversionWorker) {\r\n const geometryData = buildGeometryTransferrable(\r\n { unitsPerMeter: sceneNode.unitsPerMeter, xrAllowScaling: sceneNode.xrAllowScaling },\r\n geometry\r\n );\r\n if (geometryData) {\r\n asyncGenerators.push(\r\n conversionWorker\r\n .startTask(\r\n eWorkerTasks.usdConvertGeometry,\r\n geometryData.payload,\r\n geometryData.transfer\r\n )\r\n .pipe(\r\n take(1),\r\n map(res => {\r\n files[geometryFileName] = res.payload.file;\r\n })\r\n )\r\n .toPromise()\r\n );\r\n }\r\n } else {\r\n const meshObject = this.buildGeometryFromObject(geometry);\r\n files[geometryFileName] = buildUSDAFile(sceneNode, meshObject);\r\n }\r\n }\r\n\r\n if (!(meshMaterial.id in meshMaterial)) {\r\n materials[meshMaterial.id] = meshMaterial;\r\n }\r\n\r\n output += buildXform(subMesh, geometry, meshMaterial);\r\n }\r\n }\r\n });\r\n\r\n output += buildMaterials(materials, textures);\r\n files[modelFileName] = strToU8(output);\r\n const textureGenerators: Array<() => Promise> = [];\r\n for (const id in textures) {\r\n const texture = textures[id];\r\n const color = id.match(/[0-9A-F]{6}$/);\r\n const color3 = color && color.length === 1 ? Color3.FromHexString(`#${color[0]}`) : undefined;\r\n const isRGBA = texture.hasAlpha;\r\n textureGenerators.push(() =>\r\n processImageData(texture, isRGBA ? 'image/png' : 'image/jpeg', color3)\r\n .then(blob => {\r\n if (blob) {\r\n return blob.arrayBuffer();\r\n }\r\n })\r\n .then(buffer => {\r\n if (buffer) {\r\n files[`textures/Texture__${id}.${isRGBA ? 'png' : 'jpg'}`] = new Uint8Array(buffer);\r\n }\r\n })\r\n );\r\n } // 64 byte alignment\r\n // https://github.com/101arrowz/fflate/issues/39#issuecomment-777263109\r\n\r\n return Promise.all([processSequentially(asyncGenerators), processSequentially(textureGenerators)])\r\n .then(() => {\r\n let offset = 0;\r\n\r\n for (const filename in files) {\r\n const file = files[filename] as Uint8Array;\r\n const headerSize = 34 + filename.length;\r\n offset += headerSize;\r\n const offsetMod64 = offset & 63;\r\n\r\n if (offsetMod64 !== 4) {\r\n const padLength = 64 - offsetMod64;\r\n const padding = new Uint8Array(padLength);\r\n files[filename] = [\r\n file,\r\n {\r\n extra: {\r\n 12345: padding,\r\n },\r\n },\r\n ];\r\n }\r\n\r\n offset = file.length;\r\n }\r\n\r\n if (conversionWorker) {\r\n const transfer: ArrayBuffer[] = [];\r\n for (const fileName in files) {\r\n const file = files[fileName];\r\n if (file instanceof Uint8Array) {\r\n transfer.push(file.buffer);\r\n } else {\r\n transfer.push(file[0].buffer);\r\n }\r\n }\r\n\r\n return conversionWorker\r\n .startTask(eWorkerTasks.usdPackage, files, transfer)\r\n .pipe(\r\n take(1),\r\n map(res => {\r\n canvasResize.width = 0;\r\n canvasResize.height = 0;\r\n conversionWorker.dispose();\r\n return res.payload;\r\n })\r\n )\r\n .toPromise();\r\n } else {\r\n return this.zipUSDZFiles(files);\r\n }\r\n })\r\n .then(res => {\r\n toCleanup.forEach(item => item.dispose());\r\n return res;\r\n });\r\n }\r\n}\r\n\r\nasync function processSequentially(cbs: Array | (() => Promise)>) {\r\n const result: T[] = [];\r\n for (const cb of cbs) {\r\n if (cb instanceof Promise) {\r\n result.push(await cb);\r\n } else {\r\n result.push(await cb());\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\nexport function processImageData(texture: Texture, mimeType: string, color?: Color3): Promise {\r\n if (texture instanceof DynamicTexture) {\r\n const context = texture.getContext();\r\n\r\n const targetTexureSize = getBinClampedSize(context.canvas.width, context.canvas.height);\r\n canvasResize.width = targetTexureSize;\r\n canvasResize.height = targetTexureSize;\r\n\r\n const resizeContext = canvasResize.getContext('2d')!;\r\n const canvas = context.canvas;\r\n\r\n if (!(canvas instanceof HTMLCanvasElement)) {\r\n throw Error('texture does not have a canvas');\r\n }\r\n\r\n resizeContext.drawImage(canvas, 0, 0, targetTexureSize, targetTexureSize);\r\n\r\n if (color) {\r\n const imagedata = resizeContext.getImageData(0, 0, targetTexureSize, targetTexureSize);\r\n const data = imagedata.data;\r\n for (let i = 0; i < data.length; i += 4) {\r\n data[i + 0] = data[i + 0] * color.r;\r\n data[i + 1] = data[i + 1] * color.g;\r\n data[i + 2] = data[i + 2] * color.b;\r\n }\r\n resizeContext.putImageData(imagedata, 0, 0);\r\n }\r\n\r\n return canvasToBlob(canvasResize, mimeType);\r\n } else {\r\n const size = texture.getSize();\r\n\r\n const dataPromise = texture.readPixels() as Promise;\r\n if (!dataPromise) {\r\n return Promise.resolve(undefined);\r\n }\r\n\r\n return dataPromise.then(data => {\r\n if (data instanceof Float32Array || data instanceof Float64Array) {\r\n for (let i = 0; i < data.length; i += 4) {\r\n data[i + 0] = data[i + 0] * 255;\r\n data[i + 1] = data[i + 1] * 255;\r\n data[i + 2] = data[i + 2] * 255;\r\n data[i + 3] = data[i + 3] * 255;\r\n }\r\n }\r\n\r\n let targetTexureSize = getBinClampedSize(size.width, size.height);\r\n if (targetTexureSize > 1024) {\r\n targetTexureSize = 1024;\r\n }\r\n\r\n canvasResize.width = targetTexureSize;\r\n canvasResize.height = targetTexureSize;\r\n\r\n const pxLength = targetTexureSize * targetTexureSize;\r\n const resizedData = new Uint8ClampedArray(pxLength * 4);\r\n if (targetTexureSize !== size.width || targetTexureSize !== size.height) {\r\n const widthRatio = size.width / targetTexureSize;\r\n const heightRatio = size.height / targetTexureSize;\r\n // in the interest of speed, just downscale with nearest neighbor algorithm instead of averaging pixels.\r\n for (let i = 0; i < pxLength; i++) {\r\n const x = i % targetTexureSize;\r\n // Y must be flipped for USDZ output\r\n const y = Math.floor(targetTexureSize - i / targetTexureSize);\r\n const targetIndex = (Math.floor(x * widthRatio) + Math.floor(y * heightRatio) * size.width) * 4;\r\n const destIndex = i * 4;\r\n resizedData[destIndex + 0] = data[targetIndex + 0];\r\n resizedData[destIndex + 1] = data[targetIndex + 1];\r\n resizedData[destIndex + 2] = data[targetIndex + 2];\r\n resizedData[destIndex + 3] = data[targetIndex + 3];\r\n }\r\n } else {\r\n const lastLineOffset = (targetTexureSize - 1) * targetTexureSize;\r\n for (let y = 0; y < targetTexureSize / 2; y++) {\r\n const yOffset = y * targetTexureSize;\r\n const yOffsetTarget = lastLineOffset - yOffset;\r\n for (let x = 0; x < targetTexureSize; x++) {\r\n const offset = (yOffset + x) * 4;\r\n const offsetTarget = (yOffsetTarget + x) * 4;\r\n resizedData[offset] = data[offsetTarget];\r\n resizedData[offset + 1] = data[offsetTarget + 1];\r\n resizedData[offset + 2] = data[offsetTarget + 2];\r\n resizedData[offset + 3] = data[offsetTarget + 3];\r\n resizedData[offsetTarget] = data[offset];\r\n resizedData[offsetTarget + 1] = data[offset + 1];\r\n resizedData[offsetTarget + 2] = data[offset + 2];\r\n resizedData[offsetTarget + 3] = data[offset + 3];\r\n }\r\n }\r\n }\r\n\r\n if (color) {\r\n for (let i = 0; i < resizedData.length; i += 4) {\r\n resizedData[i + 0] = resizedData[i + 0] * color.r;\r\n resizedData[i + 1] = resizedData[i + 1] * color.g;\r\n resizedData[i + 2] = resizedData[i + 2] * color.b;\r\n }\r\n }\r\n\r\n const imageData = new ImageData(resizedData, targetTexureSize, targetTexureSize);\r\n\r\n const resizeContext = canvasResize.getContext('2d')!;\r\n resizeContext.putImageData(imageData, 0, 0);\r\n\r\n return canvasToBlob(canvasResize, mimeType);\r\n });\r\n }\r\n}\r\n\r\nfunction canvasToBlob(canvasResize: HTMLCanvasElement, mimeType: string) {\r\n return new Promise((resolve, reject) => {\r\n canvasResize.toBlob(\r\n result => {\r\n if (result) {\r\n resolve(result);\r\n }\r\n reject('Could not generate texture');\r\n },\r\n mimeType,\r\n 1\r\n );\r\n });\r\n}\r\n\r\nfunction buildMaterials(materials: Record, textures: Record) {\r\n const array = [];\r\n\r\n for (const uuid in materials) {\r\n const material = materials[uuid];\r\n array.push(buildMaterial(material, textures));\r\n }\r\n\r\n return `def \"Materials\"\r\n{\r\n${array.join('')}\r\n}\r\n`;\r\n}\r\n\r\nfunction buildMaterial(material: PBRMaterial, textures: Record) {\r\n // https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html\r\n const pad = ' ';\r\n const inputs: string[] = [];\r\n const samplers: string[] = [];\r\n const materialId = escapeGUID(material.id);\r\n\r\n const newV = new Vector3();\r\n const tMatrix = new Matrix();\r\n const t2Matrix = new Matrix();\r\n const t3Matrix = new Matrix();\r\n\r\n function buildTexture(texture: BaseTexture, mapType: string, color?: Color3) {\r\n if (texture instanceof Texture) {\r\n const textureName = escapeGUID(texture.name);\r\n const parsedTextureId = textureName + (color ? '__' + color.toHexString().substring(1) : '');\r\n textures[parsedTextureId] = texture;\r\n const angleDeg = (texture.wAng * 180) / Math.PI;\r\n\r\n // USD doesn't seem to have a good way to apply a matrix to a texture. But we can use the rotation and scale straight,\r\n // and grab the translation off of the babylon texture matrix. The matrix includes the rotation pivot related translation\r\n // which is nasty to calculate without a matrix and USD doesn't support UV Pivot\r\n const textureMatrix = texture.getTextureMatrix().m;\r\n Matrix.RotationYawPitchRollToRef(texture.vAng, texture.uAng, texture.wAng, tMatrix);\r\n Matrix.ScalingToRef(texture.uScale, texture.vScale, 1, t2Matrix);\r\n tMatrix.multiplyToRef(t2Matrix, t3Matrix);\r\n t3Matrix.invert();\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(textureMatrix[8], textureMatrix[9], 0, t3Matrix, newV);\r\n\r\n return `\r\n def Shader \"Transform2d_${mapType}\" (\r\n sdrMetadata = {\r\n string role = \"math\"\r\n }\r\n )\r\n {\r\n uniform token info:id = \"UsdTransform2d\"\r\n float2 inputs:in.connect = \r\n float2 inputs:scale = (${texture.uScale}, ${texture.vScale})\r\n float2 inputs:translation = (${newV.x}, ${newV.y})\r\n float inputs:rotation = ${angleDeg.toPrecision(PRECISION)}\r\n float2 outputs:result\r\n }\r\n def Shader \"Texture__${textureName}_${mapType}\"\r\n {\r\n uniform token info:id = \"UsdUVTexture\"\r\n asset inputs:file = @./textures/Texture__${parsedTextureId}.${texture.hasAlpha ? 'png' : 'jpg'}@\r\n float2 inputs:st.connect = \r\n token inputs:wrapS = \"repeat\"\r\n token inputs:wrapT = \"repeat\"\r\n float outputs:r\r\n float outputs:g\r\n float outputs:b\r\n ${texture.hasAlpha ? 'float outputs:a' : ''}\r\n float3 outputs:rgb\r\n }`;\r\n }\r\n\r\n return '';\r\n }\r\n\r\n if (material.albedoTexture) {\r\n inputs.push(\r\n `${pad}color3f inputs:diffuseColor.connect = `\r\n );\r\n samplers.push(buildTexture(material.albedoTexture, 'diffuse', material.albedoColor));\r\n } else {\r\n inputs.push(`${pad}color3f inputs:diffuseColor = ${buildColor(material.albedoColor)}`);\r\n }\r\n\r\n if (material.emissiveTexture) {\r\n inputs.push(\r\n `${pad}color3f inputs:emissiveColor.connect = `\r\n );\r\n samplers.push(buildTexture(material.emissiveTexture, 'emissive'));\r\n } else if (material.emissiveColor.toLuminance() > 0) {\r\n inputs.push(`${pad}color3f inputs:emissiveColor = ${buildColor(material.emissiveColor)}`);\r\n }\r\n\r\n if (material.bumpTexture) {\r\n inputs.push(\r\n `${pad}normal3f inputs:normal.connect = `\r\n );\r\n samplers.push(buildTexture(material.bumpTexture, 'normal'));\r\n }\r\n\r\n if (material.ambientTexture !== null) {\r\n inputs.push(\r\n `${pad}float inputs:occlusion.connect = `\r\n );\r\n samplers.push(buildTexture(material.ambientTexture, 'occlusion'));\r\n }\r\n\r\n if (material.microSurfaceTexture !== null && material.roughness === 1) {\r\n inputs.push(\r\n `${pad}float inputs:roughness.connect = `\r\n );\r\n samplers.push(buildTexture(material.microSurfaceTexture, 'roughness'));\r\n } else {\r\n inputs.push(`${pad}float inputs:roughness = ${material.roughness}`);\r\n }\r\n\r\n if (material.metallicTexture !== null && material.metallic === 1) {\r\n inputs.push(\r\n `${pad}float inputs:metallic.connect = `\r\n );\r\n samplers.push(buildTexture(material.metallicTexture, 'metallic'));\r\n } else {\r\n inputs.push(`${pad}float inputs:metallic = ${material.metallic}`);\r\n }\r\n\r\n if (material.opacityTexture !== null) {\r\n inputs.push(\r\n `${pad}float inputs:opacity.connect = `\r\n );\r\n inputs.push(`${pad}float inputs:opacityThreshold = 0.0001`);\r\n samplers.push(buildTexture(material.opacityTexture, 'opacity'));\r\n } else if (material.albedoTexture && material.albedoTexture.hasAlpha) {\r\n inputs.push(\r\n `${pad}float inputs:opacity.connect = `\r\n );\r\n inputs.push(`${pad}float inputs:opacityThreshold = 0.0001`);\r\n } else {\r\n inputs.push(`${pad}float inputs:opacity = ${material.alpha}`);\r\n }\r\n\r\n if (material.clearCoat && material.clearCoat.isEnabled) {\r\n inputs.push(`${pad}float inputs:clearcoat = ${material.clearCoat.intensity}`);\r\n inputs.push(`${pad}float inputs:clearcoatRoughness = ${material.clearCoat.roughness}`);\r\n // TODO More properties?\r\n }\r\n inputs.push(`${pad}float inputs:ior = ${material.indexOfRefraction}`);\r\n // TODO More properties?\r\n\r\n return `\r\n def Material \"Material__${materialId}\"\r\n {\r\n def Shader \"PreviewSurface\"\r\n {\r\n uniform token info:id = \"UsdPreviewSurface\"\r\n${inputs.join('\\n')}\r\n int inputs:useSpecularWorkflow = 0\r\n token outputs:surface\r\n }\r\n token outputs:surface.connect = \r\n token inputs:frame:stPrimvarName = \"st\"\r\n def Shader \"uvReader_st\"\r\n {\r\n uniform token info:id = \"UsdPrimvarReader_float2\"\r\n token inputs:varname.connect = \r\n float2 inputs:fallback = (0.0, 0.0)\r\n float2 outputs:result\r\n }\r\n${samplers.join('\\n')}\r\n }\r\n`;\r\n}\r\n\r\nfunction buildGeometryTransferrable(options: USDOpts, geometry: Geometry): GeometryTransferrable | undefined {\r\n const transfer: ArrayBuffer[] = [];\r\n const geometryBuffers = geometry.getVertexBuffers();\r\n const indices = geometry.getIndices();\r\n if (geometryBuffers && indices) {\r\n const vertexBuffers = Object.keys(geometryBuffers).reduce((res, type) => {\r\n const data = geometryBuffers[type].getData()!;\r\n\r\n if ('buffer' in data) {\r\n res[type] = data as Float32Array;\r\n transfer.push(res[type].slice().buffer);\r\n } else if (data instanceof ArrayBuffer || 'length' in data) {\r\n res[type] = new Float32Array(data);\r\n transfer.push(res[type].buffer);\r\n } else {\r\n console.warn('Unsupported geometry');\r\n }\r\n\r\n return res;\r\n }, {} as { [index: string]: Float32Array });\r\n\r\n const indexBuffer = Array.isArray(indices) ? new Uint32Array(indices) : indices;\r\n\r\n transfer.push(indexBuffer.slice().buffer);\r\n\r\n const result: GeometryTransferrable = {\r\n payload: {\r\n options,\r\n id: geometry.id,\r\n indices: indexBuffer,\r\n vertexBuffers,\r\n },\r\n transfer,\r\n };\r\n\r\n return result;\r\n }\r\n}\r\n\r\nfunction buildColor(color: Color3) {\r\n return `(${color.r}, ${color.g}, ${color.b})`;\r\n}\r\n","import { Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { WebXRSessionManager } from '@babylonjs/core/XR/webXRSessionManager';\r\n\r\nexport interface IXrHitResult {\r\n position: Vector3;\r\n rotation: Quaternion;\r\n matrix: Matrix;\r\n xrResult: XRHitTestResult;\r\n}\r\n\r\nexport class XrHitTester {\r\n constructor(public sessionMgr: WebXRSessionManager) {}\r\n\r\n /** holds the hit test source which is filled after initialize() has been called */\r\n public source: XRHitTestSource | undefined;\r\n /** temp variables for saving memory while processing hit results */\r\n private _tmpPos = new Vector3();\r\n private _tmpMat = new Matrix();\r\n private _tmpQuat = new Quaternion();\r\n\r\n public initialize(offsetRay?: XRRay) {\r\n const session = this.sessionMgr.session;\r\n\r\n //setup initial hit testing source\r\n if (session) {\r\n return session.requestHitTestSource!({\r\n space: this.sessionMgr.viewerReferenceSpace, //we use the viewer ref space for the source\r\n offsetRay: offsetRay,\r\n }).then(hitSource => {\r\n return (this.source = hitSource);\r\n });\r\n }\r\n }\r\n\r\n public getHitResult(frame: XRFrame): IXrHitResult | undefined {\r\n if (!this.source) return;\r\n\r\n const hits = frame.getHitTestResults(this.source);\r\n if (!hits.length) return;\r\n\r\n const hit = hits[0]; //only concentrate on the first hit... might want to reconsider this later\r\n return XrHitTester.FromXRHitTestResult(hit, this.sessionMgr.referenceSpace);\r\n\r\n // // Check that the y-coordinate of the normal is large enough that the normal\r\n // // is pointing up.\r\n // return hitMatrix hitMatrix.elements[5] > 0.75 ?\r\n // hitPosition.setFromMatrixPosition(hitMatrix) :\r\n // null;\r\n }\r\n\r\n public static FromXRHitTestResult(hit: XRHitTestResult, refSpace: XRSpace) {\r\n const pose = hit.getPose(refSpace);\r\n if (pose == null) return;\r\n\r\n const xrpos = pose.transform.position;\r\n const xrquat = pose.transform.orientation;\r\n const mat = new Matrix();\r\n Matrix.FromFloat32ArrayToRefScaled(pose.transform.matrix, 0, 1, mat);\r\n\r\n return {\r\n position: new Vector3(xrpos.x, xrpos.y, xrpos.z),\r\n rotation: new Quaternion(xrquat.x, xrquat.y, xrquat.z, xrquat.w),\r\n matrix: mat,\r\n xrResult: hit,\r\n } as IXrHitResult;\r\n }\r\n\r\n public dispose() {\r\n if (this.source) {\r\n this.source.cancel();\r\n this.source = undefined;\r\n }\r\n }\r\n}\r\n","import { DirectionalLight, ShadowLight } from '@babylonjs/core/Lights';\r\nimport { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';\r\nimport { Matrix, Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { eShadowFilter, eShadowResolution } from '@models/classes/enums';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { BoundingBoxCache, BoundingBoxInfo } from '@view/modules/bounding-box-cache';\r\nimport { Subscription } from 'rxjs';\r\n\r\n/**\r\n * Manages shadow generators and their association with lights and meshes that participate\r\n */\r\nexport class ShadowManager {\r\n constructor(private _bbCache: BoundingBoxCache) {\r\n this._bbCache.rootBoundingBoxChanged.subscribe(bbInfo => {\r\n //invalidate our projection matrix cache\r\n this.projectionMatrixCache.clear();\r\n });\r\n }\r\n\r\n private generatorMap = new Map();\r\n /** the meshes that are casting shadows. The mesh renderer adds and removes them from this list as their boolean flag is changed */\r\n private casters = new Set();\r\n /** the meshes that are receiving shadows. The mesh renderer adds and removes them from this list as their boolean flag is changed */\r\n private receivers = new Set();\r\n /**\r\n * Stores the calculated shadow projection matrix for directional lights. This cache is invalidated when\r\n * the root scene bounding box has changed or meshes change their casting / receiving flags.\r\n *\r\n * By default, babylon calculates the projection matrix of the shadows on every frame.\r\n * To be more efficient, we cache the projection matrix until something that warrants updating it happens.\r\n */\r\n private projectionMatrixCache = new Map();\r\n\r\n private bbSubscription: Subscription;\r\n /**\r\n * Add a shadow generator for the given light. Should only be called when the light.generatesShadows is set to true\r\n * @param light\r\n */\r\n public add(light: ShadowLight, shadowResolution: eShadowResolution) {\r\n let sg = this.get(light);\r\n if (!sg) {\r\n sg = new ShadowGenerator(ShadowManager.convertShadowResultion(shadowResolution), light);\r\n this.generatorMap.set(light, sg);\r\n this.addAllCastersToGenerator(sg);\r\n if (light instanceof DirectionalLight) {\r\n /**\r\n * Directional lights are tricky, as their light shadow fulstrum needs to be the optimal size for the shadows to look good.\r\n * The built-in calculation of the projection matrix does not account for meshes that are receiving shadows. So we override\r\n * the calculation here. It also gives us a way to cache and increase performance.\r\n */\r\n light.autoUpdateExtends = false;\r\n light.autoCalcShadowZBounds = false;\r\n light.customProjectionMatrixBuilder = (\r\n viewMatrix: Matrix,\r\n renderList: AbstractMesh[],\r\n matrix: Matrix\r\n ) => {\r\n return this.customProjectionMatrixBuilder(light, viewMatrix, renderList, matrix);\r\n };\r\n }\r\n }\r\n return sg;\r\n }\r\n\r\n /**\r\n * Get the shadow generator for a specific light (if it has one)\r\n * @param light\r\n */\r\n public get(light: ShadowLight) {\r\n return this.generatorMap.get(light);\r\n }\r\n\r\n /** Remove the shadow generator for the given light */\r\n public remove(light: ShadowLight) {\r\n const sg = this.get(light);\r\n (light as any).customProjectionMatrixBuilder = undefined;\r\n if (sg) {\r\n this.generatorMap.delete(light);\r\n sg.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * Adds a mesh as a shadow caster. Should only be called by the mesh renderer when the meshNode.castShadows flag is changed to true\r\n */\r\n public addCaster(mesh: AbstractMesh) {\r\n if (!this.casters.has(mesh)) {\r\n this.casters.add(mesh);\r\n for (const sg of this.generatorMap.values()) {\r\n sg.addShadowCaster(mesh);\r\n }\r\n this.projectionMatrixCache.clear();\r\n }\r\n }\r\n\r\n /**\r\n * Removes a mesh as a shadow caster. Should only be called by the mesh renderer when the meshNode.castShadows flag is changed to false\r\n */\r\n public removeCaster(mesh: AbstractMesh) {\r\n if (this.casters.has(mesh)) {\r\n this.casters.delete(mesh);\r\n for (const sg of this.generatorMap.values()) {\r\n sg.removeShadowCaster(mesh);\r\n }\r\n this.projectionMatrixCache.clear();\r\n }\r\n }\r\n\r\n /**\r\n * Adds/removes the mesh as a shadow caster\r\n * @param mesh\r\n * @param value\r\n */\r\n public toggleCaster(mesh: Mesh, value: boolean) {\r\n if (value) {\r\n this.addCaster(mesh);\r\n } else {\r\n this.removeCaster(mesh);\r\n }\r\n }\r\n\r\n protected addAllCastersToGenerator(sg: ShadowGenerator) {\r\n for (const c of this.casters.values()) {\r\n sg.addShadowCaster(c);\r\n }\r\n }\r\n\r\n public addReceiver(mesh: AbstractMesh) {\r\n if (!this.receivers.has(mesh)) {\r\n this.receivers.add(mesh);\r\n this.projectionMatrixCache.clear();\r\n }\r\n }\r\n\r\n public removeReceiver(mesh: AbstractMesh) {\r\n if (this.receivers.has(mesh)) {\r\n this.receivers.delete(mesh);\r\n this.projectionMatrixCache.clear();\r\n }\r\n }\r\n\r\n public toggleReceiver(mesh: AbstractMesh, value: boolean) {\r\n if (value) {\r\n this.addReceiver(mesh);\r\n } else {\r\n this.removeReceiver(mesh);\r\n }\r\n }\r\n\r\n public dispose() {\r\n this.projectionMatrixCache.clear();\r\n for (const light of this.generatorMap.keys()) {\r\n this.remove(light);\r\n }\r\n }\r\n\r\n public clearProjectMatrixCache() {\r\n this.projectionMatrixCache.clear();\r\n }\r\n /**\r\n * Directional lights are tricky, as their light shadow fulstrum needs to be the optimal size for the shadows to look good.\r\n * The built-in calculation of the projection matrix does not account for meshes that are receiving shadows. So we override\r\n * the calculation here. It also gives us a way to cache and increase performance.\r\n *\r\n * This is based on the built-in DirectionalLight.prototype._setDefaultAutoExtendShadowProjectionMatrix\r\n * but with these additions:\r\n * * caching of the projection matrix\r\n * * inclusion of shadow receivers in the box calculation so shadows are not chopped off with PCSS\r\n * * uses the shadowOrthoScale of the light to increase the minZ/maxZ range to avoid z-fighting on planes at one of the extents of the box\r\n */\r\n protected customProjectionMatrixBuilder(\r\n light: DirectionalLight,\r\n viewMatrix: Matrix,\r\n renderList: AbstractMesh[],\r\n matrix: Matrix\r\n ) {\r\n if (this.projectionMatrixCache.has(light)) {\r\n matrix.copyFrom(this.projectionMatrixCache.get(light)!);\r\n } else {\r\n const allMeshes = new Set([...this.casters, ...this.receivers]);\r\n\r\n const shadowOrthoScale = light.shadowOrthoScale;\r\n let orthoLeft = Number.MAX_VALUE;\r\n let orthoRight = Number.MIN_VALUE;\r\n let orthoTop = Number.MIN_VALUE;\r\n let orthoBottom = Number.MAX_VALUE;\r\n let shadowMinZ = Number.MAX_VALUE;\r\n let shadowMaxZ = Number.MIN_VALUE;\r\n const tempVector3 = Vector3.Zero();\r\n\r\n //loop through each caster/reciever to build up the fulstrum box\r\n for (const m of allMeshes) {\r\n if (m.isEnabled(true)) {\r\n const node = getByDynamicId(m.id);\r\n let bbInfo: BoundingBoxInfo | undefined;\r\n if (node) {\r\n bbInfo = this._bbCache.get(node);\r\n } else {\r\n // //not a kb3d node, but could be a shadow plan in XR\r\n // let binfo = m.getBoundingInfo();\r\n // if (binfo){\r\n // bbInfo = toBoundingBoxInfo(binfo);\r\n // }\r\n }\r\n if (bbInfo) {\r\n const boundingBox = bbInfo.boundingInfo.boundingBox;\r\n for (let index = 0; index < boundingBox.vectorsWorld.length; index++) {\r\n Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);\r\n if (tempVector3.x < orthoLeft) {\r\n orthoLeft = tempVector3.x;\r\n }\r\n if (tempVector3.y < orthoBottom) {\r\n orthoBottom = tempVector3.y;\r\n }\r\n if (tempVector3.x > orthoRight) {\r\n orthoRight = tempVector3.x;\r\n }\r\n if (tempVector3.y > orthoTop) {\r\n orthoTop = tempVector3.y;\r\n }\r\n\r\n if (tempVector3.z < shadowMinZ) {\r\n shadowMinZ = tempVector3.z;\r\n }\r\n if (tempVector3.z > shadowMaxZ) {\r\n shadowMaxZ = tempVector3.z;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n const xOffset = orthoRight - orthoLeft;\r\n const yOffset = orthoTop - orthoBottom;\r\n\r\n /** for exponential blur, it works way better when the max z is alot larger than the scene to get soft shadows */\r\n const sg = this.get(light)!;\r\n if (sg.filter == ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP) {\r\n shadowMaxZ = shadowMaxZ * 50;\r\n }\r\n const zOffset = shadowMaxZ - shadowMinZ;\r\n\r\n Matrix.OrthoOffCenterLHToRef(\r\n orthoLeft - xOffset * shadowOrthoScale,\r\n orthoRight + xOffset * shadowOrthoScale,\r\n orthoBottom - yOffset * shadowOrthoScale,\r\n orthoTop + yOffset * shadowOrthoScale,\r\n /**\r\n * Babylon does not account for the orthoScale when calculating minZ/maxZ, which leads to shadow z fighting on planes receiving shadows.\r\n * So here we change this behavior to offset by the scale just like left/right/top/bottom\r\n */\r\n shadowMinZ - zOffset * shadowOrthoScale,\r\n shadowMaxZ + zOffset * shadowOrthoScale,\r\n matrix\r\n );\r\n\r\n this.projectionMatrixCache.set(light, matrix);\r\n // console.count(\"shadow manager processed\");\r\n }\r\n }\r\n\r\n public static convertShadowResultion(r: eShadowResolution) {\r\n switch (r) {\r\n case eShadowResolution.low:\r\n return 512;\r\n case eShadowResolution.medium:\r\n return 1024;\r\n case eShadowResolution.high:\r\n return 2048;\r\n }\r\n }\r\n\r\n public static convertShadowFilter(f: eShadowFilter) {\r\n switch (f) {\r\n case eShadowFilter.none:\r\n return ShadowGenerator.FILTER_NONE;\r\n case eShadowFilter.simple:\r\n return ShadowGenerator.FILTER_PCF;\r\n case eShadowFilter.advanced:\r\n return ShadowGenerator.FILTER_PCSS;\r\n }\r\n }\r\n}\r\n","import { DirectionalLight, Light, ShadowGenerator } from '@babylonjs/core/Lights';\r\nimport { Vector3 } from '@babylonjs/core/Maths';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eShadowResolution } from '@models/classes/enums';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { ShadowManager } from '@view/render/shadow-manager';\r\n\r\nexport class XrLight extends DirectionalLight {\r\n constructor(public v: KbViewer, public scene: Scene) {\r\n super('xrLight', new Vector3(0, -3, 0), scene);\r\n\r\n //turn all existing lights off and save their setting\r\n for (const l of scene.lights) {\r\n if (l !== this) {\r\n this._originalLightEnabledMap.set(l, l.isEnabled(false));\r\n l.setEnabled(false);\r\n }\r\n }\r\n\r\n this.position = this.direction.negate();\r\n this.intensity = 0.5;\r\n\r\n this._shadowManager = new ShadowManager(this.v.bbCache);\r\n this._sg = this._shadowManager.add(this, eShadowResolution.low);\r\n this._sg.setDarkness(0.3);\r\n this._sg.filter = ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP;\r\n // this._sg.blurBoxOffset = 10;\r\n // this._sg.blurScale = 2;\r\n\r\n this._sg.useKernelBlur = true;\r\n this._sg.blurKernel = 64; //64;\r\n this._sg.blurScale = 2;\r\n\r\n /**\r\n * Add all meshes from the scene to the shadow caster.\r\n * This includes the shadow plane so that extents are auto calculated to include it\r\n */\r\n const rootNode = this.v.rendererManager.sceneRenderer.get3d(this.v.sceneNode)!;\r\n for (const m of rootNode.getChildMeshes(false)) {\r\n if (m.name == 'xrShadowPlane') {\r\n this._shadowManager.addReceiver(m);\r\n } else {\r\n this._shadowManager.addCaster(m);\r\n }\r\n // console.log(`adding mesh '${m.name}' to shadow generator`);\r\n }\r\n }\r\n\r\n private _shadowManager: ShadowManager;\r\n private _sg: ShadowGenerator;\r\n private _originalLightEnabledMap = new Map();\r\n\r\n public setDirection(x: number, y: number, z: number) {\r\n this.direction.set(x, y, z);\r\n this.position = this.direction.negate();\r\n this._shadowManager.clearProjectMatrixCache();\r\n }\r\n\r\n public dispose() {\r\n for (const [l, e] of this._originalLightEnabledMap) {\r\n l.setEnabled(e);\r\n }\r\n this._originalLightEnabledMap.clear();\r\n if (this._shadowManager) this._shadowManager.dispose();\r\n (this._shadowManager as any) = undefined;\r\n (this._sg as any) = undefined;\r\n\r\n super.dispose();\r\n }\r\n}\r\n","import { Animation } from '@babylonjs/core/Animations/animation';\r\nimport { EasingFunction, SineEase } from '@babylonjs/core/Animations/easing';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3 } from '@babylonjs/core/Maths/math.color';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subscription } from 'rxjs';\r\nimport { BoundingBoxInfo } from '../bounding-box-cache';\r\n\r\nconst SEGMENTS = 12;\r\nconst RADIUS = 0.05;\r\nconst DELTA_PHI = Math.PI / (2 * SEGMENTS);\r\nconst LINE_WIDTH = 0.02;\r\nconst FRAME_RATE = 1 / 0.3;\r\n\r\nexport class XrMarker extends Mesh {\r\n constructor(public v: KbViewer, public scene: Scene, public naturalScale: number) {\r\n super('xrMarker', scene);\r\n\r\n if (!XrMarker.MarkerMaterial) {\r\n const m = (XrMarker.MarkerMaterial = new StandardMaterial('xrMarkerMaterial', this.scene));\r\n m.emissiveColor = Color3.White();\r\n m.disableLighting = true;\r\n m.backFaceCulling = false;\r\n m.alpha = 0.5;\r\n }\r\n this.material = XrMarker.MarkerMaterial;\r\n\r\n this.resize();\r\n }\r\n\r\n private subscription: Subscription = new Subscription();\r\n static MarkerMaterial: StandardMaterial;\r\n private _lineWidth: number;\r\n private _radius: number;\r\n /**\r\n * Whether the marker and model have been placed yet.\r\n * The marker is put inside the scene root node so it transforms with\r\n * the model once placed. So our calculations change based on that\r\n **/\r\n private _placed: boolean;\r\n\r\n public place(rootNode: TransformNode) {\r\n this.setParent(rootNode);\r\n this.rotation.set(0, 0, 0);\r\n this._placed = true;\r\n\r\n this.resize();\r\n this.hide();\r\n\r\n this.subscription.add(\r\n this.v.bbCache.rootBoundingBoxChanged.subscribe(bb => {\r\n this.resizeToBoundingBox(this.v.bbCache.getWorld(this.v.sceneNode)!);\r\n })\r\n );\r\n }\r\n\r\n public show() {\r\n this.animateVisibility(1, EasingFunction.EASINGMODE_EASEIN);\r\n }\r\n\r\n public hide() {\r\n this.animateVisibility(0, EasingFunction.EASINGMODE_EASEOUT);\r\n }\r\n\r\n private animateVisibility(to: number, easingFunction: number) {\r\n const a = new Animation('hide', 'visibility', FRAME_RATE, Animation.ANIMATIONTYPE_FLOAT);\r\n a.setKeys([\r\n {\r\n frame: 0,\r\n value: this.visibility,\r\n },\r\n {\r\n frame: 1,\r\n value: to,\r\n },\r\n ]);\r\n const easing = new SineEase();\r\n easing.setEasingMode(easingFunction);\r\n a.setEasingFunction(easing);\r\n this.scene.stopAnimation(this);\r\n this.scene.beginDirectAnimation(this, [a], 0, 1, false);\r\n }\r\n\r\n private resize() {\r\n const bb = this.v.bbCache.get(this.v.sceneNode)!;\r\n if (bb) {\r\n this.resizeToBoundingBox(bb);\r\n }\r\n }\r\n\r\n private resizeToBoundingBox(bb: BoundingBoxInfo) {\r\n let deltaZ: number;\r\n let deltaX: number;\r\n\r\n if (!this._placed) {\r\n deltaX = (bb.max.x - bb.min.x) * this.naturalScale;\r\n deltaZ = (bb.max.z - bb.min.z) * this.naturalScale;\r\n this._lineWidth = LINE_WIDTH;\r\n this._radius = RADIUS;\r\n } else {\r\n deltaX = bb.max.x - bb.min.x;\r\n deltaZ = bb.max.z - bb.min.z;\r\n this._lineWidth = LINE_WIDTH / this.naturalScale;\r\n this._radius = RADIUS / this.naturalScale;\r\n }\r\n\r\n const vertexData = this.getVertexData(deltaX, deltaZ);\r\n vertexData.applyToMesh(this, true);\r\n\r\n if (this._placed) {\r\n //it's in the root node now, so center to the root node local bb\r\n this.position.set(bb.center.x, 0, bb.center.z);\r\n }\r\n }\r\n\r\n protected getVertexData(xSize: number, zSize: number) {\r\n const vertices: number[] = [];\r\n const indices: number[] = [];\r\n const normals: number[] = [];\r\n\r\n const x = xSize / 2;\r\n const z = zSize / 2;\r\n this.addCorner(vertices, x, z);\r\n this.addCorner(vertices, -x, z);\r\n this.addCorner(vertices, -x, -z);\r\n this.addCorner(vertices, x, -z);\r\n\r\n const numVertices = vertices.length / 3;\r\n for (let i = 0; i < numVertices - 2; i += 2) {\r\n indices.push(i, i + 1, i + 3, i, i + 3, i + 2);\r\n }\r\n const i = numVertices - 2;\r\n indices.push(i, i + 1, 1, i, 1, 0);\r\n\r\n VertexData.ComputeNormals(vertices, indices, normals);\r\n const vdata = new VertexData();\r\n vdata.indices = indices;\r\n vdata.positions = vertices;\r\n vdata.normals = normals;\r\n\r\n return vdata;\r\n }\r\n\r\n protected addCorner(vertices: number[], cornerX: number, cornerZ: number) {\r\n let phi = cornerX > 0 ? (cornerZ > 0 ? 0 : -Math.PI / 2) : cornerZ > 0 ? Math.PI / 2 : Math.PI;\r\n for (let i = 0; i <= SEGMENTS; ++i) {\r\n vertices.push(\r\n cornerX + (this._radius - this._lineWidth) * Math.cos(phi),\r\n 0,\r\n cornerZ + (this._radius - this._lineWidth) * Math.sin(phi),\r\n cornerX + this._radius * Math.cos(phi),\r\n 0,\r\n cornerZ + this._radius * Math.sin(phi)\r\n );\r\n phi += DELTA_PHI;\r\n }\r\n }\r\n\r\n public dispose() {\r\n this.subscription.unsubscribe();\r\n super.dispose();\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"imageProcessingCompatibility\";\nconst shader = `#ifdef IMAGEPROCESSINGPOSTPROCESS\ngl_FragColor.rgb=pow(gl_FragColor.rgb,vec3(2.2));\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const imageProcessingCompatibility = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\nimport \"core/Shaders/ShadersInclude/helperFunctions\";\nimport \"core/Shaders/ShadersInclude/lightFragmentDeclaration\";\nimport \"core/Shaders/ShadersInclude/lightUboDeclaration\";\nimport \"core/Shaders/ShadersInclude/lightsFragmentFunctions\";\nimport \"core/Shaders/ShadersInclude/shadowsFragmentFunctions\";\nimport \"core/Shaders/ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"core/Shaders/ShadersInclude/fogFragmentDeclaration\";\nimport \"core/Shaders/ShadersInclude/clipPlaneFragment\";\nimport \"core/Shaders/ShadersInclude/lightFragment\";\nimport \"core/Shaders/ShadersInclude/fogFragment\";\nimport \"core/Shaders/ShadersInclude/imageProcessingCompatibility\";\n\nconst name = \"shadowOnlyPixelShader\";\nconst shader = `precision highp float;uniform vec4 vEyePosition;uniform float alpha;uniform vec3 shadowColor;varying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include\n#include\n#include\n#include\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;float shadow=1.;float glossiness=0.;\n#include[0..1]\nvec4 color=vec4(shadowColor,(1.0-clamp(shadow,0.,1.))*alpha);\n#include\ngl_FragColor=color;\n#include\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const shadowOnlyPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\nimport \"core/Shaders/ShadersInclude/bonesDeclaration\";\nimport \"core/Shaders/ShadersInclude/bakedVertexAnimationDeclaration\";\nimport \"core/Shaders/ShadersInclude/instancesDeclaration\";\nimport \"core/Shaders/ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"core/Shaders/ShadersInclude/fogVertexDeclaration\";\nimport \"core/Shaders/ShadersInclude/lightFragmentDeclaration\";\nimport \"core/Shaders/ShadersInclude/lightUboDeclaration\";\nimport \"core/Shaders/ShadersInclude/instancesVertex\";\nimport \"core/Shaders/ShadersInclude/bonesVertex\";\nimport \"core/Shaders/ShadersInclude/bakedVertexAnimation\";\nimport \"core/Shaders/ShadersInclude/clipPlaneVertex\";\nimport \"core/Shaders/ShadersInclude/fogVertex\";\nimport \"core/Shaders/ShadersInclude/shadowsVertex\";\n\nconst name = \"shadowOnlyVertexShader\";\nconst shader = `precision highp float;attribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include\n#include\n#include\nuniform mat4 view;uniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n#include\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include\n#include\n#include\nvec4 worldPos=finalWorld*vec4(position,1.0);gl_Position=viewProjection*worldPos;vPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#include\n#include\n#include[0..maxSimultaneousLights]\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const shadowOnlyVertexShader = { name, shader };\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { SerializationHelper } from \"core/Misc/decorators\";\r\nimport type { Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { IEffectCreationOptions } from \"core/Materials/effect\";\r\nimport { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialHelper } from \"core/Materials/materialHelper\";\r\nimport { PushMaterial } from \"core/Materials/pushMaterial\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"core/Meshes/subMesh\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\n\r\nimport \"./shadowOnly.fragment\";\r\nimport \"./shadowOnly.vertex\";\r\nimport { EffectFallbacks } from \"core/Materials/effectFallbacks\";\r\nimport type { CascadedShadowGenerator } from \"core/Lights/Shadows/cascadedShadowGenerator\";\r\nimport { addClipPlaneUniforms, bindClipPlane } from \"core/Materials/clipPlaneMaterialHelper\";\r\n\r\nclass ShadowOnlyMaterialDefines extends MaterialDefines {\r\n public CLIPPLANE = false;\r\n public CLIPPLANE2 = false;\r\n public CLIPPLANE3 = false;\r\n public CLIPPLANE4 = false;\r\n public CLIPPLANE5 = false;\r\n public CLIPPLANE6 = false;\r\n public POINTSIZE = false;\r\n public FOG = false;\r\n public NORMAL = false;\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public INSTANCES = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n\r\n constructor() {\r\n super();\r\n this.rebuild();\r\n }\r\n}\r\n\r\nexport class ShadowOnlyMaterial extends PushMaterial {\r\n private _activeLight: IShadowLight;\r\n private _needAlphaBlending = true;\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n }\r\n\r\n public shadowColor = Color3.Black();\r\n\r\n public needAlphaBlending(): boolean {\r\n return this._needAlphaBlending;\r\n }\r\n\r\n public needAlphaTesting(): boolean {\r\n return false;\r\n }\r\n\r\n public getAlphaTestTexture(): Nullable {\r\n return null;\r\n }\r\n\r\n public get activeLight(): IShadowLight {\r\n return this._activeLight;\r\n }\r\n\r\n public set activeLight(light: IShadowLight) {\r\n this._activeLight = light;\r\n }\r\n\r\n private _getFirstShadowLightForMesh(mesh: AbstractMesh): Nullable {\r\n for (const light of mesh.lightSources) {\r\n if (light.shadowEnabled) {\r\n return light as IShadowLight;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n // Methods\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n if (this.isFrozen) {\r\n if (subMesh.effect && subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n subMesh.materialDefines = new ShadowOnlyMaterialDefines();\r\n }\r\n\r\n const defines = subMesh.materialDefines;\r\n const scene = this.getScene();\r\n\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n // Ensure that active light is the first shadow light\r\n if (this._activeLight) {\r\n for (const light of mesh.lightSources) {\r\n if (light.shadowEnabled) {\r\n if (this._activeLight === light) {\r\n break; // We are good\r\n }\r\n\r\n const lightPosition = mesh.lightSources.indexOf(this._activeLight);\r\n\r\n if (lightPosition !== -1) {\r\n mesh.lightSources.splice(lightPosition, 1);\r\n mesh.lightSources.splice(0, 0, this._activeLight);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false);\r\n\r\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);\r\n\r\n defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);\r\n\r\n const shadowGenerator = this._getFirstShadowLightForMesh(mesh)?.getShadowGenerator();\r\n\r\n this._needAlphaBlending = true;\r\n\r\n if (shadowGenerator && (shadowGenerator as any).getClassName && (shadowGenerator as any).getClassName() === \"CascadedShadowGenerator\") {\r\n const csg = shadowGenerator as CascadedShadowGenerator;\r\n\r\n this._needAlphaBlending = !csg.autoCalcDepthBounds;\r\n }\r\n\r\n // Attribs\r\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);\r\n\r\n // Get correct effect\r\n if (defines.isDirty) {\r\n defines.markAsProcessed();\r\n\r\n scene.resetCachedMaterial();\r\n\r\n // Fallbacks\r\n const fallbacks = new EffectFallbacks();\r\n if (defines.FOG) {\r\n fallbacks.addFallback(1, \"FOG\");\r\n }\r\n\r\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);\r\n\r\n if (defines.NUM_BONE_INFLUENCERS > 0) {\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n }\r\n\r\n defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;\r\n\r\n //Attributes\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n if (defines.NORMAL) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\r\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\r\n\r\n const shaderName = \"shadowOnly\";\r\n const join = defines.toString();\r\n const uniforms = [\"world\", \"view\", \"viewProjection\", \"vEyePosition\", \"vLightsType\", \"vFogInfos\", \"vFogColor\", \"pointSize\", \"alpha\", \"shadowColor\", \"mBones\"];\r\n const samplers = new Array();\r\n\r\n const uniformBuffers = new Array();\r\n\r\n addClipPlaneUniforms(uniforms);\r\n MaterialHelper.PrepareUniformsAndSamplersList({\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: defines,\r\n maxSimultaneousLights: 1,\r\n });\r\n\r\n subMesh.setEffect(\r\n scene.getEngine().createEffect(\r\n shaderName,\r\n {\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters: { maxSimultaneousLights: 1 },\r\n },\r\n engine\r\n ),\r\n defines,\r\n this._materialContext\r\n );\r\n }\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = true;\r\n subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;\r\n\r\n return true;\r\n }\r\n\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n\r\n const defines = subMesh.materialDefines;\r\n if (!defines) {\r\n return;\r\n }\r\n\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n this._activeEffect = effect;\r\n\r\n // Matrices\r\n this.bindOnlyWorldMatrix(world);\r\n this._activeEffect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect);\r\n\r\n if (this._mustRebind(scene, effect)) {\r\n // Clip plane\r\n bindClipPlane(effect, this, scene);\r\n\r\n // Point size\r\n if (this.pointsCloud) {\r\n this._activeEffect.setFloat(\"pointSize\", this.pointSize);\r\n }\r\n\r\n this._activeEffect.setFloat(\"alpha\", this.alpha);\r\n this._activeEffect.setColor3(\"shadowColor\", this.shadowColor);\r\n\r\n scene.bindEyePosition(effect);\r\n }\r\n\r\n // Lights\r\n if (scene.lightsEnabled) {\r\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);\r\n\r\n const light = this._getFirstShadowLightForMesh(mesh);\r\n\r\n if (light) {\r\n // Make sure the uniforms for this light will be rebound for other materials using this light when rendering the current frame.\r\n // Indeed, there is an optimization in Light that binds the light uniforms only once per frame for a given light (if using ubo).\r\n // Doing this way assumes that all uses of this light are the same, meaning all parameters passed to Light._bindLlight\r\n // are the same, notably useSpecular. However, isReadyForSubMesh (see above) is passing false for this parameter, which may not be\r\n // the value the other materials may pass.\r\n light._renderId = -1;\r\n }\r\n }\r\n\r\n // View\r\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || defines[\"SHADOWCSM0\"]) {\r\n this._activeEffect.setMatrix(\"view\", scene.getViewMatrix());\r\n }\r\n\r\n // Fog\r\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n }\r\n\r\n public clone(name: string): ShadowOnlyMaterial {\r\n return SerializationHelper.Clone(() => new ShadowOnlyMaterial(name, this.getScene()), this);\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n serializationObject.customType = \"BABYLON.ShadowOnlyMaterial\";\r\n return serializationObject;\r\n }\r\n\r\n public getClassName(): string {\r\n return \"ShadowOnlyMaterial\";\r\n }\r\n\r\n // Statics\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ShadowOnlyMaterial {\r\n return SerializationHelper.Parse(() => new ShadowOnlyMaterial(source.name, scene), source, scene, rootUrl);\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ShadowOnlyMaterial\", ShadowOnlyMaterial);\r\n","import { Matrix, Quaternion } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { ShadowOnlyMaterial } from '@babylonjs/Materials/shadowOnly/shadowOnlyMaterial';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subscription } from 'rxjs';\r\nimport { BoundingBoxInfo } from '../bounding-box-cache';\r\n\r\n/** padding in size to make enough space for shadow blur */\r\nconst SIZE_RATIO = 4;\r\n\r\nexport class XrShadowPlane extends Mesh {\r\n constructor(public v: KbViewer, public scene: Scene) {\r\n super('xrShadowPlane', scene);\r\n\r\n this.receiveShadows = true;\r\n this.isPickable = false;\r\n this.shadowMaterial = new ShadowOnlyMaterial('xrShadowMaterial', scene);\r\n this.shadowMaterial.alpha = 0.4;\r\n\r\n this.material = this.shadowMaterial;\r\n // this.material = v.rendererManager.material.defaultMaterial;\r\n\r\n this.setEnabled(false);\r\n }\r\n\r\n private subscription: Subscription = new Subscription();\r\n private shadowMaterial: ShadowOnlyMaterial;\r\n\r\n public place(rootNode: TransformNode) {\r\n this.setParent(rootNode);\r\n\r\n const bbCache = this.v.bbCache;\r\n const bb = bbCache.get(this.v.sceneNode)!;\r\n if (bb) {\r\n this.resize(bb);\r\n this.setEnabled(true);\r\n\r\n this.subscription.add(\r\n bbCache.rootBoundingBoxChanged.subscribe(newBb => {\r\n this.resize(bb);\r\n })\r\n );\r\n }\r\n }\r\n\r\n protected resize(bb: BoundingBoxInfo) {\r\n const width = (bb.max.x - bb.min.x) * SIZE_RATIO;\r\n const height = (bb.max.z - bb.min.z) * SIZE_RATIO;\r\n\r\n const vertexData = VertexData.CreatePlane({\r\n width,\r\n height,\r\n sideOrientation: 0,\r\n });\r\n //bake in a 90 degree rotation so it's flat on the ground\r\n const rotMatrix = new Matrix();\r\n Quaternion.FromEulerAngles(Math.PI / 2, 0, 0).toRotationMatrix(rotMatrix);\r\n vertexData.transform(rotMatrix);\r\n vertexData.applyToMesh(this, true);\r\n\r\n this.position.set(bb.center.x, 0, bb.center.z);\r\n }\r\n\r\n public dispose() {\r\n this.subscription.unsubscribe();\r\n super.dispose();\r\n if (this.shadowMaterial) this.shadowMaterial.dispose();\r\n }\r\n}\r\n","import { WebXRSessionManager } from '@babylonjs/core/XR/webXRSessionManager';\r\nimport { IXrHitResult, XrHitTester } from './xr-hit-tester';\r\n\r\nexport interface IXrTransientHitResult {\r\n inputSource: XRInputSource;\r\n results: IXrHitResult[];\r\n}\r\n\r\nexport class XrTransientHitTester {\r\n constructor(public sessionMgr: WebXRSessionManager) {}\r\n\r\n /** holds the hit test source which is filled after initialize() has been called */\r\n public source: XRTransientInputHitTestSource | undefined;\r\n\r\n public initialize(offsetRay?: XRRay) {\r\n const session = this.sessionMgr.session;\r\n\r\n return session.requestHitTestSourceForTransientInput!({\r\n profile: 'generic-touchscreen',\r\n offsetRay: offsetRay,\r\n }).then(hitSource => {\r\n return (this.source = hitSource);\r\n });\r\n }\r\n\r\n public getFingers(frame: XRFrame): IXrTransientHitResult[] {\r\n if (!this.source) return [];\r\n\r\n const fingers = frame.getHitTestResultsForTransientInput(this.source);\r\n if (!fingers.length) return [];\r\n\r\n const convertedFingers = new Array();\r\n for (const f of fingers) {\r\n const r = {\r\n inputSource: f.inputSource,\r\n results: [],\r\n } as IXrTransientHitResult;\r\n convertedFingers.push(r);\r\n\r\n for (const hit of f.results) {\r\n const convertedHit = XrHitTester.FromXRHitTestResult(hit, this.sessionMgr.referenceSpace);\r\n if (convertedHit) r.results.push(convertedHit);\r\n }\r\n }\r\n\r\n return convertedFingers;\r\n }\r\n\r\n public dispose() {\r\n if (this.source) {\r\n this.source.cancel();\r\n this.source = undefined;\r\n }\r\n }\r\n}\r\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { PointerEventTypes } from '@babylonjs/core/Events/pointerEvents';\r\nimport { Quaternion, Vector2, Vector3 } from '@babylonjs/core/Maths';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { WebXRCamera } from '@babylonjs/core/XR/webXRCamera';\r\nimport { WebXRSessionManager } from '@babylonjs/core/XR/webXRSessionManager';\r\nimport { WebXRRenderTarget } from '@babylonjs/core/XR/webXRTypes';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eBackground } from '@models/classes/enums';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subject } from 'rxjs';\r\nimport { XrHitTester } from './xr-hit-tester';\r\nimport { XrLight } from './xr-light';\r\nimport { XrMarker } from './xr-marker';\r\nimport { XrShadowPlane } from './xr-shadow-plane';\r\nimport { IXrTransientHitResult, XrTransientHitTester } from './xr-transient-hit-tester';\r\n\r\n/**\r\n * Stub for future lighting estimation types\r\n */\r\ndeclare global {\r\n interface XRLightEstimate {\r\n readonly sphericalHarmonicsCoefficients: Float32Array;\r\n readonly primaryLightDirection: DOMPointReadOnly;\r\n readonly primaryLightIntensity: DOMPointReadOnly;\r\n }\r\n interface XRLightProbe {\r\n readonly probeSpace: XRSpace;\r\n }\r\n interface XRSession {\r\n requestLightProbe(): Promise;\r\n }\r\n interface XRFrame {\r\n getLightEstimate(lightProbe: XRLightProbe): XRLightEstimate;\r\n }\r\n}\r\n// interface XRSystem extends EventTarget {\r\n// requestSession(mode: XRSessionMode, options?: XRSessionInit): Promise;\r\n// isSessionSupported(mode: XRSessionMode): Promise;\r\n// }\r\n\r\n// declare global {\r\n// interface Navigator {\r\n// xr?: XRSystem;\r\n// }\r\n// }\r\n\r\nenum eXrState {\r\n searchingForHit,\r\n initialPlacement,\r\n placed,\r\n}\r\n\r\nconst ROTATION_RATE = 1.5;\r\nconst SCALE_SNAP = 1.2;\r\n\r\nexport class Xr {\r\n constructor(public v: KbViewer, public scene: Scene) {}\r\n\r\n public onSessionEnd = new Subject();\r\n private _sessionMgr: WebXRSessionManager;\r\n private _session: XRSession;\r\n private _renderTarget: WebXRRenderTarget;\r\n private _state = eXrState.searchingForHit;\r\n private _originalSceneCamera: Camera | null;\r\n private _originalBackground: eBackground;\r\n private _xrCamera: WebXRCamera;\r\n private _refSpace: XRReferenceSpace;\r\n private _initialHitTester: XrHitTester | undefined;\r\n private _transientHitTester: XrTransientHitTester | undefined;\r\n private _marker: XrMarker;\r\n private _light: XrLight;\r\n private _shadow: XrShadowPlane;\r\n private _rootNode: TransformNode;\r\n private _viewerPose: XRViewerPose | undefined;\r\n private _lastFrame: XRFrame | undefined;\r\n private _isTranslating: boolean;\r\n private _isRotating: boolean;\r\n private _isScaling: boolean;\r\n private _goalScale = 0;\r\n private _goalPosition: Vector3;\r\n private _goalYaw = 0;\r\n private _lastScalar = 0;\r\n private _dragNodeStartPos: Vector3 | undefined;\r\n private _selectStartScreenPos: Vector2 | undefined;\r\n private _fingerStartPos: Vector3 | undefined;\r\n private _dragHitTester: XrTransientHitTester | undefined;\r\n private _scaleSnapHigh: number = SCALE_SNAP;\r\n private _scaleSnapLow: number = 1 / SCALE_SNAP;\r\n private _naturalScale = 1;\r\n private _lightProbe: XRLightProbe | undefined;\r\n private _wasJustPlaced = false;\r\n private sessionEndingPromise?: Promise;\r\n\r\n public startSession(mode: XRSessionMode, refSpaceType: XRReferenceSpaceType, overlayElem?: HTMLElement) {\r\n const xrInitOptions = {\r\n optionalFeatures: ['light-estimation'],\r\n requiredFeatures: ['hit-test'],\r\n } as XRSessionInit;\r\n\r\n if (overlayElem) {\r\n overlayElem.addEventListener('beforexrselect', ev => {\r\n if (ev.target != overlayElem) {\r\n ev.preventDefault();\r\n }\r\n });\r\n xrInitOptions.optionalFeatures?.push('dom-overlay');\r\n (xrInitOptions as any).domOverlay = {\r\n root: overlayElem,\r\n };\r\n }\r\n if (refSpaceType !== 'viewer' && refSpaceType !== 'local') {\r\n xrInitOptions.optionalFeatures?.push(refSpaceType);\r\n }\r\n\r\n this._naturalScale = 1 / this.v.sceneNode.unitsPerMeter;\r\n this._sessionMgr = new WebXRSessionManager(this.scene);\r\n this._sessionMgr.onXRSessionEnded.addOnce(() => this.sessionEnded());\r\n\r\n this._xrCamera = new WebXRCamera('', this.scene, this._sessionMgr);\r\n\r\n return this._sessionMgr\r\n .initializeAsync()\r\n .then(() => {\r\n this._renderTarget = this._sessionMgr.getWebXRRenderTarget();\r\n return this._sessionMgr.initializeSessionAsync(mode, xrInitOptions).then(() => {\r\n this._session = this._sessionMgr.session;\r\n });\r\n })\r\n .then(() => {\r\n return this._sessionMgr.setReferenceSpaceTypeAsync(refSpaceType).then(refSpace => {\r\n this._refSpace = refSpace;\r\n });\r\n })\r\n .then(() => {\r\n return this._renderTarget.initializeXRLayerAsync(this._sessionMgr.session);\r\n })\r\n .then(() => {\r\n return this._sessionMgr.updateRenderState({\r\n depthFar: this._xrCamera!.maxZ,\r\n depthNear: this._xrCamera!.minZ,\r\n baseLayer: this._renderTarget.xrLayer!,\r\n });\r\n })\r\n .then(() => {\r\n this._rootNode = this.v.rendererManager.sceneRenderer.get3d(this.v.sceneNode)!; //get the root transform node for our scene... this is what we will move to position the scene in AR\r\n this._rootNode.setEnabled(false);\r\n\r\n //subscribe to render loop\r\n this._sessionMgr.onXRFrameObservable.add((frame: XRFrame) => this.onXRFrame(frame));\r\n this._sessionMgr.runXRRenderLoop(); //start the render loop\r\n\r\n this._originalSceneCamera = this.scene.activeCamera;\r\n this.scene.activeCamera = this._xrCamera!; //this line is important\r\n this.scene.autoClear = false;\r\n this._xrCamera!.compensateOnFirstFrame = false;\r\n\r\n this._originalBackground = this.v.sceneNode.background;\r\n this.v.sceneNode.background = eBackground.transparent;\r\n\r\n //add xr input handlers\r\n this._session.addEventListener('selectstart', this.onSelectStart);\r\n this._session.addEventListener('selectend', this.onSelectEnd);\r\n\r\n this._initialHitTester = new XrHitTester(this._sessionMgr);\r\n return this._initialHitTester.initialize();\r\n });\r\n }\r\n\r\n public endSession() {\r\n if (this._sessionMgr) {\r\n this.sessionEndingPromise = this._sessionMgr.exitXRAsync();\r\n return this.sessionEndingPromise;\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n\r\n protected sessionEnded() {\r\n if (this.sessionEndingPromise) {\r\n this.sessionEndingPromise.then(() => {\r\n this.sessionEndingPromise = undefined;\r\n this.sessionEnded();\r\n });\r\n } else {\r\n this._session.removeEventListener('selectstart', this.onSelectStart);\r\n this._session.removeEventListener('selectend', this.onSelectEnd);\r\n\r\n if (this._xrCamera) this._xrCamera.dispose();\r\n if (this._sessionMgr) this._sessionMgr.dispose();\r\n if (this._renderTarget) this._renderTarget.dispose();\r\n if (this._initialHitTester) this._initialHitTester.dispose();\r\n if (this._marker) this._marker.dispose();\r\n if (this._light) this._light.dispose();\r\n if (this._shadow) this._shadow.dispose();\r\n\r\n if (this._originalSceneCamera) {\r\n this.scene.activeCamera = this._originalSceneCamera;\r\n }\r\n this.scene.autoClear = true;\r\n this.v.sceneNode.background = this._originalBackground || eBackground.transparent;\r\n this._rootNode.scaling = Vector3.One();\r\n this._rootNode.rotation = Vector3.Zero();\r\n this._rootNode.position = Vector3.Zero();\r\n this._rootNode.setEnabled(true);\r\n this.onSessionEnd.next();\r\n }\r\n }\r\n\r\n protected onXRFrame(frame: XRFrame) {\r\n this._lastFrame = frame;\r\n //console.log(`user height: ${this._xrCamera.realWorldHeight}`);\r\n this._viewerPose = frame.getViewerPose(this._sessionMgr.referenceSpace);\r\n\r\n this.placeInitialMarker(frame);\r\n\r\n this.processInput(frame);\r\n this.setSceneTransform();\r\n this.runLightingEstimation(frame);\r\n }\r\n\r\n private _lightingEstimationCount = 0;\r\n protected runLightingEstimation(frame: XRFrame) {\r\n if (this._lightProbe) {\r\n this._lightingEstimationCount++;\r\n if (this._lightingEstimationCount == 30) {\r\n this._lightingEstimationCount = 0;\r\n const estimate = frame.getLightEstimate(this._lightProbe);\r\n // const probePose = frame.getPose(this._lightProbe.probeSpace, this._refSpace);\r\n // console.log({probePose});\r\n // console.log({ lightEstimate: estimate });\r\n if (estimate && this._light) {\r\n const direction = new Vector3(\r\n estimate.primaryLightDirection.x,\r\n estimate.primaryLightDirection.y,\r\n estimate.primaryLightDirection.z\r\n );\r\n direction.negateInPlace();\r\n this._light.setDirection(direction.x, direction.y, direction.z);\r\n\r\n const intensity = Math.max(\r\n 1.0,\r\n Math.max(\r\n estimate.primaryLightIntensity.x,\r\n Math.max(estimate.primaryLightIntensity.y, estimate.primaryLightIntensity.z)\r\n )\r\n );\r\n\r\n this._light.specular.set(\r\n estimate.primaryLightIntensity.x / intensity,\r\n estimate.primaryLightIntensity.y / intensity,\r\n estimate.primaryLightIntensity.z / intensity\r\n );\r\n this._light.diffuse.set(\r\n estimate.primaryLightIntensity.x / intensity,\r\n estimate.primaryLightIntensity.y / intensity,\r\n estimate.primaryLightIntensity.z / intensity\r\n );\r\n\r\n this._light.intensity = intensity;\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected placeInitialMarker(frame: XRFrame) {\r\n if (this._state == eXrState.searchingForHit || this._state == eXrState.initialPlacement) {\r\n const hit = this._initialHitTester!.getHitResult(frame);\r\n if (!hit) return;\r\n\r\n if (this._state == eXrState.searchingForHit) {\r\n if (!this._marker) {\r\n this._marker = new XrMarker(this.v, this.scene, this._naturalScale);\r\n this._marker.setEnabled(true);\r\n }\r\n this._state = eXrState.initialPlacement; //we got our first hit so we change state\r\n }\r\n\r\n if (this._state == eXrState.initialPlacement) {\r\n const quat = new Quaternion();\r\n hit.matrix.decompose(this._marker.scaling, quat, this._marker.position);\r\n this._marker.rotation = quat.toEulerAngles();\r\n // console.log(JSON.stringify({ markerPosition: this._marker.position }));\r\n }\r\n }\r\n }\r\n\r\n protected onSelectStart = (event: XRInputSourceEvent) => {\r\n if (this._state == eXrState.initialPlacement) {\r\n this.placeModel();\r\n this._state = eXrState.placed;\r\n\r\n this._initialHitTester!.dispose();\r\n this._initialHitTester = undefined;\r\n\r\n this._transientHitTester = new XrTransientHitTester(this._sessionMgr);\r\n this._transientHitTester.initialize();\r\n this._wasJustPlaced = true;\r\n } else if (this._state == eXrState.placed) {\r\n const fingers = this._transientHitTester?.getFingers(this._lastFrame!);\r\n\r\n if (fingers?.length === 1) {\r\n /** for one finger we do a hit test on kb3d to see if they pressed the model */\r\n this._selectStartScreenPos = this.screenNdcToPixels(event.inputSource.gamepad!.axes); //get the screen coordinates of the finger press\r\n const pickInfo = this.pick(this._selectStartScreenPos);\r\n if (pickInfo) {\r\n // console.log({ pickInfo });\r\n this._isTranslating = true;\r\n this._dragNodeStartPos = this._rootNode.position.clone();\r\n // this._dragNodeStartScreenPos = toScreen(this._rootNode.absolutePosition, this.getRigCamera());\r\n // this._fingerStartScreenPos = this.screenNdcToPixels(fingers[0].inputSource.gamepad!.axes);\r\n const dragHitTester = new XrTransientHitTester(this._sessionMgr);\r\n\r\n const offset = this._dragNodeStartPos.subtract(pickInfo.pickedPoint.toVec3());\r\n // console.log({nodePos: this._dragNodeStartPos, pickedPoint: pickInfo.pickedPoint});\r\n const offsetRay = new XRRay(offset);\r\n\r\n dragHitTester.initialize(offsetRay).then(() => {\r\n this._dragHitTester = dragHitTester;\r\n });\r\n } else {\r\n this._isRotating = true;\r\n this._goalYaw = this._rootNode.rotation.y;\r\n this._lastScalar = event.inputSource.gamepad!.axes[0];\r\n }\r\n\r\n //simulate pointer down observable\r\n const args = this.v.interaction.getKb3dPointerArgs({\r\n type: PointerEventTypes.POINTERDOWN,\r\n event: new PointerEvent('pointerdown', { pointerId: event.inputSource.gamepad!.id } as any),\r\n pickInfo: pickInfo!,\r\n });\r\n this.v.interaction.handlePointerDown(args);\r\n this._marker.show();\r\n } else if (fingers?.length === 2 && this.v.sceneNode.xrAllowScaling) {\r\n this._isScaling = true;\r\n this._lastScalar = this.getFingerSeparation(fingers) / this._rootNode.scaling.x;\r\n this._marker.show();\r\n }\r\n }\r\n };\r\n\r\n protected onSelectEnd = (event: XRInputSourceEvent) => {\r\n this._isTranslating = false;\r\n this._isRotating = false;\r\n this._isScaling = false;\r\n if (this._dragHitTester) {\r\n this._dragHitTester.dispose();\r\n }\r\n this._dragHitTester = undefined;\r\n this._fingerStartPos = undefined;\r\n\r\n //simulate pointer up observable\r\n const fingers = this._transientHitTester?.getFingers(this._lastFrame!);\r\n const screenCoord = this.screenNdcToPixels(event.inputSource.gamepad!.axes); //get the screen coordinates of the finger press\r\n const pickInfo = this.pick(screenCoord);\r\n const args = this.v.interaction.getKb3dPointerArgs({\r\n type: PointerEventTypes.POINTERUP,\r\n event: new PointerEvent('pointerup', { pointerId: event.inputSource.gamepad!.id } as any),\r\n pickInfo: pickInfo!,\r\n });\r\n this.v.interaction.handlePointerUp(args);\r\n\r\n //simulate the pointer tap observable if the input hasn't moved much\r\n if (this._state == eXrState.placed) {\r\n if (fingers?.length === 1 && !this._wasJustPlaced) {\r\n const deltaScreen = Vector2.Distance(this._selectStartScreenPos || screenCoord, screenCoord);\r\n if (deltaScreen < 5) {\r\n const args = this.v.interaction.getKb3dPointerArgs({\r\n type: PointerEventTypes.POINTERTAP,\r\n event: new PointerEvent('pointertap', { pointerId: event.inputSource.gamepad!.id } as any),\r\n pickInfo: pickInfo!,\r\n });\r\n this.v.interaction.handleClick(args);\r\n }\r\n }\r\n\r\n this._marker.hide();\r\n this._wasJustPlaced = false;\r\n }\r\n };\r\n\r\n protected processInput(frame: XRFrame) {\r\n if (this._state == eXrState.placed && (this._isTranslating || this._isRotating || this._isScaling)) {\r\n const fingers = this._transientHitTester!.getFingers(frame);\r\n\r\n if (this._isScaling) {\r\n if (fingers.length < 2) {\r\n //the user removed their 2nd finger, so the scale is cancelled\r\n this._isScaling = false;\r\n } else {\r\n const separation = this.getFingerSeparation(fingers);\r\n const scale = separation / this._lastScalar;\r\n this._goalScale =\r\n scale < this._scaleSnapHigh && scale > this._scaleSnapLow ? this._naturalScale : scale;\r\n }\r\n } else if (fingers.length === 2 && this.v.sceneNode.xrAllowScaling) {\r\n // happens when translating or rotating and another finger was added. We switch to scaling in this instance\r\n this._isTranslating = false;\r\n this._isRotating = false;\r\n this._isScaling = true;\r\n const scale = this._rootNode.scaling.x;\r\n this._lastScalar = this.getFingerSeparation(fingers) / scale;\r\n } else if (this._isRotating) {\r\n const inputSource = fingers[0].inputSource;\r\n const dragX = inputSource.gamepad!.axes[0];\r\n this._goalYaw += (dragX - this._lastScalar) * ROTATION_RATE;\r\n this._lastScalar = dragX;\r\n } else if (this._isTranslating) {\r\n if (fingers.length > 0 && this._dragHitTester) {\r\n const dragFingers = this._dragHitTester.getFingers(frame);\r\n if (dragFingers.length && dragFingers[0].results.length) {\r\n const dragFinger = dragFingers[0];\r\n\r\n const dragFingerResult = dragFinger.results[0];\r\n if (!this._fingerStartPos) this._fingerStartPos = dragFingerResult.position;\r\n\r\n const deltaPos = dragFingerResult.position.subtract(this._fingerStartPos);\r\n this._goalPosition = this._dragNodeStartPos!.add(deltaPos);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected placeModel() {\r\n this._goalPosition = this._marker.position.clone();\r\n this._goalYaw = this._marker.rotation.y;\r\n this._goalScale = this._naturalScale;\r\n this._scaleSnapHigh = this._naturalScale * SCALE_SNAP;\r\n this._scaleSnapLow = this._naturalScale / SCALE_SNAP;\r\n\r\n //we now add the marker to the root node so it can scale and move with the model\r\n this._marker.place(this._rootNode);\r\n\r\n if (this.v.sceneNode.xrAddShadow) {\r\n this._shadow = new XrShadowPlane(this.v, this.scene);\r\n this._shadow.place(this._rootNode);\r\n\r\n this._light = new XrLight(this.v, this.scene);\r\n\r\n if (this.v.sceneNode.xrLightingEstimation && this._session.requestLightProbe) {\r\n this._session.requestLightProbe().then(lp => (this._lightProbe = lp));\r\n }\r\n }\r\n\r\n this._rootNode.setEnabled(true);\r\n\r\n //this._marker.setEnabled(false);\r\n this._state = eXrState.placed;\r\n }\r\n\r\n /** does a pick of the kb3d scene (NOT a webxr hit test). Accepts x/y as screen pixel coordinates */\r\n protected pick(screenCoord: Vector2) {\r\n /**\r\n * The WebXRCamera in babylon appears to be for reference only, and it's position/rotation\r\n * are updated on each frame to be the same as the viewer pose from XR.\r\n *\r\n * However, the forward ray from the WebXRCamera is not what we would expect, it's pointing\r\n * in exactly the opposite direction. However, inside the WebXRCamera are rig cameras (only 1\r\n * in the case of AR) who are responsible for actually doing the babylon rendering. The rig\r\n * camera direction is what we would expect. For now we are using the rig camera to do\r\n * the picking, but we should keep an eye on this part as new babylon/webxr releases come out,\r\n * as something seems amiss.\r\n */\r\n const hardwareScale = this.scene.getEngine().getHardwareScalingLevel();\r\n /** adjust by hardware scale as webxr does not support it, but the pick routine uses it */\r\n const pickInfo = this.v.interaction.pick(\r\n screenCoord.x * hardwareScale,\r\n screenCoord.y * hardwareScale,\r\n this.getRigCamera()\r\n );\r\n\r\n return pickInfo;\r\n }\r\n\r\n protected getFingerSeparation(fingers: IXrTransientHitResult[]): number {\r\n const firstFinger = fingers[0].inputSource.gamepad!.axes;\r\n const secondFinger = fingers[1].inputSource.gamepad!.axes;\r\n const deltaX = secondFinger[0] - firstFinger[0];\r\n const deltaY = secondFinger[1] - firstFinger[1];\r\n return Math.sqrt(deltaX * deltaX + deltaY * deltaY);\r\n }\r\n\r\n /** set's the transforms of the scene to the goal values */\r\n protected setSceneTransform() {\r\n if (this._state == eXrState.placed) {\r\n let invalidateRootBoundingBox = false;\r\n if (this._rootNode.scaling.x != this._goalScale) {\r\n this._rootNode.scaling = new Vector3(this._goalScale, this._goalScale, this._goalScale);\r\n invalidateRootBoundingBox = true;\r\n }\r\n if (this._rootNode.rotation.y != this._goalYaw) {\r\n this._rootNode.rotation.y = this._goalYaw; // = Quaternion.FromEulerAngles(0, this._goalYaw, 0);\r\n // this._marker.rotation.y = this._goalYaw;\r\n invalidateRootBoundingBox = true;\r\n }\r\n\r\n if (\r\n this._goalPosition &&\r\n !this._goalPosition.equalsToFloats(\r\n this._rootNode.position.x,\r\n this._rootNode.position.y,\r\n this._rootNode.position.z\r\n )\r\n ) {\r\n this._rootNode.position.set(this._goalPosition.x, this._goalPosition.y, this._goalPosition.z);\r\n //this._marker.position.set(this._goalPosition.x, this._goalPosition.y, this._goalPosition.z);\r\n invalidateRootBoundingBox = true;\r\n }\r\n\r\n if (invalidateRootBoundingBox) {\r\n this.v.bbCache.invalidate(this.v.sceneNode);\r\n }\r\n }\r\n }\r\n\r\n protected getRigCamera() {\r\n const rigCamera = this._xrCamera.rigCameras[0];\r\n return rigCamera;\r\n }\r\n\r\n protected screenNdcToPixels(axes: readonly number[]) {\r\n const canvas = this.scene.getEngine().getRenderingCanvas() as HTMLCanvasElement;\r\n //need to convert NDC units to pixels\r\n const x = (axes[0] + 1) * (canvas.width / 2);\r\n const y = (axes[1] + 1) * (canvas.height / 2);\r\n\r\n return new Vector2(x, y);\r\n }\r\n\r\n protected screenPixelsToNdc(pos: { x: number; y: number }) {\r\n const canvas = this.scene.getEngine().getRenderingCanvas() as HTMLCanvasElement;\r\n return {\r\n x: pos.x / (canvas.width / 2) - 1,\r\n y: pos.y / (canvas.height / 2) - 2,\r\n };\r\n }\r\n}\r\n","import '@babylonjs/core/XR/features/WebXRAnchorSystem';\r\nimport '@babylonjs/core/XR/features/WebXRHitTest';\r\nimport '@babylonjs/core/XR/features/WebXRPlaneDetector';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subject } from 'rxjs';\r\nimport { first } from 'rxjs/operators';\r\nimport { GLTFKb3dExporter } from './exporter-gltf';\r\nimport { USDZBabylonConverter } from './usdz/usdz-babylon-converter';\r\nimport { Xr } from './xr/xr';\r\n\r\nconst IS_IOS =\r\n /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); //https://stackoverflow.com/a/58065241\r\n\r\nconst IS_ANDROID = /android/i.test(navigator.userAgent);\r\n\r\nexport class AR {\r\n currentObjectUrl?: string;\r\n isDebug = false;\r\n\r\n constructor(private v: KbViewer, private scene: Scene) {\r\n this.isDebug = !!v.options.debugMode;\r\n this.gltfExporter = new GLTFKb3dExporter(scene);\r\n }\r\n\r\n public xrActive = false;\r\n public xrLoading = false;\r\n public onSessionEnd = new Subject();\r\n\r\n private _xr: Xr;\r\n private gltfExporter: GLTFKb3dExporter;\r\n\r\n public toggle() {\r\n if (this.xrActive) {\r\n return this.end();\r\n } else {\r\n return this.start();\r\n }\r\n }\r\n\r\n public start(overlayElem?: HTMLElement, onEnterFunc?: () => PromiseLike) {\r\n // Have to use a callback because android should run this after entering XR, but ios must run it before entering XR\r\n if (!onEnterFunc) {\r\n onEnterFunc = () => Promise.resolve();\r\n }\r\n const _onEnterFunc = onEnterFunc;\r\n if (IS_ANDROID) {\r\n return this.startWebXR(overlayElem).then(() => _onEnterFunc());\r\n } else if (IS_IOS || this.isDebug) {\r\n const usdz = new USDZBabylonConverter();\r\n if (this.v.sceneNode) {\r\n const self = this;\r\n\r\n return this.v\r\n .whenAssetsLoaded()\r\n .then(() => _onEnterFunc())\r\n .then(() => this.v.forceAndWaitForNextRender())\r\n .then(() => usdz.parse(this.scene, this.v.sceneNode, true))\r\n .then(res => {\r\n const a = document.createElement('a');\r\n\r\n if (a.relList.supports('ar') || this.isDebug) {\r\n if (self.currentObjectUrl) {\r\n window.URL.revokeObjectURL(self.currentObjectUrl);\r\n self.currentObjectUrl = undefined;\r\n }\r\n\r\n self.currentObjectUrl = window.URL.createObjectURL(res);\r\n\r\n const img = document.createElement('img');\r\n img.src = '/images/ar_ios.png';\r\n a.appendChild(img);\r\n document.body.appendChild(a);\r\n a.href = self.currentObjectUrl;\r\n a.download = 'test.usdz';\r\n a.rel = 'ar';\r\n\r\n // Fire XR Exit right away on iOS since the USDZ is already generated and static now\r\n // So, whatever scene changes they want when the user exits AR should already be in the browser\r\n this.xrActive = false;\r\n this.xrLoading = false;\r\n this.onSessionEnd.next();\r\n\r\n setTimeout(() => {\r\n a.click();\r\n\r\n setTimeout(() => {\r\n document.body.removeChild(a);\r\n }, 0);\r\n }, 50);\r\n\r\n return undefined;\r\n }\r\n\r\n return Promise.reject('Your device does not support AR.');\r\n });\r\n } else {\r\n return Promise.reject('Scene not initialized');\r\n }\r\n }\r\n\r\n return Promise.reject('Your device does not support AR.');\r\n }\r\n\r\n public end() {\r\n if (IS_ANDROID) {\r\n return this.endWebXr();\r\n } else if (IS_IOS) {\r\n if (this.currentObjectUrl) {\r\n URL.revokeObjectURL(this.currentObjectUrl);\r\n }\r\n //TODO usdz\r\n }\r\n\r\n return Promise.resolve();\r\n }\r\n\r\n public startWebXR(overlayElem?: HTMLElement) {\r\n this._xr = new Xr(this.v, this.scene);\r\n this._xr.onSessionEnd.pipe(first()).subscribe(() => {\r\n this.xrActive = false;\r\n this.xrLoading = false;\r\n this.onSessionEnd.next();\r\n });\r\n this.xrLoading = true;\r\n return this._xr.startSession('immersive-ar', 'local-floor', overlayElem).then(() => {\r\n this.xrActive = true;\r\n this.xrLoading = false;\r\n });\r\n }\r\n\r\n protected endWebXr() {\r\n if (this._xr) {\r\n return this._xr.endSession();\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n /**\r\n * Takes a URL to a USDZ file and sets the appropriate fields so that Safari\r\n * iOS can intent to their AR Quick Look.\r\n */\r\n public startIosQuickLook(usdzSrc: string, canScale: boolean) {\r\n const anchor = document.createElement('a');\r\n anchor.setAttribute('rel', 'ar');\r\n anchor.appendChild(document.createElement('img'));\r\n\r\n const modelUrl = new URL(usdzSrc, self.location.toString());\r\n if (!canScale) {\r\n modelUrl.hash = 'allowsContentScaling=0';\r\n }\r\n anchor.setAttribute('href', modelUrl.toString());\r\n anchor.click();\r\n }\r\n\r\n /**\r\n * Android SceneViewer is a native app. You build an intent link to tell\r\n * the browser to open scene viewer and show a GLB. It does not accept blob urls,\r\n * so the link must go to a file on the server: https://github.com/google/model-viewer/issues/617 *\r\n */\r\n // public startAndroidSceneViewer(glbSrc: string) {\r\n // this.gltfExporter.generateGlb().then(blob => {\r\n // let objectUrl = window.URL.createObjectURL(blob);\r\n // window.URL.revokeObjectURL(objectUrl);\r\n // //TODO: need to send GLB to server, as sceneViewer won't accept blob urls from the browser\r\n // const a = document.createElement('a');\r\n // const fallbackUrl = encodeURIComponent(self.location.toString());\r\n // /**temp hack */ objectUrl =\r\n // 'https://storage.googleapis.com/ar-answers-in-search-models/static/Tiger/model.glb';\r\n // const href = `intent://arvr.google.com/scene-viewer/1.0?file=${objectUrl}&mode=ar_preferred#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${fallbackUrl};end;`;\r\n // a.setAttribute('href', href);\r\n // a.click();\r\n // });\r\n // }\r\n}\r\n","import { Observable } from '../Observable';\nimport { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { EmptyError } from '../util/EmptyError';\nimport { OperatorFunction } from '../../internal/types';\nimport { filter } from './filter';\nimport { take } from './take';\nimport { defaultIfEmpty } from './defaultIfEmpty';\nimport { throwIfEmpty } from './throwIfEmpty';\nimport { identity } from '../util/identity';\n\n/* tslint:disable:max-line-length */\nexport function first(\n predicate?: null,\n defaultValue?: D\n): OperatorFunction;\nexport function first(\n predicate: (value: T, index: number, source: Observable) => value is S,\n defaultValue?: S\n): OperatorFunction;\nexport function first(\n predicate: (value: T, index: number, source: Observable) => boolean,\n defaultValue?: D\n): OperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Emits only the first value (or the first value that meets some condition)\n * emitted by the source Observable.\n *\n * Emits only the first value. Or emits only the first\n * value that passes some test.\n *\n * ![](first.png)\n *\n * If called with no arguments, `first` emits the first value of the source\n * Observable, then completes. If called with a `predicate` function, `first`\n * emits the first value of the source that matches the specified condition. It\n * may also take a deprecated `resultSelector` function to produce the output\n * value from the input value, and a `defaultValue` to emit in case the source\n * completes before it is able to emit a valid value. Throws an error if\n * `defaultValue` was not provided and a matching element is not found.\n *\n * ## Examples\n * Emit only the first click that happens on the DOM\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { first } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(first());\n * result.subscribe(x => console.log(x));\n * ```\n *\n * Emits the first click that happens on a DIV\n * ```ts\n * import { fromEvent } from 'rxjs';\n * import { first } from 'rxjs/operators';\n *\n * const clicks = fromEvent(document, 'click');\n * const result = clicks.pipe(first(ev => ev.target.tagName === 'DIV'));\n * result.subscribe(x => console.log(x));\n * ```\n *\n * @see {@link filter}\n * @see {@link find}\n * @see {@link take}\n *\n * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`\n * callback if the Observable completes before any `next` notification was sent.\n *\n * @param {function(value: T, index: number, source: Observable): boolean} [predicate]\n * An optional function called with each item to test for condition matching.\n * @param {R} [defaultValue] The default value emitted in case no valid value\n * was found on the source.\n * @return {Observable} An Observable of the first item that matches the\n * condition.\n * @method first\n * @owner Observable\n */\nexport function first(\n predicate?: ((value: T, index: number, source: Observable) => boolean) | null,\n defaultValue?: D\n): OperatorFunction {\n const hasDefaultValue = arguments.length >= 2;\n return (source: Observable) => source.pipe(\n predicate ? filter((v, i) => predicate(v, i, source)) : identity,\n take(1),\n hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(() => new EmptyError()),\n );\n}\n","import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';\r\nimport { Matrix, Vector3 } from '@babylonjs/core/Maths';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { BehaviorSubject, Observable, Subject } from 'rxjs';\r\nimport { mergeMap } from 'rxjs/operators';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport { Kb3dBoundingBoxChangeHandler } from '@models/classes/handlers';\r\n\r\nexport interface BoundingBoxInfo {\r\n boundingInfo: BoundingInfo;\r\n min: KbVector;\r\n max: KbVector;\r\n center: KbVector;\r\n}\r\n\r\nexport function toBoundingBoxInfo(binfo: BoundingInfo) {\r\n return {\r\n boundingInfo: binfo,\r\n min: KbVector.FromVec3(binfo.minimum),\r\n max: KbVector.FromVec3(binfo.maximum),\r\n center: KbVector.FromVec3(binfo.boundingBox.center),\r\n } as BoundingBoxInfo;\r\n}\r\n\r\ninterface IVectorLike {\r\n x?: number;\r\n y?: number;\r\n z?: number;\r\n}\r\n\r\nconst MAX_DIGESTS = 30;\r\n\r\nexport class BoundingBoxCache {\r\n constructor(private v: KbViewer) {}\r\n\r\n public boundingBoxInvalidated = new Subject();\r\n public rootBoundingBoxChanged = new Subject();\r\n private _digestCount = 0;\r\n private _db = new Map();\r\n private _watchedNodes = new Map>();\r\n private _changedNodes = new Set(); //stored dynamic id's of changed nodes\r\n\r\n public watchForChanges(node: SpaceNode): Observable {\r\n let subject = this._watchedNodes.get(node._dynamicId);\r\n\r\n if (!subject) {\r\n subject = new BehaviorSubject(undefined);\r\n this._watchedNodes.set(node._dynamicId, subject);\r\n }\r\n const _subject = subject;\r\n\r\n // This is using an internal implementation of rxjs, hence the any. But this is the only way we can add teardown logic.\r\n const observable = new Observable(s => {\r\n s.next();\r\n return () => {\r\n setTimeout(() => {\r\n if (_subject.observers.length === 0) {\r\n _subject.complete();\r\n this._watchedNodes.delete(node._dynamicId);\r\n }\r\n });\r\n };\r\n });\r\n\r\n return observable.pipe(mergeMap(() => _subject));\r\n }\r\n\r\n public refreshAndGet(node: SpaceNode) {\r\n this._db.delete(node._dynamicId);\r\n return this.get(node);\r\n }\r\n\r\n public get(node?: SpaceNode) {\r\n if (node && node.visible) {\r\n let bb = this._db.get(node._dynamicId);\r\n if (!bb) {\r\n let bbInfo: BoundingInfo | undefined;\r\n const bnode = this.v.rendererManager.mesh.get3d(node);\r\n if (node instanceof MeshNode) {\r\n if (bnode) {\r\n bbInfo = (bnode as AbstractMesh).getBoundingInfo();\r\n }\r\n } else {\r\n const childNodes = node.getSpaceChildren();\r\n const min: IVectorLike = {};\r\n const max: IVectorLike = {};\r\n let empty = true;\r\n\r\n for (const c of childNodes) {\r\n const cbb = this.get(c);\r\n // If cbb is undefined, that means the child node is not visible or doesn't exist\r\n if (cbb) {\r\n empty = false;\r\n const parentMin = cbb.min.toVec3();\r\n const parentMax = cbb.max.toVec3();\r\n const childBNode = this.v.rendererManager.mesh.get3d(c);\r\n if (childBNode) {\r\n const mat = Matrix.Compose(\r\n childBNode.scaling,\r\n childBNode.rotationQuaternion!,\r\n childBNode.position\r\n );\r\n Vector3.TransformCoordinatesToRef(parentMin, mat, parentMin);\r\n Vector3.TransformCoordinatesToRef(parentMax, mat, parentMax);\r\n }\r\n\r\n if (min.x == null) min.x = parentMin.x;\r\n if (min.y == null) min.y = parentMin.y;\r\n if (min.z == null) min.z = parentMin.z;\r\n if (max.x == null) max.x = parentMax.x;\r\n if (max.y == null) max.y = parentMax.y;\r\n if (max.z == null) max.z = parentMax.z;\r\n\r\n min.x = Math.min(min.x, parentMin.x, parentMax.x);\r\n min.y = Math.min(min.y, parentMin.y, parentMax.y);\r\n min.z = Math.min(min.z, parentMin.z, parentMax.z);\r\n max.x = Math.max(max.x, parentMin.x, parentMax.x);\r\n max.y = Math.max(max.y, parentMin.y, parentMax.y);\r\n max.z = Math.max(max.z, parentMin.z, parentMax.z);\r\n }\r\n }\r\n\r\n if (empty) {\r\n return undefined; //don't consider empty groups\r\n }\r\n\r\n bbInfo = new BoundingInfo(\r\n new Vector3(min.x || 0, min.y || 0, min.z || 0),\r\n new Vector3(max.x || 0, max.y || 0, max.z || 0)\r\n );\r\n }\r\n\r\n if (bbInfo) {\r\n bb = toBoundingBoxInfo(bbInfo);\r\n this._db.set(node._dynamicId, bb);\r\n }\r\n }\r\n return bb;\r\n } else {\r\n return undefined;\r\n }\r\n }\r\n\r\n public invalidate(node: SpaceNode | undefined) {\r\n if (node) {\r\n //when a node is invalidated, all of it's ancestors need to be invalidated\r\n let n = node;\r\n while (n && n instanceof SpaceNode) {\r\n this._changedNodes.add(n._dynamicId);\r\n n = n._parent as SpaceNode;\r\n }\r\n }\r\n }\r\n\r\n public update() {\r\n let boundingBoxesStable = true as null | boolean;\r\n\r\n if (this._changedNodes.size === 0) {\r\n return;\r\n }\r\n\r\n if(!this.v.userIsInteracting()) {\r\n this._digestCount++;\r\n }\r\n\r\n const watchersToUpdateAndClear = new Map();\r\n\r\n for (const dynamicId of this._changedNodes) {\r\n const n = getByDynamicId(dynamicId);\r\n if (!n) {\r\n continue;\r\n }\r\n const externalWatchers = n._manager?.boundingboxChangeHandlers.getByKey(n);\r\n const hasRootWatchers =\r\n this.v.sceneNode._dynamicId === n._dynamicId && this.rootBoundingBoxChanged.observers.length > 0;\r\n const hasWatchers =\r\n this._watchedNodes.has(n._dynamicId) || (externalWatchers !== undefined && externalWatchers.length > 0);\r\n\r\n const oldBoundingBox = this._db.get(n._dynamicId);\r\n this._db.delete(n._dynamicId);\r\n this.boundingBoxInvalidated.next(n);\r\n\r\n if (!hasWatchers && !hasRootWatchers) {\r\n continue;\r\n }\r\n\r\n const bbInfo = this.get(n);\r\n const boundingBoxChanged = !boundingBoxesMatch(bbInfo, oldBoundingBox);\r\n const bbWatchersSubject = this._watchedNodes.get(n._dynamicId);\r\n\r\n if (boundingBoxChanged) {\r\n boundingBoxesStable = false;\r\n }\r\n\r\n if (bbWatchersSubject) {\r\n bbWatchersSubject.next(bbInfo);\r\n }\r\n if (externalWatchers && bbInfo) {\r\n for (const w of externalWatchers) {\r\n const once = w.mode === 'once';\r\n // Always call the handler if the mode is 'once', because it will be expecting an update regardless of whether it changed or not.\r\n // For persistent watchers, only call it if the bb actually changed.\r\n if (boundingBoxChanged && !once) {\r\n w.handler(bbInfo);\r\n }\r\n if (once) {\r\n watchersToUpdateAndClear.set(n, w);\r\n }\r\n }\r\n }\r\n\r\n if (hasRootWatchers && bbInfo && boundingBoxChanged) {\r\n this.rootBoundingBoxChanged.next(bbInfo);\r\n }\r\n }\r\n\r\n if (boundingBoxesStable && this._digestCount > 3) {\r\n this._changedNodes.clear();\r\n for (const [node, watcher] of watchersToUpdateAndClear.entries()) {\r\n const bbInfo = this.get(node);\r\n if (bbInfo) {\r\n watcher.handler(bbInfo);\r\n }\r\n node._manager?.boundingboxChangeHandlers.deleteByKeyValue(node, watcher);\r\n }\r\n watchersToUpdateAndClear.clear();\r\n this._digestCount = 0;\r\n } else if (!boundingBoxesStable && this._digestCount > MAX_DIGESTS) {\r\n console.error('Bounding box digest cycle exceeded, but the meshes are not consistent');\r\n this._changedNodes.clear();\r\n watchersToUpdateAndClear.clear();\r\n this._digestCount = 0;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the world bounding box for the specified node.\r\n * Be aware that this call is not cached, so use accordingly for performance reasons\r\n * @param node\r\n */\r\n public getWorld(node?: SpaceNode) {\r\n if (node && node.visible) {\r\n const bb = this.get(node)!;\r\n if (!bb) {\r\n return null;\r\n }\r\n const bnode = this.v.rendererManager.mesh.get3d(node);\r\n const bbInfo = new BoundingInfo(\r\n new Vector3(bb.min.x || 0, bb.min.y || 0, bb.min.z || 0),\r\n new Vector3(bb.max.x || 0, bb.max.y || 0, bb.max.z || 0),\r\n bnode?.getWorldMatrix()\r\n );\r\n return {\r\n boundingInfo: bbInfo,\r\n min: KbVector.FromVec3(bbInfo.boundingBox.minimumWorld),\r\n max: KbVector.FromVec3(bbInfo.boundingBox.maximumWorld),\r\n center: KbVector.FromVec3(bbInfo.boundingBox.centerWorld),\r\n } as BoundingBoxInfo;\r\n }\r\n return null;\r\n }\r\n\r\n public dispose() {\r\n this._db.clear();\r\n this._watchedNodes.forEach(subject => {\r\n subject.complete();\r\n });\r\n this._watchedNodes.clear();\r\n }\r\n}\r\n\r\nfunction boundingBoxesMatch(a: BoundingBoxInfo | undefined, b: BoundingBoxInfo | undefined) {\r\n if (!a && !b) {\r\n return true;\r\n }\r\n if (!a || !b) {\r\n return false;\r\n }\r\n\r\n return a.center.equal(b.center) && a.min.equal(b.min) && a.max.equal(b.max);\r\n}\r\n","import { Color3, Color4, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\n\r\n/** KbVector extension methods - we have them here instead of in the class so that the class isn't referencing babylon */\r\ndeclare module '@models/classes/primitives/kb-vector' {\r\n interface KbVector {\r\n toVec3(ref?: Vector3): Vector3;\r\n }\r\n namespace KbVector {\r\n let FromVec3: (vector: Vector3) => KbVector;\r\n }\r\n}\r\nObject.defineProperty(KbVector.prototype, 'toVec3', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (ref?: Vector3) {\r\n // add ref option\r\n if (!ref) {\r\n ref = new Vector3();\r\n }\r\n return this ? ref.copyFromFloats(this.x, this.y, this.z) : ref.setAll(0);\r\n },\r\n});\r\nObject.defineProperty(KbVector, 'FromVec3', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (vector: Vector3) {\r\n return new KbVector(vector.x, vector.y, vector.z);\r\n },\r\n});\r\n\r\n/** KbQuaternion extension methods */\r\ndeclare module '@models/classes/primitives/kb-quaternion' {\r\n interface KbQuaternion {\r\n toQuat(): Quaternion;\r\n }\r\n namespace KbQuaternion {\r\n let FromQuat: (quaternion: Quaternion) => KbQuaternion;\r\n }\r\n}\r\nObject.defineProperty(KbQuaternion.prototype, 'toQuat', {\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n return this ? new Quaternion(this.x, this.y, this.z, this.w) : new Quaternion(0, 0, 0, 1);\r\n },\r\n});\r\nObject.defineProperty(KbQuaternion, 'FromQuat', {\r\n enumerable: false,\r\n writable: true,\r\n value: function (q: Quaternion) {\r\n return new KbQuaternion(q.x, q.y, q.z, q.w);\r\n },\r\n});\r\n\r\n/** KbColor extension methods */\r\ndeclare module '@models/classes/primitives/kb-color' {\r\n interface KbColor {\r\n toColor3(): Color3;\r\n toColor4(): Color4;\r\n }\r\n}\r\nObject.defineProperty(KbColor.prototype, 'toColor3', {\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n return this ? new Color3(this.r, this.g, this.b) : Color3.Black();\r\n },\r\n});\r\nObject.defineProperty(KbColor.prototype, 'toColor4', {\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n return this ? new Color4(this.r, this.g, this.b, this.a) : new Color4(0, 0, 0, 0);\r\n },\r\n});\r\n","import { Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { BaseConnector, isSketchControlPoint } from '@models/classes';\r\nimport { IKbVectorLike, KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { IBoundingBox } from '@models/classes/primitives/primitive-utilities';\r\n\r\nexport class BoundingBoxRelativeHelper {\r\n static convertRelativeToAbsolute(c: BaseConnector, bb: IBoundingBox, position?: IKbVectorLike) {\r\n if (!position) {\r\n position = c.position;\r\n }\r\n if (isSketchControlPoint(c)) {\r\n return new Vector3(\r\n ((position.x + 1) / 2) * bb.max.x + bb.min.x,\r\n ((position.y + 1) / 2) * bb.max.y + bb.min.y,\r\n ((position.z + 1) / 2) * bb.max.z + bb.min.z\r\n );\r\n } else {\r\n return new Vector3(\r\n bb.center.x + (position.x * Math.abs(bb.max.x - bb.min.x)) / 2,\r\n bb.center.y + (position.y * Math.abs(bb.max.y - bb.min.y)) / 2,\r\n bb.center.z + (position.z * Math.abs(bb.max.z - bb.min.z)) / 2\r\n );\r\n }\r\n }\r\n\r\n static convertAbsoluteToRelative(c: BaseConnector, bb: IBoundingBox, position?: IKbVectorLike) {\r\n if (!position) {\r\n position = c.position;\r\n }\r\n if (isSketchControlPoint(c)) {\r\n return new Vector3(\r\n ((position.x - bb.min.x) / bb.max.x) * 2 - 1,\r\n ((position.y - bb.min.y) / bb.max.y) * 2 - 1,\r\n ((position.z - bb.min.z) / bb.max.z) * 2 - 1\r\n );\r\n } else {\r\n return new Vector3(\r\n ((position.x - bb.center.x) * 2) / Math.abs(bb.max.x - bb.min.x),\r\n ((position.y - bb.center.y) * 2) / Math.abs(bb.max.y - bb.min.y),\r\n ((position.z - bb.center.z) * 2) / Math.abs(bb.max.z - bb.min.z)\r\n );\r\n }\r\n }\r\n\r\n static convertRelativeDirectionToAbsolute(c: BaseConnector, direction: IKbVectorLike, bb: IBoundingBox) {\r\n if (isSketchControlPoint(c)) {\r\n return new Vector3(\r\n direction.x * (bb.min.x - bb.max.x),\r\n direction.y * (bb.min.y - bb.max.y),\r\n direction.z * (bb.min.z - bb.max.z)\r\n );\r\n } else {\r\n return new Vector3(direction.x, direction.y, direction.z);\r\n }\r\n }\r\n static convertAbsoluteDirectionToRelative(c: BaseConnector, direction: IKbVectorLike, bb: IBoundingBox) {\r\n if (isSketchControlPoint(c)) {\r\n return new Vector3(\r\n direction.x / (bb.min.x - bb.max.x),\r\n direction.y / (bb.min.y - bb.max.y),\r\n direction.z / (bb.min.z - bb.max.z)\r\n );\r\n } else {\r\n return new Vector3(direction.x, direction.y, direction.z);\r\n }\r\n }\r\n}\r\n\r\nexport class BoundingBoxRelativeHelperKbVector {\r\n static convertRelativeToAbsolute(c: BaseConnector, bb: IBoundingBox, position?: IKbVectorLike) {\r\n return KbVector.FromVec3(BoundingBoxRelativeHelper.convertRelativeToAbsolute(c, bb, position));\r\n }\r\n\r\n static convertAbsoluteToRelative(c: BaseConnector, bb: IBoundingBox, position?: IKbVectorLike) {\r\n return KbVector.FromVec3(BoundingBoxRelativeHelper.convertAbsoluteToRelative(c, bb, position));\r\n }\r\n\r\n static convertRelativeDirectionToAbsolute(c: BaseConnector, direction: IKbVectorLike, bb: IBoundingBox) {\r\n return KbVector.FromVec3(BoundingBoxRelativeHelper.convertRelativeDirectionToAbsolute(c, direction, bb));\r\n }\r\n static convertAbsoluteDirectionToRelative(c: BaseConnector, direction: IKbVectorLike, bb: IBoundingBox) {\r\n return KbVector.FromVec3(BoundingBoxRelativeHelper.convertAbsoluteDirectionToRelative(c, direction, bb));\r\n }\r\n}\r\n","export enum eSideOrientationBabylonMap {\r\n frontSide = 0,\r\n backSide = 1,\r\n doubleSide = 2,\r\n}\r\nexport enum eUvMapAxisBabylonMap {\r\n x = 0,\r\n y = 1,\r\n z = 2,\r\n}\r\nexport enum eUvModeBabylonMap {\r\n planar = 0,\r\n box = 1,\r\n cylindrical = 2,\r\n spherical = 3,\r\n}\r\nexport enum eAlphaModeBabylonMap {\r\n disable = 0,\r\n add = 1,\r\n combine = 2,\r\n subtract = 3,\r\n multiply = 4,\r\n}\r\n","import { DirectionalLight, HemisphericLight, Light, SpotLight } from '@babylonjs/core/Lights';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3 } from '@babylonjs/core/Maths/math';\r\nimport { CylinderBuilder } from '@babylonjs/core/Meshes/Builders/cylinderBuilder';\r\nimport { GroundBuilder } from '@babylonjs/core/Meshes/Builders/groundBuilder';\r\nimport { SphereBuilder } from '@babylonjs/core/Meshes/Builders/sphereBuilder';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\n\r\nexport function createLightVisualization(light: Light, scene: Scene, color?: Color3) {\r\n let lightPositionGizmo: Mesh;\r\n\r\n if (!color) {\r\n color = Color3.Yellow();\r\n }\r\n\r\n if (light instanceof HemisphericLight) {\r\n lightPositionGizmo = SphereBuilder.CreateSphere(\r\n 'lightPositionMarker',\r\n { diameter: 0.75, slice: 0.5, segments: 6 },\r\n scene\r\n );\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n lightPositionGizmo.material = coloredMaterial;\r\n } else if (light instanceof SpotLight) {\r\n lightPositionGizmo = CylinderBuilder.CreateCylinder(\r\n 'lightPositionCone',\r\n { diameterTop: 0.5, height: 0.5, diameterBottom: 0, tessellation: 12 },\r\n scene\r\n );\r\n lightPositionGizmo.position.y = 0.25;\r\n lightPositionGizmo.bakeCurrentTransformIntoVertices();\r\n\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n lightPositionGizmo.material = coloredMaterial;\r\n } else if (light instanceof DirectionalLight) {\r\n const gizmoOffset = 1;\r\n lightPositionGizmo = GroundBuilder.CreateGround(\r\n 'lightPositionPlane',\r\n {\r\n height: 1.5,\r\n width: 1.5,\r\n subdivisions: 1,\r\n },\r\n scene\r\n );\r\n const cone = CylinderBuilder.CreateCylinder(\r\n 'cylinder',\r\n { diameterTop: 0, height: 0.075, diameterBottom: 0.0375, tessellation: 96 },\r\n scene\r\n );\r\n const line = CylinderBuilder.CreateCylinder(\r\n 'cylinder',\r\n { diameterTop: 0.005, height: 0.5, diameterBottom: 0.005, tessellation: 96 },\r\n scene\r\n );\r\n\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n\r\n lightPositionGizmo.material = coloredMaterial;\r\n cone.material = coloredMaterial;\r\n line.material = coloredMaterial;\r\n //cone.rotation.x = Math.PI / 2;\r\n lightPositionGizmo.position.y = -gizmoOffset;\r\n lightPositionGizmo.bakeCurrentTransformIntoVertices();\r\n\r\n cone.parent = lightPositionGizmo;\r\n line.parent = lightPositionGizmo;\r\n cone.position.y = 0.275 - gizmoOffset;\r\n line.position.y = -gizmoOffset;\r\n //line.rotation.x = Math.PI / 2;\r\n } else {\r\n // PointLight\r\n lightPositionGizmo = SphereBuilder.CreateSphere('lightPositionMarker', { diameter: 0.1 }, scene);\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.emissiveColor = color;\r\n lightPositionGizmo.material = coloredMaterial;\r\n }\r\n\r\n lightPositionGizmo.isPickable = false;\r\n lightPositionGizmo.setEnabled(true);\r\n return lightPositionGizmo;\r\n}\r\n","export class Quad {\r\n constructor(public capacity = 4) {}\r\n\r\n public points = new Array();\r\n}\r\n\r\nexport interface IPoint {\r\n x: number;\r\n y: number;\r\n}\r\n\r\nexport interface IBoundary {\r\n xmin: number;\r\n xmax: number;\r\n ymin: number;\r\n ymax: number;\r\n}\r\n\r\nexport class Boundary implements IBoundary {\r\n constructor(public xmin: number, public xmax: number, public ymin: number, public ymax: number) {}\r\n\r\n boundaryContains(point: IPoint) {\r\n return this.xmin <= point.x && this.xmax >= point.x && this.ymin <= point.y && this.ymax >= point.y;\r\n }\r\n\r\n intersects(b: Boundary) {\r\n if (this.xmin >= b.xmax || b.xmin >= this.xmax || this.ymin >= b.ymax || b.ymin >= this.ymax) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n get halfPoint() {\r\n return {\r\n x: this.xmin + this.width / 2,\r\n y: this.ymin + this.height / 2,\r\n } as IPoint;\r\n }\r\n\r\n get width() {\r\n return this.xmax - this.xmin;\r\n }\r\n get height() {\r\n return this.ymax - this.ymin;\r\n }\r\n}\r\n\r\nexport interface IQuadTreeOptions extends IBoundary {\r\n items: T[];\r\n xSelector: (item: T) => number;\r\n ySelector: (item: T) => number;\r\n capacity: number;\r\n}\r\n\r\ninterface IProximityItem {\r\n item: T;\r\n proximity: number;\r\n}\r\n\r\nexport class QuadTree extends Boundary {\r\n constructor(public o: IQuadTreeOptions) {\r\n super(o.xmin, o.xmax, o.ymin, o.ymax);\r\n\r\n this.xSelector = o.xSelector;\r\n this.ySelector = o.ySelector;\r\n this.capacity = o.capacity;\r\n\r\n if (o.items) {\r\n for (const item of o.items) this.add(item);\r\n }\r\n }\r\n\r\n public items = new Array();\r\n private size = 0;\r\n private duplicatesMap: Record = {};\r\n public xSelector: (item: T) => number;\r\n public ySelector: (item: T) => number;\r\n public capacity: number;\r\n\r\n public nw: QuadTree;\r\n public ne: QuadTree;\r\n public sw: QuadTree;\r\n public se: QuadTree;\r\n\r\n private _divided = false;\r\n public get divided() {\r\n return this._divided;\r\n }\r\n\r\n public get quads() {\r\n const arr = Array>();\r\n if (this.nw) arr.push(this.nw);\r\n if (this.ne) arr.push(this.ne);\r\n if (this.sw) arr.push(this.sw);\r\n if (this.se) arr.push(this.se);\r\n return arr;\r\n }\r\n\r\n public find(point: IPoint, radius: number): Array> {\r\n const b = new Boundary(point.x - radius, point.x + radius, point.y - radius, point.y + radius);\r\n const results = this.findByBoundary(b);\r\n\r\n //sort by proximity\r\n results.sortBy(r => r.proximity);\r\n return results;\r\n }\r\n\r\n public findByBoundary(boundary: Boundary): Array> {\r\n const results = new Array>();\r\n\r\n if (!this.intersects(boundary)) {\r\n return results;\r\n }\r\n\r\n if (this.divided) {\r\n for (const q of this.quads) {\r\n results.push(...q.findByBoundary(boundary));\r\n }\r\n } else {\r\n //check items at this level\r\n for (const i of this.items) {\r\n if (boundary.boundaryContains(this.itemPoint(i))) {\r\n results.push(this.getWithProximity(i, boundary.halfPoint));\r\n }\r\n }\r\n }\r\n\r\n return results;\r\n }\r\n\r\n protected getWithProximity(item: T, searchPoint: IPoint): IProximityItem {\r\n const itemPoint = this.itemPoint(item);\r\n return {\r\n item: item,\r\n proximity: Math.sqrt(Math.pow(searchPoint.x - itemPoint.x, 2) + Math.pow(searchPoint.y - itemPoint.y, 2)),\r\n };\r\n }\r\n\r\n protected positionKey(point: { x: number; y: number }) {\r\n return point.x + ',' + point.y;\r\n }\r\n\r\n public add(item: T): boolean {\r\n const point = this.itemPoint(item);\r\n const key = this.positionKey(point);\r\n if (!this.boundaryContains(point)) {\r\n return false;\r\n }\r\n // If there is another point in this quad with the **exact** same position, add it to this quad as well.\r\n // This may result in overfilling the quad but there's no other way to handle exact duplicate points\r\n if (this.duplicatesMap[key]) {\r\n this.items.push(item);\r\n return true;\r\n }\r\n\r\n //if there is space for it, and no sub-divisions, add it to this quad\r\n if (this.size < this.o.capacity && !this.divided) {\r\n this.items.push(item);\r\n this.duplicatesMap[key] = item;\r\n this.size++;\r\n return true;\r\n }\r\n\r\n if (!this.divided) {\r\n this.subdivide();\r\n }\r\n\r\n for (const q of this.quads) {\r\n if (q.add(item)) return true;\r\n }\r\n\r\n throw Error('unexpected error creating quadtree');\r\n }\r\n\r\n protected subdivide() {\r\n // No need to check y, if x is infinitesimally small then y is as well\r\n if (this.xmax - this.xmin <= Number.EPSILON * 2) {\r\n throw Error('unexpected error creating quadtree. Not enough granularity');\r\n }\r\n\r\n this.nw = this.createDivision({\r\n items: this.items,\r\n xmin: this.xmin,\r\n xmax: this.halfPoint.x,\r\n ymin: this.ymin,\r\n ymax: this.halfPoint.y,\r\n });\r\n this.ne = this.createDivision({\r\n items: this.items,\r\n xmin: this.halfPoint.x + Number.EPSILON,\r\n xmax: this.xmax,\r\n ymin: this.ymin,\r\n ymax: this.halfPoint.y,\r\n });\r\n this.sw = this.createDivision({\r\n items: this.items,\r\n xmin: this.xmin,\r\n xmax: this.halfPoint.x,\r\n ymin: this.halfPoint.y + Number.EPSILON,\r\n ymax: this.ymax,\r\n });\r\n this.se = this.createDivision({\r\n items: this.items,\r\n xmin: this.halfPoint.x + Number.EPSILON,\r\n xmax: this.xmax,\r\n ymin: this.halfPoint.y + Number.EPSILON,\r\n ymax: this.ymax,\r\n });\r\n\r\n this.items.clear();\r\n this.size = 0;\r\n this._divided = true;\r\n }\r\n\r\n protected itemPoint(item: T): IPoint {\r\n return {\r\n x: this.xSelector(item),\r\n y: this.ySelector(item),\r\n };\r\n }\r\n\r\n protected createDivision(options: Partial>) {\r\n return new QuadTree({\r\n ...this.o,\r\n ...options,\r\n });\r\n }\r\n}\r\n","// @ts-nocheck third party library\r\n/* eslint-disable */\r\n\r\nexport function earcut(data: number[] | Float32Array, holeIndices: number[], dim?: number): number[] {\r\n dim = dim || 2;\r\n\r\n var hasHoles = holeIndices && holeIndices.length,\r\n outerLen = hasHoles ? holeIndices[0] * dim : data.length,\r\n outerNode = linkedList(data, 0, outerLen, dim, true),\r\n triangles = [];\r\n\r\n if (!outerNode || outerNode.next === outerNode.prev) return triangles;\r\n\r\n var minX, minY, maxX, maxY, x, y, invSize;\r\n\r\n if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);\r\n\r\n // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox\r\n if (data.length > 80 * dim) {\r\n minX = maxX = data[0];\r\n minY = maxY = data[1];\r\n\r\n for (var i = dim; i < outerLen; i += dim) {\r\n x = data[i];\r\n y = data[i + 1];\r\n if (x < minX) minX = x;\r\n if (y < minY) minY = y;\r\n if (x > maxX) maxX = x;\r\n if (y > maxY) maxY = y;\r\n }\r\n\r\n // minX, minY and invSize are later used to transform coords into integers for z-order calculation\r\n invSize = Math.max(maxX - minX, maxY - minY);\r\n invSize = invSize !== 0 ? 32767 / invSize : 0;\r\n }\r\n\r\n earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);\r\n\r\n return triangles;\r\n}\r\n\r\n// create a circular doubly linked list from polygon points in the specified winding order\r\nfunction linkedList(data, start, end, dim, clockwise) {\r\n var i, last;\r\n\r\n if (clockwise === signedArea(data, start, end, dim) > 0) {\r\n for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last);\r\n } else {\r\n for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last);\r\n }\r\n\r\n if (last && equals(last, last.next)) {\r\n removeNode(last);\r\n last = last.next;\r\n }\r\n\r\n return last;\r\n}\r\n\r\n// eliminate colinear or duplicate points\r\nfunction filterPoints(start, end) {\r\n if (!start) return start;\r\n if (!end) end = start;\r\n\r\n var p = start,\r\n again;\r\n do {\r\n again = false;\r\n\r\n if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {\r\n removeNode(p);\r\n p = end = p.prev;\r\n if (p === p.next) break;\r\n again = true;\r\n } else {\r\n p = p.next;\r\n }\r\n } while (again || p !== end);\r\n\r\n return end;\r\n}\r\n\r\n// main ear slicing loop which triangulates a polygon (given as a linked list)\r\nfunction earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {\r\n if (!ear) return;\r\n\r\n // interlink polygon nodes in z-order\r\n if (!pass && invSize) indexCurve(ear, minX, minY, invSize);\r\n\r\n var stop = ear,\r\n prev,\r\n next;\r\n\r\n // iterate through ears, slicing them one by one\r\n while (ear.prev !== ear.next) {\r\n prev = ear.prev;\r\n next = ear.next;\r\n\r\n if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {\r\n // cut off the triangle\r\n triangles.push((prev.i / dim) | 0);\r\n triangles.push((ear.i / dim) | 0);\r\n triangles.push((next.i / dim) | 0);\r\n\r\n removeNode(ear);\r\n\r\n // skipping the next vertex leads to less sliver triangles\r\n ear = next.next;\r\n stop = next.next;\r\n\r\n continue;\r\n }\r\n\r\n ear = next;\r\n\r\n // if we looped through the whole remaining polygon and can't find any more ears\r\n if (ear === stop) {\r\n // try filtering points and slicing again\r\n if (!pass) {\r\n earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);\r\n\r\n // if this didn't work, try curing all small self-intersections locally\r\n } else if (pass === 1) {\r\n ear = cureLocalIntersections(filterPoints(ear), triangles, dim);\r\n earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);\r\n\r\n // as a last resort, try splitting the remaining polygon into two\r\n } else if (pass === 2) {\r\n splitEarcut(ear, triangles, dim, minX, minY, invSize);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n}\r\n\r\n// check whether a polygon node forms a valid ear with adjacent nodes\r\nfunction isEar(ear) {\r\n var a = ear.prev,\r\n b = ear,\r\n c = ear.next;\r\n\r\n if (area(a, b, c) >= 0) return false; // reflex, can't be an ear\r\n\r\n // now make sure we don't have other points inside the potential ear\r\n var ax = a.x,\r\n bx = b.x,\r\n cx = c.x,\r\n ay = a.y,\r\n by = b.y,\r\n cy = c.y;\r\n\r\n // triangle bbox; min & max are calculated like this for speed\r\n var x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx,\r\n y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy,\r\n x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx,\r\n y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;\r\n\r\n var p = c.next;\r\n while (p !== a) {\r\n if (\r\n p.x >= x0 &&\r\n p.x <= x1 &&\r\n p.y >= y0 &&\r\n p.y <= y1 &&\r\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\r\n area(p.prev, p, p.next) >= 0\r\n )\r\n return false;\r\n p = p.next;\r\n }\r\n\r\n return true;\r\n}\r\n\r\nfunction isEarHashed(ear, minX, minY, invSize) {\r\n var a = ear.prev,\r\n b = ear,\r\n c = ear.next;\r\n\r\n if (area(a, b, c) >= 0) return false; // reflex, can't be an ear\r\n\r\n var ax = a.x,\r\n bx = b.x,\r\n cx = c.x,\r\n ay = a.y,\r\n by = b.y,\r\n cy = c.y;\r\n\r\n // triangle bbox; min & max are calculated like this for speed\r\n var x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx,\r\n y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy,\r\n x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx,\r\n y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;\r\n\r\n // z-order range for the current triangle bbox;\r\n var minZ = zOrder(x0, y0, minX, minY, invSize),\r\n maxZ = zOrder(x1, y1, minX, minY, invSize);\r\n\r\n var p = ear.prevZ,\r\n n = ear.nextZ;\r\n\r\n // look for points inside the triangle in both directions\r\n while (p && p.z >= minZ && n && n.z <= maxZ) {\r\n if (\r\n p.x >= x0 &&\r\n p.x <= x1 &&\r\n p.y >= y0 &&\r\n p.y <= y1 &&\r\n p !== a &&\r\n p !== c &&\r\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\r\n area(p.prev, p, p.next) >= 0\r\n )\r\n return false;\r\n p = p.prevZ;\r\n\r\n if (\r\n n.x >= x0 &&\r\n n.x <= x1 &&\r\n n.y >= y0 &&\r\n n.y <= y1 &&\r\n n !== a &&\r\n n !== c &&\r\n pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&\r\n area(n.prev, n, n.next) >= 0\r\n )\r\n return false;\r\n n = n.nextZ;\r\n }\r\n\r\n // look for remaining points in decreasing z-order\r\n while (p && p.z >= minZ) {\r\n if (\r\n p.x >= x0 &&\r\n p.x <= x1 &&\r\n p.y >= y0 &&\r\n p.y <= y1 &&\r\n p !== a &&\r\n p !== c &&\r\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\r\n area(p.prev, p, p.next) >= 0\r\n )\r\n return false;\r\n p = p.prevZ;\r\n }\r\n\r\n // look for remaining points in increasing z-order\r\n while (n && n.z <= maxZ) {\r\n if (\r\n n.x >= x0 &&\r\n n.x <= x1 &&\r\n n.y >= y0 &&\r\n n.y <= y1 &&\r\n n !== a &&\r\n n !== c &&\r\n pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&\r\n area(n.prev, n, n.next) >= 0\r\n )\r\n return false;\r\n n = n.nextZ;\r\n }\r\n\r\n return true;\r\n}\r\n\r\n// go through all polygon nodes and cure small local self-intersections\r\nfunction cureLocalIntersections(start, triangles, dim) {\r\n var p = start;\r\n do {\r\n var a = p.prev,\r\n b = p.next.next;\r\n\r\n if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {\r\n triangles.push((a.i / dim) | 0);\r\n triangles.push((p.i / dim) | 0);\r\n triangles.push((b.i / dim) | 0);\r\n\r\n // remove two nodes involved\r\n removeNode(p);\r\n removeNode(p.next);\r\n\r\n p = start = b;\r\n }\r\n p = p.next;\r\n } while (p !== start);\r\n\r\n return filterPoints(p);\r\n}\r\n\r\n// try splitting polygon into two and triangulate them independently\r\nfunction splitEarcut(start, triangles, dim, minX, minY, invSize) {\r\n // look for a valid diagonal that divides the polygon into two\r\n var a = start;\r\n do {\r\n var b = a.next.next;\r\n while (b !== a.prev) {\r\n if (a.i !== b.i && isValidDiagonal(a, b)) {\r\n // split the polygon in two by the diagonal\r\n var c = splitPolygon(a, b);\r\n\r\n // filter colinear points around the cuts\r\n a = filterPoints(a, a.next);\r\n c = filterPoints(c, c.next);\r\n\r\n // run earcut on each half\r\n earcutLinked(a, triangles, dim, minX, minY, invSize, 0);\r\n earcutLinked(c, triangles, dim, minX, minY, invSize, 0);\r\n return;\r\n }\r\n b = b.next;\r\n }\r\n a = a.next;\r\n } while (a !== start);\r\n}\r\n\r\n// link every hole into the outer loop, producing a single-ring polygon without holes\r\nfunction eliminateHoles(data, holeIndices, outerNode, dim) {\r\n var queue = [],\r\n i,\r\n len,\r\n start,\r\n end,\r\n list;\r\n\r\n for (i = 0, len = holeIndices.length; i < len; i++) {\r\n start = holeIndices[i] * dim;\r\n end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\r\n list = linkedList(data, start, end, dim, false);\r\n if (list === list.next) list.steiner = true;\r\n queue.push(getLeftmost(list));\r\n }\r\n\r\n queue.sort(compareX);\r\n\r\n // process holes from left to right\r\n for (i = 0; i < queue.length; i++) {\r\n outerNode = eliminateHole(queue[i], outerNode);\r\n }\r\n\r\n return outerNode;\r\n}\r\n\r\nfunction compareX(a, b) {\r\n return a.x - b.x;\r\n}\r\n\r\n// find a bridge between vertices that connects hole with an outer ring and and link it\r\nfunction eliminateHole(hole, outerNode) {\r\n var bridge = findHoleBridge(hole, outerNode);\r\n if (!bridge) {\r\n return outerNode;\r\n }\r\n\r\n var bridgeReverse = splitPolygon(bridge, hole);\r\n\r\n // filter collinear points around the cuts\r\n filterPoints(bridgeReverse, bridgeReverse.next);\r\n return filterPoints(bridge, bridge.next);\r\n}\r\n\r\n// David Eberly's algorithm for finding a bridge between hole and outer polygon\r\nfunction findHoleBridge(hole, outerNode) {\r\n var p = outerNode,\r\n hx = hole.x,\r\n hy = hole.y,\r\n qx = -Infinity,\r\n m;\r\n\r\n // find a segment intersected by a ray from the hole's leftmost point to the left;\r\n // segment's endpoint with lesser x will be potential connection point\r\n do {\r\n if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {\r\n var x = p.x + ((hy - p.y) * (p.next.x - p.x)) / (p.next.y - p.y);\r\n if (x <= hx && x > qx) {\r\n qx = x;\r\n m = p.x < p.next.x ? p : p.next;\r\n if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint\r\n }\r\n }\r\n p = p.next;\r\n } while (p !== outerNode);\r\n\r\n if (!m) return null;\r\n\r\n // look for points inside the triangle of hole point, segment intersection and endpoint;\r\n // if there are no points found, we have a valid connection;\r\n // otherwise choose the point of the minimum angle with the ray as connection point\r\n\r\n var stop = m,\r\n mx = m.x,\r\n my = m.y,\r\n tanMin = Infinity,\r\n tan;\r\n\r\n p = m;\r\n\r\n do {\r\n if (\r\n hx >= p.x &&\r\n p.x >= mx &&\r\n hx !== p.x &&\r\n pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)\r\n ) {\r\n tan = Math.abs(hy - p.y) / (hx - p.x); // tangential\r\n\r\n if (\r\n locallyInside(p, hole) &&\r\n (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))\r\n ) {\r\n m = p;\r\n tanMin = tan;\r\n }\r\n }\r\n\r\n p = p.next;\r\n } while (p !== stop);\r\n\r\n return m;\r\n}\r\n\r\n// whether sector in vertex m contains sector in vertex p in the same coordinates\r\nfunction sectorContainsSector(m, p) {\r\n return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;\r\n}\r\n\r\n// interlink polygon nodes in z-order\r\nfunction indexCurve(start, minX, minY, invSize) {\r\n var p = start;\r\n do {\r\n if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize);\r\n p.prevZ = p.prev;\r\n p.nextZ = p.next;\r\n p = p.next;\r\n } while (p !== start);\r\n\r\n p.prevZ.nextZ = null;\r\n p.prevZ = null;\r\n\r\n sortLinked(p);\r\n}\r\n\r\n// Simon Tatham's linked list merge sort algorithm\r\n// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html\r\nfunction sortLinked(list) {\r\n var i,\r\n p,\r\n q,\r\n e,\r\n tail,\r\n numMerges,\r\n pSize,\r\n qSize,\r\n inSize = 1;\r\n\r\n do {\r\n p = list;\r\n list = null;\r\n tail = null;\r\n numMerges = 0;\r\n\r\n while (p) {\r\n numMerges++;\r\n q = p;\r\n pSize = 0;\r\n for (i = 0; i < inSize; i++) {\r\n pSize++;\r\n q = q.nextZ;\r\n if (!q) break;\r\n }\r\n qSize = inSize;\r\n\r\n while (pSize > 0 || (qSize > 0 && q)) {\r\n if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {\r\n e = p;\r\n p = p.nextZ;\r\n pSize--;\r\n } else {\r\n e = q;\r\n q = q.nextZ;\r\n qSize--;\r\n }\r\n\r\n if (tail) tail.nextZ = e;\r\n else list = e;\r\n\r\n e.prevZ = tail;\r\n tail = e;\r\n }\r\n\r\n p = q;\r\n }\r\n\r\n tail.nextZ = null;\r\n inSize *= 2;\r\n } while (numMerges > 1);\r\n\r\n return list;\r\n}\r\n\r\n// z-order of a point given coords and inverse of the longer side of data bbox\r\nfunction zOrder(x, y, minX, minY, invSize) {\r\n // coords are transformed into non-negative 15-bit integer range\r\n x = ((x - minX) * invSize) | 0;\r\n y = ((y - minY) * invSize) | 0;\r\n\r\n x = (x | (x << 8)) & 0x00ff00ff;\r\n x = (x | (x << 4)) & 0x0f0f0f0f;\r\n x = (x | (x << 2)) & 0x33333333;\r\n x = (x | (x << 1)) & 0x55555555;\r\n\r\n y = (y | (y << 8)) & 0x00ff00ff;\r\n y = (y | (y << 4)) & 0x0f0f0f0f;\r\n y = (y | (y << 2)) & 0x33333333;\r\n y = (y | (y << 1)) & 0x55555555;\r\n\r\n return x | (y << 1);\r\n}\r\n\r\n// find the leftmost node of a polygon ring\r\nfunction getLeftmost(start) {\r\n var p = start,\r\n leftmost = start;\r\n do {\r\n if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p;\r\n p = p.next;\r\n } while (p !== start);\r\n\r\n return leftmost;\r\n}\r\n\r\n// check if a point lies within a convex triangle\r\nfunction pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {\r\n return (\r\n (cx - px) * (ay - py) >= (ax - px) * (cy - py) &&\r\n (ax - px) * (by - py) >= (bx - px) * (ay - py) &&\r\n (bx - px) * (cy - py) >= (cx - px) * (by - py)\r\n );\r\n}\r\n\r\n// check if a diagonal between two polygon nodes is valid (lies in polygon interior)\r\nfunction isValidDiagonal(a, b) {\r\n return (\r\n a.next.i !== b.i &&\r\n a.prev.i !== b.i &&\r\n !intersectsPolygon(a, b) && // dones't intersect other edges\r\n ((locallyInside(a, b) &&\r\n locallyInside(b, a) &&\r\n middleInside(a, b) && // locally visible\r\n (area(a.prev, a, b.prev) || area(a, b.prev, b))) || // does not create opposite-facing sectors\r\n (equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0))\r\n ); // special zero-length case\r\n}\r\n\r\n// signed area of a triangle\r\nfunction area(p, q, r) {\r\n return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);\r\n}\r\n\r\n// check if two points are equal\r\nfunction equals(p1, p2) {\r\n return p1.x === p2.x && p1.y === p2.y;\r\n}\r\n\r\n// check if two segments intersect\r\nfunction intersects(p1, q1, p2, q2) {\r\n var o1 = sign(area(p1, q1, p2));\r\n var o2 = sign(area(p1, q1, q2));\r\n var o3 = sign(area(p2, q2, p1));\r\n var o4 = sign(area(p2, q2, q1));\r\n\r\n if (o1 !== o2 && o3 !== o4) return true; // general case\r\n\r\n if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1\r\n if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1\r\n if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2\r\n if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2\r\n\r\n return false;\r\n}\r\n\r\n// for collinear points p, q, r, check if point q lies on segment pr\r\nfunction onSegment(p, q, r) {\r\n return (\r\n q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y)\r\n );\r\n}\r\n\r\nfunction sign(num) {\r\n return num > 0 ? 1 : num < 0 ? -1 : 0;\r\n}\r\n\r\n// check if a polygon diagonal intersects any polygon segments\r\nfunction intersectsPolygon(a, b) {\r\n var p = a;\r\n do {\r\n if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))\r\n return true;\r\n p = p.next;\r\n } while (p !== a);\r\n\r\n return false;\r\n}\r\n\r\n// check if a polygon diagonal is locally inside the polygon\r\nfunction locallyInside(a, b) {\r\n return area(a.prev, a, a.next) < 0\r\n ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0\r\n : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;\r\n}\r\n\r\n// check if the middle point of a polygon diagonal is inside the polygon\r\nfunction middleInside(a, b) {\r\n var p = a,\r\n inside = false,\r\n px = (a.x + b.x) / 2,\r\n py = (a.y + b.y) / 2;\r\n do {\r\n if (\r\n p.y > py !== p.next.y > py &&\r\n p.next.y !== p.y &&\r\n px < ((p.next.x - p.x) * (py - p.y)) / (p.next.y - p.y) + p.x\r\n )\r\n inside = !inside;\r\n p = p.next;\r\n } while (p !== a);\r\n\r\n return inside;\r\n}\r\n\r\n// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;\r\n// if one belongs to the outer ring and another to a hole, it merges it into a single ring\r\nfunction splitPolygon(a, b) {\r\n var a2 = new Node(a.i, a.x, a.y),\r\n b2 = new Node(b.i, b.x, b.y),\r\n an = a.next,\r\n bp = b.prev;\r\n\r\n a.next = b;\r\n b.prev = a;\r\n\r\n a2.next = an;\r\n an.prev = a2;\r\n\r\n b2.next = a2;\r\n a2.prev = b2;\r\n\r\n bp.next = b2;\r\n b2.prev = bp;\r\n\r\n return b2;\r\n}\r\n\r\n// create a node and optionally link it with previous one (in a circular doubly linked list)\r\nfunction insertNode(i, x, y, last) {\r\n var p = new Node(i, x, y);\r\n\r\n if (!last) {\r\n p.prev = p;\r\n p.next = p;\r\n } else {\r\n p.next = last.next;\r\n p.prev = last;\r\n last.next.prev = p;\r\n last.next = p;\r\n }\r\n return p;\r\n}\r\n\r\nfunction removeNode(p) {\r\n p.next.prev = p.prev;\r\n p.prev.next = p.next;\r\n\r\n if (p.prevZ) p.prevZ.nextZ = p.nextZ;\r\n if (p.nextZ) p.nextZ.prevZ = p.prevZ;\r\n}\r\n\r\nfunction Node(i, x, y) {\r\n // vertex index in coordinates array\r\n this.i = i;\r\n\r\n // vertex coordinates\r\n this.x = x;\r\n this.y = y;\r\n\r\n // previous and next vertex nodes in a polygon ring\r\n this.prev = null;\r\n this.next = null;\r\n\r\n // z-order curve value\r\n this.z = 0;\r\n\r\n // previous and next nodes in z-order\r\n this.prevZ = null;\r\n this.nextZ = null;\r\n\r\n // indicates whether this is a steiner point\r\n this.steiner = false;\r\n}\r\n\r\n// return a percentage difference between the polygon area and its triangulation area;\r\n// used to verify correctness of triangulation\r\nearcut.deviation = function (data, holeIndices, dim, triangles) {\r\n var hasHoles = holeIndices && holeIndices.length;\r\n var outerLen = hasHoles ? holeIndices[0] * dim : data.length;\r\n\r\n var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));\r\n if (hasHoles) {\r\n for (var i = 0, len = holeIndices.length; i < len; i++) {\r\n var start = holeIndices[i] * dim;\r\n var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\r\n polygonArea -= Math.abs(signedArea(data, start, end, dim));\r\n }\r\n }\r\n\r\n var trianglesArea = 0;\r\n for (i = 0; i < triangles.length; i += 3) {\r\n var a = triangles[i] * dim;\r\n var b = triangles[i + 1] * dim;\r\n var c = triangles[i + 2] * dim;\r\n trianglesArea += Math.abs(\r\n (data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1])\r\n );\r\n }\r\n\r\n return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);\r\n};\r\n\r\nfunction signedArea(data, start, end, dim) {\r\n var sum = 0;\r\n for (var i = start, j = end - dim; i < end; i += dim) {\r\n sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);\r\n j = i;\r\n }\r\n return sum;\r\n}\r\n\r\n// turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts\r\nearcut.flatten = function (data) {\r\n var dim = data[0][0].length,\r\n result = { vertices: [], holes: [], dimensions: dim },\r\n holeIndex = 0;\r\n\r\n for (var i = 0; i < data.length; i++) {\r\n for (var j = 0; j < data[i].length; j++) {\r\n for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);\r\n }\r\n if (i > 0) {\r\n holeIndex += data[i - 1].length;\r\n result.holes.push(holeIndex);\r\n }\r\n }\r\n return result;\r\n};\r\n","import { Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { SubMesh } from '@babylonjs/core/Meshes/subMesh';\r\nimport { IndicesArray, Nullable } from '@babylonjs/core/types';\r\nimport { KbGeometry } from '@models/classes';\r\nimport { SubmeshData } from '@models/classes/features/submesh-feature';\r\n\r\nexport class SubmeshVertexData extends VertexData {\r\n /** Array of linked index segments, i.e. 0,1,1,2,2,3. A break in the link corresponds to a new path. */\r\n paths?: Nullable;\r\n /** Array of pairs of numbers, the first is the hole identifier, and the second is the index at which the hole starts in the path array */\r\n holes?: Nullable;\r\n submeshData?: Nullable;\r\n\r\n constructor() {\r\n super();\r\n this.indices = null;\r\n this.positions = null;\r\n this.normals = null;\r\n this.tangents = null;\r\n this.submeshData = null;\r\n }\r\n\r\n /**\r\n * @param kbGeometry the kbGeometry to copy the vertex data from.\r\n * Note that this copipes the vertex data by reference, so mutating the data WILL modify the kbGeometry.\r\n */\r\n static FromGeometry(kbGeometry: KbGeometry) {\r\n const result = new SubmeshVertexData();\r\n result.indices = kbGeometry.indices || null;\r\n result.positions = kbGeometry.positions || null;\r\n result.normals = kbGeometry.normals || null;\r\n result.tangents = kbGeometry.tangents || null;\r\n result.uvs = kbGeometry.uvs || null;\r\n result.submeshData = [\r\n {\r\n materialIndex: 0,\r\n verticesStart: 0,\r\n verticesCount: kbGeometry.positions ? kbGeometry.positions.length / 3 : 0,\r\n indexStart: 0,\r\n indexCount: kbGeometry.indices ? kbGeometry.indices.length : 0,\r\n },\r\n ];\r\n\r\n return result;\r\n }\r\n\r\n static ExtractFromMesh(mesh: Mesh, copyWhenShared?: boolean | undefined, forceCopy?: boolean | undefined) {\r\n const result = new SubmeshVertexData();\r\n const vertexData = super.ExtractFromMesh(mesh, copyWhenShared, forceCopy);\r\n\r\n SubmeshVertexData.CopyToRef(vertexData, result);\r\n if (mesh.subMeshes) {\r\n result.submeshData = extractSubmeshData(mesh.subMeshes);\r\n }\r\n if (mesh.metadata && mesh.metadata['paths']) {\r\n result.paths = copyWhenShared ? mesh.metadata['paths'].slice() : mesh.metadata['paths'];\r\n }\r\n if (mesh.metadata && mesh.metadata['holes']) {\r\n result.holes = copyWhenShared ? mesh.metadata['holes'].slice() : mesh.metadata['holes'];\r\n }\r\n\r\n return result;\r\n }\r\n\r\n static CopyToRef(source: Partial, target: SubmeshVertexData) {\r\n target.positions = source.positions || null;\r\n if ('paths' in source) {\r\n target.paths = source.paths || null;\r\n }\r\n if ('holes' in source) {\r\n target.holes = source.holes || null;\r\n }\r\n target.normals = source.normals || null;\r\n target.tangents = source.tangents || null;\r\n target.uvs = source.uvs || null;\r\n target.uvs2 = source.uvs2 || null;\r\n target.uvs3 = source.uvs3 || null;\r\n target.uvs4 = source.uvs4 || null;\r\n target.uvs5 = source.uvs5 || null;\r\n target.uvs6 = source.uvs6 || null;\r\n target.colors = source.colors || null;\r\n target.matricesIndices = source.matricesIndices || null;\r\n target.matricesWeights = source.matricesWeights || null;\r\n target.matricesIndicesExtra = source.matricesIndicesExtra || null;\r\n target.matricesWeightsExtra = source.matricesWeightsExtra || null;\r\n target.indices = source.indices || null;\r\n target.submeshData = (source as SubmeshVertexData).submeshData;\r\n }\r\n\r\n static ExtendToRef(source: Partial, target: SubmeshVertexData) {\r\n if (source.positions !== undefined) target.positions = source.positions;\r\n if ('paths' in source && source.paths !== undefined) target.paths = source.paths;\r\n if ('holes' in source && source.holes !== undefined) target.holes = source.holes;\r\n if (source.normals !== undefined) target.normals = source.normals;\r\n if (source.tangents !== undefined) target.tangents = source.tangents;\r\n if (source.uvs !== undefined) target.uvs = source.uvs;\r\n if (source.uvs2 !== undefined) target.uvs2 = source.uvs2;\r\n if (source.uvs3 !== undefined) target.uvs3 = source.uvs3;\r\n if (source.uvs4 !== undefined) target.uvs4 = source.uvs4;\r\n if (source.uvs5 !== undefined) target.uvs5 = source.uvs5;\r\n if (source.uvs6 !== undefined) target.uvs6 = source.uvs6;\r\n if (source.colors !== undefined) target.colors = source.colors;\r\n if (source.matricesIndices !== undefined) target.matricesIndices = source.matricesIndices;\r\n if (source.matricesWeights !== undefined) target.matricesWeights = source.matricesWeights;\r\n if (source.matricesIndicesExtra !== undefined) target.matricesIndicesExtra = source.matricesIndicesExtra;\r\n if (source.matricesWeightsExtra !== undefined) target.matricesWeightsExtra = source.matricesWeightsExtra;\r\n if (source.indices !== undefined) target.indices = source.indices;\r\n if ((source as SubmeshVertexData).submeshData !== undefined) {\r\n target.submeshData = (source as SubmeshVertexData).submeshData;\r\n }\r\n }\r\n\r\n deepClone() {\r\n const result = new SubmeshVertexData();\r\n result.indices = this.indices ? this.indices.slice() : null;\r\n result.positions = this.positions ? this.positions.slice() : null;\r\n result.paths = this.paths ? this.paths.slice() : null;\r\n result.holes = this.holes ? this.holes.slice() : null;\r\n result.normals = this.normals ? this.normals.slice() : null;\r\n result.tangents = this.tangents ? this.tangents.slice() : null;\r\n result.uvs = this.uvs ? this.uvs.slice() : null;\r\n result.submeshData = this.submeshData ? JSON.parse(JSON.stringify(this.submeshData)) : undefined;\r\n\r\n return result;\r\n }\r\n\r\n shallowClone() {\r\n const result = new SubmeshVertexData();\r\n SubmeshVertexData.CopyToRef(this, result);\r\n return result;\r\n }\r\n\r\n copyFrom(source: Partial) {\r\n SubmeshVertexData.CopyToRef(source, this);\r\n }\r\n\r\n merge(\r\n others: SubmeshVertexData | SubmeshVertexData[],\r\n use32BitsIndices?: boolean,\r\n forceCloneIndices?: boolean,\r\n mergeMaterialIds?: boolean,\r\n enableCompletion?: boolean\r\n ): SubmeshVertexData {\r\n if (!Array.isArray(others)) {\r\n others = [others];\r\n }\r\n\r\n let pathIdxOffset = this.paths ? this.paths.length : 0;\r\n let segmentIdxOffset = 0;\r\n let vertexIdxOffset = this.positions ? this.positions.length / 3 : 0;\r\n const newPaths: number[] = [];\r\n const newHoles: number[] = [];\r\n\r\n if (this.paths) {\r\n for (let i = 2; i < this.paths.length; i += 2) {\r\n if (this.paths[i] !== this.paths[i - 1]) {\r\n segmentIdxOffset++;\r\n }\r\n }\r\n if (this.holes) {\r\n segmentIdxOffset -= this.holes.length / 2;\r\n }\r\n segmentIdxOffset++;\r\n }\r\n\r\n others.map(other => {\r\n if (other.holes) {\r\n for (let i = 0; i < other.holes.length; i += 2) {\r\n newHoles.push(other.holes[i] + segmentIdxOffset, other.holes[i + 1] + pathIdxOffset);\r\n }\r\n segmentIdxOffset -= other.holes.length / 2;\r\n }\r\n if (other.paths) {\r\n for (let i = 0; i < other.paths.length; i++) {\r\n newPaths.push(other.paths[i] + vertexIdxOffset);\r\n }\r\n for (let i = 2; i < other.paths.length; i += 2) {\r\n if (other.paths[i] !== other.paths[i - 1]) {\r\n segmentIdxOffset++;\r\n }\r\n }\r\n segmentIdxOffset++;\r\n }\r\n\r\n vertexIdxOffset += other.positions ? other.positions.length / 3 : 0;\r\n pathIdxOffset += other.paths ? other.paths.length : 0;\r\n });\r\n\r\n super.merge(others, use32BitsIndices, true, mergeMaterialIds, enableCompletion);\r\n\r\n if (newHoles.length) {\r\n if (!this.holes) {\r\n this.holes = new Int32Array();\r\n }\r\n if ('push' in this.holes) {\r\n for (let i = 0; i < newHoles.length; i++) {\r\n this.holes.push(newHoles[i]);\r\n }\r\n } else {\r\n const newArr: Int32Array = new Int32Array(this.holes.length + newHoles.length);\r\n newArr.set(this.holes);\r\n newArr.set(newHoles, this.holes.length);\r\n this.holes = newArr;\r\n }\r\n }\r\n if (newPaths.length) {\r\n if (!this.paths) {\r\n this.paths = new Int32Array();\r\n }\r\n if ('push' in this.paths) {\r\n for (let i = 0; i < newPaths.length; i++) {\r\n this.paths.push(newPaths[i]);\r\n }\r\n } else {\r\n const newArr: Int32Array = new Int32Array(this.paths.length + newPaths.length);\r\n newArr.set(this.paths);\r\n newArr.set(newPaths, this.paths.length);\r\n this.paths = newArr;\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n applyToMesh(mesh: Mesh, updatable = true, writeSubmeshes = true) {\r\n if (!this.submeshData && writeSubmeshes && mesh.subMeshes && mesh.subMeshes.length > 1) {\r\n this.submeshData = extractSubmeshData(mesh.subMeshes);\r\n }\r\n const result = super.applyToMesh(mesh, updatable);\r\n if (this.paths) {\r\n if (!mesh.metadata) {\r\n mesh.metadata = {};\r\n }\r\n mesh.metadata['paths'] = this.paths.slice();\r\n }\r\n if (this.holes) {\r\n if (!mesh.metadata) {\r\n mesh.metadata = {};\r\n }\r\n mesh.metadata['holes'] = this.holes.slice();\r\n }\r\n if (mesh.geometry) {\r\n // Applying geometry doesn't remove vertex types if they are unset so remove them manually\r\n if (!this.normals) {\r\n mesh.geometry.removeVerticesData(VertexBuffer.NormalKind);\r\n }\r\n if (!this.uvs) {\r\n mesh.geometry.removeVerticesData(VertexBuffer.UVKind);\r\n }\r\n }\r\n\r\n if (writeSubmeshes) {\r\n if (this.submeshData) {\r\n mesh.subMeshes = [];\r\n this.submeshData.forEach(submesh => {\r\n // SubMeshes add themselves to the mesh\r\n new SubMesh(\r\n submesh.materialIndex,\r\n submesh.verticesStart,\r\n submesh.verticesCount,\r\n submesh.indexStart,\r\n submesh.indexCount,\r\n mesh\r\n );\r\n });\r\n }\r\n } else {\r\n this.submeshData = extractSubmeshData(mesh.subMeshes);\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n\r\nfunction extractSubmeshData(subMeshes: SubMesh[]): SubmeshData[] {\r\n return subMeshes.map(submesh => {\r\n return {\r\n materialIndex: submesh.materialIndex,\r\n verticesStart: submesh.verticesStart,\r\n verticesCount: submesh.verticesCount,\r\n indexStart: submesh.indexStart,\r\n indexCount: submesh.indexCount,\r\n };\r\n });\r\n}\r\n\r\n/**\r\n * @param vertexData\r\n * @returns null if geometry is valid, string if invalid\r\n */\r\nexport function verifyGeometry(vertexData: SubmeshVertexData): null | 'vertices' | 'submeshes' {\r\n let outputError: null | 'vertices' | 'submeshes' = null;\r\n if (vertexData.indices && vertexData.positions && vertexData.indices.length > 0) {\r\n const indicesCount = vertexData.indices.length;\r\n const vertexCount = vertexData.positions.length / 3;\r\n\r\n if (vertexData.submeshData) {\r\n vertexData.submeshData.forEach(submesh => {\r\n if (\r\n submesh.indexStart + submesh.indexCount > indicesCount ||\r\n submesh.verticesStart + submesh.verticesCount > vertexCount\r\n ) {\r\n outputError = 'submeshes';\r\n }\r\n });\r\n }\r\n\r\n if (!outputError) {\r\n const c = vertexData.indices.length;\r\n let maxVertex = -1;\r\n for (let i = 0; i < c; i++) {\r\n maxVertex = Math.max(maxVertex, vertexData.indices[i]);\r\n }\r\n if (maxVertex > vertexData.positions.length / 3) {\r\n outputError = 'vertices';\r\n }\r\n }\r\n }\r\n\r\n return outputError;\r\n}\r\n\r\nexport function getPolygonNormal(_points: Vector3[] | number[] | Float32Array) {\r\n const normal = Vector3.Zero();\r\n if (!_points) {\r\n return normal;\r\n }\r\n\r\n if (typeof _points[0] === 'number') {\r\n const points = _points as number[] | Float32Array;\r\n if (points.length < 9) {\r\n return normal;\r\n }\r\n\r\n const p1 = Vector3.Zero();\r\n const p2 = Vector3.Zero();\r\n\r\n let i = 0;\r\n while (p1.length() === 0 && points.length > i + 5) {\r\n p1.set(points[i + 3], points[i + 4], points[i + 5]);\r\n p1.subtractFromFloatsToRef(points[i], points[i + 1], points[i + 2], p1);\r\n i += 3;\r\n }\r\n\r\n p2.set(points[i], points[i + 1], points[i + 2]);\r\n while (normal.length() === 0 && points.length > i + 3) {\r\n p2.set(points[i + 3], points[i + 4], points[i + 5]);\r\n p2.subtractFromFloatsToRef(points[i], points[i + 1], points[i + 2], p2);\r\n Vector3.CrossToRef(p1, p2, normal);\r\n i += 3;\r\n }\r\n } else {\r\n const points = _points as Vector3[];\r\n if (points.length < 3) {\r\n return normal;\r\n }\r\n const p1 = Vector3.Zero();\r\n const p2 = Vector3.Zero();\r\n\r\n let i = 0;\r\n while (p1.length() === 0 && points.length > i + 1) {\r\n p1.copyFrom(points[i + 1]);\r\n p1.subtractInPlace(points[i]);\r\n i++;\r\n }\r\n\r\n while (normal.length() === 0 && points.length > i + 1) {\r\n p2.copyFrom(points[i + 1]);\r\n p2.subtractInPlace(points[i]);\r\n Vector3.CrossToRef(p1, p2, normal);\r\n i++;\r\n }\r\n }\r\n\r\n return normal.normalize();\r\n}\r\n","import { Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { BoundingBox, Font } from 'opentype.js';\r\nimport { earcut } from './earcut';\r\nimport { SubmeshVertexData } from './geometry-helper';\r\n\r\nconst MAX_BEZIER_STEPS = 10;\r\nconst BEZIER_STEP_SIZE = 20.0;\r\nconst GLYPH_COORDS_SCALE = 0.0005;\r\nconst IDENTITY_Q = Quaternion.Identity();\r\n\r\ninterface Point {\r\n x: number;\r\n y: number;\r\n}\r\n\r\ninterface GlyphDef {\r\n index: number;\r\n advanceWidth: number;\r\n boundingBox: BoundingBox;\r\n vertexData?: SubmeshVertexData;\r\n}\r\n\r\n// class for converting path commands into point data\r\nclass TextMeshPolygon {\r\n points: Point[] = [];\r\n children: TextMeshPolygon[] = [];\r\n area = 0.0;\r\n\r\n distance(p1: Point, p2: Point) {\r\n const dx = p1.x - p2.x,\r\n dy = p1.y - p2.y;\r\n return Math.sqrt(dx * dx + dy * dy);\r\n }\r\n\r\n lerp(p1: Point, p2: Point, t: number) {\r\n return { x: (1 - t) * p1.x + t * p2.x, y: (1 - t) * p1.y + t * p2.y };\r\n }\r\n\r\n cross(p1: Point, p2: Point) {\r\n return p1.x * p2.y - p1.y * p2.x;\r\n }\r\n\r\n moveTo(p: Point) {\r\n this.points.push(p);\r\n }\r\n\r\n lineTo(p: Point) {\r\n this.points.push(p);\r\n }\r\n\r\n close() {\r\n let cur = this.points[this.points.length - 1];\r\n\r\n this.points.forEach(next => {\r\n this.area += 0.5 * this.cross(cur, next);\r\n cur = next;\r\n });\r\n }\r\n\r\n conicTo(p: Point, p1: Point) {\r\n const p0 = this.points[this.points.length - 1];\r\n const dist = this.distance(p0, p1) + this.distance(p1, p);\r\n const steps = Math.max(2, Math.min(MAX_BEZIER_STEPS, dist / BEZIER_STEP_SIZE));\r\n\r\n for (let i = 1; i <= steps; ++i) {\r\n const t = i / steps;\r\n this.points.push(this.lerp(this.lerp(p0, p1, t), this.lerp(p1, p, t), t));\r\n }\r\n }\r\n\r\n cubicTo(p: Point, p1: Point, p2: Point) {\r\n const p0 = this.points[this.points.length - 1];\r\n const dist = this.distance(p0, p1) + this.distance(p1, p2) + this.distance(p2, p);\r\n const steps = Math.max(2, Math.min(MAX_BEZIER_STEPS, dist / BEZIER_STEP_SIZE));\r\n\r\n for (let i = 1; i <= steps; ++i) {\r\n const t = i / steps;\r\n const a = this.lerp(this.lerp(p0, p1, t), this.lerp(p1, p2, t), t);\r\n const b = this.lerp(this.lerp(p1, p2, t), this.lerp(p2, p, t), t);\r\n this.points.push(this.lerp(a, b, t));\r\n }\r\n }\r\n\r\n inside(p: Point) {\r\n const epsilon = 1e-6;\r\n let count = 0,\r\n cur = this.points[this.points.length - 1];\r\n\r\n this.points.forEach(next => {\r\n const p0 = cur.y < next.y ? cur : next;\r\n const p1 = cur.y < next.y ? next : cur;\r\n\r\n if (p0.y < p.y + epsilon && p1.y > p.y + epsilon) {\r\n if ((p1.x - p0.x) * (p.y - p0.y) > (p.x - p0.x) * (p1.y - p0.y)) {\r\n count++;\r\n }\r\n }\r\n\r\n cur = next;\r\n });\r\n return count % 2 !== 0;\r\n }\r\n}\r\n\r\nexport class TextMeshFont {\r\n glyphsParent: Mesh;\r\n glyphs: Record = {};\r\n\r\n constructor(name: string, public font: Font, private scene: Scene) {\r\n this.font = font;\r\n this.glyphsParent = new Mesh(name, scene);\r\n }\r\n\r\n createGlyph(ch: string) {\r\n if (this.glyphs[ch]) {\r\n return this.glyphs[ch];\r\n }\r\n\r\n const glyph = this.font.charToGlyph(ch);\r\n\r\n if (!glyph || !glyph.advanceWidth) {\r\n return undefined;\r\n }\r\n this.glyphs[ch] = {\r\n index: glyph.index,\r\n advanceWidth: glyph.advanceWidth,\r\n boundingBox: glyph.getBoundingBox(),\r\n };\r\n const glyphDef = this.glyphs[ch];\r\n\r\n if (!glyph.path || !glyph.path.commands || !glyph.path.commands.length) {\r\n return glyphDef;\r\n }\r\n const polys: TextMeshPolygon[] = [];\r\n glyph.path.commands.forEach(command => {\r\n const { type, x, y, x1, y1, x2, y2 } = command as unknown as Record & { type: string };\r\n switch (type) {\r\n case 'M':\r\n polys.push(new TextMeshPolygon());\r\n polys[polys.length - 1].moveTo({ x, y });\r\n break;\r\n case 'L':\r\n polys[polys.length - 1].moveTo({ x, y });\r\n break;\r\n case 'C':\r\n polys[polys.length - 1].cubicTo({ x, y }, { x: x1, y: y1 }, { x: x2, y: y2 });\r\n break;\r\n case 'Q':\r\n polys[polys.length - 1].conicTo({ x, y }, { x: x1, y: y1 });\r\n break;\r\n case 'Z':\r\n polys[polys.length - 1].close();\r\n break;\r\n }\r\n });\r\n\r\n // sort contours by descending area\r\n polys.sort((a, b) => Math.abs(b.area) - Math.abs(a.area));\r\n\r\n // classify contours to find holes and their 'parents'\r\n const root = [];\r\n\r\n for (let i = 0; i < polys.length; ++i) {\r\n let parent: TextMeshPolygon | null = null;\r\n for (let j = i - 1; j >= 0; --j) {\r\n // a contour is a hole if it is inside its parent and has different winding\r\n if (polys[j].inside(polys[i].points[0]) && polys[i].area * polys[j].area < 0) {\r\n parent = polys[j];\r\n break;\r\n }\r\n }\r\n if (parent) {\r\n parent.children.push(polys[i]);\r\n } else {\r\n root.push(polys[i]);\r\n }\r\n }\r\n\r\n const totalPoints = polys.reduce((sum, p) => sum + p.points.length, 0);\r\n const vertexData = new Float32Array(totalPoints * 2);\r\n let vertexCount = 0;\r\n let pathSegmentCount = 0;\r\n const indices: number[] = [];\r\n const paths: number[] = [];\r\n const holePaths: number[] = [];\r\n\r\n function process(poly: TextMeshPolygon) {\r\n // construct input for earcut\r\n const coords: number[] = [];\r\n const holes: number[] = [];\r\n const n = poly.points.length - 1;\r\n for (let i = 0; i < n; ++i) {\r\n const { x, y } = poly.points[n - i];\r\n if (i > 0) {\r\n const idx = coords.length / 2;\r\n paths.push(vertexCount + idx - 1, vertexCount + idx);\r\n }\r\n coords.push(x, y);\r\n }\r\n const parentSegmentIdx = pathSegmentCount;\r\n poly.children.forEach((child, i) => {\r\n // children's children are new, separate shapes\r\n child.children.forEach(process);\r\n\r\n // idx 0 of a hole is the segment index of the segment the hole is inside. each separate poly is a separate segment\r\n holePaths.push(parentSegmentIdx, paths.length);\r\n holes.push(coords.length / 2);\r\n const n = child.points.length - 1;\r\n for (let i = 0; i < n; ++i) {\r\n const { x, y } = child.points[i];\r\n if (i > 0) {\r\n const idx = coords.length / 2;\r\n paths.push(idx - 1, idx);\r\n }\r\n coords.push(x, y);\r\n }\r\n pathSegmentCount++;\r\n });\r\n\r\n // add vertex data\r\n vertexData.set(coords, vertexCount * 2);\r\n // add index data\r\n earcut(coords, holes).forEach(i => {\r\n indices.push(i + vertexCount);\r\n });\r\n vertexCount += coords.length / 2;\r\n pathSegmentCount++;\r\n }\r\n\r\n root.forEach(process);\r\n\r\n const meshdata = new SubmeshVertexData();\r\n const vertices: number[] = [];\r\n const normals: number[] = [];\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n vertices.push(vertexData[i * 2] * GLYPH_COORDS_SCALE);\r\n vertices.push(vertexData[i * 2 + 1] * GLYPH_COORDS_SCALE);\r\n vertices.push(0);\r\n\r\n normals.push(0);\r\n normals.push(0);\r\n normals.push(1);\r\n }\r\n\r\n const flipIndices = [];\r\n for (let i = 0; i < indices.length; i += 3) {\r\n flipIndices.push(indices[i], indices[i + 2], indices[i + 1]);\r\n }\r\n\r\n meshdata.positions = vertices;\r\n meshdata.indices = flipIndices;\r\n meshdata.normals = normals;\r\n meshdata.paths = paths;\r\n meshdata.holes = holePaths;\r\n\r\n glyphDef.vertexData = meshdata;\r\n\r\n return glyphDef;\r\n }\r\n}\r\n\r\nexport class TextMeshVertexData {\r\n instances: Record = {};\r\n\r\n constructor(private textMeshFont: TextMeshFont) {}\r\n\r\n getText(text: string, fontSize = 1, charSpacing = 1, radius = 0) {\r\n radius = radius / fontSize;\r\n const scaleMatrix = Matrix.Compose(new Vector3(fontSize, fontSize, 1), IDENTITY_Q, Vector3.ZeroReadOnly);\r\n const vertexData = new SubmeshVertexData();\r\n const pos = Vector3.Zero();\r\n const transformMatrix = Matrix.Identity();\r\n\r\n const generatedVertices: Array<{ data: SubmeshVertexData; transform: Matrix; center: number }> = [];\r\n\r\n for (let i = 0; i < text.length; i++) {\r\n const ch1 = text[i];\r\n\r\n if (ch1 === '\\n') {\r\n pos.x = 0;\r\n pos.y -= 1.1;\r\n continue;\r\n }\r\n transformMatrix.setTranslation(pos);\r\n\r\n const ch2 = text[i + 1];\r\n const g = this.textMeshFont.createGlyph(ch1);\r\n\r\n if (!g) {\r\n continue;\r\n }\r\n let advance = g.advanceWidth;\r\n\r\n if (g.vertexData) {\r\n generatedVertices.push({\r\n data: g.vertexData.deepClone(),\r\n transform: transformMatrix.clone(),\r\n center: (advance / 2 + g.boundingBox.x1) * GLYPH_COORDS_SCALE,\r\n });\r\n }\r\n\r\n if (advance) {\r\n if (ch2 && this.textMeshFont.glyphs[ch2]) {\r\n const kern = this.textMeshFont.font.getKerningValue(g.index, this.textMeshFont.glyphs[ch2].index);\r\n\r\n if (kern) {\r\n advance += kern;\r\n }\r\n }\r\n\r\n pos.x += (advance - g.boundingBox.x2 + g.boundingBox.x2 * charSpacing) * GLYPH_COORDS_SCALE;\r\n }\r\n }\r\n\r\n if (generatedVertices.length > 0) {\r\n const centerTransform = Matrix.Compose(Vector3.OneReadOnly, IDENTITY_Q, pos.scale(-0.5));\r\n\r\n for (const generatedVertexData of generatedVertices) {\r\n const transform = generatedVertexData.transform;\r\n transform.multiplyToRef(centerTransform, transform);\r\n\r\n // Add curve to text\r\n if (radius !== 0) {\r\n const baseOffset = transform.getTranslation();\r\n const angle = (baseOffset.x + generatedVertexData.center) / radius;\r\n const pivotMatrix = Matrix.Compose(\r\n Vector3.OneReadOnly,\r\n IDENTITY_Q,\r\n new Vector3(generatedVertexData.center, -radius, 0)\r\n );\r\n const rotMatrix = Matrix.Compose(\r\n Vector3.OneReadOnly,\r\n Quaternion.RotationAxis(new Vector3(0, 0, -1), angle),\r\n Vector3.ZeroReadOnly\r\n );\r\n const curveTransform = pivotMatrix.clone().invert();\r\n curveTransform.multiplyToRef(rotMatrix, curveTransform);\r\n curveTransform.multiplyToRef(pivotMatrix, curveTransform);\r\n curveTransform.setTranslation(\r\n curveTransform.getTranslation().addInPlaceFromFloats(-generatedVertexData.center, 0, 0)\r\n );\r\n\r\n transform.copyFrom(curveTransform);\r\n }\r\n\r\n transform.multiplyToRef(scaleMatrix, transform);\r\n generatedVertexData.data.transform(transform);\r\n }\r\n\r\n vertexData.copyFrom(generatedVertices[0].data);\r\n\r\n if (generatedVertices.length > 1) {\r\n vertexData.merge(generatedVertices.slice(1).map(generatedVertexData => generatedVertexData.data));\r\n }\r\n }\r\n\r\n // const calcW = this.textMeshFont.font.getAdvanceWidth(text) * GLYPH_COORDS_SCALE;\r\n\r\n // if (vertexData.positions) {\r\n // const max = Vector3.Zero();\r\n // for (let i = 0; i < vertexData.positions.length; i += 3) {\r\n // const p = vertexData.positions;\r\n // max.x = Math.max(max.x, p[i]);\r\n // max.y = Math.max(max.y, p[i + 1]);\r\n // max.z = Math.max(max.z, p[i + 2]);\r\n // }\r\n // const centerTransform = Matrix.Compose(Vector3.OneReadOnly, Quaternion.Identity(), max.scale(-0.5));\r\n // vertexData.transform(centerTransform);\r\n // }\r\n\r\n return vertexData;\r\n }\r\n}\r\n","import { Engine } from \"../Engines/engine\";\r\nimport { RawTexture } from \"./Textures/rawTexture\";\r\nimport { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport { Vector2, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Material } from \"./material\";\r\nimport { MaterialDefines } from \"./materialDefines\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { BaseTexture } from \"./Textures/baseTexture\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\n/**\r\n * Material types for GreasedLine\r\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#materialtype}\r\n */\r\nexport enum GreasedLineMeshMaterialType {\r\n /**\r\n * StandardMaterial\r\n */\r\n MATERIAL_TYPE_STANDARD = 0,\r\n /**\r\n * PBR Material\r\n */\r\n MATERIAL_TYPE_PBR = 1,\r\n}\r\n\r\n/**\r\n * Color blending mode of the @see GreasedLineMaterial and the base material\r\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#colormode}\r\n */\r\nexport enum GreasedLineMeshColorMode {\r\n /**\r\n * Color blending mode SET\r\n */\r\n COLOR_MODE_SET = 0,\r\n /**\r\n * Color blending mode ADD\r\n */\r\n COLOR_MODE_ADD = 1,\r\n /**\r\n * Color blending mode ADD\r\n */\r\n COLOR_MODE_MULTIPLY = 2,\r\n}\r\n\r\n/**\r\n * Color distribution type of the @see colors.\r\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#colordistributiontype}\r\n *\r\n */\r\nexport enum GreasedLineMeshColorDistributionType {\r\n /**\r\n * Colors distributed between segments of the line\r\n */\r\n COLOR_DISTRIBUTION_TYPE_SEGMENT = 0,\r\n /**\r\n * Colors distributed along the line ingoring the segments\r\n */\r\n COLOR_DISTRIBUTION_TYPE_LINE = 1,\r\n}\r\n\r\n/**\r\n * Options for GreasedLineMaterial\r\n */\r\nexport interface GreasedLineMaterialOptions {\r\n /**\r\n * Line width. If sizeAttenuation os false scene units will be used for width.\r\n * Defaults to 0.1 if @see sizeAttenuation is false, or to 1 if it's true.\r\n */\r\n width?: number;\r\n /**\r\n * If false then width units = scene units. If true then line will width be reduced.\r\n * Defaults to false.\r\n */\r\n sizeAttenuation?: boolean;\r\n /**\r\n * Type of the material to use to render the line.\r\n * Defaults to StandardMaterial.\r\n */\r\n materialType?: GreasedLineMeshMaterialType;\r\n /**\r\n * Color of the line. Applies to all line segments.\r\n * Defaults to White.\r\n */\r\n color?: Color3;\r\n /**\r\n * Color mode of the line. Applies to all line segments.\r\n * The pixel color from the material shader will be modified with the value of @see color using the colorMode.\r\n * Defaults to @see GreasedLineMeshColorMode.SET\r\n */\r\n colorMode?: GreasedLineMeshColorMode;\r\n /**\r\n * Colors of the line segments.\r\n * Defaults to empty.\r\n */\r\n colors?: Color3[];\r\n /**\r\n * If true, @see colors are used, otherwise they're ignored.\r\n * Defaults to false.\r\n */\r\n useColors?: boolean;\r\n /**\r\n * Sampling type of the colors texture\r\n * Defaults to NEAREST_NEAREST.\r\n */\r\n colorsSampling?: number;\r\n /**\r\n * The method used to distribute the colors along the line.\r\n * You can use segment distribution when each segment will use on color from the color table.\r\n * Or you can use line distribution when the colors are distributed evenly along the line ignoring the segments.\r\n */\r\n colorDistributionType?: GreasedLineMeshColorDistributionType;\r\n /**\r\n * If true, dashing is used.\r\n * Defaults to false.\r\n */\r\n useDash?: boolean;\r\n /**\r\n * @see GreasedLinePluginMaterial.setDashCount\r\n * Number of dashes in the line.\r\n * Defaults to 1.\r\n */\r\n dashCount?: number;\r\n /**\r\n * Offset of the dashes along the line. 0 to 1.\r\n * Defaults to 0.\r\n * @see GreasedLinePluginMaterial.setDashOffset\r\n */\r\n dashOffset?: number;\r\n /**\r\n * Length of the dash. 0 to 1. 0.5 means half empty, half drawn.\r\n * Defaults to 0.5.\r\n * @see GreasedLinePluginMaterial.setDashRatio\r\n */\r\n dashRatio?: number;\r\n /**\r\n * Sets the line length visibility.\r\n * 0 - 0% of the line will be visible.\r\n * 1 - 100% of the line will be visible.\r\n * @see GreasedLinePluginMaterial.setVisibility\r\n */\r\n visibility?: number;\r\n /**\r\n * Defaults to engine.getRenderWidth() and engine.getRenderHeight()\r\n * Rendering resolution\r\n */\r\n resolution?: Vector2;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MaterialGreasedLineDefines extends MaterialDefines {\r\n /**\r\n * The material has a color option specified\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n GREASED_LINE_HAS_COLOR = false;\r\n /**\r\n * The material's size attenuation optiom\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n GREASED_LINE_SIZE_ATTENUATION = false;\r\n /**\r\n * The type of color distribution is set to line this value equals to true.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE = false;\r\n /**\r\n * True if scene is in right handed coordinate system.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM = false;\r\n}\r\n\r\n/**\r\n * GreasedLinePluginMaterial for GreasedLineMesh\r\n */\r\nexport class GreasedLinePluginMaterial extends MaterialPluginBase {\r\n /**\r\n * Plugin name\r\n */\r\n public static readonly GREASED_LINE_MATERIAL_NAME = \"GreasedLinePluginMaterial\";\r\n\r\n /**\r\n * Default line color for newly created lines\r\n */\r\n public static DEFAULT_COLOR = Color3.White();\r\n /**\r\n * Default line width when sizeAttenuation is true\r\n */\r\n public static DEFAULT_WIDTH_ATTENUATED = 1;\r\n /**\r\n * Defaule line width\r\n */\r\n public static DEFAULT_WIDTH = 0.1;\r\n\r\n private static _EmptyColorsTexture: BaseTexture;\r\n\r\n /**\r\n * Whether to use the colors option to colorize the line\r\n */\r\n public useColors: boolean;\r\n\r\n /**\r\n * Normalized value of how much of the line will be visible\r\n * 0 - 0% of the line will be visible\r\n * 1 - 100% of the line will be visible\r\n */\r\n public visibility: number;\r\n\r\n /**\r\n * Dash offset\r\n */\r\n public dashOffset: number;\r\n\r\n /**\r\n * Length of the dash. 0 to 1. 0.5 means half empty, half drawn.\r\n */\r\n public dashRatio: number;\r\n\r\n /**\r\n * Line base width. At each point the line width is calculated by widths[pointIndex] * width\r\n */\r\n public width: number;\r\n\r\n /**\r\n * The type of sampling of the colors texture. The values are the same when using with textures.\r\n */\r\n public colorsSampling: number;\r\n\r\n /**\r\n * Turns on/off dash mode\r\n */\r\n public useDash: boolean;\r\n\r\n /**\r\n * The mixing mode of the color paramater. Default value is GreasedLineMeshColorMode.SET\r\n * @see GreasedLineMeshColorMode\r\n */\r\n public colorMode: GreasedLineMeshColorMode;\r\n\r\n private _dashCount: number;\r\n private _dashArray: number;\r\n private _color: Nullable;\r\n private _colors: Nullable;\r\n private _colorsDistributionType: GreasedLineMeshColorDistributionType;\r\n private _resolution: Vector2;\r\n private _aspect: number;\r\n private _sizeAttenuation: boolean;\r\n\r\n private _colorsTexture?: RawTexture;\r\n\r\n private _engine: Engine;\r\n\r\n constructor(material: Material, private _scene: Scene, options?: GreasedLineMaterialOptions) {\r\n options = options || {\r\n color: GreasedLinePluginMaterial.DEFAULT_COLOR,\r\n };\r\n\r\n const defines = new MaterialGreasedLineDefines();\r\n defines.GREASED_LINE_HAS_COLOR = !!options.color;\r\n defines.GREASED_LINE_SIZE_ATTENUATION = options.sizeAttenuation ?? false;\r\n defines.GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE = options.colorDistributionType === GreasedLineMeshColorDistributionType.COLOR_DISTRIBUTION_TYPE_LINE;\r\n defines.GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM = _scene.useRightHandedSystem;\r\n super(material, GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME, 200, defines);\r\n\r\n this._scene = this._scene ?? material.getScene();\r\n this._engine = this._scene.getEngine();\r\n\r\n this.visibility = options.visibility ?? 1;\r\n this.useDash = options.useDash ?? false;\r\n this.dashRatio = options.dashRatio ?? 0.5;\r\n this.dashOffset = options.dashOffset ?? 0;\r\n this.width = options.width ? options.width : options.sizeAttenuation ? GreasedLinePluginMaterial.DEFAULT_WIDTH_ATTENUATED : GreasedLinePluginMaterial.DEFAULT_WIDTH;\r\n this._sizeAttenuation = options.sizeAttenuation ?? false;\r\n this.colorMode = options.colorMode ?? GreasedLineMeshColorMode.COLOR_MODE_SET;\r\n this._color = options.color ?? null;\r\n this.useColors = options.useColors ?? false;\r\n this._colorsDistributionType = options.colorDistributionType ?? GreasedLineMeshColorDistributionType.COLOR_DISTRIBUTION_TYPE_SEGMENT;\r\n this.colorsSampling = options.colorsSampling ?? RawTexture.NEAREST_NEAREST;\r\n this._colors = options.colors ?? null;\r\n\r\n this.dashCount = options.dashCount ?? 1; // calculate the _dashArray value, call the setter\r\n this.resolution = options.resolution ?? new Vector2(this._engine.getRenderWidth(), this._engine.getRenderHeight()); // calculate aspect call the setter\r\n\r\n if (this._colors) {\r\n this._createColorsTexture(`${material.name}-colors-texture`, this._colors);\r\n } else {\r\n this._color = this._color ?? GreasedLinePluginMaterial.DEFAULT_COLOR;\r\n GreasedLinePluginMaterial._PrepareEmptyColorsTexture(_scene);\r\n }\r\n\r\n this._enable(true); // always enabled\r\n }\r\n\r\n /**\r\n * Get the shader attributes\r\n * @param attributes array which will be filled with the attributes\r\n */\r\n getAttributes(attributes: string[]) {\r\n attributes.push(\"grl_offsets\");\r\n attributes.push(\"grl_previousAndSide\");\r\n attributes.push(\"grl_nextAndCounters\");\r\n attributes.push(\"grl_widths\");\r\n attributes.push(\"grl_colorPointers\");\r\n }\r\n\r\n /**\r\n * Get the shader samplers\r\n * @param samplers\r\n */\r\n getSamplers(samplers: string[]) {\r\n samplers.push(\"grl_colors\");\r\n }\r\n\r\n /**\r\n * Get the shader textures\r\n * @param activeTextures\r\n */\r\n public getActiveTextures(activeTextures: BaseTexture[]): void {\r\n if (this._colorsTexture) {\r\n activeTextures.push(this._colorsTexture);\r\n }\r\n }\r\n\r\n /**\r\n * Get the shader uniforms\r\n * @returns uniforms\r\n */\r\n getUniforms() {\r\n const ubo = [\r\n { name: \"grl_projection\", size: 16, type: \"mat4\" },\r\n { name: \"grl_singleColor\", size: 3, type: \"vec3\" },\r\n { name: \"grl_aspect_resolution_lineWidth\", size: 4, type: \"vec4\" },\r\n { name: \"grl_dashOptions\", size: 4, type: \"vec4\" },\r\n { name: \"grl_colorMode_visibility_colorsWidth_useColors\", size: 4, type: \"vec4\" },\r\n ];\r\n\r\n return {\r\n ubo,\r\n vertex: `\r\n uniform vec4 grl_aspect_resolution_lineWidth;\r\n uniform mat4 grl_projection;\r\n `,\r\n fragment: `\r\n uniform vec4 grl_dashOptions;\r\n uniform vec4 grl_colorMode_visibility_colorsWidth_useColors;\r\n uniform vec3 grl_singleColor;\r\n `,\r\n };\r\n }\r\n\r\n // only getter, it doesn't make sense to use this plugin on a mesh other than GreasedLineMesh\r\n // and it doesn't make sense to disable it on the mesh\r\n get isEnabled() {\r\n return true;\r\n }\r\n\r\n /**\r\n * Bind the uniform buffer\r\n * @param uniformBuffer\r\n */\r\n bindForSubMesh(uniformBuffer: UniformBuffer) {\r\n const activeCamera = this._scene.activeCamera;\r\n\r\n if (activeCamera) {\r\n const projection = activeCamera.getProjectionMatrix();\r\n uniformBuffer.updateMatrix(\"grl_projection\", projection);\r\n } else {\r\n throw Error(\"GreasedLinePluginMaterial requires an active camera.\");\r\n }\r\n\r\n const resolutionLineWidth = TmpVectors.Vector4[0];\r\n resolutionLineWidth.x = this._aspect;\r\n resolutionLineWidth.y = this._resolution.x;\r\n resolutionLineWidth.z = this._resolution.y;\r\n resolutionLineWidth.w = this.width;\r\n uniformBuffer.updateVector4(\"grl_aspect_resolution_lineWidth\", resolutionLineWidth);\r\n\r\n const dashOptions = TmpVectors.Vector4[0];\r\n dashOptions.x = GreasedLinePluginMaterial._BooleanToNumber(this.useDash);\r\n dashOptions.y = this._dashArray;\r\n dashOptions.z = this.dashOffset;\r\n dashOptions.w = this.dashRatio;\r\n uniformBuffer.updateVector4(\"grl_dashOptions\", dashOptions);\r\n\r\n const colorModeVisibilityColorsWidthUseColors = TmpVectors.Vector4[1];\r\n colorModeVisibilityColorsWidthUseColors.x = this.colorMode;\r\n colorModeVisibilityColorsWidthUseColors.y = this.visibility;\r\n colorModeVisibilityColorsWidthUseColors.z = this._colorsTexture ? this._colorsTexture.getSize().width : 0;\r\n colorModeVisibilityColorsWidthUseColors.w = GreasedLinePluginMaterial._BooleanToNumber(this.useColors);\r\n uniformBuffer.updateVector4(\"grl_colorMode_visibility_colorsWidth_useColors\", colorModeVisibilityColorsWidthUseColors);\r\n\r\n if (this._color) {\r\n uniformBuffer.updateColor3(\"grl_singleColor\", this._color);\r\n }\r\n\r\n uniformBuffer.setTexture(\"grl_colors\", this._colorsTexture ?? GreasedLinePluginMaterial._EmptyColorsTexture);\r\n }\r\n\r\n /**\r\n * Prepare the defines\r\n * @param defines\r\n * @param _scene\r\n * @param _mesh\r\n */\r\n prepareDefines(defines: MaterialGreasedLineDefines, _scene: Scene, _mesh: AbstractMesh) {\r\n defines.GREASED_LINE_HAS_COLOR = !!this._color;\r\n defines.GREASED_LINE_SIZE_ATTENUATION = this._sizeAttenuation ?? false;\r\n defines.GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE = this._colorsDistributionType === GreasedLineMeshColorDistributionType.COLOR_DISTRIBUTION_TYPE_LINE;\r\n defines.GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM = _scene.useRightHandedSystem;\r\n }\r\n\r\n /**\r\n * Get the class name\r\n * @returns class name\r\n */\r\n getClassName() {\r\n return GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME;\r\n }\r\n\r\n /**\r\n * Get shader code\r\n * @param shaderType vertex/fragment\r\n * @returns shader code\r\n */\r\n getCustomCode(shaderType: string): Nullable<{ [pointName: string]: string }> {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_VERTEX_DEFINITIONS: `\r\n attribute vec4 grl_previousAndSide;\r\n attribute vec4 grl_nextAndCounters;\r\n attribute float grl_widths;\r\n attribute vec3 grl_offsets;\r\n attribute float grl_colorPointers;\r\n\r\n varying float grlCounters;\r\n varying float grlColorPointer;\r\n\r\n vec2 grlFix( vec4 i, float aspect ) {\r\n vec2 res = i.xy / i.w;\r\n res.x *= aspect;\r\n return res;\r\n }\r\n `,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_VERTEX_UPDATE_POSITION: `\r\n vec3 grlPositionOffset = grl_offsets;\r\n positionUpdated += grlPositionOffset;\r\n `,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_VERTEX_MAIN_END: `\r\n\r\n float grlAspect = grl_aspect_resolution_lineWidth.x;\r\n float grlBaseWidth = grl_aspect_resolution_lineWidth.w;\r\n\r\n grlColorPointer = grl_colorPointers;\r\n\r\n vec3 grlPrevious = grl_previousAndSide.xyz;\r\n float grlSide = grl_previousAndSide.w;\r\n\r\n vec3 grlNext = grl_nextAndCounters.xyz;\r\n grlCounters = grl_nextAndCounters.w;\r\n\r\n\r\n mat4 grlMatrix = viewProjection * world;\r\n vec4 grlFinalPosition = grlMatrix * vec4( positionUpdated , 1.0 );\r\n vec4 grlPrevPos = grlMatrix * vec4( grlPrevious + grlPositionOffset, 1.0 );\r\n vec4 grlNextPos = grlMatrix * vec4( grlNext + grlPositionOffset, 1.0 );\r\n\r\n vec2 grlCurrentP = grlFix( grlFinalPosition, grlAspect );\r\n vec2 grlPrevP = grlFix( grlPrevPos, grlAspect );\r\n vec2 grlNextP = grlFix( grlNextPos, grlAspect );\r\n\r\n float grlWidth = grlBaseWidth * grl_widths;\r\n\r\n vec2 grlDir;\r\n if( grlNextP == grlCurrentP ) grlDir = normalize( grlCurrentP - grlPrevP );\r\n else if( grlPrevP == grlCurrentP ) grlDir = normalize( grlNextP - grlCurrentP );\r\n else {\r\n vec2 grlDir1 = normalize( grlCurrentP - grlPrevP );\r\n vec2 grlDir2 = normalize( grlNextP - grlCurrentP );\r\n grlDir = normalize( grlDir1 + grlDir2 );\r\n }\r\n vec4 grlNormal = vec4( -grlDir.y, grlDir.x, 0., 1. );\r\n #ifdef GREASED_LNE_RIGHT_HANDED_COORDINATE_SYSTEM\r\n grlNormal.xy *= -.5 * grlWidth;\r\n #else\r\n grlNormal.xy *= .5 * grlWidth;\r\n #endif\r\n grlNormal *= grl_projection;\r\n #ifdef GREASED_LINE_SIZE_ATTENUATION\r\n grlNormal.xy *= grlFinalPosition.w;\r\n grlNormal.xy /= ( vec4( grl_aspect_resolution_lineWidth.yz, 0., 1. ) * grl_projection ).xy;\r\n #endif\r\n grlFinalPosition.xy += grlNormal.xy * grlSide;\r\n gl_Position = grlFinalPosition;\r\n\r\n vPositionW = vec3(grlFinalPosition);\r\n\r\n `,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"!gl_Position\\\\=viewProjection\\\\*worldPos;\": \"//\", // remove\r\n };\r\n }\r\n\r\n if (shaderType === \"fragment\") {\r\n return {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n varying float grlCounters;\r\n varying float grlColorPointer;\r\n uniform sampler2D grl_colors;\r\n `,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_MAIN_END: `\r\n float grlColorMode = grl_colorMode_visibility_colorsWidth_useColors.x;\r\n float grlVisibility = grl_colorMode_visibility_colorsWidth_useColors.y;\r\n float grlColorsWidth = grl_colorMode_visibility_colorsWidth_useColors.z;\r\n float grlUseColors = grl_colorMode_visibility_colorsWidth_useColors.w;\r\n\r\n float grlUseDash = grl_dashOptions.x;\r\n float grlDashArray = grl_dashOptions.y;\r\n float grlDashOffset = grl_dashOptions.z;\r\n float grlDashRatio = grl_dashOptions.w;\r\n\r\n gl_FragColor.a *= step(grlCounters, grlVisibility);\r\n if( gl_FragColor.a == 0. ) discard;\r\n\r\n if(grlUseDash == 1.){\r\n gl_FragColor.a *= ceil(mod(grlCounters + grlDashOffset, grlDashArray) - (grlDashArray * grlDashRatio));\r\n if (gl_FragColor.a == 0.) discard;\r\n }\r\n\r\n #ifdef GREASED_LINE_HAS_COLOR\r\n if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_SET}.) {\r\n gl_FragColor.rgb = grl_singleColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_ADD}.) {\r\n gl_FragColor.rgb += grl_singleColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_MULTIPLY}.) {\r\n gl_FragColor.rgb *= grl_singleColor;\r\n }\r\n #else\r\n if (grlUseColors == 1.) {\r\n #ifdef GREASED_LINE_COLOR_DISTRIBUTION_TYPE_LINE\r\n vec4 grlColor = texture2D(grl_colors, vec2(grlCounters, 0.), 0.);\r\n #else\r\n vec4 grlColor = texture2D(grl_colors, vec2(grlColorPointer/grlColorsWidth, 0.), 0.);\r\n #endif\r\n if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_SET}.) {\r\n gl_FragColor = grlColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_ADD}.) {\r\n gl_FragColor += grlColor;\r\n } else if (grlColorMode == ${GreasedLineMeshColorMode.COLOR_MODE_MULTIPLY}.) {\r\n gl_FragColor *= grlColor;\r\n }\r\n }\r\n #endif\r\n `,\r\n };\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Converts boolean to number.\r\n * @param bool\r\n * @returns 1 if true, 0 if false.\r\n */\r\n private static _BooleanToNumber(bool?: boolean) {\r\n return bool ? 1 : 0;\r\n }\r\n\r\n /**\r\n * Converts an array of Color3 to Uint8Array\r\n * @param colors Arrray of Color3\r\n * @returns Uin8Array of colors [r, g, b, a, r, g, b, a, ...]\r\n */\r\n private static _Color3toRGBAUint8(colors: Color3[]) {\r\n const colorTable: Uint8Array = new Uint8Array(colors.length * 4);\r\n for (let i = 0, j = 0; i < colors.length; i++) {\r\n colorTable[j++] = colors[i].r * 255;\r\n colorTable[j++] = colors[i].g * 255;\r\n colorTable[j++] = colors[i].b * 255;\r\n colorTable[j++] = 255;\r\n }\r\n\r\n return colorTable;\r\n }\r\n\r\n /**\r\n * Creates a RawTexture from an RGBA color array and sets it on the plugin material instance.\r\n * @param name name of the texture\r\n * @param colors Uint8Array of colors\r\n */\r\n private _createColorsTexture(name: string, colors: Color3[]) {\r\n const colorsArray = GreasedLinePluginMaterial._Color3toRGBAUint8(colors);\r\n this._colorsTexture = new RawTexture(colorsArray, colors.length, 1, Engine.TEXTUREFORMAT_RGBA, this._scene, false, true, this.colorsSampling);\r\n this._colorsTexture.name = name;\r\n }\r\n\r\n /**\r\n * Disposes the plugin material.\r\n */\r\n public dispose(): void {\r\n this._colorsTexture?.dispose();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Returns the colors used to colorize the line\r\n */\r\n get colors() {\r\n return this._colors;\r\n }\r\n\r\n /**\r\n * Sets the colors used to colorize the line\r\n */\r\n set colors(value: Nullable) {\r\n this.setColors(value);\r\n }\r\n\r\n /**\r\n * Creates or updates the colors texture\r\n * @param colors color table RGBA\r\n * @param lazy if lazy, the colors are not updated\r\n * @param forceUpdate force creation of a new texture\r\n * @returns\r\n */\r\n public setColors(colors: Nullable, lazy = false, forceUpdate = false): void {\r\n const origColorsCount = this._colors?.length ?? 0;\r\n\r\n this._colors = colors;\r\n\r\n if (colors === null || colors.length === 0) {\r\n this._colorsTexture?.dispose();\r\n return;\r\n }\r\n\r\n if (lazy && !forceUpdate) {\r\n return;\r\n }\r\n\r\n if (this._colorsTexture && origColorsCount === colors.length && !forceUpdate) {\r\n const colorArray = GreasedLinePluginMaterial._Color3toRGBAUint8(colors);\r\n this._colorsTexture.update(colorArray);\r\n } else {\r\n this._colorsTexture?.dispose();\r\n this._createColorsTexture(`${this._material.name}-colors-texture`, colors);\r\n }\r\n }\r\n\r\n /**\r\n * Updates the material. Use when material created in lazy mode.\r\n */\r\n public updateLazy() {\r\n if (this._colors) {\r\n this.setColors(this._colors, false, true);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the number of dashes in the line\r\n */\r\n get dashCount() {\r\n return this._dashCount;\r\n }\r\n /**\r\n * Sets the number of dashes in the line\r\n * @param value dash\r\n */\r\n set dashCount(value: number) {\r\n this._dashCount = value;\r\n this._dashArray = 1 / value;\r\n }\r\n\r\n /**\r\n * False means 1 unit in width = 1 unit on scene, true means 1 unit in width is reduced on the screen to make better looking lines\r\n */\r\n get sizeAttenuation() {\r\n return this._sizeAttenuation;\r\n }\r\n\r\n /**\r\n * Turn on/off attenuation of the width option and widths array.\r\n * @param value false means 1 unit in width = 1 unit on scene, true means 1 unit in width is reduced on the screen to make better looking lines\r\n */\r\n set sizeAttenuation(value: boolean) {\r\n this._sizeAttenuation = value;\r\n this.markAllDefinesAsDirty();\r\n }\r\n\r\n /**\r\n * Gets the color of the line\r\n */\r\n get color() {\r\n return this.color;\r\n }\r\n\r\n /**\r\n * Sets the color of the line\r\n * @param value Color3 or null to clear the color. You need to clear the color if you use colors and useColors = true\r\n */\r\n set color(value: Nullable) {\r\n this.setColor(value);\r\n }\r\n\r\n /**\r\n * Sets the color of the line. If set the whole line will be mixed with this color according to the colorMode option.\r\n * @param value color\r\n */\r\n public setColor(value: Nullable, doNotMarkDirty = false) {\r\n if ((this._color === null && value !== null) || (this._color !== null && value === null)) {\r\n this._color = value;\r\n !doNotMarkDirty && this.markAllDefinesAsDirty();\r\n } else {\r\n this._color = value;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the color distributiopn type\r\n */\r\n get colorsDistributionType() {\r\n return this._colorsDistributionType;\r\n }\r\n\r\n /**\r\n * Sets the color distribution type\r\n * @see GreasedLineMeshColorDistributionType\r\n * @param value color distribution type\r\n */\r\n set colorsDistributionType(value: GreasedLineMeshColorDistributionType) {\r\n this._colorsDistributionType = value;\r\n this.markAllDefinesAsDirty();\r\n }\r\n\r\n /**\r\n * Gets the resolution\r\n */\r\n get resolution() {\r\n return this._resolution;\r\n }\r\n\r\n /**\r\n * Sets the resolution\r\n * @param value resolution of the screen for GreasedLine\r\n */\r\n set resolution(value: Vector2) {\r\n this._aspect = value.x / value.y;\r\n this._resolution = value;\r\n }\r\n\r\n /**\r\n * Serializes this plugin material\r\n * @returns serializationObjec\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n const greasedLineMaterialOptions: GreasedLineMaterialOptions = {\r\n colorDistributionType: this._colorsDistributionType,\r\n colorsSampling: this.colorsSampling,\r\n colorMode: this.colorMode,\r\n dashCount: this._dashCount,\r\n dashOffset: this.dashOffset,\r\n dashRatio: this.dashRatio,\r\n resolution: this._resolution,\r\n sizeAttenuation: this._sizeAttenuation,\r\n useColors: this.useColors,\r\n useDash: this.useDash,\r\n visibility: this.visibility,\r\n width: this.width,\r\n };\r\n\r\n this._colors && (greasedLineMaterialOptions.colors = this._colors);\r\n this._color && (greasedLineMaterialOptions.color = this._color);\r\n\r\n serializationObject.greasedLineMaterialOptions = greasedLineMaterialOptions;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parses a serialized objects\r\n * @param source serialized object\r\n * @param scene scene\r\n * @param rootUrl root url for textures\r\n */\r\n public parse(source: any, scene: Scene, rootUrl: string): void {\r\n super.parse(source, scene, rootUrl);\r\n const greasedLineMaterialOptions = source.greasedLineMaterialOptions;\r\n\r\n this._colorsTexture?.dispose();\r\n\r\n if (greasedLineMaterialOptions.colors) {\r\n this._createColorsTexture(`${this._material.name}-colors-texture`, greasedLineMaterialOptions.colors);\r\n } else {\r\n GreasedLinePluginMaterial._PrepareEmptyColorsTexture(scene);\r\n }\r\n\r\n greasedLineMaterialOptions.color && this.setColor(greasedLineMaterialOptions.color, true);\r\n greasedLineMaterialOptions.colorDistributionType && (this.colorsDistributionType = greasedLineMaterialOptions.colorDistributionType);\r\n greasedLineMaterialOptions.colorsSampling && (this.colorsSampling = greasedLineMaterialOptions.colorsSampling);\r\n greasedLineMaterialOptions.colorMode && (this.colorMode = greasedLineMaterialOptions.colorMode);\r\n greasedLineMaterialOptions.useColors && (this.useColors = greasedLineMaterialOptions.useColors);\r\n greasedLineMaterialOptions.visibility && (this.visibility = greasedLineMaterialOptions.visibility);\r\n greasedLineMaterialOptions.useDash && (this.useDash = greasedLineMaterialOptions.useDash);\r\n greasedLineMaterialOptions.dashCount && (this.dashCount = greasedLineMaterialOptions.dashCount);\r\n greasedLineMaterialOptions.dashRatio && (this.dashRatio = greasedLineMaterialOptions.dashRatio);\r\n greasedLineMaterialOptions.dashOffset && (this.dashOffset = greasedLineMaterialOptions.dashOffset);\r\n greasedLineMaterialOptions.width && (this.width = greasedLineMaterialOptions.width);\r\n greasedLineMaterialOptions.sizeAttenuation && (this.sizeAttenuation = greasedLineMaterialOptions.sizeAttenuation);\r\n greasedLineMaterialOptions.resolution && (this.resolution = greasedLineMaterialOptions.resolution);\r\n\r\n this.markAllDefinesAsDirty();\r\n }\r\n\r\n /**\r\n * A minimum size texture for the colors sampler2D when there is no colors texture defined yet.\r\n * For fast switching using the useColors property without the need to use defines.\r\n * @param scene Scene\r\n */\r\n private static _PrepareEmptyColorsTexture(scene: Scene) {\r\n if (!this._EmptyColorsTexture) {\r\n const colorsArray = new Uint8Array(4);\r\n this._EmptyColorsTexture = new RawTexture(colorsArray, 1, 1, Engine.TEXTUREFORMAT_RGBA, scene, false, false, RawTexture.NEAREST_NEAREST);\r\n this._EmptyColorsTexture.name = \"grlEmptyColorsTexture\";\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(`BABYLON.${GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME}`, GreasedLinePluginMaterial);\r\n","import type { GreasedLineMaterialOptions } from \"../../Materials/greasedLinePluginMaterial\";\r\nimport { GreasedLineMeshMaterialType, GreasedLinePluginMaterial } from \"../../Materials/greasedLinePluginMaterial\";\r\nimport { StandardMaterial } from \"./../../Materials/standardMaterial\";\r\nimport { PBRMaterial } from \"../../Materials/PBR/pbrMaterial\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { GreasedLineMeshOptions } from \"../greasedLineMesh\";\r\nimport { GreasedLineMesh } from \"../greasedLineMesh\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport type { Color3 } from \"core/Maths/math.color\";\r\n\r\n/**\r\n * How are the colors distributed along the color table\r\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#colors-and-colordistribution}\r\n */\r\nexport enum GreasedLineMeshColorDistribution {\r\n /**\r\n * Do no modify the color table\r\n */\r\n COLOR_DISTRIBUTION_NONE = 0,\r\n /**\r\n * Repeat the colors until the color table is full\r\n */\r\n COLOR_DISTRIBUTION_REPEAT = 1,\r\n /**\r\n * Distribute the colors evenly through the color table\r\n */\r\n COLOR_DISTRIBUTION_EVEN = 2,\r\n /**\r\n * Put the colors to start of the color table a fill the rest with the default color\r\n */\r\n COLOR_DISTRIBUTION_START = 3,\r\n /**\r\n * Put the colors to the end of the color table and fill the rest with the default color\r\n */\r\n COLOR_DISTRIBUTION_END = 4,\r\n /**\r\n * Put the colors to start and to the end of the color table and fill the gap between with the default color\r\n */\r\n COLOR_DISTRIBUTION_START_END = 5,\r\n}\r\n\r\n/**\r\n * How are the widths distributed along the width table\r\n * {@link https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#widths-and-widthdistribution}\r\n */\r\nexport enum GreasedLineMeshWidthDistribution {\r\n /**\r\n * Do no modify the width table\r\n */\r\n WIDTH_DISTRIBUTION_NONE = 0,\r\n /**\r\n * Repeat the widths until the width table is full\r\n */\r\n WIDTH_DISTRIBUTION_REPEAT = 1,\r\n /**\r\n * Distribute the widths evenly through the width table\r\n */\r\n WIDTH_DISTRIBUTION_EVEN = 2,\r\n /**\r\n * Put the widths to start of the width table a fill the rest with the default width\r\n */\r\n WIDTH_DISTRIBUTION_START = 3,\r\n /**\r\n * Put the widths to the end of the width table and fill the rest with the default width\r\n */\r\n WIDTH_DISTRIBUTION_END = 4,\r\n /**\r\n * Put the widths to start and to the end of the width table and fill the gap between with the default width\r\n */\r\n WIDTH_DISTRIBUTION_START_END = 5,\r\n}\r\n\r\n/**\r\n * Material options for GreasedLineBuilder\r\n */\r\nexport interface GreasedLineMaterialBuilderOptions extends GreasedLineMaterialOptions {\r\n /**\r\n * If set to true a new material will be created and a new material plugin will be attached\r\n * to the material. The material will be set on the mesh. If the instance option is specified in the mesh options,\r\n * no material will be created/assigned. Defaults to true.\r\n */\r\n createAndAssignMaterial?: boolean;\r\n /**\r\n * Distribution of the colors if the color table contains fewer entries than needed. Defaults to GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_START\r\n * @see CompleteGreasedLineColorTable\r\n */\r\n colorDistribution?: GreasedLineMeshColorDistribution;\r\n}\r\n\r\n/**\r\n * Line mesh options for GreasedLineBuilder\r\n */\r\nexport interface GreasedLineMeshBuilderOptions extends GreasedLineMeshOptions {\r\n /**\r\n * Distribution of the widths if the width table contains fewer entries than needed. Defaults to GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_START\r\n * @see CompleteGreasedLineWidthTable\r\n */\r\n widthDistribution?: GreasedLineMeshWidthDistribution;\r\n}\r\n\r\n/**\r\n * Builder class for create GreasedLineMeshes\r\n */\r\n\r\n/**\r\n * Creates a new @see GreasedLinePluginMaterial\r\n * @param name name of the material\r\n * @param options material options @see GreasedLineMaterialOptions\r\n * @param scene scene or null to use the last scene\r\n * @returns StandardMaterial or PBRMaterial with the @see GreasedLinePluginMaterial attached to it\r\n */\r\nexport function CreateGreasedLineMaterial(name: string, options: GreasedLineMaterialOptions, scene: Nullable) {\r\n scene = (scene ?? EngineStore.LastCreatedScene);\r\n\r\n const material = options.materialType === GreasedLineMeshMaterialType.MATERIAL_TYPE_PBR ? new PBRMaterial(name, scene) : new StandardMaterial(name, scene);\r\n new GreasedLinePluginMaterial(material, scene, options);\r\n\r\n return material;\r\n}\r\n/**\r\n * Creates a GreasedLine mesh\r\n * @param name name of the mesh\r\n * @param options options for the mesh\r\n * @param materialOptions material options for the mesh\r\n * @param scene scene where the mesh will be created\r\n * @returns instance of GreasedLineMesh\r\n */\r\nexport function CreateGreasedLine(name: string, options: GreasedLineMeshBuilderOptions, materialOptions?: Nullable, scene?: Nullable) {\r\n scene = (scene ?? EngineStore.LastCreatedScene);\r\n\r\n let instance;\r\n const allPoints = GreasedLineMesh.ConvertPoints(options.points);\r\n\r\n let length = 0;\r\n if (Array.isArray(allPoints[0])) {\r\n allPoints.forEach((points) => {\r\n length += points.length / 3;\r\n });\r\n }\r\n\r\n options.widthDistribution = options.widthDistribution ?? GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_START;\r\n\r\n materialOptions = materialOptions ?? {\r\n color: GreasedLinePluginMaterial.DEFAULT_COLOR,\r\n };\r\n materialOptions.createAndAssignMaterial = materialOptions.createAndAssignMaterial ?? true;\r\n materialOptions.colorDistribution = materialOptions?.colorDistribution ?? GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_START;\r\n\r\n const widths = CompleteGreasedLineWidthTable(length, options.widths ?? [], options.widthDistribution);\r\n\r\n const colors = materialOptions?.colors\r\n ? CompleteGreasedLineColorTable(length, materialOptions.colors, materialOptions.colorDistribution, materialOptions.color ?? GreasedLinePluginMaterial.DEFAULT_COLOR)\r\n : undefined;\r\n\r\n // create new mesh if instance is not defined\r\n if (!options.instance) {\r\n const initialGreasedLineOptions: GreasedLineMeshOptions = {\r\n points: allPoints,\r\n updatable: options.updatable,\r\n widths,\r\n lazy: options.lazy,\r\n };\r\n\r\n instance = new GreasedLineMesh(name, scene, initialGreasedLineOptions);\r\n\r\n if (materialOptions) {\r\n const initialMaterialOptions: GreasedLineMaterialOptions = {\r\n materialType: materialOptions.materialType,\r\n dashCount: materialOptions.dashCount,\r\n dashOffset: materialOptions.dashOffset,\r\n dashRatio: materialOptions.dashRatio,\r\n resolution: materialOptions.resolution,\r\n sizeAttenuation: materialOptions.sizeAttenuation,\r\n useColors: materialOptions.useColors,\r\n useDash: materialOptions.useDash,\r\n visibility: materialOptions.visibility,\r\n width: materialOptions.width,\r\n color: materialOptions.color,\r\n colorMode: materialOptions.colorMode,\r\n colorsSampling: materialOptions.colorsSampling,\r\n colorDistributionType: materialOptions.colorDistributionType,\r\n colors,\r\n };\r\n\r\n if (materialOptions.createAndAssignMaterial) {\r\n const material = materialOptions.materialType === GreasedLineMeshMaterialType.MATERIAL_TYPE_PBR ? new PBRMaterial(name, scene) : new StandardMaterial(name, scene);\r\n new GreasedLinePluginMaterial(material, scene, initialMaterialOptions);\r\n instance.material = material;\r\n }\r\n }\r\n } else {\r\n // update the data on the mesh instance\r\n instance = options.instance;\r\n const currentWidths = instance.widths;\r\n\r\n if (currentWidths) {\r\n const newWidths = currentWidths.slice();\r\n for (const w of widths) {\r\n newWidths.push(w);\r\n }\r\n instance.widths = newWidths;\r\n } else {\r\n instance.widths = widths;\r\n }\r\n instance.addPoints(allPoints);\r\n }\r\n\r\n // add colors\r\n // it will merge if any colors already on the instance\r\n if (colors && options.instance) {\r\n if (options.instance.material instanceof StandardMaterial || instance.material instanceof PBRMaterial) {\r\n if (options.instance.greasedLineMaterial) {\r\n const currentColors = options.instance.greasedLineMaterial.colors;\r\n if (currentColors) {\r\n const newColors = currentColors.concat(colors);\r\n options.instance.greasedLineMaterial.setColors(newColors, instance.isLazy());\r\n }\r\n }\r\n }\r\n }\r\n\r\n return instance;\r\n}\r\n\r\n/**\r\n * Completes the width table/fills the missing entries. It means it creates a width entry for every point of the line mesh.\r\n * You can provide more points the widths when creating the mesh. This function will fill the empty entries.\r\n * The algorithm used to fill the empty entries can be\r\n * GreasedLineMeshWidthDistribution.REPEAT - the width table will be repeatedly copied to the empty values [wL, wU] = [wL, wU, wL, wU, wL, wU, wL, wU, ...]\r\n * GreasedLineMeshWidthDistribution.EVEN - the width table will be evenly copied to the empty values [wL, wU] = [wL, wL, wL, wL, wU, wU, wU, wU]\r\n * GreasedLineMeshWidthDistribution.START - the width table will be copied at the start of the empty values\r\n * and rest will be filled width the default width upper and default width lower values [wU, wL] = [wL, wU, dwL, dwU, dwL, dwU, dwL, dwU]\r\n * GreasedLineMeshWidthDistribution.END - the width table will be copied at the end of the empty values\r\n * and rest will be filled width the default values [wL, wU] = [wL, wU, dwL, dwU, dwL, dwU, wL, wU]\r\n * @param pointCount number of points of the line mesh\r\n * @param widths array of widths [widhtLower, widthUpper, widthLower, widthUpper ...]. Two widths (lower/upper) per point.\r\n * @param widthsDistribution how to distribute widths if the widths array has fewer entries than pointCount\r\n * @param defaultWidthUpper the default value which will be used to fill empty width entries - upper width\r\n * @param defaultWidthLower the default value which will be used to fill empty width entries - lower width\r\n * @returns completed width table.\r\n */\r\nexport function CompleteGreasedLineWidthTable(\r\n pointCount: number,\r\n widths: number[],\r\n widthsDistribution: GreasedLineMeshWidthDistribution,\r\n defaultWidthUpper = 1,\r\n defaultWidthLower = 1\r\n): number[] {\r\n const missingCount = pointCount - widths.length / 2;\r\n\r\n const widthsData: number[] = [];\r\n if (missingCount < 0) {\r\n return widths.slice(0, pointCount * 2);\r\n }\r\n\r\n // is the width table shorter than the point table?\r\n if (missingCount > 0) {\r\n // it is, fill in the missing elements\r\n if (widthsDistribution === GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_START_END) {\r\n const halfCount = Math.floor(widths.length / 2);\r\n\r\n // start sector\r\n for (let i = 0, j = 0; i < halfCount - 1; i++) {\r\n widthsData.push(widths[j++]);\r\n widthsData.push(widths[j++]);\r\n }\r\n\r\n // middle sector\r\n const widthL = widths[halfCount / 2];\r\n const widthU = widths[halfCount / 2 + 1];\r\n for (let i = 0; i < missingCount; i++) {\r\n widthsData.push(widthU);\r\n widthsData.push(widthL);\r\n }\r\n\r\n // end sector\r\n for (let i = halfCount; i < widths.length; i += 2) {\r\n widthsData.push(widths[i]);\r\n widthsData.push(widths[i + 1]);\r\n }\r\n } else if (widthsDistribution === GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_START) {\r\n // start sector\r\n for (let i = 0; i < widths.length; i += 2) {\r\n widthsData.push(widths[i]);\r\n widthsData.push(widths[i + 1]);\r\n }\r\n\r\n // end sector\r\n for (let i = 0; i < missingCount; i++) {\r\n widthsData.push(defaultWidthUpper);\r\n widthsData.push(defaultWidthLower);\r\n }\r\n } else if (widthsDistribution === GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_END) {\r\n // start sector\r\n for (let i = 0; i < missingCount; i++) {\r\n widthsData.push(defaultWidthUpper);\r\n widthsData.push(defaultWidthLower);\r\n }\r\n\r\n // end sector\r\n for (let i = 0; i < widths.length; i += 2) {\r\n widthsData.push(widths[i]);\r\n widthsData.push(widths[i + 1]);\r\n }\r\n } else if (widthsDistribution === GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_REPEAT) {\r\n let i = 0;\r\n for (let x = 0; x < pointCount; x++) {\r\n widthsData.push(widths[i++]);\r\n widthsData.push(widths[i++]);\r\n\r\n if (i === widths.length) {\r\n i = 0;\r\n }\r\n }\r\n } else if (widthsDistribution === GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_EVEN) {\r\n let j = 0;\r\n const widthsectorLength = widths.length / ((pointCount - 1) * 2);\r\n for (let x = 0; x < pointCount; x++) {\r\n const i = Math.floor(j);\r\n\r\n widthsData.push(widths[i]);\r\n widthsData.push(widths[i + 1]);\r\n\r\n j += widthsectorLength;\r\n }\r\n }\r\n } else {\r\n for (let i = 0; i < widths.length; i++) {\r\n widthsData.push(widths[i]);\r\n }\r\n }\r\n\r\n return widthsData;\r\n}\r\n\r\n/**\r\n * Completes the color table/fill the missing color entries. It means it creates a color entry for every point of the line mesh.\r\n * You can provide more points the colors when creating the mesh. This function will fill the empty entries.\r\n * The algorithm used to fill the empty entries can be\r\n * GreasedLineMesColorhDistribution.REPEAT - the color table will be repeatedly copied to the empty values [c1, c2] = [c1, c2, c1, c2, c1, c2, c1, c2]\r\n * GreasedLineMesColorhDistribution.EVEN - the color table will be evenly copied to the empty values [c1, c2] = [c1, c1, c1, c1, c2, c2, c2, c2]\r\n * GreasedLineMesColorhDistribution.START - the color table will be copied at the start of the empty values\r\n * and rest will be filled color the default color value [c1, c2] = [c1, c2, dc, dc, dc, dc, dc, dc]\r\n * GreasedLineMesColorhDistribution.START_END - the color table will be copied at the start and the end of the empty values\r\n * and rest will be filled color the default color value [c1, c2] = [c1, c2, dc, dc, dc, dc, c1, c2]\r\n * @param pointCount number of points of the line mesh\r\n * @param colors array of Color3 for the color table\r\n * @param colorDistribution how to distribute colors if the colors array has fewer entries than pointCount\r\n * @param defaultColor default color to be used to fill empty entries in the color table\r\n * @returns completed array of Color3s\r\n */\r\nexport function CompleteGreasedLineColorTable(pointCount: number, colors: Color3[], colorDistribution: GreasedLineMeshColorDistribution, defaultColor: Color3): Color3[] {\r\n const missingCount = pointCount - colors.length;\r\n if (missingCount < 0) {\r\n return colors.slice(0, pointCount);\r\n }\r\n\r\n const colorsData: Color3[] = [];\r\n // is the color table shorter than the point table?\r\n if (missingCount > 0) {\r\n // it is, fill in the missing elements\r\n if (colorDistribution === GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_START_END) {\r\n const halfCount = Math.floor(colors.length / 2);\r\n\r\n // start sector\r\n for (let i = 0; i < halfCount; i++) {\r\n colorsData.push(colors[i]);\r\n }\r\n\r\n // middle sector\r\n for (let i = 0; i < missingCount - 1; i++) {\r\n colorsData.push(defaultColor);\r\n }\r\n\r\n // end sector\r\n for (let i = halfCount; i < colors.length; i++) {\r\n colorsData.push(colors[i]);\r\n }\r\n } else if (colorDistribution === GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_START) {\r\n // start sector\r\n for (let i = 0; i < colors.length; i++) {\r\n colorsData.push(colors[i]);\r\n }\r\n\r\n // end sector\r\n for (let i = 0; i < missingCount; i++) {\r\n colorsData.push(defaultColor);\r\n }\r\n } else if (colorDistribution === GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_END) {\r\n // start sector\r\n for (let i = 0; i < missingCount - 1; i++) {\r\n colorsData.push(defaultColor);\r\n }\r\n\r\n // end sector\r\n for (let i = 0; i < colors.length; i++) {\r\n colorsData.push(colors[i]);\r\n }\r\n } else if (colorDistribution === GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_REPEAT) {\r\n let i = 0;\r\n for (let x = 0; x < pointCount; x++) {\r\n colorsData.push(colors[i]);\r\n\r\n i++;\r\n\r\n if (i === colors.length) {\r\n i = 0;\r\n }\r\n }\r\n } else if (colorDistribution === GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_EVEN) {\r\n let j = 0;\r\n const colorSectorLength = colors.length / (pointCount - 1);\r\n for (let x = 0; x < pointCount - 1; x++) {\r\n const i = Math.floor(j);\r\n\r\n colorsData.push(colors[i]);\r\n\r\n j += colorSectorLength;\r\n }\r\n } else if (colorDistribution === GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_NONE) {\r\n for (let i = 0; i < colors.length; i++) {\r\n colorsData.push(colors[i]);\r\n }\r\n }\r\n } else {\r\n for (let i = 0; i < pointCount; i++) {\r\n colorsData.push(colors[i]);\r\n }\r\n }\r\n\r\n return colorsData;\r\n}\r\n``;\r\n","import { Mesh } from \"../mesh\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { CreateSphere } from \"../Builders/sphereBuilder\";\r\nimport { CreateDisc } from \"./discBuilder\";\r\n\r\n/**\r\n * Creates a hemisphere mesh\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.segments\r\n * @param options.diameter\r\n * @param options.sideOrientation\r\n * @param scene defines the hosting scene\r\n * @returns the hemisphere mesh\r\n */\r\nexport function CreateHemisphere(name: string, options: { segments?: number; diameter?: number; sideOrientation?: number } = {}, scene?: Scene): Mesh {\r\n if (!options.diameter) {\r\n options.diameter = 1;\r\n }\r\n if (!options.segments) {\r\n options.segments = 16;\r\n }\r\n\r\n const halfSphere = CreateSphere(\"\", { slice: 0.5, diameter: options.diameter, segments: options.segments }, scene);\r\n const disc = CreateDisc(\"\", { radius: options.diameter / 2, tessellation: options.segments * 3 + (4 - options.segments) }, scene);\r\n disc.rotation.x = -Math.PI / 2;\r\n disc.parent = halfSphere;\r\n\r\n const merged = Mesh.MergeMeshes([disc, halfSphere], true);\r\n merged.name = name;\r\n\r\n return merged;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const HemisphereBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateHemisphere,\r\n};\r\n\r\n/**\r\n * Creates a hemispheric light\r\n * @param name\r\n * @param segments\r\n * @param diameter\r\n * @param scene\r\n */\r\nMesh.CreateHemisphere = (name: string, segments: number, diameter: number, scene?: Scene): Mesh => {\r\n const options = {\r\n segments: segments,\r\n diameter: diameter,\r\n };\r\n\r\n return CreateHemisphere(name, options, scene);\r\n};\r\n","import { Curve3 } from \"../Maths/math.path\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { TmpVectors, Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { IFontData } from \"../Meshes/Builders/textBuilder\";\r\nimport { CreateTextShapePaths } from \"../Meshes/Builders/textBuilder\";\r\nimport type { FloatArray, IndicesArray } from \"../types\";\r\n\r\n/**\r\n * Tool functions for GreasedLine\r\n */\r\nexport class GreasedLineTools {\r\n /**\r\n * Omit zero length lines predicate for the MeshesToLines function\r\n * @param p1 point1 position of the face\r\n * @param p2 point2 position of the face\r\n * @param p3 point3 position of the face\r\n * @returns\r\n */\r\n public static OmitZeroLengthPredicate(p1: Vector3, p2: Vector3, p3: Vector3) {\r\n return p1.lengthSquared() === 0 && p2.lengthSquared() === 0 && p3.lengthSquared() === 0;\r\n }\r\n /**\r\n * Gets mesh triangles as line positions\r\n * @param meshes array of meshes\r\n * @param omitZeroLengthLines do not generate a line when the distance if the vertices in the triangle equals to zero\r\n * @returns array of arrays of points\r\n */\r\n public static MeshesToLines(\r\n meshes: AbstractMesh[],\r\n predicate?: (\r\n p1: Vector3,\r\n p2: Vector3,\r\n p3: Vector3,\r\n indiceIndex: number,\r\n vertexIndex: number,\r\n mesh: AbstractMesh,\r\n meshIndex: number,\r\n vertices: FloatArray,\r\n indices: IndicesArray\r\n ) => Vector3[]\r\n ) {\r\n const points: Vector3[][] = [];\r\n\r\n meshes.forEach((m, meshIndex) => {\r\n const vertices = m.getVerticesData(VertexBuffer.PositionKind);\r\n const indices = m.getIndices();\r\n if (vertices && indices) {\r\n for (let i = 0, ii = 0; i < indices.length; i++) {\r\n const vi1 = indices[ii++] * 3;\r\n const vi2 = indices[ii++] * 3;\r\n const vi3 = indices[ii++] * 3;\r\n\r\n const p1 = new Vector3(vertices[vi1], vertices[vi1 + 1], vertices[vi1 + 2]);\r\n const p2 = new Vector3(vertices[vi2], vertices[vi2 + 1], vertices[vi2 + 2]);\r\n const p3 = new Vector3(vertices[vi3], vertices[vi3 + 1], vertices[vi3 + 2]);\r\n\r\n if (predicate) {\r\n const pointsFromPredicate = predicate(p1, p2, p3, i, vi1, m, meshIndex, vertices, indices);\r\n pointsFromPredicate && points.push(pointsFromPredicate);\r\n } else {\r\n points.push([p1, p2, p3, p1]);\r\n }\r\n }\r\n }\r\n });\r\n\r\n return points;\r\n }\r\n\r\n /**\r\n * Converts number coordinates to Vector3s\r\n * @param points number array of x, y, z, x, y z, ... coordinates\r\n * @returns Vector3 array\r\n */\r\n public static ToVector3Array(points: number[]) {\r\n const array: Vector3[] = [];\r\n for (let i = 0; i < points.length; i += 3) {\r\n array.push(new Vector3(points[i], points[i + 1], points[i + 2]));\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Gets a number array from a Vector3 array.\r\n * You can you for example to convert your Vector3[] offsets to the required number[] for the offsets option.\r\n * @param points Vector3 array\r\n * @returns an array of x, y, z coordinates as numbers [x, y, z, x, y, z, x, y, z, ....]\r\n */\r\n public static ToNumberArray(points: Vector3[]) {\r\n return points.flatMap((v) => [v.x, v.y, v.z]);\r\n }\r\n\r\n /**\r\n * Calculates the sum of points of every line and the number of points in each line.\r\n * This function is useful when you are drawing multiple lines in one mesh and you want\r\n * to know the counts. For example for creating an offsets table.\r\n * @param points point array\r\n * @returns points count info\r\n */\r\n public static GetPointsCountInfo(points: number[][]): { total: number; counts: number[] } {\r\n const counts = new Array(points.length);\r\n let total = 0;\r\n for (let n = points.length; n--; ) {\r\n counts[n] = points[n].length / 3;\r\n total += counts[n];\r\n }\r\n return { total, counts };\r\n }\r\n\r\n /**\r\n * Gets the length of the line counting all it's segments length\r\n * @param data array of line points\r\n * @returns length of the line\r\n */\r\n public static GetLineLength(data: Vector3[] | number[]): number {\r\n if (data.length === 0) {\r\n return 0;\r\n }\r\n\r\n let points: Vector3[];\r\n if (typeof data[0] === \"number\") {\r\n points = GreasedLineTools.ToVector3Array(data);\r\n } else {\r\n points = data;\r\n }\r\n\r\n const tmp = TmpVectors.Vector3[0];\r\n let length = 0;\r\n for (let index = 0; index < points.length - 1; index++) {\r\n const point1 = points[index];\r\n const point2 = points[index + 1];\r\n length += point2.subtractToRef(point1, tmp).length();\r\n }\r\n return length;\r\n }\r\n\r\n /**\r\n * Divides a segment into smaller segments.\r\n * A segment is a part of the line between it's two points.\r\n * @param point1 first point of the line\r\n * @param point2 second point of the line\r\n * @param segmentCount number of segments we want to have in the divided line\r\n * @returns\r\n */\r\n public static SegmentizeSegmentByCount(point1: Vector3, point2: Vector3, segmentCount: number): Vector3[] {\r\n const dividedLinePoints: Vector3[] = [];\r\n const diff = point2.subtract(point1);\r\n const divisor = TmpVectors.Vector3[0];\r\n divisor.setAll(segmentCount);\r\n const segmentVector = TmpVectors.Vector3[1];\r\n diff.divideToRef(divisor, segmentVector);\r\n\r\n let nextPoint = point1.clone();\r\n dividedLinePoints.push(nextPoint);\r\n for (let index = 0; index < segmentCount; index++) {\r\n nextPoint = nextPoint.clone();\r\n dividedLinePoints.push(nextPoint.addInPlace(segmentVector));\r\n }\r\n\r\n return dividedLinePoints;\r\n }\r\n\r\n /**\r\n * Divides a line into segments.\r\n * A segment is a part of the line between it's two points.\r\n * @param what line points\r\n * @param segmentLength length of each segment of the resulting line (distance between two line points)\r\n * @returns line point\r\n */\r\n public static SegmentizeLineBySegmentLength(what: Vector3[] | number[] | { point1: Vector3; point2: Vector3; length: number }[], segmentLength: number): Vector3[] {\r\n const subLines = what[0] instanceof Vector3 ? GreasedLineTools.GetLineSegments(what as Vector3[]) : (what as { point1: Vector3; point2: Vector3; length: number }[]);\r\n const points: Vector3[] = [];\r\n subLines.forEach((s) => {\r\n if (s.length > segmentLength) {\r\n const segments = GreasedLineTools.SegmentizeSegmentByCount(s.point1, s.point2, Math.ceil(s.length / segmentLength));\r\n segments.forEach((seg) => {\r\n points.push(seg);\r\n });\r\n } else {\r\n points.push(s.point1);\r\n points.push(s.point2);\r\n }\r\n });\r\n return points;\r\n }\r\n\r\n /**\r\n * Divides a line into segments.\r\n * A segment is a part of the line between it's two points.\r\n * @param what line points\r\n * @param segmentCount number of segments\r\n * @returns line point\r\n */\r\n public static SegmentizeLineBySegmentCount(what: Vector3[], segmentCount: number): Vector3[] {\r\n const segmentLength = GreasedLineTools.GetLineLength(what) / segmentCount;\r\n return GreasedLineTools.SegmentizeLineBySegmentLength(what, segmentLength);\r\n }\r\n /**\r\n * Gets line segments.\r\n * A segment is a part of the line between it's two points.\r\n * @param points line points\r\n * @returns segments information of the line segment including starting point, ending point and the distance between them\r\n */\r\n public static GetLineSegments(points: Vector3[]): { point1: Vector3; point2: Vector3; length: number }[] {\r\n const segments = [];\r\n for (let index = 0; index < points.length - 1; index++) {\r\n const point1 = points[index];\r\n const point2 = points[index + 1];\r\n const length = point2.subtract(point1).length();\r\n segments.push({ point1, point2, length });\r\n }\r\n\r\n return segments;\r\n }\r\n\r\n /**\r\n * Gets the minimum and the maximum length of a line segment in the line.\r\n * A segment is a part of the line between it's two points.\r\n * @param points line points\r\n * @returns\r\n */\r\n public static GetMinMaxSegmentLength(points: Vector3[]): { min: number; max: number } {\r\n const subLines = GreasedLineTools.GetLineSegments(points);\r\n const sorted = subLines.sort((s) => s.length);\r\n return {\r\n min: sorted[0].length,\r\n max: sorted[sorted.length - 1].length,\r\n };\r\n }\r\n\r\n /**\r\n * Finds the last visible position in world space of the line according to the visibility parameter\r\n * @param lineSegments segments of the line\r\n * @param lineLength total length of the line\r\n * @param visbility normalized value of visibility\r\n * @returns world space coordinate of the last visible piece of the line\r\n */\r\n public static GetPositionOnLineByVisibility(lineSegments: { point1: Vector3; point2: Vector3; length: number }[], lineLength: number, visbility: number, localSpace = false) {\r\n const lengthVisibilityRatio = lineLength * visbility;\r\n let sumSegmentLengths = 0;\r\n let segmentIndex = 0;\r\n\r\n const lineSegmentsLength = lineSegments.length;\r\n for (let i = 0; i < lineSegmentsLength; i++) {\r\n if (lengthVisibilityRatio <= sumSegmentLengths + lineSegments[i].length) {\r\n segmentIndex = i;\r\n break;\r\n }\r\n sumSegmentLengths += lineSegments[i].length;\r\n }\r\n\r\n const s = (lengthVisibilityRatio - sumSegmentLengths) / lineSegments[segmentIndex].length;\r\n\r\n lineSegments[segmentIndex].point2.subtractToRef(lineSegments[segmentIndex].point1, TmpVectors.Vector3[0]);\r\n TmpVectors.Vector3[1] = TmpVectors.Vector3[0].multiplyByFloats(s, s, s);\r\n if (!localSpace) {\r\n TmpVectors.Vector3[1].addInPlace(lineSegments[segmentIndex].point1);\r\n }\r\n\r\n return TmpVectors.Vector3[1].clone();\r\n }\r\n\r\n /**\r\n * Creates lines in a shape of circle/arc.\r\n * A segment is a part of the line between it's two points.\r\n * @param radiusX radiusX of the circle\r\n * @param segments number of segments in the circle\r\n * @param z z coordinate of the points. Defaults to 0.\r\n * @param radiusY radiusY of the circle - you can draw an oval if using different values\r\n * @param segmentAngle angle offset of the segments. Defaults to Math.PI * 2 / segments. Change this value to draw a part of the circle.\r\n * @returns line points\r\n */\r\n public static GetCircleLinePoints(radiusX: number, segments: number, z = 0, radiusY = radiusX, segmentAngle = (Math.PI * 2) / segments) {\r\n const points: Vector3[] = [];\r\n for (let i = 0; i <= segments; i++) {\r\n points.push(new Vector3(Math.cos(i * segmentAngle) * radiusX, Math.sin(i * segmentAngle) * radiusY, z));\r\n }\r\n return points;\r\n }\r\n\r\n /**\r\n * Gets line points in a shape of a bezier curve\r\n * @param p0 bezier point0\r\n * @param p1 bezier point1\r\n * @param p2 bezier point2\r\n * @param segments number of segments in the curve\r\n * @returns\r\n */\r\n public static GetBezierLinePoints(p0: Vector3, p1: Vector3, p2: Vector3, segments: number) {\r\n return Curve3.CreateQuadraticBezier(p0, p1, p2, segments)\r\n .getPoints()\r\n .flatMap((v) => [v.x, v.y, v.z]);\r\n }\r\n\r\n /**\r\n *\r\n * @param position position of the arrow cap (mainly you want to create a triangle, set widthUp and widthDown to the same value and omit widthStartUp and widthStartDown)\r\n * @param direction direction which the arrow points to\r\n * @param length length (size) of the arrow cap itself\r\n * @param widthUp the arrow width above the line\r\n * @param widthDown the arrow width belove the line\r\n * @param widthStartUp the arrow width at the start of the arrow above the line. In most scenarios this is 0.\r\n * @param widthStartDown the arrow width at the start of the arrow below the line. In most scenarios this is 0.\r\n * @returns\r\n */\r\n public static GetArrowCap(position: Vector3, direction: Vector3, length: number, widthUp: number, widthDown: number, widthStartUp = 0, widthStartDown = 0) {\r\n const points = [position.clone(), position.add(direction.multiplyByFloats(length, length, length))];\r\n const widths = [widthUp, widthDown, widthStartUp, widthStartDown];\r\n\r\n return {\r\n points,\r\n widths,\r\n };\r\n }\r\n\r\n /**\r\n * Gets 3D positions of points from a text and font\r\n * @param text Text\r\n * @param size Size of the font\r\n * @param resolution Resolution of the font\r\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\r\n * @param z z coordinate\r\n * @param includeInner include the inner parts of the font in the result. Default true. If false, only the outlines will be returned.\r\n * @returns number[][] of 3D positions\r\n */\r\n public static GetPointsFromText(text: string, size: number, resolution: number, fontData: IFontData, z = 0, includeInner = true) {\r\n const allPoints = [];\r\n const shapePaths = CreateTextShapePaths(text, size, resolution, fontData);\r\n\r\n for (const sp of shapePaths) {\r\n for (const p of sp.paths) {\r\n const points = [];\r\n const points2d = p.getPoints();\r\n for (const p2d of points2d) {\r\n points.push(p2d.x, p2d.y, z);\r\n }\r\n allPoints.push(points);\r\n }\r\n\r\n if (includeInner) {\r\n for (const h of sp.holes) {\r\n const holes = [];\r\n const points2d = h.getPoints();\r\n for (const p2d of points2d) {\r\n holes.push(p2d.x, p2d.y, z);\r\n }\r\n allPoints.push(holes);\r\n }\r\n }\r\n }\r\n\r\n return allPoints;\r\n }\r\n}\r\n","import type { Scene } from \"../scene\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { GreasedLinePluginMaterial } from \"../Materials/greasedLinePluginMaterial\";\r\nimport { Mesh } from \"./mesh\";\r\nimport type { Ray, TrianglePickingPredicate } from \"../Culling/ray\";\r\nimport { Buffer, VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"./mesh.vertexData\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Node } from \"../node\";\r\nimport { DeepCopier } from \"../Misc/deepCopier\";\r\nimport { GreasedLineTools } from \"../Misc/greasedLineTools\";\r\n\r\nexport type GreasedLinePoints = Vector3[] | Vector3[][] | Float32Array | Float32Array[] | number[][] | number[];\r\n\r\n/**\r\n * Options for creating a GreasedLineMesh\r\n */\r\nexport interface GreasedLineMeshOptions {\r\n /**\r\n * Points of the line.\r\n */\r\n points: GreasedLinePoints;\r\n /**\r\n * Each line segmment (from point to point) can have it's width multiplier. Final width = widths[segmentIdx] * width.\r\n * Defaults to empty array.\r\n */\r\n widths?: number[];\r\n /**\r\n * If instance is specified, lines are added to the specified instance.\r\n * Defaults to undefined.\r\n */\r\n instance?: GreasedLineMesh;\r\n /**\r\n * You can manually set the color pointers so you can control which segment/part\r\n * will use which color from the colors material option\r\n */\r\n colorPointers?: number[];\r\n /**\r\n * UVs for the mesh\r\n */\r\n uvs?: number[];\r\n /**\r\n * If true, offsets and widths are updatable.\r\n * Defaults to false.\r\n */\r\n updatable?: boolean;\r\n /**\r\n * Use when @see instance is specified.\r\n * If true, the line will be rendered only after calling instance.updateLazy(). If false, line will be rerendered after every call to @see CreateGreasedLine\r\n * Defaults to false.\r\n */\r\n lazy?: boolean;\r\n}\r\n\r\nMesh._GreasedLineMeshParser = (parsedMesh: any, scene: Scene): Mesh => {\r\n return GreasedLineMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * GreasedLine\r\n */\r\nexport class GreasedLineMesh extends Mesh {\r\n private _vertexPositions: number[];\r\n private _previousAndSide: number[];\r\n private _nextAndCounters: number[];\r\n\r\n private _indices: number[];\r\n private _uvs: number[];\r\n private _points: number[][];\r\n private _offsets: number[];\r\n private _colorPointers: number[];\r\n private _widths: number[];\r\n\r\n private _offsetsBuffer?: Buffer;\r\n private _widthsBuffer?: Buffer;\r\n private _colorPointersBuffer?: Buffer;\r\n\r\n private _lazy = false;\r\n private _updatable = false;\r\n\r\n private static _V_START = new Vector3();\r\n private static _V_END = new Vector3();\r\n private static _V_OFFSET_START = new Vector3();\r\n private static _V_OFFSET_END = new Vector3();\r\n\r\n /**\r\n * Treshold used to pick the mesh\r\n */\r\n public intersectionThreshold = 0.1;\r\n\r\n constructor(public readonly name: string, scene: Scene, private _options: GreasedLineMeshOptions) {\r\n super(name, scene, null, null, false, false);\r\n\r\n this._lazy = _options.lazy ?? false;\r\n this._updatable = _options.updatable ?? false;\r\n\r\n this._vertexPositions = [];\r\n this._indices = [];\r\n this._uvs = [];\r\n this._points = [];\r\n this._colorPointers = _options.colorPointers ?? [];\r\n this._widths = _options.widths ?? new Array(_options.points.length).fill(1);\r\n\r\n this._previousAndSide = [];\r\n this._nextAndCounters = [];\r\n\r\n if (_options.points) {\r\n this.addPoints(GreasedLineMesh.ConvertPoints(_options.points));\r\n }\r\n }\r\n\r\n /**\r\n * \"GreasedLineMesh\"\r\n * @returns \"GreasedLineMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"GreasedLineMesh\";\r\n }\r\n\r\n /**\r\n * Converts GreasedLinePoints to number[][]\r\n * @param points GreasedLinePoints\r\n * @returns number[][] with x, y, z coordinates of the points, like [[x, y, z, x, y, z, ...], [x, y, z, ...]]\r\n */\r\n public static ConvertPoints(points: GreasedLinePoints): number[][] {\r\n if (points.length && Array.isArray(points) && typeof points[0] === \"number\") {\r\n return [points];\r\n } else if (points.length && Array.isArray(points[0]) && typeof points[0][0] === \"number\") {\r\n return points;\r\n } else if (points.length && !Array.isArray(points[0]) && points[0] instanceof Vector3) {\r\n const positions: number[] = [];\r\n for (let j = 0; j < points.length; j++) {\r\n const p = points[j] as Vector3;\r\n positions.push(p.x, p.y, p.z);\r\n }\r\n return [positions];\r\n } else if (points.length > 0 && Array.isArray(points[0]) && points[0].length > 0 && points[0][0] instanceof Vector3) {\r\n const positions: number[][] = [];\r\n const vectorPoints = points as Vector3[][];\r\n vectorPoints.forEach((p) => {\r\n positions.push(p.flatMap((p2) => [p2.x, p2.y, p2.z]));\r\n });\r\n return positions;\r\n } else if (points instanceof Float32Array) {\r\n return [Array.from(points)];\r\n } else if (points.length && points[0] instanceof Float32Array) {\r\n const positions: number[][] = [];\r\n points.forEach((p) => {\r\n positions.push(Array.from(p as Float32Array));\r\n });\r\n return positions;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n /**\r\n * Updated a lazy line. Rerenders the line and updates boundinfo as well.\r\n */\r\n public updateLazy() {\r\n this.setPoints(this._points);\r\n if (!this._options.colorPointers) {\r\n this._updateColorPointers();\r\n }\r\n this._createVertexBuffers();\r\n this.refreshBoundingInfo();\r\n\r\n this.greasedLineMaterial?.updateLazy();\r\n }\r\n\r\n /**\r\n * Dispose the line and it's resources\r\n */\r\n public dispose() {\r\n super.dispose();\r\n }\r\n\r\n /**\r\n *\r\n * @returns true if the mesh was created in lazy mode\r\n */\r\n public isLazy(): boolean {\r\n return this._lazy;\r\n }\r\n\r\n /**\r\n * Return the the points offsets\r\n */\r\n get offsets() {\r\n return this._offsets;\r\n }\r\n\r\n /**\r\n * Sets point offests\r\n * @param offsets offset table [x,y,z, x,y,z, ....]\r\n */\r\n set offsets(offsets: number[]) {\r\n this._offsets = offsets;\r\n if (!this._offsetsBuffer) {\r\n this._createOffsetsBuffer(offsets);\r\n } else {\r\n this._offsetsBuffer && this._offsetsBuffer.update(offsets);\r\n }\r\n }\r\n\r\n /**\r\n * Gets widths at each line point like [widthLower, widthUpper, widthLower, widthUpper, ...]\r\n */\r\n get widths() {\r\n return this._widths;\r\n }\r\n\r\n /**\r\n * Sets widths at each line point\r\n * @param widths width table [widthLower, widthUpper, widthLower, widthUpper ...]\r\n */\r\n set widths(widths: number[]) {\r\n this._widths = widths;\r\n if (!this._lazy) {\r\n this._widthsBuffer && this._widthsBuffer.update(widths);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the color pointer. Each vertex need a color pointer. These color pointers points to the colors in the color table @see colors\r\n */\r\n get colorPointers() {\r\n return this._colorPointers;\r\n }\r\n\r\n /**\r\n * Sets the color pointer\r\n * @param colorPointers array of color pointer in the colors array. One pointer for every vertex is needed.\r\n */\r\n set colorPointers(colorPointers: number[]) {\r\n this._colorPointers = colorPointers;\r\n if (!this._lazy) {\r\n this._colorPointersBuffer && this._colorPointersBuffer.update(colorPointers);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the pluginMaterial associated with line\r\n */\r\n get greasedLineMaterial() {\r\n return this.material?.pluginManager?.getPlugin(GreasedLinePluginMaterial.GREASED_LINE_MATERIAL_NAME);\r\n }\r\n\r\n /**\r\n * Return copy the points.\r\n */\r\n get points() {\r\n const pointsCopy: number[][] = [];\r\n DeepCopier.DeepCopy(this._points, pointsCopy);\r\n return pointsCopy;\r\n }\r\n\r\n /**\r\n * Adds new points to the line. It doesn't rerenders the line if in lazy mode.\r\n * @param points points table\r\n */\r\n public addPoints(points: number[][]) {\r\n for (const p of points) {\r\n this._points.push(p);\r\n }\r\n\r\n if (!this._lazy) {\r\n this.setPoints(this._points);\r\n }\r\n }\r\n\r\n private _updateColorPointers() {\r\n let colorPointer = 0;\r\n this._colorPointers = [];\r\n this._points.forEach((p) => {\r\n for (let jj = 0; jj < p.length; jj += 3) {\r\n this._colorPointers.push(colorPointer);\r\n this._colorPointers.push(colorPointer++);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Sets line points and rerenders the line.\r\n * @param points points table\r\n */\r\n public setPoints(points: number[][]) {\r\n this._points = points;\r\n this._options.points = points;\r\n\r\n this._initGreasedLine();\r\n\r\n let indiceOffset = 0;\r\n\r\n points.forEach((p) => {\r\n const counters: number[] = [];\r\n const positions: number[] = [];\r\n const indices: number[] = [];\r\n\r\n const totalLength = GreasedLineTools.GetLineLength(p);\r\n for (let j = 0, jj = 0; jj < p.length; j++, jj += 3) {\r\n const partialLine = p.slice(0, jj + 3);\r\n const partialLineLength = GreasedLineTools.GetLineLength(partialLine);\r\n const c = partialLineLength / totalLength;\r\n\r\n positions.push(p[jj], p[jj + 1], p[jj + 2]);\r\n positions.push(p[jj], p[jj + 1], p[jj + 2]);\r\n counters.push(c);\r\n counters.push(c);\r\n\r\n if (jj < p.length - 3) {\r\n const n = j * 2 + indiceOffset;\r\n indices.push(n, n + 1, n + 2);\r\n indices.push(n + 2, n + 1, n + 3);\r\n }\r\n }\r\n\r\n indiceOffset += (p.length / 3) * 2;\r\n\r\n const previous: number[] = [];\r\n const next: number[] = [];\r\n const side: number[] = [];\r\n let uvs: number[] = [];\r\n\r\n this._preprocess(positions, previous, next, side, uvs);\r\n\r\n for (const vp of positions) {\r\n this._vertexPositions.push(vp);\r\n }\r\n\r\n for (const i of indices) {\r\n this._indices.push(i);\r\n }\r\n\r\n for (let i = 0; i < side.length; i++) {\r\n this._previousAndSide.push(previous[i * 3], previous[i * 3 + 1], previous[i * 3 + 2], side[i]);\r\n this._nextAndCounters.push(next[i * 3], next[i * 3 + 1], next[i * 3 + 2], counters[i]);\r\n }\r\n\r\n uvs = this._options.uvs ?? uvs;\r\n for (const uv of uvs) {\r\n this._uvs.push(uv);\r\n }\r\n });\r\n\r\n if (!this._lazy) {\r\n if (!this._options.colorPointers) {\r\n this._updateColorPointers();\r\n }\r\n this._createVertexBuffers();\r\n this.refreshBoundingInfo();\r\n }\r\n }\r\n\r\n private _createLineOptions() {\r\n const lineOptions: GreasedLineMeshOptions = {\r\n points: this._points,\r\n colorPointers: this._colorPointers,\r\n lazy: this._lazy,\r\n updatable: this._updatable,\r\n uvs: this._uvs,\r\n widths: this._widths,\r\n };\r\n return lineOptions;\r\n }\r\n\r\n /**\r\n * Clones the GreasedLineMesh.\r\n * @param name new line name\r\n * @param newParent new parent node\r\n * @returns cloned line\r\n */\r\n public clone(name: string = `${this.name}-cloned`, newParent?: Nullable) {\r\n const lineOptions = this._createLineOptions();\r\n const deepCopiedLineOptions = {};\r\n DeepCopier.DeepCopy(lineOptions, deepCopiedLineOptions, [\"instance\"]);\r\n\r\n const cloned = new GreasedLineMesh(name, this._scene, deepCopiedLineOptions);\r\n if (newParent) {\r\n cloned.parent = newParent;\r\n }\r\n\r\n cloned.material = this.material;\r\n\r\n return cloned;\r\n }\r\n\r\n /**\r\n * Serializes this GreasedLineMesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.type = this.getClassName();\r\n\r\n serializationObject.lineOptions = this._createLineOptions();\r\n }\r\n\r\n /**\r\n * Parses a serialized GreasedLineMesh\r\n * @param parsedMesh the serialized GreasedLineMesh\r\n * @param scene the scene to create the GreasedLineMesh in\r\n * @returns the created GreasedLineMesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): Mesh {\r\n const lineOptions = parsedMesh.lineOptions;\r\n const name = parsedMesh.name;\r\n const result = new GreasedLineMesh(name, scene, lineOptions);\r\n return result;\r\n }\r\n\r\n /**\r\n * Checks whether a ray is intersecting this GreasedLineMesh\r\n * @param ray ray to check the intersection of this mesh with\r\n * @param fastCheck not supported\r\n * @param trianglePredicate not supported\r\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\r\n * @param worldToUse not supported\r\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\r\n * @returns the picking info\r\n */\r\n public intersects(\r\n ray: Ray,\r\n fastCheck?: boolean,\r\n trianglePredicate?: TrianglePickingPredicate,\r\n onlyBoundingInfo = false,\r\n worldToUse?: Matrix,\r\n skipBoundingInfo = false\r\n ): PickingInfo {\r\n const pickingInfo = new PickingInfo();\r\n const intersections = this.findAllIntersections(ray, fastCheck, trianglePredicate, onlyBoundingInfo, worldToUse, skipBoundingInfo, true);\r\n if (intersections?.length === 1) {\r\n const intersection = intersections[0];\r\n pickingInfo.hit = true;\r\n pickingInfo.distance = intersection.distance;\r\n pickingInfo.ray = ray;\r\n pickingInfo.pickedMesh = this;\r\n pickingInfo.pickedPoint = intersection.point;\r\n }\r\n return pickingInfo;\r\n }\r\n\r\n /**\r\n * Gets all intersections of a ray and the line\r\n * @param ray Ray to check the intersection of this mesh with\r\n * @param _fastCheck not supported\r\n * @param _trianglePredicate not supported\r\n * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)\r\n * @param _worldToUse not supported\r\n * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check\r\n * @param firstOnly If true, the first and only intersection is immediatelly returned if found\r\n * @returns intersection(s)\r\n */\r\n public findAllIntersections(\r\n ray: Ray,\r\n _fastCheck?: boolean,\r\n _trianglePredicate?: TrianglePickingPredicate,\r\n onlyBoundingInfo = false,\r\n _worldToUse?: Matrix,\r\n skipBoundingInfo = false,\r\n firstOnly = false\r\n ): { distance: number; point: Vector3 }[] | undefined {\r\n if (onlyBoundingInfo && !skipBoundingInfo && ray.intersectsSphere(this._boundingSphere, this.intersectionThreshold) === false) {\r\n return;\r\n }\r\n\r\n const indices = this.getIndices();\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const widths = this._widths;\r\n\r\n const lineWidth = this.greasedLineMaterial?.width ?? 1;\r\n\r\n const intersects = [];\r\n if (indices && positions && widths) {\r\n let i = 0,\r\n l = 0;\r\n for (i = 0, l = indices.length - 1; i < l; i += 3) {\r\n const a = indices[i];\r\n const b = indices[i + 1];\r\n\r\n GreasedLineMesh._V_START.fromArray(positions, a * 3);\r\n GreasedLineMesh._V_END.fromArray(positions, b * 3);\r\n\r\n if (this._offsets) {\r\n GreasedLineMesh._V_OFFSET_START.fromArray(this._offsets, a * 3);\r\n GreasedLineMesh._V_OFFSET_END.fromArray(this._offsets, b * 3);\r\n GreasedLineMesh._V_START.addInPlace(GreasedLineMesh._V_OFFSET_START);\r\n GreasedLineMesh._V_END.addInPlace(GreasedLineMesh._V_OFFSET_END);\r\n }\r\n\r\n const iFloored = Math.floor(i / 3);\r\n const width = widths[iFloored] !== undefined ? widths[iFloored] : 1;\r\n const precision = (this.intersectionThreshold * (lineWidth * width)) / 2;\r\n\r\n const distance = ray.intersectionSegment(GreasedLineMesh._V_START, GreasedLineMesh._V_END, precision);\r\n if (distance !== -1) {\r\n intersects.push({\r\n distance: distance,\r\n point: ray.direction.normalize().multiplyByFloats(distance, distance, distance).add(ray.origin),\r\n });\r\n if (firstOnly) {\r\n return intersects;\r\n }\r\n }\r\n }\r\n i = l;\r\n }\r\n\r\n return intersects;\r\n }\r\n\r\n private _initGreasedLine() {\r\n this._vertexPositions = [];\r\n this._previousAndSide = [];\r\n this._nextAndCounters = [];\r\n this._indices = [];\r\n this._uvs = [];\r\n }\r\n\r\n private get _boundingSphere() {\r\n return this.getBoundingInfo().boundingSphere;\r\n }\r\n\r\n private static _CompareV3(positionIdx1: number, positionIdx2: number, positions: number[]) {\r\n const arrayIdx1 = positionIdx1 * 6;\r\n const arrayIdx2 = positionIdx2 * 6;\r\n return positions[arrayIdx1] === positions[arrayIdx2] && positions[arrayIdx1 + 1] === positions[arrayIdx2 + 1] && positions[arrayIdx1 + 2] === positions[arrayIdx2 + 2];\r\n }\r\n\r\n private static _CopyV3(positionIdx: number, positions: number[]) {\r\n const arrayIdx = positionIdx * 6;\r\n return [positions[arrayIdx], positions[arrayIdx + 1], positions[arrayIdx + 2]];\r\n }\r\n\r\n private _preprocess(positions: number[], previous: number[], next: number[], side: number[], uvs: number[]) {\r\n const l = positions.length / 6;\r\n\r\n let v: number[] = [];\r\n\r\n if (GreasedLineMesh._CompareV3(0, l - 1, positions)) {\r\n v = GreasedLineMesh._CopyV3(l - 2, positions);\r\n } else {\r\n v = GreasedLineMesh._CopyV3(0, positions);\r\n }\r\n previous.push(v[0], v[1], v[2]);\r\n previous.push(v[0], v[1], v[2]);\r\n\r\n for (let j = 0; j < l; j++) {\r\n side.push(1);\r\n side.push(-1);\r\n\r\n // uvs\r\n if (!this._options.uvs) {\r\n uvs.push(j / (l - 1), 0);\r\n uvs.push(j / (l - 1), 1);\r\n }\r\n\r\n if (j < l - 1) {\r\n v = GreasedLineMesh._CopyV3(j, positions);\r\n previous.push(v[0], v[1], v[2]);\r\n previous.push(v[0], v[1], v[2]);\r\n }\r\n if (j > 0) {\r\n v = GreasedLineMesh._CopyV3(j, positions);\r\n next.push(v[0], v[1], v[2]);\r\n next.push(v[0], v[1], v[2]);\r\n }\r\n }\r\n\r\n if (GreasedLineMesh._CompareV3(l - 1, 0, positions)) {\r\n v = GreasedLineMesh._CopyV3(1, positions);\r\n } else {\r\n v = GreasedLineMesh._CopyV3(l - 1, positions);\r\n }\r\n next.push(v[0], v[1], v[2]);\r\n next.push(v[0], v[1], v[2]);\r\n\r\n return {\r\n previous,\r\n next,\r\n uvs,\r\n side,\r\n };\r\n }\r\n\r\n private _createVertexBuffers() {\r\n const vertexData = new VertexData();\r\n vertexData.positions = this._vertexPositions;\r\n vertexData.indices = this._indices;\r\n vertexData.uvs = this._uvs;\r\n vertexData.applyToMesh(this, this._options.updatable);\r\n\r\n const engine = this._scene.getEngine();\r\n\r\n const previousAndSideBuffer = new Buffer(engine, this._previousAndSide, false, 4);\r\n this.setVerticesBuffer(previousAndSideBuffer.createVertexBuffer(\"grl_previousAndSide\", 0, 4));\r\n\r\n const nextAndCountersBuffer = new Buffer(engine, this._nextAndCounters, false, 4);\r\n this.setVerticesBuffer(nextAndCountersBuffer.createVertexBuffer(\"grl_nextAndCounters\", 0, 4));\r\n\r\n const widthBuffer = new Buffer(engine, this._widths, this._updatable, 1);\r\n this.setVerticesBuffer(widthBuffer.createVertexBuffer(\"grl_widths\", 0, 1));\r\n this._widthsBuffer = widthBuffer;\r\n\r\n const colorPointersBuffer = new Buffer(engine, this._colorPointers, this._updatable, 1);\r\n this.setVerticesBuffer(colorPointersBuffer.createVertexBuffer(\"grl_colorPointers\", 0, 1));\r\n this._colorPointersBuffer = colorPointersBuffer;\r\n }\r\n\r\n private _createOffsetsBuffer(offsets: number[]) {\r\n const engine = this._scene.getEngine();\r\n\r\n const offsetBuffer = new Buffer(engine, offsets, this._updatable, 3);\r\n this.setVerticesBuffer(offsetBuffer.createVertexBuffer(\"grl_offsets\", 0, 3));\r\n this._offsetsBuffer = offsetBuffer;\r\n }\r\n}\r\n","import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Matrix, Quaternion, Vector2, Vector3 } from '@babylonjs/core/Maths';\r\nimport { CreateBox, CreateCylinder, CreatePlane, CreateSphere } from '@babylonjs/core/Meshes/Builders';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eUvMode } from '@models/classes/enums';\r\nimport { UvMapFeature } from '@models/classes/features/uv-map-feature';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { SubmeshVertexData } from './geometry-helper';\r\nimport { applyMatrix4, computeNormal, rotationToVector } from './math-helper';\r\n\r\nconst pWorking = new Vector3();\r\nconst p1 = new Vector3();\r\nconst p2 = new Vector3();\r\nconst p3 = new Vector3();\r\nconst uv1 = new Vector2();\r\nconst uv2 = new Vector2();\r\nconst uv3 = new Vector2();\r\nconst workingUv = new Vector2();\r\nconst workingUv2 = new Vector2();\r\nconst working1 = new Vector3();\r\n\r\nexport class UVMapHelper {\r\n generateUVMapInPlace(\r\n vertexData: Partial,\r\n feature: UvMapFeature,\r\n indexList?: number[]\r\n ): Partial {\r\n const newControlPointMap: Record = {};\r\n const axis = feature.projectionAxis.toVec3();\r\n const rotation = rotationToVector(axis, new Vector3(0, 1, 0));\r\n rotation.multiplyInPlace(Quaternion.RotationAxis(new Vector3(0, 1, 0), (feature.angle / 180) * Math.PI));\r\n // const matrixRotation = new Matrix();\r\n // Matrix.FromQuaternionToRef(rotation, matrixRotation);\r\n const transformMatrix = Matrix.Compose(\r\n feature.scale ? feature.scale.toVec3() : Vector3.One(),\r\n rotation,\r\n Vector3.Zero()\r\n );\r\n\r\n const transformMatrixInv = Matrix.Invert(transformMatrix);\r\n\r\n if (!vertexData.positions) {\r\n throw Error('No vertex positions on mesh');\r\n }\r\n if (!vertexData.indices) {\r\n throw Error('No vertex indices on mesh');\r\n }\r\n const geometryPositions = vertexData.positions;\r\n const geometryIndices = vertexData.indices;\r\n\r\n const controlPointCount = geometryPositions.length / 3;\r\n\r\n const newUvs =\r\n vertexData.uvs && vertexData.uvs.length === controlPointCount * 2\r\n ? new Float32Array(vertexData.uvs)\r\n : new Float32Array(controlPointCount * 2);\r\n const appendVertexData = {\r\n positions: [] as number[],\r\n normals: [] as number[],\r\n uvs: [] as number[],\r\n };\r\n\r\n const nbFaces = indexList ? indexList.length / 3 : geometryIndices.length / 3;\r\n const touchedControlPoints = new Int8Array(controlPointCount);\r\n\r\n if (indexList) {\r\n indexList.forEach(index => {\r\n touchedControlPoints[geometryIndices[index]] = 1;\r\n });\r\n }\r\n const outputUvs = [uv1, uv2, uv3];\r\n\r\n for (let i = 0; i < nbFaces; i++) {\r\n /** here we generate the new UVs */\r\n let i1: number;\r\n let i2: number;\r\n let i3: number;\r\n if (indexList) {\r\n i1 = indexList[i * 3];\r\n i2 = indexList[i * 3 + 1];\r\n i3 = indexList[i * 3 + 2];\r\n } else {\r\n i1 = i * 3;\r\n i2 = i * 3 + 1;\r\n i3 = i * 3 + 2;\r\n }\r\n const v1 = geometryIndices[i1];\r\n const v2 = geometryIndices[i2];\r\n const v3 = geometryIndices[i3];\r\n\r\n if (feature.mode === eUvMode.useExisting) {\r\n if (vertexData.uvs) {\r\n const angle = (feature.angle / 180) * Math.PI;\r\n const vertices = [v1, v2, v3];\r\n\r\n for (let i = 0; i < 3; i++) {\r\n const uvIdx = vertices[i] * 2;\r\n\r\n const u = vertexData.uvs[uvIdx] - 0.5;\r\n const v = vertexData.uvs[uvIdx + 1] - 0.5;\r\n\r\n let newU = u * Math.cos(angle) - v * Math.sin(angle) + 0.5;\r\n let newV = u * Math.sin(angle) + v * Math.cos(angle) + 0.5;\r\n newU = newU * feature.uTile + feature.uOffset;\r\n newV = newV * feature.vTile + feature.vOffset;\r\n\r\n outputUvs[i].copyFromFloats(newU, newV);\r\n }\r\n }\r\n } else {\r\n const start = v1 * 3;\r\n p1.copyFromFloats(geometryPositions[start], geometryPositions[start + 1], geometryPositions[start + 2]);\r\n\r\n const start2 = v2 * 3;\r\n p2.copyFromFloats(\r\n geometryPositions[start2],\r\n geometryPositions[start2 + 1],\r\n geometryPositions[start2 + 2]\r\n );\r\n\r\n const start3 = v3 * 3;\r\n p3.copyFromFloats(\r\n geometryPositions[start3],\r\n geometryPositions[start3 + 1],\r\n geometryPositions[start3 + 2]\r\n );\r\n const normal = computeNormal([p1, p2, p3]);\r\n\r\n applyMatrix4(normal, transformMatrixInv);\r\n\r\n if (feature.center) {\r\n const center = feature.center.toVec3();\r\n p1.subtractInPlace(center);\r\n p2.subtractInPlace(center);\r\n p3.subtractInPlace(center);\r\n }\r\n this.updateFaceUVMapToRef(normal, p1, feature, transformMatrixInv, uv1);\r\n this.updateFaceUVMapToRef(normal, p2, feature, transformMatrixInv, uv2);\r\n this.updateFaceUVMapToRef(normal, p3, feature, transformMatrixInv, uv3);\r\n\r\n /**\r\n * Find the UV at the midpoint position between each edge of the polygon.\r\n * This should closely match the midpoints of the generated vertex UVs.If it does not, we must wrap the UVs at that edge to avoid a UV seam.\r\n * The tolerance is an arbitrary number to avoid artifacts. If wrapping is occuring when it shouldn't, increase this number.\r\n * If wrapping is not occurring when it should, reduce it.\r\n * As you try to wrap a uv on polygons that are not arranged in a good way to accept them (i.e wrap a sphere onto a 8-vertex cube), the error will become significant.\r\n */\r\n const tolerance = 0.05;\r\n working1.copyFrom(p1);\r\n this.updateFaceUVMapToRef(\r\n normal,\r\n working1.addInPlace(p2).scaleInPlace(0.5),\r\n feature,\r\n transformMatrixInv,\r\n workingUv\r\n );\r\n workingUv2.copyFrom(uv1);\r\n workingUv2.addInPlace(uv2).scaleInPlace(0.5);\r\n workingUv.subtractInPlace(workingUv2);\r\n if (Math.abs(workingUv.x % 1) > tolerance) {\r\n if (uv1.x > uv2.x) uv1.x -= 1;\r\n else uv2.x -= 1;\r\n }\r\n if (Math.abs(workingUv.y % 1) > tolerance) {\r\n if (uv1.y > uv2.y) uv1.y -= 1;\r\n else uv2.y -= 1;\r\n }\r\n\r\n if (uv2.x >= 0 && uv2.y >= 0) {\r\n working1.copyFrom(p2);\r\n this.updateFaceUVMapToRef(\r\n normal,\r\n working1.addInPlace(p3).scaleInPlace(0.5),\r\n feature,\r\n transformMatrixInv,\r\n workingUv\r\n );\r\n workingUv2.copyFrom(uv2);\r\n workingUv2.addInPlace(uv3).scaleInPlace(0.5);\r\n workingUv.subtractInPlace(workingUv2);\r\n if (Math.abs(workingUv.x % 1) > tolerance) {\r\n if (uv2.x > uv3.x) uv2.x -= 1;\r\n else uv3.x -= 1;\r\n }\r\n if (Math.abs(workingUv.y % 1) > tolerance) {\r\n if (uv2.y > uv3.y) uv2.y -= 1;\r\n else uv3.y -= 1;\r\n }\r\n }\r\n\r\n if (uv1.x >= 0 && uv1.y >= 0 && uv3.x >= 0 && uv3.y >= 0) {\r\n working1.copyFrom(p1);\r\n this.updateFaceUVMapToRef(\r\n normal,\r\n working1.addInPlace(p3).scaleInPlace(0.5),\r\n feature,\r\n transformMatrixInv,\r\n workingUv\r\n );\r\n workingUv2.copyFrom(uv1);\r\n workingUv2.addInPlace(uv3).scaleInPlace(0.5);\r\n workingUv.subtractInPlace(workingUv2);\r\n if (Math.abs(workingUv.x % 1) > tolerance) {\r\n if (uv1.x > uv3.x) uv1.x -= 1;\r\n else uv3.x -= 1;\r\n }\r\n if (Math.abs(workingUv.y % 1) > tolerance) {\r\n if (uv1.y > uv3.y) uv1.y -= 1;\r\n else uv3.y -= 1;\r\n }\r\n }\r\n }\r\n /** Done generating the new UVs, stored in uv1, uv2 and uv3 for this polygon */\r\n\r\n if (touchedControlPoints[v1]) {\r\n expandControlPoints(i1, v1, uv1);\r\n } else {\r\n newUvs[v1 * 2] = uv1.x;\r\n newUvs[v1 * 2 + 1] = uv1.y;\r\n }\r\n\r\n if (touchedControlPoints[v2]) {\r\n expandControlPoints(i2, v2, uv2);\r\n } else {\r\n newUvs[v2 * 2] = uv2.x;\r\n newUvs[v2 * 2 + 1] = uv2.y;\r\n }\r\n\r\n if (touchedControlPoints[v3]) {\r\n expandControlPoints(i3, v3, uv3);\r\n } else {\r\n newUvs[v3 * 2] = uv3.x;\r\n newUvs[v3 * 2 + 1] = uv3.y;\r\n }\r\n\r\n touchedControlPoints[v1] = 1;\r\n touchedControlPoints[v2] = 1;\r\n touchedControlPoints[v3] = 1;\r\n }\r\n\r\n if (appendVertexData.positions.length > 0) {\r\n const newPositions = new Float32Array(vertexData.positions.length + appendVertexData.positions.length);\r\n newPositions.set(vertexData.positions);\r\n newPositions.set(appendVertexData.positions, vertexData.positions.length);\r\n vertexData.positions = newPositions;\r\n }\r\n if (vertexData.normals && appendVertexData.normals.length > 0) {\r\n const newNormals = new Float32Array(vertexData.normals.length + appendVertexData.normals.length);\r\n newNormals.set(vertexData.normals);\r\n newNormals.set(appendVertexData.normals, vertexData.normals.length);\r\n vertexData.normals = newNormals;\r\n }\r\n if (appendVertexData.uvs.length > 0) {\r\n const newUvsTyped = new Float32Array(newUvs.length + appendVertexData.uvs.length);\r\n newUvsTyped.set(newUvs);\r\n newUvsTyped.set(appendVertexData.uvs, newUvs.length);\r\n vertexData.uvs = newUvsTyped;\r\n } else {\r\n vertexData.uvs = new Float32Array(newUvs);\r\n }\r\n\r\n return vertexData;\r\n\r\n function expandControlPoints(index: number, vertexIndex: number, newUv: Vector2) {\r\n if (newUvs[vertexIndex * 2] !== newUv.x || newUvs[vertexIndex * 2 + 1] !== newUv.y) {\r\n if (!vertexData.positions || !vertexData.indices) {\r\n throw Error('Invalid geometry: positions or indices are null');\r\n }\r\n const indices = vertexData.indices;\r\n const positions = vertexData.positions;\r\n const normals = vertexData.normals;\r\n\r\n const key =\r\n positions[vertexIndex * 3].toPrecision(6) +\r\n ',' +\r\n positions[vertexIndex * 3 + 1].toPrecision(6) +\r\n ',' +\r\n positions[vertexIndex * 3 + 2].toPrecision(6) +\r\n '_' +\r\n (normals\r\n ? normals[vertexIndex * 3].toPrecision(6) +\r\n ',' +\r\n normals[vertexIndex * 3 + 1].toPrecision(6) +\r\n ',' +\r\n normals[vertexIndex * 3 + 2].toPrecision(6) +\r\n '_'\r\n : '') +\r\n newUv.x.toPrecision(6) +\r\n ',' +\r\n newUv.y.toPrecision(6);\r\n\r\n if (newControlPointMap[key]) {\r\n indices[index] = newControlPointMap[key];\r\n } else {\r\n const newVertexIndex = (positions.length + appendVertexData.positions.length) / 3;\r\n indices[index] = newVertexIndex;\r\n\r\n appendVertexData.positions.push(...positions.slice(vertexIndex * 3, vertexIndex * 3 + 3));\r\n if (vertexData.normals) {\r\n appendVertexData.normals.push(\r\n ...vertexData.normals.slice(vertexIndex * 3, vertexIndex * 3 + 3)\r\n );\r\n }\r\n appendVertexData.uvs.push(newUv.x, newUv.y);\r\n\r\n if (vertexData.submeshData) {\r\n for (let i = 0; i < vertexData.submeshData.length; i++) {\r\n const submeshData = vertexData.submeshData[i];\r\n if (\r\n submeshData.verticesStart <= vertexIndex &&\r\n submeshData.verticesStart + submeshData.verticesCount > vertexIndex\r\n ) {\r\n submeshData.verticesCount += 1;\r\n } else if (submeshData.verticesStart > vertexIndex) {\r\n submeshData.verticesStart += 1;\r\n }\r\n }\r\n }\r\n\r\n newControlPointMap[key] = newVertexIndex;\r\n }\r\n }\r\n }\r\n }\r\n\r\n computeAutoFitSize(mesh: AbstractMesh): KbVector {\r\n const boundingBox = mesh.getBoundingInfo().boundingBox;\r\n\r\n //const center = boundingBox.center;\r\n\r\n const max = boundingBox.maximum;\r\n const min = boundingBox.minimum;\r\n\r\n return new KbVector(max.x - min.x, max.y - min.y, max.z - min.z);\r\n }\r\n\r\n private updateFaceUVMapToRef(\r\n faceNormal: Vector3,\r\n position: Vector3,\r\n feat: UvMapFeature,\r\n transformMatrixInv: Matrix,\r\n uv: Vector2\r\n ): Vector2 {\r\n pWorking.copyFrom(position);\r\n applyMatrix4(pWorking, transformMatrixInv);\r\n\r\n switch (feat.mode) {\r\n case eUvMode.planar:\r\n this.planarUVMap(pWorking, uv);\r\n break;\r\n case eUvMode.box:\r\n this.boxUVMap(pWorking, faceNormal, uv);\r\n break;\r\n case eUvMode.cylindrical:\r\n this.cylindricalUVMap(pWorking, uv);\r\n break;\r\n case eUvMode.spherical:\r\n this.sphericalUVMap(pWorking, uv);\r\n break;\r\n case eUvMode.useExisting:\r\n //don't do anything so that existing UVs of mesh are being used instead\r\n break;\r\n default:\r\n uv.set(0, 0);\r\n break;\r\n }\r\n if (feat.uTile && feat.uTile !== 1) {\r\n uv.x *= feat.uTile;\r\n }\r\n if (feat.vTile && feat.vTile !== 1) {\r\n uv.y *= feat.vTile;\r\n }\r\n return uv;\r\n }\r\n\r\n private planarUVMap(vertex: Vector3, uv: Vector2): Vector2 {\r\n let u = vertex.x;\r\n let v = -vertex.z;\r\n\r\n u = u + 0.5;\r\n v = v + 0.5;\r\n uv.set(u, v);\r\n return uv;\r\n }\r\n\r\n private cylindricalUVMap(vertex: Vector3, uv: Vector2): Vector2 {\r\n let lon;\r\n if (vertex.x === 0 && vertex.z === 0) {\r\n lon = 0;\r\n } else {\r\n lon = Math.atan2(vertex.x, vertex.z);\r\n if (lon < 0) {\r\n lon += Math.PI * 2;\r\n }\r\n }\r\n const t = vertex.y + 0.5;\r\n lon = lon / (Math.PI * 2);\r\n uv.set(lon, t);\r\n return uv;\r\n }\r\n\r\n private boxUVMap(vertex: Vector3, normal: Vector3, uv: Vector2): Vector2 {\r\n let s = 0,\r\n t = 0;\r\n const x = vertex.x,\r\n y = vertex.y,\r\n z = vertex.z;\r\n const nx = Math.abs(normal.x),\r\n ny = Math.abs(normal.y),\r\n nz = Math.abs(normal.z);\r\n if (nx >= ny && nx >= nz) {\r\n s = -z + 0.5;\r\n t = y + 0.5;\r\n }\r\n if (ny >= nx && ny >= nz) {\r\n s = x + 0.5;\r\n t = -z + 0.5;\r\n }\r\n if (nz >= nx && nz >= ny) {\r\n s = x + 0.5;\r\n t = y + 0.5;\r\n }\r\n // not sure what this is for but it screws up the mapping and flips the uv's halfway through\r\n // if (normal.x < 0) {\r\n // s = -s + 1\r\n // }\r\n // if (normal.y < 0) {\r\n // s = -s + 1\r\n // }\r\n // if (normal.z < 0) {\r\n // s = -s + 1\r\n // }\r\n uv.set(s, t);\r\n return uv;\r\n }\r\n\r\n private sphericalUVMap(vertex: Vector3, uv: Vector2): Vector2 {\r\n const newVertex = vertex.clone();\r\n const lonlat = xyzToLongitudeLatitude(newVertex.x, -newVertex.y, newVertex.z);\r\n const lon = lonlat.lon / (Math.PI * 2);\r\n const lat = 0.5 - lonlat.lat / Math.PI;\r\n uv.set(lon, lat);\r\n return uv;\r\n\r\n function xyzToLongitudeLatitude(x: number, y: number, z: number) {\r\n let lo: number, la: number;\r\n const EPSILON = 1e-6;\r\n if (Math.abs(x) < EPSILON && Math.abs(z) < EPSILON) {\r\n lo = 0;\r\n if (Math.abs(y) < EPSILON) {\r\n la = 0;\r\n } else {\r\n la = y < 0 ? -(Math.PI / 2) : Math.PI / 2;\r\n }\r\n } else {\r\n lo = Math.atan2(x, z);\r\n if (lo < 0) {\r\n lo += Math.PI * 2;\r\n }\r\n const h = Math.sqrt(x * x + z * z);\r\n la = Math.atan2(y, h);\r\n }\r\n return {\r\n lon: lo,\r\n lat: la,\r\n };\r\n }\r\n }\r\n}\r\n\r\nexport function createUvMapVisualization(uvMap: UvMapFeature, scene: Scene, color?: Color3) {\r\n let uvMapVisualization: Mesh;\r\n\r\n if (!color) {\r\n color = Color3.Yellow();\r\n }\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n\r\n if (uvMap.mode === eUvMode.spherical) {\r\n uvMapVisualization = CreateSphere('UvMapSphere', { segments: 6 }, scene);\r\n } else if (uvMap.mode === eUvMode.cylindrical) {\r\n uvMapVisualization = CreateCylinder('UvMapCylinder', { tessellation: 10 }, scene);\r\n } else if (uvMap.mode === eUvMode.box) {\r\n uvMapVisualization = CreateBox('UvBox', {}, scene);\r\n } else if (uvMap.mode === eUvMode.planar) {\r\n uvMapVisualization = CreatePlane('mirrorPlane', {}, scene);\r\n uvMapVisualization.rotation = new Vector3(Math.PI / 2, 0, 0);\r\n uvMapVisualization.bakeCurrentTransformIntoVertices();\r\n } else {\r\n uvMapVisualization = CreatePlane('mirrorPlane', {}, scene);\r\n uvMapVisualization.bakeCurrentTransformIntoVertices();\r\n uvMapVisualization.setEnabled(false);\r\n }\r\n uvMapVisualization.material = coloredMaterial;\r\n\r\n return uvMapVisualization;\r\n}\r\n","import { IVertexGroup } from '@models/classes/kb3d-models';\r\n\r\nexport function removeVerticesFromAll(\r\n vertexGroups: Array>,\r\n startIndex: number,\r\n endIndex: number\r\n): void {\r\n for (let i = 0; i < vertexGroups.length; i++) {\r\n const vertexGroup = vertexGroups[i];\r\n if (vertexGroupsIntersect(vertexGroup, startIndex, endIndex)) {\r\n const result = excludeVertices(vertexGroup, startIndex, endIndex);\r\n vertexGroups.splice(i, 1, ...result);\r\n }\r\n }\r\n}\r\n\r\nexport function mergeVerticesIntoAll>(vertexGroups: T[], newVertex: T): void {\r\n vertexGroups.push(newVertex);\r\n vertexGroups.sort((a, b) => a.startIndex! - b.startIndex!);\r\n\r\n for (let i = 0; i < vertexGroups.length; i++) {\r\n const vertexGroup = vertexGroups[i];\r\n const nextVertexGroup = vertexGroups[i + 1];\r\n\r\n if (nextVertexGroup && nextVertexGroup.startIndex < vertexGroup.endIndex) {\r\n const mergedVertexGroup = { ...vertexGroup, endIndex: nextVertexGroup.endIndex };\r\n vertexGroups.splice(i, 2, mergedVertexGroup);\r\n i--;\r\n }\r\n }\r\n}\r\n\r\nexport function excludeVertices>(\r\n vertexGroup: T,\r\n startIndex: number,\r\n endIndex: number\r\n): T[] {\r\n if (vertexGroupsIntersect(vertexGroup, startIndex, endIndex)) {\r\n const result = [] as T[];\r\n\r\n // Maintain the selections of either side of the current vertex\r\n if (startIndex > vertexGroup.startIndex) {\r\n result.push({\r\n ...vertexGroup,\r\n endIndex: startIndex,\r\n });\r\n }\r\n if (endIndex < vertexGroup.endIndex) {\r\n result.push({\r\n ...vertexGroup,\r\n startIndex: endIndex,\r\n });\r\n }\r\n\r\n return result;\r\n } else {\r\n return [vertexGroup];\r\n }\r\n}\r\n\r\nexport function mergeVertices>(vertexGroup: T, newVertex: T): T[] {\r\n const result = [] as T[];\r\n const newVertexGroup = { ...vertexGroup };\r\n const startIndex = newVertex.startIndex;\r\n const endIndex = newVertex.endIndex;\r\n\r\n if (vertexGroupsIntersect(vertexGroup, startIndex, endIndex)) {\r\n // Maintain the selections of either side of the current vertex\r\n if (startIndex < vertexGroup.startIndex) {\r\n newVertexGroup.startIndex = startIndex;\r\n }\r\n if (endIndex > vertexGroup.endIndex) {\r\n newVertexGroup.endIndex = endIndex;\r\n }\r\n result.push(newVertexGroup);\r\n } else {\r\n if (startIndex > vertexGroup.startIndex) {\r\n result.push(newVertexGroup, newVertex);\r\n } else {\r\n result.push(newVertex, newVertexGroup);\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\nfunction vertexGroupsIntersect(vertexGroup: Required, startIndex: number, endIndex: number) {\r\n return startIndex <= vertexGroup.endIndex && endIndex >= vertexGroup.startIndex;\r\n}\r\n","import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eViewpointTargetMode, eViewpointType } from '@models/classes/enums';\r\nimport { ViewpointNode } from '@models/classes/viewpoints';\r\n\r\nexport function createViewpointVisualization(viewpoint: ViewpointNode, scene: Scene, color?: Color3) {\r\n if (!color) {\r\n color = Color3.Green();\r\n }\r\n let targetPositionMarker: Mesh | undefined;\r\n\r\n const viewpointPositionGizmo = MeshBuilder.CreateCylinder(\r\n 'cameraGizmoLens',\r\n { diameterTop: 0.3, height: 0.2, diameterBottom: 0.2, tessellation: 8 },\r\n scene\r\n );\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n viewpointPositionGizmo.material = coloredMaterial;\r\n\r\n const lightPositionGizmoBox = MeshBuilder.CreateBox('cameraGizmoBody', { size: 0.4 }, scene);\r\n lightPositionGizmoBox.setParent(viewpointPositionGizmo);\r\n lightPositionGizmoBox.position = new Vector3(0, -0.3, 0);\r\n lightPositionGizmoBox.material = coloredMaterial;\r\n\r\n viewpointPositionGizmo.isPickable = false;\r\n viewpointPositionGizmo.setEnabled(true);\r\n\r\n if (viewpoint.type === eViewpointType.orbit && viewpoint.targetMode === eViewpointTargetMode.point) {\r\n targetPositionMarker = MeshBuilder.CreateSphere('viewpointTargetMarker', { diameter: 0.15 }, scene);\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.emissiveColor = color;\r\n targetPositionMarker.material = coloredMaterial;\r\n targetPositionMarker.isPickable = false;\r\n targetPositionMarker.setEnabled(true);\r\n }\r\n\r\n return { viewpointPositionGizmo, targetPositionMarker };\r\n}\r\n","import { BaseTexture } from '@babylonjs/core/Materials/Textures/baseTexture';\r\nimport { Material } from '@babylonjs/core/Materials/material';\r\nimport { Node } from '@babylonjs/core/node';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Kb3dObject, Token, instanceOf } from '@models/classes';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SyncService } from '@models/services';\r\nimport { KbViewer } from '@view/kb-viewer';\r\n\r\n/** The maxiumum amount of allowed time to spend in a single render cycle, to avoid locking the browser */\r\nexport const MAX_RENDER_TIME = 20000;\r\n\r\nexport abstract class Renderer {\r\n constructor(protected viewer: KbViewer, protected scene: Scene) {}\r\n\r\n public babylonMap = new Map();\r\n\r\n /**\r\n * The function to update the renderer scene for the given renderer type\r\n * @param node The node to update\r\n * @returns nothing\r\n */\r\n protected abstract update3dInternal(node: ITrackedClass): void;\r\n\r\n /**\r\n * Token that defines the type or base type of model that this\r\n * renderer processes\r\n */\r\n public abstract modelToken: Token;\r\n\r\n /**\r\n * Determines whether the given node should be handled by this renderer. Can be\r\n * overriden for special behavior\r\n */\r\n public handlesNode(node: Kb3dObject): boolean {\r\n return instanceOf(node, this.modelToken);\r\n }\r\n\r\n public update3d(node: ITrackedClass) {\r\n this.update3dInternal(node);\r\n if (this.viewer.options.validator) {\r\n this.viewer.options.validator.validateNode(node);\r\n }\r\n }\r\n\r\n public delete3d(node: ITrackedClass) {\r\n const o = this.babylonMap.get(node._dynamicId);\r\n if (o) {\r\n if (o instanceof Material) {\r\n o.dispose(true, true);\r\n } else {\r\n o.dispose();\r\n }\r\n }\r\n this.babylonMap.delete(node._dynamicId);\r\n\r\n SyncService.nodeDeletionProcessed(node);\r\n }\r\n\r\n public get3d(node: ITrackedClass | T): T3D | undefined {\r\n return this.babylonMap.get(node._dynamicId);\r\n }\r\n\r\n public set3d(node: ITrackedClass | T, babylonObject: T3D) {\r\n this.babylonMap.set(node._dynamicId, babylonObject);\r\n }\r\n\r\n public getChanges(node: ITrackedClass) {\r\n const isNew = this.get3d(node) == null;\r\n const changes = new Map(node.changes);\r\n if (isNew) {\r\n for (const prop in node) {\r\n changes.set(prop as Extract, node[prop as keyof T]);\r\n }\r\n }\r\n return changes;\r\n }\r\n\r\n public dispose() {\r\n this.babylonMap.clear();\r\n }\r\n}\r\n","import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture';\r\nimport { Color3, Color4, Plane, Quaternion, Vector3, Vector4 } from '@babylonjs/core/Maths';\r\nimport { PlaneBuilder } from '@babylonjs/core/Meshes/Builders/planeBuilder';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { getBinClampedSize } from '@common-util/texture-util';\r\nimport { AnnotationNode } from '@models/classes/annotations';\r\nimport { eAnnotationLineStyle } from '@models/classes/enums';\r\nimport { Connector } from '@models/classes/features/connector';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { SceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { getCameraPositionWithOffset, rotationToVector, roundToPlaces, transformVectorWithQuat } from '@view/helpers';\r\nimport { Subscription } from 'rxjs';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport { Renderer } from './renderer';\r\nimport { RendererManager } from './renderer-manager';\r\n\r\nconst TEXT_RESOLUTION = 128;\r\nexport interface ILineMeshOptions {\r\n points: Vector3[];\r\n updatable?: boolean;\r\n instance?: LinesMesh;\r\n colors?: Color4[];\r\n dashSize?: number;\r\n gapSize?: number;\r\n dashNb?: number;\r\n}\r\nexport interface AnnotationParts {\r\n line?: ILineMeshOptions;\r\n textMesh: AbstractMesh;\r\n textMaterial: PBRMaterial;\r\n textContainer: TransformNode;\r\n rootMesh: TransformNode;\r\n billboard: boolean;\r\n}\r\n\r\nexport interface AnnotationInfo {\r\n meshInfo?: AnnotationParts;\r\n boundingInfo?: {\r\n targetNode: Kb3dObject;\r\n subscription: Subscription;\r\n };\r\n positionNeedsUpdate: boolean;\r\n textNeedsUpdate: boolean;\r\n lineNeedsUpdate: boolean;\r\n}\r\n\r\nexport class AnnotationRenderer extends Renderer {\r\n utilityLayer: UtilityLayerRenderer;\r\n modelToken = Token.AnnotationNode;\r\n annotationStore = new Map();\r\n billboards = new Map();\r\n\r\n constructor(protected viewer: KbViewer, protected scene: Scene, protected rendererManager: RendererManager) {\r\n super(viewer, scene);\r\n this.utilityLayer = viewer.utilityLayer;\r\n scene.registerBeforeRender(() => {\r\n if (scene.activeCamera && this.billboards.size > 0) {\r\n this.billboards.forEach(meshInfo => {\r\n const camera = scene.activeCamera!;\r\n meshInfo.rootMesh.lookAt(getCameraPositionWithOffset(camera), 0, Math.PI / 2);\r\n if (meshInfo.rootMesh.parent) {\r\n if (!meshInfo.rootMesh.rotationQuaternion) {\r\n meshInfo.rootMesh.rotationQuaternion = Quaternion.Identity();\r\n }\r\n const parentRotation = meshInfo.rootMesh.parent.computeWorldMatrix().getRotationMatrix();\r\n parentRotation.invert();\r\n const parentRotationQuat = Quaternion.FromRotationMatrix(parentRotation);\r\n meshInfo.rootMesh.rotationQuaternion = parentRotationQuat.multiplyInPlace(\r\n meshInfo.rootMesh.rotationQuaternion\r\n );\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n let annotationInfo = this.annotationStore.get(node._dynamicId);\r\n if (!annotationInfo) {\r\n annotationInfo = {\r\n positionNeedsUpdate: false,\r\n textNeedsUpdate: false,\r\n lineNeedsUpdate: false,\r\n };\r\n this.annotationStore.set(node._dynamicId, annotationInfo);\r\n }\r\n\r\n if (annotationInfo.meshInfo && node.changes.has('keepOnTop')) {\r\n this.delete3d(node, true);\r\n annotationInfo.meshInfo = undefined;\r\n annotationInfo.positionNeedsUpdate = true;\r\n annotationInfo.textNeedsUpdate = true;\r\n annotationInfo.lineNeedsUpdate = true;\r\n }\r\n const scene = node.keepOnTop ? this.utilityLayer.utilityLayerScene : this.scene;\r\n\r\n if (\r\n (!annotationInfo.meshInfo && node.enabled && node.targetId) ||\r\n (node.changes.hasAny('isPickable') && node.enabled && node.targetId)\r\n ) {\r\n if (annotationInfo.meshInfo) {\r\n annotationInfo.meshInfo = undefined;\r\n }\r\n annotationInfo.meshInfo = createAnnotationTextModels(node, scene);\r\n\r\n // Put the annotation on the parent scene so the scene visibility affects the node\r\n if (node._parentScene) {\r\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\r\n annotationInfo.meshInfo.rootMesh.setParent(parentSceneMesh);\r\n }\r\n\r\n this.set3d(node, annotationInfo.meshInfo.rootMesh);\r\n }\r\n const meshInfo = annotationInfo.meshInfo;\r\n\r\n // Set position of annotation\r\n if (node.changes.hasAny('targetId', 'offset', 'billboard', 'horizontalBoxAlign', 'verticalBoxAlign')) {\r\n annotationInfo.positionNeedsUpdate = true;\r\n }\r\n if (node.changes.hasAny('color', 'lineStyle')) {\r\n annotationInfo.lineNeedsUpdate = true;\r\n }\r\n if (\r\n node.changes.hasAny(\r\n 'fontFamily',\r\n 'fontSize',\r\n 'lineSpacing',\r\n 'label',\r\n 'color',\r\n 'preloadFontStylesheet',\r\n 'horizontalTextAlign'\r\n )\r\n ) {\r\n annotationInfo.textNeedsUpdate = true;\r\n }\r\n\r\n if (meshInfo) {\r\n if (node.changes.hasAny('enabled', 'billboard', 'keepOnTop')) {\r\n if (node.enabled && node.billboard) {\r\n this.billboards.set(node._dynamicId, meshInfo);\r\n } else {\r\n this.billboards.delete(node._dynamicId);\r\n }\r\n }\r\n\r\n let needsFont = false;\r\n if (node.preloadFontStylesheet && node.fontFamily) {\r\n const fontService = node._manager!.getService(Token.FontService);\r\n\r\n if (!fontService.readyFonts.has(node.fontFamily)) {\r\n needsFont = true;\r\n fontService.loadFont(node.preloadFontStylesheet, [node.fontFamily]).then(resultFonts => {\r\n if (resultFonts.length > 0) {\r\n node.setPropertyIsModified('fontFamily', true);\r\n }\r\n });\r\n }\r\n }\r\n\r\n if (node.enabled && node.targetId && !needsFont) {\r\n const color = node.color.toColor4();\r\n\r\n if (annotationInfo.positionNeedsUpdate) {\r\n let targetNode: Kb3dObject | undefined;\r\n if (node.targetId && node._manager) {\r\n const manager = node._manager;\r\n targetNode = manager.getById(node.targetId);\r\n }\r\n\r\n if (\r\n annotationInfo.boundingInfo &&\r\n annotationInfo.boundingInfo.targetNode._dynamicId !== targetNode?._dynamicId\r\n ) {\r\n annotationInfo.boundingInfo.subscription.unsubscribe();\r\n }\r\n if (targetNode) {\r\n if (targetNode instanceof Connector) {\r\n // Only supporting connectors for now\r\n if (targetNode._parent) {\r\n annotationInfo.boundingInfo = {\r\n targetNode: targetNode,\r\n subscription: this.viewer.bbCache\r\n .watchForChanges(targetNode._parent)\r\n .subscribe(() => {\r\n node.setPropertyIsModified('targetId', true);\r\n }),\r\n };\r\n }\r\n }\r\n\r\n const transform = this.updatePositionFromAnnotation(node, targetNode, meshInfo);\r\n\r\n if (transform) {\r\n meshInfo.rootMesh.position = transform.position;\r\n // The annotation plane mesh position doesn't update in certain situations when the parent transform is moved,\r\n // so we have to manually update the world matrix\r\n meshInfo.rootMesh.getChildMeshes().forEach(mesh => mesh.computeWorldMatrix(true));\r\n meshInfo.textContainer.rotationQuaternion = transform.textRotation;\r\n if (!node.billboard) {\r\n meshInfo.rootMesh.rotationQuaternion = transform.rotation;\r\n }\r\n\r\n if (transform && transform.offset && transform.lineOffset && node.offset.length() > 0) {\r\n const basePoint = transform.position.subtract(transform.offset);\r\n meshInfo.line = {\r\n points: [basePoint, basePoint.add(transform.lineOffset)],\r\n updatable: true,\r\n colors: [color, color],\r\n instance: meshInfo.line?.instance,\r\n };\r\n\r\n // If the line is not getting rebuilt, then just update the line position\r\n if (!annotationInfo.lineNeedsUpdate) {\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\r\n }\r\n } else {\r\n if (meshInfo.line?.instance) {\r\n meshInfo.line.instance.dispose();\r\n }\r\n meshInfo.line = undefined;\r\n }\r\n }\r\n\r\n annotationInfo.positionNeedsUpdate = false;\r\n }\r\n }\r\n\r\n if (annotationInfo.lineNeedsUpdate) {\r\n if (meshInfo.line) {\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.dispose();\r\n meshInfo.line.instance = undefined;\r\n }\r\n\r\n meshInfo.line.colors = [];\r\n for (let i = 0; i < meshInfo.line.points.length; i++) {\r\n meshInfo.line.colors.push(color);\r\n }\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\r\n if (meshInfo.line.instance && node._parentScene) {\r\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\r\n meshInfo.line.instance.parent = parentSceneMesh;\r\n }\r\n\r\n annotationInfo.lineNeedsUpdate = false;\r\n }\r\n }\r\n\r\n if (annotationInfo.textNeedsUpdate) {\r\n updateAnnotationText(\r\n node,\r\n meshInfo.textMesh,\r\n meshInfo.textMaterial,\r\n this.scene.getEngine().webGLVersion < 2\r\n );\r\n annotationInfo.textNeedsUpdate = false;\r\n }\r\n }\r\n\r\n const enabled = node.enabled && !!node.targetId;\r\n\r\n if (meshInfo.rootMesh.isEnabled() !== enabled) {\r\n meshInfo.rootMesh.setEnabled(enabled);\r\n meshInfo.line?.instance?.setEnabled(enabled);\r\n }\r\n }\r\n }\r\n\r\n dispose() {\r\n this.billboards.clear();\r\n this.annotationStore.clear();\r\n super.dispose();\r\n }\r\n\r\n delete3d(node: ITrackedClass, keepInStore = false) {\r\n const annotationModels = this.annotationStore.get(node._dynamicId);\r\n if (annotationModels && annotationModels.meshInfo) {\r\n annotationModels.meshInfo.rootMesh.dispose();\r\n if (annotationModels.meshInfo.line?.instance) {\r\n annotationModels.meshInfo.line.instance.dispose();\r\n }\r\n }\r\n if (!keepInStore) {\r\n this.annotationStore.delete(node._dynamicId);\r\n this.billboards.delete(node._dynamicId);\r\n }\r\n super.delete3d(node);\r\n }\r\n\r\n private updatePositionFromAnnotation(\r\n node: ITrackedClass,\r\n targetNode: Kb3dObject,\r\n meshInfo?: AnnotationParts\r\n ) {\r\n let newPosition: Vector3 | undefined;\r\n let newDirection: Vector3 | undefined;\r\n let newAngle: number | undefined;\r\n\r\n // Only supporting connectors for now, but could support direct mesh targets in the future\r\n if (targetNode instanceof Connector) {\r\n newPosition = getPositionFromConnnector(targetNode, this.rendererManager, node._parentScene);\r\n newDirection = targetNode.direction.toVec3();\r\n newAngle = targetNode.angle;\r\n }\r\n if (newPosition && newDirection && newAngle !== undefined) {\r\n const newOffset = node.offset.toVec3();\r\n if (meshInfo) {\r\n const newPivot = new Vector3(0, 0, 0);\r\n if (node.horizontalBoxAlign == 'left') {\r\n meshInfo.rootMesh.getPivotPoint();\r\n newOffset.x += meshInfo.textMesh.scaling.x / 2;\r\n newPivot.x -= meshInfo.textMesh.scaling.x / 2;\r\n } else if (node.horizontalBoxAlign == 'right') {\r\n newOffset.x -= meshInfo.textMesh.scaling.x / 2;\r\n newPivot.x += meshInfo.textMesh.scaling.x / 2;\r\n }\r\n if (node.verticalBoxAlign == 'top') {\r\n newOffset.z += meshInfo.textMesh.scaling.z / 2;\r\n newPivot.z -= meshInfo.textMesh.scaling.z / 2;\r\n } else if (node.verticalBoxAlign == 'bottom') {\r\n newOffset.z -= meshInfo.textMesh.scaling.z / 2;\r\n newPivot.z += meshInfo.textMesh.scaling.z / 2;\r\n }\r\n meshInfo.rootMesh.setPivotPoint(newPivot);\r\n }\r\n\r\n const transform = calculateTransform(newPosition, newDirection, newAngle, newOffset, node.offset.toVec3());\r\n return transform;\r\n }\r\n }\r\n}\r\n\r\nexport function createAnnotationTextModels(node: AnnotationNode, scene: Scene, isPickable = false) {\r\n const containerMesh = new TransformNode(node._dynamicId, scene);\r\n\r\n //Create plane\r\n const plane = PlaneBuilder.CreatePlane(\r\n `${node._dynamicId}_plane`,\r\n {\r\n width: 1,\r\n height: 1,\r\n frontUVs: new Vector4(1, 0, 0, 1),\r\n backUVs: new Vector4(0, 0, 1, 1),\r\n sideOrientation: Mesh.DOUBLESIDE,\r\n sourcePlane: new Plane(0, 1, 0, 0),\r\n },\r\n scene\r\n );\r\n const planeContainer = new TransformNode(`${node._dynamicId}_planeContainer`);\r\n\r\n const dynamicTexture = new DynamicTexture(\r\n `${node._dynamicId}_planeTexture`,\r\n { width: TEXT_RESOLUTION, height: TEXT_RESOLUTION },\r\n scene,\r\n true\r\n );\r\n dynamicTexture.isBlocking = false;\r\n dynamicTexture.hasAlpha = true;\r\n\r\n //create material\r\n const mat = new PBRMaterial(`${node._dynamicId}_mat`, scene);\r\n if (node.keepOnTop) {\r\n mat.emissiveColor = Color3.White();\r\n }\r\n mat.albedoTexture = dynamicTexture;\r\n mat.useAlphaFromAlbedoTexture = true;\r\n mat.backFaceCulling = true;\r\n mat.zOffset = -1;\r\n mat.albedoColor = Color3.White();\r\n mat.roughness = 1;\r\n mat.metallic = 0;\r\n\r\n //apply material\r\n plane.material = mat;\r\n plane.parent = planeContainer;\r\n planeContainer.parent = containerMesh;\r\n plane.isPickable = isPickable || node.isPickable;\r\n\r\n const annotationModels = {\r\n textMesh: plane,\r\n textContainer: planeContainer,\r\n textMaterial: mat,\r\n rootMesh: containerMesh,\r\n billboard: node.billboard,\r\n positionNeedsUpdate: false,\r\n textNeedsUpdate: false,\r\n };\r\n\r\n return annotationModels;\r\n}\r\n\r\nexport function updateAnnotationText(\r\n node: AnnotationNode,\r\n mesh: AbstractMesh,\r\n textMaterial: PBRMaterial,\r\n webgl1Context: boolean,\r\n defaultValue = ' ',\r\n values: any = {}\r\n) {\r\n const mat = textMaterial;\r\n const dynamicTexture = mat.albedoTexture as DynamicTexture;\r\n const fontFamily = node.fontFamily || 'Arial';\r\n const labelSize = node.fontSize;\r\n const labelText = evalHandlebarString(node.label || defaultValue, values);\r\n const textGap = node.lineSpacing;\r\n const textColor = node.color.toColor3().toLinearSpace();\r\n if (node.keepOnTop) {\r\n mat.emissiveColor = textColor;\r\n }\r\n\r\n // Determine the space needed for the text\r\n const ctx = dynamicTexture.getContext();\r\n ctx.font = TEXT_RESOLUTION + 'px ' + fontFamily;\r\n const labelStats = getMultiLineStats(labelText, ctx as CanvasRenderingContext2D);\r\n const textWidth = labelStats.maximumWidth;\r\n const textHeight = labelStats.maximumHeight;\r\n const labelArray = labelStats.labelArray;\r\n const lineWidths = labelStats.lineWidths;\r\n labelArray.reverse();\r\n lineWidths.reverse();\r\n const totalCanvasHeight = (textHeight + textGap) * labelArray.length - textGap;\r\n ctx.clearRect(0 - textWidth / 2, 0, textWidth / 2, totalCanvasHeight);\r\n //ctx.clearRect(0, 0, textWidth, totalCanvasHeight);\r\n let heightRatioChange = 1;\r\n if (labelArray.length > 1) {\r\n heightRatioChange = totalCanvasHeight / textHeight;\r\n }\r\n mesh.scaling = new Vector3((textWidth / textHeight) * labelSize, labelSize * heightRatioChange, 1);\r\n\r\n let textBaseline: CanvasTextBaseline = 'bottom';\r\n if (labelStats.maximumDescent > 0) {\r\n textBaseline = 'alphabetic';\r\n }\r\n let drawFont: string;\r\n if (webgl1Context) {\r\n let textureSize = getBinClampedSize(textWidth, totalCanvasHeight, 'ceil');\r\n if (textureSize > 2048) {\r\n textureSize = 2048;\r\n }\r\n dynamicTexture.scaleTo(textureSize, textureSize);\r\n ctx.scale(textureSize / textWidth, textureSize / totalCanvasHeight);\r\n drawFont = TEXT_RESOLUTION + 'px ' + fontFamily;\r\n } else {\r\n dynamicTexture.scaleTo(textWidth, totalCanvasHeight);\r\n drawFont = TEXT_RESOLUTION + 'px ' + fontFamily;\r\n }\r\n ctx.font = drawFont;\r\n if (ctx instanceof CanvasRenderingContext2D) {\r\n ctx.textBaseline = textBaseline;\r\n }\r\n ctx.fillStyle = textColor.toHexString();\r\n\r\n let drawHeight = totalCanvasHeight;\r\n for (let i = 0; i < labelArray.length; i++) {\r\n const lineWidth = lineWidths[i];\r\n //ctx.fillStyle = 'rgb(132,244,235, 0.3)';\r\n //ctx.fillRect(0, 0, textWidth, (textHeight + textGap) * labelArray.length - textGap);\r\n //rightAllign\r\n if (node.horizontalTextAlign === 'right') {\r\n ctx.fillText(labelArray[i], textWidth - lineWidth, drawHeight - labelStats.maximumDescent);\r\n }\r\n //leftAllign\r\n else if (node.horizontalTextAlign === 'left') {\r\n ctx.fillText(labelArray[i], 0, drawHeight - labelStats.maximumDescent);\r\n } else {\r\n //centered:\r\n ctx.fillText(labelArray[i], textWidth / 2 - lineWidth / 2, drawHeight - labelStats.maximumDescent);\r\n }\r\n drawHeight = drawHeight - textHeight - textGap;\r\n }\r\n // reset the context\r\n ctx.setTransform(1, 0, 0, 1, 0, 0);\r\n dynamicTexture.update(true);\r\n}\r\n\r\nexport function getPositionFromConnnector(\r\n targetNode: Connector,\r\n rendererManager: RendererManager,\r\n relativeToScene: SceneNode | undefined\r\n) {\r\n const targetMesh = rendererManager.connector.get3d(targetNode);\r\n if (targetMesh) {\r\n targetMesh.computeWorldMatrix(true);\r\n const result = targetMesh.absolutePosition.clone();\r\n\r\n if (relativeToScene) {\r\n const sceneMesh = rendererManager.viewer.getRendererNode(relativeToScene);\r\n if (sceneMesh) {\r\n // console.log('pre', newPosition, newDirection, newAngle);\r\n const transform = sceneMesh.getWorldMatrix().clone();\r\n transform.invert();\r\n return Vector3.TransformCoordinates(result, transform);\r\n }\r\n }\r\n return result;\r\n }\r\n return Vector3.Zero();\r\n}\r\n\r\nexport function calculateTransform(\r\n position: Vector3,\r\n direction: Vector3,\r\n angle: number,\r\n offset?: Vector3,\r\n lineOffset?: Vector3\r\n) {\r\n const newPosition = position.clone();\r\n const newRotation = rotationToVector(direction);\r\n const textRotation = Quaternion.RotationAxis(Vector3.Up(), (angle - 90) * (Math.PI / 180));\r\n let offsetWithTransform: Vector3 | undefined;\r\n let lineOffsetWithTransform: Vector3 | undefined;\r\n\r\n if (offset) {\r\n offsetWithTransform = transformVectorWithQuat(offset, newRotation);\r\n newPosition.addInPlace(offsetWithTransform);\r\n }\r\n\r\n if (lineOffset) {\r\n lineOffsetWithTransform = transformVectorWithQuat(lineOffset, newRotation);\r\n }\r\n\r\n return {\r\n position: newPosition,\r\n rotation: newRotation,\r\n textRotation: textRotation,\r\n offset: offsetWithTransform,\r\n lineOffset: lineOffsetWithTransform,\r\n };\r\n}\r\n\r\nexport function drawLine(\r\n node: AnnotationNode,\r\n lineInfo: AnnotationParts['line'],\r\n lineLength: number,\r\n scene: Scene,\r\n distance?: number\r\n) {\r\n if (lineInfo && node.lineStyle !== eAnnotationLineStyle.none) {\r\n let linesMesh: LinesMesh;\r\n if (node.lineStyle === eAnnotationLineStyle.solid) {\r\n linesMesh = MeshBuilder.CreateLines(`${node._dynamicId}_line`, lineInfo, scene);\r\n } else {\r\n lineInfo.dashNb = lineLength * 30;\r\n if (node.lineStyle === eAnnotationLineStyle.dashed) {\r\n lineInfo.gapSize = 4;\r\n lineInfo.dashSize = 6;\r\n if (distance) {\r\n // lineInfo.gapSize *= distance;\r\n // lineInfo.dashSize *= distance;\r\n lineInfo.dashNb = (lineInfo.dashNb / distance) * 1.5;\r\n }\r\n } else {\r\n lineInfo.gapSize = 6;\r\n lineInfo.dashSize = 1;\r\n }\r\n linesMesh = MeshBuilder.CreateDashedLines(`${node._dynamicId}_line`, lineInfo, scene);\r\n linesMesh.color = node.color.toColor3();\r\n }\r\n lineInfo.instance = linesMesh;\r\n lineInfo.instance.isPickable = false;\r\n\r\n return linesMesh;\r\n }\r\n}\r\n\r\nfunction evalHandlebarString(label: string, values: any) {\r\n if (!label.match(/\\{.*\\}/)) {\r\n return label;\r\n }\r\n const array = label.matchAll(/\\{([\\d\\w+\\-*/]+)\\}/g);\r\n let exp = array.next();\r\n while (!exp.done) {\r\n let mathExp = exp.value[1];\r\n for (const key in values) {\r\n mathExp = mathExp.replace(key, values[key]);\r\n }\r\n if (mathExp.match(/\\d/)) {\r\n // Strip all invalid math expression characters\r\n mathExp = mathExp.replace(/[^0-9.+*/-]/g, '');\r\n const numberVal = mathEval(mathExp);\r\n label = label.replace(exp.value[0], roundToPlaces(numberVal, 0.01).toString(10));\r\n } else {\r\n label = label.replace(exp.value[0], mathExp);\r\n }\r\n exp = array.next();\r\n }\r\n\r\n return label;\r\n}\r\n\r\nfunction getMultiLineStats(label: string, ctx: CanvasRenderingContext2D) {\r\n // 402 is a florin and 96 is a backtick, generally the tallest and highest characters.\r\n const fullStringTextSize = ctx.measureText(label + String.fromCharCode(402, 71, 95, 96, 103));\r\n\r\n const substrings: string[] = label.split('\\\\n').map(label => label.trim());\r\n const lineWidths: number[] = [];\r\n let maximumWidth = 0;\r\n let maximumHeight = 0;\r\n let maximumDescent = 0;\r\n substrings.forEach(string => {\r\n if (string.length > maximumWidth) {\r\n maximumWidth = string.length;\r\n }\r\n const textSize = ctx.measureText(string);\r\n\r\n if (textSize.actualBoundingBoxLeft !== undefined && textSize.actualBoundingBoxRight !== undefined) {\r\n const textWidth = Math.abs(textSize.actualBoundingBoxLeft) + Math.abs(textSize.actualBoundingBoxRight);\r\n if (textWidth > maximumWidth) {\r\n maximumWidth = textWidth;\r\n }\r\n lineWidths.push(textWidth);\r\n } else {\r\n if (textSize.width > maximumWidth) {\r\n maximumWidth = textSize.width;\r\n }\r\n lineWidths.push(textSize.width);\r\n }\r\n });\r\n\r\n // The render puppetteer browser does not have fontBoundingBoxAscent or Descent.\r\n // That would be a better way to measure text for consistency. When upgrading puppeteer see if we can use fontBoundingBoxAscent\r\n if (\r\n fullStringTextSize.actualBoundingBoxAscent !== undefined &&\r\n fullStringTextSize.actualBoundingBoxDescent !== undefined\r\n ) {\r\n maximumHeight =\r\n Math.abs(fullStringTextSize.actualBoundingBoxAscent) +\r\n Math.abs(fullStringTextSize.actualBoundingBoxDescent);\r\n maximumDescent = fullStringTextSize.actualBoundingBoxDescent;\r\n }\r\n\r\n if (maximumHeight === 0) {\r\n maximumHeight = TEXT_RESOLUTION;\r\n }\r\n\r\n const result = {\r\n labelArray: substrings,\r\n lineWidths,\r\n maximumHeight,\r\n maximumWidth,\r\n maximumDescent,\r\n };\r\n return result;\r\n}\r\n\r\nlet loopCount = 0;\r\nfunction mathEval(exp: string) {\r\n loopCount++;\r\n if (loopCount > 1000) {\r\n console.warn('escaped infinite loop in math evaluator');\r\n return NaN;\r\n }\r\n if (!exp.match(/\\D/)) {\r\n return parseFloat(exp);\r\n }\r\n\r\n let result: number;\r\n if (exp.match(/\\+/)) {\r\n const parts = exp.split('+').reverse();\r\n result = mathEval(parts.pop()!);\r\n while (parts.length > 0) {\r\n result += mathEval(parts.pop()!);\r\n }\r\n } else if (exp.match(/-/)) {\r\n const parts = exp.split('-').reverse();\r\n result = mathEval(parts.pop()!);\r\n while (parts.length > 0) {\r\n result -= mathEval(parts.pop()!);\r\n }\r\n } else if (exp.match(/\\*/)) {\r\n const parts = exp.split('*').reverse();\r\n result = mathEval(parts.pop()!);\r\n while (parts.length > 0) {\r\n result *= mathEval(parts.pop()!);\r\n }\r\n } else if (exp.match(/\\//)) {\r\n const parts = exp.split('/').reverse();\r\n result = mathEval(parts.pop()!);\r\n while (parts.length > 0) {\r\n result /= mathEval(parts.pop()!);\r\n }\r\n } else {\r\n result = parseFloat(exp);\r\n }\r\n\r\n return result;\r\n}\r\n","import { Color4, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport {\r\n DimensionNode,\r\n Kb3dObject,\r\n eAnnotationLineStyle,\r\n eDimensionAxis,\r\n eDimensionLineCapStyle,\r\n} from '@models/classes';\r\nimport { AnnotationNode } from '@models/classes/annotations/annotation-node';\r\nimport { Connector } from '@models/classes/features/connector';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { getCameraPositionWithOffset, rotationToVector, transformVectorWithQuat } from '@view/helpers/math-helper';\r\nimport { Subscription, merge } from 'rxjs';\r\nimport { AnnotationInfo } from '.';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport {\r\n AnnotationParts,\r\n ILineMeshOptions,\r\n calculateTransform,\r\n createAnnotationTextModels,\r\n drawLine,\r\n getPositionFromConnnector,\r\n updateAnnotationText,\r\n} from './annotation';\r\nimport { Renderer } from './renderer';\r\nimport { RendererManager } from './renderer-manager';\r\n\r\nexport interface ICapMeshOptions {\r\n lines: Vector3[][];\r\n updatable?: boolean;\r\n colors?: Color4[][];\r\n instance?: LinesMesh;\r\n}\r\n\r\ninterface DimensionParts extends AnnotationParts {\r\n line: ILineMeshOptions;\r\n lineCap: ICapMeshOptions;\r\n distance: number;\r\n}\r\n\r\nexport interface DimensionInfo extends AnnotationInfo {\r\n meshInfo?: DimensionParts;\r\n canCreate: boolean;\r\n boundingInfo?: {\r\n targetNode: Kb3dObject;\r\n targetNode2: Kb3dObject;\r\n subscription: Subscription;\r\n };\r\n}\r\n\r\n/**\r\n * Move line position calculation to private function so it can be called from bbSubscription\r\n * Move text font family creation stuff to common function and call it from here with midpoint of line\r\n * Store the line mesh in annotationStore, just recreate it from the private function when something changes\r\n */\r\n\r\nexport class DimensionRenderer extends Renderer {\r\n utilityLayer: UtilityLayerRenderer;\r\n modelToken = Token.DimensionNode;\r\n\r\n watchPosition = new Map<\r\n string,\r\n {\r\n node: ITrackedClass;\r\n containerMesh: TransformNode;\r\n targetNode: Kb3dObject;\r\n }\r\n >();\r\n dimensionStore = new Map();\r\n billboards = new Map();\r\n\r\n constructor(protected viewer: KbViewer, protected scene: Scene, protected rendererManager: RendererManager) {\r\n super(viewer, scene);\r\n this.utilityLayer = viewer.utilityLayer;\r\n scene.registerBeforeRender(() => {\r\n if (scene.activeCamera && this.dimensionStore.size > 0) {\r\n this.billboards.forEach(meshInfo => {\r\n const camera = scene.activeCamera!;\r\n meshInfo.rootMesh.lookAt(getCameraPositionWithOffset(camera), 0, Math.PI / 2);\r\n });\r\n }\r\n });\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n let dimensionInfo = this.dimensionStore.get(node._dynamicId);\r\n if (!dimensionInfo) {\r\n dimensionInfo = {\r\n positionNeedsUpdate: false,\r\n textNeedsUpdate: false,\r\n lineNeedsUpdate: false,\r\n canCreate: false,\r\n };\r\n this.dimensionStore.set(node._dynamicId, dimensionInfo);\r\n }\r\n\r\n const rootMesh = dimensionInfo.meshInfo?.rootMesh;\r\n if (rootMesh && node.scaleWithCamera) {\r\n if (!node.scaleWithCamera) {\r\n this.viewer.camera.clearMaintainedNodeScreenSize(rootMesh);\r\n } else {\r\n this.viewer.camera.maintainNodeScreenSize(rootMesh, (dist: number, mode: number) => {\r\n if (dimensionInfo && dimensionInfo.meshInfo && node.lineStyle === eAnnotationLineStyle.dashed) {\r\n this.updateLineFromCamera(node, dimensionInfo.meshInfo, scene, dist);\r\n }\r\n });\r\n }\r\n }\r\n\r\n if (dimensionInfo.meshInfo && node.changes.has('keepOnTop')) {\r\n this.delete3d(node, true);\r\n dimensionInfo.meshInfo = undefined;\r\n dimensionInfo.positionNeedsUpdate = true;\r\n dimensionInfo.textNeedsUpdate = true;\r\n dimensionInfo.lineNeedsUpdate = true;\r\n }\r\n const scene = node.keepOnTop ? this.utilityLayer.utilityLayerScene : this.scene;\r\n\r\n if (!dimensionInfo.meshInfo && node.enabled && node.targetId) {\r\n dimensionInfo.meshInfo = {\r\n ...createAnnotationTextModels(node, scene, this.viewer.options.editorMode),\r\n line: {\r\n points: [],\r\n colors: [],\r\n updatable: true,\r\n },\r\n lineCap: {\r\n lines: [],\r\n colors: [],\r\n updatable: true,\r\n },\r\n distance: 0,\r\n };\r\n\r\n // Put the dimensions on the parent scene so the scene visibility affects the node\r\n if (node._parentScene) {\r\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\r\n dimensionInfo.meshInfo.rootMesh.setParent(parentSceneMesh);\r\n }\r\n\r\n this.set3d(node, dimensionInfo.meshInfo.rootMesh);\r\n }\r\n const meshInfo = dimensionInfo.meshInfo;\r\n // Set position of annotation\r\n if (\r\n node.changes.hasAny(\r\n 'enabled',\r\n 'targetId',\r\n 'target2Id',\r\n 'offset',\r\n 'billboard',\r\n 'labelOffset',\r\n 'axis',\r\n 'dimensionGap'\r\n )\r\n ) {\r\n dimensionInfo.positionNeedsUpdate = true;\r\n }\r\n\r\n if (node.changes.hasAny('color', 'lineStyle', 'lineCapStyle')) {\r\n dimensionInfo.lineNeedsUpdate = true;\r\n }\r\n\r\n if (\r\n node.changes.hasAny(\r\n 'fontFamily',\r\n 'fontSize',\r\n 'label',\r\n 'color',\r\n 'targetId',\r\n 'target2Id',\r\n 'dimensionUnitPrecision'\r\n )\r\n ) {\r\n dimensionInfo.textNeedsUpdate = true;\r\n }\r\n\r\n if (meshInfo) {\r\n if (node.changes.hasAny('enabled', 'billboard', 'keepOnTop')) {\r\n if (node.enabled && node.billboard) {\r\n this.billboards.set(node._dynamicId, meshInfo);\r\n } else {\r\n this.billboards.delete(node._dynamicId);\r\n }\r\n }\r\n\r\n if (node.enabled) {\r\n if (dimensionInfo.positionNeedsUpdate || dimensionInfo.lineNeedsUpdate) {\r\n dimensionInfo.canCreate = this.updateDimensionControlPoints(node, dimensionInfo);\r\n\r\n // If the line is not getting rebuilt, then just update the line position\r\n if (dimensionInfo.canCreate && !dimensionInfo.lineNeedsUpdate) {\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\r\n meshInfo.lineCap.instance = MeshBuilder.CreateLineSystem(\r\n `${node._dynamicId}_lineCap`,\r\n meshInfo.lineCap,\r\n scene\r\n );\r\n }\r\n\r\n dimensionInfo.positionNeedsUpdate = false;\r\n }\r\n\r\n if (dimensionInfo.canCreate) {\r\n if (dimensionInfo.lineNeedsUpdate) {\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.dispose();\r\n delete meshInfo.line.instance;\r\n }\r\n if (meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance.dispose();\r\n delete meshInfo.lineCap.instance;\r\n }\r\n\r\n this.updateDimensionLineColor(node, meshInfo.line, meshInfo.lineCap);\r\n\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, meshInfo.distance, scene);\r\n\r\n if (node.lineCapStyle !== eDimensionLineCapStyle.none) {\r\n const lineCapsMesh = MeshBuilder.CreateLineSystem(\r\n `${node._dynamicId}_lineCap`,\r\n meshInfo.lineCap,\r\n scene\r\n );\r\n if (!meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance = lineCapsMesh;\r\n }\r\n }\r\n\r\n // Put the lines on the parent scene so they get it's visibility properties\r\n if (node._parentScene) {\r\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.parent = parentSceneMesh;\r\n }\r\n if (meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance.parent = parentSceneMesh;\r\n }\r\n }\r\n\r\n dimensionInfo.lineNeedsUpdate = false;\r\n }\r\n\r\n if (dimensionInfo.textNeedsUpdate) {\r\n let distanceDefaultVal: string;\r\n if (\r\n node._parentScene &&\r\n node._parentScene.dimensionUnitScalar &&\r\n node.dimensionUnitPrecision !== undefined\r\n ) {\r\n let distance = node._parentScene.dimensionUnitScalar * meshInfo.distance;\r\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\r\n distance =\r\n Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\r\n distanceDefaultVal = distance + (node._parentScene.dimensionUnitSymbol || '');\r\n } else {\r\n let distance = meshInfo.distance;\r\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\r\n distance =\r\n Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\r\n distanceDefaultVal = distance.toString(10);\r\n }\r\n updateAnnotationText(\r\n node,\r\n meshInfo.textMesh,\r\n meshInfo.textMaterial,\r\n this.scene.getEngine().webGLVersion < 2,\r\n distanceDefaultVal,\r\n { v: meshInfo.distance }\r\n );\r\n\r\n dimensionInfo.textNeedsUpdate = false;\r\n }\r\n }\r\n }\r\n\r\n if (meshInfo.rootMesh.isEnabled() !== node.enabled) {\r\n meshInfo.rootMesh.setEnabled(node.enabled);\r\n meshInfo.line.instance?.setEnabled(node.enabled);\r\n meshInfo.lineCap.instance?.setEnabled(node.enabled);\r\n }\r\n }\r\n }\r\n\r\n delete3d(node: ITrackedClass, keepInStore = false) {\r\n const dimensionModels = this.dimensionStore.get(node._dynamicId);\r\n if (dimensionModels?.meshInfo) {\r\n this.deleteLine(dimensionModels.meshInfo);\r\n }\r\n if (!keepInStore) {\r\n this.dimensionStore.delete(node._dynamicId);\r\n this.billboards.delete(node._dynamicId);\r\n }\r\n super.delete3d(node);\r\n }\r\n\r\n dispose() {\r\n this.billboards.clear();\r\n this.dimensionStore.clear();\r\n super.dispose();\r\n }\r\n\r\n private deleteLine(dimensionModels: DimensionParts) {\r\n if (dimensionModels.line.instance) {\r\n dimensionModels.line.instance.dispose();\r\n delete dimensionModels.line.instance;\r\n }\r\n if (dimensionModels.lineCap.instance) {\r\n dimensionModels.lineCap.instance.dispose();\r\n delete dimensionModels.lineCap.instance;\r\n }\r\n }\r\n\r\n private updateLine(\r\n dimensionInfo: DimensionInfo,\r\n node: ITrackedClass,\r\n meshInfo: DimensionParts,\r\n scene: Scene\r\n ) {\r\n dimensionInfo.canCreate = this.updateDimensionControlPoints(node, dimensionInfo);\r\n\r\n // If the line is not getting rebuilt, then just update the line position\r\n if (dimensionInfo.canCreate && !dimensionInfo.lineNeedsUpdate) {\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene);\r\n meshInfo.lineCap.instance = MeshBuilder.CreateLineSystem(\r\n `${node._dynamicId}_lineCap`,\r\n meshInfo.lineCap,\r\n scene\r\n );\r\n }\r\n\r\n dimensionInfo.positionNeedsUpdate = false;\r\n if (dimensionInfo.canCreate) {\r\n if (dimensionInfo.lineNeedsUpdate) {\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.dispose();\r\n delete meshInfo.line.instance;\r\n }\r\n if (meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance.dispose();\r\n delete meshInfo.lineCap.instance;\r\n }\r\n\r\n this.updateDimensionLineColor(node, meshInfo.line, meshInfo.lineCap);\r\n\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, meshInfo.distance, scene);\r\n\r\n if (node.lineCapStyle !== eDimensionLineCapStyle.none) {\r\n const lineCapsMesh = MeshBuilder.CreateLineSystem(\r\n `${node._dynamicId}_lineCap`,\r\n meshInfo.lineCap,\r\n scene\r\n );\r\n if (!meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance = lineCapsMesh;\r\n }\r\n }\r\n\r\n // Put the lines on the parent scene so they get it's visibility properties\r\n if (node._parentScene) {\r\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.parent = parentSceneMesh;\r\n }\r\n if (meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance.parent = parentSceneMesh;\r\n }\r\n }\r\n\r\n dimensionInfo.lineNeedsUpdate = false;\r\n }\r\n\r\n if (dimensionInfo.textNeedsUpdate) {\r\n let distanceDefaultVal: string;\r\n if (\r\n node._parentScene &&\r\n node._parentScene.dimensionUnitScalar &&\r\n node.dimensionUnitPrecision !== undefined\r\n ) {\r\n let distance = node._parentScene.dimensionUnitScalar * meshInfo.distance;\r\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\r\n distance = Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\r\n distanceDefaultVal = distance + (node._parentScene.dimensionUnitSymbol || '');\r\n } else {\r\n let distance = meshInfo.distance;\r\n const precisionMultiplier = Math.pow(10, Math.abs(node.dimensionUnitPrecision));\r\n distance = Math.round((distance + Number.EPSILON) * precisionMultiplier) / precisionMultiplier;\r\n distanceDefaultVal = distance.toString(10);\r\n }\r\n updateAnnotationText(\r\n node,\r\n meshInfo.textMesh,\r\n meshInfo.textMaterial,\r\n this.scene.getEngine().webGLVersion < 2,\r\n distanceDefaultVal,\r\n { v: meshInfo.distance }\r\n );\r\n\r\n dimensionInfo.textNeedsUpdate = false;\r\n }\r\n }\r\n }\r\n\r\n private updateLineFromCamera(\r\n node: ITrackedClass,\r\n meshInfo: DimensionParts,\r\n scene: Scene,\r\n distance: number\r\n ) {\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.dispose();\r\n delete meshInfo.line.instance;\r\n }\r\n\r\n this.updateDimensionLineColor(node, meshInfo.line, meshInfo.lineCap);\r\n\r\n meshInfo.line.instance = drawLine(node, meshInfo.line, 1, scene, distance); //CreateDashedLines('lines', meshInfo.line);\r\n if (node._parentScene) {\r\n const parentSceneMesh = this.viewer.getRendererNode(node._parentScene);\r\n if (meshInfo.line.instance) {\r\n meshInfo.line.instance.parent = parentSceneMesh;\r\n }\r\n if (meshInfo.lineCap.instance) {\r\n meshInfo.lineCap.instance.parent = parentSceneMesh;\r\n }\r\n }\r\n }\r\n\r\n private updateDimensionControlPoints(node: ITrackedClass, dimensionInfo: DimensionInfo) {\r\n if (!dimensionInfo.meshInfo) {\r\n return false;\r\n }\r\n const dimensionModel = dimensionInfo.meshInfo;\r\n\r\n const lineOptions = dimensionModel.line;\r\n const annotationMesh = dimensionModel.rootMesh;\r\n let target1: Kb3dObject | undefined;\r\n let target2: Kb3dObject | undefined;\r\n\r\n if (node.targetId && node.target2Id && node._manager) {\r\n const manager = node._manager;\r\n target1 = manager.getById(node.targetId);\r\n target2 = manager.getById(node.target2Id);\r\n }\r\n\r\n if (\r\n dimensionInfo.boundingInfo &&\r\n (dimensionInfo.boundingInfo.targetNode._dynamicId !== target1?._dynamicId ||\r\n dimensionInfo.boundingInfo.targetNode2._dynamicId !== target2?._dynamicId)\r\n ) {\r\n dimensionInfo.boundingInfo.subscription.unsubscribe();\r\n dimensionInfo.boundingInfo = undefined;\r\n }\r\n\r\n if (target1 && target2) {\r\n let position1: Vector3 | undefined;\r\n let position2: Vector3 | undefined;\r\n let direction: Vector3 | undefined;\r\n let angleAdjustment = 0;\r\n\r\n // Only supporting connectors for now, but could support direct mesh targets in the future\r\n if (target1 instanceof Connector && target2 instanceof Connector) {\r\n position1 = getPositionFromConnnector(target1, this.rendererManager, node._parentScene);\r\n position2 = getPositionFromConnnector(target2, this.rendererManager, node._parentScene);\r\n direction = target1.direction.toVec3().normalize();\r\n angleAdjustment = target1.angle;\r\n\r\n if (target1._parent && target2._parent) {\r\n dimensionInfo.boundingInfo = {\r\n targetNode: target1,\r\n targetNode2: target2,\r\n subscription: merge(\r\n this.viewer.bbCache.watchForChanges(target1._parent),\r\n this.viewer.bbCache.watchForChanges(target2._parent)\r\n ).subscribe(() => {\r\n node.setPropertyIsModified('targetId', true);\r\n node.setPropertyIsModified('target2Id', true);\r\n }),\r\n };\r\n }\r\n }\r\n\r\n if (position1 && position2 && direction) {\r\n /** Calculate the dimension line */\r\n const offset = node.offset.toVec3();\r\n const startConnector = calculateTransform(position1, direction, angleAdjustment, offset);\r\n const endConnector = calculateTransform(position2, direction, angleAdjustment, offset);\r\n const dimensionLine = endConnector.position.subtract(startConnector.position);\r\n const startPostion = startConnector.position;\r\n // Depending on the dimension axis, just use the\r\n let endPosition: Vector3;\r\n if (node.axis === eDimensionAxis.free) {\r\n endPosition = endConnector.position;\r\n } else {\r\n if (node.axis === eDimensionAxis.x) {\r\n endPosition = startPostion.add(dimensionLine.multiply(new Vector3(1, 0, 0)));\r\n } else if (node.axis === eDimensionAxis.y) {\r\n endPosition = startPostion.add(dimensionLine.multiply(new Vector3(0, 1, 0)));\r\n } else {\r\n endPosition = startPostion.add(dimensionLine.multiply(new Vector3(0, 0, 1)));\r\n }\r\n }\r\n const rectifiedDimensionLine = endPosition.subtract(startPostion);\r\n const lineDirectionCross = Vector3.Cross(rectifiedDimensionLine, direction).normalize();\r\n\r\n lineOptions.points = [startPostion, endPosition];\r\n dimensionModel.distance = rectifiedDimensionLine.length();\r\n annotationMesh.position = startPostion.add(endPosition).scaleInPlace(0.5);\r\n annotationMesh.position.addInPlace(\r\n transformVectorWithQuat(node.labelOffset.toVec3(), startConnector.rotation)\r\n );\r\n dimensionModel.textContainer.rotationQuaternion = startConnector.textRotation;\r\n\r\n if (!node.billboard) {\r\n annotationMesh.rotationQuaternion = rotationToVector(lineDirectionCross);\r\n }\r\n\r\n /** Calculate the line caps */\r\n const capSize = direction.scale(node.fontSize / 3);\r\n\r\n const lineToStartConnector = direction.scale(\r\n Vector3.Dot(transformVectorWithQuat(offset, startConnector.rotation), direction) *\r\n (1 - node.dimensionGap)\r\n );\r\n const endOffset =\r\n node.axis === eDimensionAxis.free\r\n ? transformVectorWithQuat(offset, startConnector.rotation)\r\n : endPosition.subtract(position2);\r\n const lineToEndConnector = direction.scale(Vector3.Dot(endOffset, direction) * (1 - node.dimensionGap));\r\n\r\n dimensionModel.lineCap.lines = [];\r\n if (node.lineCapStyle !== eDimensionLineCapStyle.none) {\r\n dimensionModel.lineCap.lines = [\r\n [startPostion.subtract(lineToStartConnector), startPostion, startPostion.add(capSize)],\r\n [endPosition.subtract(lineToEndConnector), endPosition, endPosition.add(capSize)],\r\n ];\r\n }\r\n if (node.lineCapStyle === eDimensionLineCapStyle.arrow) {\r\n const capArrowOffset = rectifiedDimensionLine.normalizeToNew().scaleInPlace(capSize.length());\r\n dimensionModel.lineCap.lines.push(\r\n [\r\n startPostion.subtract(capSize).addInPlace(capArrowOffset),\r\n startPostion,\r\n startPostion.add(capSize).addInPlace(capArrowOffset),\r\n ],\r\n [\r\n endPosition.subtract(capSize).subtractInPlace(capArrowOffset),\r\n endPosition,\r\n endPosition.add(capSize).subtractInPlace(capArrowOffset),\r\n ]\r\n );\r\n }\r\n\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private updateDimensionLineColor(\r\n node: ITrackedClass,\r\n lineOptions: ILineMeshOptions,\r\n lineCapOptions: ICapMeshOptions\r\n ) {\r\n const color = node.color.toColor4();\r\n lineOptions.colors = [];\r\n for (let i = 0; i < lineOptions.points.length; i++) {\r\n lineOptions.colors.push(color);\r\n }\r\n\r\n lineCapOptions.colors = [];\r\n for (let i = 0; i < 4; i++) {\r\n const lineColor: Color4[] = [];\r\n lineCapOptions.colors.push(lineColor);\r\n for (let j = 0; j < 3; j++) {\r\n lineColor.push(color);\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport function getDimensionLinePoints(node: DimensionNode, rendererManager: RendererManager) {\r\n if (node.targetId && node.target2Id && node._manager) {\r\n const manager = node._manager;\r\n const target1 = manager.getById(node.targetId);\r\n const target2 = manager.getById(node.target2Id);\r\n let position1: Vector3 | undefined;\r\n let position2: Vector3 | undefined;\r\n let direction: Vector3 | undefined;\r\n if (target1 instanceof Connector && target2 instanceof Connector) {\r\n position1 = getPositionFromConnnector(target1, rendererManager, node._parentScene);\r\n position2 = getPositionFromConnnector(target2, rendererManager, node._parentScene);\r\n direction = target1.direction.toVec3();\r\n }\r\n\r\n if (position1 && position2 && direction) {\r\n const lineStart = calculateTransform(position1, direction, 0, node.offset.toVec3());\r\n const lineEnd = calculateTransform(position2, direction, 0, node.offset.toVec3());\r\n return [lineStart.position, lineEnd.position];\r\n }\r\n }\r\n\r\n return undefined;\r\n}\r\n","import { Material } from '@babylonjs/core/Materials/material';\r\nimport { MultiMaterial } from '@babylonjs/core/Materials/multiMaterial';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Axis, Color3, Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { CreateCylinderVertexData } from '@babylonjs/core/Meshes/Builders/cylinderBuilder';\r\nimport { CreateSphereVertexData } from '@babylonjs/core/Meshes/Builders/sphereBuilder';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { SubMesh } from '@babylonjs/core/Meshes/subMesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { BaseConnector, Connector, IKbVectorLike, Kb3dObject, KbVector, SketchNode, instanceOf } from '@models/classes';\r\nimport { eAxis, eConnectorPositionMode } from '@models/classes/enums';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { IBoundingBox } from '@models/classes/primitives/primitive-utilities';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { BoundingBoxRelativeHelper } from '@view/helpers/bounding-box-relative-helper';\r\nimport { getRotationBtwVectors, toRadians } from '@view/helpers/math-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subscription } from 'rxjs';\r\nimport { Renderer } from '../renderer';\r\nimport { RendererManager } from '../renderer-manager';\r\n\r\nexport interface ConnectorParts {\r\n mesh: AbstractMesh;\r\n handleContainer?: TransformNode;\r\n handleBar?: LinesMesh;\r\n directionHandle1?: AbstractMesh;\r\n directionHandle2?: AbstractMesh;\r\n}\r\n\r\nexport const CONNECTOR_DIAM = 0.1;\r\n\r\nexport interface IConnectorLayer {\r\n template: Mesh | null;\r\n map: Map;\r\n scene: Scene;\r\n withArrows: boolean;\r\n visibility: number;\r\n pickable: boolean;\r\n parts: Map;\r\n}\r\n\r\nexport class ConnectorRenderer extends Renderer {\r\n protected layers = new Map<'real' | 'utility', IConnectorLayer>();\r\n protected subscriptionMap = new Map();\r\n\r\n protected readonly controlPointScaleRatio: number = 0.24;\r\n\r\n constructor(viewer: KbViewer, scene: Scene, protected rendererManager: RendererManager) {\r\n super(viewer, scene);\r\n\r\n this.layers.set('real', {\r\n template: null,\r\n map: this.babylonMap,\r\n scene,\r\n withArrows: !!viewer.options.editorMode,\r\n visibility: 1.0,\r\n pickable: !!viewer.options.editorMode,\r\n parts: new Map(),\r\n });\r\n this.layers.set('utility', {\r\n template: null,\r\n map: new Map(),\r\n scene: viewer.utilityLayer.utilityLayerScene,\r\n withArrows: !!viewer.options.editorMode,\r\n visibility: 0.3,\r\n pickable: false, // so utility layer doesn't steal the clicks\r\n parts: new Map(),\r\n });\r\n }\r\n modelToken = Token.Connector;\r\n protected connectorMaterial: Material;\r\n protected selectedMaterial: Material;\r\n\r\n public handlesNode(node: Kb3dObject): boolean {\r\n return instanceOf(node, Token.Connector);\r\n }\r\n\r\n update3dInternal(c: ITrackedClass, forceScreenScale = false) {\r\n /**\r\n * enabled, but not visible\r\n * enabled and visible\r\n * not enabled\r\n */\r\n const mesh = this.getMesh(c, this.layers.get('real')!);\r\n\r\n const realLayer = this.layers.get('real')!;\r\n const utilityLayer = this.layers.get('utility')!;\r\n const utilityMesh = this.getMesh(c, this.layers.get('utility')!);\r\n const realParts = realLayer.parts.get(c._dynamicId);\r\n const utilityParts = utilityLayer.parts.get(c._dynamicId);\r\n\r\n if (this.viewer.options.editorMode) {\r\n this.viewer.camera.maintainNodeScreenSize(mesh, dist => {\r\n const scaledSize = dist * this.controlPointScaleRatio;\r\n realParts?.mesh.scaling.set(scaledSize, scaledSize, scaledSize);\r\n realParts?.handleContainer?.scaling.set(1 / scaledSize, 1 / scaledSize, 1 / scaledSize);\r\n realParts?.directionHandle1?.scaling.set(scaledSize, scaledSize, scaledSize);\r\n realParts?.directionHandle2?.scaling.set(scaledSize, scaledSize, scaledSize);\r\n utilityParts?.mesh.scaling.set(scaledSize, scaledSize, scaledSize);\r\n utilityParts?.handleContainer?.scaling.set(1 / scaledSize, 1 / scaledSize, 1 / scaledSize);\r\n utilityParts?.directionHandle1?.scaling.set(scaledSize, scaledSize, scaledSize);\r\n utilityParts?.directionHandle2?.scaling.set(scaledSize, scaledSize, scaledSize);\r\n });\r\n }\r\n\r\n const changes = this.getChanges(c) as Map, any>;\r\n if (changes.has('_isPickable')) {\r\n mesh.isPickable = c._isPickable;\r\n }\r\n\r\n if (changes.has('positionZeroToOne') || changes.has('_sketchControlPoints')) {\r\n if (c.positionMode === eConnectorPositionMode.moveAlongSketch) {\r\n if (c instanceof Connector) {\r\n //this.updatePositionMoveAlongSketch(c);\r\n this.updatePosition(c);\r\n this.updateDirection(c);\r\n }\r\n }\r\n }\r\n\r\n if (changes.has('position') || changes.has('positionMode')) {\r\n const bb = c._parent instanceof SpaceNode ? this.viewer.bbCache.get(c._parent) : undefined;\r\n this.updatePosition(c, bb);\r\n /**\r\n * subscribe to bounding box changes of the parent to know that\r\n * we need to invalidate the position of the connector if applicable\r\n */\r\n if (changes.has('positionMode')) {\r\n if (c.positionMode == eConnectorPositionMode.boundingBox) {\r\n this.addSubscription(c);\r\n } else {\r\n this.removeSubscription(c);\r\n }\r\n }\r\n }\r\n\r\n if (changes.hasAny('direction', 'angle')) {\r\n this.updateDirection(c);\r\n this.updatePosition(c);\r\n }\r\n\r\n if (changes.hasAny('enabled', '_visible')) {\r\n if (c.enabled && c._visible) {\r\n mesh.setEnabled(true);\r\n utilityMesh.setEnabled(true);\r\n } else {\r\n mesh.setEnabled(false);\r\n utilityMesh.setEnabled(false);\r\n }\r\n }\r\n\r\n if (changes.has('_selected')) {\r\n if (c._selected) {\r\n mesh.material = this.getSelectedMaterial(this.layers.get('real')!.withArrows);\r\n } else {\r\n mesh.material = this.getConnectorMaterial(this.layers.get('real')!.withArrows);\r\n }\r\n utilityMesh.material = mesh.material;\r\n }\r\n\r\n return { mesh, utilityMesh };\r\n }\r\n\r\n protected addSubscription(c: ITrackedClass) {\r\n if (c._parent instanceof SpaceNode) {\r\n const mesh = c._parent;\r\n\r\n if (!this.subscriptionMap.has(c)) {\r\n this.subscriptionMap.set(\r\n c,\r\n this.viewer.bbCache.watchForChanges(mesh).subscribe(bbInfo => {\r\n c.setPropertyIsModified('position', true); // Trigger changes on mates and everything using that connector\r\n this.updatePosition(c, bbInfo);\r\n this.updateScale(c);\r\n })\r\n );\r\n }\r\n }\r\n }\r\n\r\n protected removeSubscription(c: T) {\r\n const s = this.subscriptionMap.get(c);\r\n if (s) {\r\n s.unsubscribe();\r\n this.subscriptionMap.delete(c);\r\n }\r\n }\r\n\r\n public updatePosition(c: T, bb?: IBoundingBox) {\r\n const mesh = this.getMesh(c, this.layers.get('real')!);\r\n const utilityMesh = this.getMesh(c, this.layers.get('utility')!);\r\n if (c.positionMode == eConnectorPositionMode.moveAlongSketch) {\r\n if (c instanceof Connector) {\r\n const newPosition = this.updatePositionMoveAlongSketch(c);\r\n if (newPosition) {\r\n mesh.position = utilityMesh.position = newPosition;\r\n }\r\n }\r\n } else if (c.positionMode == eConnectorPositionMode.absolute) {\r\n mesh.position = utilityMesh.position = c.position.toVec3();\r\n } else if (c.positionMode == eConnectorPositionMode.boundingBox) {\r\n if (!bb) {\r\n bb = c._parent instanceof SpaceNode ? this.viewer.bbCache.get(c._parent) : undefined;\r\n }\r\n if (bb) {\r\n mesh.position = BoundingBoxRelativeHelper.convertRelativeToAbsolute(c, bb);\r\n } else {\r\n mesh.position = new Vector3(c.position.x, c.position.y, c.position.z);\r\n }\r\n utilityMesh.position = mesh.position;\r\n }\r\n if (isTrackedClass(c)) {\r\n this.rendererManager.referenceProcessor.triggerChangesOnReferencers(c);\r\n }\r\n }\r\n\r\n public updateDirection(c: T) {\r\n const mesh = this.getMesh(c, this.layers.get('real')!);\r\n const utilityMesh = this.getMesh(c, this.layers.get('utility')!);\r\n if (c.positionMode === eConnectorPositionMode.moveAlongSketch) {\r\n if (c instanceof Connector) {\r\n let newDirection = this.updateDirectionMoveAlongSketch(c);\r\n if (newDirection) {\r\n newDirection = newDirection.normalize();\r\n\r\n if (c._parent instanceof SketchNode) {\r\n const normal = c._parent.normal;\r\n const normalVector = new Vector3(1, 0, 0);\r\n if (normal === eAxis.y) {\r\n normalVector.set(0, 1, 0);\r\n } else if (normal === eAxis.z) {\r\n normalVector.set(0, 0, 1);\r\n }\r\n if (mesh.parent instanceof TransformNode) {\r\n const connectorDirection = newDirection;\r\n const angleRot = Quaternion.RotationAxis(connectorDirection, toRadians(c.angle));\r\n const angleRotMatrix = new Matrix();\r\n angleRot.toRotationMatrix(angleRotMatrix);\r\n const parentDirection = Vector3.TransformCoordinates(normalVector, angleRotMatrix);\r\n const crossProduct = Vector3.Cross(connectorDirection, parentDirection);\r\n // prettier-ignore\r\n const matrix = Matrix.FromArray([connectorDirection.x, connectorDirection.y, connectorDirection.z, 0,\r\n parentDirection.x, parentDirection.y, parentDirection.z, 0,\r\n crossProduct.x, crossProduct.y, crossProduct.z, 0,\r\n 0, 0, 0, 1,\r\n ]);\r\n const newQuaternion = Quaternion.FromRotationMatrix(matrix);\r\n mesh.rotationQuaternion = utilityMesh.rotationQuaternion = newQuaternion;\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n /**\r\n * treat the positive x axis as the direction vector,\r\n * and the angle around that axis defined by the y axis.\r\n *\r\n * See Dragger.connect for a more in depth explanation\r\n */\r\n const deltaBtwXaxisAndDirection = getRotationBtwVectors(Axis.X, c.direction.toVec3().normalize());\r\n const angleRot = Quaternion.RotationAxis(Axis.X, toRadians(c.angle));\r\n mesh.rotationQuaternion = utilityMesh.rotationQuaternion = deltaBtwXaxisAndDirection.multiply(angleRot);\r\n }\r\n this.updateScale(c);\r\n }\r\n\r\n /**\r\n * connector meshes are children of their parent mesh, meaning they will scale\r\n * with any of their ancestor meshes or groups.\r\n * To counteract this we inverse their world scale.\r\n * WARNING! this technique does not work well when an ancestor has a non-uniform scale\r\n * @param c\r\n */\r\n public updateScale(c: T) {\r\n if (this.layers.get('real')!.map.get(c._dynamicId)) {\r\n //this could get called at any time, make sure the mesh already exists\r\n const mesh = this.getMesh(c, this.layers.get('real')!);\r\n const utilityMesh = this.getMesh(c, this.layers.get('utility')!);\r\n\r\n mesh.scaling = Vector3.One();\r\n mesh.computeWorldMatrix(true);\r\n\r\n if (mesh.parent instanceof TransformNode) {\r\n const worldScale = mesh.parent.absoluteScaling;\r\n\r\n const numerator = (this.viewer.sceneNode.connectorSize || CONNECTOR_DIAM) / CONNECTOR_DIAM;\r\n const transformMatrix = Matrix.Scaling(\r\n numerator / worldScale.x,\r\n numerator / worldScale.y,\r\n numerator / worldScale.z\r\n );\r\n mesh.setPreTransformMatrix(transformMatrix);\r\n utilityMesh.setPreTransformMatrix(transformMatrix);\r\n\r\n if (isTrackedClass(c)) {\r\n this.rendererManager.referenceProcessor.triggerChangesOnReferencers(c);\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected updatePositionMoveAlongSketch(connector: Connector) {\r\n const node = connector._parent;\r\n const result = new Vector3(0, 0, 0);\r\n if (node instanceof SketchNode) {\r\n const sketchLength = node.getSketchLength();\r\n const posZeroToOne = connector.positionZeroToOne;\r\n let trackedLength = 0;\r\n let targetNotFound = true;\r\n node.paths.forEach(path => {\r\n let lastPosition: IKbVectorLike | null = null;\r\n let lastLength = 0;\r\n path._points.forEach(point => {\r\n if (!lastPosition) {\r\n lastPosition = point;\r\n } else {\r\n const currentPos = point;\r\n const distance = Math.sqrt(\r\n Math.pow(lastPosition.x - currentPos.x, 2) +\r\n Math.pow(lastPosition.y - currentPos.y, 2) +\r\n Math.pow(lastPosition.z - currentPos.z, 2)\r\n );\r\n lastLength = trackedLength;\r\n trackedLength += distance;\r\n const distanceBetweenPoints = trackedLength - lastLength;\r\n const distanceFromP1toTarget = posZeroToOne * sketchLength - lastLength;\r\n const percentageBetween2Points = distanceFromP1toTarget / distanceBetweenPoints;\r\n const vectorBetween2Points = new KbVector(\r\n currentPos.x - lastPosition.x,\r\n currentPos.y - lastPosition.y,\r\n currentPos.z - lastPosition.z\r\n );\r\n if (trackedLength > posZeroToOne * sketchLength && targetNotFound) {\r\n const calculatedPosition = vectorBetween2Points\r\n .scale(percentageBetween2Points)\r\n .add(lastPosition);\r\n result.set(calculatedPosition.x, calculatedPosition.y, calculatedPosition.z);\r\n targetNotFound = false;\r\n }\r\n lastPosition = currentPos;\r\n }\r\n });\r\n if (posZeroToOne === 1) {\r\n const path = node.paths[node.paths.length - 1];\r\n const controlPoint = path._points[path._points.length - 1];\r\n result.set(controlPoint.x, controlPoint.y, controlPoint.z);\r\n }\r\n });\r\n }\r\n return result;\r\n }\r\n\r\n protected updateDirectionMoveAlongSketch(connector: Connector) {\r\n const node = connector._parent;\r\n const result = new Vector3(0, 0, 0);\r\n if (node instanceof SketchNode) {\r\n const sketchLength = node.getSketchLength();\r\n const posZeroToOne = connector.positionZeroToOne;\r\n let trackedLength = 0;\r\n\r\n let targetNotFound = true;\r\n let lastPathVector: KbVector | null = null;\r\n let nextPathVector: KbVector | null = null;\r\n node.paths.forEach(path => {\r\n let lastPosition: IKbVectorLike | null = null;\r\n let lastLength = 0;\r\n path._points.forEach(point => {\r\n if (!lastPosition) {\r\n lastPosition = point;\r\n } else {\r\n const currentPos = point;\r\n if (lastPosition) {\r\n const index = path._points.indexOf(lastPosition) + 1;\r\n const index2 = index + 1;\r\n if (index !== path._points.length) {\r\n const nextPosition = path._points[index];\r\n if (index2 !== path._points.length) {\r\n const nextNextPosition = path._points[index2];\r\n nextPathVector = new KbVector(\r\n nextNextPosition.x - nextPosition.x,\r\n nextNextPosition.y - nextPosition.y,\r\n nextNextPosition.z - nextPosition.z\r\n ).normalize();\r\n }\r\n }\r\n }\r\n const distance = Math.sqrt(\r\n Math.pow(lastPosition.x - currentPos.x, 2) +\r\n Math.pow(lastPosition.y - currentPos.y, 2) +\r\n Math.pow(lastPosition.z - currentPos.z, 2)\r\n );\r\n lastLength = trackedLength;\r\n trackedLength += distance;\r\n const distanceBetweenPoints = trackedLength - lastLength;\r\n const distanceFromP1toTarget = posZeroToOne * sketchLength - lastLength;\r\n const percentageBetween2Points = distanceFromP1toTarget / distanceBetweenPoints;\r\n const vectorBetween2Points = new KbVector(\r\n currentPos.x - lastPosition.x,\r\n currentPos.y - lastPosition.y,\r\n currentPos.z - lastPosition.z\r\n );\r\n if (trackedLength > posZeroToOne * sketchLength && targetNotFound) {\r\n let calculatedDirection = null;\r\n if (!connector.interpolateDirection) {\r\n calculatedDirection = vectorBetween2Points.normalize();\r\n } else {\r\n if (!lastPathVector) {\r\n if (nextPathVector) {\r\n calculatedDirection = vectorBetween2Points\r\n .normalize()\r\n .scale(1 - percentageBetween2Points)\r\n .add(\r\n nextPathVector\r\n .normalize()\r\n .add(vectorBetween2Points.normalize())\r\n .normalize()\r\n .scale(percentageBetween2Points)\r\n )\r\n .normalize();\r\n } else {\r\n calculatedDirection = vectorBetween2Points.normalize();\r\n }\r\n } else if (!nextPathVector) {\r\n calculatedDirection = lastPathVector\r\n .scale(1 - percentageBetween2Points)\r\n .add(vectorBetween2Points.scale(1 + percentageBetween2Points))\r\n .scale(1 / 2)\r\n .normalize();\r\n } else {\r\n if (percentageBetween2Points <= 0.5) {\r\n calculatedDirection = lastPathVector\r\n .normalize()\r\n .add(vectorBetween2Points.normalize())\r\n .normalize()\r\n .scale(1 - percentageBetween2Points * 2)\r\n .add(vectorBetween2Points.scale(percentageBetween2Points * 2))\r\n .normalize();\r\n } else {\r\n calculatedDirection = vectorBetween2Points\r\n .normalize()\r\n .scale(1 - (percentageBetween2Points - 0.5) * 2)\r\n .add(\r\n nextPathVector\r\n .normalize()\r\n .add(vectorBetween2Points.normalize())\r\n .normalize()\r\n .scale((percentageBetween2Points - 0.5) * 2)\r\n )\r\n .normalize();\r\n }\r\n }\r\n }\r\n targetNotFound = false;\r\n result.set(calculatedDirection.x, calculatedDirection.y, calculatedDirection.z);\r\n }\r\n lastPathVector = vectorBetween2Points;\r\n lastPosition = currentPos;\r\n }\r\n });\r\n });\r\n if (posZeroToOne === 1) {\r\n if (posZeroToOne === 1) {\r\n const path = node.paths[node.paths.length - 1];\r\n const currentPos = path._points[path._points.length - 1];\r\n const lastPosition = path._points[path._points.length - 2];\r\n const vectorBetween2Points = new KbVector(\r\n currentPos.x - lastPosition.x,\r\n currentPos.y - lastPosition.y,\r\n currentPos.z - lastPosition.z\r\n ).normalize();\r\n result.set(vectorBetween2Points.x, vectorBetween2Points.y, vectorBetween2Points.z);\r\n }\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n protected getMesh(c: T, layer: IConnectorLayer) {\r\n let mesh = layer.map.get(c._dynamicId);\r\n if (!mesh) {\r\n if (!layer.template) {\r\n layer.template = this.createMeshTemplate(layer);\r\n }\r\n\r\n mesh = layer.template.clone(c._dynamicId); // layer.template.createInstance(c._dynamicId);\r\n mesh.id = c._dynamicId;\r\n\r\n const parentNode = c._parent;\r\n\r\n if (parentNode && parentNode instanceof SpaceNode) {\r\n const parent3d = this.viewer.getRendererNode(parentNode);\r\n if (parent3d) {\r\n mesh.setParent(parent3d);\r\n } else {\r\n console.warn(`mesh not found for ${parentNode.name}`);\r\n }\r\n }\r\n\r\n mesh.isPickable = layer.pickable;\r\n mesh.position = Vector3.Zero();\r\n mesh.rotationQuaternion = Quaternion.Identity();\r\n layer.map.set(c._dynamicId, mesh);\r\n layer.parts.set(c._dynamicId, {\r\n mesh,\r\n });\r\n }\r\n return mesh;\r\n }\r\n\r\n protected createMeshTemplate(layer: IConnectorLayer) {\r\n const ball = CreateSphereVertexData({\r\n segments: 8,\r\n diameter: CONNECTOR_DIAM,\r\n });\r\n\r\n if (layer.withArrows) {\r\n const arrowHead = CreateCylinderVertexData({\r\n diameterTop: 0,\r\n height: CONNECTOR_DIAM / 2,\r\n diameterBottom: CONNECTOR_DIAM / 4,\r\n tessellation: 6,\r\n });\r\n arrowHead.transform(\r\n Matrix.Compose(\r\n Vector3.One(),\r\n Quaternion.FromEulerAngles(Math.PI / 2, 0, 0),\r\n new Vector3(0, 0, CONNECTOR_DIAM * 1.75)\r\n )\r\n );\r\n\r\n const arrowShaft = CreateCylinderVertexData({\r\n diameterTop: CONNECTOR_DIAM / 10,\r\n height: CONNECTOR_DIAM,\r\n diameterBottom: CONNECTOR_DIAM / 10,\r\n tessellation: 6,\r\n });\r\n\r\n arrowShaft.transform(\r\n Matrix.Compose(\r\n Vector3.One(),\r\n Quaternion.FromEulerAngles(Math.PI / 2, 0, 0),\r\n new Vector3(0, 0, CONNECTOR_DIAM)\r\n )\r\n );\r\n\r\n ball.merge(arrowHead).merge(arrowShaft);\r\n }\r\n\r\n const mesh = new Mesh('', layer.scene);\r\n ball.applyToMesh(mesh, false); //updateable false\r\n\r\n if (layer.withArrows) {\r\n //let ballHalf1 = new SubMesh(0, 0, 231, 0, 600, mesh);\r\n new SubMesh(1, 0, 231, 0, 600, mesh); // ball half 2\r\n }\r\n\r\n mesh.rotation.y = Math.PI / 2;\r\n mesh.bakeCurrentTransformIntoVertices();\r\n mesh.position = Vector3.Zero();\r\n mesh.material = this.getConnectorMaterial(layer.withArrows);\r\n mesh.visibility = layer.visibility;\r\n mesh.setEnabled(false);\r\n return mesh;\r\n }\r\n\r\n public delete3d(c: ITrackedClass) {\r\n const utilityLayer = this.layers.get('utility')!;\r\n const utilityMesh = utilityLayer.map.get(c._dynamicId);\r\n if (utilityMesh) {\r\n utilityMesh.dispose();\r\n utilityLayer.map.delete(c._dynamicId);\r\n }\r\n\r\n this.removeSubscription(c);\r\n super.delete3d(c);\r\n }\r\n\r\n protected getConnectorMaterial(twoTone: boolean) {\r\n if (!this.connectorMaterial) {\r\n if (twoTone) {\r\n const m1 = new StandardMaterial('connectorMaterial0', this.scene);\r\n m1.emissiveColor = KbColor.KbmaxOrange().toColor3();\r\n m1.disableLighting = true;\r\n\r\n const m2 = new StandardMaterial('connectorMaterial1', this.scene);\r\n m2.emissiveColor = new Color3(0, 101 / 255, 1); //new Color3(226/255, 101/255, 29/255);// KbColor.KbmaxBlue().toColor3();\r\n m2.disableLighting = true;\r\n\r\n const m = new MultiMaterial('connectorMaterial', this.scene);\r\n m.subMaterials.push(m1, m2);\r\n this.connectorMaterial = m;\r\n } else {\r\n const m = new StandardMaterial('connectorMaterial', this.scene);\r\n m.emissiveColor = this.viewer.highlightColor.toColor3();\r\n m.disableLighting = true;\r\n this.connectorMaterial = m;\r\n }\r\n }\r\n return this.connectorMaterial;\r\n }\r\n\r\n protected getSelectedMaterial(withArrows: boolean) {\r\n if (!this.selectedMaterial) {\r\n this.selectedMaterial = this.getConnectorMaterial(withArrows);\r\n if (withArrows) {\r\n const m1 = new StandardMaterial('connectorSelectedMaterial0', this.scene);\r\n m1.emissiveColor = new Color3(254 / 255, 233 / 255, 7 / 255);\r\n m1.disableLighting = true;\r\n\r\n const m2 = new StandardMaterial('connectorSelectedMaterial1', this.scene);\r\n m2.emissiveColor = new Color3(2 / 255, 251 / 255, 248 / 255);\r\n m2.disableLighting = true;\r\n\r\n const m = new MultiMaterial('connectorSelectedMaterial', this.scene);\r\n m.subMaterials.push(m1, m2);\r\n this.selectedMaterial = m;\r\n } else {\r\n const m = new StandardMaterial('connectorSelectedMaterial', this.scene);\r\n m.emissiveColor = this.viewer.options.highlightColor!.toColor3();\r\n m.disableLighting = true;\r\n this.selectedMaterial = m;\r\n }\r\n }\r\n return this.selectedMaterial;\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n\r\n for (const [, layer] of this.layers) {\r\n if (layer.template) {\r\n layer.template.dispose();\r\n }\r\n layer.map.clear();\r\n }\r\n if (this.connectorMaterial) {\r\n this.connectorMaterial.dispose();\r\n }\r\n }\r\n}\r\n","import { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { eMeshChangeTypes, Feature } from '@models/classes/features/feature';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SyncService } from '@models/services/sync-service';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { Renderer } from '../renderer';\r\n\r\nexport abstract class FeatureRenderer extends Renderer {\r\n vertexDataCache = new Map>();\r\n\r\n public updateMeshGeometryCache(\r\n feature: T,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ): Partial {\r\n const self = this;\r\n const newVertexData: Partial = {};\r\n\r\n // Grab the properties in the mesh vertex that are needed for the feature\r\n // Only swap out the properties in the old vertex data with the stored copy if they have NOT been affected by another vertex\r\n if (feature.affectedBy) {\r\n const cachedData = this.vertexDataCache.get(feature._dynamicId);\r\n feature.affectedBy.forEach(affectedBy => {\r\n if (affectedBy === eMeshChangeTypes.VertexIndices) {\r\n if (vertexDataChanges.indices === null) {\r\n newVertexData.indices = null;\r\n clearVertexDataCache('indices');\r\n } else if (vertexDataChanges.indices) {\r\n newVertexData.indices = vertexDataChanges.indices.slice();\r\n updateVertexDataCache('indices', vertexDataChanges.indices);\r\n } else if (cachedData) {\r\n newVertexData.indices = cachedData.indices?.slice() as any;\r\n } else {\r\n newVertexData.indices = vertexData.indices!.slice();\r\n updateVertexDataCache('indices', vertexData.indices);\r\n }\r\n\r\n if (vertexDataChanges.paths === null) {\r\n newVertexData.paths = null;\r\n clearVertexDataCache('paths');\r\n } else if (vertexDataChanges.paths) {\r\n newVertexData.paths = vertexDataChanges.paths.slice();\r\n updateVertexDataCache('paths', vertexDataChanges.paths);\r\n } else if (cachedData) {\r\n newVertexData.paths = cachedData.paths?.slice() as any;\r\n } else {\r\n if (vertexData.paths) {\r\n newVertexData.paths = vertexData.paths.slice();\r\n updateVertexDataCache('paths', vertexData.paths);\r\n } else {\r\n newVertexData.paths = null;\r\n }\r\n }\r\n\r\n if (vertexDataChanges.holes === null) {\r\n newVertexData.holes = null;\r\n clearVertexDataCache('holes');\r\n } else if (vertexDataChanges.holes) {\r\n newVertexData.holes = vertexDataChanges.holes.slice();\r\n updateVertexDataCache('holes', vertexDataChanges.holes);\r\n } else if (cachedData) {\r\n newVertexData.holes = cachedData.holes?.slice() as any;\r\n } else {\r\n if (vertexData.holes) {\r\n newVertexData.holes = vertexData.holes.slice();\r\n updateVertexDataCache('holes', vertexData.holes);\r\n } else {\r\n newVertexData.holes = null;\r\n }\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.VertexPositions) {\r\n if (vertexDataChanges.positions === null) {\r\n newVertexData.positions = null;\r\n clearVertexDataCache('positions');\r\n } else if (vertexDataChanges.positions) {\r\n newVertexData.positions = vertexDataChanges.positions.slice();\r\n updateVertexDataCache('positions', vertexDataChanges.positions);\r\n } else if (cachedData) {\r\n newVertexData.positions = cachedData.positions?.slice() as any; // compiler complains about the slice generic type for some reason\r\n } else {\r\n if (!vertexData.positions) {\r\n throw Error('Invalid geometry: positions is null');\r\n }\r\n newVertexData.positions = vertexData.positions.slice();\r\n updateVertexDataCache('positions', vertexData.positions);\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.VertexNormals) {\r\n if (vertexDataChanges.normals === null) {\r\n newVertexData.normals = null;\r\n clearVertexDataCache('normals');\r\n } else if (vertexDataChanges.normals) {\r\n newVertexData.normals = vertexDataChanges.normals.slice();\r\n updateVertexDataCache('normals', vertexDataChanges.normals);\r\n } else if (cachedData) {\r\n newVertexData.normals = cachedData.normals?.slice() as any;\r\n } else {\r\n if (vertexData.normals) {\r\n newVertexData.normals = vertexData.normals.slice();\r\n updateVertexDataCache('normals', vertexData.normals);\r\n } else {\r\n newVertexData.normals = null;\r\n }\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.VertexUvs) {\r\n if (vertexDataChanges.uvs === null) {\r\n newVertexData.uvs = null;\r\n clearVertexDataCache('uvs');\r\n } else if (vertexDataChanges.uvs) {\r\n newVertexData.uvs = vertexDataChanges.uvs.slice();\r\n updateVertexDataCache('uvs', vertexDataChanges.uvs);\r\n } else if (cachedData) {\r\n newVertexData.uvs = cachedData.uvs?.slice() as any;\r\n } else {\r\n if (vertexData.uvs) {\r\n newVertexData.uvs = vertexData.uvs.slice();\r\n updateVertexDataCache('uvs', vertexData.uvs);\r\n } else {\r\n newVertexData.uvs = null;\r\n }\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.Submeshes) {\r\n if (vertexDataChanges.submeshData === null) {\r\n newVertexData.submeshData = null;\r\n clearVertexDataCache('submeshData');\r\n } else if (vertexDataChanges.submeshData) {\r\n newVertexData.submeshData = JSON.parse(JSON.stringify(vertexDataChanges.submeshData));\r\n updateVertexDataCache('submeshData', JSON.parse(JSON.stringify(vertexDataChanges.submeshData)));\r\n } else if (cachedData) {\r\n const cachedSubmeshes = cachedData.submeshData;\r\n newVertexData.submeshData = cachedSubmeshes\r\n ? JSON.parse(JSON.stringify(cachedSubmeshes))\r\n : undefined;\r\n } else {\r\n if (vertexData.submeshData) {\r\n newVertexData.submeshData = JSON.parse(JSON.stringify(vertexData.submeshData));\r\n updateVertexDataCache('submeshData', JSON.parse(JSON.stringify(vertexData.submeshData)));\r\n } else {\r\n newVertexData.submeshData = null;\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n function clearVertexDataCache(prop: keyof SubmeshVertexData) {\r\n const vertexDataCache = self.vertexDataCache.get(feature._dynamicId);\r\n if (vertexDataCache) {\r\n delete vertexDataCache[prop];\r\n }\r\n }\r\n\r\n function updateVertexDataCache(prop: keyof SubmeshVertexData, value: any) {\r\n if (!value) {\r\n throw Error('invalid geometry does not have ' + prop);\r\n }\r\n\r\n let vertexDataCache = self.vertexDataCache.get(feature._dynamicId);\r\n if (!vertexDataCache) {\r\n vertexDataCache = {};\r\n self.vertexDataCache.set(feature._dynamicId, vertexDataCache);\r\n }\r\n\r\n if (typeof value.slice !== 'function') {\r\n throw Error('fixme: how do I clone this property?');\r\n }\r\n vertexDataCache[prop] = value.slice(); // Need to make sure everything is cloned when inserted into the cache\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n public updateMeshGeometry(\r\n feature: T,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ): Partial {\r\n return this.updateMeshGeometryCache(feature, vertexData, vertexDataChanges);\r\n }\r\n\r\n public delete3d(node: ITrackedClass, preserveCache?: boolean) {\r\n if (!preserveCache) {\r\n this.vertexDataCache.delete(node._dynamicId);\r\n }\r\n const t3d = this.get3d(node);\r\n if (t3d) {\r\n super.delete3d(node);\r\n } else {\r\n SyncService.nodeDeletionProcessed(node);\r\n }\r\n }\r\n\r\n public clearCache(features?: Feature[]) {\r\n if (features) {\r\n features.forEach(feature => {\r\n this.vertexDataCache.delete(feature._dynamicId);\r\n });\r\n } else {\r\n this.vertexDataCache.clear();\r\n }\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n this.clearCache();\r\n }\r\n}\r\n","import { Quaternion, Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { eFeatureCenter } from '@models/classes/enums';\r\nimport { MoveVerticesFeature } from '@models/classes/features/move-vertices-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nexport class MoveVerticesRenderer extends FeatureRenderer {\r\n modelToken = Token.MoveVerticesFeature;\r\n updateMeshGeometry(\r\n feature: MoveVerticesFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n const parentMesh = feature._parent;\r\n\r\n if (parentMesh && newVertexData.positions && newVertexData.positions.length > 0) {\r\n const newMeshVertexPositions = newVertexData.positions;\r\n if (feature.vertexIndices && feature.vertexIndices.length > 0) {\r\n let pivot: Vector3 | undefined;\r\n let rotationQuaternion: Quaternion | undefined;\r\n let scaleVector: Vector3 | undefined;\r\n\r\n if (feature.rotationAngle !== 0 && !feature.rotationAxis.equal({ x: 0, y: 0, z: 0 })) {\r\n rotationQuaternion = Quaternion.RotationAxis(\r\n feature.rotationAxis.toVec3(),\r\n (feature.rotationAngle / 180) * Math.PI\r\n );\r\n }\r\n if (!feature.scale.equal({ x: 1, y: 1, z: 1 })) {\r\n scaleVector = feature.scale.toVec3();\r\n }\r\n\r\n // Calculate vertex center if needed\r\n if (rotationQuaternion || scaleVector) {\r\n if (feature.center === eFeatureCenter.meshPivotPoint) {\r\n pivot = parentMesh.pivot.toVec3();\r\n } else {\r\n // Calculate vertices barycenter\r\n pivot = Vector3.Zero();\r\n const currentMeshVertexPositions = newVertexData.positions;\r\n if (currentMeshVertexPositions) {\r\n feature.vertexIndices.forEach(idx => {\r\n pivot!.x += currentMeshVertexPositions[idx * 3];\r\n pivot!.y += currentMeshVertexPositions[idx * 3 + 1];\r\n pivot!.z += currentMeshVertexPositions[idx * 3 + 2];\r\n });\r\n\r\n pivot.scaleInPlace(1 / feature.vertexIndices.length);\r\n }\r\n }\r\n }\r\n\r\n const vertexPosition = new Vector3();\r\n feature.vertexIndices.forEach(index => {\r\n newMeshVertexPositions[index * 3] += feature.translation.x;\r\n newMeshVertexPositions[index * 3 + 1] += feature.translation.y;\r\n newMeshVertexPositions[index * 3 + 2] += feature.translation.z;\r\n\r\n if (pivot && (rotationQuaternion || scaleVector)) {\r\n vertexPosition.copyFromFloats(\r\n newMeshVertexPositions[index * 3] - pivot.x,\r\n newMeshVertexPositions[index * 3 + 1] - pivot.y,\r\n newMeshVertexPositions[index * 3 + 2] - pivot.z\r\n );\r\n\r\n if (rotationQuaternion) {\r\n vertexPosition.rotateByQuaternionToRef(rotationQuaternion, vertexPosition);\r\n }\r\n\r\n if (scaleVector) {\r\n vertexPosition.multiplyInPlace(scaleVector);\r\n }\r\n\r\n vertexPosition.addInPlace(pivot);\r\n\r\n newMeshVertexPositions[index * 3] = vertexPosition.x;\r\n newMeshVertexPositions[index * 3 + 1] = vertexPosition.y;\r\n newMeshVertexPositions[index * 3 + 2] = vertexPosition.z;\r\n }\r\n });\r\n }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { SubmeshData } from '@models/classes';\r\nimport { NormalSmoothingFeature } from '@models/classes/features/normal-smoothing-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { addArrays } from '@view/helpers';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nexport class NormalSmoothingRenderer extends FeatureRenderer {\r\n modelToken = Token.NormalSmoothingFeature;\r\n vertexNeighbors = new Map();\r\n planeNormals = new Map();\r\n vectorA = new Vector3();\r\n vectorB = new Vector3();\r\n vectorC = new Vector3();\r\n normalVector = new Vector3();\r\n totalSelectedIndices = 0;\r\n updateMeshGeometry(\r\n feature: ITrackedClass,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n let vertexGroups = [];\r\n\r\n //if no faces are selected, select all faces to smooth entire mesh.\r\n if (feature.vertexGroups.length === 0 && newVertexData.indices) {\r\n for (let i = 0; i < newVertexData.indices.length; i += 6) {\r\n vertexGroups.push({ startIndex: i, endIndex: i + 6 });\r\n }\r\n } else {\r\n vertexGroups = feature.vertexGroups.sort((groupA, groupB) => groupA.startIndex - groupB.startIndex);\r\n }\r\n\r\n if (newVertexData.indices) {\r\n const planeNormal = new Vector3();\r\n let normals: number[];\r\n let positions: number[];\r\n let uvs: number[];\r\n let indices: number[];\r\n const newPositions: number[] = [];\r\n const newNormals: number[] = [];\r\n const newUvs: number[] = [];\r\n const submeshDataArray: SubmeshData[] = [];\r\n if (newVertexData.normals) {\r\n normals = newVertexData.normals as number[];\r\n } else if (vertexData.normals) {\r\n normals = Array.from(vertexData.normals) as number[];\r\n } else {\r\n normals = [];\r\n }\r\n\r\n if (newVertexData.positions) {\r\n positions = newVertexData.positions as number[];\r\n } else if (vertexData.positions) {\r\n positions = Array.from(vertexData.positions) as number[];\r\n } else {\r\n positions = [];\r\n }\r\n\r\n if (newVertexData.uvs) {\r\n uvs = newVertexData.uvs as number[];\r\n } else if (vertexData.uvs) {\r\n uvs = Array.from(vertexData.uvs) as number[];\r\n } else {\r\n uvs = [];\r\n }\r\n\r\n if (newVertexData.indices) {\r\n indices = newVertexData.indices as number[];\r\n } else if (vertexData.indices) {\r\n indices = Array.from(vertexData.indices) as number[];\r\n } else {\r\n indices = [];\r\n }\r\n\r\n this.vertexNeighbors.clear();\r\n this.planeNormals.clear();\r\n this.totalSelectedIndices = 0;\r\n vertexGroups.forEach(vertexGroup => {\r\n this.totalSelectedIndices += vertexGroup.endIndex - vertexGroup.startIndex;\r\n });\r\n\r\n if (feature.smooth) {\r\n //looping through the vertex groups and finding all the neighboring faces\r\n vertexGroups.forEach(vertexGroup => {\r\n const planeCoordinates = [];\r\n const planePositions = [];\r\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\r\n if (positions && indices) {\r\n let key = '';\r\n for (let j = 0; j < 3; j++) {\r\n const vertexIndex = indices[i];\r\n const coordinate = positions[vertexIndex * 3 + j];\r\n planePositions.push(coordinate);\r\n if (j == 2) {\r\n planeCoordinates.push([...planePositions]);\r\n planePositions.clear();\r\n }\r\n key += String(coordinate);\r\n }\r\n\r\n if (planeCoordinates.length == 3) {\r\n this.calculateNormalToRef(planeCoordinates, planeNormal);\r\n this.planeNormals.set(Math.floor(i / 3), planeNormal.asArray());\r\n planeCoordinates.clear();\r\n }\r\n\r\n let neighbor = this.vertexNeighbors.get(key);\r\n if (neighbor) {\r\n neighbor.push(i);\r\n this.vertexNeighbors.set(key, neighbor);\r\n } else {\r\n neighbor = [];\r\n neighbor.push(i);\r\n this.vertexNeighbors.set(key, neighbor);\r\n }\r\n }\r\n }\r\n });\r\n\r\n this.vertexNeighbors.forEach(position => {\r\n const newNormal = this.calculateSmoothedUnitVector(position);\r\n\r\n position.forEach(index => {\r\n if (normals && indices) {\r\n for (let i = 0; i < 3; i++) {\r\n normals[indices[index] * 3 + i] = newNormal[i];\r\n }\r\n }\r\n });\r\n });\r\n } else {\r\n //looping through the selected faces to get the face normals\r\n vertexGroups.forEach(vertexGroup => {\r\n const planeCoordinates = [];\r\n const planePositions = [];\r\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\r\n if (positions && indices) {\r\n for (let j = 0; j < 3; j++) {\r\n const vertexIndex = indices[i];\r\n const coordinate = positions[vertexIndex * 3 + j];\r\n planePositions.push(coordinate);\r\n if (j == 2) {\r\n planeCoordinates.push([...planePositions]);\r\n planePositions.clear();\r\n }\r\n }\r\n\r\n if (planeCoordinates.length == 3) {\r\n this.calculateNormalToRef(planeCoordinates, planeNormal);\r\n const planeNormalArray = this.calculateUnitVector(planeNormal.asArray());\r\n this.planeNormals.set(i, planeNormalArray);\r\n this.planeNormals.set(i - 1, planeNormalArray);\r\n this.planeNormals.set(i - 2, planeNormalArray);\r\n planeCoordinates.clear();\r\n }\r\n }\r\n }\r\n });\r\n\r\n //looping through it again to change/add the normals\r\n let totalVertices = 0;\r\n if (positions) {\r\n totalVertices = positions.length / 3;\r\n }\r\n const visitedVertices: boolean[] = [];\r\n vertexGroups.forEach(vertexGroup => {\r\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\r\n const vertex = indices[i];\r\n const planeNormal = this.planeNormals.get(i);\r\n const currentNormal: number[] = [];\r\n const currentPosition: number[] = [];\r\n const currentUv: number[] = [];\r\n\r\n for (let i = 0; i < 3; i++) {\r\n currentNormal.push(normals[vertex * 3 + i]);\r\n currentPosition.push(positions[vertex * 3 + i]);\r\n }\r\n for (let i = 0; i < 2; i++) {\r\n currentUv.push(uvs[vertex * 2 + i]);\r\n }\r\n\r\n //vertex is already visited, therefor we add a new one.\r\n //else: replace the existing vertex\r\n if (visitedVertices[vertex]) {\r\n for (let i = 0; i < 3; i++) {\r\n if (planeNormal) {\r\n newNormals.push(planeNormal[i]);\r\n newPositions.push(currentPosition[i]);\r\n }\r\n }\r\n for (let i = 0; i < 2; i++) {\r\n newUvs.push(currentUv[i]);\r\n }\r\n\r\n indices[i] = totalVertices;\r\n totalVertices += 1;\r\n\r\n //handling submesh data\r\n if (vertexData.submeshData) {\r\n for (let i = 0; i < vertexData.submeshData.length; i++) {\r\n const submeshData = vertexData.submeshData[i];\r\n if (\r\n submeshData.verticesStart <= vertex &&\r\n submeshData.verticesStart + submeshData.verticesCount > vertex\r\n ) {\r\n submeshData.verticesCount += 1;\r\n } else if (submeshData.verticesStart > vertex) {\r\n submeshData.verticesStart += 1;\r\n }\r\n submeshData.indexCount = (positions.length + newPositions.length) / 3;\r\n submeshDataArray[i] = submeshData;\r\n }\r\n }\r\n } else {\r\n visitedVertices[vertex] = true;\r\n if (planeNormal) {\r\n for (let i = 0; i < 3; i++) {\r\n normals[vertex * 3 + i] = planeNormal[i];\r\n }\r\n }\r\n }\r\n }\r\n });\r\n const resultPositions = new Float32Array(positions.length + newPositions.length);\r\n resultPositions.set(positions);\r\n resultPositions.set(newPositions, positions.length);\r\n const resultNormals = new Float32Array(normals.length + newNormals.length);\r\n resultNormals.set(normals);\r\n resultNormals.set(newNormals, normals.length);\r\n const resultUvs = new Float32Array(uvs.length + newUvs.length);\r\n resultUvs.set(uvs);\r\n resultUvs.set(newUvs, uvs.length);\r\n newVertexData.positions = resultPositions;\r\n newVertexData.normals = resultNormals;\r\n newVertexData.uvs = resultUvs;\r\n newVertexData.indices = indices;\r\n newVertexData.submeshData = submeshDataArray;\r\n }\r\n }\r\n this.viewer.updateNormalSmoothingWarnings(feature, this.totalSelectedIndices / 3, false);\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n\r\n public delete3d(node: ITrackedClass, preserveCache?: boolean | undefined): void {\r\n this.viewer.updateNormalSmoothingWarnings(node, 0, true);\r\n super.delete3d(node);\r\n }\r\n //Formula for normal of a plane: (vectorA-VectorB) x (VectorB-VectorC)\r\n calculateNormalToRef(coordinates: number[][], normalVector: Vector3) {\r\n Vector3.FromArrayToRef(coordinates[0], 0, this.vectorA);\r\n Vector3.FromArrayToRef(coordinates[1], 0, this.vectorB);\r\n Vector3.FromArrayToRef(coordinates[2], 0, this.vectorC);\r\n this.vectorA.subtractInPlace(this.vectorB);\r\n this.vectorB.subtractInPlace(this.vectorC);\r\n return Vector3.CrossToRef(this.vectorB, this.vectorA, normalVector);\r\n }\r\n\r\n calculateSmoothedUnitVector(vertices: number[]) {\r\n let result: number[] = [];\r\n vertices.forEach(vertex => {\r\n const normalVector = this.planeNormals.get(Math.floor(vertex / 3));\r\n if (normalVector) {\r\n result = addArrays(result, normalVector);\r\n }\r\n });\r\n return this.calculateUnitVector(result);\r\n }\r\n\r\n calculateUnitVector(vector: number[]) {\r\n let divider = 0;\r\n const result: number[] = [];\r\n vector.forEach(element => {\r\n divider += element * element;\r\n });\r\n divider = Math.sqrt(divider);\r\n vector.forEach(element => {\r\n result.push(element / divider);\r\n });\r\n return result;\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { Vector3, TmpVectors, Quaternion, Vector4, Vector2 } from \"../Maths/math.vector\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { BoundingInfo } from \"../Culling/boundingInfo\";\r\nimport { BoundingSphere } from \"../Culling/boundingSphere\";\r\nimport type { SolidParticleSystem } from \"./solidParticleSystem\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\nimport type { Material } from \"../Materials/material\";\r\n/**\r\n * Represents one particle of a solid particle system.\r\n */\r\nexport class SolidParticle {\r\n /**\r\n * particle global index\r\n */\r\n public idx: number = 0;\r\n /**\r\n * particle identifier\r\n */\r\n public id: number = 0;\r\n /**\r\n * The color of the particle\r\n */\r\n public color: Nullable = new Color4(1.0, 1.0, 1.0, 1.0);\r\n /**\r\n * The world space position of the particle.\r\n */\r\n public position: Vector3 = Vector3.Zero();\r\n /**\r\n * The world space rotation of the particle. (Not use if rotationQuaternion is set)\r\n */\r\n public rotation: Vector3 = Vector3.Zero();\r\n /**\r\n * The world space rotation quaternion of the particle.\r\n */\r\n public rotationQuaternion: Nullable;\r\n /**\r\n * The scaling of the particle.\r\n */\r\n public scaling: Vector3 = Vector3.One();\r\n /**\r\n * The uvs of the particle.\r\n */\r\n public uvs: Vector4 = new Vector4(0.0, 0.0, 1.0, 1.0);\r\n /**\r\n * The current speed of the particle.\r\n */\r\n public velocity: Vector3 = Vector3.Zero();\r\n /**\r\n * The pivot point in the particle local space.\r\n */\r\n public pivot: Vector3 = Vector3.Zero();\r\n /**\r\n * Must the particle be translated from its pivot point in its local space ?\r\n * In this case, the pivot point is set at the origin of the particle local space and the particle is translated.\r\n * Default : false\r\n */\r\n public translateFromPivot: boolean = false;\r\n /**\r\n * Is the particle active or not ?\r\n */\r\n public alive: boolean = true;\r\n /**\r\n * Is the particle visible or not ?\r\n */\r\n public isVisible: boolean = true;\r\n /**\r\n * Index of this particle in the global \"positions\" array (Internal use)\r\n * @internal\r\n */\r\n public _pos: number = 0;\r\n /**\r\n * @internal Index of this particle in the global \"indices\" array (Internal use)\r\n */\r\n public _ind: number = 0;\r\n /**\r\n * @internal ModelShape of this particle (Internal use)\r\n */\r\n public _model: ModelShape;\r\n /**\r\n * ModelShape id of this particle\r\n */\r\n public shapeId: number = 0;\r\n /**\r\n * Index of the particle in its shape id\r\n */\r\n public idxInShape: number = 0;\r\n /**\r\n * @internal Reference to the shape model BoundingInfo object (Internal use)\r\n */\r\n public _modelBoundingInfo: BoundingInfo;\r\n private _boundingInfo: BoundingInfo;\r\n /**\r\n * @internal Reference to the SPS what the particle belongs to (Internal use)\r\n */\r\n public _sps: SolidParticleSystem;\r\n /**\r\n * @internal Still set as invisible in order to skip useless computations (Internal use)\r\n */\r\n public _stillInvisible: boolean = false;\r\n /**\r\n * @internal Last computed particle rotation matrix\r\n */\r\n public _rotationMatrix: number[] = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];\r\n /**\r\n * Parent particle Id, if any.\r\n * Default null.\r\n */\r\n public parentId: Nullable = null;\r\n /**\r\n * The particle material identifier (integer) when MultiMaterials are enabled in the SPS.\r\n */\r\n public materialIndex: Nullable = null;\r\n /**\r\n * Custom object or properties.\r\n */\r\n public props: Nullable = null;\r\n /**\r\n * The culling strategy to use to check whether the solid particle must be culled or not when using isInFrustum().\r\n * The possible values are :\r\n * - AbstractMesh.CULLINGSTRATEGY_STANDARD\r\n * - AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\r\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\r\n * - AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\r\n * The default value for solid particles is AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\r\n * Please read each static variable documentation in the class AbstractMesh to get details about the culling process.\r\n * */\r\n public cullingStrategy = AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY;\r\n\r\n /**\r\n * @internal Internal global position in the SPS.\r\n */\r\n public _globalPosition: Vector3 = Vector3.Zero();\r\n\r\n /**\r\n * Particle BoundingInfo object\r\n * @returns a BoundingInfo\r\n */\r\n public getBoundingInfo(): BoundingInfo {\r\n return this._boundingInfo;\r\n }\r\n\r\n /**\r\n * Returns true if there is already a bounding info\r\n */\r\n public get hasBoundingInfo(): boolean {\r\n return this._boundingInfo !== null;\r\n }\r\n\r\n /**\r\n * Creates a Solid Particle object.\r\n * Don't create particles manually, use instead the Solid Particle System internal tools like _addParticle()\r\n * @param particleIndex (integer) is the particle index in the Solid Particle System pool.\r\n * @param particleId (integer) is the particle identifier. Unless some particles are removed from the SPS, it's the same value than the particle idx.\r\n * @param positionIndex (integer) is the starting index of the particle vertices in the SPS \"positions\" array.\r\n * @param indiceIndex (integer) is the starting index of the particle indices in the SPS \"indices\" array.\r\n * @param model (ModelShape) is a reference to the model shape on what the particle is designed.\r\n * @param shapeId (integer) is the model shape identifier in the SPS.\r\n * @param idxInShape (integer) is the index of the particle in the current model (ex: the 10th box of addShape(box, 30))\r\n * @param sps defines the sps it is associated to\r\n * @param modelBoundingInfo is the reference to the model BoundingInfo used for intersection computations.\r\n * @param materialIndex is the particle material identifier (integer) when the MultiMaterials are enabled in the SPS.\r\n */\r\n constructor(\r\n particleIndex: number,\r\n particleId: number,\r\n positionIndex: number,\r\n indiceIndex: number,\r\n model: Nullable,\r\n shapeId: number,\r\n idxInShape: number,\r\n sps: SolidParticleSystem,\r\n modelBoundingInfo: Nullable = null,\r\n materialIndex: Nullable = null\r\n ) {\r\n this.idx = particleIndex;\r\n this.id = particleId;\r\n this._pos = positionIndex;\r\n this._ind = indiceIndex;\r\n this._model = model;\r\n this.shapeId = shapeId;\r\n this.idxInShape = idxInShape;\r\n this._sps = sps;\r\n if (modelBoundingInfo) {\r\n this._modelBoundingInfo = modelBoundingInfo;\r\n this._boundingInfo = new BoundingInfo(modelBoundingInfo.minimum, modelBoundingInfo.maximum);\r\n }\r\n if (materialIndex !== null) {\r\n this.materialIndex = materialIndex;\r\n }\r\n }\r\n /**\r\n * Copies the particle property values into the existing target : position, rotation, scaling, uvs, colors, pivot, parent, visibility, alive\r\n * @param target the particle target\r\n * @returns the current particle\r\n */\r\n public copyToRef(target: SolidParticle): SolidParticle {\r\n target.position.copyFrom(this.position);\r\n target.rotation.copyFrom(this.rotation);\r\n if (this.rotationQuaternion) {\r\n if (target.rotationQuaternion) {\r\n target.rotationQuaternion!.copyFrom(this.rotationQuaternion!);\r\n } else {\r\n target.rotationQuaternion = this.rotationQuaternion.clone();\r\n }\r\n }\r\n target.scaling.copyFrom(this.scaling);\r\n if (this.color) {\r\n if (target.color) {\r\n target.color!.copyFrom(this.color!);\r\n } else {\r\n target.color = this.color.clone();\r\n }\r\n }\r\n target.uvs.copyFrom(this.uvs);\r\n target.velocity.copyFrom(this.velocity);\r\n target.pivot.copyFrom(this.pivot);\r\n target.translateFromPivot = this.translateFromPivot;\r\n target.alive = this.alive;\r\n target.isVisible = this.isVisible;\r\n target.parentId = this.parentId;\r\n target.cullingStrategy = this.cullingStrategy;\r\n if (this.materialIndex !== null) {\r\n target.materialIndex = this.materialIndex;\r\n }\r\n return this;\r\n }\r\n /**\r\n * Legacy support, changed scale to scaling\r\n */\r\n public get scale(): Vector3 {\r\n return this.scaling;\r\n }\r\n\r\n /**\r\n * Legacy support, changed scale to scaling\r\n */\r\n public set scale(scale: Vector3) {\r\n this.scaling = scale;\r\n }\r\n\r\n /**\r\n * Legacy support, changed quaternion to rotationQuaternion\r\n */\r\n public get quaternion(): Nullable {\r\n return this.rotationQuaternion;\r\n }\r\n\r\n /**\r\n * Legacy support, changed quaternion to rotationQuaternion\r\n */\r\n public set quaternion(q: Nullable) {\r\n this.rotationQuaternion = q;\r\n }\r\n\r\n /**\r\n * Returns a boolean. True if the particle intersects another particle or another mesh, else false.\r\n * The intersection is computed on the particle bounding sphere and Axis Aligned Bounding Box (AABB)\r\n * @param target is the object (solid particle or mesh) what the intersection is computed against.\r\n * @returns true if it intersects\r\n */\r\n public intersectsMesh(target: Mesh | SolidParticle): boolean {\r\n if (!this._boundingInfo || !target.hasBoundingInfo) {\r\n return false;\r\n }\r\n if (this._sps._bSphereOnly) {\r\n return BoundingSphere.Intersects(this._boundingInfo.boundingSphere, target.getBoundingInfo().boundingSphere);\r\n }\r\n return this._boundingInfo.intersects(target.getBoundingInfo(), false);\r\n }\r\n\r\n /**\r\n * Returns `true` if the solid particle is within the frustum defined by the passed array of planes.\r\n * A particle is in the frustum if its bounding box intersects the frustum\r\n * @param frustumPlanes defines the frustum to test\r\n * @returns true if the particle is in the frustum planes\r\n */\r\n public isInFrustum(frustumPlanes: Plane[]): boolean {\r\n return this._boundingInfo !== null && this._boundingInfo.isInFrustum(frustumPlanes, this.cullingStrategy);\r\n }\r\n\r\n /**\r\n * get the rotation matrix of the particle\r\n * @internal\r\n */\r\n public getRotationMatrix(m: Matrix) {\r\n let quaternion: Quaternion;\r\n if (this.rotationQuaternion) {\r\n quaternion = this.rotationQuaternion;\r\n } else {\r\n quaternion = TmpVectors.Quaternion[0];\r\n const rotation = this.rotation;\r\n Quaternion.RotationYawPitchRollToRef(rotation.y, rotation.x, rotation.z, quaternion);\r\n }\r\n\r\n quaternion.toRotationMatrix(m);\r\n }\r\n}\r\n\r\n/**\r\n * Represents the shape of the model used by one particle of a solid particle system.\r\n * SPS internal tool, don't use it manually.\r\n */\r\nexport class ModelShape {\r\n /**\r\n * Get or set the shapeId\r\n * @deprecated Please use shapeId instead\r\n */\r\n public get shapeID(): number {\r\n return this.shapeId;\r\n }\r\n public set shapeID(shapeID: number) {\r\n this.shapeId = shapeID;\r\n }\r\n /**\r\n * The shape id\r\n * @internal\r\n */\r\n public shapeId: number;\r\n /**\r\n * flat array of model positions (internal use)\r\n * @internal\r\n */\r\n public _shape: Vector3[];\r\n /**\r\n * flat array of model UVs (internal use)\r\n * @internal\r\n */\r\n public _shapeUV: number[];\r\n /**\r\n * color array of the model\r\n * @internal\r\n */\r\n public _shapeColors: number[];\r\n /**\r\n * indices array of the model\r\n * @internal\r\n */\r\n public _indices: number[];\r\n /**\r\n * normals array of the model\r\n * @internal\r\n */\r\n public _normals: number[];\r\n /**\r\n * length of the shape in the model indices array (internal use)\r\n * @internal\r\n */\r\n public _indicesLength: number = 0;\r\n /**\r\n * Custom position function (internal use)\r\n * @internal\r\n */\r\n public _positionFunction: Nullable<(particle: SolidParticle, i: number, s: number) => void>;\r\n /**\r\n * Custom vertex function (internal use)\r\n * @internal\r\n */\r\n public _vertexFunction: Nullable<(particle: SolidParticle, vertex: Vector3, i: number) => void>;\r\n /**\r\n * Model material (internal use)\r\n * @internal\r\n */\r\n public _material: Nullable;\r\n\r\n /**\r\n * Creates a ModelShape object. This is an internal simplified reference to a mesh used as for a model to replicate particles from by the SPS.\r\n * SPS internal tool, don't use it manually.\r\n * @internal\r\n */\r\n constructor(\r\n id: number,\r\n shape: Vector3[],\r\n indices: number[],\r\n normals: number[],\r\n colors: number[],\r\n shapeUV: number[],\r\n posFunction: Nullable<(particle: SolidParticle, i: number, s: number) => void>,\r\n vtxFunction: Nullable<(particle: SolidParticle, vertex: Vector3, i: number) => void>,\r\n material: Nullable\r\n ) {\r\n this.shapeId = id;\r\n this._shape = shape;\r\n this._indices = indices;\r\n this._indicesLength = indices.length;\r\n this._shapeUV = shapeUV;\r\n this._shapeColors = colors;\r\n this._normals = normals;\r\n this._positionFunction = posFunction;\r\n this._vertexFunction = vtxFunction;\r\n this._material = material;\r\n }\r\n}\r\n\r\n/**\r\n * Represents a Depth Sorted Particle in the solid particle system.\r\n * @internal\r\n */\r\nexport class DepthSortedParticle {\r\n /**\r\n * Particle index\r\n */\r\n public idx: number = 0;\r\n /**\r\n * Index of the particle in the \"indices\" array\r\n */\r\n public ind: number = 0;\r\n /**\r\n * Length of the particle shape in the \"indices\" array\r\n */\r\n public indicesLength: number = 0;\r\n /**\r\n * Squared distance from the particle to the camera\r\n */\r\n public sqDistance: number = 0.0;\r\n /**\r\n * Material index when used with MultiMaterials\r\n */\r\n public materialIndex: number = 0;\r\n\r\n /**\r\n * Creates a new sorted particle\r\n * @param idx\r\n * @param ind\r\n * @param indLength\r\n * @param materialIndex\r\n */\r\n constructor(idx: number, ind: number, indLength: number, materialIndex: number) {\r\n this.idx = idx;\r\n this.ind = ind;\r\n this.indicesLength = indLength;\r\n this.materialIndex = materialIndex;\r\n }\r\n}\r\n\r\n/**\r\n * Represents a solid particle vertex\r\n */\r\nexport class SolidParticleVertex {\r\n /**\r\n * Vertex position\r\n */\r\n public position: Vector3;\r\n /**\r\n * Vertex color\r\n */\r\n public color: Color4;\r\n /**\r\n * Vertex UV\r\n */\r\n public uv: Vector2;\r\n /**\r\n * Creates a new solid particle vertex\r\n */\r\n constructor() {\r\n this.position = Vector3.Zero();\r\n this.color = new Color4(1.0, 1.0, 1.0, 1.0);\r\n this.uv = Vector2.Zero();\r\n }\r\n // Getters and Setters for back-compatibility\r\n /** Vertex x coordinate */\r\n public get x(): number {\r\n return this.position.x;\r\n }\r\n public set x(val: number) {\r\n this.position.x = val;\r\n }\r\n /** Vertex y coordinate */\r\n public get y(): number {\r\n return this.position.y;\r\n }\r\n public set y(val: number) {\r\n this.position.y = val;\r\n }\r\n /** Vertex z coordinate */\r\n public get z(): number {\r\n return this.position.z;\r\n }\r\n public set z(val: number) {\r\n this.position.z = val;\r\n }\r\n}\r\n","import type { Nullable, IndicesArray, FloatArray } from \"../types\";\r\nimport { Vector3, Matrix, TmpVectors, Quaternion } from \"../Maths/math.vector\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { CreateDisc } from \"../Meshes/Builders/discBuilder\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { Scene, IDisposable } from \"../scene\";\r\nimport { DepthSortedParticle, SolidParticle, ModelShape, SolidParticleVertex } from \"./solidParticle\";\r\nimport type { TargetCamera } from \"../Cameras/targetCamera\";\r\nimport { BoundingInfo } from \"../Culling/boundingInfo\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\nimport { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport { StandardMaterial } from \"../Materials/standardMaterial\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport type { PickingInfo } from \"../Collisions/pickingInfo\";\r\n\r\n/**\r\n * The SPS is a single updatable mesh. The solid particles are simply separate parts or faces of this big mesh.\r\n *As it is just a mesh, the SPS has all the same properties than any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.\r\n\r\n * The SPS is also a particle system. It provides some methods to manage the particles.\r\n * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.\r\n *\r\n * Full documentation here : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_intro\r\n */\r\nexport class SolidParticleSystem implements IDisposable {\r\n /**\r\n * The SPS array of Solid Particle objects. Just access each particle as with any classic array.\r\n * Example : var p = SPS.particles[i];\r\n */\r\n public particles: SolidParticle[] = new Array();\r\n /**\r\n * The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.\r\n */\r\n public nbParticles: number = 0;\r\n /**\r\n * If the particles must ever face the camera (default false). Useful for planar particles.\r\n */\r\n public billboard: boolean = false;\r\n /**\r\n * Recompute normals when adding a shape\r\n */\r\n public recomputeNormals: boolean = false;\r\n /**\r\n * This a counter ofr your own usage. It's not set by any SPS functions.\r\n */\r\n public counter: number = 0;\r\n /**\r\n * The SPS name. This name is also given to the underlying mesh.\r\n */\r\n public name: string;\r\n /**\r\n * The SPS mesh. It's a standard BJS Mesh, so all the methods from the Mesh class are available.\r\n */\r\n public mesh: Mesh;\r\n /**\r\n * This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity.\r\n * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/optimize_sps#limit-garbage-collection\r\n */\r\n public vars: any = {};\r\n /**\r\n * This array is populated when the SPS is set as 'pickable'.\r\n * Each key of this array is a `faceId` value that you can get from a pickResult object.\r\n * Each element of this array is an object `{idx: int, faceId: int}`.\r\n * `idx` is the picked particle index in the `SPS.particles` array\r\n * `faceId` is the picked face index counted within this particle.\r\n * This array is the first element of the pickedBySubMesh array : sps.pickBySubMesh[0].\r\n * It's not pertinent to use it when using a SPS with the support for MultiMaterial enabled.\r\n * Use the method SPS.pickedParticle(pickingInfo) instead.\r\n * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/picking_sps\r\n */\r\n public pickedParticles: { idx: number; faceId: number }[];\r\n /**\r\n * This array is populated when the SPS is set as 'pickable'\r\n * Each key of this array is a submesh index.\r\n * Each element of this array is a second array defined like this :\r\n * Each key of this second array is a `faceId` value that you can get from a pickResult object.\r\n * Each element of this second array is an object `{idx: int, faceId: int}`.\r\n * `idx` is the picked particle index in the `SPS.particles` array\r\n * `faceId` is the picked face index counted within this particle.\r\n * It's better to use the method SPS.pickedParticle(pickingInfo) rather than using directly this array.\r\n * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/picking_sps\r\n */\r\n public pickedBySubMesh: { idx: number; faceId: number }[][];\r\n /**\r\n * This array is populated when `enableDepthSort` is set to true.\r\n * Each element of this array is an instance of the class DepthSortedParticle.\r\n */\r\n public depthSortedParticles: DepthSortedParticle[];\r\n\r\n /**\r\n * If the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster). (Internal use only)\r\n * @internal\r\n */\r\n public _bSphereOnly: boolean = false;\r\n /**\r\n * A number to multiply the bounding sphere radius by in order to reduce it for instance. (Internal use only)\r\n * @internal\r\n */\r\n public _bSphereRadiusFactor: number = 1.0;\r\n\r\n protected _scene: Scene;\r\n protected _positions: number[] = new Array();\r\n protected _indices: number[] = new Array();\r\n protected _normals: number[] = new Array();\r\n protected _colors: number[] = new Array();\r\n protected _uvs: number[] = new Array();\r\n protected _indices32: IndicesArray; // used as depth sorted array if depth sort enabled, else used as typed indices\r\n protected _positions32: Float32Array; // updated positions for the VBO\r\n protected _normals32: Float32Array; // updated normals for the VBO\r\n protected _fixedNormal32: Float32Array; // initial normal references\r\n protected _colors32: Float32Array;\r\n protected _uvs32: Float32Array;\r\n protected _index: number = 0; // indices index\r\n protected _updatable: boolean = true;\r\n protected _pickable: boolean = false;\r\n protected _isVisibilityBoxLocked = false;\r\n protected _alwaysVisible: boolean = false;\r\n protected _depthSort: boolean = false;\r\n protected _expandable: boolean = false;\r\n protected _shapeCounter: number = 0;\r\n protected _copy: SolidParticle = new SolidParticle(0, 0, 0, 0, null, 0, 0, this);\r\n protected _color: Color4 = new Color4(0, 0, 0, 0);\r\n protected _computeParticleColor: boolean = true;\r\n protected _computeParticleTexture: boolean = true;\r\n protected _computeParticleRotation: boolean = true;\r\n protected _computeParticleVertex: boolean = false;\r\n protected _computeBoundingBox: boolean = false;\r\n protected _autoFixFaceOrientation: boolean = false;\r\n protected _depthSortParticles: boolean = true;\r\n protected _camera: TargetCamera;\r\n protected _mustUnrotateFixedNormals = false;\r\n protected _particlesIntersect: boolean = false;\r\n protected _needs32Bits: boolean = false;\r\n protected _isNotBuilt: boolean = true;\r\n protected _lastParticleId: number = 0;\r\n protected _idxOfId: number[] = []; // array : key = particle.id / value = particle.idx\r\n protected _multimaterialEnabled: boolean = false;\r\n protected _useModelMaterial: boolean = false;\r\n protected _indicesByMaterial: number[];\r\n protected _materialIndexes: number[];\r\n protected _depthSortFunction = (p1: DepthSortedParticle, p2: DepthSortedParticle) => p2.sqDistance - p1.sqDistance;\r\n protected _materialSortFunction = (p1: DepthSortedParticle, p2: DepthSortedParticle) => p1.materialIndex - p2.materialIndex;\r\n protected _materials: Material[];\r\n protected _multimaterial: MultiMaterial;\r\n protected _materialIndexesById: any;\r\n protected _defaultMaterial: Material;\r\n protected _autoUpdateSubMeshes: boolean = false;\r\n protected _tmpVertex: SolidParticleVertex;\r\n protected _recomputeInvisibles: boolean = false;\r\n\r\n /**\r\n * Creates a SPS (Solid Particle System) object.\r\n * @param name (String) is the SPS name, this will be the underlying mesh name.\r\n * @param scene (Scene) is the scene in which the SPS is added.\r\n * @param options defines the options of the sps e.g.\r\n * * updatable (optional boolean, default true) : if the SPS must be updatable or immutable.\r\n * * isPickable (optional boolean, default false) : if the solid particles must be pickable.\r\n * * enableDepthSort (optional boolean, default false) : if the solid particles must be sorted in the geometry according to their distance to the camera.\r\n * * useModelMaterial (optional boolean, default false) : if the model materials must be used to create the SPS multimaterial. This enables the multimaterial supports of the SPS.\r\n * * enableMultiMaterial (optional boolean, default false) : if the solid particles can be given different materials.\r\n * * expandable (optional boolean, default false) : if particles can still be added after the initial SPS mesh creation.\r\n * * particleIntersection (optional boolean, default false) : if the solid particle intersections must be computed.\r\n * * boundingSphereOnly (optional boolean, default false) : if the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster).\r\n * * bSphereRadiusFactor (optional float, default 1.0) : a number to multiply the bounding sphere radius by in order to reduce it for instance.\r\n * * computeBoundingBox (optional boolean, default false): if the bounding box of the entire SPS will be computed (for occlusion detection, for example). If it is false, the bounding box will be the bounding box of the first particle.\r\n * * autoFixFaceOrientation (optional boolean, default false): if the particle face orientations will be flipped for transformations that change orientation (scale (-1, 1, 1), for example)\r\n * @param options.updatable\r\n * @param options.isPickable\r\n * @param options.enableDepthSort\r\n * @param options.particleIntersection\r\n * @param options.boundingSphereOnly\r\n * @param options.bSphereRadiusFactor\r\n * @param options.expandable\r\n * @param options.useModelMaterial\r\n * @param options.enableMultiMaterial\r\n * @param options.computeBoundingBox\r\n * @param options.autoFixFaceOrientation\r\n * @example bSphereRadiusFactor = 1.0 / Math.sqrt(3.0) => the bounding sphere exactly matches a spherical mesh.\r\n */\r\n constructor(\r\n name: string,\r\n scene: Scene,\r\n options?: {\r\n updatable?: boolean;\r\n isPickable?: boolean;\r\n enableDepthSort?: boolean;\r\n particleIntersection?: boolean;\r\n boundingSphereOnly?: boolean;\r\n bSphereRadiusFactor?: number;\r\n expandable?: boolean;\r\n useModelMaterial?: boolean;\r\n enableMultiMaterial?: boolean;\r\n computeBoundingBox?: boolean;\r\n autoFixFaceOrientation?: boolean;\r\n }\r\n ) {\r\n this.name = name;\r\n this._scene = scene || EngineStore.LastCreatedScene;\r\n this._camera = scene.activeCamera;\r\n this._pickable = options ? options.isPickable : false;\r\n this._depthSort = options ? options.enableDepthSort : false;\r\n this._multimaterialEnabled = options ? options.enableMultiMaterial : false;\r\n this._useModelMaterial = options ? options.useModelMaterial : false;\r\n this._multimaterialEnabled = this._useModelMaterial ? true : this._multimaterialEnabled;\r\n this._expandable = options ? options.expandable : false;\r\n this._particlesIntersect = options ? options.particleIntersection : false;\r\n this._bSphereOnly = options ? options.boundingSphereOnly : false;\r\n this._bSphereRadiusFactor = options && options.bSphereRadiusFactor ? options.bSphereRadiusFactor : 1.0;\r\n this._computeBoundingBox = options?.computeBoundingBox ? options.computeBoundingBox : false;\r\n this._autoFixFaceOrientation = options?.autoFixFaceOrientation ? options.autoFixFaceOrientation : false;\r\n if (options && options.updatable !== undefined) {\r\n this._updatable = options.updatable;\r\n } else {\r\n this._updatable = true;\r\n }\r\n if (this._pickable) {\r\n this.pickedBySubMesh = [[]];\r\n this.pickedParticles = this.pickedBySubMesh[0];\r\n }\r\n if (this._depthSort || this._multimaterialEnabled) {\r\n this.depthSortedParticles = [];\r\n }\r\n if (this._multimaterialEnabled) {\r\n this._multimaterial = new MultiMaterial(this.name + \"MultiMaterial\", this._scene);\r\n this._materials = [];\r\n this._materialIndexesById = {};\r\n }\r\n this._tmpVertex = new SolidParticleVertex();\r\n }\r\n\r\n /**\r\n * Builds the SPS underlying mesh. Returns a standard Mesh.\r\n * If no model shape was added to the SPS, the returned mesh is just a single triangular plane.\r\n * @returns the created mesh\r\n */\r\n public buildMesh(): Mesh {\r\n if (!this._isNotBuilt && this.mesh) {\r\n return this.mesh;\r\n }\r\n if (this.nbParticles === 0 && !this.mesh) {\r\n const triangle = CreateDisc(\"\", { radius: 1, tessellation: 3 }, this._scene);\r\n this.addShape(triangle, 1);\r\n triangle.dispose();\r\n }\r\n this._indices32 = this._needs32Bits ? new Uint32Array(this._indices) : new Uint16Array(this._indices);\r\n this._positions32 = new Float32Array(this._positions);\r\n this._uvs32 = new Float32Array(this._uvs);\r\n this._colors32 = new Float32Array(this._colors);\r\n\r\n if (!this.mesh) {\r\n // in case it's already expanded\r\n const mesh = new Mesh(this.name, this._scene);\r\n this.mesh = mesh;\r\n }\r\n if (!this._updatable && this._multimaterialEnabled) {\r\n this._sortParticlesByMaterial(); // this may reorder the indices32\r\n }\r\n if (this.recomputeNormals) {\r\n VertexData.ComputeNormals(this._positions32, this._indices32, this._normals);\r\n }\r\n\r\n this._normals32 = new Float32Array(this._normals);\r\n this._fixedNormal32 = new Float32Array(this._normals);\r\n if (this._mustUnrotateFixedNormals) {\r\n // the particles could be created already rotated in the mesh with a positionFunction\r\n this._unrotateFixedNormals();\r\n }\r\n const vertexData = new VertexData();\r\n vertexData.indices = this._depthSort ? this._indices : this._indices32;\r\n vertexData.set(this._positions32, VertexBuffer.PositionKind);\r\n vertexData.set(this._normals32, VertexBuffer.NormalKind);\r\n\r\n if (this._uvs32.length > 0) {\r\n vertexData.set(this._uvs32, VertexBuffer.UVKind);\r\n }\r\n if (this._colors32.length > 0) {\r\n vertexData.set(this._colors32, VertexBuffer.ColorKind);\r\n }\r\n\r\n vertexData.applyToMesh(this.mesh, this._updatable);\r\n this.mesh.isPickable = this._pickable;\r\n\r\n if (this._pickable) {\r\n let faceId = 0;\r\n for (let p = 0; p < this.nbParticles; p++) {\r\n const part = this.particles[p];\r\n const lind = part._model._indicesLength;\r\n for (let i = 0; i < lind; i++) {\r\n const f = i % 3;\r\n if (f == 0) {\r\n const pickedData = { idx: part.idx, faceId: faceId };\r\n this.pickedParticles[faceId] = pickedData;\r\n faceId++;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (this._multimaterialEnabled) {\r\n this.setMultiMaterial(this._materials);\r\n }\r\n\r\n if (!this._expandable) {\r\n // free memory\r\n if (!this._depthSort && !this._multimaterialEnabled && !this._autoFixFaceOrientation) {\r\n (this._indices) = null;\r\n }\r\n (this._positions) = null;\r\n (this._normals) = null;\r\n (this._uvs) = null;\r\n (this._colors) = null;\r\n\r\n if (!this._updatable) {\r\n this.particles.length = 0;\r\n }\r\n }\r\n this._isNotBuilt = false;\r\n this.recomputeNormals = false;\r\n this._recomputeInvisibles = true;\r\n return this.mesh;\r\n }\r\n\r\n /**\r\n * Digests the mesh and generates as many solid particles in the system as wanted. Returns the SPS.\r\n * These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places.\r\n * Thus the particles generated from `digest()` have their property `position` set yet.\r\n * @param mesh ( Mesh ) is the mesh to be digested\r\n * @param options {facetNb} (optional integer, default 1) is the number of mesh facets per particle, this parameter is overridden by the parameter `number` if any\r\n * {delta} (optional integer, default 0) is the random extra number of facets per particle , each particle will have between `facetNb` and `facetNb + delta` facets\r\n * {number} (optional positive integer) is the wanted number of particles : each particle is built with `mesh_total_facets / number` facets\r\n * {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.\r\n * @param options.facetNb\r\n * @param options.number\r\n * @param options.delta\r\n * @param options.storage\r\n * @returns the current SPS\r\n */\r\n public digest(mesh: Mesh, options?: { facetNb?: number; number?: number; delta?: number; storage?: [] }): SolidParticleSystem {\r\n let size: number = (options && options.facetNb) || 1;\r\n let number: number = (options && options.number) || 0;\r\n let delta: number = (options && options.delta) || 0;\r\n const meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n const meshInd = mesh.getIndices();\r\n const meshUV = mesh.getVerticesData(VertexBuffer.UVKind);\r\n const meshCol = mesh.getVerticesData(VertexBuffer.ColorKind);\r\n const meshNor = mesh.getVerticesData(VertexBuffer.NormalKind);\r\n const storage = options && options.storage ? options.storage : null;\r\n\r\n let f: number = 0; // facet counter\r\n const totalFacets: number = meshInd.length / 3; // a facet is a triangle, so 3 indices\r\n // compute size from number\r\n if (number) {\r\n number = number > totalFacets ? totalFacets : number;\r\n size = Math.round(totalFacets / number);\r\n delta = 0;\r\n } else {\r\n size = size > totalFacets ? totalFacets : size;\r\n }\r\n\r\n const facetPos: number[] = []; // submesh positions\r\n const facetNor: number[] = [];\r\n const facetInd: number[] = []; // submesh indices\r\n const facetUV: number[] = []; // submesh UV\r\n const facetCol: number[] = []; // submesh colors\r\n const barycenter: Vector3 = Vector3.Zero();\r\n const sizeO: number = size;\r\n\r\n while (f < totalFacets) {\r\n size = sizeO + Math.floor((1 + delta) * Math.random());\r\n if (f > totalFacets - size) {\r\n size = totalFacets - f;\r\n }\r\n // reset temp arrays\r\n facetPos.length = 0;\r\n facetNor.length = 0;\r\n facetInd.length = 0;\r\n facetUV.length = 0;\r\n facetCol.length = 0;\r\n\r\n // iterate over \"size\" facets\r\n let fi: number = 0;\r\n for (let j = f * 3; j < (f + size) * 3; j++) {\r\n facetInd.push(fi);\r\n const i: number = meshInd[j];\r\n const i3: number = i * 3;\r\n facetPos.push(meshPos[i3], meshPos[i3 + 1], meshPos[i3 + 2]);\r\n facetNor.push(meshNor[i3], meshNor[i3 + 1], meshNor[i3 + 2]);\r\n if (meshUV) {\r\n const i2: number = i * 2;\r\n facetUV.push(meshUV[i2], meshUV[i2 + 1]);\r\n }\r\n if (meshCol) {\r\n const i4: number = i * 4;\r\n facetCol.push(meshCol[i4], meshCol[i4 + 1], meshCol[i4 + 2], meshCol[i4 + 3]);\r\n }\r\n fi++;\r\n }\r\n\r\n // create a model shape for each single particle\r\n let idx: number = this.nbParticles;\r\n const shape: Vector3[] = this._posToShape(facetPos);\r\n const shapeUV: number[] = this._uvsToShapeUV(facetUV);\r\n const shapeInd = facetInd.slice();\r\n const shapeCol = facetCol.slice();\r\n const shapeNor = facetNor.slice();\r\n\r\n // compute the barycenter of the shape\r\n barycenter.copyFromFloats(0, 0, 0);\r\n let v: number;\r\n for (v = 0; v < shape.length; v++) {\r\n barycenter.addInPlace(shape[v]);\r\n }\r\n barycenter.scaleInPlace(1 / shape.length);\r\n\r\n // shift the shape from its barycenter to the origin\r\n // and compute the BBox required for intersection.\r\n const minimum: Vector3 = new Vector3(Infinity, Infinity, Infinity);\r\n const maximum: Vector3 = new Vector3(-Infinity, -Infinity, -Infinity);\r\n for (v = 0; v < shape.length; v++) {\r\n shape[v].subtractInPlace(barycenter);\r\n minimum.minimizeInPlaceFromFloats(shape[v].x, shape[v].y, shape[v].z);\r\n maximum.maximizeInPlaceFromFloats(shape[v].x, shape[v].y, shape[v].z);\r\n }\r\n let bInfo;\r\n if (this._particlesIntersect) {\r\n bInfo = new BoundingInfo(minimum, maximum);\r\n }\r\n let material = null;\r\n if (this._useModelMaterial) {\r\n material = mesh.material ? mesh.material : this._setDefaultMaterial();\r\n }\r\n const modelShape = new ModelShape(this._shapeCounter, shape, shapeInd, shapeNor, shapeCol, shapeUV, null, null, material);\r\n\r\n // add the particle in the SPS\r\n const currentPos = this._positions.length;\r\n const currentInd = this._indices.length;\r\n this._meshBuilder(\r\n this._index,\r\n currentInd,\r\n shape,\r\n this._positions,\r\n shapeInd,\r\n this._indices,\r\n facetUV,\r\n this._uvs,\r\n shapeCol,\r\n this._colors,\r\n shapeNor,\r\n this._normals,\r\n idx,\r\n 0,\r\n null,\r\n modelShape\r\n );\r\n this._addParticle(idx, this._lastParticleId, currentPos, currentInd, modelShape, this._shapeCounter, 0, bInfo, storage);\r\n // initialize the particle position\r\n this.particles[this.nbParticles].position.addInPlace(barycenter);\r\n\r\n if (!storage) {\r\n this._index += shape.length;\r\n idx++;\r\n this.nbParticles++;\r\n this._lastParticleId++;\r\n }\r\n this._shapeCounter++;\r\n f += size;\r\n }\r\n this._isNotBuilt = true; // buildMesh() is now expected for setParticles() to work\r\n return this;\r\n }\r\n\r\n /**\r\n * Unrotate the fixed normals in case the mesh was built with pre-rotated particles, ex : use of positionFunction in addShape()\r\n * @internal\r\n */\r\n protected _unrotateFixedNormals() {\r\n let index = 0;\r\n let idx = 0;\r\n const tmpNormal = TmpVectors.Vector3[0];\r\n const quaternion = TmpVectors.Quaternion[0];\r\n const invertedRotMatrix = TmpVectors.Matrix[0];\r\n for (let p = 0; p < this.particles.length; p++) {\r\n const particle = this.particles[p];\r\n const shape = particle._model._shape;\r\n\r\n // computing the inverse of the rotation matrix from the quaternion\r\n // is equivalent to computing the matrix of the inverse quaternion, i.e of the conjugate quaternion\r\n if (particle.rotationQuaternion) {\r\n particle.rotationQuaternion.conjugateToRef(quaternion);\r\n } else {\r\n const rotation = particle.rotation;\r\n Quaternion.RotationYawPitchRollToRef(rotation.y, rotation.x, rotation.z, quaternion);\r\n quaternion.conjugateInPlace();\r\n }\r\n quaternion.toRotationMatrix(invertedRotMatrix);\r\n\r\n for (let pt = 0; pt < shape.length; pt++) {\r\n idx = index + pt * 3;\r\n Vector3.TransformNormalFromFloatsToRef(this._normals32[idx], this._normals32[idx + 1], this._normals32[idx + 2], invertedRotMatrix, tmpNormal);\r\n tmpNormal.toArray(this._fixedNormal32, idx);\r\n }\r\n index = idx + 3;\r\n }\r\n }\r\n\r\n /**\r\n * Resets the temporary working copy particle\r\n * @internal\r\n */\r\n protected _resetCopy() {\r\n const copy = this._copy;\r\n copy.position.setAll(0);\r\n copy.rotation.setAll(0);\r\n copy.rotationQuaternion = null;\r\n copy.scaling.setAll(1);\r\n copy.uvs.copyFromFloats(0.0, 0.0, 1.0, 1.0);\r\n copy.color = null;\r\n copy.translateFromPivot = false;\r\n copy.shapeId = 0;\r\n copy.materialIndex = null;\r\n }\r\n\r\n /**\r\n * Inserts the shape model geometry in the global SPS mesh by updating the positions, indices, normals, colors, uvs arrays\r\n * @param p the current index in the positions array to be updated\r\n * @param ind the current index in the indices array\r\n * @param shape a Vector3 array, the shape geometry\r\n * @param positions the positions array to be updated\r\n * @param meshInd the shape indices array\r\n * @param indices the indices array to be updated\r\n * @param meshUV the shape uv array\r\n * @param uvs the uv array to be updated\r\n * @param meshCol the shape color array\r\n * @param colors the color array to be updated\r\n * @param meshNor the shape normals array\r\n * @param normals the normals array to be updated\r\n * @param idx the particle index\r\n * @param idxInShape the particle index in its shape\r\n * @param options the addShape() method passed options\r\n * @param model\r\n * @model the particle model\r\n * @internal\r\n */\r\n protected _meshBuilder(\r\n p: number,\r\n ind: number,\r\n shape: Vector3[],\r\n positions: number[],\r\n meshInd: IndicesArray,\r\n indices: number[],\r\n meshUV: number[] | Float32Array,\r\n uvs: number[],\r\n meshCol: number[] | Float32Array,\r\n colors: number[],\r\n meshNor: number[] | Float32Array,\r\n normals: number[],\r\n idx: number,\r\n idxInShape: number,\r\n options: any,\r\n model: ModelShape\r\n ): SolidParticle {\r\n let i;\r\n let u = 0;\r\n let c = 0;\r\n let n = 0;\r\n\r\n this._resetCopy();\r\n const copy = this._copy;\r\n const storeApart = options && options.storage ? true : false;\r\n copy.idx = idx;\r\n copy.idxInShape = idxInShape;\r\n copy.shapeId = model.shapeId;\r\n if (this._useModelMaterial) {\r\n const materialId = model._material!.uniqueId;\r\n const materialIndexesById = this._materialIndexesById;\r\n if (!Object.prototype.hasOwnProperty.call(materialIndexesById, materialId)) {\r\n materialIndexesById[materialId] = this._materials.length;\r\n this._materials.push(model._material!);\r\n }\r\n const matIdx = materialIndexesById[materialId];\r\n copy.materialIndex = matIdx;\r\n }\r\n\r\n if (options && options.positionFunction) {\r\n // call to custom positionFunction\r\n options.positionFunction(copy, idx, idxInShape);\r\n this._mustUnrotateFixedNormals = true;\r\n }\r\n\r\n // in case the particle geometry must NOT be inserted in the SPS mesh geometry\r\n if (storeApart) {\r\n return copy;\r\n }\r\n\r\n const rotMatrix = TmpVectors.Matrix[0];\r\n const tmpVertex = this._tmpVertex;\r\n const tmpVector = tmpVertex.position;\r\n const tmpColor = tmpVertex.color;\r\n const tmpUV = tmpVertex.uv;\r\n const tmpRotated = TmpVectors.Vector3[1];\r\n const pivotBackTranslation = TmpVectors.Vector3[2];\r\n const scaledPivot = TmpVectors.Vector3[3];\r\n Matrix.IdentityToRef(rotMatrix);\r\n copy.getRotationMatrix(rotMatrix);\r\n\r\n copy.pivot.multiplyToRef(copy.scaling, scaledPivot);\r\n\r\n if (copy.translateFromPivot) {\r\n pivotBackTranslation.setAll(0.0);\r\n } else {\r\n pivotBackTranslation.copyFrom(scaledPivot);\r\n }\r\n\r\n const someVertexFunction = options && options.vertexFunction;\r\n for (i = 0; i < shape.length; i++) {\r\n tmpVector.copyFrom(shape[i]);\r\n if (copy.color) {\r\n tmpColor.copyFrom(copy.color);\r\n }\r\n if (meshUV) {\r\n tmpUV.copyFromFloats(meshUV[u], meshUV[u + 1]);\r\n }\r\n if (someVertexFunction) {\r\n options.vertexFunction(copy, tmpVertex, i);\r\n }\r\n\r\n tmpVector.multiplyInPlace(copy.scaling).subtractInPlace(scaledPivot);\r\n Vector3.TransformCoordinatesToRef(tmpVector, rotMatrix, tmpRotated);\r\n tmpRotated.addInPlace(pivotBackTranslation).addInPlace(copy.position);\r\n positions.push(tmpRotated.x, tmpRotated.y, tmpRotated.z);\r\n\r\n if (meshUV) {\r\n const copyUvs = copy.uvs;\r\n uvs.push((copyUvs.z - copyUvs.x) * tmpUV.x + copyUvs.x, (copyUvs.w - copyUvs.y) * tmpUV.y + copyUvs.y);\r\n u += 2;\r\n }\r\n\r\n if (copy.color) {\r\n this._color.copyFrom(tmpColor);\r\n } else {\r\n const color = this._color;\r\n if (meshCol && meshCol[c] !== undefined) {\r\n color.r = meshCol[c];\r\n color.g = meshCol[c + 1];\r\n color.b = meshCol[c + 2];\r\n color.a = meshCol[c + 3];\r\n } else {\r\n color.r = 1.0;\r\n color.g = 1.0;\r\n color.b = 1.0;\r\n color.a = 1.0;\r\n }\r\n }\r\n colors.push(this._color.r, this._color.g, this._color.b, this._color.a);\r\n c += 4;\r\n\r\n if (!this.recomputeNormals && meshNor) {\r\n Vector3.TransformNormalFromFloatsToRef(meshNor[n], meshNor[n + 1], meshNor[n + 2], rotMatrix, tmpVector);\r\n normals.push(tmpVector.x, tmpVector.y, tmpVector.z);\r\n n += 3;\r\n }\r\n }\r\n\r\n for (i = 0; i < meshInd.length; i++) {\r\n const current_ind = p + meshInd[i];\r\n indices.push(current_ind);\r\n if (current_ind > 65535) {\r\n this._needs32Bits = true;\r\n }\r\n }\r\n\r\n if (this._depthSort || this._multimaterialEnabled) {\r\n const matIndex = copy.materialIndex !== null ? copy.materialIndex : 0;\r\n this.depthSortedParticles.push(new DepthSortedParticle(idx, ind, meshInd.length, matIndex));\r\n }\r\n\r\n return copy;\r\n }\r\n\r\n /**\r\n * Returns a shape Vector3 array from positions float array\r\n * @param positions float array\r\n * @returns a vector3 array\r\n * @internal\r\n */\r\n protected _posToShape(positions: number[] | Float32Array): Vector3[] {\r\n const shape = [];\r\n for (let i = 0; i < positions.length; i += 3) {\r\n shape.push(Vector3.FromArray(positions, i));\r\n }\r\n return shape;\r\n }\r\n\r\n /**\r\n * Returns a shapeUV array from a float uvs (array deep copy)\r\n * @param uvs as a float array\r\n * @returns a shapeUV array\r\n * @internal\r\n */\r\n protected _uvsToShapeUV(uvs: number[] | Float32Array): number[] {\r\n const shapeUV = [];\r\n if (uvs) {\r\n for (let i = 0; i < uvs.length; i++) {\r\n shapeUV.push(uvs[i]);\r\n }\r\n }\r\n return shapeUV;\r\n }\r\n\r\n /**\r\n * Adds a new particle object in the particles array\r\n * @param idx particle index in particles array\r\n * @param id particle id\r\n * @param idxpos positionIndex : the starting index of the particle vertices in the SPS \"positions\" array\r\n * @param idxind indiceIndex : he starting index of the particle indices in the SPS \"indices\" array\r\n * @param model particle ModelShape object\r\n * @param shapeId model shape identifier\r\n * @param idxInShape index of the particle in the current model\r\n * @param bInfo model bounding info object\r\n * @param storage target storage array, if any\r\n * @internal\r\n */\r\n protected _addParticle(\r\n idx: number,\r\n id: number,\r\n idxpos: number,\r\n idxind: number,\r\n model: ModelShape,\r\n shapeId: number,\r\n idxInShape: number,\r\n bInfo: Nullable = null,\r\n storage: Nullable<[]> = null\r\n ): SolidParticle {\r\n const sp = new SolidParticle(idx, id, idxpos, idxind, model, shapeId, idxInShape, this, bInfo);\r\n const target = storage ? storage : this.particles;\r\n target.push(sp);\r\n return sp;\r\n }\r\n\r\n /**\r\n * Adds some particles to the SPS from the model shape. Returns the shape id.\r\n * Please read the doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/immutable_sps\r\n * @param mesh is any Mesh object that will be used as a model for the solid particles.\r\n * @param nb (positive integer) the number of particles to be created from this model\r\n * @param options {positionFunction} is an optional javascript function to called for each particle on SPS creation.\r\n * {vertexFunction} is an optional javascript function to called for each vertex of each particle on SPS creation\r\n * {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.\r\n * @param options.positionFunction\r\n * @param options.vertexFunction\r\n * @param options.storage\r\n * @returns the number of shapes in the system\r\n */\r\n public addShape(mesh: Mesh, nb: number, options?: { positionFunction?: any; vertexFunction?: any; storage?: [] }): number {\r\n const meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n const meshInd = mesh.getIndices();\r\n const meshUV = mesh.getVerticesData(VertexBuffer.UVKind);\r\n const meshCol = mesh.getVerticesData(VertexBuffer.ColorKind);\r\n const meshNor = mesh.getVerticesData(VertexBuffer.NormalKind);\r\n this.recomputeNormals = meshNor ? false : true;\r\n const indices = Array.from(meshInd);\r\n const shapeNormals = Array.from(meshNor);\r\n const shapeColors = meshCol ? Array.from(meshCol) : [];\r\n const storage = options && options.storage ? options.storage : null;\r\n let bbInfo: Nullable = null;\r\n if (this._particlesIntersect) {\r\n bbInfo = mesh.getBoundingInfo();\r\n }\r\n\r\n const shape = this._posToShape(meshPos);\r\n const shapeUV = this._uvsToShapeUV(meshUV);\r\n\r\n const posfunc = options ? options.positionFunction : null;\r\n const vtxfunc = options ? options.vertexFunction : null;\r\n let material = null;\r\n if (this._useModelMaterial) {\r\n material = mesh.material ? mesh.material : this._setDefaultMaterial();\r\n }\r\n const modelShape = new ModelShape(this._shapeCounter, shape, indices, shapeNormals, shapeColors, shapeUV, posfunc, vtxfunc, material);\r\n\r\n // particles\r\n for (let i = 0; i < nb; i++) {\r\n this._insertNewParticle(this.nbParticles, i, modelShape, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, storage, options);\r\n }\r\n this._shapeCounter++;\r\n this._isNotBuilt = true; // buildMesh() call is now expected for setParticles() to work\r\n return this._shapeCounter - 1;\r\n }\r\n\r\n /**\r\n * Rebuilds a particle back to its just built status : if needed, recomputes the custom positions and vertices\r\n * @internal\r\n */\r\n protected _rebuildParticle(particle: SolidParticle, reset: boolean = false): void {\r\n this._resetCopy();\r\n const copy = this._copy;\r\n if (particle._model._positionFunction) {\r\n // recall to stored custom positionFunction\r\n particle._model._positionFunction(copy, particle.idx, particle.idxInShape);\r\n }\r\n\r\n const rotMatrix = TmpVectors.Matrix[0];\r\n const tmpVertex = TmpVectors.Vector3[0];\r\n const tmpRotated = TmpVectors.Vector3[1];\r\n const pivotBackTranslation = TmpVectors.Vector3[2];\r\n const scaledPivot = TmpVectors.Vector3[3];\r\n\r\n copy.getRotationMatrix(rotMatrix);\r\n\r\n particle.pivot.multiplyToRef(particle.scaling, scaledPivot);\r\n\r\n if (copy.translateFromPivot) {\r\n pivotBackTranslation.copyFromFloats(0.0, 0.0, 0.0);\r\n } else {\r\n pivotBackTranslation.copyFrom(scaledPivot);\r\n }\r\n\r\n const shape = particle._model._shape;\r\n\r\n for (let pt = 0; pt < shape.length; pt++) {\r\n tmpVertex.copyFrom(shape[pt]);\r\n if (particle._model._vertexFunction) {\r\n particle._model._vertexFunction(copy, tmpVertex, pt); // recall to stored vertexFunction\r\n }\r\n\r\n tmpVertex.multiplyInPlace(copy.scaling).subtractInPlace(scaledPivot);\r\n Vector3.TransformCoordinatesToRef(tmpVertex, rotMatrix, tmpRotated);\r\n tmpRotated\r\n .addInPlace(pivotBackTranslation)\r\n .addInPlace(copy.position)\r\n .toArray(this._positions32, particle._pos + pt * 3);\r\n }\r\n if (reset) {\r\n particle.position.setAll(0.0);\r\n particle.rotation.setAll(0.0);\r\n particle.rotationQuaternion = null;\r\n particle.scaling.setAll(1.0);\r\n particle.uvs.setAll(0.0);\r\n particle.pivot.setAll(0.0);\r\n particle.translateFromPivot = false;\r\n particle.parentId = null;\r\n }\r\n }\r\n\r\n /**\r\n * Rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed.\r\n * @param reset boolean, default false : if the particles must be reset at position and rotation zero, scaling 1, color white, initial UVs and not parented.\r\n * @returns the SPS.\r\n */\r\n public rebuildMesh(reset: boolean = false): SolidParticleSystem {\r\n for (let p = 0; p < this.particles.length; p++) {\r\n this._rebuildParticle(this.particles[p], reset);\r\n }\r\n this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions32, false, false);\r\n return this;\r\n }\r\n\r\n /** Removes the particles from the start-th to the end-th included from an expandable SPS (required).\r\n * Returns an array with the removed particles.\r\n * If the number of particles to remove is lower than zero or greater than the global remaining particle number, then an empty array is returned.\r\n * The SPS can't be empty so at least one particle needs to remain in place.\r\n * Under the hood, the VertexData array, so the VBO buffer, is recreated each call.\r\n * @param start index of the first particle to remove\r\n * @param end index of the last particle to remove (included)\r\n * @returns an array populated with the removed particles\r\n */\r\n public removeParticles(start: number, end: number): SolidParticle[] {\r\n const nb = end - start + 1;\r\n if (!this._expandable || nb <= 0 || nb >= this.nbParticles || !this._updatable) {\r\n return [];\r\n }\r\n const particles = this.particles;\r\n const currentNb = this.nbParticles;\r\n if (end < currentNb - 1) {\r\n // update the particle indexes in the positions array in case they're remaining particles after the last removed\r\n const firstRemaining = end + 1;\r\n const shiftPos = particles[firstRemaining]._pos - particles[start]._pos;\r\n const shifInd = particles[firstRemaining]._ind - particles[start]._ind;\r\n for (let i = firstRemaining; i < currentNb; i++) {\r\n const part = particles[i];\r\n part._pos -= shiftPos;\r\n part._ind -= shifInd;\r\n }\r\n }\r\n const removed = particles.splice(start, nb);\r\n this._positions.length = 0;\r\n this._indices.length = 0;\r\n this._colors.length = 0;\r\n this._uvs.length = 0;\r\n this._normals.length = 0;\r\n this._index = 0;\r\n this._idxOfId.length = 0;\r\n if (this._depthSort || this._multimaterialEnabled) {\r\n this.depthSortedParticles = [];\r\n }\r\n let ind = 0;\r\n const particlesLength = particles.length;\r\n for (let p = 0; p < particlesLength; p++) {\r\n const particle = particles[p];\r\n const model = particle._model;\r\n const shape = model._shape;\r\n const modelIndices = model._indices;\r\n const modelNormals = model._normals;\r\n const modelColors = model._shapeColors;\r\n const modelUVs = model._shapeUV;\r\n particle.idx = p;\r\n this._idxOfId[particle.id] = p;\r\n this._meshBuilder(\r\n this._index,\r\n ind,\r\n shape,\r\n this._positions,\r\n modelIndices,\r\n this._indices,\r\n modelUVs,\r\n this._uvs,\r\n modelColors,\r\n this._colors,\r\n modelNormals,\r\n this._normals,\r\n particle.idx,\r\n particle.idxInShape,\r\n null,\r\n model\r\n );\r\n this._index += shape.length;\r\n ind += modelIndices.length;\r\n }\r\n this.nbParticles -= nb;\r\n this._isNotBuilt = true; // buildMesh() call is now expected for setParticles() to work\r\n return removed;\r\n }\r\n\r\n /**\r\n * Inserts some pre-created particles in the solid particle system so that they can be managed by setParticles().\r\n * @param solidParticleArray an array populated with Solid Particles objects\r\n * @returns the SPS\r\n */\r\n public insertParticlesFromArray(solidParticleArray: SolidParticle[]): SolidParticleSystem {\r\n if (!this._expandable) {\r\n return this;\r\n }\r\n let idxInShape = 0;\r\n let currentShapeId = solidParticleArray[0].shapeId;\r\n const nb = solidParticleArray.length;\r\n for (let i = 0; i < nb; i++) {\r\n const sp = solidParticleArray[i];\r\n const model = sp._model;\r\n const shape = model._shape;\r\n const meshInd = model._indices;\r\n const meshUV = model._shapeUV;\r\n const meshCol = model._shapeColors;\r\n const meshNor = model._normals;\r\n const noNor = meshNor ? false : true;\r\n this.recomputeNormals = noNor || this.recomputeNormals;\r\n const bbInfo = sp.getBoundingInfo();\r\n const newPart = this._insertNewParticle(this.nbParticles, idxInShape, model, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, null, null);\r\n sp.copyToRef(newPart!);\r\n idxInShape++;\r\n if (currentShapeId != sp.shapeId) {\r\n currentShapeId = sp.shapeId;\r\n idxInShape = 0;\r\n }\r\n }\r\n this._isNotBuilt = true; // buildMesh() call is now expected for setParticles() to work\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a new particle and modifies the SPS mesh geometry :\r\n * - calls _meshBuilder() to increase the SPS mesh geometry step by step\r\n * - calls _addParticle() to populate the particle array\r\n * factorized code from addShape() and insertParticlesFromArray()\r\n * @param idx particle index in the particles array\r\n * @param i particle index in its shape\r\n * @param modelShape particle ModelShape object\r\n * @param shape shape vertex array\r\n * @param meshInd shape indices array\r\n * @param meshUV shape uv array\r\n * @param meshCol shape color array\r\n * @param meshNor shape normals array\r\n * @param bbInfo shape bounding info\r\n * @param storage target particle storage\r\n * @param options\r\n * @options addShape() passed options\r\n * @internal\r\n */\r\n protected _insertNewParticle(\r\n idx: number,\r\n i: number,\r\n modelShape: ModelShape,\r\n shape: Vector3[],\r\n meshInd: IndicesArray,\r\n meshUV: number[] | Float32Array,\r\n meshCol: number[] | Float32Array,\r\n meshNor: number[] | Float32Array,\r\n bbInfo: Nullable,\r\n storage: Nullable<[]>,\r\n options: any\r\n ): Nullable {\r\n const currentPos = this._positions.length;\r\n const currentInd = this._indices.length;\r\n const currentCopy = this._meshBuilder(\r\n this._index,\r\n currentInd,\r\n shape,\r\n this._positions,\r\n meshInd,\r\n this._indices,\r\n meshUV,\r\n this._uvs,\r\n meshCol,\r\n this._colors,\r\n meshNor,\r\n this._normals,\r\n idx,\r\n i,\r\n options,\r\n modelShape\r\n );\r\n let sp: Nullable = null;\r\n if (this._updatable) {\r\n sp = this._addParticle(this.nbParticles, this._lastParticleId, currentPos, currentInd, modelShape, this._shapeCounter, i, bbInfo, storage);\r\n sp.position.copyFrom(currentCopy.position);\r\n sp.rotation.copyFrom(currentCopy.rotation);\r\n if (currentCopy.rotationQuaternion) {\r\n if (sp.rotationQuaternion) {\r\n sp.rotationQuaternion.copyFrom(currentCopy.rotationQuaternion);\r\n } else {\r\n sp.rotationQuaternion = currentCopy.rotationQuaternion.clone();\r\n }\r\n }\r\n if (currentCopy.color) {\r\n if (sp.color) {\r\n sp.color.copyFrom(currentCopy.color);\r\n } else {\r\n sp.color = currentCopy.color.clone();\r\n }\r\n }\r\n sp.scaling.copyFrom(currentCopy.scaling);\r\n sp.uvs.copyFrom(currentCopy.uvs);\r\n if (currentCopy.materialIndex !== null) {\r\n sp.materialIndex = currentCopy.materialIndex;\r\n }\r\n if (this.expandable) {\r\n this._idxOfId[sp.id] = sp.idx;\r\n }\r\n }\r\n if (!storage) {\r\n this._index += shape.length;\r\n this.nbParticles++;\r\n this._lastParticleId++;\r\n }\r\n return sp;\r\n }\r\n\r\n /**\r\n * Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.\r\n * This method calls `updateParticle()` for each particle of the SPS.\r\n * For an animated SPS, it is usually called within the render loop.\r\n * This methods does nothing if called on a non updatable or not yet built SPS. Example : buildMesh() not called after having added or removed particles from an expandable SPS.\r\n * @param start The particle index in the particle array where to start to compute the particle property values _(default 0)_\r\n * @param end The particle index in the particle array where to stop to compute the particle property values _(default nbParticle - 1)_\r\n * @param update If the mesh must be finally updated on this call after all the particle computations _(default true)_\r\n * @returns the SPS.\r\n */\r\n public setParticles(start: number = 0, end: number = this.nbParticles - 1, update: boolean = true): SolidParticleSystem {\r\n if (!this._updatable || this._isNotBuilt) {\r\n return this;\r\n }\r\n\r\n // custom beforeUpdate\r\n this.beforeUpdateParticles(start, end, update);\r\n\r\n const rotMatrix = TmpVectors.Matrix[0];\r\n const invertedMatrix = TmpVectors.Matrix[1];\r\n const mesh = this.mesh;\r\n const colors32 = this._colors32;\r\n const positions32 = this._positions32;\r\n const normals32 = this._normals32;\r\n const uvs32 = this._uvs32;\r\n const indices32 = this._indices32;\r\n const indices = this._indices;\r\n const fixedNormal32 = this._fixedNormal32;\r\n const depthSortParticles = this._depthSort && this._depthSortParticles;\r\n\r\n const tempVectors = TmpVectors.Vector3;\r\n const camAxisX = tempVectors[5].copyFromFloats(1.0, 0.0, 0.0);\r\n const camAxisY = tempVectors[6].copyFromFloats(0.0, 1.0, 0.0);\r\n const camAxisZ = tempVectors[7].copyFromFloats(0.0, 0.0, 1.0);\r\n const minimum = tempVectors[8].setAll(Number.MAX_VALUE);\r\n const maximum = tempVectors[9].setAll(-Number.MAX_VALUE);\r\n const camInvertedPosition = tempVectors[10].setAll(0);\r\n\r\n const tmpVertex = this._tmpVertex;\r\n const tmpVector = tmpVertex.position;\r\n const tmpColor = tmpVertex.color;\r\n const tmpUV = tmpVertex.uv;\r\n\r\n // cases when the World Matrix is to be computed first\r\n if (this.billboard || this._depthSort) {\r\n this.mesh.computeWorldMatrix(true);\r\n this.mesh._worldMatrix.invertToRef(invertedMatrix);\r\n }\r\n // if the particles will always face the camera\r\n if (this.billboard) {\r\n // compute the camera position and un-rotate it by the current mesh rotation\r\n const tmpVector0 = tempVectors[0];\r\n this._camera.getDirectionToRef(Axis.Z, tmpVector0);\r\n Vector3.TransformNormalToRef(tmpVector0, invertedMatrix, camAxisZ);\r\n camAxisZ.normalize();\r\n // same for camera up vector extracted from the cam view matrix\r\n const view = this._camera.getViewMatrix(true);\r\n Vector3.TransformNormalFromFloatsToRef(view.m[1], view.m[5], view.m[9], invertedMatrix, camAxisY);\r\n Vector3.CrossToRef(camAxisY, camAxisZ, camAxisX);\r\n camAxisY.normalize();\r\n camAxisX.normalize();\r\n }\r\n\r\n // if depthSort, compute the camera global position in the mesh local system\r\n if (this._depthSort) {\r\n Vector3.TransformCoordinatesToRef(this._camera.globalPosition, invertedMatrix, camInvertedPosition); // then un-rotate the camera\r\n }\r\n\r\n Matrix.IdentityToRef(rotMatrix);\r\n let idx = 0; // current position index in the global array positions32\r\n let index = 0; // position start index in the global array positions32 of the current particle\r\n let colidx = 0; // current color index in the global array colors32\r\n let colorIndex = 0; // color start index in the global array colors32 of the current particle\r\n let uvidx = 0; // current uv index in the global array uvs32\r\n let uvIndex = 0; // uv start index in the global array uvs32 of the current particle\r\n let pt = 0; // current index in the particle model shape\r\n\r\n if (this.mesh.isFacetDataEnabled) {\r\n this._computeBoundingBox = true;\r\n }\r\n\r\n end = end >= this.nbParticles ? this.nbParticles - 1 : end;\r\n if (this._computeBoundingBox) {\r\n if (start != 0 || end != this.nbParticles - 1) {\r\n // only some particles are updated, then use the current existing BBox basis. Note : it can only increase.\r\n const boundingInfo = this.mesh.getBoundingInfo();\r\n if (boundingInfo) {\r\n minimum.copyFrom(boundingInfo.minimum);\r\n maximum.copyFrom(boundingInfo.maximum);\r\n }\r\n }\r\n }\r\n\r\n // particle loop\r\n index = this.particles[start]._pos;\r\n const vpos = (index / 3) | 0;\r\n colorIndex = vpos * 4;\r\n uvIndex = vpos * 2;\r\n\r\n for (let p = start; p <= end; p++) {\r\n const particle = this.particles[p];\r\n\r\n // call to custom user function to update the particle properties\r\n this.updateParticle(particle);\r\n\r\n const shape = particle._model._shape;\r\n const shapeUV = particle._model._shapeUV;\r\n const particleRotationMatrix = particle._rotationMatrix;\r\n const particlePosition = particle.position;\r\n const particleRotation = particle.rotation;\r\n const particleScaling = particle.scaling;\r\n const particleGlobalPosition = particle._globalPosition;\r\n\r\n // camera-particle distance for depth sorting\r\n if (depthSortParticles) {\r\n const dsp = this.depthSortedParticles[p];\r\n dsp.idx = particle.idx;\r\n dsp.ind = particle._ind;\r\n dsp.indicesLength = particle._model._indicesLength;\r\n dsp.sqDistance = Vector3.DistanceSquared(particle.position, camInvertedPosition);\r\n }\r\n\r\n // skip the computations for inactive or already invisible particles\r\n if (!particle.alive || (particle._stillInvisible && !particle.isVisible && !this._recomputeInvisibles)) {\r\n // increment indexes for the next particle\r\n pt = shape.length;\r\n index += pt * 3;\r\n colorIndex += pt * 4;\r\n uvIndex += pt * 2;\r\n continue;\r\n }\r\n\r\n if (particle.isVisible) {\r\n particle._stillInvisible = false; // un-mark permanent invisibility\r\n\r\n const scaledPivot = tempVectors[12];\r\n particle.pivot.multiplyToRef(particleScaling, scaledPivot);\r\n\r\n // particle rotation matrix\r\n if (this.billboard) {\r\n particleRotation.x = 0.0;\r\n particleRotation.y = 0.0;\r\n }\r\n if (this._computeParticleRotation || this.billboard) {\r\n particle.getRotationMatrix(rotMatrix);\r\n }\r\n\r\n const particleHasParent = particle.parentId !== null;\r\n if (particleHasParent) {\r\n const parent = this.getParticleById(particle.parentId!);\r\n if (parent) {\r\n const parentRotationMatrix = parent._rotationMatrix;\r\n const parentGlobalPosition = parent._globalPosition;\r\n\r\n const rotatedY = particlePosition.x * parentRotationMatrix[1] + particlePosition.y * parentRotationMatrix[4] + particlePosition.z * parentRotationMatrix[7];\r\n const rotatedX = particlePosition.x * parentRotationMatrix[0] + particlePosition.y * parentRotationMatrix[3] + particlePosition.z * parentRotationMatrix[6];\r\n const rotatedZ = particlePosition.x * parentRotationMatrix[2] + particlePosition.y * parentRotationMatrix[5] + particlePosition.z * parentRotationMatrix[8];\r\n\r\n particleGlobalPosition.x = parentGlobalPosition.x + rotatedX;\r\n particleGlobalPosition.y = parentGlobalPosition.y + rotatedY;\r\n particleGlobalPosition.z = parentGlobalPosition.z + rotatedZ;\r\n\r\n if (this._computeParticleRotation || this.billboard) {\r\n const rotMatrixValues = rotMatrix.m;\r\n particleRotationMatrix[0] =\r\n rotMatrixValues[0] * parentRotationMatrix[0] + rotMatrixValues[1] * parentRotationMatrix[3] + rotMatrixValues[2] * parentRotationMatrix[6];\r\n particleRotationMatrix[1] =\r\n rotMatrixValues[0] * parentRotationMatrix[1] + rotMatrixValues[1] * parentRotationMatrix[4] + rotMatrixValues[2] * parentRotationMatrix[7];\r\n particleRotationMatrix[2] =\r\n rotMatrixValues[0] * parentRotationMatrix[2] + rotMatrixValues[1] * parentRotationMatrix[5] + rotMatrixValues[2] * parentRotationMatrix[8];\r\n particleRotationMatrix[3] =\r\n rotMatrixValues[4] * parentRotationMatrix[0] + rotMatrixValues[5] * parentRotationMatrix[3] + rotMatrixValues[6] * parentRotationMatrix[6];\r\n particleRotationMatrix[4] =\r\n rotMatrixValues[4] * parentRotationMatrix[1] + rotMatrixValues[5] * parentRotationMatrix[4] + rotMatrixValues[6] * parentRotationMatrix[7];\r\n particleRotationMatrix[5] =\r\n rotMatrixValues[4] * parentRotationMatrix[2] + rotMatrixValues[5] * parentRotationMatrix[5] + rotMatrixValues[6] * parentRotationMatrix[8];\r\n particleRotationMatrix[6] =\r\n rotMatrixValues[8] * parentRotationMatrix[0] + rotMatrixValues[9] * parentRotationMatrix[3] + rotMatrixValues[10] * parentRotationMatrix[6];\r\n particleRotationMatrix[7] =\r\n rotMatrixValues[8] * parentRotationMatrix[1] + rotMatrixValues[9] * parentRotationMatrix[4] + rotMatrixValues[10] * parentRotationMatrix[7];\r\n particleRotationMatrix[8] =\r\n rotMatrixValues[8] * parentRotationMatrix[2] + rotMatrixValues[9] * parentRotationMatrix[5] + rotMatrixValues[10] * parentRotationMatrix[8];\r\n }\r\n } else {\r\n // in case the parent were removed at some moment\r\n particle.parentId = null;\r\n }\r\n } else {\r\n particleGlobalPosition.x = particlePosition.x;\r\n particleGlobalPosition.y = particlePosition.y;\r\n particleGlobalPosition.z = particlePosition.z;\r\n\r\n if (this._computeParticleRotation || this.billboard) {\r\n const rotMatrixValues = rotMatrix.m;\r\n particleRotationMatrix[0] = rotMatrixValues[0];\r\n particleRotationMatrix[1] = rotMatrixValues[1];\r\n particleRotationMatrix[2] = rotMatrixValues[2];\r\n particleRotationMatrix[3] = rotMatrixValues[4];\r\n particleRotationMatrix[4] = rotMatrixValues[5];\r\n particleRotationMatrix[5] = rotMatrixValues[6];\r\n particleRotationMatrix[6] = rotMatrixValues[8];\r\n particleRotationMatrix[7] = rotMatrixValues[9];\r\n particleRotationMatrix[8] = rotMatrixValues[10];\r\n }\r\n }\r\n\r\n const pivotBackTranslation = tempVectors[11];\r\n if (particle.translateFromPivot) {\r\n pivotBackTranslation.setAll(0.0);\r\n } else {\r\n pivotBackTranslation.copyFrom(scaledPivot);\r\n }\r\n\r\n // particle vertex loop\r\n for (pt = 0; pt < shape.length; pt++) {\r\n idx = index + pt * 3;\r\n colidx = colorIndex + pt * 4;\r\n uvidx = uvIndex + pt * 2;\r\n const iu = 2 * pt;\r\n const iv = iu + 1;\r\n\r\n tmpVector.copyFrom(shape[pt]);\r\n if (this._computeParticleColor && particle.color) {\r\n tmpColor.copyFrom(particle.color);\r\n }\r\n if (this._computeParticleTexture) {\r\n tmpUV.copyFromFloats(shapeUV[iu], shapeUV[iv]);\r\n }\r\n if (this._computeParticleVertex) {\r\n this.updateParticleVertex(particle, tmpVertex, pt);\r\n }\r\n\r\n // positions\r\n const vertexX = tmpVector.x * particleScaling.x - scaledPivot.x;\r\n const vertexY = tmpVector.y * particleScaling.y - scaledPivot.y;\r\n const vertexZ = tmpVector.z * particleScaling.z - scaledPivot.z;\r\n\r\n let rotatedX = vertexX * particleRotationMatrix[0] + vertexY * particleRotationMatrix[3] + vertexZ * particleRotationMatrix[6];\r\n let rotatedY = vertexX * particleRotationMatrix[1] + vertexY * particleRotationMatrix[4] + vertexZ * particleRotationMatrix[7];\r\n let rotatedZ = vertexX * particleRotationMatrix[2] + vertexY * particleRotationMatrix[5] + vertexZ * particleRotationMatrix[8];\r\n\r\n rotatedX += pivotBackTranslation.x;\r\n rotatedY += pivotBackTranslation.y;\r\n rotatedZ += pivotBackTranslation.z;\r\n\r\n const px = (positions32[idx] = particleGlobalPosition.x + camAxisX.x * rotatedX + camAxisY.x * rotatedY + camAxisZ.x * rotatedZ);\r\n const py = (positions32[idx + 1] = particleGlobalPosition.y + camAxisX.y * rotatedX + camAxisY.y * rotatedY + camAxisZ.y * rotatedZ);\r\n const pz = (positions32[idx + 2] = particleGlobalPosition.z + camAxisX.z * rotatedX + camAxisY.z * rotatedY + camAxisZ.z * rotatedZ);\r\n\r\n if (this._computeBoundingBox) {\r\n minimum.minimizeInPlaceFromFloats(px, py, pz);\r\n maximum.maximizeInPlaceFromFloats(px, py, pz);\r\n }\r\n\r\n // normals : if the particles can't be morphed then just rotate the normals, what is much more faster than ComputeNormals()\r\n if (!this._computeParticleVertex) {\r\n const normalx = fixedNormal32[idx];\r\n const normaly = fixedNormal32[idx + 1];\r\n const normalz = fixedNormal32[idx + 2];\r\n\r\n const rotatedx = normalx * particleRotationMatrix[0] + normaly * particleRotationMatrix[3] + normalz * particleRotationMatrix[6];\r\n const rotatedy = normalx * particleRotationMatrix[1] + normaly * particleRotationMatrix[4] + normalz * particleRotationMatrix[7];\r\n const rotatedz = normalx * particleRotationMatrix[2] + normaly * particleRotationMatrix[5] + normalz * particleRotationMatrix[8];\r\n\r\n normals32[idx] = camAxisX.x * rotatedx + camAxisY.x * rotatedy + camAxisZ.x * rotatedz;\r\n normals32[idx + 1] = camAxisX.y * rotatedx + camAxisY.y * rotatedy + camAxisZ.y * rotatedz;\r\n normals32[idx + 2] = camAxisX.z * rotatedx + camAxisY.z * rotatedy + camAxisZ.z * rotatedz;\r\n }\r\n\r\n if (this._computeParticleColor && particle.color) {\r\n const colors32 = this._colors32;\r\n colors32[colidx] = tmpColor.r;\r\n colors32[colidx + 1] = tmpColor.g;\r\n colors32[colidx + 2] = tmpColor.b;\r\n colors32[colidx + 3] = tmpColor.a;\r\n }\r\n\r\n if (this._computeParticleTexture) {\r\n const uvs = particle.uvs;\r\n uvs32[uvidx] = tmpUV.x * (uvs.z - uvs.x) + uvs.x;\r\n uvs32[uvidx + 1] = tmpUV.y * (uvs.w - uvs.y) + uvs.y;\r\n }\r\n }\r\n }\r\n // particle just set invisible : scaled to zero and positioned at the origin\r\n else {\r\n particle._stillInvisible = true; // mark the particle as invisible\r\n for (pt = 0; pt < shape.length; pt++) {\r\n idx = index + pt * 3;\r\n colidx = colorIndex + pt * 4;\r\n uvidx = uvIndex + pt * 2;\r\n\r\n positions32[idx] = positions32[idx + 1] = positions32[idx + 2] = 0;\r\n normals32[idx] = normals32[idx + 1] = normals32[idx + 2] = 0;\r\n if (this._computeParticleColor && particle.color) {\r\n const color = particle.color;\r\n colors32[colidx] = color.r;\r\n colors32[colidx + 1] = color.g;\r\n colors32[colidx + 2] = color.b;\r\n colors32[colidx + 3] = color.a;\r\n }\r\n if (this._computeParticleTexture) {\r\n const uvs = particle.uvs;\r\n uvs32[uvidx] = shapeUV[pt * 2] * (uvs.z - uvs.x) + uvs.x;\r\n uvs32[uvidx + 1] = shapeUV[pt * 2 + 1] * (uvs.w - uvs.y) + uvs.y;\r\n }\r\n }\r\n }\r\n\r\n // if the particle intersections must be computed : update the bbInfo\r\n if (this._particlesIntersect) {\r\n const bInfo = particle.getBoundingInfo();\r\n const bBox = bInfo.boundingBox;\r\n const bSphere = bInfo.boundingSphere;\r\n const modelBoundingInfo = particle._modelBoundingInfo;\r\n if (!this._bSphereOnly) {\r\n // place, scale and rotate the particle bbox within the SPS local system, then update it\r\n const modelBoundingInfoVectors = modelBoundingInfo.boundingBox.vectors;\r\n\r\n const tempMin = tempVectors[1];\r\n const tempMax = tempVectors[2];\r\n tempMin.setAll(Number.MAX_VALUE);\r\n tempMax.setAll(-Number.MAX_VALUE);\r\n for (let b = 0; b < 8; b++) {\r\n const scaledX = modelBoundingInfoVectors[b].x * particleScaling.x;\r\n const scaledY = modelBoundingInfoVectors[b].y * particleScaling.y;\r\n const scaledZ = modelBoundingInfoVectors[b].z * particleScaling.z;\r\n const rotatedX = scaledX * particleRotationMatrix[0] + scaledY * particleRotationMatrix[3] + scaledZ * particleRotationMatrix[6];\r\n const rotatedY = scaledX * particleRotationMatrix[1] + scaledY * particleRotationMatrix[4] + scaledZ * particleRotationMatrix[7];\r\n const rotatedZ = scaledX * particleRotationMatrix[2] + scaledY * particleRotationMatrix[5] + scaledZ * particleRotationMatrix[8];\r\n const x = particlePosition.x + camAxisX.x * rotatedX + camAxisY.x * rotatedY + camAxisZ.x * rotatedZ;\r\n const y = particlePosition.y + camAxisX.y * rotatedX + camAxisY.y * rotatedY + camAxisZ.y * rotatedZ;\r\n const z = particlePosition.z + camAxisX.z * rotatedX + camAxisY.z * rotatedY + camAxisZ.z * rotatedZ;\r\n tempMin.minimizeInPlaceFromFloats(x, y, z);\r\n tempMax.maximizeInPlaceFromFloats(x, y, z);\r\n }\r\n\r\n bBox.reConstruct(tempMin, tempMax, mesh._worldMatrix);\r\n }\r\n\r\n // place and scale the particle bouding sphere in the SPS local system, then update it\r\n const minBbox = modelBoundingInfo.minimum.multiplyToRef(particleScaling, tempVectors[1]);\r\n const maxBbox = modelBoundingInfo.maximum.multiplyToRef(particleScaling, tempVectors[2]);\r\n\r\n const bSphereCenter = maxBbox.addToRef(minBbox, tempVectors[3]).scaleInPlace(0.5).addInPlace(particleGlobalPosition);\r\n const halfDiag = maxBbox.subtractToRef(minBbox, tempVectors[4]).scaleInPlace(0.5 * this._bSphereRadiusFactor);\r\n const bSphereMinBbox = bSphereCenter.subtractToRef(halfDiag, tempVectors[1]);\r\n const bSphereMaxBbox = bSphereCenter.addToRef(halfDiag, tempVectors[2]);\r\n bSphere.reConstruct(bSphereMinBbox, bSphereMaxBbox, mesh._worldMatrix);\r\n }\r\n\r\n // increment indexes for the next particle\r\n index = idx + 3;\r\n colorIndex = colidx + 4;\r\n uvIndex = uvidx + 2;\r\n }\r\n\r\n // if the VBO must be updated\r\n if (update) {\r\n if (this._computeParticleColor) {\r\n const vb = mesh.getVertexBuffer(VertexBuffer.ColorKind);\r\n if (vb && !mesh.isPickable) {\r\n vb.updateDirectly(colors32, 0);\r\n } else {\r\n mesh.updateVerticesData(VertexBuffer.ColorKind, colors32, false, false);\r\n }\r\n }\r\n if (this._computeParticleTexture) {\r\n const vb = mesh.getVertexBuffer(VertexBuffer.UVKind);\r\n if (vb && !mesh.isPickable) {\r\n vb.updateDirectly(uvs32, 0);\r\n } else {\r\n mesh.updateVerticesData(VertexBuffer.UVKind, uvs32, false, false);\r\n }\r\n }\r\n const vbp = mesh.getVertexBuffer(VertexBuffer.PositionKind);\r\n if (vbp && !mesh.isPickable) {\r\n vbp.updateDirectly(positions32, 0);\r\n } else {\r\n mesh.updateVerticesData(VertexBuffer.PositionKind, positions32, false, false);\r\n }\r\n if (!mesh.areNormalsFrozen || mesh.isFacetDataEnabled) {\r\n if (this._computeParticleVertex || mesh.isFacetDataEnabled) {\r\n // recompute the normals only if the particles can be morphed, update then also the normal reference array _fixedNormal32[]\r\n const params = mesh.isFacetDataEnabled ? mesh.getFacetDataParameters() : null;\r\n VertexData.ComputeNormals(positions32, indices32, normals32, params);\r\n for (let i = 0; i < normals32.length; i++) {\r\n fixedNormal32[i] = normals32[i];\r\n }\r\n }\r\n if (!mesh.areNormalsFrozen) {\r\n const vb = mesh.getVertexBuffer(VertexBuffer.NormalKind);\r\n if (vb && !mesh.isPickable) {\r\n vb.updateDirectly(normals32, 0);\r\n } else {\r\n mesh.updateVerticesData(VertexBuffer.NormalKind, normals32, false, false);\r\n }\r\n }\r\n }\r\n if (depthSortParticles) {\r\n const depthSortedParticles = this.depthSortedParticles;\r\n depthSortedParticles.sort(this._depthSortFunction);\r\n const dspl = depthSortedParticles.length;\r\n let sid = 0;\r\n let faceId = 0;\r\n for (let sorted = 0; sorted < dspl; sorted++) {\r\n const sortedParticle = depthSortedParticles[sorted];\r\n const lind = sortedParticle.indicesLength;\r\n const sind = sortedParticle.ind;\r\n for (let i = 0; i < lind; i++) {\r\n indices32[sid] = indices[sind + i];\r\n sid++;\r\n if (this._pickable) {\r\n const f = i % 3;\r\n if (f == 0) {\r\n const pickedData = this.pickedParticles[faceId];\r\n pickedData.idx = sortedParticle.idx;\r\n pickedData.faceId = faceId;\r\n faceId++;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n if (this._autoFixFaceOrientation) {\r\n let particleInd = 0;\r\n\r\n for (let particleIdx = 0; particleIdx < this.particles.length; particleIdx++) {\r\n const particle = depthSortParticles ? this.particles[this.depthSortedParticles[particleIdx].idx] : this.particles[particleIdx];\r\n const flipFaces = particle.scale.x * particle.scale.y * particle.scale.z < 0;\r\n\r\n if (flipFaces) {\r\n for (let faceInd = 0; faceInd < particle._model._indicesLength; faceInd += 3) {\r\n const tmp = indices[particle._ind + faceInd];\r\n indices32[particleInd + faceInd] = indices[particle._ind + faceInd + 1];\r\n indices32[particleInd + faceInd + 1] = tmp;\r\n }\r\n }\r\n\r\n particleInd += particle._model._indicesLength;\r\n }\r\n }\r\n\r\n if (depthSortParticles || this._autoFixFaceOrientation) {\r\n mesh.updateIndices(indices32);\r\n }\r\n }\r\n if (this._computeBoundingBox) {\r\n if (mesh.hasBoundingInfo) {\r\n mesh.getBoundingInfo().reConstruct(minimum, maximum, mesh._worldMatrix);\r\n } else {\r\n mesh.buildBoundingInfo(minimum, maximum, mesh._worldMatrix);\r\n }\r\n }\r\n if (this._autoUpdateSubMeshes) {\r\n this.computeSubMeshes();\r\n }\r\n this._recomputeInvisibles = false;\r\n this.afterUpdateParticles(start, end, update);\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes the SPS.\r\n */\r\n public dispose(): void {\r\n this.mesh.dispose();\r\n this.vars = null;\r\n // drop references to internal big arrays for the GC\r\n (this._positions) = null;\r\n (this._indices) = null;\r\n (this._normals) = null;\r\n (this._uvs) = null;\r\n (this._colors) = null;\r\n (this._indices32) = null;\r\n (this._positions32) = null;\r\n (this._normals32) = null;\r\n (this._fixedNormal32) = null;\r\n (this._uvs32) = null;\r\n (this._colors32) = null;\r\n (this.pickedParticles) = null;\r\n (this.pickedBySubMesh) = null;\r\n (this._materials) = null;\r\n (this._materialIndexes) = null;\r\n (this._indicesByMaterial) = null;\r\n (this._idxOfId) = null;\r\n }\r\n /** Returns an object {idx: number faceId: number} for the picked particle from the passed pickingInfo object.\r\n * idx is the particle index in the SPS\r\n * faceId is the picked face index counted within this particle.\r\n * Returns null if the pickInfo can't identify a picked particle.\r\n * @param pickingInfo (PickingInfo object)\r\n * @returns {idx: number, faceId: number} or null\r\n */\r\n public pickedParticle(pickingInfo: PickingInfo): Nullable<{ idx: number; faceId: number }> {\r\n if (pickingInfo.hit) {\r\n const subMesh = pickingInfo.subMeshId;\r\n const faceId = pickingInfo.faceId - this.mesh.subMeshes[subMesh].indexStart / 3;\r\n const picked = this.pickedBySubMesh;\r\n if (picked[subMesh] && picked[subMesh][faceId]) {\r\n return picked[subMesh][faceId];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Returns a SolidParticle object from its identifier : particle.id\r\n * @param id (integer) the particle Id\r\n * @returns the searched particle or null if not found in the SPS.\r\n */\r\n public getParticleById(id: number): Nullable {\r\n const p = this.particles[id];\r\n if (p && p.id == id) {\r\n return p;\r\n }\r\n const particles = this.particles;\r\n const idx = this._idxOfId[id];\r\n if (idx !== undefined) {\r\n return particles[idx];\r\n }\r\n let i = 0;\r\n const nb = this.nbParticles;\r\n while (i < nb) {\r\n const particle = particles[i];\r\n if (particle.id == id) {\r\n return particle;\r\n }\r\n i++;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Returns a new array populated with the particles having the passed shapeId.\r\n * @param shapeId (integer) the shape identifier\r\n * @returns a new solid particle array\r\n */\r\n public getParticlesByShapeId(shapeId: number): SolidParticle[] {\r\n const ref: SolidParticle[] = [];\r\n this.getParticlesByShapeIdToRef(shapeId, ref);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Populates the passed array \"ref\" with the particles having the passed shapeId.\r\n * @param shapeId the shape identifier\r\n * @returns the SPS\r\n * @param ref\r\n */\r\n public getParticlesByShapeIdToRef(shapeId: number, ref: SolidParticle[]): SolidParticleSystem {\r\n ref.length = 0;\r\n for (let i = 0; i < this.nbParticles; i++) {\r\n const p = this.particles[i];\r\n if (p.shapeId == shapeId) {\r\n ref.push(p);\r\n }\r\n }\r\n return this;\r\n }\r\n /**\r\n * Computes the required SubMeshes according the materials assigned to the particles.\r\n * @returns the solid particle system.\r\n * Does nothing if called before the SPS mesh is built.\r\n */\r\n public computeSubMeshes(): SolidParticleSystem {\r\n if (!this.mesh || !this._multimaterialEnabled) {\r\n return this;\r\n }\r\n const depthSortedParticles = this.depthSortedParticles;\r\n if (this.particles.length > 0) {\r\n for (let p = 0; p < this.particles.length; p++) {\r\n const part = this.particles[p];\r\n if (!part.materialIndex) {\r\n part.materialIndex = 0;\r\n }\r\n const sortedPart = depthSortedParticles[p];\r\n sortedPart.materialIndex = part.materialIndex;\r\n sortedPart.ind = part._ind;\r\n sortedPart.indicesLength = part._model._indicesLength;\r\n sortedPart.idx = part.idx;\r\n }\r\n }\r\n this._sortParticlesByMaterial();\r\n const indicesByMaterial = this._indicesByMaterial;\r\n const materialIndexes = this._materialIndexes;\r\n const mesh = this.mesh;\r\n mesh.subMeshes = [];\r\n const vcount = mesh.getTotalVertices();\r\n for (let m = 0; m < materialIndexes.length; m++) {\r\n const start = indicesByMaterial[m];\r\n const count = indicesByMaterial[m + 1] - start;\r\n const matIndex = materialIndexes[m];\r\n new SubMesh(matIndex, 0, vcount, start, count, mesh);\r\n }\r\n return this;\r\n }\r\n /**\r\n * Sorts the solid particles by material when MultiMaterial is enabled.\r\n * Updates the indices32 array.\r\n * Updates the indicesByMaterial array.\r\n * Updates the mesh indices array.\r\n * @returns the SPS\r\n * @internal\r\n */\r\n protected _sortParticlesByMaterial(): SolidParticleSystem {\r\n const indicesByMaterial = [0];\r\n this._indicesByMaterial = indicesByMaterial;\r\n const materialIndexes: number[] = [];\r\n this._materialIndexes = materialIndexes;\r\n const depthSortedParticles = this.depthSortedParticles;\r\n depthSortedParticles.sort(this._materialSortFunction);\r\n const length = depthSortedParticles.length;\r\n const indices32 = this._indices32;\r\n const indices = this._indices;\r\n\r\n let subMeshIndex = 0;\r\n let subMeshFaceId = 0;\r\n let sid = 0;\r\n let lastMatIndex = depthSortedParticles[0].materialIndex;\r\n materialIndexes.push(lastMatIndex);\r\n if (this._pickable) {\r\n this.pickedBySubMesh = [[]];\r\n this.pickedParticles = this.pickedBySubMesh[0];\r\n }\r\n for (let sorted = 0; sorted < length; sorted++) {\r\n const sortedPart = depthSortedParticles[sorted];\r\n const lind = sortedPart.indicesLength;\r\n const sind = sortedPart.ind;\r\n if (sortedPart.materialIndex !== lastMatIndex) {\r\n lastMatIndex = sortedPart.materialIndex;\r\n indicesByMaterial.push(sid);\r\n materialIndexes.push(lastMatIndex);\r\n if (this._pickable) {\r\n subMeshIndex++;\r\n this.pickedBySubMesh[subMeshIndex] = [];\r\n subMeshFaceId = 0;\r\n }\r\n }\r\n let faceId = 0;\r\n for (let i = 0; i < lind; i++) {\r\n indices32[sid] = indices[sind + i];\r\n if (this._pickable) {\r\n const f = i % 3;\r\n if (f == 0) {\r\n const pickedData = this.pickedBySubMesh[subMeshIndex][subMeshFaceId];\r\n if (pickedData) {\r\n pickedData.idx = sortedPart.idx;\r\n pickedData.faceId = faceId;\r\n } else {\r\n this.pickedBySubMesh[subMeshIndex][subMeshFaceId] = { idx: sortedPart.idx, faceId: faceId };\r\n }\r\n subMeshFaceId++;\r\n faceId++;\r\n }\r\n }\r\n sid++;\r\n }\r\n }\r\n\r\n indicesByMaterial.push(indices32.length); // add the last number to ease the indices start/count values for subMeshes creation\r\n if (this._updatable) {\r\n this.mesh.updateIndices(indices32);\r\n }\r\n return this;\r\n }\r\n /**\r\n * Sets the material indexes by id materialIndexesById[id] = materialIndex\r\n * @internal\r\n */\r\n protected _setMaterialIndexesById() {\r\n this._materialIndexesById = {};\r\n for (let i = 0; i < this._materials.length; i++) {\r\n const id = this._materials[i].uniqueId;\r\n this._materialIndexesById[id] = i;\r\n }\r\n }\r\n /**\r\n * Returns an array with unique values of Materials from the passed array\r\n * @param array the material array to be checked and filtered\r\n * @internal\r\n */\r\n protected _filterUniqueMaterialId(array: Material[]): Material[] {\r\n const filtered = array.filter(function (value, index, self) {\r\n return self.indexOf(value) === index;\r\n });\r\n return filtered;\r\n }\r\n /**\r\n * Sets a new Standard Material as _defaultMaterial if not already set.\r\n * @internal\r\n */\r\n protected _setDefaultMaterial(): Material {\r\n if (!this._defaultMaterial) {\r\n this._defaultMaterial = new StandardMaterial(this.name + \"DefaultMaterial\", this._scene);\r\n }\r\n return this._defaultMaterial;\r\n }\r\n /**\r\n * Visibility helper : Recomputes the visible size according to the mesh bounding box\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\r\n * @returns the SPS.\r\n */\r\n public refreshVisibleSize(): SolidParticleSystem {\r\n if (!this._isVisibilityBoxLocked) {\r\n this.mesh.refreshBoundingInfo();\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.\r\n * @param size the size (float) of the visibility box\r\n * note : this doesn't lock the SPS mesh bounding box.\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\r\n */\r\n public setVisibilityBox(size: number): void {\r\n const vis = size / 2;\r\n this.mesh.buildBoundingInfo(new Vector3(-vis, -vis, -vis), new Vector3(vis, vis, vis));\r\n }\r\n\r\n /**\r\n * Gets whether the SPS as always visible or not\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\r\n */\r\n public get isAlwaysVisible(): boolean {\r\n return this._alwaysVisible;\r\n }\r\n\r\n /**\r\n * Sets the SPS as always visible or not\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\r\n */\r\n public set isAlwaysVisible(val: boolean) {\r\n this._alwaysVisible = val;\r\n this.mesh.alwaysSelectAsActiveMesh = val;\r\n }\r\n\r\n /**\r\n * Sets the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\r\n */\r\n public set isVisibilityBoxLocked(val: boolean) {\r\n this._isVisibilityBoxLocked = val;\r\n\r\n const boundingInfo = this.mesh.getBoundingInfo();\r\n\r\n boundingInfo.isLocked = val;\r\n }\r\n\r\n /**\r\n * Gets if the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility\r\n */\r\n public get isVisibilityBoxLocked(): boolean {\r\n return this._isVisibilityBoxLocked;\r\n }\r\n\r\n /**\r\n * Tells to `setParticles()` to compute the particle rotations or not.\r\n * Default value : true. The SPS is faster when it's set to false.\r\n * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.\r\n */\r\n public set computeParticleRotation(val: boolean) {\r\n this._computeParticleRotation = val;\r\n }\r\n\r\n /**\r\n * Tells to `setParticles()` to compute the particle colors or not.\r\n * Default value : true. The SPS is faster when it's set to false.\r\n * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.\r\n */\r\n public set computeParticleColor(val: boolean) {\r\n this._computeParticleColor = val;\r\n }\r\n\r\n public set computeParticleTexture(val: boolean) {\r\n this._computeParticleTexture = val;\r\n }\r\n /**\r\n * Tells to `setParticles()` to call the vertex function for each vertex of each particle, or not.\r\n * Default value : false. The SPS is faster when it's set to false.\r\n * Note : the particle custom vertex positions aren't stored values.\r\n */\r\n public set computeParticleVertex(val: boolean) {\r\n this._computeParticleVertex = val;\r\n }\r\n /**\r\n * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.\r\n */\r\n public set computeBoundingBox(val: boolean) {\r\n this._computeBoundingBox = val;\r\n }\r\n /**\r\n * Tells to `setParticles()` to sort or not the distance between each particle and the camera.\r\n * Skipped when `enableDepthSort` is set to `false` (default) at construction time.\r\n * Default : `true`\r\n */\r\n public set depthSortParticles(val: boolean) {\r\n this._depthSortParticles = val;\r\n }\r\n\r\n /**\r\n * Gets if `setParticles()` computes the particle rotations or not.\r\n * Default value : true. The SPS is faster when it's set to false.\r\n * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.\r\n */\r\n public get computeParticleRotation(): boolean {\r\n return this._computeParticleRotation;\r\n }\r\n\r\n /**\r\n * Gets if `setParticles()` computes the particle colors or not.\r\n * Default value : true. The SPS is faster when it's set to false.\r\n * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.\r\n */\r\n public get computeParticleColor(): boolean {\r\n return this._computeParticleColor;\r\n }\r\n\r\n /**\r\n * Gets if `setParticles()` computes the particle textures or not.\r\n * Default value : true. The SPS is faster when it's set to false.\r\n * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.\r\n */\r\n public get computeParticleTexture(): boolean {\r\n return this._computeParticleTexture;\r\n }\r\n\r\n /**\r\n * Gets if `setParticles()` calls the vertex function for each vertex of each particle, or not.\r\n * Default value : false. The SPS is faster when it's set to false.\r\n * Note : the particle custom vertex positions aren't stored values.\r\n */\r\n public get computeParticleVertex(): boolean {\r\n return this._computeParticleVertex;\r\n }\r\n\r\n /**\r\n * Gets if `setParticles()` computes or not the mesh bounding box when computing the particle positions.\r\n */\r\n public get computeBoundingBox(): boolean {\r\n return this._computeBoundingBox;\r\n }\r\n\r\n /**\r\n * Gets if `setParticles()` sorts or not the distance between each particle and the camera.\r\n * Skipped when `enableDepthSort` is set to `false` (default) at construction time.\r\n * Default : `true`\r\n */\r\n public get depthSortParticles(): boolean {\r\n return this._depthSortParticles;\r\n }\r\n\r\n /**\r\n * Gets if the SPS is created as expandable at construction time.\r\n * Default : `false`\r\n */\r\n public get expandable(): boolean {\r\n return this._expandable;\r\n }\r\n /**\r\n * Gets if the SPS supports the Multi Materials\r\n */\r\n public get multimaterialEnabled(): boolean {\r\n return this._multimaterialEnabled;\r\n }\r\n /**\r\n * Gets if the SPS uses the model materials for its own multimaterial.\r\n */\r\n public get useModelMaterial(): boolean {\r\n return this._useModelMaterial;\r\n }\r\n /**\r\n * The SPS used material array.\r\n */\r\n public get materials(): Material[] {\r\n return this._materials;\r\n }\r\n /**\r\n * Sets the SPS MultiMaterial from the passed materials.\r\n * Note : the passed array is internally copied and not used then by reference.\r\n * @param materials an array of material objects. This array indexes are the materialIndex values of the particles.\r\n */\r\n public setMultiMaterial(materials: Material[]) {\r\n this._materials = this._filterUniqueMaterialId(materials);\r\n this._setMaterialIndexesById();\r\n if (this._multimaterial) {\r\n this._multimaterial.dispose();\r\n }\r\n this._multimaterial = new MultiMaterial(this.name + \"MultiMaterial\", this._scene);\r\n for (let m = 0; m < this._materials.length; m++) {\r\n this._multimaterial.subMaterials.push(this._materials[m]);\r\n }\r\n this.computeSubMeshes();\r\n this.mesh.material = this._multimaterial;\r\n }\r\n /**\r\n * The SPS computed multimaterial object\r\n */\r\n public get multimaterial(): MultiMaterial {\r\n return this._multimaterial;\r\n }\r\n public set multimaterial(mm) {\r\n this._multimaterial = mm;\r\n }\r\n /**\r\n * If the subMeshes must be updated on the next call to setParticles()\r\n */\r\n public get autoUpdateSubMeshes(): boolean {\r\n return this._autoUpdateSubMeshes;\r\n }\r\n public set autoUpdateSubMeshes(val: boolean) {\r\n this._autoUpdateSubMeshes = val;\r\n }\r\n // =======================================================================\r\n // Particle behavior logic\r\n // these following methods may be overwritten by the user to fit his needs\r\n\r\n /**\r\n * This function does nothing. It may be overwritten to set all the particle first values.\r\n * The SPS doesn't call this function, you may have to call it by your own.\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles\r\n */\r\n public initParticles(): void {}\r\n\r\n /**\r\n * This function does nothing. It may be overwritten to recycle a particle.\r\n * The SPS doesn't call this function, you may have to call it by your own.\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles\r\n * @param particle The particle to recycle\r\n * @returns the recycled particle\r\n */\r\n public recycleParticle(particle: SolidParticle): SolidParticle {\r\n return particle;\r\n }\r\n\r\n /**\r\n * Updates a particle : this function should be overwritten by the user.\r\n * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles\r\n * @example : just set a particle position or velocity and recycle conditions\r\n * @param particle The particle to update\r\n * @returns the updated particle\r\n */\r\n public updateParticle(particle: SolidParticle): SolidParticle {\r\n return particle;\r\n }\r\n\r\n /**\r\n * Updates a vertex of a particle : it can be overwritten by the user.\r\n * This will be called on each vertex particle by `setParticles()` if `computeParticleVertex` is set to true only.\r\n * @param particle the current particle\r\n * @param vertex the current vertex of the current particle : a SolidParticleVertex object\r\n * @param pt the index of the current vertex in the particle shape\r\n * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_vertices\r\n * @example : just set a vertex particle position or color\r\n * @returns the sps\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public updateParticleVertex(particle: SolidParticle, vertex: SolidParticleVertex, pt: number): SolidParticleSystem {\r\n return this;\r\n }\r\n\r\n /**\r\n * This will be called before any other treatment by `setParticles()` and will be passed three parameters.\r\n * This does nothing and may be overwritten by the user.\r\n * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\r\n * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\r\n * @param update the boolean update value actually passed to setParticles()\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void {}\r\n /**\r\n * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.\r\n * This will be passed three parameters.\r\n * This does nothing and may be overwritten by the user.\r\n * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\r\n * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()\r\n * @param update the boolean update value actually passed to setParticles()\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public afterUpdateParticles(start?: number, stop?: number, update?: boolean): void {}\r\n}\r\n","import { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\n\r\n/** This will mutate the mesh geometry. Only use this on temp/intermediate mesh data */\r\nexport function ensureNormalsExist(mesh: Mesh) {\r\n if (!mesh.getVerticesData(VertexBuffer.NormalKind)) {\r\n mesh.createNormals(true);\r\n mesh.convertToFlatShadedMesh();\r\n }\r\n}\r\n","import { Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { SolidParticle } from '@babylonjs/core/Particles/solidParticle';\r\nimport { SolidParticleSystem } from '@babylonjs/core/Particles/solidParticleSystem';\r\nimport { IKbVectorLike, KbVector } from '@models/classes';\r\nimport { PatternFeature } from '@models/classes/features/pattern-feature';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { SketchNode } from '@models/classes/meshes/sketch-node';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\nimport { ensureNormalsExist } from './utils';\r\n\r\ntype ParticleUpdaterFunction = (\r\n result: SolidParticle,\r\n iterator: IterableIterator,\r\n index?: number\r\n) => void;\r\ninterface IPatternDef {\r\n sps: SolidParticleSystem;\r\n size: number;\r\n resultMesh?: Mesh;\r\n sourceNode: MeshNode;\r\n featureUpdaters: Map;\r\n needsUpdate: boolean; // Whether we need to reposition the particles on this pattern\r\n needsRebuild: boolean; // Whether we need to rebuild the pattern mesh to create less or more geometry polygons\r\n needsSubmeshRebuild: boolean; // Whether we need to rebuild the submesh data on the pattern mesh\r\n shape: Mesh;\r\n}\r\nconst patternStore = new Map();\r\nconst identityRotation = Quaternion.Identity();\r\n\r\nexport abstract class PatternRenderer extends FeatureRenderer {\r\n update3dInternal() {}\r\n\r\n updateMeshGeometry(\r\n feature: PatternFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial,\r\n setParticlePositionFunc?: (idx: number, particle: SolidParticle) => void\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n\r\n const meshNode = feature._parent!;\r\n const mesh = this.viewer.getRendererNode(meshNode);\r\n\r\n if (mesh) {\r\n /** See line 156 */\r\n // let _pattern = patternStore.get(meshNode._dynamicId);\r\n let _pattern = null;\r\n\r\n // If there are no enabled pattern features before this one, update the pattern shape as some geometry may have changed\r\n if (!_pattern) {\r\n const meshUpdated = new Mesh('patternTempGeometry');\r\n meshUpdated.setEnabled(false);\r\n const tempVertexData = new SubmeshVertexData();\r\n tempVertexData.copyFrom(newVertexData);\r\n tempVertexData.applyToMesh(meshUpdated, false);\r\n\r\n ensureNormalsExist(meshUpdated);\r\n\r\n const sps = new SolidParticleSystem(`${mesh.id}_${feature._dynamicId}`, this.scene, {\r\n enableDepthSort: true,\r\n enableMultiMaterial: true,\r\n expandable: true,\r\n });\r\n\r\n if (feature) {\r\n if (feature.meshId) {\r\n const sketchNode = this.viewer.getNode(feature.meshId);\r\n if (sketchNode instanceof SketchNode) {\r\n let distance = feature.distance;\r\n if (distance <= 0) {\r\n distance = 1;\r\n }\r\n const positionArray = this.getPositionArray(\r\n sketchNode,\r\n feature.distance,\r\n feature.addEndMesh\r\n );\r\n sps.addShape(meshUpdated, positionArray.length);\r\n sps.counter = positionArray.length;\r\n feature.count = positionArray.length;\r\n const sketchPosition = sketchNode.position.toVec3();\r\n sps.initParticles = () => {\r\n for (let p = 0; p < sps.counter; p++) {\r\n const particle = sps.particles[p];\r\n particle.position = positionArray[p].add(sketchPosition);\r\n }\r\n };\r\n }\r\n } else {\r\n sps.addShape(meshUpdated, feature.count + 1);\r\n sps.initParticles = () => {\r\n for (let p = 0; p < sps.nbParticles; p++) {\r\n const particle = sps.particles[p];\r\n if (particle.rotationQuaternion) {\r\n particle.rotationQuaternion!.copyFrom(identityRotation);\r\n } else {\r\n particle.rotationQuaternion = Quaternion.Identity();\r\n }\r\n particle.position.setAll(0);\r\n }\r\n };\r\n }\r\n }\r\n\r\n const newPattern: IPatternDef = {\r\n sps,\r\n size: 1,\r\n featureUpdaters: new Map(),\r\n sourceNode: meshNode,\r\n needsUpdate: true,\r\n needsRebuild: true,\r\n needsSubmeshRebuild: true,\r\n shape: meshUpdated,\r\n };\r\n sps.updateParticle = particle => {\r\n // Process the last update function as it will call the prior ones recursively\r\n const updates = newPattern.featureUpdaters.values();\r\n const update: ParticleUpdaterFunction = updates.next().value;\r\n update(particle, updates);\r\n // Do we need this?\r\n // particle.scaling.copyFrom(mesh.scaling);\r\n return particle;\r\n };\r\n patternStore.set(meshNode._dynamicId, newPattern);\r\n _pattern = newPattern;\r\n }\r\n const pattern = _pattern;\r\n pattern.needsUpdate = true;\r\n\r\n pattern.featureUpdaters.set(feature._dynamicId, (particle, iterator, index) => {\r\n if (feature.enabled) {\r\n const particleIndex = particle.idx;\r\n if (particleIndex >= pattern.size) {\r\n particle.isVisible = false;\r\n return;\r\n }\r\n if (!particle.isVisible) {\r\n particle.isVisible = true;\r\n }\r\n const featureItemIndex = index !== undefined ? index : particleIndex;\r\n\r\n const i = featureItemIndex % feature.count;\r\n if (i > 0 && setParticlePositionFunc) {\r\n setParticlePositionFunc(i, particle);\r\n }\r\n\r\n const nextUpdateFunction: ParticleUpdaterFunction = iterator.next().value;\r\n if (nextUpdateFunction) {\r\n nextUpdateFunction(particle, iterator, Math.floor(featureItemIndex / feature.count));\r\n }\r\n }\r\n });\r\n\r\n pattern.size = Array.from(pattern.featureUpdaters.keys()).reduce((result, featureId) => {\r\n const feature = meshNode.features.find(feature => feature._dynamicId === featureId) as PatternFeature;\r\n return result * feature!.count;\r\n }, 1);\r\n\r\n if (\r\n !pattern.needsRebuild &&\r\n (vertexDataChanges.indices || vertexDataChanges.positions || vertexDataChanges.uvs)\r\n ) {\r\n /**\r\n * If the shape of the mesh changed, then we have to remove and re-add every particle to recompute the geometry.\r\n * Potential optimization here is to only recompute vertex positions if the vertex count is the same,\r\n * and only do the following expensive operation if the vertex count (indices?) changes.\r\n */\r\n const currentSize = pattern.sps.nbParticles;\r\n pattern.sps.addShape(pattern.shape, Math.max(pattern.size, pattern.sps.nbParticles));\r\n pattern.sps.removeParticles(0, currentSize - 1);\r\n pattern.needsRebuild = true;\r\n } else if (pattern.sps.nbParticles < pattern.size) {\r\n // If we don't have enough particles to complete the pattern, expand the SPS as needed\r\n pattern.sps.addShape(pattern.shape, pattern.size - pattern.sps.nbParticles);\r\n pattern.needsRebuild = true;\r\n }\r\n\r\n if (vertexDataChanges.submeshData) {\r\n pattern.needsSubmeshRebuild = true;\r\n }\r\n\r\n /**\r\n * We are removing the pattern feature combination system because it was causing a lot of issues around the cache, with enabling/disabling and reordering features.\r\n * In the future we will just add multi-direction properties into the pattern feature instead.\r\n */\r\n // const nextFeature = meshNode.features[thisIndex + 1];\r\n // if (!nextFeature || !(nextFeature instanceof PatternFeature)) {\r\n this.processParticleSystem(pattern, newVertexData); // mutates newVertexData\r\n patternStore.delete(meshNode._dynamicId); // Delete the pattern since we are done processing it\r\n // }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n processParticleSystem(pattern: IPatternDef, resultVertexData: Partial) {\r\n if (!pattern.needsUpdate) {\r\n return;\r\n }\r\n\r\n // Shrink the particle system if there are way too many particles (more than 50% too many)\r\n // We don't want to shrink unless necessary beca use there's a performance hit to rebuilding the mesh\r\n if (pattern.sps.nbParticles - pattern.size > pattern.size / 2) {\r\n pattern.sps.removeParticles(pattern.size, pattern.sps.nbParticles - 1);\r\n pattern.needsRebuild = true;\r\n }\r\n\r\n pattern.sps.initParticles();\r\n\r\n if (!pattern.resultMesh || pattern.needsRebuild) {\r\n pattern.resultMesh = pattern.sps.buildMesh();\r\n pattern.needsRebuild = false;\r\n pattern.needsSubmeshRebuild = true;\r\n pattern.resultMesh.setEnabled(false);\r\n }\r\n\r\n pattern.sps.computeBoundingBox = true;\r\n pattern.sps.setParticles();\r\n\r\n const totalIndicesSourceCount = resultVertexData.indices!.length;\r\n const totalVerticesSourceCount = resultVertexData.positions!.length / 3;\r\n\r\n const newVertexData = VertexData.ExtractFromMesh(pattern.resultMesh);\r\n resultVertexData.indices = newVertexData.indices;\r\n resultVertexData.positions = newVertexData.positions;\r\n if (newVertexData.normals) {\r\n resultVertexData.normals = newVertexData.normals;\r\n }\r\n if (resultVertexData.uvs && newVertexData.uvs) {\r\n // Don't add UVs if UVs never existed\r\n resultVertexData.uvs = newVertexData.uvs;\r\n }\r\n\r\n // If the source mesh has submeshes, then we need to update them\r\n if (resultVertexData.submeshData) {\r\n const submeshesToClone = resultVertexData.submeshData.slice(1);\r\n\r\n const totalIndicesResultCount = resultVertexData.indices!.length;\r\n const totalVerticesResultCount = resultVertexData.positions!.length / 3;\r\n // resultMeshCsg.dispose();\r\n const baseMaterialIndex = resultVertexData.submeshData[0].materialIndex;\r\n\r\n resultVertexData.submeshData = [];\r\n resultVertexData.submeshData.push({\r\n materialIndex: baseMaterialIndex,\r\n verticesStart: 0,\r\n verticesCount: totalVerticesResultCount,\r\n indexStart: 0,\r\n indexCount: totalIndicesResultCount,\r\n });\r\n\r\n const spsPatternSize = totalVerticesResultCount / totalVerticesSourceCount;\r\n\r\n if (submeshesToClone.length > 0) {\r\n submeshesToClone.forEach(subMesh => {\r\n for (let i = 0; i < spsPatternSize; i++) {\r\n resultVertexData.submeshData!.push({\r\n materialIndex: subMesh.materialIndex,\r\n verticesStart: subMesh.verticesStart + i * totalVerticesSourceCount,\r\n verticesCount: subMesh.verticesCount,\r\n indexStart: subMesh.indexStart + i * totalIndicesSourceCount,\r\n indexCount: subMesh.indexCount,\r\n });\r\n }\r\n });\r\n }\r\n }\r\n }\r\n\r\n getPositionArray(node: SketchNode, distance: number, addEndMesh: boolean) {\r\n const result: Vector3[] = [];\r\n const sketchLength = node.getSketchLength();\r\n const numberOfMeshes = sketchLength / distance;\r\n const percentagePoints: number[] = [];\r\n for (let i = 0; i < numberOfMeshes; i++) {\r\n percentagePoints.push((1 / numberOfMeshes) * i);\r\n }\r\n\r\n percentagePoints.forEach(point => {\r\n result.push(this.getIntervalPosition(node, point));\r\n });\r\n\r\n if (addEndMesh) {\r\n const lastPath = node.paths[node.paths.length - 1];\r\n const lastPoint = lastPath._points[lastPath._points.length - 1];\r\n const lastPointVec3 = new Vector3(lastPoint.x, lastPoint.y, lastPoint.z);\r\n result.push(lastPointVec3);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n protected getIntervalPosition(node: SketchNode, posZeroToOne: number) {\r\n const result = new Vector3(0, 0, 0);\r\n const sketchLength = node.getSketchLength();\r\n let trackedLength = 0;\r\n let targetNotFound = true;\r\n node.paths.forEach(path => {\r\n let lastPosition: IKbVectorLike | null = null;\r\n let lastLength = 0;\r\n path._points.forEach(point => {\r\n if (!lastPosition) {\r\n lastPosition = point;\r\n } else {\r\n const currentPos = point;\r\n const distance = Math.sqrt(\r\n Math.pow(lastPosition.x - currentPos.x, 2) +\r\n Math.pow(lastPosition.y - currentPos.y, 2) +\r\n Math.pow(lastPosition.z - currentPos.z, 2)\r\n );\r\n lastLength = trackedLength;\r\n trackedLength += distance;\r\n const distanceBetweenPoints = trackedLength - lastLength;\r\n const distanceFromP1toTarget = posZeroToOne * sketchLength - lastLength;\r\n const percentageBetween2Points = distanceFromP1toTarget / distanceBetweenPoints;\r\n const vectorBetween2Points = new KbVector(\r\n currentPos.x - lastPosition.x,\r\n currentPos.y - lastPosition.y,\r\n currentPos.z - lastPosition.z\r\n );\r\n if (trackedLength > posZeroToOne * sketchLength && targetNotFound) {\r\n const calculatedPosition = vectorBetween2Points\r\n .scale(percentageBetween2Points)\r\n .add(lastPosition);\r\n result.set(calculatedPosition.x, calculatedPosition.y, calculatedPosition.z);\r\n targetNotFound = false;\r\n }\r\n lastPosition = currentPos;\r\n }\r\n });\r\n if (posZeroToOne === 1) {\r\n const path = node.paths[node.paths.length - 1];\r\n const controlPoint = path._points[path._points.length - 1];\r\n result.set(controlPoint.x, controlPoint.y, controlPoint.z);\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n delete3d(feature: ITrackedClass, preserveCache?: boolean) {\r\n patternStore.forEach((pattern, meshNode) => {\r\n if (pattern.featureUpdaters.has(feature._dynamicId)) {\r\n pattern.featureUpdaters.delete(feature._dynamicId);\r\n }\r\n if (pattern.featureUpdaters.size === 0) {\r\n patternStore.delete(meshNode);\r\n }\r\n });\r\n\r\n super.delete3d(feature, preserveCache);\r\n }\r\n\r\n dispose() {\r\n super.dispose();\r\n patternStore.clear();\r\n }\r\n}\r\n","import { MultiMaterial } from '@babylonjs/core/Materials/multiMaterial';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eUvMode } from '@models/classes';\r\nimport { SubmeshData, SubmeshFeature } from '@models/classes/features/submesh-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { UVMapHelper } from '@view/helpers/uvmap-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { RendererManager } from '../renderer-manager';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nconst uvHelper = new UVMapHelper();\r\nconst multiMaterialUseCount = new Map();\r\nconst featureMappings = new Map<\r\n string,\r\n { multiMaterial?: MultiMaterial; multiMaterialIndex?: number; initialized?: boolean }\r\n>();\r\n\r\nexport class SubmeshRenderer extends FeatureRenderer {\r\n constructor(viewer: KbViewer, scene: Scene, private rendererManager: RendererManager) {\r\n super(viewer, scene);\r\n }\r\n modelToken = Token.SubmeshFeature;\r\n updateMeshGeometry(\r\n feature: ITrackedClass,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n const submeshFeatureMapping = featureMappings.get(feature._dynamicId);\r\n\r\n if (!submeshFeatureMapping) {\r\n console.warn(`INFO: Submesh mapping not found for ${feature.name}`);\r\n return newVertexData;\r\n }\r\n\r\n if (!newVertexData.submeshData) {\r\n newVertexData.submeshData = [];\r\n }\r\n\r\n if (submeshFeatureMapping.multiMaterialIndex) {\r\n const verticesCount = (vertexDataChanges.positions || newVertexData.positions!).length / 3;\r\n const indicesCount = (vertexDataChanges.indices || newVertexData.indices!).length;\r\n\r\n for (let i = 0; i < feature.vertexGroups.length; i++) {\r\n const vertexGroup = feature.vertexGroups[i];\r\n\r\n const newSubmesh: SubmeshData = {\r\n materialIndex: submeshFeatureMapping.multiMaterialIndex,\r\n verticesStart: 0,\r\n verticesCount: verticesCount,\r\n indexStart: vertexGroup.startIndex,\r\n indexCount: Math.min(vertexGroup.endIndex, indicesCount) - vertexGroup.startIndex,\r\n };\r\n\r\n const existingIndex = newVertexData.submeshData.findIndex(\r\n existingSubmesh =>\r\n existingSubmesh.materialIndex === newSubmesh.materialIndex &&\r\n existingSubmesh.verticesStart === newSubmesh.verticesStart &&\r\n existingSubmesh.verticesCount === newSubmesh.verticesCount &&\r\n existingSubmesh.indexStart === newSubmesh.indexStart &&\r\n existingSubmesh.indexCount === newSubmesh.indexCount\r\n );\r\n\r\n if (existingIndex >= 0) {\r\n newVertexData.submeshData.splice(existingIndex, 1);\r\n }\r\n\r\n newVertexData.submeshData.push(newSubmesh);\r\n }\r\n }\r\n\r\n // Calculate UV maps if that is enabled on this feature\r\n if (feature.uvMapping) {\r\n const uvMapVertexes: number[] = [];\r\n\r\n for (let i = 0; i < feature.vertexGroups.length; i++) {\r\n const vertexGroup = feature.vertexGroups[i];\r\n\r\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\r\n uvMapVertexes.push(i);\r\n }\r\n }\r\n\r\n if (uvMapVertexes.length > 0) {\r\n let existingUvs: number[] = [];\r\n if (newVertexData.uvs) {\r\n existingUvs = [...newVertexData.uvs];\r\n }\r\n\r\n uvHelper.generateUVMapInPlace(newVertexData, feature, uvMapVertexes);\r\n\r\n // for projection mode \"use existing\", only apply the new uvs to the selected faces of the submesh\r\n if (feature.mode === eUvMode.useExisting) {\r\n feature.vertexGroups.forEach(vertexGroup => {\r\n for (let i = vertexGroup.startIndex; i < vertexGroup.endIndex; i++) {\r\n if (newVertexData.indices && newVertexData.uvs) {\r\n existingUvs[newVertexData.indices[i] * 2] =\r\n newVertexData.uvs[newVertexData.indices[i] * 2];\r\n existingUvs[newVertexData.indices[i] * 2 + 1] =\r\n newVertexData.uvs[newVertexData.indices[i] * 2 + 1];\r\n }\r\n }\r\n });\r\n newVertexData.uvs = existingUvs;\r\n }\r\n }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal(feature: ITrackedClass) {\r\n let _submeshFeatureMapping = featureMappings.get(feature._dynamicId);\r\n\r\n if (feature.changes.has('materialId') || !_submeshFeatureMapping) {\r\n const meshNode = feature._parent!;\r\n const mesh = this.viewer.getRendererNode(meshNode) as Mesh;\r\n\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n if (!_submeshFeatureMapping) {\r\n _submeshFeatureMapping = {};\r\n featureMappings.set(feature._dynamicId, _submeshFeatureMapping);\r\n }\r\n\r\n const submeshFeatureMapping = _submeshFeatureMapping;\r\n\r\n if (feature.materialId) {\r\n if (!(mesh.material instanceof MultiMaterial)) {\r\n const multiMaterial = new MultiMaterial(meshNode._dynamicId, this.scene);\r\n if (mesh.material) {\r\n multiMaterial.subMaterials[0] = mesh.material;\r\n } else if (!mesh.material) {\r\n // If a submesh multimaterial has a null material at index 0, it causes shadows to not work\r\n multiMaterial.subMaterials[0] = this.rendererManager.material.defaultMaterial;\r\n }\r\n submeshFeatureMapping.multiMaterial = multiMaterial;\r\n multiMaterialUseCount.set(multiMaterial, 0);\r\n mesh.material = multiMaterial;\r\n } else {\r\n submeshFeatureMapping.multiMaterial = mesh.material;\r\n }\r\n\r\n this.rendererManager.mesh.fetchMaterialNode(meshNode, feature.materialId).then(\r\n materialNode => {\r\n // The material may have changed on the mesh, so we have to re-fetch the reference just in case.\r\n if (!(mesh.material instanceof MultiMaterial)) {\r\n throw Error('Another script has removed the multimaterial on a mesh');\r\n }\r\n const multiMaterial = mesh.material;\r\n if (multiMaterial !== submeshFeatureMapping.multiMaterial) {\r\n console.warn(\r\n `Submesh feature ${feature.name} lost reference to a multimaterial. Possible memory leak?`\r\n );\r\n submeshFeatureMapping.multiMaterial = multiMaterial;\r\n }\r\n\r\n // If the material is already part of the submaterials, do nothing\r\n const existingSubmaterialIndex = multiMaterial.subMaterials.findIndex(\r\n material => material?.id === materialNode._dynamicId\r\n );\r\n if (submeshFeatureMapping?.multiMaterialIndex === existingSubmaterialIndex) {\r\n return;\r\n } else if (existingSubmaterialIndex > -1) {\r\n submeshFeatureMapping.multiMaterialIndex = existingSubmaterialIndex;\r\n\r\n // Triggers change on this feature so the feature stack refreshes with the material index on this submesh\r\n feature.setPropertyIsModified('vertexGroups', true);\r\n } else {\r\n // init the material if the node is showing\r\n if (meshNode.visible) {\r\n materialNode.init();\r\n }\r\n\r\n const material = this.viewer.getRendererNode(materialNode);\r\n if (!material) {\r\n throw Error('Material could not be found in renderer. Has the material been created?');\r\n }\r\n\r\n submeshFeatureMapping.multiMaterialIndex = multiMaterial.subMaterials.length;\r\n multiMaterial.subMaterials.push(material);\r\n multiMaterialUseCount.set(\r\n multiMaterial,\r\n (multiMaterialUseCount.get(multiMaterial) || 0) + 1\r\n );\r\n\r\n // Triggers change on this feature so the feature stack refreshes with the material index on this submesh\r\n feature.setPropertyIsModified('vertexGroups', true);\r\n }\r\n },\r\n err => {\r\n feature.materialId = '';\r\n }\r\n );\r\n }\r\n }\r\n }\r\n\r\n public delete3d(feature: ITrackedClass, preserveCache?: boolean): void {\r\n if (!preserveCache) {\r\n const submeshFeatureMapping = featureMappings.get(feature._dynamicId);\r\n if (submeshFeatureMapping && submeshFeatureMapping.multiMaterial) {\r\n const multiMaterial = submeshFeatureMapping.multiMaterial;\r\n const count = multiMaterialUseCount.get(multiMaterial);\r\n\r\n if (count !== undefined) {\r\n if (count <= 1) {\r\n const meshNode = feature._parent!;\r\n const mesh = this.viewer.getRendererNode(meshNode) as Mesh;\r\n if (mesh) {\r\n mesh.material = multiMaterial.getSubMaterial(0);\r\n }\r\n multiMaterialUseCount.delete(multiMaterial);\r\n multiMaterial.dispose(true, true, false);\r\n } else {\r\n multiMaterialUseCount.set(multiMaterial, count - 1);\r\n }\r\n }\r\n }\r\n featureMappings.delete(feature._dynamicId);\r\n }\r\n super.delete3d(feature, preserveCache);\r\n }\r\n}\r\n","\r\nimport { Color3, Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { UvMapFeature } from '@models/classes/features/uv-map-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { rotationToVector } from '@view/helpers';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { createUvMapVisualization, UVMapHelper } from '@view/helpers/uvmap-helper';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nconst uvHelper = new UVMapHelper();\r\n\r\nexport class UvMapRenderer extends FeatureRenderer {\r\n modelToken = Token.UvMapFeature;\r\n babylonUvPreviewsMap = new Map();\r\n previewLayer: UtilityLayerRenderer = this.viewer.utilityLayer;\r\n\r\n updateMeshGeometry(\r\n feature: UvMapFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n\r\n uvHelper.generateUVMapInPlace(newVertexData, feature);\r\n\r\n return newVertexData;\r\n }\r\n\r\n protected updatePreviewMesh(feature: UvMapFeature) {\r\n let visualizationMesh = this.babylonUvPreviewsMap.get(feature.id);\r\n const scene = this.previewLayer.utilityLayerScene;\r\n\r\n if (!visualizationMesh) {\r\n visualizationMesh = createUvMapVisualization(feature, scene, Color3.Yellow());\r\n visualizationMesh.isPickable = false;\r\n this.babylonUvPreviewsMap.set(feature.id, visualizationMesh);\r\n } else {\r\n this.deletePreview3d(feature);\r\n visualizationMesh = createUvMapVisualization(feature, scene, Color3.Yellow());\r\n visualizationMesh.isPickable = false;\r\n this.babylonUvPreviewsMap.set(feature.id, visualizationMesh);\r\n }\r\n\r\n let meshPosition = visualizationMesh.getAbsolutePosition();\r\n if (feature._parent) {\r\n const featureParent = this.viewer.getRendererNode(feature._parent);\r\n meshPosition = featureParent.getAbsolutePosition();\r\n }\r\n meshPosition.add(feature.center.toVec3());\r\n meshPosition.addInPlace(feature.center.toVec3());\r\n visualizationMesh.position.set(meshPosition.x, meshPosition.y, meshPosition.z);\r\n //visualizationMesh.project;\r\n\r\n const newNormal = new Vector3();\r\n\r\n newNormal.set(feature.projectionAxis.x, feature.projectionAxis.y, feature.projectionAxis.z);\r\n\r\n visualizationMesh.rotationQuaternion = Quaternion.RotationAxis(newNormal, (feature.angle / 180) * Math.PI);\r\n visualizationMesh.rotationQuaternion = visualizationMesh.rotationQuaternion.multiply(\r\n rotationToVector(newNormal)\r\n );\r\n visualizationMesh.scaling.set(feature.scale.x, feature.scale.y, feature.scale.z);\r\n }\r\n\r\n update3dInternal(feature: ITrackedClass) {\r\n const visualizationMesh = this.babylonUvPreviewsMap.get(feature.id);\r\n\r\n visualizationMesh?.setEnabled(feature._previewMaterialVisible);\r\n\r\n // change visibility here\r\n if (feature._previewMaterialVisible) {\r\n this.updatePreviewMesh(feature);\r\n }\r\n }\r\n\r\n delete3d(feature: UvMapFeature) {\r\n this.deletePreview3d(feature);\r\n super.delete3d(feature as ITrackedClass);\r\n }\r\n\r\n deletePreview3d(feature: UvMapFeature) {\r\n const previewMesh = this.babylonUvPreviewsMap.get(feature.id);\r\n if (previewMesh) {\r\n previewMesh.dispose();\r\n }\r\n this.babylonUvPreviewsMap.delete(feature.id);\r\n }\r\n}\r\n","import {\r\n DirectionalLight,\r\n HemisphericLight,\r\n Light,\r\n PointLight,\r\n ShadowGenerator,\r\n ShadowLight,\r\n SpotLight,\r\n} from '@babylonjs/core/Lights';\r\nimport { Color3, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { DirectionalLightNode, HemisphericLightNode, PointLightNode, SpotLightNode, Token } from '@models/classes';\r\nimport { LightNode } from '@models/classes/lights/light-node';\r\nimport { ShadowLightNode } from '@models/classes/lights/shadow-light-node';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { createLightVisualization } from '@view/helpers/light-helper';\r\nimport { rotationToVector, toRadians } from '@view/helpers/math-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Renderer } from './renderer';\r\nimport { ShadowManager } from './shadow-manager';\r\n\r\ntype AnyLightNode = PointLightNode & DirectionalLightNode & HemisphericLightNode & SpotLightNode;\r\n\r\nexport class LightRenderer extends Renderer {\r\n babylonLightPreviewsMap = new Map();\r\n gizmoLayer: UtilityLayerRenderer;\r\n\r\n modelToken = Token.LightNode;\r\n\r\n set showPreviews(show: boolean) {\r\n this.showAllLightPreviews = show;\r\n this.babylonMap.forEach(light => {\r\n this.updatePreviewMesh(light);\r\n });\r\n }\r\n\r\n protected showAllLightPreviews = false;\r\n\r\n constructor(viewer: KbViewer, scene: Scene, private shadowManager: ShadowManager) {\r\n super(viewer, scene);\r\n this.gizmoLayer = this.viewer.utilityLayer;\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n if (!node._parent && node._parentScene?.isNested()) {\r\n //don't render global lights in nested scenes\r\n return;\r\n }\r\n\r\n let light = this.get3d(node);\r\n const changes = this.getChanges(node) as Map;\r\n\r\n if (!light) {\r\n if (node instanceof PointLightNode) {\r\n light = new PointLight(node._dynamicId, node.position.toVec3(), this.scene);\r\n } else if (node instanceof HemisphericLightNode) {\r\n light = new HemisphericLight(node._dynamicId, node.direction.toVec3(), this.scene);\r\n } else if (node instanceof SpotLightNode) {\r\n light = new SpotLight(\r\n node._dynamicId,\r\n node.position.toVec3(),\r\n node.direction.toVec3(),\r\n (node.coneAngle * Math.PI) / 180,\r\n 2,\r\n this.scene\r\n );\r\n (light as SpotLight).exponent = 2;\r\n } else if (node instanceof DirectionalLightNode) {\r\n light = new DirectionalLight(node._dynamicId, node.direction.toVec3(), this.scene);\r\n }\r\n\r\n this.set3d(node, light as Light);\r\n }\r\n\r\n const pLight = light as Light;\r\n\r\n if (changes.has('visible')) {\r\n // Can be falsy so need to check the map\r\n pLight.setEnabled(node.visible);\r\n }\r\n if (changes.has('intensity')) {\r\n // Can be falsy so need to check the map\r\n pLight.intensity = node.intensity;\r\n }\r\n if (changes.has('color')) {\r\n pLight.specular = node.color.toColor3();\r\n pLight.diffuse = node.color.toColor3();\r\n }\r\n if (changes.has('_parent')) {\r\n if (node._parent) {\r\n pLight.parent = this.viewer.getRendererNode(node._parent);\r\n } else {\r\n pLight.parent = null;\r\n }\r\n }\r\n\r\n let lightRotation: Quaternion;\r\n if (node.useEuler) {\r\n lightRotation = Quaternion.FromEulerAngles(\r\n toRadians(node.eulerRotation.x),\r\n toRadians(node.eulerRotation.y),\r\n toRadians(node.eulerRotation.z)\r\n );\r\n } else {\r\n lightRotation = Quaternion.RotationAxis(node.rotationAxis.toVec3(), toRadians(node.rotationAngle));\r\n }\r\n const rotationChanged = changes.hasAny('useEuler', 'eulerRotation', 'rotationAxis', 'rotationAngle');\r\n\r\n if (node instanceof PointLightNode) {\r\n const pLight = light as PointLight;\r\n if (changes.has('position')) {\r\n pLight.position = node.position.toVec3();\r\n }\r\n } else if (node instanceof HemisphericLightNode) {\r\n const pLight = light as HemisphericLight;\r\n if (changes.has('direction') || rotationChanged) {\r\n pLight.direction = this.rotateDirection(node.direction.toVec3(), lightRotation);\r\n }\r\n if (changes.has('groundColor')) {\r\n pLight.groundColor = node.groundColor.toColor3();\r\n }\r\n } else if (node instanceof SpotLightNode) {\r\n const pLight = light as SpotLight;\r\n if (changes.has('position')) {\r\n pLight.position = node.position.toVec3();\r\n }\r\n if (changes.has('direction') || rotationChanged) {\r\n pLight.direction = this.rotateDirection(node.direction.toVec3(), lightRotation);\r\n }\r\n if (changes.has('coneAngle')) {\r\n pLight.angle = (node.coneAngle * Math.PI) / 180;\r\n }\r\n } else if (node instanceof DirectionalLightNode) {\r\n const pLight = light as DirectionalLight;\r\n // pLight.position = new Vector3(0, 5, 0);\r\n if (changes.has('direction') || rotationChanged) {\r\n pLight.direction = this.rotateDirection(node.direction.toVec3(), lightRotation);\r\n //for directional lights, we hardcode the position to be negative direction for shadows\r\n pLight.position = pLight.direction.clone().negate();\r\n }\r\n }\r\n\r\n if (node instanceof ShadowLightNode) {\r\n const shadowLightNode = node as ITrackedClass;\r\n const shadowLight = light as ShadowLight;\r\n\r\n let sg = this.shadowManager.get(shadowLight);\r\n let justCreated = false;\r\n if (changes.has('generatesShadows')) {\r\n if (shadowLightNode.generatesShadows) {\r\n sg = this.shadowManager.add(shadowLight, shadowLightNode.shadowResolution);\r\n shadowLight.shadowEnabled = true;\r\n justCreated = true;\r\n changes.set('shadowFilter', shadowLightNode.shadowFilter);\r\n changes.set('shadowQuality', shadowLightNode.shadowQuality);\r\n } else {\r\n if (sg) {\r\n shadowLight.shadowEnabled = false;\r\n this.shadowManager.remove(shadowLight);\r\n sg = undefined;\r\n }\r\n }\r\n }\r\n\r\n //if the resolution is changed, and the shadow generator wasn't just created, we need to recreate it\r\n if (changes.has('shadowResolution') && sg && !justCreated) {\r\n this.shadowManager.remove(shadowLight);\r\n sg = this.shadowManager.add(shadowLight, shadowLightNode.shadowResolution);\r\n changes.set('shadowFilter', shadowLightNode.shadowFilter);\r\n changes.set('shadowQuality', shadowLightNode.shadowQuality);\r\n changes.set('processTransparency', shadowLightNode.processTransparency);\r\n }\r\n\r\n if (sg) {\r\n if (changes.has('shadowFilter')) {\r\n sg.filter = ShadowManager.convertShadowFilter(shadowLightNode.shadowFilter);\r\n }\r\n\r\n if (changes.has('processTransparency')) {\r\n sg.transparencyShadow = shadowLightNode.processTransparency;\r\n sg.enableSoftTransparentShadow = shadowLightNode.processTransparency;\r\n }\r\n\r\n if (changes.has('shadowQuality')) {\r\n sg.filteringQuality = (ShadowGenerator as any)[\r\n `QUALITY_${shadowLightNode.shadowQuality.toUpperCase()}`\r\n ];\r\n }\r\n\r\n //need to update projection matrix if direction has been changed\r\n if (changes.hasAny('direction', 'position')) {\r\n this.shadowManager.clearProjectMatrixCache();\r\n }\r\n }\r\n }\r\n\r\n if (changes.has('_selected')) {\r\n if (!pLight.metadata) {\r\n pLight.metadata = {};\r\n }\r\n pLight.metadata.selected = node._selected;\r\n }\r\n this.viewer.updateLightWarnings();\r\n this.updatePreviewMesh(pLight);\r\n }\r\n\r\n delete3d(node: ITrackedClass) {\r\n if (this.babylonLightPreviewsMap) {\r\n const lightPositionGizmo = this.babylonLightPreviewsMap.get(node._dynamicId);\r\n if (!lightPositionGizmo) {\r\n throw Error('Light gizmo not found for light ' + node.id);\r\n }\r\n lightPositionGizmo.dispose();\r\n this.babylonLightPreviewsMap!.delete(node._dynamicId);\r\n }\r\n\r\n this.shadowManager.remove(this.get3d(node) as ShadowLight); //remove also disposes the shadow generator if it exists\r\n\r\n super.delete3d(node);\r\n this.viewer.updateLightWarnings();\r\n }\r\n\r\n protected updatePreviewMesh(light: Light) {\r\n let lightPositionGizmo = this.babylonLightPreviewsMap.get(light.id);\r\n const scene = this.gizmoLayer.utilityLayerScene;\r\n\r\n if (!lightPositionGizmo) {\r\n lightPositionGizmo = createLightVisualization(light, scene, Color3.Yellow());\r\n lightPositionGizmo.isPickable = false;\r\n this.babylonLightPreviewsMap.set(light.id, lightPositionGizmo);\r\n }\r\n\r\n if (this.showAllLightPreviews) {\r\n lightPositionGizmo.setEnabled(light.metadata.selected || light.isEnabled());\r\n } else {\r\n lightPositionGizmo.setEnabled(light.metadata.selected);\r\n }\r\n\r\n if (light instanceof HemisphericLight) {\r\n lightPositionGizmo.rotationQuaternion = rotationToVector(light.direction);\r\n } else if (light instanceof SpotLight) {\r\n lightPositionGizmo.position = this.getLightPosition(light);\r\n lightPositionGizmo.rotationQuaternion = rotationToVector(light.direction);\r\n lightPositionGizmo.scaling.set(\r\n Math.sin(light.angle / 2),\r\n Math.cos(light.angle / 2),\r\n Math.sin(light.angle / 2)\r\n );\r\n } else if (light instanceof DirectionalLight) {\r\n lightPositionGizmo.rotationQuaternion = rotationToVector(light.direction);\r\n } else if (light instanceof PointLight) {\r\n lightPositionGizmo.position = this.getLightPosition(light);\r\n }\r\n }\r\n\r\n protected rotateDirection(direction: Vector3, rotation: Quaternion) {\r\n direction.rotateByQuaternionToRef(rotation, direction);\r\n return direction;\r\n }\r\n\r\n protected getLightPosition(light: SpotLight | PointLight) {\r\n return light.parent\r\n ? Vector3.TransformCoordinates(light.position, light.parent.computeWorldMatrix(true).clone())\r\n : light.position;\r\n }\r\n}\r\n","import { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { MateNode } from '@models/classes/mates/mate-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { SyncService } from '@models/services/sync-service';\r\nimport { Renderer } from './renderer';\r\n\r\nexport class MateRenderer extends Renderer {\r\n modelToken = Token.MateNode;\r\n\r\n update3dInternal(node: ITrackedClass) {}\r\n delete3d(node: ITrackedClass) {\r\n SyncService.nodeDeletionProcessed(node);\r\n }\r\n}\r\n","import { serializeAsMeshReference, serializeAsVector3, SerializationHelper } from \"../Misc/decorators\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport { AbstractScene } from \"../abstractScene\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\n\r\ndeclare module \"../abstractScene\" {\r\n export interface AbstractScene {\r\n /**\r\n * The list of reflection probes added to the scene\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes\r\n */\r\n reflectionProbes: Array;\r\n\r\n /**\r\n * Removes the given reflection probe from this scene.\r\n * @param toRemove The reflection probe to remove\r\n * @returns The index of the removed reflection probe\r\n */\r\n removeReflectionProbe(toRemove: ReflectionProbe): number;\r\n\r\n /**\r\n * Adds the given reflection probe to this scene.\r\n * @param newReflectionProbe The reflection probe to add\r\n */\r\n addReflectionProbe(newReflectionProbe: ReflectionProbe): void;\r\n }\r\n}\r\n\r\nAbstractScene.prototype.removeReflectionProbe = function (toRemove: ReflectionProbe): number {\r\n if (!this.reflectionProbes) {\r\n return -1;\r\n }\r\n\r\n const index = this.reflectionProbes.indexOf(toRemove);\r\n if (index !== -1) {\r\n this.reflectionProbes.splice(index, 1);\r\n }\r\n\r\n return index;\r\n};\r\n\r\nAbstractScene.prototype.addReflectionProbe = function (newReflectionProbe: ReflectionProbe): void {\r\n if (!this.reflectionProbes) {\r\n this.reflectionProbes = [];\r\n }\r\n\r\n this.reflectionProbes.push(newReflectionProbe);\r\n};\r\n\r\n/**\r\n * Class used to generate realtime reflection / refraction cube textures\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes\r\n */\r\nexport class ReflectionProbe {\r\n private _scene: Scene;\r\n private _renderTargetTexture: RenderTargetTexture;\r\n private _projectionMatrix: Matrix;\r\n private _viewMatrix = Matrix.Identity();\r\n private _target = Vector3.Zero();\r\n private _add = Vector3.Zero();\r\n @serializeAsMeshReference()\r\n private _attachedMesh: Nullable;\r\n\r\n private _invertYAxis = false;\r\n private _sceneUBOs: UniformBuffer[];\r\n private _currentSceneUBO: UniformBuffer;\r\n\r\n /** Gets or sets probe position (center of the cube map) */\r\n @serializeAsVector3()\r\n public position = Vector3.Zero();\r\n\r\n /**\r\n * Gets or sets an object used to store user defined information for the reflection probe.\r\n */\r\n public metadata: any = null;\r\n\r\n /** @internal */\r\n public _parentContainer: Nullable = null;\r\n\r\n /**\r\n * Creates a new reflection probe\r\n * @param name defines the name of the probe\r\n * @param size defines the texture resolution (for each face)\r\n * @param scene defines the hosting scene\r\n * @param generateMipMaps defines if mip maps should be generated automatically (true by default)\r\n * @param useFloat defines if HDR data (float data) should be used to store colors (false by default)\r\n * @param linearSpace defines if the probe should be generated in linear space or not (false by default)\r\n */\r\n constructor(\r\n /** defines the name of the probe */\r\n public name: string,\r\n size: number,\r\n scene: Scene,\r\n generateMipMaps = true,\r\n useFloat = false,\r\n linearSpace = false\r\n ) {\r\n this._scene = scene;\r\n\r\n if (scene.getEngine().supportsUniformBuffers) {\r\n this._sceneUBOs = [];\r\n for (let i = 0; i < 6; ++i) {\r\n this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name \"${name}\") face #${i}`));\r\n }\r\n }\r\n\r\n // Create the scene field if not exist.\r\n if (!this._scene.reflectionProbes) {\r\n this._scene.reflectionProbes = new Array();\r\n }\r\n this._scene.reflectionProbes.push(this);\r\n\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (useFloat) {\r\n const caps = this._scene.getEngine().getCaps();\r\n if (caps.textureHalfFloatRender) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n } else if (caps.textureFloatRender) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n }\r\n this._renderTargetTexture = new RenderTargetTexture(name, size, scene, generateMipMaps, true, textureType, true);\r\n this._renderTargetTexture.gammaSpace = !linearSpace;\r\n this._renderTargetTexture.invertZ = scene.useRightHandedSystem;\r\n\r\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\r\n\r\n this._renderTargetTexture.onBeforeRenderObservable.add((faceIndex: number) => {\r\n if (this._sceneUBOs) {\r\n scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);\r\n scene.getSceneUniformBuffer().unbindEffect();\r\n }\r\n switch (faceIndex) {\r\n case 0:\r\n this._add.copyFromFloats(1, 0, 0);\r\n break;\r\n case 1:\r\n this._add.copyFromFloats(-1, 0, 0);\r\n break;\r\n case 2:\r\n this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);\r\n break;\r\n case 3:\r\n this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);\r\n break;\r\n case 4:\r\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);\r\n break;\r\n case 5:\r\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);\r\n break;\r\n }\r\n\r\n if (this._attachedMesh) {\r\n this.position.copyFrom(this._attachedMesh.getAbsolutePosition());\r\n }\r\n\r\n this.position.addToRef(this._add, this._target);\r\n\r\n const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;\r\n const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;\r\n\r\n lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);\r\n\r\n if (scene.activeCamera) {\r\n this._projectionMatrix = perspectiveFunction(\r\n Math.PI / 2,\r\n 1,\r\n useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ,\r\n useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ,\r\n this._scene.getEngine().isNDCHalfZRange\r\n );\r\n scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);\r\n if (scene.activeCamera.isRigCamera && !this._renderTargetTexture.activeCamera) {\r\n this._renderTargetTexture.activeCamera = scene.activeCamera.rigParent || null;\r\n }\r\n }\r\n scene._forcedViewPosition = this.position;\r\n });\r\n\r\n let currentApplyByPostProcess: boolean;\r\n\r\n this._renderTargetTexture.onBeforeBindObservable.add(() => {\r\n this._currentSceneUBO = scene.getSceneUniformBuffer();\r\n scene.getEngine()._debugPushGroup?.(`reflection probe generation for ${name}`, 1);\r\n currentApplyByPostProcess = this._scene.imageProcessingConfiguration.applyByPostProcess;\r\n if (linearSpace) {\r\n scene.imageProcessingConfiguration.applyByPostProcess = true;\r\n }\r\n });\r\n\r\n this._renderTargetTexture.onAfterUnbindObservable.add(() => {\r\n scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;\r\n scene._forcedViewPosition = null;\r\n if (this._sceneUBOs) {\r\n scene.setSceneUniformBuffer(this._currentSceneUBO);\r\n }\r\n scene.updateTransformMatrix(true);\r\n scene.getEngine()._debugPopGroup?.(1);\r\n });\r\n }\r\n\r\n /** Gets or sets the number of samples to use for multi-sampling (0 by default). Required WebGL2 */\r\n public get samples(): number {\r\n return this._renderTargetTexture.samples;\r\n }\r\n\r\n public set samples(value: number) {\r\n this._renderTargetTexture.samples = value;\r\n }\r\n\r\n /** Gets or sets the refresh rate to use (on every frame by default) */\r\n public get refreshRate(): number {\r\n return this._renderTargetTexture.refreshRate;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n this._renderTargetTexture.refreshRate = value;\r\n }\r\n\r\n /**\r\n * Gets the hosting scene\r\n * @returns a Scene\r\n */\r\n public getScene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /** Gets the internal CubeTexture used to render to */\r\n public get cubeTexture(): RenderTargetTexture {\r\n return this._renderTargetTexture;\r\n }\r\n\r\n /** Gets the list of meshes to render */\r\n public get renderList(): Nullable {\r\n return this._renderTargetTexture.renderList;\r\n }\r\n\r\n /**\r\n * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)\r\n * @param mesh defines the mesh to attach to\r\n */\r\n public attachToMesh(mesh: Nullable): void {\r\n this._attachedMesh = mesh;\r\n }\r\n\r\n /**\r\n * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups\r\n * @param renderingGroupId The rendering group id corresponding to its index\r\n * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.\r\n */\r\n public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {\r\n this._renderTargetTexture.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);\r\n }\r\n\r\n /**\r\n * Clean all associated resources\r\n */\r\n public dispose() {\r\n const index = this._scene.reflectionProbes.indexOf(this);\r\n\r\n if (index !== -1) {\r\n // Remove from the scene if found\r\n this._scene.reflectionProbes.splice(index, 1);\r\n }\r\n\r\n if (this._parentContainer) {\r\n const index = this._parentContainer.reflectionProbes.indexOf(this);\r\n if (index > -1) {\r\n this._parentContainer.reflectionProbes.splice(index, 1);\r\n }\r\n this._parentContainer = null;\r\n }\r\n\r\n if (this._renderTargetTexture) {\r\n this._renderTargetTexture.dispose();\r\n (this._renderTargetTexture) = null;\r\n }\r\n\r\n if (this._sceneUBOs) {\r\n for (const ubo of this._sceneUBOs) {\r\n ubo.dispose();\r\n }\r\n this._sceneUBOs = [];\r\n }\r\n }\r\n\r\n /**\r\n * Converts the reflection probe information to a readable string for debug purpose.\r\n * @param fullDetails Supports for multiple levels of logging within scene loading\r\n * @returns the human readable reflection probe info\r\n */\r\n public toString(fullDetails?: boolean): string {\r\n let ret = \"Name: \" + this.name;\r\n\r\n if (fullDetails) {\r\n ret += \", position: \" + this.position.toString();\r\n\r\n if (this._attachedMesh) {\r\n ret += \", attached mesh: \" + this._attachedMesh.name;\r\n }\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n /**\r\n * Get the class name of the refection probe.\r\n * @returns \"ReflectionProbe\"\r\n */\r\n public getClassName(): string {\r\n return \"ReflectionProbe\";\r\n }\r\n\r\n /**\r\n * Serialize the reflection probe to a JSON representation we can easily use in the respective Parse function.\r\n * @returns The JSON representation of the texture\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this, this._renderTargetTexture.serialize());\r\n serializationObject.isReflectionProbe = true;\r\n serializationObject.metadata = this.metadata;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse the JSON representation of a reflection probe in order to recreate the reflection probe in the given scene.\r\n * @param parsedReflectionProbe Define the JSON representation of the reflection probe\r\n * @param scene Define the scene the parsed reflection probe should be instantiated in\r\n * @param rootUrl Define the root url of the parsing sequence in the case of relative dependencies\r\n * @returns The parsed reflection probe if successful\r\n */\r\n public static Parse(parsedReflectionProbe: any, scene: Scene, rootUrl: string): Nullable {\r\n let reflectionProbe: Nullable = null;\r\n if (scene.reflectionProbes) {\r\n for (let index = 0; index < scene.reflectionProbes.length; index++) {\r\n const rp = scene.reflectionProbes[index];\r\n if (rp.name === parsedReflectionProbe.name) {\r\n reflectionProbe = rp;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n reflectionProbe = SerializationHelper.Parse(\r\n () => reflectionProbe || new ReflectionProbe(parsedReflectionProbe.name, parsedReflectionProbe.renderTargetSize, scene, parsedReflectionProbe._generateMipMaps),\r\n parsedReflectionProbe,\r\n scene,\r\n rootUrl\r\n );\r\n reflectionProbe.cubeTexture._waitingRenderList = parsedReflectionProbe.renderList;\r\n\r\n if (parsedReflectionProbe._attachedMesh) {\r\n reflectionProbe.attachToMesh(scene.getMeshById(parsedReflectionProbe._attachedMesh));\r\n }\r\n\r\n if (parsedReflectionProbe.metadata) {\r\n reflectionProbe.metadata = parsedReflectionProbe.metadata;\r\n }\r\n\r\n return reflectionProbe;\r\n }\r\n}\r\n","import { Constants } from '@babylonjs/core/Engines/constants';\r\nimport { Engine } from '@babylonjs/core/Engines/engine';\r\nimport { PBRBaseSimpleMaterial } from '@babylonjs/core/Materials/PBR/pbrBaseSimpleMaterial';\r\nimport { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { BaseTexture } from '@babylonjs/core/Materials/Textures/baseTexture';\r\nimport { MirrorTexture } from '@babylonjs/core/Materials/Textures/mirrorTexture';\r\nimport { RefractionTexture } from '@babylonjs/core/Materials/Textures/refractionTexture';\r\nimport { Material } from '@babylonjs/core/Materials/material';\r\nimport { Color3, Plane, Vector2, Vector3 } from '@babylonjs/core/Maths';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { ReflectionProbe } from '@babylonjs/core/Probes/reflectionProbe';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Connector, SpaceNode } from '@models/classes';\r\nimport { instanceOf } from '@models/classes/decorators/model-utils';\r\nimport { eMaterialWorkflow, eReflectionType, eRenderMode, eTextureChannel } from '@models/classes/enums';\r\nimport { Kb3dManager } from '@models/classes/kb3d-manager';\r\nimport { AdvancedMaterialNode } from '@models/classes/materials/advanced-material-node';\r\nimport { MaterialNode } from '@models/classes/materials/material-node';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { SceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Observable } from 'rxjs';\r\nimport { map, shareReplay } from 'rxjs/operators';\r\nimport { Renderer } from './renderer';\r\nimport { TextureStackRenderer } from './texture-stack';\r\n\r\n// Performance Code from Babylon 5.0. Remove once upgrade to Babylon 5.0 is merged\r\nObject.defineProperty(BaseTexture.prototype, 'hasAlpha', {\r\n get: function () {\r\n return this._hasAlpha;\r\n },\r\n set: function (value) {\r\n const self = this;\r\n if (this._hasAlpha === value) {\r\n return;\r\n }\r\n this._hasAlpha = value;\r\n if (this._scene) {\r\n this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, function (mat: Material) {\r\n return mat.hasTexture(self);\r\n });\r\n }\r\n },\r\n enumerable: false,\r\n configurable: true,\r\n});\r\n\r\nexport class MaterialRenderer extends Renderer {\r\n private _globalMaterialCache = new Map>();\r\n private _globalMaterialManager: Kb3dManager;\r\n private _defaultMaterial: PBRMaterial;\r\n private orphanedMeshes = new Map();\r\n\r\n //keyed by the connector id of which the reflection probe is attached to\r\n private reflectionProbeMap = new Map();\r\n public reflectedMeshes = new Map();\r\n //key is the ConnectorId of the reflection probe, String[] is the ids of the meshes using the material;\r\n public meshesUsingReflectionMaterial = new Map();\r\n\r\n get defaultMaterial() {\r\n return this._defaultMaterial;\r\n }\r\n\r\n constructor(viewer: KbViewer, scene: Scene, private textureRenderer: TextureStackRenderer) {\r\n super(viewer, scene);\r\n\r\n this._defaultMaterial = new PBRMaterial('default material', scene);\r\n this._defaultMaterial.albedoColor = new Color3(0.5, 0.5, 0.5);\r\n this._defaultMaterial.alphaMode = Engine.ALPHA_COMBINE;\r\n this._defaultMaterial.metallic = 0;\r\n this._defaultMaterial.roughness = 1;\r\n }\r\n modelToken = Token.MaterialNode;\r\n\r\n _renderMode: eRenderMode;\r\n get renderMode() {\r\n return this._renderMode;\r\n }\r\n set renderMode(mode: eRenderMode) {\r\n this._renderMode = mode;\r\n this.babylonMap.forEach(material => {\r\n this.setRenderModeOnMaterial(material, mode);\r\n });\r\n this.setRenderModeOnMaterial(this._defaultMaterial, mode);\r\n }\r\n\r\n getAllDefinedMaterials() {\r\n return Array.from(this.babylonMap.values());\r\n }\r\n\r\n getGlobalMaterial(dynamicId: string) {\r\n if (!this._globalMaterialManager) {\r\n return undefined;\r\n } else {\r\n return this._globalMaterialManager.getById(dynamicId);\r\n }\r\n }\r\n\r\n delete3d(node: ITrackedClass) {\r\n this.textureRenderer.materialDeleted(node);\r\n const material = this.get3d(node);\r\n if (material instanceof PBRMaterial) {\r\n const orphanedMeshes = material.getBindedMeshes();\r\n this.orphanedMeshes.set(node.id, orphanedMeshes);\r\n }\r\n this.viewer.materialWarningsNeedsUpdate.next();\r\n return super.delete3d(node);\r\n }\r\n\r\n loadGlobalMaterial(materialId: string, managerServices: Map) {\r\n if (!this._globalMaterialManager) {\r\n this._globalMaterialManager = new Kb3dManager({ services: managerServices });\r\n }\r\n const matService = this._globalMaterialManager.getService(Token.MaterialService);\r\n\r\n if (this._globalMaterialCache.has(materialId)) {\r\n return this._globalMaterialCache.get(materialId) as Observable;\r\n } else {\r\n const obs = matService\r\n .getMaterialById(materialId)\r\n .pipe(\r\n map(imaterial => {\r\n if (imaterial) {\r\n let matNode = this._globalMaterialManager.getById(materialId);\r\n const newMatNode = this._globalMaterialManager.deserialize(imaterial.data);\r\n // If the material has already been added to the scene, just update it.\r\n if (matNode) {\r\n this._globalMaterialManager.assign(matNode, newMatNode);\r\n // We have to re-initialize the material to reload the texture\r\n if (matNode._initialized) {\r\n matNode._initialized = false;\r\n matNode.init();\r\n }\r\n } else {\r\n matNode = newMatNode;\r\n matNode._dynamicId = matNode.id; // Each global material is unique\r\n this._globalMaterialManager.register(matNode);\r\n\r\n //now create the material in babylon by rendering it\r\n this.update3d(matNode as ITrackedClass);\r\n }\r\n\r\n return matNode;\r\n }\r\n return undefined;\r\n })\r\n )\r\n .pipe(shareReplay(1));\r\n\r\n this._globalMaterialCache.set(materialId, obs);\r\n return obs;\r\n }\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n let material = this.get3d(node);\r\n let _changes = node.changes;\r\n\r\n // since the texture are nested in the material we have to refresh the texture in the material individually\r\n if (instanceOf(node, Token.AdvancedMaterialNode)) {\r\n const _node = node as ITrackedClass;\r\n let changes = _changes as typeof _node.changes;\r\n\r\n let pbrAdvMaterial = material as PBRMaterial | undefined;\r\n if (!pbrAdvMaterial) {\r\n material = pbrAdvMaterial = new PBRMaterial(node._dynamicId, this.scene);\r\n material.name = node.name;\r\n material.id = node._dynamicId;\r\n\r\n const meshesToBind = this.orphanedMeshes.get(node.id);\r\n if (meshesToBind) {\r\n const _pbrAdvMaterial = pbrAdvMaterial;\r\n meshesToBind.forEach(mesh => {\r\n mesh.material = _pbrAdvMaterial;\r\n });\r\n }\r\n\r\n changes = _changes = new Map(Object.entries(node)) as any;\r\n changes.set('textures', node.textures);\r\n\r\n /** hardcode the alphaMode because the material always overrides the engine setting and we need proper alpha for dragging effects */\r\n material.alphaMode = Engine.ALPHA_COMBINE;\r\n material.useParallax = false;\r\n // Logarithmic depth is a good concept but is buggy. Maybe try again later.\r\n // material.useLogarithmicDepth = true;\r\n material.useLightmapAsShadowmap = true;\r\n material.enableSpecularAntiAliasing = true;\r\n material.forceDepthWrite = true;\r\n pbrAdvMaterial.transparencyMode = Material.MATERIAL_ALPHABLEND;\r\n\r\n material.useMetallnessFromMetallicTextureBlue = false;\r\n material.useMicroSurfaceFromReflectivityMapAlpha = false;\r\n material.useRoughnessFromMetallicTextureGreen = false;\r\n\r\n this.setRenderModeOnMaterial(material, this.renderMode);\r\n this.set3d(node, pbrAdvMaterial);\r\n }\r\n\r\n if (changes.has('probePositionTargetId')) {\r\n this.updateReflectionProbes();\r\n }\r\n\r\n if (changes.hasAny('probePositionTargetId', 'subsurfaceReflectionEnabled', 'reflectionType')) {\r\n //if (node.reflectionType === eReflectionType.probe) {\r\n if (!node.probePositionTargetId || !node.subsurfaceReflectionEnabled) {\r\n if (pbrAdvMaterial) {\r\n pbrAdvMaterial.reflectionTexture = null;\r\n }\r\n } else {\r\n if (node.reflectionType === eReflectionType.probe) {\r\n if (node.probePositionTargetId && pbrAdvMaterial) {\r\n let reflectionProbe = this.reflectionProbeMap.get(node.probePositionTargetId);\r\n if (!reflectionProbe || reflectionProbe instanceof MirrorTexture) {\r\n reflectionProbe = new ReflectionProbe(node.probePositionTargetId, 512, this.scene);\r\n this.reflectionProbeMap.set(node.probePositionTargetId, reflectionProbe);\r\n const exceptions = this.meshesUsingReflectionMaterial.get(node.probePositionTargetId);\r\n this.reflectedMeshes.forEach(mesh => {\r\n if (reflectionProbe && reflectionProbe.renderList) {\r\n if (!exceptions?.contains(mesh.id)) {\r\n reflectionProbe.renderList?.push(mesh);\r\n }\r\n }\r\n });\r\n const sceneBackground = this.scene.meshes.find(obj => {\r\n return obj.id === 'hdrSkyBox';\r\n });\r\n if (reflectionProbe && reflectionProbe.renderList && sceneBackground) {\r\n reflectionProbe.renderList.push(sceneBackground);\r\n }\r\n }\r\n const connector = this.viewer.getNode(node.probePositionTargetId);\r\n if (connector instanceof Connector) {\r\n const connectorMesh = this.viewer.getRendererNode(connector);\r\n reflectionProbe.attachToMesh(connectorMesh as AbstractMesh);\r\n }\r\n if (pbrAdvMaterial) {\r\n reflectionProbe.cubeTexture.invertZ = false;\r\n pbrAdvMaterial.reflectionTexture = reflectionProbe.cubeTexture;\r\n }\r\n }\r\n } else {\r\n if (node.probePositionTargetId && pbrAdvMaterial) {\r\n let reflectionProbe = this.reflectionProbeMap.get(node.probePositionTargetId);\r\n let noPlane = false;\r\n if (reflectionProbe && reflectionProbe instanceof MirrorTexture) {\r\n if (!reflectionProbe.mirrorPlane) {\r\n noPlane = true;\r\n }\r\n }\r\n if (!reflectionProbe || reflectionProbe instanceof MirrorTexture || noPlane) {\r\n reflectionProbe = new ReflectionProbe(node.probePositionTargetId, 512, this.scene);\r\n this.reflectionProbeMap.set(node.probePositionTargetId, reflectionProbe);\r\n const exceptions = this.meshesUsingReflectionMaterial.get(node.probePositionTargetId);\r\n this.reflectedMeshes.forEach(mesh => {\r\n if (reflectionProbe && reflectionProbe.renderList) {\r\n if (!exceptions?.contains(mesh.id)) {\r\n reflectionProbe.renderList?.push(mesh);\r\n }\r\n }\r\n });\r\n const sceneBackground = this.scene.meshes.find(obj => {\r\n return obj.id === 'hdrSkyBox';\r\n });\r\n if (reflectionProbe && reflectionProbe.renderList && sceneBackground) {\r\n reflectionProbe.renderList.push(sceneBackground);\r\n }\r\n }\r\n const mirrorTexture = new MirrorTexture('mirrorTexture', 1024, this.scene);\r\n const connector = this.viewer.getNode(node.probePositionTargetId);\r\n let position = new Vector3(0, 0, 0);\r\n if (\r\n connector &&\r\n connector instanceof Connector &&\r\n connector._parent &&\r\n connector._parent instanceof SpaceNode\r\n ) {\r\n const connectorMesh = this.viewer.getRendererNode(connector._parent);\r\n\r\n if (connectorMesh) {\r\n const normal = Vector3.TransformCoordinates(\r\n connector.direction.toVec3().scale(-1),\r\n connectorMesh.getWorldMatrix().getRotationMatrix()\r\n );\r\n position = connectorMesh.absolutePosition;\r\n const reflector = Plane.FromPositionAndNormal(position, normal);\r\n mirrorTexture.mirrorPlane = reflector;\r\n mirrorTexture.renderList = reflectionProbe.renderList;\r\n }\r\n }\r\n if (pbrAdvMaterial) {\r\n mirrorTexture.invertZ = false;\r\n mirrorTexture.adaptiveBlurKernel = node.roughness * 100;\r\n pbrAdvMaterial.reflectionTexture = mirrorTexture;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n if (changes.has('hasTransparency')) {\r\n pbrAdvMaterial.useAlphaFromAlbedoTexture = node.hasTransparency;\r\n this.textureRenderer.setTransparency(node, node.hasTransparency);\r\n }\r\n\r\n if (changes.has('directIntensity')) pbrAdvMaterial.directIntensity = node.directIntensity;\r\n if (changes.has('emissiveIntensity')) pbrAdvMaterial.emissiveIntensity = node.emissiveIntensity;\r\n if (changes.has('environmentIntensity')) pbrAdvMaterial.environmentIntensity = node.environmentIntensity;\r\n if (changes.has('specularIntensity')) pbrAdvMaterial.specularIntensity = node.specularIntensity;\r\n if (changes.has('ambientTextureStrength')) {\r\n pbrAdvMaterial.ambientTextureStrength = node.ambientTextureStrength || 1;\r\n }\r\n\r\n if (changes.has('ambientColor')) {\r\n pbrAdvMaterial.ambientColor = new Color3(\r\n node.ambientColor.r,\r\n node.ambientColor.g,\r\n node.ambientColor.b\r\n ).toLinearSpace();\r\n }\r\n if (changes.has('albedoColor')) {\r\n pbrAdvMaterial.albedoColor = new Color3(\r\n node.albedoColor.r,\r\n node.albedoColor.g,\r\n node.albedoColor.b\r\n ).toLinearSpace();\r\n }\r\n if (changes.has('specularColor')) {\r\n pbrAdvMaterial.reflectivityColor = new Color3(\r\n node.specularColor.r,\r\n node.specularColor.g,\r\n node.specularColor.b\r\n ).toLinearSpace();\r\n }\r\n if (changes.has('reflectionColor')) {\r\n pbrAdvMaterial.reflectionColor = new Color3(\r\n node.reflectionColor.r,\r\n node.reflectionColor.g,\r\n node.reflectionColor.b\r\n ).toLinearSpace();\r\n }\r\n if (changes.has('microSurface')) pbrAdvMaterial.microSurface = node.microSurface;\r\n\r\n if (changes.has('useSpecularOverAlpha')) pbrAdvMaterial.useSpecularOverAlpha = node.useSpecularOverAlpha;\r\n if (changes.has('useRadianceOverAlpha')) pbrAdvMaterial.useRadianceOverAlpha = node.useRadianceOverAlpha;\r\n\r\n if (changes.has('textures') || changes.has('doubleSided') || changes.has('hasTransparency')) {\r\n // Only enable the material transparency handling if necessary\r\n if (\r\n (node.hasTransparency && node.doubleSided) ||\r\n node.textures.find(texture => texture.channel === eTextureChannel.opacity)\r\n ) {\r\n // These properties are necessary to ensure that partial transparency self-blending works correctly. There is a performace impact.\r\n pbrAdvMaterial.separateCullingPass = true;\r\n pbrAdvMaterial.transparencyMode = Material.MATERIAL_ALPHABLEND;\r\n\r\n // Refraction test\r\n // let renderTarget = new RefractionTexture(\"rt\", 1024, this.scene, true);\r\n // renderTarget.renderListPredicate = (mesh) => {\r\n // return mesh.name === 'hdrSkyBox'; // mesh.material === pbrAdvMaterial && mesh.isEnabled();\r\n // }\r\n // renderTarget.lodGenerationScale = 0.5;\r\n // renderTarget.depth = 1;\r\n // pbrAdvMaterial.refractionTexture = renderTarget;\r\n // renderTarget.refractionPlane = new Plane(0, 0, 0, 0);\r\n // pbrAdvMaterial.subSurface.useAlbedoToTintRefraction = true\r\n // pbrAdvMaterial.subSurface.indexOfRefraction = 1.5;\r\n // pbrAdvMaterial.subSurface.isTranslucencyEnabled = true;\r\n // pbrAdvMaterial.subSurface.linkRefractionWithTransparency = true;\r\n } else {\r\n pbrAdvMaterial.separateCullingPass = false;\r\n pbrAdvMaterial.transparencyMode = null;\r\n }\r\n }\r\n\r\n if (changes.has('anisotropicIntensity')) pbrAdvMaterial.anisotropy.intensity = node.anisotropicIntensity;\r\n if (changes.has('anisotropicDirection')) {\r\n pbrAdvMaterial.anisotropy.direction = new Vector2(\r\n node.anisotropicDirection.x,\r\n node.anisotropicDirection.y\r\n );\r\n }\r\n if (changes.has('anisotropyEnabled')) {\r\n pbrAdvMaterial.anisotropy.isEnabled = node.anisotropyEnabled;\r\n if (node.anisotropyEnabled) {\r\n const tangentTexture = node.textures.find(\r\n texture => texture.channel === eTextureChannel.anisotropyTangent\r\n );\r\n if (tangentTexture && isTrackedClass(tangentTexture)) {\r\n tangentTexture.isModified = true;\r\n }\r\n } else {\r\n pbrAdvMaterial.anisotropy.texture = null;\r\n }\r\n }\r\n\r\n if (changes.has('clearcoatIntensity')) pbrAdvMaterial.clearCoat.intensity = node.clearcoatIntensity;\r\n if (changes.has('clearcoatTintEnabled')) pbrAdvMaterial.clearCoat.isTintEnabled = node.clearcoatTintEnabled;\r\n if (changes.has('clearcoatTintIntensity')) {\r\n pbrAdvMaterial.clearCoat.tintThickness = node.clearcoatTintIntensity;\r\n }\r\n if (changes.has('clearcoatTintColor')) {\r\n pbrAdvMaterial.clearCoat.tintColor = node.clearcoatTintColor.toColor3();\r\n }\r\n if (changes.has('clearcoatEnabled')) {\r\n pbrAdvMaterial.clearCoat.isEnabled = node.clearcoatEnabled;\r\n if (node.clearcoatEnabled) {\r\n const clearcoatNormalTexture = node.textures.find(\r\n texture => texture.channel === eTextureChannel.clearCoatNormal\r\n );\r\n if (clearcoatNormalTexture && isTrackedClass(clearcoatNormalTexture)) {\r\n clearcoatNormalTexture.isModified = true;\r\n }\r\n } else {\r\n pbrAdvMaterial.clearCoat.bumpTexture = null;\r\n }\r\n }\r\n\r\n if (changes.has('subsurfaceThickness')) {\r\n pbrAdvMaterial.subSurface.minimumThickness = node.subsurfaceThickness;\r\n }\r\n if (changes.has('subsurfaceTintColor')) {\r\n pbrAdvMaterial.subSurface.tintColor = node.subsurfaceTintColor.toColor3();\r\n }\r\n if (changes.has('subsurfaceUseAlbedoForTintColor')) {\r\n pbrAdvMaterial.subSurface.useAlbedoToTintRefraction = node.subsurfaceUseAlbedoForTintColor;\r\n }\r\n if (changes.has('subsurfaceRefractionEnabled')) {\r\n pbrAdvMaterial.subSurface.isRefractionEnabled = node.subsurfaceRefractionEnabled;\r\n }\r\n if (changes.has('subsurfaceRefractionIntensity')) {\r\n pbrAdvMaterial.subSurface.refractionIntensity = node.subsurfaceRefractionIntensity;\r\n }\r\n if (changes.has('subsurfaceRefractionIndex')) {\r\n pbrAdvMaterial.subSurface.indexOfRefraction = node.subsurfaceRefractionIndex;\r\n }\r\n if (changes.has('subsurfaceRefractionLinkTransparency')) {\r\n pbrAdvMaterial.subSurface.linkRefractionWithTransparency = node.subsurfaceRefractionLinkTransparency;\r\n }\r\n if (changes.has('subsurfaceTranslucencyEnabled')) {\r\n pbrAdvMaterial.subSurface.isTranslucencyEnabled = node.subsurfaceTranslucencyEnabled;\r\n }\r\n if (changes.has('subsurfaceTranslucencyIntensity')) {\r\n pbrAdvMaterial.subSurface.translucencyIntensity = node.subsurfaceTranslucencyIntensity;\r\n }\r\n if (\r\n changes.hasAny('subsurfaceRefractionEnabled', 'subsurfaceTranslucencyEnabled', 'probePositionTargetId')\r\n ) {\r\n if (!node.probePositionTargetId || !node.subsurfaceRefractionEnabled) {\r\n pbrAdvMaterial.refractionTexture = null;\r\n } else {\r\n let refractionProbe = this.reflectionProbeMap.get(node.probePositionTargetId);\r\n if (!refractionProbe) {\r\n refractionProbe = new ReflectionProbe(node.probePositionTargetId, 512, this.scene);\r\n\r\n const connector = this.viewer.getNode(node.probePositionTargetId);\r\n if (connector instanceof Connector) {\r\n const connectorMesh = this.viewer.getRendererNode(connector);\r\n refractionProbe.attachToMesh(connectorMesh as AbstractMesh);\r\n this.reflectionProbeMap.set(node.probePositionTargetId, refractionProbe);\r\n }\r\n const exceptions = this.meshesUsingReflectionMaterial.get(node.probePositionTargetId);\r\n this.reflectedMeshes.forEach(mesh => {\r\n if (refractionProbe && refractionProbe.renderList) {\r\n if (!exceptions?.contains(mesh.id)) {\r\n refractionProbe.renderList?.push(mesh);\r\n }\r\n }\r\n });\r\n const sceneBackground = this.scene.meshes.find(obj => {\r\n return obj.id === 'hdrSkyBox';\r\n });\r\n if (refractionProbe && refractionProbe.renderList && sceneBackground) {\r\n refractionProbe.renderList.push(sceneBackground);\r\n }\r\n }\r\n const refractionTexture = new RefractionTexture('refractionTexture', 1024, this.scene);\r\n const connector = this.viewer.getNode(node.probePositionTargetId);\r\n let position = new Vector3(0, 0, 0);\r\n if (\r\n connector &&\r\n connector instanceof Connector &&\r\n connector._parent &&\r\n connector._parent instanceof SpaceNode\r\n ) {\r\n const connectorMesh = this.viewer.getRendererNode(connector._parent);\r\n\r\n if (connectorMesh) {\r\n const normal = Vector3.TransformCoordinates(\r\n connector.direction.toVec3(),\r\n connectorMesh.getWorldMatrix().getRotationMatrix()\r\n );\r\n position = connectorMesh.absolutePosition;\r\n const reflector = Plane.FromPositionAndNormal(position, normal);\r\n refractionTexture.refractionPlane = reflector;\r\n refractionTexture.renderList = refractionProbe.renderList;\r\n refractionTexture.depth = node.subsurfaceRefractionIndex;\r\n }\r\n }\r\n\r\n if (pbrAdvMaterial) {\r\n refractionTexture.invertZ = false;\r\n pbrAdvMaterial.refractionTexture = refractionTexture;\r\n }\r\n }\r\n if (node.subsurfaceRefractionEnabled || node.subsurfaceTranslucencyEnabled) {\r\n if (!pbrAdvMaterial.subSurface.thicknessTexture) {\r\n const subsurfaceThicknessTexture = node.textures.find(\r\n texture => texture.channel === eTextureChannel.subsurfaceThickness\r\n );\r\n if (subsurfaceThicknessTexture && isTrackedClass(subsurfaceThicknessTexture)) {\r\n subsurfaceThicknessTexture.isModified = true;\r\n }\r\n }\r\n } else {\r\n pbrAdvMaterial.subSurface.thicknessTexture = null;\r\n }\r\n }\r\n if (changes.has('workflowMode')) {\r\n if (node.workflowMode === eMaterialWorkflow.metallicRoughness) {\r\n pbrAdvMaterial.metallic = node.metallic;\r\n pbrAdvMaterial.roughness = node.roughness;\r\n } else {\r\n /* Remove the metallic texture if workflow is not metallic-roughness, otherwise metallic-roughness gets used */\r\n (pbrAdvMaterial.metallicTexture as any) = undefined;\r\n pbrAdvMaterial.metallic = null;\r\n pbrAdvMaterial.roughness = null;\r\n }\r\n if (pbrAdvMaterial.reflectionTexture && pbrAdvMaterial.reflectionTexture instanceof MirrorTexture) {\r\n if (node.roughness !== 0) {\r\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = node.roughness * 100;\r\n } else {\r\n //When setting the adaptiveBlurKernel to 0 we get very odd behavior.\r\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = 0.000001;\r\n }\r\n }\r\n } else if (node.workflowMode === eMaterialWorkflow.metallicRoughness) {\r\n if (changes.has('metallic')) pbrAdvMaterial.metallic = node.metallic;\r\n if (changes.has('roughness')) {\r\n pbrAdvMaterial.roughness = node.roughness;\r\n if (pbrAdvMaterial.reflectionTexture && pbrAdvMaterial.reflectionTexture instanceof MirrorTexture) {\r\n if (node.roughness !== 0) {\r\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = node.roughness * 100;\r\n } else {\r\n //When setting the adaptiveBlurKernel to 0 we get very odd behavior.\r\n pbrAdvMaterial.reflectionTexture.adaptiveBlurKernel = 0.000001;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (material) {\r\n const changes = _changes;\r\n if (changes.has('alpha')) material.alpha = node.alpha;\r\n if (changes.has('zOffset')) material.zOffset = node.zOffset || 0;\r\n if (changes.has('doubleSided')) {\r\n material.backFaceCulling = !node.doubleSided;\r\n (material as PBRMaterial).twoSidedLighting = !!node.doubleSided;\r\n }\r\n if (changes.has('emissiveColor')) {\r\n if (node.emissiveColor) {\r\n material.emissiveColor = new Color3(\r\n node.emissiveColor.r,\r\n node.emissiveColor.g,\r\n node.emissiveColor.b\r\n );\r\n } else {\r\n material.emissiveColor = Color3.Black();\r\n }\r\n }\r\n\r\n // Wireframe mode for debugging geometry\r\n // if(true || node.viewMode === eMaterialViewMode.wireframe) {\r\n // material.wireframe = true;\r\n // material.emissiveColor = Color3.Red();\r\n // }\r\n }\r\n this.viewer.materialWarningsNeedsUpdate.next();\r\n }\r\n\r\n protected setRenderModeOnMaterial(material: Material, mode: eRenderMode) {\r\n if (mode === eRenderMode.wireframe) {\r\n material.pointsCloud = false;\r\n material.wireframe = true;\r\n } else if (mode === eRenderMode.hiddenEdges) {\r\n material.wireframe = false;\r\n material.pointsCloud = true;\r\n } else {\r\n material.pointsCloud = false;\r\n material.wireframe = false;\r\n }\r\n }\r\n\r\n protected getNumberOfMaterialRef(sceneNode: SceneNode, materialNode: MaterialNode): number {\r\n const allMeshes = sceneNode.filterByType(...Token.MeshTokens);\r\n let nrefs = 0;\r\n for (const m of allMeshes) {\r\n if (m.materialId == materialNode._dynamicId) nrefs++;\r\n }\r\n return nrefs;\r\n }\r\n\r\n public updateReflectionProbes() {\r\n this.meshesUsingReflectionMaterial.clear();\r\n this.viewer.sceneNode._manager?.getAllNodes().forEach(mesh => {\r\n if (mesh instanceof MeshNode) {\r\n if (mesh.materialId) {\r\n const material = mesh._manager?.getById(mesh.materialId);\r\n if (material && material instanceof MaterialNode && material.probePositionTargetId) {\r\n let exceptionList = this.meshesUsingReflectionMaterial.get(material.probePositionTargetId);\r\n if (!exceptionList) {\r\n exceptionList = [mesh._dynamicId];\r\n } else {\r\n exceptionList.push(mesh._dynamicId);\r\n }\r\n this.meshesUsingReflectionMaterial.set(material.probePositionTargetId, exceptionList);\r\n }\r\n }\r\n }\r\n });\r\n\r\n const sceneBackground = this.scene.meshes.filter(obj => {\r\n return obj.id === 'hdrSkyBox';\r\n });\r\n\r\n for (const keyValuePair of this.reflectionProbeMap) {\r\n const reflectionProbe = keyValuePair[1];\r\n const connectorId = keyValuePair[0];\r\n reflectionProbe.renderList?.clear();\r\n const exceptions = this.meshesUsingReflectionMaterial.get(connectorId);\r\n this.reflectedMeshes.forEach(mesh => {\r\n if (!exceptions?.contains(mesh.id)) {\r\n reflectionProbe.renderList?.push(mesh);\r\n }\r\n });\r\n if (reflectionProbe && reflectionProbe.renderList) {\r\n reflectionProbe.renderList.push(sceneBackground[0]);\r\n }\r\n }\r\n }\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { eAxis } from '@models/classes/enums';\r\nimport { SketchControlPoint } from '@models/classes/features/sketch-control-point';\r\nimport { Kb3dManager } from '@models/classes/kb3d-manager';\r\nimport { SketchNode } from '@models/classes/meshes/sketch-node';\r\nimport { SketchPath } from '@models/classes/meshes/sketch-node-path';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Token } from '@models/classes/token';\r\nimport { appendOrIncrementNumber } from '@models/classes/utilities';\r\nimport { earcut } from '@view/helpers/earcut';\r\nimport { SubmeshVertexData, getPolygonNormal } from '@view/helpers/geometry-helper';\r\n\r\nexport function parseSketchGeometry(vertexData: Partial | null) {\r\n const segments: Vector3[][] = [];\r\n const holes = new Map();\r\n\r\n if (vertexData && vertexData.positions && vertexData.paths) {\r\n const paths = vertexData.paths;\r\n const holeIndices = new Map();\r\n if (vertexData.holes) {\r\n for (let i = 0; i < vertexData.holes.length; i += 2) {\r\n holeIndices.set(vertexData.holes[i + 1], vertexData.holes[i]);\r\n }\r\n }\r\n\r\n let i = 0;\r\n let currentHole: null | number = null;\r\n while (i < paths.length) {\r\n const positions = vertexData.positions;\r\n const segmentPoints: Vector3[] = [];\r\n currentHole = holeIndices.has(i) ? holeIndices.get(i)! : null;\r\n\r\n for (; i < paths.length; i += 2) {\r\n segmentPoints.push(Vector3.FromArray(positions, paths[i] * 3));\r\n if (paths[i + 2] !== paths[i + 1]) {\r\n segmentPoints.push(Vector3.FromArray(positions, paths[i + 1] * 3));\r\n i += 2;\r\n break;\r\n }\r\n }\r\n\r\n if (segmentPoints.length > 1) {\r\n if (currentHole !== null) {\r\n let currentHolePoints = holes.get(currentHole);\r\n if (!currentHolePoints) {\r\n currentHolePoints = [];\r\n holes.set(currentHole, currentHolePoints);\r\n }\r\n currentHolePoints.push(segmentPoints);\r\n } else {\r\n segments.push(segmentPoints);\r\n }\r\n }\r\n }\r\n }\r\n\r\n return { segments, holes };\r\n}\r\n\r\nexport function createSketchPointForEditor(manager: Kb3dManager, path: SketchPath, insertIndex?: number) {\r\n if (!path._parent) {\r\n throw new Error('Cannot create a sketch point for a path that has no parent sketch');\r\n }\r\n const sketch = path._parent;\r\n\r\n const c: SketchControlPoint = manager.create(Token.SketchControlPoint);\r\n c.name = 'Control Point';\r\n while (path.controlPoints.find(ec => ec.name === c.name)) {\r\n c.name = appendOrIncrementNumber(c.name);\r\n }\r\n\r\n let previousControlPoint: SketchControlPoint | undefined;\r\n if (!insertIndex) {\r\n // If insert index is zero or undefined, determine the previous control point and use its position for the new control point\r\n if (path.controlPoints.length > 0 && insertIndex === undefined) {\r\n previousControlPoint = path.controlPoints[path.controlPoints.length - 1];\r\n } else {\r\n const currentPathIndex = sketch.paths.findIndex(p => p._dynamicId === path._dynamicId);\r\n if (currentPathIndex > 0) {\r\n const previousPath = sketch.paths[currentPathIndex - 1];\r\n if (previousPath.controlPoints.length > 0) {\r\n previousControlPoint = previousPath.controlPoints[previousPath.controlPoints.length - 1];\r\n }\r\n }\r\n }\r\n } else {\r\n previousControlPoint = path.controlPoints[insertIndex];\r\n }\r\n\r\n const sketchNormal = getSketchNormalVector3(sketch.normal);\r\n // determine the axis making up the sketch plane so we can make sure the direction vectors are on the sketch plane\r\n let axis1: Vector3;\r\n if (sketchNormal.equalsWithEpsilon(Vector3.Forward()) || sketchNormal.equalsWithEpsilon(Vector3.Backward())) {\r\n axis1 = Vector3.Up();\r\n } else {\r\n axis1 = Vector3.Cross(sketchNormal, Vector3.Forward());\r\n }\r\n const axis2 = Vector3.Cross(sketchNormal, axis1);\r\n\r\n if (previousControlPoint) {\r\n // if therre is a previous control point, project its direction onto the sketch plane\r\n c.position = previousControlPoint.position.clone();\r\n const rawDirection = previousControlPoint.direction.toVec3();\r\n const projectedDirection = axis1\r\n .scale(Vector3.Dot(axis1, rawDirection))\r\n .add(axis2.scale(Vector3.Dot(axis2, rawDirection)));\r\n c.direction = KbVector.FromVec3(projectedDirection);\r\n } else {\r\n // if this is the first control point, just pick a direction vector on the sketch plane\r\n c.direction = KbVector.FromVec3(axis1);\r\n }\r\n c.direction2 = c.direction.scale(-1);\r\n\r\n if (insertIndex === undefined) {\r\n path.controlPoints.push(c);\r\n } else {\r\n path.controlPoints.splice(insertIndex, 0, c);\r\n }\r\n for (const eC of path.controlPoints) {\r\n eC._expanded = false;\r\n }\r\n\r\n c._visible = true;\r\n c._expanded = true;\r\n\r\n return c;\r\n}\r\n\r\nexport function getSketchNormalVector3(normal: KbVector | eAxis) {\r\n let planeNormal: Vector3;\r\n switch (normal) {\r\n case eAxis.x:\r\n planeNormal = Vector3.Right();\r\n break;\r\n case eAxis.y:\r\n planeNormal = Vector3.Up();\r\n break;\r\n case eAxis.z:\r\n planeNormal = Vector3.Forward();\r\n break;\r\n default:\r\n planeNormal = normal.toVec3();\r\n }\r\n planeNormal.normalize();\r\n return planeNormal;\r\n}\r\n\r\nexport function projectOnNodeAxis(node: SketchNode, x: number, y: number) {\r\n switch (node.normal) {\r\n case eAxis.y:\r\n return new KbVector(x, 0, -y);\r\n case eAxis.z:\r\n return new KbVector(-x, y, 0);\r\n default:\r\n return new KbVector(0, y, x);\r\n }\r\n}\r\n\r\nexport function axisToVector3(axis: eAxis) {\r\n switch (axis) {\r\n case eAxis.y:\r\n return Vector3.Up();\r\n case eAxis.z:\r\n return Vector3.Forward();\r\n default:\r\n return Vector3.Right();\r\n }\r\n}\r\n\r\n/**\r\n * returns the vertices in the order of positionVectors in sequence, followed by holePositions in sequence!\r\n * Indices will have to be recalculated if the vertex data is replaced with the results of this function.\r\n */\r\nexport function fillSketchPolygon(\r\n positionVectors: Vector3[],\r\n flipNormals: boolean,\r\n sketchNativeNormal: Vector3,\r\n holePositions?: Vector3[][]\r\n) {\r\n const sketchNormal = getPolygonNormal(positionVectors);\r\n if (flipNormals) {\r\n sketchNormal.scaleInPlace(-1);\r\n }\r\n // const geometryNormal = sketchNormal.scale(-1);\r\n const segmentPositions: number[] = [];\r\n let segmentIndices: number[] = [];\r\n\r\n for (let i = 0; i < positionVectors.length; i++) {\r\n const point = positionVectors[i];\r\n segmentPositions.push(point.x, point.y, point.z);\r\n }\r\n\r\n const holes: number[] = [];\r\n if (holePositions) {\r\n for (let i = 0; i < holePositions.length; i++) {\r\n const hole = holePositions[i];\r\n holes.push(segmentPositions.length / 3);\r\n for (let i = 0; i < hole.length; i++) {\r\n const point = hole[i];\r\n segmentPositions.push(point.x, point.y, point.z);\r\n }\r\n }\r\n }\r\n\r\n if (Math.abs(Vector3.Dot(sketchNormal, Vector3.UpReadOnly)) > 0.95) {\r\n const flatPositions = new Float32Array((segmentPositions.length * 2) / 3);\r\n const xAxis = Vector3.Cross(sketchNormal, new Vector3(0, 0, 1));\r\n const yAxis = Vector3.Cross(sketchNormal, xAxis);\r\n\r\n const working = new Vector3();\r\n for (let i = 0; i < segmentPositions.length; i += 3) {\r\n working.set(segmentPositions[i], segmentPositions[i + 1], segmentPositions[i + 2]);\r\n flatPositions.set([Vector3.Dot(working, xAxis), Vector3.Dot(working, yAxis)], (i * 2) / 3);\r\n }\r\n const faceNormal = calculateFaceNormalFromFloats(flatPositions, 2);\r\n if (Vector3.Dot(faceNormal, Vector3.RightHandedForwardReadOnly) < 0) {\r\n for (let i = 0; i < flatPositions.length; i += 2) {\r\n const tmp = flatPositions[i];\r\n flatPositions[i] = flatPositions[i + 1];\r\n flatPositions[i + 1] = tmp;\r\n }\r\n // geometryNormal.scaleInPlace(-1);\r\n }\r\n segmentIndices = earcut(flatPositions, holes, 2);\r\n } else {\r\n segmentIndices = earcut(segmentPositions, holes, 3);\r\n\r\n // Flip the geometry if needed so that it faces the same direction as the faces because earcut isn't aware of the 3d space\r\n const faceNormal = calculateFaceNormal(positionVectors);\r\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\r\n if (Vector3.Dot(faceNormal, sketchNativeNormal) < 0) {\r\n for (let i = 0; i < segmentIndices.length; i += 3) {\r\n const tmp = segmentIndices[i];\r\n segmentIndices[i] = segmentIndices[i + 2];\r\n segmentIndices[i + 2] = tmp;\r\n }\r\n // geometryNormal.scaleInPlace(-1);\r\n }\r\n }\r\n\r\n const segmentNormals: number[] = [];\r\n const geometryNormal = calculateFaceNormal(positionVectors);\r\n if (flipNormals) {\r\n geometryNormal.scaleInPlace(-1);\r\n }\r\n let totalVectorCount = positionVectors.length;\r\n if (holePositions) {\r\n totalVectorCount += holePositions.flat().length;\r\n }\r\n for (let i = 0; i < totalVectorCount; i++) {\r\n segmentNormals.push(geometryNormal.x, geometryNormal.y, geometryNormal.z);\r\n }\r\n const segmentUvs: number[] = [];\r\n for (let i = 0; i < totalVectorCount; i++) {\r\n segmentUvs.push(0, 0);\r\n }\r\n\r\n return {\r\n normals: segmentNormals,\r\n positions: segmentPositions,\r\n indices: segmentIndices,\r\n uvs: segmentUvs,\r\n };\r\n}\r\n\r\nexport function calculateFaceNormal(positionVectors: Vector3[]) {\r\n const v1 = Vector3.Zero();\r\n const v2 = Vector3.Zero();\r\n const barycenter = Vector3.Zero();\r\n for (let i = 0; i < positionVectors.length; i++) {\r\n barycenter.addInPlace(positionVectors[i]);\r\n }\r\n barycenter.scaleInPlace(1 / positionVectors.length);\r\n\r\n const pathHandedness = Vector3.Zero();\r\n if (positionVectors.length > 1) {\r\n for (let iP = 0; iP < positionVectors.length - 1; iP++) {\r\n const point1 = positionVectors[iP];\r\n v1.copyFromFloats(point1.x, point1.y, point1.z);\r\n v1.subtractInPlace(barycenter);\r\n const point2 = positionVectors[iP + 1];\r\n v2.copyFromFloats(point2.x, point2.y, point2.z);\r\n v2.subtractInPlace(barycenter);\r\n pathHandedness.addInPlace(Vector3.Cross(v1, v2));\r\n }\r\n return pathHandedness.normalize();\r\n }\r\n return Vector3.Zero();\r\n}\r\n\r\nexport function calculateFaceNormalFromFloats(points: number[] | Float32Array, dim: number) {\r\n const v1 = Vector3.Zero();\r\n const v2 = Vector3.Zero();\r\n const barycenter = Vector3.Zero();\r\n for (let i = 0; i < points.length; i += dim) {\r\n barycenter.addInPlaceFromFloats(points[i], points[i + 1], dim === 3 ? points[i + 2] : 0);\r\n }\r\n barycenter.scaleInPlace(3 / points.length);\r\n\r\n const pathHandedness = Vector3.Zero();\r\n if (points.length > 3) {\r\n for (let i = 0; i < points.length - dim; i += dim) {\r\n v1.copyFromFloats(points[i], points[i + 1], dim === 3 ? points[i + 2] : 0);\r\n v1.subtractInPlace(barycenter);\r\n v2.copyFromFloats(points[i + dim], points[i + dim + 1], dim === 3 ? points[i + dim + 2] : 0);\r\n v2.subtractInPlace(barycenter);\r\n pathHandedness.addInPlace(Vector3.Cross(v1, v2));\r\n }\r\n return pathHandedness.normalize();\r\n }\r\n return Vector3.Zero();\r\n}\r\n","/*! https://mths.be/codepointat v0.2.0 by @mathias */\nif (!String.prototype.codePointAt) {\n\t(function() {\n\t\t'use strict'; // needed to support `apply`/`call` with `undefined`/`null`\n\t\tvar defineProperty = (function() {\n\t\t\t// IE 8 only supports `Object.defineProperty` on DOM elements\n\t\t\ttry {\n\t\t\t\tvar object = {};\n\t\t\t\tvar $defineProperty = Object.defineProperty;\n\t\t\t\tvar result = $defineProperty(object, object, object) && $defineProperty;\n\t\t\t} catch(error) {}\n\t\t\treturn result;\n\t\t}());\n\t\tvar codePointAt = function(position) {\n\t\t\tif (this == null) {\n\t\t\t\tthrow TypeError();\n\t\t\t}\n\t\t\tvar string = String(this);\n\t\t\tvar size = string.length;\n\t\t\t// `ToInteger`\n\t\t\tvar index = position ? Number(position) : 0;\n\t\t\tif (index != index) { // better `isNaN`\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t\t// Account for out-of-bounds indices:\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// Get the first code unit\n\t\t\tvar first = string.charCodeAt(index);\n\t\t\tvar second;\n\t\t\tif ( // check if it’s the start of a surrogate pair\n\t\t\t\tfirst >= 0xD800 && first <= 0xDBFF && // high surrogate\n\t\t\t\tsize > index + 1 // there is a next code unit\n\t\t\t) {\n\t\t\t\tsecond = string.charCodeAt(index + 1);\n\t\t\t\tif (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate\n\t\t\t\t\t// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n\t\t\t\t\treturn (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn first;\n\t\t};\n\t\tif (defineProperty) {\n\t\t\tdefineProperty(String.prototype, 'codePointAt', {\n\t\t\t\t'value': codePointAt,\n\t\t\t\t'configurable': true,\n\t\t\t\t'writable': true\n\t\t\t});\n\t\t} else {\n\t\t\tString.prototype.codePointAt = codePointAt;\n\t\t}\n\t}());\n}\n","var TINF_OK = 0;\nvar TINF_DATA_ERROR = -3;\n\nfunction Tree() {\n this.table = new Uint16Array(16); /* table of code length counts */\n this.trans = new Uint16Array(288); /* code -> symbol translation table */\n}\n\nfunction Data(source, dest) {\n this.source = source;\n this.sourceIndex = 0;\n this.tag = 0;\n this.bitcount = 0;\n \n this.dest = dest;\n this.destLen = 0;\n \n this.ltree = new Tree(); /* dynamic length/symbol tree */\n this.dtree = new Tree(); /* dynamic distance tree */\n}\n\n/* --------------------------------------------------- *\n * -- uninitialized global data (static structures) -- *\n * --------------------------------------------------- */\n\nvar sltree = new Tree();\nvar sdtree = new Tree();\n\n/* extra bits and base tables for length codes */\nvar length_bits = new Uint8Array(30);\nvar length_base = new Uint16Array(30);\n\n/* extra bits and base tables for distance codes */\nvar dist_bits = new Uint8Array(30);\nvar dist_base = new Uint16Array(30);\n\n/* special ordering of code length codes */\nvar clcidx = new Uint8Array([\n 16, 17, 18, 0, 8, 7, 9, 6,\n 10, 5, 11, 4, 12, 3, 13, 2,\n 14, 1, 15\n]);\n\n/* used by tinf_decode_trees, avoids allocations every call */\nvar code_tree = new Tree();\nvar lengths = new Uint8Array(288 + 32);\n\n/* ----------------------- *\n * -- utility functions -- *\n * ----------------------- */\n\n/* build extra bits and base tables */\nfunction tinf_build_bits_base(bits, base, delta, first) {\n var i, sum;\n\n /* build bits table */\n for (i = 0; i < delta; ++i) bits[i] = 0;\n for (i = 0; i < 30 - delta; ++i) bits[i + delta] = i / delta | 0;\n\n /* build base table */\n for (sum = first, i = 0; i < 30; ++i) {\n base[i] = sum;\n sum += 1 << bits[i];\n }\n}\n\n/* build the fixed huffman trees */\nfunction tinf_build_fixed_trees(lt, dt) {\n var i;\n\n /* build fixed length tree */\n for (i = 0; i < 7; ++i) lt.table[i] = 0;\n\n lt.table[7] = 24;\n lt.table[8] = 152;\n lt.table[9] = 112;\n\n for (i = 0; i < 24; ++i) lt.trans[i] = 256 + i;\n for (i = 0; i < 144; ++i) lt.trans[24 + i] = i;\n for (i = 0; i < 8; ++i) lt.trans[24 + 144 + i] = 280 + i;\n for (i = 0; i < 112; ++i) lt.trans[24 + 144 + 8 + i] = 144 + i;\n\n /* build fixed distance tree */\n for (i = 0; i < 5; ++i) dt.table[i] = 0;\n\n dt.table[5] = 32;\n\n for (i = 0; i < 32; ++i) dt.trans[i] = i;\n}\n\n/* given an array of code lengths, build a tree */\nvar offs = new Uint16Array(16);\n\nfunction tinf_build_tree(t, lengths, off, num) {\n var i, sum;\n\n /* clear code length count table */\n for (i = 0; i < 16; ++i) t.table[i] = 0;\n\n /* scan symbol lengths, and sum code length counts */\n for (i = 0; i < num; ++i) t.table[lengths[off + i]]++;\n\n t.table[0] = 0;\n\n /* compute offset table for distribution sort */\n for (sum = 0, i = 0; i < 16; ++i) {\n offs[i] = sum;\n sum += t.table[i];\n }\n\n /* create code->symbol translation table (symbols sorted by code) */\n for (i = 0; i < num; ++i) {\n if (lengths[off + i]) t.trans[offs[lengths[off + i]]++] = i;\n }\n}\n\n/* ---------------------- *\n * -- decode functions -- *\n * ---------------------- */\n\n/* get one bit from source stream */\nfunction tinf_getbit(d) {\n /* check if tag is empty */\n if (!d.bitcount--) {\n /* load next tag */\n d.tag = d.source[d.sourceIndex++];\n d.bitcount = 7;\n }\n\n /* shift bit out of tag */\n var bit = d.tag & 1;\n d.tag >>>= 1;\n\n return bit;\n}\n\n/* read a num bit value from a stream and add base */\nfunction tinf_read_bits(d, num, base) {\n if (!num)\n return base;\n\n while (d.bitcount < 24) {\n d.tag |= d.source[d.sourceIndex++] << d.bitcount;\n d.bitcount += 8;\n }\n\n var val = d.tag & (0xffff >>> (16 - num));\n d.tag >>>= num;\n d.bitcount -= num;\n return val + base;\n}\n\n/* given a data stream and a tree, decode a symbol */\nfunction tinf_decode_symbol(d, t) {\n while (d.bitcount < 24) {\n d.tag |= d.source[d.sourceIndex++] << d.bitcount;\n d.bitcount += 8;\n }\n \n var sum = 0, cur = 0, len = 0;\n var tag = d.tag;\n\n /* get more bits while code value is above sum */\n do {\n cur = 2 * cur + (tag & 1);\n tag >>>= 1;\n ++len;\n\n sum += t.table[len];\n cur -= t.table[len];\n } while (cur >= 0);\n \n d.tag = tag;\n d.bitcount -= len;\n\n return t.trans[sum + cur];\n}\n\n/* given a data stream, decode dynamic trees from it */\nfunction tinf_decode_trees(d, lt, dt) {\n var hlit, hdist, hclen;\n var i, num, length;\n\n /* get 5 bits HLIT (257-286) */\n hlit = tinf_read_bits(d, 5, 257);\n\n /* get 5 bits HDIST (1-32) */\n hdist = tinf_read_bits(d, 5, 1);\n\n /* get 4 bits HCLEN (4-19) */\n hclen = tinf_read_bits(d, 4, 4);\n\n for (i = 0; i < 19; ++i) lengths[i] = 0;\n\n /* read code lengths for code length alphabet */\n for (i = 0; i < hclen; ++i) {\n /* get 3 bits code length (0-7) */\n var clen = tinf_read_bits(d, 3, 0);\n lengths[clcidx[i]] = clen;\n }\n\n /* build code length tree */\n tinf_build_tree(code_tree, lengths, 0, 19);\n\n /* decode code lengths for the dynamic trees */\n for (num = 0; num < hlit + hdist;) {\n var sym = tinf_decode_symbol(d, code_tree);\n\n switch (sym) {\n case 16:\n /* copy previous code length 3-6 times (read 2 bits) */\n var prev = lengths[num - 1];\n for (length = tinf_read_bits(d, 2, 3); length; --length) {\n lengths[num++] = prev;\n }\n break;\n case 17:\n /* repeat code length 0 for 3-10 times (read 3 bits) */\n for (length = tinf_read_bits(d, 3, 3); length; --length) {\n lengths[num++] = 0;\n }\n break;\n case 18:\n /* repeat code length 0 for 11-138 times (read 7 bits) */\n for (length = tinf_read_bits(d, 7, 11); length; --length) {\n lengths[num++] = 0;\n }\n break;\n default:\n /* values 0-15 represent the actual code lengths */\n lengths[num++] = sym;\n break;\n }\n }\n\n /* build dynamic trees */\n tinf_build_tree(lt, lengths, 0, hlit);\n tinf_build_tree(dt, lengths, hlit, hdist);\n}\n\n/* ----------------------------- *\n * -- block inflate functions -- *\n * ----------------------------- */\n\n/* given a stream and two trees, inflate a block of data */\nfunction tinf_inflate_block_data(d, lt, dt) {\n while (1) {\n var sym = tinf_decode_symbol(d, lt);\n\n /* check for end of block */\n if (sym === 256) {\n return TINF_OK;\n }\n\n if (sym < 256) {\n d.dest[d.destLen++] = sym;\n } else {\n var length, dist, offs;\n var i;\n\n sym -= 257;\n\n /* possibly get more bits from length code */\n length = tinf_read_bits(d, length_bits[sym], length_base[sym]);\n\n dist = tinf_decode_symbol(d, dt);\n\n /* possibly get more bits from distance code */\n offs = d.destLen - tinf_read_bits(d, dist_bits[dist], dist_base[dist]);\n\n /* copy match */\n for (i = offs; i < offs + length; ++i) {\n d.dest[d.destLen++] = d.dest[i];\n }\n }\n }\n}\n\n/* inflate an uncompressed block of data */\nfunction tinf_inflate_uncompressed_block(d) {\n var length, invlength;\n var i;\n \n /* unread from bitbuffer */\n while (d.bitcount > 8) {\n d.sourceIndex--;\n d.bitcount -= 8;\n }\n\n /* get length */\n length = d.source[d.sourceIndex + 1];\n length = 256 * length + d.source[d.sourceIndex];\n\n /* get one's complement of length */\n invlength = d.source[d.sourceIndex + 3];\n invlength = 256 * invlength + d.source[d.sourceIndex + 2];\n\n /* check length */\n if (length !== (~invlength & 0x0000ffff))\n return TINF_DATA_ERROR;\n\n d.sourceIndex += 4;\n\n /* copy block */\n for (i = length; i; --i)\n d.dest[d.destLen++] = d.source[d.sourceIndex++];\n\n /* make sure we start next block on a byte boundary */\n d.bitcount = 0;\n\n return TINF_OK;\n}\n\n/* inflate stream from source to dest */\nfunction tinf_uncompress(source, dest) {\n var d = new Data(source, dest);\n var bfinal, btype, res;\n\n do {\n /* read final block flag */\n bfinal = tinf_getbit(d);\n\n /* read block type (2 bits) */\n btype = tinf_read_bits(d, 2, 0);\n\n /* decompress block */\n switch (btype) {\n case 0:\n /* decompress uncompressed block */\n res = tinf_inflate_uncompressed_block(d);\n break;\n case 1:\n /* decompress block with fixed huffman trees */\n res = tinf_inflate_block_data(d, sltree, sdtree);\n break;\n case 2:\n /* decompress block with dynamic huffman trees */\n tinf_decode_trees(d, d.ltree, d.dtree);\n res = tinf_inflate_block_data(d, d.ltree, d.dtree);\n break;\n default:\n res = TINF_DATA_ERROR;\n }\n\n if (res !== TINF_OK)\n throw new Error('Data error');\n\n } while (!bfinal);\n\n if (d.destLen < d.dest.length) {\n if (typeof d.dest.slice === 'function')\n return d.dest.slice(0, d.destLen);\n else\n return d.dest.subarray(0, d.destLen);\n }\n \n return d.dest;\n}\n\n/* -------------------- *\n * -- initialization -- *\n * -------------------- */\n\n/* build fixed huffman trees */\ntinf_build_fixed_trees(sltree, sdtree);\n\n/* build extra bits and base tables */\ntinf_build_bits_base(length_bits, length_base, 4, 3);\ntinf_build_bits_base(dist_bits, dist_base, 2, 1);\n\n/* fix a special case */\nlength_bits[28] = 0;\nlength_base[28] = 258;\n\nmodule.exports = tinf_uncompress;\n","// The Bounding Box object\n\nfunction derive(v0, v1, v2, v3, t) {\n return Math.pow(1 - t, 3) * v0 +\n 3 * Math.pow(1 - t, 2) * t * v1 +\n 3 * (1 - t) * Math.pow(t, 2) * v2 +\n Math.pow(t, 3) * v3;\n}\n/**\n * A bounding box is an enclosing box that describes the smallest measure within which all the points lie.\n * It is used to calculate the bounding box of a glyph or text path.\n *\n * On initialization, x1/y1/x2/y2 will be NaN. Check if the bounding box is empty using `isEmpty()`.\n *\n * @exports opentype.BoundingBox\n * @class\n * @constructor\n */\nfunction BoundingBox() {\n this.x1 = Number.NaN;\n this.y1 = Number.NaN;\n this.x2 = Number.NaN;\n this.y2 = Number.NaN;\n}\n\n/**\n * Returns true if the bounding box is empty, that is, no points have been added to the box yet.\n */\nBoundingBox.prototype.isEmpty = function() {\n return isNaN(this.x1) || isNaN(this.y1) || isNaN(this.x2) || isNaN(this.y2);\n};\n\n/**\n * Add the point to the bounding box.\n * The x1/y1/x2/y2 coordinates of the bounding box will now encompass the given point.\n * @param {number} x - The X coordinate of the point.\n * @param {number} y - The Y coordinate of the point.\n */\nBoundingBox.prototype.addPoint = function(x, y) {\n if (typeof x === 'number') {\n if (isNaN(this.x1) || isNaN(this.x2)) {\n this.x1 = x;\n this.x2 = x;\n }\n if (x < this.x1) {\n this.x1 = x;\n }\n if (x > this.x2) {\n this.x2 = x;\n }\n }\n if (typeof y === 'number') {\n if (isNaN(this.y1) || isNaN(this.y2)) {\n this.y1 = y;\n this.y2 = y;\n }\n if (y < this.y1) {\n this.y1 = y;\n }\n if (y > this.y2) {\n this.y2 = y;\n }\n }\n};\n\n/**\n * Add a X coordinate to the bounding box.\n * This extends the bounding box to include the X coordinate.\n * This function is used internally inside of addBezier.\n * @param {number} x - The X coordinate of the point.\n */\nBoundingBox.prototype.addX = function(x) {\n this.addPoint(x, null);\n};\n\n/**\n * Add a Y coordinate to the bounding box.\n * This extends the bounding box to include the Y coordinate.\n * This function is used internally inside of addBezier.\n * @param {number} y - The Y coordinate of the point.\n */\nBoundingBox.prototype.addY = function(y) {\n this.addPoint(null, y);\n};\n\n/**\n * Add a Bézier curve to the bounding box.\n * This extends the bounding box to include the entire Bézier.\n * @param {number} x0 - The starting X coordinate.\n * @param {number} y0 - The starting Y coordinate.\n * @param {number} x1 - The X coordinate of the first control point.\n * @param {number} y1 - The Y coordinate of the first control point.\n * @param {number} x2 - The X coordinate of the second control point.\n * @param {number} y2 - The Y coordinate of the second control point.\n * @param {number} x - The ending X coordinate.\n * @param {number} y - The ending Y coordinate.\n */\nBoundingBox.prototype.addBezier = function(x0, y0, x1, y1, x2, y2, x, y) {\n // This code is based on http://nishiohirokazu.blogspot.com/2009/06/how-to-calculate-bezier-curves-bounding.html\n // and https://github.com/icons8/svg-path-bounding-box\n\n const p0 = [x0, y0];\n const p1 = [x1, y1];\n const p2 = [x2, y2];\n const p3 = [x, y];\n\n this.addPoint(x0, y0);\n this.addPoint(x, y);\n\n for (let i = 0; i <= 1; i++) {\n const b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];\n const a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];\n const c = 3 * p1[i] - 3 * p0[i];\n\n if (a === 0) {\n if (b === 0) continue;\n const t = -c / b;\n if (0 < t && t < 1) {\n if (i === 0) this.addX(derive(p0[i], p1[i], p2[i], p3[i], t));\n if (i === 1) this.addY(derive(p0[i], p1[i], p2[i], p3[i], t));\n }\n continue;\n }\n\n const b2ac = Math.pow(b, 2) - 4 * c * a;\n if (b2ac < 0) continue;\n const t1 = (-b + Math.sqrt(b2ac)) / (2 * a);\n if (0 < t1 && t1 < 1) {\n if (i === 0) this.addX(derive(p0[i], p1[i], p2[i], p3[i], t1));\n if (i === 1) this.addY(derive(p0[i], p1[i], p2[i], p3[i], t1));\n }\n const t2 = (-b - Math.sqrt(b2ac)) / (2 * a);\n if (0 < t2 && t2 < 1) {\n if (i === 0) this.addX(derive(p0[i], p1[i], p2[i], p3[i], t2));\n if (i === 1) this.addY(derive(p0[i], p1[i], p2[i], p3[i], t2));\n }\n }\n};\n\n/**\n * Add a quadratic curve to the bounding box.\n * This extends the bounding box to include the entire quadratic curve.\n * @param {number} x0 - The starting X coordinate.\n * @param {number} y0 - The starting Y coordinate.\n * @param {number} x1 - The X coordinate of the control point.\n * @param {number} y1 - The Y coordinate of the control point.\n * @param {number} x - The ending X coordinate.\n * @param {number} y - The ending Y coordinate.\n */\nBoundingBox.prototype.addQuad = function(x0, y0, x1, y1, x, y) {\n const cp1x = x0 + 2 / 3 * (x1 - x0);\n const cp1y = y0 + 2 / 3 * (y1 - y0);\n const cp2x = cp1x + 1 / 3 * (x - x0);\n const cp2y = cp1y + 1 / 3 * (y - y0);\n this.addBezier(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y);\n};\n\nexport default BoundingBox;\n","// Geometric objects\n\nimport BoundingBox from './bbox';\n\n/**\n * A bézier path containing a set of path commands similar to a SVG path.\n * Paths can be drawn on a context using `draw`.\n * @exports opentype.Path\n * @class\n * @constructor\n */\nfunction Path() {\n this.commands = [];\n this.fill = 'black';\n this.stroke = null;\n this.strokeWidth = 1;\n}\n\n/**\n * @param {number} x\n * @param {number} y\n */\nPath.prototype.moveTo = function(x, y) {\n this.commands.push({\n type: 'M',\n x: x,\n y: y\n });\n};\n\n/**\n * @param {number} x\n * @param {number} y\n */\nPath.prototype.lineTo = function(x, y) {\n this.commands.push({\n type: 'L',\n x: x,\n y: y\n });\n};\n\n/**\n * Draws cubic curve\n * @function\n * curveTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control 1\n * @param {number} y1 - y of control 1\n * @param {number} x2 - x of control 2\n * @param {number} y2 - y of control 2\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n */\n\n/**\n * Draws cubic curve\n * @function\n * bezierCurveTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control 1\n * @param {number} y1 - y of control 1\n * @param {number} x2 - x of control 2\n * @param {number} y2 - y of control 2\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n * @see curveTo\n */\nPath.prototype.curveTo = Path.prototype.bezierCurveTo = function(x1, y1, x2, y2, x, y) {\n this.commands.push({\n type: 'C',\n x1: x1,\n y1: y1,\n x2: x2,\n y2: y2,\n x: x,\n y: y\n });\n};\n\n/**\n * Draws quadratic curve\n * @function\n * quadraticCurveTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control\n * @param {number} y1 - y of control\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n */\n\n/**\n * Draws quadratic curve\n * @function\n * quadTo\n * @memberof opentype.Path.prototype\n * @param {number} x1 - x of control\n * @param {number} y1 - y of control\n * @param {number} x - x of path point\n * @param {number} y - y of path point\n */\nPath.prototype.quadTo = Path.prototype.quadraticCurveTo = function(x1, y1, x, y) {\n this.commands.push({\n type: 'Q',\n x1: x1,\n y1: y1,\n x: x,\n y: y\n });\n};\n\n/**\n * Closes the path\n * @function closePath\n * @memberof opentype.Path.prototype\n */\n\n/**\n * Close the path\n * @function close\n * @memberof opentype.Path.prototype\n */\nPath.prototype.close = Path.prototype.closePath = function() {\n this.commands.push({\n type: 'Z'\n });\n};\n\n/**\n * Add the given path or list of commands to the commands of this path.\n * @param {Array} pathOrCommands - another opentype.Path, an opentype.BoundingBox, or an array of commands.\n */\nPath.prototype.extend = function(pathOrCommands) {\n if (pathOrCommands.commands) {\n pathOrCommands = pathOrCommands.commands;\n } else if (pathOrCommands instanceof BoundingBox) {\n const box = pathOrCommands;\n this.moveTo(box.x1, box.y1);\n this.lineTo(box.x2, box.y1);\n this.lineTo(box.x2, box.y2);\n this.lineTo(box.x1, box.y2);\n this.close();\n return;\n }\n\n Array.prototype.push.apply(this.commands, pathOrCommands);\n};\n\n/**\n * Calculate the bounding box of the path.\n * @returns {opentype.BoundingBox}\n */\nPath.prototype.getBoundingBox = function() {\n const box = new BoundingBox();\n\n let startX = 0;\n let startY = 0;\n let prevX = 0;\n let prevY = 0;\n for (let i = 0; i < this.commands.length; i++) {\n const cmd = this.commands[i];\n switch (cmd.type) {\n case 'M':\n box.addPoint(cmd.x, cmd.y);\n startX = prevX = cmd.x;\n startY = prevY = cmd.y;\n break;\n case 'L':\n box.addPoint(cmd.x, cmd.y);\n prevX = cmd.x;\n prevY = cmd.y;\n break;\n case 'Q':\n box.addQuad(prevX, prevY, cmd.x1, cmd.y1, cmd.x, cmd.y);\n prevX = cmd.x;\n prevY = cmd.y;\n break;\n case 'C':\n box.addBezier(prevX, prevY, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);\n prevX = cmd.x;\n prevY = cmd.y;\n break;\n case 'Z':\n prevX = startX;\n prevY = startY;\n break;\n default:\n throw new Error('Unexpected path command ' + cmd.type);\n }\n }\n if (box.isEmpty()) {\n box.addPoint(0, 0);\n }\n return box;\n};\n\n/**\n * Draw the path to a 2D context.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context.\n */\nPath.prototype.draw = function(ctx) {\n ctx.beginPath();\n for (let i = 0; i < this.commands.length; i += 1) {\n const cmd = this.commands[i];\n if (cmd.type === 'M') {\n ctx.moveTo(cmd.x, cmd.y);\n } else if (cmd.type === 'L') {\n ctx.lineTo(cmd.x, cmd.y);\n } else if (cmd.type === 'C') {\n ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);\n } else if (cmd.type === 'Q') {\n ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y);\n } else if (cmd.type === 'Z') {\n ctx.closePath();\n }\n }\n\n if (this.fill) {\n ctx.fillStyle = this.fill;\n ctx.fill();\n }\n\n if (this.stroke) {\n ctx.strokeStyle = this.stroke;\n ctx.lineWidth = this.strokeWidth;\n ctx.stroke();\n }\n};\n\n/**\n * Convert the Path to a string of path data instructions\n * See http://www.w3.org/TR/SVG/paths.html#PathData\n * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values\n * @return {string}\n */\nPath.prototype.toPathData = function(decimalPlaces) {\n decimalPlaces = decimalPlaces !== undefined ? decimalPlaces : 2;\n\n function floatToString(v) {\n if (Math.round(v) === v) {\n return '' + Math.round(v);\n } else {\n return v.toFixed(decimalPlaces);\n }\n }\n\n function packValues() {\n let s = '';\n for (let i = 0; i < arguments.length; i += 1) {\n const v = arguments[i];\n if (v >= 0 && i > 0) {\n s += ' ';\n }\n\n s += floatToString(v);\n }\n\n return s;\n }\n\n let d = '';\n for (let i = 0; i < this.commands.length; i += 1) {\n const cmd = this.commands[i];\n if (cmd.type === 'M') {\n d += 'M' + packValues(cmd.x, cmd.y);\n } else if (cmd.type === 'L') {\n d += 'L' + packValues(cmd.x, cmd.y);\n } else if (cmd.type === 'C') {\n d += 'C' + packValues(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y);\n } else if (cmd.type === 'Q') {\n d += 'Q' + packValues(cmd.x1, cmd.y1, cmd.x, cmd.y);\n } else if (cmd.type === 'Z') {\n d += 'Z';\n }\n }\n\n return d;\n};\n\n/**\n * Convert the path to an SVG element, as a string.\n * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values\n * @return {string}\n */\nPath.prototype.toSVG = function(decimalPlaces) {\n let svg = '= 0 && v <= 255, 'Byte value should be between 0 and 255.');\n return [v];\n};\n/**\n * @constant\n * @type {number}\n */\nsizeOf.BYTE = constant(1);\n\n/**\n * Convert a 8-bit signed integer to a list of 1 byte.\n * @param {string}\n * @returns {Array}\n */\nencode.CHAR = function(v) {\n return [v.charCodeAt(0)];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.CHAR = constant(1);\n\n/**\n * Convert an ASCII string to a list of bytes.\n * @param {string}\n * @returns {Array}\n */\nencode.CHARARRAY = function(v) {\n if (typeof v === 'undefined') {\n v = '';\n console.warn('Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name.');\n }\n const b = [];\n for (let i = 0; i < v.length; i += 1) {\n b[i] = v.charCodeAt(i);\n }\n\n return b;\n};\n\n/**\n * @param {Array}\n * @returns {number}\n */\nsizeOf.CHARARRAY = function(v) {\n if (typeof v === 'undefined') {\n return 0;\n }\n return v.length;\n};\n\n/**\n * Convert a 16-bit unsigned integer to a list of 2 bytes.\n * @param {number}\n * @returns {Array}\n */\nencode.USHORT = function(v) {\n return [(v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.USHORT = constant(2);\n\n/**\n * Convert a 16-bit signed integer to a list of 2 bytes.\n * @param {number}\n * @returns {Array}\n */\nencode.SHORT = function(v) {\n // Two's complement\n if (v >= LIMIT16) {\n v = -(2 * LIMIT16 - v);\n }\n\n return [(v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.SHORT = constant(2);\n\n/**\n * Convert a 24-bit unsigned integer to a list of 3 bytes.\n * @param {number}\n * @returns {Array}\n */\nencode.UINT24 = function(v) {\n return [(v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.UINT24 = constant(3);\n\n/**\n * Convert a 32-bit unsigned integer to a list of 4 bytes.\n * @param {number}\n * @returns {Array}\n */\nencode.ULONG = function(v) {\n return [(v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.ULONG = constant(4);\n\n/**\n * Convert a 32-bit unsigned integer to a list of 4 bytes.\n * @param {number}\n * @returns {Array}\n */\nencode.LONG = function(v) {\n // Two's complement\n if (v >= LIMIT32) {\n v = -(2 * LIMIT32 - v);\n }\n\n return [(v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.LONG = constant(4);\n\nencode.FIXED = encode.ULONG;\nsizeOf.FIXED = sizeOf.ULONG;\n\nencode.FWORD = encode.SHORT;\nsizeOf.FWORD = sizeOf.SHORT;\n\nencode.UFWORD = encode.USHORT;\nsizeOf.UFWORD = sizeOf.USHORT;\n\n/**\n * Convert a 32-bit Apple Mac timestamp integer to a list of 8 bytes, 64-bit timestamp.\n * @param {number}\n * @returns {Array}\n */\nencode.LONGDATETIME = function(v) {\n return [0, 0, 0, 0, (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.LONGDATETIME = constant(8);\n\n/**\n * Convert a 4-char tag to a list of 4 bytes.\n * @param {string}\n * @returns {Array}\n */\nencode.TAG = function(v) {\n check.argument(v.length === 4, 'Tag should be exactly 4 ASCII characters.');\n return [v.charCodeAt(0),\n v.charCodeAt(1),\n v.charCodeAt(2),\n v.charCodeAt(3)];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.TAG = constant(4);\n\n// CFF data types ///////////////////////////////////////////////////////////\n\nencode.Card8 = encode.BYTE;\nsizeOf.Card8 = sizeOf.BYTE;\n\nencode.Card16 = encode.USHORT;\nsizeOf.Card16 = sizeOf.USHORT;\n\nencode.OffSize = encode.BYTE;\nsizeOf.OffSize = sizeOf.BYTE;\n\nencode.SID = encode.USHORT;\nsizeOf.SID = sizeOf.USHORT;\n\n// Convert a numeric operand or charstring number to a variable-size list of bytes.\n/**\n * Convert a numeric operand or charstring number to a variable-size list of bytes.\n * @param {number}\n * @returns {Array}\n */\nencode.NUMBER = function(v) {\n if (v >= -107 && v <= 107) {\n return [v + 139];\n } else if (v >= 108 && v <= 1131) {\n v = v - 108;\n return [(v >> 8) + 247, v & 0xFF];\n } else if (v >= -1131 && v <= -108) {\n v = -v - 108;\n return [(v >> 8) + 251, v & 0xFF];\n } else if (v >= -32768 && v <= 32767) {\n return encode.NUMBER16(v);\n } else {\n return encode.NUMBER32(v);\n }\n};\n\n/**\n * @param {number}\n * @returns {number}\n */\nsizeOf.NUMBER = function(v) {\n return encode.NUMBER(v).length;\n};\n\n/**\n * Convert a signed number between -32768 and +32767 to a three-byte value.\n * This ensures we always use three bytes, but is not the most compact format.\n * @param {number}\n * @returns {Array}\n */\nencode.NUMBER16 = function(v) {\n return [28, (v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.NUMBER16 = constant(3);\n\n/**\n * Convert a signed number between -(2^31) and +(2^31-1) to a five-byte value.\n * This is useful if you want to be sure you always use four bytes,\n * at the expense of wasting a few bytes for smaller numbers.\n * @param {number}\n * @returns {Array}\n */\nencode.NUMBER32 = function(v) {\n return [29, (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF];\n};\n\n/**\n * @constant\n * @type {number}\n */\nsizeOf.NUMBER32 = constant(5);\n\n/**\n * @param {number}\n * @returns {Array}\n */\nencode.REAL = function(v) {\n let value = v.toString();\n\n // Some numbers use an epsilon to encode the value. (e.g. JavaScript will store 0.0000001 as 1e-7)\n // This code converts it back to a number without the epsilon.\n const m = /\\.(\\d*?)(?:9{5,20}|0{5,20})\\d{0,2}(?:e(.+)|$)/.exec(value);\n if (m) {\n const epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));\n value = (Math.round(v * epsilon) / epsilon).toString();\n }\n\n let nibbles = '';\n for (let i = 0, ii = value.length; i < ii; i += 1) {\n const c = value[i];\n if (c === 'e') {\n nibbles += value[++i] === '-' ? 'c' : 'b';\n } else if (c === '.') {\n nibbles += 'a';\n } else if (c === '-') {\n nibbles += 'e';\n } else {\n nibbles += c;\n }\n }\n\n nibbles += (nibbles.length & 1) ? 'f' : 'ff';\n const out = [30];\n for (let i = 0, ii = nibbles.length; i < ii; i += 2) {\n out.push(parseInt(nibbles.substr(i, 2), 16));\n }\n\n return out;\n};\n\n/**\n * @param {number}\n * @returns {number}\n */\nsizeOf.REAL = function(v) {\n return encode.REAL(v).length;\n};\n\nencode.NAME = encode.CHARARRAY;\nsizeOf.NAME = sizeOf.CHARARRAY;\n\nencode.STRING = encode.CHARARRAY;\nsizeOf.STRING = sizeOf.CHARARRAY;\n\n/**\n * @param {DataView} data\n * @param {number} offset\n * @param {number} numBytes\n * @returns {string}\n */\ndecode.UTF8 = function(data, offset, numBytes) {\n const codePoints = [];\n const numChars = numBytes;\n for (let j = 0; j < numChars; j++, offset += 1) {\n codePoints[j] = data.getUint8(offset);\n }\n\n return String.fromCharCode.apply(null, codePoints);\n};\n\n/**\n * @param {DataView} data\n * @param {number} offset\n * @param {number} numBytes\n * @returns {string}\n */\ndecode.UTF16 = function(data, offset, numBytes) {\n const codePoints = [];\n const numChars = numBytes / 2;\n for (let j = 0; j < numChars; j++, offset += 2) {\n codePoints[j] = data.getUint16(offset);\n }\n\n return String.fromCharCode.apply(null, codePoints);\n};\n\n/**\n * Convert a JavaScript string to UTF16-BE.\n * @param {string}\n * @returns {Array}\n */\nencode.UTF16 = function(v) {\n const b = [];\n for (let i = 0; i < v.length; i += 1) {\n const codepoint = v.charCodeAt(i);\n b[b.length] = (codepoint >> 8) & 0xFF;\n b[b.length] = codepoint & 0xFF;\n }\n\n return b;\n};\n\n/**\n * @param {string}\n * @returns {number}\n */\nsizeOf.UTF16 = function(v) {\n return v.length * 2;\n};\n\n// Data for converting old eight-bit Macintosh encodings to Unicode.\n// This representation is optimized for decoding; encoding is slower\n// and needs more memory. The assumption is that all opentype.js users\n// want to open fonts, but saving a font will be comparatively rare\n// so it can be more expensive. Keyed by IANA character set name.\n//\n// Python script for generating these strings:\n//\n// s = u''.join([chr(c).decode('mac_greek') for c in range(128, 256)])\n// print(s.encode('utf-8'))\n/**\n * @private\n */\nconst eightBitMacEncodings = {\n 'x-mac-croatian': // Python: 'mac_croatian'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø' +\n '¿¡¬√ƒ≈Ć«Č… ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ',\n 'x-mac-cyrillic': // Python: 'mac_cyrillic'\n 'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњ' +\n 'јЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю',\n 'x-mac-gaelic': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæø' +\n 'ṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ',\n 'x-mac-greek': // Python: 'mac_greek'\n 'Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩ' +\n 'άΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ\\u00AD',\n 'x-mac-icelandic': // Python: 'mac_iceland'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüÝ°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',\n 'x-mac-inuit': // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT\n 'ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗ' +\n 'ᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł',\n 'x-mac-ce': // Python: 'mac_latin2'\n 'ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅ' +\n 'ņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ',\n macintosh: // Python: 'mac_roman'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',\n 'x-mac-romanian': // Python: 'mac_romanian'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ',\n 'x-mac-turkish': // Python: 'mac_turkish'\n 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' +\n '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ'\n};\n\n/**\n * Decodes an old-style Macintosh string. Returns either a Unicode JavaScript\n * string, or 'undefined' if the encoding is unsupported. For example, we do\n * not support Chinese, Japanese or Korean because these would need large\n * mapping tables.\n * @param {DataView} dataView\n * @param {number} offset\n * @param {number} dataLength\n * @param {string} encoding\n * @returns {string}\n */\ndecode.MACSTRING = function(dataView, offset, dataLength, encoding) {\n const table = eightBitMacEncodings[encoding];\n if (table === undefined) {\n return undefined;\n }\n\n let result = '';\n for (let i = 0; i < dataLength; i++) {\n const c = dataView.getUint8(offset + i);\n // In all eight-bit Mac encodings, the characters 0x00..0x7F are\n // mapped to U+0000..U+007F; we only need to look up the others.\n if (c <= 0x7F) {\n result += String.fromCharCode(c);\n } else {\n result += table[c & 0x7F];\n }\n }\n\n return result;\n};\n\n// Helper function for encode.MACSTRING. Returns a dictionary for mapping\n// Unicode character codes to their 8-bit MacOS equivalent. This table\n// is not exactly a super cheap data structure, but we do not care because\n// encoding Macintosh strings is only rarely needed in typical applications.\nconst macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap();\nlet macEncodingCacheKeys;\nconst getMacEncodingTable = function (encoding) {\n // Since we use encoding as a cache key for WeakMap, it has to be\n // a String object and not a literal. And at least on NodeJS 2.10.1,\n // WeakMap requires that the same String instance is passed for cache hits.\n if (!macEncodingCacheKeys) {\n macEncodingCacheKeys = {};\n for (let e in eightBitMacEncodings) {\n /*jshint -W053 */ // Suppress \"Do not use String as a constructor.\"\n macEncodingCacheKeys[e] = new String(e);\n }\n }\n\n const cacheKey = macEncodingCacheKeys[encoding];\n if (cacheKey === undefined) {\n return undefined;\n }\n\n // We can't do \"if (cache.has(key)) {return cache.get(key)}\" here:\n // since garbage collection may run at any time, it could also kick in\n // between the calls to cache.has() and cache.get(). In that case,\n // we would return 'undefined' even though we do support the encoding.\n if (macEncodingTableCache) {\n const cachedTable = macEncodingTableCache.get(cacheKey);\n if (cachedTable !== undefined) {\n return cachedTable;\n }\n }\n\n const decodingTable = eightBitMacEncodings[encoding];\n if (decodingTable === undefined) {\n return undefined;\n }\n\n const encodingTable = {};\n for (let i = 0; i < decodingTable.length; i++) {\n encodingTable[decodingTable.charCodeAt(i)] = i + 0x80;\n }\n\n if (macEncodingTableCache) {\n macEncodingTableCache.set(cacheKey, encodingTable);\n }\n\n return encodingTable;\n};\n\n/**\n * Encodes an old-style Macintosh string. Returns a byte array upon success.\n * If the requested encoding is unsupported, or if the input string contains\n * a character that cannot be expressed in the encoding, the function returns\n * 'undefined'.\n * @param {string} str\n * @param {string} encoding\n * @returns {Array}\n */\nencode.MACSTRING = function(str, encoding) {\n const table = getMacEncodingTable(encoding);\n if (table === undefined) {\n return undefined;\n }\n\n const result = [];\n for (let i = 0; i < str.length; i++) {\n let c = str.charCodeAt(i);\n\n // In all eight-bit Mac encodings, the characters 0x00..0x7F are\n // mapped to U+0000..U+007F; we only need to look up the others.\n if (c >= 0x80) {\n c = table[c];\n if (c === undefined) {\n // str contains a Unicode character that cannot be encoded\n // in the requested encoding.\n return undefined;\n }\n }\n result[i] = c;\n // result.push(c);\n }\n\n return result;\n};\n\n/**\n * @param {string} str\n * @param {string} encoding\n * @returns {number}\n */\nsizeOf.MACSTRING = function(str, encoding) {\n const b = encode.MACSTRING(str, encoding);\n if (b !== undefined) {\n return b.length;\n } else {\n return 0;\n }\n};\n\n// Helper for encode.VARDELTAS\nfunction isByteEncodable(value) {\n return value >= -128 && value <= 127;\n}\n\n// Helper for encode.VARDELTAS\nfunction encodeVarDeltaRunAsZeroes(deltas, pos, result) {\n let runLength = 0;\n const numDeltas = deltas.length;\n while (pos < numDeltas && runLength < 64 && deltas[pos] === 0) {\n ++pos;\n ++runLength;\n }\n result.push(0x80 | (runLength - 1));\n return pos;\n}\n\n// Helper for encode.VARDELTAS\nfunction encodeVarDeltaRunAsBytes(deltas, offset, result) {\n let runLength = 0;\n const numDeltas = deltas.length;\n let pos = offset;\n while (pos < numDeltas && runLength < 64) {\n const value = deltas[pos];\n if (!isByteEncodable(value)) {\n break;\n }\n\n // Within a byte-encoded run of deltas, a single zero is best\n // stored literally as 0x00 value. However, if we have two or\n // more zeroes in a sequence, it is better to start a new run.\n // Fore example, the sequence of deltas [15, 15, 0, 15, 15]\n // becomes 6 bytes (04 0F 0F 00 0F 0F) when storing the zero\n // within the current run, but 7 bytes (01 0F 0F 80 01 0F 0F)\n // when starting a new run.\n if (value === 0 && pos + 1 < numDeltas && deltas[pos + 1] === 0) {\n break;\n }\n\n ++pos;\n ++runLength;\n }\n result.push(runLength - 1);\n for (let i = offset; i < pos; ++i) {\n result.push((deltas[i] + 256) & 0xff);\n }\n return pos;\n}\n\n// Helper for encode.VARDELTAS\nfunction encodeVarDeltaRunAsWords(deltas, offset, result) {\n let runLength = 0;\n const numDeltas = deltas.length;\n let pos = offset;\n while (pos < numDeltas && runLength < 64) {\n const value = deltas[pos];\n\n // Within a word-encoded run of deltas, it is easiest to start\n // a new run (with a different encoding) whenever we encounter\n // a zero value. For example, the sequence [0x6666, 0, 0x7777]\n // needs 7 bytes when storing the zero inside the current run\n // (42 66 66 00 00 77 77), and equally 7 bytes when starting a\n // new run (40 66 66 80 40 77 77).\n if (value === 0) {\n break;\n }\n\n // Within a word-encoded run of deltas, a single value in the\n // range (-128..127) should be encoded within the current run\n // because it is more compact. For example, the sequence\n // [0x6666, 2, 0x7777] becomes 7 bytes when storing the value\n // literally (42 66 66 00 02 77 77), but 8 bytes when starting\n // a new run (40 66 66 00 02 40 77 77).\n if (isByteEncodable(value) && pos + 1 < numDeltas && isByteEncodable(deltas[pos + 1])) {\n break;\n }\n\n ++pos;\n ++runLength;\n }\n result.push(0x40 | (runLength - 1));\n for (let i = offset; i < pos; ++i) {\n const val = deltas[i];\n result.push(((val + 0x10000) >> 8) & 0xff, (val + 0x100) & 0xff);\n }\n return pos;\n}\n\n/**\n * Encode a list of variation adjustment deltas.\n *\n * Variation adjustment deltas are used in ‘gvar’ and ‘cvar’ tables.\n * They indicate how points (in ‘gvar’) or values (in ‘cvar’) get adjusted\n * when generating instances of variation fonts.\n *\n * @see https://www.microsoft.com/typography/otspec/gvar.htm\n * @see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gvar.html\n * @param {Array}\n * @return {Array}\n */\nencode.VARDELTAS = function(deltas) {\n let pos = 0;\n const result = [];\n while (pos < deltas.length) {\n const value = deltas[pos];\n if (value === 0) {\n pos = encodeVarDeltaRunAsZeroes(deltas, pos, result);\n } else if (value >= -128 && value <= 127) {\n pos = encodeVarDeltaRunAsBytes(deltas, pos, result);\n } else {\n pos = encodeVarDeltaRunAsWords(deltas, pos, result);\n }\n }\n return result;\n};\n\n// Convert a list of values to a CFF INDEX structure.\n// The values should be objects containing name / type / value.\n/**\n * @param {Array} l\n * @returns {Array}\n */\nencode.INDEX = function(l) {\n //var offset, offsets, offsetEncoder, encodedOffsets, encodedOffset, data,\n // i, v;\n // Because we have to know which data type to use to encode the offsets,\n // we have to go through the values twice: once to encode the data and\n // calculate the offsets, then again to encode the offsets using the fitting data type.\n let offset = 1; // First offset is always 1.\n const offsets = [offset];\n const data = [];\n for (let i = 0; i < l.length; i += 1) {\n const v = encode.OBJECT(l[i]);\n Array.prototype.push.apply(data, v);\n offset += v.length;\n offsets.push(offset);\n }\n\n if (data.length === 0) {\n return [0, 0];\n }\n\n const encodedOffsets = [];\n const offSize = (1 + Math.floor(Math.log(offset) / Math.log(2)) / 8) | 0;\n const offsetEncoder = [undefined, encode.BYTE, encode.USHORT, encode.UINT24, encode.ULONG][offSize];\n for (let i = 0; i < offsets.length; i += 1) {\n const encodedOffset = offsetEncoder(offsets[i]);\n Array.prototype.push.apply(encodedOffsets, encodedOffset);\n }\n\n return Array.prototype.concat(encode.Card16(l.length),\n encode.OffSize(offSize),\n encodedOffsets,\n data);\n};\n\n/**\n * @param {Array}\n * @returns {number}\n */\nsizeOf.INDEX = function(v) {\n return encode.INDEX(v).length;\n};\n\n/**\n * Convert an object to a CFF DICT structure.\n * The keys should be numeric.\n * The values should be objects containing name / type / value.\n * @param {Object} m\n * @returns {Array}\n */\nencode.DICT = function(m) {\n let d = [];\n const keys = Object.keys(m);\n const length = keys.length;\n\n for (let i = 0; i < length; i += 1) {\n // Object.keys() return string keys, but our keys are always numeric.\n const k = parseInt(keys[i], 0);\n const v = m[k];\n // Value comes before the key.\n d = d.concat(encode.OPERAND(v.value, v.type));\n d = d.concat(encode.OPERATOR(k));\n }\n\n return d;\n};\n\n/**\n * @param {Object}\n * @returns {number}\n */\nsizeOf.DICT = function(m) {\n return encode.DICT(m).length;\n};\n\n/**\n * @param {number}\n * @returns {Array}\n */\nencode.OPERATOR = function(v) {\n if (v < 1200) {\n return [v];\n } else {\n return [12, v - 1200];\n }\n};\n\n/**\n * @param {Array} v\n * @param {string}\n * @returns {Array}\n */\nencode.OPERAND = function(v, type) {\n let d = [];\n if (Array.isArray(type)) {\n for (let i = 0; i < type.length; i += 1) {\n check.argument(v.length === type.length, 'Not enough arguments given for type' + type);\n d = d.concat(encode.OPERAND(v[i], type[i]));\n }\n } else {\n if (type === 'SID') {\n d = d.concat(encode.NUMBER(v));\n } else if (type === 'offset') {\n // We make it easy for ourselves and always encode offsets as\n // 4 bytes. This makes offset calculation for the top dict easier.\n d = d.concat(encode.NUMBER32(v));\n } else if (type === 'number') {\n d = d.concat(encode.NUMBER(v));\n } else if (type === 'real') {\n d = d.concat(encode.REAL(v));\n } else {\n throw new Error('Unknown operand type ' + type);\n // FIXME Add support for booleans\n }\n }\n\n return d;\n};\n\nencode.OP = encode.BYTE;\nsizeOf.OP = sizeOf.BYTE;\n\n// memoize charstring encoding using WeakMap if available\nconst wmm = typeof WeakMap === 'function' && new WeakMap();\n\n/**\n * Convert a list of CharString operations to bytes.\n * @param {Array}\n * @returns {Array}\n */\nencode.CHARSTRING = function(ops) {\n // See encode.MACSTRING for why we don't do \"if (wmm && wmm.has(ops))\".\n if (wmm) {\n const cachedValue = wmm.get(ops);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n }\n\n let d = [];\n const length = ops.length;\n\n for (let i = 0; i < length; i += 1) {\n const op = ops[i];\n d = d.concat(encode[op.type](op.value));\n }\n\n if (wmm) {\n wmm.set(ops, d);\n }\n\n return d;\n};\n\n/**\n * @param {Array}\n * @returns {number}\n */\nsizeOf.CHARSTRING = function(ops) {\n return encode.CHARSTRING(ops).length;\n};\n\n// Utility functions ////////////////////////////////////////////////////////\n\n/**\n * Convert an object containing name / type / value to bytes.\n * @param {Object}\n * @returns {Array}\n */\nencode.OBJECT = function(v) {\n const encodingFunction = encode[v.type];\n check.argument(encodingFunction !== undefined, 'No encoding function for type ' + v.type);\n return encodingFunction(v.value);\n};\n\n/**\n * @param {Object}\n * @returns {number}\n */\nsizeOf.OBJECT = function(v) {\n const sizeOfFunction = sizeOf[v.type];\n check.argument(sizeOfFunction !== undefined, 'No sizeOf function for type ' + v.type);\n return sizeOfFunction(v.value);\n};\n\n/**\n * Convert a table object to bytes.\n * A table contains a list of fields containing the metadata (name, type and default value).\n * The table itself has the field values set as attributes.\n * @param {opentype.Table}\n * @returns {Array}\n */\nencode.TABLE = function(table) {\n let d = [];\n const length = table.fields.length;\n const subtables = [];\n const subtableOffsets = [];\n\n for (let i = 0; i < length; i += 1) {\n const field = table.fields[i];\n const encodingFunction = encode[field.type];\n check.argument(encodingFunction !== undefined, 'No encoding function for field type ' + field.type + ' (' + field.name + ')');\n let value = table[field.name];\n if (value === undefined) {\n value = field.value;\n }\n\n const bytes = encodingFunction(value);\n\n if (field.type === 'TABLE') {\n subtableOffsets.push(d.length);\n d = d.concat([0, 0]);\n subtables.push(bytes);\n } else {\n d = d.concat(bytes);\n }\n }\n\n for (let i = 0; i < subtables.length; i += 1) {\n const o = subtableOffsets[i];\n const offset = d.length;\n check.argument(offset < 65536, 'Table ' + table.tableName + ' too big.');\n d[o] = offset >> 8;\n d[o + 1] = offset & 0xff;\n d = d.concat(subtables[i]);\n }\n\n return d;\n};\n\n/**\n * @param {opentype.Table}\n * @returns {number}\n */\nsizeOf.TABLE = function(table) {\n let numBytes = 0;\n const length = table.fields.length;\n\n for (let i = 0; i < length; i += 1) {\n const field = table.fields[i];\n const sizeOfFunction = sizeOf[field.type];\n check.argument(sizeOfFunction !== undefined, 'No sizeOf function for field type ' + field.type + ' (' + field.name + ')');\n let value = table[field.name];\n if (value === undefined) {\n value = field.value;\n }\n\n numBytes += sizeOfFunction(value);\n\n // Subtables take 2 more bytes for offsets.\n if (field.type === 'TABLE') {\n numBytes += 2;\n }\n }\n\n return numBytes;\n};\n\nencode.RECORD = encode.TABLE;\nsizeOf.RECORD = sizeOf.TABLE;\n\n// Merge in a list of bytes.\nencode.LITERAL = function(v) {\n return v;\n};\n\nsizeOf.LITERAL = function(v) {\n return v.length;\n};\n\nexport { decode, encode, sizeOf };\n","// Table metadata\n\nimport check from './check';\nimport { encode, sizeOf } from './types';\n\n/**\n * @exports opentype.Table\n * @class\n * @param {string} tableName\n * @param {Array} fields\n * @param {Object} options\n * @constructor\n */\nfunction Table(tableName, fields, options) {\n // For coverage tables with coverage format 2, we do not want to add the coverage data directly to the table object,\n // as this will result in wrong encoding order of the coverage data on serialization to bytes.\n // The fallback of using the field values directly when not present on the table is handled in types.encode.TABLE() already.\n if (fields.length && (fields[0].name !== 'coverageFormat' || fields[0].value === 1)) {\n for (let i = 0; i < fields.length; i += 1) {\n const field = fields[i];\n this[field.name] = field.value;\n }\n }\n\n this.tableName = tableName;\n this.fields = fields;\n if (options) {\n const optionKeys = Object.keys(options);\n for (let i = 0; i < optionKeys.length; i += 1) {\n const k = optionKeys[i];\n const v = options[k];\n if (this[k] !== undefined) {\n this[k] = v;\n }\n }\n }\n}\n\n/**\n * Encodes the table and returns an array of bytes\n * @return {Array}\n */\nTable.prototype.encode = function() {\n return encode.TABLE(this);\n};\n\n/**\n * Get the size of the table.\n * @return {number}\n */\nTable.prototype.sizeOf = function() {\n return sizeOf.TABLE(this);\n};\n\n/**\n * @private\n */\nfunction ushortList(itemName, list, count) {\n if (count === undefined) {\n count = list.length;\n }\n const fields = new Array(list.length + 1);\n fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};\n for (let i = 0; i < list.length; i++) {\n fields[i + 1] = {name: itemName + i, type: 'USHORT', value: list[i]};\n }\n return fields;\n}\n\n/**\n * @private\n */\nfunction tableList(itemName, records, itemCallback) {\n const count = records.length;\n const fields = new Array(count + 1);\n fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};\n for (let i = 0; i < count; i++) {\n fields[i + 1] = {name: itemName + i, type: 'TABLE', value: itemCallback(records[i], i)};\n }\n return fields;\n}\n\n/**\n * @private\n */\nfunction recordList(itemName, records, itemCallback) {\n const count = records.length;\n let fields = [];\n fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};\n for (let i = 0; i < count; i++) {\n fields = fields.concat(itemCallback(records[i], i));\n }\n return fields;\n}\n\n// Common Layout Tables\n\n/**\n * @exports opentype.Coverage\n * @class\n * @param {opentype.Table}\n * @constructor\n * @extends opentype.Table\n */\nfunction Coverage(coverageTable) {\n if (coverageTable.format === 1) {\n Table.call(this, 'coverageTable',\n [{name: 'coverageFormat', type: 'USHORT', value: 1}]\n .concat(ushortList('glyph', coverageTable.glyphs))\n );\n } else if (coverageTable.format === 2) {\n Table.call(this, 'coverageTable',\n [{name: 'coverageFormat', type: 'USHORT', value: 2}]\n .concat(recordList('rangeRecord', coverageTable.ranges, function(RangeRecord) {\n return [\n {name: 'startGlyphID', type: 'USHORT', value: RangeRecord.start},\n {name: 'endGlyphID', type: 'USHORT', value: RangeRecord.end},\n {name: 'startCoverageIndex', type: 'USHORT', value: RangeRecord.index},\n ];\n }))\n );\n } else {\n check.assert(false, 'Coverage format must be 1 or 2.');\n }\n}\nCoverage.prototype = Object.create(Table.prototype);\nCoverage.prototype.constructor = Coverage;\n\nfunction ScriptList(scriptListTable) {\n Table.call(this, 'scriptListTable',\n recordList('scriptRecord', scriptListTable, function(scriptRecord, i) {\n const script = scriptRecord.script;\n let defaultLangSys = script.defaultLangSys;\n check.assert(!!defaultLangSys, 'Unable to write GSUB: script ' + scriptRecord.tag + ' has no default language system.');\n return [\n {name: 'scriptTag' + i, type: 'TAG', value: scriptRecord.tag},\n {name: 'script' + i, type: 'TABLE', value: new Table('scriptTable', [\n {name: 'defaultLangSys', type: 'TABLE', value: new Table('defaultLangSys', [\n {name: 'lookupOrder', type: 'USHORT', value: 0},\n {name: 'reqFeatureIndex', type: 'USHORT', value: defaultLangSys.reqFeatureIndex}]\n .concat(ushortList('featureIndex', defaultLangSys.featureIndexes)))}\n ].concat(recordList('langSys', script.langSysRecords, function(langSysRecord, i) {\n const langSys = langSysRecord.langSys;\n return [\n {name: 'langSysTag' + i, type: 'TAG', value: langSysRecord.tag},\n {name: 'langSys' + i, type: 'TABLE', value: new Table('langSys', [\n {name: 'lookupOrder', type: 'USHORT', value: 0},\n {name: 'reqFeatureIndex', type: 'USHORT', value: langSys.reqFeatureIndex}\n ].concat(ushortList('featureIndex', langSys.featureIndexes)))}\n ];\n })))}\n ];\n })\n );\n}\nScriptList.prototype = Object.create(Table.prototype);\nScriptList.prototype.constructor = ScriptList;\n\n/**\n * @exports opentype.FeatureList\n * @class\n * @param {opentype.Table}\n * @constructor\n * @extends opentype.Table\n */\nfunction FeatureList(featureListTable) {\n Table.call(this, 'featureListTable',\n recordList('featureRecord', featureListTable, function(featureRecord, i) {\n const feature = featureRecord.feature;\n return [\n {name: 'featureTag' + i, type: 'TAG', value: featureRecord.tag},\n {name: 'feature' + i, type: 'TABLE', value: new Table('featureTable', [\n {name: 'featureParams', type: 'USHORT', value: feature.featureParams},\n ].concat(ushortList('lookupListIndex', feature.lookupListIndexes)))}\n ];\n })\n );\n}\nFeatureList.prototype = Object.create(Table.prototype);\nFeatureList.prototype.constructor = FeatureList;\n\n/**\n * @exports opentype.LookupList\n * @class\n * @param {opentype.Table}\n * @param {Object}\n * @constructor\n * @extends opentype.Table\n */\nfunction LookupList(lookupListTable, subtableMakers) {\n Table.call(this, 'lookupListTable', tableList('lookup', lookupListTable, function(lookupTable) {\n let subtableCallback = subtableMakers[lookupTable.lookupType];\n check.assert(!!subtableCallback, 'Unable to write GSUB lookup type ' + lookupTable.lookupType + ' tables.');\n return new Table('lookupTable', [\n {name: 'lookupType', type: 'USHORT', value: lookupTable.lookupType},\n {name: 'lookupFlag', type: 'USHORT', value: lookupTable.lookupFlag}\n ].concat(tableList('subtable', lookupTable.subtables, subtableCallback)));\n }));\n}\nLookupList.prototype = Object.create(Table.prototype);\nLookupList.prototype.constructor = LookupList;\n\n// Record = same as Table, but inlined (a Table has an offset and its data is further in the stream)\n// Don't use offsets inside Records (probable bug), only in Tables.\nexport default {\n Table,\n Record: Table,\n Coverage,\n ScriptList,\n FeatureList,\n LookupList,\n ushortList,\n tableList,\n recordList,\n};\n","// Parsing utility functions\n\nimport check from './check';\n\n// Retrieve an unsigned byte from the DataView.\nfunction getByte(dataView, offset) {\n return dataView.getUint8(offset);\n}\n\n// Retrieve an unsigned 16-bit short from the DataView.\n// The value is stored in big endian.\nfunction getUShort(dataView, offset) {\n return dataView.getUint16(offset, false);\n}\n\n// Retrieve a signed 16-bit short from the DataView.\n// The value is stored in big endian.\nfunction getShort(dataView, offset) {\n return dataView.getInt16(offset, false);\n}\n\n// Retrieve an unsigned 32-bit long from the DataView.\n// The value is stored in big endian.\nfunction getULong(dataView, offset) {\n return dataView.getUint32(offset, false);\n}\n\n// Retrieve a 32-bit signed fixed-point number (16.16) from the DataView.\n// The value is stored in big endian.\nfunction getFixed(dataView, offset) {\n const decimal = dataView.getInt16(offset, false);\n const fraction = dataView.getUint16(offset + 2, false);\n return decimal + fraction / 65535;\n}\n\n// Retrieve a 4-character tag from the DataView.\n// Tags are used to identify tables.\nfunction getTag(dataView, offset) {\n let tag = '';\n for (let i = offset; i < offset + 4; i += 1) {\n tag += String.fromCharCode(dataView.getInt8(i));\n }\n\n return tag;\n}\n\n// Retrieve an offset from the DataView.\n// Offsets are 1 to 4 bytes in length, depending on the offSize argument.\nfunction getOffset(dataView, offset, offSize) {\n let v = 0;\n for (let i = 0; i < offSize; i += 1) {\n v <<= 8;\n v += dataView.getUint8(offset + i);\n }\n\n return v;\n}\n\n// Retrieve a number of bytes from start offset to the end offset from the DataView.\nfunction getBytes(dataView, startOffset, endOffset) {\n const bytes = [];\n for (let i = startOffset; i < endOffset; i += 1) {\n bytes.push(dataView.getUint8(i));\n }\n\n return bytes;\n}\n\n// Convert the list of bytes to a string.\nfunction bytesToString(bytes) {\n let s = '';\n for (let i = 0; i < bytes.length; i += 1) {\n s += String.fromCharCode(bytes[i]);\n }\n\n return s;\n}\n\nconst typeOffsets = {\n byte: 1,\n uShort: 2,\n short: 2,\n uLong: 4,\n fixed: 4,\n longDateTime: 8,\n tag: 4\n};\n\n// A stateful parser that changes the offset whenever a value is retrieved.\n// The data is a DataView.\nfunction Parser(data, offset) {\n this.data = data;\n this.offset = offset;\n this.relativeOffset = 0;\n}\n\nParser.prototype.parseByte = function() {\n const v = this.data.getUint8(this.offset + this.relativeOffset);\n this.relativeOffset += 1;\n return v;\n};\n\nParser.prototype.parseChar = function() {\n const v = this.data.getInt8(this.offset + this.relativeOffset);\n this.relativeOffset += 1;\n return v;\n};\n\nParser.prototype.parseCard8 = Parser.prototype.parseByte;\n\nParser.prototype.parseUShort = function() {\n const v = this.data.getUint16(this.offset + this.relativeOffset);\n this.relativeOffset += 2;\n return v;\n};\n\nParser.prototype.parseCard16 = Parser.prototype.parseUShort;\nParser.prototype.parseSID = Parser.prototype.parseUShort;\nParser.prototype.parseOffset16 = Parser.prototype.parseUShort;\n\nParser.prototype.parseShort = function() {\n const v = this.data.getInt16(this.offset + this.relativeOffset);\n this.relativeOffset += 2;\n return v;\n};\n\nParser.prototype.parseF2Dot14 = function() {\n const v = this.data.getInt16(this.offset + this.relativeOffset) / 16384;\n this.relativeOffset += 2;\n return v;\n};\n\nParser.prototype.parseULong = function() {\n const v = getULong(this.data, this.offset + this.relativeOffset);\n this.relativeOffset += 4;\n return v;\n};\n\nParser.prototype.parseOffset32 = Parser.prototype.parseULong;\n\nParser.prototype.parseFixed = function() {\n const v = getFixed(this.data, this.offset + this.relativeOffset);\n this.relativeOffset += 4;\n return v;\n};\n\nParser.prototype.parseString = function(length) {\n const dataView = this.data;\n const offset = this.offset + this.relativeOffset;\n let string = '';\n this.relativeOffset += length;\n for (let i = 0; i < length; i++) {\n string += String.fromCharCode(dataView.getUint8(offset + i));\n }\n\n return string;\n};\n\nParser.prototype.parseTag = function() {\n return this.parseString(4);\n};\n\n// LONGDATETIME is a 64-bit integer.\n// JavaScript and unix timestamps traditionally use 32 bits, so we\n// only take the last 32 bits.\n// + Since until 2038 those bits will be filled by zeros we can ignore them.\nParser.prototype.parseLongDateTime = function() {\n let v = getULong(this.data, this.offset + this.relativeOffset + 4);\n // Subtract seconds between 01/01/1904 and 01/01/1970\n // to convert Apple Mac timestamp to Standard Unix timestamp\n v -= 2082844800;\n this.relativeOffset += 8;\n return v;\n};\n\nParser.prototype.parseVersion = function(minorBase) {\n const major = getUShort(this.data, this.offset + this.relativeOffset);\n\n // How to interpret the minor version is very vague in the spec. 0x5000 is 5, 0x1000 is 1\n // Default returns the correct number if minor = 0xN000 where N is 0-9\n // Set minorBase to 1 for tables that use minor = N where N is 0-9\n const minor = getUShort(this.data, this.offset + this.relativeOffset + 2);\n this.relativeOffset += 4;\n if (minorBase === undefined) minorBase = 0x1000;\n return major + minor / minorBase / 10;\n};\n\nParser.prototype.skip = function(type, amount) {\n if (amount === undefined) {\n amount = 1;\n }\n\n this.relativeOffset += typeOffsets[type] * amount;\n};\n\n///// Parsing lists and records ///////////////////////////////\n\n// Parse a list of 32 bit unsigned integers.\nParser.prototype.parseULongList = function(count) {\n if (count === undefined) { count = this.parseULong(); }\n const offsets = new Array(count);\n const dataView = this.data;\n let offset = this.offset + this.relativeOffset;\n for (let i = 0; i < count; i++) {\n offsets[i] = dataView.getUint32(offset);\n offset += 4;\n }\n\n this.relativeOffset += count * 4;\n return offsets;\n};\n\n// Parse a list of 16 bit unsigned integers. The length of the list can be read on the stream\n// or provided as an argument.\nParser.prototype.parseOffset16List =\nParser.prototype.parseUShortList = function(count) {\n if (count === undefined) { count = this.parseUShort(); }\n const offsets = new Array(count);\n const dataView = this.data;\n let offset = this.offset + this.relativeOffset;\n for (let i = 0; i < count; i++) {\n offsets[i] = dataView.getUint16(offset);\n offset += 2;\n }\n\n this.relativeOffset += count * 2;\n return offsets;\n};\n\n// Parses a list of 16 bit signed integers.\nParser.prototype.parseShortList = function(count) {\n const list = new Array(count);\n const dataView = this.data;\n let offset = this.offset + this.relativeOffset;\n for (let i = 0; i < count; i++) {\n list[i] = dataView.getInt16(offset);\n offset += 2;\n }\n\n this.relativeOffset += count * 2;\n return list;\n};\n\n// Parses a list of bytes.\nParser.prototype.parseByteList = function(count) {\n const list = new Array(count);\n const dataView = this.data;\n let offset = this.offset + this.relativeOffset;\n for (let i = 0; i < count; i++) {\n list[i] = dataView.getUint8(offset++);\n }\n\n this.relativeOffset += count;\n return list;\n};\n\n/**\n * Parse a list of items.\n * Record count is optional, if omitted it is read from the stream.\n * itemCallback is one of the Parser methods.\n */\nParser.prototype.parseList = function(count, itemCallback) {\n if (!itemCallback) {\n itemCallback = count;\n count = this.parseUShort();\n }\n const list = new Array(count);\n for (let i = 0; i < count; i++) {\n list[i] = itemCallback.call(this);\n }\n return list;\n};\n\nParser.prototype.parseList32 = function(count, itemCallback) {\n if (!itemCallback) {\n itemCallback = count;\n count = this.parseULong();\n }\n const list = new Array(count);\n for (let i = 0; i < count; i++) {\n list[i] = itemCallback.call(this);\n }\n return list;\n};\n\n/**\n * Parse a list of records.\n * Record count is optional, if omitted it is read from the stream.\n * Example of recordDescription: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort }\n */\nParser.prototype.parseRecordList = function(count, recordDescription) {\n // If the count argument is absent, read it in the stream.\n if (!recordDescription) {\n recordDescription = count;\n count = this.parseUShort();\n }\n const records = new Array(count);\n const fields = Object.keys(recordDescription);\n for (let i = 0; i < count; i++) {\n const rec = {};\n for (let j = 0; j < fields.length; j++) {\n const fieldName = fields[j];\n const fieldType = recordDescription[fieldName];\n rec[fieldName] = fieldType.call(this);\n }\n records[i] = rec;\n }\n return records;\n};\n\nParser.prototype.parseRecordList32 = function(count, recordDescription) {\n // If the count argument is absent, read it in the stream.\n if (!recordDescription) {\n recordDescription = count;\n count = this.parseULong();\n }\n const records = new Array(count);\n const fields = Object.keys(recordDescription);\n for (let i = 0; i < count; i++) {\n const rec = {};\n for (let j = 0; j < fields.length; j++) {\n const fieldName = fields[j];\n const fieldType = recordDescription[fieldName];\n rec[fieldName] = fieldType.call(this);\n }\n records[i] = rec;\n }\n return records;\n};\n\n// Parse a data structure into an object\n// Example of description: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort }\nParser.prototype.parseStruct = function(description) {\n if (typeof description === 'function') {\n return description.call(this);\n } else {\n const fields = Object.keys(description);\n const struct = {};\n for (let j = 0; j < fields.length; j++) {\n const fieldName = fields[j];\n const fieldType = description[fieldName];\n struct[fieldName] = fieldType.call(this);\n }\n return struct;\n }\n};\n\n/**\n * Parse a GPOS valueRecord\n * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record\n * valueFormat is optional, if omitted it is read from the stream.\n */\nParser.prototype.parseValueRecord = function(valueFormat) {\n if (valueFormat === undefined) {\n valueFormat = this.parseUShort();\n }\n if (valueFormat === 0) {\n // valueFormat2 in kerning pairs is most often 0\n // in this case return undefined instead of an empty object, to save space\n return;\n }\n const valueRecord = {};\n\n if (valueFormat & 0x0001) { valueRecord.xPlacement = this.parseShort(); }\n if (valueFormat & 0x0002) { valueRecord.yPlacement = this.parseShort(); }\n if (valueFormat & 0x0004) { valueRecord.xAdvance = this.parseShort(); }\n if (valueFormat & 0x0008) { valueRecord.yAdvance = this.parseShort(); }\n\n // Device table (non-variable font) / VariationIndex table (variable font) not supported\n // https://docs.microsoft.com/fr-fr/typography/opentype/spec/chapter2#devVarIdxTbls\n if (valueFormat & 0x0010) { valueRecord.xPlaDevice = undefined; this.parseShort(); }\n if (valueFormat & 0x0020) { valueRecord.yPlaDevice = undefined; this.parseShort(); }\n if (valueFormat & 0x0040) { valueRecord.xAdvDevice = undefined; this.parseShort(); }\n if (valueFormat & 0x0080) { valueRecord.yAdvDevice = undefined; this.parseShort(); }\n\n return valueRecord;\n};\n\n/**\n * Parse a list of GPOS valueRecords\n * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record\n * valueFormat and valueCount are read from the stream.\n */\nParser.prototype.parseValueRecordList = function() {\n const valueFormat = this.parseUShort();\n const valueCount = this.parseUShort();\n const values = new Array(valueCount);\n for (let i = 0; i < valueCount; i++) {\n values[i] = this.parseValueRecord(valueFormat);\n }\n return values;\n};\n\nParser.prototype.parsePointer = function(description) {\n const structOffset = this.parseOffset16();\n if (structOffset > 0) {\n // NULL offset => return undefined\n return new Parser(this.data, this.offset + structOffset).parseStruct(description);\n }\n return undefined;\n};\n\nParser.prototype.parsePointer32 = function(description) {\n const structOffset = this.parseOffset32();\n if (structOffset > 0) {\n // NULL offset => return undefined\n return new Parser(this.data, this.offset + structOffset).parseStruct(description);\n }\n return undefined;\n};\n\n/**\n * Parse a list of offsets to lists of 16-bit integers,\n * or a list of offsets to lists of offsets to any kind of items.\n * If itemCallback is not provided, a list of list of UShort is assumed.\n * If provided, itemCallback is called on each item and must parse the item.\n * See examples in tables/gsub.js\n */\nParser.prototype.parseListOfLists = function(itemCallback) {\n const offsets = this.parseOffset16List();\n const count = offsets.length;\n const relativeOffset = this.relativeOffset;\n const list = new Array(count);\n for (let i = 0; i < count; i++) {\n const start = offsets[i];\n if (start === 0) {\n // NULL offset\n // Add i as owned property to list. Convenient with assert.\n list[i] = undefined;\n continue;\n }\n this.relativeOffset = start;\n if (itemCallback) {\n const subOffsets = this.parseOffset16List();\n const subList = new Array(subOffsets.length);\n for (let j = 0; j < subOffsets.length; j++) {\n this.relativeOffset = start + subOffsets[j];\n subList[j] = itemCallback.call(this);\n }\n list[i] = subList;\n } else {\n list[i] = this.parseUShortList();\n }\n }\n this.relativeOffset = relativeOffset;\n return list;\n};\n\n///// Complex tables parsing //////////////////////////////////\n\n// Parse a coverage table in a GSUB, GPOS or GDEF table.\n// https://www.microsoft.com/typography/OTSPEC/chapter2.htm\n// parser.offset must point to the start of the table containing the coverage.\nParser.prototype.parseCoverage = function() {\n const startOffset = this.offset + this.relativeOffset;\n const format = this.parseUShort();\n const count = this.parseUShort();\n if (format === 1) {\n return {\n format: 1,\n glyphs: this.parseUShortList(count)\n };\n } else if (format === 2) {\n const ranges = new Array(count);\n for (let i = 0; i < count; i++) {\n ranges[i] = {\n start: this.parseUShort(),\n end: this.parseUShort(),\n index: this.parseUShort()\n };\n }\n return {\n format: 2,\n ranges: ranges\n };\n }\n throw new Error('0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.');\n};\n\n// Parse a Class Definition Table in a GSUB, GPOS or GDEF table.\n// https://www.microsoft.com/typography/OTSPEC/chapter2.htm\nParser.prototype.parseClassDef = function() {\n const startOffset = this.offset + this.relativeOffset;\n const format = this.parseUShort();\n if (format === 1) {\n return {\n format: 1,\n startGlyph: this.parseUShort(),\n classes: this.parseUShortList()\n };\n } else if (format === 2) {\n return {\n format: 2,\n ranges: this.parseRecordList({\n start: Parser.uShort,\n end: Parser.uShort,\n classId: Parser.uShort\n })\n };\n }\n throw new Error('0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.');\n};\n\n///// Static methods ///////////////////////////////////\n// These convenience methods can be used as callbacks and should be called with \"this\" context set to a Parser instance.\n\nParser.list = function(count, itemCallback) {\n return function() {\n return this.parseList(count, itemCallback);\n };\n};\n\nParser.list32 = function(count, itemCallback) {\n return function() {\n return this.parseList32(count, itemCallback);\n };\n};\n\nParser.recordList = function(count, recordDescription) {\n return function() {\n return this.parseRecordList(count, recordDescription);\n };\n};\n\nParser.recordList32 = function(count, recordDescription) {\n return function() {\n return this.parseRecordList32(count, recordDescription);\n };\n};\n\nParser.pointer = function(description) {\n return function() {\n return this.parsePointer(description);\n };\n};\n\nParser.pointer32 = function(description) {\n return function() {\n return this.parsePointer32(description);\n };\n};\n\nParser.tag = Parser.prototype.parseTag;\nParser.byte = Parser.prototype.parseByte;\nParser.uShort = Parser.offset16 = Parser.prototype.parseUShort;\nParser.uShortList = Parser.prototype.parseUShortList;\nParser.uLong = Parser.offset32 = Parser.prototype.parseULong;\nParser.uLongList = Parser.prototype.parseULongList;\nParser.struct = Parser.prototype.parseStruct;\nParser.coverage = Parser.prototype.parseCoverage;\nParser.classDef = Parser.prototype.parseClassDef;\n\n///// Script, Feature, Lookup lists ///////////////////////////////////////////////\n// https://www.microsoft.com/typography/OTSPEC/chapter2.htm\n\nconst langSysTable = {\n reserved: Parser.uShort,\n reqFeatureIndex: Parser.uShort,\n featureIndexes: Parser.uShortList\n};\n\nParser.prototype.parseScriptList = function() {\n return this.parsePointer(Parser.recordList({\n tag: Parser.tag,\n script: Parser.pointer({\n defaultLangSys: Parser.pointer(langSysTable),\n langSysRecords: Parser.recordList({\n tag: Parser.tag,\n langSys: Parser.pointer(langSysTable)\n })\n })\n })) || [];\n};\n\nParser.prototype.parseFeatureList = function() {\n return this.parsePointer(Parser.recordList({\n tag: Parser.tag,\n feature: Parser.pointer({\n featureParams: Parser.offset16,\n lookupListIndexes: Parser.uShortList\n })\n })) || [];\n};\n\nParser.prototype.parseLookupList = function(lookupTableParsers) {\n return this.parsePointer(Parser.list(Parser.pointer(function() {\n const lookupType = this.parseUShort();\n check.argument(1 <= lookupType && lookupType <= 9, 'GPOS/GSUB lookup type ' + lookupType + ' unknown.');\n const lookupFlag = this.parseUShort();\n const useMarkFilteringSet = lookupFlag & 0x10;\n return {\n lookupType: lookupType,\n lookupFlag: lookupFlag,\n subtables: this.parseList(Parser.pointer(lookupTableParsers[lookupType])),\n markFilteringSet: useMarkFilteringSet ? this.parseUShort() : undefined\n };\n }))) || [];\n};\n\nParser.prototype.parseFeatureVariationsList = function() {\n return this.parsePointer32(function() {\n const majorVersion = this.parseUShort();\n const minorVersion = this.parseUShort();\n check.argument(majorVersion === 1 && minorVersion < 1, 'GPOS/GSUB feature variations table unknown.');\n const featureVariations = this.parseRecordList32({\n conditionSetOffset: Parser.offset32,\n featureTableSubstitutionOffset: Parser.offset32\n });\n return featureVariations;\n }) || [];\n};\n\nexport default {\n getByte,\n getCard8: getByte,\n getUShort,\n getCard16: getUShort,\n getShort,\n getULong,\n getFixed,\n getTag,\n getOffset,\n getBytes,\n bytesToString,\n Parser,\n};\n\nexport { Parser };\n","// The `cmap` table stores the mappings from characters to glyphs.\n// https://www.microsoft.com/typography/OTSPEC/cmap.htm\n\nimport check from '../check';\nimport parse from '../parse';\nimport table from '../table';\n\nfunction parseCmapTableFormat12(cmap, p) {\n //Skip reserved.\n p.parseUShort();\n\n // Length in bytes of the sub-tables.\n cmap.length = p.parseULong();\n cmap.language = p.parseULong();\n\n let groupCount;\n cmap.groupCount = groupCount = p.parseULong();\n cmap.glyphIndexMap = {};\n\n for (let i = 0; i < groupCount; i += 1) {\n const startCharCode = p.parseULong();\n const endCharCode = p.parseULong();\n let startGlyphId = p.parseULong();\n\n for (let c = startCharCode; c <= endCharCode; c += 1) {\n cmap.glyphIndexMap[c] = startGlyphId;\n startGlyphId++;\n }\n }\n}\n\nfunction parseCmapTableFormat4(cmap, p, data, start, offset) {\n // Length in bytes of the sub-tables.\n cmap.length = p.parseUShort();\n cmap.language = p.parseUShort();\n\n // segCount is stored x 2.\n let segCount;\n cmap.segCount = segCount = p.parseUShort() >> 1;\n\n // Skip searchRange, entrySelector, rangeShift.\n p.skip('uShort', 3);\n\n // The \"unrolled\" mapping from character codes to glyph indices.\n cmap.glyphIndexMap = {};\n const endCountParser = new parse.Parser(data, start + offset + 14);\n const startCountParser = new parse.Parser(data, start + offset + 16 + segCount * 2);\n const idDeltaParser = new parse.Parser(data, start + offset + 16 + segCount * 4);\n const idRangeOffsetParser = new parse.Parser(data, start + offset + 16 + segCount * 6);\n let glyphIndexOffset = start + offset + 16 + segCount * 8;\n for (let i = 0; i < segCount - 1; i += 1) {\n let glyphIndex;\n const endCount = endCountParser.parseUShort();\n const startCount = startCountParser.parseUShort();\n const idDelta = idDeltaParser.parseShort();\n const idRangeOffset = idRangeOffsetParser.parseUShort();\n for (let c = startCount; c <= endCount; c += 1) {\n if (idRangeOffset !== 0) {\n // The idRangeOffset is relative to the current position in the idRangeOffset array.\n // Take the current offset in the idRangeOffset array.\n glyphIndexOffset = (idRangeOffsetParser.offset + idRangeOffsetParser.relativeOffset - 2);\n\n // Add the value of the idRangeOffset, which will move us into the glyphIndex array.\n glyphIndexOffset += idRangeOffset;\n\n // Then add the character index of the current segment, multiplied by 2 for USHORTs.\n glyphIndexOffset += (c - startCount) * 2;\n glyphIndex = parse.getUShort(data, glyphIndexOffset);\n if (glyphIndex !== 0) {\n glyphIndex = (glyphIndex + idDelta) & 0xFFFF;\n }\n } else {\n glyphIndex = (c + idDelta) & 0xFFFF;\n }\n\n cmap.glyphIndexMap[c] = glyphIndex;\n }\n }\n}\n\n// Parse the `cmap` table. This table stores the mappings from characters to glyphs.\n// There are many available formats, but we only support the Windows format 4 and 12.\n// This function returns a `CmapEncoding` object or null if no supported format could be found.\nfunction parseCmapTable(data, start) {\n const cmap = {};\n cmap.version = parse.getUShort(data, start);\n check.argument(cmap.version === 0, 'cmap table version should be 0.');\n\n // The cmap table can contain many sub-tables, each with their own format.\n // We're only interested in a \"platform 0\" (Unicode format) and \"platform 3\" (Windows format) table.\n cmap.numTables = parse.getUShort(data, start + 2);\n let offset = -1;\n for (let i = cmap.numTables - 1; i >= 0; i -= 1) {\n const platformId = parse.getUShort(data, start + 4 + (i * 8));\n const encodingId = parse.getUShort(data, start + 4 + (i * 8) + 2);\n if ((platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10)) ||\n (platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 2 || encodingId === 3 || encodingId === 4))) {\n offset = parse.getULong(data, start + 4 + (i * 8) + 4);\n break;\n }\n }\n\n if (offset === -1) {\n // There is no cmap table in the font that we support.\n throw new Error('No valid cmap sub-tables found.');\n }\n\n const p = new parse.Parser(data, start + offset);\n cmap.format = p.parseUShort();\n\n if (cmap.format === 12) {\n parseCmapTableFormat12(cmap, p);\n } else if (cmap.format === 4) {\n parseCmapTableFormat4(cmap, p, data, start, offset);\n } else {\n throw new Error('Only format 4 and 12 cmap tables are supported (found format ' + cmap.format + ').');\n }\n\n return cmap;\n}\n\nfunction addSegment(t, code, glyphIndex) {\n t.segments.push({\n end: code,\n start: code,\n delta: -(code - glyphIndex),\n offset: 0,\n glyphIndex: glyphIndex\n });\n}\n\nfunction addTerminatorSegment(t) {\n t.segments.push({\n end: 0xFFFF,\n start: 0xFFFF,\n delta: 1,\n offset: 0\n });\n}\n\n// Make cmap table, format 4 by default, 12 if needed only\nfunction makeCmapTable(glyphs) {\n // Plan 0 is the base Unicode Plan but emojis, for example are on another plan, and needs cmap 12 format (with 32bit)\n let isPlan0Only = true;\n let i;\n\n // Check if we need to add cmap format 12 or if format 4 only is fine\n for (i = glyphs.length - 1; i > 0; i -= 1) {\n const g = glyphs.get(i);\n if (g.unicode > 65535) {\n console.log('Adding CMAP format 12 (needed!)');\n isPlan0Only = false;\n break;\n }\n }\n\n let cmapTable = [\n {name: 'version', type: 'USHORT', value: 0},\n {name: 'numTables', type: 'USHORT', value: isPlan0Only ? 1 : 2},\n\n // CMAP 4 header\n {name: 'platformID', type: 'USHORT', value: 3},\n {name: 'encodingID', type: 'USHORT', value: 1},\n {name: 'offset', type: 'ULONG', value: isPlan0Only ? 12 : (12 + 8)}\n ];\n\n if (!isPlan0Only)\n cmapTable = cmapTable.concat([\n // CMAP 12 header\n {name: 'cmap12PlatformID', type: 'USHORT', value: 3}, // We encode only for PlatformID = 3 (Windows) because it is supported everywhere\n {name: 'cmap12EncodingID', type: 'USHORT', value: 10},\n {name: 'cmap12Offset', type: 'ULONG', value: 0}\n ]);\n\n cmapTable = cmapTable.concat([\n // CMAP 4 Subtable\n {name: 'format', type: 'USHORT', value: 4},\n {name: 'cmap4Length', type: 'USHORT', value: 0},\n {name: 'language', type: 'USHORT', value: 0},\n {name: 'segCountX2', type: 'USHORT', value: 0},\n {name: 'searchRange', type: 'USHORT', value: 0},\n {name: 'entrySelector', type: 'USHORT', value: 0},\n {name: 'rangeShift', type: 'USHORT', value: 0}\n ]);\n\n const t = new table.Table('cmap', cmapTable);\n\n t.segments = [];\n for (i = 0; i < glyphs.length; i += 1) {\n const glyph = glyphs.get(i);\n for (let j = 0; j < glyph.unicodes.length; j += 1) {\n addSegment(t, glyph.unicodes[j], i);\n }\n\n t.segments = t.segments.sort(function (a, b) {\n return a.start - b.start;\n });\n }\n\n addTerminatorSegment(t);\n\n const segCount = t.segments.length;\n let segCountToRemove = 0;\n\n // CMAP 4\n // Set up parallel segment arrays.\n let endCounts = [];\n let startCounts = [];\n let idDeltas = [];\n let idRangeOffsets = [];\n let glyphIds = [];\n\n // CMAP 12\n let cmap12Groups = [];\n\n // Reminder this loop is not following the specification at 100%\n // The specification -> find suites of characters and make a group\n // Here we're doing one group for each letter\n // Doing as the spec can save 8 times (or more) space\n for (i = 0; i < segCount; i += 1) {\n const segment = t.segments[i];\n\n // CMAP 4\n if (segment.end <= 65535 && segment.start <= 65535) {\n endCounts = endCounts.concat({name: 'end_' + i, type: 'USHORT', value: segment.end});\n startCounts = startCounts.concat({name: 'start_' + i, type: 'USHORT', value: segment.start});\n idDeltas = idDeltas.concat({name: 'idDelta_' + i, type: 'SHORT', value: segment.delta});\n idRangeOffsets = idRangeOffsets.concat({name: 'idRangeOffset_' + i, type: 'USHORT', value: segment.offset});\n if (segment.glyphId !== undefined) {\n glyphIds = glyphIds.concat({name: 'glyph_' + i, type: 'USHORT', value: segment.glyphId});\n }\n } else {\n // Skip Unicode > 65535 (16bit unsigned max) for CMAP 4, will be added in CMAP 12\n segCountToRemove += 1;\n }\n\n // CMAP 12\n // Skip Terminator Segment\n if (!isPlan0Only && segment.glyphIndex !== undefined) {\n cmap12Groups = cmap12Groups.concat({name: 'cmap12Start_' + i, type: 'ULONG', value: segment.start});\n cmap12Groups = cmap12Groups.concat({name: 'cmap12End_' + i, type: 'ULONG', value: segment.end});\n cmap12Groups = cmap12Groups.concat({name: 'cmap12Glyph_' + i, type: 'ULONG', value: segment.glyphIndex});\n }\n }\n\n // CMAP 4 Subtable\n t.segCountX2 = (segCount - segCountToRemove) * 2;\n t.searchRange = Math.pow(2, Math.floor(Math.log((segCount - segCountToRemove)) / Math.log(2))) * 2;\n t.entrySelector = Math.log(t.searchRange / 2) / Math.log(2);\n t.rangeShift = t.segCountX2 - t.searchRange;\n\n t.fields = t.fields.concat(endCounts);\n t.fields.push({name: 'reservedPad', type: 'USHORT', value: 0});\n t.fields = t.fields.concat(startCounts);\n t.fields = t.fields.concat(idDeltas);\n t.fields = t.fields.concat(idRangeOffsets);\n t.fields = t.fields.concat(glyphIds);\n\n t.cmap4Length = 14 + // Subtable header\n endCounts.length * 2 +\n 2 + // reservedPad\n startCounts.length * 2 +\n idDeltas.length * 2 +\n idRangeOffsets.length * 2 +\n glyphIds.length * 2;\n\n if (!isPlan0Only) {\n // CMAP 12 Subtable\n const cmap12Length = 16 + // Subtable header\n cmap12Groups.length * 4;\n\n t.cmap12Offset = 12 + (2 * 2) + 4 + t.cmap4Length;\n t.fields = t.fields.concat([\n {name: 'cmap12Format', type: 'USHORT', value: 12},\n {name: 'cmap12Reserved', type: 'USHORT', value: 0},\n {name: 'cmap12Length', type: 'ULONG', value: cmap12Length},\n {name: 'cmap12Language', type: 'ULONG', value: 0},\n {name: 'cmap12nGroups', type: 'ULONG', value: cmap12Groups.length / 3}\n ]);\n\n t.fields = t.fields.concat(cmap12Groups);\n }\n\n return t;\n}\n\nexport default { parse: parseCmapTable, make: makeCmapTable };\n","// Glyph encoding\n\nconst cffStandardStrings = [\n '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',\n 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two',\n 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater',\n 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',\n 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',\n 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent', 'sterling',\n 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle', 'quotedblleft', 'guillemotleft',\n 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl', 'periodcentered', 'paragraph',\n 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand',\n 'questiondown', 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', 'ring',\n 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE',\n 'ordmasculine', 'ae', 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',\n 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn',\n 'threequarters', 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',\n 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex',\n 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',\n 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute',\n 'Ydieresis', 'Zcaron', 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla', 'eacute',\n 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute',\n 'ocircumflex', 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis', 'ugrave',\n 'yacute', 'ydieresis', 'zcaron', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior',\n 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', '266 ff', 'onedotenleader',\n 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',\n 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior', 'threequartersemdash', 'periodsuperior',\n 'questionsmall', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',\n 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior', 'tsuperior', 'ff', 'ffi', 'ffl',\n 'parenleftinferior', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall',\n 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall',\n 'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',\n 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall',\n 'centoldstyle', 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',\n 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall',\n 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',\n 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',\n 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',\n 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',\n 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',\n 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',\n 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall',\n 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',\n 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall', '001.000',\n '001.001', '001.002', '001.003', 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'];\n\nconst cffStandardEncoding = [\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n '', '', '', '', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',\n 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two',\n 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater',\n 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',\n 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',\n 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '', '', '', '', '', '', '', '',\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n 'exclamdown', 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle',\n 'quotedblleft', 'guillemotleft', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger',\n 'daggerdbl', 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright',\n 'guillemotright', 'ellipsis', 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex', 'tilde',\n 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla', '', 'hungarumlaut', 'ogonek', 'caron',\n 'emdash', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '', '',\n '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae', '', '', '', 'dotlessi', '', '',\n 'lslash', 'oslash', 'oe', 'germandbls'];\n\nconst cffExpertEncoding = [\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n '', '', '', '', 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle', 'dollarsuperior',\n 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader', 'onedotenleader',\n 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',\n 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',\n 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior', 'questionsmall', '', 'asuperior',\n 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',\n 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior', '', 'ff', 'fi', 'fl', 'ffi', 'ffl',\n 'parenleftinferior', '', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall',\n 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall',\n 'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',\n 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '',\n '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',\n 'exclamdownsmall', 'centoldstyle', 'Lslashsmall', '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',\n 'Brevesmall', 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '', 'figuredash', 'hypheninferior',\n '', '', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',\n 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds', '',\n '', 'zerosuperior', 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',\n 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',\n 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',\n 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',\n 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',\n 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',\n 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall',\n 'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',\n 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall'];\n\nconst standardNames = [\n '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',\n 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',\n 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',\n 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',\n 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',\n 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',\n 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',\n 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis', 'Udieresis', 'aacute', 'agrave',\n 'acircumflex', 'adieresis', 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',\n 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve', 'ocircumflex', 'odieresis',\n 'otilde', 'uacute', 'ugrave', 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section',\n 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute', 'dieresis', 'notequal',\n 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation',\n 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash', 'questiondown',\n 'exclamdown', 'logicalnot', 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft', 'guillemotright',\n 'ellipsis', 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash', 'emdash', 'quotedblleft',\n 'quotedblright', 'quoteleft', 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',\n 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered', 'quotesinglbase',\n 'quotedblbase', 'perthousand', 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',\n 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute', 'Ucircumflex',\n 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',\n 'ogonek', 'caron', 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar', 'Eth', 'eth',\n 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply', 'onesuperior', 'twosuperior', 'threesuperior',\n 'onehalf', 'onequarter', 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla', 'scedilla',\n 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];\n\n/**\n * This is the encoding used for fonts created from scratch.\n * It loops through all glyphs and finds the appropriate unicode value.\n * Since it's linear time, other encodings will be faster.\n * @exports opentype.DefaultEncoding\n * @class\n * @constructor\n * @param {opentype.Font}\n */\nfunction DefaultEncoding(font) {\n this.font = font;\n}\n\nDefaultEncoding.prototype.charToGlyphIndex = function(c) {\n const code = c.codePointAt(0);\n const glyphs = this.font.glyphs;\n if (glyphs) {\n for (let i = 0; i < glyphs.length; i += 1) {\n const glyph = glyphs.get(i);\n for (let j = 0; j < glyph.unicodes.length; j += 1) {\n if (glyph.unicodes[j] === code) {\n return i;\n }\n }\n }\n }\n return null;\n};\n\n/**\n * @exports opentype.CmapEncoding\n * @class\n * @constructor\n * @param {Object} cmap - a object with the cmap encoded data\n */\nfunction CmapEncoding(cmap) {\n this.cmap = cmap;\n}\n\n/**\n * @param {string} c - the character\n * @return {number} The glyph index.\n */\nCmapEncoding.prototype.charToGlyphIndex = function(c) {\n return this.cmap.glyphIndexMap[c.codePointAt(0)] || 0;\n};\n\n/**\n * @exports opentype.CffEncoding\n * @class\n * @constructor\n * @param {string} encoding - The encoding\n * @param {Array} charset - The character set.\n */\nfunction CffEncoding(encoding, charset) {\n this.encoding = encoding;\n this.charset = charset;\n}\n\n/**\n * @param {string} s - The character\n * @return {number} The index.\n */\nCffEncoding.prototype.charToGlyphIndex = function(s) {\n const code = s.codePointAt(0);\n const charName = this.encoding[code];\n return this.charset.indexOf(charName);\n};\n\n/**\n * @exports opentype.GlyphNames\n * @class\n * @constructor\n * @param {Object} post\n */\nfunction GlyphNames(post) {\n switch (post.version) {\n case 1:\n this.names = standardNames.slice();\n break;\n case 2:\n this.names = new Array(post.numberOfGlyphs);\n for (let i = 0; i < post.numberOfGlyphs; i++) {\n if (post.glyphNameIndex[i] < standardNames.length) {\n this.names[i] = standardNames[post.glyphNameIndex[i]];\n } else {\n this.names[i] = post.names[post.glyphNameIndex[i] - standardNames.length];\n }\n }\n\n break;\n case 2.5:\n this.names = new Array(post.numberOfGlyphs);\n for (let i = 0; i < post.numberOfGlyphs; i++) {\n this.names[i] = standardNames[i + post.glyphNameIndex[i]];\n }\n\n break;\n case 3:\n this.names = [];\n break;\n default:\n this.names = [];\n break;\n }\n}\n\n/**\n * Gets the index of a glyph by name.\n * @param {string} name - The glyph name\n * @return {number} The index\n */\nGlyphNames.prototype.nameToGlyphIndex = function(name) {\n return this.names.indexOf(name);\n};\n\n/**\n * @param {number} gid\n * @return {string}\n */\nGlyphNames.prototype.glyphIndexToName = function(gid) {\n return this.names[gid];\n};\n\nfunction addGlyphNamesAll(font) {\n let glyph;\n const glyphIndexMap = font.tables.cmap.glyphIndexMap;\n const charCodes = Object.keys(glyphIndexMap);\n\n for (let i = 0; i < charCodes.length; i += 1) {\n const c = charCodes[i];\n const glyphIndex = glyphIndexMap[c];\n glyph = font.glyphs.get(glyphIndex);\n glyph.addUnicode(parseInt(c));\n }\n\n for (let i = 0; i < font.glyphs.length; i += 1) {\n glyph = font.glyphs.get(i);\n if (font.cffEncoding) {\n if (font.isCIDFont) {\n glyph.name = 'gid' + i;\n } else {\n glyph.name = font.cffEncoding.charset[i];\n }\n } else if (font.glyphNames.names) {\n glyph.name = font.glyphNames.glyphIndexToName(i);\n }\n }\n}\n\nfunction addGlyphNamesToUnicodeMap(font) {\n font._IndexToUnicodeMap = {};\n\n const glyphIndexMap = font.tables.cmap.glyphIndexMap;\n const charCodes = Object.keys(glyphIndexMap);\n\n for (let i = 0; i < charCodes.length; i += 1) {\n const c = charCodes[i];\n let glyphIndex = glyphIndexMap[c];\n if (font._IndexToUnicodeMap[glyphIndex] === undefined) {\n font._IndexToUnicodeMap[glyphIndex] = {\n unicodes: [parseInt(c)]\n };\n } else {\n font._IndexToUnicodeMap[glyphIndex].unicodes.push(parseInt(c));\n }\n }\n}\n\n/**\n * @alias opentype.addGlyphNames\n * @param {opentype.Font}\n * @param {Object}\n */\nfunction addGlyphNames(font, opt) {\n if (opt.lowMemory) {\n addGlyphNamesToUnicodeMap(font);\n } else {\n addGlyphNamesAll(font);\n }\n}\n\nexport {\n cffStandardStrings,\n cffStandardEncoding,\n cffExpertEncoding,\n standardNames,\n DefaultEncoding,\n CmapEncoding,\n CffEncoding,\n GlyphNames,\n addGlyphNames\n};\n","// Drawing utility functions.\n\n// Draw a line on the given context from point `x1,y1` to point `x2,y2`.\nfunction line(ctx, x1, y1, x2, y2) {\n ctx.beginPath();\n ctx.moveTo(x1, y1);\n ctx.lineTo(x2, y2);\n ctx.stroke();\n}\n\nexport default { line };\n","// The Glyph object\n\nimport check from './check';\nimport draw from './draw';\nimport Path from './path';\n// import glyf from './tables/glyf' Can't be imported here, because it's a circular dependency\n\nfunction getPathDefinition(glyph, path) {\n let _path = path || new Path();\n return {\n configurable: true,\n\n get: function() {\n if (typeof _path === 'function') {\n _path = _path();\n }\n\n return _path;\n },\n\n set: function(p) {\n _path = p;\n }\n };\n}\n/**\n * @typedef GlyphOptions\n * @type Object\n * @property {string} [name] - The glyph name\n * @property {number} [unicode]\n * @property {Array} [unicodes]\n * @property {number} [xMin]\n * @property {number} [yMin]\n * @property {number} [xMax]\n * @property {number} [yMax]\n * @property {number} [advanceWidth]\n */\n\n// A Glyph is an individual mark that often corresponds to a character.\n// Some glyphs, such as ligatures, are a combination of many characters.\n// Glyphs are the basic building blocks of a font.\n//\n// The `Glyph` class contains utility methods for drawing the path and its points.\n/**\n * @exports opentype.Glyph\n * @class\n * @param {GlyphOptions}\n * @constructor\n */\nfunction Glyph(options) {\n // By putting all the code on a prototype function (which is only declared once)\n // we reduce the memory requirements for larger fonts by some 2%\n this.bindConstructorValues(options);\n}\n\n/**\n * @param {GlyphOptions}\n */\nGlyph.prototype.bindConstructorValues = function(options) {\n this.index = options.index || 0;\n\n // These three values cannot be deferred for memory optimization:\n this.name = options.name || null;\n this.unicode = options.unicode || undefined;\n this.unicodes = options.unicodes || options.unicode !== undefined ? [options.unicode] : [];\n\n // But by binding these values only when necessary, we reduce can\n // the memory requirements by almost 3% for larger fonts.\n if ('xMin' in options) {\n this.xMin = options.xMin;\n }\n\n if ('yMin' in options) {\n this.yMin = options.yMin;\n }\n\n if ('xMax' in options) {\n this.xMax = options.xMax;\n }\n\n if ('yMax' in options) {\n this.yMax = options.yMax;\n }\n\n if ('advanceWidth' in options) {\n this.advanceWidth = options.advanceWidth;\n }\n\n // The path for a glyph is the most memory intensive, and is bound as a value\n // with a getter/setter to ensure we actually do path parsing only once the\n // path is actually needed by anything.\n Object.defineProperty(this, 'path', getPathDefinition(this, options.path));\n};\n\n/**\n * @param {number}\n */\nGlyph.prototype.addUnicode = function(unicode) {\n if (this.unicodes.length === 0) {\n this.unicode = unicode;\n }\n\n this.unicodes.push(unicode);\n};\n\n/**\n * Calculate the minimum bounding box for this glyph.\n * @return {opentype.BoundingBox}\n */\nGlyph.prototype.getBoundingBox = function() {\n return this.path.getBoundingBox();\n};\n\n/**\n * Convert the glyph to a Path we can draw on a drawing context.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {Object=} options - xScale, yScale to stretch the glyph.\n * @param {opentype.Font} if hinting is to be used, the font\n * @return {opentype.Path}\n */\nGlyph.prototype.getPath = function(x, y, fontSize, options, font) {\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 72;\n let commands;\n let hPoints;\n if (!options) options = { };\n let xScale = options.xScale;\n let yScale = options.yScale;\n\n if (options.hinting && font && font.hinting) {\n // in case of hinting, the hinting engine takes care\n // of scaling the points (not the path) before hinting.\n hPoints = this.path && font.hinting.exec(this, fontSize);\n // in case the hinting engine failed hPoints is undefined\n // and thus reverts to plain rending\n }\n\n if (hPoints) {\n // Call font.hinting.getCommands instead of `glyf.getPath(hPoints).commands` to avoid a circular dependency\n commands = font.hinting.getCommands(hPoints);\n x = Math.round(x);\n y = Math.round(y);\n // TODO in case of hinting xyScaling is not yet supported\n xScale = yScale = 1;\n } else {\n commands = this.path.commands;\n const scale = 1 / (this.path.unitsPerEm || 1000) * fontSize;\n if (xScale === undefined) xScale = scale;\n if (yScale === undefined) yScale = scale;\n }\n\n const p = new Path();\n for (let i = 0; i < commands.length; i += 1) {\n const cmd = commands[i];\n if (cmd.type === 'M') {\n p.moveTo(x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'L') {\n p.lineTo(x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'Q') {\n p.quadraticCurveTo(x + (cmd.x1 * xScale), y + (-cmd.y1 * yScale),\n x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'C') {\n p.curveTo(x + (cmd.x1 * xScale), y + (-cmd.y1 * yScale),\n x + (cmd.x2 * xScale), y + (-cmd.y2 * yScale),\n x + (cmd.x * xScale), y + (-cmd.y * yScale));\n } else if (cmd.type === 'Z') {\n p.closePath();\n }\n }\n\n return p;\n};\n\n/**\n * Split the glyph into contours.\n * This function is here for backwards compatibility, and to\n * provide raw access to the TrueType glyph outlines.\n * @return {Array}\n */\nGlyph.prototype.getContours = function() {\n if (this.points === undefined) {\n return [];\n }\n\n const contours = [];\n let currentContour = [];\n for (let i = 0; i < this.points.length; i += 1) {\n const pt = this.points[i];\n currentContour.push(pt);\n if (pt.lastPointOfContour) {\n contours.push(currentContour);\n currentContour = [];\n }\n }\n\n check.argument(currentContour.length === 0, 'There are still points left in the current contour.');\n return contours;\n};\n\n/**\n * Calculate the xMin/yMin/xMax/yMax/lsb/rsb for a Glyph.\n * @return {Object}\n */\nGlyph.prototype.getMetrics = function() {\n const commands = this.path.commands;\n const xCoords = [];\n const yCoords = [];\n for (let i = 0; i < commands.length; i += 1) {\n const cmd = commands[i];\n if (cmd.type !== 'Z') {\n xCoords.push(cmd.x);\n yCoords.push(cmd.y);\n }\n\n if (cmd.type === 'Q' || cmd.type === 'C') {\n xCoords.push(cmd.x1);\n yCoords.push(cmd.y1);\n }\n\n if (cmd.type === 'C') {\n xCoords.push(cmd.x2);\n yCoords.push(cmd.y2);\n }\n }\n\n const metrics = {\n xMin: Math.min.apply(null, xCoords),\n yMin: Math.min.apply(null, yCoords),\n xMax: Math.max.apply(null, xCoords),\n yMax: Math.max.apply(null, yCoords),\n leftSideBearing: this.leftSideBearing\n };\n\n if (!isFinite(metrics.xMin)) {\n metrics.xMin = 0;\n }\n\n if (!isFinite(metrics.xMax)) {\n metrics.xMax = this.advanceWidth;\n }\n\n if (!isFinite(metrics.yMin)) {\n metrics.yMin = 0;\n }\n\n if (!isFinite(metrics.yMax)) {\n metrics.yMax = 0;\n }\n\n metrics.rightSideBearing = this.advanceWidth - metrics.leftSideBearing - (metrics.xMax - metrics.xMin);\n return metrics;\n};\n\n/**\n * Draw the glyph on the given context.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {Object=} options - xScale, yScale to stretch the glyph.\n */\nGlyph.prototype.draw = function(ctx, x, y, fontSize, options) {\n this.getPath(x, y, fontSize, options).draw(ctx);\n};\n\n/**\n * Draw the points of the glyph.\n * On-curve points will be drawn in blue, off-curve points will be drawn in red.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n */\nGlyph.prototype.drawPoints = function(ctx, x, y, fontSize) {\n function drawCircles(l, x, y, scale) {\n ctx.beginPath();\n for (let j = 0; j < l.length; j += 1) {\n ctx.moveTo(x + (l[j].x * scale), y + (l[j].y * scale));\n ctx.arc(x + (l[j].x * scale), y + (l[j].y * scale), 2, 0, Math.PI * 2, false);\n }\n\n ctx.closePath();\n ctx.fill();\n }\n\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 24;\n const scale = 1 / this.path.unitsPerEm * fontSize;\n\n const blueCircles = [];\n const redCircles = [];\n const path = this.path;\n for (let i = 0; i < path.commands.length; i += 1) {\n const cmd = path.commands[i];\n if (cmd.x !== undefined) {\n blueCircles.push({x: cmd.x, y: -cmd.y});\n }\n\n if (cmd.x1 !== undefined) {\n redCircles.push({x: cmd.x1, y: -cmd.y1});\n }\n\n if (cmd.x2 !== undefined) {\n redCircles.push({x: cmd.x2, y: -cmd.y2});\n }\n }\n\n ctx.fillStyle = 'blue';\n drawCircles(blueCircles, x, y, scale);\n ctx.fillStyle = 'red';\n drawCircles(redCircles, x, y, scale);\n};\n\n/**\n * Draw lines indicating important font measurements.\n * Black lines indicate the origin of the coordinate system (point 0,0).\n * Blue lines indicate the glyph bounding box.\n * Green line indicates the advance width of the glyph.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n */\nGlyph.prototype.drawMetrics = function(ctx, x, y, fontSize) {\n let scale;\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 24;\n scale = 1 / this.path.unitsPerEm * fontSize;\n ctx.lineWidth = 1;\n\n // Draw the origin\n ctx.strokeStyle = 'black';\n draw.line(ctx, x, -10000, x, 10000);\n draw.line(ctx, -10000, y, 10000, y);\n\n // This code is here due to memory optimization: by not using\n // defaults in the constructor, we save a notable amount of memory.\n const xMin = this.xMin || 0;\n let yMin = this.yMin || 0;\n const xMax = this.xMax || 0;\n let yMax = this.yMax || 0;\n const advanceWidth = this.advanceWidth || 0;\n\n // Draw the glyph box\n ctx.strokeStyle = 'blue';\n draw.line(ctx, x + (xMin * scale), -10000, x + (xMin * scale), 10000);\n draw.line(ctx, x + (xMax * scale), -10000, x + (xMax * scale), 10000);\n draw.line(ctx, -10000, y + (-yMin * scale), 10000, y + (-yMin * scale));\n draw.line(ctx, -10000, y + (-yMax * scale), 10000, y + (-yMax * scale));\n\n // Draw the advance width\n ctx.strokeStyle = 'green';\n draw.line(ctx, x + (advanceWidth * scale), -10000, x + (advanceWidth * scale), 10000);\n};\n\nexport default Glyph;\n","// The GlyphSet object\n\nimport Glyph from './glyph';\n\n// Define a property on the glyph that depends on the path being loaded.\nfunction defineDependentProperty(glyph, externalName, internalName) {\n Object.defineProperty(glyph, externalName, {\n get: function() {\n // Request the path property to make sure the path is loaded.\n glyph.path; // jshint ignore:line\n return glyph[internalName];\n },\n set: function(newValue) {\n glyph[internalName] = newValue;\n },\n enumerable: true,\n configurable: true\n });\n}\n\n/**\n * A GlyphSet represents all glyphs available in the font, but modelled using\n * a deferred glyph loader, for retrieving glyphs only once they are absolutely\n * necessary, to keep the memory footprint down.\n * @exports opentype.GlyphSet\n * @class\n * @param {opentype.Font}\n * @param {Array}\n */\nfunction GlyphSet(font, glyphs) {\n this.font = font;\n this.glyphs = {};\n if (Array.isArray(glyphs)) {\n for (let i = 0; i < glyphs.length; i++) {\n const glyph = glyphs[i];\n glyph.path.unitsPerEm = font.unitsPerEm;\n this.glyphs[i] = glyph;\n }\n }\n\n this.length = (glyphs && glyphs.length) || 0;\n}\n\n/**\n * @param {number} index\n * @return {opentype.Glyph}\n */\nGlyphSet.prototype.get = function(index) {\n // this.glyphs[index] is 'undefined' when low memory mode is on. glyph is pushed on request only.\n if (this.glyphs[index] === undefined) {\n this.font._push(index);\n if (typeof this.glyphs[index] === 'function') {\n this.glyphs[index] = this.glyphs[index]();\n }\n\n let glyph = this.glyphs[index];\n let unicodeObj = this.font._IndexToUnicodeMap[index];\n\n if (unicodeObj) {\n for (let j = 0; j < unicodeObj.unicodes.length; j++)\n glyph.addUnicode(unicodeObj.unicodes[j]);\n }\n\n if (this.font.cffEncoding) {\n if (this.font.isCIDFont) {\n glyph.name = 'gid' + index;\n } else {\n glyph.name = this.font.cffEncoding.charset[index];\n }\n } else if (this.font.glyphNames.names) {\n glyph.name = this.font.glyphNames.glyphIndexToName(index);\n }\n\n this.glyphs[index].advanceWidth = this.font._hmtxTableData[index].advanceWidth;\n this.glyphs[index].leftSideBearing = this.font._hmtxTableData[index].leftSideBearing;\n } else {\n if (typeof this.glyphs[index] === 'function') {\n this.glyphs[index] = this.glyphs[index]();\n }\n }\n\n return this.glyphs[index];\n};\n\n/**\n * @param {number} index\n * @param {Object}\n */\nGlyphSet.prototype.push = function(index, loader) {\n this.glyphs[index] = loader;\n this.length++;\n};\n\n/**\n * @alias opentype.glyphLoader\n * @param {opentype.Font} font\n * @param {number} index\n * @return {opentype.Glyph}\n */\nfunction glyphLoader(font, index) {\n return new Glyph({index: index, font: font});\n}\n\n/**\n * Generate a stub glyph that can be filled with all metadata *except*\n * the \"points\" and \"path\" properties, which must be loaded only once\n * the glyph's path is actually requested for text shaping.\n * @alias opentype.ttfGlyphLoader\n * @param {opentype.Font} font\n * @param {number} index\n * @param {Function} parseGlyph\n * @param {Object} data\n * @param {number} position\n * @param {Function} buildPath\n * @return {opentype.Glyph}\n */\nfunction ttfGlyphLoader(font, index, parseGlyph, data, position, buildPath) {\n return function() {\n const glyph = new Glyph({index: index, font: font});\n\n glyph.path = function() {\n parseGlyph(glyph, data, position);\n const path = buildPath(font.glyphs, glyph);\n path.unitsPerEm = font.unitsPerEm;\n return path;\n };\n\n defineDependentProperty(glyph, 'xMin', '_xMin');\n defineDependentProperty(glyph, 'xMax', '_xMax');\n defineDependentProperty(glyph, 'yMin', '_yMin');\n defineDependentProperty(glyph, 'yMax', '_yMax');\n\n return glyph;\n };\n}\n/**\n * @alias opentype.cffGlyphLoader\n * @param {opentype.Font} font\n * @param {number} index\n * @param {Function} parseCFFCharstring\n * @param {string} charstring\n * @return {opentype.Glyph}\n */\nfunction cffGlyphLoader(font, index, parseCFFCharstring, charstring) {\n return function() {\n const glyph = new Glyph({index: index, font: font});\n\n glyph.path = function() {\n const path = parseCFFCharstring(font, glyph, charstring);\n path.unitsPerEm = font.unitsPerEm;\n return path;\n };\n\n return glyph;\n };\n}\n\nexport default { GlyphSet, glyphLoader, ttfGlyphLoader, cffGlyphLoader };\n","// The `CFF` table contains the glyph outlines in PostScript format.\n// https://www.microsoft.com/typography/OTSPEC/cff.htm\n// http://download.microsoft.com/download/8/0/1/801a191c-029d-4af3-9642-555f6fe514ee/cff.pdf\n// http://download.microsoft.com/download/8/0/1/801a191c-029d-4af3-9642-555f6fe514ee/type2.pdf\n\nimport { CffEncoding, cffStandardEncoding, cffExpertEncoding, cffStandardStrings } from '../encoding';\nimport glyphset from '../glyphset';\nimport parse from '../parse';\nimport Path from '../path';\nimport table from '../table';\n\n// Custom equals function that can also check lists.\nfunction equals(a, b) {\n if (a === b) {\n return true;\n } else if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) {\n return false;\n }\n\n for (let i = 0; i < a.length; i += 1) {\n if (!equals(a[i], b[i])) {\n return false;\n }\n }\n\n return true;\n } else {\n return false;\n }\n}\n\n// Subroutines are encoded using the negative half of the number space.\n// See type 2 chapter 4.7 \"Subroutine operators\".\nfunction calcCFFSubroutineBias(subrs) {\n let bias;\n if (subrs.length < 1240) {\n bias = 107;\n } else if (subrs.length < 33900) {\n bias = 1131;\n } else {\n bias = 32768;\n }\n\n return bias;\n}\n\n// Parse a `CFF` INDEX array.\n// An index array consists of a list of offsets, then a list of objects at those offsets.\nfunction parseCFFIndex(data, start, conversionFn) {\n const offsets = [];\n const objects = [];\n const count = parse.getCard16(data, start);\n let objectOffset;\n let endOffset;\n if (count !== 0) {\n const offsetSize = parse.getByte(data, start + 2);\n objectOffset = start + ((count + 1) * offsetSize) + 2;\n let pos = start + 3;\n for (let i = 0; i < count + 1; i += 1) {\n offsets.push(parse.getOffset(data, pos, offsetSize));\n pos += offsetSize;\n }\n\n // The total size of the index array is 4 header bytes + the value of the last offset.\n endOffset = objectOffset + offsets[count];\n } else {\n endOffset = start + 2;\n }\n\n for (let i = 0; i < offsets.length - 1; i += 1) {\n let value = parse.getBytes(data, objectOffset + offsets[i], objectOffset + offsets[i + 1]);\n if (conversionFn) {\n value = conversionFn(value);\n }\n\n objects.push(value);\n }\n\n return {objects: objects, startOffset: start, endOffset: endOffset};\n}\n\nfunction parseCFFIndexLowMemory(data, start) {\n const offsets = [];\n const count = parse.getCard16(data, start);\n let objectOffset;\n let endOffset;\n if (count !== 0) {\n const offsetSize = parse.getByte(data, start + 2);\n objectOffset = start + ((count + 1) * offsetSize) + 2;\n let pos = start + 3;\n for (let i = 0; i < count + 1; i += 1) {\n offsets.push(parse.getOffset(data, pos, offsetSize));\n pos += offsetSize;\n }\n\n // The total size of the index array is 4 header bytes + the value of the last offset.\n endOffset = objectOffset + offsets[count];\n } else {\n endOffset = start + 2;\n }\n\n return {offsets: offsets, startOffset: start, endOffset: endOffset};\n}\nfunction getCffIndexObject(i, offsets, data, start, conversionFn) {\n const count = parse.getCard16(data, start);\n let objectOffset = 0;\n if (count !== 0) {\n const offsetSize = parse.getByte(data, start + 2);\n objectOffset = start + ((count + 1) * offsetSize) + 2;\n }\n\n let value = parse.getBytes(data, objectOffset + offsets[i], objectOffset + offsets[i + 1]);\n if (conversionFn) {\n value = conversionFn(value);\n }\n return value;\n}\n\n// Parse a `CFF` DICT real value.\nfunction parseFloatOperand(parser) {\n let s = '';\n const eof = 15;\n const lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'E', 'E-', null, '-'];\n while (true) {\n const b = parser.parseByte();\n const n1 = b >> 4;\n const n2 = b & 15;\n\n if (n1 === eof) {\n break;\n }\n\n s += lookup[n1];\n\n if (n2 === eof) {\n break;\n }\n\n s += lookup[n2];\n }\n\n return parseFloat(s);\n}\n\n// Parse a `CFF` DICT operand.\nfunction parseOperand(parser, b0) {\n let b1;\n let b2;\n let b3;\n let b4;\n if (b0 === 28) {\n b1 = parser.parseByte();\n b2 = parser.parseByte();\n return b1 << 8 | b2;\n }\n\n if (b0 === 29) {\n b1 = parser.parseByte();\n b2 = parser.parseByte();\n b3 = parser.parseByte();\n b4 = parser.parseByte();\n return b1 << 24 | b2 << 16 | b3 << 8 | b4;\n }\n\n if (b0 === 30) {\n return parseFloatOperand(parser);\n }\n\n if (b0 >= 32 && b0 <= 246) {\n return b0 - 139;\n }\n\n if (b0 >= 247 && b0 <= 250) {\n b1 = parser.parseByte();\n return (b0 - 247) * 256 + b1 + 108;\n }\n\n if (b0 >= 251 && b0 <= 254) {\n b1 = parser.parseByte();\n return -(b0 - 251) * 256 - b1 - 108;\n }\n\n throw new Error('Invalid b0 ' + b0);\n}\n\n// Convert the entries returned by `parseDict` to a proper dictionary.\n// If a value is a list of one, it is unpacked.\nfunction entriesToObject(entries) {\n const o = {};\n for (let i = 0; i < entries.length; i += 1) {\n const key = entries[i][0];\n const values = entries[i][1];\n let value;\n if (values.length === 1) {\n value = values[0];\n } else {\n value = values;\n }\n\n if (o.hasOwnProperty(key) && !isNaN(o[key])) {\n throw new Error('Object ' + o + ' already has key ' + key);\n }\n\n o[key] = value;\n }\n\n return o;\n}\n\n// Parse a `CFF` DICT object.\n// A dictionary contains key-value pairs in a compact tokenized format.\nfunction parseCFFDict(data, start, size) {\n start = start !== undefined ? start : 0;\n const parser = new parse.Parser(data, start);\n const entries = [];\n let operands = [];\n size = size !== undefined ? size : data.length;\n\n while (parser.relativeOffset < size) {\n let op = parser.parseByte();\n\n // The first byte for each dict item distinguishes between operator (key) and operand (value).\n // Values <= 21 are operators.\n if (op <= 21) {\n // Two-byte operators have an initial escape byte of 12.\n if (op === 12) {\n op = 1200 + parser.parseByte();\n }\n\n entries.push([op, operands]);\n operands = [];\n } else {\n // Since the operands (values) come before the operators (keys), we store all operands in a list\n // until we encounter an operator.\n operands.push(parseOperand(parser, op));\n }\n }\n\n return entriesToObject(entries);\n}\n\n// Given a String Index (SID), return the value of the string.\n// Strings below index 392 are standard CFF strings and are not encoded in the font.\nfunction getCFFString(strings, index) {\n if (index <= 390) {\n index = cffStandardStrings[index];\n } else {\n index = strings[index - 391];\n }\n\n return index;\n}\n\n// Interpret a dictionary and return a new dictionary with readable keys and values for missing entries.\n// This function takes `meta` which is a list of objects containing `operand`, `name` and `default`.\nfunction interpretDict(dict, meta, strings) {\n const newDict = {};\n let value;\n\n // Because we also want to include missing values, we start out from the meta list\n // and lookup values in the dict.\n for (let i = 0; i < meta.length; i += 1) {\n const m = meta[i];\n\n if (Array.isArray(m.type)) {\n const values = [];\n values.length = m.type.length;\n for (let j = 0; j < m.type.length; j++) {\n value = dict[m.op] !== undefined ? dict[m.op][j] : undefined;\n if (value === undefined) {\n value = m.value !== undefined && m.value[j] !== undefined ? m.value[j] : null;\n }\n if (m.type[j] === 'SID') {\n value = getCFFString(strings, value);\n }\n values[j] = value;\n }\n newDict[m.name] = values;\n } else {\n value = dict[m.op];\n if (value === undefined) {\n value = m.value !== undefined ? m.value : null;\n }\n\n if (m.type === 'SID') {\n value = getCFFString(strings, value);\n }\n newDict[m.name] = value;\n }\n }\n\n return newDict;\n}\n\n// Parse the CFF header.\nfunction parseCFFHeader(data, start) {\n const header = {};\n header.formatMajor = parse.getCard8(data, start);\n header.formatMinor = parse.getCard8(data, start + 1);\n header.size = parse.getCard8(data, start + 2);\n header.offsetSize = parse.getCard8(data, start + 3);\n header.startOffset = start;\n header.endOffset = start + 4;\n return header;\n}\n\nconst TOP_DICT_META = [\n {name: 'version', op: 0, type: 'SID'},\n {name: 'notice', op: 1, type: 'SID'},\n {name: 'copyright', op: 1200, type: 'SID'},\n {name: 'fullName', op: 2, type: 'SID'},\n {name: 'familyName', op: 3, type: 'SID'},\n {name: 'weight', op: 4, type: 'SID'},\n {name: 'isFixedPitch', op: 1201, type: 'number', value: 0},\n {name: 'italicAngle', op: 1202, type: 'number', value: 0},\n {name: 'underlinePosition', op: 1203, type: 'number', value: -100},\n {name: 'underlineThickness', op: 1204, type: 'number', value: 50},\n {name: 'paintType', op: 1205, type: 'number', value: 0},\n {name: 'charstringType', op: 1206, type: 'number', value: 2},\n {\n name: 'fontMatrix',\n op: 1207,\n type: ['real', 'real', 'real', 'real', 'real', 'real'],\n value: [0.001, 0, 0, 0.001, 0, 0]\n },\n {name: 'uniqueId', op: 13, type: 'number'},\n {name: 'fontBBox', op: 5, type: ['number', 'number', 'number', 'number'], value: [0, 0, 0, 0]},\n {name: 'strokeWidth', op: 1208, type: 'number', value: 0},\n {name: 'xuid', op: 14, type: [], value: null},\n {name: 'charset', op: 15, type: 'offset', value: 0},\n {name: 'encoding', op: 16, type: 'offset', value: 0},\n {name: 'charStrings', op: 17, type: 'offset', value: 0},\n {name: 'private', op: 18, type: ['number', 'offset'], value: [0, 0]},\n {name: 'ros', op: 1230, type: ['SID', 'SID', 'number']},\n {name: 'cidFontVersion', op: 1231, type: 'number', value: 0},\n {name: 'cidFontRevision', op: 1232, type: 'number', value: 0},\n {name: 'cidFontType', op: 1233, type: 'number', value: 0},\n {name: 'cidCount', op: 1234, type: 'number', value: 8720},\n {name: 'uidBase', op: 1235, type: 'number'},\n {name: 'fdArray', op: 1236, type: 'offset'},\n {name: 'fdSelect', op: 1237, type: 'offset'},\n {name: 'fontName', op: 1238, type: 'SID'}\n];\n\nconst PRIVATE_DICT_META = [\n {name: 'subrs', op: 19, type: 'offset', value: 0},\n {name: 'defaultWidthX', op: 20, type: 'number', value: 0},\n {name: 'nominalWidthX', op: 21, type: 'number', value: 0}\n];\n\n// Parse the CFF top dictionary. A CFF table can contain multiple fonts, each with their own top dictionary.\n// The top dictionary contains the essential metadata for the font, together with the private dictionary.\nfunction parseCFFTopDict(data, strings) {\n const dict = parseCFFDict(data, 0, data.byteLength);\n return interpretDict(dict, TOP_DICT_META, strings);\n}\n\n// Parse the CFF private dictionary. We don't fully parse out all the values, only the ones we need.\nfunction parseCFFPrivateDict(data, start, size, strings) {\n const dict = parseCFFDict(data, start, size);\n return interpretDict(dict, PRIVATE_DICT_META, strings);\n}\n\n// Returns a list of \"Top DICT\"s found using an INDEX list.\n// Used to read both the usual high-level Top DICTs and also the FDArray\n// discovered inside CID-keyed fonts. When a Top DICT has a reference to\n// a Private DICT that is read and saved into the Top DICT.\n//\n// In addition to the expected/optional values as outlined in TOP_DICT_META\n// the following values might be saved into the Top DICT.\n//\n// _subrs [] array of local CFF subroutines from Private DICT\n// _subrsBias bias value computed from number of subroutines\n// (see calcCFFSubroutineBias() and parseCFFCharstring())\n// _defaultWidthX default widths for CFF characters\n// _nominalWidthX bias added to width embedded within glyph description\n//\n// _privateDict saved copy of parsed Private DICT from Top DICT\nfunction gatherCFFTopDicts(data, start, cffIndex, strings) {\n const topDictArray = [];\n for (let iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) {\n const topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer);\n const topDict = parseCFFTopDict(topDictData, strings);\n topDict._subrs = [];\n topDict._subrsBias = 0;\n topDict._defaultWidthX = 0;\n topDict._nominalWidthX = 0;\n const privateSize = topDict.private[0];\n const privateOffset = topDict.private[1];\n if (privateSize !== 0 && privateOffset !== 0) {\n const privateDict = parseCFFPrivateDict(data, privateOffset + start, privateSize, strings);\n topDict._defaultWidthX = privateDict.defaultWidthX;\n topDict._nominalWidthX = privateDict.nominalWidthX;\n if (privateDict.subrs !== 0) {\n const subrOffset = privateOffset + privateDict.subrs;\n const subrIndex = parseCFFIndex(data, subrOffset + start);\n topDict._subrs = subrIndex.objects;\n topDict._subrsBias = calcCFFSubroutineBias(topDict._subrs);\n }\n topDict._privateDict = privateDict;\n }\n topDictArray.push(topDict);\n }\n return topDictArray;\n}\n\n// Parse the CFF charset table, which contains internal names for all the glyphs.\n// This function will return a list of glyph names.\n// See Adobe TN #5176 chapter 13, \"Charsets\".\nfunction parseCFFCharset(data, start, nGlyphs, strings) {\n let sid;\n let count;\n const parser = new parse.Parser(data, start);\n\n // The .notdef glyph is not included, so subtract 1.\n nGlyphs -= 1;\n const charset = ['.notdef'];\n\n const format = parser.parseCard8();\n if (format === 0) {\n for (let i = 0; i < nGlyphs; i += 1) {\n sid = parser.parseSID();\n charset.push(getCFFString(strings, sid));\n }\n } else if (format === 1) {\n while (charset.length <= nGlyphs) {\n sid = parser.parseSID();\n count = parser.parseCard8();\n for (let i = 0; i <= count; i += 1) {\n charset.push(getCFFString(strings, sid));\n sid += 1;\n }\n }\n } else if (format === 2) {\n while (charset.length <= nGlyphs) {\n sid = parser.parseSID();\n count = parser.parseCard16();\n for (let i = 0; i <= count; i += 1) {\n charset.push(getCFFString(strings, sid));\n sid += 1;\n }\n }\n } else {\n throw new Error('Unknown charset format ' + format);\n }\n\n return charset;\n}\n\n// Parse the CFF encoding data. Only one encoding can be specified per font.\n// See Adobe TN #5176 chapter 12, \"Encodings\".\nfunction parseCFFEncoding(data, start, charset) {\n let code;\n const enc = {};\n const parser = new parse.Parser(data, start);\n const format = parser.parseCard8();\n if (format === 0) {\n const nCodes = parser.parseCard8();\n for (let i = 0; i < nCodes; i += 1) {\n code = parser.parseCard8();\n enc[code] = i;\n }\n } else if (format === 1) {\n const nRanges = parser.parseCard8();\n code = 1;\n for (let i = 0; i < nRanges; i += 1) {\n const first = parser.parseCard8();\n const nLeft = parser.parseCard8();\n for (let j = first; j <= first + nLeft; j += 1) {\n enc[j] = code;\n code += 1;\n }\n }\n } else {\n throw new Error('Unknown encoding format ' + format);\n }\n\n return new CffEncoding(enc, charset);\n}\n\n// Take in charstring code and return a Glyph object.\n// The encoding is described in the Type 2 Charstring Format\n// https://www.microsoft.com/typography/OTSPEC/charstr2.htm\nfunction parseCFFCharstring(font, glyph, code) {\n let c1x;\n let c1y;\n let c2x;\n let c2y;\n const p = new Path();\n const stack = [];\n let nStems = 0;\n let haveWidth = false;\n let open = false;\n let x = 0;\n let y = 0;\n let subrs;\n let subrsBias;\n let defaultWidthX;\n let nominalWidthX;\n if (font.isCIDFont) {\n const fdIndex = font.tables.cff.topDict._fdSelect[glyph.index];\n const fdDict = font.tables.cff.topDict._fdArray[fdIndex];\n subrs = fdDict._subrs;\n subrsBias = fdDict._subrsBias;\n defaultWidthX = fdDict._defaultWidthX;\n nominalWidthX = fdDict._nominalWidthX;\n } else {\n subrs = font.tables.cff.topDict._subrs;\n subrsBias = font.tables.cff.topDict._subrsBias;\n defaultWidthX = font.tables.cff.topDict._defaultWidthX;\n nominalWidthX = font.tables.cff.topDict._nominalWidthX;\n }\n let width = defaultWidthX;\n\n function newContour(x, y) {\n if (open) {\n p.closePath();\n }\n\n p.moveTo(x, y);\n open = true;\n }\n\n function parseStems() {\n let hasWidthArg;\n\n // The number of stem operators on the stack is always even.\n // If the value is uneven, that means a width is specified.\n hasWidthArg = stack.length % 2 !== 0;\n if (hasWidthArg && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n }\n\n nStems += stack.length >> 1;\n stack.length = 0;\n haveWidth = true;\n }\n\n function parse(code) {\n let b1;\n let b2;\n let b3;\n let b4;\n let codeIndex;\n let subrCode;\n let jpx;\n let jpy;\n let c3x;\n let c3y;\n let c4x;\n let c4y;\n\n let i = 0;\n while (i < code.length) {\n let v = code[i];\n i += 1;\n switch (v) {\n case 1: // hstem\n parseStems();\n break;\n case 3: // vstem\n parseStems();\n break;\n case 4: // vmoveto\n if (stack.length > 1 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n y += stack.pop();\n newContour(x, y);\n break;\n case 5: // rlineto\n while (stack.length > 0) {\n x += stack.shift();\n y += stack.shift();\n p.lineTo(x, y);\n }\n\n break;\n case 6: // hlineto\n while (stack.length > 0) {\n x += stack.shift();\n p.lineTo(x, y);\n if (stack.length === 0) {\n break;\n }\n\n y += stack.shift();\n p.lineTo(x, y);\n }\n\n break;\n case 7: // vlineto\n while (stack.length > 0) {\n y += stack.shift();\n p.lineTo(x, y);\n if (stack.length === 0) {\n break;\n }\n\n x += stack.shift();\n p.lineTo(x, y);\n }\n\n break;\n case 8: // rrcurveto\n while (stack.length > 0) {\n c1x = x + stack.shift();\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 10: // callsubr\n codeIndex = stack.pop() + subrsBias;\n subrCode = subrs[codeIndex];\n if (subrCode) {\n parse(subrCode);\n }\n\n break;\n case 11: // return\n return;\n case 12: // flex operators\n v = code[i];\n i += 1;\n switch (v) {\n case 35: // flex\n // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |-\n c1x = x + stack.shift(); // dx1\n c1y = y + stack.shift(); // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y + stack.shift(); // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = jpy + stack.shift(); // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = c3y + stack.shift(); // dy5\n x = c4x + stack.shift(); // dx6\n y = c4y + stack.shift(); // dy6\n stack.shift(); // flex depth\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n case 34: // hflex\n // |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |-\n c1x = x + stack.shift(); // dx1\n c1y = y; // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y; // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = c2y; // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = y; // dy5\n x = c4x + stack.shift(); // dx6\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n case 36: // hflex1\n // |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |-\n c1x = x + stack.shift(); // dx1\n c1y = y + stack.shift(); // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y; // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = c2y; // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = c3y + stack.shift(); // dy5\n x = c4x + stack.shift(); // dx6\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n case 37: // flex1\n // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |-\n c1x = x + stack.shift(); // dx1\n c1y = y + stack.shift(); // dy1\n c2x = c1x + stack.shift(); // dx2\n c2y = c1y + stack.shift(); // dy2\n jpx = c2x + stack.shift(); // dx3\n jpy = c2y + stack.shift(); // dy3\n c3x = jpx + stack.shift(); // dx4\n c3y = jpy + stack.shift(); // dy4\n c4x = c3x + stack.shift(); // dx5\n c4y = c3y + stack.shift(); // dy5\n if (Math.abs(c4x - x) > Math.abs(c4y - y)) {\n x = c4x + stack.shift();\n } else {\n y = c4y + stack.shift();\n }\n\n p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy);\n p.curveTo(c3x, c3y, c4x, c4y, x, y);\n break;\n default:\n console.log('Glyph ' + glyph.index + ': unknown operator ' + 1200 + v);\n stack.length = 0;\n }\n break;\n case 14: // endchar\n if (stack.length > 0 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n if (open) {\n p.closePath();\n open = false;\n }\n\n break;\n case 18: // hstemhm\n parseStems();\n break;\n case 19: // hintmask\n case 20: // cntrmask\n parseStems();\n i += (nStems + 7) >> 3;\n break;\n case 21: // rmoveto\n if (stack.length > 2 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n y += stack.pop();\n x += stack.pop();\n newContour(x, y);\n break;\n case 22: // hmoveto\n if (stack.length > 1 && !haveWidth) {\n width = stack.shift() + nominalWidthX;\n haveWidth = true;\n }\n\n x += stack.pop();\n newContour(x, y);\n break;\n case 23: // vstemhm\n parseStems();\n break;\n case 24: // rcurveline\n while (stack.length > 2) {\n c1x = x + stack.shift();\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n x += stack.shift();\n y += stack.shift();\n p.lineTo(x, y);\n break;\n case 25: // rlinecurve\n while (stack.length > 6) {\n x += stack.shift();\n y += stack.shift();\n p.lineTo(x, y);\n }\n\n c1x = x + stack.shift();\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n break;\n case 26: // vvcurveto\n if (stack.length % 2) {\n x += stack.shift();\n }\n\n while (stack.length > 0) {\n c1x = x;\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x;\n y = c2y + stack.shift();\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 27: // hhcurveto\n if (stack.length % 2) {\n y += stack.shift();\n }\n\n while (stack.length > 0) {\n c1x = x + stack.shift();\n c1y = y;\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y;\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 28: // shortint\n b1 = code[i];\n b2 = code[i + 1];\n stack.push(((b1 << 24) | (b2 << 16)) >> 16);\n i += 2;\n break;\n case 29: // callgsubr\n codeIndex = stack.pop() + font.gsubrsBias;\n subrCode = font.gsubrs[codeIndex];\n if (subrCode) {\n parse(subrCode);\n }\n\n break;\n case 30: // vhcurveto\n while (stack.length > 0) {\n c1x = x;\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n if (stack.length === 0) {\n break;\n }\n\n c1x = x + stack.shift();\n c1y = y;\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n y = c2y + stack.shift();\n x = c2x + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n case 31: // hvcurveto\n while (stack.length > 0) {\n c1x = x + stack.shift();\n c1y = y;\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n y = c2y + stack.shift();\n x = c2x + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n if (stack.length === 0) {\n break;\n }\n\n c1x = x;\n c1y = y + stack.shift();\n c2x = c1x + stack.shift();\n c2y = c1y + stack.shift();\n x = c2x + stack.shift();\n y = c2y + (stack.length === 1 ? stack.shift() : 0);\n p.curveTo(c1x, c1y, c2x, c2y, x, y);\n }\n\n break;\n default:\n if (v < 32) {\n console.log('Glyph ' + glyph.index + ': unknown operator ' + v);\n } else if (v < 247) {\n stack.push(v - 139);\n } else if (v < 251) {\n b1 = code[i];\n i += 1;\n stack.push((v - 247) * 256 + b1 + 108);\n } else if (v < 255) {\n b1 = code[i];\n i += 1;\n stack.push(-(v - 251) * 256 - b1 - 108);\n } else {\n b1 = code[i];\n b2 = code[i + 1];\n b3 = code[i + 2];\n b4 = code[i + 3];\n i += 4;\n stack.push(((b1 << 24) | (b2 << 16) | (b3 << 8) | b4) / 65536);\n }\n }\n }\n }\n\n parse(code);\n\n glyph.advanceWidth = width;\n return p;\n}\n\nfunction parseCFFFDSelect(data, start, nGlyphs, fdArrayCount) {\n const fdSelect = [];\n let fdIndex;\n const parser = new parse.Parser(data, start);\n const format = parser.parseCard8();\n if (format === 0) {\n // Simple list of nGlyphs elements\n for (let iGid = 0; iGid < nGlyphs; iGid++) {\n fdIndex = parser.parseCard8();\n if (fdIndex >= fdArrayCount) {\n throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')');\n }\n fdSelect.push(fdIndex);\n }\n } else if (format === 3) {\n // Ranges\n const nRanges = parser.parseCard16();\n let first = parser.parseCard16();\n if (first !== 0) {\n throw new Error('CFF Table CID Font FDSelect format 3 range has bad initial GID ' + first);\n }\n let next;\n for (let iRange = 0; iRange < nRanges; iRange++) {\n fdIndex = parser.parseCard8();\n next = parser.parseCard16();\n if (fdIndex >= fdArrayCount) {\n throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')');\n }\n if (next > nGlyphs) {\n throw new Error('CFF Table CID Font FDSelect format 3 range has bad GID ' + next);\n }\n for (; first < next; first++) {\n fdSelect.push(fdIndex);\n }\n first = next;\n }\n if (next !== nGlyphs) {\n throw new Error('CFF Table CID Font FDSelect format 3 range has bad final GID ' + next);\n }\n } else {\n throw new Error('CFF Table CID Font FDSelect table has unsupported format ' + format);\n }\n return fdSelect;\n}\n\n// Parse the `CFF` table, which contains the glyph outlines in PostScript format.\nfunction parseCFFTable(data, start, font, opt) {\n font.tables.cff = {};\n const header = parseCFFHeader(data, start);\n const nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString);\n const topDictIndex = parseCFFIndex(data, nameIndex.endOffset);\n const stringIndex = parseCFFIndex(data, topDictIndex.endOffset, parse.bytesToString);\n const globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset);\n font.gsubrs = globalSubrIndex.objects;\n font.gsubrsBias = calcCFFSubroutineBias(font.gsubrs);\n\n const topDictArray = gatherCFFTopDicts(data, start, topDictIndex.objects, stringIndex.objects);\n if (topDictArray.length !== 1) {\n throw new Error('CFF table has too many fonts in \\'FontSet\\' - count of fonts NameIndex.length = ' + topDictArray.length);\n }\n\n const topDict = topDictArray[0];\n font.tables.cff.topDict = topDict;\n\n if (topDict._privateDict) {\n font.defaultWidthX = topDict._privateDict.defaultWidthX;\n font.nominalWidthX = topDict._privateDict.nominalWidthX;\n }\n\n if (topDict.ros[0] !== undefined && topDict.ros[1] !== undefined) {\n font.isCIDFont = true;\n }\n\n if (font.isCIDFont) {\n let fdArrayOffset = topDict.fdArray;\n let fdSelectOffset = topDict.fdSelect;\n if (fdArrayOffset === 0 || fdSelectOffset === 0) {\n throw new Error('Font is marked as a CID font, but FDArray and/or FDSelect information is missing');\n }\n fdArrayOffset += start;\n const fdArrayIndex = parseCFFIndex(data, fdArrayOffset);\n const fdArray = gatherCFFTopDicts(data, start, fdArrayIndex.objects, stringIndex.objects);\n topDict._fdArray = fdArray;\n fdSelectOffset += start;\n topDict._fdSelect = parseCFFFDSelect(data, fdSelectOffset, font.numGlyphs, fdArray.length);\n }\n\n const privateDictOffset = start + topDict.private[1];\n const privateDict = parseCFFPrivateDict(data, privateDictOffset, topDict.private[0], stringIndex.objects);\n font.defaultWidthX = privateDict.defaultWidthX;\n font.nominalWidthX = privateDict.nominalWidthX;\n\n if (privateDict.subrs !== 0) {\n const subrOffset = privateDictOffset + privateDict.subrs;\n const subrIndex = parseCFFIndex(data, subrOffset);\n font.subrs = subrIndex.objects;\n font.subrsBias = calcCFFSubroutineBias(font.subrs);\n } else {\n font.subrs = [];\n font.subrsBias = 0;\n }\n\n // Offsets in the top dict are relative to the beginning of the CFF data, so add the CFF start offset.\n let charStringsIndex;\n if (opt.lowMemory) {\n charStringsIndex = parseCFFIndexLowMemory(data, start + topDict.charStrings);\n font.nGlyphs = charStringsIndex.offsets.length;\n } else {\n charStringsIndex = parseCFFIndex(data, start + topDict.charStrings);\n font.nGlyphs = charStringsIndex.objects.length;\n }\n\n const charset = parseCFFCharset(data, start + topDict.charset, font.nGlyphs, stringIndex.objects);\n if (topDict.encoding === 0) {\n // Standard encoding\n font.cffEncoding = new CffEncoding(cffStandardEncoding, charset);\n } else if (topDict.encoding === 1) {\n // Expert encoding\n font.cffEncoding = new CffEncoding(cffExpertEncoding, charset);\n } else {\n font.cffEncoding = parseCFFEncoding(data, start + topDict.encoding, charset);\n }\n\n // Prefer the CMAP encoding to the CFF encoding.\n font.encoding = font.encoding || font.cffEncoding;\n\n font.glyphs = new glyphset.GlyphSet(font);\n if (opt.lowMemory) {\n font._push = function(i) {\n const charString = getCffIndexObject(i, charStringsIndex.offsets, data, start + topDict.charStrings);\n font.glyphs.push(i, glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString));\n };\n } else {\n for (let i = 0; i < font.nGlyphs; i += 1) {\n const charString = charStringsIndex.objects[i];\n font.glyphs.push(i, glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString));\n }\n }\n}\n\n// Convert a string to a String ID (SID).\n// The list of strings is modified in place.\nfunction encodeString(s, strings) {\n let sid;\n\n // Is the string in the CFF standard strings?\n let i = cffStandardStrings.indexOf(s);\n if (i >= 0) {\n sid = i;\n }\n\n // Is the string already in the string index?\n i = strings.indexOf(s);\n if (i >= 0) {\n sid = i + cffStandardStrings.length;\n } else {\n sid = cffStandardStrings.length + strings.length;\n strings.push(s);\n }\n\n return sid;\n}\n\nfunction makeHeader() {\n return new table.Record('Header', [\n {name: 'major', type: 'Card8', value: 1},\n {name: 'minor', type: 'Card8', value: 0},\n {name: 'hdrSize', type: 'Card8', value: 4},\n {name: 'major', type: 'Card8', value: 1}\n ]);\n}\n\nfunction makeNameIndex(fontNames) {\n const t = new table.Record('Name INDEX', [\n {name: 'names', type: 'INDEX', value: []}\n ]);\n t.names = [];\n for (let i = 0; i < fontNames.length; i += 1) {\n t.names.push({name: 'name_' + i, type: 'NAME', value: fontNames[i]});\n }\n\n return t;\n}\n\n// Given a dictionary's metadata, create a DICT structure.\nfunction makeDict(meta, attrs, strings) {\n const m = {};\n for (let i = 0; i < meta.length; i += 1) {\n const entry = meta[i];\n let value = attrs[entry.name];\n if (value !== undefined && !equals(value, entry.value)) {\n if (entry.type === 'SID') {\n value = encodeString(value, strings);\n }\n\n m[entry.op] = {name: entry.name, type: entry.type, value: value};\n }\n }\n\n return m;\n}\n\n// The Top DICT houses the global font attributes.\nfunction makeTopDict(attrs, strings) {\n const t = new table.Record('Top DICT', [\n {name: 'dict', type: 'DICT', value: {}}\n ]);\n t.dict = makeDict(TOP_DICT_META, attrs, strings);\n return t;\n}\n\nfunction makeTopDictIndex(topDict) {\n const t = new table.Record('Top DICT INDEX', [\n {name: 'topDicts', type: 'INDEX', value: []}\n ]);\n t.topDicts = [{name: 'topDict_0', type: 'TABLE', value: topDict}];\n return t;\n}\n\nfunction makeStringIndex(strings) {\n const t = new table.Record('String INDEX', [\n {name: 'strings', type: 'INDEX', value: []}\n ]);\n t.strings = [];\n for (let i = 0; i < strings.length; i += 1) {\n t.strings.push({name: 'string_' + i, type: 'STRING', value: strings[i]});\n }\n\n return t;\n}\n\nfunction makeGlobalSubrIndex() {\n // Currently we don't use subroutines.\n return new table.Record('Global Subr INDEX', [\n {name: 'subrs', type: 'INDEX', value: []}\n ]);\n}\n\nfunction makeCharsets(glyphNames, strings) {\n const t = new table.Record('Charsets', [\n {name: 'format', type: 'Card8', value: 0}\n ]);\n for (let i = 0; i < glyphNames.length; i += 1) {\n const glyphName = glyphNames[i];\n const glyphSID = encodeString(glyphName, strings);\n t.fields.push({name: 'glyph_' + i, type: 'SID', value: glyphSID});\n }\n\n return t;\n}\n\nfunction glyphToOps(glyph) {\n const ops = [];\n const path = glyph.path;\n ops.push({name: 'width', type: 'NUMBER', value: glyph.advanceWidth});\n let x = 0;\n let y = 0;\n for (let i = 0; i < path.commands.length; i += 1) {\n let dx;\n let dy;\n let cmd = path.commands[i];\n if (cmd.type === 'Q') {\n // CFF only supports bézier curves, so convert the quad to a bézier.\n const _13 = 1 / 3;\n const _23 = 2 / 3;\n\n // We're going to create a new command so we don't change the original path.\n // Since all coordinates are relative, we round() them ASAP to avoid propagating errors.\n cmd = {\n type: 'C',\n x: cmd.x,\n y: cmd.y,\n x1: Math.round(_13 * x + _23 * cmd.x1),\n y1: Math.round(_13 * y + _23 * cmd.y1),\n x2: Math.round(_13 * cmd.x + _23 * cmd.x1),\n y2: Math.round(_13 * cmd.y + _23 * cmd.y1)\n };\n }\n\n if (cmd.type === 'M') {\n dx = Math.round(cmd.x - x);\n dy = Math.round(cmd.y - y);\n ops.push({name: 'dx', type: 'NUMBER', value: dx});\n ops.push({name: 'dy', type: 'NUMBER', value: dy});\n ops.push({name: 'rmoveto', type: 'OP', value: 21});\n x = Math.round(cmd.x);\n y = Math.round(cmd.y);\n } else if (cmd.type === 'L') {\n dx = Math.round(cmd.x - x);\n dy = Math.round(cmd.y - y);\n ops.push({name: 'dx', type: 'NUMBER', value: dx});\n ops.push({name: 'dy', type: 'NUMBER', value: dy});\n ops.push({name: 'rlineto', type: 'OP', value: 5});\n x = Math.round(cmd.x);\n y = Math.round(cmd.y);\n } else if (cmd.type === 'C') {\n const dx1 = Math.round(cmd.x1 - x);\n const dy1 = Math.round(cmd.y1 - y);\n const dx2 = Math.round(cmd.x2 - cmd.x1);\n const dy2 = Math.round(cmd.y2 - cmd.y1);\n dx = Math.round(cmd.x - cmd.x2);\n dy = Math.round(cmd.y - cmd.y2);\n ops.push({name: 'dx1', type: 'NUMBER', value: dx1});\n ops.push({name: 'dy1', type: 'NUMBER', value: dy1});\n ops.push({name: 'dx2', type: 'NUMBER', value: dx2});\n ops.push({name: 'dy2', type: 'NUMBER', value: dy2});\n ops.push({name: 'dx', type: 'NUMBER', value: dx});\n ops.push({name: 'dy', type: 'NUMBER', value: dy});\n ops.push({name: 'rrcurveto', type: 'OP', value: 8});\n x = Math.round(cmd.x);\n y = Math.round(cmd.y);\n }\n\n // Contours are closed automatically.\n }\n\n ops.push({name: 'endchar', type: 'OP', value: 14});\n return ops;\n}\n\nfunction makeCharStringsIndex(glyphs) {\n const t = new table.Record('CharStrings INDEX', [\n {name: 'charStrings', type: 'INDEX', value: []}\n ]);\n\n for (let i = 0; i < glyphs.length; i += 1) {\n const glyph = glyphs.get(i);\n const ops = glyphToOps(glyph);\n t.charStrings.push({name: glyph.name, type: 'CHARSTRING', value: ops});\n }\n\n return t;\n}\n\nfunction makePrivateDict(attrs, strings) {\n const t = new table.Record('Private DICT', [\n {name: 'dict', type: 'DICT', value: {}}\n ]);\n t.dict = makeDict(PRIVATE_DICT_META, attrs, strings);\n return t;\n}\n\nfunction makeCFFTable(glyphs, options) {\n const t = new table.Table('CFF ', [\n {name: 'header', type: 'RECORD'},\n {name: 'nameIndex', type: 'RECORD'},\n {name: 'topDictIndex', type: 'RECORD'},\n {name: 'stringIndex', type: 'RECORD'},\n {name: 'globalSubrIndex', type: 'RECORD'},\n {name: 'charsets', type: 'RECORD'},\n {name: 'charStringsIndex', type: 'RECORD'},\n {name: 'privateDict', type: 'RECORD'}\n ]);\n\n const fontScale = 1 / options.unitsPerEm;\n // We use non-zero values for the offsets so that the DICT encodes them.\n // This is important because the size of the Top DICT plays a role in offset calculation,\n // and the size shouldn't change after we've written correct offsets.\n const attrs = {\n version: options.version,\n fullName: options.fullName,\n familyName: options.familyName,\n weight: options.weightName,\n fontBBox: options.fontBBox || [0, 0, 0, 0],\n fontMatrix: [fontScale, 0, 0, fontScale, 0, 0],\n charset: 999,\n encoding: 0,\n charStrings: 999,\n private: [0, 999]\n };\n\n const privateAttrs = {};\n\n const glyphNames = [];\n let glyph;\n\n // Skip first glyph (.notdef)\n for (let i = 1; i < glyphs.length; i += 1) {\n glyph = glyphs.get(i);\n glyphNames.push(glyph.name);\n }\n\n const strings = [];\n\n t.header = makeHeader();\n t.nameIndex = makeNameIndex([options.postScriptName]);\n let topDict = makeTopDict(attrs, strings);\n t.topDictIndex = makeTopDictIndex(topDict);\n t.globalSubrIndex = makeGlobalSubrIndex();\n t.charsets = makeCharsets(glyphNames, strings);\n t.charStringsIndex = makeCharStringsIndex(glyphs);\n t.privateDict = makePrivateDict(privateAttrs, strings);\n\n // Needs to come at the end, to encode all custom strings used in the font.\n t.stringIndex = makeStringIndex(strings);\n\n const startOffset = t.header.sizeOf() +\n t.nameIndex.sizeOf() +\n t.topDictIndex.sizeOf() +\n t.stringIndex.sizeOf() +\n t.globalSubrIndex.sizeOf();\n attrs.charset = startOffset;\n\n // We use the CFF standard encoding; proper encoding will be handled in cmap.\n attrs.encoding = 0;\n attrs.charStrings = attrs.charset + t.charsets.sizeOf();\n attrs.private[1] = attrs.charStrings + t.charStringsIndex.sizeOf();\n\n // Recreate the Top DICT INDEX with the correct offsets.\n topDict = makeTopDict(attrs, strings);\n t.topDictIndex = makeTopDictIndex(topDict);\n\n return t;\n}\n\nexport default { parse: parseCFFTable, make: makeCFFTable };\n","// The `head` table contains global information about the font.\n// https://www.microsoft.com/typography/OTSPEC/head.htm\n\nimport check from '../check';\nimport parse from '../parse';\nimport table from '../table';\n\n// Parse the header `head` table\nfunction parseHeadTable(data, start) {\n const head = {};\n const p = new parse.Parser(data, start);\n head.version = p.parseVersion();\n head.fontRevision = Math.round(p.parseFixed() * 1000) / 1000;\n head.checkSumAdjustment = p.parseULong();\n head.magicNumber = p.parseULong();\n check.argument(head.magicNumber === 0x5F0F3CF5, 'Font header has wrong magic number.');\n head.flags = p.parseUShort();\n head.unitsPerEm = p.parseUShort();\n head.created = p.parseLongDateTime();\n head.modified = p.parseLongDateTime();\n head.xMin = p.parseShort();\n head.yMin = p.parseShort();\n head.xMax = p.parseShort();\n head.yMax = p.parseShort();\n head.macStyle = p.parseUShort();\n head.lowestRecPPEM = p.parseUShort();\n head.fontDirectionHint = p.parseShort();\n head.indexToLocFormat = p.parseShort();\n head.glyphDataFormat = p.parseShort();\n return head;\n}\n\nfunction makeHeadTable(options) {\n // Apple Mac timestamp epoch is 01/01/1904 not 01/01/1970\n const timestamp = Math.round(new Date().getTime() / 1000) + 2082844800;\n let createdTimestamp = timestamp;\n\n if (options.createdTimestamp) {\n createdTimestamp = options.createdTimestamp + 2082844800;\n }\n\n return new table.Table('head', [\n {name: 'version', type: 'FIXED', value: 0x00010000},\n {name: 'fontRevision', type: 'FIXED', value: 0x00010000},\n {name: 'checkSumAdjustment', type: 'ULONG', value: 0},\n {name: 'magicNumber', type: 'ULONG', value: 0x5F0F3CF5},\n {name: 'flags', type: 'USHORT', value: 0},\n {name: 'unitsPerEm', type: 'USHORT', value: 1000},\n {name: 'created', type: 'LONGDATETIME', value: createdTimestamp},\n {name: 'modified', type: 'LONGDATETIME', value: timestamp},\n {name: 'xMin', type: 'SHORT', value: 0},\n {name: 'yMin', type: 'SHORT', value: 0},\n {name: 'xMax', type: 'SHORT', value: 0},\n {name: 'yMax', type: 'SHORT', value: 0},\n {name: 'macStyle', type: 'USHORT', value: 0},\n {name: 'lowestRecPPEM', type: 'USHORT', value: 0},\n {name: 'fontDirectionHint', type: 'SHORT', value: 2},\n {name: 'indexToLocFormat', type: 'SHORT', value: 0},\n {name: 'glyphDataFormat', type: 'SHORT', value: 0}\n ], options);\n}\n\nexport default { parse: parseHeadTable, make: makeHeadTable };\n","// The `hhea` table contains information for horizontal layout.\n// https://www.microsoft.com/typography/OTSPEC/hhea.htm\n\nimport parse from '../parse';\nimport table from '../table';\n\n// Parse the horizontal header `hhea` table\nfunction parseHheaTable(data, start) {\n const hhea = {};\n const p = new parse.Parser(data, start);\n hhea.version = p.parseVersion();\n hhea.ascender = p.parseShort();\n hhea.descender = p.parseShort();\n hhea.lineGap = p.parseShort();\n hhea.advanceWidthMax = p.parseUShort();\n hhea.minLeftSideBearing = p.parseShort();\n hhea.minRightSideBearing = p.parseShort();\n hhea.xMaxExtent = p.parseShort();\n hhea.caretSlopeRise = p.parseShort();\n hhea.caretSlopeRun = p.parseShort();\n hhea.caretOffset = p.parseShort();\n p.relativeOffset += 8;\n hhea.metricDataFormat = p.parseShort();\n hhea.numberOfHMetrics = p.parseUShort();\n return hhea;\n}\n\nfunction makeHheaTable(options) {\n return new table.Table('hhea', [\n {name: 'version', type: 'FIXED', value: 0x00010000},\n {name: 'ascender', type: 'FWORD', value: 0},\n {name: 'descender', type: 'FWORD', value: 0},\n {name: 'lineGap', type: 'FWORD', value: 0},\n {name: 'advanceWidthMax', type: 'UFWORD', value: 0},\n {name: 'minLeftSideBearing', type: 'FWORD', value: 0},\n {name: 'minRightSideBearing', type: 'FWORD', value: 0},\n {name: 'xMaxExtent', type: 'FWORD', value: 0},\n {name: 'caretSlopeRise', type: 'SHORT', value: 1},\n {name: 'caretSlopeRun', type: 'SHORT', value: 0},\n {name: 'caretOffset', type: 'SHORT', value: 0},\n {name: 'reserved1', type: 'SHORT', value: 0},\n {name: 'reserved2', type: 'SHORT', value: 0},\n {name: 'reserved3', type: 'SHORT', value: 0},\n {name: 'reserved4', type: 'SHORT', value: 0},\n {name: 'metricDataFormat', type: 'SHORT', value: 0},\n {name: 'numberOfHMetrics', type: 'USHORT', value: 0}\n ], options);\n}\n\nexport default { parse: parseHheaTable, make: makeHheaTable };\n","// The `hmtx` table contains the horizontal metrics for all glyphs.\n// https://www.microsoft.com/typography/OTSPEC/hmtx.htm\n\nimport parse from '../parse';\nimport table from '../table';\n\nfunction parseHmtxTableAll(data, start, numMetrics, numGlyphs, glyphs) {\n let advanceWidth;\n let leftSideBearing;\n const p = new parse.Parser(data, start);\n for (let i = 0; i < numGlyphs; i += 1) {\n // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.\n if (i < numMetrics) {\n advanceWidth = p.parseUShort();\n leftSideBearing = p.parseShort();\n }\n\n const glyph = glyphs.get(i);\n glyph.advanceWidth = advanceWidth;\n glyph.leftSideBearing = leftSideBearing;\n }\n}\n\nfunction parseHmtxTableOnLowMemory(font, data, start, numMetrics, numGlyphs) {\n font._hmtxTableData = {};\n\n let advanceWidth;\n let leftSideBearing;\n const p = new parse.Parser(data, start);\n for (let i = 0; i < numGlyphs; i += 1) {\n // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.\n if (i < numMetrics) {\n advanceWidth = p.parseUShort();\n leftSideBearing = p.parseShort();\n }\n\n font._hmtxTableData[i] = {\n advanceWidth: advanceWidth,\n leftSideBearing: leftSideBearing\n };\n }\n}\n\n// Parse the `hmtx` table, which contains the horizontal metrics for all glyphs.\n// This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph.\nfunction parseHmtxTable(font, data, start, numMetrics, numGlyphs, glyphs, opt) {\n if (opt.lowMemory)\n parseHmtxTableOnLowMemory(font, data, start, numMetrics, numGlyphs);\n else\n parseHmtxTableAll(data, start, numMetrics, numGlyphs, glyphs);\n}\n\nfunction makeHmtxTable(glyphs) {\n const t = new table.Table('hmtx', []);\n for (let i = 0; i < glyphs.length; i += 1) {\n const glyph = glyphs.get(i);\n const advanceWidth = glyph.advanceWidth || 0;\n const leftSideBearing = glyph.leftSideBearing || 0;\n t.fields.push({name: 'advanceWidth_' + i, type: 'USHORT', value: advanceWidth});\n t.fields.push({name: 'leftSideBearing_' + i, type: 'SHORT', value: leftSideBearing});\n }\n\n return t;\n}\n\nexport default { parse: parseHmtxTable, make: makeHmtxTable };\n","// The `ltag` table stores IETF BCP-47 language tags. It allows supporting\n// languages for which TrueType does not assign a numeric code.\n// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6ltag.html\n// http://www.w3.org/International/articles/language-tags/\n// http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry\n\nimport check from '../check';\nimport parse from '../parse';\nimport table from '../table';\n\nfunction makeLtagTable(tags) {\n const result = new table.Table('ltag', [\n {name: 'version', type: 'ULONG', value: 1},\n {name: 'flags', type: 'ULONG', value: 0},\n {name: 'numTags', type: 'ULONG', value: tags.length}\n ]);\n\n let stringPool = '';\n const stringPoolOffset = 12 + tags.length * 4;\n for (let i = 0; i < tags.length; ++i) {\n let pos = stringPool.indexOf(tags[i]);\n if (pos < 0) {\n pos = stringPool.length;\n stringPool += tags[i];\n }\n\n result.fields.push({name: 'offset ' + i, type: 'USHORT', value: stringPoolOffset + pos});\n result.fields.push({name: 'length ' + i, type: 'USHORT', value: tags[i].length});\n }\n\n result.fields.push({name: 'stringPool', type: 'CHARARRAY', value: stringPool});\n return result;\n}\n\nfunction parseLtagTable(data, start) {\n const p = new parse.Parser(data, start);\n const tableVersion = p.parseULong();\n check.argument(tableVersion === 1, 'Unsupported ltag table version.');\n // The 'ltag' specification does not define any flags; skip the field.\n p.skip('uLong', 1);\n const numTags = p.parseULong();\n\n const tags = [];\n for (let i = 0; i < numTags; i++) {\n let tag = '';\n const offset = start + p.parseUShort();\n const length = p.parseUShort();\n for (let j = offset; j < offset + length; ++j) {\n tag += String.fromCharCode(data.getInt8(j));\n }\n\n tags.push(tag);\n }\n\n return tags;\n}\n\nexport default { make: makeLtagTable, parse: parseLtagTable };\n","// The `maxp` table establishes the memory requirements for the font.\n// We need it just to get the number of glyphs in the font.\n// https://www.microsoft.com/typography/OTSPEC/maxp.htm\n\nimport parse from '../parse';\nimport table from '../table';\n\n// Parse the maximum profile `maxp` table.\nfunction parseMaxpTable(data, start) {\n const maxp = {};\n const p = new parse.Parser(data, start);\n maxp.version = p.parseVersion();\n maxp.numGlyphs = p.parseUShort();\n if (maxp.version === 1.0) {\n maxp.maxPoints = p.parseUShort();\n maxp.maxContours = p.parseUShort();\n maxp.maxCompositePoints = p.parseUShort();\n maxp.maxCompositeContours = p.parseUShort();\n maxp.maxZones = p.parseUShort();\n maxp.maxTwilightPoints = p.parseUShort();\n maxp.maxStorage = p.parseUShort();\n maxp.maxFunctionDefs = p.parseUShort();\n maxp.maxInstructionDefs = p.parseUShort();\n maxp.maxStackElements = p.parseUShort();\n maxp.maxSizeOfInstructions = p.parseUShort();\n maxp.maxComponentElements = p.parseUShort();\n maxp.maxComponentDepth = p.parseUShort();\n }\n\n return maxp;\n}\n\nfunction makeMaxpTable(numGlyphs) {\n return new table.Table('maxp', [\n {name: 'version', type: 'FIXED', value: 0x00005000},\n {name: 'numGlyphs', type: 'USHORT', value: numGlyphs}\n ]);\n}\n\nexport default { parse: parseMaxpTable, make: makeMaxpTable };\n","// The `name` naming table.\n// https://www.microsoft.com/typography/OTSPEC/name.htm\n\nimport { decode, encode } from '../types';\nimport parse from '../parse';\nimport table from '../table';\n\n// NameIDs for the name table.\nconst nameTableNames = [\n 'copyright', // 0\n 'fontFamily', // 1\n 'fontSubfamily', // 2\n 'uniqueID', // 3\n 'fullName', // 4\n 'version', // 5\n 'postScriptName', // 6\n 'trademark', // 7\n 'manufacturer', // 8\n 'designer', // 9\n 'description', // 10\n 'manufacturerURL', // 11\n 'designerURL', // 12\n 'license', // 13\n 'licenseURL', // 14\n 'reserved', // 15\n 'preferredFamily', // 16\n 'preferredSubfamily', // 17\n 'compatibleFullName', // 18\n 'sampleText', // 19\n 'postScriptFindFontName', // 20\n 'wwsFamily', // 21\n 'wwsSubfamily' // 22\n];\n\nconst macLanguages = {\n 0: 'en',\n 1: 'fr',\n 2: 'de',\n 3: 'it',\n 4: 'nl',\n 5: 'sv',\n 6: 'es',\n 7: 'da',\n 8: 'pt',\n 9: 'no',\n 10: 'he',\n 11: 'ja',\n 12: 'ar',\n 13: 'fi',\n 14: 'el',\n 15: 'is',\n 16: 'mt',\n 17: 'tr',\n 18: 'hr',\n 19: 'zh-Hant',\n 20: 'ur',\n 21: 'hi',\n 22: 'th',\n 23: 'ko',\n 24: 'lt',\n 25: 'pl',\n 26: 'hu',\n 27: 'es',\n 28: 'lv',\n 29: 'se',\n 30: 'fo',\n 31: 'fa',\n 32: 'ru',\n 33: 'zh',\n 34: 'nl-BE',\n 35: 'ga',\n 36: 'sq',\n 37: 'ro',\n 38: 'cz',\n 39: 'sk',\n 40: 'si',\n 41: 'yi',\n 42: 'sr',\n 43: 'mk',\n 44: 'bg',\n 45: 'uk',\n 46: 'be',\n 47: 'uz',\n 48: 'kk',\n 49: 'az-Cyrl',\n 50: 'az-Arab',\n 51: 'hy',\n 52: 'ka',\n 53: 'mo',\n 54: 'ky',\n 55: 'tg',\n 56: 'tk',\n 57: 'mn-CN',\n 58: 'mn',\n 59: 'ps',\n 60: 'ks',\n 61: 'ku',\n 62: 'sd',\n 63: 'bo',\n 64: 'ne',\n 65: 'sa',\n 66: 'mr',\n 67: 'bn',\n 68: 'as',\n 69: 'gu',\n 70: 'pa',\n 71: 'or',\n 72: 'ml',\n 73: 'kn',\n 74: 'ta',\n 75: 'te',\n 76: 'si',\n 77: 'my',\n 78: 'km',\n 79: 'lo',\n 80: 'vi',\n 81: 'id',\n 82: 'tl',\n 83: 'ms',\n 84: 'ms-Arab',\n 85: 'am',\n 86: 'ti',\n 87: 'om',\n 88: 'so',\n 89: 'sw',\n 90: 'rw',\n 91: 'rn',\n 92: 'ny',\n 93: 'mg',\n 94: 'eo',\n 128: 'cy',\n 129: 'eu',\n 130: 'ca',\n 131: 'la',\n 132: 'qu',\n 133: 'gn',\n 134: 'ay',\n 135: 'tt',\n 136: 'ug',\n 137: 'dz',\n 138: 'jv',\n 139: 'su',\n 140: 'gl',\n 141: 'af',\n 142: 'br',\n 143: 'iu',\n 144: 'gd',\n 145: 'gv',\n 146: 'ga',\n 147: 'to',\n 148: 'el-polyton',\n 149: 'kl',\n 150: 'az',\n 151: 'nn'\n};\n\n// MacOS language ID → MacOS script ID\n//\n// Note that the script ID is not sufficient to determine what encoding\n// to use in TrueType files. For some languages, MacOS used a modification\n// of a mainstream script. For example, an Icelandic name would be stored\n// with smRoman in the TrueType naming table, but the actual encoding\n// is a special Icelandic version of the normal Macintosh Roman encoding.\n// As another example, Inuktitut uses an 8-bit encoding for Canadian Aboriginal\n// Syllables but MacOS had run out of available script codes, so this was\n// done as a (pretty radical) \"modification\" of Ethiopic.\n//\n// http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt\nconst macLanguageToScript = {\n 0: 0, // langEnglish → smRoman\n 1: 0, // langFrench → smRoman\n 2: 0, // langGerman → smRoman\n 3: 0, // langItalian → smRoman\n 4: 0, // langDutch → smRoman\n 5: 0, // langSwedish → smRoman\n 6: 0, // langSpanish → smRoman\n 7: 0, // langDanish → smRoman\n 8: 0, // langPortuguese → smRoman\n 9: 0, // langNorwegian → smRoman\n 10: 5, // langHebrew → smHebrew\n 11: 1, // langJapanese → smJapanese\n 12: 4, // langArabic → smArabic\n 13: 0, // langFinnish → smRoman\n 14: 6, // langGreek → smGreek\n 15: 0, // langIcelandic → smRoman (modified)\n 16: 0, // langMaltese → smRoman\n 17: 0, // langTurkish → smRoman (modified)\n 18: 0, // langCroatian → smRoman (modified)\n 19: 2, // langTradChinese → smTradChinese\n 20: 4, // langUrdu → smArabic\n 21: 9, // langHindi → smDevanagari\n 22: 21, // langThai → smThai\n 23: 3, // langKorean → smKorean\n 24: 29, // langLithuanian → smCentralEuroRoman\n 25: 29, // langPolish → smCentralEuroRoman\n 26: 29, // langHungarian → smCentralEuroRoman\n 27: 29, // langEstonian → smCentralEuroRoman\n 28: 29, // langLatvian → smCentralEuroRoman\n 29: 0, // langSami → smRoman\n 30: 0, // langFaroese → smRoman (modified)\n 31: 4, // langFarsi → smArabic (modified)\n 32: 7, // langRussian → smCyrillic\n 33: 25, // langSimpChinese → smSimpChinese\n 34: 0, // langFlemish → smRoman\n 35: 0, // langIrishGaelic → smRoman (modified)\n 36: 0, // langAlbanian → smRoman\n 37: 0, // langRomanian → smRoman (modified)\n 38: 29, // langCzech → smCentralEuroRoman\n 39: 29, // langSlovak → smCentralEuroRoman\n 40: 0, // langSlovenian → smRoman (modified)\n 41: 5, // langYiddish → smHebrew\n 42: 7, // langSerbian → smCyrillic\n 43: 7, // langMacedonian → smCyrillic\n 44: 7, // langBulgarian → smCyrillic\n 45: 7, // langUkrainian → smCyrillic (modified)\n 46: 7, // langByelorussian → smCyrillic\n 47: 7, // langUzbek → smCyrillic\n 48: 7, // langKazakh → smCyrillic\n 49: 7, // langAzerbaijani → smCyrillic\n 50: 4, // langAzerbaijanAr → smArabic\n 51: 24, // langArmenian → smArmenian\n 52: 23, // langGeorgian → smGeorgian\n 53: 7, // langMoldavian → smCyrillic\n 54: 7, // langKirghiz → smCyrillic\n 55: 7, // langTajiki → smCyrillic\n 56: 7, // langTurkmen → smCyrillic\n 57: 27, // langMongolian → smMongolian\n 58: 7, // langMongolianCyr → smCyrillic\n 59: 4, // langPashto → smArabic\n 60: 4, // langKurdish → smArabic\n 61: 4, // langKashmiri → smArabic\n 62: 4, // langSindhi → smArabic\n 63: 26, // langTibetan → smTibetan\n 64: 9, // langNepali → smDevanagari\n 65: 9, // langSanskrit → smDevanagari\n 66: 9, // langMarathi → smDevanagari\n 67: 13, // langBengali → smBengali\n 68: 13, // langAssamese → smBengali\n 69: 11, // langGujarati → smGujarati\n 70: 10, // langPunjabi → smGurmukhi\n 71: 12, // langOriya → smOriya\n 72: 17, // langMalayalam → smMalayalam\n 73: 16, // langKannada → smKannada\n 74: 14, // langTamil → smTamil\n 75: 15, // langTelugu → smTelugu\n 76: 18, // langSinhalese → smSinhalese\n 77: 19, // langBurmese → smBurmese\n 78: 20, // langKhmer → smKhmer\n 79: 22, // langLao → smLao\n 80: 30, // langVietnamese → smVietnamese\n 81: 0, // langIndonesian → smRoman\n 82: 0, // langTagalog → smRoman\n 83: 0, // langMalayRoman → smRoman\n 84: 4, // langMalayArabic → smArabic\n 85: 28, // langAmharic → smEthiopic\n 86: 28, // langTigrinya → smEthiopic\n 87: 28, // langOromo → smEthiopic\n 88: 0, // langSomali → smRoman\n 89: 0, // langSwahili → smRoman\n 90: 0, // langKinyarwanda → smRoman\n 91: 0, // langRundi → smRoman\n 92: 0, // langNyanja → smRoman\n 93: 0, // langMalagasy → smRoman\n 94: 0, // langEsperanto → smRoman\n 128: 0, // langWelsh → smRoman (modified)\n 129: 0, // langBasque → smRoman\n 130: 0, // langCatalan → smRoman\n 131: 0, // langLatin → smRoman\n 132: 0, // langQuechua → smRoman\n 133: 0, // langGuarani → smRoman\n 134: 0, // langAymara → smRoman\n 135: 7, // langTatar → smCyrillic\n 136: 4, // langUighur → smArabic\n 137: 26, // langDzongkha → smTibetan\n 138: 0, // langJavaneseRom → smRoman\n 139: 0, // langSundaneseRom → smRoman\n 140: 0, // langGalician → smRoman\n 141: 0, // langAfrikaans → smRoman\n 142: 0, // langBreton → smRoman (modified)\n 143: 28, // langInuktitut → smEthiopic (modified)\n 144: 0, // langScottishGaelic → smRoman (modified)\n 145: 0, // langManxGaelic → smRoman (modified)\n 146: 0, // langIrishGaelicScript → smRoman (modified)\n 147: 0, // langTongan → smRoman\n 148: 6, // langGreekAncient → smRoman\n 149: 0, // langGreenlandic → smRoman\n 150: 0, // langAzerbaijanRoman → smRoman\n 151: 0 // langNynorsk → smRoman\n};\n\n// While Microsoft indicates a region/country for all its language\n// IDs, we omit the region code if it's equal to the \"most likely\n// region subtag\" according to Unicode CLDR. For scripts, we omit\n// the subtag if it is equal to the Suppress-Script entry in the\n// IANA language subtag registry for IETF BCP 47.\n//\n// For example, Microsoft states that its language code 0x041A is\n// Croatian in Croatia. We transform this to the BCP 47 language code 'hr'\n// and not 'hr-HR' because Croatia is the default country for Croatian,\n// according to Unicode CLDR. As another example, Microsoft states\n// that 0x101A is Croatian (Latin) in Bosnia-Herzegovina. We transform\n// this to 'hr-BA' and not 'hr-Latn-BA' because Latin is the default script\n// for the Croatian language, according to IANA.\n//\n// http://www.unicode.org/cldr/charts/latest/supplemental/likely_subtags.html\n// http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry\nconst windowsLanguages = {\n 0x0436: 'af',\n 0x041C: 'sq',\n 0x0484: 'gsw',\n 0x045E: 'am',\n 0x1401: 'ar-DZ',\n 0x3C01: 'ar-BH',\n 0x0C01: 'ar',\n 0x0801: 'ar-IQ',\n 0x2C01: 'ar-JO',\n 0x3401: 'ar-KW',\n 0x3001: 'ar-LB',\n 0x1001: 'ar-LY',\n 0x1801: 'ary',\n 0x2001: 'ar-OM',\n 0x4001: 'ar-QA',\n 0x0401: 'ar-SA',\n 0x2801: 'ar-SY',\n 0x1C01: 'aeb',\n 0x3801: 'ar-AE',\n 0x2401: 'ar-YE',\n 0x042B: 'hy',\n 0x044D: 'as',\n 0x082C: 'az-Cyrl',\n 0x042C: 'az',\n 0x046D: 'ba',\n 0x042D: 'eu',\n 0x0423: 'be',\n 0x0845: 'bn',\n 0x0445: 'bn-IN',\n 0x201A: 'bs-Cyrl',\n 0x141A: 'bs',\n 0x047E: 'br',\n 0x0402: 'bg',\n 0x0403: 'ca',\n 0x0C04: 'zh-HK',\n 0x1404: 'zh-MO',\n 0x0804: 'zh',\n 0x1004: 'zh-SG',\n 0x0404: 'zh-TW',\n 0x0483: 'co',\n 0x041A: 'hr',\n 0x101A: 'hr-BA',\n 0x0405: 'cs',\n 0x0406: 'da',\n 0x048C: 'prs',\n 0x0465: 'dv',\n 0x0813: 'nl-BE',\n 0x0413: 'nl',\n 0x0C09: 'en-AU',\n 0x2809: 'en-BZ',\n 0x1009: 'en-CA',\n 0x2409: 'en-029',\n 0x4009: 'en-IN',\n 0x1809: 'en-IE',\n 0x2009: 'en-JM',\n 0x4409: 'en-MY',\n 0x1409: 'en-NZ',\n 0x3409: 'en-PH',\n 0x4809: 'en-SG',\n 0x1C09: 'en-ZA',\n 0x2C09: 'en-TT',\n 0x0809: 'en-GB',\n 0x0409: 'en',\n 0x3009: 'en-ZW',\n 0x0425: 'et',\n 0x0438: 'fo',\n 0x0464: 'fil',\n 0x040B: 'fi',\n 0x080C: 'fr-BE',\n 0x0C0C: 'fr-CA',\n 0x040C: 'fr',\n 0x140C: 'fr-LU',\n 0x180C: 'fr-MC',\n 0x100C: 'fr-CH',\n 0x0462: 'fy',\n 0x0456: 'gl',\n 0x0437: 'ka',\n 0x0C07: 'de-AT',\n 0x0407: 'de',\n 0x1407: 'de-LI',\n 0x1007: 'de-LU',\n 0x0807: 'de-CH',\n 0x0408: 'el',\n 0x046F: 'kl',\n 0x0447: 'gu',\n 0x0468: 'ha',\n 0x040D: 'he',\n 0x0439: 'hi',\n 0x040E: 'hu',\n 0x040F: 'is',\n 0x0470: 'ig',\n 0x0421: 'id',\n 0x045D: 'iu',\n 0x085D: 'iu-Latn',\n 0x083C: 'ga',\n 0x0434: 'xh',\n 0x0435: 'zu',\n 0x0410: 'it',\n 0x0810: 'it-CH',\n 0x0411: 'ja',\n 0x044B: 'kn',\n 0x043F: 'kk',\n 0x0453: 'km',\n 0x0486: 'quc',\n 0x0487: 'rw',\n 0x0441: 'sw',\n 0x0457: 'kok',\n 0x0412: 'ko',\n 0x0440: 'ky',\n 0x0454: 'lo',\n 0x0426: 'lv',\n 0x0427: 'lt',\n 0x082E: 'dsb',\n 0x046E: 'lb',\n 0x042F: 'mk',\n 0x083E: 'ms-BN',\n 0x043E: 'ms',\n 0x044C: 'ml',\n 0x043A: 'mt',\n 0x0481: 'mi',\n 0x047A: 'arn',\n 0x044E: 'mr',\n 0x047C: 'moh',\n 0x0450: 'mn',\n 0x0850: 'mn-CN',\n 0x0461: 'ne',\n 0x0414: 'nb',\n 0x0814: 'nn',\n 0x0482: 'oc',\n 0x0448: 'or',\n 0x0463: 'ps',\n 0x0415: 'pl',\n 0x0416: 'pt',\n 0x0816: 'pt-PT',\n 0x0446: 'pa',\n 0x046B: 'qu-BO',\n 0x086B: 'qu-EC',\n 0x0C6B: 'qu',\n 0x0418: 'ro',\n 0x0417: 'rm',\n 0x0419: 'ru',\n 0x243B: 'smn',\n 0x103B: 'smj-NO',\n 0x143B: 'smj',\n 0x0C3B: 'se-FI',\n 0x043B: 'se',\n 0x083B: 'se-SE',\n 0x203B: 'sms',\n 0x183B: 'sma-NO',\n 0x1C3B: 'sms',\n 0x044F: 'sa',\n 0x1C1A: 'sr-Cyrl-BA',\n 0x0C1A: 'sr',\n 0x181A: 'sr-Latn-BA',\n 0x081A: 'sr-Latn',\n 0x046C: 'nso',\n 0x0432: 'tn',\n 0x045B: 'si',\n 0x041B: 'sk',\n 0x0424: 'sl',\n 0x2C0A: 'es-AR',\n 0x400A: 'es-BO',\n 0x340A: 'es-CL',\n 0x240A: 'es-CO',\n 0x140A: 'es-CR',\n 0x1C0A: 'es-DO',\n 0x300A: 'es-EC',\n 0x440A: 'es-SV',\n 0x100A: 'es-GT',\n 0x480A: 'es-HN',\n 0x080A: 'es-MX',\n 0x4C0A: 'es-NI',\n 0x180A: 'es-PA',\n 0x3C0A: 'es-PY',\n 0x280A: 'es-PE',\n 0x500A: 'es-PR',\n\n // Microsoft has defined two different language codes for\n // “Spanish with modern sorting” and “Spanish with traditional\n // sorting”. This makes sense for collation APIs, and it would be\n // possible to express this in BCP 47 language tags via Unicode\n // extensions (eg., es-u-co-trad is Spanish with traditional\n // sorting). However, for storing names in fonts, the distinction\n // does not make sense, so we give “es” in both cases.\n 0x0C0A: 'es',\n 0x040A: 'es',\n\n 0x540A: 'es-US',\n 0x380A: 'es-UY',\n 0x200A: 'es-VE',\n 0x081D: 'sv-FI',\n 0x041D: 'sv',\n 0x045A: 'syr',\n 0x0428: 'tg',\n 0x085F: 'tzm',\n 0x0449: 'ta',\n 0x0444: 'tt',\n 0x044A: 'te',\n 0x041E: 'th',\n 0x0451: 'bo',\n 0x041F: 'tr',\n 0x0442: 'tk',\n 0x0480: 'ug',\n 0x0422: 'uk',\n 0x042E: 'hsb',\n 0x0420: 'ur',\n 0x0843: 'uz-Cyrl',\n 0x0443: 'uz',\n 0x042A: 'vi',\n 0x0452: 'cy',\n 0x0488: 'wo',\n 0x0485: 'sah',\n 0x0478: 'ii',\n 0x046A: 'yo'\n};\n\n// Returns a IETF BCP 47 language code, for example 'zh-Hant'\n// for 'Chinese in the traditional script'.\nfunction getLanguageCode(platformID, languageID, ltag) {\n switch (platformID) {\n case 0: // Unicode\n if (languageID === 0xFFFF) {\n return 'und';\n } else if (ltag) {\n return ltag[languageID];\n }\n\n break;\n\n case 1: // Macintosh\n return macLanguages[languageID];\n\n case 3: // Windows\n return windowsLanguages[languageID];\n }\n\n return undefined;\n}\n\nconst utf16 = 'utf-16';\n\n// MacOS script ID → encoding. This table stores the default case,\n// which can be overridden by macLanguageEncodings.\nconst macScriptEncodings = {\n 0: 'macintosh', // smRoman\n 1: 'x-mac-japanese', // smJapanese\n 2: 'x-mac-chinesetrad', // smTradChinese\n 3: 'x-mac-korean', // smKorean\n 6: 'x-mac-greek', // smGreek\n 7: 'x-mac-cyrillic', // smCyrillic\n 9: 'x-mac-devanagai', // smDevanagari\n 10: 'x-mac-gurmukhi', // smGurmukhi\n 11: 'x-mac-gujarati', // smGujarati\n 12: 'x-mac-oriya', // smOriya\n 13: 'x-mac-bengali', // smBengali\n 14: 'x-mac-tamil', // smTamil\n 15: 'x-mac-telugu', // smTelugu\n 16: 'x-mac-kannada', // smKannada\n 17: 'x-mac-malayalam', // smMalayalam\n 18: 'x-mac-sinhalese', // smSinhalese\n 19: 'x-mac-burmese', // smBurmese\n 20: 'x-mac-khmer', // smKhmer\n 21: 'x-mac-thai', // smThai\n 22: 'x-mac-lao', // smLao\n 23: 'x-mac-georgian', // smGeorgian\n 24: 'x-mac-armenian', // smArmenian\n 25: 'x-mac-chinesesimp', // smSimpChinese\n 26: 'x-mac-tibetan', // smTibetan\n 27: 'x-mac-mongolian', // smMongolian\n 28: 'x-mac-ethiopic', // smEthiopic\n 29: 'x-mac-ce', // smCentralEuroRoman\n 30: 'x-mac-vietnamese', // smVietnamese\n 31: 'x-mac-extarabic' // smExtArabic\n};\n\n// MacOS language ID → encoding. This table stores the exceptional\n// cases, which override macScriptEncodings. For writing MacOS naming\n// tables, we need to emit a MacOS script ID. Therefore, we cannot\n// merge macScriptEncodings into macLanguageEncodings.\n//\n// http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt\nconst macLanguageEncodings = {\n 15: 'x-mac-icelandic', // langIcelandic\n 17: 'x-mac-turkish', // langTurkish\n 18: 'x-mac-croatian', // langCroatian\n 24: 'x-mac-ce', // langLithuanian\n 25: 'x-mac-ce', // langPolish\n 26: 'x-mac-ce', // langHungarian\n 27: 'x-mac-ce', // langEstonian\n 28: 'x-mac-ce', // langLatvian\n 30: 'x-mac-icelandic', // langFaroese\n 37: 'x-mac-romanian', // langRomanian\n 38: 'x-mac-ce', // langCzech\n 39: 'x-mac-ce', // langSlovak\n 40: 'x-mac-ce', // langSlovenian\n 143: 'x-mac-inuit', // langInuktitut\n 146: 'x-mac-gaelic' // langIrishGaelicScript\n};\n\nfunction getEncoding(platformID, encodingID, languageID) {\n switch (platformID) {\n case 0: // Unicode\n return utf16;\n\n case 1: // Apple Macintosh\n return macLanguageEncodings[languageID] || macScriptEncodings[encodingID];\n\n case 3: // Microsoft Windows\n if (encodingID === 1 || encodingID === 10) {\n return utf16;\n }\n\n break;\n }\n\n return undefined;\n}\n\n// Parse the naming `name` table.\n// FIXME: Format 1 additional fields are not supported yet.\n// ltag is the content of the `ltag' table, such as ['en', 'zh-Hans', 'de-CH-1904'].\nfunction parseNameTable(data, start, ltag) {\n const name = {};\n const p = new parse.Parser(data, start);\n const format = p.parseUShort();\n const count = p.parseUShort();\n const stringOffset = p.offset + p.parseUShort();\n for (let i = 0; i < count; i++) {\n const platformID = p.parseUShort();\n const encodingID = p.parseUShort();\n const languageID = p.parseUShort();\n const nameID = p.parseUShort();\n const property = nameTableNames[nameID] || nameID;\n const byteLength = p.parseUShort();\n const offset = p.parseUShort();\n const language = getLanguageCode(platformID, languageID, ltag);\n const encoding = getEncoding(platformID, encodingID, languageID);\n if (encoding !== undefined && language !== undefined) {\n let text;\n if (encoding === utf16) {\n text = decode.UTF16(data, stringOffset + offset, byteLength);\n } else {\n text = decode.MACSTRING(data, stringOffset + offset, byteLength, encoding);\n }\n\n if (text) {\n let translations = name[property];\n if (translations === undefined) {\n translations = name[property] = {};\n }\n\n translations[language] = text;\n }\n }\n }\n\n let langTagCount = 0;\n if (format === 1) {\n // FIXME: Also handle Microsoft's 'name' table 1.\n langTagCount = p.parseUShort();\n }\n\n return name;\n}\n\n// {23: 'foo'} → {'foo': 23}\n// ['bar', 'baz'] → {'bar': 0, 'baz': 1}\nfunction reverseDict(dict) {\n const result = {};\n for (let key in dict) {\n result[dict[key]] = parseInt(key);\n }\n\n return result;\n}\n\nfunction makeNameRecord(platformID, encodingID, languageID, nameID, length, offset) {\n return new table.Record('NameRecord', [\n {name: 'platformID', type: 'USHORT', value: platformID},\n {name: 'encodingID', type: 'USHORT', value: encodingID},\n {name: 'languageID', type: 'USHORT', value: languageID},\n {name: 'nameID', type: 'USHORT', value: nameID},\n {name: 'length', type: 'USHORT', value: length},\n {name: 'offset', type: 'USHORT', value: offset}\n ]);\n}\n\n// Finds the position of needle in haystack, or -1 if not there.\n// Like String.indexOf(), but for arrays.\nfunction findSubArray(needle, haystack) {\n const needleLength = needle.length;\n const limit = haystack.length - needleLength + 1;\n\n loop:\n for (let pos = 0; pos < limit; pos++) {\n for (; pos < limit; pos++) {\n for (let k = 0; k < needleLength; k++) {\n if (haystack[pos + k] !== needle[k]) {\n continue loop;\n }\n }\n\n return pos;\n }\n }\n\n return -1;\n}\n\nfunction addStringToPool(s, pool) {\n let offset = findSubArray(s, pool);\n if (offset < 0) {\n offset = pool.length;\n let i = 0;\n const len = s.length;\n for (; i < len; ++i) {\n pool.push(s[i]);\n }\n\n }\n\n return offset;\n}\n\nfunction makeNameTable(names, ltag) {\n let nameID;\n const nameIDs = [];\n\n const namesWithNumericKeys = {};\n const nameTableIds = reverseDict(nameTableNames);\n for (let key in names) {\n let id = nameTableIds[key];\n if (id === undefined) {\n id = key;\n }\n\n nameID = parseInt(id);\n\n if (isNaN(nameID)) {\n throw new Error('Name table entry \"' + key + '\" does not exist, see nameTableNames for complete list.');\n }\n\n namesWithNumericKeys[nameID] = names[key];\n nameIDs.push(nameID);\n }\n\n const macLanguageIds = reverseDict(macLanguages);\n const windowsLanguageIds = reverseDict(windowsLanguages);\n\n const nameRecords = [];\n const stringPool = [];\n\n for (let i = 0; i < nameIDs.length; i++) {\n nameID = nameIDs[i];\n const translations = namesWithNumericKeys[nameID];\n for (let lang in translations) {\n const text = translations[lang];\n\n // For MacOS, we try to emit the name in the form that was introduced\n // in the initial version of the TrueType spec (in the late 1980s).\n // However, this can fail for various reasons: the requested BCP 47\n // language code might not have an old-style Mac equivalent;\n // we might not have a codec for the needed character encoding;\n // or the name might contain characters that cannot be expressed\n // in the old-style Macintosh encoding. In case of failure, we emit\n // the name in a more modern fashion (Unicode encoding with BCP 47\n // language tags) that is recognized by MacOS 10.5, released in 2009.\n // If fonts were only read by operating systems, we could simply\n // emit all names in the modern form; this would be much easier.\n // However, there are many applications and libraries that read\n // 'name' tables directly, and these will usually only recognize\n // the ancient form (silently skipping the unrecognized names).\n let macPlatform = 1; // Macintosh\n let macLanguage = macLanguageIds[lang];\n let macScript = macLanguageToScript[macLanguage];\n const macEncoding = getEncoding(macPlatform, macScript, macLanguage);\n let macName = encode.MACSTRING(text, macEncoding);\n if (macName === undefined) {\n macPlatform = 0; // Unicode\n macLanguage = ltag.indexOf(lang);\n if (macLanguage < 0) {\n macLanguage = ltag.length;\n ltag.push(lang);\n }\n\n macScript = 4; // Unicode 2.0 and later\n macName = encode.UTF16(text);\n }\n\n const macNameOffset = addStringToPool(macName, stringPool);\n nameRecords.push(makeNameRecord(macPlatform, macScript, macLanguage,\n nameID, macName.length, macNameOffset));\n\n const winLanguage = windowsLanguageIds[lang];\n if (winLanguage !== undefined) {\n const winName = encode.UTF16(text);\n const winNameOffset = addStringToPool(winName, stringPool);\n nameRecords.push(makeNameRecord(3, 1, winLanguage,\n nameID, winName.length, winNameOffset));\n }\n }\n }\n\n nameRecords.sort(function(a, b) {\n return ((a.platformID - b.platformID) ||\n (a.encodingID - b.encodingID) ||\n (a.languageID - b.languageID) ||\n (a.nameID - b.nameID));\n });\n\n const t = new table.Table('name', [\n {name: 'format', type: 'USHORT', value: 0},\n {name: 'count', type: 'USHORT', value: nameRecords.length},\n {name: 'stringOffset', type: 'USHORT', value: 6 + nameRecords.length * 12}\n ]);\n\n for (let r = 0; r < nameRecords.length; r++) {\n t.fields.push({name: 'record_' + r, type: 'RECORD', value: nameRecords[r]});\n }\n\n t.fields.push({name: 'strings', type: 'LITERAL', value: stringPool});\n return t;\n}\n\nexport default { parse: parseNameTable, make: makeNameTable };\n","// The `OS/2` table contains metrics required in OpenType fonts.\n// https://www.microsoft.com/typography/OTSPEC/os2.htm\n\nimport parse from '../parse';\nimport table from '../table';\n\nconst unicodeRanges = [\n {begin: 0x0000, end: 0x007F}, // Basic Latin\n {begin: 0x0080, end: 0x00FF}, // Latin-1 Supplement\n {begin: 0x0100, end: 0x017F}, // Latin Extended-A\n {begin: 0x0180, end: 0x024F}, // Latin Extended-B\n {begin: 0x0250, end: 0x02AF}, // IPA Extensions\n {begin: 0x02B0, end: 0x02FF}, // Spacing Modifier Letters\n {begin: 0x0300, end: 0x036F}, // Combining Diacritical Marks\n {begin: 0x0370, end: 0x03FF}, // Greek and Coptic\n {begin: 0x2C80, end: 0x2CFF}, // Coptic\n {begin: 0x0400, end: 0x04FF}, // Cyrillic\n {begin: 0x0530, end: 0x058F}, // Armenian\n {begin: 0x0590, end: 0x05FF}, // Hebrew\n {begin: 0xA500, end: 0xA63F}, // Vai\n {begin: 0x0600, end: 0x06FF}, // Arabic\n {begin: 0x07C0, end: 0x07FF}, // NKo\n {begin: 0x0900, end: 0x097F}, // Devanagari\n {begin: 0x0980, end: 0x09FF}, // Bengali\n {begin: 0x0A00, end: 0x0A7F}, // Gurmukhi\n {begin: 0x0A80, end: 0x0AFF}, // Gujarati\n {begin: 0x0B00, end: 0x0B7F}, // Oriya\n {begin: 0x0B80, end: 0x0BFF}, // Tamil\n {begin: 0x0C00, end: 0x0C7F}, // Telugu\n {begin: 0x0C80, end: 0x0CFF}, // Kannada\n {begin: 0x0D00, end: 0x0D7F}, // Malayalam\n {begin: 0x0E00, end: 0x0E7F}, // Thai\n {begin: 0x0E80, end: 0x0EFF}, // Lao\n {begin: 0x10A0, end: 0x10FF}, // Georgian\n {begin: 0x1B00, end: 0x1B7F}, // Balinese\n {begin: 0x1100, end: 0x11FF}, // Hangul Jamo\n {begin: 0x1E00, end: 0x1EFF}, // Latin Extended Additional\n {begin: 0x1F00, end: 0x1FFF}, // Greek Extended\n {begin: 0x2000, end: 0x206F}, // General Punctuation\n {begin: 0x2070, end: 0x209F}, // Superscripts And Subscripts\n {begin: 0x20A0, end: 0x20CF}, // Currency Symbol\n {begin: 0x20D0, end: 0x20FF}, // Combining Diacritical Marks For Symbols\n {begin: 0x2100, end: 0x214F}, // Letterlike Symbols\n {begin: 0x2150, end: 0x218F}, // Number Forms\n {begin: 0x2190, end: 0x21FF}, // Arrows\n {begin: 0x2200, end: 0x22FF}, // Mathematical Operators\n {begin: 0x2300, end: 0x23FF}, // Miscellaneous Technical\n {begin: 0x2400, end: 0x243F}, // Control Pictures\n {begin: 0x2440, end: 0x245F}, // Optical Character Recognition\n {begin: 0x2460, end: 0x24FF}, // Enclosed Alphanumerics\n {begin: 0x2500, end: 0x257F}, // Box Drawing\n {begin: 0x2580, end: 0x259F}, // Block Elements\n {begin: 0x25A0, end: 0x25FF}, // Geometric Shapes\n {begin: 0x2600, end: 0x26FF}, // Miscellaneous Symbols\n {begin: 0x2700, end: 0x27BF}, // Dingbats\n {begin: 0x3000, end: 0x303F}, // CJK Symbols And Punctuation\n {begin: 0x3040, end: 0x309F}, // Hiragana\n {begin: 0x30A0, end: 0x30FF}, // Katakana\n {begin: 0x3100, end: 0x312F}, // Bopomofo\n {begin: 0x3130, end: 0x318F}, // Hangul Compatibility Jamo\n {begin: 0xA840, end: 0xA87F}, // Phags-pa\n {begin: 0x3200, end: 0x32FF}, // Enclosed CJK Letters And Months\n {begin: 0x3300, end: 0x33FF}, // CJK Compatibility\n {begin: 0xAC00, end: 0xD7AF}, // Hangul Syllables\n {begin: 0xD800, end: 0xDFFF}, // Non-Plane 0 *\n {begin: 0x10900, end: 0x1091F}, // Phoenicia\n {begin: 0x4E00, end: 0x9FFF}, // CJK Unified Ideographs\n {begin: 0xE000, end: 0xF8FF}, // Private Use Area (plane 0)\n {begin: 0x31C0, end: 0x31EF}, // CJK Strokes\n {begin: 0xFB00, end: 0xFB4F}, // Alphabetic Presentation Forms\n {begin: 0xFB50, end: 0xFDFF}, // Arabic Presentation Forms-A\n {begin: 0xFE20, end: 0xFE2F}, // Combining Half Marks\n {begin: 0xFE10, end: 0xFE1F}, // Vertical Forms\n {begin: 0xFE50, end: 0xFE6F}, // Small Form Variants\n {begin: 0xFE70, end: 0xFEFF}, // Arabic Presentation Forms-B\n {begin: 0xFF00, end: 0xFFEF}, // Halfwidth And Fullwidth Forms\n {begin: 0xFFF0, end: 0xFFFF}, // Specials\n {begin: 0x0F00, end: 0x0FFF}, // Tibetan\n {begin: 0x0700, end: 0x074F}, // Syriac\n {begin: 0x0780, end: 0x07BF}, // Thaana\n {begin: 0x0D80, end: 0x0DFF}, // Sinhala\n {begin: 0x1000, end: 0x109F}, // Myanmar\n {begin: 0x1200, end: 0x137F}, // Ethiopic\n {begin: 0x13A0, end: 0x13FF}, // Cherokee\n {begin: 0x1400, end: 0x167F}, // Unified Canadian Aboriginal Syllabics\n {begin: 0x1680, end: 0x169F}, // Ogham\n {begin: 0x16A0, end: 0x16FF}, // Runic\n {begin: 0x1780, end: 0x17FF}, // Khmer\n {begin: 0x1800, end: 0x18AF}, // Mongolian\n {begin: 0x2800, end: 0x28FF}, // Braille Patterns\n {begin: 0xA000, end: 0xA48F}, // Yi Syllables\n {begin: 0x1700, end: 0x171F}, // Tagalog\n {begin: 0x10300, end: 0x1032F}, // Old Italic\n {begin: 0x10330, end: 0x1034F}, // Gothic\n {begin: 0x10400, end: 0x1044F}, // Deseret\n {begin: 0x1D000, end: 0x1D0FF}, // Byzantine Musical Symbols\n {begin: 0x1D400, end: 0x1D7FF}, // Mathematical Alphanumeric Symbols\n {begin: 0xFF000, end: 0xFFFFD}, // Private Use (plane 15)\n {begin: 0xFE00, end: 0xFE0F}, // Variation Selectors\n {begin: 0xE0000, end: 0xE007F}, // Tags\n {begin: 0x1900, end: 0x194F}, // Limbu\n {begin: 0x1950, end: 0x197F}, // Tai Le\n {begin: 0x1980, end: 0x19DF}, // New Tai Lue\n {begin: 0x1A00, end: 0x1A1F}, // Buginese\n {begin: 0x2C00, end: 0x2C5F}, // Glagolitic\n {begin: 0x2D30, end: 0x2D7F}, // Tifinagh\n {begin: 0x4DC0, end: 0x4DFF}, // Yijing Hexagram Symbols\n {begin: 0xA800, end: 0xA82F}, // Syloti Nagri\n {begin: 0x10000, end: 0x1007F}, // Linear B Syllabary\n {begin: 0x10140, end: 0x1018F}, // Ancient Greek Numbers\n {begin: 0x10380, end: 0x1039F}, // Ugaritic\n {begin: 0x103A0, end: 0x103DF}, // Old Persian\n {begin: 0x10450, end: 0x1047F}, // Shavian\n {begin: 0x10480, end: 0x104AF}, // Osmanya\n {begin: 0x10800, end: 0x1083F}, // Cypriot Syllabary\n {begin: 0x10A00, end: 0x10A5F}, // Kharoshthi\n {begin: 0x1D300, end: 0x1D35F}, // Tai Xuan Jing Symbols\n {begin: 0x12000, end: 0x123FF}, // Cuneiform\n {begin: 0x1D360, end: 0x1D37F}, // Counting Rod Numerals\n {begin: 0x1B80, end: 0x1BBF}, // Sundanese\n {begin: 0x1C00, end: 0x1C4F}, // Lepcha\n {begin: 0x1C50, end: 0x1C7F}, // Ol Chiki\n {begin: 0xA880, end: 0xA8DF}, // Saurashtra\n {begin: 0xA900, end: 0xA92F}, // Kayah Li\n {begin: 0xA930, end: 0xA95F}, // Rejang\n {begin: 0xAA00, end: 0xAA5F}, // Cham\n {begin: 0x10190, end: 0x101CF}, // Ancient Symbols\n {begin: 0x101D0, end: 0x101FF}, // Phaistos Disc\n {begin: 0x102A0, end: 0x102DF}, // Carian\n {begin: 0x1F030, end: 0x1F09F} // Domino Tiles\n];\n\nfunction getUnicodeRange(unicode) {\n for (let i = 0; i < unicodeRanges.length; i += 1) {\n const range = unicodeRanges[i];\n if (unicode >= range.begin && unicode < range.end) {\n return i;\n }\n }\n\n return -1;\n}\n\n// Parse the OS/2 and Windows metrics `OS/2` table\nfunction parseOS2Table(data, start) {\n const os2 = {};\n const p = new parse.Parser(data, start);\n os2.version = p.parseUShort();\n os2.xAvgCharWidth = p.parseShort();\n os2.usWeightClass = p.parseUShort();\n os2.usWidthClass = p.parseUShort();\n os2.fsType = p.parseUShort();\n os2.ySubscriptXSize = p.parseShort();\n os2.ySubscriptYSize = p.parseShort();\n os2.ySubscriptXOffset = p.parseShort();\n os2.ySubscriptYOffset = p.parseShort();\n os2.ySuperscriptXSize = p.parseShort();\n os2.ySuperscriptYSize = p.parseShort();\n os2.ySuperscriptXOffset = p.parseShort();\n os2.ySuperscriptYOffset = p.parseShort();\n os2.yStrikeoutSize = p.parseShort();\n os2.yStrikeoutPosition = p.parseShort();\n os2.sFamilyClass = p.parseShort();\n os2.panose = [];\n for (let i = 0; i < 10; i++) {\n os2.panose[i] = p.parseByte();\n }\n\n os2.ulUnicodeRange1 = p.parseULong();\n os2.ulUnicodeRange2 = p.parseULong();\n os2.ulUnicodeRange3 = p.parseULong();\n os2.ulUnicodeRange4 = p.parseULong();\n os2.achVendID = String.fromCharCode(p.parseByte(), p.parseByte(), p.parseByte(), p.parseByte());\n os2.fsSelection = p.parseUShort();\n os2.usFirstCharIndex = p.parseUShort();\n os2.usLastCharIndex = p.parseUShort();\n os2.sTypoAscender = p.parseShort();\n os2.sTypoDescender = p.parseShort();\n os2.sTypoLineGap = p.parseShort();\n os2.usWinAscent = p.parseUShort();\n os2.usWinDescent = p.parseUShort();\n if (os2.version >= 1) {\n os2.ulCodePageRange1 = p.parseULong();\n os2.ulCodePageRange2 = p.parseULong();\n }\n\n if (os2.version >= 2) {\n os2.sxHeight = p.parseShort();\n os2.sCapHeight = p.parseShort();\n os2.usDefaultChar = p.parseUShort();\n os2.usBreakChar = p.parseUShort();\n os2.usMaxContent = p.parseUShort();\n }\n\n return os2;\n}\n\nfunction makeOS2Table(options) {\n return new table.Table('OS/2', [\n {name: 'version', type: 'USHORT', value: 0x0003},\n {name: 'xAvgCharWidth', type: 'SHORT', value: 0},\n {name: 'usWeightClass', type: 'USHORT', value: 0},\n {name: 'usWidthClass', type: 'USHORT', value: 0},\n {name: 'fsType', type: 'USHORT', value: 0},\n {name: 'ySubscriptXSize', type: 'SHORT', value: 650},\n {name: 'ySubscriptYSize', type: 'SHORT', value: 699},\n {name: 'ySubscriptXOffset', type: 'SHORT', value: 0},\n {name: 'ySubscriptYOffset', type: 'SHORT', value: 140},\n {name: 'ySuperscriptXSize', type: 'SHORT', value: 650},\n {name: 'ySuperscriptYSize', type: 'SHORT', value: 699},\n {name: 'ySuperscriptXOffset', type: 'SHORT', value: 0},\n {name: 'ySuperscriptYOffset', type: 'SHORT', value: 479},\n {name: 'yStrikeoutSize', type: 'SHORT', value: 49},\n {name: 'yStrikeoutPosition', type: 'SHORT', value: 258},\n {name: 'sFamilyClass', type: 'SHORT', value: 0},\n {name: 'bFamilyType', type: 'BYTE', value: 0},\n {name: 'bSerifStyle', type: 'BYTE', value: 0},\n {name: 'bWeight', type: 'BYTE', value: 0},\n {name: 'bProportion', type: 'BYTE', value: 0},\n {name: 'bContrast', type: 'BYTE', value: 0},\n {name: 'bStrokeVariation', type: 'BYTE', value: 0},\n {name: 'bArmStyle', type: 'BYTE', value: 0},\n {name: 'bLetterform', type: 'BYTE', value: 0},\n {name: 'bMidline', type: 'BYTE', value: 0},\n {name: 'bXHeight', type: 'BYTE', value: 0},\n {name: 'ulUnicodeRange1', type: 'ULONG', value: 0},\n {name: 'ulUnicodeRange2', type: 'ULONG', value: 0},\n {name: 'ulUnicodeRange3', type: 'ULONG', value: 0},\n {name: 'ulUnicodeRange4', type: 'ULONG', value: 0},\n {name: 'achVendID', type: 'CHARARRAY', value: 'XXXX'},\n {name: 'fsSelection', type: 'USHORT', value: 0},\n {name: 'usFirstCharIndex', type: 'USHORT', value: 0},\n {name: 'usLastCharIndex', type: 'USHORT', value: 0},\n {name: 'sTypoAscender', type: 'SHORT', value: 0},\n {name: 'sTypoDescender', type: 'SHORT', value: 0},\n {name: 'sTypoLineGap', type: 'SHORT', value: 0},\n {name: 'usWinAscent', type: 'USHORT', value: 0},\n {name: 'usWinDescent', type: 'USHORT', value: 0},\n {name: 'ulCodePageRange1', type: 'ULONG', value: 0},\n {name: 'ulCodePageRange2', type: 'ULONG', value: 0},\n {name: 'sxHeight', type: 'SHORT', value: 0},\n {name: 'sCapHeight', type: 'SHORT', value: 0},\n {name: 'usDefaultChar', type: 'USHORT', value: 0},\n {name: 'usBreakChar', type: 'USHORT', value: 0},\n {name: 'usMaxContext', type: 'USHORT', value: 0}\n ], options);\n}\n\nexport default { parse: parseOS2Table, make: makeOS2Table, unicodeRanges, getUnicodeRange };\n","// The `post` table stores additional PostScript information, such as glyph names.\n// https://www.microsoft.com/typography/OTSPEC/post.htm\n\nimport { standardNames } from '../encoding';\nimport parse from '../parse';\nimport table from '../table';\n\n// Parse the PostScript `post` table\nfunction parsePostTable(data, start) {\n const post = {};\n const p = new parse.Parser(data, start);\n post.version = p.parseVersion();\n post.italicAngle = p.parseFixed();\n post.underlinePosition = p.parseShort();\n post.underlineThickness = p.parseShort();\n post.isFixedPitch = p.parseULong();\n post.minMemType42 = p.parseULong();\n post.maxMemType42 = p.parseULong();\n post.minMemType1 = p.parseULong();\n post.maxMemType1 = p.parseULong();\n switch (post.version) {\n case 1:\n post.names = standardNames.slice();\n break;\n case 2:\n post.numberOfGlyphs = p.parseUShort();\n post.glyphNameIndex = new Array(post.numberOfGlyphs);\n for (let i = 0; i < post.numberOfGlyphs; i++) {\n post.glyphNameIndex[i] = p.parseUShort();\n }\n\n post.names = [];\n for (let i = 0; i < post.numberOfGlyphs; i++) {\n if (post.glyphNameIndex[i] >= standardNames.length) {\n const nameLength = p.parseChar();\n post.names.push(p.parseString(nameLength));\n }\n }\n\n break;\n case 2.5:\n post.numberOfGlyphs = p.parseUShort();\n post.offset = new Array(post.numberOfGlyphs);\n for (let i = 0; i < post.numberOfGlyphs; i++) {\n post.offset[i] = p.parseChar();\n }\n\n break;\n }\n return post;\n}\n\nfunction makePostTable() {\n return new table.Table('post', [\n {name: 'version', type: 'FIXED', value: 0x00030000},\n {name: 'italicAngle', type: 'FIXED', value: 0},\n {name: 'underlinePosition', type: 'FWORD', value: 0},\n {name: 'underlineThickness', type: 'FWORD', value: 0},\n {name: 'isFixedPitch', type: 'ULONG', value: 0},\n {name: 'minMemType42', type: 'ULONG', value: 0},\n {name: 'maxMemType42', type: 'ULONG', value: 0},\n {name: 'minMemType1', type: 'ULONG', value: 0},\n {name: 'maxMemType1', type: 'ULONG', value: 0}\n ]);\n}\n\nexport default { parse: parsePostTable, make: makePostTable };\n","// The `GSUB` table contains ligatures, among other things.\n// https://www.microsoft.com/typography/OTSPEC/gsub.htm\n\nimport check from '../check';\nimport { Parser } from '../parse';\nimport table from '../table';\n\nconst subtableParsers = new Array(9); // subtableParsers[0] is unused\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#SS\nsubtableParsers[1] = function parseLookup1() {\n const start = this.offset + this.relativeOffset;\n const substFormat = this.parseUShort();\n if (substFormat === 1) {\n return {\n substFormat: 1,\n coverage: this.parsePointer(Parser.coverage),\n deltaGlyphId: this.parseUShort()\n };\n } else if (substFormat === 2) {\n return {\n substFormat: 2,\n coverage: this.parsePointer(Parser.coverage),\n substitute: this.parseOffset16List()\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': lookup type 1 format must be 1 or 2.');\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#MS\nsubtableParsers[2] = function parseLookup2() {\n const substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Multiple Substitution Subtable identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n sequences: this.parseListOfLists()\n };\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#AS\nsubtableParsers[3] = function parseLookup3() {\n const substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Alternate Substitution Subtable identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n alternateSets: this.parseListOfLists()\n };\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#LS\nsubtableParsers[4] = function parseLookup4() {\n const substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB ligature table identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n ligatureSets: this.parseListOfLists(function() {\n return {\n ligGlyph: this.parseUShort(),\n components: this.parseUShortList(this.parseUShort() - 1)\n };\n })\n };\n};\n\nconst lookupRecordDesc = {\n sequenceIndex: Parser.uShort,\n lookupListIndex: Parser.uShort\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CSF\nsubtableParsers[5] = function parseLookup5() {\n const start = this.offset + this.relativeOffset;\n const substFormat = this.parseUShort();\n\n if (substFormat === 1) {\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n ruleSets: this.parseListOfLists(function() {\n const glyphCount = this.parseUShort();\n const substCount = this.parseUShort();\n return {\n input: this.parseUShortList(glyphCount - 1),\n lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 2) {\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n classDef: this.parsePointer(Parser.classDef),\n classSets: this.parseListOfLists(function() {\n const glyphCount = this.parseUShort();\n const substCount = this.parseUShort();\n return {\n classes: this.parseUShortList(glyphCount - 1),\n lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 3) {\n const glyphCount = this.parseUShort();\n const substCount = this.parseUShort();\n return {\n substFormat: substFormat,\n coverages: this.parseList(glyphCount, Parser.pointer(Parser.coverage)),\n lookupRecords: this.parseRecordList(substCount, lookupRecordDesc)\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': lookup type 5 format must be 1, 2 or 3.');\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CC\nsubtableParsers[6] = function parseLookup6() {\n const start = this.offset + this.relativeOffset;\n const substFormat = this.parseUShort();\n if (substFormat === 1) {\n return {\n substFormat: 1,\n coverage: this.parsePointer(Parser.coverage),\n chainRuleSets: this.parseListOfLists(function() {\n return {\n backtrack: this.parseUShortList(),\n input: this.parseUShortList(this.parseShort() - 1),\n lookahead: this.parseUShortList(),\n lookupRecords: this.parseRecordList(lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 2) {\n return {\n substFormat: 2,\n coverage: this.parsePointer(Parser.coverage),\n backtrackClassDef: this.parsePointer(Parser.classDef),\n inputClassDef: this.parsePointer(Parser.classDef),\n lookaheadClassDef: this.parsePointer(Parser.classDef),\n chainClassSet: this.parseListOfLists(function() {\n return {\n backtrack: this.parseUShortList(),\n input: this.parseUShortList(this.parseShort() - 1),\n lookahead: this.parseUShortList(),\n lookupRecords: this.parseRecordList(lookupRecordDesc)\n };\n })\n };\n } else if (substFormat === 3) {\n return {\n substFormat: 3,\n backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n inputCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n lookupRecords: this.parseRecordList(lookupRecordDesc)\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': lookup type 6 format must be 1, 2 or 3.');\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#ES\nsubtableParsers[7] = function parseLookup7() {\n // Extension Substitution subtable\n const substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Extension Substitution subtable identifier-format must be 1');\n const extensionLookupType = this.parseUShort();\n const extensionParser = new Parser(this.data, this.offset + this.parseULong());\n return {\n substFormat: 1,\n lookupType: extensionLookupType,\n extension: subtableParsers[extensionLookupType].call(extensionParser)\n };\n};\n\n// https://www.microsoft.com/typography/OTSPEC/GSUB.htm#RCCS\nsubtableParsers[8] = function parseLookup8() {\n const substFormat = this.parseUShort();\n check.argument(substFormat === 1, 'GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1');\n return {\n substFormat: substFormat,\n coverage: this.parsePointer(Parser.coverage),\n backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)),\n substitutes: this.parseUShortList()\n };\n};\n\n// https://www.microsoft.com/typography/OTSPEC/gsub.htm\nfunction parseGsubTable(data, start) {\n start = start || 0;\n const p = new Parser(data, start);\n const tableVersion = p.parseVersion(1);\n check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GSUB table version.');\n if (tableVersion === 1) {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers)\n };\n } else {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers),\n variations: p.parseFeatureVariationsList()\n };\n }\n\n}\n\n// GSUB Writing //////////////////////////////////////////////\nconst subtableMakers = new Array(9);\n\nsubtableMakers[1] = function makeLookup1(subtable) {\n if (subtable.substFormat === 1) {\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)},\n {name: 'deltaGlyphID', type: 'USHORT', value: subtable.deltaGlyphId}\n ]);\n } else {\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 2},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.ushortList('substitute', subtable.substitute)));\n }\n check.fail('Lookup type 1 substFormat must be 1 or 2.');\n};\n\nsubtableMakers[2] = function makeLookup2(subtable) {\n check.assert(subtable.substFormat === 1, 'Lookup type 2 substFormat must be 1.');\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('seqSet', subtable.sequences, function(sequenceSet) {\n return new table.Table('sequenceSetTable', table.ushortList('sequence', sequenceSet));\n })));\n};\n\nsubtableMakers[3] = function makeLookup3(subtable) {\n check.assert(subtable.substFormat === 1, 'Lookup type 3 substFormat must be 1.');\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('altSet', subtable.alternateSets, function(alternateSet) {\n return new table.Table('alternateSetTable', table.ushortList('alternate', alternateSet));\n })));\n};\n\nsubtableMakers[4] = function makeLookup4(subtable) {\n check.assert(subtable.substFormat === 1, 'Lookup type 4 substFormat must be 1.');\n return new table.Table('substitutionTable', [\n {name: 'substFormat', type: 'USHORT', value: 1},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('ligSet', subtable.ligatureSets, function(ligatureSet) {\n return new table.Table('ligatureSetTable', table.tableList('ligature', ligatureSet, function(ligature) {\n return new table.Table('ligatureTable',\n [{name: 'ligGlyph', type: 'USHORT', value: ligature.ligGlyph}]\n .concat(table.ushortList('component', ligature.components, ligature.components.length + 1))\n );\n }));\n })));\n};\n\nsubtableMakers[6] = function makeLookup6(subtable) {\n if (subtable.substFormat === 1) {\n let returnTable = new table.Table('chainContextTable', [\n {name: 'substFormat', type: 'USHORT', value: subtable.substFormat},\n {name: 'coverage', type: 'TABLE', value: new table.Coverage(subtable.coverage)}\n ].concat(table.tableList('chainRuleSet', subtable.chainRuleSets, function(chainRuleSet) {\n return new table.Table('chainRuleSetTable', table.tableList('chainRule', chainRuleSet, function(chainRule) {\n let tableData = table.ushortList('backtrackGlyph', chainRule.backtrack, chainRule.backtrack.length)\n .concat(table.ushortList('inputGlyph', chainRule.input, chainRule.input.length + 1))\n .concat(table.ushortList('lookaheadGlyph', chainRule.lookahead, chainRule.lookahead.length))\n .concat(table.ushortList('substitution', [], chainRule.lookupRecords.length));\n\n chainRule.lookupRecords.forEach((record, i) => {\n tableData = tableData\n .concat({name: 'sequenceIndex' + i, type: 'USHORT', value: record.sequenceIndex})\n .concat({name: 'lookupListIndex' + i, type: 'USHORT', value: record.lookupListIndex});\n });\n return new table.Table('chainRuleTable', tableData);\n }));\n })));\n return returnTable;\n } else if (subtable.substFormat === 2) {\n check.assert(false, 'lookup type 6 format 2 is not yet supported.');\n } else if (subtable.substFormat === 3) {\n let tableData = [\n {name: 'substFormat', type: 'USHORT', value: subtable.substFormat},\n ];\n\n tableData.push({name: 'backtrackGlyphCount', type: 'USHORT', value: subtable.backtrackCoverage.length});\n subtable.backtrackCoverage.forEach((coverage, i) => {\n tableData.push({name: 'backtrackCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});\n });\n tableData.push({name: 'inputGlyphCount', type: 'USHORT', value: subtable.inputCoverage.length});\n subtable.inputCoverage.forEach((coverage, i) => {\n tableData.push({name: 'inputCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});\n });\n tableData.push({name: 'lookaheadGlyphCount', type: 'USHORT', value: subtable.lookaheadCoverage.length});\n subtable.lookaheadCoverage.forEach((coverage, i) => {\n tableData.push({name: 'lookaheadCoverage' + i, type: 'TABLE', value: new table.Coverage(coverage)});\n });\n\n tableData.push({name: 'substitutionCount', type: 'USHORT', value: subtable.lookupRecords.length});\n subtable.lookupRecords.forEach((record, i) => {\n tableData = tableData\n .concat({name: 'sequenceIndex' + i, type: 'USHORT', value: record.sequenceIndex})\n .concat({name: 'lookupListIndex' + i, type: 'USHORT', value: record.lookupListIndex});\n });\n\n let returnTable = new table.Table('chainContextTable', tableData);\n\n return returnTable;\n }\n\n check.assert(false, 'lookup type 6 format must be 1, 2 or 3.');\n};\n\nfunction makeGsubTable(gsub) {\n return new table.Table('GSUB', [\n {name: 'version', type: 'ULONG', value: 0x10000},\n {name: 'scripts', type: 'TABLE', value: new table.ScriptList(gsub.scripts)},\n {name: 'features', type: 'TABLE', value: new table.FeatureList(gsub.features)},\n {name: 'lookups', type: 'TABLE', value: new table.LookupList(gsub.lookups, subtableMakers)}\n ]);\n}\n\nexport default { parse: parseGsubTable, make: makeGsubTable };\n","// The `GPOS` table contains kerning pairs, among other things.\n// https://www.microsoft.com/typography/OTSPEC/gpos.htm\n\nimport check from '../check';\nimport { decode } from '../types';\nimport parse from '../parse';\nimport table from '../table';\n\n// Parse the metadata `meta` table.\n// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html\nfunction parseMetaTable(data, start) {\n const p = new parse.Parser(data, start);\n const tableVersion = p.parseULong();\n check.argument(tableVersion === 1, 'Unsupported META table version.');\n p.parseULong(); // flags - currently unused and set to 0\n p.parseULong(); // tableOffset\n const numDataMaps = p.parseULong();\n\n const tags = {};\n for (let i = 0; i < numDataMaps; i++) {\n const tag = p.parseTag();\n const dataOffset = p.parseULong();\n const dataLength = p.parseULong();\n const text = decode.UTF8(data, start + dataOffset, dataLength);\n\n tags[tag] = text;\n }\n return tags;\n}\n\nfunction makeMetaTable(tags) {\n const numTags = Object.keys(tags).length;\n let stringPool = '';\n const stringPoolOffset = 16 + numTags * 12;\n\n const result = new table.Table('meta', [\n {name: 'version', type: 'ULONG', value: 1},\n {name: 'flags', type: 'ULONG', value: 0},\n {name: 'offset', type: 'ULONG', value: stringPoolOffset},\n {name: 'numTags', type: 'ULONG', value: numTags}\n ]);\n\n for (let tag in tags) {\n const pos = stringPool.length;\n stringPool += tags[tag];\n\n result.fields.push({name: 'tag ' + tag, type: 'TAG', value: tag});\n result.fields.push({name: 'offset ' + tag, type: 'ULONG', value: stringPoolOffset + pos});\n result.fields.push({name: 'length ' + tag, type: 'ULONG', value: tags[tag].length});\n }\n\n result.fields.push({name: 'stringPool', type: 'CHARARRAY', value: stringPool});\n\n return result;\n}\n\nexport default { parse: parseMetaTable, make: makeMetaTable };\n","// The `sfnt` wrapper provides organization for the tables in the font.\n// It is the top-level data structure in a font.\n// https://www.microsoft.com/typography/OTSPEC/otff.htm\n// Recommendations for creating OpenType Fonts:\n// http://www.microsoft.com/typography/otspec140/recom.htm\n\nimport check from '../check';\nimport table from '../table';\n\nimport cmap from './cmap';\nimport cff from './cff';\nimport head from './head';\nimport hhea from './hhea';\nimport hmtx from './hmtx';\nimport ltag from './ltag';\nimport maxp from './maxp';\nimport _name from './name';\nimport os2 from './os2';\nimport post from './post';\nimport gsub from './gsub';\nimport meta from './meta';\n\nfunction log2(v) {\n return Math.log(v) / Math.log(2) | 0;\n}\n\nfunction computeCheckSum(bytes) {\n while (bytes.length % 4 !== 0) {\n bytes.push(0);\n }\n\n let sum = 0;\n for (let i = 0; i < bytes.length; i += 4) {\n sum += (bytes[i] << 24) +\n (bytes[i + 1] << 16) +\n (bytes[i + 2] << 8) +\n (bytes[i + 3]);\n }\n\n sum %= Math.pow(2, 32);\n return sum;\n}\n\nfunction makeTableRecord(tag, checkSum, offset, length) {\n return new table.Record('Table Record', [\n {name: 'tag', type: 'TAG', value: tag !== undefined ? tag : ''},\n {name: 'checkSum', type: 'ULONG', value: checkSum !== undefined ? checkSum : 0},\n {name: 'offset', type: 'ULONG', value: offset !== undefined ? offset : 0},\n {name: 'length', type: 'ULONG', value: length !== undefined ? length : 0}\n ]);\n}\n\nfunction makeSfntTable(tables) {\n const sfnt = new table.Table('sfnt', [\n {name: 'version', type: 'TAG', value: 'OTTO'},\n {name: 'numTables', type: 'USHORT', value: 0},\n {name: 'searchRange', type: 'USHORT', value: 0},\n {name: 'entrySelector', type: 'USHORT', value: 0},\n {name: 'rangeShift', type: 'USHORT', value: 0}\n ]);\n sfnt.tables = tables;\n sfnt.numTables = tables.length;\n const highestPowerOf2 = Math.pow(2, log2(sfnt.numTables));\n sfnt.searchRange = 16 * highestPowerOf2;\n sfnt.entrySelector = log2(highestPowerOf2);\n sfnt.rangeShift = sfnt.numTables * 16 - sfnt.searchRange;\n\n const recordFields = [];\n const tableFields = [];\n\n let offset = sfnt.sizeOf() + (makeTableRecord().sizeOf() * sfnt.numTables);\n while (offset % 4 !== 0) {\n offset += 1;\n tableFields.push({name: 'padding', type: 'BYTE', value: 0});\n }\n\n for (let i = 0; i < tables.length; i += 1) {\n const t = tables[i];\n check.argument(t.tableName.length === 4, 'Table name' + t.tableName + ' is invalid.');\n const tableLength = t.sizeOf();\n const tableRecord = makeTableRecord(t.tableName, computeCheckSum(t.encode()), offset, tableLength);\n recordFields.push({name: tableRecord.tag + ' Table Record', type: 'RECORD', value: tableRecord});\n tableFields.push({name: t.tableName + ' table', type: 'RECORD', value: t});\n offset += tableLength;\n check.argument(!isNaN(offset), 'Something went wrong calculating the offset.');\n while (offset % 4 !== 0) {\n offset += 1;\n tableFields.push({name: 'padding', type: 'BYTE', value: 0});\n }\n }\n\n // Table records need to be sorted alphabetically.\n recordFields.sort(function(r1, r2) {\n if (r1.value.tag > r2.value.tag) {\n return 1;\n } else {\n return -1;\n }\n });\n\n sfnt.fields = sfnt.fields.concat(recordFields);\n sfnt.fields = sfnt.fields.concat(tableFields);\n return sfnt;\n}\n\n// Get the metrics for a character. If the string has more than one character\n// this function returns metrics for the first available character.\n// You can provide optional fallback metrics if no characters are available.\nfunction metricsForChar(font, chars, notFoundMetrics) {\n for (let i = 0; i < chars.length; i += 1) {\n const glyphIndex = font.charToGlyphIndex(chars[i]);\n if (glyphIndex > 0) {\n const glyph = font.glyphs.get(glyphIndex);\n return glyph.getMetrics();\n }\n }\n\n return notFoundMetrics;\n}\n\nfunction average(vs) {\n let sum = 0;\n for (let i = 0; i < vs.length; i += 1) {\n sum += vs[i];\n }\n\n return sum / vs.length;\n}\n\n// Convert the font object to a SFNT data structure.\n// This structure contains all the necessary tables and metadata to create a binary OTF file.\nfunction fontToSfntTable(font) {\n const xMins = [];\n const yMins = [];\n const xMaxs = [];\n const yMaxs = [];\n const advanceWidths = [];\n const leftSideBearings = [];\n const rightSideBearings = [];\n let firstCharIndex;\n let lastCharIndex = 0;\n let ulUnicodeRange1 = 0;\n let ulUnicodeRange2 = 0;\n let ulUnicodeRange3 = 0;\n let ulUnicodeRange4 = 0;\n\n for (let i = 0; i < font.glyphs.length; i += 1) {\n const glyph = font.glyphs.get(i);\n const unicode = glyph.unicode | 0;\n\n if (isNaN(glyph.advanceWidth)) {\n throw new Error('Glyph ' + glyph.name + ' (' + i + '): advanceWidth is not a number.');\n }\n\n if (firstCharIndex > unicode || firstCharIndex === undefined) {\n // ignore .notdef char\n if (unicode > 0) {\n firstCharIndex = unicode;\n }\n }\n\n if (lastCharIndex < unicode) {\n lastCharIndex = unicode;\n }\n\n const position = os2.getUnicodeRange(unicode);\n if (position < 32) {\n ulUnicodeRange1 |= 1 << position;\n } else if (position < 64) {\n ulUnicodeRange2 |= 1 << position - 32;\n } else if (position < 96) {\n ulUnicodeRange3 |= 1 << position - 64;\n } else if (position < 123) {\n ulUnicodeRange4 |= 1 << position - 96;\n } else {\n throw new Error('Unicode ranges bits > 123 are reserved for internal usage');\n }\n // Skip non-important characters.\n if (glyph.name === '.notdef') continue;\n const metrics = glyph.getMetrics();\n xMins.push(metrics.xMin);\n yMins.push(metrics.yMin);\n xMaxs.push(metrics.xMax);\n yMaxs.push(metrics.yMax);\n leftSideBearings.push(metrics.leftSideBearing);\n rightSideBearings.push(metrics.rightSideBearing);\n advanceWidths.push(glyph.advanceWidth);\n }\n\n const globals = {\n xMin: Math.min.apply(null, xMins),\n yMin: Math.min.apply(null, yMins),\n xMax: Math.max.apply(null, xMaxs),\n yMax: Math.max.apply(null, yMaxs),\n advanceWidthMax: Math.max.apply(null, advanceWidths),\n advanceWidthAvg: average(advanceWidths),\n minLeftSideBearing: Math.min.apply(null, leftSideBearings),\n maxLeftSideBearing: Math.max.apply(null, leftSideBearings),\n minRightSideBearing: Math.min.apply(null, rightSideBearings)\n };\n globals.ascender = font.ascender;\n globals.descender = font.descender;\n\n const headTable = head.make({\n flags: 3, // 00000011 (baseline for font at y=0; left sidebearing point at x=0)\n unitsPerEm: font.unitsPerEm,\n xMin: globals.xMin,\n yMin: globals.yMin,\n xMax: globals.xMax,\n yMax: globals.yMax,\n lowestRecPPEM: 3,\n createdTimestamp: font.createdTimestamp\n });\n\n const hheaTable = hhea.make({\n ascender: globals.ascender,\n descender: globals.descender,\n advanceWidthMax: globals.advanceWidthMax,\n minLeftSideBearing: globals.minLeftSideBearing,\n minRightSideBearing: globals.minRightSideBearing,\n xMaxExtent: globals.maxLeftSideBearing + (globals.xMax - globals.xMin),\n numberOfHMetrics: font.glyphs.length\n });\n\n const maxpTable = maxp.make(font.glyphs.length);\n\n const os2Table = os2.make(Object.assign({\n xAvgCharWidth: Math.round(globals.advanceWidthAvg),\n usFirstCharIndex: firstCharIndex,\n usLastCharIndex: lastCharIndex,\n ulUnicodeRange1: ulUnicodeRange1,\n ulUnicodeRange2: ulUnicodeRange2,\n ulUnicodeRange3: ulUnicodeRange3,\n ulUnicodeRange4: ulUnicodeRange4,\n // See http://typophile.com/node/13081 for more info on vertical metrics.\n // We get metrics for typical characters (such as \"x\" for xHeight).\n // We provide some fallback characters if characters are unavailable: their\n // ordering was chosen experimentally.\n sTypoAscender: globals.ascender,\n sTypoDescender: globals.descender,\n sTypoLineGap: 0,\n usWinAscent: globals.yMax,\n usWinDescent: Math.abs(globals.yMin),\n ulCodePageRange1: 1, // FIXME: hard-code Latin 1 support for now\n sxHeight: metricsForChar(font, 'xyvw', {yMax: Math.round(globals.ascender / 2)}).yMax,\n sCapHeight: metricsForChar(font, 'HIKLEFJMNTZBDPRAGOQSUVWXY', globals).yMax,\n usDefaultChar: font.hasChar(' ') ? 32 : 0, // Use space as the default character, if available.\n usBreakChar: font.hasChar(' ') ? 32 : 0, // Use space as the break character, if available.\n }, font.tables.os2));\n\n const hmtxTable = hmtx.make(font.glyphs);\n const cmapTable = cmap.make(font.glyphs);\n\n const englishFamilyName = font.getEnglishName('fontFamily');\n const englishStyleName = font.getEnglishName('fontSubfamily');\n const englishFullName = englishFamilyName + ' ' + englishStyleName;\n let postScriptName = font.getEnglishName('postScriptName');\n if (!postScriptName) {\n postScriptName = englishFamilyName.replace(/\\s/g, '') + '-' + englishStyleName;\n }\n\n const names = {};\n for (let n in font.names) {\n names[n] = font.names[n];\n }\n\n if (!names.uniqueID) {\n names.uniqueID = {en: font.getEnglishName('manufacturer') + ':' + englishFullName};\n }\n\n if (!names.postScriptName) {\n names.postScriptName = {en: postScriptName};\n }\n\n if (!names.preferredFamily) {\n names.preferredFamily = font.names.fontFamily;\n }\n\n if (!names.preferredSubfamily) {\n names.preferredSubfamily = font.names.fontSubfamily;\n }\n\n const languageTags = [];\n const nameTable = _name.make(names, languageTags);\n const ltagTable = (languageTags.length > 0 ? ltag.make(languageTags) : undefined);\n\n const postTable = post.make();\n const cffTable = cff.make(font.glyphs, {\n version: font.getEnglishName('version'),\n fullName: englishFullName,\n familyName: englishFamilyName,\n weightName: englishStyleName,\n postScriptName: postScriptName,\n unitsPerEm: font.unitsPerEm,\n fontBBox: [0, globals.yMin, globals.ascender, globals.advanceWidthMax]\n });\n\n const metaTable = (font.metas && Object.keys(font.metas).length > 0) ? meta.make(font.metas) : undefined;\n\n // The order does not matter because makeSfntTable() will sort them.\n const tables = [headTable, hheaTable, maxpTable, os2Table, nameTable, cmapTable, postTable, cffTable, hmtxTable];\n if (ltagTable) {\n tables.push(ltagTable);\n }\n // Optional tables\n if (font.tables.gsub) {\n tables.push(gsub.make(font.tables.gsub));\n }\n if (metaTable) {\n tables.push(metaTable);\n }\n\n const sfntTable = makeSfntTable(tables);\n\n // Compute the font's checkSum and store it in head.checkSumAdjustment.\n const bytes = sfntTable.encode();\n const checkSum = computeCheckSum(bytes);\n const tableFields = sfntTable.fields;\n let checkSumAdjusted = false;\n for (let i = 0; i < tableFields.length; i += 1) {\n if (tableFields[i].name === 'head table') {\n tableFields[i].value.checkSumAdjustment = 0xB1B0AFBA - checkSum;\n checkSumAdjusted = true;\n break;\n }\n }\n\n if (!checkSumAdjusted) {\n throw new Error('Could not find head table with checkSum to adjust.');\n }\n\n return sfntTable;\n}\n\nexport default { make: makeSfntTable, fontToTable: fontToSfntTable, computeCheckSum };\n","// The Layout object is the prototype of Substitution objects, and provides\n// utility methods to manipulate common layout tables (GPOS, GSUB, GDEF...)\n\nimport check from './check';\n\nfunction searchTag(arr, tag) {\n /* jshint bitwise: false */\n let imin = 0;\n let imax = arr.length - 1;\n while (imin <= imax) {\n const imid = (imin + imax) >>> 1;\n const val = arr[imid].tag;\n if (val === tag) {\n return imid;\n } else if (val < tag) {\n imin = imid + 1;\n } else { imax = imid - 1; }\n }\n // Not found: return -1-insertion point\n return -imin - 1;\n}\n\nfunction binSearch(arr, value) {\n /* jshint bitwise: false */\n let imin = 0;\n let imax = arr.length - 1;\n while (imin <= imax) {\n const imid = (imin + imax) >>> 1;\n const val = arr[imid];\n if (val === value) {\n return imid;\n } else if (val < value) {\n imin = imid + 1;\n } else { imax = imid - 1; }\n }\n // Not found: return -1-insertion point\n return -imin - 1;\n}\n\n// binary search in a list of ranges (coverage, class definition)\nfunction searchRange(ranges, value) {\n // jshint bitwise: false\n let range;\n let imin = 0;\n let imax = ranges.length - 1;\n while (imin <= imax) {\n const imid = (imin + imax) >>> 1;\n range = ranges[imid];\n const start = range.start;\n if (start === value) {\n return range;\n } else if (start < value) {\n imin = imid + 1;\n } else { imax = imid - 1; }\n }\n if (imin > 0) {\n range = ranges[imin - 1];\n if (value > range.end) return 0;\n return range;\n }\n}\n\n/**\n * @exports opentype.Layout\n * @class\n */\nfunction Layout(font, tableName) {\n this.font = font;\n this.tableName = tableName;\n}\n\nLayout.prototype = {\n\n /**\n * Binary search an object by \"tag\" property\n * @instance\n * @function searchTag\n * @memberof opentype.Layout\n * @param {Array} arr\n * @param {string} tag\n * @return {number}\n */\n searchTag: searchTag,\n\n /**\n * Binary search in a list of numbers\n * @instance\n * @function binSearch\n * @memberof opentype.Layout\n * @param {Array} arr\n * @param {number} value\n * @return {number}\n */\n binSearch: binSearch,\n\n /**\n * Get or create the Layout table (GSUB, GPOS etc).\n * @param {boolean} create - Whether to create a new one.\n * @return {Object} The GSUB or GPOS table.\n */\n getTable: function(create) {\n let layout = this.font.tables[this.tableName];\n if (!layout && create) {\n layout = this.font.tables[this.tableName] = this.createDefaultTable();\n }\n return layout;\n },\n\n /**\n * Returns all scripts in the substitution table.\n * @instance\n * @return {Array}\n */\n getScriptNames: function() {\n let layout = this.getTable();\n if (!layout) { return []; }\n return layout.scripts.map(function(script) {\n return script.tag;\n });\n },\n\n /**\n * Returns the best bet for a script name.\n * Returns 'DFLT' if it exists.\n * If not, returns 'latn' if it exists.\n * If neither exist, returns undefined.\n */\n getDefaultScriptName: function() {\n let layout = this.getTable();\n if (!layout) { return; }\n let hasLatn = false;\n for (let i = 0; i < layout.scripts.length; i++) {\n const name = layout.scripts[i].tag;\n if (name === 'DFLT') return name;\n if (name === 'latn') hasLatn = true;\n }\n if (hasLatn) return 'latn';\n },\n\n /**\n * Returns all LangSysRecords in the given script.\n * @instance\n * @param {string} [script='DFLT']\n * @param {boolean} create - forces the creation of this script table if it doesn't exist.\n * @return {Object} An object with tag and script properties.\n */\n getScriptTable: function(script, create) {\n const layout = this.getTable(create);\n if (layout) {\n script = script || 'DFLT';\n const scripts = layout.scripts;\n const pos = searchTag(layout.scripts, script);\n if (pos >= 0) {\n return scripts[pos].script;\n } else if (create) {\n const scr = {\n tag: script,\n script: {\n defaultLangSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: []},\n langSysRecords: []\n }\n };\n scripts.splice(-1 - pos, 0, scr);\n return scr.script;\n }\n }\n },\n\n /**\n * Returns a language system table\n * @instance\n * @param {string} [script='DFLT']\n * @param {string} [language='dlft']\n * @param {boolean} create - forces the creation of this langSysTable if it doesn't exist.\n * @return {Object}\n */\n getLangSysTable: function(script, language, create) {\n const scriptTable = this.getScriptTable(script, create);\n if (scriptTable) {\n if (!language || language === 'dflt' || language === 'DFLT') {\n return scriptTable.defaultLangSys;\n }\n const pos = searchTag(scriptTable.langSysRecords, language);\n if (pos >= 0) {\n return scriptTable.langSysRecords[pos].langSys;\n } else if (create) {\n const langSysRecord = {\n tag: language,\n langSys: {reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: []}\n };\n scriptTable.langSysRecords.splice(-1 - pos, 0, langSysRecord);\n return langSysRecord.langSys;\n }\n }\n },\n\n /**\n * Get a specific feature table.\n * @instance\n * @param {string} [script='DFLT']\n * @param {string} [language='dlft']\n * @param {string} feature - One of the codes listed at https://www.microsoft.com/typography/OTSPEC/featurelist.htm\n * @param {boolean} create - forces the creation of the feature table if it doesn't exist.\n * @return {Object}\n */\n getFeatureTable: function(script, language, feature, create) {\n const langSysTable = this.getLangSysTable(script, language, create);\n if (langSysTable) {\n let featureRecord;\n const featIndexes = langSysTable.featureIndexes;\n const allFeatures = this.font.tables[this.tableName].features;\n // The FeatureIndex array of indices is in arbitrary order,\n // even if allFeatures is sorted alphabetically by feature tag.\n for (let i = 0; i < featIndexes.length; i++) {\n featureRecord = allFeatures[featIndexes[i]];\n if (featureRecord.tag === feature) {\n return featureRecord.feature;\n }\n }\n if (create) {\n const index = allFeatures.length;\n // Automatic ordering of features would require to shift feature indexes in the script list.\n check.assert(index === 0 || feature >= allFeatures[index - 1].tag, 'Features must be added in alphabetical order.');\n featureRecord = {\n tag: feature,\n feature: { params: 0, lookupListIndexes: [] }\n };\n allFeatures.push(featureRecord);\n featIndexes.push(index);\n return featureRecord.feature;\n }\n }\n },\n\n /**\n * Get the lookup tables of a given type for a script/language/feature.\n * @instance\n * @param {string} [script='DFLT']\n * @param {string} [language='dlft']\n * @param {string} feature - 4-letter feature code\n * @param {number} lookupType - 1 to 9\n * @param {boolean} create - forces the creation of the lookup table if it doesn't exist, with no subtables.\n * @return {Object[]}\n */\n getLookupTables: function(script, language, feature, lookupType, create) {\n const featureTable = this.getFeatureTable(script, language, feature, create);\n const tables = [];\n if (featureTable) {\n let lookupTable;\n const lookupListIndexes = featureTable.lookupListIndexes;\n const allLookups = this.font.tables[this.tableName].lookups;\n // lookupListIndexes are in no particular order, so use naive search.\n for (let i = 0; i < lookupListIndexes.length; i++) {\n lookupTable = allLookups[lookupListIndexes[i]];\n if (lookupTable.lookupType === lookupType) {\n tables.push(lookupTable);\n }\n }\n if (tables.length === 0 && create) {\n lookupTable = {\n lookupType: lookupType,\n lookupFlag: 0,\n subtables: [],\n markFilteringSet: undefined\n };\n const index = allLookups.length;\n allLookups.push(lookupTable);\n lookupListIndexes.push(index);\n return [lookupTable];\n }\n }\n return tables;\n },\n\n /**\n * Find a glyph in a class definition table\n * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table\n * @param {object} classDefTable - an OpenType Layout class definition table\n * @param {number} glyphIndex - the index of the glyph to find\n * @returns {number} -1 if not found\n */\n getGlyphClass: function(classDefTable, glyphIndex) {\n switch (classDefTable.format) {\n case 1:\n if (classDefTable.startGlyph <= glyphIndex && glyphIndex < classDefTable.startGlyph + classDefTable.classes.length) {\n return classDefTable.classes[glyphIndex - classDefTable.startGlyph];\n }\n return 0;\n case 2:\n const range = searchRange(classDefTable.ranges, glyphIndex);\n return range ? range.classId : 0;\n }\n },\n\n /**\n * Find a glyph in a coverage table\n * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table\n * @param {object} coverageTable - an OpenType Layout coverage table\n * @param {number} glyphIndex - the index of the glyph to find\n * @returns {number} -1 if not found\n */\n getCoverageIndex: function(coverageTable, glyphIndex) {\n switch (coverageTable.format) {\n case 1:\n const index = binSearch(coverageTable.glyphs, glyphIndex);\n return index >= 0 ? index : -1;\n case 2:\n const range = searchRange(coverageTable.ranges, glyphIndex);\n return range ? range.index + glyphIndex - range.start : -1;\n }\n },\n\n /**\n * Returns the list of glyph indexes of a coverage table.\n * Format 1: the list is stored raw\n * Format 2: compact list as range records.\n * @instance\n * @param {Object} coverageTable\n * @return {Array}\n */\n expandCoverage: function(coverageTable) {\n if (coverageTable.format === 1) {\n return coverageTable.glyphs;\n } else {\n const glyphs = [];\n const ranges = coverageTable.ranges;\n for (let i = 0; i < ranges.length; i++) {\n const range = ranges[i];\n const start = range.start;\n const end = range.end;\n for (let j = start; j <= end; j++) {\n glyphs.push(j);\n }\n }\n return glyphs;\n }\n }\n\n};\n\nexport default Layout;\n","// The Position object provides utility methods to manipulate\n// the GPOS position table.\n\nimport Layout from './layout';\n\n/**\n * @exports opentype.Position\n * @class\n * @extends opentype.Layout\n * @param {opentype.Font}\n * @constructor\n */\nfunction Position(font) {\n Layout.call(this, font, 'gpos');\n}\n\nPosition.prototype = Layout.prototype;\n\n/**\n * Init some data for faster and easier access later.\n */\nPosition.prototype.init = function() {\n const script = this.getDefaultScriptName();\n this.defaultKerningTables = this.getKerningTables(script);\n};\n\n/**\n * Find a glyph pair in a list of lookup tables of type 2 and retrieve the xAdvance kerning value.\n *\n * @param {integer} leftIndex - left glyph index\n * @param {integer} rightIndex - right glyph index\n * @returns {integer}\n */\nPosition.prototype.getKerningValue = function(kerningLookups, leftIndex, rightIndex) {\n for (let i = 0; i < kerningLookups.length; i++) {\n const subtables = kerningLookups[i].subtables;\n for (let j = 0; j < subtables.length; j++) {\n const subtable = subtables[j];\n const covIndex = this.getCoverageIndex(subtable.coverage, leftIndex);\n if (covIndex < 0) continue;\n switch (subtable.posFormat) {\n case 1:\n // Search Pair Adjustment Positioning Format 1\n let pairSet = subtable.pairSets[covIndex];\n for (let k = 0; k < pairSet.length; k++) {\n let pair = pairSet[k];\n if (pair.secondGlyph === rightIndex) {\n return pair.value1 && pair.value1.xAdvance || 0;\n }\n }\n break; // left glyph found, not right glyph - try next subtable\n case 2:\n // Search Pair Adjustment Positioning Format 2\n const class1 = this.getGlyphClass(subtable.classDef1, leftIndex);\n const class2 = this.getGlyphClass(subtable.classDef2, rightIndex);\n const pair = subtable.classRecords[class1][class2];\n return pair.value1 && pair.value1.xAdvance || 0;\n }\n }\n }\n return 0;\n};\n\n/**\n * List all kerning lookup tables.\n *\n * @param {string} [script='DFLT'] - use font.position.getDefaultScriptName() for a better default value\n * @param {string} [language='dflt']\n * @return {object[]} The list of kerning lookup tables (may be empty), or undefined if there is no GPOS table (and we should use the kern table)\n */\nPosition.prototype.getKerningTables = function(script, language) {\n if (this.font.tables.gpos) {\n return this.getLookupTables(script, language, 'kern', 2);\n }\n};\n\nexport default Position;\n","// The Substitution object provides utility methods to manipulate\n// the GSUB substitution table.\n\nimport check from './check';\nimport Layout from './layout';\n\n/**\n * @exports opentype.Substitution\n * @class\n * @extends opentype.Layout\n * @param {opentype.Font}\n * @constructor\n */\nfunction Substitution(font) {\n Layout.call(this, font, 'gsub');\n}\n\n// Check if 2 arrays of primitives are equal.\nfunction arraysEqual(ar1, ar2) {\n const n = ar1.length;\n if (n !== ar2.length) { return false; }\n for (let i = 0; i < n; i++) {\n if (ar1[i] !== ar2[i]) { return false; }\n }\n return true;\n}\n\n// Find the first subtable of a lookup table in a particular format.\nfunction getSubstFormat(lookupTable, format, defaultSubtable) {\n const subtables = lookupTable.subtables;\n for (let i = 0; i < subtables.length; i++) {\n const subtable = subtables[i];\n if (subtable.substFormat === format) {\n return subtable;\n }\n }\n if (defaultSubtable) {\n subtables.push(defaultSubtable);\n return defaultSubtable;\n }\n return undefined;\n}\n\nSubstitution.prototype = Layout.prototype;\n\n/**\n * Create a default GSUB table.\n * @return {Object} gsub - The GSUB table.\n */\nSubstitution.prototype.createDefaultTable = function() {\n // Generate a default empty GSUB table with just a DFLT script and dflt lang sys.\n return {\n version: 1,\n scripts: [{\n tag: 'DFLT',\n script: {\n defaultLangSys: { reserved: 0, reqFeatureIndex: 0xffff, featureIndexes: [] },\n langSysRecords: []\n }\n }],\n features: [],\n lookups: []\n };\n};\n\n/**\n * List all single substitutions (lookup type 1) for a given script, language, and feature.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @param {string} feature - 4-character feature name ('aalt', 'salt', 'ss01'...)\n * @return {Array} substitutions - The list of substitutions.\n */\nSubstitution.prototype.getSingle = function(feature, script, language) {\n const substitutions = [];\n const lookupTables = this.getLookupTables(script, language, feature, 1);\n for (let idx = 0; idx < lookupTables.length; idx++) {\n const subtables = lookupTables[idx].subtables;\n for (let i = 0; i < subtables.length; i++) {\n const subtable = subtables[i];\n const glyphs = this.expandCoverage(subtable.coverage);\n let j;\n if (subtable.substFormat === 1) {\n const delta = subtable.deltaGlyphId;\n for (j = 0; j < glyphs.length; j++) {\n const glyph = glyphs[j];\n substitutions.push({ sub: glyph, by: glyph + delta });\n }\n } else {\n const substitute = subtable.substitute;\n for (j = 0; j < glyphs.length; j++) {\n substitutions.push({ sub: glyphs[j], by: substitute[j] });\n }\n }\n }\n }\n return substitutions;\n};\n\n/**\n * List all multiple substitutions (lookup type 2) for a given script, language, and feature.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @param {string} feature - 4-character feature name ('ccmp', 'stch')\n * @return {Array} substitutions - The list of substitutions.\n */\nSubstitution.prototype.getMultiple = function(feature, script, language) {\n const substitutions = [];\n const lookupTables = this.getLookupTables(script, language, feature, 2);\n for (let idx = 0; idx < lookupTables.length; idx++) {\n const subtables = lookupTables[idx].subtables;\n for (let i = 0; i < subtables.length; i++) {\n const subtable = subtables[i];\n const glyphs = this.expandCoverage(subtable.coverage);\n let j;\n\n for (j = 0; j < glyphs.length; j++) {\n const glyph = glyphs[j];\n const replacements = subtable.sequences[j];\n substitutions.push({ sub: glyph, by: replacements });\n }\n }\n }\n return substitutions;\n};\n\n/**\n * List all alternates (lookup type 3) for a given script, language, and feature.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @param {string} feature - 4-character feature name ('aalt', 'salt'...)\n * @return {Array} alternates - The list of alternates\n */\nSubstitution.prototype.getAlternates = function(feature, script, language) {\n const alternates = [];\n const lookupTables = this.getLookupTables(script, language, feature, 3);\n for (let idx = 0; idx < lookupTables.length; idx++) {\n const subtables = lookupTables[idx].subtables;\n for (let i = 0; i < subtables.length; i++) {\n const subtable = subtables[i];\n const glyphs = this.expandCoverage(subtable.coverage);\n const alternateSets = subtable.alternateSets;\n for (let j = 0; j < glyphs.length; j++) {\n alternates.push({ sub: glyphs[j], by: alternateSets[j] });\n }\n }\n }\n return alternates;\n};\n\n/**\n * List all ligatures (lookup type 4) for a given script, language, and feature.\n * The result is an array of ligature objects like { sub: [ids], by: id }\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @return {Array} ligatures - The list of ligatures.\n */\nSubstitution.prototype.getLigatures = function(feature, script, language) {\n const ligatures = [];\n const lookupTables = this.getLookupTables(script, language, feature, 4);\n for (let idx = 0; idx < lookupTables.length; idx++) {\n const subtables = lookupTables[idx].subtables;\n for (let i = 0; i < subtables.length; i++) {\n const subtable = subtables[i];\n const glyphs = this.expandCoverage(subtable.coverage);\n const ligatureSets = subtable.ligatureSets;\n for (let j = 0; j < glyphs.length; j++) {\n const startGlyph = glyphs[j];\n const ligSet = ligatureSets[j];\n for (let k = 0; k < ligSet.length; k++) {\n const lig = ligSet[k];\n ligatures.push({\n sub: [startGlyph].concat(lig.components),\n by: lig.ligGlyph\n });\n }\n }\n }\n }\n return ligatures;\n};\n\n/**\n * Add or modify a single substitution (lookup type 1)\n * Format 2, more flexible, is always used.\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {Object} substitution - { sub: id, by: id } (format 1 is not supported)\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\nSubstitution.prototype.addSingle = function(feature, substitution, script, language) {\n const lookupTable = this.getLookupTables(script, language, feature, 1, true)[0];\n const subtable = getSubstFormat(lookupTable, 2, { // lookup type 1 subtable, format 2, coverage format 1\n substFormat: 2,\n coverage: {format: 1, glyphs: []},\n substitute: []\n });\n check.assert(subtable.coverage.format === 1, 'Single: unable to modify coverage table format ' + subtable.coverage.format);\n const coverageGlyph = substitution.sub;\n let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos < 0) {\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.substitute.splice(pos, 0, 0);\n }\n subtable.substitute[pos] = substitution.by;\n};\n\n/**\n * Add or modify a multiple substitution (lookup type 2)\n * @param {string} feature - 4-letter feature name ('ccmp', 'stch')\n * @param {Object} substitution - { sub: id, by: [id] } for format 2.\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\nSubstitution.prototype.addMultiple = function(feature, substitution, script, language) {\n check.assert(substitution.by instanceof Array && substitution.by.length > 1, 'Multiple: \"by\" must be an array of two or more ids');\n const lookupTable = this.getLookupTables(script, language, feature, 2, true)[0];\n const subtable = getSubstFormat(lookupTable, 1, { // lookup type 2 subtable, format 1, coverage format 1\n substFormat: 1,\n coverage: {format: 1, glyphs: []},\n sequences: []\n });\n check.assert(subtable.coverage.format === 1, 'Multiple: unable to modify coverage table format ' + subtable.coverage.format);\n const coverageGlyph = substitution.sub;\n let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos < 0) {\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.sequences.splice(pos, 0, 0);\n }\n subtable.sequences[pos] = substitution.by;\n};\n\n/**\n * Add or modify an alternate substitution (lookup type 3)\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {Object} substitution - { sub: id, by: [ids] }\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\nSubstitution.prototype.addAlternate = function(feature, substitution, script, language) {\n const lookupTable = this.getLookupTables(script, language, feature, 3, true)[0];\n const subtable = getSubstFormat(lookupTable, 1, { // lookup type 3 subtable, format 1, coverage format 1\n substFormat: 1,\n coverage: {format: 1, glyphs: []},\n alternateSets: []\n });\n check.assert(subtable.coverage.format === 1, 'Alternate: unable to modify coverage table format ' + subtable.coverage.format);\n const coverageGlyph = substitution.sub;\n let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos < 0) {\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.alternateSets.splice(pos, 0, 0);\n }\n subtable.alternateSets[pos] = substitution.by;\n};\n\n/**\n * Add a ligature (lookup type 4)\n * Ligatures with more components must be stored ahead of those with fewer components in order to be found\n * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...)\n * @param {Object} ligature - { sub: [ids], by: id }\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\nSubstitution.prototype.addLigature = function(feature, ligature, script, language) {\n const lookupTable = this.getLookupTables(script, language, feature, 4, true)[0];\n let subtable = lookupTable.subtables[0];\n if (!subtable) {\n subtable = { // lookup type 4 subtable, format 1, coverage format 1\n substFormat: 1,\n coverage: { format: 1, glyphs: [] },\n ligatureSets: []\n };\n lookupTable.subtables[0] = subtable;\n }\n check.assert(subtable.coverage.format === 1, 'Ligature: unable to modify coverage table format ' + subtable.coverage.format);\n const coverageGlyph = ligature.sub[0];\n const ligComponents = ligature.sub.slice(1);\n const ligatureTable = {\n ligGlyph: ligature.by,\n components: ligComponents\n };\n let pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph);\n if (pos >= 0) {\n // ligatureSet already exists\n const ligatureSet = subtable.ligatureSets[pos];\n for (let i = 0; i < ligatureSet.length; i++) {\n // If ligature already exists, return.\n if (arraysEqual(ligatureSet[i].components, ligComponents)) {\n return;\n }\n }\n // ligature does not exist: add it.\n ligatureSet.push(ligatureTable);\n } else {\n // Create a new ligatureSet and add coverage for the first glyph.\n pos = -1 - pos;\n subtable.coverage.glyphs.splice(pos, 0, coverageGlyph);\n subtable.ligatureSets.splice(pos, 0, [ligatureTable]);\n }\n};\n\n/**\n * List all feature data for a given script and language.\n * @param {string} feature - 4-letter feature name\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n * @return {Array} substitutions - The list of substitutions.\n */\nSubstitution.prototype.getFeature = function(feature, script, language) {\n if (/ss\\d\\d/.test(feature)) {\n // ss01 - ss20\n return this.getSingle(feature, script, language);\n }\n switch (feature) {\n case 'aalt':\n case 'salt':\n return this.getSingle(feature, script, language)\n .concat(this.getAlternates(feature, script, language));\n case 'dlig':\n case 'liga':\n case 'rlig':\n return this.getLigatures(feature, script, language);\n case 'ccmp':\n return this.getMultiple(feature, script, language)\n .concat(this.getLigatures(feature, script, language));\n case 'stch':\n return this.getMultiple(feature, script, language);\n }\n return undefined;\n};\n\n/**\n * Add a substitution to a feature for a given script and language.\n * @param {string} feature - 4-letter feature name\n * @param {Object} sub - the substitution to add (an object like { sub: id or [ids], by: id or [ids] })\n * @param {string} [script='DFLT']\n * @param {string} [language='dflt']\n */\nSubstitution.prototype.add = function(feature, sub, script, language) {\n if (/ss\\d\\d/.test(feature)) {\n // ss01 - ss20\n return this.addSingle(feature, sub, script, language);\n }\n switch (feature) {\n case 'aalt':\n case 'salt':\n if (typeof sub.by === 'number') {\n return this.addSingle(feature, sub, script, language);\n }\n return this.addAlternate(feature, sub, script, language);\n case 'dlig':\n case 'liga':\n case 'rlig':\n return this.addLigature(feature, sub, script, language);\n case 'ccmp':\n if (sub.by instanceof Array) {\n return this.addMultiple(feature, sub, script, language);\n }\n return this.addLigature(feature, sub, script, language);\n }\n return undefined;\n};\n\nexport default Substitution;\n","function isBrowser() {\n return typeof window !== 'undefined';\n}\n\nfunction isNode() {\n return typeof window === 'undefined';\n}\n\nfunction nodeBufferToArrayBuffer(buffer) {\n const ab = new ArrayBuffer(buffer.length);\n const view = new Uint8Array(ab);\n for (let i = 0; i < buffer.length; ++i) {\n view[i] = buffer[i];\n }\n\n return ab;\n}\n\nfunction arrayBufferToNodeBuffer(ab) {\n const buffer = new Buffer(ab.byteLength);\n const view = new Uint8Array(ab);\n for (let i = 0; i < buffer.length; ++i) {\n buffer[i] = view[i];\n }\n\n return buffer;\n}\n\nfunction checkArgument(expression, message) {\n if (!expression) {\n throw message;\n }\n}\n\nexport { isBrowser, isNode, nodeBufferToArrayBuffer, arrayBufferToNodeBuffer, checkArgument };\n","// The `glyf` table describes the glyphs in TrueType outline format.\n// http://www.microsoft.com/typography/otspec/glyf.htm\n\nimport check from '../check';\nimport glyphset from '../glyphset';\nimport parse from '../parse';\nimport Path from '../path';\n\n// Parse the coordinate data for a glyph.\nfunction parseGlyphCoordinate(p, flag, previousValue, shortVectorBitMask, sameBitMask) {\n let v;\n if ((flag & shortVectorBitMask) > 0) {\n // The coordinate is 1 byte long.\n v = p.parseByte();\n // The `same` bit is re-used for short values to signify the sign of the value.\n if ((flag & sameBitMask) === 0) {\n v = -v;\n }\n\n v = previousValue + v;\n } else {\n // The coordinate is 2 bytes long.\n // If the `same` bit is set, the coordinate is the same as the previous coordinate.\n if ((flag & sameBitMask) > 0) {\n v = previousValue;\n } else {\n // Parse the coordinate as a signed 16-bit delta value.\n v = previousValue + p.parseShort();\n }\n }\n\n return v;\n}\n\n// Parse a TrueType glyph.\nfunction parseGlyph(glyph, data, start) {\n const p = new parse.Parser(data, start);\n glyph.numberOfContours = p.parseShort();\n glyph._xMin = p.parseShort();\n glyph._yMin = p.parseShort();\n glyph._xMax = p.parseShort();\n glyph._yMax = p.parseShort();\n let flags;\n let flag;\n\n if (glyph.numberOfContours > 0) {\n // This glyph is not a composite.\n const endPointIndices = glyph.endPointIndices = [];\n for (let i = 0; i < glyph.numberOfContours; i += 1) {\n endPointIndices.push(p.parseUShort());\n }\n\n glyph.instructionLength = p.parseUShort();\n glyph.instructions = [];\n for (let i = 0; i < glyph.instructionLength; i += 1) {\n glyph.instructions.push(p.parseByte());\n }\n\n const numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1;\n flags = [];\n for (let i = 0; i < numberOfCoordinates; i += 1) {\n flag = p.parseByte();\n flags.push(flag);\n // If bit 3 is set, we repeat this flag n times, where n is the next byte.\n if ((flag & 8) > 0) {\n const repeatCount = p.parseByte();\n for (let j = 0; j < repeatCount; j += 1) {\n flags.push(flag);\n i += 1;\n }\n }\n }\n\n check.argument(flags.length === numberOfCoordinates, 'Bad flags.');\n\n if (endPointIndices.length > 0) {\n const points = [];\n let point;\n // X/Y coordinates are relative to the previous point, except for the first point which is relative to 0,0.\n if (numberOfCoordinates > 0) {\n for (let i = 0; i < numberOfCoordinates; i += 1) {\n flag = flags[i];\n point = {};\n point.onCurve = !!(flag & 1);\n point.lastPointOfContour = endPointIndices.indexOf(i) >= 0;\n points.push(point);\n }\n\n let px = 0;\n for (let i = 0; i < numberOfCoordinates; i += 1) {\n flag = flags[i];\n point = points[i];\n point.x = parseGlyphCoordinate(p, flag, px, 2, 16);\n px = point.x;\n }\n\n let py = 0;\n for (let i = 0; i < numberOfCoordinates; i += 1) {\n flag = flags[i];\n point = points[i];\n point.y = parseGlyphCoordinate(p, flag, py, 4, 32);\n py = point.y;\n }\n }\n\n glyph.points = points;\n } else {\n glyph.points = [];\n }\n } else if (glyph.numberOfContours === 0) {\n glyph.points = [];\n } else {\n glyph.isComposite = true;\n glyph.points = [];\n glyph.components = [];\n let moreComponents = true;\n while (moreComponents) {\n flags = p.parseUShort();\n const component = {\n glyphIndex: p.parseUShort(),\n xScale: 1,\n scale01: 0,\n scale10: 0,\n yScale: 1,\n dx: 0,\n dy: 0\n };\n if ((flags & 1) > 0) {\n // The arguments are words\n if ((flags & 2) > 0) {\n // values are offset\n component.dx = p.parseShort();\n component.dy = p.parseShort();\n } else {\n // values are matched points\n component.matchedPoints = [p.parseUShort(), p.parseUShort()];\n }\n\n } else {\n // The arguments are bytes\n if ((flags & 2) > 0) {\n // values are offset\n component.dx = p.parseChar();\n component.dy = p.parseChar();\n } else {\n // values are matched points\n component.matchedPoints = [p.parseByte(), p.parseByte()];\n }\n }\n\n if ((flags & 8) > 0) {\n // We have a scale\n component.xScale = component.yScale = p.parseF2Dot14();\n } else if ((flags & 64) > 0) {\n // We have an X / Y scale\n component.xScale = p.parseF2Dot14();\n component.yScale = p.parseF2Dot14();\n } else if ((flags & 128) > 0) {\n // We have a 2x2 transformation\n component.xScale = p.parseF2Dot14();\n component.scale01 = p.parseF2Dot14();\n component.scale10 = p.parseF2Dot14();\n component.yScale = p.parseF2Dot14();\n }\n\n glyph.components.push(component);\n moreComponents = !!(flags & 32);\n }\n if (flags & 0x100) {\n // We have instructions\n glyph.instructionLength = p.parseUShort();\n glyph.instructions = [];\n for (let i = 0; i < glyph.instructionLength; i += 1) {\n glyph.instructions.push(p.parseByte());\n }\n }\n }\n}\n\n// Transform an array of points and return a new array.\nfunction transformPoints(points, transform) {\n const newPoints = [];\n for (let i = 0; i < points.length; i += 1) {\n const pt = points[i];\n const newPt = {\n x: transform.xScale * pt.x + transform.scale01 * pt.y + transform.dx,\n y: transform.scale10 * pt.x + transform.yScale * pt.y + transform.dy,\n onCurve: pt.onCurve,\n lastPointOfContour: pt.lastPointOfContour\n };\n newPoints.push(newPt);\n }\n\n return newPoints;\n}\n\nfunction getContours(points) {\n const contours = [];\n let currentContour = [];\n for (let i = 0; i < points.length; i += 1) {\n const pt = points[i];\n currentContour.push(pt);\n if (pt.lastPointOfContour) {\n contours.push(currentContour);\n currentContour = [];\n }\n }\n\n check.argument(currentContour.length === 0, 'There are still points left in the current contour.');\n return contours;\n}\n\n// Convert the TrueType glyph outline to a Path.\nfunction getPath(points) {\n const p = new Path();\n if (!points) {\n return p;\n }\n\n const contours = getContours(points);\n\n for (let contourIndex = 0; contourIndex < contours.length; ++contourIndex) {\n const contour = contours[contourIndex];\n\n let prev = null;\n let curr = contour[contour.length - 1];\n let next = contour[0];\n\n if (curr.onCurve) {\n p.moveTo(curr.x, curr.y);\n } else {\n if (next.onCurve) {\n p.moveTo(next.x, next.y);\n } else {\n // If both first and last points are off-curve, start at their middle.\n const start = {x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5};\n p.moveTo(start.x, start.y);\n }\n }\n\n for (let i = 0; i < contour.length; ++i) {\n prev = curr;\n curr = next;\n next = contour[(i + 1) % contour.length];\n\n if (curr.onCurve) {\n // This is a straight line.\n p.lineTo(curr.x, curr.y);\n } else {\n let prev2 = prev;\n let next2 = next;\n\n if (!prev.onCurve) {\n prev2 = { x: (curr.x + prev.x) * 0.5, y: (curr.y + prev.y) * 0.5 };\n }\n\n if (!next.onCurve) {\n next2 = { x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5 };\n }\n\n p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y);\n }\n }\n\n p.closePath();\n }\n return p;\n}\n\nfunction buildPath(glyphs, glyph) {\n if (glyph.isComposite) {\n for (let j = 0; j < glyph.components.length; j += 1) {\n const component = glyph.components[j];\n const componentGlyph = glyphs.get(component.glyphIndex);\n // Force the ttfGlyphLoader to parse the glyph.\n componentGlyph.getPath();\n if (componentGlyph.points) {\n let transformedPoints;\n if (component.matchedPoints === undefined) {\n // component positioned by offset\n transformedPoints = transformPoints(componentGlyph.points, component);\n } else {\n // component positioned by matched points\n if ((component.matchedPoints[0] > glyph.points.length - 1) ||\n (component.matchedPoints[1] > componentGlyph.points.length - 1)) {\n throw Error('Matched points out of range in ' + glyph.name);\n }\n const firstPt = glyph.points[component.matchedPoints[0]];\n let secondPt = componentGlyph.points[component.matchedPoints[1]];\n const transform = {\n xScale: component.xScale, scale01: component.scale01,\n scale10: component.scale10, yScale: component.yScale,\n dx: 0, dy: 0\n };\n secondPt = transformPoints([secondPt], transform)[0];\n transform.dx = firstPt.x - secondPt.x;\n transform.dy = firstPt.y - secondPt.y;\n transformedPoints = transformPoints(componentGlyph.points, transform);\n }\n glyph.points = glyph.points.concat(transformedPoints);\n }\n }\n }\n\n return getPath(glyph.points);\n}\n\nfunction parseGlyfTableAll(data, start, loca, font) {\n const glyphs = new glyphset.GlyphSet(font);\n\n // The last element of the loca table is invalid.\n for (let i = 0; i < loca.length - 1; i += 1) {\n const offset = loca[i];\n const nextOffset = loca[i + 1];\n if (offset !== nextOffset) {\n glyphs.push(i, glyphset.ttfGlyphLoader(font, i, parseGlyph, data, start + offset, buildPath));\n } else {\n glyphs.push(i, glyphset.glyphLoader(font, i));\n }\n }\n\n return glyphs;\n}\n\nfunction parseGlyfTableOnLowMemory(data, start, loca, font) {\n const glyphs = new glyphset.GlyphSet(font);\n\n font._push = function(i) {\n const offset = loca[i];\n const nextOffset = loca[i + 1];\n if (offset !== nextOffset) {\n glyphs.push(i, glyphset.ttfGlyphLoader(font, i, parseGlyph, data, start + offset, buildPath));\n } else {\n glyphs.push(i, glyphset.glyphLoader(font, i));\n }\n };\n\n return glyphs;\n}\n\n// Parse all the glyphs according to the offsets from the `loca` table.\nfunction parseGlyfTable(data, start, loca, font, opt) {\n if (opt.lowMemory)\n return parseGlyfTableOnLowMemory(data, start, loca, font);\n else\n return parseGlyfTableAll(data, start, loca, font);\n}\n\nexport default { getPath, parse: parseGlyfTable};\n","/* A TrueType font hinting interpreter.\n*\n* (c) 2017 Axel Kittenberger\n*\n* This interpreter has been implemented according to this documentation:\n* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html\n*\n* According to the documentation F24DOT6 values are used for pixels.\n* That means calculation is 1/64 pixel accurate and uses integer operations.\n* However, Javascript has floating point operations by default and only\n* those are available. One could make a case to simulate the 1/64 accuracy\n* exactly by truncating after every division operation\n* (for example with << 0) to get pixel exactly results as other TrueType\n* implementations. It may make sense since some fonts are pixel optimized\n* by hand using DELTAP instructions. The current implementation doesn't\n* and rather uses full floating point precision.\n*\n* xScale, yScale and rotation is currently ignored.\n*\n* A few non-trivial instructions are missing as I didn't encounter yet\n* a font that used them to test a possible implementation.\n*\n* Some fonts seem to use undocumented features regarding the twilight zone.\n* Only some of them are implemented as they were encountered.\n*\n* The exports.DEBUG statements are removed on the minified distribution file.\n*/\n'use strict';\n\nimport glyf from './tables/glyf';\n\nlet instructionTable;\nlet exec;\nlet execGlyph;\nlet execComponent;\n\n/*\n* Creates a hinting object.\n*\n* There ought to be exactly one\n* for each truetype font that is used for hinting.\n*/\nfunction Hinting(font) {\n // the font this hinting object is for\n this.font = font;\n\n this.getCommands = function (hPoints) {\n return glyf.getPath(hPoints).commands;\n };\n\n // cached states\n this._fpgmState =\n this._prepState =\n undefined;\n\n // errorState\n // 0 ... all okay\n // 1 ... had an error in a glyf,\n // continue working but stop spamming\n // the console\n // 2 ... error at prep, stop hinting at this ppem\n // 3 ... error at fpeg, stop hinting for this font at all\n this._errorState = 0;\n}\n\n/*\n* Not rounding.\n*/\nfunction roundOff(v) {\n return v;\n}\n\n/*\n* Rounding to grid.\n*/\nfunction roundToGrid(v) {\n //Rounding in TT is supposed to \"symmetrical around zero\"\n return Math.sign(v) * Math.round(Math.abs(v));\n}\n\n/*\n* Rounding to double grid.\n*/\nfunction roundToDoubleGrid(v) {\n return Math.sign(v) * Math.round(Math.abs(v * 2)) / 2;\n}\n\n/*\n* Rounding to half grid.\n*/\nfunction roundToHalfGrid(v) {\n return Math.sign(v) * (Math.round(Math.abs(v) + 0.5) - 0.5);\n}\n\n/*\n* Rounding to up to grid.\n*/\nfunction roundUpToGrid(v) {\n return Math.sign(v) * Math.ceil(Math.abs(v));\n}\n\n/*\n* Rounding to down to grid.\n*/\nfunction roundDownToGrid(v) {\n return Math.sign(v) * Math.floor(Math.abs(v));\n}\n\n/*\n* Super rounding.\n*/\nconst roundSuper = function (v) {\n const period = this.srPeriod;\n let phase = this.srPhase;\n const threshold = this.srThreshold;\n let sign = 1;\n\n if (v < 0) {\n v = -v;\n sign = -1;\n }\n\n v += threshold - phase;\n\n v = Math.trunc(v / period) * period;\n\n v += phase;\n\n // according to http://xgridfit.sourceforge.net/round.html\n if (v < 0) return phase * sign;\n\n return v * sign;\n};\n\n/*\n* Unit vector of x-axis.\n*/\nconst xUnitVector = {\n x: 1,\n\n y: 0,\n\n axis: 'x',\n\n // Gets the projected distance between two points.\n // o1/o2 ... if true, respective original position is used.\n distance: function (p1, p2, o1, o2) {\n return (o1 ? p1.xo : p1.x) - (o2 ? p2.xo : p2.x);\n },\n\n // Moves point p so the moved position has the same relative\n // position to the moved positions of rp1 and rp2 than the\n // original positions had.\n //\n // See APPENDIX on INTERPOLATE at the bottom of this file.\n interpolate: function (p, rp1, rp2, pv) {\n let do1;\n let do2;\n let doa1;\n let doa2;\n let dm1;\n let dm2;\n let dt;\n\n if (!pv || pv === this) {\n do1 = p.xo - rp1.xo;\n do2 = p.xo - rp2.xo;\n dm1 = rp1.x - rp1.xo;\n dm2 = rp2.x - rp2.xo;\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n p.x = p.xo + (dm1 + dm2) / 2;\n return;\n }\n\n p.x = p.xo + (dm1 * doa2 + dm2 * doa1) / dt;\n return;\n }\n\n do1 = pv.distance(p, rp1, true, true);\n do2 = pv.distance(p, rp2, true, true);\n dm1 = pv.distance(rp1, rp1, false, true);\n dm2 = pv.distance(rp2, rp2, false, true);\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n xUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true);\n return;\n }\n\n xUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);\n },\n\n // Slope of line normal to this\n normalSlope: Number.NEGATIVE_INFINITY,\n\n // Sets the point 'p' relative to point 'rp'\n // by the distance 'd'.\n //\n // See APPENDIX on SETRELATIVE at the bottom of this file.\n //\n // p ... point to set\n // rp ... reference point\n // d ... distance on projection vector\n // pv ... projection vector (undefined = this)\n // org ... if true, uses the original position of rp as reference.\n setRelative: function (p, rp, d, pv, org) {\n if (!pv || pv === this) {\n p.x = (org ? rp.xo : rp.x) + d;\n return;\n }\n\n const rpx = org ? rp.xo : rp.x;\n const rpy = org ? rp.yo : rp.y;\n const rpdx = rpx + d * pv.x;\n const rpdy = rpy + d * pv.y;\n\n p.x = rpdx + (p.y - rpdy) / pv.normalSlope;\n },\n\n // Slope of vector line.\n slope: 0,\n\n // Touches the point p.\n touch: function (p) {\n p.xTouched = true;\n },\n\n // Tests if a point p is touched.\n touched: function (p) {\n return p.xTouched;\n },\n\n // Untouches the point p.\n untouch: function (p) {\n p.xTouched = false;\n }\n};\n\n/*\n* Unit vector of y-axis.\n*/\nconst yUnitVector = {\n x: 0,\n\n y: 1,\n\n axis: 'y',\n\n // Gets the projected distance between two points.\n // o1/o2 ... if true, respective original position is used.\n distance: function (p1, p2, o1, o2) {\n return (o1 ? p1.yo : p1.y) - (o2 ? p2.yo : p2.y);\n },\n\n // Moves point p so the moved position has the same relative\n // position to the moved positions of rp1 and rp2 than the\n // original positions had.\n //\n // See APPENDIX on INTERPOLATE at the bottom of this file.\n interpolate: function (p, rp1, rp2, pv) {\n let do1;\n let do2;\n let doa1;\n let doa2;\n let dm1;\n let dm2;\n let dt;\n\n if (!pv || pv === this) {\n do1 = p.yo - rp1.yo;\n do2 = p.yo - rp2.yo;\n dm1 = rp1.y - rp1.yo;\n dm2 = rp2.y - rp2.yo;\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n p.y = p.yo + (dm1 + dm2) / 2;\n return;\n }\n\n p.y = p.yo + (dm1 * doa2 + dm2 * doa1) / dt;\n return;\n }\n\n do1 = pv.distance(p, rp1, true, true);\n do2 = pv.distance(p, rp2, true, true);\n dm1 = pv.distance(rp1, rp1, false, true);\n dm2 = pv.distance(rp2, rp2, false, true);\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n yUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true);\n return;\n }\n\n yUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);\n },\n\n // Slope of line normal to this.\n normalSlope: 0,\n\n // Sets the point 'p' relative to point 'rp'\n // by the distance 'd'\n //\n // See APPENDIX on SETRELATIVE at the bottom of this file.\n //\n // p ... point to set\n // rp ... reference point\n // d ... distance on projection vector\n // pv ... projection vector (undefined = this)\n // org ... if true, uses the original position of rp as reference.\n setRelative: function (p, rp, d, pv, org) {\n if (!pv || pv === this) {\n p.y = (org ? rp.yo : rp.y) + d;\n return;\n }\n\n const rpx = org ? rp.xo : rp.x;\n const rpy = org ? rp.yo : rp.y;\n const rpdx = rpx + d * pv.x;\n const rpdy = rpy + d * pv.y;\n\n p.y = rpdy + pv.normalSlope * (p.x - rpdx);\n },\n\n // Slope of vector line.\n slope: Number.POSITIVE_INFINITY,\n\n // Touches the point p.\n touch: function (p) {\n p.yTouched = true;\n },\n\n // Tests if a point p is touched.\n touched: function (p) {\n return p.yTouched;\n },\n\n // Untouches the point p.\n untouch: function (p) {\n p.yTouched = false;\n }\n};\n\nObject.freeze(xUnitVector);\nObject.freeze(yUnitVector);\n\n/*\n* Creates a unit vector that is not x- or y-axis.\n*/\nfunction UnitVector(x, y) {\n this.x = x;\n this.y = y;\n this.axis = undefined;\n this.slope = y / x;\n this.normalSlope = -x / y;\n Object.freeze(this);\n}\n\n/*\n* Gets the projected distance between two points.\n* o1/o2 ... if true, respective original position is used.\n*/\nUnitVector.prototype.distance = function(p1, p2, o1, o2) {\n return (\n this.x * xUnitVector.distance(p1, p2, o1, o2) +\n this.y * yUnitVector.distance(p1, p2, o1, o2)\n );\n};\n\n/*\n* Moves point p so the moved position has the same relative\n* position to the moved positions of rp1 and rp2 than the\n* original positions had.\n*\n* See APPENDIX on INTERPOLATE at the bottom of this file.\n*/\nUnitVector.prototype.interpolate = function(p, rp1, rp2, pv) {\n let dm1;\n let dm2;\n let do1;\n let do2;\n let doa1;\n let doa2;\n let dt;\n\n do1 = pv.distance(p, rp1, true, true);\n do2 = pv.distance(p, rp2, true, true);\n dm1 = pv.distance(rp1, rp1, false, true);\n dm2 = pv.distance(rp2, rp2, false, true);\n doa1 = Math.abs(do1);\n doa2 = Math.abs(do2);\n dt = doa1 + doa2;\n\n if (dt === 0) {\n this.setRelative(p, p, (dm1 + dm2) / 2, pv, true);\n return;\n }\n\n this.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true);\n};\n\n/*\n* Sets the point 'p' relative to point 'rp'\n* by the distance 'd'\n*\n* See APPENDIX on SETRELATIVE at the bottom of this file.\n*\n* p ... point to set\n* rp ... reference point\n* d ... distance on projection vector\n* pv ... projection vector (undefined = this)\n* org ... if true, uses the original position of rp as reference.\n*/\nUnitVector.prototype.setRelative = function(p, rp, d, pv, org) {\n pv = pv || this;\n\n const rpx = org ? rp.xo : rp.x;\n const rpy = org ? rp.yo : rp.y;\n const rpdx = rpx + d * pv.x;\n const rpdy = rpy + d * pv.y;\n\n const pvns = pv.normalSlope;\n const fvs = this.slope;\n\n const px = p.x;\n const py = p.y;\n\n p.x = (fvs * px - pvns * rpdx + rpdy - py) / (fvs - pvns);\n p.y = fvs * (p.x - px) + py;\n};\n\n/*\n* Touches the point p.\n*/\nUnitVector.prototype.touch = function(p) {\n p.xTouched = true;\n p.yTouched = true;\n};\n\n/*\n* Returns a unit vector with x/y coordinates.\n*/\nfunction getUnitVector(x, y) {\n const d = Math.sqrt(x * x + y * y);\n\n x /= d;\n y /= d;\n\n if (x === 1 && y === 0) return xUnitVector;\n else if (x === 0 && y === 1) return yUnitVector;\n else return new UnitVector(x, y);\n}\n\n/*\n* Creates a point in the hinting engine.\n*/\nfunction HPoint(\n x,\n y,\n lastPointOfContour,\n onCurve\n) {\n this.x = this.xo = Math.round(x * 64) / 64; // hinted x value and original x-value\n this.y = this.yo = Math.round(y * 64) / 64; // hinted y value and original y-value\n\n this.lastPointOfContour = lastPointOfContour;\n this.onCurve = onCurve;\n this.prevPointOnContour = undefined;\n this.nextPointOnContour = undefined;\n this.xTouched = false;\n this.yTouched = false;\n\n Object.preventExtensions(this);\n}\n\n/*\n* Returns the next touched point on the contour.\n*\n* v ... unit vector to test touch axis.\n*/\nHPoint.prototype.nextTouched = function(v) {\n let p = this.nextPointOnContour;\n\n while (!v.touched(p) && p !== this) p = p.nextPointOnContour;\n\n return p;\n};\n\n/*\n* Returns the previous touched point on the contour\n*\n* v ... unit vector to test touch axis.\n*/\nHPoint.prototype.prevTouched = function(v) {\n let p = this.prevPointOnContour;\n\n while (!v.touched(p) && p !== this) p = p.prevPointOnContour;\n\n return p;\n};\n\n/*\n* The zero point.\n*/\nconst HPZero = Object.freeze(new HPoint(0, 0));\n\n/*\n* The default state of the interpreter.\n*\n* Note: Freezing the defaultState and then deriving from it\n* makes the V8 Javascript engine going awkward,\n* so this is avoided, albeit the defaultState shouldn't\n* ever change.\n*/\nconst defaultState = {\n cvCutIn: 17 / 16, // control value cut in\n deltaBase: 9,\n deltaShift: 0.125,\n loop: 1, // loops some instructions\n minDis: 1, // minimum distance\n autoFlip: true\n};\n\n/*\n* The current state of the interpreter.\n*\n* env ... 'fpgm' or 'prep' or 'glyf'\n* prog ... the program\n*/\nfunction State(env, prog) {\n this.env = env;\n this.stack = [];\n this.prog = prog;\n\n switch (env) {\n case 'glyf' :\n this.zp0 = this.zp1 = this.zp2 = 1;\n this.rp0 = this.rp1 = this.rp2 = 0;\n /* fall through */\n case 'prep' :\n this.fv = this.pv = this.dpv = xUnitVector;\n this.round = roundToGrid;\n }\n}\n\n/*\n* Executes a glyph program.\n*\n* This does the hinting for each glyph.\n*\n* Returns an array of moved points.\n*\n* glyph: the glyph to hint\n* ppem: the size the glyph is rendered for\n*/\nHinting.prototype.exec = function(glyph, ppem) {\n if (typeof ppem !== 'number') {\n throw new Error('Point size is not a number!');\n }\n\n // Received a fatal error, don't do any hinting anymore.\n if (this._errorState > 2) return;\n\n const font = this.font;\n let prepState = this._prepState;\n\n if (!prepState || prepState.ppem !== ppem) {\n let fpgmState = this._fpgmState;\n\n if (!fpgmState) {\n // Executes the fpgm state.\n // This is used by fonts to define functions.\n State.prototype = defaultState;\n\n fpgmState =\n this._fpgmState =\n new State('fpgm', font.tables.fpgm);\n\n fpgmState.funcs = [ ];\n fpgmState.font = font;\n\n if (exports.DEBUG) {\n console.log('---EXEC FPGM---');\n fpgmState.step = -1;\n }\n\n try {\n exec(fpgmState);\n } catch (e) {\n console.log('Hinting error in FPGM:' + e);\n this._errorState = 3;\n return;\n }\n }\n\n // Executes the prep program for this ppem setting.\n // This is used by fonts to set cvt values\n // depending on to be rendered font size.\n\n State.prototype = fpgmState;\n prepState =\n this._prepState =\n new State('prep', font.tables.prep);\n\n prepState.ppem = ppem;\n\n // Creates a copy of the cvt table\n // and scales it to the current ppem setting.\n const oCvt = font.tables.cvt;\n if (oCvt) {\n const cvt = prepState.cvt = new Array(oCvt.length);\n const scale = ppem / font.unitsPerEm;\n for (let c = 0; c < oCvt.length; c++) {\n cvt[c] = oCvt[c] * scale;\n }\n } else {\n prepState.cvt = [];\n }\n\n if (exports.DEBUG) {\n console.log('---EXEC PREP---');\n prepState.step = -1;\n }\n\n try {\n exec(prepState);\n } catch (e) {\n if (this._errorState < 2) {\n console.log('Hinting error in PREP:' + e);\n }\n this._errorState = 2;\n }\n }\n\n if (this._errorState > 1) return;\n\n try {\n return execGlyph(glyph, prepState);\n } catch (e) {\n if (this._errorState < 1) {\n console.log('Hinting error:' + e);\n console.log('Note: further hinting errors are silenced');\n }\n this._errorState = 1;\n return undefined;\n }\n};\n\n/*\n* Executes the hinting program for a glyph.\n*/\nexecGlyph = function(glyph, prepState) {\n // original point positions\n const xScale = prepState.ppem / prepState.font.unitsPerEm;\n const yScale = xScale;\n let components = glyph.components;\n let contours;\n let gZone;\n let state;\n\n State.prototype = prepState;\n if (!components) {\n state = new State('glyf', glyph.instructions);\n if (exports.DEBUG) {\n console.log('---EXEC GLYPH---');\n state.step = -1;\n }\n execComponent(glyph, state, xScale, yScale);\n gZone = state.gZone;\n } else {\n const font = prepState.font;\n gZone = [];\n contours = [];\n for (let i = 0; i < components.length; i++) {\n const c = components[i];\n const cg = font.glyphs.get(c.glyphIndex);\n\n state = new State('glyf', cg.instructions);\n\n if (exports.DEBUG) {\n console.log('---EXEC COMP ' + i + '---');\n state.step = -1;\n }\n\n execComponent(cg, state, xScale, yScale);\n // appends the computed points to the result array\n // post processes the component points\n const dx = Math.round(c.dx * xScale);\n const dy = Math.round(c.dy * yScale);\n const gz = state.gZone;\n const cc = state.contours;\n for (let pi = 0; pi < gz.length; pi++) {\n const p = gz[pi];\n p.xTouched = p.yTouched = false;\n p.xo = p.x = p.x + dx;\n p.yo = p.y = p.y + dy;\n }\n\n const gLen = gZone.length;\n gZone.push.apply(gZone, gz);\n for (let j = 0; j < cc.length; j++) {\n contours.push(cc[j] + gLen);\n }\n }\n\n if (glyph.instructions && !state.inhibitGridFit) {\n // the composite has instructions on its own\n state = new State('glyf', glyph.instructions);\n\n state.gZone = state.z0 = state.z1 = state.z2 = gZone;\n\n state.contours = contours;\n\n // note: HPZero cannot be used here, since\n // the point might be modified\n gZone.push(\n new HPoint(0, 0),\n new HPoint(Math.round(glyph.advanceWidth * xScale), 0)\n );\n\n if (exports.DEBUG) {\n console.log('---EXEC COMPOSITE---');\n state.step = -1;\n }\n\n exec(state);\n\n gZone.length -= 2;\n }\n }\n\n return gZone;\n};\n\n/*\n* Executes the hinting program for a component of a multi-component glyph\n* or of the glyph itself for a non-component glyph.\n*/\nexecComponent = function(glyph, state, xScale, yScale)\n{\n const points = glyph.points || [];\n const pLen = points.length;\n const gZone = state.gZone = state.z0 = state.z1 = state.z2 = [];\n const contours = state.contours = [];\n\n // Scales the original points and\n // makes copies for the hinted points.\n let cp; // current point\n for (let i = 0; i < pLen; i++) {\n cp = points[i];\n\n gZone[i] = new HPoint(\n cp.x * xScale,\n cp.y * yScale,\n cp.lastPointOfContour,\n cp.onCurve\n );\n }\n\n // Chain links the contours.\n let sp; // start point\n let np; // next point\n\n for (let i = 0; i < pLen; i++) {\n cp = gZone[i];\n\n if (!sp) {\n sp = cp;\n contours.push(i);\n }\n\n if (cp.lastPointOfContour) {\n cp.nextPointOnContour = sp;\n sp.prevPointOnContour = cp;\n sp = undefined;\n } else {\n np = gZone[i + 1];\n cp.nextPointOnContour = np;\n np.prevPointOnContour = cp;\n }\n }\n\n if (state.inhibitGridFit) return;\n\n if (exports.DEBUG) {\n console.log('PROCESSING GLYPH', state.stack);\n for (let i = 0; i < pLen; i++) {\n console.log(i, gZone[i].x, gZone[i].y);\n }\n }\n\n gZone.push(\n new HPoint(0, 0),\n new HPoint(Math.round(glyph.advanceWidth * xScale), 0)\n );\n\n exec(state);\n\n // Removes the extra points.\n gZone.length -= 2;\n\n if (exports.DEBUG) {\n console.log('FINISHED GLYPH', state.stack);\n for (let i = 0; i < pLen; i++) {\n console.log(i, gZone[i].x, gZone[i].y);\n }\n }\n};\n\n/*\n* Executes the program loaded in state.\n*/\nexec = function(state) {\n let prog = state.prog;\n\n if (!prog) return;\n\n const pLen = prog.length;\n let ins;\n\n for (state.ip = 0; state.ip < pLen; state.ip++) {\n if (exports.DEBUG) state.step++;\n ins = instructionTable[prog[state.ip]];\n\n if (!ins) {\n throw new Error(\n 'unknown instruction: 0x' +\n Number(prog[state.ip]).toString(16)\n );\n }\n\n ins(state);\n\n // very extensive debugging for each step\n /*\n if (exports.DEBUG) {\n var da;\n if (state.gZone) {\n da = [];\n for (let i = 0; i < state.gZone.length; i++)\n {\n da.push(i + ' ' +\n state.gZone[i].x * 64 + ' ' +\n state.gZone[i].y * 64 + ' ' +\n (state.gZone[i].xTouched ? 'x' : '') +\n (state.gZone[i].yTouched ? 'y' : '')\n );\n }\n console.log('GZ', da);\n }\n\n if (state.tZone) {\n da = [];\n for (let i = 0; i < state.tZone.length; i++) {\n da.push(i + ' ' +\n state.tZone[i].x * 64 + ' ' +\n state.tZone[i].y * 64 + ' ' +\n (state.tZone[i].xTouched ? 'x' : '') +\n (state.tZone[i].yTouched ? 'y' : '')\n );\n }\n console.log('TZ', da);\n }\n\n if (state.stack.length > 10) {\n console.log(\n state.stack.length,\n '...', state.stack.slice(state.stack.length - 10)\n );\n } else {\n console.log(state.stack.length, state.stack);\n }\n }\n */\n }\n};\n\n/*\n* Initializes the twilight zone.\n*\n* This is only done if a SZPx instruction\n* refers to the twilight zone.\n*/\nfunction initTZone(state)\n{\n const tZone = state.tZone = new Array(state.gZone.length);\n\n // no idea if this is actually correct...\n for (let i = 0; i < tZone.length; i++)\n {\n tZone[i] = new HPoint(0, 0);\n }\n}\n\n/*\n* Skips the instruction pointer ahead over an IF/ELSE block.\n* handleElse .. if true breaks on matching ELSE\n*/\nfunction skip(state, handleElse)\n{\n const prog = state.prog;\n let ip = state.ip;\n let nesting = 1;\n let ins;\n\n do {\n ins = prog[++ip];\n if (ins === 0x58) // IF\n nesting++;\n else if (ins === 0x59) // EIF\n nesting--;\n else if (ins === 0x40) // NPUSHB\n ip += prog[ip + 1] + 1;\n else if (ins === 0x41) // NPUSHW\n ip += 2 * prog[ip + 1] + 1;\n else if (ins >= 0xB0 && ins <= 0xB7) // PUSHB\n ip += ins - 0xB0 + 1;\n else if (ins >= 0xB8 && ins <= 0xBF) // PUSHW\n ip += (ins - 0xB8 + 1) * 2;\n else if (handleElse && nesting === 1 && ins === 0x1B) // ELSE\n break;\n } while (nesting > 0);\n\n state.ip = ip;\n}\n\n/*----------------------------------------------------------*\n* And then a lot of instructions... *\n*----------------------------------------------------------*/\n\n// SVTCA[a] Set freedom and projection Vectors To Coordinate Axis\n// 0x00-0x01\nfunction SVTCA(v, state) {\n if (exports.DEBUG) console.log(state.step, 'SVTCA[' + v.axis + ']');\n\n state.fv = state.pv = state.dpv = v;\n}\n\n// SPVTCA[a] Set Projection Vector to Coordinate Axis\n// 0x02-0x03\nfunction SPVTCA(v, state) {\n if (exports.DEBUG) console.log(state.step, 'SPVTCA[' + v.axis + ']');\n\n state.pv = state.dpv = v;\n}\n\n// SFVTCA[a] Set Freedom Vector to Coordinate Axis\n// 0x04-0x05\nfunction SFVTCA(v, state) {\n if (exports.DEBUG) console.log(state.step, 'SFVTCA[' + v.axis + ']');\n\n state.fv = v;\n}\n\n// SPVTL[a] Set Projection Vector To Line\n// 0x06-0x07\nfunction SPVTL(a, state) {\n const stack = state.stack;\n const p2i = stack.pop();\n const p1i = stack.pop();\n const p2 = state.z2[p2i];\n const p1 = state.z1[p1i];\n\n if (exports.DEBUG) console.log('SPVTL[' + a + ']', p2i, p1i);\n\n let dx;\n let dy;\n\n if (!a) {\n dx = p1.x - p2.x;\n dy = p1.y - p2.y;\n } else {\n dx = p2.y - p1.y;\n dy = p1.x - p2.x;\n }\n\n state.pv = state.dpv = getUnitVector(dx, dy);\n}\n\n// SFVTL[a] Set Freedom Vector To Line\n// 0x08-0x09\nfunction SFVTL(a, state) {\n const stack = state.stack;\n const p2i = stack.pop();\n const p1i = stack.pop();\n const p2 = state.z2[p2i];\n const p1 = state.z1[p1i];\n\n if (exports.DEBUG) console.log('SFVTL[' + a + ']', p2i, p1i);\n\n let dx;\n let dy;\n\n if (!a) {\n dx = p1.x - p2.x;\n dy = p1.y - p2.y;\n } else {\n dx = p2.y - p1.y;\n dy = p1.x - p2.x;\n }\n\n state.fv = getUnitVector(dx, dy);\n}\n\n// SPVFS[] Set Projection Vector From Stack\n// 0x0A\nfunction SPVFS(state) {\n const stack = state.stack;\n const y = stack.pop();\n const x = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SPVFS[]', y, x);\n\n state.pv = state.dpv = getUnitVector(x, y);\n}\n\n// SFVFS[] Set Freedom Vector From Stack\n// 0x0B\nfunction SFVFS(state) {\n const stack = state.stack;\n const y = stack.pop();\n const x = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SPVFS[]', y, x);\n\n state.fv = getUnitVector(x, y);\n}\n\n// GPV[] Get Projection Vector\n// 0x0C\nfunction GPV(state) {\n const stack = state.stack;\n const pv = state.pv;\n\n if (exports.DEBUG) console.log(state.step, 'GPV[]');\n\n stack.push(pv.x * 0x4000);\n stack.push(pv.y * 0x4000);\n}\n\n// GFV[] Get Freedom Vector\n// 0x0C\nfunction GFV(state) {\n const stack = state.stack;\n const fv = state.fv;\n\n if (exports.DEBUG) console.log(state.step, 'GFV[]');\n\n stack.push(fv.x * 0x4000);\n stack.push(fv.y * 0x4000);\n}\n\n// SFVTPV[] Set Freedom Vector To Projection Vector\n// 0x0E\nfunction SFVTPV(state) {\n state.fv = state.pv;\n\n if (exports.DEBUG) console.log(state.step, 'SFVTPV[]');\n}\n\n// ISECT[] moves point p to the InterSECTion of two lines\n// 0x0F\nfunction ISECT(state)\n{\n const stack = state.stack;\n const pa0i = stack.pop();\n const pa1i = stack.pop();\n const pb0i = stack.pop();\n const pb1i = stack.pop();\n const pi = stack.pop();\n const z0 = state.z0;\n const z1 = state.z1;\n const pa0 = z0[pa0i];\n const pa1 = z0[pa1i];\n const pb0 = z1[pb0i];\n const pb1 = z1[pb1i];\n const p = state.z2[pi];\n\n if (exports.DEBUG) console.log('ISECT[], ', pa0i, pa1i, pb0i, pb1i, pi);\n\n // math from\n // en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line\n\n const x1 = pa0.x;\n const y1 = pa0.y;\n const x2 = pa1.x;\n const y2 = pa1.y;\n const x3 = pb0.x;\n const y3 = pb0.y;\n const x4 = pb1.x;\n const y4 = pb1.y;\n\n const div = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);\n const f1 = x1 * y2 - y1 * x2;\n const f2 = x3 * y4 - y3 * x4;\n\n p.x = (f1 * (x3 - x4) - f2 * (x1 - x2)) / div;\n p.y = (f1 * (y3 - y4) - f2 * (y1 - y2)) / div;\n}\n\n// SRP0[] Set Reference Point 0\n// 0x10\nfunction SRP0(state) {\n state.rp0 = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SRP0[]', state.rp0);\n}\n\n// SRP1[] Set Reference Point 1\n// 0x11\nfunction SRP1(state) {\n state.rp1 = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SRP1[]', state.rp1);\n}\n\n// SRP1[] Set Reference Point 2\n// 0x12\nfunction SRP2(state) {\n state.rp2 = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SRP2[]', state.rp2);\n}\n\n// SZP0[] Set Zone Pointer 0\n// 0x13\nfunction SZP0(state) {\n const n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SZP0[]', n);\n\n state.zp0 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) initTZone(state);\n state.z0 = state.tZone;\n break;\n case 1 :\n state.z0 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n}\n\n// SZP1[] Set Zone Pointer 1\n// 0x14\nfunction SZP1(state) {\n const n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SZP1[]', n);\n\n state.zp1 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) initTZone(state);\n state.z1 = state.tZone;\n break;\n case 1 :\n state.z1 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n}\n\n// SZP2[] Set Zone Pointer 2\n// 0x15\nfunction SZP2(state) {\n const n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SZP2[]', n);\n\n state.zp2 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) initTZone(state);\n state.z2 = state.tZone;\n break;\n case 1 :\n state.z2 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n}\n\n// SZPS[] Set Zone PointerS\n// 0x16\nfunction SZPS(state) {\n const n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SZPS[]', n);\n\n state.zp0 = state.zp1 = state.zp2 = n;\n\n switch (n) {\n case 0:\n if (!state.tZone) initTZone(state);\n state.z0 = state.z1 = state.z2 = state.tZone;\n break;\n case 1 :\n state.z0 = state.z1 = state.z2 = state.gZone;\n break;\n default :\n throw new Error('Invalid zone pointer');\n }\n}\n\n// SLOOP[] Set LOOP variable\n// 0x17\nfunction SLOOP(state) {\n state.loop = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SLOOP[]', state.loop);\n}\n\n// RTG[] Round To Grid\n// 0x18\nfunction RTG(state) {\n if (exports.DEBUG) console.log(state.step, 'RTG[]');\n\n state.round = roundToGrid;\n}\n\n// RTHG[] Round To Half Grid\n// 0x19\nfunction RTHG(state) {\n if (exports.DEBUG) console.log(state.step, 'RTHG[]');\n\n state.round = roundToHalfGrid;\n}\n\n// SMD[] Set Minimum Distance\n// 0x1A\nfunction SMD(state) {\n const d = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SMD[]', d);\n\n state.minDis = d / 0x40;\n}\n\n// ELSE[] ELSE clause\n// 0x1B\nfunction ELSE(state) {\n // This instruction has been reached by executing a then branch\n // so it just skips ahead until matching EIF.\n //\n // In case the IF was negative the IF[] instruction already\n // skipped forward over the ELSE[]\n\n if (exports.DEBUG) console.log(state.step, 'ELSE[]');\n\n skip(state, false);\n}\n\n// JMPR[] JuMP Relative\n// 0x1C\nfunction JMPR(state) {\n const o = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'JMPR[]', o);\n\n // A jump by 1 would do nothing.\n state.ip += o - 1;\n}\n\n// SCVTCI[] Set Control Value Table Cut-In\n// 0x1D\nfunction SCVTCI(state) {\n const n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SCVTCI[]', n);\n\n state.cvCutIn = n / 0x40;\n}\n\n// DUP[] DUPlicate top stack element\n// 0x20\nfunction DUP(state) {\n const stack = state.stack;\n\n if (exports.DEBUG) console.log(state.step, 'DUP[]');\n\n stack.push(stack[stack.length - 1]);\n}\n\n// POP[] POP top stack element\n// 0x21\nfunction POP(state) {\n if (exports.DEBUG) console.log(state.step, 'POP[]');\n\n state.stack.pop();\n}\n\n// CLEAR[] CLEAR the stack\n// 0x22\nfunction CLEAR(state) {\n if (exports.DEBUG) console.log(state.step, 'CLEAR[]');\n\n state.stack.length = 0;\n}\n\n// SWAP[] SWAP the top two elements on the stack\n// 0x23\nfunction SWAP(state) {\n const stack = state.stack;\n\n const a = stack.pop();\n const b = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SWAP[]');\n\n stack.push(a);\n stack.push(b);\n}\n\n// DEPTH[] DEPTH of the stack\n// 0x24\nfunction DEPTH(state) {\n const stack = state.stack;\n\n if (exports.DEBUG) console.log(state.step, 'DEPTH[]');\n\n stack.push(stack.length);\n}\n\n// LOOPCALL[] LOOPCALL function\n// 0x2A\nfunction LOOPCALL(state) {\n const stack = state.stack;\n const fn = stack.pop();\n const c = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'LOOPCALL[]', fn, c);\n\n // saves callers program\n const cip = state.ip;\n const cprog = state.prog;\n\n state.prog = state.funcs[fn];\n\n // executes the function\n for (let i = 0; i < c; i++) {\n exec(state);\n\n if (exports.DEBUG) console.log(\n ++state.step,\n i + 1 < c ? 'next loopcall' : 'done loopcall',\n i\n );\n }\n\n // restores the callers program\n state.ip = cip;\n state.prog = cprog;\n}\n\n// CALL[] CALL function\n// 0x2B\nfunction CALL(state) {\n const fn = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'CALL[]', fn);\n\n // saves callers program\n const cip = state.ip;\n const cprog = state.prog;\n\n state.prog = state.funcs[fn];\n\n // executes the function\n exec(state);\n\n // restores the callers program\n state.ip = cip;\n state.prog = cprog;\n\n if (exports.DEBUG) console.log(++state.step, 'returning from', fn);\n}\n\n// CINDEX[] Copy the INDEXed element to the top of the stack\n// 0x25\nfunction CINDEX(state) {\n const stack = state.stack;\n const k = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'CINDEX[]', k);\n\n // In case of k == 1, it copies the last element after popping\n // thus stack.length - k.\n stack.push(stack[stack.length - k]);\n}\n\n// MINDEX[] Move the INDEXed element to the top of the stack\n// 0x26\nfunction MINDEX(state) {\n const stack = state.stack;\n const k = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'MINDEX[]', k);\n\n stack.push(stack.splice(stack.length - k, 1)[0]);\n}\n\n// FDEF[] Function DEFinition\n// 0x2C\nfunction FDEF(state) {\n if (state.env !== 'fpgm') throw new Error('FDEF not allowed here');\n const stack = state.stack;\n const prog = state.prog;\n let ip = state.ip;\n\n const fn = stack.pop();\n const ipBegin = ip;\n\n if (exports.DEBUG) console.log(state.step, 'FDEF[]', fn);\n\n while (prog[++ip] !== 0x2D);\n\n state.ip = ip;\n state.funcs[fn] = prog.slice(ipBegin + 1, ip);\n}\n\n// MDAP[a] Move Direct Absolute Point\n// 0x2E-0x2F\nfunction MDAP(round, state) {\n const pi = state.stack.pop();\n const p = state.z0[pi];\n const fv = state.fv;\n const pv = state.pv;\n\n if (exports.DEBUG) console.log(state.step, 'MDAP[' + round + ']', pi);\n\n let d = pv.distance(p, HPZero);\n\n if (round) d = state.round(d);\n\n fv.setRelative(p, HPZero, d, pv);\n fv.touch(p);\n\n state.rp0 = state.rp1 = pi;\n}\n\n// IUP[a] Interpolate Untouched Points through the outline\n// 0x30\nfunction IUP(v, state) {\n const z2 = state.z2;\n const pLen = z2.length - 2;\n let cp;\n let pp;\n let np;\n\n if (exports.DEBUG) console.log(state.step, 'IUP[' + v.axis + ']');\n\n for (let i = 0; i < pLen; i++) {\n cp = z2[i]; // current point\n\n // if this point has been touched go on\n if (v.touched(cp)) continue;\n\n pp = cp.prevTouched(v);\n\n // no point on the contour has been touched?\n if (pp === cp) continue;\n\n np = cp.nextTouched(v);\n\n if (pp === np) {\n // only one point on the contour has been touched\n // so simply moves the point like that\n\n v.setRelative(cp, cp, v.distance(pp, pp, false, true), v, true);\n }\n\n v.interpolate(cp, pp, np, v);\n }\n}\n\n// SHP[] SHift Point using reference point\n// 0x32-0x33\nfunction SHP(a, state) {\n const stack = state.stack;\n const rpi = a ? state.rp1 : state.rp2;\n const rp = (a ? state.z0 : state.z1)[rpi];\n const fv = state.fv;\n const pv = state.pv;\n let loop = state.loop;\n const z2 = state.z2;\n\n while (loop--)\n {\n const pi = stack.pop();\n const p = z2[pi];\n\n const d = pv.distance(rp, rp, false, true);\n fv.setRelative(p, p, d, pv);\n fv.touch(p);\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ?\n 'loop ' + (state.loop - loop) + ': ' :\n ''\n ) +\n 'SHP[' + (a ? 'rp1' : 'rp2') + ']', pi\n );\n }\n }\n\n state.loop = 1;\n}\n\n// SHC[] SHift Contour using reference point\n// 0x36-0x37\nfunction SHC(a, state) {\n const stack = state.stack;\n const rpi = a ? state.rp1 : state.rp2;\n const rp = (a ? state.z0 : state.z1)[rpi];\n const fv = state.fv;\n const pv = state.pv;\n const ci = stack.pop();\n const sp = state.z2[state.contours[ci]];\n let p = sp;\n\n if (exports.DEBUG) console.log(state.step, 'SHC[' + a + ']', ci);\n\n const d = pv.distance(rp, rp, false, true);\n\n do {\n if (p !== rp) fv.setRelative(p, p, d, pv);\n p = p.nextPointOnContour;\n } while (p !== sp);\n}\n\n// SHZ[] SHift Zone using reference point\n// 0x36-0x37\nfunction SHZ(a, state) {\n const stack = state.stack;\n const rpi = a ? state.rp1 : state.rp2;\n const rp = (a ? state.z0 : state.z1)[rpi];\n const fv = state.fv;\n const pv = state.pv;\n\n const e = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SHZ[' + a + ']', e);\n\n let z;\n switch (e) {\n case 0 : z = state.tZone; break;\n case 1 : z = state.gZone; break;\n default : throw new Error('Invalid zone');\n }\n\n let p;\n const d = pv.distance(rp, rp, false, true);\n const pLen = z.length - 2;\n for (let i = 0; i < pLen; i++)\n {\n p = z[i];\n fv.setRelative(p, p, d, pv);\n //if (p !== rp) fv.setRelative(p, p, d, pv);\n }\n}\n\n// SHPIX[] SHift point by a PIXel amount\n// 0x38\nfunction SHPIX(state) {\n const stack = state.stack;\n let loop = state.loop;\n const fv = state.fv;\n const d = stack.pop() / 0x40;\n const z2 = state.z2;\n\n while (loop--) {\n const pi = stack.pop();\n const p = z2[pi];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +\n 'SHPIX[]', pi, d\n );\n }\n\n fv.setRelative(p, p, d);\n fv.touch(p);\n }\n\n state.loop = 1;\n}\n\n// IP[] Interpolate Point\n// 0x39\nfunction IP(state) {\n const stack = state.stack;\n const rp1i = state.rp1;\n const rp2i = state.rp2;\n let loop = state.loop;\n const rp1 = state.z0[rp1i];\n const rp2 = state.z1[rp2i];\n const fv = state.fv;\n const pv = state.dpv;\n const z2 = state.z2;\n\n while (loop--) {\n const pi = stack.pop();\n const p = z2[pi];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +\n 'IP[]', pi, rp1i, '<->', rp2i\n );\n }\n\n fv.interpolate(p, rp1, rp2, pv);\n\n fv.touch(p);\n }\n\n state.loop = 1;\n}\n\n// MSIRP[a] Move Stack Indirect Relative Point\n// 0x3A-0x3B\nfunction MSIRP(a, state) {\n const stack = state.stack;\n const d = stack.pop() / 64;\n const pi = stack.pop();\n const p = state.z1[pi];\n const rp0 = state.z0[state.rp0];\n const fv = state.fv;\n const pv = state.pv;\n\n fv.setRelative(p, rp0, d, pv);\n fv.touch(p);\n\n if (exports.DEBUG) console.log(state.step, 'MSIRP[' + a + ']', d, pi);\n\n state.rp1 = state.rp0;\n state.rp2 = pi;\n if (a) state.rp0 = pi;\n}\n\n// ALIGNRP[] Align to reference point.\n// 0x3C\nfunction ALIGNRP(state) {\n const stack = state.stack;\n const rp0i = state.rp0;\n const rp0 = state.z0[rp0i];\n let loop = state.loop;\n const fv = state.fv;\n const pv = state.pv;\n const z1 = state.z1;\n\n while (loop--) {\n const pi = stack.pop();\n const p = z1[pi];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') +\n 'ALIGNRP[]', pi\n );\n }\n\n fv.setRelative(p, rp0, 0, pv);\n fv.touch(p);\n }\n\n state.loop = 1;\n}\n\n// RTG[] Round To Double Grid\n// 0x3D\nfunction RTDG(state) {\n if (exports.DEBUG) console.log(state.step, 'RTDG[]');\n\n state.round = roundToDoubleGrid;\n}\n\n// MIAP[a] Move Indirect Absolute Point\n// 0x3E-0x3F\nfunction MIAP(round, state) {\n const stack = state.stack;\n const n = stack.pop();\n const pi = stack.pop();\n const p = state.z0[pi];\n const fv = state.fv;\n const pv = state.pv;\n let cv = state.cvt[n];\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n 'MIAP[' + round + ']',\n n, '(', cv, ')', pi\n );\n }\n\n let d = pv.distance(p, HPZero);\n\n if (round) {\n if (Math.abs(d - cv) < state.cvCutIn) d = cv;\n\n d = state.round(d);\n }\n\n fv.setRelative(p, HPZero, d, pv);\n\n if (state.zp0 === 0) {\n p.xo = p.x;\n p.yo = p.y;\n }\n\n fv.touch(p);\n\n state.rp0 = state.rp1 = pi;\n}\n\n// NPUSB[] PUSH N Bytes\n// 0x40\nfunction NPUSHB(state) {\n const prog = state.prog;\n let ip = state.ip;\n const stack = state.stack;\n\n const n = prog[++ip];\n\n if (exports.DEBUG) console.log(state.step, 'NPUSHB[]', n);\n\n for (let i = 0; i < n; i++) stack.push(prog[++ip]);\n\n state.ip = ip;\n}\n\n// NPUSHW[] PUSH N Words\n// 0x41\nfunction NPUSHW(state) {\n let ip = state.ip;\n const prog = state.prog;\n const stack = state.stack;\n const n = prog[++ip];\n\n if (exports.DEBUG) console.log(state.step, 'NPUSHW[]', n);\n\n for (let i = 0; i < n; i++) {\n let w = (prog[++ip] << 8) | prog[++ip];\n if (w & 0x8000) w = -((w ^ 0xffff) + 1);\n stack.push(w);\n }\n\n state.ip = ip;\n}\n\n// WS[] Write Store\n// 0x42\nfunction WS(state) {\n const stack = state.stack;\n let store = state.store;\n\n if (!store) store = state.store = [];\n\n const v = stack.pop();\n const l = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'WS', v, l);\n\n store[l] = v;\n}\n\n// RS[] Read Store\n// 0x43\nfunction RS(state) {\n const stack = state.stack;\n const store = state.store;\n\n const l = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'RS', l);\n\n const v = (store && store[l]) || 0;\n\n stack.push(v);\n}\n\n// WCVTP[] Write Control Value Table in Pixel units\n// 0x44\nfunction WCVTP(state) {\n const stack = state.stack;\n\n const v = stack.pop();\n const l = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'WCVTP', v, l);\n\n state.cvt[l] = v / 0x40;\n}\n\n// RCVT[] Read Control Value Table entry\n// 0x45\nfunction RCVT(state) {\n const stack = state.stack;\n const cvte = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'RCVT', cvte);\n\n stack.push(state.cvt[cvte] * 0x40);\n}\n\n// GC[] Get Coordinate projected onto the projection vector\n// 0x46-0x47\nfunction GC(a, state) {\n const stack = state.stack;\n const pi = stack.pop();\n const p = state.z2[pi];\n\n if (exports.DEBUG) console.log(state.step, 'GC[' + a + ']', pi);\n\n stack.push(state.dpv.distance(p, HPZero, a, false) * 0x40);\n}\n\n// MD[a] Measure Distance\n// 0x49-0x4A\nfunction MD(a, state) {\n const stack = state.stack;\n const pi2 = stack.pop();\n const pi1 = stack.pop();\n const p2 = state.z1[pi2];\n const p1 = state.z0[pi1];\n const d = state.dpv.distance(p1, p2, a, a);\n\n if (exports.DEBUG) console.log(state.step, 'MD[' + a + ']', pi2, pi1, '->', d);\n\n state.stack.push(Math.round(d * 64));\n}\n\n// MPPEM[] Measure Pixels Per EM\n// 0x4B\nfunction MPPEM(state) {\n if (exports.DEBUG) console.log(state.step, 'MPPEM[]');\n state.stack.push(state.ppem);\n}\n\n// FLIPON[] set the auto FLIP Boolean to ON\n// 0x4D\nfunction FLIPON(state) {\n if (exports.DEBUG) console.log(state.step, 'FLIPON[]');\n state.autoFlip = true;\n}\n\n// LT[] Less Than\n// 0x50\nfunction LT(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'LT[]', e2, e1);\n\n stack.push(e1 < e2 ? 1 : 0);\n}\n\n// LTEQ[] Less Than or EQual\n// 0x53\nfunction LTEQ(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'LTEQ[]', e2, e1);\n\n stack.push(e1 <= e2 ? 1 : 0);\n}\n\n// GTEQ[] Greater Than\n// 0x52\nfunction GT(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'GT[]', e2, e1);\n\n stack.push(e1 > e2 ? 1 : 0);\n}\n\n// GTEQ[] Greater Than or EQual\n// 0x53\nfunction GTEQ(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'GTEQ[]', e2, e1);\n\n stack.push(e1 >= e2 ? 1 : 0);\n}\n\n// EQ[] EQual\n// 0x54\nfunction EQ(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'EQ[]', e2, e1);\n\n stack.push(e2 === e1 ? 1 : 0);\n}\n\n// NEQ[] Not EQual\n// 0x55\nfunction NEQ(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'NEQ[]', e2, e1);\n\n stack.push(e2 !== e1 ? 1 : 0);\n}\n\n// ODD[] ODD\n// 0x56\nfunction ODD(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'ODD[]', n);\n\n stack.push(Math.trunc(n) % 2 ? 1 : 0);\n}\n\n// EVEN[] EVEN\n// 0x57\nfunction EVEN(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'EVEN[]', n);\n\n stack.push(Math.trunc(n) % 2 ? 0 : 1);\n}\n\n// IF[] IF test\n// 0x58\nfunction IF(state) {\n let test = state.stack.pop();\n let ins;\n\n if (exports.DEBUG) console.log(state.step, 'IF[]', test);\n\n // if test is true it just continues\n // if not the ip is skipped until matching ELSE or EIF\n if (!test) {\n skip(state, true);\n\n if (exports.DEBUG) console.log(state.step, ins === 0x1B ? 'ELSE[]' : 'EIF[]');\n }\n}\n\n// EIF[] End IF\n// 0x59\nfunction EIF(state) {\n // this can be reached normally when\n // executing an else branch.\n // -> just ignore it\n\n if (exports.DEBUG) console.log(state.step, 'EIF[]');\n}\n\n// AND[] logical AND\n// 0x5A\nfunction AND(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'AND[]', e2, e1);\n\n stack.push(e2 && e1 ? 1 : 0);\n}\n\n// OR[] logical OR\n// 0x5B\nfunction OR(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'OR[]', e2, e1);\n\n stack.push(e2 || e1 ? 1 : 0);\n}\n\n// NOT[] logical NOT\n// 0x5C\nfunction NOT(state) {\n const stack = state.stack;\n const e = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'NOT[]', e);\n\n stack.push(e ? 0 : 1);\n}\n\n// DELTAP1[] DELTA exception P1\n// DELTAP2[] DELTA exception P2\n// DELTAP3[] DELTA exception P3\n// 0x5D, 0x71, 0x72\nfunction DELTAP123(b, state) {\n const stack = state.stack;\n const n = stack.pop();\n const fv = state.fv;\n const pv = state.pv;\n const ppem = state.ppem;\n const base = state.deltaBase + (b - 1) * 16;\n const ds = state.deltaShift;\n const z0 = state.z0;\n\n if (exports.DEBUG) console.log(state.step, 'DELTAP[' + b + ']', n, stack);\n\n for (let i = 0; i < n; i++) {\n const pi = stack.pop();\n const arg = stack.pop();\n const appem = base + ((arg & 0xF0) >> 4);\n if (appem !== ppem) continue;\n\n let mag = (arg & 0x0F) - 8;\n if (mag >= 0) mag++;\n if (exports.DEBUG) console.log(state.step, 'DELTAPFIX', pi, 'by', mag * ds);\n\n const p = z0[pi];\n fv.setRelative(p, p, mag * ds, pv);\n }\n}\n\n// SDB[] Set Delta Base in the graphics state\n// 0x5E\nfunction SDB(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SDB[]', n);\n\n state.deltaBase = n;\n}\n\n// SDS[] Set Delta Shift in the graphics state\n// 0x5F\nfunction SDS(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SDS[]', n);\n\n state.deltaShift = Math.pow(0.5, n);\n}\n\n// ADD[] ADD\n// 0x60\nfunction ADD(state) {\n const stack = state.stack;\n const n2 = stack.pop();\n const n1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'ADD[]', n2, n1);\n\n stack.push(n1 + n2);\n}\n\n// SUB[] SUB\n// 0x61\nfunction SUB(state) {\n const stack = state.stack;\n const n2 = stack.pop();\n const n1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SUB[]', n2, n1);\n\n stack.push(n1 - n2);\n}\n\n// DIV[] DIV\n// 0x62\nfunction DIV(state) {\n const stack = state.stack;\n const n2 = stack.pop();\n const n1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'DIV[]', n2, n1);\n\n stack.push(n1 * 64 / n2);\n}\n\n// MUL[] MUL\n// 0x63\nfunction MUL(state) {\n const stack = state.stack;\n const n2 = stack.pop();\n const n1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'MUL[]', n2, n1);\n\n stack.push(n1 * n2 / 64);\n}\n\n// ABS[] ABSolute value\n// 0x64\nfunction ABS(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'ABS[]', n);\n\n stack.push(Math.abs(n));\n}\n\n// NEG[] NEGate\n// 0x65\nfunction NEG(state) {\n const stack = state.stack;\n let n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'NEG[]', n);\n\n stack.push(-n);\n}\n\n// FLOOR[] FLOOR\n// 0x66\nfunction FLOOR(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'FLOOR[]', n);\n\n stack.push(Math.floor(n / 0x40) * 0x40);\n}\n\n// CEILING[] CEILING\n// 0x67\nfunction CEILING(state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'CEILING[]', n);\n\n stack.push(Math.ceil(n / 0x40) * 0x40);\n}\n\n// ROUND[ab] ROUND value\n// 0x68-0x6B\nfunction ROUND(dt, state) {\n const stack = state.stack;\n const n = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'ROUND[]');\n\n stack.push(state.round(n / 0x40) * 0x40);\n}\n\n// WCVTF[] Write Control Value Table in Funits\n// 0x70\nfunction WCVTF(state) {\n const stack = state.stack;\n const v = stack.pop();\n const l = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'WCVTF[]', v, l);\n\n state.cvt[l] = v * state.ppem / state.font.unitsPerEm;\n}\n\n// DELTAC1[] DELTA exception C1\n// DELTAC2[] DELTA exception C2\n// DELTAC3[] DELTA exception C3\n// 0x73, 0x74, 0x75\nfunction DELTAC123(b, state) {\n const stack = state.stack;\n const n = stack.pop();\n const ppem = state.ppem;\n const base = state.deltaBase + (b - 1) * 16;\n const ds = state.deltaShift;\n\n if (exports.DEBUG) console.log(state.step, 'DELTAC[' + b + ']', n, stack);\n\n for (let i = 0; i < n; i++) {\n const c = stack.pop();\n const arg = stack.pop();\n const appem = base + ((arg & 0xF0) >> 4);\n if (appem !== ppem) continue;\n\n let mag = (arg & 0x0F) - 8;\n if (mag >= 0) mag++;\n\n const delta = mag * ds;\n\n if (exports.DEBUG) console.log(state.step, 'DELTACFIX', c, 'by', delta);\n\n state.cvt[c] += delta;\n }\n}\n\n// SROUND[] Super ROUND\n// 0x76\nfunction SROUND(state) {\n let n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'SROUND[]', n);\n\n state.round = roundSuper;\n\n let period;\n\n switch (n & 0xC0) {\n case 0x00:\n period = 0.5;\n break;\n case 0x40:\n period = 1;\n break;\n case 0x80:\n period = 2;\n break;\n default:\n throw new Error('invalid SROUND value');\n }\n\n state.srPeriod = period;\n\n switch (n & 0x30) {\n case 0x00:\n state.srPhase = 0;\n break;\n case 0x10:\n state.srPhase = 0.25 * period;\n break;\n case 0x20:\n state.srPhase = 0.5 * period;\n break;\n case 0x30:\n state.srPhase = 0.75 * period;\n break;\n default: throw new Error('invalid SROUND value');\n }\n\n n &= 0x0F;\n\n if (n === 0) state.srThreshold = 0;\n else state.srThreshold = (n / 8 - 0.5) * period;\n}\n\n// S45ROUND[] Super ROUND 45 degrees\n// 0x77\nfunction S45ROUND(state) {\n let n = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'S45ROUND[]', n);\n\n state.round = roundSuper;\n\n let period;\n\n switch (n & 0xC0) {\n case 0x00:\n period = Math.sqrt(2) / 2;\n break;\n case 0x40:\n period = Math.sqrt(2);\n break;\n case 0x80:\n period = 2 * Math.sqrt(2);\n break;\n default:\n throw new Error('invalid S45ROUND value');\n }\n\n state.srPeriod = period;\n\n switch (n & 0x30) {\n case 0x00:\n state.srPhase = 0;\n break;\n case 0x10:\n state.srPhase = 0.25 * period;\n break;\n case 0x20:\n state.srPhase = 0.5 * period;\n break;\n case 0x30:\n state.srPhase = 0.75 * period;\n break;\n default:\n throw new Error('invalid S45ROUND value');\n }\n\n n &= 0x0F;\n\n if (n === 0) state.srThreshold = 0;\n else state.srThreshold = (n / 8 - 0.5) * period;\n}\n\n// ROFF[] Round Off\n// 0x7A\nfunction ROFF(state) {\n if (exports.DEBUG) console.log(state.step, 'ROFF[]');\n\n state.round = roundOff;\n}\n\n// RUTG[] Round Up To Grid\n// 0x7C\nfunction RUTG(state) {\n if (exports.DEBUG) console.log(state.step, 'RUTG[]');\n\n state.round = roundUpToGrid;\n}\n\n// RDTG[] Round Down To Grid\n// 0x7D\nfunction RDTG(state) {\n if (exports.DEBUG) console.log(state.step, 'RDTG[]');\n\n state.round = roundDownToGrid;\n}\n\n// SCANCTRL[] SCAN conversion ConTRoL\n// 0x85\nfunction SCANCTRL(state) {\n const n = state.stack.pop();\n\n // ignored by opentype.js\n\n if (exports.DEBUG) console.log(state.step, 'SCANCTRL[]', n);\n}\n\n// SDPVTL[a] Set Dual Projection Vector To Line\n// 0x86-0x87\nfunction SDPVTL(a, state) {\n const stack = state.stack;\n const p2i = stack.pop();\n const p1i = stack.pop();\n const p2 = state.z2[p2i];\n const p1 = state.z1[p1i];\n\n if (exports.DEBUG) console.log(state.step, 'SDPVTL[' + a + ']', p2i, p1i);\n\n let dx;\n let dy;\n\n if (!a) {\n dx = p1.x - p2.x;\n dy = p1.y - p2.y;\n } else {\n dx = p2.y - p1.y;\n dy = p1.x - p2.x;\n }\n\n state.dpv = getUnitVector(dx, dy);\n}\n\n// GETINFO[] GET INFOrmation\n// 0x88\nfunction GETINFO(state) {\n const stack = state.stack;\n const sel = stack.pop();\n let r = 0;\n\n if (exports.DEBUG) console.log(state.step, 'GETINFO[]', sel);\n\n // v35 as in no subpixel hinting\n if (sel & 0x01) r = 35;\n\n // TODO rotation and stretch currently not supported\n // and thus those GETINFO are always 0.\n\n // opentype.js is always gray scaling\n if (sel & 0x20) r |= 0x1000;\n\n stack.push(r);\n}\n\n// ROLL[] ROLL the top three stack elements\n// 0x8A\nfunction ROLL(state) {\n const stack = state.stack;\n const a = stack.pop();\n const b = stack.pop();\n const c = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'ROLL[]');\n\n stack.push(b);\n stack.push(a);\n stack.push(c);\n}\n\n// MAX[] MAXimum of top two stack elements\n// 0x8B\nfunction MAX(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'MAX[]', e2, e1);\n\n stack.push(Math.max(e1, e2));\n}\n\n// MIN[] MINimum of top two stack elements\n// 0x8C\nfunction MIN(state) {\n const stack = state.stack;\n const e2 = stack.pop();\n const e1 = stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'MIN[]', e2, e1);\n\n stack.push(Math.min(e1, e2));\n}\n\n// SCANTYPE[] SCANTYPE\n// 0x8D\nfunction SCANTYPE(state) {\n const n = state.stack.pop();\n // ignored by opentype.js\n if (exports.DEBUG) console.log(state.step, 'SCANTYPE[]', n);\n}\n\n// INSTCTRL[] INSTCTRL\n// 0x8D\nfunction INSTCTRL(state) {\n const s = state.stack.pop();\n let v = state.stack.pop();\n\n if (exports.DEBUG) console.log(state.step, 'INSTCTRL[]', s, v);\n\n switch (s) {\n case 1 : state.inhibitGridFit = !!v; return;\n case 2 : state.ignoreCvt = !!v; return;\n default: throw new Error('invalid INSTCTRL[] selector');\n }\n}\n\n// PUSHB[abc] PUSH Bytes\n// 0xB0-0xB7\nfunction PUSHB(n, state) {\n const stack = state.stack;\n const prog = state.prog;\n let ip = state.ip;\n\n if (exports.DEBUG) console.log(state.step, 'PUSHB[' + n + ']');\n\n for (let i = 0; i < n; i++) stack.push(prog[++ip]);\n\n state.ip = ip;\n}\n\n// PUSHW[abc] PUSH Words\n// 0xB8-0xBF\nfunction PUSHW(n, state) {\n let ip = state.ip;\n const prog = state.prog;\n const stack = state.stack;\n\n if (exports.DEBUG) console.log(state.ip, 'PUSHW[' + n + ']');\n\n for (let i = 0; i < n; i++) {\n let w = (prog[++ip] << 8) | prog[++ip];\n if (w & 0x8000) w = -((w ^ 0xffff) + 1);\n stack.push(w);\n }\n\n state.ip = ip;\n}\n\n// MDRP[abcde] Move Direct Relative Point\n// 0xD0-0xEF\n// (if indirect is 0)\n//\n// and\n//\n// MIRP[abcde] Move Indirect Relative Point\n// 0xE0-0xFF\n// (if indirect is 1)\n\nfunction MDRP_MIRP(indirect, setRp0, keepD, ro, dt, state) {\n const stack = state.stack;\n const cvte = indirect && stack.pop();\n const pi = stack.pop();\n const rp0i = state.rp0;\n const rp = state.z0[rp0i];\n const p = state.z1[pi];\n\n const md = state.minDis;\n const fv = state.fv;\n const pv = state.dpv;\n let od; // original distance\n let d; // moving distance\n let sign; // sign of distance\n let cv;\n\n d = od = pv.distance(p, rp, true, true);\n sign = d >= 0 ? 1 : -1; // Math.sign would be 0 in case of 0\n\n // TODO consider autoFlip\n d = Math.abs(d);\n\n if (indirect) {\n cv = state.cvt[cvte];\n\n if (ro && Math.abs(d - cv) < state.cvCutIn) d = cv;\n }\n\n if (keepD && d < md) d = md;\n\n if (ro) d = state.round(d);\n\n fv.setRelative(p, rp, sign * d, pv);\n fv.touch(p);\n\n if (exports.DEBUG) {\n console.log(\n state.step,\n (indirect ? 'MIRP[' : 'MDRP[') +\n (setRp0 ? 'M' : 'm') +\n (keepD ? '>' : '_') +\n (ro ? 'R' : '_') +\n (dt === 0 ? 'Gr' : (dt === 1 ? 'Bl' : (dt === 2 ? 'Wh' : ''))) +\n ']',\n indirect ?\n cvte + '(' + state.cvt[cvte] + ',' + cv + ')' :\n '',\n pi,\n '(d =', od, '->', sign * d, ')'\n );\n }\n\n state.rp1 = state.rp0;\n state.rp2 = pi;\n if (setRp0) state.rp0 = pi;\n}\n\n/*\n* The instruction table.\n*/\ninstructionTable = [\n /* 0x00 */ SVTCA.bind(undefined, yUnitVector),\n /* 0x01 */ SVTCA.bind(undefined, xUnitVector),\n /* 0x02 */ SPVTCA.bind(undefined, yUnitVector),\n /* 0x03 */ SPVTCA.bind(undefined, xUnitVector),\n /* 0x04 */ SFVTCA.bind(undefined, yUnitVector),\n /* 0x05 */ SFVTCA.bind(undefined, xUnitVector),\n /* 0x06 */ SPVTL.bind(undefined, 0),\n /* 0x07 */ SPVTL.bind(undefined, 1),\n /* 0x08 */ SFVTL.bind(undefined, 0),\n /* 0x09 */ SFVTL.bind(undefined, 1),\n /* 0x0A */ SPVFS,\n /* 0x0B */ SFVFS,\n /* 0x0C */ GPV,\n /* 0x0D */ GFV,\n /* 0x0E */ SFVTPV,\n /* 0x0F */ ISECT,\n /* 0x10 */ SRP0,\n /* 0x11 */ SRP1,\n /* 0x12 */ SRP2,\n /* 0x13 */ SZP0,\n /* 0x14 */ SZP1,\n /* 0x15 */ SZP2,\n /* 0x16 */ SZPS,\n /* 0x17 */ SLOOP,\n /* 0x18 */ RTG,\n /* 0x19 */ RTHG,\n /* 0x1A */ SMD,\n /* 0x1B */ ELSE,\n /* 0x1C */ JMPR,\n /* 0x1D */ SCVTCI,\n /* 0x1E */ undefined, // TODO SSWCI\n /* 0x1F */ undefined, // TODO SSW\n /* 0x20 */ DUP,\n /* 0x21 */ POP,\n /* 0x22 */ CLEAR,\n /* 0x23 */ SWAP,\n /* 0x24 */ DEPTH,\n /* 0x25 */ CINDEX,\n /* 0x26 */ MINDEX,\n /* 0x27 */ undefined, // TODO ALIGNPTS\n /* 0x28 */ undefined,\n /* 0x29 */ undefined, // TODO UTP\n /* 0x2A */ LOOPCALL,\n /* 0x2B */ CALL,\n /* 0x2C */ FDEF,\n /* 0x2D */ undefined, // ENDF (eaten by FDEF)\n /* 0x2E */ MDAP.bind(undefined, 0),\n /* 0x2F */ MDAP.bind(undefined, 1),\n /* 0x30 */ IUP.bind(undefined, yUnitVector),\n /* 0x31 */ IUP.bind(undefined, xUnitVector),\n /* 0x32 */ SHP.bind(undefined, 0),\n /* 0x33 */ SHP.bind(undefined, 1),\n /* 0x34 */ SHC.bind(undefined, 0),\n /* 0x35 */ SHC.bind(undefined, 1),\n /* 0x36 */ SHZ.bind(undefined, 0),\n /* 0x37 */ SHZ.bind(undefined, 1),\n /* 0x38 */ SHPIX,\n /* 0x39 */ IP,\n /* 0x3A */ MSIRP.bind(undefined, 0),\n /* 0x3B */ MSIRP.bind(undefined, 1),\n /* 0x3C */ ALIGNRP,\n /* 0x3D */ RTDG,\n /* 0x3E */ MIAP.bind(undefined, 0),\n /* 0x3F */ MIAP.bind(undefined, 1),\n /* 0x40 */ NPUSHB,\n /* 0x41 */ NPUSHW,\n /* 0x42 */ WS,\n /* 0x43 */ RS,\n /* 0x44 */ WCVTP,\n /* 0x45 */ RCVT,\n /* 0x46 */ GC.bind(undefined, 0),\n /* 0x47 */ GC.bind(undefined, 1),\n /* 0x48 */ undefined, // TODO SCFS\n /* 0x49 */ MD.bind(undefined, 0),\n /* 0x4A */ MD.bind(undefined, 1),\n /* 0x4B */ MPPEM,\n /* 0x4C */ undefined, // TODO MPS\n /* 0x4D */ FLIPON,\n /* 0x4E */ undefined, // TODO FLIPOFF\n /* 0x4F */ undefined, // TODO DEBUG\n /* 0x50 */ LT,\n /* 0x51 */ LTEQ,\n /* 0x52 */ GT,\n /* 0x53 */ GTEQ,\n /* 0x54 */ EQ,\n /* 0x55 */ NEQ,\n /* 0x56 */ ODD,\n /* 0x57 */ EVEN,\n /* 0x58 */ IF,\n /* 0x59 */ EIF,\n /* 0x5A */ AND,\n /* 0x5B */ OR,\n /* 0x5C */ NOT,\n /* 0x5D */ DELTAP123.bind(undefined, 1),\n /* 0x5E */ SDB,\n /* 0x5F */ SDS,\n /* 0x60 */ ADD,\n /* 0x61 */ SUB,\n /* 0x62 */ DIV,\n /* 0x63 */ MUL,\n /* 0x64 */ ABS,\n /* 0x65 */ NEG,\n /* 0x66 */ FLOOR,\n /* 0x67 */ CEILING,\n /* 0x68 */ ROUND.bind(undefined, 0),\n /* 0x69 */ ROUND.bind(undefined, 1),\n /* 0x6A */ ROUND.bind(undefined, 2),\n /* 0x6B */ ROUND.bind(undefined, 3),\n /* 0x6C */ undefined, // TODO NROUND[ab]\n /* 0x6D */ undefined, // TODO NROUND[ab]\n /* 0x6E */ undefined, // TODO NROUND[ab]\n /* 0x6F */ undefined, // TODO NROUND[ab]\n /* 0x70 */ WCVTF,\n /* 0x71 */ DELTAP123.bind(undefined, 2),\n /* 0x72 */ DELTAP123.bind(undefined, 3),\n /* 0x73 */ DELTAC123.bind(undefined, 1),\n /* 0x74 */ DELTAC123.bind(undefined, 2),\n /* 0x75 */ DELTAC123.bind(undefined, 3),\n /* 0x76 */ SROUND,\n /* 0x77 */ S45ROUND,\n /* 0x78 */ undefined, // TODO JROT[]\n /* 0x79 */ undefined, // TODO JROF[]\n /* 0x7A */ ROFF,\n /* 0x7B */ undefined,\n /* 0x7C */ RUTG,\n /* 0x7D */ RDTG,\n /* 0x7E */ POP, // actually SANGW, supposed to do only a pop though\n /* 0x7F */ POP, // actually AA, supposed to do only a pop though\n /* 0x80 */ undefined, // TODO FLIPPT\n /* 0x81 */ undefined, // TODO FLIPRGON\n /* 0x82 */ undefined, // TODO FLIPRGOFF\n /* 0x83 */ undefined,\n /* 0x84 */ undefined,\n /* 0x85 */ SCANCTRL,\n /* 0x86 */ SDPVTL.bind(undefined, 0),\n /* 0x87 */ SDPVTL.bind(undefined, 1),\n /* 0x88 */ GETINFO,\n /* 0x89 */ undefined, // TODO IDEF\n /* 0x8A */ ROLL,\n /* 0x8B */ MAX,\n /* 0x8C */ MIN,\n /* 0x8D */ SCANTYPE,\n /* 0x8E */ INSTCTRL,\n /* 0x8F */ undefined,\n /* 0x90 */ undefined,\n /* 0x91 */ undefined,\n /* 0x92 */ undefined,\n /* 0x93 */ undefined,\n /* 0x94 */ undefined,\n /* 0x95 */ undefined,\n /* 0x96 */ undefined,\n /* 0x97 */ undefined,\n /* 0x98 */ undefined,\n /* 0x99 */ undefined,\n /* 0x9A */ undefined,\n /* 0x9B */ undefined,\n /* 0x9C */ undefined,\n /* 0x9D */ undefined,\n /* 0x9E */ undefined,\n /* 0x9F */ undefined,\n /* 0xA0 */ undefined,\n /* 0xA1 */ undefined,\n /* 0xA2 */ undefined,\n /* 0xA3 */ undefined,\n /* 0xA4 */ undefined,\n /* 0xA5 */ undefined,\n /* 0xA6 */ undefined,\n /* 0xA7 */ undefined,\n /* 0xA8 */ undefined,\n /* 0xA9 */ undefined,\n /* 0xAA */ undefined,\n /* 0xAB */ undefined,\n /* 0xAC */ undefined,\n /* 0xAD */ undefined,\n /* 0xAE */ undefined,\n /* 0xAF */ undefined,\n /* 0xB0 */ PUSHB.bind(undefined, 1),\n /* 0xB1 */ PUSHB.bind(undefined, 2),\n /* 0xB2 */ PUSHB.bind(undefined, 3),\n /* 0xB3 */ PUSHB.bind(undefined, 4),\n /* 0xB4 */ PUSHB.bind(undefined, 5),\n /* 0xB5 */ PUSHB.bind(undefined, 6),\n /* 0xB6 */ PUSHB.bind(undefined, 7),\n /* 0xB7 */ PUSHB.bind(undefined, 8),\n /* 0xB8 */ PUSHW.bind(undefined, 1),\n /* 0xB9 */ PUSHW.bind(undefined, 2),\n /* 0xBA */ PUSHW.bind(undefined, 3),\n /* 0xBB */ PUSHW.bind(undefined, 4),\n /* 0xBC */ PUSHW.bind(undefined, 5),\n /* 0xBD */ PUSHW.bind(undefined, 6),\n /* 0xBE */ PUSHW.bind(undefined, 7),\n /* 0xBF */ PUSHW.bind(undefined, 8),\n /* 0xC0 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 0),\n /* 0xC1 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 1),\n /* 0xC2 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 2),\n /* 0xC3 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 3),\n /* 0xC4 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 0),\n /* 0xC5 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 1),\n /* 0xC6 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 2),\n /* 0xC7 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 3),\n /* 0xC8 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 0),\n /* 0xC9 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 1),\n /* 0xCA */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 2),\n /* 0xCB */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 3),\n /* 0xCC */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 0),\n /* 0xCD */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 1),\n /* 0xCE */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 2),\n /* 0xCF */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 3),\n /* 0xD0 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 0),\n /* 0xD1 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 1),\n /* 0xD2 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 2),\n /* 0xD3 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 3),\n /* 0xD4 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 0),\n /* 0xD5 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 1),\n /* 0xD6 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 2),\n /* 0xD7 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 3),\n /* 0xD8 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 0),\n /* 0xD9 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 1),\n /* 0xDA */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 2),\n /* 0xDB */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 3),\n /* 0xDC */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 0),\n /* 0xDD */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 1),\n /* 0xDE */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 2),\n /* 0xDF */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 3),\n /* 0xE0 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 0),\n /* 0xE1 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 1),\n /* 0xE2 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 2),\n /* 0xE3 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 3),\n /* 0xE4 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 0),\n /* 0xE5 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 1),\n /* 0xE6 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 2),\n /* 0xE7 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 3),\n /* 0xE8 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 0),\n /* 0xE9 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 1),\n /* 0xEA */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 2),\n /* 0xEB */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 3),\n /* 0xEC */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 0),\n /* 0xED */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 1),\n /* 0xEE */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 2),\n /* 0xEF */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 3),\n /* 0xF0 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 0),\n /* 0xF1 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 1),\n /* 0xF2 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 2),\n /* 0xF3 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 3),\n /* 0xF4 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 0),\n /* 0xF5 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 1),\n /* 0xF6 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 2),\n /* 0xF7 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 3),\n /* 0xF8 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 0),\n /* 0xF9 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 1),\n /* 0xFA */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 2),\n /* 0xFB */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 3),\n /* 0xFC */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 0),\n /* 0xFD */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 1),\n /* 0xFE */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 2),\n /* 0xFF */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 3)\n];\n\nexport default Hinting;\n\n/*****************************\n Mathematical Considerations\n******************************\n\nfv ... refers to freedom vector\npv ... refers to projection vector\nrp ... refers to reference point\np ... refers to to point being operated on\nd ... refers to distance\n\nSETRELATIVE:\n============\n\ncase freedom vector == x-axis:\n------------------------------\n\n (pv)\n .-'\n rpd .-'\n .-*\n d .-'90°'\n .-' '\n .-' '\n *-' ' b\n rp '\n '\n '\n p *----------*-------------- (fv)\n pm\n\n rpdx = rpx + d * pv.x\n rpdy = rpy + d * pv.y\n\n equation of line b\n\n y - rpdy = pvns * (x- rpdx)\n\n y = p.y\n\n x = rpdx + ( p.y - rpdy ) / pvns\n\n\ncase freedom vector == y-axis:\n------------------------------\n\n * pm\n |\\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\\n | \\ b\n | \\\n | \\\n | \\ .-' (pv)\n | 90° \\.-'\n | .-'* rpd\n | .-'\n * *-' d\n p rp\n\n rpdx = rpx + d * pv.x\n rpdy = rpy + d * pv.y\n\n equation of line b:\n pvns ... normal slope to pv\n\n y - rpdy = pvns * (x - rpdx)\n\n x = p.x\n\n y = rpdy + pvns * (p.x - rpdx)\n\n\n\ngeneric case:\n-------------\n\n\n .'(fv)\n .'\n .* pm\n .' !\n .' .\n .' !\n .' . b\n .' !\n * .\n p !\n 90° . ... (pv)\n ...-*-'''\n ...---''' rpd\n ...---''' d\n *--'''\n rp\n\n rpdx = rpx + d * pv.x\n rpdy = rpy + d * pv.y\n\n equation of line b:\n pvns... normal slope to pv\n\n y - rpdy = pvns * (x - rpdx)\n\n equation of freedom vector line:\n fvs ... slope of freedom vector (=fy/fx)\n\n y - py = fvs * (x - px)\n\n\n on pm both equations are true for same x/y\n\n y - rpdy = pvns * (x - rpdx)\n\n y - py = fvs * (x - px)\n\n form to y and set equal:\n\n pvns * (x - rpdx) + rpdy = fvs * (x - px) + py\n\n expand:\n\n pvns * x - pvns * rpdx + rpdy = fvs * x - fvs * px + py\n\n switch:\n\n fvs * x - fvs * px + py = pvns * x - pvns * rpdx + rpdy\n\n solve for x:\n\n fvs * x - pvns * x = fvs * px - pvns * rpdx - py + rpdy\n\n\n\n fvs * px - pvns * rpdx + rpdy - py\n x = -----------------------------------\n fvs - pvns\n\n and:\n\n y = fvs * (x - px) + py\n\n\n\nINTERPOLATE:\n============\n\nExamples of point interpolation.\n\nThe weight of the movement of the reference point gets bigger\nthe further the other reference point is away, thus the safest\noption (that is avoiding 0/0 divisions) is to weight the\noriginal distance of the other point by the sum of both distances.\n\nIf the sum of both distances is 0, then move the point by the\narithmetic average of the movement of both reference points.\n\n\n\n\n (+6)\n rp1o *---->*rp1\n . . (+12)\n . . rp2o *---------->* rp2\n . . . .\n . . . .\n . 10 20 . .\n |.........|...................| .\n . . .\n . . (+8) .\n po *------>*p .\n . . .\n . 12 . 24 .\n |...........|.......................|\n 36\n\n\n-------\n\n\n\n (+10)\n rp1o *-------->*rp1\n . . (-10)\n . . rp2 *<---------* rpo2\n . . . .\n . . . .\n . 10 . 30 . .\n |.........|.............................|\n . .\n . (+5) .\n po *--->* p .\n . . .\n . . 20 .\n |....|..............|\n 5 15\n\n\n-------\n\n\n (+10)\n rp1o *-------->*rp1\n . .\n . .\n rp2o *-------->*rp2\n\n\n (+10)\n po *-------->* p\n\n-------\n\n\n (+10)\n rp1o *-------->*rp1\n . .\n . .(+30)\n rp2o *---------------------------->*rp2\n\n\n (+25)\n po *----------------------->* p\n\n\n\nvim: set ts=4 sw=4 expandtab:\n*****/\n","/**\n * Converts a string into a list of tokens.\n */\n\n/**\n * Create a new token\n * @param {string} char a single char\n */\nfunction Token(char) {\n this.char = char;\n this.state = {};\n this.activeState = null;\n}\n\n/**\n * Create a new context range\n * @param {number} startIndex range start index\n * @param {number} endOffset range end index offset\n * @param {string} contextName owner context name\n */\nfunction ContextRange(startIndex, endOffset, contextName) {\n this.contextName = contextName;\n this.startIndex = startIndex;\n this.endOffset = endOffset;\n}\n\n/**\n * Check context start and end\n * @param {string} contextName a unique context name\n * @param {function} checkStart a predicate function the indicates a context's start\n * @param {function} checkEnd a predicate function the indicates a context's end\n */\nfunction ContextChecker(contextName, checkStart, checkEnd) {\n this.contextName = contextName;\n this.openRange = null;\n this.ranges = [];\n this.checkStart = checkStart;\n this.checkEnd = checkEnd;\n}\n\n/**\n * @typedef ContextParams\n * @type Object\n * @property {array} context context items\n * @property {number} currentIndex current item index\n */\n\n/**\n * Create a context params\n * @param {array} context a list of items\n * @param {number} currentIndex current item index\n */\nfunction ContextParams(context, currentIndex) {\n this.context = context;\n this.index = currentIndex;\n this.length = context.length;\n this.current = context[currentIndex];\n this.backtrack = context.slice(0, currentIndex);\n this.lookahead = context.slice(currentIndex + 1);\n}\n\n/**\n * Create an event instance\n * @param {string} eventId event unique id\n */\nfunction Event(eventId) {\n this.eventId = eventId;\n this.subscribers = [];\n}\n\n/**\n * Initialize a core events and auto subscribe required event handlers\n * @param {any} events an object that enlists core events handlers\n */\nfunction initializeCoreEvents(events) {\n const coreEvents = [\n 'start', 'end', 'next', 'newToken', 'contextStart',\n 'contextEnd', 'insertToken', 'removeToken', 'removeRange',\n 'replaceToken', 'replaceRange', 'composeRUD', 'updateContextsRanges'\n ];\n\n coreEvents.forEach(eventId => {\n Object.defineProperty(this.events, eventId, {\n value: new Event(eventId)\n });\n });\n\n if (!!events) {\n coreEvents.forEach(eventId => {\n const event = events[eventId];\n if (typeof event === 'function') {\n this.events[eventId].subscribe(event);\n }\n });\n }\n const requiresContextUpdate = [\n 'insertToken', 'removeToken', 'removeRange',\n 'replaceToken', 'replaceRange', 'composeRUD'\n ];\n requiresContextUpdate.forEach(eventId => {\n this.events[eventId].subscribe(\n this.updateContextsRanges\n );\n });\n}\n\n/**\n * Converts a string into a list of tokens\n * @param {any} events tokenizer core events\n */\nfunction Tokenizer(events) {\n this.tokens = [];\n this.registeredContexts = {};\n this.contextCheckers = [];\n this.events = {};\n this.registeredModifiers = [];\n\n initializeCoreEvents.call(this, events);\n}\n\n/**\n * Sets the state of a token, usually called by a state modifier.\n * @param {string} key state item key\n * @param {any} value state item value\n */\nToken.prototype.setState = function(key, value) {\n this.state[key] = value;\n this.activeState = { key, value: this.state[key] };\n return this.activeState;\n};\n\nToken.prototype.getState = function (stateId) {\n return this.state[stateId] || null;\n};\n\n/**\n * Checks if an index exists in the tokens list.\n * @param {number} index token index\n */\nTokenizer.prototype.inboundIndex = function(index) {\n return index >= 0 && index < this.tokens.length;\n};\n\n/**\n * Compose and apply a list of operations (replace, update, delete)\n * @param {array} RUDs replace, update and delete operations\n * TODO: Perf. Optimization (lengthBefore === lengthAfter ? dispatch once)\n */\nTokenizer.prototype.composeRUD = function (RUDs) {\n const silent = true;\n const state = RUDs.map(RUD => (\n this[RUD[0]].apply(this, RUD.slice(1).concat(silent))\n ));\n const hasFAILObject = obj => (\n typeof obj === 'object' &&\n obj.hasOwnProperty('FAIL')\n );\n if (state.every(hasFAILObject)) {\n return {\n FAIL: `composeRUD: one or more operations hasn't completed successfully`,\n report: state.filter(hasFAILObject)\n };\n }\n this.dispatch('composeRUD', [state.filter(op => !hasFAILObject(op))]);\n};\n\n/**\n * Replace a range of tokens with a list of tokens\n * @param {number} startIndex range start index\n * @param {number} offset range offset\n * @param {token} tokens a list of tokens to replace\n * @param {boolean} silent dispatch events and update context ranges\n */\nTokenizer.prototype.replaceRange = function (startIndex, offset, tokens, silent) {\n offset = offset !== null ? offset : this.tokens.length;\n const isTokenType = tokens.every(token => token instanceof Token);\n if (!isNaN(startIndex) && this.inboundIndex(startIndex) && isTokenType) {\n const replaced = this.tokens.splice.apply(\n this.tokens, [startIndex, offset].concat(tokens)\n );\n if (!silent) this.dispatch('replaceToken', [startIndex, offset, tokens]);\n return [replaced, tokens];\n } else {\n return { FAIL: 'replaceRange: invalid tokens or startIndex.' };\n }\n};\n\n/**\n * Replace a token with another token\n * @param {number} index token index\n * @param {token} token a token to replace\n * @param {boolean} silent dispatch events and update context ranges\n */\nTokenizer.prototype.replaceToken = function (index, token, silent) {\n if (!isNaN(index) && this.inboundIndex(index) && token instanceof Token) {\n const replaced = this.tokens.splice(index, 1, token);\n if (!silent) this.dispatch('replaceToken', [index, token]);\n return [replaced[0], token];\n } else {\n return { FAIL: 'replaceToken: invalid token or index.' };\n }\n};\n\n/**\n * Removes a range of tokens\n * @param {number} startIndex range start index\n * @param {number} offset range offset\n * @param {boolean} silent dispatch events and update context ranges\n */\nTokenizer.prototype.removeRange = function(startIndex, offset, silent) {\n offset = !isNaN(offset) ? offset : this.tokens.length;\n const tokens = this.tokens.splice(startIndex, offset);\n if (!silent) this.dispatch('removeRange', [tokens, startIndex, offset]);\n return tokens;\n};\n\n/**\n * Remove a token at a certain index\n * @param {number} index token index\n * @param {boolean} silent dispatch events and update context ranges\n */\nTokenizer.prototype.removeToken = function(index, silent) {\n if (!isNaN(index) && this.inboundIndex(index)) {\n const token = this.tokens.splice(index, 1);\n if (!silent) this.dispatch('removeToken', [token, index]);\n return token;\n } else {\n return { FAIL: 'removeToken: invalid token index.' };\n }\n};\n\n/**\n * Insert a list of tokens at a certain index\n * @param {array} tokens a list of tokens to insert\n * @param {number} index insert the list of tokens at index\n * @param {boolean} silent dispatch events and update context ranges\n */\nTokenizer.prototype.insertToken = function (tokens, index, silent) {\n const tokenType = tokens.every(\n token => token instanceof Token\n );\n if (tokenType) {\n this.tokens.splice.apply(\n this.tokens, [index, 0].concat(tokens)\n );\n if (!silent) this.dispatch('insertToken', [tokens, index]);\n return tokens;\n } else {\n return { FAIL: 'insertToken: invalid token(s).' };\n }\n};\n\n/**\n * A state modifier that is called on 'newToken' event\n * @param {string} modifierId state modifier id\n * @param {function} condition a predicate function that returns true or false\n * @param {function} modifier a function to update token state\n */\nTokenizer.prototype.registerModifier = function(modifierId, condition, modifier) {\n this.events.newToken.subscribe(function(token, contextParams) {\n const conditionParams = [token, contextParams];\n const canApplyModifier = (\n condition === null ||\n condition.apply(this, conditionParams) === true\n );\n const modifierParams = [token, contextParams];\n if (canApplyModifier) {\n let newStateValue = modifier.apply(this, modifierParams);\n token.setState(modifierId, newStateValue);\n }\n });\n this.registeredModifiers.push(modifierId);\n};\n\n/**\n * Subscribe a handler to an event\n * @param {function} eventHandler an event handler function\n */\nEvent.prototype.subscribe = function (eventHandler) {\n if (typeof eventHandler === 'function') {\n return ((this.subscribers.push(eventHandler)) - 1);\n } else {\n return { FAIL: `invalid '${this.eventId}' event handler`};\n }\n};\n\n/**\n * Unsubscribe an event handler\n * @param {string} subsId subscription id\n */\nEvent.prototype.unsubscribe = function (subsId) {\n this.subscribers.splice(subsId, 1);\n};\n\n/**\n * Sets context params current value index\n * @param {number} index context params current value index\n */\nContextParams.prototype.setCurrentIndex = function(index) {\n this.index = index;\n this.current = this.context[index];\n this.backtrack = this.context.slice(0, index);\n this.lookahead = this.context.slice(index + 1);\n};\n\n/**\n * Get an item at an offset from the current value\n * example (current value is 3):\n * 1 2 [3] 4 5 | items values\n * -2 -1 0 1 2 | offset values\n * @param {number} offset an offset from current value index\n */\nContextParams.prototype.get = function (offset) {\n switch (true) {\n case (offset === 0):\n return this.current;\n case (offset < 0 && Math.abs(offset) <= this.backtrack.length):\n return this.backtrack.slice(offset)[0];\n case (offset > 0 && offset <= this.lookahead.length):\n return this.lookahead[offset - 1];\n default:\n return null;\n }\n};\n\n/**\n * Converts a context range into a string value\n * @param {contextRange} range a context range\n */\nTokenizer.prototype.rangeToText = function (range) {\n if (range instanceof ContextRange) {\n return (\n this.getRangeTokens(range)\n .map(token => token.char).join('')\n );\n }\n};\n\n/**\n * Converts all tokens into a string\n */\nTokenizer.prototype.getText = function () {\n return this.tokens.map(token => token.char).join('');\n};\n\n/**\n * Get a context by name\n * @param {string} contextName context name to get\n */\nTokenizer.prototype.getContext = function (contextName) {\n let context = this.registeredContexts[contextName];\n return !!context ? context : null;\n};\n\n/**\n * Subscribes a new event handler to an event\n * @param {string} eventName event name to subscribe to\n * @param {function} eventHandler a function to be invoked on event\n */\nTokenizer.prototype.on = function(eventName, eventHandler) {\n const event = this.events[eventName];\n if (!!event) {\n return event.subscribe(eventHandler);\n } else {\n return null;\n }\n};\n\n/**\n * Dispatches an event\n * @param {string} eventName event name\n * @param {any} args event handler arguments\n */\nTokenizer.prototype.dispatch = function(eventName, args) {\n const event = this.events[eventName];\n if (event instanceof Event) {\n event.subscribers.forEach(subscriber => {\n subscriber.apply(this, args || []);\n });\n }\n};\n\n/**\n * Register a new context checker\n * @param {string} contextName a unique context name\n * @param {function} contextStartCheck a predicate function that returns true on context start\n * @param {function} contextEndCheck a predicate function that returns true on context end\n * TODO: call tokenize on registration to update context ranges with the new context.\n */\nTokenizer.prototype.registerContextChecker = function(contextName, contextStartCheck, contextEndCheck) {\n if (!!this.getContext(contextName)) return {\n FAIL:\n `context name '${contextName}' is already registered.`\n };\n if (typeof contextStartCheck !== 'function') return {\n FAIL:\n `missing context start check.`\n };\n if (typeof contextEndCheck !== 'function') return {\n FAIL:\n `missing context end check.`\n };\n const contextCheckers = new ContextChecker(\n contextName, contextStartCheck, contextEndCheck\n );\n this.registeredContexts[contextName] = contextCheckers;\n this.contextCheckers.push(contextCheckers);\n return contextCheckers;\n};\n\n/**\n * Gets a context range tokens\n * @param {contextRange} range a context range\n */\nTokenizer.prototype.getRangeTokens = function(range) {\n const endIndex = range.startIndex + range.endOffset;\n return [].concat(\n this.tokens\n .slice(range.startIndex, endIndex)\n );\n};\n\n/**\n * Gets the ranges of a context\n * @param {string} contextName context name\n */\nTokenizer.prototype.getContextRanges = function(contextName) {\n const context = this.getContext(contextName);\n if (!!context) {\n return context.ranges;\n } else {\n return { FAIL: `context checker '${contextName}' is not registered.` };\n }\n};\n\n/**\n * Resets context ranges to run context update\n */\nTokenizer.prototype.resetContextsRanges = function () {\n const registeredContexts = this.registeredContexts;\n for (const contextName in registeredContexts) {\n if (registeredContexts.hasOwnProperty(contextName)) {\n const context = registeredContexts[contextName];\n context.ranges = [];\n }\n }\n};\n\n/**\n * Updates context ranges\n */\nTokenizer.prototype.updateContextsRanges = function () {\n this.resetContextsRanges();\n const chars = this.tokens.map(token => token.char);\n for (let i = 0; i < chars.length; i++) {\n const contextParams = new ContextParams(chars, i);\n this.runContextCheck(contextParams);\n }\n this.dispatch('updateContextsRanges', [this.registeredContexts]);\n};\n\n/**\n * Sets the end offset of an open range\n * @param {number} offset range end offset\n * @param {string} contextName context name\n */\nTokenizer.prototype.setEndOffset = function (offset, contextName) {\n const startIndex = this.getContext(contextName).openRange.startIndex;\n let range = new ContextRange(startIndex, offset, contextName);\n const ranges = this.getContext(contextName).ranges;\n range.rangeId = `${contextName}.${ranges.length}`;\n ranges.push(range);\n this.getContext(contextName).openRange = null;\n return range;\n};\n\n/**\n * Runs a context check on the current context\n * @param {contextParams} contextParams current context params\n */\nTokenizer.prototype.runContextCheck = function(contextParams) {\n const index = contextParams.index;\n this.contextCheckers.forEach(contextChecker => {\n let contextName = contextChecker.contextName;\n let openRange = this.getContext(contextName).openRange;\n if (!openRange && contextChecker.checkStart(contextParams)) {\n openRange = new ContextRange(index, null, contextName);\n this.getContext(contextName).openRange = openRange;\n this.dispatch('contextStart', [contextName, index]);\n }\n if (!!openRange && contextChecker.checkEnd(contextParams)) {\n const offset = (index - openRange.startIndex) + 1;\n const range = this.setEndOffset(offset, contextName);\n this.dispatch('contextEnd', [contextName, range]);\n }\n });\n};\n\n/**\n * Converts a text into a list of tokens\n * @param {string} text a text to tokenize\n */\nTokenizer.prototype.tokenize = function (text) {\n this.tokens = [];\n this.resetContextsRanges();\n let chars = Array.from(text);\n this.dispatch('start');\n for (let i = 0; i < chars.length; i++) {\n const char = chars[i];\n const contextParams = new ContextParams(chars, i);\n this.dispatch('next', [contextParams]);\n this.runContextCheck(contextParams);\n let token = new Token(char);\n this.tokens.push(token);\n this.dispatch('newToken', [token, contextParams]);\n }\n this.dispatch('end', [this.tokens]);\n return this.tokens;\n};\n\nexport default Tokenizer;\nexport { Token, Event, ContextRange, ContextParams };\n","// ╭─┄┄┄────────────────────────┄─────────────────────────────────────────────╮\n// ┊ Character Class Assertions ┊ Checks if a char belongs to a certain class ┊\n// ╰─╾──────────────────────────┄─────────────────────────────────────────────╯\n// jscs:disable maximumLineLength\n/**\n * Check if a char is Arabic\n * @param {string} c a single char\n */\nexport function isArabicChar(c) {\n return /[\\u0600-\\u065F\\u066A-\\u06D2\\u06FA-\\u06FF]/.test(c);\n}\n\n/**\n * Check if a char is an isolated arabic char\n * @param {string} c a single char\n */\nexport function isIsolatedArabicChar(char) {\n return /[\\u0630\\u0690\\u0621\\u0631\\u0661\\u0671\\u0622\\u0632\\u0672\\u0692\\u06C2\\u0623\\u0673\\u0693\\u06C3\\u0624\\u0694\\u06C4\\u0625\\u0675\\u0695\\u06C5\\u06E5\\u0676\\u0696\\u06C6\\u0627\\u0677\\u0697\\u06C7\\u0648\\u0688\\u0698\\u06C8\\u0689\\u0699\\u06C9\\u068A\\u06CA\\u066B\\u068B\\u06CB\\u068C\\u068D\\u06CD\\u06FD\\u068E\\u06EE\\u06FE\\u062F\\u068F\\u06CF\\u06EF]/.test(char);\n}\n\n/**\n * Check if a char is an Arabic Tashkeel char\n * @param {string} c a single char\n */\nexport function isTashkeelArabicChar(char) {\n return /[\\u0600-\\u0605\\u060C-\\u060E\\u0610-\\u061B\\u061E\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED]/.test(char);\n}\n\n/**\n * Check if a char is Latin\n * @param {string} c a single char\n */\nexport function isLatinChar(c) {\n return /[A-z]/.test(c);\n}\n\n/**\n * Check if a char is whitespace char\n * @param {string} c a single char\n */\nexport function isWhiteSpace(c) {\n return /\\s/.test(c);\n}\n","/**\n * Query a feature by some of it's properties to lookup a glyph substitution.\n */\n\nimport { ContextParams } from '../tokenizer';\nimport { isTashkeelArabicChar } from '../char';\n\n/**\n * Create feature query instance\n * @param {Font} font opentype font instance\n */\nfunction FeatureQuery(font) {\n this.font = font;\n this.features = {};\n}\n\n/**\n * @typedef SubstitutionAction\n * @type Object\n * @property {number} id substitution type\n * @property {string} tag feature tag\n * @property {any} substitution substitution value(s)\n */\n\n/**\n * Create a substitution action instance\n * @param {SubstitutionAction} action\n */\nfunction SubstitutionAction(action) {\n this.id = action.id;\n this.tag = action.tag;\n this.substitution = action.substitution;\n}\n\n/**\n * Lookup a coverage table\n * @param {number} glyphIndex glyph index\n * @param {CoverageTable} coverage coverage table\n */\nfunction lookupCoverage(glyphIndex, coverage) {\n if (!glyphIndex) return -1;\n switch (coverage.format) {\n case 1:\n return coverage.glyphs.indexOf(glyphIndex);\n\n case 2:\n let ranges = coverage.ranges;\n for (let i = 0; i < ranges.length; i++) {\n const range = ranges[i];\n if (glyphIndex >= range.start && glyphIndex <= range.end) {\n let offset = glyphIndex - range.start;\n return range.index + offset;\n }\n }\n break;\n default:\n return -1; // not found\n }\n return -1;\n}\n\n/**\n * Handle a single substitution - format 1\n * @param {ContextParams} contextParams context params to lookup\n */\nfunction singleSubstitutionFormat1(glyphIndex, subtable) {\n let substituteIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (substituteIndex === -1) return null;\n return glyphIndex + subtable.deltaGlyphId;\n}\n\n/**\n * Handle a single substitution - format 2\n * @param {ContextParams} contextParams context params to lookup\n */\nfunction singleSubstitutionFormat2(glyphIndex, subtable) {\n let substituteIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (substituteIndex === -1) return null;\n return subtable.substitute[substituteIndex];\n}\n\n/**\n * Lookup a list of coverage tables\n * @param {any} coverageList a list of coverage tables\n * @param {ContextParams} contextParams context params to lookup\n */\nfunction lookupCoverageList(coverageList, contextParams) {\n let lookupList = [];\n for (let i = 0; i < coverageList.length; i++) {\n const coverage = coverageList[i];\n let glyphIndex = contextParams.current;\n glyphIndex = Array.isArray(glyphIndex) ? glyphIndex[0] : glyphIndex;\n const lookupIndex = lookupCoverage(glyphIndex, coverage);\n if (lookupIndex !== -1) {\n lookupList.push(lookupIndex);\n }\n }\n if (lookupList.length !== coverageList.length) return -1;\n return lookupList;\n}\n\n/**\n * Handle chaining context substitution - format 3\n * @param {ContextParams} contextParams context params to lookup\n */\nfunction chainingSubstitutionFormat3(contextParams, subtable) {\n const lookupsCount = (\n subtable.inputCoverage.length +\n subtable.lookaheadCoverage.length +\n subtable.backtrackCoverage.length\n );\n if (contextParams.context.length < lookupsCount) return [];\n // INPUT LOOKUP //\n let inputLookups = lookupCoverageList(\n subtable.inputCoverage, contextParams\n );\n if (inputLookups === -1) return [];\n // LOOKAHEAD LOOKUP //\n const lookaheadOffset = subtable.inputCoverage.length - 1;\n if (contextParams.lookahead.length < subtable.lookaheadCoverage.length) return [];\n let lookaheadContext = contextParams.lookahead.slice(lookaheadOffset);\n while (lookaheadContext.length && isTashkeelArabicChar(lookaheadContext[0].char)) {\n lookaheadContext.shift();\n }\n const lookaheadParams = new ContextParams(lookaheadContext, 0);\n let lookaheadLookups = lookupCoverageList(\n subtable.lookaheadCoverage, lookaheadParams\n );\n // BACKTRACK LOOKUP //\n let backtrackContext = [].concat(contextParams.backtrack);\n backtrackContext.reverse();\n while (backtrackContext.length && isTashkeelArabicChar(backtrackContext[0].char)) {\n backtrackContext.shift();\n }\n if (backtrackContext.length < subtable.backtrackCoverage.length) return [];\n const backtrackParams = new ContextParams(backtrackContext, 0);\n let backtrackLookups = lookupCoverageList(\n subtable.backtrackCoverage, backtrackParams\n );\n const contextRulesMatch = (\n inputLookups.length === subtable.inputCoverage.length &&\n lookaheadLookups.length === subtable.lookaheadCoverage.length &&\n backtrackLookups.length === subtable.backtrackCoverage.length\n );\n let substitutions = [];\n if (contextRulesMatch) {\n for (let i = 0; i < subtable.lookupRecords.length; i++) {\n const lookupRecord = subtable.lookupRecords[i];\n const lookupListIndex = lookupRecord.lookupListIndex;\n const lookupTable = this.getLookupByIndex(lookupListIndex);\n for (let s = 0; s < lookupTable.subtables.length; s++) {\n const subtable = lookupTable.subtables[s];\n const lookup = this.getLookupMethod(lookupTable, subtable);\n const substitutionType = this.getSubstitutionType(lookupTable, subtable);\n if (substitutionType === '12') {\n for (let n = 0; n < inputLookups.length; n++) {\n const glyphIndex = contextParams.get(n);\n const substitution = lookup(glyphIndex);\n if (substitution) substitutions.push(substitution);\n }\n }\n }\n }\n }\n return substitutions;\n}\n\n/**\n * Handle ligature substitution - format 1\n * @param {ContextParams} contextParams context params to lookup\n */\nfunction ligatureSubstitutionFormat1(contextParams, subtable) {\n // COVERAGE LOOKUP //\n let glyphIndex = contextParams.current;\n let ligSetIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (ligSetIndex === -1) return null;\n // COMPONENTS LOOKUP\n // (!) note, components are ordered in the written direction.\n let ligature;\n let ligatureSet = subtable.ligatureSets[ligSetIndex];\n for (let s = 0; s < ligatureSet.length; s++) {\n ligature = ligatureSet[s];\n for (let l = 0; l < ligature.components.length; l++) {\n const lookaheadItem = contextParams.lookahead[l];\n const component = ligature.components[l];\n if (lookaheadItem !== component) break;\n if (l === ligature.components.length - 1) return ligature;\n }\n }\n return null;\n}\n\n/**\n * Handle decomposition substitution - format 1\n * @param {number} glyphIndex glyph index\n * @param {any} subtable subtable\n */\nfunction decompositionSubstitutionFormat1(glyphIndex, subtable) {\n let substituteIndex = lookupCoverage(glyphIndex, subtable.coverage);\n if (substituteIndex === -1) return null;\n return subtable.sequences[substituteIndex];\n}\n\n/**\n * Get default script features indexes\n */\nFeatureQuery.prototype.getDefaultScriptFeaturesIndexes = function () {\n const scripts = this.font.tables.gsub.scripts;\n for (let s = 0; s < scripts.length; s++) {\n const script = scripts[s];\n if (script.tag === 'DFLT') return (\n script.script.defaultLangSys.featureIndexes\n );\n }\n return [];\n};\n\n/**\n * Get feature indexes of a specific script\n * @param {string} scriptTag script tag\n */\nFeatureQuery.prototype.getScriptFeaturesIndexes = function(scriptTag) {\n const tables = this.font.tables;\n if (!tables.gsub) return [];\n if (!scriptTag) return this.getDefaultScriptFeaturesIndexes();\n const scripts = this.font.tables.gsub.scripts;\n for (let i = 0; i < scripts.length; i++) {\n const script = scripts[i];\n if (script.tag === scriptTag && script.script.defaultLangSys) {\n return script.script.defaultLangSys.featureIndexes;\n } else {\n let langSysRecords = script.langSysRecords;\n if (!!langSysRecords) {\n for (let j = 0; j < langSysRecords.length; j++) {\n const langSysRecord = langSysRecords[j];\n if (langSysRecord.tag === scriptTag) {\n let langSys = langSysRecord.langSys;\n return langSys.featureIndexes;\n }\n }\n }\n }\n }\n return this.getDefaultScriptFeaturesIndexes();\n};\n\n/**\n * Map a feature tag to a gsub feature\n * @param {any} features gsub features\n * @param {string} scriptTag script tag\n */\nFeatureQuery.prototype.mapTagsToFeatures = function (features, scriptTag) {\n let tags = {};\n for (let i = 0; i < features.length; i++) {\n const tag = features[i].tag;\n const feature = features[i].feature;\n tags[tag] = feature;\n }\n this.features[scriptTag].tags = tags;\n};\n\n/**\n * Get features of a specific script\n * @param {string} scriptTag script tag\n */\nFeatureQuery.prototype.getScriptFeatures = function (scriptTag) {\n let features = this.features[scriptTag];\n if (this.features.hasOwnProperty(scriptTag)) return features;\n const featuresIndexes = this.getScriptFeaturesIndexes(scriptTag);\n if (!featuresIndexes) return null;\n const gsub = this.font.tables.gsub;\n features = featuresIndexes.map(index => gsub.features[index]);\n this.features[scriptTag] = features;\n this.mapTagsToFeatures(features, scriptTag);\n return features;\n};\n\n/**\n * Get substitution type\n * @param {any} lookupTable lookup table\n * @param {any} subtable subtable\n */\nFeatureQuery.prototype.getSubstitutionType = function(lookupTable, subtable) {\n const lookupType = lookupTable.lookupType.toString();\n const substFormat = subtable.substFormat.toString();\n return lookupType + substFormat;\n};\n\n/**\n * Get lookup method\n * @param {any} lookupTable lookup table\n * @param {any} subtable subtable\n */\nFeatureQuery.prototype.getLookupMethod = function(lookupTable, subtable) {\n let substitutionType = this.getSubstitutionType(lookupTable, subtable);\n switch (substitutionType) {\n case '11':\n return glyphIndex => singleSubstitutionFormat1.apply(\n this, [glyphIndex, subtable]\n );\n case '12':\n return glyphIndex => singleSubstitutionFormat2.apply(\n this, [glyphIndex, subtable]\n );\n case '63':\n return contextParams => chainingSubstitutionFormat3.apply(\n this, [contextParams, subtable]\n );\n case '41':\n return contextParams => ligatureSubstitutionFormat1.apply(\n this, [contextParams, subtable]\n );\n case '21':\n return glyphIndex => decompositionSubstitutionFormat1.apply(\n this, [glyphIndex, subtable]\n );\n default:\n throw new Error(\n `lookupType: ${lookupTable.lookupType} - ` +\n `substFormat: ${subtable.substFormat} ` +\n `is not yet supported`\n );\n }\n};\n\n/**\n * [ LOOKUP TYPES ]\n * -------------------------------\n * Single 1;\n * Multiple 2;\n * Alternate 3;\n * Ligature 4;\n * Context 5;\n * ChainingContext 6;\n * ExtensionSubstitution 7;\n * ReverseChainingContext 8;\n * -------------------------------\n *\n */\n\n/**\n * @typedef FQuery\n * @type Object\n * @param {string} tag feature tag\n * @param {string} script feature script\n * @param {ContextParams} contextParams context params\n */\n\n/**\n * Lookup a feature using a query parameters\n * @param {FQuery} query feature query\n */\nFeatureQuery.prototype.lookupFeature = function (query) {\n let contextParams = query.contextParams;\n let currentIndex = contextParams.index;\n const feature = this.getFeature({\n tag: query.tag, script: query.script\n });\n if (!feature) return new Error(\n `font '${this.font.names.fullName.en}' ` +\n `doesn't support feature '${query.tag}' ` +\n `for script '${query.script}'.`\n );\n const lookups = this.getFeatureLookups(feature);\n const substitutions = [].concat(contextParams.context);\n for (let l = 0; l < lookups.length; l++) {\n const lookupTable = lookups[l];\n const subtables = this.getLookupSubtables(lookupTable);\n for (let s = 0; s < subtables.length; s++) {\n const subtable = subtables[s];\n const substType = this.getSubstitutionType(lookupTable, subtable);\n const lookup = this.getLookupMethod(lookupTable, subtable);\n let substitution;\n switch (substType) {\n case '11':\n substitution = lookup(contextParams.current);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 11, tag: query.tag, substitution\n }));\n }\n break;\n case '12':\n substitution = lookup(contextParams.current);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 12, tag: query.tag, substitution\n }));\n }\n break;\n case '63':\n substitution = lookup(contextParams);\n if (Array.isArray(substitution) && substitution.length) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 63, tag: query.tag, substitution\n }));\n }\n break;\n case '41':\n substitution = lookup(contextParams);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 41, tag: query.tag, substitution\n }));\n }\n break;\n case '21':\n substitution = lookup(contextParams.current);\n if (substitution) {\n substitutions.splice(currentIndex, 1, new SubstitutionAction({\n id: 21, tag: query.tag, substitution\n }));\n }\n break;\n }\n contextParams = new ContextParams(substitutions, currentIndex);\n if (Array.isArray(substitution) && !substitution.length) continue;\n substitution = null;\n }\n }\n return substitutions.length ? substitutions : null;\n};\n\n/**\n * Checks if a font supports a specific features\n * @param {FQuery} query feature query object\n */\nFeatureQuery.prototype.supports = function (query) {\n if (!query.script) return false;\n this.getScriptFeatures(query.script);\n const supportedScript = this.features.hasOwnProperty(query.script);\n if (!query.tag) return supportedScript;\n const supportedFeature = (\n this.features[query.script].some(feature => feature.tag === query.tag)\n );\n return supportedScript && supportedFeature;\n};\n\n/**\n * Get lookup table subtables\n * @param {any} lookupTable lookup table\n */\nFeatureQuery.prototype.getLookupSubtables = function (lookupTable) {\n return lookupTable.subtables || null;\n};\n\n/**\n * Get lookup table by index\n * @param {number} index lookup table index\n */\nFeatureQuery.prototype.getLookupByIndex = function (index) {\n const lookups = this.font.tables.gsub.lookups;\n return lookups[index] || null;\n};\n\n/**\n * Get lookup tables for a feature\n * @param {string} feature\n */\nFeatureQuery.prototype.getFeatureLookups = function (feature) {\n // TODO: memoize\n return feature.lookupListIndexes.map(this.getLookupByIndex.bind(this));\n};\n\n/**\n * Query a feature by it's properties\n * @param {any} query an object that describes the properties of a query\n */\nFeatureQuery.prototype.getFeature = function getFeature(query) {\n if (!this.font) return { FAIL: `No font was found`};\n if (!this.features.hasOwnProperty(query.script)) {\n this.getScriptFeatures(query.script);\n }\n const scriptFeatures = this.features[query.script];\n if (!scriptFeatures) return (\n { FAIL: `No feature for script ${query.script}`}\n );\n if (!scriptFeatures.tags[query.tag]) return null;\n return this.features[query.script].tags[query.tag];\n};\n\nexport default FeatureQuery;\nexport { FeatureQuery, SubstitutionAction };\n","/**\n * Arabic word context checkers\n */\n\nimport { isArabicChar } from '../../../char';\n\nfunction arabicWordStartCheck(contextParams) {\n const char = contextParams.current;\n const prevChar = contextParams.get(-1);\n return (\n // ? arabic first char\n (prevChar === null && isArabicChar(char)) ||\n // ? arabic char preceded with a non arabic char\n (!isArabicChar(prevChar) && isArabicChar(char))\n );\n}\n\nfunction arabicWordEndCheck(contextParams) {\n const nextChar = contextParams.get(1);\n return (\n // ? last arabic char\n (nextChar === null) ||\n // ? next char is not arabic\n (!isArabicChar(nextChar))\n );\n}\n\nexport default {\n startCheck: arabicWordStartCheck,\n endCheck: arabicWordEndCheck\n};\n","/**\n * Arabic sentence context checkers\n */\n\nimport { isArabicChar, isWhiteSpace, isTashkeelArabicChar } from '../../../char';\n\nfunction arabicSentenceStartCheck(contextParams) {\n const char = contextParams.current;\n const prevChar = contextParams.get(-1);\n return (\n // ? an arabic char preceded with a non arabic char\n (isArabicChar(char) || isTashkeelArabicChar(char)) &&\n !isArabicChar(prevChar)\n );\n}\n\nfunction arabicSentenceEndCheck(contextParams) {\n const nextChar = contextParams.get(1);\n switch (true) {\n case nextChar === null:\n return true;\n case (!isArabicChar(nextChar) && !isTashkeelArabicChar(nextChar)):\n const nextIsWhitespace = isWhiteSpace(nextChar);\n if (!nextIsWhitespace) return true;\n if (nextIsWhitespace) {\n let arabicCharAhead = false;\n arabicCharAhead = (\n contextParams.lookahead.some(\n c => isArabicChar(c) || isTashkeelArabicChar(c)\n )\n );\n if (!arabicCharAhead) return true;\n }\n break;\n default:\n return false;\n }\n}\n\nexport default {\n startCheck: arabicSentenceStartCheck,\n endCheck: arabicSentenceEndCheck\n};\n","import { SubstitutionAction } from './featureQuery';\n\n/**\n * Apply single substitution format 1\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\nfunction singleSubstitutionFormat1(action, tokens, index) {\n tokens[index].setState(action.tag, action.substitution);\n}\n\n/**\n * Apply single substitution format 2\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\nfunction singleSubstitutionFormat2(action, tokens, index) {\n tokens[index].setState(action.tag, action.substitution);\n}\n\n/**\n * Apply chaining context substitution format 3\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\nfunction chainingSubstitutionFormat3(action, tokens, index) {\n action.substitution.forEach((subst, offset) => {\n const token = tokens[index + offset];\n token.setState(action.tag, subst);\n });\n}\n\n/**\n * Apply ligature substitution format 1\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\nfunction ligatureSubstitutionFormat1(action, tokens, index) {\n let token = tokens[index];\n token.setState(action.tag, action.substitution.ligGlyph);\n const compsCount = action.substitution.components.length;\n for (let i = 0; i < compsCount; i++) {\n token = tokens[index + i + 1];\n token.setState('deleted', true);\n }\n}\n\n/**\n * Supported substitutions\n */\nconst SUBSTITUTIONS = {\n 11: singleSubstitutionFormat1,\n 12: singleSubstitutionFormat2,\n 63: chainingSubstitutionFormat3,\n 41: ligatureSubstitutionFormat1\n};\n\n/**\n * Apply substitutions to a list of tokens\n * @param {Array} substitutions substitutions\n * @param {any} tokens a list of tokens\n * @param {number} index token index\n */\nfunction applySubstitution(action, tokens, index) {\n if (action instanceof SubstitutionAction && SUBSTITUTIONS[action.id]) {\n SUBSTITUTIONS[action.id](action, tokens, index);\n }\n}\n\nexport default applySubstitution;\n","/**\n * Apply Arabic presentation forms to a range of tokens\n */\n\nimport { ContextParams } from '../../tokenizer';\nimport { isIsolatedArabicChar, isTashkeelArabicChar } from '../../char';\nimport { SubstitutionAction } from '../featureQuery';\nimport applySubstitution from '../applySubstitution';\n\n/**\n * Check if a char can be connected to it's preceding char\n * @param {ContextParams} charContextParams context params of a char\n */\nfunction willConnectPrev(charContextParams) {\n let backtrack = [].concat(charContextParams.backtrack);\n for (let i = backtrack.length - 1; i >= 0; i--) {\n const prevChar = backtrack[i];\n const isolated = isIsolatedArabicChar(prevChar);\n const tashkeel = isTashkeelArabicChar(prevChar);\n if (!isolated && !tashkeel) return true;\n if (isolated) return false;\n }\n return false;\n}\n\n/**\n * Check if a char can be connected to it's proceeding char\n * @param {ContextParams} charContextParams context params of a char\n */\nfunction willConnectNext(charContextParams) {\n if (isIsolatedArabicChar(charContextParams.current)) return false;\n for (let i = 0; i < charContextParams.lookahead.length; i++) {\n const nextChar = charContextParams.lookahead[i];\n const tashkeel = isTashkeelArabicChar(nextChar);\n if (!tashkeel) return true;\n }\n return false;\n}\n\n/**\n * Apply arabic presentation forms to a list of tokens\n * @param {ContextRange} range a range of tokens\n */\nfunction arabicPresentationForms(range) {\n const script = 'arab';\n const tags = this.featuresTags[script];\n const tokens = this.tokenizer.getRangeTokens(range);\n if (tokens.length === 1) return;\n let contextParams = new ContextParams(\n tokens.map(token => token.getState('glyphIndex')\n ), 0);\n const charContextParams = new ContextParams(\n tokens.map(token => token.char\n ), 0);\n tokens.forEach((token, index) => {\n if (isTashkeelArabicChar(token.char)) return;\n contextParams.setCurrentIndex(index);\n charContextParams.setCurrentIndex(index);\n let CONNECT = 0; // 2 bits 00 (10: can connect next) (01: can connect prev)\n if (willConnectPrev(charContextParams)) CONNECT |= 1;\n if (willConnectNext(charContextParams)) CONNECT |= 2;\n let tag;\n switch (CONNECT) {\n case 1: (tag = 'fina'); break;\n case 2: (tag = 'init'); break;\n case 3: (tag = 'medi'); break;\n }\n if (tags.indexOf(tag) === -1) return;\n let substitutions = this.query.lookupFeature({\n tag, script, contextParams\n });\n if (substitutions instanceof Error) return console.info(substitutions.message);\n substitutions.forEach((action, index) => {\n if (action instanceof SubstitutionAction) {\n applySubstitution(action, tokens, index);\n contextParams.context[index] = action.substitution;\n }\n });\n });\n}\n\nexport default arabicPresentationForms;\nexport { arabicPresentationForms };\n","/**\n * Apply Arabic required ligatures feature to a range of tokens\n */\n\nimport { ContextParams } from '../../tokenizer';\nimport applySubstitution from '../applySubstitution';\n\n/**\n * Update context params\n * @param {any} tokens a list of tokens\n * @param {number} index current item index\n */\nfunction getContextParams(tokens, index) {\n const context = tokens.map(token => token.activeState.value);\n return new ContextParams(context, index || 0);\n}\n\n/**\n * Apply Arabic required ligatures to a context range\n * @param {ContextRange} range a range of tokens\n */\nfunction arabicRequiredLigatures(range) {\n const script = 'arab';\n let tokens = this.tokenizer.getRangeTokens(range);\n let contextParams = getContextParams(tokens);\n contextParams.context.forEach((glyphIndex, index) => {\n contextParams.setCurrentIndex(index);\n let substitutions = this.query.lookupFeature({\n tag: 'rlig', script, contextParams\n });\n if (substitutions.length) {\n substitutions.forEach(\n action => applySubstitution(action, tokens, index)\n );\n contextParams = getContextParams(tokens);\n }\n });\n}\n\nexport default arabicRequiredLigatures;\nexport { arabicRequiredLigatures };\n","/**\n * Latin word context checkers\n */\n\nimport { isLatinChar } from '../../../char';\n\nfunction latinWordStartCheck(contextParams) {\n const char = contextParams.current;\n const prevChar = contextParams.get(-1);\n return (\n // ? latin first char\n (prevChar === null && isLatinChar(char)) ||\n // ? latin char preceded with a non latin char\n (!isLatinChar(prevChar) && isLatinChar(char))\n );\n}\n\nfunction latinWordEndCheck(contextParams) {\n const nextChar = contextParams.get(1);\n return (\n // ? last latin char\n (nextChar === null) ||\n // ? next char is not latin\n (!isLatinChar(nextChar))\n );\n}\n\nexport default {\n startCheck: latinWordStartCheck,\n endCheck: latinWordEndCheck\n};\n","/**\n * Apply Latin ligature feature to a range of tokens\n */\n\nimport { ContextParams } from '../../tokenizer';\nimport applySubstitution from '../applySubstitution';\n\n/**\n * Update context params\n * @param {any} tokens a list of tokens\n * @param {number} index current item index\n */\nfunction getContextParams(tokens, index) {\n const context = tokens.map(token => token.activeState.value);\n return new ContextParams(context, index || 0);\n}\n\n/**\n * Apply Arabic required ligatures to a context range\n * @param {ContextRange} range a range of tokens\n */\nfunction latinLigature(range) {\n const script = 'latn';\n let tokens = this.tokenizer.getRangeTokens(range);\n let contextParams = getContextParams(tokens);\n contextParams.context.forEach((glyphIndex, index) => {\n contextParams.setCurrentIndex(index);\n let substitutions = this.query.lookupFeature({\n tag: 'liga', script, contextParams\n });\n if (substitutions.length) {\n substitutions.forEach(\n action => applySubstitution(action, tokens, index)\n );\n contextParams = getContextParams(tokens);\n }\n });\n}\n\nexport default latinLigature;\n","/**\n * Infer bidirectional properties for a given text and apply\n * the corresponding layout rules.\n */\n\nimport Tokenizer from './tokenizer';\nimport FeatureQuery from './features/featureQuery';\nimport arabicWordCheck from './features/arab/contextCheck/arabicWord';\nimport arabicSentenceCheck from './features/arab/contextCheck/arabicSentence';\nimport arabicPresentationForms from './features/arab/arabicPresentationForms';\nimport arabicRequiredLigatures from './features/arab/arabicRequiredLigatures';\nimport latinWordCheck from './features/latn/contextCheck/latinWord';\nimport latinLigature from './features/latn/latinLigatures';\n\n/**\n * Create Bidi. features\n * @param {string} baseDir text base direction. value either 'ltr' or 'rtl'\n */\nfunction Bidi(baseDir) {\n this.baseDir = baseDir || 'ltr';\n this.tokenizer = new Tokenizer();\n this.featuresTags = {};\n}\n\n/**\n * Sets Bidi text\n * @param {string} text a text input\n */\nBidi.prototype.setText = function (text) {\n this.text = text;\n};\n\n/**\n * Store essential context checks:\n * arabic word check for applying gsub features\n * arabic sentence check for adjusting arabic layout\n */\nBidi.prototype.contextChecks = ({\n latinWordCheck,\n arabicWordCheck,\n arabicSentenceCheck\n});\n\n/**\n * Register arabic word check\n */\nfunction registerContextChecker(checkId) {\n const check = this.contextChecks[`${checkId}Check`];\n return this.tokenizer.registerContextChecker(\n checkId, check.startCheck, check.endCheck\n );\n}\n\n/**\n * Perform pre tokenization procedure then\n * tokenize text input\n */\nfunction tokenizeText() {\n registerContextChecker.call(this, 'latinWord');\n registerContextChecker.call(this, 'arabicWord');\n registerContextChecker.call(this, 'arabicSentence');\n return this.tokenizer.tokenize(this.text);\n}\n\n/**\n * Reverse arabic sentence layout\n * TODO: check base dir before applying adjustments - priority low\n */\nfunction reverseArabicSentences() {\n const ranges = this.tokenizer.getContextRanges('arabicSentence');\n ranges.forEach(range => {\n let rangeTokens = this.tokenizer.getRangeTokens(range);\n this.tokenizer.replaceRange(\n range.startIndex,\n range.endOffset,\n rangeTokens.reverse()\n );\n });\n}\n\n/**\n * Register supported features tags\n * @param {script} script script tag\n * @param {Array} tags features tags list\n */\nBidi.prototype.registerFeatures = function (script, tags) {\n const supportedTags = tags.filter(\n tag => this.query.supports({script, tag})\n );\n if (!this.featuresTags.hasOwnProperty(script)) {\n this.featuresTags[script] = supportedTags;\n } else {\n this.featuresTags[script] =\n this.featuresTags[script].concat(supportedTags);\n }\n};\n\n/**\n * Apply GSUB features\n * @param {Array} tagsList a list of features tags\n * @param {string} script a script tag\n * @param {Font} font opentype font instance\n */\nBidi.prototype.applyFeatures = function (font, features) {\n if (!font) throw new Error(\n 'No valid font was provided to apply features'\n );\n if (!this.query) this.query = new FeatureQuery(font);\n for (let f = 0; f < features.length; f++) {\n const feature = features[f];\n if (!this.query.supports({script: feature.script})) continue;\n this.registerFeatures(feature.script, feature.tags);\n }\n};\n\n/**\n * Register a state modifier\n * @param {string} modifierId state modifier id\n * @param {function} condition a predicate function that returns true or false\n * @param {function} modifier a modifier function to set token state\n */\nBidi.prototype.registerModifier = function (modifierId, condition, modifier) {\n this.tokenizer.registerModifier(modifierId, condition, modifier);\n};\n\n/**\n * Check if 'glyphIndex' is registered\n */\nfunction checkGlyphIndexStatus() {\n if (this.tokenizer.registeredModifiers.indexOf('glyphIndex') === -1) {\n throw new Error(\n 'glyphIndex modifier is required to apply ' +\n 'arabic presentation features.'\n );\n }\n}\n\n/**\n * Apply arabic presentation forms features\n */\nfunction applyArabicPresentationForms() {\n const script = 'arab';\n if (!this.featuresTags.hasOwnProperty(script)) return;\n checkGlyphIndexStatus.call(this);\n const ranges = this.tokenizer.getContextRanges('arabicWord');\n ranges.forEach(range => {\n arabicPresentationForms.call(this, range);\n });\n}\n\n/**\n * Apply required arabic ligatures\n */\nfunction applyArabicRequireLigatures() {\n const script = 'arab';\n if (!this.featuresTags.hasOwnProperty(script)) return;\n const tags = this.featuresTags[script];\n if (tags.indexOf('rlig') === -1) return;\n checkGlyphIndexStatus.call(this);\n const ranges = this.tokenizer.getContextRanges('arabicWord');\n ranges.forEach(range => {\n arabicRequiredLigatures.call(this, range);\n });\n}\n\n/**\n * Apply required arabic ligatures\n */\nfunction applyLatinLigatures() {\n const script = 'latn';\n if (!this.featuresTags.hasOwnProperty(script)) return;\n const tags = this.featuresTags[script];\n if (tags.indexOf('liga') === -1) return;\n checkGlyphIndexStatus.call(this);\n const ranges = this.tokenizer.getContextRanges('latinWord');\n ranges.forEach(range => {\n latinLigature.call(this, range);\n });\n}\n\n/**\n * Check if a context is registered\n * @param {string} contextId context id\n */\nBidi.prototype.checkContextReady = function (contextId) {\n return !!this.tokenizer.getContext(contextId);\n};\n\n/**\n * Apply features to registered contexts\n */\nBidi.prototype.applyFeaturesToContexts = function () {\n if (this.checkContextReady('arabicWord')) {\n applyArabicPresentationForms.call(this);\n applyArabicRequireLigatures.call(this);\n }\n if (this.checkContextReady('latinWord')) {\n applyLatinLigatures.call(this);\n }\n if (this.checkContextReady('arabicSentence')) {\n reverseArabicSentences.call(this);\n }\n};\n\n/**\n * process text input\n * @param {string} text an input text\n */\nBidi.prototype.processText = function(text) {\n if (!this.text || this.text !== text) {\n this.setText(text);\n tokenizeText.call(this);\n this.applyFeaturesToContexts();\n }\n};\n\n/**\n * Process a string of text to identify and adjust\n * bidirectional text entities.\n * @param {string} text input text\n */\nBidi.prototype.getBidiText = function (text) {\n this.processText(text);\n return this.tokenizer.getText();\n};\n\n/**\n * Get the current state index of each token\n * @param {text} text an input text\n */\nBidi.prototype.getTextGlyphs = function (text) {\n this.processText(text);\n let indexes = [];\n for (let i = 0; i < this.tokenizer.tokens.length; i++) {\n const token = this.tokenizer.tokens[i];\n if (token.state.deleted) continue;\n const index = token.activeState.value;\n indexes.push(Array.isArray(index) ? index[0] : index);\n }\n return indexes;\n};\n\nexport default Bidi;\n","// The Font object\n\nimport Path from './path';\nimport sfnt from './tables/sfnt';\nimport { DefaultEncoding } from './encoding';\nimport glyphset from './glyphset';\nimport Position from './position';\nimport Substitution from './substitution';\nimport { isBrowser, checkArgument, arrayBufferToNodeBuffer } from './util';\nimport HintingTrueType from './hintingtt';\nimport Bidi from './bidi';\n\n/**\n * @typedef FontOptions\n * @type Object\n * @property {Boolean} empty - whether to create a new empty font\n * @property {string} familyName\n * @property {string} styleName\n * @property {string=} fullName\n * @property {string=} postScriptName\n * @property {string=} designer\n * @property {string=} designerURL\n * @property {string=} manufacturer\n * @property {string=} manufacturerURL\n * @property {string=} license\n * @property {string=} licenseURL\n * @property {string=} version\n * @property {string=} description\n * @property {string=} copyright\n * @property {string=} trademark\n * @property {Number} unitsPerEm\n * @property {Number} ascender\n * @property {Number} descender\n * @property {Number} createdTimestamp\n * @property {string=} weightClass\n * @property {string=} widthClass\n * @property {string=} fsSelection\n */\n\n/**\n * A Font represents a loaded OpenType font file.\n * It contains a set of glyphs and methods to draw text on a drawing context,\n * or to get a path representing the text.\n * @exports opentype.Font\n * @class\n * @param {FontOptions}\n * @constructor\n */\nfunction Font(options) {\n options = options || {};\n options.tables = options.tables || {};\n\n if (!options.empty) {\n // Check that we've provided the minimum set of names.\n checkArgument(options.familyName, 'When creating a new Font object, familyName is required.');\n checkArgument(options.styleName, 'When creating a new Font object, styleName is required.');\n checkArgument(options.unitsPerEm, 'When creating a new Font object, unitsPerEm is required.');\n checkArgument(options.ascender, 'When creating a new Font object, ascender is required.');\n checkArgument(options.descender <= 0, 'When creating a new Font object, negative descender value is required.');\n\n // OS X will complain if the names are empty, so we put a single space everywhere by default.\n this.names = {\n fontFamily: {en: options.familyName || ' '},\n fontSubfamily: {en: options.styleName || ' '},\n fullName: {en: options.fullName || options.familyName + ' ' + options.styleName},\n // postScriptName may not contain any whitespace\n postScriptName: {en: options.postScriptName || (options.familyName + options.styleName).replace(/\\s/g, '')},\n designer: {en: options.designer || ' '},\n designerURL: {en: options.designerURL || ' '},\n manufacturer: {en: options.manufacturer || ' '},\n manufacturerURL: {en: options.manufacturerURL || ' '},\n license: {en: options.license || ' '},\n licenseURL: {en: options.licenseURL || ' '},\n version: {en: options.version || 'Version 0.1'},\n description: {en: options.description || ' '},\n copyright: {en: options.copyright || ' '},\n trademark: {en: options.trademark || ' '}\n };\n this.unitsPerEm = options.unitsPerEm || 1000;\n this.ascender = options.ascender;\n this.descender = options.descender;\n this.createdTimestamp = options.createdTimestamp;\n this.tables = Object.assign(options.tables, {\n os2: Object.assign({\n usWeightClass: options.weightClass || this.usWeightClasses.MEDIUM,\n usWidthClass: options.widthClass || this.usWidthClasses.MEDIUM,\n fsSelection: options.fsSelection || this.fsSelectionValues.REGULAR,\n }, options.tables.os2)\n });\n }\n\n this.supported = true; // Deprecated: parseBuffer will throw an error if font is not supported.\n this.glyphs = new glyphset.GlyphSet(this, options.glyphs || []);\n this.encoding = new DefaultEncoding(this);\n this.position = new Position(this);\n this.substitution = new Substitution(this);\n this.tables = this.tables || {};\n\n // needed for low memory mode only.\n this._push = null;\n this._hmtxTableData = {};\n\n Object.defineProperty(this, 'hinting', {\n get: function() {\n if (this._hinting) return this._hinting;\n if (this.outlinesFormat === 'truetype') {\n return (this._hinting = new HintingTrueType(this));\n }\n }\n });\n}\n\n/**\n * Check if the font has a glyph for the given character.\n * @param {string}\n * @return {Boolean}\n */\nFont.prototype.hasChar = function(c) {\n return this.encoding.charToGlyphIndex(c) !== null;\n};\n\n/**\n * Convert the given character to a single glyph index.\n * Note that this function assumes that there is a one-to-one mapping between\n * the given character and a glyph; for complex scripts this might not be the case.\n * @param {string}\n * @return {Number}\n */\nFont.prototype.charToGlyphIndex = function(s) {\n return this.encoding.charToGlyphIndex(s);\n};\n\n/**\n * Convert the given character to a single Glyph object.\n * Note that this function assumes that there is a one-to-one mapping between\n * the given character and a glyph; for complex scripts this might not be the case.\n * @param {string}\n * @return {opentype.Glyph}\n */\nFont.prototype.charToGlyph = function(c) {\n const glyphIndex = this.charToGlyphIndex(c);\n let glyph = this.glyphs.get(glyphIndex);\n if (!glyph) {\n // .notdef\n glyph = this.glyphs.get(0);\n }\n\n return glyph;\n};\n\n/**\n * Update features\n * @param {any} options features options\n */\nFont.prototype.updateFeatures = function (options) {\n // TODO: update all features options not only 'latn'.\n return this.defaultRenderOptions.features.map(feature => {\n if (feature.script === 'latn') {\n return {\n script: 'latn',\n tags: feature.tags.filter(tag => options[tag])\n };\n } else {\n return feature;\n }\n });\n};\n\n/**\n * Convert the given text to a list of Glyph objects.\n * Note that there is no strict one-to-one mapping between characters and\n * glyphs, so the list of returned glyphs can be larger or smaller than the\n * length of the given string.\n * @param {string}\n * @param {GlyphRenderOptions} [options]\n * @return {opentype.Glyph[]}\n */\nFont.prototype.stringToGlyphs = function(s, options) {\n\n const bidi = new Bidi();\n\n // Create and register 'glyphIndex' state modifier\n const charToGlyphIndexMod = token => this.charToGlyphIndex(token.char);\n bidi.registerModifier('glyphIndex', null, charToGlyphIndexMod);\n\n // roll-back to default features\n let features = options ?\n this.updateFeatures(options.features) :\n this.defaultRenderOptions.features;\n\n bidi.applyFeatures(this, features);\n\n const indexes = bidi.getTextGlyphs(s);\n\n let length = indexes.length;\n\n // convert glyph indexes to glyph objects\n const glyphs = new Array(length);\n const notdef = this.glyphs.get(0);\n for (let i = 0; i < length; i += 1) {\n glyphs[i] = this.glyphs.get(indexes[i]) || notdef;\n }\n return glyphs;\n};\n\n/**\n * @param {string}\n * @return {Number}\n */\nFont.prototype.nameToGlyphIndex = function(name) {\n return this.glyphNames.nameToGlyphIndex(name);\n};\n\n/**\n * @param {string}\n * @return {opentype.Glyph}\n */\nFont.prototype.nameToGlyph = function(name) {\n const glyphIndex = this.nameToGlyphIndex(name);\n let glyph = this.glyphs.get(glyphIndex);\n if (!glyph) {\n // .notdef\n glyph = this.glyphs.get(0);\n }\n\n return glyph;\n};\n\n/**\n * @param {Number}\n * @return {String}\n */\nFont.prototype.glyphIndexToName = function(gid) {\n if (!this.glyphNames.glyphIndexToName) {\n return '';\n }\n\n return this.glyphNames.glyphIndexToName(gid);\n};\n\n/**\n * Retrieve the value of the kerning pair between the left glyph (or its index)\n * and the right glyph (or its index). If no kerning pair is found, return 0.\n * The kerning value gets added to the advance width when calculating the spacing\n * between glyphs.\n * For GPOS kerning, this method uses the default script and language, which covers\n * most use cases. To have greater control, use font.position.getKerningValue .\n * @param {opentype.Glyph} leftGlyph\n * @param {opentype.Glyph} rightGlyph\n * @return {Number}\n */\nFont.prototype.getKerningValue = function(leftGlyph, rightGlyph) {\n leftGlyph = leftGlyph.index || leftGlyph;\n rightGlyph = rightGlyph.index || rightGlyph;\n const gposKerning = this.position.defaultKerningTables;\n if (gposKerning) {\n return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph);\n }\n // \"kern\" table\n return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0;\n};\n\n/**\n * @typedef GlyphRenderOptions\n * @type Object\n * @property {string} [script] - script used to determine which features to apply. By default, 'DFLT' or 'latn' is used.\n * See https://www.microsoft.com/typography/otspec/scripttags.htm\n * @property {string} [language='dflt'] - language system used to determine which features to apply.\n * See https://www.microsoft.com/typography/developers/opentype/languagetags.aspx\n * @property {boolean} [kerning=true] - whether to include kerning values\n * @property {object} [features] - OpenType Layout feature tags. Used to enable or disable the features of the given script/language system.\n * See https://www.microsoft.com/typography/otspec/featuretags.htm\n */\nFont.prototype.defaultRenderOptions = {\n kerning: true,\n features: [\n /**\n * these 4 features are required to render Arabic text properly\n * and shouldn't be turned off when rendering arabic text.\n */\n { script: 'arab', tags: ['init', 'medi', 'fina', 'rlig'] },\n { script: 'latn', tags: ['liga', 'rlig'] }\n ]\n};\n\n/**\n * Helper function that invokes the given callback for each glyph in the given text.\n * The callback gets `(glyph, x, y, fontSize, options)`.* @param {string} text\n * @param {string} text - The text to apply.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @param {Function} callback\n */\nFont.prototype.forEachGlyph = function(text, x, y, fontSize, options, callback) {\n x = x !== undefined ? x : 0;\n y = y !== undefined ? y : 0;\n fontSize = fontSize !== undefined ? fontSize : 72;\n options = Object.assign({}, this.defaultRenderOptions, options);\n const fontScale = 1 / this.unitsPerEm * fontSize;\n const glyphs = this.stringToGlyphs(text, options);\n let kerningLookups;\n if (options.kerning) {\n const script = options.script || this.position.getDefaultScriptName();\n kerningLookups = this.position.getKerningTables(script, options.language);\n }\n for (let i = 0; i < glyphs.length; i += 1) {\n const glyph = glyphs[i];\n callback.call(this, glyph, x, y, fontSize, options);\n if (glyph.advanceWidth) {\n x += glyph.advanceWidth * fontScale;\n }\n\n if (options.kerning && i < glyphs.length - 1) {\n // We should apply position adjustment lookups in a more generic way.\n // Here we only use the xAdvance value.\n const kerningValue = kerningLookups ?\n this.position.getKerningValue(kerningLookups, glyph.index, glyphs[i + 1].index) :\n this.getKerningValue(glyph, glyphs[i + 1]);\n x += kerningValue * fontScale;\n }\n\n if (options.letterSpacing) {\n x += options.letterSpacing * fontSize;\n } else if (options.tracking) {\n x += (options.tracking / 1000) * fontSize;\n }\n }\n return x;\n};\n\n/**\n * Create a Path object that represents the given text.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @return {opentype.Path}\n */\nFont.prototype.getPath = function(text, x, y, fontSize, options) {\n const fullPath = new Path();\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);\n fullPath.extend(glyphPath);\n });\n return fullPath;\n};\n\n/**\n * Create an array of Path objects that represent the glyphs of a given text.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @return {opentype.Path[]}\n */\nFont.prototype.getPaths = function(text, x, y, fontSize, options) {\n const glyphPaths = [];\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);\n glyphPaths.push(glyphPath);\n });\n\n return glyphPaths;\n};\n\n/**\n * Returns the advance width of a text.\n *\n * This is something different than Path.getBoundingBox() as for example a\n * suffixed whitespace increases the advanceWidth but not the bounding box\n * or an overhanging letter like a calligraphic 'f' might have a quite larger\n * bounding box than its advance width.\n *\n * This corresponds to canvas2dContext.measureText(text).width\n *\n * @param {string} text - The text to create.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n * @return advance width\n */\nFont.prototype.getAdvanceWidth = function(text, fontSize, options) {\n return this.forEachGlyph(text, 0, 0, fontSize, options, function() {});\n};\n\n/**\n * Draw the text on the given drawing context.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n */\nFont.prototype.draw = function(ctx, text, x, y, fontSize, options) {\n this.getPath(text, x, y, fontSize, options).draw(ctx);\n};\n\n/**\n * Draw the points of all glyphs in the text.\n * On-curve points will be drawn in blue, off-curve points will be drawn in red.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n */\nFont.prototype.drawPoints = function(ctx, text, x, y, fontSize, options) {\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n glyph.drawPoints(ctx, gX, gY, gFontSize);\n });\n};\n\n/**\n * Draw lines indicating important font measurements for all glyphs in the text.\n * Black lines indicate the origin of the coordinate system (point 0,0).\n * Blue lines indicate the glyph bounding box.\n * Green line indicates the advance width of the glyph.\n * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas.\n * @param {string} text - The text to create.\n * @param {number} [x=0] - Horizontal position of the beginning of the text.\n * @param {number} [y=0] - Vertical position of the *baseline* of the text.\n * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`.\n * @param {GlyphRenderOptions=} options\n */\nFont.prototype.drawMetrics = function(ctx, text, x, y, fontSize, options) {\n this.forEachGlyph(text, x, y, fontSize, options, function(glyph, gX, gY, gFontSize) {\n glyph.drawMetrics(ctx, gX, gY, gFontSize);\n });\n};\n\n/**\n * @param {string}\n * @return {string}\n */\nFont.prototype.getEnglishName = function(name) {\n const translations = this.names[name];\n if (translations) {\n return translations.en;\n }\n};\n\n/**\n * Validate\n */\nFont.prototype.validate = function() {\n const warnings = [];\n const _this = this;\n\n function assert(predicate, message) {\n if (!predicate) {\n warnings.push(message);\n }\n }\n\n function assertNamePresent(name) {\n const englishName = _this.getEnglishName(name);\n assert(englishName && englishName.trim().length > 0,\n 'No English ' + name + ' specified.');\n }\n\n // Identification information\n assertNamePresent('fontFamily');\n assertNamePresent('weightName');\n assertNamePresent('manufacturer');\n assertNamePresent('copyright');\n assertNamePresent('version');\n\n // Dimension information\n assert(this.unitsPerEm > 0, 'No unitsPerEm specified.');\n};\n\n/**\n * Convert the font object to a SFNT data structure.\n * This structure contains all the necessary tables and metadata to create a binary OTF file.\n * @return {opentype.Table}\n */\nFont.prototype.toTables = function() {\n return sfnt.fontToTable(this);\n};\n/**\n * @deprecated Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.\n */\nFont.prototype.toBuffer = function() {\n console.warn('Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.');\n return this.toArrayBuffer();\n};\n/**\n * Converts a `opentype.Font` into an `ArrayBuffer`\n * @return {ArrayBuffer}\n */\nFont.prototype.toArrayBuffer = function() {\n const sfntTable = this.toTables();\n const bytes = sfntTable.encode();\n const buffer = new ArrayBuffer(bytes.length);\n const intArray = new Uint8Array(buffer);\n for (let i = 0; i < bytes.length; i++) {\n intArray[i] = bytes[i];\n }\n\n return buffer;\n};\n\n/**\n * Initiate a download of the OpenType font.\n */\nFont.prototype.download = function(fileName) {\n const familyName = this.getEnglishName('fontFamily');\n const styleName = this.getEnglishName('fontSubfamily');\n fileName = fileName || familyName.replace(/\\s/g, '') + '-' + styleName + '.otf';\n const arrayBuffer = this.toArrayBuffer();\n\n if (isBrowser()) {\n window.URL = window.URL || window.webkitURL;\n\n if (window.URL) {\n const dataView = new DataView(arrayBuffer);\n const blob = new Blob([dataView], {type: 'font/opentype'});\n\n let link = document.createElement('a');\n link.href = window.URL.createObjectURL(blob);\n link.download = fileName;\n\n let event = document.createEvent('MouseEvents');\n event.initEvent('click', true, false);\n link.dispatchEvent(event);\n } else {\n console.warn('Font file could not be downloaded. Try using a different browser.');\n }\n } else {\n const fs = require('fs');\n const buffer = arrayBufferToNodeBuffer(arrayBuffer);\n fs.writeFileSync(fileName, buffer);\n }\n};\n/**\n * @private\n */\nFont.prototype.fsSelectionValues = {\n ITALIC: 0x001, //1\n UNDERSCORE: 0x002, //2\n NEGATIVE: 0x004, //4\n OUTLINED: 0x008, //8\n STRIKEOUT: 0x010, //16\n BOLD: 0x020, //32\n REGULAR: 0x040, //64\n USER_TYPO_METRICS: 0x080, //128\n WWS: 0x100, //256\n OBLIQUE: 0x200 //512\n};\n\n/**\n * @private\n */\nFont.prototype.usWidthClasses = {\n ULTRA_CONDENSED: 1,\n EXTRA_CONDENSED: 2,\n CONDENSED: 3,\n SEMI_CONDENSED: 4,\n MEDIUM: 5,\n SEMI_EXPANDED: 6,\n EXPANDED: 7,\n EXTRA_EXPANDED: 8,\n ULTRA_EXPANDED: 9\n};\n\n/**\n * @private\n */\nFont.prototype.usWeightClasses = {\n THIN: 100,\n EXTRA_LIGHT: 200,\n LIGHT: 300,\n NORMAL: 400,\n MEDIUM: 500,\n SEMI_BOLD: 600,\n BOLD: 700,\n EXTRA_BOLD: 800,\n BLACK: 900\n};\n\nexport default Font;\n","// The `fvar` table stores font variation axes and instances.\n// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6fvar.html\n\nimport check from '../check';\nimport parse from '../parse';\nimport table from '../table';\n\nfunction addName(name, names) {\n const nameString = JSON.stringify(name);\n let nameID = 256;\n for (let nameKey in names) {\n let n = parseInt(nameKey);\n if (!n || n < 256) {\n continue;\n }\n\n if (JSON.stringify(names[nameKey]) === nameString) {\n return n;\n }\n\n if (nameID <= n) {\n nameID = n + 1;\n }\n }\n\n names[nameID] = name;\n return nameID;\n}\n\nfunction makeFvarAxis(n, axis, names) {\n const nameID = addName(axis.name, names);\n return [\n {name: 'tag_' + n, type: 'TAG', value: axis.tag},\n {name: 'minValue_' + n, type: 'FIXED', value: axis.minValue << 16},\n {name: 'defaultValue_' + n, type: 'FIXED', value: axis.defaultValue << 16},\n {name: 'maxValue_' + n, type: 'FIXED', value: axis.maxValue << 16},\n {name: 'flags_' + n, type: 'USHORT', value: 0},\n {name: 'nameID_' + n, type: 'USHORT', value: nameID}\n ];\n}\n\nfunction parseFvarAxis(data, start, names) {\n const axis = {};\n const p = new parse.Parser(data, start);\n axis.tag = p.parseTag();\n axis.minValue = p.parseFixed();\n axis.defaultValue = p.parseFixed();\n axis.maxValue = p.parseFixed();\n p.skip('uShort', 1); // reserved for flags; no values defined\n axis.name = names[p.parseUShort()] || {};\n return axis;\n}\n\nfunction makeFvarInstance(n, inst, axes, names) {\n const nameID = addName(inst.name, names);\n const fields = [\n {name: 'nameID_' + n, type: 'USHORT', value: nameID},\n {name: 'flags_' + n, type: 'USHORT', value: 0}\n ];\n\n for (let i = 0; i < axes.length; ++i) {\n const axisTag = axes[i].tag;\n fields.push({\n name: 'axis_' + n + ' ' + axisTag,\n type: 'FIXED',\n value: inst.coordinates[axisTag] << 16\n });\n }\n\n return fields;\n}\n\nfunction parseFvarInstance(data, start, axes, names) {\n const inst = {};\n const p = new parse.Parser(data, start);\n inst.name = names[p.parseUShort()] || {};\n p.skip('uShort', 1); // reserved for flags; no values defined\n\n inst.coordinates = {};\n for (let i = 0; i < axes.length; ++i) {\n inst.coordinates[axes[i].tag] = p.parseFixed();\n }\n\n return inst;\n}\n\nfunction makeFvarTable(fvar, names) {\n const result = new table.Table('fvar', [\n {name: 'version', type: 'ULONG', value: 0x10000},\n {name: 'offsetToData', type: 'USHORT', value: 0},\n {name: 'countSizePairs', type: 'USHORT', value: 2},\n {name: 'axisCount', type: 'USHORT', value: fvar.axes.length},\n {name: 'axisSize', type: 'USHORT', value: 20},\n {name: 'instanceCount', type: 'USHORT', value: fvar.instances.length},\n {name: 'instanceSize', type: 'USHORT', value: 4 + fvar.axes.length * 4}\n ]);\n result.offsetToData = result.sizeOf();\n\n for (let i = 0; i < fvar.axes.length; i++) {\n result.fields = result.fields.concat(makeFvarAxis(i, fvar.axes[i], names));\n }\n\n for (let j = 0; j < fvar.instances.length; j++) {\n result.fields = result.fields.concat(makeFvarInstance(j, fvar.instances[j], fvar.axes, names));\n }\n\n return result;\n}\n\nfunction parseFvarTable(data, start, names) {\n const p = new parse.Parser(data, start);\n const tableVersion = p.parseULong();\n check.argument(tableVersion === 0x00010000, 'Unsupported fvar table version.');\n const offsetToData = p.parseOffset16();\n // Skip countSizePairs.\n p.skip('uShort', 1);\n const axisCount = p.parseUShort();\n const axisSize = p.parseUShort();\n const instanceCount = p.parseUShort();\n const instanceSize = p.parseUShort();\n\n const axes = [];\n for (let i = 0; i < axisCount; i++) {\n axes.push(parseFvarAxis(data, start + offsetToData + i * axisSize, names));\n }\n\n const instances = [];\n const instanceStart = start + offsetToData + axisCount * axisSize;\n for (let j = 0; j < instanceCount; j++) {\n instances.push(parseFvarInstance(data, instanceStart + j * instanceSize, axes, names));\n }\n\n return {axes: axes, instances: instances};\n}\n\nexport default { make: makeFvarTable, parse: parseFvarTable };\n","// The `GDEF` table contains various glyph properties\n// https://docs.microsoft.com/en-us/typography/opentype/spec/gdef\n\nimport check from '../check';\nimport { Parser } from '../parse';\n\nvar attachList = function() {\n return {\n coverage: this.parsePointer(Parser.coverage),\n attachPoints: this.parseList(Parser.pointer(Parser.uShortList))\n };\n};\n\nvar caretValue = function() {\n var format = this.parseUShort();\n check.argument(format === 1 || format === 2 || format === 3,\n 'Unsupported CaretValue table version.');\n if (format === 1) {\n return { coordinate: this.parseShort() };\n } else if (format === 2) {\n return { pointindex: this.parseShort() };\n } else if (format === 3) {\n // Device / Variation Index tables unsupported\n return { coordinate: this.parseShort() };\n }\n};\n\nvar ligGlyph = function() {\n return this.parseList(Parser.pointer(caretValue));\n};\n\nvar ligCaretList = function() {\n return {\n coverage: this.parsePointer(Parser.coverage),\n ligGlyphs: this.parseList(Parser.pointer(ligGlyph))\n };\n};\n\nvar markGlyphSets = function() {\n this.parseUShort(); // Version\n return this.parseList(Parser.pointer(Parser.coverage));\n};\n\nfunction parseGDEFTable(data, start) {\n start = start || 0;\n const p = new Parser(data, start);\n const tableVersion = p.parseVersion(1);\n check.argument(tableVersion === 1 || tableVersion === 1.2 || tableVersion === 1.3,\n 'Unsupported GDEF table version.');\n var gdef = {\n version: tableVersion,\n classDef: p.parsePointer(Parser.classDef),\n attachList: p.parsePointer(attachList),\n ligCaretList: p.parsePointer(ligCaretList),\n markAttachClassDef: p.parsePointer(Parser.classDef)\n };\n if (tableVersion >= 1.2) {\n gdef.markGlyphSets = p.parsePointer(markGlyphSets);\n }\n return gdef;\n}\nexport default { parse: parseGDEFTable };\n","// The `GPOS` table contains kerning pairs, among other things.\n// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos\n\nimport check from '../check';\nimport { Parser } from '../parse';\nimport table from '../table';\n\nconst subtableParsers = new Array(10); // subtableParsers[0] is unused\n\n// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable\n// this = Parser instance\nsubtableParsers[1] = function parseLookup1() {\n const start = this.offset + this.relativeOffset;\n const posformat = this.parseUShort();\n if (posformat === 1) {\n return {\n posFormat: 1,\n coverage: this.parsePointer(Parser.coverage),\n value: this.parseValueRecord()\n };\n } else if (posformat === 2) {\n return {\n posFormat: 2,\n coverage: this.parsePointer(Parser.coverage),\n values: this.parseValueRecordList()\n };\n }\n check.assert(false, '0x' + start.toString(16) + ': GPOS lookup type 1 format must be 1 or 2.');\n};\n\n// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable\nsubtableParsers[2] = function parseLookup2() {\n const start = this.offset + this.relativeOffset;\n const posFormat = this.parseUShort();\n check.assert(posFormat === 1 || posFormat === 2, '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.');\n const coverage = this.parsePointer(Parser.coverage);\n const valueFormat1 = this.parseUShort();\n const valueFormat2 = this.parseUShort();\n if (posFormat === 1) {\n // Adjustments for Glyph Pairs\n return {\n posFormat: posFormat,\n coverage: coverage,\n valueFormat1: valueFormat1,\n valueFormat2: valueFormat2,\n pairSets: this.parseList(Parser.pointer(Parser.list(function() {\n return { // pairValueRecord\n secondGlyph: this.parseUShort(),\n value1: this.parseValueRecord(valueFormat1),\n value2: this.parseValueRecord(valueFormat2)\n };\n })))\n };\n } else if (posFormat === 2) {\n const classDef1 = this.parsePointer(Parser.classDef);\n const classDef2 = this.parsePointer(Parser.classDef);\n const class1Count = this.parseUShort();\n const class2Count = this.parseUShort();\n return {\n // Class Pair Adjustment\n posFormat: posFormat,\n coverage: coverage,\n valueFormat1: valueFormat1,\n valueFormat2: valueFormat2,\n classDef1: classDef1,\n classDef2: classDef2,\n class1Count: class1Count,\n class2Count: class2Count,\n classRecords: this.parseList(class1Count, Parser.list(class2Count, function() {\n return {\n value1: this.parseValueRecord(valueFormat1),\n value2: this.parseValueRecord(valueFormat2)\n };\n }))\n };\n }\n};\n\nsubtableParsers[3] = function parseLookup3() { return { error: 'GPOS Lookup 3 not supported' }; };\nsubtableParsers[4] = function parseLookup4() { return { error: 'GPOS Lookup 4 not supported' }; };\nsubtableParsers[5] = function parseLookup5() { return { error: 'GPOS Lookup 5 not supported' }; };\nsubtableParsers[6] = function parseLookup6() { return { error: 'GPOS Lookup 6 not supported' }; };\nsubtableParsers[7] = function parseLookup7() { return { error: 'GPOS Lookup 7 not supported' }; };\nsubtableParsers[8] = function parseLookup8() { return { error: 'GPOS Lookup 8 not supported' }; };\nsubtableParsers[9] = function parseLookup9() { return { error: 'GPOS Lookup 9 not supported' }; };\n\n// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos\nfunction parseGposTable(data, start) {\n start = start || 0;\n const p = new Parser(data, start);\n const tableVersion = p.parseVersion(1);\n check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GPOS table version ' + tableVersion);\n\n if (tableVersion === 1) {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers)\n };\n } else {\n return {\n version: tableVersion,\n scripts: p.parseScriptList(),\n features: p.parseFeatureList(),\n lookups: p.parseLookupList(subtableParsers),\n variations: p.parseFeatureVariationsList()\n };\n }\n\n}\n\n// GPOS Writing //////////////////////////////////////////////\n// NOT SUPPORTED\nconst subtableMakers = new Array(10);\n\nfunction makeGposTable(gpos) {\n return new table.Table('GPOS', [\n {name: 'version', type: 'ULONG', value: 0x10000},\n {name: 'scripts', type: 'TABLE', value: new table.ScriptList(gpos.scripts)},\n {name: 'features', type: 'TABLE', value: new table.FeatureList(gpos.features)},\n {name: 'lookups', type: 'TABLE', value: new table.LookupList(gpos.lookups, subtableMakers)}\n ]);\n}\n\nexport default { parse: parseGposTable, make: makeGposTable };\n","// The `kern` table contains kerning pairs.\n// Note that some fonts use the GPOS OpenType layout table to specify kerning.\n// https://www.microsoft.com/typography/OTSPEC/kern.htm\n\nimport check from '../check';\nimport parse from '../parse';\n\nfunction parseWindowsKernTable(p) {\n const pairs = {};\n // Skip nTables.\n p.skip('uShort');\n const subtableVersion = p.parseUShort();\n check.argument(subtableVersion === 0, 'Unsupported kern sub-table version.');\n // Skip subtableLength, subtableCoverage\n p.skip('uShort', 2);\n const nPairs = p.parseUShort();\n // Skip searchRange, entrySelector, rangeShift.\n p.skip('uShort', 3);\n for (let i = 0; i < nPairs; i += 1) {\n const leftIndex = p.parseUShort();\n const rightIndex = p.parseUShort();\n const value = p.parseShort();\n pairs[leftIndex + ',' + rightIndex] = value;\n }\n return pairs;\n}\n\nfunction parseMacKernTable(p) {\n const pairs = {};\n // The Mac kern table stores the version as a fixed (32 bits) but we only loaded the first 16 bits.\n // Skip the rest.\n p.skip('uShort');\n const nTables = p.parseULong();\n //check.argument(nTables === 1, 'Only 1 subtable is supported (got ' + nTables + ').');\n if (nTables > 1) {\n console.warn('Only the first kern subtable is supported.');\n }\n p.skip('uLong');\n const coverage = p.parseUShort();\n const subtableVersion = coverage & 0xFF;\n p.skip('uShort');\n if (subtableVersion === 0) {\n const nPairs = p.parseUShort();\n // Skip searchRange, entrySelector, rangeShift.\n p.skip('uShort', 3);\n for (let i = 0; i < nPairs; i += 1) {\n const leftIndex = p.parseUShort();\n const rightIndex = p.parseUShort();\n const value = p.parseShort();\n pairs[leftIndex + ',' + rightIndex] = value;\n }\n }\n return pairs;\n}\n\n// Parse the `kern` table which contains kerning pairs.\nfunction parseKernTable(data, start) {\n const p = new parse.Parser(data, start);\n const tableVersion = p.parseUShort();\n if (tableVersion === 0) {\n return parseWindowsKernTable(p);\n } else if (tableVersion === 1) {\n return parseMacKernTable(p);\n } else {\n throw new Error('Unsupported kern table version (' + tableVersion + ').');\n }\n}\n\nexport default { parse: parseKernTable };\n","// The `loca` table stores the offsets to the locations of the glyphs in the font.\n// https://www.microsoft.com/typography/OTSPEC/loca.htm\n\nimport parse from '../parse';\n\n// Parse the `loca` table. This table stores the offsets to the locations of the glyphs in the font,\n// relative to the beginning of the glyphData table.\n// The number of glyphs stored in the `loca` table is specified in the `maxp` table (under numGlyphs)\n// The loca table has two versions: a short version where offsets are stored as uShorts, and a long\n// version where offsets are stored as uLongs. The `head` table specifies which version to use\n// (under indexToLocFormat).\nfunction parseLocaTable(data, start, numGlyphs, shortVersion) {\n const p = new parse.Parser(data, start);\n const parseFn = shortVersion ? p.parseUShort : p.parseULong;\n // There is an extra entry after the last index element to compute the length of the last glyph.\n // That's why we use numGlyphs + 1.\n const glyphOffsets = [];\n for (let i = 0; i < numGlyphs + 1; i += 1) {\n let glyphOffset = parseFn.call(p);\n if (shortVersion) {\n // The short table version stores the actual offset divided by 2.\n glyphOffset *= 2;\n }\n\n glyphOffsets.push(glyphOffset);\n }\n\n return glyphOffsets;\n}\n\nexport default { parse: parseLocaTable };\n","// opentype.js\n// https://github.com/opentypejs/opentype.js\n// (c) 2015 Frederik De Bleser\n// opentype.js may be freely distributed under the MIT license.\n\n/* global DataView, Uint8Array, XMLHttpRequest */\n\nimport 'string.prototype.codepointat';\nimport inflate from 'tiny-inflate';\nimport Font from './font';\nimport Glyph from './glyph';\nimport { CmapEncoding, GlyphNames, addGlyphNames } from './encoding';\nimport parse from './parse';\nimport BoundingBox from './bbox';\nimport Path from './path';\nimport { nodeBufferToArrayBuffer } from './util';\nimport cmap from './tables/cmap';\nimport cff from './tables/cff';\nimport fvar from './tables/fvar';\nimport glyf from './tables/glyf';\nimport gdef from './tables/gdef';\nimport gpos from './tables/gpos';\nimport gsub from './tables/gsub';\nimport head from './tables/head';\nimport hhea from './tables/hhea';\nimport hmtx from './tables/hmtx';\nimport kern from './tables/kern';\nimport ltag from './tables/ltag';\nimport loca from './tables/loca';\nimport maxp from './tables/maxp';\nimport _name from './tables/name';\nimport os2 from './tables/os2';\nimport post from './tables/post';\nimport meta from './tables/meta';\n\n/**\n * The opentype library.\n * @namespace opentype\n */\n\n// File loaders /////////////////////////////////////////////////////////\n/**\n * Loads a font from a file. The callback throws an error message as the first parameter if it fails\n * and the font as an ArrayBuffer in the second parameter if it succeeds.\n * @param {string} path - The path of the file\n * @param {Function} callback - The function to call when the font load completes\n */\nfunction loadFromFile(path, callback) {\n const fs = require('fs');\n fs.readFile(path, function(err, buffer) {\n if (err) {\n return callback(err.message);\n }\n\n callback(null, nodeBufferToArrayBuffer(buffer));\n });\n}\n/**\n * Loads a font from a URL. The callback throws an error message as the first parameter if it fails\n * and the font as an ArrayBuffer in the second parameter if it succeeds.\n * @param {string} url - The URL of the font file.\n * @param {Function} callback - The function to call when the font load completes\n */\nfunction loadFromUrl(url, callback) {\n const request = new XMLHttpRequest();\n request.open('get', url, true);\n request.responseType = 'arraybuffer';\n request.onload = function() {\n if (request.response) {\n return callback(null, request.response);\n } else {\n return callback('Font could not be loaded: ' + request.statusText);\n }\n };\n\n request.onerror = function () {\n callback('Font could not be loaded');\n };\n\n request.send();\n}\n\n// Table Directory Entries //////////////////////////////////////////////\n/**\n * Parses OpenType table entries.\n * @param {DataView}\n * @param {Number}\n * @return {Object[]}\n */\nfunction parseOpenTypeTableEntries(data, numTables) {\n const tableEntries = [];\n let p = 12;\n for (let i = 0; i < numTables; i += 1) {\n const tag = parse.getTag(data, p);\n const checksum = parse.getULong(data, p + 4);\n const offset = parse.getULong(data, p + 8);\n const length = parse.getULong(data, p + 12);\n tableEntries.push({tag: tag, checksum: checksum, offset: offset, length: length, compression: false});\n p += 16;\n }\n\n return tableEntries;\n}\n\n/**\n * Parses WOFF table entries.\n * @param {DataView}\n * @param {Number}\n * @return {Object[]}\n */\nfunction parseWOFFTableEntries(data, numTables) {\n const tableEntries = [];\n let p = 44; // offset to the first table directory entry.\n for (let i = 0; i < numTables; i += 1) {\n const tag = parse.getTag(data, p);\n const offset = parse.getULong(data, p + 4);\n const compLength = parse.getULong(data, p + 8);\n const origLength = parse.getULong(data, p + 12);\n let compression;\n if (compLength < origLength) {\n compression = 'WOFF';\n } else {\n compression = false;\n }\n\n tableEntries.push({tag: tag, offset: offset, compression: compression,\n compressedLength: compLength, length: origLength});\n p += 20;\n }\n\n return tableEntries;\n}\n\n/**\n * @typedef TableData\n * @type Object\n * @property {DataView} data - The DataView\n * @property {number} offset - The data offset.\n */\n\n/**\n * @param {DataView}\n * @param {Object}\n * @return {TableData}\n */\nfunction uncompressTable(data, tableEntry) {\n if (tableEntry.compression === 'WOFF') {\n const inBuffer = new Uint8Array(data.buffer, tableEntry.offset + 2, tableEntry.compressedLength - 2);\n const outBuffer = new Uint8Array(tableEntry.length);\n inflate(inBuffer, outBuffer);\n if (outBuffer.byteLength !== tableEntry.length) {\n throw new Error('Decompression error: ' + tableEntry.tag + ' decompressed length doesn\\'t match recorded length');\n }\n\n const view = new DataView(outBuffer.buffer, 0);\n return {data: view, offset: 0};\n } else {\n return {data: data, offset: tableEntry.offset};\n }\n}\n\n// Public API ///////////////////////////////////////////////////////////\n\n/**\n * Parse the OpenType file data (as an ArrayBuffer) and return a Font object.\n * Throws an error if the font could not be parsed.\n * @param {ArrayBuffer}\n * @param {Object} opt - options for parsing\n * @return {opentype.Font}\n */\nfunction parseBuffer(buffer, opt) {\n opt = (opt === undefined || opt === null) ? {} : opt;\n\n let indexToLocFormat;\n let ltagTable;\n\n // Since the constructor can also be called to create new fonts from scratch, we indicate this\n // should be an empty font that we'll fill with our own data.\n const font = new Font({empty: true});\n\n // OpenType fonts use big endian byte ordering.\n // We can't rely on typed array view types, because they operate with the endianness of the host computer.\n // Instead we use DataViews where we can specify endianness.\n const data = new DataView(buffer, 0);\n let numTables;\n let tableEntries = [];\n const signature = parse.getTag(data, 0);\n if (signature === String.fromCharCode(0, 1, 0, 0) || signature === 'true' || signature === 'typ1') {\n font.outlinesFormat = 'truetype';\n numTables = parse.getUShort(data, 4);\n tableEntries = parseOpenTypeTableEntries(data, numTables);\n } else if (signature === 'OTTO') {\n font.outlinesFormat = 'cff';\n numTables = parse.getUShort(data, 4);\n tableEntries = parseOpenTypeTableEntries(data, numTables);\n } else if (signature === 'wOFF') {\n const flavor = parse.getTag(data, 4);\n if (flavor === String.fromCharCode(0, 1, 0, 0)) {\n font.outlinesFormat = 'truetype';\n } else if (flavor === 'OTTO') {\n font.outlinesFormat = 'cff';\n } else {\n throw new Error('Unsupported OpenType flavor ' + signature);\n }\n\n numTables = parse.getUShort(data, 12);\n tableEntries = parseWOFFTableEntries(data, numTables);\n } else {\n throw new Error('Unsupported OpenType signature ' + signature);\n }\n\n let cffTableEntry;\n let fvarTableEntry;\n let glyfTableEntry;\n let gdefTableEntry;\n let gposTableEntry;\n let gsubTableEntry;\n let hmtxTableEntry;\n let kernTableEntry;\n let locaTableEntry;\n let nameTableEntry;\n let metaTableEntry;\n let p;\n\n for (let i = 0; i < numTables; i += 1) {\n const tableEntry = tableEntries[i];\n let table;\n switch (tableEntry.tag) {\n case 'cmap':\n table = uncompressTable(data, tableEntry);\n font.tables.cmap = cmap.parse(table.data, table.offset);\n font.encoding = new CmapEncoding(font.tables.cmap);\n break;\n case 'cvt ' :\n table = uncompressTable(data, tableEntry);\n p = new parse.Parser(table.data, table.offset);\n font.tables.cvt = p.parseShortList(tableEntry.length / 2);\n break;\n case 'fvar':\n fvarTableEntry = tableEntry;\n break;\n case 'fpgm' :\n table = uncompressTable(data, tableEntry);\n p = new parse.Parser(table.data, table.offset);\n font.tables.fpgm = p.parseByteList(tableEntry.length);\n break;\n case 'head':\n table = uncompressTable(data, tableEntry);\n font.tables.head = head.parse(table.data, table.offset);\n font.unitsPerEm = font.tables.head.unitsPerEm;\n indexToLocFormat = font.tables.head.indexToLocFormat;\n break;\n case 'hhea':\n table = uncompressTable(data, tableEntry);\n font.tables.hhea = hhea.parse(table.data, table.offset);\n font.ascender = font.tables.hhea.ascender;\n font.descender = font.tables.hhea.descender;\n font.numberOfHMetrics = font.tables.hhea.numberOfHMetrics;\n break;\n case 'hmtx':\n hmtxTableEntry = tableEntry;\n break;\n case 'ltag':\n table = uncompressTable(data, tableEntry);\n ltagTable = ltag.parse(table.data, table.offset);\n break;\n case 'maxp':\n table = uncompressTable(data, tableEntry);\n font.tables.maxp = maxp.parse(table.data, table.offset);\n font.numGlyphs = font.tables.maxp.numGlyphs;\n break;\n case 'name':\n nameTableEntry = tableEntry;\n break;\n case 'OS/2':\n table = uncompressTable(data, tableEntry);\n font.tables.os2 = os2.parse(table.data, table.offset);\n break;\n case 'post':\n table = uncompressTable(data, tableEntry);\n font.tables.post = post.parse(table.data, table.offset);\n font.glyphNames = new GlyphNames(font.tables.post);\n break;\n case 'prep' :\n table = uncompressTable(data, tableEntry);\n p = new parse.Parser(table.data, table.offset);\n font.tables.prep = p.parseByteList(tableEntry.length);\n break;\n case 'glyf':\n glyfTableEntry = tableEntry;\n break;\n case 'loca':\n locaTableEntry = tableEntry;\n break;\n case 'CFF ':\n cffTableEntry = tableEntry;\n break;\n case 'kern':\n kernTableEntry = tableEntry;\n break;\n case 'GDEF':\n gdefTableEntry = tableEntry;\n break;\n case 'GPOS':\n gposTableEntry = tableEntry;\n break;\n case 'GSUB':\n gsubTableEntry = tableEntry;\n break;\n case 'meta':\n metaTableEntry = tableEntry;\n break;\n }\n }\n\n const nameTable = uncompressTable(data, nameTableEntry);\n font.tables.name = _name.parse(nameTable.data, nameTable.offset, ltagTable);\n font.names = font.tables.name;\n\n if (glyfTableEntry && locaTableEntry) {\n const shortVersion = indexToLocFormat === 0;\n const locaTable = uncompressTable(data, locaTableEntry);\n const locaOffsets = loca.parse(locaTable.data, locaTable.offset, font.numGlyphs, shortVersion);\n const glyfTable = uncompressTable(data, glyfTableEntry);\n font.glyphs = glyf.parse(glyfTable.data, glyfTable.offset, locaOffsets, font, opt);\n } else if (cffTableEntry) {\n const cffTable = uncompressTable(data, cffTableEntry);\n cff.parse(cffTable.data, cffTable.offset, font, opt);\n } else {\n throw new Error('Font doesn\\'t contain TrueType or CFF outlines.');\n }\n\n const hmtxTable = uncompressTable(data, hmtxTableEntry);\n hmtx.parse(font, hmtxTable.data, hmtxTable.offset, font.numberOfHMetrics, font.numGlyphs, font.glyphs, opt);\n addGlyphNames(font, opt);\n\n if (kernTableEntry) {\n const kernTable = uncompressTable(data, kernTableEntry);\n font.kerningPairs = kern.parse(kernTable.data, kernTable.offset);\n } else {\n font.kerningPairs = {};\n }\n\n if (gdefTableEntry) {\n const gdefTable = uncompressTable(data, gdefTableEntry);\n font.tables.gdef = gdef.parse(gdefTable.data, gdefTable.offset);\n }\n\n if (gposTableEntry) {\n const gposTable = uncompressTable(data, gposTableEntry);\n font.tables.gpos = gpos.parse(gposTable.data, gposTable.offset);\n font.position.init();\n }\n\n if (gsubTableEntry) {\n const gsubTable = uncompressTable(data, gsubTableEntry);\n font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset);\n }\n\n if (fvarTableEntry) {\n const fvarTable = uncompressTable(data, fvarTableEntry);\n font.tables.fvar = fvar.parse(fvarTable.data, fvarTable.offset, font.names);\n }\n\n if (metaTableEntry) {\n const metaTable = uncompressTable(data, metaTableEntry);\n font.tables.meta = meta.parse(metaTable.data, metaTable.offset);\n font.metas = font.tables.meta;\n }\n\n return font;\n}\n\n/**\n * Asynchronously load the font from a URL or a filesystem. When done, call the callback\n * with two arguments `(err, font)`. The `err` will be null on success,\n * the `font` is a Font object.\n * We use the node.js callback convention so that\n * opentype.js can integrate with frameworks like async.js.\n * @alias opentype.load\n * @param {string} url - The URL of the font to load.\n * @param {Function} callback - The callback.\n */\nfunction load(url, callback, opt) {\n opt = (opt === undefined || opt === null) ? {} : opt;\n const isNode = typeof window === 'undefined';\n const loadFn = isNode && !opt.isUrl ? loadFromFile : loadFromUrl;\n\n return new Promise((resolve, reject) => {\n loadFn(url, function(err, arrayBuffer) {\n if (err) {\n if (callback) {\n return callback(err);\n } else {\n reject(err);\n }\n }\n let font;\n try {\n font = parseBuffer(arrayBuffer, opt);\n } catch (e) {\n if (callback) {\n return callback(e, null);\n } else {\n reject(e);\n }\n }\n if (callback) {\n return callback(null, font);\n } else {\n resolve(font);\n }\n });\n });\n}\n\n/**\n * Synchronously load the font from a URL or file.\n * When done, returns the font object or throws an error.\n * @alias opentype.loadSync\n * @param {string} url - The URL of the font to load.\n * @param {Object} opt - opt.lowMemory\n * @return {opentype.Font}\n */\nfunction loadSync(url, opt) {\n const fs = require('fs');\n const buffer = fs.readFileSync(url);\n return parseBuffer(nodeBufferToArrayBuffer(buffer), opt);\n}\n\nexport {\n Font,\n Glyph,\n Path,\n BoundingBox,\n parse as _parse,\n parseBuffer as parse,\n load,\n loadSync\n};\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { BoundingBox } from '@babylonjs/core/Culling/boundingBox';\r\nimport { MultiMaterial } from '@babylonjs/core/Materials/multiMaterial';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Color4, Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { CreatePlane } from '@babylonjs/core/Meshes/Builders/planeBuilder';\r\nimport { SphereBuilder as BabylonSphereBuilder } from '@babylonjs/core/Meshes/Builders/sphereBuilder';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport '@babylonjs/core/Rendering/outlineRenderer';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eAxis, eCylinderCap, eRenderMode } from '@models/classes/enums';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { IUvData } from '@models/classes/kb3d-models';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { MaterialNode } from '@models/classes/materials/material-node';\r\nimport {\r\n MeshGroupNode,\r\n SketchNode,\r\n SpaceNode,\r\n TextNode,\r\n isBoxMesh,\r\n isConeMesh,\r\n isCylinderMesh,\r\n isDiscMesh,\r\n isPlaneMesh,\r\n isSketchNode,\r\n isSphereMesh,\r\n isTextNode,\r\n isTorusMesh,\r\n} from '@models/classes/meshes';\r\nimport { CustomMeshNode } from '@models/classes/meshes/custom-mesh-node';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport {\r\n isCustomMeshNode,\r\n isMeshGroupNode,\r\n isMeshNode,\r\n isPrimitiveMeshNode,\r\n} from '@models/classes/meshes/mesh-utilities';\r\nimport { PrimitiveMeshNode } from '@models/classes/meshes/primitive-mesh-node';\r\nimport { KbColor, KbGeometry } from '@models/classes/primitives';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { SceneNode, isSceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { isDefined } from '@models/classes/utilities';\r\nimport { eParentChangeBehavior } from '@models/interfaces/settings';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SettingsManagerService } from '@models/services/settings-manager-service';\r\nimport { eSideOrientationBabylonMap } from '@view/helpers/enum-maps';\r\nimport { SubmeshVertexData, verifyGeometry } from '@view/helpers/geometry-helper';\r\nimport { toRadians } from '@view/helpers/math-helper';\r\nimport { CylinderBuilder } from '@view/helpers/mesh-builders/cylinder-builder';\r\nimport { DiscBuilder } from '@view/helpers/mesh-builders/disc-builder';\r\nimport { PlaneBuilder } from '@view/helpers/mesh-builders/plane-builder';\r\nimport { SphereBuilder } from '@view/helpers/mesh-builders/sphere-builder';\r\nimport { TorusBuilder } from '@view/helpers/mesh-builders/torus-builder';\r\nimport { TextMeshFont, TextMeshVertexData } from '@view/helpers/text-mesh-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport {\r\n axisToVector3,\r\n calculateFaceNormal,\r\n fillSketchPolygon,\r\n parseSketchGeometry,\r\n} from '@view/modules/sketching/util';\r\nimport { parse as fontParse } from 'opentype.js';\r\nimport { Subject } from 'rxjs';\r\nimport { take, takeUntil } from 'rxjs/operators';\r\nimport { Renderer } from './renderer';\r\nimport { RendererManager } from './renderer-manager';\r\nimport { ShadowManager } from './shadow-manager';\r\n\r\nconst primitiveShapeProperties = new Set([\r\n 'height',\r\n 'width',\r\n 'depth',\r\n 'radius',\r\n 'radiusTop',\r\n 'radiusBottom',\r\n 'thickness',\r\n 'arc',\r\n 'latitudeStart',\r\n 'latitudeSlice',\r\n 'tessellation',\r\n 'subdivisions',\r\n 'capMode',\r\n 'segments',\r\n]);\r\n\r\nconst PIVOT_GIZMO_SCALE = 0.33;\r\n\r\nconst capModeMap: Record = {\r\n [eCylinderCap.both]: Mesh.CAP_ALL,\r\n [eCylinderCap.start]: Mesh.CAP_START,\r\n [eCylinderCap.end]: Mesh.CAP_END,\r\n [eCylinderCap.none]: Mesh.NO_CAP,\r\n};\r\n\r\ntype meshNodeSharedChanges = ITrackedClass['changes'];\r\nconst textMeshFonts = new Map();\r\n\r\n// const lineColor = new Color4(1, 1, 1);\r\n// const selectedLineColor = new Color4(1, 0, 0);\r\n\r\nexport class MeshRenderer extends Renderer {\r\n utilityLayer: UtilityLayerRenderer;\r\n disposed = new Subject();\r\n pivotGizmos = new Map();\r\n\r\n sketchPreviews = new Map();\r\n sketchTracings = new Map();\r\n sketchPlanePreviews = new Map();\r\n\r\n private renderMode: eRenderMode;\r\n\r\n constructor(\r\n viewer: KbViewer,\r\n scene: Scene,\r\n private rendererManager: RendererManager,\r\n private shadowManager: ShadowManager\r\n ) {\r\n super(viewer, scene);\r\n this.utilityLayer = viewer.utilityLayer;\r\n\r\n const tempVector = new Vector3();\r\n viewer.afterRender.pipe(takeUntil(this.disposed)).subscribe(() => {\r\n let dist: number;\r\n const camera = this.utilityLayer.utilityLayerScene.activeCamera!;\r\n\r\n this.pivotGizmos.forEach(gizmo => {\r\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n dist = ((camera.orthoRight || 0) - (camera.orthoLeft || 0)) / 2;\r\n } else {\r\n const cameraPosition = camera.globalPosition;\r\n gizmo.position.subtractToRef(cameraPosition, tempVector);\r\n dist = tempVector.length() * PIVOT_GIZMO_SCALE;\r\n }\r\n\r\n gizmo.scaling.set(dist, dist, dist);\r\n });\r\n });\r\n }\r\n\r\n modelToken = Token.SpaceNode;\r\n handlesNode(node: Kb3dObject) {\r\n return isMeshNode(node) || isMeshGroupNode(node) || (isSceneNode(node) && node.isNested());\r\n }\r\n\r\n setRenderMode(mode: eRenderMode, sceneNode: SceneNode) {\r\n this.renderMode = mode;\r\n this.babylonMap.forEach(mesh => {\r\n if (mesh instanceof Mesh) {\r\n this.setRenderModeOnMesh(mesh, sceneNode);\r\n }\r\n });\r\n }\r\n\r\n dispose() {\r\n super.dispose();\r\n this.pivotGizmos.forEach(gizmo => {\r\n gizmo.dispose();\r\n });\r\n this.pivotGizmos.clear();\r\n this.disposed.next();\r\n }\r\n\r\n loadNewGeometry(node: CustomMeshNode) {\r\n node._loading = node.geometryId;\r\n const meshService = node._manager!.getService(Token.MeshService);\r\n meshService!.hydrateGeometry(node).then(() => {\r\n node._loading = null;\r\n this.invalidateBoundingBox(node);\r\n });\r\n }\r\n\r\n parentsVisible(node: SpaceNode) {\r\n while (node._parent && node._parent instanceof SpaceNode) {\r\n if (!node._parent.visible) {\r\n return false;\r\n }\r\n node = node._parent;\r\n }\r\n return true;\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n const isNewMesh = !this.get3d(node);\r\n if (isCustomMeshNode(node)) {\r\n if (\r\n node.visible &&\r\n this.parentsVisible(node) &&\r\n node.hasGeometry &&\r\n !node._geometry &&\r\n !node.geometryLoaded &&\r\n !node._loading\r\n ) {\r\n this.loadNewGeometry(node);\r\n }\r\n }\r\n\r\n const mesh = this.createOrUpdateMesh(node);\r\n\r\n const pivotGizmo = this.pivotGizmos.get(node._dynamicId);\r\n if (node._selected && mesh instanceof Mesh && !this.viewer.highlighter.has(node)) {\r\n this.viewer.highlighter.add(node, KbColor.Red());\r\n if (pivotGizmo) {\r\n pivotGizmo.setEnabled(true);\r\n }\r\n } else if (!node._selected && mesh instanceof Mesh && this.viewer.highlighter.has(node)) {\r\n this.viewer.highlighter.remove(node);\r\n if (pivotGizmo) {\r\n pivotGizmo.setEnabled(false);\r\n }\r\n }\r\n\r\n if (node instanceof SketchNode) {\r\n if (node._selected && node.visible) {\r\n const oldPreview = this.sketchPlanePreviews.get(node.id);\r\n if (oldPreview) {\r\n oldPreview.dispose();\r\n }\r\n const mesh = this.createSketchPlaneVisualization(node);\r\n if (node.visible && mesh) {\r\n this.sketchPlanePreviews.set(node.id, mesh);\r\n } else {\r\n mesh?.dispose();\r\n this.sketchPlanePreviews.delete(node.id);\r\n }\r\n } else if (!node._selected || !node.visible) {\r\n const SketchPlancePreviewMesh = this.sketchPlanePreviews.get(node.id);\r\n SketchPlancePreviewMesh?.dispose();\r\n this.sketchPlanePreviews.delete(node.id);\r\n }\r\n }\r\n\r\n if (!mesh) {\r\n throw Error('Could not create mesh');\r\n }\r\n\r\n if (isNewMesh || node.changes.has('_parent')) {\r\n this.updateParentMeshFromNode(node, mesh, isNewMesh);\r\n }\r\n }\r\n\r\n rebuildBaseGeometry(node: SpaceNode, preTransformChanged = false) {\r\n const mesh = this.get3d(node);\r\n if (mesh && mesh instanceof Mesh) {\r\n let meshVertexData: SubmeshVertexData | null = null;\r\n\r\n if (isPrimitiveMeshNode(node)) {\r\n const newMesh = this.createPrimitiveMesh(node);\r\n meshVertexData = SubmeshVertexData.ExtractFromMesh(newMesh);\r\n newMesh.dispose();\r\n\r\n if (isDefined(node.uvOverrides)) {\r\n this.setBabylonUvData(node.uvOverrides, meshVertexData);\r\n }\r\n\r\n if (node instanceof MeshNode && meshVertexData) {\r\n // Always pretransform primitives as they are always rebuilt from scratch\r\n this.preTransformVertices(meshVertexData, node);\r\n }\r\n } else if (isCustomMeshNode(node)) {\r\n // If custom geometry does not have a geometry, don't do anything. Return null.\r\n if (node._geometry && node._geometry.positions) {\r\n meshVertexData = this.getMeshVertexData(node);\r\n }\r\n } else if (isSketchNode(node)) {\r\n meshVertexData = this.buildSketchGeometry(node);\r\n } else if (isTextNode(node) && isTrackedClass(node)) {\r\n meshVertexData = this.buildTextGeometry(node);\r\n } else {\r\n throw Error('geometry needs to be recalculated but mesh is not a valid primitive or custom mesh');\r\n }\r\n\r\n return meshVertexData;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private buildSketchGeometry(node: SketchNode) {\r\n const result = new SubmeshVertexData();\r\n const positionVectors: Vector3[] = [];\r\n let pathSegmentIndices: number[][] = [];\r\n\r\n // Keep track of the path groups so we can match the hole paths with the groups in the vertex data\r\n // The key is the path group key, and the value is the indices of the generated polygons that are part of that path\r\n // One connected path may have multiple sketch paths because it requires different types of curves\r\n const pathGroupKeys = new Map();\r\n const holePathsReferencingKeys: string[] = [];\r\n\r\n let currentPath: number[] | undefined;\r\n let lastPoint: Vector3 | undefined;\r\n for (let i = 0; i < node.paths.length; i++) {\r\n const path = node.paths[i];\r\n\r\n if (path._points && path._points.length > 0) {\r\n let thisPoint: Vector3 | undefined;\r\n\r\n for (let iP = 0; iP < path._points.length; iP++) {\r\n const { x, y, z } = path._points[iP];\r\n thisPoint = new Vector3(x, y, z);\r\n\r\n // Separate paths that don't have a shared start/end to different logical paths\r\n if (!lastPoint || !thisPoint.equals(lastPoint)) {\r\n if (iP === 0 || !currentPath) {\r\n if (!pathGroupKeys.has(path.pathGroupKey)) {\r\n pathGroupKeys.set(path.pathGroupKey, pathSegmentIndices.length);\r\n }\r\n if (path.holeForPathGroup) {\r\n holePathsReferencingKeys[pathSegmentIndices.length] = path.holeForPathGroup;\r\n }\r\n currentPath = [];\r\n pathSegmentIndices.push(currentPath);\r\n }\r\n\r\n currentPath.push(positionVectors.length);\r\n positionVectors.push(thisPoint);\r\n }\r\n\r\n lastPoint = thisPoint;\r\n }\r\n }\r\n }\r\n\r\n if (positionVectors.length === 0 || pathSegmentIndices.length === 0) {\r\n return null;\r\n }\r\n\r\n const positions: number[] = [];\r\n const indices: number[] = [];\r\n const normals: number[] = [];\r\n const paths: number[] = [];\r\n\r\n if (node.flipPath) {\r\n pathSegmentIndices.reverse();\r\n pathSegmentIndices.forEach(segment => segment.reverse());\r\n }\r\n\r\n const primaryNormal = axisToVector3(node.normal);\r\n // /**\r\n // * We want the sketch to always \"face\" in the positive direction of the axis for consistency\r\n // * Otherwise it's indeterminate which way the sketch will face and makes the sketch hard to manage\r\n // * because it depends on the handed-ness of the points (clockwise or counter-clockwise)\r\n // */\r\n pathSegmentIndices.forEach(segment => {\r\n const segmentPositions: Vector3[] = [];\r\n for (let i = 0; i < segment.length; i++) {\r\n const point = positionVectors[segment[i]];\r\n segmentPositions.push(point);\r\n }\r\n\r\n // However, don't flip non-closed paths because it makes no sense and may be a drive curve\r\n const closedPath =\r\n (segmentPositions.length > 1 &&\r\n segmentPositions[0].equalsWithEpsilon(segmentPositions[segmentPositions.length - 1])) ||\r\n node.closePath;\r\n if (closedPath) {\r\n const faceNormal = calculateFaceNormal(segmentPositions);\r\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\r\n if (Vector3.Dot(faceNormal, primaryNormal) < 0) {\r\n segment.reverse();\r\n }\r\n }\r\n });\r\n\r\n // Parse the holes and match them to their parent polygons\r\n const holesByPathsWithIndices: number[][][] = [];\r\n pathSegmentIndices.forEach((segment, idx) => {\r\n if (!holePathsReferencingKeys[idx]) {\r\n return;\r\n }\r\n const parentPathIndex = pathGroupKeys.get(holePathsReferencingKeys[idx]);\r\n if (parentPathIndex === undefined) {\r\n return;\r\n }\r\n // This segment is a hole\r\n if (!holesByPathsWithIndices[parentPathIndex]) {\r\n holesByPathsWithIndices[parentPathIndex] = [];\r\n }\r\n holesByPathsWithIndices[parentPathIndex].push(segment);\r\n });\r\n\r\n if (node.addFace) {\r\n // We have to reorder the segment indices because the vertex position order gets modified by the face fill\r\n // Due to holes needing be be defined alongside the parent polygons\r\n const reorderedPathSegmentIndices: number[][] = [];\r\n let positionPointer = 0;\r\n pathSegmentIndices.forEach((segment, idx) => {\r\n // Skip holes in the loop since they are processed with their parent polygons\r\n if (holePathsReferencingKeys[idx]) {\r\n return;\r\n }\r\n const segmentPositions: Vector3[] = [];\r\n const segmentIndices: number[] = [];\r\n for (let i = 0; i < segment.length; i++) {\r\n const point = positionVectors[segment[i]];\r\n segmentPositions.push(point);\r\n segmentIndices.push(positionPointer);\r\n positionPointer++;\r\n }\r\n reorderedPathSegmentIndices.push(segmentIndices);\r\n\r\n const holesPositions: Vector3[][] = [];\r\n if (holesByPathsWithIndices[idx]) {\r\n for (let hi = 0; hi < holesByPathsWithIndices[idx].length; hi++) {\r\n const hole = holesByPathsWithIndices[idx][hi];\r\n const holeData: Vector3[] = [];\r\n const holeIndices: number[] = [];\r\n for (let i = 0; i < hole.length; i++) {\r\n const point = positionVectors[hole[i]];\r\n holeData.push(point);\r\n holeIndices.push(positionPointer);\r\n positionPointer++;\r\n }\r\n holesPositions.push(holeData);\r\n reorderedPathSegmentIndices.push(holeIndices);\r\n }\r\n }\r\n\r\n const newMeshVertices = fillSketchPolygon(\r\n segmentPositions,\r\n node.flipPath,\r\n primaryNormal,\r\n holesPositions\r\n );\r\n\r\n // Fix the indices to point at the right vertices\r\n const startIndex = positions.length / 3;\r\n for (let i = 0; i < newMeshVertices.indices.length; i++) {\r\n newMeshVertices.indices[i] += startIndex;\r\n }\r\n\r\n indices.push(...newMeshVertices.indices);\r\n positions.push(...newMeshVertices.positions);\r\n normals.push(...newMeshVertices.normals);\r\n });\r\n\r\n //const normals = new Float32Array(positionVectors.length * 3);\r\n const uvs = new Float32Array(positionVectors.length * 2);\r\n uvs.fill(0);\r\n\r\n result.positions = new Float32Array(positions);\r\n result.indices = new Uint16Array(indices);\r\n result.normals = new Float32Array(normals);\r\n result.uvs = uvs;\r\n pathSegmentIndices = reorderedPathSegmentIndices;\r\n } else {\r\n const positions = new Float32Array(positionVectors.length * 3);\r\n for (let i = 0; i < positionVectors.length; i++) {\r\n const point = positionVectors[i];\r\n positions.set([point.x, point.y, point.z], i * 3);\r\n }\r\n result.positions = positions;\r\n }\r\n\r\n const indexMapToGrouped: number[] = [];\r\n let i = 0;\r\n pathSegmentIndices.forEach((segment, indexOfPath) => {\r\n // Skip holes since they are processed later\r\n if (holePathsReferencingKeys[indexOfPath]) {\r\n return;\r\n }\r\n indexMapToGrouped[indexOfPath] = i;\r\n for (let i = 1; i < segment.length; i++) {\r\n paths.push(segment[i - 1], segment[i]);\r\n }\r\n\r\n if (segment.length > 2 && node.closePath) {\r\n paths.push(segment[segment.length - 1], segment[0]);\r\n }\r\n i++;\r\n });\r\n\r\n const holes: number[] = [];\r\n pathSegmentIndices.forEach((segment, indexOfPath) => {\r\n // Add holes after the regular polys\r\n if (!holePathsReferencingKeys[indexOfPath]) {\r\n return;\r\n }\r\n const parentPathIndex = pathGroupKeys.get(holePathsReferencingKeys[indexOfPath]);\r\n if (parentPathIndex === undefined) {\r\n return;\r\n }\r\n\r\n holes.push(indexMapToGrouped[parentPathIndex], paths.length);\r\n for (let i = 1; i < segment.length; i++) {\r\n paths.push(segment[i - 1], segment[i]);\r\n }\r\n\r\n if (segment.length > 2 && node.closePath) {\r\n paths.push(segment[segment.length - 1], segment[0]);\r\n }\r\n });\r\n\r\n result.paths = new Uint16Array(paths);\r\n result.holes = new Uint16Array(holes);\r\n node._sketchPoints = new Float32Array(result.positions);\r\n let counter = -1;\r\n const startingPoints = [];\r\n //for loop building the starting points array which stores sketchControlPoints at the start of a line segment\r\n for (let i = 0; i < node.paths.length; i++) {\r\n const path = node.paths[i];\r\n let lastPoint: Vector3 | undefined;\r\n\r\n if (path._points && path._points.length > 0) {\r\n let thisPoint: Vector3 | undefined;\r\n\r\n for (let iP = 0; iP < path._points.length; iP++) {\r\n const { x, y, z } = path._points[iP];\r\n thisPoint = new Vector3(x, y, z);\r\n\r\n startingPoints.push(counter);\r\n if (!lastPoint || !thisPoint.equals(lastPoint)) {\r\n if (iP === 0 || !currentPath) {\r\n startingPoints.pop();\r\n }\r\n }\r\n\r\n lastPoint = thisPoint;\r\n counter++;\r\n }\r\n }\r\n }\r\n node._lineSegmentStartingPoints = startingPoints;\r\n node.calculatedBoundingBox = this.calculateSketchBoundingBox(node);\r\n\r\n return result;\r\n }\r\n\r\n private updateSketchPreview(\r\n sketchNode: ITrackedClass,\r\n vertexData: SubmeshVertexData | null,\r\n mesh: AbstractMesh\r\n ) {\r\n const previewMesh = this.sketchPreviews.get(sketchNode._dynamicId);\r\n\r\n const { segments } = parseSketchGeometry(vertexData);\r\n\r\n if (segments.length > 0) {\r\n const baseColor = sketchNode._rootScene?.edgeColor\r\n ? sketchNode._rootScene.edgeColor.toColor4()\r\n : new Color4(1, 1, 1, 1);\r\n const colors: Color4[][] = [];\r\n\r\n segments.forEach(segmentPoints => {\r\n const segmentColors: Color4[] = [];\r\n colors.push(segmentColors);\r\n segmentPoints.forEach(() => {\r\n segmentColors.push(baseColor);\r\n });\r\n });\r\n\r\n const lineColor = colors.length > 0 ? colors : undefined;\r\n\r\n if (\r\n previewMesh &&\r\n !sketchNode.changes.has('addFace') &&\r\n !sketchNode.changes.has('paths') &&\r\n !sketchNode.changes.has('closePath')\r\n ) {\r\n MeshBuilder.CreateLineSystem(\r\n `${sketchNode._dynamicId}_preview`,\r\n {\r\n lines: segments,\r\n instance: previewMesh,\r\n colors: lineColor,\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else {\r\n if (previewMesh) {\r\n previewMesh.dispose();\r\n }\r\n const newPreviewMesh = MeshBuilder.CreateLineSystem(\r\n `${sketchNode._dynamicId}_preview`,\r\n {\r\n lines: segments,\r\n colors: lineColor,\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n this.sketchPreviews.set(sketchNode._dynamicId, newPreviewMesh);\r\n newPreviewMesh.parent = mesh;\r\n newPreviewMesh.enableEdgesRendering();\r\n newPreviewMesh.edgesColor = baseColor;\r\n this.viewer.camera.maintainNodeScreenSize(newPreviewMesh, (dist: number, mode: number) => {\r\n if (mode === Camera.PERSPECTIVE_CAMERA) {\r\n newPreviewMesh.edgesWidth = dist * 0.25;\r\n } else {\r\n newPreviewMesh.edgesWidth = 4;\r\n }\r\n });\r\n }\r\n } else if (previewMesh) {\r\n previewMesh.dispose();\r\n this.sketchPreviews.delete(sketchNode._dynamicId);\r\n }\r\n }\r\n\r\n private updateSketchTracing(\r\n sketchNode: ITrackedClass,\r\n vertexData: SubmeshVertexData | null,\r\n mesh: AbstractMesh\r\n ) {\r\n const previewMesh = this.sketchTracings.get(sketchNode._dynamicId);\r\n const sketchColor = sketchNode.pathColor.toColor4();\r\n if (sketchNode.tracePath) {\r\n if (previewMesh) {\r\n previewMesh.dispose();\r\n }\r\n //create/update drawings\r\n const linePoints: Vector3[] = [];\r\n sketchNode.paths.forEach(path => {\r\n path._points.forEach(point => {\r\n linePoints.push(new Vector3(point.x, point.y, point.z));\r\n });\r\n });\r\n if (sketchNode.closePath) {\r\n const point = sketchNode.paths[0]._points[0];\r\n linePoints.push(new Vector3(point.x, point.y, point.z));\r\n }\r\n const lines = Mesh.CreateLines('lines', linePoints, this.scene, true);\r\n lines.enableEdgesRendering();\r\n lines.edgesWidth = sketchNode.lineThickness;\r\n lines.edgesColor = sketchColor;\r\n this.sketchTracings.set(sketchNode._dynamicId, lines);\r\n } else {\r\n if (previewMesh || (previewMesh && sketchNode.tracePath === false)) {\r\n previewMesh.dispose();\r\n this.sketchTracings.delete(sketchNode._dynamicId);\r\n }\r\n }\r\n }\r\n\r\n private buildTextGeometry(node: ITrackedClass): SubmeshVertexData | null {\r\n const fontService = node._manager!.getService(Token.FontService);\r\n\r\n if (!node.fontFile || !node.text) {\r\n return null;\r\n }\r\n\r\n if (!fontService.readyFonts.has(node.fontFile)) {\r\n fontService.loadFontByFile(node.fontFile).then(resultData => {\r\n const fontBuffer = resultData;\r\n if (fontBuffer) {\r\n node.setPropertyIsModified('fontFile', true);\r\n }\r\n });\r\n return null;\r\n } else {\r\n let vertexDataBuilder = textMeshFonts.get(node.fontFile);\r\n\r\n if (!vertexDataBuilder) {\r\n const fontBuffer = fontService.readyFonts.get(node.fontFile)!;\r\n const openTypeFont = fontParse(fontBuffer);\r\n const font = new TextMeshFont(node.fontFile, openTypeFont, this.scene);\r\n vertexDataBuilder = new TextMeshVertexData(font);\r\n textMeshFonts.set(node.fontFile, vertexDataBuilder);\r\n }\r\n return vertexDataBuilder.getText(node.text, node.fontSize, node.charSpacing, node.curveRadius);\r\n }\r\n }\r\n\r\n getMeshGeometry(node: SpaceNode) {\r\n const mesh = this.get3d(node);\r\n if (mesh && mesh instanceof Mesh && mesh._geometry) {\r\n const geometry = SubmeshVertexData.ExtractFromMesh(mesh);\r\n // // Make sure the geometry is valid and actually has some geometry in it so consumers of this function don't have to deep check.\r\n // if(!geometry.indices || !geometry.positions || geometry.indices.length === 0) {\r\n // return null;\r\n // }\r\n\r\n return geometry;\r\n }\r\n return null;\r\n }\r\n\r\n fetchMaterialNode(meshNode: MeshNode, materialId: string) {\r\n const localMaterial = meshNode._manager?.getById(materialId); //find the material if it's local\r\n\r\n return new Promise((resolve, reject) => {\r\n if (localMaterial) {\r\n //it's a local material\r\n resolve(localMaterial);\r\n } else {\r\n // Not a local material, so it's a global or library material\r\n this.rendererManager.material\r\n .loadGlobalMaterial(materialId, meshNode._manager!.services)\r\n .pipe(take(1))\r\n .subscribe(globalLibMaterial => {\r\n if (!globalLibMaterial) {\r\n console.warn(\r\n `Cannot find global material ${materialId} on node ${meshNode.name} (${meshNode.id})`\r\n );\r\n reject('could not load global material');\r\n } else {\r\n resolve(globalLibMaterial);\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n setRenderModeOnMesh(mesh: Mesh, sceneNode: SceneNode) {\r\n const mode = this.renderMode;\r\n if (mesh.geometry) {\r\n if (mode === eRenderMode.edge || mode === eRenderMode.hiddenEdges) {\r\n mesh.enableEdgesRendering(sceneNode.edgeDisplayTolerance);\r\n mesh.renderOutline = true;\r\n\r\n mesh.edgesWidth = sceneNode.edgeWidth;\r\n mesh.edgesColor = sceneNode.edgeColor.toColor4();\r\n mesh.outlineWidth = sceneNode.edgeWidth / 100;\r\n mesh.outlineColor = sceneNode.edgeColor.toColor3();\r\n\r\n // Another option for the hidden edges renderer but results in render artifacts especially when meshes go on top of each other.\r\n // if (mode === eRenderMode.hiddenEdges) {\r\n // mesh.metadata = { ...mesh.metadata, visibility: mesh.visibility };\r\n // mesh.visibility = 0.001;\r\n // }\r\n } else {\r\n // mesh.visibility = mesh.metadata?.visibility || 1;\r\n mesh.renderOutline = false;\r\n mesh.disableEdgesRendering();\r\n }\r\n }\r\n }\r\n\r\n private getMeshVertexData(node: CustomMeshNode) {\r\n if (!node._geometry) {\r\n throw Error('Cannot get vertex data because mesh has no geometry');\r\n }\r\n\r\n let meshVertexData = SubmeshVertexData.FromGeometry(node._geometry);\r\n meshVertexData = this.preTransformVertices(meshVertexData, node, node._geometry);\r\n\r\n return meshVertexData;\r\n }\r\n\r\n private preTransformVertices(meshVertexData: SubmeshVertexData, node: MeshNode, cachedGeometry?: KbGeometry) {\r\n if (node.preTransform && node.preTransform.length !== 16) {\r\n throw Error('invalid pretransform array ');\r\n }\r\n\r\n // If pretransform is not set on the node, the transform we want is the identity matrix (no change from original)\r\n const transform = node.preTransform ? Matrix.FromArray(node.preTransform) : Matrix.Identity();\r\n // Check if the geometry has a transform applied\r\n const existingTransform = cachedGeometry?._hasTransform;\r\n\r\n // If the geometry has already been transformed, then we have to undo that transform to get the correct transform\r\n // Starting with the invert matrix of the existing transform will cancel out the existing transform and result in the original mesh\r\n if (existingTransform) {\r\n Matrix.FromArray(existingTransform).invert().multiplyToRef(transform, transform);\r\n }\r\n\r\n // If the transform we want (taking the existing transform into account) is the identity matrix, do nothing and return the geometry\r\n if (!transform.isIdentity()) {\r\n if (existingTransform) {\r\n // If the geometry has already been transformed, don't overwrite the transform so we don't repeatedly transform it\r\n meshVertexData = meshVertexData.deepClone();\r\n } else if (cachedGeometry) {\r\n // If the geoemtry has no existing transform, set the hasTransform property since it will get mutated with the new transform.\r\n cachedGeometry._hasTransform = node.preTransform;\r\n }\r\n meshVertexData.transform(transform);\r\n }\r\n\r\n return meshVertexData;\r\n }\r\n\r\n private updateParentMeshFromNode(node: ITrackedClass, targetNode: TransformNode, isNewMesh: boolean) {\r\n const parentNode = node._parent;\r\n if (parentNode && parentNode instanceof SpaceNode) {\r\n const isRootScene = parentNode instanceof SceneNode && !parentNode.isNested();\r\n const parent3d = isRootScene\r\n ? this.rendererManager.sceneRenderer.get3d(parentNode as SceneNode)\r\n : this.get3d(parentNode);\r\n if (parent3d) {\r\n if (targetNode instanceof Mesh) {\r\n targetNode.setParent(parent3d);\r\n } else {\r\n targetNode.parent = parent3d;\r\n }\r\n } else {\r\n console.error(`Could not find mesh by ID ${parentNode.id} in scene!`);\r\n }\r\n } else {\r\n return; // if the node has no parent, it's not part of the scene anymore\r\n }\r\n\r\n if (\r\n isNewMesh ||\r\n SettingsManagerService.get('parentChangeBehavior') === eParentChangeBehavior.PRESERVE_PROPERTY\r\n ) {\r\n this.updateMeshTransform(node, targetNode, null);\r\n } else {\r\n node.position = KbVector.FromVec3(targetNode.position);\r\n\r\n if (targetNode.rotationQuaternion) {\r\n node.useEuler = false;\r\n node.setRotationQuaternion(\r\n new KbQuaternion(\r\n targetNode.rotationQuaternion.x,\r\n targetNode.rotationQuaternion.y,\r\n targetNode.rotationQuaternion.z,\r\n targetNode.rotationQuaternion.w\r\n )\r\n );\r\n } else if (node.eulerRotation) {\r\n node.useEuler = true;\r\n node.eulerRotation = new KbVector(targetNode.rotation.x, targetNode.rotation.y, targetNode.rotation.z);\r\n }\r\n\r\n node.scaling = targetNode.scaling.x;\r\n }\r\n this.invalidateBoundingBox(parentNode); //invalidate parent node in the bounding box cache as now it has a new child\r\n }\r\n\r\n private recursiveLoadChildMeshGeometry(node: SpaceNode) {\r\n const children = node.getChildren();\r\n children.forEach(child => {\r\n if (child instanceof SpaceNode && child.visible) {\r\n if (child instanceof CustomMeshNode && isTrackedClass(child)) {\r\n if (child.hasGeometry && !child._geometry && !child.geometryLoaded && !child._loading) {\r\n this.loadNewGeometry(child);\r\n }\r\n } else {\r\n this.recursiveLoadChildMeshGeometry(child);\r\n }\r\n }\r\n });\r\n }\r\n\r\n private createOrUpdateMesh(\r\n node: ITrackedClass,\r\n otherMesh?: Mesh\r\n ): T {\r\n let mesh: TransformNode | AbstractMesh | undefined;\r\n if (otherMesh) {\r\n mesh = otherMesh;\r\n } else {\r\n mesh = this.get3d(node);\r\n }\r\n const changes = node.changes as meshNodeSharedChanges;\r\n let allChanges = false;\r\n let meshVerticesNeedReset = false;\r\n if (!mesh) {\r\n // New Mesh\r\n\r\n allChanges = true;\r\n if (isMeshNode(node)) changes.set('features', node.features);\r\n\r\n if (isMeshGroupNode(node) || isSceneNode(node)) {\r\n mesh = new TransformNode(node._dynamicId, this.scene);\r\n } else {\r\n const newMesh = (mesh = new Mesh(node._dynamicId, this.scene));\r\n if (isCustomMeshNode(node) && isTrackedClass(node) && node._geometry) {\r\n this.setBabylonVertexData(node, newMesh);\r\n } else {\r\n meshVerticesNeedReset = true;\r\n }\r\n }\r\n mesh.scaling = Vector3.One();\r\n mesh.name = node.name;\r\n mesh.id = node._dynamicId;\r\n\r\n this.set3d(node, mesh);\r\n } else if (isCustomMeshNode(node) && changes.has('geometryId') && node._loading !== node.geometryId) {\r\n // Only load new geometry if the geometry hasn't just changed\r\n this.loadNewGeometry(node);\r\n } else if (isCustomMeshNode(node) && isTrackedClass(node) && node._geometry && node.changes.has('_geometry')) {\r\n // If we're changing the geometry, we always need to (re)apply all mesh properties\r\n // to the mesh as the new geometry won't have the right properties\r\n allChanges = true;\r\n changes.set('features', node.features);\r\n }\r\n\r\n if (\r\n allChanges ||\r\n changes.hasAny(\r\n 'position',\r\n 'useEuler',\r\n 'eulerRotation',\r\n 'rotationAxis',\r\n 'rotationAngle',\r\n 'pivot',\r\n 'scaling',\r\n '_showPivot'\r\n )\r\n ) {\r\n this.updateMeshTransform(node, mesh, allChanges ? null : (changes as ITrackedClass['changes']));\r\n if (isMeshNode(node)) {\r\n this.rendererManager.material.reflectedMeshes.set(node._dynamicId, mesh as AbstractMesh);\r\n }\r\n this.rendererManager.material.updateReflectionProbes();\r\n }\r\n\r\n if (changes.has('scaling')) {\r\n this.updateConnectorScaling(node);\r\n }\r\n\r\n const pivotGizmo = this.pivotGizmos.get(node._dynamicId);\r\n\r\n if (allChanges || changes.has('visible')) {\r\n mesh.setEnabled(!!node.visible);\r\n this.viewer.polygonTracker.next();\r\n this.viewer.warningTracker.next();\r\n\r\n if (pivotGizmo) {\r\n pivotGizmo.setEnabled(!!node.visible);\r\n }\r\n this.invalidateBoundingBox(node);\r\n\r\n // If a group node is made visible and it has a child node that has geometry load it now\r\n if (node.visible && node instanceof MeshGroupNode) {\r\n let parentNode = node._parent;\r\n let allParentsVisible = true;\r\n while (parentNode) {\r\n if (!parentNode.visible) {\r\n allParentsVisible = false;\r\n break;\r\n }\r\n parentNode = parentNode._parent;\r\n }\r\n if (allParentsVisible) {\r\n this.recursiveLoadChildMeshGeometry(node);\r\n }\r\n }\r\n }\r\n\r\n if (mesh instanceof Mesh) {\r\n const meshNode = node as ITrackedClass;\r\n mesh.isBlocker = false;\r\n\r\n if (allChanges || changes.has('receiveShadows')) {\r\n mesh.receiveShadows = !!meshNode.receiveShadows;\r\n this.shadowManager.toggleReceiver(mesh, !!meshNode.receiveShadows);\r\n }\r\n\r\n if (changes.has('isPickable')) {\r\n if (meshNode.isPickable !== undefined) {\r\n mesh.isPickable = meshNode.isPickable;\r\n } else {\r\n mesh.isPickable = true;\r\n }\r\n }\r\n\r\n if (allChanges || changes.has('castShadows')) this.shadowManager.toggleCaster(mesh, !!meshNode.castShadows);\r\n if (allChanges || changes.has('checkCollisions')) mesh.checkCollisions = !!meshNode.checkCollisions;\r\n if (allChanges || changes.has('flipSurfaceOrientation')) {\r\n if (meshNode.flipSurfaceOrientation) {\r\n mesh.overrideMaterialSideOrientation = Mesh.BACKSIDE;\r\n } else {\r\n mesh.overrideMaterialSideOrientation = Mesh.FRONTSIDE;\r\n }\r\n }\r\n\r\n if (this.renderMode !== eRenderMode.hiddenEdges) {\r\n if (allChanges || changes.has('opacity')) {\r\n mesh.visibility = meshNode.opacity == null ? 1 : meshNode.opacity;\r\n }\r\n }\r\n\r\n const warningTracker = {\r\n name: meshNode.name,\r\n isEnabled: meshNode.visible,\r\n castShadows: meshNode.castShadows || false,\r\n receiveShadows: meshNode.receiveShadows || false,\r\n polygonNumber: meshNode._polygonCount || 0,\r\n featureNumber: node.features.length,\r\n };\r\n this.viewer.MeshWarningTracker.set(mesh.id, warningTracker);\r\n // Material\r\n if (allChanges || changes.has('materialId') || changes.has('visible')) {\r\n const _mesh = mesh;\r\n\r\n // If the material is a multimaterial, make sure all the material nodes making it up are initialized\r\n if (meshNode.visible && mesh.material instanceof MultiMaterial) {\r\n mesh.material.subMaterials.forEach(material => {\r\n if (material) {\r\n const localMaterial = getByDynamicId(material.id, false);\r\n\r\n if (localMaterial) {\r\n localMaterial.init();\r\n } else {\r\n // Global material ?\r\n const globalMaterial = this.rendererManager.material.getGlobalMaterial(material.id);\r\n if (globalMaterial) {\r\n globalMaterial.init();\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n if (meshNode.materialId) {\r\n this.fetchMaterialNode(meshNode, meshNode.materialId).then(\r\n materialNode => {\r\n if (meshNode.visible) {\r\n this.setMaterialOnMesh(meshNode, _mesh, materialNode);\r\n }\r\n },\r\n () => {\r\n meshNode.materialId = undefined;\r\n }\r\n );\r\n } else {\r\n if (mesh.material instanceof MultiMaterial) {\r\n mesh.material.subMaterials[0] = this.rendererManager.material.defaultMaterial;\r\n mesh.material.forceCompilation(mesh); // If you don't do this webgl vomits errors because we invalidated the cache\r\n } else {\r\n mesh.material = this.rendererManager.material.defaultMaterial;\r\n }\r\n }\r\n\r\n if (isMeshNode(node)) {\r\n this.rendererManager.material.reflectedMeshes.set(node._dynamicId, mesh);\r\n }\r\n this.rendererManager.material.updateReflectionProbes();\r\n }\r\n\r\n let sketchNode: ITrackedClass | undefined;\r\n let updateSketchDrawing = false;\r\n\r\n // For primitives, recalculate the mesh if the shape properties changed\r\n if (isPrimitiveMeshNode(meshNode)) {\r\n if (allChanges) {\r\n meshVerticesNeedReset = true;\r\n } else {\r\n meshNode.changes.forEach((_, key) => {\r\n if (primitiveShapeProperties.has(key)) {\r\n meshVerticesNeedReset = true;\r\n }\r\n });\r\n }\r\n } else if (isCustomMeshNode(meshNode) && isTrackedClass(meshNode)) {\r\n meshVerticesNeedReset = meshNode.changes.has('_geometry') && !!meshNode._geometry;\r\n } else if (isSketchNode(meshNode) && isTrackedClass(meshNode)) {\r\n sketchNode = meshNode;\r\n meshVerticesNeedReset = sketchNode.changes.hasAny(\r\n 'paths',\r\n 'addFace',\r\n 'flipPath',\r\n 'clonePath',\r\n 'closePath',\r\n '_previewVisible'\r\n );\r\n\r\n updateSketchDrawing = sketchNode.changes.hasAny(\r\n 'paths',\r\n 'addFace',\r\n 'flipPath',\r\n 'clonePath',\r\n 'closePath',\r\n '_previewVisible',\r\n 'lineThickness',\r\n 'pathColor',\r\n 'tracePath'\r\n );\r\n\r\n if (sketchNode.changes.hasAny('boundingXOverride', 'boundingYOverride', 'boundingZOverride')) {\r\n sketchNode._boundingBoxChanges.next(sketchNode.getBoundingBox());\r\n }\r\n } else if (isTextNode(meshNode) && isTrackedClass(meshNode)) {\r\n meshVerticesNeedReset = meshNode.changes.hasAny(\r\n 'text',\r\n 'fontSize',\r\n 'curveRadius',\r\n 'charSpacing',\r\n 'fontFile'\r\n );\r\n }\r\n\r\n let preTransformChanged = false;\r\n if (allChanges || changes.hasAny('features', 'preTransform')) {\r\n meshVerticesNeedReset = true;\r\n preTransformChanged = !(allChanges || changes.has('_geometry')); // If geometry has changed, then the geometry was just loaded\r\n }\r\n\r\n // Features or shape properties have been changed, we have to recalculate original geometry and reprocess features on top\r\n if (allChanges || changes.has('uvOverrides') || meshVerticesNeedReset || updateSketchDrawing) {\r\n const meshVertexData = this.rebuildBaseGeometry(node, preTransformChanged);\r\n if (meshVertexData) {\r\n // This call should also apply the new vertex data.\r\n this.rendererManager.features.resetMeshGeometry(meshNode, null, meshVertexData);\r\n } else {\r\n if (mesh.geometry) {\r\n // If mesh geometry is set, the mesh was previously initialized but now is being generated with no geometry so we should destroy the old geometry\r\n // Failing to do so will cause Babylon geometry issues\r\n mesh.dispose();\r\n this.delete3d(node);\r\n }\r\n }\r\n\r\n if (sketchNode && sketchNode._previewVisible) {\r\n this.updateSketchPreview(sketchNode, meshVertexData, mesh);\r\n }\r\n\r\n if (sketchNode && sketchNode.tracePath && updateSketchDrawing) {\r\n if (sketchNode) {\r\n this.updateSketchTracing(sketchNode, meshVertexData, mesh);\r\n }\r\n }\r\n }\r\n\r\n // If this is a sketch, see if we need to show a preview of it\r\n if (sketchNode && sketchNode.changes.has('_previewVisible')) {\r\n const previewMesh = this.sketchPreviews.get(meshNode._dynamicId);\r\n if (previewMesh) {\r\n previewMesh.setEnabled(sketchNode._previewVisible);\r\n }\r\n }\r\n this.viewer.meshWarningsNeedsUpdate.next();\r\n }\r\n return mesh as unknown as T;\r\n }\r\n\r\n private updateMeshTransform(\r\n node: SpaceNode,\r\n mesh: T,\r\n changes: ITrackedClass['changes'] | null // null means all changes\r\n ): T {\r\n const pivot = node.pivot.toVec3();\r\n const originOffset = pivot.scale(-1);\r\n\r\n const newPosition = node.position.toVec3();\r\n\r\n let newRotation: Quaternion;\r\n if (node.useEuler) {\r\n newRotation = Quaternion.FromEulerAngles(\r\n toRadians(node.eulerRotation.x),\r\n toRadians(node.eulerRotation.y),\r\n toRadians(node.eulerRotation.z)\r\n );\r\n } else {\r\n newRotation = Quaternion.RotationAxis(node.rotationAxis.toVec3(), toRadians(node.rotationAngle));\r\n }\r\n const rotationMatrix = new Matrix();\r\n newRotation.toRotationMatrix(rotationMatrix);\r\n Vector3.TransformCoordinatesToRef(originOffset, rotationMatrix, originOffset);\r\n mesh.rotationQuaternion = newRotation;\r\n\r\n const scalingMatrix = Matrix.Scaling(node.scaling, node.scaling, node.scaling);\r\n Vector3.TransformCoordinatesToRef(originOffset, scalingMatrix, originOffset);\r\n mesh.scaling = new Vector3().setAll(node.scaling);\r\n\r\n newPosition.addInPlace(originOffset).addInPlace(pivot);\r\n\r\n if (!mesh.position.equals(newPosition)) {\r\n mesh.position = newPosition;\r\n }\r\n\r\n this.rendererManager.features.transformChanged(node);\r\n this.invalidateBoundingBox(!changes || changes.has('scaling') ? node : node._parent); //scaling, changes current node, but all others only change the parent\r\n\r\n if (node._showPivot) {\r\n let pivotGizmo = this.pivotGizmos.get(node._dynamicId);\r\n if (!pivotGizmo) {\r\n pivotGizmo = BabylonSphereBuilder.CreateSphere(\r\n 'pivotSphere',\r\n { diameter: 0.05 },\r\n this.utilityLayer.utilityLayerScene\r\n );\r\n\r\n const coloredMaterial = new StandardMaterial('', this.utilityLayer.utilityLayerScene);\r\n coloredMaterial.emissiveColor = Color3.Red();\r\n pivotGizmo.material = coloredMaterial;\r\n this.pivotGizmos.set(node._dynamicId, pivotGizmo);\r\n }\r\n if (!pivotGizmo.isEnabled()) {\r\n pivotGizmo.setEnabled(true);\r\n }\r\n\r\n const worldPivot = pivot.add(node.position.toVec3());\r\n if (mesh.parent) {\r\n const transform = mesh.parent.computeWorldMatrix(true);\r\n Vector3.TransformCoordinatesToRef(worldPivot, transform, worldPivot);\r\n }\r\n\r\n pivotGizmo.position = worldPivot;\r\n } else {\r\n const pivotGizmo = this.pivotGizmos.get(node._dynamicId);\r\n if (pivotGizmo && pivotGizmo.isEnabled()) {\r\n pivotGizmo.setEnabled(false);\r\n }\r\n }\r\n\r\n return mesh;\r\n }\r\n\r\n private createPrimitiveMesh(node: PrimitiveMeshNode): Mesh {\r\n if (!isPrimitiveMeshNode(node)) throw Error('Primitive not set');\r\n\r\n if (isBoxMesh(node)) {\r\n if (node.tessellation <= 1) {\r\n return MeshBuilder.CreateBox(\r\n node._dynamicId,\r\n {\r\n height: node.height,\r\n width: node.width,\r\n depth: node.depth,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else {\r\n return MeshBuilder.CreateTiledBox(\r\n node._dynamicId,\r\n {\r\n height: node.height,\r\n width: node.width,\r\n depth: node.depth,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n updatable: true,\r\n tileSize: 1 / node.tessellation,\r\n },\r\n this.scene\r\n );\r\n }\r\n } else if (isSphereMesh(node)) {\r\n return SphereBuilder.CreateSphere(\r\n node._dynamicId,\r\n {\r\n segments: node.tessellation,\r\n diameter: node.radius * 2,\r\n arc: node.arc / 360,\r\n sliceStart: node.latitudeStart / 180,\r\n slice: node.latitudeSlice / 180,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else if (isCylinderMesh(node)) {\r\n return CylinderBuilder.CreateCylinder(\r\n node._dynamicId,\r\n {\r\n height: node.height,\r\n diameter: node.radius * 2,\r\n tessellation: node.tessellation,\r\n subdivisions: node.subdivisions,\r\n hasRings: node.subdivisions > 1,\r\n cap: capModeMap[node.capMode],\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n arc: node.arc / 360,\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else if (isConeMesh(node)) {\r\n return MeshBuilder.CreateCylinder(\r\n node._dynamicId,\r\n {\r\n height: node.height,\r\n diameterTop: node.radiusTop * 2,\r\n diameterBottom: node.radiusBottom * 2,\r\n tessellation: node.tessellation,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else if (isTorusMesh(node)) {\r\n return TorusBuilder.CreateTorus(\r\n node._dynamicId,\r\n {\r\n diameter: node.radius * 2,\r\n thickness: node.thickness,\r\n tessellation: node.tessellation,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n arc: node.arc / 360,\r\n sliceStart: node.latitudeStart / 360,\r\n slice: node.latitudeSlice / 360,\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else if (isPlaneMesh(node)) {\r\n const mesh = PlaneBuilder.CreatePlane(\r\n node._dynamicId,\r\n {\r\n width: node.width,\r\n height: node.depth,\r\n tileHeight: node.depth / node.segments,\r\n tileWidth: node.width / node.segments,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n mesh.rotation.x = Math.PI / 2;\r\n mesh.bakeCurrentTransformIntoVertices();\r\n return mesh;\r\n } else if (isDiscMesh(node)) {\r\n return DiscBuilder.CreateDisc(\r\n node._dynamicId,\r\n {\r\n radius: node.radius,\r\n tessellation: node.tessellation,\r\n sideOrientation: eSideOrientationBabylonMap[node.sideOrientation],\r\n updatable: true,\r\n },\r\n this.scene\r\n );\r\n } else {\r\n throw Error('Mesh primitive not implemented');\r\n }\r\n }\r\n\r\n private setBabylonVertexData(kbMesh: CustomMeshNode, mesh: Mesh, preserveSubmeshes = true) {\r\n if (!kbMesh._geometry) {\r\n return;\r\n }\r\n const vertexData = this.getMeshVertexData(kbMesh);\r\n\r\n const invalid = verifyGeometry(vertexData);\r\n if (invalid) {\r\n console.error(`Invalid or corrupted geometry in mesh ${kbMesh.name}. The ${invalid} are invalid.`);\r\n } else {\r\n vertexData.applyToMesh(mesh, true, preserveSubmeshes);\r\n kbMesh._polygonCount = mesh.getTotalIndices() / 3;\r\n kbMesh._verticesCount = mesh.getTotalVertices();\r\n this.viewer.polygonTracker.next();\r\n this.viewer.warningTracker.next();\r\n }\r\n\r\n this.setRenderModeOnMesh(mesh, kbMesh._rootScene!);\r\n\r\n if (mesh.isFacetDataEnabled) {\r\n mesh.updateFacetData();\r\n }\r\n }\r\n\r\n private setBabylonUvData(uvData: IUvData, vertexData: VertexData) {\r\n if (uvData.uvs) {\r\n vertexData.uvs = uvData.uvs;\r\n }\r\n if (uvData.uv2s) {\r\n vertexData.uvs2 = uvData.uv2s;\r\n }\r\n if (uvData.uv3s) {\r\n vertexData.uvs3 = uvData.uv3s;\r\n }\r\n if (uvData.uv4s) {\r\n vertexData.uvs4 = uvData.uv4s;\r\n }\r\n if (uvData.uv5s) {\r\n vertexData.uvs5 = uvData.uv5s;\r\n }\r\n if (uvData.uv6s) {\r\n vertexData.uvs6 = uvData.uv6s;\r\n }\r\n\r\n return vertexData;\r\n }\r\n\r\n protected setMaterialOnMesh(meshNode: MeshNode, babylonMesh: Mesh, materialNode: MaterialNode) {\r\n if (meshNode.visible) {\r\n materialNode.init();\r\n }\r\n\r\n const material = this.rendererManager.material.get3d(materialNode);\r\n if (!material) {\r\n throw Error('Material could not be found in renderer. Has the material been created?');\r\n }\r\n\r\n // If the mesh already has a material and it's a multimaterial, then update the material on index 0\r\n // Which is reserved for the \"base\" material.\r\n if (babylonMesh.material instanceof MultiMaterial) {\r\n babylonMesh.material.subMaterials[0] = material;\r\n babylonMesh.material.forceCompilation(babylonMesh);\r\n } else if (!babylonMesh.material || babylonMesh.material.id != materialNode._dynamicId) {\r\n babylonMesh.material = material;\r\n }\r\n }\r\n\r\n protected invalidateBoundingBox(node?: SpaceNode) {\r\n if (node) {\r\n this.viewer.bbCache.invalidate(node);\r\n }\r\n }\r\n\r\n public delete3d(node: ITrackedClass) {\r\n if (isSketchNode(node)) {\r\n node._boundingBoxChanges.complete();\r\n }\r\n\r\n const bnode = this.get3d(node);\r\n if (bnode && bnode instanceof Mesh) {\r\n this.viewer.MeshWarningTracker.delete(bnode.id);\r\n this.shadowManager.removeCaster(bnode);\r\n this.shadowManager.removeReceiver(bnode);\r\n if (bnode.material instanceof MultiMaterial) {\r\n bnode.material.dispose(true, true, false); // multimaterials are 1:1 with meshes\r\n }\r\n }\r\n this.rendererManager.material.reflectedMeshes.delete(node._dynamicId);\r\n this.rendererManager.material.updateReflectionProbes();\r\n this.viewer.meshWarningsNeedsUpdate.next();\r\n super.delete3d(node);\r\n this.viewer.polygonTracker.next();\r\n this.viewer.warningTracker.next();\r\n }\r\n\r\n public createSketchPlaneVisualization(sketch: SketchNode) {\r\n const color = Color3.Yellow();\r\n\r\n const boundingBox = sketch.calculatedBoundingBox;\r\n let squareSize = 3;\r\n let calculatedSize = 0;\r\n let boundingBoxCenter = new Vector3(0, 0, 0);\r\n if (boundingBox) {\r\n boundingBoxCenter = boundingBox.center.clone();\r\n calculatedSize = boundingBox.minimum.subtract(boundingBox.maximum).length();\r\n }\r\n if (calculatedSize > squareSize) {\r\n squareSize = calculatedSize * 1;\r\n }\r\n const coloredMaterial = new StandardMaterial('', this.scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n const sketchPlaneVisualization = CreatePlane('mirrorPlane', { size: squareSize }, this.scene);\r\n const sketchMesh = this.viewer.getRendererNode(sketch);\r\n if (sketchMesh) {\r\n const translation = sketchMesh.computeWorldMatrix();\r\n const position = Vector3.TransformCoordinates(boundingBoxCenter, translation);\r\n sketchPlaneVisualization.position = new Vector3(position.x, position.y, position.z);\r\n const sketchNormal = new Vector3(0, 0, 0);\r\n if (sketch.normal === eAxis.x) {\r\n sketchNormal.set(1, 0, 0);\r\n } else if (sketch.normal === eAxis.y) {\r\n sketchNormal.set(0, 1, 0);\r\n } else {\r\n sketchNormal.set(0, 0, 1);\r\n }\r\n const rotationVector = Vector3.TransformCoordinates(\r\n sketchNormal,\r\n sketchMesh.computeWorldMatrix().getRotationMatrix()\r\n );\r\n rotationVector.z = rotationVector.z * -1;\r\n const resultQuaternion = new Quaternion();\r\n Quaternion.FromUnitVectorsToRef(rotationVector, new Vector3(0, 0, 1), resultQuaternion);\r\n sketchPlaneVisualization.rotationQuaternion = resultQuaternion;\r\n\r\n //uvMapVisualization.rotation = Vector3.RotationFromAxis()\r\n sketchPlaneVisualization.material = coloredMaterial;\r\n\r\n sketchPlaneVisualization.bakeCurrentTransformIntoVertices();\r\n return sketchPlaneVisualization;\r\n } else {\r\n console.warn(\r\n 'Sketch visualization plane cannot be generated, please check direction and position of sketchpoints.'\r\n );\r\n return null;\r\n }\r\n }\r\n\r\n public updateConnectorScaling(node: SpaceNode) {\r\n if (node instanceof SketchNode) {\r\n node.paths.forEach(path => {\r\n path.controlPoints.forEach(controlPoint => {\r\n this.viewer.rendererManager.controlPointRenderer.updateScale(controlPoint);\r\n });\r\n });\r\n } else {\r\n if (node.connectors) {\r\n node.connectors.forEach(connector => {\r\n this.viewer.rendererManager.connector.updateScale(connector);\r\n });\r\n }\r\n const childNodes = node.getChildren();\r\n if (childNodes) {\r\n childNodes.forEach(child => {\r\n if (child instanceof SpaceNode) {\r\n this.updateConnectorScaling(child);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n\r\n public calculateSketchBoundingBox(node: SketchNode) {\r\n const firstPoint = node.paths[0]._points[0];\r\n const minVector: Vector3 = new Vector3(firstPoint.x, firstPoint.y, firstPoint.z);\r\n const maxVector: Vector3 = new Vector3(firstPoint.x, firstPoint.y, firstPoint.z);\r\n node.paths.forEach(path => {\r\n path._points.forEach(point => {\r\n if (point.x < minVector.x) {\r\n minVector.x = point.x;\r\n }\r\n if (point.y < minVector.y) {\r\n minVector.y = point.y;\r\n }\r\n if (point.z < minVector.z) {\r\n minVector.z = point.z;\r\n }\r\n if (point.x > maxVector.x) {\r\n maxVector.x = point.x;\r\n }\r\n if (point.y > maxVector.y) {\r\n maxVector.y = point.y;\r\n }\r\n if (point.z > maxVector.z) {\r\n maxVector.z = point.z;\r\n }\r\n });\r\n });\r\n return new BoundingBox(minVector, maxVector);\r\n }\r\n}\r\n","import { Matrix, Vector3, Vector4 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n */\r\nexport class SphereBuilder {\r\n /**\r\n * Creates a torus mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\r\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\r\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the torus mesh\r\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\r\n */\r\n public static CreateSphere(\r\n name: string,\r\n options: {\r\n segments?: number;\r\n diameter?: number;\r\n diameterX?: number;\r\n diameterY?: number;\r\n diameterZ?: number;\r\n arc?: number;\r\n slice?: number;\r\n sliceStart?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n },\r\n scene: any\r\n ): Mesh {\r\n const sphere = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n sphere._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = createSphere(options);\r\n\r\n vertexData.applyToMesh(sphere, options.updatable);\r\n\r\n return sphere;\r\n\r\n function createSphere(options: {\r\n segments?: number;\r\n diameter?: number;\r\n diameterX?: number;\r\n diameterY?: number;\r\n diameterZ?: number;\r\n arc?: number;\r\n slice?: number;\r\n sliceStart?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }) {\r\n const segments: number = options.segments || 32;\r\n const diameterX: number = options.diameterX || options.diameter || 1;\r\n const diameterY: number = options.diameterY || options.diameter || 1;\r\n const diameterZ: number = options.diameterZ || options.diameter || 1;\r\n const arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n const sliceStart =\r\n options.sliceStart && (options.sliceStart < 0 || options.sliceStart > 1) ? 0 : options.sliceStart || 0;\r\n let slice: number = options.slice && options.slice <= 0 ? 1.0 : options.slice || 1.0;\r\n const sideOrientation =\r\n options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n if (slice + sliceStart > 1) {\r\n slice = 1 - sliceStart;\r\n }\r\n\r\n const radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);\r\n\r\n const totalZRotationSteps = 2 + segments;\r\n const totalYRotationSegments = 2 * totalZRotationSteps;\r\n const totalYRotationSteps = totalYRotationSegments + 1;\r\n\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {\r\n const normalizedZ = zRotationStep / totalZRotationSteps;\r\n const angleZ = normalizedZ * Math.PI * slice + sliceStart * Math.PI;\r\n\r\n for (let yRotationStep = 0; yRotationStep < totalYRotationSteps; yRotationStep++) {\r\n const normalizedY = yRotationStep / totalYRotationSegments;\r\n\r\n const angleY = normalizedY * Math.PI * 2 * arc;\r\n\r\n const rotationZ = Matrix.RotationZ(-angleZ);\r\n const rotationY = Matrix.RotationY(angleY);\r\n const afterRotZ = Vector3.TransformCoordinates(Vector3.Up(), rotationZ);\r\n const complete = Vector3.TransformCoordinates(afterRotZ, rotationY);\r\n\r\n const vertex = complete.multiply(radius);\r\n const normal = complete.divide(radius).normalize();\r\n\r\n positions.push(vertex.x, vertex.y, vertex.z);\r\n normals.push(normal.x, normal.y, normal.z);\r\n uvs.push(normalizedY, 1 - normalizedZ);\r\n\r\n if (yRotationStep < totalYRotationSegments || arc === 1) {\r\n const nextYStep = (yRotationStep + 1) % totalYRotationSteps;\r\n if (sliceStart === 0 && zRotationStep === 0) {\r\n indices.push(0); // C\r\n indices.push(nextYStep); // B\r\n indices.push(yRotationStep); // A\r\n } else if (zRotationStep > 0) {\r\n indices.push((zRotationStep - 1) * totalYRotationSteps + yRotationStep); // C\r\n indices.push(zRotationStep * totalYRotationSteps + nextYStep); // B\r\n indices.push(zRotationStep * totalYRotationSteps + yRotationStep); // A\r\n\r\n indices.push((zRotationStep - 1) * totalYRotationSteps + yRotationStep); // C\r\n indices.push((zRotationStep - 1) * totalYRotationSteps + nextYStep); // D\r\n indices.push(zRotationStep * totalYRotationSteps + nextYStep); // B\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(\r\n sideOrientation,\r\n positions,\r\n indices,\r\n normals,\r\n uvs,\r\n options.frontUVs,\r\n options.backUVs\r\n );\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n }\r\n }\r\n}\r\n","import { Axis, Color4, Vector2, Vector3, Vector4 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { Nullable } from '@babylonjs/core/types';\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n */\r\nexport class CylinderBuilder {\r\n /**\r\n * Creates a torus mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\r\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\r\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/Cylinderover_basic_elements#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the torus mesh\r\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\r\n */\r\n public static CreateCylinder(\r\n name: string,\r\n options: {\r\n height?: number;\r\n diameterTop?: number;\r\n diameterBottom?: number;\r\n diameter?: number;\r\n tessellation?: number;\r\n subdivisions?: number;\r\n arc?: number;\r\n faceColors?: Color4[];\r\n faceUV?: Vector4[];\r\n hasRings?: boolean;\r\n enclose?: boolean;\r\n cap?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n },\r\n scene: any\r\n ): Mesh {\r\n const Cylinder = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n Cylinder._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = createCylinder(options);\r\n\r\n vertexData.applyToMesh(Cylinder, options.updatable);\r\n\r\n return Cylinder;\r\n\r\n function createCylinder(options: {\r\n height?: number;\r\n diameterTop?: number;\r\n diameterBottom?: number;\r\n diameter?: number;\r\n tessellation?: number;\r\n subdivisions?: number;\r\n arc?: number;\r\n faceColors?: Color4[];\r\n faceUV?: Vector4[];\r\n hasRings?: boolean;\r\n enclose?: boolean;\r\n cap?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }) {\r\n const height: number = options.height || 2;\r\n let diameterTop: number = options.diameterTop === 0 ? 0 : options.diameterTop || options.diameter || 1;\r\n let diameterBottom: number =\r\n options.diameterBottom === 0 ? 0 : options.diameterBottom || options.diameter || 1;\r\n diameterTop = diameterTop || 0.00001; // Prevent broken normals\r\n diameterBottom = diameterBottom || 0.00001; // Prevent broken normals\r\n const tessellation: number = options.tessellation || 24;\r\n const subdivisions: number = options.subdivisions || 1;\r\n const hasRings: boolean = options.hasRings ? true : false;\r\n const enclose: boolean = options.enclose ? true : false;\r\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.CAP_ALL;\r\n const arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n const sideOrientation: number =\r\n options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n const faceUV: Vector4[] = options.faceUV || new Array(3);\r\n const faceColors = options.faceColors;\r\n // default face colors and UV if undefined\r\n const quadNb: number = arc !== 1 && enclose ? 2 : 0;\r\n const ringNb: number = hasRings ? subdivisions : 1;\r\n const surfaceNb: number = 2 + (1 + quadNb) * ringNb;\r\n let f: number;\r\n\r\n for (f = 0; f < surfaceNb; f++) {\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n for (f = 0; f < surfaceNb; f++) {\r\n if (faceUV && faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n }\r\n\r\n const indices = new Array();\r\n const positions = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n const colors = new Array();\r\n\r\n const angle_step = (Math.PI * 2 * arc) / tessellation;\r\n let angle: number;\r\n let h: number;\r\n let radius: number;\r\n const tan = (diameterBottom - diameterTop) / 2 / height;\r\n const ringVertex: Vector3 = Vector3.Zero();\r\n const ringNormal: Vector3 = Vector3.Zero();\r\n const ringFirstVertex: Vector3 = Vector3.Zero();\r\n const ringFirstNormal: Vector3 = Vector3.Zero();\r\n const quadNormal: Vector3 = Vector3.Zero();\r\n const Y: Vector3 = Axis.Y;\r\n\r\n // positions, normals, uvs\r\n let i: number;\r\n let j: number;\r\n let r: number;\r\n let ringIdx = 1;\r\n let s = 1; // surface index\r\n let cs = 0;\r\n let v = 0;\r\n\r\n for (i = 0; i <= subdivisions; i++) {\r\n h = i / subdivisions;\r\n radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;\r\n ringIdx = hasRings && i !== 0 && i !== subdivisions ? 2 : 1;\r\n for (r = 0; r < ringIdx; r++) {\r\n if (hasRings) {\r\n s += r;\r\n }\r\n if (enclose) {\r\n s += 2 * r;\r\n }\r\n\r\n for (j = 0; j <= tessellation; j++) {\r\n angle = j * angle_step;\r\n\r\n // position\r\n ringVertex.x = Math.cos(-angle) * radius;\r\n ringVertex.y = -height / 2 + h * height;\r\n ringVertex.z = Math.sin(-angle) * radius;\r\n\r\n // normal\r\n if (diameterTop === 0 && i === subdivisions) {\r\n // if no top cap, reuse former normals\r\n ringNormal.x = normals[normals.length - (tessellation + 1) * 3];\r\n ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];\r\n ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];\r\n } else {\r\n ringNormal.x = ringVertex.x;\r\n ringNormal.z = ringVertex.z;\r\n ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;\r\n ringNormal.normalize();\r\n }\r\n\r\n // keep first ring vertex values for enclose\r\n if (j === 0) {\r\n ringFirstVertex.copyFrom(ringVertex);\r\n ringFirstNormal.copyFrom(ringNormal);\r\n }\r\n\r\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\r\n normals.push(ringNormal.x, ringNormal.y, ringNormal.z);\r\n if (hasRings) {\r\n v = cs !== s ? faceUV[s].y : faceUV[s].w;\r\n } else {\r\n v = faceUV[s].y + (faceUV[s].w - faceUV[s].y) * h;\r\n }\r\n uvs.push(faceUV[s].x + ((faceUV[s].z - faceUV[s].x) * j) / tessellation, v);\r\n if (faceColors) {\r\n colors.push(faceColors[s].r, faceColors[s].g, faceColors[s].b, faceColors[s].a);\r\n }\r\n }\r\n\r\n // if enclose, add four vertices and their dedicated normals\r\n if (arc !== 1 && enclose) {\r\n positions.push(ringVertex.x, ringVertex.y, ringVertex.z);\r\n positions.push(0, ringVertex.y, 0);\r\n positions.push(0, ringVertex.y, 0);\r\n positions.push(ringFirstVertex.x, ringFirstVertex.y, ringFirstVertex.z);\r\n Vector3.CrossToRef(Y, ringNormal, quadNormal);\r\n quadNormal.normalize();\r\n normals.push(\r\n quadNormal.x,\r\n quadNormal.y,\r\n quadNormal.z,\r\n quadNormal.x,\r\n quadNormal.y,\r\n quadNormal.z\r\n );\r\n Vector3.CrossToRef(ringFirstNormal, Y, quadNormal);\r\n quadNormal.normalize();\r\n normals.push(\r\n quadNormal.x,\r\n quadNormal.y,\r\n quadNormal.z,\r\n quadNormal.x,\r\n quadNormal.y,\r\n quadNormal.z\r\n );\r\n if (hasRings) {\r\n v = cs !== s ? faceUV[s + 1].y : faceUV[s + 1].w;\r\n } else {\r\n v = faceUV[s + 1].y + (faceUV[s + 1].w - faceUV[s + 1].y) * h;\r\n }\r\n uvs.push(faceUV[s + 1].x, v);\r\n uvs.push(faceUV[s + 1].z, v);\r\n if (hasRings) {\r\n v = cs !== s ? faceUV[s + 2].y : faceUV[s + 2].w;\r\n } else {\r\n v = faceUV[s + 2].y + (faceUV[s + 2].w - faceUV[s + 2].y) * h;\r\n }\r\n uvs.push(faceUV[s + 2].x, v);\r\n uvs.push(faceUV[s + 2].z, v);\r\n if (faceColors) {\r\n colors.push(\r\n faceColors[s + 1].r,\r\n faceColors[s + 1].g,\r\n faceColors[s + 1].b,\r\n faceColors[s + 1].a\r\n );\r\n colors.push(\r\n faceColors[s + 1].r,\r\n faceColors[s + 1].g,\r\n faceColors[s + 1].b,\r\n faceColors[s + 1].a\r\n );\r\n colors.push(\r\n faceColors[s + 2].r,\r\n faceColors[s + 2].g,\r\n faceColors[s + 2].b,\r\n faceColors[s + 2].a\r\n );\r\n colors.push(\r\n faceColors[s + 2].r,\r\n faceColors[s + 2].g,\r\n faceColors[s + 2].b,\r\n faceColors[s + 2].a\r\n );\r\n }\r\n }\r\n if (cs !== s) {\r\n cs = s;\r\n }\r\n }\r\n }\r\n\r\n // indices\r\n const e: number = arc !== 1 && enclose ? tessellation + 4 : tessellation; // correction of number of iteration if enclose\r\n let sI: number;\r\n i = 0;\r\n for (sI = 0; sI < subdivisions; sI++) {\r\n let i0 = 0;\r\n let i1 = 0;\r\n let i2 = 0;\r\n let i3 = 0;\r\n for (j = 0; j < tessellation; j++) {\r\n i0 = i * (e + 1) + j; // top left\r\n i1 = (i + 1) * (e + 1) + j; // bottom left\r\n i2 = i * (e + 1) + (j + 1); // top right\r\n i3 = (i + 1) * (e + 1) + (j + 1); // bottom right\r\n indices.push(i0, i1, i2);\r\n indices.push(i3, i2, i1);\r\n }\r\n if (arc !== 1 && enclose) {\r\n // if enclose, add two quads\r\n indices.push(i0 + 2, i1 + 2, i2 + 2);\r\n indices.push(i3 + 2, i2 + 2, i1 + 2);\r\n indices.push(i0 + 4, i1 + 4, i2 + 4);\r\n indices.push(i3 + 4, i2 + 4, i1 + 4);\r\n } else if (arc === 1) {\r\n indices.push(i2, i3, i * (e + 1));\r\n indices.push((i + 1) * (e + 1), i * (e + 1), i3);\r\n }\r\n i = hasRings ? i + 2 : i + 1;\r\n }\r\n\r\n // Caps\r\n const createCylinderCap = (isTop: boolean) => {\r\n const radius = isTop ? diameterTop / 2 : diameterBottom / 2;\r\n if (radius === 0) {\r\n return;\r\n }\r\n\r\n // Cap positions, normals & uvs\r\n let angle;\r\n let circleVector;\r\n let i: number;\r\n const u: Vector4 = isTop ? faceUV[surfaceNb - 1] : faceUV[0];\r\n let c: Nullable = null;\r\n if (faceColors) {\r\n c = isTop ? faceColors[surfaceNb - 1] : faceColors[0];\r\n }\r\n // cap center\r\n const vbase = positions.length / 3;\r\n const offset = isTop ? height / 2 : -height / 2;\r\n const center = new Vector3(0, offset, 0);\r\n positions.push(center.x, center.y, center.z);\r\n normals.push(0, isTop ? 1 : -1, 0);\r\n uvs.push(u.x + (u.z - u.x) * 0.5, u.y + (u.w - u.y) * 0.5);\r\n if (c) {\r\n colors.push(c.r, c.g, c.b, c.a);\r\n }\r\n\r\n const textureScale = new Vector2(0.5, 0.5);\r\n for (i = 0; i <= tessellation; i++) {\r\n angle = i * angle_step;\r\n const cos = Math.cos(-angle);\r\n const sin = Math.sin(-angle);\r\n circleVector = new Vector3(cos * radius, offset, sin * radius);\r\n const textureCoordinate = new Vector2(cos * textureScale.x + 0.5, sin * textureScale.y + 0.5);\r\n positions.push(circleVector.x, circleVector.y, circleVector.z);\r\n normals.push(0, isTop ? 1 : -1, 0);\r\n uvs.push(u.x + (u.z - u.x) * textureCoordinate.x, u.y + (u.w - u.y) * textureCoordinate.y);\r\n if (c) {\r\n colors.push(c.r, c.g, c.b, c.a);\r\n }\r\n }\r\n // Cap indices\r\n for (i = 0; i < tessellation; i++) {\r\n if (!isTop) {\r\n indices.push(vbase);\r\n indices.push(vbase + (i + 1));\r\n indices.push(vbase + (i + 2));\r\n } else {\r\n indices.push(vbase);\r\n indices.push(vbase + (i + 2));\r\n indices.push(vbase + (i + 1));\r\n }\r\n }\r\n // Close the loop\r\n if (arc === 1) {\r\n if (!isTop) {\r\n indices.push(vbase, vbase + tessellation + 1, vbase + 1);\r\n } else {\r\n indices.push(vbase, vbase + 1, vbase + tessellation + 1);\r\n }\r\n }\r\n };\r\n\r\n // add caps to geometry based on cap parameter\r\n if (cap === Mesh.CAP_START || cap === Mesh.CAP_ALL) {\r\n createCylinderCap(false);\r\n }\r\n if (cap === Mesh.CAP_END || cap === Mesh.CAP_ALL) {\r\n createCylinderCap(true);\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(\r\n sideOrientation,\r\n positions,\r\n indices,\r\n normals,\r\n uvs,\r\n options.frontUVs,\r\n options.backUVs\r\n );\r\n\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n if (faceColors) {\r\n vertexData.colors = colors;\r\n }\r\n\r\n return vertexData;\r\n }\r\n }\r\n}\r\n","import { Matrix, Vector2, Vector3, Vector4 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n */\r\nexport class TorusBuilder {\r\n /**\r\n * Creates a torus mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\r\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\r\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the torus mesh\r\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\r\n */\r\n public static CreateTorus(\r\n name: string,\r\n options: {\r\n diameter?: number;\r\n thickness?: number;\r\n tessellation?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n arc?: number;\r\n slice?: number;\r\n updatable?: boolean;\r\n sliceStart?: number;\r\n },\r\n scene: any\r\n ): Mesh {\r\n const torus = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n torus._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = createTorus(options);\r\n\r\n vertexData.applyToMesh(torus, options.updatable);\r\n\r\n return torus;\r\n\r\n function createTorus(options: {\r\n diameter?: number;\r\n thickness?: number;\r\n tessellation?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n arc?: number;\r\n slice?: number;\r\n sliceStart?: number;\r\n }) {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n const diameter = options.diameter || 1;\r\n const thickness = options.thickness || 0.5;\r\n const tessellation = options.tessellation || 12;\r\n const arc = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n let slice = options.slice && options.slice <= 0 ? 1.0 : options.slice || 1.0;\r\n const sliceStart =\r\n options.sliceStart && (options.sliceStart < 0 || options.sliceStart > 1) ? 0 : options.sliceStart || 0;\r\n const sideOrientation =\r\n options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n if (slice + sliceStart > 1) {\r\n slice = 1 - sliceStart;\r\n }\r\n\r\n const outerSegments = Math.ceil(tessellation * arc * Math.PI); // Need more segments for the torus circumference\r\n const innerSegments = Math.ceil(tessellation * slice);\r\n const closedRing = arc === 1; // handle float errors\r\n const closedTube = slice === 1;\r\n const lastOuterRing = outerSegments + 1;\r\n const lastTubeSection = innerSegments + 1;\r\n\r\n for (let i = 0; i < lastOuterRing; i++) {\r\n const u = i / outerSegments;\r\n\r\n const outerAngle = u * (arc * Math.PI * 2) - Math.PI / 2;\r\n\r\n const transform = Matrix.Translation(diameter / 2, 0, 0).multiply(Matrix.RotationY(outerAngle));\r\n\r\n for (let j = 0; j < lastTubeSection; j++) {\r\n const v = 1 - j / innerSegments;\r\n\r\n const innerAngle = (j / innerSegments) * (Math.PI * 2 * slice) + Math.PI * 2 * sliceStart;\r\n const dx = Math.cos(innerAngle);\r\n const dy = Math.sin(innerAngle);\r\n\r\n // Create a vertex.\r\n let normal = new Vector3(dx, dy, 0);\r\n let position = normal.scale(thickness / 2);\r\n const textureCoordinate = new Vector2(u, v);\r\n\r\n position = Vector3.TransformCoordinates(position, transform);\r\n normal = Vector3.TransformNormal(normal, transform);\r\n\r\n positions.push(position.x, position.y, position.z);\r\n normals.push(normal.x, normal.y, normal.z);\r\n uvs.push(textureCoordinate.x, textureCoordinate.y);\r\n\r\n if ((i < outerSegments || closedRing) && (j < innerSegments || closedTube)) {\r\n // And create indices for two triangles.\r\n const nextI = (i + 1) % lastOuterRing;\r\n const nextJ = (j + 1) % lastTubeSection;\r\n\r\n indices.push(i * lastTubeSection + j); // A\r\n indices.push(i * lastTubeSection + nextJ); // B\r\n indices.push(nextI * lastTubeSection + j); // C\r\n\r\n indices.push(i * lastTubeSection + nextJ); // B\r\n indices.push(nextI * lastTubeSection + nextJ); // D\r\n indices.push(nextI * lastTubeSection + j); // C\r\n }\r\n }\r\n }\r\n\r\n // Sides\r\n VertexData._ComputeSides(\r\n sideOrientation,\r\n positions,\r\n indices,\r\n normals,\r\n uvs,\r\n options.frontUVs,\r\n options.backUVs\r\n );\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n }\r\n }\r\n}\r\n","import { Vector4 } from '@babylonjs/core/Maths/math.vector';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n */\r\nexport class PlaneBuilder {\r\n /**\r\n * Creates a torus mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\r\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\r\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the torus mesh\r\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\r\n */\r\n public static CreatePlane(\r\n name: string,\r\n options: {\r\n pattern?: number;\r\n tileSize?: number;\r\n tileWidth?: number;\r\n tileHeight?: number;\r\n size?: number;\r\n width?: number;\r\n height?: number;\r\n alignHorizontal?: number;\r\n alignVertical?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n },\r\n scene: any\r\n ): Mesh {\r\n const plane = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n\r\n const flipTile = options.pattern || Mesh.NO_FLIP;\r\n const tileWidth = options.tileWidth || options.tileSize || 1;\r\n const tileHeight = options.tileHeight || options.tileSize || 1;\r\n const alignH = options.alignHorizontal || 0;\r\n const alignV = options.alignVertical || 0;\r\n\r\n const width = options.width || options.size || 1;\r\n const tilesX = Math.floor(width / tileWidth);\r\n let offsetX = width - tilesX * tileWidth;\r\n\r\n const height = options.height || options.size || 1;\r\n const tilesY = Math.floor(height / tileHeight);\r\n let offsetY = height - tilesY * tileHeight;\r\n\r\n const halfWidth = (tileWidth * tilesX) / 2;\r\n const halfHeight = (tileHeight * tilesY) / 2;\r\n\r\n const indices = [];\r\n const positions = [];\r\n const normals = new Float32Array(tilesX * tilesY * 12);\r\n\r\n const colorSetArray = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];\r\n const normalSetArray = [0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1];\r\n const colorSet = Float32Array.from(colorSetArray);\r\n const normalSet = Float32Array.from(normalSetArray);\r\n\r\n let adjustX = 0;\r\n let adjustY = 0;\r\n let startX = 0;\r\n let startY = 0;\r\n let endX = 0;\r\n let endY = 0;\r\n\r\n //Part Tiles\r\n if (offsetX > 0 || offsetY > 0) {\r\n startX = -halfWidth;\r\n startY = -halfHeight;\r\n endX = halfWidth;\r\n endY = halfHeight;\r\n\r\n switch (alignH) {\r\n case Mesh.CENTER:\r\n offsetX /= 2;\r\n startX -= offsetX;\r\n endX += offsetX;\r\n break;\r\n case Mesh.LEFT:\r\n endX += offsetX;\r\n adjustX = -offsetX / 2;\r\n break;\r\n case Mesh.RIGHT:\r\n startX -= offsetX;\r\n adjustX = offsetX / 2;\r\n break;\r\n }\r\n\r\n switch (alignV) {\r\n case Mesh.CENTER:\r\n offsetY /= 2;\r\n startY -= offsetY;\r\n endY += offsetY;\r\n break;\r\n case Mesh.BOTTOM:\r\n endY += offsetY;\r\n adjustY = -offsetY / 2;\r\n break;\r\n case Mesh.TOP:\r\n startY -= offsetY;\r\n adjustY = offsetY / 2;\r\n break;\r\n }\r\n }\r\n\r\n const uvBase = [];\r\n uvBase[0] = [0, 0, 1, 0, 1, 1, 0, 1];\r\n uvBase[1] = [0, 0, 1, 0, 1, 1, 0, 1];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBase[1] = [1, 1, 0, 1, 0, 0, 1, 0];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBase[1] = [1, 0, 0, 0, 0, 1, 1, 1];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBase[1] = [0, 1, 1, 1, 1, 0, 0, 0];\r\n }\r\n\r\n const uvs = new Float32Array(tilesY * tilesX * 8);\r\n const colors = new Float32Array(tilesY * tilesX * 16);\r\n let index = 0;\r\n\r\n for (let y = 0; y < tilesY; y++) {\r\n for (let x = 0; x < tilesX; x++) {\r\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(\r\n -halfWidth + (x + 1) * tileWidth + adjustX,\r\n -halfHeight + (y + 1) * tileHeight + adjustY,\r\n 0\r\n );\r\n positions.push(-halfWidth + x * tileWidth + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n if (\r\n flipTile === Mesh.FLIP_TILE ||\r\n flipTile === Mesh.ROTATE_TILE ||\r\n flipTile === Mesh.FLIP_N_ROTATE_TILE\r\n ) {\r\n uvs.set(uvBase[((x % 2) + (y % 2)) % 2], index * 2);\r\n } else if (\r\n flipTile === Mesh.FLIP_ROW ||\r\n flipTile === Mesh.ROTATE_ROW ||\r\n flipTile === Mesh.FLIP_N_ROTATE_ROW\r\n ) {\r\n uvs.set(uvBase[y % 2], index * 2);\r\n } else {\r\n uvs.set(uvBase[0], index * 2);\r\n }\r\n\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n index += 4;\r\n }\r\n }\r\n\r\n //Part Tiles\r\n if (offsetX > 0 || offsetY > 0) {\r\n const partialBottomRow: boolean = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.TOP);\r\n const partialTopRow: boolean = offsetY > 0 && (alignV === Mesh.CENTER || alignV === Mesh.BOTTOM);\r\n const partialLeftCol: boolean = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.RIGHT);\r\n const partialRightCol: boolean = offsetX > 0 && (alignH === Mesh.CENTER || alignH === Mesh.LEFT);\r\n let uvPart: number[] = [];\r\n let a, b, c, d: number;\r\n\r\n //corners\r\n if (partialBottomRow && partialLeftCol) {\r\n //bottom left corner\r\n positions.push(startX + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, startY + offsetY + adjustY, 0);\r\n positions.push(startX + adjustX, startY + offsetY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 1 - offsetX / tileWidth;\r\n b = 1 - offsetY / tileHeight;\r\n c = 1;\r\n d = 1;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_ROW) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_ROW) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs.set(uvPart, index * 2);\r\n uvs.set(uvPart, index);\r\n\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n\r\n if (partialBottomRow && partialRightCol) {\r\n //bottom right corner\r\n positions.push(halfWidth + adjustX, startY + adjustY, 0);\r\n positions.push(endX + adjustX, startY + adjustY, 0);\r\n positions.push(endX + adjustX, startY + offsetY + adjustY, 0);\r\n positions.push(halfWidth + adjustX, startY + offsetY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 0;\r\n b = 1 - offsetY / tileHeight;\r\n c = offsetX / tileWidth;\r\n d = 1;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_ROW || (flipTile === Mesh.ROTATE_TILE && tilesX % 2 === 0)) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_ROW || (flipTile === Mesh.FLIP_TILE && tilesX % 2 === 0)) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_ROW || (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesX % 2 === 0)) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs.set(uvPart, index * 2);\r\n\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n\r\n if (partialTopRow && partialLeftCol) {\r\n //top left corner\r\n positions.push(startX + adjustX, halfHeight + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, halfHeight + adjustY, 0);\r\n positions.push(-halfWidth + adjustX, endY + adjustY, 0);\r\n positions.push(startX + adjustX, endY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 1 - offsetX / tileWidth;\r\n b = 0;\r\n c = 1;\r\n d = offsetY / tileHeight;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if (\r\n (flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) ||\r\n (flipTile === Mesh.ROTATE_TILE && tilesY % 1 === 0)\r\n ) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (\r\n (flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) ||\r\n (flipTile === Mesh.FLIP_TILE && tilesY % 2 === 0)\r\n ) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (\r\n (flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) ||\r\n (flipTile === Mesh.FLIP_N_ROTATE_TILE && tilesY % 2 === 0)\r\n ) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n\r\n uvs.set(uvPart, index * 2);\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n\r\n if (partialTopRow && partialRightCol) {\r\n //top right corner\r\n positions.push(halfWidth + adjustX, halfHeight + adjustY, 0);\r\n positions.push(endX + adjustX, halfHeight + adjustY, 0);\r\n positions.push(endX + adjustX, endY + adjustY, 0);\r\n positions.push(halfWidth + adjustX, endY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n a = 0;\r\n b = 0;\r\n c = offsetX / tileWidth;\r\n d = offsetY / tileHeight;\r\n uvPart = [a, b, c, b, c, d, a, d];\r\n if (\r\n (flipTile === Mesh.ROTATE_ROW && tilesY % 2 === 1) ||\r\n (flipTile === Mesh.ROTATE_TILE && (tilesY + tilesX) % 2 === 1)\r\n ) {\r\n uvPart = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (\r\n (flipTile === Mesh.FLIP_ROW && tilesY % 2 === 1) ||\r\n (flipTile === Mesh.FLIP_TILE && (tilesY + tilesX) % 2 === 1)\r\n ) {\r\n uvPart = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (\r\n (flipTile === Mesh.FLIP_N_ROTATE_ROW && tilesY % 2 === 1) ||\r\n (flipTile === Mesh.FLIP_N_ROTATE_TILE && (tilesY + tilesX) % 2 === 1)\r\n ) {\r\n uvPart = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n uvs.set(uvPart, index * 2);\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n\r\n //part rows\r\n if (partialBottomRow) {\r\n const uvBaseBR = [];\r\n a = 0;\r\n b = 1 - offsetY / tileHeight;\r\n c = 1;\r\n d = 1;\r\n uvBaseBR[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseBR[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseBR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseBR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseBR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let x = 0; x < tilesX; x++) {\r\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, startY + offsetY + adjustY, 0);\r\n positions.push(-halfWidth + x * tileWidth + adjustX, startY + offsetY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (\r\n flipTile === Mesh.FLIP_TILE ||\r\n flipTile === Mesh.ROTATE_TILE ||\r\n flipTile === Mesh.FLIP_N_ROTATE_TILE\r\n ) {\r\n uvs.set(uvBaseBR[(x + 1) % 2], index * 2);\r\n } else if (\r\n flipTile === Mesh.FLIP_ROW ||\r\n flipTile === Mesh.ROTATE_ROW ||\r\n flipTile === Mesh.FLIP_N_ROTATE_ROW\r\n ) {\r\n uvs.set(uvBaseBR[1], index * 2);\r\n } else {\r\n uvs.set(uvBaseBR[0], index * 2);\r\n }\r\n\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n }\r\n\r\n if (partialTopRow) {\r\n const uvBaseTR = [];\r\n a = 0;\r\n b = 0;\r\n c = 1;\r\n d = offsetY / tileHeight;\r\n uvBaseTR[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseTR[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseTR[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseTR[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseTR[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let x = 0; x < tilesX; x++) {\r\n positions.push(-halfWidth + x * tileWidth + adjustX, endY - offsetY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY - offsetY + adjustY, 0);\r\n positions.push(-halfWidth + (x + 1) * tileWidth + adjustX, endY + adjustY, 0);\r\n positions.push(-halfWidth + x * tileWidth + adjustX, endY + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (\r\n flipTile === Mesh.FLIP_TILE ||\r\n flipTile === Mesh.ROTATE_TILE ||\r\n flipTile === Mesh.FLIP_N_ROTATE_TILE\r\n ) {\r\n uvs.set(uvBaseTR[(x + tilesY) % 2], index * 2);\r\n } else if (\r\n flipTile === Mesh.FLIP_ROW ||\r\n flipTile === Mesh.ROTATE_ROW ||\r\n flipTile === Mesh.FLIP_N_ROTATE_ROW\r\n ) {\r\n uvs.set(uvBaseTR[tilesY % 2], index * 2);\r\n } else {\r\n uvs.set(uvBaseTR[0], index * 2);\r\n }\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n }\r\n\r\n if (partialLeftCol) {\r\n const uvBaseLC = [];\r\n a = 1 - offsetX / tileWidth;\r\n b = 0;\r\n c = 1;\r\n d = 1;\r\n uvBaseLC[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseLC[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseLC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseLC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseLC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let y = 0; y < tilesY; y++) {\r\n positions.push(startX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(startX + offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(startX + offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n positions.push(startX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (\r\n flipTile === Mesh.FLIP_TILE ||\r\n flipTile === Mesh.ROTATE_TILE ||\r\n flipTile === Mesh.FLIP_N_ROTATE_TILE\r\n ) {\r\n uvs.set(uvBaseLC[(y + 1) % 2], index * 2);\r\n } else if (\r\n flipTile === Mesh.FLIP_ROW ||\r\n flipTile === Mesh.ROTATE_ROW ||\r\n flipTile === Mesh.FLIP_N_ROTATE_ROW\r\n ) {\r\n uvs.set(uvBaseLC[y % 2], index * 2);\r\n } else {\r\n uvs.set(uvBaseLC[0], index * 2);\r\n }\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n }\r\n\r\n if (partialRightCol) {\r\n const uvBaseRC = [];\r\n a = 0;\r\n b = 0;\r\n c = offsetX / tileHeight;\r\n d = 1;\r\n uvBaseRC[0] = [a, b, c, b, c, d, a, d];\r\n uvBaseRC[1] = [a, b, c, b, c, d, a, d];\r\n if (flipTile === Mesh.ROTATE_TILE || flipTile === Mesh.ROTATE_ROW) {\r\n uvBaseRC[1] = [1 - a, 1 - b, 1 - c, 1 - b, 1 - c, 1 - d, 1 - a, 1 - d];\r\n }\r\n if (flipTile === Mesh.FLIP_TILE || flipTile === Mesh.FLIP_ROW) {\r\n uvBaseRC[1] = [1 - a, b, 1 - c, b, 1 - c, d, 1 - a, d];\r\n }\r\n if (flipTile === Mesh.FLIP_N_ROTATE_TILE || flipTile === Mesh.FLIP_N_ROTATE_ROW) {\r\n uvBaseRC[1] = [a, 1 - b, c, 1 - b, c, 1 - d, a, 1 - d];\r\n }\r\n for (let y = 0; y < tilesY; y++) {\r\n positions.push(endX - offsetX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(endX + adjustX, -halfHeight + y * tileHeight + adjustY, 0);\r\n positions.push(endX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n positions.push(endX - offsetX + adjustX, -halfHeight + (y + 1) * tileHeight + adjustY, 0);\r\n indices.push(index, index + 1, index + 3, index + 1, index + 2, index + 3);\r\n index += 4;\r\n if (\r\n flipTile === Mesh.FLIP_TILE ||\r\n flipTile === Mesh.ROTATE_TILE ||\r\n flipTile === Mesh.FLIP_N_ROTATE_TILE\r\n ) {\r\n uvs.set(uvBaseRC[(y + tilesX) % 2], index * 2);\r\n } else if (\r\n flipTile === Mesh.FLIP_ROW ||\r\n flipTile === Mesh.ROTATE_ROW ||\r\n flipTile === Mesh.FLIP_N_ROTATE_ROW\r\n ) {\r\n uvs.set(uvBaseRC[y % 2], index * 2);\r\n } else {\r\n uvs.set(uvBaseRC[0], index * 2);\r\n }\r\n colors.set(colorSet, index * 4);\r\n normals.set(normalSet, index * 3);\r\n }\r\n }\r\n }\r\n\r\n //reverse V values since old PlaneBuilder built them that way\r\n for (let i = 0; i < uvs.length / 2; i++) {\r\n uvs[i * 2 + 1] = 1 - uvs[i * 2 + 1];\r\n }\r\n\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n vertexData.applyToMesh(plane, options.updatable);\r\n\r\n return plane;\r\n }\r\n}\r\n","import { Vector4 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n */\r\nexport class DiscBuilder {\r\n /**\r\n * Creates a torus mesh\r\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\r\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\r\n * * The parameter `tessellation` sets the number of torus sides (postive integer, default 16)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the torus mesh\r\n * @see https://doc.babylonjs.com/how_to/set_shapes#torus\r\n */\r\n public static CreateDisc(\r\n name: string,\r\n options: {\r\n radius?: number;\r\n tessellation?: number;\r\n arc?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n updatable?: boolean;\r\n },\r\n scene: any\r\n ): Mesh {\r\n const disc = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n disc._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = createDisc(options);\r\n\r\n vertexData.applyToMesh(disc, options.updatable);\r\n\r\n return disc;\r\n\r\n function createDisc(options: {\r\n radius?: number;\r\n tessellation?: number;\r\n arc?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n }) {\r\n const positions = new Array();\r\n const indices = new Array();\r\n const normals = new Array();\r\n const uvs = new Array();\r\n\r\n const radius = options.radius || 0.5;\r\n const tessellation = options.tessellation || 64;\r\n const arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;\r\n const sideOrientation =\r\n options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // positions and uvs\r\n positions.push(0, 0, 0); // disc center first\r\n uvs.push(0.5, 0.5);\r\n\r\n const theta = Math.PI * 2 * arc;\r\n const step = theta / tessellation;\r\n for (let a = 0; arc === 1 ? a < theta : a <= theta; a += step) {\r\n const x = Math.cos(a);\r\n const y = Math.sin(a);\r\n const u = (x + 1) / 2;\r\n const v = (1 - y) / 2;\r\n positions.push(radius * x, radius * y, 0);\r\n uvs.push(u, v);\r\n }\r\n\r\n //indices\r\n const vertexNb = positions.length / 3;\r\n for (let i = 1; i < vertexNb - 1; i++) {\r\n indices.push(i + 1, 0, i);\r\n }\r\n\r\n if (arc === 1) {\r\n indices.push(1, 0, vertexNb - 1); // close the circle\r\n }\r\n\r\n // result\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n VertexData._ComputeSides(\r\n sideOrientation,\r\n positions,\r\n indices,\r\n normals,\r\n uvs,\r\n options.frontUVs,\r\n options.backUVs\r\n );\r\n\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n }\r\n }\r\n}\r\n","import { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { SketchPath } from '@models/classes/meshes/sketch-node-path';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { KbViewer } from '..';\r\nimport { Renderer } from './renderer';\r\n\r\nexport class PathRenderer extends Renderer {\r\n constructor(protected viewer: KbViewer, protected scene: Scene) {\r\n super(viewer, scene);\r\n }\r\n\r\n modelToken = Token.SketchPath;\r\n\r\n update3dInternal(node: ITrackedClass) {}\r\n}\r\n","import { Ray } from '@babylonjs/core/Culling/ray';\r\nimport { Axis, Color4, Matrix, Plane, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { DeepImmutableObject } from '@babylonjs/core/types';\r\nimport { eMateType } from '@models/classes/enums';\r\nimport { MateNode } from '@models/classes/mates/mate-node';\r\nimport { rotationToVectorToRef, toRadians } from './math-helper';\r\nimport { updateMatrixOfAncestorChain } from './scene-helper';\r\n\r\nconst ENABLE_DEBUG_VISUAL = false;\r\n\r\n// function limitFPE(val: number) {\r\n// return Math.round((val + Number.EPSILON) * 100000000) / 100000000;\r\n// }\r\n\r\n// function roundQuaterion(q: Quaternion) {\r\n// return new Quaternion(limitFPE(q.x), limitFPE(q.y), limitFPE(q.z), limitFPE(q.w));\r\n// }\r\nexport function mateControlPointToConnector(\r\n mate: Partial & Pick,\r\n c1Mesh: TransformNode,\r\n controlPointMesh: TransformNode\r\n) {\r\n let grandParentContainerWorldMatrixInv: DeepImmutableObject;\r\n if (controlPointMesh.parent) {\r\n grandParentContainerWorldMatrixInv = controlPointMesh.parent.computeWorldMatrix(true).clone().invert();\r\n } else {\r\n grandParentContainerWorldMatrixInv = Matrix.IdentityReadOnly;\r\n }\r\n\r\n const targetTransformMatrix = c1Mesh.computeWorldMatrix().clone();\r\n targetTransformMatrix.multiplyToRef(grandParentContainerWorldMatrixInv, targetTransformMatrix);\r\n const position = new Vector3();\r\n const direction = new Vector3();\r\n targetTransformMatrix.decompose(undefined, undefined, position);\r\n\r\n Vector3.TransformNormalFromFloatsToRef(-1.0, 0, 0, targetTransformMatrix, direction);\r\n\r\n if (!mate.flip) {\r\n direction.scaleInPlace(-1);\r\n }\r\n direction.normalize();\r\n\r\n return {\r\n position,\r\n direction,\r\n };\r\n}\r\n\r\nconst flipMatrix = new Matrix();\r\nQuaternion.RotationAxis(Axis.Y, toRadians(180)).toRotationMatrix(flipMatrix);\r\n\r\nconst debugViz = new Map();\r\n\r\nexport function mateConnectors(\r\n mate: Partial & Pick,\r\n followerMesh: TransformNode,\r\n c1Mesh: TransformNode,\r\n c2Mesh: TransformNode\r\n) {\r\n updateMatrixOfAncestorChain(followerMesh, c2Mesh);\r\n c1Mesh.computeWorldMatrix(true);\r\n let mateOffset = Vector3.Zero();\r\n let worldDelta = Vector3.Zero(); //the translation that c2 would need to make to get to it's new position\r\n\r\n if (mate.mateType == eMateType.ball) {\r\n /**\r\n * Ball Mate\r\n * -move c2 until it's in the same position as c1\r\n * In the future this could be made more intelligent by rotating a node to satisfy this mate and another ball or slider mate\r\n */\r\n worldDelta = c1Mesh.getAbsolutePosition().subtract(c2Mesh.getAbsolutePosition());\r\n } else {\r\n /**\r\n * Aligning direction vectors\r\n * ------------------------------------------------\r\n * Easiest way to think about this:\r\n * Connectors have a direction vector, and an angle of rotation around the direction vector.\r\n * The connector meshes are rotated by the renderer such that the positive X axis is pointing\r\n * in the direction of the direction vector. And the angle vector will be pointing in the direction\r\n * of the y axis.\r\n *\r\n * We want the world transformation matrix of the second connector to match the world transform of the first connector (optionally flipped).\r\n * The math for calculating the world matrix of a connector can be written as:\r\n * * * \r\n * We are trying to solve for the local transform matrix of the connector parent so the full world transform matches the transform of the first connector,\r\n * so we can rewrite the equation as:\r\n * = * * \r\n *\r\n * Then we apply the result matrix to the connector parent.\r\n */\r\n\r\n const t = new Vector3();\r\n const r = new Quaternion();\r\n const s = new Vector3();\r\n c1Mesh.computeWorldMatrix(true).decompose(s, r, t);\r\n if (mate.offsetAngle && mate.offsetAngle !== 0) {\r\n const angleOffsetQ = Quaternion.RotationAxis(Axis.X, (mate.offsetAngle * Math.PI) / 180);\r\n r.multiplyInPlace(angleOffsetQ);\r\n }\r\n const targetWorldTransformMatrix = Matrix.Compose(followerMesh.scaling, r, t);\r\n const currentWorldTransformMatrix = c2Mesh.computeWorldMatrix(true).clone();\r\n\r\n if (!mate.flip) {\r\n flipMatrix.multiplyToRef(targetWorldTransformMatrix, targetWorldTransformMatrix);\r\n }\r\n const c2LocalTransform = Matrix.Compose(c2Mesh.scaling, c2Mesh.rotationQuaternion!, c2Mesh.position);\r\n\r\n let grandParentContainerWorldMatrix: DeepImmutableObject;\r\n if (followerMesh.parent) {\r\n grandParentContainerWorldMatrix = followerMesh.parent.computeWorldMatrix(true).clone();\r\n } else {\r\n grandParentContainerWorldMatrix = Matrix.IdentityReadOnly;\r\n }\r\n const grandParentContainerWorldMatrixInv = grandParentContainerWorldMatrix.clone().invert();\r\n\r\n let calculatedTargetWorldTransform: Matrix | undefined;\r\n\r\n if (mate.mateType.equalsAny(eMateType.revolute, eMateType.cylindrical)) {\r\n /**\r\n * For these types of mates, the objective is to match the direction vectors but allow the angle to float freely.\r\n * What this means in practice is that we have to split the quaternion into a swing and a twist component.\r\n * The swing component will rotate the direction vector to point the right way, along a rotation axis equal to the cross product of the X axis and the direction vector,\r\n * and the twist component will rotate the mesh around the direction vector to match the desired angles. We then throw away the \"new\" twist angle and use the original twist angle.\r\n * For this to work it's necessary to ensure that the same rotation axis is used for both the swing rotation of the target and the swing rotation of the current, if the directions match.\r\n * Otherwise the twist angles won't be referring to the same thing.\r\n */\r\n const targetQ = Quaternion.FromRotationMatrix(targetWorldTransformMatrix.getRotationMatrix());\r\n const currentQ = Quaternion.FromRotationMatrix(currentWorldTransformMatrix.getRotationMatrix());\r\n const targetDirection = Vector3.TransformNormal(Axis.X, targetWorldTransformMatrix).normalize();\r\n const currentDirection = c2Mesh.right;\r\n\r\n // At direction vectors close to or equal to the X axis, the twist angle becomes heavily affected by floating point errors, so we avoid loops by not updating the rotation if the direction vectors are close to each other.\r\n if (currentDirection.add(targetDirection).length() > 0.0001) {\r\n const targetST = decomposeSwingTwist(targetQ, targetDirection.scale(-1));\r\n const currentST = decomposeSwingTwist(currentQ, currentDirection);\r\n const targetRotationNew = targetST.swing.multiply(currentST.twist);\r\n\r\n calculatedTargetWorldTransform = Matrix.Compose(followerMesh.scaling, targetRotationNew, t);\r\n }\r\n } else if (mate.mateType.equalsAny(eMateType.fastened, eMateType.planar, eMateType.slider)) {\r\n calculatedTargetWorldTransform = targetWorldTransformMatrix;\r\n }\r\n\r\n if (calculatedTargetWorldTransform) {\r\n const followerMeshTransformMatrix = c2LocalTransform.clone().invert();\r\n followerMeshTransformMatrix.multiplyToRef(calculatedTargetWorldTransform, followerMeshTransformMatrix);\r\n followerMeshTransformMatrix.multiplyToRef(grandParentContainerWorldMatrixInv, followerMeshTransformMatrix);\r\n\r\n const resultFollowerRotMatrix = followerMeshTransformMatrix.getRotationMatrix();\r\n\r\n if (ENABLE_DEBUG_VISUAL) {\r\n const targetForward = Vector3.TransformNormal(Axis.X, targetWorldTransformMatrix).normalize();\r\n const targetLeft = Vector3.TransformNormal(Axis.Z, targetWorldTransformMatrix).normalize();\r\n\r\n const c2CalcWorldTransformMatrix = c2LocalTransform\r\n .multiply(resultFollowerRotMatrix)\r\n .multiply(grandParentContainerWorldMatrix);\r\n const calcDirection = Vector3.TransformNormal(Axis.X, c2CalcWorldTransformMatrix).normalize();\r\n const calcAngle = Vector3.TransformNormal(Axis.Z, c2CalcWorldTransformMatrix).normalize();\r\n updateVisualization(\r\n mate._dynamicId || '',\r\n c2Mesh.getScene(),\r\n c2Mesh.getAbsolutePosition(),\r\n calcAngle,\r\n calcDirection,\r\n targetLeft,\r\n targetForward\r\n );\r\n } else {\r\n followerMesh.rotationQuaternion = Quaternion.FromRotationMatrix(resultFollowerRotMatrix);\r\n updateMatrixOfAncestorChain(followerMesh, c2Mesh); //update world matrix after having just rotated follower mesh\r\n }\r\n }\r\n\r\n if (mate.mateType == eMateType.fastened || mate.mateType == eMateType.revolute) {\r\n //translate so the connectors line up\r\n worldDelta = c1Mesh.getAbsolutePosition().subtract(c2Mesh.getAbsolutePosition());\r\n mateOffset = new Vector3(mate.offsetX, mate.offsetY, mate.offsetZ);\r\n } else if (mate.mateType == eMateType.planar) {\r\n /**\r\n * Planar Mate\r\n * - define a plane at the position of c1, with a normal in the direction of c1\r\n * - make a ray from c2 in the direction of c2, and try to intersect the c1 plane\r\n * - if it doesn't intersect, flip it and try again\r\n * - the intersection of the ray and plane is the new position of c2 (not considering offset)\r\n */\r\n const c1PlaneNormal = Axis.X.rotateByQuaternionToRef(c1Mesh.absoluteRotationQuaternion, Vector3.Zero());\r\n const c1Plane = Plane.FromPositionAndNormal(c1Mesh.getAbsolutePosition(), c1PlaneNormal);\r\n const c2Direction = Axis.X.rotateByQuaternionToRef(c2Mesh.absoluteRotationQuaternion, Vector3.Zero());\r\n const ray = new Ray(c2Mesh.getAbsolutePosition(), c2Direction);\r\n let distance = ray.intersectsPlane(c1Plane);\r\n if (distance == null) {\r\n //if it doesn't intersect try flipping it\r\n ray.direction.negateInPlace();\r\n distance = ray.intersectsPlane(c1Plane);\r\n }\r\n worldDelta = ray.direction.scale(distance!);\r\n mateOffset = new Vector3(mate.offsetX, 0, 0); //only use the x component for planar mates\r\n } else if (mate.mateType == eMateType.slider || mate.mateType == eMateType.cylindrical) {\r\n /**\r\n * Slider Mate\r\n * - define a plane at the position of c2, with a normal in the direction of c2\r\n * - make a ray from c1 in the direction of c1, and try to intersect the c2 plane\r\n * - if it doesn't intersect, flip it and try again\r\n * - the intersection of the ray and plane is the new position of c2 (not considering offset)\r\n */\r\n const c1Pos = c1Mesh.getAbsolutePosition();\r\n const c2Pos = c2Mesh.getAbsolutePosition();\r\n const c2PlaneNormal = c2Mesh.getDirection(Axis.X).normalize();\r\n const c2Plane = Plane.FromPositionAndNormal(c2Pos, c2PlaneNormal);\r\n const c1Direction = c1Mesh.getDirection(Axis.X).normalize();\r\n const ray = new Ray(c1Pos, c1Direction);\r\n let distance = ray.intersectsPlane(c2Plane);\r\n if (distance == null) {\r\n //if it doesn't intersect try flipping it\r\n ray.direction.negateInPlace();\r\n distance = ray.intersectsPlane(c2Plane);\r\n }\r\n worldDelta = ray.direction.scale(distance!).add(c1Pos).subtract(c2Pos);\r\n mateOffset = new Vector3(0, mate.offsetY, mate.offsetZ); //don't use the x component for slider mates\r\n } else if (mate.mateType == eMateType.parallel) {\r\n //nothing to do for parallel\r\n }\r\n }\r\n\r\n /**\r\n * now we process the offset and set the position of c2 parent node\r\n */\r\n if (!mate.flip) mateOffset.negateInPlace();\r\n if (mate._swap) mateOffset.y = -mateOffset.y;\r\n const worldOffset = mateOffset.rotateByQuaternionToRef(c1Mesh.absoluteRotationQuaternion, Vector3.Zero());\r\n const totalOffset = worldOffset.add(worldDelta);\r\n const newAbsPos = followerMesh.getAbsolutePosition().add(totalOffset);\r\n followerMesh.setAbsolutePosition(newAbsPos);\r\n followerMesh.computeWorldMatrix(true);\r\n}\r\n\r\nfunction updateVisualization(\r\n id: string,\r\n scene: Scene,\r\n position: Vector3,\r\n calcLeft: Vector3,\r\n calcForward: Vector3,\r\n targetLeft: Vector3,\r\n targetForward: Vector3\r\n) {\r\n const lines = [\r\n [position.add(calcLeft), position, position.add(calcForward)],\r\n [position.add(targetLeft.scale(-1)), position, position.add(targetForward.scale(-1))],\r\n ];\r\n let viz = debugViz.get(id);\r\n if (!viz) {\r\n viz = MeshBuilder.CreateLineSystem(\r\n id,\r\n {\r\n lines,\r\n updatable: true,\r\n colors: [\r\n [new Color4(1, 0, 0, 1), new Color4(1, 1, 1, 0.5), new Color4(1, 1, 0, 1)],\r\n [new Color4(0, 1, 0, 1), new Color4(1, 1, 1, 0.5), new Color4(1, 1, 1, 1)],\r\n ],\r\n },\r\n scene\r\n );\r\n debugViz.set(id, viz);\r\n } else {\r\n viz = MeshBuilder.CreateLineSystem(id, { lines, updatable: true, instance: viz }, scene);\r\n }\r\n}\r\n\r\n/**\r\n Decompose the rotation on to 2 parts.\r\n 1. Twist - rotation around the \"direction\" vector\r\n 2. Swing - rotation around axis that is perpendicular to \"direction\" vector\r\n The rotation can be composed back by \r\n rotation = swing * twist\r\n\r\n has singularity in case of swing_rotation close to 180 degrees rotation.\r\n if the input quaternion is of non-unit length, the outputs are non-unit as well\r\n otherwise, outputs are both unit\r\n*/\r\nfunction decomposeSwingTwist(rotation: Quaternion, _direction: Vector3) {\r\n // Ensure the direction vector is normalized\r\n const direction = _direction.clone().normalize();\r\n const twist = new Quaternion();\r\n const swing = new Quaternion();\r\n\r\n // Alternate code with indeterminate swing axis\r\n // const ra = new Vector3(rotation.x, rotation.y, rotation.z);\r\n // const p = direction.scale(Vector3.Dot(ra, direction));\r\n // twist.set(p.x, p.y, p.z, rotation.w);\r\n // twist.normalize();\r\n // rotation.multiplyToRef(twist.conjugate(), swing);\r\n rotationToVectorToRef(direction, Axis.X, swing);\r\n swing.conjugate().multiplyToRef(rotation, twist);\r\n\r\n return { twist, swing };\r\n}\r\n","import { eConnectorPositionMode } from '@models/classes/enums';\r\nimport { SketchControlPoint, isConnector } from '@models/classes/features';\r\nimport { ArrayMap } from '@models/classes/handlers';\r\nimport { MateNode } from '@models/classes/mates/mate-node';\r\nimport { isSketchControlPoint } from '@models/classes/meshes/mesh-utilities';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\n\r\nexport enum ConstraintType {\r\n Sphere, // Constrains the target to a point on a shell around a point\r\n Line, // Constrains the target to a point along a line through a point\r\n Plane, // Constrains the target to a point on a plane\r\n Fixed, // Constrains the target to a fixed point\r\n None, // Does not constrain the target\r\n}\r\n\r\nexport interface ConstraintDef {\r\n [ConstraintType.Sphere]: { x: number; y: number; z: number; radius: number };\r\n [ConstraintType.Line]: { x: number; y: number; z: number; dx: number; dy: number; dz: number };\r\n [ConstraintType.Plane]: { x: number; y: number; z: number; nx: number; ny: number; nz: number };\r\n [ConstraintType.Fixed]: void;\r\n [ConstraintType.None]: void;\r\n [key: number]: unknown;\r\n}\r\n\r\ntype ConstraintDefMap = {\r\n [key in ConstraintType]: {\r\n type: key;\r\n properties: ConstraintDef[key];\r\n };\r\n};\r\ntype MateConstraint = ConstraintDefMap[keyof ConstraintDefMap];\r\n\r\ntype MatedObject = SpaceNode | SketchControlPoint;\r\n\r\ninterface MateEdge {\r\n target: MatedObject;\r\n /** if a mate is not constraining the target node's other */\r\n constraint: MateConstraint;\r\n /** if mate is null means it's a parent/child edge */\r\n mate?: MateNode;\r\n}\r\n\r\nexport interface MateSorterResult {\r\n sorted: Set;\r\n cycles: MateNode[][];\r\n overConstrained: MateNode[];\r\n}\r\n\r\nexport function sortMates(validMates: MateNode[]) {\r\n const fixed = new Set();\r\n const primes = new Set();\r\n const nodeMap = getNodeMap(validMates);\r\n\r\n //parent/child relationships are also a kind of edge in our graph, so add them\r\n for (const [node] of nodeMap) {\r\n if (node instanceof SpaceNode) {\r\n if (node.fixed) {\r\n fixed.add(node);\r\n } else if (node._primeMover) {\r\n primes.add(node);\r\n }\r\n for (const ancestor of node.getAncestors()) {\r\n if (nodeMap.has(ancestor as MatedObject)) {\r\n nodeMap.add(node, {\r\n target: ancestor as MatedObject,\r\n constraint: { type: ConstraintType.None, properties: undefined },\r\n });\r\n nodeMap.add(ancestor as MatedObject, {\r\n target: node,\r\n constraint: { type: ConstraintType.Fixed, properties: undefined },\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * * starting with primes, recurse through. Then move to non-primes, ignoring those already visited.\r\n */\r\n const visitedNodes = new Set();\r\n const visitedMates = new Set();\r\n const nodePath = new Set();\r\n const matePath = new Set();\r\n const sorted = new Set();\r\n const cycles = new Array();\r\n const overConstrained = new Array();\r\n\r\n for (const n of [...fixed, ...primes, ...nodeMap.keys()]) {\r\n recurseMateChain(nodeMap, visitedNodes, visitedMates, nodePath, matePath, sorted, cycles, overConstrained, n);\r\n }\r\n\r\n //remove overconstrained mates from sorted so they don't get processed\r\n for (const m of overConstrained) {\r\n sorted.delete(m);\r\n }\r\n\r\n return {\r\n sorted,\r\n cycles,\r\n overConstrained,\r\n } as MateSorterResult;\r\n}\r\n\r\n/**\r\n * Gets the nodes that are connected to the given through a chain of mates\r\n */\r\nexport function getNodeChain(node: MatedObject, validMates: MateNode[]) {\r\n const nodeMap = getNodeMap(validMates);\r\n const visitedNodes = new Set();\r\n const visitedMates = new Set();\r\n const nodePath = new Set();\r\n const matePath = new Set();\r\n const sorted = new Set();\r\n const cycles = new Array();\r\n const overConstrained = new Array();\r\n\r\n recurseMateChain(nodeMap, visitedNodes, visitedMates, nodePath, matePath, sorted, cycles, overConstrained, node);\r\n\r\n visitedNodes.delete(node);\r\n\r\n return visitedNodes;\r\n}\r\n\r\nexport function getNodeMap(validMates: MateNode[]) {\r\n const nodeMap = new ArrayMap();\r\n for (const mate of validMates) {\r\n const c1 = mate.getC1();\r\n const c2 = mate.getC2();\r\n let c1Parent: SpaceNode | SketchControlPoint | undefined = c1?.getSpaceParent();\r\n let c2Parent: SpaceNode | SketchControlPoint | undefined = c2?.getSpaceParent();\r\n if (c1 && isSketchControlPoint(c1)) {\r\n c1Parent = c1;\r\n }\r\n\r\n if (c2 && isSketchControlPoint(c2)) {\r\n c2Parent = c2;\r\n }\r\n\r\n if (c1 && c2 && c1Parent && c2Parent) {\r\n const constraint: MateConstraint = { type: ConstraintType.Fixed, properties: undefined };\r\n\r\n // TODO [RO] - Later on we can add more constraint types here based on mate type (CPQ-3881)\r\n //if (isConstrainingConnector(c1) && isConstrainingConnector(c2)) {\r\n // constraint = { type: ConstraintType.Fixed, properties: undefined };\r\n // } else {\r\n // constraint = { type: ConstraintType.None, properties: undefined };\r\n // }\r\n\r\n nodeMap.add(c1Parent, { target: c2Parent, mate, constraint });\r\n nodeMap.add(c2Parent, { target: c1Parent, mate, constraint });\r\n }\r\n }\r\n return nodeMap;\r\n}\r\n\r\nfunction recurseMateChain(\r\n nodeMap: ArrayMap,\r\n visitedNodes: Set,\r\n visitedMates: Set,\r\n nodePath: Set,\r\n matePath: Set,\r\n sorted: Set,\r\n cycles: MateNode[][],\r\n overConstrained: MateNode[],\r\n node: MatedObject,\r\n mate?: MateNode,\r\n sourceEdge?: MateEdge,\r\n isOverconstrained = false\r\n) {\r\n if (!sourceEdge || sourceEdge.constraint.type === ConstraintType.Fixed) {\r\n if (nodePath.has(node)) {\r\n const cycle = [...matePath];\r\n if (mate) {\r\n cycle.push(mate);\r\n }\r\n cycles.push(cycle);\r\n }\r\n\r\n if (visitedNodes.has(node)) {\r\n return;\r\n }\r\n }\r\n visitedNodes.add(node);\r\n nodePath.add(node);\r\n\r\n if (mate) {\r\n matePath.add(mate);\r\n visitedMates.add(mate);\r\n\r\n sorted.add(mate);\r\n const c1 = mate.getC1()!;\r\n const c2 = mate.getC2()!;\r\n /** Move along sketch connectors should always be the connector 1, because they can't be moved (they are read only) */\r\n if (c2.positionMode === eConnectorPositionMode.moveAlongSketch) {\r\n mate._swap = true;\r\n }\r\n /** Control points are always follower meshes */\r\n else if (isConnector(c1) && isSketchControlPoint(c2)) {\r\n mate._swap = false;\r\n } else if (isConnector(c2) && isSketchControlPoint(c1)) {\r\n mate._swap = true;\r\n } else {\r\n /** mate needs to have c1/c2 swapped if we got here in the opposite direction */\r\n mate._swap = c1._parent! === node;\r\n }\r\n }\r\n\r\n // If the source edge is fixed, we recurse through the node because all the node's connectors will be shifting.\r\n // If the source edge is not fixed, we stop here because only the mated connector will move\r\n // [RO] TODO eventually we will have to rethink this logic to support more constraint types (CPQ-3881)\r\n if (!sourceEdge || sourceEdge.constraint.type === ConstraintType.Fixed) {\r\n for (const edge of nodeMap.get(node)) {\r\n if (!edge.mate || !visitedMates.has(edge.mate)) {\r\n if (\r\n edge.target instanceof SpaceNode &&\r\n edge.target.fixed &&\r\n edge.constraint.type !== ConstraintType.None\r\n ) {\r\n isOverconstrained = true;\r\n }\r\n recurseMateChain(\r\n nodeMap,\r\n visitedNodes,\r\n visitedMates,\r\n nodePath,\r\n matePath,\r\n sorted,\r\n cycles,\r\n overConstrained,\r\n edge.target,\r\n edge.mate,\r\n edge,\r\n isOverconstrained\r\n );\r\n }\r\n }\r\n }\r\n\r\n nodePath.delete(node);\r\n if (mate) {\r\n matePath.delete(mate);\r\n if (isOverconstrained) {\r\n overConstrained.push(mate);\r\n }\r\n visitedMates.delete(mate);\r\n }\r\n}\r\n","import { ChangeMap } from '../renderer-manager';\r\n\r\nexport abstract class Processor {\r\n private afterCleanupTasks: Array<() => void> = [];\r\n\r\n beforeRender() {}\r\n beforeDeletions(deletions: ChangeMap) {}\r\n afterDeletions(deletions: ChangeMap) {}\r\n beforeUpdates(changes: ChangeMap) {}\r\n afterUpdates(changes: ChangeMap) {}\r\n afterCleanup(func: () => void) {\r\n this.afterCleanupTasks.push(func);\r\n }\r\n doAfterCleanup() {\r\n this.afterCleanupTasks.forEach(task => task());\r\n this.afterCleanupTasks.clear();\r\n }\r\n dispose() {}\r\n}\r\n","import { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { BaseConnector } from '@models/classes/features';\r\nimport { Connector, isConnector } from '@models/classes/features/connector';\r\nimport { MateNode } from '@models/classes/mates/mate-node';\r\nimport { isSketchControlPoint } from '@models/classes/meshes/mesh-utilities';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { mateConnectors, mateControlPointToConnector } from '@view/helpers/mate-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { ConnectorRenderer } from '../features/connector';\r\nimport { SketchControlPointRenderer } from '../features/sketch-control-point';\r\nimport { ChangeMap } from '../renderer-manager';\r\nimport { sortMates } from './mate-sorter';\r\nimport { Processor } from './processor';\r\nimport { ReferenceProcessor } from './reference-processor';\r\nimport { eConnectorPositionMode } from '@models/classes';\r\n\r\nconst CYCLE_ERROR_START = 'Cycle detected: ';\r\n\r\nexport class MateProcessor extends Processor {\r\n /**\r\n * Mates sorted based on their dependencies of each other\r\n */\r\n private sortedMates: Set;\r\n /**\r\n * If during rebuilding of the sorted mate graph any cycles are detected, they are stored here\r\n */\r\n private cycles: MateNode[][];\r\n\r\n /**\r\n * we try to avoid rebuilding the mate dependency graph unless a change warrants it.\r\n */\r\n private rebuildDependencies: boolean;\r\n\r\n constructor(\r\n protected viewer: KbViewer,\r\n protected scene: Scene,\r\n protected connectorRenderer: ConnectorRenderer,\r\n protected controlPointRenderer: SketchControlPointRenderer,\r\n protected referenceProcessor: ReferenceProcessor\r\n ) {\r\n super();\r\n }\r\n\r\n beforeRender() {\r\n this.rebuildDependencies = false;\r\n }\r\n\r\n beforeDeletions(deletions: ChangeMap) {\r\n const mateDeletions = deletions.get(Token.MateNode) as Array>;\r\n const connectorDeletions = deletions.get(Token.Connector) as Array>;\r\n this.rebuildDependencies =\r\n this.rebuildDependencies || mateDeletions.length > 0 || connectorDeletions.length > 0;\r\n }\r\n\r\n beforeUpdates(changes: ChangeMap) {\r\n //determine if mate dependencies need to be rebuilt\r\n const mateChanges = changes.get(Token.MateNode) as Array>;\r\n const connectorChanges = changes.get(Token.Connector) as Array>;\r\n const meshChanges = changes.get(Token.SpaceNode) as Array>;\r\n\r\n this.rebuildDependencies =\r\n this.rebuildDependencies ||\r\n mateChanges.some(m => m.changes.hasAny('connector1', 'connector2', 'enabled')) ||\r\n connectorChanges.some(c => c.changes.has('enabled')) ||\r\n meshChanges.some(c => c.changes.hasAny('fixed', '_primeMover'));\r\n\r\n /**\r\n * Mates need to be reprocessed if:\r\n * * the mate itself was changed\r\n * * connector1 of the node was changed\r\n * * parent node of connector1 was changed\r\n * * any ancestor space node of the parent node was changed\r\n * * any parent graph dependency node mate or it's parents were changed\r\n */\r\n }\r\n\r\n afterUpdates(changes: ChangeMap) {\r\n if (this.rebuildDependencies) {\r\n this.buildDependencies();\r\n }\r\n if (this.sortedMates) {\r\n if (\r\n changes.has(Token.MateNode) ||\r\n changes.has(Token.SpaceNode) ||\r\n changes.has(Token.Connector) ||\r\n changes.has(Token.Feature)\r\n ) {\r\n for (const mate of this.sortedMates) {\r\n //don't process the last mate in a cycle\r\n if (!this.cycles || !this.cycles.some(c => c.last() === mate)) {\r\n this.processMate(mate);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n dispose() {\r\n if (this.sortedMates) this.sortedMates.clear();\r\n if (this.cycles) this.cycles.clear();\r\n }\r\n\r\n processMate(mate: MateNode) {\r\n let c1 = mate.getC1()!;\r\n let c2 = mate.getC2()!;\r\n\r\n /** \r\n * If the sorter determined we need to swap the connectors. \r\n * */\r\n if (mate._swap || c2.positionMode === eConnectorPositionMode.moveAlongSketch) {\r\n const temp = c1;\r\n c1 = c2;\r\n c2 = temp;\r\n }\r\n\r\n const c1Mesh = this.getConnectorMesh(c1);\r\n const c2Mesh = this.getConnectorMesh(c2);\r\n const followerNode = c2._parent! as ITrackedClass;\r\n const followerMesh = this.viewer.rendererManager.mesh.get3d(followerNode) as TransformNode;\r\n\r\n if (!c1Mesh || !c2Mesh) return;\r\n\r\n /** \r\n * Move along sketch connectors cannot be moved, because their position is being set by the sketch itself. They can only be used \r\n * to determine the position of other connectors. Moving them will cause an immediate overconstraint condition\r\n */\r\n if(c2.positionMode === eConnectorPositionMode.moveAlongSketch) {\r\n return;\r\n }\r\n\r\n if (isSketchControlPoint(c2)) {\r\n const cp = c2;\r\n this.viewer.pauseRenderWhile(() => {\r\n const nodeWithTransform = mateControlPointToConnector(mate, c1Mesh, c2Mesh);\r\n const d1 = nodeWithTransform.direction.scale(cp.direction.length())\r\n const d2 = cp.direction2 ? nodeWithTransform.direction.scale(cp.direction2.length()) : undefined;\r\n if(\r\n !nodeWithTransform.position.equalsWithEpsilon(cp.position.toVec3()) || \r\n !d1.equalsWithEpsilon(cp.direction.toVec3()) || \r\n (cp.direction2 && d2 && !d2.equalsWithEpsilon(cp.direction2.toVec3()))\r\n ) {\r\n this.afterCleanup(() => {\r\n cp.position = KbVector.FromVec3(nodeWithTransform.position);\r\n cp.direction = KbVector.FromVec3(d1);\r\n if(cp.direction2 && d2) {\r\n cp.direction2 = KbVector.FromVec3(d2);\r\n }\r\n });\r\n }\r\n });\r\n } else if (followerMesh) {\r\n this.viewer.pauseRenderWhile(() => {\r\n const originalFollowerMeshAbsPos = followerMesh.getAbsolutePosition();\r\n const originalFollowerMeshAbsQuat = followerMesh.absoluteRotationQuaternion.clone();\r\n const originalFollowerMeshLocalPos = followerMesh.position.clone();\r\n const originalFollowerMeshLocalQuat = followerMesh.rotationQuaternion!.clone();\r\n\r\n mateConnectors(mate, followerMesh, c1Mesh, c2Mesh);\r\n\r\n /** update real kb3d nodes with new transform info */\r\n if (\r\n !originalFollowerMeshLocalPos.equalsWithEpsilon(followerMesh.position) ||\r\n !originalFollowerMeshLocalQuat.equalsWithEpsilon(followerMesh.rotationQuaternion!)\r\n ) {\r\n followerNode.trackChanges(false);\r\n followerNode.setRotationQuaternion(KbQuaternion.FromQuat(followerMesh.rotationQuaternion!));\r\n followerNode.position = KbVector.FromVec3(followerMesh.position);\r\n followerNode.trackChanges(true);\r\n this.referenceProcessor.triggerChangesOnReferencers(followerNode, new Map([['position', null]]));\r\n }\r\n\r\n /** invalidate bounding box of parent if follower mesh actually moved */\r\n if (\r\n !originalFollowerMeshAbsPos.equalsWithEpsilon(followerMesh.getAbsolutePosition()) ||\r\n !originalFollowerMeshAbsQuat.equalsWithEpsilon(followerMesh.absoluteRotationQuaternion)\r\n ) {\r\n this.viewer.bbCache.invalidate(c2.getSpaceParent());\r\n }\r\n\r\n //console.log(`mate '${mate.name} processed`);\r\n });\r\n }\r\n }\r\n\r\n protected getConnectorMesh(c: BaseConnector) {\r\n if (isSketchControlPoint(c)) {\r\n return this.controlPointRenderer.get3d(c)!;\r\n } else if (isConnector(c)) {\r\n return this.connectorRenderer.get3d(c)!;\r\n }\r\n }\r\n\r\n protected buildDependencies() {\r\n const mates = this.getValidMates();\r\n const sortResult = sortMates(mates);\r\n this.sortedMates = sortResult.sorted;\r\n this.cycles = sortResult.cycles;\r\n\r\n const validator = this.viewer.options.validator;\r\n for (const cycle of sortResult.cycles) {\r\n const err = `${CYCLE_ERROR_START}${cycle.map(n => n.name).join(' -> ')}`;\r\n if (validator) {\r\n for (const cm of cycle) {\r\n validator.addError(cm, '', err);\r\n }\r\n } else {\r\n console.warn(err);\r\n }\r\n }\r\n if (validator) {\r\n for (const om of sortResult.overConstrained) {\r\n validator.addError(om, '', `Cannot have more than one fixed node in the mate chain`);\r\n }\r\n } else {\r\n if (sortResult.overConstrained.length) {\r\n console.warn(`Mates overconstrained: [${sortResult.overConstrained.map(n => n.name).join(', ')}]`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * gets all mates (including those in nested scenes)\r\n * that are enabled, and have valid references to connectors\r\n */\r\n protected getValidMates() {\r\n const rootScene = this.viewer.sceneNode;\r\n const mates = new Array();\r\n const validator = this.viewer.options.validator;\r\n\r\n rootScene.runOnAllScenes(s => {\r\n const sceneMates = s._manager!.getByToken(Token.MateNode);\r\n for (const m of sceneMates) {\r\n if (m.isActive()) {\r\n mates.push(m);\r\n }\r\n\r\n //regardless, clear out cycle validation\r\n if (validator) {\r\n validator.clearProp(m, '');\r\n }\r\n }\r\n });\r\n return mates;\r\n }\r\n}\r\n","import { Quaternion } from '@babylonjs/core/Maths';\r\nimport { SolidParticle } from '@babylonjs/core/Particles/solidParticle';\r\nimport { CircularPatternFeature } from '@models/classes/features/circular-pattern-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { PatternRenderer } from './pattern';\r\n\r\nexport class CircularPatternRenderer extends PatternRenderer {\r\n modelToken = Token.CircularPatternFeature;\r\n updateMeshGeometry(\r\n feature: CircularPatternFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const featurePivot = feature.pivot.toVec3();\r\n const featureAxis = feature.axis.toVec3();\r\n // Don't allow a zero vector for an axis because it will blow up the math\r\n if (featureAxis.equalsToFloats(0, 0, 0)) {\r\n featureAxis.set(0, 1, 0);\r\n }\r\n const featureArc = (feature.arc * Math.PI) / 180 / feature.count;\r\n const workingQuaternion = Quaternion.Identity();\r\n\r\n return super.updateMeshGeometry(\r\n feature,\r\n vertexData,\r\n vertexDataChanges,\r\n (idx: number, particle: SolidParticle) => {\r\n particle.pivot = featurePivot;\r\n Quaternion.RotationAxisToRef(featureAxis, featureArc * idx, workingQuaternion);\r\n particle.rotationQuaternion!.multiplyInPlace(workingQuaternion);\r\n }\r\n );\r\n }\r\n}\r\n","import { DeleteFacesFeature } from '@models/classes/features/delete-faces-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nexport class DeleteFacesRenderer extends FeatureRenderer {\r\n modelToken = Token.DeleteFacesFeature;\r\n updateMeshGeometry(\r\n feature: ITrackedClass,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n\r\n if (newVertexData.indices && feature.vertexGroups.length > 0) {\r\n const vertexGroups = feature.vertexGroups.sort((groupA, groupB) => groupA.startIndex - groupB.startIndex);\r\n const newIndices = new Int32Array(newVertexData.indices);\r\n let currReadIndex = 0;\r\n\r\n vertexGroups.forEach(vertexGroup => {\r\n for (\r\n let i = Math.max(vertexGroup.startIndex, currReadIndex);\r\n i < Math.min(vertexGroup.endIndex, newIndices.length);\r\n i++\r\n ) {\r\n newIndices[i] = -1;\r\n }\r\n currReadIndex = vertexGroup.endIndex;\r\n });\r\n\r\n // We need to remove submeshes targetting the indices that are being removed as well\r\n if (newVertexData.submeshData) {\r\n newVertexData.submeshData.forEach(submeshData => {\r\n const indexStart = submeshData.indexStart;\r\n for (let i = 0; i < indexStart; i++) {\r\n if (newIndices[i] === -1) {\r\n submeshData.indexStart--;\r\n }\r\n }\r\n const indexCount = submeshData.indexCount;\r\n for (let i = 0; i < indexCount; i++) {\r\n const index = indexStart + i;\r\n if (newIndices[index] === -1) {\r\n submeshData.indexCount--;\r\n }\r\n }\r\n });\r\n }\r\n\r\n newVertexData.indices = newIndices.filter(index => index !== -1);\r\n }\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n}\r\n","import { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { getBinClampedSize } from '@common-util/texture-util';\r\nimport { eTextureChannel } from '@models/classes';\r\nimport { DisplacementMapFeature } from '@models/classes/features/displacement-map-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\nimport { ensureNormalsExist } from './utils';\r\n\r\nexport class DisplacementMapRenderer extends FeatureRenderer {\r\n _initialized: boolean;\r\n modelToken = Token.DisplacementMapFeature;\r\n textureCanvas = document.createElement('canvas');\r\n\r\n updateMeshGeometry(\r\n feature: DisplacementMapFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n const textureRenderer = this.viewer.rendererManager.textures;\r\n if (feature.textures && feature.textures.length > 0) {\r\n //create context\r\n const context = this.textureCanvas.getContext('2d', {\r\n willReadFrequently: true,\r\n });\r\n const strength = 1;\r\n const hasTransparency = false;\r\n const parameters = { strength, hasTransparency };\r\n\r\n const textureLayers = textureRenderer.getActiveLayers(feature, eTextureChannel.albedo).filter(node => {\r\n const renderer = textureRenderer.getRenderer(node);\r\n return renderer.textureHasContent(node);\r\n });\r\n\r\n if (context) {\r\n const baseImageSize = textureRenderer\r\n .getRenderer(feature.textures[0])\r\n .getNativeSize(feature.textures[0]);\r\n if (this.scene.getEngine().webGLVersion < 2) {\r\n const clampedSize = getBinClampedSize(baseImageSize.width, baseImageSize.height);\r\n context.canvas.width = clampedSize;\r\n context.canvas.height = clampedSize;\r\n } else {\r\n if (feature.textures[0]) {\r\n context.canvas.width = baseImageSize.width;\r\n context.canvas.height = baseImageSize.height;\r\n }\r\n }\r\n context.clearRect(0, 0, context.canvas.width, context.canvas.height);\r\n\r\n const paintedImage = textureRenderer.paintTextureOnCanvas(textureLayers, context, parameters);\r\n\r\n const tempVertexData = new SubmeshVertexData();\r\n tempVertexData.copyFrom(newVertexData);\r\n if (tempVertexData.uvs) {\r\n const n = tempVertexData.uvs.length;\r\n for (let i = 1; i < n; i += 2) {\r\n tempVertexData.uvs[i] = 1 - tempVertexData.uvs[i];\r\n }\r\n\r\n const mesh = this.viewer.getRendererNode(feature._parent!);\r\n const meshUpdated = new Mesh('ExistingMesh');\r\n tempVertexData.applyToMesh(meshUpdated, true);\r\n ensureNormalsExist(meshUpdated);\r\n\r\n const imageData = paintedImage?.getImageData(\r\n 0,\r\n 0,\r\n this.textureCanvas.width,\r\n this.textureCanvas.height,\r\n mesh\r\n );\r\n if (imageData) {\r\n this.displace(imageData, feature.minDisplacement, feature.maxDisplacement, meshUpdated);\r\n }\r\n const meshVertexData = VertexData.ExtractFromMesh(meshUpdated);\r\n newVertexData.positions = meshVertexData.positions;\r\n newVertexData.normals = meshVertexData.normals;\r\n meshUpdated.dispose();\r\n }\r\n }\r\n }\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n\r\n displace(context: ImageData, minDisplacement: number, maxDisplacement: number, parentMesh: Mesh) {\r\n const uInt8Array = new Uint8Array(context.data);\r\n parentMesh.applyDisplacementMapFromBuffer(\r\n uInt8Array,\r\n context.width,\r\n context.height,\r\n minDisplacement,\r\n maxDisplacement\r\n );\r\n }\r\n}\r\n","import { Matrix, Vector2, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { PolygonMeshBuilder } from '@babylonjs/core/Meshes/polygonMesh';\r\nimport { FloatArray } from '@babylonjs/core/types';\r\nimport { ExtrudeFeature, Token, eAxis, isSketchNode } from '@models/classes';\r\nimport { earcut } from '@view/helpers/earcut';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { rotationToVector } from '@view/helpers/math-helper';\r\nimport { axisToVector3, parseSketchGeometry } from '@view/modules/sketching/util';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nconst xztoxy = Matrix.FromArray([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\r\n\r\nexport class ExtrudeRenderer extends FeatureRenderer {\r\n modelToken = Token.ExtrudeFeature;\r\n\r\n updateMeshGeometry(feature: T, vertexData: SubmeshVertexData, vertexDataChanges: Partial) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n const parentMesh = feature._parent;\r\n\r\n if (\r\n parentMesh &&\r\n newVertexData.positions &&\r\n newVertexData.positions.length &&\r\n // paths are used by parseSketchGeometry\r\n newVertexData.paths &&\r\n newVertexData.paths.length > 0 &&\r\n feature.size !== 0\r\n ) {\r\n const { segments, holes } = parseSketchGeometry(newVertexData);\r\n const extrudedMeshes: Mesh[] = [];\r\n\r\n for (let i = 0; i < segments.length; i++) {\r\n const shape = segments[i];\r\n const shapeHoles = holes.get(i);\r\n\r\n const sketch = feature._parent && isSketchNode(feature._parent) ? feature._parent : undefined;\r\n const sketchNormal = sketch ? axisToVector3(sketch.normal) : Vector3.Zero();\r\n if (sketch && sketch.normal !== eAxis.z) {\r\n sketchNormal.scaleInPlace(-1);\r\n }\r\n\r\n const rotToZ = rotationToVector(sketchNormal, new Vector3(0, 0, 1));\r\n const pathTransformToZ = new Matrix();\r\n const pathTransformToZInv = new Matrix();\r\n rotToZ.toRotationMatrix(pathTransformToZ);\r\n pathTransformToZ.invertToRef(pathTransformToZInv);\r\n\r\n for (let i = 0; i < shape.length; i++) {\r\n Vector3.TransformCoordinatesToRef(shape[i], pathTransformToZ, shape[i]);\r\n }\r\n\r\n const shape2d = shape.map(point => new Vector2(point.x, point.y));\r\n\r\n const builder = new PolygonMeshBuilder(feature._dynamicId, shape2d, this.scene, earcut);\r\n if (shapeHoles) {\r\n shapeHoles.forEach(holePoints => {\r\n for (let i = 0; i < holePoints.length; i++) {\r\n Vector3.TransformCoordinatesToRef(holePoints[i], pathTransformToZ, holePoints[i]);\r\n }\r\n const hole2d = holePoints.map(point => new Vector2(point.x, point.y));\r\n builder.addHole(hole2d);\r\n });\r\n }\r\n const extruded = builder.build(true, Math.abs(feature.size), 0.9);\r\n xztoxy.multiplyToRef(pathTransformToZInv, pathTransformToZInv);\r\n\r\n extruded.bakeTransformIntoVertices(pathTransformToZInv);\r\n extrudedMeshes.push(extruded);\r\n }\r\n\r\n const extrudedAll = Mesh.MergeMeshes(extrudedMeshes, true);\r\n if (extrudedAll) {\r\n applyExtrusion(newVertexData, extrudedAll, false);\r\n extrudedAll.dispose();\r\n }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n protected getSketchShape(positions: FloatArray) {\r\n const shape: Vector3[] = [];\r\n for (let i = 0; i < positions.length; i += 3) {\r\n const newPoint = new Vector3(positions[i], positions[i + 1], positions[i + 2]);\r\n if (shape.length === 0 || !shape[shape.length - 1].equals(newPoint)) {\r\n shape.push(newPoint);\r\n }\r\n }\r\n\r\n return shape;\r\n }\r\n\r\n update3dInternal() {}\r\n}\r\n\r\nexport function applyExtrusion(newVertexData: Partial, extruded: Mesh, reverse = false) {\r\n if (extruded.geometry) {\r\n // Store the indices used for the extrude so that they can be merged into the new geometry\r\n const newIndices = extruded.geometry.getIndices(false, true);\r\n const newNormals = extruded.geometry.getVerticesData(VertexBuffer.NormalKind, false, true);\r\n const newUvs = extruded.geometry.getVerticesData(VertexBuffer.UVKind, false, true);\r\n const newPositions = extruded.geometry.getVerticesData(VertexBuffer.PositionKind, false, true);\r\n if (newPositions && reverse) {\r\n for (let i = 2; i < newPositions.length; i += 3) {\r\n newPositions[i] = -newPositions[i];\r\n }\r\n }\r\n\r\n normalizeGeometry(newVertexData);\r\n\r\n if (!newVertexData.indices) {\r\n newVertexData.indices = newIndices;\r\n } else if (newIndices) {\r\n const concatArr = new Int32Array(newVertexData.indices.length + newIndices.length);\r\n concatArr.set(newVertexData.indices);\r\n if (newVertexData.positions) {\r\n const pushAmount = newVertexData.positions.length / 3;\r\n for (let i = 0; i < newIndices.length; i++) {\r\n newIndices[i] += pushAmount;\r\n }\r\n }\r\n concatArr.set(newIndices, newVertexData.indices.length);\r\n newVertexData.indices = concatArr;\r\n }\r\n\r\n if (!newVertexData.positions) {\r\n newVertexData.positions = newPositions;\r\n } else if (newPositions) {\r\n const concatArr = new Float32Array(newVertexData.positions.length + newPositions.length);\r\n concatArr.set(newVertexData.positions);\r\n concatArr.set(newPositions, newVertexData.positions.length);\r\n newVertexData.positions = concatArr;\r\n }\r\n\r\n if (!newVertexData.normals) {\r\n newVertexData.normals = newNormals;\r\n } else if (newNormals) {\r\n const concatArr = new Float32Array(newVertexData.normals.length + newNormals.length);\r\n concatArr.set(newVertexData.normals);\r\n concatArr.set(newNormals, newVertexData.normals.length);\r\n newVertexData.normals = concatArr;\r\n }\r\n\r\n if (!newVertexData.uvs) {\r\n newVertexData.uvs = newUvs;\r\n } else if (newUvs) {\r\n const concatArr = new Float32Array(newVertexData.uvs.length + newUvs.length);\r\n concatArr.set(newVertexData.uvs);\r\n concatArr.set(newUvs, newVertexData.uvs.length);\r\n newVertexData.uvs = concatArr;\r\n }\r\n\r\n const baseMaterialIndex = newVertexData.submeshData ? newVertexData.submeshData[0].materialIndex : 0;\r\n const totalIndicesResultCount = newVertexData.indices!.length;\r\n const totalVerticesResultCount = newVertexData.positions!.length / 3;\r\n\r\n newVertexData.submeshData = [];\r\n newVertexData.submeshData.push({\r\n materialIndex: baseMaterialIndex,\r\n verticesStart: 0,\r\n verticesCount: totalVerticesResultCount,\r\n indexStart: 0,\r\n indexCount: totalIndicesResultCount,\r\n });\r\n }\r\n}\r\n\r\nexport function normalizeGeometry(newVertexData: Partial) {\r\n if (!newVertexData.indices) {\r\n // If there are no indices, throw away existing vertices because they won't be used\r\n newVertexData.positions = null;\r\n newVertexData.normals = null;\r\n newVertexData.uvs = null;\r\n } else {\r\n const indices = newVertexData.indices;\r\n let maxIdx = 0;\r\n for (let i = 0; i < indices.length; i++) {\r\n if (maxIdx < indices[i]) {\r\n maxIdx = indices[i];\r\n }\r\n }\r\n const usedVertexLength = maxIdx + 1;\r\n\r\n const positions = new Float32Array(usedVertexLength * 3);\r\n const normals = new Float32Array(usedVertexLength * 3);\r\n const uvs = new Float32Array(usedVertexLength * 2);\r\n\r\n if (newVertexData.positions) {\r\n if (Array.isArray(newVertexData.positions)) {\r\n positions.set(newVertexData.positions.slice(0, positions.length));\r\n } else {\r\n positions.set(newVertexData.positions.subarray(0, positions.length));\r\n }\r\n }\r\n if (newVertexData.normals) {\r\n if (Array.isArray(newVertexData.normals)) {\r\n normals.set(newVertexData.normals.slice(0, normals.length));\r\n } else {\r\n normals.set(newVertexData.normals.subarray(0, normals.length));\r\n }\r\n }\r\n if (newVertexData.uvs) {\r\n if (Array.isArray(newVertexData.uvs)) {\r\n uvs.set(newVertexData.uvs.slice(0, uvs.length));\r\n } else {\r\n uvs.set(newVertexData.uvs.subarray(0, uvs.length));\r\n }\r\n }\r\n newVertexData.positions = positions;\r\n newVertexData.normals = normals;\r\n newVertexData.uvs = uvs;\r\n }\r\n}\r\n","import type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Quaternion, Matrix, Vector3, Vector2 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { SubMesh } from \"../Meshes/subMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Constants } from \"../Engines/constants\";\r\n/**\r\n * Unique ID when we import meshes from Babylon to CSG\r\n */\r\nlet currentCSGMeshId = 0;\r\n\r\n/**\r\n * Represents a vertex of a polygon. Use your own vertex class instead of this\r\n * one to provide additional features like texture coordinates and vertex\r\n * colors. Custom vertex classes need to provide a `pos` property and `clone()`,\r\n * `flip()`, and `interpolate()` methods that behave analogous to the ones\r\n * defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience\r\n * functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`\r\n * is not used anywhere else.\r\n * Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes\r\n */\r\nclass Vertex {\r\n /**\r\n * Initializes the vertex\r\n * @param pos The position of the vertex\r\n * @param normal The normal of the vertex\r\n * @param uv The texture coordinate of the vertex\r\n * @param vertColor The RGBA color of the vertex\r\n */\r\n constructor(\r\n /**\r\n * The position of the vertex\r\n */\r\n public pos: Vector3,\r\n /**\r\n * The normal of the vertex\r\n */\r\n public normal: Vector3,\r\n /**\r\n * The texture coordinate of the vertex\r\n */\r\n public uv?: Vector2,\r\n /**\r\n * The texture coordinate of the vertex\r\n */\r\n public vertColor?: Color4\r\n ) {}\r\n\r\n /**\r\n * Make a clone, or deep copy, of the vertex\r\n * @returns A new Vertex\r\n */\r\n public clone(): Vertex {\r\n return new Vertex(this.pos.clone(), this.normal.clone(), this.uv?.clone(), this.vertColor?.clone());\r\n }\r\n\r\n /**\r\n * Invert all orientation-specific data (e.g. vertex normal). Called when the\r\n * orientation of a polygon is flipped.\r\n */\r\n public flip(): void {\r\n this.normal = this.normal.scale(-1);\r\n }\r\n\r\n /**\r\n * Create a new vertex between this vertex and `other` by linearly\r\n * interpolating all properties using a parameter of `t`. Subclasses should\r\n * override this to interpolate additional properties.\r\n * @param other the vertex to interpolate against\r\n * @param t The factor used to linearly interpolate between the vertices\r\n */\r\n public interpolate(other: Vertex, t: number): Vertex {\r\n return new Vertex(\r\n Vector3.Lerp(this.pos, other.pos, t),\r\n Vector3.Lerp(this.normal, other.normal, t),\r\n this.uv && other.uv ? Vector2.Lerp(this.uv, other.uv, t) : undefined,\r\n this.vertColor && other.vertColor ? Color4.Lerp(this.vertColor, other.vertColor, t) : undefined\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Represents a plane in 3D space.\r\n */\r\nclass Plane {\r\n /**\r\n * Initializes the plane\r\n * @param normal The normal for the plane\r\n * @param w\r\n */\r\n constructor(public normal: Vector3, public w: number) {}\r\n\r\n /**\r\n * `CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a\r\n * point is on the plane\r\n */\r\n static EPSILON = 1e-5;\r\n\r\n /**\r\n * Construct a plane from three points\r\n * @param a Point a\r\n * @param b Point b\r\n * @param c Point c\r\n */\r\n public static FromPoints(a: Vector3, b: Vector3, c: Vector3): Nullable {\r\n const v0 = c.subtract(a);\r\n const v1 = b.subtract(a);\r\n\r\n if (v0.lengthSquared() === 0 || v1.lengthSquared() === 0) {\r\n return null;\r\n }\r\n\r\n const n = Vector3.Normalize(Vector3.Cross(v0, v1));\r\n return new Plane(n, Vector3.Dot(n, a));\r\n }\r\n\r\n /**\r\n * Clone, or make a deep copy of the plane\r\n * @returns a new Plane\r\n */\r\n public clone(): Plane {\r\n return new Plane(this.normal.clone(), this.w);\r\n }\r\n\r\n /**\r\n * Flip the face of the plane\r\n */\r\n public flip() {\r\n this.normal.scaleInPlace(-1);\r\n this.w = -this.w;\r\n }\r\n\r\n /**\r\n * Split `polygon` by this plane if needed, then put the polygon or polygon\r\n * fragments in the appropriate lists. Coplanar polygons go into either\r\n `* coplanarFront` or `coplanarBack` depending on their orientation with\r\n * respect to this plane. Polygons in front or in back of this plane go into\r\n * either `front` or `back`\r\n * @param polygon The polygon to be split\r\n * @param coplanarFront Will contain polygons coplanar with the plane that are oriented to the front of the plane\r\n * @param coplanarBack Will contain polygons coplanar with the plane that are oriented to the back of the plane\r\n * @param front Will contain the polygons in front of the plane\r\n * @param back Will contain the polygons begind the plane\r\n */\r\n public splitPolygon(polygon: Polygon, coplanarFront: Polygon[], coplanarBack: Polygon[], front: Polygon[], back: Polygon[]): void {\r\n const COPLANAR = 0;\r\n const FRONT = 1;\r\n const BACK = 2;\r\n const SPANNING = 3;\r\n\r\n // Classify each point as well as the entire polygon into one of the above\r\n // four classes.\r\n let polygonType = 0;\r\n const types = [];\r\n let i: number;\r\n let t: number;\r\n for (i = 0; i < polygon.vertices.length; i++) {\r\n t = Vector3.Dot(this.normal, polygon.vertices[i].pos) - this.w;\r\n const type = t < -Plane.EPSILON ? BACK : t > Plane.EPSILON ? FRONT : COPLANAR;\r\n polygonType |= type;\r\n types.push(type);\r\n }\r\n\r\n // Put the polygon in the correct list, splitting it when necessary\r\n switch (polygonType) {\r\n case COPLANAR:\r\n (Vector3.Dot(this.normal, polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);\r\n break;\r\n case FRONT:\r\n front.push(polygon);\r\n break;\r\n case BACK:\r\n back.push(polygon);\r\n break;\r\n case SPANNING: {\r\n const f = [],\r\n b = [];\r\n for (i = 0; i < polygon.vertices.length; i++) {\r\n const j = (i + 1) % polygon.vertices.length;\r\n const ti = types[i],\r\n tj = types[j];\r\n const vi = polygon.vertices[i],\r\n vj = polygon.vertices[j];\r\n if (ti !== BACK) {\r\n f.push(vi);\r\n }\r\n if (ti !== FRONT) {\r\n b.push(ti !== BACK ? vi.clone() : vi);\r\n }\r\n if ((ti | tj) === SPANNING) {\r\n t = (this.w - Vector3.Dot(this.normal, vi.pos)) / Vector3.Dot(this.normal, vj.pos.subtract(vi.pos));\r\n const v = vi.interpolate(vj, t);\r\n f.push(v);\r\n b.push(v.clone());\r\n }\r\n }\r\n let poly: Polygon;\r\n if (f.length >= 3) {\r\n poly = new Polygon(f, polygon.shared);\r\n if (poly.plane) {\r\n front.push(poly);\r\n }\r\n }\r\n\r\n if (b.length >= 3) {\r\n poly = new Polygon(b, polygon.shared);\r\n\r\n if (poly.plane) {\r\n back.push(poly);\r\n }\r\n }\r\n\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents a convex polygon. The vertices used to initialize a polygon must\r\n * be coplanar and form a convex loop.\r\n *\r\n * Each convex polygon has a `shared` property, which is shared between all\r\n * polygons that are clones of each other or were split from the same polygon.\r\n * This can be used to define per-polygon properties (such as surface color)\r\n */\r\nclass Polygon {\r\n /**\r\n * Vertices of the polygon\r\n */\r\n public vertices: Vertex[];\r\n /**\r\n * Properties that are shared across all polygons\r\n */\r\n public shared: any;\r\n /**\r\n * A plane formed from the vertices of the polygon\r\n */\r\n public plane: Plane;\r\n\r\n /**\r\n * Initializes the polygon\r\n * @param vertices The vertices of the polygon\r\n * @param shared The properties shared across all polygons\r\n */\r\n constructor(vertices: Vertex[], shared: any) {\r\n this.vertices = vertices;\r\n this.shared = shared;\r\n this.plane = Plane.FromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, or the polygon\r\n */\r\n public clone(): Polygon {\r\n const vertices = this.vertices.map((v) => v.clone());\r\n return new Polygon(vertices, this.shared);\r\n }\r\n\r\n /**\r\n * Flips the faces of the polygon\r\n */\r\n public flip() {\r\n this.vertices.reverse().map((v) => {\r\n v.flip();\r\n });\r\n this.plane.flip();\r\n }\r\n}\r\n\r\n/**\r\n * Holds a node in a BSP tree. A BSP tree is built from a collection of polygons\r\n * by picking a polygon to split along. That polygon (and all other coplanar\r\n * polygons) are added directly to that node and the other polygons are added to\r\n * the front and/or back subtrees. This is not a leafy BSP tree since there is\r\n * no distinction between internal and leaf nodes\r\n */\r\nclass Node {\r\n private _plane: Nullable = null;\r\n private _front: Nullable = null;\r\n private _back: Nullable = null;\r\n private _polygons = new Array();\r\n\r\n /**\r\n * Initializes the node\r\n * @param polygons A collection of polygons held in the node\r\n */\r\n constructor(polygons?: Array) {\r\n if (polygons) {\r\n this.build(polygons);\r\n }\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, of the node\r\n * @returns The cloned node\r\n */\r\n public clone(): Node {\r\n const node = new Node();\r\n node._plane = this._plane && this._plane.clone();\r\n node._front = this._front && this._front.clone();\r\n node._back = this._back && this._back.clone();\r\n node._polygons = this._polygons.map((p) => p.clone());\r\n return node;\r\n }\r\n\r\n /**\r\n * Convert solid space to empty space and empty space to solid space\r\n */\r\n public invert(): void {\r\n for (let i = 0; i < this._polygons.length; i++) {\r\n this._polygons[i].flip();\r\n }\r\n if (this._plane) {\r\n this._plane.flip();\r\n }\r\n if (this._front) {\r\n this._front.invert();\r\n }\r\n if (this._back) {\r\n this._back.invert();\r\n }\r\n const temp = this._front;\r\n this._front = this._back;\r\n this._back = temp;\r\n }\r\n\r\n /**\r\n * Recursively remove all polygons in `polygons` that are inside this BSP\r\n * tree.\r\n * @param polygons Polygons to remove from the BSP\r\n * @returns Polygons clipped from the BSP\r\n */\r\n clipPolygons(polygons: Polygon[]): Polygon[] {\r\n if (!this._plane) {\r\n return polygons.slice();\r\n }\r\n let front = new Array(),\r\n back = new Array();\r\n for (let i = 0; i < polygons.length; i++) {\r\n this._plane.splitPolygon(polygons[i], front, back, front, back);\r\n }\r\n if (this._front) {\r\n front = this._front.clipPolygons(front);\r\n }\r\n if (this._back) {\r\n back = this._back.clipPolygons(back);\r\n } else {\r\n back = [];\r\n }\r\n return front.concat(back);\r\n }\r\n\r\n /**\r\n * Remove all polygons in this BSP tree that are inside the other BSP tree\r\n * `bsp`.\r\n * @param bsp BSP containing polygons to remove from this BSP\r\n */\r\n clipTo(bsp: Node): void {\r\n this._polygons = bsp.clipPolygons(this._polygons);\r\n if (this._front) {\r\n this._front.clipTo(bsp);\r\n }\r\n if (this._back) {\r\n this._back.clipTo(bsp);\r\n }\r\n }\r\n\r\n /**\r\n * Return a list of all polygons in this BSP tree\r\n * @returns List of all polygons in this BSP tree\r\n */\r\n allPolygons(): Polygon[] {\r\n let polygons = this._polygons.slice();\r\n if (this._front) {\r\n polygons = polygons.concat(this._front.allPolygons());\r\n }\r\n if (this._back) {\r\n polygons = polygons.concat(this._back.allPolygons());\r\n }\r\n return polygons;\r\n }\r\n\r\n /**\r\n * Build a BSP tree out of `polygons`. When called on an existing tree, the\r\n * new polygons are filtered down to the bottom of the tree and become new\r\n * nodes there. Each set of polygons is partitioned using the first polygon\r\n * (no heuristic is used to pick a good split)\r\n * @param polygons Polygons used to construct the BSP tree\r\n */\r\n build(polygons: Polygon[]): void {\r\n if (!polygons.length) {\r\n return;\r\n }\r\n if (!this._plane) {\r\n this._plane = polygons[0].plane.clone();\r\n }\r\n const front = new Array(),\r\n back = new Array();\r\n for (let i = 0; i < polygons.length; i++) {\r\n this._plane.splitPolygon(polygons[i], this._polygons, this._polygons, front, back);\r\n }\r\n if (front.length) {\r\n if (!this._front) {\r\n this._front = new Node();\r\n }\r\n this._front.build(front);\r\n }\r\n if (back.length) {\r\n if (!this._back) {\r\n this._back = new Node();\r\n }\r\n this._back.build(back);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Class for building Constructive Solid Geometry\r\n */\r\nexport class CSG {\r\n private _polygons = new Array();\r\n /**\r\n * The world matrix\r\n */\r\n public matrix: Matrix;\r\n /**\r\n * Stores the position\r\n */\r\n public position: Vector3;\r\n /**\r\n * Stores the rotation\r\n */\r\n public rotation: Vector3;\r\n /**\r\n * Stores the rotation quaternion\r\n */\r\n public rotationQuaternion: Nullable;\r\n /**\r\n * Stores the scaling vector\r\n */\r\n public scaling: Vector3;\r\n\r\n /**\r\n * Convert the Mesh to CSG\r\n * @param mesh The Mesh to convert to CSG\r\n * @param absolute If true, the final (local) matrix transformation is set to the identity and not to that of `mesh`. It can help when dealing with right-handed meshes (default: false)\r\n * @returns A new CSG from the Mesh\r\n */\r\n public static FromMesh(mesh: Mesh, absolute = false): CSG {\r\n let vertex: Vertex,\r\n normal: Vector3,\r\n uv: Vector2 | undefined = undefined,\r\n position: Vector3,\r\n vertColor: Color4 | undefined = undefined,\r\n polygon: Polygon,\r\n vertices;\r\n const polygons = new Array();\r\n let matrix: Matrix,\r\n meshPosition: Vector3,\r\n meshRotation: Vector3,\r\n meshRotationQuaternion: Nullable = null,\r\n meshScaling: Vector3;\r\n\r\n let invertWinding = false;\r\n if (mesh instanceof Mesh) {\r\n mesh.computeWorldMatrix(true);\r\n matrix = mesh.getWorldMatrix();\r\n meshPosition = mesh.position.clone();\r\n meshRotation = mesh.rotation.clone();\r\n if (mesh.rotationQuaternion) {\r\n meshRotationQuaternion = mesh.rotationQuaternion.clone();\r\n }\r\n meshScaling = mesh.scaling.clone();\r\n if (mesh.material && absolute) {\r\n invertWinding = mesh.material.sideOrientation === Constants.MATERIAL_ClockWiseSideOrientation;\r\n }\r\n } else {\r\n throw \"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh\";\r\n }\r\n\r\n const indices = mesh.getIndices(),\r\n positions = mesh.getVerticesData(VertexBuffer.PositionKind),\r\n normals = mesh.getVerticesData(VertexBuffer.NormalKind),\r\n uvs = mesh.getVerticesData(VertexBuffer.UVKind),\r\n vertColors = mesh.getVerticesData(VertexBuffer.ColorKind);\r\n\r\n const subMeshes = mesh.subMeshes;\r\n\r\n for (let sm = 0, sml = subMeshes.length; sm < sml; sm++) {\r\n for (let i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {\r\n vertices = [];\r\n for (let j = 0; j < 3; j++) {\r\n const indexIndices = j === 0 ? i + j : invertWinding ? i + 3 - j : i + j;\r\n const sourceNormal = new Vector3(normals[indices[indexIndices] * 3], normals[indices[indexIndices] * 3 + 1], normals[indices[indexIndices] * 3 + 2]);\r\n if (uvs) {\r\n uv = new Vector2(uvs[indices[indexIndices] * 2], uvs[indices[indexIndices] * 2 + 1]);\r\n }\r\n if (vertColors) {\r\n vertColor = new Color4(\r\n vertColors[indices[indexIndices] * 4],\r\n vertColors[indices[indexIndices] * 4 + 1],\r\n vertColors[indices[indexIndices] * 4 + 2],\r\n vertColors[indices[indexIndices] * 4 + 3]\r\n );\r\n }\r\n const sourcePosition = new Vector3(positions[indices[indexIndices] * 3], positions[indices[indexIndices] * 3 + 1], positions[indices[indexIndices] * 3 + 2]);\r\n position = Vector3.TransformCoordinates(sourcePosition, matrix);\r\n normal = Vector3.TransformNormal(sourceNormal, matrix);\r\n\r\n vertex = new Vertex(position, normal, uv, vertColor);\r\n vertices.push(vertex);\r\n }\r\n\r\n polygon = new Polygon(vertices, { subMeshId: sm, meshId: currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });\r\n\r\n // To handle the case of degenerated triangle\r\n // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated\r\n if (polygon.plane) {\r\n polygons.push(polygon);\r\n }\r\n }\r\n }\r\n\r\n const csg = CSG._FromPolygons(polygons);\r\n csg.matrix = absolute ? Matrix.Identity() : matrix;\r\n csg.position = absolute ? Vector3.Zero() : meshPosition;\r\n csg.rotation = absolute ? Vector3.Zero() : meshRotation;\r\n csg.scaling = absolute ? Vector3.One() : meshScaling;\r\n csg.rotationQuaternion = absolute && meshRotationQuaternion ? Quaternion.Identity() : meshRotationQuaternion;\r\n currentCSGMeshId++;\r\n\r\n return csg;\r\n }\r\n\r\n /**\r\n * Construct a CSG solid from a list of `CSG.Polygon` instances.\r\n * @param polygons Polygons used to construct a CSG solid\r\n */\r\n private static _FromPolygons(polygons: Polygon[]): CSG {\r\n const csg = new CSG();\r\n csg._polygons = polygons;\r\n return csg;\r\n }\r\n\r\n /**\r\n * Clones, or makes a deep copy, of the CSG\r\n * @returns A new CSG\r\n */\r\n public clone(): CSG {\r\n const csg = new CSG();\r\n csg._polygons = this._polygons.map((p) => p.clone());\r\n csg.copyTransformAttributes(this);\r\n return csg;\r\n }\r\n\r\n /**\r\n * Unions this CSG with another CSG\r\n * @param csg The CSG to union against this CSG\r\n * @returns The unioned CSG\r\n */\r\n public union(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Unions this CSG with another CSG in place\r\n * @param csg The CSG to union against this CSG\r\n */\r\n public unionInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Subtracts this CSG with another CSG\r\n * @param csg The CSG to subtract against this CSG\r\n * @returns A new CSG\r\n */\r\n public subtract(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n a.invert();\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Subtracts this CSG with another CSG in place\r\n * @param csg The CSG to subtract against this CSG\r\n */\r\n public subtractInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n b.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.build(b.allPolygons());\r\n a.invert();\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Intersect this CSG with another CSG\r\n * @param csg The CSG to intersect against this CSG\r\n * @returns A new CSG\r\n */\r\n public intersect(csg: CSG): CSG {\r\n const a = new Node(this.clone()._polygons);\r\n const b = new Node(csg.clone()._polygons);\r\n a.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n a.build(b.allPolygons());\r\n a.invert();\r\n return CSG._FromPolygons(a.allPolygons()).copyTransformAttributes(this);\r\n }\r\n\r\n /**\r\n * Intersects this CSG with another CSG in place\r\n * @param csg The CSG to intersect against this CSG\r\n */\r\n public intersectInPlace(csg: CSG): void {\r\n const a = new Node(this._polygons);\r\n const b = new Node(csg._polygons);\r\n\r\n a.invert();\r\n b.clipTo(a);\r\n b.invert();\r\n a.clipTo(b);\r\n b.clipTo(a);\r\n a.build(b.allPolygons());\r\n a.invert();\r\n\r\n this._polygons = a.allPolygons();\r\n }\r\n\r\n /**\r\n * Return a new CSG solid with solid and empty space switched. This solid is\r\n * not modified.\r\n * @returns A new CSG solid with solid and empty space switched\r\n */\r\n public inverse(): CSG {\r\n const csg = this.clone();\r\n csg.inverseInPlace();\r\n return csg;\r\n }\r\n\r\n /**\r\n * Inverses the CSG in place\r\n */\r\n public inverseInPlace(): void {\r\n this._polygons.map((p) => {\r\n p.flip();\r\n });\r\n }\r\n\r\n /**\r\n * This is used to keep meshes transformations so they can be restored\r\n * when we build back a Babylon Mesh\r\n * NB : All CSG operations are performed in world coordinates\r\n * @param csg The CSG to copy the transform attributes from\r\n * @returns This CSG\r\n */\r\n public copyTransformAttributes(csg: CSG): CSG {\r\n this.matrix = csg.matrix;\r\n this.position = csg.position;\r\n this.rotation = csg.rotation;\r\n this.scaling = csg.scaling;\r\n this.rotationQuaternion = csg.rotationQuaternion;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Build Raw mesh from CSG\r\n * Coordinates here are in world space\r\n * @param name The name of the mesh geometry\r\n * @param scene The Scene\r\n * @param keepSubMeshes Specifies if the submeshes should be kept\r\n * @returns A new Mesh\r\n */\r\n public buildMeshGeometry(name: string, scene?: Scene, keepSubMeshes?: boolean): Mesh {\r\n const matrix = this.matrix.clone();\r\n matrix.invert();\r\n\r\n const mesh = new Mesh(name, scene);\r\n const vertices = [];\r\n const indices = [];\r\n const normals = [];\r\n let uvs: Nullable = null;\r\n let vertColors: Nullable = null;\r\n const vertex = Vector3.Zero();\r\n const normal = Vector3.Zero();\r\n const uv = Vector2.Zero();\r\n const vertColor = new Color4(0, 0, 0, 0);\r\n const polygons = this._polygons;\r\n const polygonIndices = [0, 0, 0];\r\n let polygon;\r\n const vertice_dict = {};\r\n let vertex_idx;\r\n let currentIndex = 0;\r\n const subMeshDict = {};\r\n let subMeshObj;\r\n\r\n if (keepSubMeshes) {\r\n // Sort Polygons, since subMeshes are indices range\r\n polygons.sort((a, b) => {\r\n if (a.shared.meshId === b.shared.meshId) {\r\n return a.shared.subMeshId - b.shared.subMeshId;\r\n } else {\r\n return a.shared.meshId - b.shared.meshId;\r\n }\r\n });\r\n }\r\n\r\n for (let i = 0, il = polygons.length; i < il; i++) {\r\n polygon = polygons[i];\r\n\r\n // Building SubMeshes\r\n if (!(subMeshDict)[polygon.shared.meshId]) {\r\n (subMeshDict)[polygon.shared.meshId] = {};\r\n }\r\n if (!(subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId]) {\r\n (subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId] = {\r\n indexStart: +Infinity,\r\n indexEnd: -Infinity,\r\n materialIndex: polygon.shared.materialIndex,\r\n };\r\n }\r\n subMeshObj = (subMeshDict)[polygon.shared.meshId][polygon.shared.subMeshId];\r\n\r\n for (let j = 2, jl = polygon.vertices.length; j < jl; j++) {\r\n polygonIndices[0] = 0;\r\n polygonIndices[1] = j - 1;\r\n polygonIndices[2] = j;\r\n\r\n for (let k = 0; k < 3; k++) {\r\n vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);\r\n normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);\r\n if (polygon.vertices[polygonIndices[k]].uv) {\r\n if (!uvs) {\r\n uvs = [];\r\n }\r\n uv.copyFrom(polygon.vertices[polygonIndices[k]].uv!);\r\n }\r\n\r\n if (polygon.vertices[polygonIndices[k]].vertColor) {\r\n if (!vertColors) {\r\n vertColors = [];\r\n }\r\n vertColor.copyFrom(polygon.vertices[polygonIndices[k]].vertColor!);\r\n }\r\n const localVertex = Vector3.TransformCoordinates(vertex, matrix);\r\n const localNormal = Vector3.TransformNormal(normal, matrix);\r\n\r\n vertex_idx = (vertice_dict)[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z];\r\n\r\n let areUvsDifferent = false;\r\n\r\n if (uvs && !(uvs[vertex_idx * 2] === uv.x || uvs[vertex_idx * 2 + 1] === uv.y)) {\r\n areUvsDifferent = true;\r\n }\r\n\r\n let areColorsDifferent = false;\r\n\r\n if (\r\n vertColors &&\r\n !(\r\n vertColors[vertex_idx * 4] === vertColor.r ||\r\n vertColors[vertex_idx * 4 + 1] === vertColor.g ||\r\n vertColors[vertex_idx * 4 + 2] === vertColor.b ||\r\n vertColors[vertex_idx * 4 + 3] === vertColor.a\r\n )\r\n ) {\r\n areColorsDifferent = true;\r\n }\r\n\r\n // Check if 2 points can be merged\r\n if (\r\n !(\r\n typeof vertex_idx !== \"undefined\" &&\r\n normals[vertex_idx * 3] === localNormal.x &&\r\n normals[vertex_idx * 3 + 1] === localNormal.y &&\r\n normals[vertex_idx * 3 + 2] === localNormal.z\r\n ) ||\r\n areUvsDifferent ||\r\n areColorsDifferent\r\n ) {\r\n vertices.push(localVertex.x, localVertex.y, localVertex.z);\r\n if (uvs) {\r\n uvs.push(uv.x, uv.y);\r\n }\r\n normals.push(normal.x, normal.y, normal.z);\r\n if (vertColors) {\r\n vertColors.push(vertColor.r, vertColor.g, vertColor.b, vertColor.a);\r\n }\r\n vertex_idx = (vertice_dict)[localVertex.x + \",\" + localVertex.y + \",\" + localVertex.z] = vertices.length / 3 - 1;\r\n }\r\n\r\n indices.push(vertex_idx);\r\n\r\n subMeshObj.indexStart = Math.min(currentIndex, subMeshObj.indexStart);\r\n subMeshObj.indexEnd = Math.max(currentIndex, subMeshObj.indexEnd);\r\n currentIndex++;\r\n }\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, vertices);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n if (uvs) {\r\n mesh.setVerticesData(VertexBuffer.UVKind, uvs);\r\n }\r\n if (vertColors) {\r\n mesh.setVerticesData(VertexBuffer.ColorKind, vertColors);\r\n }\r\n mesh.setIndices(indices, null);\r\n\r\n if (keepSubMeshes) {\r\n // We offset the materialIndex by the previous number of materials in the CSG mixed meshes\r\n let materialIndexOffset = 0,\r\n materialMaxIndex;\r\n\r\n mesh.subMeshes = new Array();\r\n\r\n for (const m in subMeshDict) {\r\n materialMaxIndex = -1;\r\n for (const sm in (subMeshDict)[m]) {\r\n subMeshObj = (subMeshDict)[m][sm];\r\n SubMesh.CreateFromIndices(\r\n subMeshObj.materialIndex + materialIndexOffset,\r\n subMeshObj.indexStart,\r\n subMeshObj.indexEnd - subMeshObj.indexStart + 1,\r\n mesh\r\n );\r\n materialMaxIndex = Math.max(subMeshObj.materialIndex, materialMaxIndex);\r\n }\r\n materialIndexOffset += ++materialMaxIndex;\r\n }\r\n }\r\n\r\n return mesh;\r\n }\r\n\r\n /**\r\n * Build Mesh from CSG taking material and transforms into account\r\n * @param name The name of the Mesh\r\n * @param material The material of the Mesh\r\n * @param scene The Scene\r\n * @param keepSubMeshes Specifies if submeshes should be kept\r\n * @returns The new Mesh\r\n */\r\n public toMesh(name: string, material: Nullable = null, scene?: Scene, keepSubMeshes?: boolean): Mesh {\r\n const mesh = this.buildMeshGeometry(name, scene, keepSubMeshes);\r\n\r\n mesh.material = material;\r\n\r\n mesh.position.copyFrom(this.position);\r\n mesh.rotation.copyFrom(this.rotation);\r\n if (this.rotationQuaternion) {\r\n mesh.rotationQuaternion = this.rotationQuaternion.clone();\r\n }\r\n mesh.scaling.copyFrom(this.scaling);\r\n mesh.computeWorldMatrix(true);\r\n\r\n return mesh;\r\n }\r\n}\r\n","import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3 } from '@babylonjs/core/Maths/math';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\n\r\nexport function createJoinGeometryVisualization(targetMesh: Mesh, scene: Scene, color?: Color3) {\r\n const visualization = targetMesh;\r\n\r\n if (!color) {\r\n color = Color3.Yellow();\r\n }\r\n\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n //coloredMaterial.alpha = 0.5;\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n visualization.material = coloredMaterial;\r\n return visualization;\r\n}\r\n","import { Color3 } from '@babylonjs/core/Maths/math';\r\nimport { Quaternion } from '@babylonjs/core/Maths/math.vector';\r\nimport { CSG } from '@babylonjs/core/Meshes/csg';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { eJoinType } from '@models/classes/enums';\r\nimport { JoinGeometryFeature } from '@models/classes/features/join-geometry-feature';\r\nimport { CustomMeshNode } from '@models/classes/meshes/custom-mesh-node';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { createJoinGeometryVisualization } from '@view/helpers/join-geometry-helper';\r\nimport { Subscription } from 'rxjs';\r\nimport { FeatureRenderer } from './feature';\r\nimport { ensureNormalsExist } from './utils';\r\n\r\nconst joinedMeshes = new Map();\r\n\r\nexport class JoinGeometryRenderer extends FeatureRenderer {\r\n modelToken = Token.JoinGeometryFeature;\r\n bbSubscriptions = new Map();\r\n targetMeshVisualizationMap = new Map();\r\n parentMeshVisualizationMap = new Map();\r\n previewLayer: UtilityLayerRenderer = this.viewer.utilityLayer;\r\n\r\n updateMeshGeometry(\r\n feature: JoinGeometryFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n\r\n const targetMesh = joinedMeshes.get(feature._dynamicId);\r\n const thisMesh = this.viewer.getRendererNode(feature._parent!);\r\n\r\n if (\r\n targetMesh instanceof Mesh &&\r\n thisMesh instanceof Mesh &&\r\n targetMesh.geometry &&\r\n targetMesh.geometry.getTotalIndices() > 0 &&\r\n targetMesh != thisMesh\r\n ) {\r\n const workingVertexData = vertexData.shallowClone();\r\n const tempMesh = new Mesh('csg-temp');\r\n tempMesh.doNotSerialize = true;\r\n SubmeshVertexData.CopyToRef(newVertexData, workingVertexData);\r\n if (!workingVertexData.positions || !workingVertexData.indices) {\r\n throw 'Invalid geometry';\r\n }\r\n const targetTransform = thisMesh.computeWorldMatrix(true);\r\n workingVertexData.applyToMesh(tempMesh);\r\n\r\n let previewMesh = this.parentMeshVisualizationMap.get(feature.id);\r\n\r\n if (!previewMesh) {\r\n const newMeshInstance = new Mesh('preview-mesh');\r\n newMeshInstance.doNotSerialize = true;\r\n workingVertexData.applyToMesh(newMeshInstance);\r\n this.parentMeshVisualizationMap.set(feature.id, newMeshInstance);\r\n if (newMeshInstance instanceof Mesh) {\r\n previewMesh = createJoinGeometryVisualization(\r\n newMeshInstance,\r\n this.previewLayer.utilityLayerScene,\r\n Color3.Yellow()\r\n );\r\n this.parentMeshVisualizationMap.set(feature.id, previewMesh);\r\n previewMesh.setEnabled(false);\r\n if (feature._parent) {\r\n const featureParentMesh = this.viewer.getRendererNode(feature._parent);\r\n newMeshInstance.position.addInPlace(featureParentMesh.absolutePosition);\r\n }\r\n }\r\n }\r\n\r\n ensureNormalsExist(tempMesh);\r\n\r\n const resultCsg = CSG.FromMesh(tempMesh);\r\n\r\n const targetMeshMatchTransform = targetMesh.clone();\r\n const targetMeshTransform = targetMeshMatchTransform.computeWorldMatrix(true);\r\n targetMeshMatchTransform.parent = null;\r\n targetTransform.invert();\r\n targetMeshTransform.multiplyToRef(targetTransform, targetMeshTransform);\r\n targetMeshMatchTransform.rotationQuaternion = new Quaternion();\r\n targetMeshTransform.decompose(\r\n targetMeshMatchTransform.scaling,\r\n targetMeshMatchTransform.rotationQuaternion,\r\n targetMeshMatchTransform.position\r\n );\r\n\r\n try {\r\n const opCsg = CSG.FromMesh(targetMeshMatchTransform);\r\n if (feature.joinType === eJoinType.cut) {\r\n resultCsg.subtractInPlace(opCsg);\r\n } else if (feature.joinType === eJoinType.intersect) {\r\n resultCsg.intersectInPlace(opCsg);\r\n } else if (feature.joinType === eJoinType.union) {\r\n resultCsg.unionInPlace(opCsg);\r\n }\r\n } catch (e) {\r\n console.warn('Could not merge geometry for join ' + feature.name, e);\r\n return newVertexData;\r\n }\r\n\r\n if (resultCsg) {\r\n const resultMeshCsg = resultCsg.toMesh('temp2', null, undefined, true);\r\n\r\n const resultVertexData = SubmeshVertexData.ExtractFromMesh(resultMeshCsg);\r\n newVertexData.positions = resultVertexData.positions;\r\n if (newVertexData.normals) {\r\n newVertexData.normals = resultVertexData.normals;\r\n }\r\n if (newVertexData.uvs) {\r\n newVertexData.uvs = resultVertexData.uvs;\r\n }\r\n newVertexData.indices = resultVertexData.indices;\r\n\r\n // Sometimes the CSG will add another material to the multiMaterial to represent the cut face. Change that material to be the base material, otherwise it will be black.\r\n const existingMaterials = new Set();\r\n // get a list of all the materials that are already in the multiMaterial\r\n if (newVertexData.submeshData) {\r\n newVertexData.submeshData.forEach(submeshData => {\r\n existingMaterials.add(submeshData.materialIndex);\r\n });\r\n }\r\n if (resultVertexData.submeshData) {\r\n resultVertexData.submeshData.forEach(submeshData => {\r\n if (!existingMaterials.has(submeshData.materialIndex)) {\r\n submeshData.materialIndex = 0;\r\n }\r\n });\r\n }\r\n\r\n newVertexData.submeshData = resultVertexData.submeshData;\r\n resultMeshCsg.dispose();\r\n }\r\n tempMesh.dispose();\r\n targetMeshMatchTransform.dispose();\r\n }\r\n return newVertexData;\r\n }\r\n\r\n updatePreviewMesh(node: JoinGeometryFeature) {\r\n let featureInstance = this.targetMeshVisualizationMap.get(node.id);\r\n const scene = this.previewLayer.utilityLayerScene;\r\n const targetMesh = joinedMeshes.get(node._dynamicId);\r\n if (targetMesh && !featureInstance) {\r\n featureInstance = createJoinGeometryVisualization(targetMesh.clone(), scene, Color3.Yellow());\r\n featureInstance.isPickable = false;\r\n featureInstance.setEnabled(false);\r\n this.targetMeshVisualizationMap.set(node.id, featureInstance);\r\n return featureInstance;\r\n } else if (targetMesh) {\r\n this.deleteTargetMeshVisualization(node as ITrackedClass);\r\n featureInstance = createJoinGeometryVisualization(targetMesh.clone(), scene, Color3.Yellow());\r\n featureInstance.isPickable = false;\r\n featureInstance.setEnabled(false);\r\n this.targetMeshVisualizationMap.set(node.id, featureInstance);\r\n return featureInstance;\r\n }\r\n }\r\n\r\n update3dInternal(feature: ITrackedClass) {\r\n if (feature.changes.hasAny('meshId', 'enabled')) {\r\n const existingSubscription = this.bbSubscriptions.get(feature._dynamicId);\r\n if (existingSubscription) {\r\n existingSubscription.unsubscribe();\r\n }\r\n\r\n if (feature.enabled) {\r\n const targetMeshNode = feature._manager?.getById(feature.meshId);\r\n if (targetMeshNode && targetMeshNode instanceof MeshNode) {\r\n // if this is a custom mesh node and the geometry isn't loaded, we have to load it\r\n if (\r\n targetMeshNode instanceof CustomMeshNode &&\r\n targetMeshNode.hasGeometry &&\r\n !targetMeshNode.geometryLoaded\r\n ) {\r\n this.viewer.rendererManager.mesh.loadNewGeometry(targetMeshNode);\r\n }\r\n const targetMesh = this.viewer.getRendererNode(targetMeshNode);\r\n\r\n if (targetMesh instanceof Mesh && feature._parent) {\r\n joinedMeshes.set(feature._dynamicId, targetMesh);\r\n\r\n this.bbSubscriptions.set(\r\n feature._dynamicId,\r\n // TODO This should also watch the parent group for positional changes, otherwise the join won't update when the feature's parent mesh moves.\r\n // But watch out for infinite loops\r\n this.viewer.bbCache.watchForChanges(targetMeshNode).subscribe(() => {\r\n feature.setPropertyIsModified('meshId', true);\r\n })\r\n );\r\n } else {\r\n console.warn('Could not create CSG for join geometry');\r\n }\r\n }\r\n }\r\n }\r\n\r\n let featureInstance = this.targetMeshVisualizationMap.get(feature.id);\r\n const originalMesh = this.parentMeshVisualizationMap.get(feature.id);\r\n\r\n if (feature._previewVisible) {\r\n featureInstance = this.updatePreviewMesh(feature);\r\n }\r\n\r\n if (feature._previewVisible && feature.enabled) {\r\n if (feature.joinType === eJoinType.cut) {\r\n originalMesh?.setEnabled(false);\r\n featureInstance?.setEnabled(true);\r\n } else if (feature.joinType === eJoinType.intersect) {\r\n originalMesh?.setEnabled(true);\r\n featureInstance?.setEnabled(true);\r\n } else {\r\n originalMesh?.setEnabled(false);\r\n featureInstance?.setEnabled(false);\r\n }\r\n } else {\r\n originalMesh?.setEnabled(false);\r\n featureInstance?.setEnabled(false);\r\n }\r\n }\r\n\r\n delete3d(feature: ITrackedClass, preserveCache: boolean) {\r\n if (!preserveCache) {\r\n joinedMeshes.delete(feature._dynamicId);\r\n }\r\n this.bbSubscriptions.get(feature._dynamicId)?.unsubscribe();\r\n this.bbSubscriptions.delete(feature._dynamicId);\r\n this.deleteTargetMeshVisualization(feature);\r\n\r\n const targetMeshCopy = this.parentMeshVisualizationMap.get(feature.id);\r\n targetMeshCopy?.dispose(false, true);\r\n this.parentMeshVisualizationMap.delete(feature.id);\r\n super.delete3d(feature);\r\n }\r\n\r\n deleteTargetMeshVisualization(feature: ITrackedClass) {\r\n const previewMesh = this.targetMeshVisualizationMap.get(feature.id);\r\n previewMesh?.dispose(false, true);\r\n this.targetMeshVisualizationMap.delete(feature.id);\r\n }\r\n\r\n dispose() {\r\n this.bbSubscriptions.forEach(s => {\r\n s.unsubscribe();\r\n });\r\n this.bbSubscriptions.clear();\r\n joinedMeshes.clear();\r\n super.dispose();\r\n }\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths';\r\nimport { SolidParticle } from '@babylonjs/core/Particles/solidParticle';\r\nimport { LinearPatternFeature } from '@models/classes/features/linear-pattern-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { PatternRenderer } from './pattern';\r\n\r\nexport class LinearPatternRenderer extends PatternRenderer {\r\n modelToken = Token.LinearPatternFeature;\r\n updateMeshGeometry(\r\n feature: LinearPatternFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const featureTranslation = feature.translation.toVec3();\r\n const workingVector = Vector3.Zero();\r\n\r\n return super.updateMeshGeometry(\r\n feature,\r\n vertexData,\r\n vertexDataChanges,\r\n (idx: number, particle: SolidParticle) => {\r\n if (!feature.meshId) {\r\n workingVector.copyFrom(featureTranslation).scaleInPlace(idx);\r\n }\r\n particle.position.addInPlace(workingVector);\r\n }\r\n );\r\n }\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { MirrorFeature } from '@models/classes/features/mirror-feature';\r\nimport { SliceFeature } from '@models/classes/features/slice-feature';\r\nimport { SubmeshData } from '@models/classes/features/submesh-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { rotationToVector } from '@view/helpers/math-helper';\r\nimport { createMirrorVisualization } from '@view/helpers/mirror-helper';\r\nimport { FeatureRenderer } from './feature';\r\nexport class SliceFeatureRenderer extends FeatureRenderer {\r\n modelToken = Token.SliceFeature;\r\n previewLayer: UtilityLayerRenderer = this.viewer.utilityLayer;\r\n babylonMirrorPreviewsMap = new Map();\r\n\r\n updateMeshGeometry(\r\n feature: SliceFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n\r\n if (\r\n newVertexData.positions &&\r\n newVertexData.positions.length > 0 &&\r\n newVertexData.indices &&\r\n newVertexData.indices.length > 0\r\n ) {\r\n const positions = newVertexData.positions;\r\n const normals = newVertexData.normals;\r\n const uvs = newVertexData.uvs;\r\n const indices = newVertexData.indices;\r\n\r\n const triCount = indices.length / 3;\r\n const positionsCount = positions.length / 3;\r\n const planeNormal = feature.normal.toVec3();\r\n const planePoint = feature.intersect.toVec3();\r\n\r\n const newPositions: number[] = [];\r\n const newNormals: number[] = [];\r\n const newUvs: number[] = [];\r\n const newIndices: number[] = [];\r\n const preSliceSubmeshes = newVertexData.submeshData!;\r\n const newSubmeshes: SubmeshData[] = preSliceSubmeshes.map(submesh => ({ ...submesh }));\r\n const edgeSplits: number[] = []; // which vertices are part of how many edges being split\r\n const edgeStart = Vector3.Zero();\r\n const edgeDir = Vector3.Zero();\r\n const workingVector = Vector3.Zero();\r\n\r\n let j: number;\r\n for (let i = 0; i < triCount; i++) {\r\n let hit = 0;\r\n let d = 0;\r\n let vertexIndex = -1;\r\n for (j = 0; j < 3; j++) {\r\n const iA = j,\r\n iB = (j + 1) % 3;\r\n const vA = indices[i * 3 + iA],\r\n vB = indices[i * 3 + iB];\r\n if (vertexIndex === -1) {\r\n vertexIndex = vA;\r\n }\r\n edgeStart.set(positions[vA * 3], positions[vA * 3 + 1], positions[vA * 3 + 2]);\r\n edgeStart.subtractFromFloatsToRef(\r\n positions[vB * 3],\r\n positions[vB * 3 + 1],\r\n positions[vB * 3 + 2],\r\n edgeDir\r\n );\r\n edgeDir.scaleInPlace(-1);\r\n\r\n const lnDot = Vector3.Dot(planeNormal, edgeDir);\r\n if (lnDot === 0) {\r\n continue;\r\n }\r\n\r\n planePoint.subtractToRef(edgeStart, workingVector);\r\n d = Vector3.Dot(workingVector, planeNormal) / lnDot;\r\n\r\n // Expect floating point errors. don't want unnecessary tiny triangles\r\n // If d is between 0 and 1, then the plane hit the edge\r\n if (d > 1e-12 && d < 1 - 1e-12) {\r\n hit++;\r\n edgeSplits[iA] = (edgeSplits[iA] || 0) + 1;\r\n edgeSplits[iB] = (edgeSplits[iB] || 0) + 1;\r\n edgeDir.scaleInPlace(d);\r\n edgeStart.addToRef(edgeDir, workingVector);\r\n\r\n newPositions.push(workingVector.x, workingVector.y, workingVector.z);\r\n\r\n if (normals) {\r\n workingVector.set(normals[vA * 3], normals[vA * 3 + 1], normals[vA * 3 + 2]);\r\n workingVector.scaleInPlace(1 - d);\r\n workingVector.addInPlaceFromFloats(\r\n normals[vB * 3] * d,\r\n normals[vB * 3 + 1] * d,\r\n normals[vB * 3 + 2] * d\r\n );\r\n newNormals.push(workingVector.x, workingVector.y, workingVector.z);\r\n }\r\n\r\n if (uvs) {\r\n workingVector.set(uvs[vA * 2], uvs[vA * 2 + 1], 0);\r\n workingVector.scaleInPlace(1 - d);\r\n workingVector.addInPlaceFromFloats(uvs[vB * 2] * d, uvs[vB * 2 + 1] * d, 0);\r\n newUvs.push(workingVector.x, workingVector.y);\r\n }\r\n }\r\n }\r\n\r\n if (hit) {\r\n // divide the triangle here\r\n if (hit === 1) {\r\n const split = positionsCount - 1 + newPositions.length / 3;\r\n\r\n if (!edgeSplits[0]) {\r\n newIndices.push(\r\n indices[i * 3],\r\n indices[i * 3 + 1],\r\n split,\r\n indices[i * 3],\r\n split,\r\n indices[i * 3 + 2]\r\n );\r\n } else if (!edgeSplits[1]) {\r\n newIndices.push(\r\n indices[i * 3],\r\n indices[i * 3 + 1],\r\n split,\r\n indices[i * 3 + 1],\r\n indices[i * 3 + 2],\r\n split\r\n );\r\n } else {\r\n newIndices.push(\r\n indices[i * 3],\r\n split,\r\n indices[i * 3 + 2],\r\n indices[i * 3 + 1],\r\n indices[i * 3 + 2],\r\n split\r\n );\r\n }\r\n newSubmeshes.forEach((submeshData, sI) => {\r\n const preSliceSubmesh = preSliceSubmeshes[sI];\r\n if (\r\n preSliceSubmesh.indexStart <= i * 3 &&\r\n preSliceSubmesh.indexStart + preSliceSubmesh.indexCount > i * 3\r\n ) {\r\n submeshData.indexCount += 3;\r\n } else if (preSliceSubmesh.indexStart > i * 3) {\r\n submeshData.indexStart += 3;\r\n }\r\n });\r\n }\r\n if (hit === 2) {\r\n const aSplit = positionsCount - 1 + newPositions.length / 3 - 1,\r\n bSplit = positionsCount - 1 + newPositions.length / 3;\r\n newIndices.push(indices[i * 3]);\r\n newIndices.push(aSplit);\r\n newIndices.push(bSplit);\r\n\r\n if (edgeSplits[0] === 2) {\r\n newIndices.push(\r\n indices[i * 3 + 1],\r\n bSplit,\r\n aSplit,\r\n indices[i * 3 + 2],\r\n bSplit,\r\n indices[i * 3 + 1]\r\n );\r\n } else if (edgeSplits[1] === 2) {\r\n newIndices.push(\r\n indices[i * 3 + 2],\r\n indices[i * 3],\r\n bSplit,\r\n indices[i * 3 + 1],\r\n bSplit,\r\n aSplit\r\n );\r\n } else {\r\n newIndices.push(\r\n indices[i * 3 + 1],\r\n aSplit,\r\n indices[i * 3],\r\n indices[i * 3 + 2],\r\n bSplit,\r\n aSplit\r\n );\r\n }\r\n newSubmeshes.forEach((submeshData, sI) => {\r\n const preSliceSubmesh = preSliceSubmeshes[sI];\r\n if (\r\n preSliceSubmesh.indexStart <= i * 3 &&\r\n preSliceSubmesh.indexStart + preSliceSubmesh.indexCount > i * 3\r\n ) {\r\n submeshData.indexCount += 6;\r\n } else if (preSliceSubmesh.indexStart > i * 3) {\r\n submeshData.indexStart += 6;\r\n }\r\n });\r\n }\r\n edgeSplits.clear();\r\n hit = 0;\r\n } else {\r\n // if(feature.removeGeometry && d > 1 - 1e-12) {\r\n // // If this face is in front of the face relative to the face normal, cull it\r\n // newSubmeshes.forEach(submeshData => {\r\n // if(submeshData.indexStart <= i && submeshData.indexStart + submeshData.indexCount > i) {\r\n // submeshData.indexCount -= 3;\r\n // } else if(submeshData.indexStart > i) {\r\n // submeshData.indexStart -= 3;\r\n // }\r\n // });\r\n // continue;\r\n // } else {\r\n // console.log(d);\r\n // }\r\n newIndices.push(indices[i * 3], indices[i * 3 + 1], indices[i * 3 + 2]);\r\n }\r\n\r\n // Update the vertices the submeshes are targetting\r\n if (vertexIndex !== -1 && hit > 0) {\r\n newSubmeshes.forEach(submeshData => {\r\n if (\r\n submeshData.verticesStart <= vertexIndex &&\r\n submeshData.verticesStart + submeshData.verticesCount > vertexIndex\r\n ) {\r\n submeshData.verticesCount += hit;\r\n } else if (submeshData.verticesStart > vertexIndex) {\r\n submeshData.verticesStart += hit;\r\n }\r\n });\r\n }\r\n }\r\n\r\n newVertexData.indices = new Int32Array(newIndices);\r\n\r\n newVertexData.positions = new Float32Array(positions.length + newPositions.length);\r\n newVertexData.positions.set(positions);\r\n newVertexData.positions.set(newPositions, positions.length);\r\n\r\n if (normals) {\r\n newVertexData.normals = new Float32Array(normals.length + newNormals.length);\r\n newVertexData.normals.set(normals);\r\n newVertexData.normals.set(newNormals, normals.length);\r\n }\r\n\r\n if (uvs) {\r\n newVertexData.uvs = new Float32Array(uvs.length + newUvs.length);\r\n newVertexData.uvs.set(uvs);\r\n newVertexData.uvs.set(newUvs, uvs.length);\r\n }\r\n\r\n // Remove geometry on one side of the plane if the removeGeometry flag is true\r\n const baseGeometryVertexLength = positions.length / 3;\r\n if (feature.removeGeometry) {\r\n const indices = newVertexData.indices;\r\n const positions = newVertexData.positions;\r\n const normals = newVertexData.normals;\r\n const uvs = newVertexData.uvs;\r\n const newIndices = new Int32Array(indices.length);\r\n const newPositions = new Float32Array(positions.length);\r\n const newNormals = new Float32Array(normals?.length || 0);\r\n const newUvs = new Float32Array(uvs?.length || 0);\r\n\r\n const triCount = indices.length / 3;\r\n const vertexCount = positions.length / 3;\r\n const newPositionIndex = new Int32Array(vertexCount);\r\n\r\n // Keep track of how many positions we've used\r\n let position = 0;\r\n for (let i = 0; i < vertexCount; i++) {\r\n workingVector.set(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]);\r\n workingVector.subtractInPlace(planePoint);\r\n const d = Vector3.Dot(workingVector, planeNormal);\r\n\r\n // Don't remove new vertices that were created from the slice, those are guaranteed to be good\r\n if (i < baseGeometryVertexLength && d > 1e-12) {\r\n // Mark the original indices that have been removed so we can update the index array\r\n newPositionIndex[i] = -1;\r\n } else {\r\n // Copy over the vertex data we need and mark what new index they will have\r\n newPositionIndex[i] = position;\r\n newPositions[position * 3] = positions[i * 3];\r\n newPositions[position * 3 + 1] = positions[i * 3 + 1];\r\n newPositions[position * 3 + 2] = positions[i * 3 + 2];\r\n if (normals) {\r\n newNormals[position * 3] = normals[i * 3];\r\n newNormals[position * 3 + 1] = normals[i * 3 + 1];\r\n newNormals[position * 3 + 2] = normals[i * 3 + 2];\r\n }\r\n if (uvs) {\r\n newUvs[position * 2] = uvs[i * 2];\r\n newUvs[position * 2 + 1] = uvs[i * 2 + 1];\r\n }\r\n position++;\r\n }\r\n }\r\n // Trim off unused parts of the vertex arrays\r\n newVertexData.positions = newPositions.subarray(0, position * 3);\r\n if (normals) {\r\n newVertexData.normals = newNormals.subarray(0, position * 3);\r\n }\r\n if (uvs) {\r\n newVertexData.uvs = newUvs.subarray(0, position * 2);\r\n }\r\n\r\n position = 0;\r\n const originalSubmeshes = newSubmeshes.map(submesh => ({ ...submesh }));\r\n for (let i = 0; i < triCount; i++) {\r\n // If all of the positions in this triangle are being kept, add the triangle\r\n // The indices of the vertexes are changing so we need to use the value that we calculated prior\r\n if (\r\n newPositionIndex[indices[i * 3]] >= 0 &&\r\n newPositionIndex[indices[i * 3 + 1]] >= 0 &&\r\n newPositionIndex[indices[i * 3 + 2]] >= 0\r\n ) {\r\n newIndices[position * 3] = newPositionIndex[indices[i * 3]];\r\n newIndices[position * 3 + 1] = newPositionIndex[indices[i * 3 + 1]];\r\n newIndices[position * 3 + 2] = newPositionIndex[indices[i * 3 + 2]];\r\n position++;\r\n } else {\r\n newSubmeshes.forEach((submeshData, sI) => {\r\n const originalSubmesh = originalSubmeshes[sI];\r\n if (\r\n originalSubmesh.indexStart <= i * 3 &&\r\n originalSubmesh.indexStart + originalSubmesh.indexCount > i * 3\r\n ) {\r\n submeshData.indexCount -= 3;\r\n } else if (originalSubmesh.indexStart > i * 3) {\r\n submeshData.indexStart -= 3;\r\n }\r\n });\r\n }\r\n }\r\n // Update the vertex values on the submeshes as well\r\n for (let i = 0; i < newPositionIndex.length; i++) {\r\n if (newPositionIndex[i] === -1) {\r\n newSubmeshes.forEach(submeshData => {\r\n if (\r\n submeshData.verticesStart <= i &&\r\n submeshData.verticesStart + submeshData.verticesCount > i\r\n ) {\r\n submeshData.verticesCount--;\r\n } else if (submeshData.verticesStart > i) {\r\n submeshData.verticesStart--;\r\n }\r\n });\r\n }\r\n }\r\n newVertexData.indices = newIndices.subarray(0, position * 3);\r\n }\r\n\r\n newVertexData.submeshData = newSubmeshes;\r\n }\r\n return newVertexData;\r\n }\r\n\r\n protected updatePreviewMesh(feature: SliceFeature) {\r\n const scene = this.previewLayer.utilityLayerScene;\r\n let visualizationPlane = this.babylonMirrorPreviewsMap.get(feature.id);\r\n\r\n if (!visualizationPlane) {\r\n visualizationPlane = createMirrorVisualization(feature, scene);\r\n visualizationPlane.isPickable = false;\r\n this.babylonMirrorPreviewsMap.set(feature.id, visualizationPlane);\r\n }\r\n\r\n const currentNormal = new Vector3();\r\n currentNormal.set(0, 0, 1);\r\n const newNormal = new Vector3();\r\n newNormal.set(feature.normal.x, feature.normal.y, feature.normal.z);\r\n visualizationPlane.rotationQuaternion = rotationToVector(newNormal, currentNormal);\r\n let parentBoundingBox = undefined;\r\n if (feature._parent) {\r\n parentBoundingBox = this.viewer.getMeshBoundingBox(feature._parent);\r\n }\r\n if (parentBoundingBox) {\r\n const scale = parentBoundingBox.minWorld.subtract(parentBoundingBox.maxWorld).length();\r\n visualizationPlane.scaling.set(scale, scale, scale);\r\n }\r\n\r\n if (feature._parent) {\r\n const featureParent = this.viewer.getRendererNode(feature._parent);\r\n const meshPosition = featureParent.getAbsolutePosition();\r\n meshPosition.addInPlace(feature.intersect.toVec3());\r\n visualizationPlane.position.set(meshPosition.x, meshPosition.y, meshPosition.z);\r\n }\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n const visualizationPlane = this.babylonMirrorPreviewsMap.get(node.id);\r\n\r\n if (node._previewVisible) {\r\n this.updatePreviewMesh(node);\r\n if (node.enabled) {\r\n visualizationPlane?.setEnabled(true);\r\n }\r\n } else {\r\n visualizationPlane?.setEnabled(false);\r\n }\r\n }\r\n\r\n delete3d(node: ITrackedClass | ITrackedClass) {\r\n if (this.babylonMirrorPreviewsMap) {\r\n const featureInstance = this.babylonMirrorPreviewsMap.get(node.id);\r\n\r\n if (featureInstance) {\r\n featureInstance.dispose(false, true);\r\n }\r\n this.babylonMirrorPreviewsMap.delete(node.id);\r\n }\r\n super.delete3d(node as ITrackedClass);\r\n }\r\n}\r\n","import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3 } from '@babylonjs/core/Maths/math';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Feature } from '@models/classes';\r\n\r\nexport function createMirrorVisualization(mirror: Feature, scene: Scene, color?: Color3) {\r\n if (!color) {\r\n color = Color3.Yellow();\r\n }\r\n\r\n const mirrorVisualization: Mesh = MeshBuilder.CreatePlane('mirrorPlane', {}, scene);\r\n const coloredMaterial = new StandardMaterial('', scene);\r\n coloredMaterial.wireframe = true;\r\n coloredMaterial.emissiveColor = color;\r\n mirrorVisualization.material = coloredMaterial;\r\n\r\n mirrorVisualization.isPickable = false;\r\n mirrorVisualization.setEnabled(true);\r\n return mirrorVisualization;\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths';\r\nimport { MirrorFeature } from '@models/classes/features/mirror-feature';\r\nimport { SubmeshData } from '@models/classes/features/submesh-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { SliceFeatureRenderer } from './slice';\r\n\r\nexport class MirrorFeatureRenderer extends SliceFeatureRenderer {\r\n modelToken = Token.MirrorFeature;\r\n updateMeshGeometry(\r\n feature: MirrorFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n\r\n if (\r\n newVertexData.positions &&\r\n newVertexData.positions.length > 0 &&\r\n newVertexData.indices &&\r\n newVertexData.indices.length > 0\r\n ) {\r\n const positions = newVertexData.positions;\r\n const normals = newVertexData.normals;\r\n const uvs = newVertexData.uvs;\r\n const indices = newVertexData.indices;\r\n\r\n const newIndices = new Int32Array(indices.length);\r\n const newPositions = new Float32Array(positions.length);\r\n const newNormals = new Float32Array(normals?.length || 0);\r\n\r\n const workingVector = Vector3.Zero();\r\n const planeNormal = feature.normal.toVec3().normalize();\r\n const planeIntersect = feature.intersect.toVec3();\r\n const vertexCount = positions.length / 3;\r\n for (let i = 0; i < vertexCount; i++) {\r\n const idx = i * 3;\r\n workingVector.set(positions[idx], positions[idx + 1], positions[idx + 2]);\r\n workingVector.subtractInPlace(planeIntersect);\r\n let d = Vector3.Dot(workingVector, planeNormal);\r\n planeNormal.scaleAndAddToRef(-2 * d, workingVector);\r\n newPositions[idx] = workingVector.x + planeIntersect.x;\r\n newPositions[idx + 1] = workingVector.y + planeIntersect.y;\r\n newPositions[idx + 2] = workingVector.z + planeIntersect.z;\r\n\r\n if (normals) {\r\n workingVector.set(normals[idx], normals[idx + 1], normals[idx + 2]);\r\n d = Vector3.Dot(workingVector, planeNormal);\r\n planeNormal.scaleAndAddToRef(-2 * d, workingVector);\r\n newNormals[idx] = workingVector.x;\r\n newNormals[idx + 1] = workingVector.y;\r\n newNormals[idx + 2] = workingVector.z;\r\n }\r\n }\r\n\r\n // Flip the direction of the triangles so that the normals face the right way\r\n const triCount = indices.length / 3;\r\n for (let i = 0; i < triCount; i++) {\r\n const idx = i * 3;\r\n if (feature.cloneGeometry) {\r\n newIndices[idx] = vertexCount + indices[idx + 2];\r\n newIndices[idx + 1] = vertexCount + indices[idx + 1];\r\n newIndices[idx + 2] = vertexCount + indices[idx];\r\n } else {\r\n newIndices[idx] = indices[idx + 2];\r\n newIndices[idx + 1] = indices[idx + 1];\r\n newIndices[idx + 2] = indices[idx];\r\n }\r\n }\r\n\r\n if (feature.cloneGeometry) {\r\n const combinedIndices = new Int32Array(indices.length * 2);\r\n const combinedPositions = new Float32Array(positions.length * 2);\r\n const combinedNormals = new Float32Array((normals?.length || 0) * 2);\r\n const combinedUvs = new Float32Array((uvs?.length || 0) * 2);\r\n const combinedSubmeshes: SubmeshData[] = [];\r\n\r\n combinedIndices.set(indices);\r\n combinedIndices.set(newIndices, indices.length);\r\n combinedPositions.set(positions);\r\n combinedPositions.set(newPositions, positions.length);\r\n if (normals) {\r\n combinedNormals.set(normals);\r\n combinedNormals.set(newNormals, normals.length);\r\n }\r\n if (uvs) {\r\n combinedUvs.set(uvs);\r\n combinedUvs.set(uvs, uvs.length);\r\n }\r\n\r\n if (newVertexData.submeshData) {\r\n newVertexData.submeshData.forEach(submesh => {\r\n const newSubmesh = {\r\n ...submesh,\r\n verticesStart: submesh.verticesStart + vertexCount,\r\n indexStart: submesh.indexStart + indices.length,\r\n };\r\n combinedSubmeshes.push(submesh, newSubmesh);\r\n });\r\n }\r\n\r\n newVertexData.indices = combinedIndices;\r\n newVertexData.positions = combinedPositions;\r\n if (normals) {\r\n newVertexData.normals = combinedNormals;\r\n }\r\n if (uvs) {\r\n newVertexData.uvs = combinedUvs;\r\n }\r\n newVertexData.submeshData = combinedSubmeshes;\r\n } else {\r\n newVertexData.indices = newIndices;\r\n newVertexData.positions = newPositions;\r\n if (normals) {\r\n newVertexData.normals = newNormals;\r\n }\r\n }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n}\r\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from) {\r\n for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)\r\n to[j] = from[i];\r\n return to;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","import { SVGPathData } from \"./SVGPathData\";\nimport { SVGCommand } from \"./types\";\n\n// Encode SVG PathData\n// http://www.w3.org/TR/SVG/paths.html#PathDataBNF\n\n// Private consts : Char groups\nconst WSP = \" \";\n\nexport function encodeSVGPath(commands: SVGCommand | SVGCommand[]) {\n let str = \"\";\n\n if (!Array.isArray(commands)) {\n commands = [commands];\n }\n for (let i = 0; i < commands.length; i++) {\n const command = commands[i];\n if (command.type === SVGPathData.CLOSE_PATH) {\n str += \"z\";\n } else if (command.type === SVGPathData.HORIZ_LINE_TO) {\n str += (command.relative ? \"h\" : \"H\") +\n command.x;\n } else if (command.type === SVGPathData.VERT_LINE_TO) {\n str += (command.relative ? \"v\" : \"V\") +\n command.y;\n } else if (command.type === SVGPathData.MOVE_TO) {\n str += (command.relative ? \"m\" : \"M\") +\n command.x + WSP + command.y;\n } else if (command.type === SVGPathData.LINE_TO) {\n str += (command.relative ? \"l\" : \"L\") +\n command.x + WSP + command.y;\n } else if (command.type === SVGPathData.CURVE_TO) {\n str += (command.relative ? \"c\" : \"C\") +\n command.x1 + WSP + command.y1 +\n WSP + command.x2 + WSP + command.y2 +\n WSP + command.x + WSP + command.y;\n } else if (command.type === SVGPathData.SMOOTH_CURVE_TO) {\n str += (command.relative ? \"s\" : \"S\") +\n command.x2 + WSP + command.y2 +\n WSP + command.x + WSP + command.y;\n } else if (command.type === SVGPathData.QUAD_TO) {\n str += (command.relative ? \"q\" : \"Q\") +\n command.x1 + WSP + command.y1 +\n WSP + command.x + WSP + command.y;\n } else if (command.type === SVGPathData.SMOOTH_QUAD_TO) {\n str += (command.relative ? \"t\" : \"T\") +\n command.x + WSP + command.y;\n } else if (command.type === SVGPathData.ARC) {\n str += (command.relative ? \"a\" : \"A\") +\n command.rX + WSP + command.rY +\n WSP + command.xRot +\n WSP + (+command.lArcFlag) + WSP + (+command.sweepFlag) +\n WSP + command.x + WSP + command.y;\n } else {\n // Unknown command\n throw new Error(\n `Unexpected command type \"${ (command as any).type}\" at index ${i}.`);\n }\n }\n\n return str;\n}\n","import { SVGPathData } from \"./SVGPathData\";\nimport { CommandA, CommandC } from \"./types\";\n\nexport function rotate([x, y]: [number, number], rad: number) {\n return [\n x * Math.cos(rad) - y * Math.sin(rad),\n x * Math.sin(rad) + y * Math.cos(rad),\n ];\n}\n\nconst DEBUG_CHECK_NUMBERS = true;\nexport function assertNumbers(...numbers: number[]) {\n if (DEBUG_CHECK_NUMBERS) {\n for (let i = 0; i < numbers.length; i++) {\n if (\"number\" !== typeof numbers[i]) {\n throw new Error(\n `assertNumbers arguments[${i}] is not a number. ${typeof numbers[i]} == typeof ${numbers[i]}`);\n }\n }\n }\n return true;\n}\n\nconst PI = Math.PI;\n\n/**\n * https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes\n * Fixes rX and rY.\n * Ensures lArcFlag and sweepFlag are 0 or 1\n * Adds center coordinates: command.cX, command.cY (relative or absolute, depending on command.relative)\n * Adds start and end arc parameters (in degrees): command.phi1, command.phi2; phi1 < phi2 iff. c.sweepFlag == true\n */\nexport function annotateArcCommand(c: CommandA, x1: number, y1: number) {\n c.lArcFlag = (0 === c.lArcFlag) ? 0 : 1;\n c.sweepFlag = (0 === c.sweepFlag) ? 0 : 1;\n // tslint:disable-next-line\n let {rX, rY, x, y} = c;\n\n rX = Math.abs(c.rX);\n rY = Math.abs(c.rY);\n const [x1_, y1_] = rotate([(x1 - x) / 2, (y1 - y) / 2], -c.xRot / 180 * PI);\n const testValue = Math.pow(x1_, 2) / Math.pow(rX, 2) + Math.pow(y1_, 2) / Math.pow(rY, 2);\n\n if (1 < testValue) {\n rX *= Math.sqrt(testValue);\n rY *= Math.sqrt(testValue);\n }\n c.rX = rX;\n c.rY = rY;\n const c_ScaleTemp = (Math.pow(rX, 2) * Math.pow(y1_, 2) + Math.pow(rY, 2) * Math.pow(x1_, 2));\n const c_Scale = (c.lArcFlag !== c.sweepFlag ? 1 : -1) *\n Math.sqrt(Math.max(0, (Math.pow(rX, 2) * Math.pow(rY, 2) - c_ScaleTemp) / c_ScaleTemp));\n const cx_ = rX * y1_ / rY * c_Scale;\n const cy_ = -rY * x1_ / rX * c_Scale;\n const cRot = rotate([cx_, cy_], c.xRot / 180 * PI);\n\n c.cX = cRot[0] + (x1 + x) / 2;\n c.cY = cRot[1] + (y1 + y) / 2;\n c.phi1 = Math.atan2((y1_ - cy_) / rY, (x1_ - cx_) / rX);\n c.phi2 = Math.atan2((-y1_ - cy_) / rY, (-x1_ - cx_) / rX);\n if (0 === c.sweepFlag && c.phi2 > c.phi1) {\n c.phi2 -= 2 * PI;\n }\n if (1 === c.sweepFlag && c.phi2 < c.phi1) {\n c.phi2 += 2 * PI;\n }\n c.phi1 *= 180 / PI;\n c.phi2 *= 180 / PI;\n}\n\n/**\n * Solves a quadratic system of equations of the form\n * a * x + b * y = c\n * x² + y² = 1\n * This can be understood as the intersection of the unit circle with a line.\n * => y = (c - a x) / b\n * => x² + (c - a x)² / b² = 1\n * => x² b² + c² - 2 c a x + a² x² = b²\n * => (a² + b²) x² - 2 a c x + (c² - b²) = 0\n */\nexport function intersectionUnitCircleLine(a: number, b: number, c: number): [number, number][] {\n assertNumbers(a, b, c);\n // cf. pqFormula\n const termSqr = a * a + b * b - c * c;\n\n if (0 > termSqr) {\n return [];\n } else if (0 === termSqr) {\n return [\n [\n (a * c) / (a * a + b * b),\n (b * c) / (a * a + b * b)]];\n }\n const term = Math.sqrt(termSqr);\n\n return [\n [\n (a * c + b * term) / (a * a + b * b),\n (b * c - a * term) / (a * a + b * b)],\n [\n (a * c - b * term) / (a * a + b * b),\n (b * c + a * term) / (a * a + b * b)]];\n\n}\n\nexport const DEG = Math.PI / 180;\n\nexport function lerp(a: number, b: number, t: number) {\n return (1 - t) * a + t * b;\n}\n\nexport function arcAt(c: number, x1: number, x2: number, phiDeg: number) {\n return c + Math.cos(phiDeg / 180 * PI) * x1 + Math.sin(phiDeg / 180 * PI) * x2;\n}\n\nexport function bezierRoot(x0: number, x1: number, x2: number, x3: number) {\n const EPS = 1e-6;\n const x01 = x1 - x0;\n const x12 = x2 - x1;\n const x23 = x3 - x2;\n const a = 3 * x01 + 3 * x23 - 6 * x12;\n const b = (x12 - x01) * 6;\n const c = 3 * x01;\n // solve a * t² + b * t + c = 0\n\n if (Math.abs(a) < EPS) {\n // equivalent to b * t + c =>\n return [-c / b];\n }\n return pqFormula(b / a, c / a, EPS);\n\n}\n\nexport function bezierAt(x0: number, x1: number, x2: number, x3: number, t: number) {\n // console.log(x0, y0, x1, y1, x2, y2, x3, y3, t)\n const s = 1 - t;\n const c0 = s * s * s;\n const c1 = 3 * s * s * t;\n const c2 = 3 * s * t * t;\n const c3 = t * t * t;\n\n return x0 * c0 + x1 * c1 + x2 * c2 + x3 * c3;\n}\n\nfunction pqFormula(p: number, q: number, PRECISION = 1e-6) {\n // 4 times the discriminant:in\n const discriminantX4 = p * p / 4 - q;\n\n if (discriminantX4 < -PRECISION) {\n return [];\n } else if (discriminantX4 <= PRECISION) {\n return [-p / 2];\n }\n const root = Math.sqrt(discriminantX4);\n\n return [-(p / 2) - root, -(p / 2) + root];\n\n}\n\nexport function a2c(arc: CommandA, x0: number, y0: number): CommandC[] {\n if (!arc.cX) {\n annotateArcCommand(arc, x0, y0);\n }\n\n const phiMin = Math.min(arc.phi1!, arc.phi2!), phiMax = Math.max(arc.phi1!, arc.phi2!), deltaPhi = phiMax - phiMin;\n const partCount = Math.ceil(deltaPhi / 90 );\n\n const result: CommandC[] = new Array(partCount);\n let prevX = x0, prevY = y0;\n for (let i = 0; i < partCount; i++) {\n const phiStart = lerp(arc.phi1!, arc.phi2!, i / partCount);\n const phiEnd = lerp(arc.phi1!, arc.phi2!, (i + 1) / partCount);\n const deltaPhi = phiEnd - phiStart;\n const f = 4 / 3 * Math.tan(deltaPhi * DEG / 4);\n // x1/y1, x2/y2 and x/y coordinates on the unit circle for phiStart/phiEnd\n const [x1, y1] = [\n Math.cos(phiStart * DEG) - f * Math.sin(phiStart * DEG),\n Math.sin(phiStart * DEG) + f * Math.cos(phiStart * DEG)];\n const [x, y] = [Math.cos(phiEnd * DEG), Math.sin(phiEnd * DEG)];\n const [x2, y2] = [x + f * Math.sin(phiEnd * DEG), y - f * Math.cos(phiEnd * DEG)];\n result[i] = {relative: arc.relative, type: SVGPathData.CURVE_TO } as any;\n const transform = (x: number, y: number) => {\n const [xTemp, yTemp] = rotate([x * arc.rX, y * arc.rY], arc.xRot);\n return [arc.cX! + xTemp, arc.cY! + yTemp];\n };\n [result[i].x1, result[i].y1] = transform(x1, y1);\n [result[i].x2, result[i].y2] = transform(x2, y2);\n [result[i].x, result[i].y] = transform(x, y);\n if (arc.relative) {\n result[i].x1 -= prevX;\n result[i].y1 -= prevY;\n result[i].x2 -= prevX;\n result[i].y2 -= prevY;\n result[i].x -= prevX;\n result[i].y -= prevY;\n }\n [prevX, prevY] = [result[i].x, result[i].y];\n }\n return result;\n}\n","// Transform SVG PathData\n// http://www.w3.org/TR/SVG/paths.html#PathDataBNF\n\nimport { a2c, annotateArcCommand, arcAt, assertNumbers, bezierAt, bezierRoot,\n intersectionUnitCircleLine } from \"./mathUtils\";\nimport { SVGPathData } from \"./SVGPathData\";\nimport { SVGCommand, TransformFunction } from \"./types\";\n\nexport namespace SVGPathDataTransformer {\n // Predefined transforming functions\n // Rounds commands values\n export function ROUND(roundVal = 1e13) {\n assertNumbers(roundVal);\n function rf(val: number) { return Math.round(val * roundVal) / roundVal; }\n return function round(command: any) {\n if (\"undefined\" !== typeof command.x1) {\n command.x1 = rf(command.x1);\n }\n if (\"undefined\" !== typeof command.y1) {\n command.y1 = rf(command.y1);\n }\n\n if (\"undefined\" !== typeof command.x2) {\n command.x2 = rf(command.x2);\n }\n if (\"undefined\" !== typeof command.y2) {\n command.y2 = rf(command.y2);\n }\n\n if (\"undefined\" !== typeof command.x) {\n command.x = rf(command.x);\n }\n if (\"undefined\" !== typeof command.y) {\n command.y = rf(command.y);\n }\n\n if (\"undefined\" !== typeof command.rX) {\n command.rX = rf(command.rX);\n }\n if (\"undefined\" !== typeof command.rY) {\n command.rY = rf(command.rY);\n }\n\n return command;\n };\n }\n // Relative to absolute commands\n export function TO_ABS() {\n return INFO((command, prevX, prevY) => {\n if (command.relative) {\n // x1/y1 values\n if (\"undefined\" !== typeof command.x1) {\n command.x1 += prevX;\n }\n if (\"undefined\" !== typeof command.y1) {\n command.y1 += prevY;\n }\n // x2/y2 values\n if (\"undefined\" !== typeof command.x2) {\n command.x2 += prevX;\n }\n if (\"undefined\" !== typeof command.y2) {\n command.y2 += prevY;\n }\n // Finally x/y values\n if (\"undefined\" !== typeof command.x) {\n command.x += prevX;\n }\n if (\"undefined\" !== typeof command.y) {\n command.y += prevY;\n }\n command.relative = false;\n }\n return command;\n });\n }\n // Absolute to relative commands\n export function TO_REL() {\n return INFO((command, prevX, prevY) => {\n if (!command.relative) {\n // x1/y1 values\n if (\"undefined\" !== typeof command.x1) {\n command.x1 -= prevX;\n }\n if (\"undefined\" !== typeof command.y1) {\n command.y1 -= prevY;\n }\n // x2/y2 values\n if (\"undefined\" !== typeof command.x2) {\n command.x2 -= prevX;\n }\n if (\"undefined\" !== typeof command.y2) {\n command.y2 -= prevY;\n }\n // Finally x/y values\n if (\"undefined\" !== typeof command.x) {\n command.x -= prevX;\n }\n if (\"undefined\" !== typeof command.y) {\n command.y -= prevY;\n }\n command.relative = true;\n }\n return command;\n });\n }\n // Convert H, V, Z and A with rX = 0 to L\n export function NORMALIZE_HVZ(normalizeZ = true, normalizeH = true, normalizeV = true) {\n return INFO((command, prevX, prevY, pathStartX, pathStartY) => {\n if (isNaN(pathStartX) && !(command.type & SVGPathData.MOVE_TO)) {\n throw new Error(\"path must start with moveto\");\n }\n if (normalizeH && command.type & SVGPathData.HORIZ_LINE_TO) {\n command.type = SVGPathData.LINE_TO;\n command.y = command.relative ? 0 : prevY;\n }\n if (normalizeV && command.type & SVGPathData.VERT_LINE_TO) {\n command.type = SVGPathData.LINE_TO;\n command.x = command.relative ? 0 : prevX;\n }\n if (normalizeZ && command.type & SVGPathData.CLOSE_PATH) {\n command.type = SVGPathData.LINE_TO;\n command.x = command.relative ? pathStartX - prevX : pathStartX;\n command.y = command.relative ? pathStartY - prevY : pathStartY;\n }\n if (command.type & SVGPathData.ARC && (0 === command.rX || 0 === command.rY)) {\n command.type = SVGPathData.LINE_TO;\n delete command.rX;\n delete command.rY;\n delete command.xRot;\n delete command.lArcFlag;\n delete command.sweepFlag;\n }\n return command;\n });\n }\n /*\n * Transforms smooth curves and quads to normal curves and quads (SsTt to CcQq)\n */\n export function NORMALIZE_ST() {\n let prevCurveC2X = NaN;\n let prevCurveC2Y = NaN;\n let prevQuadCX = NaN;\n let prevQuadCY = NaN;\n\n return INFO((command, prevX, prevY) => {\n if (command.type & SVGPathData.SMOOTH_CURVE_TO) {\n command.type = SVGPathData.CURVE_TO;\n prevCurveC2X = isNaN(prevCurveC2X) ? prevX : prevCurveC2X;\n prevCurveC2Y = isNaN(prevCurveC2Y) ? prevY : prevCurveC2Y;\n command.x1 = command.relative ? prevX - prevCurveC2X : 2 * prevX - prevCurveC2X;\n command.y1 = command.relative ? prevY - prevCurveC2Y : 2 * prevY - prevCurveC2Y;\n }\n if (command.type & SVGPathData.CURVE_TO) {\n prevCurveC2X = command.relative ? prevX + command.x2 : command.x2;\n prevCurveC2Y = command.relative ? prevY + command.y2 : command.y2;\n } else {\n prevCurveC2X = NaN;\n prevCurveC2Y = NaN;\n }\n if (command.type & SVGPathData.SMOOTH_QUAD_TO) {\n command.type = SVGPathData.QUAD_TO;\n prevQuadCX = isNaN(prevQuadCX) ? prevX : prevQuadCX;\n prevQuadCY = isNaN(prevQuadCY) ? prevY : prevQuadCY;\n command.x1 = command.relative ? prevX - prevQuadCX : 2 * prevX - prevQuadCX;\n command.y1 = command.relative ? prevY - prevQuadCY : 2 * prevY - prevQuadCY;\n }\n if (command.type & SVGPathData.QUAD_TO) {\n prevQuadCX = command.relative ? prevX + command.x1 : command.x1;\n prevQuadCY = command.relative ? prevY + command.y1 : command.y1;\n } else {\n prevQuadCX = NaN;\n prevQuadCY = NaN;\n }\n\n return command;\n });\n }\n /*\n * A quadratic bézier curve can be represented by a cubic bézier curve which has\n * the same end points as the quadratic and both control points in place of the\n * quadratic\"s one.\n *\n * This transformer replaces QqTt commands with Cc commands respectively.\n * This is useful for reading path data into a system which only has a\n * representation for cubic curves.\n */\n export function QT_TO_C() {\n let prevQuadX1 = NaN;\n let prevQuadY1 = NaN;\n\n return INFO((command, prevX, prevY) => {\n if (command.type & SVGPathData.SMOOTH_QUAD_TO) {\n command.type = SVGPathData.QUAD_TO;\n prevQuadX1 = isNaN(prevQuadX1) ? prevX : prevQuadX1;\n prevQuadY1 = isNaN(prevQuadY1) ? prevY : prevQuadY1;\n command.x1 = command.relative ? prevX - prevQuadX1 : 2 * prevX - prevQuadX1;\n command.y1 = command.relative ? prevY - prevQuadY1 : 2 * prevY - prevQuadY1;\n }\n if (command.type & SVGPathData.QUAD_TO) {\n prevQuadX1 = command.relative ? prevX + command.x1 : command.x1;\n prevQuadY1 = command.relative ? prevY + command.y1 : command.y1;\n const x1 = command.x1;\n const y1 = command.y1;\n\n command.type = SVGPathData.CURVE_TO;\n command.x1 = ((command.relative ? 0 : prevX) + x1 * 2) / 3;\n command.y1 = ((command.relative ? 0 : prevY) + y1 * 2) / 3;\n command.x2 = (command.x + x1 * 2) / 3;\n command.y2 = (command.y + y1 * 2) / 3;\n } else {\n prevQuadX1 = NaN;\n prevQuadY1 = NaN;\n }\n\n return command;\n });\n }\n export function INFO(\n f: (command: any, prevXAbs: number, prevYAbs: number,\n pathStartXAbs: number, pathStartYAbs: number) => any | any[]) {\n let prevXAbs = 0;\n let prevYAbs = 0;\n let pathStartXAbs = NaN;\n let pathStartYAbs = NaN;\n\n return function transform(command: any) {\n if (isNaN(pathStartXAbs) && !(command.type & SVGPathData.MOVE_TO)) {\n throw new Error(\"path must start with moveto\");\n }\n\n const result = f(command, prevXAbs, prevYAbs, pathStartXAbs, pathStartYAbs);\n\n if (command.type & SVGPathData.CLOSE_PATH) {\n prevXAbs = pathStartXAbs;\n prevYAbs = pathStartYAbs;\n }\n\n if (\"undefined\" !== typeof command.x) {\n prevXAbs = (command.relative ? prevXAbs + command.x : command.x);\n }\n if (\"undefined\" !== typeof command.y) {\n prevYAbs = (command.relative ? prevYAbs + command.y : command.y);\n }\n\n if (command.type & SVGPathData.MOVE_TO) {\n pathStartXAbs = prevXAbs;\n pathStartYAbs = prevYAbs;\n }\n\n return result;\n };\n }\n /*\n * remove 0-length segments\n */\n export function SANITIZE(EPS = 0) {\n assertNumbers(EPS);\n let prevCurveC2X = NaN;\n let prevCurveC2Y = NaN;\n let prevQuadCX = NaN;\n let prevQuadCY = NaN;\n\n return INFO((command, prevX, prevY, pathStartX, pathStartY) => {\n const abs = Math.abs;\n let skip = false;\n let x1Rel = 0;\n let y1Rel = 0;\n\n if (command.type & SVGPathData.SMOOTH_CURVE_TO) {\n x1Rel = isNaN(prevCurveC2X) ? 0 : prevX - prevCurveC2X;\n y1Rel = isNaN(prevCurveC2Y) ? 0 : prevY - prevCurveC2Y;\n }\n if (command.type & (SVGPathData.CURVE_TO | SVGPathData.SMOOTH_CURVE_TO)) {\n prevCurveC2X = command.relative ? prevX + command.x2 : command.x2;\n prevCurveC2Y = command.relative ? prevY + command.y2 : command.y2;\n } else {\n prevCurveC2X = NaN;\n prevCurveC2Y = NaN;\n }\n if (command.type & SVGPathData.SMOOTH_QUAD_TO) {\n prevQuadCX = isNaN(prevQuadCX) ? prevX : 2 * prevX - prevQuadCX;\n prevQuadCY = isNaN(prevQuadCY) ? prevY : 2 * prevY - prevQuadCY;\n } else if (command.type & SVGPathData.QUAD_TO) {\n prevQuadCX = command.relative ? prevX + command.x1 : command.x1;\n prevQuadCY = command.relative ? prevY + command.y1 : command.y2;\n } else {\n prevQuadCX = NaN;\n prevQuadCY = NaN;\n }\n\n if (command.type & SVGPathData.LINE_COMMANDS ||\n command.type & SVGPathData.ARC && (0 === command.rX || 0 === command.rY || !command.lArcFlag) ||\n command.type & SVGPathData.CURVE_TO || command.type & SVGPathData.SMOOTH_CURVE_TO ||\n command.type & SVGPathData.QUAD_TO || command.type & SVGPathData.SMOOTH_QUAD_TO) {\n const xRel = \"undefined\" === typeof command.x ? 0 :\n (command.relative ? command.x : command.x - prevX);\n const yRel = \"undefined\" === typeof command.y ? 0 :\n (command.relative ? command.y : command.y - prevY);\n\n x1Rel = !isNaN(prevQuadCX) ? prevQuadCX - prevX :\n \"undefined\" === typeof command.x1 ? x1Rel :\n command.relative ? command.x :\n command.x1 - prevX;\n y1Rel = !isNaN(prevQuadCY) ? prevQuadCY - prevY :\n \"undefined\" === typeof command.y1 ? y1Rel :\n command.relative ? command.y :\n command.y1 - prevY;\n\n const x2Rel = \"undefined\" === typeof command.x2 ? 0 :\n (command.relative ? command.x : command.x2 - prevX);\n const y2Rel = \"undefined\" === typeof command.y2 ? 0 :\n (command.relative ? command.y : command.y2 - prevY);\n\n if (abs(xRel) <= EPS && abs(yRel) <= EPS &&\n abs(x1Rel) <= EPS && abs(y1Rel) <= EPS &&\n abs(x2Rel) <= EPS && abs(y2Rel) <= EPS) {\n skip = true;\n }\n }\n\n if (command.type & SVGPathData.CLOSE_PATH) {\n if (abs(prevX - pathStartX) <= EPS && abs(prevY - pathStartY) <= EPS) {\n skip = true;\n }\n }\n\n return skip ? [] : command;\n });\n }\n // SVG Transforms : http://www.w3.org/TR/SVGTiny12/coords.html#TransformList\n // Matrix : http://apike.ca/prog_svg_transform.html\n // a c e\n // b d f\n export function MATRIX(a: number, b: number, c: number, d: number, e: number, f: number) {\n assertNumbers(a, b, c, d, e, f);\n\n return INFO((command, prevX, prevY, pathStartX) => {\n const origX1 = command.x1;\n const origX2 = command.x2;\n // if isNaN(pathStartX), then this is the first command, which is ALWAYS an\n // absolute MOVE_TO, regardless what the relative flag says\n const comRel = command.relative && !isNaN(pathStartX);\n const x = \"undefined\" !== typeof command.x ? command.x : (comRel ? 0 : prevX);\n const y = \"undefined\" !== typeof command.y ? command.y : (comRel ? 0 : prevY);\n\n if (command.type & SVGPathData.HORIZ_LINE_TO && 0 !== b) {\n command.type = SVGPathData.LINE_TO;\n command.y = command.relative ? 0 : prevY;\n }\n if (command.type & SVGPathData.VERT_LINE_TO && 0 !== c) {\n command.type = SVGPathData.LINE_TO;\n command.x = command.relative ? 0 : prevX;\n }\n\n if (\"undefined\" !== typeof command.x) {\n command.x = (command.x * a) + (y * c) + (comRel ? 0 : e);\n }\n if (\"undefined\" !== typeof command.y) {\n command.y = (x * b) + command.y * d + (comRel ? 0 : f);\n }\n if (\"undefined\" !== typeof command.x1) {\n command.x1 = command.x1 * a + command.y1 * c + (comRel ? 0 : e);\n }\n if (\"undefined\" !== typeof command.y1) {\n command.y1 = origX1 * b + command.y1 * d + (comRel ? 0 : f);\n }\n if (\"undefined\" !== typeof command.x2) {\n command.x2 = command.x2 * a + command.y2 * c + (comRel ? 0 : e);\n }\n if (\"undefined\" !== typeof command.y2) {\n command.y2 = origX2 * b + command.y2 * d + (comRel ? 0 : f);\n }\n function sqr(x: number) { return x * x; }\n const det = a * d - b * c;\n\n if (\"undefined\" !== typeof command.xRot) {\n // Skip if this is a pure translation\n if (1 !== a || 0 !== b || 0 !== c || 1 !== d) {\n // Special case for singular matrix\n if (0 === det) {\n // In the singular case, the arc is compressed to a line. The actual geometric image of the original\n // curve under this transform possibly extends beyond the starting and/or ending points of the segment, but\n // for simplicity we ignore this detail and just replace this command with a single line segment.\n delete command.rX;\n delete command.rY;\n delete command.xRot;\n delete command.lArcFlag;\n delete command.sweepFlag;\n command.type = SVGPathData.LINE_TO;\n } else {\n // Convert to radians\n const xRot = command.xRot * Math.PI / 180;\n\n // Convert rotated ellipse to general conic form\n // x0^2/rX^2 + y0^2/rY^2 - 1 = 0\n // x0 = x*cos(xRot) + y*sin(xRot)\n // y0 = -x*sin(xRot) + y*cos(xRot)\n // --> A*x^2 + B*x*y + C*y^2 - 1 = 0, where\n const sinRot = Math.sin(xRot);\n const cosRot = Math.cos(xRot);\n const xCurve = 1 / sqr(command.rX);\n const yCurve = 1 / sqr(command.rY);\n const A = sqr(cosRot) * xCurve + sqr(sinRot) * yCurve;\n const B = 2 * sinRot * cosRot * (xCurve - yCurve);\n const C = sqr(sinRot) * xCurve + sqr(cosRot) * yCurve;\n\n // Apply matrix to A*x^2 + B*x*y + C*y^2 - 1 = 0\n // x1 = a*x + c*y\n // y1 = b*x + d*y\n // (we can ignore e and f, since pure translations don\"t affect the shape of the ellipse)\n // --> A1*x1^2 + B1*x1*y1 + C1*y1^2 - det^2 = 0, where\n const A1 = A * d * d - B * b * d + C * b * b;\n const B1 = B * (a * d + b * c) - 2 * (A * c * d + C * a * b);\n const C1 = A * c * c - B * a * c + C * a * a;\n\n // Unapply newXRot to get back to axis-aligned ellipse equation\n // x1 = x2*cos(newXRot) - y2*sin(newXRot)\n // y1 = x2*sin(newXRot) + y2*cos(newXRot)\n // A1*x1^2 + B1*x1*y1 + C1*y1^2 - det^2 =\n // x2^2*(A1*cos(newXRot)^2 + B1*sin(newXRot)*cos(newXRot) + C1*sin(newXRot)^2)\n // + x2*y2*(2*(C1 - A1)*sin(newXRot)*cos(newXRot) + B1*(cos(newXRot)^2 - sin(newXRot)^2))\n // + y2^2*(A1*sin(newXRot)^2 - B1*sin(newXRot)*cos(newXRot) + C1*cos(newXRot)^2)\n // (which must have the same zeroes as)\n // x2^2/newRX^2 + y2^2/newRY^2 - 1\n // (so we have)\n // 2*(C1 - A1)*sin(newXRot)*cos(newXRot) + B1*(cos(newXRot)^2 - sin(newXRot)^2) = 0\n // (A1 - C1)*sin(2*newXRot) = B1*cos(2*newXRot)\n // 2*newXRot = atan2(B1, A1 - C1)\n const newXRot = ((Math.atan2(B1, A1 - C1) + Math.PI) % Math.PI) / 2;\n // For any integer n, (atan2(B1, A1 - C1) + n*pi)/2 is a solution to the above; incrementing n just swaps\n // the x and y radii computed below (since that\"s what rotating an ellipse by pi/2 does). Choosing the\n // rotation between 0 and pi/2 eliminates the ambiguity and leads to more predictable output.\n\n // Finally, we get newRX and newRY from the same-zeroes relationship that gave us newXRot\n const newSinRot = Math.sin(newXRot);\n const newCosRot = Math.cos(newXRot);\n\n command.rX = Math.abs(det) /\n Math.sqrt(A1 * sqr(newCosRot) + B1 * newSinRot * newCosRot + C1 * sqr(newSinRot));\n command.rY = Math.abs(det) /\n Math.sqrt(A1 * sqr(newSinRot) - B1 * newSinRot * newCosRot + C1 * sqr(newCosRot));\n command.xRot = newXRot * 180 / Math.PI;\n }\n }\n }\n // sweepFlag needs to be inverted when mirroring shapes\n // see http://www.itk.ilstu.edu/faculty/javila/SVG/SVG_drawing1/elliptical_curve.htm\n // m 65,10 a 50,25 0 1 0 50,25\n // M 65,60 A 50,25 0 1 1 115,35\n if (\"undefined\" !== typeof command.sweepFlag && 0 > det) {\n command.sweepFlag = +!command.sweepFlag;\n }\n return command;\n });\n }\n export function ROTATE(a: number, x = 0, y = 0) {\n assertNumbers(a, x, y);\n const sin = Math.sin(a);\n const cos = Math.cos(a);\n\n return MATRIX(cos, sin, -sin, cos, x - x * cos + y * sin, y - x * sin - y * cos);\n }\n export function TRANSLATE(dX: number, dY = 0) {\n assertNumbers(dX, dY);\n return MATRIX(1, 0, 0, 1, dX, dY);\n }\n export function SCALE(dX: number, dY = dX) {\n assertNumbers(dX, dY);\n return MATRIX(dX, 0, 0, dY, 0, 0);\n }\n export function SKEW_X(a: number) {\n assertNumbers(a);\n return MATRIX(1, 0, Math.atan(a), 1, 0, 0);\n }\n export function SKEW_Y(a: number) {\n assertNumbers(a);\n return MATRIX(1, Math.atan(a), 0, 1, 0, 0);\n }\n export function X_AXIS_SYMMETRY(xOffset = 0) {\n assertNumbers(xOffset);\n return MATRIX(-1, 0, 0, 1, xOffset, 0);\n }\n export function Y_AXIS_SYMMETRY(yOffset = 0) {\n assertNumbers(yOffset);\n return MATRIX(1, 0, 0, -1, 0, yOffset);\n }\n // Convert arc commands to curve commands\n export function A_TO_C() {\n return INFO((command, prevX, prevY) => {\n if (SVGPathData.ARC === command.type) {\n return a2c(command, command.relative ? 0 : prevX, command.relative ? 0 : prevY);\n }\n return command;\n });\n }\n // @see annotateArcCommand\n export function ANNOTATE_ARCS() {\n return INFO((c, x1, y1) => {\n if (c.relative) {\n x1 = 0;\n y1 = 0;\n }\n if (SVGPathData.ARC === c.type) {\n annotateArcCommand(c, x1, y1);\n }\n return c;\n });\n }\n export function CLONE() {\n return (c: SVGCommand) => {\n const result = {} as SVGCommand;\n // tslint:disable-next-line\n for (const key in c) {\n result[key as keyof SVGCommand] = c[key as keyof SVGCommand];\n }\n return result;\n };\n }\n // @see annotateArcCommand\n export function CALCULATE_BOUNDS() {\n const clone = CLONE();\n const toAbs = TO_ABS();\n const qtToC = QT_TO_C();\n const normST = NORMALIZE_ST();\n const f: TransformFunction & {minX: number, maxX: number, minY: number, maxY: number} =\n INFO((command, prevXAbs, prevYAbs) => {\n const c = normST(qtToC(toAbs(clone(command))));\n function fixX(absX: number) {\n if (absX > f.maxX) { f.maxX = absX; }\n if (absX < f.minX) { f.minX = absX; }\n }\n function fixY(absY: number) {\n if (absY > f.maxY) { f.maxY = absY; }\n if (absY < f.minY) { f.minY = absY; }\n }\n if (c.type & SVGPathData.DRAWING_COMMANDS) {\n fixX(prevXAbs);\n fixY(prevYAbs);\n }\n if (c.type & SVGPathData.HORIZ_LINE_TO) {\n fixX(c.x);\n }\n if (c.type & SVGPathData.VERT_LINE_TO) {\n fixY(c.y);\n }\n if (c.type & SVGPathData.LINE_TO) {\n fixX(c.x);\n fixY(c.y);\n }\n if (c.type & SVGPathData.CURVE_TO) {\n // add start and end points\n fixX(c.x);\n fixY(c.y);\n const xDerivRoots = bezierRoot(prevXAbs, c.x1, c.x2, c.x);\n\n for (const derivRoot of xDerivRoots) {\n if (0 < derivRoot && 1 > derivRoot) {\n fixX(bezierAt(prevXAbs, c.x1, c.x2, c.x, derivRoot));\n }\n }\n const yDerivRoots = bezierRoot(prevYAbs, c.y1, c.y2, c.y);\n\n for (const derivRoot of yDerivRoots) {\n if (0 < derivRoot && 1 > derivRoot) {\n fixY(bezierAt(prevYAbs, c.y1, c.y2, c.y, derivRoot));\n }\n }\n }\n if (c.type & SVGPathData.ARC) {\n // add start and end points\n fixX(c.x);\n fixY(c.y);\n annotateArcCommand(c, prevXAbs, prevYAbs);\n // p = cos(phi) * xv + sin(phi) * yv\n // dp = -sin(phi) * xv + cos(phi) * yv = 0\n const xRotRad = c.xRot / 180 * Math.PI;\n // points on ellipse for phi = 0° and phi = 90°\n const x0 = Math.cos(xRotRad) * c.rX;\n const y0 = Math.sin(xRotRad) * c.rX;\n const x90 = -Math.sin(xRotRad) * c.rY;\n const y90 = Math.cos(xRotRad) * c.rY;\n\n // annotateArcCommand returns phi1 and phi2 such that -180° < phi1 < 180° and phi2 is smaller or greater\n // depending on the sweep flag. Calculate phiMin, phiMax such that -180° < phiMin < 180° and phiMin < phiMax\n const [phiMin, phiMax] = c.phi1 < c.phi2 ?\n [c.phi1, c.phi2] :\n (-180 > c.phi2 ? [c.phi2 + 360, c.phi1 + 360] : [c.phi2, c.phi1]);\n const normalizeXiEta = ([xi, eta]: [number, number]) => {\n const phiRad = Math.atan2(eta, xi);\n const phi = phiRad * 180 / Math.PI;\n\n return phi < phiMin ? phi + 360 : phi;\n };\n // xi = cos(phi), eta = sin(phi)\n\n const xDerivRoots = intersectionUnitCircleLine(x90, -x0, 0).map(normalizeXiEta);\n for (const derivRoot of xDerivRoots) {\n if (derivRoot > phiMin && derivRoot < phiMax) {\n fixX(arcAt(c.cX, x0, x90, derivRoot));\n }\n }\n\n const yDerivRoots = intersectionUnitCircleLine(y90, -y0, 0).map(normalizeXiEta);\n for (const derivRoot of yDerivRoots) {\n if (derivRoot > phiMin && derivRoot < phiMax) {\n fixY(arcAt(c.cY, y0, y90, derivRoot));\n }\n }\n }\n return command;\n }) as any;\n\n f.minX = Infinity;\n f.maxX = -Infinity;\n f.minY = Infinity;\n f.maxY = -Infinity;\n return f;\n }\n}\n","import { SVGPathDataTransformer } from \"./SVGPathDataTransformer\";\nimport { TransformFunction } from \"./types\";\n\nexport abstract class TransformableSVG {\n round(x?: number) {\n return this.transform(SVGPathDataTransformer.ROUND(x));\n }\n\n toAbs() {\n return this.transform(SVGPathDataTransformer.TO_ABS());\n }\n\n toRel() {\n return this.transform(SVGPathDataTransformer.TO_REL());\n }\n\n normalizeHVZ(a?: boolean, b?: boolean, c?: boolean) {\n return this.transform(SVGPathDataTransformer.NORMALIZE_HVZ(a, b, c));\n }\n\n normalizeST() {\n return this.transform(SVGPathDataTransformer.NORMALIZE_ST());\n }\n\n qtToC() {\n return this.transform(SVGPathDataTransformer.QT_TO_C());\n }\n\n aToC() {\n return this.transform(SVGPathDataTransformer.A_TO_C());\n }\n\n sanitize(eps?: number) {\n return this.transform(SVGPathDataTransformer.SANITIZE(eps));\n }\n\n translate(x: number, y?: number) {\n return this.transform(SVGPathDataTransformer.TRANSLATE(x, y));\n }\n\n scale(x: number, y?: number) {\n return this.transform(SVGPathDataTransformer.SCALE(x, y));\n }\n\n rotate(a: number, x?: number, y?: number) {\n return this.transform(SVGPathDataTransformer.ROTATE(a, x, y));\n }\n\n matrix(a: number, b: number, c: number, d: number, e: number, f: number) {\n return this.transform(SVGPathDataTransformer.MATRIX(a, b, c, d, e, f));\n }\n\n skewX(a: number) {\n return this.transform(SVGPathDataTransformer.SKEW_X(a));\n }\n\n skewY(a: number) {\n return this.transform(SVGPathDataTransformer.SKEW_Y(a));\n }\n\n xSymmetry(xOffset?: number) {\n return this.transform(SVGPathDataTransformer.X_AXIS_SYMMETRY(xOffset));\n }\n\n ySymmetry(yOffset?: number) {\n return this.transform(SVGPathDataTransformer.Y_AXIS_SYMMETRY(yOffset));\n }\n\n annotateArcs() {\n return this.transform(SVGPathDataTransformer.ANNOTATE_ARCS());\n }\n\n abstract transform(transformFunction: TransformFunction): this;\n}\n","// Parse SVG PathData\n// http://www.w3.org/TR/SVG/paths.html#PathDataBNF\nimport { COMMAND_ARG_COUNTS, SVGPathData } from \"./SVGPathData\";\nimport { TransformableSVG } from \"./TransformableSVG\";\nimport { SVGCommand, TransformFunction } from \"./types\";\n// Private consts : Char groups\nconst isWhiteSpace = (c: string) =>\n \" \" === c || \"\\t\" === c || \"\\r\" === c || \"\\n\" === c;\nconst isDigit = (c: string) =>\n \"0\".charCodeAt(0) <= c.charCodeAt(0) && c.charCodeAt(0) <= \"9\".charCodeAt(0);\nconst COMMANDS = \"mMzZlLhHvVcCsSqQtTaA\";\n\nexport class SVGPathDataParser extends TransformableSVG {\n private curNumber: string = \"\";\n private curCommandType: SVGCommand[\"type\"] | -1 = -1;\n private curCommandRelative = false;\n private canParseCommandOrComma = true;\n private curNumberHasExp = false;\n private curNumberHasExpDigits = false;\n private curNumberHasDecimal = false;\n private curArgs: number[] = [];\n\n constructor() {\n super();\n }\n\n finish(commands: SVGCommand[] = []) {\n this.parse(\" \", commands);\n // Adding residual command\n if (0 !== this.curArgs.length || !this.canParseCommandOrComma) {\n throw new SyntaxError(\"Unterminated command at the path end.\");\n }\n return commands;\n }\n\n parse(str: string, commands: SVGCommand[] = []) {\n const finishCommand = (command: SVGCommand) => {\n commands.push(command);\n this.curArgs.length = 0;\n this.canParseCommandOrComma = true;\n };\n\n for (let i = 0; i < str.length; i++) {\n const c = str[i];\n // White spaces parsing\n const isAArcFlag = this.curCommandType === SVGPathData.ARC &&\n (this.curArgs.length === 3 || this.curArgs.length === 4) &&\n this.curNumber.length === 1 &&\n (this.curNumber === \"0\" || this.curNumber === \"1\");\n const isEndingDigit = isDigit(c) && (\n (this.curNumber === \"0\" && c === \"0\") ||\n isAArcFlag\n );\n\n if (\n isDigit(c) &&\n !isEndingDigit\n ) {\n this.curNumber += c;\n this.curNumberHasExpDigits = this.curNumberHasExp;\n continue;\n }\n if (\"e\" === c || \"E\" === c) {\n this.curNumber += c;\n this.curNumberHasExp = true;\n continue;\n }\n if (\n (\"-\" === c || \"+\" === c) &&\n this.curNumberHasExp &&\n !this.curNumberHasExpDigits\n ) {\n this.curNumber += c;\n continue;\n }\n // if we already have a \".\", it means we are starting a new number\n if (\".\" === c && !this.curNumberHasExp && !this.curNumberHasDecimal && !isAArcFlag) {\n this.curNumber += c;\n this.curNumberHasDecimal = true;\n continue;\n }\n\n // New number\n if (this.curNumber && -1 !== this.curCommandType) {\n const val = Number(this.curNumber);\n if (isNaN(val)) {\n throw new SyntaxError(`Invalid number ending at ${i}`);\n }\n if (this.curCommandType === SVGPathData.ARC) {\n if (0 === this.curArgs.length || 1 === this.curArgs.length) {\n if (0 > val) {\n throw new SyntaxError(\n `Expected positive number, got \"${val}\" at index \"${i}\"`,\n );\n }\n } else if (3 === this.curArgs.length || 4 === this.curArgs.length) {\n if (\"0\" !== this.curNumber && \"1\" !== this.curNumber) {\n throw new SyntaxError(\n `Expected a flag, got \"${this.curNumber}\" at index \"${i}\"`,\n );\n }\n }\n }\n this.curArgs.push(val);\n if (this.curArgs.length === COMMAND_ARG_COUNTS[this.curCommandType]) {\n if (SVGPathData.HORIZ_LINE_TO === this.curCommandType) {\n finishCommand({\n type: SVGPathData.HORIZ_LINE_TO,\n relative: this.curCommandRelative,\n x: val,\n });\n } else if (SVGPathData.VERT_LINE_TO === this.curCommandType) {\n finishCommand({\n type: SVGPathData.VERT_LINE_TO,\n relative: this.curCommandRelative,\n y: val,\n });\n // Move to / line to / smooth quadratic curve to commands (x, y)\n } else if (\n this.curCommandType === SVGPathData.MOVE_TO ||\n this.curCommandType === SVGPathData.LINE_TO ||\n this.curCommandType === SVGPathData.SMOOTH_QUAD_TO\n ) {\n finishCommand({\n type: this.curCommandType,\n relative: this.curCommandRelative,\n x: this.curArgs[0],\n y: this.curArgs[1],\n } as SVGCommand);\n // Switch to line to state\n if (SVGPathData.MOVE_TO === this.curCommandType) {\n this.curCommandType = SVGPathData.LINE_TO;\n }\n } else if (this.curCommandType === SVGPathData.CURVE_TO) {\n finishCommand({\n type: SVGPathData.CURVE_TO,\n relative: this.curCommandRelative,\n x1: this.curArgs[0],\n y1: this.curArgs[1],\n x2: this.curArgs[2],\n y2: this.curArgs[3],\n x: this.curArgs[4],\n y: this.curArgs[5],\n });\n } else if (this.curCommandType === SVGPathData.SMOOTH_CURVE_TO) {\n finishCommand({\n type: SVGPathData.SMOOTH_CURVE_TO,\n relative: this.curCommandRelative,\n x2: this.curArgs[0],\n y2: this.curArgs[1],\n x: this.curArgs[2],\n y: this.curArgs[3],\n });\n } else if (this.curCommandType === SVGPathData.QUAD_TO) {\n finishCommand({\n type: SVGPathData.QUAD_TO,\n relative: this.curCommandRelative,\n x1: this.curArgs[0],\n y1: this.curArgs[1],\n x: this.curArgs[2],\n y: this.curArgs[3],\n });\n } else if (this.curCommandType === SVGPathData.ARC) {\n finishCommand({\n type: SVGPathData.ARC,\n relative: this.curCommandRelative,\n rX: this.curArgs[0],\n rY: this.curArgs[1],\n xRot: this.curArgs[2],\n lArcFlag: this.curArgs[3] as 0 | 1,\n sweepFlag: this.curArgs[4] as 0 | 1,\n x: this.curArgs[5],\n y: this.curArgs[6],\n });\n }\n }\n this.curNumber = \"\";\n this.curNumberHasExpDigits = false;\n this.curNumberHasExp = false;\n this.curNumberHasDecimal = false;\n this.canParseCommandOrComma = true;\n }\n // Continue if a white space or a comma was detected\n if (isWhiteSpace(c)) {\n continue;\n }\n if (\",\" === c && this.canParseCommandOrComma) {\n // L 0,0, H is not valid:\n this.canParseCommandOrComma = false;\n continue;\n }\n // if a sign is detected, then parse the new number\n if (\"+\" === c || \"-\" === c || \".\" === c) {\n this.curNumber = c;\n this.curNumberHasDecimal = \".\" === c;\n continue;\n }\n // if a 0 is detected, then parse the new number\n if (isEndingDigit) {\n this.curNumber = c;\n this.curNumberHasDecimal = false;\n continue;\n }\n\n // Adding residual command\n if (0 !== this.curArgs.length) {\n throw new SyntaxError(`Unterminated command at index ${i}.`);\n }\n if (!this.canParseCommandOrComma) {\n throw new SyntaxError(\n `Unexpected character \"${c}\" at index ${i}. Command cannot follow comma`,\n );\n }\n this.canParseCommandOrComma = false;\n // Detecting the next command\n if (\"z\" === c || \"Z\" === c) {\n commands.push({\n type: SVGPathData.CLOSE_PATH,\n });\n this.canParseCommandOrComma = true;\n this.curCommandType = -1;\n continue;\n // Horizontal move to command\n } else if (\"h\" === c || \"H\" === c) {\n this.curCommandType = SVGPathData.HORIZ_LINE_TO;\n this.curCommandRelative = \"h\" === c;\n // Vertical move to command\n } else if (\"v\" === c || \"V\" === c) {\n this.curCommandType = SVGPathData.VERT_LINE_TO;\n this.curCommandRelative = \"v\" === c;\n // Move to command\n } else if (\"m\" === c || \"M\" === c) {\n this.curCommandType = SVGPathData.MOVE_TO;\n this.curCommandRelative = \"m\" === c;\n // Line to command\n } else if (\"l\" === c || \"L\" === c) {\n this.curCommandType = SVGPathData.LINE_TO;\n this.curCommandRelative = \"l\" === c;\n // Curve to command\n } else if (\"c\" === c || \"C\" === c) {\n this.curCommandType = SVGPathData.CURVE_TO;\n this.curCommandRelative = \"c\" === c;\n // Smooth curve to command\n } else if (\"s\" === c || \"S\" === c) {\n this.curCommandType = SVGPathData.SMOOTH_CURVE_TO;\n this.curCommandRelative = \"s\" === c;\n // Quadratic bezier curve to command\n } else if (\"q\" === c || \"Q\" === c) {\n this.curCommandType = SVGPathData.QUAD_TO;\n this.curCommandRelative = \"q\" === c;\n // Smooth quadratic bezier curve to command\n } else if (\"t\" === c || \"T\" === c) {\n this.curCommandType = SVGPathData.SMOOTH_QUAD_TO;\n this.curCommandRelative = \"t\" === c;\n // Elliptic arc command\n } else if (\"a\" === c || \"A\" === c) {\n this.curCommandType = SVGPathData.ARC;\n this.curCommandRelative = \"a\" === c;\n } else {\n throw new SyntaxError(`Unexpected character \"${c}\" at index ${i}.`);\n }\n }\n return commands;\n }\n /**\n * Return a wrapper around this parser which applies the transformation on parsed commands.\n */\n transform(transform: TransformFunction) {\n const result = Object.create(this, {\n parse: {\n value(chunk: string, commands: SVGCommand[] = []) {\n const parsedCommands = Object.getPrototypeOf(this).parse.call(\n this,\n chunk,\n );\n for (const c of parsedCommands) {\n const cT = transform(c);\n if (Array.isArray(cT)) {\n commands.push(...cT);\n } else {\n commands.push(cT);\n }\n }\n return commands;\n },\n },\n });\n return result as this;\n }\n}\n","import { encodeSVGPath } from \"./SVGPathDataEncoder\";\nimport { SVGPathDataParser } from \"./SVGPathDataParser\";\nimport { SVGPathDataTransformer } from \"./SVGPathDataTransformer\";\nimport { TransformableSVG } from \"./TransformableSVG\";\nimport { SVGCommand } from \"./types\";\n\nexport class SVGPathData extends TransformableSVG {\n commands: SVGCommand[];\n constructor(content: string | SVGCommand[]) {\n super();\n if (\"string\" === typeof content) {\n this.commands = SVGPathData.parse(content);\n } else {\n this.commands = content;\n }\n }\n\n encode() {\n return SVGPathData.encode(this.commands);\n }\n\n getBounds() {\n const boundsTransform = SVGPathDataTransformer.CALCULATE_BOUNDS();\n\n this.transform(boundsTransform);\n return boundsTransform;\n }\n\n transform(\n transformFunction: (input: SVGCommand) => SVGCommand | SVGCommand[],\n ) {\n const newCommands = [];\n\n for (const command of this.commands) {\n const transformedCommand = transformFunction(command);\n\n if (Array.isArray(transformedCommand)) {\n newCommands.push(...transformedCommand);\n } else {\n newCommands.push(transformedCommand);\n }\n }\n this.commands = newCommands;\n return this;\n }\n\n static encode(commands: SVGCommand[]) {\n return encodeSVGPath(commands);\n }\n\n static parse(path: string) {\n const parser = new SVGPathDataParser();\n const commands: SVGCommand[] = [];\n parser.parse(path, commands);\n parser.finish(commands);\n return commands;\n }\n\n static readonly CLOSE_PATH: 1 = 1;\n static readonly MOVE_TO: 2 = 2;\n static readonly HORIZ_LINE_TO: 4 = 4;\n static readonly VERT_LINE_TO: 8 = 8;\n static readonly LINE_TO: 16 = 16;\n static readonly CURVE_TO: 32 = 32;\n static readonly SMOOTH_CURVE_TO: 64 = 64;\n static readonly QUAD_TO: 128 = 128;\n static readonly SMOOTH_QUAD_TO: 256 = 256;\n static readonly ARC: 512 = 512;\n static readonly LINE_COMMANDS = SVGPathData.LINE_TO | SVGPathData.HORIZ_LINE_TO | SVGPathData.VERT_LINE_TO;\n static readonly DRAWING_COMMANDS = SVGPathData.HORIZ_LINE_TO | SVGPathData.VERT_LINE_TO | SVGPathData.LINE_TO |\n SVGPathData.CURVE_TO | SVGPathData.SMOOTH_CURVE_TO | SVGPathData.QUAD_TO |\n SVGPathData.SMOOTH_QUAD_TO | SVGPathData.ARC;\n}\n\nexport const COMMAND_ARG_COUNTS = {\n [SVGPathData.MOVE_TO]: 2,\n [SVGPathData.LINE_TO]: 2,\n [SVGPathData.HORIZ_LINE_TO]: 1,\n [SVGPathData.VERT_LINE_TO]: 1,\n [SVGPathData.CLOSE_PATH]: 0,\n [SVGPathData.QUAD_TO]: 4,\n [SVGPathData.SMOOTH_QUAD_TO]: 2,\n [SVGPathData.CURVE_TO]: 6,\n [SVGPathData.SMOOTH_CURVE_TO]: 4,\n [SVGPathData.ARC]: 7,\n};\n\nexport {encodeSVGPath} from \"./SVGPathDataEncoder\";\nexport {SVGPathDataParser} from \"./SVGPathDataParser\";\nexport {SVGPathDataTransformer} from \"./SVGPathDataTransformer\";\n","import { Vector2 } from '@babylonjs/core/Maths/math';\r\nimport { SVGPathData } from 'svg-pathdata';\r\nimport {\r\n CommandA,\r\n CommandC,\r\n CommandH,\r\n CommandL,\r\n CommandM,\r\n CommandQ,\r\n CommandS,\r\n CommandT,\r\n CommandV,\r\n CommandZ,\r\n SVGCommand,\r\n} from 'svg-pathdata/lib/types';\r\n\r\nexport type CommandType = SVGCommand['type'];\r\n// export type Command = { type: CommandType } & Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit &\r\n// Omit;\r\n\r\nexport type Command =\r\n | CommandA\r\n | CommandC\r\n | CommandH\r\n | CommandL\r\n | CommandM\r\n | CommandQ\r\n | CommandS\r\n | CommandT\r\n | CommandV\r\n | CommandZ;\r\n\r\nexport class PathParser extends SVGPathData {\r\n control: Vector2 = new Vector2(0, 0);\r\n start: Vector2 = new Vector2(0, 0);\r\n current: Vector2 = new Vector2(0, 0);\r\n command: Command | null = null;\r\n override readonly commands: Command[] /* Babel fix: */ = this.commands;\r\n private i = -1;\r\n private previousCommand: Command | null = null;\r\n private points: Vector2[] = [];\r\n private angles: Array = [];\r\n\r\n constructor(path: string) {\r\n super(\r\n path\r\n // Fix spaces after signs.\r\n .replace(/([+\\-.])\\s+/gm, '$1')\r\n // Remove invalid part.\r\n .replace(/[^MmZzLlHhVvCcSsQqTtAae\\d\\s.,+-].*/g, '')\r\n );\r\n }\r\n\r\n reset() {\r\n this.i = -1;\r\n this.command = null;\r\n this.previousCommand = null;\r\n this.start = new Vector2(0, 0);\r\n this.control = new Vector2(0, 0);\r\n this.current = new Vector2(0, 0);\r\n this.points = [];\r\n this.angles = [];\r\n }\r\n\r\n isEnd() {\r\n const { i, commands } = this;\r\n\r\n return i >= commands.length - 1;\r\n }\r\n\r\n next() {\r\n const command = this.commands[++this.i];\r\n\r\n this.previousCommand = this.command;\r\n this.command = command;\r\n\r\n return command;\r\n }\r\n\r\n getPoint(xProp = 'x', yProp = 'y') {\r\n if (this.command) {\r\n const x = parseInt(xProp);\r\n const y = parseInt(yProp);\r\n const point = new Vector2(x, y);\r\n return this.makeAbsolute(point);\r\n }\r\n }\r\n\r\n getAsControlPoint(xProp?: string, yProp?: string) {\r\n const point = this.getPoint(xProp, yProp);\r\n if (point) {\r\n this.control = point;\r\n }\r\n\r\n return point;\r\n }\r\n\r\n getAsCurrentPoint(xProp?: string, yProp?: string) {\r\n const point = this.getPoint(xProp, yProp);\r\n if (point) {\r\n this.current = point;\r\n }\r\n\r\n return point;\r\n }\r\n\r\n getReflectedControlPoint() {\r\n let previousCommand = null;\r\n if (this.previousCommand) {\r\n previousCommand = this.previousCommand.type;\r\n }\r\n\r\n if (\r\n previousCommand !== SVGPathData.CURVE_TO &&\r\n previousCommand !== SVGPathData.SMOOTH_CURVE_TO &&\r\n previousCommand !== SVGPathData.QUAD_TO &&\r\n previousCommand !== SVGPathData.SMOOTH_QUAD_TO\r\n ) {\r\n return this.current;\r\n }\r\n\r\n // reflect point\r\n const {\r\n current: { x: cx, y: cy },\r\n control: { x: ox, y: oy },\r\n } = this;\r\n const point = new Vector2(2 * cx - ox, 2 * cy - oy);\r\n\r\n return point;\r\n }\r\n\r\n makeAbsolute(point: Vector2) {\r\n if (this.command && 'relative' in this.command && this.command.relative) {\r\n const { x, y } = this.current;\r\n\r\n point.x += x;\r\n point.y += y;\r\n }\r\n\r\n return point;\r\n }\r\n\r\n addMarker(point: Vector2, from?: Vector2, priorTo?: Vector2) {\r\n const { points, angles } = this;\r\n\r\n // if the last angle isn't filled in because we didn't have this point yet ...\r\n if (priorTo && angles.length > 0 && !angles[angles.length - 1]) {\r\n angles[angles.length - 1] = this.angleBetweenPoints(points[points.length - 1], priorTo);\r\n }\r\n\r\n this.addMarkerAngle(point, from ? this.angleBetweenPoints(from, point) : null);\r\n }\r\n\r\n addMarkerAngle(point: Vector2, angle: number | null) {\r\n this.points.push(point);\r\n this.angles.push(angle);\r\n }\r\n\r\n angleBetweenPoints(point1: Vector2, point2: Vector2) {\r\n return Math.atan2(point2.y - point1.y, point2.x - point1.x);\r\n }\r\n\r\n getMarkerPoints() {\r\n return this.points;\r\n }\r\n\r\n getMarkerAngles() {\r\n const { angles } = this;\r\n const len = angles.length;\r\n\r\n for (let i = 0; i < len; i++) {\r\n if (!angles[i]) {\r\n for (let j = i + 1; j < len; j++) {\r\n if (angles[j]) {\r\n angles[i] = angles[j];\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return angles;\r\n }\r\n}\r\n","import {\r\n eSketchPathType,\r\n Kb3dManager,\r\n KbVector,\r\n SketchControlPoint,\r\n SketchNode,\r\n SketchPath,\r\n Token,\r\n} from '@models/classes';\r\nimport {\r\n CommandA,\r\n CommandC,\r\n CommandH,\r\n CommandL,\r\n CommandM,\r\n CommandQ,\r\n CommandS,\r\n CommandT,\r\n CommandV,\r\n} from 'svg-pathdata/lib/types';\r\nimport { PathParser } from './path-parser';\r\nimport { projectOnNodeAxis } from './util';\r\n\r\nexport interface Layer {\r\n segments: Segment[];\r\n boundingbox: number[];\r\n holechildren: any[];\r\n isholepath: boolean;\r\n}\r\n\r\nexport interface Segment {\r\n type: 'L' | 'M' | 'C' | 'S' | 'Q' | 'T' | 'Z';\r\n x1: number;\r\n y1: number;\r\n x2: number;\r\n y2: number;\r\n x3?: number;\r\n y3?: number;\r\n}\r\n\r\nexport class PathHandler {\r\n private pathParser: PathParser;\r\n private nodeManager: Kb3dManager;\r\n private _currentPosition: KbVector | undefined;\r\n private initialPosition = new KbVector(0, 0, 0);\r\n\r\n get currentPosition() {\r\n return this._currentPosition || this.initialPosition;\r\n }\r\n\r\n readonly stubPath = { id: 'stub' } as SketchPath;\r\n\r\n constructor(private sketchNode: SketchNode, private scaleDivider: number, nodeManager: Kb3dManager) {\r\n this.nodeManager = nodeManager;\r\n }\r\n\r\n parseTrace(commands: Segment[]) {\r\n const newPaths: SketchPath[] = [];\r\n if (!this.sketchNode || commands.length === 0) {\r\n return [];\r\n }\r\n\r\n const first = commands[0];\r\n\r\n if (first.type !== 'M') {\r\n this.pathM(newPaths, {\r\n type: PathParser.MOVE_TO,\r\n relative: false,\r\n x: first.x1,\r\n y: first.y1,\r\n });\r\n }\r\n\r\n for (let i = 0; i < commands.length; i++) {\r\n const command = commands[i];\r\n const commonPathCommand = {\r\n relative: false,\r\n x: command.x2,\r\n y: command.y2,\r\n x1: command.x3 || -1,\r\n y1: command.y3 || -1,\r\n };\r\n switch (command.type) {\r\n case 'M': {\r\n const pathCommand: CommandM = {\r\n ...commonPathCommand,\r\n type: PathParser.MOVE_TO,\r\n };\r\n this.pathM(newPaths, pathCommand);\r\n break;\r\n }\r\n case 'L': {\r\n const pathCommand: CommandL = {\r\n ...commonPathCommand,\r\n type: PathParser.LINE_TO,\r\n };\r\n this.pathL(newPaths, pathCommand);\r\n break;\r\n }\r\n case 'Q': {\r\n if (!command.x3 || !command.y3) {\r\n console.warn('Q command without x3 or y3');\r\n } else {\r\n const pathCommand: CommandQ = {\r\n ...commonPathCommand,\r\n type: PathParser.QUAD_TO,\r\n x: command.x3,\r\n y: command.y3,\r\n x1: command.x2,\r\n y1: command.y2,\r\n };\r\n this.pathQ(newPaths, pathCommand);\r\n }\r\n break;\r\n }\r\n /** imagetracer does not return C, S, or T paths\r\n * \r\n case 'C': {\r\n const pathCommand: CommandC = {\r\n ...commonPathCommand,\r\n type: PathParser.CURVE_TO,\r\n };\r\n this.pathC(newPaths, pathCommand);\r\n break;\r\n }\r\n case 'S': {\r\n const pathCommand: CommandS = {\r\n ...commonPathCommand,\r\n type: PathParser.SMOOTH_CURVE_TO,\r\n };\r\n this.pathS(newPaths, pathCommand);\r\n break;\r\n }\r\n case 'T': {\r\n const pathCommand: CommandT = {\r\n ...commonPathCommand,\r\n type: PathParser.SMOOTH_QUAD_TO,\r\n };\r\n this.pathT(newPaths, pathCommand);\r\n break;\r\n }\r\n */\r\n case 'Z': {\r\n this.pathZ(newPaths);\r\n }\r\n }\r\n }\r\n\r\n return this.reprojectPaths(newPaths.filter(path => path !== this.stubPath));\r\n }\r\n\r\n parsePath(path: string) {\r\n this.pathParser = new PathParser(path);\r\n this.pathParser.reset();\r\n\r\n if (!this.sketchNode) {\r\n return [];\r\n }\r\n const newPaths: SketchPath[] = [];\r\n\r\n while (!this.pathParser.isEnd()) {\r\n switch (this.pathParser.next().type) {\r\n case PathParser.MOVE_TO:\r\n this.pathM(newPaths);\r\n break;\r\n\r\n case PathParser.LINE_TO:\r\n this.pathL(newPaths);\r\n break;\r\n\r\n case PathParser.HORIZ_LINE_TO:\r\n this.pathL(newPaths);\r\n break;\r\n\r\n case PathParser.VERT_LINE_TO:\r\n this.pathL(newPaths);\r\n break;\r\n\r\n case PathParser.CURVE_TO:\r\n this.pathC(newPaths);\r\n break;\r\n\r\n case PathParser.SMOOTH_CURVE_TO:\r\n this.pathS(newPaths);\r\n break;\r\n\r\n case PathParser.QUAD_TO:\r\n this.pathQ(newPaths);\r\n break;\r\n\r\n case PathParser.SMOOTH_QUAD_TO:\r\n this.pathT(newPaths);\r\n break;\r\n\r\n case PathParser.ARC:\r\n console.warn('ARC not implemented');\r\n this.pathA(newPaths);\r\n break;\r\n\r\n case PathParser.CLOSE_PATH:\r\n this.pathZ(newPaths);\r\n break;\r\n\r\n default:\r\n }\r\n }\r\n\r\n return this.reprojectPaths(newPaths.filter(path => path !== this.stubPath));\r\n }\r\n\r\n protected reprojectPaths(paths: SketchPath[]) {\r\n paths.forEach(path => {\r\n path.controlPoints.forEach(cp => {\r\n cp.position = projectOnNodeAxis(this.sketchNode, cp.position.x, cp.position.y);\r\n cp.direction = projectOnNodeAxis(this.sketchNode, cp.direction.x, cp.direction.y);\r\n if (cp.direction2) {\r\n cp.direction2 = projectOnNodeAxis(this.sketchNode, cp.direction2.x, cp.direction2.y);\r\n }\r\n });\r\n });\r\n\r\n return paths;\r\n }\r\n\r\n protected checkIfNewPathNeeded(paths: SketchPath[], desiredPathType: eSketchPathType) {\r\n let activePath = paths[paths.length - 1];\r\n if (!activePath || activePath === this.stubPath || activePath.type !== desiredPathType) {\r\n if (activePath === this.stubPath) {\r\n paths.pop();\r\n }\r\n\r\n activePath = this.addNewPath(paths, desiredPathType);\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n if (!this._currentPosition) {\r\n console.warn('new path created with no moveto command');\r\n }\r\n newControlPoint.position = this.currentPosition;\r\n\r\n activePath.controlPoints.push(newControlPoint);\r\n newControlPoint.direction2 = new KbVector(0, 0, 0);\r\n }\r\n\r\n return activePath;\r\n }\r\n\r\n protected pathM(paths: SketchPath[], command?: CommandM) {\r\n const { pathParser } = this;\r\n let x = 0;\r\n let y = 0;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandM;\r\n }\r\n if (command) {\r\n x = command.x / this.scaleDivider;\r\n y = (command.y * -1) / this.scaleDivider;\r\n\r\n if (command.relative && this.currentPosition) {\r\n x = x + this.currentPosition.x;\r\n y = y + this.currentPosition.y;\r\n }\r\n\r\n this._currentPosition = new KbVector(x, y, 0);\r\n this.initialPosition = this._currentPosition;\r\n paths.push(this.stubPath);\r\n }\r\n }\r\n\r\n protected pathL(paths: SketchPath[], command?: CommandL | CommandH | CommandV) {\r\n const { pathParser } = this;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandL;\r\n }\r\n if (command) {\r\n let x: number | undefined;\r\n let y: number | undefined;\r\n\r\n //these 2 if checks need to happen because pathL could be a horizontal or vertical line and therefore not have one of the coordinates.\r\n if ('x' in command) {\r\n x = command.x / this.scaleDivider;\r\n }\r\n if ('y' in command) {\r\n y = (command.y * -1) / this.scaleDivider;\r\n }\r\n\r\n const activePath = this.checkIfNewPathNeeded(paths, eSketchPathType.points);\r\n\r\n if (command.relative && activePath) {\r\n if (x !== undefined) {\r\n x = x + this.currentPosition.x;\r\n }\r\n if (y !== undefined) {\r\n y = y + this.currentPosition.y;\r\n }\r\n }\r\n if (x === undefined) {\r\n // V case\r\n x = this.currentPosition.x || 0;\r\n }\r\n if (y === undefined) {\r\n // H case\r\n y = this.currentPosition.y || 0;\r\n }\r\n\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(x, y, 0);\r\n this._currentPosition = newControlPoint.position;\r\n activePath.controlPoints.push(newControlPoint);\r\n }\r\n }\r\n\r\n protected pathC(paths: SketchPath[], command?: CommandC) {\r\n const { pathParser } = this;\r\n let x = 0;\r\n let y = 0;\r\n let x1 = 0;\r\n let y1 = 0;\r\n let x2 = 0;\r\n let y2 = 0;\r\n let lastControlPoint = undefined;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandC;\r\n }\r\n if (command) {\r\n x = command.x / this.scaleDivider;\r\n y = (command.y * -1) / this.scaleDivider;\r\n x1 = command.x1 / this.scaleDivider;\r\n y1 = (command.y1 * -1) / this.scaleDivider;\r\n x2 = command.x2 / this.scaleDivider;\r\n y2 = (command.y2 * -1) / this.scaleDivider;\r\n\r\n const activePath = this.checkIfNewPathNeeded(paths, eSketchPathType.cubicBezier);\r\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\r\n\r\n if (command.relative) {\r\n x = x + this.currentPosition.x;\r\n y = y + this.currentPosition.y;\r\n x1 = x1 + this.currentPosition.x;\r\n y1 = y1 + this.currentPosition.y;\r\n x2 = x2 + this.currentPosition.x;\r\n y2 = y2 + this.currentPosition.y;\r\n }\r\n\r\n if (lastControlPoint) {\r\n lastControlPoint.direction = new KbVector(\r\n x1 - lastControlPoint.position.x,\r\n y1 - lastControlPoint.position.y,\r\n 0\r\n );\r\n }\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(x, y, 0);\r\n this._currentPosition = newControlPoint.position;\r\n newControlPoint.direction2 = new KbVector(x2 - x, y2 - y, 0);\r\n activePath.controlPoints.push(newControlPoint);\r\n }\r\n }\r\n\r\n protected pathS(paths: SketchPath[], command?: CommandS) {\r\n const { pathParser } = this;\r\n let x = 0;\r\n let y = 0;\r\n let x2 = 0;\r\n let y2 = 0;\r\n let lastControlPoint = undefined;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandS;\r\n }\r\n if (command) {\r\n x = command.x / this.scaleDivider;\r\n y = (command.y * -1) / this.scaleDivider;\r\n x2 = command.x2 / this.scaleDivider;\r\n y2 = (command.y2 * -1) / this.scaleDivider;\r\n\r\n const activePath = this.checkIfNewPathNeeded(paths, eSketchPathType.cubicBezier);\r\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\r\n lastControlPoint.direction = new KbVector(0, 0, 0);\r\n\r\n if (command.relative) {\r\n x = x + this.currentPosition.x;\r\n y = y + this.currentPosition.y;\r\n x2 = x2 + this.currentPosition.x;\r\n y2 = y2 + this.currentPosition.y;\r\n }\r\n\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(x, y, 0);\r\n if (lastControlPoint && lastControlPoint.direction2) {\r\n lastControlPoint.direction = lastControlPoint.direction2?.scale(-1);\r\n newControlPoint.direction2 = new KbVector(x2 - x, y2 - y, 0);\r\n }\r\n this._currentPosition = newControlPoint.position;\r\n activePath.controlPoints.push(newControlPoint);\r\n\r\n return activePath;\r\n }\r\n }\r\n\r\n protected pathQ(paths: SketchPath[], command?: CommandQ) {\r\n const { pathParser } = this;\r\n let x = 0;\r\n let y = 0;\r\n let x1 = 0;\r\n let y1 = 0;\r\n let lastControlPoint = undefined;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandQ;\r\n }\r\n if (command) {\r\n x = command.x / this.scaleDivider;\r\n y = (command.y * -1) / this.scaleDivider;\r\n x1 = command.x1 / this.scaleDivider;\r\n y1 = (command.y1 * -1) / this.scaleDivider;\r\n\r\n const activePath = this.checkIfNewPathNeeded(paths, eSketchPathType.quadraticBezier);\r\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\r\n\r\n if (command.relative) {\r\n x = x + this.currentPosition.x;\r\n y = y + this.currentPosition.y;\r\n x1 = x1 + this.currentPosition.x;\r\n y1 = y1 + this.currentPosition.y;\r\n }\r\n\r\n if (lastControlPoint) {\r\n lastControlPoint.direction = new KbVector(\r\n x1 - lastControlPoint.position.x,\r\n y1 - lastControlPoint.position.y,\r\n 0\r\n );\r\n }\r\n\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(x, y, 0);\r\n this._currentPosition = newControlPoint.position;\r\n activePath.controlPoints.push(newControlPoint);\r\n }\r\n }\r\n\r\n protected pathT(paths: SketchPath[], command?: CommandT) {\r\n const { pathParser } = this;\r\n let x = 0;\r\n let y = 0;\r\n let lastControlPoint = undefined;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandT;\r\n }\r\n if (command) {\r\n x = command.x / this.scaleDivider;\r\n y = (command.y * -1) / this.scaleDivider;\r\n\r\n const activePath = this.checkIfNewPathNeeded(paths, eSketchPathType.quadraticBezier);\r\n lastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 1];\r\n lastControlPoint.direction = new KbVector(0, 0, 0);\r\n\r\n if (command.relative) {\r\n x = x + this.currentPosition.x;\r\n y = y + this.currentPosition.y;\r\n }\r\n\r\n const secondLastControlPoint = activePath.controlPoints[activePath.controlPoints.length - 2];\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(x, y, 0);\r\n this._currentPosition = newControlPoint.position;\r\n activePath.controlPoints.push(newControlPoint);\r\n if (lastControlPoint && secondLastControlPoint && secondLastControlPoint) {\r\n lastControlPoint.direction = this.calculateReflection(\r\n secondLastControlPoint.direction,\r\n secondLastControlPoint,\r\n lastControlPoint\r\n );\r\n }\r\n }\r\n }\r\n\r\n //Path A needs further implementing\r\n protected pathA(paths: SketchPath[], command?: CommandA) {\r\n const { pathParser } = this;\r\n\r\n if (!command && pathParser.command) {\r\n command = pathParser.command as CommandA;\r\n }\r\n if (command) {\r\n // const cX = command.cX;\r\n // const cY = command.cY;\r\n // const rX = command.rX;\r\n // const rY = command.rY;\r\n let x = command.x;\r\n let y = command.y;\r\n if (command.relative) {\r\n x = x + this.currentPosition.x;\r\n y = y + this.currentPosition.y;\r\n }\r\n // const xAxisRotation = command.xRot;\r\n // const largeArcFlag = command.lArcFlag;\r\n // const sweepFlag = command.sweepFlag;\r\n\r\n this._currentPosition = new KbVector(x, y, 0);\r\n }\r\n }\r\n\r\n protected pathZ(paths: SketchPath[]) {\r\n const activePath = this.checkIfNewPathNeeded(paths, eSketchPathType.points);\r\n\r\n const x = this.initialPosition.x;\r\n const y = this.initialPosition.y;\r\n\r\n const newControlPoint = this.nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(x, y, 0);\r\n this._currentPosition = undefined;\r\n activePath.controlPoints.push(newControlPoint);\r\n\r\n return activePath;\r\n }\r\n\r\n protected addNewPath(paths: SketchPath[], pathType?: eSketchPathType) {\r\n const newPath = this.nodeManager.create(Token.SketchPath);\r\n newPath.name = 'Path';\r\n newPath._expanded = true;\r\n paths.push(newPath);\r\n\r\n if (pathType) {\r\n newPath.type = pathType;\r\n }\r\n\r\n return newPath;\r\n }\r\n\r\n protected calculateReflection(\r\n vector: KbVector,\r\n controlPoint: SketchControlPoint,\r\n controlPoint2: SketchControlPoint\r\n ) {\r\n const n = controlPoint2.position.subtract(controlPoint.position).normalize();\r\n return vector.subtract(n.scale(2 * vector.dotProduct(n))).scale(-1);\r\n }\r\n}\r\n","const VERSION_NUMBER = \"0.2.1\";\nconst PATHSCAN_COMBINED_LOOKUP = [\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]],\n [[0, 1, 0, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [0, 2, -1, 0]],\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [0, 1, 0, -1], [0, 0, 1, 0]],\n [[0, 0, 1, 0], [-1, -1, -1, -1], [0, 2, -1, 0], [-1, -1, -1, -1]],\n [[-1, -1, -1, -1], [0, 0, 1, 0], [0, 3, 0, 1], [-1, -1, -1, -1]],\n [[13, 3, 0, 1], [13, 2, -1, 0], [7, 1, 0, -1], [7, 0, 1, 0]],\n [[-1, -1, -1, -1], [0, 1, 0, -1], [-1, -1, -1, -1], [0, 3, 0, 1]],\n [[0, 3, 0, 1], [0, 2, -1, 0], [-1, -1, -1, -1], [-1, -1, -1, -1]],\n [[0, 3, 0, 1], [0, 2, -1, 0], [-1, -1, -1, -1], [-1, -1, -1, -1]],\n [[-1, -1, -1, -1], [0, 1, 0, -1], [-1, -1, -1, -1], [0, 3, 0, 1]],\n [[11, 1, 0, -1], [14, 0, 1, 0], [14, 3, 0, 1], [11, 2, -1, 0]],\n [[-1, -1, -1, -1], [0, 0, 1, 0], [0, 3, 0, 1], [-1, -1, -1, -1]],\n [[0, 0, 1, 0], [-1, -1, -1, -1], [0, 2, -1, 0], [-1, -1, -1, -1]],\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [0, 1, 0, -1], [0, 0, 1, 0]],\n [[0, 1, 0, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [0, 2, -1, 0]],\n [[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]]\n];\nconst SPECPALETTE = [\n { r: 0, g: 0, b: 0, a: 255 },\n { r: 128, g: 128, b: 128, a: 255 },\n { r: 0, g: 0, b: 128, a: 255 },\n { r: 64, g: 64, b: 128, a: 255 },\n { r: 192, g: 192, b: 192, a: 255 },\n { r: 255, g: 255, b: 255, a: 255 },\n { r: 128, g: 128, b: 192, a: 255 },\n { r: 0, g: 0, b: 192, a: 255 },\n { r: 128, g: 0, b: 0, a: 255 },\n { r: 128, g: 64, b: 64, a: 255 },\n { r: 128, g: 0, b: 128, a: 255 },\n { r: 168, g: 168, b: 168, a: 255 },\n { r: 192, g: 128, b: 128, a: 255 },\n { r: 192, g: 0, b: 0, a: 255 },\n { r: 255, g: 255, b: 255, a: 255 },\n { r: 0, g: 128, b: 0, a: 255 }\n];\nconst GKS = [\n [0.27901, 0.44198, 0.27901],\n [0.135336, 0.228569, 0.272192, 0.228569, 0.135336],\n [0.086776, 0.136394, 0.178908, 0.195843, 0.178908, 0.136394, 0.086776],\n [0.063327, 0.093095, 0.122589, 0.144599, 0.152781, 0.144599, 0.122589, 0.093095, 0.063327],\n [0.049692, 0.069304, 0.089767, 0.107988, 0.120651, 0.125194, 0.120651, 0.107988, 0.089767, 0.069304, 0.049692]\n];\n\nconst OPTION_PRESETS = {\n default: {\n corsenabled: false,\n ltres: 1,\n qtres: 1,\n pathomit: 8,\n rightangleenhance: true,\n colorsampling: 2,\n numberofcolors: 16,\n mincolorratio: 0,\n colorquantcycles: 3,\n layering: 0,\n strokewidth: 1,\n linefilter: false,\n scale: 1,\n roundcoords: 1,\n viewbox: false,\n desc: false,\n lcpr: 0,\n qcpr: 0,\n blurradius: 0,\n blurdelta: 20\n },\n posterized1: { colorsampling: 0, numberofcolors: 2 },\n posterized2: { numberofcolors: 4, blurradius: 5 },\n curvy: { ltres: 0.01, linefilter: true, rightangleenhance: false },\n sharp: { qtres: 0.01, linefilter: false },\n detailed: { pathomit: 0, roundcoords: 2, ltres: 0.5, qtres: 0.5, numberofcolors: 64 },\n smoothed: { blurradius: 5, blurdelta: 64 },\n grayscale: { colorsampling: 0, colorquantcycles: 1, numberofcolors: 7 },\n fixedpalette: { colorsampling: 0, colorquantcycles: 1, numberofcolors: 27 },\n randomsampling1: { colorsampling: 1, numberofcolors: 8 },\n randomsampling2: { colorsampling: 1, numberofcolors: 64 },\n artistic1: { colorsampling: 0, colorquantcycles: 1, pathomit: 0, blurradius: 5, blurdelta: 64, ltres: 0.01, linefilter: true, numberofcolors: 16, strokewidth: 2 },\n artistic2: { qtres: 0.01, colorsampling: 0, colorquantcycles: 1, numberofcolors: 4, strokewidth: 0 },\n artistic3: { qtres: 10, ltres: 10, numberofcolors: 8 },\n artistic4: { qtres: 10, ltres: 10, numberofcolors: 64, blurradius: 5, blurdelta: 256, strokewidth: 2 },\n posterized3: {\n ltres: 1,\n qtres: 1,\n pathomit: 20,\n rightangleenhance: true,\n colorsampling: 0,\n numberofcolors: 3,\n mincolorratio: 0,\n colorquantcycles: 3,\n blurradius: 3,\n blurdelta: 20,\n strokewidth: 0,\n linefilter: false,\n roundcoords: 1,\n pal: [{ r: 0, g: 0, b: 100, a: 255 }, { r: 255, g: 255, b: 255, a: 255 }]\n }\n};\n\nfunction generatePalette(numberOfColors) {\n const palette = [];\n let rcnt;\n let gcnt;\n let bcnt;\n if (numberOfColors < 8) {\n const graystep = Math.floor(255 / (numberOfColors - 1));\n for (let i = 0; i < numberOfColors; i++)\n palette.push({ r: i * graystep, g: i * graystep, b: i * graystep, a: 255 });\n } else {\n const colorqnum = Math.floor(Math.pow(numberOfColors, 1 / 3));\n const colorstep = Math.floor(255 / (colorqnum - 1));\n const rndnum = numberOfColors - colorqnum * colorqnum * colorqnum;\n for (rcnt = 0; rcnt < colorqnum; rcnt++) {\n for (gcnt = 0; gcnt < colorqnum; gcnt++) {\n for (bcnt = 0; bcnt < colorqnum; bcnt++)\n palette.push({ r: rcnt * colorstep, g: gcnt * colorstep, b: bcnt * colorstep, a: 255 });\n }\n }\n for (rcnt = 0; rcnt < rndnum; rcnt++)\n palette.push({ r: Math.floor(Math.random() * 255), g: Math.floor(Math.random() * 255), b: Math.floor(Math.random() * 255), a: Math.floor(Math.random() * 255) });\n }\n return palette;\n}\nfunction samplePalette(numberOfColors, imageData) {\n let idx;\n const palette = [];\n for (let i = 0; i < numberOfColors; i++) {\n idx = Math.floor(Math.random() * imageData.data.length / 4) * 4;\n palette.push({ r: imageData.data[idx], g: imageData.data[idx + 1], b: imageData.data[idx + 2], a: imageData.data[idx + 3] });\n }\n return palette;\n}\nfunction samplePaletteByGrid(numberOfColors, imageData) {\n let idx;\n const palette = [];\n const ni = Math.ceil(Math.sqrt(numberOfColors));\n const nj = Math.ceil(numberOfColors / ni);\n const vx = imageData.width / (ni + 1);\n const vy = imageData.height / (nj + 1);\n for (let j = 0; j < nj; j++) {\n for (let i = 0; i < ni; i++) {\n if (palette.length === numberOfColors) {\n break;\n } else {\n idx = Math.floor((j + 1) * vy * imageData.width + (i + 1) * vx) * 4;\n palette.push({ r: imageData.data[idx], g: imageData.data[idx + 1], b: imageData.data[idx + 2], a: imageData.data[idx + 3] });\n }\n }\n }\n return palette;\n}\n\nfunction blur(imageData, radius, delta) {\n let i, j, k, d, idx, racc, gacc, bacc, aacc, wacc;\n const imageData2 = new ImageData(imageData.width, imageData.height);\n radius = Math.floor(radius);\n if (radius < 1)\n return imageData;\n if (radius > 5)\n radius = 5;\n delta = Math.abs(delta);\n if (delta > 1024)\n delta = 1024;\n const thisgk = GKS[radius - 1];\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n racc = 0;\n gacc = 0;\n bacc = 0;\n aacc = 0;\n wacc = 0;\n for (k = -radius; k < radius + 1; k++) {\n if (i + k > 0 && i + k < imageData.width) {\n idx = (j * imageData.width + i + k) * 4;\n racc += imageData.data[idx] * thisgk[k + radius];\n gacc += imageData.data[idx + 1] * thisgk[k + radius];\n bacc += imageData.data[idx + 2] * thisgk[k + radius];\n aacc += imageData.data[idx + 3] * thisgk[k + radius];\n wacc += thisgk[k + radius];\n }\n }\n idx = (j * imageData.width + i) * 4;\n imageData2.data[idx] = Math.floor(racc / wacc);\n imageData2.data[idx + 1] = Math.floor(gacc / wacc);\n imageData2.data[idx + 2] = Math.floor(bacc / wacc);\n imageData2.data[idx + 3] = Math.floor(aacc / wacc);\n }\n }\n const himageData = new Uint8ClampedArray(imageData2.data);\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n racc = 0;\n gacc = 0;\n bacc = 0;\n aacc = 0;\n wacc = 0;\n for (k = -radius; k < radius + 1; k++) {\n if (j + k > 0 && j + k < imageData.height) {\n idx = ((j + k) * imageData.width + i) * 4;\n racc += himageData[idx] * thisgk[k + radius];\n gacc += himageData[idx + 1] * thisgk[k + radius];\n bacc += himageData[idx + 2] * thisgk[k + radius];\n aacc += himageData[idx + 3] * thisgk[k + radius];\n wacc += thisgk[k + radius];\n }\n }\n idx = (j * imageData.width + i) * 4;\n imageData2.data[idx] = Math.floor(racc / wacc);\n imageData2.data[idx + 1] = Math.floor(gacc / wacc);\n imageData2.data[idx + 2] = Math.floor(bacc / wacc);\n imageData2.data[idx + 3] = Math.floor(aacc / wacc);\n }\n }\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n idx = (j * imageData.width + i) * 4;\n d = Math.abs(imageData2.data[idx] - imageData.data[idx]) + Math.abs(imageData2.data[idx + 1] - imageData.data[idx + 1]) + Math.abs(imageData2.data[idx + 2] - imageData.data[idx + 2]) + Math.abs(imageData2.data[idx + 3] - imageData.data[idx + 3]);\n if (d > delta) {\n imageData2.data[idx] = imageData.data[idx];\n imageData2.data[idx + 1] = imageData.data[idx + 1];\n imageData2.data[idx + 2] = imageData.data[idx + 2];\n imageData2.data[idx + 3] = imageData.data[idx + 3];\n }\n }\n }\n return imageData2;\n}\n\nfunction getDirection(x1, y1, x2, y2) {\n let result = 8;\n if (x1 < x2) {\n if (y1 < y2)\n result = 1;\n else if (y1 > y2)\n result = 7;\n else\n result = 0;\n } else if (x1 > x2) {\n if (y1 < y2)\n result = 3;\n else if (y1 > y2)\n result = 5;\n else\n result = 4;\n } else {\n if (y1 < y2)\n result = 2;\n else if (y1 > y2)\n result = 6;\n else\n result = 8;\n }\n return result;\n}\nconst roundToDec = (val, places = void 0) => +val.toFixed(places);\nfunction colorQuantization(imageData, options) {\n const arr = [];\n let idx = 0;\n let cd;\n let cdl;\n let ci;\n const paletteacc = [];\n const pixelnum = imageData.width * imageData.height;\n let i;\n let j;\n let k;\n let cnt;\n let palette;\n let imageDataCache = imageData.data;\n if (imageDataCache.length < pixelnum * 4) {\n const newImageData = new Uint8ClampedArray(pixelnum * 4);\n for (let pxcnt = 0; pxcnt < pixelnum; pxcnt++) {\n newImageData[pxcnt * 4] = imageDataCache[pxcnt * 3];\n newImageData[pxcnt * 4 + 1] = imageDataCache[pxcnt * 3 + 1];\n newImageData[pxcnt * 4 + 2] = imageDataCache[pxcnt * 3 + 2];\n newImageData[pxcnt * 4 + 3] = 255;\n }\n imageDataCache = newImageData;\n }\n for (j = 0; j < imageData.height + 2; j++) {\n arr[j] = [];\n for (i = 0; i < imageData.width + 2; i++)\n arr[j][i] = -1;\n }\n if (options.pal)\n palette = options.pal;\n else if (options.colorsampling === 0)\n palette = generatePalette(options.numberofcolors);\n else if (options.colorsampling === 1)\n palette = samplePalette(options.numberofcolors, imageData);\n else\n palette = samplePaletteByGrid(options.numberofcolors, imageData);\n if (options.blurradius > 0)\n imageData = blur(imageData, options.blurradius, options.blurdelta);\n for (cnt = 0; cnt < options.colorquantcycles; cnt++) {\n if (cnt > 0) {\n for (k = 0; k < palette.length; k++) {\n if (paletteacc[k].n > 0) {\n palette[k] = {\n r: Math.floor(paletteacc[k].r / paletteacc[k].n),\n g: Math.floor(paletteacc[k].g / paletteacc[k].n),\n b: Math.floor(paletteacc[k].b / paletteacc[k].n),\n a: Math.floor(paletteacc[k].a / paletteacc[k].n)\n };\n }\n if (paletteacc[k].n / pixelnum < options.mincolorratio && cnt < options.colorquantcycles - 1) {\n palette[k] = {\n r: Math.floor(Math.random() * 255),\n g: Math.floor(Math.random() * 255),\n b: Math.floor(Math.random() * 255),\n a: Math.floor(Math.random() * 255)\n };\n }\n }\n }\n for (i = 0; i < palette.length; i++)\n paletteacc[i] = { r: 0, g: 0, b: 0, a: 0, n: 0 };\n for (j = 0; j < imageData.height; j++) {\n for (i = 0; i < imageData.width; i++) {\n idx = (j * imageData.width + i) * 4;\n ci = 0;\n cdl = 1024;\n for (k = 0; k < palette.length; k++) {\n cd = (palette[k].r > imageDataCache[idx] ? palette[k].r - imageDataCache[idx] : imageDataCache[idx] - palette[k].r) + (palette[k].g > imageDataCache[idx + 1] ? palette[k].g - imageDataCache[idx + 1] : imageDataCache[idx + 1] - palette[k].g) + (palette[k].b > imageDataCache[idx + 2] ? palette[k].b - imageDataCache[idx + 2] : imageDataCache[idx + 2] - palette[k].b) + (palette[k].a > imageDataCache[idx + 3] ? palette[k].a - imageDataCache[idx + 3] : imageDataCache[idx + 3] - palette[k].a);\n if (cd < cdl) {\n cdl = cd;\n ci = k;\n }\n }\n paletteacc[ci].r += imageDataCache[idx];\n paletteacc[ci].g += imageDataCache[idx + 1];\n paletteacc[ci].b += imageDataCache[idx + 2];\n paletteacc[ci].a += imageDataCache[idx + 3];\n paletteacc[ci].n++;\n arr[j + 1][i + 1] = ci;\n }\n }\n }\n return { array: arr, palette };\n}\nconst toRgbaStr = (c) => `rgba(${c.r},${c.g},${c.b},${c.a})`;\n\nfunction svgPathString(tracedata, lnum, pathnum, options) {\n const layer = tracedata.layers[lnum];\n const smp = layer[pathnum];\n let str = \"\";\n let pcnt;\n if (options.linefilter && smp.segments.length < 3)\n return str;\n str = `= 0; pcnt--) {\n str += `${hsmp.segments[pcnt].type} `;\n if (hsmp.segments[pcnt].hasOwnProperty(\"x3\"))\n str += `${hsmp.segments[pcnt].x2 * options.scale} ${hsmp.segments[pcnt].y2 * options.scale} `;\n str += `${hsmp.segments[pcnt].x1 * options.scale} ${hsmp.segments[pcnt].y1 * options.scale} `;\n }\n } else {\n if (hsmp.segments[hsmp.segments.length - 1].hasOwnProperty(\"x3\"))\n str += `M ${roundToDec(hsmp.segments[hsmp.segments.length - 1].x3 * options.scale)} ${roundToDec(hsmp.segments[hsmp.segments.length - 1].y3 * options.scale)} `;\n else\n str += `M ${roundToDec(hsmp.segments[hsmp.segments.length - 1].x2 * options.scale)} ${roundToDec(hsmp.segments[hsmp.segments.length - 1].y2 * options.scale)} `;\n for (pcnt = hsmp.segments.length - 1; pcnt >= 0; pcnt--) {\n str += `${hsmp.segments[pcnt].type} `;\n if (hsmp.segments[pcnt].hasOwnProperty(\"x3\"))\n str += `${roundToDec(hsmp.segments[pcnt].x2 * options.scale)} ${roundToDec(hsmp.segments[pcnt].y2 * options.scale)} `;\n str += `${roundToDec(hsmp.segments[pcnt].x1 * options.scale)} ${roundToDec(hsmp.segments[pcnt].y1 * options.scale)} `;\n }\n }\n str += \"Z \";\n }\n str += '\" />';\n if (options.lcpr || options.qcpr) {\n for (pcnt = 0; pcnt < smp.segments.length; pcnt++) {\n if (smp.segments[pcnt].hasOwnProperty(\"x3\") && options.qcpr) {\n str += ``;\n str += ``;\n str += ``;\n str += ``;\n }\n if (!smp.segments[pcnt].hasOwnProperty(\"x3\") && options.lcpr)\n str += ``;\n }\n for (let hcnt = 0; hcnt < smp.holechildren.length; hcnt++) {\n const hsmp = layer[smp.holechildren[hcnt]];\n for (pcnt = 0; pcnt < hsmp.segments.length; pcnt++) {\n if (hsmp.segments[pcnt].hasOwnProperty(\"x3\") && options.qcpr) {\n str += ``;\n str += ``;\n str += ``;\n str += ``;\n }\n if (!hsmp.segments[pcnt].hasOwnProperty(\"x3\") && options.lcpr)\n str += ``;\n }\n }\n }\n return str;\n}\nfunction toSvgColorStr(c, options) {\n return `fill=\"rgb(${c.r},${c.g},${c.b})\" stroke=\"rgb(${c.r},${c.g},${c.b})\" stroke-width=\"${options.strokewidth}\" opacity=\"${c.a / 255}\" `;\n}\nfunction fitSeq(path, ltres, qtres, seqstart, seqend) {\n if (seqend > path.points.length || seqend < 0)\n return [];\n let errorpoint = seqstart;\n let errorval = 0;\n let curvepass = true;\n let px;\n let py;\n let dist2;\n let tl = seqend - seqstart;\n if (tl < 0)\n tl += path.points.length;\n const vx = (path.points[seqend].x - path.points[seqstart].x) / tl;\n const vy = (path.points[seqend].y - path.points[seqstart].y) / tl;\n let pcnt = (seqstart + 1) % path.points.length;\n let pl;\n while (pcnt !== seqend) {\n pl = pcnt - seqstart;\n if (pl < 0)\n pl += path.points.length;\n px = path.points[seqstart].x + vx * pl;\n py = path.points[seqstart].y + vy * pl;\n dist2 = (path.points[pcnt].x - px) * (path.points[pcnt].x - px) + (path.points[pcnt].y - py) * (path.points[pcnt].y - py);\n if (dist2 > ltres)\n curvepass = false;\n if (dist2 > errorval) {\n errorpoint = pcnt;\n errorval = dist2;\n }\n pcnt = (pcnt + 1) % path.points.length;\n }\n if (curvepass)\n return [{ type: \"L\", x1: path.points[seqstart].x, y1: path.points[seqstart].y, x2: path.points[seqend].x, y2: path.points[seqend].y }];\n const fitpoint = errorpoint;\n curvepass = true;\n errorval = 0;\n let t = (fitpoint - seqstart) / tl;\n let t1 = (1 - t) * (1 - t);\n let t2 = 2 * (1 - t) * t;\n let t3 = t * t;\n const cpx = (t1 * path.points[seqstart].x + t3 * path.points[seqend].x - path.points[fitpoint].x) / -t2;\n const cpy = (t1 * path.points[seqstart].y + t3 * path.points[seqend].y - path.points[fitpoint].y) / -t2;\n pcnt = seqstart + 1;\n while (pcnt !== seqend) {\n t = (pcnt - seqstart) / tl;\n t1 = (1 - t) * (1 - t);\n t2 = 2 * (1 - t) * t;\n t3 = t * t;\n px = t1 * path.points[seqstart].x + t2 * cpx + t3 * path.points[seqend].x;\n py = t1 * path.points[seqstart].y + t2 * cpy + t3 * path.points[seqend].y;\n dist2 = (path.points[pcnt].x - px) * (path.points[pcnt].x - px) + (path.points[pcnt].y - py) * (path.points[pcnt].y - py);\n if (dist2 > qtres)\n curvepass = false;\n if (dist2 > errorval) {\n errorpoint = pcnt;\n errorval = dist2;\n }\n pcnt = (pcnt + 1) % path.points.length;\n }\n if (curvepass)\n return [{ type: \"Q\", x1: path.points[seqstart].x, y1: path.points[seqstart].y, x2: cpx, y2: cpy, x3: path.points[seqend].x, y3: path.points[seqend].y }];\n const splitpoint = fitpoint;\n return fitSeq(path, ltres, qtres, seqstart, splitpoint).concat(fitSeq(path, ltres, qtres, splitpoint, seqend));\n}\nfunction boundingBoxIncludes(parentbbox, childbbox) {\n return parentbbox[0] < childbbox[0] && parentbbox[1] < childbbox[1] && parentbbox[2] > childbbox[2] && parentbbox[3] > childbbox[3];\n}\nfunction pointInPoly(p, pa) {\n let isin = false;\n for (let i = 0, j = pa.length - 1; i < pa.length; j = i++) {\n isin = pa[i].y > p.y !== pa[j].y > p.y && p.x < (pa[j].x - pa[i].x) * (p.y - pa[i].y) / (pa[j].y - pa[i].y) + pa[i].x ? !isin : isin;\n }\n return isin;\n}\nfunction getSvgString(tracedata, options) {\n const w = tracedata.width * options.scale;\n const h = tracedata.height * options.scale;\n let svgstr = ``;\n for (let lcnt = 0; lcnt < tracedata.layers.length; lcnt++) {\n for (let pcnt = 0; pcnt < tracedata.layers[lcnt].length; pcnt++) {\n if (!tracedata.layers[lcnt][pcnt].isholepath)\n svgstr += svgPathString(tracedata, lcnt, pcnt, options);\n }\n }\n svgstr += \"\";\n return svgstr;\n}\n\nfunction testRightAngle(path, idx1, idx2, idx3, idx4, idx5) {\n return path.points[idx3].x === path.points[idx1].x && path.points[idx3].x === path.points[idx2].x && path.points[idx3].y === path.points[idx4].y && path.points[idx3].y === path.points[idx5].y || path.points[idx3].y === path.points[idx1].y && path.points[idx3].y === path.points[idx2].y && path.points[idx3].x === path.points[idx4].x && path.points[idx3].x === path.points[idx5].x;\n}\nfunction pathScan(arr, pathomit) {\n const paths = [];\n let pacnt = 0;\n let pcnt = 0;\n let px = 0;\n let py = 0;\n const w = arr[0].length;\n const h = arr.length;\n let dir = 0;\n let pathfinished = true;\n let holepath = false;\n let lookuprow;\n for (let j = 0; j < h; j++) {\n for (let i = 0; i < w; i++) {\n if (arr[j][i] === 4 || arr[j][i] === 11) {\n px = i;\n py = j;\n paths[pacnt] = {};\n paths[pacnt].points = [];\n paths[pacnt].boundingbox = [px, py, px, py];\n paths[pacnt].holechildren = [];\n pathfinished = false;\n pcnt = 0;\n holepath = arr[j][i] === 11;\n dir = 1;\n while (!pathfinished) {\n paths[pacnt].points[pcnt] = {};\n paths[pacnt].points[pcnt].x = px - 1;\n paths[pacnt].points[pcnt].y = py - 1;\n paths[pacnt].points[pcnt].t = arr[py][px];\n if (px - 1 < paths[pacnt].boundingbox[0])\n paths[pacnt].boundingbox[0] = px - 1;\n if (px - 1 > paths[pacnt].boundingbox[2])\n paths[pacnt].boundingbox[2] = px - 1;\n if (py - 1 < paths[pacnt].boundingbox[1])\n paths[pacnt].boundingbox[1] = py - 1;\n if (py - 1 > paths[pacnt].boundingbox[3])\n paths[pacnt].boundingbox[3] = py - 1;\n lookuprow = PATHSCAN_COMBINED_LOOKUP[arr[py][px]][dir];\n arr[py][px] = lookuprow[0];\n dir = lookuprow[1];\n px += lookuprow[2];\n py += lookuprow[3];\n if (px - 1 === paths[pacnt].points[0].x && py - 1 === paths[pacnt].points[0].y) {\n pathfinished = true;\n if (paths[pacnt].points.length < pathomit) {\n paths.pop();\n } else {\n paths[pacnt].isholepath = !!holepath;\n if (holepath) {\n let parentidx = 0;\n let parentbbox = [-1, -1, w + 1, h + 1];\n for (let parentcnt = 0; parentcnt < pacnt; parentcnt++) {\n if (!paths[parentcnt].isholepath && boundingBoxIncludes(paths[parentcnt].boundingbox, paths[pacnt].boundingbox) && boundingBoxIncludes(parentbbox, paths[parentcnt].boundingbox) && pointInPoly(paths[pacnt].points[0], paths[parentcnt].points)) {\n parentidx = parentcnt;\n parentbbox = paths[parentcnt].boundingbox;\n }\n }\n paths[parentidx].holechildren.push(pacnt);\n }\n pacnt++;\n }\n }\n pcnt++;\n }\n }\n }\n }\n return paths;\n}\nfunction batchPathScan(layers, pathomit) {\n const bpaths = [];\n for (let k = 0; k < layers.length; k++)\n bpaths[k] = pathScan(layers[k], pathomit);\n return bpaths;\n}\nfunction tracePath(path, ltres, qtres) {\n let pcnt = 0;\n let segtype1;\n let segtype2;\n let seqend;\n const smp = {\n segments: [],\n boundingbox: path.boundingbox,\n holechildren: path.holechildren,\n isholepath: path.isholepath\n };\n while (pcnt < path.points.length) {\n segtype1 = path.points[pcnt].linesegment;\n segtype2 = -1;\n seqend = pcnt + 1;\n while ((path.points[seqend].linesegment === segtype1 || path.points[seqend].linesegment === segtype2 || segtype2 === -1) && seqend < path.points.length - 1) {\n if (path.points[seqend].linesegment !== segtype1 && segtype2 === -1)\n segtype2 = path.points[seqend].linesegment;\n seqend++;\n }\n if (seqend === path.points.length - 1)\n seqend = 0;\n smp.segments = smp.segments.concat(fitSeq(path, ltres, qtres, pcnt, seqend));\n if (seqend > 0)\n pcnt = seqend;\n else\n pcnt = path.points.length;\n }\n return smp;\n}\nfunction batchTracePaths(internodepaths, ltres, qtres) {\n const btracedpaths = [];\n for (let k = 0; k < internodepaths.length; k++)\n btracedpaths.push(tracePath(internodepaths[k], ltres, qtres));\n return btracedpaths;\n}\n\nfunction batchInterNodes(bpaths, options) {\n const binternodes = [];\n for (let k = 0; k < bpaths.length; k++)\n binternodes[k] = interNodes(bpaths[k], options);\n return binternodes;\n}\nfunction interNodes(paths, options) {\n const ins = [];\n let palen = 0;\n let nextidx = 0;\n let nextidx2 = 0;\n let previdx = 0;\n let previdx2 = 0;\n let pacnt;\n let pcnt;\n for (pacnt = 0; pacnt < paths.length; pacnt++) {\n ins[pacnt] = {};\n ins[pacnt].points = [];\n ins[pacnt].boundingbox = paths[pacnt].boundingbox;\n ins[pacnt].holechildren = paths[pacnt].holechildren;\n ins[pacnt].isholepath = paths[pacnt].isholepath;\n palen = paths[pacnt].points.length;\n for (pcnt = 0; pcnt < palen; pcnt++) {\n nextidx = (pcnt + 1) % palen;\n nextidx2 = (pcnt + 2) % palen;\n previdx = (pcnt - 1 + palen) % palen;\n previdx2 = (pcnt - 2 + palen) % palen;\n if (options.rightangleenhance && testRightAngle(paths[pacnt], previdx2, previdx, pcnt, nextidx, nextidx2)) {\n if (ins[pacnt].points.length > 0) {\n ins[pacnt].points[ins[pacnt].points.length - 1].linesegment = getDirection(ins[pacnt].points[ins[pacnt].points.length - 1].x, ins[pacnt].points[ins[pacnt].points.length - 1].y, paths[pacnt].points[pcnt].x, paths[pacnt].points[pcnt].y);\n }\n ins[pacnt].points.push({\n x: paths[pacnt].points[pcnt].x,\n y: paths[pacnt].points[pcnt].y,\n linesegment: getDirection(paths[pacnt].points[pcnt].x, paths[pacnt].points[pcnt].y, (paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2, (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2)\n });\n }\n ins[pacnt].points.push({\n x: (paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2,\n y: (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2,\n linesegment: getDirection((paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2, (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2, (paths[pacnt].points[nextidx].x + paths[pacnt].points[nextidx2].x) / 2, (paths[pacnt].points[nextidx].y + paths[pacnt].points[nextidx2].y) / 2)\n });\n }\n }\n return ins;\n}\n\nfunction batchTraceLayers(binternodes, ltres, qtres) {\n const btbis = [];\n for (let k = 0; k < binternodes.length; k++)\n btbis[k] = batchTracePaths(binternodes[k], ltres, qtres);\n return btbis;\n}\nfunction layering(ii) {\n const layers = [];\n let val = 0;\n const ah = ii.array.length;\n const aw = ii.array[0].length;\n let n1;\n let n2;\n let n3;\n let n4;\n let n5;\n let n6;\n let n7;\n let n8;\n let i;\n let j;\n let k;\n for (k = 0; k < ii.palette.length; k++) {\n layers[k] = [];\n for (j = 0; j < ah; j++) {\n layers[k][j] = [];\n for (i = 0; i < aw; i++)\n layers[k][j][i] = 0;\n }\n }\n for (j = 1; j < ah - 1; j++) {\n for (i = 1; i < aw - 1; i++) {\n val = ii.array[j][i];\n n1 = ii.array[j - 1][i - 1] === val ? 1 : 0;\n n2 = ii.array[j - 1][i] === val ? 1 : 0;\n n3 = ii.array[j - 1][i + 1] === val ? 1 : 0;\n n4 = ii.array[j][i - 1] === val ? 1 : 0;\n n5 = ii.array[j][i + 1] === val ? 1 : 0;\n n6 = ii.array[j + 1][i - 1] === val ? 1 : 0;\n n7 = ii.array[j + 1][i] === val ? 1 : 0;\n n8 = ii.array[j + 1][i + 1] === val ? 1 : 0;\n layers[val][j + 1][i + 1] = 1 + n5 * 2 + n8 * 4 + n7 * 8;\n if (!n4)\n layers[val][j + 1][i] = 0 + 2 + n7 * 4 + n6 * 8;\n if (!n2)\n layers[val][j][i + 1] = 0 + n3 * 2 + n5 * 4 + 8;\n if (!n1)\n layers[val][j][i] = 0 + n2 * 2 + 4 + n4 * 8;\n }\n }\n return layers;\n}\nfunction layeringStep(ii, cnum) {\n const layer = [];\n const ah = ii.array.length;\n const aw = ii.array[0].length;\n let i;\n let j;\n for (j = 0; j < ah; j++) {\n layer[j] = [];\n for (i = 0; i < aw; i++)\n layer[j][i] = 0;\n }\n for (j = 1; j < ah; j++) {\n for (i = 1; i < aw; i++) {\n layer[j][i] = (ii.array[j - 1][i - 1] === cnum ? 1 : 0) + (ii.array[j - 1][i] === cnum ? 2 : 0) + (ii.array[j][i - 1] === cnum ? 8 : 0) + (ii.array[j][i] === cnum ? 4 : 0);\n }\n }\n return layer;\n}\nfunction drawLayers(layers, palette, scale = 1, parentid) {\n let w, h, i, j;\n let div;\n if (parentid) {\n div = document.getElementById(parentid);\n if (!div) {\n div = document.createElement(\"div\");\n div.id = parentid;\n document.body.appendChild(div);\n }\n } else {\n div = document.createElement(\"div\");\n document.body.appendChild(div);\n }\n for (const layer of layers) {\n w = layer[0].length;\n h = layer.length;\n const canvas = document.createElement(\"canvas\");\n canvas.width = w * scale;\n canvas.height = h * scale;\n const context = canvas.getContext(\"2d\");\n for (j = 0; j < h; j++) {\n for (i = 0; i < w; i++) {\n context.fillStyle = toRgbaStr(palette[layer[j][i] % palette.length]);\n context.fillRect(i * scale, j * scale, scale, scale);\n }\n }\n div.appendChild(canvas);\n }\n}\n\nclass ImageTracer {\n constructor() {\n this.versionnumber = VERSION_NUMBER;\n this.optionpresets = OPTION_PRESETS;\n }\n checkOptions(options) {\n if (options === void 0)\n return { ...this.optionpresets.default };\n if (typeof options === \"string\") {\n const presetName = options;\n const preset = this.optionpresets[presetName];\n return { ...this.optionpresets.default, ...preset || {} };\n }\n if (typeof options === \"object\") {\n return { ...this.optionpresets.default, ...options };\n }\n throw new Error(`Unknown Option Type: ${typeof options}`);\n }\n async imageToSVG(url, options) {\n options = this.checkOptions(options);\n const canvas = await this.loadImage(url, options);\n return this.imageDataToSVG(this.getImgdata(canvas), options);\n }\n getImgdata(canvas) {\n const context = canvas.getContext(\"2d\");\n return context.getImageData(0, 0, canvas.width, canvas.height);\n }\n loadImage(url, options) {\n return new Promise((resolve) => {\n const img = new Image();\n if (options && options.corsenabled)\n img.crossOrigin = \"Anonymous\";\n img.src = url;\n img.onload = function() {\n const canvas = document.createElement(\"canvas\");\n canvas.width = img.width;\n canvas.height = img.height;\n const context = canvas.getContext(\"2d\");\n context?.drawImage(img, 0, 0);\n resolve(canvas);\n };\n });\n }\n imageDataToSVG(imgd, options) {\n options = this.checkOptions(options);\n const td = this.imageDataToTracedata(imgd, options);\n return getSvgString(td, options);\n }\n async imageToTracedata(url, options) {\n options = this.checkOptions(options);\n const canvas = await this.loadImage(url, options);\n return this.imageDataToTracedata(this.getImgdata(canvas), options);\n }\n imageDataToTracedata(imgd, options) {\n options = this.checkOptions(options);\n let tracedata;\n const ii = colorQuantization(imgd, options);\n if (options.layering === 0) {\n tracedata = {\n layers: [],\n palette: ii.palette,\n width: ii.array[0].length - 2,\n height: ii.array.length - 2\n };\n for (let colornum = 0; colornum < ii.palette.length; colornum++) {\n const tracedlayer = batchTracePaths(interNodes(pathScan(layeringStep(ii, colornum), options.pathomit), options), options.ltres, options.qtres);\n tracedata.layers.push(tracedlayer);\n }\n } else {\n const ls = layering(ii);\n if (options.layercontainerid)\n drawLayers(ls, SPECPALETTE, options.scale, options.layercontainerid);\n const bps = batchPathScan(ls, options.pathomit);\n const bis = batchInterNodes(bps, options);\n tracedata = {\n layers: batchTraceLayers(bis, options.ltres, options.qtres),\n palette: ii.palette,\n width: imgd.width,\n height: imgd.height\n };\n }\n return tracedata;\n }\n appendSVGString(svgstr, parentid) {\n let div;\n if (parentid) {\n div = document.getElementById(parentid);\n if (!div) {\n div = document.createElement(\"div\");\n div.id = parentid;\n document.body.appendChild(div);\n }\n } else {\n div = document.createElement(\"div\");\n document.body.appendChild(div);\n }\n div.innerHTML += svgstr;\n }\n}\nconst imageTracer = new ImageTracer();\n\nvar Colorsampling = /* @__PURE__ */ ((Colorsampling2) => {\n Colorsampling2[Colorsampling2[\"DISABLED\"] = 0] = \"DISABLED\";\n Colorsampling2[Colorsampling2[\"RANDOM_SAMPLING\"] = 1] = \"RANDOM_SAMPLING\";\n Colorsampling2[Colorsampling2[\"DETERMINISTIC_SAMPLING\"] = 2] = \"DETERMINISTIC_SAMPLING\";\n return Colorsampling2;\n})(Colorsampling || {});\n\nexport { Colorsampling, GKS, ImageTracer, OPTION_PRESETS, PATHSCAN_COMBINED_LOOKUP, SPECPALETTE, VERSION_NUMBER, batchInterNodes, batchPathScan, batchTraceLayers, batchTracePaths, boundingBoxIncludes, colorQuantization, drawLayers, fitSeq, generatePalette, getDirection, getSvgString, imageTracer, interNodes, layering, layeringStep, pathScan, pointInPoly, roundToDec, samplePalette, samplePaletteByGrid, svgPathString, testRightAngle, toRgbaStr, toSvgColorStr, tracePath };\n","import { locate } from 'locate-character';\n\nconst validNameCharacters = /[a-zA-Z0-9:_-]/;\nconst whitespace = /[\\s\\t\\r\\n]/;\nconst quotemark = /['\"]/;\n\nfunction repeat(str, i) {\n\tlet result = '';\n\twhile (i--) result += str;\n\treturn result;\n}\n\nexport function parse(source) {\n\tlet header = '';\n\tlet stack = [];\n\n\tlet state = metadata;\n\tlet currentElement = null;\n\tlet root = null;\n\n\tfunction error(message) {\n\t\tconst { line, column } = locate(source, i);\n\t\tconst before = source.slice(0, i);\n\t\tconst beforeLine = /(^|\\n).*$/.exec(before)[0].replace(/\\t/g, ' ');\n\t\tconst after = source.slice(i);\n\t\tconst afterLine = /.*(\\n|$)/.exec(after)[0];\n\n\t\tconst snippet = `${beforeLine}${afterLine}\\n${repeat(' ', beforeLine.length)}^`;\n\n\t\tthrow new Error(\n\t\t\t`${message} (${line}:${column}). If this is valid SVG, it's probably a bug in svg-parser. Please raise an issue at https://github.com/Rich-Harris/svg-parser/issues – thanks!\\n\\n${snippet}`\n\t\t);\n\t}\n\n\tfunction metadata() {\n\t\twhile ((i < source.length && source[i] !== '<') || !validNameCharacters.test(source[i + 1])) {\n\t\t\theader += source[i++];\n\t\t}\n\n\t\treturn neutral();\n\t}\n\n\tfunction neutral() {\n\t\tlet text = '';\n\t\twhile (i < source.length && source[i] !== '<') text += source[i++];\n\n\t\tif (/\\S/.test(text)) {\n\t\t\tcurrentElement.children.push({ type: 'text', value: text });\n\t\t}\n\n\t\tif (source[i] === '<') {\n\t\t\treturn tag;\n\t\t}\n\n\t\treturn neutral;\n\t}\n\n\tfunction tag() {\n\t\tconst char = source[i];\n\n\t\tif (char === '?') return neutral; // ') {\n\t\t\terror('Expected >');\n\t\t}\n\n\t\tif (!selfClosing) {\n\t\t\tcurrentElement = element;\n\t\t\tstack.push(element);\n\t\t}\n\n\t\treturn neutral;\n\t}\n\n\tfunction comment() {\n\t\tconst index = source.indexOf('-->', i);\n\t\tif (!~index) error('expected -->');\n\n\t\ti = index + 2;\n\t\treturn neutral;\n\t}\n\n\tfunction cdata() {\n\t\tconst index = source.indexOf(']]>', i);\n\t\tif (!~index) error('expected ]]>');\n\n\t\tcurrentElement.children.push(source.slice(i + 7, index));\n\n\t\ti = index + 2;\n\t\treturn neutral;\n\t}\n\n\tfunction closingTag() {\n\t\tconst tagName = getName();\n\n\t\tif (!tagName) error('Expected tag name');\n\n\t\tif (tagName !== currentElement.tagName) {\n\t\t\terror(`Expected closing tag to match opening tag <${currentElement.tagName}>`);\n\t\t}\n\n\t\tallowSpaces();\n\n\t\tif (source[i] !== '>') {\n\t\t\terror('Expected >');\n\t\t}\n\n\t\tstack.pop();\n\t\tcurrentElement = stack[stack.length - 1];\n\n\t\treturn neutral;\n\t}\n\n\tfunction getName() {\n\t\tlet name = '';\n\t\twhile (i < source.length && validNameCharacters.test(source[i])) name += source[i++];\n\n\t\treturn name;\n\t}\n\n\tfunction getAttribute() {\n\t\tif (!whitespace.test(source[i])) return null;\n\t\tallowSpaces();\n\n\t\tconst name = getName();\n\t\tif (!name) return null;\n\n\t\tlet value = true;\n\n\t\tallowSpaces();\n\t\tif (source[i] === '=') {\n\t\t\ti += 1;\n\t\t\tallowSpaces();\n\n\t\t\tvalue = getAttributeValue();\n\t\t\tif (!isNaN(value) && value.trim() !== '') value = +value; // TODO whitelist numeric attributes?\n\t\t}\n\n\t\treturn { name, value };\n\t}\n\n\tfunction getAttributeValue() {\n\t\treturn quotemark.test(source[i]) ? getQuotedAttributeValue() : getUnquotedAttributeValue();\n\t}\n\n\tfunction getUnquotedAttributeValue() {\n\t\tlet value = '';\n\t\tdo {\n\t\t\tconst char = source[i];\n\t\t\tif (char === ' ' || char === '>' || char === '/') {\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tvalue += char;\n\t\t\ti += 1;\n\t\t} while (i < source.length);\n\n\t\treturn value;\n\t}\n\n\tfunction getQuotedAttributeValue() {\n\t\tconst quotemark = source[i++];\n\n\t\tlet value = '';\n\t\tlet escaped = false;\n\n\t\twhile (i < source.length) {\n\t\t\tconst char = source[i++];\n\t\t\tif (char === quotemark && !escaped) {\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tif (char === '\\\\' && !escaped) {\n\t\t\t\tescaped = true;\n\t\t\t}\n\n\t\t\tvalue += escaped ? `\\\\${char}` : char;\n\t\t\tescaped = false;\n\t\t}\n\t}\n\n\tfunction allowSpaces() {\n\t\twhile (i < source.length && whitespace.test(source[i])) i += 1;\n\t}\n\n\tlet i = metadata.length;\n\twhile (i < source.length) {\n\t\tif (!state) error('Unexpected character');\n\t\tstate = state();\n\t\ti += 1;\n\t}\n\n\tif (state !== neutral) {\n\t\terror('Unexpected end of input');\n\t}\n\n\tif (root.tagName === 'svg') root.metadata = header;\n\treturn {\n\t\ttype: 'root',\n\t\tchildren: [root]\n\t};\n}\n","function getLocator(source, options) {\n if (options === void 0) { options = {}; }\n var offsetLine = options.offsetLine || 0;\n var offsetColumn = options.offsetColumn || 0;\n var originalLines = source.split('\\n');\n var start = 0;\n var lineRanges = originalLines.map(function (line, i) {\n var end = start + line.length + 1;\n var range = { start: start, end: end, line: i };\n start = end;\n return range;\n });\n var i = 0;\n function rangeContains(range, index) {\n return range.start <= index && index < range.end;\n }\n function getLocation(range, index) {\n return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };\n }\n function locate(search, startIndex) {\n if (typeof search === 'string') {\n search = source.indexOf(search, startIndex || 0);\n }\n var range = lineRanges[i];\n var d = search >= range.end ? 1 : -1;\n while (range) {\n if (rangeContains(range, search))\n return getLocation(range, search);\n i += d;\n range = lineRanges[i];\n }\n }\n ;\n return locate;\n}\nfunction locate(source, search, options) {\n if (typeof options === 'number') {\n throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');\n }\n return getLocator(source, options)(search, options && options.startIndex);\n}\n\nexport { getLocator, locate };","import { eSketchPathType, KbVector, SketchNode, SketchPath, Token } from '@models/classes';\r\nimport { imageTracer, ImageTracerOptionsParamers } from 'imagetracer';\r\nimport { ElementNode, parse, RootNode } from 'svg-parser';\r\nimport { Layer, PathHandler } from './path-handler';\r\nimport { projectOnNodeAxis } from './util';\r\n\r\ninterface ImageTraceColor {\r\n r: number;\r\n g: number;\r\n b: number;\r\n a: number;\r\n}\r\n\r\nexport interface ImageTraceResult {\r\n layers: Layer[][];\r\n palette: ImageTraceColor[];\r\n width: number;\r\n height: number;\r\n}\r\n\r\nexport class SvgConverter {\r\n static overwriteSketchWithSvg(node: SketchNode, data: Blob) {\r\n const decover = new TextDecoder();\r\n node.paths.clear();\r\n\r\n const header = data.slice(0, 100);\r\n header.arrayBuffer().then(buffer => {\r\n const headerText = decover.decode(buffer);\r\n if (headerText.search(/JFIF/) !== -1 || headerText.search(/PNG/) !== -1) {\r\n // is raster\r\n const dataUrl = URL.createObjectURL(data);\r\n const options: ImageTracerOptionsParamers = {\r\n qtres: 0.1,\r\n pathomit: 16,\r\n numberofcolors: 2,\r\n };\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n\r\n imageTracer.imageToTracedata(dataUrl, options).then((trace: ImageTraceResult) => {\r\n if (trace.palette && trace.palette.length > 1) {\r\n const pathParser = new PathHandler(\r\n node,\r\n SvgConverter.calculateScaleDivider([0, 0, trace.width, trace.height]),\r\n nodeManager\r\n );\r\n\r\n const paletteStrengths = (trace.palette as ImageTraceColor[]).map((color, idx) => ({\r\n idx,\r\n strength: getPaletteColorStrength(color),\r\n }));\r\n paletteStrengths.sort((a, b) => a.strength - b.strength);\r\n const bgIdx = paletteStrengths[0].idx;\r\n trace.layers.splice(bgIdx, 1);\r\n const primaryLayers = trace.layers.flat();\r\n\r\n const pathsCreated: SketchPath[][] = [];\r\n\r\n // Convert layers to sketchPaths\r\n primaryLayers.forEach((layer, layerIndex) => {\r\n const newPaths = pathParser.parseTrace(layer.segments);\r\n const pathGroupKey = 'tracedPath' + layerIndex;\r\n pathsCreated[layerIndex] = newPaths;\r\n newPaths.forEach(path => {\r\n path.pathGroupKey = pathGroupKey;\r\n });\r\n node.paths.push(...newPaths);\r\n });\r\n\r\n // Convert layers to holes\r\n primaryLayers.forEach((layer, layerIndex) => {\r\n if (layer.holechildren) {\r\n layer.holechildren.forEach(holeLayerIdx => {\r\n const pathSet = pathsCreated[holeLayerIdx];\r\n if (pathSet) {\r\n pathSet.forEach(path => {\r\n path.holeForPathGroup = 'tracedPath' + layerIndex;\r\n });\r\n }\r\n });\r\n }\r\n });\r\n }\r\n });\r\n } else {\r\n data.text().then(svgText => {\r\n const parsedSVG = parse(svgText);\r\n SvgConverter.parseSvgRecursively(node, parsedSVG);\r\n });\r\n }\r\n });\r\n }\r\n\r\n static findSvgViewBox(svg: ElementNode | RootNode) {\r\n for (let i = 0; i < svg.children.length; i++) {\r\n const child = svg.children[i] as ElementNode;\r\n if (typeof child === 'string') {\r\n return undefined;\r\n } else if (child.tagName === 'svg' && 'properties' in child) {\r\n return getViewBoxFromSvgElement(child);\r\n }\r\n }\r\n\r\n function getViewBoxFromSvgElement(elem: ElementNode): number[] | undefined {\r\n if (typeof elem.properties?.viewBox === 'string' && elem.properties.viewBox) {\r\n return elem.properties.viewBox.split(' ').map(int => parseInt(int));\r\n }\r\n if (elem.properties?.width && elem.properties?.height) {\r\n const width = elem.properties.width;\r\n const height = elem.properties.height;\r\n return [\r\n 0,\r\n 0,\r\n typeof width === 'string' ? parseInt(width) : width,\r\n typeof height === 'string' ? parseInt(height) : height,\r\n ];\r\n }\r\n }\r\n }\r\n\r\n static parseSvgRecursively(node: SketchNode, svg: ElementNode | RootNode, viewBox?: number[]) {\r\n if (!viewBox) {\r\n viewBox = SvgConverter.findSvgViewBox(svg) || [0, 0, 100, 100];\r\n }\r\n if (svg.children) {\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n\r\n for (let i = 0; i < svg.children.length; i++) {\r\n const child = svg.children[i] as ElementNode;\r\n\r\n if (child.tagName === 'path' && child.properties) {\r\n const pathParser = new PathHandler(node, SvgConverter.calculateScaleDivider(viewBox), nodeManager);\r\n const newPaths = pathParser.parsePath(child.properties.d as string);\r\n node.paths.push(...newPaths);\r\n //call actual parser\r\n } else if (child.tagName === 'rect' && child.properties) {\r\n SvgConverter.createRectangle(node, child, viewBox);\r\n } else if (child.tagName === 'circle' && child.properties) {\r\n SvgConverter.createCircle(node, child, viewBox);\r\n } else if (child.tagName === 'polyline' && child.properties) {\r\n SvgConverter.createPolyLine(node, child, viewBox);\r\n } else if (child.tagName === 'line' && child.properties) {\r\n SvgConverter.createLine(node, child, viewBox);\r\n } else if (child.tagName === 'polygon' && child.properties) {\r\n SvgConverter.createPolyLine(node, child, viewBox, true);\r\n }\r\n SvgConverter.parseSvgRecursively(node, child, viewBox);\r\n nameGeneratedPaths(node);\r\n }\r\n }\r\n }\r\n\r\n static removeBackGroundOnConvertedSVG(children: [ElementNode]) {\r\n const parent = children[0];\r\n const newChildren = parent.children as [ElementNode];\r\n const resultChildren: ElementNode[] = [];\r\n newChildren.forEach(child => {\r\n if (child && child.properties) {\r\n if ('opacity' in child.properties) {\r\n if (child.properties.opacity == 1) {\r\n resultChildren.push(child);\r\n }\r\n }\r\n }\r\n });\r\n newChildren.clear();\r\n resultChildren.forEach(child => {\r\n newChildren.push(child);\r\n });\r\n // if (svg.children) {\r\n // console.log(svg.children.length);\r\n // for (let i = 0; i < svg.children.length; i++) {\r\n // const child = svg.children[i] as ElementNode;\r\n // if (child.properties) {\r\n // if (child.properties.opacity) {\r\n // if (Number(child.properties.opacity) < 1) {\r\n // console.log('Not a valid path');\r\n // svg.children.remove(child);\r\n // } else {\r\n // console.log('valid path:', child);\r\n // }\r\n // }\r\n // }\r\n // this.removeBackGroundOnConvertedSVG(child);\r\n // }\r\n // }\r\n }\r\n\r\n // static projectSketchOnNormal(node: SketchNode) {\r\n // node.paths.forEach(path => {\r\n // path.controlPoints.forEach(point => {\r\n // if (node.normal === eAxis.y) {\r\n // point.position = new KbVector(point.position.x, 0, point.position.y);\r\n // point.direction = new KbVector(point.direction.x, 0, point.direction.y);\r\n // if (point.direction2) {\r\n // point.direction2 = new KbVector(point.direction2.x, 0, point.direction2.y);\r\n // }\r\n // } else if (node.normal === eAxis.x) {\r\n // point.position = new KbVector(0, point.position.y, point.position.x);\r\n // point.direction = new KbVector(0, point.direction.y, point.direction.x);\r\n // if (point.direction2) {\r\n // point.direction2 = new KbVector(0, point.direction2.y, point.direction2.x);\r\n // }\r\n // }\r\n // });\r\n // });\r\n // }\r\n\r\n static calculateScaleDivider(viewbox: number[]) {\r\n if (viewbox) {\r\n const width = viewbox[2];\r\n const height = viewbox[3];\r\n if (width > height) {\r\n return width;\r\n } else {\r\n return height;\r\n }\r\n } else {\r\n return 1;\r\n }\r\n }\r\n\r\n static addNewPath(node: SketchNode, pathType?: eSketchPathType) {\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n const newPath = nodeManager.create(Token.SketchPath);\r\n if (newPath) {\r\n newPath.name = 'Path';\r\n newPath._expanded = true;\r\n if (pathType) {\r\n newPath.type = pathType;\r\n }\r\n node.paths.push(newPath);\r\n }\r\n return newPath;\r\n }\r\n\r\n static createRectangle(node: SketchNode, element: ElementNode, viewbox: number[]) {\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\r\n if (!element.properties) {\r\n return;\r\n }\r\n const x = (element.properties.x as number) / scaleDivider;\r\n const y = ((element.properties.y as number) / scaleDivider) * -1;\r\n const rx = (element.properties.rx as number) / scaleDivider;\r\n const ry = ((element.properties.ry as number) / scaleDivider) * -1;\r\n const width = (element.properties.width as number) / scaleDivider;\r\n const height = ((element.properties.height as number) / scaleDivider) * -1;\r\n let newPath = SvgConverter.addNewPath(node, eSketchPathType.points);\r\n if (rx && ry) {\r\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = projectOnNodeAxis(node, x, y + ry);\r\n newPath.controlPoints.push(newControlPoint);\r\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint2.position = projectOnNodeAxis(node, x, y + height - ry);\r\n newPath.controlPoints.push(newControlPoint2);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.quadraticBezier);\r\n const newControlPoint3 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint3.position = projectOnNodeAxis(node, x, y + height - ry);\r\n newControlPoint3.direction = projectOnNodeAxis(node, 0, ry);\r\n newPath.controlPoints.push(newControlPoint3);\r\n\r\n const newControlPoint4 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint4.position = projectOnNodeAxis(node, x + rx, y + height);\r\n newPath.controlPoints.push(newControlPoint4);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.points);\r\n const newControlPoint5 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint5.position = projectOnNodeAxis(node, x + rx, y + height);\r\n newPath.controlPoints.push(newControlPoint5);\r\n\r\n const newControlPoint6 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint6.position = projectOnNodeAxis(node, width + x - rx, y + height);\r\n newPath.controlPoints.push(newControlPoint6);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.quadraticBezier);\r\n const newControlPoint7 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint7.position = projectOnNodeAxis(node, width + x - rx, y + height);\r\n newControlPoint7.direction = projectOnNodeAxis(node, -ry, 0);\r\n newPath.controlPoints.push(newControlPoint7);\r\n\r\n const newControlPoint8 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint8.position = projectOnNodeAxis(node, width + x, y + height - ry);\r\n newPath.controlPoints.push(newControlPoint8);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.points);\r\n const newControlPoint9 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint9.position = projectOnNodeAxis(node, width + x, y + height - ry);\r\n newPath.controlPoints.push(newControlPoint9);\r\n\r\n const newControlPoint10 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint10.position = projectOnNodeAxis(node, width + x, y + ry);\r\n newPath.controlPoints.push(newControlPoint10);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.quadraticBezier);\r\n const newControlPoint11 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint11.position = projectOnNodeAxis(node, width + x, y + ry);\r\n newControlPoint11.direction = projectOnNodeAxis(node, 0, -ry);\r\n newPath.controlPoints.push(newControlPoint11);\r\n\r\n const newControlPoint12 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint12.position = projectOnNodeAxis(node, width + x - rx, y);\r\n newPath.controlPoints.push(newControlPoint12);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.points);\r\n const newControlPoint13 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint13.position = projectOnNodeAxis(node, width + x - rx, y);\r\n newPath.controlPoints.push(newControlPoint13);\r\n\r\n const newControlPoint14 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint14.position = projectOnNodeAxis(node, x + rx, y);\r\n newPath.controlPoints.push(newControlPoint14);\r\n\r\n newPath = SvgConverter.addNewPath(node, eSketchPathType.quadraticBezier);\r\n const newControlPoint15 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint15.position = projectOnNodeAxis(node, x + rx, y);\r\n newControlPoint15.direction = projectOnNodeAxis(node, ry, 0);\r\n newPath.controlPoints.push(newControlPoint15);\r\n\r\n const newControlPoint16 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint16.position = projectOnNodeAxis(node, x, y + ry);\r\n newPath.controlPoints.push(newControlPoint16);\r\n } else {\r\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = projectOnNodeAxis(node, x, y);\r\n newPath.controlPoints.push(newControlPoint);\r\n\r\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint2.position = projectOnNodeAxis(node, x, y + height);\r\n newPath.controlPoints.push(newControlPoint2);\r\n\r\n const newControlPoint3 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint3.position = projectOnNodeAxis(node, x + width, y + height);\r\n newPath.controlPoints.push(newControlPoint3);\r\n\r\n const newControlPoint4 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint4.position = projectOnNodeAxis(node, x + width, y);\r\n newPath.controlPoints.push(newControlPoint4);\r\n\r\n const newControlPoint5 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint5.position = projectOnNodeAxis(node, x, y);\r\n newPath.controlPoints.push(newControlPoint5);\r\n }\r\n }\r\n\r\n static createCircle(node: SketchNode, element: ElementNode, viewbox: number[]) {\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\r\n if (element.properties) {\r\n const cx = (element.properties.cx as number) / scaleDivider;\r\n const cy = ((element.properties.cy as number) / scaleDivider) * -1;\r\n const radius = (element.properties.r as number) / scaleDivider;\r\n\r\n const newPath = SvgConverter.addNewPath(node, eSketchPathType.centerRadiusCircle);\r\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = projectOnNodeAxis(node, cx, cy);\r\n newControlPoint.direction = new KbVector(0, 0, 1);\r\n newPath.controlPoints.push(newControlPoint);\r\n\r\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint2.position = projectOnNodeAxis(node, cx + radius, cy);\r\n newPath.controlPoints.push(newControlPoint2);\r\n }\r\n }\r\n\r\n static createLine(node: SketchNode, element: ElementNode, viewbox: number[]) {\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\r\n if (element.properties) {\r\n const newPath = SvgConverter.addNewPath(node, eSketchPathType.points);\r\n const x1 = (element.properties.x1 as number) / scaleDivider;\r\n const y1 = ((element.properties.y1 as number) / scaleDivider) * -1;\r\n const x2 = (element.properties.x2 as number) / scaleDivider;\r\n const y2 = ((element.properties.y2 as number) / scaleDivider) * -1;\r\n\r\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = projectOnNodeAxis(node, x1, y1);\r\n newPath.controlPoints.push(newControlPoint);\r\n\r\n const newControlPoint2 = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint2.position = projectOnNodeAxis(node, x2, y2);\r\n newPath.controlPoints.push(newControlPoint2);\r\n }\r\n }\r\n\r\n static createPolyLine(node: SketchNode, element: ElementNode, viewbox: number[], closePath = false) {\r\n const nodeManager = node._manager;\r\n if (!nodeManager) {\r\n throw Error('no node manager');\r\n }\r\n const scaleDivider = SvgConverter.calculateScaleDivider(viewbox);\r\n if (element.properties) {\r\n const newPath = SvgConverter.addNewPath(node, eSketchPathType.points);\r\n const points = (element.properties.points as string).replace(',', ' ').split(' ');\r\n for (let i = 0; i < points.length; i = i + 2) {\r\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(\r\n parseInt(points[i]) / scaleDivider,\r\n (parseInt(points[i + 1]) / scaleDivider) * -1,\r\n 0\r\n );\r\n newPath.controlPoints.push(newControlPoint);\r\n }\r\n if (closePath) {\r\n const newControlPoint = nodeManager.create(Token.SketchControlPoint);\r\n newControlPoint.position = new KbVector(\r\n parseInt(points[0]) / scaleDivider,\r\n (parseInt(points[1]) / scaleDivider) * -1,\r\n 0\r\n );\r\n newPath.controlPoints.push(newControlPoint);\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction nameGeneratedPaths(node: SketchNode) {\r\n let counter = 0;\r\n node.paths.forEach(path => {\r\n if (counter > 0) {\r\n path.name = 'Path ' + counter.toString();\r\n }\r\n counter++;\r\n });\r\n}\r\n\r\nfunction getPaletteColorStrength(color: ImageTraceColor) {\r\n const saturation = Math.max(color.r, color.g, color.b) - Math.min(color.r, color.g, color.b);\r\n return color.a * 255 + saturation;\r\n}\r\n","import { VertexBuffer } from '@babylonjs/core/Buffers/buffer';\r\nimport { Color4, TmpVectors, Vector2, Vector3, Vector4 } from '@babylonjs/core/Maths';\r\nimport { _CreationDataStorage, Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { FloatArray, Nullable } from '@babylonjs/core/types';\r\nimport { earcut } from '@view/helpers/earcut';\r\nimport { calculateFaceNormal } from './sketching';\r\n\r\nclass CompatibilityOptions {\r\n static useOpenGLOrientationForUV: boolean;\r\n}\r\n/**\r\n * Creates the VertexData for a Ribbon\r\n * @param options an object used to set the following optional parameters for the ribbon, required but can be empty\r\n * * pathArray array of paths, each of which an array of successive Vector3\r\n * * closeArray creates a seam between the first and the last paths of the pathArray, optional, default false\r\n * * closePath creates a seam between the first and the last points of each path of the path array, optional, default false\r\n * * offset a positive integer, only used when pathArray contains a single path (offset = 10 means the point 1 is joined to the point 11), default rounded half size of the pathArray length\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * * invertUV swaps in the U and V coordinates when applying a texture, optional, default false\r\n * * uvs a linear array, of length 2 * number of vertices, of custom UV values, optional\r\n * * colors a linear array, of length 4 * number of vertices, of custom color values, optional\r\n * @returns the VertexData of the ribbon\r\n */\r\n\r\nexport function CreateRibbonVertexData(options: {\r\n pathArray: Vector3[][];\r\n closeArray?: boolean;\r\n closePath?: boolean;\r\n offset?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n invertUV?: boolean;\r\n uvs?: Vector2[];\r\n colors?: Color4[];\r\n}): VertexData {\r\n let pathArray: Vector3[][] = options.pathArray;\r\n const closeArray: boolean = options.closeArray || false;\r\n const closePath: boolean = options.closePath || false;\r\n const invertUV: boolean = options.invertUV || false;\r\n const defaultOffset: number = Math.floor(pathArray[0].length / 2);\r\n let offset: number = options.offset || defaultOffset;\r\n offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset\r\n const sideOrientation: number =\r\n options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n const customUV = options.uvs;\r\n const customColors = options.colors;\r\n\r\n const positions: number[] = [];\r\n const indices: number[] = [];\r\n const normals: number[] = [];\r\n const uvs: number[] = [];\r\n\r\n const us: number[][] = []; // us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id\r\n const vs: number[][] = []; // vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutive paths from pathArray\r\n const uTotalDistance: number[] = []; // uTotalDistance[p] : total distance of path p\r\n const vTotalDistance: number[] = []; // vTotalDistance[i] : total distance between points i of first and last path from pathArray\r\n let minlg: number; // minimal length among all paths from pathArray\r\n const lg: number[] = []; // array of path lengths : nb of vertex per path\r\n const idx: number[] = []; // array of path indexes : index of each path (first vertex) in the total vertex number\r\n let p: number; // path iterator\r\n let i: number; // point iterator\r\n let j: number; // point iterator\r\n\r\n // if single path in pathArray\r\n if (pathArray.length < 2) {\r\n const ar1: Vector3[] = [];\r\n const ar2: Vector3[] = [];\r\n for (i = 0; i < pathArray[0].length - offset; i++) {\r\n ar1.push(pathArray[0][i]);\r\n ar2.push(pathArray[0][i + offset]);\r\n }\r\n pathArray = [ar1, ar2];\r\n }\r\n\r\n // positions and horizontal distances (u)\r\n let idc: number = 0;\r\n const closePathCorr: number = closePath ? 1 : 0; // the final index will be +1 if closePath\r\n const closeArrayCorr: number = closeArray ? 1 : 0;\r\n let path: Vector3[];\r\n let l: number;\r\n minlg = pathArray[0].length;\r\n let vectlg: number;\r\n let dist: number;\r\n for (p = 0; p < pathArray.length + closeArrayCorr; p++) {\r\n uTotalDistance[p] = 0;\r\n us[p] = [0];\r\n path = p === pathArray.length ? pathArray[0] : pathArray[p];\r\n l = path.length;\r\n minlg = minlg < l ? minlg : l;\r\n\r\n j = 0;\r\n while (j < l) {\r\n positions.push(path[j].x, path[j].y, path[j].z);\r\n if (j > 0) {\r\n vectlg = path[j].subtract(path[j - 1]).length();\r\n dist = vectlg + uTotalDistance[p];\r\n us[p].push(dist);\r\n uTotalDistance[p] = dist;\r\n }\r\n j++;\r\n }\r\n\r\n if (closePath) {\r\n // an extra hidden vertex is added in the \"positions\" array\r\n j--;\r\n positions.push(path[0].x, path[0].y, path[0].z);\r\n vectlg = path[j].subtract(path[0]).length();\r\n dist = vectlg + uTotalDistance[p];\r\n us[p].push(dist);\r\n uTotalDistance[p] = dist;\r\n }\r\n\r\n lg[p] = l + closePathCorr;\r\n idx[p] = idc;\r\n idc += l + closePathCorr;\r\n }\r\n\r\n // vertical distances (v)\r\n let path1: Vector3[];\r\n let path2: Vector3[];\r\n let vertex1: Nullable = null;\r\n let vertex2: Nullable = null;\r\n for (i = 0; i < minlg + closePathCorr; i++) {\r\n vTotalDistance[i] = 0;\r\n vs[i] = [0];\r\n for (p = 0; p < pathArray.length - 1 + closeArrayCorr; p++) {\r\n path1 = pathArray[p];\r\n path2 = p === pathArray.length - 1 ? pathArray[0] : pathArray[p + 1];\r\n if (i === minlg) {\r\n // closePath\r\n vertex1 = path1[0];\r\n vertex2 = path2[0];\r\n } else {\r\n vertex1 = path1[i];\r\n vertex2 = path2[i];\r\n }\r\n vectlg = vertex2.subtract(vertex1).length();\r\n dist = vectlg + vTotalDistance[i];\r\n vs[i].push(dist);\r\n vTotalDistance[i] = dist;\r\n }\r\n }\r\n\r\n // uvs\r\n let u: number;\r\n let v: number;\r\n if (customUV) {\r\n for (p = 0; p < customUV.length; p++) {\r\n uvs.push(\r\n customUV[p].x,\r\n CompatibilityOptions.useOpenGLOrientationForUV ? 1.0 - customUV[p].y : customUV[p].y\r\n );\r\n }\r\n } else {\r\n for (p = 0; p < pathArray.length + closeArrayCorr; p++) {\r\n for (i = 0; i < minlg + closePathCorr; i++) {\r\n u = uTotalDistance[p] != 0.0 ? us[p][i] / uTotalDistance[p] : 0.0;\r\n v = vTotalDistance[i] != 0.0 ? vs[i][p] / vTotalDistance[i] : 0.0;\r\n if (invertUV) {\r\n uvs.push(v, u);\r\n } else {\r\n uvs.push(u, CompatibilityOptions.useOpenGLOrientationForUV ? 1.0 - v : v);\r\n }\r\n }\r\n }\r\n }\r\n\r\n // indices\r\n p = 0; // path index\r\n let pi: number = 0; // positions array index\r\n let l1: number = lg[p] - 1; // path1 length\r\n let l2: number = lg[p + 1] - 1; // path2 length\r\n let min: number = l1 < l2 ? l1 : l2; // current path stop index\r\n let shft: number = idx[1] - idx[0]; // shift\r\n const path1nb: number = lg.length - 1; // number of path1 to iterate on\r\n\r\n while (pi <= min && p < path1nb) {\r\n // stay under min and don't go over next to last path\r\n // draw two triangles between path1 (p1) and path2 (p2) : (p1.pi, p2.pi, p1.pi+1) and (p2.pi+1, p1.pi+1, p2.pi) clockwise\r\n\r\n indices.push(pi, pi + shft, pi + 1);\r\n indices.push(pi + shft + 1, pi + 1, pi + shft);\r\n pi += 1;\r\n if (pi === min) {\r\n // if end of one of two consecutive paths reached, go to next existing path\r\n p++;\r\n shft = idx[p + 1] - idx[p];\r\n l1 = lg[p] - 1;\r\n l2 = lg[p + 1] - 1;\r\n pi = idx[p];\r\n min = l1 < l2 ? l1 + pi : l2 + pi;\r\n }\r\n }\r\n\r\n // normals\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n if (closePath) {\r\n // update both the first and last vertex normals to their average value\r\n let indexFirst: number = 0;\r\n let indexLast: number = 0;\r\n for (p = 0; p < pathArray.length; p++) {\r\n indexFirst = idx[p] * 3;\r\n if (p + 1 < pathArray.length) {\r\n indexLast = (idx[p + 1] - 1) * 3;\r\n } else {\r\n indexLast = normals.length - 3;\r\n }\r\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\r\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\r\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\r\n const l = Math.sqrt(\r\n normals[indexFirst] * normals[indexFirst] +\r\n normals[indexFirst + 1] * normals[indexFirst + 1] +\r\n normals[indexFirst + 2] * normals[indexFirst + 2]\r\n );\r\n normals[indexFirst] /= l;\r\n normals[indexFirst + 1] /= l;\r\n normals[indexFirst + 2] /= l;\r\n normals[indexLast] = normals[indexFirst];\r\n normals[indexLast + 1] = normals[indexFirst + 1];\r\n normals[indexLast + 2] = normals[indexFirst + 2];\r\n }\r\n }\r\n\r\n if (closeArray) {\r\n let indexFirst = idx[0] * 3;\r\n let indexLast = idx[pathArray.length] * 3;\r\n for (i = 0; i < minlg + closePathCorr; i++) {\r\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\r\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\r\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\r\n const l = Math.sqrt(\r\n normals[indexFirst] * normals[indexFirst] +\r\n normals[indexFirst + 1] * normals[indexFirst + 1] +\r\n normals[indexFirst + 2] * normals[indexFirst + 2]\r\n );\r\n normals[indexFirst] /= l;\r\n normals[indexFirst + 1] /= l;\r\n normals[indexFirst + 2] /= l;\r\n normals[indexLast] = normals[indexFirst];\r\n normals[indexLast + 1] = normals[indexFirst + 1];\r\n normals[indexLast + 2] = normals[indexFirst + 2];\r\n indexFirst += 3;\r\n indexLast += 3;\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Colors\r\n let colors: Nullable = null;\r\n if (customColors) {\r\n colors = new Float32Array(customColors.length * 4);\r\n for (let c = 0; c < customColors.length; c++) {\r\n colors[c * 4] = customColors[c].r;\r\n colors[c * 4 + 1] = customColors[c].g;\r\n colors[c * 4 + 2] = customColors[c].b;\r\n colors[c * 4 + 3] = customColors[c].a;\r\n }\r\n }\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n const positions32 = new Float32Array(positions);\r\n const normals32 = new Float32Array(normals);\r\n const uvs32 = new Float32Array(uvs);\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions32;\r\n vertexData.normals = normals32;\r\n vertexData.uvs = uvs32;\r\n if (colors) {\r\n vertexData.set(colors, VertexBuffer.ColorKind);\r\n }\r\n\r\n if (closePath) {\r\n (vertexData)._idx = idx;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a ribbon mesh. The ribbon is a parametric shape. It has no predefined shape. Its final shape will depend on the input parameters\r\n * * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry\r\n * * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array\r\n * * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array\r\n * * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path\r\n * * It's the offset to join the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11\r\n * * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph#ribbon\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture\r\n * * The parameter `uvs` is an optional flat array of `Vector2` to update/set each ribbon vertex with its own custom UV values instead of the computed ones\r\n * * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values\r\n * * Note that if you use the parameters `uvs` or `colors`, the passed arrays must be populated with the right number of elements, it is to say the number of ribbon vertices. Remember that if you set `closePath` to `true`, there's one extra vertex per path in the geometry\r\n * * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the ribbon mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/ribbon_extra\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param\r\n */\r\nexport function CreateMiteredRibbon(\r\n name: string,\r\n options: {\r\n pathArray: Vector3[][];\r\n closeArray?: boolean;\r\n closePath?: boolean;\r\n offset?: number;\r\n updatable?: boolean;\r\n cap?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n instance?: Mesh;\r\n invertUV?: boolean;\r\n uvs?: Vector2[];\r\n colors?: Color4[];\r\n },\r\n scene: Nullable = null\r\n): Mesh {\r\n const pathArray = options.pathArray;\r\n const closeArray = options.closeArray;\r\n const closePath = options.closePath;\r\n const cap = options.cap === 0 ? 0 : options.cap || Mesh.NO_CAP;\r\n const sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const instance = options.instance;\r\n const updatable = options.updatable;\r\n\r\n if (instance) {\r\n // existing ribbon instance update\r\n // positionFunction : ribbon case\r\n // only pathArray and sideOrientation parameters are taken into account for positions update\r\n const minimum = TmpVectors.Vector3[0].setAll(Number.MAX_VALUE);\r\n const maximum = TmpVectors.Vector3[1].setAll(-Number.MAX_VALUE);\r\n const positionFunction = (positions: FloatArray) => {\r\n let minlg = pathArray[0].length;\r\n const mesh = instance;\r\n let i = 0;\r\n const ns = mesh._originalBuilderSideOrientation === Mesh.DOUBLESIDE ? 2 : 1;\r\n for (let si = 1; si <= ns; ++si) {\r\n for (let p = 0; p < pathArray.length; ++p) {\r\n const path = pathArray[p];\r\n const l = path.length;\r\n minlg = minlg < l ? minlg : l;\r\n for (let j = 0; j < minlg; ++j) {\r\n const pathPoint = path[j];\r\n positions[i] = pathPoint.x;\r\n positions[i + 1] = pathPoint.y;\r\n positions[i + 2] = pathPoint.z;\r\n minimum.minimizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\r\n maximum.maximizeInPlaceFromFloats(pathPoint.x, pathPoint.y, pathPoint.z);\r\n i += 3;\r\n }\r\n if (mesh._creationDataStorage && mesh._creationDataStorage.closePath) {\r\n const pathPoint = path[0];\r\n positions[i] = pathPoint.x;\r\n positions[i + 1] = pathPoint.y;\r\n positions[i + 2] = pathPoint.z;\r\n i += 3;\r\n }\r\n }\r\n }\r\n };\r\n const positions = instance.getVerticesData(VertexBuffer.PositionKind);\r\n positionFunction(positions);\r\n if (instance.hasBoundingInfo) {\r\n instance.getBoundingInfo().reConstruct(minimum, maximum, instance._worldMatrix);\r\n } else {\r\n instance.buildBoundingInfo(minimum, maximum, instance._worldMatrix);\r\n }\r\n instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);\r\n if (options.colors) {\r\n const colors = instance.getVerticesData(VertexBuffer.ColorKind);\r\n for (let c = 0, colorIndex = 0; c < options.colors.length; c++, colorIndex += 4) {\r\n const color = options.colors[c];\r\n colors[colorIndex] = color.r;\r\n colors[colorIndex + 1] = color.g;\r\n colors[colorIndex + 2] = color.b;\r\n colors[colorIndex + 3] = color.a;\r\n }\r\n instance.updateVerticesData(VertexBuffer.ColorKind, colors, false, false);\r\n }\r\n if (options.uvs) {\r\n const uvs = instance.getVerticesData(VertexBuffer.UVKind);\r\n for (let i = 0; i < options.uvs.length; i++) {\r\n uvs[i * 2] = options.uvs[i].x;\r\n uvs[i * 2 + 1] = CompatibilityOptions.useOpenGLOrientationForUV\r\n ? 1.0 - options.uvs[i].y\r\n : options.uvs[i].y;\r\n }\r\n instance.updateVerticesData(VertexBuffer.UVKind, uvs, false, false);\r\n }\r\n if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {\r\n const indices = instance.getIndices();\r\n const normals = instance.getVerticesData(VertexBuffer.NormalKind);\r\n const params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;\r\n VertexData.ComputeNormals(positions, indices, normals, params);\r\n\r\n if (instance._creationDataStorage && instance._creationDataStorage.closePath) {\r\n let indexFirst: number = 0;\r\n let indexLast: number = 0;\r\n for (let p = 0; p < pathArray.length; p++) {\r\n indexFirst = instance._creationDataStorage!.idx[p] * 3;\r\n if (p + 1 < pathArray.length) {\r\n indexLast = (instance._creationDataStorage!.idx[p + 1] - 1) * 3;\r\n } else {\r\n indexLast = normals.length - 3;\r\n }\r\n normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;\r\n normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;\r\n normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;\r\n normals[indexLast] = normals[indexFirst];\r\n normals[indexLast + 1] = normals[indexFirst + 1];\r\n normals[indexLast + 2] = normals[indexFirst + 2];\r\n }\r\n }\r\n if (!instance.areNormalsFrozen) {\r\n instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);\r\n }\r\n }\r\n return instance;\r\n } else {\r\n // new ribbon creation\r\n\r\n const ribbon = new Mesh(name, scene);\r\n ribbon._originalBuilderSideOrientation = sideOrientation;\r\n ribbon._creationDataStorage = new _CreationDataStorage();\r\n\r\n const vertexData = CreateRibbonVertexData(options);\r\n if (closePath) {\r\n ribbon._creationDataStorage.idx = (vertexData)._idx;\r\n }\r\n ribbon._creationDataStorage.closePath = closePath;\r\n ribbon._creationDataStorage.closeArray = closeArray;\r\n\r\n vertexData.applyToMesh(ribbon, updatable);\r\n\r\n createLineCaps(pathArray, cap, name, ribbon, vertexData);\r\n return ribbon;\r\n }\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateRibbon directly\r\n */\r\nexport const RibbonBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateMiteredRibbon,\r\n};\r\n\r\nfunction createLineCaps(pathArray: Vector3[][], cap: number, featureId: string, ribbon: Mesh, vertexData: VertexData) {\r\n const startCap: number[] = [];\r\n const endCap: number[] = [];\r\n let startCapVectors: Vector3[] = [];\r\n let endCapVectors: Vector3[] = [];\r\n const resultVectors: Vector3[][] = [];\r\n const resultCaps: number[][] = [];\r\n pathArray.forEach(path => {\r\n if (path[0]) {\r\n const vector = path[0];\r\n startCapVectors.push(path[0]);\r\n startCap.push(vector.x, vector.y, vector.z);\r\n }\r\n if (path[path.length - 1]) {\r\n const vector = path[path.length - 1];\r\n endCapVectors.push(path[path.length - 1]);\r\n endCap.push(vector.x, vector.y, vector.z);\r\n }\r\n });\r\n //check to see if the handedness of the endCap is correct. Otherwise, flip it\r\n if (startCapVectors.length > 0) {\r\n const faceNormal = calculateFaceNormal(startCapVectors);\r\n const firstPath = pathArray[0];\r\n if (firstPath.length >= 2) {\r\n const firstPoint = firstPath[0];\r\n const secondPoint = firstPath[1];\r\n\r\n const sketchNativeNormal = secondPoint.subtract(firstPoint);\r\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\r\n if (Vector3.Dot(faceNormal, sketchNativeNormal) < 0) {\r\n startCapVectors = reverseHandednessOfPositions(startCapVectors);\r\n }\r\n }\r\n }\r\n //check to see if the handedness of the endCap is correct. Otherwise, flip it\r\n if (endCapVectors.length > 0) {\r\n const faceNormal = calculateFaceNormal(endCapVectors);\r\n const lastPath = pathArray[pathArray.length - 1];\r\n if (lastPath.length >= 2) {\r\n const lastPoint = lastPath[lastPath.length - 1];\r\n const secondLastPoint = lastPath[lastPath.length - 2];\r\n\r\n const sketchNativeNormal = lastPoint.subtract(secondLastPoint);\r\n // If the rotation handedness is opposite the primary sketch vector, then flip the sketch path\r\n if (Vector3.Dot(faceNormal, sketchNativeNormal) < 0) {\r\n endCapVectors = reverseHandednessOfPositions(endCapVectors);\r\n }\r\n }\r\n }\r\n\r\n if (cap === Mesh.CAP_START) {\r\n const startCapIndices = earcut(startCap, [], 3);\r\n resultCaps.push(startCapIndices);\r\n resultVectors.push(startCapVectors, []);\r\n } else if (cap === Mesh.CAP_END) {\r\n const endCapIndices = earcut(endCap, [], 3);\r\n resultCaps.push(endCapIndices);\r\n\r\n resultVectors.push([], endCapVectors);\r\n } else if (cap === Mesh.CAP_ALL) {\r\n const startCapIndices = earcut(startCap, [], 3);\r\n resultCaps.push(startCapIndices);\r\n const endCapIndices = earcut(endCap, [], 3);\r\n\r\n //offset the endCapIndices otherwise they are the same as the startCapIndices\r\n for (let i = 0; i < endCapIndices.length; i++) {\r\n endCapIndices[i] = endCapIndices[i] + startCapVectors.length;\r\n }\r\n\r\n resultCaps.push(endCapIndices);\r\n resultVectors.push(startCapVectors, endCapVectors);\r\n }\r\n const newVertexData = combineVertexDataWithCaps(vertexData, resultCaps, resultVectors);\r\n newVertexData.applyToMesh(ribbon, true);\r\n return resultCaps;\r\n}\r\n\r\nfunction combineVertexDataWithCaps(\r\n baseVertexData: VertexData,\r\n capMeshIndices: number[][],\r\n capMeshPositions: Vector3[][]\r\n) {\r\n const totalBasePositions = baseVertexData.positions?.length || 0;\r\n const totalBaseNormals = baseVertexData.normals?.length || 0;\r\n const totalBaseUvs = baseVertexData.uvs?.length || 0;\r\n const totalBaseIndices = baseVertexData.indices?.length || 0;\r\n\r\n const newPositions: number[] = [];\r\n const newNormals: number[] = [];\r\n const newUvs: number[] = [];\r\n const newIndices: number[] = [];\r\n\r\n const startCapPositions = capMeshPositions[0];\r\n const endCapPositions = capMeshPositions[1];\r\n\r\n capMeshIndices.forEach(meshIndices => {\r\n meshIndices.forEach(index => {\r\n const newIndex = index + totalBasePositions / 3;\r\n newIndices.push(newIndex);\r\n });\r\n });\r\n\r\n if (startCapPositions && startCapPositions.length !== 0) {\r\n const normal = calculateFaceNormal(startCapPositions);\r\n startCapPositions.forEach(position => {\r\n newPositions.push(position.x, position.y, position.z);\r\n newNormals.push(normal.x, normal.y, normal.z);\r\n });\r\n const generatedUvs = generateUvsForCaps(startCapPositions);\r\n newUvs.push(...generatedUvs);\r\n }\r\n\r\n if (endCapPositions && endCapPositions.length !== 0) {\r\n const normal = calculateFaceNormal(endCapPositions);\r\n endCapPositions.forEach(position => {\r\n newPositions.push(position.x, position.y, position.z);\r\n newNormals.push(normal.x, normal.y, normal.z);\r\n });\r\n const generatedUvs = generateUvsForCaps(endCapPositions);\r\n newUvs.push(...generatedUvs);\r\n }\r\n\r\n const newVertexData = new VertexData();\r\n newVertexData.positions = newPositions;\r\n newVertexData.normals = newNormals;\r\n newVertexData.indices = newIndices;\r\n\r\n const combinedPositionsArray = new Float32Array(totalBasePositions + newPositions.length);\r\n const combinedNormalsArray = new Float32Array(totalBaseNormals + newNormals.length);\r\n const combinedUvsArray = new Float32Array((combinedPositionsArray.length / 3) * 2);\r\n const combinedIndicesArray = new Uint16Array(totalBaseIndices + newIndices.length);\r\n\r\n if (baseVertexData.positions) {\r\n combinedPositionsArray.set(baseVertexData.positions);\r\n combinedPositionsArray.set(newPositions, totalBasePositions);\r\n baseVertexData.positions = combinedPositionsArray;\r\n }\r\n if (baseVertexData.normals) {\r\n combinedNormalsArray.set(baseVertexData.normals);\r\n combinedNormalsArray.set(newNormals, totalBaseNormals);\r\n baseVertexData.normals = combinedNormalsArray;\r\n }\r\n if (baseVertexData.uvs) {\r\n combinedUvsArray.set(baseVertexData.uvs);\r\n combinedUvsArray.set(newUvs, totalBaseUvs);\r\n baseVertexData.uvs = combinedUvsArray;\r\n }\r\n if (baseVertexData.indices) {\r\n combinedIndicesArray.set(baseVertexData.indices);\r\n combinedIndicesArray.set(newIndices, totalBaseIndices);\r\n baseVertexData.indices = combinedIndicesArray;\r\n }\r\n return baseVertexData;\r\n}\r\n\r\nfunction reverseHandednessOfPositions(positionsArray: Vector3[]) {\r\n const reversedArray: Vector3[] = [];\r\n positionsArray.forEach(position => {\r\n reversedArray.unshift(position);\r\n });\r\n return reversedArray;\r\n}\r\n\r\nfunction generateUvsForCaps(positions: Vector3[]) {\r\n const newUvs: number[] = [];\r\n const operationVectors = findDistinctVectors(positions);\r\n if (operationVectors) {\r\n const vector1 = operationVectors[0];\r\n const vector2 = operationVectors[1];\r\n const vector3 = operationVectors[2];\r\n\r\n //xp1 is the capNormal\r\n if (vector1 && vector2 && vector3) {\r\n const xp1 = vector1.cross(vector2.subtract(vector3));\r\n const xp2 = vector1.subtract(vector2).cross(xp1);\r\n const normalizedXp3 = xp1.cross(xp2).normalize();\r\n const normalizedXp2 = xp2.normalize();\r\n positions.forEach(position => {\r\n const u = Vector3.Dot(position, normalizedXp2);\r\n const v = Vector3.Dot(position, normalizedXp3);\r\n newUvs.push(u, v);\r\n });\r\n }\r\n } else {\r\n positions.forEach(position => {\r\n newUvs.push(0, 0);\r\n });\r\n }\r\n return newUvs;\r\n}\r\n\r\nfunction findDistinctVectors(vectors: Vector3[]) {\r\n let vector1 = Vector3.Zero();\r\n let vector2 = Vector3.Zero();\r\n let vector3 = Vector3.Zero();\r\n for (let i = 0; i < vectors.length; i++) {\r\n let isZeroVector = false;\r\n if (vectors[i].x === 0 && vectors[i].y === 0 && vectors[i].z === 0) {\r\n isZeroVector = true;\r\n }\r\n if (!isZeroVector) {\r\n vector1 = vectors[i];\r\n break;\r\n }\r\n }\r\n for (let i = 0; i < vectors.length; i++) {\r\n let isZeroVector = false;\r\n if (vectors[i].x === 0 && vectors[i].y === 0 && vectors[i].z === 0) {\r\n isZeroVector = true;\r\n }\r\n if (!isZeroVector && vectors[i] !== vector1) {\r\n vector2 = vectors[i];\r\n break;\r\n }\r\n }\r\n for (let i = 0; i < vectors.length; i++) {\r\n if (vectors[i] !== vector2 && vectors[i] !== vector1) {\r\n vector3 = vectors[i];\r\n break;\r\n }\r\n }\r\n return [vector1, vector2, vector3];\r\n}\r\n\r\nVertexData.CreateRibbon = CreateRibbonVertexData;\r\n\r\nMesh.CreateRibbon = (\r\n name: string,\r\n pathArray: Vector3[][],\r\n closeArray: boolean = false,\r\n closePath: boolean,\r\n offset: number,\r\n scene?: Scene,\r\n updatable: boolean = false,\r\n sideOrientation?: number,\r\n instance?: Mesh\r\n) => {\r\n return CreateMiteredRibbon(\r\n name,\r\n {\r\n pathArray: pathArray,\r\n closeArray: closeArray,\r\n closePath: closePath,\r\n offset: offset,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n instance: instance,\r\n },\r\n scene\r\n );\r\n};\r\n","import { Ray } from '@babylonjs/core/Culling/ray';\r\nimport { Matrix, Plane, Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { SweepFeature } from '@models/classes/features/sweep-feature';\r\nimport { SketchNode } from '@models/classes/meshes/sketch-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { rotationToVector } from '@view/helpers/math-helper';\r\nimport { CreateMiteredRibbon } from '@view/modules/miteredRibbonBuilder';\r\nimport { parseSketchGeometry } from '@view/modules/sketching/util';\r\nimport { applyExtrusion } from './extrude';\r\nimport { FeatureRenderer } from './feature';\r\n\r\ninterface ExtrudeOptions {\r\n shape: Vector3[];\r\n path: Vector3[];\r\n updatable: boolean;\r\n cap: number;\r\n closeShape: boolean;\r\n}\r\n\r\n//const capMap: Map = new Map();\r\n\r\nexport class SweepRenderer extends FeatureRenderer {\r\n modelToken = Token.SweepFeature;\r\n\r\n updateMeshGeometry(\r\n feature: SweepFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n let parentMesh: TransformNode | undefined;\r\n if (feature._parent) {\r\n parentMesh = this.viewer.getRendererNode(feature._parent);\r\n }\r\n\r\n let pathPoints: Vector3[] = [];\r\n let targetPathNode: SketchNode | undefined;\r\n let pathMesh: Mesh | undefined;\r\n if (feature.path) {\r\n targetPathNode = feature._manager?.getById(feature.path);\r\n }\r\n if (targetPathNode) {\r\n pathMesh = this.viewer.getRendererNode(targetPathNode) as Mesh;\r\n const pathVertexData = SubmeshVertexData.ExtractFromMesh(pathMesh);\r\n const { segments } = parseSketchGeometry(pathVertexData);\r\n if (segments.length > 0) {\r\n pathPoints = segments[0];\r\n }\r\n }\r\n\r\n if (\r\n parentMesh &&\r\n targetPathNode &&\r\n pathMesh &&\r\n newVertexData.positions &&\r\n newVertexData.positions.length > 0 &&\r\n pathPoints.length > 1\r\n ) {\r\n const { segments } = parseSketchGeometry(newVertexData);\r\n const extrudedMeshes: Mesh[] = [];\r\n\r\n for (let i = 0; i < segments.length; i++) {\r\n const shape = segments[i];\r\n\r\n // Transform the path and the profile sketch into world space so we can combine them without worrying about local transforms\r\n const pathTransform = pathMesh.computeWorldMatrix();\r\n const sketchTransform = parentMesh.computeWorldMatrix();\r\n for (let i = 0; i < pathPoints.length; i++) {\r\n Vector3.TransformCoordinatesToRef(pathPoints[i], pathTransform, pathPoints[i]);\r\n }\r\n for (let i = 0; i < shape.length; i++) {\r\n Vector3.TransformCoordinatesToRef(shape[i], sketchTransform, shape[i]);\r\n }\r\n\r\n // Determine the vector to use as the primary direction of the extrusion\r\n const pathPrimaryVector = Vector3.Zero();\r\n let j = 0;\r\n while (pathPrimaryVector.length() === 0) {\r\n j++;\r\n pathPrimaryVector.copyFrom(pathPoints[j]).subtractInPlace(pathPoints[0]);\r\n }\r\n\r\n // Calculate the matrix to move the sketch path primary direction to be perpindicular to the XY plane for consistent behavior\r\n const rotToZ = rotationToVector(new Vector3(0, 0, 1), pathPrimaryVector);\r\n const pathTransformToZ = new Matrix();\r\n const pathTransformToZInv = new Matrix();\r\n rotToZ.toRotationMatrix(pathTransformToZ);\r\n Matrix.Compose(Vector3.One(), Quaternion.Identity(), pathPoints[0].scale(-1)).multiplyToRef(\r\n pathTransformToZ,\r\n pathTransformToZ\r\n );\r\n pathTransformToZ.invertToRef(pathTransformToZInv);\r\n\r\n // Transform both the path and the extrusion shape with the same matrix so the\r\n // shape and the path are positioned the same as before in relation to each other\r\n // but oriented to be extruded out of the XY plane, in the Z direction\r\n for (let i = 0; i < pathPoints.length; i++) {\r\n Vector3.TransformCoordinatesToRef(pathPoints[i], pathTransformToZ, pathPoints[i]);\r\n }\r\n for (let i = 0; i < shape.length; i++) {\r\n Vector3.TransformCoordinatesToRef(shape[i], pathTransformToZ, shape[i]);\r\n // Project the extrude shape onto the XY plane so that it's perfecly perpindicular to the sweep path\r\n shape[i].set(shape[i].x, shape[i].y, 0);\r\n }\r\n\r\n const extrudeOptions: ExtrudeOptions = {\r\n shape,\r\n path: pathPoints,\r\n updatable: false,\r\n cap: Mesh.NO_CAP,\r\n closeShape: false,\r\n // firstNormal: sketchNormal, this property is added in a future version of babylon\r\n };\r\n\r\n if (feature.capEnd && feature.capStart) {\r\n extrudeOptions.cap = Mesh.CAP_ALL;\r\n extrudeOptions.closeShape = true;\r\n } else if (feature.capStart) {\r\n extrudeOptions.cap = Mesh.CAP_START;\r\n extrudeOptions.closeShape = true;\r\n } else if (feature.capEnd) {\r\n extrudeOptions.cap = Mesh.CAP_END;\r\n extrudeOptions.closeShape = true;\r\n }\r\n\r\n // Perform the extrusion of the shape defined along the XY plane, to the path oriented to coincide with the Z+ axis\r\n let extruded: Mesh;\r\n if (feature.mitredExtrusion) {\r\n extrudeOptions.closeShape = false;\r\n extruded = this.mitredExtrude(feature._dynamicId, extrudeOptions, this.scene);\r\n } else {\r\n extruded = MeshBuilder.ExtrudeShape(feature._dynamicId, extrudeOptions, this.scene);\r\n }\r\n\r\n // Rotate the resulting extruded shape to match the orientation of the original shape profile\r\n sketchTransform.invert();\r\n pathTransformToZInv.multiplyToRef(sketchTransform, pathTransformToZInv);\r\n extruded.bakeTransformIntoVertices(pathTransformToZInv);\r\n\r\n extrudedMeshes.push(extruded);\r\n }\r\n\r\n const extrudedAll = Mesh.MergeMeshes(extrudedMeshes, true);\r\n if (extrudedAll) {\r\n applyExtrusion(newVertexData, extrudedAll, false);\r\n extrudedAll.dispose();\r\n }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n\r\n mitredExtrude(featureId: string, options: ExtrudeOptions, scene: Scene) {\r\n const shape = options.shape;\r\n const path = options.path;\r\n const closed = options.closeShape || false;\r\n\r\n const nbPoints = path.length;\r\n const line = Vector3.Zero();\r\n const nextLine = Vector3.Zero();\r\n let axisX = Vector3.Zero();\r\n let axisY = Vector3.Zero();\r\n let axisZ = Vector3.Zero();\r\n let nextAxisX = Vector3.Zero();\r\n let nextAxisY = Vector3.Zero();\r\n let nextAxisZ = Vector3.Zero();\r\n let startPoint = Vector3.Zero();\r\n const nextStartPoint = Vector3.Zero();\r\n const bisector = Vector3.Zero();\r\n let distance = 0;\r\n let ray;\r\n\r\n const allPaths = [];\r\n // Note that the sketch will always be rotated such that the profile is in the XY plane\r\n const up = Vector3.Up();\r\n\r\n for (let s = 0; s < shape.length; s++) {\r\n path[1].subtractToRef(path[0], line);\r\n axisZ = line.clone().normalize();\r\n axisX = Vector3.Cross(Vector3.Up(), axisZ).normalize();\r\n axisY = Vector3.Cross(axisZ, axisX);\r\n startPoint = path[0].add(axisX.scale(shape[s].x)).add(axisY.scale(shape[s].y));\r\n const ribbonPath = [startPoint.clone()];\r\n for (let p = 0; p < nbPoints - 2; p++) {\r\n path[p + 2].subtractToRef(path[p + 1], nextLine);\r\n nextAxisZ = nextLine.clone().normalize();\r\n nextAxisX = Vector3.Cross(up, nextAxisZ).normalize();\r\n nextAxisY = Vector3.Cross(nextAxisZ, nextAxisX);\r\n nextAxisZ.subtractToRef(axisZ, bisector);\r\n const planeParallel = Vector3.Cross(nextAxisZ, axisZ);\r\n const planeNormal = Vector3.Cross(planeParallel, bisector);\r\n const plane = Plane.FromPositionAndNormal(path[p + 1], planeNormal);\r\n ray = new Ray(startPoint, axisZ);\r\n distance = ray.intersectsPlane(plane) || 0;\r\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\r\n ribbonPath.push(nextStartPoint.clone());\r\n\r\n axisX = nextAxisX.clone();\r\n axisY = nextAxisY.clone();\r\n axisZ = nextAxisZ.clone();\r\n startPoint = nextStartPoint.clone();\r\n }\r\n // Last Point\r\n if (closed) {\r\n path[0].subtractToRef(path[nbPoints - 1], nextLine);\r\n nextAxisZ = nextLine.clone().normalize();\r\n nextAxisX = Vector3.Cross(up, nextAxisZ).normalize();\r\n nextAxisY = Vector3.Cross(nextAxisZ, nextAxisX);\r\n nextAxisZ.subtractToRef(axisZ, bisector);\r\n const closedPlaneParallel = Vector3.Cross(nextAxisZ, axisZ);\r\n const closedPlaneNormal = Vector3.Cross(closedPlaneParallel, bisector);\r\n const closedPlane = Plane.FromPositionAndNormal(path[nbPoints - 1], closedPlaneNormal);\r\n ray = new Ray(startPoint, axisZ);\r\n distance = ray.intersectsPlane(closedPlane) || 0;\r\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\r\n ribbonPath.push(nextStartPoint.clone());\r\n\r\n axisX = nextAxisX.clone();\r\n axisY = nextAxisY.clone();\r\n axisZ = nextAxisZ.clone();\r\n startPoint = nextStartPoint.clone();\r\n\r\n path[1].subtractToRef(path[0], nextLine);\r\n nextAxisZ = nextLine.clone().normalize();\r\n nextAxisX = Vector3.Cross(up, nextAxisZ).normalize();\r\n nextAxisY = Vector3.Cross(nextAxisZ, nextAxisX);\r\n nextAxisZ.subtractToRef(axisZ, bisector);\r\n const planeParallel = Vector3.Cross(nextAxisZ, axisZ);\r\n const planeNormal = Vector3.Cross(planeParallel, bisector);\r\n const plane = Plane.FromPositionAndNormal(path[0], planeNormal);\r\n ray = new Ray(startPoint, axisZ);\r\n distance = ray.intersectsPlane(plane) || 0;\r\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\r\n ribbonPath.shift();\r\n ribbonPath.unshift(nextStartPoint.clone());\r\n } else {\r\n const planeNormal = axisZ;\r\n const plane = Plane.FromPositionAndNormal(path[nbPoints - 1], planeNormal);\r\n ray = new Ray(startPoint, axisZ);\r\n const distance = ray.intersectsPlane(plane) || 0;\r\n startPoint.addToRef(axisZ.scale(distance), nextStartPoint);\r\n ribbonPath.push(nextStartPoint.clone());\r\n }\r\n allPaths.push(ribbonPath);\r\n }\r\n\r\n const ribbon = CreateMiteredRibbon(\r\n featureId,\r\n {\r\n pathArray: allPaths,\r\n sideOrientation: Mesh.DOUBLESIDE,\r\n closeArray: false,\r\n closePath: false,\r\n cap: options.cap,\r\n },\r\n scene\r\n );\r\n\r\n return ribbon;\r\n }\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { Token, TransformFeature } from '@models/classes';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nexport class TransformRenderer extends FeatureRenderer {\r\n modelToken = Token.TransformFeature;\r\n updateMeshGeometry(\r\n feature: TransformFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n const parentMesh = feature._parent;\r\n\r\n if (parentMesh && newVertexData.positions && newVertexData.positions.length > 0) {\r\n const newMeshVertexPositions = newVertexData.positions;\r\n const indexCount = newMeshVertexPositions.length / 3;\r\n const pivot = parentMesh.pivot.toVec3();\r\n const vertexPosition = new Vector3();\r\n\r\n let scaleVector: Vector3 | undefined;\r\n if (!feature.scale.equal({ x: 1, y: 1, z: 1 })) {\r\n scaleVector = feature.scale.toVec3();\r\n }\r\n\r\n for (let i = 0; i < indexCount; i++) {\r\n if (pivot && scaleVector) {\r\n vertexPosition.copyFromFloats(\r\n newMeshVertexPositions[i * 3] - pivot.x,\r\n newMeshVertexPositions[i * 3 + 1] - pivot.y,\r\n newMeshVertexPositions[i * 3 + 2] - pivot.z\r\n );\r\n\r\n if (scaleVector) {\r\n vertexPosition.multiplyInPlace(scaleVector);\r\n }\r\n\r\n vertexPosition.addInPlace(pivot);\r\n\r\n newMeshVertexPositions[i * 3] = vertexPosition.x;\r\n newMeshVertexPositions[i * 3 + 1] = vertexPosition.y;\r\n newMeshVertexPositions[i * 3 + 2] = vertexPosition.z;\r\n }\r\n }\r\n }\r\n\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n}\r\n","import { SubmeshData } from '@models/classes/features/submesh-feature';\r\nimport { WeldVerticesFeature } from '@models/classes/features/weld-vertices-feature';\r\nimport { Token } from '@models/classes/token';\r\nimport { SubmeshVertexData } from '@view/helpers/geometry-helper';\r\nimport { FeatureRenderer } from './feature';\r\n\r\nexport class WeldVerticesRenderer extends FeatureRenderer {\r\n modelToken = Token.WeldVerticesFeature;\r\n updateMeshGeometry(\r\n feature: WeldVerticesFeature,\r\n vertexData: SubmeshVertexData,\r\n vertexDataChanges: Partial\r\n ) {\r\n const newVertexData = super.updateMeshGeometry(feature, vertexData, vertexDataChanges);\r\n const parentMesh = feature._parent;\r\n const indices = newVertexData.indices;\r\n let positions = newVertexData.positions;\r\n let normals = newVertexData.normals;\r\n let uvs = newVertexData.uvs;\r\n const positionAverage: number[] = [0, 0, 0];\r\n const normalsAverage: number[] = [0, 0, 0];\r\n const uvAverage: number[] = [0, 0];\r\n const selectedIndices: number[] = [];\r\n const selectedVertices: number[] = [];\r\n const selectedIndicesArray: boolean[] = [];\r\n const vertexVisited: boolean[] = [];\r\n const indicesResult: number[] = [];\r\n const submeshDataArray: SubmeshData[] = [];\r\n\r\n if (parentMesh && newVertexData.positions && newVertexData.positions.length > 0) {\r\n if (newVertexData.positions) {\r\n positions = newVertexData.positions as number[];\r\n } else if (vertexData.positions) {\r\n positions = Array.from(vertexData.positions);\r\n } else {\r\n positions = [];\r\n }\r\n\r\n if (newVertexData.normals) {\r\n normals = newVertexData.normals as number[];\r\n } else if (vertexData.normals) {\r\n normals = Array.from(vertexData.normals);\r\n }\r\n\r\n if (newVertexData.uvs) {\r\n uvs = newVertexData.uvs as number[];\r\n } else if (vertexData.uvs) {\r\n uvs = Array.from(vertexData.uvs);\r\n }\r\n\r\n if (feature.vertexIndices && feature.vertexIndices.length > 0) {\r\n //creating sparse array to see which vertices are selected\r\n for (let i = 0; i < feature.vertexIndices.length; i++) {\r\n selectedIndicesArray[feature.vertexIndices[i]] = true;\r\n }\r\n\r\n if (indices) {\r\n //Looping through indices and checking which indices are touched by the selected vertices\r\n for (let j = 0; j < indices?.length; j++) {\r\n if (selectedIndicesArray[indices[j]]) {\r\n selectedIndices.push(j);\r\n if (!vertexVisited[indices[j]]) {\r\n selectedVertices.push(j);\r\n vertexVisited[indices[j]] = true;\r\n }\r\n }\r\n }\r\n }\r\n\r\n //averaging all selected positions of the vertex\r\n for (let i = 0; i < selectedVertices.length; i++) {\r\n if (indices) {\r\n const vertex = indices[selectedVertices[i]];\r\n for (let j = 0; j < 3; j++) {\r\n positionAverage[j] = positionAverage[j] + positions[vertex * 3 + j];\r\n if (normals) {\r\n normalsAverage[j] = normalsAverage[j] + normals[vertex * 3 + j];\r\n }\r\n if (j != 2 && uvs) {\r\n uvAverage[j] = uvAverage[j] + uvs[vertex * 2 + j];\r\n }\r\n }\r\n }\r\n }\r\n for (let i = 0; i < 3; i++) {\r\n positionAverage[i] = positionAverage[i] / selectedVertices.length;\r\n normalsAverage[i] = normalsAverage[i] / selectedVertices.length;\r\n if (i != 2) {\r\n uvAverage[i] = uvAverage[i] / selectedVertices.length;\r\n }\r\n }\r\n\r\n //setting one vertex to calculated average position\r\n if (indices) {\r\n const targetIndex = indices[selectedVertices[0]];\r\n for (let i = 0; i < 3; i++) {\r\n positions[targetIndex * 3 + i] = positionAverage[i];\r\n if (normals) {\r\n normals[targetIndex * 3 + i] = normalsAverage[i];\r\n }\r\n if (i != 2 && uvs) {\r\n uvs[targetIndex * 2 + i] = uvAverage[i];\r\n }\r\n }\r\n\r\n //setting all selectedIndices to targetIndex with new position\r\n for (let i = 0; i < selectedIndices.length; i++) {\r\n indices[selectedIndices[i]] = targetIndex;\r\n }\r\n\r\n //looping through indices and pruning out polygons that make up invalid geometry\r\n for (let i = 0; i < indices.length; i = i + 3) {\r\n if (\r\n indices[i] != indices[i + 1] &&\r\n indices[i] != indices[i + 2] &&\r\n indices[i + 1] != indices[i + 2]\r\n ) {\r\n indicesResult.push(indices[i]);\r\n indicesResult.push(indices[i + 1]);\r\n indicesResult.push(indices[i + 2]);\r\n }\r\n }\r\n\r\n //handling submesh data\r\n\r\n if (vertexData.submeshData) {\r\n for (let i = 0; i < vertexData.submeshData.length; i++) {\r\n const submeshData = vertexData.submeshData[i];\r\n submeshData.indexCount = indicesResult.length;\r\n submeshDataArray[i] = submeshData;\r\n }\r\n }\r\n }\r\n }\r\n newVertexData.positions = positions;\r\n newVertexData.indices = indicesResult;\r\n newVertexData.uvs = uvs;\r\n newVertexData.normals = normals;\r\n newVertexData.submeshData = submeshDataArray;\r\n }\r\n return newVertexData;\r\n }\r\n\r\n update3dInternal() {}\r\n}\r\n","import { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eMeshChangeTypes, Feature } from '@models/classes/features/feature';\r\nimport { SubmeshData } from '@models/classes/features/submesh-feature';\r\nimport { CustomMeshNode } from '@models/classes/meshes/custom-mesh-node';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { isTrackedClass, ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SubmeshVertexData, verifyGeometry } from '@view/helpers/geometry-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { NormalSmoothingRenderer } from './features';\r\nimport { CircularPatternRenderer } from './features/circular-pattern';\r\nimport { DeleteFacesRenderer } from './features/delete-faces';\r\nimport { DisplacementMapRenderer } from './features/displacement-map';\r\nimport { ExtrudeRenderer } from './features/extrude';\r\nimport { FeatureRenderer } from './features/feature';\r\nimport { JoinGeometryRenderer } from './features/join-geometry';\r\nimport { LinearPatternRenderer } from './features/linear-pattern';\r\nimport { MirrorFeatureRenderer } from './features/mirror';\r\nimport { MoveVerticesRenderer } from './features/move-vertices';\r\nimport { SliceFeatureRenderer } from './features/slice';\r\nimport { SubmeshRenderer } from './features/submesh';\r\nimport { SweepRenderer } from './features/sweep';\r\nimport { TransformRenderer } from './features/transform';\r\nimport { UvMapRenderer } from './features/uvmap';\r\nimport { WeldVerticesRenderer } from './features/weld-vertices';\r\nimport { Renderer } from './renderer';\r\nimport { RendererManager } from './renderer-manager';\r\n\r\nexport class FeatureStackRenderer extends Renderer {\r\n queuedGeometryToReset = new Map>();\r\n queuedFeaturesToProcess = new Map>(); // index of feature to start recalculation at\r\n processedFeatures = new Map();\r\n featureOrder = new Map();\r\n renderers = new Map>();\r\n\r\n constructor(viewer: KbViewer, scene: Scene, private rendererManager: RendererManager) {\r\n super(viewer, scene);\r\n const moveVertices = new MoveVerticesRenderer(viewer, scene);\r\n this.renderers.set(Token.MoveVerticesFeature, moveVertices);\r\n const weldVertices = new WeldVerticesRenderer(viewer, scene);\r\n this.renderers.set(Token.WeldVerticesFeature, weldVertices);\r\n const displacementMap = new DisplacementMapRenderer(viewer, scene);\r\n this.renderers.set(Token.DisplacementMapFeature, displacementMap);\r\n const uvMaps = new UvMapRenderer(viewer, scene);\r\n this.renderers.set(Token.UvMapFeature, uvMaps);\r\n const submeshes = new SubmeshRenderer(viewer, scene, rendererManager);\r\n this.renderers.set(Token.SubmeshFeature, submeshes);\r\n const linearPatterns = new LinearPatternRenderer(viewer, scene);\r\n this.renderers.set(Token.LinearPatternFeature, linearPatterns);\r\n const circularPatterns = new CircularPatternRenderer(viewer, scene);\r\n this.renderers.set(Token.CircularPatternFeature, circularPatterns);\r\n const joinGeometry = new JoinGeometryRenderer(viewer, scene);\r\n this.renderers.set(Token.JoinGeometryFeature, joinGeometry);\r\n const deleteFaces = new DeleteFacesRenderer(viewer, scene);\r\n this.renderers.set(Token.DeleteFacesFeature, deleteFaces);\r\n const normalSmoothing = new NormalSmoothingRenderer(viewer, scene);\r\n this.renderers.set(Token.NormalSmoothingFeature, normalSmoothing);\r\n const slice = new SliceFeatureRenderer(viewer, scene);\r\n this.renderers.set(Token.SliceFeature, slice);\r\n const mirror = new MirrorFeatureRenderer(viewer, scene);\r\n this.renderers.set(Token.MirrorFeature, mirror);\r\n const transform = new TransformRenderer(viewer, scene);\r\n this.renderers.set(Token.TransformFeature, transform);\r\n const extrude = new ExtrudeRenderer(viewer, scene);\r\n this.renderers.set(Token.ExtrudeFeature, extrude);\r\n const sweep = new SweepRenderer(viewer, scene);\r\n this.renderers.set(Token.SweepFeature, sweep);\r\n }\r\n\r\n modelToken = Token.Feature;\r\n\r\n forceRebuildGeometry(meshNode: MeshNode, vertexData?: SubmeshVertexData) {\r\n if (!this.processedFeatures.has(meshNode._dynamicId)) {\r\n if (vertexData) {\r\n this.applyNewVertexData(meshNode, {}, vertexData);\r\n }\r\n return;\r\n }\r\n\r\n if (!vertexData) {\r\n vertexData = this.rendererManager.mesh.rebuildBaseGeometry(meshNode)!;\r\n }\r\n this.queuedGeometryToReset.set(meshNode._dynamicId, vertexData);\r\n const allChanges = new Set(meshNode.features.map((_, i) => i));\r\n this.queuedFeaturesToProcess.set(meshNode, allChanges);\r\n\r\n const movedIndex = this.getMovedFeatureIndex(meshNode);\r\n this.updateFeatureOrder(meshNode);\r\n if (movedIndex !== undefined && movedIndex >= 0) {\r\n this.recursivelyUpdateFeatureVisibility([meshNode.features[movedIndex]], meshNode.features, []);\r\n }\r\n this.update3dGeometry(0, meshNode);\r\n\r\n this.renderers.forEach(renderer => {\r\n renderer.clearCache(meshNode.features);\r\n });\r\n }\r\n\r\n resetMeshGeometry(\r\n meshNode: SpaceNode,\r\n dataTypes: Set | null,\r\n vertexData?: SubmeshVertexData | null,\r\n hasFeatureToUpdate = false\r\n ) {\r\n if (!vertexData) {\r\n vertexData = this.rendererManager.mesh.rebuildBaseGeometry(meshNode);\r\n }\r\n\r\n if (vertexData) {\r\n let newGeometry: Partial;\r\n if (!dataTypes) {\r\n newGeometry = vertexData;\r\n } else {\r\n // If the feature that changed affects aspects of a geometry, reset those aspects so we can recalculate them with\r\n // this or any other features that affected that aspect\r\n newGeometry = this.queuedGeometryToReset.get(meshNode._dynamicId) || {};\r\n\r\n // Null means that the vertex data specifically doesn't have those geometries, so they will be cleared\r\n if (!newGeometry.positions && hasChange(dataTypes, eMeshChangeTypes.VertexPositions)) {\r\n newGeometry.positions = vertexData.positions || null;\r\n }\r\n if (!newGeometry.normals && hasChange(dataTypes, eMeshChangeTypes.VertexNormals)) {\r\n newGeometry.normals = vertexData.normals || null;\r\n }\r\n if (!newGeometry.uvs && hasChange(dataTypes, eMeshChangeTypes.VertexUvs)) {\r\n newGeometry.uvs = vertexData.uvs || null;\r\n }\r\n if (!newGeometry.indices && hasChange(dataTypes, eMeshChangeTypes.VertexIndices)) {\r\n newGeometry.indices = vertexData.indices || null;\r\n }\r\n if (!newGeometry.submeshData && hasChange(dataTypes, eMeshChangeTypes.Submeshes)) {\r\n newGeometry.submeshData = vertexData.submeshData || null;\r\n }\r\n }\r\n this.queuedGeometryToReset.set(meshNode._dynamicId, newGeometry);\r\n\r\n // If a feature affects a geometry element that is being reset, then it will need to be recalculated\r\n for (let i = 0; i < meshNode.features.length; i++) {\r\n const feature = meshNode.features[i];\r\n\r\n // If this geometry hasn't been flagged for recalculation, see if it needs to be\r\n if (\r\n !this.queuedFeaturesToProcess.get(meshNode)?.has(i) &&\r\n feature.affects &&\r\n featureIsAffected(feature.affects, newGeometry)\r\n ) {\r\n hasFeatureToUpdate = true;\r\n this.queueGeometryUpdate(meshNode, i);\r\n this.resetMeshGeometry(meshNode, feature.affects, vertexData, hasFeatureToUpdate);\r\n }\r\n }\r\n\r\n // If there are no features to be recalculated but we need to reset some mesh geometry, then do that directly.\r\n if (!hasFeatureToUpdate && Object.getOwnPropertyNames(newGeometry).length > 0) {\r\n const existingVertexData = this.rendererManager.mesh.getMeshGeometry(meshNode) || vertexData;\r\n this.queuedGeometryToReset.delete(meshNode._dynamicId);\r\n this.applyNewVertexData(meshNode, newGeometry, existingVertexData);\r\n }\r\n }\r\n this.updateFeatureOrder(meshNode);\r\n }\r\n\r\n transformChanged(meshNode: SpaceNode) {\r\n // If the transform on a mesh changes, any features that depend on the transform need to be updated\r\n for (let i = 0; i < meshNode.features.length; i++) {\r\n const feature = meshNode.features[i];\r\n\r\n if (feature.affectedBy && feature.affectedBy.has(eMeshChangeTypes.Transform)) {\r\n this.queueGeometryUpdate(meshNode, i);\r\n }\r\n }\r\n }\r\n\r\n queueGeometryUpdate(meshNode: SpaceNode, index?: number) {\r\n let currentChanges = this.queuedFeaturesToProcess.get(meshNode);\r\n if (!currentChanges) {\r\n currentChanges = new Set();\r\n this.queuedFeaturesToProcess.set(meshNode, currentChanges);\r\n }\r\n\r\n currentChanges.add(index === undefined ? 0 : index);\r\n }\r\n\r\n update3dInternal(feature: ITrackedClass) {\r\n if (isTrackedClass(feature)) {\r\n if (!feature.enabled || feature._suppressed) {\r\n if (feature.changes.has('enabled') || feature.changes.has('_suppressed')) {\r\n this.delete3d(feature, true);\r\n }\r\n\r\n return;\r\n }\r\n\r\n const index = this.getFeatureIndexOnParent(feature);\r\n if (index > -1) {\r\n this.queueGeometryUpdate(feature._parent!, index);\r\n }\r\n\r\n // Process all of the feature's non-geometry effects\r\n const renderer = this.renderers.get(Token.withKey(feature.$type));\r\n if (!renderer) {\r\n throw Error('no renderer for feature');\r\n }\r\n renderer.update3d(feature);\r\n }\r\n }\r\n\r\n update3dGeometry(renderStartTime = 0, node?: MeshNode) {\r\n if (!node) {\r\n for (const node of this.queuedFeaturesToProcess.keys()) {\r\n if (node instanceof MeshNode) {\r\n this.update3dGeometry(renderStartTime || performance.now(), node);\r\n }\r\n }\r\n return;\r\n }\r\n\r\n if (this.queuedFeaturesToProcess.has(node) && (!(node instanceof CustomMeshNode) || node.geometryLoaded)) {\r\n const queuedFeatureToProcess = this.queuedFeaturesToProcess.get(node)!;\r\n const startFeatureIndex = Math.min(...Array.from(queuedFeatureToProcess.values()));\r\n\r\n // There is a known issue here where the VertexData.ExtractFromMesh function does not contain the updated vertices from mesh.updateVerticesData yet.\r\n // There is probably some kind of cache that is not updated if VertexData.ExtractFromMesh runs in the same frame\r\n\r\n let vertexDataCurrent = this.rendererManager.mesh.getMeshGeometry(node);\r\n\r\n const vertexDataNew: Partial = this.queuedGeometryToReset.has(node._dynamicId)\r\n ? this.queuedGeometryToReset.get(node._dynamicId)!\r\n : {};\r\n\r\n // If the whole mesh is being reset, it may be a new mesh without geometry, so we can use the entire vertexDataNew.\r\n // If the mesh renderer asks the feature renderer for updates, it will not apply the geometry on its own so we have to make sure it happens here.\r\n // This is done to prevent applying geometry to the mesh multiple times, which is expensive for very large geometry.\r\n if (!vertexDataCurrent && vertexDataNew instanceof SubmeshVertexData) {\r\n vertexDataCurrent = vertexDataNew.shallowClone();\r\n }\r\n if (!vertexDataCurrent) {\r\n this.queuedFeaturesToProcess.delete(node);\r\n this.queuedGeometryToReset.delete(node._dynamicId);\r\n return;\r\n }\r\n\r\n for (let i = startFeatureIndex; i < node.features.length; i++) {\r\n const renderTime = performance.now() - renderStartTime;\r\n\r\n if (renderTime > this.rendererManager.maxRenderTime) {\r\n // store the progress of this feature stack to continue processing next frame\r\n console.warn(\r\n `Feature processing time exceeded ${renderTime}ms, skipping ${this.queuedFeaturesToProcess.size} features this frame`\r\n );\r\n queuedFeatureToProcess.clear();\r\n queuedFeatureToProcess.add(i);\r\n this.queuedGeometryToReset.set(node._dynamicId, vertexDataNew);\r\n return;\r\n }\r\n const feature = node.features[i];\r\n\r\n const renderer = this.renderers.get(Token.withKey(feature.$type));\r\n if (!renderer) {\r\n throw Error('no renderer for feature');\r\n }\r\n\r\n if (!feature.enabled || feature._suppressed) {\r\n // If the feature is not enabled, then we don't process it, but we still want to update the feature's geometry cache\r\n // Otherwise when the feature is enabled later it might not have the right data.\r\n renderer.updateMeshGeometryCache(feature, vertexDataCurrent, vertexDataNew);\r\n continue;\r\n }\r\n\r\n // Always process the features that were modified\r\n let processThisFeature = queuedFeatureToProcess.has(i);\r\n\r\n // Figure out if a property this feature is affected by was modified this cycle\r\n if (!processThisFeature && feature.affectedBy) {\r\n processThisFeature = featureIsAffected(feature.affectedBy, vertexDataNew);\r\n }\r\n\r\n if (isTrackedClass(feature)) {\r\n if (processThisFeature) {\r\n // Process all of the features geometry effects\r\n const resultVertexData = renderer.updateMeshGeometry(feature, vertexDataCurrent, vertexDataNew);\r\n\r\n if (feature.affects) {\r\n feature.affects.forEach(affects => {\r\n if (affects === eMeshChangeTypes.VertexPositions) {\r\n vertexDataNew.positions = resultVertexData.positions || null;\r\n }\r\n if (affects === eMeshChangeTypes.VertexNormals) {\r\n vertexDataNew.normals = resultVertexData.normals || null;\r\n }\r\n if (affects === eMeshChangeTypes.VertexUvs) {\r\n vertexDataNew.uvs = resultVertexData.uvs || null;\r\n }\r\n if (affects === eMeshChangeTypes.VertexIndices) {\r\n vertexDataNew.indices = resultVertexData.indices || null;\r\n }\r\n if (affects === eMeshChangeTypes.Submeshes) {\r\n vertexDataNew.submeshData = resultVertexData.submeshData || null;\r\n }\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (vertexDataNew.submeshData) {\r\n if (!vertexDataCurrent.positions) {\r\n throw Error('Invalid geometry: positions is null');\r\n }\r\n const submeshData = vertexDataNew.submeshData.filter(s => s.materialIndex !== 0);\r\n const baseSubmeshes = calculateBaseSubmeshes(vertexDataCurrent, vertexDataNew, submeshData);\r\n const verticesCount = (vertexDataNew.positions || vertexDataCurrent.positions).length / 3;\r\n submeshData.unshift(\r\n ...baseSubmeshes.map(bs => ({\r\n materialIndex: 0,\r\n verticesStart: 0,\r\n verticesCount: verticesCount,\r\n indexStart: bs.indexStart,\r\n indexCount: bs.indexCount,\r\n }))\r\n );\r\n vertexDataNew.submeshData = submeshData;\r\n }\r\n\r\n if (Object.getOwnPropertyNames(vertexDataNew).length > 0) {\r\n this.applyNewVertexData(node, vertexDataNew, vertexDataCurrent);\r\n }\r\n }\r\n this.queuedFeaturesToProcess.delete(node);\r\n this.queuedGeometryToReset.delete(node._dynamicId);\r\n this.processedFeatures.set(node._dynamicId, true);\r\n }\r\n\r\n private getMovedFeatureIndex(mesh: MeshNode) {\r\n const oldArray = this.featureOrder.get(mesh._dynamicId);\r\n if (oldArray) {\r\n if (oldArray.length !== mesh.features.length) {\r\n return -1;\r\n }\r\n for (let i = 0; i < oldArray.length; i++) {\r\n const newArrayId = mesh.features[i]._dynamicId;\r\n if (oldArray[i] !== newArrayId) {\r\n return i;\r\n }\r\n }\r\n } else {\r\n return -1;\r\n }\r\n }\r\n\r\n private updateFeatureOrder(mesh: MeshNode) {\r\n const features: string[] = [];\r\n mesh.features.forEach(feature => {\r\n features.push(feature._dynamicId);\r\n });\r\n this.featureOrder.set(mesh._dynamicId, features);\r\n }\r\n\r\n private recursivelyUpdateFeatureVisibility(\r\n affectedFeatures: Feature[],\r\n features: Feature[],\r\n disabledFeatures: Feature[]\r\n ) {\r\n if (affectedFeatures.length === 0) {\r\n disabledFeatures.forEach(feature => {\r\n console.warn(\r\n 'The feature named',\r\n feature.name,\r\n 'got disabled due to a possible breaking change in the feature stack.'\r\n );\r\n });\r\n return;\r\n }\r\n\r\n const newAffectedFeatures: Feature[] = [];\r\n affectedFeatures.forEach(affectedFeature => {\r\n const featureIndex = getFeatureIndex(affectedFeature, features);\r\n if (featureIndex >= 0) {\r\n for (let i = featureIndex; i < features.length; i++) {\r\n const feature = features[i];\r\n if (feature.enabled) {\r\n affectedFeature.affects?.forEach(affector => {\r\n if (feature.dependsOn && feature.dependsOn.has(affector)) {\r\n feature.enabled = false;\r\n disabledFeatures.push(feature);\r\n feature._disableFeatureStackChange = true;\r\n newAffectedFeatures.push(feature);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n });\r\n this.recursivelyUpdateFeatureVisibility(newAffectedFeatures, features, disabledFeatures);\r\n\r\n function getFeatureIndex(feature: Feature, features: Feature[]) {\r\n for (let i = 0; i < features.length; i++) {\r\n if (features[i] === feature) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n }\r\n\r\n private applyNewVertexData(\r\n node: MeshNode,\r\n vertexDataNew: Partial,\r\n vertexDataCurrent: SubmeshVertexData\r\n ) {\r\n const mesh = this.viewer.getRendererNode(node) as Mesh;\r\n\r\n SubmeshVertexData.ExtendToRef(vertexDataNew, vertexDataCurrent);\r\n\r\n const invalid = verifyGeometry(vertexDataCurrent);\r\n if (invalid) {\r\n console.error(\r\n `Invalid or corrupted geometry output after feature processing in mesh ${node.name}. The ${invalid} are invalid.`\r\n );\r\n } else {\r\n vertexDataCurrent.applyToMesh(mesh);\r\n node._polygonCount = mesh.getTotalIndices() / 3;\r\n node._verticesCount = mesh.getTotalVertices();\r\n this.viewer.polygonTracker.next();\r\n this.viewer.warningTracker.next();\r\n }\r\n\r\n this.rendererManager.mesh.setRenderModeOnMesh(mesh, node._rootScene!);\r\n\r\n this.viewer.bbCache.invalidate(node);\r\n }\r\n\r\n delete3d(feature: ITrackedClass, preserveCache?: boolean) {\r\n const meshNode = feature._parent;\r\n if (meshNode && feature.affects) {\r\n this.resetMeshGeometry(meshNode, feature.affects);\r\n }\r\n\r\n const renderer = this.renderers.get(Token.withKey(feature.$type));\r\n if (!renderer) {\r\n throw Error('no renderer for feature');\r\n }\r\n renderer.delete3d(feature, preserveCache);\r\n }\r\n\r\n dispose() {\r\n this.queuedFeaturesToProcess.clear();\r\n this.renderers.forEach(renderer => renderer.dispose());\r\n super.dispose();\r\n }\r\n\r\n private getFeatureIndexOnParent(feature: Feature) {\r\n if (feature._parent) {\r\n const index = feature._parent.features.findIndex(f => f._dynamicId === feature._dynamicId);\r\n if (index > -1) {\r\n return index;\r\n }\r\n }\r\n\r\n return -1;\r\n }\r\n}\r\n\r\nfunction calculateBaseSubmeshes(\r\n vertexDataCurrent: SubmeshVertexData,\r\n vertexDataNew: Partial,\r\n submeshData: SubmeshData[]\r\n) {\r\n submeshData.sort((a, b) => a.indexStart - b.indexStart);\r\n const indicesCount = (vertexDataNew.indices || vertexDataCurrent.indices!).length;\r\n\r\n const baseSubmeshes = [\r\n {\r\n indexStart: 0,\r\n indexCount: indicesCount,\r\n },\r\n ];\r\n\r\n submeshData.forEach(submesh => {\r\n const lastSubmesh = baseSubmeshes[baseSubmeshes.length - 1];\r\n if (lastSubmesh) {\r\n if (\r\n submesh.indexStart <= lastSubmesh.indexStart &&\r\n submesh.indexStart + submesh.indexCount > lastSubmesh.indexStart\r\n ) {\r\n lastSubmesh.indexStart = submesh.indexStart + submesh.indexCount;\r\n lastSubmesh.indexCount = indicesCount - lastSubmesh.indexStart;\r\n\r\n if (lastSubmesh.indexCount <= 0) {\r\n baseSubmeshes.splice(-1, 1);\r\n }\r\n } else if (submesh.indexStart > lastSubmesh.indexStart) {\r\n lastSubmesh.indexCount = submesh.indexStart - lastSubmesh.indexStart;\r\n\r\n const remainingIndexCount = indicesCount - (submesh.indexStart + submesh.indexCount);\r\n if (remainingIndexCount > 0) {\r\n baseSubmeshes.push({\r\n indexStart: submesh.indexStart + submesh.indexCount,\r\n indexCount: remainingIndexCount,\r\n });\r\n }\r\n }\r\n }\r\n });\r\n\r\n return baseSubmeshes;\r\n}\r\n\r\nfunction featureIsAffected(affected: Set, vertexDataNew: Partial) {\r\n let result = false;\r\n affected.forEach(affectedBy => {\r\n if (affectedBy === eMeshChangeTypes.VertexPositions) {\r\n if (vertexDataNew.positions) {\r\n result = true; // Process the feature if a property it's affected by was changed this cycle\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.VertexNormals) {\r\n if (vertexDataNew.normals) {\r\n result = true; // Process the feature if a property it's affected by was changed this cycle\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.VertexUvs) {\r\n if (vertexDataNew.uvs) {\r\n result = true; // See above\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.VertexIndices) {\r\n if (vertexDataNew.indices) {\r\n result = true; // See above\r\n }\r\n }\r\n if (affectedBy === eMeshChangeTypes.Submeshes) {\r\n if (vertexDataNew.submeshData) {\r\n result = true; // See above\r\n }\r\n }\r\n });\r\n\r\n return result;\r\n}\r\n\r\nfunction hasChange(set: Set, changeType: eMeshChangeTypes) {\r\n return set.has(changeType);\r\n}\r\n","import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Axis, Color3 } from '@babylonjs/core/Maths/math';\r\nimport { Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { CreateSphere } from '@babylonjs/core/Meshes/Builders/sphereBuilder';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { KbVector } from '@models/classes';\r\nimport { instanceOf } from '@models/classes/decorators';\r\nimport { eConnectorPositionMode, eSketchPathType } from '@models/classes/enums';\r\nimport { BaseConnector } from '@models/classes/features/base-connector';\r\nimport { SketchControlPoint } from '@models/classes/features/sketch-control-point';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { SketchPath } from '@models/classes/meshes/sketch-node-path';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { IBoundingBox } from '@models/classes/primitives/primitive-utilities';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { BoundingBoxRelativeHelper } from '@view/helpers/bounding-box-relative-helper';\r\nimport { getRotationBtwVectors, toRadians } from '@view/helpers/math-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { RendererManager } from '../renderer-manager';\r\nimport { CONNECTOR_DIAM, ConnectorParts, ConnectorRenderer, IConnectorLayer } from './connector';\r\n\r\ninterface IConnectorLayerWithParts extends IConnectorLayer {\r\n parts: Map;\r\n}\r\n\r\nconst getMeshName = {\r\n handles: (dynamicId: string) => `${dynamicId}_handles`,\r\n handleBar: (dynamicId: string) => `${dynamicId}_handleBar`,\r\n directionHandle1: (dynamicId: string) => `${dynamicId}_directionHandle1`,\r\n directionHandle2: (dynamicId: string) => `${dynamicId}_directionHandle2`,\r\n};\r\n\r\nexport class SketchControlPointRenderer extends ConnectorRenderer {\r\n protected layers: Map<'real' | 'utility', IConnectorLayerWithParts>;\r\n protected readonly controlPointScaleRatio = 0.12;\r\n\r\n constructor(viewer: KbViewer, scene: Scene, rendererManager: RendererManager) {\r\n super(viewer, scene, rendererManager);\r\n this.layers.forEach(layer => {\r\n layer.parts = new Map();\r\n });\r\n }\r\n modelToken = Token.SketchControlPoint;\r\n\r\n public handlesNode(node: Kb3dObject): boolean {\r\n return instanceOf(node, Token.SketchControlPoint);\r\n }\r\n\r\n update3dInternal(c: ITrackedClass) {\r\n const realLayer = this.layers.get('real')!;\r\n const utilityLayer = this.layers.get('utility')!;\r\n const { mesh, utilityMesh } = super.update3dInternal(c as ITrackedClass, true);\r\n\r\n if (c._parent instanceof SketchPath) {\r\n const realParts = realLayer.parts.get(c._dynamicId);\r\n const utilityParts = utilityLayer.parts.get(c._dynamicId);\r\n\r\n if (c.changes.hasAny('direction', 'direction2')) {\r\n if (realParts) {\r\n updateHandles(realParts, c, c._parent);\r\n }\r\n if (utilityParts) {\r\n updateHandles(utilityParts, c, c._parent);\r\n }\r\n }\r\n }\r\n\r\n return { mesh, utilityMesh };\r\n\r\n function updateHandles(parts: ConnectorParts, controlPoint: SketchControlPoint, path: SketchPath) {\r\n let enableHandle1: boolean, enableHandle2: boolean;\r\n\r\n switch (path.type) {\r\n case eSketchPathType.arcThrough3Points:\r\n case eSketchPathType.points:\r\n case eSketchPathType.centerRadiusCircle:\r\n case eSketchPathType.catmullRom:\r\n enableHandle1 = false;\r\n enableHandle2 = false;\r\n break;\r\n\r\n case eSketchPathType.quadraticBezier:\r\n case eSketchPathType.hermite:\r\n // Don't show handles on the ends of the path since that handle does nothing\r\n enableHandle1 =\r\n path.controlPoints.findIndex(cp => cp._dynamicId === controlPoint._dynamicId) <\r\n path.controlPoints.length - 1;\r\n enableHandle2 = false;\r\n break;\r\n\r\n default:\r\n // Don't show handles on the ends of the path since that handle does nothing\r\n enableHandle1 =\r\n path.controlPoints.findIndex(cp => cp._dynamicId === controlPoint._dynamicId) <\r\n path.controlPoints.length - 1;\r\n enableHandle2 = path.controlPoints.findIndex(cp => cp._dynamicId === controlPoint._dynamicId) > 0;\r\n }\r\n\r\n if (parts.directionHandle1 && c.direction.length() > 0) {\r\n parts.directionHandle1.position = c.direction.toVec3();\r\n }\r\n if (parts.directionHandle2 && c.direction2 && c.direction2.length() > 0) {\r\n parts.directionHandle2.position = c.direction2.toVec3();\r\n }\r\n parts.directionHandle1?.setEnabled(enableHandle1);\r\n parts.directionHandle2?.setEnabled(enableHandle2);\r\n\r\n if (parts.handleBar) {\r\n parts.handleBar.setEnabled(true);\r\n parts.handleBar = MeshBuilder.CreateDashedLines(getMeshName.handleBar(c._dynamicId), {\r\n points: [\r\n enableHandle1 ? c.direction.toVec3() : Vector3.Zero(),\r\n Vector3.Zero(),\r\n enableHandle2 && c.direction2 ? c.direction2.toVec3() : Vector3.Zero(),\r\n ],\r\n updatable: true,\r\n instance: parts.handleBar,\r\n });\r\n }\r\n }\r\n }\r\n\r\n delete3d(c: ITrackedClass) {\r\n const mesh = this.getMesh(c, this.layers.get('real')!);\r\n const utilityMesh = this.getMesh(c, this.layers.get('utility')!);\r\n this.viewer.camera.clearMaintainedNodeScreenSize(mesh);\r\n if (utilityMesh) {\r\n this.viewer.camera.clearMaintainedNodeScreenSize(utilityMesh);\r\n }\r\n super.delete3d(c);\r\n\r\n const sketchPath = c._parent;\r\n if (sketchPath && isTrackedClass(sketchPath)) {\r\n sketchPath.setPropertyIsModified('controlPoints', true);\r\n }\r\n }\r\n\r\n updateDirection(c: SketchControlPoint) {\r\n const realLayer = this.layers.get('real')!;\r\n const utilityLayer = this.layers.get('utility')!;\r\n const mesh = this.getMesh(c, realLayer);\r\n const utilityMesh = this.getMesh(c, utilityLayer);\r\n\r\n const deltaBtwXaxisAndDirection = getRotationBtwVectors(\r\n Axis.X,\r\n this.getRelativeDirection(c, c.direction).normalize()\r\n );\r\n const angleRot = Quaternion.RotationAxis(Axis.X, toRadians(c.angle));\r\n mesh.rotationQuaternion = utilityMesh.rotationQuaternion = deltaBtwXaxisAndDirection.multiply(angleRot);\r\n\r\n const realParts = realLayer.parts.get(c._dynamicId);\r\n const utilityParts = utilityLayer.parts.get(c._dynamicId);\r\n if (realParts?.handleContainer) {\r\n const invTransform = Matrix.Compose(Vector3.One(), mesh.rotationQuaternion, Vector3.Zero());\r\n invTransform.invert();\r\n invTransform.decomposeToTransformNode(realParts.handleContainer);\r\n if (utilityParts?.handleContainer) {\r\n invTransform.decomposeToTransformNode(utilityParts.handleContainer);\r\n }\r\n }\r\n\r\n this.updateScale(c);\r\n }\r\n\r\n updatePosition(c: SketchControlPoint, bb?: IBoundingBox) {\r\n const mesh = this.getMesh(c, this.layers.get('real')!);\r\n const utilityMesh = this.getMesh(c, this.layers.get('utility')!);\r\n\r\n mesh.position = this.getControlPointAbsPosition(c, bb);\r\n if (utilityMesh) {\r\n utilityMesh.position = mesh.position;\r\n }\r\n\r\n const sketchPath = c._parent;\r\n if (sketchPath && isTrackedClass(sketchPath)) {\r\n sketchPath.setPropertyIsModified('controlPoints', true);\r\n }\r\n }\r\n\r\n getControlPointAbsPosition(c: SketchControlPoint, bb?: IBoundingBox) {\r\n if (c.positionMode == eConnectorPositionMode.boundingBox) {\r\n if (!bb) {\r\n bb = c.getSketch()?.getBoundingBox();\r\n }\r\n if (bb) {\r\n return BoundingBoxRelativeHelper.convertRelativeToAbsolute(c, bb);\r\n } else {\r\n return new Vector3(c.position.x, c.position.y, c.position.z);\r\n }\r\n } else {\r\n return c.position.toVec3();\r\n }\r\n }\r\n\r\n getRelativeDirection(c: SketchControlPoint, direction: KbVector, bb?: IBoundingBox) {\r\n if (c.positionMode === eConnectorPositionMode.absolute) {\r\n return direction.toVec3();\r\n } else {\r\n if (!bb) {\r\n bb = c.getSketch()?.getBoundingBox();\r\n }\r\n if (!bb) {\r\n return Vector3.Zero();\r\n }\r\n return BoundingBoxRelativeHelper.convertRelativeDirectionToAbsolute(c, direction, bb);\r\n }\r\n }\r\n\r\n protected getMesh(c: BaseConnector, layer: IConnectorLayerWithParts) {\r\n let mesh = layer.map.get(c._dynamicId);\r\n if (!mesh) {\r\n if (!layer.template) {\r\n layer.template = this.createMeshTemplate(layer);\r\n }\r\n\r\n mesh = layer.template.clone(c._dynamicId); // layer.template.createInstance(c._dynamicId);\r\n mesh.id = c._dynamicId;\r\n\r\n const [handleContainer] = mesh.getChildren() as TransformNode[];\r\n const [directionHandle1, directionHandle2, _handleBar] = handleContainer.getChildMeshes(true);\r\n const handleBar = _handleBar as LinesMesh;\r\n handleBar.makeGeometryUnique();\r\n\r\n handleContainer.id = getMeshName.handles(c._dynamicId);\r\n directionHandle1.id = getMeshName.directionHandle1(c._dynamicId);\r\n directionHandle2.id = getMeshName.directionHandle2(c._dynamicId);\r\n\r\n const parentNode = c._parent?._parent;\r\n\r\n if (parentNode && parentNode instanceof SpaceNode) {\r\n const parent3d = this.viewer.getRendererNode(parentNode);\r\n if (parent3d) {\r\n mesh.setParent(parent3d);\r\n }\r\n }\r\n\r\n mesh.isPickable = layer.pickable;\r\n mesh.position = Vector3.Zero();\r\n mesh.rotationQuaternion = Quaternion.Identity();\r\n layer.map.set(c._dynamicId, mesh);\r\n layer.parts.set(c._dynamicId, {\r\n mesh,\r\n handleContainer: handleContainer as TransformNode,\r\n directionHandle1,\r\n directionHandle2,\r\n handleBar: handleBar,\r\n });\r\n }\r\n return mesh;\r\n }\r\n\r\n protected createMeshTemplate(layer: IConnectorLayer) {\r\n const mesh = super.createMeshTemplate(layer);\r\n\r\n const handleContainer = new TransformNode('', this.scene);\r\n\r\n const handleBall = CreateSphere('handle1', {\r\n segments: 4,\r\n diameter: CONNECTOR_DIAM / 2,\r\n });\r\n handleBall.setParent(handleContainer);\r\n const m = new StandardMaterial('controlPointMaterial', this.scene);\r\n m.emissiveColor = this.viewer.highlightColor.toColor3();\r\n m.disableLighting = true;\r\n handleBall.material = m;\r\n\r\n const handle1 = handleBall;\r\n const handle2 = handleBall.clone('handle2', handleContainer, true);\r\n handle1.setEnabled(false);\r\n handle2.setEnabled(false);\r\n const baseColor = this.viewer.sceneNode?.edgeColor\r\n ? this.viewer.sceneNode.edgeColor.toColor3()\r\n : Color3.White();\r\n const handleBar = MeshBuilder.CreateDashedLines('handleBar', {\r\n points: [Vector3.Up(), Vector3.Zero(), Vector3.Down()],\r\n updatable: true,\r\n dashSize: 1,\r\n gapSize: 1,\r\n dashNb: 30,\r\n });\r\n handleBar.color = baseColor;\r\n handleBar.isPickable = false;\r\n // const handleBarMaterial = new StandardMaterial('controlPointHandleBarMaterial', this.scene);\r\n // handleBarMaterial.emissiveColor = this.viewer.sceneNode?.edgeColor ? this.viewer.sceneNode.edgeColor.toColor3() : Color3.White();\r\n // handleBar.material = handleBarMaterial;\r\n handleBar.setParent(handleContainer);\r\n handleContainer.setParent(mesh);\r\n\r\n return mesh;\r\n }\r\n\r\n protected addSubscription(c: ITrackedClass) {\r\n const sketch = c.getSketch();\r\n\r\n if (sketch && !this.subscriptionMap.has(c)) {\r\n this.subscriptionMap.set(\r\n c,\r\n sketch._boundingBoxChanges.subscribe(bbInfo => {\r\n this.updatePosition(c, bbInfo);\r\n this.updateScale(c);\r\n })\r\n );\r\n }\r\n }\r\n}\r\n","import { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { isTrackedClass, ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { ChangeMap } from '../renderer-manager';\r\nimport { Processor } from './processor';\r\n\r\nexport class ReferenceProcessor extends Processor {\r\n /**\r\n * referencedNodeId => ( referencedByNodeId => referencedByNode )\r\n *\r\n * Any node that is in a nested scene will be keyed by the nested scene ID.\r\n * If the node is not in a nested scene (or there is no nesting), then the node will be keyed by the bare node id.\r\n * This applies to the referencedNodeId and the referencedByNodeId.\r\n * */\r\n\r\n referencesTo = new Map<\r\n string,\r\n Map<\r\n string,\r\n {\r\n limitKeys?: Set;\r\n ref: Kb3dObject;\r\n referencePropertyName: string | symbol;\r\n }\r\n >\r\n >();\r\n\r\n orphanedReferences = new Map<\r\n string,\r\n {\r\n referencedBy: Kb3dObject;\r\n propName: string | symbol;\r\n referenceId: string;\r\n }\r\n >();\r\n\r\n constructor(private viewer: KbViewer) {\r\n super();\r\n }\r\n\r\n beforeDeletions(deletions: ChangeMap) {\r\n const rootScene = this.viewer.sceneNode;\r\n if (!rootScene || !rootScene._manager) {\r\n return;\r\n }\r\n const rootManager = rootScene._manager;\r\n\r\n deletions.all().forEach(node => {\r\n if (!node._manager) {\r\n return;\r\n }\r\n\r\n let nodeId = node.id;\r\n if (node._parentScene?.isNested()) {\r\n nodeId = rootScene.getNestedPathTo(node);\r\n }\r\n\r\n const referenceTo = this.referencesTo.get(nodeId);\r\n if (referenceTo && referenceTo.size > 0) {\r\n referenceTo.forEach((opts, referencedById) => {\r\n const referencedBy = rootManager.getById(referencedById);\r\n if (referencedBy && (referencedBy as any)[opts.referencePropertyName] === nodeId) {\r\n this.orphanedReferences.set(nodeId, {\r\n referencedBy,\r\n propName: opts.referencePropertyName,\r\n referenceId: (referencedBy as any)[opts.referencePropertyName],\r\n });\r\n (referencedBy as any)[opts.referencePropertyName] = undefined;\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n getReferencesTo() {\r\n return this.referencesTo;\r\n }\r\n\r\n beforeUpdates(changes: ChangeMap): void {\r\n const rootScene = this.viewer.sceneNode;\r\n if (!rootScene || !rootScene._manager) {\r\n return;\r\n }\r\n\r\n changes.all().forEach(node => {\r\n let nodeId = node.id;\r\n if (node._parentScene?.isNested()) {\r\n nodeId = rootScene.getNestedPathTo(node);\r\n }\r\n\r\n const orphanedReference = this.orphanedReferences.get(nodeId);\r\n if (orphanedReference) {\r\n (orphanedReference.referencedBy as any)[orphanedReference.propName] = orphanedReference.referenceId;\r\n }\r\n });\r\n }\r\n\r\n afterUpdates(changes: ChangeMap) {\r\n const rootScene = this.viewer.sceneNode;\r\n if (!rootScene || !rootScene._manager) {\r\n return;\r\n }\r\n\r\n changes.all().forEach(node => {\r\n if (!node._manager) {\r\n return;\r\n }\r\n\r\n const changedNodeManager = node._manager;\r\n // This block is for managing/updating the node reference\r\n // First, check nodes referencing other nodes for updates\r\n if (node.nodeReferences) {\r\n const targettingProperties = node.nodeReferences.keys();\r\n for (const _prop of targettingProperties) {\r\n const property = _prop as keyof Kb3dObject;\r\n const referenceSettings = node.nodeReferences.get(_prop)!;\r\n\r\n // If a node's references were changed, update all the references.\r\n if (node.changes.has(property)) {\r\n if (node[property] && typeof node[property] !== 'string') {\r\n console.error(`Non-string id reference value found on ${node.name} property ${property}`);\r\n }\r\n\r\n // First, remove the node from the previous target node's referencing nodes set\r\n if (node.originalValues.has(property)) {\r\n const originalReferencedNodeId: string = node.originalValues.get(property);\r\n if (originalReferencedNodeId) {\r\n // Figure out the original target node's key\r\n let originalReferencedNodeKey = originalReferencedNodeId;\r\n const originalReferencedNode = changedNodeManager.getById(originalReferencedNodeId);\r\n if (originalReferencedNode?._parentScene?.isNested()) {\r\n originalReferencedNodeKey = rootScene.getNestedPathTo(originalReferencedNode);\r\n }\r\n\r\n const referencedBy = this.referencesTo.get(originalReferencedNodeKey);\r\n if (referencedBy) {\r\n let nestedPathIdSource = node.id;\r\n if (node._parentScene?.isNested()) {\r\n nestedPathIdSource = rootScene.getNestedPathTo(node);\r\n }\r\n referencedBy.delete(nestedPathIdSource);\r\n }\r\n }\r\n }\r\n\r\n // Set up the new references or delete the reference from entry if the reference was cleared\r\n if (node[property]) {\r\n const targetNode = node._manager.getById(node[property]);\r\n if (targetNode) {\r\n if (targetNode instanceof referenceSettings.classRef) {\r\n let nestedPathIdTarget: string = node[property];\r\n let nestedPathIdSource = node.id;\r\n const isNestedSource = node._parentScene?.isNested() || false;\r\n\r\n if (nestedPathIdTarget.startsWith('@')) {\r\n const nestedTargetNode = changedNodeManager.getById(nestedPathIdTarget);\r\n if (nestedTargetNode) {\r\n nestedPathIdTarget = rootScene.getNestedPathTo(nestedTargetNode);\r\n }\r\n } else if (isNestedSource) {\r\n // If source node is in a nested scene and the target node id is not a nested path, that means that\r\n // the nested node is targetting a node in it's own scene. But we need to use\r\n // a nested path because there could be multiple instances of the nested node's scene\r\n nestedPathIdTarget = rootScene.getNestedPathTo(targetNode);\r\n }\r\n if (isNestedSource) {\r\n nestedPathIdSource = rootScene.getNestedPathTo(node);\r\n }\r\n\r\n let referencedBy = this.referencesTo.get(nestedPathIdTarget);\r\n if (!referencedBy) {\r\n referencedBy = new Map();\r\n\r\n this.referencesTo.set(nestedPathIdTarget, referencedBy);\r\n }\r\n\r\n referencedBy.set(nestedPathIdSource, {\r\n limitKeys: referenceSettings.limitKeys,\r\n ref: node,\r\n referencePropertyName: property,\r\n });\r\n } else {\r\n console.warn(\r\n `Node ${node.name} property ${property} is not referencing a ${referenceSettings.classRef}`\r\n );\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n });\r\n\r\n // Next, check nodes being referenced by other nodes to see if the other nodes will need to be updated\r\n changes.all().forEach(node => {\r\n this.triggerChangesOnReferencers(node);\r\n });\r\n }\r\n\r\n triggerChangesOnReferencers(node: ITrackedClass, changes?: Map) {\r\n const changeMap = changes || new Map(node.changes);\r\n\r\n if (changeMap.size > 0) {\r\n this.afterCleanup(() => {\r\n this.triggerChangesOnReferencersSync(node, changeMap);\r\n });\r\n }\r\n }\r\n\r\n private triggerChangesOnReferencersSync(\r\n node: ITrackedClass,\r\n changes: Map,\r\n transformationPropagation?: boolean\r\n ) {\r\n const rootScene = this.viewer.sceneNode;\r\n if (!rootScene || !rootScene._manager) {\r\n return;\r\n }\r\n const rootManager = rootScene._manager;\r\n\r\n let nodeId = node.id;\r\n if (node._parentScene?.isNested()) {\r\n nodeId = rootScene.getNestedPathTo(node);\r\n }\r\n\r\n const referenceTo = this.referencesTo.get(nodeId);\r\n if (referenceTo) {\r\n referenceTo.forEach((referenceSettings, referencedById) => {\r\n const referencedBy = rootManager.getById(referencedById);\r\n if (referencedBy && isTrackedClass(referencedBy)) {\r\n if (\r\n !referenceSettings.limitKeys ||\r\n transformationPropagation ||\r\n changes.hasAny(...(referenceSettings.limitKeys as Set))\r\n ) {\r\n referencedBy.setPropertyIsModified(referenceSettings.referencePropertyName, true);\r\n }\r\n }\r\n });\r\n }\r\n\r\n // For transformation changes, propagate to the children because the children will also get moved without passing through the change tracker\r\n // This avoids needing a secondary watcher for node position\r\n if (\r\n node instanceof SpaceNode &&\r\n (changes as Map).hasAny(\r\n 'position',\r\n 'eulerRotation',\r\n 'rotationAngle',\r\n 'rotationAxis',\r\n 'pivot',\r\n 'scaling'\r\n )\r\n ) {\r\n const children = node.getChildren();\r\n for (let i = 0; i < children.length; i++) {\r\n // Always trigger changes on children because they may have different property names\r\n this.triggerChangesOnReferencersSync(children[i] as ITrackedClass, changes, true);\r\n }\r\n }\r\n }\r\n\r\n dispose() {\r\n this.referencesTo.clear();\r\n }\r\n}\r\n","import { Curve3, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { eConnectorPositionMode, eSketchPathType } from '@models/classes/enums';\r\nimport { SketchControlPoint } from '@models/classes/features/sketch-control-point';\r\nimport { SketchNode } from '@models/classes/meshes/sketch-node';\r\nimport { SketchPath } from '@models/classes/meshes/sketch-node-path';\r\nimport { IKbVectorLike, KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { IBoundingBox } from '@models/classes/primitives/primitive-utilities';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { SketchControlPointRenderer } from '../features/sketch-control-point';\r\nimport { ChangeMap } from '../renderer-manager';\r\nimport { Processor } from './processor';\r\n\r\n/**\r\n * Processor to calculate the bounding box of a sketch, since it is determined by the path defined within.\r\n * Must run after the mate processor because mates can move sketch points and change the bounding box.\r\n */\r\nexport class SketchProcessor extends Processor {\r\n constructor(private controlPointRenderer: SketchControlPointRenderer) {\r\n super();\r\n }\r\n\r\n beforeRender() {}\r\n\r\n beforeDeletions(deletions: ChangeMap) {\r\n // Update paths that need to be updated\r\n if (deletions.has(Token.SketchPath)) {\r\n const sketchPaths = deletions.get(Token.SketchPath) as Array>;\r\n sketchPaths.forEach(p => this.updatePath(p));\r\n }\r\n\r\n if (deletions.has(Token.SketchControlPoint) || deletions.has(Token.SketchPath)) {\r\n const sketchPathChanges = deletions.get(Token.SketchPath) as Array>;\r\n const sketchControlPointChanges = deletions.get(Token.SketchControlPoint) as Array<\r\n ITrackedClass\r\n >;\r\n const sketchesToUpdate = new Map();\r\n sketchPathChanges.forEach(node => {\r\n const sketch = node._parent;\r\n if (sketch) {\r\n if (!sketchesToUpdate.has(sketch._dynamicId)) {\r\n sketchesToUpdate.set(sketch._dynamicId, sketch);\r\n }\r\n }\r\n });\r\n sketchControlPointChanges.forEach(node => {\r\n const sketch = node.getSketch();\r\n if (sketch) {\r\n if (!sketchesToUpdate.has(sketch._dynamicId)) {\r\n sketchesToUpdate.set(sketch._dynamicId, sketch);\r\n }\r\n }\r\n });\r\n\r\n sketchesToUpdate.forEach(this.calculateSketchBounds);\r\n }\r\n }\r\n\r\n beforeUpdates(changes: ChangeMap) {\r\n // Update paths that need to be updated\r\n if (changes.has(Token.SketchPath)) {\r\n const sketchPaths = changes.get(Token.SketchPath) as Array>;\r\n sketchPaths.forEach(p => this.updatePath(p));\r\n }\r\n\r\n // Update the sketch bounding box with the path control points within it that are absolute positioned\r\n if (changes.has(Token.SketchControlPoint)) {\r\n const sketchControlPointChanges = changes.get(Token.SketchControlPoint) as Array<\r\n ITrackedClass\r\n >;\r\n const sketchesToUpdate = new Map();\r\n sketchControlPointChanges.forEach(node => {\r\n if (node.changes.hasAny('position', 'positionMode')) {\r\n const sketch = node.getSketch();\r\n if (sketch) {\r\n if (!sketchesToUpdate.has(sketch._dynamicId)) {\r\n sketchesToUpdate.set(sketch._dynamicId, sketch);\r\n }\r\n }\r\n }\r\n });\r\n\r\n sketchesToUpdate.forEach(this.calculateSketchBounds);\r\n }\r\n }\r\n\r\n afterUpdates(changes: ChangeMap): void {\r\n if (changes.has(Token.SketchControlPoint)) {\r\n const sketchControlPointChanges = changes.get(Token.SketchControlPoint) as Array<\r\n ITrackedClass\r\n >;\r\n sketchControlPointChanges.forEach(node => {\r\n const sketch = node.getSketch();\r\n if (sketch) {\r\n this.afterCleanup(() => {\r\n sketch.paths.forEach(path => {\r\n if (isTrackedClass(path)) {\r\n this.updatePath(path, true);\r\n }\r\n });\r\n sketch.connectors.forEach(connector => {\r\n if (connector.positionMode === eConnectorPositionMode.moveAlongSketch) {\r\n if (connector._parent instanceof SketchNode) {\r\n connector._sketchControlPoints = this.getControlPoints(connector._parent);\r\n }\r\n }\r\n });\r\n });\r\n }\r\n });\r\n }\r\n }\r\n\r\n calculateSketchBounds(sketch: SketchNode) {\r\n const controlPoints = sketch.paths.flatMap(path => path.controlPoints);\r\n let min: Vector3 | undefined;\r\n let max: Vector3 | undefined;\r\n\r\n controlPoints.forEach(controlPoint => {\r\n if (controlPoint.positionMode === eConnectorPositionMode.absolute) {\r\n const position = controlPoint.position;\r\n if (!min) {\r\n min = position.toVec3();\r\n }\r\n\r\n max = position.toVec3();\r\n }\r\n });\r\n\r\n if (min && max) {\r\n sketch._boundingBoxMin = KbVector.FromVec3(min);\r\n sketch._boundingBoxMax = KbVector.FromVec3(max);\r\n } else {\r\n sketch._boundingBoxMin = KbVector.Zero();\r\n sketch._boundingBoxMax = KbVector.Zero();\r\n }\r\n sketch._boundingBoxChanges.next(sketch.getBoundingBox());\r\n }\r\n\r\n private updatePath(path: ITrackedClass, force?: boolean) {\r\n let points: Vector3[] | undefined;\r\n\r\n if (\r\n force ||\r\n path.changes.hasAny('controlPoints', 'tessellation', 'type', 'holeForPathGroup', 'pathGroupKey') ||\r\n !path._points?.length\r\n ) {\r\n points = this.buildSketchPoints(path);\r\n path._points = points;\r\n\r\n const parent = path._parent;\r\n if (parent instanceof SketchNode && isTrackedClass(parent)) {\r\n parent.setPropertyIsModified('paths', true);\r\n }\r\n } else if (path.changes.has('_selected')) {\r\n const parent = path._parent;\r\n if (parent instanceof SketchNode && isTrackedClass(parent)) {\r\n parent.setPropertyIsModified('paths', true);\r\n }\r\n }\r\n }\r\n\r\n private buildSketchPoints(path: SketchPath) {\r\n const points: Vector3[] = [];\r\n if (!path._parent) {\r\n return points;\r\n }\r\n const bb = path._parent.getBoundingBox();\r\n\r\n switch (path.type) {\r\n case eSketchPathType.catmullRom: {\r\n const positions = path.controlPoints.map(v => this.getPointPosition(v));\r\n if (positions.length > 2) {\r\n const curve = Curve3.CreateCatmullRomSpline(positions, path.tessellation, false);\r\n points.push(...curve.getPoints());\r\n } else {\r\n points.push(...positions);\r\n }\r\n\r\n break;\r\n }\r\n case eSketchPathType.hermite: {\r\n for (let i = 0; i + 1 < path.controlPoints.length; i++) {\r\n const start = path.controlPoints[i],\r\n end = path.controlPoints[i + 1];\r\n const p0 = this.getPointPosition(start);\r\n const p1 = this.getPointPosition(end);\r\n const d0 = this.getPointDirection(start, bb);\r\n const d1 = this.getPointDirection(end, bb);\r\n\r\n const curve = Curve3.CreateHermiteSpline(p0, d0, p1, d1, path.tessellation);\r\n points.push(...curve.getPoints());\r\n }\r\n break;\r\n }\r\n case eSketchPathType.cubicBezier: {\r\n for (let i = 0; i + 1 < path.controlPoints.length; i++) {\r\n const start = path.controlPoints[i],\r\n end = path.controlPoints[i + 1];\r\n const direction2 = this.getPointDirection2(end, bb);\r\n if (direction2) {\r\n const p0 = this.getPointPosition(start);\r\n const p3 = this.getPointPosition(end);\r\n if (p0.equals(p3)) {\r\n continue;\r\n }\r\n\r\n const p1 = p0.add(this.getPointDirection(start, bb));\r\n const p2 = p3.add(direction2);\r\n const curve = Curve3.CreateCubicBezier(p0, p1, p2, p3, path.tessellation);\r\n points.push(...curve.getPoints());\r\n }\r\n }\r\n break;\r\n }\r\n case eSketchPathType.quadraticBezier: {\r\n const controlPoint = new Vector3();\r\n for (let i = 0; i + 1 < path.controlPoints.length; i++) {\r\n const start = path.controlPoints[i],\r\n end = path.controlPoints[i + 1];\r\n const p0 = this.getPointPosition(start);\r\n const p2 = this.getPointPosition(end);\r\n if (p0.equals(p2)) {\r\n continue;\r\n }\r\n\r\n p0.addToRef(this.getPointDirection(start, bb), controlPoint);\r\n\r\n const curve = Curve3.CreateQuadraticBezier(p0, controlPoint, p2, path.tessellation);\r\n points.push(...curve.getPoints());\r\n }\r\n break;\r\n }\r\n case eSketchPathType.centerRadiusCircle: {\r\n if (path.controlPoints.length >= 2) {\r\n const [p0, p1] = path.controlPoints.slice(0, 2).map(cp => this.getPointPosition(cp));\r\n const normal = this.getPointDirection(path.controlPoints[0], bb).normalize();\r\n const p2 = Vector3.Cross(p0.subtract(p1), normal).addInPlace(p0);\r\n const curve = Curve3.ArcThru3Points(\r\n p0.scale(2).subtractInPlace(p1),\r\n p1,\r\n p2,\r\n path.tessellation * 2,\r\n false,\r\n true\r\n );\r\n points.push(...curve.getPoints());\r\n }\r\n break;\r\n }\r\n case eSketchPathType.arcThrough3Points: {\r\n if (path.controlPoints.length >= 3) {\r\n const [p0, p1, p2] = path.controlPoints.slice(0, 3).map(cp => this.getPointPosition(cp));\r\n const curve = Curve3.ArcThru3Points(p0, p1, p2, path.tessellation, false, false);\r\n points.push(...curve.getPoints());\r\n }\r\n break;\r\n }\r\n\r\n default: {\r\n path.controlPoints.forEach(point => {\r\n points.push(this.getPointPosition(point));\r\n });\r\n }\r\n }\r\n\r\n // /**\r\n // * We want the sketch to always \"face\" in the positive direction of the axis for consistency\r\n // * Otherwise it's indeterminate which way the sketch will face and makes the sketch hard to manage\r\n // * because it depends on the handed-ness of the points (clockwise or counter-clockwise)\r\n // */\r\n // const primaryNormal = axisToVector3(path._parent.normal);\r\n // const faceNormal = calculateFaceNormal(points);\r\n // if (Vector3.Dot(faceNormal, primaryNormal) < 0) {\r\n // points.reverse();\r\n // }\r\n\r\n return points;\r\n }\r\n\r\n private getPointPosition(point: SketchControlPoint) {\r\n return this.controlPointRenderer.getControlPointAbsPosition(point);\r\n }\r\n\r\n private getPointDirection(point: SketchControlPoint, bb: IBoundingBox) {\r\n return this.controlPointRenderer.getRelativeDirection(point, point.direction, bb);\r\n }\r\n private getPointDirection2(point: SketchControlPoint, bb: IBoundingBox) {\r\n if (!point.direction2) {\r\n return undefined;\r\n } else {\r\n return this.controlPointRenderer.getRelativeDirection(point, point.direction2, bb);\r\n }\r\n }\r\n\r\n private getControlPoints(node: SketchNode) {\r\n const controlPoints: IKbVectorLike[] = [];\r\n node.paths.forEach(path => {\r\n path._points.forEach(point => {\r\n controlPoints.push(point);\r\n });\r\n });\r\n return controlPoints;\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\nimport type { PostProcessRenderEffect } from \"./postProcessRenderEffect\";\r\nimport type { IInspectable } from \"../../Misc/iInspectable\";\r\n\r\nimport type { PrePassRenderer } from \"../../Rendering/prePassRenderer\";\r\n\r\n/**\r\n * PostProcessRenderPipeline\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n */\r\nexport class PostProcessRenderPipeline {\r\n protected _renderEffects: { [key: string]: PostProcessRenderEffect };\r\n protected _renderEffectsForIsolatedPass: PostProcessRenderEffect[];\r\n\r\n /**\r\n * List of inspectable custom properties (used by the Inspector)\r\n * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility\r\n */\r\n public inspectableCustomProperties: IInspectable[];\r\n\r\n /**\r\n * @internal\r\n */\r\n protected _cameras: Camera[];\r\n\r\n /** @internal */\r\n @serialize()\r\n public _name: string;\r\n\r\n /**\r\n * Gets pipeline name\r\n */\r\n public get name(): string {\r\n return this._name;\r\n }\r\n\r\n /** Gets the list of attached cameras */\r\n public get cameras() {\r\n return this._cameras;\r\n }\r\n\r\n /**\r\n * Initializes a PostProcessRenderPipeline\r\n * @param _engine engine to add the pipeline to\r\n * @param name name of the pipeline\r\n */\r\n constructor(private _engine: Engine, name: string) {\r\n this._name = name;\r\n\r\n this._renderEffects = {};\r\n this._renderEffectsForIsolatedPass = new Array();\r\n\r\n this._cameras = [];\r\n }\r\n\r\n /**\r\n * Gets the class name\r\n * @returns \"PostProcessRenderPipeline\"\r\n */\r\n public getClassName(): string {\r\n return \"PostProcessRenderPipeline\";\r\n }\r\n\r\n /**\r\n * If all the render effects in the pipeline are supported\r\n */\r\n public get isSupported(): boolean {\r\n for (const renderEffectName in this._renderEffects) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\r\n if (!this._renderEffects[renderEffectName].isSupported) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Adds an effect to the pipeline\r\n * @param renderEffect the effect to add\r\n */\r\n public addEffect(renderEffect: PostProcessRenderEffect): void {\r\n (this._renderEffects)[renderEffect._name] = renderEffect;\r\n }\r\n\r\n // private\r\n\r\n /** @internal */\r\n public _rebuild() {}\r\n\r\n /** @internal */\r\n public _enableEffect(renderEffectName: string, cameras: Camera): void;\r\n /** @internal */\r\n public _enableEffect(renderEffectName: string, cameras: Camera[]): void;\r\n /**\r\n * @internal\r\n */\r\n public _enableEffect(renderEffectName: string, cameras: any): void {\r\n const renderEffects: PostProcessRenderEffect = (this._renderEffects)[renderEffectName];\r\n\r\n if (!renderEffects) {\r\n return;\r\n }\r\n\r\n renderEffects._enable(Tools.MakeArray(cameras || this._cameras));\r\n }\r\n\r\n /** @internal */\r\n public _disableEffect(renderEffectName: string, cameras: Nullable): void;\r\n /** @internal */\r\n public _disableEffect(renderEffectName: string, cameras: Nullable): void;\r\n /**\r\n * @internal\r\n */\r\n public _disableEffect(renderEffectName: string, cameras: Nullable): void {\r\n const renderEffects: PostProcessRenderEffect = (this._renderEffects)[renderEffectName];\r\n\r\n if (!renderEffects) {\r\n return;\r\n }\r\n\r\n renderEffects._disable(Tools.MakeArray(cameras || this._cameras));\r\n }\r\n\r\n /** @internal */\r\n public _attachCameras(cameras: Camera, unique: boolean): void;\r\n /** @internal */\r\n public _attachCameras(cameras: Camera[], unique: boolean): void;\r\n /**\r\n * @internal\r\n */\r\n public _attachCameras(cameras: any, unique: boolean): void {\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n const indicesToDelete = [];\r\n let i: number;\r\n for (i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n if (!camera) {\r\n continue;\r\n }\r\n\r\n if (this._cameras.indexOf(camera) === -1) {\r\n this._cameras.push(camera);\r\n } else if (unique) {\r\n indicesToDelete.push(i);\r\n }\r\n }\r\n\r\n for (i = 0; i < indicesToDelete.length; i++) {\r\n cams.splice(indicesToDelete[i], 1);\r\n }\r\n\r\n for (const renderEffectName in this._renderEffects) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\r\n this._renderEffects[renderEffectName]._attachCameras(cams);\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _detachCameras(cameras: Camera): void;\r\n /** @internal */\r\n public _detachCameras(cameras: Nullable): void;\r\n /**\r\n * @internal\r\n */\r\n public _detachCameras(cameras: any): void {\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (const renderEffectName in this._renderEffects) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\r\n this._renderEffects[renderEffectName]._detachCameras(cams);\r\n }\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n this._cameras.splice(this._cameras.indexOf(cams[i]), 1);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _update(): void {\r\n for (const renderEffectName in this._renderEffects) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderEffects, renderEffectName)) {\r\n this._renderEffects[renderEffectName]._update();\r\n }\r\n }\r\n\r\n for (let i = 0; i < this._cameras.length; i++) {\r\n if (!this._cameras[i]) {\r\n continue;\r\n }\r\n const cameraName = this._cameras[i].name;\r\n if ((this._renderEffectsForIsolatedPass)[cameraName]) {\r\n (this._renderEffectsForIsolatedPass)[cameraName]._update();\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _reset(): void {\r\n this._renderEffects = {};\r\n this._renderEffectsForIsolatedPass = new Array();\r\n }\r\n\r\n protected _enableMSAAOnFirstPostProcess(sampleCount: number): boolean {\r\n if (!this._engine._features.supportMSAA) {\r\n return false;\r\n }\r\n\r\n // Set samples of the very first post process to 4 to enable native anti-aliasing in browsers that support webGL 2.0 (See: https://github.com/BabylonJS/Babylon.js/issues/3754)\r\n const effectKeys = Object.keys(this._renderEffects);\r\n if (effectKeys.length > 0) {\r\n const postProcesses = this._renderEffects[effectKeys[0]].getPostProcesses();\r\n if (postProcesses) {\r\n postProcesses[0].samples = sampleCount;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Sets the required values to the prepass renderer.\r\n * @param prePassRenderer defines the prepass renderer to setup.\r\n * @returns true if the pre pass is needed.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {\r\n // Do Nothing by default\r\n return false;\r\n }\r\n\r\n /**\r\n * Disposes of the pipeline\r\n */\r\n public dispose() {\r\n // Must be implemented by children\r\n }\r\n}\r\n","import type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { Engine } from \"../../Engines/engine\";\r\n/**\r\n * This represents a set of one or more post processes in Babylon.\r\n * A post process can be used to apply a shader to a texture after it is rendered.\r\n * @example https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n */\r\nexport class PostProcessRenderEffect {\r\n private _postProcesses: { [Key: string]: Array };\r\n private _getPostProcesses: () => Nullable>;\r\n\r\n private _singleInstance: boolean;\r\n\r\n private _cameras: { [key: string]: Nullable };\r\n private _indicesForCamera: { [key: string]: number[] };\r\n\r\n /**\r\n * Name of the effect\r\n * @internal\r\n */\r\n public _name: string;\r\n\r\n /**\r\n * Instantiates a post process render effect.\r\n * A post process can be used to apply a shader to a texture after it is rendered.\r\n * @param engine The engine the effect is tied to\r\n * @param name The name of the effect\r\n * @param getPostProcesses A function that returns a set of post processes which the effect will run in order to be run.\r\n * @param singleInstance False if this post process can be run on multiple cameras. (default: true)\r\n */\r\n constructor(engine: Engine, name: string, getPostProcesses: () => Nullable>, singleInstance?: boolean) {\r\n this._name = name;\r\n this._singleInstance = singleInstance || true;\r\n\r\n this._getPostProcesses = getPostProcesses;\r\n\r\n this._cameras = {};\r\n this._indicesForCamera = {};\r\n\r\n this._postProcesses = {};\r\n }\r\n\r\n /**\r\n * Checks if all the post processes in the effect are supported.\r\n */\r\n public get isSupported(): boolean {\r\n for (const index in this._postProcesses) {\r\n if (Object.prototype.hasOwnProperty.call(this._postProcesses, index)) {\r\n const pps = this._postProcesses[index];\r\n for (let ppIndex = 0; ppIndex < pps.length; ppIndex++) {\r\n if (!pps[ppIndex].isSupported) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Updates the current state of the effect\r\n * @internal\r\n */\r\n public _update(): void {}\r\n\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: Camera): void;\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: Camera[]): void;\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: any): void {\r\n let cameraKey;\r\n\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n if (!camera) {\r\n continue;\r\n }\r\n\r\n const cameraName = camera.name;\r\n\r\n if (this._singleInstance) {\r\n cameraKey = 0;\r\n } else {\r\n cameraKey = cameraName;\r\n }\r\n\r\n if (!this._postProcesses[cameraKey]) {\r\n const postProcess = this._getPostProcesses();\r\n if (postProcess) {\r\n this._postProcesses[cameraKey] = Array.isArray(postProcess) ? postProcess : [postProcess];\r\n }\r\n }\r\n\r\n if (!this._indicesForCamera[cameraName]) {\r\n this._indicesForCamera[cameraName] = [];\r\n }\r\n\r\n this._postProcesses[cameraKey].forEach((postProcess: PostProcess) => {\r\n const index = camera.attachPostProcess(postProcess);\r\n\r\n this._indicesForCamera[cameraName].push(index);\r\n });\r\n\r\n if (!this._cameras[cameraName]) {\r\n this._cameras[cameraName] = camera;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: Camera): void;\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: Camera[]): void;\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: any): void {\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera: Camera = cams[i];\r\n const cameraName: string = camera.name;\r\n const postProcesses = this._postProcesses[this._singleInstance ? 0 : cameraName];\r\n\r\n if (postProcesses) {\r\n postProcesses.forEach((postProcess: PostProcess) => {\r\n camera.detachPostProcess(postProcess);\r\n });\r\n }\r\n\r\n if (this._cameras[cameraName]) {\r\n this._cameras[cameraName] = null;\r\n }\r\n\r\n delete this._indicesForCamera[cameraName];\r\n }\r\n }\r\n\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: Camera): void;\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: Nullable): void;\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: any): void {\r\n const cams: Nullable> = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n const cameraName = camera.name;\r\n const cameraKey = this._singleInstance ? 0 : cameraName;\r\n\r\n for (let j = 0; j < this._indicesForCamera[cameraName].length; j++) {\r\n const index = this._indicesForCamera[cameraName][j];\r\n const postProcess = camera._postProcesses[index];\r\n if (postProcess === undefined || postProcess === null) {\r\n cams![i].attachPostProcess(this._postProcesses[cameraKey][j], index);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: Camera): void;\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: Nullable): void;\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: any): void {\r\n const cams: Nullable> = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n const cameraName = camera.name;\r\n this._postProcesses[this._singleInstance ? 0 : cameraName].forEach((postProcess) => {\r\n camera.detachPostProcess(postProcess);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Gets a list of the post processes contained in the effect.\r\n * @param camera The camera to get the post processes on.\r\n * @returns The list of the post processes in the effect.\r\n */\r\n public getPostProcesses(camera?: Camera): Nullable> {\r\n if (this._singleInstance) {\r\n return this._postProcesses[0];\r\n } else {\r\n if (!camera) {\r\n return null;\r\n }\r\n return this._postProcesses[camera.name];\r\n }\r\n }\r\n}\r\n","import type { Camera } from \"../../Cameras/camera\";\r\nimport type { PostProcessRenderPipeline } from \"./postProcessRenderPipeline\";\r\n/**\r\n * PostProcessRenderPipelineManager class\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n */\r\nexport class PostProcessRenderPipelineManager {\r\n private _renderPipelines: { [Key: string]: PostProcessRenderPipeline };\r\n\r\n /**\r\n * Initializes a PostProcessRenderPipelineManager\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n */\r\n constructor() {\r\n this._renderPipelines = {};\r\n }\r\n\r\n /**\r\n * Gets the list of supported render pipelines\r\n */\r\n public get supportedPipelines(): PostProcessRenderPipeline[] {\r\n const result = [];\r\n\r\n for (const renderPipelineName in this._renderPipelines) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\r\n const pipeline = this._renderPipelines[renderPipelineName];\r\n if (pipeline.isSupported) {\r\n result.push(pipeline);\r\n }\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Adds a pipeline to the manager\r\n * @param renderPipeline The pipeline to add\r\n */\r\n public addPipeline(renderPipeline: PostProcessRenderPipeline): void {\r\n this._renderPipelines[renderPipeline._name] = renderPipeline;\r\n }\r\n\r\n /**\r\n * Remove the pipeline from the manager\r\n * @param renderPipelineName the name of the pipeline to remove\r\n */\r\n public removePipeline(renderPipelineName: string): void {\r\n delete this._renderPipelines[renderPipelineName];\r\n }\r\n\r\n /**\r\n * Attaches a camera to the pipeline\r\n * @param renderPipelineName The name of the pipeline to attach to\r\n * @param cameras the camera to attach\r\n * @param unique if the camera can be attached multiple times to the pipeline\r\n */\r\n public attachCamerasToRenderPipeline(renderPipelineName: string, cameras: any | Camera[] | Camera, unique: boolean = false): void {\r\n const renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];\r\n\r\n if (!renderPipeline) {\r\n return;\r\n }\r\n\r\n renderPipeline._attachCameras(cameras, unique);\r\n }\r\n\r\n /**\r\n * Detaches a camera from the pipeline\r\n * @param renderPipelineName The name of the pipeline to detach from\r\n * @param cameras the camera to detach\r\n */\r\n public detachCamerasFromRenderPipeline(renderPipelineName: string, cameras: any | Camera[] | Camera): void {\r\n const renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];\r\n\r\n if (!renderPipeline) {\r\n return;\r\n }\r\n\r\n renderPipeline._detachCameras(cameras);\r\n }\r\n\r\n /**\r\n * Enables an effect by name on a pipeline\r\n * @param renderPipelineName the name of the pipeline to enable the effect in\r\n * @param renderEffectName the name of the effect to enable\r\n * @param cameras the cameras that the effect should be enabled on\r\n */\r\n public enableEffectInPipeline(renderPipelineName: string, renderEffectName: string, cameras: any | Camera[] | Camera): void {\r\n const renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];\r\n\r\n if (!renderPipeline) {\r\n return;\r\n }\r\n\r\n renderPipeline._enableEffect(renderEffectName, cameras);\r\n }\r\n\r\n /**\r\n * Disables an effect by name on a pipeline\r\n * @param renderPipelineName the name of the pipeline to disable the effect in\r\n * @param renderEffectName the name of the effect to disable\r\n * @param cameras the cameras that the effect should be disabled on\r\n */\r\n public disableEffectInPipeline(renderPipelineName: string, renderEffectName: string, cameras: any | Camera[] | Camera): void {\r\n const renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];\r\n\r\n if (!renderPipeline) {\r\n return;\r\n }\r\n\r\n renderPipeline._disableEffect(renderEffectName, cameras);\r\n }\r\n\r\n /**\r\n * Updates the state of all contained render pipelines and disposes of any non supported pipelines\r\n */\r\n public update(): void {\r\n for (const renderPipelineName in this._renderPipelines) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\r\n const pipeline = this._renderPipelines[renderPipelineName];\r\n if (!pipeline.isSupported) {\r\n pipeline.dispose();\r\n delete this._renderPipelines[renderPipelineName];\r\n } else {\r\n pipeline._update();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n for (const renderPipelineName in this._renderPipelines) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\r\n const pipeline = this._renderPipelines[renderPipelineName];\r\n pipeline._rebuild();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the manager and pipelines\r\n */\r\n public dispose(): void {\r\n for (const renderPipelineName in this._renderPipelines) {\r\n if (Object.prototype.hasOwnProperty.call(this._renderPipelines, renderPipelineName)) {\r\n const pipeline = this._renderPipelines[renderPipelineName];\r\n pipeline.dispose();\r\n }\r\n }\r\n }\r\n}\r\n","import type { ISceneComponent } from \"../../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../../sceneComponent\";\r\nimport { PostProcessRenderPipelineManager } from \"./postProcessRenderPipelineManager\";\r\nimport { Scene } from \"../../scene\";\r\n\r\ndeclare module \"../../scene\" {\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _postProcessRenderPipelineManager: PostProcessRenderPipelineManager;\r\n\r\n /**\r\n * Gets the postprocess render pipeline manager\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/defaultRenderingPipeline\r\n */\r\n readonly postProcessRenderPipelineManager: PostProcessRenderPipelineManager;\r\n }\r\n}\r\n\r\nObject.defineProperty(Scene.prototype, \"postProcessRenderPipelineManager\", {\r\n get: function (this: Scene) {\r\n if (!this._postProcessRenderPipelineManager) {\r\n // Register the G Buffer component to the scene.\r\n let component = this._getComponent(SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER) as PostProcessRenderPipelineManagerSceneComponent;\r\n if (!component) {\r\n component = new PostProcessRenderPipelineManagerSceneComponent(this);\r\n this._addComponent(component);\r\n }\r\n this._postProcessRenderPipelineManager = new PostProcessRenderPipelineManager();\r\n }\r\n\r\n return this._postProcessRenderPipelineManager;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * Defines the Render Pipeline scene component responsible to rendering pipelines\r\n */\r\nexport class PostProcessRenderPipelineManagerSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER, this, this._gatherRenderTargets);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n if (this.scene._postProcessRenderPipelineManager) {\r\n this.scene._postProcessRenderPipelineManager._rebuild();\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n if (this.scene._postProcessRenderPipelineManager) {\r\n this.scene._postProcessRenderPipelineManager.dispose();\r\n }\r\n }\r\n\r\n private _gatherRenderTargets(): void {\r\n if (this.scene._postProcessRenderPipelineManager) {\r\n this.scene._postProcessRenderPipelineManager.update();\r\n }\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"chromaticAberrationPixelShader\";\nconst shader = `uniform sampler2D textureSampler; \nuniform float chromatic_aberration;uniform float radialIntensity;uniform vec2 direction;uniform vec2 centerPosition;uniform float screen_width;uniform float screen_height;varying vec2 vUV;\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec2 centered_screen_pos=vec2(vUV.x-centerPosition.x,vUV.y-centerPosition.y);vec2 directionOfEffect=direction;if(directionOfEffect.x==0. && directionOfEffect.y==0.){directionOfEffect=normalize(centered_screen_pos);}\nfloat radius2=centered_screen_pos.x*centered_screen_pos.x\n+ centered_screen_pos.y*centered_screen_pos.y;float radius=sqrt(radius2);vec4 original=texture2D(textureSampler,vUV);vec3 ref_indices=vec3(-0.3,0.0,0.3);float ref_shiftX=chromatic_aberration*pow(radius,radialIntensity)*directionOfEffect.x/screen_width;float ref_shiftY=chromatic_aberration*pow(radius,radialIntensity)*directionOfEffect.y/screen_height;vec2 ref_coords_r=vec2(vUV.x+ref_indices.r*ref_shiftX,vUV.y+ref_indices.r*ref_shiftY*0.5);vec2 ref_coords_g=vec2(vUV.x+ref_indices.g*ref_shiftX,vUV.y+ref_indices.g*ref_shiftY*0.5);vec2 ref_coords_b=vec2(vUV.x+ref_indices.b*ref_shiftX,vUV.y+ref_indices.b*ref_shiftY*0.5);original.r=texture2D(textureSampler,ref_coords_r).r;original.g=texture2D(textureSampler,ref_coords_g).g;original.b=texture2D(textureSampler,ref_coords_b).b;original.a=clamp(texture2D(textureSampler,ref_coords_r).a+texture2D(textureSampler,ref_coords_g).a+texture2D(textureSampler,ref_coords_b).a,0.,1.);gl_FragColor=original;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const chromaticAberrationPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"lensHighlightsPixelShader\";\nconst shader = `uniform sampler2D textureSampler; \nuniform float gain;uniform float threshold;uniform float screen_width;uniform float screen_height;varying vec2 vUV;vec4 highlightColor(vec4 color) {vec4 highlight=color;float luminance=dot(highlight.rgb,vec3(0.2125,0.7154,0.0721));float lum_threshold;if (threshold>1.0) { lum_threshold=0.94+0.01*threshold; }\nelse { lum_threshold=0.5+0.44*threshold; }\nluminance=clamp((luminance-lum_threshold)*(1.0/(1.0-lum_threshold)),0.0,1.0);highlight*=luminance*gain;highlight.a=1.0;return highlight;}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec4 original=texture2D(textureSampler,vUV);if (gain==-1.0) {gl_FragColor=vec4(0.0,0.0,0.0,1.0);return;}\nfloat w=2.0/screen_width;float h=2.0/screen_height;float weight=1.0;vec4 blurred=vec4(0.0,0.0,0.0,0.0);\n#ifdef PENTAGON\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.84*w,0.43*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.48*w,-1.29*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.61*w,1.51*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.55*w,-0.74*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.71*w,-0.52*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.94*w,1.59*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.40*w,-1.87*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.62*w,1.16*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.09*w,0.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.46*w,-1.71*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.08*w,2.42*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.85*w,-1.89*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.89*w,0.16*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.29*w,1.88*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.40*w,-2.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.54*w,2.26*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.60*w,-0.61*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.31*w,-1.30*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.83*w,2.53*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.12*w,-2.48*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.60*w,1.11*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.99*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.50*w,-2.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.85*w,3.33*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.94*w,-1.92*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.27*w,-0.53*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.95*w,2.48*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.23*w,-3.04*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.17*w,2.05*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.97*w,-0.04*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.25*w,-2.00*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.31*w,3.08*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.94*w,-2.59*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.37*w,0.64*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.13*w,1.93*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.03*w,-3.65*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.60*w,3.17*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.14*w,-1.19*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.00*w,-1.19*h)));\n#else\nblurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.85*w,0.36*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.52*w,-1.14*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.46*w,1.42*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.46*w,-0.83*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.79*w,-0.42*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.11*w,1.62*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.29*w,-2.07*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.69*w,1.39*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.28*w,0.12*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.65*w,-1.69*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.08*w,2.44*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.63*w,-1.90*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.55*w,0.31*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.13*w,1.52*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.56*w,-2.61*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.38*w,2.34*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.64*w,-0.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.53*w,-1.21*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.06*w,2.63*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.00*w,-2.69*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.59*w,1.32*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.82*w,0.78*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.57*w,-2.50*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(0.54*w,2.93*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.39*w,-1.81*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,-0.28*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.04*w,2.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.02*w,-3.05*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.09*w,2.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-3.07*w,-0.25*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.44*w,-1.90*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-0.52*w,3.05*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-1.68*w,-2.61*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(3.01*w,0.79*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.76*w,1.46*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.05*w,-2.94*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(1.21*w,2.88*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(-2.84*w,-1.30*h)));blurred+=highlightColor(texture2D(textureSampler,vUV+vec2(2.98*w,-0.96*h)));\n#endif\nblurred/=39.0;gl_FragColor=blurred;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const lensHighlightsPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"depthOfFieldPixelShader\";\nconst shader = `uniform sampler2D textureSampler;uniform sampler2D highlightsSampler;uniform sampler2D depthSampler;uniform sampler2D grainSampler;uniform float grain_amount;uniform bool blur_noise;uniform float screen_width;uniform float screen_height;uniform float distortion;uniform bool dof_enabled;uniform float screen_distance; \nuniform float aperture;uniform float darken;uniform float edge_blur;uniform bool highlights;uniform float near;uniform float far;varying vec2 vUV;\n#define PI 3.14159265\n#define TWOPI 6.28318530\n#define inverse_focal_length 0.1 \nvec2 centered_screen_pos;vec2 distorted_coords;float radius2;float radius;vec2 rand(vec2 co)\n{float noise1=(fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453));float noise2=(fract(sin(dot(co,vec2(12.9898,78.233)*2.0))*43758.5453));return clamp(vec2(noise1,noise2),0.0,1.0);}\nvec2 getDistortedCoords(vec2 coords) {if (distortion==0.0) { return coords; }\nvec2 direction=1.0*normalize(centered_screen_pos);vec2 dist_coords=vec2(0.5,0.5);dist_coords.x=0.5+direction.x*radius2*1.0;dist_coords.y=0.5+direction.y*radius2*1.0;float dist_amount=clamp(distortion*0.23,0.0,1.0);dist_coords=mix(coords,dist_coords,dist_amount);return dist_coords;}\nfloat sampleScreen(inout vec4 color,in vec2 offset,in float weight) {vec2 coords=distorted_coords;float angle=rand(coords*100.0).x*TWOPI;coords+=vec2(offset.x*cos(angle)-offset.y*sin(angle),offset.x*sin(angle)+offset.y*cos(angle));color+=texture2D(textureSampler,coords)*weight;return weight;}\nfloat getBlurLevel(float size) {return min(3.0,ceil(size/1.0));}\nvec4 getBlurColor(float size) {vec4 col=texture2D(textureSampler,distorted_coords);float blur_level=getBlurLevel(size);float w=(size/screen_width);float h=(size/screen_height);float total_weight=1.0;vec2 sample_coords;total_weight+=sampleScreen(col,vec2(-0.50*w,0.24*h),0.93);total_weight+=sampleScreen(col,vec2(0.30*w,-0.75*h),0.90);total_weight+=sampleScreen(col,vec2(0.36*w,0.96*h),0.87);total_weight+=sampleScreen(col,vec2(-1.08*w,-0.55*h),0.85);total_weight+=sampleScreen(col,vec2(1.33*w,-0.37*h),0.83);total_weight+=sampleScreen(col,vec2(-0.82*w,1.31*h),0.80);total_weight+=sampleScreen(col,vec2(-0.31*w,-1.67*h),0.78);total_weight+=sampleScreen(col,vec2(1.47*w,1.11*h),0.76);total_weight+=sampleScreen(col,vec2(-1.97*w,0.19*h),0.74);total_weight+=sampleScreen(col,vec2(1.42*w,-1.57*h),0.72);if (blur_level>1.0) {total_weight+=sampleScreen(col,vec2(0.01*w,2.25*h),0.70);total_weight+=sampleScreen(col,vec2(-1.62*w,-1.74*h),0.67);total_weight+=sampleScreen(col,vec2(2.49*w,0.20*h),0.65);total_weight+=sampleScreen(col,vec2(-2.07*w,1.61*h),0.63);total_weight+=sampleScreen(col,vec2(0.46*w,-2.70*h),0.61);total_weight+=sampleScreen(col,vec2(1.55*w,2.40*h),0.59);total_weight+=sampleScreen(col,vec2(-2.88*w,-0.75*h),0.56);total_weight+=sampleScreen(col,vec2(2.73*w,-1.44*h),0.54);total_weight+=sampleScreen(col,vec2(-1.08*w,3.02*h),0.52);total_weight+=sampleScreen(col,vec2(-1.28*w,-3.05*h),0.49);}\nif (blur_level>2.0) {total_weight+=sampleScreen(col,vec2(3.11*w,1.43*h),0.46);total_weight+=sampleScreen(col,vec2(-3.36*w,1.08*h),0.44);total_weight+=sampleScreen(col,vec2(1.80*w,-3.16*h),0.41);total_weight+=sampleScreen(col,vec2(0.83*w,3.65*h),0.38);total_weight+=sampleScreen(col,vec2(-3.16*w,-2.19*h),0.34);total_weight+=sampleScreen(col,vec2(3.92*w,-0.53*h),0.31);total_weight+=sampleScreen(col,vec2(-2.59*w,3.12*h),0.26);total_weight+=sampleScreen(col,vec2(-0.20*w,-4.15*h),0.22);total_weight+=sampleScreen(col,vec2(3.02*w,3.00*h),0.15);}\ncol/=total_weight; \nif (darken>0.0) {col.rgb*=clamp(0.3,1.0,1.05-size*0.5*darken);}\nreturn col;}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{centered_screen_pos=vec2(vUV.x-0.5,vUV.y-0.5);radius2=centered_screen_pos.x*centered_screen_pos.x+centered_screen_pos.y*centered_screen_pos.y;radius=sqrt(radius2);distorted_coords=getDistortedCoords(vUV); \nvec2 texels_coords=vec2(vUV.x*screen_width,vUV.y*screen_height); \nfloat depth=texture2D(depthSampler,distorted_coords).r; \nfloat distance=near+(far-near)*depth; \nvec4 color=texture2D(textureSampler,vUV); \nfloat coc=abs(aperture*(screen_distance*(inverse_focal_length-1.0/distance)-1.0));if (dof_enabled==false || coc<0.07) { coc=0.0; }\nfloat edge_blur_amount=0.0;if (edge_blur>0.0) {edge_blur_amount=clamp((radius*2.0-1.0+0.15*edge_blur)*1.5,0.0,1.0)*1.3;}\nfloat blur_amount=max(edge_blur_amount,coc);if (blur_amount==0.0) {gl_FragColor=texture2D(textureSampler,distorted_coords);}\nelse {gl_FragColor=getBlurColor(blur_amount*1.7);if (highlights) {gl_FragColor.rgb+=clamp(coc,0.0,1.0)*texture2D(highlightsSampler,distorted_coords).rgb;}\nif (blur_noise) {vec2 noise=rand(distorted_coords)*0.01*blur_amount;vec2 blurred_coord=vec2(distorted_coords.x+noise.x,distorted_coords.y+noise.y);gl_FragColor=0.04*texture2D(textureSampler,blurred_coord)+0.96*gl_FragColor;}}\nif (grain_amount>0.0) {vec4 grain_color=texture2D(grainSampler,texels_coords*0.003);gl_FragColor.rgb+=(-0.5+grain_color.rgb)*0.30*grain_amount;}}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const depthOfFieldPixelShader = { name, shader };\n","/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Camera } from \"../../../Cameras/camera\";\r\nimport type { Effect } from \"../../../Materials/effect\";\r\nimport { Texture } from \"../../../Materials/Textures/texture\";\r\nimport { DynamicTexture } from \"../../../Materials/Textures/dynamicTexture\";\r\nimport type { RenderTargetTexture } from \"../../../Materials/Textures/renderTargetTexture\";\r\nimport { PostProcess } from \"../../../PostProcesses/postProcess\";\r\nimport { PostProcessRenderPipeline } from \"../../../PostProcesses/RenderPipeline/postProcessRenderPipeline\";\r\nimport { PostProcessRenderEffect } from \"../../../PostProcesses/RenderPipeline/postProcessRenderEffect\";\r\nimport type { Scene } from \"../../../scene\";\r\n\r\nimport \"../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent\";\r\n\r\nimport \"../../../Shaders/chromaticAberration.fragment\";\r\nimport \"../../../Shaders/lensHighlights.fragment\";\r\nimport \"../../../Shaders/depthOfField.fragment\";\r\n\r\n/**\r\n * BABYLON.JS Chromatic Aberration GLSL Shader\r\n * Author: Olivier Guyot\r\n * Separates very slightly R, G and B colors on the edges of the screen\r\n * Inspired by Francois Tarlier & Martins Upitis\r\n */\r\nexport class LensRenderingPipeline extends PostProcessRenderPipeline {\r\n // Lens effects can be of the following:\r\n // - chromatic aberration (slight shift of RGB colors)\r\n // - blur on the edge of the lens\r\n // - lens distortion\r\n // - depth-of-field blur & highlights enhancing\r\n // - depth-of-field 'bokeh' effect (shapes appearing in blurred areas)\r\n // - grain effect (noise or custom texture)\r\n\r\n // Two additional texture samplers are needed:\r\n // - depth map (for depth-of-field)\r\n // - grain texture\r\n\r\n /**\r\n * @ignore\r\n * The chromatic aberration PostProcess id in the pipeline\r\n */\r\n public LensChromaticAberrationEffect: string = \"LensChromaticAberrationEffect\";\r\n /**\r\n * @ignore\r\n * The highlights enhancing PostProcess id in the pipeline\r\n */\r\n public HighlightsEnhancingEffect: string = \"HighlightsEnhancingEffect\";\r\n /**\r\n * @ignore\r\n * The depth-of-field PostProcess id in the pipeline\r\n */\r\n public LensDepthOfFieldEffect: string = \"LensDepthOfFieldEffect\";\r\n\r\n private _scene: Scene;\r\n private _depthTexture: RenderTargetTexture;\r\n private _grainTexture: Texture;\r\n\r\n private _chromaticAberrationPostProcess: PostProcess;\r\n private _highlightsPostProcess: PostProcess;\r\n private _depthOfFieldPostProcess: PostProcess;\r\n\r\n private _edgeBlur: number;\r\n private _grainAmount: number;\r\n private _chromaticAberration: number;\r\n private _distortion: number;\r\n private _highlightsGain: number;\r\n private _highlightsThreshold: number;\r\n private _dofDistance: number;\r\n private _dofAperture: number;\r\n private _dofDarken: number;\r\n private _dofPentagon: boolean;\r\n private _blurNoise: boolean;\r\n\r\n /**\r\n * @constructor\r\n *\r\n * Effect parameters are as follow:\r\n * {\r\n * chromatic_aberration: number; // from 0 to x (1 for realism)\r\n * edge_blur: number; // from 0 to x (1 for realism)\r\n * distortion: number; // from 0 to x (1 for realism), note that this will effect the pointer position precision\r\n * grain_amount: number; // from 0 to 1\r\n * grain_texture: BABYLON.Texture; // texture to use for grain effect; if unset, use random B&W noise\r\n * dof_focus_distance: number; // depth-of-field: focus distance; unset to disable (disabled by default)\r\n * dof_aperture: number; // depth-of-field: focus blur bias (default: 1)\r\n * dof_darken: number; // depth-of-field: darken that which is out of focus (from 0 to 1, disabled by default)\r\n * dof_pentagon: boolean; // depth-of-field: makes a pentagon-like \"bokeh\" effect\r\n * dof_gain: number; // depth-of-field: highlights gain; unset to disable (disabled by default)\r\n * dof_threshold: number; // depth-of-field: highlights threshold (default: 1)\r\n * blur_noise: boolean; // add a little bit of noise to the blur (default: true)\r\n * }\r\n * Note: if an effect parameter is unset, effect is disabled\r\n *\r\n * @param name The rendering pipeline name\r\n * @param parameters - An object containing all parameters (see above)\r\n * @param scene The scene linked to this pipeline\r\n * @param ratio The size of the postprocesses (0.5 means that your postprocess will have a width = canvas.width 0.5 and a height = canvas.height 0.5)\r\n * @param cameras The array of cameras that the rendering pipeline will be attached to\r\n */\r\n constructor(name: string, parameters: any, scene: Scene, ratio: number = 1.0, cameras?: Camera[]) {\r\n super(scene.getEngine(), name);\r\n\r\n this._scene = scene;\r\n\r\n // Fetch texture samplers\r\n this._depthTexture = scene.enableDepthRenderer().getDepthMap(); // Force depth renderer \"on\"\r\n if (parameters.grain_texture) {\r\n this._grainTexture = parameters.grain_texture;\r\n } else {\r\n this._createGrainTexture();\r\n }\r\n\r\n // save parameters\r\n this._edgeBlur = parameters.edge_blur ? parameters.edge_blur : 0;\r\n this._grainAmount = parameters.grain_amount ? parameters.grain_amount : 0;\r\n this._chromaticAberration = parameters.chromatic_aberration ? parameters.chromatic_aberration : 0;\r\n this._distortion = parameters.distortion ? parameters.distortion : 0;\r\n this._highlightsGain = parameters.dof_gain !== undefined ? parameters.dof_gain : -1;\r\n this._highlightsThreshold = parameters.dof_threshold ? parameters.dof_threshold : 1;\r\n this._dofDistance = parameters.dof_focus_distance !== undefined ? parameters.dof_focus_distance : -1;\r\n this._dofAperture = parameters.dof_aperture ? parameters.dof_aperture : 1;\r\n this._dofDarken = parameters.dof_darken ? parameters.dof_darken : 0;\r\n this._dofPentagon = parameters.dof_pentagon !== undefined ? parameters.dof_pentagon : true;\r\n this._blurNoise = parameters.blur_noise !== undefined ? parameters.blur_noise : true;\r\n\r\n // Create effects\r\n this._createChromaticAberrationPostProcess(ratio);\r\n this._createHighlightsPostProcess(ratio);\r\n this._createDepthOfFieldPostProcess(ratio / 4);\r\n\r\n // Set up pipeline\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.LensChromaticAberrationEffect,\r\n () => {\r\n return this._chromaticAberrationPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.HighlightsEnhancingEffect,\r\n () => {\r\n return this._highlightsPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.LensDepthOfFieldEffect,\r\n () => {\r\n return this._depthOfFieldPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n\r\n if (this._highlightsGain === -1) {\r\n this._disableEffect(this.HighlightsEnhancingEffect, null);\r\n }\r\n\r\n // Finish\r\n scene.postProcessRenderPipelineManager.addPipeline(this);\r\n if (cameras) {\r\n scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(name, cameras);\r\n }\r\n }\r\n\r\n /**\r\n * Get the class name\r\n * @returns \"LensRenderingPipeline\"\r\n */\r\n public getClassName(): string {\r\n return \"LensRenderingPipeline\";\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets associated scene\r\n */\r\n public get scene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Gets or sets the edge blur\r\n */\r\n public get edgeBlur(): number {\r\n return this._edgeBlur;\r\n }\r\n\r\n public set edgeBlur(value: number) {\r\n this.setEdgeBlur(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the grain amount\r\n */\r\n public get grainAmount(): number {\r\n return this._grainAmount;\r\n }\r\n\r\n public set grainAmount(value: number) {\r\n this.setGrainAmount(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the chromatic aberration amount\r\n */\r\n public get chromaticAberration(): number {\r\n return this._chromaticAberration;\r\n }\r\n\r\n public set chromaticAberration(value: number) {\r\n this.setChromaticAberration(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the depth of field aperture\r\n */\r\n public get dofAperture(): number {\r\n return this._dofAperture;\r\n }\r\n\r\n public set dofAperture(value: number) {\r\n this.setAperture(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the edge distortion\r\n */\r\n public get edgeDistortion(): number {\r\n return this._distortion;\r\n }\r\n\r\n public set edgeDistortion(value: number) {\r\n this.setEdgeDistortion(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the depth of field distortion\r\n */\r\n public get dofDistortion(): number {\r\n return this._dofDistance;\r\n }\r\n\r\n public set dofDistortion(value: number) {\r\n this.setFocusDistance(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the darken out of focus amount\r\n */\r\n public get darkenOutOfFocus(): number {\r\n return this._dofDarken;\r\n }\r\n\r\n public set darkenOutOfFocus(value: number) {\r\n this.setDarkenOutOfFocus(value);\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if blur noise is enabled\r\n */\r\n public get blurNoise(): boolean {\r\n return this._blurNoise;\r\n }\r\n\r\n public set blurNoise(value: boolean) {\r\n this._blurNoise = value;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if pentagon bokeh is enabled\r\n */\r\n public get pentagonBokeh(): boolean {\r\n return this._pentagonBokehIsEnabled;\r\n }\r\n\r\n public set pentagonBokeh(value: boolean) {\r\n if (value) {\r\n this.enablePentagonBokeh();\r\n } else {\r\n this.disablePentagonBokeh();\r\n }\r\n }\r\n\r\n /**\r\n * Gets or sets the highlight grain amount\r\n */\r\n public get highlightsGain(): number {\r\n return this._highlightsGain;\r\n }\r\n\r\n public set highlightsGain(value: number) {\r\n this.setHighlightsGain(value);\r\n }\r\n\r\n /**\r\n * Gets or sets the highlight threshold\r\n */\r\n public get highlightsThreshold(): number {\r\n return this._highlightsThreshold;\r\n }\r\n\r\n public set highlightsThreshold(value: number) {\r\n this.setHighlightsThreshold(value);\r\n }\r\n\r\n // public methods (self explanatory)\r\n /**\r\n * Sets the amount of blur at the edges\r\n * @param amount blur amount\r\n */\r\n public setEdgeBlur(amount: number) {\r\n this._edgeBlur = amount;\r\n }\r\n /**\r\n * Sets edge blur to 0\r\n */\r\n public disableEdgeBlur() {\r\n this._edgeBlur = 0;\r\n }\r\n /**\r\n * Sets the amount of grain\r\n * @param amount Amount of grain\r\n */\r\n public setGrainAmount(amount: number) {\r\n this._grainAmount = amount;\r\n }\r\n /**\r\n * Set grain amount to 0\r\n */\r\n public disableGrain() {\r\n this._grainAmount = 0;\r\n }\r\n /**\r\n * Sets the chromatic aberration amount\r\n * @param amount amount of chromatic aberration\r\n */\r\n public setChromaticAberration(amount: number) {\r\n this._chromaticAberration = amount;\r\n }\r\n /**\r\n * Sets chromatic aberration amount to 0\r\n */\r\n public disableChromaticAberration() {\r\n this._chromaticAberration = 0;\r\n }\r\n /**\r\n * Sets the EdgeDistortion amount\r\n * @param amount amount of EdgeDistortion\r\n */\r\n public setEdgeDistortion(amount: number) {\r\n this._distortion = amount;\r\n }\r\n /**\r\n * Sets edge distortion to 0\r\n */\r\n public disableEdgeDistortion() {\r\n this._distortion = 0;\r\n }\r\n /**\r\n * Sets the FocusDistance amount\r\n * @param amount amount of FocusDistance\r\n */\r\n public setFocusDistance(amount: number) {\r\n this._dofDistance = amount;\r\n }\r\n /**\r\n * Disables depth of field\r\n */\r\n public disableDepthOfField() {\r\n this._dofDistance = -1;\r\n }\r\n /**\r\n * Sets the Aperture amount\r\n * @param amount amount of Aperture\r\n */\r\n public setAperture(amount: number) {\r\n this._dofAperture = amount;\r\n }\r\n /**\r\n * Sets the DarkenOutOfFocus amount\r\n * @param amount amount of DarkenOutOfFocus\r\n */\r\n public setDarkenOutOfFocus(amount: number) {\r\n this._dofDarken = amount;\r\n }\r\n\r\n private _pentagonBokehIsEnabled = false;\r\n /**\r\n * Creates a pentagon bokeh effect\r\n */\r\n public enablePentagonBokeh() {\r\n this._highlightsPostProcess.updateEffect(\"#define PENTAGON\\n\");\r\n this._pentagonBokehIsEnabled = true;\r\n }\r\n /**\r\n * Disables the pentagon bokeh effect\r\n */\r\n public disablePentagonBokeh() {\r\n this._pentagonBokehIsEnabled = false;\r\n this._highlightsPostProcess.updateEffect();\r\n }\r\n /**\r\n * Enables noise blur\r\n */\r\n public enableNoiseBlur() {\r\n this._blurNoise = true;\r\n }\r\n /**\r\n * Disables noise blur\r\n */\r\n public disableNoiseBlur() {\r\n this._blurNoise = false;\r\n }\r\n /**\r\n * Sets the HighlightsGain amount\r\n * @param amount amount of HighlightsGain\r\n */\r\n public setHighlightsGain(amount: number) {\r\n this._highlightsGain = amount;\r\n }\r\n /**\r\n * Sets the HighlightsThreshold amount\r\n * @param amount amount of HighlightsThreshold\r\n */\r\n public setHighlightsThreshold(amount: number) {\r\n if (this._highlightsGain === -1) {\r\n this._highlightsGain = 1.0;\r\n }\r\n this._highlightsThreshold = amount;\r\n }\r\n /**\r\n * Disables highlights\r\n */\r\n public disableHighlights() {\r\n this._highlightsGain = -1;\r\n }\r\n\r\n /**\r\n * Removes the internal pipeline assets and detaches the pipeline from the scene cameras\r\n * @param disableDepthRender If the scene's depth rendering should be disabled (default: false)\r\n */\r\n public dispose(disableDepthRender: boolean = false): void {\r\n this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);\r\n\r\n (this._chromaticAberrationPostProcess) = null;\r\n (this._highlightsPostProcess) = null;\r\n (this._depthOfFieldPostProcess) = null;\r\n\r\n this._grainTexture.dispose();\r\n\r\n if (disableDepthRender) {\r\n this._scene.disableDepthRenderer();\r\n }\r\n }\r\n\r\n // colors shifting and distortion\r\n private _createChromaticAberrationPostProcess(ratio: number): void {\r\n this._chromaticAberrationPostProcess = new PostProcess(\r\n \"LensChromaticAberration\",\r\n \"chromaticAberration\",\r\n [\"chromatic_aberration\", \"screen_width\", \"screen_height\", \"direction\", \"radialIntensity\", \"centerPosition\"], // uniforms\r\n [], // samplers\r\n ratio,\r\n null,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n this._scene.getEngine(),\r\n false\r\n );\r\n\r\n this._chromaticAberrationPostProcess.onApply = (effect: Effect) => {\r\n effect.setFloat(\"chromatic_aberration\", this._chromaticAberration);\r\n effect.setFloat(\"screen_width\", this._scene.getEngine().getRenderWidth());\r\n effect.setFloat(\"screen_height\", this._scene.getEngine().getRenderHeight());\r\n effect.setFloat(\"radialIntensity\", 1);\r\n effect.setFloat2(\"direction\", 17, 17);\r\n effect.setFloat2(\"centerPosition\", 0.5, 0.5);\r\n };\r\n }\r\n\r\n // highlights enhancing\r\n private _createHighlightsPostProcess(ratio: number): void {\r\n this._highlightsPostProcess = new PostProcess(\r\n \"LensHighlights\",\r\n \"lensHighlights\",\r\n [\"gain\", \"threshold\", \"screen_width\", \"screen_height\"], // uniforms\r\n [], // samplers\r\n ratio,\r\n null,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n this._scene.getEngine(),\r\n false,\r\n this._dofPentagon ? \"#define PENTAGON\\n\" : \"\"\r\n );\r\n\r\n this._highlightsPostProcess.externalTextureSamplerBinding = true;\r\n this._highlightsPostProcess.onApply = (effect: Effect) => {\r\n effect.setFloat(\"gain\", this._highlightsGain);\r\n effect.setFloat(\"threshold\", this._highlightsThreshold);\r\n effect.setTextureFromPostProcess(\"textureSampler\", this._chromaticAberrationPostProcess);\r\n effect.setFloat(\"screen_width\", this._scene.getEngine().getRenderWidth());\r\n effect.setFloat(\"screen_height\", this._scene.getEngine().getRenderHeight());\r\n };\r\n }\r\n\r\n // colors shifting and distortion\r\n private _createDepthOfFieldPostProcess(ratio: number): void {\r\n this._depthOfFieldPostProcess = new PostProcess(\r\n \"LensDepthOfField\",\r\n \"depthOfField\",\r\n [\r\n \"grain_amount\",\r\n \"blur_noise\",\r\n \"screen_width\",\r\n \"screen_height\",\r\n \"distortion\",\r\n \"dof_enabled\",\r\n \"screen_distance\",\r\n \"aperture\",\r\n \"darken\",\r\n \"edge_blur\",\r\n \"highlights\",\r\n \"near\",\r\n \"far\",\r\n ],\r\n [\"depthSampler\", \"grainSampler\", \"highlightsSampler\"],\r\n ratio,\r\n null,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n this._scene.getEngine(),\r\n false\r\n );\r\n\r\n this._depthOfFieldPostProcess.externalTextureSamplerBinding = true;\r\n this._depthOfFieldPostProcess.onApply = (effect: Effect) => {\r\n effect.setTexture(\"depthSampler\", this._depthTexture);\r\n effect.setTexture(\"grainSampler\", this._grainTexture);\r\n effect.setTextureFromPostProcess(\"textureSampler\", this._highlightsPostProcess);\r\n effect.setTextureFromPostProcess(\"highlightsSampler\", this._depthOfFieldPostProcess);\r\n\r\n effect.setFloat(\"grain_amount\", this._grainAmount);\r\n effect.setBool(\"blur_noise\", this._blurNoise);\r\n\r\n effect.setFloat(\"screen_width\", this._scene.getEngine().getRenderWidth());\r\n effect.setFloat(\"screen_height\", this._scene.getEngine().getRenderHeight());\r\n\r\n effect.setFloat(\"distortion\", this._distortion);\r\n\r\n effect.setBool(\"dof_enabled\", this._dofDistance !== -1);\r\n effect.setFloat(\"screen_distance\", 1.0 / (0.1 - 1.0 / this._dofDistance));\r\n effect.setFloat(\"aperture\", this._dofAperture);\r\n effect.setFloat(\"darken\", this._dofDarken);\r\n\r\n effect.setFloat(\"edge_blur\", this._edgeBlur);\r\n\r\n effect.setBool(\"highlights\", this._highlightsGain !== -1);\r\n\r\n if (this._scene.activeCamera) {\r\n effect.setFloat(\"near\", this._scene.activeCamera.minZ);\r\n effect.setFloat(\"far\", this._scene.activeCamera.maxZ);\r\n }\r\n };\r\n }\r\n\r\n // creates a black and white random noise texture, 512x512\r\n private _createGrainTexture(): void {\r\n const size = 512;\r\n\r\n this._grainTexture = new DynamicTexture(\"LensNoiseTexture\", size, this._scene, false, Texture.BILINEAR_SAMPLINGMODE);\r\n this._grainTexture.wrapU = Texture.WRAP_ADDRESSMODE;\r\n this._grainTexture.wrapV = Texture.WRAP_ADDRESSMODE;\r\n\r\n const context = (this._grainTexture).getContext();\r\n\r\n const rand = (min: number, max: number) => {\r\n return Math.random() * (max - min) + min;\r\n };\r\n\r\n let value;\r\n for (let x = 0; x < size; x++) {\r\n for (let y = 0; y < size; y++) {\r\n value = Math.floor(rand(0.42, 0.58) * 255);\r\n context.fillStyle = \"rgb(\" + value + \", \" + value + \", \" + value + \")\";\r\n context.fillRect(x, y, 1, 1);\r\n }\r\n }\r\n (this._grainTexture).update(false);\r\n }\r\n}\r\n","import { Constants } from \"../Engines/constants\";\r\nimport type { PrePassEffectConfiguration } from \"./prePassEffectConfiguration\";\r\n\r\n/**\r\n * Contains all parameters needed for the prepass to perform\r\n * screen space subsurface scattering\r\n */\r\nexport class SSAO2Configuration implements PrePassEffectConfiguration {\r\n /**\r\n * Is subsurface enabled\r\n */\r\n public enabled = false;\r\n\r\n /**\r\n * Name of the configuration\r\n */\r\n public name = \"ssao2\";\r\n\r\n /**\r\n * Textures that should be present in the MRT for this effect to work\r\n */\r\n public readonly texturesRequired: number[] = [Constants.PREPASS_NORMAL_TEXTURE_TYPE, Constants.PREPASS_DEPTH_TEXTURE_TYPE];\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"ssao2PixelShader\";\nconst shader = `precision highp float;uniform sampler2D textureSampler;varying vec2 vUV;\n#ifdef SSAO\nfloat scales[16]=float[16](\n0.1,\n0.11406250000000001,\n0.131640625,\n0.15625,\n0.187890625,\n0.2265625,\n0.272265625,\n0.325,\n0.384765625,\n0.4515625,\n0.525390625,\n0.60625,\n0.694140625,\n0.7890625,\n0.891015625,\n1.0\n);uniform float near;uniform float radius;uniform sampler2D depthSampler;uniform sampler2D randomSampler;uniform sampler2D normalSampler;uniform float randTextureTiles;uniform float samplesFactor;uniform vec3 sampleSphere[SAMPLES];uniform float totalStrength;uniform float base;uniform float xViewport;uniform float yViewport;uniform mat3 depthProjection;uniform float maxZ;uniform float minZAspect;uniform vec2 texelSize;uniform mat4 projection;void main()\n{vec3 random=textureLod(randomSampler,vUV*randTextureTiles,0.0).rgb;float depth=textureLod(depthSampler,vUV,0.0).r;float depthSign=depth/abs(depth);depth=depth*depthSign;vec3 normal=textureLod(normalSampler,vUV,0.0).rgb;float occlusion=0.0;float correctedRadius=min(radius,minZAspect*depth/near);vec3 vViewRay=vec3((vUV.x*2.0-1.0)*xViewport,(vUV.y*2.0-1.0)*yViewport,depthSign);vec3 vDepthFactor=depthProjection*vec3(1.0,1.0,depth);vec3 origin=vViewRay*vDepthFactor;vec3 rvec=random*2.0-1.0;rvec.z=0.0;float dotProduct=dot(rvec,normal);rvec=1.0-abs(dotProduct)>1e-2 ? rvec : vec3(-rvec.y,0.0,rvec.x);vec3 tangent=normalize(rvec-normal*dot(rvec,normal));vec3 bitangent=cross(normal,tangent);mat3 tbn=mat3(tangent,bitangent,normal);float difference;for (int i=0; i1.0 || offset.y>1.0) {continue;}\nfloat sampleDepth=abs(textureLod(depthSampler,offset.xy,0.0).r);difference=depthSign*samplePosition.z-sampleDepth;float rangeCheck=1.0-smoothstep(correctedRadius*0.5,correctedRadius,difference);occlusion+=step(EPSILON,difference)*rangeCheck;}\nocclusion=occlusion*(1.0-smoothstep(maxZ*0.75,maxZ,depth));float ao=1.0-totalStrength*occlusion*samplesFactor;float result=clamp(ao+base,0.0,1.0);gl_FragColor=vec4(vec3(result),1.0);}\n#endif\n#ifdef BLUR\nuniform float outSize;uniform float soften;uniform float tolerance;uniform int samples;\n#ifndef BLUR_BYPASS\nuniform sampler2D depthSampler;\n#ifdef BLUR_LEGACY\n#define inline\nfloat blur13Bilateral(sampler2D image,vec2 uv,vec2 step) {float result=0.0;vec2 off1=vec2(1.411764705882353)*step;vec2 off2=vec2(3.2941176470588234)*step;vec2 off3=vec2(5.176470588235294)*step;float compareDepth=abs(textureLod(depthSampler,uv,0.0).r);float sampleDepth;float weight;float weightSum=30.0;result+=textureLod(image,uv,0.0).r*30.0;sampleDepth=abs(textureLod(depthSampler,uv+off1,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+= weight;result+=textureLod(image,uv+off1,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv-off1,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+= weight;result+=textureLod(image,uv-off1,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv+off2,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv+off2,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv-off2,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv-off2,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv+off3,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv+off3,0.0).r*weight;sampleDepth=abs(textureLod(depthSampler,uv-off3,0.0).r);weight=clamp(1.0/( 0.003+abs(compareDepth-sampleDepth)),0.0,30.0);weightSum+=weight;result+=textureLod(image,uv-off3,0.0).r*weight;return result/weightSum;}\n#endif\n#endif\nvoid main()\n{float result=0.0;\n#ifdef BLUR_BYPASS\nresult=textureLod(textureSampler,vUV,0.0).r;\n#else\n#ifdef BLUR_H\nvec2 step=vec2(1.0/outSize,0.0);\n#else\nvec2 step=vec2(0.0,1.0/outSize);\n#endif\n#ifdef BLUR_LEGACY\nresult=blur13Bilateral(textureSampler,vUV,step);\n#else\nfloat compareDepth=abs(textureLod(depthSampler,vUV,0.0).r);float weightSum=0.0;for (int i=-samples; i {\r\n if (!this._forceGeometryBuffer) {\r\n return null;\r\n }\r\n return this._scene.geometryBufferRenderer;\r\n }\r\n private get _prePassRenderer(): Nullable {\r\n if (this._forceGeometryBuffer) {\r\n return null;\r\n }\r\n return this._scene.prePassRenderer;\r\n }\r\n\r\n /**\r\n * Ratio object used for SSAO ratio and blur ratio\r\n */\r\n @serialize()\r\n private _ratio: any;\r\n\r\n /*\r\n * The texture type used by the different post processes created by SSAO\r\n */\r\n @serialize()\r\n private _textureType: number;\r\n\r\n /**\r\n * Dynamically generated sphere sampler.\r\n */\r\n private _sampleSphere: number[];\r\n\r\n /**\r\n * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0\r\n */\r\n @serialize()\r\n public radius: number = 2.0;\r\n\r\n /**\r\n * The base color of the SSAO post-process\r\n * The final result is \"base + ssao\" between [0, 1]\r\n */\r\n @serialize()\r\n public base: number = 0;\r\n\r\n @serialize(\"bypassBlur\")\r\n private _bypassBlur: boolean = false;\r\n /**\r\n * Skips the denoising (blur) stage of the SSAO calculations.\r\n *\r\n * Useful to temporarily set while experimenting with the other SSAO2 settings.\r\n */\r\n public set bypassBlur(b: boolean) {\r\n const defines = this._getDefinesForBlur(this.expensiveBlur, b);\r\n const samplers = this._getSamplersForBlur(b);\r\n this._blurHPostProcess.updateEffect(defines.h, null, samplers);\r\n this._blurVPostProcess.updateEffect(defines.v, null, samplers);\r\n this._bypassBlur = b;\r\n }\r\n public get bypassBlur(): boolean {\r\n return this._bypassBlur;\r\n }\r\n\r\n @serialize(\"expensiveBlur\")\r\n private _expensiveBlur: boolean = true;\r\n /**\r\n * Enables the configurable bilateral denoising (blurring) filter. Default is true.\r\n * Set to false to instead use a legacy bilateral filter that can't be configured.\r\n *\r\n * The denoising filter runs after the SSAO calculations and is a very important step. Both options results in a so called bilateral being used, but the \"expensive\" one can be\r\n * configured in several ways to fit your scene.\r\n */\r\n public set expensiveBlur(b: boolean) {\r\n const defines = this._getDefinesForBlur(b, this._bypassBlur);\r\n this._blurHPostProcess.updateEffect(defines.h);\r\n this._blurVPostProcess.updateEffect(defines.v);\r\n this._expensiveBlur = b;\r\n }\r\n public get expensiveBlur(): boolean {\r\n return this._expensiveBlur;\r\n }\r\n\r\n /**\r\n * The number of samples the bilateral filter uses in both dimensions when denoising the SSAO calculations. Default value is 16.\r\n *\r\n * A higher value should result in smoother shadows but will use more processing time in the shaders.\r\n *\r\n * A high value can cause the shadows to get to blurry or create visible artifacts (bands) near sharp details in the geometry. The artifacts can sometimes be mitigated by increasing the bilateralSoften setting.\r\n */\r\n @serialize()\r\n public bilateralSamples: number = 16;\r\n\r\n /**\r\n * Controls the shape of the denoising kernel used by the bilateral filter. Default value is 0.\r\n *\r\n * By default the bilateral filter acts like a box-filter, treating all samples on the same depth with equal weights. This is effective to maximize the denoising effect given a limited set of samples. However, it also often results in visible ghosting around sharp shadow regions and can spread out lines over large areas so they are no longer visible.\r\n *\r\n * Increasing this setting will make the filter pay less attention to samples further away from the center sample, reducing many artifacts but at the same time increasing noise.\r\n *\r\n * Useful value range is [0..1].\r\n */\r\n @serialize()\r\n public bilateralSoften: number = 0;\r\n\r\n /**\r\n * How forgiving the bilateral denoiser should be when rejecting samples. Default value is 0.\r\n *\r\n * A higher value results in the bilateral filter being more forgiving and thus doing a better job at denoising slanted and curved surfaces, but can lead to shadows spreading out around corners or between objects that are close to each other depth wise.\r\n *\r\n * Useful value range is normally [0..1], but higher values are allowed.\r\n */\r\n @serialize()\r\n public bilateralTolerance: number = 0;\r\n\r\n /**\r\n * Support test.\r\n */\r\n public static get IsSupported(): boolean {\r\n const engine = EngineStore.LastCreatedEngine;\r\n if (!engine) {\r\n return false;\r\n }\r\n return engine._features.supportSSAO2;\r\n }\r\n\r\n private _scene: Scene;\r\n private _randomTexture: DynamicTexture;\r\n private _originalColorPostProcess: PassPostProcess;\r\n private _ssaoPostProcess: PostProcess;\r\n private _blurHPostProcess: PostProcess;\r\n private _blurVPostProcess: PostProcess;\r\n private _ssaoCombinePostProcess: PostProcess;\r\n\r\n /**\r\n * Gets active scene\r\n */\r\n public get scene(): Scene {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * @constructor\r\n * @param name The rendering pipeline name\r\n * @param scene The scene linked to this pipeline\r\n * @param ratio The size of the postprocesses. Can be a number shared between passes or an object for more precision: { ssaoRatio: 0.5, blurRatio: 1.0 }\r\n * @param cameras The array of cameras that the rendering pipeline will be attached to\r\n * @param forceGeometryBuffer Set to true if you want to use the legacy geometry buffer renderer\r\n * @param textureType The texture type used by the different post processes created by SSAO (default: Constants.TEXTURETYPE_UNSIGNED_INT)\r\n */\r\n constructor(name: string, scene: Scene, ratio: any, cameras?: Camera[], forceGeometryBuffer = false, textureType = Constants.TEXTURETYPE_UNSIGNED_INT) {\r\n super(scene.getEngine(), name);\r\n\r\n this._scene = scene;\r\n this._ratio = ratio;\r\n this._textureType = textureType;\r\n this._forceGeometryBuffer = forceGeometryBuffer;\r\n\r\n if (!this.isSupported) {\r\n Logger.Error(\"The current engine does not support SSAO 2.\");\r\n return;\r\n }\r\n\r\n const ssaoRatio = this._ratio.ssaoRatio || ratio;\r\n const blurRatio = this._ratio.blurRatio || ratio;\r\n\r\n // Set up assets\r\n if (this._forceGeometryBuffer) {\r\n scene.enableGeometryBufferRenderer();\r\n } else {\r\n scene.enablePrePassRenderer();\r\n }\r\n\r\n this._createRandomTexture();\r\n\r\n this._originalColorPostProcess = new PassPostProcess(\"SSAOOriginalSceneColor\", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), undefined, this._textureType);\r\n this._originalColorPostProcess.samples = this.textureSamples;\r\n this._createSSAOPostProcess(1.0, textureType);\r\n this._createBlurPostProcess(ssaoRatio, blurRatio, this._textureType);\r\n this._createSSAOCombinePostProcess(blurRatio, this._textureType);\r\n\r\n // Set up pipeline\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.SSAOOriginalSceneColorEffect,\r\n () => {\r\n return this._originalColorPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.SSAORenderEffect,\r\n () => {\r\n return this._ssaoPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.SSAOBlurHRenderEffect,\r\n () => {\r\n return this._blurHPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.SSAOBlurVRenderEffect,\r\n () => {\r\n return this._blurVPostProcess;\r\n },\r\n true\r\n )\r\n );\r\n this.addEffect(\r\n new PostProcessRenderEffect(\r\n scene.getEngine(),\r\n this.SSAOCombineRenderEffect,\r\n () => {\r\n return this._ssaoCombinePostProcess;\r\n },\r\n true\r\n )\r\n );\r\n\r\n // Finish\r\n scene.postProcessRenderPipelineManager.addPipeline(this);\r\n if (cameras) {\r\n scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(name, cameras);\r\n }\r\n }\r\n\r\n // Public Methods\r\n\r\n /**\r\n * Get the class name\r\n * @returns \"SSAO2RenderingPipeline\"\r\n */\r\n public getClassName(): string {\r\n return \"SSAO2RenderingPipeline\";\r\n }\r\n\r\n /**\r\n * Removes the internal pipeline assets and detaches the pipeline from the scene cameras\r\n * @param disableGeometryBufferRenderer\r\n */\r\n public dispose(disableGeometryBufferRenderer: boolean = false): void {\r\n for (let i = 0; i < this._scene.cameras.length; i++) {\r\n const camera = this._scene.cameras[i];\r\n\r\n this._originalColorPostProcess.dispose(camera);\r\n this._ssaoPostProcess.dispose(camera);\r\n this._blurHPostProcess.dispose(camera);\r\n this._blurVPostProcess.dispose(camera);\r\n this._ssaoCombinePostProcess.dispose(camera);\r\n }\r\n\r\n this._randomTexture.dispose();\r\n\r\n if (disableGeometryBufferRenderer) {\r\n this._scene.disableGeometryBufferRenderer();\r\n }\r\n\r\n this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);\r\n\r\n super.dispose();\r\n }\r\n\r\n // Private Methods\r\n\r\n /** @internal */\r\n public _rebuild() {\r\n super._rebuild();\r\n }\r\n\r\n private _getSamplersForBlur(disabled: boolean): Array {\r\n return disabled ? [\"textureSampler\"] : [\"textureSampler\", \"depthSampler\"];\r\n }\r\n\r\n private _getDefinesForBlur(bilateral: boolean, disabled: boolean): { h: string; v: string } {\r\n let define = \"#define BLUR\\n\";\r\n if (disabled) {\r\n define += \"#define BLUR_BYPASS\\n\";\r\n }\r\n if (!bilateral) {\r\n define += \"#define BLUR_LEGACY\\n\";\r\n }\r\n return { h: define + \"#define BLUR_H\\n\", v: define };\r\n }\r\n\r\n private _createBlurPostProcess(ssaoRatio: number, blurRatio: number, textureType: number): void {\r\n const defines = this._getDefinesForBlur(this.expensiveBlur, this.bypassBlur);\r\n const samplers = this._getSamplersForBlur(this.bypassBlur);\r\n\r\n this._blurHPostProcess = this._createBlurFilter(\"BlurH\", samplers, ssaoRatio, defines.h, textureType, true);\r\n this._blurVPostProcess = this._createBlurFilter(\"BlurV\", samplers, blurRatio, defines.v, textureType, false);\r\n }\r\n\r\n private _createBlurFilter(name: string, samplers: Array, ratio: number, defines: string, textureType: number, horizontal: boolean): PostProcess {\r\n const blurFilter = new PostProcess(\r\n name,\r\n \"ssao2\",\r\n [\"outSize\", \"samples\", \"soften\", \"tolerance\"],\r\n samplers,\r\n ratio,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n this._scene.getEngine(),\r\n false,\r\n defines,\r\n textureType\r\n );\r\n\r\n blurFilter.onApply = (effect: Effect) => {\r\n if (!this._scene.activeCamera) {\r\n return;\r\n }\r\n\r\n const ssaoCombineSize = horizontal ? this._ssaoCombinePostProcess.width : this._ssaoCombinePostProcess.height;\r\n const originalColorSize = horizontal ? this._originalColorPostProcess.width : this._originalColorPostProcess.height;\r\n\r\n effect.setFloat(\"outSize\", ssaoCombineSize > 0 ? ssaoCombineSize : originalColorSize);\r\n effect.setInt(\"samples\", this.bilateralSamples);\r\n effect.setFloat(\"soften\", this.bilateralSoften);\r\n effect.setFloat(\"tolerance\", this.bilateralTolerance);\r\n if (this._geometryBufferRenderer) {\r\n effect.setTexture(\"depthSampler\", this._geometryBufferRenderer.getGBuffer().textures[0]);\r\n } else if (this._prePassRenderer) {\r\n effect.setTexture(\"depthSampler\", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(Constants.PREPASS_DEPTH_TEXTURE_TYPE)]);\r\n }\r\n };\r\n\r\n blurFilter.samples = this.textureSamples;\r\n return blurFilter;\r\n }\r\n\r\n private _bits = new Uint32Array(1);\r\n\r\n //Van der Corput radical inverse\r\n private _radicalInverse_VdC(i: number) {\r\n this._bits[0] = i;\r\n this._bits[0] = ((this._bits[0] << 16) | (this._bits[0] >> 16)) >>> 0;\r\n this._bits[0] = ((this._bits[0] & 0x55555555) << 1) | (((this._bits[0] & 0xaaaaaaaa) >>> 1) >>> 0);\r\n this._bits[0] = ((this._bits[0] & 0x33333333) << 2) | (((this._bits[0] & 0xcccccccc) >>> 2) >>> 0);\r\n this._bits[0] = ((this._bits[0] & 0x0f0f0f0f) << 4) | (((this._bits[0] & 0xf0f0f0f0) >>> 4) >>> 0);\r\n this._bits[0] = ((this._bits[0] & 0x00ff00ff) << 8) | (((this._bits[0] & 0xff00ff00) >>> 8) >>> 0);\r\n return this._bits[0] * 2.3283064365386963e-10; // / 0x100000000 or / 4294967296\r\n }\r\n\r\n private _hammersley(i: number, n: number) {\r\n return [i / n, this._radicalInverse_VdC(i)];\r\n }\r\n\r\n private _hemisphereSample_uniform(u: number, v: number): Vector3 {\r\n const phi = v * 2.0 * Math.PI;\r\n // rejecting samples that are close to tangent plane to avoid z-fighting artifacts\r\n const cosTheta = 1.0 - u * 0.85;\r\n const sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);\r\n return new Vector3(Math.cos(phi) * sinTheta, Math.sin(phi) * sinTheta, cosTheta);\r\n }\r\n\r\n private _generateHemisphere(): number[] {\r\n const numSamples = this.samples;\r\n const result = [];\r\n let vector;\r\n\r\n let i = 0;\r\n while (i < numSamples) {\r\n if (numSamples < 16) {\r\n vector = this._hemisphereSample_uniform(Math.random(), Math.random());\r\n } else {\r\n const rand = this._hammersley(i, numSamples);\r\n vector = this._hemisphereSample_uniform(rand[0], rand[1]);\r\n }\r\n\r\n result.push(vector.x, vector.y, vector.z);\r\n i++;\r\n }\r\n\r\n return result;\r\n }\r\n\r\n private _getDefinesForSSAO() {\r\n const defines = `#define SSAO\\n#define SAMPLES ${this.samples}\\n#define EPSILON ${this.epsilon.toFixed(4)}`;\r\n\r\n return defines;\r\n }\r\n\r\n private static readonly ORTHO_DEPTH_PROJECTION = [1, 0, 0, 0, 1, 0, 0, 0, 1];\r\n\r\n private static readonly PERSPECTIVE_DEPTH_PROJECTION = [0, 0, 0, 0, 0, 0, 1, 1, 1];\r\n\r\n private _createSSAOPostProcess(ratio: number, textureType: number): void {\r\n this._sampleSphere = this._generateHemisphere();\r\n\r\n const defines = this._getDefinesForSSAO();\r\n const samplers = [\"randomSampler\", \"depthSampler\", \"normalSampler\"];\r\n\r\n this._ssaoPostProcess = new PostProcess(\r\n \"ssao2\",\r\n \"ssao2\",\r\n [\r\n \"sampleSphere\",\r\n \"samplesFactor\",\r\n \"randTextureTiles\",\r\n \"totalStrength\",\r\n \"radius\",\r\n \"base\",\r\n \"range\",\r\n \"projection\",\r\n \"near\",\r\n \"texelSize\",\r\n \"xViewport\",\r\n \"yViewport\",\r\n \"maxZ\",\r\n \"minZAspect\",\r\n \"depthProjection\",\r\n ],\r\n samplers,\r\n ratio,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n this._scene.getEngine(),\r\n false,\r\n defines,\r\n textureType\r\n );\r\n\r\n this._ssaoPostProcess.onApply = (effect: Effect) => {\r\n if (!this._scene.activeCamera) {\r\n return;\r\n }\r\n\r\n effect.setArray3(\"sampleSphere\", this._sampleSphere);\r\n effect.setFloat(\"randTextureTiles\", 32.0);\r\n effect.setFloat(\"samplesFactor\", 1 / this.samples);\r\n effect.setFloat(\"totalStrength\", this.totalStrength);\r\n effect.setFloat2(\"texelSize\", 1 / this._ssaoPostProcess.width, 1 / this._ssaoPostProcess.height);\r\n effect.setFloat(\"radius\", this.radius);\r\n effect.setFloat(\"maxZ\", this.maxZ);\r\n effect.setFloat(\"minZAspect\", this.minZAspect);\r\n effect.setFloat(\"base\", this.base);\r\n effect.setFloat(\"near\", this._scene.activeCamera.minZ);\r\n if (this._scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA) {\r\n effect.setMatrix3x3(\"depthProjection\", SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION);\r\n effect.setFloat(\"xViewport\", Math.tan(this._scene.activeCamera.fov / 2) * this._scene.getEngine().getAspectRatio(this._scene.activeCamera, true));\r\n effect.setFloat(\"yViewport\", Math.tan(this._scene.activeCamera.fov / 2));\r\n } else {\r\n const halfWidth = this._scene.getEngine().getRenderWidth() / 2.0;\r\n const halfHeight = this._scene.getEngine().getRenderHeight() / 2.0;\r\n const orthoLeft = this._scene.activeCamera.orthoLeft ?? -halfWidth;\r\n const orthoRight = this._scene.activeCamera.orthoRight ?? halfWidth;\r\n const orthoBottom = this._scene.activeCamera.orthoBottom ?? -halfHeight;\r\n const orthoTop = this._scene.activeCamera.orthoTop ?? halfHeight;\r\n effect.setMatrix3x3(\"depthProjection\", SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION);\r\n effect.setFloat(\"xViewport\", (orthoRight - orthoLeft) * 0.5);\r\n effect.setFloat(\"yViewport\", (orthoTop - orthoBottom) * 0.5);\r\n }\r\n effect.setMatrix(\"projection\", this._scene.getProjectionMatrix());\r\n\r\n if (this._geometryBufferRenderer) {\r\n effect.setTexture(\"depthSampler\", this._geometryBufferRenderer.getGBuffer().textures[0]);\r\n effect.setTexture(\"normalSampler\", this._geometryBufferRenderer.getGBuffer().textures[1]);\r\n } else if (this._prePassRenderer) {\r\n effect.setTexture(\"depthSampler\", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(Constants.PREPASS_DEPTH_TEXTURE_TYPE)]);\r\n effect.setTexture(\"normalSampler\", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(Constants.PREPASS_NORMAL_TEXTURE_TYPE)]);\r\n }\r\n effect.setTexture(\"randomSampler\", this._randomTexture);\r\n };\r\n this._ssaoPostProcess.samples = this.textureSamples;\r\n\r\n if (!this._forceGeometryBuffer) {\r\n this._ssaoPostProcess._prePassEffectConfiguration = new SSAO2Configuration();\r\n }\r\n }\r\n\r\n private _createSSAOCombinePostProcess(ratio: number, textureType: number): void {\r\n this._ssaoCombinePostProcess = new PostProcess(\r\n \"ssaoCombine\",\r\n \"ssaoCombine\",\r\n [],\r\n [\"originalColor\", \"viewport\"],\r\n ratio,\r\n null,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n this._scene.getEngine(),\r\n false,\r\n undefined,\r\n textureType\r\n );\r\n\r\n this._ssaoCombinePostProcess.onApply = (effect: Effect) => {\r\n const viewport = this._scene.activeCamera!.viewport;\r\n effect.setVector4(\"viewport\", TmpVectors.Vector4[0].copyFromFloats(viewport.x, viewport.y, viewport.width, viewport.height));\r\n effect.setTextureFromPostProcessOutput(\"originalColor\", this._originalColorPostProcess);\r\n };\r\n this._ssaoCombinePostProcess.samples = this.textureSamples;\r\n }\r\n\r\n private _createRandomTexture(): void {\r\n const size = 128;\r\n\r\n this._randomTexture = new DynamicTexture(\"SSAORandomTexture\", size, this._scene, false, Texture.BILINEAR_SAMPLINGMODE);\r\n this._randomTexture.wrapU = Texture.WRAP_ADDRESSMODE;\r\n this._randomTexture.wrapV = Texture.WRAP_ADDRESSMODE;\r\n\r\n const context = this._randomTexture.getContext();\r\n\r\n const rand = (min: number, max: number) => {\r\n return Math.random() * (max - min) + min;\r\n };\r\n\r\n const randVector = Vector3.Zero();\r\n\r\n for (let x = 0; x < size; x++) {\r\n for (let y = 0; y < size; y++) {\r\n randVector.x = rand(0.0, 1.0);\r\n randVector.y = rand(0.0, 1.0);\r\n randVector.z = 0.0;\r\n\r\n randVector.normalize();\r\n\r\n randVector.scaleInPlace(255);\r\n randVector.x = Math.floor(randVector.x);\r\n randVector.y = Math.floor(randVector.y);\r\n\r\n context.fillStyle = \"rgb(\" + randVector.x + \", \" + randVector.y + \", \" + randVector.z + \")\";\r\n context.fillRect(x, y, 1, 1);\r\n }\r\n }\r\n\r\n this._randomTexture.update(false);\r\n }\r\n\r\n /**\r\n * Serialize the rendering pipeline (Used when exporting)\r\n * @returns the serialized object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n serializationObject.customType = \"SSAO2RenderingPipeline\";\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse the serialized pipeline\r\n * @param source Source pipeline.\r\n * @param scene The scene to load the pipeline to.\r\n * @param rootUrl The URL of the serialized pipeline.\r\n * @returns An instantiated pipeline from the serialized object.\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): SSAO2RenderingPipeline {\r\n return SerializationHelper.Parse(\r\n () => new SSAO2RenderingPipeline(source._name, scene, source._ratio, undefined, source._forceGeometryBuffer, source._textureType),\r\n source,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.SSAO2RenderingPipeline\", SSAO2RenderingPipeline);\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"fxaaPixelShader\";\nconst shader = `#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)\n#else\n#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)\n#endif\nuniform sampler2D textureSampler;uniform vec2 texelSize;varying vec2 vUV;varying vec2 sampleCoordS;varying vec2 sampleCoordE;varying vec2 sampleCoordN;varying vec2 sampleCoordW;varying vec2 sampleCoordNW;varying vec2 sampleCoordSE;varying vec2 sampleCoordNE;varying vec2 sampleCoordSW;const float fxaaQualitySubpix=1.0;const float fxaaQualityEdgeThreshold=0.166;const float fxaaQualityEdgeThresholdMin=0.0833;const vec3 kLumaCoefficients=vec3(0.2126,0.7152,0.0722);\n#define FxaaLuma(rgba) dot(rgba.rgb,kLumaCoefficients)\nvoid main(){vec2 posM;posM.x=vUV.x;posM.y=vUV.y;vec4 rgbyM=TEXTUREFUNC(textureSampler,vUV,0.0);float lumaM=FxaaLuma(rgbyM);float lumaS=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordS,0.0));float lumaE=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordE,0.0));float lumaN=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordN,0.0));float lumaW=FxaaLuma(TEXTUREFUNC(textureSampler,sampleCoordW,0.0));float maxSM=max(lumaS,lumaM);float minSM=min(lumaS,lumaM);float maxESM=max(lumaE,maxSM);float minESM=min(lumaE,minSM);float maxWN=max(lumaN,lumaW);float minWN=min(lumaN,lumaW);float rangeMax=max(maxWN,maxESM);float rangeMin=min(minWN,minESM);float rangeMaxScaled=rangeMax*fxaaQualityEdgeThreshold;float range=rangeMax-rangeMin;float rangeMaxClamped=max(fxaaQualityEdgeThresholdMin,rangeMaxScaled);\n#ifndef MALI\nif(range=edgeVert;float subpixA=subpixNSWE*2.0+subpixNWSWNESE;if (!horzSpan)\n{lumaN=lumaW;}\nif (!horzSpan) \n{lumaS=lumaE;}\nif (horzSpan) \n{lengthSign=texelSize.y;}\nfloat subpixB=(subpixA*(1.0/12.0))-lumaM;float gradientN=lumaN-lumaM;float gradientS=lumaS-lumaM;float lumaNN=lumaN+lumaM;float lumaSS=lumaS+lumaM;bool pairN=abs(gradientN)>=abs(gradientS);float gradient=max(abs(gradientN),abs(gradientS));if (pairN)\n{lengthSign=-lengthSign;}\nfloat subpixC=clamp(abs(subpixB)*subpixRcpRange,0.0,1.0);vec2 posB;posB.x=posM.x;posB.y=posM.y;vec2 offNP;offNP.x=(!horzSpan) ? 0.0 : texelSize.x;offNP.y=(horzSpan) ? 0.0 : texelSize.y;if (!horzSpan) \n{posB.x+=lengthSign*0.5;}\nif (horzSpan)\n{posB.y+=lengthSign*0.5;}\nvec2 posN;posN.x=posB.x-offNP.x*1.5;posN.y=posB.y-offNP.y*1.5;vec2 posP;posP.x=posB.x+offNP.x*1.5;posP.y=posB.y+offNP.y*1.5;float subpixD=((-2.0)*subpixC)+3.0;float lumaEndN=FxaaLuma(TEXTUREFUNC(textureSampler,posN,0.0));float subpixE=subpixC*subpixC;float lumaEndP=FxaaLuma(TEXTUREFUNC(textureSampler,posP,0.0));if (!pairN) \n{lumaNN=lumaSS;}\nfloat gradientScaled=gradient*1.0/4.0;float lumaMM=lumaM-lumaNN*0.5;float subpixF=subpixD*subpixE;bool lumaMLTZero=lumaMM<0.0;lumaEndN-=lumaNN*0.5;lumaEndP-=lumaNN*0.5;bool doneN=abs(lumaEndN)>=gradientScaled;bool doneP=abs(lumaEndP)>=gradientScaled;if (!doneN) \n{posN.x-=offNP.x*3.0;}\nif (!doneN) \n{posN.y-=offNP.y*3.0;}\nbool doneNP=(!doneN) || (!doneP);if (!doneP) \n{posP.x+=offNP.x*3.0;}\nif (!doneP)\n{posP.y+=offNP.y*3.0;}\nif (doneNP)\n{if (!doneN) lumaEndN=FxaaLuma(TEXTUREFUNC(textureSampler,posN.xy,0.0));if (!doneP) lumaEndP=FxaaLuma(TEXTUREFUNC(textureSampler,posP.xy,0.0));if (!doneN) lumaEndN=lumaEndN-lumaNN*0.5;if (!doneP) lumaEndP=lumaEndP-lumaNN*0.5;doneN=abs(lumaEndN)>=gradientScaled;doneP=abs(lumaEndP)>=gradientScaled;if (!doneN) posN.x-=offNP.x*12.0;if (!doneN) posN.y-=offNP.y*12.0;doneNP=(!doneN) || (!doneP);if (!doneP) posP.x+=offNP.x*12.0;if (!doneP) posP.y+=offNP.y*12.0;}\nfloat dstN=posM.x-posN.x;float dstP=posP.x-posM.x;if (!horzSpan)\n{dstN=posM.y-posN.y;}\nif (!horzSpan) \n{dstP=posP.y-posM.y;}\nbool goodSpanN=(lumaEndN<0.0) != lumaMLTZero;float spanLength=(dstP+dstN);bool goodSpanP=(lumaEndP<0.0) != lumaMLTZero;float spanLengthRcp=1.0/spanLength;bool directionN=dstN = null,\r\n samplingMode?: number,\r\n engine?: Engine,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT\r\n ) {\r\n super(name, \"fxaa\", [\"texelSize\"], null, options, camera, samplingMode || Texture.BILINEAR_SAMPLINGMODE, engine, reusable, null, textureType, \"fxaa\", undefined, true);\r\n\r\n const defines = this._getDefines();\r\n this.updateEffect(defines);\r\n\r\n this.onApplyObservable.add((effect: Effect) => {\r\n const texelSize = this.texelSize;\r\n effect.setFloat2(\"texelSize\", texelSize.x, texelSize.y);\r\n });\r\n }\r\n\r\n private _getDefines(): Nullable {\r\n const engine = this.getEngine();\r\n if (!engine) {\r\n return null;\r\n }\r\n\r\n const glInfo = engine.getGlInfo();\r\n if (glInfo && glInfo.renderer && glInfo.renderer.toLowerCase().indexOf(\"mali\") > -1) {\r\n return \"#define MALI 1\\n\";\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {\r\n return SerializationHelper.Parse(\r\n () => {\r\n return new FxaaPostProcess(\r\n parsedPostProcess.name,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n scene.getEngine(),\r\n parsedPostProcess.reusable\r\n );\r\n },\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.FxaaPostProcess\", FxaaPostProcess);\r\n","import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { BaseTexture } from '@babylonjs/core/Materials/Textures/baseTexture';\r\nimport { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';\r\nimport { HDRCubeTexture } from '@babylonjs/core/Materials/Textures/hdrCubeTexture';\r\nimport { Texture } from '@babylonjs/core/Materials/Textures/texture';\r\nimport { Color4, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { LensRenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline';\r\nimport { SSAO2RenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline';\r\nimport { FxaaPostProcess } from '@babylonjs/core/PostProcesses/fxaaPostProcess';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { eBackground, eTextureSamplingMode } from '@models/classes/enums';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { SceneNode, isSceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { GuiHelper } from '@view/helpers/gui-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Renderer } from './renderer';\r\nimport { RendererManager } from './renderer-manager';\r\n\r\nexport const SKYBOX_SIZE = 1000;\r\n\r\nexport const SamplingModeMap = {\r\n [eTextureSamplingMode.nearest]: Texture.NEAREST_SAMPLINGMODE,\r\n [eTextureSamplingMode.bilinear]: Texture.BILINEAR_SAMPLINGMODE,\r\n [eTextureSamplingMode.trilinear]: Texture.TRILINEAR_SAMPLINGMODE,\r\n};\r\n\r\nexport class SceneRenderer extends Renderer {\r\n private ssaoPostProcess: SSAO2RenderingPipeline;\r\n private lensEffectPostProcess: LensRenderingPipeline;\r\n private fxaaPostProcess: FxaaPostProcess;\r\n private yVector = new Vector3(0, 1, 0);\r\n\r\n constructor(viewer: KbViewer, scene: Scene, private gui: GuiHelper, private renderManager: RendererManager) {\r\n super(viewer, scene);\r\n }\r\n\r\n modelToken = Token.SceneNode;\r\n handlesNode(node: Kb3dObject) {\r\n return isSceneNode(node) && !node.isNested();\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n this.processEnvironment(node);\r\n\r\n //we create a transform node that ends up holding all space nodes in the scene\r\n //this creates parity with nested scenes and gives us something to transform in WebXR without re-parenting anything\r\n let tnode = this.get3d(node);\r\n if (!tnode) {\r\n tnode = new TransformNode(node._dynamicId, this.scene);\r\n this.set3d(node, tnode);\r\n\r\n if (!this.viewer.options.forceDisablePostProcess && this.scene.activeCamera) {\r\n if (node.enableFxaaPostProcess) {\r\n this.fxaaPostProcess = new FxaaPostProcess(\r\n 'fxaa',\r\n 1.0,\r\n this.scene.activeCamera,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n this.scene.getEngine()\r\n );\r\n }\r\n if (node.enableLensEffectsPostProcess) {\r\n this.lensEffectPostProcess = new LensRenderingPipeline(\r\n 'lens',\r\n {\r\n edge_blur: 0.5,\r\n chromatic_aberration: 0.5,\r\n distortion: 0, // Used to be 0.5 but lens distortion makes mouse selection useless,\r\n dof_focus_distance: 200,\r\n dof_aperture: 5.0, // set this very high for tilt-shift effect\r\n grain_amount: 0.1,\r\n dof_pentagon: true,\r\n dof_gain: 1.0,\r\n dof_threshold: 1.0,\r\n dof_darken: 0,\r\n },\r\n this.scene,\r\n 1.0,\r\n [this.scene.activeCamera]\r\n );\r\n }\r\n if (node.enableSSAOPostProcess) {\r\n this.ssaoPostProcess = new SSAO2RenderingPipeline('ssaopipeline', this.scene, 0.75);\r\n }\r\n }\r\n }\r\n\r\n if (node.changes.has('enableDeferredSceneUpdates')) {\r\n this.renderManager.maxRenderTime =\r\n node.enableDeferredSceneUpdates && !this.viewer.options.editorMode ? 20 : 20000;\r\n }\r\n\r\n if (node.changes.has('textureSamplingMode')) {\r\n const samplingMode = SamplingModeMap[node.textureSamplingMode];\r\n const materials = this.renderManager.material.getAllDefinedMaterials();\r\n\r\n materials.forEach(material => {\r\n material.getActiveTextures().forEach(texture => {\r\n if (texture) {\r\n texture.updateSamplingMode(samplingMode);\r\n }\r\n });\r\n });\r\n }\r\n\r\n if (node.changes.has('backgroundColor') || node.changes.has('background')) {\r\n if (node.background == eBackground.color) {\r\n this.scene.clearColor = node.backgroundColor.toColor4();\r\n } else {\r\n this.scene.clearColor = new Color4(0, 0, 0, 0);\r\n }\r\n }\r\n if (node.changes.has('ambientColor')) {\r\n this.scene.ambientColor = node.ambientColor.toColor3();\r\n }\r\n if (node.changes.hasAny('renderMode', 'edgeWidth', 'edgeColor', 'edgeDisplayTolerance')) {\r\n this.viewer.setRenderMode(node.renderMode);\r\n }\r\n if (node.changes.has('enableHoverEffects')) {\r\n this.scene.constantlyUpdateMeshUnderPointer = node.enableHoverEffects;\r\n }\r\n if (node.changes.has('connectorSize')) {\r\n for (const c of node.getAllConnectors()) {\r\n this.viewer.rendererManager.connector.updateScale(c);\r\n }\r\n for (const c of node.getAllSketchControlPoints()) {\r\n this.viewer.rendererManager.controlPointRenderer.updateScale(c);\r\n }\r\n }\r\n if (node.changes.hasAny('dimensionUnitScalar', 'dimensionUnitSymbol')) {\r\n node.annotations.forEach(annotationNode => {\r\n if (isTrackedClass(annotationNode)) {\r\n annotationNode.isModified = true;\r\n }\r\n });\r\n }\r\n\r\n let gridNeedsRebuild = false;\r\n if (\r\n node.changes.hasAny(\r\n '_forceGrid',\r\n 'gridSize',\r\n 'gridNormal',\r\n 'gridStepSize',\r\n 'gridMajorInterval',\r\n 'backgroundColor'\r\n )\r\n ) {\r\n if (node._forceGrid || node.enableGrid) {\r\n this.gui.disableGrid();\r\n gridNeedsRebuild = true;\r\n }\r\n if (node._forceGrid || node.enableGridAxes) {\r\n this.gui.disableGridAxes();\r\n gridNeedsRebuild = true;\r\n }\r\n }\r\n if (gridNeedsRebuild || node.changes.has('enableGrid')) {\r\n if (node._forceGrid || node.enableGrid) {\r\n this.gui.enableGrid(node, node._forceGrid || node.enableGridAxes);\r\n } else {\r\n this.gui.disableGrid();\r\n }\r\n }\r\n if (gridNeedsRebuild || node.changes.has('enableGridAxes')) {\r\n if (node._forceGrid || node.enableGridAxes) {\r\n this.gui.enableGridAxes(node);\r\n } else {\r\n this.gui.disableGridAxes();\r\n }\r\n }\r\n\r\n if (node._rootScene?._dynamicId === node._dynamicId) {\r\n const eventPayload = Object.fromEntries(node.changes);\r\n if (this.viewer.canvas) {\r\n this.viewer.canvas.dispatchEvent(\r\n new CustomEvent('kb3d.scenePropertyChange', { detail: eventPayload, bubbles: true })\r\n );\r\n }\r\n }\r\n }\r\n\r\n private _envTexture: BaseTexture;\r\n private _envTexturePath: string;\r\n public skybox: Mesh | null;\r\n\r\n processEnvironment(node: ITrackedClass) {\r\n if (node.changes.has('environment') || node.changes.has('background') || node.changes.has('environmentBlur')) {\r\n const matService = node._manager?.getService(Token.MaterialService);\r\n if (!matService) {\r\n throw Error('Cannot fetch environment material');\r\n }\r\n\r\n let path: string;\r\n if (node.background === eBackground.environment) {\r\n if (node.environmentBlur < 0.15) {\r\n path = matService.getAbsoluteEnvironmentPath(node.environment, 3);\r\n } else {\r\n path = matService.getAbsoluteEnvironmentPath(node.environment, 1);\r\n }\r\n } else {\r\n path = matService.getAbsoluteEnvironmentPath(node.environment, 0);\r\n }\r\n\r\n if (path !== '' && this._envTexturePath !== path) {\r\n this._envTexturePath = path;\r\n if (this._envTexture) {\r\n this._envTexture.dispose();\r\n }\r\n\r\n let texture: BaseTexture | undefined = undefined;\r\n\r\n if (path.match(/\\.dds(\\?.*)?$/) || path.match(/\\.env(\\?.*)?$/)) {\r\n texture = CubeTexture.CreateFromPrefilteredData(path, this.scene);\r\n } else if (path.match(/\\.hdr(\\?.*)?$/)) {\r\n texture = new HDRCubeTexture(path, this.scene, 128);\r\n }\r\n\r\n if (texture != null) {\r\n texture.gammaSpace = false;\r\n this.scene.environmentTexture = texture;\r\n this._envTexture = texture;\r\n } else {\r\n this.scene.environmentTexture = null;\r\n }\r\n }\r\n }\r\n\r\n if (\r\n (node.changes.has('background') || node.changes.has('environment')) &&\r\n node.background == eBackground.environment &&\r\n this._envTexture\r\n ) {\r\n if (!this.skybox) {\r\n this.skybox = this.scene.createDefaultSkybox(this._envTexture, true, SKYBOX_SIZE, node.environmentBlur);\r\n } else if (node.changes.has('environment')) {\r\n const skyMat = this.skybox.material as PBRMaterial;\r\n skyMat.reflectionTexture = this._envTexture.clone();\r\n skyMat.reflectionTexture!.coordinatesMode = Texture.SKYBOX_MODE;\r\n }\r\n }\r\n\r\n if (node.changes.has('background') && node.background != eBackground.environment) {\r\n if (this.skybox) {\r\n this.skybox.dispose();\r\n this.skybox = null;\r\n }\r\n }\r\n\r\n if (node.changes.has('environmentBlur')) {\r\n if (this.skybox) {\r\n const skyMat = this.skybox.material as PBRMaterial;\r\n skyMat.microSurface = 1.0 - node.environmentBlur;\r\n }\r\n }\r\n\r\n if (node.changes.has('environmentIntensity')) {\r\n this.scene.environmentIntensity = node.environmentIntensity;\r\n }\r\n\r\n if (node.changes.has('environmentRotation') && this.scene.environmentTexture) {\r\n if (\r\n this.scene.environmentTexture instanceof CubeTexture ||\r\n this.scene.environmentTexture instanceof HDRCubeTexture\r\n ) {\r\n this.scene.environmentTexture.rotationY = (node.environmentRotation * Math.PI) / 180;\r\n if (this.skybox) {\r\n this.skybox.rotationQuaternion = Quaternion.RotationAxis(\r\n this.yVector,\r\n (node.environmentRotation * Math.PI) / 180\r\n );\r\n }\r\n }\r\n }\r\n }\r\n\r\n public dispose() {\r\n super.dispose();\r\n if (this._envTexture) {\r\n this._envTexture.dispose();\r\n }\r\n if (this.skybox) {\r\n this.skybox.dispose();\r\n }\r\n if (this.ssaoPostProcess) {\r\n this.ssaoPostProcess.dispose();\r\n }\r\n if (this.lensEffectPostProcess) {\r\n this.lensEffectPostProcess.dispose();\r\n }\r\n if (this.fxaaPostProcess) {\r\n this.fxaaPostProcess.dispose();\r\n }\r\n }\r\n\r\n public getSkyBox() {\r\n return this.skybox;\r\n }\r\n}\r\n","import { BaseTexture } from '@babylonjs/core/Materials/Textures/baseTexture';\r\nimport { Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { MaterialNode } from '@models/classes';\r\nimport {\r\n eTextureBlendMode,\r\n eTextureChannel,\r\n eTextureFit,\r\n eTextureHorizontalAlign,\r\n eTextureVerticalAlign,\r\n} from '@models/classes/enums';\r\nimport { FileTextureLayer } from '@models/classes/materials/file-texture-layer';\r\nimport { TextureLayer } from '@models/classes/materials/texture-layer';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { Renderer } from '../renderer';\r\nimport { TextureParameters } from '../texture-stack';\r\n\r\ninterface ICanvasSize {\r\n width: number;\r\n height: number;\r\n}\r\n\r\nexport interface IDrawOperations {\r\n mask?: { context: CanvasRenderingContext2D };\r\n normalRotate?: { angle: number };\r\n flipNormalsRg?: boolean;\r\n colorize?: { color: KbColor };\r\n}\r\n\r\nconst blendModeMap = {\r\n [eTextureBlendMode.normal]: 'source-over',\r\n [eTextureBlendMode.multiply]: 'multiply',\r\n [eTextureBlendMode.screen]: 'screen',\r\n [eTextureBlendMode.overlay]: 'overlay',\r\n [eTextureBlendMode.darken]: 'darken',\r\n [eTextureBlendMode.lighten]: 'lighten',\r\n [eTextureBlendMode.hue]: 'hue',\r\n [eTextureBlendMode.saturation]: 'saturation',\r\n [eTextureBlendMode.color]: 'color',\r\n [eTextureBlendMode.luminosity]: 'luminosity',\r\n [eTextureBlendMode.difference]: 'difference',\r\n [eTextureBlendMode.mask]: 'destination-in',\r\n [eTextureBlendMode.vector]: 'kb3d-vector', // special blending mode\r\n};\r\n\r\nconst workingCanvases: HTMLCanvasElement[] = [];\r\n/** Make sure to dispose the canvas after use! Otherwise you'll get a memory leak! */\r\nfunction getWorkingCanvas(width: number, height: number) {\r\n let canvas: HTMLCanvasElement | undefined;\r\n for (let i = 0; i < workingCanvases.length; i++) {\r\n if (workingCanvases[i].width === 1) {\r\n canvas = workingCanvases[i];\r\n break;\r\n }\r\n }\r\n if (!canvas) {\r\n canvas = document.createElement('canvas');\r\n workingCanvases.push(canvas);\r\n }\r\n canvas.width = width;\r\n canvas.height = height;\r\n const context = canvas.getContext('2d', {\r\n willReadFrequently: true,\r\n })!;\r\n context.clearRect(0, 0, canvas.width, canvas.height);\r\n return canvas;\r\n}\r\nfunction disposeWorkingCanvas(canvas: HTMLCanvasElement) {\r\n canvas.width = 1;\r\n canvas.height = 1;\r\n}\r\n\r\nexport abstract class TextureLayerRenderer extends Renderer {\r\n modelToken = Token.TextureLayer;\r\n\r\n paintTexture(\r\n texture: T,\r\n context: CanvasRenderingContext2D,\r\n parameters: TextureParameters,\r\n operations: IDrawOperations\r\n ) {}\r\n\r\n getNativeSize(texture: T): ICanvasSize {\r\n return { width: 1, height: 1 };\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n this.viewer.updateTextureWarnings();\r\n }\r\n\r\n textureHasContent(node: ITrackedClass): boolean {\r\n return false;\r\n }\r\n\r\n protected calculateOffsetAndDimensions(\r\n texture: T,\r\n ctxWidth: number,\r\n ctxHeight: number,\r\n sourceWidth: number,\r\n sourceHeight: number\r\n ) {\r\n let offsetX = texture.uOffset * ctxWidth,\r\n offsetY = texture.vOffset * ctxHeight,\r\n drawHeight = sourceHeight,\r\n drawWidth = sourceWidth;\r\n\r\n switch (texture.verticalFit) {\r\n case eTextureFit.contain:\r\n if (sourceHeight < ctxHeight) {\r\n break;\r\n }\r\n // falls through\r\n case eTextureFit.stretch:\r\n drawHeight = ctxHeight;\r\n }\r\n switch (texture.horizontalFit) {\r\n case eTextureFit.contain:\r\n if (sourceWidth < ctxWidth) {\r\n break;\r\n }\r\n // falls through\r\n case eTextureFit.stretch:\r\n drawWidth = ctxWidth;\r\n }\r\n if (texture.maintainAspect) {\r\n const minRatio = Math.min(drawWidth / sourceWidth, drawHeight / sourceHeight);\r\n drawWidth = minRatio * sourceWidth;\r\n drawHeight = minRatio * sourceHeight;\r\n }\r\n\r\n switch (texture.verticalAlign) {\r\n // left is offset with no adjustment\r\n case eTextureVerticalAlign.bottom:\r\n offsetY += ctxHeight - drawHeight;\r\n break;\r\n case eTextureVerticalAlign.middle:\r\n offsetY += (ctxHeight - drawHeight) / 2;\r\n break;\r\n }\r\n switch (texture.horizontalAlign) {\r\n // top is offset with no adjustment\r\n case eTextureHorizontalAlign.right:\r\n offsetX += ctxWidth - drawWidth;\r\n break;\r\n case eTextureHorizontalAlign.center:\r\n offsetX += (ctxWidth - drawWidth) / 2;\r\n break;\r\n }\r\n\r\n return {\r\n offsetX,\r\n offsetY,\r\n drawHeight,\r\n drawWidth,\r\n };\r\n }\r\n\r\n protected drawInBlendedContext(\r\n texture: T,\r\n context: CanvasRenderingContext2D,\r\n parameters: TextureParameters,\r\n cb: (context: CanvasRenderingContext2D) => void,\r\n operations: IDrawOperations\r\n ) {\r\n if (operations.mask) {\r\n const maskingCtx = operations.mask.context;\r\n delete operations.mask;\r\n // Transfer transform from context to masking context to mask what is drawn\r\n const transform = context.getTransform();\r\n maskingCtx.setTransform(transform);\r\n context.setTransform(1, 0, 0, 1, 0, 0);\r\n\r\n maskingCtx.globalCompositeOperation = 'source-in';\r\n cb(maskingCtx);\r\n maskingCtx.setTransform(1, 0, 0, 1, 0, 0);\r\n\r\n this.drawInBlendedContext(\r\n texture,\r\n context,\r\n parameters,\r\n ctx => {\r\n ctx.drawImage(maskingCtx.canvas, 0, 0, ctx.canvas.width, ctx.canvas.height);\r\n },\r\n operations\r\n );\r\n } else if (Object.keys(operations).length > 0) {\r\n const tempCanvas = getWorkingCanvas(context.canvas.width, context.canvas.height);\r\n const tempContext = tempCanvas.getContext('2d')!;\r\n cb(tempContext);\r\n this.filterImageInPlace(tempCanvas, operations);\r\n\r\n this.drawInBlendedContext(\r\n texture,\r\n context,\r\n parameters,\r\n ctx => {\r\n ctx.drawImage(tempCanvas, 0, 0, ctx.canvas.width, ctx.canvas.height);\r\n disposeWorkingCanvas(tempCanvas);\r\n },\r\n operations\r\n );\r\n } else {\r\n context.globalAlpha = texture.strength / parameters.strength;\r\n switch (texture.blendMode) {\r\n case eTextureBlendMode.vector: {\r\n const tempCanvas = getWorkingCanvas(context.canvas.width, context.canvas.height);\r\n const tempContext = tempCanvas.getContext('2d')!;\r\n cb(tempContext);\r\n const srcData = tempContext.getImageData(0, 0, context.canvas.width, context.canvas.height).data;\r\n const dstImageData = context.getImageData(0, 0, context.canvas.width, context.canvas.height);\r\n const dstData = dstImageData.data;\r\n const v1 = Vector3.Zero();\r\n const v2 = Vector3.Zero();\r\n\r\n const alphaScale = context.globalAlpha / 255;\r\n for (let i = 0, n = srcData.length; i < n; i += 4) {\r\n v1.copyFromFloats(dstData[i] / 128 - 1, dstData[i + 1] / 128 - 1, dstData[i + 2] / 256 - 0.5);\r\n v2.copyFromFloats(srcData[i] / 128 - 1, srcData[i + 1] / 128 - 1, srcData[i + 2] / 256 - 0.5);\r\n v2.scaleInPlace(srcData[i + 3] * alphaScale);\r\n v1.addInPlace(v2);\r\n v1.normalize();\r\n dstData[i] = (v1.x + 1) * 128;\r\n dstData[i + 1] = (v1.y + 1) * 128;\r\n dstData[i + 2] = (v1.z + 1) * 128;\r\n dstData[i + 3] = 255;\r\n }\r\n tempContext.putImageData(dstImageData, 0, 0);\r\n context.drawImage(tempCanvas, 0, 0, context.canvas.width, context.canvas.height);\r\n disposeWorkingCanvas(tempCanvas);\r\n\r\n break;\r\n }\r\n\r\n default: {\r\n (context.globalCompositeOperation as unknown) = blendModeMap[texture.blendMode] || 'source-over';\r\n cb(context);\r\n context.globalCompositeOperation = 'source-over';\r\n }\r\n }\r\n context.globalAlpha = 1;\r\n }\r\n }\r\n\r\n protected filterImageInPlace(buffer: HTMLCanvasElement, operations: IDrawOperations) {\r\n const ctx = buffer.getContext('2d')!;\r\n const width = buffer.width;\r\n const height = buffer.height;\r\n\r\n if (Object.keys(operations).length === 0) {\r\n return buffer;\r\n }\r\n\r\n if (operations.colorize) {\r\n const tempCanvas = getWorkingCanvas(width, height);\r\n const tmpCtx = tempCanvas.getContext('2d')!;\r\n\r\n const color = operations.colorize.color;\r\n delete operations.colorize;\r\n\r\n tmpCtx.globalCompositeOperation = 'source-over';\r\n tmpCtx.fillStyle = `rgb(${color.r * 255}, ${color.g * 255}, ${color.b * 255})`;\r\n tmpCtx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);\r\n\r\n tmpCtx.globalCompositeOperation = 'luminosity';\r\n tmpCtx.drawImage(buffer, 0, 0);\r\n tmpCtx.globalCompositeOperation = 'destination-in';\r\n tmpCtx.drawImage(buffer, 0, 0);\r\n ctx.drawImage(tempCanvas, 0, 0);\r\n disposeWorkingCanvas(tempCanvas);\r\n }\r\n\r\n if (Object.keys(operations).length === 0) {\r\n return buffer;\r\n }\r\n\r\n const imgData = ctx.getImageData(0, 0, width, height);\r\n const data = imgData.data;\r\n\r\n if (operations.normalRotate) {\r\n const rotateAngle = -1 * operations.normalRotate.angle;\r\n delete operations.normalRotate;\r\n const cosA = Math.cos((rotateAngle * Math.PI) / 180);\r\n const sinA = Math.sin((rotateAngle * Math.PI) / 180);\r\n\r\n for (let i = 0, n = data.length; i < n; i += 4) {\r\n const x1 = data[i] / 128 - 1;\r\n const y1 = data[i + 1] / 128 - 1;\r\n const x2 = cosA * x1 - sinA * y1;\r\n const y2 = sinA * x1 + cosA * y1;\r\n data[i] = (x2 + 1) * 128;\r\n data[i + 1] = (y2 + 1) * 128;\r\n }\r\n }\r\n if (operations.flipNormalsRg) {\r\n delete operations.flipNormalsRg;\r\n\r\n for (let i = 0, n = data.length; i < n; i += 4) {\r\n const r = data[i];\r\n data[i] = data[i + 1];\r\n data[i + 1] = r;\r\n }\r\n }\r\n ctx.putImageData(imgData, 0, 0);\r\n\r\n return buffer;\r\n }\r\n\r\n protected drawSourceToCanvas(\r\n texture: T,\r\n source: ImageBitmap | HTMLCanvasElement, // | CanvasImageSource,\r\n context: CanvasRenderingContext2D,\r\n parameters: TextureParameters,\r\n operations: IDrawOperations\r\n ) {\r\n let width = source.width as number,\r\n height = source.height as number;\r\n const ctxWidth = context.canvas.width,\r\n ctxHeight = context.canvas.height;\r\n\r\n if (texture.colorize) {\r\n operations.colorize = { color: texture.colorize };\r\n }\r\n\r\n const firstTextureLayer =\r\n texture._parent?.textures\r\n .filter(t => t.channel === texture.channel && t.enabled)\r\n .findIndex(t => t === texture) === 0;\r\n\r\n if (texture.wAngle && texture.channel === eTextureChannel.normal && !firstTextureLayer) {\r\n operations.normalRotate = { angle: texture.wAngle };\r\n }\r\n if (\r\n texture instanceof FileTextureLayer &&\r\n texture.flipNormalsRg &&\r\n texture.channel === eTextureChannel.normal\r\n ) {\r\n operations.flipNormalsRg = true;\r\n }\r\n\r\n if (!firstTextureLayer) {\r\n const drawAt = this.calculateOffsetAndDimensions(texture, ctxWidth, ctxHeight, width, height);\r\n\r\n const pivotX = texture.uPivot * ctxWidth,\r\n pivotY = texture.vPivot * ctxHeight;\r\n\r\n if (texture.tile) {\r\n let patternCanvas: HTMLCanvasElement | undefined;\r\n let patternAttempt: CanvasPattern | undefined;\r\n // In the case of stretch modes, the draw image size will differ from the native size so we have to redraw it first\r\n // iOS is unable to draw ImageBitmaps to patterns, so we have to try/catch for iOS\r\n if (drawAt.drawWidth === width && drawAt.drawHeight === height) {\r\n try {\r\n patternAttempt = context.createPattern(source, 'repeat')!;\r\n } catch (e) {\r\n // Do nothing, fallback below\r\n }\r\n }\r\n if (!patternAttempt) {\r\n patternCanvas = getWorkingCanvas(drawAt.drawWidth, drawAt.drawHeight);\r\n const patternContext = patternCanvas.getContext('2d')!;\r\n patternContext.drawImage(source, 0, 0, drawAt.drawWidth, drawAt.drawHeight);\r\n\r\n width = drawAt.drawWidth;\r\n height = drawAt.drawHeight;\r\n patternAttempt = context.createPattern(patternCanvas, 'repeat')!;\r\n }\r\n const pattern = patternAttempt;\r\n\r\n // Initial canvas transformations for angle and scaling\r\n context.translate(pivotX, pivotY);\r\n\r\n //if legacy mode enabled\r\n if (\r\n texture._parent &&\r\n texture._parent instanceof MaterialNode &&\r\n texture._parent.legacyTextureStacking === false\r\n ) {\r\n context.scale(texture.uScale, texture.vScale);\r\n context.rotate((texture.wAngle * Math.PI) / 180);\r\n } else {\r\n context.rotate((texture.wAngle * Math.PI) / 180);\r\n context.scale(texture.uScale, texture.vScale);\r\n if ((texture.uScale !== 1 || texture.vScale !== 1) && texture.wAngle !== 0) {\r\n console.warn(\r\n `Texture scale and angle are both altered on the texture layer \"${texture.name}\" with legacy mode enabled on the material \"${texture._parent?.name}\". The order of operations for scale and angle are now reversed on new materials. Please disable legacy mode on this material and adjust the texture stack properties as needed to preserve the desired behavior when legacy mode is deprecated.`\r\n );\r\n }\r\n }\r\n // Remove extra offset since the image will be tiled anyways\r\n drawAt.offsetX = drawAt.offsetX % width;\r\n drawAt.offsetY = drawAt.offsetY % height;\r\n\r\n // Initially set the draw size to cover the canvas\r\n let drawWidth = (ctxWidth - drawAt.offsetX) / texture.uScale;\r\n let drawHeight = (ctxHeight - drawAt.offsetY) / texture.vScale;\r\n\r\n // If the offset is greater than zero there will be a gap on the top or the left so we have to move the context over one tile\r\n if (drawAt.offsetX > 0) {\r\n context.translate(-width, 0);\r\n drawWidth += width;\r\n }\r\n if (drawAt.offsetY > 0) {\r\n context.translate(0, -height);\r\n drawHeight += height;\r\n }\r\n\r\n // add the offset and remove the pivot from earlier that was used to get the correct rotation and scaling matrix parts\r\n context.translate(drawAt.offsetX - pivotX, drawAt.offsetY - pivotY);\r\n\r\n // If the texture was scaled with a pivot, we need to draw the image larger to make sure there are no gaps\r\n if ((texture.uPivot !== 0 || texture.vPivot !== 0) && (texture.uScale !== 1 || texture.vScale !== 1)) {\r\n const scaleOffsetU = Math.abs(Math.ceil(texture.uPivot / texture.uScale)) * width;\r\n const scaleOffsetV = Math.abs(Math.ceil(texture.vPivot / texture.vScale)) * height;\r\n if (scaleOffsetU !== 0 || scaleOffsetV !== 0) {\r\n context.translate(-scaleOffsetU, -scaleOffsetV);\r\n drawWidth += scaleOffsetU * 2;\r\n drawHeight += scaleOffsetV * 2;\r\n }\r\n }\r\n\r\n // If the texture was rotated, we need to draw the image larger to make sure there are no gaps\r\n if (texture.wAngle !== 0) {\r\n const rotateOffsetU = Math.ceil(texture.uPivot / texture.uScale) * width;\r\n const rotateOffsetV = Math.ceil(texture.vPivot / texture.vScale) * height;\r\n if (rotateOffsetU > 0 || rotateOffsetV > 0) {\r\n context.translate(-rotateOffsetU, -rotateOffsetV);\r\n drawWidth += rotateOffsetU * 2;\r\n drawHeight += rotateOffsetV * 2;\r\n }\r\n }\r\n\r\n this.drawInBlendedContext(\r\n texture,\r\n context,\r\n parameters,\r\n innerContext => {\r\n innerContext.fillStyle = pattern;\r\n // Note that any rectangle start point outside of the box will not be rendered so all image transforms must be done on the canvas context\r\n innerContext.fillRect(0, 0, drawWidth, drawHeight);\r\n if (patternCanvas) {\r\n disposeWorkingCanvas(patternCanvas);\r\n }\r\n },\r\n operations\r\n );\r\n } else {\r\n context.translate(pivotX, pivotY);\r\n context.scale(texture.uScale, texture.vScale);\r\n context.rotate((texture.wAngle * Math.PI) / 180);\r\n context.translate(-pivotX, -pivotY);\r\n\r\n this.drawInBlendedContext(\r\n texture,\r\n context,\r\n parameters,\r\n innerContext => {\r\n innerContext.drawImage(\r\n source,\r\n drawAt.offsetX,\r\n drawAt.offsetY,\r\n drawAt.drawWidth,\r\n drawAt.drawHeight\r\n );\r\n },\r\n operations\r\n );\r\n\r\n if (texture._visualize) {\r\n context.strokeStyle = '#00FF00';\r\n context.strokeRect(texture.uOffset * ctxWidth, texture.vOffset * ctxHeight, ctxWidth, ctxHeight);\r\n }\r\n }\r\n\r\n // reset the context\r\n context.setTransform(1, 0, 0, 1, 0, 0);\r\n } else {\r\n // this block will never need to be masked because the layers using a clipping mask will never be the first layer\r\n if (Object.keys(operations).length > 0) {\r\n if (source instanceof HTMLCanvasElement) {\r\n source = this.filterImageInPlace(source, operations);\r\n } else {\r\n const tempCanvas = getWorkingCanvas(width, height);\r\n const tempCtx = tempCanvas.getContext('2d')!;\r\n tempCtx.drawImage(source, 0, 0);\r\n source = this.filterImageInPlace(tempCanvas, operations);\r\n }\r\n }\r\n context.drawImage(source, 0, 0, ctxWidth, ctxHeight);\r\n }\r\n\r\n return context;\r\n }\r\n}\r\n","import { getRotatedDimensions } from '@common-util/texture-util';\r\nimport { ColorFillTextureLayer } from '@models/classes/materials/color-fill-texture-layer';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { TextureParameters } from '../texture-stack';\r\nimport { IDrawOperations, TextureLayerRenderer } from './texture';\r\n\r\nexport class ColorFillTextureLayerRenderer extends TextureLayerRenderer {\r\n modelToken = Token.ColorFillTextureLayer;\r\n\r\n paintTexture(\r\n texture: ColorFillTextureLayer,\r\n context: CanvasRenderingContext2D,\r\n parameters: TextureParameters,\r\n operations: IDrawOperations\r\n ) {\r\n this.drawInBlendedContext(\r\n texture,\r\n context,\r\n parameters,\r\n innerContext => {\r\n innerContext.fillStyle = texture.color.cssString();\r\n innerContext.fillRect(0, 0, innerContext.canvas.width, innerContext.canvas.height);\r\n },\r\n operations\r\n );\r\n }\r\n\r\n textureHasContent() {\r\n return true;\r\n }\r\n\r\n getNativeSize(texture: ColorFillTextureLayer) {\r\n const width = texture.width,\r\n height = texture.height;\r\n\r\n if (texture.wAngle !== 0) {\r\n return getRotatedDimensions(width, height, texture.wAngle);\r\n } else {\r\n return { width, height };\r\n }\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n super.update3dInternal(node);\r\n }\r\n}\r\n","import { getRotatedDimensions } from '@common-util/texture-util';\r\nimport { DisplacementMapFeature } from '@models/classes';\r\nimport { FileTextureLayer } from '@models/classes/materials/file-texture-layer';\r\nimport { MaterialNode } from '@models/classes/materials/material-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { TextureParameters } from '../texture-stack';\r\nimport { IDrawOperations, TextureLayerRenderer } from './texture';\r\n\r\nexport class FileTextureLayerRenderer extends TextureLayerRenderer {\r\n modelToken = Token.FileTextureLayer;\r\n\r\n paintTexture(\r\n texture: FileTextureLayer,\r\n context: CanvasRenderingContext2D,\r\n parameters: TextureParameters,\r\n operations: IDrawOperations\r\n ) {\r\n if (texture._buffer) {\r\n return this.drawSourceToCanvas(texture, texture._buffer, context, parameters, operations);\r\n }\r\n }\r\n\r\n textureHasContent(node: FileTextureLayer) {\r\n return node.path !== '';\r\n }\r\n\r\n getNativeSize(texture: FileTextureLayer) {\r\n if (texture._buffer) {\r\n const width = Math.max(texture._buffer.width, 1),\r\n height = Math.max(texture._buffer.height, 1);\r\n\r\n if (texture.wAngle !== 0) {\r\n return getRotatedDimensions(width, height, texture.wAngle);\r\n } else {\r\n return { width, height };\r\n }\r\n }\r\n return { width: 1, height: 1 };\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n if (\r\n ((node.changes.has('height') || node.changes.has('width')) && node.path.endsWith('.svg')) ||\r\n node.changes.has('path') ||\r\n (node.changes.has('enabled') && !node._buffer) ||\r\n node.changes.has('_init')\r\n ) {\r\n node._needsImageUpdate = true;\r\n }\r\n\r\n if (node._needsImageUpdate && node.enabled && node.path && node._init) {\r\n this.loadTextureBuffer(node);\r\n }\r\n super.update3dInternal(node);\r\n }\r\n\r\n private loadTextureBuffer(node: ITrackedClass) {\r\n if (node._parent instanceof MaterialNode || node._parent instanceof DisplacementMapFeature) {\r\n node._needsImageUpdate = false;\r\n if (node._buffer) {\r\n node.trackChanges(false);\r\n node._buffer = undefined; // Remove the buffer so the texture stack doesn't think the image is already loaded if the image was changed\r\n node.trackChanges(true);\r\n }\r\n node._parent._materialService.getTextureImage(node).subscribe(resp => {\r\n node._buffer = resp.bitmap;\r\n node._bufferSource = resp.url;\r\n });\r\n } else {\r\n console.warn('Texure is not attached to a material node. Cannot load texture image bitmap.');\r\n }\r\n }\r\n}\r\n","export function base64ArrayBuffer(arrayBuffer: ArrayBuffer) {\r\n let base64 = '';\r\n const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\r\n\r\n const bytes = new Uint8Array(arrayBuffer);\r\n const byteLength = bytes.byteLength;\r\n const byteRemainder = byteLength % 3;\r\n const mainLength = byteLength - byteRemainder;\r\n\r\n let a, b, c, d;\r\n let chunk;\r\n\r\n // Main loop deals with bytes in chunks of 3\r\n for (let i = 0; i < mainLength; i = i + 3) {\r\n // Combine the three bytes into a single integer\r\n chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];\r\n\r\n // Use bitmasks to extract 6-bit segments from the triplet\r\n a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18\r\n b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12\r\n c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6\r\n d = chunk & 63; // 63 = 2^6 - 1\r\n\r\n // Convert the raw binary segments to the appropriate ASCII encoding\r\n base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d];\r\n }\r\n\r\n // Deal with the remaining bytes and padding\r\n if (byteRemainder == 1) {\r\n chunk = bytes[mainLength];\r\n\r\n a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2\r\n\r\n // Set the 4 least significant bits to zero\r\n b = (chunk & 3) << 4; // 3 = 2^2 - 1\r\n\r\n base64 += encodings[a] + encodings[b] + '==';\r\n } else if (byteRemainder == 2) {\r\n chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1];\r\n\r\n a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10\r\n b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4\r\n\r\n // Set the 2 least significant bits to zero\r\n c = (chunk & 15) << 2; // 15 = 2^4 - 1\r\n\r\n base64 += encodings[a] + encodings[b] + encodings[c] + '=';\r\n }\r\n\r\n return base64;\r\n}\r\n","import { base64ArrayBuffer } from '@common-util/buffer-util';\r\nimport { getRotatedDimensions, scaleImagePreserveAspect } from '@common-util/texture-util';\r\nimport { SvgTextureLayer } from '@models/classes/materials/svg-texture-layer';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { TextureParameters } from '../texture-stack';\r\nimport { IDrawOperations, TextureLayerRenderer } from './texture';\r\n\r\nexport class SvgTextureLayerRenderer extends TextureLayerRenderer {\r\n modelToken = Token.FileTextureLayer;\r\n imageElement = document.createElement('img');\r\n svgHelpers = new Map<\r\n string,\r\n {\r\n imgElement: HTMLImageElement;\r\n renderedWidth: number;\r\n renderedHeight: number;\r\n }\r\n >();\r\n\r\n paintTexture(\r\n texture: SvgTextureLayer,\r\n context: CanvasRenderingContext2D,\r\n parameters: TextureParameters,\r\n operations: IDrawOperations\r\n ) {\r\n const helper = this.svgHelpers.get(texture._dynamicId);\r\n\r\n if (\r\n texture._raster &&\r\n helper &&\r\n context.canvas.width === helper.renderedWidth &&\r\n context.canvas.height === helper.renderedHeight\r\n ) {\r\n return this.drawSourceToCanvas(texture, texture._raster, context, parameters, operations);\r\n } else {\r\n let fontLoadPromise: Promise | void>;\r\n\r\n if (texture.preloadFontStylesheet) {\r\n const fontFacesFound = [...texture.svgXml.matchAll(/font-family\\s*[=:]\\s*[\"'](.+?)[\"']/g)];\r\n const fontsToLoad: string[] = [];\r\n for (const match of fontFacesFound) {\r\n fontsToLoad.push(match[1]);\r\n }\r\n\r\n if (fontsToLoad.length > 0) {\r\n const manager = this.viewer.sceneNode._manager!;\r\n const fontService = manager.getService(Token.FontService);\r\n\r\n fontLoadPromise = fontService.loadFontData(texture.preloadFontStylesheet, fontsToLoad);\r\n } else {\r\n fontLoadPromise = Promise.resolve();\r\n }\r\n } else {\r\n fontLoadPromise = Promise.resolve();\r\n }\r\n\r\n fontLoadPromise\r\n .then(result =>\r\n this.generateSvg(texture, context.canvas.width, context.canvas.height, result || undefined)\r\n )\r\n .then(bitmap => {\r\n if (bitmap) {\r\n texture._raster = bitmap;\r\n }\r\n })\r\n .catch(() => {\r\n // Don't need to do anything\r\n });\r\n }\r\n }\r\n\r\n textureHasContent(node: SvgTextureLayer) {\r\n return !!node.svgXml;\r\n }\r\n\r\n getNativeSize(texture: SvgTextureLayer) {\r\n const width = texture.width,\r\n height = texture.height;\r\n\r\n if (texture.wAngle !== 0) {\r\n return getRotatedDimensions(width, height, texture.wAngle);\r\n } else {\r\n return { width, height };\r\n }\r\n }\r\n\r\n update3dInternal(node: ITrackedClass) {\r\n if (\r\n node.changes.has('svgXml') ||\r\n node.changes.has('width') ||\r\n node.changes.has('height') ||\r\n node.changes.has('preloadFontStylesheet')\r\n ) {\r\n node._raster = undefined;\r\n }\r\n super.update3dInternal(node);\r\n }\r\n\r\n generateSvg(texture: SvgTextureLayer, width: number, height: number, embedFonts?: Record) {\r\n if (texture.svgXml !== '' && width > 0 && height > 0) {\r\n let helper = this.svgHelpers.get(texture._dynamicId);\r\n\r\n if (!helper) {\r\n helper = {\r\n imgElement: document.createElement('img'),\r\n renderedHeight: height,\r\n renderedWidth: width,\r\n };\r\n this.svgHelpers.set(texture._dynamicId, helper);\r\n } else {\r\n helper.renderedHeight = height;\r\n helper.renderedWidth = width;\r\n }\r\n\r\n try {\r\n const imageElement = this.svgHelpers.get(texture._dynamicId)!.imgElement;\r\n\r\n let svgString = texture.svgXml;\r\n\r\n // Adding svg required tags\r\n if (!svgString.match(/` +\r\n svgString;\r\n }\r\n if (!svgString.match(/<\\?xml/)) {\r\n svgString = `` + svgString;\r\n }\r\n if (!svgString.match(/]*xmlns=[^>]*>/)) {\r\n svgString = svgString.replace(//m);\r\n if (!match) {\r\n console.warn('Invalid SVG');\r\n return Promise.reject();\r\n } else {\r\n if (embedFonts) {\r\n let fontStyles = '';\r\n for (const fontFamily in embedFonts) {\r\n const arrayBuffer = embedFonts[fontFamily];\r\n fontStyles += ` \r\n@font-face {\r\n font-family: \"${fontFamily}\";\r\n src: url(\"data:application/font-woff;charset=utf-8;base64,${base64ArrayBuffer(arrayBuffer)}\");\r\n}\r\n `;\r\n }\r\n const offset = (match.index || 0) + match[0].length;\r\n\r\n svgString =\r\n svgString.substring(0, offset) +\r\n `` +\r\n svgString.substring(offset);\r\n }\r\n\r\n const blobUrl = URL.createObjectURL(new Blob([svgString], { type: 'image/svg+xml;charset=utf-8' }));\r\n imageElement.src = blobUrl;\r\n\r\n const generateImagePromise = imageElement.decode().then(\r\n () => {\r\n // Don't use the img element from the closure so it can get garbage collected if this function isn't called!\r\n // There's no way to explicitly dispose of a DOM element\r\n const loadedImageElement = this.svgHelpers.get(texture._dynamicId)!.imgElement;\r\n\r\n // Figure out what resolution to actually draw the SVG at to fit within the envelope\r\n const scaled = scaleImagePreserveAspect(\r\n width,\r\n height,\r\n loadedImageElement.naturalWidth,\r\n loadedImageElement.naturalHeight\r\n );\r\n\r\n return createImageBitmap(loadedImageElement, {\r\n resizeWidth: scaled.drawWidth,\r\n resizeHeight: scaled.drawHeight,\r\n });\r\n },\r\n err => {\r\n console.warn('Could not decode SVG XML: ', svgString);\r\n }\r\n );\r\n\r\n this.viewer.deferSceneReady(generateImagePromise);\r\n return generateImagePromise;\r\n }\r\n } catch (e) {\r\n console.warn('Could not generate SVG Texture: ', e);\r\n Promise.reject(e);\r\n }\r\n }\r\n\r\n return Promise.reject();\r\n }\r\n\r\n delete3d(node: ITrackedClass) {\r\n const helper = this.svgHelpers.get(node._dynamicId);\r\n if (helper) {\r\n this.svgHelpers.delete(node._dynamicId);\r\n }\r\n super.delete3d(node);\r\n }\r\n}\r\n","import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { DynamicTexture, Texture } from '@babylonjs/core/Materials/Textures';\r\nimport { Material } from '@babylonjs/core/Materials/material';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { getBinClampedSize } from '@common-util/texture-util';\r\nimport { instanceOf } from '@models/classes/decorators/model-utils';\r\nimport { eMaterialWorkflow, eTextureChannel } from '@models/classes/enums';\r\nimport { FeatureWithTextures, isFeatureNode } from '@models/classes/features/feature';\r\nimport { FileTextureLayer } from '@models/classes/materials/file-texture-layer';\r\nimport { MaterialNode, isMaterialNode } from '@models/classes/materials/material-node';\r\nimport { TextureLayer } from '@models/classes/materials/texture-layer';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass, isTrackedClass } from '@models/interfaces/tracked-class';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subject, merge } from 'rxjs';\r\nimport { debounceTime, takeWhile, throttleTime } from 'rxjs/operators';\r\nimport { Renderer } from './renderer';\r\nimport { RendererManager } from './renderer-manager';\r\nimport { SamplingModeMap } from './scene';\r\nimport { FileTextureLayerRenderer } from './textures';\r\nimport { ColorFillTextureLayerRenderer } from './textures/color-fill-texture';\r\nimport { SvgTextureLayerRenderer } from './textures/svg-texture';\r\nimport { TextureLayerRenderer } from './textures/texture';\r\n\r\nexport type TextureParameters = {\r\n strength: number;\r\n hasTransparency: boolean;\r\n};\r\n\r\nconst textureChannelMap: Record = {\r\n // General\r\n [eTextureChannel.emissive]: 'emissiveTexture',\r\n [eTextureChannel.ambientOcclusion]: 'lightmapTexture',\r\n\r\n // PBR\r\n [eTextureChannel.albedo]: 'albedoTexture',\r\n [eTextureChannel.normal]: 'bumpTexture',\r\n [eTextureChannel.ambient]: 'ambientTexture',\r\n [eTextureChannel.opacity]: 'opacityTexture',\r\n [eTextureChannel.metallic]: 'metallicTexture',\r\n [eTextureChannel.reflection]: 'reflectionTexture',\r\n [eTextureChannel.specular]: 'reflectivityTexture',\r\n [eTextureChannel.roughness]: 'microSurfaceTexture',\r\n [eTextureChannel.glossiness]: 'microSurfaceTexture',\r\n [eTextureChannel.anisotropyTangent]: ['anisotropy', 'texture'],\r\n [eTextureChannel.clearCoatNormal]: ['clearCoat', 'bumpTexture'],\r\n [eTextureChannel.subsurfaceThickness]: ['subSurface', 'thicknessTexture'],\r\n};\r\nconst maskingCanvas = document.createElement('canvas');\r\n\r\nexport class TextureStackRenderer extends Renderer {\r\n modelToken = Token.TextureLayer;\r\n\r\n queuedTexturesToProcess = new Map>();\r\n queueSize = new Subject();\r\n renderers = new Map>();\r\n noMipMapFallback = false;\r\n\r\n private updateTextureStackRequest = new Subject();\r\n private deferCalled = false;\r\n\r\n constructor(viewer: KbViewer, scene: Scene, private rendererManager: RendererManager) {\r\n super(viewer, scene);\r\n const fileTexture = new FileTextureLayerRenderer(viewer, scene);\r\n const svgTexture = new SvgTextureLayerRenderer(viewer, scene);\r\n const colorTexture = new ColorFillTextureLayerRenderer(viewer, scene);\r\n this.renderers.set(Token.FileTextureLayer, fileTexture);\r\n this.renderers.set(Token.SvgTextureLayer, svgTexture);\r\n this.renderers.set(Token.ColorFillTextureLayer, colorTexture);\r\n\r\n /**\r\n * See render.ts comment - this delay must be added to the render as a change can take up to this delay time to be displayed.\r\n * We don't want to repeatedly processes texture changes coming in quick succession, which often happens if there are many textures being loaded at once.\r\n * */\r\n const throttleDebounceTime = 800;\r\n merge(\r\n this.updateTextureStackRequest.pipe(throttleTime(throttleDebounceTime)),\r\n this.updateTextureStackRequest.pipe(debounceTime(throttleDebounceTime))\r\n ).subscribe(() => {\r\n this.updateTextureStacksExec();\r\n });\r\n\r\n // This code works for forcing intel gpus to not use mipmaps, but some scenes don't have artifacting issues and need mipmaps. So\r\n // In the future we can introduce a scene setting to enable the intel fallback\r\n // if (this.viewer.glInfo.match(/Intel.*Iris.*Xe/)) {\r\n // this.noMipMapFallback = true;\r\n // }\r\n }\r\n\r\n materialDeleted(node: MaterialNode) {\r\n for (const channel in eTextureChannel) {\r\n const textureId = this.getTexture3dId(node, channel as eTextureChannel);\r\n const texture = this.babylonMap.get(textureId);\r\n if (texture) {\r\n this.disposeTexture(texture);\r\n this.babylonMap.delete(this.getTexture3dId(node, channel as eTextureChannel));\r\n }\r\n this.babylonMap.delete(textureId);\r\n }\r\n }\r\n\r\n /** This should only be called from the editor. Has a very heavy performance impact. */\r\n forceRebuildTexture(materialNode: MaterialNode | FeatureWithTextures, channel?: eTextureChannel) {\r\n if (channel) {\r\n this.resetTextureStack(materialNode, channel);\r\n } else {\r\n for (const channel in eTextureChannel) {\r\n this.resetTextureStack(materialNode, channel as eTextureChannel);\r\n }\r\n }\r\n this.updateTextureStacksInternal(materialNode);\r\n }\r\n\r\n resetTextureStack(\r\n texturedNode: MaterialNode | FeatureWithTextures,\r\n channel: eTextureChannel,\r\n setParameters?: Partial\r\n ) {\r\n let material: Material | undefined;\r\n let materialNode: MaterialNode | undefined;\r\n\r\n if (isMaterialNode(texturedNode)) {\r\n materialNode = texturedNode;\r\n if (!materialNode._initialized) {\r\n return;\r\n }\r\n material = this.rendererManager.material.get3d(materialNode)!;\r\n if (!material) {\r\n // There might not be a material in babylon if the material was deleted prior to this renderer running.\r\n // console.warn(`material not generated from ${materialNode.name}`);\r\n return;\r\n }\r\n }\r\n\r\n const hasTextureInChannel = !!texturedNode.textures.find(t => t.channel === channel);\r\n if (!hasTextureInChannel) {\r\n return;\r\n }\r\n\r\n let channelsToProcess = this.queuedTexturesToProcess.get(texturedNode);\r\n if (!channelsToProcess) {\r\n channelsToProcess = new Map();\r\n this.queuedTexturesToProcess.set(texturedNode, channelsToProcess);\r\n }\r\n\r\n // Here we don't want to filter out textures with no data because they cam still be used to set the canvas size\r\n const textureLayers = this.getActiveLayers(texturedNode, channel);\r\n\r\n // Register that the channel needs to be processed.\r\n // Figure out the highest strength among the texture layers so we can\r\n // calculate the strength of each one as a fraction of that.\r\n let channelStrength = 0;\r\n textureLayers.forEach(textureLayer => {\r\n channelStrength = Math.max(channelStrength, textureLayer.strength);\r\n });\r\n\r\n const existingProcess = channelsToProcess.get(channel);\r\n channelsToProcess.set(channel, {\r\n strength: channelStrength,\r\n hasTransparency: materialNode ? materialNode.hasTransparency : false,\r\n ...(existingProcess || {}),\r\n ...(setParameters || {}),\r\n });\r\n\r\n const propName3d = textureChannelMap[channel as eTextureChannel] as keyof Material;\r\n\r\n if (material && materialNode) {\r\n // Reset the material to re-run the texture stack (or clear the texture if there are no textures anymore)\r\n if (textureLayers.length === 0) {\r\n // If no textures are using this channel anymore, then remove it from the material\r\n if (Array.isArray(propName3d)) {\r\n const res = getObjectPropertyAtPath(material, propName3d, false);\r\n if (res.obj && res.obj[res.prop]) {\r\n const texture = res.obj[res.prop];\r\n if (texture instanceof Texture) {\r\n this.disposeTexture(texture);\r\n res.obj[res.prop] = null;\r\n this.babylonMap.delete(this.getTexture3dId(materialNode, channel));\r\n }\r\n }\r\n } else {\r\n if (material && material[propName3d]) {\r\n (material[propName3d] as Texture).dispose();\r\n (material[propName3d] as null) = null;\r\n this.babylonMap.delete(this.getTexture3dId(materialNode, channel));\r\n }\r\n }\r\n } else {\r\n const texture = this.getTexture(materialNode, channel);\r\n\r\n if (texture instanceof DynamicTexture) {\r\n const baseImageSize = this.getRenderer(textureLayers[0]).getNativeSize(textureLayers[0]);\r\n const context = texture.getContext();\r\n\r\n if (this.scene.getEngine().webGLVersion < 2) {\r\n const clampedSize = getBinClampedSize(baseImageSize.width, baseImageSize.height);\r\n context.canvas.width = clampedSize;\r\n context.canvas.height = clampedSize;\r\n } else {\r\n context.canvas.width = baseImageSize.width;\r\n context.canvas.height = baseImageSize.height;\r\n }\r\n context.clearRect(0, 0, context.canvas.width, context.canvas.height);\r\n }\r\n }\r\n }\r\n }\r\n\r\n update3dInternal(feature: ITrackedClass) {\r\n if (isTrackedClass(feature)) {\r\n if (!feature.enabled || feature._suppressed) {\r\n if (feature.changes.has('enabled') || feature.changes.has('_suppressed')) {\r\n this.delete3d(feature);\r\n }\r\n\r\n return;\r\n }\r\n\r\n const renderer = this.renderers.get(Token.withKey(feature.$type));\r\n if (!renderer) {\r\n throw Error('no renderer for feature');\r\n }\r\n if (feature._parent && isFeatureNode(feature._parent)) {\r\n feature.init(feature._parent);\r\n }\r\n renderer.update3d(feature);\r\n\r\n if (feature._parent && isFeatureNode(feature._parent) && isTrackedClass(feature._parent)) {\r\n feature._parent.setPropertyIsModified('textures', true);\r\n }\r\n\r\n if (feature._parent) {\r\n this.resetTextureStack(feature._parent, feature.channel);\r\n }\r\n }\r\n }\r\n\r\n updateTextureStacks() {\r\n if (!this.deferCalled && this.queuedTexturesToProcess.size > 0) {\r\n const queueLive = this.queueSize.pipe(takeWhile(size => size > 0));\r\n const p = queueLive.toPromise();\r\n this.viewer.deferSceneReady(p);\r\n this.deferCalled = true;\r\n }\r\n for (const node of this.queuedTexturesToProcess.keys()) {\r\n if (isFeatureNode(node) || node._initialized) {\r\n for (const texture of node.textures) {\r\n if (!texture._init) {\r\n texture.init(node);\r\n }\r\n }\r\n }\r\n }\r\n this.updateTextureStackRequest.next();\r\n }\r\n\r\n private updateTextureStacksExec() {\r\n this.queueSize.next(this.queuedTexturesToProcess.size);\r\n\r\n for (const node of this.queuedTexturesToProcess.keys()) {\r\n this.updateTextureStacksInternal(node);\r\n\r\n if (this.queuedTexturesToProcess.size > 0) {\r\n this.updateTextureStacks();\r\n }\r\n // Low perf code to prevent iOS from erroring out. Doesn't seem necessary for now\r\n // return;\r\n // End low perf code\r\n }\r\n\r\n this.queueSize.next(this.queuedTexturesToProcess.size);\r\n }\r\n\r\n private updateTextureStacksInternal(node: MaterialNode | FeatureWithTextures) {\r\n if (this.queuedTexturesToProcess.has(node)) {\r\n if (isMaterialNode(node)) {\r\n const channels = this.queuedTexturesToProcess.get(node);\r\n const material = this.rendererManager.material.get3d(node);\r\n\r\n if (!channels || !material) {\r\n return;\r\n }\r\n\r\n // Process texture stack\r\n channels.forEach((parameters, channel) => {\r\n // Put the texture in the right place on the material\r\n const propName3d = textureChannelMap[channel as eTextureChannel];\r\n if (instanceOf(node, Token.AdvancedMaterialNode)) {\r\n if (\r\n node.workflowMode === eMaterialWorkflow.metallicRoughness &&\r\n channel === eTextureChannel.glossiness\r\n ) {\r\n return;\r\n } else if (\r\n node.workflowMode === eMaterialWorkflow.specularGlossiness &&\r\n channel === eTextureChannel.roughness\r\n ) {\r\n return;\r\n }\r\n }\r\n\r\n const texture = this.getTexture(node, channel);\r\n // If texture is undefined, that means that there is a missing setting/layers that means we don't need a texture for this channel\r\n if (texture) {\r\n // Paint the image onto the texture\r\n // We don't want to count layers with no content in the stack, like file textures with no file or svg textures with no data\r\n const textureLayers = this.getActiveLayers(node, channel).filter(node => {\r\n const renderer = this.getRenderer(node);\r\n return renderer.textureHasContent(node);\r\n });\r\n\r\n if (textureLayers.length > 0) {\r\n // Put the texture in the right place on the material if it's not already\r\n if (Array.isArray(propName3d)) {\r\n const res = getObjectPropertyAtPath(material, propName3d);\r\n if (res.obj[res.prop] !== texture) {\r\n res.obj[res.prop] = texture;\r\n }\r\n } else {\r\n if (material[propName3d as keyof Material] !== texture) {\r\n (material[propName3d as keyof Material] as Texture) = texture;\r\n }\r\n }\r\n\r\n if (texture instanceof DynamicTexture) {\r\n const context = texture.getContext();\r\n\r\n if (!(context instanceof CanvasRenderingContext2D)) {\r\n throw Error('Unexpected rendering context');\r\n }\r\n if (channel !== eTextureChannel.albedo) {\r\n // Fill texture with color that makes sense depending on the texture channel\r\n switch (channel) {\r\n case eTextureChannel.normal: {\r\n context.fillStyle = 'rgb(128, 128, 255)';\r\n break;\r\n }\r\n\r\n case eTextureChannel.opacity:\r\n case eTextureChannel.ambient:\r\n case eTextureChannel.ambientOcclusion: {\r\n context.fillStyle = 'rgb(255, 255, 255)';\r\n break;\r\n }\r\n\r\n default: {\r\n context.fillStyle = 'rgb(0, 0, 0)';\r\n break;\r\n }\r\n }\r\n\r\n context.fillRect(0, 0, context.canvas.width, context.canvas.height);\r\n }\r\n this.paintTextureOnCanvas(textureLayers, context, parameters);\r\n\r\n updateTextureProps(texture, parameters);\r\n\r\n texture.update(true); // invertY\r\n } else {\r\n // If texture is not a dynamic texture, then it's a basic texture and there is only one texture layer. We just have to make sure the path is correct\r\n const fileTextureLayer = textureLayers[0];\r\n if (!(fileTextureLayer instanceof FileTextureLayer)) {\r\n throw Error('Unexpected texture type');\r\n } else {\r\n if (fileTextureLayer._parent instanceof MaterialNode) {\r\n const path = fileTextureLayer._bufferSource || '';\r\n if (texture.url !== path && fileTextureLayer._buffer) {\r\n texture.updateURL(path, (fileTextureLayer._buffer || null) as any);\r\n }\r\n }\r\n\r\n updateTextureProps(texture, parameters);\r\n }\r\n }\r\n }\r\n }\r\n });\r\n } else {\r\n if (isTrackedClass(node)) {\r\n node.setPropertyIsModified('textures', true);\r\n this.queuedTexturesToProcess.delete(node);\r\n return;\r\n }\r\n }\r\n }\r\n if (isMaterialNode(node) && isTrackedClass(node)) {\r\n this.applyUvProperties(node);\r\n } else {\r\n throw Error('Material is not being tracked');\r\n }\r\n this.queuedTexturesToProcess.delete(node);\r\n\r\n function updateTextureProps(texture: Texture, parameters: TextureParameters) {\r\n texture.level = parameters.strength;\r\n texture.hasAlpha = parameters.hasTransparency;\r\n }\r\n }\r\n\r\n delete3d(feature: ITrackedClass) {\r\n if (feature._parent) {\r\n this.resetTextureStack(feature._parent, feature.channel);\r\n }\r\n\r\n const renderer = this.renderers.get(Token.withKey(feature.$type));\r\n if (!renderer) {\r\n throw Error('no renderer for feature');\r\n }\r\n renderer.delete3d(feature);\r\n }\r\n\r\n get3d(texture: TextureLayer) {\r\n if (!texture._parent) {\r\n return undefined;\r\n }\r\n if (texture._parent instanceof MaterialNode) {\r\n return this.babylonMap.get(this.getTexture3dId(texture._parent, texture.channel));\r\n }\r\n }\r\n\r\n set3d(texture: TextureLayer, babylonObject: Texture) {\r\n if (texture._parent) {\r\n if (texture._parent instanceof MaterialNode) {\r\n this.babylonMap.set(this.getTexture3dId(texture._parent, texture.channel), babylonObject);\r\n }\r\n }\r\n }\r\n\r\n dispose() {\r\n this.queuedTexturesToProcess.clear();\r\n this.renderers.forEach(renderer => renderer.dispose());\r\n this.updateTextureStackRequest.complete();\r\n super.dispose();\r\n }\r\n\r\n setTransparency(materialNode: MaterialNode | FeatureWithTextures, hasTransparency: boolean) {\r\n // TODO: limit this to only albedo textures for now. Will need testing.\r\n this.resetTextureStack(materialNode, eTextureChannel.albedo, { hasTransparency });\r\n }\r\n\r\n applyUvProperties(materialNode: ITrackedClass) {\r\n const material = this.rendererManager.material.get3d(materialNode);\r\n if (material) {\r\n for (const channel in textureChannelMap) {\r\n const firstTextureLayer = materialNode.textures.find(\r\n t => t.channel === channel\r\n ) as ITrackedClass;\r\n\r\n const propName3d = textureChannelMap[channel as eTextureChannel] as keyof Material;\r\n\r\n let texture: Texture;\r\n if (Array.isArray(propName3d)) {\r\n const res = getObjectPropertyAtPath(material, propName3d);\r\n texture = res.obj[res.prop];\r\n } else {\r\n texture = material[propName3d];\r\n }\r\n\r\n if (texture && firstTextureLayer) {\r\n if (!(texture instanceof Texture)) {\r\n throw Error(propName3d.toString() + ' is not a texture');\r\n }\r\n texture.uOffset = firstTextureLayer.uOffset;\r\n texture.vOffset = firstTextureLayer.vOffset;\r\n texture.uScale = firstTextureLayer.uScale;\r\n texture.vScale = firstTextureLayer.vScale;\r\n texture.uAng = (firstTextureLayer.uAngle * Math.PI) / 180;\r\n texture.vAng = (firstTextureLayer.vAngle * Math.PI) / 180;\r\n texture.wAng = (firstTextureLayer.wAngle * Math.PI) / 180;\r\n texture.uRotationCenter = firstTextureLayer.uPivot;\r\n texture.vRotationCenter = firstTextureLayer.vPivot;\r\n texture.wRotationCenter = firstTextureLayer.wPivot;\r\n // if (firstTextureLayer.uWrap === eTextureWrapAddressMode.clamp) {\r\n // texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n // } else {\r\n // texture.wrapU = Texture.WRAP_ADDRESSMODE;\r\n // }\r\n // if (firstTextureLayer.vWrap === eTextureWrapAddressMode.clamp) {\r\n // texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n // } else {\r\n // texture.wrapV = Texture.WRAP_ADDRESSMODE;\r\n // }\r\n\r\n // For some reason wrap addressmode is not getting converted correctly. Repeat is the safer option so\r\n // Let's hardcode repeat for now\r\n texture.wrapU = Texture.WRAP_ADDRESSMODE;\r\n texture.wrapV = Texture.WRAP_ADDRESSMODE;\r\n\r\n if (!(texture instanceof DynamicTexture)) {\r\n texture.vScale *= -1;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n paintTextureOnCanvas(textureLayers: TextureLayer[], context: any, parameters: TextureParameters) {\r\n let clippingTexture: TextureLayer | null = null;\r\n\r\n for (let i = 0; i < textureLayers.length; i++) {\r\n if (!textureLayers[i]._init) {\r\n continue;\r\n }\r\n\r\n const textureLayer = textureLayers[i];\r\n const renderer = this.getRenderer(textureLayer);\r\n\r\n // Continue clipping with the same texture as long as useClippingMask is true.\r\n // When there's a texture that's not clipping, that can potentially be a new clipping mask.\r\n if (!textureLayer.useClippingMask) {\r\n clippingTexture = null;\r\n }\r\n\r\n const maskingCtx = maskingCanvas.getContext('2d', {\r\n willReadFrequently: true,\r\n })!;\r\n if (textureLayers[i + 1] && textureLayers[i + 1].useClippingMask && !clippingTexture) {\r\n maskingCanvas.width = context.canvas.width;\r\n maskingCanvas.height = context.canvas.height;\r\n clippingTexture = textureLayer;\r\n } else if (textureLayer.useClippingMask && clippingTexture) {\r\n const clippingTextureRenderer = this.getRenderer(clippingTexture);\r\n maskingCtx.clearRect(0, 0, maskingCanvas.width, maskingCanvas.height);\r\n clippingTextureRenderer.paintTexture(\r\n clippingTexture,\r\n maskingCtx,\r\n { strength: 1, hasTransparency: true },\r\n {}\r\n );\r\n renderer.paintTexture(textureLayer, context, parameters, {\r\n mask: { context: maskingCtx },\r\n });\r\n } else {\r\n renderer.paintTexture(textureLayer, context, parameters, {});\r\n }\r\n }\r\n return context;\r\n }\r\n\r\n getActiveLayers(\r\n materialNode: MaterialNode | FeatureWithTextures,\r\n channel: eTextureChannel,\r\n includeSupressed = false\r\n ) {\r\n return materialNode.textures.filter(\r\n texture => texture.channel === channel && texture.enabled && (includeSupressed || !texture._suppressed)\r\n );\r\n }\r\n\r\n getRenderer(textureLayer: TextureLayer) {\r\n const renderer = this.renderers.get(Token.withKey(textureLayer.$type));\r\n if (!renderer) {\r\n throw Error('no renderer for texture layer');\r\n }\r\n return renderer;\r\n }\r\n\r\n private canUseSimpleTexture(activeLayers: TextureLayer[]) {\r\n if (activeLayers.length === 1) {\r\n const layer = activeLayers[0];\r\n return layer instanceof FileTextureLayer;\r\n }\r\n return false;\r\n }\r\n\r\n private disposeTexture(texture: Texture) {\r\n // Resizing textures before they are ready results in an error. Remove this code for now\r\n // if (texture instanceof DynamicTexture) {\r\n // texture.scaleTo(1, 1); // Prevent memory leaks in Safari\r\n // }\r\n texture.dispose();\r\n }\r\n\r\n private getTexture3dId(node: MaterialNode, channel: eTextureChannel) {\r\n return `${node._dynamicId}_${channel}`;\r\n }\r\n\r\n private getTexture(node: MaterialNode, channel: eTextureChannel) {\r\n const rootScene = this.viewer.sceneNode;\r\n const activeLayers = this.getActiveLayers(node, channel, true);\r\n const canUseSimpleTexture = this.canUseSimpleTexture(activeLayers);\r\n\r\n let texture = this.babylonMap.get(this.getTexture3dId(node, channel));\r\n const originalTexture = texture;\r\n\r\n if (originalTexture) {\r\n if (originalTexture instanceof DynamicTexture && canUseSimpleTexture) {\r\n this.disposeTexture(originalTexture);\r\n } else if (activeLayers.length > 1 && !(texture instanceof DynamicTexture)) {\r\n this.disposeTexture(originalTexture);\r\n } else {\r\n return originalTexture;\r\n }\r\n }\r\n\r\n if (canUseSimpleTexture) {\r\n const fileTexture = activeLayers[0] as FileTextureLayer;\r\n if (fileTexture.path && fileTexture._buffer && fileTexture._parent instanceof MaterialNode) {\r\n texture = new Texture(\r\n fileTexture._bufferSource || '',\r\n this.scene,\r\n this.noMipMapFallback,\r\n false,\r\n SamplingModeMap[rootScene.textureSamplingMode],\r\n null,\r\n null,\r\n fileTexture._buffer\r\n );\r\n texture.name = this.getTexture3dId(node, channel);\r\n } else {\r\n return undefined;\r\n }\r\n } else {\r\n texture = new DynamicTexture(\r\n this.getTexture3dId(node, channel),\r\n 256,\r\n this.scene,\r\n !this.noMipMapFallback,\r\n SamplingModeMap[rootScene.textureSamplingMode]\r\n );\r\n }\r\n\r\n texture.homogeneousRotationInUVTransform = true;\r\n this.babylonMap.set(this.getTexture3dId(node, channel), texture);\r\n\r\n // set initial values\r\n if (originalTexture) {\r\n texture.hasAlpha = originalTexture.hasAlpha;\r\n texture.level = originalTexture.level;\r\n texture.getAlphaFromRGB = originalTexture.getAlphaFromRGB;\r\n } else {\r\n texture.hasAlpha = false;\r\n if (channel === eTextureChannel.opacity) {\r\n texture.getAlphaFromRGB = true;\r\n } else {\r\n texture.getAlphaFromRGB = false;\r\n }\r\n texture.level = 1;\r\n }\r\n texture.coordinatesIndex = 0;\r\n texture.coordinatesMode = 0;\r\n texture.anisotropicFilteringLevel = 4;\r\n\r\n if (texture instanceof Texture) {\r\n texture.uOffset = 0; // Define an offset on the texture to offset the u coordinates of the UVs\r\n texture.vOffset = 0; // Define an offset on the texture to offset the v coordinates of the UVs\r\n texture.uScale = -1; // Define an offset on the texture to scale the u coordinates of the UVs\r\n texture.vScale = 1; // Define an offset on the texture to scale the v coordinates of the UVs\r\n texture.uAng = 0; // Define an offset on the texture to rotate around the u coordinates of the UVs\r\n texture.vAng = 0; // Define an offset on the texture to rotate around the v coordinates of the UVs\r\n texture.wAng = 0; // Define an offset on the texture to rotate around the w coordinates of the UVs (in case of 3d texture)\r\n texture.uRotationCenter = 0.5; // Defines the center of rotation (U)\r\n texture.vRotationCenter = 0.5; // Defines the center of rotation (V)\r\n texture.wRotationCenter = 0.5; // Defin\r\n texture.isBlocking = false;\r\n }\r\n\r\n return texture;\r\n }\r\n}\r\n\r\nfunction getObjectPropertyAtPath(_obj: T, path: string[], throwOnNotFound = true) {\r\n let obj = _obj as any;\r\n const propPath = path.slice().reverse();\r\n while (propPath.length > 1 && obj) {\r\n const prop = propPath.pop() as any;\r\n if (prop in obj) {\r\n obj = obj[prop];\r\n } else {\r\n obj = null;\r\n }\r\n }\r\n if (throwOnNotFound && !obj) {\r\n throw Error('Texture property not found for ' + path.toString());\r\n }\r\n\r\n return { obj, prop: propPath[0] as string };\r\n}\r\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { Token } from '@models/classes/token';\r\nimport { ViewpointNode } from '@models/classes/viewpoints/viewpoint-node';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { Renderer } from './renderer';\r\n\r\nexport class ViewpointRenderer extends Renderer {\r\n modelToken = Token.ViewpointNode;\r\n update3dInternal(node: ITrackedClass) {}\r\n}\r\n","import { Scene } from '@babylonjs/core/scene';\r\nimport { eMaterialLocation, eRenderMode } from '@models/classes/enums';\r\nimport { ArrayMap } from '@models/classes/handlers';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { MaterialNode } from '@models/classes/materials/material-node';\r\nimport { TextureLayer } from '@models/classes/materials/texture-layer';\r\nimport { SceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces';\r\nimport { SyncService } from '@models/services/sync-service';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { AnnotationRenderer } from './annotation';\r\nimport { DimensionRenderer } from './dimension';\r\nimport { FeatureStackRenderer } from './feature-stack';\r\nimport { ConnectorRenderer } from './features';\r\nimport { SketchControlPointRenderer } from './features/sketch-control-point';\r\nimport { LightRenderer } from './light';\r\nimport { MateRenderer } from './mate';\r\nimport { MaterialRenderer } from './material';\r\nimport { MeshRenderer } from './mesh';\r\nimport { PathRenderer } from './path';\r\nimport { MateProcessor } from './processors/mate-processor';\r\nimport { Processor } from './processors/processor';\r\nimport { ReferenceProcessor } from './processors/reference-processor';\r\nimport { SketchProcessor } from './processors/sketch-processor';\r\nimport { MAX_RENDER_TIME, Renderer } from './renderer';\r\nimport { SceneRenderer } from './scene';\r\nimport { ShadowManager } from './shadow-manager';\r\nimport { TextureStackRenderer } from './texture-stack';\r\nimport { ViewpointRenderer } from './viewpoint';\r\n\r\nlet unprocessedChangesCount = 0;\r\n\r\nexport class ChangeMap extends ArrayMap> {}\r\n\r\nexport class RendererManager {\r\n deferredChanges: Array> = [];\r\n maxRenderTime = MAX_RENDER_TIME;\r\n renderers: Set>;\r\n sceneRenderer: SceneRenderer;\r\n light: LightRenderer;\r\n material: MaterialRenderer;\r\n mesh: MeshRenderer;\r\n textures: TextureStackRenderer;\r\n viewpoint: ViewpointRenderer;\r\n features: FeatureStackRenderer;\r\n connector: ConnectorRenderer;\r\n controlPointRenderer: SketchControlPointRenderer;\r\n annotation: AnnotationRenderer;\r\n dimension: DimensionRenderer;\r\n mate: MateRenderer;\r\n path: PathRenderer;\r\n\r\n shadowManager: ShadowManager;\r\n processors = new Array();\r\n mateProcessor: MateProcessor;\r\n referenceProcessor: ReferenceProcessor;\r\n sketchProcessor: SketchProcessor;\r\n\r\n private forcedRenderingMode: eRenderMode | undefined;\r\n\r\n getRenderMode() {\r\n return this.material.renderMode;\r\n }\r\n /** Do not use this function directly. Call setRenderMode on the viewer instead so the correct sceneNode is used. */\r\n setRenderMode(mode: eRenderMode, sceneNode: SceneNode, force?: boolean) {\r\n if (force) {\r\n this.forcedRenderingMode = mode;\r\n }\r\n this.material.renderMode = this.forcedRenderingMode || mode;\r\n this.mesh.setRenderMode(this.forcedRenderingMode || mode, sceneNode);\r\n }\r\n\r\n constructor(public viewer: KbViewer, public scene: Scene) {\r\n this.shadowManager = new ShadowManager(viewer.bbCache);\r\n this.sceneRenderer = new SceneRenderer(viewer, scene, viewer.gui, this);\r\n this.textures = new TextureStackRenderer(viewer, scene, this);\r\n this.material = new MaterialRenderer(viewer, scene, this.textures);\r\n this.light = new LightRenderer(viewer, scene, this.shadowManager);\r\n this.viewpoint = new ViewpointRenderer(viewer, scene);\r\n this.mesh = new MeshRenderer(viewer, scene, this, this.shadowManager);\r\n this.features = new FeatureStackRenderer(viewer, scene, this);\r\n this.connector = new ConnectorRenderer(viewer, scene, this);\r\n this.controlPointRenderer = new SketchControlPointRenderer(viewer, scene, this);\r\n this.annotation = new AnnotationRenderer(viewer, scene, this);\r\n this.dimension = new DimensionRenderer(viewer, scene, this);\r\n this.mate = new MateRenderer(viewer, scene);\r\n this.path = new PathRenderer(viewer, scene);\r\n\r\n // Order is important here, it defines the order in which renderers will be run\r\n this.renderers = new Set>([\r\n this.sceneRenderer,\r\n this.material,\r\n this.textures,\r\n this.viewpoint,\r\n this.path,\r\n this.mesh,\r\n this.light,\r\n this.features,\r\n this.connector,\r\n this.controlPointRenderer,\r\n this.annotation,\r\n this.dimension,\r\n this.mate,\r\n ]);\r\n\r\n this.referenceProcessor = new ReferenceProcessor(viewer);\r\n this.mateProcessor = new MateProcessor(\r\n viewer,\r\n scene,\r\n this.connector,\r\n this.controlPointRenderer,\r\n this.referenceProcessor\r\n );\r\n this.sketchProcessor = new SketchProcessor(this.controlPointRenderer);\r\n this.processors.push(this.mateProcessor);\r\n this.processors.push(this.referenceProcessor);\r\n this.processors.push(this.sketchProcessor);\r\n }\r\n\r\n isStable() {\r\n return (\r\n !SyncService.hasChanges &&\r\n this.features.queuedFeaturesToProcess.size === 0 &&\r\n this.textures.queuedTexturesToProcess.size === 0\r\n );\r\n }\r\n\r\n render() {\r\n let changes: ChangeMap;\r\n if (this.deferredChanges.length > 0) {\r\n changes = this.getChangeMap(this.deferredChanges);\r\n } else {\r\n for (const p of this.processors) {\r\n p.beforeRender();\r\n }\r\n // run deletions first\r\n const deletions = this.getChangeMap(SyncService.getDeletedNodes(), true);\r\n for (const p of this.processors) {\r\n p.beforeDeletions(deletions);\r\n }\r\n this.runChanges(deletions, (renderer, change) => renderer.delete3d(change));\r\n for (const p of this.processors) {\r\n p.afterDeletions(deletions);\r\n }\r\n //then run updates\r\n const newChanges = SyncService.getChangedNodes();\r\n changes = this.getChangeMap(newChanges);\r\n\r\n for (const p of this.processors) {\r\n p.beforeUpdates(changes);\r\n }\r\n changes = this.getChangeMap(SyncService.getChangedNodes()); //need to update changes in case processors added any\r\n }\r\n\r\n const allChangesByDid = new Map(\r\n changes.all().map(change => {\r\n return [change._dynamicId, change];\r\n })\r\n );\r\n const allChangeCount = allChangesByDid.size;\r\n const processedChangeMap = this.runChanges(changes, (renderer, change) => {\r\n renderer.update3d(change);\r\n });\r\n const processedChanges = processedChangeMap.all();\r\n processedChanges.forEach(change => {\r\n allChangesByDid.delete(change._dynamicId);\r\n });\r\n this.deferredChanges = Array.from(allChangesByDid.values());\r\n\r\n const skipCount = allChangeCount - processedChanges.length;\r\n // For now we are processing all changes becuase it causes unpredictable behavior.\r\n // The heaviest part of the render cycle is the geometry features processing.\r\n // if (processedChanges.length > 0 || skipCount > 0) {\r\n // console.log('processed ' + processedChanges.length + ' changes, skipped ' + skipCount + ' changes');\r\n // }\r\n\r\n // Don't run the geometry and texture stack processing until all changes have been processed\r\n if (skipCount === 0) {\r\n this.features.update3dGeometry();\r\n this.textures.updateTextureStacks();\r\n }\r\n\r\n for (const p of this.processors) p.afterUpdates(processedChangeMap);\r\n for (const n of processedChanges) {\r\n n.commitChanges();\r\n }\r\n\r\n for (const p of this.processors) p.doAfterCleanup();\r\n\r\n // Output a console warning if there are a lot of changes not being processed, as this could indicate a problem with changes not being processed.\r\n const unchangedNodes = SyncService.getChangedNodes();\r\n\r\n if (unchangedNodes.length > 0) {\r\n unprocessedChangesCount++;\r\n if (unprocessedChangesCount > 1000) {\r\n unprocessedChangesCount = 0;\r\n console.warn('Scene stabilization is taking longer than expected.');\r\n for(const n of unchangedNodes) {\r\n if(n._rootScene._dynamicId !== this.viewer.sceneNode._dynamicId) {\r\n n.commitChanges();\r\n console.warn(`node ${n.name} (${n.id}) is from a different, non-active scene instance. Clearing the change.`)\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** runs a change map in order */\r\n protected runChanges(\r\n changes: ChangeMap,\r\n action: (renderer: Renderer, change: ITrackedClass) => void\r\n ) {\r\n const processedChanges = new ChangeMap();\r\n const renderStart = performance.now();\r\n\r\n for (const renderer of this.renderers) {\r\n const changeList = changes.get(renderer.modelToken);\r\n for (const change of changeList) {\r\n action(renderer, change);\r\n processedChanges.add(renderer.modelToken, change);\r\n }\r\n }\r\n\r\n const renderTime = performance.now() - renderStart;\r\n if (renderTime > 50) {\r\n console.warn(`Change cycle took ${renderTime}ms`);\r\n }\r\n\r\n return processedChanges;\r\n }\r\n protected getChangeMap(nodes: Array>, includeOrphaned = false) {\r\n const changes = new ChangeMap();\r\n for (const n of nodes) {\r\n if (\r\n (n._rootScene?._dynamicId === this.viewer.sceneNode._dynamicId && n._level > -1) ||\r\n includeOrphaned ||\r\n this.isGlobalMaterialOrTexture(n) //global/library material nodes held outside of graph\r\n ) {\r\n const renderer = this.renderers.find(r => r.handlesNode(n));\r\n if (!renderer) throw 'unknown node type';\r\n changes.add(renderer.modelToken, n);\r\n } else if (n._rootScene == null) {\r\n // Clear changes on nodes that are not in any scene tree\r\n n.commitChanges();\r\n }\r\n }\r\n\r\n changes.get(Token.SpaceNode).sortBy(m => m._level); //sort meshes by level first\r\n\r\n return changes;\r\n }\r\n disposeAll() {\r\n this.shadowManager.dispose();\r\n for (const processor of this.processors) processor.dispose();\r\n for (const renderer of this.renderers) renderer.dispose();\r\n }\r\n\r\n protected isGlobalMaterialOrTexture(n: Kb3dObject) {\r\n let mat = n;\r\n if (n instanceof TextureLayer) mat = n._parent as Kb3dObject;\r\n return mat instanceof MaterialNode && mat.location != eMaterialLocation.local;\r\n }\r\n}\r\n","import { ICameraInput } from '@babylonjs/core/Cameras/cameraInputsManager';\r\nimport { IWheelEvent } from '@babylonjs/core/Events/deviceInputEvents';\r\nimport { PointerEventTypes, PointerInfo } from '@babylonjs/core/Events/pointerEvents';\r\nimport { Epsilon, Scalar } from '@babylonjs/core/Maths';\r\nimport { EventState, Observer } from '@babylonjs/core/Misc/observable';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { KbArcRotateCamera } from './kb-arc-rotate-camera';\r\n\r\n/**\r\n * We are overriding the default mouse wheet input for the arc rotate camera here because\r\n * the default one does not act correctly when zoomed in close to the target: it\r\n * calculates the inertia based on the radius at the time the event happens. The result\r\n * is that zooming in is fast than zooming out. They had a misguided attempt at fixing\r\n * that here: https://github.com/BabylonJS/Babylon.js/issues/6215 but it is inadequate.\r\n * See comments below for where we changed the code\r\n */\r\nexport class KbArcRotateCameraMouseWheelInput implements ICameraInput {\r\n public camera: KbArcRotateCamera;\r\n public wheelPrecision = 3.0;\r\n public wheelDeltaPercentage = 0;\r\n\r\n private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;\r\n private _observer: Nullable>;\r\n\r\n private computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta: number, radius: number) {\r\n let delta = 0;\r\n const wheelDelta = mouseWheelDelta * 0.01 * this.wheelDeltaPercentage * radius;\r\n if (mouseWheelDelta > 0) {\r\n delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);\r\n } else {\r\n delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);\r\n }\r\n return delta;\r\n }\r\n\r\n public attachControl(noPreventDefault?: boolean): void {\r\n this._wheel = (p, s) => {\r\n if (p.type !== PointerEventTypes.POINTERWHEEL) {\r\n return;\r\n }\r\n const event = p.event as IWheelEvent;\r\n let delta = 0;\r\n\r\n const mouseWheelLegacyEvent = event as any;\r\n let wheelDelta = 0;\r\n\r\n if (mouseWheelLegacyEvent.wheelDelta) {\r\n wheelDelta = mouseWheelLegacyEvent.wheelDelta;\r\n } else {\r\n wheelDelta = -(event.deltaY || event.detail || 0) * 60;\r\n }\r\n\r\n if (this.wheelDeltaPercentage) {\r\n delta = this.computeDeltaFromMouseWheelLegacyEvent(wheelDelta, this.camera.radius);\r\n\r\n // If zooming in, estimate the target radius and use that to compute the delta for inertia\r\n // this will stop multiple scroll events zooming in from adding too much inertia\r\n //if (delta > 0) { //KB Note: their misguided attempt at fixing the problem only affected zoom in, when it should affect both, so we commented this line out\r\n let estimatedTargetRadius = this.camera.radius;\r\n let targetInertia = this.camera.inertialRadiusOffset + delta;\r\n for (let i = 0; i < 20 && Math.abs(targetInertia) > this.camera.speed * Epsilon; i++) {\r\n //KB Note: fixed the lower limit where it opts out to match the camera's own intertial calculation\r\n estimatedTargetRadius -= targetInertia;\r\n targetInertia *= this.camera.inertia;\r\n }\r\n estimatedTargetRadius = Scalar.Clamp(estimatedTargetRadius, 0, Number.MAX_VALUE);\r\n delta = this.computeDeltaFromMouseWheelLegacyEvent(wheelDelta, estimatedTargetRadius);\r\n //}\r\n } else {\r\n delta = wheelDelta / (this.wheelPrecision * 40);\r\n }\r\n\r\n if (delta) {\r\n this.camera.inertialRadiusOffset += delta;\r\n }\r\n\r\n if (event.preventDefault) {\r\n if (!noPreventDefault) {\r\n event.preventDefault();\r\n }\r\n }\r\n };\r\n\r\n this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, PointerEventTypes.POINTERWHEEL);\r\n }\r\n\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene().onPointerObservable.remove(this._observer);\r\n this._observer = null;\r\n this._wheel = null;\r\n }\r\n }\r\n\r\n public getClassName(): string {\r\n return 'KbArcRotateCameraMouseWheelInput';\r\n }\r\n\r\n public getSimpleName(): string {\r\n return 'mousewheel';\r\n }\r\n}\r\n","import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';\r\nimport { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { Epsilon, Vector2, Vector3 } from '@babylonjs/core/Maths';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { KbArcRotateCameraMouseWheelInput } from './kb-arc-rotate-camera-wheel-input';\r\n\r\n/** Arc Rotate Camera (orbit camera) modified to offset the screen position on pan and keep the orbit target in the same position */\r\nexport class KbArcRotateCamera extends ArcRotateCamera {\r\n constructor(\r\n name: string,\r\n alpha: number,\r\n beta: number,\r\n radius: number,\r\n target: Vector3,\r\n private scene: Scene,\r\n setActiveOnSceneIfNoneActive?: boolean\r\n ) {\r\n super(name, alpha, beta, radius, target, scene, setActiveOnSceneIfNoneActive);\r\n\r\n //replace the wheel input with our own\r\n this.inputs.removeByType('ArcRotateCameraMouseWheelInput');\r\n this.inputs.add(new KbArcRotateCameraMouseWheelInput());\r\n this.updateClient();\r\n }\r\n inertialOffsetPanningX = 0;\r\n inertialOffsetPanningY = 0;\r\n inertialOrthoZoom = 0;\r\n clientInfo = {\r\n mouseX: 0,\r\n mouseY: 0,\r\n screenLeft: 0,\r\n screenTop: 0,\r\n screenWidth: 0,\r\n screenHeight: 0,\r\n };\r\n lockRotation = false;\r\n lockPanning = false;\r\n lockZoom = false;\r\n limitMinimumTargetDistance = false;\r\n\r\n private disposeListeners: (() => void) | undefined;\r\n private _orthoWidth = 0;\r\n get orthoWidth() {\r\n return this._orthoWidth;\r\n }\r\n set orthoWidth(val) {\r\n this._orthoWidth = this.clampOrthoWidth(val);\r\n this.updateOrthographicPosition();\r\n }\r\n\r\n orthoFit(sizeX: number, sizeY: number) {\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n const ratio = this.clientInfo.screenHeight / this.clientInfo.screenWidth;\r\n if (sizeX * ratio < sizeY) {\r\n this.orthoWidth = sizeY / ratio;\r\n } else {\r\n this.orthoWidth = sizeX;\r\n }\r\n }\r\n }\r\n\r\n update() {\r\n if (this.scene.activeCamera !== this) {\r\n return;\r\n }\r\n let startZoomLevel: number | undefined;\r\n if (!this.targetScreenOffset) {\r\n this.targetScreenOffset = new Vector2(0, 0);\r\n }\r\n\r\n if (this.lockRotation && (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0)) {\r\n this.inertialPanningX = this.inertialAlphaOffset;\r\n this.inertialPanningY = -this.inertialBetaOffset;\r\n this.inertialAlphaOffset = this.inertialBetaOffset = 0;\r\n }\r\n\r\n if (this.inertialPanningX !== 0 || this.inertialPanningY !== 0) {\r\n if (!this.lockPanning) {\r\n this.inertialOffsetPanningX = this.inertialPanningX;\r\n this.inertialOffsetPanningY = this.inertialPanningY;\r\n }\r\n this.inertialPanningX = 0;\r\n this.inertialPanningY = 0;\r\n }\r\n\r\n if (this.lockZoom && this.inertialRadiusOffset !== 0) {\r\n this.inertialRadiusOffset = 0;\r\n }\r\n\r\n if (this.inertialRadiusOffset !== 0) {\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n this.inertialOrthoZoom = this.inertialRadiusOffset;\r\n this.inertialRadiusOffset = 0;\r\n } else {\r\n startZoomLevel = this.radius;\r\n //this.inertialRadiusOffset = 0; //override so we have full control over the zoom\r\n //if (this.inertialRadiusOffset < .001) this.inertialRadiusOffset = .001;\r\n }\r\n }\r\n\r\n if (this.inertialOrthoZoom !== 0) {\r\n startZoomLevel = this.orthoWidth;\r\n }\r\n\r\n super.update();\r\n\r\n if (this.inertialOffsetPanningX !== 0 || this.inertialOffsetPanningY !== 0) {\r\n let offset: Vector2;\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n offset = new Vector2(\r\n this.inertialOffsetPanningX * this.orthoWidth,\r\n this.inertialOffsetPanningY * this.orthoWidth\r\n );\r\n } else {\r\n offset = new Vector2(\r\n this.inertialOffsetPanningX * this.radius,\r\n this.inertialOffsetPanningY * this.radius\r\n );\r\n }\r\n this.targetScreenOffset.subtractInPlace(offset);\r\n\r\n this.inertialOffsetPanningX *= this.panningInertia;\r\n this.inertialOffsetPanningY *= this.panningInertia;\r\n }\r\n\r\n if (this.inertialOrthoZoom !== 0) {\r\n this.orthoWidth = this.orthoWidth - this.inertialOrthoZoom * this.orthoWidth;\r\n\r\n this.inertialOrthoZoom *= this.panningInertia;\r\n }\r\n\r\n if (Math.abs(this.inertialOffsetPanningX) < this.speed * Epsilon) {\r\n this.inertialOffsetPanningX = 0;\r\n }\r\n if (Math.abs(this.inertialOffsetPanningY) < this.speed * Epsilon) {\r\n this.inertialOffsetPanningY = 0;\r\n }\r\n if (Math.abs(this.inertialOrthoZoom) < this.speed * Epsilon) {\r\n this.inertialOrthoZoom = 0;\r\n }\r\n\r\n // When zooming, adjust the camera pan so you zoom into your mouse position, as long as pan is enabled\r\n if (!this.lockPanning && startZoomLevel !== undefined) {\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n const zoomChange = (startZoomLevel - this.orthoWidth) / 2;\r\n\r\n this.targetScreenOffset.x -= zoomChange * this.clientInfo.mouseX;\r\n this.targetScreenOffset.y += zoomChange * this.clientInfo.mouseY;\r\n } else {\r\n const gamma = Math.tan(this.fov / 2);\r\n const zoomChange = startZoomLevel - this.radius;\r\n\r\n const shiftX = zoomChange * gamma * this.clientInfo.mouseX;\r\n const shiftY = zoomChange * gamma * this.clientInfo.mouseY;\r\n this.targetScreenOffset.x -= shiftX;\r\n this.targetScreenOffset.y += shiftY;\r\n }\r\n }\r\n }\r\n\r\n updateClient() {\r\n const canvas = this.getEngine().getRenderingCanvas();\r\n if (!canvas) {\r\n return;\r\n }\r\n\r\n const clientRect = canvas.getBoundingClientRect();\r\n this.clientInfo.screenWidth = clientRect.width;\r\n this.clientInfo.screenHeight = clientRect.height;\r\n this.clientInfo.screenLeft = clientRect.left;\r\n this.clientInfo.screenTop = clientRect.top;\r\n\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n this.updateOrthographicPosition();\r\n\r\n this.panningSensibility = clientRect.width;\r\n } else {\r\n const focalLength = clientRect.height / (2 * Math.tan(this.fov / 2));\r\n this.panningSensibility = focalLength;\r\n }\r\n\r\n return canvas;\r\n }\r\n\r\n attachControl(noPreventDefault = false) {\r\n super.attachControl(noPreventDefault, true);\r\n if (this.disposeListeners) {\r\n this.disposeListeners();\r\n }\r\n\r\n const updateMousePosition = (event: MouseEvent) => {\r\n this.clientInfo.mouseX =\r\n ((event.clientX - this.clientInfo.screenLeft) * 2) / this.clientInfo.screenWidth - 1;\r\n this.clientInfo.mouseY =\r\n ((event.clientY - this.clientInfo.screenTop) * 2) / this.clientInfo.screenHeight - 1;\r\n };\r\n const canvas = this.updateClient();\r\n const updateClientWrap = () => this.updateClient();\r\n\r\n if (canvas) {\r\n window.addEventListener('resize', updateClientWrap);\r\n canvas.addEventListener('mousemove', updateMousePosition);\r\n\r\n this.disposeListeners = () => {\r\n window.removeEventListener('resize', updateClientWrap);\r\n canvas.removeEventListener('mousemove', updateMousePosition);\r\n this.disposeListeners = undefined;\r\n };\r\n }\r\n }\r\n\r\n _checkLimits() {\r\n super._checkLimits();\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n this.orthoWidth = this.clampOrthoWidth(this.orthoWidth);\r\n }\r\n }\r\n\r\n private clampOrthoWidth(val: number) {\r\n if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n if (this.lowerRadiusLimit != null && val < this.lowerRadiusLimit) {\r\n val = this.lowerRadiusLimit;\r\n }\r\n if (this.upperRadiusLimit != null && val > this.upperRadiusLimit) {\r\n val = this.upperRadiusLimit;\r\n }\r\n }\r\n\r\n return val;\r\n }\r\n\r\n dispose() {\r\n super.dispose();\r\n if (this.disposeListeners) {\r\n this.disposeListeners();\r\n }\r\n }\r\n\r\n private updateOrthographicPosition() {\r\n if (this.clientInfo) {\r\n const ratio = this.clientInfo.screenHeight / this.clientInfo.screenWidth;\r\n this.orthoRight = this.orthoWidth / 2;\r\n this.orthoLeft = -this.orthoWidth / 2;\r\n this.orthoTop = (this.orthoWidth * ratio) / 2;\r\n this.orthoBottom = (-this.orthoWidth * ratio) / 2;\r\n }\r\n }\r\n}\r\n","import { Animatable } from '@babylonjs/core/Animations/animatable';\r\nimport { Animation } from '@babylonjs/core/Animations/animation';\r\nimport { CircleEase, SineEase } from '@babylonjs/core/Animations/easing';\r\nimport { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';\r\nimport { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { FreeCamera } from '@babylonjs/core/Cameras/freeCamera';\r\nimport { UniversalCamera } from '@babylonjs/core/Cameras/universalCamera';\r\nimport { BoundingSphere } from '@babylonjs/core/Culling/boundingSphere';\r\nimport { Plane, Vector2, Vector3 } from '@babylonjs/core/Maths';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { PostProcessRenderPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/postProcessRenderPipeline';\r\nimport { WebXRCamera } from '@babylonjs/core/XR/webXRCamera';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { AnnotationNode, DimensionNode } from '@models/classes/annotations';\r\nimport { defaults } from '@models/classes/default-values';\r\nimport { eViewpointProjection, eViewpointTargetMode, eViewpointType } from '@models/classes/enums';\r\nimport { MeshNode, SpaceNode } from '@models/classes/meshes';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { ViewpointNode } from '@models/classes/viewpoints/viewpoint-node';\r\nimport { getCameraPositionWithOffset, toRadians } from '@view/helpers/math-helper';\r\nimport { AnnotationInfo, SKYBOX_SIZE } from '@view/render';\r\nimport { Observable, Subject } from 'rxjs';\r\nimport { finalize, share, startWith, takeUntil } from 'rxjs/operators';\r\nimport { getScreenBoundingBox, nodeToScreen } from '../helpers/scene-helper';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport { KbArcRotateCamera } from './cameras/kb-arc-rotate-camera';\r\n\r\nconst ANIMATION_FPS = 30;\r\n\r\nenum eCameraType {\r\n Universal,\r\n ArcRotate,\r\n}\r\n\r\nexport interface ICameraAnimationOptions {\r\n duration: number;\r\n frame?: boolean;\r\n frameOptions?: Partial;\r\n frameTarget?: SpaceNode;\r\n}\r\n\r\nexport interface IFramingOptions {\r\n rotate: boolean;\r\n pan: boolean;\r\n zoom: boolean;\r\n padding: number;\r\n}\r\n\r\nexport enum eCameraOrientation {\r\n perspective = 'perspective',\r\n front = 'front',\r\n left = 'left',\r\n back = 'back',\r\n right = 'right',\r\n top = 'top',\r\n bottom = 'bottom',\r\n}\r\n\r\ntype ScalingHandler = (distance: number, type: number) => void;\r\n\r\nexport class CameraTools {\r\n get cameraMoving() {\r\n const camera = this.scene.activeCamera;\r\n if (this._activeAnimation) {\r\n return true;\r\n }\r\n if (camera instanceof KbArcRotateCamera) {\r\n return (\r\n Math.abs(camera.inertialRadiusOffset) > 0 ||\r\n Math.abs(camera.inertialAlphaOffset) > 0 ||\r\n Math.abs(camera.inertialBetaOffset) > 0 ||\r\n Math.abs(camera.inertialOffsetPanningX) > 0 ||\r\n Math.abs(camera.inertialOffsetPanningY) > 0 ||\r\n Math.abs(camera.inertialOrthoZoom) > 0\r\n );\r\n }\r\n if (camera instanceof UniversalCamera) {\r\n return (\r\n Math.abs(camera.cameraDirection.x) > 0 ||\r\n Math.abs(camera.cameraDirection.y) > 0 ||\r\n Math.abs(camera.cameraDirection.z) > 0 ||\r\n Math.abs(camera.cameraRotation.x) > 0 ||\r\n Math.abs(camera.cameraRotation.y) > 0\r\n );\r\n }\r\n return false;\r\n }\r\n\r\n public activeCamera: Partial;\r\n\r\n private _cameraSettingsChange?: Subject>;\r\n private _beforeRender: () => void;\r\n private _storedViewpoint?: ViewpointNode;\r\n private _activeAnimation?: Animatable;\r\n private disposePreviousCamera: Subject | undefined;\r\n private _lastOrientation = eCameraOrientation.perspective;\r\n private _lastPerspectivePosition: KbVector;\r\n private minVector = new Vector3(0, 0, 0);\r\n private maxVector = new Vector3(0, 0, 0);\r\n private activePipeline: PostProcessRenderPipeline | undefined;\r\n\r\n private objectsToScaleWithDistance = new Map();\r\n\r\n constructor(private scene: Scene, private canvas: HTMLElement, private kbViewer: KbViewer) {\r\n this._beforeRender = () => {\r\n if (this._cameraSettingsChange && scene.activeCamera && this.cameraMoving) {\r\n const camera = scene.activeCamera as KbArcRotateCamera | UniversalCamera;\r\n const changeList: Partial = {};\r\n copyCameraStateIntoViewpoint(changeList, camera);\r\n\r\n this._cameraSettingsChange.next(changeList);\r\n }\r\n };\r\n scene.registerBeforeRender(this._beforeRender);\r\n\r\n kbViewer.viewChanged.subscribe(() => {\r\n const camera = scene.activeCamera;\r\n if (camera) {\r\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n const dist = ((camera.orthoRight || 0) - (camera.orthoLeft || 0)) * 0.6;\r\n this.objectsToScaleWithDistance.forEach((param, item) => {\r\n if (item.isDisposed()) {\r\n this.objectsToScaleWithDistance.delete(item);\r\n return;\r\n }\r\n if (typeof param === 'function') {\r\n param(dist, camera.mode);\r\n } else {\r\n const scaledSize = param * dist;\r\n item.scaling.set(scaledSize, scaledSize, scaledSize);\r\n }\r\n });\r\n } else {\r\n let cameraPosition: Vector3;\r\n if (camera instanceof WebXRCamera && camera.globalPosition) {\r\n cameraPosition = camera.globalPosition;\r\n } else if (camera instanceof ArcRotateCamera) {\r\n cameraPosition = getCameraPositionWithOffset(camera);\r\n } else {\r\n cameraPosition = camera.globalPosition;\r\n }\r\n this.objectsToScaleWithDistance.forEach((param, item) => {\r\n if (item.isDisposed()) {\r\n this.objectsToScaleWithDistance.delete(item);\r\n return;\r\n }\r\n const dist = item.absolutePosition.subtract(cameraPosition).length();\r\n if (typeof param === 'function') {\r\n param(dist, camera.mode);\r\n } else {\r\n const scaledSize = dist * param;\r\n item.scaling.set(scaledSize, scaledSize, scaledSize);\r\n }\r\n });\r\n }\r\n }\r\n });\r\n\r\n this.activeCamera = {\r\n get position() {\r\n return scene.activeCamera ? KbVector.FromVec3(scene.activeCamera.position) : KbVector.Zero();\r\n },\r\n set position(vector: KbVector) {\r\n if (scene.activeCamera) {\r\n if (\r\n scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA &&\r\n scene.activeCamera instanceof ArcRotateCamera\r\n ) {\r\n const target = scene.activeCamera.target;\r\n scene.activeCamera.position = vector\r\n .toVec3()\r\n .subtract(target)\r\n .normalize()\r\n .scale(5000)\r\n .add(target);\r\n } else {\r\n scene.activeCamera.position = vector.toVec3();\r\n }\r\n }\r\n },\r\n get targetPoint() {\r\n return scene.activeCamera instanceof ArcRotateCamera\r\n ? KbVector.FromVec3(scene.activeCamera.target)\r\n : KbVector.Zero();\r\n },\r\n set targetPoint(vector: KbVector) {\r\n scene.activeCamera instanceof ArcRotateCamera && (scene.activeCamera.target = vector.toVec3());\r\n },\r\n get rotation() {\r\n return scene.activeCamera instanceof UniversalCamera\r\n ? KbVector.FromVec3(scene.activeCamera.rotation)\r\n : KbVector.Zero();\r\n },\r\n set rotation(vector: KbVector) {\r\n scene.activeCamera instanceof UniversalCamera && (scene.activeCamera.rotation = vector.toVec3());\r\n },\r\n get offsetX() {\r\n return scene.activeCamera instanceof ArcRotateCamera ? scene.activeCamera.targetScreenOffset!.x : 0;\r\n },\r\n set offsetX(offset: number) {\r\n scene.activeCamera instanceof ArcRotateCamera && (scene.activeCamera.targetScreenOffset.x = offset);\r\n },\r\n get offsetY() {\r\n return scene.activeCamera instanceof ArcRotateCamera ? scene.activeCamera.targetScreenOffset!.y : 0;\r\n },\r\n set offsetY(offset: number) {\r\n scene.activeCamera instanceof ArcRotateCamera && (scene.activeCamera.targetScreenOffset.y = offset);\r\n },\r\n get projection() {\r\n if (!scene.activeCamera) {\r\n return undefined;\r\n }\r\n return scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA\r\n ? eViewpointProjection.perspective\r\n : eViewpointProjection.orthographic;\r\n },\r\n set projection(projection: eViewpointProjection | undefined) {\r\n scene.activeCamera &&\r\n (scene.activeCamera.mode =\r\n projection === eViewpointProjection.perspective\r\n ? Camera.PERSPECTIVE_CAMERA\r\n : Camera.ORTHOGRAPHIC_CAMERA);\r\n },\r\n get fov() {\r\n if (!scene.activeCamera) {\r\n return 50;\r\n }\r\n return scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA\r\n ? scene.activeCamera.orthoRight! - scene.activeCamera.orthoLeft!\r\n : (scene.activeCamera.fov * 180) / Math.PI;\r\n },\r\n set fov(fov: number) {\r\n if (!scene.activeCamera) {\r\n return;\r\n }\r\n if (\r\n scene.activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA &&\r\n scene.activeCamera instanceof KbArcRotateCamera\r\n ) {\r\n scene.activeCamera.orthoWidth = fov;\r\n } else {\r\n scene.activeCamera.fov = (fov * Math.PI) / 180;\r\n }\r\n },\r\n get allowOrbit() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return !scene.activeCamera.lockRotation;\r\n } else if (scene.activeCamera instanceof UniversalCamera) {\r\n return !!scene.activeCamera.inputs.attached.mouse;\r\n }\r\n return false;\r\n },\r\n set allowOrbit(allow) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.lockRotation = !allow;\r\n } else if (scene.activeCamera instanceof UniversalCamera) {\r\n scene.activeCamera.inputs.clear();\r\n enableFreeLook(scene.activeCamera);\r\n }\r\n },\r\n get allowPan() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return !scene.activeCamera.lockPanning;\r\n } else if (scene.activeCamera instanceof UniversalCamera) {\r\n return !!scene.activeCamera.inputs.attached.keyboard;\r\n }\r\n return false;\r\n },\r\n set allowPan(allow) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.lockPanning = !allow;\r\n } else if (scene.activeCamera instanceof UniversalCamera) {\r\n scene.activeCamera.inputs.clear();\r\n enableFreeMove(scene.activeCamera);\r\n }\r\n },\r\n get allowZoom() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return !scene.activeCamera.lockZoom;\r\n }\r\n return false;\r\n },\r\n set allowZoom(allow) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.lockZoom = !allow;\r\n }\r\n },\r\n get limitMinimumTargetDistance() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return scene.activeCamera.limitMinimumTargetDistance;\r\n }\r\n return false;\r\n },\r\n set limitMinimumTargetDistance(allow) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.limitMinimumTargetDistance = !allow;\r\n }\r\n },\r\n get minTargetDistance() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return scene.activeCamera.lowerRadiusLimit || defaults.ViewpointNode.minTargetDistance;\r\n }\r\n return defaults.ViewpointNode.minTargetDistance;\r\n },\r\n set minTargetDistance(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.lowerRadiusLimit = value;\r\n }\r\n },\r\n get maxTargetDistance() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return scene.activeCamera.upperRadiusLimit || defaults.ViewpointNode.maxTargetDistance;\r\n }\r\n return defaults.ViewpointNode.maxTargetDistance;\r\n },\r\n set maxTargetDistance(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.upperRadiusLimit = value;\r\n }\r\n },\r\n\r\n get orbitAxis() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return KbVector.FromVec3(scene.activeCamera.upVector);\r\n }\r\n return KbVector.From(defaults.ViewpointNode.orbitAxis);\r\n },\r\n set orbitAxis(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.upVector = value.toVec3();\r\n }\r\n },\r\n\r\n get limitMinLatitude() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return ((scene.activeCamera.lowerBetaLimit || 0) * 180) / Math.PI;\r\n }\r\n return defaults.ViewpointNode.limitMinLatitude;\r\n },\r\n set limitMinLatitude(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.lowerBetaLimit = (value * Math.PI) / 180;\r\n }\r\n },\r\n get limitMaxLatitude() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return (\r\n ((typeof scene.activeCamera.upperBetaLimit === 'number'\r\n ? scene.activeCamera.upperBetaLimit\r\n : Math.PI) *\r\n 180) /\r\n Math.PI\r\n );\r\n }\r\n return defaults.ViewpointNode.limitMaxLatitude;\r\n },\r\n set limitMaxLatitude(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.upperBetaLimit = (value * Math.PI) / 180;\r\n }\r\n },\r\n get limitMinLongitude() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return scene.activeCamera.lowerAlphaLimit\r\n ? (scene.activeCamera.lowerAlphaLimit * 180) / Math.PI\r\n : defaults.ViewpointNode.limitMinLongitude;\r\n }\r\n return defaults.ViewpointNode.limitMinLongitude;\r\n },\r\n set limitMinLongitude(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.lowerAlphaLimit = (value * Math.PI) / 180;\r\n }\r\n },\r\n get limitMaxLongitude() {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n return scene.activeCamera.upperAlphaLimit\r\n ? (scene.activeCamera.upperAlphaLimit * 180) / Math.PI\r\n : defaults.ViewpointNode.limitMinLongitude;\r\n }\r\n return defaults.ViewpointNode.limitMinLongitude;\r\n },\r\n set limitMaxLongitude(value) {\r\n if (scene.activeCamera instanceof KbArcRotateCamera) {\r\n scene.activeCamera.upperAlphaLimit = (value * Math.PI) / 180;\r\n }\r\n },\r\n };\r\n }\r\n\r\n dispose() {\r\n this.scene.unregisterBeforeRender(this._beforeRender);\r\n }\r\n\r\n setPipeline(pipeline: PostProcessRenderPipeline) {\r\n this.activePipeline = pipeline;\r\n if (this.scene.activeCamera) {\r\n this.applyScenePostProcesses(this.scene.activeCamera);\r\n }\r\n }\r\n\r\n /** Frames the current active camera to fit the provided mesh node\r\n * @param node The node to fit on the screen\r\n * @param padding If provided, pads the node by a percentage of the node's size.\r\n */\r\n frameCamera(node: SpaceNode, options?: Partial, camera?: Camera) {\r\n const _options: IFramingOptions = {\r\n rotate: false,\r\n pan: true,\r\n padding: 1,\r\n zoom: true,\r\n ...(options || {}),\r\n };\r\n const activeCamera = camera || this.scene.activeCamera;\r\n if (!activeCamera) {\r\n throw Error('No active camera');\r\n }\r\n\r\n const bounding = this.kbViewer.bbCache.getWorld(node);\r\n\r\n if (!bounding || bounding.boundingInfo.diagonalLength === 0) {\r\n return; // no op if the bounding box doesn't exist\r\n } else {\r\n const childrenBounding = this.kbViewer.sceneNode.getChildren();\r\n const maxVector = bounding.boundingInfo.boundingBox.maximum;\r\n const minVector = bounding.boundingInfo.boundingBox.minimum;\r\n childrenBounding.forEach(element => {\r\n if (\r\n (element instanceof AnnotationNode && element.enabled) ||\r\n (element instanceof DimensionNode && element.enabled)\r\n ) {\r\n let nodeInfo: AnnotationInfo | undefined;\r\n if (element instanceof AnnotationNode) {\r\n nodeInfo = this.kbViewer.rendererManager.annotation.annotationStore.get(element._dynamicId);\r\n }\r\n if (element instanceof DimensionNode) {\r\n nodeInfo = this.kbViewer.rendererManager.dimension.dimensionStore.get(element._dynamicId);\r\n }\r\n const minBoundingBox = nodeInfo?.meshInfo?.textContainer.getHierarchyBoundingVectors().min;\r\n const maxBoundingBox = nodeInfo?.meshInfo?.textContainer.getHierarchyBoundingVectors().max;\r\n if (minBoundingBox && minBoundingBox.x < minVector.x) {\r\n minVector.x = minBoundingBox.x;\r\n }\r\n if (minBoundingBox && minBoundingBox.y < minVector.y) {\r\n minVector.y = minBoundingBox.y;\r\n }\r\n if (minBoundingBox && minBoundingBox.z < minVector.z) {\r\n minVector.z = minBoundingBox.z;\r\n }\r\n if (maxBoundingBox && maxBoundingBox.x > maxVector.x) {\r\n maxVector.x = maxBoundingBox.x;\r\n }\r\n if (maxBoundingBox && maxBoundingBox.y > maxVector.y) {\r\n maxVector.y = maxBoundingBox.y;\r\n }\r\n if (maxBoundingBox && maxBoundingBox.z > maxVector.z) {\r\n maxVector.z = maxBoundingBox.z;\r\n }\r\n }\r\n });\r\n this.minVector.set(minVector.x, minVector.y, minVector.z);\r\n\r\n this.maxVector.set(maxVector.x, maxVector.y, maxVector.z);\r\n\r\n bounding.boundingInfo.boundingBox.reConstruct(\r\n this.minVector,\r\n this.maxVector,\r\n bounding.boundingInfo.boundingBox.getWorldMatrix()\r\n );\r\n const bbCenter = bounding.center.toVec3();\r\n\r\n const bbCorners = bounding.boundingInfo.boundingBox.vectorsWorld;\r\n\r\n if (activeCamera instanceof UniversalCamera) {\r\n activeCamera.setTarget(bbCenter);\r\n } else if (activeCamera instanceof KbArcRotateCamera) {\r\n if (_options.rotate) {\r\n activeCamera.setTarget(bbCenter);\r\n if (_options.pan) {\r\n activeCamera.targetScreenOffset.set(0, 0);\r\n }\r\n } else if (_options.pan) {\r\n const cameraRay = activeCamera.getForwardRay();\r\n const cameraProjectionTargetPlane = Plane.FromPositionAndNormal(bbCenter, cameraRay.direction);\r\n const cameraDistance = cameraRay.intersectsPlane(cameraProjectionTargetPlane);\r\n const cameraProjectionTargetPoint = cameraRay.origin.add(\r\n cameraRay.direction.scale(cameraDistance!)\r\n );\r\n const cameraPositionWorldOffset = cameraProjectionTargetPoint.subtract(bbCenter);\r\n\r\n const planeProjectionX = Vector3.Cross(cameraRay.direction, Vector3.Up()).normalize();\r\n const planeProjectionY = Vector3.Cross(cameraRay.direction, planeProjectionX).normalize();\r\n\r\n const bbCenterOffset = new Vector2(\r\n Vector3.Dot(cameraPositionWorldOffset, planeProjectionX),\r\n -Vector3.Dot(cameraPositionWorldOffset, planeProjectionY)\r\n );\r\n activeCamera.targetScreenOffset.copyFrom(bbCenterOffset);\r\n }\r\n\r\n if (_options.zoom) {\r\n const clientRect = this.canvas.getBoundingClientRect();\r\n const ratio = clientRect.height / clientRect.width;\r\n const cameraRay = activeCamera.getForwardRay();\r\n const xAxis = Vector3.Cross(cameraRay.direction, Vector3.Up()).normalize();\r\n const yAxis = Vector3.Cross(cameraRay.direction, xAxis).normalize();\r\n const cameraTruePosition = cameraRay.origin\r\n .add(xAxis.scale(-activeCamera.targetScreenOffset.x))\r\n .add(yAxis.scale(activeCamera.targetScreenOffset.y));\r\n const cameraTrueTarget = activeCamera.target\r\n .add(xAxis.scale(-activeCamera.targetScreenOffset.x))\r\n .add(yAxis.scale(activeCamera.targetScreenOffset.y));\r\n const xPlane = Plane.FromPositionAndNormal(cameraTruePosition, yAxis);\r\n const yPlane = Plane.FromPositionAndNormal(cameraTruePosition, xAxis);\r\n const padding = 1 + _options.padding / 100;\r\n\r\n if (activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n let maxX = 0,\r\n maxY = 0;\r\n bbCorners.forEach(bbCorner => {\r\n const xO = xPlane.signedDistanceTo(bbCorner) * padding;\r\n maxX = Math.max(maxX, Math.abs(xO));\r\n\r\n const yO = yPlane.signedDistanceTo(bbCorner) * padding;\r\n maxY = Math.max(maxY, Math.abs(yO));\r\n });\r\n\r\n // The calculated distance is the maximum distance from the centerline to the bounding box corner. So double it to get the total width/height\r\n activeCamera.orthoFit(maxY * 2, maxX * 2);\r\n } else {\r\n let desiredDistance = 0;\r\n const fovH = 2 * Math.atan(Math.tan(activeCamera.fov / 2) / ratio);\r\n const thV = Math.tan(activeCamera.fov / 2);\r\n const thH = Math.tan(fovH / 2);\r\n bbCorners.forEach(bbCorner => {\r\n const xO = xPlane.signedDistanceTo(bbCorner) * padding;\r\n const xP = bbCorner.subtract(cameraTrueTarget).subtract(yAxis.scale(xO));\r\n const xA = Math.abs(xO) / thV;\r\n const xR = Vector3.Dot(xP, cameraRay.direction.scale(-1)) + xA;\r\n desiredDistance = Math.max(desiredDistance, xR);\r\n\r\n const yO = yPlane.signedDistanceTo(bbCorner) * padding;\r\n const yP = bbCorner.subtract(cameraTrueTarget).subtract(xAxis.scale(yO));\r\n const yA = Math.abs(yO) / thH;\r\n const yR = Vector3.Dot(yP, cameraRay.direction.scale(-1)) + yA;\r\n desiredDistance = Math.max(desiredDistance, yR);\r\n });\r\n\r\n activeCamera.radius = Math.max(desiredDistance, 0.001);\r\n }\r\n }\r\n }\r\n this.kbViewer.fireViewChangedOnNextRender(); //render loop won't pick up that the view changed, because no kb3d nodes changes, so we must update it explicitly\r\n }\r\n }\r\n\r\n getScreenPositionOfNode(node: MeshNode) {\r\n if (!this.scene.activeCamera) {\r\n throw Error('No active camera');\r\n }\r\n const bNode = this.kbViewer.getRendererNode(node);\r\n\r\n if (bNode) {\r\n return nodeToScreen(bNode, this.scene.activeCamera);\r\n }\r\n }\r\n\r\n getScreenBoundingBoxOfNode(node: MeshNode) {\r\n if (!this.scene.activeCamera) {\r\n throw Error('No active camera');\r\n }\r\n const bNode = this.kbViewer.getRendererNode(node);\r\n if (bNode) {\r\n return getScreenBoundingBox(bNode, this.scene.activeCamera, true);\r\n }\r\n }\r\n\r\n moveCameraToViewpoint(viewpoint: ViewpointNode) {\r\n const newCamera = this.createCameraFromViewpoint(viewpoint)!;\r\n this._activateCamera(newCamera);\r\n }\r\n\r\n animateToViewpoint(viewpoint: ViewpointNode, options?: Partial) {\r\n if (!this.scene.activeCamera) {\r\n throw Error('No active camera');\r\n }\r\n let activeCamera = this.scene.activeCamera;\r\n const _options: ICameraAnimationOptions = {\r\n duration: 1000,\r\n ...(options || {}),\r\n };\r\n const endFrame = 30 * (_options.duration / 1000);\r\n const animations: Animation[] = [];\r\n const ease = new SineEase();\r\n ease.setEasingMode(SineEase.EASINGMODE_EASEINOUT);\r\n const circEaseOut = new CircleEase();\r\n circEaseOut.setEasingMode(CircleEase.EASINGMODE_EASEOUT);\r\n\r\n // Create the new viewpoint converted to an arc rotate camera so we can tween arc rotate properties\r\n // The arc rotate cameras are easier to animate between nicely.\r\n const newCameraTarget = this.createCameraFromViewpoint(viewpoint, eCameraType.ArcRotate)!;\r\n const newCamera = this.createCameraFromViewpoint(viewpoint)!;\r\n\r\n if (_options.frame && newCamera instanceof ArcRotateCamera) {\r\n const target = _options.frameTarget || viewpoint._parentScene;\r\n if (!target) {\r\n throw Error('Cannot frame camera, no target node to frame');\r\n } else {\r\n this.frameCamera(target, _options.frameOptions || {}, newCameraTarget);\r\n this.frameCamera(target, _options.frameOptions || {}, newCamera);\r\n }\r\n }\r\n if (activeCamera instanceof ArcRotateCamera) {\r\n if (Math.abs(activeCamera.alpha) > Math.PI * 2) {\r\n activeCamera.alpha = activeCamera.alpha % (Math.PI * 2);\r\n }\r\n }\r\n if (activeCamera instanceof UniversalCamera && viewpoint.type != eViewpointType.firstPerson) {\r\n const orbitRotation = activeCamera.rotationQuaternion\r\n ? activeCamera.rotationQuaternion.toEulerAngles()\r\n : activeCamera.rotation;\r\n const ray = activeCamera.getForwardRay(newCameraTarget.radius);\r\n // If the current camera is a universal camera, convert it to an arc rotate camera as well/\r\n // The arc rotate target position is placed from the camera at the same distance as the destination viewpoint's target\r\n activeCamera = new KbArcRotateCamera(\r\n 'temporaryCamera',\r\n -(orbitRotation.y + Math.PI / 2),\r\n Math.PI / 2 - orbitRotation.x,\r\n ray.length,\r\n ray.direction.scale(ray.length).add(ray.origin),\r\n this.scene\r\n );\r\n activeCamera.fov = this.scene.activeCamera.fov;\r\n this._activateCamera(activeCamera);\r\n }\r\n\r\n if (!newCameraTarget) {\r\n throw Error('Could not create new camera');\r\n }\r\n\r\n if (activeCamera instanceof UniversalCamera && viewpoint.type === eViewpointType.firstPerson) {\r\n const targetRotation = new Vector3(0, 0, 0);\r\n const targetPosition = new Vector3(viewpoint.position.x, viewpoint.position.y, viewpoint.position.z);\r\n targetRotation.y = (viewpoint.rotation.y * Math.PI) / 180;\r\n targetRotation.x = (viewpoint.rotation.x * Math.PI) / 180;\r\n targetRotation.z = (viewpoint.rotation.z * Math.PI) / 180;\r\n\r\n let activeAlpha = activeCamera.rotation.y;\r\n let targetAlpha = (viewpoint.rotation.y * Math.PI) / 180;\r\n let arc = 0;\r\n\r\n //Normalizing values to be between -PI and PI\r\n activeAlpha = normalizeRotation(activeAlpha);\r\n targetAlpha = normalizeRotation(targetAlpha);\r\n\r\n //calculating shortest arc and seeing if it crosses zero\r\n //if it does, change the target vector to account for expected direction of animation\r\n if (activeAlpha > targetAlpha) {\r\n arc = activeAlpha - targetAlpha;\r\n } else {\r\n arc = targetAlpha - activeAlpha;\r\n }\r\n if (arc > Math.PI) {\r\n if (activeAlpha < targetAlpha) {\r\n targetRotation.y = targetRotation.y - 2 * Math.PI;\r\n } else {\r\n targetRotation.y = targetRotation.y + 2 * Math.PI;\r\n }\r\n }\r\n\r\n const translateRotation = new Animation(\r\n 'translateCameraRotation',\r\n 'rotation',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_VECTOR3,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateRotation.setKeys([\r\n { frame: 0, value: activeCamera.rotation },\r\n { frame: endFrame, value: targetRotation },\r\n ]);\r\n\r\n const translatePosition = new Animation(\r\n 'translateCameraPosition',\r\n 'position',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_VECTOR3,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translatePosition.setKeys([\r\n { frame: 0, value: activeCamera.position },\r\n { frame: endFrame, value: targetPosition },\r\n ]);\r\n const translateFov = new Animation(\r\n 'translateCameraFOV',\r\n 'fov',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateFov.setKeys([\r\n { frame: 0, value: activeCamera.fov },\r\n { frame: endFrame, value: (viewpoint.fov / 180) * Math.PI },\r\n ]);\r\n translateRotation.setEasingFunction(ease);\r\n translatePosition.setEasingFunction(ease);\r\n translateFov.setEasingFunction(ease);\r\n\r\n animations.push(translateRotation);\r\n animations.push(translatePosition);\r\n animations.push(translateFov);\r\n } else if (newCameraTarget instanceof ArcRotateCamera && activeCamera instanceof ArcRotateCamera) {\r\n // When rotating between two arc rotate cameras, rotate around the target while animating the target\r\n\r\n if (!activeCamera.target.equals(newCameraTarget.target)) {\r\n const translateTarget = new Animation(\r\n 'translateCameraTarget',\r\n 'target',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_VECTOR3,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateTarget.setKeys([\r\n { frame: 0, value: activeCamera.target },\r\n { frame: endFrame, value: newCameraTarget.target },\r\n ]);\r\n animations.push(translateTarget);\r\n }\r\n\r\n const translateA = new Animation(\r\n 'translateCameraA',\r\n 'alpha',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n\r\n let crossesZero = false;\r\n let arc = 0;\r\n let shortestArc = 0;\r\n\r\n //Normalizing values to be between -PI and PI\r\n activeCamera.alpha = normalizeRotation(activeCamera.alpha);\r\n newCameraTarget.alpha = normalizeRotation(newCameraTarget.alpha);\r\n\r\n //calculating shortest arc between two cameras\r\n if (activeCamera.alpha > newCameraTarget.alpha) {\r\n arc = activeCamera.alpha - newCameraTarget.alpha;\r\n } else {\r\n arc = newCameraTarget.alpha - activeCamera.alpha;\r\n }\r\n if (arc > Math.PI) {\r\n shortestArc = 2 * Math.PI - arc;\r\n crossesZero = true;\r\n }\r\n\r\n //altering newCameraTarget to take shortest path\r\n if (newCameraTarget.alpha > 0 && crossesZero) {\r\n newCameraTarget.alpha = activeCamera.alpha - shortestArc;\r\n } else if (newCameraTarget.alpha < 0 && crossesZero) {\r\n newCameraTarget.alpha = activeCamera.alpha + shortestArc;\r\n }\r\n\r\n translateA.setKeys([\r\n { frame: 0, value: activeCamera.alpha },\r\n { frame: endFrame, value: newCameraTarget.alpha },\r\n ]);\r\n const translateB = new Animation(\r\n 'translateCameraB',\r\n 'beta',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateB.setKeys([\r\n { frame: 0, value: activeCamera.beta },\r\n { frame: endFrame, value: newCameraTarget.beta },\r\n ]);\r\n const translateR = new Animation(\r\n 'translateCameraR',\r\n 'radius',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateR.setKeys([\r\n { frame: 0, value: activeCamera.radius },\r\n { frame: endFrame, value: newCameraTarget.radius },\r\n ]);\r\n const translateOffset = new Animation(\r\n 'translateCameraOffset',\r\n 'targetScreenOffset',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_VECTOR2,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateOffset.setKeys([\r\n { frame: 0, value: activeCamera.targetScreenOffset },\r\n { frame: endFrame, value: newCameraTarget.targetScreenOffset },\r\n ]);\r\n const translateFov = new Animation(\r\n 'translateCameraFOV',\r\n 'fov',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateFov.setKeys([\r\n { frame: 0, value: activeCamera.fov },\r\n { frame: endFrame, value: newCameraTarget.fov },\r\n ]);\r\n if (\r\n activeCamera instanceof KbArcRotateCamera &&\r\n activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA &&\r\n newCameraTarget.mode === Camera.ORTHOGRAPHIC_CAMERA\r\n ) {\r\n const translateOrthoWidth = new Animation(\r\n 'translateOrthoWidth',\r\n 'orthoWidth',\r\n ANIMATION_FPS,\r\n Animation.ANIMATIONTYPE_FLOAT,\r\n Animation.ANIMATIONLOOPMODE_CONSTANT\r\n );\r\n translateOrthoWidth.setKeys([\r\n { frame: 0, value: activeCamera.orthoWidth },\r\n { frame: endFrame, value: newCameraTarget.orthoWidth },\r\n ]);\r\n translateOrthoWidth.setEasingFunction(ease);\r\n\r\n animations.push(translateOrthoWidth);\r\n }\r\n\r\n translateA.setEasingFunction(ease);\r\n translateB.setEasingFunction(ease);\r\n translateR.setEasingFunction(ease);\r\n translateOffset.setEasingFunction(ease);\r\n translateFov.setEasingFunction(circEaseOut);\r\n\r\n animations.push(translateA);\r\n animations.push(translateB);\r\n animations.push(translateR);\r\n animations.push(translateOffset);\r\n animations.push(translateFov);\r\n }\r\n\r\n animations.forEach(animation => {\r\n activeCamera.animations.push(animation);\r\n });\r\n\r\n return new Promise(resolve => {\r\n this._activeAnimation = this.scene.beginAnimation(activeCamera, 0, endFrame, false, 1, () => {\r\n // on end of animation\r\n delete this._activeAnimation;\r\n\r\n this._activateCamera(newCamera);\r\n resolve();\r\n });\r\n });\r\n }\r\n\r\n storeCameraSettings() {\r\n if (!this.scene.activeCamera) {\r\n throw Error('No active camera');\r\n }\r\n this._storedViewpoint = new ViewpointNode();\r\n const camera = this.scene.activeCamera as KbArcRotateCamera | UniversalCamera;\r\n\r\n copyCameraStateIntoViewpoint(this._storedViewpoint, camera);\r\n }\r\n\r\n restoreCameraSettings() {\r\n if (this._storedViewpoint) {\r\n this.moveCameraToViewpoint(this._storedViewpoint);\r\n } else {\r\n console.warn('No stored camera settings to restore');\r\n }\r\n }\r\n\r\n watch(): Observable> {\r\n this._cameraSettingsChange = new Subject();\r\n\r\n return this._cameraSettingsChange.pipe(\r\n finalize(() => {\r\n delete this._cameraSettingsChange;\r\n }),\r\n share()\r\n );\r\n }\r\n\r\n maintainNodeScreenSize(renderedNode: TransformNode, relativeSize: number | ScalingHandler) {\r\n this.objectsToScaleWithDistance.set(renderedNode, relativeSize);\r\n }\r\n\r\n clearMaintainedNodeScreenSize(renderedNode: TransformNode) {\r\n this.objectsToScaleWithDistance.delete(renderedNode);\r\n }\r\n\r\n private _activateCamera(newCamera: Camera) {\r\n this.scene.cameras.forEach(camera => {\r\n if (camera !== newCamera) {\r\n /**\r\n * Don't dispose the whole camera because that goes too hard and disposes all the render target textures and\r\n * post processes which messes things up for the next camera that's reusing those things. Instead, just dispose the\r\n * parts of the camera we don't need.\r\n */\r\n camera.onViewMatrixChangedObservable.clear();\r\n camera.onProjectionMatrixChangedObservable.clear();\r\n camera.onAfterCheckInputsObservable.clear();\r\n camera.onRestoreStateObservable.clear();\r\n\r\n // Inputs\r\n if (camera.inputs) {\r\n camera.inputs.clear();\r\n }\r\n\r\n // Animations\r\n this.scene.stopAnimation(camera);\r\n\r\n // Remove from scene\r\n this.scene.removeCamera(camera);\r\n\r\n this.scene.getEngine().releaseRenderPassId(camera.renderPassId);\r\n }\r\n });\r\n this.scene.customRenderTargets.forEach(rtt => {\r\n rtt.activeCamera = newCamera;\r\n });\r\n this.applyScenePostProcesses(newCamera);\r\n newCamera!.attachControl(false);\r\n this.scene.activeCamera = newCamera;\r\n }\r\n\r\n private applyScenePostProcesses(camera: Camera) {\r\n if (this.activePipeline) {\r\n this.scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this.activePipeline.name, camera);\r\n }\r\n }\r\n\r\n private createCameraFromViewpoint(\r\n viewpoint: ViewpointNode,\r\n convertToCameraType: eCameraType.Universal\r\n ): Nullable;\r\n private createCameraFromViewpoint(\r\n viewpoint: ViewpointNode,\r\n convertToCameraType: eCameraType.ArcRotate\r\n ): Nullable;\r\n private createCameraFromViewpoint(viewpoint: ViewpointNode, convertToCameraType?: eCameraType): Nullable;\r\n private createCameraFromViewpoint(viewpoint: ViewpointNode, convertToCameraType?: eCameraType): Nullable {\r\n const viewer = this.kbViewer;\r\n const bbCache = this.kbViewer.bbCache;\r\n const sceneNode = this.kbViewer.sceneNode;\r\n\r\n if (this.disposePreviousCamera && !this.disposePreviousCamera.isStopped) {\r\n this.disposePreviousCamera.next();\r\n this.disposePreviousCamera.complete();\r\n }\r\n const dispose = (this.disposePreviousCamera = new Subject());\r\n\r\n switch (viewpoint.type) {\r\n case eViewpointType.orbit:\r\n case eViewpointType.overhead:\r\n if (convertToCameraType === eCameraType.Universal) {\r\n const universalCamera = new UniversalCamera(viewpoint.id, viewpoint.position.toVec3(), this.scene);\r\n\r\n // this should be set in the setCommonViewpointProperties\r\n // const direction = viewpoint.targetPoint!.subtract(viewpoint.position).toVec3();\r\n // universalCamera.rotation = rotationToVector(direction).toEulerAngles();\r\n applyViewpointProperties(viewpoint, universalCamera);\r\n\r\n return universalCamera;\r\n } else {\r\n const arcRotateCamera = new KbArcRotateCamera(\r\n viewpoint.id,\r\n 0,\r\n 0,\r\n 0,\r\n viewpoint.targetPoint ? viewpoint.targetPoint.toVec3() : Vector3.Zero(),\r\n this.scene\r\n );\r\n\r\n applyViewpointProperties(viewpoint, arcRotateCamera);\r\n\r\n // overhead camera overrides target\r\n if (viewpoint.type === eViewpointType.overhead) {\r\n arcRotateCamera.lockRotation = true;\r\n arcRotateCamera.target = new Vector3(viewpoint.position.x, 0, viewpoint.position.z);\r\n }\r\n\r\n return arcRotateCamera;\r\n }\r\n case eViewpointType.firstPerson:\r\n //case eViewpointType.fixedPosition:\r\n if (convertToCameraType === eCameraType.ArcRotate) {\r\n const arcRotateCamera = new KbArcRotateCamera(\r\n viewpoint.id,\r\n 0,\r\n 0,\r\n 0,\r\n viewpoint.position.toVec3(),\r\n this.scene\r\n );\r\n\r\n const orbitRotation = viewpoint.rotation.toVec3().scale(Math.PI / 180);\r\n applyViewpointProperties(viewpoint, arcRotateCamera);\r\n arcRotateCamera.alpha = orbitRotation.y - Math.PI / 2;\r\n arcRotateCamera.beta = Math.PI / 2 - orbitRotation.x;\r\n arcRotateCamera.radius = 0.0001;\r\n\r\n return arcRotateCamera;\r\n } else {\r\n const universalCamera = new UniversalCamera(viewpoint.id, viewpoint.position.toVec3(), this.scene);\r\n\r\n applyViewpointProperties(viewpoint, universalCamera);\r\n\r\n return universalCamera;\r\n }\r\n }\r\n\r\n return null;\r\n\r\n function applyViewpointProperties(viewpoint: ViewpointNode, camera: KbArcRotateCamera | UniversalCamera) {\r\n if (viewpoint.projection === eViewpointProjection.orthographic) {\r\n camera.mode = Camera.ORTHOGRAPHIC_CAMERA;\r\n camera.maxZ = 200000;\r\n if (camera instanceof ArcRotateCamera) {\r\n camera.orthoWidth = viewpoint.fov || 8;\r\n camera.wheelPrecision = 60;\r\n camera.pinchPrecision = 60;\r\n camera.setPosition(\r\n viewpoint.position.toVec3().subtract(camera.target).normalize().scale(5000).add(camera.target)\r\n );\r\n }\r\n } else if (viewpoint.projection === eViewpointProjection.perspective) {\r\n camera.mode = Camera.PERSPECTIVE_CAMERA;\r\n camera.fov = (viewpoint.fov * Math.PI) / 180;\r\n if (camera instanceof ArcRotateCamera) {\r\n camera.wheelDeltaPercentage = 0.01;\r\n //camera.wheelPrecision = 10;\r\n camera.speed = 0.0001;\r\n camera.lowerRadiusLimit = 0.0001;\r\n\r\n camera.pinchDeltaPercentage = 0.001;\r\n camera.setPosition(viewpoint.position.toVec3());\r\n }\r\n }\r\n\r\n if (camera instanceof ArcRotateCamera) {\r\n if (!viewpoint.allowOrbit) {\r\n camera.lockRotation = true;\r\n }\r\n if (!viewpoint.allowPan) {\r\n camera.lockPanning = true;\r\n }\r\n if (!viewpoint.allowZoom) {\r\n camera.lockZoom = true;\r\n }\r\n camera.useFramingBehavior = false;\r\n camera.targetScreenOffset.x = viewpoint.offsetX;\r\n camera.targetScreenOffset.y = viewpoint.offsetY;\r\n if (viewpoint.limitMinimumTargetDistance) {\r\n viewer.bbCache.rootBoundingBoxChanged\r\n .pipe(takeUntil(dispose))\r\n .pipe(startWith(null))\r\n .subscribe(() => {\r\n const bounding = viewer.bbCache.getWorld(sceneNode);\r\n if (bounding) {\r\n const minVector = new Vector3(bounding.min.x, bounding.min.y, bounding.min.z);\r\n const maxVector = new Vector3(bounding.max.x, bounding.max.y, bounding.max.z);\r\n const boundingSphere = new BoundingSphere(minVector, maxVector);\r\n camera.lowerRadiusLimit = boundingSphere.radiusWorld;\r\n } else {\r\n camera.lowerRadiusLimit = viewpoint.minTargetDistance;\r\n }\r\n });\r\n } else {\r\n camera.lowerRadiusLimit = viewpoint.minTargetDistance;\r\n }\r\n\r\n camera.upperRadiusLimit = viewpoint.maxTargetDistance;\r\n\r\n if (viewpoint.orbitAxis) {\r\n const upVector = viewpoint.orbitAxis.toVec3();\r\n if (upVector.length() === 0) {\r\n upVector.set(0, 1, 0);\r\n }\r\n camera.upVector = upVector;\r\n }\r\n if (viewpoint.limitLngOrbit) {\r\n camera.lowerAlphaLimit = (viewpoint.limitMinLongitude * Math.PI) / 180;\r\n camera.upperAlphaLimit = (viewpoint.limitMaxLongitude * Math.PI) / 180;\r\n } else {\r\n camera.lowerAlphaLimit = null;\r\n camera.upperAlphaLimit = null;\r\n }\r\n\r\n if (viewpoint.limitLatOrbit) {\r\n camera.lowerBetaLimit = (viewpoint.limitMinLatitude * Math.PI) / 180;\r\n camera.upperBetaLimit = (viewpoint.limitMaxLatitude * Math.PI) / 180;\r\n } else {\r\n camera.lowerBetaLimit = 0.001;\r\n camera.upperBetaLimit = Math.PI - 0.001;\r\n }\r\n } else if (camera instanceof UniversalCamera) {\r\n // // For fixed rotation, only allow targeting the camera with the mouse and disable movement.\r\n // if (viewpoint.type === eViewpointType.fixedPosition) {\r\n // camera.inputs.clear();\r\n // camera.inputs.addMouse();\r\n // }\r\n camera.inputs.clear();\r\n if (viewpoint.allowPan) {\r\n enableFreeMove(camera);\r\n }\r\n if (viewpoint.allowOrbit) {\r\n enableFreeLook(camera);\r\n }\r\n }\r\n\r\n if (viewpoint.targetMode === eViewpointTargetMode.point) {\r\n camera.setTarget(viewpoint.targetPoint.toVec3());\r\n } else if (viewpoint.targetMode === eViewpointTargetMode.mesh) {\r\n const targetMeshNode = viewpoint._manager!.getById(viewpoint.targetMeshId!) as MeshNode;\r\n if (targetMeshNode) {\r\n // TODO: When updating to babylon 5.0, use targetHost property for targetting mesh\r\n bbCache.rootBoundingBoxChanged.pipe(takeUntil(dispose)).subscribe(() => {\r\n const bbInfo = bbCache.getWorld(targetMeshNode);\r\n if (bbInfo) {\r\n camera.setTarget(bbInfo.center.toVec3());\r\n }\r\n });\r\n }\r\n } else {\r\n // rotation\r\n if (camera instanceof ArcRotateCamera) {\r\n camera.alpha = (viewpoint.rotation.y * Math.PI) / 180; // yaw = longitude\r\n camera.beta = (viewpoint.rotation.x * Math.PI) / 180; // pitch = latitude\r\n } else {\r\n camera.rotation = viewpoint.rotation.toVec3().scale(Math.PI / 180);\r\n }\r\n }\r\n\r\n bbCache\r\n .watchForChanges(sceneNode)\r\n .pipe(takeUntil(dispose))\r\n .subscribe(bbInfo => {\r\n if (bbInfo && bbInfo.boundingInfo.diagonalLength > 0) {\r\n const cameraDistance = bbInfo.boundingInfo.diagonalLength * 2;\r\n /**\r\n * This piece of code is very important. if the maxZ is too small, things will disappear as you zoom out.\r\n * If the maxZ is too large, the camera will not have enough buffer and\r\n * all kinds of things get messed up - clicking doesn't work, you start getting z-fighting.\r\n * Smallest the maxZ should be \"10\" due to the grid.\r\n * However ortho camera should be double that because calculations are made from half of the frame\r\n * And perspective camera should also take the camera distance into account (but have some sane multiplier based on the mesh size)\r\n */\r\n // should we set the minZ here as well, or just hard code it?\r\n if (\r\n viewpoint.projection === eViewpointProjection.orthographic &&\r\n camera instanceof ArcRotateCamera\r\n ) {\r\n camera.setPosition(\r\n camera.position\r\n .subtract(camera.target)\r\n .normalize()\r\n .scale(cameraDistance)\r\n .add(camera.target)\r\n );\r\n camera.maxZ = Math.max(cameraDistance, 10) * 2;\r\n } else if (camera instanceof ArcRotateCamera && camera.upperRadiusLimit) {\r\n camera.maxZ = Math.max(\r\n Math.max(cameraDistance, 10) * 16,\r\n camera.upperRadiusLimit + cameraDistance\r\n );\r\n } else {\r\n camera.maxZ = Math.max(cameraDistance, 10) * 16;\r\n }\r\n\r\n // If maxZ is too high then it breaks clicking because the unprojected rays start returning NaN/Infinity\r\n if (camera.maxZ > 200000) {\r\n camera.maxZ = 200000;\r\n }\r\n\r\n if (viewer.rendererManager.sceneRenderer?.skybox) {\r\n // need to resize skybox if it exists, otherwise it will get clipped\r\n const scale = camera.maxZ / 2 / SKYBOX_SIZE;\r\n viewer.rendererManager.sceneRenderer.skybox.scaling = new Vector3(scale, scale, scale);\r\n }\r\n }\r\n });\r\n\r\n camera.onDisposeObservable.add(() => {\r\n dispose.next();\r\n dispose.complete();\r\n });\r\n camera.minZ = 0.01; // hack the camera minz until we have a more automated way to set it\r\n camera.doNotSerialize = true;\r\n }\r\n }\r\n\r\n orient(orientation: eCameraOrientation) {\r\n const bbCache = this.kbViewer.bbCache;\r\n\r\n if (this._lastOrientation === eCameraOrientation.perspective) {\r\n this._lastPerspectivePosition = KbVector.From(this.scene.activeCamera!.position);\r\n }\r\n //get a viewpoint representing the current camera settings\r\n const viewpoint = new ViewpointNode();\r\n const camera = this.scene.activeCamera as KbArcRotateCamera | UniversalCamera;\r\n copyCameraStateIntoViewpoint(viewpoint, camera);\r\n\r\n let targetPoint = KbVector.Zero();\r\n if (viewpoint.targetMode == eViewpointTargetMode.point) {\r\n targetPoint = viewpoint.targetPoint;\r\n } else if (viewpoint.targetMode == eViewpointTargetMode.mesh) {\r\n const targetMeshNode = this.kbViewer.sceneNode._manager!.getById(viewpoint.targetMeshId!) as MeshNode;\r\n if (targetMeshNode) {\r\n const bbInfo = bbCache.getWorld(targetMeshNode);\r\n if (bbInfo) {\r\n targetPoint = bbInfo.center;\r\n }\r\n }\r\n }\r\n let distance = viewpoint.position.subtract(targetPoint).length();\r\n\r\n let newPos = targetPoint.toObject();\r\n if (orientation == eCameraOrientation.top) {\r\n newPos.y += distance;\r\n } else if (orientation == eCameraOrientation.front) {\r\n newPos.z += distance;\r\n } else if (orientation == eCameraOrientation.left) {\r\n newPos.x -= distance;\r\n } else if (orientation == eCameraOrientation.back) {\r\n newPos.z -= distance;\r\n } else if (orientation == eCameraOrientation.right) {\r\n newPos.x += distance;\r\n } else if (orientation == eCameraOrientation.bottom) {\r\n newPos.y -= distance;\r\n } else if (orientation == eCameraOrientation.perspective) {\r\n const lastLength = this._lastPerspectivePosition.length();\r\n const ratio = distance / lastLength;\r\n newPos = this._lastPerspectivePosition.scale(ratio);\r\n }\r\n viewpoint.position = KbVector.From(newPos);\r\n if (orientation != eCameraOrientation.perspective) {\r\n viewpoint.projection = eViewpointProjection.orthographic;\r\n viewpoint.allowOrbit = false;\r\n } else {\r\n viewpoint.projection = eViewpointProjection.perspective;\r\n viewpoint.allowOrbit = true;\r\n }\r\n\r\n if (\r\n this._lastOrientation === eCameraOrientation.perspective &&\r\n orientation !== eCameraOrientation.perspective\r\n ) {\r\n //switching to orthographic so we need to deal with fov\r\n viewpoint.fov = 2 * distance * Math.tan(toRadians(viewpoint.fov / 2));\r\n } else if (\r\n this._lastOrientation !== eCameraOrientation.perspective &&\r\n orientation === eCameraOrientation.perspective\r\n ) {\r\n const orthoWidth = viewpoint.fov; //in orthographic, fov is the ortho width\r\n distance = orthoWidth / (2 * Math.tan(toRadians(defaults.ViewpointNode.fov / 2)));\r\n viewpoint.position = this._lastPerspectivePosition.scale(distance / this._lastPerspectivePosition.length());\r\n viewpoint.fov = defaults.ViewpointNode.fov;\r\n }\r\n viewpoint.offsetX = 0;\r\n viewpoint.offsetY = 0;\r\n\r\n this.moveCameraToViewpoint(viewpoint);\r\n this.frameCamera(this.kbViewer.sceneNode, {\r\n rotate: false,\r\n pan: true,\r\n zoom: false,\r\n });\r\n\r\n this._lastOrientation = orientation;\r\n }\r\n}\r\n\r\nfunction enableFreeLook(camera: UniversalCamera) {\r\n camera.inputs.addMouse();\r\n}\r\n\r\nfunction enableFreeMove(camera: UniversalCamera) {\r\n camera.inputs.addKeyboard();\r\n camera.inputs.addTouch();\r\n}\r\n\r\nfunction copyCameraStateIntoViewpoint(viewpoint: Partial, camera: Camera) {\r\n let normalizedPosition = camera.position;\r\n\r\n // If this is an orthographic camera, the real position is set very far away to prevent clipping. So normalize the position so the biggest dimension is 5.\r\n if (camera instanceof ArcRotateCamera && camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n normalizedPosition = normalizedPosition.subtract(camera.position).normalize().add(camera.position);\r\n if (normalizedPosition.length() > 0) {\r\n const scale = Math.max(...normalizedPosition.asArray().map(dim => Math.abs(dim)));\r\n normalizedPosition = Vector3.FromArray(\r\n normalizedPosition.asArray().map(dim => Math.round((dim / scale) * 500) / 100)\r\n );\r\n }\r\n }\r\n\r\n if (camera instanceof FreeCamera) {\r\n const rotDegrees = camera.rotation.scale(180 / Math.PI);\r\n viewpoint.rotation = KbVector.FromVec3(rotDegrees);\r\n }\r\n viewpoint.position = KbVector.FromVec3(normalizedPosition);\r\n viewpoint.offsetX = camera instanceof KbArcRotateCamera ? camera.targetScreenOffset.x : 0;\r\n viewpoint.offsetY = camera instanceof KbArcRotateCamera ? camera.targetScreenOffset.y : 0;\r\n viewpoint.fov =\r\n camera.mode === Camera.ORTHOGRAPHIC_CAMERA\r\n ? camera.orthoRight! - camera.orthoLeft!\r\n : (camera.fov * 180) / Math.PI;\r\n viewpoint.projection =\r\n camera.mode === Camera.ORTHOGRAPHIC_CAMERA\r\n ? eViewpointProjection.orthographic\r\n : eViewpointProjection.perspective;\r\n}\r\n\r\nfunction normalizeRotation(alpha: number): number {\r\n const oneRotation = Math.PI * 2;\r\n const rotations = Math.floor(alpha / oneRotation);\r\n const radiansToRemove = rotations > 1 ? rotations * oneRotation : 0;\r\n const normalizedRotation = alpha - radiansToRemove;\r\n return normalizedRotation;\r\n}\r\n","import { Observable } from '../Observable';\nimport { concat } from '../observable/concat';\nimport { isScheduler } from '../util/isScheduler';\nimport { MonoTypeOperatorFunction, OperatorFunction, SchedulerLike } from '../types';\n\n/* tslint:disable:max-line-length */\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(scheduler: SchedulerLike): MonoTypeOperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(v1: D, scheduler: SchedulerLike): OperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(v1: D, v2: E, scheduler: SchedulerLike): OperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(v1: D, v2: E, v3: F, scheduler: SchedulerLike): OperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(v1: D, v2: E, v3: F, v4: G, scheduler: SchedulerLike): OperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(v1: D, v2: E, v3: F, v4: G, v5: H, scheduler: SchedulerLike): OperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(v1: D, v2: E, v3: F, v4: G, v5: H, v6: I, scheduler: SchedulerLike): OperatorFunction;\n\nexport function startWith(v1: D): OperatorFunction;\nexport function startWith(v1: D, v2: E): OperatorFunction;\nexport function startWith(v1: D, v2: E, v3: F): OperatorFunction;\nexport function startWith(v1: D, v2: E, v3: F, v4: G): OperatorFunction;\nexport function startWith(v1: D, v2: E, v3: F, v4: G, v5: H): OperatorFunction;\nexport function startWith(v1: D, v2: E, v3: F, v4: G, v5: H, v6: I): OperatorFunction;\nexport function startWith(...array: D[]): OperatorFunction;\n/** @deprecated use {@link scheduled} and {@link concatAll} (e.g. `scheduled([[a, b, c], source], scheduler).pipe(concatAll())`) */\nexport function startWith(...array: Array): OperatorFunction;\n/* tslint:enable:max-line-length */\n\n/**\n * Returns an Observable that emits the items you specify as arguments before it begins to emit\n * items emitted by the source Observable.\n *\n * First emits its arguments in order, and then any\n * emissions from the source.\n *\n * ![](startWith.png)\n *\n * ## Examples\n *\n * Start the chain of emissions with `\"first\"`, `\"second\"`\n *\n * ```ts\n * import { of } from 'rxjs';\n * import { startWith } from 'rxjs/operators';\n *\n * of(\"from source\")\n * .pipe(startWith(\"first\", \"second\"))\n * .subscribe(x => console.log(x));\n *\n * // results:\n * // \"first\"\n * // \"second\"\n * // \"from source\"\n * ```\n *\n * @param {...T} values - Items you want the modified Observable to emit first.\n * @param {SchedulerLike} [scheduler] - A {@link SchedulerLike} to use for scheduling\n * the emissions of the `next` notifications.\n * @return {Observable} An Observable that emits the items in the specified Iterable and then emits the items\n * emitted by the source Observable.\n * @method startWith\n * @owner Observable\n */\nexport function startWith(...array: Array): OperatorFunction {\n const scheduler = array[array.length - 1] as SchedulerLike;\n if (isScheduler(scheduler)) {\n // deprecated path\n array.pop();\n return (source: Observable) => concat(array as T[], source, scheduler);\n } else {\n return (source: Observable) => concat(array as T[], source);\n }\n}\n","import type { SmartArrayNoDuplicate } from \"../../Misc/smartArray\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Ray } from \"../../Culling/ray\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\n\r\n/**\r\n * Contains an array of blocks representing the octree\r\n */\r\nexport interface IOctreeContainer {\r\n /**\r\n * Blocks within the octree\r\n */\r\n blocks: Array>;\r\n}\r\n\r\n/**\r\n * Class used to store a cell in an octree\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n */\r\nexport class OctreeBlock {\r\n /**\r\n * Gets the content of the current block\r\n */\r\n public entries = new Array();\r\n\r\n /**\r\n * Gets the list of block children\r\n */\r\n public blocks: Array>;\r\n\r\n private _depth: number;\r\n private _maxDepth: number;\r\n private _capacity: number;\r\n private _minPoint: Vector3;\r\n private _maxPoint: Vector3;\r\n private _boundingVectors = new Array();\r\n private _creationFunc: (entry: T, block: OctreeBlock) => void;\r\n\r\n /**\r\n * Creates a new block\r\n * @param minPoint defines the minimum vector (in world space) of the block's bounding box\r\n * @param maxPoint defines the maximum vector (in world space) of the block's bounding box\r\n * @param capacity defines the maximum capacity of this block (if capacity is reached the block will be split into sub blocks)\r\n * @param depth defines the current depth of this block in the octree\r\n * @param maxDepth defines the maximal depth allowed (beyond this value, the capacity is ignored)\r\n * @param creationFunc defines a callback to call when an element is added to the block\r\n */\r\n constructor(minPoint: Vector3, maxPoint: Vector3, capacity: number, depth: number, maxDepth: number, creationFunc: (entry: T, block: OctreeBlock) => void) {\r\n this._capacity = capacity;\r\n this._depth = depth;\r\n this._maxDepth = maxDepth;\r\n this._creationFunc = creationFunc;\r\n\r\n this._minPoint = minPoint;\r\n this._maxPoint = maxPoint;\r\n\r\n this._boundingVectors.push(minPoint.clone());\r\n this._boundingVectors.push(maxPoint.clone());\r\n\r\n this._boundingVectors.push(minPoint.clone());\r\n this._boundingVectors[2].x = maxPoint.x;\r\n\r\n this._boundingVectors.push(minPoint.clone());\r\n this._boundingVectors[3].y = maxPoint.y;\r\n\r\n this._boundingVectors.push(minPoint.clone());\r\n this._boundingVectors[4].z = maxPoint.z;\r\n\r\n this._boundingVectors.push(maxPoint.clone());\r\n this._boundingVectors[5].z = minPoint.z;\r\n\r\n this._boundingVectors.push(maxPoint.clone());\r\n this._boundingVectors[6].x = minPoint.x;\r\n\r\n this._boundingVectors.push(maxPoint.clone());\r\n this._boundingVectors[7].y = minPoint.y;\r\n }\r\n\r\n // Property\r\n\r\n /**\r\n * Gets the maximum capacity of this block (if capacity is reached the block will be split into sub blocks)\r\n */\r\n public get capacity(): number {\r\n return this._capacity;\r\n }\r\n\r\n /**\r\n * Gets the minimum vector (in world space) of the block's bounding box\r\n */\r\n public get minPoint(): Vector3 {\r\n return this._minPoint;\r\n }\r\n\r\n /**\r\n * Gets the maximum vector (in world space) of the block's bounding box\r\n */\r\n public get maxPoint(): Vector3 {\r\n return this._maxPoint;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Add a new element to this block\r\n * @param entry defines the element to add\r\n */\r\n public addEntry(entry: T): void {\r\n if (this.blocks) {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.addEntry(entry);\r\n }\r\n return;\r\n }\r\n\r\n this._creationFunc(entry, this);\r\n\r\n if (this.entries.length > this.capacity && this._depth < this._maxDepth) {\r\n this.createInnerBlocks();\r\n }\r\n }\r\n\r\n /**\r\n * Remove an element from this block\r\n * @param entry defines the element to remove\r\n */\r\n public removeEntry(entry: T): void {\r\n if (this.blocks) {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.removeEntry(entry);\r\n }\r\n return;\r\n }\r\n\r\n const entryIndex = this.entries.indexOf(entry);\r\n\r\n if (entryIndex > -1) {\r\n this.entries.splice(entryIndex, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Add an array of elements to this block\r\n * @param entries defines the array of elements to add\r\n */\r\n public addEntries(entries: T[]): void {\r\n for (let index = 0; index < entries.length; index++) {\r\n const mesh = entries[index];\r\n this.addEntry(mesh);\r\n }\r\n }\r\n\r\n /**\r\n * Test if the current block intersects the frustum planes and if yes, then add its content to the selection array\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @param selection defines the array to store current content if selection is positive\r\n * @param allowDuplicate defines if the selection array can contains duplicated entries\r\n */\r\n public select(frustumPlanes: Plane[], selection: SmartArrayNoDuplicate, allowDuplicate?: boolean): void {\r\n if (BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {\r\n if (this.blocks) {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.select(frustumPlanes, selection, allowDuplicate);\r\n }\r\n return;\r\n }\r\n\r\n if (allowDuplicate) {\r\n selection.concat(this.entries);\r\n } else {\r\n selection.concatWithNoDuplicate(this.entries);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Test if the current block intersect with the given bounding sphere and if yes, then add its content to the selection array\r\n * @param sphereCenter defines the bounding sphere center\r\n * @param sphereRadius defines the bounding sphere radius\r\n * @param selection defines the array to store current content if selection is positive\r\n * @param allowDuplicate defines if the selection array can contains duplicated entries\r\n */\r\n public intersects(sphereCenter: Vector3, sphereRadius: number, selection: SmartArrayNoDuplicate, allowDuplicate?: boolean): void {\r\n if (BoundingBox.IntersectsSphere(this._minPoint, this._maxPoint, sphereCenter, sphereRadius)) {\r\n if (this.blocks) {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersects(sphereCenter, sphereRadius, selection, allowDuplicate);\r\n }\r\n return;\r\n }\r\n\r\n if (allowDuplicate) {\r\n selection.concat(this.entries);\r\n } else {\r\n selection.concatWithNoDuplicate(this.entries);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Test if the current block intersect with the given ray and if yes, then add its content to the selection array\r\n * @param ray defines the ray to test with\r\n * @param selection defines the array to store current content if selection is positive\r\n */\r\n public intersectsRay(ray: Ray, selection: SmartArrayNoDuplicate): void {\r\n if (ray.intersectsBoxMinMax(this._minPoint, this._maxPoint)) {\r\n if (this.blocks) {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersectsRay(ray, selection);\r\n }\r\n return;\r\n }\r\n selection.concatWithNoDuplicate(this.entries);\r\n }\r\n }\r\n\r\n /**\r\n * Subdivide the content into child blocks (this block will then be empty)\r\n */\r\n public createInnerBlocks(): void {\r\n OctreeBlock._CreateBlocks(this._minPoint, this._maxPoint, this.entries, this._capacity, this._depth, this._maxDepth, this, this._creationFunc);\r\n this.entries.splice(0);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _CreateBlocks(\r\n worldMin: Vector3,\r\n worldMax: Vector3,\r\n entries: T[],\r\n maxBlockCapacity: number,\r\n currentDepth: number,\r\n maxDepth: number,\r\n target: IOctreeContainer,\r\n creationFunc: (entry: T, block: OctreeBlock) => void\r\n ): void {\r\n target.blocks = new Array>();\r\n const blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n\r\n // Segmenting space\r\n for (let x = 0; x < 2; x++) {\r\n for (let y = 0; y < 2; y++) {\r\n for (let z = 0; z < 2; z++) {\r\n const localMin = worldMin.add(blockSize.multiplyByFloats(x, y, z));\r\n const localMax = worldMin.add(blockSize.multiplyByFloats(x + 1, y + 1, z + 1));\r\n\r\n const block = new OctreeBlock(localMin, localMax, maxBlockCapacity, currentDepth + 1, maxDepth, creationFunc);\r\n block.addEntries(entries);\r\n target.blocks.push(block);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n","import type { SmartArray } from \"../../Misc/smartArray\";\r\nimport { SmartArrayNoDuplicate } from \"../../Misc/smartArray\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Ray } from \"../../Culling/ray\";\r\nimport { OctreeBlock } from \"./octreeBlock\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\n\r\n/**\r\n * Octrees are a really powerful data structure that can quickly select entities based on space coordinates.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n */\r\nexport class Octree {\r\n /**\r\n * Blocks within the octree containing objects\r\n */\r\n public blocks: Array>;\r\n /**\r\n * Content stored in the octree\r\n */\r\n public dynamicContent = new Array();\r\n\r\n private _maxBlockCapacity: number;\r\n private _selectionContent: SmartArrayNoDuplicate;\r\n private _creationFunc: (entry: T, block: OctreeBlock) => void;\r\n\r\n /**\r\n * Creates a octree\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n * @param creationFunc function to be used to instantiate the octree\r\n * @param maxBlockCapacity defines the maximum number of meshes you want on your octree's leaves (default: 64)\r\n * @param maxDepth defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.)\r\n */\r\n constructor(\r\n creationFunc: (entry: T, block: OctreeBlock) => void,\r\n maxBlockCapacity?: number,\r\n /** Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.) */\r\n public maxDepth = 2\r\n ) {\r\n this._maxBlockCapacity = maxBlockCapacity || 64;\r\n this._selectionContent = new SmartArrayNoDuplicate(1024);\r\n this._creationFunc = creationFunc;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Updates the octree by adding blocks for the passed in meshes within the min and max world parameters\r\n * @param worldMin worldMin for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n * @param worldMax worldMax for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n * @param entries meshes to be added to the octree blocks\r\n */\r\n public update(worldMin: Vector3, worldMax: Vector3, entries: T[]): void {\r\n OctreeBlock._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);\r\n }\r\n\r\n /**\r\n * Adds a mesh to the octree\r\n * @param entry Mesh to add to the octree\r\n */\r\n public addMesh(entry: T): void {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.addEntry(entry);\r\n }\r\n }\r\n\r\n /**\r\n * Remove an element from the octree\r\n * @param entry defines the element to remove\r\n */\r\n public removeMesh(entry: T): void {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.removeEntry(entry);\r\n }\r\n }\r\n\r\n /**\r\n * Selects an array of meshes within the frustum\r\n * @param frustumPlanes The frustum planes to use which will select all meshes within it\r\n * @param allowDuplicate If duplicate objects are allowed in the resulting object array\r\n * @returns array of meshes within the frustum\r\n */\r\n public select(frustumPlanes: Plane[], allowDuplicate?: boolean): SmartArray {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.select(frustumPlanes, this._selectionContent, allowDuplicate);\r\n }\r\n\r\n if (allowDuplicate) {\r\n this._selectionContent.concat(this.dynamicContent);\r\n } else {\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n }\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Test if the octree intersect with the given bounding sphere and if yes, then add its content to the selection array\r\n * @param sphereCenter defines the bounding sphere center\r\n * @param sphereRadius defines the bounding sphere radius\r\n * @param allowDuplicate defines if the selection array can contains duplicated entries\r\n * @returns an array of objects that intersect the sphere\r\n */\r\n public intersects(sphereCenter: Vector3, sphereRadius: number, allowDuplicate?: boolean): SmartArray {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersects(sphereCenter, sphereRadius, this._selectionContent, allowDuplicate);\r\n }\r\n\r\n if (allowDuplicate) {\r\n this._selectionContent.concat(this.dynamicContent);\r\n } else {\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n }\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Test if the octree intersect with the given ray and if yes, then add its content to resulting array\r\n * @param ray defines the ray to test with\r\n * @returns array of intersected objects\r\n */\r\n public intersectsRay(ray: Ray): SmartArray {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersectsRay(ray, this._selectionContent);\r\n }\r\n\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Adds a mesh into the octree block if it intersects the block\r\n * @param entry\r\n * @param block\r\n */\r\n public static CreationFuncForMeshes = (entry: AbstractMesh, block: OctreeBlock): void => {\r\n const boundingInfo = entry.getBoundingInfo();\r\n if (!entry.isBlocked && boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\r\n block.entries.push(entry);\r\n }\r\n };\r\n\r\n /**\r\n * Adds a submesh into the octree block if it intersects the block\r\n * @param entry\r\n * @param block\r\n */\r\n public static CreationFuncForSubMeshes = (entry: SubMesh, block: OctreeBlock): void => {\r\n const boundingInfo = entry.getBoundingInfo();\r\n if (boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\r\n block.entries.push(entry);\r\n }\r\n };\r\n}\r\n","import { Octree } from '@babylonjs/core/Culling/Octrees/octree';\r\nimport { Ray } from '@babylonjs/core/Culling/ray';\r\nimport { PointerEventTypes, PointerInfo } from '@babylonjs/core/Events/pointerEvents';\r\nimport { Matrix, Plane, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Observer } from '@babylonjs/core/Misc/observable';\r\nimport { Node } from '@babylonjs/core/node';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { eConnectionMode, eConnectorPositionMode, eDragMode, eMateType } from '@models/classes/enums';\r\nimport { Connector, isConnector } from '@models/classes/features/connector';\r\nimport { SketchControlPoint } from '@models/classes/features/sketch-control-point';\r\nimport { IConnection, IDragArgs, IDraggable, IKb3dPointerArgs, PointerInfoMinimal } from '@models/classes/handlers';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { isSpaceNode } from '@models/classes/meshes/mesh-utilities';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Token } from '@models/classes/token';\r\nimport { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { mateConnectors } from '@view/helpers/mate-helper';\r\nimport { QuadTree } from '@view/helpers/quadtree';\r\nimport { IScreenPosition, toScreen } from '@view/helpers/scene-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { ConnectorRenderer, getNodeChain } from '@view/render';\r\n\r\ninterface IPotential {\r\n otherMesh: TransformNode;\r\n proximity: number;\r\n distanceToCamera?: number;\r\n}\r\n\r\ninterface IPotentialConnector extends IPotential {\r\n dragConnector: Connector;\r\n dragConnectorMesh: TransformNode;\r\n}\r\n\r\ninterface IMeshScreenPosition {\r\n mesh: TransformNode;\r\n pos: IScreenPosition;\r\n}\r\n\r\ninterface IConnectionMesh extends IConnection {\r\n dragConnectorMesh: TransformNode;\r\n otherConnectorMesh: TransformNode;\r\n}\r\n\r\ntype MatedObject = SpaceNode | SketchControlPoint;\r\n\r\nconst CLICK_THRESHOLD = 8;\r\n\r\nexport class Dragger {\r\n constructor(private viewer: KbViewer, private scene: Scene) {}\r\n\r\n private _dragNode: SpaceNode;\r\n private _dragNodeStartPosition: KbVector;\r\n private _dragNodeInverseTransform: Matrix;\r\n private _dragMesh: TransformNode;\r\n private _draggable: IDraggable;\r\n private _pointerObserver: Nullable>;\r\n private _dragPlane: Plane;\r\n private _dragSurfaces: string[]; //array of dynamic id's of the drag surfaces if mode is \"surface\"\r\n private _startMouseIntersect?: Vector3;\r\n private _onComplete: () => void;\r\n private _externalConnectors = new Map(); //connectors out in the scene that are not part of what is being dragged\r\n private _dragConnectors = new Map(); //connectors that are children of what is being dragged\r\n private _dragConnectorsByDynamicId = new Map(); //the drag connectors stored by their dynamic id\r\n private _dropPreviewConnectors = new Map(); //the drop preview is a clone of the dragNode, this tracks the connector meshes in the drop preview\r\n private _oct: Octree; //the octree holding connectors for fast retrieval\r\n private _quadTree: QuadTree;\r\n private _dropPreview: TransformNode;\r\n private _activeConnection: IConnectionMesh | undefined;\r\n private _connectorRenderer: ConnectorRenderer;\r\n private _dragFriends = new Set();\r\n private _dragFriendMeshes = new Array();\r\n private _dragFriendConnectors = new Set();\r\n private _matedConnectors = new Set();\r\n\r\n public startDrag(pointerArgs: IKb3dPointerArgs, draggable: IDraggable, onComplete: () => void) {\r\n let totalMoved = 0;\r\n let lastX: number;\r\n let lastY: number;\r\n\r\n this._pointerObserver = this.scene.onPointerObservable.add(p => {\r\n switch (p.type) {\r\n case PointerEventTypes.POINTERMOVE: {\r\n let movX = 0;\r\n let movY = 0;\r\n if (typeof lastX === 'undefined' || typeof lastY === 'undefined') {\r\n lastX = p.event.offsetX;\r\n lastY = p.event.offsetY;\r\n } else {\r\n movX = Math.abs(lastX - p.event.offsetX);\r\n movY = Math.abs(lastY - p.event.offsetY);\r\n }\r\n totalMoved += Math.sqrt(movX * movX + movY * movY);\r\n\r\n if (totalMoved > CLICK_THRESHOLD) {\r\n this.startDragCommit(pointerArgs, draggable, onComplete);\r\n this.dragging(p);\r\n }\r\n\r\n break;\r\n }\r\n case PointerEventTypes.POINTERUP: {\r\n if (totalMoved > CLICK_THRESHOLD) {\r\n this.dropped(p);\r\n }\r\n this.scene.onPointerObservable.remove(this._pointerObserver);\r\n this._pointerObserver = undefined as any;\r\n break;\r\n }\r\n }\r\n });\r\n\r\n this.scene.activeCamera?.detachControl();\r\n }\r\n\r\n public startDragCommit(pointerArgs: IKb3dPointerArgs, draggable: IDraggable, onComplete: () => void) {\r\n if (!this._draggable) {\r\n this._connectorRenderer = this.viewer.rendererManager.connector;\r\n this._dragNode = pointerArgs.sourceNode!;\r\n this._dragNodeStartPosition = this._dragNode.position.clone();\r\n this._dragMesh = this.viewer.rendererManager.mesh.get3d(this._dragNode) as TransformNode;\r\n if (this._dragMesh.parent) {\r\n this._dragNodeInverseTransform = this._dragMesh.parent\r\n .computeWorldMatrix(true)\r\n .clone()\r\n .setTranslation(Vector3.Zero())\r\n .invert();\r\n }\r\n this._draggable = draggable;\r\n if (this._draggable.connectionMode == null) this._draggable.connectionMode = eConnectionMode.none;\r\n if (this._draggable.connectionType == null) this._draggable.connectionType = eMateType.fastened;\r\n if (this._draggable.connectRadius == null) {\r\n if (this._draggable.connectionMode == eConnectionMode.screen) {\r\n this._draggable.connectRadius = 5; //5 pixels\r\n } else {\r\n this._draggable.connectRadius = 0.3; //3d units\r\n }\r\n }\r\n if (this._draggable.dragOpacity == null) this._draggable.dragOpacity = 0.7;\r\n\r\n this._onComplete = onComplete;\r\n\r\n this.setupDragSurface(pointerArgs);\r\n\r\n if (this._draggable.dragStart) {\r\n this._draggable.dragStart(\r\n this.getDragArgs(pointerArgs, this._dragNodeStartPosition, this._dragMesh.rotationQuaternion)\r\n );\r\n }\r\n\r\n this.setupDragFriends();\r\n this.setupConnectors();\r\n this.setOpacity(this._draggable.dragOpacity!, this._dragMesh, ...this._dragFriendMeshes);\r\n }\r\n }\r\n\r\n protected dragging(p: PointerInfo) {\r\n // this._dragNode._dragging = true;\r\n\r\n const newConnection = this.findConnection();\r\n //let connectionChanged = !this.connectionsAreEqual(newConnection, this._activeConnection);\r\n this._activeConnection = newConnection;\r\n\r\n if (this._activeConnection) {\r\n //if (connectionChanged) { //don't bother processing the connection if it's the same\r\n this.showDropPreview(this._activeConnection);\r\n //}\r\n } else {\r\n this.hideDropPreview();\r\n }\r\n this.processDragPosition(p, this._draggable.dragging);\r\n }\r\n\r\n protected applyDragResultToNode(node: SpaceNode, dragArgs: IDragArgs, applyEuler: boolean) {\r\n node.position = dragArgs.newPos;\r\n // If euler rotation was changed, apply the changed euler rotation. If not, then apply the quaternion rotation regardless of whether it was changed.\r\n if (applyEuler) {\r\n node.eulerRotation = dragArgs.newRotationEuler;\r\n const newKbQuat = KbQuaternion.FromYawPitchRoll(dragArgs.newRotationEuler);\r\n dragArgs.newRotationAngle = newKbQuat.getAngle();\r\n dragArgs.newRotationAxis = newKbQuat.getAxis();\r\n node.rotationAxis = dragArgs.newRotationAxis;\r\n node.rotationAngle = dragArgs.newRotationAngle;\r\n } else {\r\n node.rotationAxis = dragArgs.newRotationAxis;\r\n node.rotationAngle = dragArgs.newRotationAngle;\r\n node.eulerRotation = KbQuaternion.FromRotationAxis(\r\n dragArgs.newRotationAxis,\r\n dragArgs.newRotationAngle\r\n ).toEuler();\r\n }\r\n }\r\n\r\n protected dropped(p: PointerInfo) {\r\n this._dragNode._primeMover = false;\r\n\r\n const complete = new Promise(resolve => {\r\n if (this._activeConnection) {\r\n this._activeConnection.otherConnector._parent!._primeMover = true;\r\n this.connect(this._activeConnection, this._dragMesh);\r\n // let newRotation = KbVector.FromVec3(this._dragMesh.rotation);\r\n\r\n const dragArgs: IDragArgs & Required> = {\r\n ...this.getDragArgs(p, this._dragMesh.position, this._dragMesh.rotationQuaternion),\r\n connection: this._activeConnection,\r\n };\r\n if (this._draggable.withMates) {\r\n dragArgs.mate = this.viewer.sceneNode._manager!.create(Token.MateNode, {\r\n connector1: this.viewer.sceneNode.getNestedPathTo(dragArgs.connection.otherConnector),\r\n connector2: this.viewer.sceneNode.getNestedPathTo(dragArgs.connection.dragConnector),\r\n mateType: this._draggable.connectionType,\r\n });\r\n }\r\n const previousEuler = dragArgs.newRotationEuler.clone();\r\n\r\n this.applyDragResultToNode(this._dragNode, dragArgs, !previousEuler.equal(dragArgs.newRotationEuler));\r\n if (dragArgs.mate) {\r\n this.viewer.sceneNode.mates.push(dragArgs.mate);\r\n }\r\n\r\n this.viewer.forceAndWaitForNextRender().then(() => {\r\n if (this._draggable.dropped) {\r\n this._draggable.dropped(dragArgs);\r\n\r\n if (!dragArgs.allow) {\r\n console.warn(\r\n 'Cannot disallow dropping when using connectors, use canConnect handler instead'\r\n );\r\n }\r\n }\r\n resolve();\r\n });\r\n } else {\r\n this.processDragPosition(p, this._draggable.dragging);\r\n this.processDragPosition(p, this._draggable.dropped);\r\n resolve();\r\n }\r\n });\r\n\r\n complete.then(() => {\r\n this.toggleAllConnectors(false);\r\n this.resetOpacity(this._dragMesh, ...this._dragFriendMeshes);\r\n this.scene.activeCamera?.attachControl(this.viewer.canvas!);\r\n if (this._onComplete) this._onComplete();\r\n\r\n this.disposeDropPreview();\r\n this._onComplete = undefined as any;\r\n this._dragNode = undefined as any;\r\n this._dragMesh = undefined as any;\r\n this._draggable = undefined as any;\r\n this._dragPlane = undefined as any;\r\n this._dragSurfaces = undefined as any;\r\n this._onComplete = undefined as any;\r\n if (this._externalConnectors) this._externalConnectors.clear();\r\n if (this._dragConnectors) this._dragConnectors.clear();\r\n if (this._dragConnectorsByDynamicId) this._dragConnectorsByDynamicId.clear();\r\n if (this._dropPreviewConnectors) this._dropPreviewConnectors.clear();\r\n this._oct = undefined as any;\r\n this._quadTree = undefined as any;\r\n if (this._quadTree) this._quadTree.items;\r\n this._dropPreview = undefined as any;\r\n this._activeConnection = undefined as any;\r\n this._connectorRenderer = undefined as any;\r\n if (this._dragFriends) this._dragFriends.clear();\r\n if (this._dragFriendMeshes) this._dragFriendMeshes.clear();\r\n if (this._dragFriendConnectors) this._dragFriendConnectors.clear();\r\n if (this._matedConnectors) this._matedConnectors.clear();\r\n });\r\n }\r\n\r\n protected processDragPosition(p: PointerInfo, event?: (a: IDragArgs) => void) {\r\n const newMouseIntersect = this.intersectPointerToDragSurface(p);\r\n if (newMouseIntersect) {\r\n let newPos: KbVector;\r\n if (this._draggable.disableOffset || this._draggable.mode == eDragMode.surface) {\r\n newPos = KbVector.FromVec3(newMouseIntersect);\r\n } else {\r\n if (this._startMouseIntersect) {\r\n const delta = newMouseIntersect.subtract(this._startMouseIntersect);\r\n if (this._dragNodeInverseTransform) {\r\n Vector3.TransformCoordinatesToRef(delta, this._dragNodeInverseTransform, delta);\r\n }\r\n newPos = this._dragNodeStartPosition.add(delta);\r\n } else {\r\n newPos = this._dragNodeStartPosition;\r\n this._startMouseIntersect = newMouseIntersect;\r\n }\r\n }\r\n\r\n const dragArgs = this.getDragArgs(p, newPos, this._dragMesh.rotationQuaternion);\r\n const previousEuler = dragArgs.newRotationEuler.clone();\r\n if (event) {\r\n event(dragArgs);\r\n }\r\n if (dragArgs.allow) {\r\n this.applyDragResultToNode(this._dragNode, dragArgs, !previousEuler.equal(dragArgs.newRotationEuler));\r\n }\r\n return dragArgs;\r\n }\r\n return undefined;\r\n }\r\n\r\n protected setupDragSurface(p: IKb3dPointerArgs) {\r\n const d = this._draggable;\r\n const manager = this._dragNode._manager!;\r\n if (d.mode == eDragMode.plane) {\r\n // d.planeOrigin = p.pickedPoint!; // d.planeOrigin || this._dragNode.position;\r\n\r\n /** intersection plane is defined by the pickedPoint and the plane normal */\r\n d.planeNormal = d.planeNormal || new KbVector(0, 1, 0);\r\n this._dragPlane = Plane.FromPositionAndNormal(p.pickInfo!.pickedPoint!, d.planeNormal!.toVec3());\r\n } else if (d.mode == eDragMode.free) {\r\n const cameraDirection = this.scene.activeCamera!.position.subtract(this._dragMesh.getAbsolutePosition());\r\n this._dragPlane = Plane.FromPositionAndNormal(this._dragNode.position.toVec3(), cameraDirection);\r\n } else if (d.mode == eDragMode.surface) {\r\n const surfaceIds = Array.isArray(d.surfaceNodes) ? d.surfaceNodes : [d.surfaceNodes];\r\n this._dragSurfaces =\r\n (surfaceIds.map(sn => sn && manager.getById(sn)?._dynamicId).filter(sn => sn != null) as string[]) ||\r\n [];\r\n }\r\n }\r\n\r\n protected intersectPointerToDragSurface(p: PointerInfo) {\r\n return this.intersectDragSurface(p.pickInfo!.ray!);\r\n }\r\n\r\n protected intersectDragSurface(ray: Ray): Vector3 | undefined {\r\n switch (this._draggable.mode) {\r\n case eDragMode.plane:\r\n case eDragMode.free: {\r\n const distance = ray.intersectsPlane(this._dragPlane);\r\n if (distance != null) {\r\n return ray.direction.scale(distance).add(ray.origin);\r\n }\r\n break;\r\n }\r\n case eDragMode.surface: {\r\n const surfacePick = this.scene.pickWithRay(ray, mesh => {\r\n return this._dragSurfaces.some(sn => mesh.id == sn);\r\n });\r\n if (surfacePick && surfacePick.pickedPoint) {\r\n return surfacePick.pickedPoint;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n protected getDragArgs(\r\n p: PointerInfoMinimal,\r\n newPos: KbVector | Vector3,\r\n newRotation?: Nullable\r\n ): IDragArgs {\r\n const newKbRotation = KbQuaternion.FromQuat(newRotation || Quaternion.Identity());\r\n\r\n return {\r\n dragNode: this._dragNode,\r\n startPos: this._dragNodeStartPosition,\r\n allow: true,\r\n u: p.pickInfo?.bu || 0.5,\r\n v: p.pickInfo?.bv || 0.5,\r\n newPos: newPos instanceof Vector3 ? KbVector.FromVec3(newPos) : newPos,\r\n newRotationAxis: newKbRotation.getAxis(),\r\n newRotationAngle: newKbRotation.getAngle(),\r\n newRotationEuler: newKbRotation.toEuler(),\r\n };\r\n }\r\n\r\n protected findConnection(): IConnectionMesh | undefined {\r\n if (this._draggable.connectionMode != eConnectionMode.none) {\r\n const potentialConnectors = new Array();\r\n\r\n for (const [dragConnector, dragConnectorMesh] of this._dragConnectors) {\r\n const dragConPos = dragConnectorMesh.getAbsolutePosition();\r\n for (const p of this.intersectOctree(dragConPos)) {\r\n potentialConnectors.push({\r\n ...p,\r\n dragConnector,\r\n dragConnectorMesh,\r\n });\r\n }\r\n }\r\n\r\n if (this._draggable.connectionMode == eConnectionMode.world) {\r\n potentialConnectors.sortBy(p => p.proximity);\r\n } else {\r\n potentialConnectors.sortBy(p => p.distanceToCamera);\r\n }\r\n\r\n for (const p of potentialConnectors) {\r\n const otherConnector = getByDynamicId(p.otherMesh.id)!;\r\n const a = {\r\n dragConnector: p.dragConnector,\r\n otherConnector: otherConnector,\r\n dragNode: p.dragConnector._parent,\r\n otherNode: otherConnector._parent,\r\n allow: true,\r\n\r\n // Private properties below, don't expose to Snap\r\n dragConnectorMesh: p.dragConnectorMesh,\r\n otherConnectorMesh: p.otherMesh,\r\n };\r\n if (this._draggable.canConnect) {\r\n this._draggable.canConnect(a);\r\n }\r\n if (a.allow) {\r\n return a;\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected connectionsAreEqual(c1?: IConnection, c2?: IConnection) {\r\n return (\r\n (!c1 && !c2) || (c1 && c2 && c1.dragConnector == c2.dragConnector && c1.otherConnector == c2.otherConnector)\r\n );\r\n }\r\n\r\n protected setupConnectors() {\r\n if (this._draggable.connectionMode != eConnectionMode.none) {\r\n const externalConnectorMeshes = new Set();\r\n for (const c of this.viewer.sceneNode.getAllConnectors()) {\r\n if (\r\n !this._dragFriendConnectors.has(c) &&\r\n (!this._draggable.withMates || !this._matedConnectors.has(c)) &&\r\n this.parentsEnabled(c)\r\n ) {\r\n let mesh = this.getConnectorMesh(c);\r\n if (!mesh) {\r\n this._connectorRenderer.update3d(c as ITrackedClass);\r\n mesh = this.getConnectorMesh(c);\r\n }\r\n externalConnectorMeshes.add(mesh);\r\n this._externalConnectors.set(c, mesh);\r\n }\r\n }\r\n const dragConnectors = this._dragNode\r\n .filterNodes(n => isSpaceNode(n) && n.visible, true, false)\r\n .selectMany(n => n.connectors);\r\n\r\n for (const c of dragConnectors) {\r\n //remove the drag connectors from the outside connectors\r\n if (this._externalConnectors.has(c)) {\r\n const mesh = this._externalConnectors.get(c)!;\r\n this._dragConnectors.set(c, mesh);\r\n this._dragConnectorsByDynamicId.set(c._dynamicId, c);\r\n this._externalConnectors.delete(c);\r\n externalConnectorMeshes.delete(mesh);\r\n }\r\n }\r\n\r\n this.toggleAllConnectors(true);\r\n\r\n if (this._draggable.connectionMode == eConnectionMode.world) {\r\n //create an octree for holding the connectors\r\n this._oct = new Octree(Octree.CreationFuncForMeshes, 64, 2);\r\n\r\n //get the bounding extents of all the external connectors to contain the octree volume\r\n const boundingVectors = this.scene.getWorldExtends(m => externalConnectorMeshes.has(m));\r\n\r\n //update the octree with the connector meshes\r\n this._oct.update(boundingVectors!.min, boundingVectors!.max, [...externalConnectorMeshes]);\r\n } else {\r\n //screen mode\r\n const extConnectorPositions = new Array<{ mesh: TransformNode; pos: IScreenPosition }>();\r\n externalConnectorMeshes.forEach(m => {\r\n extConnectorPositions.push({\r\n mesh: m,\r\n pos: toScreen(m.getAbsolutePosition(), this.scene.activeCamera!),\r\n });\r\n });\r\n\r\n const engine = this.scene.getEngine();\r\n this._quadTree = new QuadTree({\r\n items: extConnectorPositions,\r\n xSelector: d => d.pos.x,\r\n ySelector: d => d.pos.y,\r\n capacity: 4,\r\n xmin: 0,\r\n xmax: engine.getRenderWidth(),\r\n ymin: 0,\r\n ymax: engine.getRenderHeight(),\r\n });\r\n }\r\n }\r\n }\r\n\r\n protected parentsEnabled(item: Kb3dObject) {\r\n while (item._parent && item._parent instanceof SpaceNode) {\r\n if (!item._parent.visible) {\r\n return false;\r\n }\r\n item = item._parent;\r\n }\r\n return true;\r\n }\r\n\r\n protected setupDragFriends() {\r\n const activeMates = this.viewer.getActiveMates();\r\n for (const mate of activeMates) {\r\n const c1 = mate.getC1();\r\n if (c1 && isConnector(c1)) this._matedConnectors.add(c1);\r\n const c2 = mate.getC2();\r\n if (c2 && isConnector(c2)) this._matedConnectors.add(c2);\r\n }\r\n\r\n this._dragFriends = getNodeChain(this._dragNode as MatedObject, activeMates);\r\n this._dragFriends.forEach(friend => {\r\n if (!(friend instanceof SpaceNode)) {\r\n this._dragFriends.delete(friend);\r\n }\r\n });\r\n\r\n for (const friendNode of this._dragFriends) {\r\n if (friendNode instanceof SpaceNode) {\r\n friendNode._primeMover = false;\r\n\r\n const friendMesh = this.viewer.rendererManager.mesh.get3d(friendNode);\r\n if (friendMesh) {\r\n this._dragFriendMeshes.push(friendMesh);\r\n }\r\n\r\n const connectors = friendNode.filterByType(Token.Connector);\r\n for (const c of connectors) this._dragFriendConnectors.add(c);\r\n }\r\n }\r\n this._dragNode._primeMover = true;\r\n }\r\n\r\n protected getConnectorMesh(c: Connector) {\r\n return this._connectorRenderer.get3d(c)!;\r\n }\r\n\r\n protected toggleAllConnectors(show: boolean) {\r\n if (this._draggable.showConnectors) {\r\n for (const [c] of this._externalConnectors) {\r\n c._visible = show;\r\n }\r\n for (const [c] of this._dragConnectors) {\r\n c._visible = show;\r\n }\r\n }\r\n }\r\n\r\n protected intersectOctree(v: Vector3): IPotential[] {\r\n let potentials = new Array();\r\n if (this._draggable.connectionMode == eConnectionMode.world) {\r\n const bpotentials = this._oct.intersects(v, this._draggable.connectRadius!, false);\r\n bpotentials.forEach(p => {\r\n const proximity = p.getAbsolutePosition().subtract(v).length();\r\n if (proximity < this._draggable.connectRadius!) {\r\n potentials.push({ otherMesh: p, proximity });\r\n }\r\n });\r\n //potentials.sortBy(p => p.proximity);\r\n } else {\r\n //screen mode\r\n const screenPos = toScreen(v, this.scene.activeCamera!);\r\n\r\n potentials = this._quadTree.find(screenPos, this._draggable.connectRadius!).map(p => {\r\n return {\r\n otherMesh: p.item.mesh,\r\n proximity: p.proximity,\r\n distanceToCamera: Vector3.Distance(\r\n this.scene.activeCamera!.position,\r\n p.item.mesh.getAbsolutePosition()\r\n ),\r\n };\r\n });\r\n //potentials.sortBy(i => i.distanceToCamera);\r\n\r\n // let ray = this.scene.createPickingRay(screenPos.x, screenPos.y, Matrix.Identity(), this.scene.activeCamera);\r\n // let bpotentials = this._oct.intersectsRay(ray);\r\n // bpotentials.forEach(p => {\r\n // let potentialScreenPos = toScreen(p.getAbsolutePosition(), this.scene.activeCamera!);\r\n // let screenProximity = Math.sqrt(Math.pow(screenPos.x - potentialScreenPos.x, 2) + Math.pow(screenPos.y - potentialScreenPos.y, 2));\r\n // let realProximity = p.getAbsolutePosition().subtract(v).length();\r\n // console.log({ screenProximity, realProximity });\r\n // if (screenProximity < this._draggable.connectRadius!) {\r\n // potentials.push({ mesh: p, proximity: screenProximity });\r\n // }\r\n // });\r\n // potentials.sortBy(p => p.proximity);\r\n }\r\n return potentials;\r\n }\r\n\r\n protected showDropPreview(c: IConnectionMesh) {\r\n if (!this._dropPreview) {\r\n /**\r\n * for the drop preview, we get the drag node and any other nodes that are connected to it through mates\r\n * and clone them, put them in a transformNode, and then that transform node becomes the drop preview\r\n */\r\n this._dropPreview = new TransformNode('_droppreview', this.viewer.scene);\r\n this._dropPreview.position = Vector3.Zero();\r\n this._dropPreview.rotationQuaternion = Quaternion.Identity();\r\n this._dropPreview.computeWorldMatrix(true);\r\n const dragMeshTransform = this._dragMesh.computeWorldMatrix(true).getRotationMatrix();\r\n dragMeshTransform.invert();\r\n\r\n for (const friendMesh of [this._dragMesh, ...this._dragFriendMeshes]) {\r\n createDragPreview(friendMesh, this._dropPreview, this);\r\n }\r\n this._dropPreview.setPreTransformMatrix(dragMeshTransform);\r\n } else {\r\n //line drop preview back up with the source models as they might have rotated\r\n if (this._draggable.connectionType != eMateType.fastened) {\r\n this.connect(\r\n {\r\n dragConnector: c.dragConnector,\r\n otherConnector: c.dragConnector,\r\n otherConnectorMesh: c.dragConnectorMesh,\r\n dragConnectorMesh: this._dropPreviewConnectors.get(c.dragConnector)!, //pass in the drop preview connector mesh\r\n },\r\n this._dropPreview,\r\n eMateType.fastened,\r\n true\r\n );\r\n }\r\n }\r\n\r\n this.connect(\r\n {\r\n ...c,\r\n dragConnectorMesh: this._dropPreviewConnectors.get(c.dragConnector)!, //pass in the drop preview connector mesh\r\n },\r\n this._dropPreview\r\n );\r\n\r\n this._dropPreview.setEnabled(true);\r\n //hide the drag node\r\n this._dragMesh.setEnabled(false);\r\n for (const friend of this._dragFriendMeshes) friend.setEnabled(false);\r\n\r\n function createDragPreview(mesh: TransformNode, parent: TransformNode, self: Dragger) {\r\n const clonedMeshGroup = mesh.clone(mesh.id + '_dropPreview', mesh.parent, true);\r\n if (clonedMeshGroup) {\r\n clonedMeshGroup.setPivotMatrix(Matrix.Identity());\r\n\r\n // Cloning does not copy the pretransform matrix over so we have to do that manually\r\n // Otherwise the connector meshes scaling does not get applied to the preview meshes\r\n clonedMeshGroup.setEnabled(mesh.isEnabled());\r\n if (c instanceof Mesh && mesh instanceof Mesh) {\r\n c.setPreTransformMatrix(mesh.getPivotMatrix());\r\n }\r\n\r\n clonedMeshGroup.setParent(parent); // setting the parent with setParent will make the node stay in the same absolute position.\r\n const children = mesh.getChildren(child => child instanceof TransformNode, true);\r\n children.forEach(child => {\r\n createDragPreview(child as TransformNode, clonedMeshGroup, self);\r\n });\r\n\r\n clonedMeshGroup.metadata = {}; // babylon metadata refers to same instance of object after cloning so we clear it out\r\n const kbnode = getByDynamicId(mesh.id);\r\n if (kbnode && kbnode instanceof Connector) {\r\n const connector = kbnode as Connector;\r\n self._dropPreviewConnectors.set(connector, clonedMeshGroup as Mesh);\r\n clonedMeshGroup.setEnabled(connector._visible); //connector.enabled && !!this._draggable.showConnectors);\r\n } else {\r\n self.setOpacity(self._draggable.dragOpacity!, clonedMeshGroup);\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected connect(\r\n c: IConnectionMesh,\r\n followerMesh: TransformNode,\r\n mateType = this._draggable.connectionType,\r\n flip = false\r\n ) {\r\n this.viewer.pauseRenderWhile(() => {\r\n mateConnectors(\r\n {\r\n mateType: mateType!,\r\n flip: flip,\r\n offsetX: 0,\r\n offsetY: 0,\r\n offsetZ: 0,\r\n },\r\n followerMesh,\r\n c.otherConnectorMesh,\r\n c.dragConnectorMesh\r\n );\r\n });\r\n }\r\n\r\n protected hideDropPreview() {\r\n if (this._dropPreview) this._dropPreview.setEnabled(false);\r\n this._dragMesh.setEnabled(true); //show the drag node again\r\n if (this._dragFriendMeshes) {\r\n for (const friend of this._dragFriendMeshes) {\r\n friend.setEnabled(getByDynamicId(friend.id)!.visible);\r\n }\r\n }\r\n }\r\n\r\n protected disposeDropPreview() {\r\n this.hideDropPreview();\r\n if (this._dropPreview) this._dropPreview.dispose();\r\n if (this._dragFriendMeshes) this._dragFriendMeshes.clear();\r\n if (this._dragFriends) this._dragFriends.clear();\r\n }\r\n\r\n protected getConnectorLocalPoint(connector: Connector) {\r\n if (connector.positionMode == eConnectorPositionMode.absolute) {\r\n return connector.position;\r\n } else {\r\n //TODO\r\n }\r\n }\r\n\r\n protected setOpacity(value: number, ...nodes: TransformNode[]) {\r\n if (this.shouldSetOpacity()) {\r\n for (const node of nodes) {\r\n for (const m of this.getAllMeshes(node, m => !(m instanceof InstancedMesh))) {\r\n //set opacity of all non-connector meshes being dragged\r\n if (!m.metadata) {\r\n m.metadata = {};\r\n }\r\n m.metadata.originalVisibility = m.visibility;\r\n m.visibility = value;\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected resetOpacity(...nodes: TransformNode[]) {\r\n for (const node of nodes) {\r\n for (const m of this.getAllMeshes(node, m => !(m instanceof InstancedMesh))) {\r\n //set opacity of all non-connector meshes being dragged\r\n if (m.metadata && m.metadata.originalVisibility !== undefined) {\r\n m.visibility = m.metadata.originalVisibility;\r\n delete m.metadata.originalVisibility;\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected shouldSetOpacity() {\r\n return this._draggable.connectionMode != eConnectionMode.none && this._draggable.showConnectors; // && this._dragConnectors.size ;\r\n }\r\n\r\n /**get's all child meshes and includes the given node if it's a mesh */\r\n protected getAllMeshes(node: TransformNode, predicate?: (node: Node) => boolean) {\r\n const meshes = new Set(node.getChildMeshes(false, predicate));\r\n if (node instanceof AbstractMesh) meshes.add(node);\r\n return meshes;\r\n }\r\n}\r\n","import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { OBJExport } from '@babylonjs/serializers/OBJ';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { RendererManager } from '@view/render/renderer-manager';\r\n\r\nexport class ObjKb3dExporter {\r\n constructor(private scene: Scene, private rendererManager: RendererManager) {}\r\n\r\n /** generates the current scene into a glb file and returns an object url for it */\r\n public generateObj(meshNode?: MeshNode): string | null {\r\n let meshes: Mesh[];\r\n if (!meshNode) {\r\n meshes = this.scene.meshes.filter(this.shouldExportMesh);\r\n } else {\r\n const mesh = this.rendererManager.mesh.get3d(meshNode);\r\n if (mesh && mesh instanceof Mesh) {\r\n meshes = [mesh];\r\n } else {\r\n return null;\r\n }\r\n }\r\n return OBJExport.OBJ(meshes, false, undefined, meshes.length > 1);\r\n }\r\n\r\n public exportObj(filename = 'scene', meshNode?: MeshNode) {\r\n const objData = this.generateObj(meshNode);\r\n if (objData) {\r\n const blob = this.createObjBlob(objData);\r\n const link = document.createElement('a');\r\n document.body.appendChild(link);\r\n link.setAttribute('type', 'hidden');\r\n link.download = `${filename}.obj`;\r\n link.href = window.URL.createObjectURL(blob);\r\n link.click();\r\n setTimeout(() => {\r\n window.URL.revokeObjectURL(link.href);\r\n link.remove();\r\n });\r\n }\r\n }\r\n\r\n protected shouldExportMesh(mesh: AbstractMesh): mesh is Mesh {\r\n return mesh instanceof Mesh && mesh.isVisible && mesh.isEnabled() && !!getByDynamicId(mesh.id);\r\n }\r\n\r\n protected createObjBlob(objData: string) {\r\n const mimeType = { type: 'text/plain' };\r\n return new Blob([objData], mimeType);\r\n }\r\n}\r\n","import type { Nullable } from \"core/types\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { Geometry } from \"core/Meshes/geometry\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\n\r\n/**\r\n * Class for generating OBJ data from a Babylon scene.\r\n */\r\nexport class OBJExport {\r\n /**\r\n * Exports the geometry of a Mesh array in .OBJ file format (text)\r\n * @param mesh defines the list of meshes to serialize\r\n * @param materials defines if materials should be exported\r\n * @param matlibname defines the name of the associated mtl file\r\n * @param globalposition defines if the exported positions are globals or local to the exported mesh\r\n * @returns the OBJ content\r\n */\r\n public static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string {\r\n const output: string[] = [];\r\n let v = 1;\r\n // keep track of uv index in case mixed meshes are passed in\r\n let textureV = 1;\r\n\r\n if (materials) {\r\n if (!matlibname) {\r\n matlibname = \"mat\";\r\n }\r\n output.push(\"mtllib \" + matlibname + \".mtl\");\r\n }\r\n for (let j = 0; j < mesh.length; j++) {\r\n output.push(\"g object\" + j);\r\n output.push(\"o object_\" + j);\r\n\r\n //Uses the position of the item in the scene, to the file (this back to normal in the end)\r\n let inverseTransform: Nullable = null;\r\n if (globalposition) {\r\n const transform = mesh[j].computeWorldMatrix(true);\r\n inverseTransform = new Matrix();\r\n transform.invertToRef(inverseTransform);\r\n\r\n mesh[j].bakeTransformIntoVertices(transform);\r\n }\r\n\r\n //TODO: submeshes (groups)\r\n //TODO: smoothing groups (s 1, s off);\r\n if (materials) {\r\n const mat = mesh[j].material;\r\n\r\n if (mat) {\r\n output.push(\"usemtl \" + mat.id);\r\n }\r\n }\r\n const g: Nullable = mesh[j].geometry;\r\n\r\n if (!g) {\r\n Tools.Warn(\"No geometry is present on the mesh\");\r\n continue;\r\n }\r\n\r\n const trunkVerts = g.getVerticesData(\"position\");\r\n const trunkNormals = g.getVerticesData(\"normal\");\r\n const trunkUV = g.getVerticesData(\"uv\");\r\n const trunkFaces = g.getIndices();\r\n let currentV = 0;\r\n let currentTextureV = 0;\r\n\r\n if (!trunkVerts || !trunkFaces) {\r\n Tools.Warn(\"There are no position vertices or indices on the mesh!\");\r\n continue;\r\n }\r\n\r\n for (let i = 0; i < trunkVerts.length; i += 3) {\r\n // Babylon.js default is left handed, while OBJ default is right handed\r\n // Need to invert Z vertices unless Babylon is set to use a right handed system\r\n if (mesh[0].getScene().useRightHandedSystem) {\r\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\r\n } else {\r\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + -trunkVerts[i + 2]);\r\n }\r\n currentV++;\r\n }\r\n\r\n if (trunkNormals != null) {\r\n for (let i = 0; i < trunkNormals.length; i += 3) {\r\n output.push(\"vn \" + trunkNormals[i] + \" \" + trunkNormals[i + 1] + \" \" + trunkNormals[i + 2]);\r\n }\r\n }\r\n if (trunkUV != null) {\r\n for (let i = 0; i < trunkUV.length; i += 2) {\r\n output.push(\"vt \" + trunkUV[i] + \" \" + trunkUV[i + 1]);\r\n currentTextureV++;\r\n }\r\n }\r\n\r\n for (let i = 0; i < trunkFaces.length; i += 3) {\r\n const indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];\r\n const textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];\r\n const blanks: string[] = [\"\", \"\", \"\"];\r\n\r\n const facePositions = indices;\r\n const faceUVs = trunkUV != null ? textureIndices : blanks;\r\n const faceNormals = trunkNormals != null ? indices : blanks;\r\n\r\n output.push(\r\n \"f \" +\r\n facePositions[0] +\r\n \"/\" +\r\n faceUVs[0] +\r\n \"/\" +\r\n faceNormals[0] +\r\n \" \" +\r\n facePositions[1] +\r\n \"/\" +\r\n faceUVs[1] +\r\n \"/\" +\r\n faceNormals[1] +\r\n \" \" +\r\n facePositions[2] +\r\n \"/\" +\r\n faceUVs[2] +\r\n \"/\" +\r\n faceNormals[2]\r\n );\r\n }\r\n //back de previous matrix, to not change the original mesh in the scene\r\n if (globalposition && inverseTransform) {\r\n mesh[j].bakeTransformIntoVertices(inverseTransform);\r\n }\r\n v += currentV;\r\n textureV += currentTextureV;\r\n }\r\n const text: string = output.join(\"\\n\");\r\n return text;\r\n }\r\n\r\n /**\r\n * Exports the material(s) of a mesh in .MTL file format (text)\r\n * @param mesh defines the mesh to extract the material from\r\n * @returns the mtl content\r\n */\r\n //TODO: Export the materials of mesh array\r\n public static MTL(mesh: Mesh): string {\r\n const output = [];\r\n const m = mesh.material;\r\n output.push(\"newmtl mat1\");\r\n output.push(\" Ns \" + m.specularPower.toFixed(4));\r\n output.push(\" Ni 1.5000\");\r\n output.push(\" d \" + m.alpha.toFixed(4));\r\n output.push(\" Tr 0.0000\");\r\n output.push(\" Tf 1.0000 1.0000 1.0000\");\r\n output.push(\" illum 2\");\r\n output.push(\" Ka \" + m.ambientColor.r.toFixed(4) + \" \" + m.ambientColor.g.toFixed(4) + \" \" + m.ambientColor.b.toFixed(4));\r\n output.push(\" Kd \" + m.diffuseColor.r.toFixed(4) + \" \" + m.diffuseColor.g.toFixed(4) + \" \" + m.diffuseColor.b.toFixed(4));\r\n output.push(\" Ks \" + m.specularColor.r.toFixed(4) + \" \" + m.specularColor.g.toFixed(4) + \" \" + m.specularColor.b.toFixed(4));\r\n output.push(\" Ke \" + m.emissiveColor.r.toFixed(4) + \" \" + m.emissiveColor.g.toFixed(4) + \" \" + m.emissiveColor.b.toFixed(4));\r\n\r\n //TODO: uv scale, offset, wrap\r\n //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?\r\n const uvscale = \"\";\r\n\r\n if (m.ambientTexture) {\r\n output.push(\" map_Ka \" + uvscale + m.ambientTexture.name);\r\n }\r\n\r\n if (m.diffuseTexture) {\r\n output.push(\" map_Kd \" + uvscale + m.diffuseTexture.name);\r\n //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)\r\n }\r\n\r\n if (m.specularTexture) {\r\n output.push(\" map_Ks \" + uvscale + m.specularTexture.name);\r\n /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)\r\n if (m.useGlossinessFromSpecularMapAlpha) {\r\n output.push(\" map_Ns \"+uvscale + m.specularTexture.name);\r\n }\r\n */\r\n }\r\n\r\n /* TODO: emissive texture not in .MAT format (???)\r\n if (m.emissiveTexture) {\r\n output.push(\" map_d \"+uvscale+m.emissiveTexture.name);\r\n }\r\n */\r\n\r\n if (m.bumpTexture) {\r\n output.push(\" map_bump -imfchan z \" + uvscale + m.bumpTexture.name);\r\n }\r\n\r\n if (m.opacityTexture) {\r\n output.push(\" map_d \" + uvscale + m.opacityTexture.name);\r\n }\r\n\r\n const text = output.join(\"\\n\");\r\n return text;\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"boundingBoxRendererFragmentDeclaration\";\nconst shader = `uniform vec4 color;\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const boundingBoxRendererFragmentDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"boundingBoxRendererUboDeclaration\";\nconst shader = `#ifdef WEBGL2\nuniform vec4 color;uniform mat4 world;uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\n#else\nlayout(std140,column_major) uniform;uniform BoundingBoxRenderer {vec4 color;mat4 world;mat4 viewProjection;mat4 viewProjectionR;};\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const boundingBoxRendererUboDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/boundingBoxRendererFragmentDeclaration\";\nimport \"./ShadersInclude/boundingBoxRendererUboDeclaration\";\n\nconst name = \"boundingBoxRendererPixelShader\";\nconst shader = `#include<__decl__boundingBoxRendererFragment>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const boundingBoxRendererPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"boundingBoxRendererVertexDeclaration\";\nconst shader = `uniform mat4 world;uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const boundingBoxRendererVertexDeclaration = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/boundingBoxRendererVertexDeclaration\";\nimport \"./ShadersInclude/boundingBoxRendererUboDeclaration\";\n\nconst name = \"boundingBoxRendererVertexShader\";\nconst shader = `attribute vec3 position;\n#include<__decl__boundingBoxRendererVertex>\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec4 worldPos=world*vec4(position,1.0);\n#ifdef MULTIVIEW\nif (gl_ViewID_OVR==0u) {gl_Position=viewProjection*worldPos;} else {gl_Position=viewProjectionR*worldPos;}\n#else\ngl_Position=viewProjection*worldPos;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const boundingBoxRendererVertexShader = { name, shader };\n","import { Scene } from \"../scene\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Matrix } from \"../Maths/math.vector\";\r\nimport { SmartArray } from \"../Misc/smartArray\";\r\nimport type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport type { BoundingBox } from \"../Culling/boundingBox\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { ShaderMaterial } from \"../Materials/shaderMaterial\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\nimport { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport { CreateBoxVertexData } from \"../Meshes/Builders/boxBuilder\";\r\n\r\nimport \"../Shaders/boundingBoxRenderer.fragment\";\r\nimport \"../Shaders/boundingBoxRenderer.vertex\";\r\n\r\ndeclare module \"../scene\" {\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _boundingBoxRenderer: BoundingBoxRenderer;\r\n\r\n /** @internal (Backing field) */\r\n _forceShowBoundingBoxes: boolean;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if all bounding boxes must be rendered\r\n */\r\n forceShowBoundingBoxes: boolean;\r\n\r\n /**\r\n * Gets the bounding box renderer associated with the scene\r\n * @returns a BoundingBoxRenderer\r\n */\r\n getBoundingBoxRenderer(): BoundingBoxRenderer;\r\n }\r\n}\r\n\r\nObject.defineProperty(Scene.prototype, \"forceShowBoundingBoxes\", {\r\n get: function (this: Scene) {\r\n return this._forceShowBoundingBoxes || false;\r\n },\r\n set: function (this: Scene, value: boolean) {\r\n this._forceShowBoundingBoxes = value;\r\n // Lazyly creates a BB renderer if needed.\r\n if (value) {\r\n this.getBoundingBoxRenderer();\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\nScene.prototype.getBoundingBoxRenderer = function (): BoundingBoxRenderer {\r\n if (!this._boundingBoxRenderer) {\r\n this._boundingBoxRenderer = new BoundingBoxRenderer(this);\r\n }\r\n\r\n return this._boundingBoxRenderer;\r\n};\r\n\r\ndeclare module \"../Meshes/abstractMesh\" {\r\n export interface AbstractMesh {\r\n /** @internal (Backing field) */\r\n _showBoundingBox: boolean;\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the bounding box must be rendered as well (false by default)\r\n */\r\n showBoundingBox: boolean;\r\n }\r\n}\r\n\r\nObject.defineProperty(AbstractMesh.prototype, \"showBoundingBox\", {\r\n get: function (this: AbstractMesh) {\r\n return this._showBoundingBox || false;\r\n },\r\n set: function (this: AbstractMesh, value: boolean) {\r\n this._showBoundingBox = value;\r\n // Lazyly creates a BB renderer if needed.\r\n if (value) {\r\n this.getScene().getBoundingBoxRenderer();\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * Component responsible of rendering the bounding box of the meshes in a scene.\r\n * This is usually used through the mesh.showBoundingBox or the scene.forceShowBoundingBoxes properties\r\n */\r\nexport class BoundingBoxRenderer implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_BOUNDINGBOXRENDERER;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Color of the bounding box lines placed in front of an object\r\n */\r\n public frontColor = new Color3(1, 1, 1);\r\n /**\r\n * Color of the bounding box lines placed behind an object\r\n */\r\n public backColor = new Color3(0.1, 0.1, 0.1);\r\n /**\r\n * Defines if the renderer should show the back lines or not\r\n */\r\n public showBackLines = true;\r\n\r\n /**\r\n * Observable raised before rendering a bounding box\r\n */\r\n public onBeforeBoxRenderingObservable = new Observable();\r\n\r\n /**\r\n * Observable raised after rendering a bounding box\r\n */\r\n public onAfterBoxRenderingObservable = new Observable();\r\n\r\n /**\r\n * Observable raised after resources are created\r\n */\r\n public onResourcesReadyObservable = new Observable();\r\n\r\n /**\r\n * When false, no bounding boxes will be rendered\r\n */\r\n public enabled = true;\r\n\r\n /**\r\n * @internal\r\n */\r\n public renderList = new SmartArray(32);\r\n\r\n private _colorShader: ShaderMaterial;\r\n private _colorShaderForOcclusionQuery: ShaderMaterial;\r\n private _vertexBuffers: { [key: string]: Nullable } = {};\r\n private _indexBuffer: DataBuffer;\r\n private _fillIndexBuffer: Nullable = null;\r\n private _fillIndexData: Nullable = null;\r\n private _uniformBufferFront: UniformBuffer;\r\n private _uniformBufferBack: UniformBuffer;\r\n private _renderPassIdForOcclusionQuery: number;\r\n\r\n /**\r\n * Instantiates a new bounding box renderer in a scene.\r\n * @param scene the scene the renderer renders in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n scene._addComponent(this);\r\n this._uniformBufferFront = new UniformBuffer(this.scene.getEngine(), undefined, undefined, \"BoundingBoxRendererFront\", !this.scene.getEngine().isWebGPU);\r\n this._buildUniformLayout(this._uniformBufferFront);\r\n this._uniformBufferBack = new UniformBuffer(this.scene.getEngine(), undefined, undefined, \"BoundingBoxRendererBack\", !this.scene.getEngine().isWebGPU);\r\n this._buildUniformLayout(this._uniformBufferBack);\r\n }\r\n\r\n private _buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"color\", 4);\r\n ubo.addUniform(\"world\", 16);\r\n ubo.addUniform(\"viewProjection\", 16);\r\n ubo.addUniform(\"viewProjectionR\", 16);\r\n ubo.create();\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {\r\n this.scene._beforeEvaluateActiveMeshStage.registerStep(SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER, this, this.reset);\r\n\r\n this.scene._preActiveMeshStage.registerStep(SceneComponentConstants.STEP_PREACTIVEMESH_BOUNDINGBOXRENDERER, this, this._preActiveMesh);\r\n\r\n this.scene._evaluateSubMeshStage.registerStep(SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER, this, this._evaluateSubMesh);\r\n\r\n this.scene._afterRenderingGroupDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_BOUNDINGBOXRENDERER, this, this.render);\r\n }\r\n\r\n private _evaluateSubMesh(mesh: AbstractMesh, subMesh: SubMesh): void {\r\n if (mesh.showSubMeshesBoundingBox) {\r\n const boundingInfo = subMesh.getBoundingInfo();\r\n if (boundingInfo !== null && boundingInfo !== undefined) {\r\n boundingInfo.boundingBox._tag = mesh.renderingGroupId;\r\n this.renderList.push(boundingInfo.boundingBox);\r\n }\r\n }\r\n }\r\n\r\n private _preActiveMesh(mesh: AbstractMesh): void {\r\n if (mesh.showBoundingBox || this.scene.forceShowBoundingBoxes) {\r\n const boundingInfo = mesh.getBoundingInfo();\r\n boundingInfo.boundingBox._tag = mesh.renderingGroupId;\r\n this.renderList.push(boundingInfo.boundingBox);\r\n }\r\n }\r\n\r\n private _prepareResources(): void {\r\n if (this._colorShader) {\r\n return;\r\n }\r\n\r\n this._colorShader = new ShaderMaterial(\r\n \"colorShader\",\r\n this.scene,\r\n \"boundingBoxRenderer\",\r\n {\r\n attributes: [VertexBuffer.PositionKind],\r\n uniforms: [\"world\", \"viewProjection\", \"viewProjectionR\", \"color\"],\r\n uniformBuffers: [\"BoundingBoxRenderer\"],\r\n },\r\n false\r\n );\r\n this._colorShader.doNotSerialize = true;\r\n\r\n this._colorShader.reservedDataStore = {\r\n hidden: true,\r\n };\r\n\r\n this._colorShaderForOcclusionQuery = new ShaderMaterial(\r\n \"colorShaderOccQuery\",\r\n this.scene,\r\n \"boundingBoxRenderer\",\r\n {\r\n attributes: [VertexBuffer.PositionKind],\r\n uniforms: [\"world\", \"viewProjection\", \"viewProjectionR\", \"color\"],\r\n uniformBuffers: [\"BoundingBoxRenderer\"],\r\n },\r\n true\r\n );\r\n this._colorShaderForOcclusionQuery.doNotSerialize = true;\r\n\r\n this._colorShaderForOcclusionQuery.reservedDataStore = {\r\n hidden: true,\r\n };\r\n\r\n const engine = this.scene.getEngine();\r\n const boxdata = CreateBoxVertexData({ size: 1.0 });\r\n this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);\r\n this._createIndexBuffer();\r\n this._fillIndexData = boxdata.indices;\r\n this.onResourcesReadyObservable.notifyObservers(this);\r\n }\r\n\r\n private _createIndexBuffer(): void {\r\n const engine = this.scene.getEngine();\r\n this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);\r\n }\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n const vb = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (vb) {\r\n vb._rebuild();\r\n }\r\n this._createIndexBuffer();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public reset(): void {\r\n this.renderList.reset();\r\n }\r\n\r\n /**\r\n * Render the bounding boxes of a specific rendering group\r\n * @param renderingGroupId defines the rendering group to render\r\n */\r\n public render(renderingGroupId: number): void {\r\n if (this.renderList.length === 0 || !this.enabled) {\r\n return;\r\n }\r\n\r\n this._prepareResources();\r\n\r\n if (!this._colorShader.isReady()) {\r\n return;\r\n }\r\n\r\n const engine = this.scene.getEngine();\r\n engine.setDepthWrite(false);\r\n\r\n const transformMatrix = this.scene.getTransformMatrix();\r\n\r\n for (let boundingBoxIndex = 0; boundingBoxIndex < this.renderList.length; boundingBoxIndex++) {\r\n const boundingBox = this.renderList.data[boundingBoxIndex];\r\n if (boundingBox._tag !== renderingGroupId) {\r\n continue;\r\n }\r\n\r\n this._createWrappersForBoundingBox(boundingBox);\r\n this.onBeforeBoxRenderingObservable.notifyObservers(boundingBox);\r\n\r\n const min = boundingBox.minimum;\r\n const max = boundingBox.maximum;\r\n const diff = max.subtract(min);\r\n const median = min.add(diff.scale(0.5));\r\n\r\n const worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z).multiply(Matrix.Translation(median.x, median.y, median.z)).multiply(boundingBox.getWorldMatrix());\r\n\r\n const useReverseDepthBuffer = engine.useReverseDepthBuffer;\r\n\r\n if (this.showBackLines) {\r\n const drawWrapperBack = boundingBox._drawWrapperBack ?? this._colorShader._getDrawWrapper();\r\n\r\n this._colorShader._preBind(drawWrapperBack);\r\n\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());\r\n\r\n // Back\r\n if (useReverseDepthBuffer) {\r\n engine.setDepthFunctionToLessOrEqual();\r\n } else {\r\n engine.setDepthFunctionToGreaterOrEqual();\r\n }\r\n this._uniformBufferBack.bindToEffect(drawWrapperBack.effect!, \"BoundingBoxRenderer\");\r\n this._uniformBufferBack.updateColor4(\"color\", this.backColor, 1);\r\n this._uniformBufferBack.updateMatrix(\"world\", worldMatrix);\r\n this._uniformBufferBack.updateMatrix(\"viewProjection\", transformMatrix);\r\n this._uniformBufferBack.update();\r\n\r\n // Draw order\r\n engine.drawElementsType(Material.LineListDrawMode, 0, 24);\r\n }\r\n\r\n const drawWrapperFront = boundingBox._drawWrapperFront ?? this._colorShader._getDrawWrapper();\r\n\r\n this._colorShader._preBind(drawWrapperFront);\r\n\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());\r\n\r\n // Front\r\n if (useReverseDepthBuffer) {\r\n engine.setDepthFunctionToGreater();\r\n } else {\r\n engine.setDepthFunctionToLess();\r\n }\r\n this._uniformBufferFront.bindToEffect(drawWrapperFront.effect!, \"BoundingBoxRenderer\");\r\n this._uniformBufferFront.updateColor4(\"color\", this.frontColor, 1);\r\n this._uniformBufferFront.updateMatrix(\"world\", worldMatrix);\r\n this._uniformBufferFront.updateMatrix(\"viewProjection\", transformMatrix);\r\n this._uniformBufferFront.update();\r\n\r\n // Draw order\r\n engine.drawElementsType(Material.LineListDrawMode, 0, 24);\r\n\r\n this.onAfterBoxRenderingObservable.notifyObservers(boundingBox);\r\n }\r\n this._colorShader.unbind();\r\n engine.setDepthFunctionToLessOrEqual();\r\n engine.setDepthWrite(true);\r\n }\r\n\r\n private _createWrappersForBoundingBox(boundingBox: BoundingBox): void {\r\n if (!boundingBox._drawWrapperFront) {\r\n const engine = this.scene.getEngine();\r\n\r\n boundingBox._drawWrapperFront = new DrawWrapper(engine);\r\n boundingBox._drawWrapperBack = new DrawWrapper(engine);\r\n\r\n boundingBox._drawWrapperFront.setEffect(this._colorShader.getEffect());\r\n boundingBox._drawWrapperBack.setEffect(this._colorShader.getEffect());\r\n }\r\n }\r\n\r\n /**\r\n * In case of occlusion queries, we can render the occlusion bounding box through this method\r\n * @param mesh Define the mesh to render the occlusion bounding box for\r\n */\r\n public renderOcclusionBoundingBox(mesh: AbstractMesh): void {\r\n const engine = this.scene.getEngine();\r\n\r\n if (this._renderPassIdForOcclusionQuery === undefined) {\r\n this._renderPassIdForOcclusionQuery = engine.createRenderPassId(`Render pass for occlusion query`);\r\n }\r\n\r\n const currentRenderPassId = engine.currentRenderPassId;\r\n\r\n engine.currentRenderPassId = this._renderPassIdForOcclusionQuery;\r\n\r\n this._prepareResources();\r\n\r\n const subMesh = mesh.subMeshes[0];\r\n\r\n if (!this._colorShaderForOcclusionQuery.isReady(mesh, undefined, subMesh) || !mesh.hasBoundingInfo) {\r\n engine.currentRenderPassId = currentRenderPassId;\r\n return;\r\n }\r\n\r\n if (!this._fillIndexBuffer) {\r\n this._fillIndexBuffer = engine.createIndexBuffer(this._fillIndexData!);\r\n }\r\n\r\n const useReverseDepthBuffer = engine.useReverseDepthBuffer;\r\n\r\n engine.setDepthWrite(false);\r\n engine.setColorWrite(false);\r\n\r\n const boundingBox = mesh.getBoundingInfo().boundingBox;\r\n const min = boundingBox.minimum;\r\n const max = boundingBox.maximum;\r\n const diff = max.subtract(min);\r\n const median = min.add(diff.scale(0.5));\r\n\r\n const worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z).multiply(Matrix.Translation(median.x, median.y, median.z)).multiply(boundingBox.getWorldMatrix());\r\n\r\n const drawWrapper = subMesh._drawWrapper;\r\n\r\n this._colorShaderForOcclusionQuery._preBind(drawWrapper);\r\n\r\n engine.bindBuffers(this._vertexBuffers, this._fillIndexBuffer, drawWrapper.effect);\r\n\r\n if (useReverseDepthBuffer) {\r\n engine.setDepthFunctionToGreater();\r\n } else {\r\n engine.setDepthFunctionToLess();\r\n }\r\n\r\n this.scene.resetCachedMaterial();\r\n\r\n this._uniformBufferFront.bindToEffect(drawWrapper.effect!, \"BoundingBoxRenderer\");\r\n this._uniformBufferFront.updateMatrix(\"world\", worldMatrix);\r\n this._uniformBufferFront.updateMatrix(\"viewProjection\", this.scene.getTransformMatrix());\r\n this._uniformBufferFront.update();\r\n\r\n engine.drawElementsType(Material.TriangleFillMode, 0, 36);\r\n\r\n this._colorShaderForOcclusionQuery.unbind();\r\n engine.setDepthFunctionToLessOrEqual();\r\n engine.setDepthWrite(true);\r\n engine.setColorWrite(true);\r\n\r\n engine.currentRenderPassId = currentRenderPassId;\r\n }\r\n\r\n /**\r\n * Dispose and release the resources attached to this renderer.\r\n */\r\n public dispose(): void {\r\n if (this._renderPassIdForOcclusionQuery !== undefined) {\r\n this.scene.getEngine().releaseRenderPassId(this._renderPassIdForOcclusionQuery);\r\n this._renderPassIdForOcclusionQuery = undefined as any;\r\n }\r\n\r\n if (!this._colorShader) {\r\n return;\r\n }\r\n\r\n this.onBeforeBoxRenderingObservable.clear();\r\n this.onAfterBoxRenderingObservable.clear();\r\n this.onResourcesReadyObservable.clear();\r\n\r\n this.renderList.dispose();\r\n\r\n this._colorShader.dispose();\r\n this._colorShaderForOcclusionQuery.dispose();\r\n\r\n this._uniformBufferFront.dispose();\r\n this._uniformBufferBack.dispose();\r\n\r\n const buffer = this._vertexBuffers[VertexBuffer.PositionKind];\r\n if (buffer) {\r\n buffer.dispose();\r\n this._vertexBuffers[VertexBuffer.PositionKind] = null;\r\n }\r\n this.scene.getEngine()._releaseBuffer(this._indexBuffer);\r\n\r\n if (this._fillIndexBuffer) {\r\n this.scene.getEngine()._releaseBuffer(this._fillIndexBuffer);\r\n this._fillIndexBuffer = null;\r\n }\r\n }\r\n}\r\n","import { Vector3, Matrix } from \"../Maths/math.vector\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\n/**\r\n * Class containing a set of static utilities functions for managing Pivots\r\n * @internal\r\n */\r\nexport class PivotTools {\r\n // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)\r\n // store/remove pivot point should only be applied during their outermost calls\r\n private static _PivotCached = 0;\r\n private static _OldPivotPoint = new Vector3();\r\n private static _PivotTranslation = new Vector3();\r\n private static _PivotTmpVector = new Vector3();\r\n private static _PivotPostMultiplyPivotMatrix = false;\r\n /**\r\n * @internal\r\n */\r\n public static _RemoveAndStorePivotPoint(mesh: TransformNode) {\r\n if (mesh && PivotTools._PivotCached === 0) {\r\n // Save old pivot and set pivot to 0,0,0\r\n mesh.getPivotPointToRef(PivotTools._OldPivotPoint);\r\n PivotTools._PivotPostMultiplyPivotMatrix = mesh._postMultiplyPivotMatrix;\r\n if (!PivotTools._OldPivotPoint.equalsToFloats(0, 0, 0)) {\r\n mesh.setPivotMatrix(Matrix.IdentityReadOnly);\r\n PivotTools._OldPivotPoint.subtractToRef(mesh.getPivotPoint(), PivotTools._PivotTranslation);\r\n PivotTools._PivotTmpVector.copyFromFloats(1, 1, 1);\r\n PivotTools._PivotTmpVector.subtractInPlace(mesh.scaling);\r\n PivotTools._PivotTmpVector.multiplyInPlace(PivotTools._PivotTranslation);\r\n mesh.position.addInPlace(PivotTools._PivotTmpVector);\r\n }\r\n }\r\n PivotTools._PivotCached++;\r\n }\r\n /**\r\n * @internal\r\n */\r\n public static _RestorePivotPoint(mesh: TransformNode) {\r\n if (mesh && !PivotTools._OldPivotPoint.equalsToFloats(0, 0, 0) && PivotTools._PivotCached === 1) {\r\n mesh.setPivotPoint(PivotTools._OldPivotPoint);\r\n mesh._postMultiplyPivotMatrix = PivotTools._PivotPostMultiplyPivotMatrix;\r\n PivotTools._PivotTmpVector.copyFromFloats(1, 1, 1);\r\n PivotTools._PivotTmpVector.subtractInPlace(mesh.scaling);\r\n PivotTools._PivotTmpVector.multiplyInPlace(PivotTools._PivotTranslation);\r\n mesh.position.subtractInPlace(PivotTools._PivotTmpVector);\r\n }\r\n this._PivotCached--;\r\n }\r\n}\r\n","import type { Behavior } from \"../../Behaviors/behavior\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport { Ray } from \"../../Culling/ray\";\r\nimport { PivotTools } from \"../../Misc/pivotTools\";\r\nimport type { ArcRotateCamera } from \"../../Cameras/arcRotateCamera\";\r\nimport { CreatePlane } from \"../../Meshes/Builders/planeBuilder\";\r\n\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n\r\n/**\r\n * A behavior that when attached to a mesh will allow the mesh to be dragged around the screen based on pointer events\r\n */\r\nexport class PointerDragBehavior implements Behavior {\r\n private static _AnyMouseId = -2;\r\n /**\r\n * Abstract mesh the behavior is set on\r\n */\r\n public attachedNode: AbstractMesh;\r\n protected _dragPlane: Mesh;\r\n private _scene: Scene;\r\n private _pointerObserver: Nullable>;\r\n private _beforeRenderObserver: Nullable>;\r\n private static _PlaneScene: Scene;\r\n private _useAlternatePickedPointAboveMaxDragAngleDragSpeed = -1.1;\r\n private _activeDragButton: number = -1;\r\n private _activePointerInfo: Nullable;\r\n /**\r\n * The maximum tolerated angle between the drag plane and dragging pointer rays to trigger pointer events. Set to 0 to allow any angle (default: 0)\r\n */\r\n public maxDragAngle = 0;\r\n /**\r\n * Butttons that can be used to initiate a drag\r\n */\r\n public dragButtons = [0, 1, 2];\r\n /**\r\n * @internal\r\n */\r\n public _useAlternatePickedPointAboveMaxDragAngle = false;\r\n /**\r\n * Get or set the currentDraggingPointerId\r\n * @deprecated Please use currentDraggingPointerId instead\r\n */\r\n public get currentDraggingPointerID(): number {\r\n return this.currentDraggingPointerId;\r\n }\r\n public set currentDraggingPointerID(currentDraggingPointerID: number) {\r\n this.currentDraggingPointerId = currentDraggingPointerID;\r\n }\r\n /**\r\n * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)\r\n */\r\n public currentDraggingPointerId = -1;\r\n /**\r\n * The last position where the pointer hit the drag plane in world space\r\n */\r\n public lastDragPosition: Vector3;\r\n /**\r\n * If the behavior is currently in a dragging state\r\n */\r\n public dragging = false;\r\n /**\r\n * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)\r\n */\r\n public dragDeltaRatio = 0.2;\r\n /**\r\n * If the drag plane orientation should be updated during the dragging (Default: true)\r\n */\r\n public updateDragPlane = true;\r\n // Debug mode will display drag planes to help visualize behavior\r\n private _debugMode = false;\r\n private _moving = false;\r\n /**\r\n * Fires each time the attached mesh is dragged with the pointer\r\n * * delta between last drag position and current drag position in world space\r\n * * dragDistance along the drag axis\r\n * * dragPlaneNormal normal of the current drag plane used during the drag\r\n * * dragPlanePoint in world space where the drag intersects the drag plane\r\n *\r\n * (if validatedDrag is used, the position of the attached mesh might not equal dragPlanePoint)\r\n */\r\n public onDragObservable = new Observable<{\r\n delta: Vector3;\r\n dragPlanePoint: Vector3;\r\n dragPlaneNormal: Vector3;\r\n dragDistance: number;\r\n pointerId: number;\r\n pointerInfo: Nullable;\r\n }>();\r\n /**\r\n * Fires each time a drag begins (eg. mouse down on mesh)\r\n * * dragPlanePoint in world space where the drag intersects the drag plane\r\n *\r\n * (if validatedDrag is used, the position of the attached mesh might not equal dragPlanePoint)\r\n */\r\n public onDragStartObservable = new Observable<{ dragPlanePoint: Vector3; pointerId: number; pointerInfo: Nullable }>();\r\n /**\r\n * Fires each time a drag ends (eg. mouse release after drag)\r\n * * dragPlanePoint in world space where the drag intersects the drag plane\r\n *\r\n * (if validatedDrag is used, the position of the attached mesh might not equal dragPlanePoint)\r\n */\r\n public onDragEndObservable = new Observable<{ dragPlanePoint: Vector3; pointerId: number; pointerInfo: Nullable }>();\r\n /**\r\n * Fires each time behavior enabled state changes\r\n */\r\n public onEnabledObservable = new Observable();\r\n\r\n /**\r\n * If the attached mesh should be moved when dragged\r\n */\r\n public moveAttached = true;\r\n\r\n /**\r\n * If the drag behavior will react to drag events (Default: true)\r\n */\r\n public set enabled(value: boolean) {\r\n if (value != this._enabled) {\r\n this.onEnabledObservable.notifyObservers(value);\r\n }\r\n this._enabled = value;\r\n }\r\n\r\n public get enabled() {\r\n return this._enabled;\r\n }\r\n private _enabled = true;\r\n\r\n /**\r\n * If pointer events should start and release the drag (Default: true)\r\n */\r\n public startAndReleaseDragOnPointerEvents = true;\r\n /**\r\n * If camera controls should be detached during the drag\r\n */\r\n public detachCameraControls = true;\r\n\r\n /**\r\n * If set, the drag plane/axis will be rotated based on the attached mesh's world rotation (Default: true)\r\n */\r\n public useObjectOrientationForDragging = true;\r\n\r\n private _options: { dragAxis?: Vector3; dragPlaneNormal?: Vector3 };\r\n\r\n /**\r\n * Gets the options used by the behavior\r\n */\r\n public get options(): { dragAxis?: Vector3; dragPlaneNormal?: Vector3 } {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * Sets the options used by the behavior\r\n */\r\n public set options(options: { dragAxis?: Vector3; dragPlaneNormal?: Vector3 }) {\r\n this._options = options;\r\n }\r\n\r\n /**\r\n * Creates a pointer drag behavior that can be attached to a mesh\r\n * @param options The drag axis or normal of the plane that will be dragged across. If no options are specified the drag plane will always face the ray's origin (eg. camera)\r\n * @param options.dragAxis\r\n * @param options.dragPlaneNormal\r\n */\r\n constructor(options?: { dragAxis?: Vector3; dragPlaneNormal?: Vector3 }) {\r\n this._options = options ? options : {};\r\n\r\n let optionCount = 0;\r\n if (this._options.dragAxis) {\r\n optionCount++;\r\n }\r\n if (this._options.dragPlaneNormal) {\r\n optionCount++;\r\n }\r\n if (optionCount > 1) {\r\n throw \"Multiple drag modes specified in dragBehavior options. Only one expected\";\r\n }\r\n }\r\n\r\n /**\r\n * Predicate to determine if it is valid to move the object to a new position when it is moved\r\n * @param targetPosition\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public validateDrag = (targetPosition: Vector3) => {\r\n return true;\r\n };\r\n\r\n /**\r\n * The name of the behavior\r\n */\r\n public get name(): string {\r\n return \"PointerDrag\";\r\n }\r\n\r\n /**\r\n * Initializes the behavior\r\n */\r\n public init() {}\r\n\r\n private _tmpVector = new Vector3(0, 0, 0);\r\n private _alternatePickedPoint = new Vector3(0, 0, 0);\r\n private _worldDragAxis = new Vector3(0, 0, 0);\r\n private _targetPosition = new Vector3(0, 0, 0);\r\n private _attachedToElement: boolean = false;\r\n /**\r\n * Attaches the drag behavior the passed in mesh\r\n * @param ownerNode The mesh that will be dragged around once attached\r\n * @param predicate Predicate to use for pick filtering\r\n */\r\n public attach(ownerNode: AbstractMesh, predicate?: (m: AbstractMesh) => boolean): void {\r\n this._scene = ownerNode.getScene();\r\n ownerNode.isNearGrabbable = true;\r\n this.attachedNode = ownerNode;\r\n\r\n // Initialize drag plane to not interfere with existing scene\r\n if (!PointerDragBehavior._PlaneScene) {\r\n if (this._debugMode) {\r\n PointerDragBehavior._PlaneScene = this._scene;\r\n } else {\r\n PointerDragBehavior._PlaneScene = new Scene(this._scene.getEngine(), { virtual: true });\r\n PointerDragBehavior._PlaneScene.detachControl();\r\n this._scene.onDisposeObservable.addOnce(() => {\r\n PointerDragBehavior._PlaneScene.dispose();\r\n (PointerDragBehavior._PlaneScene) = null;\r\n });\r\n }\r\n }\r\n this._dragPlane = CreatePlane(\r\n \"pointerDragPlane\",\r\n { size: this._debugMode ? 1 : 10000, updatable: false, sideOrientation: Mesh.DOUBLESIDE },\r\n PointerDragBehavior._PlaneScene\r\n );\r\n\r\n // State of the drag\r\n this.lastDragPosition = new Vector3(0, 0, 0);\r\n\r\n const pickPredicate = predicate\r\n ? predicate\r\n : (m: AbstractMesh) => {\r\n return this.attachedNode == m || m.isDescendantOf(this.attachedNode);\r\n };\r\n\r\n this._pointerObserver = this._scene.onPointerObservable.add((pointerInfo) => {\r\n if (!this.enabled) {\r\n // If behavior is disabled before releaseDrag is ever called, call it now.\r\n if (this._attachedToElement) {\r\n this.releaseDrag();\r\n }\r\n\r\n return;\r\n }\r\n\r\n if (pointerInfo.type == PointerEventTypes.POINTERDOWN) {\r\n if (\r\n this.startAndReleaseDragOnPointerEvents &&\r\n !this.dragging &&\r\n pointerInfo.pickInfo &&\r\n pointerInfo.pickInfo.hit &&\r\n pointerInfo.pickInfo.pickedMesh &&\r\n pointerInfo.pickInfo.pickedPoint &&\r\n pointerInfo.pickInfo.ray &&\r\n pickPredicate(pointerInfo.pickInfo.pickedMesh)\r\n ) {\r\n if (this._activeDragButton === -1 && this.dragButtons.indexOf(pointerInfo.event.button) !== -1) {\r\n this._activeDragButton = pointerInfo.event.button;\r\n this._activePointerInfo = pointerInfo;\r\n this._startDrag((pointerInfo.event).pointerId, pointerInfo.pickInfo.ray, pointerInfo.pickInfo.pickedPoint);\r\n }\r\n }\r\n } else if (pointerInfo.type == PointerEventTypes.POINTERUP) {\r\n if (\r\n this.startAndReleaseDragOnPointerEvents &&\r\n this.currentDraggingPointerId == (pointerInfo.event).pointerId &&\r\n (this._activeDragButton === pointerInfo.event.button || this._activeDragButton === -1)\r\n ) {\r\n this.releaseDrag();\r\n }\r\n } else if (pointerInfo.type == PointerEventTypes.POINTERMOVE) {\r\n const pointerId = (pointerInfo.event).pointerId;\r\n\r\n // If drag was started with anyMouseID specified, set pointerID to the next mouse that moved\r\n if (this.currentDraggingPointerId === PointerDragBehavior._AnyMouseId && pointerId !== PointerDragBehavior._AnyMouseId) {\r\n const evt = pointerInfo.event;\r\n const isMouseEvent = evt.pointerType === \"mouse\" || (!this._scene.getEngine().hostInformation.isMobile && evt instanceof MouseEvent);\r\n if (isMouseEvent) {\r\n if (this._lastPointerRay[this.currentDraggingPointerId]) {\r\n this._lastPointerRay[pointerId] = this._lastPointerRay[this.currentDraggingPointerId];\r\n delete this._lastPointerRay[this.currentDraggingPointerId];\r\n }\r\n this.currentDraggingPointerId = pointerId;\r\n }\r\n }\r\n\r\n // Keep track of last pointer ray, this is used simulating the start of a drag in startDrag()\r\n if (!this._lastPointerRay[pointerId]) {\r\n this._lastPointerRay[pointerId] = new Ray(new Vector3(), new Vector3());\r\n }\r\n if (pointerInfo.pickInfo && pointerInfo.pickInfo.ray) {\r\n this._lastPointerRay[pointerId].origin.copyFrom(pointerInfo.pickInfo.ray.origin);\r\n this._lastPointerRay[pointerId].direction.copyFrom(pointerInfo.pickInfo.ray.direction);\r\n\r\n if (this.currentDraggingPointerId == pointerId && this.dragging) {\r\n this._moveDrag(pointerInfo.pickInfo.ray);\r\n }\r\n }\r\n }\r\n });\r\n\r\n this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(() => {\r\n if (this._moving && this.moveAttached) {\r\n let needMatrixUpdate = false;\r\n PivotTools._RemoveAndStorePivotPoint(this.attachedNode);\r\n // Slowly move mesh to avoid jitter\r\n this._targetPosition.subtractToRef(this.attachedNode.absolutePosition, this._tmpVector);\r\n this._tmpVector.scaleInPlace(this.dragDeltaRatio);\r\n this.attachedNode.getAbsolutePosition().addToRef(this._tmpVector, this._tmpVector);\r\n if (this.validateDrag(this._tmpVector)) {\r\n this.attachedNode.setAbsolutePosition(this._tmpVector);\r\n needMatrixUpdate = true;\r\n }\r\n PivotTools._RestorePivotPoint(this.attachedNode);\r\n if (needMatrixUpdate) {\r\n this.attachedNode.computeWorldMatrix();\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Force release the drag action by code.\r\n */\r\n public releaseDrag() {\r\n if (this.dragging) {\r\n this.dragging = false;\r\n this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerId, pointerInfo: this._activePointerInfo });\r\n }\r\n\r\n this.currentDraggingPointerId = -1;\r\n this._activeDragButton = -1;\r\n this._activePointerInfo = null;\r\n this._moving = false;\r\n\r\n // Reattach camera controls\r\n if (this.detachCameraControls && this._attachedToElement && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {\r\n if (this._scene.activeCamera.getClassName() === \"ArcRotateCamera\") {\r\n const arcRotateCamera = this._scene.activeCamera as ArcRotateCamera;\r\n arcRotateCamera.attachControl(\r\n arcRotateCamera.inputs ? arcRotateCamera.inputs.noPreventDefault : true,\r\n arcRotateCamera._useCtrlForPanning,\r\n arcRotateCamera._panningMouseButton\r\n );\r\n } else {\r\n this._scene.activeCamera.attachControl(this._scene.activeCamera.inputs ? this._scene.activeCamera.inputs.noPreventDefault : true);\r\n }\r\n this._attachedToElement = false;\r\n }\r\n }\r\n\r\n private _startDragRay = new Ray(new Vector3(), new Vector3());\r\n private _lastPointerRay: { [key: number]: Ray } = {};\r\n /**\r\n * Simulates the start of a pointer drag event on the behavior\r\n * @param pointerId pointerID of the pointer that should be simulated (Default: Any mouse pointer ID)\r\n * @param fromRay initial ray of the pointer to be simulated (Default: Ray from camera to attached mesh)\r\n * @param startPickedPoint picked point of the pointer to be simulated (Default: attached mesh position)\r\n */\r\n public startDrag(pointerId: number = PointerDragBehavior._AnyMouseId, fromRay?: Ray, startPickedPoint?: Vector3) {\r\n this._startDrag(pointerId, fromRay, startPickedPoint);\r\n\r\n let lastRay = this._lastPointerRay[pointerId];\r\n if (pointerId === PointerDragBehavior._AnyMouseId) {\r\n lastRay = this._lastPointerRay[Object.keys(this._lastPointerRay)[0]];\r\n }\r\n\r\n if (lastRay) {\r\n // if there was a last pointer ray drag the object there\r\n this._moveDrag(lastRay);\r\n }\r\n }\r\n\r\n protected _startDrag(pointerId: number, fromRay?: Ray, startPickedPoint?: Vector3) {\r\n if (!this._scene.activeCamera || this.dragging || !this.attachedNode) {\r\n return;\r\n }\r\n\r\n PivotTools._RemoveAndStorePivotPoint(this.attachedNode);\r\n // Create start ray from the camera to the object\r\n if (fromRay) {\r\n this._startDragRay.direction.copyFrom(fromRay.direction);\r\n this._startDragRay.origin.copyFrom(fromRay.origin);\r\n } else {\r\n this._startDragRay.origin.copyFrom(this._scene.activeCamera.position);\r\n this.attachedNode.getWorldMatrix().getTranslationToRef(this._tmpVector);\r\n this._tmpVector.subtractToRef(this._scene.activeCamera.position, this._startDragRay.direction);\r\n }\r\n\r\n this._updateDragPlanePosition(this._startDragRay, startPickedPoint ? startPickedPoint : this._tmpVector);\r\n\r\n const pickedPoint = this._pickWithRayOnDragPlane(this._startDragRay);\r\n if (pickedPoint) {\r\n this.dragging = true;\r\n this.currentDraggingPointerId = pointerId;\r\n this.lastDragPosition.copyFrom(pickedPoint);\r\n this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerId, pointerInfo: this._activePointerInfo });\r\n this._targetPosition.copyFrom(this.attachedNode.getAbsolutePosition());\r\n\r\n // Detatch camera controls\r\n if (this.detachCameraControls && this._scene.activeCamera && this._scene.activeCamera.inputs && !this._scene.activeCamera.leftCamera) {\r\n if (this._scene.activeCamera.inputs.attachedToElement) {\r\n this._scene.activeCamera.detachControl();\r\n this._attachedToElement = true;\r\n } else {\r\n this._attachedToElement = false;\r\n }\r\n }\r\n } else {\r\n this.releaseDrag();\r\n }\r\n PivotTools._RestorePivotPoint(this.attachedNode);\r\n }\r\n\r\n private _dragDelta = new Vector3();\r\n protected _moveDrag(ray: Ray) {\r\n this._moving = true;\r\n const pickedPoint = this._pickWithRayOnDragPlane(ray);\r\n\r\n if (pickedPoint) {\r\n PivotTools._RemoveAndStorePivotPoint(this.attachedNode);\r\n\r\n if (this.updateDragPlane) {\r\n this._updateDragPlanePosition(ray, pickedPoint);\r\n }\r\n let dragLength = 0;\r\n // depending on the drag mode option drag accordingly\r\n if (this._options.dragAxis) {\r\n // Convert local drag axis to world if useObjectOrientationForDragging\r\n this.useObjectOrientationForDragging\r\n ? Vector3.TransformCoordinatesToRef(this._options.dragAxis, this.attachedNode.getWorldMatrix().getRotationMatrix(), this._worldDragAxis)\r\n : this._worldDragAxis.copyFrom(this._options.dragAxis);\r\n\r\n // Project delta drag from the drag plane onto the drag axis\r\n pickedPoint.subtractToRef(this.lastDragPosition, this._tmpVector);\r\n dragLength = Vector3.Dot(this._tmpVector, this._worldDragAxis);\r\n this._worldDragAxis.scaleToRef(dragLength, this._dragDelta);\r\n } else {\r\n dragLength = this._dragDelta.length();\r\n pickedPoint.subtractToRef(this.lastDragPosition, this._dragDelta);\r\n }\r\n this._targetPosition.addInPlace(this._dragDelta);\r\n this.onDragObservable.notifyObservers({\r\n dragDistance: dragLength,\r\n delta: this._dragDelta,\r\n dragPlanePoint: pickedPoint,\r\n dragPlaneNormal: this._dragPlane.forward,\r\n pointerId: this.currentDraggingPointerId,\r\n pointerInfo: this._activePointerInfo,\r\n });\r\n this.lastDragPosition.copyFrom(pickedPoint);\r\n\r\n PivotTools._RestorePivotPoint(this.attachedNode);\r\n }\r\n }\r\n\r\n private _pickWithRayOnDragPlane(ray: Nullable) {\r\n if (!ray) {\r\n return null;\r\n }\r\n\r\n // Calculate angle between plane normal and ray\r\n let angle = Math.acos(Vector3.Dot(this._dragPlane.forward, ray.direction));\r\n // Correct if ray is casted from oposite side\r\n if (angle > Math.PI / 2) {\r\n angle = Math.PI - angle;\r\n }\r\n\r\n // If the angle is too perpendicular to the plane pick another point on the plane where it is looking\r\n if (this.maxDragAngle > 0 && angle > this.maxDragAngle) {\r\n if (this._useAlternatePickedPointAboveMaxDragAngle) {\r\n // Invert ray direction along the towards object axis\r\n this._tmpVector.copyFrom(ray.direction);\r\n this.attachedNode.absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);\r\n this._alternatePickedPoint.normalize();\r\n this._alternatePickedPoint.scaleInPlace(this._useAlternatePickedPointAboveMaxDragAngleDragSpeed * Vector3.Dot(this._alternatePickedPoint, this._tmpVector));\r\n this._tmpVector.addInPlace(this._alternatePickedPoint);\r\n\r\n // Project resulting vector onto the drag plane and add it to the attached nodes absolute position to get a picked point\r\n const dot = Vector3.Dot(this._dragPlane.forward, this._tmpVector);\r\n this._dragPlane.forward.scaleToRef(-dot, this._alternatePickedPoint);\r\n this._alternatePickedPoint.addInPlace(this._tmpVector);\r\n this._alternatePickedPoint.addInPlace(this.attachedNode.absolutePosition);\r\n return this._alternatePickedPoint;\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n const pickResult = PointerDragBehavior._PlaneScene.pickWithRay(ray, (m) => {\r\n return m == this._dragPlane;\r\n });\r\n if (pickResult && pickResult.hit && pickResult.pickedMesh && pickResult.pickedPoint) {\r\n return pickResult.pickedPoint;\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n // Variables to avoid instantiation in the below method\r\n private _pointA = new Vector3(0, 0, 0);\r\n private _pointC = new Vector3(0, 0, 0);\r\n private _localAxis = new Vector3(0, 0, 0);\r\n private _lookAt = new Vector3(0, 0, 0);\r\n // Position the drag plane based on the attached mesh position, for single axis rotate the plane along the axis to face the camera\r\n private _updateDragPlanePosition(ray: Ray, dragPlanePosition: Vector3) {\r\n this._pointA.copyFrom(dragPlanePosition);\r\n if (this._options.dragAxis) {\r\n this.useObjectOrientationForDragging\r\n ? Vector3.TransformCoordinatesToRef(this._options.dragAxis, this.attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis)\r\n : this._localAxis.copyFrom(this._options.dragAxis);\r\n\r\n // Calculate plane normal that is the cross product of local axis and (eye-dragPlanePosition)\r\n ray.origin.subtractToRef(this._pointA, this._pointC);\r\n this._pointC.normalize();\r\n if (Math.abs(Vector3.Dot(this._localAxis, this._pointC)) > 0.999) {\r\n // the drag axis is colinear with the (eye to position) ray. The cross product will give jittered values.\r\n // A new axis vector need to be computed\r\n if (Math.abs(Vector3.Dot(Vector3.UpReadOnly, this._pointC)) > 0.999) {\r\n this._lookAt.copyFrom(Vector3.Right());\r\n } else {\r\n this._lookAt.copyFrom(Vector3.UpReadOnly);\r\n }\r\n } else {\r\n Vector3.CrossToRef(this._localAxis, this._pointC, this._lookAt);\r\n // Get perpendicular line from previous result and drag axis to adjust lineB to be perpendicular to camera\r\n Vector3.CrossToRef(this._localAxis, this._lookAt, this._lookAt);\r\n this._lookAt.normalize();\r\n }\r\n\r\n this._dragPlane.position.copyFrom(this._pointA);\r\n this._pointA.addToRef(this._lookAt, this._lookAt);\r\n this._dragPlane.lookAt(this._lookAt);\r\n } else if (this._options.dragPlaneNormal) {\r\n this.useObjectOrientationForDragging\r\n ? Vector3.TransformCoordinatesToRef(this._options.dragPlaneNormal, this.attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis)\r\n : this._localAxis.copyFrom(this._options.dragPlaneNormal);\r\n this._dragPlane.position.copyFrom(this._pointA);\r\n this._pointA.addToRef(this._localAxis, this._lookAt);\r\n this._dragPlane.lookAt(this._lookAt);\r\n } else {\r\n this._dragPlane.position.copyFrom(this._pointA);\r\n this._dragPlane.lookAt(ray.origin);\r\n }\r\n // Update the position of the drag plane so it doesn't get out of sync with the node (eg. when moving back and forth quickly)\r\n this._dragPlane.position.copyFrom(this.attachedNode.getAbsolutePosition());\r\n\r\n this._dragPlane.computeWorldMatrix(true);\r\n }\r\n\r\n /**\r\n * Detaches the behavior from the mesh\r\n */\r\n public detach(): void {\r\n this._lastPointerRay = {};\r\n if (this.attachedNode) {\r\n this.attachedNode.isNearGrabbable = false;\r\n }\r\n if (this._pointerObserver) {\r\n this._scene.onPointerObservable.remove(this._pointerObserver);\r\n }\r\n if (this._beforeRenderObserver) {\r\n this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n if (this._dragPlane) {\r\n this._dragPlane.dispose();\r\n }\r\n this.releaseDrag();\r\n }\r\n}\r\n","import { PointerDragBehavior } from '@babylonjs/core/Behaviors/Meshes/pointerDragBehavior';\r\nimport { WebVRFreeCamera } from '@babylonjs/core/Cameras/VR/webVRCamera';\r\nimport { PointerEventTypes, PointerInfo } from '@babylonjs/core/Events/pointerEvents';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { CylinderBuilder } from '@babylonjs/core/Meshes/Builders/cylinderBuilder';\r\nimport { SphereBuilder } from '@babylonjs/core/Meshes/Builders/sphereBuilder';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Observable, Observer } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { rotationToVector, rotationToVectorToRef } from '@view/helpers/math-helper';\r\n\r\n/**\r\n * Single plane rotation gizmo\r\n */\r\nexport class KbAxisMorphGizmo {\r\n /**\r\n * Drag behavior responsible for the gizmos dragging interactions\r\n */\r\n public dragBehavior: PointerDragBehavior;\r\n public dragActive = false;\r\n public direction = new Vector3();\r\n private _rootMesh: Mesh;\r\n private axisMesh: AbstractMesh;\r\n private _pointerObserver: Nullable> = null;\r\n private _tempVector = new Vector3();\r\n private _updateQuat = new Quaternion();\r\n\r\n protected _scaleRatio = 1;\r\n\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n public set scaleRatio(value: number) {\r\n this._scaleRatio = value;\r\n }\r\n\r\n public get scaleRatio() {\r\n return this._scaleRatio;\r\n }\r\n\r\n public set gizmoPosition(value: Vector3) {\r\n this._rootMesh.position = value;\r\n }\r\n\r\n public get gizmoPosition() {\r\n return this._rootMesh.position;\r\n }\r\n\r\n /**\r\n * Rotation distance in radians that the gizmo will snap to (Default: 0)\r\n */\r\n public snapDistance = 0;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the the change in distance\r\n */\r\n public updateObservable = new Observable<{ delta: Quaternion }>();\r\n\r\n private _beforeRenderObserver: Nullable>;\r\n\r\n /**\r\n * Creates a PlaneRotationGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param color The color of the gizmo\r\n * @param tessellation Amount of tessellation to be used when creating rotation circles\r\n */\r\n constructor(\r\n color: Color3 = Color3.Gray(),\r\n private gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n tessellation = 24\r\n ) {\r\n this._rootMesh = new Mesh('gizmoRootNode', gizmoLayer.utilityLayerScene);\r\n\r\n // Create Material\r\n const coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n coloredMaterial.emissiveColor = color;\r\n\r\n const wireframeMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n wireframeMaterial.emissiveColor = color;\r\n wireframeMaterial.alpha = 0.4;\r\n // coloredMaterial.diffuseColor = color;\r\n // coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\r\n\r\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n wireframeMaterial.alpha = 0.6;\r\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n\r\n // Build mesh to hold axis line\r\n this.axisMesh = new AbstractMesh('', gizmoLayer.utilityLayerScene);\r\n this.axisMesh.rotationQuaternion = Quaternion.Identity();\r\n\r\n const line = CylinderBuilder.CreateCylinder(\r\n '',\r\n { diameterTop: 0.01, height: 0.3, diameterBottom: 0.01, tessellation },\r\n gizmoLayer.utilityLayerScene\r\n );\r\n line.material = coloredMaterial;\r\n line.position.y = 0.375;\r\n const line2 = CylinderBuilder.CreateCylinder(\r\n '',\r\n { diameterTop: 0.005, height: 0.9, diameterBottom: 0.005, tessellation },\r\n gizmoLayer.utilityLayerScene\r\n );\r\n line2.material = coloredMaterial;\r\n line2.position.y = -0.225;\r\n\r\n const sphereMesh = SphereBuilder.CreateSphere(\r\n '',\r\n { segments: tessellation, diameter: 0.45 },\r\n gizmoLayer.utilityLayerScene\r\n );\r\n sphereMesh.material = wireframeMaterial;\r\n\r\n this.axisMesh.isPickable = false;\r\n this.axisMesh.addChild(line);\r\n this.axisMesh.addChild(line2);\r\n\r\n sphereMesh.addChild(this.axisMesh);\r\n sphereMesh.scaling.scaleInPlace(1 / 3);\r\n this._rootMesh.addChild(sphereMesh);\r\n\r\n let lastDragPosition: Vector3 | null = null;\r\n\r\n // Add drag behavior to handle events when the gizmo is dragged\r\n this.dragBehavior = new PointerDragBehavior();\r\n this.dragBehavior.moveAttached = false;\r\n\r\n this.dragBehavior.onDragStartObservable.add(() => {\r\n this.dragActive = true;\r\n });\r\n this.dragBehavior.onDragObservable.add(event => {\r\n // activeCamera.getForwardRayToRef(forwardRay, 1);\r\n // const cameraDirection = forwardRay.direction;\r\n // cameraDirection.rotateByQuaternionToRef(parentMesh.rotationQuaternion!, cameraDirection);\r\n // cameraDirection.addToRef(event.delta, targetDirection);\r\n // rotationToVectorToRef(targetDirection, cameraDirection, this._updateQuat);\r\n // parentMesh.rotationQuaternion!.multiplyInPlace(this._updateQuat);\r\n // this.updateObservable.notifyObservers({ delta: this._updateQuat });\r\n });\r\n this.dragBehavior.onDragEndObservable.add(() => {\r\n this.dragActive = false;\r\n });\r\n\r\n this._rootMesh.addBehavior(this.dragBehavior);\r\n this.dragBehavior.enabled = true;\r\n\r\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\r\n const isHovered =\r\n pointerInfo.pickInfo &&\r\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\r\n sphereMesh.material = isHovered ? hoverMaterial : wireframeMaterial;\r\n\r\n if (pointerInfo.pickInfo && isHovered) {\r\n const point = pointerInfo.pickInfo.pickedPoint;\r\n if (point) {\r\n point.subtractInPlace(this._rootMesh.position);\r\n switch (pointerInfo.type) {\r\n case PointerEventTypes.POINTERDOWN:\r\n lastDragPosition = point.clone();\r\n break;\r\n case PointerEventTypes.POINTERMOVE:\r\n if (lastDragPosition && this.dragActive) {\r\n rotationToVectorToRef(point, lastDragPosition, this._updateQuat);\r\n lastDragPosition.copyFrom(point);\r\n // console.log(point, this._updateQuat);\r\n this.direction.rotateByQuaternionToRef(this._updateQuat, this.direction);\r\n this.updateObservable.notifyObservers({ delta: this._updateQuat });\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n });\r\n\r\n // let light = gizmoLayer._getSharedGizmoLight();\r\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));\r\n\r\n this._beforeRenderObserver = this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.add(() => {\r\n this._update();\r\n });\r\n }\r\n protected _update() {\r\n if (this.direction) {\r\n this.axisMesh.rotationQuaternion = rotationToVector(this.direction);\r\n }\r\n const activeCamera = this.gizmoLayer.utilityLayerScene.activeCamera!;\r\n let cameraPosition = activeCamera.globalPosition;\r\n if ((activeCamera).devicePosition) {\r\n cameraPosition = (activeCamera).devicePosition;\r\n }\r\n this._rootMesh.position.subtractToRef(cameraPosition, this._tempVector);\r\n const dist = this._tempVector.length() * this.scaleRatio;\r\n this._rootMesh.scaling.set(dist, dist, dist);\r\n\r\n // Account for handedness, similar to Matrix.decompose\r\n if (this.gizmoLayer.originalScene.meshes[0]?._getWorldMatrixDeterminant() < 0) {\r\n this._rootMesh.scaling.y *= -1;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\r\n this._rootMesh.dispose();\r\n this.dragBehavior.detach();\r\n\r\n if (this._beforeRenderObserver) {\r\n this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n}\r\n","import type { Observer } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { WebVRFreeCamera } from \"../Cameras/VR/webVRCamera\";\r\nimport type { Scene, IDisposable } from \"../scene\";\r\nimport { Quaternion, Vector3, Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport type { TargetCamera } from \"../Cameras/targetCamera\";\r\nimport type { Node } from \"../node\";\r\nimport type { Bone } from \"../Bones/bone\";\r\nimport { UtilityLayerRenderer } from \"../Rendering/utilityLayerRenderer\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { StandardMaterial } from \"../Materials/standardMaterial\";\r\nimport type { PointerInfo } from \"../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../Events/pointerEvents\";\r\nimport type { LinesMesh } from \"../Meshes/linesMesh\";\r\nimport type { PointerDragBehavior } from \"../Behaviors/Meshes/pointerDragBehavior\";\r\nimport type { ShadowLight } from \"../Lights/shadowLight\";\r\nimport { Light } from \"../Lights/light\";\r\n\r\n/**\r\n * Cache built by each axis. Used for managing state between all elements of gizmo for enhanced UI\r\n */\r\nexport interface GizmoAxisCache {\r\n /** Mesh used to render the Gizmo */\r\n gizmoMeshes: Mesh[];\r\n /** Mesh used to detect user interaction with Gizmo */\r\n colliderMeshes: Mesh[];\r\n /** Material used to indicate color of gizmo mesh */\r\n material: StandardMaterial;\r\n /** Material used to indicate hover state of the Gizmo */\r\n hoverMaterial: StandardMaterial;\r\n /** Material used to indicate disabled state of the Gizmo */\r\n disableMaterial: StandardMaterial;\r\n /** Used to indicate Active state of the Gizmo */\r\n active: boolean;\r\n /** DragBehavior */\r\n dragBehavior: PointerDragBehavior;\r\n}\r\n\r\n/**\r\n * Anchor options where the Gizmo can be positioned in relation to its anchored node\r\n */\r\nexport enum GizmoAnchorPoint {\r\n /** The origin of the attached node */\r\n Origin,\r\n /** The pivot point of the attached node*/\r\n Pivot,\r\n}\r\n\r\n/**\r\n * Coordinates mode: Local or World. Defines how axis is aligned: either on world axis or transform local axis\r\n */\r\nexport enum GizmoCoordinatesMode {\r\n World,\r\n Local,\r\n}\r\n\r\n/**\r\n * Interface for basic gizmo\r\n */\r\nexport interface IGizmo extends IDisposable {\r\n /** True when the mouse pointer is hovered a gizmo mesh */\r\n readonly isHovered: boolean;\r\n /** The root mesh of the gizmo */\r\n _rootMesh: Mesh;\r\n /** Ratio for the scale of the gizmo */\r\n scaleRatio: number;\r\n /**\r\n * Mesh that the gizmo will be attached to. (eg. on a drag gizmo the mesh that will be dragged)\r\n * * When set, interactions will be enabled\r\n */\r\n attachedMesh: Nullable;\r\n /**\r\n * Node that the gizmo will be attached to. (eg. on a drag gizmo the mesh, bone or NodeTransform that will be dragged)\r\n * * When set, interactions will be enabled\r\n */\r\n attachedNode: Nullable;\r\n /**\r\n * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)\r\n */\r\n updateGizmoRotationToMatchAttachedMesh: boolean;\r\n /** The utility layer the gizmo will be added to */\r\n gizmoLayer: UtilityLayerRenderer;\r\n /**\r\n * If set the gizmo's position will be updated to match the attached mesh each frame (Default: true)\r\n */\r\n updateGizmoPositionToMatchAttachedMesh: boolean;\r\n /**\r\n * Defines where the gizmo will be positioned if `updateGizmoPositionToMatchAttachedMesh` is enabled.\r\n * (Default: GizmoAnchorPoint.Origin)\r\n */\r\n anchorPoint: GizmoAnchorPoint;\r\n\r\n /**\r\n * Set the coordinate mode to use. By default it's local.\r\n */\r\n coordinatesMode: GizmoCoordinatesMode;\r\n\r\n /**\r\n * When set, the gizmo will always appear the same size no matter where the camera is (default: true)\r\n */\r\n updateScale: boolean;\r\n /**\r\n * posture that the gizmo will be display\r\n * When set null, default value will be used (Quaternion(0, 0, 0, 1))\r\n */\r\n customRotationQuaternion: Nullable;\r\n /** Disposes and replaces the current meshes in the gizmo with the specified mesh */\r\n setCustomMesh(mesh: Mesh): void;\r\n}\r\n/**\r\n * Renders gizmos on top of an existing scene which provide controls for position, rotation, etc.\r\n */\r\nexport class Gizmo implements IGizmo {\r\n /**\r\n * The root mesh of the gizmo\r\n */\r\n public _rootMesh: Mesh;\r\n protected _attachedMesh: Nullable = null;\r\n protected _attachedNode: Nullable = null;\r\n protected _customRotationQuaternion: Nullable = null;\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n protected _scaleRatio = 1;\r\n\r\n /**\r\n * boolean updated by pointermove when a gizmo mesh is hovered\r\n */\r\n protected _isHovered = false;\r\n\r\n /**\r\n * When enabled, any gizmo operation will perserve scaling sign. Default is off.\r\n * Only valid for TransformNode derived classes (Mesh, AbstractMesh, ...)\r\n */\r\n public static PreserveScaling = false;\r\n\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n public set scaleRatio(value: number) {\r\n this._scaleRatio = value;\r\n }\r\n\r\n public get scaleRatio() {\r\n return this._scaleRatio;\r\n }\r\n\r\n /**\r\n * True when the mouse pointer is hovered a gizmo mesh\r\n */\r\n public get isHovered() {\r\n return this._isHovered;\r\n }\r\n\r\n /**\r\n * If a custom mesh has been set (Default: false)\r\n */\r\n protected _customMeshSet = false;\r\n /**\r\n * Mesh that the gizmo will be attached to. (eg. on a drag gizmo the mesh that will be dragged)\r\n * * When set, interactions will be enabled\r\n */\r\n public get attachedMesh() {\r\n return this._attachedMesh;\r\n }\r\n public set attachedMesh(value) {\r\n this._attachedMesh = value;\r\n if (value) {\r\n this._attachedNode = value;\r\n }\r\n this._rootMesh.setEnabled(value ? true : false);\r\n this._attachedNodeChanged(value);\r\n }\r\n /**\r\n * Node that the gizmo will be attached to. (eg. on a drag gizmo the mesh, bone or NodeTransform that will be dragged)\r\n * * When set, interactions will be enabled\r\n */\r\n public get attachedNode() {\r\n return this._attachedNode;\r\n }\r\n public set attachedNode(value) {\r\n this._attachedNode = value;\r\n this._attachedMesh = null;\r\n this._rootMesh.setEnabled(value ? true : false);\r\n this._attachedNodeChanged(value);\r\n }\r\n\r\n /**\r\n * Disposes and replaces the current meshes in the gizmo with the specified mesh\r\n * @param mesh The mesh to replace the default mesh of the gizmo\r\n */\r\n public setCustomMesh(mesh: Mesh) {\r\n if (mesh.getScene() != this.gizmoLayer.utilityLayerScene) {\r\n throw \"When setting a custom mesh on a gizmo, the custom meshes scene must be the same as the gizmos (eg. gizmo.gizmoLayer.utilityLayerScene)\";\r\n }\r\n this._rootMesh.getChildMeshes().forEach((c) => {\r\n c.dispose();\r\n });\r\n mesh.parent = this._rootMesh;\r\n this._customMeshSet = true;\r\n }\r\n\r\n protected _updateGizmoRotationToMatchAttachedMesh = true;\r\n protected _updateGizmoPositionToMatchAttachedMesh = true;\r\n protected _anchorPoint = GizmoAnchorPoint.Origin;\r\n protected _updateScale = true;\r\n protected _coordinatesMode = GizmoCoordinatesMode.Local;\r\n\r\n /**\r\n * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)\r\n * NOTE: This is only possible for meshes with uniform scaling, as otherwise it's not possible to decompose the rotation\r\n */\r\n public set updateGizmoRotationToMatchAttachedMesh(value: boolean) {\r\n this._updateGizmoRotationToMatchAttachedMesh = value;\r\n }\r\n public get updateGizmoRotationToMatchAttachedMesh() {\r\n return this._updateGizmoRotationToMatchAttachedMesh;\r\n }\r\n /**\r\n * If set the gizmo's position will be updated to match the attached mesh each frame (Default: true)\r\n */\r\n public set updateGizmoPositionToMatchAttachedMesh(value: boolean) {\r\n this._updateGizmoPositionToMatchAttachedMesh = value;\r\n }\r\n public get updateGizmoPositionToMatchAttachedMesh() {\r\n return this._updateGizmoPositionToMatchAttachedMesh;\r\n }\r\n\r\n /**\r\n * Defines where the gizmo will be positioned if `updateGizmoPositionToMatchAttachedMesh` is enabled.\r\n * (Default: GizmoAnchorPoint.Origin)\r\n */\r\n public set anchorPoint(value: GizmoAnchorPoint) {\r\n this._anchorPoint = value;\r\n }\r\n public get anchorPoint() {\r\n return this._anchorPoint;\r\n }\r\n\r\n /**\r\n * Set the coordinate system to use. By default it's local.\r\n * But it's possible for a user to tweak so its local for translation and world for rotation.\r\n * In that case, setting the coordinate system will change `updateGizmoRotationToMatchAttachedMesh` and `updateGizmoPositionToMatchAttachedMesh`\r\n */\r\n public set coordinatesMode(coordinatesMode: GizmoCoordinatesMode) {\r\n this._coordinatesMode = coordinatesMode;\r\n const local = coordinatesMode == GizmoCoordinatesMode.Local;\r\n this.updateGizmoRotationToMatchAttachedMesh = local;\r\n this.updateGizmoPositionToMatchAttachedMesh = local;\r\n }\r\n\r\n public get coordinatesMode() {\r\n return this._coordinatesMode;\r\n }\r\n\r\n /**\r\n * When set, the gizmo will always appear the same size no matter where the camera is (default: true)\r\n */\r\n\r\n public set updateScale(value: boolean) {\r\n this._updateScale = value;\r\n }\r\n public get updateScale() {\r\n return this._updateScale;\r\n }\r\n protected _interactionsEnabled = true;\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _attachedNodeChanged(value: Nullable) {}\r\n\r\n protected _beforeRenderObserver: Nullable>;\r\n private _rightHandtoLeftHandMatrix = Matrix.RotationY(Math.PI);\r\n\r\n /**\r\n * Creates a gizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n */\r\n constructor(\r\n /** The utility layer the gizmo will be added to */\r\n public gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer\r\n ) {\r\n this._rootMesh = new Mesh(\"gizmoRootNode\", gizmoLayer.utilityLayerScene);\r\n this._rootMesh.rotationQuaternion = Quaternion.Identity();\r\n\r\n this._beforeRenderObserver = this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.add(() => {\r\n this._update();\r\n });\r\n }\r\n\r\n /**\r\n * posture that the gizmo will be display\r\n * When set null, default value will be used (Quaternion(0, 0, 0, 1))\r\n */\r\n public get customRotationQuaternion(): Nullable {\r\n return this._customRotationQuaternion;\r\n }\r\n\r\n public set customRotationQuaternion(customRotationQuaternion: Nullable) {\r\n this._customRotationQuaternion = customRotationQuaternion;\r\n }\r\n\r\n /**\r\n * Updates the gizmo to match the attached mesh's position/rotation\r\n */\r\n protected _update() {\r\n if (this.attachedNode) {\r\n let effectiveNode = this.attachedNode;\r\n if (this.attachedMesh) {\r\n effectiveNode = this.attachedMesh || this.attachedNode;\r\n }\r\n\r\n // Position\r\n if (this.updateGizmoPositionToMatchAttachedMesh) {\r\n if (this.anchorPoint == GizmoAnchorPoint.Pivot && (effectiveNode).getAbsolutePivotPoint) {\r\n const position = (effectiveNode).getAbsolutePivotPoint();\r\n this._rootMesh.position.copyFrom(position);\r\n } else {\r\n const row = effectiveNode.getWorldMatrix().getRow(3);\r\n const position = row ? row.toVector3() : new Vector3(0, 0, 0);\r\n this._rootMesh.position.copyFrom(position);\r\n }\r\n }\r\n\r\n // Rotation\r\n if (this.updateGizmoRotationToMatchAttachedMesh) {\r\n const supportedNode =\r\n (effectiveNode)._isMesh ||\r\n effectiveNode.getClassName() === \"AbstractMesh\" ||\r\n effectiveNode.getClassName() === \"TransformNode\" ||\r\n effectiveNode.getClassName() === \"InstancedMesh\";\r\n const transformNode = supportedNode ? (effectiveNode as TransformNode) : undefined;\r\n effectiveNode.getWorldMatrix().decompose(undefined, this._rootMesh.rotationQuaternion!, undefined, Gizmo.PreserveScaling ? transformNode : undefined);\r\n } else {\r\n if (this._customRotationQuaternion) {\r\n this._rootMesh.rotationQuaternion!.copyFrom(this._customRotationQuaternion);\r\n } else {\r\n this._rootMesh.rotationQuaternion!.set(0, 0, 0, 1);\r\n }\r\n }\r\n\r\n // Scale\r\n if (this.updateScale) {\r\n const activeCamera = this.gizmoLayer.utilityLayerScene.activeCamera!;\r\n let cameraPosition = activeCamera.globalPosition;\r\n if ((activeCamera).devicePosition) {\r\n cameraPosition = (activeCamera).devicePosition;\r\n }\r\n this._rootMesh.position.subtractToRef(cameraPosition, TmpVectors.Vector3[0]);\r\n let scale = this.scaleRatio;\r\n if (activeCamera.mode == Camera.ORTHOGRAPHIC_CAMERA) {\r\n if (activeCamera.orthoTop && activeCamera.orthoBottom) {\r\n const orthoHeight = activeCamera.orthoTop - activeCamera.orthoBottom;\r\n scale *= orthoHeight;\r\n }\r\n } else {\r\n const camForward = activeCamera.getScene().useRightHandedSystem ? Vector3.RightHandedForwardReadOnly : Vector3.LeftHandedForwardReadOnly;\r\n const direction = activeCamera.getDirection(camForward);\r\n scale *= Vector3.Dot(TmpVectors.Vector3[0], direction);\r\n }\r\n this._rootMesh.scaling.setAll(scale);\r\n\r\n // Account for handedness, similar to Matrix.decompose\r\n if (effectiveNode._getWorldMatrixDeterminant() < 0 && !Gizmo.PreserveScaling) {\r\n this._rootMesh.scaling.y *= -1;\r\n }\r\n } else {\r\n this._rootMesh.scaling.setAll(this.scaleRatio);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Handle position/translation when using an attached node using pivot\r\n */\r\n protected _handlePivot() {\r\n const attachedNodeTransform = this._attachedNode as any;\r\n // check there is an active pivot for the TransformNode attached\r\n if (attachedNodeTransform.isUsingPivotMatrix && attachedNodeTransform.isUsingPivotMatrix() && attachedNodeTransform.position) {\r\n // When a TransformNode has an active pivot, even without parenting,\r\n // translation from the world matrix is different from TransformNode.position.\r\n // Pivot works like a virtual parent that's using the node orientation.\r\n // As the world matrix is transformed by the gizmo and then decomposed to TRS\r\n // its translation part must be set to the Node's position.\r\n attachedNodeTransform.getWorldMatrix().setTranslation(attachedNodeTransform.position);\r\n }\r\n }\r\n /**\r\n * computes the rotation/scaling/position of the transform once the Node world matrix has changed.\r\n */\r\n protected _matrixChanged() {\r\n if (!this._attachedNode) {\r\n return;\r\n }\r\n\r\n if ((this._attachedNode)._isCamera) {\r\n const camera = this._attachedNode as Camera;\r\n let worldMatrix;\r\n let worldMatrixUC;\r\n if (camera.parent) {\r\n const parentInv = TmpVectors.Matrix[1];\r\n camera.parent._worldMatrix.invertToRef(parentInv);\r\n this._attachedNode._worldMatrix.multiplyToRef(parentInv, TmpVectors.Matrix[0]);\r\n worldMatrix = TmpVectors.Matrix[0];\r\n } else {\r\n worldMatrix = this._attachedNode._worldMatrix;\r\n }\r\n\r\n if (camera.getScene().useRightHandedSystem) {\r\n // avoid desync with RH matrix computation. Otherwise, rotation of PI around Y axis happens each frame resulting in axis flipped because worldMatrix is computed as inverse of viewMatrix.\r\n this._rightHandtoLeftHandMatrix.multiplyToRef(worldMatrix, TmpVectors.Matrix[1]);\r\n worldMatrixUC = TmpVectors.Matrix[1];\r\n } else {\r\n worldMatrixUC = worldMatrix;\r\n }\r\n\r\n worldMatrixUC.decompose(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0]);\r\n\r\n const inheritsTargetCamera =\r\n this._attachedNode.getClassName() === \"FreeCamera\" ||\r\n this._attachedNode.getClassName() === \"FlyCamera\" ||\r\n this._attachedNode.getClassName() === \"ArcFollowCamera\" ||\r\n this._attachedNode.getClassName() === \"TargetCamera\" ||\r\n this._attachedNode.getClassName() === \"TouchCamera\" ||\r\n this._attachedNode.getClassName() === \"UniversalCamera\";\r\n\r\n if (inheritsTargetCamera) {\r\n const targetCamera = this._attachedNode as TargetCamera;\r\n targetCamera.rotation = TmpVectors.Quaternion[0].toEulerAngles();\r\n\r\n if (targetCamera.rotationQuaternion) {\r\n targetCamera.rotationQuaternion.copyFrom(TmpVectors.Quaternion[0]);\r\n targetCamera.rotationQuaternion.normalize();\r\n }\r\n }\r\n\r\n camera.position.copyFrom(TmpVectors.Vector3[0]);\r\n } else if (\r\n (this._attachedNode)._isMesh ||\r\n this._attachedNode.getClassName() === \"AbstractMesh\" ||\r\n this._attachedNode.getClassName() === \"TransformNode\" ||\r\n this._attachedNode.getClassName() === \"InstancedMesh\"\r\n ) {\r\n const transform = this._attachedNode as TransformNode;\r\n if (transform.parent) {\r\n const parentInv = TmpVectors.Matrix[0];\r\n const localMat = TmpVectors.Matrix[1];\r\n transform.parent.getWorldMatrix().invertToRef(parentInv);\r\n this._attachedNode.getWorldMatrix().multiplyToRef(parentInv, localMat);\r\n localMat.decompose(TmpVectors.Vector3[0], TmpVectors.Quaternion[0], transform.position, Gizmo.PreserveScaling ? transform : undefined);\r\n } else {\r\n this._attachedNode._worldMatrix.decompose(TmpVectors.Vector3[0], TmpVectors.Quaternion[0], transform.position, Gizmo.PreserveScaling ? transform : undefined);\r\n }\r\n TmpVectors.Vector3[0].scaleInPlace(1.0 / transform.scalingDeterminant);\r\n transform.scaling.copyFrom(TmpVectors.Vector3[0]);\r\n if (!transform.billboardMode) {\r\n if (transform.rotationQuaternion) {\r\n transform.rotationQuaternion.copyFrom(TmpVectors.Quaternion[0]);\r\n transform.rotationQuaternion.normalize();\r\n } else {\r\n transform.rotation = TmpVectors.Quaternion[0].toEulerAngles();\r\n }\r\n }\r\n } else if (this._attachedNode.getClassName() === \"Bone\") {\r\n const bone = this._attachedNode as Bone;\r\n const parent = bone.getParent();\r\n\r\n if (parent) {\r\n const invParent = TmpVectors.Matrix[0];\r\n const boneLocalMatrix = TmpVectors.Matrix[1];\r\n parent.getFinalMatrix().invertToRef(invParent);\r\n bone.getFinalMatrix().multiplyToRef(invParent, boneLocalMatrix);\r\n const lmat = bone.getLocalMatrix();\r\n lmat.copyFrom(boneLocalMatrix);\r\n } else {\r\n const lmat = bone.getLocalMatrix();\r\n lmat.copyFrom(bone.getFinalMatrix());\r\n }\r\n bone.markAsDirty();\r\n } else {\r\n const light = this._attachedNode as ShadowLight;\r\n if (light.getTypeID) {\r\n const type = light.getTypeID();\r\n if (type === Light.LIGHTTYPEID_DIRECTIONALLIGHT || type === Light.LIGHTTYPEID_SPOTLIGHT || type === Light.LIGHTTYPEID_POINTLIGHT) {\r\n const parent = light.parent;\r\n\r\n if (parent) {\r\n const invParent = TmpVectors.Matrix[0];\r\n const nodeLocalMatrix = TmpVectors.Matrix[1];\r\n parent.getWorldMatrix().invertToRef(invParent);\r\n light.getWorldMatrix().multiplyToRef(invParent, nodeLocalMatrix);\r\n nodeLocalMatrix.decompose(undefined, TmpVectors.Quaternion[0], TmpVectors.Vector3[0]);\r\n } else {\r\n this._attachedNode._worldMatrix.decompose(undefined, TmpVectors.Quaternion[0], TmpVectors.Vector3[0]);\r\n }\r\n // setter doesn't copy values. Need a new Vector3\r\n light.position = new Vector3(TmpVectors.Vector3[0].x, TmpVectors.Vector3[0].y, TmpVectors.Vector3[0].z);\r\n if (light.direction) {\r\n light.direction = new Vector3(light.direction.x, light.direction.y, light.direction.z);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * refresh gizmo mesh material\r\n * @param gizmoMeshes\r\n * @param material material to apply\r\n */\r\n protected _setGizmoMeshMaterial(gizmoMeshes: Mesh[], material: StandardMaterial) {\r\n if (gizmoMeshes) {\r\n gizmoMeshes.forEach((m: Mesh) => {\r\n m.material = material;\r\n if ((m).color) {\r\n (m).color = material.diffuseColor;\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Subscribes to pointer up, down, and hover events. Used for responsive gizmos.\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param gizmoAxisCache Gizmo axis definition used for reactive gizmo UI\r\n * @returns {Observer} pointerObserver\r\n */\r\n public static GizmoAxisPointerObserver(gizmoLayer: UtilityLayerRenderer, gizmoAxisCache: Map): Observer {\r\n let dragging = false;\r\n\r\n const pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {\r\n if (pointerInfo.pickInfo) {\r\n // On Hover Logic\r\n if (pointerInfo.type === PointerEventTypes.POINTERMOVE) {\r\n if (dragging) {\r\n return;\r\n }\r\n gizmoAxisCache.forEach((cache) => {\r\n if (cache.colliderMeshes && cache.gizmoMeshes) {\r\n const isHovered = cache.colliderMeshes?.indexOf(pointerInfo?.pickInfo?.pickedMesh as Mesh) != -1;\r\n const material = cache.dragBehavior.enabled ? (isHovered || cache.active ? cache.hoverMaterial : cache.material) : cache.disableMaterial;\r\n cache.gizmoMeshes.forEach((m: Mesh) => {\r\n m.material = material;\r\n if ((m as LinesMesh).color) {\r\n (m as LinesMesh).color = material.diffuseColor;\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n // On Mouse Down\r\n if (pointerInfo.type === PointerEventTypes.POINTERDOWN) {\r\n // If user Clicked Gizmo\r\n if (gizmoAxisCache.has(pointerInfo.pickInfo.pickedMesh?.parent as Mesh)) {\r\n dragging = true;\r\n const statusMap = gizmoAxisCache.get(pointerInfo.pickInfo.pickedMesh?.parent as Mesh);\r\n statusMap!.active = true;\r\n gizmoAxisCache.forEach((cache) => {\r\n const isHovered = cache.colliderMeshes?.indexOf(pointerInfo?.pickInfo?.pickedMesh as Mesh) != -1;\r\n const material = (isHovered || cache.active) && cache.dragBehavior.enabled ? cache.hoverMaterial : cache.disableMaterial;\r\n cache.gizmoMeshes.forEach((m: Mesh) => {\r\n m.material = material;\r\n if ((m as LinesMesh).color) {\r\n (m as LinesMesh).color = material.diffuseColor;\r\n }\r\n });\r\n });\r\n }\r\n }\r\n\r\n // On Mouse Up\r\n if (pointerInfo.type === PointerEventTypes.POINTERUP) {\r\n gizmoAxisCache.forEach((cache) => {\r\n cache.active = false;\r\n dragging = false;\r\n cache.gizmoMeshes.forEach((m: Mesh) => {\r\n m.material = cache.dragBehavior.enabled ? cache.material : cache.disableMaterial;\r\n if ((m as LinesMesh).color) {\r\n (m as LinesMesh).color = cache.material.diffuseColor;\r\n }\r\n });\r\n });\r\n }\r\n }\r\n });\r\n\r\n return pointerObserver!;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this._rootMesh.dispose();\r\n if (this._beforeRenderObserver) {\r\n this.gizmoLayer.utilityLayerScene.onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n}\r\n","import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';\r\nimport { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { Gizmo } from '@babylonjs/core/Gizmos/gizmo';\r\nimport { Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { WebXRCamera } from '@babylonjs/core/XR/webXRCamera';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { getCameraPositionWithOffset } from '@view/helpers/math-helper';\r\n/**\r\n * Renders gizmos on top of an existing scene which provide controls for position, rotation, etc.\r\n */\r\n\r\nexport const AUTO_MESH_NAME = '_autoGizmoMesh';\r\nexport abstract class KbGizmo extends Gizmo {\r\n updateGizmoPosition() {\r\n this._update();\r\n }\r\n\r\n attachTo(node: Kb3dObject | KbVector) {}\r\n\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n onDragStartObservable: Observable;\r\n /** Fires an event while any of it's sub gizmos are dragged */\r\n onDragObservable: Observable;\r\n /** Fires an event when any of it's sub gizmos are released from dragging */\r\n onDragEndObservable: Observable;\r\n\r\n get attachedMesh() {\r\n return super.attachedMesh;\r\n }\r\n set attachedMesh(m: AbstractMesh | null) {\r\n if (m) {\r\n super.attachedMesh = m;\r\n }\r\n }\r\n\r\n get visibility() {\r\n return this._rootMesh.visibility;\r\n }\r\n set visibility(visibility: number) {\r\n this._rootMesh.setEnabled(visibility === 1);\r\n }\r\n\r\n protected attachMeshAtNodeSpace(scene: Scene, target: SpaceNode | KbVector, positionSpaceTransform?: Matrix) {\r\n if (!this.attachedMesh) {\r\n this.attachedMesh = new Mesh(AUTO_MESH_NAME, scene);\r\n }\r\n let translation: Vector3;\r\n const rotation = Quaternion.Identity();\r\n const scale = Vector3.One();\r\n\r\n translation = target instanceof SpaceNode ? target.position.toVec3() : target.toVec3();\r\n if (positionSpaceTransform) {\r\n translation = Vector3.TransformCoordinates(translation, positionSpaceTransform);\r\n positionSpaceTransform.decompose(scale, rotation);\r\n }\r\n\r\n this.attachedMesh.position = translation;\r\n this.attachedMesh.rotationQuaternion = rotation;\r\n this.attachedMesh.scaling = scale;\r\n\r\n return this.attachedMesh;\r\n }\r\n\r\n protected _update() {\r\n if (this.attachedMesh) {\r\n const _tempVector = new Vector3();\r\n const _tmpMatrix = new Matrix();\r\n if (this.updateGizmoRotationToMatchAttachedMesh) {\r\n if (!this._rootMesh.rotationQuaternion) {\r\n this._rootMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(\r\n this._rootMesh.rotation.y,\r\n this._rootMesh.rotation.x,\r\n this._rootMesh.rotation.z\r\n );\r\n }\r\n\r\n // Remove scaling before getting rotation matrix to get rotation matrix unmodified by scale\r\n _tempVector.copyFrom(this.attachedMesh.scaling);\r\n if (this.attachedMesh.scaling.x < 0) {\r\n this.attachedMesh.scaling.x *= -1;\r\n }\r\n if (this.attachedMesh.scaling.y < 0) {\r\n this.attachedMesh.scaling.y *= -1;\r\n }\r\n if (this.attachedMesh.scaling.z < 0) {\r\n this.attachedMesh.scaling.z *= -1;\r\n }\r\n this.attachedMesh.computeWorldMatrix().getRotationMatrixToRef(_tmpMatrix);\r\n this.attachedMesh.scaling.copyFrom(_tempVector);\r\n this.attachedMesh.computeWorldMatrix();\r\n Quaternion.FromRotationMatrixToRef(_tmpMatrix, this._rootMesh.rotationQuaternion);\r\n }\r\n // else if (this._rootMesh.rotationQuaternion) {\r\n // this._rootMesh.rotationQuaternion.set(0, 0, 0, 1);\r\n // }\r\n if (this.updateGizmoPositionToMatchAttachedMesh) {\r\n this._rootMesh.position.copyFrom(this.attachedMesh.absolutePosition);\r\n }\r\n if (this.updateScale && this.gizmoLayer.utilityLayerScene.activeCamera && this.attachedMesh) {\r\n let dist: number;\r\n const camera = this.gizmoLayer.utilityLayerScene.activeCamera;\r\n\r\n if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n dist = ((camera.orthoRight || 0) - (camera.orthoLeft || 0)) / 2;\r\n } else {\r\n let cameraPosition: Vector3;\r\n if (camera instanceof WebXRCamera && camera.globalPosition) {\r\n cameraPosition = camera.globalPosition;\r\n } else if (camera instanceof ArcRotateCamera) {\r\n cameraPosition = getCameraPositionWithOffset(camera);\r\n } else {\r\n cameraPosition = camera.globalPosition;\r\n }\r\n\r\n this._rootMesh.position.subtractToRef(cameraPosition, _tempVector);\r\n dist = _tempVector.length() * this.scaleRatio;\r\n }\r\n this._rootMesh.scaling.set(dist, dist, dist);\r\n }\r\n\r\n const pivot = this.attachedMesh.getPivotPoint();\r\n //let absolutePosition = this.attachedMesh.absolutePosition;\r\n\r\n // Absolute position is getting skewed because of the pivot point; need to get position without the rotation\r\n // if (pivot.length() > 0 && this.attachedMesh.rotationQuaternion) {\r\n // var m = new Matrix();\r\n // this.attachedMesh.rotationQuaternion.toRotationMatrix(m);\r\n // absolutePosition = Vector3.TransformCoordinates(absolutePosition, m)\r\n // }\r\n // if (pivot.length() > 0) {\r\n // absolutePosition = Vector3.Zero();\r\n // }\r\n\r\n this._rootMesh.position.copyFrom(Vector3.TransformCoordinates(pivot, this.attachedMesh.getWorldMatrix()));\r\n }\r\n }\r\n}\r\n","import { PointerDragBehavior } from '@babylonjs/core/Behaviors/Meshes/pointerDragBehavior';\r\nimport { PointerInfo } from '@babylonjs/core/Events/pointerEvents';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Observable, Observer } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { KbGizmo } from './gizmo';\r\n\r\n/**\r\n * Single plane rotation gizmo\r\n */\r\nexport class KbPlaneRotationGizmo extends KbGizmo {\r\n /**\r\n * Drag behavior responsible for the gizmos dragging interactions\r\n */\r\n public dragBehavior: PointerDragBehavior;\r\n private _pointerObserver: Nullable> = null;\r\n private rotationMesh: AbstractMesh;\r\n\r\n /**\r\n * Rotation distance in radians that the gizmo will snap to (Default: 0)\r\n */\r\n public snapDistance = 0;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the the change in distance\r\n */\r\n public onSnapObservable = new Observable<{ snapDistance: number }>();\r\n public updateObservable = new Observable<{ delta: Quaternion; deltaAngle: number }>();\r\n\r\n /**\r\n * Creates a PlaneRotationGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param planeNormal The normal of the plane which the gizmo will be able to rotate on\r\n * @param color The color of the gizmo\r\n * @param tessellation Amount of tessellation to be used when creating rotation circles\r\n */\r\n constructor(\r\n planeNormal: Vector3,\r\n color: Color3 = Color3.Gray(),\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n tessellation = 32\r\n ) {\r\n super(gizmoLayer);\r\n\r\n // Create Material\r\n const coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n coloredMaterial.emissiveColor = color;\r\n // coloredMaterial.diffuseColor = color;\r\n // coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\r\n\r\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n\r\n // Build mesh on root node\r\n const parentMesh = new AbstractMesh('', gizmoLayer.utilityLayerScene);\r\n\r\n const drag = Mesh.CreateTorus('', 0.6, 0.045, tessellation, gizmoLayer.utilityLayerScene);\r\n drag.visibility = 0;\r\n const rotationMesh = Mesh.CreateTorus('', 0.6, 0.01, tessellation, gizmoLayer.utilityLayerScene);\r\n rotationMesh.material = coloredMaterial;\r\n\r\n // Position arrow pointing in its drag axis\r\n rotationMesh.rotation.x = Math.PI / 2;\r\n drag.rotation.x = Math.PI / 2;\r\n parentMesh.addChild(rotationMesh);\r\n parentMesh.addChild(drag);\r\n parentMesh.lookAt(this._rootMesh.position.add(planeNormal));\r\n this.rotationMesh = parentMesh;\r\n\r\n this._rootMesh.addChild(parentMesh);\r\n parentMesh.scaling.scaleInPlace(1 / 3);\r\n // Add drag behavior to handle events when the gizmo is dragged\r\n this.dragBehavior = new PointerDragBehavior({ dragPlaneNormal: planeNormal });\r\n this.dragBehavior.moveAttached = false;\r\n this.dragBehavior.maxDragAngle = (Math.PI * 9) / 20;\r\n this.dragBehavior._useAlternatePickedPointAboveMaxDragAngle = true;\r\n this._rootMesh.addBehavior(this.dragBehavior);\r\n\r\n const lastDragPosition = new Vector3();\r\n\r\n this.dragBehavior.onDragStartObservable.add(e => {\r\n if (this.attachedMesh) {\r\n lastDragPosition.copyFrom(e.dragPlanePoint);\r\n }\r\n });\r\n\r\n const rotationMatrix = new Matrix();\r\n const planeNormalTowardsCamera = new Vector3();\r\n let localPlaneNormalTowardsCamera = new Vector3();\r\n\r\n const tmpSnapEvent = { snapDistance: 0 };\r\n let currentSnapDragDistance = 0;\r\n const tmpMatrix = new Matrix();\r\n const tmpVector = new Vector3();\r\n const amountToRotate = new Quaternion();\r\n this.dragBehavior.onDragObservable.add(event => {\r\n if (this.attachedMesh) {\r\n if (!this.attachedMesh.rotationQuaternion) {\r\n this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(\r\n this.attachedMesh.rotation.y,\r\n this.attachedMesh.rotation.x,\r\n this.attachedMesh.rotation.z\r\n );\r\n }\r\n\r\n // Remove parent priort to rotating\r\n const attachedMeshParent = this.attachedMesh.parent;\r\n if (attachedMeshParent) {\r\n this.attachedMesh.setParent(null);\r\n }\r\n\r\n // Calc angle over full 360 degree (https://stackoverflow.com/questions/43493711/the-angle-between-two-3d-vectors-with-a-result-range-0-360)\r\n const pivot = this.attachedMesh.getPivotPoint();\r\n const attachedMeshPosition = this.attachedMesh.absolutePosition.add(pivot);\r\n const newVector = event.dragPlanePoint.subtract(attachedMeshPosition).normalize();\r\n const originalVector = lastDragPosition.subtract(attachedMeshPosition).normalize();\r\n const cross = Vector3.Cross(newVector, originalVector);\r\n const dot = Vector3.Dot(newVector, originalVector);\r\n let angle = Math.atan2(cross.length(), dot);\r\n planeNormalTowardsCamera.copyFrom(planeNormal);\r\n localPlaneNormalTowardsCamera.copyFrom(planeNormal);\r\n if (this.updateGizmoRotationToMatchAttachedMesh) {\r\n this.attachedMesh.rotationQuaternion.toRotationMatrix(rotationMatrix);\r\n localPlaneNormalTowardsCamera = Vector3.TransformCoordinates(\r\n planeNormalTowardsCamera,\r\n rotationMatrix\r\n );\r\n }\r\n // Flip up vector depending on which side the camera is on\r\n if (gizmoLayer.utilityLayerScene.activeCamera) {\r\n const camVec = gizmoLayer.utilityLayerScene.activeCamera.position.subtract(\r\n this.attachedMesh.position\r\n );\r\n if (Vector3.Dot(camVec, localPlaneNormalTowardsCamera) > 0) {\r\n planeNormalTowardsCamera.scaleInPlace(-1);\r\n localPlaneNormalTowardsCamera.scaleInPlace(-1);\r\n }\r\n }\r\n const halfCircleSide = Vector3.Dot(localPlaneNormalTowardsCamera, cross) > 0.0;\r\n if (halfCircleSide) {\r\n angle = -angle;\r\n }\r\n\r\n // Snapping logic\r\n let snapped = false;\r\n if (this.snapDistance != 0) {\r\n currentSnapDragDistance += angle;\r\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\r\n let dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\r\n if (currentSnapDragDistance < 0) {\r\n dragSteps *= -1;\r\n }\r\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\r\n angle = this.snapDistance * dragSteps;\r\n snapped = true;\r\n } else {\r\n angle = 0;\r\n }\r\n }\r\n\r\n // If the mesh has a parent, convert needed world rotation to local rotation\r\n tmpMatrix.reset();\r\n if (this.attachedMesh.parent) {\r\n this.attachedMesh.parent.computeWorldMatrix().invertToRef(tmpMatrix);\r\n tmpMatrix.getRotationMatrixToRef(tmpMatrix);\r\n Vector3.TransformCoordinatesToRef(planeNormalTowardsCamera, tmpMatrix, planeNormalTowardsCamera);\r\n }\r\n\r\n // Convert angle and axis to quaternion (http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm)\r\n const quaternionCoefficient = Math.sin(angle / 2);\r\n amountToRotate.set(\r\n planeNormalTowardsCamera.x * quaternionCoefficient,\r\n planeNormalTowardsCamera.y * quaternionCoefficient,\r\n planeNormalTowardsCamera.z * quaternionCoefficient,\r\n Math.cos(angle / 2)\r\n );\r\n\r\n // If the meshes local scale is inverted (eg. loaded gltf file parent with z scale of -1) the rotation needs to be inverted on the y axis\r\n if (tmpMatrix.determinant() > 0) {\r\n amountToRotate.toEulerAnglesToRef(tmpVector);\r\n Quaternion.RotationYawPitchRollToRef(tmpVector.y, -tmpVector.x, -tmpVector.z, amountToRotate);\r\n }\r\n\r\n if (this.updateGizmoRotationToMatchAttachedMesh) {\r\n // Rotate selected mesh quaternion over fixed axis\r\n this.attachedMesh.rotationQuaternion.multiplyToRef(\r\n amountToRotate,\r\n this.attachedMesh.rotationQuaternion\r\n );\r\n } else {\r\n // Rotate selected mesh quaternion over rotated axis\r\n amountToRotate.multiplyToRef(\r\n this.attachedMesh.rotationQuaternion,\r\n this.attachedMesh.rotationQuaternion\r\n );\r\n }\r\n this.updateObservable.notifyObservers({ delta: amountToRotate, deltaAngle: angle });\r\n\r\n lastDragPosition.copyFrom(event.dragPlanePoint);\r\n if (snapped) {\r\n tmpSnapEvent.snapDistance = angle;\r\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\r\n }\r\n\r\n // Restore parent\r\n if (attachedMeshParent) {\r\n this.attachedMesh.setParent(attachedMeshParent);\r\n }\r\n }\r\n });\r\n\r\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\r\n if (this._customMeshSet) {\r\n return;\r\n }\r\n const isHovered =\r\n pointerInfo.pickInfo &&\r\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\r\n const material = isHovered ? hoverMaterial : coloredMaterial;\r\n this._rootMesh.getChildMeshes().forEach(m => {\r\n m.material = material;\r\n if ((m).color) {\r\n (m).color = material.diffuseColor;\r\n }\r\n });\r\n });\r\n\r\n // var light = gizmoLayer._getSharedGizmoLight();\r\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));\r\n }\r\n\r\n protected _attachedMeshChanged(value: Nullable) {\r\n if (this.dragBehavior) {\r\n this.dragBehavior.enabled = value ? true : false;\r\n }\r\n // if (value) {\r\n // this.rotationMesh.setPivotPoint(Vector3.Zero(), Space.LOCAL);\r\n // }\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.onSnapObservable.clear();\r\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\r\n this.dragBehavior.detach();\r\n super.dispose();\r\n }\r\n}\r\n","import { Color3, Matrix, Space, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Logger } from '@babylonjs/core/Misc/logger';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { KbAxisMorphGizmo } from './axis-morph-gizmo';\r\nimport { KbGizmo } from './gizmo';\r\nimport { KbPlaneRotationGizmo } from './plane-rotation-gizmo';\r\n\r\nconst tessellation = 32;\r\n\r\n/**\r\n * TODO\r\n * Copy in plane rotation gizmo code here and change it to use a sphere and click projection on the sphere\r\n * Convert it to return an axis\r\n * Edit code in here to return an axis and angle\r\n * update gizmo tools code to hook to this gizmo\r\n * remove the vector option from the original rotation gizmo (now the euler rotation gizmo), simplify code\r\n */\r\n\r\n/**\r\n * Gizmo that enables rotating a mesh along 3 axis\r\n */\r\nexport class KbAxisAngleGizmo extends KbGizmo {\r\n public targetAxis = new Vector3();\r\n /**\r\n * Internal gizmo used for interactions on the angle around the axis\r\n */\r\n public angleGizmo: KbPlaneRotationGizmo | undefined;\r\n\r\n /**\r\n * Internal gizmo used for interactions modifying the axis\r\n */\r\n public axisGizmo: KbAxisMorphGizmo;\r\n\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n public onDragStartObservable = new Observable();\r\n /** Fires an event when any of it's sub gizmos are released from dragging */\r\n public onDragObservable = new Observable<{ deltaAxis: Vector3; deltaAngle: number }>();\r\n public onDragEndObservable = new Observable<{ deltaAxis: Vector3; deltaAngle: number }>();\r\n\r\n public gizmoOffset: KbVector | undefined;\r\n public placementOffset: KbVector | undefined;\r\n private _positionSpace: TransformNode | undefined;\r\n\r\n attachTo(target: KbVector, positionSpace?: SpaceNode, placementOffset?: KbVector) {\r\n if (positionSpace) {\r\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\r\n }\r\n\r\n this._updateGizmoPosition(target, placementOffset);\r\n }\r\n updateGizmoPosition(changeTarget?: KbVector, placementOffset?: KbVector) {\r\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\r\n this.kbViewer.onNextFrame(() => {\r\n this._updateGizmoPosition(changeTarget, placementOffset);\r\n });\r\n }\r\n\r\n private _updateGizmoPosition(changeTarget?: KbVector, placementOffset?: KbVector) {\r\n // Maintain the placement offset if it is not provided later, so this can be called from other contexts to update based on external changes\r\n if (!placementOffset && this.placementOffset) {\r\n placementOffset = this.placementOffset;\r\n } else if (placementOffset) {\r\n this.placementOffset = placementOffset;\r\n }\r\n\r\n const positionSpaceTransform = this._positionSpace?.computeWorldMatrix(true);\r\n if (changeTarget) {\r\n changeTarget.toVec3(this.targetAxis);\r\n\r\n // If target is a vector, then we want to rotate it as a direction, so set the gizmo position to the origin to calculations are done from there\r\n // But store the position as the offset because we want the gizmo itself to be visually placed on the position space origin\r\n this.attachMeshAtNodeSpace(\r\n this.gizmoLayer.utilityLayerScene,\r\n placementOffset || KbVector.Zero(),\r\n positionSpaceTransform\r\n );\r\n\r\n if (this.attachedMesh) {\r\n this.gizmoOffset = KbVector.FromVec3(this.attachedMesh.position);\r\n this.attachedMesh.position = Vector3.Zero();\r\n this.attachedMesh.computeWorldMatrix(true);\r\n }\r\n const targetAxisTransformed = this.targetAxis.clone();\r\n if (positionSpaceTransform) {\r\n Vector3.TransformCoordinatesToRef(\r\n this.targetAxis,\r\n positionSpaceTransform.getRotationMatrix(),\r\n targetAxisTransformed\r\n );\r\n }\r\n this.axisGizmo.direction.copyFrom(targetAxisTransformed);\r\n }\r\n if (this.gizmoOffset && this.attachedMesh) {\r\n this.attachedMesh.position.copyFrom(this.gizmoOffset.toVec3());\r\n this.axisGizmo.gizmoPosition.copyFrom(this.gizmoOffset.toVec3());\r\n // if (placementOffset) {\r\n // this.axisGizmo.gizmoPosition.addInPlace(placementOffset.toVec3());\r\n // }\r\n }\r\n // if (positionSpaceTransform) {\r\n // Vector3.TransformCoordinatesToRef(this.axisGizmo.gizmoPosition, positionSpaceTransform, this.axisGizmo.gizmoPosition);\r\n // }\r\n super.updateGizmoPosition();\r\n }\r\n\r\n public get attachedMesh() {\r\n return super.attachedMesh;\r\n }\r\n public set attachedMesh(mesh: Nullable) {\r\n super.attachedMesh = mesh;\r\n if (mesh) {\r\n const angleMesh = new Mesh('', this.gizmoLayer.utilityLayerScene);\r\n mesh.addChild(angleMesh);\r\n if (this.angleGizmo) {\r\n this.angleGizmo.attachedMesh = angleMesh;\r\n }\r\n angleMesh.lookAt(this.targetAxis);\r\n angleMesh.setPivotPoint(mesh.getPivotPoint(), Space.WORLD);\r\n } else if (this.angleGizmo) {\r\n this.angleGizmo.attachedMesh = null;\r\n }\r\n }\r\n\r\n private axisChange: Vector3;\r\n private angleChange: number;\r\n /**\r\n * Creates a RotationGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param tessellation Amount of tessellation to be used when creating rotation circles\r\n */\r\n constructor(\r\n private kbViewer: KbViewer,\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n disableAngle = false\r\n ) {\r\n super(gizmoLayer);\r\n this.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.axisGizmo = new KbAxisMorphGizmo(Color3.Green().scale(0.5), gizmoLayer, tessellation);\r\n if (!disableAngle) {\r\n this.angleGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(0, 0, 1),\r\n Color3.Green().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.angleGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n }\r\n\r\n const zeroVector = Vector3.Zero();\r\n const tempVector = Vector3.Zero();\r\n const tempVector2 = Vector3.Zero();\r\n let positionSpaceTransform: Matrix | undefined;\r\n this.axisChange = Vector3.Zero();\r\n this.angleChange = 0;\r\n\r\n // Relay drag events\r\n [this.axisGizmo, this.angleGizmo].forEach(gizmo => {\r\n if (gizmo) {\r\n gizmo.dragBehavior.onDragStartObservable.add(() => {\r\n this.onDragStartObservable.notifyObservers();\r\n this.axisChange = Vector3.Zero();\r\n this.angleChange = 0;\r\n if (!positionSpaceTransform && this._positionSpace) {\r\n positionSpaceTransform = this._positionSpace\r\n .computeWorldMatrix(true)\r\n .getRotationMatrix()\r\n .clone()\r\n .invert();\r\n }\r\n });\r\n gizmo.dragBehavior.onDragEndObservable.add(() => {\r\n this.onDragEndObservable.notifyObservers({\r\n deltaAxis: this.axisChange,\r\n deltaAngle: this.angleChange,\r\n });\r\n });\r\n }\r\n });\r\n this.axisGizmo.updateObservable.add(event => {\r\n tempVector.copyFrom(this.targetAxis);\r\n // if (positionSpaceTransform) {\r\n // Vector3.TransformCoordinatesToRef(tempVector, positionSpaceTransform, tempVector);\r\n // }\r\n\r\n tempVector.rotateByQuaternionToRef(event.delta, tempVector2);\r\n // if (positionSpaceTransform) {\r\n // Vector3.TransformCoordinatesToRef(tempVector2, positionSpaceTransform.clone().invert(), tempVector2);\r\n // }\r\n\r\n tempVector2.subtractToRef(this.targetAxis, tempVector2);\r\n\r\n this.targetAxis.addInPlace(tempVector2);\r\n this.axisChange.addInPlace(tempVector2);\r\n this.onDragObservable.notifyObservers({ deltaAxis: tempVector2, deltaAngle: 0 });\r\n\r\n if (this.angleGizmo && this.angleGizmo.attachedMesh) {\r\n this.angleGizmo.attachedMesh.lookAt(\r\n positionSpaceTransform\r\n ? Vector3.TransformCoordinates(this.targetAxis, positionSpaceTransform)\r\n : this.targetAxis\r\n );\r\n }\r\n });\r\n if (this.angleGizmo) {\r\n this.angleGizmo.updateObservable.add(event => {\r\n this.angleChange -= event.deltaAngle;\r\n this.onDragObservable.notifyObservers({ deltaAxis: zeroVector, deltaAngle: -event.deltaAngle });\r\n });\r\n }\r\n\r\n this.attachedMesh = null;\r\n }\r\n\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public set snapDistance(value: number) {\r\n if (this.axisGizmo) {\r\n this.axisGizmo.snapDistance = value;\r\n }\r\n if (this.angleGizmo) {\r\n this.angleGizmo.snapDistance = value;\r\n }\r\n }\r\n public get snapDistance() {\r\n return this.axisGizmo.snapDistance;\r\n }\r\n\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n public set scaleRatio(value: number) {\r\n if (this.axisGizmo) {\r\n this.axisGizmo.scaleRatio = value;\r\n }\r\n if (this.angleGizmo) {\r\n this.angleGizmo.scaleRatio = value;\r\n }\r\n }\r\n public get scaleRatio() {\r\n return this.axisGizmo.scaleRatio;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n if (this.axisGizmo) {\r\n this.axisGizmo.dispose();\r\n }\r\n if (this.angleGizmo) {\r\n this.angleGizmo.dispose();\r\n }\r\n this.onDragStartObservable.clear();\r\n this.onDragEndObservable.clear();\r\n }\r\n\r\n /**\r\n * CustomMeshes are not supported by this gizmo\r\n * @param mesh The mesh to replace the default mesh of the gizmo\r\n */\r\n public setCustomMesh(mesh: Mesh) {\r\n Logger.Error(\r\n 'Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.angleGizmo, gizmo.zGizmo)'\r\n );\r\n }\r\n}\r\n","import { Vector3 } from '@babylonjs/core/Maths';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { take } from 'rxjs/operators';\r\nimport { BoundingBoxCache } from './bounding-box-cache';\r\n\r\nexport interface IMeshInfo {\r\n faceCount: number;\r\n faceNeighbors: number[][];\r\n facePositions: number[];\r\n faceNormals: number[];\r\n}\r\n\r\nconst meshFaceInfo = new Map();\r\n\r\nexport class MeshFaceEngine {\r\n private bbCache: BoundingBoxCache;\r\n\r\n constructor(private kbViewer: KbViewer) {\r\n this.bbCache = kbViewer.bbCache;\r\n }\r\n\r\n initialize(node: MeshNode | Mesh) {\r\n let meshNode: MeshNode;\r\n let mesh: Mesh;\r\n if (node instanceof Kb3dObject) {\r\n mesh = this.kbViewer.getRendererNode(node) as Mesh;\r\n meshNode = node;\r\n } else {\r\n mesh = node;\r\n meshNode = getByDynamicId(node.id) as MeshNode;\r\n }\r\n if (mesh instanceof Mesh && mesh.geometry) {\r\n this.bbCache\r\n .watchForChanges(meshNode)\r\n .pipe(take(1))\r\n .subscribe(() => {\r\n meshFaceInfo.delete(meshNode._dynamicId);\r\n });\r\n\r\n return this.updateNodeGeometry(mesh);\r\n }\r\n }\r\n\r\n getMeshFaces(node: MeshNode | Mesh) {\r\n let result = meshFaceInfo.get(node instanceof Kb3dObject ? node._dynamicId : node.id);\r\n if (!result) {\r\n result = this.initialize(node);\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * @param selection array of selected faces to expand from\r\n * @param limitAngle angle to limit selection to. If undefined, function will expand by 1 polygon\r\n */\r\n expandSelection(selection: number[], node: MeshNode | Mesh, limitAngle?: number) {\r\n const faceInfo = this.getMeshFaces(node);\r\n const faceNormals = faceInfo!.faceNormals;\r\n\r\n const selectedFaceIds: boolean[] = [];\r\n const newSelection: number[] = [];\r\n if (limitAngle !== undefined) {\r\n limitAngle = (limitAngle * Math.PI) / 180;\r\n }\r\n const v1 = new Vector3(),\r\n v2 = new Vector3();\r\n\r\n if (!faceInfo) {\r\n return selection;\r\n }\r\n\r\n for (let i = 0; i < selection.length; i++) {\r\n selectedFaceIds[selection[i]] = true;\r\n }\r\n for (let i = 0; i < selection.length; i++) {\r\n const faceId = selection[i];\r\n v1.copyFromFloats(faceNormals[faceId * 3], faceNormals[faceId * 3 + 1], faceNormals[faceId * 3 + 2]);\r\n recursiveExpandSelection(faceId, 1, v1);\r\n }\r\n for (const faceId in selectedFaceIds) {\r\n newSelection.push(parseInt(faceId, 10));\r\n }\r\n\r\n return newSelection;\r\n\r\n function recursiveExpandSelection(faceId: number, iterCount: number, normal: Vector3) {\r\n const neighbors = faceInfo!.faceNeighbors[faceId];\r\n if (limitAngle === undefined && iterCount <= 0) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < neighbors.length; i++) {\r\n const adjacentFaceId = neighbors[i];\r\n if (!selectedFaceIds[adjacentFaceId]) {\r\n if (limitAngle !== undefined) {\r\n v2.copyFromFloats(\r\n faceNormals[adjacentFaceId * 3],\r\n faceNormals[adjacentFaceId * 3 + 1],\r\n faceNormals[adjacentFaceId * 3 + 2]\r\n );\r\n\r\n if (\r\n Math.abs(Math.acos(Math.round(Vector3.Dot(normal, v2) * 1000000) / 1000000)) <= limitAngle\r\n ) {\r\n // deal with FP Errors\r\n selectedFaceIds[adjacentFaceId] = true;\r\n recursiveExpandSelection(adjacentFaceId, iterCount - 1, normal);\r\n }\r\n } else {\r\n selectedFaceIds[adjacentFaceId] = true;\r\n recursiveExpandSelection(adjacentFaceId, iterCount - 1, normal);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private updateNodeGeometry(mesh: Mesh) {\r\n if (mesh.geometry) {\r\n const indices = mesh.geometry.getIndices();\r\n const positions = mesh.geometry.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n const v1 = new Vector3();\r\n const v2 = new Vector3();\r\n const v3 = new Vector3();\r\n const v4 = new Vector3();\r\n\r\n if (indices && positions) {\r\n const facesByEdges: { [key: string]: number[] } = {};\r\n /** Sets of three faces by index adjacent to each face by index */\r\n const faceNeighbors: number[][] = [];\r\n /** Sets of xyz scalars making up the face normals */\r\n const faceNormals: number[] = [];\r\n const facePositions: number[] = [];\r\n\r\n const trianglesCount = indices.length / 3;\r\n for (let triId = 0; triId < trianglesCount; triId++) {\r\n const triOffset = triId * 3;\r\n // Get the triangle position vertices\r\n v1.copyFromFloats(\r\n positions[indices[triOffset] * 3],\r\n positions[indices[triOffset] * 3 + 1],\r\n positions[indices[triOffset] * 3 + 2]\r\n );\r\n v2.copyFromFloats(\r\n positions[indices[triOffset + 1] * 3],\r\n positions[indices[triOffset + 1] * 3 + 1],\r\n positions[indices[triOffset + 1] * 3 + 2]\r\n );\r\n v3.copyFromFloats(\r\n positions[indices[triOffset + 2] * 3],\r\n positions[indices[triOffset + 2] * 3 + 1],\r\n positions[indices[triOffset + 2] * 3 + 2]\r\n );\r\n\r\n // Calculate the centroid of each face\r\n v4.setAll(0);\r\n v4.addInPlace(v1).addInPlace(v2).addInPlace(v3);\r\n v4.scaleInPlace(1 / 3);\r\n facePositions.push(v4.x, v4.y, v4.z);\r\n\r\n // Get two of the triangle edges\r\n v1.subtractInPlace(v2);\r\n v2.subtractInPlace(v3);\r\n\r\n // Get the triangle face normal with the two edges.\r\n // Note that this is not the geometry normal, but the position-based face normal\r\n Vector3.CrossToRef(v1, v2, v4);\r\n const faceNormal = v4;\r\n faceNormal.normalize();\r\n faceNormals.push(faceNormal.x, faceNormal.y, faceNormal.z);\r\n\r\n // Now we need to consolidate what triangles are next to each other by organizing them by edges\r\n for (let i = 0; i < 3; i++) {\r\n const idx1 = indices[triOffset + i];\r\n const idx2 = indices[triOffset + ((i + 1) % 3)];\r\n\r\n // This is not going to work for geometry seams like on cylinders.\r\n // Possibly change from index ids to a representation of the vertex position\r\n const edgeId = idx1 > idx2 ? `${idx1}-${idx2}` : `${idx2}-${idx1}`;\r\n if (!facesByEdges[edgeId]) {\r\n facesByEdges[edgeId] = [];\r\n }\r\n\r\n facesByEdges[edgeId].push(triId);\r\n }\r\n }\r\n\r\n // Now we go through the edges and register the neighbors for each triangle\r\n for (const edgeId in facesByEdges) {\r\n const faces = facesByEdges[edgeId];\r\n if (!faceNeighbors[faces[0]]) {\r\n faceNeighbors[faces[0]] = [];\r\n }\r\n // Some edges may only have one face if the face is on the edge of the geometry\r\n if (faces.length > 1) {\r\n if (!faceNeighbors[faces[1]]) {\r\n faceNeighbors[faces[1]] = [];\r\n }\r\n\r\n faceNeighbors[faces[0]].push(faces[1]);\r\n faceNeighbors[faces[1]].push(faces[0]);\r\n }\r\n }\r\n\r\n const result = {\r\n faceCount: trianglesCount,\r\n faceNeighbors,\r\n facePositions,\r\n faceNormals,\r\n };\r\n meshFaceInfo.set(mesh.id, result);\r\n return result;\r\n }\r\n }\r\n }\r\n}\r\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { PickingInfo } from '@babylonjs/core/Collisions/pickingInfo';\r\nimport { Ray } from '@babylonjs/core/Culling/ray';\r\nimport { KeyboardEventTypes, KeyboardInfo } from '@babylonjs/core/Events/keyboardEvents';\r\nimport { PointerEventTypes } from '@babylonjs/core/Events/pointerEvents';\r\nimport { Matrix, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Node as babylonNode } from '@babylonjs/core/node';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { instanceOf } from '@models/classes/decorators/model-utils';\r\nimport {\r\n IDraggable,\r\n IKb3dFacetSelectArgs,\r\n IKb3dPickInfo,\r\n IKb3dPointerArgs,\r\n IKeyboardArgs,\r\n Kb3dPointerHandler,\r\n PointerInfoMinimal,\r\n eHandler,\r\n} from '@models/classes/handlers';\r\nimport { Kb3dManager, getByDynamicId } from '@models/classes/kb3d-manager';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { Token } from '@models/classes/token';\r\nimport { EMPTY, Observable, Subject } from 'rxjs';\r\nimport { distinctUntilChanged } from 'rxjs/operators';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport { KbArcRotateCamera } from './cameras/kb-arc-rotate-camera';\r\nimport { Dragger } from './dragger';\r\nimport { MeshFaceEngine } from './face-engine';\r\nimport { Highlighter } from './highlighter';\r\n\r\ninterface INodeHandlers {\r\n node: SpaceNode;\r\n handlers: T[];\r\n}\r\n\r\nexport enum eMarqueeSelectMode {\r\n Facets,\r\n Vertices,\r\n}\r\n\r\nexport interface IMarqueeSelectOptions {\r\n cullSelection?: boolean; // If true, don't select faces facing away\r\n onlyOnShiftPress?: boolean;\r\n}\r\n\r\nexport class Interaction {\r\n constructor(private kbViewer: KbViewer, private scene: Scene, public highlighter: Highlighter) {\r\n this.meshFaceEngine = new MeshFaceEngine(kbViewer);\r\n\r\n this.onClick = this.onClick$.asObservable();\r\n this.onFacetClick = this.onFacetClick$.asObservable();\r\n this.onDoubleClick = this.onDoubleClick$.asObservable();\r\n this.onPointerMove = this.onPointerMove$.asObservable();\r\n this.onPointerDown = this.onPointerDown$.asObservable();\r\n this.onPointerUp = this.onPointerUp$.asObservable();\r\n this.onKeyboard = this.onKeyboard$.asObservable();\r\n\r\n this.attachScene(scene);\r\n }\r\n\r\n attachScene(scene: Scene, utilityLayer = false) {\r\n scene.onPointerObservable.add(p => {\r\n const args = this.getKb3dPointerArgs(p);\r\n\r\n switch (p.type) {\r\n case PointerEventTypes.POINTERDOWN:\r\n this.handlePointerDown(args);\r\n break;\r\n case PointerEventTypes.POINTERUP:\r\n this.handlePointerUp(args);\r\n break;\r\n case PointerEventTypes.POINTERMOVE:\r\n this.handleMove(args);\r\n break;\r\n // case PointerEventTypes.POINTERWHEEL:\r\n // console.log(\"POINTER WHEEL\");\r\n // break;\r\n // case PointerEventTypes.POINTERPICK:\r\n // console.log(\"POINTER PICK\");\r\n // break;\r\n case PointerEventTypes.POINTERTAP:\r\n this.handleClick(args);\r\n break;\r\n case PointerEventTypes.POINTERDOUBLETAP:\r\n this.handleDoubleClick(args);\r\n break;\r\n }\r\n });\r\n\r\n scene.onKeyboardObservable.add(k => {\r\n const args = this.getKeyboardArgs(k);\r\n\r\n switch (k.type) {\r\n case KeyboardEventTypes.KEYDOWN:\r\n this.handleKeyboard(args);\r\n }\r\n });\r\n }\r\n\r\n /**observables for consumers to subscribe to */\r\n public onClick: Observable;\r\n public onFacetClick: Observable;\r\n public onDoubleClick: Observable;\r\n public onPointerMove: Observable;\r\n public onPointerDown: Observable;\r\n public onPointerUp: Observable;\r\n public onKeyboard: Observable;\r\n private onClick$ = new Subject();\r\n private onFacetClick$ = new Subject();\r\n private onDoubleClick$ = new Subject();\r\n private onPointerMove$ = new Subject();\r\n private onPointerDown$ = new Subject();\r\n private onPointerUp$ = new Subject();\r\n private onKeyboard$ = new Subject();\r\n\r\n private onMarqueeSelect: Subject | null = null;\r\n\r\n public pointerIsDown = false;\r\n public dragInProgress = false;\r\n private readonly meshFaceEngine: MeshFaceEngine;\r\n private selectionTolerance = 0;\r\n private marqueeSelectOptions: IMarqueeSelectOptions & {\r\n mode: eMarqueeSelectMode;\r\n startX: number;\r\n startY: number;\r\n startRay?: Ray;\r\n selectBox?: HTMLDivElement;\r\n mesh: Mesh;\r\n };\r\n private cameraFacingDirection = new Vector3();\r\n\r\n public setSelectionTolerance(tolerance: number) {\r\n this.selectionTolerance = tolerance;\r\n }\r\n\r\n public setSelectionCulling(enabled: boolean) {\r\n if (this.marqueeSelectOptions) {\r\n this.marqueeSelectOptions.cullSelection = enabled;\r\n }\r\n }\r\n\r\n public enableMarqueeSelect(meshNode: MeshNode, mode: eMarqueeSelectMode, options?: IMarqueeSelectOptions) {\r\n const mesh = this.kbViewer.getRendererNode(meshNode);\r\n\r\n if (mesh instanceof Mesh) {\r\n this.onMarqueeSelect = new Subject();\r\n\r\n this.marqueeSelectOptions = {\r\n cullSelection: false,\r\n onlyOnShiftPress: true,\r\n startX: 0,\r\n startY: 0,\r\n mode,\r\n mesh,\r\n ...(options || {}),\r\n };\r\n\r\n return this.onMarqueeSelect.asObservable().pipe(\r\n distinctUntilChanged((prev, curr) => {\r\n if (\r\n prev.selectedFaces.length !== curr.selectedFaces.length ||\r\n prev.vertexList.length !== curr.vertexList.length\r\n ) {\r\n return false;\r\n }\r\n for (let i = 0; i < curr.selectedFaces.length; i++) {\r\n if (curr.selectedFaces[i] !== prev.selectedFaces[i]) {\r\n return false;\r\n }\r\n }\r\n for (let i = 0; i < curr.vertexList.length; i++) {\r\n if (curr.vertexList[i] !== prev.vertexList[i]) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n })\r\n );\r\n }\r\n return EMPTY;\r\n }\r\n\r\n public disableMarqueeSelect() {\r\n if (this.onMarqueeSelect) {\r\n this.onMarqueeSelect.complete();\r\n }\r\n this.onMarqueeSelect = null;\r\n }\r\n\r\n /** Do a hit test of the scene using x,y screen pixel coordinates */\r\n public pick(x: number, y: number, camera?: Camera) {\r\n const pickInfo = this.scene.pick(x, y, undefined, undefined, camera);\r\n if (pickInfo && pickInfo.hit) {\r\n const info = { ...pickInfo } as PickingInfo & IKb3dPickInfo;\r\n this.fillKb3dPickInfo(pickInfo, info);\r\n return info;\r\n }\r\n return undefined;\r\n }\r\n\r\n protected handleClickTypeEvent(args: IKb3dPointerArgs, handlerType: eHandler) {\r\n // For debugging\r\n // if (args.pickInfo?.ray) {\r\n // RayHelper.CreateAndShow(args.pickInfo.ray, this.scene, new Color3(1, 1, 0.1));\r\n // }\r\n\r\n if (args.targetNode) {\r\n //bubble up event, calling any handlers that have been applied to the nodes\r\n let h = this.getNextNodeHandlers(args.targetNode, handlerType)!;\r\n\r\n while (h) {\r\n let propagate = false;\r\n args.sourceNode = h.node;\r\n for (const handler of h.handlers) {\r\n handler(args);\r\n if (args.propagate) propagate = true;\r\n }\r\n if (!propagate) break;\r\n h = this.getNextNodeHandlers(h.node._parent!, handlerType)!;\r\n }\r\n } else {\r\n //there was no clicked mesh, but if there is a handler on the root scene node, we trigger that\r\n const handlers = this.getHandlerMap(this.kbViewer.sceneNode, handlerType).getByKey(\r\n this.kbViewer.sceneNode\r\n ) as Kb3dPointerHandler[];\r\n if (handlers) {\r\n args.targetNode = args.sourceNode = this.kbViewer.sceneNode;\r\n for (const handler of handlers) {\r\n handler(args);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public handleClick(args: IKb3dPointerArgs) {\r\n this.handleClickTypeEvent(args, eHandler.click);\r\n // trigger the normal generic observable\r\n this.onClick$.next(args);\r\n\r\n // if there is an observer on the facet click, then send the facet data there\r\n if (this.onFacetClick$.observers.length > 0) {\r\n if (args.pickInfo?.pickedMesh && args.pickInfo.pickedMesh instanceof Mesh) {\r\n const pickedMesh = args.pickInfo.pickedMesh;\r\n\r\n const selectedTriangle = args.pickInfo.faceId;\r\n const faceInfo = this.meshFaceEngine.getMeshFaces(pickedMesh);\r\n if (faceInfo) {\r\n let selection: number[] = [];\r\n if (this.selectionTolerance >= 0) {\r\n selection = this.meshFaceEngine.expandSelection(\r\n [selectedTriangle],\r\n pickedMesh,\r\n this.selectionTolerance\r\n );\r\n } else {\r\n selection = [selectedTriangle];\r\n }\r\n\r\n const facetArgs: IKb3dFacetSelectArgs = {\r\n ...args,\r\n altKey: args.event.altKey,\r\n selectedFaces: selection,\r\n };\r\n\r\n this.onFacetClick$.next(facetArgs);\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected handleDoubleClick(args: IKb3dPointerArgs) {\r\n this.handleClickTypeEvent(args, eHandler.doubleClick);\r\n //trigger the normal generic observable\r\n this.onDoubleClick$.next(args);\r\n }\r\n\r\n protected handleMove(args: IKb3dPointerArgs) {\r\n if (!this.pointerIsDown && this.kbViewer.sceneNode && this.kbViewer.sceneNode.enableHoverEffects) {\r\n if (args.targetNode) {\r\n const clicks = this.getNextClickHandlers(args.targetNode);\r\n const draggables = this.getNextDraggables(args.targetNode);\r\n if (clicks || draggables) {\r\n const n = clicks?.node || (draggables?.node as SpaceNode);\r\n this.highlighter.hover(n);\r\n }\r\n } else {\r\n this.highlighter.clearHover();\r\n }\r\n }\r\n\r\n if (this.scene.activeCamera instanceof KbArcRotateCamera && this.pointerIsDown && this.onMarqueeSelect) {\r\n if (!this.marqueeSelectOptions.onlyOnShiftPress || args.shiftKey) {\r\n args.event.preventDefault();\r\n (args.event as MouseEvent).stopPropagation();\r\n this.handleMarquee(args, this.scene.activeCamera);\r\n } else {\r\n this.unlockCamera();\r\n }\r\n }\r\n\r\n this.onPointerMove$.next(args);\r\n }\r\n\r\n public handlePointerDown(args: IKb3dPointerArgs) {\r\n this.pointerIsDown = true;\r\n\r\n if (this.onMarqueeSelect) {\r\n if (!this.marqueeSelectOptions.onlyOnShiftPress || args.shiftKey) {\r\n this.marqueeSelectOptions.startX = args.canvasX || 0;\r\n this.marqueeSelectOptions.startY = args.canvasY || 0;\r\n this.marqueeSelectOptions.startRay =\r\n this.scene.pick(args.canvasX!, args.canvasY!, undefined, undefined, this.scene.activeCamera)?.ray ||\r\n undefined;\r\n\r\n if (this.kbViewer.uiOverlay) {\r\n const selectBox = document.createElement('div');\r\n selectBox.style.position = 'absolute';\r\n selectBox.style.border = '1px dashed white';\r\n selectBox.style.background = 'rgba(128, 128, 128, 0.1)';\r\n selectBox.style.opacity = '0.5';\r\n this.kbViewer.uiOverlay.appendChild(selectBox);\r\n this.marqueeSelectOptions.selectBox = selectBox;\r\n }\r\n\r\n this.cameraFacingDirection = this.scene.activeCamera!.getForwardRay().direction;\r\n if (\r\n !this.marqueeSelectOptions.mesh.isFacetDataEnabled &&\r\n this.marqueeSelectOptions.mode === eMarqueeSelectMode.Facets\r\n ) {\r\n const normals = this.marqueeSelectOptions.mesh.getVerticesData(VertexBuffer.NormalKind);\r\n if (!normals) {\r\n this.marqueeSelectOptions.mesh.setVerticesData(\r\n VertexBuffer.NormalKind,\r\n new Float32Array(this.marqueeSelectOptions.mesh.getTotalVertices() * 3)\r\n );\r\n }\r\n }\r\n }\r\n } else if (args.targetNode) {\r\n const d = this.getNextDraggables(args.targetNode);\r\n if (d) {\r\n this.highlighter.clearHover();\r\n args.sourceNode = d.node;\r\n const dragger = new Dragger(this.kbViewer, this.scene);\r\n this.dragInProgress = true;\r\n dragger.startDrag(args, d.handlers[0], () => {\r\n this.dragInProgress = false;\r\n });\r\n }\r\n }\r\n\r\n this.onPointerDown$.next(args);\r\n }\r\n\r\n protected unlockCamera() {\r\n this.scene.activeCamera?.attachControl(this.kbViewer.canvas!);\r\n }\r\n\r\n public handlePointerUp(args: IKb3dPointerArgs) {\r\n this.pointerIsDown = false;\r\n if (this.marqueeSelectOptions && this.marqueeSelectOptions.selectBox) {\r\n this.kbViewer.uiOverlay?.removeChild(this.marqueeSelectOptions.selectBox);\r\n delete this.marqueeSelectOptions.selectBox;\r\n }\r\n this.unlockCamera();\r\n\r\n this.onPointerUp$.next(args);\r\n }\r\n\r\n protected handleKeyboard(args: IKeyboardArgs) {\r\n this.onKeyboard$.next(args);\r\n }\r\n\r\n protected handleMarquee(args: IKb3dPointerArgs, activeCamera: KbArcRotateCamera) {\r\n const mouseX = args.canvasX || 0;\r\n const mouseY = args.canvasY || 0;\r\n\r\n activeCamera.detachControl();\r\n\r\n if (this.marqueeSelectOptions.selectBox) {\r\n this.marqueeSelectOptions.selectBox.style.left = Math.min(this.marqueeSelectOptions.startX, mouseX) + 'px';\r\n this.marqueeSelectOptions.selectBox.style.top = Math.min(this.marqueeSelectOptions.startY, mouseY) + 'px';\r\n this.marqueeSelectOptions.selectBox.style.width =\r\n Math.abs(this.marqueeSelectOptions.startX - mouseX) + 'px';\r\n this.marqueeSelectOptions.selectBox.style.height =\r\n Math.abs(this.marqueeSelectOptions.startY - mouseY) + 'px';\r\n }\r\n let topOrigin: Vector3;\r\n let leftOrigin: Vector3;\r\n let rightOrigin: Vector3;\r\n let bottomOrigin: Vector3;\r\n let topNormal: Vector3 | undefined;\r\n let leftNormal: Vector3 | undefined;\r\n let rightNormal: Vector3 | undefined;\r\n let bottomNormal: Vector3 | undefined;\r\n const m = Matrix.Identity();\r\n const boxL = Math.min(this.marqueeSelectOptions.startX, mouseX);\r\n const boxR = Math.max(this.marqueeSelectOptions.startX, mouseX);\r\n const boxT = Math.min(this.marqueeSelectOptions.startY, mouseY);\r\n const boxB = Math.max(this.marqueeSelectOptions.startY, mouseY);\r\n\r\n if (activeCamera.mode === Camera.ORTHOGRAPHIC_CAMERA) {\r\n // ORTHOGRAPHIC CAMERA\r\n const forwardDirection = activeCamera.getForwardRay().direction;\r\n const sideDirection = Vector3.Cross(forwardDirection, Vector3.Up());\r\n topNormal = Vector3.Cross(forwardDirection, sideDirection);\r\n leftNormal = sideDirection;\r\n rightNormal = sideDirection.scale(-1);\r\n bottomNormal = Vector3.Cross(sideDirection, forwardDirection);\r\n topOrigin = this.scene.createPickingRay(boxL, boxT, m, activeCamera).origin;\r\n leftOrigin = this.scene.createPickingRay(boxL, boxT, m, activeCamera).origin;\r\n rightOrigin = this.scene.createPickingRay(boxR, boxB, m, activeCamera).origin;\r\n bottomOrigin = this.scene.createPickingRay(boxR, boxB, m, activeCamera).origin;\r\n } else {\r\n // PERSPECTIVE CAMERA\r\n // Assemble the 4 planes of the marquee select\r\n const origin = this.marqueeSelectOptions.startRay?.origin || activeCamera.position;\r\n topOrigin = origin;\r\n leftOrigin = origin;\r\n rightOrigin = origin;\r\n bottomOrigin = origin;\r\n\r\n const topLeft = this.scene.createPickingRay(boxL, boxT, m, activeCamera).direction;\r\n const topRight = this.scene.createPickingRay(boxR, boxT, m, activeCamera).direction;\r\n const botLeft = this.scene.createPickingRay(boxL, boxB, m, activeCamera).direction;\r\n const botRight = this.scene.createPickingRay(boxR, boxB, m, activeCamera).direction;\r\n\r\n if (topLeft && topRight && botLeft && botRight) {\r\n // Normals of the planes are equal to the cross product of the two vectors that define the plane\r\n topNormal = Vector3.Cross(topLeft, topRight);\r\n leftNormal = Vector3.Cross(botLeft, topLeft);\r\n rightNormal = Vector3.Cross(topRight, botRight);\r\n bottomNormal = Vector3.Cross(botRight, botLeft);\r\n }\r\n }\r\n\r\n if (topNormal && leftNormal && rightNormal && bottomNormal) {\r\n const mesh = this.marqueeSelectOptions.mesh;\r\n const fP = new Vector3();\r\n const fN = new Vector3();\r\n\r\n if (this.marqueeSelectOptions.mode === eMarqueeSelectMode.Facets) {\r\n const faceInfo = this.meshFaceEngine.getMeshFaces(mesh)!;\r\n const transform = mesh.computeWorldMatrix();\r\n\r\n const n = faceInfo.faceCount;\r\n const res = [] as number[];\r\n\r\n for (let i = 0; i < n; i++) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(\r\n faceInfo.facePositions[i * 3],\r\n faceInfo.facePositions[i * 3 + 1],\r\n faceInfo.facePositions[i * 3 + 2],\r\n transform,\r\n fP\r\n );\r\n if (this.marqueeSelectOptions.cullSelection) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(\r\n faceInfo.faceNormals[i * 3],\r\n faceInfo.faceNormals[i * 3 + 1],\r\n faceInfo.faceNormals[i * 3 + 2],\r\n transform,\r\n fN\r\n );\r\n }\r\n if (\r\n (!this.marqueeSelectOptions.cullSelection || Vector3.Dot(this.cameraFacingDirection, fN) > 0) &&\r\n pointPlaneSizeToRef(topNormal, topOrigin, fP) >= 0 &&\r\n pointPlaneSizeToRef(leftNormal, leftOrigin, fP) >= 0 &&\r\n pointPlaneSizeToRef(rightNormal, rightOrigin, fP) >= 0 &&\r\n pointPlaneSizeToRef(bottomNormal, bottomOrigin, fP) >= 0\r\n ) {\r\n res.push(i);\r\n }\r\n }\r\n\r\n this.onMarqueeSelect!.next({\r\n ...args,\r\n altKey: args.event.altKey,\r\n vertexList: [],\r\n selectedFaces: res,\r\n });\r\n } else if (this.marqueeSelectOptions.mode === eMarqueeSelectMode.Vertices) {\r\n const vertexPositions = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n const transform = mesh.getWorldMatrix();\r\n const res = [] as number[];\r\n\r\n if (vertexPositions) {\r\n const n = vertexPositions.length / 3;\r\n for (let i = 0; i < n; i++) {\r\n fP.copyFromFloats(\r\n vertexPositions[i * 3],\r\n vertexPositions[i * 3 + 1],\r\n vertexPositions[i * 3 + 2]\r\n );\r\n Vector3.TransformCoordinatesToRef(fP, transform, fP);\r\n\r\n if (\r\n (!this.marqueeSelectOptions.cullSelection ||\r\n Vector3.Dot(this.cameraFacingDirection, mesh.getFacetNormal(i))) &&\r\n pointPlaneSizeToRef(topNormal, topOrigin, fP) >= 0 &&\r\n pointPlaneSizeToRef(leftNormal, leftOrigin, fP) >= 0 &&\r\n pointPlaneSizeToRef(rightNormal, rightOrigin, fP) >= 0 &&\r\n pointPlaneSizeToRef(bottomNormal, bottomOrigin, fP) >= 0\r\n ) {\r\n res.push(i);\r\n }\r\n }\r\n\r\n mesh.getIndices();\r\n this.onMarqueeSelect!.next({\r\n ...args,\r\n altKey: args.event.altKey,\r\n vertexList: res,\r\n selectedFaces: [],\r\n });\r\n }\r\n }\r\n }\r\n\r\n function pointPlaneSizeToRef(normal: Vector3, origin: Vector3, point: Vector3) {\r\n return normal.x * (point.x - origin.x) + normal.y * (point.y - origin.y) + normal.z * (point.z - origin.z);\r\n }\r\n }\r\n\r\n public getKb3dPointerArgs(p: PointerInfoMinimal) {\r\n const args = {\r\n ...p,\r\n pickInfo: p.pickInfo,\r\n propagate: false,\r\n pointerType: (p.event as any).pointerType,\r\n button: p.event.button,\r\n ctrlKey: p.event.ctrlKey || p.event.metaKey,\r\n shiftKey: p.event.shiftKey,\r\n canvasX: p.event.offsetX,\r\n canvasY: p.event.offsetY,\r\n getNormal: () => {\r\n if (p.pickInfo) {\r\n const normal = p.pickInfo.getNormal();\r\n return normal ? KbVector.FromVec3(normal) : undefined;\r\n }\r\n return undefined;\r\n },\r\n } as IKb3dPointerArgs;\r\n\r\n if (p.pickInfo) {\r\n this.fillKb3dPickInfo(p.pickInfo, args);\r\n }\r\n return args;\r\n }\r\n\r\n protected fillKb3dPickInfo(b: PickingInfo, k: IKb3dPickInfo) {\r\n k.u = b.bu;\r\n k.v = b.bv;\r\n if (b.pickedPoint) k.pickedPoint = KbVector.FromVec3(b.pickedPoint);\r\n if (b.pickedMesh) {\r\n // recurse up the tree until we find something, or return undefined\r\n let pickedMesh: babylonNode = b.pickedMesh;\r\n k.targetNode = getByDynamicId(pickedMesh.id);\r\n while (!k.targetNode && pickedMesh.parent) {\r\n pickedMesh = pickedMesh.parent;\r\n k.targetNode = getByDynamicId(pickedMesh.id);\r\n }\r\n\r\n if (b.pickedPoint) {\r\n k.meshPoint = KbVector.FromVec3(\r\n Vector3.TransformCoordinates(b.pickedPoint, b.pickedMesh.getWorldMatrix().clone().invert())\r\n );\r\n }\r\n }\r\n }\r\n\r\n protected getKeyboardArgs(k: KeyboardInfo) {\r\n const event = k.event as unknown as KeyboardEvent;\r\n const args = {\r\n ...k,\r\n key: event.key,\r\n keyCode: event.keyCode,\r\n altKey: event.altKey,\r\n ctrlKey: event.ctrlKey || event.metaKey,\r\n shiftKey: event.shiftKey,\r\n repeat: event.repeat,\r\n } as IKeyboardArgs;\r\n\r\n return args;\r\n }\r\n\r\n /**\r\n * scans the given node and ancestors to find the first node with a click handler and returns\r\n * the node and it's handlers\r\n */\r\n protected getNextNodeHandlers(node: SpaceNode, handlerType: eHandler): INodeHandlers | undefined {\r\n //bubble up event, calling any handlers that have been applied to the nodes\r\n let handlers = new Array();\r\n while (node && node._manager) {\r\n const hmap = this.getHandlerMap(node, handlerType);\r\n handlers = hmap.getByKey(node);\r\n //if this is a scene node, then we also have to look in the parent scene manager for click events on this item\r\n if (instanceOf(node, Token.SceneNode) && node.isNested() && node._parent && node._parent._manager) {\r\n handlers.push(...this.getHandlerMap(node._parent, handlerType).getByKey(node));\r\n }\r\n\r\n if (handlers && handlers.length) {\r\n break;\r\n }\r\n\r\n node = node._parent as SpaceNode;\r\n }\r\n\r\n return node ? { node, handlers } : undefined;\r\n }\r\n\r\n protected getHandlerMap(node: Kb3dObject, type: eHandler) {\r\n const m = node._manager as Kb3dManager;\r\n if (type == eHandler.click) return m.clickHandlers;\r\n else if (type == eHandler.draggable) return m.draggables;\r\n else if (type == eHandler.doubleClick) return m.doubleClickHandlers;\r\n else throw 'unrecognized handler type';\r\n }\r\n\r\n protected getNextClickHandlers(node: SpaceNode) {\r\n return this.getNextNodeHandlers(node, eHandler.click);\r\n }\r\n\r\n protected getNextDoubleClickHandlers(node: SpaceNode) {\r\n return this.getNextNodeHandlers(node, eHandler.doubleClick);\r\n }\r\n\r\n protected getNextDraggables(node: SpaceNode) {\r\n return this.getNextNodeHandlers(node, eHandler.draggable);\r\n }\r\n}\r\n","import { MultiMaterial } from '@babylonjs/core/Materials/multiMaterial';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { SubMesh } from '@babylonjs/core/Meshes/subMesh';\r\nimport { Logger } from '@babylonjs/core/Misc/logger';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { IVertexGroup } from '@models/classes/kb3d-models';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subject } from 'rxjs';\r\nimport { takeUntil } from 'rxjs/operators';\r\nimport { MeshFaceEngine } from '../face-engine';\r\nimport { eMarqueeSelectMode } from '../interaction';\r\nimport { KbGizmo } from './gizmo';\r\n\r\nexport interface VertexChanges {\r\n mesh: AbstractMesh;\r\n delta: Vector3;\r\n vertexIndices: number[];\r\n}\r\nconst dbSubmeshes = new Map<\r\n string,\r\n {\r\n visualizationMesh: Mesh;\r\n highlightMaterial: StandardMaterial;\r\n vertices: IVertexGroup[];\r\n }\r\n>();\r\n\r\n/**\r\n * Gizmo that enables moving vertices on a mesh.\r\n */\r\nexport class KbFacetSelectGizmo extends KbGizmo {\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n public onSelectionChange = new Observable<{ selectedFacets: Array> }>();\r\n\r\n public get attachedMesh() {\r\n return this.__attachedMesh;\r\n }\r\n public set attachedMesh(mesh: Nullable) {\r\n if (mesh && !(mesh instanceof Mesh)) {\r\n throw Error('facet select gizmo must be attached to a mesh with geometry');\r\n }\r\n this.__attachedMesh = mesh;\r\n }\r\n\r\n private utilLayer: UtilityLayerRenderer;\r\n private meshFaceEngine: MeshFaceEngine;\r\n private disposeSubject: Subject;\r\n private __attachedNode: Nullable;\r\n private __attachedMesh: Nullable = null;\r\n\r\n private currentSelection = new Map();\r\n private selectionsEnabled = false;\r\n private highlightOpacity = 0.75;\r\n\r\n /**\r\n * Creates a PositionGizmo\r\n * @param camera The camera being used for the scene. Used for positioning the particles so they line up with the vertices\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n */\r\n constructor(private kbViewer: KbViewer, private scene: Scene) {\r\n super(kbViewer.utilityLayer);\r\n this.meshFaceEngine = new MeshFaceEngine(kbViewer);\r\n\r\n this.utilLayer = kbViewer.utilityLayer;\r\n\r\n this.attachedMesh = null;\r\n }\r\n\r\n attachTo(target: MeshNode) {\r\n this.__attachedNode = target;\r\n const aMesh = this.kbViewer.getRendererNode(target);\r\n if (!aMesh) {\r\n throw Error('Could not find mesh in scene to attach gizmo');\r\n }\r\n if (!(aMesh instanceof Mesh)) {\r\n throw Error('facet select gizmo must be attached to a mesh with geometry');\r\n }\r\n const mesh = aMesh;\r\n this.attachedMesh = mesh as Mesh;\r\n\r\n // Clean up old marquee\r\n if (this.disposeSubject) {\r\n this.disposeSubject.next();\r\n this.disposeSubject.complete();\r\n }\r\n\r\n this.disposeSubject = new Subject();\r\n\r\n this.kbViewer.interaction.onFacetClick.pipe(takeUntil(this.disposeSubject)).subscribe(event => {\r\n if (!this.selectionsEnabled) {\r\n return;\r\n }\r\n event.selectedFaces.sort();\r\n\r\n if (event.ctrlKey) {\r\n // Add selections\r\n for (let i = 0; i < event.selectedFaces.length; i++) {\r\n this.currentSelection.set(event.selectedFaces[i], null);\r\n }\r\n } else if (event.altKey) {\r\n // Remove selections\r\n for (let i = 0; i < event.selectedFaces.length; i++) {\r\n this.currentSelection.delete(event.selectedFaces[i]);\r\n }\r\n } else {\r\n this.currentSelection.clear();\r\n for (let i = 0; i < event.selectedFaces.length; i++) {\r\n this.currentSelection.set(event.selectedFaces[i], null);\r\n }\r\n }\r\n const result = this.getVertexGroups(this.currentSelection.keys());\r\n\r\n this.visualizeSubmesh(mesh, result, KbColor.Red());\r\n this.onSelectionChange.notifyObservers({ selectedFacets: result });\r\n });\r\n }\r\n\r\n updateGizmoPosition() {\r\n this.kbViewer.forceAndWaitForNextRender().then(() => {\r\n if (this.__attachedMesh) {\r\n const result = this.getVertexGroups(this.currentSelection.keys());\r\n this.visualizeSubmesh(this.__attachedMesh, result, KbColor.Red(), true);\r\n }\r\n });\r\n }\r\n\r\n selectFacetGroups(selection: IVertexGroup[]) {\r\n selection.forEach(vertexGroup => {\r\n if (vertexGroup.startIndex === undefined || vertexGroup.endIndex === undefined) {\r\n throw Error('corrupt vertex group');\r\n }\r\n const startFacet = Math.round(vertexGroup.startIndex / 3);\r\n const endFacet = Math.ceil(vertexGroup.endIndex / 3);\r\n\r\n for (let i = startFacet; i < endFacet; i++) {\r\n this.currentSelection.set(i, null);\r\n }\r\n });\r\n\r\n this.updateGizmoPosition();\r\n }\r\n\r\n enableSelectionChange() {\r\n this.selectionsEnabled = true;\r\n if (this.__attachedNode) {\r\n this.kbViewer.interaction\r\n .enableMarqueeSelect(this.__attachedNode, eMarqueeSelectMode.Facets)\r\n .pipe(takeUntil(this.disposeSubject))\r\n .subscribe(event => {\r\n if (\r\n this.selectionsEnabled &&\r\n this.__attachedMesh &&\r\n event.selectedFaces &&\r\n event.selectedFaces.length > 0\r\n ) {\r\n if (event.ctrlKey) {\r\n // Add selections\r\n for (let i = 0; i < event.selectedFaces.length; i++) {\r\n this.currentSelection.set(event.selectedFaces[i], null);\r\n }\r\n } else if (event.altKey) {\r\n // Remove selections\r\n for (let i = 0; i < event.selectedFaces.length; i++) {\r\n this.currentSelection.delete(event.selectedFaces[i]);\r\n }\r\n } else {\r\n this.currentSelection.clear();\r\n for (let i = 0; i < event.selectedFaces.length; i++) {\r\n this.currentSelection.set(event.selectedFaces[i], null);\r\n }\r\n }\r\n const result = this.getVertexGroups(this.currentSelection.keys());\r\n\r\n this.visualizeSubmesh(this.__attachedMesh, result, KbColor.Red());\r\n this.onSelectionChange.notifyObservers({ selectedFacets: result });\r\n }\r\n });\r\n }\r\n }\r\n\r\n disableSelectionChange() {\r\n this.selectionsEnabled = false;\r\n this.kbViewer.interaction.disableMarqueeSelect();\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n dispose() {\r\n if (this.__attachedNode) {\r\n this.kbViewer.highlighter.remove(this.__attachedNode);\r\n }\r\n if (this.__attachedMesh) {\r\n const submeshInfo = dbSubmeshes.get(this.__attachedMesh.id);\r\n submeshInfo?.visualizationMesh.setEnabled(false);\r\n }\r\n }\r\n\r\n /**\r\n * CustomMeshes are not supported by this gizmo\r\n * @param mesh The mesh to replace the default mesh of the gizmo\r\n */\r\n setCustomMesh(mesh: Mesh) {\r\n Logger.Error('Custom meshes are not supported on this gizmo.');\r\n }\r\n\r\n setBackfaceCulling(enable: boolean) {\r\n this.kbViewer.interaction.setSelectionCulling(enable);\r\n }\r\n\r\n setTolerance(tolerance: number) {\r\n this.kbViewer.interaction.setSelectionTolerance(tolerance);\r\n }\r\n\r\n expandSelection(tolerance?: number) {\r\n if (this.attachedMesh instanceof Mesh) {\r\n const currentSelection = Array.from(this.currentSelection.keys());\r\n const newSelection = this.meshFaceEngine.expandSelection(currentSelection, this.attachedMesh, tolerance);\r\n\r\n for (let i = 0; i < newSelection.length; i++) {\r\n this.currentSelection.set(newSelection[i], null);\r\n }\r\n const result = this.getVertexGroups(this.currentSelection.keys());\r\n\r\n this.visualizeSubmesh(this.attachedMesh, result, KbColor.Red());\r\n this.onSelectionChange.notifyObservers({ selectedFacets: result });\r\n }\r\n }\r\n\r\n setVisualization(opacity: number) {\r\n const submeshInfo = dbSubmeshes.get(this.attachedMesh!.id);\r\n if (submeshInfo && submeshInfo.visualizationMesh.material instanceof MultiMaterial) {\r\n submeshInfo.highlightMaterial.alpha = opacity;\r\n }\r\n this.highlightOpacity = opacity;\r\n }\r\n\r\n private getVertexGroups(faceIds: IterableIterator): Array> {\r\n const result: Array> = [];\r\n\r\n for (const faceId of faceIds) {\r\n if (result.length > 0 && result[result.length - 1].endIndex === faceId * 3) {\r\n result[result.length - 1].endIndex += 3;\r\n } else {\r\n result.push({\r\n startIndex: faceId * 3,\r\n endIndex: (faceId + 1) * 3,\r\n });\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n private visualizeSubmesh(\r\n node: Mesh,\r\n vertices: IVertexGroup[],\r\n color?: KbColor | null,\r\n geometryNeedsUpdate?: boolean\r\n ) {\r\n if (node instanceof Mesh && node.geometry) {\r\n let submeshInfo = dbSubmeshes.get(node.id);\r\n let highlightMaterial: StandardMaterial | undefined;\r\n const utilityLayerScene = this.utilLayer.utilityLayerScene;\r\n\r\n if (submeshInfo) {\r\n highlightMaterial = submeshInfo.highlightMaterial;\r\n }\r\n\r\n if (submeshInfo && geometryNeedsUpdate) {\r\n submeshInfo.visualizationMesh.dispose();\r\n submeshInfo = undefined;\r\n }\r\n\r\n if (!submeshInfo) {\r\n const multiMaterial = new MultiMaterial(`submeshVisualizationMat_${node.id}`, utilityLayerScene);\r\n\r\n const transparantMaterial = new StandardMaterial(\r\n `submeshVisualizationMat1_${node.id}`,\r\n utilityLayerScene\r\n );\r\n transparantMaterial.alpha = 0;\r\n multiMaterial.subMaterials.push(transparantMaterial);\r\n\r\n if (!highlightMaterial) {\r\n highlightMaterial = new StandardMaterial(`submeshVisualizationMat2_${node.id}`, utilityLayerScene);\r\n highlightMaterial.emissiveColor = color?.toColor3() || KbColor.KbmaxOrange().toColor3();\r\n highlightMaterial.alpha = this.highlightOpacity;\r\n }\r\n multiMaterial.subMaterials.push(highlightMaterial);\r\n\r\n submeshInfo = {\r\n visualizationMesh: new Mesh(`submeshVisualization_${node.id}`, utilityLayerScene, null, node, true),\r\n highlightMaterial,\r\n vertices,\r\n };\r\n\r\n submeshInfo.visualizationMesh.makeGeometryUnique();\r\n submeshInfo.visualizationMesh.material = multiMaterial;\r\n submeshInfo.visualizationMesh.isPickable = false;\r\n\r\n dbSubmeshes.set(node.id, submeshInfo);\r\n } else {\r\n submeshInfo.visualizationMesh.setEnabled(true);\r\n }\r\n\r\n const vMesh = submeshInfo.visualizationMesh;\r\n const totalIndices = node.geometry.getTotalIndices();\r\n const totalVertices = node.geometry.getTotalVertices();\r\n vMesh.subMeshes = [];\r\n new SubMesh(0, 0, totalVertices, 0, totalIndices, vMesh);\r\n\r\n vertices.forEach(indexGroup => {\r\n if (indexGroup.startIndex === undefined || indexGroup.endIndex === undefined) {\r\n throw Error('Missing submesh information');\r\n }\r\n new SubMesh(\r\n 1,\r\n 0,\r\n totalVertices,\r\n indexGroup.startIndex,\r\n indexGroup.endIndex - indexGroup.startIndex,\r\n vMesh\r\n );\r\n });\r\n }\r\n }\r\n}\r\n","import { Light, PointLight, SpotLight } from '@babylonjs/core/Lights';\r\nimport { Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { LightNode } from '@models/classes/lights/light-node';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { createLightVisualization } from '../../helpers/light-helper';\r\nimport { KbGizmo } from './gizmo';\r\nimport { KbPositionGizmo } from './position-gizmo';\r\nimport { KbRotationGizmo } from './rotation-gizmo';\r\n\r\n/**\r\n * Gizmo that enables dragging and rotating lights\r\n */\r\nexport class KbLightGizmo extends KbGizmo {\r\n /**\r\n * Internal gizmo used for positioning lights\r\n */\r\n posGizmo: KbPositionGizmo | undefined;\r\n /**\r\n * Internal gizmo used for rotating lights\r\n */\r\n rotGizmo: KbRotationGizmo | undefined;\r\n\r\n private _attachedLight?: LightNode;\r\n private _helperMesh: AbstractMesh | undefined;\r\n\r\n lightPositionGizmo: Mesh | undefined;\r\n\r\n attachTo(lightNode: LightNode) {\r\n const light = this.kbViewer.getRendererNode(lightNode);\r\n if (!light) {\r\n console.warn('could not find light in scene');\r\n return;\r\n }\r\n this._attachedLight = lightNode;\r\n\r\n if (this.posGizmo) {\r\n this.posGizmo.dispose();\r\n }\r\n if (this.rotGizmo) {\r\n this.rotGizmo.dispose();\r\n }\r\n const _helperMesh = (this._helperMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene));\r\n _helperMesh.rotationQuaternion = Quaternion.Identity();\r\n const lightVisual = this.updatePreviewMesh(light);\r\n _helperMesh.addChild(lightVisual);\r\n }\r\n\r\n /**\r\n * Creates a PositionGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n */\r\n constructor(\r\n private kbViewer: KbViewer,\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer\r\n ) {\r\n super(gizmoLayer);\r\n\r\n this.attachedMesh = null;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n dispose() {\r\n if (this.posGizmo) {\r\n this.posGizmo.dispose();\r\n }\r\n if (this.rotGizmo) {\r\n this.rotGizmo.dispose();\r\n }\r\n if (this._helperMesh) {\r\n this._helperMesh.dispose();\r\n }\r\n if (this.lightPositionGizmo) {\r\n this.lightPositionGizmo.dispose();\r\n }\r\n delete this._attachedLight;\r\n }\r\n\r\n updateGizmoPosition(lightNode?: LightNode) {\r\n if (!lightNode) {\r\n return;\r\n }\r\n const light = this.kbViewer.getRendererNode(lightNode);\r\n if (light) {\r\n if (!this._attachedLight || lightNode._dynamicId !== this._attachedLight._dynamicId) {\r\n this.attachTo(lightNode);\r\n } else {\r\n this.updatePreviewMesh(light);\r\n }\r\n }\r\n }\r\n\r\n protected updatePreviewMesh(light: Light) {\r\n const scene = this.gizmoLayer.utilityLayerScene;\r\n\r\n if (!this.lightPositionGizmo) {\r\n this.lightPositionGizmo = createLightVisualization(light, scene);\r\n }\r\n\r\n if (light instanceof SpotLight || light instanceof PointLight) {\r\n this.lightPositionGizmo.position = light.parent\r\n ? Vector3.TransformCoordinates(light.position, light.parent.computeWorldMatrix(true).clone().invert())\r\n : light.position;\r\n }\r\n\r\n return this.lightPositionGizmo;\r\n }\r\n}\r\n","import { PointerDragBehavior } from '@babylonjs/core/Behaviors/Meshes/pointerDragBehavior';\r\nimport { PointerInfo } from '@babylonjs/core/Events/pointerEvents';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Matrix, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { CylinderBuilder } from '@babylonjs/core/Meshes/Builders/cylinderBuilder';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Observable, Observer } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { KbGizmo } from './gizmo';\r\n\r\n/**\r\n * Single axis drag gizmo\r\n */\r\nexport class KbAxisDragGizmo extends KbGizmo {\r\n /**\r\n * Drag behavior responsible for the gizmos dragging interactions\r\n */\r\n public dragBehavior: PointerDragBehavior;\r\n private _pointerObserver: Nullable> = null;\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public snapDistance = 0;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the the change in distance\r\n */\r\n public onSnapObservable = new Observable<{ snapDistance: number }>();\r\n public updateObservable = new Observable<{ delta: Vector3 }>();\r\n\r\n /** @hidden */\r\n public static _CreateArrow(scene: Scene, material: StandardMaterial): TransformNode {\r\n const arrow = new TransformNode('arrow', scene);\r\n const cylinder = CylinderBuilder.CreateCylinder(\r\n 'cylinder',\r\n { diameterTop: 0, height: 0.075, diameterBottom: 0.0375, tessellation: 12 },\r\n scene\r\n );\r\n const line = CylinderBuilder.CreateCylinder(\r\n 'cylinder',\r\n { diameterTop: 0.01, height: 0.275, diameterBottom: 0.01, tessellation: 6 },\r\n scene\r\n );\r\n const drag = CylinderBuilder.CreateCylinder(\r\n 'cylinder',\r\n { diameterTop: 0.06, height: 0.4, diameterBottom: 0.06, tessellation: 6 },\r\n scene\r\n );\r\n line.material = material;\r\n cylinder.parent = arrow;\r\n line.parent = arrow;\r\n drag.parent = arrow;\r\n\r\n // Position arrow pointing in its drag axis\r\n cylinder.material = material;\r\n cylinder.rotation.x = Math.PI / 2;\r\n cylinder.position.z += 0.3;\r\n line.position.z += 0.275 / 2;\r\n line.rotation.x = Math.PI / 2;\r\n\r\n drag.position.z += 0.4 / 2;\r\n drag.rotation = line.rotation;\r\n drag.visibility = 0;\r\n\r\n return arrow;\r\n }\r\n\r\n /** @hidden */\r\n public static _CreateArrowInstance(scene: Scene, arrow: TransformNode): TransformNode {\r\n const instance = new TransformNode('arrow', scene);\r\n for (const mesh of arrow.getChildMeshes()) {\r\n const childInstance = (mesh as Mesh).createInstance(mesh.name);\r\n childInstance.parent = instance;\r\n }\r\n return instance;\r\n }\r\n\r\n /**\r\n * Creates an AxisDragGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param dragAxis The axis which the gizmo will be able to drag on\r\n * @param color The color of the gizmo\r\n */\r\n constructor(\r\n dragAxis: Vector3,\r\n color: Color3 = Color3.Gray(),\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer\r\n ) {\r\n super(gizmoLayer);\r\n\r\n // Create Material\r\n const coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n coloredMaterial.emissiveColor = color;\r\n // coloredMaterial.diffuseColor = color;\r\n // coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\r\n\r\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n\r\n // Build mesh on root node\r\n const arrow = KbAxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, coloredMaterial);\r\n\r\n arrow.lookAt(this._rootMesh.position.add(dragAxis));\r\n arrow.scaling.scaleInPlace(1 / 3);\r\n arrow.parent = this._rootMesh;\r\n\r\n let currentSnapDragDistance = 0;\r\n const tmpVector = new Vector3();\r\n const tmpSnapEvent = { snapDistance: 0 };\r\n // Add drag behavior to handle events when the gizmo is dragged\r\n this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });\r\n this.dragBehavior.moveAttached = false;\r\n this._rootMesh.addBehavior(this.dragBehavior);\r\n\r\n const localDelta = new Vector3();\r\n const tmpMatrix = new Matrix();\r\n this.dragBehavior.onDragObservable.add(event => {\r\n if (this.attachedMesh) {\r\n // Convert delta to local translation if it has a parent\r\n if (this.attachedMesh.parent) {\r\n this.attachedMesh.parent.computeWorldMatrix().invertToRef(tmpMatrix);\r\n tmpMatrix.setTranslationFromFloats(0, 0, 0);\r\n Vector3.TransformCoordinatesToRef(event.delta, tmpMatrix, localDelta);\r\n } else {\r\n localDelta.copyFrom(event.delta);\r\n }\r\n // Snapping logic\r\n if (this.snapDistance == 0) {\r\n this.attachedMesh.position.addInPlace(localDelta);\r\n this.updateObservable.notifyObservers({ delta: localDelta });\r\n } else {\r\n currentSnapDragDistance += event.dragDistance;\r\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\r\n const dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\r\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\r\n localDelta.normalizeToRef(tmpVector);\r\n tmpVector.scaleInPlace(this.snapDistance * dragSteps);\r\n this.attachedMesh.position.addInPlace(tmpVector);\r\n tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;\r\n this.updateObservable.notifyObservers({ delta: tmpVector });\r\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\r\n }\r\n }\r\n }\r\n });\r\n\r\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\r\n if (this._customMeshSet) {\r\n return;\r\n }\r\n const isHovered =\r\n pointerInfo.pickInfo &&\r\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\r\n const material = isHovered ? hoverMaterial : coloredMaterial;\r\n this._rootMesh.getChildMeshes().forEach(m => {\r\n m.material = material;\r\n if ((m).color) {\r\n (m).color = material.diffuseColor;\r\n }\r\n });\r\n });\r\n }\r\n protected _attachedMeshChanged(value: Nullable) {\r\n if (this.dragBehavior) {\r\n this.dragBehavior.enabled = value ? true : false;\r\n }\r\n }\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.onSnapObservable.clear();\r\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\r\n this.dragBehavior.detach();\r\n super.dispose();\r\n }\r\n}\r\n","import { Color3, Matrix, Quaternion, Space, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Logger } from '@babylonjs/core/Misc/logger';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { KbAxisDragGizmo } from './axis-drag-gizmo';\r\nimport { AUTO_MESH_NAME, KbGizmo } from './gizmo';\r\n\r\n/**\r\n * Gizmo that enables dragging a mesh along 3 axis\r\n */\r\nexport class KbPositionGizmo extends KbGizmo {\r\n /**\r\n * Internal gizmo used for interactions on the x axis\r\n */\r\n public xGizmo: KbAxisDragGizmo;\r\n /**\r\n * Internal gizmo used for interactions on the y axis\r\n */\r\n public yGizmo: KbAxisDragGizmo;\r\n /**\r\n * Internal gizmo used for interactions on the z axis\r\n */\r\n public zGizmo: KbAxisDragGizmo;\r\n\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n public onDragStartObservable = new Observable();\r\n /** Fires an event while any of it's sub gizmos are dragged */\r\n public onDragObservable = new Observable<{ delta: Vector3 }>();\r\n /** Fires an event when any of it's sub gizmos are released from dragging */\r\n public onDragEndObservable = new Observable<{ delta: Vector3 }>();\r\n\r\n private _attachedSpaceNode: SpaceNode | undefined;\r\n private _positionSpace: TransformNode | undefined;\r\n\r\n attachTo(target: SpaceNode | KbVector, positionSpace?: SpaceNode, orientGizmo?: Quaternion) {\r\n if (orientGizmo) {\r\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = false;\r\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = false;\r\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = false;\r\n this.xGizmo._rootMesh.rotationQuaternion = orientGizmo;\r\n this.yGizmo._rootMesh.rotationQuaternion = orientGizmo;\r\n this.zGizmo._rootMesh.rotationQuaternion = orientGizmo;\r\n }\r\n if (!positionSpace && target instanceof SpaceNode && target._parent) {\r\n positionSpace = target._parent;\r\n }\r\n if (positionSpace) {\r\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\r\n }\r\n if (target instanceof SpaceNode) {\r\n this._attachedSpaceNode = target;\r\n this._updateGizmoPosition();\r\n } else {\r\n this._updateGizmoPosition(target);\r\n }\r\n }\r\n\r\n updateGizmoPosition(changeTarget?: KbVector) {\r\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\r\n this.kbViewer.onNextFrame(() => {\r\n this._updateGizmoPosition(changeTarget);\r\n });\r\n }\r\n\r\n private _updateGizmoPosition(changeTarget?: KbVector) {\r\n const positionSpaceTransform = this._positionSpace?.computeWorldMatrix(true);\r\n if (changeTarget) {\r\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, changeTarget, positionSpaceTransform);\r\n } else if (this._attachedSpaceNode) {\r\n this.attachMeshAtNodeSpace(\r\n this.gizmoLayer.utilityLayerScene,\r\n this._attachedSpaceNode,\r\n positionSpaceTransform\r\n );\r\n }\r\n super.updateGizmoPosition();\r\n }\r\n\r\n public get attachedMesh() {\r\n if (this.xGizmo) {\r\n return this.xGizmo.attachedMesh;\r\n } else if (this.yGizmo) {\r\n return this.yGizmo.attachedMesh;\r\n } else {\r\n return this.zGizmo.attachedMesh;\r\n }\r\n }\r\n\r\n public set attachedMesh(mesh: Nullable) {\r\n if (this.xGizmo) {\r\n this.xGizmo.attachedMesh = mesh;\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.attachedMesh = mesh;\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.attachedMesh = mesh;\r\n }\r\n if (mesh) {\r\n this._rootMesh.rotationQuaternion = mesh.rotationQuaternion\r\n ? mesh.rotationQuaternion\r\n : mesh.rotation.toQuaternion();\r\n this._rootMesh.position = mesh.position;\r\n this._rootMesh.setPivotPoint(mesh.getPivotPoint(), Space.WORLD);\r\n }\r\n }\r\n\r\n get visibility() {\r\n return this.xGizmo.visibility;\r\n }\r\n set visibility(visibility: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.visibility = visibility;\r\n this.yGizmo.visibility = visibility;\r\n this.zGizmo.visibility = visibility;\r\n }\r\n }\r\n\r\n private positionChange = Vector3.Zero();\r\n\r\n /**\r\n * Creates a PositionGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n */\r\n constructor(\r\n private kbViewer: KbViewer,\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n axisVisibility?: [boolean, boolean, boolean]\r\n ) {\r\n super(gizmoLayer);\r\n let activeGizmos = [];\r\n if (axisVisibility) {\r\n if (axisVisibility[0]) {\r\n this.xGizmo = new KbAxisDragGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);\r\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[0];\r\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[0];\r\n activeGizmos.push(this.xGizmo);\r\n }\r\n if (axisVisibility[1]) {\r\n this.yGizmo = new KbAxisDragGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);\r\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[1];\r\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[1];\r\n activeGizmos.push(this.yGizmo);\r\n }\r\n if (axisVisibility[2]) {\r\n this.zGizmo = new KbAxisDragGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);\r\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[2];\r\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[2];\r\n activeGizmos.push(this.zGizmo);\r\n }\r\n } else {\r\n this.xGizmo = new KbAxisDragGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);\r\n this.yGizmo = new KbAxisDragGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);\r\n this.zGizmo = new KbAxisDragGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);\r\n\r\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n activeGizmos = [this.xGizmo, this.yGizmo, this.zGizmo];\r\n }\r\n\r\n // Relay drag events\r\n activeGizmos.forEach(gizmo => {\r\n gizmo.dragBehavior.onDragStartObservable.add(() => {\r\n this.onDragStartObservable.notifyObservers();\r\n this.positionChange.setAll(0);\r\n });\r\n gizmo.updateObservable.add(event => {\r\n // transform the rotation to be in local space, the gizmos return global space movements\r\n const transform = new Matrix();\r\n this.attachedMesh!.computeWorldMatrix(true).invertToRef(transform);\r\n transform.setTranslation(Vector3.Zero());\r\n const { delta } = event;\r\n const result = Vector3.TransformCoordinates(delta, transform);\r\n\r\n // squish floating point errors that look gross in the output\r\n if (Math.abs(result.x) < 0.00000001) result.x = 0;\r\n if (Math.abs(result.y) < 0.00000001) result.y = 0;\r\n if (Math.abs(result.z) < 0.00000001) result.z = 0;\r\n\r\n this.positionChange.addInPlace(result);\r\n this.onDragObservable.notifyObservers({ delta: result });\r\n });\r\n gizmo.dragBehavior.onDragEndObservable.add(() => {\r\n this.onDragEndObservable.notifyObservers({ delta: this.positionChange });\r\n });\r\n });\r\n this.attachedMesh = null;\r\n }\r\n\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public set snapDistance(value: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.snapDistance = value;\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.snapDistance = value;\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.snapDistance = value;\r\n }\r\n }\r\n public get snapDistance() {\r\n if (this.xGizmo) {\r\n return this.xGizmo.snapDistance;\r\n } else if (this.yGizmo) {\r\n return this.yGizmo.snapDistance;\r\n } else {\r\n return this.zGizmo.snapDistance;\r\n }\r\n }\r\n\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n public set scaleRatio(value: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.scaleRatio = value;\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.scaleRatio = value;\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.scaleRatio = value;\r\n }\r\n }\r\n public get scaleRatio() {\r\n if (this.xGizmo) {\r\n return this.xGizmo.scaleRatio;\r\n } else if (this.yGizmo) {\r\n return this.yGizmo.scaleRatio;\r\n } else {\r\n return this.zGizmo.scaleRatio;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n if (this.xGizmo) {\r\n this.xGizmo.dispose();\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.dispose();\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.dispose();\r\n }\r\n this.onDragStartObservable.clear();\r\n this.onDragEndObservable.clear();\r\n if (this.attachedMesh && this.attachedMesh.name === AUTO_MESH_NAME) {\r\n this.attachedMesh.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * CustomMeshes are not supported by this gizmo\r\n * @param mesh The mesh to replace the default mesh of the gizmo\r\n */\r\n public setCustomMesh(mesh: Mesh) {\r\n Logger.Error(\r\n 'Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.yGizmo, gizmo.zGizmo)'\r\n );\r\n }\r\n}\r\n","import { Color3, Quaternion, Space, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Logger } from '@babylonjs/core/Misc/logger';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { rotationToVector } from '@view/helpers/math-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { KbGizmo } from './gizmo';\r\nimport { KbPlaneRotationGizmo } from './plane-rotation-gizmo';\r\n\r\nconst tessellation = 32;\r\n\r\n/**\r\n * Gizmo that enables rotating a mesh along 3 axis\r\n */\r\nexport class KbRotationGizmo extends KbGizmo {\r\n /**\r\n * Internal gizmo used for interactions on the x axis\r\n */\r\n public xGizmo: KbPlaneRotationGizmo | undefined;\r\n /**\r\n * Internal gizmo used for interactions on the y axis\r\n */\r\n public yGizmo: KbPlaneRotationGizmo | undefined;\r\n /**\r\n * Internal gizmo used for interactions on the z axis\r\n */\r\n public zGizmo: KbPlaneRotationGizmo | undefined;\r\n\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n public onDragStartObservable = new Observable();\r\n /** Fires an event when any of it's sub gizmos are released from dragging */\r\n public onDragObservable = new Observable<{ delta: Quaternion }>();\r\n public onDragEndObservable = new Observable<{ delta: Quaternion }>();\r\n\r\n public gizmoOffset: KbVector | undefined;\r\n private _attachedSpaceNode: SpaceNode | undefined;\r\n private _positionSpace: TransformNode | undefined;\r\n\r\n attachTo(target: SpaceNode | KbVector, positionSpace?: SpaceNode, placementOffset?: KbVector) {\r\n if (!positionSpace && target instanceof SpaceNode && target._parent) {\r\n positionSpace = target._parent;\r\n }\r\n if (positionSpace) {\r\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\r\n }\r\n\r\n if (target instanceof SpaceNode) {\r\n this._attachedSpaceNode = target;\r\n this._updateGizmoPosition();\r\n } else {\r\n this._updateGizmoPosition(target, placementOffset);\r\n }\r\n }\r\n updateGizmoPosition(changeTarget?: KbVector, placementOffset?: KbVector) {\r\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\r\n this.kbViewer.onNextFrame(() => {\r\n this._updateGizmoPosition(changeTarget, placementOffset);\r\n });\r\n }\r\n\r\n private _updateGizmoPosition(changeTarget?: KbVector, placementOffset?: KbVector) {\r\n const positionSpaceTransform = this._positionSpace?.computeWorldMatrix(true);\r\n if (changeTarget) {\r\n // If target is a vector, then we want to rotate it as a direction, so set the gizmo position to the origin to calculations are done from there\r\n // But store the position as the offset because we want the gizmo itself to be visually placed on the position space origin\r\n this.attachMeshAtNodeSpace(\r\n this.gizmoLayer.utilityLayerScene,\r\n placementOffset || KbVector.Zero(),\r\n positionSpaceTransform\r\n );\r\n\r\n const corr = rotationToVector(changeTarget.toVec3(), Vector3.Up());\r\n this.gizmoOffset = KbVector.FromVec3(this.attachedMesh!.position);\r\n this.attachedMesh!.position = Vector3.Zero();\r\n this.attachedMesh!.rotationQuaternion?.multiplyInPlace(corr);\r\n this.attachedMesh!.computeWorldMatrix(true);\r\n } else if (this._attachedSpaceNode) {\r\n this.attachMeshAtNodeSpace(\r\n this.gizmoLayer.utilityLayerScene,\r\n this._attachedSpaceNode.position.add(this._attachedSpaceNode.pivot),\r\n positionSpaceTransform\r\n );\r\n\r\n let currentRotation: Quaternion;\r\n // Rotation gizmo should be rotated to match the current rotation if the target is a node\r\n if (this._attachedSpaceNode.useEuler) {\r\n currentRotation = this._attachedSpaceNode.eulerRotation\r\n .toVec3()\r\n .scale(Math.PI / 180)\r\n .toQuaternion();\r\n } else {\r\n currentRotation = rotationToVector(this._attachedSpaceNode.rotationAxis.toVec3());\r\n }\r\n this.attachedMesh!.rotationQuaternion = (\r\n positionSpaceTransform\r\n ? Quaternion.FromRotationMatrix(positionSpaceTransform.getRotationMatrix())\r\n : Quaternion.Identity()\r\n ).multiply(currentRotation);\r\n }\r\n this.gizmoOffset && this.attachedMesh!.position.addInPlace(this.gizmoOffset.toVec3());\r\n super.updateGizmoPosition();\r\n }\r\n\r\n public get attachedMesh() {\r\n return (this.xGizmo || this.yGizmo || this.zGizmo)!.attachedMesh;\r\n }\r\n public set attachedMesh(mesh: Nullable) {\r\n if (this.xGizmo) {\r\n this.xGizmo.attachedMesh = mesh;\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.attachedMesh = mesh;\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.attachedMesh = mesh;\r\n }\r\n if (mesh) {\r\n this._rootMesh.setPivotPoint(mesh.getPivotPoint(), Space.WORLD);\r\n }\r\n }\r\n\r\n private rotationChange: Quaternion;\r\n /**\r\n * Creates a RotationGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param tessellation Amount of tessellation to be used when creating rotation circles\r\n */\r\n constructor(\r\n private kbViewer: KbViewer,\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n axes?: Record<'x' | 'y' | 'z', boolean>,\r\n axisVisibility?: [boolean, boolean, boolean]\r\n ) {\r\n super(gizmoLayer);\r\n let activeGizmos = [];\r\n if (axisVisibility) {\r\n if (axisVisibility[0]) {\r\n this.xGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(1, 0, 0),\r\n Color3.Red().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[0];\r\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[0];\r\n activeGizmos.push(this.xGizmo);\r\n }\r\n if (axisVisibility[1]) {\r\n this.yGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(0, 1, 0),\r\n Color3.Green().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[1];\r\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[1];\r\n activeGizmos.push(this.yGizmo);\r\n }\r\n if (axisVisibility[2]) {\r\n this.zGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(0, 0, 1),\r\n Color3.Blue().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = axisVisibility[2];\r\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = axisVisibility[2];\r\n activeGizmos.push(this.zGizmo);\r\n }\r\n } else {\r\n this.updateGizmoRotationToMatchAttachedMesh = true;\r\n if (!axes || axes.x) {\r\n this.xGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(1, 0, 0),\r\n Color3.Red().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.xGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n }\r\n if (!axes || axes.y) {\r\n this.yGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(0, 1, 0),\r\n Color3.Green().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.yGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n }\r\n if (!axes || axes.z) {\r\n this.zGizmo = new KbPlaneRotationGizmo(\r\n new Vector3(0, 0, 1),\r\n Color3.Blue().scale(0.5),\r\n gizmoLayer,\r\n tessellation\r\n );\r\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = true;\r\n this.zGizmo.updateGizmoPositionToMatchAttachedMesh = true;\r\n }\r\n activeGizmos = [this.xGizmo, this.yGizmo, this.zGizmo];\r\n }\r\n\r\n this.rotationChange = Quaternion.Identity();\r\n\r\n // Relay drag events\r\n activeGizmos.forEach(gizmo => {\r\n if (gizmo) {\r\n gizmo.dragBehavior.onDragStartObservable.add(() => {\r\n this.onDragStartObservable.notifyObservers();\r\n this.rotationChange = Quaternion.Identity();\r\n });\r\n gizmo.updateObservable.add(event => {\r\n this.rotationChange.multiplyInPlace(event.delta);\r\n this.onDragObservable.notifyObservers({ delta: event.delta });\r\n });\r\n gizmo.dragBehavior.onDragEndObservable.add(() => {\r\n this.onDragEndObservable.notifyObservers({ delta: this.rotationChange });\r\n });\r\n }\r\n });\r\n\r\n this.attachedMesh = null;\r\n }\r\n\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public set snapDistance(value: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.snapDistance = value;\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.snapDistance = value;\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.snapDistance = value;\r\n }\r\n }\r\n public get snapDistance() {\r\n return (this.xGizmo || this.yGizmo || this.zGizmo)!.snapDistance;\r\n }\r\n\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n public set scaleRatio(value: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.scaleRatio = value;\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.scaleRatio = value;\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.scaleRatio = value;\r\n }\r\n }\r\n public get scaleRatio() {\r\n return (this.xGizmo || this.yGizmo || this.zGizmo)!.scaleRatio;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n if (this.xGizmo) {\r\n this.xGizmo.dispose();\r\n }\r\n if (this.yGizmo) {\r\n this.yGizmo.dispose();\r\n }\r\n if (this.zGizmo) {\r\n this.zGizmo.dispose();\r\n }\r\n this.onDragStartObservable.clear();\r\n this.onDragEndObservable.clear();\r\n }\r\n\r\n /**\r\n * CustomMeshes are not supported by this gizmo\r\n * @param mesh The mesh to replace the default mesh of the gizmo\r\n */\r\n public setCustomMesh(mesh: Mesh) {\r\n Logger.Error(\r\n 'Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.yGizmo, gizmo.zGizmo)'\r\n );\r\n }\r\n}\r\n","import { PointerDragBehavior } from '@babylonjs/core/Behaviors/Meshes/pointerDragBehavior';\r\nimport { PointerInfo } from '@babylonjs/core/Events/pointerEvents';\r\nimport { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';\r\nimport { Color3, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { BoxBuilder } from '@babylonjs/core/Meshes/Builders/boxBuilder';\r\nimport { CylinderBuilder } from '@babylonjs/core/Meshes/Builders/cylinderBuilder';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Observable, Observer } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { KbGizmo } from './gizmo';\r\n\r\n/**\r\n * Single axis scale gizmo\r\n */\r\nexport class KbAxisScaleGizmo extends KbGizmo {\r\n private _coloredMaterial: StandardMaterial;\r\n /**\r\n * Drag behavior responsible for the gizmos dragging interactions\r\n */\r\n public dragBehavior: PointerDragBehavior;\r\n private _pointerObserver: Nullable> = null;\r\n /**\r\n * Scale distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public snapDistance = 0;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the the change in distance\r\n */\r\n public onSnapObservable = new Observable<{ snapDistance: number }>();\r\n public updateObservable = new Observable<{ delta: Vector3 }>();\r\n /**\r\n * If the scaling operation should be done on all axis (default: false)\r\n */\r\n public uniformScaling = false;\r\n /**\r\n * Creates an AxisScaleGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param dragAxis The axis which the gizmo will be able to scale on\r\n * @param color The color of the gizmo\r\n */\r\n constructor(\r\n dragAxis: Vector3,\r\n color: Color3 = Color3.Gray(),\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer\r\n ) {\r\n super(gizmoLayer);\r\n\r\n // Create Material\r\n this._coloredMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n this._coloredMaterial.disableLighting = true;\r\n this._coloredMaterial.emissiveColor = color;\r\n // this._coloredMaterial.diffuseColor = color;\r\n // this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\r\n\r\n const hoverMaterial = new StandardMaterial('', gizmoLayer.utilityLayerScene);\r\n hoverMaterial.disableLighting = true;\r\n hoverMaterial.emissiveColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n // hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));\r\n\r\n // Build mesh on root node\r\n const arrow = new AbstractMesh('', gizmoLayer.utilityLayerScene);\r\n const arrowMesh = BoxBuilder.CreateBox('yPosMesh', { size: 0.4 }, gizmoLayer.utilityLayerScene);\r\n const arrowTail = CylinderBuilder.CreateCylinder(\r\n 'cylinder',\r\n { diameterTop: 0.005, height: 0.275, diameterBottom: 0.005, tessellation: 96 },\r\n gizmoLayer.utilityLayerScene\r\n );\r\n arrowTail.material = this._coloredMaterial;\r\n arrow.addChild(arrowMesh);\r\n arrow.addChild(arrowTail);\r\n\r\n // Position arrow pointing in its drag axis\r\n arrowMesh.scaling.scaleInPlace(0.1);\r\n arrowMesh.material = this._coloredMaterial;\r\n arrowMesh.rotation.x = Math.PI / 2;\r\n arrowMesh.position.z += 0.3;\r\n arrowTail.position.z += 0.275 / 2;\r\n arrowTail.rotation.x = Math.PI / 2;\r\n arrow.lookAt(this._rootMesh.position.add(dragAxis));\r\n this._rootMesh.addChild(arrow);\r\n arrow.scaling.scaleInPlace(1 / 3);\r\n\r\n // Add drag behavior to handle events when the gizmo is dragged\r\n this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });\r\n this.dragBehavior.moveAttached = false;\r\n this._rootMesh.addBehavior(this.dragBehavior);\r\n\r\n let currentSnapDragDistance = 0;\r\n const tmpVector = new Vector3();\r\n const tmpSnapEvent = { snapDistance: 0 };\r\n this.dragBehavior.onDragObservable.add(event => {\r\n if (this.attachedMesh) {\r\n // Drag strength is modified by the scale of the gizmo (eg. for small objects like boombox the strength will be increased to match the behavior of larger objects)\r\n const dragStrength = event.dragDistance * ((this.scaleRatio * 8) / this._rootMesh.scaling.length());\r\n\r\n // Snapping logic\r\n let snapped = false;\r\n let dragSteps = 0;\r\n if (this.uniformScaling) {\r\n this.attachedMesh.scaling.normalizeToRef(tmpVector);\r\n if (tmpVector.y < 0) {\r\n tmpVector.scaleInPlace(-1);\r\n }\r\n } else {\r\n tmpVector.copyFrom(dragAxis);\r\n }\r\n if (this.snapDistance == 0) {\r\n tmpVector.scaleToRef(dragStrength, tmpVector);\r\n } else {\r\n currentSnapDragDistance += dragStrength;\r\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\r\n dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\r\n if (currentSnapDragDistance < 0) {\r\n dragSteps *= -1;\r\n }\r\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\r\n tmpVector.scaleToRef(this.snapDistance * dragSteps, tmpVector);\r\n snapped = true;\r\n } else {\r\n tmpVector.scaleInPlace(0);\r\n }\r\n }\r\n\r\n this.attachedMesh.scaling.addInPlace(tmpVector);\r\n this.updateObservable.notifyObservers({ delta: tmpVector });\r\n\r\n if (snapped) {\r\n tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;\r\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\r\n }\r\n }\r\n });\r\n\r\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add(pointerInfo => {\r\n if (this._customMeshSet) {\r\n return;\r\n }\r\n const isHovered =\r\n pointerInfo.pickInfo &&\r\n this._rootMesh.getChildMeshes().indexOf(pointerInfo.pickInfo.pickedMesh) != -1;\r\n const material = isHovered ? hoverMaterial : this._coloredMaterial;\r\n this._rootMesh.getChildMeshes().forEach(m => {\r\n m.material = material;\r\n if ((m).color) {\r\n (m).color = material.diffuseColor;\r\n }\r\n });\r\n });\r\n\r\n // var light = gizmoLayer._getSharedGizmoLight();\r\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes());\r\n }\r\n\r\n protected _attachedMeshChanged(value: Nullable) {\r\n if (this.dragBehavior) {\r\n this.dragBehavior.enabled = value ? true : false;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.onSnapObservable.clear();\r\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\r\n this.dragBehavior.detach();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Disposes and replaces the current meshes in the gizmo with the specified mesh\r\n * @param mesh The mesh to replace the default mesh of the gizmo\r\n * @param useGizmoMaterial If the gizmo's default material should be used (default: false)\r\n */\r\n public setCustomMesh(mesh: Mesh, useGizmoMaterial = false) {\r\n super.setCustomMesh(mesh);\r\n if (useGizmoMaterial) {\r\n this._rootMesh.getChildMeshes().forEach(m => {\r\n m.material = this._coloredMaterial;\r\n if ((m).color) {\r\n (m).color = this._coloredMaterial.diffuseColor;\r\n }\r\n });\r\n this._customMeshSet = false;\r\n }\r\n }\r\n}\r\n","import { Color3, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { PolyhedronBuilder } from '@babylonjs/core/Meshes/Builders/polyhedronBuilder';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { Logger } from '@babylonjs/core/Misc/logger';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Nullable } from '@babylonjs/core/types';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { KbAxisScaleGizmo } from './axis-scale-gizmo';\r\nimport { KbGizmo } from './gizmo';\r\n/**\r\n * Gizmo that enables scaling a mesh along 3 axis\r\n */\r\nexport class KbScaleGizmo extends KbGizmo {\r\n /**\r\n * Internal gizmo used for interactions on the x axis\r\n */\r\n public xGizmo: KbAxisScaleGizmo;\r\n /**\r\n * Internal gizmo used for interactions on the y axis\r\n */\r\n public yGizmo: KbAxisScaleGizmo;\r\n /**\r\n * Internal gizmo used for interactions on the z axis\r\n */\r\n public zGizmo: KbAxisScaleGizmo;\r\n\r\n /**\r\n * Internal gizmo used to scale all axis equally\r\n */\r\n public uniformScaleGizmo: KbAxisScaleGizmo;\r\n\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n public onDragStartObservable = new Observable();\r\n /** Fires an event while any of it's sub gizmos are dragged */\r\n public onDragObservable = new Observable<{ delta: Vector3 }>();\r\n /** Fires an event when any of it's sub gizmos are released from dragging */\r\n public onDragEndObservable = new Observable<{ delta: Vector3 }>();\r\n\r\n private _attachedSpaceNode: SpaceNode | undefined;\r\n private _positionSpace: TransformNode | undefined;\r\n\r\n public gizmoOffset: KbVector | undefined;\r\n\r\n attachTo(target: SpaceNode | KbVector, positionSpace?: SpaceNode) {\r\n if (!positionSpace && target instanceof SpaceNode && target._parent) {\r\n positionSpace = target._parent;\r\n }\r\n if (positionSpace) {\r\n this._positionSpace = this.kbViewer.getRendererNode(positionSpace);\r\n }\r\n if (target instanceof SpaceNode) {\r\n this._attachedSpaceNode = target;\r\n this._updateGizmoPosition();\r\n } else {\r\n this._updateGizmoPosition(target);\r\n }\r\n }\r\n updateGizmoPosition(changeTarget?: KbVector) {\r\n // Need to wait for the next frame because this can be called before the babylon object is actually updated\r\n this.kbViewer.onNextFrame(() => {\r\n this._updateGizmoPosition(changeTarget);\r\n });\r\n }\r\n\r\n private _updateGizmoPosition(changeTarget?: KbVector) {\r\n const positionSpaceTransform = this._positionSpace?.computeWorldMatrix(true);\r\n if (changeTarget) {\r\n // If target is a vector, then we want to rotate it as a direction, so set the gizmo position to the origin to calculations are done from there\r\n // But store the position as the offset because we want the gizmo itself to be visually placed on the position space origin\r\n this.attachMeshAtNodeSpace(this.gizmoLayer.utilityLayerScene, changeTarget, positionSpaceTransform);\r\n\r\n this.gizmoOffset = KbVector.FromVec3(this.attachedMesh!.position);\r\n } else if (this._attachedSpaceNode) {\r\n this.attachMeshAtNodeSpace(\r\n this.gizmoLayer.utilityLayerScene,\r\n this._attachedSpaceNode,\r\n positionSpaceTransform\r\n );\r\n\r\n // Put the gizmo in the same position as the pivot, in world space\r\n this.attachedMesh!.position.addInPlace(this._attachedSpaceNode.pivot.toVec3());\r\n }\r\n super.updateGizmoPosition();\r\n }\r\n\r\n public get attachedMesh() {\r\n return this.xGizmo.attachedMesh;\r\n }\r\n public set attachedMesh(mesh: Nullable) {\r\n if (this.xGizmo) {\r\n this.xGizmo.attachedMesh = mesh;\r\n this.yGizmo.attachedMesh = mesh;\r\n this.zGizmo.attachedMesh = mesh;\r\n this.uniformScaleGizmo.attachedMesh = mesh;\r\n }\r\n }\r\n\r\n private scaleChange = Vector3.Zero();\r\n\r\n /**\r\n * Creates a ScaleGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n */\r\n constructor(\r\n private kbViewer: KbViewer,\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer\r\n ) {\r\n super(gizmoLayer);\r\n this.xGizmo = new KbAxisScaleGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);\r\n this.yGizmo = new KbAxisScaleGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);\r\n this.zGizmo = new KbAxisScaleGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);\r\n\r\n // Create uniform scale gizmo\r\n this.uniformScaleGizmo = new KbAxisScaleGizmo(new Vector3(0, 1, 0), Color3.Yellow().scale(0.5), gizmoLayer);\r\n this.uniformScaleGizmo.updateGizmoRotationToMatchAttachedMesh = false;\r\n this.uniformScaleGizmo.uniformScaling = true;\r\n const uniformScalingMesh = PolyhedronBuilder.CreatePolyhedron(\r\n '',\r\n { type: 1 },\r\n this.uniformScaleGizmo.gizmoLayer.utilityLayerScene\r\n );\r\n uniformScalingMesh.scaling.scaleInPlace(0.03);\r\n uniformScalingMesh.visibility = 0;\r\n const octahedron = PolyhedronBuilder.CreatePolyhedron(\r\n '',\r\n { type: 1 },\r\n this.uniformScaleGizmo.gizmoLayer.utilityLayerScene\r\n );\r\n octahedron.scaling.scaleInPlace(0.007);\r\n uniformScalingMesh.addChild(octahedron);\r\n this.uniformScaleGizmo.setCustomMesh(uniformScalingMesh, true);\r\n // var light = gizmoLayer._getSharedGizmoLight();\r\n // light.includedOnlyMeshes = light.includedOnlyMeshes.concat(octahedron);\r\n\r\n // Relay drag events\r\n [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach(gizmo => {\r\n gizmo.dragBehavior.onDragStartObservable.add(() => {\r\n this.onDragStartObservable.notifyObservers();\r\n this.scaleChange.setAll(0);\r\n });\r\n gizmo.updateObservable.add(event => {\r\n this.scaleChange.addInPlace(event.delta);\r\n this.onDragObservable.notifyObservers({ delta: event.delta });\r\n });\r\n gizmo.dragBehavior.onDragEndObservable.add(() => {\r\n this.onDragEndObservable.notifyObservers({ delta: this.scaleChange });\r\n });\r\n });\r\n\r\n this.attachedMesh = null;\r\n }\r\n\r\n public set updateGizmoRotationToMatchAttachedMesh(value: boolean) {\r\n if (!value) {\r\n Logger.Warn('Setting updateGizmoRotationToMatchAttachedMesh = false on scaling gizmo is not supported.');\r\n }\r\n if (this.xGizmo) {\r\n this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;\r\n this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;\r\n this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;\r\n }\r\n }\r\n public get updateGizmoRotationToMatchAttachedMesh() {\r\n return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;\r\n }\r\n\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public set snapDistance(value: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.snapDistance = value;\r\n this.yGizmo.snapDistance = value;\r\n this.zGizmo.snapDistance = value;\r\n this.uniformScaleGizmo.snapDistance = value;\r\n }\r\n }\r\n public get snapDistance() {\r\n return this.xGizmo.snapDistance;\r\n }\r\n\r\n /**\r\n * Ratio for the scale of the gizmo (Default: 1)\r\n */\r\n public set scaleRatio(value: number) {\r\n if (this.xGizmo) {\r\n this.xGizmo.scaleRatio = value;\r\n this.yGizmo.scaleRatio = value;\r\n this.zGizmo.scaleRatio = value;\r\n this.uniformScaleGizmo.scaleRatio = value;\r\n }\r\n }\r\n public get scaleRatio() {\r\n return this.xGizmo.scaleRatio;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.xGizmo.dispose();\r\n this.yGizmo.dispose();\r\n this.zGizmo.dispose();\r\n this.uniformScaleGizmo.dispose();\r\n this.onDragStartObservable.clear();\r\n this.onDragEndObservable.clear();\r\n }\r\n}\r\n","import type { Color3 } from \"../Maths/math.color\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\n\r\n/** Interface used by value gradients (color, factor, ...) */\r\nexport interface IValueGradient {\r\n /**\r\n * Gets or sets the gradient value (between 0 and 1)\r\n */\r\n gradient: number;\r\n}\r\n\r\n/** Class used to store color4 gradient */\r\nexport class ColorGradient implements IValueGradient {\r\n /**\r\n * Creates a new color4 gradient\r\n * @param gradient gets or sets the gradient value (between 0 and 1)\r\n * @param color1 gets or sets first associated color\r\n * @param color2 gets or sets first second color\r\n */\r\n public constructor(\r\n /**\r\n * Gets or sets the gradient value (between 0 and 1)\r\n */\r\n public gradient: number,\r\n /**\r\n * Gets or sets first associated color\r\n */\r\n public color1: Color4,\r\n /**\r\n * Gets or sets second associated color\r\n */\r\n public color2?: Color4\r\n ) {}\r\n\r\n /**\r\n * Will get a color picked randomly between color1 and color2.\r\n * If color2 is undefined then color1 will be used\r\n * @param result defines the target Color4 to store the result in\r\n */\r\n public getColorToRef(result: Color4) {\r\n if (!this.color2) {\r\n result.copyFrom(this.color1);\r\n return;\r\n }\r\n\r\n Color4.LerpToRef(this.color1, this.color2, Math.random(), result);\r\n }\r\n}\r\n\r\n/** Class used to store color 3 gradient */\r\nexport class Color3Gradient implements IValueGradient {\r\n /**\r\n * Creates a new color3 gradient\r\n * @param gradient gets or sets the gradient value (between 0 and 1)\r\n * @param color gets or sets associated color\r\n */\r\n public constructor(\r\n /**\r\n * Gets or sets the gradient value (between 0 and 1)\r\n */\r\n public gradient: number,\r\n /**\r\n * Gets or sets the associated color\r\n */\r\n public color: Color3\r\n ) {}\r\n}\r\n\r\n/** Class used to store factor gradient */\r\nexport class FactorGradient implements IValueGradient {\r\n /**\r\n * Creates a new factor gradient\r\n * @param gradient gets or sets the gradient value (between 0 and 1)\r\n * @param factor1 gets or sets first associated factor\r\n * @param factor2 gets or sets second associated factor\r\n */\r\n public constructor(\r\n /**\r\n * Gets or sets the gradient value (between 0 and 1)\r\n */\r\n public gradient: number,\r\n /**\r\n * Gets or sets first associated factor\r\n */\r\n public factor1: number,\r\n /**\r\n * Gets or sets second associated factor\r\n */\r\n public factor2?: number\r\n ) {}\r\n\r\n /**\r\n * Will get a number picked randomly between factor1 and factor2.\r\n * If factor2 is undefined then factor1 will be used\r\n * @returns the picked number\r\n */\r\n public getFactor(): number {\r\n if (this.factor2 === undefined || this.factor2 === this.factor1) {\r\n return this.factor1;\r\n }\r\n\r\n return this.factor1 + (this.factor2 - this.factor1) * Math.random();\r\n }\r\n}\r\n\r\n/**\r\n * Helper used to simplify some generic gradient tasks\r\n */\r\nexport class GradientHelper {\r\n /**\r\n * Gets the current gradient from an array of IValueGradient\r\n * @param ratio defines the current ratio to get\r\n * @param gradients defines the array of IValueGradient\r\n * @param updateFunc defines the callback function used to get the final value from the selected gradients\r\n */\r\n public static GetCurrentGradient(ratio: number, gradients: IValueGradient[], updateFunc: (current: IValueGradient, next: IValueGradient, scale: number) => void) {\r\n // Use last index if over\r\n if (gradients[0].gradient > ratio) {\r\n updateFunc(gradients[0], gradients[0], 1.0);\r\n return;\r\n }\r\n\r\n for (let gradientIndex = 0; gradientIndex < gradients.length - 1; gradientIndex++) {\r\n const currentGradient = gradients[gradientIndex];\r\n const nextGradient = gradients[gradientIndex + 1];\r\n\r\n if (ratio >= currentGradient.gradient && ratio <= nextGradient.gradient) {\r\n const scale = (ratio - currentGradient.gradient) / (nextGradient.gradient - currentGradient.gradient);\r\n updateFunc(currentGradient, nextGradient, scale);\r\n return;\r\n }\r\n }\r\n\r\n // Use last index if over\r\n const lastIndex = gradients.length - 1;\r\n updateFunc(gradients[lastIndex], gradients[lastIndex], 1.0);\r\n }\r\n}\r\n","import type { Nullable } from \"../types\";\r\nimport { Vector2, Vector3, TmpVectors, Vector4 } from \"../Maths/math.vector\";\r\nimport { Color4 } from \"../Maths/math.color\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport type { ParticleSystem } from \"./particleSystem\";\r\nimport type { SubEmitter } from \"./subEmitter\";\r\nimport type { ColorGradient, FactorGradient } from \"../Misc/gradients\";\r\n\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\n\r\n/**\r\n * A particle represents one of the element emitted by a particle system.\r\n * This is mainly define by its coordinates, direction, velocity and age.\r\n */\r\nexport class Particle {\r\n private static _Count = 0;\r\n /**\r\n * Unique ID of the particle\r\n */\r\n public id: number;\r\n /**\r\n * The world position of the particle in the scene.\r\n */\r\n public position = Vector3.Zero();\r\n\r\n /**\r\n * The world direction of the particle in the scene.\r\n */\r\n public direction = Vector3.Zero();\r\n\r\n /**\r\n * The color of the particle.\r\n */\r\n public color = new Color4(0, 0, 0, 0);\r\n\r\n /**\r\n * The color change of the particle per step.\r\n */\r\n public colorStep = new Color4(0, 0, 0, 0);\r\n\r\n /**\r\n * Defines how long will the life of the particle be.\r\n */\r\n public lifeTime = 1.0;\r\n\r\n /**\r\n * The current age of the particle.\r\n */\r\n public age = 0;\r\n\r\n /**\r\n * The current size of the particle.\r\n */\r\n public size = 0;\r\n\r\n /**\r\n * The current scale of the particle.\r\n */\r\n public scale = new Vector2(1, 1);\r\n\r\n /**\r\n * The current angle of the particle.\r\n */\r\n public angle = 0;\r\n\r\n /**\r\n * Defines how fast is the angle changing.\r\n */\r\n public angularSpeed = 0;\r\n\r\n /**\r\n * Defines the cell index used by the particle to be rendered from a sprite.\r\n */\r\n public cellIndex: number = 0;\r\n\r\n /**\r\n * The information required to support color remapping\r\n */\r\n public remapData: Vector4;\r\n\r\n /** @internal */\r\n public _randomCellOffset?: number;\r\n\r\n /** @internal */\r\n public _initialDirection: Nullable;\r\n\r\n /** @internal */\r\n public _attachedSubEmitters: Nullable> = null;\r\n\r\n /** @internal */\r\n public _initialStartSpriteCellID: number;\r\n /** @internal */\r\n public _initialEndSpriteCellID: number;\r\n /** @internal */\r\n public _initialSpriteCellLoop: boolean;\r\n\r\n /** @internal */\r\n public _currentColorGradient: Nullable;\r\n /** @internal */\r\n public _currentColor1 = new Color4(0, 0, 0, 0);\r\n /** @internal */\r\n public _currentColor2 = new Color4(0, 0, 0, 0);\r\n\r\n /** @internal */\r\n public _currentSizeGradient: Nullable;\r\n /** @internal */\r\n public _currentSize1 = 0;\r\n /** @internal */\r\n public _currentSize2 = 0;\r\n\r\n /** @internal */\r\n public _currentAngularSpeedGradient: Nullable;\r\n /** @internal */\r\n public _currentAngularSpeed1 = 0;\r\n /** @internal */\r\n public _currentAngularSpeed2 = 0;\r\n\r\n /** @internal */\r\n public _currentVelocityGradient: Nullable;\r\n /** @internal */\r\n public _currentVelocity1 = 0;\r\n /** @internal */\r\n public _currentVelocity2 = 0;\r\n\r\n /** @internal */\r\n public _currentLimitVelocityGradient: Nullable;\r\n /** @internal */\r\n public _currentLimitVelocity1 = 0;\r\n /** @internal */\r\n public _currentLimitVelocity2 = 0;\r\n\r\n /** @internal */\r\n public _currentDragGradient: Nullable;\r\n /** @internal */\r\n public _currentDrag1 = 0;\r\n /** @internal */\r\n public _currentDrag2 = 0;\r\n\r\n /** @internal */\r\n public _randomNoiseCoordinates1: Vector3;\r\n /** @internal */\r\n public _randomNoiseCoordinates2: Vector3;\r\n\r\n /** @internal */\r\n public _localPosition?: Vector3;\r\n\r\n /**\r\n * Creates a new instance Particle\r\n * @param particleSystem the particle system the particle belongs to\r\n */\r\n constructor(\r\n /**\r\n * The particle system the particle belongs to.\r\n */\r\n public particleSystem: ParticleSystem\r\n ) {\r\n this.id = Particle._Count++;\r\n if (!this.particleSystem.isAnimationSheetEnabled) {\r\n return;\r\n }\r\n\r\n this._updateCellInfoFromSystem();\r\n }\r\n\r\n private _updateCellInfoFromSystem(): void {\r\n this.cellIndex = this.particleSystem.startSpriteCellID;\r\n }\r\n\r\n /**\r\n * Defines how the sprite cell index is updated for the particle\r\n */\r\n public updateCellIndex(): void {\r\n let offsetAge = this.age;\r\n let changeSpeed = this.particleSystem.spriteCellChangeSpeed;\r\n\r\n if (this.particleSystem.spriteRandomStartCell) {\r\n if (this._randomCellOffset === undefined) {\r\n this._randomCellOffset = Math.random() * this.lifeTime;\r\n }\r\n\r\n if (changeSpeed === 0) {\r\n // Special case when speed = 0 meaning we want to stay on initial cell\r\n changeSpeed = 1;\r\n offsetAge = this._randomCellOffset;\r\n } else {\r\n offsetAge += this._randomCellOffset;\r\n }\r\n }\r\n\r\n const dist = this._initialEndSpriteCellID - this._initialStartSpriteCellID;\r\n let ratio: number;\r\n if (this._initialSpriteCellLoop) {\r\n ratio = Scalar.Clamp(((offsetAge * changeSpeed) % this.lifeTime) / this.lifeTime);\r\n } else {\r\n ratio = Scalar.Clamp((offsetAge * changeSpeed) / this.lifeTime);\r\n }\r\n this.cellIndex = (this._initialStartSpriteCellID + ratio * dist) | 0;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _inheritParticleInfoToSubEmitter(subEmitter: SubEmitter) {\r\n if ((subEmitter.particleSystem.emitter).position) {\r\n const emitterMesh = subEmitter.particleSystem.emitter;\r\n emitterMesh.position.copyFrom(this.position);\r\n if (subEmitter.inheritDirection) {\r\n const temp = TmpVectors.Vector3[0];\r\n this.direction.normalizeToRef(temp);\r\n emitterMesh.setDirection(temp, 0, Math.PI / 2);\r\n }\r\n } else {\r\n const emitterPosition = subEmitter.particleSystem.emitter;\r\n emitterPosition.copyFrom(this.position);\r\n }\r\n // Set inheritedVelocityOffset to be used when new particles are created\r\n this.direction.scaleToRef(subEmitter.inheritedVelocityAmount / 2, TmpVectors.Vector3[0]);\r\n subEmitter.particleSystem._inheritedVelocityOffset.copyFrom(TmpVectors.Vector3[0]);\r\n }\r\n\r\n /** @internal */\r\n public _inheritParticleInfoToSubEmitters() {\r\n if (this._attachedSubEmitters && this._attachedSubEmitters.length > 0) {\r\n this._attachedSubEmitters.forEach((subEmitter) => {\r\n this._inheritParticleInfoToSubEmitter(subEmitter);\r\n });\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _reset() {\r\n this.age = 0;\r\n this.id = Particle._Count++;\r\n this._currentColorGradient = null;\r\n this._currentSizeGradient = null;\r\n this._currentAngularSpeedGradient = null;\r\n this._currentVelocityGradient = null;\r\n this._currentLimitVelocityGradient = null;\r\n this._currentDragGradient = null;\r\n this.cellIndex = this.particleSystem.startSpriteCellID;\r\n this._randomCellOffset = undefined;\r\n }\r\n\r\n /**\r\n * Copy the properties of particle to another one.\r\n * @param other the particle to copy the information to.\r\n */\r\n public copyTo(other: Particle) {\r\n other.position.copyFrom(this.position);\r\n if (this._initialDirection) {\r\n if (other._initialDirection) {\r\n other._initialDirection.copyFrom(this._initialDirection);\r\n } else {\r\n other._initialDirection = this._initialDirection.clone();\r\n }\r\n } else {\r\n other._initialDirection = null;\r\n }\r\n other.direction.copyFrom(this.direction);\r\n if (this._localPosition) {\r\n if (other._localPosition) {\r\n other._localPosition.copyFrom(this._localPosition);\r\n } else {\r\n other._localPosition = this._localPosition.clone();\r\n }\r\n }\r\n other.color.copyFrom(this.color);\r\n other.colorStep.copyFrom(this.colorStep);\r\n other.lifeTime = this.lifeTime;\r\n other.age = this.age;\r\n other._randomCellOffset = this._randomCellOffset;\r\n other.size = this.size;\r\n other.scale.copyFrom(this.scale);\r\n other.angle = this.angle;\r\n other.angularSpeed = this.angularSpeed;\r\n other.particleSystem = this.particleSystem;\r\n other.cellIndex = this.cellIndex;\r\n other.id = this.id;\r\n other._attachedSubEmitters = this._attachedSubEmitters;\r\n if (this._currentColorGradient) {\r\n other._currentColorGradient = this._currentColorGradient;\r\n other._currentColor1.copyFrom(this._currentColor1);\r\n other._currentColor2.copyFrom(this._currentColor2);\r\n }\r\n if (this._currentSizeGradient) {\r\n other._currentSizeGradient = this._currentSizeGradient;\r\n other._currentSize1 = this._currentSize1;\r\n other._currentSize2 = this._currentSize2;\r\n }\r\n if (this._currentAngularSpeedGradient) {\r\n other._currentAngularSpeedGradient = this._currentAngularSpeedGradient;\r\n other._currentAngularSpeed1 = this._currentAngularSpeed1;\r\n other._currentAngularSpeed2 = this._currentAngularSpeed2;\r\n }\r\n if (this._currentVelocityGradient) {\r\n other._currentVelocityGradient = this._currentVelocityGradient;\r\n other._currentVelocity1 = this._currentVelocity1;\r\n other._currentVelocity2 = this._currentVelocity2;\r\n }\r\n if (this._currentLimitVelocityGradient) {\r\n other._currentLimitVelocityGradient = this._currentLimitVelocityGradient;\r\n other._currentLimitVelocity1 = this._currentLimitVelocity1;\r\n other._currentLimitVelocity2 = this._currentLimitVelocity2;\r\n }\r\n if (this._currentDragGradient) {\r\n other._currentDragGradient = this._currentDragGradient;\r\n other._currentDrag1 = this._currentDrag1;\r\n other._currentDrag2 = this._currentDrag2;\r\n }\r\n if (this.particleSystem.isAnimationSheetEnabled) {\r\n other._initialStartSpriteCellID = this._initialStartSpriteCellID;\r\n other._initialEndSpriteCellID = this._initialEndSpriteCellID;\r\n other._initialSpriteCellLoop = this._initialSpriteCellLoop;\r\n }\r\n if (this.particleSystem.useRampGradients) {\r\n if (other.remapData && this.remapData) {\r\n other.remapData.copyFrom(this.remapData);\r\n } else {\r\n other.remapData = new Vector4(0, 0, 0, 0);\r\n }\r\n }\r\n if (this._randomNoiseCoordinates1) {\r\n if (other._randomNoiseCoordinates1) {\r\n other._randomNoiseCoordinates1.copyFrom(this._randomNoiseCoordinates1);\r\n other._randomNoiseCoordinates2.copyFrom(this._randomNoiseCoordinates2);\r\n } else {\r\n other._randomNoiseCoordinates1 = this._randomNoiseCoordinates1.clone();\r\n other._randomNoiseCoordinates2 = this._randomNoiseCoordinates2.clone();\r\n }\r\n }\r\n }\r\n}\r\n","import { Vector3 } from \"../Maths/math.vector\";\r\nimport { _WarnImport } from \"../Misc/devTools\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { GetClass } from \"../Misc/typeStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ParticleSystem } from \"../Particles/particleSystem\";\r\n\r\n/**\r\n * Type of sub emitter\r\n */\r\nexport enum SubEmitterType {\r\n /**\r\n * Attached to the particle over it's lifetime\r\n */\r\n ATTACHED,\r\n /**\r\n * Created when the particle dies\r\n */\r\n END,\r\n}\r\n\r\n/**\r\n * Sub emitter class used to emit particles from an existing particle\r\n */\r\nexport class SubEmitter {\r\n /**\r\n * Type of the submitter (Default: END)\r\n */\r\n public type = SubEmitterType.END;\r\n /**\r\n * If the particle should inherit the direction from the particle it's attached to. (+Y will face the direction the particle is moving) (Default: false)\r\n * Note: This only is supported when using an emitter of type Mesh\r\n */\r\n public inheritDirection = false;\r\n /**\r\n * How much of the attached particles speed should be added to the sub emitted particle (default: 0)\r\n */\r\n public inheritedVelocityAmount = 0;\r\n\r\n /**\r\n * Creates a sub emitter\r\n * @param particleSystem the particle system to be used by the sub emitter\r\n */\r\n constructor(\r\n /**\r\n * the particle system to be used by the sub emitter\r\n */\r\n public particleSystem: ParticleSystem\r\n ) {\r\n // Create mesh as emitter to support rotation\r\n if (!particleSystem.emitter || !(particleSystem.emitter).dispose) {\r\n const internalClass = GetClass(\"BABYLON.AbstractMesh\");\r\n particleSystem.emitter = new internalClass(\"SubemitterSystemEmitter\", particleSystem.getScene());\r\n particleSystem._disposeEmitterOnDispose = true;\r\n }\r\n }\r\n /**\r\n * Clones the sub emitter\r\n * @returns the cloned sub emitter\r\n */\r\n public clone(): SubEmitter {\r\n // Clone particle system\r\n let emitter = this.particleSystem.emitter;\r\n if (!emitter) {\r\n emitter = new Vector3();\r\n } else if (emitter instanceof Vector3) {\r\n emitter = emitter.clone();\r\n } else if (emitter.getClassName().indexOf(\"Mesh\") !== -1) {\r\n const internalClass = GetClass(\"BABYLON.Mesh\");\r\n emitter = new internalClass(\"\", emitter.getScene());\r\n (emitter! as any).isVisible = false;\r\n }\r\n const clone = new SubEmitter(this.particleSystem.clone(this.particleSystem.name, emitter));\r\n\r\n // Clone properties\r\n clone.particleSystem.name += \"Clone\";\r\n clone.type = this.type;\r\n clone.inheritDirection = this.inheritDirection;\r\n clone.inheritedVelocityAmount = this.inheritedVelocityAmount;\r\n\r\n clone.particleSystem._disposeEmitterOnDispose = true;\r\n clone.particleSystem.disposeOnStop = true;\r\n return clone;\r\n }\r\n\r\n /**\r\n * Serialize current object to a JSON object\r\n * @param serializeTexture defines if the texture must be serialized as well\r\n * @returns the serialized object\r\n */\r\n public serialize(serializeTexture: boolean = false): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.type;\r\n serializationObject.inheritDirection = this.inheritDirection;\r\n serializationObject.inheritedVelocityAmount = this.inheritedVelocityAmount;\r\n serializationObject.particleSystem = this.particleSystem.serialize(serializeTexture);\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static _ParseParticleSystem(system: any, sceneOrEngine: Scene | ThinEngine, rootUrl: string, doNotStart = false): ParticleSystem {\r\n throw _WarnImport(\"ParseParticle\");\r\n }\r\n\r\n /**\r\n * Creates a new SubEmitter from a serialized JSON version\r\n * @param serializationObject defines the JSON object to read from\r\n * @param sceneOrEngine defines the hosting scene or the hosting engine\r\n * @param rootUrl defines the rootUrl for data loading\r\n * @returns a new SubEmitter\r\n */\r\n public static Parse(serializationObject: any, sceneOrEngine: Scene | ThinEngine, rootUrl: string): SubEmitter {\r\n const system = serializationObject.particleSystem;\r\n const subEmitter = new SubEmitter(SubEmitter._ParseParticleSystem(system, sceneOrEngine, rootUrl, true));\r\n subEmitter.type = serializationObject.type;\r\n subEmitter.inheritDirection = serializationObject.inheritDirection;\r\n subEmitter.inheritedVelocityAmount = serializationObject.inheritedVelocityAmount;\r\n subEmitter.particleSystem._isSubEmitter = true;\r\n\r\n return subEmitter;\r\n }\r\n\r\n /** Release associated resources */\r\n public dispose() {\r\n this.particleSystem.dispose();\r\n }\r\n}\r\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/imageProcessingDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/imageProcessingFunctions\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/logDepthFragment\";\n\nconst name = \"particlesPixelShader\";\nconst shader = `#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nvarying vec2 vUV;varying vec4 vColor;uniform vec4 textureMask;uniform sampler2D diffuseSampler;\n#include\n#include\n#include\n#include\n#include\n#ifdef RAMPGRADIENT\nvarying vec4 remapRanges;uniform sampler2D rampSampler;\n#endif\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include\nvec4 textureColor=texture2D(diffuseSampler,vUV);vec4 baseColor=(textureColor*textureMask+(vec4(1.,1.,1.,1.)-textureMask))*vColor;\n#ifdef RAMPGRADIENT\nfloat alpha=baseColor.a;float remappedColorIndex=clamp((alpha-remapRanges.x)/remapRanges.y,0.0,1.0);vec4 rampColor=texture2D(rampSampler,vec2(1.0-remappedColorIndex,0.));baseColor.rgb*=rampColor.rgb;float finalAlpha=baseColor.a;baseColor.a=clamp((alpha*rampColor.a-remapRanges.z)/remapRanges.w,0.0,1.0);\n#endif\n#ifdef BLENDMULTIPLYMODE\nfloat sourceAlpha=vColor.a*textureColor.a;baseColor.rgb=baseColor.rgb*sourceAlpha+vec3(1.0)*(1.0-sourceAlpha);\n#endif\n#include\n#ifdef IMAGEPROCESSINGPOSTPROCESS\nbaseColor.rgb=toLinearSpace(baseColor.rgb);\n#else\n#ifdef IMAGEPROCESSING\nbaseColor.rgb=toLinearSpace(baseColor.rgb);baseColor=applyImageProcessing(baseColor);\n#endif\n#endif\ngl_FragColor=baseColor;\n#define CUSTOM_FRAGMENT_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const particlesPixelShader = { name, shader };\n","// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/clipPlaneVertexDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/clipPlaneVertex\";\nimport \"./ShadersInclude/logDepthVertex\";\n\nconst name = \"particlesVertexShader\";\nconst shader = `attribute vec3 position;attribute vec4 color;attribute float angle;attribute vec2 size;\n#ifdef ANIMATESHEET\nattribute float cellIndex;\n#endif\n#ifndef BILLBOARD\nattribute vec3 direction;\n#endif\n#ifdef BILLBOARDSTRETCHED\nattribute vec3 direction;\n#endif\n#ifdef RAMPGRADIENT\nattribute vec4 remapData;\n#endif\nattribute vec2 offset;uniform mat4 view;uniform mat4 projection;uniform vec2 translationPivot;\n#ifdef ANIMATESHEET\nuniform vec3 particlesInfos; \n#endif\nvarying vec2 vUV;varying vec4 vColor;varying vec3 vPositionW;\n#ifdef RAMPGRADIENT\nvarying vec4 remapRanges;\n#endif\n#if defined(BILLBOARD) && !defined(BILLBOARDY) && !defined(BILLBOARDSTRETCHED)\nuniform mat4 invView;\n#endif\n#include\n#include\n#ifdef BILLBOARD\nuniform vec3 eyePosition;\n#endif\nvec3 rotate(vec3 yaxis,vec3 rotatedCorner) {vec3 xaxis=normalize(cross(vec3(0.,1.0,0.),yaxis));vec3 zaxis=normalize(cross(yaxis,xaxis));vec3 row0=vec3(xaxis.x,xaxis.y,xaxis.z);vec3 row1=vec3(yaxis.x,yaxis.y,yaxis.z);vec3 row2=vec3(zaxis.x,zaxis.y,zaxis.z);mat3 rotMatrix= mat3(row0,row1,row2);vec3 alignedCorner=rotMatrix*rotatedCorner;return position+alignedCorner;}\n#ifdef BILLBOARDSTRETCHED\nvec3 rotateAlign(vec3 toCamera,vec3 rotatedCorner) {vec3 normalizedToCamera=normalize(toCamera);vec3 normalizedCrossDirToCamera=normalize(cross(normalize(direction),normalizedToCamera));vec3 row0=vec3(normalizedCrossDirToCamera.x,normalizedCrossDirToCamera.y,normalizedCrossDirToCamera.z);vec3 row2=vec3(normalizedToCamera.x,normalizedToCamera.y,normalizedToCamera.z);\n#ifdef BILLBOARDSTRETCHED_LOCAL\nvec3 row1=direction;\n#else\nvec3 crossProduct=normalize(cross(normalizedToCamera,normalizedCrossDirToCamera));vec3 row1=vec3(crossProduct.x,crossProduct.y,crossProduct.z);\n#endif\nmat3 rotMatrix= mat3(row0,row1,row2);vec3 alignedCorner=rotMatrix*rotatedCorner;return position+alignedCorner;}\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\nvec2 cornerPos;cornerPos=(vec2(offset.x-0.5,offset.y -0.5)-translationPivot)*size+translationPivot;\n#ifdef BILLBOARD\nvec3 rotatedCorner;\n#ifdef BILLBOARDY\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.y=0.;vec3 yaxis=position-eyePosition;yaxis.y=0.;vPositionW=rotate(normalize(yaxis),rotatedCorner);vec3 viewPos=(view*vec4(vPositionW,1.0)).xyz;\n#elif defined(BILLBOARDSTRETCHED)\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.z=0.;vec3 toCamera=position-eyePosition;vPositionW=rotateAlign(toCamera,rotatedCorner);vec3 viewPos=(view*vec4(vPositionW,1.0)).xyz;\n#else\nrotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.z=0.;vec3 viewPos=(view*vec4(position,1.0)).xyz+rotatedCorner;vPositionW=(invView*vec4(viewPos,1)).xyz;\n#endif\n#ifdef RAMPGRADIENT\nremapRanges=remapData;\n#endif\ngl_Position=projection*vec4(viewPos,1.0);\n#else\nvec3 rotatedCorner;rotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.y=0.;vec3 yaxis=normalize(direction);vPositionW=rotate(yaxis,rotatedCorner);gl_Position=projection*view*vec4(vPositionW,1.0);\n#endif\nvColor=color;\n#ifdef ANIMATESHEET\nfloat rowOffset=floor(cellIndex*particlesInfos.z);float columnOffset=cellIndex-rowOffset/particlesInfos.z;vec2 uvScale=particlesInfos.xy;vec2 uvOffset=vec2(offset.x ,1.0-offset.y);vUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;\n#else\nvUV=offset;\n#endif\n#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)\nvec4 worldPos=vec4(vPositionW,1.0);\n#endif\n#include\n#include\n#define CUSTOM_VERTEX_MAIN_END\n}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const particlesVertexShader = { name, shader };\n","/* eslint-disable import/no-internal-modules */\r\nimport type { Immutable, Nullable } from \"../types\";\r\nimport { FactorGradient, ColorGradient, Color3Gradient, GradientHelper } from \"../Misc/gradients\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport { Vector3, Matrix, TmpVectors, Vector4 } from \"../Maths/math.vector\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { VertexBuffer, Buffer } from \"../Buffers/buffer\";\r\n\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { ImageProcessingConfiguration } from \"../Materials/imageProcessingConfiguration\";\r\nimport { RawTexture } from \"../Materials/Textures/rawTexture\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport type { IParticleEmitterType } from \"../Particles/EmitterTypes/index\";\r\nimport {\r\n BoxParticleEmitter,\r\n HemisphericParticleEmitter,\r\n SphereParticleEmitter,\r\n SphereDirectedParticleEmitter,\r\n CylinderParticleEmitter,\r\n ConeParticleEmitter,\r\n PointParticleEmitter,\r\n MeshParticleEmitter,\r\n CylinderDirectedParticleEmitter,\r\n} from \"../Particles/EmitterTypes/index\";\r\nimport type { IParticleSystem } from \"./IParticleSystem\";\r\nimport { BaseParticleSystem } from \"./baseParticleSystem\";\r\nimport { Particle } from \"./particle\";\r\nimport { SubEmitter, SubEmitterType } from \"./subEmitter\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { SerializationHelper } from \"../Misc/decorators\";\r\nimport { GetClass } from \"../Misc/typeStore\";\r\nimport type { IAnimatable } from \"../Animations/animatable.interface\";\r\nimport { DrawWrapper } from \"../Materials/drawWrapper\";\r\n\r\nimport \"../Shaders/particles.fragment\";\r\nimport \"../Shaders/particles.vertex\";\r\nimport type { DataBuffer } from \"../Buffers/dataBuffer\";\r\nimport { Color4, Color3, TmpColors } from \"../Maths/math.color\";\r\nimport type { ISize } from \"../Maths/math.size\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { MaterialHelper } from \"../Materials/materialHelper\";\r\n\r\nimport \"../Engines/Extensions/engine.alpha\";\r\nimport { addClipPlaneUniforms, prepareStringDefinesForClipPlanes, bindClipPlane } from \"../Materials/clipPlaneMaterialHelper\";\r\n\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ProceduralTexture } from \"../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * This represents a particle system in Babylon.\r\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\r\n * Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.\r\n * @example https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro\r\n */\r\nexport class ParticleSystem extends BaseParticleSystem implements IDisposable, IAnimatable, IParticleSystem {\r\n /**\r\n * Billboard mode will only apply to Y axis\r\n */\r\n public static readonly BILLBOARDMODE_Y = Constants.PARTICLES_BILLBOARDMODE_Y;\r\n /**\r\n * Billboard mode will apply to all axes\r\n */\r\n public static readonly BILLBOARDMODE_ALL = Constants.PARTICLES_BILLBOARDMODE_ALL;\r\n /**\r\n * Special billboard mode where the particle will be biilboard to the camera but rotated to align with direction\r\n */\r\n public static readonly BILLBOARDMODE_STRETCHED = Constants.PARTICLES_BILLBOARDMODE_STRETCHED;\r\n /**\r\n * Special billboard mode where the particle will be billboard to the camera but only around the axis of the direction of particle emission\r\n */\r\n public static readonly BILLBOARDMODE_STRETCHED_LOCAL = Constants.PARTICLES_BILLBOARDMODE_STRETCHED_LOCAL;\r\n\r\n /**\r\n * This function can be defined to provide custom update for active particles.\r\n * This function will be called instead of regular update (age, position, color, etc.).\r\n * Do not forget that this function will be called on every frame so try to keep it simple and fast :)\r\n */\r\n public updateFunction: (particles: Particle[]) => void;\r\n\r\n private _emitterWorldMatrix: Matrix;\r\n private _emitterInverseWorldMatrix: Matrix = Matrix.Identity();\r\n\r\n /**\r\n * This function can be defined to specify initial direction for every new particle.\r\n * It by default use the emitterType defined function\r\n */\r\n public startDirectionFunction: (worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean) => void;\r\n /**\r\n * This function can be defined to specify initial position for every new particle.\r\n * It by default use the emitterType defined function\r\n */\r\n public startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean) => void;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _inheritedVelocityOffset = new Vector3();\r\n /**\r\n * An event triggered when the system is disposed\r\n */\r\n public onDisposeObservable = new Observable();\r\n /**\r\n * An event triggered when the system is stopped\r\n */\r\n public onStoppedObservable = new Observable();\r\n\r\n private _onDisposeObserver: Nullable>;\r\n /**\r\n * Sets a callback that will be triggered when the system is disposed\r\n */\r\n public set onDispose(callback: () => void) {\r\n if (this._onDisposeObserver) {\r\n this.onDisposeObservable.remove(this._onDisposeObserver);\r\n }\r\n this._onDisposeObserver = this.onDisposeObservable.add(callback);\r\n }\r\n\r\n private _particles = new Array();\r\n private _epsilon: number;\r\n private _capacity: number;\r\n private _stockParticles = new Array();\r\n private _newPartsExcess = 0;\r\n private _vertexData: Float32Array;\r\n private _vertexBuffer: Nullable;\r\n private _vertexBuffers: { [key: string]: VertexBuffer } = {};\r\n private _spriteBuffer: Nullable;\r\n private _indexBuffer: Nullable;\r\n private _drawWrappers: DrawWrapper[][]; // first index is render pass id, second index is blend mode\r\n private _customWrappers: { [blendMode: number]: Nullable };\r\n private _scaledColorStep = new Color4(0, 0, 0, 0);\r\n private _colorDiff = new Color4(0, 0, 0, 0);\r\n private _scaledDirection = Vector3.Zero();\r\n private _scaledGravity = Vector3.Zero();\r\n private _currentRenderId = -1;\r\n private _alive: boolean;\r\n private _useInstancing = false;\r\n private _vertexArrayObject: Nullable;\r\n\r\n private _started = false;\r\n private _stopped = false;\r\n private _actualFrame = 0;\r\n private _scaledUpdateSpeed: number;\r\n private _vertexBufferSize: number;\r\n\r\n /** @internal */\r\n public _currentEmitRateGradient: Nullable;\r\n /** @internal */\r\n public _currentEmitRate1 = 0;\r\n /** @internal */\r\n public _currentEmitRate2 = 0;\r\n\r\n /** @internal */\r\n public _currentStartSizeGradient: Nullable;\r\n /** @internal */\r\n public _currentStartSize1 = 0;\r\n /** @internal */\r\n public _currentStartSize2 = 0;\r\n\r\n /** Indicates that the update of particles is done in the animate function */\r\n public readonly updateInAnimate = true;\r\n\r\n private readonly _rawTextureWidth = 256;\r\n private _rampGradientsTexture: Nullable;\r\n private _useRampGradients = false;\r\n\r\n /** Gets or sets a matrix to use to compute projection */\r\n public defaultProjectionMatrix: Matrix;\r\n\r\n /** Gets or sets a matrix to use to compute view */\r\n public defaultViewMatrix: Matrix;\r\n\r\n /** Gets or sets a boolean indicating that ramp gradients must be used\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro#ramp-gradients\r\n */\r\n public get useRampGradients(): boolean {\r\n return this._useRampGradients;\r\n }\r\n\r\n public set useRampGradients(value: boolean) {\r\n if (this._useRampGradients === value) {\r\n return;\r\n }\r\n\r\n this._useRampGradients = value;\r\n\r\n this._resetEffect();\r\n }\r\n\r\n // Sub-emitters\r\n /**\r\n * The Sub-emitters templates that will be used to generate the sub particle system to be associated with the system, this property is used by the root particle system only.\r\n * When a particle is spawned, an array will be chosen at random and all the emitters in that array will be attached to the particle. (Default: [])\r\n */\r\n public subEmitters: Array>;\r\n // the subEmitters field above converted to a constant type\r\n private _subEmitters: Array>;\r\n /**\r\n * @internal\r\n * If the particle systems emitter should be disposed when the particle system is disposed\r\n */\r\n public _disposeEmitterOnDispose = false;\r\n /**\r\n * The current active Sub-systems, this property is used by the root particle system only.\r\n */\r\n public activeSubSystems: Array;\r\n\r\n /**\r\n * Specifies if the particles are updated in emitter local space or world space\r\n */\r\n public isLocal = false;\r\n\r\n /** Indicates that the particle system is CPU based */\r\n public readonly isGPU = false;\r\n\r\n private _rootParticleSystem: Nullable;\r\n //end of Sub-emitter\r\n\r\n /**\r\n * Gets the current list of active particles\r\n */\r\n public get particles(): Particle[] {\r\n return this._particles;\r\n }\r\n\r\n /**\r\n * Gets the number of particles active at the same time.\r\n * @returns The number of active particles.\r\n */\r\n public getActiveCount() {\r\n return this._particles.length;\r\n }\r\n\r\n /**\r\n * Returns the string \"ParticleSystem\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"ParticleSystem\";\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating that the system is stopping\r\n * @returns true if the system is currently stopping\r\n */\r\n public isStopping() {\r\n return this._stopped && this.isAlive();\r\n }\r\n\r\n /**\r\n * Gets the custom effect used to render the particles\r\n * @param blendMode Blend mode for which the effect should be retrieved\r\n * @returns The effect\r\n */\r\n public getCustomEffect(blendMode: number = 0): Nullable {\r\n return this._customWrappers[blendMode]?.effect ?? this._customWrappers[0]!.effect;\r\n }\r\n\r\n private _getCustomDrawWrapper(blendMode: number = 0): Nullable {\r\n return this._customWrappers[blendMode] ?? this._customWrappers[0];\r\n }\r\n\r\n /**\r\n * Sets the custom effect used to render the particles\r\n * @param effect The effect to set\r\n * @param blendMode Blend mode for which the effect should be set\r\n */\r\n public setCustomEffect(effect: Nullable, blendMode: number = 0) {\r\n this._customWrappers[blendMode] = new DrawWrapper(this._engine);\r\n this._customWrappers[blendMode]!.effect = effect;\r\n if (this._customWrappers[blendMode]!.drawContext) {\r\n this._customWrappers[blendMode]!.drawContext!.useInstancing = this._useInstancing;\r\n }\r\n }\r\n\r\n /** @internal */\r\n private _onBeforeDrawParticlesObservable: Nullable>> = null;\r\n\r\n /**\r\n * Observable that will be called just before the particles are drawn\r\n */\r\n public get onBeforeDrawParticlesObservable(): Observable> {\r\n if (!this._onBeforeDrawParticlesObservable) {\r\n this._onBeforeDrawParticlesObservable = new Observable>();\r\n }\r\n\r\n return this._onBeforeDrawParticlesObservable;\r\n }\r\n\r\n /**\r\n * Gets the name of the particle vertex shader\r\n */\r\n public get vertexShaderName(): string {\r\n return \"particles\";\r\n }\r\n\r\n /**\r\n * Gets the vertex buffers used by the particle system\r\n */\r\n public get vertexBuffers(): Immutable<{ [key: string]: VertexBuffer }> {\r\n return this._vertexBuffers;\r\n }\r\n\r\n /**\r\n * Gets the index buffer used by the particle system (or null if no index buffer is used (if _useInstancing=true))\r\n */\r\n public get indexBuffer(): Nullable {\r\n return this._indexBuffer;\r\n }\r\n\r\n /**\r\n * Instantiates a particle system.\r\n * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.\r\n * @param name The name of the particle system\r\n * @param capacity The max number of particles alive at the same time\r\n * @param sceneOrEngine The scene the particle system belongs to or the engine to use if no scene\r\n * @param customEffect a custom effect used to change the way particles are rendered by default\r\n * @param isAnimationSheetEnabled Must be true if using a spritesheet to animate the particles texture\r\n * @param epsilon Offset used to render the particles\r\n */\r\n constructor(\r\n name: string,\r\n capacity: number,\r\n sceneOrEngine: Scene | ThinEngine,\r\n customEffect: Nullable = null,\r\n isAnimationSheetEnabled: boolean = false,\r\n epsilon: number = 0.01\r\n ) {\r\n super(name);\r\n\r\n this._capacity = capacity;\r\n\r\n this._epsilon = epsilon;\r\n this._isAnimationSheetEnabled = isAnimationSheetEnabled;\r\n\r\n if (!sceneOrEngine || sceneOrEngine.getClassName() === \"Scene\") {\r\n this._scene = (sceneOrEngine as Scene) || EngineStore.LastCreatedScene;\r\n this._engine = this._scene.getEngine();\r\n this.uniqueId = this._scene.getUniqueId();\r\n this._scene.particleSystems.push(this);\r\n } else {\r\n this._engine = sceneOrEngine as ThinEngine;\r\n this.defaultProjectionMatrix = Matrix.PerspectiveFovLH(0.8, 1, 0.1, 100, this._engine.isNDCHalfZRange);\r\n }\r\n\r\n if (this._engine.getCaps().vertexArrayObject) {\r\n this._vertexArrayObject = null;\r\n }\r\n\r\n // Setup the default processing configuration to the scene.\r\n this._attachImageProcessingConfiguration(null);\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n this._customWrappers = { 0: new DrawWrapper(this._engine) };\r\n this._customWrappers[0]!.effect = customEffect;\r\n\r\n this._drawWrappers = [];\r\n this._useInstancing = this._engine.getCaps().instancedArrays;\r\n\r\n this._createIndexBuffer();\r\n this._createVertexBuffers();\r\n\r\n // Default emitter type\r\n this.particleEmitterType = new BoxParticleEmitter();\r\n let noiseTextureData: Nullable = null;\r\n\r\n // Update\r\n this.updateFunction = (particles: Particle[]): void => {\r\n let noiseTextureSize: Nullable = null;\r\n\r\n if (this.noiseTexture) {\r\n // We need to get texture data back to CPU\r\n noiseTextureSize = this.noiseTexture.getSize();\r\n this.noiseTexture.getContent()?.then((data) => {\r\n noiseTextureData = data as Uint8Array;\r\n });\r\n }\r\n\r\n const sameParticleArray = particles === this._particles;\r\n\r\n for (let index = 0; index < particles.length; index++) {\r\n const particle = particles[index];\r\n\r\n let scaledUpdateSpeed = this._scaledUpdateSpeed;\r\n const previousAge = particle.age;\r\n particle.age += scaledUpdateSpeed;\r\n\r\n // Evaluate step to death\r\n if (particle.age > particle.lifeTime) {\r\n const diff = particle.age - previousAge;\r\n const oldDiff = particle.lifeTime - previousAge;\r\n\r\n scaledUpdateSpeed = (oldDiff * scaledUpdateSpeed) / diff;\r\n\r\n particle.age = particle.lifeTime;\r\n }\r\n\r\n const ratio = particle.age / particle.lifeTime;\r\n\r\n // Color\r\n if (this._colorGradients && this._colorGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._colorGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== particle._currentColorGradient) {\r\n particle._currentColor1.copyFrom(particle._currentColor2);\r\n (nextGradient).getColorToRef(particle._currentColor2);\r\n particle._currentColorGradient = currentGradient;\r\n }\r\n Color4.LerpToRef(particle._currentColor1, particle._currentColor2, scale, particle.color);\r\n });\r\n } else {\r\n particle.colorStep.scaleToRef(scaledUpdateSpeed, this._scaledColorStep);\r\n particle.color.addInPlace(this._scaledColorStep);\r\n\r\n if (particle.color.a < 0) {\r\n particle.color.a = 0;\r\n }\r\n }\r\n\r\n // Angular speed\r\n if (this._angularSpeedGradients && this._angularSpeedGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._angularSpeedGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== particle._currentAngularSpeedGradient) {\r\n particle._currentAngularSpeed1 = particle._currentAngularSpeed2;\r\n particle._currentAngularSpeed2 = (nextGradient).getFactor();\r\n particle._currentAngularSpeedGradient = currentGradient;\r\n }\r\n particle.angularSpeed = Scalar.Lerp(particle._currentAngularSpeed1, particle._currentAngularSpeed2, scale);\r\n });\r\n }\r\n particle.angle += particle.angularSpeed * scaledUpdateSpeed;\r\n\r\n // Direction\r\n let directionScale = scaledUpdateSpeed;\r\n\r\n /// Velocity\r\n if (this._velocityGradients && this._velocityGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._velocityGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== particle._currentVelocityGradient) {\r\n particle._currentVelocity1 = particle._currentVelocity2;\r\n particle._currentVelocity2 = (nextGradient).getFactor();\r\n particle._currentVelocityGradient = currentGradient;\r\n }\r\n directionScale *= Scalar.Lerp(particle._currentVelocity1, particle._currentVelocity2, scale);\r\n });\r\n }\r\n\r\n particle.direction.scaleToRef(directionScale, this._scaledDirection);\r\n\r\n /// Limit velocity\r\n if (this._limitVelocityGradients && this._limitVelocityGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._limitVelocityGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== particle._currentLimitVelocityGradient) {\r\n particle._currentLimitVelocity1 = particle._currentLimitVelocity2;\r\n particle._currentLimitVelocity2 = (nextGradient).getFactor();\r\n particle._currentLimitVelocityGradient = currentGradient;\r\n }\r\n\r\n const limitVelocity = Scalar.Lerp(particle._currentLimitVelocity1, particle._currentLimitVelocity2, scale);\r\n const currentVelocity = particle.direction.length();\r\n\r\n if (currentVelocity > limitVelocity) {\r\n particle.direction.scaleInPlace(this.limitVelocityDamping);\r\n }\r\n });\r\n }\r\n\r\n /// Drag\r\n if (this._dragGradients && this._dragGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._dragGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== particle._currentDragGradient) {\r\n particle._currentDrag1 = particle._currentDrag2;\r\n particle._currentDrag2 = (nextGradient).getFactor();\r\n particle._currentDragGradient = currentGradient;\r\n }\r\n\r\n const drag = Scalar.Lerp(particle._currentDrag1, particle._currentDrag2, scale);\r\n\r\n this._scaledDirection.scaleInPlace(1.0 - drag);\r\n });\r\n }\r\n\r\n if (this.isLocal && particle._localPosition) {\r\n particle._localPosition!.addInPlace(this._scaledDirection);\r\n Vector3.TransformCoordinatesToRef(particle._localPosition!, this._emitterWorldMatrix, particle.position);\r\n } else {\r\n particle.position.addInPlace(this._scaledDirection);\r\n }\r\n\r\n // Noise\r\n if (noiseTextureData && noiseTextureSize && particle._randomNoiseCoordinates1) {\r\n const fetchedColorR = this._fetchR(\r\n particle._randomNoiseCoordinates1.x,\r\n particle._randomNoiseCoordinates1.y,\r\n noiseTextureSize.width,\r\n noiseTextureSize.height,\r\n noiseTextureData\r\n );\r\n const fetchedColorG = this._fetchR(\r\n particle._randomNoiseCoordinates1.z,\r\n particle._randomNoiseCoordinates2.x,\r\n noiseTextureSize.width,\r\n noiseTextureSize.height,\r\n noiseTextureData\r\n );\r\n const fetchedColorB = this._fetchR(\r\n particle._randomNoiseCoordinates2.y,\r\n particle._randomNoiseCoordinates2.z,\r\n noiseTextureSize.width,\r\n noiseTextureSize.height,\r\n noiseTextureData\r\n );\r\n\r\n const force = TmpVectors.Vector3[0];\r\n const scaledForce = TmpVectors.Vector3[1];\r\n\r\n force.copyFromFloats(\r\n (2 * fetchedColorR - 1) * this.noiseStrength.x,\r\n (2 * fetchedColorG - 1) * this.noiseStrength.y,\r\n (2 * fetchedColorB - 1) * this.noiseStrength.z\r\n );\r\n\r\n force.scaleToRef(scaledUpdateSpeed, scaledForce);\r\n particle.direction.addInPlace(scaledForce);\r\n }\r\n\r\n // Gravity\r\n this.gravity.scaleToRef(scaledUpdateSpeed, this._scaledGravity);\r\n particle.direction.addInPlace(this._scaledGravity);\r\n\r\n // Size\r\n if (this._sizeGradients && this._sizeGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._sizeGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== particle._currentSizeGradient) {\r\n particle._currentSize1 = particle._currentSize2;\r\n particle._currentSize2 = (nextGradient).getFactor();\r\n particle._currentSizeGradient = currentGradient;\r\n }\r\n particle.size = Scalar.Lerp(particle._currentSize1, particle._currentSize2, scale);\r\n });\r\n }\r\n\r\n // Remap data\r\n if (this._useRampGradients) {\r\n if (this._colorRemapGradients && this._colorRemapGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._colorRemapGradients, (currentGradient, nextGradient, scale) => {\r\n const min = Scalar.Lerp((currentGradient).factor1, (nextGradient).factor1, scale);\r\n const max = Scalar.Lerp((currentGradient).factor2!, (nextGradient).factor2!, scale);\r\n\r\n particle.remapData.x = min;\r\n particle.remapData.y = max - min;\r\n });\r\n }\r\n\r\n if (this._alphaRemapGradients && this._alphaRemapGradients.length > 0) {\r\n GradientHelper.GetCurrentGradient(ratio, this._alphaRemapGradients, (currentGradient, nextGradient, scale) => {\r\n const min = Scalar.Lerp((currentGradient).factor1, (nextGradient).factor1, scale);\r\n const max = Scalar.Lerp((currentGradient).factor2!, (nextGradient).factor2!, scale);\r\n\r\n particle.remapData.z = min;\r\n particle.remapData.w = max - min;\r\n });\r\n }\r\n }\r\n\r\n if (this._isAnimationSheetEnabled) {\r\n particle.updateCellIndex();\r\n }\r\n\r\n // Update the position of the attached sub-emitters to match their attached particle\r\n particle._inheritParticleInfoToSubEmitters();\r\n\r\n if (particle.age >= particle.lifeTime) {\r\n // Recycle by swapping with last particle\r\n this._emitFromParticle(particle);\r\n if (particle._attachedSubEmitters) {\r\n particle._attachedSubEmitters.forEach((subEmitter) => {\r\n subEmitter.particleSystem.disposeOnStop = true;\r\n subEmitter.particleSystem.stop();\r\n });\r\n particle._attachedSubEmitters = null;\r\n }\r\n this.recycleParticle(particle);\r\n if (sameParticleArray) {\r\n index--;\r\n }\r\n continue;\r\n }\r\n }\r\n };\r\n }\r\n\r\n private _addFactorGradient(factorGradients: FactorGradient[], gradient: number, factor: number, factor2?: number) {\r\n const newGradient = new FactorGradient(gradient, factor, factor2);\r\n factorGradients.push(newGradient);\r\n\r\n factorGradients.sort((a, b) => {\r\n if (a.gradient < b.gradient) {\r\n return -1;\r\n } else if (a.gradient > b.gradient) {\r\n return 1;\r\n }\r\n\r\n return 0;\r\n });\r\n }\r\n\r\n private _removeFactorGradient(factorGradients: Nullable, gradient: number) {\r\n if (!factorGradients) {\r\n return;\r\n }\r\n\r\n let index = 0;\r\n for (const factorGradient of factorGradients) {\r\n if (factorGradient.gradient === gradient) {\r\n factorGradients.splice(index, 1);\r\n break;\r\n }\r\n index++;\r\n }\r\n }\r\n\r\n /**\r\n * Adds a new life time gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the life time factor to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addLifeTimeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._lifeTimeGradients) {\r\n this._lifeTimeGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._lifeTimeGradients, gradient, factor, factor2);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific life time gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeLifeTimeGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._lifeTimeGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new size gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the size factor to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._sizeGradients) {\r\n this._sizeGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._sizeGradients, gradient, factor, factor2);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific size gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeSizeGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._sizeGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new color remap gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param min defines the color remap minimal range\r\n * @param max defines the color remap maximal range\r\n * @returns the current particle system\r\n */\r\n public addColorRemapGradient(gradient: number, min: number, max: number): IParticleSystem {\r\n if (!this._colorRemapGradients) {\r\n this._colorRemapGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._colorRemapGradients, gradient, min, max);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific color remap gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeColorRemapGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._colorRemapGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new alpha remap gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param min defines the alpha remap minimal range\r\n * @param max defines the alpha remap maximal range\r\n * @returns the current particle system\r\n */\r\n public addAlphaRemapGradient(gradient: number, min: number, max: number): IParticleSystem {\r\n if (!this._alphaRemapGradients) {\r\n this._alphaRemapGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._alphaRemapGradients, gradient, min, max);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific alpha remap gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeAlphaRemapGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._alphaRemapGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new angular speed gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the angular speed to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addAngularSpeedGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._angularSpeedGradients) {\r\n this._angularSpeedGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._angularSpeedGradients, gradient, factor, factor2);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific angular speed gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeAngularSpeedGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._angularSpeedGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new velocity gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the velocity to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._velocityGradients) {\r\n this._velocityGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._velocityGradients, gradient, factor, factor2);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific velocity gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeVelocityGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._velocityGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new limit velocity gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the limit velocity value to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addLimitVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._limitVelocityGradients) {\r\n this._limitVelocityGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._limitVelocityGradients, gradient, factor, factor2);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific limit velocity gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeLimitVelocityGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._limitVelocityGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new drag gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the drag value to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addDragGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._dragGradients) {\r\n this._dragGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._dragGradients, gradient, factor, factor2);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific drag gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeDragGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._dragGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new emit rate gradient (please note that this will only work if you set the targetStopDuration property)\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the emit rate value to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addEmitRateGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._emitRateGradients) {\r\n this._emitRateGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._emitRateGradients, gradient, factor, factor2);\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific emit rate gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeEmitRateGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._emitRateGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new start size gradient (please note that this will only work if you set the targetStopDuration property)\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param factor defines the start size value to affect to the specified gradient\r\n * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from\r\n * @returns the current particle system\r\n */\r\n public addStartSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem {\r\n if (!this._startSizeGradients) {\r\n this._startSizeGradients = [];\r\n }\r\n\r\n this._addFactorGradient(this._startSizeGradients, gradient, factor, factor2);\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific start size gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeStartSizeGradient(gradient: number): IParticleSystem {\r\n this._removeFactorGradient(this._startSizeGradients, gradient);\r\n\r\n return this;\r\n }\r\n\r\n private _createRampGradientTexture() {\r\n if (!this._rampGradients || !this._rampGradients.length || this._rampGradientsTexture || !this._scene) {\r\n return;\r\n }\r\n\r\n const data = new Uint8Array(this._rawTextureWidth * 4);\r\n const tmpColor = TmpColors.Color3[0];\r\n\r\n for (let x = 0; x < this._rawTextureWidth; x++) {\r\n const ratio = x / this._rawTextureWidth;\r\n\r\n GradientHelper.GetCurrentGradient(ratio, this._rampGradients, (currentGradient, nextGradient, scale) => {\r\n Color3.LerpToRef((currentGradient).color, (nextGradient).color, scale, tmpColor);\r\n data[x * 4] = tmpColor.r * 255;\r\n data[x * 4 + 1] = tmpColor.g * 255;\r\n data[x * 4 + 2] = tmpColor.b * 255;\r\n data[x * 4 + 3] = 255;\r\n });\r\n }\r\n\r\n this._rampGradientsTexture = RawTexture.CreateRGBATexture(data, this._rawTextureWidth, 1, this._scene, false, false, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n }\r\n\r\n /**\r\n * Gets the current list of ramp gradients.\r\n * You must use addRampGradient and removeRampGradient to update this list\r\n * @returns the list of ramp gradients\r\n */\r\n public getRampGradients(): Nullable> {\r\n return this._rampGradients;\r\n }\r\n\r\n /** Force the system to rebuild all gradients that need to be resync */\r\n public forceRefreshGradients() {\r\n this._syncRampGradientTexture();\r\n }\r\n\r\n private _syncRampGradientTexture() {\r\n if (!this._rampGradients) {\r\n return;\r\n }\r\n\r\n this._rampGradients.sort((a, b) => {\r\n if (a.gradient < b.gradient) {\r\n return -1;\r\n } else if (a.gradient > b.gradient) {\r\n return 1;\r\n }\r\n\r\n return 0;\r\n });\r\n\r\n if (this._rampGradientsTexture) {\r\n this._rampGradientsTexture.dispose();\r\n this._rampGradientsTexture = null;\r\n }\r\n\r\n this._createRampGradientTexture();\r\n }\r\n\r\n /**\r\n * Adds a new ramp gradient used to remap particle colors\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param color defines the color to affect to the specified gradient\r\n * @returns the current particle system\r\n */\r\n public addRampGradient(gradient: number, color: Color3): ParticleSystem {\r\n if (!this._rampGradients) {\r\n this._rampGradients = [];\r\n }\r\n\r\n const rampGradient = new Color3Gradient(gradient, color);\r\n this._rampGradients.push(rampGradient);\r\n\r\n this._syncRampGradientTexture();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific ramp gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns the current particle system\r\n */\r\n public removeRampGradient(gradient: number): ParticleSystem {\r\n this._removeGradientAndTexture(gradient, this._rampGradients, this._rampGradientsTexture);\r\n this._rampGradientsTexture = null;\r\n\r\n if (this._rampGradients && this._rampGradients.length > 0) {\r\n this._createRampGradientTexture();\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a new color gradient\r\n * @param gradient defines the gradient to use (between 0 and 1)\r\n * @param color1 defines the color to affect to the specified gradient\r\n * @param color2 defines an additional color used to define a range ([color, color2]) with main color to pick the final color from\r\n * @returns this particle system\r\n */\r\n public addColorGradient(gradient: number, color1: Color4, color2?: Color4): IParticleSystem {\r\n if (!this._colorGradients) {\r\n this._colorGradients = [];\r\n }\r\n\r\n const colorGradient = new ColorGradient(gradient, color1, color2);\r\n this._colorGradients.push(colorGradient);\r\n\r\n this._colorGradients.sort((a, b) => {\r\n if (a.gradient < b.gradient) {\r\n return -1;\r\n } else if (a.gradient > b.gradient) {\r\n return 1;\r\n }\r\n\r\n return 0;\r\n });\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove a specific color gradient\r\n * @param gradient defines the gradient to remove\r\n * @returns this particle system\r\n */\r\n public removeColorGradient(gradient: number): IParticleSystem {\r\n if (!this._colorGradients) {\r\n return this;\r\n }\r\n\r\n let index = 0;\r\n for (const colorGradient of this._colorGradients) {\r\n if (colorGradient.gradient === gradient) {\r\n this._colorGradients.splice(index, 1);\r\n break;\r\n }\r\n index++;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Resets the draw wrappers cache\r\n */\r\n public resetDrawCache(): void {\r\n for (const drawWrappers of this._drawWrappers) {\r\n if (drawWrappers) {\r\n for (const drawWrapper of drawWrappers) {\r\n drawWrapper?.dispose();\r\n }\r\n }\r\n }\r\n\r\n this._drawWrappers = [];\r\n }\r\n\r\n private _fetchR(u: number, v: number, width: number, height: number, pixels: Uint8Array): number {\r\n u = Math.abs(u) * 0.5 + 0.5;\r\n v = Math.abs(v) * 0.5 + 0.5;\r\n\r\n const wrappedU = (u * width) % width | 0;\r\n const wrappedV = (v * height) % height | 0;\r\n\r\n const position = (wrappedU + wrappedV * width) * 4;\r\n return pixels[position] / 255;\r\n }\r\n\r\n protected _reset() {\r\n this._resetEffect();\r\n }\r\n\r\n private _resetEffect() {\r\n if (this._vertexBuffer) {\r\n this._vertexBuffer.dispose();\r\n this._vertexBuffer = null;\r\n }\r\n\r\n if (this._spriteBuffer) {\r\n this._spriteBuffer.dispose();\r\n this._spriteBuffer = null;\r\n }\r\n\r\n if (this._vertexArrayObject) {\r\n this._engine.releaseVertexArrayObject(this._vertexArrayObject);\r\n this._vertexArrayObject = null;\r\n }\r\n\r\n this._createVertexBuffers();\r\n }\r\n\r\n private _createVertexBuffers() {\r\n this._vertexBufferSize = this._useInstancing ? 10 : 12;\r\n if (this._isAnimationSheetEnabled) {\r\n this._vertexBufferSize += 1;\r\n }\r\n\r\n if (!this._isBillboardBased || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\r\n this._vertexBufferSize += 3;\r\n }\r\n\r\n if (this._useRampGradients) {\r\n this._vertexBufferSize += 4;\r\n }\r\n\r\n const engine = this._engine;\r\n const vertexSize = this._vertexBufferSize * (this._useInstancing ? 1 : 4);\r\n this._vertexData = new Float32Array(this._capacity * vertexSize);\r\n this._vertexBuffer = new Buffer(engine, this._vertexData, true, vertexSize);\r\n\r\n let dataOffset = 0;\r\n const positions = this._vertexBuffer.createVertexBuffer(VertexBuffer.PositionKind, dataOffset, 3, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[VertexBuffer.PositionKind] = positions;\r\n dataOffset += 3;\r\n\r\n const colors = this._vertexBuffer.createVertexBuffer(VertexBuffer.ColorKind, dataOffset, 4, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[VertexBuffer.ColorKind] = colors;\r\n dataOffset += 4;\r\n\r\n const options = this._vertexBuffer.createVertexBuffer(\"angle\", dataOffset, 1, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[\"angle\"] = options;\r\n dataOffset += 1;\r\n\r\n const size = this._vertexBuffer.createVertexBuffer(\"size\", dataOffset, 2, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[\"size\"] = size;\r\n dataOffset += 2;\r\n\r\n if (this._isAnimationSheetEnabled) {\r\n const cellIndexBuffer = this._vertexBuffer.createVertexBuffer(\"cellIndex\", dataOffset, 1, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[\"cellIndex\"] = cellIndexBuffer;\r\n dataOffset += 1;\r\n }\r\n\r\n if (!this._isBillboardBased || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\r\n const directionBuffer = this._vertexBuffer.createVertexBuffer(\"direction\", dataOffset, 3, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[\"direction\"] = directionBuffer;\r\n dataOffset += 3;\r\n }\r\n\r\n if (this._useRampGradients) {\r\n const rampDataBuffer = this._vertexBuffer.createVertexBuffer(\"remapData\", dataOffset, 4, this._vertexBufferSize, this._useInstancing);\r\n this._vertexBuffers[\"remapData\"] = rampDataBuffer;\r\n dataOffset += 4;\r\n }\r\n\r\n let offsets: VertexBuffer;\r\n if (this._useInstancing) {\r\n const spriteData = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);\r\n this._spriteBuffer = new Buffer(engine, spriteData, false, 2);\r\n offsets = this._spriteBuffer.createVertexBuffer(\"offset\", 0, 2);\r\n } else {\r\n offsets = this._vertexBuffer.createVertexBuffer(\"offset\", dataOffset, 2, this._vertexBufferSize, this._useInstancing);\r\n dataOffset += 2;\r\n }\r\n this._vertexBuffers[\"offset\"] = offsets;\r\n\r\n this.resetDrawCache();\r\n }\r\n\r\n private _createIndexBuffer() {\r\n if (this._useInstancing) {\r\n return;\r\n }\r\n const indices = [];\r\n let index = 0;\r\n for (let count = 0; count < this._capacity; count++) {\r\n indices.push(index);\r\n indices.push(index + 1);\r\n indices.push(index + 2);\r\n indices.push(index);\r\n indices.push(index + 2);\r\n indices.push(index + 3);\r\n index += 4;\r\n }\r\n\r\n this._indexBuffer = this._engine.createIndexBuffer(indices);\r\n }\r\n\r\n /**\r\n * Gets the maximum number of particles active at the same time.\r\n * @returns The max number of active particles.\r\n */\r\n public getCapacity(): number {\r\n return this._capacity;\r\n }\r\n\r\n /**\r\n * Gets whether there are still active particles in the system.\r\n * @returns True if it is alive, otherwise false.\r\n */\r\n public isAlive(): boolean {\r\n return this._alive;\r\n }\r\n\r\n /**\r\n * Gets if the system has been started. (Note: this will still be true after stop is called)\r\n * @returns True if it has been started, otherwise false.\r\n */\r\n public isStarted(): boolean {\r\n return this._started;\r\n }\r\n\r\n private _prepareSubEmitterInternalArray() {\r\n this._subEmitters = new Array>();\r\n if (this.subEmitters) {\r\n this.subEmitters.forEach((subEmitter) => {\r\n if (subEmitter instanceof ParticleSystem) {\r\n this._subEmitters.push([new SubEmitter(subEmitter)]);\r\n } else if (subEmitter instanceof SubEmitter) {\r\n this._subEmitters.push([subEmitter]);\r\n } else if (subEmitter instanceof Array) {\r\n this._subEmitters.push(subEmitter);\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Starts the particle system and begins to emit\r\n * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)\r\n */\r\n public start(delay = this.startDelay): void {\r\n if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {\r\n throw \"Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set\";\r\n }\r\n if (delay) {\r\n setTimeout(() => {\r\n this.start(0);\r\n }, delay);\r\n return;\r\n }\r\n // Convert the subEmitters field to the constant type field _subEmitters\r\n this._prepareSubEmitterInternalArray();\r\n\r\n this._started = true;\r\n this._stopped = false;\r\n this._actualFrame = 0;\r\n if (this._subEmitters && this._subEmitters.length != 0) {\r\n this.activeSubSystems = new Array();\r\n }\r\n\r\n // Reset emit gradient so it acts the same on every start\r\n if (this._emitRateGradients) {\r\n if (this._emitRateGradients.length > 0) {\r\n this._currentEmitRateGradient = this._emitRateGradients[0];\r\n this._currentEmitRate1 = this._currentEmitRateGradient.getFactor();\r\n this._currentEmitRate2 = this._currentEmitRate1;\r\n }\r\n if (this._emitRateGradients.length > 1) {\r\n this._currentEmitRate2 = this._emitRateGradients[1].getFactor();\r\n }\r\n }\r\n // Reset start size gradient so it acts the same on every start\r\n if (this._startSizeGradients) {\r\n if (this._startSizeGradients.length > 0) {\r\n this._currentStartSizeGradient = this._startSizeGradients[0];\r\n this._currentStartSize1 = this._currentStartSizeGradient.getFactor();\r\n this._currentStartSize2 = this._currentStartSize1;\r\n }\r\n if (this._startSizeGradients.length > 1) {\r\n this._currentStartSize2 = this._startSizeGradients[1].getFactor();\r\n }\r\n }\r\n\r\n if (this.preWarmCycles) {\r\n if (this.emitter?.getClassName().indexOf(\"Mesh\") !== -1) {\r\n (this.emitter as any).computeWorldMatrix(true);\r\n }\r\n\r\n const noiseTextureAsProcedural = this.noiseTexture as ProceduralTexture;\r\n\r\n if (noiseTextureAsProcedural && noiseTextureAsProcedural.onGeneratedObservable) {\r\n noiseTextureAsProcedural.onGeneratedObservable.addOnce(() => {\r\n setTimeout(() => {\r\n for (let index = 0; index < this.preWarmCycles; index++) {\r\n this.animate(true);\r\n noiseTextureAsProcedural.render();\r\n }\r\n });\r\n });\r\n } else {\r\n for (let index = 0; index < this.preWarmCycles; index++) {\r\n this.animate(true);\r\n }\r\n }\r\n }\r\n\r\n // Animations\r\n if (this.beginAnimationOnStart && this.animations && this.animations.length > 0 && this._scene) {\r\n this._scene.beginAnimation(this, this.beginAnimationFrom, this.beginAnimationTo, this.beginAnimationLoop);\r\n }\r\n }\r\n\r\n /**\r\n * Stops the particle system.\r\n * @param stopSubEmitters if true it will stop the current system and all created sub-Systems if false it will stop the current root system only, this param is used by the root particle system only. the default value is true.\r\n */\r\n public stop(stopSubEmitters = true): void {\r\n if (this._stopped) {\r\n return;\r\n }\r\n\r\n this.onStoppedObservable.notifyObservers(this);\r\n\r\n this._stopped = true;\r\n\r\n if (stopSubEmitters) {\r\n this._stopSubEmitters();\r\n }\r\n }\r\n\r\n // animation sheet\r\n\r\n /**\r\n * Remove all active particles\r\n */\r\n public reset(): void {\r\n this._stockParticles.length = 0;\r\n this._particles.length = 0;\r\n }\r\n\r\n /**\r\n * @internal (for internal use only)\r\n */\r\n public _appendParticleVertex(index: number, particle: Particle, offsetX: number, offsetY: number): void {\r\n let offset = index * this._vertexBufferSize;\r\n\r\n this._vertexData[offset++] = particle.position.x + this.worldOffset.x;\r\n this._vertexData[offset++] = particle.position.y + this.worldOffset.y;\r\n this._vertexData[offset++] = particle.position.z + this.worldOffset.z;\r\n this._vertexData[offset++] = particle.color.r;\r\n this._vertexData[offset++] = particle.color.g;\r\n this._vertexData[offset++] = particle.color.b;\r\n this._vertexData[offset++] = particle.color.a;\r\n this._vertexData[offset++] = particle.angle;\r\n\r\n this._vertexData[offset++] = particle.scale.x * particle.size;\r\n this._vertexData[offset++] = particle.scale.y * particle.size;\r\n\r\n if (this._isAnimationSheetEnabled) {\r\n this._vertexData[offset++] = particle.cellIndex;\r\n }\r\n\r\n if (!this._isBillboardBased) {\r\n if (particle._initialDirection) {\r\n let initialDirection = particle._initialDirection;\r\n if (this.isLocal) {\r\n Vector3.TransformNormalToRef(initialDirection, this._emitterWorldMatrix, TmpVectors.Vector3[0]);\r\n initialDirection = TmpVectors.Vector3[0];\r\n }\r\n if (initialDirection.x === 0 && initialDirection.z === 0) {\r\n initialDirection.x = 0.001;\r\n }\r\n\r\n this._vertexData[offset++] = initialDirection.x;\r\n this._vertexData[offset++] = initialDirection.y;\r\n this._vertexData[offset++] = initialDirection.z;\r\n } else {\r\n let direction = particle.direction;\r\n if (this.isLocal) {\r\n Vector3.TransformNormalToRef(direction, this._emitterWorldMatrix, TmpVectors.Vector3[0]);\r\n direction = TmpVectors.Vector3[0];\r\n }\r\n\r\n if (direction.x === 0 && direction.z === 0) {\r\n direction.x = 0.001;\r\n }\r\n this._vertexData[offset++] = direction.x;\r\n this._vertexData[offset++] = direction.y;\r\n this._vertexData[offset++] = direction.z;\r\n }\r\n } else if (this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED || this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\r\n this._vertexData[offset++] = particle.direction.x;\r\n this._vertexData[offset++] = particle.direction.y;\r\n this._vertexData[offset++] = particle.direction.z;\r\n }\r\n\r\n if (this._useRampGradients && particle.remapData) {\r\n this._vertexData[offset++] = particle.remapData.x;\r\n this._vertexData[offset++] = particle.remapData.y;\r\n this._vertexData[offset++] = particle.remapData.z;\r\n this._vertexData[offset++] = particle.remapData.w;\r\n }\r\n\r\n if (!this._useInstancing) {\r\n if (this._isAnimationSheetEnabled) {\r\n if (offsetX === 0) {\r\n offsetX = this._epsilon;\r\n } else if (offsetX === 1) {\r\n offsetX = 1 - this._epsilon;\r\n }\r\n\r\n if (offsetY === 0) {\r\n offsetY = this._epsilon;\r\n } else if (offsetY === 1) {\r\n offsetY = 1 - this._epsilon;\r\n }\r\n }\r\n\r\n this._vertexData[offset++] = offsetX;\r\n this._vertexData[offset++] = offsetY;\r\n }\r\n }\r\n\r\n // start of sub system methods\r\n\r\n /**\r\n * \"Recycles\" one of the particle by copying it back to the \"stock\" of particles and removing it from the active list.\r\n * Its lifetime will start back at 0.\r\n * @param particle\r\n */\r\n public recycleParticle: (particle: Particle) => void = (particle) => {\r\n // move particle from activeParticle list to stock particles\r\n const lastParticle = this._particles.pop();\r\n if (lastParticle !== particle) {\r\n lastParticle.copyTo(particle);\r\n }\r\n this._stockParticles.push(lastParticle);\r\n };\r\n\r\n private _stopSubEmitters(): void {\r\n if (!this.activeSubSystems) {\r\n return;\r\n }\r\n this.activeSubSystems.forEach((subSystem) => {\r\n subSystem.stop(true);\r\n });\r\n this.activeSubSystems = new Array();\r\n }\r\n\r\n private _createParticle: () => Particle = () => {\r\n let particle: Particle;\r\n if (this._stockParticles.length !== 0) {\r\n particle = this._stockParticles.pop();\r\n particle._reset();\r\n } else {\r\n particle = new Particle(this);\r\n }\r\n\r\n // Attach emitters\r\n if (this._subEmitters && this._subEmitters.length > 0) {\r\n const subEmitters = this._subEmitters[Math.floor(Math.random() * this._subEmitters.length)];\r\n particle._attachedSubEmitters = [];\r\n subEmitters.forEach((subEmitter) => {\r\n if (subEmitter.type === SubEmitterType.ATTACHED) {\r\n const newEmitter = subEmitter.clone();\r\n (>particle._attachedSubEmitters).push(newEmitter);\r\n newEmitter.particleSystem.start();\r\n }\r\n });\r\n }\r\n return particle;\r\n };\r\n\r\n private _removeFromRoot(): void {\r\n if (!this._rootParticleSystem) {\r\n return;\r\n }\r\n\r\n const index = this._rootParticleSystem.activeSubSystems.indexOf(this);\r\n if (index !== -1) {\r\n this._rootParticleSystem.activeSubSystems.splice(index, 1);\r\n }\r\n\r\n this._rootParticleSystem = null;\r\n }\r\n\r\n private _emitFromParticle: (particle: Particle) => void = (particle) => {\r\n if (!this._subEmitters || this._subEmitters.length === 0) {\r\n return;\r\n }\r\n const templateIndex = Math.floor(Math.random() * this._subEmitters.length);\r\n\r\n this._subEmitters[templateIndex].forEach((subEmitter) => {\r\n if (subEmitter.type === SubEmitterType.END) {\r\n const subSystem = subEmitter.clone();\r\n particle._inheritParticleInfoToSubEmitter(subSystem);\r\n subSystem.particleSystem._rootParticleSystem = this;\r\n this.activeSubSystems.push(subSystem.particleSystem);\r\n subSystem.particleSystem.start();\r\n }\r\n });\r\n };\r\n\r\n // End of sub system methods\r\n\r\n private _update(newParticles: number): void {\r\n // Update current\r\n this._alive = this._particles.length > 0;\r\n\r\n if ((this.emitter).position) {\r\n const emitterMesh = this.emitter;\r\n this._emitterWorldMatrix = emitterMesh.getWorldMatrix();\r\n } else {\r\n const emitterPosition = this.emitter;\r\n this._emitterWorldMatrix = Matrix.Translation(emitterPosition.x, emitterPosition.y, emitterPosition.z);\r\n }\r\n\r\n this._emitterWorldMatrix.invertToRef(this._emitterInverseWorldMatrix);\r\n this.updateFunction(this._particles);\r\n\r\n // Add new ones\r\n let particle: Particle;\r\n for (let index = 0; index < newParticles; index++) {\r\n if (this._particles.length === this._capacity) {\r\n break;\r\n }\r\n\r\n particle = this._createParticle();\r\n\r\n this._particles.push(particle);\r\n\r\n // Life time\r\n if (this.targetStopDuration && this._lifeTimeGradients && this._lifeTimeGradients.length > 0) {\r\n const ratio = Scalar.Clamp(this._actualFrame / this.targetStopDuration);\r\n GradientHelper.GetCurrentGradient(ratio, this._lifeTimeGradients, (currentGradient, nextGradient) => {\r\n const factorGradient1 = currentGradient;\r\n const factorGradient2 = nextGradient;\r\n const lifeTime1 = factorGradient1.getFactor();\r\n const lifeTime2 = factorGradient2.getFactor();\r\n const gradient = (ratio - factorGradient1.gradient) / (factorGradient2.gradient - factorGradient1.gradient);\r\n particle.lifeTime = Scalar.Lerp(lifeTime1, lifeTime2, gradient);\r\n });\r\n } else {\r\n particle.lifeTime = Scalar.RandomRange(this.minLifeTime, this.maxLifeTime);\r\n }\r\n\r\n // Emitter\r\n const emitPower = Scalar.RandomRange(this.minEmitPower, this.maxEmitPower);\r\n\r\n if (this.startPositionFunction) {\r\n this.startPositionFunction(this._emitterWorldMatrix, particle.position, particle, this.isLocal);\r\n } else {\r\n this.particleEmitterType.startPositionFunction(this._emitterWorldMatrix, particle.position, particle, this.isLocal);\r\n }\r\n\r\n if (this.isLocal) {\r\n if (!particle._localPosition) {\r\n particle._localPosition = particle.position.clone();\r\n } else {\r\n particle._localPosition.copyFrom(particle.position);\r\n }\r\n Vector3.TransformCoordinatesToRef(particle._localPosition!, this._emitterWorldMatrix, particle.position);\r\n }\r\n\r\n if (this.startDirectionFunction) {\r\n this.startDirectionFunction(this._emitterWorldMatrix, particle.direction, particle, this.isLocal);\r\n } else {\r\n this.particleEmitterType.startDirectionFunction(this._emitterWorldMatrix, particle.direction, particle, this.isLocal, this._emitterInverseWorldMatrix);\r\n }\r\n\r\n if (emitPower === 0) {\r\n if (!particle._initialDirection) {\r\n particle._initialDirection = particle.direction.clone();\r\n } else {\r\n particle._initialDirection.copyFrom(particle.direction);\r\n }\r\n } else {\r\n particle._initialDirection = null;\r\n }\r\n\r\n particle.direction.scaleInPlace(emitPower);\r\n\r\n // Size\r\n if (!this._sizeGradients || this._sizeGradients.length === 0) {\r\n particle.size = Scalar.RandomRange(this.minSize, this.maxSize);\r\n } else {\r\n particle._currentSizeGradient = this._sizeGradients[0];\r\n particle._currentSize1 = particle._currentSizeGradient.getFactor();\r\n particle.size = particle._currentSize1;\r\n\r\n if (this._sizeGradients.length > 1) {\r\n particle._currentSize2 = this._sizeGradients[1].getFactor();\r\n } else {\r\n particle._currentSize2 = particle._currentSize1;\r\n }\r\n }\r\n // Size and scale\r\n particle.scale.copyFromFloats(Scalar.RandomRange(this.minScaleX, this.maxScaleX), Scalar.RandomRange(this.minScaleY, this.maxScaleY));\r\n\r\n // Adjust scale by start size\r\n if (this._startSizeGradients && this._startSizeGradients[0] && this.targetStopDuration) {\r\n const ratio = this._actualFrame / this.targetStopDuration;\r\n GradientHelper.GetCurrentGradient(ratio, this._startSizeGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== this._currentStartSizeGradient) {\r\n this._currentStartSize1 = this._currentStartSize2;\r\n this._currentStartSize2 = (nextGradient).getFactor();\r\n this._currentStartSizeGradient = currentGradient;\r\n }\r\n\r\n const value = Scalar.Lerp(this._currentStartSize1, this._currentStartSize2, scale);\r\n particle.scale.scaleInPlace(value);\r\n });\r\n }\r\n\r\n // Angle\r\n if (!this._angularSpeedGradients || this._angularSpeedGradients.length === 0) {\r\n particle.angularSpeed = Scalar.RandomRange(this.minAngularSpeed, this.maxAngularSpeed);\r\n } else {\r\n particle._currentAngularSpeedGradient = this._angularSpeedGradients[0];\r\n particle.angularSpeed = particle._currentAngularSpeedGradient.getFactor();\r\n particle._currentAngularSpeed1 = particle.angularSpeed;\r\n\r\n if (this._angularSpeedGradients.length > 1) {\r\n particle._currentAngularSpeed2 = this._angularSpeedGradients[1].getFactor();\r\n } else {\r\n particle._currentAngularSpeed2 = particle._currentAngularSpeed1;\r\n }\r\n }\r\n particle.angle = Scalar.RandomRange(this.minInitialRotation, this.maxInitialRotation);\r\n\r\n // Velocity\r\n if (this._velocityGradients && this._velocityGradients.length > 0) {\r\n particle._currentVelocityGradient = this._velocityGradients[0];\r\n particle._currentVelocity1 = particle._currentVelocityGradient.getFactor();\r\n\r\n if (this._velocityGradients.length > 1) {\r\n particle._currentVelocity2 = this._velocityGradients[1].getFactor();\r\n } else {\r\n particle._currentVelocity2 = particle._currentVelocity1;\r\n }\r\n }\r\n\r\n // Limit velocity\r\n if (this._limitVelocityGradients && this._limitVelocityGradients.length > 0) {\r\n particle._currentLimitVelocityGradient = this._limitVelocityGradients[0];\r\n particle._currentLimitVelocity1 = particle._currentLimitVelocityGradient.getFactor();\r\n\r\n if (this._limitVelocityGradients.length > 1) {\r\n particle._currentLimitVelocity2 = this._limitVelocityGradients[1].getFactor();\r\n } else {\r\n particle._currentLimitVelocity2 = particle._currentLimitVelocity1;\r\n }\r\n }\r\n\r\n // Drag\r\n if (this._dragGradients && this._dragGradients.length > 0) {\r\n particle._currentDragGradient = this._dragGradients[0];\r\n particle._currentDrag1 = particle._currentDragGradient.getFactor();\r\n\r\n if (this._dragGradients.length > 1) {\r\n particle._currentDrag2 = this._dragGradients[1].getFactor();\r\n } else {\r\n particle._currentDrag2 = particle._currentDrag1;\r\n }\r\n }\r\n\r\n // Color\r\n if (!this._colorGradients || this._colorGradients.length === 0) {\r\n const step = Scalar.RandomRange(0, 1.0);\r\n\r\n Color4.LerpToRef(this.color1, this.color2, step, particle.color);\r\n\r\n this.colorDead.subtractToRef(particle.color, this._colorDiff);\r\n this._colorDiff.scaleToRef(1.0 / particle.lifeTime, particle.colorStep);\r\n } else {\r\n particle._currentColorGradient = this._colorGradients[0];\r\n particle._currentColorGradient.getColorToRef(particle.color);\r\n particle._currentColor1.copyFrom(particle.color);\r\n\r\n if (this._colorGradients.length > 1) {\r\n this._colorGradients[1].getColorToRef(particle._currentColor2);\r\n } else {\r\n particle._currentColor2.copyFrom(particle.color);\r\n }\r\n }\r\n\r\n // Sheet\r\n if (this._isAnimationSheetEnabled) {\r\n particle._initialStartSpriteCellID = this.startSpriteCellID;\r\n particle._initialEndSpriteCellID = this.endSpriteCellID;\r\n particle._initialSpriteCellLoop = this.spriteCellLoop;\r\n }\r\n\r\n // Inherited Velocity\r\n particle.direction.addInPlace(this._inheritedVelocityOffset);\r\n\r\n // Ramp\r\n if (this._useRampGradients) {\r\n particle.remapData = new Vector4(0, 1, 0, 1);\r\n }\r\n\r\n // Noise texture coordinates\r\n if (this.noiseTexture) {\r\n if (particle._randomNoiseCoordinates1) {\r\n particle._randomNoiseCoordinates1.copyFromFloats(Math.random(), Math.random(), Math.random());\r\n particle._randomNoiseCoordinates2.copyFromFloats(Math.random(), Math.random(), Math.random());\r\n } else {\r\n particle._randomNoiseCoordinates1 = new Vector3(Math.random(), Math.random(), Math.random());\r\n particle._randomNoiseCoordinates2 = new Vector3(Math.random(), Math.random(), Math.random());\r\n }\r\n }\r\n\r\n // Update the position of the attached sub-emitters to match their attached particle\r\n particle._inheritParticleInfoToSubEmitters();\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _GetAttributeNamesOrOptions(isAnimationSheetEnabled = false, isBillboardBased = false, useRampGradients = false): string[] {\r\n const attributeNamesOrOptions = [VertexBuffer.PositionKind, VertexBuffer.ColorKind, \"angle\", \"offset\", \"size\"];\r\n\r\n if (isAnimationSheetEnabled) {\r\n attributeNamesOrOptions.push(\"cellIndex\");\r\n }\r\n\r\n if (!isBillboardBased) {\r\n attributeNamesOrOptions.push(\"direction\");\r\n }\r\n\r\n if (useRampGradients) {\r\n attributeNamesOrOptions.push(\"remapData\");\r\n }\r\n\r\n return attributeNamesOrOptions;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _GetEffectCreationOptions(isAnimationSheetEnabled = false, useLogarithmicDepth = false): string[] {\r\n const effectCreationOption = [\"invView\", \"view\", \"projection\", \"textureMask\", \"translationPivot\", \"eyePosition\"];\r\n\r\n addClipPlaneUniforms(effectCreationOption);\r\n\r\n if (isAnimationSheetEnabled) {\r\n effectCreationOption.push(\"particlesInfos\");\r\n }\r\n if (useLogarithmicDepth) {\r\n effectCreationOption.push(\"logarithmicDepthConstant\");\r\n }\r\n\r\n return effectCreationOption;\r\n }\r\n\r\n /**\r\n * Fill the defines array according to the current settings of the particle system\r\n * @param defines Array to be updated\r\n * @param blendMode blend mode to take into account when updating the array\r\n */\r\n public fillDefines(defines: Array, blendMode: number) {\r\n if (this._scene) {\r\n prepareStringDefinesForClipPlanes(this, this._scene, defines);\r\n }\r\n\r\n if (this._isAnimationSheetEnabled) {\r\n defines.push(\"#define ANIMATESHEET\");\r\n }\r\n\r\n if (this.useLogarithmicDepth) {\r\n defines.push(\"#define LOGARITHMICDEPTH\");\r\n }\r\n\r\n if (blendMode === ParticleSystem.BLENDMODE_MULTIPLY) {\r\n defines.push(\"#define BLENDMULTIPLYMODE\");\r\n }\r\n\r\n if (this._useRampGradients) {\r\n defines.push(\"#define RAMPGRADIENT\");\r\n }\r\n\r\n if (this._isBillboardBased) {\r\n defines.push(\"#define BILLBOARD\");\r\n\r\n switch (this.billboardMode) {\r\n case ParticleSystem.BILLBOARDMODE_Y:\r\n defines.push(\"#define BILLBOARDY\");\r\n break;\r\n case ParticleSystem.BILLBOARDMODE_STRETCHED:\r\n case ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL:\r\n defines.push(\"#define BILLBOARDSTRETCHED\");\r\n if (this.billboardMode === ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL) {\r\n defines.push(\"#define BILLBOARDSTRETCHED_LOCAL\");\r\n }\r\n break;\r\n case ParticleSystem.BILLBOARDMODE_ALL:\r\n defines.push(\"#define BILLBOARDMODE_ALL\");\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n\r\n if (this._imageProcessingConfiguration) {\r\n this._imageProcessingConfiguration.prepareDefines(this._imageProcessingConfigurationDefines);\r\n defines.push(this._imageProcessingConfigurationDefines.toString());\r\n }\r\n }\r\n\r\n /**\r\n * Fill the uniforms, attributes and samplers arrays according to the current settings of the particle system\r\n * @param uniforms Uniforms array to fill\r\n * @param attributes Attributes array to fill\r\n * @param samplers Samplers array to fill\r\n */\r\n public fillUniformsAttributesAndSamplerNames(uniforms: Array, attributes: Array, samplers: Array) {\r\n attributes.push(\r\n ...ParticleSystem._GetAttributeNamesOrOptions(\r\n this._isAnimationSheetEnabled,\r\n this._isBillboardBased && this.billboardMode !== ParticleSystem.BILLBOARDMODE_STRETCHED && this.billboardMode !== ParticleSystem.BILLBOARDMODE_STRETCHED_LOCAL,\r\n this._useRampGradients\r\n )\r\n );\r\n\r\n uniforms.push(...ParticleSystem._GetEffectCreationOptions(this._isAnimationSheetEnabled, this.useLogarithmicDepth));\r\n\r\n samplers.push(\"diffuseSampler\", \"rampSampler\");\r\n\r\n if (this._imageProcessingConfiguration) {\r\n ImageProcessingConfiguration.PrepareUniforms(uniforms, this._imageProcessingConfigurationDefines);\r\n ImageProcessingConfiguration.PrepareSamplers(samplers, this._imageProcessingConfigurationDefines);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n private _getWrapper(blendMode: number): DrawWrapper {\r\n const customWrapper = this._getCustomDrawWrapper(blendMode);\r\n\r\n if (customWrapper?.effect) {\r\n return customWrapper;\r\n }\r\n\r\n const defines: Array = [];\r\n\r\n this.fillDefines(defines, blendMode);\r\n\r\n // Effect\r\n const currentRenderPassId = this._engine._features.supportRenderPasses ? (this._engine as Engine).currentRenderPassId : Constants.RENDERPASS_MAIN;\r\n let drawWrappers = this._drawWrappers[currentRenderPassId];\r\n if (!drawWrappers) {\r\n drawWrappers = this._drawWrappers[currentRenderPassId] = [];\r\n }\r\n let drawWrapper = drawWrappers[blendMode];\r\n if (!drawWrapper) {\r\n drawWrapper = new DrawWrapper(this._engine);\r\n if (drawWrapper.drawContext) {\r\n drawWrapper.drawContext.useInstancing = this._useInstancing;\r\n }\r\n drawWrappers[blendMode] = drawWrapper;\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n if (drawWrapper.defines !== join) {\r\n const attributesNamesOrOptions: Array = [];\r\n const effectCreationOption: Array = [];\r\n const samplers: Array = [];\r\n\r\n this.fillUniformsAttributesAndSamplerNames(effectCreationOption, attributesNamesOrOptions, samplers);\r\n\r\n drawWrapper.setEffect(this._engine.createEffect(\"particles\", attributesNamesOrOptions, effectCreationOption, samplers, join), join);\r\n }\r\n\r\n return drawWrapper;\r\n }\r\n\r\n /**\r\n * Animates the particle system for the current frame by emitting new particles and or animating the living ones.\r\n * @param preWarmOnly will prevent the system from updating the vertex buffer (default is false)\r\n */\r\n public animate(preWarmOnly = false): void {\r\n if (!this._started) {\r\n return;\r\n }\r\n\r\n if (!preWarmOnly && this._scene) {\r\n // Check\r\n if (!this.isReady()) {\r\n return;\r\n }\r\n\r\n if (this._currentRenderId === this._scene.getFrameId()) {\r\n return;\r\n }\r\n this._currentRenderId = this._scene.getFrameId();\r\n }\r\n\r\n this._scaledUpdateSpeed = this.updateSpeed * (preWarmOnly ? this.preWarmStepOffset : this._scene?.getAnimationRatio() || 1);\r\n\r\n // Determine the number of particles we need to create\r\n let newParticles;\r\n\r\n if (this.manualEmitCount > -1) {\r\n newParticles = this.manualEmitCount;\r\n this._newPartsExcess = 0;\r\n this.manualEmitCount = 0;\r\n } else {\r\n let rate = this.emitRate;\r\n\r\n if (this._emitRateGradients && this._emitRateGradients.length > 0 && this.targetStopDuration) {\r\n const ratio = this._actualFrame / this.targetStopDuration;\r\n GradientHelper.GetCurrentGradient(ratio, this._emitRateGradients, (currentGradient, nextGradient, scale) => {\r\n if (currentGradient !== this._currentEmitRateGradient) {\r\n this._currentEmitRate1 = this._currentEmitRate2;\r\n this._currentEmitRate2 = (nextGradient).getFactor();\r\n this._currentEmitRateGradient = currentGradient;\r\n }\r\n\r\n rate = Scalar.Lerp(this._currentEmitRate1, this._currentEmitRate2, scale);\r\n });\r\n }\r\n\r\n newParticles = (rate * this._scaledUpdateSpeed) >> 0;\r\n this._newPartsExcess += rate * this._scaledUpdateSpeed - newParticles;\r\n }\r\n\r\n if (this._newPartsExcess > 1.0) {\r\n newParticles += this._newPartsExcess >> 0;\r\n this._newPartsExcess -= this._newPartsExcess >> 0;\r\n }\r\n\r\n this._alive = false;\r\n\r\n if (!this._stopped) {\r\n this._actualFrame += this._scaledUpdateSpeed;\r\n\r\n if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration) {\r\n this.stop();\r\n }\r\n } else {\r\n newParticles = 0;\r\n }\r\n this._update(newParticles);\r\n\r\n // Stopped?\r\n if (this._stopped) {\r\n if (!this._alive) {\r\n this._started = false;\r\n if (this.onAnimationEnd) {\r\n this.onAnimationEnd();\r\n }\r\n if (this.disposeOnStop && this._scene) {\r\n this._scene._toBeDisposed.push(this);\r\n }\r\n }\r\n }\r\n\r\n if (!preWarmOnly) {\r\n // Update VBO\r\n let offset = 0;\r\n for (let index = 0; index < this._particles.length; index++) {\r\n const particle = this._particles[index];\r\n this._appendParticleVertices(offset, particle);\r\n offset += this._useInstancing ? 1 : 4;\r\n }\r\n\r\n if (this._vertexBuffer) {\r\n this._vertexBuffer.updateDirectly(this._vertexData, 0, this._particles.length);\r\n }\r\n }\r\n\r\n if (this.manualEmitCount === 0 && this.disposeOnStop) {\r\n this.stop();\r\n }\r\n }\r\n\r\n private _appendParticleVertices(offset: number, particle: Particle) {\r\n this._appendParticleVertex(offset++, particle, 0, 0);\r\n if (!this._useInstancing) {\r\n this._appendParticleVertex(offset++, particle, 1, 0);\r\n this._appendParticleVertex(offset++, particle, 1, 1);\r\n this._appendParticleVertex(offset++, particle, 0, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Rebuilds the particle system.\r\n */\r\n public rebuild(): void {\r\n if (this._engine.getCaps().vertexArrayObject) {\r\n this._vertexArrayObject = null;\r\n }\r\n\r\n this._createIndexBuffer();\r\n\r\n this._spriteBuffer?._rebuild();\r\n\r\n this._vertexBuffer?._rebuild();\r\n\r\n for (const key in this._vertexBuffers) {\r\n this._vertexBuffers[key]._rebuild();\r\n }\r\n\r\n this.resetDrawCache();\r\n }\r\n\r\n /**\r\n * Is this system ready to be used/rendered\r\n * @returns true if the system is ready\r\n */\r\n public isReady(): boolean {\r\n if (!this.emitter || (this._imageProcessingConfiguration && !this._imageProcessingConfiguration.isReady()) || !this.particleTexture || !this.particleTexture.isReady()) {\r\n return false;\r\n }\r\n\r\n if (this.blendMode !== ParticleSystem.BLENDMODE_MULTIPLYADD) {\r\n if (!this._getWrapper(this.blendMode).effect!.isReady()) {\r\n return false;\r\n }\r\n } else {\r\n if (!this._getWrapper(ParticleSystem.BLENDMODE_MULTIPLY).effect!.isReady()) {\r\n return false;\r\n }\r\n if (!this._getWrapper(ParticleSystem.BLENDMODE_ADD).effect!.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _render(blendMode: number) {\r\n const drawWrapper = this._getWrapper(blendMode);\r\n const effect = drawWrapper.effect!;\r\n\r\n const engine = this._engine;\r\n\r\n // Render\r\n engine.enableEffect(drawWrapper);\r\n\r\n const viewMatrix = this.defaultViewMatrix ?? this._scene!.getViewMatrix();\r\n effect.setTexture(\"diffuseSampler\", this.particleTexture);\r\n effect.setMatrix(\"view\", viewMatrix);\r\n effect.setMatrix(\"projection\", this.defaultProjectionMatrix ?? this._scene!.getProjectionMatrix());\r\n\r\n if (this._isAnimationSheetEnabled && this.particleTexture) {\r\n const baseSize = this.particleTexture.getBaseSize();\r\n effect.setFloat3(\"particlesInfos\", this.spriteCellWidth / baseSize.width, this.spriteCellHeight / baseSize.height, this.spriteCellWidth / baseSize.width);\r\n }\r\n\r\n effect.setVector2(\"translationPivot\", this.translationPivot);\r\n effect.setFloat4(\"textureMask\", this.textureMask.r, this.textureMask.g, this.textureMask.b, this.textureMask.a);\r\n\r\n if (this._isBillboardBased && this._scene) {\r\n const camera = this._scene.activeCamera!;\r\n effect.setVector3(\"eyePosition\", camera.globalPosition);\r\n }\r\n\r\n if (this._rampGradientsTexture) {\r\n if (!this._rampGradients || !this._rampGradients.length) {\r\n this._rampGradientsTexture.dispose();\r\n this._rampGradientsTexture = null;\r\n }\r\n effect.setTexture(\"rampSampler\", this._rampGradientsTexture);\r\n }\r\n\r\n const defines = effect.defines;\r\n\r\n if (this._scene) {\r\n bindClipPlane(effect, this, this._scene);\r\n }\r\n\r\n if (defines.indexOf(\"#define BILLBOARDMODE_ALL\") >= 0) {\r\n viewMatrix.invertToRef(TmpVectors.Matrix[0]);\r\n effect.setMatrix(\"invView\", TmpVectors.Matrix[0]);\r\n }\r\n\r\n if (this._vertexArrayObject !== undefined) {\r\n if (!this._vertexArrayObject) {\r\n this._vertexArrayObject = this._engine.recordVertexArrayObject(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n this._engine.bindVertexArrayObject(this._vertexArrayObject, this._indexBuffer);\r\n } else {\r\n engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);\r\n }\r\n\r\n // Log. depth\r\n if (this.useLogarithmicDepth && this._scene) {\r\n MaterialHelper.BindLogDepth(defines, effect, this._scene);\r\n }\r\n\r\n // image processing\r\n if (this._imageProcessingConfiguration && !this._imageProcessingConfiguration.applyByPostProcess) {\r\n this._imageProcessingConfiguration.bind(effect);\r\n }\r\n\r\n // Draw order\r\n switch (blendMode) {\r\n case ParticleSystem.BLENDMODE_ADD:\r\n engine.setAlphaMode(Constants.ALPHA_ADD);\r\n break;\r\n case ParticleSystem.BLENDMODE_ONEONE:\r\n engine.setAlphaMode(Constants.ALPHA_ONEONE);\r\n break;\r\n case ParticleSystem.BLENDMODE_STANDARD:\r\n engine.setAlphaMode(Constants.ALPHA_COMBINE);\r\n break;\r\n case ParticleSystem.BLENDMODE_MULTIPLY:\r\n engine.setAlphaMode(Constants.ALPHA_MULTIPLY);\r\n break;\r\n }\r\n\r\n if (this._onBeforeDrawParticlesObservable) {\r\n this._onBeforeDrawParticlesObservable.notifyObservers(effect);\r\n }\r\n\r\n if (this._useInstancing) {\r\n engine.drawArraysType(Constants.MATERIAL_TriangleStripDrawMode, 0, 4, this._particles.length);\r\n } else {\r\n engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, this._particles.length * 6);\r\n }\r\n\r\n return this._particles.length;\r\n }\r\n\r\n /**\r\n * Renders the particle system in its current state.\r\n * @returns the current number of particles\r\n */\r\n public render(): number {\r\n // Check\r\n if (!this.isReady() || !this._particles.length) {\r\n return 0;\r\n }\r\n\r\n const engine = this._engine as any;\r\n if (engine.setState) {\r\n engine.setState(false);\r\n\r\n if (this.forceDepthWrite) {\r\n engine.setDepthWrite(true);\r\n }\r\n }\r\n\r\n let outparticles = 0;\r\n\r\n if (this.blendMode === ParticleSystem.BLENDMODE_MULTIPLYADD) {\r\n outparticles = this._render(ParticleSystem.BLENDMODE_MULTIPLY) + this._render(ParticleSystem.BLENDMODE_ADD);\r\n } else {\r\n outparticles = this._render(this.blendMode);\r\n }\r\n\r\n this._engine.unbindInstanceAttributes();\r\n this._engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n\r\n return outparticles;\r\n }\r\n\r\n /**\r\n * Disposes the particle system and free the associated resources\r\n * @param disposeTexture defines if the particle texture must be disposed as well (true by default)\r\n */\r\n public dispose(disposeTexture = true): void {\r\n this.resetDrawCache();\r\n\r\n if (this._vertexBuffer) {\r\n this._vertexBuffer.dispose();\r\n this._vertexBuffer = null;\r\n }\r\n\r\n if (this._spriteBuffer) {\r\n this._spriteBuffer.dispose();\r\n this._spriteBuffer = null;\r\n }\r\n\r\n if (this._indexBuffer) {\r\n this._engine._releaseBuffer(this._indexBuffer);\r\n this._indexBuffer = null;\r\n }\r\n\r\n if (this._vertexArrayObject) {\r\n this._engine.releaseVertexArrayObject(this._vertexArrayObject);\r\n this._vertexArrayObject = null;\r\n }\r\n\r\n if (disposeTexture && this.particleTexture) {\r\n this.particleTexture.dispose();\r\n this.particleTexture = null;\r\n }\r\n\r\n if (disposeTexture && this.noiseTexture) {\r\n this.noiseTexture.dispose();\r\n this.noiseTexture = null;\r\n }\r\n\r\n if (this._rampGradientsTexture) {\r\n this._rampGradientsTexture.dispose();\r\n this._rampGradientsTexture = null;\r\n }\r\n\r\n this._removeFromRoot();\r\n\r\n if (this.subEmitters && !this._subEmitters) {\r\n this._prepareSubEmitterInternalArray();\r\n }\r\n\r\n if (this._subEmitters && this._subEmitters.length) {\r\n for (let index = 0; index < this._subEmitters.length; index++) {\r\n for (const subEmitter of this._subEmitters[index]) {\r\n subEmitter.dispose();\r\n }\r\n }\r\n\r\n this._subEmitters = [];\r\n this.subEmitters = [];\r\n }\r\n\r\n if (this._disposeEmitterOnDispose && this.emitter && (this.emitter as AbstractMesh).dispose) {\r\n (this.emitter).dispose(true);\r\n }\r\n\r\n if (this._onBeforeDrawParticlesObservable) {\r\n this._onBeforeDrawParticlesObservable.clear();\r\n }\r\n\r\n // Remove from scene\r\n if (this._scene) {\r\n const index = this._scene.particleSystems.indexOf(this);\r\n if (index > -1) {\r\n this._scene.particleSystems.splice(index, 1);\r\n }\r\n\r\n this._scene._activeParticleSystems.dispose();\r\n }\r\n\r\n // Callback\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n this.onStoppedObservable.clear();\r\n\r\n this.reset();\r\n }\r\n\r\n // Clone\r\n /**\r\n * Clones the particle system.\r\n * @param name The name of the cloned object\r\n * @param newEmitter The new emitter to use\r\n * @param cloneTexture Also clone the textures if true\r\n * @returns the cloned particle system\r\n */\r\n public clone(name: string, newEmitter: any, cloneTexture = false): ParticleSystem {\r\n const custom = { ...this._customWrappers };\r\n let program: any = null;\r\n const engine = this._engine as Engine;\r\n if (engine.createEffectForParticles) {\r\n if (this.customShader != null) {\r\n program = this.customShader;\r\n const defines: string = program.shaderOptions.defines.length > 0 ? program.shaderOptions.defines.join(\"\\n\") : \"\";\r\n const effect = engine.createEffectForParticles(program.shaderPath.fragmentElement, program.shaderOptions.uniforms, program.shaderOptions.samplers, defines);\r\n if (!custom[0]) {\r\n this.setCustomEffect(effect, 0);\r\n } else {\r\n custom[0].effect = effect;\r\n }\r\n }\r\n }\r\n\r\n const serialization = this.serialize(cloneTexture);\r\n const result = ParticleSystem.Parse(serialization, this._scene || this._engine, this._rootUrl);\r\n result.name = name;\r\n result.customShader = program;\r\n result._customWrappers = custom;\r\n\r\n if (newEmitter === undefined) {\r\n newEmitter = this.emitter;\r\n }\r\n\r\n if (this.noiseTexture) {\r\n result.noiseTexture = this.noiseTexture.clone();\r\n }\r\n\r\n result.emitter = newEmitter;\r\n if (!this.preventAutoStart) {\r\n result.start();\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object\r\n * @param serializeTexture defines if the texture must be serialized as well\r\n * @returns the JSON object\r\n */\r\n public serialize(serializeTexture = false): any {\r\n const serializationObject: any = {};\r\n\r\n ParticleSystem._Serialize(serializationObject, this, serializeTexture);\r\n\r\n serializationObject.textureMask = this.textureMask.asArray();\r\n serializationObject.customShader = this.customShader;\r\n serializationObject.preventAutoStart = this.preventAutoStart;\r\n\r\n // SubEmitters\r\n if (this.subEmitters) {\r\n serializationObject.subEmitters = [];\r\n\r\n if (!this._subEmitters) {\r\n this._prepareSubEmitterInternalArray();\r\n }\r\n\r\n for (const subs of this._subEmitters) {\r\n const cell = [];\r\n for (const sub of subs) {\r\n cell.push(sub.serialize(serializeTexture));\r\n }\r\n\r\n serializationObject.subEmitters.push(cell);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Serialize(serializationObject: any, particleSystem: IParticleSystem, serializeTexture: boolean) {\r\n serializationObject.name = particleSystem.name;\r\n serializationObject.id = particleSystem.id;\r\n\r\n serializationObject.capacity = particleSystem.getCapacity();\r\n\r\n serializationObject.disposeOnStop = particleSystem.disposeOnStop;\r\n serializationObject.manualEmitCount = particleSystem.manualEmitCount;\r\n\r\n // Emitter\r\n if ((particleSystem.emitter).position) {\r\n const emitterMesh = particleSystem.emitter;\r\n serializationObject.emitterId = emitterMesh.id;\r\n } else {\r\n const emitterPosition = particleSystem.emitter;\r\n serializationObject.emitter = emitterPosition.asArray();\r\n }\r\n\r\n // Emitter\r\n if (particleSystem.particleEmitterType) {\r\n serializationObject.particleEmitterType = particleSystem.particleEmitterType.serialize();\r\n }\r\n\r\n if (particleSystem.particleTexture) {\r\n if (serializeTexture) {\r\n serializationObject.texture = particleSystem.particleTexture.serialize();\r\n } else {\r\n serializationObject.textureName = particleSystem.particleTexture.name;\r\n serializationObject.invertY = !!(particleSystem.particleTexture as any)._invertY;\r\n }\r\n }\r\n\r\n serializationObject.isLocal = particleSystem.isLocal;\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(particleSystem, serializationObject);\r\n serializationObject.beginAnimationOnStart = particleSystem.beginAnimationOnStart;\r\n serializationObject.beginAnimationFrom = particleSystem.beginAnimationFrom;\r\n serializationObject.beginAnimationTo = particleSystem.beginAnimationTo;\r\n serializationObject.beginAnimationLoop = particleSystem.beginAnimationLoop;\r\n\r\n // Particle system\r\n serializationObject.startDelay = particleSystem.startDelay;\r\n serializationObject.renderingGroupId = particleSystem.renderingGroupId;\r\n serializationObject.isBillboardBased = particleSystem.isBillboardBased;\r\n serializationObject.billboardMode = particleSystem.billboardMode;\r\n serializationObject.minAngularSpeed = particleSystem.minAngularSpeed;\r\n serializationObject.maxAngularSpeed = particleSystem.maxAngularSpeed;\r\n serializationObject.minSize = particleSystem.minSize;\r\n serializationObject.maxSize = particleSystem.maxSize;\r\n serializationObject.minScaleX = particleSystem.minScaleX;\r\n serializationObject.maxScaleX = particleSystem.maxScaleX;\r\n serializationObject.minScaleY = particleSystem.minScaleY;\r\n serializationObject.maxScaleY = particleSystem.maxScaleY;\r\n serializationObject.minEmitPower = particleSystem.minEmitPower;\r\n serializationObject.maxEmitPower = particleSystem.maxEmitPower;\r\n serializationObject.minLifeTime = particleSystem.minLifeTime;\r\n serializationObject.maxLifeTime = particleSystem.maxLifeTime;\r\n serializationObject.emitRate = particleSystem.emitRate;\r\n serializationObject.gravity = particleSystem.gravity.asArray();\r\n serializationObject.noiseStrength = particleSystem.noiseStrength.asArray();\r\n serializationObject.color1 = particleSystem.color1.asArray();\r\n serializationObject.color2 = particleSystem.color2.asArray();\r\n serializationObject.colorDead = particleSystem.colorDead.asArray();\r\n serializationObject.updateSpeed = particleSystem.updateSpeed;\r\n serializationObject.targetStopDuration = particleSystem.targetStopDuration;\r\n serializationObject.blendMode = particleSystem.blendMode;\r\n serializationObject.preWarmCycles = particleSystem.preWarmCycles;\r\n serializationObject.preWarmStepOffset = particleSystem.preWarmStepOffset;\r\n serializationObject.minInitialRotation = particleSystem.minInitialRotation;\r\n serializationObject.maxInitialRotation = particleSystem.maxInitialRotation;\r\n serializationObject.startSpriteCellID = particleSystem.startSpriteCellID;\r\n serializationObject.spriteCellLoop = particleSystem.spriteCellLoop;\r\n serializationObject.endSpriteCellID = particleSystem.endSpriteCellID;\r\n serializationObject.spriteCellChangeSpeed = particleSystem.spriteCellChangeSpeed;\r\n serializationObject.spriteCellWidth = particleSystem.spriteCellWidth;\r\n serializationObject.spriteCellHeight = particleSystem.spriteCellHeight;\r\n serializationObject.spriteRandomStartCell = particleSystem.spriteRandomStartCell;\r\n serializationObject.isAnimationSheetEnabled = particleSystem.isAnimationSheetEnabled;\r\n serializationObject.useLogarithmicDepth = particleSystem.useLogarithmicDepth;\r\n\r\n const colorGradients = particleSystem.getColorGradients();\r\n if (colorGradients) {\r\n serializationObject.colorGradients = [];\r\n for (const colorGradient of colorGradients) {\r\n const serializedGradient: any = {\r\n gradient: colorGradient.gradient,\r\n color1: colorGradient.color1.asArray(),\r\n };\r\n\r\n if (colorGradient.color2) {\r\n serializedGradient.color2 = colorGradient.color2.asArray();\r\n } else {\r\n serializedGradient.color2 = colorGradient.color1.asArray();\r\n }\r\n\r\n serializationObject.colorGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const rampGradients = particleSystem.getRampGradients();\r\n if (rampGradients) {\r\n serializationObject.rampGradients = [];\r\n for (const rampGradient of rampGradients) {\r\n const serializedGradient: any = {\r\n gradient: rampGradient.gradient,\r\n color: rampGradient.color.asArray(),\r\n };\r\n\r\n serializationObject.rampGradients.push(serializedGradient);\r\n }\r\n serializationObject.useRampGradients = particleSystem.useRampGradients;\r\n }\r\n\r\n const colorRemapGradients = particleSystem.getColorRemapGradients();\r\n if (colorRemapGradients) {\r\n serializationObject.colorRemapGradients = [];\r\n for (const colorRemapGradient of colorRemapGradients) {\r\n const serializedGradient: any = {\r\n gradient: colorRemapGradient.gradient,\r\n factor1: colorRemapGradient.factor1,\r\n };\r\n\r\n if (colorRemapGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = colorRemapGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = colorRemapGradient.factor1;\r\n }\r\n\r\n serializationObject.colorRemapGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const alphaRemapGradients = particleSystem.getAlphaRemapGradients();\r\n if (alphaRemapGradients) {\r\n serializationObject.alphaRemapGradients = [];\r\n for (const alphaRemapGradient of alphaRemapGradients) {\r\n const serializedGradient: any = {\r\n gradient: alphaRemapGradient.gradient,\r\n factor1: alphaRemapGradient.factor1,\r\n };\r\n\r\n if (alphaRemapGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = alphaRemapGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = alphaRemapGradient.factor1;\r\n }\r\n\r\n serializationObject.alphaRemapGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const sizeGradients = particleSystem.getSizeGradients();\r\n if (sizeGradients) {\r\n serializationObject.sizeGradients = [];\r\n for (const sizeGradient of sizeGradients) {\r\n const serializedGradient: any = {\r\n gradient: sizeGradient.gradient,\r\n factor1: sizeGradient.factor1,\r\n };\r\n\r\n if (sizeGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = sizeGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = sizeGradient.factor1;\r\n }\r\n\r\n serializationObject.sizeGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const angularSpeedGradients = particleSystem.getAngularSpeedGradients();\r\n if (angularSpeedGradients) {\r\n serializationObject.angularSpeedGradients = [];\r\n for (const angularSpeedGradient of angularSpeedGradients) {\r\n const serializedGradient: any = {\r\n gradient: angularSpeedGradient.gradient,\r\n factor1: angularSpeedGradient.factor1,\r\n };\r\n\r\n if (angularSpeedGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = angularSpeedGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = angularSpeedGradient.factor1;\r\n }\r\n\r\n serializationObject.angularSpeedGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const velocityGradients = particleSystem.getVelocityGradients();\r\n if (velocityGradients) {\r\n serializationObject.velocityGradients = [];\r\n for (const velocityGradient of velocityGradients) {\r\n const serializedGradient: any = {\r\n gradient: velocityGradient.gradient,\r\n factor1: velocityGradient.factor1,\r\n };\r\n\r\n if (velocityGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = velocityGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = velocityGradient.factor1;\r\n }\r\n\r\n serializationObject.velocityGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const dragGradients = particleSystem.getDragGradients();\r\n if (dragGradients) {\r\n serializationObject.dragGradients = [];\r\n for (const dragGradient of dragGradients) {\r\n const serializedGradient: any = {\r\n gradient: dragGradient.gradient,\r\n factor1: dragGradient.factor1,\r\n };\r\n\r\n if (dragGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = dragGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = dragGradient.factor1;\r\n }\r\n\r\n serializationObject.dragGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const emitRateGradients = particleSystem.getEmitRateGradients();\r\n if (emitRateGradients) {\r\n serializationObject.emitRateGradients = [];\r\n for (const emitRateGradient of emitRateGradients) {\r\n const serializedGradient: any = {\r\n gradient: emitRateGradient.gradient,\r\n factor1: emitRateGradient.factor1,\r\n };\r\n\r\n if (emitRateGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = emitRateGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = emitRateGradient.factor1;\r\n }\r\n\r\n serializationObject.emitRateGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const startSizeGradients = particleSystem.getStartSizeGradients();\r\n if (startSizeGradients) {\r\n serializationObject.startSizeGradients = [];\r\n for (const startSizeGradient of startSizeGradients) {\r\n const serializedGradient: any = {\r\n gradient: startSizeGradient.gradient,\r\n factor1: startSizeGradient.factor1,\r\n };\r\n\r\n if (startSizeGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = startSizeGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = startSizeGradient.factor1;\r\n }\r\n\r\n serializationObject.startSizeGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const lifeTimeGradients = particleSystem.getLifeTimeGradients();\r\n if (lifeTimeGradients) {\r\n serializationObject.lifeTimeGradients = [];\r\n for (const lifeTimeGradient of lifeTimeGradients) {\r\n const serializedGradient: any = {\r\n gradient: lifeTimeGradient.gradient,\r\n factor1: lifeTimeGradient.factor1,\r\n };\r\n\r\n if (lifeTimeGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = lifeTimeGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = lifeTimeGradient.factor1;\r\n }\r\n\r\n serializationObject.lifeTimeGradients.push(serializedGradient);\r\n }\r\n }\r\n\r\n const limitVelocityGradients = particleSystem.getLimitVelocityGradients();\r\n if (limitVelocityGradients) {\r\n serializationObject.limitVelocityGradients = [];\r\n for (const limitVelocityGradient of limitVelocityGradients) {\r\n const serializedGradient: any = {\r\n gradient: limitVelocityGradient.gradient,\r\n factor1: limitVelocityGradient.factor1,\r\n };\r\n\r\n if (limitVelocityGradient.factor2 !== undefined) {\r\n serializedGradient.factor2 = limitVelocityGradient.factor2;\r\n } else {\r\n serializedGradient.factor2 = limitVelocityGradient.factor1;\r\n }\r\n\r\n serializationObject.limitVelocityGradients.push(serializedGradient);\r\n }\r\n\r\n serializationObject.limitVelocityDamping = particleSystem.limitVelocityDamping;\r\n }\r\n\r\n if (particleSystem.noiseTexture) {\r\n serializationObject.noiseTexture = particleSystem.noiseTexture.serialize();\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _Parse(parsedParticleSystem: any, particleSystem: IParticleSystem, sceneOrEngine: Scene | ThinEngine, rootUrl: string) {\r\n let scene: Nullable;\r\n\r\n if (sceneOrEngine instanceof ThinEngine) {\r\n scene = null;\r\n } else {\r\n scene = sceneOrEngine as Scene;\r\n }\r\n\r\n const internalClass = GetClass(\"BABYLON.Texture\");\r\n if (internalClass && scene) {\r\n // Texture\r\n if (parsedParticleSystem.texture) {\r\n particleSystem.particleTexture = internalClass.Parse(parsedParticleSystem.texture, scene, rootUrl) as BaseTexture;\r\n } else if (parsedParticleSystem.textureName) {\r\n particleSystem.particleTexture = new internalClass(\r\n rootUrl + parsedParticleSystem.textureName,\r\n scene,\r\n false,\r\n parsedParticleSystem.invertY !== undefined ? parsedParticleSystem.invertY : true\r\n );\r\n particleSystem.particleTexture!.name = parsedParticleSystem.textureName;\r\n }\r\n }\r\n\r\n // Emitter\r\n if (!parsedParticleSystem.emitterId && parsedParticleSystem.emitterId !== 0 && parsedParticleSystem.emitter === undefined) {\r\n particleSystem.emitter = Vector3.Zero();\r\n } else if (parsedParticleSystem.emitterId && scene) {\r\n particleSystem.emitter = scene.getLastMeshById(parsedParticleSystem.emitterId);\r\n } else {\r\n particleSystem.emitter = Vector3.FromArray(parsedParticleSystem.emitter);\r\n }\r\n\r\n particleSystem.isLocal = !!parsedParticleSystem.isLocal;\r\n\r\n // Misc.\r\n if (parsedParticleSystem.renderingGroupId !== undefined) {\r\n particleSystem.renderingGroupId = parsedParticleSystem.renderingGroupId;\r\n }\r\n\r\n if (parsedParticleSystem.isBillboardBased !== undefined) {\r\n particleSystem.isBillboardBased = parsedParticleSystem.isBillboardBased;\r\n }\r\n\r\n if (parsedParticleSystem.billboardMode !== undefined) {\r\n particleSystem.billboardMode = parsedParticleSystem.billboardMode;\r\n }\r\n\r\n if (parsedParticleSystem.useLogarithmicDepth !== undefined) {\r\n particleSystem.useLogarithmicDepth = parsedParticleSystem.useLogarithmicDepth;\r\n }\r\n\r\n // Animations\r\n if (parsedParticleSystem.animations) {\r\n for (let animationIndex = 0; animationIndex < parsedParticleSystem.animations.length; animationIndex++) {\r\n const parsedAnimation = parsedParticleSystem.animations[animationIndex];\r\n const internalClass = GetClass(\"BABYLON.Animation\");\r\n if (internalClass) {\r\n particleSystem.animations.push(internalClass.Parse(parsedAnimation));\r\n }\r\n }\r\n particleSystem.beginAnimationOnStart = parsedParticleSystem.beginAnimationOnStart;\r\n particleSystem.beginAnimationFrom = parsedParticleSystem.beginAnimationFrom;\r\n particleSystem.beginAnimationTo = parsedParticleSystem.beginAnimationTo;\r\n particleSystem.beginAnimationLoop = parsedParticleSystem.beginAnimationLoop;\r\n }\r\n\r\n if (parsedParticleSystem.autoAnimate && scene) {\r\n scene.beginAnimation(\r\n particleSystem,\r\n parsedParticleSystem.autoAnimateFrom,\r\n parsedParticleSystem.autoAnimateTo,\r\n parsedParticleSystem.autoAnimateLoop,\r\n parsedParticleSystem.autoAnimateSpeed || 1.0\r\n );\r\n }\r\n\r\n // Particle system\r\n particleSystem.startDelay = parsedParticleSystem.startDelay | 0;\r\n particleSystem.minAngularSpeed = parsedParticleSystem.minAngularSpeed;\r\n particleSystem.maxAngularSpeed = parsedParticleSystem.maxAngularSpeed;\r\n particleSystem.minSize = parsedParticleSystem.minSize;\r\n particleSystem.maxSize = parsedParticleSystem.maxSize;\r\n\r\n if (parsedParticleSystem.minScaleX) {\r\n particleSystem.minScaleX = parsedParticleSystem.minScaleX;\r\n particleSystem.maxScaleX = parsedParticleSystem.maxScaleX;\r\n particleSystem.minScaleY = parsedParticleSystem.minScaleY;\r\n particleSystem.maxScaleY = parsedParticleSystem.maxScaleY;\r\n }\r\n\r\n if (parsedParticleSystem.preWarmCycles !== undefined) {\r\n particleSystem.preWarmCycles = parsedParticleSystem.preWarmCycles;\r\n particleSystem.preWarmStepOffset = parsedParticleSystem.preWarmStepOffset;\r\n }\r\n\r\n if (parsedParticleSystem.minInitialRotation !== undefined) {\r\n particleSystem.minInitialRotation = parsedParticleSystem.minInitialRotation;\r\n particleSystem.maxInitialRotation = parsedParticleSystem.maxInitialRotation;\r\n }\r\n\r\n particleSystem.minLifeTime = parsedParticleSystem.minLifeTime;\r\n particleSystem.maxLifeTime = parsedParticleSystem.maxLifeTime;\r\n particleSystem.minEmitPower = parsedParticleSystem.minEmitPower;\r\n particleSystem.maxEmitPower = parsedParticleSystem.maxEmitPower;\r\n particleSystem.emitRate = parsedParticleSystem.emitRate;\r\n particleSystem.gravity = Vector3.FromArray(parsedParticleSystem.gravity);\r\n if (parsedParticleSystem.noiseStrength) {\r\n particleSystem.noiseStrength = Vector3.FromArray(parsedParticleSystem.noiseStrength);\r\n }\r\n particleSystem.color1 = Color4.FromArray(parsedParticleSystem.color1);\r\n particleSystem.color2 = Color4.FromArray(parsedParticleSystem.color2);\r\n particleSystem.colorDead = Color4.FromArray(parsedParticleSystem.colorDead);\r\n particleSystem.updateSpeed = parsedParticleSystem.updateSpeed;\r\n particleSystem.targetStopDuration = parsedParticleSystem.targetStopDuration;\r\n particleSystem.blendMode = parsedParticleSystem.blendMode;\r\n\r\n if (parsedParticleSystem.colorGradients) {\r\n for (const colorGradient of parsedParticleSystem.colorGradients) {\r\n particleSystem.addColorGradient(\r\n colorGradient.gradient,\r\n Color4.FromArray(colorGradient.color1),\r\n colorGradient.color2 ? Color4.FromArray(colorGradient.color2) : undefined\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.rampGradients) {\r\n for (const rampGradient of parsedParticleSystem.rampGradients) {\r\n particleSystem.addRampGradient(rampGradient.gradient, Color3.FromArray(rampGradient.color));\r\n }\r\n particleSystem.useRampGradients = parsedParticleSystem.useRampGradients;\r\n }\r\n\r\n if (parsedParticleSystem.colorRemapGradients) {\r\n for (const colorRemapGradient of parsedParticleSystem.colorRemapGradients) {\r\n particleSystem.addColorRemapGradient(\r\n colorRemapGradient.gradient,\r\n colorRemapGradient.factor1 !== undefined ? colorRemapGradient.factor1 : colorRemapGradient.factor,\r\n colorRemapGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.alphaRemapGradients) {\r\n for (const alphaRemapGradient of parsedParticleSystem.alphaRemapGradients) {\r\n particleSystem.addAlphaRemapGradient(\r\n alphaRemapGradient.gradient,\r\n alphaRemapGradient.factor1 !== undefined ? alphaRemapGradient.factor1 : alphaRemapGradient.factor,\r\n alphaRemapGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.sizeGradients) {\r\n for (const sizeGradient of parsedParticleSystem.sizeGradients) {\r\n particleSystem.addSizeGradient(sizeGradient.gradient, sizeGradient.factor1 !== undefined ? sizeGradient.factor1 : sizeGradient.factor, sizeGradient.factor2);\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.angularSpeedGradients) {\r\n for (const angularSpeedGradient of parsedParticleSystem.angularSpeedGradients) {\r\n particleSystem.addAngularSpeedGradient(\r\n angularSpeedGradient.gradient,\r\n angularSpeedGradient.factor1 !== undefined ? angularSpeedGradient.factor1 : angularSpeedGradient.factor,\r\n angularSpeedGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.velocityGradients) {\r\n for (const velocityGradient of parsedParticleSystem.velocityGradients) {\r\n particleSystem.addVelocityGradient(\r\n velocityGradient.gradient,\r\n velocityGradient.factor1 !== undefined ? velocityGradient.factor1 : velocityGradient.factor,\r\n velocityGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.dragGradients) {\r\n for (const dragGradient of parsedParticleSystem.dragGradients) {\r\n particleSystem.addDragGradient(dragGradient.gradient, dragGradient.factor1 !== undefined ? dragGradient.factor1 : dragGradient.factor, dragGradient.factor2);\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.emitRateGradients) {\r\n for (const emitRateGradient of parsedParticleSystem.emitRateGradients) {\r\n particleSystem.addEmitRateGradient(\r\n emitRateGradient.gradient,\r\n emitRateGradient.factor1 !== undefined ? emitRateGradient.factor1 : emitRateGradient.factor,\r\n emitRateGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.startSizeGradients) {\r\n for (const startSizeGradient of parsedParticleSystem.startSizeGradients) {\r\n particleSystem.addStartSizeGradient(\r\n startSizeGradient.gradient,\r\n startSizeGradient.factor1 !== undefined ? startSizeGradient.factor1 : startSizeGradient.factor,\r\n startSizeGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.lifeTimeGradients) {\r\n for (const lifeTimeGradient of parsedParticleSystem.lifeTimeGradients) {\r\n particleSystem.addLifeTimeGradient(\r\n lifeTimeGradient.gradient,\r\n lifeTimeGradient.factor1 !== undefined ? lifeTimeGradient.factor1 : lifeTimeGradient.factor,\r\n lifeTimeGradient.factor2\r\n );\r\n }\r\n }\r\n\r\n if (parsedParticleSystem.limitVelocityGradients) {\r\n for (const limitVelocityGradient of parsedParticleSystem.limitVelocityGradients) {\r\n particleSystem.addLimitVelocityGradient(\r\n limitVelocityGradient.gradient,\r\n limitVelocityGradient.factor1 !== undefined ? limitVelocityGradient.factor1 : limitVelocityGradient.factor,\r\n limitVelocityGradient.factor2\r\n );\r\n }\r\n particleSystem.limitVelocityDamping = parsedParticleSystem.limitVelocityDamping;\r\n }\r\n\r\n if (parsedParticleSystem.noiseTexture && scene) {\r\n const internalClass = GetClass(\"BABYLON.ProceduralTexture\");\r\n particleSystem.noiseTexture = internalClass.Parse(parsedParticleSystem.noiseTexture, scene, rootUrl);\r\n }\r\n\r\n // Emitter\r\n let emitterType: IParticleEmitterType;\r\n if (parsedParticleSystem.particleEmitterType) {\r\n switch (parsedParticleSystem.particleEmitterType.type) {\r\n case \"SphereParticleEmitter\":\r\n emitterType = new SphereParticleEmitter();\r\n break;\r\n case \"SphereDirectedParticleEmitter\":\r\n emitterType = new SphereDirectedParticleEmitter();\r\n break;\r\n case \"ConeEmitter\":\r\n case \"ConeParticleEmitter\":\r\n emitterType = new ConeParticleEmitter();\r\n break;\r\n case \"CylinderParticleEmitter\":\r\n emitterType = new CylinderParticleEmitter();\r\n break;\r\n case \"CylinderDirectedParticleEmitter\":\r\n emitterType = new CylinderDirectedParticleEmitter();\r\n break;\r\n case \"HemisphericParticleEmitter\":\r\n emitterType = new HemisphericParticleEmitter();\r\n break;\r\n case \"PointParticleEmitter\":\r\n emitterType = new PointParticleEmitter();\r\n break;\r\n case \"MeshParticleEmitter\":\r\n emitterType = new MeshParticleEmitter();\r\n break;\r\n case \"BoxEmitter\":\r\n case \"BoxParticleEmitter\":\r\n default:\r\n emitterType = new BoxParticleEmitter();\r\n break;\r\n }\r\n\r\n emitterType.parse(parsedParticleSystem.particleEmitterType, scene);\r\n } else {\r\n emitterType = new BoxParticleEmitter();\r\n emitterType.parse(parsedParticleSystem, scene);\r\n }\r\n particleSystem.particleEmitterType = emitterType;\r\n\r\n // Animation sheet\r\n particleSystem.startSpriteCellID = parsedParticleSystem.startSpriteCellID;\r\n particleSystem.endSpriteCellID = parsedParticleSystem.endSpriteCellID;\r\n particleSystem.spriteCellLoop = parsedParticleSystem.spriteCellLoop ?? true;\r\n particleSystem.spriteCellWidth = parsedParticleSystem.spriteCellWidth;\r\n particleSystem.spriteCellHeight = parsedParticleSystem.spriteCellHeight;\r\n particleSystem.spriteCellChangeSpeed = parsedParticleSystem.spriteCellChangeSpeed;\r\n particleSystem.spriteRandomStartCell = parsedParticleSystem.spriteRandomStartCell;\r\n\r\n particleSystem.disposeOnStop = parsedParticleSystem.disposeOnStop ?? false;\r\n particleSystem.manualEmitCount = parsedParticleSystem.manualEmitCount ?? -1;\r\n }\r\n\r\n /**\r\n * Parses a JSON object to create a particle system.\r\n * @param parsedParticleSystem The JSON object to parse\r\n * @param sceneOrEngine The scene or the engine to create the particle system in\r\n * @param rootUrl The root url to use to load external dependencies like texture\r\n * @param doNotStart Ignore the preventAutoStart attribute and does not start\r\n * @param capacity defines the system capacity (if null or undefined the sotred capacity will be used)\r\n * @returns the Parsed particle system\r\n */\r\n public static Parse(parsedParticleSystem: any, sceneOrEngine: Scene | ThinEngine, rootUrl: string, doNotStart = false, capacity?: number): ParticleSystem {\r\n const name = parsedParticleSystem.name;\r\n let custom: Nullable = null;\r\n let program: any = null;\r\n let engine: ThinEngine;\r\n let scene: Nullable;\r\n\r\n if (sceneOrEngine instanceof ThinEngine) {\r\n engine = sceneOrEngine;\r\n } else {\r\n scene = sceneOrEngine as Scene;\r\n engine = scene.getEngine();\r\n }\r\n\r\n if (parsedParticleSystem.customShader && (engine as any).createEffectForParticles) {\r\n program = parsedParticleSystem.customShader;\r\n const defines: string = program.shaderOptions.defines.length > 0 ? program.shaderOptions.defines.join(\"\\n\") : \"\";\r\n custom = (engine as any).createEffectForParticles(program.shaderPath.fragmentElement, program.shaderOptions.uniforms, program.shaderOptions.samplers, defines);\r\n }\r\n const particleSystem = new ParticleSystem(name, capacity || parsedParticleSystem.capacity, sceneOrEngine, custom, parsedParticleSystem.isAnimationSheetEnabled);\r\n particleSystem.customShader = program;\r\n particleSystem._rootUrl = rootUrl;\r\n\r\n if (parsedParticleSystem.id) {\r\n particleSystem.id = parsedParticleSystem.id;\r\n }\r\n\r\n // SubEmitters\r\n if (parsedParticleSystem.subEmitters) {\r\n particleSystem.subEmitters = [];\r\n for (const cell of parsedParticleSystem.subEmitters) {\r\n const cellArray = [];\r\n for (const sub of cell) {\r\n cellArray.push(SubEmitter.Parse(sub, sceneOrEngine, rootUrl));\r\n }\r\n\r\n particleSystem.subEmitters.push(cellArray);\r\n }\r\n }\r\n\r\n ParticleSystem._Parse(parsedParticleSystem, particleSystem, sceneOrEngine, rootUrl);\r\n\r\n if (parsedParticleSystem.textureMask) {\r\n particleSystem.textureMask = Color4.FromArray(parsedParticleSystem.textureMask);\r\n }\r\n\r\n // Auto start\r\n if (parsedParticleSystem.preventAutoStart) {\r\n particleSystem.preventAutoStart = parsedParticleSystem.preventAutoStart;\r\n }\r\n\r\n if (!doNotStart && !particleSystem.preventAutoStart) {\r\n particleSystem.start();\r\n }\r\n\r\n return particleSystem;\r\n }\r\n}\r\n\r\nSubEmitter._ParseParticleSystem = ParticleSystem.Parse;\r\n","import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';\r\nimport { RawTexture } from '@babylonjs/core/Materials/Textures/rawTexture';\r\nimport { Color4, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Logger } from '@babylonjs/core/Misc/logger';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { ParticleSystem } from '@babylonjs/core/Particles/particleSystem';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { FloatArray, Nullable } from '@babylonjs/core/types';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { getCameraPositionWithOffset } from '@view/helpers/math-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subject } from 'rxjs';\r\nimport { takeUntil } from 'rxjs/operators';\r\nimport { eMarqueeSelectMode } from '../interaction';\r\nimport { KbGizmo } from './gizmo';\r\n\r\nexport interface VertexChanges {\r\n mesh: AbstractMesh;\r\n delta: Vector3;\r\n vertexIndices: number[];\r\n}\r\n\r\n/**\r\n * Gizmo that enables moving vertices on a mesh.\r\n */\r\nexport class KbVertexSelectGizmo extends KbGizmo {\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n public onSelectionChange = new Observable<{ selectedIndices: number[] }>();\r\n public vertexTracker = new Subject();\r\n public particleScale = 0.005;\r\n public get attachedMesh() {\r\n return this.__attachedMesh;\r\n }\r\n\r\n public set attachedMesh(mesh: Nullable) {\r\n this.__attachedMesh = mesh;\r\n if (this.particleSystem) {\r\n this.particleSystem.dispose();\r\n this.particleSystem = undefined;\r\n }\r\n if (mesh) {\r\n this.drawVertices(mesh);\r\n }\r\n }\r\n\r\n private verticesUtilLayer: UtilityLayerRenderer;\r\n private particleSystem?: ParticleSystem;\r\n private currentMeshVertexPositions?: FloatArray;\r\n private redrawVertices = false;\r\n private selectionsEnabled: boolean;\r\n private disposeMarquee: Subject;\r\n private saveAnimate: (() => void) | undefined;\r\n\r\n private __attachedMesh: Nullable = null;\r\n private selectedVertices = new Map();\r\n\r\n readonly vertexSelectedColor = new Color4(0.4, 1, 0, 0.5);\r\n readonly vertexUnSelectedColor = new Color4(0, 0.2, 1, 0.5);\r\n readonly vertexTransparentColor = new Color4(0, 0, 0, 0);\r\n\r\n constructor(private kbViewer: KbViewer, private scene: Scene) {\r\n super(kbViewer.utilityLayer);\r\n this.verticesUtilLayer = kbViewer.utilityLayer;\r\n this.attachedMesh = null;\r\n }\r\n\r\n attachTo(target: MeshNode) {\r\n const mesh = this.kbViewer.getRendererNode(target);\r\n if (!mesh) {\r\n throw Error('Could not find mesh in scene to attach gizmo');\r\n }\r\n this.attachedMesh = mesh as Mesh;\r\n\r\n // Clean up old marquee\r\n if (this.disposeMarquee) {\r\n this.disposeMarquee.next();\r\n this.disposeMarquee.complete();\r\n }\r\n\r\n this.disposeMarquee = new Subject();\r\n let selectionMode: null | 'new' | 'add' | 'remove' = null;\r\n\r\n this.kbViewer.interaction\r\n .enableMarqueeSelect(target, eMarqueeSelectMode.Vertices)\r\n .pipe(takeUntil(this.disposeMarquee))\r\n .subscribe(event => {\r\n if (selectionMode || event.vertexList.length > 0) {\r\n const vertices = event.vertexList;\r\n\r\n // If user is making a new selection, set the selection mode based on modifier keys\r\n if (selectionMode === null) {\r\n if (event.ctrlKey) {\r\n selectionMode = 'add';\r\n } else if (event.altKey) {\r\n selectionMode = 'remove';\r\n } else {\r\n selectionMode = 'new';\r\n }\r\n }\r\n\r\n if (selectionMode === 'new') {\r\n this.selectedVertices.clear();\r\n }\r\n if (selectionMode === 'remove') {\r\n vertices.forEach(vertex => this.selectedVertices.delete(vertex));\r\n } else {\r\n vertices.forEach(vertex => this.selectedVertices.set(vertex, null));\r\n }\r\n this.redraw();\r\n this.emitSelectionChange();\r\n }\r\n });\r\n\r\n this.kbViewer.interaction.onPointerUp.pipe(takeUntil(this.disposeMarquee)).subscribe(() => {\r\n selectionMode = null;\r\n });\r\n }\r\n\r\n updateParticleScale(scale: number) {\r\n this.particleScale = scale;\r\n this.redraw();\r\n }\r\n\r\n updateGizmoPosition() {\r\n this.kbViewer.forceAndWaitForNextRender().then(() => {\r\n if (this.__attachedMesh) {\r\n this.currentMeshVertexPositions = this.__attachedMesh\r\n .getVerticesData(VertexBuffer.PositionKind)\r\n ?.slice() as any;\r\n if (!this.currentMeshVertexPositions) {\r\n return;\r\n }\r\n this.redraw();\r\n }\r\n });\r\n }\r\n\r\n dispose() {\r\n if (this.particleSystem) {\r\n this.particleSystem.dispose();\r\n this.particleSystem = undefined;\r\n }\r\n this.disposeMarquee.next();\r\n this.disposeMarquee.complete();\r\n this.kbViewer.interaction.disableMarqueeSelect();\r\n }\r\n\r\n setCustomMesh(mesh: Mesh) {\r\n Logger.Error('Custom meshes are not supported on this gizmo.');\r\n }\r\n\r\n selectVertices(vertexIndices: number[]) {\r\n this.selectedVertices.clear();\r\n vertexIndices.forEach(vertex => this.selectedVertices.set(vertex, null));\r\n this.redraw();\r\n this.emitSelectionChange();\r\n }\r\n\r\n enableSelectionChange() {\r\n this.selectionsEnabled = true;\r\n this.redraw();\r\n }\r\n\r\n disableSelectionChange() {\r\n this.selectionsEnabled = false;\r\n this.redraw();\r\n this.vertexTracker.complete();\r\n }\r\n\r\n getBarycenter(indices: number[]) {\r\n let x = 0,\r\n y = 0,\r\n z = 0;\r\n const currentMeshVertexPositions = this.currentMeshVertexPositions;\r\n\r\n if (currentMeshVertexPositions) {\r\n indices.forEach(idx => {\r\n x += currentMeshVertexPositions[idx * 3];\r\n y += currentMeshVertexPositions[idx * 3 + 1];\r\n z += currentMeshVertexPositions[idx * 3 + 2];\r\n });\r\n }\r\n\r\n return new KbVector(x / indices.length, y / indices.length, z / indices.length);\r\n }\r\n\r\n private redraw() {\r\n this.vertexTracker.next(this.selectedVertices.size.toString());\r\n if (this.particleSystem && this.saveAnimate) {\r\n this.particleSystem.animate = this.saveAnimate;\r\n this.redrawVertices = true;\r\n }\r\n }\r\n\r\n private emitSelectionChange() {\r\n this.onSelectionChange.notifyObservers({ selectedIndices: Array.from(this.selectedVertices.keys()) });\r\n }\r\n\r\n private drawVertices(targetMesh: AbstractMesh) {\r\n if (!this.currentMeshVertexPositions) {\r\n this.currentMeshVertexPositions = targetMesh.getVerticesData(VertexBuffer.PositionKind)?.slice();\r\n }\r\n if (!this.currentMeshVertexPositions) {\r\n return;\r\n }\r\n\r\n const vertexCount = this.currentMeshVertexPositions.length / 3;\r\n this.particleSystem = new ParticleSystem(\r\n 'vertexSelectParticleSystem',\r\n vertexCount,\r\n this.verticesUtilLayer.utilityLayerScene\r\n );\r\n\r\n const camera = this.scene.activeCamera instanceof ArcRotateCamera ? this.scene.activeCamera : null;\r\n const cameraDistance = Vector3.Zero();\r\n const cameraPosition = Vector3.Zero();\r\n this.saveAnimate = this.particleSystem.animate.bind(this.particleSystem);\r\n\r\n let particleIdx = 0;\r\n this.particleSystem.startPositionFunction = (worldMatrix, positionToUpdate, particle) => {\r\n particleIdx += 3;\r\n const vertexPositions = this.currentMeshVertexPositions!;\r\n Vector3.TransformCoordinatesFromFloatsToRef(\r\n vertexPositions[particleIdx],\r\n vertexPositions[particleIdx + 1],\r\n vertexPositions[particleIdx + 2],\r\n worldMatrix,\r\n positionToUpdate\r\n );\r\n };\r\n const transform = targetMesh.computeWorldMatrix(true);\r\n\r\n this.particleSystem.updateFunction = particles => {\r\n let particlesToProcess = false;\r\n if (camera) {\r\n cameraPosition.copyFrom(getCameraPositionWithOffset(camera));\r\n }\r\n\r\n for (let i = 0; i < particles.length; i++) {\r\n const particle = particles[i];\r\n const vertexPositions = this.currentMeshVertexPositions;\r\n\r\n if (vertexPositions && (particle.age === 0 || this.redrawVertices)) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(\r\n vertexPositions[i * 3],\r\n vertexPositions[i * 3 + 1],\r\n vertexPositions[i * 3 + 2],\r\n transform,\r\n particle.position\r\n );\r\n particle.age = 1;\r\n if (this.selectedVertices.has(i)) {\r\n particle.color = this.vertexSelectedColor;\r\n } else {\r\n if (this.selectionsEnabled) {\r\n particle.color = this.vertexUnSelectedColor;\r\n } else {\r\n particle.color = this.vertexTransparentColor;\r\n }\r\n }\r\n if (!particlesToProcess) {\r\n particlesToProcess = true;\r\n }\r\n }\r\n\r\n if (camera) {\r\n cameraPosition.subtractToRef(particle.position, cameraDistance);\r\n particle.size = (this.particleScale - 0.001) * cameraDistance.length();\r\n } else {\r\n particle.size = this.particleScale - 0.004;\r\n }\r\n }\r\n\r\n this.redrawVertices = false;\r\n // If there are a large number of particles, kill the updating function for performance\r\n if (particles.length && particles.length > 10000 && !particlesToProcess && this.particleSystem) {\r\n // stable\r\n this.particleSystem.stop();\r\n this.particleSystem.animate = () => void 0;\r\n }\r\n };\r\n\r\n const colorArray = new Uint8Array(3);\r\n for (let i = 0; i < colorArray.length; i += 3) {\r\n colorArray[i] = 225;\r\n colorArray[i + 1] = 225;\r\n colorArray[i + 2] = 225;\r\n }\r\n\r\n this.particleSystem.emitter = targetMesh;\r\n this.particleSystem.minSize = this.particleScale;\r\n this.particleSystem.maxSize = this.particleScale;\r\n this.particleSystem.disposeOnStop = false;\r\n this.particleSystem.particleTexture = RawTexture.CreateRGBTexture(\r\n colorArray,\r\n 1,\r\n 1,\r\n this.verticesUtilLayer.utilityLayerScene\r\n );\r\n this.particleSystem.manualEmitCount = vertexCount;\r\n // this.particleSystem.emitRate\r\n this.particleSystem.start();\r\n }\r\n}\r\n","import { Quaternion, Vector3 } from '@babylonjs/core/Maths/math';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Observable } from '@babylonjs/core/Misc/observable';\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { eViewpointTargetMode, eViewpointType } from '@models/classes/enums';\r\nimport { MeshNode } from '@models/classes/meshes';\r\nimport { ViewpointNode } from '@models/classes/viewpoints';\r\nimport { rotationToVector } from '@view/helpers/math-helper';\r\nimport { createViewpointVisualization } from '@view/helpers/viewpoint-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { KbGizmo } from './gizmo';\r\nimport { KbPositionGizmo } from './position-gizmo';\r\nimport { KbRotationGizmo } from './rotation-gizmo';\r\n\r\n/**\r\n * Gizmo that enables dragging and rotating lights\r\n */\r\nexport class KbViewpointGizmo extends KbGizmo {\r\n posGizmo: KbPositionGizmo | undefined;\r\n targetGizmo: KbPositionGizmo | undefined;\r\n rotGizmo: KbRotationGizmo | undefined;\r\n\r\n _attachedViewpoint: ViewpointNode | undefined;\r\n _gizmoMesh: AbstractMesh | undefined;\r\n _visualMesh: AbstractMesh | undefined;\r\n _targetVisualMesh: AbstractMesh | undefined;\r\n\r\n viewpointPositionGizmo: Mesh | undefined;\r\n\r\n /** Fires an event when any of it's sub gizmos are dragged */\r\n onDragStartObservable = new Observable();\r\n /** Fires an event while any of it's sub gizmos are dragged */\r\n onDragObservable = new Observable<{ deltaPos?: Vector3; deltaTargetPos?: Vector3; deltaRotation?: Quaternion }>();\r\n /** Fires an event when any of it's sub gizmos are released from dragging */\r\n onDragEndObservable = new Observable<{\r\n deltaPos?: Vector3;\r\n deltaTargetPos?: Vector3;\r\n deltaRotation?: Quaternion;\r\n }>();\r\n\r\n previousTargetMode?: eViewpointTargetMode;\r\n\r\n attachTo(viewpoint: ViewpointNode) {\r\n // Get rid of any old gizmos\r\n if (this.posGizmo) {\r\n this.posGizmo.dispose();\r\n this.posGizmo = undefined;\r\n }\r\n if (this.targetGizmo) {\r\n this.targetGizmo.dispose();\r\n this.targetGizmo = undefined;\r\n }\r\n if (this.rotGizmo) {\r\n this.rotGizmo.dispose();\r\n this.rotGizmo = undefined;\r\n }\r\n\r\n // Create mesh to attach gizmos to, and the camera preview visualization attached to that mesh\r\n this._visualMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene);\r\n const { targetPositionMarker, viewpointPositionGizmo } = createViewpointVisualization(\r\n viewpoint,\r\n this.gizmoLayer.utilityLayerScene\r\n );\r\n this._visualMesh.addChild(viewpointPositionGizmo);\r\n\r\n // Always create the position gizmo\r\n this.posGizmo = new KbPositionGizmo(this.kbViewer, this.gizmoLayer);\r\n this.previousTargetMode = viewpoint.targetMode;\r\n\r\n // Determine which gizmos to show. No extra gizmos for overhead camera (only position)\r\n // For the target point type viewpoint, make a separate mesh to hold the position gizmo\r\n if (viewpoint.type === eViewpointType.overhead) {\r\n viewpointPositionGizmo.scaling = new Vector3(1, -1, 1);\r\n viewpointPositionGizmo.bakeCurrentTransformIntoVertices();\r\n } else {\r\n if (viewpoint.targetMode === eViewpointTargetMode.rotation) {\r\n this.rotGizmo = new KbRotationGizmo(this.kbViewer, this.gizmoLayer, { x: true, y: true, z: false });\r\n\r\n // The first person camera is oriented pointing parallel to the +Z axis\r\n if (viewpoint.type == eViewpointType.firstPerson) {\r\n viewpointPositionGizmo.rotate(Vector3.Right(), Math.PI / 2);\r\n viewpointPositionGizmo.bakeCurrentTransformIntoVertices();\r\n }\r\n } else if (viewpoint.targetMode === eViewpointTargetMode.point) {\r\n this._gizmoMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene);\r\n this._targetVisualMesh = new AbstractMesh('', this.gizmoLayer.utilityLayerScene);\r\n if (targetPositionMarker) {\r\n this._targetVisualMesh?.addChild(targetPositionMarker);\r\n }\r\n this.targetGizmo = new KbPositionGizmo(this.kbViewer, this.gizmoLayer);\r\n }\r\n }\r\n if (!this._gizmoMesh) {\r\n this._gizmoMesh = this._visualMesh;\r\n } else {\r\n this._visualMesh.isPickable = false;\r\n }\r\n\r\n this.updateHelperMeshes(viewpoint);\r\n\r\n // Set up event handlers on the gizmos\r\n if (this.posGizmo) {\r\n this.posGizmo.attachedMesh = this._gizmoMesh;\r\n const positionChange = Vector3.Zero();\r\n this.posGizmo.onDragStartObservable.add(event => {\r\n positionChange.setAll(0);\r\n this.onDragStartObservable.notifyObservers();\r\n });\r\n this.posGizmo.onDragObservable.add(event => {\r\n if (this._gizmoMesh !== this._visualMesh) {\r\n this._visualMesh?.position.addInPlace(event.delta);\r\n }\r\n\r\n positionChange.addInPlace(event.delta);\r\n this.onDragObservable.notifyObservers({ deltaPos: event.delta });\r\n this.updateHelperMeshDirectionToRotation(this._attachedViewpoint!);\r\n });\r\n this.posGizmo.onDragEndObservable.add(event => {\r\n this.onDragEndObservable.notifyObservers({ deltaPos: positionChange });\r\n });\r\n }\r\n if (this.targetGizmo) {\r\n this.targetGizmo.attachedMesh = this._targetVisualMesh!;\r\n const targetChange = Vector3.Zero();\r\n this.targetGizmo.onDragStartObservable.add(event => {\r\n targetChange.setAll(0);\r\n this.onDragStartObservable.notifyObservers();\r\n });\r\n this.targetGizmo.onDragObservable.add(event => {\r\n targetChange.addInPlace(event.delta);\r\n this.onDragObservable.notifyObservers({ deltaTargetPos: event.delta });\r\n this.updateHelperMeshDirectionToRotation(this._attachedViewpoint!);\r\n });\r\n this.targetGizmo.onDragEndObservable.add(event => {\r\n this.onDragEndObservable.notifyObservers({ deltaTargetPos: targetChange });\r\n });\r\n }\r\n if (this.rotGizmo) {\r\n this.rotGizmo.attachedMesh = this._visualMesh;\r\n let rotationChange = this._visualMesh.rotationQuaternion || Quaternion.Identity();\r\n this.rotGizmo.onDragStartObservable.add(event => {\r\n this.onDragStartObservable.notifyObservers();\r\n rotationChange = Quaternion.Identity();\r\n });\r\n this.rotGizmo.onDragObservable.add(event => {\r\n const { delta } = event;\r\n rotationChange.multiplyInPlace(delta);\r\n this.onDragObservable.notifyObservers({ deltaRotation: delta });\r\n });\r\n this.rotGizmo.onDragEndObservable.add(() => {\r\n this.onDragEndObservable.notifyObservers({ deltaRotation: rotationChange });\r\n });\r\n }\r\n\r\n this._attachedViewpoint = viewpoint;\r\n }\r\n\r\n updateGizmoPosition(viewpointNode?: ViewpointNode) {\r\n if (viewpointNode && viewpointNode !== this._attachedViewpoint) {\r\n this._attachedViewpoint = viewpointNode;\r\n }\r\n\r\n // If the target mode changed, rebuild the gizmo\r\n if (this._attachedViewpoint && this.previousTargetMode !== this._attachedViewpoint.targetMode) {\r\n const viewpoint = this._attachedViewpoint;\r\n this.dispose(true);\r\n this.attachTo(viewpoint);\r\n } else {\r\n if (this._attachedViewpoint) {\r\n this.updateHelperMeshes(this._attachedViewpoint);\r\n }\r\n super.updateGizmoPosition();\r\n }\r\n }\r\n\r\n private updateHelperMeshes(viewpoint: ViewpointNode) {\r\n if (!this._visualMesh || !this._gizmoMesh) {\r\n return;\r\n }\r\n this._visualMesh.position = viewpoint.position.toVec3();\r\n this._gizmoMesh.position = viewpoint.position.toVec3();\r\n\r\n if (this._targetVisualMesh) {\r\n this._targetVisualMesh.position = viewpoint.targetPoint.toVec3();\r\n }\r\n\r\n if (viewpoint.targetMode === eViewpointTargetMode.rotation) {\r\n const eulerRot = viewpoint.rotation.toVec3().scale(Math.PI / 180);\r\n this._visualMesh.rotationQuaternion = Quaternion.FromEulerVector(eulerRot);\r\n } else {\r\n this.updateHelperMeshDirectionToRotation(viewpoint);\r\n }\r\n }\r\n\r\n private updateHelperMeshDirectionToRotation(viewpoint: ViewpointNode, delta?: Vector3) {\r\n if (!this._visualMesh) {\r\n return;\r\n }\r\n if (!delta) {\r\n delta = Vector3.Zero();\r\n }\r\n const _visualMesh = this._visualMesh;\r\n\r\n if (viewpoint.targetMode !== eViewpointTargetMode.rotation) {\r\n let direction: Vector3;\r\n\r\n if (this._targetVisualMesh) {\r\n direction = this._targetVisualMesh.position.subtract(_visualMesh.position);\r\n } else {\r\n // mesh\r\n const targetMeshNode = viewpoint._manager!.getById(viewpoint.targetMeshId!) as MeshNode;\r\n if (targetMeshNode) {\r\n direction = targetMeshNode.position.subtract(viewpoint.position).toVec3();\r\n } else {\r\n direction = Vector3.Zero();\r\n }\r\n }\r\n const rotation = rotationToVector(direction);\r\n _visualMesh.rotationQuaternion = rotation;\r\n\r\n // This code is for fixing the rotation of the camera gizmo so that the x axis is always in the XZ plane (keeping the camera model level with the horizon.)\r\n // But, it is not working quite right.\r\n // _visualMesh.computeWorldMatrix(true);\r\n // let newXAxis = _visualMesh.getDirection(Vector3.Right());\r\n // const correction = rotationToVector(direction.cross(Vector3.Up()), newXAxis);\r\n // _visualMesh.rotationQuaternion = _visualMesh.rotationQuaternion.multiply(correction);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a PositionGizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n */\r\n constructor(\r\n private kbViewer: KbViewer,\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer\r\n ) {\r\n super(gizmoLayer);\r\n\r\n this.attachedMesh = null;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n dispose(recreate?: boolean) {\r\n if (this.posGizmo) {\r\n this.posGizmo.dispose();\r\n }\r\n if (this.rotGizmo) {\r\n this.rotGizmo.dispose();\r\n }\r\n if (this.targetGizmo) {\r\n this.targetGizmo.dispose();\r\n }\r\n if (this._visualMesh) {\r\n this._visualMesh.dispose();\r\n }\r\n if (this._targetVisualMesh) {\r\n this._targetVisualMesh.dispose();\r\n }\r\n if (this.viewpointPositionGizmo) {\r\n this.viewpointPositionGizmo.dispose();\r\n }\r\n if (!recreate) {\r\n this.onDragStartObservable.clear();\r\n this.onDragEndObservable.clear();\r\n delete this._attachedViewpoint;\r\n }\r\n }\r\n}\r\n","import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { Texture } from '@babylonjs/core/Materials/Textures/texture';\r\nimport { Material } from '@babylonjs/core/Materials/material';\r\nimport { Color3, Matrix, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport '@babylonjs/core/Rendering/boundingBoxRenderer'; // Required by mesh bounding box feature\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { UvMapFeature } from '@models/classes';\r\nimport { IVertexGroup } from '@models/classes/kb3d-models';\r\nimport { LightNode } from '@models/classes/lights/light-node';\r\nimport { MeshNode, SpaceNode } from '@models/classes/meshes';\r\nimport { KbQuaternion } from '@models/classes/primitives/kb-quaternion';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { ViewpointNode } from '@models/classes/viewpoints';\r\nimport { KbViewer } from '@view/kb-viewer';\r\nimport { Subject } from 'rxjs';\r\nimport { KbAxisAngleGizmo } from './gizmos/axis-angle-gizmo';\r\nimport { KbFacetSelectGizmo } from './gizmos/facet-select-gizmo';\r\nimport { KbGizmo } from './gizmos/gizmo';\r\nimport { KbLightGizmo } from './gizmos/light-gizmo';\r\nimport { KbPositionGizmo } from './gizmos/position-gizmo';\r\nimport { KbRotationGizmo } from './gizmos/rotation-gizmo';\r\nimport { KbScaleGizmo } from './gizmos/scale-gizmo';\r\nimport { KbVertexSelectGizmo } from './gizmos/vertex-select-gizmo';\r\nimport { KbViewpointGizmo } from './gizmos/viewpoint-gizmo';\r\n\r\ninterface GizmoInfo {\r\n subjects: Array>;\r\n gizmo: KbGizmo;\r\n}\r\n\r\n/**\r\n * Manages the various gizmos and their connections to the scene meshes.\r\n * Keeps track of what gizmo is active and the selected meshes to put the gizmos on.\r\n * @param scene The root scene on which the utility/gizmo layer will be placed.\r\n * @param camera The camera being used. Required by some gizmos for displaying them correctly\r\n */\r\nconst PREVIEW_NAME = '__UV_PREVIEW_MATERIAL__';\r\nexport class GizmoTools {\r\n activeGizmoSettings: GizmoInfo[] = [];\r\n dragging = false;\r\n uvMapStoredMaterials = new Map();\r\n private scene: Scene;\r\n private gizmoLayer: UtilityLayerRenderer;\r\n private previewMaterial: PBRMaterial | undefined;\r\n\r\n constructor(scene: Scene, private kbViewer: KbViewer) {\r\n this.scene = scene;\r\n this.gizmoLayer = kbViewer.utilityLayer;\r\n this.gizmoLayer.utilityLayerScene.useRightHandedSystem = true;\r\n }\r\n\r\n selectLight(lightNode: LightNode) {\r\n const lightGizmo = new KbLightGizmo(this.kbViewer, this.gizmoLayer);\r\n\r\n const updatePosition = new Subject();\r\n const updateDirection = new Subject();\r\n const totalDeltaPosition = new Subject();\r\n this.activeGizmoSettings.push({\r\n subjects: [updatePosition, updateDirection, totalDeltaPosition],\r\n gizmo: lightGizmo,\r\n });\r\n\r\n lightGizmo.attachTo(lightNode);\r\n this.dragging = false;\r\n\r\n return {\r\n updateLightGizmo: (node: LightNode) => {\r\n lightGizmo.updateGizmoPosition(node);\r\n },\r\n };\r\n }\r\n\r\n selectViewpoint(viewpoint: ViewpointNode) {\r\n const viewpointGizmo = new KbViewpointGizmo(this.kbViewer, this.gizmoLayer);\r\n viewpointGizmo.attachTo(viewpoint);\r\n\r\n const updatePosition = new Subject();\r\n const updateTargetPosition = new Subject();\r\n const updateRotation = new Subject();\r\n const totalDeltaPosition = new Subject();\r\n const totalDeltaTargetPosition = new Subject();\r\n const totalDeltaRotation = new Subject();\r\n this.activeGizmoSettings.push({\r\n subjects: [\r\n updatePosition,\r\n updateTargetPosition,\r\n updateRotation,\r\n totalDeltaPosition,\r\n totalDeltaTargetPosition,\r\n totalDeltaRotation,\r\n ],\r\n gizmo: viewpointGizmo,\r\n });\r\n\r\n this.dragging = false;\r\n const totalDeltaPositionQueue = Vector3.Zero();\r\n const totalDeltaTargetPositionQueue = Vector3.Zero();\r\n const totalDeltaRotationQueue = Quaternion.Identity();\r\n\r\n viewpointGizmo.onDragStartObservable.add(() => {\r\n this.dragging = true;\r\n });\r\n viewpointGizmo.onDragObservable.add(event => {\r\n if (this.dragging) {\r\n if (event.deltaPos) {\r\n updatePosition.next(KbVector.FromVec3(event.deltaPos));\r\n totalDeltaPositionQueue.addInPlace(event.deltaPos);\r\n }\r\n if (event.deltaTargetPos) {\r\n updateTargetPosition.next(KbVector.FromVec3(event.deltaTargetPos));\r\n totalDeltaTargetPositionQueue.addInPlace(event.deltaTargetPos);\r\n }\r\n if (event.deltaRotation) {\r\n updateRotation.next(KbVector.FromVec3(event.deltaRotation.toEulerAngles().scale(180 / Math.PI)));\r\n totalDeltaRotationQueue.multiplyInPlace(event.deltaRotation);\r\n }\r\n }\r\n });\r\n viewpointGizmo.onDragEndObservable.add(() => {\r\n if (this.dragging) {\r\n this.dragging = false;\r\n if (!totalDeltaPositionQueue.equalsToFloats(0, 0, 0)) {\r\n totalDeltaPosition.next(KbVector.FromVec3(totalDeltaPositionQueue));\r\n totalDeltaPositionQueue.setAll(0);\r\n } else if (!totalDeltaTargetPositionQueue.equalsToFloats(0, 0, 0)) {\r\n totalDeltaTargetPosition.next(KbVector.FromVec3(totalDeltaTargetPositionQueue));\r\n totalDeltaTargetPositionQueue.setAll(0);\r\n } else if (!totalDeltaRotationQueue.equals(Quaternion.Identity())) {\r\n totalDeltaRotation.next(\r\n KbVector.FromVec3(totalDeltaRotationQueue.toEulerAngles().scale(180 / Math.PI))\r\n );\r\n totalDeltaRotationQueue.copyFrom(Quaternion.Identity());\r\n }\r\n }\r\n });\r\n\r\n return {\r\n updatePosition: updatePosition.asObservable(),\r\n updateTargetPosition: updateTargetPosition.asObservable(),\r\n updateRotation: updateRotation.asObservable(),\r\n totalDeltaPosition: totalDeltaPosition.asObservable(),\r\n totalDeltaTargetPosition: totalDeltaTargetPosition.asObservable(),\r\n totalDeltaRotation: totalDeltaRotation.asObservable(),\r\n updateViewpointGizmo: (node: ViewpointNode) => {\r\n viewpointGizmo.updateGizmoPosition(node);\r\n },\r\n };\r\n }\r\n\r\n position(\r\n target: SpaceNode | KbVector,\r\n positionSpace?: SpaceNode,\r\n axisVisibility?: [boolean, boolean, boolean],\r\n orientGizmo?: Quaternion\r\n ) {\r\n const positionGizmo = new KbPositionGizmo(this.kbViewer, this.gizmoLayer, axisVisibility);\r\n positionGizmo.attachTo(target, positionSpace, orientGizmo);\r\n\r\n const updatePosition = new Subject();\r\n const totalDelta = new Subject();\r\n this.activeGizmoSettings.push({\r\n subjects: [updatePosition, totalDelta],\r\n gizmo: positionGizmo,\r\n });\r\n this.dragging = false;\r\n let totalDeltaQueue = Vector3.Zero();\r\n\r\n positionGizmo.onDragStartObservable.add(() => {\r\n this.dragging = true;\r\n });\r\n positionGizmo.onDragObservable.add(event => {\r\n if (this.dragging) {\r\n totalDeltaQueue.addInPlace(event.delta);\r\n updatePosition.next(KbVector.FromVec3(event.delta));\r\n }\r\n });\r\n positionGizmo.onDragEndObservable.add(() => {\r\n if (this.dragging) {\r\n totalDelta.next(KbVector.FromVec3(totalDeltaQueue));\r\n totalDeltaQueue = Vector3.Zero();\r\n this.dragging = false;\r\n }\r\n });\r\n\r\n return {\r\n update: updatePosition.asObservable(),\r\n totalDelta: totalDelta.asObservable(),\r\n updateGizmoPosition: (update?: KbVector) => positionGizmo.updateGizmoPosition(update),\r\n dispose: () => this.clearGizmo(positionGizmo),\r\n };\r\n }\r\n\r\n rotateAxisAngle(\r\n target: KbVector,\r\n positionSpace?: SpaceNode,\r\n options?: { placementOffset?: KbVector; disableAngle?: boolean }\r\n ) {\r\n const updateAxisAngle = new Subject<{ axis: KbVector; angle: number }>();\r\n const totalDelta = new Subject<{ axis: KbVector; angle: number }>();\r\n const totalDeltaQueue = { axis: Vector3.Zero(), angle: 0 };\r\n\r\n const axisAngleGizmo = new KbAxisAngleGizmo(this.kbViewer, this.gizmoLayer, options?.disableAngle);\r\n axisAngleGizmo.attachTo(target, positionSpace, options?.placementOffset);\r\n\r\n this.activeGizmoSettings.push({\r\n subjects: [updateAxisAngle, totalDelta],\r\n gizmo: axisAngleGizmo,\r\n });\r\n this.dragging = false;\r\n\r\n axisAngleGizmo.onDragStartObservable.add(() => {\r\n this.dragging = true;\r\n });\r\n axisAngleGizmo.onDragObservable.add(event => {\r\n if (this.dragging) {\r\n const angle = (event.deltaAngle * 180) / Math.PI;\r\n totalDeltaQueue.axis.addInPlace(event.deltaAxis);\r\n totalDeltaQueue.angle += angle;\r\n updateAxisAngle.next({ axis: KbVector.FromVec3(event.deltaAxis), angle });\r\n }\r\n });\r\n axisAngleGizmo.onDragEndObservable.add(() => {\r\n if (this.dragging) {\r\n totalDelta.next({ axis: KbVector.FromVec3(totalDeltaQueue.axis), angle: totalDeltaQueue.angle });\r\n totalDeltaQueue.axis = Vector3.Zero();\r\n totalDeltaQueue.angle = 0;\r\n this.dragging = false;\r\n }\r\n });\r\n\r\n return {\r\n update: updateAxisAngle.asObservable(),\r\n totalDelta: totalDelta.asObservable(),\r\n updateGizmoPosition: (updateAxis?: KbVector, updatePosition?: KbVector) =>\r\n axisAngleGizmo.updateGizmoPosition(updateAxis, updatePosition),\r\n dispose: () => this.clearGizmo(axisAngleGizmo),\r\n };\r\n }\r\n\r\n /**\r\n * Creates a rotation gizmo that can rotate many items\r\n * nodes will be rotated and repositioned in space if the center of rotation is not equal to the position\r\n * vectors will be repositioned in space as if each vector is the position of a point\r\n */\r\n rotate(\r\n targets: Array,\r\n positionSpace?: SpaceNode,\r\n placementOffset?: KbVector,\r\n axisVisibility?: [boolean, boolean, boolean]\r\n ) {\r\n let gizmoOffset = Vector3.Zero();\r\n\r\n // Get the transform matrix to get the world space rotation and coordinates of the node we are rotating\r\n let positionTransform: Matrix | undefined;\r\n if (positionSpace) {\r\n positionTransform = this.kbViewer.getRendererNode(positionSpace)?.computeWorldMatrix(true);\r\n } else if (targets[0] instanceof SpaceNode && targets[0]._parent) {\r\n positionTransform = this.kbViewer.getRendererNode(targets[0]._parent)?.computeWorldMatrix(true);\r\n }\r\n const rotationGizmo = new KbRotationGizmo(this.kbViewer, this.gizmoLayer, undefined, axisVisibility);\r\n\r\n if (targets.length === 1) {\r\n const target = targets[0];\r\n rotationGizmo.attachTo(target, positionSpace, placementOffset);\r\n } else {\r\n // If multiple targets are selected, put the pivot in the average of the positions\r\n // Maybe enhance this to use bounding box later, if that's important...\r\n const pivot = targets\r\n .reduce((result: KbVector, current) => {\r\n return result.add(current instanceof SpaceNode ? current.position : current);\r\n }, KbVector.Zero())\r\n .scale(1 / targets.length);\r\n rotationGizmo.attachTo(KbVector.Zero(), undefined, pivot);\r\n }\r\n\r\n const update = new Subject<\r\n Array<{ rotation: KbVector; position: KbVector; axisTranslate: KbVector; worldTransformMatrix: Matrix }>\r\n >();\r\n const totalDelta = new Subject<{\r\n rotation: KbVector;\r\n position: KbVector;\r\n axisTranslate: KbVector;\r\n }>();\r\n this.activeGizmoSettings.push({\r\n subjects: [update, totalDelta],\r\n gizmo: rotationGizmo,\r\n });\r\n\r\n this.dragging = false;\r\n let totalDeltaQueue = {\r\n rotation: Quaternion.Identity(),\r\n position: Vector3.Zero(),\r\n axisTranslate: Vector3.Zero(),\r\n };\r\n\r\n // Set up caches for the positions and rotations of the nodes because it's not guaranteed that they will be updated by reference\r\n // And as you drag the nodes these values will change and the gizmos won't be dragging in the right direction anymore\r\n const positions = targets.map(target =>\r\n target instanceof SpaceNode ? target.position.toVec3() : target.toVec3()\r\n );\r\n const axes = targets.map(target => (target instanceof SpaceNode ? target.rotationAxis.toVec3() : null));\r\n const quaternionCache = targets.map(target =>\r\n target instanceof SpaceNode\r\n ? Quaternion.FromEulerVector(target.eulerRotation.toVec3().scale(Math.PI / 180))\r\n : Quaternion.Identity()\r\n );\r\n\r\n // Get the current pivot which will always be where the gizmo is located (minus the offset which just visually offsets the gizmo position)\r\n let gizmoPosition = rotationGizmo.attachedMesh!.position;\r\n\r\n rotationGizmo.onDragStartObservable.add(() => {\r\n this.dragging = true;\r\n if (rotationGizmo.gizmoOffset) {\r\n gizmoOffset = rotationGizmo.gizmoOffset.toVec3();\r\n }\r\n if (gizmoOffset) {\r\n gizmoPosition = gizmoPosition.subtract(gizmoOffset);\r\n }\r\n });\r\n rotationGizmo.onDragObservable.add(event => {\r\n if (this.dragging) {\r\n const result: Array<{\r\n rotation: KbVector;\r\n position: KbVector;\r\n axisTranslate: KbVector;\r\n worldTransformMatrix: Matrix;\r\n }> = [];\r\n\r\n const rotationMatrix = new Matrix();\r\n\r\n const gizmoRotation = rotationGizmo.attachedMesh!.rotationQuaternion || Quaternion.Identity();\r\n // Get the true world space rotation in the case that the gizmo is rotated\r\n // The gizmos output their rotation deltas in local space\r\n const meshSpaceRotation = gizmoRotation.multiply(event.delta).multiply(gizmoRotation.conjugate());\r\n meshSpaceRotation.toRotationMatrix(rotationMatrix);\r\n const worldTransformMatrix = new Matrix();\r\n event.delta.toRotationMatrix(worldTransformMatrix);\r\n worldTransformMatrix.multiplyToRef(\r\n rotationGizmo.attachedMesh!.computeWorldMatrix(),\r\n worldTransformMatrix\r\n );\r\n\r\n // Inverse the position transform to rotate the delta back into local \"positionSpace\" space\r\n const positionTransformInv = positionTransform?.clone().invert();\r\n\r\n positions.forEach((position, index) => {\r\n let positionDelta: Vector3;\r\n let axisDelta: Vector3 | undefined;\r\n const target = targets[index];\r\n const axis = axes[index];\r\n\r\n // If the node is a space node, then rotate it around the pivot to get the updated position\r\n if (target instanceof SpaceNode) {\r\n // Treat the pivot point as the center of the node so the node rotates around the pivot point\r\n let worldNodePivot = target.pivot.toVec3();\r\n const nodeTransform = this.kbViewer.getRendererNode(target)?.computeWorldMatrix(true);\r\n if (nodeTransform) {\r\n worldNodePivot = Vector3.TransformCoordinates(worldNodePivot, nodeTransform);\r\n }\r\n positionDelta = Vector3.TransformCoordinates(\r\n worldNodePivot.subtract(gizmoPosition),\r\n rotationMatrix\r\n )\r\n .add(gizmoPosition)\r\n .subtract(worldNodePivot);\r\n // If the node is a vector, then it's a direction vector, so we want to rotate it as if the vector started from the origin.\r\n // So don't rotate around the pivot point. The updated position will actually be the updated direction.\r\n } else {\r\n positionDelta = Vector3.TransformCoordinates(position, rotationMatrix).subtract(position);\r\n }\r\n\r\n if (axis) {\r\n axisDelta = Vector3.TransformCoordinates(\r\n axis.length() === 0 ? new Vector3(0, 1, 0) : axis,\r\n rotationMatrix\r\n ).subtract(axis);\r\n axis.addInPlace(axisDelta);\r\n }\r\n\r\n // Rotate the delta vector into local \"positionSpace\" space\r\n if (positionTransformInv) {\r\n positionDelta = Vector3.TransformCoordinates(\r\n positionDelta,\r\n positionTransformInv.getRotationMatrix()\r\n );\r\n }\r\n\r\n // Update the position cache by reference (make sure this position variable isn't shadowed)\r\n position.addInPlace(positionDelta);\r\n totalDeltaQueue.position.addInPlace(positionDelta);\r\n if (axisDelta) {\r\n totalDeltaQueue.axisTranslate.addInPlace(axisDelta);\r\n }\r\n\r\n // Get the rotation delta by converting the previous quaternion rotation to euler, rotating to the new position, and getting euler angles of that.\r\n // This is necessary because it we output the plain quaternion delta euler, the euler rotation order could result\r\n // In an incorrect rotation if there are other euler angles being rotated first\r\n const previousAngle = quaternionCache[index].toEulerAngles();\r\n quaternionCache[index].multiplyInPlace(event.delta);\r\n const newAngle = quaternionCache[index].toEulerAngles();\r\n\r\n totalDeltaQueue.rotation.multiplyInPlace(event.delta);\r\n result.push({\r\n position: KbVector.FromVec3(positionDelta),\r\n rotation: KbVector.FromVec3(newAngle.subtract(previousAngle).scale(180 / Math.PI)),\r\n worldTransformMatrix: worldTransformMatrix,\r\n axisTranslate: axisDelta ? KbVector.FromVec3(axisDelta) : KbVector.Zero(),\r\n });\r\n });\r\n update.next(result);\r\n }\r\n });\r\n rotationGizmo.onDragEndObservable.add(() => {\r\n if (this.dragging) {\r\n totalDelta.next({\r\n rotation: KbVector.FromVec3(totalDeltaQueue.rotation.toEulerAngles().scale(180 / Math.PI)),\r\n position: KbVector.FromVec3(totalDeltaQueue.position),\r\n axisTranslate: KbVector.FromVec3(totalDeltaQueue.axisTranslate),\r\n });\r\n totalDeltaQueue = {\r\n rotation: Quaternion.Identity(),\r\n position: Vector3.Zero(),\r\n axisTranslate: Vector3.Zero(),\r\n };\r\n this.dragging = false;\r\n }\r\n });\r\n\r\n return {\r\n update: update.asObservable(),\r\n totalDelta: totalDelta.asObservable(),\r\n updateGizmoPosition: (update?: KbVector, offset?: KbVector) =>\r\n rotationGizmo.updateGizmoPosition(update, offset),\r\n dispose: () => this.clearGizmo(rotationGizmo),\r\n };\r\n }\r\n\r\n scale(targets: Array, positionSpace?: SpaceNode) {\r\n // if (targets.length === 0) {\r\n // return {\r\n // update: empty(),\r\n // totalDelta: empty(),\r\n // };\r\n // }\r\n\r\n const scaleGizmo = new KbScaleGizmo(this.kbViewer, this.gizmoLayer);\r\n\r\n if (targets.length === 1) {\r\n const target = targets[0];\r\n scaleGizmo.attachTo(target, positionSpace);\r\n } else {\r\n // If multiple targets are selected, put the pivot in the average of the positions\r\n // Maybe enhance this to use bounding box later, if that's important...\r\n const pivot = targets\r\n .reduce((result: KbVector, current) => {\r\n return result.add(current instanceof SpaceNode ? current.position : current);\r\n }, KbVector.Zero())\r\n .scale(1 / targets.length);\r\n\r\n scaleGizmo.attachTo(pivot, positionSpace);\r\n }\r\n\r\n const update = new Subject>();\r\n const totalDelta = new Subject();\r\n this.activeGizmoSettings.push({\r\n subjects: [update, totalDelta],\r\n gizmo: scaleGizmo,\r\n });\r\n\r\n this.dragging = false;\r\n let totalDeltaQueue = Vector3.Zero();\r\n let positionTransform: Matrix | undefined;\r\n\r\n // Get the transform matrix to get the world space rotation and coordinates of the node we are scaling\r\n if (positionSpace) {\r\n positionTransform = this.kbViewer.getRendererNode(positionSpace)?.computeWorldMatrix(true);\r\n } else if (targets[0] instanceof SpaceNode && targets[0]._parent) {\r\n positionTransform = this.kbViewer.getRendererNode(targets[0]._parent)?.computeWorldMatrix(true);\r\n }\r\n\r\n // Get the current pivot which will always be where the gizmo is located\r\n let gizmoPosition = scaleGizmo.attachedMesh!.position;\r\n\r\n scaleGizmo.onDragStartObservable.add(() => {\r\n this.dragging = true;\r\n if (scaleGizmo.gizmoOffset) {\r\n gizmoPosition = gizmoPosition.subtract(scaleGizmo.gizmoOffset.toVec3());\r\n }\r\n });\r\n scaleGizmo.onDragObservable.add(event => {\r\n if (this.dragging) {\r\n const result: Array<{ scaling: KbVector; position: KbVector }> = [];\r\n\r\n targets.forEach(target => {\r\n let positionDelta: Vector3;\r\n\r\n // If the node is a space node, then rotate it around the pivot to get the updated position\r\n if (target instanceof SpaceNode) {\r\n // Treat the pivot point as the center of the node so the node rotates around the pivot point\r\n let worldNodePivot = target.pivot.toVec3();\r\n const nodeTransform = this.kbViewer.getRendererNode(target)?.computeWorldMatrix(true);\r\n if (nodeTransform) {\r\n worldNodePivot = Vector3.TransformCoordinates(worldNodePivot, nodeTransform);\r\n }\r\n positionDelta = worldNodePivot\r\n .subtract(gizmoPosition)\r\n .multiply(event.delta)\r\n .add(gizmoPosition)\r\n .subtract(worldNodePivot);\r\n // If the node is a vector, then it's a direction vector, so we want to rotate it as if the vector started from the origin.\r\n // So don't rotate around the pivot point. The updated position will actually be the updated direction.\r\n } else {\r\n // Transform the node position to world space because the pivot and gizmo will be in world space as well\r\n let worldPosition = target.toVec3();\r\n if (positionTransform) {\r\n worldPosition = Vector3.TransformCoordinates(worldPosition, positionTransform);\r\n }\r\n positionDelta = worldPosition.multiply(event.delta).subtract(worldPosition);\r\n }\r\n\r\n totalDeltaQueue.addInPlace(event.delta);\r\n result.push({\r\n position: KbVector.FromVec3(positionDelta),\r\n scaling: KbVector.FromVec3(event.delta),\r\n });\r\n });\r\n update.next(result);\r\n }\r\n });\r\n scaleGizmo.onDragEndObservable.add(() => {\r\n if (this.dragging) {\r\n totalDelta.next(KbVector.FromVec3(totalDeltaQueue));\r\n totalDeltaQueue = Vector3.Zero();\r\n this.dragging = false;\r\n }\r\n });\r\n\r\n return {\r\n update: update.asObservable(),\r\n totalDelta: totalDelta.asObservable(),\r\n updateGizmoPosition: (update?: KbVector) => scaleGizmo.updateGizmoPosition(update),\r\n dispose: () => this.clearGizmo(scaleGizmo),\r\n };\r\n }\r\n\r\n selectVertices(target: MeshNode, selectedVertices?: number[]) {\r\n const vertexSelectionGizmo = new KbVertexSelectGizmo(this.kbViewer, this.scene);\r\n vertexSelectionGizmo.attachTo(target);\r\n\r\n const update = new Subject<{\r\n vertexIndices: number[];\r\n }>();\r\n this.activeGizmoSettings.push({\r\n subjects: [update],\r\n gizmo: vertexSelectionGizmo,\r\n });\r\n\r\n if (selectedVertices) {\r\n vertexSelectionGizmo.selectVertices(selectedVertices);\r\n }\r\n\r\n this.dragging = false;\r\n vertexSelectionGizmo.onSelectionChange.add(result => {\r\n if (result) {\r\n update.next({\r\n vertexIndices: result.selectedIndices,\r\n });\r\n }\r\n });\r\n\r\n return {\r\n update: update.asObservable(),\r\n vertexTracker: vertexSelectionGizmo.vertexTracker,\r\n updateGizmoPositions: () => vertexSelectionGizmo.updateGizmoPosition(),\r\n updateParticleScale: (scale: number) => vertexSelectionGizmo.updateParticleScale(scale),\r\n disableSelectionChange: () => vertexSelectionGizmo.disableSelectionChange(),\r\n enableSelectionChange: () => vertexSelectionGizmo.enableSelectionChange(),\r\n getBarycenter: (indices: number[]) => vertexSelectionGizmo.getBarycenter(indices),\r\n dispose: () => this.clearGizmo(vertexSelectionGizmo),\r\n };\r\n }\r\n\r\n selectFacets(target: MeshNode, selectedVertices?: IVertexGroup[]) {\r\n const facetSelectionGizmo = new KbFacetSelectGizmo(this.kbViewer, this.scene);\r\n facetSelectionGizmo.attachTo(target);\r\n\r\n const update = new Subject<{\r\n selectedFacets: Array>;\r\n }>();\r\n this.activeGizmoSettings.push({\r\n subjects: [update],\r\n gizmo: facetSelectionGizmo,\r\n });\r\n\r\n if (selectedVertices) {\r\n facetSelectionGizmo.selectFacetGroups(selectedVertices);\r\n }\r\n\r\n this.dragging = false;\r\n facetSelectionGizmo.onSelectionChange.add(result => {\r\n if (result) {\r\n update.next({\r\n selectedFacets: result.selectedFacets,\r\n });\r\n }\r\n });\r\n\r\n return {\r\n update: update.asObservable(),\r\n updateGizmoPositions: () => facetSelectionGizmo.updateGizmoPosition(),\r\n disableSelectionChange: () => facetSelectionGizmo.disableSelectionChange(),\r\n enableSelectionChange: () => facetSelectionGizmo.enableSelectionChange(),\r\n dispose: () => this.clearGizmo(facetSelectionGizmo),\r\n\r\n setBackfaceCulling: (enabled: boolean) => facetSelectionGizmo.setBackfaceCulling(enabled),\r\n setTolerance: (tolerance: number) => facetSelectionGizmo.setTolerance(tolerance),\r\n setVisualization: (opacity: number) => facetSelectionGizmo.setVisualization(opacity),\r\n expandSelection: (tolerance?: number) => facetSelectionGizmo.expandSelection(tolerance),\r\n };\r\n }\r\n\r\n clearGizmo(gizmo?: KbGizmo) {\r\n if (gizmo) {\r\n const index = this.activeGizmoSettings.findIndex(g => g.gizmo === gizmo);\r\n if (index >= 0) {\r\n const gizmoSettings = this.activeGizmoSettings[index];\r\n gizmoSettings.subjects.forEach(subject => subject.complete());\r\n gizmoSettings.gizmo.dispose();\r\n\r\n this.activeGizmoSettings.splice(index, 1);\r\n }\r\n } else {\r\n this.activeGizmoSettings.forEach(gizmoSettings => {\r\n gizmoSettings.subjects.forEach(subject => subject.complete());\r\n gizmoSettings.gizmo.dispose();\r\n });\r\n this.activeGizmoSettings = [];\r\n }\r\n }\r\n\r\n updateGizmoPositions() {\r\n if (!this.dragging) {\r\n this.activeGizmoSettings.forEach(gizmoSettings => {\r\n gizmoSettings.gizmo.updateGizmoPosition();\r\n });\r\n }\r\n }\r\n\r\n showUvMapMaterial(target: UvMapFeature) {\r\n if (target._showMaterial && target._previewMaterialVisible) {\r\n if (target._parent) {\r\n const mesh = this.kbViewer.getRendererNode(target._parent);\r\n if (mesh instanceof Mesh) {\r\n if (mesh.material != null && mesh.material.name != PREVIEW_NAME) {\r\n const previousMaterial = mesh.material;\r\n this.uvMapStoredMaterials.set(target.id, previousMaterial);\r\n }\r\n\r\n if (!this.previewMaterial) {\r\n this.previewMaterial = new PBRMaterial(PREVIEW_NAME, this.kbViewer.scene);\r\n const previewTexture = new Texture('/assets/images/uv_colorgrid.png', this.kbViewer.scene);\r\n this.previewMaterial.albedoTexture = previewTexture;\r\n this.previewMaterial.albedoColor = Color3.White();\r\n this.previewMaterial.metallic = 0;\r\n this.previewMaterial.roughness = 1;\r\n }\r\n\r\n mesh.material = this.previewMaterial;\r\n }\r\n }\r\n } else {\r\n if (target._parent) {\r\n const mesh = this.kbViewer.getRendererNode(target._parent);\r\n if (mesh instanceof Mesh) {\r\n const storedMaterial = this.uvMapStoredMaterials.get(target.id);\r\n if (storedMaterial) {\r\n mesh.material = storedMaterial;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Bounding mesh code is not used right now, but it may be useful when we are doing mates\r\n // private calculateBoundingBox(nodes: TransformNode[]) {\r\n // const meshes = nodes.filter((node): node is Mesh => node instanceof Mesh);\r\n // meshes.forEach(mesh => mesh.computeWorldMatrix(true));\r\n // if (meshes.length === 0) {\r\n // return {\r\n // pivot: Vector3.Zero(),\r\n // boundingInfo: new BoundingInfo(Vector3.Zero(), Vector3.Zero())\r\n // };\r\n // }\r\n\r\n // let boundingInfo = meshes[0].getBoundingInfo();\r\n // let minimumWorld = boundingInfo.boundingBox.minimumWorld;\r\n // let maximumWorld = boundingInfo.boundingBox.maximumWorld;\r\n\r\n // for (let i = 1; i < meshes.length; i++) {\r\n // let boundingInfo = meshes[i].getBoundingInfo();\r\n // minimumWorld = Vector3.Minimize(minimumWorld, boundingInfo.boundingBox.minimumWorld);\r\n // maximumWorld = Vector3.Maximize(maximumWorld, boundingInfo.boundingBox.maximumWorld);\r\n // }\r\n // let bounding = new BoundingInfo(minimumWorld, maximumWorld);\r\n // let middlePivot = new Vector3(bounding.boundingBox.center.x, bounding.boundingBox.center.y, bounding.boundingBox.center.z);\r\n\r\n // return {\r\n // pivot: middlePivot,\r\n // boundingInfo: bounding\r\n // };\r\n // }\r\n\r\n // private displayKbBoundingBox(mesh: Mesh) {\r\n // let oMesh: Mesh & { kbBoundingBox?: boundingBoxGeometry };\r\n // oMesh = mesh;\r\n // var bbNode: boundingBoxGeometry;\r\n\r\n // if (this.currentSelectedMeshes.length === 0) {\r\n // if (oMesh.kbBoundingBox) {\r\n // oMesh.kbBoundingBox.wireFrame.dispose();\r\n // delete oMesh.kbBoundingBox;\r\n // }\r\n // return;\r\n // }\r\n\r\n // // if the mesh is resized/rotated/something we need to recalculate the bounding box\r\n // mesh.computeWorldMatrix(true);\r\n // mesh.refreshBoundingInfo();\r\n\r\n // mesh.refreshBoundingInfo = (applySkeleton?: boolean) => {\r\n // return mesh;\r\n // };\r\n\r\n // const center = mesh.getBoundingInfo().boundingBox.centerWorld.clone();\r\n // const diagonalLen = mesh.getBoundingInfo().diagonalLength;\r\n\r\n // const min = mesh.getBoundingInfo().boundingBox.minimumWorld;\r\n // const max = mesh.getBoundingInfo().boundingBox.maximumWorld;\r\n // const d = max.subtract(min);\r\n\r\n // const bOffset = 0.02;\r\n // d.x += bOffset;\r\n // d.y += bOffset;\r\n // d.z += bOffset;\r\n // // calculate the position of the bounding box vertices\r\n // const v1 = new Vector3(center.x - d.x / 2, center.y + d.y / 2, center.z + d.z / 2);\r\n // const v2 = new Vector3(center.x + d.x / 2, center.y + d.y / 2, center.z + d.z / 2);\r\n // const v3 = new Vector3(center.x - d.x / 2, center.y - d.y / 2, center.z + d.z / 2);\r\n // const v4 = new Vector3(center.x + d.x / 2, center.y - d.y / 2, center.z + d.z / 2);\r\n // const v5 = new Vector3(center.x - d.x / 2, center.y + d.y / 2, center.z - d.z / 2);\r\n // const v6 = new Vector3(center.x + d.x / 2, center.y + d.y / 2, center.z - d.z / 2);\r\n // const v7 = new Vector3(center.x - d.x / 2, center.y - d.y / 2, center.z - d.z / 2);\r\n // const v8 = new Vector3(center.x + d.x / 2, center.y - d.y / 2, center.z - d.z / 2);\r\n\r\n // const lines = Mesh.CreateLines(KBMAXPREFIX + \"boundingBox\", [\r\n // v1, v2,\r\n // v1, v3,\r\n // v3, v4,\r\n // v4, v2,\r\n // v2, v6,\r\n // v6, v5,\r\n // v5, v7,\r\n // v7, v8,\r\n // v8, v6,\r\n // v8, v4,\r\n // v3, v7,\r\n // v5, v1\r\n // ], this.gizmoLayer.utilityLayerScene);\r\n // lines.color = new Color3(1, 1, 1);\r\n // lines.isPickable = false;\r\n\r\n // if (oMesh.kbBoundingBox) {\r\n // // the bounding box exists so it must be recalculated and repositioned\r\n // bbNode = oMesh.kbBoundingBox;\r\n // bbNode.wireFrame.dispose(); // it is easier to recreate it then reposition it\r\n // bbNode.wireFrame = lines;\r\n // }\r\n // else {\r\n // // the bounding box does not exist, so it must be created\r\n // bbNode = new boundingBoxGeometry(lines);\r\n // }\r\n\r\n // oMesh.kbBoundingBox = bbNode; // force to attach the current boundingBox\r\n // }\r\n\r\n private filterToChangedValues(vector: Vector3 | Quaternion): Partial {\r\n return {\r\n x: vector.x ? vector.x : undefined,\r\n y: vector.y ? vector.y : undefined,\r\n z: vector.z ? vector.z : undefined,\r\n w: 'w' in vector ? vector.w : undefined,\r\n };\r\n }\r\n}\r\n\r\n// class boundingBoxGeometry {\r\n// mateHelper1?: Mesh;\r\n// mateHelper2?: Mesh;\r\n// mateHelper3?: Mesh;\r\n// mateHelper4?: Mesh;\r\n// mateHelper5?: Mesh;\r\n// mateHelper6?: Mesh;\r\n// wireFrame: Mesh;\r\n\r\n// constructor(wireFrame: Mesh) {\r\n// this.wireFrame = wireFrame;\r\n// }\r\n// }\r\n","import { Camera } from '@babylonjs/core/Cameras/camera';\r\nimport { BoundingSphere } from '@babylonjs/core/Culling/boundingSphere';\r\nimport { Ray } from '@babylonjs/core/Culling/ray';\r\nimport { Plane } from '@babylonjs/core/Maths/math.plane';\r\nimport { Vector3 } from '@babylonjs/core/Maths/math.vector';\r\nimport { LinesMesh } from '@babylonjs/core/Meshes/linesMesh';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { SketchControlPoint, SketchPath, SpaceNode, Token, getByDynamicId } from '@models/classes';\r\nimport { eAxis, eSketchPathType } from '@models/classes/enums';\r\nimport { SketchNode } from '@models/classes/meshes/sketch-node';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { roundVectorToPlaces } from '@view/helpers/math-helper';\r\nimport { createSketchPointForEditor, getSketchNormalVector3 } from '@view/modules/sketching/util';\r\nimport { CONNECTOR_DIAM } from '@view/render/features/connector';\r\nimport { Subject } from 'rxjs';\r\nimport { take, takeUntil } from 'rxjs/operators';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport { KbArcRotateCamera } from './cameras/kb-arc-rotate-camera';\r\n\r\nconst DefaultSketchOptions = {\r\n faceCamera: true,\r\n snapSize: 0.5,\r\n};\r\n\r\nlet activeHitPoint: SketchControlPoint | undefined;\r\nlet sketchPlaneIntersect: KbVector;\r\n\r\nexport type ISketchOptions = Partial;\r\n\r\nexport class SketchEditor {\r\n mouseUp = new Subject();\r\n\r\n constructor(private kbViewer: KbViewer, private scene: Scene, private defaultHighlightColor: KbColor) {}\r\n\r\n private currentOptions: Required | undefined;\r\n private end = new Subject();\r\n private sketchPoints: SketchControlPoint[] = [];\r\n private activeSketch: SketchNode | undefined;\r\n\r\n updateActiveOptions(options: ISketchOptions) {\r\n if (this.currentOptions) {\r\n for (const prop in options) {\r\n // @ts-expect-error typing not smart enough to know that option objects are the same\r\n this.currentOptions[prop] = options[prop];\r\n }\r\n }\r\n }\r\n\r\n start(sketch: SketchNode) {\r\n let origin = KbVector.Zero();\r\n for (let i = 0; i < sketch.paths.length; i++) {\r\n const path = sketch.paths[i];\r\n if (path.controlPoints.length > 0) {\r\n origin = path.controlPoints[0].position;\r\n break;\r\n }\r\n }\r\n\r\n return this.startOnPlane(\r\n sketch,\r\n {\r\n normal: sketch.normal,\r\n intersect: origin,\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n\r\n startOnPlane(\r\n sketch: SketchNode,\r\n plane: { normal: KbVector | eAxis; intersect: KbVector },\r\n userOptions?: ISketchOptions,\r\n useSketchNormal = false\r\n ) {\r\n this.activeSketch = sketch;\r\n sketchPlaneIntersect = plane.intersect;\r\n const currentCanvas = this.kbViewer.canvas!;\r\n const options: Required = { ...DefaultSketchOptions, ...userOptions };\r\n this.currentOptions = options;\r\n this.sketchPoints = sketch.paths.reduce((result, path) => {\r\n for (const point of path.controlPoints) {\r\n point._visible = true;\r\n result.push(point);\r\n }\r\n return result;\r\n }, [] as SketchControlPoint[]);\r\n\r\n const previewVisibleOriginal = sketch._previewVisible;\r\n sketch._previewVisible = true;\r\n let planeNormal = getSketchNormalVector3(plane.normal);\r\n if (useSketchNormal) {\r\n const sketchNode = this.kbViewer.getRendererNode(sketch);\r\n if (sketchNode) {\r\n const matrix = sketchNode.getWorldMatrix().getRotationMatrix();\r\n planeNormal = Vector3.TransformCoordinates(planeNormal, matrix);\r\n }\r\n }\r\n const planeIntersect = plane.intersect.toVec3();\r\n const sketchPlane = Plane.FromPositionAndNormal(planeIntersect, planeNormal);\r\n\r\n const originalCamera = this.scene.activeCamera!;\r\n\r\n let sketchCamera: KbArcRotateCamera | undefined;\r\n if (options.faceCamera) {\r\n originalCamera.detachControl();\r\n // camera.storeCameraSettings();\r\n // const viewpoint = new ViewpointNode()\r\n // camera.moveCameraToViewpoint(viewpoint);\r\n sketchCamera = new KbArcRotateCamera('sketchEditorView', 0, 0, 10, planeIntersect, this.scene);\r\n sketchCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;\r\n sketchCamera.lockRotation = true;\r\n sketchCamera.wheelPrecision = 60;\r\n sketchCamera.pinchPrecision = 60;\r\n switch (plane.normal) {\r\n case eAxis.x:\r\n case eAxis.z:\r\n sketchCamera.upVector = Vector3.Up();\r\n break;\r\n case eAxis.y:\r\n sketchCamera.upVector = Vector3.Backward();\r\n break;\r\n default:\r\n sketchCamera.upVector = Vector3.Cross(\r\n planeNormal,\r\n planeNormal.equalsToFloats(0, 1, 0) ? Vector3.Right() : Vector3.Up()\r\n );\r\n }\r\n sketchCamera.setPosition(planeNormal.scale(5000).add(planeIntersect));\r\n sketchCamera.orthoFit(10, 10);\r\n\r\n this.scene.activeCamera = sketchCamera;\r\n currentCanvas.focus();\r\n sketchCamera.attachControl();\r\n this.kbViewer.viewChanged.next();\r\n }\r\n\r\n const currentCamera = this.scene.activeCamera!;\r\n\r\n interface DragInfo {\r\n point: SketchControlPoint;\r\n handle: 'position' | 'direction' | 'direction2';\r\n }\r\n let dragObjects: DragInfo[] = [];\r\n let lastMousePosition: Vector3 | null = null;\r\n const sketchParent = sketch._parent ? this.kbViewer.getRendererNode(sketch._parent) : undefined;\r\n\r\n this.kbViewer.interaction.onPointerDown.pipe(takeUntil(this.end)).subscribe(e => {\r\n if (e.button === 0 && e.pickInfo && e.pickInfo.ray) {\r\n const deletedPoints: SketchControlPoint[] = [];\r\n const ray = e.pickInfo.ray;\r\n lastMousePosition = getPointOnPlane(ray);\r\n if (lastMousePosition) {\r\n roundVectorToPlaces(lastMousePosition, options.snapSize);\r\n }\r\n\r\n const v1 = new Vector3(-1, -1, -1),\r\n v2 = new Vector3(1, 1, 1),\r\n collisionSphere = new BoundingSphere(v1, v2);\r\n\r\n const r = CONNECTOR_DIAM / 2;\r\n\r\n for (let i = 0; i < this.sketchPoints.length; i++) {\r\n const point = this.sketchPoints[i];\r\n const pointRendered = this.kbViewer.getRendererNode(point);\r\n if (!pointRendered || pointRendered.isDisposed()) {\r\n this.sketchPoints.splice(i, 1);\r\n i--;\r\n continue;\r\n }\r\n\r\n const cpCenter = pointRendered.position.clone();\r\n const cpHandle1 = cpCenter.add(point.direction.toVec3());\r\n const cpHandle2 = point.direction2 ? cpCenter.add(point.direction2.toVec3()) : undefined;\r\n if (sketchParent) {\r\n const matrix = sketchParent.computeWorldMatrix();\r\n Vector3.TransformCoordinatesToRef(cpCenter, matrix, cpCenter);\r\n Vector3.TransformCoordinatesToRef(cpHandle1, matrix, cpHandle1);\r\n if (cpHandle2) {\r\n Vector3.TransformCoordinatesToRef(cpHandle2, matrix, cpHandle2);\r\n }\r\n }\r\n v1.copyFrom(cpCenter).addInPlaceFromFloats(-r, -r, -r);\r\n v2.copyFrom(cpCenter).addInPlaceFromFloats(r, r, r);\r\n collisionSphere.reConstruct(v1, v2);\r\n let hit = ray.intersectsSphere(collisionSphere);\r\n let handle: DragInfo['handle'] = 'position';\r\n\r\n if (!hit) {\r\n v1.copyFrom(cpHandle1).addInPlaceFromFloats(-r, -r, -r);\r\n v2.copyFrom(cpHandle1).addInPlaceFromFloats(r, r, r);\r\n collisionSphere.reConstruct(v1, v2);\r\n hit = ray.intersectsSphere(collisionSphere);\r\n handle = 'direction';\r\n }\r\n if (!hit && cpHandle2) {\r\n v1.copyFrom(cpHandle2).addInPlaceFromFloats(-r, -r, -r);\r\n v2.copyFrom(cpHandle2).addInPlaceFromFloats(r, r, r);\r\n collisionSphere.reConstruct(v1, v2);\r\n hit = ray.intersectsSphere(collisionSphere);\r\n handle = 'direction2';\r\n }\r\n\r\n if (hit) {\r\n dragObjects.push({ point, handle });\r\n\r\n // If ctrl key is held down, allow dragging just one point so you can separate paths\r\n if (e.ctrlKey) {\r\n break;\r\n }\r\n }\r\n }\r\n deletedPoints.forEach(point => {\r\n const index = this.sketchPoints.findIndex(ec => ec.id === point.id);\r\n this.sketchPoints.splice(index, 1);\r\n });\r\n\r\n // If both direction handles and positions are hit, only drag the positions and leave the handles alone\r\n if (dragObjects.find(d => d.handle === 'position')) {\r\n dragObjects = dragObjects.filter(d => d.handle === 'position');\r\n }\r\n\r\n if (dragObjects.length === 0) {\r\n activeHitPoint = undefined;\r\n } else {\r\n activeHitPoint = dragObjects[0].point;\r\n currentCamera.detachControl();\r\n }\r\n }\r\n });\r\n\r\n this.kbViewer.interaction.onPointerUp.pipe(takeUntil(this.end)).subscribe(e => {\r\n dragObjects = [];\r\n this.mouseUp.next();\r\n currentCamera.attachControl(currentCanvas);\r\n });\r\n\r\n this.kbViewer.interaction.onPointerMove.pipe(takeUntil(this.end)).subscribe(e => {\r\n if (dragObjects.length > 0 && e.pickInfo && e.pickInfo.ray) {\r\n const ray = e.pickInfo.ray;\r\n const intersect = getPointOnPlane(ray);\r\n if (intersect) {\r\n if (sketchParent) {\r\n const transformInv = sketchParent.computeWorldMatrix().clone().invert();\r\n Vector3.TransformCoordinatesToRef(intersect, transformInv, intersect);\r\n }\r\n roundVectorToPlaces(intersect, options.snapSize);\r\n dragObjects.forEach(dragObject => {\r\n if (dragObject.handle === 'position') {\r\n roundVectorToPlaces(intersect, options.snapSize);\r\n dragObject.point.position = KbVector.FromVec3(intersect);\r\n } else {\r\n const movement = intersect.subtract(dragObject.point.position.toVec3());\r\n roundVectorToPlaces(intersect, options.snapSize);\r\n\r\n if (dragObject.handle === 'direction') {\r\n dragObject.point.direction = KbVector.FromVec3(movement);\r\n } else if (dragObject.point.direction2) {\r\n dragObject.point.direction2 = KbVector.FromVec3(movement);\r\n }\r\n }\r\n });\r\n }\r\n }\r\n });\r\n\r\n this.kbViewer.interaction.onClick.pipe(takeUntil(this.end)).subscribe(e => {\r\n if (dragObjects.length === 0 && e.pickInfo) {\r\n if (e.button === 2 && e.canvasX && e.canvasY) {\r\n if (e.pickInfo.pickedMesh instanceof LinesMesh && e.pickInfo.pickedPoint) {\r\n this.kbViewer.rightClickMenu.showContextMenu(\r\n e.canvasX,\r\n e.canvasY,\r\n this.getRightClickButtonsForLines(sketch, e.pickInfo.faceId, e.pickInfo.pickedPoint)\r\n );\r\n } else if (e.pickInfo.pickedMesh instanceof Mesh) {\r\n const kb3dNode = getByDynamicId(e.pickInfo.pickedMesh.id);\r\n if (kb3dNode instanceof SketchControlPoint) {\r\n activeHitPoint = kb3dNode;\r\n this.kbViewer.rightClickMenu.showContextMenu(\r\n e.canvasX,\r\n e.canvasY,\r\n this.getRightClickButtons()\r\n );\r\n }\r\n }\r\n } else if (e.button === 0 && e.pickInfo.ray) {\r\n if (this.kbViewer.rightClickMenu.isOpen()) {\r\n this.kbViewer.rightClickMenu.hideContextMenu();\r\n return;\r\n }\r\n const ray = e.pickInfo.ray;\r\n const intersect = getPointOnPlane(ray);\r\n if (intersect) {\r\n const manager = sketch._manager!;\r\n roundVectorToPlaces(intersect, options.snapSize);\r\n\r\n let lastPath = sketch.paths.length > 0 ? sketch.paths[sketch.paths.length - 1] : undefined;\r\n if (!lastPath) {\r\n lastPath = manager.create(Token.SketchPath);\r\n lastPath.name = 'Path';\r\n sketch.addChildren(lastPath);\r\n }\r\n\r\n const c = createSketchPointForEditor(manager, lastPath);\r\n\r\n if (sketch._parent instanceof SpaceNode) {\r\n const rendererNode = this.kbViewer.getRendererNode(sketch);\r\n\r\n if (rendererNode) {\r\n Vector3.TransformCoordinatesToRef(\r\n intersect,\r\n rendererNode.computeWorldMatrix().clone().invert(),\r\n intersect\r\n );\r\n }\r\n c.position = KbVector.FromVec3(intersect);\r\n }\r\n\r\n this.sketchPoints.push(c);\r\n }\r\n }\r\n }\r\n });\r\n\r\n this.end.pipe(take(1)).subscribe(() => {\r\n if (!previewVisibleOriginal) {\r\n sketch.paths.forEach(path => {\r\n for (const point of path.controlPoints) {\r\n point._visible = false;\r\n }\r\n });\r\n }\r\n\r\n originalCamera.attachControl(currentCanvas);\r\n this.scene.activeCamera = originalCamera;\r\n if (sketchCamera) {\r\n sketchCamera.dispose();\r\n }\r\n sketch._previewVisible = previewVisibleOriginal;\r\n });\r\n\r\n function getPointOnPlane(ray: Ray) {\r\n const d = ray.intersectsPlane(sketchPlane);\r\n if (typeof d === 'number') {\r\n return ray.origin.add(ray.direction.scale(d));\r\n }\r\n return null;\r\n }\r\n }\r\n\r\n clear() {\r\n this.end.next();\r\n this.kbViewer.rightClickMenu.hideContextMenu();\r\n this.currentOptions = undefined;\r\n this.activeSketch = undefined;\r\n }\r\n\r\n dispose() {\r\n this.kbViewer.rightClickMenu.hideContextMenu();\r\n this.end.next();\r\n this.end.complete();\r\n this.mouseUp.complete();\r\n this.activeSketch = undefined;\r\n }\r\n\r\n private deleteSketchPoint() {\r\n if (this.kbViewer.sceneNode._manager && activeHitPoint) {\r\n const path = activeHitPoint._parent;\r\n const targetPoint = activeHitPoint;\r\n if (path instanceof SketchPath) {\r\n const index = path.controlPoints.findIndex(ec => ec.id === targetPoint.id);\r\n path.controlPoints.splice(index, 1);\r\n }\r\n }\r\n }\r\n\r\n private deleteSketchPath() {\r\n if (this.kbViewer.sceneNode._manager && activeHitPoint) {\r\n if (this.activeSketch) {\r\n const sketch = this.activeSketch;\r\n const targetPoint = activeHitPoint;\r\n sketch.paths.forEach(path => {\r\n if (path instanceof SketchPath) {\r\n const index = path.controlPoints.findIndex(\r\n ec => ec._dynamicId === targetPoint._parent?._dynamicId\r\n );\r\n sketch.paths.splice(index, 1);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n\r\n private separateSketchNode(sketchpathType: eSketchPathType) {\r\n if (this.kbViewer.sceneNode._manager && activeHitPoint) {\r\n // let targetControlPoint: SketchControlPoint | undefined;\r\n const manager = this.kbViewer.sceneNode._manager;\r\n\r\n if (this.activeSketch) {\r\n const sketch = this.activeSketch;\r\n const targetPoint = activeHitPoint;\r\n for (let pathIndex = 0; pathIndex < sketch.paths.length; pathIndex++) {\r\n const path = sketch.paths[pathIndex];\r\n const cpIndex = path.controlPoints.findIndex(ec => ec._dynamicId === targetPoint._dynamicId);\r\n if (cpIndex === -1) {\r\n continue;\r\n }\r\n if (path.type === sketchpathType) {\r\n return;\r\n }\r\n\r\n if (path.controlPoints.length === 1 && sketchpathType === eSketchPathType.arcThrough3Points) {\r\n const newControlPoint2 = createSketchPointForEditor(manager, path);\r\n const newControlPoint3 = createSketchPointForEditor(manager, path);\r\n\r\n let sketchNormal = new Vector3(1, 0, 0);\r\n if (sketch.normal === eAxis.y) {\r\n sketchNormal = new Vector3(0, 1, 0);\r\n } else if (sketch.normal === eAxis.z) {\r\n sketchNormal = new Vector3(0, 0, 1);\r\n }\r\n const controlPointMesh = this.kbViewer.getRendererNode(\r\n sketch.paths[pathIndex].controlPoints[0]\r\n );\r\n const pointOnePosition = sketchNormal.cross(\r\n sketchPlaneIntersect.toVec3().subtract(controlPointMesh.getAbsolutePosition())\r\n );\r\n newControlPoint2.position = new KbVector(\r\n pointOnePosition.x,\r\n pointOnePosition.y,\r\n pointOnePosition.z\r\n );\r\n const pointTwoPosition = sketchNormal.cross(\r\n pointOnePosition.subtract(controlPointMesh.getAbsolutePosition())\r\n );\r\n newControlPoint3.position = new KbVector(\r\n pointTwoPosition.x,\r\n pointTwoPosition.y,\r\n pointTwoPosition.z\r\n );\r\n\r\n path._expanded = true;\r\n path.type = sketchpathType;\r\n this.sketchPoints.push(newControlPoint2);\r\n this.sketchPoints.push(newControlPoint3);\r\n break;\r\n } else if (cpIndex === 0 && sketch.paths[pathIndex - 1]?.type === sketchpathType) {\r\n // If an adjacent path has the same path type as the one we're making, we'll just add the control point to it\r\n // Previous path matching case\r\n const cp = path.controlPoints.shift()!;\r\n\r\n sketch.paths[pathIndex - 1].controlPoints.push(cp.clone()!);\r\n break;\r\n } else if (\r\n // Next path matching case\r\n cpIndex === path.controlPoints.length - 1 &&\r\n sketch.paths[pathIndex + 1]?.type === sketchpathType\r\n ) {\r\n const cp = path.controlPoints.pop()!;\r\n sketch.paths[pathIndex + 1].controlPoints.push(cp.clone()!);\r\n break;\r\n } else if (path.controlPoints.length > 1) {\r\n let selectedControlPoints: SketchControlPoint[];\r\n let previousPath: SketchPath | undefined;\r\n let selectedPath: SketchPath;\r\n let nextPath: SketchPath | undefined;\r\n\r\n if (cpIndex === 0) {\r\n selectedPath = path;\r\n } else {\r\n previousPath = path;\r\n selectedControlPoints = Array.from(\r\n previousPath.controlPoints.splice(cpIndex, path.controlPoints.length - cpIndex)\r\n );\r\n\r\n selectedPath = manager.create(Token.SketchPath);\r\n sketch.paths.splice(pathIndex + 1, 0, selectedPath);\r\n selectedPath.name = 'Path';\r\n selectedControlPoints.reverse();\r\n while (selectedControlPoints.length > 0) {\r\n const cp = manager.clone(selectedControlPoints.pop()!);\r\n cp._visible = true;\r\n selectedPath.controlPoints.push(cp);\r\n this.sketchPoints.push(cp);\r\n }\r\n }\r\n\r\n if (selectedPath.controlPoints.length > 2) {\r\n let nextPathPoints: SketchControlPoint[];\r\n if (\r\n sketchpathType == eSketchPathType.arcThrough3Points &&\r\n selectedPath.controlPoints.length > 3\r\n ) {\r\n nextPathPoints = Array.from(\r\n selectedPath.controlPoints.splice(3, selectedPath.controlPoints.length - 3)\r\n );\r\n } else {\r\n nextPathPoints = Array.from(\r\n selectedPath.controlPoints.splice(1, selectedPath.controlPoints.length - 1)\r\n );\r\n }\r\n\r\n nextPath = manager.create(Token.SketchPath);\r\n sketch.paths.splice(pathIndex + 2, 0, nextPath);\r\n nextPath.name = 'Path';\r\n nextPathPoints.reverse();\r\n while (nextPathPoints.length > 0) {\r\n const cp = manager.clone(nextPathPoints.pop()!);\r\n cp._visible = true;\r\n nextPath.controlPoints.push(cp);\r\n this.sketchPoints.push(cp);\r\n }\r\n }\r\n\r\n selectedPath._expanded = true;\r\n selectedPath.type = sketchpathType;\r\n\r\n if (previousPath) {\r\n const match = manager.clone(selectedPath.controlPoints[0]);\r\n match._visible = true;\r\n previousPath.controlPoints.push(match);\r\n this.sketchPoints.push(match);\r\n }\r\n if (nextPath && nextPath.controlPoints.length > 0) {\r\n const match = manager.clone(nextPath.controlPoints[0]);\r\n match._visible = true;\r\n selectedPath.controlPoints.push(match);\r\n this.sketchPoints.push(match);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private addSketchNodeOnPath(node: SketchNode, faceId: number, pickedPoint: Vector3) {\r\n const index = node._lineSegmentStartingPoints[faceId];\r\n let counter = 0;\r\n const manager = node._manager!;\r\n\r\n for (let pathIndex = 0; pathIndex < node.paths.length; pathIndex++) {\r\n const path = node.paths[pathIndex];\r\n for (let cpIndex = 0; cpIndex < node.paths.length; cpIndex++) {\r\n const controlPoint = path.controlPoints[cpIndex];\r\n if (counter === index) {\r\n const spliceIndex = path.controlPoints.indexOf(controlPoint);\r\n const sketchControlPoint = manager.create(Token.SketchControlPoint);\r\n sketchControlPoint.position = KbVector.FromVec3(pickedPoint);\r\n path.controlPoints.splice(spliceIndex + 1, 0, sketchControlPoint);\r\n sketchControlPoint._visible = true;\r\n sketchControlPoint._expanded = true;\r\n this.sketchPoints.push(sketchControlPoint);\r\n return;\r\n }\r\n counter++;\r\n }\r\n }\r\n }\r\n\r\n private getRightClickButtons() {\r\n return [\r\n { label: 'delete node', callback: () => this.deleteSketchPoint() },\r\n { label: 'delete path', callback: () => this.deleteSketchPath() },\r\n { label: 'convert to cubic bezier', callback: () => this.separateSketchNode(eSketchPathType.cubicBezier) },\r\n {\r\n label: 'convert to quadratic bezier',\r\n callback: () => this.separateSketchNode(eSketchPathType.quadraticBezier),\r\n },\r\n { label: 'convert to hermite', callback: () => this.separateSketchNode(eSketchPathType.hermite) },\r\n { label: 'convert to catmullrom', callback: () => this.separateSketchNode(eSketchPathType.catmullRom) },\r\n { label: 'convert to points', callback: () => this.separateSketchNode(eSketchPathType.points) },\r\n {\r\n label: 'arc through 3 points',\r\n callback: () => this.separateSketchNode(eSketchPathType.arcThrough3Points),\r\n },\r\n ];\r\n }\r\n\r\n private getRightClickButtonsForLines(node: SketchNode, faceId: number, pickedPoint: Vector3) {\r\n return [\r\n {\r\n label: 'add point on line',\r\n callback: () => this.addSketchNodeOnPath(node, faceId, pickedPoint),\r\n },\r\n ];\r\n }\r\n}\r\n","import { Scene } from '@babylonjs/core/scene';\r\nimport { ViewpointNode } from '@models/classes/viewpoints/viewpoint-node';\r\nimport { dataURLtoBlob, downloadBlob } from '@view/helpers/blob-helper';\r\nimport { KbViewer } from '../kb-viewer';\r\n\r\nexport enum eSnapshotType {\r\n image = 'image',\r\n blob = 'blob',\r\n dataUrl = 'dataUrl',\r\n}\r\n\r\nexport interface ISnapshotArgs {\r\n dataType: eSnapshotType;\r\n width: number;\r\n height: number;\r\n frameCamera?: boolean;\r\n framePadding?: number;\r\n viewpoint?: string;\r\n mimeType?: string; //defaults to \"image/png\"\r\n filename?: string;\r\n}\r\n\r\nexport class SnapshotModule {\r\n constructor(private v: KbViewer, private scene: Scene) {}\r\n\r\n public take(args: ISnapshotArgs): Promise {\r\n if (args.dataType == eSnapshotType.image) {\r\n return this.download(args);\r\n } else if (args.dataType == eSnapshotType.blob) {\r\n return this.takeAsBlob(args);\r\n } else {\r\n return this.takeAsDataUrl(args);\r\n }\r\n }\r\n\r\n public takeAsDataUrl(args: ISnapshotArgs): Promise {\r\n //set the viewpoint\r\n let viewpointSet = false;\r\n if (args.viewpoint) {\r\n const viewpoint = this.v.sceneNode._manager!.getNodeByIdOrName(args.viewpoint);\r\n if (!viewpoint) {\r\n throw `Could not find viewpoint ${args.viewpoint} for snapshot`;\r\n } else {\r\n this.v.camera.storeCameraSettings();\r\n this.v.camera.moveCameraToViewpoint(viewpoint);\r\n viewpointSet = true;\r\n }\r\n }\r\n\r\n return this.v\r\n .whenAssetsLoaded()\r\n .then(() => {\r\n if (args.frameCamera) {\r\n this.v.camera.frameCamera(this.v.sceneNode, {\r\n padding: args.framePadding,\r\n });\r\n }\r\n return this.v.forceAndWaitForNextRender().then(() => {\r\n return this.v.forceAndWaitForNextRender();\r\n });\r\n })\r\n .then(() => {\r\n const engine = this.v.scene.getEngine();\r\n const mimeType = args.mimeType || 'image/png';\r\n const snapshotCanvas = document.createElement('canvas');\r\n snapshotCanvas.width = args.width;\r\n snapshotCanvas.height = args.height;\r\n const renderContext = snapshotCanvas.getContext('2d');\r\n const ratio = engine.getRenderWidth() / engine.getRenderHeight();\r\n let newWidth = args.width;\r\n let newHeight = newWidth / ratio;\r\n if (newHeight > args.height) {\r\n newHeight = args.height;\r\n newWidth = newHeight * ratio;\r\n }\r\n const offsetX = Math.max(0, args.width - newWidth) / 2;\r\n const offsetY = Math.max(0, args.height - newHeight) / 2;\r\n const renderingCanvas = engine.getRenderingCanvas();\r\n if (renderContext && renderingCanvas) {\r\n renderContext.drawImage(renderingCanvas, offsetX, offsetY, newWidth, newHeight);\r\n }\r\n const dataUrl = snapshotCanvas.toDataURL(mimeType);\r\n if (viewpointSet) {\r\n this.v.camera.restoreCameraSettings();\r\n }\r\n snapshotCanvas.width = 0;\r\n snapshotCanvas.height = 0;\r\n return dataUrl;\r\n });\r\n }\r\n\r\n public takeAsBlob(args: ISnapshotArgs): Promise {\r\n return this.takeAsDataUrl(args).then(dataUrl => dataURLtoBlob(dataUrl));\r\n }\r\n\r\n public download(args: ISnapshotArgs): Promise {\r\n return this.takeAsBlob(args).then(blob => downloadBlob(blob, args.filename));\r\n }\r\n}\r\n","export function downloadBlob(blob: Blob, filename = 'download') {\r\n const url = URL.createObjectURL(blob);\r\n const a = document.createElement('a');\r\n a.href = url;\r\n a.download = filename || 'download';\r\n\r\n const clickHandler = () => {\r\n setTimeout(() => {\r\n URL.revokeObjectURL(url);\r\n a.removeEventListener('click', clickHandler);\r\n }, 150);\r\n };\r\n a.addEventListener('click', clickHandler, false);\r\n a.click();\r\n}\r\n\r\nexport function dataURLtoBlob(dataurl: string) {\r\n const arr = dataurl.split(',');\r\n const mime = arr[0].match(/:(.*?);/)![1];\r\n const bstr = atob(arr[1]);\r\n let n = bstr.length;\r\n const u8arr = new Uint8Array(n);\r\n\r\n while (n--) {\r\n u8arr[n] = bstr.charCodeAt(n);\r\n }\r\n return new Blob([u8arr], { type: mime });\r\n}\r\n","import { Engine } from '@babylonjs/core/Engines/engine';\r\nimport { RenderTargetTexture } from '@babylonjs/core/Materials/Textures/renderTargetTexture';\r\nimport { Effect } from '@babylonjs/core/Materials/effect';\r\nimport { ShaderMaterial } from '@babylonjs/core/Materials/shaderMaterial';\r\nimport { Color4 } from '@babylonjs/core/Maths';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport { PostProcessRenderEffect } from '@babylonjs/core/PostProcesses/RenderPipeline/postProcessRenderEffect';\r\nimport { PostProcessRenderPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/postProcessRenderPipeline';\r\nimport { PostProcess } from '@babylonjs/core/PostProcesses/postProcess';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbViewer } from '../kb-viewer';\r\nimport { CameraTools } from './camera-tools';\r\nimport maskFragmentShader from './shaders/mask-fragment-shader.fx';\r\nimport maskVertexShader from './shaders/mask-vertex-shader.fx';\r\nimport outlineFragmentShader from './shaders/outline-fragment-shader.fx';\r\n\r\nexport interface IHoverRenderer {\r\n hoverNode(node: SpaceNode): void;\r\n clearHover(): void;\r\n}\r\n\r\nEffect.ShadersStore['customMaskVertexShader'] = maskVertexShader;\r\nEffect.ShadersStore['customMaskFragmentShader'] = maskFragmentShader;\r\nEffect.ShadersStore['simpleOutlineFragmentShader'] = outlineFragmentShader;\r\n\r\nexport class Highlighter {\r\n highlightPipeline: PostProcessRenderPipeline;\r\n postProcess: PostProcess;\r\n renderTarget: RenderTargetTexture;\r\n\r\n private engine: Engine;\r\n\r\n constructor(\r\n private kbViewer: KbViewer,\r\n private scene: Scene,\r\n public defaultHighlightColor: KbColor,\r\n cameraManager: CameraTools\r\n ) {\r\n this.engine = scene.getEngine();\r\n this.highlightPipeline = new PostProcessRenderPipeline(this.engine, 'highlightPipeline');\r\n\r\n this.renderTarget = new RenderTargetTexture('Highlight render target', 1024, scene, { samples: 2 });\r\n this.renderTarget.renderList = [];\r\n this.renderTarget.clearColor = new Color4(0, 0, 0, 0);\r\n scene.customRenderTargets.push(this.renderTarget);\r\n\r\n this.postProcess = new PostProcess(\r\n 'Highlighter post process',\r\n 'simpleOutline',\r\n ['screenSize', 'threshold', 'lineWidth', 'debug'],\r\n ['maskSampler'],\r\n 1.0,\r\n null,\r\n undefined,\r\n this.engine,\r\n true\r\n );\r\n // This may help with the highlight separating from the scene meshes, if we can ge the highlight to combine with the scene\r\n // this.postProcess.autoClear = false;\r\n // this.postProcess.alphaMode = Engine.ALPHA_COMBINE;\r\n this.postProcess.samples = 4;\r\n this.postProcess.onApply = effect => {\r\n effect.setFloat2('screenSize', this.postProcess.width, this.postProcess.height);\r\n effect.setFloat('threshold', 0.3);\r\n effect.setFloat('lineWidth', 4.0);\r\n effect.setBool('debug', false);\r\n effect.setTexture('maskSampler', this.renderTarget);\r\n (window as any).enableHighlightDebug = () => {\r\n enableHighlightDebug(effect);\r\n };\r\n };\r\n const highlightEffect = new PostProcessRenderEffect(\r\n this.engine,\r\n 'highlightEffect',\r\n () => [this.postProcess],\r\n false\r\n );\r\n this.highlightPipeline.addEffect(highlightEffect);\r\n this.scene.postProcessRenderPipelineManager.addPipeline(this.highlightPipeline);\r\n cameraManager.setPipeline(this.highlightPipeline);\r\n\r\n function enableHighlightDebug(effect: Effect) {\r\n effect.setBool('debug', true);\r\n }\r\n }\r\n\r\n private colorMap = new Map<\r\n string,\r\n {\r\n material: ShaderMaterial;\r\n meshes: Set;\r\n }\r\n >();\r\n private nodeColors = new Map();\r\n private activeHover: SpaceNode | undefined;\r\n private highlighterDb = new Map();\r\n\r\n public has(node: SpaceNode) {\r\n return this.highlighterDb.has(node._dynamicId);\r\n }\r\n\r\n public add(node: SpaceNode, color: KbColor = this.defaultHighlightColor) {\r\n this.startPostProcess();\r\n\r\n const renderNode = this.kbViewer.getRendererNode(node);\r\n this.highlighterDb.set(node._dynamicId, color);\r\n this.addHighlightToRendered(renderNode, color);\r\n }\r\n\r\n public remove(node: SpaceNode) {\r\n if (this.highlighterDb.has(node._dynamicId)) {\r\n const renderNode = this.kbViewer.getRendererNode(node);\r\n if (this.activeHover?._dynamicId !== node._dynamicId) {\r\n // Don't remove the highlight from a hover. Once the hover clears the highlight will be cleared.\r\n this.removeHighlightFromRendered(renderNode);\r\n this.highlighterDb.delete(node._dynamicId);\r\n }\r\n }\r\n }\r\n\r\n public hover(node: SpaceNode) {\r\n if (node != this.activeHover) {\r\n this.startPostProcess();\r\n this.clearHover();\r\n this.activeHover = node;\r\n const renderNode = this.kbViewer.getRendererNode(node);\r\n this.addHighlightToRendered(renderNode, this.defaultHighlightColor);\r\n this.kbViewer.canvas!.style.cursor = 'pointer';\r\n this.scene.defaultCursor = 'pointer';\r\n this.kbViewer.forceRenderOnNextFrame = true;\r\n }\r\n }\r\n\r\n public clearHover() {\r\n if (this.activeHover) {\r\n const renderNode = this.kbViewer.getRendererNode(this.activeHover);\r\n this.removeHighlightFromRendered(renderNode);\r\n //if the node had a highlight previously, restore it\r\n if (this.highlighterDb.has(this.activeHover._dynamicId)) {\r\n const color = this.highlighterDb.get(this.activeHover._dynamicId)!;\r\n this.addHighlightToRendered(renderNode, color);\r\n }\r\n // const targets = renderNode instanceof AbstractMesh ? [renderNode] : renderNode.getChildMeshes();\r\n // for (const target of targets) {\r\n // if (this.highlighterDb.has(target)) {\r\n // const color = this.highlighterDb.get(target)!;\r\n // this.addHighlightToRendered(target, color);\r\n // }\r\n // }\r\n this.activeHover = undefined;\r\n this.kbViewer.canvas!.style.cursor = 'default';\r\n this.scene.defaultCursor = 'default';\r\n this.kbViewer.forceRenderOnNextFrame = true;\r\n }\r\n }\r\n\r\n public clearAll() {\r\n this.colorMap.forEach(entry => {\r\n this.renderTarget.setMaterialForRendering(Array.from(entry.meshes), undefined);\r\n });\r\n if (this.renderTarget.renderList) {\r\n while (this.renderTarget.renderList.length > 0) {\r\n this.renderTarget.renderList.pop();\r\n }\r\n }\r\n this.nodeColors.clear();\r\n this.highlighterDb.clear();\r\n this.colorMap.clear();\r\n this.activeHover = undefined;\r\n }\r\n\r\n private addHighlightToRendered(node: TransformNode, color: KbColor) {\r\n const targets = node instanceof AbstractMesh ? [node] : node.getChildMeshes();\r\n for (const renderNode of targets) {\r\n if (this.renderTarget.renderList?.contains(renderNode) === false) {\r\n if (!this.renderTarget.renderList) {\r\n this.renderTarget.renderList = [];\r\n }\r\n this.renderTarget.renderList.push(renderNode);\r\n }\r\n let colorMapKey = '';\r\n\r\n if (color) {\r\n colorMapKey = this.colorToString(color);\r\n } else {\r\n colorMapKey = this.colorToString(this.defaultHighlightColor);\r\n }\r\n\r\n this.addNodeToColorMap(colorMapKey, renderNode, color);\r\n this.nodeColors.set(renderNode, colorMapKey);\r\n }\r\n }\r\n\r\n private removeHighlightFromRendered(node: TransformNode) {\r\n const targets = node instanceof AbstractMesh ? [node] : node.getChildMeshes();\r\n for (const renderNode of targets) {\r\n const colorKey = this.nodeColors.get(renderNode);\r\n this.renderTarget.renderList?.remove(renderNode);\r\n if (colorKey) {\r\n this.removeNodeFromColorMap(colorKey, renderNode);\r\n this.nodeColors.delete(renderNode);\r\n }\r\n }\r\n }\r\n\r\n private addNodeToColorMap(colorMapKey: string, node: AbstractMesh, color?: KbColor) {\r\n let colorMapEntry = this.colorMap.get(colorMapKey);\r\n if (!colorMapEntry) {\r\n const newShader = new ShaderMaterial('customMaskMat_' + colorMapKey, this.scene, 'customMask', {\r\n attributes: ['position', 'uv'],\r\n uniforms: ['worldViewProjection', 'color', 'lineColor'],\r\n });\r\n if (color) {\r\n newShader.setColor4('lineColor', color.toColor4());\r\n } else {\r\n newShader.setColor4('lineColor', this.defaultHighlightColor.toColor4());\r\n }\r\n colorMapEntry = {\r\n material: newShader,\r\n meshes: new Set(),\r\n };\r\n }\r\n colorMapEntry.meshes.add(node);\r\n this.renderTarget.setMaterialForRendering(Array.from(colorMapEntry.meshes), colorMapEntry.material);\r\n }\r\n\r\n private removeNodeFromColorMap(colorMapKey: string, node: AbstractMesh) {\r\n const colorMapEntry = this.colorMap.get(colorMapKey);\r\n if (colorMapEntry) {\r\n colorMapEntry.meshes.delete(node);\r\n this.renderTarget.setMaterialForRendering(node, undefined);\r\n }\r\n }\r\n\r\n private colorToString(color: KbColor) {\r\n return color.cssString();\r\n }\r\n\r\n private startPostProcess() {}\r\n}\r\n","import { Scene } from '@babylonjs/core/scene';\r\nimport { KbViewer } from '@view/kb-viewer';\r\n\r\nexport class RightClickMenu {\r\n constructor(private viewer: KbViewer, private scene: Scene) {}\r\n\r\n isOpen() {\r\n return this.contextMenuOpen;\r\n }\r\n\r\n private contextmenu?: HTMLDivElement;\r\n private contextMenuOpen = false;\r\n\r\n showContextMenu(xPosition: number, yPosition: number, buttons: Array<{ label: string; callback: () => void }>) {\r\n this.createContextMenu(xPosition, yPosition, buttons);\r\n if (this.viewer.uiOverlay && this.contextmenu) {\r\n this.viewer.container.appendChild(this.contextmenu);\r\n this.contextMenuOpen = true;\r\n }\r\n }\r\n\r\n hideContextMenu() {\r\n if (this.contextmenu) {\r\n this.contextmenu.style.display = 'none';\r\n this.contextMenuOpen = false;\r\n }\r\n }\r\n\r\n private createContextMenu(\r\n xPosition: number,\r\n yPosition: number,\r\n buttons: Array<{ label: string; callback: () => void }>\r\n ) {\r\n //const buttons = [];\r\n if (this.contextmenu && this.viewer.container.contains(this.contextmenu)) {\r\n this.viewer.container?.removeChild(this.contextmenu);\r\n }\r\n const contextMenu = document.createElement('div');\r\n contextMenu.style.position = 'absolute';\r\n contextMenu.style.top = yPosition.toString() + 'px';\r\n contextMenu.style.left = (xPosition + 10).toString() + 'px';\r\n contextMenu.style.width = 'auto';\r\n contextMenu.style.height = 'auto';\r\n contextMenu.style.zIndex = '2';\r\n contextMenu.addEventListener('click', e => {\r\n if (e.button === 2) {\r\n e.preventDefault();\r\n e.stopImmediatePropagation();\r\n }\r\n });\r\n document.addEventListener('click', e => {\r\n if (e.button != 2) {\r\n this.hideContextMenu();\r\n }\r\n });\r\n document.addEventListener('wheel', e => {\r\n this.hideContextMenu();\r\n });\r\n contextMenu.addEventListener('scroll', e => {\r\n if (this.contextmenu) {\r\n this.contextmenu.style.display = 'none';\r\n }\r\n });\r\n\r\n this.contextmenu = contextMenu;\r\n\r\n buttons.forEach(button => {\r\n const newButton = document.createElement('div');\r\n newButton.innerText = button.label;\r\n newButton.addEventListener('click', e => {\r\n button.callback();\r\n this.hideContextMenu();\r\n });\r\n this.contextmenu?.appendChild(newButton);\r\n newButton.style.zIndex = '100000';\r\n newButton.style.color = 'white';\r\n newButton.style.background = 'rgba(36,36,36,255)';\r\n newButton.style.cursor = 'pointer';\r\n newButton.style.padding = '10px';\r\n newButton.addEventListener('mouseover', e => {\r\n newButton.style.background = 'rgba(61,61,61,255)';\r\n });\r\n newButton.addEventListener('mouseout', e => {\r\n newButton.style.background = 'rgba(36,36,36,255)';\r\n });\r\n });\r\n }\r\n}\r\n","import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';\r\nimport { Engine } from '@babylonjs/core/Engines/engine';\r\nimport '@babylonjs/core/Helpers/sceneHelpers';\r\nimport '@babylonjs/core/Layers/effectLayerSceneComponent'; // Required by highlight layer\r\nimport { Light, PointLight, SpotLight } from '@babylonjs/core/Lights';\r\nimport { Color3, Color4, Quaternion, Vector3 } from '@babylonjs/core/Maths';\r\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\r\nimport { VertexBuffer } from '@babylonjs/core/Meshes/buffer';\r\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\r\nimport { TransformNode } from '@babylonjs/core/Meshes/transformNode';\r\nimport {\r\n HardwareScalingOptimization,\r\n LensFlaresOptimization,\r\n ParticlesOptimization,\r\n PostProcessesOptimization,\r\n RenderTargetsOptimization,\r\n SceneOptimizer,\r\n SceneOptimizerOptions,\r\n ShadowsOptimization,\r\n TextureOptimization,\r\n} from '@babylonjs/core/Misc/sceneOptimizer';\r\nimport { SceneSerializer } from '@babylonjs/core/Misc/sceneSerializer';\r\nimport '@babylonjs/core/Rendering/depthRendererSceneComponent'; // For SSAO Pipeline\r\nimport '@babylonjs/core/Rendering/edgesRenderer'; // Required by mesh renderOverlay\r\nimport '@babylonjs/core/Rendering/geometryBufferRendererSceneComponent'; // For SSRPrepass and LensPipeline\r\nimport '@babylonjs/core/Rendering/outlineRenderer'; // Required by mesh renderOverlay\r\nimport '@babylonjs/core/Rendering/prePassRendererSceneComponent'; // For SSRPrepass and LensPipeline\r\nimport { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';\r\nimport { Scene } from '@babylonjs/core/scene';\r\nimport { DeepImmutableObject } from '@babylonjs/core/types';\r\n// import \"@babylonjs/loaders/glTF\";\r\n// import '@babylonjs/loaders/glTF/2.0';\r\n// import \"@babylonjs/loaders/OBJ\";\r\nimport { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';\r\nimport { BaseTexture } from '@babylonjs/core/Materials/Textures/baseTexture';\r\nimport { Texture } from '@babylonjs/core/Materials/Textures/texture';\r\nimport { Material } from '@babylonjs/core/Materials/material';\r\nimport { MultiMaterial } from '@babylonjs/core/Materials/multiMaterial';\r\nimport { VertexData } from '@babylonjs/core/Meshes/mesh.vertexData';\r\nimport {\r\n BaseConnector,\r\n IVertexGroup,\r\n KbQuaternion,\r\n MateNode,\r\n MeshGroupNode,\r\n NormalSmoothingFeature,\r\n SketchNode,\r\n} from '@models/classes';\r\nimport { nextTick } from '@models/classes/decorators/change-tracker';\r\nimport { eLoadingExperience, eRenderMode, eViewpointTargetMode, eViewpointType } from '@models/classes/enums';\r\nimport { isConnector } from '@models/classes/features/connector';\r\nimport { Kb3dManager } from '@models/classes/kb3d-manager';\r\nimport { Kb3dObject } from '@models/classes/kb3d-object';\r\nimport { LightNode, isLightNode } from '@models/classes/lights/light-node';\r\nimport { MaterialNode, TextureLayer, isMaterialNode, isTextureLayer } from '@models/classes/materials';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { isSketchControlPoint, isSpaceNode } from '@models/classes/meshes/mesh-utilities';\r\nimport { SpaceNode } from '@models/classes/meshes/space-node';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbGeometry } from '@models/classes/primitives/kb-geometry';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { SceneNode, isSceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { Validator } from '@models/classes/validator';\r\nimport { ViewpointNode } from '@models/classes/viewpoints';\r\nimport { KBMAXPREFIX } from '@models/constants';\r\nimport { SettingsManagerService } from '@models/services/settings-manager-service';\r\nimport { SyncService } from '@models/services/sync-service';\r\nimport { Observable, Subject } from 'rxjs';\r\nimport { take, throttleTime } from 'rxjs/operators';\r\nimport { GuiHelper } from './helpers/gui-helper';\r\nimport './helpers/imagedata-polyfill';\r\nimport { IScreenBoundingBox, getScreenBoundingBox, nodeToScreen } from './helpers/scene-helper';\r\nimport { Kb3dWorker } from './kb-worker';\r\nimport { SketchEditor, SnapshotModule } from './modules';\r\nimport { AnimationModule } from './modules/animation';\r\nimport { AR } from './modules/ar';\r\nimport { BoundingBoxCache } from './modules/bounding-box-cache';\r\nimport { CameraTools } from './modules/camera-tools';\r\nimport { GLTFKb3dExporter } from './modules/exporter-gltf';\r\nimport { ObjKb3dExporter } from './modules/exporter-obj';\r\nimport { GizmoTools } from './modules/gizmo-tools';\r\nimport { Highlighter } from './modules/highlighter';\r\nimport { Interaction } from './modules/interaction';\r\nimport { RightClickMenu } from './modules/right-click-menu';\r\nimport { SvgConverter } from './modules/sketching/svg-converter';\r\nimport { RendererManager } from './render/renderer-manager';\r\n\r\nexport { IScreenBoundingBox };\r\n\r\ninterface IKbViewerOptions {\r\n /** HTML Element to insert the viewer canvas into. Can be any block-level element. */\r\n container: HTMLElement;\r\n debugMode?: boolean;\r\n highlightColor?: KbColor;\r\n editorMode?: boolean;\r\n enableScreenshots?: boolean;\r\n forceDisablePostProcess?: boolean;\r\n forceDisableGraphicsOptimization?: boolean;\r\n /** optionally provide a path to the kb3d webworker script. Defaults to worker3d.js */\r\n webworkerPath?: string;\r\n /** optionally provide a validator to validate nodes. Only used by creator */\r\n validator?: Validator;\r\n}\r\ninterface ILoadSceneOptions {\r\n sceneNode: SceneNode;\r\n /** overrides the default viewpoint of the scene */\r\n viewpoint?: ViewpointNode;\r\n /** overrides the frame option for the default viewpoint */\r\n frameViewpoint?: boolean;\r\n /** overrides the loading experience of the scene */\r\n loadingExperience?: eLoadingExperience;\r\n /** If provided, will defer the end of the loading experience until the promise resolves */\r\n deferLoadingPromise?: Promise;\r\n}\r\n\r\nexport interface IMeshSelectedEvent {\r\n node: Kb3dObject;\r\n multiSelect: boolean;\r\n}\r\n\r\nexport interface IAfterRenderArgs {\r\n /** Whether the render was skipped because nothing had changed from the last render */\r\n skipped: boolean;\r\n}\r\n\r\nconst FADE_TIME = 300;\r\n/**\r\n * Applcation class for the viewer, to contain all of the initializers and hooks and connect the modules and 3d engine.\r\n * @param canvasElement An HTML DOM element that the viewer will be attached to\r\n */\r\nexport class KbViewer {\r\n options: IKbViewerOptions;\r\n\r\n constructor(options: IKbViewerOptions) {\r\n this.options = {\r\n highlightColor: KbColor.KbmaxOrange(),\r\n editorMode: false,\r\n forceDisablePostProcess: false,\r\n enableScreenshots: false,\r\n debugMode: false,\r\n webworkerPath: '/worker3d.js',\r\n ...options,\r\n };\r\n\r\n if (typeof window !== 'undefined' && options.webworkerPath && !options.webworkerPath.startsWith('http')) {\r\n this.options.webworkerPath = `${window.location.protocol}//${window.location.host}${this.options.webworkerPath}`;\r\n }\r\n\r\n Kb3dWorker.workerPath = this.options.webworkerPath!;\r\n\r\n // Create canvas and engine.\r\n this.container = options.container;\r\n this.canvas = this.createCanvas();\r\n // Anti-aliasing=true (second parameter) causes the canvas to not get cleared on iOS 15.4. Warrants testing in future iOS updates.\r\n const iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);\r\n this.engine = new Engine(\r\n this.canvas,\r\n !iOS,\r\n { stencil: true, preserveDrawingBuffer: this.options.enableScreenshots },\r\n true\r\n ); //set adaptToDeviceRatio to true, and let the hardware scaling optimizer take over from there\r\n this.engine.setAlphaMode(Engine.ALPHA_COMBINE);\r\n this.glInfo = this.engine.getGlInfo();\r\n // eslint-disable-next-line no-console\r\n console.log('WebGL Renderer', this.glInfo.vendor, this.glInfo.renderer, this.glInfo.version);\r\n\r\n // Create the scene.\r\n const scene = this.createScene();\r\n this.scene = scene;\r\n this.scene.hoverCursor = 'pointer';\r\n this.utilityLayer = new UtilityLayerRenderer(this.scene);\r\n this.utilityLayer.utilityLayerScene.useRightHandedSystem = true;\r\n this.utilityLayer.processAllEvents = true;\r\n\r\n this.camera = new CameraTools(this.scene, this.canvas, this);\r\n this.bbCache = new BoundingBoxCache(this);\r\n\r\n // var hdrTexture = CubeTexture.CreateFromPrefilteredData('/assets/environments/environment.dds', scene);\r\n // hdrTexture.gammaSpace = false;\r\n // scene.environmentTexture = hdrTexture;\r\n this.highlightColor = options.highlightColor || KbColor.KbmaxOrange();\r\n\r\n this.gizmos = new GizmoTools(scene, this);\r\n this.rightClickMenu = new RightClickMenu(this, this.scene);\r\n this.animation = new AnimationModule(this, this.scene);\r\n this.highlighter = new Highlighter(this, this.scene, this.highlightColor, this.camera);\r\n this.interaction = new Interaction(this, this.scene, this.highlighter);\r\n this.sketchEditor = new SketchEditor(this, this.scene, this.highlightColor);\r\n this.gui = new GuiHelper(scene, this.highlighter);\r\n this.ar = new AR(this, scene);\r\n this.snapshot = new SnapshotModule(this, scene);\r\n this.rendererManager = new RendererManager(this, scene);\r\n\r\n this.interaction.attachScene(this.utilityLayer.utilityLayerScene, true);\r\n this.gltfExporter = new GLTFKb3dExporter(scene);\r\n this.objExporter = new ObjKb3dExporter(scene, this.rendererManager);\r\n }\r\n\r\n /** Public Properties */\r\n public scene: Scene;\r\n public forceRenderOnNextFrame = false;\r\n public pauseRender = false;\r\n public canvas?: HTMLCanvasElement;\r\n public uiOverlay?: HTMLDivElement;\r\n public loadingOverlay?: HTMLDivElement;\r\n //public contextmenu?: HTMLDivElement;\r\n public container: HTMLElement;\r\n public sceneNode: SceneNode;\r\n public renderMode: eRenderMode.shaded;\r\n public warningMessages: string[];\r\n public lightsWarningMessages: string[];\r\n public textureWarningMessages: string[];\r\n public MeshWarningTracker = new Map<\r\n string,\r\n {\r\n name: string;\r\n isEnabled: boolean;\r\n castShadows: boolean;\r\n receiveShadows: boolean;\r\n polygonNumber: number;\r\n featureNumber: number;\r\n }\r\n >();\r\n public meshWarningMessages: string[];\r\n public materialWarningMessages: string[];\r\n public normalSmoothingWarnings = new Map();\r\n public totalPolygons: number;\r\n\r\n /** Events / Observables */\r\n /** observable for tracking when something changed that could affect the position of a node on the screen */\r\n public viewChanged = new Subject();\r\n public afterRender = new Subject();\r\n public fpsTracker = new Subject();\r\n public polygonTracker = new Subject<{ polygons: number; vertices: number }>();\r\n public warningTracker = new Subject<{ warningMessages: string[] }>();\r\n public meshWarningsNeedsUpdate = new Subject();\r\n public materialWarningsNeedsUpdate = new Subject();\r\n public animationWarningsNeedsUpdate = new Subject();\r\n\r\n /** Modules */\r\n public rendererManager: RendererManager;\r\n public readonly interaction: Interaction;\r\n public gizmos: GizmoTools;\r\n public rightClickMenu: RightClickMenu;\r\n public camera: CameraTools;\r\n public gui: GuiHelper;\r\n public sketchEditor: SketchEditor;\r\n public svgConverter: SvgConverter;\r\n public bbCache: BoundingBoxCache;\r\n public readonly animation: AnimationModule;\r\n public readonly highlighter: Highlighter;\r\n public readonly ar: AR;\r\n public readonly snapshot: SnapshotModule;\r\n public readonly utilityLayer: UtilityLayerRenderer;\r\n public readonly glInfo: {\r\n vendor: string;\r\n renderer: string;\r\n version: string;\r\n };\r\n public highlightColor: KbColor;\r\n\r\n private disposed = false;\r\n private forceRunRenderer = false;\r\n private engine: Engine;\r\n private manager: Kb3dManager;\r\n private gltfExporter: GLTFKb3dExporter;\r\n private objExporter: ObjKb3dExporter;\r\n private isDevEnvironment = false;\r\n /** tracks babylon nodes who are being tracked for positions (hotspots) */\r\n private positionTrackedNodes = new Map();\r\n\r\n private nextFrameCallbacks: Array<() => void> = [];\r\n private resizeObserver?: ResizeObserver;\r\n private _renderLoopRunning = false;\r\n private allAssetsLoaded = false;\r\n\r\n /** tracks any additional promises that renders and load spinners should wait for */\r\n private additionalLoadBlockers: Array> = [];\r\n\r\n get settings() {\r\n return SettingsManagerService;\r\n }\r\n\r\n setRenderMode(mode: eRenderMode, force?: boolean) {\r\n this.rendererManager.setRenderMode(mode, this.sceneNode, force);\r\n }\r\n\r\n loadScene(o: ILoadSceneOptions) {\r\n if (!o.sceneNode._manager) {\r\n throw 'sceneNode must be constructed with a manager';\r\n }\r\n\r\n this.sceneNode = o.sceneNode;\r\n this.manager = o.sceneNode._manager as Kb3dManager;\r\n this.isDevEnvironment = this.manager.isDevEnvironment;\r\n\r\n const loadingExperience = o.loadingExperience || this.sceneNode.loadingExperience;\r\n this.createLoadingExperience(loadingExperience, this.sceneNode.loadingImagePath);\r\n\r\n let viewpoint =\r\n o.viewpoint ||\r\n (o.sceneNode.viewpointId ? this.manager.getById(o.sceneNode.viewpointId) : undefined);\r\n if (!viewpoint) {\r\n viewpoint = this.manager.create(Token.ViewpointNode);\r\n viewpoint.type = eViewpointType.orbit;\r\n viewpoint.targetMode = eViewpointTargetMode.point;\r\n viewpoint.position = new KbVector(3, 3, 3);\r\n viewpoint.targetPoint = KbVector.Zero();\r\n }\r\n this.camera.moveCameraToViewpoint(viewpoint);\r\n\r\n // Start render loop.\r\n this.startRender();\r\n\r\n // The canvas/window resize event handler.\r\n // window.addEventListener('resize', () => {\r\n // if (!this.ar.xrLoading && !this.ar.xrActive) { //don't mess with the AR canvas resize\r\n // this.engine.resize();\r\n // this.viewChanged.next();\r\n // }\r\n // });\r\n\r\n const promises = [this.whenAssetsLoaded()];\r\n if (o.deferLoadingPromise) promises.push(o.deferLoadingPromise);\r\n\r\n return Promise.all(promises).then(() => {\r\n const http = this.sceneNode._manager?.getService(Token.HttpService);\r\n\r\n let frame = true;\r\n if (this.sceneNode.viewpointId) frame = this.sceneNode.frameViewpoint;\r\n if (o.frameViewpoint != null) frame = o.frameViewpoint;\r\n\r\n if (frame) {\r\n this.camera.frameCamera(this.sceneNode);\r\n }\r\n this.hideLoadingExperience();\r\n\r\n // Wait for everything to be loaded and processed before trying to optimize scene because the scene optimizer watches the FPS and we want the state to be stable\r\n // Disable the graphics optimization (for example when rendering)\r\n if (!this.options.forceDisableGraphicsOptimization) {\r\n this.waitForNextKb3dRender().then(() => {\r\n this.optimizeScene(this.scene);\r\n });\r\n }\r\n\r\n this.meshWarningsNeedsUpdate\r\n .pipe(throttleTime(1000, undefined, { leading: true, trailing: true }))\r\n .subscribe(() => {\r\n this.updateMeshWarnings();\r\n this.updateTextureWarnings();\r\n });\r\n\r\n this.materialWarningsNeedsUpdate\r\n .pipe(throttleTime(15000, undefined, { leading: true, trailing: false }))\r\n .subscribe(() => {\r\n this.updateMaterialWarnings();\r\n });\r\n\r\n this.animationWarningsNeedsUpdate.subscribe(value => {\r\n this.updateAnimationWarnings(value);\r\n });\r\n this.updateTextureWarnings();\r\n this.updateLightWarnings();\r\n this.updateMaterialWarnings();\r\n if (http) {\r\n http.executeDeferredCalls();\r\n }\r\n });\r\n }\r\n\r\n getNode(id: string) {\r\n return this.manager.getById(id);\r\n }\r\n\r\n getRendererNode(n: LightNode): Light;\r\n getRendererNode(n: SpaceNode): TransformNode | AbstractMesh;\r\n getRendererNode(n: BaseConnector): TransformNode;\r\n getRendererNode(n: MaterialNode): PBRMaterial;\r\n getRendererNode(n: TextureLayer): Texture;\r\n getRendererNode(n: Kb3dObject | TextureLayer) {\r\n if (isSceneNode(n) && n.isNested() === false) {\r\n return this.rendererManager.sceneRenderer.get3d(n);\r\n } else if (isSceneNode(n) && n.isNested()) {\r\n return this.rendererManager.mesh.get3d(n);\r\n } else if (isLightNode(n)) {\r\n return this.rendererManager.light.get3d(n);\r\n } else if (isSpaceNode(n)) {\r\n return this.rendererManager.mesh.get3d(n);\r\n } else if (isMaterialNode(n)) {\r\n return this.rendererManager.material.get3d(n);\r\n } else if (isConnector(n)) {\r\n return this.rendererManager.connector.get3d(n);\r\n } else if (isSketchControlPoint(n)) {\r\n return this.rendererManager.controlPointRenderer.get3d(n);\r\n } else if (isTextureLayer(n)) {\r\n return this.rendererManager.textures.get3d(n);\r\n }\r\n return undefined;\r\n }\r\n\r\n getFPS() {\r\n return this.engine.getFps().toFixed();\r\n }\r\n\r\n getWarnings() {\r\n return this.warningMessages;\r\n }\r\n\r\n getMeshBoundingBox(node: MeshNode, vertexGroups?: IVertexGroup[]) {\r\n let mesh = this.rendererManager.mesh.get3d(node);\r\n let newMesh: Mesh | undefined;\r\n if (vertexGroups) {\r\n const newIndices: number[] = [];\r\n const newPositions: number[] = [];\r\n let indices: number[];\r\n let positions: number[];\r\n if (mesh instanceof Mesh && mesh.geometry) {\r\n positions = mesh.geometry.getVerticesData(VertexBuffer.PositionKind) as number[];\r\n indices = mesh.geometry.getIndices() as number[];\r\n } else {\r\n indices = [];\r\n positions = [];\r\n }\r\n for (let i = 0; i < vertexGroups.length; i++) {\r\n const vertexGroup = vertexGroups[i];\r\n if (vertexGroup && vertexGroup.startIndex && vertexGroup.endIndex) {\r\n for (let j = vertexGroup.startIndex; j < vertexGroup.endIndex; j++) {\r\n newIndices.push(indices[j]);\r\n for (let k = 0; k < 3; k++) {\r\n newPositions[indices[j] * 3 + k] = positions[indices[j] * 3 + k];\r\n }\r\n }\r\n }\r\n }\r\n newMesh = new Mesh('temp mesh', this.scene, mesh?.parent);\r\n const newVertexData = new VertexData();\r\n newVertexData.indices = newIndices;\r\n newVertexData.positions = newPositions;\r\n newVertexData.applyToMesh(newMesh, true);\r\n newMesh.visibility = 0;\r\n }\r\n\r\n if (newMesh) {\r\n mesh = newMesh;\r\n }\r\n if (mesh && mesh instanceof AbstractMesh) {\r\n const boundingBox = mesh.getBoundingInfo().boundingBox;\r\n newMesh?.dispose();\r\n return {\r\n maximum: boundingBox.maximum,\r\n minimum: boundingBox.minimum,\r\n center: boundingBox.center,\r\n minWorld: boundingBox.minimumWorld,\r\n maxWorld: boundingBox.maximumWorld,\r\n };\r\n }\r\n }\r\n\r\n updateLightWarnings() {\r\n let totalSpotLights = 0;\r\n let totalPointLights = 0;\r\n let shadowCastingLights = 0;\r\n let tempWarning = '';\r\n this.lightsWarningMessages = [];\r\n\r\n this.scene.lights.forEach(light => {\r\n if (light.isEnabled()) {\r\n if (light instanceof SpotLight) {\r\n totalSpotLights += 1;\r\n } else if (light instanceof PointLight) {\r\n totalPointLights += 1;\r\n }\r\n if (light.shadowEnabled) {\r\n shadowCastingLights += 1;\r\n }\r\n }\r\n });\r\n if (totalSpotLights + totalPointLights > 10) {\r\n tempWarning = `Performance Warning: The number of spotlights (${totalSpotLights}) and/or pointlights (${totalPointLights}) is higher than recommended for optimal performance.`;\r\n this.lightsWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n if (shadowCastingLights > 4) {\r\n tempWarning = `Performance Warning: The number of shadow casting lights (${shadowCastingLights}) is higher than recommended for optimal performance.`;\r\n this.lightsWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n this.updateWarnings();\r\n }\r\n\r\n updateTextureWarnings() {\r\n const bigTextures2048 = new Map();\r\n const bigTextures4096 = new Map();\r\n let tempWarning = '';\r\n this.textureWarningMessages = [];\r\n\r\n this.sceneNode.meshes.forEach(node => {\r\n const mesh = this.getRendererNode(node);\r\n let textures: Texture[] | BaseTexture[] = [];\r\n if (mesh instanceof AbstractMesh && mesh.isEnabled()) {\r\n if (mesh.material instanceof MultiMaterial) {\r\n mesh.material.subMaterials.forEach(subMaterial => {\r\n const subMaterialTextures = subMaterial?.getActiveTextures();\r\n if (subMaterialTextures) {\r\n subMaterialTextures.forEach(texture => {\r\n if (texture instanceof Texture) {\r\n textures.push(texture);\r\n }\r\n });\r\n }\r\n });\r\n } else if (mesh.material instanceof Material) {\r\n textures = mesh.material.getActiveTextures();\r\n }\r\n }\r\n\r\n if (textures) {\r\n textures.forEach(texture => {\r\n const textureSize = Math.max(texture.getSize().height, texture.getSize().width);\r\n if (texture instanceof Texture) {\r\n if (textureSize > 4096) {\r\n bigTextures4096.set(texture.uniqueId, texture);\r\n bigTextures2048.set(texture.uniqueId, texture);\r\n } else if (textureSize > 2048) {\r\n bigTextures2048.set(texture.uniqueId, texture);\r\n }\r\n }\r\n });\r\n }\r\n });\r\n\r\n if (bigTextures4096.size > 4) {\r\n tempWarning = `Warning, number of textures with resolutions over 4096 (${bigTextures4096.size}) is higher than recommended for optimal performance.`;\r\n this.textureWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n } else if (bigTextures2048.size > 20) {\r\n tempWarning = `Warning, number of textures with resolutions over 2048 (${bigTextures2048.size}) is higher than recommended for optimal performance.`;\r\n this.textureWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n this.updateWarnings();\r\n }\r\n\r\n updateMeshWarnings() {\r\n this.totalPolygons = this.recursiveGetPolygons(this.sceneNode).polygons;\r\n let meshCastAndReceiveShadows = 0;\r\n let tempWarning = '';\r\n this.meshWarningMessages = [];\r\n\r\n this.MeshWarningTracker.forEach(mesh => {\r\n if (mesh.isEnabled) {\r\n if (mesh.featureNumber > 15) {\r\n tempWarning = `Performance Warning: The number of features on ${mesh.name} is higher than recommended for optimal performance.`;\r\n this.meshWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n\r\n if (mesh.castShadows && mesh.receiveShadows) {\r\n meshCastAndReceiveShadows += 1;\r\n }\r\n }\r\n });\r\n\r\n if (this.totalPolygons > 500000) {\r\n tempWarning = `Performance Warning: Polygon count of ${this.totalPolygons} is higher than recommended for optimal performance.`;\r\n this.meshWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n\r\n if (meshCastAndReceiveShadows > 10) {\r\n tempWarning = `Performance Warning: The number of meshes that cast and receive shadows (${meshCastAndReceiveShadows}) is higher than recommended for optimal performance.`;\r\n this.meshWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n\r\n this.updateWarnings();\r\n }\r\n\r\n updateNormalSmoothingWarnings(feature: NormalSmoothingFeature, polygonCount: number, removed?: boolean) {\r\n if (removed) {\r\n this.normalSmoothingWarnings.delete(feature.id);\r\n } else {\r\n if (polygonCount > 100000 && feature.enabled) {\r\n const warning = `Performance Warning: Too many polygons (${polygonCount}) are selected inside \"${feature.name}\" on \"${feature._parent?.name}\".`;\r\n this.normalSmoothingWarnings.set(feature.id, warning);\r\n if (this.isDevEnvironment) {\r\n console.warn(warning);\r\n }\r\n } else {\r\n this.normalSmoothingWarnings.delete(feature.id);\r\n }\r\n }\r\n this.updateWarnings;\r\n }\r\n\r\n updateMaterialWarnings() {\r\n let tempWarning = '';\r\n const localMaterialCount = this.getLocalMaterialsRecursive(this.sceneNode);\r\n this.materialWarningMessages = [];\r\n if (localMaterialCount > 20) {\r\n tempWarning = `Performance Warning: The number of local materials (${localMaterialCount}) is higher than recommended for optimal performance.`;\r\n this.materialWarningMessages.push(tempWarning);\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n }\r\n\r\n updateAnimationWarnings(activeAnimations: number) {\r\n let tempWarning = '';\r\n if (activeAnimations > 1) {\r\n tempWarning = `Performance Warning: More than 1 animation (${activeAnimations}) is active at the same instance.`;\r\n if (this.isDevEnvironment) {\r\n console.warn(tempWarning);\r\n }\r\n }\r\n }\r\n\r\n updateWarnings() {\r\n const tempArray: string[] = [];\r\n if (this.lightsWarningMessages && this.lightsWarningMessages.length > 0) {\r\n this.lightsWarningMessages.forEach(warning => {\r\n tempArray.push(warning);\r\n });\r\n }\r\n if (this.textureWarningMessages && this.textureWarningMessages.length > 0) {\r\n this.textureWarningMessages.forEach(warning => {\r\n tempArray.push(warning);\r\n });\r\n }\r\n if (this.meshWarningMessages && this.meshWarningMessages.length > 0) {\r\n this.meshWarningMessages.forEach(warning => {\r\n tempArray.push(warning);\r\n });\r\n }\r\n if (this.materialWarningMessages && this.materialWarningMessages.length > 0) {\r\n this.materialWarningMessages.forEach(warning => {\r\n tempArray.push(warning);\r\n });\r\n }\r\n if (this.normalSmoothingWarnings && this.normalSmoothingWarnings.size > 0) {\r\n this.normalSmoothingWarnings.forEach(warning => {\r\n tempArray.push(warning);\r\n });\r\n }\r\n if (tempArray.length === 0) {\r\n tempArray.push('No warnings to display.');\r\n }\r\n this.warningMessages = tempArray;\r\n this.warningTracker.next();\r\n }\r\n\r\n extractMeshGeometry(node: MeshNode) {\r\n const mesh = this.rendererManager.mesh.get3d(node);\r\n if (mesh && mesh instanceof Mesh && mesh.geometry) {\r\n const newGeometry = new KbGeometry();\r\n newGeometry.indices = new Uint32Array(mesh.geometry.getIndices() || []);\r\n newGeometry.positions = new Float32Array(mesh.geometry.getVerticesData(VertexBuffer.PositionKind) || []);\r\n if (newGeometry.indices.length === 0 || newGeometry.positions.length === 0) {\r\n return null;\r\n }\r\n const normals = mesh.geometry.getVerticesData(VertexBuffer.NormalKind);\r\n if (normals) {\r\n newGeometry.normals = new Float32Array(normals);\r\n }\r\n const tangents = mesh.geometry.getVerticesData(VertexBuffer.TangentKind);\r\n if (tangents) {\r\n newGeometry.tangents = new Float32Array(tangents);\r\n }\r\n const uvs = mesh.geometry.getVerticesData(VertexBuffer.UVKind);\r\n if (uvs) {\r\n newGeometry.uvs = new Float32Array(uvs);\r\n }\r\n\r\n return newGeometry;\r\n }\r\n }\r\n\r\n applySvgToSketch(node: SketchNode, data: Blob) {\r\n return SvgConverter.overwriteSketchWithSvg(node, data);\r\n }\r\n\r\n draggingEvent(mousePosition: Observable<{ x: number; y: number }>) {\r\n let lastPickedMesh: SpaceNode | undefined;\r\n const dragOver = new Subject();\r\n mousePosition.subscribe(\r\n position => {\r\n const pickInfo = this.interaction.pick(position.x, position.y);\r\n const mesh = pickInfo?.targetNode;\r\n if (lastPickedMesh !== mesh) {\r\n if (lastPickedMesh) {\r\n this.highlighter.remove(lastPickedMesh);\r\n }\r\n if (mesh) {\r\n this.highlighter.add(mesh, KbColor.Green());\r\n }\r\n dragOver.next(mesh);\r\n lastPickedMesh = mesh;\r\n }\r\n },\r\n () => {},\r\n () => {\r\n if (lastPickedMesh) {\r\n this.highlighter.remove(lastPickedMesh);\r\n dragOver.complete();\r\n }\r\n }\r\n );\r\n return dragOver.asObservable();\r\n }\r\n\r\n dispose() {\r\n this.disposed = true;\r\n this.positionTrackedNodes.clear();\r\n this.rendererManager.disposeAll();\r\n this.scene.dispose();\r\n this.engine.dispose();\r\n this.camera!.dispose();\r\n this.manager.dispose();\r\n this.bbCache.dispose();\r\n this.sketchEditor.dispose();\r\n if (this.canvas) {\r\n this.container.removeChild(this.canvas);\r\n delete this.canvas;\r\n }\r\n if (this.uiOverlay) {\r\n this.container.removeChild(this.uiOverlay);\r\n delete this.uiOverlay;\r\n }\r\n if (this.resizeObserver) {\r\n this.resizeObserver.disconnect();\r\n delete this.resizeObserver;\r\n }\r\n this.fpsTracker.complete();\r\n this.polygonTracker.complete();\r\n this.warningTracker.complete();\r\n this.meshWarningsNeedsUpdate.complete();\r\n this.materialWarningsNeedsUpdate.complete();\r\n this.animationWarningsNeedsUpdate.complete();\r\n }\r\n\r\n getScreenPositionOfNode(node: SpaceNode) {\r\n const bNode = this.rendererManager.mesh.get3d(node);\r\n\r\n if (bNode) {\r\n return nodeToScreen(bNode, this.scene.activeCamera!);\r\n }\r\n }\r\n\r\n getScreenBoundingBoxOfNode(node: SpaceNode) {\r\n const bNode = this.rendererManager.mesh.get3d(node);\r\n if (bNode) {\r\n return getScreenBoundingBox(bNode, this.scene.activeCamera!, true);\r\n }\r\n }\r\n\r\n getBabylonJson() {\r\n return JSON.stringify(SceneSerializer.Serialize(this.scene), null, 2);\r\n }\r\n\r\n exportGlb() {\r\n return this.gltfExporter.exportGlb(this.sceneNode?.name);\r\n }\r\n\r\n exportObj(meshNode?: MeshNode) {\r\n const fileName = meshNode ? meshNode.name : this.sceneNode?.name;\r\n return this.objExporter.exportObj(fileName, meshNode);\r\n }\r\n\r\n //returns an object containing the polygons and vertices withing the selected node\r\n recursiveGetPolygons(node: SpaceNode) {\r\n if (node.visible == false) {\r\n return { polygons: 0, vertices: 0 };\r\n }\r\n if (node instanceof MeshNode) {\r\n return { polygons: node._polygonCount || 0, vertices: node._verticesCount || 0 };\r\n }\r\n const result = { polygons: 0, vertices: 0 };\r\n const children = node.getChildren();\r\n\r\n children.forEach(child => {\r\n if (child instanceof MeshNode || child instanceof MeshGroupNode) {\r\n const childData = this.recursiveGetPolygons(child);\r\n result.polygons += childData.polygons;\r\n result.vertices += childData.vertices;\r\n }\r\n });\r\n return result;\r\n }\r\n\r\n //call with null\r\n onNextFrame(func: () => void) {\r\n this.nextFrameCallbacks.push(func);\r\n }\r\n\r\n userIsInteracting() {\r\n return this.interaction.pointerIsDown || this.gizmos.dragging;\r\n }\r\n\r\n /** runs the kb3d renderers. Called before the babylon render */\r\n protected preRender() {\r\n // If this kb viewer instance is disposed, exit the render loop\r\n if (this.disposed) {\r\n return;\r\n }\r\n\r\n this.bbCache.update(); //update watchers of the bbcache of everything that changed since the last frame\r\n this.animation.update(); //update all animations. This can result in changes, so should be called before the check for changes\r\n if (!this.rendererManager.isStable()) {\r\n /** nodes must be processed in a specific order. For example, materials must be processed before meshes,\r\n * or a new material wouldn't exist yet in babylon when the mesh renderer tries to apply it.\r\n */\r\n const hasChanges = SyncService.hasChanges;\r\n\r\n this.rendererManager.render();\r\n this.gizmos.updateGizmoPositions();\r\n\r\n //if there were changes, force a babylon render asap to keep responsive\r\n if (hasChanges) {\r\n this.forceRenderOnNextFrame = true;\r\n }\r\n\r\n this.viewChanged.next();\r\n\r\n while (this.nextFrameCallbacks.length > 0) {\r\n this.nextFrameCallbacks.pop()!();\r\n }\r\n nextTick();\r\n }\r\n }\r\n\r\n public startRender(): void {\r\n if (!this._renderLoopRunning) {\r\n this._renderLoopRunning = true;\r\n let frameCount = 0;\r\n // Run the render loop.\r\n this.engine.runRenderLoop(() => {\r\n this.preRender();\r\n let skipped = true;\r\n\r\n if (!this.pauseRender) {\r\n frameCount++;\r\n if (\r\n this.forceRunRenderer ||\r\n this.forceRenderOnNextFrame ||\r\n this.userIsInteracting() ||\r\n this.camera!.cameraMoving ||\r\n this.animation.animationsAreRunning ||\r\n this.ar.xrActive\r\n ) {\r\n this.scene.render();\r\n this.forceRenderOnNextFrame = false;\r\n this.viewChanged.next();\r\n skipped = false;\r\n } else if (frameCount > 10) {\r\n this.scene.render();\r\n skipped = false;\r\n }\r\n if (frameCount > 10) {\r\n frameCount = 0;\r\n this.fpsTracker.next(this.getFPS());\r\n }\r\n this.afterRender.next({ skipped });\r\n }\r\n });\r\n }\r\n }\r\n\r\n public stopRender() {\r\n this.engine.stopRenderLoop();\r\n this._renderLoopRunning = false;\r\n }\r\n\r\n protected createCanvas() {\r\n const canvas = document.createElement('canvas');\r\n canvas.style.width = '100%';\r\n canvas.style.height = '100%';\r\n canvas.style.outline = 'none';\r\n canvas.style.opacity = '0';\r\n canvas.style.transition = `opacity ${FADE_TIME}ms linear`;\r\n this.container.appendChild(canvas);\r\n\r\n if (!this.container.style.position) {\r\n this.container.style.position = 'relative';\r\n }\r\n this.uiOverlay = this.createOverlay();\r\n this.container.appendChild(this.uiOverlay);\r\n\r\n this.resizeObserver = new ResizeObserver(() => this.resize());\r\n this.resizeObserver.observe(canvas);\r\n\r\n return canvas;\r\n }\r\n\r\n protected createOverlay() {\r\n const overlay = document.createElement('div');\r\n overlay.style.position = 'absolute';\r\n overlay.style.top = '0';\r\n overlay.style.left = '0';\r\n overlay.style.width = '100%';\r\n overlay.style.height = '100%';\r\n overlay.style.pointerEvents = 'none';\r\n return overlay;\r\n }\r\n\r\n protected createLoadingExperience(loadingExperience: eLoadingExperience, loadingImagePath: string) {\r\n if (loadingExperience == eLoadingExperience.image) {\r\n const matService = this.manager.getService(Token.MaterialService)!;\r\n this.loadingOverlay = this.createOverlay();\r\n this.loadingOverlay.style.opacity = '0';\r\n this.loadingOverlay.style.transition = `opacity ${FADE_TIME}ms linear`;\r\n const img = document.createElement('img');\r\n img.style.position = 'absolute';\r\n img.style.width = '100%';\r\n img.style.height = '100%';\r\n img.style.backgroundSize = 'auto 100%';\r\n img.style.backgroundRepeat = 'no-repeat';\r\n img.style.backgroundPosition = 'center';\r\n img.style.backgroundColor = 'transparent';\r\n img.style.backgroundImage = `url('${matService.getAbsoluteTexturePath(loadingImagePath)}')`;\r\n this.loadingOverlay.appendChild(img);\r\n this.container.appendChild(this.loadingOverlay);\r\n this.loadingOverlay.style.opacity = '1';\r\n } else if (loadingExperience == eLoadingExperience.fade) {\r\n // do nothing\r\n } else if (loadingExperience == eLoadingExperience.spinner) {\r\n this.loadingOverlay = this.createOverlay();\r\n this.loadingOverlay.style.opacity = '0';\r\n this.loadingOverlay.style.transition = `opacity ${FADE_TIME}ms linear`;\r\n this.loadingOverlay.style.display = 'flex';\r\n this.loadingOverlay.style.alignItems = 'center';\r\n this.loadingOverlay.style.justifyContent = 'center';\r\n\r\n this.loadingOverlay.innerHTML = `\r\n \r\n \r\n \r\n \r\n `;\r\n this.container.appendChild(this.loadingOverlay);\r\n this.loadingOverlay.style.opacity = '1';\r\n } else {\r\n this.canvas!.style.opacity = '1';\r\n }\r\n }\r\n\r\n protected hideLoadingExperience() {\r\n if (this.loadingOverlay) {\r\n this.loadingOverlay.style.opacity = '0';\r\n\r\n setTimeout(() => {\r\n this.loadingOverlay?.remove();\r\n this.loadingOverlay = undefined;\r\n }, FADE_TIME);\r\n }\r\n this.canvas!.style.opacity = '1';\r\n }\r\n\r\n resize() {\r\n if (!this.ar || (!this.ar.xrLoading && !this.ar.xrActive)) {\r\n //don't mess with the AR canvas resize\r\n this.engine.resize();\r\n this.fireViewChangedOnNextRender();\r\n }\r\n }\r\n\r\n protected optimizeScene(scene: Scene) {\r\n if (this.sceneNode.enableSceneOptimization) {\r\n this.forceRunRenderer = true; // Run renderer until optimizer is done optimizing\r\n const sceneOptimizerOptions = new SceneOptimizerOptions(30, 2000);\r\n\r\n let priority = 0;\r\n sceneOptimizerOptions.addCustomOptimization(\r\n function () {\r\n console.warn('Low scene performance detected - disabling 3d features to improve performance.');\r\n return true;\r\n },\r\n function () {\r\n return 'custom optimization to throw console warning when optimizer needs to run.';\r\n },\r\n priority\r\n );\r\n\r\n sceneOptimizerOptions.optimizations.push(new ShadowsOptimization(priority));\r\n sceneOptimizerOptions.optimizations.push(new LensFlaresOptimization(priority));\r\n\r\n // Next priority\r\n priority++;\r\n sceneOptimizerOptions.optimizations.push(new PostProcessesOptimization(priority));\r\n sceneOptimizerOptions.optimizations.push(new ParticlesOptimization(priority));\r\n\r\n priority++;\r\n sceneOptimizerOptions.optimizations.push(new TextureOptimization(priority, 256));\r\n\r\n priority++;\r\n sceneOptimizerOptions.optimizations.push(new RenderTargetsOptimization(priority));\r\n\r\n // Don't scale the resolution when in editor mode because it affects usability\r\n if (!this.options.editorMode) {\r\n priority++;\r\n sceneOptimizerOptions.optimizations.push(new HardwareScalingOptimization(priority, 4));\r\n }\r\n\r\n const sceneOptimizer = new SceneOptimizer(scene, sceneOptimizerOptions, false);\r\n sceneOptimizer.onSuccessObservable.add(() => {\r\n this.startSceneRenderAutoStop(scene, this.engine);\r\n\r\n // Run optimizer in improvement mode in case the scene speeds up later\r\n new SceneOptimizer(scene, sceneOptimizerOptions, false, true);\r\n });\r\n sceneOptimizer.onFailureObservable.add(() => this.startSceneRenderAutoStop(scene, this.engine));\r\n\r\n sceneOptimizer.start();\r\n }\r\n }\r\n\r\n protected createScene() {\r\n // Create a basic BJS Scene object.\r\n const scene = new Scene(this.engine);\r\n scene.useRightHandedSystem = true;\r\n scene.clearColor = new Color4(0, 0, 0, 0); //default background to transparent\r\n\r\n // Create a FreeCamera, and set its position to (x:0, y:5, z:-10).\r\n //this.m_camera = new FreeCamera('camera1', new Vector3(0, 5, -10), this.m_scene);\r\n\r\n //scene.createDefaultCameraOrLight(true, true, true);\r\n\r\n this.createDefaultEnv();\r\n\r\n return scene;\r\n }\r\n\r\n protected startSceneRenderAutoStop(scene: Scene, engine: Engine) {\r\n this.forceRunRenderer = false;\r\n }\r\n\r\n protected createDefaultEnv() {\r\n if (!this.scene) {\r\n return;\r\n }\r\n const helper = this.scene.createDefaultEnvironment({\r\n skyboxSize: 500,\r\n groundShadowLevel: 0.5,\r\n });\r\n\r\n if (helper !== null && helper.skybox !== null && helper.ground !== null) {\r\n helper.setMainColor(Color3.Gray());\r\n helper.rootMesh.position.y = -5;\r\n helper.skybox.isPickable = false;\r\n helper.rootMesh.isPickable = false;\r\n helper.ground.isPickable = false;\r\n //helper.rootMesh.name = KbViewer.KBMAXPREFIX + helper.rootMesh.name;\r\n //helper.skybox.name = KbViewer.KBMAXPREFIX + helper.skybox.name;\r\n for (let i = 0; i < this.scene.meshes.length; i++) {\r\n this.scene.meshes[i].name = KBMAXPREFIX + this.scene.meshes[i].name;\r\n this.scene.meshes[i].id = KBMAXPREFIX + this.scene.meshes[i].id;\r\n }\r\n }\r\n }\r\n\r\n public pauseRenderWhile(action: () => void) {\r\n this.pauseRender = true;\r\n action();\r\n this.pauseRender = false;\r\n }\r\n\r\n /**\r\n * returns a promise that is resolved when the following has happened:\r\n * * the scene graph is fully loaded\r\n * * at least one pass through the render loop since the scene has been loaded has completed\r\n * * any server assets in flight (meshes, textures) have been received and processed\r\n */\r\n public whenAssetsLoaded(waitForMaterials = true) {\r\n if (!this.sceneNode) {\r\n throw Error('a scene needs to be loaded into the viewer to wait for assets');\r\n }\r\n\r\n const promise = new Promise((resolve, reject) => {\r\n const http = this.sceneNode._manager?.getService(Token.HttpService);\r\n const materialService = this.sceneNode._manager?.getService(Token.MaterialService);\r\n\r\n if (!http) {\r\n throw Error('HTTP API service could not be initialized');\r\n }\r\n if (!materialService) {\r\n throw Error('Material service could not be initialized');\r\n }\r\n\r\n this.forceAndWaitForNextRender().then(() => {\r\n const promises = [\r\n ...http.trackedAssetCalls,\r\n ...this.additionalLoadBlockers,\r\n this.scene.whenReadyAsync(),\r\n ];\r\n if (waitForMaterials) {\r\n promises.push(...materialService.trackedAssetCalls);\r\n }\r\n Promise.all(promises).finally(() => {\r\n // now wait for a render loop and make sure no new loading blockers were added since the last batch\r\n this.forceAndWaitForNextRender().then(() => {\r\n if (\r\n http.trackedAssetCalls.length ||\r\n this.additionalLoadBlockers.length ||\r\n (waitForMaterials && materialService.trackedAssetCalls.length) ||\r\n !this.scene.isReady() ||\r\n !this.rendererManager.isStable()\r\n ) {\r\n return this.whenAssetsLoaded(waitForMaterials).finally(() => {\r\n resolve();\r\n });\r\n } else {\r\n resolve();\r\n }\r\n });\r\n });\r\n });\r\n });\r\n\r\n return promise;\r\n }\r\n\r\n public deferSceneReady(promise: Promise) {\r\n promise.then(() => {\r\n this.additionalLoadBlockers = this.additionalLoadBlockers.filter(somePromise => somePromise !== promise);\r\n });\r\n\r\n this.additionalLoadBlockers.push(promise);\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when the next kb3d render processing has happened.\r\n * Note that this does not necessarily mean that the babylon render has happened!\r\n * If you want to wait for both, see forceAndWaitForNextRender\r\n */\r\n protected waitForNextKb3dRender() {\r\n return this.afterRender.pipe(take(1)).toPromise();\r\n }\r\n\r\n public forceAndWaitForNextRender() {\r\n this.forceRenderOnNextFrame = true;\r\n return this.waitForNextKb3dRender();\r\n }\r\n\r\n public async waitForStableRender(timeout = 5000) {\r\n const start = performance.now();\r\n\r\n await this.forceAndWaitForNextRender();\r\n while (!this.rendererManager.isStable()) {\r\n await this.forceAndWaitForNextRender();\r\n\r\n if (performance.now() - start > timeout) {\r\n console.error(`waiting for stable render took longer than timeout of ${timeout}ms, unblocking loading`);\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public fireViewChangedOnNextRender() {\r\n this.forceAndWaitForNextRender().then(() => {\r\n this.viewChanged.next();\r\n });\r\n }\r\n\r\n public getActiveMates() {\r\n const mates = new Array();\r\n\r\n this.sceneNode.runOnAllScenes(s => {\r\n mates.push(...s._manager!.getByToken(Token.MateNode).filter(m => m.isActive()));\r\n });\r\n\r\n return mates;\r\n }\r\n\r\n public nodesIntersect(node1: SpaceNode, node2: SpaceNode) {\r\n const bb1 = this.bbCache.getWorld(node1);\r\n const bb2 = this.bbCache.getWorld(node2);\r\n if (bb1 && bb2) {\r\n return bb1.boundingInfo.intersects(bb2.boundingInfo as DeepImmutableObject, false);\r\n }\r\n return false;\r\n }\r\n\r\n public getReferenceNodes(dynamicId: string) {\r\n const result: Array = [];\r\n const references = this.rendererManager.referenceProcessor.getReferencesTo();\r\n if (references.has(dynamicId)) {\r\n const ids = references.get(dynamicId)?.keys();\r\n if (ids) {\r\n for (const key of ids) {\r\n result.push(this.manager.getById(key));\r\n }\r\n }\r\n return result;\r\n } else {\r\n return [];\r\n }\r\n }\r\n\r\n public getLocalMaterialsRecursive(node: SceneNode) {\r\n let result = 0;\r\n\r\n if (!node.scenes) {\r\n return node.materials.length | 0;\r\n } else {\r\n node.scenes.forEach(scene => {\r\n result += this.getLocalMaterialsRecursive(scene);\r\n });\r\n result += node.materials.length;\r\n }\r\n return result;\r\n }\r\n\r\n public getTransformSpaceDifference(originNode: Kb3dObject, destinationNode: Kb3dObject) {\r\n const originMesh = this.getRendererNode(originNode as SpaceNode);\r\n const destinationMesh = this.getRendererNode(destinationNode as SpaceNode);\r\n const result = {\r\n scale: Vector3.One(),\r\n rotationQuaternion: new Quaternion(),\r\n translation: Vector3.Zero(),\r\n };\r\n if (!destinationMesh) {\r\n const resultMatrix = originMesh.getWorldMatrix();\r\n resultMatrix.decompose(result.scale, result.rotationQuaternion, result.translation);\r\n } else if (originMesh && destinationMesh) {\r\n const originMatrix = originMesh.getWorldMatrix();\r\n const destinationMatrix = destinationMesh.getWorldMatrix().clone();\r\n destinationMatrix.invert();\r\n const resultMatrix = originMatrix.multiply(destinationMatrix);\r\n resultMatrix.decompose(result.scale, result.rotationQuaternion, result.translation);\r\n } else {\r\n return null;\r\n }\r\n return {\r\n scale: result.scale.x,\r\n rotationQuaternion: KbQuaternion.FromQuat(result.rotationQuaternion),\r\n translation: KbVector.FromVec3(result.translation),\r\n };\r\n }\r\n\r\n public centerMeshToOrigin(node: Kb3dObject) {\r\n const boundingBox = this.getMeshBoundingBox(node as MeshNode);\r\n const center = boundingBox?.maxWorld.add(boundingBox.minWorld);\r\n if (center) {\r\n center?.scaleInPlace(-0.5);\r\n const result = new KbVector(center.x, center.y, center.z);\r\n return result;\r\n } else {\r\n return new KbVector(0, 0, 0);\r\n }\r\n }\r\n}\r\n","export * from './models';\r\nexport * from './tests';\r\nexport * from './view';\r\nimport * as _kb3dEnums from './models/classes/enums';\r\nexport const kb3dEnums = _kb3dEnums;\r\n","import { ITrackedClass } from '@models/interfaces/tracked-class';\r\nimport { Kb3dModels } from './decorators';\r\nimport { Kb3dObject } from './kb3d-object';\r\n\r\nexport type KeyOfAndEmpty = keyof T | '';\r\n\r\nexport class Validator {\r\n protected vmap = new Map>();\r\n\r\n public getAll() {\r\n return this.vmap;\r\n }\r\n\r\n public validateNode(node: ITrackedClass) {\r\n const model = Kb3dModels.get(node._token);\r\n if (model && model.validate) {\r\n model.validate(node, this);\r\n }\r\n }\r\n\r\n public nodeIsValid(node: Kb3dObject) {\r\n return (\r\n !this.vmap.has(node.id) ||\r\n !this.vmap.get(node.id)!.size ||\r\n [...this.vmap.get(node.id)!.values()].every(a => a == null || a.length == 0)\r\n );\r\n }\r\n\r\n public getErrors(nodeId: string, prop: string) {\r\n return this.vmap.get(nodeId)?.get(prop as string);\r\n }\r\n\r\n /** removes all validation errors for the given property */\r\n public clearProp(node: T, prop: KeyOfAndEmpty) {\r\n if (this.vmap.has(node.id) && this.vmap.get(node.id)!.has(prop as string)) {\r\n this.vmap.get(node.id)?.delete(prop as string);\r\n }\r\n return this;\r\n }\r\n\r\n /** removes a specific validation errors for the given property */\r\n public clearPropError(node: T, prop: KeyOfAndEmpty, ...errors: string[]) {\r\n return this.clearPropErrorWhere(node, prop, e => e.equalsAny(...errors));\r\n }\r\n\r\n public clearPropErrorWhere(\r\n node: T,\r\n prop: KeyOfAndEmpty,\r\n predicate: (error: string) => boolean\r\n ) {\r\n if (this.vmap.has(node.id) && this.vmap.get(node.id)!.has(prop as string)) {\r\n this.vmap\r\n .get(node.id)\r\n ?.get(prop as string)\r\n ?.removeWhere(e => predicate(e));\r\n }\r\n return this;\r\n }\r\n\r\n public clearNode(node: T) {\r\n this.vmap.delete(node.id);\r\n }\r\n\r\n public addError(node: T, prop: KeyOfAndEmpty, ...errors: string[]) {\r\n if (!this.vmap.has(node.id)) {\r\n this.vmap.set(node.id, new Map());\r\n }\r\n const entry = this.vmap.get(node.id)!;\r\n const sprop = prop as string;\r\n if (!entry.has(sprop)) {\r\n entry.set(sprop, [...errors]);\r\n } else {\r\n const existingErrors = entry.get(sprop)!;\r\n for (const err of errors) {\r\n if (!existingErrors.contains(err)) {\r\n existingErrors.push(err);\r\n }\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n public assert(node: T, prop: KeyOfAndEmpty, expression: boolean, ...errors: string[]) {\r\n if (expression) {\r\n this.clearPropError(node, prop, ...errors);\r\n } else {\r\n this.addError(node, prop, ...errors);\r\n }\r\n return this;\r\n }\r\n}\r\n","import { Matrix } from '@babylonjs/core/Maths';\r\nimport { MeshNode } from '@models/classes/meshes/mesh-node';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { computeLocalTransform } from '../helpers/math-helper';\r\n\r\nexport function bakeMeshTransform(node: MeshNode) {\r\n const newTransform = computeLocalTransform(node);\r\n\r\n if (node.preTransform) {\r\n if (node.preTransform.length !== 16) {\r\n throw Error('invalid pretransform array ');\r\n }\r\n const preTransform = Matrix.FromArray(node.preTransform);\r\n preTransform.multiplyToRef(newTransform, newTransform);\r\n }\r\n node.preTransform = Array.from(newTransform.toArray());\r\n\r\n node.pivot = KbVector.Zero();\r\n node.position = KbVector.Zero();\r\n node.scaling = 1;\r\n node.rotationAngle = 0;\r\n node.rotationAxis = new KbVector(0, 1, 0);\r\n node.eulerRotation = KbVector.Zero();\r\n\r\n return node;\r\n}\r\n","import { Engine } from '@babylonjs/core/Engines/engine';\r\nimport { HDRCubeTexture } from '@babylonjs/core/Materials/Textures/hdrCubeTexture';\r\nimport { EnvironmentTextureTools } from '@babylonjs/core/Misc/environmentTextureTools';\r\nimport { Observable } from 'rxjs';\r\n\r\nexport function convertHdrToEnv(hdrFile: Blob, hdrSize: number): Observable {\r\n return new Observable(subject => {\r\n const dataUri = URL.createObjectURL(hdrFile);\r\n const canvas = document.createElement('canvas');\r\n const dummyEngine = new Engine(canvas, true, {\r\n premultipliedAlpha: false,\r\n });\r\n\r\n const env = new HDRCubeTexture(dataUri, dummyEngine, hdrSize, false, true, false, true, () => {\r\n EnvironmentTextureTools.CreateEnvTextureAsync(env).then(buffer => {\r\n URL.revokeObjectURL(dataUri);\r\n dummyEngine.dispose();\r\n subject.next(new Blob([buffer]));\r\n subject.complete();\r\n });\r\n });\r\n });\r\n\r\n // return new Promise((resolve, reject) => {\r\n // const env = new HDRCubeTexture(\r\n // \"textures/environment.hdr\",\r\n // scene,\r\n // hdrSize,\r\n // false,\r\n // true,\r\n // false,\r\n // true,\r\n // () => {\r\n // console.log(\"environment loaded\");\r\n\r\n // EnvironmentTextureTools\r\n // .CreateEnvTextureAsync(env)\r\n // .then((buffer) => {\r\n // console.log(buffer);\r\n // console.log('success');\r\n // resolve(new Blob([buffer]));\r\n // })\r\n // }\r\n // );\r\n // });\r\n}\r\n","import { eEasing } from '@models/classes/enums';\r\nimport { SetMap } from '@models/classes/handlers';\r\nimport { Kb3dManager } from '@models/classes/kb3d-manager';\r\nimport { KbColor } from '@models/classes/primitives/kb-color';\r\nimport { KbVector } from '@models/classes/primitives/kb-vector';\r\nimport { SceneNode } from '@models/classes/scene-node';\r\nimport { Token } from '@models/classes/token';\r\nimport { topologicalSort } from '@view/helpers/graph-helper';\r\nimport { KbViewer } from '@view/kb-viewer';\r\n\r\nexport function kb3dTest() {\r\n let map = new SetMap();\r\n map.add('A', 'B', 'C');\r\n map.add('B', 'C', 'D');\r\n map.add('C', 'E');\r\n map.add('D', 'E', 'F');\r\n map.add('E');\r\n map.add('F');\r\n map.add('G', 'F', 'E');\r\n topologicalSort(map, s => s);\r\n\r\n map = new SetMap();\r\n map.add('0', '1', '2');\r\n map.add('1', '2');\r\n map.add('2', '0', '3');\r\n map.add('3');\r\n topologicalSort(map, s => s);\r\n\r\n map = new SetMap();\r\n map.add('2');\r\n map.add('3', '8', '10');\r\n map.add('5', '11');\r\n map.add('7', '8', '11');\r\n map.add('8', '9');\r\n map.add('9');\r\n map.add('10');\r\n map.add('11', '2', '9', '10');\r\n topologicalSort(map, s => s);\r\n\r\n const kbViewer = new KbViewer({ container: document.getElementById('viewer-div') as HTMLElement });\r\n let manager = new Kb3dManager({ assetRoot: '' }); //default services automatically used\r\n let sceneNode = manager.create(Token.SceneNode);\r\n sceneNode.backgroundColor = new KbColor(0.9, 0.9, 0.9, 1);\r\n sceneNode.enableHoverEffects = true;\r\n kbViewer.loadScene({ sceneNode });\r\n\r\n const group = manager.create(Token.MeshGroupNode);\r\n\r\n const box = manager.create(Token.BoxNode);\r\n const boxId = box.id;\r\n group.meshes.push(box);\r\n\r\n // let blah = manager.getById(boxId);\r\n // let db = manager.getAll().map(n => { return { id: n.id, name: n.name, type: n.$type }; });\r\n // alert(JSON.stringify(db, null, 2));\r\n\r\n // sceneNode.meshes.push(group);\r\n // db = manager.getAll().map(n => { return { id: n.id, name: n.name, type: n.$type }; });\r\n // alert(JSON.stringify(db, null, 2));\r\n\r\n // setTimeout(() => {\r\n // sceneNode.meshes.remove(group);\r\n // db = manager.getAll().map(n => { return { id: n.id, name: n.name, type: n.$type }; });\r\n // alert(JSON.stringify(db, null, 2));\r\n // }, 500);\r\n\r\n //sceneNode.meshes.push(box);\r\n\r\n // function animate(time: number) {\r\n // requestAnimationFrame(animate);\r\n // TWEEN.update(time);\r\n // }\r\n // requestAnimationFrame(animate);\r\n\r\n // let pos = { x: box.position.x, y: box.position.y, z: box.position.z };\r\n // const anim = new TWEEN.Tween(pos)\r\n // .to({ x: 3, y: 0, z: 0 }, 5000)\r\n // .onUpdate(() => {\r\n // box.position = KbVector.From(pos);\r\n // })\r\n // .start();\r\n\r\n // let group = manager.create(Token.MeshGroupNode);\r\n // group.rotation = new KbVector(0, 0, 0);\r\n // sceneNode.meshes.push(group);\r\n\r\n // let box = manager.create(Token.BoxNode);\r\n // let boxId = box.id;\r\n // box.materialId = \"bricks01\";\r\n // group.meshes.push(box);\r\n\r\n // let conn1 = manager.create(Token.Connector, {\r\n // positionMode: eConnectorPositionMode.boundingBox,\r\n // position: new KbVector(0, 1, 1),\r\n // direction: new KbVector(0, 0, 1)\r\n // });\r\n // box.features.push(conn1);\r\n\r\n // let mat = manager.create(Token.AdvancedMaterialNode, {\r\n // albedoColor: new KbColor(1, 0, 0),\r\n // backFaceCulling: false\r\n // });\r\n // sceneNode.materials.push(mat);\r\n // box.materialId = mat.id;\r\n\r\n // let sphere = manager.create(Token.SphereNode, {\r\n // diameter: 1,\r\n // position: new KbVector(2, 0,0)\r\n // });\r\n // group.meshes.push(sphere);\r\n\r\n // let box2 = manager.create(Token.BoxNode);\r\n // sceneNode.meshes.push(box2);\r\n // box2.position = new KbVector(0, 0, 3);\r\n // box2.width = 2;\r\n // let conn3 = manager.create(Token.Connector, {\r\n // positionMode: eConnectorPositionMode.absolute,\r\n // position: new KbVector(0, 0, -0.5),\r\n // direction: new KbVector(0, 0, -1),\r\n // angle: 0\r\n // });\r\n // let conn4 = manager.create(Token.Connector, {\r\n // positionMode: eConnectorPositionMode.absolute,\r\n // position: new KbVector(1, 0, 0),\r\n // direction: new KbVector(1, 0, 0),\r\n // angle: 30\r\n // });\r\n // let conn5 = manager.create(Token.Connector, {\r\n // positionMode: eConnectorPositionMode.absolute,\r\n // position: new KbVector(0, .5, 0),\r\n // direction: new KbVector(0, 1, 0),\r\n // angle: 0\r\n // });\r\n // box2.features.push(conn3);\r\n // box2.features.push(conn4);\r\n // box2.features.push(conn5);\r\n\r\n // manager.draggables.add(group.id, \"blah\", {\r\n // mode: eDragMode.free,\r\n // //surfaceNodes: [sphere.id, sphere2.id],\r\n // planeNormal: new KbVector(0, 1, 0),\r\n // // planeOrigin: new KbVector(0,0,0),\r\n // //disableOffset: false,\r\n // connectionMode: eConnectionMode.screen,\r\n // showConnectors: true,\r\n // connectRadius: 10,\r\n // dragOpacity: .3,\r\n // dragStart: (a) => {\r\n\r\n // },\r\n // dragging: (a) => {\r\n\r\n // },\r\n // dropped: (a) => {\r\n\r\n // },\r\n // // canConnect: (a) => {\r\n // // a.\r\n // // }\r\n // });\r\n\r\n // kbViewer.interaction.onPointerUp.subscribe(p => {\r\n // console.log(kbViewer.getScreenPositionOfNode(box));\r\n // console.log(kbViewer.getScreenBoundingBoxOfNode(box));\r\n // });\r\n\r\n const light = manager.create(Token.DirectionalLightNode);\r\n sceneNode.lights.push(light);\r\n\r\n // let mat = manager.create(tok.AdvancedMaterialNode, {\r\n // albedoColor: new KbColor(252, 0, 0)\r\n // });\r\n // sceneNode.materials.push(mat);\r\n // box.materialId = mat.id;\r\n\r\n //box.materialId = \"4454a0e3-e1e4-42d4-aea5-6915681bfc12\";\r\n\r\n // for (let row = 0; row < 10; row++){\r\n // for (let col = 0; col < 10; col++) {\r\n // let nested = manager.nestScene(sceneNode);\r\n // nested.name = \"nested\" + row;\r\n // let nestedManager = nested._manager as Kb3dManager;\r\n // let nestedBox = nestedManager.create(tok.BoxNode);\r\n // nestedBox.name = \"nestedBox\" + row;\r\n // if (row % 2 > 0) {\r\n // nestedBox.materialId = \"rock01\";\r\n // } else {\r\n // nestedBox.materialId = \"bricks01\";\r\n // }\r\n // nested.meshes.push(nestedBox);\r\n // nested.position = new KbVector(row * 1.5, col * 1.5, 0);\r\n // }\r\n // }\r\n\r\n kbViewer.interaction.onClick.subscribe(p => {\r\n console.log(p);\r\n });\r\n\r\n kbViewer.interaction.onKeyboard.subscribe(k => {\r\n console.log(k);\r\n });\r\n\r\n const btnAnimate = document.getElementById('btnAnimate');\r\n if (btnAnimate) {\r\n btnAnimate.onclick = () => {\r\n kbViewer.animation\r\n .queue({\r\n name: 'a1',\r\n node: box,\r\n prop: 'position',\r\n toValue: new KbVector(10, 0, 0),\r\n duration: 1000,\r\n easing: eEasing.quadraticIn,\r\n })\r\n .then(() => {\r\n return kbViewer.animation.queue({\r\n name: 'a2',\r\n node: box,\r\n prop: 'rotation',\r\n toValue: new KbVector(box.eulerRotation.x + 720, 0, 0),\r\n duration: 1000,\r\n });\r\n })\r\n .then(() => {\r\n return kbViewer.animation.queue({\r\n name: 'a3',\r\n node: box,\r\n prop: 'position',\r\n toValue: new KbVector(0, 0, 0),\r\n duration: 1000,\r\n easing: eEasing.quadraticOut,\r\n });\r\n });\r\n };\r\n }\r\n\r\n const btnStop = document.getElementById('btnStop');\r\n if (btnStop) {\r\n btnStop.onclick = () => {\r\n kbViewer.animation.stop('a1');\r\n };\r\n }\r\n\r\n const txtJson = document.getElementById('txtJson') as HTMLTextAreaElement;\r\n const txtCounter = document.getElementById('txtCounter') as HTMLDivElement;\r\n\r\n const btnToJson = document.getElementById('btnToJson');\r\n if (btnToJson) {\r\n btnToJson.onclick = () => {\r\n txtJson.value = manager.serializeToJson(sceneNode, { prettyPrint: true });\r\n updateJsonLength();\r\n };\r\n }\r\n\r\n const btnToFullJson = document.getElementById('btnToFullJson');\r\n if (btnToFullJson) {\r\n btnToFullJson.onclick = () => {\r\n txtJson.value = manager.serializeToJson(sceneNode, { omitDefaultValues: false, prettyPrint: true });\r\n updateJsonLength();\r\n };\r\n }\r\n\r\n const btnFromJson = document.getElementById('btnFromJson');\r\n if (btnFromJson) {\r\n btnFromJson.onclick = () => {\r\n manager = new Kb3dManager();\r\n const jsonObject = JSON.parse(txtJson.value);\r\n sceneNode = manager.create(Token.SceneNode, jsonObject);\r\n kbViewer.loadScene({ sceneNode });\r\n };\r\n }\r\n\r\n const btnBabylonJson = document.getElementById('btnBabylonJson');\r\n if (btnBabylonJson) {\r\n btnBabylonJson.onclick = () => {\r\n txtJson.value = kbViewer.getBabylonJson();\r\n };\r\n }\r\n\r\n const btnWidth = document.getElementById('btnWidth');\r\n if (btnWidth) {\r\n btnWidth.onclick = () => {\r\n box.depth = box.depth + 1;\r\n };\r\n }\r\n\r\n const btnMaterialColor = document.getElementById('btnMaterialColor');\r\n if (btnMaterialColor) {\r\n btnMaterialColor.onclick = () => {\r\n //mat.albedoColor = new KbColor(0, 0, 252);\r\n };\r\n }\r\n\r\n // let btnToggleVisible = document.getElementById(\"btnToggleVisible\");\r\n // if (btnToggleVisible) {\r\n // btnToggleVisible.onclick = () => {\r\n // box.visible = !box.visible;\r\n // };\r\n // }\r\n\r\n const btnSaveMesh = document.getElementById('btnSaveMesh');\r\n if (btnSaveMesh) {\r\n btnSaveMesh.onclick = () => {\r\n const myArray = new ArrayBuffer(512);\r\n const longInt8View = new Uint8Array(myArray);\r\n\r\n // generate some data\r\n for (let i = 0; i < longInt8View.length; i++) {\r\n longInt8View[i] = i % 256;\r\n }\r\n\r\n const xhr = new XMLHttpRequest();\r\n xhr.open('POST', '/api/meshes/72b7487f-2ab2-4faf-b034-a1178feeb191', false);\r\n xhr.send(myArray);\r\n };\r\n }\r\n\r\n const btnGetSavedMesh = document.getElementById('btnGetSavedMesh');\r\n if (btnGetSavedMesh) {\r\n btnGetSavedMesh.onclick = () => {\r\n const oReq = new XMLHttpRequest();\r\n oReq.open('GET', '/api/meshes/72b7487f-2ab2-4faf-b034-a1178feeb191', true);\r\n oReq.responseType = 'arraybuffer';\r\n\r\n oReq.onload = function (oEvent) {\r\n const arrayBuffer = oReq.response; // Note: not oReq.responseText\r\n if (arrayBuffer) {\r\n const byteArray = new Uint8Array(arrayBuffer);\r\n for (let i = 0; i < byteArray.byteLength; i++) {\r\n // do something with each byte in the array\r\n console.log(byteArray[i]);\r\n }\r\n }\r\n };\r\n\r\n oReq.send(null);\r\n };\r\n }\r\n\r\n const updateJsonLength = () => {\r\n txtCounter.innerHTML = new TextEncoder().encode(txtJson.value).length.toString() + ' bytes';\r\n };\r\n}\r\n"]}